diff options
author | Dan Williams <dcbw@redhat.com> | 2012-08-08 16:20:32 -0500 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2012-08-08 16:23:02 -0500 |
commit | 1e286f80eae1d4cbdb7e92c52d68529f0662fa22 (patch) | |
tree | cdfa715b262d41a0cdaa48e90b23a50f102b69b3 /libqcdm | |
parent | 36594dd9fbe3d1a9848343b529ae404121aa2423 (diff) | |
download | ModemManager-1e286f80eae1d4cbdb7e92c52d68529f0662fa22.tar.gz |
qcdm: interpret MCC value from StatusSnapshot command
Diffstat (limited to 'libqcdm')
-rw-r--r-- | libqcdm/src/commands.c | 36 | ||||
-rw-r--r-- | libqcdm/src/commands.h | 4 | ||||
-rw-r--r-- | libqcdm/tests/test-qcdm-com.c | 5 |
3 files changed, 45 insertions, 0 deletions
diff --git a/libqcdm/src/commands.c b/libqcdm/src/commands.c index f906f1a8d..53d831e50 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 6d301f5e8..466645b46 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 d359df56e..df3633a2c 100644 --- a/libqcdm/tests/test-qcdm-com.c +++ b/libqcdm/tests/test-qcdm-com.c @@ -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)); |