kopia lustrzana https://github.com/micropython/micropython
extmod/modbluetooth: Allow NimBLE to use Zephyr static address.
Zephyr controllers can be queried for a static address (computed from the device ID). BlueKitchen already supports this, but make them both use the same macro to enable the feature.pull/6907/head
rodzic
236274f08f
commit
4005138882
|
@ -282,7 +282,7 @@ STATIC void btstack_packet_handler_att_server(uint8_t packet_type, uint16_t chan
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if MICROPY_BLUETOOTH_BTSTACK_ZEPHYR_STATIC_ADDRESS
|
#if MICROPY_BLUETOOTH_USE_ZEPHYR_STATIC_ADDRESS
|
||||||
// During startup, the controller (e.g. Zephyr) might give us a static address that we can use.
|
// During startup, the controller (e.g. Zephyr) might give us a static address that we can use.
|
||||||
STATIC uint8_t controller_static_addr[6] = {0};
|
STATIC uint8_t controller_static_addr[6] = {0};
|
||||||
STATIC bool controller_static_addr_available = false;
|
STATIC bool controller_static_addr_available = false;
|
||||||
|
@ -349,13 +349,13 @@ STATIC void btstack_packet_handler(uint8_t packet_type, uint8_t *packet, uint8_t
|
||||||
DEBUG_printf(" --> hci transport packet sent\n");
|
DEBUG_printf(" --> hci transport packet sent\n");
|
||||||
} else if (event_type == HCI_EVENT_COMMAND_COMPLETE) {
|
} else if (event_type == HCI_EVENT_COMMAND_COMPLETE) {
|
||||||
DEBUG_printf(" --> hci command complete\n");
|
DEBUG_printf(" --> hci command complete\n");
|
||||||
#if MICROPY_BLUETOOTH_BTSTACK_ZEPHYR_STATIC_ADDRESS
|
#if MICROPY_BLUETOOTH_USE_ZEPHYR_STATIC_ADDRESS
|
||||||
if (memcmp(packet, read_static_address_command_complete_prefix, sizeof(read_static_address_command_complete_prefix)) == 0) {
|
if (memcmp(packet, read_static_address_command_complete_prefix, sizeof(read_static_address_command_complete_prefix)) == 0) {
|
||||||
DEBUG_printf(" --> static address available\n");
|
DEBUG_printf(" --> static address available\n");
|
||||||
reverse_48(&packet[7], controller_static_addr);
|
reverse_48(&packet[7], controller_static_addr);
|
||||||
controller_static_addr_available = true;
|
controller_static_addr_available = true;
|
||||||
}
|
}
|
||||||
#endif // MICROPY_BLUETOOTH_BTSTACK_ZEPHYR_STATIC_ADDRESS
|
#endif // MICROPY_BLUETOOTH_USE_ZEPHYR_STATIC_ADDRESS
|
||||||
} else if (event_type == HCI_EVENT_COMMAND_STATUS) {
|
} else if (event_type == HCI_EVENT_COMMAND_STATUS) {
|
||||||
DEBUG_printf(" --> hci command status\n");
|
DEBUG_printf(" --> hci command status\n");
|
||||||
} else if (event_type == HCI_EVENT_NUMBER_OF_COMPLETED_PACKETS) {
|
} else if (event_type == HCI_EVENT_NUMBER_OF_COMPLETED_PACKETS) {
|
||||||
|
@ -575,12 +575,12 @@ STATIC bool set_public_address(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void set_random_address(void) {
|
STATIC void set_random_address(void) {
|
||||||
#if MICROPY_BLUETOOTH_BTSTACK_ZEPHYR_STATIC_ADDRESS
|
#if MICROPY_BLUETOOTH_USE_ZEPHYR_STATIC_ADDRESS
|
||||||
if (controller_static_addr_available) {
|
if (controller_static_addr_available) {
|
||||||
DEBUG_printf("set_random_address: Using static address supplied by controller.\n");
|
DEBUG_printf("set_random_address: Using static address supplied by controller.\n");
|
||||||
gap_random_address_set(controller_static_addr);
|
gap_random_address_set(controller_static_addr);
|
||||||
} else
|
} else
|
||||||
#endif // MICROPY_BLUETOOTH_BTSTACK_ZEPHYR_STATIC_ADDRESS
|
#endif // MICROPY_BLUETOOTH_USE_ZEPHYR_STATIC_ADDRESS
|
||||||
{
|
{
|
||||||
bd_addr_t static_addr;
|
bd_addr_t static_addr;
|
||||||
|
|
||||||
|
@ -635,7 +635,7 @@ int mp_bluetooth_init(void) {
|
||||||
|
|
||||||
btstack_memory_init();
|
btstack_memory_init();
|
||||||
|
|
||||||
#if MICROPY_BLUETOOTH_BTSTACK_ZEPHYR_STATIC_ADDRESS
|
#if MICROPY_BLUETOOTH_USE_ZEPHYR_STATIC_ADDRESS
|
||||||
controller_static_addr_available = false;
|
controller_static_addr_available = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,11 @@
|
||||||
#include "nimble/host/src/ble_l2cap_priv.h"
|
#include "nimble/host/src/ble_l2cap_priv.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if MICROPY_PY_BLUETOOTH_ENABLE_HCI_CMD || MICROPY_BLUETOOTH_USE_ZEPHYR_STATIC_ADDRESS
|
||||||
|
// For ble_hs_hci_cmd_tx
|
||||||
|
#include "nimble/host/src/ble_hs_hci_priv.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef MICROPY_PY_BLUETOOTH_DEFAULT_GAP_NAME
|
#ifndef MICROPY_PY_BLUETOOTH_DEFAULT_GAP_NAME
|
||||||
#define MICROPY_PY_BLUETOOTH_DEFAULT_GAP_NAME "MPY NIMBLE"
|
#define MICROPY_PY_BLUETOOTH_DEFAULT_GAP_NAME "MPY NIMBLE"
|
||||||
#endif
|
#endif
|
||||||
|
@ -179,6 +184,14 @@ STATIC void set_random_address(bool nrpa) {
|
||||||
// Mark it as STATIC (not RPA or NRPA).
|
// Mark it as STATIC (not RPA or NRPA).
|
||||||
addr.val[5] |= 0xc0;
|
addr.val[5] |= 0xc0;
|
||||||
} else
|
} else
|
||||||
|
#elif MICROPY_BLUETOOTH_USE_ZEPHYR_STATIC_ADDRESS
|
||||||
|
if (!nrpa) {
|
||||||
|
DEBUG_printf("set_random_address: Generating static address from Zephyr controller\n");
|
||||||
|
uint8_t buf[23];
|
||||||
|
rc = ble_hs_hci_cmd_tx(BLE_HCI_OP(BLE_HCI_OGF_VENDOR, 0x09), NULL, 0, buf, sizeof(buf));
|
||||||
|
assert(rc == 0);
|
||||||
|
memcpy(addr.val, buf + 1, 6);
|
||||||
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
DEBUG_printf("set_random_address: Generating random static address\n");
|
DEBUG_printf("set_random_address: Generating random static address\n");
|
||||||
|
@ -1688,9 +1701,6 @@ int mp_bluetooth_l2cap_recvinto(uint16_t conn_handle, uint16_t cid, uint8_t *buf
|
||||||
|
|
||||||
#if MICROPY_PY_BLUETOOTH_ENABLE_HCI_CMD
|
#if MICROPY_PY_BLUETOOTH_ENABLE_HCI_CMD
|
||||||
|
|
||||||
// For ble_hs_hci_cmd_tx
|
|
||||||
#include "nimble/host/src/ble_hs_hci_priv.h"
|
|
||||||
|
|
||||||
int mp_bluetooth_hci_cmd(uint16_t ogf, uint16_t ocf, const uint8_t *req, size_t req_len, uint8_t *resp, size_t resp_len, uint8_t *status) {
|
int mp_bluetooth_hci_cmd(uint16_t ogf, uint16_t ocf, const uint8_t *req, size_t req_len, uint8_t *resp, size_t resp_len, uint8_t *status) {
|
||||||
int rc = ble_hs_hci_cmd_tx(BLE_HCI_OP(ogf, ocf), req, req_len, resp, resp_len);
|
int rc = ble_hs_hci_cmd_tx(BLE_HCI_OP(ogf, ocf), req, req_len, resp, resp_len);
|
||||||
if (rc < BLE_HS_ERR_HCI_BASE || rc >= BLE_HS_ERR_HCI_BASE + 0x100) {
|
if (rc < BLE_HS_ERR_HCI_BASE || rc >= BLE_HS_ERR_HCI_BASE + 0x100) {
|
||||||
|
|
Ładowanie…
Reference in New Issue