From 5f87d1a569c38fbac474d03bb3fe8348c0ee4aa5 Mon Sep 17 00:00:00 2001 From: Caiwen Zhang Date: Fri, 15 Mar 2013 11:42:38 +0800 Subject: [PATCH] s-modem: replace "+XSIM:" unsolicited message handling with SIM status notification TNOTI_SIM_STATUS handling. Change-Id: I5eb03a48431fe98afd808d3cc44e185d0a0c1570 --- src/s_modem.c | 51 ++++++++++++++++++--------------------------------- 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/src/s_modem.c b/src/s_modem.c index 530db2f..f73b495 100644 --- a/src/s_modem.c +++ b/src/s_modem.c @@ -99,7 +99,7 @@ typedef struct { static void prepare_and_send_pending_request(CoreObject *co, const char *at_cmd, const char *prefix, enum tcore_at_command_type at_cmd_type, TcorePendingResponseCallback callback); -static void on_confirmation_modem_message_send(TcorePending *p, gboolean result, void *user_data); // from Kernel +static void on_confirmation_modem_message_send(TcorePending *p, gboolean result, void *user_data); static void on_response_network_registration(TcorePending *p, int data_len, const void *data, void *user_data); static void on_response_enable_proactive_command(TcorePending *p, int data_len, const void *data, void *user_data); @@ -398,41 +398,27 @@ OUT: return; } -static gboolean on_event_bootup_sim_status(CoreObject *o, const void *event_info, void *user_data) +static enum tcore_hook_return on_hook_sim_status(Server *s, CoreObject *source, enum tcore_notification_command command, + unsigned int data_len, void *data, void *user_data) { - GSList *tok = NULL; - GSList *lines = NULL; - int value = -1; - char *line = NULL; - - lines = (GSList *) event_info; - if (1 != g_slist_length(lines)) { - dbg("unsolicited msg but multiple line"); - goto OUT; + const struct tnoti_sim_status *sim = data; + CoreObject *co_sat; + CoreObject *co_network; + TcorePlugin *plugin = tcore_object_ref_plugin(source); + + co_sat = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_SAT); + co_network = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_NETWORK); + + if (sim->sim_status == SIM_STATUS_INIT_COMPLETED) { + dbg("SIM ready for attach"); + dbg("Enable STK and Fetching of proactive Commands"); + prepare_and_send_pending_request(co_sat, "AT+CFUN=6", NULL, TCORE_AT_NO_RESULT, on_response_enable_proactive_command); + prepare_and_send_pending_request(co_network, "AT+COPS=0", NULL, TCORE_AT_NO_RESULT, on_response_network_registration); } - line = (char *) (lines->data); - dbg("on_bootup_event_sim_status notification : %s", line); - - tok = tcore_at_tok_new(line); - value = atoi(g_slist_nth_data(tok, 0)); - - if (7 == value) { - dbg("SIM ready. request COPS & remove callback"); - dbg("power on done set for proactive command receiving mode"); - prepare_and_send_pending_request(o, "AT+CFUN=6", NULL, TCORE_AT_NO_RESULT, on_response_enable_proactive_command); - prepare_and_send_pending_request(o, "AT+COPS=0", NULL, TCORE_AT_NO_RESULT, on_response_network_registration); - return FALSE; - } - -OUT: - if (tok != NULL) - tcore_at_tok_free(tok); - return TRUE; + return TCORE_HOOK_RETURN_CONTINUE; } - - gboolean modem_power_on(TcorePlugin *p) { CoreObject *co_modem = NULL; @@ -622,8 +608,7 @@ gboolean s_modem_init(TcorePlugin *cp, CoreObject *co_modem) sn_property = g_try_new0(TelMiscSNInformation, 1); tcore_plugin_link_property(cp, "SN", sn_property); - dbg("Registering for +XSIM event"); - tcore_object_override_callback(co_modem, "+XSIM", on_event_bootup_sim_status, NULL); + tcore_server_add_notification_hook(tcore_plugin_ref_server(cp), TNOTI_SIM_STATUS, on_hook_sim_status, co_modem); dbg("Exit"); -- 2.7.4