bsim: Add EDTT hci test app

adopted from Zephyr.
This commit is contained in:
Magdalena Kasenberg
2022-02-19 15:02:07 +01:00
committed by Andrzej Kaczmarek
parent e58e71271b
commit fd3b1466d7
14 changed files with 2043 additions and 1 deletions
+32
View File
@@ -0,0 +1,32 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
#
pkg.name: babblesim/edtt/hci_test
pkg.type: app
pkg.description: nRF52 on BabbleSim - EDTT tester
pkg.author: "Codecoup"
pkg.homepage: "http://mynewt.apache.org/"
pkg.keywords:
pkg.deps:
- "@apache-mynewt-core/sys/console/stub"
- "@apache-mynewt-core/sys/log/stub"
- "@apache-mynewt-core/sys/stats/full"
- "@apache-mynewt-core/kernel/os"
- nimble/transport
- babblesim/edtt/hci_transport
+45
View File
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2021 Codecoup
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 "os/mynewt.h"
#include "ble_hci_edtt.h"
static int
main_fn(int argc, char **argv)
{
sysinit();
edtt_init();
while (1) {
os_eventq_run(os_eventq_dflt_get());
}
return 0;
}
int
main(int argc, char **argv)
{
extern void bsim_init(int argc, char** argv, void *main_fn);
bsim_init(argc, argv, main_fn);
return 0;
}
+30
View File
@@ -0,0 +1,30 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
#
syscfg.vals:
BLE_HOST: 0
BLE_HCI_TRANSPORT: custom
# EDTT requires 0x123456789ABC address for first device
# and 0x456789ABCDEF for second
BLE_LL_PUBLIC_DEV_ADDR: 0x123456789ABC
# BLE_LL_PUBLIC_DEV_ADDR: 0x456789ABCDEF
# For LL/CON/ADV/BV-09-C, LL/CON/ADV/BV-10-C
BLE_LL_CFG_FEAT_LE_CSA2: 1
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2021 Codecoup
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 H_BLE_HCI_EDTT_
#define H_BLE_HCI_EDTT_
#ifdef __cplusplus
extern "C" {
#endif
int edtt_init(void);
#ifdef __cplusplus
}
#endif
#endif
@@ -0,0 +1,242 @@
/*
* Copyright (c) 2019 Oticon A/S
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef EDDT_APP_COMMANDS_H
#define EDDT_APP_COMMANDS_H
enum commands_t {
CMD_NOTHING = 0,
CMD_ECHO_REQ,
CMD_ECHO_RSP,
CMD_INQUIRE_REQ,
CMD_INQUIRE_RSP,
CMD_DISCONNECT_REQ,
CMD_DISCONNECT_RSP,
CMD_READ_REMOTE_VERSION_INFORMATION_REQ,
CMD_READ_REMOTE_VERSION_INFORMATION_RSP,
CMD_SET_EVENT_MASK_REQ,
CMD_SET_EVENT_MASK_RSP,
CMD_RESET_REQ,
CMD_RESET_RSP,
CMD_READ_TRANSMIT_POWER_LEVEL_REQ,
CMD_READ_TRANSMIT_POWER_LEVEL_RSP,
CMD_SET_CONTROLLER_TO_HOST_FLOW_CONTROL_REQ,
CMD_SET_CONTROLLER_TO_HOST_FLOW_CONTROL_RSP,
CMD_HOST_BUFFER_SIZE_REQ,
CMD_HOST_BUFFER_SIZE_RSP,
CMD_HOST_NUMBER_OF_COMPLETED_PACKETS_REQ,
CMD_HOST_NUMBER_OF_COMPLETED_PACKETS_RSP,
CMD_SET_EVENT_MASK_PAGE_2_REQ,
CMD_SET_EVENT_MASK_PAGE_2_RSP,
CMD_WRITE_LE_HOST_SUPPORT_REQ,
CMD_WRITE_LE_HOST_SUPPORT_RSP,
CMD_READ_AUTHENTICATED_PAYLOAD_TIMEOUT_REQ,
CMD_READ_AUTHENTICATED_PAYLOAD_TIMEOUT_RSP,
CMD_WRITE_AUTHENTICATED_PAYLOAD_TIMEOUT_REQ,
CMD_WRITE_AUTHENTICATED_PAYLOAD_TIMEOUT_RSP,
CMD_READ_LOCAL_VERSION_INFORMATION_REQ,
CMD_READ_LOCAL_VERSION_INFORMATION_RSP,
CMD_READ_LOCAL_SUPPORTED_COMMANDS_REQ,
CMD_READ_LOCAL_SUPPORTED_COMMANDS_RSP,
CMD_READ_LOCAL_SUPPORTED_FEATURES_REQ,
CMD_READ_LOCAL_SUPPORTED_FEATURES_RSP,
CMD_READ_BUFFER_SIZE_REQ,
CMD_READ_BUFFER_SIZE_RSP,
CMD_READ_BD_ADDR_REQ,
CMD_READ_BD_ADDR_RSP,
CMD_READ_RSSI_REQ,
CMD_READ_RSSI_RSP,
CMD_LE_SET_EVENT_MASK_REQ,
CMD_LE_SET_EVENT_MASK_RSP,
CMD_LE_READ_BUFFER_SIZE_REQ,
CMD_LE_READ_BUFFER_SIZE_RSP,
CMD_LE_READ_LOCAL_SUPPORTED_FEATURES_REQ,
CMD_LE_READ_LOCAL_SUPPORTED_FEATURES_RSP,
CMD_LE_SET_RANDOM_ADDRESS_REQ,
CMD_LE_SET_RANDOM_ADDRESS_RSP,
CMD_LE_SET_ADVERTISING_PARAMETERS_REQ,
CMD_LE_SET_ADVERTISING_PARAMETERS_RSP,
CMD_LE_READ_ADVERTISING_CHANNEL_TX_POWER_REQ,
CMD_LE_READ_ADVERTISING_CHANNEL_TX_POWER_RSP,
CMD_LE_SET_ADVERTISING_DATA_REQ,
CMD_LE_SET_ADVERTISING_DATA_RSP,
CMD_LE_SET_SCAN_RESPONSE_DATA_REQ,
CMD_LE_SET_SCAN_RESPONSE_DATA_RSP,
CMD_LE_SET_ADVERTISING_ENABLE_REQ,
CMD_LE_SET_ADVERTISING_ENABLE_RSP,
CMD_LE_SET_SCAN_PARAMETERS_REQ,
CMD_LE_SET_SCAN_PARAMETERS_RSP,
CMD_LE_SET_SCAN_ENABLE_REQ,
CMD_LE_SET_SCAN_ENABLE_RSP,
CMD_LE_CREATE_CONNECTION_REQ,
CMD_LE_CREATE_CONNECTION_RSP,
CMD_LE_CREATE_CONNECTION_CANCEL_REQ,
CMD_LE_CREATE_CONNECTION_CANCEL_RSP,
CMD_LE_READ_FILTER_ACCEPT_LIST_SIZE_REQ,
CMD_LE_READ_FILTER_ACCEPT_LIST_SIZE_RSP,
CMD_LE_CLEAR_FILTER_ACCEPT_LIST_REQ,
CMD_LE_CLEAR_FILTER_ACCEPT_LIST_RSP,
CMD_LE_ADD_DEVICE_TO_FILTER_ACCEPT_LIST_REQ,
CMD_LE_ADD_DEVICE_TO_FILTER_ACCEPT_LIST_RSP,
CMD_LE_REMOVE_DEVICE_FROM_FILTER_ACCEPT_LIST_REQ,
CMD_LE_REMOVE_DEVICE_FROM_FILTER_ACCEPT_LIST_RSP,
CMD_LE_CONNECTION_UPDATE_REQ,
CMD_LE_CONNECTION_UPDATE_RSP,
CMD_LE_SET_HOST_CHANNEL_CLASSIFICATION_REQ,
CMD_LE_SET_HOST_CHANNEL_CLASSIFICATION_RSP,
CMD_LE_READ_CHANNEL_MAP_REQ,
CMD_LE_READ_CHANNEL_MAP_RSP,
CMD_LE_READ_REMOTE_FEATURES_REQ,
CMD_LE_READ_REMOTE_FEATURES_RSP,
CMD_LE_ENCRYPT_REQ,
CMD_LE_ENCRYPT_RSP,
CMD_LE_RAND_REQ,
CMD_LE_RAND_RSP,
CMD_LE_START_ENCRYPTION_REQ,
CMD_LE_START_ENCRYPTION_RSP,
CMD_LE_LONG_TERM_KEY_REQUEST_REPLY_REQ,
CMD_LE_LONG_TERM_KEY_REQUEST_REPLY_RSP,
CMD_LE_LONG_TERM_KEY_REQUEST_NEGATIVE_REPLY_REQ,
CMD_LE_LONG_TERM_KEY_REQUEST_NEGATIVE_REPLY_RSP,
CMD_LE_READ_SUPPORTED_STATES_REQ,
CMD_LE_READ_SUPPORTED_STATES_RSP,
CMD_LE_RECEIVER_TEST_REQ,
CMD_LE_RECEIVER_TEST_RSP,
CMD_LE_TRANSMITTER_TEST_REQ,
CMD_LE_TRANSMITTER_TEST_RSP,
CMD_LE_TEST_END_REQ,
CMD_LE_TEST_END_RSP,
CMD_LE_REMOTE_CONNECTION_PARAMETER_REQUEST_REPLY_REQ,
CMD_LE_REMOTE_CONNECTION_PARAMETER_REQUEST_REPLY_RSP,
CMD_LE_REMOTE_CONNECTION_PARAMETER_REQUEST_NEGATIVE_REPLY_REQ,
CMD_LE_REMOTE_CONNECTION_PARAMETER_REQUEST_NEGATIVE_REPLY_RSP,
CMD_LE_SET_DATA_LENGTH_REQ,
CMD_LE_SET_DATA_LENGTH_RSP,
CMD_LE_READ_SUGGESTED_DEFAULT_DATA_LENGTH_REQ,
CMD_LE_READ_SUGGESTED_DEFAULT_DATA_LENGTH_RSP,
CMD_LE_WRITE_SUGGESTED_DEFAULT_DATA_LENGTH_REQ,
CMD_LE_WRITE_SUGGESTED_DEFAULT_DATA_LENGTH_RSP,
CMD_LE_READ_LOCAL_P_256_PUBLIC_KEY_COMMAND_REQ,
CMD_LE_READ_LOCAL_P_256_PUBLIC_KEY_COMMAND_RSP,
CMD_LE_GENERATE_DHKEY_COMMAND_REQ,
CMD_LE_GENERATE_DHKEY_COMMAND_RSP,
CMD_LE_ADD_DEVICE_TO_RESOLVING_LIST_REQ,
CMD_LE_ADD_DEVICE_TO_RESOLVING_LIST_RSP,
CMD_LE_REMOVE_DEVICE_FROM_RESOLVING_LIST_REQ,
CMD_LE_REMOVE_DEVICE_FROM_RESOLVING_LIST_RSP,
CMD_LE_CLEAR_RESOLVING_LIST_REQ,
CMD_LE_CLEAR_RESOLVING_LIST_RSP,
CMD_LE_READ_RESOLVING_LIST_SIZE_REQ,
CMD_LE_READ_RESOLVING_LIST_SIZE_RSP,
CMD_LE_READ_PEER_RESOLVABLE_ADDRESS_REQ,
CMD_LE_READ_PEER_RESOLVABLE_ADDRESS_RSP,
CMD_LE_READ_LOCAL_RESOLVABLE_ADDRESS_REQ,
CMD_LE_READ_LOCAL_RESOLVABLE_ADDRESS_RSP,
CMD_LE_SET_ADDRESS_RESOLUTION_ENABLE_REQ,
CMD_LE_SET_ADDRESS_RESOLUTION_ENABLE_RSP,
CMD_LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT_REQ,
CMD_LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT_RSP,
CMD_LE_READ_MAXIMUM_DATA_LENGTH_REQ,
CMD_LE_READ_MAXIMUM_DATA_LENGTH_RSP,
CMD_LE_READ_PHY_REQ,
CMD_LE_READ_PHY_RSP,
CMD_LE_SET_DEFAULT_PHY_REQ,
CMD_LE_SET_DEFAULT_PHY_RSP,
CMD_LE_SET_PHY_REQ,
CMD_LE_SET_PHY_RSP,
CMD_LE_ENHANCED_RECEIVER_TEST_REQ,
CMD_LE_ENHANCED_RECEIVER_TEST_RSP,
CMD_LE_ENHANCED_TRANSMITTER_TEST_REQ,
CMD_LE_ENHANCED_TRANSMITTER_TEST_RSP,
CMD_LE_SET_EXTENDED_ADVERTISING_PARAMETERS_REQ,
CMD_LE_SET_EXTENDED_ADVERTISING_PARAMETERS_RSP,
CMD_LE_SET_EXTENDED_ADVERTISING_DATA_REQ,
CMD_LE_SET_EXTENDED_ADVERTISING_DATA_RSP,
CMD_LE_SET_EXTENDED_SCAN_RESPONSE_DATA_REQ,
CMD_LE_SET_EXTENDED_SCAN_RESPONSE_DATA_RSP,
CMD_LE_SET_EXTENDED_ADVERTISING_ENABLE_REQ,
CMD_LE_SET_EXTENDED_ADVERTISING_ENABLE_RSP,
CMD_LE_READ_MAXIMUM_ADVERTISING_DATA_LENGTH_REQ,
CMD_LE_READ_MAXIMUM_ADVERTISING_DATA_LENGTH_RSP,
CMD_LE_READ_NUMBER_OF_SUPPORTED_ADVERTISING_SETS_REQ,
CMD_LE_READ_NUMBER_OF_SUPPORTED_ADVERTISING_SETS_RSP,
CMD_LE_REMOVE_ADVERTISING_SET_REQ,
CMD_LE_REMOVE_ADVERTISING_SET_RSP,
CMD_LE_CLEAR_ADVERTISING_SETS_REQ,
CMD_LE_CLEAR_ADVERTISING_SETS_RSP,
CMD_LE_SET_PERIODIC_ADVERTISING_PARAMETERS_REQ,
CMD_LE_SET_PERIODIC_ADVERTISING_PARAMETERS_RSP,
CMD_LE_SET_PERIODIC_ADVERTISING_DATA_REQ,
CMD_LE_SET_PERIODIC_ADVERTISING_DATA_RSP,
CMD_LE_SET_PERIODIC_ADVERTISING_ENABLE_REQ,
CMD_LE_SET_PERIODIC_ADVERTISING_ENABLE_RSP,
CMD_LE_SET_EXTENDED_SCAN_PARAMETERS_REQ,
CMD_LE_SET_EXTENDED_SCAN_PARAMETERS_RSP,
CMD_LE_SET_EXTENDED_SCAN_ENABLE_REQ,
CMD_LE_SET_EXTENDED_SCAN_ENABLE_RSP,
CMD_LE_EXTENDED_CREATE_CONNECTION_REQ,
CMD_LE_EXTENDED_CREATE_CONNECTION_RSP,
CMD_LE_PERIODIC_ADVERTISING_CREATE_SYNC_REQ,
CMD_LE_PERIODIC_ADVERTISING_CREATE_SYNC_RSP,
CMD_LE_PERIODIC_ADVERTISING_CREATE_SYNC_CANCEL_REQ,
CMD_LE_PERIODIC_ADVERTISING_CREATE_SYNC_CANCEL_RSP,
CMD_LE_PERIODIC_ADVERTISING_TERMINATE_SYNC_REQ,
CMD_LE_PERIODIC_ADVERTISING_TERMINATE_SYNC_RSP,
CMD_LE_ADD_DEVICE_TO_PERIODIC_ADVERTISER_LIST_REQ,
CMD_LE_ADD_DEVICE_TO_PERIODIC_ADVERTISER_LIST_RSP,
CMD_LE_REMOVE_DEVICE_FROM_PERIODIC_ADVERTISER_LIST_REQ,
CMD_LE_REMOVE_DEVICE_FROM_PERIODIC_ADVERTISER_LIST_RSP,
CMD_LE_CLEAR_PERIODIC_ADVERTISER_LIST_REQ,
CMD_LE_CLEAR_PERIODIC_ADVERTISER_LIST_RSP,
CMD_LE_READ_PERIODIC_ADVERTISER_LIST_SIZE_REQ,
CMD_LE_READ_PERIODIC_ADVERTISER_LIST_SIZE_RSP,
CMD_LE_READ_TRANSMIT_POWER_REQ,
CMD_LE_READ_TRANSMIT_POWER_RSP,
CMD_LE_READ_RF_PATH_COMPENSATION_REQ,
CMD_LE_READ_RF_PATH_COMPENSATION_RSP,
CMD_LE_WRITE_RF_PATH_COMPENSATION_REQ,
CMD_LE_WRITE_RF_PATH_COMPENSATION_RSP,
CMD_LE_SET_PRIVACY_MODE_REQ,
CMD_LE_SET_PRIVACY_MODE_RSP,
CMD_WRITE_BD_ADDR_REQ,
CMD_WRITE_BD_ADDR_RSP,
CMD_FLUSH_EVENTS_REQ,
CMD_FLUSH_EVENTS_RSP,
CMD_HAS_EVENT_REQ,
CMD_HAS_EVENT_RSP,
CMD_GET_EVENT_REQ,
CMD_GET_EVENT_RSP,
CMD_LE_FLUSH_DATA_REQ,
CMD_LE_FLUSH_DATA_RSP,
CMD_LE_DATA_READY_REQ,
CMD_LE_DATA_READY_RSP,
CMD_LE_DATA_WRITE_REQ,
CMD_LE_DATA_WRITE_RSP,
CMD_LE_DATA_READ_REQ,
CMD_LE_DATA_READ_RSP,
CMD_GATT_SERVICE_SET_REQ,
CMD_GATT_SERVICE_SET_RSP,
CMD_GATT_SERVICE_NOTIFY_REQ,
CMD_GATT_SERVICE_NOTIFY_RSP,
CMD_GATT_SERVICE_INDICATE_REQ,
CMD_GATT_SERVICE_INDICATE_RSP,
CMD_GAP_ADVERTISING_MODE_REQ,
CMD_GAP_ADVERTISING_MODE_RSP,
CMD_GAP_ADVERTISING_DATA_REQ,
CMD_GAP_ADVERTISING_DATA_RSP,
CMD_GAP_SCANNING_MODE_REQ,
CMD_GAP_SCANNING_MODE_RSP,
CMD_READ_STATIC_ADDRESSES_REQ,
CMD_READ_STATIC_ADDRESSES_RSP,
CMD_READ_KEY_HIERARCHY_ROOTS_REQ,
CMD_READ_KEY_HIERARCHY_ROOTS_RSP,
CMD_GAP_READ_IRK_REQ,
CMD_GAP_READ_IRK_RSP,
CMD_GAP_ROLE_REQ,
CMD_GAP_ROLE_RSP
};
#endif /* EDDT_APP_COMMANDS_H */
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2019 Oticon A/S
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef EDTT_DRIVER_H
#define EDTT_DRIVER_H
#include <stdlib.h>
#include <stdbool.h>
#define EDTTT_NONBLOCK 0
#define EDTTT_BLOCK 1
#ifdef __cplusplus
extern "C" {
#endif
/**
* Generic EDTT interface
*/
bool edtt_start(void);
bool edtt_stop(void);
int edtt_read(uint8_t *ptr, size_t size, int flags);
int edtt_write(uint8_t *ptr, size_t size, int flags);
/**
* Exclusive functions for the BabbleSim driver
*/
void enable_edtt_mode(void);
void set_edtt_autoshutdown(bool mode);
#ifdef __cplusplus
}
#endif
#endif /* EDTT_DRIVER_H */
+35
View File
@@ -0,0 +1,35 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
#
pkg.name: babblesim/edtt/hci_transport
pkg.description: Provides communication with EDTT bridge over named pipes
pkg.author: "Apache Mynewt <[email protected]>"
pkg.homepage: "http://mynewt.apache.org/"
pkg.deps:
- "@apache-mynewt-core/sys/console/stub"
- "@apache-mynewt-core/sys/log/stub"
- "@apache-mynewt-core/sys/stats/full"
- "@apache-mynewt-core/kernel/os"
- nimble/controller
pkg.apis:
- ble_transport
pkg.init:
ble_hci_edtt_init: 500
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,286 @@
/*
* Copyright (c) 2019 Oticon A/S
* Copyright (c) 2021 Codecoup
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include "bs_tracing.h"
#include "bs_oswrap.h"
#include "bs_pc_base_fifo_user.h"
#include <time_machine.h>
#include "edtt_driver.h"
/* Recheck if something arrived from the EDTT every 5ms */
#define EDTT_IF_RECHECK_DELTA 5 /* ms */
/* We want the runs to be deterministic => we want to resync with the Phy
* before we retry any read so the bridge device may also run
*/
#define EDTT_SIMU_RESYNC_TIME_WITH_EDTT \
(EDTT_IF_RECHECK_DELTA * 1000 - 1)
static int edtt_mode_enabled = 0;
/* In this mode, when the EDTTool closes the FIFO we automatically terminate
* this simulated device. If false, we just continue running
*/
static int edtt_autoshutdown;
#define TO_DEVICE 0
#define TO_BRIDGE 1
static int fifo[2] = { -1, -1 };
static char *fifo_path[2] = {NULL, NULL};
extern unsigned int global_device_nbr;
static void edttd_clean_up(void);
static void edptd_create_fifo_if(void);
static int fifo_low_level_read(uint8_t *bufptr, int size);
bool edtt_start(void)
{
if (edtt_mode_enabled == false) {
/* otherwise we don't try to open the EDTT interface */
return true;
}
edptd_create_fifo_if();
extern void tm_set_phy_max_resync_offset(uint64_t offset_in_us);
tm_set_phy_max_resync_offset(EDTT_SIMU_RESYNC_TIME_WITH_EDTT);
return true;
}
bool edtt_stop(void)
{
if (edtt_mode_enabled == false) {
/* otherwise we don't try to open the EDTT interface */
return true;
}
bs_trace_raw(9, "EDTTT: %s called\n", __func__);
edttd_clean_up();
edtt_mode_enabled = false;
return true;
}
static void
print_hex_array(int lvl, uint8_t *buf, int len)
{
char str[2*len];
char *p = str;
int i;
for (i = 0; i < len; i++) {
if (i > 0) *p++ = ' ';
sprintf(p++, "%02X", buf[i]);
}
*p = '\n';
bs_trace_raw(lvl, str);
}
/**
* Attempt to read size bytes thru the EDTT IF into the buffer <*ptr>
* <flags> can be set to EDTTT_BLOCK or EDTTT_NONBLOCK
*
* If set to EDTTT_BLOCK it will block the calling thread until <size>
* bytes have been read or the interface has been closed.
* If set to EDTTT_NONBLOCK it returns as soon as there is no more data to be
* read
*
* Returns the amount of read bytes, or -1 on error
*/
int edtt_read(uint8_t *ptr, size_t size, int flags)
{
uint8_t *buf = ptr;
if (edtt_mode_enabled == false) {
return -1;
}
bs_trace_raw_time(8, "EDTT: Asked to read %i bytes\n", size);
int read = 0;
while (size > 0) {
int received_bytes;
received_bytes = fifo_low_level_read(ptr, size);
if (received_bytes < 0) {
return -1;
} else if (received_bytes > 0) {
size -= received_bytes;
ptr += received_bytes;
read += received_bytes;
} else {
if (flags & EDTTT_BLOCK) {
bs_trace_raw_time(9, "EDTT: No enough data yet,"
"sleeping for %i ms\n",
EDTT_IF_RECHECK_DELTA);
tm_tick_limited(6000);
} else {
bs_trace_raw_time(9, "EDTT: No enough data yet,"
"returning\n");
break;
}
}
}
if (read > 0) {
bs_trace_raw_time(8, "Read %i bytes:\n", read);
print_hex_array(8, buf, read);
}
return read;
}
/**
* Write <size> bytes from <ptr> toward the EDTTool
*
* <flags> is ignored in this driver, all writes to the tool are
* instantaneous
*/
int edtt_write(uint8_t *ptr, size_t size, int flags)
{
if (edtt_mode_enabled == false) {
return -1;
}
bs_trace_raw_time(6, "EDTT: Asked to write %i bytes: ", size);
print_hex_array(6, ptr, size);
if (write(fifo[TO_BRIDGE], ptr, size) != size) {
if (errno == EPIPE) {
bs_trace_error_line("EDTT IF suddenly closed by other "
"end\n");
}
if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
bs_trace_error_line("EDTT IF to bridge filled up (FIFO "
"size needs to be increased)\n");
}
bs_trace_error_line("EDTT IF: Unexpected error on write\n");
}
return size;
}
/*
* Applications may want to enable the EDTT interface only in some
* cases. By default it is not enabled in this driver. This function
* must be called once before starting it to do so
*/
void enable_edtt_mode(void)
{
edtt_mode_enabled = true;
}
/**
* Automatically terminate this device execution once the EDTTool disconnects
*/
void set_edtt_autoshutdown(bool Mode)
{
edtt_autoshutdown = Mode;
}
static void edptd_create_fifo_if(void)
{
int flags;
bs_trace_raw_time(9, "Bringing EDTT IF up (waiting for other side)\n");
if (pb_com_path == NULL) {
bs_trace_error_line("Not connected to Phy."
"EDTT IF cannot be brough up\n");
}
/* At this point we have connected to the Phy so the COM folder does
* already exist
* also SIGPIPE is already ignored
*/
fifo_path[TO_DEVICE] = (char *)bs_calloc(pb_com_path_length + 30,
sizeof(char));
fifo_path[TO_BRIDGE] = (char *)bs_calloc(pb_com_path_length + 30,
sizeof(char));
sprintf(fifo_path[TO_DEVICE], "%s/Device%i.PTTin",
pb_com_path, global_device_nbr);
sprintf(fifo_path[TO_BRIDGE], "%s/Device%i.PTTout",
pb_com_path, global_device_nbr);
if ((pb_create_fifo_if_not_there(fifo_path[TO_DEVICE]) != 0)
|| (pb_create_fifo_if_not_there(fifo_path[TO_BRIDGE]) != 0)) {
bs_trace_error_line("Couldnt create FIFOs for EDTT IF\n");
}
/* we block here until the bridge opens its end */
fifo[TO_BRIDGE] = open(fifo_path[TO_BRIDGE], O_WRONLY);
if (fifo[TO_BRIDGE] == -1) {
bs_trace_error_line("Couldn't create FIFOs for EDTT IF\n");
}
flags = fcntl(fifo[TO_BRIDGE], F_GETFL);
flags |= O_NONBLOCK;
fcntl(fifo[TO_BRIDGE], F_SETFL, flags);
/* we will block here until the bridge opens its end */
fifo[TO_DEVICE] = open(fifo_path[TO_DEVICE], O_RDONLY);
if (fifo[TO_DEVICE] == -1) {
bs_trace_error_line("Couldn't create FIFOs for EDTT IF\n");
}
flags = fcntl(fifo[TO_DEVICE], F_GETFL);
flags |= O_NONBLOCK;
fcntl(fifo[TO_DEVICE], F_SETFL, flags);
}
static void edttd_clean_up(void)
{
for (int dir = TO_DEVICE ; dir <= TO_BRIDGE ; dir++) {
if (fifo_path[dir]) {
if (fifo[dir] != -1) {
close(fifo[dir]);
remove(fifo_path[dir]);
fifo[dir] = -1;
}
free(fifo_path[dir]);
fifo_path[dir] = NULL;
}
}
if (pb_com_path != NULL) {
rmdir(pb_com_path);
}
}
static int fifo_low_level_read(uint8_t *bufptr, int size)
{
int received_bytes = read(fifo[TO_DEVICE], bufptr, size);
if ((received_bytes == -1) && (errno == EAGAIN)) {
return 0;
} else if (received_bytes == EOF || received_bytes == 0) {
/*The FIFO was closed by the bridge*/
if (edtt_autoshutdown) {
bs_trace_raw_time(3, "EDTT: FIFO closed "
"(ptt_autoshutdown==true) =>"
" Terminate\n");
edttd_clean_up();
bs_trace_exit_line("\n");
} else {
bs_trace_raw_time(3, "EDTT: FIFO closed "
"(ptt_autoshutdown==false) => We close "
"the FIFOs and move on\n");
edttd_clean_up();
edtt_mode_enabled = false;
return -1;
}
} else if (received_bytes == -1) {
bs_trace_error_line("EDTT: Unexpected error\n");
}
return received_bytes;
}
+49
View File
@@ -0,0 +1,49 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
#
syscfg.defs:
EDTT_HCI_LOG_FILE:
description: >
Path to the HCI log file. Skip file extension
because device id and .log will be appended.
value: "hci_logs"
EDTT_HCI_LOGS:
description: Turn on HCI commands logging.
value: 0
EDTT_POLLER_PRIO:
description: 'Priority of native EDTT poller task.'
type: task_priority
value: 2
BLE_HCI_ACL_OUT_COUNT:
description: >
This count is used in creating a pool of elements used by the
code to enqueue various elements. In the case of the controller
only HCI, this number should be equal to the number of mbufs in
the msys pool. For host only, it is really dependent on the
number of ACL buffers that the controller tells the host it
has.
value: 12
syscfg.vals:
BLE_ACL_BUF_COUNT: 32
BLE_ACL_BUF_SIZE: 255
BLE_HCI_EVT_BUF_SIZE: 257
BLE_HCI_EVT_HI_BUF_COUNT: 32
BLE_HCI_EVT_LO_BUF_COUNT: 32
+1 -1
View File
@@ -37,7 +37,7 @@ syscfg.vals:
OS_MAIN_STACK_SIZE: 8000
MCU_TIMER_POLLER_PRIO: 0
BLE_LL_PRIO: 1
MCU_UART_POLLER_PRIO: 2
MCU_UART_POLLER_PRIO: 9
# Enable nRF52832 MCU
MCU_TARGET: nRF52832
+24
View File
@@ -0,0 +1,24 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
#
pkg.name: babblesim/targets/edtthci
pkg.type: target
pkg.description:
pkg.author:
pkg.homepage:
+55
View File
@@ -0,0 +1,55 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
#
syscfg.vals:
# EDTT requires 0x123456789ABC address for the first device
# and 0x456789ABCDEF for the second one
BLE_LL_PUBLIC_DEV_ADDR: 0x123456789ABC # d=1
# BLE_LL_PUBLIC_DEV_ADDR: 0x456789ABCDEF # d=2
EDTT_HCI_LOG_FILE: ("hci_logs")
EDTT_HCI_LOGS: 1
BLE_LL_CFG_FEAT_LE_ENCRYPTION: 1
BLE_LL_CFG_FEAT_CONN_PARAM_REQ: 1
BLE_LL_CFG_FEAT_SLAVE_INIT_FEAT_XCHG: 1
BLE_LL_CFG_FEAT_LE_PING: 1
BLE_LL_CFG_FEAT_DATA_LEN_EXT: 1
BLE_LL_CFG_FEAT_LL_PRIVACY: 1
BLE_LL_CFG_FEAT_LE_CSA2: 1
BLE_LL_CFG_FEAT_LE_2M_PHY: 1
# BLE_LL_CFG_FEAT_LE_CODED_PHY: 1 # not modeled in bsim
BLE_LL_CFG_FEAT_LL_EXT_ADV: 1
BLE_LL_CFG_FEAT_LL_PERIODIC_ADV: 1
BLE_LL_CFG_FEAT_LL_PERIODIC_ADV_SYNC_TRANSFER: 1
BLE_LL_CFG_FEAT_CTRL_TO_HOST_FLOW_CONTROL: 1
BLE_LL_CFG_FEAT_LL_SCA_UPDATE: 1
BLE_ROLE_CENTRAL: 1
BLE_ROLE_PERIPHERAL: 1
BLE_ROLE_BROADCASTER: 1
BLE_ROLE_OBSERVER: 1
BLE_VERSION: 52
BLE_CONTROLLER: 1
BLE_LL_ROLE_CENTRAL: 1
BLE_LL_ROLE_PERIPHERAL: 1
BLE_LL_ROLE_BROADCASTER: 1
BLE_LL_ROLE_OBSERVER: 1
BLE_HW_WHITELIST_ENABLE: 1
+22
View File
@@ -0,0 +1,22 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
#
target.app: "@apache-mynewt-nimble/babblesim/edtt/hci_test"
target.bsp: "@apache-mynewt-nimble/babblesim/hw/bsp/nrf52_bsim"
target.build_profile: debug