@@ -145,6 +145,7 @@ static struct sm_socket *find_avail_socket(void)
145145
146146 return NULL ;
147147}
148+
148149static struct async_poll_ctx * poll_ctx_from_sock (struct sm_socket * sock )
149150{
150151 if (sock == NULL ) {
@@ -248,7 +249,7 @@ static void auto_reception(struct sm_socket *sock)
248249 }
249250 if (!in_datamode (sock -> pipe )) {
250251 /* <CR><LF> after the data. */
251- rsp_send ( "\r\n" );
252+ rsp_send_to ( sock -> pipe , "\r\n" );
252253 }
253254}
254255
@@ -360,12 +361,7 @@ void sm_at_socket_poll_work_handler(struct k_work *work)
360361 /* Do not send URC for the same events twice, unless send/recv is done. */
361362 sock -> async_poll .xapoll_events &= ~xapoll_events ;
362363 if (xapoll_events ) {
363- /* TODO: If we are in sm_work_q context, and not an idle handler
364- * then this "pipe" might be the wrong one.
365- * rsp_send() goes into "current" pipe, not the one associated
366- * with this poll_ctx.
367- */
368- rsp_send ("\r\n#XAPOLL: %d,%d\r\n" , sock -> fd , xapoll_events );
364+ rsp_send_to (pipe , "\r\n#XAPOLL: %d,%d\r\n" , sock -> fd , xapoll_events );
369365 }
370366 }
371367
@@ -459,12 +455,8 @@ static void send_cb(const struct nrf_modem_sendcb_params *params)
459455 sock -> send_ntf .bytes_sent = params -> bytes_sent ;
460456 atomic_set (& sock -> send_ntf .ready , 1 );
461457
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- }
458+ /* Schedule work to execute in AT context */
459+ sm_at_host_queue_idle_work (sock -> pipe , & work );
468460}
469461
470462static int set_so_send_cb (struct sm_socket * socket )
@@ -1052,7 +1044,7 @@ static int do_send(struct sm_socket *sock, const uint8_t *data, int len, int fla
10521044 sent += ret ;
10531045 }
10541046
1055- if (!in_datamode (sock -> pipe )) {
1047+ if (!in_datamode (sm_at_host_get_current () )) {
10561048 rsp_send ("\r\n#XSEND: %d,%d,%d\r\n" , sock -> fd ,
10571049 send_ntf ? AT_SOCKET_SEND_RESULT_NW_ACK_URC
10581050 : AT_SOCKET_SEND_RESULT_DEFAULT ,
@@ -1080,7 +1072,7 @@ static int data_send_hex(struct sm_socket *sock, const uint8_t *buf, int recv_le
10801072 LOG_ERR ("Failed to convert binary data to hex string" );
10811073 return - EINVAL ;
10821074 }
1083- data_send (hex_buf , size );
1075+ data_send (sock -> pipe , hex_buf , size );
10841076 consumed += size / 2 ; /* size is in hex string length */
10851077 if (recv_len - consumed < data_len ) {
10861078 data_len = recv_len - consumed ;
@@ -1117,7 +1109,7 @@ static int do_recv(struct sm_socket *sock, int timeout, int flags,
11171109 LOG_WRN ("nrf_recv() return 0" );
11181110 } else {
11191111 if (!in_datamode (sock -> pipe )) {
1120- rsp_send ( "\r\n#XRECV: %d,%d,%d\r\n" , sock -> fd , mode , ret );
1112+ rsp_send_to ( sock -> pipe , "\r\n#XRECV: %d,%d,%d\r\n" , sock -> fd , mode , ret );
11211113 }
11221114
11231115 if (mode == AT_SOCKET_MODE_HEX ) {
@@ -1126,7 +1118,7 @@ static int do_recv(struct sm_socket *sock, int timeout, int flags,
11261118 return ret ;
11271119 }
11281120 } else {
1129- data_send (sm_data_buf , ret );
1121+ data_send (sock -> pipe , sm_data_buf , ret );
11301122 }
11311123 ret = 0 ;
11321124
@@ -1189,7 +1181,7 @@ static int do_sendto(struct sm_socket *sock, const char *url, uint16_t port, con
11891181 }
11901182
11911183 if (!in_datamode (sock -> pipe )) {
1192- rsp_send ( "\r\n#XSENDTO: %d,%d,%d\r\n" , sock -> fd ,
1184+ rsp_send_to ( sock -> pipe , "\r\n#XSENDTO: %d,%d,%d\r\n" , sock -> fd ,
11931185 send_ntf ? AT_SOCKET_SEND_RESULT_NW_ACK_URC
11941186 : AT_SOCKET_SEND_RESULT_DEFAULT ,
11951187 sent );
@@ -1233,7 +1225,7 @@ static int do_recvfrom(struct sm_socket *sock, int timeout, int flags,
12331225 uint16_t peer_port = 0 ;
12341226
12351227 util_get_peer_addr (& remote , peer_addr , & peer_port );
1236- rsp_send ( "\r\n#XRECVFROM: %d,%d,%d,\"%s\",%d\r\n" , sock -> fd , mode ,
1228+ rsp_send_to ( sock -> pipe , "\r\n#XRECVFROM: %d,%d,%d,\"%s\",%d\r\n" , sock -> fd , mode ,
12371229 ret , peer_addr , peer_port );
12381230 }
12391231
@@ -1243,7 +1235,7 @@ static int do_recvfrom(struct sm_socket *sock, int timeout, int flags,
12431235 return ret ;
12441236 }
12451237 } else {
1246- data_send (sm_data_buf , ret );
1238+ data_send (sock -> pipe , sm_data_buf , ret );
12471239 }
12481240
12491241 update_poll_events (sock , NRF_POLLIN , true);
@@ -1709,6 +1701,7 @@ STATIC int handle_at_connect(enum at_parser_cmd_type cmd_type, struct at_parser
17091701 if (err ) {
17101702 return err ;
17111703 }
1704+ sock -> pipe = sm_at_host_get_current_pipe ();
17121705 err = do_connect (sock , url , port );
17131706 break ;
17141707
@@ -1749,6 +1742,7 @@ STATIC int handle_at_send(enum at_parser_cmd_type cmd_type, struct at_parser *pa
17491742 if (err ) {
17501743 return err ;
17511744 }
1745+ sock -> pipe = sm_at_host_get_current_pipe ();
17521746 if (mode == AT_SOCKET_MODE_UNFORMATTED || mode == AT_SOCKET_MODE_HEX ) {
17531747 if (param_count > 4 ) {
17541748 err = at_parser_string_ptr_get (parser , 4 , & str_ptr , & size );
@@ -1846,6 +1840,7 @@ STATIC int handle_at_recv(enum at_parser_cmd_type cmd_type, struct at_parser *pa
18461840 return - ENOBUFS ;
18471841 }
18481842 }
1843+ sock -> pipe = sm_at_host_get_current_pipe ();
18491844 err = do_recv (sock , timeout , flags , mode , data_len );
18501845 break ;
18511846
@@ -1896,6 +1891,7 @@ STATIC int handle_at_sendto(enum at_parser_cmd_type cmd_type, struct at_parser *
18961891 if (err ) {
18971892 return err ;
18981893 }
1894+ sock -> pipe = sm_at_host_get_current_pipe ();
18991895 if (mode == AT_SOCKET_MODE_UNFORMATTED || mode == AT_SOCKET_MODE_HEX ) {
19001896 if (param_count > 6 ) {
19011897 err = at_parser_string_ptr_get (parser , 6 , & str_ptr , & size );
@@ -1995,6 +1991,7 @@ STATIC int handle_at_recvfrom(enum at_parser_cmd_type cmd_type, struct at_parser
19951991 return - ENOBUFS ;
19961992 }
19971993 }
1994+ sock -> pipe = sm_at_host_get_current_pipe ();
19981995 err = do_recvfrom (sock , timeout , flags , mode , data_len );
19991996 break ;
20001997
@@ -2123,17 +2120,18 @@ static void xapoll_read_response(void)
21232120static int set_xapoll_events (struct sm_socket * sock , uint8_t events )
21242121{
21252122 int ret ;
2123+ struct modem_pipe * pipe = sm_at_host_get_current_pipe ();
2124+ struct async_poll_ctx * poll_ctx =
2125+ sm_at_host_get_async_poll_ctx (pipe );
21262126
21272127 if (sock ) {
2128+ sock -> pipe = pipe ;
21282129 /* Set events for a specific socket. */
21292130 sock -> async_poll .xapoll_events_requested = events ;
21302131 return update_poll_events (sock , events , true);
21312132 }
21322133
21332134 /* Set events for all sockets in this context */
2134- struct modem_pipe * pipe = sm_at_host_get_current_pipe ();
2135- struct async_poll_ctx * poll_ctx =
2136- sm_at_host_get_async_poll_ctx (pipe );
21372135 poll_ctx -> xapoll_events_requested = events ;
21382136 for (int i = 0 ; i < SM_MAX_SOCKET_COUNT ; i ++ ) {
21392137 if (socks [i ].fd != INVALID_SOCKET && socks [i ].pipe == pipe ) {
@@ -2258,6 +2256,7 @@ STATIC int handle_at_recvcfg(enum at_parser_cmd_type cmd_type, struct at_parser
22582256 return - EINVAL ;
22592257 }
22602258 if (sock ) {
2259+ sock -> pipe = pipe ;
22612260 sock -> async_poll .adr_flags = flags ;
22622261 sock -> async_poll .adr_hex = hex_mode != 0 ;
22632262 err = update_poll_events (sock , NRF_POLLIN , false);
0 commit comments