diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/at_cellularcontexttest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/at_cellularcontexttest.cpp index 4d7b80cb98..df7a5bbfb6 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/at_cellularcontexttest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularcontext/at_cellularcontexttest.cpp @@ -27,7 +27,6 @@ #include "Semaphore_stub.h" #include "CellularDevice_stub.h" #include "equeue_stub.h" -#include "CellularSIM.h" using namespace mbed; using namespace events; @@ -528,7 +527,7 @@ TEST_F(TestAT_CellularContext, set_sim_ready) cell_callback_data_t data; data.error = NSAPI_ERROR_OK; ctx.cellular_callback((nsapi_event_t)CellularDeviceReady, (intptr_t)&data); - data.status_data = CellularSIM::SimStateReady; + data.status_data = CellularDevice::SimStateReady; ctx.cellular_callback((nsapi_event_t)CellularSIMStatusChanged, (intptr_t)&data); } diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp index 622844aecb..6c14c61c58 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/at_cellulardevicetest.cpp @@ -56,7 +56,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_at_handler) EXPECT_TRUE(dev.open_network(&fh1)); EXPECT_TRUE(dev.open_sms(&fh2)); AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value; - EXPECT_TRUE(dev.open_sim(&fh3)); + EXPECT_TRUE(dev.open_information(&fh3)); ATHandler_stub::fh_value = &fh1; EXPECT_TRUE(dev.open_power(&fh1)); @@ -112,19 +112,6 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_power) EXPECT_TRUE(pwr1 == pwr); } -TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_sim) -{ - FileHandle_stub fh1; - AT_CellularDevice dev(&fh1); - - CellularSIM *sim = dev.open_sim(NULL); - CellularSIM *sim1 = dev.open_sim(&fh1); - - EXPECT_TRUE(sim); - EXPECT_TRUE(sim1); - EXPECT_TRUE(sim1 == sim); -} - TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_information) { FileHandle_stub fh1; @@ -180,26 +167,6 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_power) EXPECT_TRUE(ATHandler_stub::ref_count == kATHandler_destructor_ref_ount); } -TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_sim) -{ - FileHandle_stub fh1; - AT_CellularDevice dev(&fh1); - ATHandler_stub::ref_count = 0; - int ana = 0; - - EXPECT_TRUE(dev.open_sim(&fh1)); - AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value; - - ana = ATHandler_stub::ref_count; - - dev.close_sms(); // this should not affect to refcount as it's not opened - EXPECT_TRUE(ATHandler_stub::ref_count == 1); - ana = ATHandler_stub::ref_count; - - dev.close_sim(); - EXPECT_TRUE(ATHandler_stub::ref_count == kATHandler_destructor_ref_ount); -} - TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_information) { FileHandle_stub fh1; @@ -233,19 +200,18 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_timeout) ATHandler_stub::timeout = 0; ATHandler_stub::default_timeout = false; - // no interfaces open so settings timeout should not change anything dev.set_timeout(5000); - EXPECT_TRUE(ATHandler_stub::timeout == 0); - EXPECT_TRUE(ATHandler_stub::default_timeout == false); + EXPECT_TRUE(ATHandler_stub::timeout == 5000); + EXPECT_TRUE(ATHandler_stub::default_timeout == true); - EXPECT_TRUE(dev.open_sim(&fh1)); + EXPECT_TRUE(dev.open_sms(&fh1)); EXPECT_TRUE(ATHandler_stub::ref_count == 1); dev.set_timeout(5000); EXPECT_TRUE(ATHandler_stub::timeout == 5000); EXPECT_TRUE(ATHandler_stub::default_timeout == true); - dev.close_sim(); + dev.close_sms(); } TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_modem_debug_on) @@ -254,17 +220,16 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_modem_debug_on) AT_CellularDevice dev(&fh1); ATHandler_stub::debug_on = false; - // no interfaces open so debug toggling should not affect dev.modem_debug_on(true); - EXPECT_TRUE(ATHandler_stub::debug_on == false); + EXPECT_TRUE(ATHandler_stub::debug_on == true); - EXPECT_TRUE(dev.open_sim(&fh1)); + EXPECT_TRUE(dev.open_sms(&fh1)); EXPECT_TRUE(ATHandler_stub::ref_count == 1); dev.modem_debug_on(true); EXPECT_TRUE(ATHandler_stub::debug_on == true); - dev.close_sim(); + dev.close_sms(); } TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_send_delay) @@ -333,3 +298,64 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_create_delete_context) delete dev; } + +TEST_F(TestAT_CellularDevice, TestAT_CellularDevice_set_pin) +{ + FileHandle_stub fh1; + AT_CellularDevice *dev = new AT_CellularDevice(&fh1); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ASSERT_EQ(NSAPI_ERROR_OK, dev->set_pin("12")); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + ASSERT_EQ(NSAPI_ERROR_DEVICE_ERROR, dev->set_pin("12")); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::read_string_value = (char *)"SIM PIN"; + ATHandler_stub::ssize_value = 7; + ASSERT_EQ(NSAPI_ERROR_PARAMETER, dev->set_pin(NULL)); + + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::read_string_value = (char *)"READY"; + ATHandler_stub::ssize_value = 5; + ASSERT_EQ(NSAPI_ERROR_OK, dev->set_pin("12")); + + ASSERT_EQ(NSAPI_ERROR_OK, dev->set_pin(NULL)); + + delete dev; +} + +TEST_F(TestAT_CellularDevice, TestAT_CellularDevice_get_sim_state) +{ + FileHandle_stub fh1; + AT_CellularDevice *dev = new AT_CellularDevice(&fh1); + + CellularDevice::SimState state; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::ssize_value = -1; + ATHandler_stub::read_string_value = NULL; + ASSERT_EQ(NSAPI_ERROR_OK, dev->get_sim_state(state)); + ASSERT_EQ(CellularDevice::SimStateUnknown, state); + + ATHandler_stub::read_string_value = (char *)"READY"; + ATHandler_stub::ssize_value = 5; + ASSERT_EQ(NSAPI_ERROR_OK, dev->get_sim_state(state)); + ASSERT_EQ(CellularDevice::SimStateReady, state); + + ATHandler_stub::read_string_value = (char *)"SIM PIN"; + ATHandler_stub::ssize_value = 7; + ASSERT_EQ(NSAPI_ERROR_OK, dev->get_sim_state(state)); + ASSERT_EQ(CellularDevice::SimStatePinNeeded, state); + + ATHandler_stub::read_string_value = (char *)"SIM PUK"; + ATHandler_stub::ssize_value = 7; + ASSERT_EQ(NSAPI_ERROR_OK, dev->get_sim_state(state)); + ASSERT_EQ(CellularDevice::SimStatePukNeeded, state); + + ATHandler_stub::read_string_value = (char *)"SOME CRAP"; + ATHandler_stub::ssize_value = 9; + ASSERT_EQ(NSAPI_ERROR_OK, dev->get_sim_state(state)); + ASSERT_EQ(CellularDevice::SimStateUnknown, state); + + delete dev; +} diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake index 5ce257eab7..92af9005b6 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake +++ b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake @@ -27,7 +27,6 @@ set(unittest-test-sources stubs/AT_CellularNetwork_stub.cpp stubs/ATHandler_stub.cpp stubs/AT_CellularSMS_stub.cpp - stubs/AT_CellularSIM_stub.cpp stubs/AT_CellularPower_stub.cpp stubs/AT_CellularInformation_stub.cpp stubs/CellularUtil_stub.cpp diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularinformation/at_cellularinformationtest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularinformation/at_cellularinformationtest.cpp index 0a6d649e74..883bffd00c 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularinformation/at_cellularinformationtest.cpp +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularinformation/at_cellularinformationtest.cpp @@ -34,6 +34,10 @@ protected: void SetUp() { + ATHandler_stub::read_string_index = kRead_string_table_size; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::read_string_value = NULL; + ATHandler_stub::ssize_value = 0; } void TearDown() @@ -118,6 +122,8 @@ TEST_F(TestAT_CellularInformation, test_AT_CellularInformation_get_revision) EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == aci->get_revision(buf, 8)); EXPECT_TRUE(strlen(buf) == 0); + EXPECT_TRUE(NSAPI_ERROR_PARAMETER == aci->get_revision(NULL, 8)); + EXPECT_TRUE(NSAPI_ERROR_PARAMETER == aci->get_revision(buf, 0)); delete aci; } @@ -152,4 +158,59 @@ TEST_F(TestAT_CellularInformation, test_AT_CellularInformation_get_serial_number AT_CellularBase_stub::supported_bool = true; EXPECT_TRUE(NSAPI_ERROR_OK == aci.get_serial_number(buf, 8, CellularInformation::IMEI)); EXPECT_TRUE(strcmp("1234567", buf) == 0); + + EXPECT_TRUE(NSAPI_ERROR_PARAMETER == aci.get_serial_number(NULL, 8, CellularInformation::IMEI)); + EXPECT_TRUE(NSAPI_ERROR_PARAMETER == aci.get_serial_number(buf, 0, CellularInformation::IMEI)); +} + +TEST_F(TestAT_CellularInformation, TestAT_CellularInformation_get_imsi) +{ + EventQueue eq; + FileHandle_stub fh; + ATHandler ah(&fh, eq, 0, ","); + AT_CellularInformation aci(ah); + + char imsi[16]; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::read_string_value = (char *)"123456789012345"; + ATHandler_stub::ssize_value = 15; + ASSERT_EQ(NSAPI_ERROR_OK, aci.get_imsi(imsi, sizeof(imsi))); + ASSERT_STREQ(ATHandler_stub::read_string_value, imsi); + + ATHandler_stub::read_string_value = NULL; + ATHandler_stub::ssize_value = -1; + ATHandler_stub::read_string_index = -1; + imsi[0] = 0; + ASSERT_EQ(NSAPI_ERROR_DEVICE_ERROR, aci.get_imsi(imsi, sizeof(imsi))); + ASSERT_EQ(strlen(imsi), 0); + + ASSERT_EQ(NSAPI_ERROR_PARAMETER, aci.get_imsi(NULL, sizeof(imsi))); + + char imsi2[5]; + ASSERT_EQ(NSAPI_ERROR_PARAMETER, aci.get_imsi(imsi2, sizeof(imsi2))); +} + +TEST_F(TestAT_CellularInformation, TestAT_CellularInformation_get_iccid) +{ + EventQueue eq; + FileHandle_stub fh; + ATHandler ah(&fh, eq, 0, ","); + AT_CellularInformation aci(ah); + + char buf[16]; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; + ATHandler_stub::read_string_value = (char *)"123456789012345"; + ATHandler_stub::ssize_value = 15; + ASSERT_EQ(NSAPI_ERROR_OK, aci.get_iccid(buf, 16)); + ASSERT_STREQ(ATHandler_stub::read_string_value, buf); + + buf[0] = 0; + ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; + ATHandler_stub::read_string_value = NULL; + ATHandler_stub::ssize_value = -1; + ASSERT_EQ(NSAPI_ERROR_DEVICE_ERROR, aci.get_iccid(buf, 16)); + ASSERT_EQ(strlen(buf), 0); + + ASSERT_EQ(NSAPI_ERROR_PARAMETER, aci.get_iccid(buf, 0)); + ASSERT_EQ(NSAPI_ERROR_PARAMETER, aci.get_iccid(NULL, 16)); } diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularsim/at_cellularsimtest.cpp b/UNITTESTS/features/cellular/framework/AT/at_cellularsim/at_cellularsimtest.cpp deleted file mode 100644 index e4fe6a1ce1..0000000000 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularsim/at_cellularsimtest.cpp +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright (c) 2018, 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 "gtest/gtest.h" -#include "ATHandler_stub.h" -#include -#include "AT_CellularNetwork.h" -#include "EventQueue.h" -#include "ATHandler.h" -#include "AT_CellularSIM.h" -#include "FileHandle_stub.h" -#include "CellularLog.h" -#include "ATHandler_stub.h" - -using namespace mbed; -using namespace events; - -// AStyle ignored as the definition is not clear due to preprocessor usage -// *INDENT-OFF* -class TestAT_CellularSIM : public testing::Test { -protected: - - void SetUp() - { - ATHandler_stub::read_string_index = kRead_string_table_size; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::read_string_value = NULL; - ATHandler_stub::ssize_value = 0; - } - - void TearDown() - { - } -}; -// *INDENT-ON* - -TEST_F(TestAT_CellularSIM, Create) -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularSIM *sim = new AT_CellularSIM(at); - - EXPECT_TRUE(sim != NULL); - delete sim; -} - -TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_set_pin) -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularSIM sim(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin("12")); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.set_pin("12")); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::read_string_value = (char *)"READY"; - ATHandler_stub::ssize_value = 5; - EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin("12")); - - EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin(NULL)); -} - -TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_change_pin) -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularSIM sim(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - EXPECT_TRUE(NSAPI_ERROR_OK == sim.change_pin("12", "34")); - EXPECT_TRUE(NSAPI_ERROR_OK == sim.change_pin(NULL, "34")); - EXPECT_TRUE(NSAPI_ERROR_OK == sim.change_pin("12", NULL)); - EXPECT_TRUE(NSAPI_ERROR_OK == sim.change_pin(NULL, NULL)); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.change_pin("12", "34")); -} - -TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_set_pin_query) -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularSIM sim(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin_query("12", true)); - EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin_query(NULL, true)); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin_query("12", false)); - EXPECT_TRUE(NSAPI_ERROR_OK == sim.set_pin_query(NULL, false)); - - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.set_pin_query("12", false)); - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.set_pin_query("12", true)); -} - -TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_get_sim_state) -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - AT_CellularSIM sim(at); - CellularSIM::SimState state; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::ssize_value = -1; - ATHandler_stub::read_string_value = NULL; - EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_sim_state(state)); - EXPECT_TRUE(CellularSIM::SimStateUnknown == state); - - ATHandler_stub::read_string_value = (char *)"READY"; - ATHandler_stub::ssize_value = 5; - EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_sim_state(state)); - EXPECT_TRUE(CellularSIM::SimStateReady == state); - - ATHandler_stub::read_string_value = (char *)"SIM PIN"; - ATHandler_stub::ssize_value = 7; - EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_sim_state(state)); - EXPECT_TRUE(CellularSIM::SimStatePinNeeded == state); - - ATHandler_stub::read_string_value = (char *)"SIM PUK"; - ATHandler_stub::ssize_value = 7; - EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_sim_state(state)); - EXPECT_TRUE(CellularSIM::SimStatePukNeeded == state); - - ATHandler_stub::read_string_value = (char *)"SOME CRAP"; - ATHandler_stub::ssize_value = 9; - EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_sim_state(state)); - EXPECT_TRUE(CellularSIM::SimStateUnknown == state); -} - -TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_get_imsi) -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - char imsi[16]; - AT_CellularSIM sim(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::read_string_value = (char *)"123456789012345"; - ATHandler_stub::ssize_value = 15; - EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_imsi(imsi)); - EXPECT_TRUE(strcmp(ATHandler_stub::read_string_value, imsi) == 0); - - ATHandler_stub::read_string_value = NULL; - ATHandler_stub::ssize_value = -1; - ATHandler_stub::read_string_index = -1; - imsi[0] = 0; - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.get_imsi(imsi)); - EXPECT_TRUE(strlen(imsi) == 0); - - EXPECT_TRUE(NSAPI_ERROR_PARAMETER == sim.get_imsi(NULL)); - - // this would fail as get_imsi should take another param which is the size of the buffer which we could use for validation. - // Now we have improved documentation that that the given imsi buffer size must be over 15. - //char imsi2[5]; - //EXPECT_TRUE(NSAPI_ERROR_PARAMETER == sim.get_imsi(imsi2)); -} - -TEST_F(TestAT_CellularSIM, test_AT_CellularSIM_get_iccid) -{ - EventQueue que; - FileHandle_stub fh1; - ATHandler at(&fh1, que, 0, ","); - - char buf[16]; - AT_CellularSIM sim(at); - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_OK; - ATHandler_stub::read_string_value = (char *)"123456789012345"; - ATHandler_stub::ssize_value = 15; - EXPECT_TRUE(NSAPI_ERROR_OK == sim.get_iccid(buf, 16)); - EXPECT_TRUE(strcmp(ATHandler_stub::read_string_value, buf) == 0); - - buf[0] = 0; - ATHandler_stub::nsapi_error_value = NSAPI_ERROR_DEVICE_ERROR; - ATHandler_stub::read_string_value = NULL; - ATHandler_stub::ssize_value = -1; - EXPECT_TRUE(NSAPI_ERROR_DEVICE_ERROR == sim.get_iccid(buf, 16)); - EXPECT_TRUE(strlen(buf) == 0); -} diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularsim/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/at_cellularsim/unittest.cmake deleted file mode 100644 index 7adbfef871..0000000000 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularsim/unittest.cmake +++ /dev/null @@ -1,29 +0,0 @@ - -#################### -# UNIT TESTS -#################### - -# Add test specific include paths -set(unittest-includes ${unittest-includes} - features/cellular/framework/common/util - ../features/cellular/framework/common - ../features/cellular/framework/AT - ../features/frameworks/mbed-client-randlib/mbed-client-randlib -) - -# Source files -set(unittest-sources - ../features/cellular/framework/AT/AT_CellularSIM.cpp -) - -# Test files -set(unittest-test-sources - features/cellular/framework/AT/at_cellularsim/at_cellularsimtest.cpp - stubs/ATHandler_stub.cpp - stubs/AT_CellularBase_stub.cpp - stubs/EventQueue_stub.cpp - stubs/FileHandle_stub.cpp - stubs/CellularUtil_stub.cpp - stubs/us_ticker_stub.cpp - stubs/mbed_assert_stub.c -) diff --git a/UNITTESTS/features/cellular/framework/device/cellulardevice/cellulardevicetest.cpp b/UNITTESTS/features/cellular/framework/device/cellulardevice/cellulardevicetest.cpp index 4eb5e3d6e6..d615f592f7 100644 --- a/UNITTESTS/features/cellular/framework/device/cellulardevice/cellulardevicetest.cpp +++ b/UNITTESTS/features/cellular/framework/device/cellulardevice/cellulardevicetest.cpp @@ -21,7 +21,6 @@ #include "FileHandle_stub.h" #include "myCellularDevice.h" #include "CellularStateMachine_stub.h" -#include "CellularSIM.h" using namespace mbed; @@ -221,7 +220,7 @@ TEST_F(TestCellularDevice, test_cellular_callback) dev->cellular_callback((nsapi_event_t)CellularDeviceReady, (intptr_t)&data); dev->set_sim_pin("1234"); - data.status_data = CellularSIM::SimStatePinNeeded; + data.status_data = CellularDevice::SimStatePinNeeded; dev->cellular_callback((nsapi_event_t)CellularSIMStatusChanged, (intptr_t)&data); CellularContext *ctx = dev->create_context(); diff --git a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp index 7ef169e736..169929df30 100644 --- a/UNITTESTS/stubs/AT_CellularDevice_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularDevice_stub.cpp @@ -24,7 +24,7 @@ const int DEFAULT_AT_TIMEOUT = 1000; using namespace mbed; AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh), _network(0), _sms(0), - _sim(0), _power(0), _information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT), + _power(0), _information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT), _modem_debug_on(false) { } @@ -54,12 +54,10 @@ nsapi_error_t AT_CellularDevice::release_at_handler(ATHandler *at_handler) CellularContext *create_context(FileHandle *fh = NULL, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN) { - } void delete_context(CellularContext *context) { - } CellularNetwork *AT_CellularDevice::open_network(FileHandle *fh) @@ -72,11 +70,6 @@ CellularSMS *AT_CellularDevice::open_sms(FileHandle *fh) return NULL; } -CellularSIM *AT_CellularDevice::open_sim(FileHandle *fh) -{ - return NULL; -} - CellularPower *AT_CellularDevice::open_power(FileHandle *fh) { return NULL; @@ -99,10 +92,6 @@ void AT_CellularDevice::close_power() { } -void AT_CellularDevice::close_sim() -{ -} - void AT_CellularDevice::close_information() { } @@ -124,7 +113,6 @@ AT_CellularContext *AT_CellularDevice::create_context_impl(ATHandler &at, const void AT_CellularDevice::delete_context(CellularContext *context) { - } AT_CellularNetwork *AT_CellularDevice::open_network_impl(ATHandler &at) @@ -142,11 +130,6 @@ AT_CellularPower *AT_CellularDevice::open_power_impl(ATHandler &at) return NULL; } -AT_CellularSIM *AT_CellularDevice::open_sim_impl(ATHandler &at) -{ - return NULL; -} - AT_CellularInformation *AT_CellularDevice::open_information_impl(ATHandler &at) { return NULL; @@ -172,3 +155,13 @@ nsapi_error_t AT_CellularDevice::init_module() { return NSAPI_ERROR_OK; } + +nsapi_error_t AT_CellularDevice::set_pin(const char *sim_pin) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularDevice::get_sim_state(SimState &state) +{ + return NSAPI_ERROR_OK; +} diff --git a/UNITTESTS/stubs/AT_CellularInformation_stub.cpp b/UNITTESTS/stubs/AT_CellularInformation_stub.cpp index ae35f29bde..832c038433 100644 --- a/UNITTESTS/stubs/AT_CellularInformation_stub.cpp +++ b/UNITTESTS/stubs/AT_CellularInformation_stub.cpp @@ -47,3 +47,13 @@ nsapi_error_t AT_CellularInformation::get_serial_number(char *buf, size_t buf_si { return NSAPI_ERROR_OK; } + +nsapi_error_t AT_CellularInformation::get_imsi(char *imsi, size_t buf_size) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t AT_CellularInformation::get_iccid(char *buf, size_t buf_size) +{ + return NSAPI_ERROR_OK; +} diff --git a/UNITTESTS/stubs/AT_CellularSIM_stub.cpp b/UNITTESTS/stubs/AT_CellularSIM_stub.cpp deleted file mode 100644 index afab1012bd..0000000000 --- a/UNITTESTS/stubs/AT_CellularSIM_stub.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) , 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 "AT_CellularSIM.h" -#include "CellularLog.h" - -using namespace mbed; - -AT_CellularSIM::AT_CellularSIM(ATHandler &at) : AT_CellularBase(at) -{ -} - -AT_CellularSIM::~AT_CellularSIM() -{ -} - -nsapi_error_t AT_CellularSIM::get_sim_state(SimState &state) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularSIM::set_pin(const char *sim_pin) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularSIM::change_pin(const char *sim_pin, const char *new_pin) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularSIM::set_pin_query(const char *sim_pin, bool query_pin) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularSIM::get_imsi(char *imsi) -{ - return NSAPI_ERROR_OK; -} - -nsapi_error_t AT_CellularSIM::get_iccid(char *buf, size_t buf_size) -{ - return NSAPI_ERROR_OK; -} diff --git a/UNITTESTS/stubs/CellularDevice_stub.cpp b/UNITTESTS/stubs/CellularDevice_stub.cpp index e64118f0f6..24141cfb99 100644 --- a/UNITTESTS/stubs/CellularDevice_stub.cpp +++ b/UNITTESTS/stubs/CellularDevice_stub.cpp @@ -30,7 +30,7 @@ MBED_WEAK CellularDevice *CellularDevice::get_default_instance() return NULL; } -CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0), _power_ref_count(0), _sim_ref_count(0), +CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0), _power_ref_count(0), _info_ref_count(0), _fh(fh), _queue(5 * EVENTS_EVENT_SIZE), _state_machine(0), _nw(0) { } @@ -87,3 +87,13 @@ nsapi_error_t CellularDevice::attach_to_network() return NSAPI_ERROR_OK; } + +nsapi_error_t CellularDevice::set_pin(const char *sim_pin) +{ + return NSAPI_ERROR_OK; +} + +nsapi_error_t CellularDevice::get_sim_state(SimState &state) +{ + return NSAPI_ERROR_OK; +} diff --git a/UNITTESTS/target_h/myCellularDevice.h b/UNITTESTS/target_h/myCellularDevice.h index 28dfb8a1ac..7190f8f6f9 100644 --- a/UNITTESTS/target_h/myCellularDevice.h +++ b/UNITTESTS/target_h/myCellularDevice.h @@ -29,7 +29,6 @@ namespace mbed { class CellularPower; class CellularSMS; -class CellularSIM; class CellularInformation; class CellularContext; class FileHandle; @@ -42,6 +41,17 @@ public: delete _context_list; delete _network; } + + virtual nsapi_error_t set_pin(const char *sim_pin) + { + return NSAPI_ERROR_OK; + } + + virtual nsapi_error_t get_sim_state(SimState &state) + { + return NSAPI_ERROR_OK; + } + virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = NULL) { EventQueue que; @@ -74,11 +84,6 @@ public: return NULL; } - virtual CellularSIM *open_sim(FileHandle *fh = NULL) - { - return NULL; - } - virtual CellularInformation *open_information(FileHandle *fh = NULL) { return NULL; @@ -93,8 +98,6 @@ public: virtual void close_power() {} - virtual void close_sim() {} - virtual void close_information() {} virtual void set_timeout(int timeout) {} diff --git a/features/cellular/TESTS/api/cellular_device/main.cpp b/features/cellular/TESTS/api/cellular_device/main.cpp index 9246e3e112..df8fb467f8 100644 --- a/features/cellular/TESTS/api/cellular_device/main.cpp +++ b/features/cellular/TESTS/api/cellular_device/main.cpp @@ -15,7 +15,6 @@ * limitations under the License. */ - #if !defined(MBED_CONF_NSAPI_PRESENT) #error [NOT_SUPPORTED] A json configuration file is needed. Skipping this build. #endif @@ -27,6 +26,10 @@ #error [NOT_SUPPORTED] CELLULAR_DEVICE must be defined #endif +#ifndef MBED_CONF_APP_CELLULAR_SIM_PIN +#error [NOT_SUPPORTED] SIM pin code is needed. Skipping this build. +#endif + #include "greentea-client/test_env.h" #include "unity.h" #include "utest.h" @@ -36,9 +39,24 @@ #include "CellularLog.h" #include "CellularDevice.h" #include CELLULAR_STRINGIFY(CELLULAR_DEVICE.h) +#include "Semaphore.h" +#include "../../cellular_tests_common.h" static UARTSerial cellular_serial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE); static CellularDevice *device; +static rtos::Semaphore semaphore; + + +const int TIME_OUT_DEVICE_READY = 5 * 60 * 1000; // 5 minutes +const int TIME_OUT_REGISTER = 10 * 60 * 1000; // 10 minutes + +enum CurrentOp { + OP_DEVICE_READY, + OP_SIM_READY, + OP_REGISTER, + OP_ATTACH +}; +static CurrentOp op; static void create_device() { @@ -52,10 +70,6 @@ static void open_close_interfaces() TEST_ASSERT(nw != NULL); device->close_network(); - CellularSIM *sim = device->open_sim(&cellular_serial); - TEST_ASSERT(sim != NULL); - device->close_sim(); - CellularInformation *info = device->open_information(&cellular_serial); TEST_ASSERT(info != NULL); device->close_information(); @@ -70,6 +84,7 @@ static void open_close_interfaces() CellularContext *ctx = device->create_context(); TEST_ASSERT(ctx != NULL); + TEST_ASSERT(device->get_context_list() == ctx); device->delete_context(ctx); } @@ -83,10 +98,13 @@ static void other_methods() CellularNetwork *nw = device->open_network(&cellular_serial); TEST_ASSERT(nw != NULL); - // then test witj open interface which is called + // then test with open interface which is called device->set_timeout(5000); device->modem_debug_on(true); device->modem_debug_on(false); + + TEST_ASSERT(device->get_queue() != NULL); + TEST_ASSERT_EQUAL_INT(device->init_module(), NSAPI_ERROR_OK); } static void delete_device() @@ -96,10 +114,85 @@ static void delete_device() device = NULL; } +static void callback_func(nsapi_event_t ev, intptr_t ptr) +{ + if (ev >= NSAPI_EVENT_CELLULAR_STATUS_BASE && ev <= NSAPI_EVENT_CELLULAR_STATUS_END) { + cell_callback_data_t *ptr_data = (cell_callback_data_t *)ptr; + cellular_connection_status_t cell_ev = (cellular_connection_status_t)ev; + if (cell_ev == CellularDeviceReady && ptr_data->error == NSAPI_ERROR_OK && op == OP_DEVICE_READY) { + TEST_ASSERT_EQUAL_INT(semaphore.release(), osOK); + } else if (cell_ev == CellularSIMStatusChanged && ptr_data->error == NSAPI_ERROR_OK && + ptr_data->status_data == CellularDevice::SimStateReady && op == OP_SIM_READY) { + TEST_ASSERT_EQUAL_INT(semaphore.release(), osOK); + } else if (cell_ev == CellularRegistrationStatusChanged && + (ptr_data->status_data == CellularNetwork::RegisteredHomeNetwork || + ptr_data->status_data == CellularNetwork::RegisteredRoaming || + ptr_data->status_data == CellularNetwork::AlreadyRegistered) && + ptr_data->error == NSAPI_ERROR_OK && + op == OP_REGISTER) { + TEST_ASSERT_EQUAL_INT(semaphore.release(), osOK); + } else if (cell_ev == CellularAttachNetwork && ptr_data->status_data == CellularNetwork::Attached && + ptr_data->error == NSAPI_ERROR_OK && op == OP_ATTACH) { + TEST_ASSERT_EQUAL_INT(semaphore.release(), osOK); + } + } +} + +static void init_to_device_ready_state() +{ + device = CellularDevice::get_default_instance(); + TEST_ASSERT(device != NULL); + +#ifdef MBED_CONF_APP_CELLULAR_SIM_PIN + device->set_sim_pin(MBED_CONF_APP_CELLULAR_SIM_PIN); +#endif +#ifdef MBED_CONF_APP_CELLULAR_PLMN + device->set_plmn(MBED_CONF_APP_CELLULAR_PLMN); +#endif + device->attach(&callback_func); + + op = OP_DEVICE_READY; + TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, device->init_module()); + TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, device->set_device_ready()); + + int sema_err = semaphore.wait(TIME_OUT_DEVICE_READY); + TEST_ASSERT_EQUAL_INT(1, sema_err); +} + +static void continue_to_sim_ready_state() +{ + op = OP_SIM_READY; + TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, device->set_sim_ready()); + + int sema_err = semaphore.wait(TIME_OUT_DEVICE_READY); + TEST_ASSERT_EQUAL_INT(1, sema_err); +} + +static void continue_to_register_state() +{ + op = OP_REGISTER; + TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, device->register_to_network()); + + int sema_err = semaphore.wait(TIME_OUT_REGISTER); // cellular network searching may take several minutes + TEST_ASSERT_EQUAL_INT(1, sema_err); +} + +static void continue_to_attach_state() +{ + op = OP_ATTACH; + TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, device->attach_to_network()); + + int sema_err = semaphore.wait(TIME_OUT_REGISTER); // cellular network attach may take several minutes + TEST_ASSERT_EQUAL_INT(1, sema_err); +} + using namespace utest::v1; static utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { +#if MBED_CONF_MBED_TRACE_ENABLE + trace_close(); +#endif greentea_case_failure_abort_handler(source, reason); return STATUS_ABORT; } @@ -108,7 +201,11 @@ static Case cases[] = { Case("CellularDevice create device", create_device, greentea_failure_handler), Case("CellularDevice Open and close interfaces", open_close_interfaces, greentea_failure_handler), Case("CellularDevice other methods", other_methods, greentea_failure_handler), - Case("CellularDevice delete device", delete_device, greentea_failure_handler) + Case("CellularDevice delete device", delete_device, greentea_failure_handler), + Case("CellularDevice init to device ready", init_to_device_ready_state, greentea_failure_handler), + Case("CellularDevice sim ready", continue_to_sim_ready_state, greentea_failure_handler), + Case("CellularDevice register", continue_to_register_state, greentea_failure_handler), + Case("CellularDevice attach", continue_to_attach_state, greentea_failure_handler) }; static utest::v1::status_t test_setup(const size_t number_of_cases) @@ -121,8 +218,14 @@ static Specification specification(test_setup, cases); int main() { - mbed_trace_init(); +#if MBED_CONF_MBED_TRACE_ENABLE + trace_open(); +#endif - return Harness::run(specification); + int ret = Harness::run(specification); +#if MBED_CONF_MBED_TRACE_ENABLE + trace_close(); +#endif + return ret; } diff --git a/features/cellular/TESTS/api/cellular_information/main.cpp b/features/cellular/TESTS/api/cellular_information/main.cpp index 942da3177f..bf18c553e2 100644 --- a/features/cellular/TESTS/api/cellular_information/main.cpp +++ b/features/cellular/TESTS/api/cellular_information/main.cpp @@ -80,6 +80,12 @@ static void test_information_interface() err = info->get_serial_number(buf, kbuf_size, CellularInformation::SVN); TEST_ASSERT(err == NSAPI_ERROR_UNSUPPORTED || err == NSAPI_ERROR_OK); + err = info->get_imsi(buf, kbuf_size); + TEST_ASSERT(err == NSAPI_ERROR_UNSUPPORTED || err == NSAPI_ERROR_OK); + + err = info->get_iccid(buf, kbuf_size); + TEST_ASSERT(err == NSAPI_ERROR_UNSUPPORTED || err == NSAPI_ERROR_OK); + dev->close_information(); delete [] buf; diff --git a/features/cellular/TESTS/api/cellular_sim/main.cpp b/features/cellular/TESTS/api/cellular_sim/main.cpp deleted file mode 100644 index 3da5b951bb..0000000000 --- a/features/cellular/TESTS/api/cellular_sim/main.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2018, 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. - */ - - -#if !defined(MBED_CONF_NSAPI_PRESENT) -#error [NOT_SUPPORTED] A json configuration file is needed. Skipping this build. -#endif - -#include "CellularUtil.h" // for CELLULAR_ helper macros -#include "CellularTargets.h" - -#ifndef CELLULAR_DEVICE -#error [NOT_SUPPORTED] CELLULAR_DEVICE must be defined -#endif - -#ifndef MBED_CONF_APP_CELLULAR_SIM_PIN -#error [NOT_SUPPORTED] SIM pin code is needed. Skipping this build. -#endif - -#include "greentea-client/test_env.h" -#include "unity.h" -#include "utest.h" - -#include "mbed.h" - -#include "CellularContext.h" -#include "CellularDevice.h" -#include "CellularSIM.h" -#include "../../cellular_tests_common.h" -#include CELLULAR_STRINGIFY(CELLULAR_DEVICE.h) - -#define NETWORK_TIMEOUT (180*1000) - -static CellularContext *ctx; -static CellularDevice *device; - -static void init_to_device_ready_state() -{ - ctx = CellularContext::get_default_instance(); - TEST_ASSERT(ctx != NULL); - TEST_ASSERT(ctx->set_device_ready() == NSAPI_ERROR_OK); - - device = CellularDevice::get_default_instance(); - TEST_ASSERT(device != NULL); -} - -static void test_sim_interface() -{ - CellularSIM *sim = device->open_sim(); - TEST_ASSERT(sim != NULL); - - // set SIM at time out to 9000 - device->set_timeout(9000); - wait(4); // we need to wait for some time so that SIM interface is working in all modules. - // 1. test set_pin - nsapi_error_t err = sim->set_pin(MBED_CONF_APP_CELLULAR_SIM_PIN); - MBED_ASSERT(err == NSAPI_ERROR_OK); - - // 2. test set_pin_query - wait(1); - err = sim->set_pin_query(MBED_CONF_APP_CELLULAR_SIM_PIN, false); - TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED); - - wait(1); - err = sim->set_pin_query(MBED_CONF_APP_CELLULAR_SIM_PIN, true); - TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_UNSUPPORTED); - - wait(1); - // 3. test get_sim_state - CellularSIM::SimState state; - err = sim->get_sim_state(state); - TEST_ASSERT(err == NSAPI_ERROR_OK); - TEST_ASSERT(state == CellularSIM::SimStateReady); - - wait(1); - // 4. test get_imsi - char imsi[16] = {0}; - err = sim->get_imsi(imsi); - TEST_ASSERT(err == NSAPI_ERROR_OK); - TEST_ASSERT(strlen(imsi) > 0); -} - -using namespace utest::v1; - -static utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) -{ - greentea_case_failure_abort_handler(source, reason); - return STATUS_ABORT; -} - -static Case cases[] = { - Case("CellularSIM init", init_to_device_ready_state, greentea_failure_handler), - Case("CellularSIM test interface", test_sim_interface, greentea_failure_handler) -}; - -static utest::v1::status_t test_setup(const size_t number_of_cases) -{ - GREENTEA_SETUP(10 * 60, "default_auto"); - return verbose_test_setup_handler(number_of_cases); -} - -static Specification specification(test_setup, cases); - -int main() -{ -#if MBED_CONF_MBED_TRACE_ENABLE - trace_open(); -#endif - int ret = Harness::run(specification); -#if MBED_CONF_MBED_TRACE_ENABLE - trace_close(); -#endif - return ret; -} diff --git a/features/cellular/TESTS/socket/udp/template_mbed_app.json.txt b/features/cellular/TESTS/socket/udp/template_mbed_app.json.txt index be58e16e68..983fd68dd9 100644 --- a/features/cellular/TESTS/socket/udp/template_mbed_app.json.txt +++ b/features/cellular/TESTS/socket/udp/template_mbed_app.json.txt @@ -4,6 +4,10 @@ "help": "PIN code", "value": "\"1234\"" }, + "cellular_plmn": { + "help": "plmn to select manual registration", + "value": 0 + }, "apn": { "help": "The APN string to use for this SIM/network, set to 0 if none", "value": 0 @@ -27,7 +31,6 @@ "nsapi.dns-response-wait-time": 30000, "ppp-cell-iface.apn-lookup": false, "cellular.use-apn-lookup": false, - "target.features_add": ["LWIP"], "mbed-trace.enable": false, "lwip.ipv4-enabled": true, "lwip.ipv6-enabled": true, diff --git a/features/cellular/framework/API/CellularDevice.h b/features/cellular/framework/API/CellularDevice.h index a494114023..12ddb7315a 100644 --- a/features/cellular/framework/API/CellularDevice.h +++ b/features/cellular/framework/API/CellularDevice.h @@ -27,7 +27,6 @@ namespace mbed { class CellularPower; class CellularSMS; -class CellularSIM; class CellularInformation; class CellularNetwork; class CellularContext; @@ -35,6 +34,7 @@ class FileHandle; const int MAX_PIN_SIZE = 8; const int MAX_PLMN_SIZE = 16; +const int MAX_SIM_READY_WAITING_TIME = 30; /** * @addtogroup cellular @@ -49,6 +49,13 @@ const int MAX_PLMN_SIZE = 16; */ class CellularDevice { public: + /* enumeration for possible SIM states */ + enum SimState { + SimStateReady = 0, + SimStatePinNeeded, + SimStatePukNeeded, + SimStateUnknown + }; /** Returns singleton instance of CellularDevice if CELLULAR_DEVICE is defined. If CELLULAR_DEVICE is not * defined, then it returns NULL. Implementation is marked as weak. @@ -67,6 +74,23 @@ public: */ virtual ~CellularDevice(); + /** Open the SIM card by setting the pin code for SIM. + * + * @param sim_pin PIN for the SIM card + * @return NSAPI_ERROR_OK on success + * NSAPI_ERROR_PARAMETER if sim_pin is null and sim is not ready + * NSAPI_ERROR_DEVICE_ERROR on failure + */ + virtual nsapi_error_t set_pin(const char *sim_pin) = 0; + + /** Get SIM card's state + * + * @param state current state of SIM + * @return NSAPI_ERROR_OK on success + * NSAPI_ERROR_DEVICE_ERROR on failure + */ + virtual nsapi_error_t get_sim_state(SimState &state) = 0; + /** Creates a new CellularContext interface. * * @param fh file handle used in communication to modem. This can be, for example, UART handle. If null, then the default @@ -154,11 +178,11 @@ public: /** Register callback for status reporting. * - * The specified status callback function is called on the network, and the cellular device status changes. - * The parameters on the callback are the event type and event type dependent reason parameter. + * The specified status callback function will be called on the network and cellular device status changes. + * The parameters on the callback are the event type and event-type dependent reason parameter. * - * @remark deleting CellularDevice/CellularContext in callback is not allowed. - * @remark application should not attach to this function if it uses CellularContext::attach because it contains the + * @remark deleting CellularDevice/CellularContext in callback not allowed. + * @remark application should not attach to this function if using CellularContext::attach as it will contain the * same information. * * @param status_cb The callback for status changes. @@ -189,14 +213,6 @@ public: */ virtual CellularPower *open_power(FileHandle *fh = NULL) = 0; - /** Create new CellularSIM interface. - * - * @param fh file handle used in communication to modem. This can be, for example, UART handle. If null, then the default - * file handle is used. - * @return New instance of interface CellularSIM. - */ - virtual CellularSIM *open_sim(FileHandle *fh = NULL) = 0; - /** 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 @@ -217,10 +233,6 @@ public: */ virtual void close_power() = 0; - /** Closes the opened CellularSIM by deleting the CellularSIM instance. - */ - virtual void close_sim() = 0; - /** Closes the opened CellularInformation by deleting the CellularInformation instance. */ virtual void close_information() = 0; @@ -283,7 +295,6 @@ protected: int _network_ref_count; int _sms_ref_count; int _power_ref_count; - int _sim_ref_count; int _info_ref_count; FileHandle *_fh; events::EventQueue _queue; diff --git a/features/cellular/framework/API/CellularInformation.h b/features/cellular/framework/API/CellularInformation.h index 9ab79d6e92..689e78f673 100644 --- a/features/cellular/framework/API/CellularInformation.h +++ b/features/cellular/framework/API/CellularInformation.h @@ -21,6 +21,9 @@ #include #include "nsapi_types.h" +const int MAX_IMSI_LENGTH = 15; +const int MAX_ICCID_LENGTH = 20 + 1; // +1 for zero termination + namespace mbed { /** @@ -48,6 +51,7 @@ public: * @param buf manufacturer identification as zero terminated string * @param buf_size max length of manufacturer identification is 2048 characters * @return NSAPI_ERROR_OK on success + * NSAPI_ERROR_PARAMETER if buf is null or buf_size is zero * NSAPI_ERROR_DEVICE_ERROR on failure */ virtual nsapi_error_t get_manufacturer(char *buf, size_t buf_size) = 0; @@ -57,6 +61,7 @@ public: * @param buf model identification as zero terminated string * @param buf_size max length of model identification is 2048 characters * @return NSAPI_ERROR_OK on success + * NSAPI_ERROR_PARAMETER if buf is null or buf_size is zero * NSAPI_ERROR_DEVICE_ERROR on failure */ virtual nsapi_error_t get_model(char *buf, size_t buf_size) = 0; @@ -66,6 +71,7 @@ public: * @param buf revision identification as zero terminated string * @param buf_size max length of revision identification is 2048 characters * @return NSAPI_ERROR_OK on success + * NSAPI_ERROR_PARAMETER if buf is null or buf_size is zero * NSAPI_ERROR_DEVICE_ERROR on failure */ virtual nsapi_error_t get_revision(char *buf, size_t buf_size) = 0; @@ -76,6 +82,7 @@ public: * @param buf_size max length of serial number is 2048 characters * @param type serial number type to read * @return NSAPI_ERROR_OK on success + * NSAPI_ERROR_PARAMETER if buf is null or buf_size is zero * NSAPI_ERROR_UNSUPPORTED if the modem does not support SerialNumberType * NSAPI_ERROR_DEVICE_ERROR on other failures */ @@ -85,7 +92,30 @@ public: IMEISV = 2, // IMEI and Software Version number SVN = 3 // Software Version Number }; - virtual nsapi_error_t get_serial_number(char *buf, size_t buf_size, SerialNumberType type = SN) = 0; + virtual nsapi_size_or_error_t get_serial_number(char *buf, size_t buf_size, SerialNumberType type = SN) = 0; + + /** Get IMSI from the sim card + * + * @remark Given imsi buffer length must be 16 or more as imsi max length is 15! + * + * @param imsi preallocated char* which after successful request contains imsi + * @param buf_size size of imsi buffer + * @return NSAPI_ERROR_OK on success + * NSAPI_ERROR_PARAMETER if imsi is null or buf_size is zero or buf_size is smaller than + * MAX_IMSI_LENGTH + 1 + * NSAPI_ERROR_DEVICE_ERROR on other failures + */ + virtual nsapi_error_t get_imsi(char *imsi, size_t buf_size) = 0; + + /** Get serial number from the SIM card + * + * @param buf SIM ICCID as zero terminated string + * @param buf_size max length of SIM ICCID is MAX_ICCID_LENGTH + * @return NSAPI_ERROR_OK on success + * NSAPI_ERROR_PARAMETER if buf is null or buf_size is zero + * NSAPI_ERROR_DEVICE_ERROR on failure + */ + virtual nsapi_error_t get_iccid(char *buf, size_t buf_size) = 0; }; /** diff --git a/features/cellular/framework/API/CellularSIM.h b/features/cellular/framework/API/CellularSIM.h deleted file mode 100644 index 13ff7d3700..0000000000 --- a/features/cellular/framework/API/CellularSIM.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2017, 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 CELLULAR_SIM_H_ -#define CELLULAR_SIM_H_ - -#include - -#include "nsapi_types.h" - -namespace mbed { - -const int MAX_SIM_READY_WAITING_TIME = 30; -const int MAX_IMSI_LENGTH = 15; -const int MAX_ICCID_LENGTH = 20 + 1; // +1 for zero termination -/** - * Class CellularSIM - * - * An abstract interface for SIM card handling. - */ -class CellularSIM { -protected: - // friend of CellularDevice so that it's the only way to close/delete this class. - friend class CellularDevice; - - /** - * virtual Destructor - */ - virtual ~CellularSIM() {}; - -public: - /* enumeration for possible SIM states */ - enum SimState { - SimStateReady = 0, - SimStatePinNeeded, - SimStatePukNeeded, - SimStateUnknown - }; - - /** Open the SIM card by setting the pin code for SIM. - * - * @param sim_pin PIN for the SIM card - * @return NSAPI_ERROR_OK on success - * NSAPI_ERROR_DEVICE_ERROR on failure - */ - virtual nsapi_error_t set_pin(const char *sim_pin) = 0; - - /** Change SIM pin code. - * - * @param sim_pin Current PIN for SIM - * @param new_pin New PIN for SIM - * @return NSAPI_ERROR_OK on success - * NSAPI_ERROR_DEVICE_ERROR on failure - */ - virtual nsapi_error_t change_pin(const char *sim_pin, const char *new_pin) = 0; - - /** Change is pin query needed after boot - * - * @param sim_pin Valid PIN for SIM card - * @param query_pin False if PIN query not needed, True if PIN query needed after boot. - * @return NSAPI_ERROR_OK on success - * NSAPI_ERROR_DEVICE_ERROR on failure - */ - virtual nsapi_error_t set_pin_query(const char *sim_pin, bool query_pin) = 0; - - /** Get SIM card's state - * - * @param state current state of SIM - * @return NSAPI_ERROR_OK on success - * NSAPI_ERROR_DEVICE_ERROR on failure - */ - virtual nsapi_error_t get_sim_state(SimState &state) = 0; - - /** Get IMSI from the sim card - * @remark Given imsi buffer length must be 16 or more as imsi max length is 15! - * - * @param imsi preallocated char* which after successful request contains imsi - * @return NSAPI_ERROR_OK on success - * NSAPI_ERROR_PARAMETER if imsi if null - * NSAPI_ERROR_DEVICE_ERROR on other failures - */ - virtual nsapi_error_t get_imsi(char *imsi) = 0; - - /** Get serial number from the SIM card - * - * @param buf SIM ICCID as zero terminated string - * @param buf_size max length of SIM ICCID is MAX_ICCID_LENGTH - * @return NSAPI_ERROR_OK on success - * NSAPI_ERROR_DEVICE_ERROR on failure - */ - virtual nsapi_error_t get_iccid(char *buf, size_t buf_size) = 0; -}; - -} // namespace mbed - -#endif // CELLULAR_SIM_H_ diff --git a/features/cellular/framework/AT/AT_CellularContext.cpp b/features/cellular/framework/AT/AT_CellularContext.cpp index 1cb280318f..a2a7ddd1fa 100644 --- a/features/cellular/framework/AT/AT_CellularContext.cpp +++ b/features/cellular/framework/AT/AT_CellularContext.cpp @@ -20,7 +20,6 @@ #include "AT_CellularStack.h" #include "CellularLog.h" #include "CellularUtil.h" -#include "CellularSIM.h" #include "UARTSerial.h" #include "mbed_wait_api.h" @@ -35,6 +34,7 @@ #define USE_APN_LOOKUP (MBED_CONF_CELLULAR_USE_APN_LOOKUP || (NSAPI_PPP_AVAILABLE && MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP)) #if USE_APN_LOOKUP +#include "CellularInformation.h" #include "APN_db.h" #endif //USE_APN_LOOKUP @@ -835,12 +835,12 @@ void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr) _cb_data.error = data->error; tr_debug("CellularContext: event %d, err %d, data %d", ev, data->error, data->status_data); #if USE_APN_LOOKUP - if (st == CellularSIMStatusChanged && data->status_data == CellularSIM::SimStateReady && + if (st == CellularSIMStatusChanged && data->status_data == CellularDevice::SimStateReady && _cb_data.error == NSAPI_ERROR_OK) { if (!_apn) { char imsi[MAX_IMSI_LENGTH + 1]; wait(1); // need to wait to access SIM in some modems - _cb_data.error = _device->open_sim()->get_imsi(imsi); + _cb_data.error = _device->open_information()->get_imsi(imsi, sizeof(imsi)); if (_cb_data.error == NSAPI_ERROR_OK) { const char *apn_config = apnconfig(imsi); if (apn_config) { @@ -858,7 +858,7 @@ void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr) _semaphore.release(); } } - _device->close_sim(); + _device->close_information(); } } #endif // USE_APN_LOOKUP @@ -874,7 +874,7 @@ void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr) } else { if ((st == CellularDeviceReady && _current_op == OP_DEVICE_READY) || (st == CellularSIMStatusChanged && _current_op == OP_SIM_READY && - data->status_data == CellularSIM::SimStateReady)) { + data->status_data == CellularDevice::SimStateReady)) { // target reached, release semaphore _semaphore.release(); } else if (st == CellularRegistrationStatusChanged && (data->status_data == CellularNetwork::RegisteredHomeNetwork || diff --git a/features/cellular/framework/AT/AT_CellularDevice.cpp b/features/cellular/framework/AT/AT_CellularDevice.cpp index 0ab15c60bf..8d8b3de1a4 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.cpp +++ b/features/cellular/framework/AT/AT_CellularDevice.cpp @@ -19,7 +19,6 @@ #include "AT_CellularInformation.h" #include "AT_CellularNetwork.h" #include "AT_CellularPower.h" -#include "AT_CellularSIM.h" #include "AT_CellularSMS.h" #include "AT_CellularContext.h" #include "AT_CellularStack.h" @@ -32,11 +31,15 @@ using namespace events; 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), - _sim(0), _power(0), _information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT), + _power(0), _information(0), _context_list(0), _default_timeout(DEFAULT_AT_TIMEOUT), _modem_debug_on(false) { + MBED_ASSERT(fh); + _at = get_at_handler(fh); + MBED_ASSERT(_at); } AT_CellularDevice::~AT_CellularDevice() @@ -47,13 +50,11 @@ AT_CellularDevice::~AT_CellularDevice() _network_ref_count = 1; _sms_ref_count = 1; _power_ref_count = 1; - _sim_ref_count = 1; _info_ref_count = 1; close_network(); close_sms(); close_power(); - close_sim(); close_information(); AT_CellularContext *curr = _context_list; @@ -92,6 +93,73 @@ nsapi_error_t AT_CellularDevice::release_at_handler(ATHandler *at_handler) } } +nsapi_error_t AT_CellularDevice::get_sim_state(SimState &state) +{ + char simstr[MAX_SIM_RESPONSE_LENGTH]; + _at->lock(); + _at->flush(); + _at->cmd_start("AT+CPIN?"); + _at->cmd_stop(); + _at->resp_start("+CPIN:"); + ssize_t len = _at->read_string(simstr, sizeof(simstr)); + if (len != -1) { + if (len >= 5 && memcmp(simstr, "READY", 5) == 0) { + state = SimStateReady; + } else if (len >= 7 && memcmp(simstr, "SIM PIN", 7) == 0) { + state = SimStatePinNeeded; + } else if (len >= 7 && memcmp(simstr, "SIM PUK", 7) == 0) { + state = SimStatePukNeeded; + } else { + simstr[len] = '\0'; + tr_error("Unknown SIM state %s", simstr); + state = SimStateUnknown; + } + } else { + tr_warn("SIM not readable."); + state = SimStateUnknown; // SIM may not be ready yet or +CPIN may be unsupported command + } + _at->resp_stop(); + nsapi_error_t error = _at->get_last_error(); + _at->unlock(); +#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 AT_CellularDevice::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+CPIN="); + _at->write_string(sim_pin); + _at->cmd_stop_read_resp(); + return _at->unlock_return_error(); +} + CellularContext *AT_CellularDevice::get_context_list() const { return _context_list; @@ -178,20 +246,6 @@ CellularSMS *AT_CellularDevice::open_sms(FileHandle *fh) return _sms; } -CellularSIM *AT_CellularDevice::open_sim(FileHandle *fh) -{ - if (!_sim) { - ATHandler *atHandler = get_at_handler(fh); - if (atHandler) { - _sim = open_sim_impl(*atHandler); - } - } - if (_sim) { - _sim_ref_count++; - } - return _sim; -} - CellularPower *AT_CellularDevice::open_power(FileHandle *fh) { if (!_power) { @@ -235,11 +289,6 @@ AT_CellularPower *AT_CellularDevice::open_power_impl(ATHandler &at) return new AT_CellularPower(at); } -AT_CellularSIM *AT_CellularDevice::open_sim_impl(ATHandler &at) -{ - return new AT_CellularSIM(at); -} - AT_CellularInformation *AT_CellularDevice::open_information_impl(ATHandler &at) { return new AT_CellularInformation(at); @@ -284,19 +333,6 @@ void AT_CellularDevice::close_power() } } -void AT_CellularDevice::close_sim() -{ - if (_sim) { - _sim_ref_count--; - if (_sim_ref_count == 0) { - ATHandler *atHandler = &_sim->get_at_handler(); - delete _sim; - _sim = NULL; - release_at_handler(atHandler); - } - } -} - void AT_CellularDevice::close_information() { if (_information) { diff --git a/features/cellular/framework/AT/AT_CellularDevice.h b/features/cellular/framework/AT/AT_CellularDevice.h index 9b171a724b..2068417dba 100644 --- a/features/cellular/framework/AT/AT_CellularDevice.h +++ b/features/cellular/framework/AT/AT_CellularDevice.h @@ -26,7 +26,6 @@ class ATHandler; class AT_CellularInformation; class AT_CellularNetwork; class AT_CellularPower; -class AT_CellularSIM; class AT_CellularSMS; class AT_CellularContext; @@ -41,7 +40,12 @@ public: AT_CellularDevice(FileHandle *fh); virtual ~AT_CellularDevice(); + virtual nsapi_error_t set_pin(const char *sim_pin); + + virtual nsapi_error_t get_sim_state(SimState &state); + virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = NULL); + virtual void delete_context(CellularContext *context); virtual CellularNetwork *open_network(FileHandle *fh = NULL); @@ -50,8 +54,6 @@ public: virtual CellularPower *open_power(FileHandle *fh = NULL); - virtual CellularSIM *open_sim(FileHandle *fh = NULL); - virtual CellularInformation *open_information(FileHandle *fh = NULL); virtual void close_network(); @@ -60,8 +62,6 @@ public: virtual void close_power(); - virtual void close_sim(); - virtual void close_information(); virtual void set_timeout(int timeout); @@ -113,13 +113,6 @@ public: */ virtual AT_CellularPower *open_power_impl(ATHandler &at); - /** Create new instance of AT_CellularSIM or if overridden, modem specific implementation. - * - * @param at ATHandler reference for communication with the modem. - * @return new instance of class AT_CellularSIM - */ - virtual AT_CellularSIM *open_sim_impl(ATHandler &at); - /** Create new instance of AT_CellularInformation or if overridden, modem specific implementation. * * @param at ATHandler reference for communication with the modem. @@ -131,12 +124,12 @@ public: AT_CellularNetwork *_network; AT_CellularSMS *_sms; - AT_CellularSIM *_sim; AT_CellularPower *_power; AT_CellularInformation *_information; AT_CellularContext *_context_list; int _default_timeout; bool _modem_debug_on; + ATHandler *_at; }; } // namespace mbed diff --git a/features/cellular/framework/AT/AT_CellularInformation.cpp b/features/cellular/framework/AT/AT_CellularInformation.cpp index 73a49f4fe0..585cd211e8 100644 --- a/features/cellular/framework/AT/AT_CellularInformation.cpp +++ b/features/cellular/framework/AT/AT_CellularInformation.cpp @@ -46,6 +46,10 @@ nsapi_error_t AT_CellularInformation::get_revision(char *buf, size_t buf_size) nsapi_error_t AT_CellularInformation::get_serial_number(char *buf, size_t buf_size, SerialNumberType type) { + if (buf == NULL || buf_size == 0) { + return NSAPI_ERROR_PARAMETER; + } + if (type == SN) { return get_info("AT+CGSN", buf, buf_size); } @@ -66,8 +70,10 @@ nsapi_error_t AT_CellularInformation::get_serial_number(char *buf, size_t buf_si nsapi_error_t AT_CellularInformation::get_info(const char *cmd, char *buf, size_t buf_size) { + if (buf == NULL || buf_size == 0) { + return NSAPI_ERROR_PARAMETER; + } _at.lock(); - _at.cmd_start(cmd); _at.cmd_stop(); _at.set_delimiter(0); @@ -75,6 +81,36 @@ nsapi_error_t AT_CellularInformation::get_info(const char *cmd, char *buf, size_ _at.read_string(buf, buf_size - 1); _at.resp_stop(); _at.set_default_delimiter(); - + return _at.unlock_return_error(); +} + +nsapi_error_t AT_CellularInformation::get_imsi(char *imsi, size_t buf_size) +{ + if (imsi == NULL || buf_size == 0 || buf_size < MAX_IMSI_LENGTH + 1) { + return NSAPI_ERROR_PARAMETER; + } + _at.lock(); + _at.cmd_start("AT+CIMI"); + _at.cmd_stop(); + _at.resp_start(); + int len = _at.read_string(imsi, MAX_IMSI_LENGTH); + if (len > 0) { + imsi[len] = '\0'; + } + _at.resp_stop(); + return _at.unlock_return_error(); +} + +nsapi_error_t AT_CellularInformation::get_iccid(char *buf, size_t buf_size) +{ + if (buf == NULL || buf_size == 0) { + return NSAPI_ERROR_PARAMETER; + } + _at.lock(); + _at.cmd_start("AT+CCID?"); + _at.cmd_stop(); + _at.resp_start("+CCID:"); + _at.read_string(buf, buf_size); + _at.resp_stop(); return _at.unlock_return_error(); } diff --git a/features/cellular/framework/AT/AT_CellularInformation.h b/features/cellular/framework/AT/AT_CellularInformation.h index d9679d3f25..6e7e6f8cad 100644 --- a/features/cellular/framework/AT/AT_CellularInformation.h +++ b/features/cellular/framework/AT/AT_CellularInformation.h @@ -42,6 +42,9 @@ public: virtual nsapi_error_t get_serial_number(char *buf, size_t buf_size, SerialNumberType type); + virtual nsapi_error_t get_imsi(char *imsi, size_t buf_size); + + virtual nsapi_error_t get_iccid(char *buf, size_t buf_size); protected: /** Request information text from cellular device * diff --git a/features/cellular/framework/AT/AT_CellularSIM.cpp b/features/cellular/framework/AT/AT_CellularSIM.cpp deleted file mode 100644 index 86425a852a..0000000000 --- a/features/cellular/framework/AT/AT_CellularSIM.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (c) 2017, 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 "AT_CellularSIM.h" -#include "CellularLog.h" - -using namespace mbed; - -const int MAX_SIM_RESPONSE_LENGTH = 16; - -AT_CellularSIM::AT_CellularSIM(ATHandler &at) : AT_CellularBase(at) -{ -} - -AT_CellularSIM::~AT_CellularSIM() -{ -} - -nsapi_error_t AT_CellularSIM::get_sim_state(SimState &state) -{ - char simstr[MAX_SIM_RESPONSE_LENGTH]; - _at.lock(); - _at.flush(); - _at.cmd_start("AT+CPIN?"); - _at.cmd_stop(); - _at.resp_start("+CPIN:"); - ssize_t len = _at.read_string(simstr, sizeof(simstr)); - if (len != -1) { - if (len >= 5 && memcmp(simstr, "READY", 5) == 0) { - state = SimStateReady; - } else if (len >= 6 && memcmp(simstr, "SIM PIN", 6) == 0) { - state = SimStatePinNeeded; - } else if (len >= 6 && memcmp(simstr, "SIM PUK", 6) == 0) { - state = SimStatePukNeeded; - } else { - simstr[len] = '\0'; - tr_error("Unknown SIM state %s", simstr); - state = SimStateUnknown; - } - } else { - tr_warn("SIM not readable."); - state = SimStateUnknown; // SIM may not be ready yet or +CPIN may be unsupported command - } - _at.resp_stop(); - nsapi_error_t error = _at.get_last_error(); - _at.unlock(); -#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 AT_CellularSIM::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; - } - - _at.lock(); - _at.cmd_start("AT+CPIN="); - _at.write_string(sim_pin); - _at.cmd_stop_read_resp(); - return _at.unlock_return_error(); -} - -nsapi_error_t AT_CellularSIM::change_pin(const char *sim_pin, const char *new_pin) -{ - _at.lock(); - _at.cmd_start("AT+CPWD="); - _at.write_string("SC"); - _at.write_string(sim_pin); - _at.write_string(new_pin); - _at.cmd_stop_read_resp(); - return _at.unlock_return_error(); -} - -nsapi_error_t AT_CellularSIM::set_pin_query(const char *sim_pin, bool query_pin) -{ - _at.lock(); - if (query_pin) { - /* use the SIM locked */ - _at.cmd_start("AT+CLCK="); - _at.write_string("SC"); - _at.write_int(1); - _at.write_string(sim_pin); - _at.cmd_stop_read_resp(); - } else { - /* use the SIM unlocked */ - _at.cmd_start("AT+CLCK="); - _at.write_string("SC"); - _at.write_int(0); - _at.write_string(sim_pin); - _at.cmd_stop_read_resp(); - } - return _at.unlock_return_error(); -} - -nsapi_error_t AT_CellularSIM::get_imsi(char *imsi) -{ - if (imsi == NULL) { - return NSAPI_ERROR_PARAMETER; - } - _at.lock(); - _at.cmd_start("AT+CIMI"); - _at.cmd_stop(); - _at.resp_start(); - int len = _at.read_string(imsi, MAX_IMSI_LENGTH); - if (len > 0) { - imsi[len] = '\0'; - } - _at.resp_stop(); - return _at.unlock_return_error(); -} - -nsapi_error_t AT_CellularSIM::get_iccid(char *buf, size_t buf_size) -{ - _at.lock(); - _at.cmd_start("AT+CCID?"); - _at.cmd_stop(); - _at.resp_start("+CCID:"); - _at.read_string(buf, buf_size); - _at.resp_stop(); - return _at.unlock_return_error(); -} diff --git a/features/cellular/framework/AT/AT_CellularSIM.h b/features/cellular/framework/AT/AT_CellularSIM.h deleted file mode 100644 index 379de706bc..0000000000 --- a/features/cellular/framework/AT/AT_CellularSIM.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2017, 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 AT_CELLULAR_SIM_H_ -#define AT_CELLULAR_SIM_H_ - -#include "CellularSIM.h" -#include "AT_CellularBase.h" - -namespace mbed { - -/** - * Class AT_CellularSIM - * - * Class for SIM card handling. - */ -class AT_CellularSIM : public CellularSIM, public AT_CellularBase { - -public: - AT_CellularSIM(ATHandler &atHandler); - virtual ~AT_CellularSIM(); - -public: - virtual nsapi_error_t set_pin(const char *sim_pin); - - virtual nsapi_error_t change_pin(const char *sim_pin, const char *new_pin); - - virtual nsapi_error_t set_pin_query(const char *sim_pin, bool query_pin); - - virtual nsapi_error_t get_sim_state(SimState &state); - - virtual nsapi_error_t get_imsi(char *imsi); - - virtual nsapi_error_t get_iccid(char *buf, size_t buf_size); -}; - -} // namespace mbed - -#endif // AT_CELLULAR_SIM_H_ diff --git a/features/cellular/framework/device/CellularDevice.cpp b/features/cellular/framework/device/CellularDevice.cpp index bb623fe501..d0b48ce8c9 100644 --- a/features/cellular/framework/device/CellularDevice.cpp +++ b/features/cellular/framework/device/CellularDevice.cpp @@ -17,7 +17,6 @@ #include "CellularDevice.h" #include "CellularContext.h" -#include "CellularSIM.h" #include "CellularUtil.h" #include "CellularLog.h" #include "CellularTargets.h" @@ -50,7 +49,7 @@ MBED_WEAK CellularDevice *CellularDevice::get_default_instance() } #endif // CELLULAR_DEVICE -CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0), _power_ref_count(0), _sim_ref_count(0), +CellularDevice::CellularDevice(FileHandle *fh) : _network_ref_count(0), _sms_ref_count(0), _power_ref_count(0), _info_ref_count(0), _fh(fh), _queue(5 * EVENTS_EVENT_SIZE), _state_machine(0), _nw(0), _status_cb(0) { set_sim_pin(NULL); @@ -184,7 +183,7 @@ void CellularDevice::cellular_callback(nsapi_event_t ev, intptr_t ptr) _state_machine->set_plmn(_plmn); } } else if (cell_ev == CellularSIMStatusChanged && ptr_data->error == NSAPI_ERROR_OK && - ptr_data->status_data == CellularSIM::SimStatePinNeeded) { + ptr_data->status_data == SimStatePinNeeded) { if (strlen(_sim_pin)) { _state_machine->set_sim_pin(_sim_pin); } diff --git a/features/cellular/framework/device/CellularStateMachine.cpp b/features/cellular/framework/device/CellularStateMachine.cpp index fcf2ffab9a..2fb57a22c9 100644 --- a/features/cellular/framework/device/CellularStateMachine.cpp +++ b/features/cellular/framework/device/CellularStateMachine.cpp @@ -18,7 +18,6 @@ #include "CellularStateMachine.h" #include "CellularDevice.h" #include "CellularPower.h" -#include "CellularSIM.h" #include "CellularLog.h" #include "Thread.h" #include "UARTSerial.h" @@ -47,7 +46,7 @@ namespace mbed { CellularStateMachine::CellularStateMachine(CellularDevice &device, events::EventQueue &queue) : _cellularDevice(device), _state(STATE_INIT), _next_state(_state), _target_state(_state), - _event_status_cb(0), _network(0), _power(0), _sim(0), _queue(queue), _queue_thread(0), _sim_pin(0), + _event_status_cb(0), _network(0), _power(0), _queue(queue), _queue_thread(0), _sim_pin(0), _retry_count(0), _event_timeout(-1), _event_id(-1), _plmn(0), _command_success(false), _plmn_network_found(false), _is_retry(false), _cb_data(), _current_event(NSAPI_EVENT_CONNECTION_STATUS_CHANGE), _network_status(0) @@ -106,11 +105,6 @@ void CellularStateMachine::stop() _power = NULL; } - if (_sim) { - _cellularDevice.close_sim(); - _sim = NULL; - } - if (_network) { _cellularDevice.close_network(); _network = NULL; @@ -143,15 +137,10 @@ void CellularStateMachine::set_plmn(const char *plmn) bool CellularStateMachine::open_sim() { - if (!_sim) { - // can only fail with allocation with new and then it's critical error - _sim = _cellularDevice.open_sim(); - } - - CellularSIM::SimState state = CellularSIM::SimStateUnknown; + CellularDevice::SimState state = CellularDevice::SimStateUnknown; // wait until SIM is readable // here you could add wait(secs) if you know start delay of your SIM - _cb_data.error = _sim->get_sim_state(state); + _cb_data.error = _cellularDevice.get_sim_state(state); if (_cb_data.error != NSAPI_ERROR_OK) { tr_info("Waiting for SIM (err while reading)..."); return false; @@ -163,10 +152,10 @@ bool CellularStateMachine::open_sim() _event_status_cb((nsapi_event_t)CellularSIMStatusChanged, (intptr_t)&_cb_data); } - if (state == CellularSIM::SimStatePinNeeded) { + if (state == CellularDevice::SimStatePinNeeded) { if (strlen(_sim_pin)) { - tr_info("Entering PIN to open SIM."); - _cb_data.error = _sim->set_pin(_sim_pin); + tr_info("Entering PIN to open SIM"); + _cb_data.error = _cellularDevice.set_pin(_sim_pin); if (_cb_data.error) { tr_error("Failed to set PIN: error %d", _cb_data.error); } @@ -178,7 +167,7 @@ bool CellularStateMachine::open_sim() } } - return state == CellularSIM::SimStateReady; + return state == CellularDevice::SimStateReady; } bool CellularStateMachine::is_registered() @@ -512,8 +501,6 @@ void CellularStateMachine::state_attaching() _cb_data.error = _network->set_attach(); } if (_cb_data.error == NSAPI_ERROR_OK) { - _cellularDevice.close_sim(); - _sim = NULL; if (_event_status_cb) { _cb_data.status_data = CellularNetwork::Attached; _event_status_cb(_current_event, (intptr_t)&_cb_data); @@ -688,10 +675,8 @@ void CellularStateMachine::set_cellular_callback(mbed::Callbacklock(); + _at->flush(); + _at->cmd_start("AT+NCCID?"); + _at->cmd_stop(); + _at->resp_start("+NCCID:"); + if (_at->info_resp()) { + state = SimStateReady; + } else { + tr_warn("SIM not readable."); + state = SimStateUnknown; // SIM may not be ready yet + } + _at->resp_stop(); + return _at->unlock_return_error(); +} + AT_CellularNetwork *QUECTEL_BC95::open_network_impl(ATHandler &at) { return new QUECTEL_BC95_CellularNetwork(at); @@ -55,12 +73,13 @@ AT_CellularPower *QUECTEL_BC95::open_power_impl(ATHandler &at) return new QUECTEL_BC95_CellularPower(at); } -AT_CellularSIM *QUECTEL_BC95::open_sim_impl(ATHandler &at) -{ - return new QUECTEL_BC95_CellularSIM(at); -} - AT_CellularContext *QUECTEL_BC95::create_context_impl(ATHandler &at, const char *apn) { return new QUECTEL_BC95_CellularContext(at, this, apn); } + +AT_CellularInformation *QUECTEL_BC95::open_information_impl(ATHandler &at) +{ + return new QUECTEL_BC95_CellularInformation(at); +} + diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h index 7dd9937f4c..1df0f2d05f 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95.h @@ -27,11 +27,14 @@ public: QUECTEL_BC95(FileHandle *fh); virtual ~QUECTEL_BC95(); +public: // AT_CellularDevice + virtual nsapi_error_t get_sim_state(SimState &state); + protected: // AT_CellularDevice virtual AT_CellularNetwork *open_network_impl(ATHandler &at); virtual AT_CellularPower *open_power_impl(ATHandler &at); - virtual AT_CellularSIM *open_sim_impl(ATHandler &at); virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn); + virtual AT_CellularInformation *open_information_impl(ATHandler &at); public: // NetworkInterface void handle_urc(FileHandle *fh); diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularInformation.cpp b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularInformation.cpp new file mode 100644 index 0000000000..8bc51c5aef --- /dev/null +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularInformation.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2018, 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 "QUECTEL_BC95_CellularInformation.h" + +namespace mbed { + +QUECTEL_BC95_CellularInformation::QUECTEL_BC95_CellularInformation(ATHandler &at) : AT_CellularInformation(at) +{ +} + +QUECTEL_BC95_CellularInformation::~QUECTEL_BC95_CellularInformation() +{ +} + +// According to BC95_AT_Commands_Manual_V1.9 +nsapi_error_t QUECTEL_BC95_CellularInformation::get_iccid(char *buf, size_t buf_size) +{ + _at.lock(); + _at.cmd_start("AT+NCCID?"); + _at.cmd_stop(); + _at.resp_start("+NCCID:"); + _at.read_string(buf, buf_size); + _at.resp_stop(); + return _at.unlock_return_error(); +} + +} /* namespace mbed */ diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularSIM.h b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularInformation.h similarity index 66% rename from features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularSIM.h rename to features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularInformation.h index efbcf5b3ed..833649eee9 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularSIM.h +++ b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularInformation.h @@ -14,23 +14,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#ifndef QUECTEL_BC95_CELLULARINFORMATION_H_ +#define QUECTEL_BC95_CELLULARINFORMATION_H_ -#ifndef QUECTEL_BG96_CELLULAR_SIM_H_ -#define QUECTEL_BG96_CELLULAR_SIM_H_ - -#include "AT_CellularSIM.h" +#include "AT_CellularInformation.h" namespace mbed { -class QUECTEL_BG96_CellularSIM : public AT_CellularSIM { +class QUECTEL_BC95_CellularInformation : public AT_CellularInformation { public: - QUECTEL_BG96_CellularSIM(ATHandler &atHandler); - virtual ~QUECTEL_BG96_CellularSIM(); + QUECTEL_BC95_CellularInformation(ATHandler &at); + virtual ~QUECTEL_BC95_CellularInformation(); -public: //from CellularSIM +public: virtual nsapi_error_t get_iccid(char *buf, size_t buf_size); }; -} // namespace mbed +} /* namespace mbed */ -#endif // QUECTEL_BG96_CELLULAR_SIM_H_ +#endif /* QUECTEL_BC95_CELLULARINFORMATION_H_ */ diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularSIM.cpp b/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularSIM.cpp deleted file mode 100644 index 6da7e5f554..0000000000 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularSIM.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2017, 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 "QUECTEL_BC95_CellularSIM.h" -#include "CellularLog.h" - -using namespace mbed; - -QUECTEL_BC95_CellularSIM::QUECTEL_BC95_CellularSIM(ATHandler &atHandler) : AT_CellularSIM(atHandler) -{ - -} - -QUECTEL_BC95_CellularSIM::~QUECTEL_BC95_CellularSIM() -{ - -} - -nsapi_error_t QUECTEL_BC95_CellularSIM::get_sim_state(SimState &state) -{ - _at.lock(); - _at.flush(); - _at.cmd_start("AT+NCCID?"); - _at.cmd_stop(); - _at.resp_start("+NCCID:"); - if (_at.info_resp()) { - state = SimStateReady; - } else { - tr_warn("SIM not readable."); - state = SimStateUnknown; // SIM may not be ready yet - } - _at.resp_stop(); - return _at.unlock_return_error(); -} - -// According to BC95_AT_Commands_Manual_V1.9 -nsapi_error_t QUECTEL_BC95_CellularSIM::get_iccid(char *buf, size_t buf_size) -{ - _at.lock(); - _at.cmd_start("AT+NCCID?"); - _at.cmd_stop(); - _at.resp_start("+NCCID:"); - _at.read_string(buf, buf_size); - _at.resp_stop(); - return _at.unlock_return_error(); -} - -nsapi_error_t QUECTEL_BC95_CellularSIM::change_pin(const char *sim_pin, const char *new_pin) -{ - return NSAPI_ERROR_UNSUPPORTED; -} - -nsapi_error_t QUECTEL_BC95_CellularSIM::set_pin_query(const char *sim_pin, bool query_pin) -{ - return NSAPI_ERROR_UNSUPPORTED; -} diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp index e07b7001c0..55e673acfd 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp @@ -18,7 +18,7 @@ #include "QUECTEL_BG96.h" #include "QUECTEL_BG96_CellularNetwork.h" #include "QUECTEL_BG96_CellularStack.h" -#include "QUECTEL_BG96_CellularSIM.h" +#include "QUECTEL_BG96_CellularInformation.h" #include "QUECTEL_BG96_CellularPower.h" #include "QUECTEL_BG96_CellularContext.h" @@ -52,11 +52,6 @@ AT_CellularNetwork *QUECTEL_BG96::open_network_impl(ATHandler &at) return new QUECTEL_BG96_CellularNetwork(at); } -AT_CellularSIM *QUECTEL_BG96::open_sim_impl(ATHandler &at) -{ - return new QUECTEL_BG96_CellularSIM(at); -} - AT_CellularPower *QUECTEL_BG96::open_power_impl(ATHandler &at) { return new QUECTEL_BG96_CellularPower(at); @@ -67,3 +62,7 @@ AT_CellularContext *QUECTEL_BG96::create_context_impl(ATHandler &at, const char return new QUECTEL_BG96_CellularContext(at, this, apn); } +AT_CellularInformation *QUECTEL_BG96::open_information_impl(ATHandler &at) +{ + return new QUECTEL_BG96_CellularInformation(at); +} diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h index 86eb63bd4c..1cc8b4a892 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h @@ -29,9 +29,9 @@ public: protected: // AT_CellularDevice virtual AT_CellularNetwork *open_network_impl(ATHandler &at); - virtual AT_CellularSIM *open_sim_impl(ATHandler &at); virtual AT_CellularPower *open_power_impl(ATHandler &at); virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn); + virtual AT_CellularInformation *open_information_impl(ATHandler &at); public: void handle_urc(FileHandle *fh); }; diff --git a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularSIM.cpp b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularInformation.cpp similarity index 72% rename from features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularSIM.cpp rename to features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularInformation.cpp index 80cae03db5..c8f4319ce6 100644 --- a/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularSIM.cpp +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularInformation.cpp @@ -14,24 +14,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "QUECTEL_BG96_CellularInformation.h" -#include "QUECTEL_BG96_CellularSIM.h" -#include "CellularLog.h" +namespace mbed { -using namespace mbed; - -QUECTEL_BG96_CellularSIM::QUECTEL_BG96_CellularSIM(ATHandler &atHandler) : AT_CellularSIM(atHandler) +QUECTEL_BG96_CellularInformation::QUECTEL_BG96_CellularInformation(ATHandler &at) : AT_CellularInformation(at) { - } -QUECTEL_BG96_CellularSIM::~QUECTEL_BG96_CellularSIM() +QUECTEL_BG96_CellularInformation::~QUECTEL_BG96_CellularInformation() { - } // According to BG96_AT_Commands_Manual_V2.0 -nsapi_error_t QUECTEL_BG96_CellularSIM::get_iccid(char *buf, size_t buf_size) +nsapi_error_t QUECTEL_BG96_CellularInformation::get_iccid(char *buf, size_t buf_size) { _at.lock(); _at.cmd_start("AT+QCCID"); @@ -41,3 +37,5 @@ nsapi_error_t QUECTEL_BG96_CellularSIM::get_iccid(char *buf, size_t buf_size) _at.resp_stop(); return _at.unlock_return_error(); } + +} /* namespace mbed */ diff --git a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularSIM.h b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularInformation.h similarity index 53% rename from features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularSIM.h rename to features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularInformation.h index 498be76817..c952eac33e 100644 --- a/features/cellular/framework/targets/QUECTEL/BC95/QUECTEL_BC95_CellularSIM.h +++ b/features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularInformation.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Arm Limited and affiliates. + * Copyright (c) 2018, Arm Limited and affiliates. * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,26 +14,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#ifndef QUECTEL_BG96_CELLULARINFORMATION_H_ +#define QUECTEL_BG96_CELLULARINFORMATION_H_ -#ifndef QUECTEL_BC95_CELLULAR_SIM_H_ -#define QUECTEL_BC95_CELLULAR_SIM_H_ - -#include "AT_CellularSIM.h" +#include "AT_CellularInformation.h" namespace mbed { -class QUECTEL_BC95_CellularSIM : public AT_CellularSIM { +class QUECTEL_BG96_CellularInformation: public AT_CellularInformation { public: - QUECTEL_BC95_CellularSIM(ATHandler &atHandler); - virtual ~QUECTEL_BC95_CellularSIM(); + QUECTEL_BG96_CellularInformation(ATHandler &at); + virtual ~QUECTEL_BG96_CellularInformation(); -public: //from CellularSIM - virtual nsapi_error_t get_sim_state(SimState &state); +public: // AT_CellularInformation virtual nsapi_error_t get_iccid(char *buf, size_t buf_size); - virtual nsapi_error_t change_pin(const char *sim_pin, const char *new_pin); - virtual nsapi_error_t set_pin_query(const char *sim_pin, bool query_pin); }; -} // namespace mbed +} /* namespace mbed */ -#endif // QUECTEL_BC95_CELLULAR_SIM_H_ +#endif /* QUECTEL_BG96_CELLULARINFORMATION_H_ */