aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libqcdm/src/Makefile.am1
-rw-r--r--libqcdm/src/commands.c53
-rw-r--r--libqcdm/src/commands.h14
-rw-r--r--libqcdm/src/nv-items.h35
-rw-r--r--libqcdm/tests/test-qcdm-com.c29
5 files changed, 130 insertions, 2 deletions
diff --git a/libqcdm/src/Makefile.am b/libqcdm/src/Makefile.am
index 18edc707..5cc05682 100644
--- a/libqcdm/src/Makefile.am
+++ b/libqcdm/src/Makefile.am
@@ -6,6 +6,7 @@ libqcdm_la_CPPFLAGS = \
libqcdm_la_SOURCES = \
dm-commands.h \
+ nv-items.h \
com.c \
com.h \
commands.c \
diff --git a/libqcdm/src/commands.c b/libqcdm/src/commands.c
index 9f2f9a79..41356935 100644
--- a/libqcdm/src/commands.c
+++ b/libqcdm/src/commands.c
@@ -20,6 +20,7 @@
#include "commands.h"
#include "error.h"
#include "dm-commands.h"
+#include "nv-items.h"
#include "result-private.h"
#include "utils.h"
@@ -215,3 +216,55 @@ qcdm_cmd_esn_result (const char *buf, gsize len, GError **error)
return result;
}
+/**********************************************************************/
+
+gsize
+qcdm_cmd_nv_get_mdn_new (char *buf, gsize len, guint8 profile, GError **error)
+{
+ char cmdbuf[sizeof (DMCmdNVReadWrite) + DIAG_TRAILER_LEN];
+ DMCmdNVReadWrite *cmd = (DMCmdNVReadWrite *) &cmdbuf[0];
+ DMNVItemMdn *req;
+
+ g_return_val_if_fail (buf != NULL, 0);
+ g_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 = GUINT16_TO_LE (DIAG_NV_DIR_NUMBER);
+
+ req = (DMNVItemMdn *) &cmd->data[0];
+ req->profile = profile;
+
+ return dm_encapsulate_buffer (cmdbuf, sizeof (*cmd), sizeof (cmdbuf), buf, len);
+}
+
+QCDMResult *
+qcdm_cmd_nv_get_mdn_result (const char *buf, gsize len, GError **error)
+{
+ QCDMResult *result = NULL;
+ DMCmdNVReadWrite *rsp = (DMCmdNVReadWrite *) buf;
+ DMNVItemMdn *mdn;
+ char tmp[11];
+
+ g_return_val_if_fail (buf != NULL, NULL);
+
+ if (!check_command (buf, len, DIAG_CMD_NV_READ, sizeof (DMCmdNVReadWrite), error))
+ return NULL;
+
+ mdn = (DMNVItemMdn *) &rsp->data[0];
+
+ result = qcdm_result_new ();
+
+ qcdm_result_add_uint8 (result, QCDM_CMD_NV_GET_MDN_ITEM_PROFILE, mdn->profile);
+
+ memset (tmp, 0, sizeof (tmp));
+ g_assert (sizeof (mdn->mdn) <= sizeof (tmp));
+ memcpy (tmp, mdn->mdn, sizeof (mdn->mdn));
+ qcdm_result_add_string (result, QCDM_CMD_NV_GET_MDN_ITEM_MDN, tmp);
+
+ return result;
+}
+
+/**********************************************************************/
+
+
diff --git a/libqcdm/src/commands.h b/libqcdm/src/commands.h
index 67d7fbb1..8e62b7ef 100644
--- a/libqcdm/src/commands.h
+++ b/libqcdm/src/commands.h
@@ -52,4 +52,18 @@ QCDMResult *qcdm_cmd_esn_result (const char *buf,
/**********************************************************************/
+#define QCDM_CMD_NV_GET_MDN_ITEM_PROFILE "profile"
+#define QCDM_CMD_NV_GET_MDN_ITEM_MDN "mdn"
+
+gsize qcdm_cmd_nv_get_mdn_new (char *buf,
+ gsize len,
+ guint8 profile,
+ GError **error);
+
+QCDMResult *qcdm_cmd_nv_get_mdn_result (const char *buf,
+ gsize len,
+ GError **error);
+
+/**********************************************************************/
+
#endif /* LIBQCDM_COMMANDS_H */
diff --git a/libqcdm/src/nv-items.h b/libqcdm/src/nv-items.h
new file mode 100644
index 00000000..6f058121
--- /dev/null
+++ b/libqcdm/src/nv-items.h
@@ -0,0 +1,35 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Copyright (C) 2010 Red Hat, Inc.
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef LIBQCDM_NV_ITEMS_H
+#define LIBQCDM_NV_ITEMS_H
+
+enum {
+ DIAG_NV_DIR_NUMBER = 178, /* Mobile Directory Number (MDN) */
+};
+
+
+/* DIAG_NV_DIR_NUMBER */
+struct DMNVItemMdn {
+ guint8 profile;
+ guint8 mdn[10];
+} __attribute__ ((packed));
+typedef struct DMNVItemMdn DMNVItemMdn;
+
+
+#endif /* LIBQCDM_NV_ITEMS_H */
+
diff --git a/libqcdm/tests/test-qcdm-com.c b/libqcdm/tests/test-qcdm-com.c
index 676aea85..927fa1a4 100644
--- a/libqcdm/tests/test-qcdm-com.c
+++ b/libqcdm/tests/test-qcdm-com.c
@@ -204,7 +204,7 @@ test_com (void *f, void *data)
TestComData *d = data;
gboolean success;
GError *error = NULL;
- char buf[100];
+ char buf[512];
const char *str;
gint len;
QCDMResult *result;
@@ -219,6 +219,8 @@ test_com (void *f, void *data)
}
g_assert (success);
+ /*** Get the device's firmware version information ***/
+
len = qcdm_cmd_version_info_new (buf, sizeof (buf), NULL);
g_assert (len == 4);
@@ -255,7 +257,7 @@ test_com (void *f, void *data)
qcdm_result_unref (result);
- /* Get the device's ESN */
+ /*** Get the device's ESN ***/
len = qcdm_cmd_esn_new (buf, sizeof (buf), NULL);
g_assert (len == 4);
@@ -276,5 +278,28 @@ test_com (void *f, void *data)
g_message ("%s: ESN: %s", __func__, str);
qcdm_result_unref (result);
+
+
+ /*** Get the device's phone number ***/
+
+ len = qcdm_cmd_nv_get_mdn_new (buf, sizeof (buf), 0, NULL);
+ 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_mdn_result (buf, reply_len, &error);
+ g_assert (result);
+
+ str = NULL;
+ qcdm_result_get_string (result, QCDM_CMD_NV_GET_MDN_ITEM_MDN, &str);
+ g_message ("%s: MDN: %s", __func__, str);
+
+ qcdm_result_unref (result);
}