Skip to content

Commit

Permalink
Disable SMS by default from Cellular stack
Browse files Browse the repository at this point in the history
  • Loading branch information
Antti Kauppila committed Nov 15, 2019
1 parent 6993724 commit 64add0f
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@ set(unittest-test-sources
stubs/ConditionVariable_stub.cpp
stubs/Mutex_stub.cpp
)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_CELLULAR_USE_SMS=1")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_CELLULAR_USE_SMS=1")


6 changes: 3 additions & 3 deletions UNITTESTS/stubs/NetworkInterfaceDefaults_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
#include "netsocket/NetworkInterface.h"
#include "WiFiInterface.h"
#include "CellularBase.h"
#include "CellularInterface.h"
#include "MeshInterface.h"

MBED_WEAK WiFiInterface *WiFiInterface::get_default_instance()
Expand All @@ -29,7 +29,7 @@ MBED_WEAK MeshInterface *MeshInterface::get_default_instance()
return NULL;
}

MBED_WEAK CellularBase *CellularBase::get_default_instance()
MBED_WEAK CellularInterface *CellularInterface::get_default_instance()
{
return NULL;
}
Expand All @@ -52,7 +52,7 @@ void WiFiInterface::set_default_parameters()
{
}

void CellularBase::set_default_parameters()
void CellularInterface::set_default_parameters()
{
}

Expand Down
13 changes: 9 additions & 4 deletions features/cellular/framework/API/CellularDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ class CellularDevice {
*/
virtual CellularNetwork *open_network(FileHandle *fh = NULL) = 0;

#if MBED_CONF_CELLULAR_USE_SMS || defined(DOXYGEN_ONLY)
/** Create new CellularSMS interface.
*
* @param fh file handle used in communication to modem. This can be, for example, UART handle. If null, then the default
Expand All @@ -322,6 +323,12 @@ class CellularDevice {
*/
virtual CellularSMS *open_sms(FileHandle *fh = NULL) = 0;

/** Closes the opened CellularSMS by deleting the CellularSMS instance.
*/
virtual void close_sms() = 0;

#endif // MBED_CONF_CELLULAR_USE_SMS

/** Create new CellularInformation interface.
*
* @param fh file handle used in communication to modem. This can be, for example, UART handle. If null, then the default
Expand All @@ -334,10 +341,6 @@ class CellularDevice {
*/
virtual void close_network() = 0;

/** Closes the opened CellularSMS by deleting the CellularSMS instance.
*/
virtual void close_sms() = 0;

/** Closes the opened CellularInformation by deleting the CellularInformation instance.
*/
virtual void close_information() = 0;
Expand Down Expand Up @@ -472,7 +475,9 @@ class CellularDevice {
virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr, CellularContext *ctx = NULL);
void stm_callback(nsapi_event_t ev, intptr_t ptr);
int _network_ref_count;
#if MBED_CONF_CELLULAR_USE_SMS
int _sms_ref_count;
#endif // MBED_CONF_CELLULAR_USE_SMS
int _info_ref_count;
FileHandle *_fh;
events::EventQueue _queue;
Expand Down
4 changes: 4 additions & 0 deletions features/cellular/framework/API/CellularSMS.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#ifndef CELLULAR_SMS_H_
#define CELLULAR_SMS_H_

#if MBED_CONF_CELLULAR_USE_SMS

#include "Callback.h"
#include "nsapi_types.h"

Expand Down Expand Up @@ -179,4 +181,6 @@ class CellularSMS {

} // namespace mbed

#endif // MBED_CONF_CELLULAR_USE_SMS

#endif // CELLULAR_SMS_H_
60 changes: 36 additions & 24 deletions features/cellular/framework/AT/AT_CellularDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ using namespace mbed;
#define DEFAULT_AT_TIMEOUT 1000 // at default timeout in milliseconds
const int MAX_SIM_RESPONSE_LENGTH = 16;

AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh), _network(0), _sms(0),
_information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT),
AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh),
#if MBED_CONF_CELLULAR_USE_SMS
_sms(0),
#endif // MBED_CONF_CELLULAR_USE_SMS
_network(0), _information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT),
_modem_debug_on(false)
{
MBED_ASSERT(fh);
Expand All @@ -58,11 +61,17 @@ AT_CellularDevice::~AT_CellularDevice()

// make sure that all is deleted even if somewhere close was not called and reference counting is messed up.
_network_ref_count = 1;
#if MBED_CONF_CELLULAR_USE_SMS
_sms_ref_count = 1;
#endif // MBED_CONF_CELLULAR_USE_SMS
_info_ref_count = 1;

close_network();

#if MBED_CONF_CELLULAR_USE_SMS
close_sms();
#endif //MBED_CONF_CELLULAR_USE_SMS

close_information();

AT_CellularContext *curr = _context_list;
Expand Down Expand Up @@ -350,15 +359,6 @@ CellularNetwork *AT_CellularDevice::open_network(FileHandle *fh)
return _network;
}

CellularSMS *AT_CellularDevice::open_sms(FileHandle *fh)
{
if (!_sms) {
_sms = open_sms_impl(*get_at_handler(fh));
}
_sms_ref_count++;
return _sms;
}

CellularInformation *AT_CellularDevice::open_information(FileHandle *fh)
{
if (!_information) {
Expand All @@ -373,10 +373,35 @@ AT_CellularNetwork *AT_CellularDevice::open_network_impl(ATHandler &at)
return new AT_CellularNetwork(at);
}

#if MBED_CONF_CELLULAR_USE_SMS

CellularSMS *AT_CellularDevice::open_sms(FileHandle *fh)
{
if (!_sms) {
_sms = open_sms_impl(*get_at_handler(fh));
}
_sms_ref_count++;
return _sms;
}

void AT_CellularDevice::close_sms()
{
if (_sms) {
_sms_ref_count--;
if (_sms_ref_count == 0) {
ATHandler *atHandler = &_sms->get_at_handler();
delete _sms;
_sms = NULL;
release_at_handler(atHandler);
}
}
}

AT_CellularSMS *AT_CellularDevice::open_sms_impl(ATHandler &at)
{
return new AT_CellularSMS(at);
}
#endif // MBED_CONF_CELLULAR_USE_SMS

AT_CellularInformation *AT_CellularDevice::open_information_impl(ATHandler &at)
{
Expand All @@ -396,19 +421,6 @@ void AT_CellularDevice::close_network()
}
}

void AT_CellularDevice::close_sms()
{
if (_sms) {
_sms_ref_count--;
if (_sms_ref_count == 0) {
ATHandler *atHandler = &_sms->get_at_handler();
delete _sms;
_sms = NULL;
release_at_handler(atHandler);
}
}
}

void AT_CellularDevice::close_information()
{
if (_information) {
Expand Down
29 changes: 17 additions & 12 deletions features/cellular/framework/AT/AT_CellularDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,10 @@ class AT_CellularDevice : public CellularDevice {

virtual CellularNetwork *open_network(FileHandle *fh = NULL);

virtual CellularSMS *open_sms(FileHandle *fh = NULL);

virtual CellularInformation *open_information(FileHandle *fh = NULL);

virtual void close_network();

virtual void close_sms();

virtual void close_information();

virtual void set_timeout(int timeout);
Expand Down Expand Up @@ -119,13 +115,6 @@ class AT_CellularDevice : public CellularDevice {
*/
virtual AT_CellularNetwork *open_network_impl(ATHandler &at);

/** Create new instance of AT_CellularSMS or if overridden, modem specific implementation.
*
* @param at ATHandler reference for communication with the modem.
* @return new instance of class AT_CellularSMS
*/
virtual AT_CellularSMS *open_sms_impl(ATHandler &at);

/** Create new instance of AT_CellularInformation or if overridden, modem specific implementation.
*
* @param at ATHandler reference for communication with the modem.
Expand All @@ -137,8 +126,24 @@ class AT_CellularDevice : public CellularDevice {

virtual nsapi_error_t set_baud_rate(int baud_rate);

AT_CellularNetwork *_network;
#if MBED_CONF_CELLULAR_USE_SMS
virtual CellularSMS *open_sms(FileHandle *fh = NULL);

virtual void close_sms();

/** Create new instance of AT_CellularSMS or if overridden, modem specific implementation.
*
* @param at ATHandler reference for communication with the modem.
* @return new instance of class AT_CellularSMS
*/
virtual AT_CellularSMS *open_sms_impl(ATHandler &at);

AT_CellularSMS *_sms;

#endif // MBED_CONF_CELLULAR_USE_SMS

AT_CellularNetwork *_network;

AT_CellularInformation *_information;
AT_CellularContext *_context_list;
int _default_timeout;
Expand Down
3 changes: 3 additions & 0 deletions features/cellular/framework/AT/AT_CellularSMS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* limitations under the License.
*/

#if MBED_CONF_CELLULAR_USE_SMS

#include <time.h>
#include <stdlib.h>
#include <stdio.h>
Expand Down Expand Up @@ -1248,3 +1250,4 @@ uint16_t AT_CellularSMS::unpack_7_bit_gsm_to_str(const char *str, int len, char

return decodedCount;
}
#endif //MBED_CONF_CELLULAR_USE_SMS
4 changes: 4 additions & 0 deletions features/cellular/framework/AT/AT_CellularSMS.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#ifndef AT_CELLULAR_SMS_H_
#define AT_CELLULAR_SMS_H_

#if MBED_CONF_CELLULAR_USE_SMS

#include "CellularSMS.h"
#include "AT_CellularBase.h"
#include "Callback.h"
Expand Down Expand Up @@ -167,4 +169,6 @@ class AT_CellularSMS: public CellularSMS, public AT_CellularBase {

} // namespace mbed

#endif //MBED_CONF_CELLULAR_USE_SMS

#endif // AT_CELLULAR_SMS_H_
5 changes: 4 additions & 1 deletion features/cellular/framework/device/CellularDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ MBED_WEAK CellularDevice *CellularDevice::get_target_default_instance()
return NULL;
}

CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0),
CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0),
#if MBED_CONF_CELLULAR_USE_SMS
_sms_ref_count(0),
#endif //MBED_CONF_CELLULAR_USE_SMS
_info_ref_count(0), _fh(fh), _queue(10 * EVENTS_EVENT_SIZE), _state_machine(0), _nw(0), _status_cb(0)
{
MBED_ASSERT(fh);
Expand Down
2 changes: 2 additions & 0 deletions features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ AT_CellularContext *UBLOX_N2XX::create_context_impl(ATHandler &at, const char *a
return new UBLOX_N2XX_CellularContext(at, this, apn, cp_req, nonip_req);
}

#if MBED_CONF_CELLULAR_USE_SMS
AT_CellularSMS *UBLOX_N2XX::open_sms_impl(ATHandler &at)
{
return new UBLOX_N2XX_CellularSMS(at);
}
#endif // MBED_CONF_CELLULAR_USE_SMS

nsapi_error_t UBLOX_N2XX::init()
{
Expand Down
2 changes: 2 additions & 0 deletions features/cellular/framework/targets/UBLOX/N2XX/UBLOX_N2XX.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ class UBLOX_N2XX : public AT_CellularDevice {
protected: // AT_CellularDevice

virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false);
#if MBED_CONF_CELLULAR_USE_SMS
virtual AT_CellularSMS *open_sms_impl(ATHandler &at);
#endif // MBED_CONF_CELLULAR_USE_SMS
virtual void set_at_urcs_impl();

public: // NetworkInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* limitations under the License.
*/

#if MBED_CONF_CELLULAR_USE_SMS

#include "UBLOX_N2XX_CellularSMS.h"

using namespace mbed;
Expand Down Expand Up @@ -47,3 +49,5 @@ nsapi_error_t UBLOX_N2XX_CellularSMS::delete_all_messages()
{
return NSAPI_ERROR_UNSUPPORTED;
}

#endif // MBED_CONF_CELLULAR_USE_SMS
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include "AT_CellularSMS.h"

#if MBED_CONF_CELLULAR_USE_SMS

namespace mbed {

class UBLOX_N2XX_CellularSMS : public AT_CellularSMS {
Expand All @@ -42,4 +44,6 @@ class UBLOX_N2XX_CellularSMS : public AT_CellularSMS {

} // namespace mbed

#endif // MBED_CONF_CELLULAR_USE_SMS

#endif // UBLOX_N2XX_CELLULAR_SMS_H_
4 changes: 4 additions & 0 deletions features/cellular/mbed_lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
"help": "Use APN database lookup",
"value": true
},
"use-sms": {
"help": "Enable or disable SMS functionality in Cellular stack.",
"value": false
},
"random_max_start_delay": {
"help": "Maximum random delay value used in start-up sequence in milliseconds",
"value": 0
Expand Down

0 comments on commit 64add0f

Please sign in to comment.