From d8add3907a6f5d9bae3623e9e823b33d2fede443 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 7 Nov 2023 08:47:19 +0100 Subject: [PATCH 01/20] GSMUdp: fix file header --- libraries/GSM/src/GSMUdp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 984b4fd2f353e4e4f2ca0f56ae2b56669e63bf1f Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 7 Nov 2023 08:50:24 +0100 Subject: [PATCH 02/20] GSM: add isConnected() method --- libraries/GSM/src/GSM.cpp | 9 +++++++++ libraries/GSM/src/GSM.h | 1 + 2 files changed, 10 insertions(+) diff --git a/libraries/GSM/src/GSM.cpp b/libraries/GSM/src/GSM.cpp index 1da0d49b3..78055aaf3 100644 --- a/libraries/GSM/src/GSM.cpp +++ b/libraries/GSM/src/GSM.cpp @@ -130,6 +130,15 @@ bool arduino::GSMClass::setTime(unsigned long const epoch, int const timezone) return _device->set_time(epoch, timezone); } +bool arduino::GSMClass::isConnected() +{ + if (_context) { + return _context->is_connected(); + } else { + return false; + } +} + static PlatformMutex trace_mutex; static void trace_wait() diff --git a/libraries/GSM/src/GSM.h b/libraries/GSM/src/GSM.h index 8b48d3e84..8643dcd2a 100644 --- a/libraries/GSM/src/GSM.h +++ b/libraries/GSM/src/GSM.h @@ -91,6 +91,7 @@ class GSMClass : public MbedSocketClass { 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; From 03be3671c0bc42b2dacabf47f773f61a18f24b63 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 7 Nov 2023 08:52:51 +0100 Subject: [PATCH 03/20] Add GSMSSLClient class --- libraries/GSM/src/GSM.h | 1 + libraries/GSM/src/GSMSSLClient.h | 38 ++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 libraries/GSM/src/GSMSSLClient.h diff --git a/libraries/GSM/src/GSM.h b/libraries/GSM/src/GSM.h index 8643dcd2a..933054201 100644 --- a/libraries/GSM/src/GSM.h +++ b/libraries/GSM/src/GSM.h @@ -116,6 +116,7 @@ class GSMClass : public MbedSocketClass { extern GSMClass GSM; #include "GSMClient.h" +#include "GSMSSLClient.h" #include "GSMUdp.h" #endif diff --git a/libraries/GSM/src/GSMSSLClient.h b/libraries/GSM/src/GSMSSLClient.h new file mode 100644 index 000000000..92ae4206b --- /dev/null +++ b/libraries/GSM/src/GSMSSLClient.h @@ -0,0 +1,38 @@ +/* + 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 { + NetworkInterface *getNetwork() { + return GSM.getNetwork(); + } +}; + +} + +#endif /* GSMSSLCLIENT_H */ \ No newline at end of file From 69e563ed49f5507ba4fbc0b82d8ad27afd047d29 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 7 Nov 2023 10:14:15 +0100 Subject: [PATCH 04/20] MbedClient add possibility to set socket timeout in constructor --- libraries/SocketWrapper/src/MbedClient.h | 4 ++++ 1 file changed, 4 insertions(+) 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) From 4cedb61fcf837125c77447a8bef4a1e71b7496c7 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 7 Nov 2023 15:10:44 +0100 Subject: [PATCH 05/20] MbedClient::connectSSL set timeout before TLS handshake starts --- libraries/SocketWrapper/src/MbedClient.cpp | 5 +++++ 1 file changed, 5 insertions(+) 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; From 389a2c9030e004b6629114de466d0b59e3dd117c Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 7 Nov 2023 15:13:52 +0100 Subject: [PATCH 06/20] MbedSSLClient add possibility to set socket timeout in constructor --- libraries/SocketWrapper/src/MbedSSLClient.cpp | 4 ++++ libraries/SocketWrapper/src/MbedSSLClient.h | 3 +++ 2 files changed, 7 insertions(+) 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..3fafd47c6 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(); } From 89cec9fd283a80e00a922c913a77c96a04250485 Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 7 Nov 2023 15:17:04 +0100 Subject: [PATCH 07/20] GSMClient: set default socket timeout --- libraries/GSM/src/GSMClient.cpp | 24 ++++++++++++++++++++++++ libraries/GSM/src/GSMClient.h | 4 ++++ libraries/GSM/src/GSMSSLClient.cpp | 24 ++++++++++++++++++++++++ libraries/GSM/src/GSMSSLClient.h | 4 ++++ 4 files changed, 56 insertions(+) create mode 100644 libraries/GSM/src/GSMClient.cpp create mode 100644 libraries/GSM/src/GSMSSLClient.cpp 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 index 92ae4206b..2ea0ae713 100644 --- a/libraries/GSM/src/GSMSSLClient.h +++ b/libraries/GSM/src/GSMSSLClient.h @@ -28,6 +28,10 @@ extern const char CA_CERTIFICATES[]; namespace arduino { class GSMSSLClient : public arduino::MbedSSLClient { +public: + GSMSSLClient(); + +private: NetworkInterface *getNetwork() { return GSM.getNetwork(); } From 703289d1099d0f3d1ddd6e0b53e814ed12a3e2ec Mon Sep 17 00:00:00 2001 From: pennam Date: Tue, 7 Nov 2023 15:19:54 +0100 Subject: [PATCH 08/20] GSM: Add GSMSSLClient example --- .../examples/GSMSSLClient/GSMSSLClient.ino | 66 +++++++++++++++++++ .../examples/GSMSSLClient/arduino_secrets.h | 4 ++ 2 files changed, 70 insertions(+) create mode 100644 libraries/GSM/examples/GSMSSLClient/GSMSSLClient.ino create mode 100644 libraries/GSM/examples/GSMSSLClient/arduino_secrets.h 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 "" From ef79b5b3694a6ce65f409c15f8d5a703e86f5145 Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 9 Nov 2023 13:13:26 +0100 Subject: [PATCH 09/20] GSM: fix file headers --- libraries/GSM/src/GSM.cpp | 19 +++++++++++++++++++ libraries/GSM/src/GSM.h | 5 ++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/libraries/GSM/src/GSM.cpp b/libraries/GSM/src/GSM.cpp index 78055aaf3..d8aaeab71 100644 --- a/libraries/GSM/src/GSM.cpp +++ b/libraries/GSM/src/GSM.cpp @@ -1,3 +1,22 @@ +/* + 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" diff --git a/libraries/GSM/src/GSM.h b/libraries/GSM/src/GSM.h index 933054201..0a25571c2 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 From 66b026a02b958c3378b84978a421894195d43639 Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 9 Nov 2023 13:13:54 +0100 Subject: [PATCH 10/20] GSM: remove unused function --- libraries/GSM/src/GSM.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/GSM/src/GSM.cpp b/libraries/GSM/src/GSM.cpp index d8aaeab71..8f37827eb 100644 --- a/libraries/GSM/src/GSM.cpp +++ b/libraries/GSM/src/GSM.cpp @@ -27,7 +27,6 @@ #define MAXRETRY 3 -bool _cmuxEnable = false; arduino::CMUXClass * arduino::CMUXClass::get_default_instance() { static mbed::UnbufferedSerial serial(MBED_CONF_GEMALTO_CINTERION_TX, MBED_CONF_GEMALTO_CINTERION_RX, 115200); From bed52018a551dd790b40822169c5562d261c1cbb Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 9 Nov 2023 15:06:50 +0100 Subject: [PATCH 11/20] GSM: rename debug() method into trace() * Move functions in a separate GSMTrace.cpp file * Add function to set trace level and enable/disable trace timestamps * Cleanup --- libraries/GSM/src/GSM.cpp | 46 -------------------- libraries/GSM/src/GSM.h | 3 +- libraries/GSM/src/GSMTrace.cpp | 79 ++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 47 deletions(-) create mode 100644 libraries/GSM/src/GSMTrace.cpp diff --git a/libraries/GSM/src/GSM.cpp b/libraries/GSM/src/GSM.cpp index 8f37827eb..700a33701 100644 --- a/libraries/GSM/src/GSM.cpp +++ b/libraries/GSM/src/GSM.cpp @@ -157,53 +157,7 @@ bool arduino::GSMClass::isConnected() } } -static PlatformMutex trace_mutex; -static void trace_wait() -{ - 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); - } -} - -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 0a25571c2..e9e95fc77 100644 --- a/libraries/GSM/src/GSM.h +++ b/libraries/GSM/src/GSM.h @@ -90,7 +90,8 @@ 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); 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 +} From 2cb24dfff583b2a19b3b5c918feba2dee86eee1d Mon Sep 17 00:00:00 2001 From: pennam Date: Thu, 9 Nov 2023 15:10:48 +0100 Subject: [PATCH 12/20] GSM: fix identation and spacing --- libraries/GSM/src/GSM.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/libraries/GSM/src/GSM.cpp b/libraries/GSM/src/GSM.cpp index 700a33701..9285ce838 100644 --- a/libraries/GSM/src/GSM.cpp +++ b/libraries/GSM/src/GSM.cpp @@ -21,13 +21,14 @@ #include "mbed.h" #include "CellularLog.h" +#include "CellularDevice.h" #include "CellularContext.h" #include "CellularInterface.h" #include "GEMALTO_CINTERION_CellularStack.h" #define MAXRETRY 3 -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); @@ -37,11 +38,11 @@ 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) { @@ -117,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; } From 5131eefeb6d7731037a1a0d07124659841f0561e Mon Sep 17 00:00:00 2001 From: pennam Date: Fri, 10 Nov 2023 17:13:00 +0100 Subject: [PATCH 13/20] GSM: use define for RESET and power ON pin --- libraries/GSM/src/GSM.cpp | 14 +++++++------- libraries/GSM/src/GSM.h | 2 ++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/libraries/GSM/src/GSM.cpp b/libraries/GSM/src/GSM.cpp index 9285ce838..19305540b 100644 --- a/libraries/GSM/src/GSM.cpp +++ b/libraries/GSM/src/GSM.cpp @@ -48,14 +48,14 @@ mbed::CellularDevice *mbed::CellularDevice::get_default_instance() 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 @@ -69,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); diff --git a/libraries/GSM/src/GSM.h b/libraries/GSM/src/GSM.h index e9e95fc77..278cb1e92 100644 --- a/libraries/GSM/src/GSM.h +++ b/libraries/GSM/src/GSM.h @@ -37,6 +37,8 @@ #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 #define MBED_CONF_APP_SOCK_TYPE 1 #if defined __has_include From afb706d873424b2402e54eecc10a9069f5c82aed Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 10 Oct 2023 14:43:53 +0200 Subject: [PATCH 14/20] edge_control: enable cellular connectivity --- variants/EDGE_CONTROL/conf/.mbedignore | 1 - variants/EDGE_CONTROL/conf/mbed_app.json | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) 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..d65a83fbd 100644 --- a/variants/EDGE_CONTROL/conf/mbed_app.json +++ b/variants/EDGE_CONTROL/conf/mbed_app.json @@ -14,6 +14,10 @@ "platform.default-serial-baud-rate": 115200, "platform.callback-nontrivial": true, "rtos.main-thread-stack-size": 32768, + "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": { From d7ae070635fe0dcc55a8208fd753a3284bfd5b5a Mon Sep 17 00:00:00 2001 From: pennam Date: Fri, 10 Nov 2023 17:51:03 +0100 Subject: [PATCH 15/20] edge_control: reduce rtos.main-thread-stack-size to 4K --- variants/EDGE_CONTROL/conf/mbed_app.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variants/EDGE_CONTROL/conf/mbed_app.json b/variants/EDGE_CONTROL/conf/mbed_app.json index d65a83fbd..28d922ab0 100644 --- a/variants/EDGE_CONTROL/conf/mbed_app.json +++ b/variants/EDGE_CONTROL/conf/mbed_app.json @@ -13,7 +13,7 @@ "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, From dc22e059887af00a95ab171f6f8aa6fb47cd10dc Mon Sep 17 00:00:00 2001 From: pennam Date: Fri, 10 Nov 2023 17:53:07 +0100 Subject: [PATCH 16/20] edge_control: TLS enable SHA1 --- variants/EDGE_CONTROL/conf/mbed_app.json | 1 + 1 file changed, 1 insertion(+) diff --git a/variants/EDGE_CONTROL/conf/mbed_app.json b/variants/EDGE_CONTROL/conf/mbed_app.json index 28d922ab0..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": { From f0e429a6d178a88e8adad6ae6da0661b62377df3 Mon Sep 17 00:00:00 2001 From: pennam Date: Fri, 10 Nov 2023 18:09:23 +0100 Subject: [PATCH 17/20] GSM: edge_control add pins definitions --- libraries/GSM/src/GSM.h | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/libraries/GSM/src/GSM.h b/libraries/GSM/src/GSM.h index 278cb1e92..60339fb80 100644 --- a/libraries/GSM/src/GSM.h +++ b/libraries/GSM/src/GSM.h @@ -33,12 +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 -#define MBED_CONF_GEMALTO_CINTERION_RST PJ_10 -#define MBED_CONF_GEMALTO_CINTERION_ON PJ_7 +#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 From a4d9a38731583a00898f52902c329ada63b0e5d7 Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 13 Nov 2023 10:39:53 +0100 Subject: [PATCH 18/20] MbedSSLClient: load certificates from filesystem only if supported --- libraries/SocketWrapper/src/MbedSSLClient.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libraries/SocketWrapper/src/MbedSSLClient.h b/libraries/SocketWrapper/src/MbedSSLClient.h index 3fafd47c6..ddedcb563 100644 --- a/libraries/SocketWrapper/src/MbedSSLClient.h +++ b/libraries/SocketWrapper/src/MbedSSLClient.h @@ -58,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; } @@ -76,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); From 74d0c52ed65bdbd3d4657b07cd0b7e4c8d566e87 Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 13 Nov 2023 17:16:34 +0100 Subject: [PATCH 19/20] Add Gemalto Cinterion mbed-os patches --- ...n-Cellular-Disable-urcs-while-readin.patch | 109 ++++++++++++++++ ...xt-Fix-SCFG-commands-to-configure-ba.patch | 49 +++++++ ...xt-move-enable_access_technology-at-.patch | 123 ++++++++++++++++++ ...N_CellularContext-do-not-disable-all.patch | 32 +++++ ...N_CellularContext-add-return-value-t.patch | 108 +++++++++++++++ ...N_CellularContext-connect-check-retu.patch | 64 +++++++++ ...-allow-appending-ca_cert-to-an-empty.patch | 31 +++++ 7 files changed, 516 insertions(+) create mode 100644 patches/0215-Gemalto-Cinterion-Cellular-Disable-urcs-while-readin.patch create mode 100644 patches/0216-AT_CellularContext-Fix-SCFG-commands-to-configure-ba.patch create mode 100644 patches/0217-AT_CellularContext-move-enable_access_technology-at-.patch create mode 100644 patches/0218-GEMALTO_CINTERION_CellularContext-do-not-disable-all.patch create mode 100644 patches/0219-GEMALTO_CINTERION_CellularContext-add-return-value-t.patch create mode 100644 patches/0220-GEMALTO_CINTERION_CellularContext-connect-check-retu.patch create mode 100644 patches/0221-TLSSocketWrapper-allow-appending-ca_cert-to-an-empty.patch 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 + From 149883bf0611050e3b3d077e0f0a80385cc71d37 Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 13 Nov 2023 17:53:19 +0100 Subject: [PATCH 20/20] CI: remove GSM library from target GIGA --- .github/workflows/compile-examples.yml | 1 - 1 file changed, 1 deletion(-) 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