|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#pragma once |
| 8 | + |
| 9 | +#include <stdbool.h> |
| 10 | +#include <stdint.h> |
| 11 | + |
| 12 | +#include "esp_err.h" |
| 13 | +#include "esp_event_base.h" |
| 14 | + |
| 15 | +#ifdef __cplusplus |
| 16 | +extern "C" |
| 17 | +{ |
| 18 | +#endif |
| 19 | + |
| 20 | +/** @cond **/ |
| 21 | +/* BLE UDS EVENTS BASE */ |
| 22 | +ESP_EVENT_DECLARE_BASE(BLE_UDS_EVENTS); |
| 23 | +/** @endcond **/ |
| 24 | + |
| 25 | +/* UDS Characteristic Value Length */ |
| 26 | +#define BLE_UDS_ATT_VAL_LEN 20 /*!< Attribute value length */ |
| 27 | +#define BLE_UDS_USER_CTRL_POINT_PARAM_LEN 18 /*!< User control point param length */ |
| 28 | + |
| 29 | +/* 16 Bit USER DATA Service UUID */ |
| 30 | +#define BLE_UDS_UUID16 0x181C |
| 31 | + |
| 32 | +/* 16 Bit User Data Characteristics UUIDs */ |
| 33 | +#define BLE_UDS_CHR_UUID16_DATABASH_CHG 0x2A99 |
| 34 | +#define BLE_UDS_CHR_UUID16_USER_INDEX 0x2A9A |
| 35 | +#define BLE_UDS_CHR_UUID16_USER_CTRL 0x2A9F |
| 36 | +#define BLE_UDS_CHR_UUID16_REG_USER 0x2B37 |
| 37 | + |
| 38 | +/* User Control Point characteristic OP-Code */ |
| 39 | +#define BLE_UDS_USER_CTRL_REG_NEW_OP 0x01 |
| 40 | +#define BLE_UDS_USER_CTRL_CONSENT_OP 0x02 |
| 41 | +#define BLE_UDS_USER_CTRL_DEL_DATA_OP 0x03 |
| 42 | +#define BLE_UDS_USER_CTRL_LIST_ALL_OP 0x04 |
| 43 | +#define BLE_UDS_USER_CTRL_DEL_USER_OP 0x05 |
| 44 | +#define BLE_UDS_USER_CTRL_RSP_OP 0x20 |
| 45 | + |
| 46 | +/** |
| 47 | + * @brief Database Change Increment |
| 48 | + */ |
| 49 | +typedef struct { |
| 50 | + uint8_t len; /*!< Database buffer length */ |
| 51 | + uint8_t db_buf[BLE_UDS_ATT_VAL_LEN]; /*!< Database buffer */ |
| 52 | +} esp_ble_uds_db_t; |
| 53 | + |
| 54 | +/** |
| 55 | + * @brief Register User Characteristic |
| 56 | + */ |
| 57 | +typedef struct { |
| 58 | + struct { |
| 59 | + uint8_t first_segment: 1; /*!< 0: False, 1: True */ |
| 60 | + uint8_t last_segment: 1; /*!< 0: False, 1: True */ |
| 61 | + uint8_t rolling_segment_number: 6; /*!< When the Rolling segment number is equal to 63, the value is reset to 0 the next time it is incremented */ |
| 62 | + } header; /*!< The structure of the Segmentation Header field */ |
| 63 | + |
| 64 | + struct { |
| 65 | + uint8_t user_name_present: 1; /*!< 0: False, 1: True */ |
| 66 | + uint8_t user_name_truncated: 1; /*!< 0: False, 1: True */ |
| 67 | + } flag; /*!< Defines the value of the flags field that a server shall use when the register user characteristic is indicate */ |
| 68 | + |
| 69 | + uint8_t user_index; /*!< User ID Index*/ |
| 70 | + uint8_t user_name[BLE_UDS_ATT_VAL_LEN]; /*!< User name*/ |
| 71 | +} __attribute__((packed)) esp_ble_uds_reg_user_t; |
| 72 | + |
| 73 | +/** |
| 74 | + * @brief User Control Point |
| 75 | + */ |
| 76 | +typedef struct { |
| 77 | + uint8_t op_code; /*!< User control point opcode */ |
| 78 | + uint8_t param_len; /*!< Parameter buffer length */ |
| 79 | + uint8_t parameter[BLE_UDS_USER_CTRL_POINT_PARAM_LEN]; /*!< Parameter depend on opcode */ |
| 80 | +} esp_ble_uds_user_ctrl_t; |
| 81 | + |
| 82 | +/** |
| 83 | + * @brief Read the value of Database Change Increment characteristic. |
| 84 | + * |
| 85 | + * @param[in] out_val The pointer to store the Database Change Increment. |
| 86 | + * |
| 87 | + * @return |
| 88 | + * - ESP_OK on successful |
| 89 | + * - ESP_ERR_INVALID_ARG on wrong parameter |
| 90 | + */ |
| 91 | +esp_err_t esp_ble_uds_get_db_incre(esp_ble_uds_db_t *out_val); |
| 92 | + |
| 93 | +/** |
| 94 | + * @brief Set the Database Change Increment characteristic value. |
| 95 | + * |
| 96 | + * @param[in] in_val The pointer to store the Database Change Increment Information. |
| 97 | + * |
| 98 | + * @param[in] need_send If set to true, the User Data Info will send to remote client. |
| 99 | + * |
| 100 | + * @return |
| 101 | + * - ESP_OK on successful |
| 102 | + * - ESP_ERR_INVALID_ARG on wrong initialization |
| 103 | + * - ESP_FAIL on error |
| 104 | + */ |
| 105 | +esp_err_t esp_ble_uds_set_db_incre(esp_ble_uds_db_t *in_val, bool need_send); |
| 106 | + |
| 107 | +/** |
| 108 | + * @brief Read the value of User Control characteristic. |
| 109 | + * |
| 110 | + * @param[in] out_val The pointer to store the User Control value. |
| 111 | + * |
| 112 | + * @return |
| 113 | + * - ESP_OK on successful |
| 114 | + * - ESP_ERR_INVALID_ARG on wrong parameter |
| 115 | + */ |
| 116 | +esp_err_t esp_ble_uds_get_user_ctrl(esp_ble_uds_user_ctrl_t *out_val); |
| 117 | + |
| 118 | +/** |
| 119 | + * @brief Set the User Control Point characteristic value. |
| 120 | + * |
| 121 | + * @param[in] in_val The pointer to store the User Control Value. |
| 122 | + * |
| 123 | + * @param[in] need_send If set to true, the User Control Value will send to remote client. |
| 124 | + * |
| 125 | + * @return |
| 126 | + * - ESP_OK on successful |
| 127 | + * - ESP_ERR_INVALID_ARG on wrong initialization |
| 128 | + * - ESP_FAIL on error |
| 129 | + */ |
| 130 | +esp_err_t esp_ble_uds_set_user_ctrl(esp_ble_uds_user_ctrl_t *in_val, bool need_send); |
| 131 | + |
| 132 | +/** |
| 133 | + * @brief Read the value of Register User characteristic. |
| 134 | + * |
| 135 | + * @param[in] out_val The pointer to store the Register User value. |
| 136 | + * |
| 137 | + * @return |
| 138 | + * - ESP_OK on successful |
| 139 | + * - ESP_ERR_INVALID_ARG on wrong parameter |
| 140 | + */ |
| 141 | +esp_err_t esp_ble_uds_get_reg_user(esp_ble_uds_reg_user_t *out_val); |
| 142 | + |
| 143 | +/** |
| 144 | + * @brief Set the Register User characteristic value. |
| 145 | + * |
| 146 | + * @param[in] in_val The pointer to store the Register User Value. |
| 147 | + * |
| 148 | + * @param[in] need_send If set to true, the Register User Value will send to remote client. |
| 149 | + * |
| 150 | + * @return |
| 151 | + * - ESP_OK on successful |
| 152 | + * - ESP_ERR_INVALID_ARG on wrong initialization |
| 153 | + * - ESP_FAIL on error |
| 154 | + */ |
| 155 | +esp_err_t esp_ble_uds_set_reg_user(esp_ble_uds_reg_user_t *in_val, bool need_send); |
| 156 | + |
| 157 | +/** |
| 158 | + * @brief Initialization User Data Service |
| 159 | + * |
| 160 | + * @return |
| 161 | + * - ESP_OK on successful |
| 162 | + * - ESP_ERR_INVALID_ARG on wrong initialization |
| 163 | + * - ESP_FAIL on error |
| 164 | + */ |
| 165 | +esp_err_t esp_ble_uds_init(void); |
| 166 | + |
| 167 | +#ifdef __cplusplus |
| 168 | +} |
| 169 | +#endif |
0 commit comments