From 8974fcd6cf20b16173cce26fdeacd4051c3413f7 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Wed, 10 Feb 2016 11:35:31 +0100 Subject: [PATCH] move Bluetooth related types to bluetooth.h and BTstack types to btstack_defines.h --- src/ble/sm.h | 16 +++++----- src/bluetooth.h | 49 +++++++++++++++++++++++++++++++ src/btstack_defines.h | 25 ++++++++++------ src/btstack_util.h | 48 +++--------------------------- src/classic/btstack_link_key_db.h | 3 +- src/hci.h | 1 + 6 files changed, 80 insertions(+), 62 deletions(-) diff --git a/src/ble/sm.h b/src/ble/sm.h index c605c5c1e..4ec869afb 100644 --- a/src/ble/sm.h +++ b/src/ble/sm.h @@ -38,16 +38,14 @@ #ifndef __SM_H #define __SM_H -#include -#include "btstack_util.h" - -#if defined __cplusplus + #if defined __cplusplus extern "C" { #endif -// PTS testing -void sm_test_set_irk(sm_key_t irk); -void sm_test_use_fixed_local_csrk(void); +#include +#include "btstack_util.h" +#include "btstack_defines.h" +#include "hci.h" typedef struct { btstack_linked_item_t item; @@ -204,6 +202,10 @@ int sm_address_resolution_lookup(uint8_t addr_type, bd_addr_t addr); int sm_le_device_index(uint16_t handle ); /* API_END */ +// PTS testing +void sm_test_set_irk(sm_key_t irk); +void sm_test_use_fixed_local_csrk(void); + #if defined __cplusplus } #endif diff --git a/src/bluetooth.h b/src/bluetooth.h index dd36656d9..30c1337be 100644 --- a/src/bluetooth.h +++ b/src/bluetooth.h @@ -46,6 +46,55 @@ #include +/** + * @brief hci connection handle type + */ +typedef uint16_t hci_con_handle_t; + +/** + * @brief Length of a bluetooth device address. + */ +#define BD_ADDR_LEN 6 + +/** + * @brief Bluetooth address + */ +typedef uint8_t bd_addr_t[BD_ADDR_LEN]; + +/** + * Address types + * @note: BTstack uses a custom addr type to refer to classic ACL and SCO devices + */ + typedef enum { + BD_ADDR_TYPE_LE_PUBLIC = 0, + BD_ADDR_TYPE_LE_RANDOM = 1, + BD_ADDR_TYPE_SCO = 0xfe, + BD_ADDR_TYPE_CLASSIC = 0xff, + BD_ADDR_TYPE_UNKNOWN = 0xfe +} bd_addr_type_t; + +/** + * @brief link key + */ +#define LINK_KEY_LEN 16 +#define LINK_KEY_STR_LEN (LINK_KEY_LEN*2) +typedef uint8_t link_key_t[LINK_KEY_LEN]; + +/** + * @brief link key type + */ +typedef enum { + COMBINATION_KEY = 0, // standard pairing + LOCAL_UNIT_KEY, // ? + REMOTE_UNIT_KEY, // ? + DEBUG_COMBINATION_KEY, // SSP with debug + UNAUTHENTICATED_COMBINATION_KEY_GENERATED_FROM_P192, // SSP Simple Pairing + AUTHENTICATED_COMBINATION_KEY_GENERATED_FROM_P192, // SSP Passkey, Number confirm, OOB + CHANGED_COMBINATION_KEY, // Link key changed using Change Connection Lnk Key + UNAUTHENTICATED_COMBINATION_KEY_GENERATED_FROM_P256, // SSP Simpe Pairing + AUTHENTICATED_COMBINATION_KEY_GENERATED_FROM_P256, // SSP Passkey, Number confirm, OOB +} link_key_type_t; + /** * HCI Transport */ diff --git a/src/btstack_defines.h b/src/btstack_defines.h index 55986afe0..f003635f8 100644 --- a/src/btstack_defines.h +++ b/src/btstack_defines.h @@ -43,17 +43,24 @@ #ifndef __BTSTACK_DEFINES_H #define __BTSTACK_DEFINES_H +#include +#include "btstack_linked_list.h" + +// TYPES + +// packet handler +typedef void (*btstack_packet_handler_t) (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size); + +// packet callback supporting multiple registrations +typedef struct { + btstack_linked_item_t item; + btstack_packet_handler_t callback; +} btstack_packet_callback_registration_t; + /** - * Address types - * @note: BTstack uses a custom addr type to refer to classic ACL and SCO devices + * @brief 128 bit key used with AES128 in Security Manager */ - typedef enum { - BD_ADDR_TYPE_LE_PUBLIC = 0, - BD_ADDR_TYPE_LE_RANDOM = 1, - BD_ADDR_TYPE_SCO = 0xfe, - BD_ADDR_TYPE_CLASSIC = 0xff, - BD_ADDR_TYPE_UNKNOWN = 0xfe - } bd_addr_type_t; +typedef uint8_t sm_key_t[16]; // DEFINES diff --git a/src/btstack_util.h b/src/btstack_util.h index 763632776..47a775784 100644 --- a/src/btstack_util.h +++ b/src/btstack_util.h @@ -52,42 +52,11 @@ extern "C" { #endif #include +#include "bluetooth.h" +#include "btstack_defines.h" #include "btstack_linked_list.h" - -/** - * @brief hci connection handle type - */ -typedef uint16_t hci_con_handle_t; - -/** - * @brief Length of a bluetooth device address. - */ -#define BD_ADDR_LEN 6 -typedef uint8_t bd_addr_t[BD_ADDR_LEN]; - -/** - * @brief link key and its type - */ -#define LINK_KEY_LEN 16 -#define LINK_KEY_STR_LEN (LINK_KEY_LEN*2) -typedef uint8_t link_key_t[LINK_KEY_LEN]; - -typedef enum { - COMBINATION_KEY = 0, // standard pairing - LOCAL_UNIT_KEY, // ? - REMOTE_UNIT_KEY, // ? - DEBUG_COMBINATION_KEY, // SSP with debug - UNAUTHENTICATED_COMBINATION_KEY_GENERATED_FROM_P192, // SSP Simple Pairing - AUTHENTICATED_COMBINATION_KEY_GENERATED_FROM_P192, // SSP Passkey, Number confirm, OOB - CHANGED_COMBINATION_KEY, // Link key changed using Change Connection Lnk Key - UNAUTHENTICATED_COMBINATION_KEY_GENERATED_FROM_P256, // SSP Simpe Pairing - AUTHENTICATED_COMBINATION_KEY_GENERATED_FROM_P256, // SSP Passkey, Number confirm, OOB -} link_key_type_t; - -/** - * @brief 128 bit key used with AES128 in Security Manager - */ -typedef uint8_t sm_key_t[16]; + +// will be moved to daemon/btstack_device_name_db.h /** * @brief The device name type @@ -95,16 +64,7 @@ typedef uint8_t sm_key_t[16]; #define DEVICE_NAME_LEN 248 typedef uint8_t device_name_t[DEVICE_NAME_LEN+1]; -// packet handler -typedef void (*btstack_packet_handler_t) (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size); -// packet callback supporting multiple registrations -typedef struct { - btstack_linked_item_t item; - btstack_packet_handler_t callback; -} btstack_packet_callback_registration_t; - - // helper for BT little endian format #define little_endian_read_16( buffer, pos) ( ((uint16_t) buffer[pos]) | (((uint16_t)buffer[(pos)+1]) << 8)) #define little_endian_read_24( buffer, pos) ( ((uint32_t) buffer[pos]) | (((uint32_t)buffer[(pos)+1]) << 8) | (((uint32_t)buffer[(pos)+2]) << 16)) diff --git a/src/classic/btstack_link_key_db.h b/src/classic/btstack_link_key_db.h index 73c8545ae..4ab10da6b 100644 --- a/src/classic/btstack_link_key_db.h +++ b/src/classic/btstack_link_key_db.h @@ -42,8 +42,7 @@ #ifndef __BTSTACK_LINK_KEY_DB_H #define __BTSTACK_LINK_KEY_DB_H -#include "btstack_util.h" -#include "gap.h" +#include "bluetooth.h" #if defined __cplusplus extern "C" { diff --git a/src/hci.h b/src/hci.h index 8000b9988..7c0c19c1d 100644 --- a/src/hci.h +++ b/src/hci.h @@ -53,6 +53,7 @@ #include "btstack_util.h" #include "classic/btstack_link_key_db.h" #include "hci_cmd.h" +#include "gap.h" #include "hci_transport.h" #include