bluetooth.h 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276
  1. /*
  2. * Copyright (C) 2015 BlueKitchen GmbH
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the copyright holders nor the names of
  14. * contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. * 4. Any redistribution, use, or modification is done solely for
  17. * personal benefit and not for any commercial purpose or for
  18. * monetary gain.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
  21. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  23. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
  24. * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  25. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  26. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  27. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  28. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  29. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  30. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31. * SUCH DAMAGE.
  32. *
  33. * Please inquire about commercial licensing options at
  34. * contact@bluekitchen-gmbh.com
  35. *
  36. */
  37. /*
  38. * bluetooth.h
  39. *
  40. * Numbers defined or derived from the official Bluetooth specification
  41. */
  42. #ifndef __BLUETOOTH_H
  43. #define __BLUETOOTH_H
  44. #include <stdint.h>
  45. /**
  46. * @brief hci connection handle type
  47. */
  48. typedef uint16_t hci_con_handle_t;
  49. /**
  50. * @brief Length of a bluetooth device address.
  51. */
  52. #define BD_ADDR_LEN 6
  53. /**
  54. * @brief Bluetooth address
  55. */
  56. typedef uint8_t bd_addr_t[BD_ADDR_LEN];
  57. /**
  58. * Address types
  59. * @note: BTstack uses a custom addr type to refer to classic ACL and SCO devices
  60. */
  61. typedef enum {
  62. BD_ADDR_TYPE_LE_PUBLIC = 0,
  63. BD_ADDR_TYPE_LE_RANDOM = 1,
  64. BD_ADDR_TYPE_LE_PRIVAT_FALLBACK_PUBLIC = 2,
  65. BD_ADDR_TYPE_LE_PRIVAT_FALLBACK_RANDOM = 3,
  66. BD_ADDR_TYPE_SCO = 0xfe,
  67. BD_ADDR_TYPE_CLASSIC = 0xff,
  68. BD_ADDR_TYPE_UNKNOWN = 0xfe
  69. } bd_addr_type_t;
  70. /**
  71. * @brief link key
  72. */
  73. #define LINK_KEY_LEN 16
  74. #define LINK_KEY_STR_LEN (LINK_KEY_LEN*2)
  75. typedef uint8_t link_key_t[LINK_KEY_LEN];
  76. /**
  77. * @brief link key type
  78. */
  79. typedef enum {
  80. COMBINATION_KEY = 0, // standard pairing
  81. LOCAL_UNIT_KEY, // ?
  82. REMOTE_UNIT_KEY, // ?
  83. DEBUG_COMBINATION_KEY, // SSP with debug
  84. UNAUTHENTICATED_COMBINATION_KEY_GENERATED_FROM_P192, // SSP Simple Pairing
  85. AUTHENTICATED_COMBINATION_KEY_GENERATED_FROM_P192, // SSP Passkey, Number confirm, OOB
  86. CHANGED_COMBINATION_KEY, // Link key changed using Change Connection Lnk Key
  87. UNAUTHENTICATED_COMBINATION_KEY_GENERATED_FROM_P256, // SSP Simpe Pairing
  88. AUTHENTICATED_COMBINATION_KEY_GENERATED_FROM_P256, // SSP Passkey, Number confirm, OOB
  89. } link_key_type_t;
  90. /**
  91. * @brief Inquiry modes
  92. */
  93. typedef enum {
  94. INQUIRY_MODE_STANDARD = 0,
  95. INQUIRY_MODE_RSSI,
  96. INQUIRY_MODE_RSSI_AND_EIR,
  97. } inquiry_mode_t;
  98. /*
  99. * @brief L2CAP Segmentation And Reassembly packet type in I-Frames
  100. */
  101. typedef enum {
  102. L2CAP_SEGMENTATION_AND_REASSEMBLY_UNSEGMENTED_L2CAP_SDU = 0,
  103. L2CAP_SEGMENTATION_AND_REASSEMBLY_START_OF_L2CAP_SDU,
  104. L2CAP_SEGMENTATION_AND_REASSEMBLY_END_OF_L2CAP_SDU,
  105. L2CAP_SEGMENTATION_AND_REASSEMBLY_CONTINUATION_OF_L2CAP_SDU
  106. } l2cap_segmentation_and_reassembly_t;
  107. /*
  108. * @brief L2CAP Supervisory function in S-Frames
  109. */
  110. typedef enum {
  111. L2CAP_SUPERVISORY_FUNCTION_RR_RECEIVER_READY = 0,
  112. L2CAP_SUPERVISORY_FUNCTION_REJ_REJECT,
  113. L2CAP_SUPERVISORY_FUNCTION_RNR_RECEIVER_NOT_READY,
  114. L2CAP_SUPERVISORY_FUNCTION_SREJ_SELECTIVE_REJECT
  115. } l2cap_supervisory_function_t;
  116. /**
  117. * @brief L2CAP Information Types used in Information Request & Response
  118. */
  119. typedef enum {
  120. L2CAP_INFO_TYPE_CONNECTIONLESS_MTU = 1,
  121. L2CAP_INFO_TYPE_EXTENDED_FEATURES_SUPPORTED,
  122. L2CAP_INFO_TYPE_FIXED_CHANNELS_SUPPORTED,
  123. } l2cap_info_type_t;
  124. /**
  125. * @brief L2CAP Configuration Option Types used in Configurateion Request & Response
  126. */
  127. typedef enum {
  128. L2CAP_CONFIG_OPTION_TYPE_MAX_TRANSMISSION_UNIT = 1,
  129. L2CAP_CONFIG_OPTION_TYPE_FLUSH_TIMEOUT,
  130. L2CAP_CONFIG_OPTION_TYPE_QUALITY_OF_SERVICE,
  131. L2CAP_CONFIG_OPTION_TYPE_RETRANSMISSION_AND_FLOW_CONTROL,
  132. L2CAP_CONFIG_OPTION_TYPE_FRAME_CHECK_SEQUENCE,
  133. L2CAP_CONFIG_OPTION_TYPE_EXTENDED_FLOW_SPECIFICATION,
  134. L2CAP_CONFIG_OPTION_TYPE_EXTENDED_WINDOW_SIZE,
  135. } l2cap_config_option_type_t;
  136. /**
  137. * HCI Transport
  138. */
  139. /**
  140. * packet types - used in BTstack and over the H4 UART interface
  141. */
  142. #define HCI_COMMAND_DATA_PACKET 0x01
  143. #define HCI_ACL_DATA_PACKET 0x02
  144. #define HCI_SCO_DATA_PACKET 0x03
  145. #define HCI_EVENT_PACKET 0x04
  146. // packet header sizes
  147. #define HCI_CMD_HEADER_SIZE 3
  148. #define HCI_ACL_HEADER_SIZE 4
  149. #define HCI_SCO_HEADER_SIZE 3
  150. #define HCI_EVENT_HEADER_SIZE 2
  151. /**
  152. * HCI Layer
  153. */
  154. //
  155. // Error Codes rfom Bluetooth Core Specification
  156. //
  157. /* ENUM_START: BLUETOOTH_ERROR_CODE */
  158. #define ERROR_CODE_SUCCESS 0x00
  159. #define ERROR_CODE_UNKNOWN_HCI_COMMAND 0x01
  160. #define ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER 0x02
  161. #define ERROR_CODE_HARDWARE_FAILURE 0x03
  162. #define ERROR_CODE_PAGE_TIMEOUT 0x04
  163. #define ERROR_CODE_AUTHENTICATION_FAILURE 0x05
  164. #define ERROR_CODE_PIN_OR_KEY_MISSING 0x06
  165. #define ERROR_CODE_MEMORY_CAPACITY_EXCEEDED 0x07
  166. #define ERROR_CODE_CONNECTION_TIMEOUT 0x08
  167. #define ERROR_CODE_CONNECTION_LIMIT_EXCEEDED 0x09
  168. #define ERROR_CODE_SYNCHRONOUS_CONNECTION_LIMIT_TO_A_DEVICE_EXCEEDED 0x0A
  169. #define ERROR_CODE_ACL_CONNECTION_ALREADY_EXISTS 0x0B
  170. #define ERROR_CODE_COMMAND_DISALLOWED 0x0C
  171. #define ERROR_CODE_CONNECTION_REJECTED_DUE_TO_LIMITED_RESOURCES 0x0D
  172. #define ERROR_CODE_CONNECTION_REJECTED_DUE_TO_SECURITY_REASONS 0x0E
  173. #define ERROR_CODE_CONNECTION_REJECTED_DUE_TO_UNACCEPTABLE_BD_ADDR 0x0F
  174. #define ERROR_CODE_CONNECTION_ACCEPT_TIMEOUT_EXCEEDED 0x10
  175. #define ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE 0x11
  176. #define ERROR_CODE_INVALID_HCI_COMMAND_PARAMETERS 0x12
  177. #define ERROR_CODE_REMOTE_USER_TERMINATED_CONNECTION 0x13
  178. #define ERROR_CODE_REMOTE_DEVICE_TERMINATED_CONNECTION_DUE_TO_LOW_RESOURCES 0x14
  179. #define ERROR_CODE_REMOTE_DEVICE_TERMINATED_CONNECTION_DUE_TO_POWER_OFF 0x15
  180. #define ERROR_CODE_CONNECTION_TERMINATED_BY_LOCAL_HOST 0x16
  181. #define ERROR_CODE_REPEATED_ATTEMPTS 0x17
  182. #define ERROR_CODE_PAIRING_NOT_ALLOWED 0x18
  183. #define ERROR_CODE_UNKNOWN_LMP_PDU 0x19
  184. #define ERROR_CODE_UNSUPPORTED_REMOTE_FEATURE_UNSUPPORTED_LMP_FEATURE 0x1A
  185. #define ERROR_CODE_SCO_OFFSET_REJECTED 0x1B
  186. #define ERROR_CODE_SCO_INTERVAL_REJECTED 0x1C
  187. #define ERROR_CODE_SCO_AIR_MODE_REJECTED 0x1D
  188. #define ERROR_CODE_INVALID_LMP_PARAMETERS_INVALID_LL_PARAMETERS 0x1E
  189. #define ERROR_CODE_UNSPECIFIED_ERROR 0x1F
  190. #define ERROR_CODE_UNSUPPORTED_LMP_PARAMETER_VALUE_UNSUPPORTED_LL_PARAMETER_VALUE 0x20
  191. #define ERROR_CODE_ROLE_CHANGE_NOT_ALLOWED 0x21
  192. #define ERROR_CODE_LMP_RESPONSE_TIMEOUT_LL_RESPONSE_TIMEOUT 0x22
  193. #define ERROR_CODE_LMP_ERROR_TRANSACTION_COLLISION 0x23
  194. #define ERROR_CODE_LMP_PDU_NOT_ALLOWED 0x24
  195. #define ERROR_CODE_ENCRYPTION_MODE_NOT_ACCEPTABLE 0x25
  196. #define ERROR_CODE_LINK_KEY_CANNOT_BE_CHANGED 0x26
  197. #define ERROR_CODE_REQUESTED_QOS_NOT_SUPPORTED 0x27
  198. #define ERROR_CODE_INSTANT_PASSED 0x28
  199. #define ERROR_CODE_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED 0x29
  200. #define ERROR_CODE_DIFFERENT_TRANSACTION_COLLISION 0x2A
  201. #define ERROR_CODE_RESERVED 0x2B
  202. #define ERROR_CODE_QOS_UNACCEPTABLE_PARAMETER 0x2C
  203. #define ERROR_CODE_QOS_REJECTED 0x2D
  204. #define ERROR_CODE_CHANNEL_CLASSIFICATION_NOT_SUPPORTED 0x2E
  205. #define ERROR_CODE_INSUFFICIENT_SECURITY 0x2F
  206. #define ERROR_CODE_PARAMETER_OUT_OF_MANDATORY_RANGE 0x30
  207. // #define ERROR_CODE_RESERVED
  208. #define ERROR_CODE_ROLE_SWITCH_PENDING 0x32
  209. // #define ERROR_CODE_RESERVED
  210. #define ERROR_CODE_RESERVED_SLOT_VIOLATION 0x34
  211. #define ERROR_CODE_ROLE_SWITCH_FAILED 0x35
  212. #define ERROR_CODE_EXTENDED_INQUIRY_RESPONSE_TOO_LARGE 0x36
  213. #define ERROR_CODE_SECURE_SIMPLE_PAIRING_NOT_SUPPORTED_BY_HOST 0x37
  214. #define ERROR_CODE_HOST_BUSY_PAIRING 0x38
  215. #define ERROR_CODE_CONNECTION_REJECTED_DUE_TO_NO_SUITABLE_CHANNEL_FOUND 0x39
  216. #define ERROR_CODE_CONTROLLER_BUSY 0x3A
  217. #define ERROR_CODE_UNACCEPTABLE_CONNECTION_PARAMETERS 0x3B
  218. #define ERROR_CODE_DIRECTED_ADVERTISING_TIMEOUT 0x3C
  219. #define ERROR_CODE_CONNECTION_TERMINATED_DUE_TO_MIC_FAILURE 0x3D
  220. #define ERROR_CODE_CONNECTION_FAILED_TO_BE_ESTABLISHED 0x3E
  221. #define ERROR_CODE_MAC_CONNECTION_FAILED 0x3F
  222. #define ERROR_CODE_COARSE_CLOCK_ADJUSTMENT_REJECTED_BUT_WILL_TRY_TO_ADJUST_USING_CLOCK_DRAGGING 0x40
  223. /* ENUM_END */
  224. /* ENUM_START: AVRCP_BROWSING_ERROR_CODE */
  225. #define AVRCP_BROWSING_ERROR_CODE_INVALID_COMMAND 0x00 // Sent if TG received a PDU that it did not understand. Valid for All.
  226. #define AVRCP_BROWSING_ERROR_CODE_INVALID_PARAMETER 0x01 // Sent if the TG received a PDU with a parameter ID that it did not understand. Sent if there is only one parameter ID in the PDU. Valid for All.
  227. #define AVRCP_BROWSING_ERROR_CODE_SPECIFIED_PARAMETER_NOT_FOUND 0x02 // Sent if the parameter ID is understood, but content is wrong or corrupted. Valid for All.
  228. #define AVRCP_BROWSING_ERROR_CODE_INTERNAL_ERROR 0x03 // Sent if there are error conditions not covered by a more specific error code. Valid for All.
  229. #define AVRCP_BROWSING_ERROR_CODE_SUCCESS 0x04 // This is the status that should be returned if the operation was successful. Valid for All except where the response CType is AV/C REJECTED.
  230. #define AVRCP_BROWSING_ERROR_CODE_UID_CHANGED 0x05 // The UIDs on the device have changed. Valid for All.
  231. #define AVRCP_BROWSING_ERROR_CODE_RESERVED_06 0x06 // Valid for All.
  232. #define AVRCP_BROWSING_ERROR_CODE_INVALID_DIRECTION 0x07 // The Direction parameter is invalid. Valid for Change Path.
  233. #define AVRCP_BROWSING_ERROR_CODE_NOT_A_DIRECTORY 0x08 // The UID provided does not refer to a folder item. Valid for Change Path.
  234. #define AVRCP_BROWSING_ERROR_CODE_DOES_NOT_EXIST 0x09 // The UID provided does not refer to any currently valid. Valid for Change Path, PlayItem, AddToNowPlaying, GetItemAttributes.
  235. #define AVRCP_BROWSING_ERROR_CODE_INVALID_SCOPE 0x0a // The scope parameter is invalid. Valid for GetFolderItems, PlayItem, AddToNowPlayer, GetItemAttributes,.
  236. #define AVRCP_BROWSING_ERROR_CODE_RANGE_OUT_OF_BOUNDS 0x0b // The start of range provided is not valid. Valid for GetFolderItems.
  237. #define AVRCP_BROWSING_ERROR_CODE_UID_IS_A_DIRECTORY 0x0c // The UID provided refers to a directory, which cannot be handled by this media player. Valid for PlayItem, AddToNowPlaying.
  238. #define AVRCP_BROWSING_ERROR_CODE_MEDIA_IN_USES 0x0d // The media is not able to be used for this operation at this time. Valid for PlayItem, AddToNowPlaying.
  239. #define AVRCP_BROWSING_ERROR_CODE_NOW_PLAYING_LIST_FULL 0x0e // No more items can be added to the Now Playing List. Valid for AddToNowPlaying.
  240. #define AVRCP_BROWSING_ERROR_CODE_SEARCH_NOT_SUPPORTED 0x0f // The Browsed Media Player does not support search. Valid for Search.
  241. #define AVRCP_BROWSING_ERROR_CODE_SEARCH_IN_PROGRESS 0x10 // A search operation is already in progress. Valid for Search.
  242. #define AVRCP_BROWSING_ERROR_CODE_INVALID_PLAYER_ID 0x11 // The specified Player Id does not refer to a valid player. Valid for SetAddressedPlayer, SetBrowsedPlayer.
  243. #define AVRCP_BROWSING_ERROR_CODE_PLAYER_NOT_BROWSABLE 0x12 // The Player Id supplied refers to a Media Player which does not support browsing. Valid for SetBrowsedPlayer.
  244. #define AVRCP_BROWSING_ERROR_CODE_PLAYER_NOT_ADDRESSED 0x13 // The Player Id supplied refers to a player which is not currently addressed, and the command is not able to be performed if the player is not set as addressed. Valid for Search SetBrowsedPlayer.
  245. #define AVRCP_BROWSING_ERROR_CODE_NO_VALID_SEARCH_RESULTS 0x14 // The Search result list does not contain valid entries, e.g. after being invalidated due to change of browsed player. Valid for GetFolderItems.
  246. #define AVRCP_BROWSING_ERROR_CODE_NO_AVAILABLE_PLAYERS 0x15 // Valid for All.
  247. #define AVRCP_BROWSING_ERROR_CODE_ADDRESSED_PLAYER_CHANGED 0x16 // Valid for Register Notification.
  248. // 0x17-0xff Reserved
  249. /* ENUM_END */
  250. // HCI roles
  251. #define HCI_ROLE_MASTER 0
  252. #define HCI_ROLE_SLAVE 1
  253. // packet sizes (max payload)
  254. #define HCI_ACL_DM1_SIZE 17
  255. #define HCI_ACL_DH1_SIZE 27
  256. #define HCI_ACL_2DH1_SIZE 54
  257. #define HCI_ACL_3DH1_SIZE 83
  258. #define HCI_ACL_DM3_SIZE 121
  259. #define HCI_ACL_DH3_SIZE 183
  260. #define HCI_ACL_DM5_SIZE 224
  261. #define HCI_ACL_DH5_SIZE 339
  262. #define HCI_ACL_2DH3_SIZE 367
  263. #define HCI_ACL_3DH3_SIZE 552
  264. #define HCI_ACL_2DH5_SIZE 679
  265. #define HCI_ACL_3DH5_SIZE 1021
  266. #define HCI_EVENT_PAYLOAD_SIZE 255
  267. #define HCI_CMD_PAYLOAD_SIZE 255
  268. #define LE_ADVERTISING_DATA_SIZE 31
  269. // Link Policy Settings
  270. #define LM_LINK_POLICY_DISABLE_ALL_LM_MODES 0
  271. #define LM_LINK_POLICY_ENABLE_ROLE_SWITCH 1
  272. #define LM_LINK_POLICY_ENABLE_HOLD_MODE 2
  273. #define LM_LINK_POLICY_ENABLE_SNIFF_MODE 3
  274. // ACL Connection Modes
  275. #define ACL_CONNECTION_MODE_ACTIVE 0
  276. #define ACL_CONNECTION_MODE_HOLD 1
  277. #define ACL_CONNECTION_MODE_SNIFF 2
  278. /**
  279. * Default INQ Mode
  280. */
  281. #define GAP_IAC_GENERAL_INQUIRY 0x9E8B33L // General/Unlimited Inquiry Access Code (GIAC)
  282. #define GAP_IAC_LIMITED_INQUIRY 0x9E8B00L // Limited Dedicated Inquiry Access Code (LIAC)
  283. /**
  284. * SSP IO Capabilities
  285. */
  286. #define SSP_IO_CAPABILITY_DISPLAY_ONLY 0
  287. #define SSP_IO_CAPABILITY_DISPLAY_YES_NO 1
  288. #define SSP_IO_CAPABILITY_KEYBOARD_ONLY 2
  289. #define SSP_IO_CAPABILITY_NO_INPUT_NO_OUTPUT 3
  290. #define SSP_IO_CAPABILITY_UNKNOWN 0xff
  291. /**
  292. * SSP Authentication Requirements, see IO Capability Request Reply Commmand
  293. */
  294. // Numeric comparison with automatic accept allowed.
  295. #define SSP_IO_AUTHREQ_MITM_PROTECTION_NOT_REQUIRED_NO_BONDING 0x00
  296. // Use IO Capabilities to deter- mine authentication procedure
  297. #define SSP_IO_AUTHREQ_MITM_PROTECTION_REQUIRED_NO_BONDING 0x01
  298. // Numeric compar- ison with automatic accept allowed.
  299. #define SSP_IO_AUTHREQ_MITM_PROTECTION_NOT_REQUIRED_DEDICATED_BONDING 0x02
  300. // Use IO Capabilities to determine authentication procedure
  301. #define SSP_IO_AUTHREQ_MITM_PROTECTION_REQUIRED_DEDICATED_BONDING 0x03
  302. // Numeric Compari- son with automatic accept allowed.
  303. #define SSP_IO_AUTHREQ_MITM_PROTECTION_NOT_REQUIRED_GENERAL_BONDING 0x04
  304. // Use IO capabilities to determine authentication procedure.
  305. #define SSP_IO_AUTHREQ_MITM_PROTECTION_REQUIRED_GENERAL_BONDING 0x05
  306. // OGFs
  307. #define OGF_LINK_CONTROL 0x01
  308. #define OGF_LINK_POLICY 0x02
  309. #define OGF_CONTROLLER_BASEBAND 0x03
  310. #define OGF_INFORMATIONAL_PARAMETERS 0x04
  311. #define OGF_STATUS_PARAMETERS 0x05
  312. #define OGF_TESTING 0x06
  313. #define OGF_LE_CONTROLLER 0x08
  314. #define OGF_VENDOR 0x3f
  315. // Events from host controller to host
  316. /**
  317. * @format 1
  318. * @param status
  319. */
  320. #define HCI_EVENT_INQUIRY_COMPLETE 0x01
  321. /**
  322. * @format 1B11132
  323. * @param num_responses
  324. * @param bd_addr
  325. * @param page_scan_repetition_mode
  326. * @param reserved1
  327. * @param reserved2
  328. * @param class_of_device
  329. * @param clock_offset
  330. */
  331. #define HCI_EVENT_INQUIRY_RESULT 0x02
  332. /**
  333. * @format 12B11
  334. * @param status
  335. * @param connection_handle
  336. * @param bd_addr
  337. * @param link_type
  338. * @param encryption_enabled
  339. */
  340. #define HCI_EVENT_CONNECTION_COMPLETE 0x03
  341. /**
  342. * @format B31
  343. * @param bd_addr
  344. * @param class_of_device
  345. * @param link_type
  346. */
  347. #define HCI_EVENT_CONNECTION_REQUEST 0x04
  348. /**
  349. * @format 121
  350. * @param status
  351. * @param connection_handle
  352. * @param reason
  353. */
  354. #define HCI_EVENT_DISCONNECTION_COMPLETE 0x05
  355. /**
  356. * @format 12
  357. * @param status
  358. * @param connection_handle
  359. */
  360. #define HCI_EVENT_AUTHENTICATION_COMPLETE 0x06
  361. // HCI_EVENT_AUTHENTICATION_COMPLETE_EVENT is deprecated, use HCI_EVENT_AUTHENTICATION_COMPLETE instead
  362. #define HCI_EVENT_AUTHENTICATION_COMPLETE_EVENT HCI_EVENT_AUTHENTICATION_COMPLETE
  363. /**
  364. * @format 1BN
  365. * @param status
  366. * @param bd_addr
  367. * @param remote_name
  368. */
  369. #define HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE 0x07
  370. /**
  371. * @format 121
  372. * @param status
  373. * @param connection_handle
  374. * @param encryption_enabled
  375. */
  376. #define HCI_EVENT_ENCRYPTION_CHANGE 0x08
  377. /**
  378. * @format 12
  379. * @param status
  380. * @param connection_handle
  381. */
  382. #define HCI_EVENT_CHANGE_CONNECTION_LINK_KEY_COMPLETE 0x09
  383. /**
  384. * @format 121
  385. * @param status
  386. * @param connection_handle
  387. * @param key_flag
  388. */
  389. #define HCI_EVENT_MASTER_LINK_KEY_COMPLETE 0x0A
  390. #define HCI_EVENT_READ_REMOTE_SUPPORTED_FEATURES_COMPLETE 0x0B
  391. #define HCI_EVENT_READ_REMOTE_VERSION_INFORMATION_COMPLETE 0x0C
  392. #define HCI_EVENT_QOS_SETUP_COMPLETE 0x0D
  393. /**
  394. * @format 12R
  395. * @param num_hci_command_packets
  396. * @param command_opcode
  397. * @param return_parameters
  398. */
  399. #define HCI_EVENT_COMMAND_COMPLETE 0x0E
  400. /**
  401. * @format 112
  402. * @param status
  403. * @param num_hci_command_packets
  404. * @param command_opcode
  405. */
  406. #define HCI_EVENT_COMMAND_STATUS 0x0F
  407. /**
  408. * @format 1
  409. * @param hardware_code
  410. */
  411. #define HCI_EVENT_HARDWARE_ERROR 0x10
  412. #define HCI_EVENT_FLUSH_OCCURRED 0x11
  413. /**
  414. * @format 1B1
  415. * @param status
  416. * @param bd_addr
  417. * @param role
  418. */
  419. #define HCI_EVENT_ROLE_CHANGE 0x12
  420. // TODO: number_of_handles 1, connection_handle[H*i], hc_num_of_completed_packets[2*i]
  421. #define HCI_EVENT_NUMBER_OF_COMPLETED_PACKETS 0x13
  422. /**
  423. * @format 1H12
  424. * @param status
  425. * @param handle
  426. * @param mode
  427. * @param interval
  428. */
  429. #define HCI_EVENT_MODE_CHANGE 0x14
  430. // TODO: num_keys, bd_addr[B*i], link_key[16 octets * i]
  431. #define HCI_EVENT_RETURN_LINK_KEYS 0x15
  432. /**
  433. * @format B
  434. * @param bd_addr
  435. */
  436. #define HCI_EVENT_PIN_CODE_REQUEST 0x16
  437. /**
  438. * @format B
  439. * @param bd_addr
  440. */
  441. #define HCI_EVENT_LINK_KEY_REQUEST 0x17
  442. // TODO: bd_addr B, link_key 16octets, key_type 1
  443. #define HCI_EVENT_LINK_KEY_NOTIFICATION 0x18
  444. /**
  445. * @format 1
  446. * @param link_type
  447. */
  448. #define HCI_EVENT_DATA_BUFFER_OVERFLOW 0x1A
  449. /**
  450. * @format H1
  451. * @param handle
  452. * @param lmp_max_slots
  453. */
  454. #define HCI_EVENT_MAX_SLOTS_CHANGED 0x1B
  455. /**
  456. * @format 1H2
  457. * @param status
  458. * @param handle
  459. * @param clock_offset
  460. */
  461. #define HCI_EVENT_READ_CLOCK_OFFSET_COMPLETE 0x1C
  462. /**
  463. * @format 1H2
  464. * @param status
  465. * @param handle
  466. * @param packet_types
  467. * @pnote packet_type is in plural to avoid clash with Java binding Packet.getPacketType()
  468. */
  469. #define HCI_EVENT_CONNECTION_PACKET_TYPE_CHANGED 0x1D
  470. /**
  471. * @format 1B11321
  472. * @param num_responses
  473. * @param bd_addr
  474. * @param page_scan_repetition_mode
  475. * @param reserved
  476. * @param class_of_device
  477. * @param clock_offset
  478. * @param rssi
  479. */
  480. #define HCI_EVENT_INQUIRY_RESULT_WITH_RSSI 0x22
  481. /**
  482. * @format 1HB111221
  483. * @param status
  484. * @param handle
  485. * @param bd_addr
  486. * @param link_type
  487. * @param transmission_interval
  488. * @param retransmission_interval
  489. * @param rx_packet_length
  490. * @param tx_packet_length
  491. * @param air_mode
  492. */
  493. #define HCI_EVENT_SYNCHRONOUS_CONNECTION_COMPLETE 0x2C
  494. // TODO: serialize extended_inquiry_response and provide parser
  495. /**
  496. * @format 1B11321
  497. * @param num_responses
  498. * @param bd_addr
  499. * @param page_scan_repetition_mode
  500. * @param reserved
  501. * @param class_of_device
  502. * @param clock_offset
  503. * @param rssi
  504. */
  505. #define HCI_EVENT_EXTENDED_INQUIRY_RESPONSE 0x2F
  506. /**
  507. * @format 1H
  508. * @param status
  509. * @param handle
  510. */
  511. #define HCI_EVENT_ENCRYPTION_KEY_REFRESH_COMPLETE 0x30
  512. #define HCI_EVENT_IO_CAPABILITY_REQUEST 0x31
  513. #define HCI_EVENT_IO_CAPABILITY_RESPONSE 0x32
  514. /**
  515. * @format B4
  516. * @param bd_addr
  517. * @param numeric_value
  518. */
  519. #define HCI_EVENT_USER_CONFIRMATION_REQUEST 0x33
  520. /**
  521. * @format B
  522. * @param bd_addr
  523. */
  524. #define HCI_EVENT_USER_PASSKEY_REQUEST 0x34
  525. /**
  526. * @format B
  527. * @param bd_addr
  528. */
  529. #define HCI_EVENT_REMOTE_OOB_DATA_REQUEST 0x35
  530. /**
  531. * @format 1B
  532. * @param status
  533. * @param bd_addr
  534. */
  535. #define HCI_EVENT_SIMPLE_PAIRING_COMPLETE 0x36
  536. #define HCI_EVENT_LE_META 0x3E
  537. // last used HCI_EVENT in 2.1 is 0x3d
  538. // last used HCI_EVENT in 4.1 is 0x57
  539. #define HCI_EVENT_VENDOR_SPECIFIC 0xFF
  540. /**
  541. * @format 11H11B2221
  542. * @param subevent_code
  543. * @param status
  544. * @param connection_handle
  545. * @param role
  546. * @param peer_address_type
  547. * @param peer_address
  548. * @param conn_interval
  549. * @param conn_latency
  550. * @param supervision_timeout
  551. * @param master_clock_accuracy
  552. */
  553. #define HCI_SUBEVENT_LE_CONNECTION_COMPLETE 0x01
  554. // array of advertisements, not handled by event accessor generator
  555. #define HCI_SUBEVENT_LE_ADVERTISING_REPORT 0x02
  556. /**
  557. * @format 11H222
  558. * @param subevent_code
  559. * @param status
  560. * @param connection_handle
  561. * @param conn_interval
  562. * @param conn_latency
  563. * @param supervision_timeout
  564. */
  565. #define HCI_SUBEVENT_LE_CONNECTION_UPDATE_COMPLETE 0x03
  566. /**
  567. * @format 1HD2
  568. * @param subevent_code
  569. * @param connection_handle
  570. * @param random_number
  571. * @param encryption_diversifier
  572. */
  573. #define HCI_SUBEVENT_LE_READ_REMOTE_USED_FEATURES_COMPLETE 0x04
  574. /**
  575. * @format 1HD2
  576. * @param subevent_code
  577. * @param connection_handle
  578. * @param random_number
  579. * @param encryption_diversifier
  580. */
  581. #define HCI_SUBEVENT_LE_LONG_TERM_KEY_REQUEST 0x05
  582. /**
  583. * @format 1H2222
  584. * @param subevent_code
  585. * @param connection_handle
  586. * @param interval_min
  587. * @param interval_max
  588. * @param latency
  589. * @param timeout
  590. */
  591. #define HCI_SUBEVENT_LE_REMOTE_CONNECTION_PARAMETER_REQUEST 0x06
  592. /**
  593. * @format 1H2222
  594. * @param subevent_code
  595. * @param connection_handle
  596. * @param max_tx_octets
  597. * @param max_tx_time
  598. * @param max_rx_octets
  599. * @param max_rx_time
  600. */
  601. #define HCI_SUBEVENT_LE_DATA_LENGTH_CHANGE 0x07
  602. /**
  603. * @format 11QQ
  604. * @param subevent_code
  605. * @param status
  606. * @param dhkey_x x coordinate of P256 public key
  607. * @param dhkey_y y coordinate of P256 public key
  608. */
  609. #define HCI_SUBEVENT_LE_READ_LOCAL_P256_PUBLIC_KEY_COMPLETE 0x08
  610. /**
  611. * @format 11Q
  612. * @param subevent_code
  613. * @param status
  614. * @param dhkey Diffie-Hellman key
  615. */
  616. #define HCI_SUBEVENT_LE_GENERATE_DHKEY_COMPLETE 0x09
  617. /**
  618. * @format 11H11BBB2221
  619. * @param subevent_code
  620. * @param status
  621. * @param connection_handle
  622. * @param role
  623. * @param peer_address_type
  624. * @param perr_addresss
  625. * @param local_resolvable_private_addres
  626. * @param peer_resolvable_private_addres
  627. * @param conn_interval
  628. * @param conn_latency
  629. * @param supervision_timeout
  630. * @param master_clock_accuracy
  631. */
  632. #define HCI_SUBEVENT_LE_ENHANCED_CONNECTION_COMPLETE 0x0A
  633. // array of advertisements, not handled by event accessor generator
  634. #define HCI_SUBEVENT_LE_DIRECT_ADVERTISING_REPORT 0x0B
  635. /**
  636. * L2CAP Layer
  637. */
  638. #define L2CAP_HEADER_SIZE 4
  639. #define L2CAP_SIG_ID_INVALID 0
  640. // size of HCI ACL + L2CAP Header for regular data packets (8)
  641. #define COMPLETE_L2CAP_HEADER (HCI_ACL_HEADER_SIZE + L2CAP_HEADER_SIZE)
  642. // minimum signaling MTU
  643. #define L2CAP_MINIMAL_MTU 48
  644. #define L2CAP_DEFAULT_MTU 672
  645. // Minimum/default MTU
  646. #define L2CAP_LE_DEFAULT_MTU 23
  647. // L2CAP Fixed Channel IDs
  648. #define L2CAP_CID_SIGNALING 0x0001
  649. #define L2CAP_CID_CONNECTIONLESS_CHANNEL 0x0002
  650. #define L2CAP_CID_ATTRIBUTE_PROTOCOL 0x0004
  651. #define L2CAP_CID_SIGNALING_LE 0x0005
  652. #define L2CAP_CID_SECURITY_MANAGER_PROTOCOL 0x0006
  653. // L2CAP Configuration Result Codes
  654. #define L2CAP_CONF_RESULT_SUCCESS 0x0000
  655. #define L2CAP_CONF_RESULT_UNACCEPTABLE_PARAMETERS 0x0001
  656. #define L2CAP_CONF_RESULT_REJECT 0x0002
  657. #define L2CAP_CONF_RESULT_UNKNOWN_OPTIONS 0x0003
  658. #define L2CAP_CONF_RESULT_PENDING 0x0004
  659. #define L2CAP_CONF_RESULT_FLOW_SPEC_REJECTED 0x0005
  660. // L2CAP Reject Result Codes
  661. #define L2CAP_REJ_CMD_UNKNOWN 0x0000
  662. // Response Timeout eXpired
  663. #define L2CAP_RTX_TIMEOUT_MS 10000
  664. // Extended Response Timeout eXpired
  665. #define L2CAP_ERTX_TIMEOUT_MS 120000
  666. //
  667. // Fixed PSM numbers from https://www.bluetooth.com/specifications/assigned-numbers/logical-link-control
  668. //
  669. // @TODO: replace with BLUETOOTH_PROTOCOL_xxx in rest of code
  670. #define PSM_SDP BLUETOOTH_PROTOCOL_SDP
  671. #define PSM_RFCOMM BLUETOOTH_PROTOCOL_RFCOMM
  672. #define PSM_BNEP BLUETOOTH_PROTOCOL_BNEP
  673. // @TODO: scrape PSMs Bluetooth SIG site and put in bluetooth_psm.h or bluetooth_l2cap.h
  674. #define PSM_HID_CONTROL 0x11
  675. #define PSM_HID_INTERRUPT 0x13
  676. #define PSM_IPSP 0x23
  677. /**
  678. * SDP Protocol
  679. */
  680. // PDU Types
  681. typedef enum {
  682. SDP_Invalid = 0,
  683. SDP_ErrorResponse = 1,
  684. SDP_ServiceSearchRequest,
  685. SDP_ServiceSearchResponse,
  686. SDP_ServiceAttributeRequest,
  687. SDP_ServiceAttributeResponse,
  688. SDP_ServiceSearchAttributeRequest,
  689. SDP_ServiceSearchAttributeResponse
  690. } SDP_PDU_ID_t;
  691. /* Please use assigned numbers from bluetooth_sdp.h instead for thsese ...*/
  692. // UNIVERSAL ATTRIBUTE DEFINITIONS
  693. #define SDP_ServiceRecordHandle BLUETOOTH_ATTRIBUTE_SERVICE_RECORD_HANDLE
  694. #define SDP_ServiceClassIDList BLUETOOTH_ATTRIBUTE_SERVICE_CLASS_ID_LIST
  695. #define SDP_ServiceRecordState BLUETOOTH_ATTRIBUTE_SERVICE_RECORD_STATE
  696. #define SDP_ServiceID BLUETOOTH_ATTRIBUTE_SERVICE_ID
  697. #define SDP_ProtocolDescriptorList BLUETOOTH_ATTRIBUTE_PROTOCOL_DESCRIPTOR_LIST
  698. #define SDP_BrowseGroupList BLUETOOTH_ATTRIBUTE_BROWSE_GROUP_LIST
  699. #define SDP_LanguageBaseAttributeIDList BLUETOOTH_ATTRIBUTE_LANGUAGE_BASE_ATTRIBUTE_ID_LIST
  700. #define SDP_ServiceInfoTimeToLive BLUETOOTH_ATTRIBUTE_SERVICE_INFO_TIME_TO_LIVE
  701. #define SDP_ServiceAvailability BLUETOOTH_ATTRIBUTE_SERVICE_AVAILABILITY
  702. #define SDP_BluetoothProfileDescriptorList BLUETOOTH_ATTRIBUTE_BLUETOOTH_PROFILE_DESCRIPTOR_LIST
  703. #define SDP_DocumentationURL BLUETOOTH_ATTRIBUTE_DOCUMENTATION_URL
  704. #define SDP_ClientExecutableURL BLUETOOTH_ATTRIBUTE_CLIENT_EXECUTABLE_URL
  705. #define SDP_IconURL BLUETOOTH_ATTRIBUTE_ICON_URL
  706. #define SDP_AdditionalProtocolDescriptorList BLUETOOTH_ATTRIBUTE_ADDITIONAL_PROTOCOL_DESCRIPTOR_LISTS
  707. #define SDP_SupportedFormatsList BLUETOOTH_ATTRIBUTE_SUPPORTED_FORMATS_LIST
  708. // SERVICE CLASSES
  709. #define SDP_OBEXObjectPush BLUETOOTH_SERVICE_CLASS_OBEX_OBJECT_PUSH
  710. #define SDP_OBEXFileTransfer BLUETOOTH_SERVICE_CLASS_OBEX_FILE_TRANSFER
  711. #define SDP_PublicBrowseGroup BLUETOOTH_ATTRIBUTE_PUBLIC_BROWSE_ROOT
  712. #define SDP_HSP BLUETOOTH_SERVICE_CLASS_HEADSET
  713. #define SDP_Headset_AG BLUETOOTH_SERVICE_CLASS_HEADSET_AUDIO_GATEWAY_AG
  714. #define SDP_PANU BLUETOOTH_SERVICE_CLASS_PANU
  715. #define SDP_NAP BLUETOOTH_SERVICE_CLASS_NAP
  716. #define SDP_GN BLUETOOTH_SERVICE_CLASS_GN
  717. #define SDP_Handsfree BLUETOOTH_SERVICE_CLASS_HANDSFREE
  718. #define SDP_HandsfreeAudioGateway BLUETOOTH_SERVICE_CLASS_HANDSFREE_AUDIO_GATEWAY
  719. #define SDP_Headset_HS BLUETOOTH_SERVICE_CLASS_HEADSET_HS
  720. #define SDP_GenericAudio BLUETOOTH_SERVICE_CLASS_GENERIC_AUDIO
  721. // PROTOCOLS
  722. #define SDP_SDPProtocol BLUETOOTH_PROTOCOL_SDP
  723. #define SDP_UDPProtocol BLUETOOTH_PROTOCOL_UDP
  724. #define SDP_RFCOMMProtocol BLUETOOTH_PROTOCOL_RFCOMM
  725. #define SDP_OBEXProtocol BLUETOOTH_PROTOCOL_OBEX
  726. #define SDP_L2CAPProtocol BLUETOOTH_PROTOCOL_L2CAP
  727. #define SDP_BNEPProtocol BLUETOOTH_PROTOCOL_BNEP
  728. #define SDP_AVDTPProtocol BLUETOOTH_PROTOCOL_AVDTP
  729. /** .. until here ..*/
  730. // OFFSETS FOR LOCALIZED ATTRIBUTES - SDP_LanguageBaseAttributeIDList
  731. #define SDP_Offest_ServiceName 0x0000
  732. #define SDP_Offest_ServiceDescription 0x0001
  733. #define SDP_Offest_ProviderName 0x0002
  734. // Device Vendor ID Sources
  735. #define DEVICE_ID_VENDOR_ID_SOURCE_BLUETOOTH 0x0001
  736. #define DEVICE_ID_VENDOR_ID_SOURCE_USB 0x0002
  737. // OBEX
  738. #define SDP_vCard_2_1 0x01
  739. #define SDP_vCard_3_0 0x02
  740. #define SDP_vCal_1_0 0x03
  741. #define SDP_iCal_2_0 0x04
  742. #define SDP_vNote 0x05
  743. #define SDP_vMessage 0x06
  744. #define SDP_OBEXFileTypeAny 0xFF
  745. /**
  746. * RFCOMM Protocol
  747. */
  748. // Control field values bit no. 1 2 3 4 PF 6 7 8
  749. #define BT_RFCOMM_SABM 0x3F // 1 1 1 1 1 1 0 0
  750. #define BT_RFCOMM_UA 0x73 // 1 1 0 0 1 1 1 0
  751. #define BT_RFCOMM_DM 0x0F // 1 1 1 1 0 0 0 0
  752. #define BT_RFCOMM_DM_PF 0x1F // 1 1 1 1 1 0 0 0
  753. #define BT_RFCOMM_DISC 0x53 // 1 1 0 0 1 0 1 0
  754. #define BT_RFCOMM_UIH 0xEF // 1 1 1 1 0 1 1 1
  755. #define BT_RFCOMM_UIH_PF 0xFF // 1 1 1 1 0 1 1 1
  756. // Multiplexer message types
  757. #define BT_RFCOMM_CLD_CMD 0xC3
  758. #define BT_RFCOMM_FCON_CMD 0xA3
  759. #define BT_RFCOMM_FCON_RSP 0xA1
  760. #define BT_RFCOMM_FCOFF_CMD 0x63
  761. #define BT_RFCOMM_FCOFF_RSP 0x61
  762. #define BT_RFCOMM_MSC_CMD 0xE3
  763. #define BT_RFCOMM_MSC_RSP 0xE1
  764. #define BT_RFCOMM_NSC_RSP 0x11
  765. #define BT_RFCOMM_PN_CMD 0x83
  766. #define BT_RFCOMM_PN_RSP 0x81
  767. #define BT_RFCOMM_RLS_CMD 0x53
  768. #define BT_RFCOMM_RLS_RSP 0x51
  769. #define BT_RFCOMM_RPN_CMD 0x93
  770. #define BT_RFCOMM_RPN_RSP 0x91
  771. #define BT_RFCOMM_TEST_CMD 0x23
  772. #define BT_RFCOMM_TEST_RSP 0x21
  773. // Line Status
  774. #define LINE_STATUS_NO_ERROR 0x00
  775. #define LINE_STATUS_OVERRUN_ERROR 0x03
  776. #define LINE_STATUS_PARITY_ERORR 0x05
  777. #define LINE_STATUS_FRAMING_ERROR 0x09
  778. // Modem Status Flags
  779. #define MODEM_STATUS_FC 0x02
  780. #define MODEM_STATUS_RTC 0x04
  781. #define MODEM_STATUS_RTR 0x08
  782. #define MODEM_STATUS_IC 0x40
  783. #define MODEM_STATUS_DV 0x80
  784. typedef enum rpn_baud {
  785. RPN_BAUD_2400 = 0,
  786. RPN_BAUD_4800,
  787. RPN_BAUD_7200,
  788. RPN_BAUD_9600,
  789. RPN_BAUD_19200,
  790. RPN_BAUD_38400,
  791. RPN_BAUD_57600,
  792. RPN_BAUD_115200,
  793. RPN_BAUD_230400
  794. } rpn_baud_t;
  795. typedef enum rpn_data_bits {
  796. RPN_DATA_BITS_5 = 0,
  797. RPN_DATA_BITS_6 = 0,
  798. RPN_DATA_BITS_7 = 0,
  799. RPN_DATA_BITS_8 = 0
  800. } rpn_data_bits_t;
  801. typedef enum rpn_stop_bits {
  802. RPN_STOP_BITS_1_0 = 0,
  803. RPN_STOP_BITS_1_5
  804. } rpn_stop_bits_t;
  805. typedef enum rpn_parity {
  806. RPN_PARITY_NONE = 0,
  807. RPN_PARITY_ODD = 1,
  808. RPN_PARITY_EVEN = 3,
  809. RPN_PARITY_MARK = 5,
  810. RPN_PARITY_SPACE = 7,
  811. } rpn_parity_t;
  812. typedef enum rpn_flow_control {
  813. RPN_FLOW_CONTROL_XONXOFF_ON_INPUT = 1 << 0,
  814. RPN_FLOW_CONTROL_XONXOFF_ON_OUTPUT = 1 << 1,
  815. RPN_FLOW_CONTROL_RTR_ON_INPUT = 1 << 2,
  816. RPN_FLOW_CONTROL_RTR_ON_OUTPUT = 1 << 3,
  817. RPN_FLOW_CONTROL_RTC_ON_INPUT = 1 << 4,
  818. RPN_FLOW_CONTROL_RTC_ON_OUTPUT = 1 << 5,
  819. } rpn_flow_control_t;
  820. #define RPN_PARAM_MASK_0_BAUD 0x01
  821. #define RPN_PARAM_MASK_0_DATA_BITS 0x02
  822. #define RPN_PARAM_MASK_0_STOP_BITS 0x04
  823. #define RPN_PARAM_MASK_0_PARITY 0x08
  824. #define RPN_PARAM_MASK_0_PARITY_TYPE 0x10
  825. #define RPN_PARAM_MASK_0_XON_CHAR 0x20
  826. #define RPN_PARAM_MASK_0_XOFF_CHAR 0x40
  827. #define RPN_PARAM_MASK_0_RESERVED 0x80
  828. // @note: values are identical to rpn_flow_control_t
  829. #define RPN_PARAM_MASK_1_XONOFF_ON_INPUT 0x01
  830. #define RPN_PARAM_MASK_1_XONOFF_ON_OUTPUT 0x02
  831. #define RPN_PARAM_MASK_1_RTR_ON_INPUT 0x04
  832. #define RPN_PARAM_MASK_1_RTR_ON_OUTPUT 0x08
  833. #define RPN_PARAM_MASK_1_RTC_ON_INPUT 0x10
  834. #define RPN_PARAM_MASK_1_RTC_ON_OUTPUT 0x20
  835. #define RPN_PARAM_MASK_1_RESERVED_0 0x40
  836. #define RPN_PARAM_MASK_1_RESERVED_1 0x80
  837. /**
  838. * BNEP Protocol
  839. */
  840. #ifndef ETHER_ADDR_LEN
  841. #define ETHER_ADDR_LEN 6
  842. #endif
  843. #ifndef ETHERTYPE_VLAN
  844. #define ETHERTYPE_VLAN 0x8100 /* IEEE 802.1Q VLAN tag */
  845. #endif
  846. #define BNEP_MTU_MIN 1691
  847. #define BNEP_EXT_FLAG 0x80
  848. #define BNEP_TYPE_MASK 0x7F
  849. #define BNEP_TYPE(header) ((header) & BNEP_TYPE_MASK)
  850. #define BNEP_HEADER_HAS_EXT(x) (((x) & BNEP_EXT_FLAG) == BNEP_EXT_FLAG)
  851. /* BNEP packet types */
  852. #define BNEP_PKT_TYPE_GENERAL_ETHERNET 0x00
  853. #define BNEP_PKT_TYPE_CONTROL 0x01
  854. #define BNEP_PKT_TYPE_COMPRESSED_ETHERNET 0x02
  855. #define BNEP_PKT_TYPE_COMPRESSED_ETHERNET_SOURCE_ONLY 0x03
  856. #define BNEP_PKT_TYPE_COMPRESSED_ETHERNET_DEST_ONLY 0x04
  857. /* BNEP control types */
  858. #define BNEP_CONTROL_TYPE_COMMAND_NOT_UNDERSTOOD 0x00
  859. #define BNEP_CONTROL_TYPE_SETUP_CONNECTION_REQUEST 0x01
  860. #define BNEP_CONTROL_TYPE_SETUP_CONNECTION_RESPONSE 0x02
  861. #define BNEP_CONTROL_TYPE_FILTER_NET_TYPE_SET 0x03
  862. #define BNEP_CONTROL_TYPE_FILTER_NET_TYPE_RESPONSE 0x04
  863. #define BNEP_CONTROL_TYPE_FILTER_MULTI_ADDR_SET 0x05
  864. #define BNEP_CONTROL_TYPE_FILTER_MULTI_ADDR_RESPONSE 0x06
  865. /* BNEP extension header types */
  866. #define BNEP_EXT_HEADER_TYPE_EXTENSION_CONTROL 0x00
  867. /* BNEP setup response codes */
  868. #define BNEP_RESP_SETUP_SUCCESS 0x0000
  869. #define BNEP_RESP_SETUP_INVALID_DEST_UUID 0x0001
  870. #define BNEP_RESP_SETUP_INVALID_SOURCE_UUID 0x0002
  871. #define BNEP_RESP_SETUP_INVALID_SERVICE_UUID_SIZE 0x0003
  872. #define BNEP_RESP_SETUP_CONNECTION_NOT_ALLOWED 0x0004
  873. /* BNEP filter response codes */
  874. #define BNEP_RESP_FILTER_SUCCESS 0x0000
  875. #define BNEP_RESP_FILTER_UNSUPPORTED_REQUEST 0x0001
  876. #define BNEP_RESP_FILTER_ERR_INVALID_RANGE 0x0002
  877. #define BNEP_RESP_FILTER_ERR_TOO_MANY_FILTERS 0x0003
  878. #define BNEP_RESP_FILTER_ERR_SECURITY 0x0004
  879. /**
  880. * PAN Profile
  881. */
  882. typedef enum {
  883. BNEP_SECURITY_NONE = 0x0000,
  884. BNEP_SECURITY_SERVICE_LEVEL_ENFORCED,
  885. BNEP_SECURITY_802_1X
  886. } security_description_t;
  887. typedef enum {
  888. PAN_NET_ACCESS_TYPE_PSTN = 0x0000,
  889. PAN_NET_ACCESS_TYPE_ISDN,
  890. PAN_NET_ACCESS_TYPE_DSL,
  891. PAN_NET_ACCESS_TYPE_CABLE_MODEM,
  892. PAN_NET_ACCESS_TYPE_10MB_ETHERNET,
  893. PAN_NET_ACCESS_TYPE_100MB_ETHERNET,
  894. PAN_NET_ACCESS_TYPE_4MB_TOKEN_RING,
  895. PAN_NET_ACCESS_TYPE_16MB_TOKEN_RING,
  896. PAN_NET_ACCESS_TYPE_100MB_TOKEN_RING,
  897. PAN_NET_ACCESS_TYPE_FDDI,
  898. PAN_NET_ACCESS_TYPE_GSM,
  899. PAN_NET_ACCESS_TYPE_CDMA,
  900. PAN_NET_ACCESS_TYPE_GPRS,
  901. PAN_NET_ACCESS_TYPE_3G,
  902. PAN_NET_ACCESS_TYPE_CELULAR,
  903. PAN_NET_ACCESS_TYPE_OTHER = 0xFFFE,
  904. PAN_NET_ACCESS_TYPE_NONE
  905. } net_access_type_t;
  906. /**
  907. * ATT
  908. */
  909. // Minimum/default MTU
  910. #define ATT_DEFAULT_MTU 23
  911. // MARK: Attribute PDU Opcodes
  912. #define ATT_ERROR_RESPONSE 0x01
  913. #define ATT_EXCHANGE_MTU_REQUEST 0x02
  914. #define ATT_EXCHANGE_MTU_RESPONSE 0x03
  915. #define ATT_FIND_INFORMATION_REQUEST 0x04
  916. #define ATT_FIND_INFORMATION_REPLY 0x05
  917. #define ATT_FIND_BY_TYPE_VALUE_REQUEST 0x06
  918. #define ATT_FIND_BY_TYPE_VALUE_RESPONSE 0x07
  919. #define ATT_READ_BY_TYPE_REQUEST 0x08
  920. #define ATT_READ_BY_TYPE_RESPONSE 0x09
  921. #define ATT_READ_REQUEST 0x0a
  922. #define ATT_READ_RESPONSE 0x0b
  923. #define ATT_READ_BLOB_REQUEST 0x0c
  924. #define ATT_READ_BLOB_RESPONSE 0x0d
  925. #define ATT_READ_MULTIPLE_REQUEST 0x0e
  926. #define ATT_READ_MULTIPLE_RESPONSE 0x0f
  927. #define ATT_READ_BY_GROUP_TYPE_REQUEST 0x10
  928. #define ATT_READ_BY_GROUP_TYPE_RESPONSE 0x11
  929. #define ATT_WRITE_REQUEST 0x12
  930. #define ATT_WRITE_RESPONSE 0x13
  931. #define ATT_PREPARE_WRITE_REQUEST 0x16
  932. #define ATT_PREPARE_WRITE_RESPONSE 0x17
  933. #define ATT_EXECUTE_WRITE_REQUEST 0x18
  934. #define ATT_EXECUTE_WRITE_RESPONSE 0x19
  935. #define ATT_HANDLE_VALUE_NOTIFICATION 0x1b
  936. #define ATT_HANDLE_VALUE_INDICATION 0x1d
  937. #define ATT_HANDLE_VALUE_CONFIRMATION 0x1e
  938. #define ATT_WRITE_COMMAND 0x52
  939. #define ATT_SIGNED_WRITE_COMMAND 0xD2
  940. // MARK: ATT Error Codes
  941. #define ATT_ERROR_INVALID_HANDLE 0x01
  942. #define ATT_ERROR_READ_NOT_PERMITTED 0x02
  943. #define ATT_ERROR_WRITE_NOT_PERMITTED 0x03
  944. #define ATT_ERROR_INVALID_PDU 0x04
  945. #define ATT_ERROR_INSUFFICIENT_AUTHENTICATION 0x05
  946. #define ATT_ERROR_REQUEST_NOT_SUPPORTED 0x06
  947. #define ATT_ERROR_INVALID_OFFSET 0x07
  948. #define ATT_ERROR_INSUFFICIENT_AUTHORIZATION 0x08
  949. #define ATT_ERROR_PREPARE_QUEUE_FULL 0x09
  950. #define ATT_ERROR_ATTRIBUTE_NOT_FOUND 0x0a
  951. #define ATT_ERROR_ATTRIBUTE_NOT_LONG 0x0b
  952. #define ATT_ERROR_INSUFFICIENT_ENCRYPTION_KEY_SIZE 0x0c
  953. #define ATT_ERROR_INVALID_ATTRIBUTE_VALUE_LENGTH 0x0d
  954. #define ATT_ERROR_UNLIKELY_ERROR 0x0e
  955. #define ATT_ERROR_INSUFFICIENT_ENCRYPTION 0x0f
  956. #define ATT_ERROR_UNSUPPORTED_GROUP_TYPE 0x10
  957. #define ATT_ERROR_INSUFFICIENT_RESOURCES 0x11
  958. // MARK: ATT Error Codes from Cycling Power Service spec
  959. #define CYCLING_POWER_ERROR_CODE_INAPPROPRIATE_CONNECTION_PARAMETERS 0x80
  960. #define CYCLING_POWER_ERROR_CODE_PROCEDURE_ALREADY_IN_PROGRESS 0xFE
  961. #define CYCLING_POWER_ERROR_CODE_CCC_DESCRIPTOR_IMPROPERLY_CONFIGURED 0xFD
  962. // MARK: ATT Error Codes from Cycling Speed and Cadence Service spec
  963. #define CYCLING_SPEED_AND_CADENCE_ERROR_CODE_PROCEDURE_ALREADY_IN_PROGRESS 0x80
  964. #define CYCLING_SPEED_AND_CADENCE_ERROR_CODE_CCC_DESCRIPTOR_IMPROPERLY_CONFIGURED 0x81
  965. // MARK: Attribute Property Flags
  966. #define ATT_PROPERTY_BROADCAST 0x01
  967. #define ATT_PROPERTY_READ 0x02
  968. #define ATT_PROPERTY_WRITE_WITHOUT_RESPONSE 0x04
  969. #define ATT_PROPERTY_WRITE 0x08
  970. #define ATT_PROPERTY_NOTIFY 0x10
  971. #define ATT_PROPERTY_INDICATE 0x20
  972. #define ATT_PROPERTY_AUTHENTICATED_SIGNED_WRITE 0x40
  973. #define ATT_PROPERTY_EXTENDED_PROPERTIES 0x80
  974. // MARK: Attribute Property Flag, BTstack extension
  975. // value is asked from client
  976. #define ATT_PROPERTY_DYNAMIC 0x100
  977. // Security levels
  978. #define ATT_SECURITY_NONE 0
  979. #define ATT_SECURITY_ENCRYPTED 1
  980. #define ATT_SECURITY_AUTHENTICATED 2
  981. #define ATT_SECURITY_AUTHORIZED 3
  982. #define ATT_SECURITY_AUTHENTICATED_SC 4
  983. // internal additions
  984. // 128 bit UUID used
  985. #define ATT_PROPERTY_UUID128 0x200
  986. // Read/Write Permission bits
  987. #define ATT_PROPERTY_READ_PERMISSION_BIT_0 0x0400
  988. #define ATT_PROPERTY_READ_PERMISSION_BIT_1 0x0800
  989. #define ATT_PROPERTY_WRITE_PERMISSION_BIT_0 0x0001
  990. #define ATT_PROPERTY_WRITE_PERMISSION_BIT_1 0x0010
  991. #define ATT_PROPERTY_READ_PERMISSION_SC 0x0020
  992. #define ATT_PROPERTY_WRITE_PERMISSION_SC 0x0080
  993. // ATT Transaction Timeout of 30 seconds for Command/Response or Indication/Confirmation
  994. #define ATT_TRANSACTION_TIMEOUT_MS 30000
  995. #define ATT_TRANSACTION_MODE_NONE 0x0
  996. #define ATT_TRANSACTION_MODE_ACTIVE 0x1
  997. #define ATT_TRANSACTION_MODE_EXECUTE 0x2
  998. #define ATT_TRANSACTION_MODE_CANCEL 0x3
  999. #define ATT_TRANSACTION_MODE_VALIDATE 0x4
  1000. // MARK: GATT UUIDs
  1001. #define GATT_PRIMARY_SERVICE_UUID 0x2800
  1002. #define GATT_SECONDARY_SERVICE_UUID 0x2801
  1003. #define GATT_INCLUDE_SERVICE_UUID 0x2802
  1004. #define GATT_CHARACTERISTICS_UUID 0x2803
  1005. #define GATT_CHARACTERISTIC_EXTENDED_PROPERTIES 0x2900
  1006. #define GATT_CHARACTERISTIC_USER_DESCRIPTION 0x2901
  1007. #define GATT_CLIENT_CHARACTERISTICS_CONFIGURATION 0x2902
  1008. #define GATT_SERVER_CHARACTERISTICS_CONFIGURATION 0x2903
  1009. #define GATT_CHARACTERISTIC_PRESENTATION_FORMAT 0x2904
  1010. #define GATT_CHARACTERISTIC_AGGREGATE_FORMAT 0x2905
  1011. #define GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NONE 0
  1012. #define GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION 1
  1013. #define GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION 2
  1014. // GAP Service and Characteristics
  1015. #define GAP_SERVICE_UUID 0x1800
  1016. #define GAP_DEVICE_NAME_UUID 0x2a00
  1017. #define GAP_APPEARANCE_UUID 0x2a01
  1018. #define GAP_PERIPHERAL_PRIVACY_FLAG 0x2a02
  1019. #define GAP_RECONNECTION_ADDRESS_UUID 0x2a03
  1020. #define GAP_PERIPHERAL_PREFERRED_CONNECTION_PARAMETERS_UUID 0x2a04
  1021. #define GAP_SERVICE_CHANGED 0x2a05
  1022. // Bluetooth GATT types
  1023. typedef struct {
  1024. uint16_t year; // 0 - year is not known; or [1582,9999]
  1025. uint8_t month; // 0 - month is not known; or [1,12]
  1026. uint8_t day; // 0 - day is not known; or [1,31]
  1027. uint8_t hours; // [0,23]
  1028. uint8_t minutes; // [0,59]
  1029. uint8_t seconds; // [0,59]
  1030. } gatt_date_time_t;
  1031. /**
  1032. * SM - LE Security Manager
  1033. */
  1034. // Bluetooth Spec definitions
  1035. typedef enum {
  1036. SM_CODE_PAIRING_REQUEST = 0X01,
  1037. SM_CODE_PAIRING_RESPONSE,
  1038. SM_CODE_PAIRING_CONFIRM,
  1039. SM_CODE_PAIRING_RANDOM,
  1040. SM_CODE_PAIRING_FAILED,
  1041. SM_CODE_ENCRYPTION_INFORMATION,
  1042. SM_CODE_MASTER_IDENTIFICATION,
  1043. SM_CODE_IDENTITY_INFORMATION,
  1044. SM_CODE_IDENTITY_ADDRESS_INFORMATION,
  1045. SM_CODE_SIGNING_INFORMATION,
  1046. SM_CODE_SECURITY_REQUEST,
  1047. SM_CODE_PAIRING_PUBLIC_KEY,
  1048. SM_CODE_PAIRING_DHKEY_CHECK,
  1049. SM_CODE_KEYPRESS_NOTIFICATION,
  1050. } SECURITY_MANAGER_COMMANDS;
  1051. // IO Capability Values
  1052. typedef enum {
  1053. IO_CAPABILITY_DISPLAY_ONLY = 0,
  1054. IO_CAPABILITY_DISPLAY_YES_NO,
  1055. IO_CAPABILITY_KEYBOARD_ONLY,
  1056. IO_CAPABILITY_NO_INPUT_NO_OUTPUT,
  1057. IO_CAPABILITY_KEYBOARD_DISPLAY, // not used by secure simple pairing
  1058. } io_capability_t;
  1059. // Authentication requirement flags
  1060. #define SM_AUTHREQ_NO_BONDING 0x00
  1061. #define SM_AUTHREQ_BONDING 0x01
  1062. #define SM_AUTHREQ_MITM_PROTECTION 0x04
  1063. #define SM_AUTHREQ_SECURE_CONNECTION 0x08
  1064. #define SM_AUTHREQ_KEYPRESS 0x10
  1065. // Key distribution flags used by spec
  1066. #define SM_KEYDIST_ENC_KEY 0x01
  1067. #define SM_KEYDIST_ID_KEY 0x02
  1068. #define SM_KEYDIST_SIGN 0x04
  1069. #define SM_KEYDIST_LINK_KEY 0x08
  1070. // Key distribution flags used internally
  1071. #define SM_KEYDIST_FLAG_ENCRYPTION_INFORMATION 0x01
  1072. #define SM_KEYDIST_FLAG_MASTER_IDENTIFICATION 0x02
  1073. #define SM_KEYDIST_FLAG_IDENTITY_INFORMATION 0x04
  1074. #define SM_KEYDIST_FLAG_IDENTITY_ADDRESS_INFORMATION 0x08
  1075. #define SM_KEYDIST_FLAG_SIGNING_IDENTIFICATION 0x10
  1076. // STK Generation Methods
  1077. #define SM_STK_GENERATION_METHOD_JUST_WORKS 0x01
  1078. #define SM_STK_GENERATION_METHOD_OOB 0x02
  1079. #define SM_STK_GENERATION_METHOD_PASSKEY 0x04
  1080. #define SM_STK_GENERATION_METHOD_NUMERIC_COMPARISON 0x08
  1081. // Pairing Failed Reasons
  1082. #define SM_REASON_RESERVED 0x00
  1083. #define SM_REASON_PASSKEY_ENTRY_FAILED 0x01
  1084. #define SM_REASON_OOB_NOT_AVAILABLE 0x02
  1085. #define SM_REASON_AUTHENTHICATION_REQUIREMENTS 0x03
  1086. #define SM_REASON_CONFIRM_VALUE_FAILED 0x04
  1087. #define SM_REASON_PAIRING_NOT_SUPPORTED 0x05
  1088. #define SM_REASON_ENCRYPTION_KEY_SIZE 0x06
  1089. #define SM_REASON_COMMAND_NOT_SUPPORTED 0x07
  1090. #define SM_REASON_UNSPECIFIED_REASON 0x08
  1091. #define SM_REASON_REPEATED_ATTEMPTS 0x09
  1092. #define SM_REASON_INVALID_PARAMETERS 0x0a
  1093. #define SM_REASON_DHKEY_CHECK_FAILED 0x0b
  1094. #define SM_REASON_NUMERIC_COMPARISON_FAILED 0x0c
  1095. // also, invalid parameters
  1096. // and reserved
  1097. // Keypress Notifications
  1098. #define SM_KEYPRESS_PASSKEY_ENTRY_STARTED 0x00
  1099. #define SM_KEYPRESS_PASSKEY_DIGIT_ENTERED 0x01
  1100. #define SM_KEYPRESS_PASSKEY_DIGIT_ERASED 0x02
  1101. #define SM_KEYPRESS_PASSKEY_CLEARED 0x03
  1102. #define SM_KEYPRESS_PASSKEY_ENTRY_COMPLETED 0x04
  1103. #endif