gap.h 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182
  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: gap.h
  30. $Date:
  31. $Revision:
  32. */
  33. #ifndef GAP_H
  34. #define GAP_H
  35. #ifdef __cplusplus
  36. extern "C"
  37. {
  38. #endif
  39. /*-------------------------------------------------------------------
  40. * INCLUDES
  41. */
  42. #include "bcomdef.h"
  43. #include "OSAL.h"
  44. #include "sm.h"
  45. /*-------------------------------------------------------------------
  46. * MACROS
  47. */
  48. /*-------------------------------------------------------------------
  49. * CONSTANTS
  50. */
  51. /** @defgroup BLE_GAP_DEFINES BLE GAP Constants and Structures
  52. * @{
  53. */
  54. /** @defgroup GAP_MSG_EVENT_DEFINES GAP Message IDs
  55. * @{
  56. */
  57. #define GAP_DEVICE_INIT_DONE_EVENT 0x00 //!< Sent when the Device Initialization is complete. This event is sent as an OSAL message defined as gapDeviceInitDoneEvent_t.
  58. #define GAP_DEVICE_DISCOVERY_EVENT 0x01 //!< Sent when the Device Discovery Process is complete. This event is sent as an OSAL message defined as gapDevDiscEvent_t.
  59. #define GAP_ADV_DATA_UPDATE_DONE_EVENT 0x02 //!< Sent when the Advertising Data or SCAN_RSP Data has been updated. This event is sent as an OSAL message defined as gapAdvDataUpdateEvent_t.
  60. #define GAP_MAKE_DISCOVERABLE_DONE_EVENT 0x03 //!< Sent when the Make Discoverable Request is complete. This event is sent as an OSAL message defined as gapMakeDiscoverableRspEvent_t.
  61. #define GAP_END_DISCOVERABLE_DONE_EVENT 0x04 //!< Sent when the Advertising has ended. This event is sent as an OSAL message defined as gapEndDiscoverableRspEvent_t.
  62. #define GAP_LINK_ESTABLISHED_EVENT 0x05 //!< Sent when the Establish Link Request is complete. This event is sent as an OSAL message defined as gapEstLinkReqEvent_t.
  63. #define GAP_LINK_TERMINATED_EVENT 0x06 //!< Sent when a connection was terminated. This event is sent as an OSAL message defined as gapTerminateLinkEvent_t.
  64. #define GAP_LINK_PARAM_UPDATE_EVENT 0x07 //!< Sent when an Update Parameters Event is received. This event is sent as an OSAL message defined as gapLinkUpdateEvent_t.
  65. #define GAP_RANDOM_ADDR_CHANGED_EVENT 0x08 //!< Sent when a random address was changed. This event is sent as an OSAL message defined as gapRandomAddrEvent_t.
  66. #define GAP_SIGNATURE_UPDATED_EVENT 0x09 //!< Sent when the device's signature counter is updated. This event is sent as an OSAL message defined as gapSignUpdateEvent_t.
  67. #define GAP_AUTHENTICATION_COMPLETE_EVENT 0x0A //!< Sent when the Authentication (pairing) process is complete. This event is sent as an OSAL message defined as gapAuthCompleteEvent_t.
  68. #define GAP_PASSKEY_NEEDED_EVENT 0x0B //!< Sent when a Passkey is needed. This is part of the pairing process. This event is sent as an OSAL message defined as gapPasskeyNeededEvent_t.
  69. #define GAP_SLAVE_REQUESTED_SECURITY_EVENT 0x0C //!< Sent when a Slave Security Request is received. This event is sent as an OSAL message defined as gapSlaveSecurityReqEvent_t.
  70. #define GAP_DEVICE_INFO_EVENT 0x0D //!< Sent during the Device Discovery Process when a device is discovered. This event is sent as an OSAL message defined as gapDeviceInfoEvent_t.
  71. #define GAP_BOND_COMPLETE_EVENT 0x0E //!< Sent when the bonding(bound) process is complete. This event is sent as an OSAL message defined as gapBondCompleteEvent_t.
  72. #define GAP_PAIRING_REQ_EVENT 0x0F //!< Sent when an unexpected Pairing Request is received. This event is sent as an OSAL message defined as gapPairingReqEvent_t.
  73. /** @} End GAP_MSG_EVENT_DEFINES */
  74. /** @defgroup GAP_CONN_HANDLE_DEFINES GAP Special Connection Handles
  75. * Used by GAP_TerminateLinkReq()
  76. * @{
  77. */
  78. #define GAP_CONNHANDLE_INIT 0xFFFE //!< terminates a link create
  79. #define GAP_CONNHANDLE_ALL 0xFFFF //!< terminates all links for the matching task ID.
  80. /** @} End GAP_CONN_HANDLE_DEFINES */
  81. /** @defgroup GAP_PROFILE_ROLE_DEFINES GAP Profile Roles
  82. * Bit mask values
  83. * @{
  84. */
  85. #define GAP_PROFILE_BROADCASTER 0x01 //!< A device that sends advertising events only.
  86. #define GAP_PROFILE_OBSERVER 0x02 //!< A device that receives advertising events only.
  87. #define GAP_PROFILE_PERIPHERAL 0x04 //!< A device that accepts the establishment of an LE physical link using the connection establishment procedure
  88. #define GAP_PROFILE_CENTRAL 0x08 //!< A device that supports the Central role initiates the establishment of a physical connection
  89. /** @} End GAP_PROFILE_ROLE_DEFINES */
  90. /**
  91. * @defgroup GAP_PARAMETER_ID_DEFINES GAP Parameter IDs
  92. * Used in place of gapParamIDs_t.
  93. * @{
  94. */
  95. // Timers
  96. #define TGAP_GEN_DISC_ADV_MIN 0 //!< Minimum time to remain advertising, when in Discoverable mode (mSec). Setting this parameter to 0 turns off the timeout (default).
  97. #define TGAP_LIM_ADV_TIMEOUT 1 //!< Maximum time to remain advertising, when in Limited Discoverable mode. In seconds (default 180 seconds)
  98. #define TGAP_GEN_DISC_SCAN 2 //!< Minimum time to perform scanning, when performing General Discovery proc (mSec)
  99. #define TGAP_LIM_DISC_SCAN 3 //!< Minimum time to perform scanning, when performing Limited Discovery proc (mSec)
  100. #define TGAP_CONN_EST_ADV_TIMEOUT 4 //!< Advertising timeout, when performing Connection Establishment proc (mSec)
  101. #define TGAP_CONN_PARAM_TIMEOUT 5 //!< Link Layer connection parameter update notification timer, connection parameter update proc (mSec)
  102. // Constants
  103. #define TGAP_LIM_DISC_ADV_INT_MIN 6 //!< Minimum advertising interval, when in limited discoverable mode (n * 0.625 mSec)
  104. #define TGAP_LIM_DISC_ADV_INT_MAX 7 //!< Maximum advertising interval, when in limited discoverable mode (n * 0.625 mSec)
  105. #define TGAP_GEN_DISC_ADV_INT_MIN 8 //!< Minimum advertising interval, when in General discoverable mode (n * 0.625 mSec)
  106. #define TGAP_GEN_DISC_ADV_INT_MAX 9 //!< Maximum advertising interval, when in General discoverable mode (n * 0.625 mSec)
  107. #define TGAP_CONN_ADV_INT_MIN 10 //!< Minimum advertising interval, when in Connectable mode (n * 0.625 mSec)
  108. #define TGAP_CONN_ADV_INT_MAX 11 //!< Maximum advertising interval, when in Connectable mode (n * 0.625 mSec)
  109. #define TGAP_CONN_SCAN_INT 12 //!< Scan interval used during Link Layer Initiating state, when in Connectable mode (n * 0.625 mSec)
  110. #define TGAP_CONN_SCAN_WIND 13 //!< Scan window used during Link Layer Initiating state, when in Connectable mode (n * 0.625 mSec)
  111. #define TGAP_CONN_HIGH_SCAN_INT 14 //!< Scan interval used during Link Layer Initiating state, when in Connectable mode, high duty scan cycle scan paramaters (n * 0.625 mSec)
  112. #define TGAP_CONN_HIGH_SCAN_WIND 15 //!< Scan window used during Link Layer Initiating state, when in Connectable mode, high duty scan cycle scan paramaters (n * 0.625 mSec)
  113. #define TGAP_GEN_DISC_SCAN_INT 16 //!< Scan interval used during Link Layer Scanning state, when in General Discovery proc (n * 0.625 mSec)
  114. #define TGAP_GEN_DISC_SCAN_WIND 17 //!< Scan window used during Link Layer Scanning state, when in General Discovery proc (n * 0.625 mSec)
  115. #define TGAP_LIM_DISC_SCAN_INT 18 //!< Scan interval used during Link Layer Scanning state, when in Limited Discovery proc (n * 0.625 mSec)
  116. #define TGAP_LIM_DISC_SCAN_WIND 19 //!< Scan window used during Link Layer Scanning state, when in Limited Discovery proc (n * 0.625 mSec)
  117. #define TGAP_CONN_EST_ADV 20 //!< Advertising interval, when using Connection Establishment proc (n * 0.625 mSec). Obsolete - Do not use.
  118. #define TGAP_CONN_EST_INT_MIN 21 //!< Minimum Link Layer connection interval, when using Connection Establishment proc (n * 1.25 mSec)
  119. #define TGAP_CONN_EST_INT_MAX 22 //!< Maximum Link Layer connection interval, when using Connection Establishment proc (n * 1.25 mSec)
  120. #define TGAP_CONN_EST_SCAN_INT 23 //!< Scan interval used during Link Layer Initiating state, when using Connection Establishment proc (n * 0.625 mSec)
  121. #define TGAP_CONN_EST_SCAN_WIND 24 //!< Scan window used during Link Layer Initiating state, when using Connection Establishment proc (n * 0.625 mSec)
  122. #define TGAP_CONN_EST_SUPERV_TIMEOUT 25 //!< Link Layer connection supervision timeout, when using Connection Establishment proc (n * 10 mSec)
  123. #define TGAP_CONN_EST_LATENCY 26 //!< Link Layer connection slave latency, when using Connection Establishment proc (in number of connection events)
  124. #define TGAP_CONN_EST_MIN_CE_LEN 27 //!< Local informational parameter about min len of connection needed, when using Connection Establishment proc (n * 0.625 mSec)
  125. #define TGAP_CONN_EST_MAX_CE_LEN 28 //!< Local informational parameter about max len of connection needed, when using Connection Establishment proc (n * 0.625 mSec)
  126. #define TGAP_PRIVATE_ADDR_INT 29 //!< Minimum Time Interval between private (resolvable) address changes. In minutes (default 15 minutes)
  127. #define TGAP_CONN_PAUSE_CENTRAL 30 //!< Central idle timer. In seconds (default 1 second)
  128. #define TGAP_CONN_PAUSE_PERIPHERAL 31 //!< Minimum time upon connection establishment before the peripheral starts a connection update procedure. In seconds (default 5 seconds)
  129. // Proprietary
  130. #define TGAP_SM_TIMEOUT 32 //!< SM Message Timeout (milliseconds). Default 30 seconds.
  131. #define TGAP_SM_MIN_KEY_LEN 33 //!< SM Minimum Key Length supported. Default 7.
  132. #define TGAP_SM_MAX_KEY_LEN 34 //!< SM Maximum Key Length supported. Default 16.
  133. #define TGAP_FILTER_ADV_REPORTS 35 //!< Filter duplicate advertising reports. Default TRUE.
  134. #define TGAP_SCAN_RSP_RSSI_MIN 36 //!< Minimum RSSI required for scan responses to be reported to the app. Default -127.
  135. #define TGAP_REJECT_CONN_PARAMS 37 //!< Whether or not to reject Connection Parameter Update Request received on Central device. Default FALSE.
  136. #if !defined ( TESTMODES )
  137. #define TGAP_AUTH_TASK_ID 38 //!< Task ID override for Task Authentication control (for stack internal use only)
  138. #define TGAP_PARAMID_MAX 39 //!< ID MAX-valid Parameter ID
  139. #else
  140. #define TGAP_GAP_TESTCODE 38 //!< GAP TestCodes - puts GAP into a test mode
  141. #define TGAP_SM_TESTCODE 39 //!< SM TestCodes - puts SM into a test mode
  142. #define TGAP_AUTH_TASK_ID 40 //!< Task ID override for Task Authentication control (for stack internal use only)
  143. #define TGAP_PARAMID_MAX 41 //!< ID MAX-valid Parameter ID
  144. #define TGAP_GATT_TESTCODE 100 //!< GATT TestCodes - puts GATT into a test mode (paramValue maintained by GATT)
  145. #define TGAP_ATT_TESTCODE 101 //!< ATT TestCodes - puts ATT into a test mode (paramValue maintained by ATT)
  146. #define TGAP_GGS_TESTCODE 102 //!< GGS TestCodes - puts GGS into a test mode (paramValue maintained by GGS)
  147. #endif
  148. /** @} End GAP_PARAMETER_ID_DEFINES */
  149. /** @defgroup GAP_DEVDISC_MODE_DEFINES GAP Device Discovery Modes
  150. * @{
  151. */
  152. #define DEVDISC_MODE_NONDISCOVERABLE 0x00 //!< No discoverable setting
  153. #define DEVDISC_MODE_GENERAL 0x01 //!< General Discoverable devices
  154. #define DEVDISC_MODE_LIMITED 0x02 //!< Limited Discoverable devices
  155. #define DEVDISC_MODE_ALL 0x03 //!< Not filtered
  156. /** @} End GAP_DEVDISC_MODE_DEFINES */
  157. /** @defgroup GAP_ADDR_TYPE_DEFINES GAP Address Types
  158. * @{
  159. */
  160. #define ADDRTYPE_PUBLIC 0x00 //!< Use the BD_ADDR
  161. #define ADDRTYPE_STATIC 0x01 //!< Static address
  162. #define ADDRTYPE_PRIVATE_NONRESOLVE 0x02 //!< Generate Non-Resolvable Private Address
  163. #define ADDRTYPE_PRIVATE_RESOLVE 0x03 //!< Generate Resolvable Private Address
  164. /** @} End GAP_ADDR_TYPE_DEFINES */
  165. /** @defgroup GAP_ADVERTISEMENT_TYPE_DEFINES GAP Advertising Event Types
  166. * for eventType field in gapAdvertisingParams_t
  167. * @{
  168. */
  169. #define GAP_ADTYPE_ADV_IND 0x00 //!< Connectable undirected advertisement
  170. #define GAP_ADTYPE_ADV_HDC_DIRECT_IND 0x01 //!< Connectable high duty cycle directed advertisement
  171. #define GAP_ADTYPE_ADV_SCAN_IND 0x02 //!< Scannable undirected advertisement
  172. #define GAP_ADTYPE_ADV_NONCONN_IND 0x03 //!< Non-Connectable undirected advertisement
  173. #define GAP_ADTYPE_ADV_LDC_DIRECT_IND 0x04 //!< Connectable low duty cycle directed advertisement
  174. /** @} End GAP_ADVERTISEMENT_TYPE_DEFINES */
  175. /** @defgroup GAP_ADVERTISEMENT_REPORT_TYPE_DEFINES GAP Advertising Report Event Types
  176. * for eventType field in gapDevRec_t and gapDeviceInfoEvent_t
  177. * @{
  178. */
  179. #define GAP_ADRPT_ADV_IND 0x00 //!< Connectable undirected advertisement
  180. #define GAP_ADRPT_ADV_DIRECT_IND 0x01 //!< Connectable directed advertisement
  181. #define GAP_ADRPT_ADV_SCAN_IND 0x02 //!< Scannable undirected advertisement
  182. #define GAP_ADRPT_ADV_NONCONN_IND 0x03 //!< Non-Connectable undirected advertisement
  183. #define GAP_ADRPT_SCAN_RSP 0x04 //!< Scan Response
  184. /** @} End GAP_ADVERTISEMENT_REPORT_TYPE_DEFINES */
  185. /** @defgroup GAP_FILTER_POLICY_DEFINES GAP Advertiser Filter Scan Parameters
  186. * @{
  187. */
  188. #define GAP_FILTER_POLICY_ALL 0x00 //!< Allow Scan Request from Any, Allow Connect Request from Any (default).
  189. #define GAP_FILTER_POLICY_WHITE_SCAN 0x01 //!< Allow Scan Request from White List Only, Allow Connect from Any
  190. #define GAP_FILTER_POLICY_WHITE_CON 0x02 //!< Allow Scan Request from Any, Connect from White List Only
  191. #define GAP_FILTER_POLICY_WHITE 0x03 //!< Allow Scan Request and Connect from White List Only
  192. /** @} End GAP_FILTER_POLICY_DEFINES */
  193. //! Advertiser Channel Map
  194. #define ADV_CHANMAP_SIZE 5
  195. //! Maximum Pairing Passcode/Passkey value. Range of a passkey can be 0 - 999,999.
  196. #define GAP_PASSCODE_MAX 999999
  197. /** Sign Counter Initialized - Sign counter hasn't been used yet. Used when setting up
  198. * a connection's signing information.
  199. */
  200. #define GAP_INIT_SIGN_COUNTER 0xFFFFFFFF
  201. /** @defgroup GAP_ADVCHAN_DEFINES GAP Advertisement Channel Map
  202. * @{
  203. */
  204. #define GAP_ADVCHAN_37 0x01 //!< Advertisement Channel 37
  205. #define GAP_ADVCHAN_38 0x02 //!< Advertisement Channel 38
  206. #define GAP_ADVCHAN_39 0x04 //!< Advertisement Channel 39
  207. #define GAP_ADVCHAN_ALL (GAP_ADVCHAN_37 | GAP_ADVCHAN_38 | GAP_ADVCHAN_39) //!< All Advertisement Channels Enabled
  208. /** @} End GAP_ADVCHAN_DEFINES */
  209. /** @defgroup GAP_WHITELIST_DEFINES GAP White List Options
  210. * @{
  211. */
  212. #define WL_NOTUSED 0x00 //!< White list not used but the advertiser's address in this command is used
  213. #define WL_USED 0x01 //!< White list is used and the advertiser's address in this command is not used.
  214. /** @} End GAP_WHITELIST_DEFINES */
  215. /** @defgroup GAP_ADTYPE_DEFINES GAP Advertisment Data Types
  216. * These are the data type identifiers for the data tokens in the advertisement data field.
  217. * @{
  218. */
  219. #define GAP_ADTYPE_FLAGS 0x01 //!< Discovery Mode: @ref GAP_ADTYPE_FLAGS_MODES
  220. #define GAP_ADTYPE_16BIT_MORE 0x02 //!< Service: More 16-bit UUIDs available
  221. #define GAP_ADTYPE_16BIT_COMPLETE 0x03 //!< Service: Complete list of 16-bit UUIDs
  222. #define GAP_ADTYPE_32BIT_MORE 0x04 //!< Service: More 32-bit UUIDs available
  223. #define GAP_ADTYPE_32BIT_COMPLETE 0x05 //!< Service: Complete list of 32-bit UUIDs
  224. #define GAP_ADTYPE_128BIT_MORE 0x06 //!< Service: More 128-bit UUIDs available
  225. #define GAP_ADTYPE_128BIT_COMPLETE 0x07 //!< Service: Complete list of 128-bit UUIDs
  226. #define GAP_ADTYPE_LOCAL_NAME_SHORT 0x08 //!< Shortened local name
  227. #define GAP_ADTYPE_LOCAL_NAME_COMPLETE 0x09 //!< Complete local name
  228. #define GAP_ADTYPE_POWER_LEVEL 0x0A //!< TX Power Level: 0xXX: -127 to +127 dBm
  229. #define GAP_ADTYPE_OOB_CLASS_OF_DEVICE 0x0D //!< Simple Pairing OOB Tag: Class of device (3 octets)
  230. #define GAP_ADTYPE_OOB_SIMPLE_PAIRING_HASHC 0x0E //!< Simple Pairing OOB Tag: Simple Pairing Hash C (16 octets)
  231. #define GAP_ADTYPE_OOB_SIMPLE_PAIRING_RANDR 0x0F //!< Simple Pairing OOB Tag: Simple Pairing Randomizer R (16 octets)
  232. #define GAP_ADTYPE_SM_TK 0x10 //!< Security Manager TK Value
  233. #define GAP_ADTYPE_SM_OOB_FLAG 0x11 //!< Secutiry Manager OOB Flags
  234. #define GAP_ADTYPE_SLAVE_CONN_INTERVAL_RANGE 0x12 //!< Min and Max values of the connection interval (2 octets Min, 2 octets Max) (0xFFFF indicates no conn interval min or max)
  235. #define GAP_ADTYPE_SIGNED_DATA 0x13 //!< Signed Data field
  236. #define GAP_ADTYPE_SERVICES_LIST_16BIT 0x14 //!< Service Solicitation: list of 16-bit Service UUIDs
  237. #define GAP_ADTYPE_SERVICES_LIST_128BIT 0x15 //!< Service Solicitation: list of 128-bit Service UUIDs
  238. #define GAP_ADTYPE_SERVICE_DATA 0x16 //!< Service Data
  239. #define GAP_ADTYPE_APPEARANCE 0x19 //!< Appearance
  240. #define GAP_ADTYPE_MANUFACTURER_SPECIFIC 0xFF //!< Manufacturer Specific Data: first 2 octets contain the Company Identifier Code followed by the additional manufacturer specific data
  241. /** @} End GAP_ADTYPE_DEFINES */
  242. /** @defgroup GAP_ADTYPE_FLAGS_MODES GAP ADTYPE Flags Discovery Modes
  243. * @{
  244. */
  245. #define GAP_ADTYPE_FLAGS_LIMITED 0x01 //!< Discovery Mode: LE Limited Discoverable Mode
  246. #define GAP_ADTYPE_FLAGS_GENERAL 0x02 //!< Discovery Mode: LE General Discoverable Mode
  247. #define GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED 0x04 //!< Discovery Mode: BR/EDR Not Supported
  248. /** @} End GAP_ADTYPE_FLAGS_MODES */
  249. /** @defgroup GAP_APPEARANCE_VALUES GAP Appearance Values
  250. * @{
  251. */
  252. #define GAP_APPEARE_UNKNOWN 0x0000 //!< Unknown
  253. #define GAP_APPEARE_GENERIC_PHONE 0x0040 //!< Generic Phone
  254. #define GAP_APPEARE_GENERIC_COMPUTER 0x0080 //!< Generic Computer
  255. #define GAP_APPEARE_GENERIC_WATCH 0x00C0 //!< Generic Watch
  256. #define GAP_APPEARE_WATCH_SPORTS 0x00C1 //!< Watch: Sports Watch
  257. #define GAP_APPEARE_GENERIC_CLOCK 0x0100 //!< Generic Clock
  258. #define GAP_APPEARE_GENERIC_DISPLAY 0x0140 //!< Generic Display
  259. #define GAP_APPEARE_GENERIC_RC 0x0180 //!< Generic Remote Control
  260. #define GAP_APPEARE_GENERIC_EYE_GALSSES 0x01C0 //!< Generic Eye-glasses
  261. #define GAP_APPEARE_GENERIC_TAG 0x0200 //!< Generic Tag
  262. #define GAP_APPEARE_GENERIC_KEYRING 0x0240 //!< Generic Keyring
  263. #define GAP_APPEARE_GENERIC_MEDIA_PLAYER 0x0280 //!< Generic Media Player
  264. #define GAP_APPEARE_GENERIC_BARCODE_SCANNER 0x02C0 //!< Generic Barcode Scanner
  265. #define GAP_APPEARE_GENERIC_THERMOMETER 0x0300 //!< Generic Thermometer
  266. #define GAP_APPEARE_GENERIC_THERMO_EAR 0x0301 //!< Thermometer: Ear
  267. #define GAP_APPEARE_GENERIC_HR_SENSOR 0x0340 //!< Generic Heart rate Sensor
  268. #define GAP_APPEARE_GENERIC_HRS_BELT 0x0341 //!< Heart Rate Sensor: Heart Rate Belt
  269. #define GAP_APPEARE_GENERIC_BLOOD_PRESSURE 0x0380 //!< Generic Blood Pressure
  270. #define GAP_APPEARE_GENERIC_BP_ARM 0x0381 //!< Blood Pressure: Arm
  271. #define GAP_APPEARE_GENERIC_BP_WRIST 0x0382 //!< Blood Pressure: Wrist
  272. #define GAP_APPEARE_GENERIC_HID 0x03C0 //!< Generic Human Interface Device (HID)
  273. #define GAP_APPEARE_HID_KEYBOARD 0x03C1 //!< HID Keyboard
  274. #define GAP_APPEARE_HID_MOUSE 0x03C2 //!< HID Mouse
  275. #define GAP_APPEARE_HID_JOYSTIC 0x03C3 //!< HID Joystick
  276. #define GAP_APPEARE_HID_GAMEPAD 0x03C4 //!< HID Gamepad
  277. #define GAP_APPEARE_HID_DIGITIZER_TYABLET 0x03C5 //!< HID Digitizer Tablet
  278. #define GAP_APPEARE_HID_DIGITAL_CARDREADER 0x03C6 //!< HID Card Reader
  279. #define GAP_APPEARE_HID_DIGITAL_PEN 0x03C7 //!< HID Digital Pen
  280. #define GAP_APPEARE_HID_BARCODE_SCANNER 0x03C8 //!< HID Barcode Scanner
  281. /** @} End GAP_APPEARANCE_VALUES */
  282. /*-------------------------------------------------------------------
  283. * TYPEDEFS - Initialization and Configuration
  284. */
  285. /**
  286. * GAP Parameters IDs: @ref GAP_PARAMETER_ID_DEFINES
  287. */
  288. typedef uint16 gapParamIDs_t;
  289. /**
  290. * GAP event header format.
  291. */
  292. typedef struct
  293. {
  294. osal_event_hdr_t hdr; //!< GAP_MSG_EVENT and status
  295. uint8 opcode; //!< GAP type of command. Ref: @ref GAP_MSG_EVENT_DEFINES
  296. } gapEventHdr_t;
  297. /**
  298. * GAP_RANDOM_ADDR_CHANGED_EVENT message format. This message is sent to the
  299. * app when the random address changes.
  300. */
  301. typedef struct
  302. {
  303. osal_event_hdr_t hdr; //!< GAP_MSG_EVENT and status
  304. uint8 opcode; //!< GAP_RANDOM_ADDR_CHANGED_EVENT
  305. uint8 addrType; //!< Address type: @ref GAP_ADDR_TYPE_DEFINES
  306. uint8 newRandomAddr[B_ADDR_LEN]; //!< the new calculated private addr
  307. } gapRandomAddrEvent_t;
  308. /**
  309. * Connection parameters for the peripheral device. These numbers are used
  310. * to compare against connection events and request connection parameter
  311. * updates with the master.
  312. */
  313. typedef struct
  314. {
  315. /** Minimum value for the connection event (interval. 0x0006 - 0x0C80 * 1.25 ms) */
  316. uint16 intervalMin;
  317. /** Maximum value for the connection event (interval. 0x0006 - 0x0C80 * 1.25 ms) */
  318. uint16 intervalMax;
  319. /** Number of LL latency connection events (0x0000 - 0x03e8) */
  320. uint16 latency;
  321. /** Connection Timeout (0x000A - 0x0C80 * 10 ms) */
  322. uint16 timeout;
  323. } gapPeriConnectParams_t;
  324. /**
  325. * GAP_DEVICE_INIT_DONE_EVENT message format. This message is sent to the
  326. * app when the Device Initialization is done [initiated by calling
  327. * GAP_DeviceInit()].
  328. */
  329. typedef struct
  330. {
  331. osal_event_hdr_t hdr; //!< GAP_MSG_EVENT and status
  332. uint8 opcode; //!< GAP_DEVICE_INIT_DONE_EVENT
  333. uint8 devAddr[B_ADDR_LEN]; //!< Device's BD_ADDR
  334. uint16 dataPktLen; //!< HC_LE_Data_Packet_Length
  335. uint8 numDataPkts; //!< HC_Total_Num_LE_Data_Packets
  336. } gapDeviceInitDoneEvent_t;
  337. /**
  338. * GAP_SIGNATURE_UPDATED_EVENT message format. This message is sent to the
  339. * app when the signature counter has changed. This message is to inform the
  340. * application in case it wants to save it to be restored on reboot or reconnect.
  341. * This message is sent to update a connection's signature counter and to update
  342. * this device's signature counter. If devAddr == BD_ADDR, then this message pertains
  343. * to this device.
  344. */
  345. typedef struct
  346. {
  347. osal_event_hdr_t hdr; //!< GAP_MSG_EVENT and status
  348. uint8 opcode; //!< GAP_SIGNATURE_UPDATED_EVENT
  349. uint8 addrType; //!< Device's address type for devAddr
  350. uint8 devAddr[B_ADDR_LEN]; //!< Device's BD_ADDR, could be own address
  351. uint32 signCounter; //!< new Signed Counter
  352. } gapSignUpdateEvent_t;
  353. /**
  354. * GAP_DEVICE_INFO_EVENT message format. This message is sent to the
  355. * app during a Device Discovery Request, when a new advertisement or scan
  356. * response is received.
  357. */
  358. typedef struct
  359. {
  360. osal_event_hdr_t hdr; //!< GAP_MSG_EVENT and status
  361. uint8 opcode; //!< GAP_DEVICE_INFO_EVENT
  362. uint8 eventType; //!< Advertisement Type: @ref GAP_ADVERTISEMENT_REPORT_TYPE_DEFINES
  363. uint8 addrType; //!< address type: @ref GAP_ADDR_TYPE_DEFINES
  364. uint8 addr[B_ADDR_LEN]; //!< Address of the advertisement or SCAN_RSP
  365. int8 rssi; //!< Advertisement or SCAN_RSP RSSI
  366. uint8 dataLen; //!< Length (in bytes) of the data field (evtData)
  367. uint8 *pEvtData; //!< Data field of advertisement or SCAN_RSP
  368. } gapDeviceInfoEvent_t;
  369. /*-------------------------------------------------------------------
  370. * TYPEDEFS - Device Discovery
  371. */
  372. /**
  373. * Type of device discovery (Scan) to perform.
  374. */
  375. typedef struct
  376. {
  377. uint8 taskID; //!< Requesting App's Task ID, used to return results
  378. uint8 mode; //!< Discovery Mode: @ref GAP_DEVDISC_MODE_DEFINES
  379. uint8 activeScan; //!< TRUE for active scanning
  380. uint8 whiteList; //!< TRUE to only allow advertisements from devices in the white list.
  381. } gapDevDiscReq_t;
  382. /**
  383. * Type of device discovery (Scan) to perform.
  384. */
  385. typedef struct
  386. {
  387. uint8 eventType; //!< Indicates advertising event type used by the advertiser: @ref GAP_ADVERTISEMENT_REPORT_TYPE_DEFINES
  388. uint8 addrType; //!< Address Type: @ref GAP_ADDR_TYPE_DEFINES
  389. uint8 addr[B_ADDR_LEN]; //!< Device's Address
  390. } gapDevRec_t;
  391. /**
  392. * GAP_DEVICE_DISCOVERY_EVENT message format. This message is sent to the
  393. * Application after a scan is performed.
  394. */
  395. typedef struct
  396. {
  397. osal_event_hdr_t hdr; //!< GAP_MSG_EVENT and status
  398. uint8 opcode; //!< GAP_DEVICE_DISCOVERY_EVENT
  399. uint8 numDevs; //!< Number of devices found during scan
  400. gapDevRec_t *pDevList; //!< array of device records
  401. } gapDevDiscEvent_t;
  402. /**
  403. * Advertising Parameters
  404. */
  405. typedef struct
  406. {
  407. uint8 eventType; //!< Advertise Event Type: @ref GAP_ADVERTISEMENT_TYPE_DEFINES
  408. uint8 initiatorAddrType; //!< Initiator's address type: @ref GAP_ADDR_TYPE_DEFINES
  409. uint8 initiatorAddr[B_ADDR_LEN]; //!< Initiator's addr - used only with connectable directed eventType (ADV_EVTTYPE_CONNECTABLE_DIRECTED).
  410. uint8 channelMap; //!< Channel Map: Bit mask @ref GAP_ADVCHAN_DEFINES
  411. uint8 filterPolicy; //!< Filer Policy: @ref GAP_FILTER_POLICY_DEFINES. Ignored when directed advertising is used.
  412. } gapAdvertisingParams_t;
  413. /**
  414. * GAP_MAKE_DISCOVERABLE_DONE_EVENT message format. This message is sent to the
  415. * app when the Advertise config is complete.
  416. */
  417. typedef struct
  418. {
  419. osal_event_hdr_t hdr; //!< GAP_MSG_EVENT and status
  420. uint8 opcode; //!< GAP_MAKE_DISCOVERABLE_DONE_EVENT
  421. uint16 interval; //!< actual advertising interval selected by controller
  422. } gapMakeDiscoverableRspEvent_t;
  423. /**
  424. * GAP_END_DISCOVERABLE_DONE_EVENT message format. This message is sent to the
  425. * app when the Advertising has stopped.
  426. */
  427. typedef struct
  428. {
  429. osal_event_hdr_t hdr; //!< GAP_MSG_EVENT and status
  430. uint8 opcode; //!< GAP_END_DISCOVERABLE_DONE_EVENT
  431. } gapEndDiscoverableRspEvent_t;
  432. /**
  433. * GAP_ADV_DATA_UPDATE_DONE_EVENT message format. This message is sent to the
  434. * app when Advertising Data Update is complete.
  435. */
  436. typedef struct
  437. {
  438. osal_event_hdr_t hdr; //!< GAP_MSG_EVENT and status
  439. uint8 opcode; //!< GAP_ADV_DATA_UPDATE_DONE_EVENT
  440. uint8 adType; //!< TRUE if advertising data, FALSE if SCAN_RSP
  441. } gapAdvDataUpdateEvent_t;
  442. /*-------------------------------------------------------------------
  443. * TYPEDEFS - Link Establishment
  444. */
  445. /**
  446. * Establish Link Request parameters
  447. */
  448. typedef struct
  449. {
  450. uint8 taskID; //!< Requesting App/Profile's Task ID
  451. uint8 highDutyCycle; //!< TRUE to high duty cycle scan, FALSE if not.
  452. uint8 whiteList; //!< Determines use of the white list: @ref GAP_WHITELIST_DEFINES
  453. uint8 addrTypePeer; //!< Address type of the advertiser: @ref GAP_ADDR_TYPE_DEFINES
  454. uint8 peerAddr[B_ADDR_LEN]; //!< Advertiser's address
  455. } gapEstLinkReq_t;
  456. /**
  457. * Update Link Parameters Request parameters
  458. */
  459. typedef struct
  460. {
  461. uint16 connectionHandle; //!< Connection handle of the update
  462. uint16 intervalMin; //!< Minimum Connection Interval
  463. uint16 intervalMax; //!< Maximum Connection Interval
  464. uint16 connLatency; //!< Connection Latency
  465. uint16 connTimeout; //!< Connection Timeout
  466. } gapUpdateLinkParamReq_t;
  467. /**
  468. * GAP_LINK_ESTABLISHED_EVENT message format. This message is sent to the app
  469. * when the link request is complete.<BR>
  470. * <BR>
  471. * For an Observer, this message is sent to complete the Establish Link Request.<BR>
  472. * For a Peripheral, this message is sent to indicate that a link has been created.
  473. */
  474. typedef struct
  475. {
  476. osal_event_hdr_t hdr; //!< GAP_MSG_EVENT and status
  477. uint8 opcode; //!< GAP_LINK_ESTABLISHED_EVENT
  478. uint8 devAddrType; //!< Device address type: @ref GAP_ADDR_TYPE_DEFINES
  479. uint8 devAddr[B_ADDR_LEN]; //!< Device address of link
  480. uint16 connectionHandle; //!< Connection Handle from controller used to ref the device
  481. uint16 connInterval; //!< Connection Interval
  482. uint16 connLatency; //!< Conenction Latency
  483. uint16 connTimeout; //!< Connection Timeout
  484. uint8 clockAccuracy; //!< Clock Accuracy
  485. } gapEstLinkReqEvent_t;
  486. /**
  487. * GAP_LINK_PARAM_UPDATE_EVENT message format. This message is sent to the app
  488. * when the connection parameters update request is complete.
  489. */
  490. typedef struct
  491. {
  492. osal_event_hdr_t hdr; //!< GAP_MSG_EVENT and status
  493. uint8 opcode; //!< GAP_LINK_PARAM_UPDATE_EVENT
  494. uint8 status; //!< bStatus_t
  495. uint16 connectionHandle; //!< Connection handle of the update
  496. uint16 connInterval; //!< Requested connection interval
  497. uint16 connLatency; //!< Requested connection latency
  498. uint16 connTimeout; //!< Requested connection timeout
  499. } gapLinkUpdateEvent_t;
  500. /**
  501. * GAP_LINK_TERMINATED_EVENT message format. This message is sent to the
  502. * app when a link to a device is terminated.
  503. */
  504. typedef struct
  505. {
  506. osal_event_hdr_t hdr; //!< GAP_MSG_EVENT and status
  507. uint8 opcode; //!< GAP_LINK_TERMINATED_EVENT
  508. uint16 connectionHandle; //!< connection Handle
  509. uint8 reason; //!< termination reason from LL
  510. } gapTerminateLinkEvent_t;
  511. /*-------------------------------------------------------------------
  512. * TYPEDEFS - Authentication, Bounding and Pairing
  513. */
  514. /**
  515. * GAP_PASSKEY_NEEDED_EVENT message format. This message is sent to the
  516. * app when a Passkey is needed from the app's user interface.
  517. */
  518. typedef struct
  519. {
  520. osal_event_hdr_t hdr; //!< GAP_MSG_EVENT and status
  521. uint8 opcode; //!< GAP_PASSKEY_NEEDED_EVENT
  522. uint8 deviceAddr[B_ADDR_LEN]; //!< address of device to pair with, and could be either public or random.
  523. uint16 connectionHandle; //!< Connection handle
  524. uint8 uiInputs; //!< Pairing User Interface Inputs - Ask user to input passcode
  525. uint8 uiOutputs; //!< Pairing User Interface Outputs - Display passcode
  526. } gapPasskeyNeededEvent_t;
  527. /**
  528. * GAP_AUTHENTICATION_COMPLETE_EVENT message format. This message is sent to the app
  529. * when the authentication request is complete.
  530. */
  531. typedef struct
  532. {
  533. osal_event_hdr_t hdr; //!< GAP_MSG_EVENT and status
  534. uint8 opcode; //!< GAP_AUTHENTICATION_COMPLETE_EVENT
  535. uint16 connectionHandle; //!< Connection Handle from controller used to ref the device
  536. uint8 authState; //!< TRUE if the pairing was authenticated (MITM)
  537. smSecurityInfo_t *pSecurityInfo; //!< BOUND - security information from this device
  538. smSigningInfo_t *pSigningInfo; //!< Signing information
  539. smSecurityInfo_t *pDevSecInfo; //!< BOUND - security information from connected device
  540. smIdentityInfo_t *pIdentityInfo; //!< BOUND - identity information
  541. } gapAuthCompleteEvent_t;
  542. /**
  543. * securityInfo and identityInfo are only used if secReqs.bondable == BOUND, which means that
  544. * the device is already bound and we should use the security information and keys.
  545. */
  546. typedef struct
  547. {
  548. uint16 connectionHandle; //!< Connection Handle from controller,
  549. smLinkSecurityReq_t secReqs; //!< Pairing Control info
  550. } gapAuthParams_t;
  551. /**
  552. * GAP_SLAVE_REQUESTED_SECURITY_EVENT message format. This message is sent to the app
  553. * when a Slave Security Request is received.
  554. */
  555. typedef struct
  556. {
  557. osal_event_hdr_t hdr; //!< GAP_MSG_EVENT and status
  558. uint8 opcode; //!< GAP_SLAVE_REQUESTED_SECURITY_EVENT
  559. uint16 connectionHandle; //!< Connection Handle
  560. uint8 deviceAddr[B_ADDR_LEN]; //!< address of device requesting security
  561. uint8 authReq; //!< Authentication Requirements: Bit 2: MITM, Bits 0-1: bonding (0 - no bonding, 1 - bonding)
  562. } gapSlaveSecurityReqEvent_t;
  563. /**
  564. * GAP_BOND_COMPLETE_EVENT message format. This message is sent to the
  565. * app when a bonding is complete. This means that a key is loaded and the link is encrypted.
  566. */
  567. typedef struct
  568. {
  569. osal_event_hdr_t hdr; //!< GAP_MSG_EVENT and status
  570. uint8 opcode; //!< GAP_BOND_COMPLETE_EVENT
  571. uint16 connectionHandle; //!< connection Handle
  572. } gapBondCompleteEvent_t;
  573. /**
  574. * Pairing Request fields - the parsed fields of the SMP Pairing Request command.
  575. */
  576. typedef struct
  577. {
  578. uint8 ioCap; //!< Pairing Request ioCap field
  579. uint8 oobDataFlag; //!< Pairing Request OOB Data Flag field
  580. uint8 authReq; //!< Pairing Request Auth Req field
  581. uint8 maxEncKeySize; //!< Pairing Request Maximum Encryption Key Size field
  582. keyDist_t keyDist; //!< Pairing Request Key Distribution field
  583. } gapPairingReq_t;
  584. /**
  585. * GAP_PAIRING_REQ_EVENT message format.<BR>
  586. * <BR>
  587. * This message is sent to the
  588. * app when an unexpected Pairing Request is received. The application is
  589. * expected to setup for a Security Manager pairing/bonding.<BR>
  590. * <BR>
  591. * To setup an SM Pairing, the application should call GAP_Authenticate() with these "pairReq" fields.<BR>
  592. * <BR>
  593. * NOTE: This message should only be sent to peripheral devices.
  594. */
  595. typedef struct
  596. {
  597. osal_event_hdr_t hdr; //!< GAP_MSG_EVENT and status
  598. uint8 opcode; //!< GAP_PAIRING_REQ_EVENT
  599. uint16 connectionHandle; //!< connection Handle
  600. gapPairingReq_t pairReq; //!< The Pairing Request fields received.
  601. } gapPairingReqEvent_t;
  602. /**
  603. * GAP Advertisement/Scan Response Data Token - These data items are stored as low byte first (OTA
  604. * format). The data space for these items are passed in and maintained by
  605. * the calling application
  606. */
  607. typedef struct
  608. {
  609. uint8 adType; //!< ADTYPE value: @ref GAP_ADTYPE_DEFINES
  610. uint8 attrLen; //!< Number of bytes in the attribute data
  611. uint8 *pAttrData; //!< pointer to Attribute data
  612. } gapAdvDataToken_t;
  613. /** @} End BLE_GAP_DEFINES */
  614. /*-------------------------------------------------------------------
  615. * GLOBAL VARIABLES
  616. */
  617. /**
  618. * @defgroup GAP_API GAP API Functions
  619. *
  620. * @{
  621. */
  622. /*-------------------------------------------------------------------
  623. * FUNCTIONS - Initialization and Configuation
  624. */
  625. /**
  626. * @brief Called to setup the device. Call just once on initialization.
  627. *
  628. * NOTE: When initialization is complete, the calling app will be
  629. * sent the GAP_DEVICE_INIT_DONE_EVENT
  630. *
  631. * @param taskID - Default task ID to send events.
  632. * @param profileRole - GAP Profile Roles: @ref GAP_PROFILE_ROLE_DEFINES
  633. * @param maxScanResponses - maximum number to scan responses
  634. * we can receive during a device discovery.
  635. * @param pIRK - pointer to Identity Root Key, NULLKEY (all zeroes) if the app
  636. * wants the GAP to generate the key.
  637. * @param pSRK - pointer to Sign Resolving Key, NULLKEY if the app
  638. * wants the GAP to generate the key.
  639. * @param pSignCounter - 32 bit value used in the SM Signing
  640. * algorithm that shall be initialized to zero and incremented
  641. * with every new signing. This variable must also be maintained
  642. * by the application.
  643. *
  644. * @return SUCCESS - Processing, expect GAP_DEVICE_INIT_DONE_EVENT, <BR>
  645. * INVALIDPARAMETER - for invalid profile role or role combination, <BR>
  646. * bleIncorrectMode - trouble communicating with HCI
  647. */
  648. extern bStatus_t GAP_DeviceInit( uint8 taskID,
  649. uint8 profileRole,
  650. uint8 maxScanResponses,
  651. uint8 *pIRK,
  652. uint8 *pSRK,
  653. uint32 *pSignCounter );
  654. /**
  655. * @brief Called to setup a GAP Advertisement/Scan Response data token.
  656. *
  657. * NOTE: The data in these items are stored as low byte first (OTA format).
  658. * The passed in structure "token" should be allocated by the calling app/profile
  659. * and not released until after calling GAP_RemoveAdvToken().
  660. *
  661. * @param pToken - Advertisement/Scan response token to write.
  662. *
  663. * @return SUCCESS - advertisement token added to the GAP list <BR>
  664. * INVALIDPARAMETER - Invalid Advertisement Type or pAttrData is NULL <BR>
  665. * INVALID_MEM_SIZE - The tokens take up too much space and don't fit into Advertisment data and Scan Response Data<BR>
  666. * bleInvalidRange - token ID already exists.<BR>
  667. * bleIncorrectMode - not a peripheral device<BR>
  668. * bleMemAllocError - memory allocation failure,
  669. */
  670. extern bStatus_t GAP_SetAdvToken( gapAdvDataToken_t *pToken );
  671. /**
  672. * @brief Called to read a GAP Advertisement/Scan Response data token.
  673. *
  674. * @param adType - Advertisement type to get
  675. *
  676. * @return pointer to the advertisement data token structure, NULL if not found.
  677. */
  678. extern gapAdvDataToken_t *GAP_GetAdvToken( uint8 adType );
  679. /**
  680. * @brief Called to remove a GAP Advertisement/Scan Response data token.
  681. *
  682. * @param adType - Advertisement type to remove
  683. *
  684. * @return pointer to the token structure removed from the GAP ADType list
  685. * NULL if the requested adType wasn't found.
  686. */
  687. extern gapAdvDataToken_t *GAP_RemoveAdvToken( uint8 adType );
  688. /**
  689. * @brief Called to rebuild and load Advertisement and Scan Response data from existing
  690. * GAP Advertisement Tokens.
  691. *
  692. * @return SUCCESS or bleIncorrectMode
  693. */
  694. extern bStatus_t GAP_UpdateAdvTokens( void );
  695. /**
  696. * @brief Set a GAP Parameter value. Use this function to change
  697. * the default GAP parameter values.
  698. *
  699. * @param paramID - parameter ID: @ref GAP_PARAMETER_ID_DEFINES
  700. * @param paramValue - new param value
  701. *
  702. * @return SUCCESS or INVALIDPARAMETER (invalid paramID)
  703. */
  704. extern bStatus_t GAP_SetParamValue( gapParamIDs_t paramID, uint16 paramValue );
  705. /**
  706. * @brief Get a GAP Parameter value.
  707. *
  708. * @param paramID - parameter ID: @ref GAP_PARAMETER_ID_DEFINES
  709. *
  710. * @return GAP Parameter value or 0xFFFF if invalid
  711. */
  712. extern uint16 GAP_GetParamValue( gapParamIDs_t paramID );
  713. /**
  714. * @brief Setup the device's address type. If ADDRTYPE_PRIVATE_RESOLVE
  715. * is selected, the address will change periodically.
  716. *
  717. * @param addrType - @ref GAP_ADDR_TYPE_DEFINES
  718. * @param pStaticAddr - Only used with ADDRTYPE_STATIC
  719. * or ADDRTYPE_PRIVATE_NONRESOLVE type.<BR>
  720. * NULL to auto generate otherwise the application
  721. * can specify the address value
  722. *
  723. * @return SUCCESS: address type updated,<BR>
  724. * bleNotReady: Can't be called until GAP_DeviceInit() is called
  725. * and the init process is completed,<BR>
  726. * bleIncorrectMode: can't change with an active connection,<BR>
  727. * or INVALIDPARAMETER.<BR>
  728. *
  729. * If return value isn't SUCCESS, the address type remains
  730. * the same as before this call.
  731. */
  732. extern bStatus_t GAP_ConfigDeviceAddr( uint8 addrType, uint8 *pStaticAddr );
  733. /**
  734. * @brief Register your task ID to receive extra (unwanted)
  735. * HCI status and complete events.
  736. *
  737. * @param taskID - Default task ID to send events.
  738. *
  739. * @return none
  740. */
  741. extern void GAP_RegisterForHCIMsgs( uint8 taskID );
  742. /*-------------------------------------------------------------------
  743. * FUNCTIONS - Device Discovery
  744. */
  745. /**
  746. * @brief Start a device discovery scan.
  747. *
  748. * @param pParams - Device Discovery parameters
  749. *
  750. * @return SUCCESS: scan started,<BR>
  751. * bleIncorrectMode: invalid profile role,<BR>
  752. * bleAlreadyInRequestedMode: not available<BR>
  753. */
  754. extern bStatus_t GAP_DeviceDiscoveryRequest( gapDevDiscReq_t *pParams );
  755. /**
  756. * @brief Cancel an existing device discovery request.
  757. *
  758. * @param taskID - used to return GAP_DEVICE_DISCOVERY_EVENT
  759. *
  760. * @return SUCCESS: cancel started,<BR>
  761. * bleInvalidTaskID: Not the task that started discovery,<BR>
  762. * bleIncorrectMode: not in discovery mode<BR>
  763. */
  764. extern bStatus_t GAP_DeviceDiscoveryCancel( uint8 taskID );
  765. /**
  766. * @brief Setup or change advertising. Also starts advertising.
  767. *
  768. * @param taskID - used to return GAP_DISCOVERABLE_RESPONSE_EVENT
  769. * @param pParams - advertising parameters
  770. *
  771. * @return SUCCESS: advertising started,<BR>
  772. * bleIncorrectMode: invalid profile role,<BR>
  773. * bleAlreadyInRequestedMode: not available at this time,<BR>
  774. * bleNotReady: advertising data isn't set up yet.<BR>
  775. */
  776. extern bStatus_t GAP_MakeDiscoverable( uint8 taskID, gapAdvertisingParams_t *pParams );
  777. /**
  778. * @brief Setup or change advertising and scan response data.
  779. *
  780. * NOTE: if the return status from this function is SUCCESS,
  781. * the task isn't complete until the GAP_ADV_DATA_UPDATE_DONE_EVENT
  782. * is sent to the calling application task.
  783. *
  784. * @param taskID - task ID of the app requesting the change
  785. * @param adType - TRUE - advertisement data, FALSE - scan response data
  786. * @param dataLen - Octet length of advertData
  787. * @param pAdvertData - advertising or scan response data
  788. *
  789. * @return SUCCESS: data accepted,<BR>
  790. * bleIncorrectMode: invalid profile role,<BR>
  791. */
  792. extern bStatus_t GAP_UpdateAdvertisingData( uint8 taskID, uint8 adType,
  793. uint8 dataLen, uint8 *pAdvertData );
  794. /**
  795. * @brief Stops advertising.
  796. *
  797. * @param taskID - of task that called GAP_MakeDiscoverable
  798. *
  799. * @return SUCCESS: stopping discoverable mode,<BR>
  800. * bleIncorrectMode: not in discoverable mode,<BR>
  801. * bleInvalidTaskID: not correct task<BR>
  802. */
  803. extern bStatus_t GAP_EndDiscoverable( uint8 taskID );
  804. /**
  805. * @brief Resolves a private address against an IRK.
  806. *
  807. * @param pIRK - pointer to the IRK
  808. * @param pAddr - pointer to the Resovable Private address
  809. *
  810. * @return SUCCESS: match,<BR>
  811. * FAILURE: don't match,<BR>
  812. * INVALIDPARAMETER: parameters invalid<BR>
  813. */
  814. extern bStatus_t GAP_ResolvePrivateAddr( uint8 *pIRK, uint8 *pAddr );
  815. /*-------------------------------------------------------------------
  816. * FUNCTIONS - Link Establishment
  817. */
  818. /**
  819. * @brief Establish a link to a slave device.
  820. *
  821. * @param pParams - link establishment parameters
  822. *
  823. * @return SUCCESS: started establish link process,<BR>
  824. * bleIncorrectMode: invalid profile role,<BR>
  825. * bleNotReady: a scan is in progress,<BR>
  826. * bleAlreadyInRequestedMode: can’t process now,<BR>
  827. * bleNoResources: Too many links<BR>
  828. */
  829. extern bStatus_t GAP_EstablishLinkReq( gapEstLinkReq_t *pParams );
  830. /**
  831. * @brief Terminate a link connection.
  832. *
  833. * @param taskID - requesting app's task id.
  834. * @param connectionHandle - connection handle of link to terminate
  835. * or @ref GAP_CONN_HANDLE_DEFINES
  836. * @param reason - terminate reason.
  837. *
  838. * @return SUCCESS: Terminate started,<BR>
  839. * bleIncorrectMode: No Link to terminate,<BR>
  840. * bleInvalidTaskID: not app that established link<BR>
  841. */
  842. extern bStatus_t GAP_TerminateLinkReq( uint8 taskID, uint16 connectionHandle, uint8 reason );
  843. /**
  844. * @brief Update the link parameters to a slave device.
  845. *
  846. * @param pParams - link update parameters
  847. *
  848. * @return SUCCESS: started update link process,<BR
  849. * INVALIDPARAMETER: one of the parameters were invalid,<BR>
  850. * bleIncorrectMode: invalid profile role,<BR>
  851. * bleNotConnected: not in a connection<BR>
  852. */
  853. extern bStatus_t GAP_UpdateLinkParamReq( gapUpdateLinkParamReq_t *pParams );
  854. /**
  855. * @brief Returns the number of active connections.
  856. *
  857. * @return Number of active connections.
  858. */
  859. extern uint8 GAP_NumActiveConnections( void );
  860. /*-------------------------------------------------------------------
  861. * FUNCTIONS - Pairing
  862. */
  863. /**
  864. * @brief Start the Authentication process with the requested device.
  865. * This function is used to Initiate/Allow pairing.
  866. * Called by both master and slave device (Central and Peripheral).
  867. *
  868. * NOTE: This function is called after the link is established.
  869. *
  870. * @param pParams - Authentication parameters
  871. * @param pPairReq - Enter these parameters if the Pairing Request was already received.
  872. * NULL, if waiting for Pairing Request or if initiating.
  873. *
  874. * @return SUCCESS,<BR>
  875. * bleIncorrectMode: Not correct profile role,<BR>
  876. * INVALIDPARAMETER, <BR>
  877. * bleNotConnected,<BR>
  878. * bleAlreadyInRequestedMode,<BR>
  879. * FAILURE - not workable.<BR>
  880. */
  881. extern bStatus_t GAP_Authenticate( gapAuthParams_t *pParams, gapPairingReq_t *pPairReq );
  882. /**
  883. * @brief Send a Pairing Failed message and end any existing pairing.
  884. *
  885. * @param connectionHandle - connection handle.
  886. * @param reason - Pairing Failed reason code.
  887. *
  888. * @return SUCCESS - function was successful,<BR>
  889. * bleMemAllocError - memory allocation error,<BR>
  890. * INVALIDPARAMETER - one of the parameters were invalid,<BR>
  891. * bleNotConnected - link not found,<BR>
  892. * bleInvalidRange - one of the parameters were not within range.
  893. */
  894. extern bStatus_t GAP_TerminateAuth( uint16 connectionHandle, uint8 reason );
  895. /**
  896. * @brief Update the passkey in string format. This function is called by the
  897. * application/profile in response to receiving the
  898. * GAP_PASSKEY_NEEDED_EVENT message.
  899. *
  900. * NOTE: This function is the same as GAP_PasscodeUpdate(), except that
  901. * the passkey is passed in as a string format.
  902. *
  903. * @param pPasskey - new passkey - pointer to numeric string (ie. "019655" ).
  904. * This string's range is "000000" to "999999".
  905. * @param connectionHandle - connection handle.
  906. *
  907. * @return SUCCESS: will start pairing with this entry,<BR>
  908. * bleIncorrectMode: Link not found,<BR>
  909. * INVALIDPARAMETER: passkey == NULL or passkey isn't formatted properly.<BR>
  910. */
  911. extern bStatus_t GAP_PasskeyUpdate( uint8 *pPasskey, uint16 connectionHandle );
  912. /**
  913. * @brief Update the passkey in a numeric value (not string).
  914. * This function is called by the application/profile in response
  915. * to receiving the GAP_PASSKEY_NEEDED_EVENT message.
  916. *
  917. * NOTE: This function is the same as GAP_PasskeyUpdate(), except that
  918. * the passkey is passed in as a non-string format.
  919. *
  920. * @param passcode - not string - range: 0 - 999,999.
  921. * @param connectionHandle - connection handle.
  922. *
  923. * @return SUCCESS: will start pairing with this entry,<BR>
  924. * bleIncorrectMode: Link not found,<BR>
  925. * INVALIDPARAMETER: passkey == NULL or passkey isn't formatted properly.<BR>
  926. */
  927. extern bStatus_t GAP_PasscodeUpdate( uint32 passcode, uint16 connectionHandle );
  928. /**
  929. * @brief Generate a Slave Requested Security message to the master.
  930. *
  931. * @param connectionHandle - connection handle.
  932. * @param authReq - Authentication Requirements: Bit 2: MITM, Bits 0-1: bonding (0 - no bonding, 1 - bonding)
  933. *
  934. * @return SUCCESS: will send,<BR>
  935. * bleNotConnected: Link not found,<BR>
  936. * bleIncorrectMode: wrong GAP role, must be a Peripheral Role<BR>
  937. */
  938. extern bStatus_t GAP_SendSlaveSecurityRequest( uint16 connectionHandle, uint8 authReq );
  939. /**
  940. * @brief Set up the connection to accept signed data.
  941. *
  942. * NOTE: This function is called after the link is established.
  943. *
  944. * @param connectionHandle - connection handle of the signing information
  945. * @param authenticated - TRUE if the signing information is authenticated, FALSE otherwise
  946. * @param pParams - signing parameters
  947. *
  948. * @return SUCCESS, <BR>
  949. * bleIncorrectMode: Not correct profile role,<BR>
  950. * INVALIDPARAMETER, <BR>
  951. * bleNotConnected,<BR>
  952. * FAILURE: not workable.<BR>
  953. */
  954. extern bStatus_t GAP_Signable( uint16 connectionHandle, uint8 authenticated, smSigningInfo_t *pParams );
  955. /**
  956. * @brief Set up the connection's bound paramaters.
  957. *
  958. * NOTE: This function is called after the link is established.
  959. *
  960. * @param connectionHandle - connection handle of the signing information
  961. * @param authenticated - this connection was previously authenticated
  962. * @param pParams - the connected device's security parameters
  963. * @param startEncryption - whether or not to start encryption
  964. *
  965. * @return SUCCESS, <BR>
  966. * bleIncorrectMode: Not correct profile role,<BR>
  967. * INVALIDPARAMETER, <BR>
  968. * bleNotConnected,<BR>
  969. * FAILURE: not workable.<BR>
  970. */
  971. extern bStatus_t GAP_Bond( uint16 connectionHandle, uint8 authenticated,
  972. smSecurityInfo_t *pParams, uint8 startEncryption );
  973. /**
  974. * @} End GAP_API
  975. */
  976. /*-------------------------------------------------------------------
  977. * Internal API - These functions are only called from gap.c module.
  978. */
  979. /**
  980. * @internal
  981. *
  982. * @brief Setup the device configuration parameters.
  983. *
  984. * @param taskID - Default task ID to send events.
  985. * @param profileRole - GAP Profile Roles
  986. *
  987. * @return SUCCESS or bleIncorrectMode
  988. */
  989. extern bStatus_t GAP_ParamsInit( uint8 taskID, uint8 profileRole );
  990. /**
  991. * @internal
  992. *
  993. * @brief Setup the device security configuration parameters.
  994. *
  995. * @param pIRK - pointer to Identity Root Key, NULLKEY (all zeroes) if the app
  996. * wants the GAP to generate the key.
  997. * @param pSRK - pointer to Sign Resolving Key, NULLKEY if the app
  998. * wants the GAP to generate the key.
  999. * @param pSignCounter - 32 bit value used in the SM Signing
  1000. * algorithm that shall be initialized to zero and incremented
  1001. * with every new signing. This variable must also be maintained
  1002. * by the application.
  1003. *
  1004. * @return none
  1005. */
  1006. extern void GAP_SecParamsInit( uint8 *pIRK, uint8 *pSRK, uint32 *pSignCounter );
  1007. /**
  1008. * @internal
  1009. *
  1010. * @brief Initialize the GAP Peripheral Dev Manager.
  1011. *
  1012. * @param none
  1013. *
  1014. * @return SUCCESS or bleMemAllocError
  1015. */
  1016. extern bStatus_t GAP_PeriDevMgrInit( void );
  1017. /**
  1018. * @internal
  1019. *
  1020. * @brief Initialize the GAP Central Dev Manager.
  1021. *
  1022. * @param maxScanResponses - maximum number to scan responses
  1023. * we can receive during a device discovery.
  1024. *
  1025. * @return SUCCESS or bleMemAllocError
  1026. */
  1027. extern bStatus_t GAP_CentDevMgrInit( uint8 maxScanResponses );
  1028. /**
  1029. * @internal
  1030. *
  1031. * @brief Register the GAP Central Connection processing functions.
  1032. *
  1033. * @param none
  1034. *
  1035. * @return none
  1036. */
  1037. extern void GAP_CentConnRegister( void );
  1038. /*-------------------------------------------------------------------
  1039. * TASK API - These functions must only be called OSAL.
  1040. */
  1041. /**
  1042. * @internal
  1043. *
  1044. * @brief GAP Task initialization function.
  1045. *
  1046. * @param taskID - GAP task ID.
  1047. *
  1048. * @return void
  1049. */
  1050. extern void GAP_Init( uint8 task_id );
  1051. /**
  1052. * @internal
  1053. *
  1054. * @brief GAP Task event processing function.
  1055. *
  1056. * @param taskID - GAP task ID
  1057. * @param events - GAP events.
  1058. *
  1059. * @return events not processed
  1060. */
  1061. extern uint16 GAP_ProcessEvent( uint8 task_id, uint16 events );
  1062. /*-------------------------------------------------------------------
  1063. -------------------------------------------------------------------*/
  1064. #ifdef __cplusplus
  1065. }
  1066. #endif
  1067. #endif /* GAP_H */