qcdm: add initial roaming and mode preference bits
This commit is contained in:
@@ -107,6 +107,19 @@ check_command (const char *buf, gsize len, guint8 cmd, gsize min_len, GError **e
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* NV read/write have a status byte at the end too */
|
||||
if (cmd == DIAG_CMD_NV_READ || cmd == DIAG_CMD_NV_WRITE) {
|
||||
DMCmdNVReadWrite *nvcmd = (DMCmdNVReadWrite *) buf;
|
||||
|
||||
g_warn_if_fail (len >= sizeof (DMCmdNVReadWrite));
|
||||
if (nvcmd->status != 0) {
|
||||
g_set_error (error, QCDM_COMMAND_ERROR, QCDM_COMMAND_NVCMD_FAILED,
|
||||
"The NV operation failed (status 0x%X).",
|
||||
GUINT16_FROM_LE (nvcmd->status));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -384,6 +397,108 @@ qcdm_cmd_nv_get_mdn_result (const char *buf, gsize len, GError **error)
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
static gboolean
|
||||
roam_pref_validate (guint8 dm)
|
||||
{
|
||||
if ( dm == DIAG_NV_ROAM_PREF_HOME_ONLY
|
||||
|| dm == DIAG_NV_ROAM_PREF_ROAM_ONLY
|
||||
|| dm == DIAG_NV_ROAM_PREF_AUTO)
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gsize
|
||||
qcdm_cmd_nv_get_roam_pref_new (char *buf, gsize len, guint8 profile, GError **error)
|
||||
{
|
||||
char cmdbuf[sizeof (DMCmdNVReadWrite) + 2];
|
||||
DMCmdNVReadWrite *cmd = (DMCmdNVReadWrite *) &cmdbuf[0];
|
||||
DMNVItemRoamPref *req;
|
||||
|
||||
g_return_val_if_fail (buf != NULL, 0);
|
||||
g_return_val_if_fail (len >= sizeof (*cmd) + DIAG_TRAILER_LEN, 0);
|
||||
|
||||
memset (cmd, 0, sizeof (*cmd));
|
||||
cmd->code = DIAG_CMD_NV_READ;
|
||||
cmd->nv_item = GUINT16_TO_LE (DIAG_NV_ROAM_PREF);
|
||||
|
||||
req = (DMNVItemRoamPref *) &cmd->data[0];
|
||||
req->profile = profile;
|
||||
|
||||
return dm_encapsulate_buffer (cmdbuf, sizeof (*cmd), sizeof (cmdbuf), buf, len);
|
||||
}
|
||||
|
||||
QCDMResult *
|
||||
qcdm_cmd_nv_get_roam_pref_result (const char *buf, gsize len, GError **error)
|
||||
{
|
||||
QCDMResult *result = NULL;
|
||||
DMCmdNVReadWrite *rsp = (DMCmdNVReadWrite *) buf;
|
||||
DMNVItemRoamPref *roam;
|
||||
|
||||
g_return_val_if_fail (buf != NULL, NULL);
|
||||
|
||||
if (!check_command (buf, len, DIAG_CMD_NV_READ, sizeof (DMCmdNVReadWrite), error))
|
||||
return NULL;
|
||||
|
||||
roam = (DMNVItemRoamPref *) &rsp->data[0];
|
||||
|
||||
if (!roam_pref_validate (roam->roam_pref)) {
|
||||
g_set_error (error, QCDM_COMMAND_ERROR, QCDM_COMMAND_BAD_PARAMETER,
|
||||
"Unknown roam preference 0x%X",
|
||||
roam->roam_pref);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
result = qcdm_result_new ();
|
||||
qcdm_result_add_uint8 (result, QCDM_CMD_NV_GET_ROAM_PREF_ITEM_PROFILE, roam->profile);
|
||||
qcdm_result_add_uint8 (result, QCDM_CMD_NV_GET_ROAM_PREF_ITEM_ROAM_PREF, roam->roam_pref);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
gsize
|
||||
qcdm_cmd_nv_set_roam_pref_new (char *buf,
|
||||
gsize len,
|
||||
guint8 profile,
|
||||
guint8 roam_pref,
|
||||
GError **error)
|
||||
{
|
||||
char cmdbuf[sizeof (DMCmdNVReadWrite) + 2];
|
||||
DMCmdNVReadWrite *cmd = (DMCmdNVReadWrite *) &cmdbuf[0];
|
||||
DMNVItemRoamPref *req;
|
||||
|
||||
g_return_val_if_fail (buf != NULL, 0);
|
||||
g_return_val_if_fail (len >= sizeof (*cmd) + DIAG_TRAILER_LEN, 0);
|
||||
|
||||
if (!roam_pref_validate (roam_pref)) {
|
||||
g_set_error (error, QCDM_COMMAND_ERROR, QCDM_COMMAND_BAD_PARAMETER,
|
||||
"Invalid roam preference %d", roam_pref);
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset (cmd, 0, sizeof (*cmd));
|
||||
cmd->code = DIAG_CMD_NV_WRITE;
|
||||
cmd->nv_item = GUINT16_TO_LE (DIAG_NV_ROAM_PREF);
|
||||
|
||||
req = (DMNVItemRoamPref *) &cmd->data[0];
|
||||
req->profile = profile;
|
||||
req->roam_pref = roam_pref;
|
||||
|
||||
return dm_encapsulate_buffer (cmdbuf, sizeof (*cmd), sizeof (cmdbuf), buf, len);
|
||||
}
|
||||
|
||||
QCDMResult *
|
||||
qcdm_cmd_nv_set_roam_pref_result (const char *buf, gsize len, GError **error)
|
||||
{
|
||||
g_return_val_if_fail (buf != NULL, NULL);
|
||||
|
||||
if (!check_command (buf, len, DIAG_CMD_NV_WRITE, sizeof (DMCmdNVReadWrite), error))
|
||||
return NULL;
|
||||
|
||||
return qcdm_result_new ();
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
gsize
|
||||
qcdm_cmd_cm_subsys_state_info_new (char *buf, gsize len, GError **error)
|
||||
{
|
||||
@@ -407,12 +522,21 @@ qcdm_cmd_cm_subsys_state_info_result (const char *buf, gsize len, GError **error
|
||||
QCDMResult *result = NULL;
|
||||
DMCmdSubsysCMStateInfoRsp *rsp = (DMCmdSubsysCMStateInfoRsp *) buf;
|
||||
guint32 tmp_num;
|
||||
guint32 roam_pref;
|
||||
|
||||
g_return_val_if_fail (buf != NULL, NULL);
|
||||
|
||||
if (!check_command (buf, len, DIAG_CMD_SUBSYS, sizeof (DMCmdSubsysCMStateInfoRsp), error))
|
||||
return NULL;
|
||||
|
||||
roam_pref = (guint32) GUINT32_FROM_LE (rsp->roam_pref);
|
||||
if (!roam_pref_validate (roam_pref)) {
|
||||
g_set_error (error, QCDM_COMMAND_ERROR, QCDM_COMMAND_BAD_PARAMETER,
|
||||
"Unknown roam preference 0x%X",
|
||||
roam_pref);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
result = qcdm_result_new ();
|
||||
|
||||
tmp_num = (guint32) GUINT32_FROM_LE (rsp->call_state);
|
||||
@@ -430,8 +554,7 @@ qcdm_cmd_cm_subsys_state_info_result (const char *buf, gsize len, GError **error
|
||||
tmp_num = (guint32) GUINT32_FROM_LE (rsp->band_pref);
|
||||
qcdm_result_add_uint32 (result, QCDM_CMD_CM_SUBSYS_STATE_INFO_ITEM_BAND_PREF, tmp_num);
|
||||
|
||||
tmp_num = (guint32) GUINT32_FROM_LE (rsp->roam_pref);
|
||||
qcdm_result_add_uint32 (result, QCDM_CMD_CM_SUBSYS_STATE_INFO_ITEM_ROAM_PREF, tmp_num);
|
||||
qcdm_result_add_uint32 (result, QCDM_CMD_CM_SUBSYS_STATE_INFO_ITEM_ROAM_PREF, roam_pref);
|
||||
|
||||
tmp_num = (guint32) GUINT32_FROM_LE (rsp->srv_domain_pref);
|
||||
qcdm_result_add_uint32 (result, QCDM_CMD_CM_SUBSYS_STATE_INFO_ITEM_SERVICE_DOMAIN_PREF, tmp_num);
|
||||
|
@@ -112,6 +112,37 @@ QCDMResult *qcdm_cmd_nv_get_mdn_result (const char *buf,
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
/* Values for QCDM_CMD_NV_GET_ROAM_PREF_ITEM_ROAM_PREF */
|
||||
enum {
|
||||
QCDM_CMD_NV_ROAM_PREF_ITEM_ROAM_PREF_HOME_ONLY = 0x01,
|
||||
QCDM_CMD_NV_ROAM_PREF_ITEM_ROAM_PREF_ROAM_ONLY = 0x06,
|
||||
QCDM_CMD_NV_ROAM_PREF_ITEM_ROAM_PREF_AUTO = 0xFF,
|
||||
};
|
||||
|
||||
#define QCDM_CMD_NV_GET_ROAM_PREF_ITEM_PROFILE "profile"
|
||||
#define QCDM_CMD_NV_GET_ROAM_PREF_ITEM_ROAM_PREF "roam-pref"
|
||||
|
||||
gsize qcdm_cmd_nv_get_roam_pref_new (char *buf,
|
||||
gsize len,
|
||||
guint8 profile,
|
||||
GError **error);
|
||||
|
||||
QCDMResult *qcdm_cmd_nv_get_roam_pref_result (const char *buf,
|
||||
gsize len,
|
||||
GError **error);
|
||||
|
||||
gsize qcdm_cmd_nv_set_roam_pref_new (char *buf,
|
||||
gsize len,
|
||||
guint8 profile,
|
||||
guint8 roam_pref,
|
||||
GError **error);
|
||||
|
||||
QCDMResult *qcdm_cmd_nv_set_roam_pref_result (const char *buf,
|
||||
gsize len,
|
||||
GError **error);
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
/* Values for QCDM_CMD_CM_SUBSYS_STATE_INFO_ITEM_OPERATING_MODE */
|
||||
enum {
|
||||
QCDM_CMD_CM_SUBSYS_STATE_INFO_OPERATING_MODE_ONLINE = 5
|
||||
@@ -126,6 +157,18 @@ enum {
|
||||
QCDM_CMD_CM_SUBSYS_STATE_INFO_SYSTEM_MODE_WCDMA = 5
|
||||
};
|
||||
|
||||
/* Values for QCDM_CMD_CM_SUBSYS_STATE_INFO_ITEM_ROAM_PREF */
|
||||
enum {
|
||||
QCDM_CMD_CM_SUBSYS_STATE_INFO_ROAM_PREF_HOME_ONLY = 0x01,
|
||||
QCDM_CMD_CM_SUBSYS_STATE_INFO_ROAM_PREF_ROAM_ONLY = 0x06,
|
||||
QCDM_CMD_CM_SUBSYS_STATE_INFO_ROAM_PREF_AUTO = 0xFF,
|
||||
};
|
||||
|
||||
/* Values for QCDM_CMD_CM_SUBSYS_STATE_INFO_ITEM_MODE_PREF */
|
||||
enum {
|
||||
QCDM_CMD_CM_SUBSYS_STATE_INFO_MODE_PREF_AUTO = 0x02,
|
||||
};
|
||||
|
||||
#define QCDM_CMD_CM_SUBSYS_STATE_INFO_ITEM_CALL_STATE "call-state"
|
||||
#define QCDM_CMD_CM_SUBSYS_STATE_INFO_ITEM_OPERATING_MODE "operating-mode"
|
||||
#define QCDM_CMD_CM_SUBSYS_STATE_INFO_ITEM_SYSTEM_MODE "system-mode"
|
||||
|
@@ -74,6 +74,7 @@ qcdm_command_error_get_type (void)
|
||||
ENUM_ENTRY (QCDM_COMMAND_BAD_PARAMETER, "QcdmCommandBadParameter"),
|
||||
ENUM_ENTRY (QCDM_COMMAND_NOT_ACCEPTED, "QcdmCommandNotAccepted"),
|
||||
ENUM_ENTRY (QCDM_COMMAND_BAD_MODE, "QcdmCommandBadMode"),
|
||||
ENUM_ENTRY (QCDM_COMMAND_NVCMD_FAILED, "QcdmCommandNvCmdFailed"),
|
||||
{ 0, 0, 0 }
|
||||
};
|
||||
|
||||
|
@@ -39,7 +39,8 @@ enum {
|
||||
QCDM_COMMAND_BAD_COMMAND = 3,
|
||||
QCDM_COMMAND_BAD_PARAMETER = 4,
|
||||
QCDM_COMMAND_NOT_ACCEPTED = 5,
|
||||
QCDM_COMMAND_BAD_MODE = 6
|
||||
QCDM_COMMAND_BAD_MODE = 6,
|
||||
QCDM_COMMAND_NVCMD_FAILED = 7,
|
||||
};
|
||||
|
||||
#define QCDM_COMMAND_ERROR (qcdm_command_error_quark ())
|
||||
|
@@ -19,10 +19,27 @@
|
||||
#define LIBQCDM_NV_ITEMS_H
|
||||
|
||||
enum {
|
||||
DIAG_NV_MODE_PREF = 10, /* Mode preference: 1x, HDR, auto */
|
||||
DIAG_NV_DIR_NUMBER = 178, /* Mobile Directory Number (MDN) */
|
||||
DIAG_NV_ROAM_PREF = 442, /* Roaming preference */
|
||||
};
|
||||
|
||||
|
||||
/* Mode preference values */
|
||||
enum {
|
||||
DIAG_NV_MODE_PREF_AUTO = 0x04,
|
||||
DIAG_NV_MODE_PREF_1X_ONLY = 0x09,
|
||||
DIAG_NV_MODE_PREF_HDR_ONLY = 0x0A,
|
||||
};
|
||||
|
||||
/* DIAG_NV_MODE_PREF */
|
||||
struct DMNVItemModePref {
|
||||
guint8 profile;
|
||||
guint8 _unknown1;
|
||||
guint8 mode_pref;
|
||||
} __attribute__ ((packed));
|
||||
typedef struct DMNVItemModePref DMNVItemModePref;
|
||||
|
||||
/* DIAG_NV_DIR_NUMBER */
|
||||
struct DMNVItemMdn {
|
||||
guint8 profile;
|
||||
@@ -30,6 +47,19 @@ struct DMNVItemMdn {
|
||||
} __attribute__ ((packed));
|
||||
typedef struct DMNVItemMdn DMNVItemMdn;
|
||||
|
||||
/* Roam preference values */
|
||||
enum {
|
||||
DIAG_NV_ROAM_PREF_HOME_ONLY = 0x01,
|
||||
DIAG_NV_ROAM_PREF_ROAM_ONLY = 0x06,
|
||||
DIAG_NV_ROAM_PREF_AUTO = 0xFF,
|
||||
};
|
||||
|
||||
/* DIAG_NV_ROAM_PREF */
|
||||
struct DMNVItemRoamPref {
|
||||
guint8 profile;
|
||||
guint8 roam_pref;
|
||||
} __attribute__ ((packed));
|
||||
typedef struct DMNVItemRoamPref DMNVItemRoamPref;
|
||||
|
||||
#endif /* LIBQCDM_NV_ITEMS_H */
|
||||
|
||||
|
@@ -336,6 +336,56 @@ test_com_mdn (void *f, void *data)
|
||||
qcdm_result_unref (result);
|
||||
}
|
||||
|
||||
void
|
||||
test_com_read_roam_pref (void *f, void *data)
|
||||
{
|
||||
TestComData *d = data;
|
||||
gboolean success;
|
||||
GError *error = NULL;
|
||||
char buf[512];
|
||||
guint8 pref;
|
||||
const char *msg;
|
||||
gint len;
|
||||
QCDMResult *result;
|
||||
gsize reply_len;
|
||||
|
||||
len = qcdm_cmd_nv_get_roam_pref_new (buf, sizeof (buf), 0, NULL);
|
||||
g_assert (len > 0);
|
||||
|
||||
/* Send the command */
|
||||
success = send_command (d, buf, len);
|
||||
g_assert (success);
|
||||
|
||||
/* Get a response */
|
||||
reply_len = wait_reply (d, buf, sizeof (buf));
|
||||
|
||||
/* Parse the response into a result structure */
|
||||
result = qcdm_cmd_nv_get_roam_pref_result (buf, reply_len, &error);
|
||||
g_assert (result);
|
||||
|
||||
g_print ("\n");
|
||||
|
||||
success = qcdm_result_get_uint8 (result, QCDM_CMD_NV_GET_ROAM_PREF_ITEM_ROAM_PREF, &pref);
|
||||
g_assert (success);
|
||||
|
||||
switch (pref) {
|
||||
case QCDM_CMD_NV_ROAM_PREF_ITEM_ROAM_PREF_HOME_ONLY:
|
||||
msg = "Home only";
|
||||
break;
|
||||
case QCDM_CMD_NV_ROAM_PREF_ITEM_ROAM_PREF_ROAM_ONLY:
|
||||
msg = "Roaming only";
|
||||
break;
|
||||
case QCDM_CMD_NV_ROAM_PREF_ITEM_ROAM_PREF_AUTO:
|
||||
msg = "Automatic";
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
g_message ("%s: Roam preference: %s", __func__, msg);
|
||||
|
||||
qcdm_result_unref (result);
|
||||
}
|
||||
|
||||
void
|
||||
test_com_status (void *f, void *data)
|
||||
{
|
||||
@@ -519,7 +569,14 @@ test_com_cm_subsys_state_info (void *f, void *data)
|
||||
|
||||
n32 = 0;
|
||||
qcdm_result_get_uint32 (result, QCDM_CMD_CM_SUBSYS_STATE_INFO_ITEM_MODE_PREF, &n32);
|
||||
g_message ("%s: Mode Preference: %u", __func__, n32);
|
||||
switch (n32) {
|
||||
case QCDM_CMD_CM_SUBSYS_STATE_INFO_MODE_PREF_AUTO:
|
||||
detail = "Automatic";
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
g_message ("%s: Mode Preference: %s", __func__, detail);
|
||||
|
||||
n32 = 0;
|
||||
qcdm_result_get_uint32 (result, QCDM_CMD_CM_SUBSYS_STATE_INFO_ITEM_BAND_PREF, &n32);
|
||||
@@ -527,7 +584,20 @@ test_com_cm_subsys_state_info (void *f, void *data)
|
||||
|
||||
n32 = 0;
|
||||
qcdm_result_get_uint32 (result, QCDM_CMD_CM_SUBSYS_STATE_INFO_ITEM_ROAM_PREF, &n32);
|
||||
g_message ("%s: Roam Preference: %u", __func__, n32);
|
||||
switch (n32) {
|
||||
case QCDM_CMD_CM_SUBSYS_STATE_INFO_ROAM_PREF_HOME_ONLY:
|
||||
detail = "Home only";
|
||||
break;
|
||||
case QCDM_CMD_CM_SUBSYS_STATE_INFO_ROAM_PREF_ROAM_ONLY:
|
||||
detail = "Roaming only";
|
||||
break;
|
||||
case QCDM_CMD_CM_SUBSYS_STATE_INFO_ROAM_PREF_AUTO:
|
||||
detail = "Automatic";
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
g_message ("%s: Roam Preference: %s", __func__, detail);
|
||||
|
||||
n32 = 0;
|
||||
qcdm_result_get_uint32 (result, QCDM_CMD_CM_SUBSYS_STATE_INFO_ITEM_SERVICE_DOMAIN_PREF, &n32);
|
||||
|
@@ -29,6 +29,8 @@ void test_com_esn (void *f, void *data);
|
||||
|
||||
void test_com_mdn (void *f, void *data);
|
||||
|
||||
void test_com_read_roam_pref (void *f, void *data);
|
||||
|
||||
void test_com_status (void *f, void *data);
|
||||
|
||||
void test_com_sw_version (void *f, void *data);
|
||||
|
@@ -92,6 +92,7 @@ int main (int argc, char **argv)
|
||||
g_test_suite_add (suite, TESTCASE (test_com_version_info, data->com_data));
|
||||
g_test_suite_add (suite, TESTCASE (test_com_esn, data->com_data));
|
||||
g_test_suite_add (suite, TESTCASE (test_com_mdn, data->com_data));
|
||||
g_test_suite_add (suite, TESTCASE (test_com_read_roam_pref, data->com_data));
|
||||
g_test_suite_add (suite, TESTCASE (test_com_status, data->com_data));
|
||||
g_test_suite_add (suite, TESTCASE (test_com_sw_version, data->com_data));
|
||||
g_test_suite_add (suite, TESTCASE (test_com_cm_subsys_state_info, data->com_data));
|
||||
|
Reference in New Issue
Block a user