aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2012-08-08 16:20:32 -0500
committerDan Williams <dcbw@redhat.com>2012-08-08 16:21:23 -0500
commitcaaa9a8813720cc39b3c11753685368eb9856da6 (patch)
treec3dd258393bd3eb487315898b7c669824f727ad3
parent2810e9991d1270e00e1de26760a2e9a6305bfb0e (diff)
qcdm: interpret MCC value from StatusSnapshot command
-rw-r--r--libqcdm/src/commands.c36
-rw-r--r--libqcdm/src/commands.h4
-rw-r--r--libqcdm/tests/test-qcdm-com.c5
3 files changed, 45 insertions, 0 deletions
diff --git a/libqcdm/src/commands.c b/libqcdm/src/commands.c
index 0b10154a..a33269ca 100644
--- a/libqcdm/src/commands.c
+++ b/libqcdm/src/commands.c
@@ -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));
diff --git a/libqcdm/src/commands.h b/libqcdm/src/commands.h
index bb948e89..063152c6 100644
--- a/libqcdm/src/commands.h
+++ b/libqcdm/src/commands.h
@@ -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"
diff --git a/libqcdm/tests/test-qcdm-com.c b/libqcdm/tests/test-qcdm-com.c
index c9ce1003..bc299236 100644
--- a/libqcdm/tests/test-qcdm-com.c
+++ b/libqcdm/tests/test-qcdm-com.c
@@ -929,6 +929,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);
@@ -951,6 +952,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));