Skip to content

Commit 411b91c

Browse files
Initial attempt at porting Arduino's Cinterion TX62 patch
1 parent 8357e3e commit 411b91c

File tree

15 files changed

+222
-6
lines changed

15 files changed

+222
-6
lines changed

connectivity/cellular/include/cellular/framework/API/ATHandler.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,12 @@ class ATHandler {
363363
*/
364364
void write_hex_string(const char *str, size_t size, bool quote_string = true);
365365

366+
/** Get the error detected during read_int()
367+
*
368+
* @return the latest negative integer error got from read_int().
369+
*/
370+
int32_t get_last_read_error() const;
371+
366372
/** Reads as string and converts result to integer. Supports only non-negative integers.
367373
*
368374
* @return the non-negative integer or -1 in case of error.
@@ -599,6 +605,7 @@ class ATHandler {
599605
nsapi_error_t _last_err;
600606
int _last_3gpp_error;
601607
device_err_t _last_at_err;
608+
int32_t _last_read_error{};
602609
uint16_t _oob_string_max_length;
603610
char *_output_delimiter;
604611

connectivity/cellular/include/cellular/framework/API/CellularContext.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,29 @@ namespace mbed {
4141
* @{
4242
*/
4343

44+
/// Radio Access Technology type
45+
enum RadioAccessTechnologyType {
46+
CATM1 = 7, ///< LTE CAT-M or LTE-M
47+
CATNB = 8 ///< NB-IoT (Narrowband IoT)
48+
};
49+
50+
enum FrequencyBand {
51+
BAND_1 = 0x01,
52+
BAND_2 = 0x02,
53+
BAND_3 = 0x04,
54+
BAND_4 = 0x08,
55+
BAND_5 = 0x10,
56+
BAND_8 = 0x80,
57+
BAND_12 = 0x800,
58+
BAND_13 = 0x1000,
59+
BAND_18 = 0x20000,
60+
BAND_19 = 0x40000,
61+
BAND_20 = 0x80000,
62+
BAND_25 = 0x1000000,
63+
BAND_26 = 0x2000000,
64+
BAND_28 = 0x8000000
65+
};
66+
4467
/// CellularContext is CellularInterface/NetworkInterface with extensions for cellular connectivity
4568
class CellularContext : public CellularInterface {
4669

@@ -158,6 +181,8 @@ class CellularContext : public CellularInterface {
158181
virtual nsapi_error_t connect(const char *sim_pin, const char *apn = 0, const char *uname = 0,
159182
const char *pwd = 0) = 0;
160183
virtual void set_credentials(const char *apn, const char *uname = 0, const char *pwd = 0) = 0;
184+
virtual void set_access_technology(RadioAccessTechnologyType rat = CATM1) = 0;
185+
virtual void set_band(FrequencyBand band = BAND_20) = 0;
161186
virtual bool is_connected() = 0;
162187

163188
/** Same as NetworkInterface::get_default_instance()

connectivity/cellular/include/cellular/framework/AT/AT_CellularContext.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "rtos/Semaphore.h"
2323
#include "AT_CellularDevice.h"
2424

25+
#include <optional>
2526

2627
const int MAX_APN_LENGTH = 63 + 1;
2728

@@ -54,6 +55,8 @@ class AT_CellularContext : public CellularContext {
5455
virtual nsapi_error_t connect(const char *sim_pin, const char *apn = 0, const char *uname = 0,
5556
const char *pwd = 0);
5657
virtual void set_credentials(const char *apn, const char *uname = 0, const char *pwd = 0);
58+
virtual void set_access_technology(RadioAccessTechnologyType rat = CATM1);
59+
virtual void set_band(FrequencyBand band = BAND_20);
5760

5861
// from CellularContext
5962
virtual nsapi_error_t get_pdpcontext_params(pdpContextList_t &params_list);
@@ -115,6 +118,13 @@ class AT_CellularContext : public CellularContext {
115118
*/
116119
virtual const char *get_nonip_context_type_str();
117120

121+
/**
122+
* @brief Set the cellular technology and band based on the \c _rat and \c _band class variables.
123+
*
124+
* Modems which support this functionality should override this in their CellularContext implementations.
125+
*/
126+
virtual void enable_access_technology() {}
127+
118128
private:
119129
#if NSAPI_PPP_AVAILABLE
120130
nsapi_error_t open_data_channel();
@@ -146,6 +156,8 @@ class AT_CellularContext : public CellularContext {
146156
bool _cp_req;
147157
bool _is_connected;
148158
ATHandler &_at;
159+
std::optional<RadioAccessTechnologyType> _rat;
160+
std::optional<FrequencyBand> _band;
149161
};
150162

151163
/**

connectivity/cellular/source/framework/AT/AT_CellularContext.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,19 @@ nsapi_error_t AT_CellularContext::connect()
109109
}
110110
call_network_cb(NSAPI_STATUS_CONNECTING);
111111

112+
set_device_ready();
113+
114+
_at.lock();
115+
bool valid_context = get_context();
116+
_at.unlock();
117+
if(!valid_context) {
118+
set_new_context(_cid);
119+
}
120+
121+
do_user_authentication();
122+
123+
enable_access_technology();
124+
112125
nsapi_error_t err = _device->attach_to_network();
113126
_cb_data.error = check_operation(err, OP_CONNECT);
114127
_retry_count = 0;
@@ -278,6 +291,16 @@ void AT_CellularContext::set_credentials(const char *apn, const char *uname, con
278291
_pwd = pwd;
279292
}
280293

294+
void AT_CellularContext::set_access_technology(RadioAccessTechnologyType rat)
295+
{
296+
_rat = rat;
297+
}
298+
299+
void AT_CellularContext::set_band(FrequencyBand band)
300+
{
301+
_band = band;
302+
}
303+
281304
// PDP Context handling
282305
void AT_CellularContext::delete_current_context()
283306
{
@@ -352,7 +375,7 @@ bool AT_CellularContext::get_context()
352375
int pdp_type_len = _at.read_string(pdp_type_from_context, sizeof(pdp_type_from_context));
353376
if (pdp_type_len > 0) {
354377
apn_len = _at.read_string(apn, sizeof(apn));
355-
if (apn_len >= 0) {
378+
if (apn_len > 0) {
356379
if (_apn && (strcmp(apn, _apn) != 0)) {
357380
tr_debug("CID %d APN \"%s\"", cid, apn);
358381
continue;
@@ -370,6 +393,9 @@ bool AT_CellularContext::get_context()
370393
set_cid(cid);
371394
}
372395
}
396+
else {
397+
cid_max = 0;
398+
}
373399
}
374400
}
375401

connectivity/cellular/source/framework/AT/AT_CellularDevice.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,8 @@ nsapi_error_t AT_CellularDevice::init()
414414
_at.flush();
415415
_at.at_cmd_discard("E0", "");
416416
if (_at.get_last_error() == NSAPI_ERROR_OK) {
417-
_at.at_cmd_discard("+CMEE", "=1");
417+
// Enable verbose error messages
418+
_at.at_cmd_discard("+CMEE", "=2");
418419
_at.at_cmd_discard("+CFUN", "=1");
419420
if (_at.get_last_error() == NSAPI_ERROR_OK) {
420421
break;

connectivity/cellular/source/framework/AT/AT_CellularNetwork.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ nsapi_error_t AT_CellularNetwork::set_registration(const char *plmn)
219219
return NSAPI_ERROR_DEVICE_ERROR;
220220
}
221221
if (mode != NWModeAutomatic) {
222+
// Force operator registration
222223
return _at.at_cmd_discard("+COPS", "=0");
223224
}
224225
return NSAPI_ERROR_OK;

connectivity/cellular/source/framework/device/ATHandler.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ using namespace std::chrono_literals;
4646
#define PROCESS_URC_TIME 20ms
4747

4848
// Suppress logging of very big packet payloads, maxlen is approximate due to write/read are cached
49-
#define DEBUG_MAXLEN 60
49+
#define DEBUG_MAXLEN 120
5050
#define DEBUG_END_MARK "..\r"
5151

5252
const char *mbed::OK = "OK\r\n";
@@ -697,6 +697,11 @@ ssize_t ATHandler::read_hex_string(char *buf, size_t size)
697697
return buf_idx;
698698
}
699699

700+
int32_t ATHandler::get_last_read_error() const
701+
{
702+
return _last_read_error;
703+
}
704+
700705
int32_t ATHandler::read_int()
701706
{
702707
if (!ok_to_proceed() || !_stop_tag || _stop_tag->found) {
@@ -711,9 +716,11 @@ int32_t ATHandler::read_int()
711716
errno = 0;
712717
long result = std::strtol(buff, NULL, 10);
713718
if ((result == LONG_MIN || result == LONG_MAX) && errno == ERANGE) {
719+
_last_read_error = result;
714720
return -1; // overflow/underflow
715721
}
716722
if (result < 0) {
723+
_last_read_error = result;
717724
return -1; // negative values are unsupported
718725
}
719726
if (*buff == '\0') {

connectivity/cellular/source/framework/device/CellularStateMachine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ using namespace std::chrono_literals;
2828

2929
// timeout to wait for AT responses
3030
#define TIMEOUT_POWER_ON 1s
31-
#define TIMEOUT_SIM_PIN 1s
31+
#define TIMEOUT_SIM_PIN 10s
3232
#define TIMEOUT_NETWORK 10s
3333
/** CellularStateMachine does connecting up to packet service attach, and
3434
* after that it's up to CellularContext::connect() to connect to PDN.

connectivity/drivers/cellular/GEMALTO/COMPONENT_GEMALTO_CINTERION/GEMALTO_CINTERION.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ nsapi_error_t GEMALTO_CINTERION::init()
7070
init_module_ems31();
7171
} else if (memcmp(model, "EHS5-E", sizeof("EHS5-E") - 1) == 0) {
7272
init_module_ehs5e();
73+
} else if (memcmp(model, "TX62", sizeof("TX62") - 1) == 0) {
74+
init_module_tx62();
7375
} else {
7476
tr_error("Cinterion model unsupported %s", model);
7577
return NSAPI_ERROR_UNSUPPORTED;
@@ -202,6 +204,35 @@ void GEMALTO_CINTERION::init_module_ehs5e()
202204
_module = ModuleEHS5E;
203205
}
204206

207+
void GEMALTO_CINTERION::init_module_tx62()
208+
{
209+
// TX-62
210+
static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
211+
AT_CellularNetwork::RegistrationModeLAC,// C_EREG
212+
AT_CellularNetwork::RegistrationModeDisable, // C_GREG
213+
AT_CellularNetwork::RegistrationModeDisable, // C_REG
214+
0, // AT_CGSN_WITH_TYPE
215+
0, // AT_CGDATA
216+
1, // AT_CGAUTH
217+
1, // AT_CNMI
218+
1, // AT_CSMP
219+
1, // AT_CMGF
220+
0, // AT_CSDH
221+
1, // PROPERTY_IPV4_STACK
222+
0, // PROPERTY_IPV6_STACK
223+
0, // PROPERTY_IPV4V6_STACK
224+
0, // PROPERTY_NON_IP_PDP_TYPE
225+
0, // PROPERTY_AT_CGEREP
226+
0, // PROPERTY_AT_COPS_FALLBACK_AUTO
227+
7, // PROPERTY_SOCKET_COUNT
228+
1, // PROPERTY_IP_TCP
229+
1, // PROPERTY_IP_UDP
230+
100, // PROPERTY_AT_SEND_DELAY
231+
};
232+
set_cellular_properties(cellular_properties);
233+
_module = ModuleTX62;
234+
}
235+
205236
#if MBED_CONF_GEMALTO_CINTERION_PROVIDE_DEFAULT
206237
#include "drivers/BufferedSerial.h"
207238
CellularDevice *CellularDevice::get_default_instance()

connectivity/drivers/cellular/GEMALTO/COMPONENT_GEMALTO_CINTERION/GEMALTO_CINTERION.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class GEMALTO_CINTERION : public AT_CellularDevice {
4444
ModuleBGS2,
4545
ModuleEMS31,
4646
ModuleEHS5E,
47+
ModuleTX62,
4748
};
4849
static Module get_module();
4950

@@ -60,6 +61,7 @@ class GEMALTO_CINTERION : public AT_CellularDevice {
6061
void init_module_els61();
6162
void init_module_ems31();
6263
void init_module_ehs5e();
64+
void init_module_tx62();
6365
};
6466

6567
} // namespace mbed

0 commit comments

Comments
 (0)