MS_brr_api.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. /**
  2. * \file MS_brr_api.h
  3. *
  4. * \brief This file defines the Mesh Bearer Application Interface - includes
  5. * Data Structures and Methods.
  6. */
  7. /*
  8. * Copyright (C) 2017. Mindtree Ltd.
  9. * All rights reserved.
  10. */
  11. #ifndef _H_MS_BRR_API_
  12. #define _H_MS_BRR_API_
  13. /* --------------------------------------------- Header File Inclusion */
  14. #include "MS_common.h"
  15. /* --------------------------------------------- Global Definitions */
  16. /**
  17. * \defgroup brr_module BEARER (Mesh Bearer Layer)
  18. * \{
  19. * This section describes the interfaces & APIs offered by the EtherMind
  20. * Mesh Bearer (BEARER) module to the Application and other upper
  21. * layers of the stack.
  22. */
  23. /**
  24. * \defgroup brr_defines Defines
  25. * \{
  26. * Describes defines for the module.
  27. */
  28. /**
  29. * \defgroup brr_constants Constants
  30. * \{
  31. * Describes Constants defined by the module.
  32. */
  33. /** Invalid Bearer handle identifier */
  34. #define BRR_HANDLE_INVALID 0xFF
  35. /** Bearer Interface events to the above layer */
  36. #define BRR_IFACE_DOWN 0x00
  37. #define BRR_IFACE_UP 0x01
  38. #define BRR_IFACE_DATA 0x02
  39. #define BRR_IFACE_PROXY_DATA 0x03
  40. /** Bearer beacon types - Connectable (Active) and Non-Connectable (Passive) */
  41. #define BRR_BCON_PASSIVE 0x00
  42. #define BRR_BCON_ACTIVE 0x01
  43. /** Bearer Beacon Operations - Broadcast/Observe */
  44. #define BRR_BROADCAST 0x00
  45. #define BRR_OBSERVE 0x01
  46. /** Bearer Beacon Actions - Enable/Disable */
  47. #define BRR_DISABLE 0x00
  48. #define BRR_ENABLE 0x01
  49. /** Maximum PDU size for data received over bearer */
  50. #define BRR_MAX_PDU_SIZE 65
  51. /** Bearer Server Client Roles */
  52. #define BRR_CLIENT_ROLE 0x00
  53. #define BRR_SERVER_ROLE 0x01
  54. #define BRR_INVALID_ROLE 0xFF
  55. /** Bearer Transmit and Receive operation modes */
  56. #define BRR_TX 0x01
  57. #define BRR_RX 0x02
  58. /** \} */
  59. /** \} */
  60. /**
  61. * \defgroup brr_events Events
  62. * \{
  63. * This section lists the Asynchronous Events notified to Application by the
  64. * Module.
  65. */
  66. /**
  67. * \defgroup brr_marcos Utility Macros
  68. * \{
  69. * Initialization and other Utility Macros offered by the module.
  70. */
  71. /** \} */
  72. /** \} */
  73. /* --------------------------------------------- Data Types/ Structures */
  74. /**
  75. * \addtogroup brr_defines Defines
  76. * \{
  77. */
  78. /** Bearer handle identifier */
  79. typedef UCHAR BRR_HANDLE;
  80. /** Bearer Type definitions */
  81. typedef enum _BRR_TYPE
  82. {
  83. /** Beacon Bearer */
  84. BRR_TYPE_BCON,
  85. /** Advertising Bearer */
  86. BRR_TYPE_ADV,
  87. /** Provisioning Advertising Bearer */
  88. BRR_TYPE_PB_ADV,
  89. /** GATT Bearer */
  90. BRR_TYPE_GATT,
  91. /** Provisioning GATT Bearer */
  92. BRR_TYPE_PB_GATT,
  93. /** Number of bearers supported */
  94. BRR_COUNT
  95. } BRR_TYPE;
  96. /* GATT Bearer Message Type Masks */
  97. #define BRR_SUBTYPE_GATT_T_MASK_BIT_OFFSET 6
  98. #define BRR_SUBTYPE_GATT_T_MASK (0xC0)
  99. #define BRR_SUBTYPE_GATT_NETWORK_T_MASK ((MESH_GATT_TYPE_NETWORK << BRR_SUBTYPE_GATT_T_MASK_BIT_OFFSET) & (BRR_SUBTYPE_GATT_T_MASK))
  100. #define BRR_SUBTYPE_GATT_BEACON_T_MASK ((MESH_GATT_TYPE_BEACON << BRR_SUBTYPE_GATT_T_MASK_BIT_OFFSET) & (BRR_SUBTYPE_GATT_T_MASK))
  101. #define BRR_SUBTYPE_GATT_PROXY_T_MASK ((MESH_GATT_TYPE_PROXY << BRR_SUBTYPE_GATT_T_MASK_BIT_OFFSET) & (BRR_SUBTYPE_GATT_T_MASK))
  102. #define BRR_SUBTYPE_GATT_PROV_T_MASK ((MESH_GATT_TYPE_PROV << BRR_SUBTYPE_GATT_T_MASK_BIT_OFFSET) & (BRR_SUBTYPE_GATT_T_MASK))
  103. /** Bearer Beacon type definitions */
  104. typedef enum _BRR_BCON_TYPE
  105. {
  106. /* Unprovisioned Device Beacon */
  107. BRR_BCON_TYPE_UNPROV_DEVICE,
  108. /* Secure Network Beacon */
  109. BRR_BCON_TYPE_SECURE_NET,
  110. /* Proxy beacon with Network ID */
  111. BRR_BCON_TYPE_PROXY_NETID,
  112. /* Proxy beacon with Node Identity */
  113. BRR_BCON_TYPE_PROXY_NODEID,
  114. /** Number of Beacon types */
  115. BRR_BCON_COUNT
  116. } BRR_BCON_TTYPE;
  117. /**
  118. * \addtogroup brr_structures Structures
  119. * \{
  120. */
  121. /** Bearer information to register */
  122. typedef struct _BRR_BEARER_INFO
  123. {
  124. /** Bearer Information */
  125. MS_BUFFER * binfo;
  126. /** Data Send routine */
  127. API_RESULT (*bearer_send)(BRR_HANDLE *, UCHAR, void *, UINT16);
  128. /** Data Receive routine */
  129. void (*bearer_recv)(BRR_HANDLE *, UCHAR *, UINT16, MS_BUFFER * info);
  130. /** Bearer Sleep Interface */
  131. void (*bearer_sleep)(BRR_HANDLE *);
  132. /** Bearer Wakeup Interface */
  133. void (*bearer_wakeup)(BRR_HANDLE *, UINT8 mode);
  134. } BRR_BEARER_INFO;
  135. /** Bearer Beacon type data structure */
  136. typedef struct _BRR_BEACON_INFO
  137. {
  138. /**
  139. * Beacon Action
  140. * - Lower Nibble:
  141. * > BRR_OBSERVE
  142. * > BRR_BROADCAST
  143. *
  144. * - Higher Nibble:
  145. * > BRR_ENABLE
  146. * > BRR_DISABLE
  147. */
  148. UCHAR action;
  149. /**
  150. * Beacon type
  151. * - Lower Nibble:
  152. * > BRR_BCON_PASSIVE - Non Connectable beacon
  153. * > BRR_BCON_ACTIVE - Connectable beacon
  154. *
  155. * - Higher Nibble (Valid only when Passive)
  156. * > BRR_BCON_TYPE_UNPROV_DEVICE
  157. * > BRR_BCON_TYPE_SECURE_NET
  158. */
  159. UCHAR type;
  160. /** Beacon Broadcast Data */
  161. UCHAR * bcon_data;
  162. /** Beacon Broadcast Data length */
  163. UINT16 bcon_datalen;
  164. /** URI information in case of Unprovisioned Beacons */
  165. MS_BUFFER * uri;
  166. } BRR_BEACON_INFO;
  167. /** Bearer GATT Channel informartion related data structure */
  168. typedef struct _BRR_BEARER_CH_INFO
  169. {
  170. /** Identifies the MTU for the Bearer Channel */
  171. UINT16 mtu;
  172. /** Identifies the role for the Bearer channel */
  173. UCHAR role;
  174. }BRR_BEARER_CH_INFO;
  175. /** \} */
  176. /** \} */
  177. /**
  178. * \defgroup brr_cb Application Callback
  179. * \{
  180. * This Section Describes the module Notification Callback interface offered
  181. * to the application
  182. */
  183. /**
  184. * BEARER Application Asynchronous Notification Callback.
  185. *
  186. * BEARER calls the registered callback to indicate events occurred to the
  187. * application.
  188. *
  189. * \param brr_type Bearer Type.
  190. * \param data Data associated with the event if any or NULL.
  191. * \param data_len Size of the event data. 0 if event data is NULL.
  192. */
  193. typedef API_RESULT (*BRR_NTF_CB)
  194. (
  195. BRR_HANDLE * brr_handle,
  196. UCHAR brr_event,
  197. UCHAR * data_param,
  198. UINT16 data_len
  199. ) DECL_REENTRANT;
  200. /**
  201. * BEARER Application Asynchronous Notification Callback for Beacons.
  202. *
  203. * Application registers callback for beacon notification with bearer.
  204. *
  205. * \param brr_type Bearer Type.
  206. * \param data Data associated with the event if any or NULL.
  207. * \param data_len Size of the event data. 0 if event data is NULL.
  208. */
  209. typedef void (*BRR_BCON_CB)
  210. (
  211. UCHAR * data_param,
  212. UINT16 data_len
  213. ) DECL_REENTRANT;
  214. /** \} */
  215. /**
  216. * \addtogroup brr_defines Defines
  217. * \{
  218. */
  219. /**
  220. * \addtogroup brr_structures Structures
  221. * \{
  222. */
  223. /** \} */
  224. /** \} */
  225. /* --------------------------------------------- Function */
  226. /**
  227. * \defgroup brr_api_defs API Definitions
  228. * \{
  229. * This section describes the EtherMind Mesh Bearer Layer APIs.
  230. */
  231. #ifdef __cplusplus
  232. extern "C" {
  233. #endif
  234. /**
  235. * \brief Register Interface with Bearer Layer
  236. *
  237. * \par Description
  238. * This routine registers interface with the Bearer Layer.
  239. * Bearer Layer supports single Application, hence this rouine shall be called once.
  240. *
  241. * \param [in] brr_type
  242. * Bearer Type
  243. *
  244. * \param [in] brr_cb
  245. * Details describing Application Notification Callback
  246. *
  247. * \return API_SUCCESS or an error code indicating reason for failure
  248. *
  249. */
  250. API_RESULT MS_brr_register
  251. (
  252. /* IN */ BRR_TYPE brr_type,
  253. /* IN */ BRR_NTF_CB brr_cb
  254. );
  255. /**
  256. * \brief Register Beacon Interface with Bearer Layer
  257. *
  258. * \par Description
  259. * This routine registers interface with the Bearer Layer to process Beacons.
  260. * Bearer Layer supports single Application, hence this rouine shall be called once.
  261. *1
  262. * \param [in] bcon_type
  263. * Beacon type - Unprovisioned Device or Secure Network.
  264. *
  265. * \param [in] bcon_handler
  266. * Callback handler to be registered for the given beacon type.
  267. *
  268. * \return API_SUCCESS or an error code indicating reason for failure
  269. *
  270. */
  271. API_RESULT MS_brr_register_beacon_handler
  272. (
  273. /* IN */ UCHAR bcon_type,
  274. /* IN */ void (*bcon_handler) (UCHAR * data, UINT16 datalen)
  275. );
  276. /**
  277. * \brief Add a bearer to Bearer Layer
  278. *
  279. * \par Description
  280. * This routine adds a bearer that is setup by the application
  281. * for use by the Mesh Stack. Bearer Layer supports single Application,
  282. * hence this rouine shall be called once.
  283. *
  284. * \param [in] brr_type
  285. * Bearer Type
  286. *
  287. * \param [in] brr_info
  288. * Details describing the Bearer being added
  289. *
  290. * \param [out] brr_handle
  291. * Handle to the bearer that is added. Used in data APIs.
  292. *
  293. * \return API_SUCCESS or an error code indicating reason for failure
  294. *
  295. */
  296. API_RESULT MS_brr_add_bearer
  297. (
  298. /* IN */ BRR_TYPE brr_type,
  299. /* IN */ BRR_BEARER_INFO * brr_info,
  300. /* OUT */ BRR_HANDLE * brr_handle
  301. );
  302. /**
  303. * \brief Remove a bearer from Bearer Layer
  304. *
  305. * \par Description
  306. * This routine removes a bearer from the Mesh Stack. Bearer Layer
  307. * supports single Application, hence this rouine shall be called once.
  308. *
  309. * \param [in] brr_type
  310. * Bearer Type
  311. *
  312. * \param [out] brr_handle
  313. * Handle to the bearer that is added. Used in data APIs.
  314. *
  315. * \return API_SUCCESS or an error code indicating reason for failure
  316. *
  317. */
  318. API_RESULT MS_brr_remove_bearer
  319. (
  320. /* IN */ BRR_TYPE brr_type,
  321. /* IN */ BRR_HANDLE * brr_handle
  322. );
  323. /**
  324. * \brief Observe ON/OFF for the beacon type
  325. *
  326. * \par Description
  327. * This routine sends enables/disables the observation procedure
  328. * for the given beacon type.
  329. *
  330. * \param [in] bcon_type
  331. * Type of beacon to observe - Active/Passive.
  332. *
  333. * \param [in] enable
  334. * Enable or Disable the observation procedure.
  335. *
  336. * \return API_SUCCESS or an error code indicating reason for failure
  337. *
  338. */
  339. API_RESULT MS_brr_observe_beacon
  340. (
  341. /* IN */ UCHAR bcon_type,
  342. /* IN */ UCHAR enable
  343. );
  344. /**
  345. * \brief API to send Unprovisioned Device Beacon
  346. *
  347. * \par Description
  348. * This routine sends Unprovisioned Device Beacon
  349. *
  350. * \param [in] type
  351. * Active or Passive Broadcast type.
  352. *
  353. * \param [in] dev_uuid
  354. * Device UUID uniquely identifying this device.
  355. *
  356. * \param [in] oob_info
  357. * OOB Information
  358. *
  359. * \param [in] uri
  360. * Optional Parameter. NULL if not present.
  361. * Points to the length and payload pointer of the URI string to be
  362. * advertised interleaving with the unprovisioned beacon.
  363. *
  364. * \return API_SUCCESS or an error code indicating reason for failure
  365. */
  366. API_RESULT MS_brr_bcast_unprovisioned_beacon
  367. (
  368. /* IN */ UCHAR type,
  369. /* IN */ UCHAR * dev_uuid,
  370. /* IN */ UINT16 oob_info,
  371. /* IN */ MS_BUFFER * uri
  372. );
  373. /**
  374. * \brief API to broadcast a beacon
  375. *
  376. * \par Description
  377. * This routine sends the beacon of given type on Adv and GATT bearers
  378. *
  379. * \param [in] type
  380. * The type of beacon
  381. *
  382. * \param [in] packet
  383. * Beacon data
  384. *
  385. * \param [in] length
  386. * Beacon data length
  387. *
  388. * \return API_SUCCESS or an error code indicating reason for failure
  389. */
  390. API_RESULT MS_brr_broadcast_beacon
  391. (
  392. /* IN */ UCHAR type,
  393. /* IN */ UCHAR * packet,
  394. /* IN */ UINT16 length
  395. );
  396. /**
  397. * \brief API to send Proxy Device ADV
  398. *
  399. * \par Description
  400. * This routine sends Proxy Device ADV
  401. *
  402. * \param [in] type
  403. * Proxy ADV Type:
  404. * 0x00 - Network ID
  405. * 0x01 - Node Identity
  406. *
  407. * \param [in] data
  408. * Data to be advertised by Proxy.
  409. * If the "type" is:
  410. * 0x00 - Network ID - 8 Bytes of Network ID
  411. * 0x01 - Node Identity - 8 Bytes Hash, 8 Bytes Random num
  412. *
  413. * \param [in] datalen
  414. * Length of the data to be advertised by Proxy.
  415. * If the "type" is:
  416. * 0x00 - Network ID - 8 Bytes of Network ID
  417. * 0x01 - Node Identity - 8 Bytes Hash, 8 Bytes Random num
  418. *
  419. * \return API_SUCCESS or an error code indicating reason for failure
  420. */
  421. API_RESULT MS_brr_start_proxy_adv
  422. (
  423. /* IN */ UCHAR type,
  424. /* IN */ UCHAR * data,
  425. /* IN */ UINT16 datalen
  426. );
  427. /**
  428. * \brief API to disable broadcast of given beacon type
  429. *
  430. * \par Description
  431. * This routine stops advertising of given beacon type.
  432. *
  433. * \param [in] bcon
  434. * The Bearer Beacon (Unprovisioned/Secure Network).
  435. *
  436. * \param [in] type
  437. * The type of braodcast beacon (Active/Passive).
  438. *
  439. * \return API_SUCCESS or an error code indicating reason for failure
  440. */
  441. API_RESULT MS_brr_bcast_end
  442. (
  443. /* IN */ UCHAR bcon,
  444. /* IN */ UCHAR type
  445. );
  446. /**
  447. * \brief Send a bearer PDU
  448. *
  449. * \par Description
  450. * This routine sends a PDU from the Mesh stack to over the bearer
  451. * indicated by the bearer handle.
  452. *
  453. * \param [in] brr_handle
  454. * Bearer handle on which PDU is to be sent.
  455. *
  456. * \param [in] brr_type
  457. * Type of Bearer as in \ref BRR_TYPE.
  458. *
  459. * \param [in] buffer
  460. * PDU data to be sent.
  461. *
  462. * \return API_SUCCESS or an error code indicating reason for failure
  463. *
  464. */
  465. API_RESULT MS_brr_send_pdu
  466. (
  467. /* IN */ BRR_HANDLE * brr_handle,
  468. /* IN */ BRR_TYPE brr_type,
  469. /* IN */ MS_BUFFER * buffer
  470. );
  471. /**
  472. * \brief Get the RSSI of current received packet being processed.
  473. *
  474. * \par Description
  475. * This routine returns the RSSI value of the received packet in its
  476. * context when called from the Mesh stack.
  477. *
  478. * \return RSSI value of the current packet in context.
  479. *
  480. * \note This applies only when the packet is received over ADV bearer
  481. *
  482. */
  483. UCHAR MS_brr_get_packet_rssi(void);
  484. /**
  485. * \brief Put the bearer to sleep.
  486. *
  487. * \par Description
  488. * This routine requests the underlying bearer interface to sleep.
  489. * Default bearer interface is that of advertising bearer.
  490. *
  491. * \return API_SUCCESS
  492. *
  493. */
  494. API_RESULT MS_brr_sleep(void);
  495. /**
  496. * \brief Wakeup the bearer.
  497. *
  498. * \par Description
  499. * This routine requests the underlying bearer interface to wakeup.
  500. * Default bearer interface is that of advertising bearer.
  501. *
  502. * \param mode
  503. * Identifies the mode (BRR_TX/BRR_RX) for which bearer is requested
  504. * for wakeup.
  505. *
  506. * \return API_SUCCESS
  507. *
  508. */
  509. API_RESULT MS_brr_wakeup(UINT8 mode);
  510. #ifdef __cplusplus
  511. };
  512. #endif
  513. /** \} */
  514. /** \} */
  515. #endif /* _H_MS_BRR_API_ */