esp_bt_defs.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef __ESP_BT_DEFS_H__
  14. #define __ESP_BT_DEFS_H__
  15. #include <stdint.h>
  16. #include <stdbool.h>
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /// Status Return Value
  21. typedef enum {
  22. ESP_BT_STATUS_SUCCESS = 0, /* Successful operation. */
  23. ESP_BT_STATUS_FAILURE = 1, /* Generic failure. */
  24. ESP_BT_STATUS_PENDING = 2, /* API cannot be completed right now */
  25. ESP_BT_STATUS_BUSY = 3,
  26. ESP_BT_STATUS_NO_RESOURCES = 4,
  27. ESP_BT_STATUS_WRONG_MODE = 5,
  28. } esp_bt_status_t;
  29. /*Define the bt octet 16 bit size*/
  30. #define ESP_BT_OCTET16_LEN 16
  31. typedef uint8_t esp_bt_octet16_t[ESP_BT_OCTET16_LEN]; /* octet array: size 16 */
  32. #define ESP_BT_OCTET8_LEN 8
  33. typedef uint8_t esp_bt_octet8_t[ESP_BT_OCTET8_LEN]; /* octet array: size 8 */
  34. typedef uint8_t esp_link_key[ESP_BT_OCTET16_LEN]; /* Link Key */
  35. /// Default GATT interface id
  36. #define ESP_DEFAULT_GATT_IF 0xff
  37. /// Default BLE connection param, if the value doesn't be overwritten
  38. #define ESP_BLE_CONN_PARAM_UNDEF 0xffff /* use this value when a specific value not to be overwritten */
  39. /// Check the param is valid or not
  40. #define ESP_BLE_IS_VALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)) || ((x) == ESP_BLE_CONN_PARAM_UNDEF))
  41. /// UUID type
  42. typedef struct {
  43. #define ESP_UUID_LEN_16 2
  44. #define ESP_UUID_LEN_32 4
  45. #define ESP_UUID_LEN_128 16
  46. uint16_t len; /*!< UUID length, 16bit, 32bit or 128bit */
  47. union {
  48. uint16_t uuid16;
  49. uint32_t uuid32;
  50. uint8_t uuid128[ESP_UUID_LEN_128];
  51. } uuid; /*!< UUID */
  52. } __attribute__((packed)) esp_bt_uuid_t;
  53. /// Bluetooth device type
  54. typedef enum {
  55. ESP_BT_DEVICE_TYPE_BREDR = 0x01,
  56. ESP_BT_DEVICE_TYPE_BLE = 0x02,
  57. ESP_BT_DEVICE_TYPE_DUMO = 0x03,
  58. } esp_bt_dev_type_t;
  59. /// Bluetooth address length
  60. #define ESP_BD_ADDR_LEN 6
  61. /// Bluetooth device address
  62. typedef uint8_t esp_bd_addr_t[ESP_BD_ADDR_LEN];
  63. /// Own BD address source of the device
  64. typedef enum {
  65. /// Public Address
  66. BD_ADDR_PUBLIC,
  67. /// Provided random address
  68. BD_ADDR_PROVIDED_RND,
  69. /// Provided static random address
  70. BD_ADDR_GEN_STATIC_RND,
  71. /// Generated resolvable private random address
  72. BD_ADDR_GEN_RSLV,
  73. /// Generated non-resolvable private random address
  74. BD_ADDR_GEN_NON_RSLV,
  75. /// Provided Reconnection address
  76. BD_ADDR_PROVIDED_RECON,
  77. } esp_bd_addr_type_t;
  78. /// BLE device address type
  79. typedef enum {
  80. BLE_ADDR_TYPE_PUBLIC = 0x00,
  81. BLE_ADDR_TYPE_RANDOM = 0x01,
  82. BLE_ADDR_TYPE_RPA_PUBLIC = 0x02,
  83. BLE_ADDR_TYPE_RPA_RANDOM = 0x03,
  84. } esp_ble_addr_type_t;
  85. /// Used to exchange the encrytyption key in the init key & response key
  86. #define ESP_BLE_ENC_KEY_MASK (1 << 0)
  87. /// Used to exchange the IRK key in the init key & response key
  88. #define ESP_BLE_ID_KEY_MASK (1 << 1)
  89. /// Used to exchange the CSRK key in the init key & response key
  90. #define ESP_BLE_CSR_KEY_MASK (1 << 2)
  91. /// Used to exchange the link key(this key just used in the BLE & BR/EDR coexist mode) in the init key & response key
  92. #define ESP_BLE_LINK_KEY_MASK (1 << 3)
  93. /// Minimum of the application id
  94. #define ESP_APP_ID_MIN 0x0000
  95. /// Maximum of the application id
  96. #define ESP_APP_ID_MAX 0x7fff
  97. #define ESP_BD_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x"
  98. #define ESP_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]
  99. #ifdef __cplusplus
  100. }
  101. #endif
  102. #endif /* __ESP_BT_DEFS_H__ */