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 Model Common APIs. 9 */ 10 11 #ifndef _BLE_MESH_COMMON_H_ 12 #define _BLE_MESH_COMMON_H_ 13 14 #include <stddef.h> 15 #include <stdlib.h> 16 17 #include "esp_attr.h" 18 #include "esp_heap_caps.h" 19 20 #include "mesh_byteorder.h" 21 #include "mesh_ffs.h" 22 #include "mesh_trace.h" 23 #include "mesh_mutex.h" 24 #include "mesh_access.h" 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 IRAM_ATTR void *bt_mesh_malloc(size_t size); 31 32 IRAM_ATTR void *bt_mesh_calloc(size_t size); 33 34 IRAM_ATTR void bt_mesh_free(void *ptr); 35 36 /** 37 * @brief This function allocates memory to store outgoing message. 38 * 39 * @param[in] size: Length of memory allocated to store message value 40 * 41 * @return NULL-fail, pointer of a net_buf_simple structure-success 42 */ 43 struct net_buf_simple *bt_mesh_alloc_buf(uint16_t size); 44 45 /** 46 * @brief This function releases the memory allocated for the outgoing message. 47 * 48 * @param[in] buf: Pointer to the net_buf_simple structure to be freed 49 * 50 * @return none 51 */ 52 void bt_mesh_free_buf(struct net_buf_simple *buf); 53 54 /** 55 * @brief This function gets device role for stack internal use. 56 * 57 * @Note Currently Provisioner only support client models, Node supports 58 * client models and server models. Hence if srv_send is set to be 59 * TRUE, then role NODE will be returned. 60 * 61 * @param[in] model: Pointer to the model structure 62 * @param[in] srv_send: Indicate if the message is sent by a server model 63 * 64 * @return 0 - Node, 1 - Provisioner 65 */ 66 uint8_t bt_mesh_get_device_role(struct bt_mesh_model *model, bool srv_send); 67 68 int bt_mesh_rand(void *buf, size_t len); 69 70 #ifdef __cplusplus 71 } 72 #endif 73 74 #endif /* _BLE_MESH_COMMON_H_ */ 75