From 75a8e4fae1e397c60f0d9bd39509394087fdba4e Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Mon, 8 Feb 2021 14:56:07 +0100 Subject: [PATCH] gap: emit GAP_EVENT_LOCAL_OOB_DATA --- src/btstack_defines.h | 10 +++++++ src/btstack_event.h | 46 +++++++++++++++++++++++++++++++++ src/hci.c | 21 ++++++++++++++- tool/btstack_event_generator.py | 7 ++--- 4 files changed, 80 insertions(+), 4 deletions(-) diff --git a/src/btstack_defines.h b/src/btstack_defines.h index 9802031bc..d2f3985f3 100644 --- a/src/btstack_defines.h +++ b/src/btstack_defines.h @@ -1386,6 +1386,16 @@ typedef uint8_t sm_key_t[16]; */ #define GAP_EVENT_RSSI_MEASUREMENT 0xE5 +/** + * @format 1KKKK + * @param oob_data_present 0 = none, 1 = p_192, 2 = p_256, 3 = both + * @param c_192 Simple Pairing Hash C derived from P-192 public key + * @param r_192 Simple Pairing Randomizer derived from P-192 public key + * @param c_256 Simple Pairing Hash C derived from P-256 public key + * @param r_256 Simple Pairing Randomizer derived from P-256 public key + */ +#define GAP_EVENT_LOCAL_OOB_DATA 0xE6 + // Meta Events, see below for sub events #define HCI_EVENT_HSP_META 0xE8 #define HCI_EVENT_HFP_META 0xE9 diff --git a/src/btstack_event.h b/src/btstack_event.h index a7eeda113..e3a97b422 100644 --- a/src/btstack_event.h +++ b/src/btstack_event.h @@ -3325,6 +3325,52 @@ static inline uint8_t gap_event_rssi_measurement_get_rssi(const uint8_t * event) return event[4]; } +/** + * @brief Get field oob_data_present from event GAP_EVENT_LOCAL_OOB_DATA + * @param event packet + * @return oob_data_present + * @note: btstack_type 1 + */ +static inline uint8_t gap_event_local_oob_data_get_oob_data_present(const uint8_t * event){ + return event[2]; +} +/** + * @brief Get field c_192 from event GAP_EVENT_LOCAL_OOB_DATA + * @param event packet + * @param Pointer to storage for c_192 + * @note: btstack_type K + */ +static inline void gap_event_local_oob_data_get_c_192(const uint8_t * event, uint8_t * c_192){ + reverse_bytes(&event[3], c_192, 16); +} +/** + * @brief Get field r_192 from event GAP_EVENT_LOCAL_OOB_DATA + * @param event packet + * @param Pointer to storage for r_192 + * @note: btstack_type K + */ +static inline void gap_event_local_oob_data_get_r_192(const uint8_t * event, uint8_t * r_192){ + reverse_bytes(&event[19], r_192, 16); +} +/** + * @brief Get field c_256 from event GAP_EVENT_LOCAL_OOB_DATA + * @param event packet + * @param Pointer to storage for c_256 + * @note: btstack_type K + */ +static inline void gap_event_local_oob_data_get_c_256(const uint8_t * event, uint8_t * c_256){ + reverse_bytes(&event[35], c_256, 16); +} +/** + * @brief Get field r_256 from event GAP_EVENT_LOCAL_OOB_DATA + * @param event packet + * @param Pointer to storage for r_256 + * @note: btstack_type K + */ +static inline void gap_event_local_oob_data_get_r_256(const uint8_t * event, uint8_t * r_256){ + reverse_bytes(&event[51], r_256, 16); +} + /** * @brief Get field status from event HCI_SUBEVENT_LE_CONNECTION_COMPLETE * @param event packet diff --git a/src/hci.c b/src/hci.c index ec7864fbe..9c7f28370 100644 --- a/src/hci.c +++ b/src/hci.c @@ -2154,8 +2154,27 @@ static void handle_command_complete_event(uint8_t * packet, uint16_t size){ hci_handle_read_encryption_key_size_complete(conn, key_size); } break; +#ifdef ENABLE_CLASSIC_PAIRING_OOB + case HCI_OPCODE_HCI_READ_LOCAL_OOB_DATA: + case HCI_OPCODE_HCI_READ_LOCAL_EXTENDED_OOB_DATA:{ + uint8_t event[67]; + event[0] = GAP_EVENT_LOCAL_OOB_DATA; + event[1] = 65; + (void)memset(&event[2], 0, 65); + if (packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE] == ERROR_CODE_SUCCESS){ + (void)memcpy(&event[3], &packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1], 32); + if (opcode == HCI_OPCODE_HCI_READ_LOCAL_EXTENDED_OOB_DATA){ + event[2] = 3; + (void)memcpy(&event[35], &packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+33], 32); + } else { + event[2] = 1; + } + } + hci_emit_event(event, sizeof(event), 0); + break; + } +#endif #endif - default: break; } diff --git a/tool/btstack_event_generator.py b/tool/btstack_event_generator.py index b335dc226..e03a933aa 100755 --- a/tool/btstack_event_generator.py +++ b/tool/btstack_event_generator.py @@ -191,6 +191,7 @@ param_read = { 'N' : 'return (const char *) &event[{offset}];', 'T' : 'return (const char *) &event[{offset}];', 'D' : 'return (const uint8_t *) &event[{offset}];', + 'K' : 'reverse_bytes(&event[{offset}], {result_name}, 16);', 'Q' : 'reverse_bytes(&event[{offset}], {result_name}, 32);', 'V' : 'return &event[{offset}];', 'X' : 'gatt_client_deserialize_service(event, {offset}, {result_name});', @@ -204,13 +205,13 @@ def c_type_for_btstack_type(type): 'D' : 'const uint8_t *', 'E' : 'const uint8_t * ', 'N' : 'const char *' , 'P' : 'const uint8_t *', 'A' : 'const uint8_t *', 'R' : 'const uint8_t *', 'S' : 'const uint8_t *', 'J' : 'uint8_t', 'L' : 'uint16_t', 'V' : 'const uint8_t *', 'U' : 'BT_UUID', - 'Q' : 'uint8_t *', + 'Q' : 'uint8_t *', 'K' : 'uint8_t *', 'X' : 'gatt_client_service_t *', 'Y' : 'gatt_client_characteristic_t *', 'Z' : 'gatt_client_characteristic_descriptor_t *', 'T' : 'const char *'} return param_types[type] def size_for_type(type): - param_sizes = { '1' : 1, '2' : 2, '3' : 3, '4' : 4, 'H' : 2, 'B' : 6, 'D' : 8, 'E' : 240, 'N' : 248, 'P' : 16, 'Q':32, + param_sizes = { '1' : 1, '2' : 2, '3' : 3, '4' : 4, 'H' : 2, 'B' : 6, 'D' : 8, 'E' : 240, 'N' : 248, 'P' : 16, 'Q':32, 'K':16, 'A' : 31, 'S' : -1, 'V': -1, 'J' : 1, 'L' : 2, 'U' : 16, 'X' : 20, 'Y' : 24, 'Z' : 18, 'T':-1} return param_sizes[type] @@ -223,7 +224,7 @@ def format_function_name(event_name): def template_for_type(field_type): global c_prototoype_simple_return global c_prototoype_struct_return - types_with_struct_return = "BQXYZ" + types_with_struct_return = "BKQXYZ" if field_type in types_with_struct_return: return c_prototoype_struct_return else: