Skip to content

Commit 104effe

Browse files
mike-scottnashif
authored andcommitted
drivers: modem: wncm14a2a: Fix timeout handling for AT@SOCKCONN
Socket-based API sends timeout K_FOREVER(-1) to net_context_connect() function where previously net_app APIs used an actual timeout value. Now that we've switched to socket-based APIs, we reveal poor handling for the timeout value which causes an error in the WNC-M14A2A driver due to math performed on the -1 value. Let's be sure to check for valid timeout values prior to performing math and then make sure it falls within the allowable range of values for the AT@SOCKCONN command (30 seconds to 360 seconds). Signed-off-by: Michael Scott <[email protected]>
1 parent a4cedf5 commit 104effe

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

drivers/modem/wncm14a2a.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,10 +1581,14 @@ static int offload_connect(struct net_context *context,
15811581
void *user_data)
15821582
{
15831583
int ret, dst_port = -1;
1584-
s32_t timeout_sec = timeout / MSEC_PER_SEC;
1584+
s32_t timeout_sec = -1; /* if not changed, this will be min timeout */
15851585
char buf[sizeof("AT@SOCKCONN=#,###.###.###.###,#####,#####\r")];
15861586
struct wncm14a2a_socket *sock;
15871587

1588+
if (timeout > 0) {
1589+
timeout_sec = timeout / MSEC_PER_SEC;
1590+
}
1591+
15881592
if (!context || !addr) {
15891593
return -EINVAL;
15901594
}
@@ -1628,10 +1632,11 @@ static int offload_connect(struct net_context *context,
16281632
return -EINVAL;
16291633
}
16301634

1631-
/* minimum timeout in seconds is 30 */
1632-
if (timeout_sec < 30) {
1633-
timeout_sec = 30;
1634-
}
1635+
/*
1636+
* AT@SOCKCONN timeout param has minimum value of 30 seconds and
1637+
* maximum value of 360 seconds, otherwise an error is generated
1638+
*/
1639+
timeout_sec = MIN(360, MAX(timeout_sec, 30));
16351640

16361641
snprintk(buf, sizeof(buf), "AT@SOCKCONN=%d,\"%s\",%d,%d",
16371642
sock->socket_id, wncm14a2a_sprint_ip_addr(addr),

0 commit comments

Comments
 (0)