1 /* 2 * SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 /** @file 8 * @brief Bluetooth Mesh Generic Client Model APIs. 9 */ 10 11 #ifndef _GENERIC_CLIENT_H_ 12 #define _GENERIC_CLIENT_H_ 13 14 #include "client_common.h" 15 16 #ifdef __cplusplus 17 extern "C" { 18 #endif 19 20 /* Generic client model common structure */ 21 typedef bt_mesh_client_user_data_t bt_mesh_generic_client_t; 22 typedef bt_mesh_client_internal_data_t generic_internal_data_t; 23 24 /* Generic Client Model Callback */ 25 extern const struct bt_mesh_model_cb bt_mesh_generic_client_cb; 26 27 /* Generic OnOff Client Model Context */ 28 extern const struct bt_mesh_model_op bt_mesh_gen_onoff_cli_op[]; 29 30 /** @def BLE_MESH_MODEL_GEN_ONOFF_CLI 31 * 32 * Define a new generic onoff client model. Note that this API 33 * needs to be repeated for each element which the application 34 * wants to have a generic onoff client model on. 35 * @param cli_pub Pointer to a unique struct bt_mesh_model_pub. 36 * @param cli_data Pointer to a unique struct bt_mesh_gen_onoff_cli. 37 * 38 * @return New generic onoff client model instance. 39 */ 40 #define BLE_MESH_MODEL_GEN_ONOFF_CLI(cli_pub, cli_data) \ 41 BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_GEN_ONOFF_CLI, \ 42 bt_mesh_gen_onoff_cli_op, cli_pub, cli_data, &bt_mesh_generic_client_cb) 43 44 typedef bt_mesh_client_user_data_t bt_mesh_gen_onoff_client_t; 45 46 struct bt_mesh_gen_onoff_status { 47 bool op_en; /* Indicate whether optional parameters included */ 48 uint8_t present_onoff; /* Present value of Generic OnOff state */ 49 uint8_t target_onoff; /* Target value of Generic OnOff state (optional) */ 50 uint8_t remain_time; /* Time to complete state transition (C.1) */ 51 }; 52 53 struct bt_mesh_gen_onoff_set { 54 bool op_en; /* Indicate whether optional parameters included */ 55 uint8_t onoff; /* Target value of Generic OnOff state */ 56 uint8_t tid; /* Transaction Identifier */ 57 uint8_t trans_time; /* Time to complete state transition (optional) */ 58 uint8_t delay; /* Indicate message execution delay (C.1) */ 59 }; 60 61 /* Generic Level Client Model Context */ 62 extern const struct bt_mesh_model_op bt_mesh_gen_level_cli_op[]; 63 64 /** @def BLE_MESH_MODEL_GEN_LEVEL_CLI 65 * 66 * Define a new generic level client model. Note that this API 67 * needs to be repeated for each element which the application 68 * wants to have a generic level client model on. 69 * @param cli_pub Pointer to a unique struct bt_mesh_model_pub. 70 * @param cli_data Pointer to a unique struct bt_mesh_gen_level_cli. 71 * 72 * @return New generic level client model instance. 73 */ 74 #define BLE_MESH_MODEL_GEN_LEVEL_CLI(cli_pub, cli_data) \ 75 BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_GEN_LEVEL_CLI, \ 76 bt_mesh_gen_level_cli_op, cli_pub, cli_data, &bt_mesh_generic_client_cb) 77 78 typedef bt_mesh_client_user_data_t bt_mesh_gen_level_client_t; 79 80 struct bt_mesh_gen_level_status { 81 bool op_en; /* Indicate whether optional parameters included */ 82 int16_t present_level; /* Present value of Generic Level state */ 83 int16_t target_level; /* Target value of the Generic Level state (optional) */ 84 uint8_t remain_time; /* Time to complete state transition (C.1) */ 85 }; 86 87 struct bt_mesh_gen_level_set { 88 bool op_en; /* Indicate whether optional parameters included */ 89 int16_t level; /* Target value of Generic Level state */ 90 uint8_t tid; /* Transaction Identifier */ 91 uint8_t trans_time; /* Time to complete state transition (optional) */ 92 uint8_t delay; /* Indicate message execution delay (C.1) */ 93 }; 94 95 struct bt_mesh_gen_delta_set { 96 bool op_en; /* Indicate whether optional parameters included */ 97 int32_t delta_level; /* Delta change of Generic Level state */ 98 uint8_t tid; /* Transaction Identifier */ 99 uint8_t trans_time; /* Time to complete state transition (optional) */ 100 uint8_t delay; /* Indicate message execution delay (C.1) */ 101 }; 102 103 struct bt_mesh_gen_move_set { 104 bool op_en; /* Indicate whether optional parameters included */ 105 int16_t delta_level; /* Delta Level step to calculate Move speed for Generic Level state */ 106 uint8_t tid; /* Transaction Identifier */ 107 uint8_t trans_time; /* Time to complete state transition (optional) */ 108 uint8_t delay; /* Indicate message execution delay (C.1) */ 109 }; 110 111 /* Generic Default Transition Time Client Model Context */ 112 extern const struct bt_mesh_model_op bt_mesh_gen_def_trans_time_cli_op[]; 113 114 /** @def BLE_MESH_MODEL_GEN_DEF_TRANS_TIME_CLI 115 * 116 * Define a new generic default transition time client model. Note 117 * that this API needs to be repeated for each element that the 118 * application wants to have a generic default transition client 119 * model on. 120 * @param cli_pub Pointer to a unique struct bt_mesh_model_pub. 121 * @param cli_data Pointer to a unique struct bt_mesh_gen_def_trans_time_cli. 122 * 123 * @return New generic default transition time client model instance. 124 */ 125 #define BLE_MESH_MODEL_GEN_DEF_TRANS_TIME_CLI(cli_pub, cli_data) \ 126 BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_CLI, \ 127 bt_mesh_gen_def_trans_time_cli_op, cli_pub, cli_data, &bt_mesh_generic_client_cb) 128 129 typedef bt_mesh_client_user_data_t bt_mesh_gen_def_trans_time_client_t; 130 131 struct bt_mesh_gen_def_trans_time_set { 132 uint8_t trans_time; /* The value of the Generic Default Transition Time state */ 133 }; 134 135 struct bt_mesh_gen_def_trans_time_status { 136 uint8_t trans_time; /* The value of the Generic Default Transition Time state */ 137 }; 138 139 /* Generic Power OnOff Client Model Context */ 140 extern const struct bt_mesh_model_op bt_mesh_gen_power_onoff_cli_op[]; 141 142 /** @def BLE_MESH_MODEL_GEN_POWER_ONOFF_CLI 143 * 144 * Define a new generic power onoff client model. Note that this API 145 * needs to be repeated for each element which the application wants 146 * to have a generic power onoff client model on. 147 * @param cli_pub Pointer to a unique struct bt_mesh_model_pub. 148 * @param cli_data Pointer to a unique struct bt_mesh_gen_power_onoff_cli. 149 * 150 * @return New generic power onoff client model instance. 151 */ 152 #define BLE_MESH_MODEL_GEN_POWER_ONOFF_CLI(cli_pub, cli_data) \ 153 BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI, \ 154 bt_mesh_gen_power_onoff_cli_op, cli_pub, cli_data, &bt_mesh_generic_client_cb) 155 156 typedef bt_mesh_client_user_data_t bt_mesh_gen_power_onoff_client_t; 157 158 struct bt_mesh_gen_onpowerup_set { 159 uint8_t onpowerup; /* The value of the Generic OnPowerUp state */ 160 }; 161 162 struct bt_mesh_gen_onpowerup_status { 163 uint8_t onpowerup; /* The value of the Generic OnPowerUp state */ 164 }; 165 166 /* Generic Power Level Client Model Context */ 167 extern const struct bt_mesh_model_op bt_mesh_gen_power_level_cli_op[]; 168 169 /** @def BLE_MESH_MODEL_GEN_POWER_LEVEL_CLI 170 * 171 * Define a new generic power level client model. Note that this API 172 * needs to be repeated for each element which the application wants 173 * to have a generic power level client model on. 174 * @param cli_pub Pointer to a unique struct bt_mesh_model_pub. 175 * @param cli_data Pointer to a unique struct bt_mesh_gen_power_level_cli. 176 * 177 * @return New generic power level client model instance. 178 */ 179 #define BLE_MESH_MODEL_GEN_POWER_LEVEL_CLI(cli_pub, cli_data) \ 180 BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_CLI, \ 181 bt_mesh_gen_power_level_cli_op, cli_pub, cli_data, &bt_mesh_generic_client_cb) 182 183 typedef bt_mesh_client_user_data_t bt_mesh_gen_power_level_client_t; 184 185 struct bt_mesh_gen_power_level_status { 186 bool op_en; /* Indicate whether optional parameters included */ 187 uint16_t present_power; /* Present value of Generic Power Actual state */ 188 uint16_t target_power; /* Target value of Generic Power Actual state (optional) */ 189 uint8_t remain_time; /* Time to complete state transition (C.1) */ 190 }; 191 192 struct bt_mesh_gen_power_last_status { 193 uint16_t power; /* The value of the Generic Power Last state */ 194 }; 195 196 struct bt_mesh_gen_power_default_status { 197 uint16_t power; /* The value of the Generic Default Last state */ 198 }; 199 200 struct bt_mesh_gen_power_range_status { 201 uint8_t status_code; /* Status Code for the requesting message */ 202 uint16_t range_min; /* Value of Range Min field of Generic Power Range state */ 203 uint16_t range_max; /* Value of Range Max field of Generic Power Range state */ 204 }; 205 206 struct bt_mesh_gen_power_level_set { 207 bool op_en; /* Indicate whether optional parameters included */ 208 uint16_t power; /* Target value of Generic Power Actual state */ 209 uint8_t tid; /* Transaction Identifier */ 210 uint8_t trans_time; /* Time to complete state transition (optional) */ 211 uint8_t delay; /* Indicate message execution delay (C.1) */ 212 }; 213 214 struct bt_mesh_gen_power_default_set { 215 uint16_t power; /* The value of the Generic Power Default state */ 216 }; 217 218 struct bt_mesh_gen_power_range_set { 219 uint16_t range_min; /* Value of Range Min field of Generic Power Range state */ 220 uint16_t range_max; /* Value of Range Max field of Generic Power Range state */ 221 }; 222 223 /* Generic Battery Client Model Context */ 224 extern const struct bt_mesh_model_op bt_mesh_gen_battery_cli_op[]; 225 226 /** @def BLE_MESH_MODEL_GEN_BATTERY_CLI 227 * 228 * Define a new generic battery client model. Note that this API 229 * needs to be repeated for each element which the application 230 * wants to have a generic battery client model on. 231 * @param cli_pub Pointer to a unique struct bt_mesh_model_pub. 232 * @param cli_data Pointer to a unique struct bt_mesh_gen_battery_cli. 233 * 234 * @return New generic battery client model instance. 235 */ 236 #define BLE_MESH_MODEL_GEN_BATTERY_CLI(cli_pub, cli_data) \ 237 BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_GEN_BATTERY_CLI, \ 238 bt_mesh_gen_battery_cli_op, cli_pub, cli_data, &bt_mesh_generic_client_cb) 239 240 typedef bt_mesh_client_user_data_t bt_mesh_gen_battery_client_t; 241 242 struct bt_mesh_gen_battery_status { 243 uint32_t battery_level : 8; /* Value of Generic Battery Level state */ 244 uint32_t time_to_discharge : 24; /* Value of Generic Battery Time to Discharge state */ 245 uint32_t time_to_charge : 24; /* Value of Generic Battery Time to Charge state */ 246 uint32_t flags : 8; /* Value of Generic Battery Flags state */ 247 }; 248 249 /* Generic Location Client Model Context */ 250 extern const struct bt_mesh_model_op bt_mesh_gen_location_cli_op[]; 251 252 /** @def BLE_MESH_MODEL_GEN_LOCATION_CLI 253 * 254 * Define a new generic location client model. Note that this API 255 * needs to be repeated for each element which the application 256 * wants to have a generic location client model on. 257 * @param cli_pub Pointer to a unique struct bt_mesh_model_pub. 258 * @param cli_data Pointer to a unique struct bt_mesh_gen_location_cli. 259 * 260 * @return New generic location client model instance. 261 */ 262 #define BLE_MESH_MODEL_GEN_LOCATION_CLI(cli_pub, cli_data) \ 263 BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_GEN_LOCATION_CLI, \ 264 bt_mesh_gen_location_cli_op, cli_pub, cli_data, &bt_mesh_generic_client_cb) 265 266 typedef bt_mesh_client_user_data_t bt_mesh_gen_location_client_t; 267 268 struct bt_mesh_gen_loc_global_status { 269 int32_t global_latitude; /* Global Coordinates (Latitude) */ 270 int32_t global_longitude; /* Global Coordinates (Longitude) */ 271 int16_t global_altitude; /* Global Altitude */ 272 }; 273 274 struct bt_mesh_gen_loc_local_status { 275 int16_t local_north; /* Local Coordinates (North) */ 276 int16_t local_east; /* Local Coordinates (East) */ 277 int16_t local_altitude; /* Local Altitude */ 278 uint8_t floor_number; /* Floor Number */ 279 uint16_t uncertainty; /* Uncertainty */ 280 }; 281 282 struct bt_mesh_gen_loc_global_set { 283 int32_t global_latitude; /* Global Coordinates (Latitude) */ 284 int32_t global_longitude; /* Global Coordinates (Longitude) */ 285 int16_t global_altitude; /* Global Altitude */ 286 }; 287 288 struct bt_mesh_gen_loc_local_set { 289 int16_t local_north; /* Local Coordinates (North) */ 290 int16_t local_east; /* Local Coordinates (East) */ 291 int16_t local_altitude; /* Local Altitude */ 292 uint8_t floor_number; /* Floor Number */ 293 uint16_t uncertainty; /* Uncertainty */ 294 }; 295 296 /* Generic Property Client Model Context */ 297 extern const struct bt_mesh_model_op bt_mesh_gen_property_cli_op[]; 298 299 /** @def BLE_MESH_MODEL_GEN_LOCATION_CLI 300 * 301 * Define a new generic location client model. Note that this API 302 * needs to be repeated for each element which the application 303 * wants to have a generic location client model on. 304 * @param cli_pub Pointer to a unique struct bt_mesh_model_pub. 305 * @param cli_data Pointer to a unique struct bt_mesh_gen_location_cli. 306 * 307 * @return New generic location client model instance. 308 */ 309 #define BLE_MESH_MODEL_GEN_PROPERTY_CLI(cli_pub, cli_data) \ 310 BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_GEN_PROP_CLI, \ 311 bt_mesh_gen_property_cli_op, cli_pub, cli_data, &bt_mesh_generic_client_cb) 312 313 typedef bt_mesh_client_user_data_t bt_mesh_gen_property_client_t; 314 315 struct bt_mesh_gen_user_properties_status { 316 struct net_buf_simple *user_property_ids; /* Buffer contains a sequence of N User Property IDs */ 317 }; 318 319 struct bt_mesh_gen_user_property_status { 320 bool op_en; /* Indicate whether optional parameters included */ 321 uint16_t user_property_id; /* Property ID identifying a Generic User Property */ 322 uint8_t user_access; /* Enumeration indicating user access (optional) */ 323 struct net_buf_simple *user_property_value; /* Raw value for the User Property (C.1) */ 324 }; 325 326 struct bt_mesh_gen_admin_properties_status { 327 struct net_buf_simple *admin_property_ids; /* Buffer contains a sequence of N Admin Property IDs */ 328 }; 329 330 struct bt_mesh_gen_admin_property_status { 331 bool op_en; /* Indicate whether optional parameters included */ 332 uint16_t admin_property_id; /* Property ID identifying a Generic Admin Property */ 333 uint8_t admin_user_access; /* Enumeration indicating user access (optional) */ 334 struct net_buf_simple *admin_property_value; /* Raw value for the Admin Property (C.1) */ 335 }; 336 337 struct bt_mesh_gen_manu_properties_status { 338 struct net_buf_simple *manu_property_ids; /* Buffer contains a sequence of N Manufacturer Property IDs */ 339 }; 340 341 struct bt_mesh_gen_manu_property_status { 342 bool op_en; /* Indicate whether optional parameters included */ 343 uint16_t manu_property_id; /* Property ID identifying a Generic Manufacturer Property */ 344 uint8_t manu_user_access; /* Enumeration indicating user access (optional) */ 345 struct net_buf_simple *manu_property_value; /* Raw value for the Manufacturer Property (C.1) */ 346 }; 347 348 struct bt_mesh_gen_client_properties_status { 349 struct net_buf_simple *client_property_ids; /* Buffer contains a sequence of N Client Property IDs */ 350 }; 351 352 struct bt_mesh_gen_user_property_get { 353 uint16_t user_property_id; /* Property ID identifying a Generic User Property */ 354 }; 355 356 struct bt_mesh_gen_user_property_set { 357 uint16_t user_property_id; /* Property ID identifying a Generic User Property */ 358 struct net_buf_simple *user_property_value; /* Raw value for the User Property */ 359 }; 360 361 struct bt_mesh_gen_admin_property_get { 362 uint16_t admin_property_id; /* Property ID identifying a Generic Admin Property */ 363 }; 364 365 struct bt_mesh_gen_admin_property_set { 366 uint16_t admin_property_id; /* Property ID identifying a Generic Admin Property */ 367 uint8_t admin_user_access; /* Enumeration indicating user access */ 368 struct net_buf_simple *admin_property_value; /* Raw value for the Admin Property */ 369 }; 370 371 struct bt_mesh_gen_manu_property_get { 372 uint16_t manu_property_id; /* Property ID identifying a Generic Manufacturer Property */ 373 }; 374 375 struct bt_mesh_gen_manu_property_set { 376 uint16_t manu_property_id; /* Property ID identifying a Generic Manufacturer Property */ 377 uint8_t manu_user_access; /* Enumeration indicating user access */ 378 }; 379 380 struct bt_mesh_gen_client_properties_get { 381 uint16_t client_property_id; /* A starting Client Property ID present within an element */ 382 }; 383 384 /** 385 * @brief This function is called to get generic states. 386 * 387 * @param[in] common: Message common information structure 388 * @param[in] get: Pointer of generic get message value 389 * 390 * @return Zero-success, other-fail 391 */ 392 int bt_mesh_generic_client_get_state(bt_mesh_client_common_param_t *common, void *get); 393 394 /** 395 * @brief This function is called to set generic states. 396 * 397 * @param[in] common: Message common information structure 398 * @param[in] set: Pointer of generic set message value 399 * 400 * @return Zero-success, other-fail 401 */ 402 int bt_mesh_generic_client_set_state(bt_mesh_client_common_param_t *common, void *set); 403 404 #ifdef __cplusplus 405 } 406 #endif 407 408 #endif /* _GENERIC_CLIENT_H_ */ 409