mirror of https://github.com/ARMmbed/mbed-os.git
Removed CellularSIM interface.
Moved methods to classes CellularDevice and CellularInformation. SIM interface was removed to simplify cellular usage and methods better suite new classes. Updated greentea and unit tests.pull/9472/head
parent
235c2bc00d
commit
22d9105318
|
@ -27,7 +27,6 @@
|
||||||
#include "Semaphore_stub.h"
|
#include "Semaphore_stub.h"
|
||||||
#include "CellularDevice_stub.h"
|
#include "CellularDevice_stub.h"
|
||||||
#include "equeue_stub.h"
|
#include "equeue_stub.h"
|
||||||
#include "CellularSIM.h"
|
|
||||||
|
|
||||||
using namespace mbed;
|
using namespace mbed;
|
||||||
using namespace events;
|
using namespace events;
|
||||||
|
@ -528,7 +527,7 @@ TEST_F(TestAT_CellularContext, set_sim_ready)
|
||||||
cell_callback_data_t data;
|
cell_callback_data_t data;
|
||||||
data.error = NSAPI_ERROR_OK;
|
data.error = NSAPI_ERROR_OK;
|
||||||
ctx.cellular_callback((nsapi_event_t)CellularDeviceReady, (intptr_t)&data);
|
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);
|
ctx.cellular_callback((nsapi_event_t)CellularSIMStatusChanged, (intptr_t)&data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_get_at_handler)
|
||||||
EXPECT_TRUE(dev.open_network(&fh1));
|
EXPECT_TRUE(dev.open_network(&fh1));
|
||||||
EXPECT_TRUE(dev.open_sms(&fh2));
|
EXPECT_TRUE(dev.open_sms(&fh2));
|
||||||
AT_CellularBase_stub::handler_value = AT_CellularBase_stub::handler_at_constructor_value;
|
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;
|
ATHandler_stub::fh_value = &fh1;
|
||||||
EXPECT_TRUE(dev.open_power(&fh1));
|
EXPECT_TRUE(dev.open_power(&fh1));
|
||||||
|
|
||||||
|
@ -112,19 +112,6 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_power)
|
||||||
EXPECT_TRUE(pwr1 == pwr);
|
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)
|
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_open_information)
|
||||||
{
|
{
|
||||||
FileHandle_stub fh1;
|
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);
|
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)
|
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_close_information)
|
||||||
{
|
{
|
||||||
FileHandle_stub fh1;
|
FileHandle_stub fh1;
|
||||||
|
@ -233,19 +200,18 @@ TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_set_timeout)
|
||||||
ATHandler_stub::timeout = 0;
|
ATHandler_stub::timeout = 0;
|
||||||
ATHandler_stub::default_timeout = false;
|
ATHandler_stub::default_timeout = false;
|
||||||
|
|
||||||
// no interfaces open so settings timeout should not change anything
|
|
||||||
dev.set_timeout(5000);
|
dev.set_timeout(5000);
|
||||||
EXPECT_TRUE(ATHandler_stub::timeout == 0);
|
EXPECT_TRUE(ATHandler_stub::timeout == 5000);
|
||||||
EXPECT_TRUE(ATHandler_stub::default_timeout == false);
|
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);
|
EXPECT_TRUE(ATHandler_stub::ref_count == 1);
|
||||||
|
|
||||||
dev.set_timeout(5000);
|
dev.set_timeout(5000);
|
||||||
EXPECT_TRUE(ATHandler_stub::timeout == 5000);
|
EXPECT_TRUE(ATHandler_stub::timeout == 5000);
|
||||||
EXPECT_TRUE(ATHandler_stub::default_timeout == true);
|
EXPECT_TRUE(ATHandler_stub::default_timeout == true);
|
||||||
|
|
||||||
dev.close_sim();
|
dev.close_sms();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TestAT_CellularDevice, test_AT_CellularDevice_modem_debug_on)
|
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);
|
AT_CellularDevice dev(&fh1);
|
||||||
ATHandler_stub::debug_on = false;
|
ATHandler_stub::debug_on = false;
|
||||||
|
|
||||||
// no interfaces open so debug toggling should not affect
|
|
||||||
dev.modem_debug_on(true);
|
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);
|
EXPECT_TRUE(ATHandler_stub::ref_count == 1);
|
||||||
|
|
||||||
dev.modem_debug_on(true);
|
dev.modem_debug_on(true);
|
||||||
EXPECT_TRUE(ATHandler_stub::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)
|
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;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ set(unittest-test-sources
|
||||||
stubs/AT_CellularNetwork_stub.cpp
|
stubs/AT_CellularNetwork_stub.cpp
|
||||||
stubs/ATHandler_stub.cpp
|
stubs/ATHandler_stub.cpp
|
||||||
stubs/AT_CellularSMS_stub.cpp
|
stubs/AT_CellularSMS_stub.cpp
|
||||||
stubs/AT_CellularSIM_stub.cpp
|
|
||||||
stubs/AT_CellularPower_stub.cpp
|
stubs/AT_CellularPower_stub.cpp
|
||||||
stubs/AT_CellularInformation_stub.cpp
|
stubs/AT_CellularInformation_stub.cpp
|
||||||
stubs/CellularUtil_stub.cpp
|
stubs/CellularUtil_stub.cpp
|
||||||
|
|
|
@ -34,6 +34,10 @@ protected:
|
||||||
|
|
||||||
void SetUp()
|
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()
|
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(NSAPI_ERROR_DEVICE_ERROR == aci->get_revision(buf, 8));
|
||||||
EXPECT_TRUE(strlen(buf) == 0);
|
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;
|
delete aci;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,4 +158,59 @@ TEST_F(TestAT_CellularInformation, test_AT_CellularInformation_get_serial_number
|
||||||
AT_CellularBase_stub::supported_bool = true;
|
AT_CellularBase_stub::supported_bool = true;
|
||||||
EXPECT_TRUE(NSAPI_ERROR_OK == aci.get_serial_number(buf, 8, CellularInformation::IMEI));
|
EXPECT_TRUE(NSAPI_ERROR_OK == aci.get_serial_number(buf, 8, CellularInformation::IMEI));
|
||||||
EXPECT_TRUE(strcmp("1234567", buf) == 0);
|
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));
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 <string.h>
|
|
||||||
#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);
|
|
||||||
}
|
|
|
@ -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
|
|
||||||
)
|
|
|
@ -21,7 +21,6 @@
|
||||||
#include "FileHandle_stub.h"
|
#include "FileHandle_stub.h"
|
||||||
#include "myCellularDevice.h"
|
#include "myCellularDevice.h"
|
||||||
#include "CellularStateMachine_stub.h"
|
#include "CellularStateMachine_stub.h"
|
||||||
#include "CellularSIM.h"
|
|
||||||
|
|
||||||
using namespace mbed;
|
using namespace mbed;
|
||||||
|
|
||||||
|
@ -221,7 +220,7 @@ TEST_F(TestCellularDevice, test_cellular_callback)
|
||||||
dev->cellular_callback((nsapi_event_t)CellularDeviceReady, (intptr_t)&data);
|
dev->cellular_callback((nsapi_event_t)CellularDeviceReady, (intptr_t)&data);
|
||||||
|
|
||||||
dev->set_sim_pin("1234");
|
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);
|
dev->cellular_callback((nsapi_event_t)CellularSIMStatusChanged, (intptr_t)&data);
|
||||||
|
|
||||||
CellularContext *ctx = dev->create_context();
|
CellularContext *ctx = dev->create_context();
|
||||||
|
|
|
@ -24,7 +24,7 @@ const int DEFAULT_AT_TIMEOUT = 1000;
|
||||||
using namespace mbed;
|
using namespace mbed;
|
||||||
|
|
||||||
AT_CellularDevice::AT_CellularDevice(FileHandle *fh) : CellularDevice(fh), _network(0), _sms(0),
|
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)
|
_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)
|
CellularContext *create_context(FileHandle *fh = NULL, const char *apn = MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void delete_context(CellularContext *context)
|
void delete_context(CellularContext *context)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CellularNetwork *AT_CellularDevice::open_network(FileHandle *fh)
|
CellularNetwork *AT_CellularDevice::open_network(FileHandle *fh)
|
||||||
|
@ -72,11 +70,6 @@ CellularSMS *AT_CellularDevice::open_sms(FileHandle *fh)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
CellularSIM *AT_CellularDevice::open_sim(FileHandle *fh)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
CellularPower *AT_CellularDevice::open_power(FileHandle *fh)
|
CellularPower *AT_CellularDevice::open_power(FileHandle *fh)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -99,10 +92,6 @@ void AT_CellularDevice::close_power()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void AT_CellularDevice::close_sim()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void AT_CellularDevice::close_information()
|
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)
|
void AT_CellularDevice::delete_context(CellularContext *context)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AT_CellularNetwork *AT_CellularDevice::open_network_impl(ATHandler &at)
|
AT_CellularNetwork *AT_CellularDevice::open_network_impl(ATHandler &at)
|
||||||
|
@ -142,11 +130,6 @@ AT_CellularPower *AT_CellularDevice::open_power_impl(ATHandler &at)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
AT_CellularSIM *AT_CellularDevice::open_sim_impl(ATHandler &at)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
AT_CellularInformation *AT_CellularDevice::open_information_impl(ATHandler &at)
|
AT_CellularInformation *AT_CellularDevice::open_information_impl(ATHandler &at)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -172,3 +155,13 @@ nsapi_error_t AT_CellularDevice::init_module()
|
||||||
{
|
{
|
||||||
return NSAPI_ERROR_OK;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -47,3 +47,13 @@ nsapi_error_t AT_CellularInformation::get_serial_number(char *buf, size_t buf_si
|
||||||
{
|
{
|
||||||
return NSAPI_ERROR_OK;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
|
@ -30,7 +30,7 @@ MBED_WEAK CellularDevice *CellularDevice::get_default_instance()
|
||||||
return NULL;
|
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)
|
_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;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -29,7 +29,6 @@ namespace mbed {
|
||||||
|
|
||||||
class CellularPower;
|
class CellularPower;
|
||||||
class CellularSMS;
|
class CellularSMS;
|
||||||
class CellularSIM;
|
|
||||||
class CellularInformation;
|
class CellularInformation;
|
||||||
class CellularContext;
|
class CellularContext;
|
||||||
class FileHandle;
|
class FileHandle;
|
||||||
|
@ -42,6 +41,17 @@ public:
|
||||||
delete _context_list;
|
delete _context_list;
|
||||||
delete _network;
|
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)
|
virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = NULL)
|
||||||
{
|
{
|
||||||
EventQueue que;
|
EventQueue que;
|
||||||
|
@ -74,11 +84,6 @@ public:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual CellularSIM *open_sim(FileHandle *fh = NULL)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual CellularInformation *open_information(FileHandle *fh = NULL)
|
virtual CellularInformation *open_information(FileHandle *fh = NULL)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -93,8 +98,6 @@ public:
|
||||||
|
|
||||||
virtual void close_power() {}
|
virtual void close_power() {}
|
||||||
|
|
||||||
virtual void close_sim() {}
|
|
||||||
|
|
||||||
virtual void close_information() {}
|
virtual void close_information() {}
|
||||||
|
|
||||||
virtual void set_timeout(int timeout) {}
|
virtual void set_timeout(int timeout) {}
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#if !defined(MBED_CONF_NSAPI_PRESENT)
|
#if !defined(MBED_CONF_NSAPI_PRESENT)
|
||||||
#error [NOT_SUPPORTED] A json configuration file is needed. Skipping this build.
|
#error [NOT_SUPPORTED] A json configuration file is needed. Skipping this build.
|
||||||
#endif
|
#endif
|
||||||
|
@ -27,6 +26,10 @@
|
||||||
#error [NOT_SUPPORTED] CELLULAR_DEVICE must be defined
|
#error [NOT_SUPPORTED] CELLULAR_DEVICE must be defined
|
||||||
#endif
|
#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 "greentea-client/test_env.h"
|
||||||
#include "unity.h"
|
#include "unity.h"
|
||||||
#include "utest.h"
|
#include "utest.h"
|
||||||
|
@ -36,9 +39,24 @@
|
||||||
#include "CellularLog.h"
|
#include "CellularLog.h"
|
||||||
#include "CellularDevice.h"
|
#include "CellularDevice.h"
|
||||||
#include CELLULAR_STRINGIFY(CELLULAR_DEVICE.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 UARTSerial cellular_serial(MDMTXD, MDMRXD, MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE);
|
||||||
static CellularDevice *device;
|
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()
|
static void create_device()
|
||||||
{
|
{
|
||||||
|
@ -52,10 +70,6 @@ static void open_close_interfaces()
|
||||||
TEST_ASSERT(nw != NULL);
|
TEST_ASSERT(nw != NULL);
|
||||||
device->close_network();
|
device->close_network();
|
||||||
|
|
||||||
CellularSIM *sim = device->open_sim(&cellular_serial);
|
|
||||||
TEST_ASSERT(sim != NULL);
|
|
||||||
device->close_sim();
|
|
||||||
|
|
||||||
CellularInformation *info = device->open_information(&cellular_serial);
|
CellularInformation *info = device->open_information(&cellular_serial);
|
||||||
TEST_ASSERT(info != NULL);
|
TEST_ASSERT(info != NULL);
|
||||||
device->close_information();
|
device->close_information();
|
||||||
|
@ -70,6 +84,7 @@ static void open_close_interfaces()
|
||||||
|
|
||||||
CellularContext *ctx = device->create_context();
|
CellularContext *ctx = device->create_context();
|
||||||
TEST_ASSERT(ctx != NULL);
|
TEST_ASSERT(ctx != NULL);
|
||||||
|
TEST_ASSERT(device->get_context_list() == ctx);
|
||||||
device->delete_context(ctx);
|
device->delete_context(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,10 +98,13 @@ static void other_methods()
|
||||||
CellularNetwork *nw = device->open_network(&cellular_serial);
|
CellularNetwork *nw = device->open_network(&cellular_serial);
|
||||||
TEST_ASSERT(nw != NULL);
|
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->set_timeout(5000);
|
||||||
device->modem_debug_on(true);
|
device->modem_debug_on(true);
|
||||||
device->modem_debug_on(false);
|
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()
|
static void delete_device()
|
||||||
|
@ -96,10 +114,85 @@ static void delete_device()
|
||||||
device = NULL;
|
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;
|
using namespace utest::v1;
|
||||||
|
|
||||||
static utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason)
|
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);
|
greentea_case_failure_abort_handler(source, reason);
|
||||||
return STATUS_ABORT;
|
return STATUS_ABORT;
|
||||||
}
|
}
|
||||||
|
@ -108,7 +201,11 @@ static Case cases[] = {
|
||||||
Case("CellularDevice create device", create_device, greentea_failure_handler),
|
Case("CellularDevice create device", create_device, greentea_failure_handler),
|
||||||
Case("CellularDevice Open and close interfaces", open_close_interfaces, 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 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)
|
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()
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,6 +80,12 @@ static void test_information_interface()
|
||||||
err = info->get_serial_number(buf, kbuf_size, CellularInformation::SVN);
|
err = info->get_serial_number(buf, kbuf_size, CellularInformation::SVN);
|
||||||
TEST_ASSERT(err == NSAPI_ERROR_UNSUPPORTED || err == NSAPI_ERROR_OK);
|
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();
|
dev->close_information();
|
||||||
|
|
||||||
delete [] buf;
|
delete [] buf;
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
|
@ -4,6 +4,10 @@
|
||||||
"help": "PIN code",
|
"help": "PIN code",
|
||||||
"value": "\"1234\""
|
"value": "\"1234\""
|
||||||
},
|
},
|
||||||
|
"cellular_plmn": {
|
||||||
|
"help": "plmn to select manual registration",
|
||||||
|
"value": 0
|
||||||
|
},
|
||||||
"apn": {
|
"apn": {
|
||||||
"help": "The APN string to use for this SIM/network, set to 0 if none",
|
"help": "The APN string to use for this SIM/network, set to 0 if none",
|
||||||
"value": 0
|
"value": 0
|
||||||
|
@ -27,7 +31,6 @@
|
||||||
"nsapi.dns-response-wait-time": 30000,
|
"nsapi.dns-response-wait-time": 30000,
|
||||||
"ppp-cell-iface.apn-lookup": false,
|
"ppp-cell-iface.apn-lookup": false,
|
||||||
"cellular.use-apn-lookup": false,
|
"cellular.use-apn-lookup": false,
|
||||||
"target.features_add": ["LWIP"],
|
|
||||||
"mbed-trace.enable": false,
|
"mbed-trace.enable": false,
|
||||||
"lwip.ipv4-enabled": true,
|
"lwip.ipv4-enabled": true,
|
||||||
"lwip.ipv6-enabled": true,
|
"lwip.ipv6-enabled": true,
|
||||||
|
|
|
@ -27,7 +27,6 @@ namespace mbed {
|
||||||
|
|
||||||
class CellularPower;
|
class CellularPower;
|
||||||
class CellularSMS;
|
class CellularSMS;
|
||||||
class CellularSIM;
|
|
||||||
class CellularInformation;
|
class CellularInformation;
|
||||||
class CellularNetwork;
|
class CellularNetwork;
|
||||||
class CellularContext;
|
class CellularContext;
|
||||||
|
@ -35,6 +34,7 @@ class FileHandle;
|
||||||
|
|
||||||
const int MAX_PIN_SIZE = 8;
|
const int MAX_PIN_SIZE = 8;
|
||||||
const int MAX_PLMN_SIZE = 16;
|
const int MAX_PLMN_SIZE = 16;
|
||||||
|
const int MAX_SIM_READY_WAITING_TIME = 30;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @addtogroup cellular
|
* @addtogroup cellular
|
||||||
|
@ -49,6 +49,13 @@ const int MAX_PLMN_SIZE = 16;
|
||||||
*/
|
*/
|
||||||
class CellularDevice {
|
class CellularDevice {
|
||||||
public:
|
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
|
/** 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.
|
* defined, then it returns NULL. Implementation is marked as weak.
|
||||||
|
@ -67,6 +74,23 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual ~CellularDevice();
|
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.
|
/** 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
|
* @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.
|
/** Register callback for status reporting.
|
||||||
*
|
*
|
||||||
* The specified status callback function is called on the network, and the cellular device status changes.
|
* 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.
|
* 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 deleting CellularDevice/CellularContext in callback not allowed.
|
||||||
* @remark application should not attach to this function if it uses CellularContext::attach because it contains the
|
* @remark application should not attach to this function if using CellularContext::attach as it will contain the
|
||||||
* same information.
|
* same information.
|
||||||
*
|
*
|
||||||
* @param status_cb The callback for status changes.
|
* @param status_cb The callback for status changes.
|
||||||
|
@ -189,14 +213,6 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual CellularPower *open_power(FileHandle *fh = NULL) = 0;
|
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.
|
/** 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
|
* @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;
|
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.
|
/** Closes the opened CellularInformation by deleting the CellularInformation instance.
|
||||||
*/
|
*/
|
||||||
virtual void close_information() = 0;
|
virtual void close_information() = 0;
|
||||||
|
@ -283,7 +295,6 @@ protected:
|
||||||
int _network_ref_count;
|
int _network_ref_count;
|
||||||
int _sms_ref_count;
|
int _sms_ref_count;
|
||||||
int _power_ref_count;
|
int _power_ref_count;
|
||||||
int _sim_ref_count;
|
|
||||||
int _info_ref_count;
|
int _info_ref_count;
|
||||||
FileHandle *_fh;
|
FileHandle *_fh;
|
||||||
events::EventQueue _queue;
|
events::EventQueue _queue;
|
||||||
|
|
|
@ -21,6 +21,9 @@
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include "nsapi_types.h"
|
#include "nsapi_types.h"
|
||||||
|
|
||||||
|
const int MAX_IMSI_LENGTH = 15;
|
||||||
|
const int MAX_ICCID_LENGTH = 20 + 1; // +1 for zero termination
|
||||||
|
|
||||||
namespace mbed {
|
namespace mbed {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,6 +51,7 @@ public:
|
||||||
* @param buf manufacturer identification as zero terminated string
|
* @param buf manufacturer identification as zero terminated string
|
||||||
* @param buf_size max length of manufacturer identification is 2048 characters
|
* @param buf_size max length of manufacturer identification is 2048 characters
|
||||||
* @return NSAPI_ERROR_OK on success
|
* @return NSAPI_ERROR_OK on success
|
||||||
|
* NSAPI_ERROR_PARAMETER if buf is null or buf_size is zero
|
||||||
* NSAPI_ERROR_DEVICE_ERROR on failure
|
* NSAPI_ERROR_DEVICE_ERROR on failure
|
||||||
*/
|
*/
|
||||||
virtual nsapi_error_t get_manufacturer(char *buf, size_t buf_size) = 0;
|
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 model identification as zero terminated string
|
||||||
* @param buf_size max length of model identification is 2048 characters
|
* @param buf_size max length of model identification is 2048 characters
|
||||||
* @return NSAPI_ERROR_OK on success
|
* @return NSAPI_ERROR_OK on success
|
||||||
|
* NSAPI_ERROR_PARAMETER if buf is null or buf_size is zero
|
||||||
* NSAPI_ERROR_DEVICE_ERROR on failure
|
* NSAPI_ERROR_DEVICE_ERROR on failure
|
||||||
*/
|
*/
|
||||||
virtual nsapi_error_t get_model(char *buf, size_t buf_size) = 0;
|
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 revision identification as zero terminated string
|
||||||
* @param buf_size max length of revision identification is 2048 characters
|
* @param buf_size max length of revision identification is 2048 characters
|
||||||
* @return NSAPI_ERROR_OK on success
|
* @return NSAPI_ERROR_OK on success
|
||||||
|
* NSAPI_ERROR_PARAMETER if buf is null or buf_size is zero
|
||||||
* NSAPI_ERROR_DEVICE_ERROR on failure
|
* NSAPI_ERROR_DEVICE_ERROR on failure
|
||||||
*/
|
*/
|
||||||
virtual nsapi_error_t get_revision(char *buf, size_t buf_size) = 0;
|
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 buf_size max length of serial number is 2048 characters
|
||||||
* @param type serial number type to read
|
* @param type serial number type to read
|
||||||
* @return NSAPI_ERROR_OK on success
|
* @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_UNSUPPORTED if the modem does not support SerialNumberType
|
||||||
* NSAPI_ERROR_DEVICE_ERROR on other failures
|
* NSAPI_ERROR_DEVICE_ERROR on other failures
|
||||||
*/
|
*/
|
||||||
|
@ -85,7 +92,30 @@ public:
|
||||||
IMEISV = 2, // IMEI and Software Version number
|
IMEISV = 2, // IMEI and Software Version number
|
||||||
SVN = 3 // 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;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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 <stddef.h>
|
|
||||||
|
|
||||||
#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_
|
|
|
@ -20,7 +20,6 @@
|
||||||
#include "AT_CellularStack.h"
|
#include "AT_CellularStack.h"
|
||||||
#include "CellularLog.h"
|
#include "CellularLog.h"
|
||||||
#include "CellularUtil.h"
|
#include "CellularUtil.h"
|
||||||
#include "CellularSIM.h"
|
|
||||||
#include "UARTSerial.h"
|
#include "UARTSerial.h"
|
||||||
#include "mbed_wait_api.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))
|
#define USE_APN_LOOKUP (MBED_CONF_CELLULAR_USE_APN_LOOKUP || (NSAPI_PPP_AVAILABLE && MBED_CONF_PPP_CELL_IFACE_APN_LOOKUP))
|
||||||
|
|
||||||
#if USE_APN_LOOKUP
|
#if USE_APN_LOOKUP
|
||||||
|
#include "CellularInformation.h"
|
||||||
#include "APN_db.h"
|
#include "APN_db.h"
|
||||||
#endif //USE_APN_LOOKUP
|
#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;
|
_cb_data.error = data->error;
|
||||||
tr_debug("CellularContext: event %d, err %d, data %d", ev, data->error, data->status_data);
|
tr_debug("CellularContext: event %d, err %d, data %d", ev, data->error, data->status_data);
|
||||||
#if USE_APN_LOOKUP
|
#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) {
|
_cb_data.error == NSAPI_ERROR_OK) {
|
||||||
if (!_apn) {
|
if (!_apn) {
|
||||||
char imsi[MAX_IMSI_LENGTH + 1];
|
char imsi[MAX_IMSI_LENGTH + 1];
|
||||||
wait(1); // need to wait to access SIM in some modems
|
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) {
|
if (_cb_data.error == NSAPI_ERROR_OK) {
|
||||||
const char *apn_config = apnconfig(imsi);
|
const char *apn_config = apnconfig(imsi);
|
||||||
if (apn_config) {
|
if (apn_config) {
|
||||||
|
@ -858,7 +858,7 @@ void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr)
|
||||||
_semaphore.release();
|
_semaphore.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_device->close_sim();
|
_device->close_information();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // USE_APN_LOOKUP
|
#endif // USE_APN_LOOKUP
|
||||||
|
@ -874,7 +874,7 @@ void AT_CellularContext::cellular_callback(nsapi_event_t ev, intptr_t ptr)
|
||||||
} else {
|
} else {
|
||||||
if ((st == CellularDeviceReady && _current_op == OP_DEVICE_READY) ||
|
if ((st == CellularDeviceReady && _current_op == OP_DEVICE_READY) ||
|
||||||
(st == CellularSIMStatusChanged && _current_op == OP_SIM_READY &&
|
(st == CellularSIMStatusChanged && _current_op == OP_SIM_READY &&
|
||||||
data->status_data == CellularSIM::SimStateReady)) {
|
data->status_data == CellularDevice::SimStateReady)) {
|
||||||
// target reached, release semaphore
|
// target reached, release semaphore
|
||||||
_semaphore.release();
|
_semaphore.release();
|
||||||
} else if (st == CellularRegistrationStatusChanged && (data->status_data == CellularNetwork::RegisteredHomeNetwork ||
|
} else if (st == CellularRegistrationStatusChanged && (data->status_data == CellularNetwork::RegisteredHomeNetwork ||
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
#include "AT_CellularInformation.h"
|
#include "AT_CellularInformation.h"
|
||||||
#include "AT_CellularNetwork.h"
|
#include "AT_CellularNetwork.h"
|
||||||
#include "AT_CellularPower.h"
|
#include "AT_CellularPower.h"
|
||||||
#include "AT_CellularSIM.h"
|
|
||||||
#include "AT_CellularSMS.h"
|
#include "AT_CellularSMS.h"
|
||||||
#include "AT_CellularContext.h"
|
#include "AT_CellularContext.h"
|
||||||
#include "AT_CellularStack.h"
|
#include "AT_CellularStack.h"
|
||||||
|
@ -32,11 +31,15 @@ using namespace events;
|
||||||
using namespace mbed;
|
using namespace mbed;
|
||||||
|
|
||||||
#define DEFAULT_AT_TIMEOUT 1000 // at default timeout in milliseconds
|
#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),
|
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)
|
_modem_debug_on(false)
|
||||||
{
|
{
|
||||||
|
MBED_ASSERT(fh);
|
||||||
|
_at = get_at_handler(fh);
|
||||||
|
MBED_ASSERT(_at);
|
||||||
}
|
}
|
||||||
|
|
||||||
AT_CellularDevice::~AT_CellularDevice()
|
AT_CellularDevice::~AT_CellularDevice()
|
||||||
|
@ -47,13 +50,11 @@ AT_CellularDevice::~AT_CellularDevice()
|
||||||
_network_ref_count = 1;
|
_network_ref_count = 1;
|
||||||
_sms_ref_count = 1;
|
_sms_ref_count = 1;
|
||||||
_power_ref_count = 1;
|
_power_ref_count = 1;
|
||||||
_sim_ref_count = 1;
|
|
||||||
_info_ref_count = 1;
|
_info_ref_count = 1;
|
||||||
|
|
||||||
close_network();
|
close_network();
|
||||||
close_sms();
|
close_sms();
|
||||||
close_power();
|
close_power();
|
||||||
close_sim();
|
|
||||||
close_information();
|
close_information();
|
||||||
|
|
||||||
AT_CellularContext *curr = _context_list;
|
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
|
CellularContext *AT_CellularDevice::get_context_list() const
|
||||||
{
|
{
|
||||||
return _context_list;
|
return _context_list;
|
||||||
|
@ -178,20 +246,6 @@ CellularSMS *AT_CellularDevice::open_sms(FileHandle *fh)
|
||||||
return _sms;
|
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)
|
CellularPower *AT_CellularDevice::open_power(FileHandle *fh)
|
||||||
{
|
{
|
||||||
if (!_power) {
|
if (!_power) {
|
||||||
|
@ -235,11 +289,6 @@ AT_CellularPower *AT_CellularDevice::open_power_impl(ATHandler &at)
|
||||||
return new AT_CellularPower(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)
|
AT_CellularInformation *AT_CellularDevice::open_information_impl(ATHandler &at)
|
||||||
{
|
{
|
||||||
return new AT_CellularInformation(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()
|
void AT_CellularDevice::close_information()
|
||||||
{
|
{
|
||||||
if (_information) {
|
if (_information) {
|
||||||
|
|
|
@ -26,7 +26,6 @@ class ATHandler;
|
||||||
class AT_CellularInformation;
|
class AT_CellularInformation;
|
||||||
class AT_CellularNetwork;
|
class AT_CellularNetwork;
|
||||||
class AT_CellularPower;
|
class AT_CellularPower;
|
||||||
class AT_CellularSIM;
|
|
||||||
class AT_CellularSMS;
|
class AT_CellularSMS;
|
||||||
class AT_CellularContext;
|
class AT_CellularContext;
|
||||||
|
|
||||||
|
@ -41,7 +40,12 @@ public:
|
||||||
AT_CellularDevice(FileHandle *fh);
|
AT_CellularDevice(FileHandle *fh);
|
||||||
virtual ~AT_CellularDevice();
|
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 CellularContext *create_context(FileHandle *fh = NULL, const char *apn = NULL);
|
||||||
|
|
||||||
virtual void delete_context(CellularContext *context);
|
virtual void delete_context(CellularContext *context);
|
||||||
|
|
||||||
virtual CellularNetwork *open_network(FileHandle *fh = NULL);
|
virtual CellularNetwork *open_network(FileHandle *fh = NULL);
|
||||||
|
@ -50,8 +54,6 @@ public:
|
||||||
|
|
||||||
virtual CellularPower *open_power(FileHandle *fh = NULL);
|
virtual CellularPower *open_power(FileHandle *fh = NULL);
|
||||||
|
|
||||||
virtual CellularSIM *open_sim(FileHandle *fh = NULL);
|
|
||||||
|
|
||||||
virtual CellularInformation *open_information(FileHandle *fh = NULL);
|
virtual CellularInformation *open_information(FileHandle *fh = NULL);
|
||||||
|
|
||||||
virtual void close_network();
|
virtual void close_network();
|
||||||
|
@ -60,8 +62,6 @@ public:
|
||||||
|
|
||||||
virtual void close_power();
|
virtual void close_power();
|
||||||
|
|
||||||
virtual void close_sim();
|
|
||||||
|
|
||||||
virtual void close_information();
|
virtual void close_information();
|
||||||
|
|
||||||
virtual void set_timeout(int timeout);
|
virtual void set_timeout(int timeout);
|
||||||
|
@ -113,13 +113,6 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual AT_CellularPower *open_power_impl(ATHandler &at);
|
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.
|
/** Create new instance of AT_CellularInformation or if overridden, modem specific implementation.
|
||||||
*
|
*
|
||||||
* @param at ATHandler reference for communication with the modem.
|
* @param at ATHandler reference for communication with the modem.
|
||||||
|
@ -131,12 +124,12 @@ public:
|
||||||
|
|
||||||
AT_CellularNetwork *_network;
|
AT_CellularNetwork *_network;
|
||||||
AT_CellularSMS *_sms;
|
AT_CellularSMS *_sms;
|
||||||
AT_CellularSIM *_sim;
|
|
||||||
AT_CellularPower *_power;
|
AT_CellularPower *_power;
|
||||||
AT_CellularInformation *_information;
|
AT_CellularInformation *_information;
|
||||||
AT_CellularContext *_context_list;
|
AT_CellularContext *_context_list;
|
||||||
int _default_timeout;
|
int _default_timeout;
|
||||||
bool _modem_debug_on;
|
bool _modem_debug_on;
|
||||||
|
ATHandler *_at;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mbed
|
} // namespace mbed
|
||||||
|
|
|
@ -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)
|
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) {
|
if (type == SN) {
|
||||||
return get_info("AT+CGSN", buf, buf_size);
|
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)
|
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.lock();
|
||||||
|
|
||||||
_at.cmd_start(cmd);
|
_at.cmd_start(cmd);
|
||||||
_at.cmd_stop();
|
_at.cmd_stop();
|
||||||
_at.set_delimiter(0);
|
_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.read_string(buf, buf_size - 1);
|
||||||
_at.resp_stop();
|
_at.resp_stop();
|
||||||
_at.set_default_delimiter();
|
_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();
|
return _at.unlock_return_error();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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_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:
|
protected:
|
||||||
/** Request information text from cellular device
|
/** Request information text from cellular device
|
||||||
*
|
*
|
||||||
|
|
|
@ -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();
|
|
||||||
}
|
|
|
@ -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_
|
|
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
#include "CellularDevice.h"
|
#include "CellularDevice.h"
|
||||||
#include "CellularContext.h"
|
#include "CellularContext.h"
|
||||||
#include "CellularSIM.h"
|
|
||||||
#include "CellularUtil.h"
|
#include "CellularUtil.h"
|
||||||
#include "CellularLog.h"
|
#include "CellularLog.h"
|
||||||
#include "CellularTargets.h"
|
#include "CellularTargets.h"
|
||||||
|
@ -50,7 +49,7 @@ MBED_WEAK CellularDevice *CellularDevice::get_default_instance()
|
||||||
}
|
}
|
||||||
#endif // CELLULAR_DEVICE
|
#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)
|
_info_ref_count(0), _fh(fh), _queue(5 * EVENTS_EVENT_SIZE), _state_machine(0), _nw(0), _status_cb(0)
|
||||||
{
|
{
|
||||||
set_sim_pin(NULL);
|
set_sim_pin(NULL);
|
||||||
|
@ -184,7 +183,7 @@ void CellularDevice::cellular_callback(nsapi_event_t ev, intptr_t ptr)
|
||||||
_state_machine->set_plmn(_plmn);
|
_state_machine->set_plmn(_plmn);
|
||||||
}
|
}
|
||||||
} else if (cell_ev == CellularSIMStatusChanged && ptr_data->error == NSAPI_ERROR_OK &&
|
} 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)) {
|
if (strlen(_sim_pin)) {
|
||||||
_state_machine->set_sim_pin(_sim_pin);
|
_state_machine->set_sim_pin(_sim_pin);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
#include "CellularStateMachine.h"
|
#include "CellularStateMachine.h"
|
||||||
#include "CellularDevice.h"
|
#include "CellularDevice.h"
|
||||||
#include "CellularPower.h"
|
#include "CellularPower.h"
|
||||||
#include "CellularSIM.h"
|
|
||||||
#include "CellularLog.h"
|
#include "CellularLog.h"
|
||||||
#include "Thread.h"
|
#include "Thread.h"
|
||||||
#include "UARTSerial.h"
|
#include "UARTSerial.h"
|
||||||
|
@ -47,7 +46,7 @@ namespace mbed {
|
||||||
|
|
||||||
CellularStateMachine::CellularStateMachine(CellularDevice &device, events::EventQueue &queue) :
|
CellularStateMachine::CellularStateMachine(CellularDevice &device, events::EventQueue &queue) :
|
||||||
_cellularDevice(device), _state(STATE_INIT), _next_state(_state), _target_state(_state),
|
_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),
|
_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),
|
_plmn_network_found(false), _is_retry(false), _cb_data(), _current_event(NSAPI_EVENT_CONNECTION_STATUS_CHANGE),
|
||||||
_network_status(0)
|
_network_status(0)
|
||||||
|
@ -106,11 +105,6 @@ void CellularStateMachine::stop()
|
||||||
_power = NULL;
|
_power = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_sim) {
|
|
||||||
_cellularDevice.close_sim();
|
|
||||||
_sim = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_network) {
|
if (_network) {
|
||||||
_cellularDevice.close_network();
|
_cellularDevice.close_network();
|
||||||
_network = NULL;
|
_network = NULL;
|
||||||
|
@ -143,15 +137,10 @@ void CellularStateMachine::set_plmn(const char *plmn)
|
||||||
|
|
||||||
bool CellularStateMachine::open_sim()
|
bool CellularStateMachine::open_sim()
|
||||||
{
|
{
|
||||||
if (!_sim) {
|
CellularDevice::SimState state = CellularDevice::SimStateUnknown;
|
||||||
// can only fail with allocation with new and then it's critical error
|
|
||||||
_sim = _cellularDevice.open_sim();
|
|
||||||
}
|
|
||||||
|
|
||||||
CellularSIM::SimState state = CellularSIM::SimStateUnknown;
|
|
||||||
// wait until SIM is readable
|
// wait until SIM is readable
|
||||||
// here you could add wait(secs) if you know start delay of your SIM
|
// 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) {
|
if (_cb_data.error != NSAPI_ERROR_OK) {
|
||||||
tr_info("Waiting for SIM (err while reading)...");
|
tr_info("Waiting for SIM (err while reading)...");
|
||||||
return false;
|
return false;
|
||||||
|
@ -163,10 +152,10 @@ bool CellularStateMachine::open_sim()
|
||||||
_event_status_cb((nsapi_event_t)CellularSIMStatusChanged, (intptr_t)&_cb_data);
|
_event_status_cb((nsapi_event_t)CellularSIMStatusChanged, (intptr_t)&_cb_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state == CellularSIM::SimStatePinNeeded) {
|
if (state == CellularDevice::SimStatePinNeeded) {
|
||||||
if (strlen(_sim_pin)) {
|
if (strlen(_sim_pin)) {
|
||||||
tr_info("Entering PIN to open SIM.");
|
tr_info("Entering PIN to open SIM");
|
||||||
_cb_data.error = _sim->set_pin(_sim_pin);
|
_cb_data.error = _cellularDevice.set_pin(_sim_pin);
|
||||||
if (_cb_data.error) {
|
if (_cb_data.error) {
|
||||||
tr_error("Failed to set PIN: error %d", _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()
|
bool CellularStateMachine::is_registered()
|
||||||
|
@ -512,8 +501,6 @@ void CellularStateMachine::state_attaching()
|
||||||
_cb_data.error = _network->set_attach();
|
_cb_data.error = _network->set_attach();
|
||||||
}
|
}
|
||||||
if (_cb_data.error == NSAPI_ERROR_OK) {
|
if (_cb_data.error == NSAPI_ERROR_OK) {
|
||||||
_cellularDevice.close_sim();
|
|
||||||
_sim = NULL;
|
|
||||||
if (_event_status_cb) {
|
if (_event_status_cb) {
|
||||||
_cb_data.status_data = CellularNetwork::Attached;
|
_cb_data.status_data = CellularNetwork::Attached;
|
||||||
_event_status_cb(_current_event, (intptr_t)&_cb_data);
|
_event_status_cb(_current_event, (intptr_t)&_cb_data);
|
||||||
|
@ -688,10 +675,8 @@ void CellularStateMachine::set_cellular_callback(mbed::Callback<void(nsapi_event
|
||||||
|
|
||||||
bool CellularStateMachine::check_is_target_reached()
|
bool CellularStateMachine::check_is_target_reached()
|
||||||
{
|
{
|
||||||
tr_debug("check_is_target_reached(): target state %s, _state: %s, _cb_data.error: %d, _event_id: %d,_is_retry: %d", get_state_string(_target_state), get_state_string(_state), _cb_data.error, _event_id, _is_retry);
|
tr_debug("check_is_target_reached(): target state %s, _state: %s, _cb_data.error: %d, _event_id: %d, _is_retry: %d", get_state_string(_target_state), get_state_string(_state), _cb_data.error, _event_id, _is_retry);
|
||||||
|
|
||||||
if ((_target_state == _state && _cb_data.error == NSAPI_ERROR_OK && !_is_retry) || _event_id == STM_STOPPED) {
|
if ((_target_state == _state && _cb_data.error == NSAPI_ERROR_OK && !_is_retry) || _event_id == STM_STOPPED) {
|
||||||
tr_debug("Target state reached: %s, _cb_data.error: %d, _event_id: %d", get_state_string(_target_state), _cb_data.error, _event_id);
|
|
||||||
_event_id = -1;
|
_event_id = -1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,6 @@ class Thread;
|
||||||
namespace mbed {
|
namespace mbed {
|
||||||
|
|
||||||
class CellularPower;
|
class CellularPower;
|
||||||
class CellularSIM;
|
|
||||||
class CellularDevice;
|
class CellularDevice;
|
||||||
|
|
||||||
const int RETRY_ARRAY_SIZE = 10;
|
const int RETRY_ARRAY_SIZE = 10;
|
||||||
|
@ -168,7 +167,6 @@ private:
|
||||||
|
|
||||||
CellularNetwork *_network;
|
CellularNetwork *_network;
|
||||||
CellularPower *_power;
|
CellularPower *_power;
|
||||||
CellularSIM *_sim;
|
|
||||||
events::EventQueue &_queue;
|
events::EventQueue &_queue;
|
||||||
rtos::Thread *_queue_thread;
|
rtos::Thread *_queue_thread;
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,10 @@
|
||||||
|
|
||||||
#include "QUECTEL_BC95_CellularNetwork.h"
|
#include "QUECTEL_BC95_CellularNetwork.h"
|
||||||
#include "QUECTEL_BC95_CellularPower.h"
|
#include "QUECTEL_BC95_CellularPower.h"
|
||||||
#include "QUECTEL_BC95_CellularSIM.h"
|
|
||||||
#include "QUECTEL_BC95_CellularContext.h"
|
#include "QUECTEL_BC95_CellularContext.h"
|
||||||
|
#include "QUECTEL_BC95_CellularInformation.h"
|
||||||
#include "QUECTEL_BC95.h"
|
#include "QUECTEL_BC95.h"
|
||||||
|
#include "CellularLog.h"
|
||||||
|
|
||||||
#define CONNECT_DELIM "\r\n"
|
#define CONNECT_DELIM "\r\n"
|
||||||
#define CONNECT_BUFFER_SIZE (1280 + 80 + 80) // AT response + sscanf format
|
#define CONNECT_BUFFER_SIZE (1280 + 80 + 80) // AT response + sscanf format
|
||||||
|
@ -45,6 +46,23 @@ QUECTEL_BC95::~QUECTEL_BC95()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsapi_error_t QUECTEL_BC95::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();
|
||||||
|
}
|
||||||
|
|
||||||
AT_CellularNetwork *QUECTEL_BC95::open_network_impl(ATHandler &at)
|
AT_CellularNetwork *QUECTEL_BC95::open_network_impl(ATHandler &at)
|
||||||
{
|
{
|
||||||
return new QUECTEL_BC95_CellularNetwork(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);
|
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)
|
AT_CellularContext *QUECTEL_BC95::create_context_impl(ATHandler &at, const char *apn)
|
||||||
{
|
{
|
||||||
return new QUECTEL_BC95_CellularContext(at, this, apn);
|
return new QUECTEL_BC95_CellularContext(at, this, apn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AT_CellularInformation *QUECTEL_BC95::open_information_impl(ATHandler &at)
|
||||||
|
{
|
||||||
|
return new QUECTEL_BC95_CellularInformation(at);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,11 +27,14 @@ public:
|
||||||
QUECTEL_BC95(FileHandle *fh);
|
QUECTEL_BC95(FileHandle *fh);
|
||||||
virtual ~QUECTEL_BC95();
|
virtual ~QUECTEL_BC95();
|
||||||
|
|
||||||
|
public: // AT_CellularDevice
|
||||||
|
virtual nsapi_error_t get_sim_state(SimState &state);
|
||||||
|
|
||||||
protected: // AT_CellularDevice
|
protected: // AT_CellularDevice
|
||||||
virtual AT_CellularNetwork *open_network_impl(ATHandler &at);
|
virtual AT_CellularNetwork *open_network_impl(ATHandler &at);
|
||||||
virtual AT_CellularPower *open_power_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_CellularContext *create_context_impl(ATHandler &at, const char *apn);
|
||||||
|
virtual AT_CellularInformation *open_information_impl(ATHandler &at);
|
||||||
|
|
||||||
public: // NetworkInterface
|
public: // NetworkInterface
|
||||||
void handle_urc(FileHandle *fh);
|
void handle_urc(FileHandle *fh);
|
||||||
|
|
|
@ -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 */
|
|
@ -14,23 +14,22 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
#ifndef QUECTEL_BC95_CELLULARINFORMATION_H_
|
||||||
|
#define QUECTEL_BC95_CELLULARINFORMATION_H_
|
||||||
|
|
||||||
#ifndef QUECTEL_BG96_CELLULAR_SIM_H_
|
#include "AT_CellularInformation.h"
|
||||||
#define QUECTEL_BG96_CELLULAR_SIM_H_
|
|
||||||
|
|
||||||
#include "AT_CellularSIM.h"
|
|
||||||
|
|
||||||
namespace mbed {
|
namespace mbed {
|
||||||
|
|
||||||
class QUECTEL_BG96_CellularSIM : public AT_CellularSIM {
|
class QUECTEL_BC95_CellularInformation : public AT_CellularInformation {
|
||||||
public:
|
public:
|
||||||
QUECTEL_BG96_CellularSIM(ATHandler &atHandler);
|
QUECTEL_BC95_CellularInformation(ATHandler &at);
|
||||||
virtual ~QUECTEL_BG96_CellularSIM();
|
virtual ~QUECTEL_BC95_CellularInformation();
|
||||||
|
|
||||||
public: //from CellularSIM
|
public:
|
||||||
virtual nsapi_error_t get_iccid(char *buf, size_t buf_size);
|
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_ */
|
|
@ -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;
|
|
||||||
}
|
|
|
@ -18,7 +18,7 @@
|
||||||
#include "QUECTEL_BG96.h"
|
#include "QUECTEL_BG96.h"
|
||||||
#include "QUECTEL_BG96_CellularNetwork.h"
|
#include "QUECTEL_BG96_CellularNetwork.h"
|
||||||
#include "QUECTEL_BG96_CellularStack.h"
|
#include "QUECTEL_BG96_CellularStack.h"
|
||||||
#include "QUECTEL_BG96_CellularSIM.h"
|
#include "QUECTEL_BG96_CellularInformation.h"
|
||||||
#include "QUECTEL_BG96_CellularPower.h"
|
#include "QUECTEL_BG96_CellularPower.h"
|
||||||
#include "QUECTEL_BG96_CellularContext.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);
|
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)
|
AT_CellularPower *QUECTEL_BG96::open_power_impl(ATHandler &at)
|
||||||
{
|
{
|
||||||
return new QUECTEL_BG96_CellularPower(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);
|
return new QUECTEL_BG96_CellularContext(at, this, apn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AT_CellularInformation *QUECTEL_BG96::open_information_impl(ATHandler &at)
|
||||||
|
{
|
||||||
|
return new QUECTEL_BG96_CellularInformation(at);
|
||||||
|
}
|
||||||
|
|
|
@ -29,9 +29,9 @@ public:
|
||||||
|
|
||||||
protected: // AT_CellularDevice
|
protected: // AT_CellularDevice
|
||||||
virtual AT_CellularNetwork *open_network_impl(ATHandler &at);
|
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_CellularPower *open_power_impl(ATHandler &at);
|
||||||
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn);
|
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn);
|
||||||
|
virtual AT_CellularInformation *open_information_impl(ATHandler &at);
|
||||||
public:
|
public:
|
||||||
void handle_urc(FileHandle *fh);
|
void handle_urc(FileHandle *fh);
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,24 +14,20 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
#include "QUECTEL_BG96_CellularInformation.h"
|
||||||
|
|
||||||
#include "QUECTEL_BG96_CellularSIM.h"
|
namespace mbed {
|
||||||
#include "CellularLog.h"
|
|
||||||
|
|
||||||
using namespace mbed;
|
QUECTEL_BG96_CellularInformation::QUECTEL_BG96_CellularInformation(ATHandler &at) : AT_CellularInformation(at)
|
||||||
|
|
||||||
QUECTEL_BG96_CellularSIM::QUECTEL_BG96_CellularSIM(ATHandler &atHandler) : AT_CellularSIM(atHandler)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QUECTEL_BG96_CellularSIM::~QUECTEL_BG96_CellularSIM()
|
QUECTEL_BG96_CellularInformation::~QUECTEL_BG96_CellularInformation()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// According to BG96_AT_Commands_Manual_V2.0
|
// 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.lock();
|
||||||
_at.cmd_start("AT+QCCID");
|
_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();
|
_at.resp_stop();
|
||||||
return _at.unlock_return_error();
|
return _at.unlock_return_error();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} /* namespace mbed */
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2017, Arm Limited and affiliates.
|
* Copyright (c) 2018, Arm Limited and affiliates.
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@ -14,26 +14,22 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
#ifndef QUECTEL_BG96_CELLULARINFORMATION_H_
|
||||||
|
#define QUECTEL_BG96_CELLULARINFORMATION_H_
|
||||||
|
|
||||||
#ifndef QUECTEL_BC95_CELLULAR_SIM_H_
|
#include "AT_CellularInformation.h"
|
||||||
#define QUECTEL_BC95_CELLULAR_SIM_H_
|
|
||||||
|
|
||||||
#include "AT_CellularSIM.h"
|
|
||||||
|
|
||||||
namespace mbed {
|
namespace mbed {
|
||||||
|
|
||||||
class QUECTEL_BC95_CellularSIM : public AT_CellularSIM {
|
class QUECTEL_BG96_CellularInformation: public AT_CellularInformation {
|
||||||
public:
|
public:
|
||||||
QUECTEL_BC95_CellularSIM(ATHandler &atHandler);
|
QUECTEL_BG96_CellularInformation(ATHandler &at);
|
||||||
virtual ~QUECTEL_BC95_CellularSIM();
|
virtual ~QUECTEL_BG96_CellularInformation();
|
||||||
|
|
||||||
public: //from CellularSIM
|
public: // AT_CellularInformation
|
||||||
virtual nsapi_error_t get_sim_state(SimState &state);
|
|
||||||
virtual nsapi_error_t get_iccid(char *buf, size_t buf_size);
|
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_ */
|
Loading…
Reference in New Issue