#include <storage.h>
#include <server.h>
#include <at.h>
-#include <mux.h>
#include "imc_common.h"
#include "imc_modem.h"
#include "nvm/nvm.h"
-
-#define ID_RESERVED_AT 0x0229
-
-#define MAX_VERSION_LEN 32
-#define TAPI_MISC_ME_SN_LEN_MAX 32
-#define TAPI_MISC_PRODUCT_CODE_LEN_MAX 32
-#define TAPI_MISC_MODEL_ID_LEN_MAX 17
-#define TAPI_MISC_PRL_ERI_VER_LEN_MAX 17
-
-#define CPAS_RES_READY 0
-#define CPAS_RES_UNAVAIL 1
-#define CPAS_RES_UNKNOWN 2
-#define CPAS_RES_RINGING 3
-#define CPAS_RES_CALL_PROGRESS 4
-#define CPAS_RES_ASLEEP 5
-#define AT_VER_LEN 20
-
-
-enum cp_state {
- CP_STATE_OFFLINE,
- CP_STATE_CRASH_RESET,
- CP_STATE_CRASH_EXIT,
- CP_STATE_BOOTING,
- CP_STATE_ONLINE,
- CP_STATE_NV_REBUILDING,
- CP_STATE_LOADER_DONE,
-};
-
-typedef enum {
- TAPI_MISC_ME_IMEI = 0x00, /**< 0x00: IMEI, GSM/UMTS device */
- TAPI_MISC_ME_ESN = 0x01, /**< 0x01: ESN(Electronic Serial Number), It`s essentially run out. CDMA device */
- TAPI_MISC_ME_MEID = 0x02, /**< 0x02: MEID, This value can have hexa decimal digits. CDMA device */
- TAPI_MISC_ME_MAX = 0xff /**< 0xff: reserved */
-} TelMiscSNIndexType_t;
-
-typedef struct {
- TelMiscSNIndexType_t sn_index; /**< serial number index */
- int sn_len; /**< Length */
- unsigned char szNumber[TAPI_MISC_ME_SN_LEN_MAX]; /**< Number */
-} TelMiscSNInformation;
-
-/**
- * Mobile Equipment Version Information
+/*
+ * Modem Private data
*/
typedef struct {
- 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 */
- unsigned char szSwVersion[MAX_VERSION_LEN]; /**< Software version, null termination */
- unsigned char szHwVersion[MAX_VERSION_LEN]; /**< Hardware version, null termination */
- unsigned char szRfCalDate[MAX_VERSION_LEN]; /**< Calculation Date, null termination */
- unsigned char szProductCode[TAPI_MISC_PRODUCT_CODE_LEN_MAX]; /**< product code, null termination */
- unsigned char szModelId[TAPI_MISC_MODEL_ID_LEN_MAX]; /**< model id (only for CDMA), null termination */
- unsigned char prl_nam_num; /**< number of PRL NAM fields */
- unsigned char szPrlVersion[TAPI_MISC_PRL_ERI_VER_LEN_MAX * 3]; /**< prl version (only for CDMA), null termination */
- unsigned char eri_nam_num; /**< number of PRL NAM fields */
- unsigned char szEriVersion[TAPI_MISC_PRL_ERI_VER_LEN_MAX * 3]; /**< eri version (only for CDMA), null termination */
-} TelMiscVersionInformation;
-
-
-static void prepare_and_send_pending_request(CoreObject *co, const char *at_cmd, const char *prefix, enum tcore_at_command_type at_cmd_type, TcorePendingResponseCallback callback);
-static void on_confirmation_modem_message_send(TcorePending *p, gboolean result, void *user_data);
-static void on_response_network_registration(TcorePending *p, int data_len, const void *data, void *user_data);
-static void on_response_enable_proactive_command(TcorePending *p, int data_len, const void *data, void *user_data);
+ /* IMEI */
+ gboolean imei_valid; /**< IMEI validatity flag */
+ char imei[MODEM_DEVICE_IMEI_LEN_MAX];
+
+ /* Version information */
+ gboolean version_valid; /**< Version validatity flag */
+ char software[33];
+ char hardware[33];
+ char calibration[33];
+ char product_code[33];
+} PrivateData;
+
+static void on_confirmation_modem_message_send(TcorePending *pending,
+ gboolean result, void *user_data);
+static void on_response_network_registration(TcorePending *pending,
+ int data_len, const void *data, void *user_data);
+static void on_response_enable_proactive_command(TcorePending *pending,
+ int data_len, const void *data, void *user_data);
/* NVM */
-static gboolean on_event_nvm_update(CoreObject *o, const void *event_info, void *user_data);
-static void modem_unsuspend_nvm_updates(CoreObject *o);
-static void modem_send_nvm_update_ack(CoreObject *o);
-static void modem_send_nvm_update_request_ack(CoreObject *o);
-
-static void on_confirmation_modem_message_send(TcorePending *p, gboolean result, void *user_data)
+static gboolean on_event_modem_nvm_update(CoreObject *co_modem,
+ const void *event_info, void *user_data);
+static void modem_unsuspend_nvm_updates(CoreObject *co_modem);
+static void modem_send_nvm_update_ack(CoreObject *co_modem);
+static void modem_send_nvm_update_request_ack(CoreObject *co_modem);
+
+static void on_confirmation_modem_message_send(TcorePending *pending,
+ gboolean result, void *user_data)
{
- dbg("on_confirmation_modem_message_send - msg out from queue.\n");
-
- if (result == FALSE) {
- /* Fail */
- dbg("SEND FAIL");
- } else {
- dbg("SEND OK");
- }
+ dbg("Request send: [%s]", (result == TRUE ? "Success" : "Fail"));
}
-static void on_response_enable_proactive_command(TcorePending *p, int data_len, const void *data, void *user_data)
+static void on_response_enable_proactive_command(TcorePending *pending,
+ int data_len, const void *data, void *user_data)
{
- const TcoreATResponse *resp = data;
+ const TcoreATResponse *at_resp = data;
- if (resp->success > 0) {
- dbg("RESPONSE OK proactive command enabled");
- } else {
- dbg("RESPONSE NOK proactive command disabled");
- }
+ dbg("[Response] Pro-active command enabling - RESPONSE '%s'",
+ (at_resp->success > 0 ? "OK" : "NOK"));
}
-static void on_response_network_registration(TcorePending *p, int data_len, const void *data, void *user_data)
+static void on_response_network_registration(TcorePending *pending,
+ int data_len, const void *data, void *user_data)
{
- const TcoreATResponse *resp = data;
+ const TcoreATResponse *at_resp = data;
- if (resp->success > 0) {
- dbg("registration attempt OK");
- } else {
- dbg("registration attempt failed");
- }
+ dbg("[Response] Network Registration enable - RESPONSE '%s'",
+ (at_resp->success > 0 ? "OK" : "NOK"));
}
-void prepare_and_send_pending_request(CoreObject *co, const char *at_cmd, const char *prefix, enum tcore_at_command_type at_cmd_type, TcorePendingResponseCallback callback)
+static void on_response_modem_power_off(TcorePending *pending,
+ int data_len, const void *data, void *user_data)
{
- TcoreATRequest *req = NULL;
- TcoreHal *hal = NULL;
- TcorePending *pending = NULL;
- TReturn ret;
-
- hal = tcore_object_get_hal(co);
- dbg("hal: %p", hal);
-
- pending = tcore_pending_new(co, 0);
- if (!pending)
- dbg("Pending is NULL");
- req = tcore_at_request_new(at_cmd, prefix, at_cmd_type);
-
- dbg("cmd : %s, prefix(if any) :%s, cmd_len : %d", req->cmd, req->prefix, strlen(req->cmd));
-
- tcore_pending_set_request_data(pending, 0, req);
- tcore_pending_set_response_callback(pending, callback, NULL);
- tcore_pending_set_send_callback(pending, on_confirmation_modem_message_send, NULL);
- ret = tcore_hal_send_request(hal, pending);
-
- if (ret != TCORE_RETURN_SUCCESS)
- err("Failed to send AT request - ret: [0x%x]", ret);
+ const TcoreATResponse *at_resp = data;
+ struct tresp_modem_power_off modem_power_off_resp;
+ CoreObject *co_modem = 0;
+ UserRequest *ur;
+ TcoreHal *h = 0;
-}
+ dbg("[Response] Modem Power OFF - RESPONSE '%s'",
+ (at_resp->success > 0 ? "OK" : "NOK"));
-static void on_response_power_off(TcorePending *p, int data_len, const void *data, void *user_data)
-{
- CoreObject *o = 0;
- TcoreHal *h = 0;
+ co_modem = tcore_pending_ref_core_object(pending);
+ h = tcore_object_get_hal(co_modem);
- o = tcore_pending_ref_core_object(p);
- h = tcore_object_get_hal(o);
+ if (at_resp->success > 0) {
+ modem_power_off_resp.result = TCORE_RETURN_SUCCESS;
- dbg("modem power off");
+ /* Update HAL state */
+ tcore_hal_set_power_state(h, FALSE);
+ } else {
+ modem_power_off_resp.result = TCORE_RETURN_FAILURE;
+ }
- tcore_hal_set_power_state(h, FALSE);
+ /* Send Response */
+ ur = tcore_pending_ref_user_request(pending);
+ tcore_user_request_send_response(ur,
+ TRESP_MODEM_POWER_OFF,
+ sizeof(struct tresp_modem_power_off), &modem_power_off_resp);
}
-static void on_response_set_flight_mode(TcorePending *p, int data_len, const void *data, void *user_data)
+static void on_response_modem_set_flight_mode(TcorePending *pending,
+ int data_len, const void *data, void *user_data)
{
- CoreObject *o = NULL;
+ CoreObject *co_modem = NULL;
UserRequest *ur = NULL;
- const TcoreATResponse *ATresp = data;
- struct tresp_modem_set_flightmode res = {0};
+ const TcoreATResponse *at_resp = data;
+ struct tresp_modem_set_flightmode modem_set_flightmode_resp = {0};
int response = 0;
struct tnoti_modem_flight_mode modem_flight_mode = {0};
- o = tcore_pending_ref_core_object(p);
- ur = tcore_pending_ref_user_request(p);
+ co_modem = tcore_pending_ref_core_object(pending);
+ ur = tcore_pending_ref_user_request(pending);
- if (ATresp->success > 0) {
- dbg("RESPONSE OK - flight mode operation finished");
- res.result = TCORE_RETURN_SUCCESS;
+ dbg("[Response] Modem Set Flight mode - RESPONSE '%s'",
+ (at_resp->success > 0 ? "OK" : "NOK"));
+
+ if (at_resp->success > 0) {
+ modem_set_flightmode_resp.result = TCORE_RETURN_SUCCESS;
} else {
GSList *tokens = NULL;
const char *line = NULL;
- dbg("RESPONSE NOK");
- line = (const char *) ATresp->final_response;
+ line = (const char *) at_resp->final_response;
tokens = tcore_at_tok_new(line);
if (g_slist_length(tokens) < 1) {
/* TODO: CMEE error mapping is required. */
}
tcore_at_tok_free(tokens);
- res.result = TCORE_RETURN_3GPP_ERROR;
+ modem_set_flightmode_resp.result = TCORE_RETURN_3GPP_ERROR;
}
if (NULL == ur) {
- dbg("No user request. Internal request created during boot-up sequence");
+ dbg("Internal request created during boot-up sequence");
- if (ATresp->success > 0) {
- modem_flight_mode.enable = tcore_modem_get_flight_mode_state(o);
- dbg("sucess case - Sending Flight Mode Notification (%d) to Telephony Server", modem_flight_mode.enable);
+ if (at_resp->success > 0) {
+ Server *server;
- tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_MODEM_FLIGHT_MODE,
- sizeof(struct tnoti_modem_flight_mode), &modem_flight_mode);
+ modem_flight_mode.enable =
+ tcore_modem_get_flight_mode_state(co_modem);
+ dbg("Sending Flight Mode Notification (%d) to Telephony Server",
+ modem_flight_mode.enable);
+
+ server = tcore_plugin_ref_server(tcore_object_ref_plugin(co_modem));
+
+ /* Send Notification */
+ tcore_server_send_notification(server,
+ co_modem, TNOTI_MODEM_FLIGHT_MODE,
+ sizeof(struct tnoti_modem_flight_mode), &modem_flight_mode);
}
} else {
+ Server *server;
const struct treq_modem_set_flightmode *req_data = NULL;
dbg("Sending response for Flight mode operation");
req_data = tcore_user_request_ref_data(ur, NULL);
- if (TCORE_RETURN_SUCCESS == res.result) {
- if (TRUE == req_data->enable){
- tcore_modem_set_flight_mode_state(o, TRUE);
- } else {
- tcore_modem_set_flight_mode_state(o, FALSE);
- }
+ if (TCORE_RETURN_SUCCESS == modem_set_flightmode_resp.result) {
+ if (TRUE == req_data->enable)
+ tcore_modem_set_flight_mode_state(co_modem, TRUE);
+ else
+ tcore_modem_set_flight_mode_state(co_modem, FALSE);
}
- tcore_user_request_send_response(ur, TRESP_MODEM_SET_FLIGHTMODE, sizeof(struct tresp_modem_set_flightmode), &res);
- modem_flight_mode.enable = tcore_modem_get_flight_mode_state(o);
- tcore_server_send_notification(tcore_plugin_ref_server(tcore_object_ref_plugin(o)), o, TNOTI_MODEM_FLIGHT_MODE,
- sizeof(struct tnoti_modem_flight_mode), &modem_flight_mode);
+ /* Send Response */
+ tcore_user_request_send_response(ur,
+ TRESP_MODEM_SET_FLIGHTMODE,
+ sizeof(struct tresp_modem_set_flightmode), &modem_set_flightmode_resp);
+
+ modem_flight_mode.enable = tcore_modem_get_flight_mode_state(co_modem);
+
+
+ server = tcore_plugin_ref_server(tcore_object_ref_plugin(co_modem));
+
+ /* Send Notification */
+ tcore_server_send_notification(server,
+ co_modem, TNOTI_MODEM_FLIGHT_MODE,
+ sizeof(struct tnoti_modem_flight_mode), &modem_flight_mode);
if (req_data->enable == 0) {
dbg("Flight mode is disabled, trigger COPS to register on network");
+
/* Trigger Network registration (for the moment automatic) */
- prepare_and_send_pending_request(o, "AT+COPS=0", NULL, TCORE_AT_NO_RESULT, NULL);
+ tcore_prepare_and_send_at_request(co_modem,
+ "AT+COPS=0", NULL,
+ TCORE_AT_NO_RESULT, NULL,
+ NULL, NULL,
+ NULL, NULL, 0, NULL, NULL);
}
}
}
-static void on_response_imei(TcorePending *p, int data_len, const void *data, void *user_data)
+static void on_response_modem_get_imei(TcorePending *pending,
+ int data_len, const void *data, void *user_data)
{
- const TcoreATResponse *resp = data;
- TcorePlugin *plugin = NULL;
- struct tresp_modem_get_imei res;
- TelMiscSNInformation *imei_property = NULL;
+ const TcoreATResponse *at_resp = data;
+ struct tresp_modem_get_imei modem_get_imei_resp;
UserRequest *ur = NULL;
GSList *tokens = NULL;
const char *line;
- int response = 0;
- memset(&res, 0, sizeof(struct tresp_modem_get_imei));
+ memset(&modem_get_imei_resp, 0x0, sizeof(struct tresp_modem_get_imei));
+
+ if (at_resp->success > 0) {
+ CoreObject *co = NULL;
+ PrivateData *priv_data = NULL;
- if (resp->success > 0) {
dbg("RESPONSE OK");
- if (resp->lines) {
- line = (const char *) resp->lines->data;
+
+ if (at_resp->lines) {
+ line = (const char *) at_resp->lines->data;
tokens = tcore_at_tok_new(line);
if (g_slist_length(tokens) != 1) {
msg("invalid message");
goto OUT;
}
}
- res.result = TCORE_RETURN_SUCCESS;
- strncpy(res.imei, g_slist_nth_data(tokens, 0), 16);
- dbg("imei = [%s]", res.imei);
+ modem_get_imei_resp.result = TCORE_RETURN_SUCCESS;
+ strncpy(modem_get_imei_resp.imei, g_slist_nth_data(tokens, 0), MODEM_DEVICE_IMEI_LEN_MAX - 1);
+ dbg("IMEI: [%s]", modem_get_imei_resp.imei);
- plugin = tcore_pending_ref_plugin(p);
- imei_property = tcore_plugin_ref_property(plugin, "IMEI");
- if (imei_property) {
- imei_property->sn_index = TAPI_MISC_ME_IMEI;
- imei_property->sn_len = strlen(res.imei);
- memcpy(imei_property->szNumber, res.imei, imei_property->sn_len);
- }
+ /* Cache IMEI */
+ co = tcore_pending_ref_core_object(pending);
+ priv_data = tcore_object_ref_user_data(co);
+ priv_data->imei_valid = TRUE;
+ strncpy(priv_data->imei, modem_get_imei_resp.imei, MODEM_DEVICE_IMEI_LEN_MAX - 1);
} else {
dbg("RESPONSE NOK");
- if (resp->lines) {
- line = (const char *) resp->lines->data;
+
+ if (at_resp->lines) {
+ line = (const char *) at_resp->lines->data;
tokens = tcore_at_tok_new(line);
}
-
if (g_slist_length(tokens) < 1) {
dbg("err cause not specified or string corrupted");
- res.result = TCORE_RETURN_3GPP_ERROR;
+
+ modem_get_imei_resp.result = TCORE_RETURN_3GPP_ERROR;
} else {
- response = atoi(g_slist_nth_data(tokens, 0));
+ int response = atoi(g_slist_nth_data(tokens, 0));
err("error response: %d", response);
+
/* TODO: CMEE error mapping is required. */
- res.result = TCORE_RETURN_3GPP_ERROR;
+ modem_get_imei_resp.result = TCORE_RETURN_3GPP_ERROR;
}
}
- ur = tcore_pending_ref_user_request(p);
- tcore_user_request_send_response(ur, TRESP_MODEM_GET_IMEI,
- sizeof(struct tresp_modem_get_imei), &res);
+ /* Send Response */
+ ur = tcore_pending_ref_user_request(pending);
+ tcore_user_request_send_response(ur,
+ TRESP_MODEM_GET_IMEI,
+ sizeof(struct tresp_modem_get_imei), &modem_get_imei_resp);
OUT:
- if (tokens != NULL)
- tcore_at_tok_free(tokens);
-
- return;
+ tcore_at_tok_free(tokens);
}
-static void on_response_version(TcorePending *p, int data_len, const void *data, void *user_data)
+static void on_response_modem_get_version(TcorePending *pending,
+ int data_len, const void *data, void *user_data)
{
- const TcoreATResponse *resp = data;
- TcorePlugin *plugin = NULL;
- struct tresp_modem_get_version res = {0};
- TelMiscVersionInformation *vi_property = NULL;
- TelMiscVersionInformation *vi = NULL;
+ const TcoreATResponse *at_resp = data;
+ struct tresp_modem_get_version modem_get_version_resp;
UserRequest *ur = NULL;
GSList *tokens = NULL;
const char *line = NULL;
- char *swver = NULL;
- char *hwver = NULL;
- char *caldate = NULL;
- char *pcode = NULL;
- char *id = NULL;
- int response = 0;
- if (resp->success > 0) {
+ memset(&modem_get_version_resp, 0, sizeof(struct tresp_modem_get_version));
+
+ if (at_resp->success > 0) {
+ CoreObject *co = NULL;
+ PrivateData *priv_data = NULL;
+
+ char *software_version = NULL;
+ char *hardware_version = NULL;
+ char *calibration_date = NULL;
+ char *product_code = NULL;
+ char *model_id = NULL;
+
dbg("RESPONSE OK");
- if (resp->lines) {
- line = (const char *) resp->lines->data;
+
+ if (at_resp->lines) {
+ line = (const char *) at_resp->lines->data;
+
tokens = tcore_at_tok_new(line);
if (g_slist_length(tokens) == 1) {
- swver = g_slist_nth_data(tokens, 0);
- dbg("version: sw=[%s]", swver);
+ software_version = g_slist_nth_data(tokens, 0);
+ dbg("Software version: [%s]", software_version);
} else if (g_slist_length(tokens) == 5) {
- swver = g_slist_nth_data(tokens, 0);
- hwver = g_slist_nth_data(tokens, 1);
- caldate = g_slist_nth_data(tokens, 2);
- pcode = g_slist_nth_data(tokens, 3);
- id = g_slist_nth_data(tokens, 4);
-
- dbg("version: sw=[%s], hw=[%s], rf_cal=[%s], product_code=[%s], model_id=[%s]",
- swver, hwver, caldate, pcode, id);
+ software_version = g_slist_nth_data(tokens, 0);
+ hardware_version = g_slist_nth_data(tokens, 1);
+ calibration_date = g_slist_nth_data(tokens, 2);
+ product_code = g_slist_nth_data(tokens, 3);
+ model_id = g_slist_nth_data(tokens, 4);
+
+ dbg("Software version: [%s] Hardware version: [%s] " \
+ "Calibration: [%s] Product code: [%s] Model ID: [%s]",
+ software_version, hardware_version,
+ calibration_date, product_code, model_id);
} else {
- msg("invalid message");
+ err("Invalid message");
goto OUT;
}
}
- vi = g_try_new0(TelMiscVersionInformation, 1);
- if (NULL != swver)
- memcpy(vi->szSwVersion, swver, strlen(swver));
- if (NULL != hwver)
- memcpy(vi->szHwVersion, hwver, strlen(hwver));
- if (NULL != caldate)
- memcpy(vi->szRfCalDate, caldate, strlen(caldate));
- if (NULL != pcode)
- memcpy(vi->szProductCode, pcode, strlen(pcode));
- if (NULL != id)
- memcpy(vi->szModelId, id, strlen(id));
-
- memset(&res, 0, sizeof(struct tresp_modem_get_version));
-
- if (NULL != swver) {
- snprintf(res.software,
- (AT_VER_LEN > strlen(swver) ? strlen(swver) : AT_VER_LEN),
- "%s", swver);
+ co = tcore_pending_ref_core_object(pending);
+ priv_data = tcore_object_ref_user_data(co);
+
+ /*
+ * Update response structure and Cache data
+ */
+ priv_data->version_valid = TRUE;
+
+ /* Software version */
+ if (software_version) {
+ snprintf(modem_get_version_resp.software,
+ 33, "%s", software_version);
+ snprintf(priv_data->software,
+ 33, "%s", software_version);
+ }
+
+ /* Hardware version */
+ if (hardware_version) {
+ snprintf(modem_get_version_resp.hardware,
+ 33, "%s", hardware_version);
+ snprintf(priv_data->hardware,
+ 33, "%s", hardware_version);
}
- if (NULL != hwver) {
- snprintf(res.hardware,
- (AT_VER_LEN > strlen(hwver) ? strlen(hwver) : AT_VER_LEN),
- "%s", hwver);
+ /* Calibration date */
+ if (calibration_date) {
+ snprintf(modem_get_version_resp.calibration,
+ 33, "%s", calibration_date);
+ snprintf(priv_data->calibration,
+ 33, "%s", calibration_date);
}
- plugin = tcore_pending_ref_plugin(p);
- vi_property = tcore_plugin_ref_property(plugin, "VERSION");
- memcpy(vi_property, vi, sizeof(TelMiscVersionInformation));
- g_free(vi);
+ /* Product code */
+ if (product_code) {
+ snprintf(modem_get_version_resp.product_code,
+ 33, "%s", product_code);
+ snprintf(priv_data->product_code,
+ 33, "%s", product_code);
+ }
} else {
dbg("RESPONSE NOK");
- if (resp->lines) {
- line = (const char *) resp->lines->data;
+ if (at_resp->lines) {
+ line = (const char *) at_resp->lines->data;
tokens = tcore_at_tok_new(line);
}
- memset(&res, 0, sizeof(struct tresp_modem_get_version));
-
-
if (g_slist_length(tokens) < 1) {
dbg("err cause not specified or string corrupted");
- res.result = TCORE_RETURN_3GPP_ERROR;
+
+ modem_get_version_resp.result = TCORE_RETURN_3GPP_ERROR;
} else {
- response = atoi(g_slist_nth_data(tokens, 0));
+ int response = atoi(g_slist_nth_data(tokens, 0));
err("error response: %d", response);
+
/* TODO: CMEE error mapping is required. */
- res.result = TCORE_RETURN_3GPP_ERROR;
+ modem_get_version_resp.result = TCORE_RETURN_3GPP_ERROR;
}
}
- ur = tcore_pending_ref_user_request(p);
- tcore_user_request_send_response(ur, TRESP_MODEM_GET_VERSION,
- sizeof(struct tresp_modem_get_version), &res);
+ /* Send Response */
+ ur = tcore_pending_ref_user_request(pending);
+ tcore_user_request_send_response(ur,
+ TRESP_MODEM_GET_VERSION,
+ sizeof(struct tresp_modem_get_version), &modem_get_version_resp);
OUT:
- if (tokens != NULL)
- tcore_at_tok_free(tokens);
-
- return;
+ tcore_at_tok_free(tokens);
}
-static enum tcore_hook_return on_hook_sim_status(Server *s,
- CoreObject *source, enum tcore_notification_command command,
- unsigned int data_len, void *data, void *user_data)
+static enum tcore_hook_return on_hook_modem_sim_init_status(Server *s,
+ CoreObject *source, enum tcore_notification_command command,
+ unsigned int data_len, void *data, void *user_data)
{
- TcorePlugin *plugin;
const struct tnoti_sim_status *noti_sim_status;
- CoreObject *co_sat;
- CoreObject *co_network;
- plugin = tcore_object_ref_plugin(source);
- co_sat = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_SAT);
- if (co_sat == NULL)
- return TCORE_HOOK_RETURN_CONTINUE;
+ dbg("SIM INIT Status");
- co_network = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_NETWORK);
- if (co_network == NULL)
- return TCORE_HOOK_RETURN_CONTINUE;
-
- dbg("Get SIM status");
noti_sim_status = data;
- if (noti_sim_status == NULL)
+ if (noti_sim_status == NULL) {
+ err("SIM notification data is NULL");
return TCORE_HOOK_RETURN_CONTINUE;
+ }
/* If SIM is initialized, Enable STK and and attach to Network */
dbg("SIM Status: [%d]", noti_sim_status->sim_status);
if (noti_sim_status->sim_status == SIM_STATUS_INIT_COMPLETED) {
+ TcorePlugin *plugin;
+ CoreObject *co_network;
+ CoreObject *co_sat;
+
dbg("SIM ready for attach!!! Enable STK and attach to Network");
- /* Sending AT+CFUN=6 */
- prepare_and_send_pending_request(co_sat, "AT+CFUN=6", NULL,
- TCORE_AT_NO_RESULT, on_response_enable_proactive_command);
+ plugin = tcore_object_ref_plugin(source);
+
+ co_network = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_NETWORK);
+ if (co_network) {
+ /* Sending AT+COPS */
+ tcore_prepare_and_send_at_request(co_network,
+ "AT+COPS=0", NULL,
+ TCORE_AT_NO_RESULT, NULL,
+ on_response_network_registration, NULL,
+ NULL, NULL, 0, NULL, NULL);
+ }
+
+ co_sat = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_SAT);
+ if (co_sat) {
+ /* Sending AT+CFUN=6 */
+ tcore_prepare_and_send_at_request(co_sat,
+ "AT+CFUN=6", NULL,
+ TCORE_AT_NO_RESULT, NULL,
+ on_response_enable_proactive_command, NULL,
+ NULL, NULL, 0, NULL, NULL);
+ }
- /* Sending AT+COPS */
- prepare_and_send_pending_request(co_network, "AT+COPS=0", NULL,
- TCORE_AT_NO_RESULT, on_response_network_registration);
}
return TCORE_HOOK_RETURN_CONTINUE;
gboolean modem_power_on(TcorePlugin *plugin)
{
+ Server *server;
CoreObject *co_modem = NULL;
- struct treq_modem_set_flightmode flight_mode_set = {0};
- struct tnoti_modem_power modem_power = {0};
+ struct treq_modem_set_flightmode flight_mode_set;
+ struct tnoti_modem_power modem_power;
Storage *strg = NULL;
co_modem = tcore_plugin_ref_core_object(plugin, CORE_OBJECT_TYPE_MODEM);
/* Set Modem Power State to 'ON' */
tcore_modem_set_powered(co_modem, TRUE);
+ server = tcore_plugin_ref_server(plugin);
+
/* Get Flight mode from VCONFKEY */
- strg = tcore_server_find_storage(tcore_plugin_ref_server(plugin), "vconf");
+ strg = tcore_server_find_storage(server, "vconf");
flight_mode_set.enable = tcore_storage_get_bool(strg, STORAGE_KEY_FLIGHT_MODE_BOOL);
- /* Set Flight mode as per AP settings */
+ /*
+ * Set Flight mode as per AP settings
+ */
if (flight_mode_set.enable) { /* Radio OFF */
- prepare_and_send_pending_request(co_modem, "AT+CFUN=4", NULL,
- TCORE_AT_NO_RESULT, on_response_set_flight_mode);
+ dbg("Enabling Flight mode");
+
+ tcore_prepare_and_send_at_request(co_modem,
+ "AT+CFUN=4", NULL,
+ TCORE_AT_NO_RESULT, NULL,
+ on_response_modem_set_flight_mode, NULL,
+ NULL, NULL, 0, NULL, NULL);
/* Set Flight mode TRUE */
tcore_modem_set_flight_mode_state(co_modem, TRUE);
- } else { /* Radio ON */
- prepare_and_send_pending_request(co_modem, "AT+CFUN=1", NULL,
- TCORE_AT_NO_RESULT, on_response_set_flight_mode);
+ } else { /* Radio ON */
+ dbg("Disabling Flight mode");
+
+ tcore_prepare_and_send_at_request(co_modem,
+ "AT+CFUN=1", NULL,
+ TCORE_AT_NO_RESULT, NULL,
+ on_response_modem_set_flight_mode, NULL,
+ NULL, NULL, 0, NULL, NULL);
/* Set Flight mode FALSE */
tcore_modem_set_flight_mode_state(co_modem, FALSE);
}
/* Get IMEI */
- prepare_and_send_pending_request(co_modem, "AT+CGSN", NULL,
- TCORE_AT_NUMERIC, on_response_imei);
+ tcore_prepare_and_send_at_request(co_modem,
+ "AT+CGSN", NULL,
+ TCORE_AT_NUMERIC, NULL,
+ on_response_modem_get_imei, NULL,
+ NULL, NULL, 0, NULL, NULL);
/* Get Version Number */
- prepare_and_send_pending_request(co_modem, "AT+CGMR", NULL,
- TCORE_AT_SINGLELINE, on_response_version);
+ tcore_prepare_and_send_at_request(co_modem,
+ "AT+CGMR", NULL,
+ TCORE_AT_SINGLELINE, NULL,
+ on_response_modem_get_version, NULL,
+ NULL, NULL, 0, NULL, NULL);
- /* Send Notification to TAPI - MODEM_POWER */
+ /* Send Notification - MODEM_POWER */
modem_power.state = MODEM_STATE_ONLINE;
dbg("Sending notification - Modem Power state: [ONLINE]");
- tcore_server_send_notification(tcore_plugin_ref_server(plugin),
- co_modem, TNOTI_MODEM_POWER, sizeof(modem_power), &modem_power);
+ tcore_server_send_notification(server, co_modem,
+ TNOTI_MODEM_POWER,
+ sizeof(modem_power), &modem_power);
return TRUE;
}
-static TReturn power_off(CoreObject *o, UserRequest *ur)
+static TReturn modem_power_off(CoreObject *co_modem, UserRequest *ur)
{
- TcoreHal *hal = NULL;
- TcoreATRequest *req = NULL;
- TcorePending *pending = NULL;
+ TcoreHal *hal;
- hal = tcore_object_get_hal(o);
- pending = tcore_pending_new(o, 0);
+ hal = tcore_object_get_hal(co_modem);
+ if (FALSE == tcore_hal_get_power_state(hal)) {
+ struct tresp_modem_power_off modem_power_off_resp;
- req = tcore_at_request_new("AT+CFUN=0", NULL, TCORE_AT_NO_RESULT);
+ err("Modem is in Powered OFF state!");
- dbg("Command: [%s], Prefix(if any): [%s], Command Length: [%d]",
- req->cmd, req->prefix, strlen(req->cmd));
+ modem_power_off_resp.result = TCORE_RETURN_SUCCESS;
- tcore_pending_set_request_data(pending, 0, req);
- tcore_pending_set_response_callback(pending, on_response_power_off, hal);
- tcore_pending_link_user_request(pending, ur);
- tcore_pending_set_send_callback(pending, on_confirmation_modem_message_send, NULL);
+ tcore_user_request_send_response(ur,
+ TRESP_MODEM_POWER_OFF,
+ sizeof(struct tresp_modem_power_off), &modem_power_off_resp);
- tcore_hal_send_request(hal, pending);
+ return TCORE_RETURN_SUCCESS;
+ }
+
+ dbg("[Request] Modem Power OFF - Command: [%s]", "AT+CFUN=0");
- return TCORE_RETURN_SUCCESS;
+ return tcore_prepare_and_send_at_request(co_modem,
+ "AT+CFUN=0", NULL,
+ TCORE_AT_NO_RESULT, ur,
+ on_response_modem_power_off, hal,
+ on_confirmation_modem_message_send, NULL,
+ 0, NULL, NULL);
}
-static TReturn get_imei(CoreObject *o, UserRequest *ur)
+static TReturn modem_get_imei(CoreObject *co_modem, UserRequest *ur)
{
+ PrivateData *priv_data = NULL;
TcoreHal *hal;
- TcoreATRequest *req;
- TcorePending *pending = NULL;
- hal = tcore_object_get_hal(o);
+ dbg("Exit");
+
+ hal = tcore_object_get_hal(co_modem);
if (FALSE == tcore_hal_get_power_state(hal)) {
- dbg("cp not ready/n");
+ err("CP not ready!");
return TCORE_RETURN_ENOSYS;
}
- pending = tcore_pending_new(o, 0);
-
- req = tcore_at_request_new("AT+CGSN", NULL, TCORE_AT_NUMERIC);
- dbg("Command: [%s], Prefix(if any): [%s], Command Length: [%d]",
- req->cmd, req->prefix, strlen(req->cmd));
+ /*
+ * Check if valid IMEI is available in Cache -
+ * if Yes, then provide form Cache;
+ * else, fetch from CP
+ */
+ priv_data = tcore_object_ref_user_data(co_modem);
+ if (priv_data && priv_data->imei_valid) {
+ struct tresp_modem_get_imei modem_get_imei_resp;
+ TReturn ret;
+
+ memset(&modem_get_imei_resp, 0x0, sizeof(struct tresp_modem_get_imei));
+
+ modem_get_imei_resp.result = TCORE_RETURN_SUCCESS;
+ memcpy(modem_get_imei_resp.imei,
+ priv_data->imei, MODEM_DEVICE_IMEI_LEN_MAX);
+
+ dbg("Valid IMEI information present in cache - IMEI: [%s]",
+ modem_get_imei_resp.imei);
+
+ /* Send Response */
+ ret = tcore_user_request_send_response(ur,
+ TRESP_MODEM_GET_IMEI,
+ sizeof(struct tresp_modem_get_imei), &modem_get_imei_resp);
+ if (ret == TCORE_RETURN_SUCCESS)
+ tcore_user_request_unref(ur);
+
+ return ret;
+ }
- tcore_pending_set_request_data(pending, 0, req);
- tcore_pending_set_response_callback(pending, on_response_imei, hal);
- tcore_pending_link_user_request(pending, ur);
- tcore_pending_set_send_callback(pending, on_confirmation_modem_message_send, NULL);
+ dbg("[Request] Get IMEI - Command: [%s]", "AT+CGSN");
- return tcore_hal_send_request(hal, pending);
+ return tcore_prepare_and_send_at_request(co_modem,
+ "AT+CGSN", NULL,
+ TCORE_AT_NUMERIC, ur,
+ on_response_modem_get_imei, hal,
+ on_confirmation_modem_message_send, NULL,
+ 0, NULL, NULL);
}
-static TReturn get_version(CoreObject *o, UserRequest *ur)
+static TReturn modem_get_version(CoreObject *co_modem, UserRequest *ur)
{
+ PrivateData *priv_data = NULL;
TcoreHal *hal;
- TcoreATRequest *req;
- TcorePending *pending = NULL;
- hal = tcore_object_get_hal(o);
+ hal = tcore_object_get_hal(co_modem);
if (FALSE == tcore_hal_get_power_state(hal)) {
- dbg("cp not ready/n");
+ err("CP not ready!");
return TCORE_RETURN_ENOSYS;
}
- pending = tcore_pending_new(o, 0);
-
- req = tcore_at_request_new("AT+CGMR", NULL, TCORE_AT_SINGLELINE);
- dbg("Command: [%s], Prefix(if any): [%s], Command Length: [%d]",
- req->cmd, req->prefix, strlen(req->cmd));
+ /*
+ * Check if valid Version information is available in Cache -
+ * if Yes, then provide form Cache;
+ * else, fetch from CP
+ */
+ priv_data = tcore_object_ref_user_data(co_modem);
+ if (priv_data && priv_data->version_valid) {
+ struct tresp_modem_get_version modem_get_version_resp;
+ TReturn ret;
+
+ memset(&modem_get_version_resp, 0x0, sizeof(struct tresp_modem_get_version));
+
+ modem_get_version_resp.result = TCORE_RETURN_SUCCESS;
+ snprintf(modem_get_version_resp.software,
+ 33, "%s", priv_data->software);
+ snprintf(modem_get_version_resp.hardware,
+ 33, "%s", priv_data->hardware);
+ snprintf(modem_get_version_resp.calibration,
+ 33, "%s", priv_data->calibration);
+ snprintf(modem_get_version_resp.product_code,
+ 33, "%s", priv_data->product_code);
+
+ dbg("Valid Version information present in cache -" \
+ "Software: [%s] Hardware: [%s] Calibration: [%s] Product code: [%s]",
+ modem_get_version_resp.software, modem_get_version_resp.hardware,
+ modem_get_version_resp.calibration, modem_get_version_resp.product_code);
+
+ /* Send Response */
+ ret = tcore_user_request_send_response(ur,
+ TRESP_MODEM_GET_VERSION,
+ sizeof(struct tresp_modem_get_version), &modem_get_version_resp);
+ if (ret == TCORE_RETURN_SUCCESS)
+ tcore_user_request_unref(ur);
+
+ return ret;
+ }
- tcore_pending_set_request_data(pending, 0, req);
- tcore_pending_set_response_callback(pending, on_response_version, hal);
- tcore_pending_link_user_request(pending, ur);
- tcore_pending_set_send_callback(pending, on_confirmation_modem_message_send, NULL);
+ dbg("[Request] Get VERSION - Command: [%s]", "AT+CGMR");
- return tcore_hal_send_request(hal, pending);
+ return tcore_prepare_and_send_at_request(co_modem,
+ "AT+CGMR", NULL,
+ TCORE_AT_SINGLELINE, ur,
+ on_response_modem_get_version, hal,
+ on_confirmation_modem_message_send, NULL,
+ 0, NULL, NULL);
}
-static TReturn set_flight_mode(CoreObject *o, UserRequest *ur)
+static TReturn modem_set_flight_mode(CoreObject *co_modem, UserRequest *ur)
{
TcoreHal *hal = NULL;
- TcoreATRequest *req = NULL;
- TcorePending *pending = NULL;
const struct treq_modem_set_flightmode *req_data = NULL;
char *cmd_str = NULL;
- hal = tcore_object_get_hal(o);
+ hal = tcore_object_get_hal(co_modem);
if (FALSE == tcore_hal_get_power_state(hal)) {
- dbg("cp not ready/n");
+ err("CP not ready!");
return TCORE_RETURN_ENOSYS;
}
- pending = tcore_pending_new(o, 0);
req_data = tcore_user_request_ref_data(ur, NULL);
-
- if (req_data->enable) {
- dbg("Flight mode on/n");
- cmd_str = g_strdup("AT+CFUN=4");
- } else {
- dbg("Flight mode off/n");
- cmd_str = g_strdup("AT+CFUN=1");
- }
-
- req = tcore_at_request_new((const char *)cmd_str, NULL, TCORE_AT_NO_RESULT);
- g_free(cmd_str);
-
- dbg("Command: [%s], Prefix(if any): [%s], Command Length: [%d]",
- req->cmd, req->prefix, strlen(req->cmd));
-
- tcore_pending_set_request_data(pending, 0, req);
- tcore_pending_set_response_callback(pending, on_response_set_flight_mode, hal);
- tcore_pending_link_user_request(pending, ur);
- tcore_pending_set_send_callback(pending, on_confirmation_modem_message_send, NULL);
-
- return tcore_hal_send_request(hal, pending);
+ if (req_data->enable)
+ cmd_str = "AT+CFUN=4";
+ else
+ cmd_str = "AT+CFUN=1";
+
+ dbg("[Request] Set Modem Flight mode [%s] - Command: [%s]",
+ (req_data->enable ? "ON" : "OFF"), cmd_str);
+
+ return tcore_prepare_and_send_at_request(co_modem,
+ (const char *)cmd_str, NULL,
+ TCORE_AT_NO_RESULT, ur,
+ on_response_modem_set_flight_mode, hal,
+ on_confirmation_modem_message_send, NULL,
+ 0, NULL, NULL);
}
-static TReturn get_flight_mode(CoreObject *co_modem, UserRequest *ur)
+static TReturn modem_get_flight_mode(CoreObject *co_modem, UserRequest *ur)
{
- struct tresp_modem_get_flightmode resp_data;
+ struct tresp_modem_get_flightmode modem_get_flightmode_resp;
TReturn ret;
- memset(&resp_data, 0x0, sizeof(struct tresp_modem_get_flightmode));
+ dbg("[Request] Get Modem Flight mode");
+
+ memset(&modem_get_flightmode_resp, 0x0, sizeof(struct tresp_modem_get_flightmode));
- resp_data.enable = tcore_modem_get_flight_mode_state(co_modem);
- resp_data.result = TCORE_RETURN_SUCCESS;
- dbg("Get Flight mode: Flight mdoe: [%s]", (resp_data.enable ? "ON" : "OFF"));
+ modem_get_flightmode_resp.result = TCORE_RETURN_SUCCESS;
+ modem_get_flightmode_resp.enable = tcore_modem_get_flight_mode_state(co_modem);
+ dbg("Flight mode: [%s]", (modem_get_flightmode_resp.enable ? "ON" : "OFF"));
ret = tcore_user_request_send_response(ur,
TRESP_MODEM_GET_FLIGHTMODE,
- sizeof(struct tresp_modem_get_flightmode), &resp_data);
- dbg("ret: [0x%x]", ret);
+ sizeof(struct tresp_modem_get_flightmode), &modem_get_flightmode_resp);
+ if (ret == TCORE_RETURN_SUCCESS)
+ tcore_user_request_unref(ur);
return ret;
}
+/* Modem operations */
static struct tcore_modem_operations modem_ops = {
.power_on = NULL,
- .power_off = power_off,
+ .power_off = modem_power_off,
.power_reset = NULL,
- .set_flight_mode = set_flight_mode,
- .get_flight_mode = get_flight_mode,
- .get_imei = get_imei,
- .get_version = get_version,
+ .set_flight_mode = modem_set_flight_mode,
+ .get_flight_mode = modem_get_flight_mode,
+ .get_imei = modem_get_imei,
+ .get_version = modem_get_version,
.get_sn = NULL,
.dun_pin_ctrl = NULL,
};
-gboolean imc_modem_init(TcorePlugin *cp, CoreObject *co_modem)
+gboolean imc_modem_init(TcorePlugin *plugin, CoreObject *co_modem)
{
- TelMiscVersionInformation *vi_property;
- TelMiscSNInformation *imei_property;
- TelMiscSNInformation *sn_property;
+ PrivateData *priv_data = NULL;
dbg("Enter");
/* Set operations */
- tcore_modem_set_ops(co_modem, &modem_ops);
-
- vi_property = g_try_new0(TelMiscVersionInformation, 1);
- tcore_plugin_link_property(cp, "VERSION", vi_property);
+ tcore_modem_set_ops(co_modem, &modem_ops, TCORE_OPS_TYPE_CP);
- imei_property = g_try_new0(TelMiscSNInformation, 1);
- tcore_plugin_link_property(cp, "IMEI", imei_property);
+ /* Private data */
+ priv_data = g_malloc0(sizeof(PrivateData));
+ priv_data->imei_valid = FALSE;
+ priv_data->version_valid = FALSE;
+ tcore_object_link_user_data(co_modem, priv_data);
- sn_property = g_try_new0(TelMiscSNInformation, 1);
- tcore_plugin_link_property(cp, "SN", sn_property);
+ /* Notification hooks */
+ tcore_server_add_notification_hook(tcore_plugin_ref_server(plugin),
+ TNOTI_SIM_STATUS, on_hook_modem_sim_init_status, NULL);
- tcore_server_add_notification_hook(tcore_plugin_ref_server(cp),
- TNOTI_SIM_STATUS, on_hook_sim_status, NULL);
dbg("Registering for +XDRVI event");
- tcore_object_add_callback(co_modem, "+XDRVI", on_event_nvm_update, NULL);
+ tcore_object_add_callback(co_modem,
+ "+XDRVI", on_event_modem_nvm_update, NULL);
dbg("Exit");
return TRUE;
}
-void imc_modem_exit(TcorePlugin *cp, CoreObject *co_modem)
+void imc_modem_exit(TcorePlugin *plugin, CoreObject *co_modem)
{
- TelMiscVersionInformation *vi_property;
- TelMiscSNInformation *imei_property;
- TelMiscSNInformation *sn_property;
- TcorePlugin *plugin = tcore_object_ref_plugin(co_modem);
-
- vi_property = tcore_plugin_ref_property(plugin, "VERSION");
- g_free(vi_property);
-
- imei_property = tcore_plugin_ref_property(plugin, "IMEI");
- g_free(imei_property);
-
- sn_property = tcore_plugin_ref_property(plugin, "SN");
- g_free(sn_property);
+ PrivateData *priv_data = NULL;
dbg("Exit");
+
+ priv_data = tcore_object_ref_user_data(co_modem);
+ g_free(priv_data);
}
/*
* NV Manager - Support for Remote File System
*/
/* NVM Hook */
-static gboolean modem_rfs_hook(const char *data)
+static gboolean __modem_rfs_hook(const char *data)
{
- if (data != NULL)
- if (data[NVM_FUNCTION_ID_OFFSET] == XDRV_INDICATION)
- return TRUE;
+ if (data && data[NVM_FUNCTION_ID_OFFSET] == XDRV_INDICATION)
+ return TRUE;
return FALSE;
}
/* NVM event Notification */
-static gboolean on_event_nvm_update(CoreObject *o, const void *event_info, void *user_data)
+static gboolean on_event_modem_nvm_update(CoreObject *co_modem,
+ const void *event_info, void *user_data)
{
GSList *tokens = NULL;
GSList *lines;
dbg("NV data processed successfully");
/* Acknowledge NV Update */
- modem_send_nvm_update_ack(o);
+ modem_send_nvm_update_ack(co_modem);
return ret;
} else {
if (g_slist_length(tokens) < 3) {
err("XDRVI event with less number of tokens, Ignore!!!");
ret = FALSE;
- }
- else if (IUFP_GROUP_ID != atoi(g_slist_nth_data(tokens, 0))) {
+ } else if (IUFP_GROUP_ID != atoi(g_slist_nth_data(tokens, 0))) {
err("Group ID mismatch, Ignore!!!");
ret = FALSE;
- }
- else {
- switch (atoi(g_slist_nth_data(tokens, 1))) {
- case IUFP_UPDATE_REQ:
- dbg("NV Update Request");
-
- /* Acknowledge the Update Request */
- modem_send_nvm_update_request_ack(o);
- break;
-
- case IUFP_NO_PENDING_UPDATE:
- dbg("NO pending NV Update(s)!!!");
- /* Can send FLUSH request to get fresh updates */
- break;
-
- default:
- err("Unspported Function ID [%d], Ignore", atoi(g_slist_nth_data(tokens, 1)));
- ret = FALSE;
+ } else {
+ int command = atoi(g_slist_nth_data(tokens, 1));
+ switch (command) {
+ case IUFP_UPDATE_REQ:
+ dbg("NV Update Request");
+
+ /* Acknowledge the Update Request */
+ modem_send_nvm_update_request_ack(co_modem);
+ break;
+
+ case IUFP_NO_PENDING_UPDATE:
+ dbg("NO pending NV Update(s)!!!");
+ /* Can send FLUSH request to get fresh updates */
+ break;
+
+ default:
+ err("Unspported Function ID [%d], Ignore", command);
+ ret = FALSE;
+ break;
}
}
/* NVM Responses */
static gboolean __modem_check_nvm_response(const void *data, int command)
{
- const TcoreATResponse *resp = data;
+ const TcoreATResponse *at_resp = data;
const char *line;
char *resp_str;
GSList *tokens = NULL;
dbg("Entered");
/* +XDRV: <group_id>,<function_id>,<xdrv_result>[,<response_n>] */
- if (NULL == resp) {
+ if (NULL == at_resp) {
err("Input data is NULL");
return FALSE;
}
- if (resp->success > 0) {
- dbg("RESPONSE OK");
- line = (const char *) (((GSList *) resp->lines)->data);
- tokens = tcore_at_tok_new(line);
-
- /* Group ID */
- resp_str = g_slist_nth_data(tokens, 0);
- if (NULL == resp_str) {
- err("Group ID is missing ");
- goto OUT;
- }
- else if (IUFP_GROUP_ID != atoi(resp_str)) {
- err("Group ID mismatch");
- goto OUT;
- }
+ if (at_resp->success <= 0) {
+ dbg("Response NOK");
+ return FALSE;
+ }
- /* Function ID */
- resp_str = g_slist_nth_data(tokens, 1);
- if (NULL == resp_str) {
- err("Function ID is missing ");
- goto OUT;
- }
- else if (command != atoi(resp_str)) {
- err("Function ID mismatch");
- goto OUT;
- }
+ dbg("RESPONSE OK");
+ line = (const char *) (((GSList *) at_resp->lines)->data);
+ tokens = tcore_at_tok_new(line);
+
+ /* Group ID */
+ resp_str = g_slist_nth_data(tokens, 0);
+ if (NULL == resp_str) {
+ err("Group ID is missing ");
+ goto OUT;
+ } else if (IUFP_GROUP_ID != atoi(resp_str)) {
+ err("Group ID mismatch");
+ goto OUT;
+ }
- /* XDRV Result */
- resp_str = g_slist_nth_data(tokens, 2);
- if (NULL == resp_str) {
- err("XDRV result is missing ");
- goto OUT;
- }
- else if (XDRV_RESULT_OK != atoi(resp_str)) {
- err("XDRV result[%d] ", atoi(resp_str));
- goto OUT;
- }
+ /* Function ID */
+ resp_str = g_slist_nth_data(tokens, 1);
+ if (NULL == resp_str) {
+ err("Function ID is missing ");
+ goto OUT;
+ } else if (command != atoi(resp_str)) {
+ err("Function ID mismatch");
+ goto OUT;
+ }
- /* Result code */
- resp_str = g_slist_nth_data(tokens, 3);
- if (NULL == resp_str) {
- err("UTA result is missing ");
- goto OUT;
- }
- else if (UTA_SUCCESS != atoi(resp_str)) {
- err("uta result[%d] ", atoi(resp_str));
- goto OUT;
- }
+ /* XDRV Result */
+ resp_str = g_slist_nth_data(tokens, 2);
+ if (NULL == resp_str) {
+ err("XDRV result is missing ");
+ goto OUT;
+ } else if (XDRV_RESULT_OK != atoi(resp_str)) {
+ err("XDRV result[%d] ", atoi(resp_str));
+ goto OUT;
+ }
- ret = TRUE;
- } else {
- dbg("Response NOK");
+ /* Result code */
+ resp_str = g_slist_nth_data(tokens, 3);
+ if (NULL == resp_str) {
+ err("UTA result is missing ");
+ goto OUT;
+ } else if (UTA_SUCCESS != atoi(resp_str)) {
+ err("uta result[%d] ", atoi(resp_str));
+ goto OUT;
}
+ ret = TRUE;
+
OUT:
tcore_at_tok_free(tokens);
return ret;
}
-static void _on_response_modem_unsuspend_nvm_updates(TcorePending *p,
- int data_len, const void *data, void *user_data)
+static void on_response_modem_unsuspend_nvm_updates(TcorePending *pending,
+ int data_len, const void *data, void *user_data)
{
/* Check NVM response */
if (TRUE == __modem_check_nvm_response(data, IUFP_SUSPEND)) {
dbg("Priority level is set to get all updates since Boot-up");
/* Create NV data file */
- if (nvm_create_nvm_data() == FALSE) {
+ if (nvm_create_nvm_data() == FALSE)
err("Failed to Create NV data file");
- }
return;
}
err("Response NOT OK");
}
-static void _on_response_modem_send_nvm_update_ack(TcorePending *p,
- int data_len, const void *data, void *user_data)
+static void on_response_modem_send_nvm_update_ack(TcorePending *pending,
+ int data_len, const void *data, void *user_data)
{
/* Check NVM response */
if (TRUE == __modem_check_nvm_response(data, IUFP_UPDATE_ACK)) {
err("[UPDATE ACK] NOT OK");
}
-static void _on_response_modem_send_nvm_update_request_ack(TcorePending *p,
- int data_len, const void *data, void *user_data)
+static void on_response_modem_send_nvm_update_request_ack(TcorePending *pending,
+ int data_len, const void *data, void *user_data)
{
/* Check NVM response */
if (TRUE == __modem_check_nvm_response(data, IUFP_UPDATE_REQ_ACK)) {
err("[REQUEST ACK] NOT OK");
}
-static void _on_response_modem_register_nvm(TcorePending *p,
- int data_len, const void *data, void *user_data)
+static void on_response_modem_register_nvm(TcorePending *pending,
+ int data_len, const void *data, void *user_data)
{
/* Check NVM response */
if (TRUE == __modem_check_nvm_response(data, IUFP_REGISTER)) {
- dbg("Registering successful");
+ dbg("Registering successful!");
/* Send SUSPEND_UPDATE for all UPDATES */
- modem_unsuspend_nvm_updates(tcore_pending_ref_core_object(p));
+ modem_unsuspend_nvm_updates(tcore_pending_ref_core_object(pending));
dbg("Exit");
return;
}
/* NVM Requests */
-static void modem_unsuspend_nvm_updates(CoreObject *o)
+static void modem_unsuspend_nvm_updates(CoreObject *co_modem)
{
- TcorePending *pending = NULL;
char *cmd_str;
+ TReturn ret;
+
dbg("Entered");
/* Prepare AT-Command */
cmd_str = g_strdup_printf("AT+XDRV=%d, %d, %d, %d",
- IUFP_GROUP_ID, IUFP_SUSPEND,
- 0, UTA_FLASH_PLUGIN_PRIO_UNSUSPEND_ALL);
+ IUFP_GROUP_ID, IUFP_SUSPEND,
+ 0, UTA_FLASH_PLUGIN_PRIO_UNSUSPEND_ALL);
/* Prepare pending request */
- pending = tcore_at_pending_new(o,
- cmd_str,
- "+XDRV:",
- TCORE_AT_SINGLELINE,
- _on_response_modem_unsuspend_nvm_updates,
- NULL);
- if (pending == NULL) {
- err("Failed to form pending request");
- }
- else if (tcore_hal_send_request(tcore_object_get_hal(o), pending)
- != TCORE_RETURN_SUCCESS) {
+ ret = tcore_prepare_and_send_at_request(co_modem,
+ cmd_str, "+XDRV:",
+ TCORE_AT_SINGLELINE, NULL,
+ on_response_modem_unsuspend_nvm_updates, NULL,
+ NULL, NULL, 0, NULL, NULL);
+ if (ret != TCORE_RETURN_SUCCESS)
err("IUFP_SUSPEND - Unable to send AT-Command");
- }
- else {
+ else
dbg("IUFP_SUSPEND - Successfully sent AT-Command");
- }
g_free(cmd_str);
}
-static void modem_send_nvm_update_ack(CoreObject *o)
+static void modem_send_nvm_update_ack(CoreObject *co_modem)
{
- TcorePending *pending = NULL;
char *cmd_str;
+ TReturn ret;
+
dbg("Entered");
/* Prepare AT-Command */
cmd_str = g_strdup_printf("AT+XDRV=%s, %s", IUFP_GROUP, IUFP_UPDATE_ACK_STR);
/* Prepare pending request */
- pending = tcore_at_pending_new(o,
- cmd_str,
- "+XDRV:",
- TCORE_AT_SINGLELINE,
- _on_response_modem_send_nvm_update_ack,
- NULL);
- if (pending == NULL) {
- err("Failed to form pending request");
- }
- else if (tcore_hal_send_request(tcore_object_get_hal(o), pending)
- != TCORE_RETURN_SUCCESS) {
+ ret = tcore_prepare_and_send_at_request(co_modem,
+ cmd_str, "+XDRV:",
+ TCORE_AT_SINGLELINE, NULL,
+ on_response_modem_send_nvm_update_ack, NULL,
+ NULL, NULL, 0, NULL, NULL);
+ if (ret != TCORE_RETURN_SUCCESS)
err("IUFP_UPDATE_ACK - Unable to send AT-Command");
- }
- else {
+ else
dbg("IUFP_UPDATE_ACK - Successfully sent AT-Command");
- }
g_free(cmd_str);
}
-static void modem_send_nvm_update_request_ack(CoreObject *o)
+static void modem_send_nvm_update_request_ack(CoreObject *co_modem)
{
- TcorePending *pending = NULL;
char *cmd_str;
+ TReturn ret;
+
dbg("Entered");
/* Prepare AT-Command */
cmd_str = g_strdup_printf("AT+XDRV=%s, %s", IUFP_GROUP, IUFP_UPDATE_REQ_ACK_STR);
/* Prepare pending request */
- pending = tcore_at_pending_new(o,
- cmd_str,
- "+XDRV:",
- TCORE_AT_SINGLELINE,
- _on_response_modem_send_nvm_update_request_ack,
- NULL);
-
-
- if (pending == NULL) {
- err("Failed to form pending request");
- }
- else if (tcore_hal_send_request(tcore_object_get_hal(o), pending)
- != TCORE_RETURN_SUCCESS) {
+ ret = tcore_prepare_and_send_at_request(co_modem,
+ cmd_str, "+XDRV:",
+ TCORE_AT_SINGLELINE, NULL,
+ on_response_modem_send_nvm_update_request_ack, NULL,
+ NULL, NULL, 0, NULL, NULL);
+ if (ret != TCORE_RETURN_SUCCESS)
err("IUFP_UPDATE_REQ_ACK - Unable to send AT-Ccommand");
- }
- else {
+ else
dbg("IUFP_UPDATE_REQ_ACK - Successfully sent AT-Command");
- }
g_free(cmd_str);
}
void modem_register_nvm(CoreObject *co_modem)
{
- TcorePending *pending = NULL;
char *cmd_str;
+ TReturn ret;
+
dbg("Entered");
/* Prepare AT-Command */
cmd_str = g_strdup_printf("AT+XDRV=%s, %s, %s",
- IUFP_GROUP, IUFP_REGISTER_STR, XDRV_ENABLE);
+ IUFP_GROUP, IUFP_REGISTER_STR, XDRV_ENABLE);
/* Prepare pending request */
- pending = tcore_at_pending_new(co_modem,
- cmd_str,
- "+XDRV:",
- TCORE_AT_SINGLELINE,
- _on_response_modem_register_nvm,
- NULL);
- if (pending == NULL) {
- err("Failed to form pending request");
- }
- else if (tcore_hal_send_request(tcore_object_get_hal(co_modem), pending)
- != TCORE_RETURN_SUCCESS) {
+ ret = tcore_prepare_and_send_at_request(co_modem,
+ cmd_str, "+XDRV:",
+ TCORE_AT_SINGLELINE, NULL,
+ on_response_modem_register_nvm, NULL,
+ NULL, NULL, 0, NULL, NULL);
+ if (ret != TCORE_RETURN_SUCCESS) {
err("IUFP_REGISTER (Enable) -Unable to send AT-Command");
- }
- else {
+ } else {
dbg("IUFP_REGISTER (Enable) -Successfully sent AT-Command");
/* Add RFS hook */
/* Todo unblock this api */
- tcore_at_add_hook(tcore_object_get_hal(co_modem), modem_rfs_hook);
+ tcore_at_add_hook(tcore_object_get_hal(co_modem),
+ __modem_rfs_hook);
}
g_free(cmd_str);