qcdm: add command to get MDN (ie, phone number)
This commit is contained in:
@@ -6,6 +6,7 @@ libqcdm_la_CPPFLAGS = \
|
|||||||
|
|
||||||
libqcdm_la_SOURCES = \
|
libqcdm_la_SOURCES = \
|
||||||
dm-commands.h \
|
dm-commands.h \
|
||||||
|
nv-items.h \
|
||||||
com.c \
|
com.c \
|
||||||
com.h \
|
com.h \
|
||||||
commands.c \
|
commands.c \
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "dm-commands.h"
|
#include "dm-commands.h"
|
||||||
|
#include "nv-items.h"
|
||||||
#include "result-private.h"
|
#include "result-private.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
@@ -215,3 +216,55 @@ qcdm_cmd_esn_result (const char *buf, gsize len, GError **error)
|
|||||||
return result;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
@@ -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 */
|
#endif /* LIBQCDM_COMMANDS_H */
|
||||||
|
35
libqcdm/src/nv-items.h
Normal file
35
libqcdm/src/nv-items.h
Normal file
@@ -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 */
|
||||||
|
|
@@ -204,7 +204,7 @@ test_com (void *f, void *data)
|
|||||||
TestComData *d = data;
|
TestComData *d = data;
|
||||||
gboolean success;
|
gboolean success;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
char buf[100];
|
char buf[512];
|
||||||
const char *str;
|
const char *str;
|
||||||
gint len;
|
gint len;
|
||||||
QCDMResult *result;
|
QCDMResult *result;
|
||||||
@@ -219,6 +219,8 @@ test_com (void *f, void *data)
|
|||||||
}
|
}
|
||||||
g_assert (success);
|
g_assert (success);
|
||||||
|
|
||||||
|
/*** Get the device's firmware version information ***/
|
||||||
|
|
||||||
len = qcdm_cmd_version_info_new (buf, sizeof (buf), NULL);
|
len = qcdm_cmd_version_info_new (buf, sizeof (buf), NULL);
|
||||||
g_assert (len == 4);
|
g_assert (len == 4);
|
||||||
|
|
||||||
@@ -255,7 +257,7 @@ test_com (void *f, void *data)
|
|||||||
|
|
||||||
qcdm_result_unref (result);
|
qcdm_result_unref (result);
|
||||||
|
|
||||||
/* Get the device's ESN */
|
/*** Get the device's ESN ***/
|
||||||
|
|
||||||
len = qcdm_cmd_esn_new (buf, sizeof (buf), NULL);
|
len = qcdm_cmd_esn_new (buf, sizeof (buf), NULL);
|
||||||
g_assert (len == 4);
|
g_assert (len == 4);
|
||||||
@@ -276,5 +278,28 @@ test_com (void *f, void *data)
|
|||||||
g_message ("%s: ESN: %s", __func__, str);
|
g_message ("%s: ESN: %s", __func__, str);
|
||||||
|
|
||||||
qcdm_result_unref (result);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user