1 /* 2 * Copyright (c) 2020 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 /** Provisioning protocol timeout in seconds. */ 8 #define PROTOCOL_TIMEOUT_SEC 60 9 #define PROTOCOL_TIMEOUT_EXT_SEC 120 10 11 /** Provisioning protocol timeout. */ 12 #define PROTOCOL_TIMEOUT K_SECONDS(PROTOCOL_TIMEOUT_SEC) 13 #define PROTOCOL_TIMEOUT_EXT K_SECONDS(PROTOCOL_TIMEOUT_EXT_SEC) 14 15 /** @def PROV_BEARER_BUF_HEADROOM 16 * 17 * @brief Required headroom for the bearer packet buffers. 18 */ 19 #if defined(CONFIG_BT_MESH_PB_GATT_COMMON) 20 #define PROV_BEARER_BUF_HEADROOM 5 21 #elif defined(CONFIG_BT_MESH_RPR_CLI) || defined(CONFIG_BT_MESH_RPR_SRV) 22 #define PROV_BEARER_BUF_HEADROOM 3 23 #else 24 #define PROV_BEARER_BUF_HEADROOM 0 25 #endif 26 27 /** 28 * 29 * @brief Required tailroom for the bearer packet buffers. 30 */ 31 #if defined(CONFIG_BT_MESH_RPR_CLI) || defined(CONFIG_BT_MESH_RPR_SRV) 32 #define PROV_BEARER_BUF_TAILROOM 4 33 #else 34 #define PROV_BEARER_BUF_TAILROOM 0 35 #endif 36 37 enum prov_bearer_link_status { 38 PROV_BEARER_LINK_STATUS_SUCCESS, 39 PROV_BEARER_LINK_STATUS_TIMEOUT, 40 PROV_BEARER_LINK_STATUS_FAIL, 41 }; 42 43 struct prov_bearer; 44 45 /** Callbacks from bearer to host */ 46 struct prov_bearer_cb { 47 48 void (*link_opened)(const struct prov_bearer *bearer, void *cb_data); 49 50 void (*link_closed)(const struct prov_bearer *bearer, void *cb_data, 51 enum prov_bearer_link_status reason); 52 53 void (*error)(const struct prov_bearer *bearer, void *cb_data, 54 uint8_t err); 55 56 void (*recv)(const struct prov_bearer *bearer, void *cb_data, 57 struct net_buf_simple *buf); 58 }; 59 60 typedef void (*prov_bearer_send_complete_t)(int err, void *cb_data); 61 62 /** Provisioning bearer API */ 63 struct prov_bearer { 64 /** Provisioning bearer type. */ 65 bt_mesh_prov_bearer_t type; 66 67 /** @brief Enable link establishment as a provisionee. 68 * 69 * Prompts the bearer to make itself visible to provisioners, and 70 * start accepting link open messages. 71 * 72 * @param cb Bearer event callbacks used for the duration of the link. 73 * @param cb_data Context parameter to pass to the bearer callbacks. 74 * 75 * @return Zero on success, or (negative) error code otherwise. 76 */ 77 int (*link_accept)(const struct prov_bearer_cb *cb, void *cb_data); 78 79 /** @brief Disable link establishment as a provisionee. 80 * 81 * Stops accepting link open messages and sending unprovisioned beacons. 82 */ 83 void (*link_cancel)(void); 84 85 /** @brief Send a packet on an established link. 86 * 87 * @param buf Payload buffer. Requires @ref 88 * PROV_BEARER_BUF_HEADROOM bytes of headroom. 89 * @param cb Callback to call when sending is complete. 90 * @param cb_data Callback data. 91 * 92 * @return Zero on success, or (negative) error code otherwise. 93 */ 94 int (*send)(struct net_buf_simple *buf, prov_bearer_send_complete_t cb, 95 void *cb_data); 96 97 /** @brief Clear any ongoing transmissions, if possible. 98 * 99 * Bearers that don't support tx clearing must implement this callback 100 * and leave it empty. 101 */ 102 void (*clear_tx)(void); 103 104 /* Only available in provisioners: */ 105 106 /** @brief Open a new link as a provisioner. 107 * 108 * Only available in provisioners. Bearers that don't support the 109 * provisioner role should leave this as NULL. 110 * 111 * @param uuid UUID of the node to establish a link to. 112 * @param timeout Link open timeout in seconds. 113 * @param cb Bearer event callbacks used for the duration of the link. 114 * @param cb_data Context parameter to pass to the bearer callbacks. 115 * 116 * @return Zero on success, or (negative) error code otherwise. 117 */ 118 int (*link_open)(const uint8_t uuid[16], uint8_t timeout, 119 const struct prov_bearer_cb *cb, void *cb_data); 120 121 /** @brief Close the current link. 122 * 123 * Only available in provisioners. Bearers that don't support the 124 * provisioner role should leave this as NULL. 125 * 126 * @param status Link status for the link close message. 127 */ 128 void (*link_close)(enum prov_bearer_link_status status); 129 }; 130 131 struct pb_remote_ctx { 132 struct bt_mesh_rpr_cli *cli; 133 const struct bt_mesh_rpr_node *srv; 134 enum bt_mesh_rpr_node_refresh refresh; 135 }; 136 137 extern const struct prov_bearer bt_mesh_pb_adv; 138 extern const struct prov_bearer bt_mesh_pb_gatt; 139 extern const struct prov_bearer pb_remote_cli; 140 extern const struct prov_bearer pb_remote_srv; 141 142 void bt_mesh_pb_adv_init(void); 143 void bt_mesh_pb_gatt_init(void); 144 145 void bt_mesh_pb_adv_reset(void); 146 void bt_mesh_pb_gatt_reset(void); 147