Import Mbed OS hard-float snapshot
This commit is contained in:
88
TEST_APPS/device/nanostack_mac_tester/README.md
Normal file
88
TEST_APPS/device/nanostack_mac_tester/README.md
Normal file
@@ -0,0 +1,88 @@
|
||||
# Nanostack MAC test application
|
||||
|
||||
You can use this application to test the Nanostack RF driver implementations that follow the [Nanostack RF driver porting instructions](https://os.mbed.com/docs/v5.6/reference/contributing-connectivity.html#porting-new-rf-driver-for-6lowpan-stack). The application has a command-line interface that is used to send commands to Nanostack's MAC layer, for example starting PANs, scanning or sending data. The provided tests do not test performance or stability and only indirectly test RF functionalities.
|
||||
|
||||
## Table of contents
|
||||
|
||||
* [Prerequisites](#prerequisites)
|
||||
* [Setting up the application](#setting-up-the-application)
|
||||
* [Application usage](#application-usage)
|
||||
* [Interactive mode](#interactive-mode)
|
||||
* [Automated mode](#automated-mode)
|
||||
* [Testcases](#testcases)
|
||||
* [Considerations](#considerations)
|
||||
|
||||
## Prerequisites
|
||||
|
||||
* [Mbed CLI](https://github.com/ARMmbed/mbed-cli).
|
||||
* Mbed OS target board with build in radio, OR RF shield with Mbed OS driver
|
||||
|
||||
## Setting up the application
|
||||
|
||||
### Add your RF driver
|
||||
|
||||
When using RF shield, you need to configure it to be a default RF driver and instruct Mbed OS that RF driver is present. For example, configuring Atmel RF driver to provide default driver:
|
||||
|
||||
```
|
||||
"target_overrides": {
|
||||
"*": {
|
||||
"target.device_has_add": ["802_15_4_RF_PHY"],
|
||||
"atmel-rf.provide-default": true
|
||||
```
|
||||
|
||||
### Checking platform support
|
||||
|
||||
Check that your choice of platform is supported by your choice of toolchain:
|
||||
|
||||
```
|
||||
mbed compile --supported
|
||||
```
|
||||
|
||||
<span class="notes">**Note:** Targets are often abbreviated from the full model names. In the case of `FRDM-K64F` the target is `K64F`.</span>
|
||||
|
||||
## Run tests
|
||||
|
||||
You can use this application in interactive or automated mode.
|
||||
|
||||
### Interactive mode
|
||||
|
||||
To set the application to interactive mode:
|
||||
|
||||
1. Build the application.
|
||||
```
|
||||
mbed test --compile --icetea -t TOOLCHAIN -m TARGET_PLATFORM -DICETEA_MAC_TESTER_ENABLED --test-config NANOSTACK_MAC_TESTER -n address_read_and_write,send_data,send_data_indirect,send_large_payloads,create_and_join_PAN,ED_scan
|
||||
```
|
||||
2. Connect your board and copy the compiled application binary from the `BUILD/tests/TARGET_PLATFORM/TOOLCHAIN/TEST_APPS/device/nanostack_mac_tester/` folder to the board.
|
||||
3. Wait for the device to flash the binary.
|
||||
4. Open a serial connection with a program such as PuTTY, screen or minicom. The default baudrate is 115200.
|
||||
5. Press the reset button on the board. The Arm Mbed logo and trace appears in the terminal window.
|
||||
|
||||
If the driver registration and SW MAC creation was successful, the application is ready to receive commands.
|
||||
|
||||
To start off, type `help` to list all commands available and furthermore `help <command>` to print detailed information about a specific command.
|
||||
|
||||
### Automated mode
|
||||
|
||||
```
|
||||
mbed test --clean --compile --run --icetea -t TOOLCHAIN -m TARGET_PLATFORM -DICETEA_MAC_TESTER_ENABLED --test-config NANOSTACK_MAC_TESTER -n address_read_and_write,send_data,send_data_indirect,send_large_payloads,create_and_join_PAN,ED_scan
|
||||
```
|
||||
|
||||
Many of the provided testcases have a `self.channel` variable in the `setUp()` function for setting the RF channel. The default channel is 11. If you wish to run a test on another channel, you will need to change it manually in TEST_APPS/testcases/nanostack_mac_tester/.
|
||||
|
||||
Some testcases also use a secondary channel for transmitting and will use the next higher channel for that purpose. If the given channel is 26, the secondary channel will default to 25.
|
||||
|
||||
### Test cases
|
||||
|
||||
The automated test set runs the following testcases included in the repository under `TEST_APPS/testcases/nanostack_mac_tester/`.
|
||||
* Create and join PAN
|
||||
* Direct data transmission(Transmission between two devices)
|
||||
* Indirect data transmission(Transmission between two devices with one device acting as intermediary)
|
||||
* ED scan(Energy Density scanning)
|
||||
* Address read and write
|
||||
* Large data transmission
|
||||
|
||||
### Considerations
|
||||
|
||||
* Devices need to be power cycled if they are unresponsive to test framework commands even after resetting.
|
||||
* Devices can be enclosed in an RF isolation box to improve the consistency of test results.
|
||||
* Some boards and radio modules come with a PCB trace antenna, instead of an SMD antenna, and need to be spaced further apart to decrease interference.
|
||||
156
TEST_APPS/device/nanostack_mac_tester/main.cpp
Normal file
156
TEST_APPS/device/nanostack_mac_tester/main.cpp
Normal file
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Arm Limited and affiliates.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "mbed.h"
|
||||
#include "rtos.h"
|
||||
#include "sw_mac.h"
|
||||
#include "ns_hal_init.h"
|
||||
#define MBED_CMDLINE_MAX_LINE_LENGTH 250
|
||||
#include "ns_cmdline.h"
|
||||
|
||||
#include "mac_commands.h"
|
||||
|
||||
#define HEAP_FOR_MAC_TESTER_SIZE 10000
|
||||
#define RX_BUFFER_SIZE 512
|
||||
|
||||
#define ATMEL 1
|
||||
#define MCR20 2
|
||||
#define OTHER 3
|
||||
|
||||
#define TRACE_GROUP "Main"
|
||||
#include "mbed-trace/mbed_trace.h"
|
||||
|
||||
#include "NanostackRfPhy.h"
|
||||
|
||||
#if !DEVICE_802_15_4_PHY
|
||||
#error [NOT_SUPPORTED] No 802.15.4 RF driver found for this target
|
||||
#endif
|
||||
|
||||
#ifndef ICETEA_MAC_TESTER_ENABLED
|
||||
#error [NOT_SUPPORTED] Skipping Nanostack MAC tester application.
|
||||
#endif
|
||||
|
||||
extern mac_api_s *mac_interface;
|
||||
UnbufferedSerial pc(USBTX, USBRX);
|
||||
osThreadId_t main_thread;
|
||||
static CircularBuffer<uint8_t, RX_BUFFER_SIZE> rx_buffer;
|
||||
static uint8_t ns_heap[HEAP_FOR_MAC_TESTER_SIZE];
|
||||
|
||||
static void app_heap_error_handler(heap_fail_t event)
|
||||
{
|
||||
tr_error("Heap error (%d), app_heap_error_handler()", event);
|
||||
switch (event) {
|
||||
case NS_DYN_MEM_NULL_FREE:
|
||||
case NS_DYN_MEM_DOUBLE_FREE:
|
||||
case NS_DYN_MEM_ALLOCATE_SIZE_NOT_VALID:
|
||||
case NS_DYN_MEM_POINTER_NOT_VALID:
|
||||
case NS_DYN_MEM_HEAP_SECTOR_CORRUPTED:
|
||||
case NS_DYN_MEM_HEAP_SECTOR_UNITIALIZED:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
while (1);
|
||||
}
|
||||
|
||||
static void rx_interrupt(void)
|
||||
{
|
||||
uint8_t c;
|
||||
pc.read(&c, 1);
|
||||
rx_buffer.push(c);
|
||||
if (main_thread != NULL) {
|
||||
osThreadFlagsSet(main_thread, 1);
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_rx_data(void)
|
||||
{
|
||||
bool exit = false;
|
||||
uint8_t data;
|
||||
|
||||
while (1) {
|
||||
exit = !rx_buffer.pop(data);
|
||||
if (exit) {
|
||||
break;
|
||||
}
|
||||
cmd_char_input(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int mac_prepare(void)
|
||||
{
|
||||
NanostackRfPhy &rf_phy = NanostackRfPhy::get_default_instance();
|
||||
int8_t rf_driver_id = rf_phy.rf_register();
|
||||
uint8_t rf_eui64[8];
|
||||
|
||||
if (rf_driver_id < 0) {
|
||||
tr_error("Failed to register RF driver.");
|
||||
return -1;
|
||||
}
|
||||
rf_phy.get_mac_address(rf_eui64);
|
||||
mac_description_storage_size_t mac_description;
|
||||
mac_description.device_decription_table_size = DEVICE_DESCRIPTOR_TABLE_SIZE; /** MAC Device description list size */
|
||||
mac_description.key_description_table_size = KEY_DESCRIPTOR_TABLE_SIZE; /** MAC Key description list size */
|
||||
mac_description.key_lookup_size = LOOKUP_DESCRIPTOR_TABLE_SIZE; /** Key description key lookup list size */
|
||||
mac_description.key_usage_size = USAGE_DESCRIPTOR_TABLE_SIZE; /** Key description key usage list size */
|
||||
tr_info("Registered RF driver with id: %hhu, EUI64: %s", rf_driver_id, mbed_trace_array(rf_eui64, 8));
|
||||
mac_interface = ns_sw_mac_create(rf_driver_id, &mac_description);
|
||||
if (!mac_interface) {
|
||||
tr_error("Failed to create SW MAC.");
|
||||
return -2;
|
||||
}
|
||||
|
||||
return mac_interface->mac_initialize(mac_interface, mac_data_confirm_handler,
|
||||
mac_data_indication_handler, mac_purge_confirm_handler, mac_mlme_confirm_handler,
|
||||
mac_mlme_indication_handler, rf_driver_id);
|
||||
}
|
||||
|
||||
static void cmd_ready_cb(int retcode)
|
||||
{
|
||||
cmd_next(retcode);
|
||||
}
|
||||
|
||||
static void trace_printer(const char *str)
|
||||
{
|
||||
printf("%s\n", str);
|
||||
cmd_output();
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
main_thread = ThisThread::get_id();
|
||||
pc.baud(MBED_CONF_PLATFORM_STDIO_BAUD_RATE);
|
||||
pc.attach(rx_interrupt);
|
||||
ns_hal_init(ns_heap, HEAP_FOR_MAC_TESTER_SIZE, app_heap_error_handler, NULL);
|
||||
mbed_trace_init();
|
||||
mbed_trace_print_function_set(trace_printer);
|
||||
cmd_init(&default_cmd_response_out);
|
||||
cmd_set_ready_cb(cmd_ready_cb);
|
||||
mac_commands_init();
|
||||
|
||||
if (mac_prepare() != 0) {
|
||||
return -1;
|
||||
}
|
||||
tr_info("Created driver & SW MAC");
|
||||
|
||||
while (true) {
|
||||
ThisThread::flags_wait_any(1);
|
||||
handle_rx_data();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
16
TEST_APPS/device/nanostack_mac_tester/mbed_app.json
Normal file
16
TEST_APPS/device/nanostack_mac_tester/mbed_app.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"macros": ["MBED_TRACE_LINE_LENGTH=200", "OS_TASKCNT=4", "OS_IDLESTKSIZE=32"],
|
||||
"target_overrides": {
|
||||
"*": {
|
||||
"nanostack.configuration": "lowpan_host",
|
||||
"platform.stdio-convert-newlines": true,
|
||||
"platform.stdio-baud-rate": 115200,
|
||||
"mbed-mesh-api.heap-size": 6000,
|
||||
"nanostack-hal.event_loop_thread_stack_size": 2000,
|
||||
"mbed-trace.enable": true,
|
||||
"nsapi.default-stack": "LWIP",
|
||||
"target.device_has_add": ["802_15_4_PHY"],
|
||||
"atmel-rf.provide-default": true
|
||||
}
|
||||
}
|
||||
}
|
||||
1654
TEST_APPS/device/nanostack_mac_tester/source/mac_commands.cpp
Normal file
1654
TEST_APPS/device/nanostack_mac_tester/source/mac_commands.cpp
Normal file
File diff suppressed because it is too large
Load Diff
65
TEST_APPS/device/nanostack_mac_tester/source/mac_commands.h
Normal file
65
TEST_APPS/device/nanostack_mac_tester/source/mac_commands.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Arm Limited and affiliates.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MAC_COMMANDS_H_
|
||||
#define MAC_COMMANDS_H_
|
||||
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "ns_cmdline.h"
|
||||
#include "nsdynmemLIB.h"
|
||||
#include "mbed_trace.h"
|
||||
#include "mac_api.h"
|
||||
#include "mlme.h"
|
||||
#include "mac_mcps.h"
|
||||
#include "mac_common_defines.h"
|
||||
#include "mac_filter_api.h"
|
||||
#include "mac_tester_util.h"
|
||||
|
||||
#define LOOKUP_DESCRIPTOR_TABLE_SIZE 2
|
||||
#define DEVICE_DESCRIPTOR_TABLE_SIZE 2
|
||||
#define USAGE_DESCRIPTOR_TABLE_SIZE 2
|
||||
#define KEY_DESCRIPTOR_TABLE_SIZE 2
|
||||
|
||||
void mac_commands_init(void);
|
||||
|
||||
void mac_data_confirm_handler(const mac_api_t *api, const mcps_data_conf_t *data);
|
||||
void mac_data_indication_handler(const mac_api_t *api, const mcps_data_ind_t *data);
|
||||
void mac_purge_confirm_handler(const mac_api_t *api, mcps_purge_conf_t *data);
|
||||
void mac_mlme_confirm_handler(const mac_api_t *api, mlme_primitive id, const void *data);
|
||||
void mac_mlme_indication_handler(const mac_api_t *api, mlme_primitive id, const void *data);
|
||||
|
||||
int mac_start_command(int argc, char *argv[]);
|
||||
int mac_scan_command(int argc, char *argv[]);
|
||||
int mac_data_command(int argc, char *argv[]);
|
||||
int mac_poll_command(int argc, char *argv[]);
|
||||
int mac_purge_command(int argc, char *argv[]);
|
||||
int mac_set_command(int argc, char *argv[]);
|
||||
int mac_get_command(int argc, char *argv[]);
|
||||
int mac_reset_command(int argc, char *argv[]);
|
||||
int mac_address_command(int argc, char *argv[]);
|
||||
int mac_key_command(int argc, char *argv[]);
|
||||
int mac_add_neighbour_command(int argc, char *argv[]);
|
||||
int mac_filter_command(int argc, char *argv[]);
|
||||
int mac_config_status_command(int argc, char *argv[]);
|
||||
int mac_find_beacon_command(int argc, char *argv[]);
|
||||
int mac_wait_command(int argc, char *argv[]);
|
||||
int mac_analyze_ed_command(int argc, char *argv[]);
|
||||
int reset_command(int argc, char *argv[]);
|
||||
int silent_mode_command(int argc, char *argv[]);
|
||||
|
||||
#endif
|
||||
124
TEST_APPS/device/nanostack_mac_tester/source/mac_tester_util.cpp
Normal file
124
TEST_APPS/device/nanostack_mac_tester/source/mac_tester_util.cpp
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Arm Limited and affiliates.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "mac_tester_util.h"
|
||||
|
||||
int string_to_bytes(const char *str, uint8_t *buf, int bytes)
|
||||
{
|
||||
int len = strlen(str);
|
||||
|
||||
if (len <= (3 * bytes - 1)) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < bytes; ++i) {
|
||||
if (i * 3 < len) {
|
||||
buf[i] = (uint8_t)strtoul(str + i * 3, NULL, 16);
|
||||
} else {
|
||||
buf[i] = 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *mlme_status_string(uint8_t status)
|
||||
{
|
||||
switch (status) {
|
||||
case MLME_SUCCESS:
|
||||
return "MLME_SUCCESS";
|
||||
case MLME_BUSY_CHAN:
|
||||
return "MLME_BUSY_CHAN";
|
||||
case MLME_BUSY_RX:
|
||||
return "MLME_BUSY_RX";
|
||||
case MLME_BUSY_TX:
|
||||
return "MLME_BUSY_TX";
|
||||
case MLME_FORCE_TRX_OFF:
|
||||
return "MLME_FORCE_TRX_OFF";
|
||||
case MLME_IDLE:
|
||||
return "MLME_IDLE";
|
||||
case MLME_RX_ON:
|
||||
return "MLME_RX_ON";
|
||||
case MLME_TRX_OFF:
|
||||
return "MLME_TRX_OFF";
|
||||
case MLME_TX_ON:
|
||||
return "MLME_TX_ON";
|
||||
case MLME_COUNTER_ERROR:
|
||||
return "MLME_COUNTER_ERROR";
|
||||
case MLME_IMPROPER_KEY_TYPE:
|
||||
return "MLME_IMPROPER_KEY_TYPE";
|
||||
case MLME_IMPROPER_SECURITY_LEVEL:
|
||||
return "MLME_IMPROPER_SECURITY_LEVEL";
|
||||
case MLME_UNSUPPORTED_LEGACY:
|
||||
return "MLME_UNSUPPORTED_LEGACY";
|
||||
case MLME_UNSUPPORTED_SECURITY:
|
||||
return "MLME_UNSUPPORTED_SECURITY";
|
||||
case MLME_SECURITY_FAIL:
|
||||
return "MLME_SECURITY_FAIL";
|
||||
case MLME_FRAME_TOO_LONG:
|
||||
return "MLME_FRAME_TOO_LONG";
|
||||
case MLME_INVALID_HANDLE:
|
||||
return "MLME_INVALID_HANDLE";
|
||||
case MLME_INVALID_PARAMETER:
|
||||
return "MLME_INVALID_PARAMETER";
|
||||
case MLME_TX_NO_ACK:
|
||||
return "MLME_TX_NO_ACK";
|
||||
case MLME_NO_BEACON:
|
||||
return "MLME_NO_BEACON";
|
||||
case MLME_NO_DATA:
|
||||
return "MLME_NO_DATA";
|
||||
case MLME_NO_SHORT_ADDRESS:
|
||||
return "MLME_NO_SHORT_ADDRESS";
|
||||
case MLME_PAN_ID_CONFLICT:
|
||||
return "MLME_PAN_ID_CONFLICT";
|
||||
case MLME_TRANSACTION_EXPIRED:
|
||||
return "MLME_TRANSACTION_EXPIRED";
|
||||
case MLME_TRANSACTION_OVERFLOW:
|
||||
return "MLME_TRANSACTION_OVERFLOW";
|
||||
case MLME_UNAVAILABLE_KEY:
|
||||
return "MLME_UNAVAILABLE_KEY";
|
||||
case MLME_UNSUPPORTED_ATTRIBUTE:
|
||||
return "MLME_UNSUPPORTED_ATTRIBUTE";
|
||||
case MLME_INVALID_ADDRESS:
|
||||
return "MLME_INVALID_ADDRESS";
|
||||
case MLME_INVALID_INDEX:
|
||||
return "MLME_INVALID_INDEX";
|
||||
case MLME_LIMIT_REACHED:
|
||||
return "MLME_LIMIT_REACHED";
|
||||
case MLME_READ_ONLY:
|
||||
return "MLME_READ_ONLY";
|
||||
case MLME_SCAN_IN_PROGRESS:
|
||||
return "MLME_SCAN_IN_PROGRESS";
|
||||
case MLME_DATA_POLL_NOTIFICATION:
|
||||
return "MLME_DATA_POLL_NOTIFICATION";
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int channel_from_mask(uint32_t channel_mask, int index)
|
||||
{
|
||||
int expected_index = 0;
|
||||
for (int i = 0; i < 27; ++i) {
|
||||
if ((channel_mask >> i) & 1) {
|
||||
if (expected_index == index) {
|
||||
return i;
|
||||
}
|
||||
++expected_index;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Arm Limited and affiliates.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef UTIL_H_
|
||||
#define UTIL_H_
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#include "mbed.h"
|
||||
#include "mlme.h"
|
||||
|
||||
int string_to_bytes(const char *str, uint8_t *buf, int bytes);
|
||||
const char *mlme_status_string(uint8_t status);
|
||||
int channel_from_mask(uint32_t channel_mask, int index);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user