Skip to content

Commit acbde4e

Browse files
authored
Merge pull request #8841 from VeijoPesonen/bugfix-restrict_send_size2
Bugfix restrict send size; namespace fixes; ATCmdParser::read return value fix
2 parents 179098d + fefef0d commit acbde4e

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

components/wifi/esp8266-driver/ESP8266/ESP8266.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727

2828
#define TRACE_GROUP "ESPA" // ESP8266 AT layer
2929

30-
using namespace mbed;
31-
3230
#define ESP8266_DEFAULT_BAUD_RATE 115200
3331
#define ESP8266_ALL_SOCKET_IDS -1
3432

@@ -550,6 +548,16 @@ bool ESP8266::dns_lookup(const char *name, char *ip)
550548

551549
nsapi_error_t ESP8266::send(int id, const void *data, uint32_t amount)
552550
{
551+
// +CIPSEND supports up to 2048 bytes at a time
552+
// Data stream can be truncated
553+
if (amount > 2048 && _sock_i[id].proto == NSAPI_TCP) {
554+
amount = 2048;
555+
// Datagram must stay intact
556+
} else if (amount > 2048 && _sock_i[id].proto == NSAPI_UDP) {
557+
tr_debug("UDP datagram maximum size is 2048");
558+
return NSAPI_ERROR_PARAMETER;
559+
}
560+
553561
//May take a second try if device is busy
554562
for (unsigned i = 0; i < 2; i++) {
555563
_smutex.lock();
@@ -954,7 +962,7 @@ void ESP8266::_oob_tcp_data_hdlr()
954962
return;
955963
}
956964

957-
if (!_parser.read(_sock_i[_sock_active_id].tcp_data, len)) {
965+
if (_parser.read(_sock_i[_sock_active_id].tcp_data, len) == -1) {
958966
return;
959967
}
960968

components/wifi/esp8266-driver/ESP8266Interface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ const char *ESP8266Interface::get_ip_address()
241241
}
242242

243243
const char *ip_buff = _esp.ip_addr();
244-
if (!ip_buff || std::strcmp(ip_buff, "0.0.0.0") == 0) {
244+
if (!ip_buff || strcmp(ip_buff, "0.0.0.0") == 0) {
245245
return NULL;
246246
}
247247

0 commit comments

Comments
 (0)