Skip to content

Commit b94fe13

Browse files
authored
Merge pull request ARMmbed#14288 from boraozgen/bg96-socket-send-segmentation
BG96: Add segmentation to TCP socket send
2 parents d13aaf4 + 35465ae commit b94fe13

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
@@ -370,10 +370,6 @@ nsapi_error_t QUECTEL_BG96_CellularStack::create_socket_impl(CellularSocket *soc
370370
nsapi_size_or_error_t QUECTEL_BG96_CellularStack::socket_sendto_impl(CellularSocket *socket, const SocketAddress &address,
371371
const void *data, nsapi_size_t size)
372372
{
373-
if (size > BG96_MAX_SEND_SIZE) {
374-
return NSAPI_ERROR_PARAMETER;
375-
}
376-
377373
if (_ip_ver_sendto != address.get_ip_version()) {
378374
_ip_ver_sendto = address.get_ip_version();
379375
socket_close_impl(socket->id);
@@ -393,29 +389,59 @@ nsapi_size_or_error_t QUECTEL_BG96_CellularStack::socket_sendto_impl(CellularSoc
393389

394390
// Send
395391
if (socket->proto == NSAPI_UDP) {
392+
if (size > BG96_MAX_SEND_SIZE) {
393+
return NSAPI_ERROR_PARAMETER;
394+
}
396395
char ipdot[NSAPI_IP_SIZE];
397396
ip2dot(address, ipdot);
398397
_at.cmd_start_stop("+QISEND", "=", "%d%d%s%d", socket->id, size,
399398
ipdot, address.get_port());
400-
} else {
401-
if (socket->tls_socket) {
402-
_at.cmd_start_stop("+QSSLSEND", "=", "%d%d", socket->id, size);
403-
} else {
404-
_at.cmd_start_stop("+QISEND", "=", "%d%d", socket->id, size);
399+
_at.resp_start(">");
400+
_at.write_bytes((uint8_t *)data, size);
401+
_at.resp_start();
402+
_at.set_stop_tag("\r\n");
403+
// Possible responses are SEND OK, SEND FAIL or ERROR.
404+
char response[16];
405+
response[0] = '\0';
406+
_at.read_string(response, sizeof(response));
407+
_at.resp_stop();
408+
if (strcmp(response, "SEND OK") != 0) {
409+
return NSAPI_ERROR_DEVICE_ERROR;
405410
}
406-
}
411+
} else {
412+
const char *buf = (const char *)data;
413+
nsapi_size_t blk = BG96_MAX_SEND_SIZE;
414+
nsapi_size_t count = size;
407415

408-
_at.resp_start(">");
409-
_at.write_bytes((uint8_t *)data, size);
410-
_at.resp_start();
411-
_at.set_stop_tag("\r\n");
412-
// Possible responses are SEND OK, SEND FAIL or ERROR.
413-
char response[16];
414-
response[0] = '\0';
415-
_at.read_string(response, sizeof(response));
416-
_at.resp_stop();
417-
if (strcmp(response, "SEND OK") != 0) {
418-
return NSAPI_ERROR_DEVICE_ERROR;
416+
while (count > 0) {
417+
if (count < blk) {
418+
blk = count;
419+
}
420+
421+
if (socket->tls_socket) {
422+
_at.cmd_start_stop("+QSSLSEND", "=", "%d%d", socket->id, blk);
423+
}
424+
425+
else {
426+
_at.cmd_start_stop("+QISEND", "=", "%d%d", socket->id, blk);
427+
}
428+
429+
_at.resp_start(">");
430+
_at.write_bytes((uint8_t *)buf, blk);
431+
_at.resp_start();
432+
_at.set_stop_tag("\r\n");
433+
// Possible responses are SEND OK, SEND FAIL or ERROR.
434+
char response[16];
435+
response[0] = '\0';
436+
_at.read_string(response, sizeof(response));
437+
_at.resp_stop();
438+
if (strcmp(response, "SEND OK") != 0) {
439+
return NSAPI_ERROR_DEVICE_ERROR;
440+
}
441+
442+
buf += blk;
443+
count -= blk;
444+
}
419445
}
420446

421447
// Get the sent count after sending

0 commit comments

Comments
 (0)