diff --git a/features/cellular/TESTS/api/cellular_sms/main.cpp b/features/cellular/TESTS/api/cellular_sms/main.cpp index 1c770c44ca4..79390bc0d6b 100644 --- a/features/cellular/TESTS/api/cellular_sms/main.cpp +++ b/features/cellular/TESTS/api/cellular_sms/main.cpp @@ -110,21 +110,21 @@ static void test_sms_initialize_text_mode() static void test_sms_initialize_pdu_mode() { nsapi_error_t err = sms->initialize(CellularSMS::CellularSMSMmodePDU); - TEST_ASSERT(err == NSAPI_ERROR_OK || (err == NSAPI_ERROR_DEVICE_ERROR && - ((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY)); + TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED || (err == NSAPI_ERROR_DEVICE_ERROR && + ((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY)); } static void test_set_cscs() { nsapi_error_t err = sms->set_cscs("IRA"); - TEST_ASSERT(err == NSAPI_ERROR_OK || (err == NSAPI_ERROR_DEVICE_ERROR && - ((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY)); + TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED || (err == NSAPI_ERROR_DEVICE_ERROR && + ((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY)); err = sms->set_cscs("UCS2"); - TEST_ASSERT(err == NSAPI_ERROR_OK || (err == NSAPI_ERROR_DEVICE_ERROR && - ((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY)); + TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED || (err == NSAPI_ERROR_DEVICE_ERROR && + ((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY)); err = sms->set_cscs("GSM"); - TEST_ASSERT(err == NSAPI_ERROR_OK || (err == NSAPI_ERROR_DEVICE_ERROR && - ((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY)); + TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED || (err == NSAPI_ERROR_DEVICE_ERROR && + ((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY)); } static void test_set_csca() @@ -143,8 +143,8 @@ static void test_set_csca() static void test_set_cpms_me() { nsapi_error_t err = sms->set_cpms("ME", "ME", "ME"); - TEST_ASSERT(err == NSAPI_ERROR_OK || (err == NSAPI_ERROR_DEVICE_ERROR && - ((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY)); + TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED || (err == NSAPI_ERROR_DEVICE_ERROR && + ((AT_CellularSMS *)sms)->get_device_error().errCode == SIM_BUSY)); } #ifdef MBED_CONF_APP_CELLULAR_PHONE_NUMBER diff --git a/features/cellular/framework/AT/AT_CellularBase.h b/features/cellular/framework/AT/AT_CellularBase.h index 4a993f40668..0e6ba258e1f 100644 --- a/features/cellular/framework/AT/AT_CellularBase.h +++ b/features/cellular/framework/AT/AT_CellularBase.h @@ -49,6 +49,10 @@ class AT_CellularBase { PROPERTY_AT_CGSN_WITH_TYPE, // 0 = not supported, 1 = supported. AT+CGSN without type is likely always supported similar to AT+GSN. PROPERTY_AT_CGDATA, // 0 = not supported, 1 = supported. Alternative is to support only ATD*99***# PROPERTY_AT_CGAUTH, // 0 = not supported, 1 = supported. APN authentication AT commands supported + PROPERTY_AT_CNMI, // 0 = not supported, 1 = supported. New message (SMS) indication AT command + PROPERTY_AT_CSMP, // 0 = not supported, 1 = supported. Set text mode AT command + PROPERTY_AT_CMGF, // 0 = not supported, 1 = supported. Set preferred message format AT command + PROPERTY_AT_CSDH, // 0 = not supported, 1 = supported. Show text mode AT command PROPERTY_IPV4_PDP_TYPE, // 0 = not supported, 1 = supported. Does modem support IPV4? PROPERTY_IPV6_PDP_TYPE, // 0 = not supported, 1 = supported. Does modem support IPV6? PROPERTY_IPV4V6_PDP_TYPE, // 0 = not supported, 1 = supported. Does modem support dual stack IPV4V6? diff --git a/features/cellular/framework/AT/AT_CellularSMS.cpp b/features/cellular/framework/AT/AT_CellularSMS.cpp index c4e24ced49a..435f513812e 100644 --- a/features/cellular/framework/AT/AT_CellularSMS.cpp +++ b/features/cellular/framework/AT/AT_CellularSMS.cpp @@ -210,6 +210,9 @@ void AT_CellularSMS::cmti_urc() nsapi_error_t AT_CellularSMS::set_cnmi() { + if (!get_property(PROPERTY_AT_CNMI)) { + return NSAPI_ERROR_UNSUPPORTED; + } _at.lock(); _at.cmd_start("AT+CNMI=2,1"); _at.cmd_stop_read_resp(); @@ -218,6 +221,9 @@ nsapi_error_t AT_CellularSMS::set_cnmi() nsapi_error_t AT_CellularSMS::set_cmgf(int msg_format) { + if (!get_property(PROPERTY_AT_CMGF)) { + return NSAPI_ERROR_UNSUPPORTED; + } _at.lock(); _at.cmd_start("AT+CMGF="); _at.write_int(msg_format); @@ -227,6 +233,9 @@ nsapi_error_t AT_CellularSMS::set_cmgf(int msg_format) nsapi_error_t AT_CellularSMS::set_csmp(int fo, int vp, int pid, int dcs) { + if (!get_property(PROPERTY_AT_CSMP)) { + return NSAPI_ERROR_UNSUPPORTED; + } _at.lock(); _at.cmd_start("AT+CSMP="); _at.write_int(fo); @@ -239,6 +248,9 @@ nsapi_error_t AT_CellularSMS::set_csmp(int fo, int vp, int pid, int dcs) nsapi_error_t AT_CellularSMS::set_csdh(int show_header) { + if (!get_property(PROPERTY_AT_CSDH)) { + return NSAPI_ERROR_UNSUPPORTED; + } _at.lock(); _at.cmd_start("AT+CSDH="); _at.write_int(show_header); diff --git a/features/cellular/framework/AT/AT_CellularStack.cpp b/features/cellular/framework/AT/AT_CellularStack.cpp index 8c09f738494..432ca3da66c 100644 --- a/features/cellular/framework/AT/AT_CellularStack.cpp +++ b/features/cellular/framework/AT/AT_CellularStack.cpp @@ -132,9 +132,7 @@ nsapi_error_t AT_CellularStack::socket_open(nsapi_socket_t *handle, nsapi_protoc tr_info("Socket %d open", index); // create local socket structure, socket on modem is created when app calls sendto/recvfrom _socket[index] = new CellularSocket; - CellularSocket *psock; - psock = _socket[index]; - memset(psock, 0, sizeof(CellularSocket)); + CellularSocket *psock = _socket[index]; SocketAddress addr(0, get_dynamic_ip_port()); psock->id = index; psock->localAddress = addr; diff --git a/features/cellular/framework/common/CellularTargets.h b/features/cellular/framework/common/CellularTargets.h index 2ffb377c4f6..60d46466410 100644 --- a/features/cellular/framework/common/CellularTargets.h +++ b/features/cellular/framework/common/CellularTargets.h @@ -32,8 +32,10 @@ namespace mbed { #elif TARGET_MTB_MTS_DRAGONFLY #define CELLULAR_DEVICE TELIT_HE910 #elif TARGET_UBLOX_C030 -#if defined(TARGET_UBLOX_C030_N211) || defined(TARGET_UBLOX_C030_R41XM) +#if defined(TARGET_UBLOX_C030_R41XM) #define CELLULAR_DEVICE UBLOX_AT +#elif defined(TARGET_UBLOX_C030_N211) +#define CELLULAR_DEVICE UBLOX_N2XX #else #define CELLULAR_DEVICE UBLOX_PPP #endif diff --git a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp index 26d7feb9f1c..3b21c90c755 100644 --- a/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp +++ b/features/cellular/framework/targets/GEMALTO/CINTERION/GEMALTO_CINTERION.cpp @@ -99,6 +99,10 @@ void GEMALTO_CINTERION::init_module_bgs2() 0, // AT_CGSN_WITH_TYPE 1, // AT_CGDATA 1, // AT_CGAUTH + 1, // AT_CNMI + 1, // AT_CSMP + 1, // AT_CMGF + 1, // AT_CSDH 1, // PROPERTY_IPV4_STACK 0, // PROPERTY_IPV6_STACK 0, // PROPERTY_IPV4V6_STACK diff --git a/features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.cpp b/features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.cpp index a7203fb0c43..5358346b664 100644 --- a/features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.cpp +++ b/features/cellular/framework/targets/GENERIC/GENERIC_AT3GPP/GENERIC_AT3GPP.cpp @@ -28,6 +28,10 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { 1, // AT_CGSN_WITH_TYPE 1, // AT_CGDATA 1, // AT_CGAUTH + 1, // AT_CNMI + 1, // AT_CSMP + 1, // AT_CMGF + 1, // AT_CSDH 1, // PROPERTY_IPV4_STACK 1, // PROPERTY_IPV6_STACK 1, // PROPERTY_IPV4V6_STACK diff --git a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp index 55fe2df1de2..79f617c82e7 100644 --- a/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp +++ b/features/cellular/framework/targets/MultiTech/DragonflyNano/PPP/SARA4_PPP.cpp @@ -28,6 +28,10 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { 0, // AT_CGSN_WITH_TYPE 0, // AT_CGDATA 1, // AT_CGAUTH + 1, // AT_CNMI + 1, // AT_CSMP + 1, // AT_CMGF + 1, // AT_CSDH 1, // PROPERTY_IPV4_STACK 0, // PROPERTY_IPV6_STACK 0, // PROPERTY_IPV4V6_STACK diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp index a76aedccb94..ef35e4f3a52 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.cpp @@ -35,6 +35,10 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { 1, // AT_CGSN_WITH_TYPE 1, // AT_CGDATA 0, // AT_CGAUTH, BC95_AT_Commands_Manual_V1.9 + 1, // AT_CNMI + 1, // AT_CSMP + 1, // AT_CMGF + 1, // AT_CSDH 1, // PROPERTY_IPV4_STACK 0, // PROPERTY_IPV6_STACK 0, // PROPERTY_IPV4V6_STACK diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp index 092652f354a..f45568cba87 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp @@ -37,6 +37,10 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { 0, // AT_CGSN_WITH_TYPE 0, // AT_CGDATA 1, // AT_CGAUTH + 1, // AT_CNMI + 1, // AT_CSMP + 1, // AT_CMGF + 1, // AT_CSDH 1, // PROPERTY_IPV4_STACK 0, // PROPERTY_IPV6_STACK 0, // PROPERTY_IPV4V6_STACK diff --git a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26.cpp b/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26.cpp index 612628a7a03..ee6b27dd7c0 100644 --- a/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26.cpp +++ b/features/cellular/framework/targets/QUECTEL/M26/QUECTEL_M26.cpp @@ -31,6 +31,10 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { 0, // AT_CGSN_WITH_TYPE 1, // AT_CGDATA 0, // AT_CGAUTH + 1, // AT_CNMI + 1, // AT_CSMP + 1, // AT_CMGF + 1, // AT_CSDH 1, // PROPERTY_IPV4_STACK 0, // PROPERTY_IPV6_STACK 0, // PROPERTY_IPV4V6_STACK diff --git a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp index 695ce9f5025..ebb20b1c731 100644 --- a/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp +++ b/features/cellular/framework/targets/QUECTEL/UG96/QUECTEL_UG96.cpp @@ -34,6 +34,10 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { 1, // AT_CGSN_WITH_TYPE 1, // AT_CGDATA 1, // AT_CGAUTH + 1, // AT_CNMI + 1, // AT_CSMP + 1, // AT_CMGF + 1, // AT_CSDH 1, // PROPERTY_IPV4_STACK 0, // PROPERTY_IPV6_STACK 0, // PROPERTY_IPV4V6_STACK diff --git a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp index cd25409d82b..6c40f91f96b 100644 --- a/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp +++ b/features/cellular/framework/targets/TELIT/HE910/TELIT_HE910.cpp @@ -28,6 +28,10 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { 0, // AT_CGSN_WITH_TYPE 1, // AT_CGDATA 0, // AT_CGAUTH + 1, // AT_CNMI + 1, // AT_CSMP + 1, // AT_CMGF + 1, // AT_CSDH 1, // PROPERTY_IPV4_STACK 0, // PROPERTY_IPV6_STACK 0, // PROPERTY_IPV4V6_STACK diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp index b4bb6cbfb3d..33d3b808a40 100644 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp +++ b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT.cpp @@ -29,7 +29,11 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { AT_CellularNetwork::RegistrationModeLAC, // C_REG 0, // AT_CGSN_WITH_TYPE 1, // AT_CGDATA - 1, // AT_CGAUTH, + 1, // AT_CGAUTH + 1, // AT_CNMI + 1, // AT_CSMP + 1, // AT_CMGF + 1, // AT_CSDH 1, // PROPERTY_IPV4_STACK 0, // PROPERTY_IPV6_STACK 0, // PROPERTY_IPV4V6_STACK @@ -42,6 +46,10 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { 1, // AT_CGSN_WITH_TYPE 1, // AT_CGDATA 1, // AT_CGAUTH + 1, // AT_CNMI + 1, // AT_CSMP + 1, // AT_CMGF + 1, // AT_CSDH 1, // PROPERTY_IPV4_STACK 0, // PROPERTY_IPV6_STACK 0, // PROPERTY_IPV4V6_STACK diff --git a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularStack.cpp b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularStack.cpp index 33e92ca4110..0c49d85c0e6 100644 --- a/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularStack.cpp +++ b/features/cellular/framework/targets/UBLOX/AT/UBLOX_AT_CellularStack.cpp @@ -296,6 +296,12 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_recvfrom_impl(CellularSocke _at.read_string(ipAddress, sizeof(ipAddress)); port = _at.read_int(); usorf_sz = _at.read_int(); + if (usorf_sz > size) { + usorf_sz = size; + } + _at.read_bytes(&ch, 1); + _at.read_bytes((uint8_t *)buffer + count, usorf_sz); + _at.resp_stop(); // Must use what +USORF returns here as it may be less or more than we asked for if (usorf_sz > socket->pending_bytes) { @@ -304,13 +310,6 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_recvfrom_impl(CellularSocke socket->pending_bytes -= usorf_sz; } - if (usorf_sz > size) { - usorf_sz = size; - } - _at.read_bytes(&ch, 1); - _at.read_bytes((uint8_t *)buffer + count, usorf_sz); - _at.resp_stop(); - if (usorf_sz > 0) { count += usorf_sz; size -= usorf_sz; @@ -345,6 +344,12 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_recvfrom_impl(CellularSocke _at.resp_start("+USORD:"); _at.skip_param(); // receiving socket id usorf_sz = _at.read_int(); + if (usorf_sz > size) { + usorf_sz = size; + } + _at.read_bytes(&ch, 1); + _at.read_bytes((uint8_t *)buffer + count, usorf_sz); + _at.resp_stop(); // Must use what +USORD returns here as it may be less or more than we asked for if (usorf_sz > socket->pending_bytes) { @@ -353,13 +358,6 @@ nsapi_size_or_error_t UBLOX_AT_CellularStack::socket_recvfrom_impl(CellularSocke socket->pending_bytes -= usorf_sz; } - if (usorf_sz > size) { - usorf_sz = size; - } - _at.read_bytes(&ch, 1); - _at.read_bytes((uint8_t *)buffer + count, usorf_sz); - _at.resp_stop(); - if (usorf_sz > 0) { count += usorf_sz; size -= usorf_sz; diff --git a/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.cpp b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.cpp new file mode 100644 index 00000000000..0aa1ede2d74 --- /dev/null +++ b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.cpp @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2019, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "UBLOX_N2XX.h" + +using namespace mbed; +using namespace events; + +static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { + AT_CellularNetwork::RegistrationModeLAC, // C_EREG + AT_CellularNetwork::RegistrationModeDisable, // C_GREG + AT_CellularNetwork::RegistrationModeDisable, // C_REG + 1, // AT_CGSN_WITH_TYPE + 0, // AT_CGDATA + 0, // AT_CGAUTH + 0, // AT_CNMI + 0, // AT_CSMP + 0, // AT_CMGF + 0, // AT_CSDH + 1, // PROPERTY_IPV4_STACK + 0, // PROPERTY_IPV6_STACK + 0, // PROPERTY_IPV4V6_STACK +}; + +UBLOX_N2XX::UBLOX_N2XX(FileHandle *fh): AT_CellularDevice(fh) +{ + AT_CellularBase::set_cellular_properties(cellular_properties); + _at->set_urc_handler("+NPIN:", mbed::Callback(this, &UBLOX_N2XX::NPIN_URC)); + memset(simstr,0,sizeof(simstr)); +} + +UBLOX_N2XX::~UBLOX_N2XX() +{ + _at->set_urc_handler("+NPIN:", NULL); +} + +// Callback for Sim Pin. +void UBLOX_N2XX::NPIN_URC() +{ + _at->read_string(simstr, sizeof(simstr)); +} + +AT_CellularContext *UBLOX_N2XX::create_context_impl(ATHandler &at, const char *apn, bool cp_req, bool nonip_req) +{ + return new UBLOX_N2XX_CellularContext(at, this, apn, cp_req, nonip_req); +} + +AT_CellularSMS *UBLOX_N2XX::open_sms_impl(ATHandler &at) +{ + return new UBLOX_N2XX_CellularSMS(at); +} + +nsapi_error_t UBLOX_N2XX::init() +{ + _at->lock(); + _at->flush(); + _at->cmd_start("AT"); // echo off + _at->cmd_stop_read_resp(); + + _at->cmd_start("AT+CMEE=1"); // verbose responses + _at->cmd_stop_read_resp(); + +#ifdef MBED_CONF_NSAPI_DEFAULT_CELLULAR_SIM_PIN + set_pin(MBED_CONF_NSAPI_DEFAULT_CELLULAR_SIM_PIN); +#endif + return _at->unlock_return_error(); +} + +nsapi_error_t UBLOX_N2XX::get_sim_state(SimState &state) +{ + nsapi_error_t error = NSAPI_ERROR_DEVICE_ERROR; + + _at->lock(); + _at->flush(); + _at->cmd_start("AT+CFUN=1"); + _at->cmd_stop(); + + _at->resp_start(); + _at->read_string(simstr, sizeof(simstr)); + _at->resp_stop(); + error = _at->unlock_return_error(); + + int len = strlen(simstr); + if (len > 0 || error == NSAPI_ERROR_OK) { + if (error == NSAPI_ERROR_OK) { + state = SimStateReady; + } else if (len >= 6 && memcmp(simstr, "ENTER PIN", 9) == 0) { + state = SimStatePinNeeded; + } else { + simstr[len] = '\0'; + tr_error("Unknown SIM state %s", simstr); + state = SimStateUnknown; + } + error = NSAPI_ERROR_OK; + } else { + tr_warn("SIM not readable."); + state = SimStateUnknown; // SIM may not be ready yet or pin command may not be supported + } + +#if MBED_CONF_MBED_TRACE_ENABLE + switch (state) { + case SimStatePinNeeded: + tr_info("SIM PIN required"); + break; + case SimStatePukNeeded: + tr_error("SIM PUK required"); + break; + case SimStateUnknown: + tr_warn("SIM state unknown"); + break; + default: + tr_info("SIM is ready"); + break; + } +#endif + return error; +} + +nsapi_error_t UBLOX_N2XX::set_pin(const char *sim_pin) +{ + // if SIM is already in ready state then settings the PIN + // will return error so let's check the state before settings the pin. + SimState state; + if (get_sim_state(state) == NSAPI_ERROR_OK && state == SimStateReady) { + return NSAPI_ERROR_OK; + } + + if (sim_pin == NULL) { + return NSAPI_ERROR_PARAMETER; + } + + _at->lock(); + _at->cmd_start("AT+NPIN=0,"); + _at->write_string(sim_pin); + _at->cmd_stop_read_resp(); + return _at->unlock_return_error(); +} diff --git a/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.h b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.h new file mode 100644 index 00000000000..4f96b1e772b --- /dev/null +++ b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2019, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef UBLOX_N2XX_H_ +#define UBLOX_N2XX_H_ + +#ifdef TARGET_FF_ARDUINO +#ifndef MBED_CONF_UBLOX_N2XX_TX +#define MBED_CONF_UBLOX_N2XX_TX D1 +#endif +#ifndef MBED_CONF_UBLOX_N2XX_RX +#define MBED_CONF_UBLOX_N2XX_RX D0 +#endif +#endif /* TARGET_FF_ARDUINO */ + +#include "mbed.h" +#include "CellularLog.h" +#include "AT_CellularDevice.h" +#include "AT_CellularNetwork.h" +#include "UBLOX_N2XX_CellularSMS.h" +#include "UBLOX_N2XX_CellularContext.h" + +namespace mbed { + +class UBLOX_N2XX : public AT_CellularDevice { + +public: + + UBLOX_N2XX(FileHandle *fh); + virtual ~UBLOX_N2XX(); + + virtual nsapi_error_t init(); + virtual nsapi_error_t get_sim_state(SimState &state); + virtual nsapi_error_t set_pin(const char *sim_pin); + + +protected: // AT_CellularDevice + + virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false); + virtual AT_CellularSMS *open_sms_impl(ATHandler &at); + +public: // NetworkInterface + + void handle_urc(FileHandle *fh); + +private: + + static const int MAX_SIM_RESPONSE_LENGTH = 25; + + // URC handlers + void NPIN_URC(); + + char simstr[MAX_SIM_RESPONSE_LENGTH]; +}; + +} // namespace mbed + +#endif // UBLOX_N2XX_H_ diff --git a/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularContext.cpp b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularContext.cpp new file mode 100644 index 00000000000..2d39c10429d --- /dev/null +++ b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularContext.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2019, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "UBLOX_N2XX_CellularContext.h" +#include "UBLOX_N2XX_CellularStack.h" +#include "CellularLog.h" +#include "APN_db.h" + +namespace mbed { + +UBLOX_N2XX_CellularContext::UBLOX_N2XX_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req, bool nonip_req): + AT_CellularContext(at, device, apn, cp_req, nonip_req) +{ +} + +UBLOX_N2XX_CellularContext::~UBLOX_N2XX_CellularContext() +{ +} + +#if !NSAPI_PPP_AVAILABLE +NetworkStack *UBLOX_N2XX_CellularContext::get_stack() +{ + if (_pdp_type == NON_IP_PDP_TYPE || _cp_in_use) { + tr_error("Requesting stack for NON-IP context! Should request control plane netif: get_cp_netif()"); + return NULL; + } + if (!_stack) { + _stack = new UBLOX_N2XX_CellularStack(_at, _cid, (nsapi_ip_stack_t)_pdp_type); + } + return _stack; +} +#endif + +} /* namespace mbed */ diff --git a/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularContext.h b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularContext.h new file mode 100644 index 00000000000..d2bd9d33277 --- /dev/null +++ b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularContext.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2019, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef UBLOX_N2XX_CELLULARCONTEXT_H_ +#define UBLOX_N2XX_CELLULARCONTEXT_H_ + +#include "AT_CellularContext.h" + +namespace mbed { + +class UBLOX_N2XX_CellularContext: public AT_CellularContext { + +public: + + UBLOX_N2XX_CellularContext(ATHandler &at, CellularDevice *device, const char *apn, bool cp_req = false, bool nonip_req = false); + virtual ~UBLOX_N2XX_CellularContext(); + +protected: + +#if !NSAPI_PPP_AVAILABLE + virtual NetworkStack *get_stack(); +#endif + +}; + +} /* namespace mbed */ + +#endif // UBLOX_N2XX_CELLULARCONTEXT_H_ diff --git a/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularSMS.cpp b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularSMS.cpp new file mode 100644 index 00000000000..08498b34523 --- /dev/null +++ b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularSMS.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2019, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "UBLOX_N2XX_CellularSMS.h" + +using namespace mbed; + +UBLOX_N2XX_CellularSMS::UBLOX_N2XX_CellularSMS(ATHandler &atHandler) : AT_CellularSMS(atHandler) +{ +} + +UBLOX_N2XX_CellularSMS::~UBLOX_N2XX_CellularSMS() +{ +} + +nsapi_error_t UBLOX_N2XX_CellularSMS::set_cpms(const char *memr, const char *memw, const char *mems) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_size_or_error_t UBLOX_N2XX_CellularSMS::set_cscs(const char *chr_set) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_size_or_error_t UBLOX_N2XX_CellularSMS::get_sms(char *buf, uint16_t len, char *phone_num, uint16_t phone_len, + char *time_stamp, uint16_t time_len, int *buf_size) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t UBLOX_N2XX_CellularSMS::delete_all_messages() +{ + return NSAPI_ERROR_UNSUPPORTED; +} diff --git a/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularSMS.h b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularSMS.h new file mode 100644 index 00000000000..eee36417080 --- /dev/null +++ b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularSMS.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2019, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef UBLOX_N2XX_CELLULAR_SMS_H_ +#define UBLOX_N2XX_CELLULAR_SMS_H_ + +#include "AT_CellularSMS.h" + +namespace mbed { + +class UBLOX_N2XX_CellularSMS : public AT_CellularSMS { + +public: + + UBLOX_N2XX_CellularSMS(ATHandler &atHandler); + virtual ~UBLOX_N2XX_CellularSMS(); + + virtual nsapi_error_t set_cpms(const char *memr, const char *memw, const char *mems); + + virtual nsapi_size_or_error_t set_cscs(const char *chr_set); + + virtual nsapi_size_or_error_t get_sms(char *buf, uint16_t buf_len, char *phone_num, uint16_t phone_len, + char *time_stamp, uint16_t time_len, int *buf_size); + + virtual nsapi_error_t delete_all_messages(); + +}; + +} // namespace mbed + +#endif // UBLOX_N2XX_CELLULAR_SMS_H_ diff --git a/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularStack.cpp b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularStack.cpp new file mode 100644 index 00000000000..e9d0287aa04 --- /dev/null +++ b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularStack.cpp @@ -0,0 +1,239 @@ +/* + * Copyright (c) 2019, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "UBLOX_N2XX_CellularStack.h" +#include "CellularUtil.h" +#include + +using namespace mbed; +using namespace mbed_cellular_util; + +UBLOX_N2XX_CellularStack::UBLOX_N2XX_CellularStack(ATHandler &atHandler, int cid, nsapi_ip_stack_t stack_type): AT_CellularStack(atHandler, cid, stack_type) +{ + // URC handlers for sockets + _at.set_urc_handler("+NSONMI:", callback(this, &UBLOX_N2XX_CellularStack::NSONMI_URC)); +} + +UBLOX_N2XX_CellularStack::~UBLOX_N2XX_CellularStack() +{ + _at.set_urc_handler("+NSONMI:", NULL); +} + +nsapi_error_t UBLOX_N2XX_CellularStack::socket_listen(nsapi_socket_t handle, int backlog) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +nsapi_error_t UBLOX_N2XX_CellularStack::socket_accept(void *server, void **socket, SocketAddress *addr) +{ + return NSAPI_ERROR_UNSUPPORTED; +} + +// Callback for Socket Read URC. +void UBLOX_N2XX_CellularStack::NSONMI_URC() +{ + int a, b; + CellularSocket *socket; + + a = _at.read_int(); + b = _at.read_int(); + + socket = find_socket(a); + if (socket != NULL) { + socket->pending_bytes = b; + // No debug prints here as they can affect timing + // and cause data loss in UARTSerial + if (socket->_cb != NULL) { + socket->_cb(socket->_data); + } + } +} + +int UBLOX_N2XX_CellularStack::get_max_socket_count() +{ + return N2XX_MAX_SOCKET; +} + +bool UBLOX_N2XX_CellularStack::is_protocol_supported(nsapi_protocol_t protocol) +{ + return (protocol == NSAPI_UDP); +} + +nsapi_error_t UBLOX_N2XX_CellularStack::create_socket_impl(CellularSocket *socket) +{ + int sock_id = 0; + int localport = socket->localAddress.get_port(); + + if(localport == 5683 || localport < 0 || localport > 65535) { + return NSAPI_ERROR_NO_SOCKET; + } + + _at.lock(); + _at.cmd_start("AT+NSOCR=\"DGRAM\",17,"); + _at.write_int(localport); + _at.write_int(1); + _at.cmd_stop(); + + _at.resp_start(); + sock_id = _at.read_int(); + _at.resp_stop(); + + if ((_at.get_last_error() != NSAPI_ERROR_OK) || (sock_id == -1)) { + _at.unlock(); + return NSAPI_ERROR_NO_SOCKET; + } + _at.unlock(); + + // Check for duplicate socket id delivered by modem + for (int i = 0; i < N2XX_MAX_SOCKET; i++) { + CellularSocket *sock = _socket[i]; + if (sock && sock->created && sock->id == sock_id) { + return NSAPI_ERROR_NO_SOCKET; + } + } + + socket->id = sock_id; + socket->created = true; + + return NSAPI_ERROR_OK; +} + +nsapi_size_or_error_t UBLOX_N2XX_CellularStack::socket_sendto_impl(CellularSocket *socket, const SocketAddress &address, + const void *data, nsapi_size_t size) +{ + if (size > N2XX_MAX_PACKET_SIZE) { + return NSAPI_ERROR_PARAMETER; + } + + int sent_len = 0; + char *dataStr = new char [(size * 2) + 1](); + if (!dataStr) + return NSAPI_ERROR_NO_MEMORY; + char_str_to_hex_str((const char*)data, size, dataStr); + + _at.cmd_start("AT+NSOST="); + _at.write_int(socket->id); + _at.write_string(address.get_ip_address()); + _at.write_int(address.get_port()); + _at.write_int(size); + _at.write_string(dataStr); + _at.cmd_stop(); + + _at.resp_start(); + _at.skip_param(); // skip socket id + sent_len = _at.read_int(); + _at.resp_stop(); + + delete[] dataStr; + if ((_at.get_last_error() == NSAPI_ERROR_OK)) { + return sent_len; + } + + return _at.get_last_error(); +} + +nsapi_size_or_error_t UBLOX_N2XX_CellularStack::socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address, + void *buffer, nsapi_size_t size) +{ + nsapi_size_or_error_t nsapi_error_size = NSAPI_ERROR_DEVICE_ERROR; + nsapi_size_t read_blk, usorf_sz, count = 0, length = size; + bool success = true; + char ipAddress[NSAPI_IP_SIZE]; + int port = 0; + Timer timer; + + if (socket->pending_bytes == 0) { + _at.process_oob(); + if (socket->pending_bytes == 0) { + return NSAPI_ERROR_WOULD_BLOCK; + } + } + + timer.start(); + while (success && (length > 0)) { + read_blk = N2XX_MAX_PACKET_SIZE; + if (read_blk > length) { + read_blk = length; + } + if (socket->pending_bytes > 0) { + _at.cmd_start("AT+NSORF="); + _at.write_int(socket->id); + _at.write_int(read_blk); + _at.cmd_stop(); + + _at.resp_start(); + _at.skip_param(); // receiving socket id + _at.read_string(ipAddress, sizeof(ipAddress)); + port = _at.read_int(); + usorf_sz = _at.read_int(); + if (usorf_sz > length) { + usorf_sz = length; + } + _at.read_hex_string((char *)buffer + count, usorf_sz); + _at.resp_stop(); + + // Must use what +NSORF returns here as it may be less or more than we asked for + if (usorf_sz >= socket->pending_bytes) { + socket->pending_bytes = 0; + } else { + socket->pending_bytes -= usorf_sz; + } + + if (usorf_sz > 0) { + count += (usorf_sz); + length -= (usorf_sz); + } else { + // read() should not fail + success = false; + } + } else if (timer.read_ms() < SOCKET_TIMEOUT) { + // Wait for URCs + _at.process_oob(); + } else { + if (count == 0) { + // Timeout with nothing received + nsapi_error_size = NSAPI_ERROR_WOULD_BLOCK; + success = false; + } + length = 0; // This simply to cause an exit + } + } + timer.stop(); + + socket->pending_bytes = 0; + if (!count || (_at.get_last_error() != NSAPI_ERROR_OK)) { + return NSAPI_ERROR_WOULD_BLOCK; + } + + if (success && socket->proto == NSAPI_UDP && address) { + address->set_ip_address(ipAddress); + address->get_ip_address(); + address->set_port(port); + } + + return nsapi_error_size = count; +} + +nsapi_error_t UBLOX_N2XX_CellularStack::socket_close_impl(int sock_id) +{ + _at.lock(); + _at.cmd_start("AT+NSOCL="); + _at.write_int(sock_id); + _at.cmd_stop_read_resp(); + + return _at.unlock_return_error(); +} diff --git a/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularStack.h b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularStack.h new file mode 100644 index 00000000000..638e2217b5d --- /dev/null +++ b/features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX_CellularStack.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2019, Arm Limited and affiliates. + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef UBLOX_N2XX_CELLULARSTACK_H_ +#define UBLOX_N2XX_CELLULARSTACK_H_ + +#include "AT_CellularStack.h" +#include "CellularUtil.h" +#include "mbed_wait_api.h" +#include "drivers/Timer.h" + +namespace mbed { + +class UBLOX_N2XX_CellularStack : public AT_CellularStack { + +public: + + UBLOX_N2XX_CellularStack(ATHandler &atHandler, int cid, nsapi_ip_stack_t stack_type); + virtual ~UBLOX_N2XX_CellularStack(); + +protected: + + virtual nsapi_error_t socket_listen(nsapi_socket_t handle, int backlog); + + virtual nsapi_error_t socket_accept(nsapi_socket_t server, + nsapi_socket_t *handle, SocketAddress *address = 0); + +protected: + + /** Socket timeout value in milliseconds. + * Note: the sockets layer above will retry the + * call to the functions here when they return NSAPI_ERROR_WOULD_BLOCK + * and the user has set a larger timeout or full blocking. + */ + static const int SOCKET_TIMEOUT = 1000; + + /** Maximum allowed sockets. + */ + static const int N2XX_MAX_SOCKET = 7; + + /** The maximum number of bytes in a packet that can be write/read from + * the AT interface in one go. + */ + static const int N2XX_MAX_PACKET_SIZE = 512; + + virtual int get_max_socket_count(); + + virtual bool is_protocol_supported(nsapi_protocol_t protocol); + + virtual nsapi_error_t create_socket_impl(CellularSocket *socket); + + virtual nsapi_size_or_error_t socket_sendto_impl(CellularSocket *socket, const SocketAddress &address, + const void *data, nsapi_size_t size); + + virtual nsapi_size_or_error_t socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address, + void *buffer, nsapi_size_t size); + + virtual nsapi_error_t socket_close_impl(int sock_id); + +private: + + // URC handlers + void NSONMI_URC(); +}; + +} // namespace mbed + +#endif // UBLOX_N2XX_CELLULARSTACK_H_ diff --git a/features/cellular/framework/targets/UBLOX/N2XX/mbed_lib.json b/features/cellular/framework/targets/UBLOX/N2XX/mbed_lib.json new file mode 100644 index 00000000000..e4af2bade84 --- /dev/null +++ b/features/cellular/framework/targets/UBLOX/N2XX/mbed_lib.json @@ -0,0 +1,29 @@ +{ + "name": "UBLOX_N2XX", + "config": { + "tx": { + "help": "TX pin for serial connection. D1 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.", + "value": null + }, + "rx": { + "help": "RX pin for serial connection. D0 assumed if Arduino Form Factor, needs to be set/overwritten otherwise.", + "value": null + }, + "rts": { + "help": "RTS pin for serial connection", + "value": null + }, + "cts": { + "help": "CTS pin for serial connection", + "value": null + }, + "baudrate" : { + "help": "Serial connection baud rate", + "value": 9600 + }, + "provide-default": { + "help": "Provide as default CellularDevice [true/false]", + "value": false + } + } +} diff --git a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp index 0acc86b7c5b..2f09de4d759 100644 --- a/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp +++ b/features/cellular/framework/targets/UBLOX/PPP/UBLOX_PPP.cpp @@ -29,6 +29,10 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { 0, // AT_CGSN_WITH_TYPE 1, // AT_CGDATA 1, // AT_CGAUTH + 1, // AT_CNMI + 1, // AT_CSMP + 1, // AT_CMGF + 1, // AT_CSDH 1, // PROPERTY_IPV4_STACK 0, // PROPERTY_IPV6_STACK 0, // PROPERTY_IPV4V6_STACK @@ -41,6 +45,10 @@ static const intptr_t cellular_properties[AT_CellularBase::PROPERTY_MAX] = { 1, // AT_CGSN_WITH_TYPE 1, // AT_CGDATA 1, // AT_CGAUTH + 1, // AT_CNMI + 1, // AT_CSMP + 1, // AT_CMGF + 1, // AT_CSDH 1, // PROPERTY_IPV4_STACK 0, // PROPERTY_IPV6_STACK 0, // PROPERTY_IPV4V6_STACK diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX.cpp b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX.cpp index fd630a8422d..b6ec7052ed2 100644 --- a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX.cpp +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX.cpp @@ -18,17 +18,21 @@ #include "ONBOARD_UBLOX_AT.h" #include "ONBOARD_UBLOX_PPP.h" +#include "ONBOARD_UBLOX_N2XX.h" #include "UARTSerial.h" using namespace mbed; CellularDevice *CellularDevice::get_target_default_instance() { -#if defined(TARGET_UBLOX_C030_N211) || defined(TARGET_UBLOX_C030_R41XM) - static UARTSerial serial(MDMTXD, MDMRXD, 115200); +#if defined(TARGET_UBLOX_C030_R410M) + static UARTSerial serial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE); static ONBOARD_UBLOX_AT device(&serial); +#elif defined(TARGET_UBLOX_C030_N211) + static UARTSerial serial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE); + static ONBOARD_UBLOX_N2XX device(&serial); #else - static UARTSerial serial(MDMTXD, MDMRXD, 115200); + static UARTSerial serial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE); static ONBOARD_UBLOX_PPP device(&serial); #endif return &device; diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_N2XX.cpp b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_N2XX.cpp new file mode 100644 index 00000000000..4d867beab0d --- /dev/null +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_N2XX.cpp @@ -0,0 +1,52 @@ +/* mbed Microcontroller Library + * Copyright (c) 2018 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#if MBED_CONF_NSAPI_PRESENT + +#include "ONBOARD_UBLOX_N2XX.h" +#include "cellular/onboard_modem_api.h" + +using namespace mbed; + +ONBOARD_UBLOX_N2XX::ONBOARD_UBLOX_N2XX(FileHandle *fh) : UBLOX_N2XX(fh) +{ +} + +nsapi_error_t ONBOARD_UBLOX_N2XX::hard_power_on() +{ + ::onboard_modem_init(); + return NSAPI_ERROR_OK; +} + +nsapi_error_t ONBOARD_UBLOX_N2XX::hard_power_off() +{ + ::onboard_modem_deinit(); + return NSAPI_ERROR_OK; +} + +nsapi_error_t ONBOARD_UBLOX_N2XX::soft_power_on() +{ + ::onboard_modem_power_up(); + return NSAPI_ERROR_OK; +} + +nsapi_error_t ONBOARD_UBLOX_N2XX::soft_power_off() +{ + ::onboard_modem_power_down(); + return NSAPI_ERROR_OK; +} + +#endif // MBED_CONF_NSAPI_PRESENT diff --git a/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_N2XX.h b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_N2XX.h new file mode 100644 index 00000000000..a12a5a55ffe --- /dev/null +++ b/targets/TARGET_STM/TARGET_STM32F4/TARGET_STM32F437xG/TARGET_UBLOX_C030/ONBOARD_UBLOX_N2XX.h @@ -0,0 +1,36 @@ +/* mbed Microcontroller Library + * Copyright (c) 2018 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ONBOARD_UBLOX_N2XX_ +#define ONBOARD_UBLOX_N2XX_ + +#include "UBLOX_N2XX.h" + +namespace mbed { + +class ONBOARD_UBLOX_N2XX : public UBLOX_N2XX { +public: + ONBOARD_UBLOX_N2XX(FileHandle *fh); + + virtual nsapi_error_t hard_power_on(); + virtual nsapi_error_t hard_power_off(); + virtual nsapi_error_t soft_power_on(); + virtual nsapi_error_t soft_power_off(); +}; + +} // namespace mbed + +#endif // ONBOARD_UBLOX_N2XX_