1 /* 2 * Copyright (c) 2024 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_INCLUDE_BLUETOOTH_MESH_BRG_CFG_CLI_H__ 8 #define ZEPHYR_INCLUDE_BLUETOOTH_MESH_BRG_CFG_CLI_H__ 9 10 #include <zephyr/bluetooth/mesh/brg_cfg.h> 11 12 #ifdef __cplusplus 13 extern "C" { 14 #endif 15 16 /** 17 * @defgroup bt_mesh_brg_cfg_cli Bridge Configuration Client Model 18 * @ingroup bt_mesh 19 * @{ 20 * @brief API for the Bluetooth Mesh Bridge Configuration Client model 21 */ 22 23 struct bt_mesh_brg_cfg_cli; 24 25 /** 26 * @brief Bridge Configuration Client model Composition Data entry. 27 * 28 * @param _cli Pointer to a @ref bt_mesh_brg_cfg_cli instance. 29 */ 30 #define BT_MESH_MODEL_BRG_CFG_CLI(_cli) \ 31 BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_BRG_CFG_CLI, _bt_mesh_brg_cfg_cli_op, NULL, _cli, \ 32 &_bt_mesh_brg_cfg_cli_cb) 33 34 /** Mesh Bridge Configuration Client Status messages callback */ 35 struct bt_mesh_brg_cfg_cli_cb { 36 /** @brief Optional callback for Subnet Bridge Status message. 37 * 38 * Handles received Subnet Bridge Status messages from a Bridge 39 * Configuration Server. 40 41 * @param cli Bridge Configuration Client context. 42 * @param addr Address of the sender. 43 * @param status Status received from the server. 44 */ 45 void (*bridge_status)(struct bt_mesh_brg_cfg_cli *cli, uint16_t addr, 46 enum bt_mesh_brg_cfg_state status); 47 48 /** @brief Optional callback for Bridging Table Size Status message. 49 * 50 * Handles received Bridging Table Size Status messages from a Bridge 51 * Configuration Server. 52 * 53 * @param cli Bridge Configuration Client context. 54 * @param addr Address of the sender. 55 * @param size Size received from the server. 56 */ 57 void (*table_size_status)(struct bt_mesh_brg_cfg_cli *cli, uint16_t addr, uint16_t size); 58 59 /** @brief Optional callback for Bridging Table Status message. 60 * 61 * Handles received Bridging Table status messages from a Bridge 62 * Configuration Server. 63 * 64 * @param cli Bridge Configuration Client context. 65 * @param addr Address of the sender. 66 * @param rsp Response received from the Bridging Configuration Server. 67 */ 68 void (*table_status)(struct bt_mesh_brg_cfg_cli *cli, uint16_t addr, 69 struct bt_mesh_brg_cfg_table_status *rsp); 70 71 /** @brief Optional callback for Bridged Subnets List message. 72 * 73 * Handles received Bridged Subnets List messages from a Bridge 74 * Configuration Server. 75 * 76 * @param cli Bridge Configuration Client context. 77 * @param addr Address of the sender. 78 * @param rsp Response received from the Bridging Configuration Server. 79 */ 80 void (*subnets_list)(struct bt_mesh_brg_cfg_cli *cli, uint16_t addr, 81 struct bt_mesh_brg_cfg_subnets_list *rsp); 82 83 /** @brief Optional callback for Bridging Table List message. 84 * 85 * Handles received Bridging Table List messages from a Bridge 86 * Configuration Server. 87 * 88 * @param cli Bridge Configuration Client context. 89 * @param addr Address of the sender. 90 * @param rsp Response received from the Bridging Configuration Server. 91 */ 92 void (*table_list)(struct bt_mesh_brg_cfg_cli *cli, uint16_t addr, 93 struct bt_mesh_brg_cfg_table_list *rsp); 94 }; 95 96 /** Bridge Configuration Client Model Context */ 97 struct bt_mesh_brg_cfg_cli { 98 /** Bridge Configuration model entry pointer */ 99 const struct bt_mesh_model *model; 100 101 /** Event handler callbacks */ 102 const struct bt_mesh_brg_cfg_cli_cb *cb; 103 104 /* Internal parameters for tracking message responses. */ 105 struct bt_mesh_msg_ack_ctx ack_ctx; 106 }; 107 108 /** @brief Sends a Subnet Bridge Get message to the given destination address 109 * 110 * This function sends a Subnet Bridge Get message to the given destination 111 * address to query the value of the Subnet Bridge state of a subnet. The 112 * Subnet Bridge state indicates whether the subnet bridged feature is enabled 113 * or not. The function expects a Subnet Bridge Status message as a response 114 * from the destination node. 115 * 116 * This method can be used asynchronously by setting @p status as NULL. This 117 * way the method will not wait for response and will return immediately after 118 * sending the command. 119 * 120 * @param net_idx Network index to encrypt the message with. 121 * @param addr Target node address. 122 * @param status Status response parameter, returns one of 123 * @ref BT_MESH_BRG_CFG_DISABLED or 124 * @ref BT_MESH_BRG_CFG_ENABLED on success. 125 * 126 * @return 0 on success, or (negative) error code on failure. 127 */ 128 int bt_mesh_brg_cfg_cli_get(uint16_t net_idx, uint16_t addr, enum bt_mesh_brg_cfg_state *status); 129 130 /** @brief Sends a Subnet Bridge Set message to the given destination address 131 * with the given parameters 132 * 133 * This function sends a Subnet Bridge Set message to the given destination 134 * address with the given parameters to set the value of the Subnet Bridge 135 * state of a subnet. The Subnet Bridge state indicates whether the subnet 136 * bridge feature is enabled or not. The function expects a Subnet Bridge 137 * Status message as a response from the destination node. 138 * 139 * This method can be used asynchronously by setting @p status as NULL. This 140 * way the method will not wait for response and will return immediately after 141 * sending the command. 142 * 143 * @param net_idx Network index to encrypt the message with. 144 * @param addr Target node address. 145 * @param val Value to set the Subnet Bridge state to. Must be one of 146 * @ref BT_MESH_BRG_CFG_DISABLED or 147 * @ref BT_MESH_BRG_CFG_ENABLED. 148 * @param status Status response parameter, returns one of 149 * @ref BT_MESH_BRG_CFG_DISABLED or 150 * @ref BT_MESH_BRG_CFG_ENABLED on success. 151 * 152 * @return 0 on success, or (negative) error code on failure. 153 */ 154 int bt_mesh_brg_cfg_cli_set(uint16_t net_idx, uint16_t addr, enum bt_mesh_brg_cfg_state val, 155 enum bt_mesh_brg_cfg_state *status); 156 157 /** @brief Sends a Bridging Table Size Get message to the given destination 158 * address with the given parameters 159 * 160 * This function sends a Bridging Table Size Get message to the given 161 * destination address with the given parameters to get the size of the Bridging 162 * Table of the node. The Bridging Table size indicates the maximum number of 163 * entries that can be stored in the Bridging Table. The function expects a 164 * Bridging Table Size Status message as a response from the destination node. 165 * 166 * This method can be used asynchronously by setting @p size as NULL. This way 167 * the method will not wait for response and will return immediately after 168 * sending the command. 169 * 170 * @param net_idx Network index to encrypt the message with. 171 * @param addr Target node address. 172 * @param size Bridging Table size response parameter. 173 * 174 * @return 0 on success, or (negative) error code on failure. 175 */ 176 int bt_mesh_brg_cfg_cli_table_size_get(uint16_t net_idx, uint16_t addr, uint16_t *size); 177 178 /** @brief Sends a Bridging Table Add message to the given destination address 179 * with the given parameters 180 * 181 * This function sends a Bridging Table Add message to the given destination 182 * address with the given parameters to add an entry to the Bridging Table. The 183 * Bridging Table contains the net keys and addresses that are authorized to be 184 * bridged by the node. The function expects a Bridging Table Status message as 185 * a response from the destination node. 186 * 187 * This method can be used asynchronously by setting @p rsp as NULL. This way 188 * the method will not wait for response and will return immediately after 189 * sending the command. 190 * 191 * @param net_idx Network index to encrypt the message with. 192 * @param addr Target node address. 193 * @param entry Pointer to bridging Table entry to add. 194 * @param rsp Status response parameter 195 * 196 * @return 0 on success, or (negative) error code on failure. 197 */ 198 int bt_mesh_brg_cfg_cli_table_add(uint16_t net_idx, uint16_t addr, 199 struct bt_mesh_brg_cfg_table_entry *entry, 200 struct bt_mesh_brg_cfg_table_status *rsp); 201 202 /** @brief Sends a Bridging Table Remove message to the given destination 203 * address with the given parameters 204 * 205 * This function sends a Bridging Table Remove message to the given destination 206 * address with the given parameters to remove an entry from the Bridging 207 * Table. The Bridging Table contains the net keys and addresses that are 208 * authorized to be bridged by the node. The function expects a Bridging Table 209 * Status message as a response from the destination node. 210 * 211 * This method can be used asynchronously by setting @p rsp as NULL. This way 212 * the method will not wait for response and will return immediately after 213 * sending the command. 214 * 215 * @param net_idx Network index to encrypt the message with. 216 * @param addr Target node address. 217 * @param net_idx1 NetKey Index of the first subnet 218 * @param net_idx2 NetKey Index of the second subnet 219 * @param addr1 Address of the node in the first subnet 220 * @param addr2 Address of the node in the second subnet 221 * @param rsp Pointer to a struct storing the received response from the 222 * server, or NULL to not wait for a response. 223 * 224 * @return 0 on success, or (negative) error code on failure. 225 */ 226 int bt_mesh_brg_cfg_cli_table_remove(uint16_t net_idx, uint16_t addr, uint16_t net_idx1, 227 uint16_t net_idx2, uint16_t addr1, uint16_t addr2, 228 struct bt_mesh_brg_cfg_table_status *rsp); 229 230 /** @brief Sends a Bridged Subnets Get message to the given destination address 231 * with the given parameters 232 * 233 * This function sends a Bridged Subnets Get message to the given destination 234 * address with the given parameters to get the list of subnets that are 235 * bridged by the node. The function expects a Bridged Subnets List message as 236 * a response from the destination node. 237 * 238 * This method can be used asynchronously by setting @p rsp as NULL. This way 239 * the method will not wait for response and will return immediately after 240 * sending the command. 241 * 242 * When @c rsp is set, the user is responsible for providing a buffer for the 243 * filtered set of N pairs of NetKey Indexes in 244 * @ref bt_mesh_brg_cfg_subnets_list::list. If a buffer is not provided, the 245 * bridged subnets won't be copied. 246 247 * @param net_idx Network index to encrypt the message with. 248 * @param addr Target node address. 249 * @param filter_net_idx Filter and NetKey Index used for filtering 250 * @param start_idx Start offset to read in units of Bridging Table state entries 251 * @param rsp Pointer to a struct storing the received response 252 * from the server, or NULL to not wait for a response. 253 * 254 * @return 0 on success, or (negative) error code on failure. 255 */ 256 int bt_mesh_brg_cfg_cli_subnets_get(uint16_t net_idx, uint16_t addr, 257 struct bt_mesh_brg_cfg_filter_netkey filter_net_idx, 258 uint8_t start_idx, struct bt_mesh_brg_cfg_subnets_list *rsp); 259 260 /** @brief Sends a Bridging Table Get message to the given destination address 261 * with the given parameters 262 * 263 * This function sends a Bridging Table Get message to the given destination 264 * address with the given parameters to get the contents of the Bridging Table. 265 * The Bridging Table contains the addresses that are authorized to be bridged 266 * by the node. The function expects a Bridging Table List message as a 267 * response from the destination node. 268 * 269 * This method can be used asynchronously by setting @p rsp as NULL. This way 270 * the method will not wait for response and will return immediately after 271 * sending the command. 272 * 273 * When @c rsp is set, the user is responsible for providing a buffer for the 274 * filtered set of N pairs of NetKey Indexes in 275 * @ref bt_mesh_brg_cfg_table_list::list. If a buffer is not provided, 276 * the bridged addresses won't be copied. If a buffer size is shorter than 277 * received list, only those many entries that fit in the buffer will be copied 278 * from the list, and rest will be discarded. 279 * 280 * @param net_idx Network index to encrypt the message with. 281 * @param addr Target node address. 282 * @param net_idx1 NetKey Index of the first subnet. 283 * @param net_idx2 NetKey Index of the second subnet. 284 * @param start_idx Start offset to read in units of Bridging Table state entries. 285 * @param rsp Pointer to a struct storing the received response from the 286 * server, or NULL to not wait for a response. 287 * 288 * @return 0 on success, or (negative) error code on failure. 289 */ 290 int bt_mesh_brg_cfg_cli_table_get(uint16_t net_idx, uint16_t addr, uint16_t net_idx1, 291 uint16_t net_idx2, uint16_t start_idx, 292 struct bt_mesh_brg_cfg_table_list *rsp); 293 294 /** @brief Get the current transmission timeout value. 295 * 296 * @return The configured transmission timeout in milliseconds. 297 */ 298 int32_t bt_mesh_brg_cfg_cli_timeout_get(void); 299 300 /** @brief Set the transmission timeout value. 301 * 302 * @param timeout The new transmission timeout. 303 */ 304 void bt_mesh_brg_cfg_cli_timeout_set(int32_t timeout); 305 306 /** @cond INTERNAL_HIDDEN */ 307 extern const struct bt_mesh_model_op _bt_mesh_brg_cfg_cli_op[]; 308 extern const struct bt_mesh_model_cb _bt_mesh_brg_cfg_cli_cb; 309 /** @endcond */ 310 311 /** 312 * @} 313 */ 314 315 #ifdef __cplusplus 316 } 317 #endif 318 319 #endif /* ZEPHYR_INCLUDE_BLUETOOTH_MESH_BRG_CFG_CLI_H__ */ 320