qcdm: interpret MCC value from StatusSnapshot command

This commit is contained in:
Dan Williams
2012-08-08 16:23:02 -05:00
parent 36594dd9fb
commit 1e286f80ea
3 changed files with 45 additions and 0 deletions
+36
View File
@@ -507,11 +507,26 @@ snapshot_state_to_qcdm (u_int8_t cdma_state)
return cdma_state + 1;
}
static inline u_int8_t
digit_fixup (u_int8_t d)
{
/* CDMA MCC/IMSI conversion adds 1 to each digit, and digits equal to
* 10 are really zero.
*/
if (d + 1 < 10)
return d + 1;
return 0;
}
QcdmResult *
qcdm_cmd_status_snapshot_result (const char *buf, size_t len, int *out_error)
{
QcdmResult *result = NULL;
DMCmdStatusSnapshotRsp *rsp = (DMCmdStatusSnapshotRsp *) buf;
char *tmp;
u_int8_t swapped[4];
u_int8_t tmcc[3];
u_int16_t mcc, hmcc;
qcdm_return_val_if_fail (buf != NULL, NULL);
@@ -520,6 +535,27 @@ qcdm_cmd_status_snapshot_result (const char *buf, size_t len, int *out_error)
result = qcdm_result_new ();
/* Convert the ESN from binary to a hex string; it's LE so we have to
* swap it to get the correct ordering.
*/
swapped[0] = rsp->esn[3];
swapped[1] = rsp->esn[2];
swapped[2] = rsp->esn[1];
swapped[3] = rsp->esn[0];
tmp = bin2hexstr (&swapped[0], sizeof (swapped));
qcdm_result_add_string (result, QCDM_CMD_STATUS_SNAPSHOT_ITEM_ESN, tmp);
free (tmp);
/* Cheap binary -> decimal conversion */
hmcc = le16toh (rsp->mcc);
tmcc[2] = hmcc / 100;
tmcc[1] = (hmcc - (tmcc[2] * 100)) / 10;
tmcc[0] = (hmcc - (tmcc[2] * 100) - (tmcc[1] * 10));
mcc = (100 * digit_fixup (tmcc[2])) + (10 * digit_fixup (tmcc[1])) + digit_fixup (tmcc[0]);
qcdm_result_add_u32 (result, QCDM_CMD_STATUS_SNAPSHOT_ITEM_HOME_MCC, mcc);
qcdm_result_add_u8 (result, QCDM_CMD_STATUS_SNAPSHOT_ITEM_BAND_CLASS, cdma_band_class_to_qcdm (rsp->band_class));
qcdm_result_add_u8 (result, QCDM_CMD_STATUS_SNAPSHOT_ITEM_BASE_STATION_PREV, cdma_prev_to_qcdm (rsp->prev));
qcdm_result_add_u8 (result, QCDM_CMD_STATUS_SNAPSHOT_ITEM_MOBILE_PREV, cdma_prev_to_qcdm (rsp->mob_prev));
+4
View File
@@ -146,6 +146,10 @@ QcdmResult *qcdm_cmd_sw_version_result (const char *buf,
/**********************************************************************/
#define QCDM_CMD_STATUS_SNAPSHOT_ITEM_ESN "esn"
#define QCDM_CMD_STATUS_SNAPSHOT_ITEM_HOME_MCC "mcc"
/* One of QCDM_CDMA_BAND_CLASS_* */
#define QCDM_CMD_STATUS_SNAPSHOT_ITEM_BAND_CLASS "band-class"
+5
View File
@@ -887,6 +887,7 @@ test_com_status_snapshot (void *f, void *data)
QcdmResult *result;
gsize reply_len;
guint8 n8;
guint32 n32;
len = qcdm_cmd_status_snapshot_new (buf, sizeof (buf));
g_assert (len == 4);
@@ -909,6 +910,10 @@ test_com_status_snapshot (void *f, void *data)
g_print ("\n");
n32 = 0;
qcdm_result_get_u32 (result, QCDM_CMD_STATUS_SNAPSHOT_ITEM_HOME_MCC, &n32);
g_message ("%s: Home MCC: %d", __func__, n32);
n8 = 0;
qcdm_result_get_u8 (result, QCDM_CMD_STATUS_SNAPSHOT_ITEM_BAND_CLASS, &n8);
g_message ("%s: Band Class: %s", __func__, band_class_to_string (n8));