main.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. /** @file
  2. * @brief Bluetooth mesh Profile APIs.
  3. */
  4. /*
  5. * Copyright (c) 2017 Intel Corporation
  6. *
  7. * SPDX-License-Identifier: Apache-2.0
  8. */
  9. #ifndef ZEPHYR_INCLUDE_BLUETOOTH_MESH_MAIN_H_
  10. #define ZEPHYR_INCLUDE_BLUETOOTH_MESH_MAIN_H_
  11. /**
  12. * @brief Provisioning
  13. * @defgroup bt_mesh_prov Provisioning
  14. * @ingroup bt_mesh
  15. * @{
  16. */
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /** Available Provisioning output authentication actions. */
  21. typedef enum {
  22. BT_MESH_NO_OUTPUT = 0,
  23. BT_MESH_BLINK = BIT(0),
  24. BT_MESH_BEEP = BIT(1),
  25. BT_MESH_VIBRATE = BIT(2),
  26. BT_MESH_DISPLAY_NUMBER = BIT(3),
  27. BT_MESH_DISPLAY_STRING = BIT(4),
  28. } bt_mesh_output_action_t;
  29. /** Available Provisioning input authentication actions. */
  30. typedef enum {
  31. BT_MESH_NO_INPUT = 0,
  32. BT_MESH_PUSH = BIT(0),
  33. BT_MESH_TWIST = BIT(1),
  34. BT_MESH_ENTER_NUMBER = BIT(2),
  35. BT_MESH_ENTER_STRING = BIT(3),
  36. } bt_mesh_input_action_t;
  37. /** Available Provisioning bearers. */
  38. typedef enum {
  39. BT_MESH_PROV_ADV = BIT(0),
  40. BT_MESH_PROV_GATT = BIT(1),
  41. } bt_mesh_prov_bearer_t;
  42. /** Out of Band information location. */
  43. typedef enum {
  44. BT_MESH_PROV_OOB_OTHER = BIT(0),
  45. BT_MESH_PROV_OOB_URI = BIT(1),
  46. BT_MESH_PROV_OOB_2D_CODE = BIT(2),
  47. BT_MESH_PROV_OOB_BAR_CODE = BIT(3),
  48. BT_MESH_PROV_OOB_NFC = BIT(4),
  49. BT_MESH_PROV_OOB_NUMBER = BIT(5),
  50. BT_MESH_PROV_OOB_STRING = BIT(6),
  51. /* 7 - 10 are reserved */
  52. BT_MESH_PROV_OOB_ON_BOX = BIT(11),
  53. BT_MESH_PROV_OOB_IN_BOX = BIT(12),
  54. BT_MESH_PROV_OOB_ON_PAPER = BIT(13),
  55. BT_MESH_PROV_OOB_IN_MANUAL = BIT(14),
  56. BT_MESH_PROV_OOB_ON_DEV = BIT(15),
  57. } bt_mesh_prov_oob_info_t;
  58. /** Device Capabilities. */
  59. struct bt_mesh_dev_capabilities {
  60. /** Number of elements supported by the device */
  61. uint8_t elem_count;
  62. /** Supported algorithms and other capabilities */
  63. uint16_t algorithms;
  64. /** Supported public key types */
  65. uint8_t pub_key_type;
  66. /** Supported static OOB Types */
  67. uint8_t static_oob;
  68. /** Supported Output OOB Actions */
  69. bt_mesh_output_action_t output_actions;
  70. /** Supported Input OOB Actions */
  71. bt_mesh_input_action_t input_actions;
  72. /** Maximum size of Output OOB supported */
  73. uint8_t output_size;
  74. /** Maximum size in octets of Input OOB supported */
  75. uint8_t input_size;
  76. };
  77. /** Provisioning properties & capabilities. */
  78. struct bt_mesh_prov {
  79. /** The UUID that's used when advertising as unprovisioned */
  80. const uint8_t *uuid;
  81. /** Optional URI. This will be advertised separately from the
  82. * unprovisioned beacon, however the unprovisioned beacon will
  83. * contain a hash of it so the two can be associated by the
  84. * provisioner.
  85. */
  86. const char *uri;
  87. /** Out of Band information field. */
  88. bt_mesh_prov_oob_info_t oob_info;
  89. /** Pointer to Public Key in big-endian for OOB public key type support.
  90. *
  91. * Remember to enable @kconfig{CONFIG_BT_MESH_PROV_OOB_PUBLIC_KEY}
  92. * when initializing this parameter.
  93. *
  94. * Must be used together with @ref bt_mesh_prov::private_key_be.
  95. */
  96. const uint8_t *public_key_be;
  97. /** Pointer to Private Key in big-endian for OOB public key type support.
  98. *
  99. * Remember to enable @kconfig{CONFIG_BT_MESH_PROV_OOB_PUBLIC_KEY}
  100. * when initializing this parameter.
  101. *
  102. * Must be used together with @ref bt_mesh_prov::public_key_be.
  103. */
  104. const uint8_t *private_key_be;
  105. /** Static OOB value */
  106. const uint8_t *static_val;
  107. /** Static OOB value length */
  108. uint8_t static_val_len;
  109. /** Maximum size of Output OOB supported */
  110. uint8_t output_size;
  111. /** Supported Output OOB Actions */
  112. uint16_t output_actions;
  113. /** Maximum size of Input OOB supported */
  114. uint8_t input_size;
  115. /** Supported Input OOB Actions */
  116. uint16_t input_actions;
  117. /** @brief Provisioning Capabilities.
  118. *
  119. * This callback notifies the application that the provisioning capabilities
  120. * of the unprovisioned device has been received.
  121. *
  122. * The application can consequently call bt_mesh_auth_method_set_<*> to
  123. * select suitable provisioning oob authentication method.
  124. *
  125. * When this callback returns, the provisioner will start authentication with
  126. * the chosen method.
  127. *
  128. * @param cap capabilities supported by device.
  129. */
  130. void (*capabilities)(const struct bt_mesh_dev_capabilities *cap);
  131. /** @brief Output of a number is requested.
  132. *
  133. * This callback notifies the application that it should
  134. * output the given number using the given action.
  135. *
  136. * @param act Action for outputting the number.
  137. * @param num Number to be outputted.
  138. *
  139. * @return Zero on success or negative error code otherwise
  140. */
  141. int (*output_number)(bt_mesh_output_action_t act, uint32_t num);
  142. /** @brief Output of a string is requested.
  143. *
  144. * This callback notifies the application that it should
  145. * display the given string to the user.
  146. *
  147. * @param str String to be displayed.
  148. *
  149. * @return Zero on success or negative error code otherwise
  150. */
  151. int (*output_string)(const char *str);
  152. /** @brief Input is requested.
  153. *
  154. * This callback notifies the application that it should
  155. * request input from the user using the given action. The
  156. * requested input will either be a string or a number, and
  157. * the application needs to consequently call the
  158. * bt_mesh_input_string() or bt_mesh_input_number() functions
  159. * once the data has been acquired from the user.
  160. *
  161. * @param act Action for inputting data.
  162. * @param num Maximum size of the inputted data.
  163. *
  164. * @return Zero on success or negative error code otherwise
  165. */
  166. int (*input)(bt_mesh_input_action_t act, uint8_t size);
  167. /** @brief The other device finished their OOB input.
  168. *
  169. * This callback notifies the application that it should stop
  170. * displaying its output OOB value, as the other party finished their
  171. * OOB input.
  172. */
  173. void (*input_complete)(void);
  174. /** @brief Unprovisioned beacon has been received.
  175. *
  176. * This callback notifies the application that an unprovisioned
  177. * beacon has been received.
  178. *
  179. * @param uuid UUID
  180. * @param oob_info OOB Information
  181. * @param uri_hash Pointer to URI Hash value. NULL if no hash was
  182. * present in the beacon.
  183. */
  184. void (*unprovisioned_beacon)(uint8_t uuid[16],
  185. bt_mesh_prov_oob_info_t oob_info,
  186. uint32_t *uri_hash);
  187. /** @brief Provisioning link has been opened.
  188. *
  189. * This callback notifies the application that a provisioning
  190. * link has been opened on the given provisioning bearer.
  191. *
  192. * @param bearer Provisioning bearer.
  193. */
  194. void (*link_open)(bt_mesh_prov_bearer_t bearer);
  195. /** @brief Provisioning link has been closed.
  196. *
  197. * This callback notifies the application that a provisioning
  198. * link has been closed on the given provisioning bearer.
  199. *
  200. * @param bearer Provisioning bearer.
  201. */
  202. void (*link_close)(bt_mesh_prov_bearer_t bearer);
  203. /** @brief Provisioning is complete.
  204. *
  205. * This callback notifies the application that provisioning has
  206. * been successfully completed, and that the local node has been
  207. * assigned the specified NetKeyIndex and primary element address.
  208. *
  209. * @param net_idx NetKeyIndex given during provisioning.
  210. * @param addr Primary element address.
  211. */
  212. void (*complete)(uint16_t net_idx, uint16_t addr);
  213. /** @brief A new node has been added to the provisioning database.
  214. *
  215. * This callback notifies the application that provisioning has
  216. * been successfully completed, and that a node has been assigned
  217. * the specified NetKeyIndex and primary element address.
  218. *
  219. * @param net_idx NetKeyIndex given during provisioning.
  220. * @param uuid UUID of the added node
  221. * @param addr Primary element address.
  222. * @param num_elem Number of elements that this node has.
  223. */
  224. void (*node_added)(uint16_t net_idx, uint8_t uuid[16], uint16_t addr,
  225. uint8_t num_elem);
  226. /** @brief Node has been reset.
  227. *
  228. * This callback notifies the application that the local node
  229. * has been reset and needs to be reprovisioned. The node will
  230. * not automatically advertise as unprovisioned, rather the
  231. * bt_mesh_prov_enable() API needs to be called to enable
  232. * unprovisioned advertising on one or more provisioning bearers.
  233. */
  234. void (*reset)(void);
  235. };
  236. /** @brief Provide provisioning input OOB string.
  237. *
  238. * This is intended to be called after the bt_mesh_prov input callback
  239. * has been called with BT_MESH_ENTER_STRING as the action.
  240. *
  241. * @param str String.
  242. *
  243. * @return Zero on success or (negative) error code otherwise.
  244. */
  245. int bt_mesh_input_string(const char *str);
  246. /** @brief Provide provisioning input OOB number.
  247. *
  248. * This is intended to be called after the bt_mesh_prov input callback
  249. * has been called with BT_MESH_ENTER_NUMBER as the action.
  250. *
  251. * @param num Number.
  252. *
  253. * @return Zero on success or (negative) error code otherwise.
  254. */
  255. int bt_mesh_input_number(uint32_t num);
  256. /** @brief Provide Device public key.
  257. *
  258. * @param public_key Device public key in big-endian.
  259. *
  260. * @return Zero on success or (negative) error code otherwise.
  261. */
  262. int bt_mesh_prov_remote_pub_key_set(const uint8_t public_key[64]);
  263. /** @brief Use Input OOB authentication.
  264. *
  265. * Provisioner only.
  266. *
  267. * Instruct the unprovisioned device to use the specified Input OOB
  268. * authentication action. When using @ref BT_MESH_PUSH, @ref BT_MESH_TWIST or
  269. * @ref BT_MESH_ENTER_NUMBER, the @ref bt_mesh_prov::output_number callback is
  270. * called with a random number that has to be entered on the unprovisioned
  271. * device.
  272. *
  273. * When using @ref BT_MESH_ENTER_STRING, the @ref bt_mesh_prov::output_string
  274. * callback is called with a random string that has to be entered on the
  275. * unprovisioned device.
  276. *
  277. * @param action Authentication action used by the unprovisioned device.
  278. * @param size Authentication size.
  279. *
  280. * @return Zero on success or (negative) error code otherwise.
  281. */
  282. int bt_mesh_auth_method_set_input(bt_mesh_input_action_t action, uint8_t size);
  283. /** @brief Use Output OOB authentication.
  284. *
  285. * Provisioner only.
  286. *
  287. * Instruct the unprovisioned device to use the specified Output OOB
  288. * authentication action. The @ref bt_mesh_prov::input callback will
  289. * be called.
  290. *
  291. * When using @ref BT_MESH_BLINK, @ref BT_MESH_BEEP, @ref BT_MESH_VIBRATE
  292. * or @ref BT_MESH_DISPLAY_NUMBER, and the application has to call
  293. * @ref bt_mesh_input_number with the random number indicated by
  294. * the unprovisioned device.
  295. *
  296. * When using @ref BT_MESH_DISPLAY_STRING, the application has to call
  297. * @ref bt_mesh_input_string with the random string displayed by the
  298. * unprovisioned device.
  299. *
  300. * @param action Authentication action used by the unprovisioned device.
  301. * @param size Authentication size.
  302. *
  303. * @return Zero on success or (negative) error code otherwise.
  304. */
  305. int bt_mesh_auth_method_set_output(bt_mesh_output_action_t action, uint8_t size);
  306. /** @brief Use static OOB authentication.
  307. *
  308. * Provisioner only.
  309. *
  310. * Instruct the unprovisioned device to use static OOB authentication, and use
  311. * the given static authentication value when provisioning.
  312. *
  313. * @param static_val Static OOB value.
  314. * @param size Static OOB value size.
  315. *
  316. * @return Zero on success or (negative) error code otherwise.
  317. */
  318. int bt_mesh_auth_method_set_static(const uint8_t *static_val, uint8_t size);
  319. /** @brief Don't use OOB authentication.
  320. *
  321. * Provisioner only.
  322. *
  323. * Don't use any authentication when provisioning new devices. This is the
  324. * default behavior.
  325. *
  326. * @warning Not using any authentication exposes the mesh network to
  327. * impersonation attacks, where attackers can pretend to be the
  328. * unprovisioned device to gain access to the network. Authentication
  329. * is strongly encouraged.
  330. *
  331. * @return Zero on success or (negative) error code otherwise.
  332. */
  333. int bt_mesh_auth_method_set_none(void);
  334. /** @brief Enable specific provisioning bearers
  335. *
  336. * Enable one or more provisioning bearers.
  337. *
  338. * @param bearers Bit-wise or of provisioning bearers.
  339. *
  340. * @return Zero on success or (negative) error code otherwise.
  341. */
  342. int bt_mesh_prov_enable(bt_mesh_prov_bearer_t bearers);
  343. /** @brief Disable specific provisioning bearers
  344. *
  345. * Disable one or more provisioning bearers.
  346. *
  347. * @param bearers Bit-wise or of provisioning bearers.
  348. *
  349. * @return Zero on success or (negative) error code otherwise.
  350. */
  351. int bt_mesh_prov_disable(bt_mesh_prov_bearer_t bearers);
  352. /** @brief Provision the local Mesh Node.
  353. *
  354. * This API should normally not be used directly by the application. The
  355. * only exception is for testing purposes where manual provisioning is
  356. * desired without an actual external provisioner.
  357. *
  358. * @param net_key Network Key
  359. * @param net_idx Network Key Index
  360. * @param flags Provisioning Flags
  361. * @param iv_index IV Index
  362. * @param addr Primary element address
  363. * @param dev_key Device Key
  364. *
  365. * @return Zero on success or (negative) error code otherwise.
  366. */
  367. int bt_mesh_provision(const uint8_t net_key[16], uint16_t net_idx,
  368. uint8_t flags, uint32_t iv_index, uint16_t addr,
  369. const uint8_t dev_key[16]);
  370. /** @brief Provision a Mesh Node using PB-ADV
  371. *
  372. * @param uuid UUID
  373. * @param net_idx Network Key Index
  374. * @param addr Address to assign to remote device. If addr is 0,
  375. * the lowest available address will be chosen.
  376. * @param attention_duration The attention duration to be send to remote device
  377. *
  378. * @return Zero on success or (negative) error code otherwise.
  379. */
  380. int bt_mesh_provision_adv(const uint8_t uuid[16], uint16_t net_idx, uint16_t addr,
  381. uint8_t attention_duration);
  382. /** @brief Check if the local node has been provisioned.
  383. *
  384. * This API can be used to check if the local node has been provisioned
  385. * or not. It can e.g. be helpful to determine if there was a stored
  386. * network in flash, i.e. if the network was restored after calling
  387. * settings_load().
  388. *
  389. * @return True if the node is provisioned. False otherwise.
  390. */
  391. bool bt_mesh_is_provisioned(void);
  392. /**
  393. * @}
  394. */
  395. /**
  396. * @brief Bluetooth mesh
  397. * @defgroup bt_mesh Bluetooth mesh
  398. * @ingroup bluetooth
  399. * @{
  400. */
  401. /* Primary Network Key index */
  402. #define BT_MESH_NET_PRIMARY 0x000
  403. /** Relay feature */
  404. #define BT_MESH_FEAT_RELAY BIT(0)
  405. /** GATT Proxy feature */
  406. #define BT_MESH_FEAT_PROXY BIT(1)
  407. /** Friend feature */
  408. #define BT_MESH_FEAT_FRIEND BIT(2)
  409. /** Low Power Node feature */
  410. #define BT_MESH_FEAT_LOW_POWER BIT(3)
  411. #define BT_MESH_FEAT_SUPPORTED (BT_MESH_FEAT_RELAY | \
  412. BT_MESH_FEAT_PROXY | \
  413. BT_MESH_FEAT_FRIEND | \
  414. BT_MESH_FEAT_LOW_POWER)
  415. /** @brief Initialize Mesh support
  416. *
  417. * After calling this API, the node will not automatically advertise as
  418. * unprovisioned, rather the bt_mesh_prov_enable() API needs to be called
  419. * to enable unprovisioned advertising on one or more provisioning bearers.
  420. *
  421. * @param prov Node provisioning information.
  422. * @param comp Node Composition.
  423. *
  424. * @return Zero on success or (negative) error code otherwise.
  425. */
  426. int bt_mesh_init(const struct bt_mesh_prov *prov,
  427. const struct bt_mesh_comp *comp);
  428. /** @brief Reset the state of the local Mesh node.
  429. *
  430. * Resets the state of the node, which means that it needs to be
  431. * reprovisioned to become an active node in a Mesh network again.
  432. *
  433. * After calling this API, the node will not automatically advertise as
  434. * unprovisioned, rather the bt_mesh_prov_enable() API needs to be called
  435. * to enable unprovisioned advertising on one or more provisioning bearers.
  436. *
  437. */
  438. void bt_mesh_reset(void);
  439. /** @brief Suspend the Mesh network temporarily.
  440. *
  441. * This API can be used for power saving purposes, but the user should be
  442. * aware that leaving the local node suspended for a long period of time
  443. * may cause it to become permanently disconnected from the Mesh network.
  444. * If at all possible, the Friendship feature should be used instead, to
  445. * make the node into a Low Power Node.
  446. *
  447. * @return 0 on success, or (negative) error code on failure.
  448. */
  449. int bt_mesh_suspend(void);
  450. /** @brief Resume a suspended Mesh network.
  451. *
  452. * This API resumes the local node, after it has been suspended using the
  453. * bt_mesh_suspend() API.
  454. *
  455. * @return 0 on success, or (negative) error code on failure.
  456. */
  457. int bt_mesh_resume(void);
  458. /** @brief Toggle the IV Update test mode
  459. *
  460. * This API is only available if the IV Update test mode has been enabled
  461. * in Kconfig. It is needed for passing most of the IV Update qualification
  462. * test cases.
  463. *
  464. * @param enable true to enable IV Update test mode, false to disable it.
  465. */
  466. void bt_mesh_iv_update_test(bool enable);
  467. /** @brief Toggle the IV Update state
  468. *
  469. * This API is only available if the IV Update test mode has been enabled
  470. * in Kconfig. It is needed for passing most of the IV Update qualification
  471. * test cases.
  472. *
  473. * @return true if IV Update In Progress state was entered, false otherwise.
  474. */
  475. bool bt_mesh_iv_update(void);
  476. /** @brief Toggle the Low Power feature of the local device
  477. *
  478. * Enables or disables the Low Power feature of the local device. This is
  479. * exposed as a run-time feature, since the device might want to change
  480. * this e.g. based on being plugged into a stable power source or running
  481. * from a battery power source.
  482. *
  483. * @param enable true to enable LPN functionality, false to disable it.
  484. *
  485. * @return Zero on success or (negative) error code otherwise.
  486. */
  487. int bt_mesh_lpn_set(bool enable);
  488. /** @brief Send out a Friend Poll message.
  489. *
  490. * Send a Friend Poll message to the Friend of this node. If there is no
  491. * established Friendship the function will return an error.
  492. *
  493. * @return Zero on success or (negative) error code otherwise.
  494. */
  495. int bt_mesh_lpn_poll(void);
  496. /** Low Power Node callback functions. */
  497. struct bt_mesh_lpn_cb {
  498. /** @brief Friendship established.
  499. *
  500. * This callback notifies the application that friendship has
  501. * been successfully established.
  502. *
  503. * @param net_idx NetKeyIndex used during friendship establishment.
  504. * @param friend_addr Friend address.
  505. * @param queue_size Friend queue size.
  506. * @param recv_window Low Power Node's listens duration for
  507. * Friend response.
  508. */
  509. void (*established)(uint16_t net_idx, uint16_t friend_addr,
  510. uint8_t queue_size, uint8_t recv_window);
  511. /** @brief Friendship terminated.
  512. *
  513. * This callback notifies the application that friendship has
  514. * been terminated.
  515. *
  516. * @param net_idx NetKeyIndex used during friendship establishment.
  517. * @param friend_addr Friend address.
  518. */
  519. void (*terminated)(uint16_t net_idx, uint16_t friend_addr);
  520. /** @brief Local Poll Request.
  521. *
  522. * This callback notifies the application that the local node has
  523. * polled the friend node.
  524. *
  525. * This callback will be called before @ref bt_mesh_lpn_cb::established
  526. * when attempting to establish a friendship.
  527. *
  528. * @param net_idx NetKeyIndex used during friendship establishment.
  529. * @param friend_addr Friend address.
  530. * @param retry Retry or first poll request for each transaction.
  531. */
  532. void (*polled)(uint16_t net_idx, uint16_t friend_addr, bool retry);
  533. };
  534. /** @def BT_MESH_LPN_CB_DEFINE
  535. *
  536. * @brief Register a callback structure for Friendship events.
  537. *
  538. * @param _name Name of callback structure.
  539. */
  540. #define BT_MESH_LPN_CB_DEFINE(_name) \
  541. static const STRUCT_SECTION_ITERABLE(bt_mesh_lpn_cb, \
  542. _CONCAT(bt_mesh_lpn_cb_, \
  543. _name))
  544. /** Friend Node callback functions. */
  545. struct bt_mesh_friend_cb {
  546. /** @brief Friendship established.
  547. *
  548. * This callback notifies the application that friendship has
  549. * been successfully established.
  550. *
  551. * @param net_idx NetKeyIndex used during friendship establishment.
  552. * @param lpn_addr Low Power Node address.
  553. * @param recv_delay Receive Delay in units of 1 millisecond.
  554. * @param polltimeout PollTimeout in units of 1 millisecond.
  555. */
  556. void (*established)(uint16_t net_idx, uint16_t lpn_addr,
  557. uint8_t recv_delay, uint32_t polltimeout);
  558. /** @brief Friendship terminated.
  559. *
  560. * This callback notifies the application that friendship has
  561. * been terminated.
  562. *
  563. * @param net_idx NetKeyIndex used during friendship establishment.
  564. * @param lpn_addr Low Power Node address.
  565. */
  566. void (*terminated)(uint16_t net_idx, uint16_t lpn_addr);
  567. /** @brief Friend Poll Request.
  568. *
  569. * This callback notifies the application that the low power node has
  570. * polled the friend node.
  571. *
  572. * This callback will be called before @ref bt_mesh_friend_cb::established
  573. * when attempting to establish a friendship.
  574. *
  575. * @param net_idx NetKeyIndex used during friendship establishment.
  576. * @param lpn_addr LPN address.
  577. */
  578. void (*polled)(uint16_t net_idx, uint16_t lpn_addr);
  579. };
  580. /** @def BT_MESH_FRIEND_CB_DEFINE
  581. *
  582. * @brief Register a callback structure for Friendship events.
  583. *
  584. * Registers a callback structure that will be called whenever Friendship
  585. * gets established or terminated.
  586. *
  587. * @param _name Name of callback structure.
  588. */
  589. #define BT_MESH_FRIEND_CB_DEFINE(_name) \
  590. static const STRUCT_SECTION_ITERABLE(bt_mesh_friend_cb, \
  591. _CONCAT(bt_mesh_friend_cb_, \
  592. _name))
  593. /** @brief Terminate Friendship.
  594. *
  595. * Terminated Friendship for given LPN.
  596. *
  597. * @param lpn_addr Low Power Node address.
  598. *
  599. * @return Zero on success or (negative) error code otherwise.
  600. */
  601. int bt_mesh_friend_terminate(uint16_t lpn_addr);
  602. /** @brief Store pending RPL entry(ies) in the persistent storage.
  603. *
  604. * This API allows the user to store pending RPL entry(ies) in the persistent
  605. * storage without waiting for the timeout.
  606. *
  607. * @note When flash is used as the persistent storage, calling this API too
  608. * frequently may wear it out.
  609. *
  610. * @param addr Address of the node which RPL entry needs to be stored or
  611. * @ref BT_MESH_ADDR_ALL_NODES to store all pending RPL entries.
  612. */
  613. void bt_mesh_rpl_pending_store(uint16_t addr);
  614. #ifdef __cplusplus
  615. }
  616. #endif
  617. /**
  618. * @}
  619. */
  620. #endif /* ZEPHYR_INCLUDE_BLUETOOTH_MESH_MAIN_H_ */