Skip to content

Commit f360718

Browse files
Thomas LE ROUXjukkar
authored andcommitted
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 <[email protected]>
1 parent ae2836e commit f360718

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

drivers/modem/quectel-bg9x.c

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,46 @@ static const struct setup_cmd setup_cmds[] = {
961961
SETUP_CMD_NOHANDLE("AT+QICSGP=1,1,\"" MDM_APN "\",\"" MDM_USERNAME "\", \"" MDM_PASSWORD "\",1"),
962962
};
963963

964+
/* Func: modem_pdp_context_active
965+
* Desc: This helper function is called from modem_setup, and is
966+
* used to open the PDP context. If there is trouble activating the
967+
* PDP context, we try to deactive and reactive MDM_PDP_ACT_RETRY_COUNT times.
968+
* If it fails, we return an error.
969+
*/
970+
static int modem_pdp_context_activate(void)
971+
{
972+
int ret;
973+
int retry_count = 0;
974+
975+
ret = modem_cmd_send(&mctx.iface, &mctx.cmd_handler,
976+
NULL, 0U, "AT+QIACT=1", &mdata.sem_response,
977+
MDM_CMD_TIMEOUT);
978+
979+
/* If there is trouble activating the PDP context, we try to deactivate/reactive it. */
980+
while (ret == -EIO && retry_count < MDM_PDP_ACT_RETRY_COUNT) {
981+
ret = modem_cmd_send(&mctx.iface, &mctx.cmd_handler,
982+
NULL, 0U, "AT+QIDEACT=1", &mdata.sem_response,
983+
MDM_CMD_TIMEOUT);
984+
985+
/* If there's any error for AT+QIDEACT, restart the module. */
986+
if (ret != 0) {
987+
return ret;
988+
}
989+
990+
ret = modem_cmd_send(&mctx.iface, &mctx.cmd_handler,
991+
NULL, 0U, "AT+QIACT=1", &mdata.sem_response,
992+
MDM_CMD_TIMEOUT);
993+
994+
retry_count++;
995+
}
996+
997+
if (ret == -EIO && retry_count >= MDM_PDP_ACT_RETRY_COUNT) {
998+
LOG_ERR("Retried activating/deactivating too many times.");
999+
}
1000+
1001+
return ret;
1002+
}
1003+
9641004
/* Func: modem_setup
9651005
* Desc: This function is used to setup the modem from zero. The idea
9661006
* is that this function will be called right after the modem is
@@ -1032,13 +1072,10 @@ static int modem_setup(void)
10321072
&mdata.rssi_query_work,
10331073
K_SECONDS(RSSI_TIMEOUT_SECS));
10341074

1035-
/* Once the network is ready, activate PDP context. */
1036-
ret = modem_cmd_send(&mctx.iface, &mctx.cmd_handler,
1037-
NULL, 0U, "AT+QIACT=1", &mdata.sem_response,
1038-
MDM_CMD_TIMEOUT);
1039-
1040-
/* Retry or Possibly Exit. */
1075+
/* Once the network is ready, we try to activate the PDP context. */
1076+
ret = modem_pdp_context_activate();
10411077
if (ret < 0 && init_retry_count++ < MDM_INIT_RETRY_COUNT) {
1078+
LOG_ERR("Error activating modem with pdp context");
10421079
goto restart;
10431080
}
10441081

drivers/modem/quectel-bg9x.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#define MDM_BASE_SOCKET_NUM 0
3737
#define MDM_NETWORK_RETRY_COUNT 10
3838
#define MDM_INIT_RETRY_COUNT 10
39+
#define MDM_PDP_ACT_RETRY_COUNT 3
3940
#define MDM_WAIT_FOR_RSSI_COUNT 10
4041
#define MDM_WAIT_FOR_RSSI_DELAY K_SECONDS(2)
4142
#define BUF_ALLOC_TIMEOUT K_SECONDS(1)

0 commit comments

Comments
 (0)