Skip to content

Commit 35465ae

Browse files
committed
BG96: Add segmentation to TCP socket send
Unlike some other cellular modem drivers which use segmentation, the BG96 driver did not support sending of large TCP packets, i.e. maximum TCP packet size was restricted to 1400 bytes. This adds segmentation to the send function, so larger packets can be sent using the TCP socket.
1 parent 0c6753b commit 35465ae

File tree

1 file changed

+47
-21
lines changed

1 file changed

+47
-21
lines changed

connectivity/drivers/cellular/QUECTEL/BG96/QUECTEL_BG96_CellularStack.cpp

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,6 @@ nsapi_error_t QUECTEL_BG96_CellularStack::create_socket_impl(CellularSocket *soc
335335
nsapi_size_or_error_t QUECTEL_BG96_CellularStack::socket_sendto_impl(CellularSocket *socket, const SocketAddress &address,
336336
const void *data, nsapi_size_t size)
337337
{
338-
if (size > BG96_MAX_SEND_SIZE) {
339-
return NSAPI_ERROR_PARAMETER;
340-
}
341-
342338
if (_ip_ver_sendto != address.get_ip_version()) {
343339
_ip_ver_sendto = address.get_ip_version();
344340
socket_close_impl(socket->id);
@@ -358,29 +354,59 @@ nsapi_size_or_error_t QUECTEL_BG96_CellularStack::socket_sendto_impl(CellularSoc
358354

359355
// Send
360356
if (socket->proto == NSAPI_UDP) {
357+
if (size > BG96_MAX_SEND_SIZE) {
358+
return NSAPI_ERROR_PARAMETER;
359+
}
361360
char ipdot[NSAPI_IP_SIZE];
362361
ip2dot(address, ipdot);
363362
_at.cmd_start_stop("+QISEND", "=", "%d%d%s%d", socket->id, size,
364363
ipdot, address.get_port());
365-
} else {
366-
if (socket->tls_socket) {
367-
_at.cmd_start_stop("+QSSLSEND", "=", "%d%d", socket->id, size);
368-
} else {
369-
_at.cmd_start_stop("+QISEND", "=", "%d%d", socket->id, size);
364+
_at.resp_start(">");
365+
_at.write_bytes((uint8_t *)data, size);
366+
_at.resp_start();
367+
_at.set_stop_tag("\r\n");
368+
// Possible responses are SEND OK, SEND FAIL or ERROR.
369+
char response[16];
370+
response[0] = '\0';
371+
_at.read_string(response, sizeof(response));
372+
_at.resp_stop();
373+
if (strcmp(response, "SEND OK") != 0) {
374+
return NSAPI_ERROR_DEVICE_ERROR;
370375
}
371-
}
376+
} else {
377+
const char *buf = (const char *)data;
378+
nsapi_size_t blk = BG96_MAX_SEND_SIZE;
379+
nsapi_size_t count = size;
372380

373-
_at.resp_start(">");
374-
_at.write_bytes((uint8_t *)data, size);
375-
_at.resp_start();
376-
_at.set_stop_tag("\r\n");
377-
// Possible responses are SEND OK, SEND FAIL or ERROR.
378-
char response[16];
379-
response[0] = '\0';
380-
_at.read_string(response, sizeof(response));
381-
_at.resp_stop();
382-
if (strcmp(response, "SEND OK") != 0) {
383-
return NSAPI_ERROR_DEVICE_ERROR;
381+
while (count > 0) {
382+
if (count < blk) {
383+
blk = count;
384+
}
385+
386+
if (socket->tls_socket) {
387+
_at.cmd_start_stop("+QSSLSEND", "=", "%d%d", socket->id, blk);
388+
}
389+
390+
else {
391+
_at.cmd_start_stop("+QISEND", "=", "%d%d", socket->id, blk);
392+
}
393+
394+
_at.resp_start(">");
395+
_at.write_bytes((uint8_t *)buf, blk);
396+
_at.resp_start();
397+
_at.set_stop_tag("\r\n");
398+
// Possible responses are SEND OK, SEND FAIL or ERROR.
399+
char response[16];
400+
response[0] = '\0';
401+
_at.read_string(response, sizeof(response));
402+
_at.resp_stop();
403+
if (strcmp(response, "SEND OK") != 0) {
404+
return NSAPI_ERROR_DEVICE_ERROR;
405+
}
406+
407+
buf += blk;
408+
count -= blk;
409+
}
384410
}
385411

386412
// Get the sent count after sending

0 commit comments

Comments
 (0)