Search
SailfishOS Open Build Service
>
Projects
>
nemo
:
devel:hw
:
pine
:
dontbeevil
>
ofono
> _service:tar_git:0010-Add-slot-support-to-the-gobi-plugin.patch
Log In
Username
Password
Cancel
Overview
Repositories
Revisions
Requests
Users
Advanced
Attributes
Meta
File _service:tar_git:0010-Add-slot-support-to-the-gobi-plugin.patch of Package ofono
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Adam Pigg <adam@piggz.co.uk> Date: Sun, 10 Mar 2024 12:25:57 +0000 Subject: [PATCH 1/1] *mb2-prepare* Add slot support to the gobi plugin Mb2-scrape: filename=0010-Add-slot-support-to-the-gobi-plugin.patch --- plugins/gobi.c | 193 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 192 insertions(+), 1 deletion(-) diff --git a/plugins/gobi.c b/plugins/gobi.c index 431df17e..a12dba01 100644 --- a/plugins/gobi.c +++ b/plugins/gobi.c @@ -52,6 +52,7 @@ #include <ofono/location-reporting.h> #include <ofono/log.h> #include <ofono/message-waiting.h> +#include <ofono/slot.h> #include <ell/ell.h> @@ -72,10 +73,34 @@ #define GOBI_VOICE (1 << 9) #define GOBI_WDA (1 << 10) +#define IMEI_LEN 16 + +static char imei[IMEI_LEN] = "1234567890123456"; + +typedef struct ofono_slot_driver_data { + struct ofono_slot_manager *slot_manager; + struct l_queue *slots; +} GobiPlugin; + +typedef struct ofono_slot_data { + struct ofono_slot *handle; + struct ofono_modem *modem; + GobiPlugin *plugin; + char imei[IMEI_LEN]; +} GobiSlot; + +static struct ofono_modem *global_modem = NULL; +static GobiPlugin *global_plugin = NULL; +static struct ofono_slot_driver_reg *gobi_ofono_slot_driver = NULL; +static bool gobi_slot_plugin_start(void *user_data); +static void gobi_slot_driver_startup_check(); +static void gobi_slot_set_sim_state(struct ofono_sim *sim); + struct gobi_data { struct qmi_device *device; struct qmi_service *dms; struct qmi_service *wda; + struct ofono_sim *sim; unsigned long features; unsigned int discover_attempts; uint8_t oper_mode; @@ -94,6 +119,28 @@ static void gobi_debug(const char *str, void *user_data) ofono_info("%s%s", prefix, str); } +/*IMEI CALLBACK*/ +static void gobi_get_ids_cb(struct qmi_result *result, void *user_data) +{ + char *str; + struct cb_data *cbd = user_data; + ofono_devinfo_query_cb_t cb = cbd->cb; + + str = qmi_result_get_string(result, QMI_DMS_RESULT_ESN); + if (!str || strcmp(str, "0") == 0) { + str = qmi_result_get_string(result, QMI_DMS_RESULT_IMEI); + if (!str) { + CALLBACK_WITH_FAILURE(cb, NULL, cbd->data); + return; + } else { + ofono_info("Got IMEI %s", str); + l_strlcpy(imei, str, sizeof(imei)); + gobi_slot_driver_startup_check(); + } + } + qmi_free(str); +} + static int gobi_probe(struct ofono_modem *modem) { struct gobi_data *data; @@ -119,6 +166,11 @@ static int gobi_probe(struct ofono_modem *modem) ofono_modem_set_data(modem, data); ofono_modem_set_capabilities(modem, OFONO_MODEM_CAPABILITY_LTE); + if (!global_modem) { + global_modem = modem; + } + + gobi_slot_plugin_start(gobi_ofono_slot_driver); return 0; } @@ -146,6 +198,8 @@ static void gobi_remove(struct ofono_modem *modem) cleanup_services(data); + ofono_slot_driver_unregister(gobi_ofono_slot_driver); + qmi_device_free(data->device); l_free(data); @@ -310,6 +364,11 @@ static void get_data_format_cb(struct qmi_result *result, void *user_data) } done: + + /*Get modem IMEI*/ + qmi_service_send(data->dms, QMI_DMS_GET_IDS, NULL, + gobi_get_ids_cb, modem, NULL); + if (qmi_service_send(data->dms, QMI_DMS_GET_CAPS, NULL, get_caps_cb, modem, NULL) > 0) return; @@ -635,7 +694,7 @@ static void gobi_pre_sim(struct ofono_modem *modem) sim_driver = "qmimodem_legacy"; if (sim_driver) - ofono_sim_create(modem, 0, sim_driver, data->device); + data->sim = ofono_sim_create(modem, 0, sim_driver, data->device); if (data->features & GOBI_VOICE) ofono_voicecall_create(modem, 0, "qmimodem", data->device); @@ -643,6 +702,8 @@ static void gobi_pre_sim(struct ofono_modem *modem) if (data->features & GOBI_PDS) ofono_location_reporting_create(modem, 0, "qmimodem", data->device); + + gobi_slot_set_sim_state(data->sim); } static void gobi_setup_gprs(struct ofono_modem *modem) @@ -742,6 +803,8 @@ static void gobi_post_sim(struct ofono_modem *modem) if (data->features & GOBI_WDS) gobi_setup_gprs(modem); + + gobi_slot_set_sim_state(data->sim); } static void gobi_post_online(struct ofono_modem *modem) @@ -764,6 +827,131 @@ static void gobi_post_online(struct ofono_modem *modem) } } +// ========== Slot Driver ========== + +static GobiPlugin *gobi_slot_driver_init(struct ofono_slot_manager *m) +{ + DBG("gobi_slot_driver_init"); + + GobiPlugin *plugin = l_new(GobiPlugin, 1); + plugin->slot_manager = m; + + GobiSlot *slot = l_new(GobiSlot, 1); + plugin->slots = l_queue_new(); + l_queue_push_tail(plugin->slots, slot); + + global_plugin = plugin; + return plugin; +} + +static void gobi_slot_set_sim_state(struct ofono_sim *sim) +{ + DBG("gobi_slot_set_sim_state"); + + if (!sim) { + DBG("No SIM"); + return; + } + + GobiSlot *slot = NULL; + slot = (GobiSlot *)l_queue_peek_head(global_plugin->slots); + + if (!slot) { + DBG("No slot yet"); + return; + } + + enum ofono_sim_state state = ofono_sim_get_state(sim); + enum ofono_slot_sim_presence p = OFONO_SLOT_SIM_UNKNOWN; + + switch (state) { + case OFONO_SIM_STATE_INSERTED: + case OFONO_SIM_STATE_READY: + p = OFONO_SLOT_SIM_PRESENT; + break; + case OFONO_SIM_STATE_NOT_PRESENT: + p = OFONO_SLOT_SIM_ABSENT; + break; + case OFONO_SIM_STATE_LOCKED_OUT: + case OFONO_SIM_STATE_RESETTING: + p = OFONO_SLOT_SIM_UNKNOWN; + break; + } + ofono_slot_set_sim_presence(slot->handle, p); +} + +static void gobi_slot_driver_startup_check() +{ + static bool _started = false; + DBG("gobi_slot_driver_startup_check"); + + if (_started) { + return; + } + + if (!global_plugin) { + DBG("No global plugin yet"); + return; + } + + GobiSlot *slot = NULL; + slot = (GobiSlot *)l_queue_peek_head(global_plugin->slots); + + if (!slot) { + DBG("No slot yet"); + return; + } + + if (!slot->modem) { + slot->modem = global_modem; + } + l_strlcpy(slot->imei, imei, sizeof(slot->imei) ); + + slot->handle = ofono_slot_add(global_plugin->slot_manager, + ofono_modem_get_path(slot->modem), (OFONO_RADIO_ACCESS_MODE_GSM | OFONO_RADIO_ACCESS_MODE_UMTS | OFONO_RADIO_ACCESS_MODE_LTE), + slot->imei, "00", + OFONO_SLOT_SIM_UNKNOWN, + OFONO_SLOT_NO_FLAGS); + + ofono_slot_driver_started(gobi_ofono_slot_driver); + _started = true; +} + +static uint gobi_slot_driver_start(GobiPlugin *plugin) +{ + DBG("gobi_slot_driver_start"); + return 1; +} + +static void gobi_slot_driver_cancel(GobiPlugin *plugin, uint id) +{ + DBG("gobi_slot_driver_cancel"); +} + +static void gobi_slot_driver_cleanup(GobiPlugin *plugin) +{ + DBG("gobi_slot_driver_cleanup"); + l_queue_destroy(plugin->slots, l_free); + l_free(plugin); +} + +static bool gobi_slot_plugin_start(void *user_data) +{ + ofono_info("gobi_slot_plugin_start"); + static const struct ofono_slot_driver gobi_slot_driver = { + .name = "gobi_slot", + .api_version = OFONO_SLOT_API_VERSION, + .init = gobi_slot_driver_init, + .start = gobi_slot_driver_start, + .cancel = gobi_slot_driver_cancel, + .cleanup = gobi_slot_driver_cleanup, + }; + + /* Register the driver */ + gobi_ofono_slot_driver = ofono_slot_driver_register(&gobi_slot_driver); + return true; +} + static struct ofono_modem_driver gobi_driver = { .probe = gobi_probe, .remove = gobi_remove,