wmc: protocol and testcase update

This commit is contained in:
Dan Williams
2011-11-11 23:39:20 -06:00
parent ae3f1cd578
commit 1aa6d01d53
6 changed files with 262 additions and 4 deletions
+96 -2
View File
@@ -131,12 +131,16 @@ wmc_cmd_device_info_result (const char *buf, gsize buflen)
{
WmcResult *r = NULL;
WmcCmdDeviceInfoRsp *rsp = (WmcCmdDeviceInfoRsp *) buf;
WmcCmdDeviceInfo2Rsp *rsp2 = (WmcCmdDeviceInfo2Rsp *) buf;
char tmp[65];
g_return_val_if_fail (buf != NULL, NULL);
if (check_command (buf, buflen, WMC_CMD_DEVICE_INFO, sizeof (WmcCmdDeviceInfoRsp)) < 0)
return NULL;
if (check_command (buf, buflen, WMC_CMD_DEVICE_INFO, sizeof (WmcCmdDeviceInfo2Rsp)) < 0) {
rsp2 = NULL;
if (check_command (buf, buflen, WMC_CMD_DEVICE_INFO, sizeof (WmcCmdDeviceInfoRsp)) < 0)
return NULL;
}
r = wmc_result_new ();
@@ -164,6 +168,96 @@ wmc_cmd_device_info_result (const char *buf, gsize buflen)
memcpy (tmp, rsp->hwrev, sizeof (rsp->hwrev));
wmc_result_add_string (r, WMC_CMD_DEVICE_INFO_ITEM_HW_REVISION, tmp);
if (rsp2) {
/* IMEI */
memset (tmp, 0, sizeof (tmp));
g_assert (sizeof (rsp2->imei) <= sizeof (tmp));
memcpy (tmp, rsp2->imei, sizeof (rsp2->imei));
wmc_result_add_string (r, WMC_CMD_DEVICE_INFO_ITEM_IMEI, tmp);
/* IMSI */
memset (tmp, 0, sizeof (tmp));
g_assert (sizeof (rsp2->imsi) <= sizeof (tmp));
memcpy (tmp, rsp2->imsi, sizeof (rsp2->imsi));
wmc_result_add_string (r, WMC_CMD_DEVICE_INFO_ITEM_IMSI, tmp);
/* MCC */
memset (tmp, 0, sizeof (tmp));
g_assert (sizeof (rsp2->mcc) <= sizeof (tmp));
memcpy (tmp, rsp2->mcc, sizeof (rsp2->mcc));
wmc_result_add_string (r, WMC_CMD_DEVICE_INFO_ITEM_MCC, tmp);
/* MNC */
memset (tmp, 0, sizeof (tmp));
g_assert (sizeof (rsp2->mnc) <= sizeof (tmp));
memcpy (tmp, rsp2->mnc, sizeof (rsp2->mnc));
wmc_result_add_string (r, WMC_CMD_DEVICE_INFO_ITEM_MNC, tmp);
}
return r;
}
/**********************************************************************/
size_t
wmc_cmd_status_new (char *buf, size_t buflen)
{
WmcCmdHeader *cmd = (WmcCmdHeader *) buf;
wmc_return_val_if_fail (buf != NULL, 0);
wmc_return_val_if_fail (buflen >= sizeof (*cmd), 0);
memset (cmd, 0, sizeof (*cmd));
cmd->marker = WMC_CMD_MARKER;
cmd->cmd = WMC_CMD_STATUS;
return sizeof (*cmd);
}
static u_int8_t
sanitize_dbm (u_int8_t in_dbm)
{
/* 0x7D (-125 dBm) really means no signal */
return in_dbm >= 0x7D ? 0 : in_dbm;
}
WmcResult *
wmc_cmd_status_result (const char *buf, gsize buflen)
{
WmcResult *r = NULL;
WmcCmdStatusRsp *rsp = (WmcCmdStatusRsp *) buf;
WmcCmdStatus2Rsp *rsp2 = (WmcCmdStatus2Rsp *) buf;
char tmp[65];
g_return_val_if_fail (buf != NULL, NULL);
if (check_command (buf, buflen, WMC_CMD_STATUS, sizeof (WmcCmdStatus2Rsp)) < 0) {
rsp2 = NULL;
if (check_command (buf, buflen, WMC_CMD_STATUS, sizeof (WmcCmdStatusRsp)) < 0)
return NULL;
}
r = wmc_result_new ();
wmc_result_add_u8 (r, WMC_CMD_STATUS_ITEM_CDMA_DBM, sanitize_dbm (rsp->cdma1x_dbm));
if (rsp2) {
wmc_result_add_u8 (r, WMC_CMD_STATUS_ITEM_HDR_DBM, sanitize_dbm (rsp2->hdr_dbm));
wmc_result_add_u8 (r, WMC_CMD_STATUS_ITEM_LTE_DBM, sanitize_dbm (rsp2->lte_dbm));
memset (tmp, 0, sizeof (tmp));
if (sanitize_dbm (rsp2->lte_dbm)) {
/* LTE operator name */
g_assert (sizeof (rsp2->lte_opname) <= sizeof (tmp));
memcpy (tmp, rsp2->lte_opname, sizeof (rsp2->lte_opname));
wmc_result_add_string (r, WMC_CMD_STATUS_ITEM_OPNAME, tmp);
} else if (sanitize_dbm (rsp2->hdr_dbm) || sanitize_dbm (rsp2->cdma1x_dbm)) {
/* CDMA2000 operator name */
g_assert (sizeof (rsp2->cdma_opname) <= sizeof (tmp));
memcpy (tmp, rsp2->cdma_opname, sizeof (rsp2->cdma_opname));
wmc_result_add_string (r, WMC_CMD_STATUS_ITEM_OPNAME, tmp);
}
}
return r;
}
+15
View File
@@ -36,6 +36,10 @@ WmcResult * wmc_cmd_init_result (const char *buf, size_t len, int wmc2);
#define WMC_CMD_DEVICE_INFO_ITEM_MODEL "model"
#define WMC_CMD_DEVICE_INFO_ITEM_FW_REVISION "firmware-revision"
#define WMC_CMD_DEVICE_INFO_ITEM_HW_REVISION "hardware-revision"
#define WMC_CMD_DEVICE_INFO_ITEM_IMEI "imei"
#define WMC_CMD_DEVICE_INFO_ITEM_IMSI "imsi"
#define WMC_CMD_DEVICE_INFO_ITEM_MCC "mcc"
#define WMC_CMD_DEVICE_INFO_ITEM_MNC "mnc"
size_t wmc_cmd_device_info_new (char *buf, size_t buflen);
@@ -43,4 +47,15 @@ WmcResult * wmc_cmd_device_info_result (const char *buf, size_t len);
/**********************************************************************/
#define WMC_CMD_STATUS_ITEM_CDMA_DBM "cdma-dbm"
#define WMC_CMD_STATUS_ITEM_HDR_DBM "hdr-dbm"
#define WMC_CMD_STATUS_ITEM_LTE_DBM "lte-dbm"
#define WMC_CMD_STATUS_ITEM_OPNAME "opname"
size_t wmc_cmd_status_new (char *buf, size_t buflen);
WmcResult * wmc_cmd_status_result (const char *buf, size_t len);
/**********************************************************************/
#endif /* LIBWMC_COMMANDS_H */
+84 -1
View File
@@ -49,7 +49,6 @@ struct WmcCmdInit2Rsp {
} __attribute__ ((packed));
typedef struct WmcCmdInit2Rsp WmcCmdInit2Rsp;
struct WmcCmdDeviceInfoRsp {
WmcCmdHeader hdr;
u_int8_t _unknown1[27];
@@ -65,5 +64,89 @@ struct WmcCmdDeviceInfoRsp {
} __attribute__ ((packed));
typedef struct WmcCmdDeviceInfoRsp WmcCmdDeviceInfoRsp;
struct WmcCmdDeviceInfo2Rsp {
WmcCmdHeader hdr;
u_int8_t _unknown1[27];
char manf[64];
char model[64];
char fwrev[64];
char hwrev[64];
u_int8_t _unknown2[64];
u_int8_t _unknown3[64];
u_int8_t _unknown4[22];
u_int8_t _unknown5[8];
u_int8_t _unknown6[6];
u_int8_t _unknown7[64];
u_int8_t _unknown8[20];
u_int8_t imei[22];
u_int8_t _unknown9[16];
u_int8_t imsi[22];
u_int8_t _unknown10[4];
u_int8_t mcc[16];
u_int8_t mnc[16];
u_int8_t _unknown11[4];
u_int8_t _unknown12[4];
u_int8_t _unknown13[4];
} __attribute__ ((packed));
typedef struct WmcCmdDeviceInfo2Rsp WmcCmdDeviceInfo2Rsp;
/* Shorter response used by earlier devices like PC5740 */
struct WmcCmdStatusRsp {
WmcCmdHeader hdr;
u_int8_t _unknown1;
u_int8_t _unknown2[3]; /* Always zero */
u_int8_t _unknown3; /* Always 0x06 */
u_int8_t _unknown4; /* Either 0x00 or 0x01 */
u_int8_t magic[10];
u_int16_t counter1; /* A timestamp/counter? */
u_int8_t _unknown5;
u_int8_t _unknown6;
u_int8_t _unknown7[3]; /* Always 0xFE 0xFF 0xFF */
u_int8_t cdma1x_dbm;
u_int8_t _unknown8[37]; /* Always zero */
} __attribute__ ((packed));
typedef struct WmcCmdStatusRsp WmcCmdStatusRsp;
/* Long-format response used on newer devices like the UML290 */
struct WmcCmdStatus2Rsp {
WmcCmdHeader hdr;
u_int8_t _unknown1; /* 0x00 on LTE, 0x07 or 0x1F on CDMA */
u_int8_t _unknown2[3]; /* Always zero */
u_int8_t _unknown3; /* 0x0E on LTE, 0x0F on CDMA */
u_int8_t _unknown4;
u_int8_t magic[10]; /* Whatever was passed in WMC_CMD_INIT with some changes */
u_int16_t counter1; /* A timestamp/counter? */
u_int16_t counter2; /* Time since firmware start? */
u_int8_t _unknown5; /* 0x00 on LTE, various values (0xD4, 0x5C) on CDMA */
u_int8_t _unknown6[3]; /* always zero on LTE, 0xFE 0xFF 0xFF on CDMA */
u_int8_t cdma1x_dbm; /* 0x7D = no signal */
u_int8_t _unknown7[3]; /* Always zero */
u_int8_t cdma_opname[16]; /* Zero terminated? */
u_int8_t _unknown8[18]; /* Always zero */
u_int8_t hdr_dbm; /* 0x7D = no signal */
u_int8_t _unknown9[3]; /* Always zero */
u_int8_t _unknown10; /* 0x01 on LTE, 0x40 on CDMA */
u_int8_t _unknown11[3]; /* Always zero */
u_int8_t _unknown12; /* Always 0x01 */
u_int8_t lte_opname[8]; /* Zero terminated? Sometimes "MCC MNC" too */
u_int8_t _unknown13[60]; /* Always zero */
u_int8_t lte_dbm; /* 0x00 if not in LTE mode */
u_int8_t _unknown14[3]; /* Always zero */
u_int8_t _unknown15[4];
} __attribute__ ((packed));
typedef struct WmcCmdStatus2Rsp WmcCmdStatus2Rsp;
struct WmcCmdIpInfoRsp {
WmcCmdHeader hdr;
u_int32_t xfer_bytes;
u_int32_t xfer_bytes2; /* Same value as xfer_bytes */
u_int8_t _unknown3[8];
u_int8_t _unknown4; /* Either 0x01, 0x02, 0x03, or 0x04 */
u_int8_t _unknown5[7]; /* Always 0xc0 0x0b 0x00 0x01 0x00 0x00 0x00 */
u_int8_t ip4_address[16]; /* String format, ie "10.156.45.3" */
u_int8_t _unknown6[8]; /* Netmask? */
u_int8_t ip6_address[40]; /* String format */
} __attribute__ ((packed));
typedef struct WmcCmdIpInfoRsp WmcCmdIpInfoRsp;
#endif /* LIBWMC_PROTOCOL_H */