diff options
author | Kim Tommy Humborstad <kim.tommy.humborstad@stericsson.com> | 2011-06-01 16:16:27 +0200 |
---|---|---|
committer | Sverre Vegge <sverre.vegge@stericsson.com> | 2011-08-02 22:11:21 +0200 |
commit | 844cff457535424575aa4d796612e618ee8f4ea2 (patch) | |
tree | 613283f4d2547185713342492817c206ea2d8fa0 | |
parent | 8e97d24a6bf1056f7cf6832414998bb3e4afb4d3 (diff) | |
download | u300-844cff457535424575aa4d796612e618ee8f4ea2.tar.gz |
Manager: Code moved from RIL_Init beacuse it needs to return immediatly
* Netlink interface setup moved from RIL_Init to manager thread. Also
all waiting loops for dbus and MID "on" message moved to manager thread.
This was requred to not hold RIL_Init any longer than nessasary so that
RIL daemon can connect to Android framework.
* Enabling of SAT in initializeDefault removed.
Signed-off-by: Sverre Vegge <sverre.vegge@stericsson.com>
-rw-r--r-- | u300-ril-manager.c | 288 | ||||
-rw-r--r-- | u300-ril-stk.c | 13 | ||||
-rw-r--r-- | u300-ril-stk.h | 2 | ||||
-rw-r--r-- | u300-ril.c | 3 |
4 files changed, 143 insertions, 163 deletions
diff --git a/u300-ril-manager.c b/u300-ril-manager.c index 1ec1818..1a959aa 100644 --- a/u300-ril-manager.c +++ b/u300-ril-manager.c @@ -99,6 +99,43 @@ static pthread_mutex_t s_dbus_watch_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_t s_tid_dbusRunner; #define UNUSED(expr) do { (void)(expr); } while (0) +#ifndef CAIF_SOCKET_SUPPORT_DISABLED +static bool createNetworkInterface(const char *ifname, int connection_id) +{ + int ret; + int ifindex = -1; + char loop = 0; + char ifnamecpy[MAX_IFNAME_LEN]; + bool success = true; + + strncpy(ifnamecpy, ifname, MAX_IFNAME_LEN); + ifnamecpy[MAX_IFNAME_LEN - 1] = '\0'; + + ret = rtnl_create_caif_interface(IFLA_CAIF_IPV4_CONNID, connection_id, + ifnamecpy, &ifindex, loop); + if (!ret) + LOGI("%s() created CAIF net-interface: Name = %s, connection ID = %d, " + "Index = %d", __func__, ifnamecpy, connection_id, ifindex); + else if (ret == -EEXIST) /* Use the existing interface, NOT an error. */ + LOGI("%s() found existing CAIF net-interface with same name, reusing: " + "Name = %s, connection ID = %d, Index = %d", + __func__, ifnamecpy, connection_id, ifindex ); + else { + LOGE("%s() failed creating CAIF net-interface. errno: %d (%s)!", + __func__, errno, strerror(errno)); + success = false; + } + + if (strncmp(ifnamecpy, ifname, MAX_IFNAME_LEN) != 0) { + LOGE("%s() did not get required interface name. Suggested %s but got " + "%s. This is considered an error.", __func__, ifname, ifnamecpy); + success = false; + } + + return success; +} +#endif + /* MID signal message handler */ static DBusHandlerResult midSignalHandler(DBusConnection *dbcon, DBusMessage *msg, void *data) @@ -498,6 +535,112 @@ static void *managerRunner(void *param) pthread_t s_tid_queueRunner[RIL_MAX_NR_OF_CHANNELS]; struct queueArgs *queueArgs[RIL_MAX_NR_OF_CHANNELS] = { NULL, NULL }; +#ifndef EXTERNAL_MODEM_CONTROL_MODULE_DISABLED + /***************************************************** + * Loop until we have connection to Dbus daemon * + *****************************************************/ + DBusError dbusErr; + DBusConnection *dbcon = NULL; + bool dbusIsHere = false; + + /* Initial shutdown flag when Dbus enabled*/ + g_shutdownCompleted = false; + + /* Connect to system dbus */ + do { + dbus_error_init(&dbusErr); + dbcon = dbus_bus_get(DBUS_BUS_SYSTEM, &dbusErr); + + if (!dbcon || dbus_error_is_set(&dbusErr)) { + LOGI("[DBUS]: connect to DBUS daemon returned error (%s).Will try" + " again in %d second(s)", dbusErr.name, DBUS_CONNECT_DELAY); + dbus_error_free(&dbusErr); + sleep(DBUS_CONNECT_DELAY); + } else + dbusIsHere = true; + } while (!dbusIsHere); + + LOGI("[DBUS]: Connected to system dbus."); + ret = pthread_attr_init(&attr); + if (ret != 0) + LOGW("%s(): Failed to initialize dbus pthread attribute: %s", + __func__, strerror(ret)); + + ret = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + if (ret != 0) + LOGW("%s(): Failed to set the dbus PTHREAD_CREATE_DETACHED " + "attribute: %s", __func__, strerror(ret)); + + /************************************************* + * Configure Dbus Connection. * + *************************************************/ + if (!dbus_connection_set_watch_functions(dbcon, addWatch, + removeWatch, NULL, NULL, NULL)) { + LOGE("%s(): dbus_connection_set_watch_functions failed.", __func__); + } + + dbus_error_init(&dbusErr); + /* + * Adds a match rule to match messages going through the message bus + * Listen only signal from com.stericsson.mid.Modem interface (MID + * state changes) + */ + dbus_bus_add_match(dbcon, + "type='signal', interface='com.stericsson.mid.Modem'", &dbusErr); + if (dbus_error_is_set(&dbusErr)) { + LOGE("%s(): DBUS match error %s: %s.", __func__, + dbusErr.name, dbusErr.message); + dbus_error_free(&dbusErr); + } + + /* Add a message filter to process incoming messages */ + if (!dbus_connection_add_filter(dbcon, + (DBusHandleMessageFunction)midSignalHandler, NULL, NULL)) { + LOGE("%s(): DBUS filter error.", __func__); + } + + /********************************************************** + * Need to be sure CAIF interfaces are up. Wait for * + * "on" message, and release command threads immediately. * + * ToDo: Add mutex, and wait for 'on' instead. * + **********************************************************/ + while (!queryModemOn(dbcon)) + sleep(DBUS_CONNECT_DELAY); + + ret = pthread_create(&s_tid_dbusRunner, &attr, + dbusAndThreadRunner, (void *)dbcon); + if (ret != 0) { + LOGE("%s(): Failed to create dbus runner thread: %s. Asserting." + , __func__, strerror(ret)); + assert(0); + } +#endif /* EXTERNAL_MODEM_CONTROL_MODULE_DISABLED */ + + /* Modem is up. QueueRunners can start directly. */ + releaseCommandThreads(); + +#ifndef CAIF_SOCKET_SUPPORT_DISABLED + /********************************************** + * Create CAIF interfaces for PDP contexts * + **********************************************/ + if (strncasecmp(mgrArgs.type, "CAIF", 4) == 0) { + for (i = 0; i < RIL_MAX_NUMBER_OF_PDP_CONTEXTS; i++) { + char ifaceName[MAX_IFNAME_LEN]; + snprintf(ifaceName, MAX_IFNAME_LEN, "%s%d", ril_iface, i); + if (!createNetworkInterface(ifaceName, i + RIL_FIRST_CID_INDEX)) { + LOGE("%s(): Failed to create Caif interface. Asserting." + , __func__); + assert(0); + } + } + } +#else + if (mgrArgs.type == NULL || strcmp(mgrArgs.type, "") == 0) { + LOGE("%s(): AT/Data channel type was not supplied!", __func__); + assert(0); + } +#endif + for(;;) { ret = 0; @@ -566,7 +709,6 @@ static void *managerRunner(void *param) __func__); #ifndef EXTERNAL_MODEM_CONTROL_MODULE_DISABLED - DBusConnection *dbcon = (DBusConnection *)param; char responseArray[BUF_MID_RESPONSE_SIZE]; char *pResponse = responseArray; @@ -599,43 +741,6 @@ static void *managerRunner(void *param) return NULL; } -#ifndef CAIF_SOCKET_SUPPORT_DISABLED -static bool createNetworkInterface(const char *ifname, int connection_id) -{ - int ret; - int ifindex = -1; - char loop = 0; - char ifnamecpy[MAX_IFNAME_LEN]; - bool success = true; - - strncpy(ifnamecpy, ifname, MAX_IFNAME_LEN); - ifnamecpy[MAX_IFNAME_LEN - 1] = '\0'; - - ret = rtnl_create_caif_interface(IFLA_CAIF_IPV4_CONNID, connection_id, - ifnamecpy, &ifindex, loop); - if (!ret) - LOGI("%s() created CAIF net-interface: Name = %s, connection ID = %d, " - "Index = %d", __func__, ifnamecpy, connection_id, ifindex); - else if (ret == -EEXIST) /* Use the existing interface, NOT an error. */ - LOGI("%s() found existing CAIF net-interface with same name, reusing: " - "Name = %s, connection ID = %d, Index = %d", - __func__, ifnamecpy, connection_id, ifindex ); - else { - LOGE("%s() failed creating CAIF net-interface. errno: %d (%s)!", - __func__, errno, strerror(errno)); - success = false; - } - - if (strncmp(ifnamecpy, ifname, MAX_IFNAME_LEN) != 0) { - LOGE("%s() did not get required interface name. Suggested %s but got " - "%s. This is considered an error.", __func__, ifname, ifnamecpy); - success = false; - } - - return success; -} -#endif - static void usage(char *s) { fprintf(stderr, "usage: %s [-c <connection type>]" @@ -730,113 +835,12 @@ const RIL_RadioFunctions *RIL_Init(const struct RIL_Env *env, int argc, strcpy(ril_iface, "rmnet"); } -#ifndef EXTERNAL_MODEM_CONTROL_MODULE_DISABLED - /***************************************************** - * Loop until we have connection to Dbus daemon * - *****************************************************/ - DBusError dbusErr; - DBusConnection *dbcon = NULL; - bool dbusIsHere = false; - - /* Initial shutdown flag when Dbus enabled*/ - g_shutdownCompleted = false; - - /* Connect to system dbus */ - do { - dbus_error_init(&dbusErr); - dbcon = dbus_bus_get(DBUS_BUS_SYSTEM, &dbusErr); - - if (!dbcon || dbus_error_is_set(&dbusErr)) { - LOGI("[DBUS]: connect to DBUS daemon returned error (%s).Will try" - " again in %d second(s)", dbusErr.name, DBUS_CONNECT_DELAY); - dbus_error_free(&dbusErr); - sleep(DBUS_CONNECT_DELAY); - } else - dbusIsHere = true; - } while (!dbusIsHere); - - LOGI("[DBUS]: Connected to system dbus."); - err = pthread_attr_init(&attr); - if (err != 0) - LOGW("%s(): Failed to initialize dbus pthread attribute: %s", - __func__, strerror(err)); - - err = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - if (err != 0) - LOGW("%s(): Failed to set the dbus PTHREAD_CREATE_DETACHED " - "attribute: %s", __func__, strerror(err)); - - /************************************************* - * Configure Dbus Connection. * - *************************************************/ - if (!dbus_connection_set_watch_functions(dbcon, addWatch, - removeWatch, NULL, NULL, NULL)) { - LOGE("%s(): dbus_connection_set_watch_functions failed.", __func__); - } - - dbus_error_init(&dbusErr); - /* - * Adds a match rule to match messages going through the message bus - * Listen only signal from com.stericsson.mid.Modem interface (MID - * state changes) - */ - dbus_bus_add_match(dbcon, - "type='signal', interface='com.stericsson.mid.Modem'", &dbusErr); - if (dbus_error_is_set(&dbusErr)) { - LOGE("%s(): DBUS match error %s: %s.", __func__, - dbusErr.name, dbusErr.message); - dbus_error_free(&dbusErr); - } - - /* Add a message filter to process incoming messages */ - if (!dbus_connection_add_filter(dbcon, - (DBusHandleMessageFunction)midSignalHandler, NULL, NULL)) { - LOGE("%s(): DBUS filter error.", __func__); - } - - /********************************************************** - * Need to be sure CAIF interfaces are up. Wait for * - * "on" message, and release command threads immediately. * - * ToDo: Add mutex, and wait for 'on' instead. * - **********************************************************/ - while (!queryModemOn(dbcon)) - sleep(DBUS_CONNECT_DELAY); - - err = pthread_create(&s_tid_dbusRunner, &attr, - dbusAndThreadRunner, (void *)dbcon); - if (err != 0) { - LOGE("%s(): Failed to create dbus runner thread: %s. Asserting." - , __func__, strerror(err)); - assert(0); - } -#endif /* EXTERNAL_MODEM_CONTROL_MODULE_DISABLED */ - - /* Modem is up. QueueRunners can start directly. */ - releaseCommandThreads(); - #ifndef CAIF_SOCKET_SUPPORT_DISABLED - /********************************************** - * Create CAIF interfaces for PDP contexts * - **********************************************/ if (mgrArgs.type == NULL || strncasecmp(mgrArgs.type, "", 1) == 0) { LOGW("%s: AT/Data channel type was not supplied." " Falling back to CAIF!", __func__); mgrArgs.type = "CAIF"; } - - if (strncasecmp(mgrArgs.type, "CAIF", 4) == 0) { - for (i = 0; i < RIL_MAX_NUMBER_OF_PDP_CONTEXTS; i++) { - char ifaceName[MAX_IFNAME_LEN]; - snprintf(ifaceName, MAX_IFNAME_LEN, "%s%d", ril_iface, i); - if (!createNetworkInterface(ifaceName, i + RIL_FIRST_CID_INDEX)) - goto error; - } - } -#else - if (mgrArgs.type == NULL || strcmp(mgrArgs.type, "") == 0) { - LOGE("%s(): AT/Data channel type was not supplied!", __func__); - goto error; - } #endif /* Start Manager thread. */ @@ -850,14 +854,8 @@ const RIL_RadioFunctions *RIL_Init(const struct RIL_Env *env, int argc, LOGW("%s(): Failed to set the RIL Manager PTHREAD_CREATE_DETACHED " "attribute: %s", __func__, strerror(err)); -#ifndef EXTERNAL_MODEM_CONTROL_MODULE_DISABLED - err = pthread_create(&s_tid_managerRunner, &attr, - managerRunner, (void *)dbcon); -#else err = pthread_create(&s_tid_managerRunner, &attr, managerRunner, NULL); -#endif /* EXTERNAL_MODEM_CONTROL_MODULE_DISABLED */ - if (err != 0) LOGE("%s(): Failed to create RIL manager runner thread: %s", __func__, strerror(err)); diff --git a/u300-ril-stk.c b/u300-ril-stk.c index 2f12dff..ea58aa3 100644 --- a/u300-ril-stk.c +++ b/u300-ril-stk.c @@ -325,19 +325,6 @@ exit: } /** - * enableStk() enables STK in the modem - */ -void enableStk(void) -{ - if (!s_StkIsRunning && reportStkServiceIsRunning()) { - /* store STK service state in case of later modem restart */ - s_StkIsRunning = true; - } - - return; -} - -/** * RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING * * Turn on STK unsol commands. diff --git a/u300-ril-stk.h b/u300-ril-stk.h index e36ba95..31a3d7f 100644 --- a/u300-ril-stk.h +++ b/u300-ril-stk.h @@ -40,6 +40,4 @@ void onStkSimRefresh(const char *s); void onStkEventNotify(const char *s); void onResetModemStateStk(int resetState); - -void enableStk(void); #endif @@ -1531,9 +1531,6 @@ static bool initializeDefault() else LOGI("[ECC]: SIM is absent, keeping default ECCs"); - /* FIXME: Temporarly workaround to always initiate STK */ - enableStk(); - /* In case of modem restart do a reset on internal RIL state */ if (s_queueRuns > 1) resetModemState(RESET_AT_INITIALIZED); |