mesh_common.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. /** @file
  14. * @brief Bluetooth Mesh Model Common APIs.
  15. */
  16. #ifndef _BLE_MESH_COMMON_H_
  17. #define _BLE_MESH_COMMON_H_
  18. #include <stddef.h>
  19. #include <stdlib.h>
  20. #include "esp_attr.h"
  21. #include "esp_heap_caps.h"
  22. #include "mesh_byteorder.h"
  23. #include "mesh_ffs.h"
  24. #include "mesh_trace.h"
  25. #include "mesh_mutex.h"
  26. #include "mesh_access.h"
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. IRAM_ATTR void *bt_mesh_malloc(size_t size);
  31. IRAM_ATTR void *bt_mesh_calloc(size_t size);
  32. IRAM_ATTR void bt_mesh_free(void *ptr);
  33. /**
  34. * @brief This function allocates memory to store outgoing message.
  35. *
  36. * @param[in] size: Length of memory allocated to store message value
  37. *
  38. * @return NULL-fail, pointer of a net_buf_simple structure-success
  39. */
  40. struct net_buf_simple *bt_mesh_alloc_buf(uint16_t size);
  41. /**
  42. * @brief This function releases the memory allocated for the outgoing message.
  43. *
  44. * @param[in] buf: Pointer to the net_buf_simple structure to be freed
  45. *
  46. * @return none
  47. */
  48. void bt_mesh_free_buf(struct net_buf_simple *buf);
  49. /**
  50. * @brief This function gets device role for stack internal use.
  51. *
  52. * @Note Currently Provisioner only support client models, Node supports
  53. * client models and server models. Hence if srv_send is set to be
  54. * TRUE, then role NODE will be returned.
  55. *
  56. * @param[in] model: Pointer to the model structure
  57. * @param[in] srv_send: Indicate if the message is sent by a server model
  58. *
  59. * @return 0 - Node, 1 - Provisioner
  60. */
  61. uint8_t bt_mesh_get_device_role(struct bt_mesh_model *model, bool srv_send);
  62. int bt_mesh_rand(void *buf, size_t len);
  63. #ifdef __cplusplus
  64. }
  65. #endif
  66. #endif /* _BLE_MESH_COMMON_H_ */