drivers: modem: Get the IMSI and ICCID from the SIM
This adds an option to query the modem for the SIM's IMSI and ICCID numbers, just like the modem's IMEI is queried today. This requires the SIM to be present, which might not be the case for all applications, so it can be disabled. Signed-off-by: Göran Weinholt <goran.weinholt@endian.se> Signed-off-by: Benjamin Lindqvist <benjamin.lindqvist@endian.se>
This commit is contained in:
parent
e86e6fa769
commit
1ccc65a9c9
5 changed files with 80 additions and 1 deletions
|
@ -124,6 +124,15 @@ config MODEM_SHELL
|
|||
Activate shell module that provides modem utilities like
|
||||
sending a command to the modem UART.
|
||||
|
||||
config MODEM_SIM_NUMBERS
|
||||
bool "Enable querying the SIM for IMSI and ICCID"
|
||||
depends on MODEM_SHELL
|
||||
default y
|
||||
help
|
||||
Query the SIM card for the IMSI and ICCID identifiers. This
|
||||
can be disabled if the application does not use a SIM.
|
||||
|
||||
|
||||
source "drivers/modem/Kconfig.ublox-sara-r4"
|
||||
source "drivers/modem/Kconfig.wncm14a2a"
|
||||
source "drivers/modem/Kconfig.gsm"
|
||||
|
|
|
@ -112,12 +112,18 @@ static struct modem_cmd response_cmds[] = {
|
|||
#define MDM_MODEL_LENGTH 16
|
||||
#define MDM_REVISION_LENGTH 64
|
||||
#define MDM_IMEI_LENGTH 16
|
||||
#define MDM_IMSI_LENGTH 16
|
||||
#define MDM_ICCID_LENGTH 32
|
||||
|
||||
struct modem_info {
|
||||
char mdm_manufacturer[MDM_MANUFACTURER_LENGTH];
|
||||
char mdm_model[MDM_MODEL_LENGTH];
|
||||
char mdm_revision[MDM_REVISION_LENGTH];
|
||||
char mdm_imei[MDM_IMEI_LENGTH];
|
||||
#if defined(CONFIG_MODEM_SIM_NUMBERS)
|
||||
char mdm_imsi[MDM_IMSI_LENGTH];
|
||||
char mdm_iccid[MDM_ICCID_LENGTH];
|
||||
#endif
|
||||
};
|
||||
|
||||
static struct modem_info minfo;
|
||||
|
@ -181,6 +187,46 @@ MODEM_CMD_DEFINE(on_cmd_atcmdinfo_imei)
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_MODEM_SIM_NUMBERS)
|
||||
/* Handler: <IMSI> */
|
||||
MODEM_CMD_DEFINE(on_cmd_atcmdinfo_imsi)
|
||||
{
|
||||
size_t out_len;
|
||||
|
||||
out_len = net_buf_linearize(minfo.mdm_imsi, sizeof(minfo.mdm_imsi) - 1,
|
||||
data->rx_buf, 0, len);
|
||||
minfo.mdm_imsi[out_len] = '\0';
|
||||
LOG_INF("IMSI: %s", log_strdup(minfo.mdm_imsi));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Handler: <ICCID> */
|
||||
MODEM_CMD_DEFINE(on_cmd_atcmdinfo_iccid)
|
||||
{
|
||||
size_t out_len;
|
||||
|
||||
out_len = net_buf_linearize(minfo.mdm_iccid, sizeof(minfo.mdm_iccid) - 1,
|
||||
data->rx_buf, 0, len);
|
||||
minfo.mdm_iccid[out_len] = '\0';
|
||||
if (minfo.mdm_iccid[0] == '+') {
|
||||
/* Seen on U-blox SARA: "+CCID: nnnnnnnnnnnnnnnnnnnn".
|
||||
* Skip over the +CCID bit, which other modems omit.
|
||||
*/
|
||||
char *p = strchr(minfo.mdm_iccid, ' ');
|
||||
|
||||
if (p) {
|
||||
size_t len = strlen(p+1);
|
||||
|
||||
memmove(minfo.mdm_iccid, p+1, len+1);
|
||||
}
|
||||
}
|
||||
LOG_INF("ICCID: %s", log_strdup(minfo.mdm_iccid));
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_MODEM_SIM_NUMBERS */
|
||||
#endif /* CONFIG_MODEM_SHELL */
|
||||
|
||||
static struct setup_cmd setup_cmds[] = {
|
||||
|
@ -196,6 +242,10 @@ static struct setup_cmd setup_cmds[] = {
|
|||
SETUP_CMD("AT+CGMI", "", on_cmd_atcmdinfo_manufacturer, 0U, ""),
|
||||
SETUP_CMD("AT+CGMM", "", on_cmd_atcmdinfo_model, 0U, ""),
|
||||
SETUP_CMD("AT+CGMR", "", on_cmd_atcmdinfo_revision, 0U, ""),
|
||||
# if defined(CONFIG_MODEM_SIM_NUMBERS)
|
||||
SETUP_CMD("AT+CIMI", "", on_cmd_atcmdinfo_imsi, 0U, ""),
|
||||
SETUP_CMD("AT+CCID", "", on_cmd_atcmdinfo_iccid, 0U, ""),
|
||||
# endif
|
||||
SETUP_CMD("AT+CGSN", "", on_cmd_atcmdinfo_imei, 0U, ""),
|
||||
#endif
|
||||
|
||||
|
@ -591,7 +641,11 @@ static int gsm_init(struct device *device)
|
|||
gsm->context.data_model = minfo.mdm_model;
|
||||
gsm->context.data_revision = minfo.mdm_revision;
|
||||
gsm->context.data_imei = minfo.mdm_imei;
|
||||
#endif
|
||||
#if defined(CONFIG_MODEM_SIM_NUMBERS)
|
||||
gsm->context.data_imsi = minfo.mdm_imsi;
|
||||
gsm->context.data_iccid = minfo.mdm_iccid;
|
||||
#endif /* CONFIG_MODEM_SIM_NUMBERS */
|
||||
#endif /* CONFIG_MODEM_SHELL */
|
||||
|
||||
gsm->gsm_data.isr_buf = &gsm->gsm_isr_buf[0];
|
||||
gsm->gsm_data.isr_buf_len = sizeof(gsm->gsm_isr_buf);
|
||||
|
|
|
@ -62,6 +62,10 @@ struct modem_context {
|
|||
char *data_model;
|
||||
char *data_revision;
|
||||
char *data_imei;
|
||||
#if defined(CONFIG_MODEM_SIM_NUMBERS)
|
||||
char *data_imsi;
|
||||
char *data_iccid;
|
||||
#endif
|
||||
int data_rssi;
|
||||
|
||||
/* pin config */
|
||||
|
|
|
@ -32,7 +32,11 @@ struct mdm_receiver_context {
|
|||
char *data_manufacturer;
|
||||
char *data_model;
|
||||
char *data_revision;
|
||||
#if defined(CONFIG_MODEM_SIM_NUMBERS)
|
||||
char *data_imei;
|
||||
char *data_imsi;
|
||||
#endif
|
||||
char *data_iccid;
|
||||
int data_rssi;
|
||||
};
|
||||
|
||||
|
|
|
@ -63,12 +63,20 @@ static int cmd_modem_list(const struct shell *shell, size_t argc,
|
|||
"\tModel: %s\n"
|
||||
"\tRevision: %s\n"
|
||||
"\tIMEI: %s\n"
|
||||
#if defined(CONFIG_MODEM_SIM_NUMBERS)
|
||||
"\tIMSI: %s\n"
|
||||
"\tICCID: %s\n"
|
||||
#endif
|
||||
"\tRSSI: %d\n", i,
|
||||
UART_DEV_NAME(mdm_ctx),
|
||||
mdm_ctx->data_manufacturer,
|
||||
mdm_ctx->data_model,
|
||||
mdm_ctx->data_revision,
|
||||
mdm_ctx->data_imei,
|
||||
#if defined(CONFIG_MODEM_SIM_NUMBERS)
|
||||
mdm_ctx->data_imsi,
|
||||
mdm_ctx->data_iccid,
|
||||
#endif
|
||||
mdm_ctx->data_rssi);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue