adv.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* Bluetooth Mesh */
  2. /*
  3. * SPDX-FileCopyrightText: 2017 Intel Corporation
  4. * SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
  5. *
  6. * SPDX-License-Identifier: Apache-2.0
  7. */
  8. #ifndef _ADV_H_
  9. #define _ADV_H_
  10. #include "mesh/access.h"
  11. #include "mesh/adapter.h"
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. /* Maximum advertising data payload for a single data type */
  16. #define BLE_MESH_ADV_DATA_SIZE 29
  17. /* The user data is a pointer (4 bytes) to struct bt_mesh_adv */
  18. #define BLE_MESH_ADV_USER_DATA_SIZE 4
  19. #define BLE_MESH_ADV(buf) (*(struct bt_mesh_adv **)net_buf_user_data(buf))
  20. uint16_t bt_mesh_pdu_duration(uint8_t xmit);
  21. typedef struct bt_mesh_msg {
  22. bool relay; /* Flag indicates if the packet is a relayed one */
  23. void *arg; /* Pointer to the struct net_buf */
  24. uint16_t src; /* Source address for relay packets */
  25. uint16_t dst; /* Destination address for relay packets */
  26. uint32_t timestamp; /* Timestamp recorded when the relay packet is posted to queue */
  27. } bt_mesh_msg_t;
  28. enum bt_mesh_adv_type {
  29. BLE_MESH_ADV_PROV,
  30. BLE_MESH_ADV_DATA,
  31. BLE_MESH_ADV_BEACON,
  32. BLE_MESH_ADV_URI,
  33. BLE_MESH_ADV_BLE,
  34. BLE_MESH_ADV_PROXY_SOLIC,
  35. };
  36. struct bt_mesh_adv {
  37. const struct bt_mesh_send_cb *cb;
  38. void *cb_data;
  39. uint8_t type:3,
  40. busy:1;
  41. uint8_t xmit;
  42. };
  43. typedef struct bt_mesh_adv *(*bt_mesh_adv_alloc_t)(int id);
  44. struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, int32_t timeout);
  45. typedef enum {
  46. BLE_MESH_BUF_REF_EQUAL,
  47. BLE_MESH_BUF_REF_SMALL,
  48. BLE_MESH_BUF_REF_MAX,
  49. } bt_mesh_buf_ref_flag_t;
  50. void bt_mesh_adv_buf_ref_debug(const char *func, struct net_buf *buf,
  51. uint8_t ref_cmp, bt_mesh_buf_ref_flag_t flag);
  52. struct net_buf *bt_mesh_adv_create_from_pool(struct net_buf_pool *pool,
  53. bt_mesh_adv_alloc_t get_id,
  54. enum bt_mesh_adv_type type,
  55. int32_t timeout);
  56. void bt_mesh_unref_buf_from_pool(struct net_buf_pool *pool);
  57. void bt_mesh_adv_send(struct net_buf *buf, uint8_t xmit,
  58. const struct bt_mesh_send_cb *cb,
  59. void *cb_data);
  60. struct net_buf *bt_mesh_relay_adv_create(enum bt_mesh_adv_type type, int32_t timeout);
  61. void bt_mesh_relay_adv_send(struct net_buf *buf, uint8_t xmit,
  62. uint16_t src, uint16_t dst,
  63. const struct bt_mesh_send_cb *cb,
  64. void *cb_data);
  65. uint16_t bt_mesh_get_stored_relay_count(void);
  66. void bt_mesh_adv_update(void);
  67. void bt_mesh_adv_init(void);
  68. void bt_mesh_adv_deinit(void);
  69. #if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
  70. int bt_mesh_start_ble_advertising(const struct bt_mesh_ble_adv_param *param,
  71. const struct bt_mesh_ble_adv_data *data, uint8_t *index);
  72. int bt_mesh_stop_ble_advertising(uint8_t index);
  73. #endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */
  74. #ifdef __cplusplus
  75. }
  76. #endif
  77. #endif /* _ADV_H_ */