Skip to content

Commit d9b5b3c

Browse files
committed
drivers: modem: hl78xx: support per-command timeout in send API
Extend modem_dynamic_cmd_send() with a response_timeout parameter to allow callers to specify the overall script timeout per command. The previously hardcoded 1000 ms timeout is removed (set to 0 in params) and the script timeout is now driven by the passed-in value. Update all internal call sites to provide MDM_CMD_TIMEOUT (in seconds) and increase the default command timeout from 10 s to 40 s. Several chat scripts and configuration paths are updated accordingly. This improves reliability for long-running HL78xx operations and ensures consistent timeout handling across sockets, RAT/band configuration, APN setup, PDP activation, AirVantage DM session control, and TLS/TCP/UDP socket management. Signed-off-by: Zafer SEN <zafersn93@gmail.com>
1 parent ea03e63 commit d9b5b3c

File tree

6 files changed

+26
-19
lines changed

6 files changed

+26
-19
lines changed

drivers/modem/hl78xx/hl78xx.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ int modem_dynamic_cmd_send(
768768
modem_chat_script_callback script_user_callback,
769769
const uint8_t *cmd, uint16_t cmd_size,
770770
const struct modem_chat_match *response_matches, uint16_t matches_size,
771-
bool user_cmd
771+
uint16_t response_timeout, bool user_cmd
772772
)
773773
{
774774
int ret = 0;
@@ -784,7 +784,7 @@ int modem_dynamic_cmd_send(
784784
.request_size = cmd_size,
785785
.response_matches = response_matches,
786786
.response_matches_size = matches_size,
787-
.timeout = 1000,
787+
.timeout = 0, /* Has no effect */
788788
};
789789
struct modem_chat_script chat_script = {
790790
.name = "dynamic_script",
@@ -793,7 +793,7 @@ int modem_dynamic_cmd_send(
793793
.abort_matches = hl78xx_get_abort_matches(),
794794
.abort_matches_size = hl78xx_get_abort_matches_size(),
795795
.callback = script_user_callback,
796-
.timeout = 1000
796+
.timeout = response_timeout, /* overall script timeout */
797797
};
798798

799799
ret = k_mutex_lock(&data->tx_lock, K_NO_WAIT);

drivers/modem/hl78xx/hl78xx.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
#include "../modem_context.h"
2626
#include "../modem_socket.h"
2727
#include <stdint.h>
28-
29-
#define MDM_CMD_TIMEOUT (10) /*K_SECONDS*/
28+
/* clang-format off */
29+
#define MDM_CMD_TIMEOUT (40) /*K_SECONDS*/
3030
#define MDM_DNS_TIMEOUT (70) /*K_SECONDS*/
3131
#define MDM_CELL_BAND_SEARCH_TIMEOUT (60) /*K_SECONDS*/
3232
#define MDM_CMD_CONN_TIMEOUT (120) /*K_SECONDS*/
@@ -123,6 +123,8 @@
123123
(LOG_DBG(str, ##__VA_ARGS__)), \
124124
((void)0))
125125

126+
/* clang-format on */
127+
126128
/* HL78XX States */
127129
enum hl78xx_state {
128130
MODEM_HL78XX_STATE_IDLE = 0,
@@ -473,13 +475,14 @@ void iface_status_work_cb(struct hl78xx_data *data,
473475
* @param cmd_len Length of the command in bytes.
474476
* @param response_matches Array of expected response match patterns.
475477
* @param matches_size Number of elements in the response_matches array.
478+
* @param response_timeout Response timeout in seconds.
476479
*
477480
* @return 0 on success, negative errno code on failure.
478481
*/
479482
int modem_dynamic_cmd_send(struct hl78xx_data *data,
480483
modem_chat_script_callback script_user_callback, const uint8_t *cmd,
481484
uint16_t cmd_len, const struct modem_chat_match *response_matches,
482-
uint16_t matches_size, bool user_cmd);
485+
uint16_t matches_size, uint16_t response_timeout, bool user_cmd);
483486

484487
#define HASH_MULTIPLIER 37
485488
/**

drivers/modem/hl78xx/hl78xx_apis.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static int hl78xx_send_cmd(struct hl78xx_data *data, const char *cmd,
2828
return -EINVAL;
2929
}
3030
return modem_dynamic_cmd_send(data, chat_cb, cmd, (uint16_t)strlen(cmd), matches,
31-
match_count, true);
31+
match_count, MDM_CMD_TIMEOUT, true);
3232
}
3333

3434
int hl78xx_api_func_get_signal(const struct device *dev, const enum cellular_signal_type type,
@@ -292,7 +292,7 @@ int hl78xx_api_func_modem_dynamic_cmd_send(const struct device *dev, const char
292292
}
293293
/* respect provided matches_size and serialize modem access */
294294
return modem_dynamic_cmd_send(data, NULL, cmd, cmd_size, response_matches, matches_size,
295-
true);
295+
MDM_CMD_TIMEOUT, true);
296296
}
297297
#ifdef CONFIG_MODEM_HL78XX_AIRVANTAGE
298298
int hl78xx_start_airvantage_dm_session(const struct device *dev)

drivers/modem/hl78xx/hl78xx_cfg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ int hl78xx_rat_cfg(struct hl78xx_data *data, bool *modem_require_restart,
6161
}
6262
/* Query current rat */
6363
ret = modem_dynamic_cmd_send(data, NULL, cmd_ksrat_query, strlen(cmd_ksrat_query),
64-
hl78xx_get_ksrat_match(), 1, false);
64+
hl78xx_get_ksrat_match(), 1, MDM_CMD_TIMEOUT, false);
6565
if (ret < 0) {
6666
goto error;
6767
}

drivers/modem/hl78xx/hl78xx_chat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ MODEM_CHAT_SCRIPT_CMDS_DEFINE(hl78xx_post_restart_chat_script_cmds,
186186
);
187187

188188
MODEM_CHAT_SCRIPT_DEFINE(hl78xx_post_restart_chat_script, hl78xx_post_restart_chat_script_cmds,
189-
hl78xx_abort_matches, hl78xx_chat_callback_handler, 1000);
189+
hl78xx_abort_matches, hl78xx_chat_callback_handler, 12);
190190

191191
/* init_fail_script moved from hl78xx.c */
192192
MODEM_CHAT_SCRIPT_CMDS_DEFINE(init_fail_script_cmds,

drivers/modem/hl78xx/hl78xx_sockets.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,7 @@ void iface_status_work_cb(struct hl78xx_data *data, modem_chat_script_callback s
11791179
int ret = 0;
11801180

11811181
ret = modem_dynamic_cmd_send(data, script_user_callback, cmd, strlen(cmd),
1182-
hl78xx_get_cgdcontrdp_match(), 1, false);
1182+
hl78xx_get_cgdcontrdp_match(), 1, MDM_CMD_TIMEOUT, false);
11831183
if (ret < 0) {
11841184
LOG_ERR("Failed to send AT+CGCONTRDP command: %d", ret);
11851185
return;
@@ -1402,7 +1402,7 @@ static int send_tcp_or_tls_config(struct modem_socket *sock, uint16_t dst_port,
14021402
snprintk(cmd_buf, sizeof(cmd_buf), "AT+KTCPCFG=1,%d,\"%s\",%u,,,,%d,%s,0", mode,
14031403
socket_data->tls.hostname, dst_port, af, mode == 3 ? "0" : "");
14041404
ret = modem_dynamic_cmd_send(socket_data->mdata_global, NULL, cmd_buf, strlen(cmd_buf),
1405-
hl78xx_get_ktcpcfg_match(), 1, false);
1405+
hl78xx_get_ktcpcfg_match(), 1, MDM_CMD_TIMEOUT, false);
14061406
if (ret < 0 ||
14071407
socket_data->tcp_conn_status[HL78XX_TCP_STATUS_ID(sock->id)].is_created == false) {
14081408
LOG_ERR("%s ret:%d", cmd_buf, ret);
@@ -1430,7 +1430,9 @@ static int send_udp_config(const struct net_sockaddr *addr, struct hl78xx_socket
14301430
(addr->sa_family - 1), 0);
14311431

14321432
ret = modem_dynamic_cmd_send(socket_data->mdata_global, NULL, cmd_buf, strlen(cmd_buf),
1433-
hl78xx_get_kudpind_match(), hl78xx_get_kudpind_allow_matches_size(), MDM_CMD_TIMEOUT_MS, false);
1433+
hl78xx_get_kudpind_match(),
1434+
hl78xx_get_kudpind_allow_matches_size(), MDM_CMD_TIMEOUT,
1435+
false);
14341436
if (ret < 0) {
14351437
goto error;
14361438
}
@@ -1493,7 +1495,8 @@ static int socket_close(struct hl78xx_socket_data *socket_data, struct modem_soc
14931495
}
14941496
ret = modem_dynamic_cmd_send(socket_data->mdata_global, NULL, buf, strlen(buf),
14951497
hl78xx_get_sockets_allow_matches(),
1496-
hl78xx_get_sockets_allow_matches_size(), false);
1498+
hl78xx_get_sockets_allow_matches_size(), MDM_CMD_TIMEOUT,
1499+
false);
14971500
if (ret < 0) {
14981501
LOG_ERR("%s ret:%d", buf, ret);
14991502
}
@@ -1516,7 +1519,8 @@ static int socket_delete(struct hl78xx_socket_data *socket_data, struct modem_so
15161519
snprintk(buf, sizeof(buf), "AT+KTCPDEL=%d", sock->id);
15171520
ret = modem_dynamic_cmd_send(socket_data->mdata_global, NULL, buf, strlen(buf),
15181521
hl78xx_get_sockets_allow_matches(),
1519-
hl78xx_get_sockets_allow_matches_size(), false);
1522+
hl78xx_get_sockets_allow_matches_size(), MDM_CMD_TIMEOUT,
1523+
false);
15201524
if (ret < 0) {
15211525
LOG_ERR("%s ret:%d", buf, ret);
15221526
}
@@ -1649,7 +1653,7 @@ static int offload_connect(void *obj, const struct net_sockaddr *addr, net_sockl
16491653
/* send connect command */
16501654
snprintk(cmd_buf, sizeof(cmd_buf), "AT+KTCPCNX=%d", sock->id);
16511655
ret = modem_dynamic_cmd_send(socket_data->mdata_global, NULL, cmd_buf, strlen(cmd_buf),
1652-
hl78xx_get_ktcpind_match(), 1, false);
1656+
hl78xx_get_ktcpind_match(), 1, MDM_CMD_TIMEOUT, false);
16531657
if (ret < 0 ||
16541658
socket_data->tcp_conn_status[HL78XX_TCP_STATUS_ID(sock->id)].is_connected == false) {
16551659
sock->is_connected = false;
@@ -1784,7 +1788,7 @@ static void check_tcp_state_if_needed(struct hl78xx_socket_data *socket_data,
17841788
sock && sock->ip_proto == NET_IPPROTO_TCP) {
17851789
modem_dynamic_cmd_send(socket_data->mdata_global, NULL, check_ktcp_stat,
17861790
strlen(check_ktcp_stat), hl78xx_get_ktcp_state_match(), 1,
1787-
true);
1791+
MDM_CMD_TIMEOUT, true);
17881792
}
17891793
}
17901794

@@ -2016,7 +2020,7 @@ static ssize_t send_socket_data(void *obj, struct hl78xx_socket_data *socket_dat
20162020
}
20172021
ret = modem_dynamic_cmd_send(socket_data->mdata_global, NULL, cmd_buf, strlen(cmd_buf),
20182022
(const struct modem_chat_match *)hl78xx_get_connect_matches(),
2019-
hl78xx_get_connect_matches_size(), false);
2023+
hl78xx_get_connect_matches_size(), MDM_CMD_TIMEOUT, false);
20202024
if (ret < 0 || socket_data->socket_data_error) {
20212025
hl78xx_set_errno_from_code(ret);
20222026
ret = -1;
@@ -2417,7 +2421,7 @@ static ssize_t hl78xx_send_cert(struct hl78xx_socket_data *socket_data, const ch
24172421
}
24182422
ret = modem_dynamic_cmd_send(socket_data->mdata_global, NULL, send_buf, strlen(send_buf),
24192423
(const struct modem_chat_match *)hl78xx_get_connect_matches(),
2420-
hl78xx_get_connect_matches_size(), false);
2424+
hl78xx_get_connect_matches_size(), MDM_CMD_TIMEOUT, false);
24212425
if (ret < 0) {
24222426
LOG_ERR("Error sending AT command %d", ret);
24232427
}

0 commit comments

Comments
 (0)