4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Harish Bishnoi <hbishnoi@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
30 #include <core_object.h>
32 #include <user_request.h>
45 #define ID_RESERVED_AT 0x0229
47 #define MAX_VERSION_LEN 32
48 #define TAPI_MISC_ME_SN_LEN_MAX 32
49 #define TAPI_MISC_PRODUCT_CODE_LEN_MAX 32
50 #define TAPI_MISC_MODEL_ID_LEN_MAX 17
51 #define TAPI_MISC_PRL_ERI_VER_LEN_MAX 17
53 #define CPAS_RES_READY 0
54 #define CPAS_RES_UNAVAIL 1
55 #define CPAS_RES_UNKNOWN 2
56 #define CPAS_RES_RINGING 3
57 #define CPAS_RES_CALL_PROGRESS 4
58 #define CPAS_RES_ASLEEP 5
68 CP_STATE_NV_REBUILDING,
73 TAPI_MISC_ME_IMEI = 0x00, /**< 0x00: IMEI, GSM/UMTS device */
74 TAPI_MISC_ME_ESN = 0x01, /**< 0x01: ESN(Electronic Serial Number), It`s essentially run out. CDMA device */
75 TAPI_MISC_ME_MEID = 0x02, /**< 0x02: MEID, This value can have hexa decimal digits. CDMA device */
76 TAPI_MISC_ME_MAX = 0xff /**< 0xff: reserved */
77 } TelMiscSNIndexType_t;
80 TelMiscSNIndexType_t sn_index; /**< serial number index */
81 int sn_len; /**< Length */
82 unsigned char szNumber[TAPI_MISC_ME_SN_LEN_MAX]; /**< Number */
83 } TelMiscSNInformation;
86 * Mobile Equipment Version Information
89 unsigned char ver_mask; /**< version mask - 0x01:SW_ver, 0x02:HW_ver, 0x04:RF_CAL_date, 0x08:Product_code, 0x10:Model_ID, 0x20:PRL, 0x04:ERI, 0xff:all */
90 unsigned char szSwVersion[MAX_VERSION_LEN]; /**< Software version, null termination */
91 unsigned char szHwVersion[MAX_VERSION_LEN]; /**< Hardware version, null termination */
92 unsigned char szRfCalDate[MAX_VERSION_LEN]; /**< Calculation Date, null termination */
93 unsigned char szProductCode[TAPI_MISC_PRODUCT_CODE_LEN_MAX]; /**< product code, null termination */
94 unsigned char szModelId[TAPI_MISC_MODEL_ID_LEN_MAX]; /**< model id (only for CDMA), null termination */
95 unsigned char prl_nam_num; /**< number of PRL NAM fields */
96 unsigned char szPrlVersion[TAPI_MISC_PRL_ERI_VER_LEN_MAX * 3]; /**< prl version (only for CDMA), null termination */
97 unsigned char eri_nam_num; /**< number of PRL NAM fields */
98 unsigned char szEriVersion[TAPI_MISC_PRL_ERI_VER_LEN_MAX * 3]; /**< eri version (only for CDMA), null termination */
99 } TelMiscVersionInformation;
102 static void prepare_and_send_pending_request(CoreObject *co, const char *at_cmd, const char *prefix, enum tcore_at_command_type at_cmd_type, TcorePendingResponseCallback callback);
103 static void on_confirmation_modem_message_send(TcorePending *p, gboolean result, void *user_data);
104 static void on_response_network_registration(TcorePending *p, int data_len, const void *data, void *user_data);
105 static void on_response_enable_proactive_command(TcorePending *p, int data_len, const void *data, void *user_data);
108 static gboolean on_event_nvm_update(CoreObject *o, const void *event_info, void *user_data);
109 static void modem_unsuspend_nvm_updates(CoreObject *o);
110 static void modem_send_nvm_update_ack(CoreObject *o);
111 static void modem_send_nvm_update_request_ack(CoreObject *o);
113 static void on_confirmation_modem_message_send(TcorePending *p, gboolean result, void *user_data)
115 dbg("on_confirmation_modem_message_send - msg out from queue.\n");
117 if (result == FALSE) {
125 static void on_response_enable_proactive_command(TcorePending *p, int data_len, const void *data, void *user_data)
127 const TcoreATResponse *resp = data;
129 if (resp->success > 0) {
130 dbg("RESPONSE OK proactive command enabled");
132 dbg("RESPONSE NOK proactive command disabled");
136 static void on_response_network_registration(TcorePending *p, int data_len, const void *data, void *user_data)
138 const TcoreATResponse *resp = data;
140 if (resp->success > 0) {
141 dbg("registration attempt OK");
143 dbg("registration attempt failed");
147 void prepare_and_send_pending_request(CoreObject *co, const char *at_cmd, const char *prefix, enum tcore_at_command_type at_cmd_type, TcorePendingResponseCallback callback)
149 TcoreATRequest *req = NULL;
150 TcoreHal *hal = NULL;
151 TcorePending *pending = NULL;
154 hal = tcore_object_get_hal(co);
157 pending = tcore_pending_new(co, 0);
159 dbg("Pending is NULL");
160 req = tcore_at_request_new(at_cmd, prefix, at_cmd_type);
162 dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
164 tcore_pending_set_request_data(pending, 0, req);
165 tcore_pending_set_response_callback(pending, callback, NULL);
166 tcore_pending_set_send_callback(pending, on_confirmation_modem_message_send, NULL);
167 ret = tcore_hal_send_request(hal, pending);
170 static void on_response_power_off(TcorePending *p, int data_len, const void *data, void *user_data)
175 o = tcore_pending_ref_core_object(p);
176 h = tcore_object_get_hal(o);
178 dbg("modem power off");
180 tcore_hal_set_power_state(h, FALSE);
183 static void on_response_set_flight_mode(TcorePending *p, int data_len, const void *data, void *user_data)
185 CoreObject *o = NULL;
186 UserRequest *ur = NULL;
187 const TcoreATResponse *ATresp = data;
188 GSList *tokens = NULL;
189 const char *line = NULL;
190 struct tresp_modem_set_flightmode res = {0};
192 struct tnoti_modem_flight_mode modem_flight_mode = {0};
193 const struct treq_modem_set_flightmode *req_data = NULL;
195 o = tcore_pending_ref_core_object(p);
197 if (ATresp->success > 0) {
198 dbg("RESPONSE OK - flight mode operation finished");
199 res.result = TCORE_RETURN_SUCCESS;
202 line = (const char *) ATresp->final_response;
203 tokens = tcore_at_tok_new(line);
205 if (g_slist_length(tokens) < 1) {
206 dbg("err cause not specified or string corrupted");
207 res.result = TCORE_RETURN_3GPP_ERROR;
209 response = atoi(g_slist_nth_data(tokens, 0));
210 /* TODO: CMEE error mapping is required. */
211 res.result = TCORE_RETURN_3GPP_ERROR;
215 ur = tcore_pending_ref_user_request(p);
217 dbg("No user request. Internal request created during boot-up sequence");
219 if (ATresp->success > 0) {
220 modem_flight_mode.enable = tcore_modem_get_flight_mode_state(o);
221 dbg("sucess case - Sending Flight Mode Notification (%d) to Telephony Server", modem_flight_mode.enable);
223 tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_MODEM_FLIGHT_MODE,
224 sizeof(struct tnoti_modem_flight_mode), &modem_flight_mode);
227 dbg("Sending response for Flight mode operation");
229 req_data = tcore_user_request_ref_data(ur, NULL);
231 if (TCORE_RETURN_SUCCESS == res.result) {
232 if (TRUE == req_data->enable)
240 tcore_user_request_send_response(ur, TRESP_MODEM_SET_FLIGHTMODE, sizeof(struct tresp_modem_set_flightmode), &res);
242 if (req_data->enable == 0) {
243 dbg("Flight mode is disabled, trigger COPS to register on network");
244 /* Trigger Network registration (for the moment automatic) */
245 prepare_and_send_pending_request(o, "AT+COPS=0", NULL, TCORE_AT_NO_RESULT, NULL);
249 tcore_at_tok_free(tokens);
252 static void on_response_imei(TcorePending *p, int data_len, const void *data, void *user_data)
254 const TcoreATResponse *resp = data;
255 TcorePlugin *plugin = NULL;
256 struct tresp_modem_get_imei res;
257 TelMiscSNInformation *imei_property = NULL;
258 UserRequest *ur = NULL;
259 GSList *tokens = NULL;
263 memset(&res, 0, sizeof(struct tresp_modem_get_imei));
265 if (resp->success > 0) {
268 line = (const char *) resp->lines->data;
269 tokens = tcore_at_tok_new(line);
270 if (g_slist_length(tokens) != 1) {
271 msg("invalid message");
275 res.result = TCORE_RETURN_SUCCESS;
276 strncpy(res.imei, g_slist_nth_data(tokens, 0), 16);
278 dbg("imei = [%s]", res.imei);
280 plugin = tcore_pending_ref_plugin(p);
281 imei_property = tcore_plugin_ref_property(plugin, "IMEI");
283 imei_property->sn_index = TAPI_MISC_ME_IMEI;
284 imei_property->sn_len = strlen(res.imei);
285 memcpy(imei_property->szNumber, res.imei, imei_property->sn_len);
290 line = (const char *) resp->lines->data;
291 tokens = tcore_at_tok_new(line);
295 if (g_slist_length(tokens) < 1) {
296 dbg("err cause not specified or string corrupted");
297 res.result = TCORE_RETURN_3GPP_ERROR;
299 response = atoi(g_slist_nth_data(tokens, 0));
300 /* TODO: CMEE error mapping is required. */
301 res.result = TCORE_RETURN_3GPP_ERROR;
305 ur = tcore_pending_ref_user_request(p);
306 tcore_user_request_send_response(ur, TRESP_MODEM_GET_IMEI,
307 sizeof(struct tresp_modem_get_imei), &res);
311 tcore_at_tok_free(tokens);
316 static void on_response_version(TcorePending *p, int data_len, const void *data, void *user_data)
318 const TcoreATResponse *resp = data;
319 TcorePlugin *plugin = NULL;
320 struct tresp_modem_get_version res = {0};
321 TelMiscVersionInformation *vi_property = NULL;
322 TelMiscVersionInformation *vi = NULL;
323 UserRequest *ur = NULL;
324 GSList *tokens = NULL;
325 const char *line = NULL;
328 char *caldate = NULL;
334 if (resp->success > 0) {
337 line = (const char *) resp->lines->data;
338 tokens = tcore_at_tok_new(line);
339 if (g_slist_length(tokens) == 1) {
340 swver = g_slist_nth_data(tokens, 0);
341 dbg("version: sw=[%s]", swver);
342 } else if (g_slist_length(tokens) == 5) {
343 swver = g_slist_nth_data(tokens, 0);
344 hwver = g_slist_nth_data(tokens, 1);
345 caldate = g_slist_nth_data(tokens, 2);
346 pcode = g_slist_nth_data(tokens, 3);
347 id = g_slist_nth_data(tokens, 4);
349 dbg("version: sw=[%s], hw=[%s], rf_cal=[%s], product_code=[%s], model_id=[%s]",
350 swver, hwver, caldate, pcode, id);
352 msg("invalid message");
357 vi = g_try_new0(TelMiscVersionInformation, 1);
359 memcpy(vi->szSwVersion, swver, strlen(swver));
361 memcpy(vi->szHwVersion, hwver, strlen(hwver));
363 memcpy(vi->szRfCalDate, caldate, strlen(caldate));
365 memcpy(vi->szProductCode, pcode, strlen(pcode));
367 memcpy(vi->szModelId, id, strlen(id));
369 memset(&res, 0, sizeof(struct tresp_modem_get_version));
372 snprintf(res.software,
373 (AT_VER_LEN > strlen(swver) ? strlen(swver) : AT_VER_LEN),
378 snprintf(res.hardware,
379 (AT_VER_LEN > strlen(hwver) ? strlen(hwver) : AT_VER_LEN),
383 plugin = tcore_pending_ref_plugin(p);
384 vi_property = tcore_plugin_ref_property(plugin, "VERSION");
385 memcpy(vi_property, vi, sizeof(TelMiscVersionInformation));
390 line = (const char *) resp->lines->data;
391 tokens = tcore_at_tok_new(line);
394 memset(&res, 0, sizeof(struct tresp_modem_get_version));
397 if (g_slist_length(tokens) < 1) {
398 dbg("err cause not specified or string corrupted");
399 res.result = TCORE_RETURN_3GPP_ERROR;
401 response = atoi(g_slist_nth_data(tokens, 0));
402 /* TODO: CMEE error mapping is required. */
403 res.result = TCORE_RETURN_3GPP_ERROR;
407 ur = tcore_pending_ref_user_request(p);
408 tcore_user_request_send_response(ur, TRESP_MODEM_GET_VERSION,
409 sizeof(struct tresp_modem_get_version), &res);
413 tcore_at_tok_free(tokens);
418 static enum tcore_hook_return on_hook_sim_status(Server *s,
419 CoreObject *source, enum tcore_notification_command command,
420 unsigned int data_len, void *data, void *user_data)
423 const struct tnoti_sim_status *noti_sim_status;
425 CoreObject *co_network;
427 plugin = tcore_object_ref_plugin(source);
428 co_sat = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_SAT);
430 return TCORE_HOOK_RETURN_CONTINUE;
432 co_network = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_NETWORK);
433 if (co_network == NULL)
434 return TCORE_HOOK_RETURN_CONTINUE;
436 dbg("Get SIM status");
437 noti_sim_status = data;
438 if (noti_sim_status == NULL)
439 return TCORE_HOOK_RETURN_CONTINUE;
441 /* If SIM is initialized, Enable STK and and attach to Network */
442 dbg("SIM Status: [%d]", noti_sim_status->sim_status);
443 if (noti_sim_status->sim_status == SIM_STATUS_INIT_COMPLETED) {
444 dbg("SIM ready for attach!!! Enable STK and attach to Network");
446 /* Sending AT+CFUN=6 */
447 prepare_and_send_pending_request(co_sat, "AT+CFUN=6", NULL,
448 TCORE_AT_NO_RESULT, on_response_enable_proactive_command);
450 /* Sending AT+COPS */
451 prepare_and_send_pending_request(co_network, "AT+COPS=0", NULL,
452 TCORE_AT_NO_RESULT, on_response_network_registration);
455 return TCORE_HOOK_RETURN_CONTINUE;
458 gboolean modem_power_on(TcorePlugin *plugin)
460 CoreObject *co_modem = NULL;
461 struct treq_modem_set_flightmode flight_mode_set = {0};
462 struct tnoti_modem_power modem_power = {0};
463 Storage *strg = NULL;
465 co_modem = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_MODEM);
466 if (co_modem == NULL) {
467 err("Modem Core object is NULL");
471 /* Set Modem Power State to 'ON' */
472 tcore_modem_set_powered(co_modem, TRUE);
474 /* Get Flight mode from VCONFKEY */
475 strg = tcore_server_find_storage(tcore_plugin_ref_server(plugin), "vconf");
476 flight_mode_set.enable = tcore_storage_get_bool(strg, STORAGE_KEY_FLIGHT_MODE_BOOL);
478 /* Set Flight mode as per AP settings */
479 if (flight_mode_set.enable) { /* Radio OFF */
480 prepare_and_send_pending_request(co_modem, "AT+CFUN=4", NULL,
481 TCORE_AT_NO_RESULT, on_response_set_flight_mode);
483 /* Set Flight mode TRUE */
484 tcore_modem_set_flight_mode_state(co_modem, TRUE);
485 } else { /* Radio ON */
486 prepare_and_send_pending_request(co_modem, "AT+CFUN=1", NULL,
487 TCORE_AT_NO_RESULT, on_response_set_flight_mode);
489 /* Set Flight mode FALSE */
490 tcore_modem_set_flight_mode_state(co_modem, FALSE);
494 prepare_and_send_pending_request(co_modem, "AT+CGSN", NULL,
495 TCORE_AT_NUMERIC, on_response_imei);
497 /* Get Version Number */
498 prepare_and_send_pending_request(co_modem, "AT+CGMR", NULL,
499 TCORE_AT_SINGLELINE, on_response_version);
501 /* Send Notification to TAPI - MODEM_POWER */
502 modem_power.state = MODEM_STATE_ONLINE;
504 dbg("Sending notification - Modem Power state: [ONLINE]");
505 tcore_server_send_notification(tcore_plugin_ref_server(plugin),
506 co_modem, TNOTI_MODEM_POWER, sizeof(modem_power), &modem_power);
511 static TReturn power_off(CoreObject *o, UserRequest *ur)
513 TcoreHal *hal = NULL;
514 TcoreATRequest *req = NULL;
515 TcorePending *pending = NULL;
517 hal = tcore_object_get_hal(o);
518 pending = tcore_pending_new(o, 0);
520 req = tcore_at_request_new("AT+CFUN=0", NULL, TCORE_AT_NO_RESULT);
522 dbg("Command: [%s], Prefix(if any): [%s], Command Length: [%d]",
523 req->cmd, req->prefix, strlen(req->cmd));
525 tcore_pending_set_request_data(pending, 0, req);
526 tcore_pending_set_response_callback(pending, on_response_power_off, hal);
527 tcore_pending_link_user_request(pending, ur);
528 tcore_pending_set_send_callback(pending, on_confirmation_modem_message_send, NULL);
530 tcore_hal_send_request(hal, pending);
532 return TCORE_RETURN_SUCCESS;
535 static TReturn get_imei(CoreObject *o, UserRequest *ur)
539 TcorePending *pending = NULL;
541 hal = tcore_object_get_hal(o);
542 if (FALSE == tcore_hal_get_power_state(hal)) {
543 dbg("cp not ready/n");
544 return TCORE_RETURN_ENOSYS;
546 pending = tcore_pending_new(o, 0);
548 req = tcore_at_request_new("AT+CGSN", NULL, TCORE_AT_NUMERIC);
550 dbg("Command: [%s], Prefix(if any): [%s], Command Length: [%d]",
551 req->cmd, req->prefix, strlen(req->cmd));
553 tcore_pending_set_request_data(pending, 0, req);
554 tcore_pending_set_response_callback(pending, on_response_imei, hal);
555 tcore_pending_link_user_request(pending, ur);
556 tcore_pending_set_send_callback(pending, on_confirmation_modem_message_send, NULL);
558 return tcore_hal_send_request(hal, pending);
562 static TReturn get_version(CoreObject *o, UserRequest *ur)
566 TcorePending *pending = NULL;
568 hal = tcore_object_get_hal(o);
569 if (FALSE == tcore_hal_get_power_state(hal)) {
570 dbg("cp not ready/n");
571 return TCORE_RETURN_ENOSYS;
573 pending = tcore_pending_new(o, 0);
575 req = tcore_at_request_new("AT+CGMR", NULL, TCORE_AT_SINGLELINE);
577 dbg("Command: [%s], Prefix(if any): [%s], Command Length: [%d]",
578 req->cmd, req->prefix, strlen(req->cmd));
580 tcore_pending_set_request_data(pending, 0, req);
581 tcore_pending_set_response_callback(pending, on_response_version, hal);
582 tcore_pending_link_user_request(pending, ur);
583 tcore_pending_set_send_callback(pending, on_confirmation_modem_message_send, NULL);
585 return tcore_hal_send_request(hal, pending);
588 static TReturn set_flight_mode(CoreObject *o, UserRequest *ur)
590 TcoreHal *hal = NULL;
591 TcoreATRequest *req = NULL;
592 TcorePending *pending = NULL;
593 const struct treq_modem_set_flightmode *req_data = NULL;
594 char *cmd_str = NULL;
596 hal = tcore_object_get_hal(o);
597 if (FALSE == tcore_hal_get_power_state(hal)) {
598 dbg("cp not ready/n");
599 return TCORE_RETURN_ENOSYS;
601 pending = tcore_pending_new(o, 0);
603 req_data = tcore_user_request_ref_data(ur, NULL);
605 if (req_data->enable) {
606 dbg("Flight mode on/n");
607 cmd_str = g_strdup("AT+CFUN=4");
609 dbg("Flight mode off/n");
610 cmd_str = g_strdup("AT+CFUN=1");
613 req = tcore_at_request_new((const char *)cmd_str, NULL, TCORE_AT_NO_RESULT);
616 dbg("Command: [%s], Prefix(if any): [%s], Command Length: [%d]",
617 req->cmd, req->prefix, strlen(req->cmd));
619 tcore_pending_set_request_data(pending, 0, req);
620 tcore_pending_set_response_callback(pending, on_response_set_flight_mode, hal);
621 tcore_pending_link_user_request(pending, ur);
622 tcore_pending_set_send_callback(pending, on_confirmation_modem_message_send, NULL);
624 return tcore_hal_send_request(hal, pending);
628 static struct tcore_modem_operations modem_ops = {
630 .power_off = power_off,
632 .set_flight_mode = set_flight_mode,
633 .get_imei = get_imei,
634 .get_version = get_version,
636 .dun_pin_ctrl = NULL,
639 gboolean s_modem_init(TcorePlugin *cp, CoreObject *co_modem)
641 TelMiscVersionInformation *vi_property;
642 TelMiscSNInformation *imei_property;
643 TelMiscSNInformation *sn_property;
647 tcore_modem_override_ops(co_modem, &modem_ops);
649 vi_property = g_try_new0(TelMiscVersionInformation, 1);
650 tcore_plugin_link_property(cp, "VERSION", vi_property);
652 imei_property = g_try_new0(TelMiscSNInformation, 1);
653 tcore_plugin_link_property(cp, "IMEI", imei_property);
655 sn_property = g_try_new0(TelMiscSNInformation, 1);
656 tcore_plugin_link_property(cp, "SN", sn_property);
658 tcore_server_add_notification_hook(tcore_plugin_ref_server(cp),
659 TNOTI_SIM_STATUS, on_hook_sim_status, NULL);
660 dbg("Registering for +XDRVI event");
661 tcore_object_add_callback(co_modem, "+XDRVI", on_event_nvm_update, NULL);
667 void s_modem_exit(TcorePlugin *cp, CoreObject *co_modem)
669 TelMiscVersionInformation *vi_property;
670 TelMiscSNInformation *imei_property;
671 TelMiscSNInformation *sn_property;
672 TcorePlugin *plugin = tcore_object_ref_plugin(co_modem);
674 vi_property = tcore_plugin_ref_property(plugin, "VERSION");
677 imei_property = tcore_plugin_ref_property(plugin, "IMEI");
678 g_free(imei_property);
680 sn_property = tcore_plugin_ref_property(plugin, "SN");
687 * NV Manager - Support for Remote File System
690 static gboolean modem_rfs_hook(const char *data)
693 if (data[NVM_FUNCTION_ID_OFFSET] == XDRV_INDICATION)
699 /* NVM event Notification */
700 static gboolean on_event_nvm_update(CoreObject *o, const void *event_info, void *user_data)
702 GSList *tokens = NULL;
710 lines = (GSList *)event_info;
712 dbg("Line: [%s]", line);
714 function_id = nvm_sum_4_bytes(&line[NVM_FUNCTION_ID_OFFSET]);
715 dbg("Function ID: [%d]", function_id);
716 if (IUFP_UPDATE == function_id) {
717 dbg("Calling process nvm_update");
720 * Process NV Update indication
722 * +XDRVI: IUFP_GROUP, IUFP_UPDATE, <xdrv_result>, <data>
724 if (NVM_NO_ERR == nvm_process_nv_update(line)) {
725 dbg("NV data processed successfully");
727 /* Acknowledge NV Update */
728 modem_send_nvm_update_ack(o);
732 err("NV data processing failed");
736 tokens = tcore_at_tok_new(line);
737 if (g_slist_length(tokens) < 3) {
738 err("XDRVI event with less number of tokens, Ignore!!!");
741 else if (IUFP_GROUP_ID != atoi(g_slist_nth_data(tokens, 0))) {
742 err("Group ID mismatch, Ignore!!!");
746 switch (atoi(g_slist_nth_data(tokens, 1))) {
747 case IUFP_UPDATE_REQ:
748 dbg("NV Update Request");
750 /* Acknowledge the Update Request */
751 modem_send_nvm_update_request_ack(o);
754 case IUFP_NO_PENDING_UPDATE:
755 dbg("NO pending NV Update(s)!!!");
756 /* Can send FLUSH request to get fresh updates */
760 err("Unspported Function ID [%d], Ignore", atoi(g_slist_nth_data(tokens, 1)));
765 tcore_at_tok_free(tokens);
773 static gboolean __modem_check_nvm_response(const void *data, int command)
775 const TcoreATResponse *resp = data;
778 GSList *tokens = NULL;
779 gboolean ret = FALSE;
782 /* +XDRV: <group_id>,<function_id>,<xdrv_result>[,<response_n>] */
784 err("Input data is NULL");
788 if (resp->success > 0) {
790 line = (const char *) (((GSList *) resp->lines)->data);
791 tokens = tcore_at_tok_new(line);
794 resp_str = g_slist_nth_data(tokens, 0);
795 if (NULL == resp_str) {
796 err("Group ID is missing ");
799 else if (IUFP_GROUP_ID != atoi(resp_str)) {
800 err("Group ID mismatch");
805 resp_str = g_slist_nth_data(tokens, 1);
806 if (NULL == resp_str) {
807 err("Function ID is missing ");
810 else if (command != atoi(resp_str)) {
811 err("Function ID mismatch");
816 resp_str = g_slist_nth_data(tokens, 2);
817 if (NULL == resp_str) {
818 err("XDRV result is missing ");
821 else if (XDRV_RESULT_OK != atoi(resp_str)) {
822 err("XDRV result[%d] ", atoi(resp_str));
827 resp_str = g_slist_nth_data(tokens, 3);
828 if (NULL == resp_str) {
829 err("UTA result is missing ");
832 else if (UTA_SUCCESS != atoi(resp_str)) {
833 err("uta result[%d] ", atoi(resp_str));
843 tcore_at_tok_free(tokens);
849 static void _on_response_modem_unsuspend_nvm_updates(TcorePending *p,
850 int data_len, const void *data, void *user_data)
852 /* Check NVM response */
853 if (TRUE == __modem_check_nvm_response(data, IUFP_SUSPEND)) {
854 dbg("Priority level is set to get all updates since Boot-up");
856 /* Create NV data file */
857 if (nvm_create_nvm_data() == FALSE) {
858 err("Failed to Create NV data file");
864 err("Response NOT OK");
867 static void _on_response_modem_send_nvm_update_ack(TcorePending *p,
868 int data_len, const void *data, void *user_data)
870 /* Check NVM response */
871 if (TRUE == __modem_check_nvm_response(data, IUFP_UPDATE_ACK)) {
872 dbg("[UPDATE ACK] OK");
876 err("[UPDATE ACK] NOT OK");
879 static void _on_response_modem_send_nvm_update_request_ack(TcorePending *p,
880 int data_len, const void *data, void *user_data)
882 /* Check NVM response */
883 if (TRUE == __modem_check_nvm_response(data, IUFP_UPDATE_REQ_ACK)) {
884 dbg("[REQUEST ACK] OK");
888 err("[REQUEST ACK] NOT OK");
891 static void _on_response_modem_register_nvm(TcorePending *p,
892 int data_len, const void *data, void *user_data)
894 /* Check NVM response */
895 if (TRUE == __modem_check_nvm_response(data, IUFP_REGISTER)) {
896 dbg("Registering successful");
898 /* Send SUSPEND_UPDATE for all UPDATES */
899 modem_unsuspend_nvm_updates(tcore_pending_ref_core_object(p));
905 err("Response NOT OK");
909 static void modem_unsuspend_nvm_updates(CoreObject *o)
911 TcorePending *pending = NULL;
915 /* Prepare AT-Command */
916 cmd_str = g_strdup_printf("AT+XDRV=%d, %d, %d, %d",
917 IUFP_GROUP_ID, IUFP_SUSPEND,
918 0, UTA_FLASH_PLUGIN_PRIO_UNSUSPEND_ALL);
920 /* Prepare pending request */
921 pending = tcore_at_pending_new(o,
925 _on_response_modem_unsuspend_nvm_updates,
927 if (pending == NULL) {
928 err("Failed to form pending request");
930 else if (tcore_hal_send_request(tcore_object_get_hal(o), pending)
931 != TCORE_RETURN_SUCCESS) {
932 err("IUFP_SUSPEND - Unable to send AT-Command");
935 dbg("IUFP_SUSPEND - Successfully sent AT-Command");
941 static void modem_send_nvm_update_ack(CoreObject *o)
943 TcorePending *pending = NULL;
947 /* Prepare AT-Command */
948 cmd_str = g_strdup_printf("AT+XDRV=%s, %s", IUFP_GROUP, IUFP_UPDATE_ACK_STR);
950 /* Prepare pending request */
951 pending = tcore_at_pending_new(o,
955 _on_response_modem_send_nvm_update_ack,
957 if (pending == NULL) {
958 err("Failed to form pending request");
960 else if (tcore_hal_send_request(tcore_object_get_hal(o), pending)
961 != TCORE_RETURN_SUCCESS) {
962 err("IUFP_UPDATE_ACK - Unable to send AT-Command");
965 dbg("IUFP_UPDATE_ACK - Successfully sent AT-Command");
971 static void modem_send_nvm_update_request_ack(CoreObject *o)
973 TcorePending *pending = NULL;
977 /* Prepare AT-Command */
978 cmd_str = g_strdup_printf("AT+XDRV=%s, %s", IUFP_GROUP, IUFP_UPDATE_REQ_ACK_STR);
980 /* Prepare pending request */
981 pending = tcore_at_pending_new(o,
985 _on_response_modem_send_nvm_update_request_ack,
989 if (pending == NULL) {
990 err("Failed to form pending request");
992 else if (tcore_hal_send_request(tcore_object_get_hal(o), pending)
993 != TCORE_RETURN_SUCCESS) {
994 err("IUFP_UPDATE_REQ_ACK - Unable to send AT-Ccommand");
997 dbg("IUFP_UPDATE_REQ_ACK - Successfully sent AT-Command");
1003 void modem_register_nvm(CoreObject *co_modem)
1005 TcorePending *pending = NULL;
1009 /* Prepare AT-Command */
1010 cmd_str = g_strdup_printf("AT+XDRV=%s, %s, %s",
1011 IUFP_GROUP, IUFP_REGISTER_STR, XDRV_ENABLE);
1013 /* Prepare pending request */
1014 pending = tcore_at_pending_new(co_modem,
1017 TCORE_AT_SINGLELINE,
1018 _on_response_modem_register_nvm,
1020 if (pending == NULL) {
1021 err("Failed to form pending request");
1023 else if (tcore_hal_send_request(tcore_object_get_hal(co_modem), pending)
1024 != TCORE_RETURN_SUCCESS) {
1025 err("IUFP_REGISTER (Enable) -Unable to send AT-Command");
1028 dbg("IUFP_REGISTER (Enable) -Successfully sent AT-Command");
1031 tcore_at_add_hook(tcore_object_get_hal(co_modem), modem_rfs_hook);