Skip to content

Commit 4da21c0

Browse files
authored
Merge pull request #10463 from mirelachirica/wise_1570_tcp_endpoint_close
Cellular: Add WISE-1570 handling for socket closing URC
2 parents d212638 + 948f8b5 commit 4da21c0

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularStack.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ using namespace mbed_cellular_util;
2727
QUECTEL_BC95_CellularStack::QUECTEL_BC95_CellularStack(ATHandler &atHandler, int cid, nsapi_ip_stack_t stack_type) : AT_CellularStack(atHandler, cid, stack_type)
2828
{
2929
_at.set_urc_handler("+NSONMI:", mbed::Callback<void()>(this, &QUECTEL_BC95_CellularStack::urc_nsonmi));
30+
_at.set_urc_handler("+NSOCLI:", mbed::Callback<void()>(this, &QUECTEL_BC95_CellularStack::urc_nsocli));
3031
}
3132

3233
QUECTEL_BC95_CellularStack::~QUECTEL_BC95_CellularStack()
3334
{
35+
_at.set_urc_handler("+NSONMI:", NULL);
36+
_at.set_urc_handler("+NSOCLI:", NULL);
3437
}
3538

3639
nsapi_error_t QUECTEL_BC95_CellularStack::socket_listen(nsapi_socket_t handle, int backlog)
@@ -88,6 +91,28 @@ void QUECTEL_BC95_CellularStack::urc_nsonmi()
8891
}
8992
}
9093

94+
void QUECTEL_BC95_CellularStack::urc_nsocli()
95+
{
96+
int sock_id = _at.read_int();
97+
98+
const nsapi_error_t err = _at.get_last_error();
99+
100+
if (err != NSAPI_ERROR_OK) {
101+
return;
102+
}
103+
104+
CellularSocket *sock = find_socket(sock_id);
105+
106+
if (sock) {
107+
sock->closed = true;
108+
if (sock->_cb) {
109+
sock->_cb(sock->_data);
110+
}
111+
tr_info("Socket closed %d", sock_id);
112+
}
113+
}
114+
115+
91116
int QUECTEL_BC95_CellularStack::get_max_socket_count()
92117
{
93118
return BC95_SOCKET_MAX;
@@ -100,6 +125,11 @@ bool QUECTEL_BC95_CellularStack::is_protocol_supported(nsapi_protocol_t protocol
100125

101126
nsapi_error_t QUECTEL_BC95_CellularStack::socket_close_impl(int sock_id)
102127
{
128+
CellularSocket *sock = find_socket(sock_id);
129+
130+
if (sock && sock->closed) {
131+
return NSAPI_ERROR_OK;
132+
}
103133
_at.cmd_start("AT+NSOCL=");
104134
_at.write_int(sock_id);
105135
_at.cmd_stop_read_resp();

features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularStack.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class QUECTEL_BC95_CellularStack : public AT_CellularStack {
5757
private:
5858
// URC handlers
5959
void urc_nsonmi();
60+
void urc_nsocli();
6061
};
6162
} // namespace mbed
6263
#endif /* QUECTEL_BC95_CELLULARSTACK_H_ */

0 commit comments

Comments
 (0)