diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 7de329e48..2ad59d3f8 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -156,7 +156,6 @@ jobs: - libraries/USBHOST - libraries/USBMSD/examples/AccessFlashAsUSBDisk - libraries/WiFi - - libraries/GSM - ~/Arduino/libraries/ArduinoBLE - board: fqbn: arduino:mbed:nicla_voice diff --git a/libraries/GSM/examples/GSMSSLClient/GSMSSLClient.ino b/libraries/GSM/examples/GSMSSLClient/GSMSSLClient.ino new file mode 100644 index 000000000..5d35c7d62 --- /dev/null +++ b/libraries/GSM/examples/GSMSSLClient/GSMSSLClient.ino @@ -0,0 +1,66 @@ +/* + GSMSSLlient + + This sketch connects to a website (https://ifconfig.me) + using the Portenta CAT.M1/NB IoT GNSS Shield and TLS. + + */ + +#include + +#include "arduino_secrets.h" +char pin[] = SECRET_PIN; +char apn[] = SECRET_APN; +char username[] = SECRET_USERNAME; +char pass[] = SECRET_PASSWORD; + +const char server[] = "ifconfig.me"; +const char* ip_address; +int port = 443; +GSMSSLClient client; + +void setup() { + Serial.begin(115200); + while(!Serial) {} + Serial.println("Starting Carrier Network registration"); + if(!GSM.begin(pin, apn, username, pass, CATM1, BAND_3 | BAND_20 | BAND_19)){ + Serial.println("The board was not able to register to the network..."); + // do nothing forevermore: + while(1); + } + Serial.println("\nStarting connection to server..."); + // if you get a connection, report back via serial: + if (client.connect(server, port)) { + Serial.println("connected to server"); + // Make a HTTP request: + client.println("GET /ip HTTP/1.1"); + client.print("Host: "); + client.println(server); + client.println("Connection: close"); + client.println(); + } else { + Serial.println("unable to connect to server"); + } + +} + +void loop() { + + // if there are incoming bytes available + // from the server, read them and print them: + while (client.available()) { + char c = client.read(); + Serial.write(c); + } + + // if the server's disconnected, stop the client: + if (!client.connected()) { + Serial.println(); + Serial.println("disconnecting from server."); + client.stop(); + + // do nothing forevermore: + while (true); + } + +} diff --git a/libraries/GSM/examples/GSMSSLClient/arduino_secrets.h b/libraries/GSM/examples/GSMSSLClient/arduino_secrets.h new file mode 100644 index 000000000..8c5842fa6 --- /dev/null +++ b/libraries/GSM/examples/GSMSSLClient/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_PIN "" +#define SECRET_APN "" +#define SECRET_USERNAME "" +#define SECRET_PASSWORD "" diff --git a/libraries/GSM/src/GSM.cpp b/libraries/GSM/src/GSM.cpp index 1da0d49b3..19305540b 100644 --- a/libraries/GSM/src/GSM.cpp +++ b/libraries/GSM/src/GSM.cpp @@ -1,15 +1,34 @@ +/* + GSM.cpp - Library for GSM on mbed platforms. + Copyright (c) 2011-2023 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + #include "GSM.h" #include "mbed.h" #include "CellularLog.h" +#include "CellularDevice.h" #include "CellularContext.h" #include "CellularInterface.h" #include "GEMALTO_CINTERION_CellularStack.h" #define MAXRETRY 3 -bool _cmuxEnable = false; -arduino::CMUXClass * arduino::CMUXClass::get_default_instance() +arduino::CMUXClass *arduino::CMUXClass::get_default_instance() { static mbed::UnbufferedSerial serial(MBED_CONF_GEMALTO_CINTERION_TX, MBED_CONF_GEMALTO_CINTERION_RX, 115200); serial.set_flow_control(mbed::SerialBase::RTSCTS_SW, MBED_CONF_GEMALTO_CINTERION_CTS, NC); @@ -19,24 +38,24 @@ arduino::CMUXClass * arduino::CMUXClass::get_default_instance() mbed::CellularDevice *mbed::CellularDevice::get_default_instance() { - static auto cmux = arduino::CMUXClass::get_default_instance(); - static mbed::GEMALTO_CINTERION device(cmux->get_serial(0)); - nextSerialPort++; - device.enableCMUXChannel = mbed::callback(cmux, &arduino::CMUXClass::enableCMUXChannel); - return &device; + static auto cmux = arduino::CMUXClass::get_default_instance(); + static mbed::GEMALTO_CINTERION device(cmux->get_serial(0)); + nextSerialPort++; + device.enableCMUXChannel = mbed::callback(cmux, &arduino::CMUXClass::enableCMUXChannel); + return &device; } int arduino::GSMClass::begin(const char* pin, const char* apn, const char* username, const char* password, RadioAccessTechnologyType rat, uint32_t band, bool restart) { if(restart || isCmuxEnable()) { - pinMode(PJ_10, OUTPUT); - digitalWrite(PJ_10, HIGH); + pinMode(MBED_CONF_GEMALTO_CINTERION_RST, OUTPUT); + digitalWrite(MBED_CONF_GEMALTO_CINTERION_RST, HIGH); delay(800); - digitalWrite(PJ_10, LOW); - pinMode(PJ_7, OUTPUT); - digitalWrite(PJ_7, LOW); + digitalWrite(MBED_CONF_GEMALTO_CINTERION_RST, LOW); + pinMode(MBED_CONF_GEMALTO_CINTERION_ON, OUTPUT); + digitalWrite(MBED_CONF_GEMALTO_CINTERION_ON, LOW); delay(1); - digitalWrite(PJ_7, HIGH); + digitalWrite(MBED_CONF_GEMALTO_CINTERION_ON, HIGH); delay(1); // this timer is to make sure that at boottime and when the CMUX is used, // ^SYSTART is received in time to avoid stranger behaviour @@ -50,7 +69,7 @@ int arduino::GSMClass::begin(const char* pin, const char* apn, const char* usern printf("Invalid context\n"); return 0; } - pinMode(PJ_7, INPUT_PULLDOWN); + pinMode(MBED_CONF_GEMALTO_CINTERION_ON, INPUT_PULLDOWN); static mbed::DigitalOut rts(MBED_CONF_GEMALTO_CINTERION_RTS, 0); @@ -99,11 +118,11 @@ int arduino::GSMClass::begin(const char* pin, const char* apn, const char* usern return connect_status == NSAPI_ERROR_OK ? 1 : 0; } -void arduino::GSMClass::enableCmux(){ +void arduino::GSMClass::enableCmux() { _cmuxGSMenable = true; } -bool arduino::GSMClass::isCmuxEnable(){ +bool arduino::GSMClass::isCmuxEnable() { return _cmuxGSMenable; } @@ -130,53 +149,16 @@ bool arduino::GSMClass::setTime(unsigned long const epoch, int const timezone) return _device->set_time(epoch, timezone); } -static PlatformMutex trace_mutex; - -static void trace_wait() +bool arduino::GSMClass::isConnected() { - trace_mutex.lock(); -} - -static void trace_release() -{ - trace_mutex.unlock(); -} - -static char* trace_time(size_t ss) -{ - static char time_st[50]; - auto ms = std::chrono::time_point_cast(rtos::Kernel::Clock::now()).time_since_epoch().count(); - //snprintf(time_st, 49, "[%08llums]", ms); - snprintf(time_st, 1, "\n"); - return time_st; -} - -static Stream* trace_stream = nullptr; -static void arduino_print(const char* c) { - if (trace_stream) { - trace_stream->println(c); + if (_context) { + return _context->is_connected(); + } else { + return false; } } -void arduino::GSMClass::debug(Stream& stream) { - -#if MBED_CONF_MBED_TRACE_ENABLE - - mbed_trace_init(); - trace_stream = &stream; - mbed_trace_print_function_set(arduino_print); - mbed_trace_prefix_function_set( &trace_time ); - - mbed_trace_mutex_wait_function_set(trace_wait); - mbed_trace_mutex_release_function_set(trace_release); - - mbed_cellular_trace::mutex_wait_function_set(trace_wait); - mbed_cellular_trace::mutex_release_function_set(trace_release); - -#endif - -} NetworkInterface* arduino::GSMClass::getNetwork() { return _context; diff --git a/libraries/GSM/src/GSM.h b/libraries/GSM/src/GSM.h index 8b48d3e84..60339fb80 100644 --- a/libraries/GSM/src/GSM.h +++ b/libraries/GSM/src/GSM.h @@ -1,14 +1,17 @@ /* GSM.h - Library for GSM on mbed platforms. - Copyright (c) 2011-2021 Arduino LLC. All right reserved. + Copyright (c) 2011-2023 Arduino LLC. All right reserved. + This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA @@ -30,10 +33,28 @@ #include "CMUXClass.h" #include "PTYSerial.h" -#define MBED_CONF_GEMALTO_CINTERION_TX PA_0 -#define MBED_CONF_GEMALTO_CINTERION_RX PI_9 -#define MBED_CONF_GEMALTO_CINTERION_RTS PI_10 -#define MBED_CONF_GEMALTO_CINTERION_CTS PI_13 +#if defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4) + #define MBED_CONF_GEMALTO_CINTERION_TX PA_0 + #define MBED_CONF_GEMALTO_CINTERION_RX PI_9 + #define MBED_CONF_GEMALTO_CINTERION_RTS PI_10 + #define MBED_CONF_GEMALTO_CINTERION_CTS PI_13 + #define MBED_CONF_GEMALTO_CINTERION_RST PJ_10 + #define MBED_CONF_GEMALTO_CINTERION_ON PJ_7 +#elif defined (ARDUINO_EDGE_CONTROL) + /* IMPORTANT: turn on the module's 5V on demand by calling + pinMode(ON_MKR2, OUTPUT); + digitalWrite(ON_MKR2, HIGH); + */ + #define MBED_CONF_GEMALTO_CINTERION_TX p24 + #define MBED_CONF_GEMALTO_CINTERION_RX p25 + #define MBED_CONF_GEMALTO_CINTERION_RTS NC + #define MBED_CONF_GEMALTO_CINTERION_CTS NC + #define MBED_CONF_GEMALTO_CINTERION_RST p31 + #define MBED_CONF_GEMALTO_CINTERION_ON p2 +#else + #error Gemalto Cinterion cellular connectivity not supported +#endif + #define MBED_CONF_APP_SOCK_TYPE 1 #if defined __has_include @@ -87,10 +108,12 @@ class GSMClass : public MbedSocketClass { bool setTime(unsigned long const epoch, int const timezone = 0); void enableCmux(); bool isCmuxEnable(); - void debug(Stream& stream); + void trace(Stream& stream); + void setTraceLevel(int trace_level, bool timestamp = false); int ping(const char* hostname, uint8_t ttl = 128); int ping(const String& hostname, uint8_t ttl = 128); int ping(IPAddress host, uint8_t ttl = 128); + bool isConnected(); friend class GSMClient; friend class GSMUDP; @@ -115,6 +138,7 @@ class GSMClass : public MbedSocketClass { extern GSMClass GSM; #include "GSMClient.h" +#include "GSMSSLClient.h" #include "GSMUdp.h" #endif diff --git a/libraries/GSM/src/GSMClient.cpp b/libraries/GSM/src/GSMClient.cpp new file mode 100644 index 000000000..71043da70 --- /dev/null +++ b/libraries/GSM/src/GSMClient.cpp @@ -0,0 +1,24 @@ +/* + GSMClient.cpp + Copyright (c) 2023 Arduino SA. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "GSMClient.h" + +arduino::GSMClient::GSMClient(): MbedClient(100) { + +} diff --git a/libraries/GSM/src/GSMClient.h b/libraries/GSM/src/GSMClient.h index b2f4a9036..8ac465975 100644 --- a/libraries/GSM/src/GSMClient.h +++ b/libraries/GSM/src/GSMClient.h @@ -26,6 +26,10 @@ namespace arduino { class GSMClient : public MbedClient { +public: + GSMClient(); + +private: NetworkInterface *getNetwork() { return GSM.getNetwork(); } diff --git a/libraries/GSM/src/GSMSSLClient.cpp b/libraries/GSM/src/GSMSSLClient.cpp new file mode 100644 index 000000000..c953adb4f --- /dev/null +++ b/libraries/GSM/src/GSMSSLClient.cpp @@ -0,0 +1,24 @@ +/* + GSMSSLClient.cpp + Copyright (c) 2023 Arduino SA. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "GSMSSLClient.h" + +arduino::GSMSSLClient::GSMSSLClient(): MbedSSLClient(100) { + +} diff --git a/libraries/GSM/src/GSMSSLClient.h b/libraries/GSM/src/GSMSSLClient.h new file mode 100644 index 000000000..2ea0ae713 --- /dev/null +++ b/libraries/GSM/src/GSMSSLClient.h @@ -0,0 +1,42 @@ +/* + GSMSSLClient.h + Copyright (c) 2023 Arduino SA. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef GSMSSLCLIENT_H +#define GSMSSLCLIENT_H + +#include "GSM.h" +#include "MbedSSLClient.h" + +extern const char CA_CERTIFICATES[]; + +namespace arduino { + +class GSMSSLClient : public arduino::MbedSSLClient { +public: + GSMSSLClient(); + +private: + NetworkInterface *getNetwork() { + return GSM.getNetwork(); + } +}; + +} + +#endif /* GSMSSLCLIENT_H */ \ No newline at end of file diff --git a/libraries/GSM/src/GSMTrace.cpp b/libraries/GSM/src/GSMTrace.cpp new file mode 100644 index 000000000..8c65e192a --- /dev/null +++ b/libraries/GSM/src/GSMTrace.cpp @@ -0,0 +1,79 @@ +/* + GSM.h - Library for GSM on mbed platforms. + Copyright (c) 2011-2023 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include +#include + +#if MBED_CONF_MBED_TRACE_ENABLE + +static Stream* trace_stream = nullptr; +static PlatformMutex trace_mutex; +static char trace_timestamp[8]; + +static void trace_wait() { + trace_mutex.lock(); +} + +static void trace_release() { + trace_mutex.unlock(); +} + +static char* trace_time(size_t ss) { + auto ms = std::chrono::time_point_cast(rtos::Kernel::Clock::now()).time_since_epoch().count(); + snprintf(trace_timestamp, 8, "[%08llu]", ms); + return trace_timestamp; +} + +static void trace_println(const char* c) { + if (trace_stream) { + trace_stream->println(c); + } +} +#endif + +void arduino::GSMClass::setTraceLevel(int trace_level, bool timestamp) { +#if MBED_CONF_MBED_TRACE_ENABLE + switch(trace_level) { + case 0: mbed_trace_config_set(TRACE_ACTIVE_LEVEL_NONE); break; + case 1: mbed_trace_config_set(TRACE_ACTIVE_LEVEL_CMD); break; + case 2: mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ERROR); break; + case 3: mbed_trace_config_set(TRACE_ACTIVE_LEVEL_WARN); break; + case 4: mbed_trace_config_set(TRACE_ACTIVE_LEVEL_INFO); break; + case 5: mbed_trace_config_set(TRACE_ACTIVE_LEVEL_DEBUG); break; + case 6: mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL); break; + default: mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL); break; + } + + if (timestamp) { + mbed_trace_prefix_function_set( &trace_time ); + } +#endif +} + +void arduino::GSMClass::trace(Stream& stream) { +#if MBED_CONF_MBED_TRACE_ENABLE + trace_stream = &stream; + + mbed_trace_init(); + mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL); + mbed_trace_print_function_set(trace_println); + mbed_trace_mutex_wait_function_set(trace_wait); + mbed_trace_mutex_release_function_set(trace_release); +#endif +} diff --git a/libraries/GSM/src/GSMUdp.h b/libraries/GSM/src/GSMUdp.h index 6b93bd966..519adff50 100644 --- a/libraries/GSM/src/GSMUdp.h +++ b/libraries/GSM/src/GSMUdp.h @@ -1,5 +1,5 @@ /* - WiFiUdp.h + GSMUdp.h Copyright (c) 2021 Arduino SA. All right reserved. This library is free software; you can redistribute it and/or diff --git a/libraries/SocketWrapper/src/MbedClient.cpp b/libraries/SocketWrapper/src/MbedClient.cpp index dfd856f77..49265c002 100644 --- a/libraries/SocketWrapper/src/MbedClient.cpp +++ b/libraries/SocketWrapper/src/MbedClient.cpp @@ -150,6 +150,11 @@ int arduino::MbedClient::connectSSL(SocketAddress socketAddress) { return 0; } + /* For TLS connection timeout needs to be configured before handshake starts + * otherwise socket timeout is not adopted. See TLSSocketWrapper::set_timeout(int timeout) + */ + sock->set_timeout(_timeout); + restart_connect: nsapi_error_t returnCode = static_cast(sock)->connect(socketAddress); int ret = 0; diff --git a/libraries/SocketWrapper/src/MbedClient.h b/libraries/SocketWrapper/src/MbedClient.h index a2132ebf3..eca0e5a34 100644 --- a/libraries/SocketWrapper/src/MbedClient.h +++ b/libraries/SocketWrapper/src/MbedClient.h @@ -49,6 +49,10 @@ class MbedClient : public arduino::Client { public: MbedClient(); + MbedClient(unsigned long timeout) { + _timeout = timeout; + } + // Copy constructor, to be used when a Client returned by server.available() // needs to "survive" event if it goes out of scope // Sample usage: Client* new_client = new Client(existing_client) diff --git a/libraries/SocketWrapper/src/MbedSSLClient.cpp b/libraries/SocketWrapper/src/MbedSSLClient.cpp index e0aa1d2dd..3233c8dba 100644 --- a/libraries/SocketWrapper/src/MbedSSLClient.cpp +++ b/libraries/SocketWrapper/src/MbedSSLClient.cpp @@ -1,5 +1,9 @@ #include "MbedSSLClient.h" +arduino::MbedSSLClient::MbedSSLClient(unsigned long timeout): MbedClient(timeout), _disableSNI{false} { + onBeforeConnect(mbed::callback(this, &MbedSSLClient::setRootCA)); +} + arduino::MbedSSLClient::MbedSSLClient(): _disableSNI{false} { onBeforeConnect(mbed::callback(this, &MbedSSLClient::setRootCA)); }; diff --git a/libraries/SocketWrapper/src/MbedSSLClient.h b/libraries/SocketWrapper/src/MbedSSLClient.h index 3ef2d9a1c..ddedcb563 100644 --- a/libraries/SocketWrapper/src/MbedSSLClient.h +++ b/libraries/SocketWrapper/src/MbedSSLClient.h @@ -32,6 +32,9 @@ class MbedSSLClient : public arduino::MbedClient { public: MbedSSLClient(); + + MbedSSLClient(unsigned long timeout); + virtual ~MbedSSLClient() { stop(); } @@ -55,8 +58,11 @@ class MbedSSLClient : public arduino::MbedClient { private: int setRootCA() { + int err = 0; + +#if defined(MBEDTLS_FS_IO) mbed::BlockDevice* root = mbed::BlockDevice::get_default_instance(); - int err = root->init(); + err = root->init(); if( err != 0) { return err; } @@ -73,6 +79,7 @@ class MbedSSLClient : public arduino::MbedClient { if( err != NSAPI_ERROR_OK) { return err; } +#endif if(_ca_cert_custom != NULL) { err = ((TLSSocket*)sock)->append_root_ca_cert(_ca_cert_custom); diff --git a/patches/0215-Gemalto-Cinterion-Cellular-Disable-urcs-while-readin.patch b/patches/0215-Gemalto-Cinterion-Cellular-Disable-urcs-while-readin.patch new file mode 100644 index 000000000..b0ba08c8e --- /dev/null +++ b/patches/0215-Gemalto-Cinterion-Cellular-Disable-urcs-while-readin.patch @@ -0,0 +1,109 @@ +From ae470a5d61a27ec11fea588fa53a1f4f1ddac1cb Mon Sep 17 00:00:00 2001 +From: pennam +Date: Tue, 7 Nov 2023 10:38:21 +0100 +Subject: [PATCH 215/221] Gemalto Cinterion Cellular: Disable urcs while + reading + +--- + .../GEMALTO_CINTERION_CellularStack.cpp | 23 +++++++++++-------- + 1 file changed, 14 insertions(+), 9 deletions(-) + +diff --git a/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularStack.cpp b/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularStack.cpp +index 33a73bf9a3..fc2e8985d7 100644 +--- a/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularStack.cpp ++++ b/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularStack.cpp +@@ -524,6 +524,9 @@ sisw_retry: + return (_at.get_last_error() == NSAPI_ERROR_OK) ? accept_len : NSAPI_ERROR_DEVICE_ERROR; + } + ++#define DISABLE_URCs _at.at_cmd_discard("^SCFG", "=", "%s%s","Tcp/WithURCs","off") ++#define RESTORE_URCs_AND_RETURN(ret) do { _at.at_cmd_discard("^SCFG", "=", "%s%s","Tcp/WithURCs","on"); return ret; } while(0) ++ + nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address, + void *buffer, nsapi_size_t size) + { +@@ -531,13 +534,15 @@ nsapi_size_or_error_t GEMALTO_CINTERION_CellularStack::socket_recvfrom_impl(Cell + // open on the modem, assert here to catch a programming error + MBED_ASSERT(socket->id != -1); + ++ DISABLE_URCs; ++ + // we must use this flag, otherwise ^SISR URC can come while we are reading response and there is + // no way to detect if that is really an URC or response + if (!socket->pending_bytes) { + _at.process_oob(); // check for ^SISR URC + if (!socket->pending_bytes) { + tr_debug("Socket %d recv would block", socket->id); +- return NSAPI_ERROR_WOULD_BLOCK; ++ RESTORE_URCs_AND_RETURN(NSAPI_ERROR_WOULD_BLOCK); + } + } + +@@ -552,7 +557,7 @@ sisr_retry: + _at.resp_start("^SISR:"); + if (!_at.info_resp()) { + tr_error("Socket %d not responding", socket->id); +- return NSAPI_ERROR_DEVICE_ERROR; ++ RESTORE_URCs_AND_RETURN(NSAPI_ERROR_DEVICE_ERROR); + } + + int socket_id = _at.read_int(); +@@ -564,24 +569,24 @@ sisr_retry: + goto sisr_retry; + } + tr_error("Socket recvfrom id %d != %d", socket_id, socket->id); +- return NSAPI_ERROR_DEVICE_ERROR; ++ RESTORE_URCs_AND_RETURN(NSAPI_ERROR_DEVICE_ERROR); + } + + nsapi_size_or_error_t len = _at.read_int(); + if (len == 0) { + tr_warn("Socket %d no data", socket->id); + _at.resp_stop(); +- return NSAPI_ERROR_WOULD_BLOCK; ++ RESTORE_URCs_AND_RETURN(NSAPI_ERROR_WOULD_BLOCK); + } + if (len == -1) { + if (GEMALTO_CINTERION::get_module() == GEMALTO_CINTERION::ModuleTX62 && _at.get_last_read_error() == -2) { + _at.process_oob(); + tr_error("Socket %d recvfrom finished!", socket->id); + socket->pending_bytes = 0; +- return NSAPI_ERROR_OK; ++ RESTORE_URCs_AND_RETURN(NSAPI_ERROR_OK); + } + tr_error("Socket %d recvfrom failed!", socket->id); +- return NSAPI_ERROR_DEVICE_ERROR; ++ RESTORE_URCs_AND_RETURN(NSAPI_ERROR_DEVICE_ERROR); + } + if (len >= (nsapi_size_or_error_t)size) { + len = (nsapi_size_or_error_t)size; +@@ -606,7 +611,7 @@ sisr_retry: + int len = _at.read_bytes(at_buf + ip_len, 1); + if (len <= 0) { + tr_error("Socket %d recvfrom addr (len %d)", socket->id, ip_len); +- return NSAPI_ERROR_DEVICE_ERROR; ++ RESTORE_URCs_AND_RETURN(NSAPI_ERROR_DEVICE_ERROR); + } + ip_len += len; + } while (ip_len < ip_address_len && at_buf[ip_len - 2] != '\r' && at_buf[ip_len - 1] != '\n'); +@@ -629,7 +634,7 @@ sisr_retry: + int ip_len = _at.read_string(ip_address, sizeof(ip_address)); + if (ip_len <= 0) { + tr_error("Socket %d recvfrom addr (len %d)", socket->id, ip_len); +- return NSAPI_ERROR_DEVICE_ERROR; ++ RESTORE_URCs_AND_RETURN(NSAPI_ERROR_DEVICE_ERROR); + } + } + +@@ -671,7 +676,7 @@ sisr_retry: + + _at.resp_stop(); + +- return (_at.get_last_error() == NSAPI_ERROR_OK) ? (recv_len ? recv_len : NSAPI_ERROR_WOULD_BLOCK) : NSAPI_ERROR_DEVICE_ERROR; ++ RESTORE_URCs_AND_RETURN((_at.get_last_error() == NSAPI_ERROR_OK) ? (recv_len ? recv_len : NSAPI_ERROR_WOULD_BLOCK) : NSAPI_ERROR_DEVICE_ERROR); + } + + // setup internet connection profile for sockets +-- +2.42.0 + diff --git a/patches/0216-AT_CellularContext-Fix-SCFG-commands-to-configure-ba.patch b/patches/0216-AT_CellularContext-Fix-SCFG-commands-to-configure-ba.patch new file mode 100644 index 000000000..656fabd77 --- /dev/null +++ b/patches/0216-AT_CellularContext-Fix-SCFG-commands-to-configure-ba.patch @@ -0,0 +1,49 @@ +From 8dd642cb19e16ae9169fa52f26f4b1a6abc489d8 Mon Sep 17 00:00:00 2001 +From: pennam +Date: Tue, 7 Nov 2023 14:10:31 +0100 +Subject: [PATCH 216/221] AT_CellularContext: Fix ^SCFG commands to configure + bands and URCs + +--- + .../source/framework/AT/AT_CellularContext.cpp | 15 +++++---------- + 1 file changed, 5 insertions(+), 10 deletions(-) + +diff --git a/connectivity/cellular/source/framework/AT/AT_CellularContext.cpp b/connectivity/cellular/source/framework/AT/AT_CellularContext.cpp +index 087846e9b5..e876e384c9 100644 +--- a/connectivity/cellular/source/framework/AT/AT_CellularContext.cpp ++++ b/connectivity/cellular/source/framework/AT/AT_CellularContext.cpp +@@ -452,26 +452,21 @@ void AT_CellularContext::enable_access_technology() + { + case CATM1: + _at.at_cmd_discard("^SXRAT", "=","%d", _rat); +- _at.cmd_start_stop("^SCFG", "=","%s%s", "Radio/Band/CatM",buffer); +- _at.resp_start("^SCFG"); +- _at.cmd_start_stop("^SCFG", "=","%s%d%d", "Radio/Band/CatNB",0,0); +- _at.resp_start("^SCFG"); ++ _at.at_cmd_discard("^SCFG", "=","%s%s", "Radio/Band/CatM",buffer); ++ _at.at_cmd_discard("^SCFG", "=","%s%d%d", "Radio/Band/CatNB",0,0); + break; + + case CATNB: + _at.at_cmd_discard("^SXRAT", "=","%d", _rat); +- _at.cmd_start_stop("^SCFG", "=","%s%s", "Radio/Band/CatNB",buffer); +- _at.resp_start("^SCFG"); +- _at.cmd_start_stop("^SCFG", "=","%s%d%d", "Radio/Band/CatM",0,0); +- _at.resp_start("^SCFG"); ++ _at.at_cmd_discard("^SCFG", "=","%s%s", "Radio/Band/CatNB",buffer); ++ _at.at_cmd_discard("^SCFG", "=","%s%d%d", "Radio/Band/CatM",0,0); + break; + + default: + break; + } + +- _at.cmd_start_stop("^SCFG", "=", "%s%s", "Tcp/withURCs", "on"); +- _at.resp_start("^SCFG"); ++ _at.at_cmd_discard("^SCFG", "=", "%s%s", "Tcp/withURCs", "on"); + free(buffer); + + } +-- +2.42.0 + diff --git a/patches/0217-AT_CellularContext-move-enable_access_technology-at-.patch b/patches/0217-AT_CellularContext-move-enable_access_technology-at-.patch new file mode 100644 index 000000000..233e71ddf --- /dev/null +++ b/patches/0217-AT_CellularContext-move-enable_access_technology-at-.patch @@ -0,0 +1,123 @@ +From 822f1b2b855afd1f332dc3c8e490c1f7b08923b5 Mon Sep 17 00:00:00 2001 +From: pennam +Date: Fri, 10 Nov 2023 10:30:12 +0100 +Subject: [PATCH 217/221] AT_CellularContext: move enable_access_technology() + at commands into GEMALTO_CINTERION_CellularContext + +--- + .../framework/AT/AT_CellularContext.h | 4 +-- + .../framework/AT/AT_CellularContext.cpp | 25 +---------------- + .../GEMALTO_CINTERION_CellularContext.cpp | 28 +++++++++++++++++++ + .../GEMALTO_CINTERION_CellularContext.h | 1 + + 4 files changed, 32 insertions(+), 26 deletions(-) + +diff --git a/connectivity/cellular/include/cellular/framework/AT/AT_CellularContext.h b/connectivity/cellular/include/cellular/framework/AT/AT_CellularContext.h +index eb3bf5afdd..2f68f1f97b 100644 +--- a/connectivity/cellular/include/cellular/framework/AT/AT_CellularContext.h ++++ b/connectivity/cellular/include/cellular/framework/AT/AT_CellularContext.h +@@ -135,8 +135,6 @@ private: + + PinName _dcd_pin; + bool _active_high; +- RadioAccessTechnologyType _rat; +- FrequencyBand _band; + + protected: + char _found_apn[MAX_APN_LENGTH]; +@@ -144,6 +142,8 @@ protected: + bool _cp_req; + bool _is_connected; + ATHandler &_at; ++ RadioAccessTechnologyType _rat; ++ FrequencyBand _band; + }; + + } // namespace mbed +diff --git a/connectivity/cellular/source/framework/AT/AT_CellularContext.cpp b/connectivity/cellular/source/framework/AT/AT_CellularContext.cpp +index e876e384c9..c05fc386e0 100644 +--- a/connectivity/cellular/source/framework/AT/AT_CellularContext.cpp ++++ b/connectivity/cellular/source/framework/AT/AT_CellularContext.cpp +@@ -445,30 +445,7 @@ bool AT_CellularContext::set_new_context(int cid) + + void AT_CellularContext::enable_access_technology() + { +- char *buffer = new char [8]; +- memset(buffer, 0, 8); +- sprintf(buffer,"%08X", _band); +- switch (_rat) +- { +- case CATM1: +- _at.at_cmd_discard("^SXRAT", "=","%d", _rat); +- _at.at_cmd_discard("^SCFG", "=","%s%s", "Radio/Band/CatM",buffer); +- _at.at_cmd_discard("^SCFG", "=","%s%d%d", "Radio/Band/CatNB",0,0); +- break; +- +- case CATNB: +- _at.at_cmd_discard("^SXRAT", "=","%d", _rat); +- _at.at_cmd_discard("^SCFG", "=","%s%s", "Radio/Band/CatNB",buffer); +- _at.at_cmd_discard("^SCFG", "=","%s%d%d", "Radio/Band/CatM",0,0); +- break; +- +- default: +- break; +- } +- +- _at.at_cmd_discard("^SCFG", "=", "%s%s", "Tcp/withURCs", "on"); +- free(buffer); +- ++ enable_access_technology(); + } + + nsapi_error_t AT_CellularContext::do_activate_context() +diff --git a/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.cpp b/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.cpp +index 7ee2c8e53c..bc2b1d514c 100644 +--- a/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.cpp ++++ b/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.cpp +@@ -148,4 +148,32 @@ NetworkStack *GEMALTO_CINTERION_CellularContext::get_stack() + } + #endif // NSAPI_PPP_AVAILABLE + ++void GEMALTO_CINTERION_CellularContext::enable_access_technology() ++{ ++ char *buffer = new char [8]; ++ memset(buffer, 0, 8); ++ sprintf(buffer,"%08X", _band); ++ switch (_rat) ++ { ++ case CATM1: ++ _at.at_cmd_discard("^SXRAT", "=","%d", _rat); ++ _at.at_cmd_discard("^SCFG", "=","%s%s", "Radio/Band/CatM",buffer); ++ _at.at_cmd_discard("^SCFG", "=","%s%d%d", "Radio/Band/CatNB",0,0); ++ break; ++ ++ case CATNB: ++ _at.at_cmd_discard("^SXRAT", "=","%d", _rat); ++ _at.at_cmd_discard("^SCFG", "=","%s%s", "Radio/Band/CatNB",buffer); ++ _at.at_cmd_discard("^SCFG", "=","%s%d%d", "Radio/Band/CatM",0,0); ++ break; ++ ++ default: ++ break; ++ } ++ ++ _at.at_cmd_discard("^SCFG", "=", "%s%s", "Tcp/withURCs", "on"); ++ free(buffer); ++ ++} ++ + } /* namespace mbed */ +diff --git a/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.h b/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.h +index 0645b2b87c..cd9aef0222 100644 +--- a/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.h ++++ b/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.h +@@ -34,6 +34,7 @@ protected: + virtual NetworkStack *get_stack(); + #endif // NSAPI_PPP_AVAILABLE + virtual nsapi_error_t do_user_authentication(); ++ virtual void enable_access_technology(); + }; + + } /* namespace mbed */ +-- +2.42.0 + diff --git a/patches/0218-GEMALTO_CINTERION_CellularContext-do-not-disable-all.patch b/patches/0218-GEMALTO_CINTERION_CellularContext-do-not-disable-all.patch new file mode 100644 index 000000000..e0904957c --- /dev/null +++ b/patches/0218-GEMALTO_CINTERION_CellularContext-do-not-disable-all.patch @@ -0,0 +1,32 @@ +From 915ad28bd3e9d369128691e8558c4626bc65fb82 Mon Sep 17 00:00:00 2001 +From: pennam +Date: Fri, 10 Nov 2023 10:30:54 +0100 +Subject: [PATCH 218/221] GEMALTO_CINTERION_CellularContext: do not disable all + bands + + * Switching rat AT command fails and should not be necessary to disable bands since we do not use a fallback rat +--- + .../GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.cpp | 2 -- + 1 file changed, 2 deletions(-) + +diff --git a/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.cpp b/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.cpp +index bc2b1d514c..bf7522621b 100644 +--- a/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.cpp ++++ b/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.cpp +@@ -158,13 +158,11 @@ void GEMALTO_CINTERION_CellularContext::enable_access_technology() + case CATM1: + _at.at_cmd_discard("^SXRAT", "=","%d", _rat); + _at.at_cmd_discard("^SCFG", "=","%s%s", "Radio/Band/CatM",buffer); +- _at.at_cmd_discard("^SCFG", "=","%s%d%d", "Radio/Band/CatNB",0,0); + break; + + case CATNB: + _at.at_cmd_discard("^SXRAT", "=","%d", _rat); + _at.at_cmd_discard("^SCFG", "=","%s%s", "Radio/Band/CatNB",buffer); +- _at.at_cmd_discard("^SCFG", "=","%s%d%d", "Radio/Band/CatM",0,0); + break; + + default: +-- +2.42.0 + diff --git a/patches/0219-GEMALTO_CINTERION_CellularContext-add-return-value-t.patch b/patches/0219-GEMALTO_CINTERION_CellularContext-add-return-value-t.patch new file mode 100644 index 000000000..8c1ad17ab --- /dev/null +++ b/patches/0219-GEMALTO_CINTERION_CellularContext-add-return-value-t.patch @@ -0,0 +1,108 @@ +From 64e0c1f45702e5e2d11a667176c12582c3a36bdf Mon Sep 17 00:00:00 2001 +From: pennam +Date: Fri, 10 Nov 2023 10:58:37 +0100 +Subject: [PATCH 219/221] GEMALTO_CINTERION_CellularContext: add return value + to enable_access_technology() + +--- + .../framework/AT/AT_CellularContext.h | 2 +- + .../framework/AT/AT_CellularContext.cpp | 4 +-- + .../GEMALTO_CINTERION_CellularContext.cpp | 25 +++++++++++-------- + .../GEMALTO_CINTERION_CellularContext.h | 2 +- + 4 files changed, 19 insertions(+), 14 deletions(-) + +diff --git a/connectivity/cellular/include/cellular/framework/AT/AT_CellularContext.h b/connectivity/cellular/include/cellular/framework/AT/AT_CellularContext.h +index 2f68f1f97b..6291bb11d7 100644 +--- a/connectivity/cellular/include/cellular/framework/AT/AT_CellularContext.h ++++ b/connectivity/cellular/include/cellular/framework/AT/AT_CellularContext.h +@@ -109,7 +109,7 @@ protected: + * @return NIDD context text, e.g. Non-IP or NONIP + */ + virtual const char *get_nonip_context_type_str(); +- virtual void enable_access_technology(); ++ virtual nsapi_error_t enable_access_technology(); + virtual void set_cid(int cid); + + private: +diff --git a/connectivity/cellular/source/framework/AT/AT_CellularContext.cpp b/connectivity/cellular/source/framework/AT/AT_CellularContext.cpp +index c05fc386e0..f5e69aac80 100644 +--- a/connectivity/cellular/source/framework/AT/AT_CellularContext.cpp ++++ b/connectivity/cellular/source/framework/AT/AT_CellularContext.cpp +@@ -443,9 +443,9 @@ bool AT_CellularContext::set_new_context(int cid) + return success; + } + +-void AT_CellularContext::enable_access_technology() ++nsapi_error_t AT_CellularContext::enable_access_technology() + { +- enable_access_technology(); ++ return enable_access_technology(); + } + + nsapi_error_t AT_CellularContext::do_activate_context() +diff --git a/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.cpp b/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.cpp +index bf7522621b..bbd5c4c4b5 100644 +--- a/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.cpp ++++ b/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.cpp +@@ -148,30 +148,35 @@ NetworkStack *GEMALTO_CINTERION_CellularContext::get_stack() + } + #endif // NSAPI_PPP_AVAILABLE + +-void GEMALTO_CINTERION_CellularContext::enable_access_technology() ++nsapi_error_t GEMALTO_CINTERION_CellularContext::enable_access_technology() + { +- char *buffer = new char [8]; +- memset(buffer, 0, 8); +- sprintf(buffer,"%08X", _band); ++ nsapi_error_t error = NSAPI_ERROR_OK; ++ char buffer[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; ++ ++ snprintf(buffer, 9, "%08X", _band); + switch (_rat) + { + case CATM1: +- _at.at_cmd_discard("^SXRAT", "=","%d", _rat); +- _at.at_cmd_discard("^SCFG", "=","%s%s", "Radio/Band/CatM",buffer); ++ error = _at.at_cmd_discard("^SCFG", "=","%s%s", "Radio/Band/CatM", buffer); + break; + + case CATNB: +- _at.at_cmd_discard("^SXRAT", "=","%d", _rat); +- _at.at_cmd_discard("^SCFG", "=","%s%s", "Radio/Band/CatNB",buffer); ++ error = _at.at_cmd_discard("^SCFG", "=","%s%s", "Radio/Band/CatNB", buffer); + break; + + default: + break; + } ++ if (error != NSAPI_ERROR_OK) { ++ return error; ++ } + +- _at.at_cmd_discard("^SCFG", "=", "%s%s", "Tcp/withURCs", "on"); +- free(buffer); ++ error = _at.at_cmd_discard("^SXRAT", "=","%d", _rat); ++ if (error != NSAPI_ERROR_OK) { ++ return error; ++ } + ++ return _at.at_cmd_discard("^SCFG", "=", "%s%s", "Tcp/withURCs", "on"); + } + + } /* namespace mbed */ +diff --git a/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.h b/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.h +index cd9aef0222..24ff87bc08 100644 +--- a/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.h ++++ b/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.h +@@ -34,7 +34,7 @@ protected: + virtual NetworkStack *get_stack(); + #endif // NSAPI_PPP_AVAILABLE + virtual nsapi_error_t do_user_authentication(); +- virtual void enable_access_technology(); ++ virtual nsapi_error_t enable_access_technology(); + }; + + } /* namespace mbed */ +-- +2.42.0 + diff --git a/patches/0220-GEMALTO_CINTERION_CellularContext-connect-check-retu.patch b/patches/0220-GEMALTO_CINTERION_CellularContext-connect-check-retu.patch new file mode 100644 index 000000000..0b4784e27 --- /dev/null +++ b/patches/0220-GEMALTO_CINTERION_CellularContext-connect-check-retu.patch @@ -0,0 +1,64 @@ +From b5d44a4f3be3938045c185d5f1753cbade22a6f9 Mon Sep 17 00:00:00 2001 +From: pennam +Date: Fri, 10 Nov 2023 17:06:53 +0100 +Subject: [PATCH 220/221] GEMALTO_CINTERION_CellularContext::connect check + return codes and print errors + +--- + .../GEMALTO_CINTERION_CellularContext.cpp | 29 +++++++++++++++---- + 1 file changed, 24 insertions(+), 5 deletions(-) + +diff --git a/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.cpp b/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.cpp +index bbd5c4c4b5..0af08a786d 100644 +--- a/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.cpp ++++ b/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularContext.cpp +@@ -33,22 +33,41 @@ GEMALTO_CINTERION_CellularContext::~GEMALTO_CINTERION_CellularContext() + nsapi_error_t GEMALTO_CINTERION_CellularContext::connect(const char *sim_pin, const char *apn, const char *uname, + const char *pwd) + { ++ nsapi_error_t error = NSAPI_ERROR_OK; ++ + set_sim_pin(sim_pin); + set_credentials(apn, uname, pwd); + +- set_device_ready(); ++ error = set_device_ready(); ++ if ((error != NSAPI_ERROR_OK) && (error != NSAPI_ERROR_ALREADY)) { ++ tr_error("Failure connecting to GEMALTO CINTERION modem"); ++ return error; ++ } + + _at.lock(); + bool valid_context = get_context(); + _at.unlock(); + +- if(!valid_context) { +- set_new_context(_cid); ++ if (!valid_context) { ++ valid_context = set_new_context(_cid); ++ } ++ ++ if (!valid_context) { ++ tr_error("Invalid AT cellular context %d", _cid); ++ return NSAPI_ERROR_DEVICE_ERROR; + } + +- do_user_authentication(); ++ error = do_user_authentication(); ++ if (error != NSAPI_ERROR_OK) { ++ tr_error("Failure during user authentication"); ++ return error; ++ } + +- enable_access_technology(); ++ error = enable_access_technology(); ++ if (error != NSAPI_ERROR_OK) { ++ tr_error("Failure enabling access technology"); ++ return error; ++ } + + return AT_CellularContext::connect(); + } +-- +2.42.0 + diff --git a/patches/0221-TLSSocketWrapper-allow-appending-ca_cert-to-an-empty.patch b/patches/0221-TLSSocketWrapper-allow-appending-ca_cert-to-an-empty.patch new file mode 100644 index 000000000..d2655ce38 --- /dev/null +++ b/patches/0221-TLSSocketWrapper-allow-appending-ca_cert-to-an-empty.patch @@ -0,0 +1,31 @@ +From e69150d098a78a9f4d10f5f993dee29602cd076a Mon Sep 17 00:00:00 2001 +From: pennam +Date: Mon, 13 Nov 2023 16:22:14 +0100 +Subject: [PATCH 221/221] TLSSocketWrapper: allow appending ca_cert to an empty + chain + +--- + connectivity/netsocket/source/TLSSocketWrapper.cpp | 5 +++-- + 1 file changed, 3 insertions(+), 2 deletions(-) + +diff --git a/connectivity/netsocket/source/TLSSocketWrapper.cpp b/connectivity/netsocket/source/TLSSocketWrapper.cpp +index 6665f64cc0..1fb9c21769 100644 +--- a/connectivity/netsocket/source/TLSSocketWrapper.cpp ++++ b/connectivity/netsocket/source/TLSSocketWrapper.cpp +@@ -145,10 +145,11 @@ nsapi_error_t TLSSocketWrapper::append_root_ca_cert(const void *root_ca, size_t + + crt = get_ca_chain(); + if (!crt) { +- return NSAPI_ERROR_NO_MEMORY; ++ /* In no chain is configured create a new one */ ++ return set_root_ca_cert(root_ca, len); + } + +- /* Parse CA certification */ ++ /* Append root_ca to the crt chain */ + int ret; + if ((ret = mbedtls_x509_crt_parse(crt, static_cast(root_ca), + len)) != 0) { +-- +2.42.0 + diff --git a/variants/EDGE_CONTROL/conf/.mbedignore b/variants/EDGE_CONTROL/conf/.mbedignore index 3562a46dc..d10167ba6 100644 --- a/variants/EDGE_CONTROL/conf/.mbedignore +++ b/variants/EDGE_CONTROL/conf/.mbedignore @@ -1,2 +1 @@ -mbed-os/connectivity/drivers/cellular/* mbed-os/connectivity/nanostack/* \ No newline at end of file diff --git a/variants/EDGE_CONTROL/conf/mbed_app.json b/variants/EDGE_CONTROL/conf/mbed_app.json index 065dece92..572df7428 100644 --- a/variants/EDGE_CONTROL/conf/mbed_app.json +++ b/variants/EDGE_CONTROL/conf/mbed_app.json @@ -4,6 +4,7 @@ "MBED_STACK_STATS_ENABLED=1", "MBED_MEM_TRACING_ENABLED=1", "NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS=8", + "MBEDTLS_SHA1_C=1", "NRFX_WDT_ENABLED=1" ], "target_overrides": { @@ -13,7 +14,11 @@ "platform.stdio-baud-rate": 115200, "platform.default-serial-baud-rate": 115200, "platform.callback-nontrivial": true, - "rtos.main-thread-stack-size": 32768, + "rtos.main-thread-stack-size": 4096, + "cellular.debug-at": true, + "cellular.offload-dns-queries": true, + "cellular.at-handler-buffer-size": 1024, + "mbed-trace.enable": true, "target.mbed_app_start": "0x10000" }, "EDGE_CONTROL": { pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy