NimBLE: Add optional mbedTLS support to NimBLE (backport)
- NimBLE: Additional menuconfig option to enable mbedTLS instead of Tinycrypt from NimBLE, changes `component.mk` & `CMakeLists.txt` for the same. - Addition of NimBLE stack size configuration and misc changes. - mbedTLS: Addition of `CMAC` and `ECP_RESTARTABLE` to mbedTLS menuconfig option and `esp_config.h`. - Example: Minor changes to `app_mesh.c` application.
This commit is contained in:
committed by
Jiang Jiang Jian
parent
7f9626d378
commit
daa65b6f91
@@ -64,6 +64,8 @@ def test_example_app_ble_central(env, extra_data):
|
||||
adv_type = 'peripheral'
|
||||
adv_uuid = '1811'
|
||||
|
||||
subprocess.check_output(['rm','-rf','/var/lib/bluetooth/*'])
|
||||
subprocess.check_output(['hciconfig','hci0','reset'])
|
||||
# Acquire DUT
|
||||
dut = env.get_dut("blecent", "examples/bluetooth/nimble/blecent")
|
||||
|
||||
@@ -75,8 +77,8 @@ def test_example_app_ble_central(env, extra_data):
|
||||
# Upload binary and start testing
|
||||
Utility.console_log("Starting blecent example test app")
|
||||
dut.start_app()
|
||||
dut.reset()
|
||||
|
||||
subprocess.check_output(['rm','-rf','/var/lib/bluetooth/*'])
|
||||
device_addr = ':'.join(re.findall('..', '%012x' % uuid.getnode()))
|
||||
|
||||
# Get BLE client module
|
||||
@@ -18,7 +18,9 @@ from __future__ import print_function
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
from threading import Thread
|
||||
import threading
|
||||
import traceback
|
||||
import Queue
|
||||
import subprocess
|
||||
|
||||
try:
|
||||
@@ -51,7 +53,7 @@ import Utility
|
||||
# > export TEST_FW_PATH=~/esp/esp-idf/tools/tiny-test-fw
|
||||
|
||||
|
||||
def blehr_client_task(dut_addr, dut):
|
||||
def blehr_client_task(hr_obj, dut_addr):
|
||||
interface = 'hci0'
|
||||
ble_devname = 'blehr_sensor_1.0'
|
||||
hr_srv_uuid = '180d'
|
||||
@@ -70,20 +72,18 @@ def blehr_client_task(dut_addr, dut):
|
||||
# Connect BLE Device
|
||||
is_connected = ble_client_obj.connect()
|
||||
if not is_connected:
|
||||
Utility.console_log("Connection to device ", ble_devname, "failed !!")
|
||||
# Call disconnect to perform cleanup operations before exiting application
|
||||
ble_client_obj.disconnect()
|
||||
return
|
||||
raise RuntimeError("Connection to device " + str(ble_devname) + " failed !!")
|
||||
|
||||
# Read Services
|
||||
services_ret = ble_client_obj.get_services()
|
||||
if services_ret:
|
||||
print("\nServices\n")
|
||||
print(services_ret)
|
||||
Utility.console_log("\nServices\n")
|
||||
Utility.console_log(str(services_ret))
|
||||
else:
|
||||
print("Failure: Read Services failed")
|
||||
ble_client_obj.disconnect()
|
||||
return
|
||||
raise RuntimeError("Failure: Read Services failed")
|
||||
|
||||
'''
|
||||
Blehr application run:
|
||||
@@ -93,14 +93,27 @@ def blehr_client_task(dut_addr, dut):
|
||||
'''
|
||||
blehr_ret = ble_client_obj.hr_update_simulation(hr_srv_uuid, hr_char_uuid)
|
||||
if blehr_ret:
|
||||
print("Success: blehr example test passed")
|
||||
Utility.console_log("Success: blehr example test passed")
|
||||
else:
|
||||
print("Failure: blehr example test failed")
|
||||
raise RuntimeError("Failure: blehr example test failed")
|
||||
|
||||
# Call disconnect to perform cleanup operations before exiting application
|
||||
ble_client_obj.disconnect()
|
||||
|
||||
|
||||
class BleHRThread(threading.Thread):
|
||||
def __init__(self, dut_addr, exceptions_queue):
|
||||
threading.Thread.__init__(self)
|
||||
self.dut_addr = dut_addr
|
||||
self.exceptions_queue = exceptions_queue
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
blehr_client_task(self, self.dut_addr)
|
||||
except Exception:
|
||||
self.exceptions_queue.put(traceback.format_exc(), block=False)
|
||||
|
||||
|
||||
@IDF.idf_example_test(env_tag="Example_WIFI_BT")
|
||||
def test_example_app_ble_hr(env, extra_data):
|
||||
"""
|
||||
@@ -111,38 +124,47 @@ def test_example_app_ble_hr(env, extra_data):
|
||||
4. Updated value is retrieved
|
||||
5. Stop Notifications
|
||||
"""
|
||||
try:
|
||||
# Acquire DUT
|
||||
dut = env.get_dut("blehr", "examples/bluetooth/nimble/blehr")
|
||||
subprocess.check_output(['rm','-rf','/var/lib/bluetooth/*'])
|
||||
subprocess.check_output(['hciconfig','hci0','reset'])
|
||||
|
||||
# Get binary file
|
||||
binary_file = os.path.join(dut.app.binary_path, "blehr.bin")
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
IDF.log_performance("blehr_bin_size", "{}KB".format(bin_size // 1024))
|
||||
IDF.check_performance("blehr_bin_size", bin_size // 1024)
|
||||
# Acquire DUT
|
||||
dut = env.get_dut("blehr", "examples/bluetooth/nimble/blehr")
|
||||
|
||||
# Upload binary and start testing
|
||||
Utility.console_log("Starting blehr simple example test app")
|
||||
dut.start_app()
|
||||
# Get binary file
|
||||
binary_file = os.path.join(dut.app.binary_path, "blehr.bin")
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
IDF.log_performance("blehr_bin_size", "{}KB".format(bin_size // 1024))
|
||||
IDF.check_performance("blehr_bin_size", bin_size // 1024)
|
||||
|
||||
subprocess.check_output(['rm','-rf','/var/lib/bluetooth/*'])
|
||||
# Upload binary and start testing
|
||||
Utility.console_log("Starting blehr simple example test app")
|
||||
dut.start_app()
|
||||
dut.reset()
|
||||
|
||||
# Get device address from dut
|
||||
dut_addr = dut.expect(re.compile(r"Device Address: ([a-fA-F0-9:]+)"), timeout=30)[0]
|
||||
# Get device address from dut
|
||||
dut_addr = dut.expect(re.compile(r"Device Address: ([a-fA-F0-9:]+)"), timeout=30)[0]
|
||||
exceptions_queue = Queue.Queue()
|
||||
# Starting a py-client in a separate thread
|
||||
blehr_thread_obj = BleHRThread(dut_addr, exceptions_queue)
|
||||
blehr_thread_obj.start()
|
||||
blehr_thread_obj.join()
|
||||
|
||||
# Starting a py-client in a separate thread
|
||||
thread1 = Thread(target=blehr_client_task, args=(dut_addr,dut,))
|
||||
thread1.start()
|
||||
thread1.join()
|
||||
exception_msg = None
|
||||
while True:
|
||||
try:
|
||||
exception_msg = exceptions_queue.get(block=False)
|
||||
except Queue.Empty:
|
||||
break
|
||||
else:
|
||||
Utility.console_log("\n" + exception_msg)
|
||||
|
||||
# Check dut responses
|
||||
dut.expect("subscribe event; cur_notify=1", timeout=30)
|
||||
dut.expect("GATT procedure initiated: notify;", timeout=30)
|
||||
dut.expect("subscribe event; cur_notify=0", timeout=30)
|
||||
dut.expect("disconnect;", timeout=30)
|
||||
if exception_msg:
|
||||
raise Exception("Thread did not run successfully")
|
||||
|
||||
except Exception as e:
|
||||
sys.exit(e)
|
||||
# Check dut responses
|
||||
dut.expect("subscribe event; cur_notify=1", timeout=30)
|
||||
dut.expect("subscribe event; cur_notify=0", timeout=30)
|
||||
dut.expect("disconnect;", timeout=30)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
@@ -32,7 +32,7 @@
|
||||
#include "mesh/mesh.h"
|
||||
|
||||
static const char *tag = "NimBLE_MESH";
|
||||
void ble_store_ram_init(void);
|
||||
void ble_store_config_init(void);
|
||||
|
||||
#define BT_DBG_ENABLED (MYNEWT_VAL(BLE_MESH_DEBUG))
|
||||
|
||||
@@ -418,6 +418,7 @@ void blemesh_host_task(void *param)
|
||||
|
||||
health_pub_init();
|
||||
nimble_port_run();
|
||||
nimble_port_freertos_deinit();
|
||||
}
|
||||
|
||||
void app_main()
|
||||
@@ -438,7 +439,7 @@ void app_main()
|
||||
|
||||
bt_mesh_register_gatt();
|
||||
/* XXX Need to have template for store */
|
||||
ble_store_ram_init();
|
||||
ble_store_config_init();
|
||||
|
||||
nimble_port_freertos_init(blemesh_host_task);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,9 @@ from __future__ import print_function
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
from threading import Thread
|
||||
import Queue
|
||||
import traceback
|
||||
import threading
|
||||
import subprocess
|
||||
|
||||
try:
|
||||
@@ -50,7 +52,7 @@ import Utility
|
||||
# > export TEST_FW_PATH=~/esp/esp-idf/tools/tiny-test-fw
|
||||
|
||||
|
||||
def bleprph_client_task(dut_addr, dut):
|
||||
def bleprph_client_task(prph_obj, dut, dut_addr):
|
||||
interface = 'hci0'
|
||||
ble_devname = 'nimble-bleprph'
|
||||
srv_uuid = '2f12'
|
||||
@@ -68,10 +70,9 @@ def bleprph_client_task(dut_addr, dut):
|
||||
# Connect BLE Device
|
||||
is_connected = ble_client_obj.connect()
|
||||
if not is_connected:
|
||||
Utility.console_log("Connection to device ", ble_devname, "failed !!")
|
||||
# Call disconnect to perform cleanup operations before exiting application
|
||||
ble_client_obj.disconnect()
|
||||
return
|
||||
raise RuntimeError("Connection to device " + ble_devname + " failed !!")
|
||||
|
||||
# Check dut responses
|
||||
dut.expect("GAP procedure initiated: advertise;", timeout=30)
|
||||
@@ -79,12 +80,11 @@ def bleprph_client_task(dut_addr, dut):
|
||||
# Read Services
|
||||
services_ret = ble_client_obj.get_services(srv_uuid)
|
||||
if services_ret:
|
||||
print("\nServices\n")
|
||||
print(services_ret)
|
||||
Utility.console_log("\nServices\n")
|
||||
Utility.console_log(str(services_ret))
|
||||
else:
|
||||
print("Failure: Read Services failed")
|
||||
ble_client_obj.disconnect()
|
||||
return
|
||||
raise RuntimeError("Failure: Read Services failed")
|
||||
|
||||
# Read Characteristics
|
||||
chars_ret = {}
|
||||
@@ -92,14 +92,13 @@ def bleprph_client_task(dut_addr, dut):
|
||||
if chars_ret:
|
||||
Utility.console_log("\nCharacteristics retrieved")
|
||||
for path, props in chars_ret.items():
|
||||
print("\n\tCharacteristic: ", path)
|
||||
print("\tCharacteristic UUID: ", props[2])
|
||||
print("\tValue: ", props[0])
|
||||
print("\tProperties: : ", props[1])
|
||||
Utility.console_log("\n\tCharacteristic: " + str(path))
|
||||
Utility.console_log("\tCharacteristic UUID: " + str(props[2]))
|
||||
Utility.console_log("\tValue: " + str(props[0]))
|
||||
Utility.console_log("\tProperties: : " + str(props[1]))
|
||||
else:
|
||||
print("Failure: Read Characteristics failed")
|
||||
ble_client_obj.disconnect()
|
||||
return
|
||||
raise RuntimeError("Failure: Read Characteristics failed")
|
||||
|
||||
'''
|
||||
Write Characteristics
|
||||
@@ -110,19 +109,32 @@ def bleprph_client_task(dut_addr, dut):
|
||||
if chars_ret_on_write:
|
||||
Utility.console_log("\nCharacteristics after write operation")
|
||||
for path, props in chars_ret_on_write.items():
|
||||
print("\n\tCharacteristic:", path)
|
||||
print("\tCharacteristic UUID: ", props[2])
|
||||
print("\tValue:", props[0])
|
||||
print("\tProperties: : ", props[1])
|
||||
Utility.console_log("\n\tCharacteristic:" + str(path))
|
||||
Utility.console_log("\tCharacteristic UUID: " + str(props[2]))
|
||||
Utility.console_log("\tValue:" + str(props[0]))
|
||||
Utility.console_log("\tProperties: : " + str(props[1]))
|
||||
else:
|
||||
print("Failure: Write Characteristics failed")
|
||||
ble_client_obj.disconnect()
|
||||
return
|
||||
raise RuntimeError("Failure: Write Characteristics failed")
|
||||
|
||||
# Call disconnect to perform cleanup operations before exiting application
|
||||
ble_client_obj.disconnect()
|
||||
|
||||
|
||||
class BlePrphThread(threading.Thread):
|
||||
def __init__(self, dut, dut_addr, exceptions_queue):
|
||||
threading.Thread.__init__(self)
|
||||
self.dut = dut
|
||||
self.dut_addr = dut_addr
|
||||
self.exceptions_queue = exceptions_queue
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
bleprph_client_task(self, self.dut, self.dut_addr)
|
||||
except Exception:
|
||||
self.exceptions_queue.put(traceback.format_exc(), block=False)
|
||||
|
||||
|
||||
@IDF.idf_example_test(env_tag="Example_WIFI_BT")
|
||||
def test_example_app_ble_peripheral(env, extra_data):
|
||||
"""
|
||||
@@ -133,36 +145,47 @@ def test_example_app_ble_peripheral(env, extra_data):
|
||||
4. Read Characteristics
|
||||
5. Write Characteristics
|
||||
"""
|
||||
try:
|
||||
subprocess.check_output(['rm','-rf','/var/lib/bluetooth/*'])
|
||||
subprocess.check_output(['hciconfig','hci0','reset'])
|
||||
|
||||
# Acquire DUT
|
||||
dut = env.get_dut("bleprph", "examples/bluetooth/nimble/bleprph")
|
||||
# Acquire DUT
|
||||
dut = env.get_dut("bleprph", "examples/bluetooth/nimble/bleprph")
|
||||
|
||||
# Get binary file
|
||||
binary_file = os.path.join(dut.app.binary_path, "bleprph.bin")
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
IDF.log_performance("bleprph_bin_size", "{}KB".format(bin_size // 1024))
|
||||
IDF.check_performance("bleprph_bin_size", bin_size // 1024)
|
||||
# Get binary file
|
||||
binary_file = os.path.join(dut.app.binary_path, "bleprph.bin")
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
IDF.log_performance("bleprph_bin_size", "{}KB".format(bin_size // 1024))
|
||||
IDF.check_performance("bleprph_bin_size", bin_size // 1024)
|
||||
|
||||
# Upload binary and start testing
|
||||
Utility.console_log("Starting bleprph simple example test app")
|
||||
dut.start_app()
|
||||
# Upload binary and start testing
|
||||
Utility.console_log("Starting bleprph simple example test app")
|
||||
dut.start_app()
|
||||
dut.reset()
|
||||
|
||||
subprocess.check_output(['rm','-rf','/var/lib/bluetooth/*'])
|
||||
# Get device address from dut
|
||||
dut_addr = dut.expect(re.compile(r"Device Address: ([a-fA-F0-9:]+)"), timeout=30)[0]
|
||||
|
||||
# Get device address from dut
|
||||
dut_addr = dut.expect(re.compile(r"Device Address: ([a-fA-F0-9:]+)"), timeout=30)[0]
|
||||
exceptions_queue = Queue.Queue()
|
||||
# Starting a py-client in a separate thread
|
||||
bleprph_thread_obj = BlePrphThread(dut, dut_addr, exceptions_queue)
|
||||
bleprph_thread_obj.start()
|
||||
bleprph_thread_obj.join()
|
||||
|
||||
# Starting a py-client in a separate thread
|
||||
thread1 = Thread(target=bleprph_client_task, args=(dut_addr,dut,))
|
||||
thread1.start()
|
||||
thread1.join()
|
||||
exception_msg = None
|
||||
while True:
|
||||
try:
|
||||
exception_msg = exceptions_queue.get(block=False)
|
||||
except Queue.Empty:
|
||||
break
|
||||
else:
|
||||
Utility.console_log("\n" + exception_msg)
|
||||
|
||||
# Check dut responses
|
||||
dut.expect("connection established; status=0", timeout=30)
|
||||
dut.expect("disconnect;", timeout=30)
|
||||
except Exception as e:
|
||||
sys.exit(e)
|
||||
if exception_msg:
|
||||
raise Exception("Thread did not run successfully")
|
||||
|
||||
# Check dut responses
|
||||
dut.expect("connection established; status=0", timeout=30)
|
||||
dut.expect("disconnect;", timeout=30)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
Reference in New Issue
Block a user