Skip to content

Commit 61ef41f

Browse files
rerickson1nashif
authored andcommitted
drivers: modem: hl7800: Add query carrier config
Add API to query the carrier config of the HL7800. Signed-off-by: Ryan Erickson <[email protected]>
1 parent 6fb6533 commit 61ef41f

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

drivers/modem/hl7800.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ struct hl7800_iface_ctx {
514514
bool mdm_startup_reporting_on;
515515
int device_services_ind;
516516
bool new_rat_cmd_support;
517+
uint8_t operator_index;
517518

518519
/* modem state */
519520
bool allow_sleep;
@@ -1051,6 +1052,24 @@ int32_t mdm_hl7800_get_local_time(struct tm *tm, int32_t *offset)
10511052
}
10521053
#endif
10531054

1055+
int32_t mdm_hl7800_get_operator_index(void)
1056+
{
1057+
int ret;
1058+
1059+
hl7800_lock();
1060+
wakeup_hl7800();
1061+
ictx.last_socket_id = 0;
1062+
ret = send_at_cmd(NULL, "AT+KCARRIERCFG?", MDM_CMD_SEND_TIMEOUT, 0,
1063+
false);
1064+
allow_sleep(true);
1065+
hl7800_unlock();
1066+
if (ret < 0) {
1067+
return ret;
1068+
} else {
1069+
return ictx.operator_index;
1070+
}
1071+
}
1072+
10541073
void mdm_hl7800_generate_status_events(void)
10551074
{
10561075
hl7800_lock();
@@ -2371,6 +2390,32 @@ static bool on_cmd_network_report_query(struct net_buf **buf, uint16_t len)
23712390
return true;
23722391
}
23732392

2393+
static bool on_cmd_operator_index_query(struct net_buf **buf, uint16_t len)
2394+
{
2395+
struct net_buf *frag = NULL;
2396+
char carrier[MDM_HL7800_OPERATOR_INDEX_SIZE];
2397+
size_t out_len;
2398+
2399+
wait_for_modem_data_and_newline(buf, net_buf_frags_len(*buf),
2400+
MDM_HL7800_OPERATOR_INDEX_SIZE);
2401+
2402+
frag = NULL;
2403+
len = net_buf_findcrlf(*buf, &frag);
2404+
if (!frag) {
2405+
LOG_ERR("Unable to find end of operator index response");
2406+
goto done;
2407+
}
2408+
2409+
out_len = net_buf_linearize(carrier, MDM_HL7800_OPERATOR_INDEX_STRLEN,
2410+
*buf, 0, len);
2411+
carrier[out_len] = 0;
2412+
ictx.operator_index = (uint8_t)strtol(carrier, NULL, 10);
2413+
2414+
LOG_INF("Operator Index: %u", ictx.operator_index);
2415+
done:
2416+
return true;
2417+
}
2418+
23742419
#ifdef CONFIG_NEWLIB_LIBC
23752420
/* Handler: +CCLK: "yy/MM/dd,hh:mm:ss±zz" */
23762421
static bool on_cmd_rtc_query(struct net_buf **buf, uint16_t len)
@@ -3335,6 +3380,7 @@ static void hl7800_rx(void)
33353380
CMD_HANDLER("+WPPP: 1,1,", atcmdinfo_pdp_authentication_cfg),
33363381
CMD_HANDLER("+CGDCONT: 1", atcmdinfo_pdp_context),
33373382
CMD_HANDLER("AT+CEREG?", network_report_query),
3383+
CMD_HANDLER("+KCARRIERCFG: ", operator_index_query),
33383384
#ifdef CONFIG_NEWLIB_LIBC
33393385
CMD_HANDLER("+CCLK: ", rtc_query),
33403386
#endif

include/drivers/modem/hl7800.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ struct mdm_hl7800_apn {
5757
#define MDM_HL7800_LTE_BAND_STR_SIZE 21
5858
#define MDM_HL7800_LTE_BAND_STRLEN (MDM_HL7800_LTE_BAND_STR_SIZE - 1)
5959

60+
#define MDM_HL7800_OPERATOR_INDEX_SIZE 3
61+
#define MDM_HL7800_OPERATOR_INDEX_STRLEN (MDM_HL7800_OPERATOR_INDEX_SIZE - 1)
62+
6063
enum mdm_hl7800_radio_mode { MDM_RAT_CAT_M1 = 0, MDM_RAT_CAT_NB1 };
6164

6265
enum mdm_hl7800_event {
@@ -263,6 +266,13 @@ int32_t mdm_hl7800_get_local_time(struct tm *tm, int32_t *offset);
263266
int32_t mdm_hl7800_update_fw(char *file_path);
264267
#endif
265268

269+
/**
270+
* @brief Read the operator index from the modem.
271+
*
272+
* @retval negative error code, 0 on success
273+
*/
274+
int32_t mdm_hl7800_get_operator_index(void);
275+
266276
#ifdef __cplusplus
267277
}
268278
#endif

0 commit comments

Comments
 (0)