Skip to content

Add TLS support to Portenta CAT.M1/NB IoT GNSS Shield #759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add Gemalto Cinterion mbed-os patches
  • Loading branch information
pennam committed Nov 13, 2023
commit 74d0c52ed65bdbd3d4657b07cd0b7e4c8d566e87
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
From ae470a5d61a27ec11fea588fa53a1f4f1ddac1cb Mon Sep 17 00:00:00 2001
From: pennam <m.pennasilico@arduino.cc>
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

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
From 8dd642cb19e16ae9169fa52f26f4b1a6abc489d8 Mon Sep 17 00:00:00 2001
From: pennam <m.pennasilico@arduino.cc>
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

Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
From 822f1b2b855afd1f332dc3c8e490c1f7b08923b5 Mon Sep 17 00:00:00 2001
From: pennam <m.pennasilico@arduino.cc>
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

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
From 915ad28bd3e9d369128691e8558c4626bc65fb82 Mon Sep 17 00:00:00 2001
From: pennam <m.pennasilico@arduino.cc>
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

Loading