summaryrefslogtreecommitdiff
authorDan Williams <dcbw@redhat.com>2012-07-25 19:06:17 (GMT)
committer Dan Williams <dcbw@redhat.com>2012-11-14 17:11:03 (GMT)
commitb74741e6420519767bd7551f29dc69f9f31b4c51 (patch) (side-by-side diff)
tree946976354531a06375845650103ffe156f576803
parent773d0022d0d1756ca8a29ad273bea38916a93499 (diff)
downloadModemManager-b74741e6420519767bd7551f29dc69f9f31b4c51.zip
ModemManager-b74741e6420519767bd7551f29dc69f9f31b4c51.tar.gz
qcdm: get/set functions for hybrid preference
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libqcdm/src/commands.c88
-rw-r--r--libqcdm/src/commands.h23
-rw-r--r--libqcdm/src/nv-items.h13
-rw-r--r--libqcdm/tests/test-qcdm-com.c42
-rw-r--r--libqcdm/tests/test-qcdm-com.h2
-rw-r--r--libqcdm/tests/test-qcdm.c1
6 files changed, 169 insertions, 0 deletions
diff --git a/libqcdm/src/commands.c b/libqcdm/src/commands.c
index e5a94b0..e53c473 100644
--- a/libqcdm/src/commands.c
+++ b/libqcdm/src/commands.c
@@ -988,6 +988,94 @@ qcdm_cmd_nv_set_mode_pref_result (const char *buf, size_t len, int *out_error)
/**********************************************************************/
+size_t
+qcdm_cmd_nv_get_hybrid_pref_new (char *buf, size_t len)
+{
+ char cmdbuf[sizeof (DMCmdNVReadWrite) + 2];
+ DMCmdNVReadWrite *cmd = (DMCmdNVReadWrite *) &cmdbuf[0];
+
+ qcdm_return_val_if_fail (buf != NULL, 0);
+ qcdm_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 = htole16 (DIAG_NV_HYBRID_PREF);
+
+ return dm_encapsulate_buffer (cmdbuf, sizeof (*cmd), sizeof (cmdbuf), buf, len);
+}
+
+QcdmResult *
+qcdm_cmd_nv_get_hybrid_pref_result (const char *buf, size_t len, int *out_error)
+{
+ QcdmResult *result = NULL;
+ DMCmdNVReadWrite *rsp = (DMCmdNVReadWrite *) buf;
+ DMNVItemHybridPref *hybrid;
+
+ qcdm_return_val_if_fail (buf != NULL, NULL);
+
+ if (!check_command (buf, len, DIAG_CMD_NV_READ, sizeof (DMCmdNVReadWrite), out_error))
+ return NULL;
+
+ if (!check_nv_cmd (rsp, DIAG_NV_HYBRID_PREF, out_error))
+ return NULL;
+
+ hybrid = (DMNVItemHybridPref *) &rsp->data[0];
+
+ if (hybrid->hybrid_pref > 1)
+ qcdm_warn (0, "Unknown hybrid preference 0x%X", hybrid->hybrid_pref);
+
+ result = qcdm_result_new ();
+ qcdm_result_add_u8 (result, QCDM_CMD_NV_GET_HYBRID_PREF_ITEM_HYBRID_PREF, hybrid->hybrid_pref);
+
+ return result;
+}
+
+size_t
+qcdm_cmd_nv_set_hybrid_pref_new (char *buf,
+ size_t len,
+ u_int8_t hybrid_pref)
+{
+ char cmdbuf[sizeof (DMCmdNVReadWrite) + 2];
+ DMCmdNVReadWrite *cmd = (DMCmdNVReadWrite *) &cmdbuf[0];
+ DMNVItemHybridPref *req;
+
+ qcdm_return_val_if_fail (buf != NULL, 0);
+ qcdm_return_val_if_fail (len >= sizeof (*cmd) + DIAG_TRAILER_LEN, 0);
+
+ if (hybrid_pref > QCDM_CMD_NV_HYBRID_PREF_ITEM_REV_HYBRID_ON) {
+ qcdm_err (0, "Invalid hybrid preference %d", hybrid_pref);
+ return 0;
+ }
+
+ memset (cmd, 0, sizeof (*cmd));
+ cmd->code = DIAG_CMD_NV_WRITE;
+ cmd->nv_item = htole16 (DIAG_NV_HYBRID_PREF);
+
+ req = (DMNVItemHybridPref *) &cmd->data[0];
+ if (hybrid_pref == QCDM_CMD_NV_HYBRID_PREF_ITEM_REV_HYBRID_OFF)
+ req->hybrid_pref = DIAG_NV_HYBRID_PREF_OFF;
+ else if (hybrid_pref == QCDM_CMD_NV_HYBRID_PREF_ITEM_REV_HYBRID_ON)
+ req->hybrid_pref = DIAG_NV_HYBRID_PREF_ON;
+
+ return dm_encapsulate_buffer (cmdbuf, sizeof (*cmd), sizeof (cmdbuf), buf, len);
+}
+
+QcdmResult *
+qcdm_cmd_nv_set_hybrid_pref_result (const char *buf, size_t len, int *out_error)
+{
+ qcdm_return_val_if_fail (buf != NULL, NULL);
+
+ if (!check_command (buf, len, DIAG_CMD_NV_WRITE, sizeof (DMCmdNVReadWrite), out_error))
+ return NULL;
+
+ if (!check_nv_cmd ((DMCmdNVReadWrite *) buf, DIAG_NV_HYBRID_PREF, out_error))
+ return NULL;
+
+ return qcdm_result_new ();
+}
+
+/**********************************************************************/
+
static qcdmbool
hdr_rev_pref_validate (u_int8_t dm)
{
diff --git a/libqcdm/src/commands.h b/libqcdm/src/commands.h
index 20941be..d106ed0 100644
--- a/libqcdm/src/commands.h
+++ b/libqcdm/src/commands.h
@@ -312,6 +312,29 @@ QcdmResult *qcdm_cmd_nv_set_mode_pref_result (const char *buf,
/**********************************************************************/
+enum {
+ QCDM_CMD_NV_HYBRID_PREF_ITEM_REV_HYBRID_OFF = 0x00,
+ QCDM_CMD_NV_HYBRID_PREF_ITEM_REV_HYBRID_ON = 0x01,
+};
+
+#define QCDM_CMD_NV_GET_HYBRID_PREF_ITEM_HYBRID_PREF "hybrid-pref"
+
+size_t qcdm_cmd_nv_get_hybrid_pref_new (char *buf, size_t len);
+
+QcdmResult *qcdm_cmd_nv_get_hybrid_pref_result (const char *buf,
+ size_t len,
+ int *out_error);
+
+size_t qcdm_cmd_nv_set_hybrid_pref_new (char *buf,
+ size_t len,
+ u_int8_t hybrid_pref);
+
+QcdmResult *qcdm_cmd_nv_set_hybrid_pref_result (const char *buf,
+ size_t len,
+ int *out_error);
+
+/**********************************************************************/
+
/* Values for QCDM_CMD_NV_GET_HDR_REV_PREF_ITEM_REV_PREF */
enum {
QCDM_CMD_NV_HDR_REV_PREF_ITEM_REV_PREF_0 = 0x00,
diff --git a/libqcdm/src/nv-items.h b/libqcdm/src/nv-items.h
index 7f496db..1714a17 100644
--- a/libqcdm/src/nv-items.h
+++ b/libqcdm/src/nv-items.h
@@ -36,6 +36,7 @@ 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 */
+ DIAG_NV_HYBRID_PREF = 562, /* Hybrid 1x + HDR preference */
DIAG_NV_HDR_REV_PREF = 4964, /* HDR mode preference(?): rev0, revA, eHRPD */
};
@@ -100,5 +101,17 @@ struct DMNVItemHdrRevPref {
} __attribute__ ((packed));
typedef struct DMNVItemHdrRevPref DMNVItemHdrRevPref;
+/* Hybrid pref */
+enum {
+ DIAG_NV_HYBRID_PREF_OFF = 0x00,
+ DIAG_NV_HYBRID_PREF_ON = 0x01,
+};
+
+/* DIAG_NV_HYBRID_PREF */
+struct DMNVItemHybridPref {
+ u_int8_t hybrid_pref;
+} __attribute__ ((packed));
+typedef struct DMNVItemHybridPref DMNVItemHybridPref;
+
#endif /* LIBQCDM_NV_ITEMS_H */
diff --git a/libqcdm/tests/test-qcdm-com.c b/libqcdm/tests/test-qcdm-com.c
index df3633a..bc29923 100644
--- a/libqcdm/tests/test-qcdm-com.c
+++ b/libqcdm/tests/test-qcdm-com.c
@@ -653,6 +653,48 @@ test_com_read_mode_pref (void *f, void *data)
}
void
+test_com_read_hybrid_pref (void *f, void *data)
+{
+ TestComData *d = data;
+ gboolean success;
+ int err = QCDM_SUCCESS;
+ char buf[512];
+ guint8 pref;
+ gint len;
+ QcdmResult *result;
+ gsize reply_len;
+
+ len = qcdm_cmd_nv_get_hybrid_pref_new (buf, sizeof (buf));
+ 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_hybrid_pref_result (buf, reply_len, &err);
+ if (!result) {
+ if ( err == -QCDM_ERROR_NVCMD_FAILED
+ || err == -QCDM_ERROR_RESPONSE_BAD_PARAMETER
+ || err == -QCDM_ERROR_NV_ERROR_INACTIVE
+ || err == -QCDM_ERROR_NV_ERROR_BAD_PARAMETER)
+ return;
+ g_assert_cmpint (err, ==, QCDM_SUCCESS);
+ }
+
+ g_print ("\n");
+
+ err = qcdm_result_get_u8 (result, QCDM_CMD_NV_GET_HYBRID_PREF_ITEM_HYBRID_PREF, &pref);
+ g_assert_cmpint (err, ==, QCDM_SUCCESS);
+ g_message ("%s: Hybrid preference: 0x%02X", __func__, pref);
+
+ qcdm_result_unref (result);
+}
+
+void
test_com_read_hdr_rev_pref (void *f, void *data)
{
TestComData *d = data;
diff --git a/libqcdm/tests/test-qcdm-com.h b/libqcdm/tests/test-qcdm-com.h
index 57e00b0..2bb3f1f 100644
--- a/libqcdm/tests/test-qcdm-com.h
+++ b/libqcdm/tests/test-qcdm-com.h
@@ -33,6 +33,8 @@ void test_com_read_roam_pref (void *f, void *data);
void test_com_read_mode_pref (void *f, void *data);
+void test_com_read_hybrid_pref (void *f, void *data);
+
void test_com_read_hdr_rev_pref (void *f, void *data);
void test_com_status (void *f, void *data);
diff --git a/libqcdm/tests/test-qcdm.c b/libqcdm/tests/test-qcdm.c
index 8d25d82..0cf977b 100644
--- a/libqcdm/tests/test-qcdm.c
+++ b/libqcdm/tests/test-qcdm.c
@@ -103,6 +103,7 @@ int main (int argc, char **argv)
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_read_mode_pref, data->com_data));
+ g_test_suite_add (suite, TESTCASE (test_com_read_hybrid_pref, data->com_data));
g_test_suite_add (suite, TESTCASE (test_com_read_hdr_rev_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));