drivers: modem: gsm: allow the user to get modem information
Make modem_info structure public in order to allow the user to get modem information using gsm_ppp_modem_info function. Move modem info query commands into separate function that's called only once during gsm configuring because there is no necessity to re-querying modem since they should not change. Signed-off-by: Bartosz Bilas <b.bilas@grinn-global.com>
This commit is contained in:
parent
cb30cc5f8c
commit
5107691441
2 changed files with 79 additions and 34 deletions
|
@ -85,6 +85,7 @@ static struct gsm_modem {
|
||||||
bool mux_setup_done : 1;
|
bool mux_setup_done : 1;
|
||||||
bool setup_done : 1;
|
bool setup_done : 1;
|
||||||
bool attached : 1;
|
bool attached : 1;
|
||||||
|
bool modem_info_queried : 1;
|
||||||
|
|
||||||
void *user_data;
|
void *user_data;
|
||||||
|
|
||||||
|
@ -98,6 +99,7 @@ K_KERNEL_STACK_DEFINE(gsm_rx_stack, GSM_RX_STACK_SIZE);
|
||||||
|
|
||||||
struct k_thread gsm_rx_thread;
|
struct k_thread gsm_rx_thread;
|
||||||
static struct k_work_delayable rssi_work_handle;
|
static struct k_work_delayable rssi_work_handle;
|
||||||
|
static struct gsm_ppp_modem_info minfo;
|
||||||
|
|
||||||
#if defined(CONFIG_MODEM_GSM_ENABLE_CESQ_RSSI)
|
#if defined(CONFIG_MODEM_GSM_ENABLE_CESQ_RSSI)
|
||||||
/* helper macro to keep readability */
|
/* helper macro to keep readability */
|
||||||
|
@ -195,27 +197,6 @@ MODEM_CMD_DEFINE(on_cmd_atcmdinfo_cops)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_MODEM_SHELL)
|
|
||||||
#define MDM_MANUFACTURER_LENGTH 10
|
|
||||||
#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;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Provide modem info if modem shell is enabled. This can be shown with
|
* Provide modem info if modem shell is enabled. This can be shown with
|
||||||
* "modem list" shell command.
|
* "modem list" shell command.
|
||||||
|
@ -358,7 +339,6 @@ static int gsm_query_cellinfo(struct gsm_modem *gsm)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_MODEM_CELL_INFO */
|
#endif /* CONFIG_MODEM_CELL_INFO */
|
||||||
#endif /* CONFIG_MODEM_SHELL */
|
|
||||||
|
|
||||||
#if defined(CONFIG_MODEM_GSM_ENABLE_CESQ_RSSI)
|
#if defined(CONFIG_MODEM_GSM_ENABLE_CESQ_RSSI)
|
||||||
/*
|
/*
|
||||||
|
@ -420,6 +400,18 @@ static const struct modem_cmd read_rssi_cmd =
|
||||||
MODEM_CMD("+CSQ:", on_cmd_atcmdinfo_rssi_csq, 2U, ",");
|
MODEM_CMD("+CSQ:", on_cmd_atcmdinfo_rssi_csq, 2U, ",");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static const struct setup_cmd setup_modem_info_cmds[] = {
|
||||||
|
/* query modem info */
|
||||||
|
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, ""),
|
||||||
|
SETUP_CMD("AT+CGSN", "", on_cmd_atcmdinfo_imei, 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
|
||||||
|
};
|
||||||
|
|
||||||
static const struct setup_cmd setup_cmds[] = {
|
static const struct setup_cmd setup_cmds[] = {
|
||||||
/* no echo */
|
/* no echo */
|
||||||
SETUP_CMD_NOHANDLE("ATE0"),
|
SETUP_CMD_NOHANDLE("ATE0"),
|
||||||
|
@ -428,18 +420,6 @@ static const struct setup_cmd setup_cmds[] = {
|
||||||
/* extender errors in numeric form */
|
/* extender errors in numeric form */
|
||||||
SETUP_CMD_NOHANDLE("AT+CMEE=1"),
|
SETUP_CMD_NOHANDLE("AT+CMEE=1"),
|
||||||
|
|
||||||
#if defined(CONFIG_MODEM_SHELL)
|
|
||||||
/* query modem info */
|
|
||||||
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
|
|
||||||
|
|
||||||
/* disable unsolicited network registration codes */
|
/* disable unsolicited network registration codes */
|
||||||
SETUP_CMD_NOHANDLE("AT+CREG=0"),
|
SETUP_CMD_NOHANDLE("AT+CREG=0"),
|
||||||
|
|
||||||
|
@ -475,6 +455,30 @@ static const struct setup_cmd connect_cmds[] = {
|
||||||
SETUP_CMD_NOHANDLE("ATD*99#"),
|
SETUP_CMD_NOHANDLE("ATD*99#"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int gsm_query_modem_info(struct gsm_modem *gsm)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (gsm->modem_info_queried) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = modem_cmd_handler_setup_cmds_nolock(&gsm->context.iface,
|
||||||
|
&gsm->context.cmd_handler,
|
||||||
|
setup_modem_info_cmds,
|
||||||
|
ARRAY_SIZE(setup_modem_info_cmds),
|
||||||
|
&gsm->sem_response,
|
||||||
|
GSM_CMD_SETUP_TIMEOUT);
|
||||||
|
|
||||||
|
if (ret < 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
gsm->modem_info_queried = true;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int gsm_setup_mccmno(struct gsm_modem *gsm)
|
static int gsm_setup_mccmno(struct gsm_modem *gsm)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
@ -645,6 +649,13 @@ static void gsm_finalize_connection(struct gsm_modem *gsm)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = gsm_query_modem_info(gsm);
|
||||||
|
if (ret < 0) {
|
||||||
|
LOG_DBG("Unable to query modem information %d", ret);
|
||||||
|
(void)k_work_reschedule(&gsm->gsm_configure_work, K_SECONDS(1));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
attaching:
|
attaching:
|
||||||
/* Don't initialize PPP until we're attached to packet service */
|
/* Don't initialize PPP until we're attached to packet service */
|
||||||
ret = modem_cmd_send_nolock(&gsm->context.iface,
|
ret = modem_cmd_send_nolock(&gsm->context.iface,
|
||||||
|
@ -1059,6 +1070,13 @@ void gsm_ppp_register_modem_power_callback(const struct device *dev,
|
||||||
gsm->user_data = user_data;
|
gsm->user_data = user_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const struct gsm_ppp_modem_info *gsm_ppp_modem_info(const struct device *dev)
|
||||||
|
{
|
||||||
|
ARG_UNUSED(dev);
|
||||||
|
|
||||||
|
return &minfo;
|
||||||
|
}
|
||||||
|
|
||||||
static int gsm_init(const struct device *dev)
|
static int gsm_init(const struct device *dev)
|
||||||
{
|
{
|
||||||
struct gsm_modem *gsm = dev->data;
|
struct gsm_modem *gsm = dev->data;
|
||||||
|
|
|
@ -7,6 +7,24 @@
|
||||||
#ifndef ZEPHYR_INCLUDE_DRIVERS_MODEM_GSM_PPP_H_
|
#ifndef ZEPHYR_INCLUDE_DRIVERS_MODEM_GSM_PPP_H_
|
||||||
#define ZEPHYR_INCLUDE_DRIVERS_MODEM_GSM_PPP_H_
|
#define ZEPHYR_INCLUDE_DRIVERS_MODEM_GSM_PPP_H_
|
||||||
|
|
||||||
|
#define GSM_PPP_MDM_MANUFACTURER_LENGTH 10
|
||||||
|
#define GSM_PPP_MDM_MODEL_LENGTH 16
|
||||||
|
#define GSM_PPP_MDM_REVISION_LENGTH 64
|
||||||
|
#define GSM_PPP_MDM_IMEI_LENGTH 16
|
||||||
|
#define GSM_PPP_MDM_IMSI_LENGTH 16
|
||||||
|
#define GSM_PPP_MDM_ICCID_LENGTH 32
|
||||||
|
|
||||||
|
struct gsm_ppp_modem_info {
|
||||||
|
char mdm_manufacturer[GSM_PPP_MDM_MANUFACTURER_LENGTH];
|
||||||
|
char mdm_model[GSM_PPP_MDM_MODEL_LENGTH];
|
||||||
|
char mdm_revision[GSM_PPP_MDM_REVISION_LENGTH];
|
||||||
|
char mdm_imei[GSM_PPP_MDM_IMEI_LENGTH];
|
||||||
|
#if defined(CONFIG_MODEM_SIM_NUMBERS)
|
||||||
|
char mdm_imsi[GSM_PPP_MDM_IMSI_LENGTH];
|
||||||
|
char mdm_iccid[GSM_PPP_MDM_ICCID_LENGTH];
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
/** @cond INTERNAL_HIDDEN */
|
/** @cond INTERNAL_HIDDEN */
|
||||||
struct device;
|
struct device;
|
||||||
typedef void (*gsm_modem_power_cb)(const struct device *, void *);
|
typedef void (*gsm_modem_power_cb)(const struct device *, void *);
|
||||||
|
@ -32,4 +50,13 @@ void gsm_ppp_register_modem_power_callback(const struct device *dev,
|
||||||
gsm_modem_power_cb modem_off,
|
gsm_modem_power_cb modem_off,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get GSM modem information.
|
||||||
|
*
|
||||||
|
* @param dev: GSM modem device.
|
||||||
|
*
|
||||||
|
* @retval struct gsm_ppp_modem_info * pointer to modem information structure.
|
||||||
|
*/
|
||||||
|
const struct gsm_ppp_modem_info *gsm_ppp_modem_info(const struct device *dev);
|
||||||
|
|
||||||
#endif /* ZEPHYR_INCLUDE_DRIVERS_MODEM_GSM_PPP_H_ */
|
#endif /* ZEPHYR_INCLUDE_DRIVERS_MODEM_GSM_PPP_H_ */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue