From 42f7622c520f2718a61812515ddc1b2793c5ec17 Mon Sep 17 00:00:00 2001 From: Dongchul Lim Date: Mon, 19 May 2014 19:52:52 +0900 Subject: [PATCH] IMC plugin update 1. [Phonebook, SAP] Error mapping 2. [Call, SS, SMS SIM & Network] Error mapping 3. [Modem] Error mapping 4. Prevent issues fix 5. [SAT, SIM] Error mapping 6. [SIM] SPN information set into VCONF 7. [SIM] Updated Set MailboxInfo 8. Header files unification 9. [SMS] code cleanup 10.[Network]fix for memory leak 11.[SIM]fix for memory leak Change-Id: I8421351d22bbb938ad3ab60cd2c00fa48d6a000a --- CMakeLists.txt | 2 +- include/tel-plugin-imc.manifest | 11 - packaging/tel-plugin-imc.spec | 1 + src/desc-imc.c | 8 +- src/imc_call.c | 388 ++++++++++-- src/imc_modem.c | 78 ++- src/imc_network.c | 90 ++- src/imc_phonebook.c | 78 ++- src/imc_sap.c | 66 +- src/imc_sat.c | 103 +++- src/imc_sim.c | 396 +++++++++--- src/imc_sms.c | 1303 +++++++++++++++++++++++---------------- src/imc_ss.c | 121 +++- src/nvm/nvm.c | 21 +- 14 files changed, 1891 insertions(+), 775 deletions(-) delete mode 100644 include/tel-plugin-imc.manifest diff --git a/CMakeLists.txt b/CMakeLists.txt index 34749de..0644560 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ SET(INCLUDEDIR "\${prefix}/include") # Set required packages INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs REQUIRED glib-2.0 tcore db-util libxml-2.0 libtzplatform-config vconf) +pkg_check_modules(pkgs REQUIRED glib-2.0 tcore tel-headers db-util libxml-2.0 libtzplatform-config vconf) FOREACH(flag ${pkgs_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") diff --git a/include/tel-plugin-imc.manifest b/include/tel-plugin-imc.manifest deleted file mode 100644 index 143fb79..0000000 --- a/include/tel-plugin-imc.manifest +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/packaging/tel-plugin-imc.spec b/packaging/tel-plugin-imc.spec index 6ebea56..d91d2fa 100644 --- a/packaging/tel-plugin-imc.spec +++ b/packaging/tel-plugin-imc.spec @@ -16,6 +16,7 @@ Requires(postun):/sbin/ldconfig BuildRequires: cmake BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(tcore) +BuildRequires: pkgconfig(tel-headers) BuildRequires: pkgconfig(db-util) BuildRequires: pkgconfig(libxml-2.0) BuildRequires: pkgconfig(libtzplatform-config) diff --git a/src/desc-imc.c b/src/desc-imc.c index f639fc9..281f1a3 100644 --- a/src/desc-imc.c +++ b/src/desc-imc.c @@ -209,16 +209,12 @@ static void __subscribe_modem_notifications(TcorePlugin *plugin) tcore_strdup("AT+XDNS=1,1")); /* CMEE */ - __send_request(ps, "AT+CMEE=2", + __send_request(ps, "AT+CMEE=1", __on_response_subscribe_bootup_notification, - tcore_strdup("AT+CMEE=2")); + tcore_strdup("AT+CMEE=1")); /****** SMS subscriptions ******/ sms = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_SMS); - /* CMEE */ - __send_request(sms, "AT+CMEE=2", - __on_response_subscribe_bootup_notification, - tcore_strdup("AT+CMEE=2")); /* Incoming SMS, Cell Broadcast, Status Report Subscription */ __send_request(sms, "AT+CNMI=1,2,2,1,0", diff --git a/src/imc_call.c b/src/imc_call.c index 4107085..64220d0 100644 --- a/src/imc_call.c +++ b/src/imc_call.c @@ -69,6 +69,9 @@ static void on_response_imc_call_default(TcorePending *p, static TelReturn __call_list_get(CoreObject *co, gboolean flag); +static void __on_response_imc_call_end_cause(TcorePending *p, + guint data_len, const void *data, void *user_data); + static TelCallType __call_type(int type) { dbg("Entry"); @@ -166,7 +169,7 @@ static void __call_branch_by_status(CoreObject *co, CallObject *call_obj, case TEL_CALL_STATE_INCOMING: case TEL_CALL_STATE_WAITING: { TelCallIncomingInfo incoming = {0,}; - command = TCORE_NOTIFICATION_CALL_STATUS_INCOMING; + incoming.call_id = call_id; tcore_call_object_get_cli_validity(call_obj, &incoming.cli_validity); tcore_call_object_get_number(call_obj, incoming.number); @@ -176,22 +179,41 @@ static void __call_branch_by_status(CoreObject *co, CallObject *call_obj, tcore_call_object_get_active_line(call_obj, &incoming.active_line); /* Send notification */ - tcore_object_send_notification(co, command, + tcore_object_send_notification(co, + TCORE_NOTIFICATION_CALL_STATUS_INCOMING, sizeof(TelCallIncomingInfo), &incoming); return; } case TEL_CALL_STATE_IDLE: { - TelCallStatusIdleNoti idle; - command = TCORE_NOTIFICATION_CALL_STATUS_IDLE; - idle.call_id = call_id; + /* Send AT+CEER command*/ + ImcRespCbData *resp_cb_data = NULL; + TelReturn ret; - /* TODO - get proper call end cause. */ - idle.cause = TEL_CALL_END_CAUSE_NONE; + /* Response callback data */ + resp_cb_data = imc_create_resp_cb_data(NULL, NULL, &call_id, sizeof(call_id)); - /* Send notification */ - tcore_object_send_notification(co, command, - sizeof(TelCallStatusIdleNoti), &idle); + /* Send Request to modem */ + ret = tcore_at_prepare_and_send_request(co, + "AT+CEER", "+CEER:", + TCORE_AT_COMMAND_TYPE_SINGLELINE, + NULL, + __on_response_imc_call_end_cause, resp_cb_data, + on_send_imc_request, NULL); + if (ret != TEL_RETURN_SUCCESS) { + warn("Failed to send request"); + TelCallStatusIdleNoti idle; + + idle.call_id = call_id; + idle.cause = TEL_CALL_END_CAUSE_NONE; + + /* Send notification */ + tcore_object_send_notification(co, + TCORE_NOTIFICATION_CALL_STATUS_IDLE, + sizeof(TelCallStatusIdleNoti), &idle); + + imc_destroy_resp_cb_data(resp_cb_data); + } /* Free Call object */ tcore_call_object_free(co, call_obj); @@ -226,14 +248,13 @@ static void __call_branch_by_status(CoreObject *co, CallObject *call_obj, case TEL_CALL_STATE_IDLE: { TelCallStatusIdleNoti idle; - command = TCORE_NOTIFICATION_VIDEO_CALL_STATUS_IDLE; - idle.call_id = call_id; - /* TODO - get proper call end cause. */ + idle.call_id = call_id; idle.cause = TEL_CALL_END_CAUSE_NONE; /* Send notification */ - tcore_object_send_notification(co, command, + tcore_object_send_notification(co, + TCORE_NOTIFICATION_VIDEO_CALL_STATUS_IDLE, sizeof(TelCallStatusIdleNoti), &idle); /* Free Call object */ @@ -241,8 +262,7 @@ static void __call_branch_by_status(CoreObject *co, CallObject *call_obj, return; } } - } - else { + } else { err("Unknown Call type: [%d]", call_type); } @@ -257,7 +277,7 @@ static void __handle_call_list_get(CoreObject *co, gboolean flag, void *data) int call_type; int state; int mpty; - int ton; + int ton = -1; GSList *tokens = NULL; char *resp = NULL; char *line; @@ -471,7 +491,7 @@ static void __on_response_imc_call_list_get(TcorePending *p, guint data_len, con CoreObject *co = tcore_pending_ref_core_object(p); ImcRespCbData *resp_cb_data = user_data; GSList *lines = NULL; - TelCallResult result = TEL_CALL_RESULT_FAILURE; //TODO - CME error mapping required + TelCallResult result = TEL_CALL_RESULT_FAILURE; gboolean *flag = IMC_GET_DATA_FROM_RESP_CB_DATA(resp_cb_data); int count; dbg("entry"); @@ -568,26 +588,163 @@ static TelReturn __call_list_get(CoreObject *co, gboolean flag) return ret; } +static TelCallResult __convert_imc_extended_err_tel_call_result(gint error) +{ + /* + * CEER error codes + * 1 - unassigned (unallocated) number. + * 28 - invalid number format (incomplete number). + * 96 - invalid mandatory information. + * 258 - Invalid parameters. + * 371 - Invalid mandatory info. + * 257 - Out of memory. + * 279 - FDN Failed. + * 42 - switching equipment congestion + * 287 - MM network failure unspecified. + * 380 - Congestion. + */ + dbg("CEER Error: [%d]", error); + + switch (error) { + case 1: + case 28: + case 96: + case 258: + case 371: + return TEL_CALL_RESULT_INVALID_PARAMETER; + case 257: + return TEL_CALL_RESULT_MEMORY_FAILURE; + case 279: + return TEL_CALL_RESULT_FDN_RESTRICTED; + case 42: + case 287: + case 380: + return TEL_CALL_RESULT_NETWORK_BUSY; + default: + return TEL_CALL_RESULT_FAILURE; + } +} + +static TelCallEndCause __convert_imc_extended_err_call_end_cause(gint error) +{ + /* + * CEER error codes + * 1 - unassigned (unallocated) number. + * 3 - No route to destination. + * 16 - operator determined barring. + * 17 - user busy. + * 18 - no user responding. + * 19 - user alerting, no answer. + * 21 - call rejected. + * 22 - number changed + * 27 - destination out of order. + * 28 - invalid number format (incomplete number). + * 29 - facility rejected + * 34 - no circuit / channel available. + * 38 - network out of order + * 41 - temporary failure + * 44 - requested circuit / channel not available. + * 50 - requested facility not subscribed + * 68 - ACM equal to or greater than ACMmax + */ + dbg("Call end-cause: [%d]", error); + switch (error) { + case 1: + return TEL_CALL_END_CAUSE_UNASSIGNED_NUMBER; + case 3: + return TEL_CALL_END_CAUSE_NO_ROUTE_TO_DEST; + case 8: + return TEL_CALL_END_CAUSE_OPERATOR_DETERMINED_BARRING; + case 16: + return TEL_CALL_END_CAUSE_NORMAL_CALL_CLEARING; + case 17: + return TEL_CALL_END_CAUSE_USER_BUSY; + case 18: + return TEL_CALL_END_CAUSE_NO_USER_RESPONDING; + case 19: + return TEL_CALL_END_CAUSE_USER_ALERTING_NO_ANSWER; + case 21: + return TEL_CALL_END_CAUSE_CALL_REJECTED; + case 22: + return TEL_CALL_END_CAUSE_NUMBER_CHANGED; + case 27: + return TEL_CALL_END_CAUSE_DESTINATION_OUT_OF_ORDER; + case 28: + return TEL_CALL_END_CAUSE_INVALID_NUMBER_FORMAT; + case 29: + return TEL_CALL_END_CAUSE_FACILITY_REJECTED; + case 34: + return TEL_CALL_END_CAUSE_NO_CIRCUIT_CHANNEL_AVAILABLE; + case 38: + return TEL_CALL_END_CAUSE_NETWORK_OUT_OF_ORDER; + case 41: + return TEL_CALL_END_CAUSE_TEMPORARY_FAILURE; + case 42: + return TEL_CALL_END_CAUSE_SWITCHING_EQUIPMENT_CONGESTION; + case 44: + return TEL_CALL_END_CAUSE_REQUESTED_CIRCUIT_CHANNEL_NOT_AVAILABLE; + case 50: + return TEL_CALL_END_CAUSE_REQUESTED_FACILITY_NOT_SUBSCRIBED; + case 68: + return TEL_CALL_END_CAUSE_ACM_GEQ_ACMMAX; + case 63: + case 79: + return TEL_CALL_END_CAUSE_SERVICE_OPTION_OUT_OF_ORDER; + default: + return TEL_CALL_END_CAUSE_FAILED; + } +} + +static TelCallResult __convert_imc_xdrv_result_tel_call_result(gint xdrv_err) +{ + /* + * 0 - Command was executed without any error. + * 1 - One of the parameters is out of range. + * 2 - The function doesn’t exist for this driver. + * 3 - The group is not supported. + * 4 - The internal state of the driver is not allowing to process the command. + * 5 - The driver interface function for the command is not available. + * 6 - The corresponding driver for the command retuns an error. + * 7 - Timeout occured when expecting response from the corresponding driver. + * 8 - The driver is not supported for this product. + * 12 - No of parameteres passed for the command is mismatch with the rquirements. + * 13 - The given command to xdrv is invalid. + * 14 - Any internal error in xdrv like out of memory. + */ + + dbg("XDRV result: [%d]", xdrv_err); + switch (xdrv_err) { + case 1: + case 12: + case 13: + return TEL_CALL_RESULT_INVALID_PARAMETER; + case 14: + return TEL_CALL_RESULT_MEMORY_FAILURE; + default: + return TEL_CALL_RESULT_OPERATION_NOT_SUPPORTED; + } +} + /* Notification */ /* -* Operation - call status notification from network. -* notification message format: -* +XCALLSTAT: -* where -* -* indicates the call identification (GSM02.30 4.5.5.1) -* -* 0 active -* 1 hold -* 2 dialling (MO call) -* 3 alerting (MO call; ringing for the remote party) -* 4 ringing (MT call) -* 5 waiting (MT call) -* 6 disconnected -* 7 connected (indicates the completion of a call setup first time for MT and MO calls -* this is reported in addition to state active) -*/ + * Operation - call status notification from network. + * notification message format: + * +XCALLSTAT: + * where + * + * indicates the call identification (GSM02.30 4.5.5.1) + * + * 0 active + * 1 hold + * 2 dialling (MO call) + * 3 alerting (MO call; ringing for the remote party) + * 4 ringing (MT call) + * 5 waiting (MT call) + * 6 disconnected + * 7 connected (indicates the completion of a call setup first time + * for MT and MO calls this is reported in addition to state active) + */ static gboolean on_notification_imc_call_status(CoreObject *co, const void *data, void *user_data) { @@ -846,6 +1003,132 @@ static gboolean on_notification_imc_call_clip_info(CoreObject *co, const void *d } /* Response */ +static void __on_response_imc_call_handle_error_report(TcorePending *p, + guint data_len, const void *data, void *user_data) +{ + const TcoreAtResponse *at_resp = data; + CoreObject *co = tcore_pending_ref_core_object(p); + ImcRespCbData *resp_cb_data = user_data; + TelCallResult result = TEL_CALL_RESULT_FAILURE; + GSList *tokens = NULL; + dbg("entry"); + + tcore_check_return_assert(co != NULL); + tcore_check_return_assert(resp_cb_data != NULL); + + if (at_resp && at_resp->success) { + GSList *resp_data = NULL; + gchar *resp_str; + gint error; + + resp_data = at_resp->lines; + if (!resp_data) { + err("invalid response data received"); + goto OUT; + } + + tokens = tcore_at_tok_new(resp_data->data); + resp_str = g_slist_nth_data(tokens, 0); + if (!resp_str) { + err("In extended error report - missing"); + goto OUT; + } + dbg("category[%s]", resp_str); + + resp_str = g_slist_nth_data(tokens, 1); + if (!resp_str) { + err("In extended error report - missing"); + goto OUT; + } + error = atoi(resp_str); + dbg("Cause: [%d] description: [%s]", error, g_slist_nth_data(tokens, 2)); + + result = __convert_imc_extended_err_tel_call_result(error); + dbg("result: [%d]", result); + } else { + err("Response - [NOK]"); + } +OUT: + + dbg("%s: [%s]", IMC_GET_DATA_FROM_RESP_CB_DATA(resp_cb_data), + (result == TEL_CALL_RESULT_SUCCESS ? "SUCCESS" : "FAIL")); + + /* Invoke callback */ + if (resp_cb_data->cb) + resp_cb_data->cb(co, (gint)result, NULL, resp_cb_data->cb_data); + + /* Free callback data */ + imc_destroy_resp_cb_data(resp_cb_data); + + /* Free tokens*/ + tcore_at_tok_free(tokens); +} + +static void __on_response_imc_call_end_cause(TcorePending *p, + guint data_len, const void *data, void *user_data) +{ + const TcoreAtResponse *at_resp = data; + CoreObject *co = tcore_pending_ref_core_object(p); + ImcRespCbData *resp_cb_data = user_data; + TelCallStatusIdleNoti idle; + TcoreNotification command; + TelCallEndCause cause = TEL_CALL_END_CAUSE_NONE; + guint *call_id; + GSList *tokens = NULL; + + dbg("entry"); + + tcore_check_return_assert(co != NULL); + tcore_check_return_assert(resp_cb_data != NULL); + call_id = IMC_GET_DATA_FROM_RESP_CB_DATA(resp_cb_data); + + if (at_resp && at_resp->success) { + GSList *resp_data = NULL; + gchar *resp_str; + gint error; + + resp_data = at_resp->lines; + if (!resp_data) { + err("invalid response data received"); + goto OUT; + } + tokens = tcore_at_tok_new(resp_data->data); + resp_str = g_slist_nth_data(tokens, 0); + if (!resp_str) { + err("In extended error report - missing"); + goto OUT; + } + dbg("category[%s]", resp_str); + resp_str = g_slist_nth_data(tokens, 1); + if (!resp_str) { + err("In extended error report - missing"); + goto OUT; + } + error = atoi(resp_str); + dbg("cause: [%d] description: [%s]", error, g_slist_nth_data(tokens, 2)); + + cause = __convert_imc_extended_err_call_end_cause(error); + dbg("cause: [%d]", cause); + + } else { + err("RESPONSE - [NOK]"); + } +OUT: + command = TCORE_NOTIFICATION_CALL_STATUS_IDLE; + idle.call_id = *call_id; + + idle.cause = cause; + + /* Send notification */ + tcore_object_send_notification(co, command, + sizeof(TelCallStatusIdleNoti), &idle); + + /* Free callback data */ + imc_destroy_resp_cb_data(resp_cb_data); + + /* Free tokens*/ + tcore_at_tok_free(tokens); +} static void on_response_imc_call_default(TcorePending *p, guint data_len, const void *data, void *user_data) { @@ -862,16 +1145,22 @@ static void on_response_imc_call_default(TcorePending *p, if (at_resp && at_resp->success) { result = TEL_CALL_RESULT_SUCCESS; } else { + TelReturn ret; if(at_resp){ err("ERROR[%s]", at_resp->final_response); - - if(at_resp->lines) - err("CME error[%s]", at_resp->lines->data); } - /* - * TODO - need to map CME error and final - * response error to TelCallResult - */ + + /* Send Request to modem to get extended error report*/ + ret = tcore_at_prepare_and_send_request(co, + "AT+CEER", "+CEER:", + TCORE_AT_COMMAND_TYPE_SINGLELINE, + NULL, + __on_response_imc_call_handle_error_report, resp_cb_data, + on_send_imc_request, NULL); + + + if (ret == TEL_RETURN_SUCCESS) + return; } dbg("%s: [%s]", IMC_GET_DATA_FROM_RESP_CB_DATA(resp_cb_data), @@ -896,7 +1185,6 @@ static void on_response_imc_call_set_volume_info(TcorePending *p, char *resp_str = NULL; gboolean error; - /* TODO: XDRV error mapping required */ TelCallResult result = TEL_CALL_RESULT_FAILURE; dbg("Enter"); @@ -930,6 +1218,7 @@ static void on_response_imc_call_set_volume_info(TcorePending *p, error = atoi(resp_str); if (error) { err("RESPONSE NOK"); + result = __convert_imc_xdrv_result_tel_call_result(error); goto OUT; } @@ -1022,7 +1311,7 @@ static void on_response_imc_call_set_sound_path(TcorePending *p, gboolean error; gint xdrv_func_id = -1; - TelCallResult result = TEL_CALL_RESULT_FAILURE; // TODO: XDRV error mapping is required + TelCallResult result = TEL_CALL_RESULT_FAILURE; dbg("Enter"); tcore_check_return_assert(co != NULL); @@ -1049,6 +1338,7 @@ static void on_response_imc_call_set_sound_path(TcorePending *p, error = atoi(resp_str); if (error) { err("RESPONSE NOK"); + result = __convert_imc_xdrv_result_tel_call_result(error); goto OUT; } @@ -1117,7 +1407,7 @@ static void on_response_imc_call_set_mute(TcorePending *p, guint data_len, char *resp_str = NULL; gboolean error; - TelCallResult result = TEL_CALL_RESULT_FAILURE; // TODO: XDRV error mapping is required + TelCallResult result = TEL_CALL_RESULT_FAILURE; dbg("Enter"); tcore_check_return_assert(co != NULL); @@ -1127,7 +1417,6 @@ static void on_response_imc_call_set_mute(TcorePending *p, guint data_len, line = (((GSList *)at_resp->lines)->data); tokens = tcore_at_tok_new(line); - resp_str = g_slist_nth_data(tokens, 0); if (!g_slist_nth_data(tokens, 0)) { err("group_id missing"); goto OUT; @@ -1138,14 +1427,15 @@ static void on_response_imc_call_set_mute(TcorePending *p, guint data_len, goto OUT; } - resp_str = g_slist_nth_data(tokens, 2); - if (!(resp_str = g_slist_nth_data(tokens, 1))) { + if (!(resp_str = g_slist_nth_data(tokens, 2))) { err("xdrv_result missing"); goto OUT; } + error = atoi(resp_str); - if (!error) { + if (error) { err(" RESPONSE NOK [%d]", error); + result = __convert_imc_xdrv_result_tel_call_result(error); goto OUT; } result = TEL_CALL_RESULT_SUCCESS; diff --git a/src/imc_modem.c b/src/imc_modem.c index 6ae002f..d18215e 100644 --- a/src/imc_modem.c +++ b/src/imc_modem.c @@ -40,6 +40,65 @@ static gboolean on_event_imc_nvm_update(CoreObject *co, const void *event_info, void *user_data); +static TelModemResult +__imc_modem_convert_cme_error_tel_modem_result(const TcoreAtResponse *at_resp) +{ + TelModemResult result = TEL_MODEM_RESULT_FAILURE; + const gchar *line; + GSList *tokens = NULL; + + dbg("Entry"); + + if (!at_resp || !at_resp->lines) { + err("Invalid response data"); + return result; + } + + line = (const gchar *)at_resp->lines->data; + tokens = tcore_at_tok_new(line); + if (g_slist_length(tokens) > 0) { + gchar *resp_str; + gint cme_err; + + resp_str = g_slist_nth_data(tokens, 0); + if (!resp_str) { + err("Invalid CME Error data"); + tcore_at_tok_free(tokens); + return result; + } + cme_err = atoi(resp_str); + dbg("CME error[%d]", cme_err); + + switch (cme_err) { + case 3: + result = TEL_MODEM_RESULT_OPERATION_NOT_PERMITTED; + break; + + case 4: + result = TEL_MODEM_RESULT_OPERATION_NOT_SUPPORTED; + break; + + case 20: + result = TEL_MODEM_RESULT_MEMORY_FAILURE; + break; + + case 50: + result = TEL_MODEM_RESULT_INVALID_PARAMETER; + break; + + case 100: + result = TEL_MODEM_RESULT_UNKNOWN_FAILURE; + break; + + default: + result = TEL_MODEM_RESULT_FAILURE; + } + } + tcore_at_tok_free(tokens); + + return result; +} + /* NVM Req/Response */ static gboolean __imc_modem_check_nvm_response(const void *data, int command) { @@ -334,8 +393,14 @@ static void on_response_imc_modem_set_power_status(TcorePending *p, tcore_check_return_assert(co != NULL); tcore_check_return_assert(resp_cb_data != NULL); - if (at_resp && at_resp->success) + if (at_resp && at_resp->success){ + dbg("RESPONSE OK"); result = TEL_MODEM_RESULT_SUCCESS; + } else{ + err("RESPONSE NOK"); + result = __imc_modem_convert_cme_error_tel_modem_result(at_resp); + goto END; + } status = (TelModemPowerStatus *) IMC_GET_DATA_FROM_RESP_CB_DATA(resp_cb_data); @@ -359,6 +424,7 @@ static void on_response_imc_modem_set_power_status(TcorePending *p, } tcore_modem_set_powered(co, powered); +END: /* Invoke callback */ if (resp_cb_data->cb) resp_cb_data->cb(co, (gint)result, NULL, resp_cb_data->cb_data); @@ -381,8 +447,14 @@ static void on_response_imc_modem_set_flight_mode(TcorePending *p, tcore_check_return_assert(co != NULL); tcore_check_return_assert(resp_cb_data != NULL); - if (at_resp && at_resp->success) + if (at_resp && at_resp->success){ + dbg("RESPONSE OK"); result = TEL_MODEM_RESULT_SUCCESS; + } else{ + err("RESPONSE NOK"); + result = __imc_modem_convert_cme_error_tel_modem_result(at_resp); + goto END; + } enable = (gboolean *)IMC_GET_DATA_FROM_RESP_CB_DATA(resp_cb_data); @@ -393,6 +465,7 @@ static void on_response_imc_modem_set_flight_mode(TcorePending *p, /* Update Core Object */ (void)tcore_modem_set_flight_mode_state(co, *enable); +END: /* Invoke callback */ if (resp_cb_data->cb) resp_cb_data->cb(co, (gint)result, NULL, resp_cb_data->cb_data); @@ -521,6 +594,7 @@ static void on_response_imc_modem_get_imei(TcorePending *p, } else { err("RESPONSE - [NOK]"); err("[%s]", g_slist_nth_data(tokens, 0)); + result = __imc_modem_convert_cme_error_tel_modem_result(at_resp); } } else { err("Invalid response message"); diff --git a/src/imc_network.c b/src/imc_network.c index c5d19ae..e4b9b7c 100644 --- a/src/imc_network.c +++ b/src/imc_network.c @@ -142,6 +142,66 @@ static void __imc_network_register_to_network(CoreObject *co) (ret == TEL_RETURN_SUCCESS ? "SUCCESS" : "FAIL")); } +static TelNetworkResult +__imc_network_convert_cme_error_tel_network_result(const TcoreAtResponse *at_resp) +{ + TelNetworkResult result = TEL_NETWORK_RESULT_FAILURE; + const gchar *line; + GSList *tokens = NULL; + + dbg("Entry"); + + if (!at_resp || !at_resp->lines) { + err("Invalid response data"); + return result; + } + + line = (const gchar *)at_resp->lines->data; + tokens = tcore_at_tok_new(line); + if (g_slist_length(tokens) > 0) { + gchar *resp_str; + gint cme_err; + + resp_str = g_slist_nth_data(tokens, 0); + if (!resp_str) { + err("Invalid CME Error data"); + tcore_at_tok_free(tokens); + return result; + } + cme_err = atoi(resp_str); + dbg("CME error[%d]", cme_err); + + switch (cme_err) { + case 3: + result = TEL_NETWORK_RESULT_OPERATION_NOT_PERMITTED; + break; + + case 4: + result = TEL_NETWORK_RESULT_OPERATION_NOT_SUPPORTED; + break; + + case 20: + result = TEL_NETWORK_RESULT_MEMORY_FAILURE; + break; + + case 30: + case 31: + result = TEL_NETWORK_RESULT_FAILURE; + break; + + case 50: + result = TEL_NETWORK_RESULT_INVALID_PARAMETER; + break; + + default: + result = TEL_NETWORK_RESULT_FAILURE; + } + } + tcore_at_tok_free(tokens); + + return result; +} + static void __on_response_imc_network_fetch_nw_name_internal(CoreObject *co, gint result, const void *response, void *user_data) { @@ -199,6 +259,7 @@ static void __on_response_imc_network_fetch_nw_name(TcorePending *p, nol = g_slist_length(at_resp->lines); if (nol > 3) { err("Invalid response message"); + imc_destroy_resp_cb_data(resp_cb_data); return; } @@ -926,7 +987,7 @@ static void on_response_imc_network_search(TcorePending *p, CustomData *custom_data; ImcRespCbData *resp_cb_data = user_data; - TelNetworkResult result = TEL_NETWORK_RESULT_FAILURE; //TODO - CME Error mapping required. + TelNetworkResult result = TEL_NETWORK_RESULT_FAILURE; TelNetworkPlmnList plmn_list = {0, }; guint num_network_avail = 0; guint count; @@ -1035,8 +1096,7 @@ static void on_response_imc_network_search(TcorePending *p, result = TEL_NETWORK_RESULT_SUCCESS; } else { err("RESPONSE NOK"); - if (at_resp->lines) - err("CME Error[%s]",(char *)at_resp->lines->data); + result = __imc_network_convert_cme_error_tel_network_result(at_resp); } END: @@ -1089,7 +1149,7 @@ static void on_response_imc_network_get_selection_mode(TcorePending *p, TelNetworkSelectionMode selection_mode = -1; GSList *tokens = NULL; - TelNetworkResult result = TEL_NETWORK_RESULT_FAILURE; //TODO - CME Error mapping required. + TelNetworkResult result = TEL_NETWORK_RESULT_FAILURE; dbg("Enter"); tcore_check_return_assert(co != NULL); @@ -1123,6 +1183,7 @@ static void on_response_imc_network_get_selection_mode(TcorePending *p, } else { err("RESPONSE NOK"); + result = __imc_network_convert_cme_error_tel_network_result(at_resp); } END: @@ -1144,7 +1205,7 @@ static void on_response_imc_network_default(TcorePending *p, const TcoreAtResponse *at_resp = data; CoreObject *co = tcore_pending_ref_core_object(p); ImcRespCbData *resp_cb_data = user_data; - TelNetworkResult result = TEL_NETWORK_RESULT_FAILURE; //TODO - CME Error mapping required. + TelNetworkResult result = TEL_NETWORK_RESULT_FAILURE; dbg("Enter"); tcore_check_return_assert(co != NULL); @@ -1155,8 +1216,7 @@ static void on_response_imc_network_default(TcorePending *p, result = TEL_NETWORK_RESULT_SUCCESS; } else { err("RESPONSE NOK"); - if (at_resp->lines) - err("CME Error[%s]",(char *)at_resp->lines->data); + result = __imc_network_convert_cme_error_tel_network_result(at_resp); } /* Invoke callback */ @@ -1173,7 +1233,7 @@ static void on_response_imc_network_get_mode(TcorePending *p, const TcoreAtResponse *at_resp = data; CoreObject *co = tcore_pending_ref_core_object(p); ImcRespCbData *resp_cb_data = user_data; - TelNetworkResult result = TEL_NETWORK_RESULT_FAILURE; //TODO - CME Error mapping required. + TelNetworkResult result = TEL_NETWORK_RESULT_FAILURE; TelNetworkMode mode = -1; GSList *tokens = NULL; @@ -1201,7 +1261,7 @@ static void on_response_imc_network_get_mode(TcorePending *p, net_mode = atoi(tcore_at_tok_nth(tokens, 0)); dbg("mode = %d", net_mode); - switch(net_mode) { + switch (net_mode) { case 0: mode = TEL_NETWORK_MODE_2G; break; @@ -1218,6 +1278,7 @@ static void on_response_imc_network_get_mode(TcorePending *p, result = TEL_NETWORK_RESULT_SUCCESS; } else { err("RESPONSE NOK"); + result = __imc_network_convert_cme_error_tel_network_result(at_resp); } END: /* Invoke callback */ @@ -1238,7 +1299,7 @@ static void on_response_imc_network_get_preferred_plmn(TcorePending *p, ImcRespCbData *resp_cb_data = user_data; TelNetworkPreferredPlmnList plmn_list = {0,}; guint count = 0, total_lines = 0; - TelNetworkResult result = TEL_NETWORK_RESULT_FAILURE; //TODO - CME Error mapping required. + TelNetworkResult result = TEL_NETWORK_RESULT_FAILURE; dbg("Enter"); tcore_check_return_assert(co != NULL); @@ -1315,8 +1376,7 @@ static void on_response_imc_network_get_preferred_plmn(TcorePending *p, plmn_list.count = count; } else { err("RESPONSE NOK"); - if (at_resp->lines) - err("CME Error[%s]",(char *)at_resp->lines->data); + result = __imc_network_convert_cme_error_tel_network_result(at_resp); } END: @@ -1577,7 +1637,7 @@ static TelReturn imc_network_select_manual(CoreObject *co, gint act; dbg("entry"); - switch(sel_manual->act) { + switch (sel_manual->act) { case TEL_NETWORK_ACT_GSM: case TEL_NETWORK_ACT_GPRS: case TEL_NETWORK_ACT_EGPRS: @@ -1695,7 +1755,7 @@ static TelReturn imc_network_set_preferred_plmn(CoreObject *co, TelReturn ret = TEL_RETURN_INVALID_PARAMETER; dbg("entry"); - switch(pref_plmn->act) { + switch (pref_plmn->act) { case TEL_NETWORK_ACT_GSM: case TEL_NETWORK_ACT_GPRS: case TEL_NETWORK_ACT_EGPRS: @@ -1799,7 +1859,7 @@ static TelReturn imc_network_set_mode(CoreObject *co, TelNetworkMode mode, int act; gchar *at_cmd; - switch(mode) { + switch (mode) { case TEL_NETWORK_MODE_AUTO: act = 1; break; diff --git a/src/imc_phonebook.c b/src/imc_phonebook.c index 20b653e..ca8ee04 100644 --- a/src/imc_phonebook.c +++ b/src/imc_phonebook.c @@ -51,6 +51,77 @@ typedef struct { gboolean used_index_usim_valid; } PrivateInfo; +static TelPbResult +__imc_phonebook_convert_cme_error_tel_phonebook_result(const TcoreAtResponse *at_resp) +{ + TelPbResult result = TEL_PB_RESULT_FAILURE; + GSList *tokens = NULL; + const gchar *line; + + dbg("Entry"); + + if (!at_resp || !at_resp->lines) { + err("Invalid response data"); + return result; + } + + line = (const gchar *)at_resp->lines->data; + tokens = tcore_at_tok_new(line); + if (g_slist_length(tokens) > 0) { + gchar *resp_str; + gint cme_err; + + resp_str = g_slist_nth_data(tokens, 0); + if (!resp_str) { + err("Invalid CME Error data"); + tcore_at_tok_free(tokens); + return result; + } + cme_err = atoi(resp_str); + dbg("CME Error: [%d]", cme_err); + + switch (cme_err) { + case 3: + result = TEL_PB_RESULT_OPERATION_NOT_PERMITTED; + break; + + case 4: + result = TEL_PB_RESULT_OPERATION_NOT_SUPPORTED; + break; + + case 17: + result = TEL_PB_RESULT_PIN2_REQUIRED; + break; + + case 18: + result = TEL_PB_RESULT_PUK2_REQUIRED; + break; + + case 20: + result = TEL_PB_RESULT_MEMORY_FAILURE; + break; + + case 21: + result = TEL_PB_RESULT_INVALID_INDEX; + break; + + case 50: + result = TEL_PB_RESULT_INVALID_PARAMETER; + break; + + case 100: + result = TEL_PB_RESULT_UNKNOWN_FAILURE; + break; + + default: + result = TEL_PB_RESULT_FAILURE; + } + } + tcore_at_tok_free(tokens); + + return result; +} + static gboolean __imc_phonebook_get_sim_type(CoreObject *co_pb, TelSimCardType *sim_type) { @@ -416,6 +487,7 @@ static void on_response_imc_phonebook_get_info(TcorePending *p, if (at_resp->success != TRUE) { err("Response NOK"); + result = __imc_phonebook_convert_cme_error_tel_phonebook_result(at_resp); goto out; } @@ -538,6 +610,7 @@ static void on_response_imc_phonebook_read_record(TcorePending *p, if (at_resp->success != TRUE) { err("Response NOK"); + result = __imc_phonebook_convert_cme_error_tel_phonebook_result(at_resp); goto out; } @@ -704,6 +777,7 @@ static void on_response_imc_phonebook_update_record(TcorePending *p, if (at_resp->success != TRUE) { err("Response NOK"); + result = __imc_phonebook_convert_cme_error_tel_phonebook_result(at_resp); goto out; } @@ -721,6 +795,7 @@ static void on_response_imc_phonebook_update_record(TcorePending *p, } else { list = g_slist_insert_sorted(list, (gpointer)req_data->index, __imc_phonebook_compare_index); + dbg("list: [0x%x]", list); } out: @@ -748,6 +823,7 @@ static void on_response_imc_phonebook_delete_record(TcorePending *p, if (at_resp->success != TRUE) { err("Response NOK"); + result = __imc_phonebook_convert_cme_error_tel_phonebook_result(at_resp); goto out; } @@ -764,7 +840,7 @@ static void on_response_imc_phonebook_delete_record(TcorePending *p, err("used_index list is NOT valid"); } else { list = g_slist_remove(list, (gconstpointer)req_data->index); - dbg("Remove index: [%u]", req_data->index); + dbg("Remove index: [%u], list: [0x%x]", req_data->index, list); } out: diff --git a/src/imc_sap.c b/src/imc_sap.c index b0653dc..a49bfbd 100644 --- a/src/imc_sap.c +++ b/src/imc_sap.c @@ -36,6 +36,53 @@ #include "imc_sap.h" #include "imc_common.h" +static TelSapResult __imc_sap_convert_cme_error_tel_sap_result(const TcoreAtResponse *at_resp) +{ + TelSapResult result = TEL_SAP_RESULT_FAILURE_NO_REASON; + const gchar *line; + GSList *tokens = NULL; + + dbg("Entry"); + + if (!at_resp || !at_resp->lines) { + err("Invalid response data"); + return result; + } + + line = (const gchar *)at_resp->lines->data; + tokens = tcore_at_tok_new(line); + if (g_slist_length(tokens) > 0) { + gchar *resp_str; + gint cme_err; + + resp_str = g_slist_nth_data(tokens, 0); + if (!resp_str) { + err("Invalid CME Error data"); + tcore_at_tok_free(tokens); + return result; + } + cme_err = atoi(resp_str); + dbg("CME Error: [%d]", cme_err); + + switch (cme_err) { + case 3: + case 4: + result = TEL_SAP_RESULT_OPERATION_NOT_PERMITTED; + break; + + case 14: + result = TEL_SAP_RESULT_ONGOING_CALL; + break; + + default: + result = TEL_SAP_RESULT_FAILURE_NO_REASON; + } + } + tcore_at_tok_free(tokens); + + return result; +} + static TelSapResult __map_sap_status_to_result(int sap_status) { switch(sap_status){ @@ -132,8 +179,8 @@ static void on_response_imc_sap_req_connect(TcorePending *p, result = TEL_SAP_RESULT_SUCCESS; memcpy(&max_msg_size, IMC_GET_DATA_FROM_RESP_CB_DATA(resp_cb_data), sizeof(unsigned int)); } else { - err("CME error[%s]", at_resp->lines->data); - /*TODO - need to map CME error to TelSapResult */ + err("RESPONSE NOK"); + result = __imc_sap_convert_cme_error_tel_sap_result(at_resp); } dbg("Request to sap connection : [%s]", @@ -162,8 +209,8 @@ static void on_response_imc_sap_req_disconnect(TcorePending *p, if (at_resp && at_resp->success) { result = TEL_SAP_RESULT_SUCCESS; } else { - err("CME error[%s]", at_resp->lines->data); - /*TODO - need to map CME error to TelSapResult */ + err("RESPONSE NOK"); + result = __imc_sap_convert_cme_error_tel_sap_result(at_resp); } dbg("Request to sap connection : [%s]", @@ -219,6 +266,7 @@ static void on_response_imc_sap_get_atr(TcorePending *p, tcore_at_tok_free(tokens); } else { err("RESPONSE NOK"); + result = __imc_sap_convert_cme_error_tel_sap_result(at_resp); } END: @@ -286,6 +334,7 @@ static void on_response_imc_sap_req_transfer_apdu(TcorePending *p, tcore_at_tok_free(tokens); } else { err("RESPONSE NOK"); + result = __imc_sap_convert_cme_error_tel_sap_result(at_resp); } END: @@ -331,6 +380,7 @@ static void on_response_imc_sap_req_power_operation(TcorePending *p, tcore_at_tok_free(tokens); } else { err("RESPONSE NOK"); + result = __imc_sap_convert_cme_error_tel_sap_result(at_resp); } END: @@ -377,18 +427,20 @@ static void on_response_imc_sap_get_cardreader_status(TcorePending *p, result = __map_sap_status_to_result(atoi(g_slist_nth_data(tokens, 0))); card_reader_status = (unsigned char)atoi(g_slist_nth_data(tokens, 1)); - card_reader_status = card_reader_status >> 3; + card_reader_status = card_reader_status >> 3; for (count = 8; count > 3; count--) { //check bit 8 to 3 + /*TODO - Need to map card reader status to TelSapCardStatus. if ((card_reader_status & 0x80) == TRUE) { //Check most significant bit - //card_status = //TODO - Need to map card reader status to TelSapCardStatus. + //card_status = TEL_SAP_CARD_STATUS_UNKNOWN; break; } + */ card_reader_status = card_reader_status << 1; //left shift by 1 } tcore_at_tok_free(tokens); } else { err("RESPONSE NOK"); - result = TEL_SAP_RESULT_FAILURE_NO_REASON; + result = __imc_sap_convert_cme_error_tel_sap_result(at_resp); } END: diff --git a/src/imc_sat.c b/src/imc_sat.c index 155bad2..601f706 100644 --- a/src/imc_sat.c +++ b/src/imc_sat.c @@ -38,6 +38,63 @@ #define PROACTV_CMD_LEN 256 +static TelSatResult +__imc_sim_convert_cme_error_tel_sat_result(const TcoreAtResponse *at_resp) +{ + TelSatResult result = TEL_SAT_RESULT_FAILURE; + const gchar *line; + GSList *tokens = NULL; + + dbg("Entry"); + + if (!at_resp || !at_resp->lines) { + err("Invalid response data"); + return result; + } + + line = (const gchar *)at_resp->lines->data; + tokens = tcore_at_tok_new(line); + if (g_slist_length(tokens) > 0) { + gchar *resp_str; + gint cme_err; + + resp_str = g_slist_nth_data(tokens, 0); + if (!resp_str) { + err("Invalid CME Error data"); + tcore_at_tok_free(tokens); + return result; + } + + cme_err = atoi(resp_str); + dbg("CME error[%d]", cme_err); + switch (cme_err) { + case 3: + case 4: + result = TEL_SAT_RESULT_OPERATION_NOT_SUPPORTED; + break; + + case 20: + case 23: + result = TEL_SAT_RESULT_MEMORY_FAILURE; + break; + + case 50: + result = TEL_SAT_RESULT_INVALID_PARAMETER; + break; + + case 100: + result = TEL_SAT_RESULT_UNKNOWN_FAILURE; + break; + + default: + result = TEL_SAT_RESULT_FAILURE; + } + } + tcore_at_tok_free(tokens); + + return result; +} + static void on_response_enable_sat(TcorePending *p, guint data_len, const void *data, void *user_data) { @@ -66,15 +123,17 @@ static TcoreHookReturn on_hook_imc_sim_status(TcorePlugin *plugin, */ dbg("SIM Status: [%d]", *sim_status); if (*sim_status == TEL_SIM_STATUS_SIM_INIT_COMPLETED) { + TelReturn ret; dbg("SIM Initialized!!! Enable SAT"); /* Enable SAT - Send AT+CFUN=6 */ - tcore_at_prepare_and_send_request(co, + ret = tcore_at_prepare_and_send_request(co, "AT+CFUN=6", NULL, TCORE_AT_COMMAND_TYPE_NO_RESULT, NULL, on_response_enable_sat, NULL, on_send_imc_request, NULL); + IMC_CHECK_REQUEST_RET(ret, NULL, "Enable SAT"); } return TCORE_HOOK_RETURN_CONTINUE; @@ -339,7 +398,6 @@ static void on_response_imc_sat_send_envelop_cmd(TcorePending *p, TelSatResult result = TEL_SAT_RESULT_FAILURE; GSList *tokens = NULL; const gchar *line = NULL; - const gchar *env_res = NULL; gint sw2 = -1; dbg("Entry"); @@ -356,28 +414,33 @@ static void on_response_imc_sat_send_envelop_cmd(TcorePending *p, tokens = tcore_at_tok_new(line); if (g_slist_length(tokens) < 1) { err("invalid message"); - tcore_at_tok_free(tokens); - return; + goto OUT; } - } - env_res = g_slist_nth_data(tokens, 0); - envelop_resp = TEL_SAT_ENVELOPE_SUCCESS; - dbg("RESPONSE tokens present"); - if (NULL != g_slist_nth_data(tokens, 1)) { - sw2 = atoi(g_slist_nth_data(tokens, 1)); - dbg("status word SW2:[%d]", sw2); - if (sw2 == 0) { - dbg("Response is processed completely and sending session end notification"); - /* Send Session End notification */ - tcore_object_send_notification(co, - TCORE_NOTIFICATION_SAT_SESSION_END, 0, NULL); + + envelop_resp = TEL_SAT_ENVELOPE_SUCCESS; + dbg("RESPONSE tokens present"); + if (NULL != g_slist_nth_data(tokens, 1)) { + sw2 = atoi(g_slist_nth_data(tokens, 1)); + dbg("status word SW2:[%d]", sw2); + if (sw2 == 0) { + dbg("Response is processed completely " \ + "and sending session end notification"); + + /* Send Session End notification */ + tcore_object_send_notification(co, + TCORE_NOTIFICATION_SAT_SESSION_END, + 0, NULL); + } } } } else { - dbg("RESPONSE NOK"); + err("RESPONSE NOK"); + envelop_resp = TEL_SAT_ENVELOPE_FAILED; + result = __imc_sim_convert_cme_error_tel_sat_result(at_resp); } +OUT: /* Invoke callback */ if (resp_cb_data->cb) resp_cb_data->cb(co, (gint)result, &envelop_resp, resp_cb_data->cb_data); @@ -407,6 +470,9 @@ static void on_response_imc_sat_send_terminal_response(TcorePending *p, dbg(" at_resp->success = %d", at_resp->success); /* Send Session End notification */ tcore_object_send_notification(co, TCORE_NOTIFICATION_SAT_SESSION_END, 0, NULL); + } else { + err("RESPONSE NOK"); + result = __imc_sim_convert_cme_error_tel_sat_result(at_resp); } /* Invoke callback */ @@ -434,6 +500,9 @@ static void on_response_imc_sat_send_user_confirmation(TcorePending *p, if (at_resp && at_resp->success) { dbg("RESPONSE OK"); result = TEL_SAT_RESULT_SUCCESS; + } else { + err("RESPONSE NOK"); + result = __imc_sim_convert_cme_error_tel_sat_result(at_resp); } /* Invoke callback */ diff --git a/src/imc_sim.c b/src/imc_sim.c index 92b90f3..86596ae 100644 --- a/src/imc_sim.c +++ b/src/imc_sim.c @@ -41,6 +41,8 @@ #define ENABLE_FLAG 1 #define DISABLE_FLAG 2 +#define VAL_MINUS_ONE (-1) + #define IMC_SIM_ACCESS_READ_BINARY 176 #define IMC_SIM_ACCESS_READ_RECORD 178 #define IMC_SIM_ACCESS_GET_RESPONSE 192 @@ -108,6 +110,7 @@ typedef enum { typedef struct { guint smsp_count; /**< SMSP record count */ guint smsp_rec_len; /**< SMSP record length */ + guint mb_rec_len; /**< MBDN record length */ } ImcSimPrivateInfo; typedef struct { @@ -115,17 +118,19 @@ typedef struct { guint rec_length; /**< Length of one record in file */ guint rec_count; /**< Number of records in file */ guint data_size; /**< File size */ - guint current_index; /**< Current index to read */ - guint mb_count; /**< Current mbdn read index */ + guint current_index; /**< Current index to read */ + guint mb_count; /**< Current mbdn read index */ int mb_index[TEL_SIM_MSP_CNT_MAX * TEL_SIM_MAILBOX_TYPE_MAX]; /**< List of mbdn index to read */ + int mbdn_index; /**< MBDN index to set mb_data */ + TelSimMailBoxNumber *mb_data; /**< Set MailBox data */ ImcSimFileType file_type; /**< File type and structure */ - ImcSimCurrSecOp sec_op; /**< Current index to read */ - TelSimFileId file_id; /**< Current file id */ + ImcSimCurrSecOp sec_op; /**< Current index to read */ + TelSimFileId file_id; /**< Current file id */ TelSimResult file_result; /**< File access result */ - TelSimFileResult files; /**< File read data */ - TcoreCommand req_command; /**< Request command Id */ - TelSimImsiInfo imsi; /**< Stored locally as of now, - Need to store in secure storage*/ + TelSimFileResult files; /**< File read data */ + TcoreCommand req_command; /**< Request command Id */ + TelSimImsiInfo imsi; /**< Stored locally as of now, + Need to store in secure storage */ } ImcSimMetaInfo; /* Utility Function Declaration */ @@ -133,17 +138,23 @@ static TelSimResult __imc_sim_decode_status_word(unsigned short status_word1, un static void __imc_sim_update_sim_status(CoreObject *co, TelSimCardStatus sim_status); static void __imc_sim_notify_sms_state(CoreObject *co, gboolean sms_ready); static TelReturn __imc_sim_start_to_cache(CoreObject *co); -static gboolean __imc_sim_get_sim_type(CoreObject *co, TcoreObjectResponseCallback cb, void *cb_data); -static void __imc_sim_next_from_read_binary(CoreObject *co, ImcRespCbData *resp_cb_data, TelSimResult sim_result, gboolean decode_ret); -static void __imc_sim_next_from_get_response(CoreObject *co, ImcRespCbData *resp_cb_data, TelSimResult sim_result); -static TelReturn __imc_sim_update_file(CoreObject *co, ImcRespCbData *resp_cb_data, int cmd, TelSimFileId ef, - int p1, int p2, int p3, char *encoded_data); +static TelReturn __imc_sim_get_sim_type(CoreObject *co, + TcoreObjectResponseCallback cb, void *cb_data); +static void __imc_sim_next_from_read_binary(CoreObject *co, + ImcRespCbData *resp_cb_data, TelSimResult sim_result, gboolean decode_ret); +static void __imc_sim_next_from_get_response(CoreObject *co, + ImcRespCbData *resp_cb_data, TelSimResult sim_result); +static void __sim_set_mailbox_info(CoreObject *co, ImcRespCbData *resp_cb_data); +static TelReturn __imc_sim_update_file(CoreObject *co, + ImcRespCbData *resp_cb_data, int cmd, TelSimFileId ef, + int p1, int p2, int p3, char *encoded_data); static void __imc_sim_read_record(CoreObject *co, ImcRespCbData *resp_cb_data); static void __imc_sim_read_binary(CoreObject *co, ImcRespCbData *resp_cb_data); static TelReturn __imc_sim_get_response (CoreObject *co, ImcRespCbData *resp_cb_data); static TelReturn __imc_sim_get_retry_count(CoreObject *co, ImcRespCbData *resp_cb_data); static TelSimLockType __imc_sim_lock_type(int lock_type); -static char *__imc_sim_get_fac_from_lock_type(TelSimLockType lock_type, ImcSimCurrSecOp *sec_op, int flag); +static char *__imc_sim_get_fac_from_lock_type(TelSimLockType lock_type, + ImcSimCurrSecOp *sec_op, int flag); static int __imc_sim_get_lock_type(ImcSimCurrSecOp sec_op); /* Internal Response Functions*/ @@ -154,6 +165,90 @@ static void __on_response_imc_sim_get_response(TcorePending *p, guint data_len, static void __on_response_imc_sim_get_retry_count(TcorePending *p, guint data_len, const void *data, void *user_data); static void __on_response_imc_sim_update_file(TcorePending *p, guint data_len, const void *data, void *user_data); +static TelSimResult +__imc_sim_convert_cme_error_tel_sim_result(const TcoreAtResponse *at_resp) +{ + + TelSimResult result = TEL_SIM_RESULT_FAILURE; + const gchar *line; + GSList *tokens = NULL; + + dbg("Entry"); + + if (!at_resp || !at_resp->lines) { + err("Invalid response data"); + return result; + } + + line = (const gchar *)at_resp->lines->data; + tokens = tcore_at_tok_new(line); + if (g_slist_length(tokens) > 0) { + gchar *resp_str; + gint cme_err; + + resp_str = g_slist_nth_data(tokens, 0); + if (!resp_str) { + err("Invalid CME Error data"); + tcore_at_tok_free(tokens); + return result; + } + cme_err = atoi(resp_str); + dbg("CME error[%d]", cme_err); + + switch (cme_err) { + case 3: + result = TEL_SIM_RESULT_OPERATION_NOT_PERMITTED; + break; + + case 4: + result = TEL_SIM_RESULT_OPERATION_NOT_SUPPORTED; + break; + + case 10: + case 13: + case 14: + case 15: + result = TEL_SIM_RESULT_CARD_ERROR; + break; + + case 5: + case 6: + case 11: + case 17: + case 46: + case 47: + result = TEL_SIM_RESULT_PIN_REQUIRED; + break; + + case 7: + case 12: + case 18: + case 45: + result = TEL_SIM_RESULT_PUK_REQUIRED; + break; + + case 16: + result = TEL_SIM_RESULT_INCORRECT_PASSWORD; + break; + + case 20: + case 23: + result = TEL_SIM_RESULT_MEMORY_FAILURE; + break; + + case 50: + result = TEL_SIM_RESULT_INVALID_PARAMETER; + break; + + default: + result = TEL_SIM_RESULT_FAILURE; + } + } + tcore_at_tok_free(tokens); + + return result; +} + /* GET SMSP info for SMS module */ gboolean imc_sim_get_smsp_info(TcorePlugin *plugin, int *rec_count, int *rec_len) { @@ -348,7 +443,7 @@ TelReturn __imc_sim_start_to_cache(CoreObject *co) IMC_SIM_READ_FILE(co, NULL, NULL, TEL_SIM_EF_ECC, ret); IMC_SIM_READ_FILE(co, NULL, NULL, TEL_SIM_EF_MSISDN, ret); IMC_SIM_READ_FILE(co, NULL, NULL, TEL_SIM_EF_SMSP, ret); - + IMC_SIM_READ_FILE(co, NULL, NULL, TEL_SIM_EF_MBDN, ret); return ret; } @@ -447,7 +542,7 @@ static void __on_response_imc_sim_get_sim_type(TcorePending *p, * Failure: * +CME ERROR: */ -gboolean __imc_sim_get_sim_type(CoreObject *co, +TelReturn __imc_sim_get_sim_type(CoreObject *co, TcoreObjectResponseCallback cb, void *cb_data) { ImcRespCbData *resp_cb_data; @@ -696,7 +791,7 @@ static void __imc_sim_next_from_read_binary(CoreObject *co, ImcRespCbData *resp_ /* 2G */ /* The ME requests the Extended Language Preference. The ME only requests the Language Preference (EFLP) if at least one of the following conditions holds: - EFELP is not available; - - EFELP does not contain an entry corresponding to a language specified in ISO 639[30]; + - EFELP does not contain an Entry corresponding to a language specified in ISO 639[30]; - the ME does not support any of the languages in EFELP. */ /* 3G */ @@ -806,21 +901,41 @@ static void __imc_sim_next_from_read_binary(CoreObject *co, ImcRespCbData *resp_ break; case TEL_SIM_EF_USIM_MBI: - if (file_meta->current_index == file_meta->rec_count) { - /* Init file_meta to read next EF file */ - file_meta->rec_count = 0; - file_meta->current_index = 0; - file_meta->file_id = TEL_SIM_EF_MBDN; - /* Read MBDN record*/ - dbg("Read MBDN record"); - __imc_sim_get_response(co, resp_cb_data); - return; + if (file_meta->current_index == file_meta->rec_count) { + if (file_meta->mb_data) { + guint i = 0; + for (i = 0; i < file_meta->files.data.mb.count; i++) { + if (file_meta->files.data.mb.list[i].mb_type + == file_meta->mb_data->mb_type) + file_meta->mbdn_index = file_meta->mb_index[i]; + } - } else { - file_meta->current_index++; - __imc_sim_read_record(co, resp_cb_data); - return; - } + if(!file_meta->mbdn_index) + file_meta->mbdn_index = VAL_MINUS_ONE; + + __sim_set_mailbox_info(co, resp_cb_data); + + return; + } + + /* Init file_meta to read next EF file */ + file_meta->rec_count = 0; + file_meta->current_index = 0; + file_meta->file_id = TEL_SIM_EF_MBDN; + + /* Read MBDN record*/ + dbg("Read MBDN record"); + __imc_sim_get_response(co, resp_cb_data); + + return; + + } else { + file_meta->current_index++; + + __imc_sim_read_record(co, resp_cb_data); + + return; + } break; case TEL_SIM_EF_MBDN: @@ -937,6 +1052,8 @@ static void __imc_sim_next_from_get_response(CoreObject *co, ImcRespCbData *resp && (sim_result != TEL_SIM_RESULT_SUCCESS)) { if (resp_cb_data->cb) resp_cb_data->cb(co, (gint)sim_result, &file_meta->files.data, resp_cb_data->cb_data); + /* free resp_cb_data */ + imc_destroy_resp_cb_data(resp_cb_data); return; } @@ -963,6 +1080,8 @@ static void __imc_sim_next_from_get_response(CoreObject *co, ImcRespCbData *resp dbg(" [SIM DATA]fail to get Language information in USIM(EF-LI(6F05),EF-PL(2F05))"); if (resp_cb_data->cb) resp_cb_data->cb(co, (gint)sim_result, &file_meta->files.data, resp_cb_data->cb_data); + /* free resp_cb_data */ + imc_destroy_resp_cb_data(resp_cb_data); return; } } @@ -979,6 +1098,9 @@ static void __imc_sim_next_from_get_response(CoreObject *co, ImcRespCbData *resp if (TEL_SIM_CARD_TYPE_GSM == card_type) { if (resp_cb_data->cb) resp_cb_data->cb(co, (gint)sim_result, &file_meta->files.data, resp_cb_data->cb_data); + /* free resp_cb_data */ + imc_destroy_resp_cb_data(resp_cb_data); + return; } /* if EFLI is not present, then the language selection shall be as defined in EFPL at the MF level */ @@ -1007,6 +1129,9 @@ static void __imc_sim_next_from_get_response(CoreObject *co, ImcRespCbData *resp " [SIM DATA]SIM_EF_USIM_PL(2A05) access fail. Request SIM_EF_ECC(0x6FB7) info"); if (resp_cb_data->cb) resp_cb_data->cb(co, (gint)sim_result, &file_meta->files.data, resp_cb_data->cb_data); + /* free resp_cb_data */ + imc_destroy_resp_cb_data(resp_cb_data); + return; } break; @@ -1048,6 +1173,9 @@ static void __imc_sim_next_from_get_response(CoreObject *co, ImcRespCbData *resp tcore_sim_set_cphs_status(co, FALSE); if (resp_cb_data->cb) resp_cb_data->cb(co, (gint)sim_result, &file_meta->files.data, resp_cb_data->cb_data); + + /* free resp_cb_data */ + imc_destroy_resp_cb_data(resp_cb_data); } break; @@ -1068,9 +1196,15 @@ static void __imc_sim_next_from_get_response(CoreObject *co, ImcRespCbData *resp break; case TEL_SIM_EF_MBDN: + { + ImcSimPrivateInfo *priv_info = NULL; + priv_info = tcore_sim_ref_userdata(co); + if(priv_info) + priv_info->mb_rec_len = file_meta->rec_length; file_meta->mb_count = 0; file_meta->current_index = file_meta->mb_index[file_meta->mb_count]; __imc_sim_read_record(co, resp_cb_data); + } break; case TEL_SIM_EF_OPL: @@ -1140,13 +1274,16 @@ static void __on_response_imc_sim_update_file(TcorePending *p, guint data_len, c } } else { err("RESPONSE NOK"); - sim_result = TEL_SIM_RESULT_FAILURE; + sim_result = __imc_sim_convert_cme_error_tel_sim_result(resp); } OUT: /* Send Response */ if (resp_cb_data->cb) resp_cb_data->cb(co_sim, (gint)sim_result, NULL, resp_cb_data->cb_data); + /* free resp_cb_data */ + imc_destroy_resp_cb_data(resp_cb_data); + tcore_at_tok_free(tokens); dbg("Exit"); } @@ -1181,6 +1318,8 @@ static void __on_response_imc_sim_read_data(TcorePending *p, guint data_len, if (g_slist_length(tokens) < 2) { err("Invalid message"); tcore_at_tok_free(tokens); + /* free resp_cb_data */ + imc_destroy_resp_cb_data(resp_cb_data); return; } } @@ -1244,6 +1383,12 @@ static void __on_response_imc_sim_read_data(TcorePending *p, guint data_len, case TEL_SIM_EF_SPN: dr = tcore_sim_decode_spn((unsigned char *)res, res_len, &file_meta->files.data.spn); + if( dr == FALSE ) { + err("SPN decoding failed"); + } else { + tcore_sim_set_disp_condition(co, file_meta->files.data.spn.display_condition); + tcore_sim_set_spn(co, file_meta->files.data.spn.spn); + } break; case TEL_SIM_EF_SPDI: @@ -1541,7 +1686,7 @@ static void __on_response_imc_sim_read_data(TcorePending *p, guint data_len, } else { err("RESPONSE NOK"); dbg("Error - File ID: [0x%x]", file_meta->file_id); - sim_result = TEL_SIM_RESULT_FAILURE; + sim_result = __imc_sim_convert_cme_error_tel_sim_result(resp); } /* Get File data */ @@ -1576,7 +1721,7 @@ static void __on_response_imc_sim_get_response(TcorePending *p, if (g_slist_length(tokens) < 2) { err("Invalid message"); tcore_at_tok_free(tokens); - return; + goto OUT; } } sw1 = atoi(g_slist_nth_data(tokens, 0)); @@ -1702,7 +1847,7 @@ static void __on_response_imc_sim_get_response(TcorePending *p, dbg("INVALID FCP received - DEbug!"); tcore_at_tok_free(tokens); g_free(record_data); - return; + goto OUT; } /*File identifier - 0x84,0x85,0x86 etc are currently ignored and not handled */ @@ -1725,7 +1870,7 @@ static void __on_response_imc_sim_get_response(TcorePending *p, dbg("INVALID FCP received - DEbug!"); tcore_at_tok_free(tokens); g_free(record_data); - return; + goto OUT; } /* proprietary information */ @@ -1808,7 +1953,7 @@ static void __on_response_imc_sim_get_response(TcorePending *p, dbg("INVALID FCP received[0x%x] - DEbug!", *ptr_data); tcore_at_tok_free(tokens); g_free(record_data); - return; + goto OUT; } dbg("Current ptr_data value is [%x]", *ptr_data); @@ -1830,7 +1975,7 @@ static void __on_response_imc_sim_get_response(TcorePending *p, dbg("INVALID FCP received - DEbug!"); tcore_at_tok_free(tokens); g_free(record_data); - return; + goto OUT; } /* total file size including structural info*/ @@ -1856,7 +2001,7 @@ static void __on_response_imc_sim_get_response(TcorePending *p, dbg("INVALID FCP received - DEbug!"); tcore_at_tok_free(tokens); g_free(record_data); - return; + goto OUT; } } else if (TEL_SIM_CARD_TYPE_GSM == card_type) { unsigned char gsm_specific_file_data_len = 0; @@ -1963,9 +2108,10 @@ static void __on_response_imc_sim_get_response(TcorePending *p, } else { err("RESPONSE NOK"); err("Failed to get ef[0x%x] (file_meta->file_id) ", file_meta->file_id); - sim_result = TEL_SIM_RESULT_FAILURE; + sim_result = __imc_sim_convert_cme_error_tel_sim_result(resp); } +OUT: dbg("Calling __imc_sim_next_from_get_response"); __imc_sim_next_from_get_response(co, resp_cb_data, sim_result); dbg("Exit"); @@ -2334,7 +2480,7 @@ static TelReturn __imc_sim_get_retry_count(CoreObject *co, static TelSimLockType __imc_sim_lock_type(int lock_type) { - switch(lock_type) { + switch (lock_type) { case 1 : return TEL_SIM_LOCK_SC; case 2 : @@ -2359,7 +2505,7 @@ static char *__imc_sim_get_fac_from_lock_type(TelSimLockType lock_type, ImcSimCurrSecOp *sec_op, int flag) { char *fac = NULL; - switch(lock_type) { + switch (lock_type) { case TEL_SIM_LOCK_PS : fac = "PS"; if (flag == ENABLE_FLAG) @@ -2431,7 +2577,7 @@ static char *__imc_sim_get_fac_from_lock_type(TelSimLockType lock_type, static int __imc_sim_get_lock_type(ImcSimCurrSecOp sec_op) { - switch(sec_op) { + switch (sec_op) { case IMC_SIM_CURR_SEC_OP_SIM_DISABLE : case IMC_SIM_CURR_SEC_OP_SIM_ENABLE : case IMC_SIM_CURR_SEC_OP_SIM_STATUS : @@ -2558,7 +2704,7 @@ static void on_response_imc_sim_req_authentication(TcorePending *p, guint data_l if (NULL == at_resp) { err("at_resp is NULL"); auth_resp.detailed_result = TEL_SIM_AUTH_CANNOT_PERFORM; - goto out; + goto OUT; } auth_resp.auth_type = *auth_type; @@ -2574,14 +2720,14 @@ static void on_response_imc_sim_req_authentication(TcorePending *p, guint data_l } else { err("at_resp->lines is NULL"); auth_resp.detailed_result = TEL_SIM_AUTH_CANNOT_PERFORM; - goto out; + goto OUT; } tokens = tcore_at_tok_new(line); if (tokens == NULL) { err("tokens is NULL"); auth_resp.detailed_result = TEL_SIM_AUTH_CANNOT_PERFORM; - goto out; + goto OUT; } status = atoi(g_slist_nth_data(tokens, 0)); @@ -2593,19 +2739,19 @@ static void on_response_imc_sim_req_authentication(TcorePending *p, guint data_l case 1: err("Synchronize fail"); auth_resp.detailed_result = TEL_SIM_AUTH_SYNCH_FAILURE; - goto out; + goto OUT; case 2: err("MAC wrong"); auth_resp.detailed_result = TEL_SIM_AUTH_MAK_CODE_FAILURE; - goto out; + goto OUT; case 3: err("Does not support security context"); auth_resp.detailed_result = TEL_SIM_AUTH_UNSUPPORTED_CONTEXT; - goto out; + goto OUT; default: err("Other failure"); auth_resp.detailed_result = TEL_SIM_AUTH_CANNOT_PERFORM; - goto out; + goto OUT; } if (auth_resp.auth_type == TEL_SIM_AUTH_GSM) { @@ -2631,7 +2777,7 @@ static void on_response_imc_sim_req_authentication(TcorePending *p, guint data_l } else { err("Invalid Kc"); auth_resp.detailed_result = TEL_SIM_AUTH_CANNOT_PERFORM; - goto out; + goto OUT; } sres = g_slist_nth_data(tokens, 2); @@ -2653,7 +2799,7 @@ static void on_response_imc_sim_req_authentication(TcorePending *p, guint data_l } else { err("Invalid SRES"); auth_resp.detailed_result = TEL_SIM_AUTH_CANNOT_PERFORM; - goto out; + goto OUT; } } else if (auth_resp.auth_type == TEL_SIM_AUTH_3G_CTX) { char *res, *ck, *ik, *kc; @@ -2679,7 +2825,7 @@ static void on_response_imc_sim_req_authentication(TcorePending *p, guint data_l } else { err("Invalid RES/AUTS"); auth_resp.detailed_result = TEL_SIM_AUTH_CANNOT_PERFORM; - goto out; + goto OUT; } ck = g_slist_nth_data(tokens, 2); @@ -2701,7 +2847,7 @@ static void on_response_imc_sim_req_authentication(TcorePending *p, guint data_l } else { err("Invalid CK"); auth_resp.detailed_result = TEL_SIM_AUTH_CANNOT_PERFORM; - goto out; + goto OUT; } ik = g_slist_nth_data(tokens, 3); @@ -2723,7 +2869,7 @@ static void on_response_imc_sim_req_authentication(TcorePending *p, guint data_l } else { err("Invalid IK"); auth_resp.detailed_result = TEL_SIM_AUTH_CANNOT_PERFORM; - goto out; + goto OUT; } kc = g_slist_nth_data(tokens, 4); @@ -2745,12 +2891,12 @@ static void on_response_imc_sim_req_authentication(TcorePending *p, guint data_l } else { err("Invalid Kc"); auth_resp.detailed_result = TEL_SIM_AUTH_CANNOT_PERFORM; - goto out; + goto OUT; } } else { err("Not supported"); auth_resp.detailed_result = TEL_SIM_AUTH_CANNOT_PERFORM; - goto out; + goto OUT; } sim_result = TEL_SIM_RESULT_SUCCESS; } else { @@ -2758,10 +2904,13 @@ static void on_response_imc_sim_req_authentication(TcorePending *p, guint data_l auth_resp.detailed_result = TEL_SIM_AUTH_CANNOT_PERFORM; } -out: +OUT: if(resp_cb_data->cb) resp_cb_data->cb(co, (gint)sim_result, &auth_resp, resp_cb_data->cb_data); + /* free resp_cb_data */ + imc_destroy_resp_cb_data(resp_cb_data); + tcore_at_tok_free(tokens); } @@ -3040,6 +3189,8 @@ static void on_response_imc_sim_get_facility(TcorePending *p, guint data_len, tcore_at_tok_free(tokens); } else { err("Sim Get Facility Response- [NOK]"); + result = __imc_sim_convert_cme_error_tel_sim_result(at_resp); + } EXIT: /* Invoke callback */ @@ -3094,6 +3245,7 @@ static void on_response_imc_sim_get_lock_info(TcorePending *p, guint data_len, tcore_at_tok_free(tokens); } else { err("Sim Get Lock Info Response- [NOK]"); + result = __imc_sim_convert_cme_error_tel_sim_result(at_resp); } EXIT: /* Invoke callback */ @@ -3140,6 +3292,7 @@ static void on_response_imc_sim_req_apdu (TcorePending *p, guint data_len, const } } else { err("RESPONSE NOK"); + sim_result = __imc_sim_convert_cme_error_tel_sim_result(resp); } OUT: @@ -3147,6 +3300,7 @@ OUT: if (resp_cb_data->cb) resp_cb_data->cb(co, (gint)sim_result, &apdu_resp, resp_cb_data->cb_data); tcore_at_tok_free(tokens); + imc_destroy_resp_cb_data(resp_cb_data); dbg("Exit"); } @@ -3188,6 +3342,8 @@ static void on_response_imc_sim_req_atr(TcorePending *p, guint data_len, const v } } else { err("RESPONSE NOK"); + sim_result = __imc_sim_convert_cme_error_tel_sim_result(resp); + } OUT: @@ -3195,6 +3351,7 @@ OUT: if (resp_cb_data->cb) resp_cb_data->cb(co, (gint)sim_result, &atr_res, resp_cb_data->cb_data); tcore_at_tok_free(tokens); + imc_destroy_resp_cb_data(resp_cb_data); dbg("Exit"); } @@ -3426,48 +3583,105 @@ static TelReturn imc_sim_get_mailbox_info (CoreObject *co, return ret; } -static TelReturn imc_sim_set_mailbox_info (CoreObject *co, - const TelSimMailBoxNumber *request, TcoreObjectResponseCallback cb, void *cb_data) +static void __sim_set_mailbox_info(CoreObject *co, ImcRespCbData *resp_cb_data) { - ImcSimMetaInfo file_meta = {0, }; - ImcRespCbData *resp_cb_data = NULL; char *tmp = NULL; - int tmp_len = 0; char *encoded_data = NULL; int encoded_data_len = 0; int p1 = 0; int p2 = 0; int p3 = 0; + TelSimResult sim_result = TEL_SIM_RESULT_FAILURE; + ImcSimMetaInfo *file_meta = (ImcSimMetaInfo *)IMC_GET_DATA_FROM_RESP_CB_DATA(resp_cb_data); + ImcSimPrivateInfo *priv_info = tcore_sim_ref_userdata(co); dbg("Entry"); - file_meta.file_id = TEL_SIM_EF_USIM_MBI; - file_meta.file_result = TEL_SIM_RESULT_FAILURE; + if (!file_meta || !file_meta->mb_data || !priv_info) { + err("NULL data : file_meta[%p], file_meta->mb_data[%p], priv_info[%p]", + file_meta, file_meta->mb_data, priv_info); + goto OUT; + } - /* TBD - Do Encoding. - if (!tcore_sim_encode_mbi(request, sizeof(request), tmp, &tmp_len)) { - err("Failed to encode mwis"); - return TEL_RETURN_FAILURE; - } */ + if (file_meta->mbdn_index == VAL_MINUS_ONE) { + err("Failed to get MBDN Index"); + goto OUT; + } + + dbg("mbdn_index:[%d], mb_rec_len:[%d]", + file_meta->mbdn_index, priv_info->mb_rec_len); - encoded_data_len = tmp_len * 2; + if (!tcore_sim_encode_xdn(file_meta->mb_data->alpha_id, + file_meta->mb_data->number, + priv_info->mb_rec_len, &tmp)) { + err("Failed to encode mailbox_info"); + goto OUT; + } + + if (!tmp) + goto OUT; + + dbg("Record length: [%d]", priv_info->mb_rec_len); + + encoded_data_len = 2 * priv_info->mb_rec_len; encoded_data = (char *)tcore_malloc0(encoded_data_len + 1); - tcore_util_byte_to_hex(tmp, encoded_data, tmp_len); + tcore_util_byte_to_hex(tmp, encoded_data, priv_info->mb_rec_len); if (!encoded_data) { err("Failed to convert byte to hex"); - tcore_free(encoded_data); - return TEL_RETURN_FAILURE; + goto OUT; } - p1 = 1; + p1 = file_meta->mbdn_index; p2 = 0x04; - p3 = encoded_data_len; - dbg("encoded_data - [%s], encoded_data_len - %d", encoded_data, encoded_data_len); + p3 = priv_info->mb_rec_len; + dbg("encoded_data - [%s], encoded_data_len - %d", + encoded_data, priv_info->mb_rec_len); + + __imc_sim_update_file(co, resp_cb_data, + IMC_SIM_ACCESS_UPDATE_RECORD, + TEL_SIM_EF_MBDN, p1, p2, p3, encoded_data); + + tcore_free(tmp); + tcore_free(file_meta->mb_data); + file_meta->mb_data = NULL; + + dbg("Exit"); + return; + +OUT: + /* Send Response */ + if (resp_cb_data->cb) + resp_cb_data->cb(co, (gint)sim_result, NULL, resp_cb_data->cb_data); + + /* Free Memory */ + tcore_free(tmp); + tcore_free(encoded_data); + tcore_free(file_meta->mb_data); + file_meta->mb_data = NULL; + imc_destroy_resp_cb_data(resp_cb_data); + + dbg("Exit"); +} + +static TelReturn imc_sim_set_mailbox_info (CoreObject *co, + const TelSimMailBoxNumber *request, TcoreObjectResponseCallback cb, void *cb_data) +{ + ImcSimMetaInfo file_meta = {0, }; + ImcRespCbData *resp_cb_data = NULL; + TelReturn ret; + + dbg("Entry"); + + file_meta.file_id = TEL_SIM_EF_USIM_MBI; + file_meta.file_result = TEL_SIM_RESULT_FAILURE; + + file_meta.mb_data = (TelSimMailBoxNumber *)tcore_malloc0(sizeof(TelSimMailBoxNumber)); + memcpy(file_meta.mb_data, request, sizeof(TelSimMailBoxNumber)); resp_cb_data = imc_create_resp_cb_data(cb, cb_data, &file_meta, sizeof(ImcSimMetaInfo)); + ret = __imc_sim_get_response(co, resp_cb_data); - return __imc_sim_update_file(co, resp_cb_data, IMC_SIM_ACCESS_UPDATE_RECORD, - TEL_SIM_EF_USIM_MBI, p1, p2, p3, encoded_data); + return ret; } static TelReturn imc_sim_get_msisdn (CoreObject *co, @@ -3537,14 +3751,9 @@ static TelReturn imc_sim_req_authentication (CoreObject *co, return TEL_SIM_RESULT_OPERATION_NOT_SUPPORTED; } - if (request->rand_data != NULL) { - convert_rand = tcore_malloc0(request->rand_length*2 + 1); - tcore_util_byte_to_hex(request->rand_data, convert_rand, request->rand_length); - dbg("Convert RAND hex to string: [%s]", convert_rand); - } else { - err("rand_data is NULL"); - goto EXIT; - } + convert_rand = tcore_malloc0(request->rand_length*2 + 1); + tcore_util_byte_to_hex(request->rand_data, convert_rand, request->rand_length); + dbg("Convert RAND hex to string: [%s]", convert_rand); switch (request->auth_type) { case TEL_SIM_AUTH_GSM: @@ -3554,14 +3763,11 @@ static TelReturn imc_sim_req_authentication (CoreObject *co, break; case TEL_SIM_AUTH_3G_CTX: context_type = 1; - if (request->autn_data != NULL) { - convert_autn = tcore_malloc0(request->autn_length*2 + 1); - tcore_util_byte_to_hex(request->autn_data, convert_autn, request->autn_length); - dbg("Convert AUTN hex to string: [%s]", convert_autn); - } else { - err("autn_data is NULL"); - goto EXIT; - } + convert_autn = tcore_malloc0(request->autn_length*2 + 1); + tcore_util_byte_to_hex(request->autn_data, convert_autn, request->autn_length); + + dbg("Convert AUTN hex to string: [%s]", convert_autn); + cmd_str = g_strdup_printf("AT+XAUTH=%d,%d,\"%s\",\"%s\"", session_id, context_type, convert_rand, convert_autn); break; diff --git a/src/imc_sms.c b/src/imc_sms.c index 005f08f..ca9482e 100644 --- a/src/imc_sms.c +++ b/src/imc_sms.c @@ -65,6 +65,190 @@ typedef struct { guint index; TelSmsParamsInfo *params; } ImcSmsParamsCbData; + +static TelSmsResult +__imc_sms_convert_cms_error_tel_sms_result(const TcoreAtResponse *at_resp) +{ + TelSmsResult result = TEL_SMS_RESULT_FAILURE; + const gchar *line; + GSList *tokens = NULL; + dbg("Entry"); + + if (!at_resp || !at_resp->lines) { + err("Invalid response data"); + return result; + } + + line = (const gchar *)at_resp->lines->data; + tokens = tcore_at_tok_new(line); + if (g_slist_length(tokens) > 0) { + gchar *resp_str; + gint cms_err; + + resp_str = g_slist_nth_data(tokens, 0); + if (!resp_str) { + err("invalid cms error data"); + tcore_at_tok_free(tokens); + return result; + } + cms_err = atoi(resp_str); + dbg("CMS error[%d]", cms_err); + + switch (cms_err) { + case 96: + result = TEL_SMS_RESULT_INVALID_MANDATORY_INFO; + break; + + case 208: + case 209: + case 211: + case 320: + case 321: + case 322: + result = TEL_SMS_RESULT_MEMORY_FAILURE; + break; + + case 42: + result = TEL_SMS_RESULT_NETWORK_CONGESTION; + break; + + case 17: + case 38: + case 287: + case 290: + case 331: + case 332: + case 538: + result = TEL_SMS_RESULT_NETWORK_FAILURE; + break; + + case 8: + case 10: + case 302: + case 303: + result = TEL_SMS_RESULT_OPERATION_NOT_SUPPORTED; + break; + + case 255: + case 500: + case 548: + case 547: + result = TEL_SMS_RESULT_UNKNOWN_FAILURE; + break; + + case 310: + case 311: + case 312: + case 313: + case 314: + case 315: + result = TEL_SMS_RESULT_SIM_FAILURE; + break; + + case 84: + case 95: + case 161: + case 176: + case 195: + case 304: + case 305: + case 516: + case 521: + case 524: + case 525: + case 526: + case 527: + case 528: + case 529: + case 530: + case 531: + case 532: + case 533: + case 534: + case 535: + result = TEL_SMS_RESULT_INVALID_PARAMETER; + break; + + default: + result = TEL_SMS_RESULT_FAILURE; + } + } + tcore_at_tok_free(tokens); + + return result; +} + +static TelSmsResult +__imc_sms_convert_cme_error_tel_sms_result(const TcoreAtResponse *at_resp) +{ + TelSmsResult result = TEL_SMS_RESULT_FAILURE; + const gchar *line; + GSList *tokens = NULL; + dbg("Entry"); + + if (!at_resp || !at_resp->lines) { + err("Invalid response data"); + return result; + } + + line = (const gchar *)at_resp->lines->data; + tokens = tcore_at_tok_new(line); + if (g_slist_length(tokens) > 0) { + gchar *resp_str; + gint cme_err; + + resp_str = g_slist_nth_data(tokens, 0); + if (!resp_str) { + err("Invalid CME Error data"); + tcore_at_tok_free(tokens); + return result; + } + cme_err = atoi(resp_str); + dbg("CME error[%d]", cme_err); + + switch (cme_err) { + case 3: + case 4: + result = TEL_SMS_RESULT_OPERATION_NOT_SUPPORTED; + break; + + case 10: + case 11: + case 12: + case 13: + case 14: + case 15: + case 17: + case 18: + result = TEL_SMS_RESULT_SIM_FAILURE; + break; + + case 20: + result = TEL_SMS_RESULT_MEMORY_FAILURE; + break; + + case 30: + case 31: + result = TEL_SMS_RESULT_NETWORK_FAILURE; + break; + + case 50: + result = TEL_SMS_RESULT_INVALID_PARAMETER; + break; + + case 100: + result = TEL_SMS_RESULT_UNKNOWN_FAILURE; + break; + + default: + result = TEL_SMS_RESULT_FAILURE; + } + } + tcore_at_tok_free(tokens); + + return result; +} + /* * Notification - SMS-DELIVER * +CMT = [], (PDU mode enabled) @@ -102,7 +286,8 @@ static gboolean on_notification_imc_sms_incoming_msg(CoreObject *co, return TRUE; } - line = (char *)g_slist_nth_data(lines, 0); /* Fetch Line 1 */ + /* Fetch Line 1 */ + line = (char *)g_slist_nth_data(lines, 0); if (!line) { err("Line 1 is invalid"); return TRUE; @@ -152,11 +337,11 @@ static gboolean on_notification_imc_sms_incoming_msg(CoreObject *co, guint encoded_sca_len; /* * byte_pdu[1] - sca_address_type - * Excluding sca_address_type and copy SCA + * Excluding sca_address_type and copy SCA */ encoded_sca_len = sca_length - 1; decoded_sca = - tcore_util_convert_bcd_to_ascii(&byte_pdu[2], encoded_sca_len, encoded_sca_len*2); + tcore_util_convert_bcd_to_ascii(&byte_pdu[2], encoded_sca_len, encoded_sca_len * 2); dbg("Decoded SCA: [%s]", decoded_sca); g_strlcpy(incoming_msg.sca.number, decoded_sca, strlen(decoded_sca)+1); tcore_free(decoded_sca); @@ -167,8 +352,7 @@ static gboolean on_notification_imc_sms_incoming_msg(CoreObject *co, dbg("TON: [%d] NPI: [%d] SCA: [%s]", incoming_msg.sca.ton, incoming_msg.sca.npi, incoming_msg.sca.number); - } - else { + } else { dbg("NO SCA Present"); } @@ -206,49 +390,49 @@ static gboolean on_notification_imc_sms_cb_incom_msg(CoreObject *co, guint byte_pdu_len = 0; GSList *lines = NULL; - TelSmsCbMsgInfo cb_noti = { 0, }; + TelSmsCbMsgInfo cb_noti = {0, }; dbg("Enter"); lines = (GSList *)event_info; - - line = (char *)(lines->data);/*Fetch Line 1*/ + /* Fetch Line 1 */ + line = (char *)(lines->data); if (line != NULL) { - tokens = tcore_at_tok_new(line); /* Split Line 1 into tokens */ + /* Split Line 1 into tokens */ + tokens = tcore_at_tok_new(line); line_token = g_slist_nth_data(tokens, 0); - if (line_token) { - cb_noti.length = atoi(line_token); - } else { - dbg("token 0 is NULL"); - tcore_at_tok_free(tokens); - return TRUE; + if (!line_token) { + err("invalid token"); + goto OUT; } - pdu = g_slist_nth_data(lines, 1); - if (pdu != NULL) { - cb_noti.cb_type = TEL_SMS_CB_MSG_GSM; - dbg("CB Msg LENGTH [%d]", cb_noti.length); + cb_noti.length = atoi(line_token); + pdu = g_slist_nth_data(lines, 1); + if (!pdu) { + err("NULL PDU Recieved "); + goto OUT; + } - if ((cb_noti.length > 0) && (TEL_SMS_CB_DATA_SIZE_MAX >= cb_noti.length)) { - tcore_util_hexstring_to_bytes(pdu, (gchar **)&byte_pdu, &byte_pdu_len); + cb_noti.cb_type = TEL_SMS_CB_MSG_GSM; + dbg("CB Msg LENGTH [%d]", cb_noti.length); - memcpy(cb_noti.cb_data, (char*)byte_pdu, cb_noti.length); - } else { - err("Invalid Message Length"); - tcore_at_tok_free(tokens); - return TRUE; - } + if ((cb_noti.length > 0) && (cb_noti.length <= TEL_SMS_CB_DATA_SIZE_MAX)) { + tcore_util_hexstring_to_bytes(pdu, (gchar **)&byte_pdu, &byte_pdu_len); + cb_noti.cb_data = tcore_malloc0(cb_noti.length + 1); + memcpy(cb_noti.cb_data, (char*)byte_pdu, cb_noti.length); } else { - err("NULL PDU Recieved "); - tcore_at_tok_free(tokens); - return TRUE; + err("Invalid Message Length"); + goto OUT; } + tcore_object_send_notification(co, - TCORE_NOTIFICATION_SMS_CB_INCOM_MSG, sizeof(TelSmsCbMsgInfo), &cb_noti); + TCORE_NOTIFICATION_SMS_CB_INCOM_MSG, + sizeof(TelSmsCbMsgInfo), &cb_noti); g_free(byte_pdu); + tcore_free(cb_noti.cb_data); } else { - err("Response NOK"); + err("Invalid Message received"); } - +OUT: tcore_at_tok_free(tokens); return TRUE; } @@ -285,12 +469,12 @@ static gboolean on_notification_imc_sms_memory_status(CoreObject *co, /* Send notification */ tcore_object_send_notification(co, - TCORE_NOTIFICATION_SMS_MEMORY_STATUS, - sizeof(gboolean), &memory_status); + TCORE_NOTIFICATION_SMS_MEMORY_STATUS, + sizeof(gboolean), &memory_status); } tcore_at_tok_free(tokens); } else { - err("Response NOK"); + err("invalid message received"); } return TRUE; @@ -301,93 +485,89 @@ static void on_response_imc_class2_sms_incom_msg(TcorePending *p, { const TcoreAtResponse *at_resp = data; CoreObject *co = tcore_pending_ref_core_object(p); - - TelSmsDatapackageInfo incoming_msg = { { 0 }, }; - - GSList *tokens=NULL; - char *gslist_line = NULL, *line_token = NULL, *byte_pdu = NULL, *hex_pdu = NULL; + GSList *tokens = NULL; + char *gslist_line = NULL, *line_token = NULL; + char *byte_pdu = NULL, *hex_pdu = NULL; gint sca_length = 0; guint byte_pdu_len = 0; + TelSmsDatapackageInfo incoming_msg = { { 0 }, }; dbg("Enter"); if (at_resp && at_resp->success) { dbg("RESPONSE OK"); - if (at_resp->lines) { - /* - * TCORE_AT_PDU: - * Multi-line output - * - * Fetching First Line - */ - gslist_line = (char *)at_resp->lines->data; - dbg("gslist_line: [%s]", gslist_line); + if (!at_resp->lines) { + err("Invalid Response Received"); + return; + } + /* + * TCORE_AT_PDU: + * Multi-line output + * + * Fetching First Line + */ + gslist_line = (char *)at_resp->lines->data; + dbg("gslist_line: [%s]", gslist_line); - /*Tokenize*/ - tokens = tcore_at_tok_new(gslist_line); - dbg("Number of tokens: [%d]", g_slist_length(tokens)); + /* Tokenize */ + tokens = tcore_at_tok_new(gslist_line); + dbg("Number of tokens: [%d]", g_slist_length(tokens)); - /* First Token : status - * Second Token: Alpha ID - not needed - */ - line_token = g_slist_nth_data(tokens, 2); /* Third Token: PDU Length */ - if (line_token != NULL) { - incoming_msg.tpdu_length = atoi(line_token); - dbg("Length: [%d]", incoming_msg.tpdu_length); - } - else { - err("Line Token for PDU Length is NULL"); - return; - } + /* First Token : status (ignore) + * Second Token: Alpha ID(ignore) + * Third Token: PDU Length. + */ + line_token = g_slist_nth_data(tokens, 2); + if (line_token != NULL) { + incoming_msg.tpdu_length = atoi(line_token); + dbg("Length: [%d]", incoming_msg.tpdu_length); + } else { + err("Line Token for PDU Length is NULL"); + tcore_at_tok_free(tokens); + return; + } - /* Fetching line: Second line is PDU */ - hex_pdu = (char *) at_resp->lines->next->data; - dbg("EF-SMS PDU: [%s]", hex_pdu); + /* Fetching line: Second line is PDU */ + hex_pdu = (char *) at_resp->lines->next->data; + dbg("EF-SMS PDU: [%s]", hex_pdu); - tcore_at_tok_free(tokens); /* free the consumed token */ - if (NULL != hex_pdu) { - tcore_util_hexstring_to_bytes(hex_pdu, &byte_pdu, &byte_pdu_len); + if (NULL != hex_pdu) { + tcore_util_hexstring_to_bytes(hex_pdu, &byte_pdu, &byte_pdu_len); + sca_length = (int)byte_pdu[0]; + dbg("SCA Length [%d], msgLength: [%d]", + sca_length, incoming_msg.tpdu_length); - sca_length = (int)byte_pdu[0]; + if (ZERO == sca_length) { + memcpy(incoming_msg.tpdu, &byte_pdu[1], + incoming_msg.tpdu_length); + } else { + char sca_toa; - dbg("SCA Length [%d], msgLength: [%d]", sca_length, incoming_msg.tpdu_length); + /* + * byte_pdu[1] - sca_address_type + * Excluding sca_address_type and copy SCA + */ + memcpy(incoming_msg.sca.number, &byte_pdu[2], + (sca_length - 1)); - if (ZERO == sca_length) { - memcpy(incoming_msg.tpdu, &byte_pdu[1], incoming_msg.tpdu_length); - } - else { - char sca_toa; - - /* - * byte_pdu[1] - sca_address_type - * Excluding sca_address_type and copy SCA - */ - memcpy(incoming_msg.sca.number, &byte_pdu[2], (sca_length-1)); - - /* - * SCA Conversion: Address Type - * 3GPP TS 23.040 V6.5.0 Section: 9.1.2.5 - */ - sca_toa = byte_pdu[1]; - incoming_msg.sca.npi = IMC_NUM_PLAN_ID(sca_toa); - incoming_msg.sca.ton = IMC_TYPE_OF_NUM(sca_toa); - - memcpy(incoming_msg.tpdu, - &byte_pdu[sca_length+1], - incoming_msg.tpdu_length); - } - } + /* + * SCA Conversion: Address Type + * 3GPP TS 23.040 V6.5.0 Section: 9.1.2.5 + */ + sca_toa = byte_pdu[1]; + incoming_msg.sca.npi = IMC_NUM_PLAN_ID(sca_toa); + incoming_msg.sca.ton = IMC_TYPE_OF_NUM(sca_toa); - tcore_object_send_notification(co, - TCORE_NOTIFICATION_SMS_INCOM_MSG, - sizeof(TelSmsDatapackageInfo), &incoming_msg); - tcore_at_tok_free(tokens); - g_free(byte_pdu); - } - else { - err("Invalid Response Received"); + memcpy(incoming_msg.tpdu,&byte_pdu[sca_length+1], + incoming_msg.tpdu_length); + } } - } - else { + + tcore_object_send_notification(co, + TCORE_NOTIFICATION_SMS_INCOM_MSG, + sizeof(TelSmsDatapackageInfo), &incoming_msg); + tcore_at_tok_free(tokens); + g_free(byte_pdu); + } else { err("RESPONSE NOK"); } } @@ -400,29 +580,34 @@ static void on_response_imc_class2_sms_incom_msg(TcorePending *p, * memory location * index where msg is stored */ -static gboolean on_notification_imc_sms_class2_incoming_msg(CoreObject *co, const void *event_info, void *user_data) +static gboolean on_notification_imc_sms_class2_incoming_msg(CoreObject *co, + const void *event_info, void *user_data) { - gchar *at_cmd; + gchar *at_cmd = NULL; TelReturn ret; - GSList *tokens = NULL , *lines = NULL; char *line = NULL; gint index, mem_type = 0; dbg("Enter"); lines = (GSList *)event_info; - line = (char *)g_slist_nth_data(lines, 0); /* Fetch Line 1 */ + /* Fetch Line 1 */ + line = (char *)g_slist_nth_data(lines, 0); if (!line) { err("Line 1 is invalid"); return TRUE; } dbg("Line 1: [%s]", line); - tokens = tcore_at_tok_new(line); /* Split Line 1 into tokens */ - mem_type = atoi(g_slist_nth_data(tokens, 0));/* Type of Memory stored */ - dbg("mem_type=[%d]", mem_type); + /* Split Line 1 into tokens */ + tokens = tcore_at_tok_new(line); + /* Type of Memory stored */ + mem_type = atoi(g_slist_nth_data(tokens, 0)); + dbg("mem_type = [%d]", mem_type); index = atoi((char *) g_slist_nth_data(tokens, 1)); dbg("index: [%d]", index); + /* Free resources */ + tcore_at_tok_free(tokens); /* * Operation - read_sms_in_sim @@ -439,7 +624,8 @@ static gboolean on_notification_imc_sms_class2_incoming_msg(CoreObject *co, cons * Failure: * +CMS ERROR: */ - /*AT Command*/ + + /* AT Command */ at_cmd = g_strdup_printf("AT+CMGR=%d", index); /* Send Request to modem */ @@ -449,6 +635,7 @@ static gboolean on_notification_imc_sms_class2_incoming_msg(CoreObject *co, cons NULL, on_response_imc_class2_sms_incom_msg, NULL, on_send_imc_request, NULL); + if (ret != TEL_RETURN_SUCCESS) { err("Failed to Read Class2 Incomming Message"); } @@ -478,7 +665,7 @@ static void on_response_imc_sms_send_sms(TcorePending *p, CoreObject *co = tcore_pending_ref_core_object(p); ImcRespCbData *resp_cb_data = user_data; - TelSmsResult result = TEL_SMS_RESULT_FAILURE;/*TODO: CMS error mapping required */ + TelSmsResult result = TEL_SMS_RESULT_FAILURE; dbg("Enter"); tcore_check_return_assert(co != NULL); @@ -496,22 +683,23 @@ static void on_response_imc_sms_send_sms(TcorePending *p, tokens = tcore_at_tok_new(line); line_token = g_slist_nth_data(tokens, 0); if (line_token != NULL) { - /*Response from MODEM for send SMS: +CMGS: [,]*/ - /*Message Reference is not used by MSG_SERVER and application.So Filling only result*/ + /* Response from MODEM for send SMS: +CMGS: + * [,]. + * + * Message Reference is not used by MSG_SERVER, + * and application. So Filling only result + */ msg_ref = atoi(line_token); - dbg("Message Reference: [%d]", msg_ref); - result = TEL_SMS_RESULT_SUCCESS; - } - else { - dbg("No Message Reference received"); + } else { + err("No Message Reference received"); } tcore_at_tok_free(tokens); } - } - else { - err("Response NOK"); + } else { + err("RESPONSE NOK"); + result = __imc_sms_convert_cms_error_tel_sms_result(at_resp); } /* Invoke callback */ @@ -530,35 +718,32 @@ static void on_response_imc_sms_write_sms_in_sim(TcorePending *p, ImcRespCbData *resp_cb_data = user_data; TelSmsResult result = TEL_SMS_RESULT_FAILURE; - GSList *tokens = NULL; char *line = NULL, *line_token = NULL; - guint index = -1; - + gint index = -1; dbg("Enter"); + tcore_check_return_assert(co != NULL); + tcore_check_return_assert(resp_cb_data != NULL); if (at_resp && at_resp->success) { dbg("Response OK"); if (at_resp->lines) { - line = (char *)at_resp->lines->data; + line = (char *)at_resp->lines->data; tokens = tcore_at_tok_new(line); line_token = g_slist_nth_data(tokens, 0); if (line_token) { - index = (atoi(line_token)); + index = atoi(line_token); dbg("SMS written to '%d' index", index); result = TEL_SMS_RESULT_SUCCESS; + } else { + err("invalid message"); } - else { - dbg("No Tokens"); - result = TEL_SMS_RESULT_FAILURE; - } - } - else { + } else { err("Lines NOT present"); } - } - else { - dbg("Response NOK"); + } else { + err("RESPONSE NOK"); + result = __imc_sms_convert_cms_error_tel_sms_result(at_resp); } /* Invoke callback */ @@ -575,42 +760,47 @@ static void on_response_imc_sms_read_sms_in_sim(TcorePending *p, const TcoreAtResponse *at_resp = data; CoreObject *co = tcore_pending_ref_core_object(p); ImcRespCbData *resp_cb_data = user_data; - TelSmsSimDataInfo read_resp; + TelSmsSimDataInfo read_resp = {0,}; GSList *tokens = NULL; - TelSmsResult result = TEL_SMS_RESULT_FAILURE;/* CMS error mapping required */ + TelSmsResult result = TEL_SMS_RESULT_FAILURE; dbg("Enter"); - memset(&read_resp, 0x0, sizeof(TelSmsSimDataInfo)); + tcore_check_return_assert(co != NULL); + tcore_check_return_assert(resp_cb_data != NULL); if (at_resp && at_resp->success) { dbg("RESPONSE OK"); if (at_resp->lines) { - char *gslist_line = NULL,*line_token = NULL,*byte_pdu = NULL,*hex_pdu = NULL; + gchar *gslist_line = NULL, *line_token = NULL; + gchar *byte_pdu = NULL, *hex_pdu = NULL; gint msg_status = 0, pdu_len = 0, alpha_id = 0; + gint sca_length = 0; + guint byte_pdu_len = 0; /* * TCORE_AT_PDU: - * Multi-line output + * Multi-line output * * Fetching First Line */ gslist_line = (char *)at_resp->lines->data; dbg("gslist_line: [%s]", gslist_line); - /*Tokenize*/ + /* Tokenize */ tokens = tcore_at_tok_new(gslist_line); dbg("Number of tokens: [%d]", g_slist_length(tokens)); - /*+CMGR: ,[],*/ - line_token = g_slist_nth_data(tokens, 0); /*First Token: Message status*/ + /* +CMGR: ,[], */ + /* First Token: Message status */ + line_token = g_slist_nth_data(tokens, 0); if (line_token == NULL) { err("Invalid stat"); goto OUT; } msg_status = atoi(line_token); - dbg("msg_status is %d",msg_status); + dbg("msg_status [%d]", msg_status); switch (msg_status) { case AT_MT_UNREAD: @@ -631,14 +821,14 @@ static void on_response_imc_sms_read_sms_in_sim(TcorePending *p, break; } - /*Second Token: Alpha ID*/ + /* Second Token: Alpha ID */ line_token = g_slist_nth_data(tokens, 1); if (line_token != NULL) { alpha_id = atoi(line_token); dbg("alpha_id: [%d]", alpha_id); } - /*Third Token: Length*/ + /* Third Token: Length */ line_token = g_slist_nth_data(tokens, 2); if (line_token == NULL) { err("Invalid PDU length"); @@ -647,66 +837,67 @@ static void on_response_imc_sms_read_sms_in_sim(TcorePending *p, pdu_len = atoi(line_token); dbg("PDU length: [%d]", pdu_len); - /*Fetching line: Second line is PDU*/ + /* Fetching line: Second line is PDU */ hex_pdu = (char *) at_resp->lines->next->data; dbg("EF-SMS PDU: [%s]", hex_pdu); - if (NULL != hex_pdu) { - gint sca_length = 0; - guint byte_pdu_len = 0; - - tcore_util_hex_dump(" ", sizeof(hex_pdu), (void *)hex_pdu); - - tcore_util_hexstring_to_bytes(hex_pdu, &byte_pdu, &byte_pdu_len); - - sca_length = byte_pdu[0]; - dbg("SCA length = %d", sca_length); - if (sca_length) { - gchar *decoded_sca; - guint encoded_sca_len; - - /* - * byte_pdu[1] - sca_address_type - * Excluding sca_address_type and copy SCA - */ - encoded_sca_len = sca_length - 1; - decoded_sca = - tcore_util_convert_bcd_to_ascii(&byte_pdu[2], - encoded_sca_len, encoded_sca_len*2); - - dbg("Decoded SCA: [%s]", decoded_sca); - memcpy(read_resp.data.sca.number, decoded_sca, TEL_SMS_SCA_LEN_MAX); - tcore_free(decoded_sca); - - /*SCA Conversion for Address type*/ - read_resp.data.sca.ton = IMC_TYPE_OF_NUM(byte_pdu[1]); - read_resp.data.sca.npi = IMC_NUM_PLAN_ID(byte_pdu[1]); - dbg("TON: [%d] NPI: [%d] SCA: [%s]", - read_resp.data.sca.ton, read_resp.data.sca.npi, - read_resp.data.sca.number); - } else { - err("NO SCA Present"); - } + if (NULL == hex_pdu) { + err("Invalid Response Received"); + goto OUT; + } - /* TPDU */ - read_resp.data.tpdu_length = pdu_len; - if ((read_resp.data.tpdu_length > 0) - && (read_resp.data.tpdu_length <= TEL_SMS_SMDATA_SIZE_MAX)) { - memcpy(read_resp.data.tpdu, &byte_pdu[sca_length+1], - read_resp.data.tpdu_length); - } else { - warn("Invalid TPDU length: [%d]", read_resp.data.tpdu_length); - } + tcore_util_hex_dump(" ", sizeof(hex_pdu), (void *)hex_pdu); - result = TEL_SMS_RESULT_SUCCESS; - g_free(byte_pdu); + tcore_util_hexstring_to_bytes(hex_pdu, &byte_pdu, &byte_pdu_len); + + sca_length = byte_pdu[0]; + dbg("SCA length = %d", sca_length); + if (sca_length) { + gchar *decoded_sca; + guint encoded_sca_len; + + /* + * byte_pdu[1] - sca_address_type + * Excluding sca_address_type and copy SCA + */ + encoded_sca_len = sca_length - 1; + decoded_sca = + tcore_util_convert_bcd_to_ascii(&byte_pdu[2], + encoded_sca_len, encoded_sca_len * 2); + + dbg("Decoded SCA: [%s]", decoded_sca); + memcpy(read_resp.data.sca.number, decoded_sca, + TEL_SMS_SCA_LEN_MAX); + tcore_free(decoded_sca); + + /* SCA Conversion for Address type */ + read_resp.data.sca.ton = IMC_TYPE_OF_NUM(byte_pdu[1]); + read_resp.data.sca.npi = IMC_NUM_PLAN_ID(byte_pdu[1]); + dbg("TON: [%d] NPI: [%d] SCA: [%s]", + read_resp.data.sca.ton, read_resp.data.sca.npi, + read_resp.data.sca.number); + } else { + err("NO SCA Present"); } - } else { - err("Invalid Response Received"); + + /* TPDU */ + read_resp.data.tpdu_length = pdu_len; + if ((read_resp.data.tpdu_length > 0) + && (read_resp.data.tpdu_length <= TEL_SMS_SMDATA_SIZE_MAX)) { + memcpy(read_resp.data.tpdu, &byte_pdu[sca_length+1], + read_resp.data.tpdu_length); + } else { + warn("Invalid TPDU length: [%d]", + read_resp.data.tpdu_length); + } + + result = TEL_SMS_RESULT_SUCCESS; + g_free(byte_pdu); } - } - else { + + } else { err("RESPONSE NOK"); + result = __imc_sms_convert_cms_error_tel_sms_result(at_resp); } OUT: /* Invoke callback */ @@ -716,7 +907,7 @@ OUT: /* Free callback data */ imc_destroy_resp_cb_data(resp_cb_data); - /*free the consumed token*/ + /* free the consumed token */ tcore_at_tok_free(tokens); } @@ -731,13 +922,14 @@ static void on_response_imc_sms_delete_sms_in_sim(TcorePending *p, dbg("Enter"); tcore_check_return_assert(co != NULL); + tcore_check_return_assert(resp_cb_data != NULL); if (at_resp && at_resp->success) { dbg("Response OK"); result = TEL_SMS_RESULT_SUCCESS; - } - else { - dbg("Response NOK"); + } else { + err("RESPONSE NOK"); + result = __imc_sms_convert_cms_error_tel_sms_result(at_resp); } /* Invoke callback */ @@ -751,20 +943,22 @@ static void on_response_imc_sms_delete_sms_in_sim(TcorePending *p, static void on_response_imc_sms_get_msg_indices(TcorePending *p, guint data_len, const void *data, void *user_data) { - TelSmsStoredMsgCountInfo *count_info;/*Response from get_count Request*/ - TelSmsResult result = TEL_SMS_RESULT_FAILURE;/*TODO: CMS error mapping required */ - + /* Response from get_count Request */ + TelSmsStoredMsgCountInfo *count_info; const TcoreAtResponse *at_resp = data; CoreObject *co = tcore_pending_ref_core_object(p); ImcRespCbData *resp_cb_data = user_data; + TelSmsResult result = TEL_SMS_RESULT_FAILURE; dbg("Enter"); + tcore_check_return_assert(co != NULL); + tcore_check_return_assert(resp_cb_data != NULL); count_info = (TelSmsStoredMsgCountInfo *)IMC_GET_DATA_FROM_RESP_CB_DATA(resp_cb_data); if (at_resp && at_resp->success) { dbg("RESPONSE OK"); if (at_resp->lines) { - char *gslist_line = NULL; + gchar *gslist_line = NULL; gint gslist_line_count = 0, ctr_loop = 0; gslist_line_count = g_slist_length(at_resp->lines); @@ -780,41 +974,42 @@ static void on_response_imc_sms_get_msg_indices(TcorePending *p, if (NULL != gslist_line) { GSList *tokens = NULL; - char *line_token = NULL; + gchar *line_token = NULL; tokens = tcore_at_tok_new(gslist_line); line_token = g_slist_nth_data(tokens, 0); if (NULL != line_token) { - count_info->index_list[ctr_loop] = atoi(line_token); - } - else { - dbg("line_token of gslist_line [%d] is NULL", ctr_loop); + count_info->index_list[ctr_loop] = + atoi(line_token); + } else { + dbg("line_token of gslist_line [%d] is NULL", + ctr_loop); } tcore_at_tok_free(tokens); - } - else { + } else { err("gslist_line is NULL"); - goto ERROR; + goto OUT; } } result = TEL_SMS_RESULT_SUCCESS; - } - else { - err("Invalid Response received. No Lines present in Response"); - + } else { + err("Invalid Response received. No Lines present in response"); /* Check if used count is zero*/ if (count_info->used_count == 0) result = TEL_SMS_RESULT_SUCCESS; } - } - else { + } else { err("RESPONSE NOK"); + result = __imc_sms_convert_cms_error_tel_sms_result(at_resp); } -ERROR: +OUT: + dbg("get msg indices: [%s]", + (result == TEL_SMS_RESULT_SUCCESS ? "SUCCESS" : "FAIL")); + /* Invoke callback */ if (resp_cb_data->cb) resp_cb_data->cb(co, (gint)result, count_info, resp_cb_data->cb_data); @@ -828,121 +1023,119 @@ static void on_response_imc_sms_get_sms_count(TcorePending *p, { gchar *at_cmd; TelReturn ret; - TelSmsStoredMsgCountInfo count_info = {0, }; - TelSmsResult result = TEL_SMS_RESULT_FAILURE; int used_count = 0, total_count = 0; - const TcoreAtResponse *at_resp = data; CoreObject *co = tcore_pending_ref_core_object(p); ImcRespCbData *resp_cb_data = user_data; ImcRespCbData *getcnt_resp_cb_data; + TelSmsResult result = TEL_SMS_RESULT_FAILURE; dbg("Enter"); + tcore_check_return_assert(co != NULL); + tcore_check_return_assert(resp_cb_data != NULL); + if (at_resp && at_resp->success) { dbg("RESPONSE OK"); if (at_resp->lines) { GSList *tokens = NULL; - char *line = NULL, *line_token = NULL; + gchar *line = NULL, *line_token = NULL; - line = (char *)at_resp->lines->data; - dbg("line: [%s]",line); + line = (gchar *)at_resp->lines->data; + dbg("line: [%s]", line); /* * Tokenize * - * +CPMS: , , , , , + * +CPMS: , , , , + * , */ tokens = tcore_at_tok_new(line); /* */ line_token = g_slist_nth_data(tokens, 0); - if (line_token) { - used_count =atoi(line_token); - dbg("used cnt is %d",used_count); - } - else { + if (!line_token) { err("Line Token for used count is NULL"); tcore_at_tok_free(tokens); - goto ERROR; + goto OUT; } + used_count = atoi(line_token); + dbg("used count [%d]", used_count); /* */ line_token = g_slist_nth_data(tokens, 1); - if (line_token) { - total_count = atoi(line_token); + if (!line_token) { + err("Line Token for Total count is NULL"); + tcore_at_tok_free(tokens); + goto OUT; + } + total_count = atoi(line_token); + count_info.total_count = total_count; + count_info.used_count = used_count; + dbg("Count - used: [%d] total: [%d]", used_count, total_count); - count_info.total_count = total_count; - count_info.used_count = used_count; - dbg("Count - used: [%d] total: [%d]", used_count, total_count); + /* + * Operation - get_msg_indices_in_sim + * + * Request - + * AT-Command: AT+CMGL + * +CPMS=[, [,]] + * where + * memory storage to read. + * + * Response - + * Success: (Multi-line output) + * +CMGL=] + * + * status of the message. + * Failure: + * +CMS ERROR: + */ - /* - * Operation - get_msg_indices_in_sim - * - * Request - - * AT-Command: AT+CMGL - * +CPMS=[, [,]] - * where - * memory storage to read. - * - * Response - - * Success: (Multi-line output) - * +CMGL=] - * - * status of the message. - * Failure: - * +CMS ERROR: - */ - - /* Sending the Second AT Request to fetch msg indices */ - at_cmd = g_strdup_printf("AT+CMGL=4"); - - /* Response callback data */ - getcnt_resp_cb_data = imc_create_resp_cb_data(resp_cb_data->cb, - resp_cb_data->cb_data, - &count_info, sizeof(TelSmsStoredMsgCountInfo)); - - /* Free previous request callback data */ - imc_destroy_resp_cb_data(resp_cb_data); + /* Sending the Second AT Request to fetch msg indices */ + at_cmd = g_strdup_printf("AT+CMGL=4"); - /* Send Request to modem */ - ret = tcore_at_prepare_and_send_request(co, - at_cmd, "+CMGL", - TCORE_AT_COMMAND_TYPE_MULTILINE, - NULL, - on_response_imc_sms_get_msg_indices, getcnt_resp_cb_data, - on_send_imc_request, NULL); + /* Response callback data */ + getcnt_resp_cb_data = imc_create_resp_cb_data(resp_cb_data->cb, + resp_cb_data->cb_data, + &count_info, sizeof(TelSmsStoredMsgCountInfo)); - /* free the consumed token */ - tcore_at_tok_free(tokens); - g_free(at_cmd); + /* Free previous request callback data */ + imc_destroy_resp_cb_data(resp_cb_data); + resp_cb_data = NULL; + /* free the consumed token */ + tcore_at_tok_free(tokens); - IMC_CHECK_REQUEST_RET(ret, getcnt_resp_cb_data, "Get Indices in SIM"); - if (ret != TEL_RETURN_SUCCESS) { - err("Failed to Process Get Msg Indices Request"); - goto ERROR; - } + /* Send Request to modem */ + ret = tcore_at_prepare_and_send_request(co, + at_cmd, "+CMGL", + TCORE_AT_COMMAND_TYPE_MULTILINE, + NULL, + on_response_imc_sms_get_msg_indices, + getcnt_resp_cb_data, + on_send_imc_request, NULL); - dbg("Exit"); - return; + g_free(at_cmd); + if (ret != TEL_RETURN_SUCCESS) { + err("Failed to Process Get Msg Indices Request"); + imc_destroy_resp_cb_data(getcnt_resp_cb_data); + goto OUT; } - else { - err("Line Token for Total count is NULL"); + dbg("Exit"); + return; - /* free the consumed token */ - tcore_at_tok_free(tokens); - goto ERROR; - } - } - else { + } else { err("Invalid Response Received: NO Lines Present"); } - } - else { + } else { err("RESPONSE NOK"); + result = __imc_sms_convert_cms_error_tel_sms_result(at_resp); } -ERROR: +OUT: + dbg("Get sms count: [%s]", + (result == TEL_SMS_RESULT_SUCCESS ? "SUCCESS" : "FAIL")); + /* Invoke callback in case of error*/ if (resp_cb_data->cb) resp_cb_data->cb(co, (gint)result, NULL, resp_cb_data->cb_data); @@ -961,14 +1154,19 @@ static void on_response_imc_sms_set_sca(TcorePending *p, TelSmsResult result = TEL_SMS_RESULT_FAILURE; dbg("Enter"); + tcore_check_return_assert(co != NULL); + tcore_check_return_assert(resp_cb_data != NULL); + if (at_resp && at_resp->success) { dbg("Response OK"); result = TEL_SMS_RESULT_SUCCESS; - } - else { + } else { err("Response NOK"); } + dbg("Set sca: [%s]", + (result == TEL_SMS_RESULT_SUCCESS ? "SUCCESS" : "FAIL")); + /* Invoke callback */ if (resp_cb_data->cb) resp_cb_data->cb(co, (gint)result, NULL, resp_cb_data->cb_data); @@ -988,15 +1186,19 @@ static void on_response_imc_sms_get_sca(TcorePending *p, TelSmsResult result = TEL_SMS_RESULT_FAILURE; dbg("Enter"); + tcore_check_return_assert(co != NULL); + tcore_check_return_assert(resp_cb_data != NULL); + if (at_resp && at_resp->success) { dbg("Response OK"); if (at_resp->lines) { GSList *tokens = NULL; const char *sca_tok_addr; - gchar *line = NULL, *sca_addr = NULL, *sca_toa = NULL; + gchar *line = NULL, *sca_addr = NULL; gint hexa_toa = 0; + gchar *sca_toa = NULL; - line = (char *)at_resp->lines->data; + line = (gchar *)at_resp->lines->data; tokens = tcore_at_tok_new(line); sca_tok_addr = g_slist_nth_data(tokens, 0); sca_toa = g_slist_nth_data(tokens, 1); @@ -1011,21 +1213,22 @@ static void on_response_imc_sms_get_sca(TcorePending *p, sca_resp.npi = hexa_toa & 0x0F; sca_resp.ton = (hexa_toa & 0x70) >> 4; result = TEL_SMS_RESULT_SUCCESS; - } - else { + } else { err("SCA is NULL"); } tcore_at_tok_free(tokens); g_free(sca_addr); + } else { + err("Invalid RESPONSE. No Lines Received"); } - else { - err("Invalid Response.No Lines Received"); - } - } - else { - err("Response NOK"); + } else { + err("RESPONSE NOK"); + result = __imc_sms_convert_cms_error_tel_sms_result(at_resp); } + dbg("Get sca: [%s]", + (result == TEL_SMS_RESULT_SUCCESS ? "SUCCESS" : "FAIL")); + /* Invoke callback */ if (resp_cb_data->cb) resp_cb_data->cb(co, (gint)result, &sca_resp, resp_cb_data->cb_data); @@ -1041,16 +1244,22 @@ static void on_response_imc_sms_set_cb_config(TcorePending *p, CoreObject *co = tcore_pending_ref_core_object(p); ImcRespCbData *resp_cb_data = user_data; - TelSmsResult result = TEL_SMS_RESULT_FAILURE;/*TODO: CME error mapping required */ + TelSmsResult result = TEL_SMS_RESULT_FAILURE; dbg("Enter"); + tcore_check_return_assert(co != NULL); + tcore_check_return_assert(resp_cb_data != NULL); + if (at_resp && at_resp->success) { dbg("Response OK"); result = TEL_SMS_RESULT_SUCCESS; + } else { + err("RESPONSE NOK"); + result = __imc_sms_convert_cme_error_tel_sms_result(at_resp); } - else { - err("Response NOK"); - } + + dbg("Set cb config: [%s]", + (result == TEL_SMS_RESULT_SUCCESS ? "SUCCESS" : "FAIL")); /* Invoke callback */ if (resp_cb_data->cb) @@ -1067,104 +1276,110 @@ static void on_response_imc_sms_get_cb_config(TcorePending *p, CoreObject *co = tcore_pending_ref_core_object(p); ImcRespCbData *resp_cb_data = user_data; - GSList *cb_tokens = NULL; - char *cb_str_token = NULL; - int num_cb_tokens = 0; - char *mid_tok = NULL; - char *first_tok = NULL, *second_tok = NULL; - gint i = 0, mode = 0; - char delim[] = "-"; - TelSmsCbConfigInfo get_cb_conf = {0, }; TelSmsResult result = TEL_SMS_RESULT_FAILURE; dbg("Enter"); + tcore_check_return_assert(co != NULL); + tcore_check_return_assert(resp_cb_data != NULL); + if (at_resp && at_resp->success) { dbg("Response OK"); if (at_resp->lines) { GSList *tokens = NULL; - char *line_token = NULL, *line = NULL; - line = (char*)at_resp->lines->data; - if (line != NULL) { - tokens = tcore_at_tok_new(line); - /* - * Response - - * +CSCB: ,, - */ - line_token = g_slist_nth_data(tokens, 0); - if (line_token) { - mode = atoi(line_token); - dbg("mode:[%d]", mode); - get_cb_conf.cb_enabled = mode; - } - else { - err("Line Token for Mode is NULL"); - tcore_at_tok_free(tokens); - goto OUT; - } - line_token = g_slist_nth_data(tokens, 1); - if (line_token) { - cb_str_token = tcore_at_tok_extract(line_token); - cb_tokens = tcore_at_tok_new((const char *)cb_str_token); - - num_cb_tokens = g_slist_length(cb_tokens); - dbg("num_cb_tokens = %d", num_cb_tokens); - if (num_cb_tokens == 0) { - if (mode == 1) { /* All CBS Enabled */ - get_cb_conf.msg_id_range_cnt = 1; - get_cb_conf.msg_ids[0].from_msg_id = 0x0000; - get_cb_conf.msg_ids[0].to_msg_id = TEL_SMS_GSM_CBMI_LIST_SIZE_MAX + 1; - get_cb_conf.msg_ids[0].selected = TRUE; - } - else { /* All CBS Disabled */ - get_cb_conf.msg_id_range_cnt = 0; - get_cb_conf.msg_ids[0].selected = FALSE; - } - } + gchar *data = NULL, *line = NULL; + gchar *msg_ids = NULL; + GSList *cb_tokens = NULL; + gint num_cb_tokens = 0; + gchar *mid_tok = NULL; + gint i = 0, mode = 0; + gchar *first_tok = NULL, *second_tok = NULL; + gchar delim[] = "-"; + + line = (gchar*)at_resp->lines->data; + if (!line) { + err("Line is NULL"); + goto OUT; + } - for(i = 0; i < num_cb_tokens; i++) { - get_cb_conf.msg_ids[i].selected = TRUE; - dbg("msgIdRangeCount:[%d]", get_cb_conf.msg_id_range_cnt); - get_cb_conf.msg_id_range_cnt++; - dbg("Incremented msgIdRangeCount:[%d]", get_cb_conf.msg_id_range_cnt); - - mid_tok = tcore_at_tok_nth(cb_tokens, i); - first_tok = strtok(mid_tok, delim); - second_tok = strtok(NULL, delim); - - if ((first_tok != NULL) && (second_tok != NULL)) {/* mids in range (320-478) */ - get_cb_conf.msg_ids[i].from_msg_id = atoi(first_tok); - get_cb_conf.msg_ids[i].to_msg_id = atoi(second_tok); - } - else {/* single mid value (0,1,5, 922)*/ - get_cb_conf.msg_ids[i].from_msg_id = atoi(mid_tok); - get_cb_conf.msg_ids[i].to_msg_id = atoi(mid_tok); - } - } - } - else { - err("Line Token for MID is NULL"); - tcore_at_tok_free(tokens); - goto OUT; + tokens = tcore_at_tok_new(line); + /* + * Response - + * +CSCB: ,, + */ + data = g_slist_nth_data(tokens, 0); + if (data) { + mode = atoi(data); + dbg("mode:[%d]", mode); + get_cb_conf.cb_enabled = mode; + } else { + err("Line Token for Mode is NULL"); + tcore_at_tok_free(tokens); + goto OUT; + } + + data = g_slist_nth_data(tokens, 1); + if (!data) { + err("Line Token for MID is NULL"); + tcore_at_tok_free(tokens); + goto OUT; + } + msg_ids = tcore_at_tok_extract(data); + cb_tokens = tcore_at_tok_new((const char *)msg_ids); + num_cb_tokens = g_slist_length(cb_tokens); + dbg("num_cb_tokens = %d", num_cb_tokens); + + if (num_cb_tokens == 0) { + if (mode == 1) { /* All CBS Enabled */ + get_cb_conf.msg_id_range_cnt = 1; + get_cb_conf.msg_ids[0].from_msg_id = 0x0000; + get_cb_conf.msg_ids[0].to_msg_id = + TEL_SMS_GSM_CBMI_LIST_SIZE_MAX + 1; + get_cb_conf.msg_ids[0].selected = TRUE; + } else { /* All CBS Disabled */ + get_cb_conf.msg_id_range_cnt = 0; + get_cb_conf.msg_ids[0].selected = FALSE; } } - else { - err("Line is NULL"); + + for (i = 0; i < num_cb_tokens; i++) { + get_cb_conf.msg_ids[i].selected = TRUE; + dbg("msgIdRangeCount:[%d]", get_cb_conf.msg_id_range_cnt); + + get_cb_conf.msg_id_range_cnt++; + dbg("Incremented msgIdRangeCount:[%d]", + get_cb_conf.msg_id_range_cnt); + + mid_tok = tcore_at_tok_nth(cb_tokens, i); + first_tok = strtok(mid_tok, delim); + second_tok = strtok(NULL, delim); + + /* mids in range (320-478) */ + if ((first_tok != NULL) && (second_tok != NULL)) { + get_cb_conf.msg_ids[i].from_msg_id = atoi(first_tok); + get_cb_conf.msg_ids[i].to_msg_id = atoi(second_tok); + } else { /* single mid value (0,1,5, 922)*/ + get_cb_conf.msg_ids[i].from_msg_id = atoi(mid_tok); + get_cb_conf.msg_ids[i].to_msg_id = atoi(mid_tok); + } } + result = TEL_SMS_RESULT_SUCCESS; tcore_at_tok_free(tokens); tcore_at_tok_free(cb_tokens); - g_free(cb_str_token); - } - else { + g_free(msg_ids); + } else { err("Invalid Response.No Lines Received"); } - } - else { - err("Response NOK"); + } else { + err("RESPONSE NOK"); + result = __imc_sms_convert_cme_error_tel_sms_result(at_resp); } OUT: + dbg("Get cb config: [%s]", + (result == TEL_SMS_RESULT_SUCCESS ? "SUCCESS" : "FAIL")); + /* Invoke callback */ if (resp_cb_data->cb) resp_cb_data->cb(co, (gint)result, &get_cb_conf, resp_cb_data->cb_data); @@ -1183,14 +1398,19 @@ static void on_response_imc_sms_set_memory_status(TcorePending *p, TelSmsResult result = TEL_SMS_RESULT_FAILURE; dbg("Enter"); + tcore_check_return_assert(co != NULL); + tcore_check_return_assert(resp_cb_data != NULL); + if (at_resp && at_resp->success) { dbg("Response OK"); result = TEL_SMS_RESULT_SUCCESS; - } - else { - err("Response NOK"); + } else { + err("RESPONSE NOK"); + result = __imc_sms_convert_cme_error_tel_sms_result(at_resp); } + dbg("Set memory status: [%s]", + (result == TEL_SMS_RESULT_SUCCESS ? "SUCCESS" : "FAIL")); /* Invoke callback */ if (resp_cb_data->cb) resp_cb_data->cb(co, (gint)result, NULL, resp_cb_data->cb_data); @@ -1207,50 +1427,55 @@ static void on_response_imc_sms_set_message_status(TcorePending *p, ImcRespCbData *resp_cb_data = user_data; TelSmsResult result = TEL_SMS_RESULT_FAILURE; - int response = 0, sw1 = 0, sw2 = 0; - const char *line = NULL; - char *line_token = NULL; - GSList *tokens = NULL; dbg("Enter"); + tcore_check_return_assert(co != NULL); + tcore_check_return_assert(resp_cb_data != NULL); + if (at_resp && at_resp->success) { dbg("RESPONSE OK"); if (at_resp->lines) { + gint response = 0, sw1 = 0, sw2 = 0; + const char *line = NULL; + gchar *data = NULL; + GSList *tokens = NULL; + line = (const char *) at_resp->lines->data; tokens = tcore_at_tok_new(line); - line_token = g_slist_nth_data(tokens, 0); - if (line_token != NULL) { - sw1 = atoi(line_token); - } - else { + data = g_slist_nth_data(tokens, 0); + if (data != NULL) { + sw1 = atoi(data); + } else { dbg("sw1 is NULL"); } - line_token = g_slist_nth_data(tokens, 1); - if (line_token != NULL) { - sw2 = atoi(line_token); + + data = g_slist_nth_data(tokens, 1); + if (data != NULL) { + sw2 = atoi(data); if ((sw1 == 0x90) && (sw2 == 0)) { result = TEL_SMS_RESULT_SUCCESS; } - } - else { + } else { dbg("sw2 is NULL"); } - line_token = g_slist_nth_data(tokens, 3); - if (line_token != NULL) { - response = atoi(line_token); + data = g_slist_nth_data(tokens, 3); + if (data != NULL) { + response = atoi(data); dbg("response is %s", response); } tcore_at_tok_free(tokens); + } else { + err("No lines"); } - else { - dbg("No lines"); - } - } - else { - err("RESPONSE NOK"); + } else { + err("RESPONSE NOK"); + result = __imc_sms_convert_cme_error_tel_sms_result(at_resp); } + dbg("Set message status: [%s]", + (result == TEL_SMS_RESULT_SUCCESS ? "SUCCESS" : "FAIL")); + /* Invoke callback */ if (resp_cb_data->cb) resp_cb_data->cb(co, (gint)result, NULL, resp_cb_data->cb_data); @@ -1270,30 +1495,37 @@ static void _response_get_efsms_data(TcorePending *p, TelSmsStatusInfo *status_info; TelSmsResult result = TEL_SMS_RESULT_FAILURE; TelReturn ret; - - char *encoded_data = NULL; - int encoded_len = 0; - char msg_status = 0; - char *line_token = NULL; - GSList *tokens=NULL; - const char *line = NULL; - int sw1 = 0; - int sw2 = 0; dbg("Enter"); + tcore_check_return_assert(co != NULL); + tcore_check_return_assert(resp_cb_data != NULL); + status_info = (TelSmsStatusInfo *)IMC_GET_DATA_FROM_RESP_CB_DATA(resp_cb_data); if (at_resp && at_resp->success) { dbg("RESPONSE OK"); if (at_resp->lines) { - dbg("Entry:lines Ok"); + char *encoded_data = NULL; + int encoded_len = 0; + char msg_status = 0; + char *line_token = NULL; + GSList *tokens = NULL; + const char *line = NULL; + gint sw1 = 0, sw2 = 0; + line = (const char *) at_resp->lines->data; tokens = tcore_at_tok_new(line); sw1 = atoi(g_slist_nth_data(tokens, 0)); sw2 = atoi(g_slist_nth_data(tokens, 1)); line_token = g_slist_nth_data(tokens, 2); + encoded_len = strlen(line_token); - dbg("line_token:[%s], Length of line token:[%d]", line_token, strlen(line_token)); + dbg("line_token:[%s], Length of line token:[%d]", + line_token, encoded_len); + + encoded_data = tcore_malloc0(2 * encoded_len + 1); + memcpy(encoded_data, line_token, encoded_len); + dbg("encoded_data: [%s]", encoded_data); if ((sw1 == 0x90 && sw2 == 0x00) || sw1 == 0x91) { switch (status_info->status) { @@ -1327,14 +1559,6 @@ static void _response_get_efsms_data(TcorePending *p, break; } } - encoded_len = strlen(line_token); - dbg("Encoded data length:[%d]", encoded_len); - - encoded_data = tcore_malloc0(2*encoded_len + 1); - - memcpy(encoded_data, line_token, encoded_len); - dbg("encoded_data: [%s]", encoded_data); - /* overwrite Status byte information */ tcore_util_byte_to_hex((const char *)&msg_status, encoded_data, 1); @@ -1344,14 +1568,15 @@ static void _response_get_efsms_data(TcorePending *p, * */ at_cmd = g_strdup_printf("AT+CRSM=220,28476,%d, 4, %d, \"%s\"", - (status_info->index), IMC_AT_EF_SMS_RECORD_LEN, encoded_data); + (status_info->index), IMC_AT_EF_SMS_RECORD_LEN, encoded_data); /* Send Request to modem */ ret = tcore_at_prepare_and_send_request(co, at_cmd, "+CRSM:", TCORE_AT_COMMAND_TYPE_SINGLELINE, NULL, - on_response_imc_sms_set_message_status, resp_cb_data, + on_response_imc_sms_set_message_status, + resp_cb_data, on_send_imc_request, NULL); IMC_CHECK_REQUEST_RET(ret, resp_cb_data, "Set Message Status-Updating status in Record"); @@ -1360,15 +1585,18 @@ static void _response_get_efsms_data(TcorePending *p, g_free(status_info); tcore_at_tok_free(tokens); return; - } - else { + } else { err("Invalid Response Received"); } } else { - err("Response NOK"); + err("RESPONSE NOK"); + result = __imc_sms_convert_cme_error_tel_sms_result(at_resp); } + dbg("get efsms status: [%s]", + (result == TEL_SMS_RESULT_SUCCESS ? "SUCCESS" : "FAIL")); + /* Invoke callback */ if (resp_cb_data->cb) resp_cb_data->cb(co, (gint)result, NULL, resp_cb_data->cb_data); @@ -1414,19 +1642,19 @@ static void on_response_imc_sms_get_sms_params(TcorePending *p, err("invalid response received"); goto OUT; } - hex_data = tcore_at_tok_extract((const gchar *)hex_data); + hex_data = tcore_at_tok_extract((const gchar *)hex_data); tcore_util_hexstring_to_bytes(hex_data, &record_data, (guint*)&decoding_length); tcore_free(hex_data); /* * Decrementing the Record Count and Filling the ParamsInfo List - * Final Response will be posted when Record count is ZERO + * Final RESPONSE will be posted when Record count is ZERO */ params_req_data->params[params_req_data->index].index = params_req_data->index; tcore_util_decode_sms_parameters((unsigned char *)record_data, - decoding_length, - ¶ms_req_data->params[params_req_data->index]); + decoding_length, + ¶ms_req_data->params[params_req_data->index]); params_req_data->total_param_count -= 1; @@ -1465,16 +1693,16 @@ static void on_response_imc_sms_get_sms_params(TcorePending *p, return; } } else { - err("Invalid Response Received"); + err("Invalid RESPONSE Received"); } } else { err("RESPONSE NOK"); + result = __imc_sms_convert_cme_error_tel_sms_result(at_resp); } OUT: { TelSmsParamsInfoList param_info_list = {0, }; - if (result == TEL_SMS_RESULT_SUCCESS) { param_info_list.params = params_req_data->params; param_info_list.count = params_req_data->record_count; @@ -1501,16 +1729,19 @@ static void on_response_imc_sms_set_sms_params(TcorePending *p, const TcoreAtResponse *at_resp = data; CoreObject *co = tcore_pending_ref_core_object(p); ImcRespCbData *resp_cb_data = user_data; - TelSmsResult result = TEL_SMS_RESULT_FAILURE; - gint sw1 = 0 , sw2 = 0; - const char *line = NULL; - GSList *tokens=NULL; dbg("Enter"); + tcore_check_return_assert(co != NULL); + tcore_check_return_assert(resp_cb_data != NULL); + if (at_resp && at_resp->success) { dbg("Response OK"); if (at_resp->lines) { + gint sw1 = 0 , sw2 = 0; + const char *line = NULL; + GSList *tokens = NULL; + line = (const char *) at_resp->lines->data; tokens = tcore_at_tok_new(line); @@ -1520,15 +1751,17 @@ static void on_response_imc_sms_set_sms_params(TcorePending *p, if ((sw1 == 0x90 && sw2 == 0x00) || sw1 == 0x91) { result = TEL_SMS_RESULT_SUCCESS; } - else { - result = TEL_SMS_RESULT_FAILURE; - } + tcore_at_tok_free(tokens); } - tcore_at_tok_free(tokens); + } else { - err("Response NOK"); + err("RESPONSE NOK"); + result = __imc_sms_convert_cme_error_tel_sms_result(at_resp); } + dbg("set sms params: [%s]", + (result == TEL_SMS_RESULT_SUCCESS ? "SUCCESS" : "FAIL")); + /* Invoke callback */ if (resp_cb_data->cb) resp_cb_data->cb(co, (gint)result, NULL, resp_cb_data->cb_data); @@ -1561,18 +1794,18 @@ static gboolean async_callback(gpointer data) * * Request - * AT-Command: AT+CMGS - * For PDU mode (+CMGF=0): - * +CMGS= - * PDU is given + * For PDU mode (+CMGF=0): + * +CMGS= + * PDU is given * where, * Length of the pdu. * PDU to send. * * Response - - *+CMGS: [,] - * OK + * +CMGS: [,] + * OK * Failure: - * +CMS ERROR: + * +CMS ERROR: */ static TelReturn imc_sms_send_sms(CoreObject *co, const TelSmsSendInfo *send_info, TcoreObjectResponseCallback cb, void *cb_data) @@ -1640,18 +1873,18 @@ static TelReturn imc_sms_send_sms(CoreObject *co, * * Request - * AT-Command: AT+CMGW - * AT+CMGW = [,]PDU is given + * AT+CMGW = [,]PDU is given * where - * length of the tpdu - * status of the message - * PDu of the message + * length of the tpdu + * status of the message + * PDu of the message * * Response - - * +CMGW: + * +CMGW: * Success: (Single line) * OK * Failure: - * +CMS ERROR: + * +CMS ERROR: */ static TelReturn imc_sms_write_sms_in_sim(CoreObject *co, const TelSmsSimDataInfo *wdata, TcoreObjectResponseCallback cb, void *cb_data) @@ -1728,7 +1961,7 @@ static TelReturn imc_sms_write_sms_in_sim(CoreObject *co, * * Request - * AT-Command: At+CMGR= - * where + * where * index of the message to be read. * * Response - @@ -1736,7 +1969,7 @@ static TelReturn imc_sms_write_sms_in_sim(CoreObject *co, * +CMGR: ,[], * * Failure: - * +CMS ERROR: + * +CMS ERROR: */ static TelReturn imc_sms_read_sms_in_sim(CoreObject *co, unsigned int index, TcoreObjectResponseCallback cb, void *cb_data) @@ -1773,13 +2006,13 @@ static TelReturn imc_sms_read_sms_in_sim(CoreObject *co, * * Request - * AT-Command: AT+CGMD - * +CMGD=[,] + * +CMGD=[,] * * Response - * Success: (NO RESULT) - - * OK + * OK * Failure: - * +CMS ERROR: + * +CMS ERROR: */ static TelReturn imc_sms_delete_sms_in_sim(CoreObject *co, unsigned int index, @@ -1802,7 +2035,7 @@ static TelReturn imc_sms_delete_sms_in_sim(CoreObject *co, */ /* AT-Command */ - at_cmd = g_strdup_printf("AT+CMGD=%d,0", index); /*Delete specified index*/ + at_cmd = g_strdup_printf("AT+CMGD=%d,0", index); /* Delete specified index */ /* Send Request to modem */ ret = tcore_at_prepare_and_send_request(co, @@ -1824,8 +2057,8 @@ static TelReturn imc_sms_delete_sms_in_sim(CoreObject *co, * * Request - * AT-Command: AT+CPMS - * +CPMS=[, [,]] - * where + * +CPMS=[, [,]] + * where * memory storage to read. * * Response - @@ -1835,7 +2068,7 @@ static TelReturn imc_sms_delete_sms_in_sim(CoreObject *co, * OK * * Failure: - * +CMS ERROR: + * +CMS ERROR: */ static TelReturn imc_sms_get_msg_count_in_sim(CoreObject *co, TcoreObjectResponseCallback cb, void *cb_data) @@ -1872,17 +2105,17 @@ static TelReturn imc_sms_get_msg_count_in_sim(CoreObject *co, * * Request - * AT-Command: AT+CSCA - * AT+CSCA=[,] + * AT+CSCA=[,] * where * Service center number * address type of SCA * * Response - * Success: No result - * OK + * OK * * Failure: - * +CMS ERROR: + * +CMS ERROR: */ static TelReturn imc_sms_set_sca(CoreObject *co, const TelSmsSca *sca, TcoreObjectResponseCallback cb, void *cb_data) @@ -1923,9 +2156,9 @@ static TelReturn imc_sms_get_msg_count_in_sim(CoreObject *co, * AT-Command: AT+CSCA? * * Response - - * Success: Single-Line - * +CSCA: , - * OK + * Success: Single-Line + * +CSCA: , + * OK * where * Service center number * address type of SCA @@ -1934,30 +2167,22 @@ static TelReturn imc_sms_get_msg_count_in_sim(CoreObject *co, static TelReturn imc_sms_get_sca(CoreObject *co, TcoreObjectResponseCallback cb, void *cb_data) { - gchar *at_cmd; - ImcRespCbData *resp_cb_data; TelReturn ret; dbg("Enter"); - /* AT Command */ - at_cmd = g_strdup_printf("AT+CSCA?"); - /* Response callback data */ resp_cb_data = imc_create_resp_cb_data(cb, cb_data, NULL, 0); /* Send Request to modem */ ret = tcore_at_prepare_and_send_request(co, - at_cmd, "+CSCA", + "AT+CSCA?", "+CSCA", TCORE_AT_COMMAND_TYPE_SINGLELINE, NULL, on_response_imc_sms_get_sca, resp_cb_data, on_send_imc_request, NULL); IMC_CHECK_REQUEST_RET(ret, resp_cb_data, "Get SCA"); - /* Free resources */ - g_free(at_cmd); - return ret; } @@ -1966,24 +2191,22 @@ static TelReturn imc_sms_get_msg_count_in_sim(CoreObject *co, * * Request - * AT-Command: AT+CSCB - * +CSCB=[[,[,]]] + * +CSCB=[[,[,]]] * * Response - * Success * OK * * Failure: - * +CME ERROR: + * +CME ERROR: */ static TelReturn imc_sms_set_cb_config(CoreObject *co, const TelSmsCbConfigInfo *cb_conf, TcoreObjectResponseCallback cb, void *cb_data) { gchar *at_cmd; - ImcRespCbData *resp_cb_data; TelReturn ret; - unsigned short ctr1 = 0, ctr2 = 0, msg_id_range = 0; unsigned short append_msg_id = 0; dbg("Enter"); @@ -1994,10 +2217,11 @@ static TelReturn imc_sms_set_cb_config(CoreObject *co, at_cmd = NULL; mid_string = g_string_new("AT+CSCB=0,\""); - for(ctr1 = 0; ctr1 < cb_conf->msg_id_range_cnt; ctr1++) { + for (ctr1 = 0; ctr1 < cb_conf->msg_id_range_cnt; ctr1++) { if (cb_conf->msg_ids[ctr1].selected == FALSE) continue; - msg_id_range = ((cb_conf->msg_ids[ctr1].to_msg_id) - (cb_conf->msg_ids[ctr1].from_msg_id)); + msg_id_range = ((cb_conf->msg_ids[ctr1].to_msg_id) - + (cb_conf->msg_ids[ctr1].from_msg_id)); if (TEL_SMS_GSM_CBMI_LIST_SIZE_MAX <= msg_id_range) { mid_string = g_string_new("AT+CSCB=1"); /* Enable All CBS */ @@ -2006,12 +2230,13 @@ static TelReturn imc_sms_set_cb_config(CoreObject *co, append_msg_id = cb_conf->msg_ids[ctr1].from_msg_id; dbg( "%x", append_msg_id); - for(ctr2 = 0; ctr2 <= msg_id_range; ctr2++) { - mid_string = g_string_append(mid_string, g_strdup_printf("%d", append_msg_id)); + for (ctr2 = 0; ctr2 <= msg_id_range; ctr2++) { + mid_string = g_string_append(mid_string, + g_strdup_printf("%d", append_msg_id)); if (ctr2 == msg_id_range) { - mid_string = g_string_append(mid_string, "\""); /*Mids string termination*/ - } - else { + /* Mids string termination */ + mid_string = g_string_append(mid_string, "\""); + } else { mid_string = g_string_append(mid_string, ","); } append_msg_id++; @@ -2020,9 +2245,9 @@ static TelReturn imc_sms_set_cb_config(CoreObject *co, mids_str = g_string_free(mid_string, FALSE); at_cmd = g_strdup_printf("%s", mids_str); g_free(mids_str); - } - else { - at_cmd = g_strdup_printf("AT+CSCB=%d", cb_conf->cb_enabled); /* Enable or Disable MsgId's */ + } else { + /* Enable or Disable MsgId's */ + at_cmd = g_strdup_printf("AT+CSCB=%d", cb_conf->cb_enabled); } /* Response callback data */ @@ -2048,41 +2273,33 @@ static TelReturn imc_sms_set_cb_config(CoreObject *co, * * Request - * AT-Command: AT+CSCB - * +CSCB? + * +CSCB? * * Response - * Success - (Single line) - * +CSCB : ,, + * +CSCB : ,, * OK * */ static TelReturn imc_sms_get_cb_config(CoreObject *co, TcoreObjectResponseCallback cb, void *cb_data) { - gchar *at_cmd; - ImcRespCbData *resp_cb_data; TelReturn ret; dbg("Enter"); - /* AT Command */ - at_cmd = g_strdup_printf("AT+CSCB?"); - /* Response callback data */ resp_cb_data = imc_create_resp_cb_data(cb, cb_data, NULL, 0); /* Send Request to modem */ ret = tcore_at_prepare_and_send_request(co, - at_cmd, NULL, + "AT+CSCB?", NULL, TCORE_AT_COMMAND_TYPE_SINGLELINE, NULL, on_response_imc_sms_get_cb_config, resp_cb_data, on_send_imc_request, NULL); IMC_CHECK_REQUEST_RET(ret, resp_cb_data, "Get Cb Config"); - /* Free resources */ - g_free(at_cmd); - return ret; } @@ -2090,7 +2307,7 @@ static TelReturn imc_sms_set_cb_config(CoreObject *co, * Operation - send_deliver_report * * Request - - * Modem Takes care of sending the ACK to the network + * Modem Takes care of sending the ACK to the network * * Response - * Success: Default response always SUCCESS posted @@ -2121,16 +2338,16 @@ static TelReturn imc_sms_send_deliver_report(CoreObject *co, * * Request - * AT-Command: AT+XTESM= - * status of the external SMS storage which may be: + * status of the external SMS storage which may be: * 0: memory capacity free * 1: memory capacity full * * Response -No Result - * Success - * OK + * Success + * OK * * Failure: - * +CME ERROR: + * +CME ERROR: */ static TelReturn imc_sms_set_memory_status(CoreObject *co, gboolean available, TcoreObjectResponseCallback cb, void *cb_data) @@ -2165,16 +2382,16 @@ static TelReturn imc_sms_set_memory_status(CoreObject *co, * * Request - * AT-Command: AT+CRSM= command>[,[,,,[,[,]]]] - * p1 Index - * p3 SMSP record length + * p1 Index + * p3 SMSP record length * * * Response -Single Line - * Success - * OK + * Success + * OK * * Failure: - * +CME ERROR: + * +CME ERROR: */ static TelReturn imc_sms_set_message_status(CoreObject *co, const TelSmsStatusInfo *status_info, @@ -2213,16 +2430,16 @@ static TelReturn imc_sms_set_message_status(CoreObject *co, * * Request - * AT-Command: AT+CRSM - * AT+CRSM= command>[,[,,,[,[,]]]] + * AT+CRSM= command>[,[,,,[,[,]]]] * * Response - * Success: (Single-line output) - * +CRSM: - * ,[,] - * OK + * +CRSM: + * ,[,] + * OK * * Failure: - * +CME ERROR: + * +CME ERROR: */ static TelReturn imc_sms_get_sms_params(CoreObject *co, TcoreObjectResponseCallback cb, void *cb_data) @@ -2230,7 +2447,7 @@ static TelReturn imc_sms_get_sms_params(CoreObject *co, TcorePlugin *plugin; ImcRespCbData *resp_cb_data; ImcSmsParamsCbData params_req_data = {0, }; - gint loop_count, record_count = 0, smsp_record_len = 0; + gint record_count = 0, smsp_record_len = 0; gchar *at_cmd; @@ -2260,7 +2477,7 @@ static TelReturn imc_sms_get_sms_params(CoreObject *co, /* SMSP record length */ params_req_data.record_length = smsp_record_len; - /* Response callback data */ + /* RESPONSE callback data */ resp_cb_data = imc_create_resp_cb_data(cb, cb_data, (void *)¶ms_req_data, sizeof(ImcSmsParamsCbData)); @@ -2294,13 +2511,13 @@ static TelReturn imc_sms_get_sms_params(CoreObject *co, * * Request - * AT-Command: AT+CRSM - * AT+CRSM= command>[,[,,,[,[,]]]] + * AT+CRSM= command>[,[,,,[,[,]]]] * * Response - * Success: (Single-line output) - * +CRSM: - * ,[,] - * OK + * +CRSM: + * ,[,] + * OK * * Failure: * +CME ERROR: @@ -2342,7 +2559,7 @@ static TelReturn imc_sms_set_sms_params(CoreObject *co, tcore_util_byte_to_hex((const char *)set_params_data, (char *)encoded_data, smsp_record_len); - /* Response callback data */ + /* RESPONSE callback data */ resp_cb_data = imc_create_resp_cb_data(cb, cb_data, NULL, 0); /* AT+ Command*/ diff --git a/src/imc_ss.c b/src/imc_ss.c index 888386a..112b8c8 100644 --- a/src/imc_ss.c +++ b/src/imc_ss.c @@ -152,9 +152,72 @@ static gboolean on_notification_imc_ss_ussd(CoreObject *co, const void *event_da return TRUE; } +static TelSsResult __imc_ss_convert_cme_error_tel_ss_result(const TcoreAtResponse *at_resp) +{ + TelSsResult result = TEL_SS_RESULT_FAILURE; + const gchar *line; + GSList *tokens = NULL; + dbg("Entry"); + + if (!at_resp || !at_resp->lines) { + err("Invalid response data"); + return result; + } + + line = (const gchar *)at_resp->lines->data; + tokens = tcore_at_tok_new(line); + if (g_slist_length(tokens) > 0) { + gchar *resp_str; + gint cme_err; + + resp_str = g_slist_nth_data(tokens, 0); + if (!resp_str) { + err("invalid cme error data"); + tcore_at_tok_free(tokens); + return result; + } + cme_err = atoi(resp_str); + dbg("CME error[%d]", cme_err); + + switch (cme_err) { + case 3: + result = TEL_SS_RESULT_OPERATION_NOT_PERMITTED; + break; + + case 4: + result = TEL_SS_RESULT_OPERATION_NOT_SUPPORTED; + break; + + case 16: + result = TEL_SS_RESULT_INVALID_PASSWORD; + break; + + case 20: + result = TEL_SS_RESULT_MEMORY_FAILURE; + break; + + case 50: + result = TEL_SS_RESULT_INVALID_PARAMETER; + break; + + case 132: + case 133: + case 134: + result = TEL_SS_RESULT_SERVICE_NOT_AVAILABLE; + break; + + default: + result = TEL_SS_RESULT_FAILURE; + } + } + tcore_at_tok_free(tokens); + + return result; +} + static gboolean __imc_ss_convert_modem_class_to_class(gint classx, TelSsClass *class) { - switch(classx) + switch (classx) { case 7: *class = TEL_SS_CLASS_ALL_TELE; @@ -193,7 +256,7 @@ static gboolean __imc_ss_convert_modem_class_to_class(gint classx, TelSsClass *c static guint __imc_ss_convert_class_to_imc_class(TelSsClass class) { - switch(class) + switch (class) { case TEL_SS_CLASS_ALL_TELE: return 7; @@ -231,7 +294,7 @@ static guint __imc_ss_convert_class_to_imc_class(TelSsClass class) static gboolean __imc_ss_convert_barring_type_to_facility(TelSsBarringType type, gchar **facility) { - switch(type) + switch (type) { case TEL_SS_CB_TYPE_BAOC: *facility = "AO"; @@ -270,7 +333,7 @@ static gboolean __imc_ss_convert_barring_type_to_facility(TelSsBarringType type, static gboolean __imc_ss_convert_forwarding_mode_to_modem_mode(TelSsForwardMode mode, guint *modex) { - switch(mode) + switch (mode) { case TEL_SS_CF_MODE_DISABLE: *modex = 0; @@ -349,7 +412,7 @@ static gint __imc_ss_convert_clir_status_modem_status(gint clir_status) static gboolean __imc_ss_convert_cli_info_modem_info(const TelSsCliInfo **cli_info,gint *status, gchar **cmd_prefix) { - switch((*cli_info)->type) + switch ((*cli_info)->type) { case TEL_SS_CLI_CLIR: if ((*status = __imc_ss_convert_clir_status_modem_status((*cli_info)->status.clir)) @@ -467,7 +530,7 @@ static gboolean __imc_ss_convert_modem_cli_dev_status_cli_status(TelSsCliType cl return FALSE; } } else { //CLIP, COLP,COLR,CNAP. - switch(dev_status) { + switch (dev_status) { case 0: *status = TEL_SS_CLI_DISABLE; break; @@ -499,6 +562,10 @@ static void on_response_imc_ss_set_barring(TcorePending *p, if (at_resp && at_resp->success) result = TEL_SS_RESULT_SUCCESS; + else { + err("RESPONSE NOK"); + result = __imc_ss_convert_cme_error_tel_ss_result(at_resp); + } dbg("Setting Barring status: [%s]", (result == TEL_SS_RESULT_SUCCESS ? "SUCCESS" : "FAIL")); @@ -537,6 +604,7 @@ static void on_response_imc_ss_get_barring_status(TcorePending *p, } else { err("RESPONSE - [NOK]"); + result = __imc_ss_convert_cme_error_tel_ss_result(at_resp); } } else { err("No response data"); @@ -573,7 +641,8 @@ static void on_response_imc_ss_get_barring_status(TcorePending *p, if (!classx_str) { dbg("Class error. Setting to the requested class: [%d]", req_info->class); - barring_resp.records[valid_records].class = req_info->class; + barring_resp.records[valid_records].class = + req_info->class; } else { if (__imc_ss_convert_modem_class_to_class(atoi(classx_str), &(barring_resp.records[valid_records].class)) @@ -614,7 +683,6 @@ static void on_response_imc_ss_change_barring_password(TcorePending *p, const TcoreAtResponse *at_resp = data; CoreObject *co = tcore_pending_ref_core_object(p); ImcRespCbData *resp_cb_data = user_data; - /* TODO: CMEE error mapping is required */ TelSsResult result = TEL_SS_RESULT_FAILURE; dbg("Enter"); @@ -623,6 +691,10 @@ static void on_response_imc_ss_change_barring_password(TcorePending *p, if (at_resp && at_resp->success) result = TEL_SS_RESULT_SUCCESS; + else { + err("RESPONSE NOK"); + result = __imc_ss_convert_cme_error_tel_ss_result(at_resp); + } dbg("Change Barring Password: [%s]", (result == TEL_SS_RESULT_SUCCESS ? "SUCCESS" : "FAIL")); @@ -650,6 +722,10 @@ static void on_response_imc_ss_set_forwarding(TcorePending *p, if (at_resp && at_resp->success) result = TEL_SS_RESULT_SUCCESS; + else { + err("RESPONSE NOK"); + result = __imc_ss_convert_cme_error_tel_ss_result(at_resp); + } dbg("Set Forwarding Status: [%s]", (result == TEL_SS_RESULT_SUCCESS ? "SUCCESS" : "FAIL")); @@ -671,7 +747,6 @@ static void on_response_imc_ss_get_forwarding_status(TcorePending *p, TelSsForwardGetInfo *req_info; gint valid_records = 0; GSList *resp_data = NULL; - /* TODO: CMEE error mapping is required */ TelSsResult result = TEL_SS_RESULT_FAILURE; dbg("Enter"); @@ -687,6 +762,7 @@ static void on_response_imc_ss_get_forwarding_status(TcorePending *p, dbg("Total records: [%d]", forwarding_resp.record_num); } else { err("RESPONSE - [NOK]"); + result = __imc_ss_convert_cme_error_tel_ss_result(at_resp); } } else { err("No response data"); @@ -782,7 +858,6 @@ static void on_response_imc_ss_set_waiting(TcorePending *p, const TcoreAtResponse *at_resp = data; CoreObject *co = tcore_pending_ref_core_object(p); ImcRespCbData *resp_cb_data = user_data; - /* TODO: CMEE error mapping is required */ TelSsResult result = TEL_SS_RESULT_FAILURE; dbg("Enter"); @@ -791,6 +866,10 @@ static void on_response_imc_ss_set_waiting(TcorePending *p, if (at_resp && at_resp->success) result = TEL_SS_RESULT_SUCCESS; + else { + err("RESPONSE NOK"); + result = __imc_ss_convert_cme_error_tel_ss_result(at_resp); + } dbg("Set Waiting Status: [%s]", (result == TEL_SS_RESULT_SUCCESS ? "SUCCESS" : "FAIL")); @@ -812,7 +891,6 @@ static void on_response_imc_ss_get_waiting_status(TcorePending *p, TelSsClass *class; gint valid_records = 0; GSList *resp_data = NULL; - /* TODO: CMEE error mapping is required */ TelSsResult result = TEL_SS_RESULT_FAILURE; dbg("Enter"); @@ -826,9 +904,9 @@ static void on_response_imc_ss_get_waiting_status(TcorePending *p, resp_data = (GSList *) at_resp->lines; waiting_resp.record_num= g_slist_length(resp_data); dbg("Total records: [%d]", waiting_resp.record_num); - } - else { + } else { err("RESPONSE - [NOK]"); + result = __imc_ss_convert_cme_error_tel_ss_result(at_resp); } } else { err("No response data"); @@ -915,6 +993,10 @@ static void on_response_imc_ss_set_cli(TcorePending *p, if (at_resp && at_resp->success) result = TEL_SS_RESULT_SUCCESS; + else { + err("RESPONSE - [NOK]"); + result = __imc_ss_convert_cme_error_tel_ss_result(at_resp); + } dbg("Set Cli Status: [%s]", (result == TEL_SS_RESULT_SUCCESS ? "SUCCESS" : "FAIL")); @@ -979,7 +1061,7 @@ static void on_response_imc_ss_get_cli_status(TcorePending *p, atoi(status), &net_status)) goto END; - switch(*cli_type){ + switch (*cli_type){ case TEL_SS_CLI_CLIR: cli_resp.status.clir.net_status = net_status; cli_resp.status.clir.dev_status = dev_status; @@ -1010,6 +1092,7 @@ static void on_response_imc_ss_get_cli_status(TcorePending *p, result = TEL_SS_RESULT_SUCCESS; } else{ err("RESPONSE NOK"); + result = __imc_ss_convert_cme_error_tel_ss_result(at_resp); } END: @@ -1047,16 +1130,17 @@ static void on_response_imc_ss_send_ussd_request(TcorePending *p, /* Need to initialise ussd response string */ ussd_resp.str = (unsigned char *)g_strdup("Operation success"); } else { + err("RESPONSE - [NOK]"); ussd_resp.str = (unsigned char *)g_strdup("Operation failed"); - } + result = __imc_ss_convert_cme_error_tel_ss_result(at_resp); + } dbg("Send Ussd Request: [%s]", (result == TEL_SS_RESULT_SUCCESS ? "SUCCESS" : "FAIL")); tcore_ss_ussd_destroy_session(ussd_s); - /* Invoke callback */ if (resp_cb_data->cb) resp_cb_data->cb(co, (gint)result, &ussd_resp, resp_cb_data->cb_data); @@ -1214,10 +1298,7 @@ static TelReturn imc_ss_change_barring_password(CoreObject *co, ImcRespCbData *resp_cb_data = NULL; TelReturn ret = TEL_RETURN_INVALID_PARAMETER; - if (barring_pwd_info->old_pwd == NULL || barring_pwd_info->new_pwd == NULL) { - err("Invalid data"); - return ret; - } + tcore_check_return_value(barring_pwd_info != NULL, ret); dbg("Old password: [%s], New password: [%s]", barring_pwd_info->old_pwd, barring_pwd_info->new_pwd); diff --git a/src/nvm/nvm.c b/src/nvm/nvm.c index 2ec6169..fa32d9b 100644 --- a/src/nvm/nvm.c +++ b/src/nvm/nvm.c @@ -229,15 +229,20 @@ gboolean nvm_create_nvm_data() /* Close 'modem_fd' */ close(modem_fd); return ret_val; - } else if (open(NV_FILE_PATH, O_EXCL) > 0) { - /* NV data file already exists */ - dbg("File exists: [%s]", NV_FILE_PATH); - - /* Close 'modem_fd' */ - close(modem_fd); - return TRUE; } else { - dbg("File does't exsits... need to create!!!"); + gint fd = open(NV_FILE_PATH, O_EXCL); + if (fd < 0) { + dbg("File does't exsits... need to create!!!"); + } else { + /* NV data file already exists */ + dbg("File exists: [%s]", NV_FILE_PATH); + + /* Close 'fds' */ + close(fd); + close(modem_fd); + + return TRUE; + } } } -- 2.7.4