mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #9508 from ARMmbed/release-candidate
Release candidate for mbed-os-5.11.3pull/9634/head mbed-os-5.11.3
commit
a8d1d26fa7
|
@ -19,7 +19,7 @@
|
|||
<!--
|
||||
Required
|
||||
Add detailed description of what you are reporting.
|
||||
Good example: https://os.mbed.com/docs/latest/reference/workflow.html
|
||||
Good example: https://os.mbed.com/docs/mbed-os/latest/contributing/workflow.html
|
||||
Things to consider sharing:
|
||||
- What target does this relate to?
|
||||
- What toolchain (name + version) are you using?
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<!--
|
||||
Required
|
||||
Add here detailed changes summary, testing results, dependencies
|
||||
Good example: https://os.mbed.com/docs/latest/reference/workflow.html (Pull request template)
|
||||
Good example: https://os.mbed.com/docs/mbed-os/latest/contributing/workflow.html (Pull request template)
|
||||
-->
|
||||
|
||||
|
||||
|
|
54
.travis.yml
54
.travis.yml
|
@ -85,7 +85,6 @@ matrix:
|
|||
- doxygen doxyfile_options 2>&1
|
||||
# Once Mbed OS has been fixed, enable the full test by replacing the top line with this:
|
||||
# - ( ! doxygen doxyfile_options 2>&1 | grep . )
|
||||
|
||||
# Assert that all binary libraries are named correctly
|
||||
# The strange command below asserts that there are exactly 0 libraries
|
||||
# that do not start with lib
|
||||
|
@ -106,12 +105,20 @@ matrix:
|
|||
install:
|
||||
# Install dependencies
|
||||
- sudo apt-get install gcc-arm-embedded
|
||||
- pip install -r requirements.txt
|
||||
- pip install pytest pylint hypothesis==3.88.3 mock coverage coveralls
|
||||
# Print versions we use
|
||||
|
||||
- arm-none-eabi-gcc --version
|
||||
# Add additional dependencies specific for testing
|
||||
- python --version
|
||||
- |-
|
||||
tr -d ' ' >> requirements.txt <<< "
|
||||
mock==2.0.0
|
||||
pytest==3.3.0
|
||||
pylint>=1.9,<2
|
||||
hypothesis>=3,<4
|
||||
coverage>=4.5,<5
|
||||
coveralls>=1.5,<2
|
||||
"
|
||||
# ... and install.
|
||||
- pip install -r requirements.txt
|
||||
- pip list --verbose
|
||||
script:
|
||||
# Run local testing on tools
|
||||
|
@ -122,7 +129,27 @@ matrix:
|
|||
after_success:
|
||||
# Coverage for tools
|
||||
- coveralls
|
||||
# Report success since we have overridden default behaviour
|
||||
# Report success since we have overridden default behavior
|
||||
- bash -c "$STATUS" success "Local $NAME testing has passed"
|
||||
|
||||
- env:
|
||||
- NAME=doxy-spellcheck
|
||||
|
||||
install:
|
||||
- sudo apt-get install aspell
|
||||
|
||||
script:
|
||||
# Run local testing on header file doxy
|
||||
- ./tools/test/travis-ci/doxy-spellchecker/spell.sh drivers
|
||||
- ./tools/test/travis-ci/doxy-spellchecker/spell.sh platform
|
||||
- ./tools/test/travis-ci/doxy-spellchecker/spell.sh events
|
||||
- ./tools/test/travis-ci/doxy-spellchecker/spell.sh rtos
|
||||
- ./tools/test/travis-ci/doxy-spellchecker/spell.sh features/netsocket
|
||||
|
||||
after_success:
|
||||
# Coverage for tools
|
||||
- coveralls
|
||||
# Report success since we have overridden default behavior
|
||||
- bash -c "$STATUS" success "Local $NAME testing has passed"
|
||||
|
||||
# - <<: *tools-pytest
|
||||
|
@ -275,9 +302,18 @@ matrix:
|
|||
- env:
|
||||
- NAME=licence_check
|
||||
script:
|
||||
- echo 'Checking that there is no GPL licence text in code'
|
||||
- ! git grep -q --ignore-case "gnu general public";
|
||||
- ! git grep -q --ignore-case "gnu library general public";
|
||||
- >-
|
||||
! grep --recursive --max-count=100 --ignore-case --exclude .travis.yml \
|
||||
"gnu general\|gnu lesser\|lesser general\|public license"
|
||||
|
||||
- env:
|
||||
- NAME=include_check
|
||||
script:
|
||||
- echo 'Checking that there are no '#include "mbed.h"' in code where it should not be'
|
||||
- |
|
||||
! git grep '^#include\s["'"']mbed.h['"'"]$' -- '*.c' '*.h' '*.cpp' '*.hpp' \
|
||||
':!*platform_mbed.h' ':!*TESTS/*' ':!TEST_APPS/' ':!UNITTESTS/' \
|
||||
':!*tests/*' ':!*targets/*' ':!*TARGET_*' ':!*unsupported/*'
|
||||
|
||||
- env:
|
||||
- NAME=psa-autogen
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
|
||||
Mbed OS is an open-source, device software platform for the Internet of Things. Contributions are an important part of the platform, and our goal is to make it as simple as possible to become a contributor.
|
||||
|
||||
To encourage productive collaboration, as well as robust, consistent and maintainable code, we have a set of guidelines for [contributing to Mbed OS](https://os.mbed.com/docs/latest/reference/contributing.html).
|
||||
To encourage productive collaboration, as well as robust, consistent and maintainable code, we have a set of guidelines for [contributing to Mbed OS](https://os.mbed.com/docs/mbed-os/latest/contributing/index.html).
|
||||
|
|
|
@ -60,7 +60,7 @@ class CrashReportingTest(BaseHostTest):
|
|||
wait_after_reset = wait_after_reset if wait_after_reset is not None else DEFAULT_CYCLE_PERIOD
|
||||
|
||||
#Wait 2 seconds for system to init
|
||||
time.sleep(2.0)
|
||||
time.sleep(7.0)
|
||||
#self.send_kv(MSG_KEY_SYNC, MSG_VALUE_DUMMY)
|
||||
self.send_kv(MSG_KEY_DEVICE_ERROR, MSG_VALUE_DUMMY)
|
||||
time.sleep(5.0)
|
||||
|
|
|
@ -128,6 +128,7 @@ void flashiap_cross_sector_program_test()
|
|||
agg_size += sector_size;
|
||||
address -= sector_size;
|
||||
}
|
||||
utest_printf("ROM ends at 0x%lx, test starts at 0x%lx\n", FLASHIAP_APP_ROM_END_ADDR, address);
|
||||
TEST_SKIP_UNLESS_MESSAGE(address >= FLASHIAP_APP_ROM_END_ADDR, "Test skipped. Test region overlaps code.");
|
||||
ret = flash_device.erase(address, agg_size);
|
||||
TEST_ASSERT_EQUAL_INT32(0, ret);
|
||||
|
@ -184,6 +185,7 @@ void flashiap_program_error_test()
|
|||
TEST_ASSERT_TRUE(address != 0UL);
|
||||
|
||||
// unaligned address
|
||||
utest_printf("ROM ends at 0x%lx, test starts at 0x%lx\n", FLASHIAP_APP_ROM_END_ADDR, address);
|
||||
TEST_SKIP_UNLESS_MESSAGE(address >= FLASHIAP_APP_ROM_END_ADDR, "Test skipped. Test region overlaps code.");
|
||||
ret = flash_device.erase(address + 1, sector_size);
|
||||
TEST_ASSERT_EQUAL_INT32(-1, ret);
|
||||
|
@ -220,6 +222,9 @@ void flashiap_timing_test()
|
|||
utest_printf("\nFlash timing:\n");
|
||||
uint32_t sector_size = flash_device.get_sector_size(end_address - 1UL);
|
||||
uint32_t base_address = end_address - sector_size;
|
||||
utest_printf("ROM ends at 0x%lx, test starts at 0x%lx\n", FLASHIAP_APP_ROM_END_ADDR, base_address);
|
||||
TEST_SKIP_UNLESS_MESSAGE(base_address >= FLASHIAP_APP_ROM_END_ADDR, "Test skipped. Test region overlaps code.");
|
||||
|
||||
timer.start();
|
||||
for (num_write_sizes = 0; num_write_sizes < max_write_sizes; num_write_sizes++) {
|
||||
if (write_size > sector_size) {
|
||||
|
|
|
@ -175,6 +175,10 @@ void flash_erase_sector_test()
|
|||
uint32_t last_sector_size = flash_get_sector_size(&test_flash, addr_after_last - 1);
|
||||
uint32_t last_sector = addr_after_last - last_sector_size;
|
||||
TEST_ASSERT_EQUAL_INT32(0, last_sector % last_sector_size);
|
||||
|
||||
utest_printf("ROM ends at 0x%lx, test starts at 0x%lx\n", FLASHIAP_APP_ROM_END_ADDR, last_sector);
|
||||
TEST_SKIP_UNLESS_MESSAGE(last_sector >= FLASHIAP_APP_ROM_END_ADDR, "Test skipped. Test region overlaps code.");
|
||||
|
||||
ret = flash_erase_sector(&test_flash, last_sector);
|
||||
TEST_ASSERT_EQUAL_INT32(0, ret);
|
||||
|
||||
|
@ -201,6 +205,9 @@ void flash_program_page_test()
|
|||
|
||||
// sector size might not be same as page size
|
||||
uint32_t erase_sector_boundary = ALIGN_DOWN(address, flash_get_sector_size(&test_flash, address));
|
||||
utest_printf("ROM ends at 0x%lx, test starts at 0x%lx\n", FLASHIAP_APP_ROM_END_ADDR, erase_sector_boundary);
|
||||
TEST_SKIP_UNLESS_MESSAGE(erase_sector_boundary >= FLASHIAP_APP_ROM_END_ADDR, "Test skipped. Test region overlaps code.");
|
||||
|
||||
ret = flash_erase_sector(&test_flash, erase_sector_boundary);
|
||||
TEST_ASSERT_EQUAL_INT32(0, ret);
|
||||
|
||||
|
|
|
@ -53,12 +53,17 @@ void test_crash_reporting()
|
|||
|
||||
// Report readiness
|
||||
greentea_send_kv(MSG_KEY_DEVICE_READY, MSG_VALUE_DUMMY);
|
||||
printf("\nMessage sent: %s\n", MSG_KEY_DEVICE_READY);
|
||||
|
||||
static char _key[MSG_KEY_LEN + 1] = { };
|
||||
static char _value[MSG_VALUE_LEN + 1] = { };
|
||||
|
||||
printf("\nWaiting for crash inject error message: %s\n", MSG_KEY_DEVICE_ERROR);
|
||||
greentea_parse_kv(_key, _value, MSG_KEY_LEN, MSG_VALUE_LEN);
|
||||
printf("\nCrash inject error message received\n");
|
||||
|
||||
if (strcmp(_key, MSG_KEY_DEVICE_ERROR) == 0) {
|
||||
printf("\nForcing error\n");
|
||||
MBED_ERROR1(MBED_ERROR_OUT_OF_MEMORY, "Executing crash reporting test.", 0xDEADBAD);
|
||||
TEST_ASSERT_MESSAGE(0, "crash_reporting() error call failed.");
|
||||
}
|
||||
|
@ -67,7 +72,7 @@ void test_crash_reporting()
|
|||
|
||||
int main(void)
|
||||
{
|
||||
GREENTEA_SETUP(30, "crash_reporting");
|
||||
GREENTEA_SETUP(40, "crash_reporting");
|
||||
test_crash_reporting();
|
||||
GREENTEA_TESTSUITE_RESULT(0);
|
||||
|
||||
|
|
|
@ -245,7 +245,10 @@ void test_handler_called_once(void)
|
|||
int32_t sem_slots = st.sem_wait(0);
|
||||
TEST_ASSERT_EQUAL_INT32(0, sem_slots);
|
||||
|
||||
sem_slots = st.sem_wait(osWaitForever);
|
||||
// Wait in a busy loop to prevent entering sleep or deepsleep modes.
|
||||
while (sem_slots != 1) {
|
||||
sem_slots = st.sem_wait(0);
|
||||
}
|
||||
us_timestamp_t t2 = st.get_time();
|
||||
TEST_ASSERT_EQUAL_INT32(1, sem_slots);
|
||||
TEST_ASSERT_EQUAL_UINT32(1, st.get_tick());
|
||||
|
|
|
@ -243,6 +243,10 @@ content at minimum:
|
|||
"help" : "Port of echo server",
|
||||
"value" : "7"
|
||||
}
|
||||
"echo-server-discard-port" : {
|
||||
"help" : "Discard port of echo server",
|
||||
"value" : "9"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
|
@ -160,7 +160,7 @@ static void net_bringup()
|
|||
// Test setup
|
||||
utest::v1::status_t test_setup(const size_t number_of_cases)
|
||||
{
|
||||
GREENTEA_SETUP(120, "default_auto");
|
||||
GREENTEA_SETUP(200, "default_auto");
|
||||
net_bringup();
|
||||
return verbose_test_setup_handler(number_of_cases);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@
|
|||
using namespace utest::v1;
|
||||
|
||||
namespace {
|
||||
NetworkInterface *net;
|
||||
Timer tc_bucket; // Timer to limit a test cases run time
|
||||
}
|
||||
|
||||
|
@ -45,11 +44,6 @@ mbed_stats_socket_t tcp_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT];
|
|||
char tcp_global::rx_buffer[RX_BUFF_SIZE];
|
||||
char tcp_global::tx_buffer[TX_BUFF_SIZE];
|
||||
|
||||
NetworkInterface *get_interface()
|
||||
{
|
||||
return net;
|
||||
}
|
||||
|
||||
void drop_bad_packets(TCPSocket &sock, int orig_timeout)
|
||||
{
|
||||
nsapi_error_t err;
|
||||
|
@ -65,7 +59,7 @@ void drop_bad_packets(TCPSocket &sock, int orig_timeout)
|
|||
|
||||
static void _ifup()
|
||||
{
|
||||
net = NetworkInterface::get_default_instance();
|
||||
NetworkInterface *net = NetworkInterface::get_default_instance();
|
||||
nsapi_error_t err = net->connect();
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
|
||||
printf("MBED: TCPClient IP address is '%s'\n", net->get_ip_address());
|
||||
|
@ -73,38 +67,42 @@ static void _ifup()
|
|||
|
||||
static void _ifdown()
|
||||
{
|
||||
net->disconnect();
|
||||
NetworkInterface::get_default_instance()->disconnect();
|
||||
printf("MBED: ifdown\n");
|
||||
}
|
||||
|
||||
nsapi_error_t tcpsocket_connect_to_srv(TCPSocket &sock, uint16_t port)
|
||||
{
|
||||
SocketAddress tcp_addr;
|
||||
|
||||
NetworkInterface::get_default_instance()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &tcp_addr);
|
||||
tcp_addr.set_port(port);
|
||||
|
||||
printf("MBED: Server '%s', port %d\n", tcp_addr.get_ip_address(), tcp_addr.get_port());
|
||||
|
||||
nsapi_error_t err = sock.open(NetworkInterface::get_default_instance());
|
||||
if (err != NSAPI_ERROR_OK) {
|
||||
printf("Error from sock.open: %d\n", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = sock.connect(tcp_addr);
|
||||
if (err != NSAPI_ERROR_OK) {
|
||||
printf("Error from sock.connect: %d\n", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
nsapi_error_t tcpsocket_connect_to_echo_srv(TCPSocket &sock)
|
||||
{
|
||||
SocketAddress tcp_addr;
|
||||
|
||||
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &tcp_addr);
|
||||
tcp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
|
||||
|
||||
nsapi_error_t err = sock.open(get_interface());
|
||||
if (err != NSAPI_ERROR_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return sock.connect(tcp_addr);
|
||||
return tcpsocket_connect_to_srv(sock, MBED_CONF_APP_ECHO_SERVER_PORT);
|
||||
}
|
||||
|
||||
nsapi_error_t tcpsocket_connect_to_discard_srv(TCPSocket &sock)
|
||||
{
|
||||
SocketAddress tcp_addr;
|
||||
|
||||
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &tcp_addr);
|
||||
tcp_addr.set_port(9);
|
||||
|
||||
nsapi_error_t err = sock.open(get_interface());
|
||||
if (err != NSAPI_ERROR_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return sock.connect(tcp_addr);
|
||||
return tcpsocket_connect_to_srv(sock, MBED_CONF_APP_ECHO_SERVER_DISCARD_PORT);
|
||||
}
|
||||
|
||||
void fill_tx_buffer_ascii(char *buff, size_t len)
|
||||
|
|
|
@ -36,9 +36,10 @@ void TCPSOCKET_BIND_ADDRESS()
|
|||
TCPSocket *sock = new TCPSocket;
|
||||
if (!sock) {
|
||||
TEST_FAIL();
|
||||
return;
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
||||
SocketAddress sockAddr = SocketAddress(get_interface()->get_ip_address(), 80);
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||
SocketAddress sockAddr = SocketAddress(NetworkInterface::get_default_instance()->get_ip_address(), 80);
|
||||
nsapi_error_t bind_result = sock->bind(sockAddr);
|
||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||
|
|
|
@ -36,8 +36,9 @@ void TCPSOCKET_BIND_ADDRESS_INVALID()
|
|||
TCPSocket *sock = new TCPSocket;
|
||||
if (!sock) {
|
||||
TEST_FAIL();
|
||||
return;
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||
nsapi_error_t bind_result = sock->bind("190.2.3.4", 1024);
|
||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||
|
|
|
@ -36,8 +36,9 @@ void TCPSOCKET_BIND_ADDRESS_NULL()
|
|||
TCPSocket *sock = new TCPSocket;
|
||||
if (!sock) {
|
||||
TEST_FAIL();
|
||||
return;
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||
nsapi_error_t bind_result = sock->bind(NULL, 1024);
|
||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||
|
|
|
@ -36,9 +36,10 @@ void TCPSOCKET_BIND_ADDRESS_PORT()
|
|||
TCPSocket *sock = new TCPSocket;
|
||||
if (!sock) {
|
||||
TEST_FAIL();
|
||||
return;
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
||||
nsapi_error_t bind_result = sock->bind(get_interface()->get_ip_address(), 80);
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||
nsapi_error_t bind_result = sock->bind(NetworkInterface::get_default_instance()->get_ip_address(), 80);
|
||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||
} else {
|
||||
|
|
|
@ -36,8 +36,9 @@ void TCPSOCKET_BIND_PORT()
|
|||
TCPSocket *sock = new TCPSocket;
|
||||
if (!sock) {
|
||||
TEST_FAIL();
|
||||
return;
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||
nsapi_error_t bind_result = sock->bind(1024);
|
||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||
|
|
|
@ -36,8 +36,9 @@ void TCPSOCKET_BIND_PORT_FAIL()
|
|||
TCPSocket *sock = new TCPSocket;
|
||||
if (!sock) {
|
||||
TEST_FAIL();
|
||||
return;
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||
nsapi_error_t bind_result = sock->bind(1024);
|
||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||
|
@ -51,7 +52,7 @@ void TCPSOCKET_BIND_PORT_FAIL()
|
|||
if (!sock2) {
|
||||
TEST_FAIL();
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock2->open(get_interface()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock2->open(NetworkInterface::get_default_instance()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, sock2->bind(1024));
|
||||
|
||||
delete sock;
|
||||
|
|
|
@ -36,6 +36,7 @@ void TCPSOCKET_BIND_UNOPENED()
|
|||
TCPSocket *sock = new TCPSocket;
|
||||
if (!sock) {
|
||||
TEST_FAIL();
|
||||
return;
|
||||
}
|
||||
nsapi_error_t bind_result = sock->bind(1024);
|
||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||
|
|
|
@ -36,8 +36,9 @@ void TCPSOCKET_BIND_WRONG_TYPE()
|
|||
TCPSocket *sock = new TCPSocket;
|
||||
if (!sock) {
|
||||
TEST_FAIL();
|
||||
return;
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||
char addr_bytes[16] = {0xfe, 0x80, 0xff, 0x1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
SocketAddress sockAddr = SocketAddress(addr_bytes, NSAPI_IPv4, 80);
|
||||
nsapi_error_t bind_result = sock->bind(sockAddr);
|
||||
|
|
|
@ -27,7 +27,7 @@ using namespace utest::v1;
|
|||
void TCPSOCKET_CONNECT_INVALID()
|
||||
{
|
||||
TCPSocket sock;
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_interface()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
|
||||
|
||||
TEST_ASSERT(sock.connect(NULL, 9) < 0);
|
||||
TEST_ASSERT(sock.connect("", 9) < 0);
|
||||
|
|
|
@ -36,14 +36,25 @@ static const int pkt_sizes[PKTS] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, \
|
|||
};
|
||||
TCPSocket sock;
|
||||
Semaphore tx_sem(0, 1);
|
||||
events::EventQueue *event_queue;
|
||||
int bytes2recv;
|
||||
int bytes2recv_total;
|
||||
|
||||
Timer tc_exec_time;
|
||||
int time_allotted;
|
||||
bool receive_error;
|
||||
}
|
||||
|
||||
void tcpsocket_echotest_nonblock_receive();
|
||||
|
||||
static void _sigio_handler(osThreadId id)
|
||||
{
|
||||
osSignalSet(id, SIGNAL_SIGIO);
|
||||
if (event_queue != NULL) {
|
||||
event_queue->call(tcpsocket_echotest_nonblock_receive);
|
||||
} else {
|
||||
TEST_FAIL_MESSAGE("_sigio_handler running when event_queue is NULL");
|
||||
}
|
||||
}
|
||||
|
||||
void TCPSOCKET_ECHOTEST()
|
||||
|
@ -83,33 +94,31 @@ void TCPSOCKET_ECHOTEST()
|
|||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
|
||||
}
|
||||
|
||||
void tcpsocket_echotest_nonblock_receiver(void *receive_bytes)
|
||||
void tcpsocket_echotest_nonblock_receive()
|
||||
{
|
||||
int bytes2recv = *(int *)receive_bytes;
|
||||
int recvd;
|
||||
while (bytes2recv) {
|
||||
recvd = sock.recv(&(tcp_global::rx_buffer[*(int *)receive_bytes - bytes2recv]), bytes2recv);
|
||||
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
|
||||
if (tc_exec_time.read() >= time_allotted) {
|
||||
TEST_FAIL();
|
||||
break;
|
||||
}
|
||||
wait(1);
|
||||
continue;
|
||||
} else if (recvd < 0) {
|
||||
TEST_FAIL();
|
||||
break;
|
||||
int recvd = sock.recv(&(tcp_global::rx_buffer[bytes2recv_total - bytes2recv]), bytes2recv);
|
||||
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
|
||||
if (tc_exec_time.read() >= time_allotted) {
|
||||
receive_error = true;
|
||||
}
|
||||
return;
|
||||
} else if (recvd < 0) {
|
||||
receive_error = true;
|
||||
} else {
|
||||
bytes2recv -= recvd;
|
||||
}
|
||||
|
||||
TEST_ASSERT_EQUAL(0, memcmp(tcp_global::tx_buffer, tcp_global::rx_buffer, *(int *)receive_bytes));
|
||||
|
||||
static int round = 0;
|
||||
printf("[Recevr#%02d] bytes received: %d\n", round++, *(int *)receive_bytes);
|
||||
|
||||
tx_sem.release();
|
||||
if (bytes2recv == 0) {
|
||||
TEST_ASSERT_EQUAL(0, memcmp(tcp_global::tx_buffer, tcp_global::rx_buffer, bytes2recv_total));
|
||||
|
||||
static int round = 0;
|
||||
printf("[Recevr#%02d] bytes received: %d\n", round++, bytes2recv_total);
|
||||
tx_sem.release();
|
||||
} else if (receive_error || bytes2recv < 0) {
|
||||
TEST_FAIL();
|
||||
tx_sem.release();
|
||||
}
|
||||
// else - no error, not all bytes were received yet.
|
||||
}
|
||||
|
||||
void TCPSOCKET_ECHOTEST_NONBLOCK()
|
||||
|
@ -124,6 +133,9 @@ void TCPSOCKET_ECHOTEST_NONBLOCK()
|
|||
tc_exec_time.start();
|
||||
time_allotted = split2half_rmng_tcp_test_time(); // [s]
|
||||
|
||||
EventQueue queue(2 * EVENTS_EVENT_SIZE);
|
||||
event_queue = &queue;
|
||||
|
||||
tcpsocket_connect_to_echo_srv(sock);
|
||||
sock.set_blocking(false);
|
||||
sock.sigio(callback(_sigio_handler, ThisThread::get_id()));
|
||||
|
@ -131,17 +143,20 @@ void TCPSOCKET_ECHOTEST_NONBLOCK()
|
|||
int bytes2send;
|
||||
int sent;
|
||||
int s_idx = 0;
|
||||
Thread *thread;
|
||||
receive_error = false;
|
||||
unsigned char *stack_mem = (unsigned char *)malloc(tcp_global::TCP_OS_STACK_SIZE);
|
||||
TEST_ASSERT_NOT_NULL(stack_mem);
|
||||
Thread *receiver_thread = new Thread(osPriorityNormal,
|
||||
tcp_global::TCP_OS_STACK_SIZE,
|
||||
stack_mem,
|
||||
"receiver");
|
||||
|
||||
TEST_ASSERT_EQUAL(osOK, receiver_thread->start(callback(&queue, &EventQueue::dispatch_forever)));
|
||||
|
||||
for (int pkt_s = pkt_sizes[s_idx]; s_idx < PKTS; ++s_idx) {
|
||||
pkt_s = pkt_sizes[s_idx];
|
||||
thread = new Thread(osPriorityNormal,
|
||||
tcp_global::TCP_OS_STACK_SIZE,
|
||||
stack_mem,
|
||||
"receiver");
|
||||
TEST_ASSERT_EQUAL(osOK, thread->start(callback(tcpsocket_echotest_nonblock_receiver, &pkt_s)));
|
||||
bytes2recv = pkt_s;
|
||||
bytes2recv_total = pkt_s;
|
||||
|
||||
fill_tx_buffer_ascii(tcp_global::tx_buffer, pkt_s);
|
||||
|
||||
|
@ -151,16 +166,12 @@ void TCPSOCKET_ECHOTEST_NONBLOCK()
|
|||
if (sent == NSAPI_ERROR_WOULD_BLOCK) {
|
||||
if (tc_exec_time.read() >= time_allotted ||
|
||||
osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
|
||||
thread->terminate();
|
||||
delete thread;
|
||||
TEST_FAIL();
|
||||
goto END;
|
||||
}
|
||||
continue;
|
||||
} else if (sent <= 0) {
|
||||
printf("[Sender#%02d] network error %d\n", s_idx, sent);
|
||||
thread->terminate();
|
||||
delete thread;
|
||||
TEST_FAIL();
|
||||
goto END;
|
||||
}
|
||||
|
@ -176,12 +187,17 @@ void TCPSOCKET_ECHOTEST_NONBLOCK()
|
|||
}
|
||||
TEST_ASSERT_EQUAL(bytes2send, tcp_stats[j].sent_bytes);
|
||||
#endif
|
||||
tx_sem.wait(split2half_rmng_tcp_test_time());
|
||||
thread->join();
|
||||
delete thread;
|
||||
tx_sem.wait(split2half_rmng_tcp_test_time() * 1000); // *1000 to convert s->ms
|
||||
if (receive_error) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
END:
|
||||
sock.sigio(NULL);
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
|
||||
receiver_thread->terminate();
|
||||
delete receiver_thread;
|
||||
receiver_thread = NULL;
|
||||
tc_exec_time.stop();
|
||||
free(stack_mem);
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
|
||||
}
|
||||
|
|
|
@ -78,8 +78,7 @@ void TCPSOCKET_ECHOTEST_BURST()
|
|||
}
|
||||
|
||||
if (bt_left != 0) {
|
||||
drop_bad_packets(sock, 0);
|
||||
TEST_FAIL();
|
||||
TEST_FAIL_MESSAGE("bt_left != 0");
|
||||
goto END;
|
||||
}
|
||||
|
||||
|
@ -142,7 +141,6 @@ void TCPSOCKET_ECHOTEST_BURST_NONBLOCK()
|
|||
|
||||
if (bt_left != 0) {
|
||||
printf("network error %d, missing %d bytes from a burst\n", recvd, bt_left);
|
||||
drop_bad_packets(sock, -1);
|
||||
TEST_FAIL();
|
||||
goto END;
|
||||
}
|
||||
|
|
|
@ -38,10 +38,10 @@ static nsapi_error_t _tcpsocket_connect_to_daytime_srv(TCPSocket &sock)
|
|||
{
|
||||
SocketAddress tcp_addr;
|
||||
|
||||
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &tcp_addr);
|
||||
NetworkInterface::get_default_instance()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &tcp_addr);
|
||||
tcp_addr.set_port(13);
|
||||
|
||||
nsapi_error_t err = sock.open(get_interface());
|
||||
nsapi_error_t err = sock.open(NetworkInterface::get_default_instance());
|
||||
if (err != NSAPI_ERROR_OK) {
|
||||
return err;
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ void TCPSOCKET_OPEN_CLOSE_REPEAT()
|
|||
}
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->close());
|
||||
}
|
||||
delete sock;
|
||||
|
|
|
@ -38,7 +38,7 @@ void TCPSOCKET_OPEN_DESTRUCT()
|
|||
if (!sock) {
|
||||
TEST_FAIL();
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||
delete sock;
|
||||
}
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
|
|
|
@ -46,7 +46,7 @@ void TCPSOCKET_OPEN_LIMIT()
|
|||
if (!sock) {
|
||||
break;
|
||||
}
|
||||
ret = sock->open(get_interface());
|
||||
ret = sock->open(NetworkInterface::get_default_instance());
|
||||
if (ret == NSAPI_ERROR_NO_MEMORY || ret == NSAPI_ERROR_NO_SOCKET) {
|
||||
printf("[round#%02d] unable to open new socket, error: %d\n", i, ret);
|
||||
delete sock;
|
||||
|
|
|
@ -37,8 +37,8 @@ void TCPSOCKET_OPEN_TWICE()
|
|||
TEST_FAIL();
|
||||
}
|
||||
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, sock->open(get_interface()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, sock->open(NetworkInterface::get_default_instance()));
|
||||
|
||||
delete sock;
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
|
|
|
@ -33,10 +33,10 @@ static nsapi_error_t _tcpsocket_connect_to_chargen_srv(TCPSocket &sock)
|
|||
{
|
||||
SocketAddress tcp_addr;
|
||||
|
||||
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &tcp_addr);
|
||||
NetworkInterface::get_default_instance()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &tcp_addr);
|
||||
tcp_addr.set_port(19);
|
||||
|
||||
nsapi_error_t err = sock.open(get_interface());
|
||||
nsapi_error_t err = sock.open(NetworkInterface::get_default_instance());
|
||||
if (err != NSAPI_ERROR_OK) {
|
||||
return err;
|
||||
}
|
||||
|
|
|
@ -27,9 +27,18 @@ using namespace utest::v1;
|
|||
void TCPSOCKET_SETSOCKOPT_KEEPALIVE_VALID()
|
||||
{
|
||||
TCPSocket sock;
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_interface()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
|
||||
int32_t seconds = 7200;
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.setsockopt(NSAPI_SOCKET, NSAPI_KEEPALIVE, &seconds, sizeof(int)));
|
||||
|
||||
int ret = sock.setsockopt(NSAPI_SOCKET, NSAPI_KEEPALIVE, &seconds, sizeof(int));
|
||||
|
||||
if (ret == NSAPI_ERROR_UNSUPPORTED) {
|
||||
TEST_IGNORE_MESSAGE("NSAPI_KEEPALIVE option not supported");
|
||||
sock.close();
|
||||
return;
|
||||
}
|
||||
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, ret);
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.connect(MBED_CONF_APP_ECHO_SERVER_ADDR, 9));
|
||||
// LWIP stack does not support getsockopt so the part below is commented out
|
||||
// int32_t optval;
|
||||
|
|
|
@ -33,22 +33,13 @@
|
|||
|
||||
using namespace utest::v1;
|
||||
|
||||
namespace {
|
||||
NetworkInterface *net;
|
||||
}
|
||||
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
mbed_stats_socket_t udp_stats[MBED_CONF_NSAPI_SOCKET_STATS_MAX_COUNT];
|
||||
#endif
|
||||
|
||||
NetworkInterface *get_interface()
|
||||
{
|
||||
return net;
|
||||
}
|
||||
|
||||
static void _ifup()
|
||||
{
|
||||
net = NetworkInterface::get_default_instance();
|
||||
NetworkInterface *net = NetworkInterface::get_default_instance();
|
||||
nsapi_error_t err = net->connect();
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
|
||||
printf("MBED: UDPClient IP address is '%s'\n", net->get_ip_address());
|
||||
|
@ -56,7 +47,7 @@ static void _ifup()
|
|||
|
||||
static void _ifdown()
|
||||
{
|
||||
net->disconnect();
|
||||
NetworkInterface::get_default_instance()->disconnect();
|
||||
printf("MBED: ifdown\n");
|
||||
}
|
||||
|
||||
|
|
|
@ -37,8 +37,8 @@ void UDPSOCKET_BIND_ADDRESS()
|
|||
if (!sock) {
|
||||
TEST_FAIL();
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
||||
SocketAddress sockAddr = SocketAddress(get_interface()->get_ip_address(), 80);
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||
SocketAddress sockAddr = SocketAddress(NetworkInterface::get_default_instance()->get_ip_address(), 80);
|
||||
nsapi_error_t bind_result = sock->bind(sockAddr);
|
||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||
|
|
|
@ -37,7 +37,7 @@ void UDPSOCKET_BIND_ADDRESS_INVALID()
|
|||
if (!sock) {
|
||||
TEST_FAIL();
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||
nsapi_error_t bind_result = sock->bind("190.2.3.4", 1024);
|
||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||
|
|
|
@ -37,7 +37,7 @@ void UDPSOCKET_BIND_ADDRESS_NULL()
|
|||
if (!sock) {
|
||||
TEST_FAIL();
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||
nsapi_error_t bind_result = sock->bind(NULL, 1024);
|
||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||
|
|
|
@ -37,8 +37,8 @@ void UDPSOCKET_BIND_ADDRESS_PORT()
|
|||
if (!sock) {
|
||||
TEST_FAIL();
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
||||
nsapi_error_t bind_result = sock->bind(get_interface()->get_ip_address(), 80);
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||
nsapi_error_t bind_result = sock->bind(NetworkInterface::get_default_instance()->get_ip_address(), 80);
|
||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||
} else {
|
||||
|
|
|
@ -37,7 +37,7 @@ void UDPSOCKET_BIND_PORT()
|
|||
if (!sock) {
|
||||
TEST_FAIL();
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||
nsapi_error_t bind_result = sock->bind(1024);
|
||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||
|
|
|
@ -37,7 +37,7 @@ void UDPSOCKET_BIND_PORT_FAIL()
|
|||
if (!sock) {
|
||||
TEST_FAIL();
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||
nsapi_error_t bind_result = sock->bind(1024);
|
||||
if (bind_result == NSAPI_ERROR_UNSUPPORTED) {
|
||||
TEST_IGNORE_MESSAGE("bind() not supported");
|
||||
|
@ -51,7 +51,7 @@ void UDPSOCKET_BIND_PORT_FAIL()
|
|||
if (!sock2) {
|
||||
TEST_FAIL();
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock2->open(get_interface()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock2->open(NetworkInterface::get_default_instance()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, sock2->bind(1024));
|
||||
|
||||
delete sock;
|
||||
|
|
|
@ -37,7 +37,7 @@ void UDPSOCKET_BIND_WRONG_TYPE()
|
|||
if (!sock) {
|
||||
TEST_FAIL();
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||
char addr_bytes[16] = {0xfe, 0x80, 0xff, 0x1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
SocketAddress sockAddr = SocketAddress(addr_bytes, NSAPI_IPv4, 80);
|
||||
nsapi_error_t bind_result = sock->bind(sockAddr);
|
||||
|
|
|
@ -55,11 +55,11 @@ static void _sigio_handler(osThreadId id)
|
|||
void UDPSOCKET_ECHOTEST()
|
||||
{
|
||||
SocketAddress udp_addr;
|
||||
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
||||
NetworkInterface::get_default_instance()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
||||
udp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
|
||||
|
||||
UDPSocket sock;
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_interface()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
|
||||
|
||||
int recvd;
|
||||
int sent;
|
||||
|
@ -109,6 +109,10 @@ void udpsocket_echotest_nonblock_receiver(void *receive_bytes)
|
|||
wait_ms(WAIT2RECV_TIMEOUT);
|
||||
--retry_cnt;
|
||||
continue;
|
||||
} else if (recvd < 0) {
|
||||
printf("sock.recvfrom returned %d\n", recvd);
|
||||
TEST_FAIL();
|
||||
break;
|
||||
} else if (recvd == expt2recv) {
|
||||
break;
|
||||
}
|
||||
|
@ -130,10 +134,10 @@ void UDPSOCKET_ECHOTEST_NONBLOCK()
|
|||
#endif
|
||||
|
||||
SocketAddress udp_addr;
|
||||
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
||||
NetworkInterface::get_default_instance()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
||||
udp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
|
||||
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_interface()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
|
||||
sock.set_blocking(false);
|
||||
sock.sigio(callback(_sigio_handler, ThisThread::get_id()));
|
||||
|
||||
|
|
|
@ -71,12 +71,12 @@ static void _sigio_handler(osThreadId id)
|
|||
void UDPSOCKET_ECHOTEST_BURST()
|
||||
{
|
||||
SocketAddress udp_addr;
|
||||
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
||||
NetworkInterface::get_default_instance()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
||||
udp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
|
||||
|
||||
UDPSocket sock;
|
||||
const int TIMEOUT = 5000; // [ms]
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_interface()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
|
||||
sock.set_timeout(TIMEOUT);
|
||||
sock.sigio(callback(_sigio_handler, ThisThread::get_id()));
|
||||
|
||||
|
@ -150,11 +150,11 @@ void UDPSOCKET_ECHOTEST_BURST()
|
|||
void UDPSOCKET_ECHOTEST_BURST_NONBLOCK()
|
||||
{
|
||||
SocketAddress udp_addr;
|
||||
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
||||
NetworkInterface::get_default_instance()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
||||
udp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
|
||||
|
||||
UDPSocket sock;
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_interface()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
|
||||
sock.set_blocking(false);
|
||||
sock.sigio(callback(_sigio_handler, ThisThread::get_id()));
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ void UDPSOCKET_OPEN_CLOSE_REPEAT()
|
|||
}
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->close());
|
||||
}
|
||||
delete sock;
|
||||
|
|
|
@ -38,7 +38,7 @@ void UDPSOCKET_OPEN_DESTRUCT()
|
|||
if (!sock) {
|
||||
TEST_FAIL();
|
||||
}
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||
delete sock;
|
||||
}
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
|
|
|
@ -47,7 +47,7 @@ void UDPSOCKET_OPEN_LIMIT()
|
|||
if (!sock) {
|
||||
break;
|
||||
}
|
||||
ret = sock->open(get_interface());
|
||||
ret = sock->open(NetworkInterface::get_default_instance());
|
||||
if (ret == NSAPI_ERROR_NO_MEMORY || ret == NSAPI_ERROR_NO_SOCKET) {
|
||||
printf("[round#%02d] unable to open new socket, error: %d\n", i, ret);
|
||||
delete sock;
|
||||
|
|
|
@ -37,8 +37,8 @@ void UDPSOCKET_OPEN_TWICE()
|
|||
TEST_FAIL();
|
||||
}
|
||||
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(get_interface()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, sock->open(get_interface()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, sock->open(NetworkInterface::get_default_instance()));
|
||||
|
||||
delete sock;
|
||||
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
|
||||
|
|
|
@ -37,14 +37,14 @@ static void _sigio_handler(osThreadId id)
|
|||
void UDPSOCKET_RECV_TIMEOUT()
|
||||
{
|
||||
SocketAddress udp_addr;
|
||||
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
||||
NetworkInterface::get_default_instance()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
||||
udp_addr.set_port(MBED_CONF_APP_ECHO_SERVER_PORT);
|
||||
|
||||
static const int DATA_LEN = 100;
|
||||
char buff[DATA_LEN] = {0};
|
||||
|
||||
UDPSocket sock;
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_interface()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
|
||||
sock.set_timeout(100);
|
||||
sock.sigio(callback(_sigio_handler, ThisThread::get_id()));
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ using namespace utest::v1;
|
|||
void UDPSOCKET_SENDTO_INVALID()
|
||||
{
|
||||
UDPSocket sock;
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_interface()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
|
||||
|
||||
TEST_ASSERT(sock.sendto(NULL, 9, NULL, 0) < 0);
|
||||
TEST_ASSERT(sock.sendto("", 9, NULL, 0) < 0);
|
||||
|
|
|
@ -27,10 +27,10 @@ using namespace utest::v1;
|
|||
void UDPSOCKET_SENDTO_REPEAT()
|
||||
{
|
||||
UDPSocket sock;
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_interface()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
|
||||
|
||||
SocketAddress udp_addr;
|
||||
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
||||
NetworkInterface::get_default_instance()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
||||
udp_addr.set_port(9);
|
||||
|
||||
int sent;
|
||||
|
|
|
@ -30,10 +30,10 @@ void UDPSOCKET_SENDTO_TIMEOUT()
|
|||
fill_tx_buffer_ascii(tx_buffer, sizeof(tx_buffer));
|
||||
|
||||
UDPSocket sock;
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(get_interface()));
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.open(NetworkInterface::get_default_instance()));
|
||||
|
||||
SocketAddress udp_addr;
|
||||
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
||||
NetworkInterface::get_default_instance()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &udp_addr);
|
||||
udp_addr.set_port(9);
|
||||
|
||||
Timer timer;
|
||||
|
@ -43,12 +43,14 @@ void UDPSOCKET_SENDTO_TIMEOUT()
|
|||
TEST_ASSERT_EQUAL(sizeof(tx_buffer), sent);
|
||||
TEST_ASSERT(timer.read_ms() <= 100);
|
||||
|
||||
sock.set_timeout(1000);
|
||||
|
||||
timer.reset();
|
||||
timer.start();
|
||||
sent = sock.sendto(udp_addr, tx_buffer, sizeof(tx_buffer));
|
||||
timer.stop();
|
||||
TEST_ASSERT_EQUAL(sizeof(tx_buffer), sent);
|
||||
TEST_ASSERT(timer.read_ms() <= 100);
|
||||
TEST_ASSERT(timer.read_ms() <= 1000);
|
||||
printf("MBED: Time taken: %fs\n", timer.read());
|
||||
|
||||
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
|
||||
|
|
|
@ -42,7 +42,7 @@ class Testcase(Bench):
|
|||
'*': {
|
||||
"count":3,
|
||||
"type": "hardware",
|
||||
"allowed_platforms": ["K64F", "K66F", "NUCLEO_F429ZI", "KW24D", "UBLOX_EVK_ODIN_W2"],
|
||||
"allowed_platforms": ["K64F", "K66F", "NUCLEO_F429ZI", "KW24D", "UBLOX_EVK_ODIN_W2", "KW41Z"],
|
||||
"application": {
|
||||
"name": "TEST_APPS-device-nanostack_mac_tester"
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ class Testcase(Bench):
|
|||
'*': {
|
||||
"count":1,
|
||||
"type": "hardware",
|
||||
"allowed_platforms": ["K64F", "K66F", "NUCLEO_F429ZI", "KW24D", "UBLOX_EVK_ODIN_W2"],
|
||||
"allowed_platforms": ["K64F", "K66F", "NUCLEO_F429ZI", "KW24D", "UBLOX_EVK_ODIN_W2", "KW41Z"],
|
||||
"application": {
|
||||
"name": "TEST_APPS-device-nanostack_mac_tester"
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ class Testcase(Bench):
|
|||
'*': {
|
||||
"count":3,
|
||||
"type": "hardware",
|
||||
"allowed_platforms": ["K64F", "K66F", "NUCLEO_F429ZI", "KW24D", "UBLOX_EVK_ODIN_W2"],
|
||||
"allowed_platforms": ["K64F", "K66F", "NUCLEO_F429ZI", "KW24D", "UBLOX_EVK_ODIN_W2", "KW41Z"],
|
||||
"application": {
|
||||
"name": "TEST_APPS-device-nanostack_mac_tester"
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ class Testcase(Bench):
|
|||
'*': {
|
||||
"count":2,
|
||||
"type": "hardware",
|
||||
"allowed_platforms": ["K64F", "K66F", "NUCLEO_F429ZI", "KW24D", "UBLOX_EVK_ODIN_W2"],
|
||||
"allowed_platforms": ["K64F", "K66F", "NUCLEO_F429ZI", "KW24D", "UBLOX_EVK_ODIN_W2", "KW41Z"],
|
||||
"application": {
|
||||
"name": "TEST_APPS-device-nanostack_mac_tester"
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ class Testcase(Bench):
|
|||
'*': {
|
||||
"count":3,
|
||||
"type": "hardware",
|
||||
"allowed_platforms": ["K64F", "K66F", "NUCLEO_F429ZI", "KW24D", "UBLOX_EVK_ODIN_W2"],
|
||||
"allowed_platforms": ["K64F", "K66F", "NUCLEO_F429ZI", "KW24D", "UBLOX_EVK_ODIN_W2", "KW41Z"],
|
||||
"application": {
|
||||
"name": "TEST_APPS-device-nanostack_mac_tester"
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ class Testcase(Bench):
|
|||
'*': {
|
||||
"count":2,
|
||||
"type": "hardware",
|
||||
"allowed_platforms": ["K64F", "K66F", "NUCLEO_F429ZI", "KW24D", "UBLOX_EVK_ODIN_W2"],
|
||||
"allowed_platforms": ["K64F", "K66F", "NUCLEO_F429ZI", "KW24D", "UBLOX_EVK_ODIN_W2", "KW41Z"],
|
||||
"application": {
|
||||
"name": "TEST_APPS-device-nanostack_mac_tester"
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ In a terminal window:
|
|||
sudo easy_install pip
|
||||
```
|
||||
|
||||
1. Install Gcovr and [Mbed CLI](https://os.mbed.com/docs/latest/tools/developing-arm-mbed-cli.html) with `pip install "gcovr>=4.1" mbed-cli`.
|
||||
1. Install Gcovr and [Mbed CLI](https://os.mbed.com/docs/mbed-os/latest/tools/developing-mbed-cli.html) with `pip install "gcovr>=4.1" mbed-cli`.
|
||||
|
||||
#### Installing dependencies on macOS
|
||||
|
||||
|
@ -48,7 +48,7 @@ In a terminal window:
|
|||
sudo easy_install pip
|
||||
```
|
||||
|
||||
1. Install Gcovr and [Mbed CLI](https://os.mbed.com/docs/latest/tools/developing-arm-mbed-cli.html) with `pip install "gcovr>=4.1" mbed-cli`.
|
||||
1. Install Gcovr and [Mbed CLI](https://os.mbed.com/docs/mbed-os/latest/tools/developing-mbed-cli.html) with `pip install "gcovr>=4.1" mbed-cli`.
|
||||
1. (Optional) Install GCC with `brew install gcc`.
|
||||
|
||||
#### Installing dependencies on Windows
|
||||
|
@ -59,7 +59,7 @@ In a terminal window:
|
|||
1. Download CMake binaries from https://cmake.org/download/, and run the installer.
|
||||
1. Download Python 2.7 or Python 3 from https://www.python.org/getit/, and run the installer.
|
||||
1. Add MinGW, CMake and Python into system PATH.
|
||||
1. Install Gcovr and [Mbed CLI](https://os.mbed.com/docs/latest/tools/developing-arm-mbed-cli.html) with `pip install "gcovr>=4.1" mbed-cli`.
|
||||
1. Install Gcovr and [Mbed CLI](https://os.mbed.com/docs/mbed-os/latest/tools/developing-mbed-cli.html) with `pip install "gcovr>=4.1" mbed-cli`.
|
||||
|
||||
### Test code structure
|
||||
|
||||
|
@ -79,7 +79,7 @@ The build system automatically generates names of test suites. The name is const
|
|||
|
||||
### Unit testing with Mbed CLI
|
||||
|
||||
Mbed CLI supports unit tests through the `mbed test --unittests` command. For information on using Mbed CLI, please see the [CLI documentation](https://os.mbed.com/docs/latest/tools/developing-arm-mbed-cli.html).
|
||||
Mbed CLI supports unit tests through the `mbed test --unittests` command. For information on using Mbed CLI, please see the [CLI documentation](https://os.mbed.com/docs/mbed-os/latest/tools/developing-mbed-cli.html).
|
||||
|
||||
### Writing unit tests
|
||||
|
||||
|
|
|
@ -29,8 +29,6 @@ using namespace mbed;
|
|||
|
||||
/* Default QSPIF Parameters */
|
||||
/****************************/
|
||||
#define QSPIF_DEFAULT_READ_SIZE 1
|
||||
#define QSPIF_DEFAULT_PROG_SIZE 1
|
||||
#define QSPIF_DEFAULT_PAGE_SIZE 256
|
||||
#define QSPIF_DEFAULT_SE_SIZE 4096
|
||||
#define QSPI_MAX_STATUS_REGISTER_SIZE 3
|
||||
|
@ -95,6 +93,7 @@ enum qspif_default_instructions {
|
|||
QSPIF_RSTEN = 0x66, // Reset Enable
|
||||
QSPIF_RST = 0x99, // Reset
|
||||
QSPIF_RDID = 0x9f, // Read Manufacturer and JDEC Device ID
|
||||
QSPIF_ULBPR = 0x98, // Clears all write-protection bits in the Block-Protection register
|
||||
};
|
||||
|
||||
// Local Function
|
||||
|
@ -204,9 +203,9 @@ int QSPIFBlockDevice::init()
|
|||
switch (vendor_device_ids[0]) {
|
||||
case 0xbf:
|
||||
// SST devices come preset with block protection
|
||||
// enabled for some regions, issue write disable instruction to clear
|
||||
// enabled for some regions, issue global protection unlock to clear
|
||||
_set_write_enable();
|
||||
_qspi_send_general_command(QSPIF_WRDI, QSPI_NO_ADDRESS_COMMAND, NULL, 0, NULL, 0);
|
||||
_qspi_send_general_command(QSPIF_ULBPR, QSPI_NO_ADDRESS_COMMAND, NULL, 0, NULL, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -461,14 +460,14 @@ exit_point:
|
|||
|
||||
bd_size_t QSPIFBlockDevice::get_read_size() const
|
||||
{
|
||||
// Assuming all devices support 1byte read granularity
|
||||
return QSPIF_DEFAULT_READ_SIZE;
|
||||
// Return minimum read size in bytes for the device
|
||||
return MBED_CONF_QSPIF_QSPI_MIN_READ_SIZE;
|
||||
}
|
||||
|
||||
bd_size_t QSPIFBlockDevice::get_program_size() const
|
||||
{
|
||||
// Assuming all devices support 1byte program granularity
|
||||
return QSPIF_DEFAULT_PROG_SIZE;
|
||||
// Return minimum program/write size in bytes for the device
|
||||
return MBED_CONF_QSPIF_QSPI_MIN_PROG_SIZE;
|
||||
}
|
||||
|
||||
bd_size_t QSPIFBlockDevice::get_erase_size() const
|
||||
|
|
|
@ -8,7 +8,9 @@
|
|||
"QSPI_SCK": "QSPI_FLASH1_SCK",
|
||||
"QSPI_CSN": "QSPI_FLASH1_CSN",
|
||||
"QSPI_POLARITY_MODE": 0,
|
||||
"QSPI_FREQ": "40000000"
|
||||
"QSPI_FREQ": "40000000",
|
||||
"QSPI_MIN_READ_SIZE": "1",
|
||||
"QSPI_MIN_PROG_SIZE": "1"
|
||||
},
|
||||
"target_overrides": {
|
||||
"DISCO_F413ZH": {
|
||||
|
@ -32,8 +34,10 @@
|
|||
"DISCO_F769NI": {
|
||||
"QSPI_FREQ": "8000000"
|
||||
},
|
||||
"NRF52840_DK": {
|
||||
"QSPI_FREQ": "32000000"
|
||||
"MCU_NRF52840": {
|
||||
"QSPI_FREQ": "32000000",
|
||||
"QSPI_MIN_READ_SIZE": "4",
|
||||
"QSPI_MIN_PROG_SIZE": "4"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ enum ops {
|
|||
SPIF_WRDI = 0x04, // Write Disable
|
||||
SPIF_RDSR = 0x05, // Read Status Register
|
||||
SPIF_RDID = 0x9f, // Read Manufacturer and JDEC Device ID
|
||||
SPIF_ULBPR = 0x98, // Clears all write-protection bits in the Block-Protection register
|
||||
};
|
||||
|
||||
// Status register from RDSR
|
||||
|
@ -66,9 +67,9 @@ int SPIFReducedBlockDevice::init()
|
|||
switch (id[0]) {
|
||||
case 0xbf:
|
||||
// SST devices come preset with block protection
|
||||
// enabled for some regions, issue gbpu instruction to clear
|
||||
// enabled for some regions, issue global protection unlock to clear
|
||||
_wren();
|
||||
_cmdwrite(0x98, 0, 0, 0x0, NULL);
|
||||
_cmdwrite(SPIF_ULBPR, 0, 0, 0x0, NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -80,6 +80,7 @@ static const char *sd_testfile_path = "/sd/test.txt";
|
|||
SDBlockDevice sd(MBED_CONF_SD_SPI_MOSI, MBED_CONF_SD_SPI_MISO, MBED_CONF_SD_SPI_CLK, MBED_CONF_SD_SPI_CS);
|
||||
FATFileSystem fs("sd", &sd);
|
||||
|
||||
#define FSFAT_FOPEN_TEST_00 fsfat_fopen_test_00
|
||||
#define FSFAT_FOPEN_TEST_01 fsfat_fopen_test_01
|
||||
#define FSFAT_FOPEN_TEST_02 fsfat_fopen_test_02
|
||||
#define FSFAT_FOPEN_TEST_03 fsfat_fopen_test_03
|
||||
|
@ -276,6 +277,26 @@ static int32_t fsfat_filepath_make_dirs(char *filepath, bool do_asserts)
|
|||
return ret;
|
||||
}
|
||||
|
||||
/** @brief
|
||||
* First and last test must format the SD card to FAT FS format:
|
||||
* @return on success returns CaseNext to continue to next test case, otherwise will assert on errors.
|
||||
*/
|
||||
control_t fsfat_fopen_test_00(const size_t call_count)
|
||||
{
|
||||
FSFAT_FENTRYLOG("%s:entered\n", __func__);
|
||||
(void) call_count;
|
||||
int32_t ret = -1;
|
||||
|
||||
fs.unmount();
|
||||
ret = fs.format(&sd);
|
||||
FSFAT_TEST_UTEST_MESSAGE(fsfat_fopen_utest_msg_g, FSFAT_UTEST_MSG_BUF_SIZE,
|
||||
"%s:Error: failed to format sdcard (ret=%d)\n", __func__, (int) ret);
|
||||
TEST_ASSERT_MESSAGE(ret == 0, fsfat_fopen_utest_msg_g);
|
||||
fs.mount(&sd);
|
||||
|
||||
return CaseNext;
|
||||
}
|
||||
|
||||
|
||||
/* FIX ME: errno not set correctly when error occurs. This indicates a problem with the implementation. */
|
||||
|
||||
|
@ -1535,7 +1556,7 @@ control_t fsfat_fopen_test_16(const size_t call_count)
|
|||
|
||||
#else
|
||||
|
||||
|
||||
#define FSFAT_FOPEN_TEST_00 fsfat_fopen_test_dummy
|
||||
#define FSFAT_FOPEN_TEST_01 fsfat_fopen_test_dummy
|
||||
#define FSFAT_FOPEN_TEST_02 fsfat_fopen_test_dummy
|
||||
#define FSFAT_FOPEN_TEST_03 fsfat_fopen_test_dummy
|
||||
|
@ -1590,6 +1611,7 @@ utest::v1::status_t greentea_setup(const size_t number_of_cases)
|
|||
Case cases[] = {
|
||||
/* 1 2 3 4 5 6 7 */
|
||||
/* 1234567890123456789012345678901234567890123456789012345678901234567890 */
|
||||
Case("FSFAT_FOPEN_TEST_00: format sd card to FAT FS.", FSFAT_FOPEN_TEST_00),
|
||||
Case("FSFAT_FOPEN_TEST_01: fopen()/fwrite()/fclose() directories/file in multi-dir filepath.", FSFAT_FOPEN_TEST_01),
|
||||
Case("FSFAT_FOPEN_TEST_02: fopen(r) pre-existing file try to write it.", FSFAT_FOPEN_TEST_02),
|
||||
Case("FSFAT_FOPEN_TEST_03: fopen(w+) pre-existing file try to write it.", FSFAT_FOPEN_TEST_03),
|
||||
|
|
|
@ -88,6 +88,7 @@ enum spif_default_instructions {
|
|||
SPIF_RSTEN = 0x66, // Reset Enable
|
||||
SPIF_RST = 0x99, // Reset
|
||||
SPIF_RDID = 0x9f, // Read Manufacturer and JDEC Device ID
|
||||
SPIF_ULBPR = 0x98, // Clears all write-protection bits in the Block-Protection register
|
||||
};
|
||||
|
||||
// Mutex is used for some SPI Driver commands that must be done sequentially with no other commands in between
|
||||
|
@ -167,9 +168,9 @@ int SPIFBlockDevice::init()
|
|||
switch (vendor_device_ids[0]) {
|
||||
case 0xbf:
|
||||
// SST devices come preset with block protection
|
||||
// enabled for some regions, issue write disable instruction to clear
|
||||
// enabled for some regions, issue global protection unlock to clear
|
||||
_set_write_enable();
|
||||
_spi_send_general_command(SPIF_WRDI, SPI_NO_ADDRESS_COMMAND, NULL, 0, NULL, 0);
|
||||
_spi_send_general_command(SPIF_ULBPR, SPI_NO_ADDRESS_COMMAND, NULL, 0, NULL, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -715,6 +715,10 @@ int32_t ESP8266::_recv_tcp_passive(int id, void *data, uint32_t amount, uint32_t
|
|||
|
||||
// update internal variable tcp_data_avbl to reflect the remaining data
|
||||
if (_sock_i[id].tcp_data_rcvd > 0) {
|
||||
if (_sock_i[id].tcp_data_rcvd > (int32_t)amount) {
|
||||
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_DRIVER, MBED_ERROR_CODE_EBADMSG), \
|
||||
"ESP8266::_recv_tcp_passive() too much data from modem\n");
|
||||
}
|
||||
if (_sock_i[id].tcp_data_avbl > _sock_i[id].tcp_data_rcvd) {
|
||||
_sock_i[id].tcp_data_avbl -= _sock_i[id].tcp_data_rcvd;
|
||||
} else {
|
||||
|
|
|
@ -55,11 +55,14 @@ ESP8266Interface::ESP8266Interface()
|
|||
: _esp(MBED_CONF_ESP8266_TX, MBED_CONF_ESP8266_RX, MBED_CONF_ESP8266_DEBUG, MBED_CONF_ESP8266_RTS, MBED_CONF_ESP8266_CTS),
|
||||
_rst_pin(MBED_CONF_ESP8266_RST), // Notice that Pin7 CH_EN cannot be left floating if used as reset
|
||||
_ap_sec(NSAPI_SECURITY_UNKNOWN),
|
||||
_if_blocking(true),
|
||||
_if_connected(_cmutex),
|
||||
_initialized(false),
|
||||
_conn_stat(NSAPI_STATUS_DISCONNECTED),
|
||||
_conn_stat_cb(NULL),
|
||||
_global_event_queue(NULL),
|
||||
_oob_event_id(0)
|
||||
_oob_event_id(0),
|
||||
_connect_event_id(0)
|
||||
{
|
||||
memset(_cbs, 0, sizeof(_cbs));
|
||||
memset(ap_ssid, 0, sizeof(ap_ssid));
|
||||
|
@ -83,11 +86,14 @@ ESP8266Interface::ESP8266Interface(PinName tx, PinName rx, bool debug, PinName r
|
|||
: _esp(tx, rx, debug, rts, cts),
|
||||
_rst_pin(rst),
|
||||
_ap_sec(NSAPI_SECURITY_UNKNOWN),
|
||||
_if_blocking(true),
|
||||
_if_connected(_cmutex),
|
||||
_initialized(false),
|
||||
_conn_stat(NSAPI_STATUS_DISCONNECTED),
|
||||
_conn_stat_cb(NULL),
|
||||
_global_event_queue(NULL),
|
||||
_oob_event_id(0)
|
||||
_oob_event_id(0),
|
||||
_connect_event_id(0)
|
||||
{
|
||||
memset(_cbs, 0, sizeof(_cbs));
|
||||
memset(ap_ssid, 0, sizeof(ap_ssid));
|
||||
|
@ -111,6 +117,12 @@ ESP8266Interface::~ESP8266Interface()
|
|||
_global_event_queue->cancel(_oob_event_id);
|
||||
}
|
||||
|
||||
_cmutex.lock();
|
||||
if (_connect_event_id) {
|
||||
_global_event_queue->cancel(_connect_event_id);
|
||||
}
|
||||
_cmutex.unlock();
|
||||
|
||||
// Power down the modem
|
||||
_rst_pin.rst_assert();
|
||||
}
|
||||
|
@ -167,9 +179,36 @@ void ESP8266Interface::_oob2global_event_queue()
|
|||
}
|
||||
}
|
||||
|
||||
void ESP8266Interface::_connect_async()
|
||||
{
|
||||
_cmutex.lock();
|
||||
if (!_connect_event_id) {
|
||||
tr_debug("_connect_async(): cancelled");
|
||||
_cmutex.unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
if (_esp.connect(ap_ssid, ap_pass) != NSAPI_ERROR_OK) {
|
||||
// Postpone to give other stuff time to run
|
||||
_connect_event_id = _global_event_queue->call_in(ESP8266_CONNECT_TIMEOUT, callback(this, &ESP8266Interface::_connect_async));
|
||||
|
||||
if (!_connect_event_id) {
|
||||
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_DRIVER, MBED_ERROR_CODE_ENOMEM), \
|
||||
"_connect_async(): unable to add event to queue");
|
||||
}
|
||||
} else {
|
||||
_connect_event_id = 0;
|
||||
_if_connected.notify_all();
|
||||
}
|
||||
_cmutex.unlock();
|
||||
}
|
||||
|
||||
int ESP8266Interface::connect()
|
||||
{
|
||||
nsapi_error_t status;
|
||||
nsapi_error_t status = _conn_status_to_error();
|
||||
if (status != NSAPI_ERROR_NO_CONNECTION) {
|
||||
return status;
|
||||
}
|
||||
|
||||
if (strlen(ap_ssid) == 0) {
|
||||
return NSAPI_ERROR_NO_SSID;
|
||||
|
@ -194,11 +233,32 @@ int ESP8266Interface::connect()
|
|||
return NSAPI_ERROR_DHCP_FAILURE;
|
||||
}
|
||||
|
||||
return _esp.connect(ap_ssid, ap_pass);
|
||||
_cmutex.lock();
|
||||
|
||||
MBED_ASSERT(!_connect_event_id);
|
||||
_connect_event_id = _global_event_queue->call(callback(this, &ESP8266Interface::_connect_async));
|
||||
|
||||
if (!_connect_event_id) {
|
||||
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_DRIVER, MBED_ERROR_CODE_ENOMEM), \
|
||||
"connect(): unable to add event to queue");
|
||||
}
|
||||
|
||||
while (_if_blocking && (_conn_status_to_error() != NSAPI_ERROR_IS_CONNECTED)) {
|
||||
_if_connected.wait();
|
||||
}
|
||||
|
||||
_cmutex.unlock();
|
||||
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
int ESP8266Interface::set_credentials(const char *ssid, const char *pass, nsapi_security_t security)
|
||||
{
|
||||
nsapi_error_t status = _conn_status_to_error();
|
||||
if (status != NSAPI_ERROR_NO_CONNECTION) {
|
||||
return status;
|
||||
}
|
||||
|
||||
_ap_sec = security;
|
||||
|
||||
if (!ssid) {
|
||||
|
@ -244,10 +304,16 @@ int ESP8266Interface::set_channel(uint8_t channel)
|
|||
|
||||
int ESP8266Interface::disconnect()
|
||||
{
|
||||
_cmutex.lock();
|
||||
if (_connect_event_id) {
|
||||
_global_event_queue->cancel(_connect_event_id);
|
||||
_connect_event_id = 0; // cancel asynchronous connection attempt if one is ongoing
|
||||
}
|
||||
_cmutex.unlock();
|
||||
_initialized = false;
|
||||
|
||||
if (_conn_stat == NSAPI_STATUS_DISCONNECTED)
|
||||
{
|
||||
nsapi_error_t status = _conn_status_to_error();
|
||||
if (status == NSAPI_ERROR_NO_CONNECTION || !get_ip_address()) {
|
||||
return NSAPI_ERROR_NO_CONNECTION;
|
||||
}
|
||||
|
||||
|
@ -508,9 +574,11 @@ int ESP8266Interface::socket_send(void *handle, const void *data, unsigned size)
|
|||
} while ((sendStartTime - rtos::Kernel::get_ms_count() < 50)
|
||||
&& (status != NSAPI_ERROR_OK));
|
||||
|
||||
if (status == NSAPI_ERROR_WOULD_BLOCK) {
|
||||
debug("Enqueuing the event call");
|
||||
if (status == NSAPI_ERROR_WOULD_BLOCK && socket->proto == NSAPI_TCP) {
|
||||
tr_debug("ESP8266Interface::socket_send(): enqueuing the event call");
|
||||
_global_event_queue->call_in(100, callback(this, &ESP8266Interface::event));
|
||||
} else if (status == NSAPI_ERROR_WOULD_BLOCK && socket->proto == NSAPI_UDP) {
|
||||
status = NSAPI_ERROR_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
return status != NSAPI_ERROR_OK ? status : size;
|
||||
|
@ -714,4 +782,35 @@ void ESP8266Interface::proc_oob_evnt()
|
|||
_esp.bg_process_oob(ESP8266_RECV_TIMEOUT, true);
|
||||
}
|
||||
|
||||
nsapi_error_t ESP8266Interface::_conn_status_to_error()
|
||||
{
|
||||
nsapi_error_t ret;
|
||||
|
||||
_esp.bg_process_oob(ESP8266_RECV_TIMEOUT, true);
|
||||
|
||||
switch (_conn_stat) {
|
||||
case NSAPI_STATUS_DISCONNECTED:
|
||||
ret = NSAPI_ERROR_NO_CONNECTION;
|
||||
break;
|
||||
case NSAPI_STATUS_CONNECTING:
|
||||
ret = NSAPI_ERROR_ALREADY;
|
||||
break;
|
||||
case NSAPI_STATUS_GLOBAL_UP:
|
||||
ret = NSAPI_ERROR_IS_CONNECTED;
|
||||
break;
|
||||
default:
|
||||
ret = NSAPI_ERROR_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
nsapi_error_t ESP8266Interface::set_blocking(bool blocking)
|
||||
{
|
||||
_if_blocking = blocking;
|
||||
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
#include "features/netsocket/WiFiAccessPoint.h"
|
||||
#include "features/netsocket/WiFiInterface.h"
|
||||
#include "platform/Callback.h"
|
||||
#include "rtos/ConditionVariable.h"
|
||||
#include "rtos/Mutex.h"
|
||||
|
||||
#define ESP8266_SOCKET_COUNT 5
|
||||
|
||||
|
@ -316,6 +318,13 @@ protected:
|
|||
return this;
|
||||
}
|
||||
|
||||
/** Set blocking status of connect() which by default should be blocking.
|
||||
*
|
||||
* @param blocking Use true to make connect() blocking.
|
||||
* @return NSAPI_ERROR_OK on success, negative error code on failure.
|
||||
*/
|
||||
virtual nsapi_error_t set_blocking(bool blocking);
|
||||
|
||||
private:
|
||||
// AT layer
|
||||
ESP8266 _esp;
|
||||
|
@ -341,6 +350,12 @@ private:
|
|||
char ap_pass[ESP8266_PASSPHRASE_MAX_LENGTH + 1]; /* The longest possible passphrase; +1 for the \0 */
|
||||
nsapi_security_t _ap_sec;
|
||||
|
||||
bool _if_blocking; // NetworkInterface, blocking or not
|
||||
rtos::ConditionVariable _if_connected;
|
||||
|
||||
// connect status reporting
|
||||
nsapi_error_t _conn_status_to_error();
|
||||
|
||||
// Drivers's socket info
|
||||
struct _sock_info {
|
||||
bool open;
|
||||
|
@ -369,8 +384,12 @@ private:
|
|||
// Use global EventQueue
|
||||
events::EventQueue *_global_event_queue;
|
||||
int _oob_event_id;
|
||||
int _connect_event_id;
|
||||
void proc_oob_evnt();
|
||||
void _oob2global_event_queue();
|
||||
void _connect_async();
|
||||
rtos::Mutex _cmutex; // Protect asynchronous connection logic
|
||||
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -63,7 +63,7 @@ The following is a list of all storage parameters available and their descriptio
|
|||
* `FILESYSTEM`.
|
||||
* `FILESYSTEM_NO_RBP`.
|
||||
* `default`
|
||||
If default is set, the system will choose the type of storage base on the block device component set in target.json. For QSPIF, SPIF and DATAFLASH block devices TDB_EXTERNAL will be used. If SD is set a FILESYSTEM storage is set and if only FLASHIAP exists as the only block device component, a TDB_INTERNAL will be used.
|
||||
If the `default` configuration is set, the system will choose the type of storage based on the block device component set in `target.json`. If QSPIF, SPIF or DATAFLASH is the block device component in `target.json`, the system chooses `TDB_EXTERNAL` as its storage option. If SD is the block device in `target.json`, the system chooses FILESYSTEM. If FLASHIAP is the only block device component, the system chooses `TDB_INTERNAL`.
|
||||
* `default_kv` - This is a string representing the path for the default KVStore instantiation. Applications can pass an empty path (only the key name) or pass the generated name for this parameter (`MBED_CONF_STORAGE_DEFAULT_KV`) as the path to use this configuration.
|
||||
* `internal_size` - The size in bytes for the internal FlashIAP block device. This, together with the `internal_base_address`, adjusts exactly the size and location where the block device resides on memory. If not defined, the block device will try to get the maximum size available.
|
||||
* `internal_base_address` - The address where the internal FlashIAP blockDevice starts. This helps to prevent collisions with other needs, such as firmware updates. If not defined, the start address will be set to the first sector after the application code ends in `TDB_internal`. In any external configurations with rollback protection support, it will be set to end of flash - `rbp_internal_size`.
|
||||
|
|
|
@ -33,6 +33,8 @@
|
|||
|
||||
namespace mbed {
|
||||
|
||||
const unsigned int num_write_retries = 16;
|
||||
|
||||
SingletonPtr<PlatformMutex> FlashIAP::_mutex;
|
||||
|
||||
static inline bool is_aligned(uint32_t number, uint32_t alignment)
|
||||
|
@ -119,7 +121,7 @@ int FlashIAP::program(const void *buffer, uint32_t addr, uint32_t size)
|
|||
|
||||
int ret = 0;
|
||||
_mutex->lock();
|
||||
while (size) {
|
||||
while (size && !ret) {
|
||||
uint32_t current_sector_size = flash_get_sector_size(&_flash, addr);
|
||||
bool unaligned_src = (((size_t) buf / sizeof(uint32_t) * sizeof(uint32_t)) != (size_t) buf);
|
||||
chunk = std::min(current_sector_size - (addr % current_sector_size), size);
|
||||
|
@ -141,11 +143,17 @@ int FlashIAP::program(const void *buffer, uint32_t addr, uint32_t size)
|
|||
prog_size = chunk;
|
||||
}
|
||||
{
|
||||
ScopedRamExecutionLock make_ram_executable;
|
||||
ScopedRomWriteLock make_rom_writable;
|
||||
if (flash_program_page(&_flash, addr, prog_buf, prog_size)) {
|
||||
ret = -1;
|
||||
break;
|
||||
// Few boards may fail the write actions due to HW limitations (like critical drivers that
|
||||
// disable flash operations). Just retry a few times until success.
|
||||
for (unsigned int retry = 0; retry < num_write_retries; retry++) {
|
||||
ScopedRamExecutionLock make_ram_executable;
|
||||
ScopedRomWriteLock make_rom_writable;
|
||||
ret = flash_program_page(&_flash, addr, prog_buf, prog_size);
|
||||
if (ret) {
|
||||
ret = -1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
size -= chunk;
|
||||
|
@ -187,15 +195,18 @@ int FlashIAP::erase(uint32_t addr, uint32_t size)
|
|||
|
||||
int32_t ret = 0;
|
||||
_mutex->lock();
|
||||
while (size) {
|
||||
{
|
||||
while (size && !ret) {
|
||||
// Few boards may fail the erase actions due to HW limitations (like critical drivers that
|
||||
// disable flash operations). Just retry a few times until success.
|
||||
for (unsigned int retry = 0; retry < num_write_retries; retry++) {
|
||||
ScopedRamExecutionLock make_ram_executable;
|
||||
ScopedRomWriteLock make_rom_writable;
|
||||
ret = flash_erase_sector(&_flash, addr);
|
||||
}
|
||||
if (ret != 0) {
|
||||
ret = -1;
|
||||
break;
|
||||
if (ret) {
|
||||
ret = -1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
current_sector_size = flash_get_sector_size(&_flash, addr);
|
||||
size -= current_sector_size;
|
||||
|
|
|
@ -497,7 +497,7 @@ private:
|
|||
}
|
||||
|
||||
/** Constructor init called from all specialized cases of constructor.
|
||||
* Note: All construtor common code should be in this function.
|
||||
* Note: All constructor common code should be in this function.
|
||||
*/
|
||||
void mbed_crc_ctor(void)
|
||||
{
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2015 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
* Copyright (c) 2006-2015 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_BLE_IBEACON_H__
|
||||
#define MBED_BLE_IBEACON_H__
|
||||
|
||||
|
@ -28,8 +28,8 @@
|
|||
* number generally used to determine the location of devices or physical objects
|
||||
* near a mobile phone user.
|
||||
*
|
||||
* iOS scans for iBeacon devices in a background task and notifies Apps
|
||||
* subscribed to a specific region when the area is entered or left. Apps may
|
||||
* iOS scans for iBeacon devices in a background task and notifies apps
|
||||
* that subscribe to a specific region when a device enters or leaves an area. Apps may
|
||||
* use this information to display context-aware content to users.
|
||||
*
|
||||
* As an example, a museum can deploy an app that informs the user when one of
|
||||
|
@ -48,7 +48,7 @@
|
|||
* of iBeacons in relevant touristic locations it operates. The UUID may
|
||||
* identify a place managed by the city. The major ID would identify the place;
|
||||
* it can be a museum, a historic monument, a metro station and so on. The minor ID
|
||||
* would locate a specific spot within a specific city place. It can be a
|
||||
* would identify a specific spot within a specific city place. It can be a
|
||||
* piece of art, a ticket dispenser or a relevant point of interest.
|
||||
*
|
||||
* Each iBeacon device is physically attached to the spot it locates and
|
||||
|
@ -78,7 +78,7 @@
|
|||
*
|
||||
* @attention If you are interested in manufacturing iBeacons, you must obtain a
|
||||
* license from Apple. More information at https://developer.apple.com/ibeacon/.
|
||||
* The licence also grant access to the iBeacons technical specification.
|
||||
* The license also grant access to the iBeacons technical specification.
|
||||
*
|
||||
* @note More information at https://developer.apple.com/ibeacon/Getting-Started-with-iBeacon.pdf
|
||||
*
|
||||
|
@ -88,9 +88,9 @@ MBED_DEPRECATED_SINCE(
|
|||
"mbed-os-5.11",
|
||||
"This service is deprecated, and no replacement is currently available."
|
||||
)
|
||||
class iBeacon
|
||||
{
|
||||
class iBeacon {
|
||||
public:
|
||||
#if !(DOXYGEN_ONLY)
|
||||
/**
|
||||
* Data buffer of a location UUID.
|
||||
*/
|
||||
|
@ -116,12 +116,12 @@ public:
|
|||
uint16_t companyID;
|
||||
|
||||
/**
|
||||
* Packet ID; Equal to 2 for an iBeacon.
|
||||
* Packet ID; equal to 2 for an iBeacon.
|
||||
*/
|
||||
uint8_t ID;
|
||||
|
||||
/**
|
||||
* Length of the remaining data presents in the payload.
|
||||
* Length of the remaining data present in the payload.
|
||||
*/
|
||||
uint8_t len;
|
||||
|
||||
|
@ -131,7 +131,7 @@ public:
|
|||
uint8_t proximityUUID[16];
|
||||
|
||||
/**
|
||||
* Beacon Major group ID.
|
||||
* Beacon major group ID.
|
||||
*/
|
||||
uint16_t majorNumber;
|
||||
|
||||
|
@ -150,11 +150,11 @@ public:
|
|||
* Assemble an iBeacon payload.
|
||||
*
|
||||
* @param[in] uuid Beacon network ID. iBeacon operators use this value
|
||||
* to group their iBeacons into a single network, a single region and
|
||||
* to group their iBeacons into a single network, a single region, and
|
||||
* identify their organization among others.
|
||||
*
|
||||
* @param[in] majNum Beacon major group ID. iBeacon exploitants may use
|
||||
* this field to divide the region into subregions, their network into
|
||||
* this field to divide the region into subregions, and their network into
|
||||
* subnetworks.
|
||||
*
|
||||
* @param[in] minNum Identifier of the Beacon in its subregion.
|
||||
|
@ -181,7 +181,7 @@ public:
|
|||
memcpy(proximityUUID, uuid, sizeof(LocationUUID_t));
|
||||
}
|
||||
};
|
||||
|
||||
#endif //#if !(DOXYGEN_ONLY)
|
||||
public:
|
||||
/**
|
||||
* Construct an iBeacon::Payload and register it into Gap.
|
||||
|
@ -189,17 +189,17 @@ public:
|
|||
* @param[in] _ble The BLE interface to configure with the iBeacon payload.
|
||||
*
|
||||
* @param[in] uuid Beacon network ID. iBeacon operators use this value
|
||||
* to group their iBeacons into a single network, a single region and
|
||||
* to group their iBeacons into a single network, a single region, and
|
||||
* identify their organization among others.
|
||||
*
|
||||
* @param[in] majNum Beacon major group ID. iBeacon exploitants may use
|
||||
* this field to divide the region into subregions, their network into
|
||||
* @param[in] majNum Beacon major group ID. iBeacon fleet operators may use
|
||||
* this field to divide the region into subregions, and their network into
|
||||
* subnetworks.
|
||||
*
|
||||
* @param[in] minNum Identifier of the Beacon in its subregion.
|
||||
*
|
||||
* @param[in] txP Measured transmit power of the beacon at 1
|
||||
* meter. Scanners use this parameter to approximate the distance
|
||||
* @param[in] txP Measured transmit power of the beacon at distance of
|
||||
* one meter. Scanners use this parameter to approximate the distance
|
||||
* to the beacon.
|
||||
*
|
||||
* @param[in] compID ID of the beacon manufacturer.
|
||||
|
|
|
@ -64,6 +64,10 @@ static const GapScanningParams default_scan_params;
|
|||
static const mbed_error_status_t mixed_scan_api_error =
|
||||
MBED_MAKE_ERROR(MBED_MODULE_BLE, MBED_ERROR_CODE_BLE_USE_INCOMPATIBLE_API);
|
||||
|
||||
static const mbed_error_status_t illegal_state_error =
|
||||
MBED_MAKE_ERROR(MBED_MODULE_BLE, MBED_ERROR_CODE_BLE_ILLEGAL_STATE);
|
||||
|
||||
|
||||
/*
|
||||
* Return true if value is included in the range [lower_bound : higher_bound]
|
||||
*/
|
||||
|
@ -1782,7 +1786,8 @@ void GenericGap::on_disconnection_complete(const pal::GapDisconnectionCompleteEv
|
|||
void GenericGap::on_connection_parameter_request(const pal::GapRemoteConnectionParameterRequestEvent &e)
|
||||
{
|
||||
if (_user_manage_connection_parameter_requests) {
|
||||
_eventHandler->onUpdateConnectionParametersRequest(
|
||||
if (_eventHandler) {
|
||||
_eventHandler->onUpdateConnectionParametersRequest(
|
||||
UpdateConnectionParametersRequestEvent(
|
||||
e.connection_handle,
|
||||
conn_interval_t(e.min_connection_interval),
|
||||
|
@ -1791,6 +1796,9 @@ void GenericGap::on_connection_parameter_request(const pal::GapRemoteConnectionP
|
|||
supervision_timeout_t(e.supervision_timeout)
|
||||
)
|
||||
);
|
||||
} else {
|
||||
MBED_ERROR(illegal_state_error, "Event handler required if connection params are user handled");
|
||||
}
|
||||
} else {
|
||||
_pal_gap.accept_connection_parameter_request(
|
||||
e.connection_handle,
|
||||
|
@ -1806,6 +1814,10 @@ void GenericGap::on_connection_parameter_request(const pal::GapRemoteConnectionP
|
|||
|
||||
void GenericGap::on_connection_update(const pal::GapConnectionUpdateEvent &e)
|
||||
{
|
||||
if (!_eventHandler) {
|
||||
return;
|
||||
}
|
||||
|
||||
_eventHandler->onConnectionParametersUpdateComplete(
|
||||
ConnectionParametersUpdateCompleteEvent(
|
||||
e.status == pal::hci_error_code_t::SUCCESS ? BLE_ERROR_NONE : BLE_ERROR_UNSPECIFIED,
|
||||
|
|
|
@ -653,14 +653,20 @@ ble_error_t GenericSecurityManager::generateOOB(
|
|||
/* Secure connections. Avoid generating if we're already waiting for it.
|
||||
* If a local random is set to 0 it means we're already calculating. */
|
||||
if (!is_all_zeros(_oob_local_random)) {
|
||||
status = _pal.generate_secure_connections_oob();
|
||||
/* save the current values in case the call to
|
||||
* generate_secure_connections_oob fails */
|
||||
address_t orig_local_address = _oob_local_address;
|
||||
oob_lesc_value_t orig_local_random = _oob_local_random;
|
||||
|
||||
if (status == BLE_ERROR_NONE) {
|
||||
_oob_local_address = *address;
|
||||
/* this will be updated when calculation completes,
|
||||
* a value of all zeros is an invalid random value */
|
||||
set_all_zeros(_oob_local_random);
|
||||
} else if (status != BLE_ERROR_NOT_IMPLEMENTED) {
|
||||
_oob_local_address = *address;
|
||||
/* this will be updated when calculation completes,
|
||||
* a value of all zeros is an invalid random value */
|
||||
set_all_zeros(_oob_local_random);
|
||||
|
||||
status = _pal.generate_secure_connections_oob();
|
||||
if (status != BLE_ERROR_NONE && status != BLE_ERROR_NOT_IMPLEMENTED) {
|
||||
_oob_local_address = orig_local_address;
|
||||
_oob_local_random = orig_local_random;
|
||||
return status;
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -423,10 +423,10 @@ void BLE::callDispatcher()
|
|||
|
||||
wsfOsDispatcher();
|
||||
|
||||
static Timeout nextTimeout;
|
||||
CriticalSectionLock critical_section;
|
||||
|
||||
if (wsfOsReadyToSleep()) {
|
||||
static Timeout nextTimeout;
|
||||
// setup an mbed timer for the next Cordio timeout
|
||||
bool_t pTimerRunning;
|
||||
timestamp_t nextTimestamp = (timestamp_t) (WsfTimerNextExpiration(&pTimerRunning) * WSF_MS_PER_TICK) * 1000;
|
||||
|
|
|
@ -355,9 +355,10 @@ void btle_handler(const ble_evt_t *p_ble_evt)
|
|||
uint8_t const data_length_peer =
|
||||
p_gap_evt->params.data_length_update_request.peer_params.max_tx_octets;
|
||||
|
||||
const uint8_t max_data_length = NRF_SDH_BLE_GATT_MAX_MTU_SIZE + 4 /* L2CAP header size */;
|
||||
|
||||
uint8_t const data_length = MIN(max_data_length, data_length_peer);
|
||||
uint8_t const data_length = MIN(
|
||||
NRF_SDH_BLE_GATT_MAX_MTU_SIZE + 4 /* L2CAP header size */,
|
||||
data_length_peer
|
||||
);
|
||||
|
||||
ble_gap_data_length_params_t const dlp =
|
||||
{
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include "platform/mbed_assert.h"
|
||||
#include "nRF5xPalSecurityManager.h"
|
||||
#include "nRF5xn.h"
|
||||
#include "ble/Gap.h"
|
||||
|
@ -80,11 +81,6 @@ struct nRF5xSecurityManager::pairing_control_block_t {
|
|||
ble_gap_id_key_t peer_id_key;
|
||||
ble_gap_sign_info_t peer_sign_key;
|
||||
ble_gap_lesc_p256_pk_t peer_pk;
|
||||
|
||||
// flag required to help DHKey computation/process; should be removed with
|
||||
// later versions of the softdevice
|
||||
uint8_t own_oob:1;
|
||||
uint8_t peer_oob:1;
|
||||
};
|
||||
|
||||
nRF5xSecurityManager::nRF5xSecurityManager()
|
||||
|
@ -662,26 +658,37 @@ ble_error_t nRF5xSecurityManager::secure_connections_oob_request_reply(
|
|||
const oob_lesc_value_t &peer_random,
|
||||
const oob_confirm_t &peer_confirm
|
||||
) {
|
||||
bool have_oob_own;
|
||||
bool have_oob_peer;
|
||||
const oob_lesc_value_t zerokey;
|
||||
ble_gap_lesc_oob_data_t oob_own;
|
||||
ble_gap_lesc_oob_data_t oob_peer;
|
||||
|
||||
pairing_control_block_t* pairing_cb = get_pairing_cb(connection);
|
||||
if (!pairing_cb) {
|
||||
return BLE_ERROR_INVALID_STATE;
|
||||
}
|
||||
|
||||
ble_gap_lesc_oob_data_t oob_own;
|
||||
ble_gap_lesc_oob_data_t oob_peer;
|
||||
have_oob_own = false;
|
||||
if (local_random != zerokey) {
|
||||
have_oob_own = true;
|
||||
// is own address important ?
|
||||
memcpy(oob_own.r, local_random.data(), local_random.size());
|
||||
// FIXME: What to do with local confirm ???
|
||||
}
|
||||
|
||||
// is own address important ?
|
||||
memcpy(oob_own.r, local_random.data(), local_random.size());
|
||||
// FIXME: What to do with local confirm ???
|
||||
|
||||
// is peer address important ?
|
||||
memcpy(oob_peer.r, peer_random.data(), peer_random.size());
|
||||
memcpy(oob_peer.c, peer_confirm.data(), peer_confirm.size());
|
||||
have_oob_peer = false;
|
||||
if (peer_random != zerokey && peer_confirm != zerokey) {
|
||||
have_oob_peer = true;
|
||||
// is peer address important ?
|
||||
memcpy(oob_peer.r, peer_random.data(), peer_random.size());
|
||||
memcpy(oob_peer.c, peer_confirm.data(), peer_confirm.size());
|
||||
}
|
||||
|
||||
uint32_t err = sd_ble_gap_lesc_oob_data_set(
|
||||
connection,
|
||||
pairing_cb->own_oob ? &oob_own : NULL,
|
||||
pairing_cb->peer_oob ? &oob_peer : NULL
|
||||
have_oob_own ? &oob_own : NULL,
|
||||
have_oob_peer ? &oob_peer : NULL
|
||||
);
|
||||
|
||||
return convert_sd_error(err);
|
||||
|
@ -734,7 +741,9 @@ ble_error_t nRF5xSecurityManager::generate_secure_connections_oob()
|
|||
ble_gap_lesc_p256_pk_t own_secret;
|
||||
ble_gap_lesc_oob_data_t oob_data;
|
||||
|
||||
memcpy(own_secret.pk, secret.data(), secret.size());
|
||||
MBED_ASSERT(sizeof(own_secret.pk) >= X.size() + Y.size());
|
||||
memcpy(own_secret.pk, X.data(), X.size());
|
||||
memcpy(own_secret.pk + X.size(), Y.data(), Y.size());
|
||||
|
||||
uint32_t err = sd_ble_gap_lesc_oob_data_get(
|
||||
BLE_CONN_HANDLE_INVALID,
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace mbed {
|
|||
#elif TARGET_MTB_MTS_DRAGONFLY
|
||||
#define CELLULAR_DEVICE TELIT_HE910
|
||||
#elif TARGET_UBLOX_C030
|
||||
#if defined(TARGET_UBLOX_C030_N211) || defined(TARGET_UBLOX_C030_R410M)
|
||||
#if defined(TARGET_UBLOX_C030_N211) || defined(TARGET_UBLOX_C030_R41XM)
|
||||
#define CELLULAR_DEVICE UBLOX_AT
|
||||
#else
|
||||
#define CELLULAR_DEVICE UBLOX_PPP
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* 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_M26_CellularNetwork.h"
|
||||
#include "QUECTEL_M26_CellularPower.h"
|
||||
#include "QUECTEL_M26_CellularSIM.h"
|
||||
#include "QUECTEL_M26_CellularContext.h"
|
||||
#include "QUECTEL_M26.h"
|
||||
|
||||
using namespace events;
|
||||
using namespace mbed;
|
||||
|
||||
#define CONNECT_DELIM "\r\n"
|
||||
#define CONNECT_BUFFER_SIZE (1280 + 80 + 80) // AT response + sscanf format
|
||||
#define CONNECT_TIMEOUT 8000
|
||||
|
||||
#define MAX_STARTUP_TRIALS 5
|
||||
#define MAX_RESET_TRIALS 5
|
||||
|
||||
static const AT_CellularBase::SupportedFeature unsupported_features[] = {
|
||||
AT_CellularBase::AT_CGSN_WITH_TYPE,
|
||||
AT_CellularBase::AT_CGAUTH,
|
||||
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
|
||||
};
|
||||
|
||||
QUECTEL_M26::QUECTEL_M26(FileHandle *fh) : AT_CellularDevice(fh)
|
||||
{
|
||||
AT_CellularBase::set_unsupported_features(unsupported_features);
|
||||
}
|
||||
|
||||
QUECTEL_M26::~QUECTEL_M26()
|
||||
{
|
||||
}
|
||||
|
||||
AT_CellularNetwork *QUECTEL_M26::open_network_impl(ATHandler &at)
|
||||
{
|
||||
return new QUECTEL_M26_CellularNetwork(at);
|
||||
}
|
||||
|
||||
AT_CellularPower *QUECTEL_M26::open_power_impl(ATHandler &at)
|
||||
{
|
||||
return new QUECTEL_M26_CellularPower(at);
|
||||
}
|
||||
|
||||
AT_CellularSIM *QUECTEL_M26::open_sim_impl(ATHandler &at)
|
||||
{
|
||||
return new QUECTEL_M26_CellularSIM(at);
|
||||
}
|
||||
|
||||
AT_CellularContext *QUECTEL_M26::create_context_impl(ATHandler &at, const char *apn)
|
||||
{
|
||||
return new QUECTEL_M26_CellularContext(at, this, apn);
|
||||
}
|
|
@ -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.
|
||||
*/
|
||||
|
||||
#ifndef QUECTEL_M26_H_
|
||||
#define QUECTEL_M26_H_
|
||||
|
||||
#include "AT_CellularDevice.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
class QUECTEL_M26 : public AT_CellularDevice {
|
||||
public:
|
||||
QUECTEL_M26(FileHandle *fh);
|
||||
virtual ~QUECTEL_M26();
|
||||
|
||||
protected: // AT_CellularDevice
|
||||
virtual AT_CellularNetwork *open_network_impl(ATHandler &at);
|
||||
virtual AT_CellularPower *open_power_impl(ATHandler &at);
|
||||
virtual AT_CellularSIM *open_sim_impl(ATHandler &at);
|
||||
virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn);
|
||||
|
||||
public: // NetworkInterface
|
||||
void handle_urc(FileHandle *fh);
|
||||
};
|
||||
} // namespace mbed
|
||||
|
||||
#endif // QUECTEL_M26_H_
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* 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_M26_CellularContext.h"
|
||||
#include "QUECTEL_M26_CellularStack.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
QUECTEL_M26_CellularContext::QUECTEL_M26_CellularContext(ATHandler &at, CellularDevice *device, const char *apn) :
|
||||
AT_CellularContext(at, device, apn)
|
||||
{
|
||||
}
|
||||
|
||||
QUECTEL_M26_CellularContext::~QUECTEL_M26_CellularContext()
|
||||
{
|
||||
}
|
||||
|
||||
bool QUECTEL_M26_CellularContext::stack_type_supported(nsapi_ip_stack_t stack_type)
|
||||
{
|
||||
return stack_type == IPV4_STACK ? true : false;
|
||||
}
|
||||
|
||||
#if !NSAPI_PPP_AVAILABLE
|
||||
NetworkStack *QUECTEL_M26_CellularContext::get_stack()
|
||||
{
|
||||
if (!_stack) {
|
||||
_stack = new QUECTEL_M26_CellularStack(_at, _cid, _ip_stack_type);
|
||||
}
|
||||
return _stack;
|
||||
}
|
||||
#endif // #if !NSAPI_PPP_AVAILABLE
|
||||
|
||||
nsapi_error_t QUECTEL_M26_CellularContext::do_user_authentication()
|
||||
{
|
||||
|
||||
_at.cmd_start("AT+QICSGP=");
|
||||
_at.write_int(1); /*GPRS MODE = 1, CSD MODE = 0*/
|
||||
_at.write_string(_apn);
|
||||
if (_pwd && _uname) {
|
||||
_at.write_string(_uname);
|
||||
_at.write_string(_pwd);
|
||||
}
|
||||
_at.cmd_stop();
|
||||
_at.resp_start();
|
||||
_at.resp_stop();
|
||||
if (_at.get_last_error() != NSAPI_ERROR_OK) {
|
||||
return NSAPI_ERROR_AUTH_FAILURE;
|
||||
}
|
||||
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
} /* namespace mbed */
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef QUECTEL_M26_CELLULARCONTEXT_H_
|
||||
#define QUECTEL_M26_CELLULARCONTEXT_H_
|
||||
|
||||
#include "AT_CellularContext.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
class QUECTEL_M26_CellularContext: public AT_CellularContext {
|
||||
public:
|
||||
QUECTEL_M26_CellularContext(ATHandler &at, CellularDevice *device, const char *apn);
|
||||
virtual ~QUECTEL_M26_CellularContext();
|
||||
|
||||
protected:
|
||||
virtual bool stack_type_supported(nsapi_ip_stack_t stack_type);
|
||||
#if !NSAPI_PPP_AVAILABLE
|
||||
virtual NetworkStack *get_stack();
|
||||
#endif // #if !NSAPI_PPP_AVAILABLE
|
||||
virtual nsapi_error_t do_user_authentication();
|
||||
};
|
||||
|
||||
} /* namespace mbed */
|
||||
|
||||
#endif // QUECTEL_M26_CELLULARCONTEXT_H_
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* 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_M26_CellularNetwork.h"
|
||||
|
||||
using namespace mbed;
|
||||
|
||||
QUECTEL_M26_CellularNetwork::QUECTEL_M26_CellularNetwork(ATHandler &atHandler) : AT_CellularNetwork(atHandler)
|
||||
{
|
||||
_op_act = RAT_EGPRS;
|
||||
}
|
||||
|
||||
QUECTEL_M26_CellularNetwork::~QUECTEL_M26_CellularNetwork()
|
||||
{
|
||||
}
|
||||
|
||||
AT_CellularNetwork::RegistrationMode QUECTEL_M26_CellularNetwork::has_registration(RegistrationType reg_type)
|
||||
{
|
||||
return (reg_type == C_GREG) ? RegistrationModeLAC : RegistrationModeDisable;
|
||||
}
|
||||
|
||||
nsapi_error_t QUECTEL_M26_CellularNetwork::set_access_technology_impl(RadioAccessTechnology opRat)
|
||||
{
|
||||
if (opRat != RAT_EGPRS) {
|
||||
// only GPRS support in the driver.
|
||||
_op_act = RAT_EGPRS;
|
||||
return NSAPI_ERROR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef QUECTEL_M26_CELLULAR_NETWORK_H_
|
||||
#define QUECTEL_M26_CELLULAR_NETWORK_H_
|
||||
|
||||
#include "AT_CellularNetwork.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
class QUECTEL_M26_CellularNetwork : public AT_CellularNetwork {
|
||||
public:
|
||||
QUECTEL_M26_CellularNetwork(ATHandler &atHandler);
|
||||
virtual ~QUECTEL_M26_CellularNetwork();
|
||||
|
||||
protected:
|
||||
virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology opRat);
|
||||
virtual RegistrationMode has_registration(RegistrationType reg_type);
|
||||
};
|
||||
} // namespace mbed
|
||||
#endif // QUECTEL_M26_CELLULAR_NETWORK_H_
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* 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_M26_CellularPower.h"
|
||||
|
||||
using namespace mbed;
|
||||
|
||||
QUECTEL_M26_CellularPower::QUECTEL_M26_CellularPower(ATHandler &atHandler) : AT_CellularPower(atHandler)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QUECTEL_M26_CellularPower::~QUECTEL_M26_CellularPower()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
nsapi_error_t QUECTEL_M26_CellularPower::set_at_mode()
|
||||
{
|
||||
_at.lock();
|
||||
_at.cmd_start("AT");
|
||||
_at.cmd_stop_read_resp();
|
||||
|
||||
_at.cmd_start("AT+CMEE="); // verbose responses
|
||||
_at.write_int(1);
|
||||
_at.cmd_stop_read_resp();
|
||||
|
||||
return _at.unlock_return_error();
|
||||
}
|
||||
|
||||
nsapi_error_t QUECTEL_M26_CellularPower::on()
|
||||
{
|
||||
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
nsapi_error_t QUECTEL_M26_CellularPower::off()
|
||||
{
|
||||
_at.lock();
|
||||
_at.cmd_start("AT+QPOWD=0");
|
||||
_at.cmd_stop();
|
||||
_at.resp_start();
|
||||
_at.resp_stop();
|
||||
|
||||
return _at.unlock_return_error();;
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef QUECTEL_M26_CELLULAR_POWER_H_
|
||||
#define QUECTEL_M26_CELLULAR_POWER_H_
|
||||
|
||||
#include "AT_CellularPower.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
class QUECTEL_M26_CellularPower : public AT_CellularPower {
|
||||
public:
|
||||
QUECTEL_M26_CellularPower(ATHandler &atHandler);
|
||||
virtual ~QUECTEL_M26_CellularPower();
|
||||
|
||||
public: //from CellularPower
|
||||
virtual nsapi_error_t set_at_mode();
|
||||
|
||||
virtual nsapi_error_t on();
|
||||
|
||||
virtual nsapi_error_t off();
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif // QUECTEL_M26_CELLULAR_POWER_H_
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* 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_M26_CellularSIM.h"
|
||||
#include "CellularLog.h"
|
||||
|
||||
using namespace mbed;
|
||||
|
||||
QUECTEL_M26_CellularSIM::QUECTEL_M26_CellularSIM(ATHandler &atHandler) : AT_CellularSIM(atHandler)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QUECTEL_M26_CellularSIM::~QUECTEL_M26_CellularSIM()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
nsapi_error_t QUECTEL_M26_CellularSIM::get_sim_state(SimState &state)
|
||||
{
|
||||
char buf[13];
|
||||
|
||||
_at.lock();
|
||||
_at.cmd_start("AT+CPIN?");
|
||||
_at.cmd_stop();
|
||||
_at.resp_start("+CPIN:");
|
||||
if (_at.info_resp()) {
|
||||
_at.read_string(buf, 13);
|
||||
tr_debug("CPIN: %s", buf);
|
||||
|
||||
if (memcmp(buf, "READY", 5) == 0) {
|
||||
state = SimStateReady;
|
||||
} else if (memcmp(buf, "SIM PIN", 7) == 0) {
|
||||
state = SimStatePinNeeded;
|
||||
} else if (memcmp(buf, "SIM PUK", 7) == 0) {
|
||||
state = SimStatePukNeeded;
|
||||
} else if (memcmp(buf, "PH_SIM PIN", 10) == 0) {
|
||||
state = SimStatePinNeeded;
|
||||
} else if (memcmp(buf, "PH_SIM PUK", 10) == 0) {
|
||||
state = SimStatePukNeeded;
|
||||
} else if (memcmp(buf, "SIM PIN2", 8) == 0) {
|
||||
state = SimStatePinNeeded;
|
||||
} else if (memcmp(buf, "SIM PUK2", 8) == 0) {
|
||||
state = SimStatePukNeeded;
|
||||
} else {
|
||||
state = SimStateUnknown; // SIM may not be ready yet
|
||||
}
|
||||
|
||||
}
|
||||
_at.resp_stop();
|
||||
return _at.unlock_return_error();
|
||||
}
|
||||
|
||||
// According to M26_AT_Commands_Manual_V1.9
|
||||
nsapi_error_t QUECTEL_M26_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();
|
||||
}
|
||||
|
||||
nsapi_error_t QUECTEL_M26_CellularSIM::change_pin(const char *sim_pin, const char *new_pin)
|
||||
{
|
||||
return NSAPI_ERROR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
nsapi_error_t QUECTEL_M26_CellularSIM::set_pin_query(const char *sim_pin, bool query_pin)
|
||||
{
|
||||
return NSAPI_ERROR_UNSUPPORTED;
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef QUECTEL_M26_CELLULAR_SIM_H_
|
||||
#define QUECTEL_M26_CELLULAR_SIM_H_
|
||||
|
||||
#include "AT_CellularSIM.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
class QUECTEL_M26_CellularSIM : public AT_CellularSIM {
|
||||
public:
|
||||
QUECTEL_M26_CellularSIM(ATHandler &atHandler);
|
||||
virtual ~QUECTEL_M26_CellularSIM();
|
||||
|
||||
public: //from CellularSIM
|
||||
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 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
|
||||
|
||||
#endif // QUECTEL_M26_CELLULAR_SIM_H_
|
|
@ -0,0 +1,498 @@
|
|||
/*
|
||||
* 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/M26/QUECTEL_M26_CellularStack.h"
|
||||
#include "CellularLog.h"
|
||||
|
||||
using namespace mbed;
|
||||
|
||||
QUECTEL_M26_CellularStack::QUECTEL_M26_CellularStack(ATHandler &atHandler, int cid, nsapi_ip_stack_t stack_type) : AT_CellularStack(atHandler, cid, stack_type)
|
||||
{
|
||||
_at.set_urc_handler("+QIRDI:", mbed::Callback<void()>(this, &QUECTEL_M26_CellularStack::urc_qiurc));
|
||||
}
|
||||
|
||||
QUECTEL_M26_CellularStack::~QUECTEL_M26_CellularStack()
|
||||
{
|
||||
}
|
||||
|
||||
nsapi_error_t QUECTEL_M26_CellularStack::socket_listen(nsapi_socket_t handle, int backlog)
|
||||
{
|
||||
return NSAPI_ERROR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
nsapi_error_t QUECTEL_M26_CellularStack::socket_accept(void *server, void **socket, SocketAddress *addr)
|
||||
{
|
||||
return NSAPI_ERROR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
nsapi_error_t QUECTEL_M26_CellularStack::socket_bind(nsapi_socket_t handle, const SocketAddress &addr)
|
||||
{
|
||||
return NSAPI_ERROR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
void QUECTEL_M26_CellularStack::urc_qiurc()
|
||||
{
|
||||
int sock_id = 0;
|
||||
|
||||
_at.lock();
|
||||
(void) _at.skip_param(); /*<id> AT+QIFGCNT*/
|
||||
(void) _at.skip_param(); /*<sc> 1 Client, 2 Server*/
|
||||
sock_id = _at.read_int();
|
||||
(void) _at.skip_param(); /*<num>*/
|
||||
(void) _at.skip_param(); /*<len>*/
|
||||
(void) _at.skip_param(); /*<tlen>*/
|
||||
_at.unlock();
|
||||
|
||||
for (int i = 0; i < get_max_socket_count(); i++) {
|
||||
CellularSocket *sock = _socket[i];
|
||||
if (sock && sock->id == sock_id) {
|
||||
if (sock->_cb) {
|
||||
sock->_cb(sock->_data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsapi_error_t QUECTEL_M26_CellularStack::socket_stack_init()
|
||||
{
|
||||
int tcpip_mode = 1;
|
||||
int mux_mode = 0;
|
||||
int cache_mode = 0;
|
||||
nsapi_error_t ret_val;
|
||||
|
||||
tr_debug("QUECTEL_M26_CellularStack:%s:%u: START ", __FUNCTION__, __LINE__);
|
||||
_at.lock();
|
||||
|
||||
/*AT+QIFGCNT=0*/
|
||||
_at.cmd_start("AT+QIFGCNT=");
|
||||
_at.write_int(0); /* Set the Context 0 as the foreground context.*/
|
||||
_at.cmd_stop();
|
||||
_at.resp_start();
|
||||
_at.resp_stop();
|
||||
|
||||
ret_val = _at.get_last_error();
|
||||
if (ret_val != NSAPI_ERROR_OK) {
|
||||
_at.unlock();
|
||||
return NSAPI_ERROR_DEVICE_ERROR;
|
||||
}
|
||||
#if 0
|
||||
/*AT+QICSGP=1*/
|
||||
_at.cmd_start("AT+QICSGP=");
|
||||
_at.write_int(1); /* mode: 0-CSD, 1-GPRS */
|
||||
_at.write_string(_apn);
|
||||
if (_pwd && _uname) {
|
||||
_at.write_string(_uname);
|
||||
_at.write_string(_pwd);
|
||||
}
|
||||
_at.cmd_stop();
|
||||
_at.resp_start();
|
||||
_at.resp_stop();
|
||||
#endif
|
||||
ret_val = _at.get_last_error();
|
||||
if (ret_val != NSAPI_ERROR_OK) {
|
||||
_at.unlock();
|
||||
return NSAPI_ERROR_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
/*AT+QIMODE=0 Set transparent mode*/
|
||||
_at.cmd_start("AT+QIMODE?");
|
||||
_at.cmd_stop();
|
||||
_at.resp_start("+QIMODE:");
|
||||
if (_at.info_resp()) {
|
||||
tcpip_mode = _at.read_int();
|
||||
}
|
||||
_at.resp_stop();
|
||||
if (tcpip_mode) {
|
||||
_at.cmd_start("AT+QIMOD=");
|
||||
_at.write_int(0); /* 0-Disable, 1-Enable */
|
||||
_at.cmd_stop();
|
||||
_at.resp_start();
|
||||
_at.resp_stop();
|
||||
}
|
||||
ret_val = _at.get_last_error();
|
||||
if (ret_val != NSAPI_ERROR_OK) {
|
||||
_at.unlock();
|
||||
return NSAPI_ERROR_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
/*AT+QIMUX=1*/
|
||||
_at.cmd_start("AT+QIMUX?");
|
||||
_at.cmd_stop();
|
||||
_at.resp_start("+QIMUX:");
|
||||
if (_at.info_resp()) {
|
||||
mux_mode = _at.read_int();
|
||||
}
|
||||
_at.resp_stop();
|
||||
if (!mux_mode) {
|
||||
_at.cmd_start("AT+QIMUX=");
|
||||
_at.write_int(1); /* 0-Disable, 1-Enable */
|
||||
_at.cmd_stop();
|
||||
_at.resp_start();
|
||||
_at.resp_stop();
|
||||
}
|
||||
ret_val = _at.get_last_error();
|
||||
if (ret_val != NSAPI_ERROR_OK) {
|
||||
_at.unlock();
|
||||
return NSAPI_ERROR_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
/*AT+QINDI=2*/
|
||||
_at.cmd_start("AT+QINDI?");
|
||||
_at.cmd_stop();
|
||||
_at.resp_start();
|
||||
if (_at.info_resp()) {
|
||||
cache_mode = _at.read_int();
|
||||
}
|
||||
_at.resp_stop();
|
||||
if (cache_mode != 2) {
|
||||
_at.cmd_start("AT+QINDI=");
|
||||
_at.write_int(2); /* 0-Disable, 1-Single Cache, 2-Multi Cache */
|
||||
_at.cmd_stop();
|
||||
_at.resp_start();
|
||||
_at.resp_stop();
|
||||
}
|
||||
|
||||
ret_val = _at.get_last_error();
|
||||
if (ret_val != NSAPI_ERROR_OK) {
|
||||
_at.unlock();
|
||||
return NSAPI_ERROR_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
_at.unlock();
|
||||
|
||||
tr_debug("QUECTEL_M26_CellularStack:%s:%u: SUCCESS ", __FUNCTION__, __LINE__);
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
int QUECTEL_M26_CellularStack::get_max_socket_count()
|
||||
{
|
||||
return M26_SOCKET_MAX;
|
||||
}
|
||||
|
||||
bool QUECTEL_M26_CellularStack::is_protocol_supported(nsapi_protocol_t protocol)
|
||||
{
|
||||
return (protocol == NSAPI_UDP || protocol == NSAPI_TCP);
|
||||
}
|
||||
|
||||
nsapi_error_t QUECTEL_M26_CellularStack::socket_close_impl(int sock_id)
|
||||
{
|
||||
tr_debug("QUECTEL_M26_CellularStack:%s:%u:", __FUNCTION__, __LINE__);
|
||||
|
||||
_at.cmd_start("AT+QICLOSE=");
|
||||
_at.write_int(sock_id);
|
||||
_at.cmd_stop();
|
||||
_at.resp_start();
|
||||
_at.resp_stop();
|
||||
|
||||
return _at.get_last_error();
|
||||
}
|
||||
|
||||
void QUECTEL_M26_CellularStack::handle_open_socket_response(int &modem_connect_id, int &err)
|
||||
{
|
||||
char status[15];
|
||||
tr_debug("QUECTEL_M26_CellularStack:%s:%u: START", __FUNCTION__, __LINE__);
|
||||
|
||||
_at.resp_start("ALREADY CONNECT");
|
||||
if (_at.info_resp()) {
|
||||
/* ALREADY CONNECT: The request socket already connected */
|
||||
err = 0;
|
||||
return;
|
||||
}
|
||||
_at.resp_stop();
|
||||
if (_at.get_last_error() != NSAPI_ERROR_OK) {
|
||||
/* ERROR: The command format error */
|
||||
err = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
tr_debug("QUECTEL_M26_CellularStack:%s:%u: OK", __FUNCTION__, __LINE__);
|
||||
|
||||
_at.set_at_timeout(M26_CREATE_SOCKET_TIMEOUT);
|
||||
_at.resp_start();
|
||||
_at.set_stop_tag("\r\n");
|
||||
modem_connect_id = _at.read_int();
|
||||
_at.read_string(status, sizeof(status), true);
|
||||
_at.resp_stop();
|
||||
_at.restore_at_timeout();
|
||||
|
||||
if ((!strcmp(status, "CONNECT FAIL")) || (_at.get_last_error() != NSAPI_ERROR_OK)) {
|
||||
err = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
err = 0;
|
||||
tr_debug("QUECTEL_M26_CellularStack:%s:%u: END [%s, %d]", __FUNCTION__, __LINE__, status, err);
|
||||
}
|
||||
|
||||
|
||||
nsapi_error_t QUECTEL_M26_CellularStack::socket_connect(nsapi_socket_t handle, const SocketAddress &address)
|
||||
{
|
||||
CellularSocket *socket = (CellularSocket *)handle;
|
||||
|
||||
int modem_connect_id = -1;
|
||||
int request_connect_id = socket->id;
|
||||
int err = -1;
|
||||
|
||||
_at.lock();
|
||||
if (socket->proto == NSAPI_TCP) {
|
||||
_at.cmd_start("AT+QIOPEN=");
|
||||
_at.write_int(request_connect_id);
|
||||
_at.write_string("TCP");
|
||||
_at.write_string(address.get_ip_address());
|
||||
_at.write_int(address.get_port());
|
||||
_at.cmd_stop();
|
||||
|
||||
handle_open_socket_response(modem_connect_id, err);
|
||||
|
||||
if ((_at.get_last_error() == NSAPI_ERROR_OK) && err) {
|
||||
_at.cmd_start("AT+QICLOSE=");
|
||||
_at.write_int(modem_connect_id);
|
||||
_at.cmd_stop();
|
||||
_at.resp_start();
|
||||
_at.resp_stop();
|
||||
|
||||
_at.cmd_start("AT+QIOPEN=");
|
||||
_at.write_int(request_connect_id);
|
||||
_at.write_string("TCP");
|
||||
_at.write_string(address.get_ip_address());
|
||||
_at.write_int(address.get_port());
|
||||
_at.cmd_stop();
|
||||
|
||||
handle_open_socket_response(modem_connect_id, err);
|
||||
}
|
||||
}
|
||||
|
||||
// If opened successfully BUT not requested one, close it
|
||||
if (!err && (modem_connect_id != request_connect_id)) {
|
||||
_at.cmd_start("AT+QICLOSE=");
|
||||
_at.write_int(modem_connect_id);
|
||||
_at.cmd_stop();
|
||||
_at.resp_start();
|
||||
_at.resp_stop();
|
||||
}
|
||||
|
||||
nsapi_error_t ret_val = _at.get_last_error();
|
||||
_at.unlock();
|
||||
|
||||
if ((ret_val == NSAPI_ERROR_OK) && (modem_connect_id == request_connect_id)) {
|
||||
socket->created = true;
|
||||
socket->remoteAddress = address;
|
||||
socket->connected = true;
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
return NSAPI_ERROR_NO_CONNECTION;
|
||||
}
|
||||
|
||||
nsapi_error_t QUECTEL_M26_CellularStack::create_socket_impl(CellularSocket *socket)
|
||||
{
|
||||
int request_connect_id = socket->id;
|
||||
int modem_connect_id = request_connect_id;
|
||||
int err = -1;
|
||||
nsapi_error_t ret_val;
|
||||
tr_debug("QUECTEL_M26_CellularStack:%s:%u:[%d,%d]", __FUNCTION__, __LINE__, socket->proto, socket->connected);
|
||||
|
||||
if (socket->connected) {
|
||||
_at.cmd_start("AT+QIOPEN=");
|
||||
_at.write_int(request_connect_id);
|
||||
_at.write_string((socket->proto == NSAPI_TCP) ? "TCP" : "UDP");
|
||||
_at.write_string(socket->remoteAddress.get_ip_address());
|
||||
_at.write_int(socket->remoteAddress.get_port());
|
||||
_at.cmd_stop();
|
||||
|
||||
handle_open_socket_response(modem_connect_id, err);
|
||||
|
||||
/* Close and retry if socket create fail */
|
||||
if ((_at.get_last_error() != NSAPI_ERROR_OK) || err) {
|
||||
_at.cmd_start("AT+QICLOSE=");
|
||||
_at.write_int(modem_connect_id);
|
||||
_at.cmd_stop();
|
||||
_at.resp_start();
|
||||
_at.resp_stop();
|
||||
|
||||
_at.cmd_start("AT+QIOPEN=");
|
||||
_at.write_int(request_connect_id);
|
||||
_at.write_string((socket->proto == NSAPI_TCP) ? "TCP" : "UDP");
|
||||
_at.write_string(socket->remoteAddress.get_ip_address());
|
||||
_at.write_int(socket->remoteAddress.get_port());
|
||||
_at.cmd_stop();
|
||||
|
||||
handle_open_socket_response(modem_connect_id, err);
|
||||
}
|
||||
|
||||
/* If opened successfully BUT not requested one, close it */
|
||||
if (!err && (modem_connect_id != request_connect_id)) {
|
||||
_at.cmd_start("AT+QICLOSE=");
|
||||
_at.write_int(modem_connect_id);
|
||||
_at.cmd_stop();
|
||||
_at.resp_start();
|
||||
_at.resp_stop();
|
||||
}
|
||||
|
||||
ret_val = _at.get_last_error();
|
||||
socket->created = ((ret_val == NSAPI_ERROR_OK) && (modem_connect_id == request_connect_id));
|
||||
return ret_val;
|
||||
} else {
|
||||
tr_warn("QUECTEL_M26_CellularStack:%s:%u: Do not support TCP Listner/UDP Service Mode [%d,%d]", __FUNCTION__, __LINE__, socket->created, ret_val);
|
||||
ret_val = NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
tr_debug("QUECTEL_M26_CellularStack:%s:%u: END [%d,%d]", __FUNCTION__, __LINE__, socket->created, ret_val);
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
|
||||
nsapi_size_or_error_t QUECTEL_M26_CellularStack::socket_sendto_impl(CellularSocket *socket, const SocketAddress &address,
|
||||
const void *data, nsapi_size_t size)
|
||||
{
|
||||
int sent_len = (size > M26_SENT_BYTE_MAX) ? M26_SENT_BYTE_MAX : size;
|
||||
int sent_acked = 0;
|
||||
int sent_nacked = 0;
|
||||
int sent_len_before = 0;
|
||||
int sent_len_after = 0;
|
||||
nsapi_error_t error;
|
||||
|
||||
tr_debug("QUECTEL_M26_CellularStack:%s:%u:[%d-%d]", __FUNCTION__, __LINE__, sent_len, size);
|
||||
|
||||
if (sent_len == 0) {
|
||||
tr_error("QUECTEL_M26_CellularStack:%s:%u:[NSAPI_ERROR_PARAMETER]", __FUNCTION__, __LINE__);
|
||||
return NSAPI_ERROR_PARAMETER;
|
||||
}
|
||||
|
||||
if (!socket->created) {
|
||||
socket->remoteAddress = address;
|
||||
socket->connected = true;
|
||||
nsapi_error_t ret_val = create_socket_impl(socket);
|
||||
if ((ret_val != NSAPI_ERROR_OK) || (!socket->created)) {
|
||||
tr_error("QUECTEL_M26_CellularStack:%s:%u:[NSAPI_ERROR_NO_SOCKET]", __FUNCTION__, __LINE__);
|
||||
return NSAPI_ERROR_NO_SOCKET;
|
||||
}
|
||||
}
|
||||
|
||||
if (socket->proto == NSAPI_TCP) {
|
||||
_at.cmd_start("AT+QISACK=");
|
||||
_at.write_int(socket->id);
|
||||
_at.cmd_stop();
|
||||
_at.resp_start("+QISACK:");
|
||||
sent_len_before = _at.read_int();
|
||||
sent_acked = _at.read_int();
|
||||
sent_nacked = _at.read_int();
|
||||
_at.resp_stop();
|
||||
|
||||
if (_at.get_last_error() != NSAPI_ERROR_OK) {
|
||||
tr_error("QUECTEL_M26_CellularStack:%s:%u:[NSAPI_ERROR_DEVICE_ERROR]", __FUNCTION__, __LINE__);
|
||||
return NSAPI_ERROR_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
if (sent_nacked != 0) {
|
||||
tr_debug("QUECTEL_M26_CellularStack:%s:%u:[NSAPI_ERROR_WOULD_BLOCK]", __FUNCTION__, __LINE__);
|
||||
return NSAPI_ERROR_WOULD_BLOCK;
|
||||
}
|
||||
}
|
||||
|
||||
_at.cmd_start("AT+QISEND=");
|
||||
_at.write_int(socket->id);
|
||||
_at.write_int(sent_len);
|
||||
_at.cmd_stop();
|
||||
|
||||
_at.resp_start(">");
|
||||
_at.write_bytes((uint8_t *)data, sent_len);
|
||||
_at.resp_start();
|
||||
_at.resp_stop();
|
||||
|
||||
if (_at.get_last_error() != NSAPI_ERROR_OK) {
|
||||
tr_error("QUECTEL_M26_CellularStack:%s:%u:[NSAPI_ERROR_DEVICE_ERROR]", __FUNCTION__, __LINE__);
|
||||
return NSAPI_ERROR_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
if (socket->proto == NSAPI_TCP) {
|
||||
_at.cmd_start("AT+QISACK=");
|
||||
_at.write_int(socket->id);
|
||||
_at.cmd_stop();
|
||||
|
||||
_at.resp_start("+QISACK:");
|
||||
sent_len_after = _at.read_int();
|
||||
sent_acked = _at.read_int();
|
||||
sent_nacked = _at.read_int();
|
||||
_at.resp_stop();
|
||||
|
||||
error = _at.get_last_error();
|
||||
if (error == NSAPI_ERROR_OK) {
|
||||
sent_len = sent_len_after - sent_len_before;
|
||||
tr_debug("QUECTEL_M26_CellularStack:%s:%u:[TCP: BA %d-%d, ACK %d-%d,LEN %d-%d]", __FUNCTION__, __LINE__, sent_len_before, sent_len_after, sent_acked, sent_nacked, sent_len, size);
|
||||
return sent_len;
|
||||
}
|
||||
|
||||
tr_error("QUECTEL_M26_CellularStack:%s:%u:[TCP: %d]", __FUNCTION__, __LINE__, error);
|
||||
return error;
|
||||
}
|
||||
|
||||
error = _at.get_last_error();
|
||||
if (error == NSAPI_ERROR_OK) {
|
||||
tr_debug("QUECTEL_M26_CellularStack:%s:%u:[UDP: %d]", __FUNCTION__, __LINE__, sent_len);
|
||||
return sent_len;
|
||||
}
|
||||
|
||||
tr_debug("QUECTEL_M26_CellularStack:%s:%u:[ERROR: %d]", __FUNCTION__, __LINE__, error);
|
||||
return error;
|
||||
}
|
||||
|
||||
nsapi_size_or_error_t QUECTEL_M26_CellularStack::socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address,
|
||||
void *buffer, nsapi_size_t size)
|
||||
{
|
||||
nsapi_size_or_error_t recv_len = (size > M26_RECV_BYTE_MAX) ? M26_RECV_BYTE_MAX : size;
|
||||
int recv_len_after = 0;
|
||||
int port;
|
||||
char type[8];
|
||||
char ip_address[NSAPI_IP_SIZE + 1];
|
||||
|
||||
tr_debug("QUECTEL_M26_CellularStack:%s:%u:[%d]", __FUNCTION__, __LINE__, size);
|
||||
_at.cmd_start("AT+QIRD=");
|
||||
_at.write_int(0); /* at+qifgcnt 0-1 */
|
||||
_at.write_int(1); /* 1-Client, 2-Server */
|
||||
_at.write_int(socket->id);
|
||||
_at.write_int(recv_len);
|
||||
_at.cmd_stop();
|
||||
|
||||
_at.resp_start("+QIRD:");
|
||||
if (_at.info_resp()) {
|
||||
_at.set_delimiter(':');
|
||||
_at.read_string(ip_address, sizeof(ip_address));
|
||||
_at.set_default_delimiter();
|
||||
port = _at.read_int();
|
||||
_at.read_string(type, sizeof(type));
|
||||
recv_len_after = _at.read_int();
|
||||
if (recv_len_after > 0) {
|
||||
_at.read_bytes((uint8_t *)buffer, recv_len_after);
|
||||
}
|
||||
}
|
||||
_at.resp_stop();
|
||||
|
||||
if (!recv_len_after || (_at.get_last_error() != NSAPI_ERROR_OK)) {
|
||||
tr_debug("QUECTEL_M26_CellularStack:%s:%u:[ERROR NSAPI_ERROR_WOULD_BLOCK]", __FUNCTION__, __LINE__);
|
||||
return NSAPI_ERROR_WOULD_BLOCK;
|
||||
}
|
||||
|
||||
if (address) {
|
||||
address->set_ip_address(ip_address);
|
||||
address->set_port(port);
|
||||
}
|
||||
|
||||
tr_debug("QUECTEL_M26_CellularStack:%s:%u:[%d]", __FUNCTION__, __LINE__, recv_len_after);
|
||||
return recv_len_after;
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef QUECTEL_M26_CELLULARSTACK_H_
|
||||
#define QUECTEL_M26_CELLULARSTACK_H_
|
||||
|
||||
#include "AT_CellularStack.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
#define M26_SOCKET_MAX 6
|
||||
#define M26_CREATE_SOCKET_TIMEOUT 75000 //75 seconds
|
||||
#define M26_SENT_BYTE_MAX 1460
|
||||
#define M26_RECV_BYTE_MAX 1000
|
||||
|
||||
class QUECTEL_M26_CellularStack : public AT_CellularStack {
|
||||
public:
|
||||
QUECTEL_M26_CellularStack(ATHandler &atHandler, int cid, nsapi_ip_stack_t stack_type);
|
||||
virtual ~QUECTEL_M26_CellularStack();
|
||||
|
||||
protected: // NetworkStack
|
||||
|
||||
virtual nsapi_error_t socket_listen(nsapi_socket_t handle, int backlog);
|
||||
|
||||
virtual nsapi_error_t socket_accept(nsapi_socket_t server,
|
||||
nsapi_socket_t *handle, SocketAddress *address = 0);
|
||||
|
||||
virtual nsapi_error_t socket_bind(nsapi_socket_t handle, const SocketAddress &address);
|
||||
|
||||
virtual nsapi_error_t socket_connect(nsapi_socket_t handle, const SocketAddress &address);
|
||||
|
||||
protected: // AT_CellularStack
|
||||
|
||||
virtual nsapi_error_t socket_stack_init();
|
||||
|
||||
virtual int get_max_socket_count();
|
||||
|
||||
virtual bool is_protocol_supported(nsapi_protocol_t protocol);
|
||||
|
||||
virtual nsapi_error_t socket_close_impl(int sock_id);
|
||||
|
||||
virtual nsapi_error_t create_socket_impl(CellularSocket *socket);
|
||||
|
||||
virtual nsapi_size_or_error_t socket_sendto_impl(CellularSocket *socket, const SocketAddress &address,
|
||||
const void *data, nsapi_size_t size);
|
||||
|
||||
virtual nsapi_size_or_error_t socket_recvfrom_impl(CellularSocket *socket, SocketAddress *address,
|
||||
void *buffer, nsapi_size_t size);
|
||||
|
||||
private:
|
||||
// URC handlers
|
||||
// URC handlers
|
||||
void urc_qiurc();
|
||||
|
||||
void handle_open_socket_response(int &modem_connect_id, int &err);
|
||||
};
|
||||
} // namespace mbed
|
||||
#endif /* QUECTEL_M26_CELLULARSTACK_H_ */
|
|
@ -23,7 +23,7 @@
|
|||
using namespace mbed;
|
||||
using namespace events;
|
||||
|
||||
#ifdef TARGET_UBLOX_C030_R410M
|
||||
#ifdef TARGET_UBLOX_C030_R41XM
|
||||
static const AT_CellularBase::SupportedFeature unsupported_features[] = {
|
||||
AT_CellularBase::AT_CGSN_WITH_TYPE,
|
||||
AT_CellularBase::SUPPORTED_FEATURE_END_MARK
|
||||
|
@ -32,7 +32,7 @@ static const AT_CellularBase::SupportedFeature unsupported_features[] = {
|
|||
|
||||
UBLOX_AT::UBLOX_AT(FileHandle *fh) : AT_CellularDevice(fh)
|
||||
{
|
||||
#ifdef TARGET_UBLOX_C030_R410M
|
||||
#ifdef TARGET_UBLOX_C030_R41XM
|
||||
AT_CellularBase::set_unsupported_features(unsupported_features);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ void UBLOX_AT_CellularContext::do_connect()
|
|||
_cb_data.error = NSAPI_ERROR_NO_CONNECTION;
|
||||
|
||||
// Attempt to establish a connection
|
||||
#ifdef TARGET_UBLOX_C030_R410M
|
||||
#ifdef TARGET_UBLOX_C030_R41XM
|
||||
_cb_data.error = NSAPI_ERROR_OK;
|
||||
#else
|
||||
_cb_data.error = open_data_channel();
|
||||
|
|
|
@ -54,10 +54,10 @@ nsapi_error_t UBLOX_AT_CellularNetwork::set_access_technology_impl(RadioAccessTe
|
|||
break;
|
||||
case RAT_HSDPA_HSUPA:
|
||||
break;
|
||||
#elif defined(TARGET_UBLOX_C030_R410M)
|
||||
#elif defined(TARGET_UBLOX_C030_R41XM)
|
||||
case RAT_CATM1:
|
||||
break;
|
||||
#elif defined(TARGET_UBLOX_C030_R410M) || defined(TARGET_UBLOX_C030_N211)
|
||||
#elif defined(TARGET_UBLOX_C030_R41XM) || defined(TARGET_UBLOX_C030_N211)
|
||||
case RAT_NB1:
|
||||
break;
|
||||
#endif
|
||||
|
|
|
@ -24,5 +24,5 @@ To port your CC 310 driver to Mbed OS on your specific target, do the following:
|
|||
1. In `features/cryptocell/FEATURE_CRYPTOCELL310/TARGET_<target name>`, add your platform-specific libraries for all toolchains in `TOOLCHAIN_ARM`, `TOOLCHAIN_GCC_ARM` and `TOOLCHAIN_IAR` respectively.
|
||||
1. Add your CC setup code:
|
||||
* Implement `crypto_platform_setup()` and `crypto_platform_terminate()` to enable CC on your platform, in case you have board-specific setup functionality, required for CC setup. You MUST call 'SaSi_LibInit()` and 'SaSi_LibFini()' respectively in these functions.
|
||||
* Define `crypto_platform_ctx` in `crypto_platform.h` in a way that suits your implementation.
|
||||
* Define `crypto_platform_ctx` in `crypto_device_platform.h` in a way that suits your implementation.
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include "trng_api.h"
|
||||
#include "mbedtls/platform.h"
|
||||
|
||||
extern mbedtls_platform_context ctx;
|
||||
extern mbedtls_platform_context plat_ctx;
|
||||
static CRYS_RND_WorkBuff_t rndWorkBuff = { { 0 } };
|
||||
|
||||
/* Implementation that should never be optimized out by the compiler */
|
||||
|
@ -49,7 +49,7 @@ CRYSError_t LLF_RND_GetTrngSource(
|
|||
|
||||
void trng_init(trng_t *obj)
|
||||
{
|
||||
RNG_PLAT_SetUserRngParameters(&ctx.platform_impl_ctx.rndState, obj);
|
||||
RNG_PLAT_SetUserRngParameters(&plat_ctx.platform_impl_ctx.rndState, obj);
|
||||
}
|
||||
|
||||
void trng_free(trng_t *obj)
|
||||
|
@ -67,7 +67,7 @@ int trng_get_bytes(trng_t *obj, uint8_t *output, size_t length, size_t *outputLe
|
|||
uint32_t actualLength;
|
||||
|
||||
ret = LLF_RND_GetTrngSource(
|
||||
&ctx.platform_impl_ctx.rndState , /*in/out*/
|
||||
&plat_ctx.platform_impl_ctx.rndState , /*in/out*/
|
||||
obj, /*in/out*/
|
||||
0, /*in*/
|
||||
&entropySizeBits, /*in/out*/
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "entropy.h"
|
||||
#include "platform_mbed.h"
|
||||
#include "mbed_trace.h"
|
||||
#include "ssl_internal.h"
|
||||
|
||||
#define TRACE_GROUP "DEVKEY"
|
||||
|
||||
|
@ -260,12 +261,14 @@ int DeviceKey::generate_key_by_random(uint32_t *output, size_t size)
|
|||
}
|
||||
|
||||
#if DEVICE_TRNG
|
||||
uint32_t test_buff[DEVICE_KEY_32BYTE / sizeof(int)];
|
||||
mbedtls_entropy_context *entropy = new mbedtls_entropy_context;
|
||||
mbedtls_entropy_init(entropy);
|
||||
memset(output, 0, size);
|
||||
memset(test_buff, 0, size);
|
||||
|
||||
ret = mbedtls_entropy_func(entropy, (unsigned char *)output, size);
|
||||
if (ret != MBED_SUCCESS) {
|
||||
if (ret != MBED_SUCCESS || mbedtls_ssl_safer_memcmp(test_buff, (unsigned char *)output, size) == 0) {
|
||||
ret = DEVICEKEY_GENERATE_RANDOM_ERROR;
|
||||
} else {
|
||||
ret = DEVICEKEY_SUCCESS;
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#define __PLATFORM_ALT__
|
||||
#include "platform_mbed.h"
|
||||
#if defined(MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT)
|
||||
#include "crypto_platform.h"
|
||||
#include "crypto_device_platform.h"
|
||||
/**
|
||||
* \brief The platform context structure.
|
||||
*
|
||||
|
|
|
@ -22,30 +22,30 @@
|
|||
#if defined(MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT)
|
||||
#include "mbed_critical.h"
|
||||
|
||||
mbedtls_platform_context ctx = { { 0 } };
|
||||
mbedtls_platform_context plat_ctx = { { 0 } };
|
||||
|
||||
int mbedtls_platform_setup( mbedtls_platform_context *unused_ctx )
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
core_util_atomic_incr_u32( ( volatile uint32_t * )&ctx.reference_count, 1 );
|
||||
core_util_atomic_incr_u32( ( volatile uint32_t * )&plat_ctx.reference_count, 1 );
|
||||
|
||||
if( ctx.reference_count == 1 )
|
||||
if( plat_ctx.reference_count == 1 )
|
||||
{
|
||||
/* call platform specific code to setup crypto driver */
|
||||
ret = crypto_platform_setup( &ctx.platform_impl_ctx );
|
||||
ret = crypto_platform_setup( &plat_ctx.platform_impl_ctx );
|
||||
}
|
||||
return ( ret );
|
||||
}
|
||||
|
||||
void mbedtls_platform_teardown( mbedtls_platform_context *unused_ctx )
|
||||
{
|
||||
core_util_atomic_decr_u32( ( volatile uint32_t * )&ctx.reference_count, 1 );
|
||||
if( ctx.reference_count < 1 )
|
||||
core_util_atomic_decr_u32( ( volatile uint32_t * )&plat_ctx.reference_count, 1 );
|
||||
if( plat_ctx.reference_count < 1 )
|
||||
{
|
||||
/* call platform specific code to terminate crypto driver */
|
||||
crypto_platform_terminate( &ctx.platform_impl_ctx );
|
||||
ctx.reference_count = 0;
|
||||
crypto_platform_terminate( &plat_ctx.platform_impl_ctx );
|
||||
plat_ctx.reference_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -161,6 +161,9 @@
|
|||
},
|
||||
"NCS36510": {
|
||||
"mbed-mesh-api.heap-size": 14000
|
||||
},
|
||||
"KW41Z": {
|
||||
"mbed-mesh-api.heap-size": 14000
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
},
|
||||
"TB_SENSE_12": {
|
||||
"nanostack.configuration": "lowpan_router"
|
||||
},
|
||||
"KW41Z": {
|
||||
"nanostack.configuration": "lowpan_router"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -759,7 +759,7 @@ static void thread_host_child_update_request_process(protocol_interface_info_ent
|
|||
uint64_t pending_timestamp = 0;// means no pending timestamp
|
||||
mac_neighbor_table_entry_t *entry_temp;
|
||||
bool data_request_needed = false;
|
||||
mle_tlv_info_t tlv_info = {0};
|
||||
mle_tlv_info_t tlv_info = {MLE_TYPE_SRC_ADDRESS, 0, 0};
|
||||
|
||||
tr_debug("Child update request");
|
||||
entry_temp = mac_neighbor_entry_get_by_ll64(mac_neighbor_info(cur), mle_msg->packet_src_address, false, NULL);
|
||||
|
@ -831,7 +831,7 @@ static void thread_parse_child_update_response(protocol_interface_info_entry_t *
|
|||
thread_leader_data_t leaderData = {0};
|
||||
uint8_t status;
|
||||
bool leader_data_received;
|
||||
mle_tlv_info_t tlv_info = {0};
|
||||
mle_tlv_info_t tlv_info = {MLE_TYPE_SRC_ADDRESS, 0, 0};
|
||||
|
||||
if (cur->thread_info->thread_endnode_parent == NULL) {
|
||||
return;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (c) 2018 ARM Limited. All rights reserved.
|
||||
* 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 NANOSTACK_PHY_KW41Z_H_
|
||||
#define NANOSTACK_PHY_KW41Z_H_
|
||||
|
||||
#if MBED_CONF_RTOS_PRESENT
|
||||
#include "rtos/rtos.h"
|
||||
#endif
|
||||
#include "NanostackRfPhy.h"
|
||||
#include "fsl_common.h"
|
||||
|
||||
class NanostackRfPhyKw41z : public NanostackRfPhy {
|
||||
public:
|
||||
NanostackRfPhyKw41z();
|
||||
~NanostackRfPhyKw41z();
|
||||
int8_t rf_register();
|
||||
void rf_unregister();
|
||||
void get_mac_address(uint8_t *mac);
|
||||
void set_mac_address(uint8_t *mac);
|
||||
};
|
||||
|
||||
#endif /* NANOSTACK_PHY_KW41Z_H_ */
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue