Skip to content

Commit f865b46

Browse files
committed
app: Use sm_at_host_get_current() instead of sock->pipe
For most cases, where we are going to send something to AT pipe, the in_datamode() should be called with the current AT context, not with the pipe reference where the socket was originally created. This is because if DLC1 creates a sockets and If DLC2 is used to AT#RECV, then in_datamode(sock->pipe) would return wrong data, because sock->pipe refers to DLC1 not the context where AT command is coming. Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
1 parent 74560b0 commit f865b46

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

app/src/sm_at_socket.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ static void auto_reception(struct sm_socket *sock)
246246
LOG_ERR("auto_reception() error: %d", err);
247247
return;
248248
}
249-
if (!in_datamode(sock->pipe)) {
249+
if (!in_datamode(sm_at_host_get_current())) {
250250
/* <CR><LF> after the data. */
251251
sm_at_send_str("\r\n");
252252
}
@@ -459,12 +459,8 @@ static void send_cb(const struct nrf_modem_sendcb_params *params)
459459
sock->send_ntf.bytes_sent = params->bytes_sent;
460460
atomic_set(&sock->send_ntf.ready, 1);
461461

462-
if (sock->pipe) {
463-
/* Schedule work to execute in AT context */
464-
sm_at_host_queue_idle_work(sock->pipe, &work);
465-
} else {
466-
k_work_submit_to_queue(&sm_work_q, &work);
467-
}
462+
/* Schedule work to execute in AT context */
463+
sm_at_host_queue_idle_work(sock->pipe, &work);
468464
}
469465

470466
static int set_so_send_cb(struct sm_socket *socket)
@@ -1052,7 +1048,7 @@ static int do_send(struct sm_socket *sock, const uint8_t *data, int len, int fla
10521048
sent += ret;
10531049
}
10541050

1055-
if (!in_datamode(sock->pipe)) {
1051+
if (!in_datamode(sm_at_host_get_current())) {
10561052
rsp_send("\r\n#XSEND: %d,%d,%d\r\n", sock->fd,
10571053
send_ntf ? AT_SOCKET_SEND_RESULT_NW_ACK_URC
10581054
: AT_SOCKET_SEND_RESULT_DEFAULT,
@@ -1116,7 +1112,7 @@ static int do_recv(struct sm_socket *sock, int timeout, int flags,
11161112
if (ret == 0) {
11171113
LOG_WRN("nrf_recv() return 0");
11181114
} else {
1119-
if (!in_datamode(sock->pipe)) {
1115+
if (!in_datamode(sm_at_host_get_current())) {
11201116
rsp_send("\r\n#XRECV: %d,%d,%d\r\n", sock->fd, mode, ret);
11211117
}
11221118

@@ -1188,7 +1184,7 @@ static int do_sendto(struct sm_socket *sock, const char *url, uint16_t port, con
11881184
LOG_ERR("Sent %u out of %u bytes. (%d)", sent, len, ret);
11891185
}
11901186

1191-
if (!in_datamode(sock->pipe)) {
1187+
if (!in_datamode(sm_at_host_get_current())) {
11921188
rsp_send("\r\n#XSENDTO: %d,%d,%d\r\n", sock->fd,
11931189
send_ntf ? AT_SOCKET_SEND_RESULT_NW_ACK_URC
11941190
: AT_SOCKET_SEND_RESULT_DEFAULT,
@@ -1228,7 +1224,7 @@ static int do_recvfrom(struct sm_socket *sock, int timeout, int flags,
12281224
if (ret == 0) {
12291225
LOG_WRN("nrf_recvfrom() return 0");
12301226
} else {
1231-
if (!in_datamode(sock->pipe)) {
1227+
if (!in_datamode(sm_at_host_get_current())) {
12321228
char peer_addr[NRF_INET6_ADDRSTRLEN] = {0};
12331229
uint16_t peer_port = 0;
12341230

0 commit comments

Comments
 (0)