drivers: modem: Fix PDP context management for BG9X
The PDP context might be active. If that's the case, the AT+QIACT command returns an error. It's then not possible to succeed at setting up the module. Furthermore, we apply the logic described in the Quectel Documentation : - If there is an issue 3 consecutive times on activating/deactivating the context, we restart the module. - If the AT+QIDEAT command returns an error, we restart the module. This PR is bug-fix aimed. We leave parameterization of context ID for future enhancement. Signed-off-by: Thomas LE ROUX <thomas.leroux@smile.fr>
This commit is contained in:
parent
ae2836e867
commit
f360718d0b
2 changed files with 44 additions and 6 deletions
|
@ -961,6 +961,46 @@ static const struct setup_cmd setup_cmds[] = {
|
|||
SETUP_CMD_NOHANDLE("AT+QICSGP=1,1,\"" MDM_APN "\",\"" MDM_USERNAME "\", \"" MDM_PASSWORD "\",1"),
|
||||
};
|
||||
|
||||
/* Func: modem_pdp_context_active
|
||||
* Desc: This helper function is called from modem_setup, and is
|
||||
* used to open the PDP context. If there is trouble activating the
|
||||
* PDP context, we try to deactive and reactive MDM_PDP_ACT_RETRY_COUNT times.
|
||||
* If it fails, we return an error.
|
||||
*/
|
||||
static int modem_pdp_context_activate(void)
|
||||
{
|
||||
int ret;
|
||||
int retry_count = 0;
|
||||
|
||||
ret = modem_cmd_send(&mctx.iface, &mctx.cmd_handler,
|
||||
NULL, 0U, "AT+QIACT=1", &mdata.sem_response,
|
||||
MDM_CMD_TIMEOUT);
|
||||
|
||||
/* If there is trouble activating the PDP context, we try to deactivate/reactive it. */
|
||||
while (ret == -EIO && retry_count < MDM_PDP_ACT_RETRY_COUNT) {
|
||||
ret = modem_cmd_send(&mctx.iface, &mctx.cmd_handler,
|
||||
NULL, 0U, "AT+QIDEACT=1", &mdata.sem_response,
|
||||
MDM_CMD_TIMEOUT);
|
||||
|
||||
/* If there's any error for AT+QIDEACT, restart the module. */
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = modem_cmd_send(&mctx.iface, &mctx.cmd_handler,
|
||||
NULL, 0U, "AT+QIACT=1", &mdata.sem_response,
|
||||
MDM_CMD_TIMEOUT);
|
||||
|
||||
retry_count++;
|
||||
}
|
||||
|
||||
if (ret == -EIO && retry_count >= MDM_PDP_ACT_RETRY_COUNT) {
|
||||
LOG_ERR("Retried activating/deactivating too many times.");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Func: modem_setup
|
||||
* Desc: This function is used to setup the modem from zero. The idea
|
||||
* is that this function will be called right after the modem is
|
||||
|
@ -1032,13 +1072,10 @@ restart_rssi:
|
|||
&mdata.rssi_query_work,
|
||||
K_SECONDS(RSSI_TIMEOUT_SECS));
|
||||
|
||||
/* Once the network is ready, activate PDP context. */
|
||||
ret = modem_cmd_send(&mctx.iface, &mctx.cmd_handler,
|
||||
NULL, 0U, "AT+QIACT=1", &mdata.sem_response,
|
||||
MDM_CMD_TIMEOUT);
|
||||
|
||||
/* Retry or Possibly Exit. */
|
||||
/* Once the network is ready, we try to activate the PDP context. */
|
||||
ret = modem_pdp_context_activate();
|
||||
if (ret < 0 && init_retry_count++ < MDM_INIT_RETRY_COUNT) {
|
||||
LOG_ERR("Error activating modem with pdp context");
|
||||
goto restart;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#define MDM_BASE_SOCKET_NUM 0
|
||||
#define MDM_NETWORK_RETRY_COUNT 10
|
||||
#define MDM_INIT_RETRY_COUNT 10
|
||||
#define MDM_PDP_ACT_RETRY_COUNT 3
|
||||
#define MDM_WAIT_FOR_RSSI_COUNT 10
|
||||
#define MDM_WAIT_FOR_RSSI_DELAY K_SECONDS(2)
|
||||
#define BUF_ALLOC_TIMEOUT K_SECONDS(1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue