protocomm_ble.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Copyright 2018 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. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #include <protocomm.h>
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /**
  20. * BLE device name cannot be larger than this value
  21. * 31 bytes (max scan response size) - 1 byte (length) - 1 byte (type) = 29 bytes
  22. */
  23. #define MAX_BLE_DEVNAME_LEN 29
  24. #define BLE_UUID128_VAL_LENGTH 16
  25. /**
  26. * @brief This structure maps handler required by protocomm layer to
  27. * UUIDs which are used to uniquely identify BLE characteristics
  28. * from a smartphone or a similar client device.
  29. */
  30. typedef struct name_uuid {
  31. /**
  32. * Name of the handler, which is passed to protocomm layer
  33. */
  34. const char *name;
  35. /**
  36. * UUID to be assigned to the BLE characteristic which is
  37. * mapped to the handler
  38. */
  39. uint16_t uuid;
  40. } protocomm_ble_name_uuid_t;
  41. /**
  42. * @brief Config parameters for protocomm BLE service
  43. */
  44. typedef struct protocomm_ble_config {
  45. /**
  46. * BLE device name being broadcast at the time of provisioning
  47. */
  48. char device_name[MAX_BLE_DEVNAME_LEN];
  49. /**
  50. * 128 bit UUID of the provisioning service
  51. */
  52. uint8_t service_uuid[BLE_UUID128_VAL_LENGTH];
  53. /**
  54. * Number of entries in the Name-UUID lookup table
  55. */
  56. ssize_t nu_lookup_count;
  57. /**
  58. * Pointer to the Name-UUID lookup table
  59. */
  60. protocomm_ble_name_uuid_t *nu_lookup;
  61. } protocomm_ble_config_t;
  62. /**
  63. * @brief Start Bluetooth Low Energy based transport layer for provisioning
  64. *
  65. * Initialize and start required BLE service for provisioning. This includes
  66. * the initialization for characteristics/service for BLE.
  67. *
  68. * @param[in] pc Protocomm instance pointer obtained from protocomm_new()
  69. * @param[in] config Pointer to config structure for initializing BLE
  70. *
  71. * @return
  72. * - ESP_OK : Success
  73. * - ESP_FAIL : Simple BLE start error
  74. * - ESP_ERR_NO_MEM : Error allocating memory for internal resources
  75. * - ESP_ERR_INVALID_STATE : Error in ble config
  76. * - ESP_ERR_INVALID_ARG : Null arguments
  77. */
  78. esp_err_t protocomm_ble_start(protocomm_t *pc, const protocomm_ble_config_t *config);
  79. /**
  80. * @brief Stop Bluetooth Low Energy based transport layer for provisioning
  81. *
  82. * Stops service/task responsible for BLE based interactions for provisioning
  83. *
  84. * @note You might want to optionally reclaim memory from Bluetooth.
  85. * Refer to the documentation of `esp_bt_mem_release` in that case.
  86. *
  87. * @param[in] pc Same protocomm instance that was passed to protocomm_ble_start()
  88. *
  89. * @return
  90. * - ESP_OK : Success
  91. * - ESP_FAIL : Simple BLE stop error
  92. * - ESP_ERR_INVALID_ARG : Null / incorrect protocomm instance
  93. */
  94. esp_err_t protocomm_ble_stop(protocomm_t *pc);
  95. #ifdef __cplusplus
  96. }
  97. #endif