bcomdef.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /**************************************************************************************************
  2. Phyplus Microelectronics Limited confidential and proprietary.
  3. All rights reserved.
  4. IMPORTANT: All rights of this software belong to Phyplus Microelectronics
  5. Limited ("Phyplus"). Your use of this Software is limited to those
  6. specific rights granted under the terms of the business contract, the
  7. confidential agreement, the non-disclosure agreement and any other forms
  8. of agreements as a customer or a partner of Phyplus. You may not use this
  9. Software unless you agree to abide by the terms of these agreements.
  10. You acknowledge that the Software may not be modified, copied,
  11. distributed or disclosed unless embedded on a Phyplus Bluetooth Low Energy
  12. (BLE) integrated circuit, either as a product or is integrated into your
  13. products. Other than for the aforementioned purposes, you may not use,
  14. reproduce, copy, prepare derivative works of, modify, distribute, perform,
  15. display or sell this Software and/or its documentation for any purposes.
  16. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  17. PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  18. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  19. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  20. PHYPLUS OR ITS SUBSIDIARIES BE LIABLE OR OBLIGATED UNDER CONTRACT,
  21. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  22. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  23. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  24. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  25. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  26. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  27. **************************************************************************************************/
  28. /**
  29. @headerfile: bcomdef.h
  30. <!--
  31. Revised:
  32. Revision:
  33. Description: Type definitions and macros for BLE stack.
  34. -->
  35. **************************************************************************************************/
  36. #ifndef BCOMDEF_H
  37. #define BCOMDEF_H
  38. #ifdef __cplusplus
  39. extern "C"
  40. {
  41. #endif
  42. /*********************************************************************
  43. * INCLUDES
  44. */
  45. #include "comdef.h"
  46. #include "log.h"
  47. //#define AT_LOG(...)
  48. /*********************************************************************
  49. * CONSTANTS
  50. */
  51. #define CTRL_CONFIG ( ADV_NCONN_CFG | ADV_CONN_CFG | SCAN_CFG | INIT_CFG )
  52. //#if defined ( HOST_CONFIG )
  53. // // Set the Controller Configuration
  54. // #if ( HOST_CONFIG == ( CENTRAL_CFG | PERIPHERAL_CFG ) )
  55. // #define CTRL_CONFIG ( ADV_NCONN_CFG | ADV_CONN_CFG | SCAN_CFG | INIT_CFG )
  56. // #elif ( HOST_CONFIG == ( CENTRAL_CFG | BROADCASTER_CFG ) )
  57. // #define CTRL_CONFIG ( ADV_NCONN_CFG | SCAN_CFG | INIT_CFG )
  58. // #elif ( HOST_CONFIG == ( PERIPHERAL_CFG | OBSERVER_CFG ) )
  59. // #define CTRL_CONFIG ( ADV_NCONN_CFG | ADV_CONN_CFG | SCAN_CFG )
  60. // #elif ( HOST_CONFIG == ( BROADCASTER_CFG | OBSERVER_CFG ) )
  61. // #define CTRL_CONFIG ( ADV_NCONN_CFG | SCAN_CFG )
  62. // #elif ( HOST_CONFIG == CENTRAL_CFG )
  63. // #define CTRL_CONFIG ( SCAN_CFG | INIT_CFG )
  64. // #elif ( HOST_CONFIG == PERIPHERAL_CFG )
  65. // #define CTRL_CONFIG ( ADV_NCONN_CFG | ADV_CONN_CFG )
  66. // #elif ( HOST_CONFIG == OBSERVER_CFG )
  67. // #define CTRL_CONFIG SCAN_CFG
  68. // #elif ( HOST_CONFIG == BROADCASTER_CFG )
  69. // #define CTRL_CONFIG ADV_NCONN_CFG
  70. // #else
  71. // #error "Build Configuration Error: Invalid Host Role!"
  72. // #endif
  73. //#else
  74. // // Controller Sanity Check: Stop build when no configuration is defined.
  75. // #if !defined( CTRL_CONFIG ) || !( CTRL_CONFIG & ( ADV_NCONN_CFG | \
  76. // ADV_CONN_CFG | \
  77. // SCAN_CFG | \
  78. // INIT_CFG ) )
  79. // #error "Build Configuration Error: At least one Controller build component required!"
  80. // #endif // no Controller build components defined
  81. //#endif
  82. #if !defined ( MAX_NUM_LL_CONN )
  83. #if ( CTRL_CONFIG & INIT_CFG )
  84. #define MAX_NUM_LL_CONN 1// 3
  85. #elif ( !( CTRL_CONFIG & INIT_CFG ) && ( CTRL_CONFIG & ADV_CONN_CFG ) )
  86. #define MAX_NUM_LL_CONN 1
  87. #else // no connection needed
  88. #define MAX_NUM_LL_CONN 0
  89. #endif // CTRL_CONFIG=INIT_CFG
  90. #endif // !MAX_NUM_LL_CONN
  91. /** @defgroup BLE_COMMON_DEFINES BLE Common Defines
  92. * @{
  93. */
  94. //! Default Public and Random Address Length
  95. #define B_ADDR_LEN 6
  96. //! Default key length
  97. #define KEYLEN 16
  98. //! BLE Channel Map length
  99. #define B_CHANNEL_MAP_LEN 5
  100. //! BLE Event mask length
  101. #define B_EVENT_MASK_LEN 8
  102. //! BLE Local Name length
  103. #define B_LOCAL_NAME_LEN 248
  104. //! BLE Maximum Advertising Packet Length
  105. #define B_MAX_ADV_LEN 31
  106. //! BLE Random Number Size
  107. #define B_RANDOM_NUM_SIZE 8
  108. //! BLE Feature Supported length
  109. #define B_FEATURE_SUPPORT_LENGTH 8
  110. /** @defgroup BLE_STATUS_VALUES BLE Default BLE Status Values
  111. * returned as bStatus_t
  112. * @{
  113. */
  114. #define bleInvalidTaskID INVALID_TASK //!< Task ID isn't setup properly
  115. #define bleNotReady 0x10 //!< Not ready to perform task
  116. #define bleAlreadyInRequestedMode 0x11 //!< Already performing that task
  117. #define bleIncorrectMode 0x12 //!< Not setup properly to perform that task
  118. #define bleMemAllocError 0x13 //!< Memory allocation error occurred
  119. #define bleNotConnected 0x14 //!< Can't perform function when not in a connection
  120. #define bleNoResources 0x15 //!< There are no resource available
  121. #define blePending 0x16 //!< Waiting
  122. #define bleTimeout 0x17 //!< Timed out performing function
  123. #define bleInvalidRange 0x18 //!< A parameter is out of range
  124. #define bleLinkEncrypted 0x19 //!< The link is already encrypted
  125. #define bleProcedureComplete 0x1A //!< The Procedure is completed
  126. // GAP Status Return Values - returned as bStatus_t
  127. #define bleGAPUserCanceled 0x30 //!< The user canceled the task
  128. #define bleGAPConnNotAcceptable 0x31 //!< The connection was not accepted
  129. #define bleGAPBondRejected 0x32 //!< The bound information was rejected.
  130. // ATT Status Return Values - returned as bStatus_t
  131. #define bleInvalidPDU 0x40 //!< The attribute PDU is invalid
  132. #define bleInsufficientAuthen 0x41 //!< The attribute has insufficient authentication
  133. #define bleInsufficientEncrypt 0x42 //!< The attribute has insufficient encryption
  134. #define bleInsufficientKeySize 0x43 //!< The attribute has insufficient encryption key size
  135. // L2CAP Status Return Values - returned as bStatus_t
  136. #define INVALID_TASK_ID 0xFF //!< Task ID isn't setup properly
  137. /** @} End BLE_STATUS_VALUES */
  138. /** @defgroup BLE_NV_IDS BLE Non-volatile IDs
  139. * @{
  140. */
  141. // Device NV Items - Range 0 - 0x1F
  142. #define BLE_NVID_IRK 0x02 //!< The Device's IRK
  143. #define BLE_NVID_CSRK 0x03 //!< The Device's CSRK
  144. #define BLE_NVID_SIGNCOUNTER 0x04 //!< The Device's Sign Counter
  145. // Bonding NV Items - Range 0x20 - 0x5F - This allows for 10 bondings
  146. #define BLE_NVID_GAP_BOND_START 0x20 //!< Start of the GAP Bond Manager's NV IDs
  147. #define BLE_NVID_GAP_BOND_END 0x5f //!< End of the GAP Bond Manager's NV IDs Range
  148. // GATT Configuration NV Items - Range 0x70 - 0x79 - This must match the number of Bonding entries
  149. #define BLE_NVID_GATT_CFG_START 0x70 //!< Start of the GATT Configuration NV IDs
  150. #define BLE_NVID_GATT_CFG_END 0x79 //!< End of the GATT Configuration NV IDs
  151. /** @} End BLE_NV_IDS */
  152. /*********************************************************************
  153. * BLE OSAL GAP GLOBAL Events
  154. */
  155. #define GAP_EVENT_SIGN_COUNTER_CHANGED 0x4000 //!< The device level sign counter changed
  156. /** @defgroup BLE_MSG_IDS BLE OSAL Message ID Events
  157. * Reserved Message ID Event Values:<BR>
  158. * 0xC0 - Key Presses<BR>
  159. * 0xE0 to 0xFC - App<BR>
  160. * @{
  161. */
  162. // GAP - Messages IDs (0xD0 - 0xDF)
  163. #define GAP_MSG_EVENT 0xD0 //!< Incoming GAP message
  164. // SM - Messages IDs (0xC1 - 0xCF)
  165. #define SM_NEW_RAND_KEY_EVENT 0xC1 //!< New Rand Key Event message
  166. // GATT - Messages IDs (0xB0 - 0xBF)
  167. #define GATT_MSG_EVENT 0xB0 //!< Incoming GATT message
  168. #define GATT_SERV_MSG_EVENT 0xB1 //!< Incoming GATT Serv App message
  169. // L2CAP - Messages IDs (0xA0 - 0xAF)
  170. #define L2CAP_DATA_EVENT 0xA0 //!< Incoming data on a channel
  171. #define L2CAP_SIGNAL_EVENT 0xA2 //!< Incoming Signaling message
  172. // HCI - Messages IDs (0x90 - 0x9F)
  173. #define HCI_DATA_EVENT 0x90 //!< HCI Data Event message
  174. #define HCI_GAP_EVENT_EVENT 0x91 //!< GAP Event message
  175. #define HCI_SMP_EVENT_EVENT 0x92 //!< SMP Event message
  176. #define HCI_EXT_CMD_EVENT 0x93 //!< HCI Extended Command Event message
  177. /** @} End BLE_MSG_IDS */
  178. /*********************************************************************
  179. * TYPEDEFS
  180. */
  181. //! BLE Generic Status return: @ref BLE_STATUS_VALUES
  182. typedef Status_t bStatus_t;
  183. /** @} End GAP_MSG_EVENT_DEFINES */
  184. /*********************************************************************
  185. * System Events
  186. */
  187. /*********************************************************************
  188. * Global System Messages
  189. */
  190. /*********************************************************************
  191. * MACROS
  192. */
  193. #define TI_BASE_UUID_128( uuid ) 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB0, \
  194. 0x00, 0x40, 0x51, 0x04, LO_UINT16( uuid ), HI_UINT16( uuid ), 0x00, 0xF0
  195. /*********************************************************************
  196. * GLOBAL VARIABLES
  197. */
  198. /*********************************************************************
  199. * FUNCTIONS
  200. */
  201. /*********************************************************************
  202. *********************************************************************/
  203. #ifdef __cplusplus
  204. }
  205. #endif
  206. #endif /* BCOMDEF_H */