Skip to content

Commit e1a3b3c

Browse files
committed
Add mbed patch to support cmux
1 parent b5e1ec9 commit e1a3b3c

File tree

1 file changed

+249
-0
lines changed

1 file changed

+249
-0
lines changed

patches/0109-cmux-support.patch

+249
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
From 2245cb8f3b0fc6eb18b724cb7994b0b234605fe8 Mon Sep 17 00:00:00 2001
2+
From: Riccardo Rizzo <r.rizzo@arduino.cc>
3+
Date: Fri, 26 Nov 2021 14:46:40 +0100
4+
Subject: [PATCH] cmux support
5+
6+
- CMUX.h handle ongoig packet from all serial(virtual, real) and route to the correct owner, when
7+
also the cmux enable is ready is supposed that this class should also handle and frammentate the packet to be
8+
routed in the properly channel, actually should work as a big serialpassthrough because tested over a unique channel(GSMpty.s0)
9+
- PTYSerial.h virtual serial buffer
10+
- PTYclass.h take two serial and set s1.in to s0.out and viceversa used in
11+
CMUXManager.cpp, in mbed-core, during init time to set properly the interfaced used by all actors
12+
- GSM.h and GPS.h, in mbed-core, reworked in order to:
13+
1. take the serial as input
14+
2. in begin() method use the serial propagated by input in order to create a device -> get_default_istance()
15+
than set this device for cinterion stack usage(GSMPTY.s1 or GPSPTY.s1)
16+
- CMUXManager.cpp set the thread that should be used for manage the comunication between the virtuar serial and hw serial
17+
provide get method to access the PTYclass serials for stack side
18+
19+
https://github.com/Rocketct/ArduinoCore-mbed/tree/cmux_core_211126
20+
21+
modified cellular cstate machine to take enable CMUX when required.
22+
added support API for enable and disable CMUX from cellular device.
23+
added callback logic to enable virtual channels.
24+
---
25+
.../cellular/framework/API/CellularDevice.h | 9 ++++++
26+
.../cellular/framework/AT/AT_CellularDevice.h | 9 ++++++
27+
.../source/framework/AT/AT_CellularDevice.cpp | 31 +++++++++++++++++++
28+
.../framework/device/CellularStateMachine.cpp | 6 ++++
29+
.../GEMALTO/CINTERION/GEMALTO_CINTERION.cpp | 7 +++--
30+
.../GEMALTO_CINTERION_CellularNetwork.cpp | 5 +++
31+
.../GEMALTO_CINTERION_CellularNetwork.h | 2 ++
32+
.../GEMALTO_CINTERION_CellularStack.cpp | 9 +++---
33+
.../GEMALTO_CINTERION_CellularStack.h | 1 +
34+
9 files changed, 73 insertions(+), 6 deletions(-)
35+
36+
diff --git a/connectivity/cellular/include/cellular/framework/API/CellularDevice.h b/connectivity/cellular/include/cellular/framework/API/CellularDevice.h
37+
index a5fa3b68fd..0c8d1a2db2 100644
38+
--- a/connectivity/cellular/include/cellular/framework/API/CellularDevice.h
39+
+++ b/connectivity/cellular/include/cellular/framework/API/CellularDevice.h
40+
@@ -73,6 +73,8 @@ public:
41+
*/
42+
static CellularDevice *get_default_instance();
43+
44+
+ mbed::Callback<void(void)> enableCMUXChannel = nullptr;
45+
+
46+
/** Return target onboard instance of CellularDevice
47+
*
48+
* @remark Mbed OS target shall override (non-weak) this function for an onboard modem.
49+
@@ -216,6 +218,13 @@ public: //Pure virtual functions
50+
*/
51+
virtual nsapi_error_t get_sim_state(SimState &state) = 0;
52+
53+
+ virtual nsapi_error_t enable_cmux() = 0;
54+
+
55+
+
56+
+ virtual bool is_cmux_enabled() = 0;
57+
+
58+
+ virtual void set_cmux_status_flag(bool cmux_status) = 0;
59+
+
60+
/** Creates a new CellularContext interface.
61+
*
62+
* @param fh file handle used in communication to modem. This can be, for example, UART handle. If null, then the default
63+
diff --git a/connectivity/cellular/include/cellular/framework/AT/AT_CellularDevice.h b/connectivity/cellular/include/cellular/framework/AT/AT_CellularDevice.h
64+
index 5ee2d5cf2d..60ae735e79 100755
65+
--- a/connectivity/cellular/include/cellular/framework/AT/AT_CellularDevice.h
66+
+++ b/connectivity/cellular/include/cellular/framework/AT/AT_CellularDevice.h
67+
@@ -84,6 +84,14 @@ public:
68+
69+
virtual nsapi_error_t get_sim_state(SimState &state);
70+
71+
+ nsapi_error_t enable_cmux();
72+
+
73+
+ nsapi_error_t config_cmux();
74+
+
75+
+ void set_cmux_status_flag(bool cmux_status);
76+
+
77+
+ virtual bool is_cmux_enabled();
78+
+
79+
virtual CellularContext *create_context(const char *apn = NULL, bool cp_req = false, bool nonip_req = false);
80+
81+
virtual void delete_context(CellularContext *context);
82+
@@ -206,6 +214,7 @@ private:
83+
84+
std::chrono::duration<int, std::milli> _default_timeout;
85+
bool _modem_debug_on;
86+
+ bool _cmux_status;
87+
const intptr_t *_property_array;
88+
};
89+
90+
diff --git a/connectivity/cellular/source/framework/AT/AT_CellularDevice.cpp b/connectivity/cellular/source/framework/AT/AT_CellularDevice.cpp
91+
index 0b2d37e714..923fb11fbc 100644
92+
--- a/connectivity/cellular/source/framework/AT/AT_CellularDevice.cpp
93+
+++ b/connectivity/cellular/source/framework/AT/AT_CellularDevice.cpp
94+
@@ -241,6 +241,37 @@ nsapi_error_t AT_CellularDevice::get_sim_state(SimState &state)
95+
return error;
96+
}
97+
98+
+nsapi_error_t AT_CellularDevice::enable_cmux()
99+
+{
100+
+setup_at_handler();
101+
+
102+
+ _at.lock();
103+
+ for (int retry = 1; retry <= 3; retry++) {
104+
+ _at.clear_error();
105+
+ _at.flush();
106+
+ _at.at_cmd_discard("E0", "");
107+
+ if (_at.get_last_error() == NSAPI_ERROR_OK) {
108+
+ _at.at_cmd_discard("+CMUX", "=0");
109+
+ if (_at.get_last_error() == NSAPI_ERROR_OK) {
110+
+ break;
111+
+ }
112+
+ }
113+
+ tr_debug("Wait 100ms to init modem");
114+
+ rtos::ThisThread::sleep_for(100ms); // let modem have time to get ready
115+
+ }
116+
+ return _at.unlock_return_error();
117+
+}
118+
+
119+
+
120+
+bool AT_CellularDevice::is_cmux_enabled()
121+
+{
122+
+ return _cmux_status;
123+
+}
124+
+
125+
+void AT_CellularDevice::set_cmux_status_flag(bool cmux_status)
126+
+{
127+
+ _cmux_status = cmux_status;
128+
+}
129+
nsapi_error_t AT_CellularDevice::set_pin(const char *sim_pin)
130+
{
131+
// if SIM is already in ready state then settings the PIN
132+
diff --git a/connectivity/cellular/source/framework/device/CellularStateMachine.cpp b/connectivity/cellular/source/framework/device/CellularStateMachine.cpp
133+
index 0a452eacb3..833f1d2239 100644
134+
--- a/connectivity/cellular/source/framework/device/CellularStateMachine.cpp
135+
+++ b/connectivity/cellular/source/framework/device/CellularStateMachine.cpp
136+
@@ -361,6 +361,12 @@ void CellularStateMachine::state_device_ready()
137+
_cb_data.error = _cellularDevice.soft_power_on();
138+
}
139+
if (_cb_data.error == NSAPI_ERROR_OK) {
140+
+ if(_cellularDevice.is_cmux_enabled()){
141+
+ _cb_data.error = _cellularDevice.enable_cmux();
142+
+ if (_cb_data.error == NSAPI_ERROR_OK) {
143+
+ _cellularDevice.enableCMUXChannel();
144+
+ }
145+
+ }
146+
_cb_data.error = _cellularDevice.init();
147+
if (_cb_data.error == NSAPI_ERROR_OK) {
148+
149+
diff --git a/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp b/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp
150+
index c7790fe348..1f82199106 100644
151+
--- a/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp
152+
+++ b/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp
153+
@@ -51,6 +51,11 @@ AT_CellularNetwork *GEMALTO_CINTERION::open_network_impl(ATHandler &at)
154+
155+
nsapi_error_t GEMALTO_CINTERION::init()
156+
{
157+
+ // init CMUX if requested
158+
+ if(is_cmux_enabled()){
159+
+ enable_cmux();
160+
+ enableCMUXChannel();
161+
+ }
162+
nsapi_error_t err = AT_CellularDevice::init();
163+
if (err != NSAPI_ERROR_OK) {
164+
return err;
165+
@@ -67,7 +72,6 @@ nsapi_error_t GEMALTO_CINTERION::init()
166+
tr_error("Cellular model not found!");
167+
return NSAPI_ERROR_DEVICE_ERROR;
168+
}
169+
-
170+
if (memcmp(model, "ELS61", sizeof("ELS61") - 1) == 0) {
171+
init_module_els61();
172+
} else if (memcmp(model, "BGS2", sizeof("BGS2") - 1) == 0) {
173+
@@ -83,7 +87,6 @@ nsapi_error_t GEMALTO_CINTERION::init()
174+
return NSAPI_ERROR_UNSUPPORTED;
175+
}
176+
tr_info("Cinterion model %s (%d)", model, _module);
177+
-
178+
set_at_urcs();
179+
180+
return NSAPI_ERROR_OK;
181+
diff --git a/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularNetwork.cpp b/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularNetwork.cpp
182+
index 37ca733b6e..f749b4e575 100644
183+
--- a/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularNetwork.cpp
184+
+++ b/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularNetwork.cpp
185+
@@ -31,4 +31,9 @@ nsapi_error_t GEMALTO_CINTERION_CellularNetwork::set_attach()
186+
return NSAPI_ERROR_OK;
187+
}
188+
189+
+void GEMALTO_CINTERION_CellularNetwork::get_context_state_command()
190+
+{
191+
+ _at.cmd_start_stop("^SICA", "?");
192+
+ _at.resp_start("^SICA:");
193+
+}
194+
/* namespace mbed */
195+
diff --git a/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularNetwork.h b/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularNetwork.h
196+
index 8d5f49cf5a..7483c5e019 100644
197+
--- a/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularNetwork.h
198+
+++ b/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularNetwork.h
199+
@@ -26,6 +26,8 @@ public:
200+
GEMALTO_CINTERION_CellularNetwork(ATHandler &at, AT_CellularDevice &device);
201+
virtual ~GEMALTO_CINTERION_CellularNetwork();
202+
virtual nsapi_error_t set_attach();
203+
+ virtual void get_context_state_command();
204+
+
205+
206+
protected:
207+
};
208+
diff --git a/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularStack.cpp b/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularStack.cpp
209+
index 9f111d7da0..2993285049 100644
210+
--- a/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularStack.cpp
211+
+++ b/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularStack.cpp
212+
@@ -165,6 +165,11 @@ void GEMALTO_CINTERION_CellularStack::endGNSS() {
213+
_at.unlock();
214+
}
215+
216+
+void GEMALTO_CINTERION_CellularStack::enableCmux()
217+
+{
218+
+ _at.at_cmd_discard("+CMUX", "=0");
219+
+}
220+
+
221+
int GEMALTO_CINTERION_CellularStack::startGNSS() {
222+
_at.lock();
223+
_engine = false;
224+
@@ -304,10 +309,6 @@ retry_open:
225+
bool foundSrvType = false;
226+
bool foundConIdType = false;
227+
228+
- if (GEMALTO_CINTERION::get_module() == GEMALTO_CINTERION::ModuleTX62) {
229+
- _at.cmd_start_stop("^SICA", "=", "%d%d", 1, _cid);
230+
- }
231+
-
232+
_at.cmd_start_stop("^SISS", "?");
233+
_at.resp_start("^SISS:");
234+
235+
diff --git a/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularStack.h b/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularStack.h
236+
index 37eee5858a..f89da8c314 100644
237+
--- a/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularStack.h
238+
+++ b/connectivity/drivers/cellular/GEMALTO/CINTERION/GEMALTO_CINTERION_CellularStack.h
239+
@@ -37,6 +37,7 @@ public:
240+
void lock();
241+
void unlock();
242+
void beginGNSS(mbed::Callback<void(char*)> gnss_cb);
243+
+ void enableCmux();
244+
void endGNSS();
245+
int startGNSS();
246+
void stopGNSS();
247+
--
248+
2.34.1
249+

0 commit comments

Comments
 (0)