Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions generated/Kconfig.kv_keys
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ config KV_STORE_KEY_LTE_NETWORKING_MODES
help
Enabled LTE networking modes and preferences

config KV_STORE_KEY_LTE_SIM_IMSI
bool "Enable KV key LTE_SIM_IMSI"
default y if NRF_MODEM_LIB
help
'International Modem Subscriber Identity' as returned by AT+CIMI

config KV_STORE_KEY_BLUETOOTH_PEER
bool "Enable KV key BLUETOOTH_PEER"
help
Expand Down
19 changes: 19 additions & 0 deletions generated/include/infuse/fs/kv_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,12 @@ struct kv_lte_networking_modes {
uint8_t prefer;
} __packed;

/** 'International Modem Subscriber Identity' as returned by AT+CIMI */
struct kv_lte_sim_imsi {
/** 15 digit IMSI */
uint64_t imsi;
} __packed;

/** Bluetooth peer device */
struct kv_bluetooth_peer {
/** Peer device Bluetooth address */
Expand Down Expand Up @@ -452,6 +458,8 @@ enum kv_builtin_id {
KV_KEY_LTE_PDP_CONFIG = 45,
/** Enabled LTE networking modes and preferences */
KV_KEY_LTE_NETWORKING_MODES = 46,
/** 'International Modem Subscriber Identity' as returned by AT+CIMI */
KV_KEY_LTE_SIM_IMSI = 47,
/** Bluetooth peer device */
KV_KEY_BLUETOOTH_PEER = 50,
/** LoRa modem configuration */
Expand Down Expand Up @@ -502,6 +510,7 @@ enum kv_builtin_size {
_KV_KEY_EPACKET_UDP_PORT_SIZE = sizeof(struct kv_epacket_udp_port),
_KV_KEY_LTE_MODEM_IMEI_SIZE = sizeof(struct kv_lte_modem_imei),
_KV_KEY_LTE_NETWORKING_MODES_SIZE = sizeof(struct kv_lte_networking_modes),
_KV_KEY_LTE_SIM_IMSI_SIZE = sizeof(struct kv_lte_sim_imsi),
_KV_KEY_BLUETOOTH_PEER_SIZE = sizeof(struct kv_bluetooth_peer),
_KV_KEY_LORA_CONFIG_SIZE = sizeof(struct kv_lora_config),
_KV_KEY_BLUETOOTH_THROUGHPUT_LIMIT_SIZE = sizeof(struct kv_bluetooth_throughput_limit),
Expand Down Expand Up @@ -531,6 +540,7 @@ enum kv_builtin_size {
#define _KV_KEY_LTE_SIM_UICC_TYPE struct kv_lte_sim_uicc
#define _KV_KEY_LTE_PDP_CONFIG_TYPE struct kv_lte_pdp_config
#define _KV_KEY_LTE_NETWORKING_MODES_TYPE struct kv_lte_networking_modes
#define _KV_KEY_LTE_SIM_IMSI_TYPE struct kv_lte_sim_imsi
#define _KV_KEY_BLUETOOTH_PEER_TYPE struct kv_bluetooth_peer
#define _KV_KEY_LORA_CONFIG_TYPE struct kv_lora_config
#define _KV_KEY_BLUETOOTH_THROUGHPUT_LIMIT_TYPE struct kv_bluetooth_throughput_limit
Expand Down Expand Up @@ -580,6 +590,8 @@ enum kv_builtin_size {
(1 +)) \
IF_ENABLED(CONFIG_KV_STORE_KEY_LTE_NETWORKING_MODES, \
(1 +)) \
IF_ENABLED(CONFIG_KV_STORE_KEY_LTE_SIM_IMSI, \
(1 +)) \
IF_ENABLED(CONFIG_KV_STORE_KEY_BLUETOOTH_PEER, \
(1 +)) \
IF_ENABLED(CONFIG_KV_STORE_KEY_LORA_CONFIG, \
Expand Down Expand Up @@ -770,6 +782,13 @@ static struct key_value_slot_definition _KV_SLOTS_ARRAY_DEFINE[] = {
.flags = KV_FLAGS_REFLECT,
},
#endif /* CONFIG_KV_STORE_KEY_LTE_NETWORKING_MODES */
#ifdef CONFIG_KV_STORE_KEY_LTE_SIM_IMSI
{
.key = KV_KEY_LTE_SIM_IMSI,
.range = 1,
.flags = KV_FLAGS_REFLECT | KV_FLAGS_READ_ONLY,
},
#endif /* CONFIG_KV_STORE_KEY_LTE_SIM_IMSI */
#ifdef CONFIG_KV_STORE_KEY_BLUETOOTH_PEER
{
.key = KV_KEY_BLUETOOTH_PEER,
Expand Down
10 changes: 9 additions & 1 deletion lib/common_boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,17 @@ static int infuse_common_boot(void)
KV_STRUCT_KV_STRING_VAR(24) sim_uicc;

if (KV_STORE_READ(KV_KEY_LTE_SIM_UICC, &sim_uicc) > 0) {
LOG_INF("\t SIM: %s", sim_uicc.value);
LOG_INF("\t UICC: %s", sim_uicc.value);
}
#endif /* CONFIG_KV_STORE_KEY_LTE_SIM_UICC */
#ifdef CONFIG_KV_STORE_KEY_LTE_SIM_IMSI
KV_KEY_TYPE(KV_KEY_LTE_SIM_IMSI) sim_imsi;

if (KV_STORE_READ(KV_KEY_LTE_SIM_IMSI, &sim_imsi) > 0) {
LOG_INF("\t IMSI: %lld", sim_imsi.imsi);
}
#endif /* CONFIG_KV_STORE_KEY_LTE_SIM_IMSI */

LOG_INF("\tReboots: %d", reboot.count);
#ifdef CONFIG_INFUSE_REBOOT
struct timeutil_sync_instant reference;
Expand Down
4 changes: 4 additions & 0 deletions lib/nrf_modem_lib/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ config INFUSE_NRF_MODEM_LIB_SIM_IMEI
string "Simulated IMEI"
default "359404230110000"

config INFUSE_NRF_MODEM_LIB_SIM_IMSI
string "Simulated IMSI"
default "525053090792900"

config INFUSE_NRF_MODEM_LIB_SIM_UICC
string "Simulated UICC"
default "8901990000000000000"
Expand Down
2 changes: 2 additions & 0 deletions lib/nrf_modem_lib/nrf_modem_lib_sim.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ int nrf_modem_at_scanf(const char *cmd, const char *fmt, ...)
out = CONFIG_INFUSE_NRF_MODEM_LIB_SIM_ESN "\nOK";
} else if (strstr("AT+CGSN=1", cmd)) {
out = "+CGSN: \"" CONFIG_INFUSE_NRF_MODEM_LIB_SIM_IMEI "\"\nOK";
} else if (strstr("AT+CIMI", cmd)) {
out = CONFIG_INFUSE_NRF_MODEM_LIB_SIM_IMSI "\nOK";
} else if (strstr("AT%XICCID", cmd)) {
out = "%XICCID: " CONFIG_INFUSE_NRF_MODEM_LIB_SIM_UICC "\nOK";
} else if (strstr("AT+CESQ", cmd)) {
Expand Down
12 changes: 11 additions & 1 deletion lib/nrf_modem_lib/nrf_modem_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,25 @@ static void network_info_update(struct k_work *work)
}

if (!sim_card_queried) {
KV_KEY_TYPE(KV_KEY_LTE_SIM_IMSI) sim_imsi;
KV_STRUCT_KV_STRING_VAR(25) sim_uicc;

/* SIM IMSI */
rc = nrf_modem_at_scanf("AT+CIMI", "%" SCNd64 "\n", &sim_imsi.imsi);
if (rc == 1) {
if (KV_STORE_WRITE(KV_KEY_LTE_SIM_IMSI, &sim_imsi) > 0) {
/* Print value when first saved to KV store */
LOG_INF("IMSI: %lld", sim_imsi.imsi);
}
}
/* SIM ICCID */
rc = nrf_modem_at_scanf("AT%XICCID", "%%XICCID: %24s", sim_uicc.value);
if (rc == 1) {
sim_uicc.value_num = strlen(sim_uicc.value) + 1;
if (kv_store_write(KV_KEY_LTE_SIM_UICC, &sim_uicc, 1 + sim_uicc.value_num) >
0) {
/* Print value when first saved to KV store */
LOG_INF("SIM: %s", sim_uicc.value);
LOG_INF("UICC: %s", sim_uicc.value);
}
sim_card_queried = true;
}
Expand Down
10 changes: 10 additions & 0 deletions scripts/west_commands/cloud_definitions/kv_store.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,16 @@
{"name": "prefer", "type": "uint8_t", "description": "Preference as per `enum lte_lc_system_mode_preference`"}
]
},
"47": {
"name": "LTE_SIM_IMSI",
"description": "'International Modem Subscriber Identity' as returned by AT+CIMI",
"reflect": true,
"read_only": true,
"default": "y if NRF_MODEM_LIB",
"fields": [
{"name": "imsi", "type": "uint64_t", "description": "15 digit IMSI"}
]
},
"50": {
"name": "BLUETOOTH_PEER",
"description": "Bluetooth peer device",
Expand Down
1 change: 1 addition & 0 deletions tests/lib/common_boot/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ CONFIG_ZTEST=y
CONFIG_INFUSE_SDK=y
# Test the various boot print options
CONFIG_KV_STORE_KEY_LTE_SIM_UICC=y
CONFIG_KV_STORE_KEY_LTE_SIM_IMSI=y
CONFIG_KV_STORE_KEY_INFUSE_APPLICATION_ID=y
# Explicitly want reboot handling in this test
CONFIG_INFUSE_REBOOT=y
Expand Down
6 changes: 5 additions & 1 deletion tests/lib/common_boot/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ static __noinit int resetting_with_bad_id;
ZTEST(common_boot, test_boot)
{
KV_STRING_CONST(sim_uicc, "89000000000012345");
KV_KEY_TYPE(KV_KEY_LTE_SIM_IMSI) sim_imsi;
KV_KEY_TYPE(KV_KEY_INFUSE_APPLICATION_ID) id;
KV_KEY_TYPE(KV_KEY_REBOOTS) reboots;
uint64_t time_2020 = epoch_time_from_gps(2086, 259218, 0);
Expand All @@ -44,6 +45,7 @@ ZTEST(common_boot, test_boot)
if (resetting_with_bad_id == KV_FINAL_RESET_KEY) {
/* KV store should have been reset */
zassert_false(kv_store_key_exists(KV_KEY_LTE_SIM_UICC), "KV store not reset");
zassert_false(kv_store_key_exists(KV_KEY_LTE_SIM_IMSI), "KV store not reset");
zassert_equal(1, reboots.count, "KV store not reset");
/* We should still have the reboot reason state */
rc = infuse_common_boot_last_reboot(&reboot_state);
Expand All @@ -57,8 +59,10 @@ ZTEST(common_boot, test_boot)

switch (reboots.count) {
case 1:
/* Set SIM value */
sim_imsi.imsi = 123456789012345ll;
/* Set SIM values */
zassert_equal(sizeof(sim_uicc), KV_STORE_WRITE(KV_KEY_LTE_SIM_UICC, &sim_uicc));
zassert_equal(sizeof(sim_imsi), KV_STORE_WRITE(KV_KEY_LTE_SIM_IMSI, &sim_imsi));
/* No reboot information yet */
rc = infuse_common_boot_last_reboot(&reboot_state);
zassert_equal(-ENOENT, rc);
Expand Down
12 changes: 12 additions & 0 deletions tests/lib/common_boot/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ common:
min_ram: 32
tests:
lib.common_boot:
ignore_faults: true
expect_reboot: true
platform_exclude:
- native_sim
Expand All @@ -12,3 +13,14 @@ tests:
- infuse
integration_platforms:
- mps2/an385
harness: console
harness_config:
type: multi_line
ordered: false
regex:
- "Version: (.*)"
- "Device: (.*)"
- "Board: (.*)"
- "UICC: (.*)"
- "IMSI: (.*)"
- "Reboots: (.*)"
1 change: 1 addition & 0 deletions tests/net/nrf_modem_lib/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ CONFIG_KV_STORE_KEY_LTE_MODEM_FIRMWARE_REVISION=y
CONFIG_KV_STORE_KEY_LTE_MODEM_ESN=y
CONFIG_KV_STORE_KEY_LTE_MODEM_IMEI=y
CONFIG_KV_STORE_KEY_LTE_SIM_UICC=y
CONFIG_KV_STORE_KEY_LTE_SIM_IMSI=y
CONFIG_KV_STORE_KEY_LTE_PDP_CONFIG=y
CONFIG_KV_STORE_KEY_LTE_NETWORKING_MODES=y

Expand Down
6 changes: 6 additions & 0 deletions tests/net/nrf_modem_lib/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ ZTEST(infuse_nrf_modem_monitor, test_integration)
KV_KEY_TYPE_VAR(KV_KEY_LTE_PDP_CONFIG, 16) pdp_config;
KV_KEY_TYPE(KV_KEY_LTE_NETWORKING_MODES) net_modes;
KV_KEY_TYPE(KV_KEY_LTE_MODEM_IMEI) imei;
KV_KEY_TYPE(KV_KEY_LTE_SIM_IMSI) imsi;
struct net_if *iface = net_if_get_default();
struct nrf_modem_network_state net_state;
struct nrf_modem_fault_info fault_info = {0};
Expand All @@ -182,6 +183,7 @@ ZTEST(infuse_nrf_modem_monitor, test_integration)
zassert_false(kv_store_key_exists(KV_KEY_LTE_MODEM_ESN));
zassert_false(kv_store_key_exists(KV_KEY_LTE_MODEM_IMEI));
zassert_false(kv_store_key_exists(KV_KEY_LTE_SIM_UICC));
zassert_false(kv_store_key_exists(KV_KEY_LTE_SIM_IMSI));
zassert_false(kv_store_key_exists(KV_KEY_LTE_PDP_CONFIG));
zassert_false(kv_store_key_exists(KV_KEY_LTE_NETWORKING_MODES));

Expand All @@ -195,6 +197,7 @@ ZTEST(infuse_nrf_modem_monitor, test_integration)
zassert_true(kv_store_key_exists(KV_KEY_LTE_MODEM_ESN));
zassert_true(kv_store_key_exists(KV_KEY_LTE_MODEM_IMEI));
zassert_false(kv_store_key_exists(KV_KEY_LTE_SIM_UICC));
zassert_false(kv_store_key_exists(KV_KEY_LTE_SIM_IMSI));
zassert_true(kv_store_key_exists(KV_KEY_LTE_PDP_CONFIG));
zassert_true(kv_store_key_exists(KV_KEY_LTE_NETWORKING_MODES));

Expand Down Expand Up @@ -227,6 +230,9 @@ ZTEST(infuse_nrf_modem_monitor, test_integration)
/* SIM card queried now that LTE is active */
zassert_true(kv_store_key_exists(KV_KEY_LTE_SIM_UICC));
kv_string_equal(KV_KEY_LTE_SIM_UICC, CONFIG_INFUSE_NRF_MODEM_LIB_SIM_UICC);
zassert_true(kv_store_key_exists(KV_KEY_LTE_SIM_IMSI));
KV_STORE_READ(KV_KEY_LTE_SIM_IMSI, &imsi);
zassert_equal(atoll(CONFIG_INFUSE_NRF_MODEM_LIB_SIM_IMSI), imsi.imsi);

nrf_modem_monitor_network_state(&net_state);
zassert_equal(LTE_LC_NW_REG_SEARCHING, net_state.nw_reg_status);
Expand Down