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>
40 #include "imc_common.h"
41 #include "imc_modem.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);
169 if (ret != TCORE_RETURN_SUCCESS)
170 err("Failed to send AT request - ret: [0x%x]", ret);
174 static void on_response_power_off(TcorePending *p, int data_len, const void *data, void *user_data)
179 o = tcore_pending_ref_core_object(p);
180 h = tcore_object_get_hal(o);
182 dbg("modem power off");
184 tcore_hal_set_power_state(h, FALSE);
187 static void on_response_set_flight_mode(TcorePending *p, int data_len, const void *data, void *user_data)
189 CoreObject *o = NULL;
190 UserRequest *ur = NULL;
191 const TcoreATResponse *ATresp = data;
192 struct tresp_modem_set_flightmode res = {0};
194 struct tnoti_modem_flight_mode modem_flight_mode = {0};
196 o = tcore_pending_ref_core_object(p);
197 ur = tcore_pending_ref_user_request(p);
199 if (ATresp->success > 0) {
200 dbg("RESPONSE OK - flight mode operation finished");
201 res.result = TCORE_RETURN_SUCCESS;
203 GSList *tokens = NULL;
204 const char *line = NULL;
207 line = (const char *) ATresp->final_response;
208 tokens = tcore_at_tok_new(line);
210 if (g_slist_length(tokens) < 1) {
211 dbg("err cause not specified or string corrupted");
213 response = atoi(g_slist_nth_data(tokens, 0));
214 err("error response: %d", response);
215 /* TODO: CMEE error mapping is required. */
217 tcore_at_tok_free(tokens);
218 res.result = TCORE_RETURN_3GPP_ERROR;
222 dbg("No user request. Internal request created during boot-up sequence");
224 if (ATresp->success > 0) {
225 modem_flight_mode.enable = tcore_modem_get_flight_mode_state(o);
226 dbg("sucess case - Sending Flight Mode Notification (%d) to Telephony Server", modem_flight_mode.enable);
228 tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_MODEM_FLIGHT_MODE,
229 sizeof(struct tnoti_modem_flight_mode), &modem_flight_mode);
232 const struct treq_modem_set_flightmode *req_data = NULL;
234 dbg("Sending response for Flight mode operation");
236 req_data = tcore_user_request_ref_data(ur, NULL);
238 if (TCORE_RETURN_SUCCESS == res.result) {
239 if (TRUE == req_data->enable){
240 tcore_modem_set_flight_mode_state(o, TRUE);
242 tcore_modem_set_flight_mode_state(o, FALSE);
245 tcore_user_request_send_response(ur, TRESP_MODEM_SET_FLIGHTMODE, sizeof(struct tresp_modem_set_flightmode), &res);
247 modem_flight_mode.enable = tcore_modem_get_flight_mode_state(o);
248 tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_MODEM_FLIGHT_MODE,
249 sizeof(struct tnoti_modem_flight_mode), &modem_flight_mode);
251 if (req_data->enable == 0) {
252 dbg("Flight mode is disabled, trigger COPS to register on network");
253 /* Trigger Network registration (for the moment automatic) */
254 prepare_and_send_pending_request(o, "AT+COPS=0", NULL, TCORE_AT_NO_RESULT, NULL);
259 static void on_response_imei(TcorePending *p, int data_len, const void *data, void *user_data)
261 const TcoreATResponse *resp = data;
262 TcorePlugin *plugin = NULL;
263 struct tresp_modem_get_imei res;
264 TelMiscSNInformation *imei_property = NULL;
265 UserRequest *ur = NULL;
266 GSList *tokens = NULL;
270 memset(&res, 0, sizeof(struct tresp_modem_get_imei));
272 if (resp->success > 0) {
275 line = (const char *) resp->lines->data;
276 tokens = tcore_at_tok_new(line);
277 if (g_slist_length(tokens) != 1) {
278 msg("invalid message");
282 res.result = TCORE_RETURN_SUCCESS;
283 strncpy(res.imei, g_slist_nth_data(tokens, 0), 16);
285 dbg("imei = [%s]", res.imei);
287 plugin = tcore_pending_ref_plugin(p);
288 imei_property = tcore_plugin_ref_property(plugin, "IMEI");
290 imei_property->sn_index = TAPI_MISC_ME_IMEI;
291 imei_property->sn_len = strlen(res.imei);
292 memcpy(imei_property->szNumber, res.imei, imei_property->sn_len);
297 line = (const char *) resp->lines->data;
298 tokens = tcore_at_tok_new(line);
302 if (g_slist_length(tokens) < 1) {
303 dbg("err cause not specified or string corrupted");
304 res.result = TCORE_RETURN_3GPP_ERROR;
306 response = atoi(g_slist_nth_data(tokens, 0));
307 err("error response: %d", response);
308 /* TODO: CMEE error mapping is required. */
309 res.result = TCORE_RETURN_3GPP_ERROR;
313 ur = tcore_pending_ref_user_request(p);
314 tcore_user_request_send_response(ur, TRESP_MODEM_GET_IMEI,
315 sizeof(struct tresp_modem_get_imei), &res);
319 tcore_at_tok_free(tokens);
324 static void on_response_version(TcorePending *p, int data_len, const void *data, void *user_data)
326 const TcoreATResponse *resp = data;
327 TcorePlugin *plugin = NULL;
328 struct tresp_modem_get_version res = {0};
329 TelMiscVersionInformation *vi_property = NULL;
330 TelMiscVersionInformation *vi = NULL;
331 UserRequest *ur = NULL;
332 GSList *tokens = NULL;
333 const char *line = NULL;
336 char *caldate = NULL;
341 if (resp->success > 0) {
344 line = (const char *) resp->lines->data;
345 tokens = tcore_at_tok_new(line);
346 if (g_slist_length(tokens) == 1) {
347 swver = g_slist_nth_data(tokens, 0);
348 dbg("version: sw=[%s]", swver);
349 } else if (g_slist_length(tokens) == 5) {
350 swver = g_slist_nth_data(tokens, 0);
351 hwver = g_slist_nth_data(tokens, 1);
352 caldate = g_slist_nth_data(tokens, 2);
353 pcode = g_slist_nth_data(tokens, 3);
354 id = g_slist_nth_data(tokens, 4);
356 dbg("version: sw=[%s], hw=[%s], rf_cal=[%s], product_code=[%s], model_id=[%s]",
357 swver, hwver, caldate, pcode, id);
359 msg("invalid message");
364 vi = g_try_new0(TelMiscVersionInformation, 1);
366 memcpy(vi->szSwVersion, swver, strlen(swver));
368 memcpy(vi->szHwVersion, hwver, strlen(hwver));
370 memcpy(vi->szRfCalDate, caldate, strlen(caldate));
372 memcpy(vi->szProductCode, pcode, strlen(pcode));
374 memcpy(vi->szModelId, id, strlen(id));
376 memset(&res, 0, sizeof(struct tresp_modem_get_version));
379 snprintf(res.software,
380 (AT_VER_LEN > strlen(swver) ? strlen(swver) : AT_VER_LEN),
385 snprintf(res.hardware,
386 (AT_VER_LEN > strlen(hwver) ? strlen(hwver) : AT_VER_LEN),
390 plugin = tcore_pending_ref_plugin(p);
391 vi_property = tcore_plugin_ref_property(plugin, "VERSION");
392 memcpy(vi_property, vi, sizeof(TelMiscVersionInformation));
397 line = (const char *) resp->lines->data;
398 tokens = tcore_at_tok_new(line);
401 memset(&res, 0, sizeof(struct tresp_modem_get_version));
404 if (g_slist_length(tokens) < 1) {
405 dbg("err cause not specified or string corrupted");
406 res.result = TCORE_RETURN_3GPP_ERROR;
408 response = atoi(g_slist_nth_data(tokens, 0));
409 err("error response: %d", response);
410 /* TODO: CMEE error mapping is required. */
411 res.result = TCORE_RETURN_3GPP_ERROR;
415 ur = tcore_pending_ref_user_request(p);
416 tcore_user_request_send_response(ur, TRESP_MODEM_GET_VERSION,
417 sizeof(struct tresp_modem_get_version), &res);
421 tcore_at_tok_free(tokens);
426 static enum tcore_hook_return on_hook_sim_status(Server *s,
427 CoreObject *source, enum tcore_notification_command command,
428 unsigned int data_len, void *data, void *user_data)
431 const struct tnoti_sim_status *noti_sim_status;
433 CoreObject *co_network;
435 plugin = tcore_object_ref_plugin(source);
436 co_sat = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_SAT);
438 return TCORE_HOOK_RETURN_CONTINUE;
440 co_network = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_NETWORK);
441 if (co_network == NULL)
442 return TCORE_HOOK_RETURN_CONTINUE;
444 dbg("Get SIM status");
445 noti_sim_status = data;
446 if (noti_sim_status == NULL)
447 return TCORE_HOOK_RETURN_CONTINUE;
449 /* If SIM is initialized, Enable STK and and attach to Network */
450 dbg("SIM Status: [%d]", noti_sim_status->sim_status);
451 if (noti_sim_status->sim_status == SIM_STATUS_INIT_COMPLETED) {
452 dbg("SIM ready for attach!!! Enable STK and attach to Network");
454 /* Sending AT+CFUN=6 */
455 prepare_and_send_pending_request(co_sat, "AT+CFUN=6", NULL,
456 TCORE_AT_NO_RESULT, on_response_enable_proactive_command);
458 /* Sending AT+COPS */
459 prepare_and_send_pending_request(co_network, "AT+COPS=0", NULL,
460 TCORE_AT_NO_RESULT, on_response_network_registration);
463 return TCORE_HOOK_RETURN_CONTINUE;
466 gboolean modem_power_on(TcorePlugin *plugin)
468 CoreObject *co_modem = NULL;
469 struct treq_modem_set_flightmode flight_mode_set = {0};
470 struct tnoti_modem_power modem_power = {0};
471 Storage *strg = NULL;
473 co_modem = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_MODEM);
474 if (co_modem == NULL) {
475 err("Modem Core object is NULL");
479 /* Set Modem Power State to 'ON' */
480 tcore_modem_set_powered(co_modem, TRUE);
482 /* Get Flight mode from VCONFKEY */
483 strg = tcore_server_find_storage(tcore_plugin_ref_server(plugin), "vconf");
484 flight_mode_set.enable = tcore_storage_get_bool(strg, STORAGE_KEY_FLIGHT_MODE_BOOL);
486 /* Set Flight mode as per AP settings */
487 if (flight_mode_set.enable) { /* Radio OFF */
488 prepare_and_send_pending_request(co_modem, "AT+CFUN=4", NULL,
489 TCORE_AT_NO_RESULT, on_response_set_flight_mode);
491 /* Set Flight mode TRUE */
492 tcore_modem_set_flight_mode_state(co_modem, TRUE);
493 } else { /* Radio ON */
494 prepare_and_send_pending_request(co_modem, "AT+CFUN=1", NULL,
495 TCORE_AT_NO_RESULT, on_response_set_flight_mode);
497 /* Set Flight mode FALSE */
498 tcore_modem_set_flight_mode_state(co_modem, FALSE);
502 prepare_and_send_pending_request(co_modem, "AT+CGSN", NULL,
503 TCORE_AT_NUMERIC, on_response_imei);
505 /* Get Version Number */
506 prepare_and_send_pending_request(co_modem, "AT+CGMR", NULL,
507 TCORE_AT_SINGLELINE, on_response_version);
509 /* Send Notification to TAPI - MODEM_POWER */
510 modem_power.state = MODEM_STATE_ONLINE;
512 dbg("Sending notification - Modem Power state: [ONLINE]");
513 tcore_server_send_notification(tcore_plugin_ref_server(plugin),
514 co_modem, TNOTI_MODEM_POWER, sizeof(modem_power), &modem_power);
519 static TReturn power_off(CoreObject *o, UserRequest *ur)
521 TcoreHal *hal = NULL;
522 TcoreATRequest *req = NULL;
523 TcorePending *pending = NULL;
525 hal = tcore_object_get_hal(o);
526 pending = tcore_pending_new(o, 0);
528 req = tcore_at_request_new("AT+CFUN=0", NULL, TCORE_AT_NO_RESULT);
530 dbg("Command: [%s], Prefix(if any): [%s], Command Length: [%d]",
531 req->cmd, req->prefix, strlen(req->cmd));
533 tcore_pending_set_request_data(pending, 0, req);
534 tcore_pending_set_response_callback(pending, on_response_power_off, hal);
535 tcore_pending_link_user_request(pending, ur);
536 tcore_pending_set_send_callback(pending, on_confirmation_modem_message_send, NULL);
538 tcore_hal_send_request(hal, pending);
540 return TCORE_RETURN_SUCCESS;
543 static TReturn get_imei(CoreObject *o, UserRequest *ur)
547 TcorePending *pending = NULL;
549 hal = tcore_object_get_hal(o);
550 if (FALSE == tcore_hal_get_power_state(hal)) {
551 dbg("cp not ready/n");
552 return TCORE_RETURN_ENOSYS;
554 pending = tcore_pending_new(o, 0);
556 req = tcore_at_request_new("AT+CGSN", NULL, TCORE_AT_NUMERIC);
558 dbg("Command: [%s], Prefix(if any): [%s], Command Length: [%d]",
559 req->cmd, req->prefix, strlen(req->cmd));
561 tcore_pending_set_request_data(pending, 0, req);
562 tcore_pending_set_response_callback(pending, on_response_imei, hal);
563 tcore_pending_link_user_request(pending, ur);
564 tcore_pending_set_send_callback(pending, on_confirmation_modem_message_send, NULL);
566 return tcore_hal_send_request(hal, pending);
570 static TReturn get_version(CoreObject *o, UserRequest *ur)
574 TcorePending *pending = NULL;
576 hal = tcore_object_get_hal(o);
577 if (FALSE == tcore_hal_get_power_state(hal)) {
578 dbg("cp not ready/n");
579 return TCORE_RETURN_ENOSYS;
581 pending = tcore_pending_new(o, 0);
583 req = tcore_at_request_new("AT+CGMR", NULL, TCORE_AT_SINGLELINE);
585 dbg("Command: [%s], Prefix(if any): [%s], Command Length: [%d]",
586 req->cmd, req->prefix, strlen(req->cmd));
588 tcore_pending_set_request_data(pending, 0, req);
589 tcore_pending_set_response_callback(pending, on_response_version, hal);
590 tcore_pending_link_user_request(pending, ur);
591 tcore_pending_set_send_callback(pending, on_confirmation_modem_message_send, NULL);
593 return tcore_hal_send_request(hal, pending);
596 static TReturn set_flight_mode(CoreObject *o, UserRequest *ur)
598 TcoreHal *hal = NULL;
599 TcoreATRequest *req = NULL;
600 TcorePending *pending = NULL;
601 const struct treq_modem_set_flightmode *req_data = NULL;
602 char *cmd_str = NULL;
604 hal = tcore_object_get_hal(o);
605 if (FALSE == tcore_hal_get_power_state(hal)) {
606 dbg("cp not ready/n");
607 return TCORE_RETURN_ENOSYS;
609 pending = tcore_pending_new(o, 0);
611 req_data = tcore_user_request_ref_data(ur, NULL);
613 if (req_data->enable) {
614 dbg("Flight mode on/n");
615 cmd_str = g_strdup("AT+CFUN=4");
617 dbg("Flight mode off/n");
618 cmd_str = g_strdup("AT+CFUN=1");
621 req = tcore_at_request_new((const char *)cmd_str, NULL, TCORE_AT_NO_RESULT);
624 dbg("Command: [%s], Prefix(if any): [%s], Command Length: [%d]",
625 req->cmd, req->prefix, strlen(req->cmd));
627 tcore_pending_set_request_data(pending, 0, req);
628 tcore_pending_set_response_callback(pending, on_response_set_flight_mode, hal);
629 tcore_pending_link_user_request(pending, ur);
630 tcore_pending_set_send_callback(pending, on_confirmation_modem_message_send, NULL);
632 return tcore_hal_send_request(hal, pending);
635 static TReturn get_flight_mode(CoreObject *co_modem, UserRequest *ur)
637 struct tresp_modem_get_flightmode resp_data;
640 memset(&resp_data, 0x0, sizeof(struct tresp_modem_get_flightmode));
642 resp_data.enable = tcore_modem_get_flight_mode_state(co_modem);
643 resp_data.result = TCORE_RETURN_SUCCESS;
644 dbg("Get Flight mode: Flight mdoe: [%s]", (resp_data.enable ? "ON" : "OFF"));
646 ret = tcore_user_request_send_response(ur,
647 TRESP_MODEM_GET_FLIGHTMODE,
648 sizeof(struct tresp_modem_get_flightmode), &resp_data);
649 dbg("ret: [0x%x]", ret);
654 static struct tcore_modem_operations modem_ops = {
656 .power_off = power_off,
658 .set_flight_mode = set_flight_mode,
659 .get_flight_mode = get_flight_mode,
660 .get_imei = get_imei,
661 .get_version = get_version,
663 .dun_pin_ctrl = NULL,
666 gboolean imc_modem_init(TcorePlugin *cp, CoreObject *co_modem)
668 TelMiscVersionInformation *vi_property;
669 TelMiscSNInformation *imei_property;
670 TelMiscSNInformation *sn_property;
675 tcore_modem_set_ops(co_modem, &modem_ops);
677 vi_property = g_try_new0(TelMiscVersionInformation, 1);
678 tcore_plugin_link_property(cp, "VERSION", vi_property);
680 imei_property = g_try_new0(TelMiscSNInformation, 1);
681 tcore_plugin_link_property(cp, "IMEI", imei_property);
683 sn_property = g_try_new0(TelMiscSNInformation, 1);
684 tcore_plugin_link_property(cp, "SN", sn_property);
686 tcore_server_add_notification_hook(tcore_plugin_ref_server(cp),
687 TNOTI_SIM_STATUS, on_hook_sim_status, NULL);
688 dbg("Registering for +XDRVI event");
689 tcore_object_add_callback(co_modem, "+XDRVI", on_event_nvm_update, NULL);
695 void imc_modem_exit(TcorePlugin *cp, CoreObject *co_modem)
697 TelMiscVersionInformation *vi_property;
698 TelMiscSNInformation *imei_property;
699 TelMiscSNInformation *sn_property;
700 TcorePlugin *plugin = tcore_object_ref_plugin(co_modem);
702 vi_property = tcore_plugin_ref_property(plugin, "VERSION");
705 imei_property = tcore_plugin_ref_property(plugin, "IMEI");
706 g_free(imei_property);
708 sn_property = tcore_plugin_ref_property(plugin, "SN");
715 * NV Manager - Support for Remote File System
718 static gboolean modem_rfs_hook(const char *data)
721 if (data[NVM_FUNCTION_ID_OFFSET] == XDRV_INDICATION)
727 /* NVM event Notification */
728 static gboolean on_event_nvm_update(CoreObject *o, const void *event_info, void *user_data)
730 GSList *tokens = NULL;
738 lines = (GSList *)event_info;
740 dbg("Line: [%s]", line);
742 function_id = nvm_sum_4_bytes(&line[NVM_FUNCTION_ID_OFFSET]);
743 dbg("Function ID: [%d]", function_id);
744 if (IUFP_UPDATE == function_id) {
745 dbg("Calling process nvm_update");
748 * Process NV Update indication
750 * +XDRVI: IUFP_GROUP, IUFP_UPDATE, <xdrv_result>, <data>
752 if (NVM_NO_ERR == nvm_process_nv_update(line)) {
753 dbg("NV data processed successfully");
755 /* Acknowledge NV Update */
756 modem_send_nvm_update_ack(o);
760 err("NV data processing failed");
764 tokens = tcore_at_tok_new(line);
765 if (g_slist_length(tokens) < 3) {
766 err("XDRVI event with less number of tokens, Ignore!!!");
769 else if (IUFP_GROUP_ID != atoi(g_slist_nth_data(tokens, 0))) {
770 err("Group ID mismatch, Ignore!!!");
774 switch (atoi(g_slist_nth_data(tokens, 1))) {
775 case IUFP_UPDATE_REQ:
776 dbg("NV Update Request");
778 /* Acknowledge the Update Request */
779 modem_send_nvm_update_request_ack(o);
782 case IUFP_NO_PENDING_UPDATE:
783 dbg("NO pending NV Update(s)!!!");
784 /* Can send FLUSH request to get fresh updates */
788 err("Unspported Function ID [%d], Ignore", atoi(g_slist_nth_data(tokens, 1)));
793 tcore_at_tok_free(tokens);
801 static gboolean __modem_check_nvm_response(const void *data, int command)
803 const TcoreATResponse *resp = data;
806 GSList *tokens = NULL;
807 gboolean ret = FALSE;
810 /* +XDRV: <group_id>,<function_id>,<xdrv_result>[,<response_n>] */
812 err("Input data is NULL");
816 if (resp->success > 0) {
818 line = (const char *) (((GSList *) resp->lines)->data);
819 tokens = tcore_at_tok_new(line);
822 resp_str = g_slist_nth_data(tokens, 0);
823 if (NULL == resp_str) {
824 err("Group ID is missing ");
827 else if (IUFP_GROUP_ID != atoi(resp_str)) {
828 err("Group ID mismatch");
833 resp_str = g_slist_nth_data(tokens, 1);
834 if (NULL == resp_str) {
835 err("Function ID is missing ");
838 else if (command != atoi(resp_str)) {
839 err("Function ID mismatch");
844 resp_str = g_slist_nth_data(tokens, 2);
845 if (NULL == resp_str) {
846 err("XDRV result is missing ");
849 else if (XDRV_RESULT_OK != atoi(resp_str)) {
850 err("XDRV result[%d] ", atoi(resp_str));
855 resp_str = g_slist_nth_data(tokens, 3);
856 if (NULL == resp_str) {
857 err("UTA result is missing ");
860 else if (UTA_SUCCESS != atoi(resp_str)) {
861 err("uta result[%d] ", atoi(resp_str));
871 tcore_at_tok_free(tokens);
877 static void _on_response_modem_unsuspend_nvm_updates(TcorePending *p,
878 int data_len, const void *data, void *user_data)
880 /* Check NVM response */
881 if (TRUE == __modem_check_nvm_response(data, IUFP_SUSPEND)) {
882 dbg("Priority level is set to get all updates since Boot-up");
884 /* Create NV data file */
885 if (nvm_create_nvm_data() == FALSE) {
886 err("Failed to Create NV data file");
892 err("Response NOT OK");
895 static void _on_response_modem_send_nvm_update_ack(TcorePending *p,
896 int data_len, const void *data, void *user_data)
898 /* Check NVM response */
899 if (TRUE == __modem_check_nvm_response(data, IUFP_UPDATE_ACK)) {
900 dbg("[UPDATE ACK] OK");
904 err("[UPDATE ACK] NOT OK");
907 static void _on_response_modem_send_nvm_update_request_ack(TcorePending *p,
908 int data_len, const void *data, void *user_data)
910 /* Check NVM response */
911 if (TRUE == __modem_check_nvm_response(data, IUFP_UPDATE_REQ_ACK)) {
912 dbg("[REQUEST ACK] OK");
916 err("[REQUEST ACK] NOT OK");
919 static void _on_response_modem_register_nvm(TcorePending *p,
920 int data_len, const void *data, void *user_data)
922 /* Check NVM response */
923 if (TRUE == __modem_check_nvm_response(data, IUFP_REGISTER)) {
924 dbg("Registering successful");
926 /* Send SUSPEND_UPDATE for all UPDATES */
927 modem_unsuspend_nvm_updates(tcore_pending_ref_core_object(p));
933 err("Response NOT OK");
937 static void modem_unsuspend_nvm_updates(CoreObject *o)
939 TcorePending *pending = NULL;
943 /* Prepare AT-Command */
944 cmd_str = g_strdup_printf("AT+XDRV=%d, %d, %d, %d",
945 IUFP_GROUP_ID, IUFP_SUSPEND,
946 0, UTA_FLASH_PLUGIN_PRIO_UNSUSPEND_ALL);
948 /* Prepare pending request */
949 pending = tcore_at_pending_new(o,
953 _on_response_modem_unsuspend_nvm_updates,
955 if (pending == NULL) {
956 err("Failed to form pending request");
958 else if (tcore_hal_send_request(tcore_object_get_hal(o), pending)
959 != TCORE_RETURN_SUCCESS) {
960 err("IUFP_SUSPEND - Unable to send AT-Command");
963 dbg("IUFP_SUSPEND - Successfully sent AT-Command");
969 static void modem_send_nvm_update_ack(CoreObject *o)
971 TcorePending *pending = NULL;
975 /* Prepare AT-Command */
976 cmd_str = g_strdup_printf("AT+XDRV=%s, %s", IUFP_GROUP, IUFP_UPDATE_ACK_STR);
978 /* Prepare pending request */
979 pending = tcore_at_pending_new(o,
983 _on_response_modem_send_nvm_update_ack,
985 if (pending == NULL) {
986 err("Failed to form pending request");
988 else if (tcore_hal_send_request(tcore_object_get_hal(o), pending)
989 != TCORE_RETURN_SUCCESS) {
990 err("IUFP_UPDATE_ACK - Unable to send AT-Command");
993 dbg("IUFP_UPDATE_ACK - Successfully sent AT-Command");
999 static void modem_send_nvm_update_request_ack(CoreObject *o)
1001 TcorePending *pending = NULL;
1005 /* Prepare AT-Command */
1006 cmd_str = g_strdup_printf("AT+XDRV=%s, %s", IUFP_GROUP, IUFP_UPDATE_REQ_ACK_STR);
1008 /* Prepare pending request */
1009 pending = tcore_at_pending_new(o,
1012 TCORE_AT_SINGLELINE,
1013 _on_response_modem_send_nvm_update_request_ack,
1017 if (pending == NULL) {
1018 err("Failed to form pending request");
1020 else if (tcore_hal_send_request(tcore_object_get_hal(o), pending)
1021 != TCORE_RETURN_SUCCESS) {
1022 err("IUFP_UPDATE_REQ_ACK - Unable to send AT-Ccommand");
1025 dbg("IUFP_UPDATE_REQ_ACK - Successfully sent AT-Command");
1031 void modem_register_nvm(CoreObject *co_modem)
1033 TcorePending *pending = NULL;
1037 /* Prepare AT-Command */
1038 cmd_str = g_strdup_printf("AT+XDRV=%s, %s, %s",
1039 IUFP_GROUP, IUFP_REGISTER_STR, XDRV_ENABLE);
1041 /* Prepare pending request */
1042 pending = tcore_at_pending_new(co_modem,
1045 TCORE_AT_SINGLELINE,
1046 _on_response_modem_register_nvm,
1048 if (pending == NULL) {
1049 err("Failed to form pending request");
1051 else if (tcore_hal_send_request(tcore_object_get_hal(co_modem), pending)
1052 != TCORE_RETURN_SUCCESS) {
1053 err("IUFP_REGISTER (Enable) -Unable to send AT-Command");
1056 dbg("IUFP_REGISTER (Enable) -Successfully sent AT-Command");
1059 /* Todo unblock this api */
1060 tcore_at_add_hook(tcore_object_get_hal(co_modem), modem_rfs_hook);