1 /*
2  * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef __ESP_GAP_BLE_API_H__
8 #define __ESP_GAP_BLE_API_H__
9 
10 #include <stdint.h>
11 #include <stdbool.h>
12 
13 #include "esp_err.h"
14 #include "esp_bt_defs.h"
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 /**
21  * @brief BLE_ADV_DATA_FLAG data flag bit definition used for advertising data flag
22  */
23 #define ESP_BLE_ADV_FLAG_LIMIT_DISC         (0x01 << 0)
24 #define ESP_BLE_ADV_FLAG_GEN_DISC           (0x01 << 1)
25 #define ESP_BLE_ADV_FLAG_BREDR_NOT_SPT      (0x01 << 2)
26 #define ESP_BLE_ADV_FLAG_DMT_CONTROLLER_SPT (0x01 << 3)
27 #define ESP_BLE_ADV_FLAG_DMT_HOST_SPT       (0x01 << 4)
28 #define ESP_BLE_ADV_FLAG_NON_LIMIT_DISC     (0x00 )
29 
30 
31 /// relate to BTM_LE_KEY_xxx in stack/btm_api.h
32 #define ESP_LE_KEY_NONE                    0           /*!< No encryption key */
33 #define ESP_LE_KEY_PENC                    (1 << 0)    /*!< encryption key, encryption information of peer device */
34 #define ESP_LE_KEY_PID                     (1 << 1)    /*!< identity key of the peer device */
35 #define ESP_LE_KEY_PCSRK                   (1 << 2)    /*!< peer SRK */
36 #define ESP_LE_KEY_PLK                     (1 << 3)    /*!< Link key*/
37 #define ESP_LE_KEY_LLK                     (ESP_LE_KEY_PLK << 4)      /*!< peer link key*/
38 #define ESP_LE_KEY_LENC                    (ESP_LE_KEY_PENC << 4)     /*!< master role security information:div */
39 #define ESP_LE_KEY_LID                     (ESP_LE_KEY_PID << 4)      /*!< master device ID key */
40 #define ESP_LE_KEY_LCSRK                   (ESP_LE_KEY_PCSRK << 4)    /*!< local CSRK has been deliver to peer */
41 typedef uint8_t esp_ble_key_type_t;
42 
43 /// relate to BTM_LE_AUTH_xxx in stack/btm_api.h
44 #define ESP_LE_AUTH_NO_BOND                 0x00        /*!< 0  no bondingv*/
45 #define ESP_LE_AUTH_BOND                    0x01        /*!< 1 << 0 device in the bonding with peer */
46 #define ESP_LE_AUTH_REQ_MITM                (1 << 2)    /*!< 1 << 2 man in the middle attack */
47 #define ESP_LE_AUTH_REQ_BOND_MITM           (ESP_LE_AUTH_BOND | ESP_LE_AUTH_REQ_MITM) /*!< 0101 banding with man in the middle attack */
48 #define ESP_LE_AUTH_REQ_SC_ONLY             (1 << 3)                                  /*!< 1 << 3  secure connection */
49 #define ESP_LE_AUTH_REQ_SC_BOND             (ESP_LE_AUTH_BOND | ESP_LE_AUTH_REQ_SC_ONLY)            /*!< 1001 secure connection with band*/
50 #define ESP_LE_AUTH_REQ_SC_MITM             (ESP_LE_AUTH_REQ_MITM | ESP_LE_AUTH_REQ_SC_ONLY)        /*!< 1100 secure conn with MITM */
51 #define ESP_LE_AUTH_REQ_SC_MITM_BOND        (ESP_LE_AUTH_REQ_MITM | ESP_LE_AUTH_REQ_SC_ONLY | ESP_LE_AUTH_BOND)   /*!< 1101 SC with MITM and Bonding*/
52 typedef uint8_t   esp_ble_auth_req_t;         /*!< combination of the above bit pattern */
53 
54 #define ESP_BLE_ONLY_ACCEPT_SPECIFIED_AUTH_DISABLE 0    /*!< authentication disable*/
55 #define ESP_BLE_ONLY_ACCEPT_SPECIFIED_AUTH_ENABLE  1    /*!< authentication enable*/
56 
57 #define ESP_BLE_OOB_DISABLE 0    /*!< disbale the out of bond*/
58 #define ESP_BLE_OOB_ENABLE  1    /*!< enable the out of bond*/
59 
60 /// relate to BTM_IO_CAP_xxx in stack/btm_api.h
61 #define ESP_IO_CAP_OUT                      0   /*!< DisplayOnly */
62 #define ESP_IO_CAP_IO                       1   /*!< DisplayYesNo */
63 #define ESP_IO_CAP_IN                       2   /*!< KeyboardOnly */
64 #define ESP_IO_CAP_NONE                     3   /*!< NoInputNoOutput */
65 #define ESP_IO_CAP_KBDISP                   4   /*!< Keyboard display */
66 
67 #define ESP_BLE_APPEARANCE_UNKNOWN                 0x0000 /*!< relate to BTM_BLE_APPEARANCE_UNKNOWN in stack/btm_ble_api.h */
68 #define ESP_BLE_APPEARANCE_GENERIC_PHONE           0x0040 /*!< relate to BTM_BLE_APPEARANCE_GENERIC_PHONE in stack/btm_ble_api.h */
69 #define ESP_BLE_APPEARANCE_GENERIC_COMPUTER        0x0080 /*!< relate to BTM_BLE_APPEARANCE_GENERIC_COMPUTER in stack/btm_ble_api.h */
70 #define ESP_BLE_APPEARANCE_GENERIC_WATCH           0x00C0 /*!< relate to BTM_BLE_APPEARANCE_GENERIC_WATCH in stack/btm_ble_api.h */
71 #define ESP_BLE_APPEARANCE_SPORTS_WATCH            0x00C1 /*!< relate to BTM_BLE_APPEARANCE_SPORTS_WATCH in stack/btm_ble_api.h */
72 #define ESP_BLE_APPEARANCE_GENERIC_CLOCK           0x0100 /*!< relate to BTM_BLE_APPEARANCE_GENERIC_CLOCK in stack/btm_ble_api.h */
73 #define ESP_BLE_APPEARANCE_GENERIC_DISPLAY         0x0140 /*!< relate to BTM_BLE_APPEARANCE_GENERIC_DISPLAY in stack/btm_ble_api.h */
74 #define ESP_BLE_APPEARANCE_GENERIC_REMOTE          0x0180 /*!< relate to BTM_BLE_APPEARANCE_GENERIC_REMOTE in stack/btm_ble_api.h */
75 #define ESP_BLE_APPEARANCE_GENERIC_EYEGLASSES      0x01C0 /*!< relate to BTM_BLE_APPEARANCE_GENERIC_EYEGLASSES in stack/btm_ble_api.h */
76 #define ESP_BLE_APPEARANCE_GENERIC_TAG             0x0200 /*!< relate to BTM_BLE_APPEARANCE_GENERIC_TAG in stack/btm_ble_api.h */
77 #define ESP_BLE_APPEARANCE_GENERIC_KEYRING         0x0240 /*!< relate to BTM_BLE_APPEARANCE_GENERIC_KEYRING in stack/btm_ble_api.h */
78 #define ESP_BLE_APPEARANCE_GENERIC_MEDIA_PLAYER    0x0280 /*!< relate to BTM_BLE_APPEARANCE_GENERIC_MEDIA_PLAYER in stack/btm_ble_api.h */
79 #define ESP_BLE_APPEARANCE_GENERIC_BARCODE_SCANNER 0x02C0 /*!< relate to BTM_BLE_APPEARANCE_GENERIC_BARCODE_SCANNER in stack/btm_ble_api.h */
80 #define ESP_BLE_APPEARANCE_GENERIC_THERMOMETER     0x0300 /*!< relate to BTM_BLE_APPEARANCE_GENERIC_THERMOMETER in stack/btm_ble_api.h */
81 #define ESP_BLE_APPEARANCE_THERMOMETER_EAR         0x0301 /*!< relate to BTM_BLE_APPEARANCE_THERMOMETER_EAR in stack/btm_ble_api.h */
82 #define ESP_BLE_APPEARANCE_GENERIC_HEART_RATE      0x0340 /*!< relate to BTM_BLE_APPEARANCE_GENERIC_HEART_RATE in stack/btm_ble_api.h */
83 #define ESP_BLE_APPEARANCE_HEART_RATE_BELT         0x0341 /*!< relate to BTM_BLE_APPEARANCE_HEART_RATE_BELT in stack/btm_ble_api.h */
84 #define ESP_BLE_APPEARANCE_GENERIC_BLOOD_PRESSURE  0x0380 /*!< relate to BTM_BLE_APPEARANCE_GENERIC_BLOOD_PRESSURE in stack/btm_ble_api.h */
85 #define ESP_BLE_APPEARANCE_BLOOD_PRESSURE_ARM      0x0381 /*!< relate to BTM_BLE_APPEARANCE_BLOOD_PRESSURE_ARM in stack/btm_ble_api.h */
86 #define ESP_BLE_APPEARANCE_BLOOD_PRESSURE_WRIST    0x0382 /*!< relate to BTM_BLE_APPEARANCE_BLOOD_PRESSURE_WRIST in stack/btm_ble_api.h */
87 #define ESP_BLE_APPEARANCE_GENERIC_HID             0x03C0 /*!< relate to BTM_BLE_APPEARANCE_GENERIC_HID in stack/btm_ble_api.h */
88 #define ESP_BLE_APPEARANCE_HID_KEYBOARD            0x03C1 /*!< relate to BTM_BLE_APPEARANCE_HID_KEYBOARD in stack/btm_ble_api.h */
89 #define ESP_BLE_APPEARANCE_HID_MOUSE               0x03C2 /*!< relate to BTM_BLE_APPEARANCE_HID_MOUSE in stack/btm_ble_api.h */
90 #define ESP_BLE_APPEARANCE_HID_JOYSTICK            0x03C3 /*!< relate to BTM_BLE_APPEARANCE_HID_JOYSTICK in stack/btm_ble_api.h */
91 #define ESP_BLE_APPEARANCE_HID_GAMEPAD             0x03C4 /*!< relate to BTM_BLE_APPEARANCE_HID_GAMEPAD in stack/btm_ble_api.h */
92 #define ESP_BLE_APPEARANCE_HID_DIGITIZER_TABLET    0x03C5 /*!< relate to BTM_BLE_APPEARANCE_HID_DIGITIZER_TABLET in stack/btm_ble_api.h */
93 #define ESP_BLE_APPEARANCE_HID_CARD_READER         0x03C6 /*!< relate to BTM_BLE_APPEARANCE_HID_CARD_READER in stack/btm_ble_api.h */
94 #define ESP_BLE_APPEARANCE_HID_DIGITAL_PEN         0x03C7 /*!< relate to BTM_BLE_APPEARANCE_HID_DIGITAL_PEN in stack/btm_ble_api.h */
95 #define ESP_BLE_APPEARANCE_HID_BARCODE_SCANNER     0x03C8 /*!< relate to BTM_BLE_APPEARANCE_HID_BARCODE_SCANNER in stack/btm_ble_api.h */
96 #define ESP_BLE_APPEARANCE_GENERIC_GLUCOSE         0x0400 /*!< relate to BTM_BLE_APPEARANCE_GENERIC_GLUCOSE in stack/btm_ble_api.h */
97 #define ESP_BLE_APPEARANCE_GENERIC_WALKING         0x0440 /*!< relate to BTM_BLE_APPEARANCE_GENERIC_WALKING in stack/btm_ble_api.h */
98 #define ESP_BLE_APPEARANCE_WALKING_IN_SHOE         0x0441 /*!< relate to BTM_BLE_APPEARANCE_WALKING_IN_SHOE in stack/btm_ble_api.h */
99 #define ESP_BLE_APPEARANCE_WALKING_ON_SHOE         0x0442 /*!< relate to BTM_BLE_APPEARANCE_WALKING_ON_SHOE in stack/btm_ble_api.h */
100 #define ESP_BLE_APPEARANCE_WALKING_ON_HIP          0x0443 /*!< relate to BTM_BLE_APPEARANCE_WALKING_ON_HIP in stack/btm_ble_api.h */
101 #define ESP_BLE_APPEARANCE_GENERIC_CYCLING         0x0480 /*!< relate to BTM_BLE_APPEARANCE_GENERIC_CYCLING in stack/btm_ble_api.h */
102 #define ESP_BLE_APPEARANCE_CYCLING_COMPUTER        0x0481 /*!< relate to BTM_BLE_APPEARANCE_CYCLING_COMPUTER in stack/btm_ble_api.h */
103 #define ESP_BLE_APPEARANCE_CYCLING_SPEED           0x0482 /*!< relate to BTM_BLE_APPEARANCE_CYCLING_SPEED in stack/btm_ble_api.h */
104 #define ESP_BLE_APPEARANCE_CYCLING_CADENCE         0x0483 /*!< relate to BTM_BLE_APPEARANCE_CYCLING_CADENCE in stack/btm_ble_api.h */
105 #define ESP_BLE_APPEARANCE_CYCLING_POWER           0x0484 /*!< relate to BTM_BLE_APPEARANCE_CYCLING_POWER in stack/btm_ble_api.h */
106 #define ESP_BLE_APPEARANCE_CYCLING_SPEED_CADENCE   0x0485 /*!< relate to BTM_BLE_APPEARANCE_CYCLING_SPEED_CADENCE in stack/btm_ble_api.h */
107 #define ESP_BLE_APPEARANCE_STANDALONE_SPEAKER      0x0841 /*!< relate to BTM_BLE_APPEARANCE_STANDALONE_SPEAKER in stack/btm_ble_api.h */
108 #define ESP_BLE_APPEARANCE_GENERIC_PULSE_OXIMETER  0x0C40 /*!< relate to BTM_BLE_APPEARANCE_GENERIC_PULSE_OXIMETER in stack/btm_ble_api.h */
109 #define ESP_BLE_APPEARANCE_PULSE_OXIMETER_FINGERTIP 0x0C41 /*!< relate to BTM_BLE_APPEARANCE_PULSE_OXIMETER_FINGERTIP in stack/btm_ble_api.h */
110 #define ESP_BLE_APPEARANCE_PULSE_OXIMETER_WRIST    0x0C42 /*!< relate to BTM_BLE_APPEARANCE_PULSE_OXIMETER_WRIST in stack/btm_ble_api.h */
111 #define ESP_BLE_APPEARANCE_GENERIC_WEIGHT          0x0C80 /*!< relate to BTM_BLE_APPEARANCE_GENERIC_WEIGHT in stack/btm_ble_api.h */
112 #define ESP_BLE_APPEARANCE_GENERIC_PERSONAL_MOBILITY_DEVICE    0x0CC0 /*!< relate to BTM_BLE_APPEARANCE_GENERIC_PERSONAL_MOBILITY_DEVICE in stack/btm_ble_api.h */
113 #define ESP_BLE_APPEARANCE_POWERED_WHEELCHAIR                  0x0CC1 /*!< relate to BTM_BLE_APPEARANCE_POWERED_WHEELCHAIR in stack/btm_ble_api.h */
114 #define ESP_BLE_APPEARANCE_MOBILITY_SCOOTER                    0x0CC2 /*!< relate to BTM_BLE_APPEARANCE_MOBILITY_SCOOTER in stack/btm_ble_api.h */
115 #define ESP_BLE_APPEARANCE_GENERIC_CONTINUOUS_GLUCOSE_MONITOR  0x0D00 /*!< relate to BTM_BLE_APPEARANCE_GENERIC_CONTINUOUS_GLUCOSE_MONITOR in stack/btm_ble_api.h */
116 #define ESP_BLE_APPEARANCE_GENERIC_INSULIN_PUMP                0x0D40 /*!< relate to BTM_BLE_APPEARANCE_GENERIC_INSULIN_PUMP in stack/btm_ble_api.h */
117 #define ESP_BLE_APPEARANCE_INSULIN_PUMP_DURABLE_PUMP           0x0D41 /*!< relate to BTM_BLE_APPEARANCE_INSULIN_PUMP_DURABLE_PUMP in stack/btm_ble_api.h */
118 #define ESP_BLE_APPEARANCE_INSULIN_PUMP_PATCH_PUMP             0x0D44 /*!< relate to BTM_BLE_APPEARANCE_INSULIN_PUMP_PATCH_PUMP in stack/btm_ble_api.h */
119 #define ESP_BLE_APPEARANCE_INSULIN_PEN                         0x0D48 /*!< relate to BTM_BLE_APPEARANCE_INSULIN_PEN in stack/btm_ble_api.h */
120 #define ESP_BLE_APPEARANCE_GENERIC_MEDICATION_DELIVERY         0x0D80 /*!< relate to BTM_BLE_APPEARANCE_GENERIC_MEDICATION_DELIVERY in stack/btm_ble_api.h */
121 #define ESP_BLE_APPEARANCE_GENERIC_OUTDOOR_SPORTS  0x1440             /*!< relate to BTM_BLE_APPEARANCE_GENERIC_OUTDOOR_SPORTS in stack/btm_ble_api.h */
122 #define ESP_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION 0x1441             /*!< relate to BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION in stack/btm_ble_api.h */
123 #define ESP_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_AND_NAV     0x1442 /*!< relate to BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_AND_NAV in stack/btm_ble_api.h */
124 #define ESP_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_POD         0x1443 /*!< relate to BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_POD in stack/btm_ble_api.h */
125 #define ESP_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_POD_AND_NAV 0x1444 /*!< relate to BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_POD_AND_NAV in stack/btm_ble_api.h */
126 
127 typedef uint8_t esp_ble_io_cap_t;               /*!< combination of the io capability */
128 
129 #define    BLE_DTM_PKT_PAYLOAD_0x00   0x00       /*!< PRBS9 sequence ‘11111111100000111101...’ (in transmission order) as described in [Vol 6] Part F, Section 4.1.5 */
130 #define    BLE_DTM_PKT_PAYLOAD_0x01   0x01       /*!< Repeated ‘11110000’ (in transmission order) sequence as described in [Vol 6] Part F, Section 4.1.5 */
131 #define    BLE_DTM_PKT_PAYLOAD_0x02   0x02       /*!< Repeated ‘10101010’ (in transmission order) sequence as described in [Vol 6] Part F, Section 4.1.5 */
132 #define    BLE_DTM_PKT_PAYLOAD_0x03   0x03       /*!< PRBS15 sequence as described in [Vol 6] Part F, Section 4.1.5 */
133 #define    BLE_DTM_PKT_PAYLOAD_0x04   0x04       /*!< Repeated ‘11111111’ (in transmission order) sequence */
134 #define    BLE_DTM_PKT_PAYLOAD_0x05   0x05       /*!< Repeated ‘00000000’ (in transmission order) sequence */
135 #define    BLE_DTM_PKT_PAYLOAD_0x06   0x06       /*!< Repeated ‘00001111’ (in transmission order) sequence */
136 #define    BLE_DTM_PKT_PAYLOAD_0x07   0x07       /*!< Repeated ‘01010101’ (in transmission order) sequence */
137 #define    BLE_DTM_PKT_PAYLOAD_MAX    0x08       /*!< 0x08 ~ 0xFF, Reserved for future use */
138 
139 typedef uint8_t esp_ble_dtm_pkt_payload_t;
140 
141 /// GAP BLE callback event type
142 typedef enum {
143     //BLE_42_FEATURE_SUPPORT
144     ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT        = 0,       /*!< When advertising data set complete, the event comes */
145     ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT,             /*!< When scan response data set complete, the event comes */
146     ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT,                /*!< When scan parameters set complete, the event comes */
147     ESP_GAP_BLE_SCAN_RESULT_EVT,                            /*!< When one scan result ready, the event comes each time */
148     ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT,              /*!< When raw advertising data set complete, the event comes */
149     ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT,         /*!< When raw scan response data set complete, the event comes */
150     ESP_GAP_BLE_ADV_START_COMPLETE_EVT,                     /*!< When start advertising complete, the event comes */
151     ESP_GAP_BLE_SCAN_START_COMPLETE_EVT,                    /*!< When start scan complete, the event comes */
152     //BLE_INCLUDED
153     ESP_GAP_BLE_AUTH_CMPL_EVT = 8,                          /*!< Authentication complete indication. */
154     ESP_GAP_BLE_KEY_EVT,                                    /*!< BLE  key event for peer device keys */
155     ESP_GAP_BLE_SEC_REQ_EVT,                                /*!< BLE  security request */
156     ESP_GAP_BLE_PASSKEY_NOTIF_EVT,                          /*!< passkey notification event */
157     ESP_GAP_BLE_PASSKEY_REQ_EVT,                            /*!< passkey request event */
158     ESP_GAP_BLE_OOB_REQ_EVT,                                /*!< OOB request event */
159     ESP_GAP_BLE_LOCAL_IR_EVT,                               /*!< BLE local IR (identity Root 128-bit random static value used to generate Long Term Key) event */
160     ESP_GAP_BLE_LOCAL_ER_EVT,                               /*!< BLE local ER (Encryption Root value used to generate identity resolving key) event */
161     ESP_GAP_BLE_NC_REQ_EVT,                                 /*!< Numeric Comparison request event */
162     //BLE_42_FEATURE_SUPPORT
163     ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT,                      /*!< When stop adv complete, the event comes */
164     ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT,                     /*!< When stop scan complete, the event comes */
165     //BLE_INCLUDED
166     ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT = 19,              /*!< When set the static rand address complete, the event comes */
167     ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT,                     /*!< When update connection parameters complete, the event comes */
168     ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT,                /*!< When set pkt length complete, the event comes */
169     ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT,             /*!< When  Enable/disable privacy on the local device complete, the event comes */
170     ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT,               /*!< When remove the bond device complete, the event comes */
171     ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT,                /*!< When clear the bond device clear complete, the event comes */
172     ESP_GAP_BLE_GET_BOND_DEV_COMPLETE_EVT,                  /*!< When get the bond device list complete, the event comes */
173     ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT,                     /*!< When read the rssi complete, the event comes */
174     ESP_GAP_BLE_UPDATE_WHITELIST_COMPLETE_EVT,              /*!< When add or remove whitelist complete, the event comes */
175     //BLE_42_FEATURE_SUPPORT
176     ESP_GAP_BLE_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_COMPLETE_EVT,  /*!< When update duplicate exceptional list complete, the event comes */
177     //BLE_INCLUDED
178     ESP_GAP_BLE_SET_CHANNELS_EVT = 29,                           /*!< When setting BLE channels complete, the event comes */
179     //BLE_50_FEATURE_SUPPORT
180     ESP_GAP_BLE_READ_PHY_COMPLETE_EVT,                           /*!< when reading phy complete, this event comes */
181     ESP_GAP_BLE_SET_PREFERRED_DEFAULT_PHY_COMPLETE_EVT,          /*!< when preferred default phy complete, this event comes */
182     ESP_GAP_BLE_SET_PREFERRED_PHY_COMPLETE_EVT,                  /*!< when preferred phy complete , this event comes */
183     ESP_GAP_BLE_EXT_ADV_SET_RAND_ADDR_COMPLETE_EVT,              /*!< when extended set random address complete, the event comes */
184     ESP_GAP_BLE_EXT_ADV_SET_PARAMS_COMPLETE_EVT,                 /*!< when extended advertising parameter complete, the event comes */
185     ESP_GAP_BLE_EXT_ADV_DATA_SET_COMPLETE_EVT,                   /*!< when extended advertising data complete, the event comes */
186     ESP_GAP_BLE_EXT_SCAN_RSP_DATA_SET_COMPLETE_EVT,              /*!< when extended scan response data complete, the event comes */
187     ESP_GAP_BLE_EXT_ADV_START_COMPLETE_EVT,                      /*!< when extended advertising start complete, the event comes */
188     ESP_GAP_BLE_EXT_ADV_STOP_COMPLETE_EVT,                       /*!< when extended advertising stop complete, the event comes */
189     ESP_GAP_BLE_EXT_ADV_SET_REMOVE_COMPLETE_EVT,                 /*!< when extended advertising set remove complete, the event comes */
190     ESP_GAP_BLE_EXT_ADV_SET_CLEAR_COMPLETE_EVT,                  /*!< when extended advertising set clear complete, the event comes */
191     ESP_GAP_BLE_PERIODIC_ADV_SET_PARAMS_COMPLETE_EVT,            /*!< when periodic advertising parameter complete, the event comes */
192     ESP_GAP_BLE_PERIODIC_ADV_DATA_SET_COMPLETE_EVT,              /*!< when periodic advertising data complete, the event comes */
193     ESP_GAP_BLE_PERIODIC_ADV_START_COMPLETE_EVT,                 /*!< when periodic advertising start complete, the event comes */
194     ESP_GAP_BLE_PERIODIC_ADV_STOP_COMPLETE_EVT,                  /*!< when periodic advertising stop complete, the event comes */
195     ESP_GAP_BLE_PERIODIC_ADV_CREATE_SYNC_COMPLETE_EVT,           /*!< when periodic advertising create sync complete, the event comes */
196     ESP_GAP_BLE_PERIODIC_ADV_SYNC_CANCEL_COMPLETE_EVT,           /*!< when extended advertising sync cancel complete, the event comes */
197     ESP_GAP_BLE_PERIODIC_ADV_SYNC_TERMINATE_COMPLETE_EVT,        /*!< when extended advertising sync terminate complete, the event comes */
198     ESP_GAP_BLE_PERIODIC_ADV_ADD_DEV_COMPLETE_EVT,               /*!< when extended advertising add device complete , the event comes */
199     ESP_GAP_BLE_PERIODIC_ADV_REMOVE_DEV_COMPLETE_EVT,            /*!< when extended advertising remove device complete, the event comes */
200     ESP_GAP_BLE_PERIODIC_ADV_CLEAR_DEV_COMPLETE_EVT,             /*!< when extended advertising clear device, the event comes */
201     ESP_GAP_BLE_SET_EXT_SCAN_PARAMS_COMPLETE_EVT,                /*!< when extended scan parameter complete, the event comes */
202     ESP_GAP_BLE_EXT_SCAN_START_COMPLETE_EVT,                     /*!< when extended scan start complete, the event comes */
203     ESP_GAP_BLE_EXT_SCAN_STOP_COMPLETE_EVT,                      /*!< when extended scan stop complete, the event comes */
204     ESP_GAP_BLE_PREFER_EXT_CONN_PARAMS_SET_COMPLETE_EVT,         /*!< when extended prefer connection parameter set complete, the event comes */
205     ESP_GAP_BLE_PHY_UPDATE_COMPLETE_EVT,                         /*!< when ble phy update complete, the event comes */
206     ESP_GAP_BLE_EXT_ADV_REPORT_EVT,                              /*!< when extended advertising report complete, the event comes */
207     ESP_GAP_BLE_SCAN_TIMEOUT_EVT,                                /*!< when scan timeout complete, the event comes */
208     ESP_GAP_BLE_ADV_TERMINATED_EVT,                              /*!< when advertising terminate data complete, the event comes */
209     ESP_GAP_BLE_SCAN_REQ_RECEIVED_EVT,                           /*!< when scan req received complete, the event comes */
210     ESP_GAP_BLE_CHANNEL_SELECT_ALGORITHM_EVT,                    /*!< when channel select algorithm complete, the event comes */
211     ESP_GAP_BLE_PERIODIC_ADV_REPORT_EVT,                         /*!< when periodic report advertising complete, the event comes */
212     ESP_GAP_BLE_PERIODIC_ADV_SYNC_LOST_EVT,                      /*!< when periodic advertising sync lost complete, the event comes */
213     ESP_GAP_BLE_PERIODIC_ADV_SYNC_ESTAB_EVT,                     /*!< when periodic advertising sync establish complete, the event comes */
214     //BLE_INCLUDED
215     ESP_GAP_BLE_SC_OOB_REQ_EVT,                                  /*!< Secure Connection OOB request event */
216     ESP_GAP_BLE_SC_CR_LOC_OOB_EVT,                               /*!< Secure Connection create OOB data complete event */
217     ESP_GAP_BLE_GET_DEV_NAME_COMPLETE_EVT,                       /*!< When getting BT device name complete, the event comes */
218     //BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER
219     ESP_GAP_BLE_PERIODIC_ADV_RECV_ENABLE_COMPLETE_EVT,           /*!< when set periodic advertising receive enable complete, the event comes */
220     ESP_GAP_BLE_PERIODIC_ADV_SYNC_TRANS_COMPLETE_EVT,            /*!< when periodic advertising sync transfer complete, the event comes */
221     ESP_GAP_BLE_PERIODIC_ADV_SET_INFO_TRANS_COMPLETE_EVT,        /*!< when periodic advertising set info transfer complete, the event comes */
222     ESP_GAP_BLE_SET_PAST_PARAMS_COMPLETE_EVT,                    /*!< when set periodic advertising sync transfer params complete, the event comes */
223     ESP_GAP_BLE_PERIODIC_ADV_SYNC_TRANS_RECV_EVT,                /*!< when periodic advertising sync transfer received, the event comes */
224     // DTM
225     ESP_GAP_BLE_DTM_TEST_UPDATE_EVT,                             /*!< when direct test mode state changes, the event comes */
226     // BLE_INCLUDED
227     ESP_GAP_BLE_ADV_CLEAR_COMPLETE_EVT,                          /*!< When clear advertising complete, the event comes */
228     ESP_GAP_BLE_SET_RPA_TIMEOUT_COMPLETE_EVT,                    /*!< When set the Resolvable Private Address (RPA) timeout completes, the event comes */
229     ESP_GAP_BLE_ADD_DEV_TO_RESOLVING_LIST_COMPLETE_EVT,          /*!< when add a device to the resolving list completes, the event comes*/
230     ESP_GAP_BLE_VENDOR_CMD_COMPLETE_EVT,                         /*!< When vendor hci command complete, the event comes */
231     ESP_GAP_BLE_SET_PRIVACY_MODE_COMPLETE_EVT,                   /*!< When set privacy mode complete, the event comes */
232     ESP_GAP_BLE_SET_CSA_SUPPORT_COMPLETE_EVT,                    /*!< When set CSA support complete, the event comes */
233     ESP_GAP_BLE_EVT_MAX,                                         /*!< when maximum advertising event complete, the event comes */
234 } esp_gap_ble_cb_event_t;
235 
236 #define ESP_GAP_BLE_CHANNELS_LEN     5                           /*!< channel length*/
237 typedef uint8_t esp_gap_ble_channels[ESP_GAP_BLE_CHANNELS_LEN];
238 
239 /// This is the old name, just for backwards compatibility
240 #define ESP_GAP_BLE_ADD_WHITELIST_COMPLETE_EVT ESP_GAP_BLE_UPDATE_WHITELIST_COMPLETE_EVT
241 
242 /// Advertising data maximum length
243 #define ESP_BLE_ADV_DATA_LEN_MAX               31
244 /// Scan response data maximum length
245 #define ESP_BLE_SCAN_RSP_DATA_LEN_MAX          31
246 
247 #define VENDOR_HCI_CMD_MASK                    (0x3F << 10) /**!< 0xFC00 */
248 
249 /* relate to BTM_BLE_AD_TYPE_xxx in stack/btm_ble_api.h */
250 /// The type of advertising data(not adv_type)
251 typedef enum {
252     ESP_BLE_AD_TYPE_FLAG                     = 0x01,    /* relate to BTM_BLE_AD_TYPE_FLAG in stack/btm_ble_api.h */
253     ESP_BLE_AD_TYPE_16SRV_PART               = 0x02,    /* relate to BTM_BLE_AD_TYPE_16SRV_PART in stack/btm_ble_api.h */
254     ESP_BLE_AD_TYPE_16SRV_CMPL               = 0x03,    /* relate to BTM_BLE_AD_TYPE_16SRV_CMPL in stack/btm_ble_api.h */
255     ESP_BLE_AD_TYPE_32SRV_PART               = 0x04,    /* relate to BTM_BLE_AD_TYPE_32SRV_PART in stack/btm_ble_api.h */
256     ESP_BLE_AD_TYPE_32SRV_CMPL               = 0x05,    /* relate to BTM_BLE_AD_TYPE_32SRV_CMPL in stack/btm_ble_api.h */
257     ESP_BLE_AD_TYPE_128SRV_PART              = 0x06,    /* relate to BTM_BLE_AD_TYPE_128SRV_PART in stack/btm_ble_api.h */
258     ESP_BLE_AD_TYPE_128SRV_CMPL              = 0x07,    /* relate to BTM_BLE_AD_TYPE_128SRV_CMPL in stack/btm_ble_api.h */
259     ESP_BLE_AD_TYPE_NAME_SHORT               = 0x08,    /* relate to BTM_BLE_AD_TYPE_NAME_SHORT in stack/btm_ble_api.h */
260     ESP_BLE_AD_TYPE_NAME_CMPL                = 0x09,    /* relate to BTM_BLE_AD_TYPE_NAME_CMPL in stack/btm_ble_api.h */
261     ESP_BLE_AD_TYPE_TX_PWR                   = 0x0A,    /* relate to BTM_BLE_AD_TYPE_TX_PWR in stack/btm_ble_api.h */
262     ESP_BLE_AD_TYPE_DEV_CLASS                = 0x0D,    /* relate to BTM_BLE_AD_TYPE_DEV_CLASS in stack/btm_ble_api.h */
263     ESP_BLE_AD_TYPE_SM_TK                    = 0x10,    /* relate to BTM_BLE_AD_TYPE_SM_TK in stack/btm_ble_api.h */
264     ESP_BLE_AD_TYPE_SM_OOB_FLAG              = 0x11,    /* relate to BTM_BLE_AD_TYPE_SM_OOB_FLAG in stack/btm_ble_api.h */
265     ESP_BLE_AD_TYPE_INT_RANGE                = 0x12,    /* relate to BTM_BLE_AD_TYPE_INT_RANGE in stack/btm_ble_api.h */
266     ESP_BLE_AD_TYPE_SOL_SRV_UUID             = 0x14,    /* relate to BTM_BLE_AD_TYPE_SOL_SRV_UUID in stack/btm_ble_api.h */
267     ESP_BLE_AD_TYPE_128SOL_SRV_UUID          = 0x15,    /* relate to BTM_BLE_AD_TYPE_128SOL_SRV_UUID in stack/btm_ble_api.h */
268     ESP_BLE_AD_TYPE_SERVICE_DATA             = 0x16,    /* relate to BTM_BLE_AD_TYPE_SERVICE_DATA in stack/btm_ble_api.h */
269     ESP_BLE_AD_TYPE_PUBLIC_TARGET            = 0x17,    /* relate to BTM_BLE_AD_TYPE_PUBLIC_TARGET in stack/btm_ble_api.h */
270     ESP_BLE_AD_TYPE_RANDOM_TARGET            = 0x18,    /* relate to BTM_BLE_AD_TYPE_RANDOM_TARGET in stack/btm_ble_api.h */
271     ESP_BLE_AD_TYPE_APPEARANCE               = 0x19,    /* relate to BTM_BLE_AD_TYPE_APPEARANCE in stack/btm_ble_api.h */
272     ESP_BLE_AD_TYPE_ADV_INT                  = 0x1A,    /* relate to BTM_BLE_AD_TYPE_ADV_INT in stack/btm_ble_api.h */
273     ESP_BLE_AD_TYPE_LE_DEV_ADDR              = 0x1b,    /* relate to BTM_BLE_AD_TYPE_LE_DEV_ADDR in stack/btm_ble_api.h */
274     ESP_BLE_AD_TYPE_LE_ROLE                  = 0x1c,    /* relate to BTM_BLE_AD_TYPE_LE_ROLE in stack/btm_ble_api.h */
275     ESP_BLE_AD_TYPE_SPAIR_C256               = 0x1d,    /* relate to BTM_BLE_AD_TYPE_SPAIR_C256 in stack/btm_ble_api.h */
276     ESP_BLE_AD_TYPE_SPAIR_R256               = 0x1e,    /* relate to BTM_BLE_AD_TYPE_SPAIR_R256 in stack/btm_ble_api.h */
277     ESP_BLE_AD_TYPE_32SOL_SRV_UUID           = 0x1f,    /* relate to BTM_BLE_AD_TYPE_32SOL_SRV_UUID in stack/btm_ble_api.h */
278     ESP_BLE_AD_TYPE_32SERVICE_DATA           = 0x20,    /* relate to BTM_BLE_AD_TYPE_32SERVICE_DATA in stack/btm_ble_api.h */
279     ESP_BLE_AD_TYPE_128SERVICE_DATA          = 0x21,    /* relate to BTM_BLE_AD_TYPE_128SERVICE_DATA in stack/btm_ble_api.h */
280     ESP_BLE_AD_TYPE_LE_SECURE_CONFIRM        = 0x22,    /* relate to BTM_BLE_AD_TYPE_LE_SECURE_CONFIRM in stack/btm_ble_api.h */
281     ESP_BLE_AD_TYPE_LE_SECURE_RANDOM         = 0x23,    /* relate to BTM_BLE_AD_TYPE_LE_SECURE_RANDOM in stack/btm_ble_api.h */
282     ESP_BLE_AD_TYPE_URI                      = 0x24,    /* relate to BTM_BLE_AD_TYPE_URI in stack/btm_ble_api.h */
283     ESP_BLE_AD_TYPE_INDOOR_POSITION          = 0x25,    /* relate to BTM_BLE_AD_TYPE_INDOOR_POSITION in stack/btm_ble_api.h */
284     ESP_BLE_AD_TYPE_TRANS_DISC_DATA          = 0x26,    /* relate to BTM_BLE_AD_TYPE_TRANS_DISC_DATA in stack/btm_ble_api.h */
285     ESP_BLE_AD_TYPE_LE_SUPPORT_FEATURE       = 0x27,    /* relate to BTM_BLE_AD_TYPE_LE_SUPPORT_FEATURE in stack/btm_ble_api.h */
286     ESP_BLE_AD_TYPE_CHAN_MAP_UPDATE          = 0x28,    /* relate to BTM_BLE_AD_TYPE_CHAN_MAP_UPDATE in stack/btm_ble_api.h */
287     ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE    = 0xFF,    /* relate to BTM_BLE_AD_MANUFACTURER_SPECIFIC_TYPE in stack/btm_ble_api.h */
288 } esp_ble_adv_data_type;
289 
290 /// Advertising mode
291 typedef enum {
292     ADV_TYPE_IND                = 0x00,
293     ADV_TYPE_DIRECT_IND_HIGH    = 0x01,
294     ADV_TYPE_SCAN_IND           = 0x02,
295     ADV_TYPE_NONCONN_IND        = 0x03,
296     ADV_TYPE_DIRECT_IND_LOW     = 0x04,
297 } esp_ble_adv_type_t;
298 
299 /// Advertising channel mask
300 typedef enum {
301     ADV_CHNL_37     = 0x01,
302     ADV_CHNL_38     = 0x02,
303     ADV_CHNL_39     = 0x04,
304     ADV_CHNL_ALL    = 0x07,
305 } esp_ble_adv_channel_t;
306 
307 typedef enum {
308     ///Allow both scan and connection requests from anyone
309     ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY  = 0x00,
310     ///Allow both scan req from White List devices only and connection req from anyone
311     ADV_FILTER_ALLOW_SCAN_WLST_CON_ANY,
312     ///Allow both scan req from anyone and connection req from White List devices only
313     ADV_FILTER_ALLOW_SCAN_ANY_CON_WLST,
314     ///Allow scan and connection requests from White List devices only
315     ADV_FILTER_ALLOW_SCAN_WLST_CON_WLST,
316     ///Enumeration end value for advertising filter policy value check
317 } esp_ble_adv_filter_t;
318 
319 
320 /* relate to BTA_DM_BLE_SEC_xxx in bta/bta_api.h */
321 typedef enum {
322     ESP_BLE_SEC_ENCRYPT = 1,            /*!< relate to BTA_DM_BLE_SEC_ENCRYPT in bta/bta_api.h. If the device has already
323                                            bonded, the stack will used Long Term Key (LTK) to encrypt with the remote device directly.
324                                            Else if the device hasn't bonded, the stack will used the default authentication request
325                                            used the esp_ble_gap_set_security_param function set by the user. */
326     ESP_BLE_SEC_ENCRYPT_NO_MITM,        /*!< relate to BTA_DM_BLE_SEC_ENCRYPT_NO_MITM in bta/bta_api.h. If the device has been already
327                                            bonded, the stack will check the LTK (Long Term Key) Whether the authentication request has been met, and if met, use the LTK
328                                            to encrypt with the remote device directly, else re-pair with the remote device.
329                                            Else if the device hasn't been bonded, the stack will use NO MITM authentication request in the current link instead of
330                                            using the authreq in the esp_ble_gap_set_security_param function set by the user. */
331     ESP_BLE_SEC_ENCRYPT_MITM,           /*!< relate to BTA_DM_BLE_SEC_ENCRYPT_MITM in bta/bta_api.h. If the device has been already
332                                            bonded, the stack will check the LTK (Long Term Key) whether the authentication request has been met, and if met, use the LTK
333                                            to encrypt with the remote device directly, else re-pair with the remote device.
334                                            Else if the device hasn't been bonded, the stack will use MITM authentication request in the current link instead of
335                                            using the authreq in the esp_ble_gap_set_security_param function set by the user. */
336 }esp_ble_sec_act_t;
337 
338 typedef enum {
339     ESP_BLE_SM_PASSKEY = 0,
340     /*!< Authentication requirements of local device */
341     ESP_BLE_SM_AUTHEN_REQ_MODE,
342     /*!< The IO capability of local device */
343     ESP_BLE_SM_IOCAP_MODE,
344     /*!< Initiator Key Distribution/Generation */
345     ESP_BLE_SM_SET_INIT_KEY,
346     /*!< Responder Key Distribution/Generation */
347     ESP_BLE_SM_SET_RSP_KEY,
348     /*!< Maximum Encryption key size to support */
349     ESP_BLE_SM_MAX_KEY_SIZE,
350     /*!< Minimum Encryption key size requirement from Peer */
351     ESP_BLE_SM_MIN_KEY_SIZE,
352     /*!< Set static Passkey */
353     ESP_BLE_SM_SET_STATIC_PASSKEY,
354     /*!< Reset static Passkey */
355     ESP_BLE_SM_CLEAR_STATIC_PASSKEY,
356     /*!< Accept only specified SMP Authentication requirement */
357     ESP_BLE_SM_ONLY_ACCEPT_SPECIFIED_SEC_AUTH,
358     /*!< Enable/Disable OOB support */
359     ESP_BLE_SM_OOB_SUPPORT,
360     /*!< Appl encryption key size */
361     ESP_BLE_APP_ENC_KEY_SIZE,
362     /*!< authentication max param */
363     ESP_BLE_SM_MAX_PARAM,
364 } esp_ble_sm_param_t;
365 
366 typedef enum {
367     /// DTM TX start event
368     DTM_TX_START_EVT  = 0x00,
369     ///DTM RX start event
370     DTM_RX_START_EVT,
371     ///DTM test end event
372     DTM_TEST_STOP_EVT,
373 } esp_ble_dtm_update_evt_t;
374 
375 /**
376  * @brief Vendor HCI command parameters
377  */
378 typedef struct {
379     uint16_t opcode;                /*!< vendor hci command opcode */
380     uint8_t param_len;              /*!< the length of parameter */
381     uint8_t *p_param_buf;           /*!< the point of parameter buffer */
382 } esp_ble_vendor_cmd_params_t;
383 
384 #if (BLE_42_FEATURE_SUPPORT == TRUE)
385 /**
386 * @brief DTM TX parameters
387 */
388 typedef struct
389 {
390     uint8_t                         tx_channel;            /*!<  channel for sending test data, tx_channel = (Frequency -2402)/2, tx_channel range:0x00-0x27, Frequency range: 2402 MHz to 2480 MHz */
391     uint8_t                         len_of_data;           /*!<  length in bytes of payload data in each packet */
392     esp_ble_dtm_pkt_payload_t       pkt_payload;           /*!<  packet payload type. value range: 0x00-0x07 */
393 } esp_ble_dtm_tx_t;
394 /**
395 * @brief DTM RX parameters
396 */
397 typedef struct
398 {
399     uint8_t          rx_channel;            /*!<  channel for test data reception, rx_channel = (Frequency -2402)/2, tx_channel range:0x00-0x27, Frequency range: 2402 MHz to 2480 MHz */
400 } esp_ble_dtm_rx_t;
401 
402 /// Advertising parameters
403 typedef struct {
404     uint16_t                adv_int_min;        /*!< Minimum advertising interval for
405                                                   undirected and low duty cycle directed advertising.
406                                                   Range: 0x0020 to 0x4000 Default: N = 0x0800 (1.28 second)
407                                                   Time = N * 0.625 msec Time Range: 20 ms to 10.24 sec */
408     uint16_t                adv_int_max;        /*!< Maximum advertising interval for
409                                                   undirected and low duty cycle directed advertising.
410                                                   Range: 0x0020 to 0x4000 Default: N = 0x0800 (1.28 second)
411                                                   Time = N * 0.625 msec Time Range: 20 ms to 10.24 sec Advertising max interval */
412     esp_ble_adv_type_t      adv_type;           /*!< Advertising type */
413     esp_ble_addr_type_t     own_addr_type;      /*!< Owner bluetooth device address type */
414     esp_bd_addr_t           peer_addr;          /*!< Peer device bluetooth device address */
415     esp_ble_addr_type_t     peer_addr_type;     /*!< Peer device bluetooth device address type, only support public address type and random address type */
416     esp_ble_adv_channel_t   channel_map;        /*!< Advertising channel map */
417     esp_ble_adv_filter_t    adv_filter_policy;  /*!< Advertising filter policy */
418 } esp_ble_adv_params_t;
419 
420 /// Advertising data content, according to "Supplement to the Bluetooth Core Specification"
421 typedef struct {
422     bool                    set_scan_rsp;           /*!< Set this advertising data as scan response or not*/
423     bool                    include_name;           /*!< Advertising data include device name or not */
424     bool                    include_txpower;        /*!< Advertising data include TX power */
425     int                     min_interval;           /*!< Advertising data show slave preferred connection min interval.
426                                                     The connection interval in the following manner:
427                                                     connIntervalmin = Conn_Interval_Min * 1.25 ms
428                                                     Conn_Interval_Min range: 0x0006 to 0x0C80
429                                                     Value of 0xFFFF indicates no specific minimum.
430                                                     Values not defined above are reserved for future use.*/
431 
432     int                     max_interval;           /*!< Advertising data show slave preferred connection max interval.
433                                                     The connection interval in the following manner:
434                                                     connIntervalmax = Conn_Interval_Max * 1.25 ms
435                                                     Conn_Interval_Max range: 0x0006 to 0x0C80
436                                                     Conn_Interval_Max shall be equal to or greater than the Conn_Interval_Min.
437                                                     Value of 0xFFFF indicates no specific maximum.
438                                                     Values not defined above are reserved for future use.*/
439 
440     int                     appearance;             /*!< External appearance of device */
441     uint16_t                manufacturer_len;       /*!< Manufacturer data length */
442     uint8_t                 *p_manufacturer_data;   /*!< Manufacturer data point */
443     uint16_t                service_data_len;       /*!< Service data length */
444     uint8_t                 *p_service_data;        /*!< Service data point */
445     uint16_t                service_uuid_len;       /*!< Service uuid length */
446     uint8_t                 *p_service_uuid;        /*!< Service uuid array point */
447     uint8_t                 flag;                   /*!< Advertising flag of discovery mode, see BLE_ADV_DATA_FLAG detail */
448 } esp_ble_adv_data_t;
449 
450 #endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
451 
452 /// Ble scan type
453 typedef enum {
454     BLE_SCAN_TYPE_PASSIVE   =   0x0,            /*!< Passive scan */
455     BLE_SCAN_TYPE_ACTIVE    =   0x1,            /*!< Active scan */
456 } esp_ble_scan_type_t;
457 
458 /// Ble scan filter type
459 typedef enum {
460     BLE_SCAN_FILTER_ALLOW_ALL           = 0x0,  /*!< Accept all :
461                                                   1. advertisement packets except directed advertising packets not addressed to this device (default). */
462     BLE_SCAN_FILTER_ALLOW_ONLY_WLST     = 0x1,  /*!< Accept only :
463                                                   1. advertisement packets from devices where the advertiser’s address is in the White list.
464                                                   2. Directed advertising packets which are not addressed for this device shall be ignored. */
465     BLE_SCAN_FILTER_ALLOW_UND_RPA_DIR   = 0x2,  /*!< Accept all :
466                                                   1. undirected advertisement packets, and
467                                                   2. directed advertising packets where the initiator address is a resolvable private address, and
468                                                   3. directed advertising packets addressed to this device. */
469     BLE_SCAN_FILTER_ALLOW_WLIST_RPA_DIR = 0x3,  /*!< Accept all :
470                                                   1. advertisement packets from devices where the advertiser’s address is in the White list, and
471                                                   2. directed advertising packets where the initiator address is a resolvable private address, and
472                                                   3. directed advertising packets addressed to this device.*/
473 } esp_ble_scan_filter_t;
474 
475 /// Ble scan duplicate type
476 typedef enum {
477     BLE_SCAN_DUPLICATE_DISABLE           = 0x0,  /*!< the Link Layer should generate advertising reports to the host for each packet received */
478     BLE_SCAN_DUPLICATE_ENABLE            = 0x1,  /*!< the Link Layer should filter out duplicate advertising reports to the Host */
479     #if (BLE_50_FEATURE_SUPPORT == TRUE)
480     BLE_SCAN_DUPLICATE_ENABLE_RESET,             /*!< Duplicate filtering enabled, reset for each scan period, only supported in BLE 5.0. */
481     #endif
482     BLE_SCAN_DUPLICATE_MAX                       /*!< Reserved for future use. */
483 } esp_ble_scan_duplicate_t;
484 #if (BLE_42_FEATURE_SUPPORT == TRUE)
485 /// Ble scan parameters
486 typedef struct {
487     esp_ble_scan_type_t     scan_type;              /*!< Scan type */
488     esp_ble_addr_type_t     own_addr_type;          /*!< Owner address type */
489     esp_ble_scan_filter_t   scan_filter_policy;     /*!< Scan filter policy */
490     uint16_t                scan_interval;          /*!< Scan interval. This is defined as the time interval from
491                                                       when the Controller started its last LE scan until it begins the subsequent LE scan.
492                                                       Range: 0x0004 to 0x4000 Default: 0x0010 (10 ms)
493                                                       Time = N * 0.625 msec
494                                                       Time Range: 2.5 msec to 10.24 seconds*/
495     uint16_t                scan_window;            /*!< Scan window. The duration of the LE scan. LE_Scan_Window
496                                                       shall be less than or equal to LE_Scan_Interval
497                                                       Range: 0x0004 to 0x4000 Default: 0x0010 (10 ms)
498                                                       Time = N * 0.625 msec
499                                                       Time Range: 2.5 msec to 10240 msec */
500     esp_ble_scan_duplicate_t  scan_duplicate;       /*!< The Scan_Duplicates parameter controls whether the Link Layer should filter out
501                                                         duplicate advertising reports (BLE_SCAN_DUPLICATE_ENABLE) to the Host, or if the Link Layer should generate
502                                                         advertising reports for each packet received */
503 } esp_ble_scan_params_t;
504 #endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
505 /// connection parameters information
506 typedef struct {
507     uint16_t             interval;                  /*!< connection interval */
508     uint16_t             latency;                   /*!< Slave latency for the connection in number of connection events. Range: 0x0000 to 0x01F3 */
509     uint16_t             timeout;                   /*!< Supervision timeout for the LE Link. Range: 0x000A to 0x0C80.
510                                                       Mandatory Range: 0x000A to 0x0C80 Time = N * 10 msec
511                                                       Time Range: 100 msec to 32 seconds */
512 } esp_gap_conn_params_t;
513 
514 /// Connection update parameters
515 typedef struct {
516     esp_bd_addr_t bda;                              /*!< Bluetooth device address */
517     uint16_t min_int;                               /*!< Min connection interval */
518     uint16_t max_int;                               /*!< Max connection interval */
519     uint16_t latency;                               /*!< Slave latency for the connection in number of connection events. Range: 0x0000 to 0x01F3 */
520     uint16_t timeout;                               /*!< Supervision timeout for the LE Link. Range: 0x000A to 0x0C80.
521                                                       Mandatory Range: 0x000A to 0x0C80 Time = N * 10 msec
522                                                       Time Range: 100 msec to 32 seconds */
523 } esp_ble_conn_update_params_t;
524 
525 /**
526 * @brief BLE pkt date length keys
527 */
528 typedef struct
529 {
530     uint16_t rx_len;                   /*!< pkt rx data length value */
531     uint16_t tx_len;                   /*!< pkt tx data length value */
532 } esp_ble_pkt_data_length_params_t;
533 
534 /**
535 * @brief BLE encryption keys
536 */
537 typedef struct
538 {
539     esp_bt_octet16_t     ltk;          /*!< The long term key*/
540     esp_bt_octet8_t      rand;         /*!< The random number*/
541     uint16_t             ediv;         /*!< The ediv value*/
542     uint8_t              sec_level;    /*!< The security level of the security link*/
543     uint8_t              key_size;     /*!< The key size(7~16) of the security link*/
544 } esp_ble_penc_keys_t;                 /*!< The key type*/
545 
546 /**
547 * @brief  BLE CSRK keys
548 */
549 typedef struct
550 {
551     uint32_t            counter;      /*!< The counter */
552     esp_bt_octet16_t    csrk;         /*!< The csrk key */
553     uint8_t             sec_level;    /*!< The security level */
554 } esp_ble_pcsrk_keys_t;               /*!< The pcsrk key type */
555 
556 /**
557 * @brief  BLE pid keys
558 */
559 typedef struct
560 {
561     esp_bt_octet16_t          irk;           /*!< The irk value */
562     esp_ble_addr_type_t       addr_type;     /*!< The address type */
563     esp_bd_addr_t             static_addr;   /*!< The static address */
564 } esp_ble_pid_keys_t;                        /*!< The pid key type */
565 
566 /**
567 * @brief  BLE Encryption reproduction keys
568 */
569 typedef struct
570 {
571     esp_bt_octet16_t  ltk;                  /*!< The long term key */
572     uint16_t          div;                  /*!< The div value */
573     uint8_t           key_size;             /*!< The key size of the security link */
574     uint8_t           sec_level;            /*!< The security level of the security link */
575 } esp_ble_lenc_keys_t;                      /*!< The  key type */
576 
577 /**
578 * @brief  BLE SRK keys
579 */
580 typedef struct
581 {
582     uint32_t          counter;              /*!< The counter value */
583     uint16_t          div;                  /*!< The div value */
584     uint8_t           sec_level;            /*!< The security level of the security link */
585     esp_bt_octet16_t  csrk;                 /*!< The csrk key value */
586 } esp_ble_lcsrk_keys;                       /*!< The csrk key type */
587 
588 /**
589 * @brief  Structure associated with ESP_KEY_NOTIF_EVT
590 */
591 typedef struct
592 {
593     esp_bd_addr_t  bd_addr;        /*!< peer address */
594     uint32_t       passkey;        /*!< the numeric value for comparison. If just_works, do not show this number to UI */
595 } esp_ble_sec_key_notif_t;         /*!< BLE key notify type*/
596 
597 /**
598 * @brief  Structure of the security request
599 */
600 typedef struct
601 {
602     esp_bd_addr_t  bd_addr;        /*!< peer address */
603 } esp_ble_sec_req_t;               /*!< BLE security request type*/
604 
605 /**
606 * @brief  union type of the security key value
607 */
608 typedef union
609 {
610     esp_ble_penc_keys_t   penc_key;       /*!< received peer encryption key */
611     esp_ble_pcsrk_keys_t  pcsrk_key;      /*!< received peer device SRK */
612     esp_ble_pid_keys_t    pid_key;        /*!< peer device ID key */
613     esp_ble_lenc_keys_t   lenc_key;       /*!< local encryption reproduction keys LTK = = d1(ER,DIV,0)*/
614     esp_ble_lcsrk_keys    lcsrk_key;      /*!< local device CSRK = d1(ER,DIV,1)*/
615 } esp_ble_key_value_t;                    /*!< ble key value type*/
616 
617 /**
618 * @brief  struct type of the bond key information value
619 */
620 typedef struct
621 {
622     esp_ble_key_mask_t    key_mask;       /*!< the key mask to indicate witch key is present */
623     esp_ble_penc_keys_t   penc_key;       /*!< received peer encryption key */
624     esp_ble_pcsrk_keys_t  pcsrk_key;      /*!< received peer device SRK */
625     esp_ble_pid_keys_t    pid_key;        /*!< peer device ID key */
626 } esp_ble_bond_key_info_t;                /*!< ble bond key information value type */
627 
628 /**
629 * @brief  struct type of the bond device value
630 */
631 typedef struct
632 {
633     esp_bd_addr_t  bd_addr;               /*!< peer address */
634     esp_ble_bond_key_info_t bond_key;     /*!< the bond key information */
635     esp_ble_addr_type_t bd_addr_type;     /*!< peer address type */
636 } esp_ble_bond_dev_t;                     /*!< the ble bond device type */
637 
638 
639 /**
640 * @brief  union type of the security key value
641 */
642 typedef struct
643 {
644     esp_bd_addr_t               bd_addr;        /*!< peer address */
645     esp_ble_key_type_t          key_type;       /*!< key type of the security link */
646     esp_ble_key_value_t         p_key_value;    /*!< the pointer to the key value */
647 } esp_ble_key_t;                                /*!< the union to the ble key value type*/
648 
649 /**
650 * @brief  structure type of the ble local id keys value
651 */
652 typedef struct {
653     esp_bt_octet16_t       ir;                  /*!< the 16 bits of the ir value */
654     esp_bt_octet16_t       irk;                 /*!< the 16 bits of the ir key value */
655     esp_bt_octet16_t       dhk;                 /*!< the 16 bits of the dh key value */
656 } esp_ble_local_id_keys_t;                      /*!< the structure of the ble local id keys value type*/
657 
658 /**
659 * @brief  structure type of the ble local oob data value
660 */
661 typedef struct {
662     esp_bt_octet16_t        oob_c;              /*!< the 128 bits of confirmation value */
663     esp_bt_octet16_t        oob_r;              /*!< the 128 bits of randomizer value */
664 } esp_ble_local_oob_data_t;
665 
666 /**
667 * @brief Definition of the authentication failed reason
668 */
669 typedef enum {
670     // Failure reason defined in Bluetooth Core Spec 5.0 Vol3, Part H, 3.5.5
671     ESP_AUTH_SMP_PASSKEY_FAIL = 78,         /*!< The user input of passkey failed */
672     ESP_AUTH_SMP_OOB_FAIL,                  /*!< The OOB data is not available */
673     ESP_AUTH_SMP_PAIR_AUTH_FAIL,            /*!< The authentication requirements cannot be met */
674     ESP_AUTH_SMP_CONFIRM_VALUE_FAIL,        /*!< The confirm value does not match the calculated comparison value */
675     ESP_AUTH_SMP_PAIR_NOT_SUPPORT,          /*!< Pairing is not supported by the device */
676     ESP_AUTH_SMP_ENC_KEY_SIZE,              /*!< The resultant encryption key size is not long enough */
677     ESP_AUTH_SMP_INVALID_CMD,               /*!< The SMP command received is not supported by this device */
678     ESP_AUTH_SMP_UNKNOWN_ERR,               /*!< Pairing failed due to an unspecified reason */
679     ESP_AUTH_SMP_REPEATED_ATTEMPT,          /*!< Pairing or authentication procedure is disallowed */
680     ESP_AUTH_SMP_INVALID_PARAMETERS,        /*!< The command length is invalid or that a parameter is outside the specified range */
681     ESP_AUTH_SMP_DHKEY_CHK_FAIL,            /*!< The DHKey Check value received doesn’t match the one calculated by the local device */
682     ESP_AUTH_SMP_NUM_COMP_FAIL,             /*!< The confirm values in the numeric comparison protocol do not match */
683     ESP_AUTH_SMP_BR_PARING_IN_PROGR,        /*!< Pairing Request sent over the BR/EDR transport is in progress */
684     ESP_AUTH_SMP_XTRANS_DERIVE_NOT_ALLOW,   /*!< The BR/EDR Link Key or BLE LTK cannot be used to derive */
685 
686     // Failure reason defined in Bluedroid Host
687     ESP_AUTH_SMP_INTERNAL_ERR,              /*!< Internal error in pairing procedure */
688     ESP_AUTH_SMP_UNKNOWN_IO,                /*!< Unknown IO capability, unable to decide association model */
689     ESP_AUTH_SMP_INIT_FAIL,                 /*!< SMP pairing initiation failed */
690     ESP_AUTH_SMP_CONFIRM_FAIL,              /*!< The confirm value does not match */
691     ESP_AUTH_SMP_BUSY,                      /*!< Pending security request on going */
692     ESP_AUTH_SMP_ENC_FAIL,                  /*!< The Controller failed to start encryption */
693     ESP_AUTH_SMP_STARTED,                   /*!< SMP pairing process started */
694     ESP_AUTH_SMP_RSP_TIMEOUT,               /*!< Security Manager timeout due to no SMP command being received */
695     ESP_AUTH_SMP_DIV_NOT_AVAIL,             /*!< Encrypted Diversifier value not available */
696     ESP_AUTH_SMP_UNSPEC_ERR,                /*!< Unspecified failed reason */
697     ESP_AUTH_SMP_CONN_TOUT,                 /*!< Pairing process failed due to connection timeout */
698 } esp_ble_auth_fail_rsn_t;
699 
700 /**
701   * @brief Structure associated with ESP_AUTH_CMPL_EVT
702   */
703 typedef struct
704 {
705     esp_bd_addr_t             bd_addr;               /*!< BD address of peer device */
706     bool                      key_present;           /*!< True if the link key value is valid; false otherwise */
707     esp_link_key              key;                   /*!< Link key associated with peer device */
708     uint8_t                   key_type;              /*!< The type of link key */
709     bool                      success;               /*!< True if authentication succeeded; false otherwise */
710     esp_ble_auth_fail_rsn_t   fail_reason;           /*!< The HCI reason/error code for failure when success is false */
711     esp_ble_addr_type_t       addr_type;             /*!< Peer device address type */
712     esp_bt_dev_type_t         dev_type;              /*!< Device type */
713     esp_ble_auth_req_t        auth_mode;             /*!< Authentication mode */
714 } esp_ble_auth_cmpl_t;                               /*!< The ble authentication complete cb type */
715 
716 /**
717   * @brief union associated with ble security
718   */
719 typedef union
720 {
721     esp_ble_sec_key_notif_t    key_notif;      /*!< passkey notification */
722     esp_ble_sec_req_t          ble_req;        /*!< BLE SMP related request */
723     esp_ble_key_t              ble_key;        /*!< BLE SMP keys used when pairing */
724     esp_ble_local_id_keys_t    ble_id_keys;    /*!< BLE IR event */
725     esp_ble_local_oob_data_t   oob_data;       /*!< BLE SMP secure connection OOB data */
726     esp_ble_auth_cmpl_t        auth_cmpl;      /*!< Authentication complete indication. */
727 } esp_ble_sec_t;                               /*!< BLE security type */
728 #if (BLE_42_FEATURE_SUPPORT == TRUE)
729 /// Sub Event of ESP_GAP_BLE_SCAN_RESULT_EVT
730 typedef enum {
731     ESP_GAP_SEARCH_INQ_RES_EVT             = 0,      /*!< Inquiry result for a peer device. */
732     ESP_GAP_SEARCH_INQ_CMPL_EVT            = 1,      /*!< Inquiry complete. */
733     ESP_GAP_SEARCH_DISC_RES_EVT            = 2,      /*!< Discovery result for a peer device. */
734     ESP_GAP_SEARCH_DISC_BLE_RES_EVT        = 3,      /*!< Discovery result for BLE GATT based service on a peer device. */
735     ESP_GAP_SEARCH_DISC_CMPL_EVT           = 4,      /*!< Discovery complete. */
736     ESP_GAP_SEARCH_DI_DISC_CMPL_EVT        = 5,      /*!< Discovery complete. */
737     ESP_GAP_SEARCH_SEARCH_CANCEL_CMPL_EVT  = 6,      /*!< Search cancelled */
738     ESP_GAP_SEARCH_INQ_DISCARD_NUM_EVT     = 7,      /*!< The number of pkt discarded by flow control */
739 } esp_gap_search_evt_t;
740 #endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
741 /**
742  * @brief Ble scan result event type, to indicate the
743  *        result is scan response or advertising data or other
744  */
745 typedef enum {
746     ESP_BLE_EVT_CONN_ADV         = 0x00,        /*!< Connectable undirected advertising (ADV_IND) */
747     ESP_BLE_EVT_CONN_DIR_ADV     = 0x01,        /*!< Connectable directed advertising (ADV_DIRECT_IND) */
748     ESP_BLE_EVT_DISC_ADV         = 0x02,        /*!< Scannable undirected advertising (ADV_SCAN_IND) */
749     ESP_BLE_EVT_NON_CONN_ADV     = 0x03,        /*!< Non connectable undirected advertising (ADV_NONCONN_IND) */
750     ESP_BLE_EVT_SCAN_RSP         = 0x04,        /*!< Scan Response (SCAN_RSP) */
751 } esp_ble_evt_type_t;
752 
753 typedef enum{
754     ESP_BLE_WHITELIST_REMOVE     = 0X00,    /*!< remove mac from whitelist */
755     ESP_BLE_WHITELIST_ADD        = 0X01,    /*!< add address to whitelist */
756     ESP_BLE_WHITELIST_CLEAR      = 0x02,    /*!< clear all device in whitelist */
757 } esp_ble_wl_operation_t;
758 #if (BLE_42_FEATURE_SUPPORT == TRUE)
759 typedef enum {
760     ESP_BLE_DUPLICATE_EXCEPTIONAL_LIST_ADD      = 0,  /*!< Add device info into duplicate scan exceptional list */
761     ESP_BLE_DUPLICATE_EXCEPTIONAL_LIST_REMOVE,        /*!< Remove device info from duplicate scan exceptional list */
762     ESP_BLE_DUPLICATE_EXCEPTIONAL_LIST_CLEAN,         /*!< Clean duplicate scan exceptional list */
763 } esp_bt_duplicate_exceptional_subcode_type_t;
764 #endif //#if (BLE_42_FEATURE_SUPPORT == TRUE)
765 
766 #define BLE_BIT(n) (1UL<<(n))
767 #if (BLE_42_FEATURE_SUPPORT == TRUE)
768 typedef enum {
769     ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_INFO_ADV_ADDR       = 0,  /*!< BLE advertising address , device info will be added into ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_ADDR_LIST */
770     ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_INFO_MESH_LINK_ID,        /*!< BLE mesh link ID, it is for BLE mesh, device info will be added into ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_MESH_LINK_ID_LIST */
771     ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_INFO_MESH_BEACON_TYPE,    /*!< BLE mesh beacon AD type, the format is | Len | 0x2B | Beacon Type | Beacon Data | */
772     ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_INFO_MESH_PROV_SRV_ADV,   /*!< BLE mesh provisioning service uuid, the format is | 0x02 | 0x01 | flags | 0x03 | 0x03 | 0x1827 | .... |` */
773     ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_INFO_MESH_PROXY_SRV_ADV,  /*!< BLE mesh adv with proxy service uuid, the format is | 0x02 | 0x01 | flags | 0x03 | 0x03 | 0x1828 | .... |` */
774     ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_INFO_MESH_PROXY_SOLIC_ADV,  /*!< BLE mesh adv with proxy service uuid, the format is | 0x02 | 0x01 | flags | 0x03 | 0x03 | 0x1859 | .... |` */
775     ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_INFO_MESH_URI_ADV,        /*!< BLE mesh URI adv, the format is ...| Len | 0x24 | data |... */
776 } esp_ble_duplicate_exceptional_info_type_t;
777 
778 typedef enum {
779     ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_ADDR_LIST                  = BLE_BIT(0),             /*!< duplicate scan exceptional addr list */
780     ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_MESH_LINK_ID_LIST          = BLE_BIT(1),             /*!< duplicate scan exceptional mesh link ID list */
781     ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_MESH_BEACON_TYPE_LIST      = BLE_BIT(2),             /*!< duplicate scan exceptional mesh beacon type list */
782     ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_MESH_PROV_SRV_ADV_LIST     = BLE_BIT(3),             /*!< duplicate scan exceptional mesh adv with provisioning service uuid */
783     ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_MESH_PROXY_SRV_ADV_LIST    = BLE_BIT(4),             /*!< duplicate scan exceptional mesh adv with proxy service uuid */
784     ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_MESH_PROXY_SOLIC_ADV_LIST  = BLE_BIT(5),             /*!< duplicate scan exceptional mesh adv with proxy solicitation PDU uuid */
785     ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_MESH_URI_ADV_LIST          = BLE_BIT(6),             /*!< duplicate scan exceptional URI list */
786     ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_ALL_LIST                   = 0xFFFF,                 /*!< duplicate scan exceptional all list */
787 } esp_duplicate_scan_exceptional_list_type_t;
788 
789 typedef uint8_t esp_duplicate_info_t[ESP_BD_ADDR_LEN];
790 
791 #endif //#if (BLE_42_FEATURE_SUPPORT == TRUE)
792 
793 #if (BLE_50_FEATURE_SUPPORT == TRUE)
794 #define ESP_BLE_GAP_SET_EXT_ADV_PROP_NONCONN_NONSCANNABLE_UNDIRECTED      (0 << 0) /*!< Non-Connectable and Non-Scannable Undirected advertising */
795 #define ESP_BLE_GAP_SET_EXT_ADV_PROP_CONNECTABLE                          (1 << 0) /*!< Connectable advertising */
796 #define ESP_BLE_GAP_SET_EXT_ADV_PROP_SCANNABLE                            (1 << 1) /*!< Scannable advertising */
797 #define ESP_BLE_GAP_SET_EXT_ADV_PROP_DIRECTED                             (1 << 2) /*!< Directed advertising */
798 #define ESP_BLE_GAP_SET_EXT_ADV_PROP_HD_DIRECTED                          (1 << 3) /*!< High Duty Cycle Directed Connectable advertising (<= 3.75 ms Advertising Interval) */
799 #define ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY                               (1 << 4) /*!< Use legacy advertising PDUs */
800 #define ESP_BLE_GAP_SET_EXT_ADV_PROP_ANON_ADV                             (1 << 5) /*!< Omit advertiser's address from all PDUs ("anonymous advertising") */
801 #define ESP_BLE_GAP_SET_EXT_ADV_PROP_INCLUDE_TX_PWR                       (1 << 6) /*!< Include TxPower in the extended header of the advertising PDU */
802 #define ESP_BLE_GAP_SET_EXT_ADV_PROP_MASK                                 (0x7F)   /*!< Reserved for future use */
803 
804 /*!<  If extended advertising PDU types are being used (bit 4 = 0) then:
805     The advertisement shall not be both connectable and scannable.
806     High duty cycle directed connectable advertising (<= 3.75 ms advertising interval) shall not be used (bit 3 = 0)
807 */
808 /*!< ADV_IND */
809 #define ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_IND        (ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY |\
810                                                         ESP_BLE_GAP_SET_EXT_ADV_PROP_CONNECTABLE |\
811                                                         ESP_BLE_GAP_SET_EXT_ADV_PROP_SCANNABLE)
812 /*!< ADV_DIRECT_IND (low duty cycle) */
813 #define ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_LD_DIR     (ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY |\
814                                                         ESP_BLE_GAP_SET_EXT_ADV_PROP_CONNECTABLE |\
815                                                         ESP_BLE_GAP_SET_EXT_ADV_PROP_DIRECTED)
816 /*!< ADV_DIRECT_IND (high duty cycle) */
817 #define ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_HD_DIR     (ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY |\
818                                                         ESP_BLE_GAP_SET_EXT_ADV_PROP_CONNECTABLE |\
819                                                         ESP_BLE_GAP_SET_EXT_ADV_PROP_HD_DIRECTED)
820 /*!< ADV_SCAN_IND */
821 #define ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_SCAN       (ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY |\
822                                                         ESP_BLE_GAP_SET_EXT_ADV_PROP_SCANNABLE)
823 /*!< ADV_NONCONN_IND */
824 #define ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_NONCONN    (ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY)
825 typedef uint16_t esp_ble_ext_adv_type_mask_t;
826 
827 #define ESP_BLE_GAP_PHY_1M                             1 /*!< Secondery Advertisement PHY is LE1M */
828 #define ESP_BLE_GAP_PHY_2M                             2 /*!< Secondery Advertisement PHY is LE2M */
829 #define ESP_BLE_GAP_PHY_CODED                          3 /*!< Secondery Advertisement PHY is LE Coded */
830 typedef uint8_t esp_ble_gap_phy_t;
831 
832 #define ESP_BLE_GAP_NO_PREFER_TRANSMIT_PHY     (1<<0) /*!< No Prefer TX PHY supported by controller */
833 #define ESP_BLE_GAP_NO_PREFER_RECEIVE_PHY      (1<<1) /*!< No Prefer RX PHY supported by controller */
834 typedef uint8_t esp_ble_gap_all_phys_t;
835 
836 /// Primary phy only support 1M and LE coded phy
837 #define ESP_BLE_GAP_PRI_PHY_1M     ESP_BLE_GAP_PHY_1M     /*!< Primary Phy is LE1M */
838 #define ESP_BLE_GAP_PRI_PHY_CODED  ESP_BLE_GAP_PHY_CODED  /*!< Primary Phy is LE CODED */
839 typedef uint8_t esp_ble_gap_pri_phy_t; // primary phy
840 
841 #define ESP_BLE_GAP_PHY_1M_PREF_MASK                   (1 << 0) /*!< The Host prefers use the LE1M transmitter or receiver PHY */
842 #define ESP_BLE_GAP_PHY_2M_PREF_MASK                   (1 << 1) /*!< The Host prefers use the LE2M transmitter or receiver PHY */
843 #define ESP_BLE_GAP_PHY_CODED_PREF_MASK                (1 << 2) /*!< The Host prefers use the LE CODED transmitter or receiver PHY */
844 typedef uint8_t esp_ble_gap_phy_mask_t;
845 
846 #define ESP_BLE_GAP_PHY_OPTIONS_NO_PREF                  0 /*!< The Host has no preferred coding when transmitting on the LE Coded PHY */
847 #define ESP_BLE_GAP_PHY_OPTIONS_PREF_S2_CODING           1 /*!< The Host prefers that S=2 coding be used when transmitting on the LE Coded PHY */
848 #define ESP_BLE_GAP_PHY_OPTIONS_PREF_S8_CODING           2 /*!< The Host prefers that S=8 coding be used when transmitting on the LE Coded PHY */
849 typedef uint16_t esp_ble_gap_prefer_phy_options_t;
850 
851 #define ESP_BLE_GAP_EXT_SCAN_CFG_UNCODE_MASK           0x01 /*!< Scan Advertisements on the LE1M PHY */
852 #define ESP_BLE_GAP_EXT_SCAN_CFG_CODE_MASK             0x02 /*!< Scan advertisements on the LE coded PHY */
853 typedef uint8_t esp_ble_ext_scan_cfg_mask_t;
854 
855 /// Advertising data
856 #define ESP_BLE_GAP_EXT_ADV_DATA_COMPLETE              0x00 /*!< extended advertising data compete */
857 #define ESP_BLE_GAP_EXT_ADV_DATA_INCOMPLETE            0x01 /*!< extended advertising data incomplete */
858 #define ESP_BLE_GAP_EXT_ADV_DATA_TRUNCATED             0x02 /*!< extended advertising data truncated mode */
859 typedef uint8_t esp_ble_gap_ext_adv_data_status_t;
860 
861 /// Advertising SYNC policy
862 #define ESP_BLE_GAP_SYNC_POLICY_BY_ADV_INFO       0 /*!< sync policy by advertising info */
863 #define ESP_BLE_GAP_SYNC_POLICY_BY_PERIODIC_LIST  1 /*!< periodic advertising sync policy */
864 typedef uint8_t esp_ble_gap_sync_t;
865 
866 /// Advertising report
867 #define ESP_BLE_ADV_REPORT_EXT_ADV_IND                    (1<<0) /*!< advertising report with extended advertising indication type */
868 #define ESP_BLE_ADV_REPORT_EXT_SCAN_IND                   (1<<1) /*!< advertising report with extended scan indication type */
869 #define ESP_BLE_ADV_REPORT_EXT_DIRECT_ADV                 (1<<2) /*!< advertising report with extended direct advertising indication type */
870 #define ESP_BLE_ADV_REPORT_EXT_SCAN_RSP                   (1<<3) /*!< advertising report with extended scan response indication type */
871 
872 /*!< Bluetooth 5.0, Vol 2, Part E, 7.7.65.13 */
873 #define ESP_BLE_LEGACY_ADV_TYPE_IND                       (0x13) /*!< advertising report with legacy advertising indication type */
874 #define ESP_BLE_LEGACY_ADV_TYPE_DIRECT_IND                (0x15) /*!< advertising report with legacy direct indication type */
875 #define ESP_BLE_LEGACY_ADV_TYPE_SCAN_IND                  (0x12) /*!< advertising report with legacy scan indication type */
876 #define ESP_BLE_LEGACY_ADV_TYPE_NONCON_IND                (0x10) /*!< advertising report with legacy non connectable indication type */
877 #define ESP_BLE_LEGACY_ADV_TYPE_SCAN_RSP_TO_ADV_IND       (0x1b) /*!< advertising report with legacy scan response indication type */
878 #define ESP_BLE_LEGACY_ADV_TYPE_SCAN_RSP_TO_ADV_SCAN_IND  (0x1a) /*!< advertising report with legacy advertising with scan response indication type */
879 
880 typedef uint8_t esp_ble_gap_adv_type_t;
881 
882 /// Extend advertising tx power, range: [-127, +126] dBm
883 #define EXT_ADV_TX_PWR_NO_PREFERENCE                      (127) /*!< host has no preference for tx power */
884 
885 
886 /// max number of advertising sets to enable or disable
887 #define EXT_ADV_NUM_SETS_MAX                              (10) /*!< max evt instance num */
888 
889 /**
890 * @brief ext adv parameters
891 */
892 typedef struct {
893     esp_ble_ext_adv_type_mask_t type;   /*!< ext adv type */
894     uint32_t interval_min;              /*!< ext adv minimum interval */
895     uint32_t interval_max;              /*!< ext adv maximum interval */
896     esp_ble_adv_channel_t channel_map;  /*!< ext adv channel map */
897     esp_ble_addr_type_t own_addr_type;  /*!< ext adv own address type */
898     esp_ble_addr_type_t peer_addr_type; /*!< ext adv peer address type */
899     esp_bd_addr_t peer_addr;            /*!< ext adv peer address */
900     esp_ble_adv_filter_t filter_policy; /*!< ext adv filter policy */
901     int8_t tx_power;                    /*!< ext adv tx power */
902     esp_ble_gap_pri_phy_t primary_phy;  /*!< ext adv primary phy */
903     uint8_t max_skip;                   /*!< ext adv maximum skip */
904     esp_ble_gap_phy_t secondary_phy;    /*!< ext adv secondary phy */
905     uint8_t sid;                        /*!< ext adv sid */
906     bool scan_req_notif;                /*!< ext adv scan request event notify */
907 } esp_ble_gap_ext_adv_params_t;
908 
909 /**
910 * @brief ext scan config
911 */
912 typedef struct {
913     esp_ble_scan_type_t scan_type; /*!< ext scan type */
914     uint16_t scan_interval;        /*!< ext scan interval */
915     uint16_t scan_window;          /*!< ext scan window */
916 } esp_ble_ext_scan_cfg_t;
917 
918 /**
919 * @brief ext scan parameters
920 */
921 typedef struct {
922     esp_ble_addr_type_t own_addr_type;        /*!< ext scan own address type */
923     esp_ble_scan_filter_t filter_policy;      /*!< ext scan filter policy */
924     esp_ble_scan_duplicate_t  scan_duplicate; /*!< ext scan duplicate scan */
925     esp_ble_ext_scan_cfg_mask_t cfg_mask;     /*!< ext scan config mask */
926     esp_ble_ext_scan_cfg_t uncoded_cfg;       /*!< ext scan uncoded config parameters */
927     esp_ble_ext_scan_cfg_t coded_cfg;         /*!< ext scan coded config parameters */
928 } esp_ble_ext_scan_params_t;
929 
930 /**
931 * @brief create extend connection parameters
932 */
933 typedef struct {
934     uint16_t scan_interval;       /*!< init scan interval */
935     uint16_t scan_window;         /*!< init scan window */
936     uint16_t interval_min;        /*!< minimum interval */
937     uint16_t interval_max;        /*!< maximum interval */
938     uint16_t latency;             /*!< ext scan type */
939     uint16_t supervision_timeout; /*!< connection supervision timeout */
940     uint16_t min_ce_len;          /*!< minimum ce length */
941     uint16_t max_ce_len;          /*!< maximum ce length */
942 } esp_ble_gap_conn_params_t;
943 
944 /**
945 * @brief extend adv enable parameters
946 */
947 typedef struct {
948     uint8_t instance;        /*!< advertising handle */
949     int duration;            /*!< advertising duration */
950     int max_events;          /*!< maximum number of extended advertising events */
951 } esp_ble_gap_ext_adv_t;
952 
953 /**
954 * @brief periodic adv parameters
955 */
956 typedef struct {
957     uint16_t interval_min;     /*!< periodic advertising minimum interval */
958     uint16_t interval_max;     /*!< periodic advertising maximum interval */
959     uint8_t  properties;       /*!< periodic advertising properties */
960 } esp_ble_gap_periodic_adv_params_t;
961 
962 /**
963 * @brief periodic adv sync parameters
964 */
965 typedef struct {
966     esp_ble_gap_sync_t filter_policy;       /*!< Configures the filter policy for periodic advertising sync:
967                                                  0: Use Advertising SID, Advertiser Address Type, and Advertiser Address parameters to determine the advertiser to listen to.
968                                                  1: Use the Periodic Advertiser List to determine the advertiser to listen to. */
969     #if (CONFIG_BT_BLE_FEAT_CREATE_SYNC_ENH)
970     esp_ble_gap_sync_t reports_disabled;    /*!< Supported only by esp32c2, esp32c6, and esp32h2; can be set by menuconfig:
971                                                  0: Reporting initially enabled.
972                                                  1: Reporting initially disabled. */
973     esp_ble_gap_sync_t filter_duplicates;   /*!< Supported only by esp32c2, esp32c6, and esp32h2; can be set by menuconfig:
974                                                  0: Duplicate filtering initially disabled.
975                                                  1: Duplicate filtering initially enabled. */
976     #endif
977     uint8_t sid;                            /*!< SID of the periodic advertising */
978     esp_ble_addr_type_t addr_type;          /*!< Address type of the periodic advertising */
979     esp_bd_addr_t addr;                     /*!< Address of the periodic advertising */
980     uint16_t skip;                          /*!< Maximum number of periodic advertising events that can be skipped */
981     uint16_t sync_timeout;                  /*!< Synchronization timeout */
982 } esp_ble_gap_periodic_adv_sync_params_t;
983 
984 /**
985 * @brief extend adv report parameters
986 */
987 typedef struct {
988     // uint8_t props;
989     // uint8_t legacy_event_type;
990     esp_ble_gap_adv_type_t event_type;              /*!< extend advertising type */
991     uint8_t addr_type;                              /*!< extend advertising address type */
992     esp_bd_addr_t addr;                             /*!< extend advertising address */
993     esp_ble_gap_pri_phy_t primary_phy;              /*!< extend advertising primary phy */
994     esp_ble_gap_phy_t secondly_phy;                 /*!< extend advertising secondary phy */
995     uint8_t sid;                                    /*!< extend advertising sid */
996     uint8_t tx_power;                               /*!< extend advertising tx power */
997     int8_t rssi;                                    /*!< extend advertising rssi */
998     uint16_t per_adv_interval;                      /*!< periodic advertising interval */
999     uint8_t dir_addr_type;                          /*!< direct address type */
1000     esp_bd_addr_t dir_addr;                         /*!< direct address */
1001     esp_ble_gap_ext_adv_data_status_t data_status;  /*!< data type */
1002     uint8_t adv_data_len;                           /*!< extend advertising data length */
1003     uint8_t adv_data[251];                          /*!< extend advertising data */
1004 } esp_ble_gap_ext_adv_report_t;
1005 
1006 /**
1007 * @brief periodic adv report parameters
1008 */
1009 typedef struct {
1010     uint16_t sync_handle;                          /*!< periodic advertising train handle */
1011     uint8_t tx_power;                              /*!< periodic advertising tx power*/
1012     int8_t rssi;                                   /*!< periodic advertising rssi */
1013     esp_ble_gap_ext_adv_data_status_t data_status; /*!< periodic advertising data type*/
1014     uint8_t data_length;                           /*!< periodic advertising data length */
1015     uint8_t data[251];                             /*!< periodic advertising data */
1016 } esp_ble_gap_periodic_adv_report_t;
1017 
1018 /**
1019 * @brief perodic adv sync establish parameters
1020 */
1021 typedef struct {
1022     uint8_t status;                               /*!< periodic advertising sync status */
1023     uint16_t sync_handle;                         /*!< periodic advertising train handle */
1024     uint8_t sid;                                  /*!< periodic advertising sid */
1025     esp_ble_addr_type_t addr_type;                /*!< periodic advertising address type */
1026     esp_bd_addr_t adv_addr;                       /*!< periodic advertising address */
1027     esp_ble_gap_phy_t adv_phy;                    /*!< periodic advertising adv phy type */
1028     uint16_t period_adv_interval;                 /*!< periodic advertising interval */
1029     uint8_t adv_clk_accuracy;                     /*!< periodic advertising clock accuracy */
1030 } esp_ble_gap_periodic_adv_sync_estab_t;
1031 
1032 /**
1033 * @brief DTM TX parameters
1034 */
1035 typedef struct
1036 {
1037     uint8_t                     tx_channel;            /*!<  channel for sending test data, tx_channel = (Frequency -2402)/2, tx_channel range:0x00-0x27, Frequency range: 2402 MHz to 2480 MHz */
1038     uint8_t                     len_of_data;           /*!<  length in bytes of payload data in each packet */
1039     esp_ble_dtm_pkt_payload_t   pkt_payload;           /*!<  packet payload type. value range: 0x00-0x07 */
1040     esp_ble_gap_phy_t           phy;                   /*!<  the phy type used by the transmitter, coded phy with S=2:0x04 */
1041 } esp_ble_dtm_enh_tx_t;
1042 
1043 /**
1044 * @brief DTM RX parameters
1045 */
1046 typedef struct
1047 {
1048     uint8_t             rx_channel;            /*!<  channel for test data reception, rx_channel = (Frequency -2402)/2, tx_channel range:0x00-0x27, Frequency range: 2402 MHz to 2480 MHz */
1049     esp_ble_gap_phy_t   phy;                   /*!<  the phy type used by the receiver, 1M phy: 0x01, 2M phy:0x02, coded phy:0x03 */
1050     uint8_t             modulation_idx;        /*!<  modulation index, 0x00:standard modulation index, 0x01:stable modulation index */
1051 } esp_ble_dtm_enh_rx_t;
1052 
1053 #endif //#if (BLE_50_FEATURE_SUPPORT == TRUE)
1054 
1055 #if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
1056 /// Periodic advertising sync trans mode
1057 #define ESP_BLE_GAP_PAST_MODE_NO_SYNC_EVT                 (0x00) /*!< No attempt is made to sync and no periodic adv sync transfer received event */
1058 #define ESP_BLE_GAP_PAST_MODE_NO_REPORT_EVT               (0x01) /*!< An periodic adv sync transfer received event and no periodic adv report events */
1059 #define ESP_BLE_GAP_PAST_MODE_DUP_FILTER_DISABLED         (0x02) /*!< Periodic adv report events will be enabled with duplicate filtering disabled */
1060 #define ESP_BLE_GAP_PAST_MODE_DUP_FILTER_ENABLED          (0x03) /*!< Periodic adv report events will be enabled with duplicate filtering enabled */
1061 typedef uint8_t esp_ble_gap_past_mode_t;
1062 
1063 /**
1064 * @brief periodic adv sync transfer parameters
1065 */
1066 typedef struct {
1067     esp_ble_gap_past_mode_t mode;       /*!< periodic advertising sync transfer mode */
1068     uint16_t skip;                      /*!< the number of periodic advertising packets that can be skipped */
1069     uint16_t sync_timeout;              /*!< synchronization timeout for the periodic advertising train */
1070     uint8_t cte_type;                   /*!< periodic advertising sync transfer CET type */
1071 } esp_ble_gap_past_params_t;
1072 #endif // #if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
1073 
1074 typedef enum{
1075     ESP_BLE_NETWORK_PRIVACY_MODE    = 0X00,    /*!< Network Privacy Mode for peer device (default) */
1076     ESP_BLE_DEVICE_PRIVACY_MODE     = 0X01,    /*!< Device Privacy Mode for peer device */
1077 } esp_ble_privacy_mode_t;
1078 
1079 /**
1080  * @brief Gap callback parameters union
1081  */
1082 typedef union {
1083     /**
1084      * @brief ESP_GAP_BLE_GET_DEV_NAME_COMPLETE_EVT
1085      */
1086     struct ble_get_dev_name_cmpl_evt_param {
1087         esp_bt_status_t status;                     /*!< Indicate the get device name success status */
1088         char *name;                                 /*!< Name of bluetooth device */
1089     } get_dev_name_cmpl;                            /*!< Event parameter of ESP_GAP_BLE_GET_DEV_NAME_COMPLETE_EVT */
1090 #if (BLE_42_FEATURE_SUPPORT == TRUE)
1091     /**
1092      * @brief ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT
1093      */
1094     struct ble_adv_data_cmpl_evt_param {
1095         esp_bt_status_t status;                     /*!< Indicate the set advertising data operation success status */
1096     } adv_data_cmpl;                                /*!< Event parameter of ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT */
1097     /**
1098      * @brief ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT
1099      */
1100     struct ble_scan_rsp_data_cmpl_evt_param {
1101         esp_bt_status_t status;                     /*!< Indicate the set scan response data operation success status */
1102     } scan_rsp_data_cmpl;                           /*!< Event parameter of ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT */
1103     /**
1104      * @brief ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT
1105      */
1106     struct ble_scan_param_cmpl_evt_param {
1107         esp_bt_status_t status;                     /*!< Indicate the set scan param operation success status */
1108     } scan_param_cmpl;                              /*!< Event parameter of ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT */
1109     /**
1110      * @brief ESP_GAP_BLE_SCAN_RESULT_EVT
1111      */
1112     struct ble_scan_result_evt_param {
1113         esp_gap_search_evt_t search_evt;            /*!< Search event type */
1114         esp_bd_addr_t bda;                          /*!< Bluetooth device address which has been searched */
1115         esp_bt_dev_type_t dev_type;                 /*!< Device type */
1116         esp_ble_addr_type_t ble_addr_type;          /*!< Ble device address type */
1117         esp_ble_evt_type_t ble_evt_type;            /*!< Ble scan result event type */
1118         int rssi;                                   /*!< Searched device's RSSI */
1119         uint8_t  ble_adv[ESP_BLE_ADV_DATA_LEN_MAX + ESP_BLE_SCAN_RSP_DATA_LEN_MAX];     /*!< Received EIR */
1120         int flag;                                   /*!< Advertising data flag bit */
1121         int num_resps;                              /*!< Scan result number */
1122         uint8_t adv_data_len;                       /*!< Adv data length */
1123         uint8_t scan_rsp_len;                       /*!< Scan response length */
1124         uint32_t num_dis;                          /*!< The number of discard packets */
1125     } scan_rst;                                     /*!< Event parameter of ESP_GAP_BLE_SCAN_RESULT_EVT */
1126     /**
1127      * @brief ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT
1128      */
1129     struct ble_adv_data_raw_cmpl_evt_param {
1130         esp_bt_status_t status;                     /*!< Indicate the set raw advertising data operation success status */
1131     } adv_data_raw_cmpl;                            /*!< Event parameter of ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT */
1132     /**
1133      * @brief ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT
1134      */
1135     struct ble_scan_rsp_data_raw_cmpl_evt_param {
1136         esp_bt_status_t status;                     /*!< Indicate the set raw advertising data operation success status */
1137     } scan_rsp_data_raw_cmpl;                       /*!< Event parameter of ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT */
1138     /**
1139      * @brief ESP_GAP_BLE_ADV_START_COMPLETE_EVT
1140      */
1141     struct ble_adv_start_cmpl_evt_param {
1142         esp_bt_status_t status;                     /*!< Indicate advertising start operation success status */
1143     } adv_start_cmpl;                               /*!< Event parameter of ESP_GAP_BLE_ADV_START_COMPLETE_EVT */
1144     /**
1145      * @brief ESP_GAP_BLE_SCAN_START_COMPLETE_EVT
1146      */
1147     struct ble_scan_start_cmpl_evt_param {
1148         esp_bt_status_t status;                     /*!< Indicate scan start operation success status */
1149     } scan_start_cmpl;                              /*!< Event parameter of ESP_GAP_BLE_SCAN_START_COMPLETE_EVT */
1150 #endif //#if (BLE_42_FEATURE_SUPPORT == TRUE)
1151     esp_ble_sec_t ble_security;                     /*!< ble gap security union type */
1152 #if (BLE_42_FEATURE_SUPPORT == TRUE)
1153     /**
1154      * @brief ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT
1155      */
1156     struct ble_scan_stop_cmpl_evt_param {
1157         esp_bt_status_t status;                     /*!< Indicate scan stop operation success status */
1158     } scan_stop_cmpl;                               /*!< Event parameter of ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT */
1159     /**
1160      * @brief ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT
1161      */
1162     struct ble_adv_stop_cmpl_evt_param {
1163         esp_bt_status_t status;                     /*!< Indicate adv stop operation success status */
1164     } adv_stop_cmpl;                                /*!< Event parameter of ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT */
1165     /**
1166      * @brief ESP_GAP_BLE_ADV_CLEAR_COMPLETE_EVT
1167      */
1168     struct ble_adv_clear_cmpl_evt_param {
1169         esp_bt_status_t status;                     /*!< Indicate adv clear operation success status */
1170     } adv_clear_cmpl;                                /*!< Event parameter of ESP_GAP_BLE_ADV_CLEAR_COMPLETE_EVT */
1171 #endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
1172     /**
1173      * @brief ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT
1174      */
1175     struct ble_set_rand_cmpl_evt_param {
1176         esp_bt_status_t status;                     /*!< Indicate set static rand address operation success status */
1177     } set_rand_addr_cmpl;                           /*!< Event parameter of ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT */
1178     /**
1179      * @brief ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT
1180      */
1181     struct ble_update_conn_params_evt_param {
1182         esp_bt_status_t status;                    /*!< Indicate update connection parameters success status */
1183         esp_bd_addr_t bda;                         /*!< Bluetooth device address */
1184         uint16_t min_int;                          /*!< Minimum connection interval. If the master initiates the connection parameter update, this value is not applicable for the slave and will be set to zero. */
1185         uint16_t max_int;                          /*!< Maximum connection interval. If the master initiates the connection parameter update, this value is not applicable for the slave and will be set to zero. */
1186         uint16_t latency;                          /*!< Slave latency for the connection in number of connection events. Range: 0x0000 to 0x01F3 */
1187         uint16_t conn_int;                         /*!< Current connection interval in milliseconds, calculated as N × 1.25 ms */
1188         uint16_t timeout;                          /*!< Supervision timeout for the LE Link. Range: 0x000A to 0x0C80.
1189                                                     This value is calculated as N × 10 ms */
1190     } update_conn_params;                          /*!< Event parameter for ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT */
1191     /**
1192      * @brief ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT
1193      */
1194     struct ble_pkt_data_length_cmpl_evt_param {
1195         esp_bt_status_t status;                     /*!< Indicate the set pkt data length operation success status */
1196         esp_ble_pkt_data_length_params_t params;    /*!<  pkt data length value */
1197     } pkt_data_length_cmpl;                          /*!< Event parameter of ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT */
1198     /**
1199      * @brief ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT
1200      */
1201     struct ble_local_privacy_cmpl_evt_param {
1202         esp_bt_status_t status;                     /*!< Indicate the set local privacy operation success status */
1203     } local_privacy_cmpl;                           /*!< Event parameter of ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT */
1204     /**
1205      * @brief ESP_GAP_BLE_SET_RPA_TIMEOUT_COMPLETE_EVT
1206      */
1207     struct ble_rpa_timeout_cmpl_evt_param {
1208         esp_bt_status_t status;                     /*!< Indicate the set RPA timeout operation success status */
1209     } set_rpa_timeout_cmpl;                         /*!< Event parameter of ESP_GAP_BLE_SET_RPA_TIMEOUT_COMPLETE_EVT */
1210     /**
1211      * @brief ESP_GAP_BLE_ADD_DEV_TO_RESOLVING_LIST_COMPLETE_EVT
1212      */
1213     struct ble_add_dev_to_resolving_list_cmpl_evt_param {
1214         esp_bt_status_t status;         /*!< Indicates the success status of adding a device to the resolving list */
1215     } add_dev_to_resolving_list_cmpl;  /*!< Event parameter of ESP_GAP_BLE_ADD_DEV_TO_RESOLVING_LIST_COMPLETE_EVT */
1216 
1217     /**
1218      * @brief ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT
1219      */
1220     struct ble_remove_bond_dev_cmpl_evt_param {
1221         esp_bt_status_t status;                     /*!< Indicate the remove bond device operation success status */
1222         esp_bd_addr_t bd_addr;                      /*!< The device address which has been remove from the bond list */
1223     } remove_bond_dev_cmpl;                         /*!< Event parameter of ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT */
1224     /**
1225      * @brief ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT
1226      */
1227     struct ble_clear_bond_dev_cmpl_evt_param {
1228         esp_bt_status_t status;                     /*!< Indicate the clear bond device operation success status */
1229     } clear_bond_dev_cmpl;                          /*!< Event parameter of ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT */
1230     /**
1231      * @brief ESP_GAP_BLE_GET_BOND_DEV_COMPLETE_EVT
1232      */
1233     struct ble_get_bond_dev_cmpl_evt_param {
1234         esp_bt_status_t status;                     /*!< Indicate the get bond device operation success status */
1235         uint8_t dev_num;                            /*!< Indicate the get number device in the bond list */
1236         esp_ble_bond_dev_t *bond_dev;               /*!< the pointer to the bond device Structure */
1237     } get_bond_dev_cmpl;                            /*!< Event parameter of ESP_GAP_BLE_GET_BOND_DEV_COMPLETE_EVT */
1238     /**
1239      * @brief ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT
1240      */
1241     struct ble_read_rssi_cmpl_evt_param {
1242         esp_bt_status_t status;                     /*!< Indicate the read adv tx power operation success status */
1243         int8_t rssi;                                /*!< The ble remote device rssi value, the range is from -127 to 20, the unit is dbm,
1244                                                          if the RSSI cannot be read, the RSSI metric shall be set to 127. */
1245         esp_bd_addr_t remote_addr;                  /*!< The remote device address */
1246     } read_rssi_cmpl;                               /*!< Event parameter of ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT */
1247     /**
1248      * @brief ESP_GAP_BLE_UPDATE_WHITELIST_COMPLETE_EVT
1249      */
1250     struct ble_update_whitelist_cmpl_evt_param {
1251         esp_bt_status_t status;                     /*!< Indicate the add or remove whitelist operation success status */
1252         esp_ble_wl_operation_t wl_operation;        /*!< The value is ESP_BLE_WHITELIST_ADD if add address to whitelist operation success, ESP_BLE_WHITELIST_REMOVE if remove address from the whitelist operation success */
1253     } update_whitelist_cmpl;                        /*!< Event parameter of ESP_GAP_BLE_UPDATE_WHITELIST_COMPLETE_EVT */
1254 #if (BLE_42_FEATURE_SUPPORT == TRUE)
1255     /**
1256      * @brief ESP_GAP_BLE_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_COMPLETE_EVT
1257      */
1258     struct ble_update_duplicate_exceptional_list_cmpl_evt_param {
1259         esp_bt_status_t status;                     /*!< Indicate update duplicate scan exceptional list operation success status */
1260         uint8_t         subcode;                    /*!< Define in esp_bt_duplicate_exceptional_subcode_type_t */
1261         uint16_t         length;                     /*!< The length of device_info */
1262         esp_duplicate_info_t device_info;           /*!< device information, when subcode is ESP_BLE_DUPLICATE_EXCEPTIONAL_LIST_CLEAN, the value is invalid */
1263     } update_duplicate_exceptional_list_cmpl;       /*!< Event parameter of ESP_GAP_BLE_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_COMPLETE_EVT */
1264 #endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
1265     /**
1266      * @brief ESP_GAP_BLE_SET_CHANNELS_EVT
1267       */
1268     struct ble_set_channels_evt_param {
1269         esp_bt_status_t stat;                       /*!< BLE set channel status */
1270     } ble_set_channels;                             /*!< Event parameter of ESP_GAP_BLE_SET_CHANNELS_EVT */
1271 
1272 #if (BLE_50_FEATURE_SUPPORT == TRUE)
1273     /**
1274      * @brief ESP_GAP_BLE_READ_PHY_COMPLETE_EVT
1275      */
1276     struct ble_read_phy_cmpl_evt_param {
1277         esp_bt_status_t status;                   /*!< read phy complete status */
1278         esp_bd_addr_t bda;                        /*!< read phy address */
1279         esp_ble_gap_phy_t tx_phy;                 /*!< tx phy type */
1280         esp_ble_gap_phy_t rx_phy;                 /*!< rx phy type */
1281     } read_phy;                                   /*!< Event parameter of ESP_GAP_BLE_READ_PHY_COMPLETE_EVT */
1282     /**
1283      * @brief ESP_GAP_BLE_SET_PREFERRED_DEFAULT_PHY_COMPLETE_EVT
1284      */
1285     struct ble_set_perf_def_phy_cmpl_evt_param {
1286         esp_bt_status_t status;                     /*!< Indicate perf default phy set status */
1287     } set_perf_def_phy;                             /*!< Event parameter of ESP_GAP_BLE_SET_PREFERRED_DEFAULT_PHY_COMPLETE_EVT */
1288     /**
1289      * @brief ESP_GAP_BLE_SET_PREFERRED_PHY_COMPLETE_EVT
1290      */
1291     struct ble_set_perf_phy_cmpl_evt_param {
1292         esp_bt_status_t status;                     /*!< Indicate perf phy set status */
1293     } set_perf_phy;                                 /*!< Event parameter of ESP_GAP_BLE_SET_PREFERRED_PHY_COMPLETE_EVT */
1294     /**
1295      * @brief ESP_GAP_BLE_EXT_ADV_SET_RAND_ADDR_COMPLETE_EVT
1296      */
1297     struct ble_ext_adv_set_rand_addr_cmpl_evt_param {
1298         esp_bt_status_t status;                      /*!< Indicate extend advertising random address set status */
1299         uint8_t instance;                            /*!< extend advertising handle */
1300     } ext_adv_set_rand_addr;                         /*!< Event parameter of ESP_GAP_BLE_EXT_ADV_SET_RAND_ADDR_COMPLETE_EVT */
1301     /**
1302      * @brief ESP_GAP_BLE_EXT_ADV_SET_PARAMS_COMPLETE_EVT
1303      */
1304     struct ble_ext_adv_set_params_cmpl_evt_param {
1305         esp_bt_status_t status;                     /*!< Indicate extend advertising parameters set status */
1306         uint8_t instance;                           /*!< extend advertising handle */
1307     } ext_adv_set_params;                           /*!< Event parameter of ESP_GAP_BLE_EXT_ADV_SET_PARAMS_COMPLETE_EVT */
1308     /**
1309      * @brief ESP_GAP_BLE_EXT_ADV_DATA_SET_COMPLETE_EVT
1310      */
1311      struct ble_ext_adv_data_set_cmpl_evt_param {
1312         esp_bt_status_t status;                      /*!< Indicate extend advertising data set status */
1313         uint8_t instance;                            /*!< extend advertising handle */
1314     } ext_adv_data_set;                              /*!< Event parameter of ESP_GAP_BLE_EXT_ADV_DATA_SET_COMPLETE_EVT */
1315     /**
1316      * @brief ESP_GAP_BLE_EXT_SCAN_RSP_DATA_SET_COMPLETE_EVT
1317      */
1318     struct ble_ext_adv_scan_rsp_set_cmpl_evt_param {
1319         esp_bt_status_t status;                      /*!< Indicate extend advertising scan response data set status */
1320         uint8_t instance;                            /*!< extend advertising handle */
1321     } scan_rsp_set;                                  /*!< Event parameter of ESP_GAP_BLE_EXT_SCAN_RSP_DATA_SET_COMPLETE_EVT */
1322     /**
1323      * @brief ESP_GAP_BLE_EXT_ADV_START_COMPLETE_EVT
1324      */
1325     struct ble_ext_adv_start_cmpl_evt_param {
1326         esp_bt_status_t status;                     /*!< Indicate advertising start operation success status */
1327         uint8_t instance_num;                       /*!< extend advertising handle numble*/
1328         uint8_t instance[EXT_ADV_NUM_SETS_MAX];                       /*!< extend advertising handle list*/
1329     } ext_adv_start;                                /*!< Event parameter of ESP_GAP_BLE_EXT_ADV_START_COMPLETE_EVT */
1330     /**
1331      * @brief ESP_GAP_BLE_EXT_ADV_STOP_COMPLETE_EVT
1332      */
1333     struct ble_ext_adv_stop_cmpl_evt_param {
1334         esp_bt_status_t status;                     /*!< Indicate advertising stop operation success status */
1335         uint8_t instance_num;                       /*!< extend advertising handle numble*/
1336         uint8_t instance[EXT_ADV_NUM_SETS_MAX];                       /*!< extend advertising handle list*/
1337     } ext_adv_stop;                                 /*!< Event parameter of ESP_GAP_BLE_EXT_ADV_STOP_COMPLETE_EVT */
1338     /**
1339      * @brief ESP_GAP_BLE_EXT_ADV_SET_REMOVE_COMPLETE_EVT
1340      */
1341     struct ble_ext_adv_set_remove_cmpl_evt_param {
1342         esp_bt_status_t status;                     /*!< Indicate advertising stop operation success status */
1343         uint8_t instance;                           /*!< extend advertising handle */
1344     } ext_adv_remove;                               /*!< Event parameter of ESP_GAP_BLE_EXT_ADV_SET_REMOVE_COMPLETE_EVT */
1345     /**
1346      * @brief ESP_GAP_BLE_EXT_ADV_SET_CLEAR_COMPLETE_EVT
1347      */
1348     struct ble_ext_adv_set_clear_cmpl_evt_param {
1349         esp_bt_status_t status;                     /*!< Indicate advertising stop operation success status */
1350         uint8_t instance;                           /*!< extend advertising handle */
1351     } ext_adv_clear;                                /*!< Event parameter of ESP_GAP_BLE_EXT_ADV_SET_CLEAR_COMPLETE_EVT */
1352     /**
1353      * @brief ESP_GAP_BLE_PERIODIC_ADV_SET_PARAMS_COMPLETE_EVT
1354      */
1355     struct ble_periodic_adv_set_params_cmpl_param {
1356         esp_bt_status_t status;                    /*!< Indicate periodic advertisingparameters set status */
1357         uint8_t instance;                          /*!< extend advertising handle */
1358     } peroid_adv_set_params;                       /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_SET_PARAMS_COMPLETE_EVT */
1359     /**
1360      * @brief ESP_GAP_BLE_PERIODIC_ADV_DATA_SET_COMPLETE_EVT
1361      */
1362     struct ble_periodic_adv_data_set_cmpl_param {
1363         esp_bt_status_t status;                    /*!< Indicate periodic advertising data set status */
1364         uint8_t instance;                           /*!< extend advertising handle */
1365     } period_adv_data_set;                         /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_DATA_SET_COMPLETE_EVT */
1366     /**
1367      * @brief ESP_GAP_BLE_PERIODIC_ADV_START_COMPLETE_EVT
1368      */
1369     struct ble_periodic_adv_start_cmpl_param {
1370         esp_bt_status_t status;                   /*!< Indicate periodic advertising start status */
1371         uint8_t instance;                         /*!< extend advertising handle */
1372     } period_adv_start;                           /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_START_COMPLETE_EVT */
1373     /**
1374      * @brief ESP_GAP_BLE_PERIODIC_ADV_STOP_COMPLETE_EVT
1375      */
1376     struct ble_periodic_adv_stop_cmpl_param {
1377         esp_bt_status_t status;                  /*!< Indicate periodic advertising stop status */
1378         uint8_t instance;                        /*!< extend advertising handle */
1379     } period_adv_stop;                           /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_STOP_COMPLETE_EVT */
1380     /**
1381      * @brief ESP_GAP_BLE_PERIODIC_ADV_CREATE_SYNC_COMPLETE_EVT
1382      */
1383     struct ble_period_adv_create_sync_cmpl_param {
1384         esp_bt_status_t status;                  /*!< Indicate periodic advertising create sync status */
1385     } period_adv_create_sync;                    /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_CREATE_SYNC_COMPLETE_EVT */
1386     /**
1387      * @brief ESP_GAP_BLE_PERIODIC_ADV_SYNC_CANCEL_COMPLETE_EVT
1388      */
1389     struct ble_period_adv_sync_cancel_cmpl_param {
1390         esp_bt_status_t status;                  /*!< Indicate periodic advertising sync cancel status */
1391     } period_adv_sync_cancel;                    /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_SYNC_CANCEL_COMPLETE_EVT */
1392      /**
1393      * @brief ESP_GAP_BLE_PERIODIC_ADV_SYNC_TERMINATE_COMPLETE_EVT
1394      */
1395     struct ble_period_adv_sync_terminate_cmpl_param {
1396         esp_bt_status_t status;                  /*!< Indicate periodic advertising sync terminate status */
1397     } period_adv_sync_term;                      /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_SYNC_TERMINATE_COMPLETE_EVT */
1398     /**
1399      * @brief ESP_GAP_BLE_PERIODIC_ADV_ADD_DEV_COMPLETE_EVT
1400      */
1401     struct ble_period_adv_add_dev_cmpl_param {
1402         esp_bt_status_t status;                 /*!< Indicate periodic advertising device list add status */
1403     } period_adv_add_dev;                       /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_ADD_DEV_COMPLETE_EVT */
1404     /**
1405      * @brief ESP_GAP_BLE_PERIODIC_ADV_REMOVE_DEV_COMPLETE_EVT
1406      */
1407     struct ble_period_adv_remove_dev_cmpl_param {
1408         esp_bt_status_t status;                /*!< Indicate periodic advertising device list remove status */
1409     } period_adv_remove_dev;                   /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_REMOVE_DEV_COMPLETE_EVT */
1410     /**
1411      * @brief ESP_GAP_BLE_PERIODIC_ADV_CLEAR_DEV_COMPLETE_EVT
1412      */
1413     struct ble_period_adv_clear_dev_cmpl_param {
1414         esp_bt_status_t status;               /*!< Indicate periodic advertising device list clean status */
1415     } period_adv_clear_dev;                   /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_CLEAR_DEV_COMPLETE_EVT */
1416     /**
1417      * @brief ESP_GAP_BLE_SET_EXT_SCAN_PARAMS_COMPLETE_EVT
1418      */
1419     struct ble_set_ext_scan_params_cmpl_param {
1420         esp_bt_status_t status;              /*!< Indicate extend advertising parameters set status */
1421     } set_ext_scan_params;                   /*!< Event parameter of ESP_GAP_BLE_SET_EXT_SCAN_PARAMS_COMPLETE_EVT */
1422     /**
1423      * @brief ESP_GAP_BLE_EXT_SCAN_START_COMPLETE_EVT
1424      */
1425     struct ble_ext_scan_start_cmpl_param {
1426         esp_bt_status_t status;             /*!< Indicate extend advertising start status */
1427     } ext_scan_start;                       /*!< Event parameter of ESP_GAP_BLE_EXT_SCAN_START_COMPLETE_EVT */
1428     /**
1429      * @brief ESP_GAP_BLE_EXT_SCAN_STOP_COMPLETE_EVT
1430      */
1431     struct ble_ext_scan_stop_cmpl_param {
1432         esp_bt_status_t status;            /*!< Indicate extend advertising stop status */
1433     } ext_scan_stop;                       /*!< Event parameter of ESP_GAP_BLE_EXT_SCAN_STOP_COMPLETE_EVT */
1434     /**
1435      * @brief ESP_GAP_BLE_PREFER_EXT_CONN_PARAMS_SET_COMPLETE_EVT
1436      */
1437     struct ble_ext_conn_params_set_cmpl_param {
1438         esp_bt_status_t status;            /*!< Indicate extend connection parameters set status */
1439     } ext_conn_params_set;                 /*!< Event parameter of ESP_GAP_BLE_PREFER_EXT_CONN_PARAMS_SET_COMPLETE_EVT */
1440     /**
1441      * @brief ESP_GAP_BLE_ADV_TERMINATED_EVT
1442      */
1443     struct ble_adv_terminate_param {
1444         uint8_t status;                   /*!< Indicate adv terminate status */
1445         /*  status 0x3c indicates that advertising for a fixed duration completed or,
1446             for directed advertising, that advertising completed without a connection
1447             being created;
1448             status 0x00 indicates that advertising successfully ended with a connection being created.
1449         */
1450         uint8_t adv_instance;           /*!< extend advertising handle */
1451         uint16_t conn_idx;              /*!< connection index */
1452         uint8_t completed_event;        /*!< the number of completed extend advertising events */
1453     } adv_terminate;                    /*!< Event parameter of ESP_GAP_BLE_ADV_TERMINATED_EVT */
1454     /**
1455      * @brief ESP_GAP_BLE_SCAN_REQ_RECEIVED_EVT
1456      */
1457     struct ble_scan_req_received_param {
1458         uint8_t adv_instance;                /*!< extend advertising handle */
1459         esp_ble_addr_type_t scan_addr_type;  /*!< scanner address type */
1460         esp_bd_addr_t scan_addr;             /*!< scanner address */
1461     } scan_req_received;                     /*!< Event parameter of ESP_GAP_BLE_SCAN_REQ_RECEIVED_EVT */
1462     /**
1463      * @brief ESP_GAP_BLE_CHANNEL_SELECT_ALGORITHM_EVT
1464      */
1465     struct ble_channel_sel_alg_param {
1466         uint16_t conn_handle;              /*!< connection handle */
1467         uint8_t channel_sel_alg;           /*!< channel selection algorithm */
1468     } channel_sel_alg;                     /*!< Event parameter of ESP_GAP_BLE_CHANNEL_SELECT_ALGORITHM_EVT */
1469     /**
1470      * @brief ESP_GAP_BLE_PERIODIC_ADV_SYNC_LOST_EVT
1471      */
1472     struct ble_periodic_adv_sync_lost_param {
1473         uint16_t sync_handle;                 /*!< sync handle */
1474     } periodic_adv_sync_lost;                 /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_SYNC_LOST_EVT */
1475     /**
1476      * @brief ESP_GAP_BLE_PERIODIC_ADV_SYNC_ESTAB_EVT
1477      */
1478     struct ble_periodic_adv_sync_estab_param {
1479         uint8_t status;                      /*!< periodic advertising sync status */
1480         uint16_t sync_handle;                /*!< periodic advertising sync handle */
1481         uint8_t sid;                         /*!< periodic advertising sid */
1482         esp_ble_addr_type_t adv_addr_type;   /*!< periodic advertising address type */
1483         esp_bd_addr_t adv_addr;              /*!< periodic advertising address */
1484         esp_ble_gap_phy_t adv_phy;           /*!< periodic advertising phy type */
1485         uint16_t period_adv_interval;        /*!< periodic advertising interval */
1486         uint8_t adv_clk_accuracy;            /*!< periodic advertising clock accuracy */
1487     } periodic_adv_sync_estab;               /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_SYNC_ESTAB_EVT */
1488     /**
1489      * @brief ESP_GAP_BLE_PHY_UPDATE_COMPLETE_EVT
1490      */
1491     struct ble_phy_update_cmpl_param {
1492         esp_bt_status_t status;             /*!< phy update status */
1493         esp_bd_addr_t bda;                  /*!< address */
1494         esp_ble_gap_phy_t tx_phy;           /*!< tx phy type */
1495         esp_ble_gap_phy_t rx_phy;           /*!< rx phy type */
1496     } phy_update;                           /*!< Event parameter of ESP_GAP_BLE_PHY_UPDATE_COMPLETE_EVT */
1497     /**
1498      * @brief ESP_GAP_BLE_EXT_ADV_REPORT_EVT
1499      */
1500     struct ble_ext_adv_report_param {
1501         esp_ble_gap_ext_adv_report_t params;   /*!< extend advertising report parameters */
1502     } ext_adv_report;                          /*!< Event parameter of ESP_GAP_BLE_EXT_ADV_REPORT_EVT */
1503     /**
1504      * @brief ESP_GAP_BLE_PERIODIC_ADV_REPORT_EVT
1505      */
1506     struct ble_periodic_adv_report_param {
1507         esp_ble_gap_periodic_adv_report_t params; /*!< periodic advertising report parameters */
1508     } period_adv_report;                          /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_REPORT_EVT */
1509 #endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
1510 #if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
1511     /**
1512      * @brief ESP_GAP_BLE_PERIODIC_ADV_RECV_ENABLE_COMPLETE_EVT
1513      */
1514     struct ble_periodic_adv_recv_enable_cmpl_param {
1515         esp_bt_status_t status;             /*!< Set periodic advertising receive enable status */
1516     } period_adv_recv_enable;               /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_RECV_ENABLE_COMPLETE_EVT */
1517     /**
1518      * @brief ESP_GAP_BLE_PERIODIC_ADV_SYNC_TRANS_COMPLETE_EVT
1519      */
1520     struct ble_periodic_adv_sync_trans_cmpl_param {
1521         esp_bt_status_t status;             /*!< Periodic advertising sync transfer status */
1522         esp_bd_addr_t bda;                  /*!< The remote device address */
1523     } period_adv_sync_trans;                /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_SYNC_TRANS_COMPLETE_EVT */
1524     /**
1525      * @brief ESP_GAP_BLE_PERIODIC_ADV_SET_INFO_TRANS_COMPLETE_EVT
1526      */
1527     struct ble_periodic_adv_set_info_trans_cmpl_param {
1528         esp_bt_status_t status;             /*!< Periodic advertising set info transfer status */
1529         esp_bd_addr_t bda;                  /*!< The remote device address */
1530     } period_adv_set_info_trans;            /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_SET_INFO_TRANS_COMPLETE_EVT */
1531     /**
1532      * @brief ESP_GAP_BLE_SET_PAST_PARAMS_COMPLETE_EVT
1533      */
1534     struct ble_set_past_params_cmpl_param {
1535         esp_bt_status_t status;             /*!< Set periodic advertising sync transfer params status */
1536         esp_bd_addr_t bda;                  /*!< The remote device address */
1537     } set_past_params;                      /*!< Event parameter of ESP_GAP_BLE_SET_PAST_PARAMS_COMPLETE_EVT */
1538     /**
1539      * @brief ESP_GAP_BLE_PERIODIC_ADV_SYNC_TRANS_RECV_EVT
1540      */
1541     struct ble_periodic_adv_sync_trans_recv_param {
1542         esp_bt_status_t status;             /*!< Periodic advertising sync transfer received status */
1543         esp_bd_addr_t bda;                  /*!< The remote device address */
1544         uint16_t service_data;              /*!< The value provided by the peer device */
1545         uint16_t sync_handle;               /*!< Periodic advertising sync handle */
1546         uint8_t adv_sid;                    /*!< Periodic advertising set id */
1547         uint8_t adv_addr_type;              /*!< Periodic advertiser address type */
1548         esp_bd_addr_t adv_addr;             /*!< Periodic advertiser address */
1549         esp_ble_gap_phy_t adv_phy;          /*!< Periodic advertising PHY */
1550         uint16_t adv_interval;              /*!< Periodic advertising interval */
1551         uint8_t adv_clk_accuracy;           /*!< Periodic advertising clock accuracy */
1552     } past_received;                        /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_SYNC_TRANS_RECV_EVT */
1553 #endif // #if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
1554     /**
1555      * @brief ESP_GAP_BLE_DTM_TEST_UPDATE_EVT
1556      */
1557     struct ble_dtm_state_update_evt_param {
1558         esp_bt_status_t status;                     /*!< Indicate DTM operation success status */
1559         esp_ble_dtm_update_evt_t update_evt;        /*!< DTM state change event, 0x00: DTM TX start, 0x01: DTM RX start, 0x02:DTM end */
1560         uint16_t num_of_pkt;                        /*!< number of packets received, only valid if update_evt is DTM_TEST_STOP_EVT and shall be reported as 0 for a transmitter */
1561     } dtm_state_update;                             /*!< Event parameter of ESP_GAP_BLE_DTM_TEST_UPDATE_EVT */
1562     /**
1563      * @brief ESP_GAP_BLE_VENDOR_CMD_COMPLETE_EVT
1564      */
1565     struct vendor_cmd_cmpl_evt_param {
1566         uint16_t        opcode;                     /*!< vendor hci command opcode */
1567         uint16_t        param_len;                  /*!< The length of parameter buffer */
1568         uint8_t         *p_param_buf;               /*!< The point of parameter buffer */
1569     } vendor_cmd_cmpl;                              /*!< Event parameter of ESP_GAP_BLE_VENDOR_CMD_COMPLETE_EVT */
1570     /**
1571      * @brief ESP_GAP_BLE_SET_PRIVACY_MODE_COMPLETE_EVT
1572      */
1573     struct ble_set_privacy_mode_cmpl_evt_param {
1574         esp_bt_status_t status;                     /*!< Indicate privacy mode set operation success status */
1575     } set_privacy_mode_cmpl;                        /*!< Event parameter of ESP_GAP_BLE_SET_PRIVACY_MODE_COMPLETE_EVT */
1576     /**
1577      * @brief ESP_GAP_BLE_SET_CSA_SUPPORT_COMPLETE_EVT
1578      */
1579     struct ble_set_csa_support_cmpl_evt_param {
1580         esp_bt_status_t status;                     /*!< Indicate CSA support set operation success status */
1581     } set_csa_support_cmpl;                        /*!< Event parameter of ESP_GAP_BLE_SET_CSA_SUPPORT_COMPLETE_EVT */
1582 } esp_ble_gap_cb_param_t;
1583 
1584 /**
1585  * @brief GAP callback function type
1586  * @param event : Event type
1587  * @param param : Point to callback parameter, currently is union type
1588  */
1589 typedef void (* esp_gap_ble_cb_t)(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param);
1590 
1591 /**
1592  * @brief           This function is called to occur gap event, such as scan result
1593  *
1594  * @param[in]       callback: callback function
1595  *
1596  * @return
1597  *                  - ESP_OK : success
1598  *                  - other  : failed
1599  *
1600  */
1601 esp_err_t esp_ble_gap_register_callback(esp_gap_ble_cb_t callback);
1602 
1603 /**
1604  * @brief           This function is called to get the current gap callback
1605  *
1606  * @return
1607  *                  - esp_gap_ble_cb_t : callback function
1608  *
1609  */
1610 esp_gap_ble_cb_t esp_ble_gap_get_callback(void);
1611 
1612 #if (BLE_42_FEATURE_SUPPORT == TRUE)
1613 /**
1614  * @brief           This function is called to override the BTA default ADV parameters.
1615  *
1616  * @param[in]       adv_data: Pointer to User defined ADV data structure. This
1617  *                  memory space can not be freed until callback of config_adv_data
1618  *                  is received.
1619  *
1620  * @return
1621  *                  - ESP_OK : success
1622  *                  - other  : failed
1623  *
1624  */
1625 esp_err_t esp_ble_gap_config_adv_data (esp_ble_adv_data_t *adv_data);
1626 
1627 
1628 
1629 /**
1630  * @brief           This function is called to set scan parameters
1631  *
1632  * @param[in]       scan_params: Pointer to User defined scan_params data structure. This
1633  *                  memory space can not be freed until callback of set_scan_params
1634  *
1635  * @return
1636  *                  - ESP_OK : success
1637  *                  - other  : failed
1638  *
1639  */
1640 esp_err_t esp_ble_gap_set_scan_params(esp_ble_scan_params_t *scan_params);
1641 
1642 
1643 /**
1644  * @brief           This procedure keep the device scanning the peer device which advertising on the air
1645  *
1646  * @param[in]       duration: Keeping the scanning time, the unit is second.
1647  *
1648  * @return
1649  *                  - ESP_OK : success
1650  *                  - other  : failed
1651  *
1652  */
1653 esp_err_t esp_ble_gap_start_scanning(uint32_t duration);
1654 
1655 
1656 /**
1657  * @brief          This function call to stop the device scanning the peer device which advertising on the air
1658  * @return
1659  *                 - ESP_OK : success
1660  *                  - other  : failed
1661  *
1662  */
1663 esp_err_t esp_ble_gap_stop_scanning(void);
1664 
1665 /**
1666  * @brief           This function is called to start advertising.
1667  *
1668  * @param[in]       adv_params: pointer to User defined adv_params data structure.
1669 
1670  * @return
1671  *                  - ESP_OK : success
1672  *                  - other  : failed
1673  *
1674  */
1675 esp_err_t esp_ble_gap_start_advertising (esp_ble_adv_params_t *adv_params);
1676 
1677 
1678 
1679 /**
1680  * @brief           This function is called to stop advertising.
1681  *
1682  * @return
1683  *                  - ESP_OK : success
1684  *                  - other  : failed
1685  *
1686  */
1687 esp_err_t esp_ble_gap_stop_advertising(void);
1688 #endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
1689 
1690 
1691 /**
1692  * @brief           Update connection parameters, can only be used when connection is up.
1693  *
1694  * @param[in]       params   -  connection update parameters
1695  *
1696  * @return
1697  *                  - ESP_OK : success
1698  *                  - other  : failed
1699  *
1700  */
1701 esp_err_t esp_ble_gap_update_conn_params(esp_ble_conn_update_params_t *params);
1702 
1703 
1704 /**
1705  * @brief           This function is to set maximum LE data packet size
1706  *
1707  * @return
1708  *                  - ESP_OK : success
1709  *                  - other  : failed
1710  *
1711  */
1712 esp_err_t esp_ble_gap_set_pkt_data_len(esp_bd_addr_t remote_device, uint16_t tx_data_length);
1713 
1714 /**
1715  * @brief           This function allows configuring either a Non-Resolvable Private Address or a Static Random Address
1716  *
1717  * @param[in]       rand_addr: The address to be configured. Refer to the table below for possible address subtypes:
1718  *
1719  *               | address [47:46] | Address Type                | Corresponding API                      |
1720  *               |-----------------|-----------------------------|----------------------------------------|
1721  *               |      0b00       | Non-Resolvable Private      | esp_ble_gap_addr_create_nrpa           |
1722  *               |                 | Address (NRPA)              |                                        |
1723  *               |-----------------|-----------------------------|----------------------------------------|
1724  *               |      0b11       | Static Random Address       | esp_ble_gap_addr_create_static         |
1725  *               |-----------------|-----------------------------|----------------------------------------|
1726  *
1727  * @return
1728  *                  - ESP_OK : success
1729  *                  - other  : failed
1730  *
1731  */
1732 esp_err_t esp_ble_gap_set_rand_addr(esp_bd_addr_t rand_addr);
1733 
1734 /**
1735  * @brief           Create a static device address
1736  * @param[out]      rand_addr: Pointer to the buffer where the static device address will be stored.
1737  * @return          - ESP_OK : Success
1738  *                  - Other  : Failed
1739  */
1740 esp_err_t esp_ble_gap_addr_create_static(esp_bd_addr_t rand_addr);
1741 
1742 /**
1743  * @brief           Create a non-resolvable private address (NRPA)
1744  * @param[out]      rand_addr: Pointer to the buffer where the NRPA will be stored.
1745  * @return          - ESP_OK : Success
1746  *                  - Other  : Failed
1747  */
1748 esp_err_t esp_ble_gap_addr_create_nrpa(esp_bd_addr_t rand_addr);
1749 
1750 /**
1751  * @brief           This function sets the length of time the Controller uses a Resolvable Private Address
1752  *                  before generating and starting to use a new resolvable private address.
1753  *
1754  * @note            Note: This function is currently not supported on the ESP32 but will be enabled in a future update.
1755  *
1756  * @param[in]       rpa_timeout: The timeout duration in seconds for how long a Resolvable Private Address
1757  *                  is used before a new one is generated. The value must be within the range specified by
1758  *                  the Bluetooth specification (0x0001 to 0x0E10), which corresponds to a time range of
1759  *                  1 second to 1 hour. The default value is 0x0384 (900 seconds or 15 minutes).
1760  * @return
1761  *                  - ESP_OK : success
1762  *                  - other  : failed
1763  *
1764  */
1765 esp_err_t esp_ble_gap_set_resolvable_private_address_timeout(uint16_t rpa_timeout);
1766 
1767 
1768 /**
1769  * @brief           This function adds a device to the resolving list used to generate and resolve Resolvable Private Addresses
1770  *                  in the Controller.
1771  *
1772  * @note            Note: This function shall not be used when address resolution is enabled in the Controller and:
1773  *                      - Advertising (other than periodic advertising) is enabled,
1774  *                      - Scanning is enabled, or
1775  *                      - an HCI_LE_Create_Connection, HCI_LE_Extended_Create_Connection, or HCI_LE_Periodic_Advertising_Create_Sync command is pending.
1776  *                  This command may be used at any time when address resolution is disabled in the Controller.
1777  *                  The added device shall be set to Network Privacy mode.
1778  *
1779  * @param[in]       peer_addr: The peer identity address of the device to be added to the resolving list.
1780  * @param[in]       addr_type: The address type of the peer identity address (BLE_ADDR_TYPE_PUBLIC or BLE_ADDR_TYPE_RANDOM).
1781  * @param[in]       peer_irk: The Identity Resolving Key (IRK) of the device.
1782  * @return
1783  *                  - ESP_OK : success
1784  *                  - other  : failed
1785  *
1786  */
1787 esp_err_t esp_ble_gap_add_device_to_resolving_list(esp_bd_addr_t peer_addr, uint8_t addr_type, uint8_t *peer_irk);
1788 /**
1789  * @brief           This function clears the random address for the application
1790  *
1791  * @return
1792  *                  - ESP_OK : success
1793  *                  - other  : failed
1794  *
1795  */
1796 esp_err_t esp_ble_gap_clear_rand_addr(void);
1797 
1798 /**
1799  * @brief           Enable/disable privacy (including address resolution) on the local device
1800  *
1801  * @param[in]       privacy_enable   - enable/disable privacy on remote device.
1802  *
1803  * @return
1804  *                  - ESP_OK : success
1805  *                  - other  : failed
1806  *
1807  */
1808 esp_err_t esp_ble_gap_config_local_privacy (bool privacy_enable);
1809 
1810 /**
1811  * @brief           set local gap appearance icon
1812  *
1813  *
1814  * @param[in]       icon   - External appearance value, these values are defined by the Bluetooth SIG, please refer to
1815  *                  https://www.bluetooth.com/specifications/assigned-numbers/
1816  *
1817  * @return
1818  *                  - ESP_OK : success
1819  *                  - other  : failed
1820  *
1821  */
1822 esp_err_t esp_ble_gap_config_local_icon (uint16_t icon);
1823 
1824 /**
1825 * @brief            Add or remove device from white list
1826 *
1827 * @param[in]        add_remove: the value is true if added the ble device to the white list, and false remove to the white list.
1828 * @param[in]        remote_bda: the remote device address add/remove from the white list.
1829 * @param[in]        wl_addr_type: whitelist address type
1830 * @return
1831 *                     - ESP_OK : success
1832 *                     - other  : failed
1833 *
1834 */
1835 esp_err_t esp_ble_gap_update_whitelist(bool add_remove, esp_bd_addr_t remote_bda, esp_ble_wl_addr_type_t wl_addr_type);
1836 
1837 /**
1838 * @brief            Clear all white list
1839 *
1840 * @return
1841 *                     - ESP_OK : success
1842 *                     - other  : failed
1843 *
1844 */
1845 esp_err_t esp_ble_gap_clear_whitelist(void);
1846 
1847 /**
1848 * @brief            Get the whitelist size in the controller
1849 *
1850 * @param[out]       length: the white list length.
1851 * @return
1852 *                     - ESP_OK : success
1853 *                     - other  : failed
1854 *
1855 */
1856 esp_err_t esp_ble_gap_get_whitelist_size(uint16_t *length);
1857 #if (BLE_42_FEATURE_SUPPORT == TRUE)
1858 /**
1859 * @brief            This function is called to set the preferred connection
1860 *                   parameters when default connection parameter is not desired before connecting.
1861 *                   This API can only be used in the master role.
1862 *
1863 * @param[in]        bd_addr: BD address of the peripheral
1864 * @param[in]        min_conn_int: minimum preferred connection interval
1865 * @param[in]        max_conn_int: maximum preferred connection interval
1866 * @param[in]        slave_latency: preferred slave latency
1867 * @param[in]        supervision_tout: preferred supervision timeout
1868 *
1869 * @return
1870 *                   - ESP_OK : success
1871 *                   - other  : failed
1872 *
1873 */
1874 esp_err_t esp_ble_gap_set_prefer_conn_params(esp_bd_addr_t bd_addr,
1875                                                                  uint16_t min_conn_int, uint16_t max_conn_int,
1876                                                                  uint16_t slave_latency, uint16_t supervision_tout);
1877 #endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
1878 /**
1879  * @brief           Set device name to the local device
1880  *                  Note: This API don't affect the advertising data
1881  *
1882  * @param[in]       name   -  device name.
1883  *
1884  * @return
1885  *                  - ESP_OK : success
1886  *                  - other  : failed
1887  *
1888  */
1889 esp_err_t esp_ble_gap_set_device_name(const char *name);
1890 
1891 /**
1892  * @brief           Get device name of the local device
1893  *
1894  * @return
1895  *                  - ESP_OK : success
1896  *                  - other  : failed
1897  *
1898  */
1899 esp_err_t esp_ble_gap_get_device_name(void);
1900 
1901 /**
1902  * @brief          This function is called to get local used address and address type.
1903  *                 uint8_t *esp_bt_dev_get_address(void) get the public address
1904  *
1905  * @param[in]       local_used_addr - current local used ble address (six bytes)
1906  * @param[in]       addr_type   - ble address type
1907  *
1908  * @return          - ESP_OK : success
1909  *                  - other  : failed
1910  *
1911  */
1912 esp_err_t esp_ble_gap_get_local_used_addr(esp_bd_addr_t local_used_addr, uint8_t * addr_type);
1913 
1914 /**
1915  * @brief          This function is called to get ADV data for a specific type.
1916  *
1917  * @note           This is the recommended function to use for resolving ADV data by type.
1918  *                 It improves upon the deprecated `esp_ble_resolve_adv_data` function by
1919  *                 including an additional parameter to specify the length of the ADV data,
1920  *                 thereby offering better safety and reliability.
1921  *
1922  * @param[in]      adv_data - pointer of ADV data which to be resolved
1923  * @param[in]      adv_data_len - the length of ADV data which to be resolved.
1924  * @param[in]      type   - finding ADV data type
1925  * @param[out]     length - return the length of ADV data not including type
1926  *
1927  * @return         pointer of ADV data
1928  *
1929  */
1930 uint8_t *esp_ble_resolve_adv_data_by_type( uint8_t *adv_data, uint16_t adv_data_len, esp_ble_adv_data_type type, uint8_t *length);
1931 
1932 /**
1933  * @brief          This function is called to get ADV data for a specific type.
1934  *
1935  * @note           This function has been deprecated and will be removed in a future release.
1936  *                 Please use `esp_ble_resolve_adv_data_by_type` instead, which provides
1937  *                 better parameter validation and supports more accurate data resolution.
1938  *
1939  * @param[in]      adv_data - pointer of ADV data which to be resolved
1940  * @param[in]      type   - finding ADV data type
1941  * @param[out]     length - return the length of ADV data not including type
1942  *
1943  * @return         pointer of ADV data
1944  *
1945  */
1946 uint8_t *esp_ble_resolve_adv_data(uint8_t *adv_data, uint8_t type, uint8_t *length);
1947 
1948 #if (BLE_42_FEATURE_SUPPORT == TRUE)
1949 /**
1950  * @brief           This function is called to set raw advertising data. User need to fill
1951  *                  ADV data by self.
1952  *
1953  * @param[in]       raw_data : raw advertising data with the format: [Length 1][Data Type 1][Data 1][Length 2][Data Type 2][Data 2] ...
1954  * @param[in]       raw_data_len : raw advertising data length , less than 31 bytes
1955  *
1956  * @return
1957  *                  - ESP_OK : success
1958  *                  - other  : failed
1959  *
1960  */
1961 esp_err_t esp_ble_gap_config_adv_data_raw(uint8_t *raw_data, uint32_t raw_data_len);
1962 
1963 /**
1964  * @brief           This function is called to set raw scan response data. User need to fill
1965  *                  scan response data by self.
1966  *
1967  * @param[in]       raw_data : raw scan response data
1968  * @param[in]       raw_data_len : raw scan response data length , less than 31 bytes
1969  *
1970  * @return
1971  *                  - ESP_OK : success
1972  *                  - other  : failed
1973  */
1974 esp_err_t esp_ble_gap_config_scan_rsp_data_raw(uint8_t *raw_data, uint32_t raw_data_len);
1975 #endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
1976 
1977 /**
1978  * @brief           This function is called to read the RSSI of remote device.
1979  *                  The address of link policy results are returned in the gap callback function with
1980  *                  ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT event.
1981  *
1982  * @param[in]       remote_addr : The remote connection device address.
1983  *
1984  * @return
1985  *                  - ESP_OK : success
1986  *                  - other  : failed
1987  */
1988 esp_err_t esp_ble_gap_read_rssi(esp_bd_addr_t remote_addr);
1989 #if (BLE_42_FEATURE_SUPPORT == TRUE)
1990 /**
1991  * @brief           This function is called to add a device info into the duplicate scan exceptional list.
1992  *
1993  *
1994  * @param[in]       type: device info type, it is defined in esp_ble_duplicate_exceptional_info_type_t
1995  *                  when type is MESH_BEACON_TYPE, MESH_PROV_SRV_ADV or MESH_PROXY_SRV_ADV , device_info is invalid.
1996  * @param[in]       device_info: the device information.
1997  * @return
1998  *                  - ESP_OK : success
1999  *                  - other  : failed
2000  */
2001 esp_err_t esp_ble_gap_add_duplicate_scan_exceptional_device(esp_ble_duplicate_exceptional_info_type_t type, esp_duplicate_info_t device_info);
2002 
2003 /**
2004  * @brief           This function is called to remove a device info from the duplicate scan exceptional list.
2005  *
2006  *
2007  * @param[in]       type: device info type, it is defined in esp_ble_duplicate_exceptional_info_type_t
2008  *                  when type is MESH_BEACON_TYPE, MESH_PROV_SRV_ADV or MESH_PROXY_SRV_ADV , device_info is invalid.
2009  * @param[in]       device_info: the device information.
2010  * @return
2011  *                  - ESP_OK : success
2012  *                  - other  : failed
2013  */
2014 esp_err_t esp_ble_gap_remove_duplicate_scan_exceptional_device(esp_ble_duplicate_exceptional_info_type_t type, esp_duplicate_info_t device_info);
2015 
2016 /**
2017  * @brief           This function is called to clean the duplicate scan exceptional list.
2018  *                  This API will delete all device information in the duplicate scan exceptional list.
2019  *
2020  *
2021  * @param[in]       list_type: duplicate scan exceptional list type, the value can be one or more of esp_duplicate_scan_exceptional_list_type_t.
2022  *
2023  * @return
2024  *                  - ESP_OK : success
2025  *                  - other  : failed
2026  */
2027 esp_err_t esp_ble_gap_clean_duplicate_scan_exceptional_list(esp_duplicate_scan_exceptional_list_type_t list_type);
2028 #endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
2029 
2030 #if (SMP_INCLUDED == TRUE)
2031 /**
2032 * @brief             Set a GAP security parameter value. Overrides the default value.
2033 *
2034 *                    Secure connection is highly recommended to avoid some major
2035 *                    vulnerabilities like 'Impersonation in the Pin Pairing Protocol'
2036 *                    (CVE-2020-26555) and 'Authentication of the LE Legacy Pairing
2037 *                    Protocol'.
2038 *
2039 *                    To accept only `secure connection mode`, it is necessary do as following:
2040 *
2041 *                    1. Set bit `ESP_LE_AUTH_REQ_SC_ONLY` (`param_type` is
2042 *                    `ESP_BLE_SM_AUTHEN_REQ_MODE`), bit `ESP_LE_AUTH_BOND` and bit
2043 *                    `ESP_LE_AUTH_REQ_MITM` is optional as required.
2044 *
2045 *                    2. Set to `ESP_BLE_ONLY_ACCEPT_SPECIFIED_AUTH_ENABLE` (`param_type` is
2046 *                    `ESP_BLE_SM_ONLY_ACCEPT_SPECIFIED_SEC_AUTH`).
2047 *
2048 * @param[in]       param_type : the type of the param which to be set
2049 * @param[in]       value  : the param value
2050 * @param[in]       len : the length of the param value
2051 *
2052 * @return            - ESP_OK : success
2053 *                       - other  : failed
2054 *
2055 */
2056 esp_err_t esp_ble_gap_set_security_param(esp_ble_sm_param_t param_type,
2057                                          void *value, uint8_t len);
2058 
2059 /**
2060 * @brief             Grant security request access.
2061 *
2062 * @param[in]       bd_addr : BD address of the peer
2063 * @param[in]       accept  :  accept the security request or not
2064 *
2065 * @return            - ESP_OK : success
2066 *                    - other  : failed
2067 *
2068 */
2069 esp_err_t esp_ble_gap_security_rsp(esp_bd_addr_t bd_addr,  bool accept);
2070 
2071 
2072 /**
2073 * @brief             Set a gap parameter value. Use this function to change
2074 *                    the default GAP parameter values.
2075 *
2076 * @param[in]       bd_addr : the address of the peer device need to encryption
2077 * @param[in]       sec_act  : This is the security action to indicate
2078 *                                   what kind of BLE security level is required for
2079 *                                   the BLE link if the BLE is supported
2080 *
2081 * @return            - ESP_OK : success
2082 *                       - other  : failed
2083 *
2084 */
2085 esp_err_t esp_ble_set_encryption(esp_bd_addr_t bd_addr, esp_ble_sec_act_t sec_act);
2086 
2087 /**
2088 * @brief          Reply the key value to the peer device in the legacy connection stage.
2089 *
2090 * @param[in]      bd_addr : BD address of the peer
2091 * @param[in]      accept : passkey entry successful or declined.
2092 * @param[in]      passkey : passkey value, must be a 6 digit number,
2093 *                                     can be lead by 0.
2094 *
2095 * @return            - ESP_OK : success
2096 *                  - other  : failed
2097 *
2098 */
2099 esp_err_t esp_ble_passkey_reply(esp_bd_addr_t bd_addr, bool accept, uint32_t passkey);
2100 
2101 
2102 /**
2103 * @brief           Reply the confirm value to the peer device in the secure connection stage.
2104 *
2105 * @param[in]       bd_addr : BD address of the peer device
2106 * @param[in]       accept : numbers to compare are the same or different.
2107 *
2108 * @return            - ESP_OK : success
2109 *                       - other  : failed
2110 *
2111 */
2112 esp_err_t esp_ble_confirm_reply(esp_bd_addr_t bd_addr, bool accept);
2113 
2114 /**
2115 * @brief           Removes a device from the security database list of
2116 *                  peer device. It manages unpairing event while connected.
2117 *
2118 * @param[in]       bd_addr : BD address of the peer device
2119 *
2120 * @return            - ESP_OK : success
2121 *                       - other  : failed
2122 *
2123 */
2124 esp_err_t esp_ble_remove_bond_device(esp_bd_addr_t bd_addr);
2125 
2126 /**
2127 * @brief           Get the device number from the security database list of peer device.
2128 *                  It will return the device bonded number immediately.
2129 *
2130 * @return          - >= 0 : bonded devices number.
2131 *                  - ESP_FAIL  : failed
2132 *
2133 */
2134 int esp_ble_get_bond_device_num(void);
2135 
2136 /**
2137 * @brief           Get the device from the security database list of peer device.
2138 *                  It will return the device bonded information immediately.
2139 * @param[inout]    dev_num: Indicate the dev_list array(buffer) size as input.
2140 *                           If dev_num is large enough, it means the actual number as output.
2141 *                           Suggest that dev_num value equal to esp_ble_get_bond_device_num().
2142 *
2143 * @param[out]      dev_list: an array(buffer) of `esp_ble_bond_dev_t` type. Use for storing the bonded devices address.
2144 *                            The dev_list should be allocated by who call this API.
2145 * @return          - ESP_OK : success
2146 *                  - other  : failed
2147 *
2148 */
2149 esp_err_t esp_ble_get_bond_device_list(int *dev_num, esp_ble_bond_dev_t *dev_list);
2150 
2151 /**
2152 * @brief           This function is called to provide the OOB data for
2153 *                  SMP in response to ESP_GAP_BLE_OOB_REQ_EVT
2154 *
2155 * @param[in]       bd_addr: BD address of the peer device.
2156 * @param[in]       TK: Temporary Key value, the TK value shall be a 128-bit random number
2157 * @param[in]       len: length of temporary key, should always be 128-bit
2158 *
2159 * @return          - ESP_OK : success
2160 *                  - other  : failed
2161 *
2162 */
2163 esp_err_t esp_ble_oob_req_reply(esp_bd_addr_t bd_addr, uint8_t *TK, uint8_t len);
2164 
2165 /**
2166 * @brief           This function is called to provide the OOB data for
2167 *                  SMP in response to ESP_GAP_BLE_SC_OOB_REQ_EVT
2168 *
2169 * @param[in]       bd_addr: BD address of the peer device.
2170 * @param[in]       p_c: Confirmation value, it shall be a 128-bit random number
2171 * @param[in]       p_r: Randomizer value, it should be a 128-bit random number
2172 *
2173 * @return          - ESP_OK : success
2174 *                  - other  : failed
2175 *
2176 */
2177 esp_err_t esp_ble_sc_oob_req_reply(esp_bd_addr_t bd_addr, uint8_t p_c[16], uint8_t p_r[16]);
2178 
2179 /**
2180 * @brief           This function is called to create the OOB data for
2181 *                  SMP when secure connection
2182 *
2183 * @return          - ESP_OK : success
2184 *                  - other  : failed
2185 *
2186 */
2187 esp_err_t esp_ble_create_sc_oob_data(void);
2188 #endif /* #if (SMP_INCLUDED == TRUE) */
2189 
2190 /**
2191 * @brief           This function is to disconnect the physical connection of the peer device
2192 *                  gattc may have multiple virtual GATT server connections when multiple app_id registered.
2193 *                  esp_ble_gattc_close (esp_gatt_if_t gattc_if, uint16_t conn_id) only close one virtual GATT server connection.
2194 *                  if there exist other virtual GATT server connections, it does not disconnect the physical connection.
2195 *                  esp_ble_gap_disconnect(esp_bd_addr_t remote_device) disconnect the physical connection directly.
2196 *
2197 *
2198 *
2199 * @param[in]       remote_device : BD address of the peer device
2200 *
2201 * @return            - ESP_OK : success
2202 *                    - other  : failed
2203 *
2204 */
2205 esp_err_t esp_ble_gap_disconnect(esp_bd_addr_t remote_device);
2206 
2207 /**
2208 * @brief           This function is called to read the connection
2209 *                  parameters information of the device
2210 *
2211 * @param[in]       bd_addr: BD address of the peer device.
2212 * @param[out]      conn_params: the connection parameters information
2213 *
2214 * @return          - ESP_OK : success
2215 *                  - other  : failed
2216 *
2217 */
2218 esp_err_t esp_ble_get_current_conn_params(esp_bd_addr_t bd_addr, esp_gap_conn_params_t *conn_params);
2219 
2220 /**
2221 * @brief            BLE set channels
2222 *
2223 * @param[in]        channels :   The n th such field (in the range 0 to 36) contains the value for the link layer channel index n.
2224 *                                0 means channel n is bad.
2225 *                                1 means channel n is unknown.
2226 *                                The most significant bits are reserved and shall be set to 0.
2227 *                                At least one channel shall be marked as unknown.
2228 *
2229 * @return           - ESP_OK : success
2230 *                   - ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled
2231 *                   - other  : failed
2232 *
2233 */
2234 esp_err_t esp_gap_ble_set_channels(esp_gap_ble_channels channels);
2235 
2236 /**
2237 * @brief           This function is called to authorized a link after Authentication(MITM protection)
2238 *
2239 * @param[in]       bd_addr: BD address of the peer device.
2240 * @param[out]      authorize: Authorized the link or not.
2241 *
2242 * @return          - ESP_OK : success
2243 *                  - other  : failed
2244 *
2245 */
2246 esp_err_t esp_gap_ble_set_authorization(esp_bd_addr_t bd_addr, bool authorize);
2247 
2248 #if (BLE_50_FEATURE_SUPPORT == TRUE)
2249 
2250 /**
2251 * @brief           This function is used to read the current transmitter PHY
2252 *                  and receiver PHY on the connection identified by remote address.
2253 *
2254 * @param[in]       bd_addr : BD address of the peer device
2255 *
2256 * @return            - ESP_OK : success
2257 *                    - other  : failed
2258 *
2259 */
2260 esp_err_t esp_ble_gap_read_phy(esp_bd_addr_t bd_addr);
2261 
2262 /**
2263 * @brief           This function is used to allows the Host to specify its preferred values
2264 *                  for the transmitter PHY and receiver PHY to be used for all subsequent connections
2265 *                  over the LE transport.
2266 *
2267 * @param[in]       tx_phy_mask : indicates the transmitter PHYs that the Host prefers the Controller to use
2268 * @param[in]       rx_phy_mask : indicates the receiver PHYs that the Host prefers the Controller to use
2269 *
2270 * @return            - ESP_OK : success
2271 *                    - other  : failed
2272 *
2273 */
2274 esp_err_t esp_ble_gap_set_preferred_default_phy(esp_ble_gap_phy_mask_t tx_phy_mask, esp_ble_gap_phy_mask_t rx_phy_mask);
2275 /**
2276 * @brief           This function is used to set the PHY preferences for the connection identified by the remote address.
2277 *                  The Controller might not be able to make the change (e.g. because the peer does not support the requested PHY)
2278 *                  or may decide that the current PHY is preferable.
2279 *
2280 * @param[in]       bd_addr : remote address
2281 * @param[in]       all_phys_mask : a bit field that allows the Host to specify
2282 * @param[in]       tx_phy_mask : a bit field that indicates the transmitter PHYs that the Host prefers the Controller to use
2283 * @param[in]       rx_phy_mask : a bit field that indicates the receiver PHYs that the Host prefers the Controller to use
2284 * @param[in]       phy_options : a bit field that allows the Host to specify options for PHYs
2285 *
2286 * @return            - ESP_OK : success
2287 *                    - other  : failed
2288 *
2289 */
2290 esp_err_t esp_ble_gap_set_preferred_phy(esp_bd_addr_t bd_addr,
2291                                        esp_ble_gap_all_phys_t all_phys_mask,
2292                                        esp_ble_gap_phy_mask_t tx_phy_mask,
2293                                        esp_ble_gap_phy_mask_t rx_phy_mask,
2294                                        esp_ble_gap_prefer_phy_options_t phy_options);
2295 
2296 /**
2297 * @brief           This function is used by the Host to set the random device address specified by the Random_Address parameter.
2298 *
2299 * @param[in]       instance  : Used to identify an advertising set
2300 * @param[in]       rand_addr : Random Device Address
2301 *
2302 * @return            - ESP_OK : success
2303 *                    - other  : failed
2304 *
2305 */
2306 esp_err_t esp_ble_gap_ext_adv_set_rand_addr(uint8_t instance, esp_bd_addr_t rand_addr);
2307 
2308 /**
2309 * @brief           This function is used by the Host to set the advertising parameters.
2310 *
2311 * @param[in]       instance : identifies the advertising set whose parameters are being configured.
2312 * @param[in]       params   : advertising parameters
2313 *
2314 * @return            - ESP_OK : success
2315 *                    - other  : failed
2316 *
2317 */
2318 esp_err_t esp_ble_gap_ext_adv_set_params(uint8_t instance, const esp_ble_gap_ext_adv_params_t *params);
2319 
2320 /**
2321 * @brief           This function is used to set the data used in advertising PDUs that have a data field
2322 *
2323 * @param[in]       instance : identifies the advertising set whose data are being configured
2324 * @param[in]       length   : data length
2325 * @param[in]       data     : data information
2326 *
2327 * @return            - ESP_OK : success
2328 *                    - other  : failed
2329 *
2330 */
2331 esp_err_t esp_ble_gap_config_ext_adv_data_raw(uint8_t instance, uint16_t length, const uint8_t *data);
2332 
2333 /**
2334 * @brief           This function is used to provide scan response data used in scanning response PDUs
2335 *
2336 * @param[in]       instance : identifies the advertising set whose response data are being configured.
2337 * @param[in]       length : responsedata length
2338 * @param[in]       scan_rsp_data : response data information
2339 *
2340 * @return            - ESP_OK : success
2341 *                    - other  : failed
2342 *
2343 */
2344 esp_err_t esp_ble_gap_config_ext_scan_rsp_data_raw(uint8_t instance, uint16_t length,
2345                                                                    const uint8_t *scan_rsp_data);
2346 /**
2347 * @brief           This function is used to request the Controller to enable one or more
2348 *                  advertising sets using the advertising sets identified by the instance parameter.
2349 *
2350 * @param[in]       num_adv : Number of advertising sets to enable or disable
2351 * @param[in]       ext_adv : adv parameters
2352 *
2353 * @return            - ESP_OK : success
2354 *                    - other  : failed
2355 *
2356 */
2357 esp_err_t esp_ble_gap_ext_adv_start(uint8_t num_adv, const esp_ble_gap_ext_adv_t *ext_adv);
2358 
2359 /**
2360 * @brief           This function is used to request the Controller to disable one or more
2361 *                  advertising sets using the advertising sets identified by the instance parameter.
2362 *
2363 * @param[in]       num_adv : Number of advertising sets to enable or disable
2364 * @param[in]       ext_adv_inst : ext adv instance
2365 *
2366 * @return            - ESP_OK : success
2367 *                    - other  : failed
2368 *
2369 */
2370 esp_err_t esp_ble_gap_ext_adv_stop(uint8_t num_adv, const uint8_t *ext_adv_inst);
2371 
2372 /**
2373 * @brief           This function is used to remove an advertising set from the Controller.
2374 *
2375 * @param[in]       instance : Used to identify an advertising set
2376 *
2377 * @return            - ESP_OK : success
2378 *                    - other  : failed
2379 *
2380 */
2381 esp_err_t esp_ble_gap_ext_adv_set_remove(uint8_t instance);
2382 
2383 /**
2384 * @brief           This function is used to remove all existing advertising sets from the Controller.
2385 *
2386 *
2387 * @return            - ESP_OK : success
2388 *                    - other  : failed
2389 *
2390 */
2391 esp_err_t esp_ble_gap_ext_adv_set_clear(void);
2392 
2393 /**
2394 * @brief           This function is used by the Host to set the parameters for periodic advertising.
2395 *
2396 * @param[in]       instance : identifies the advertising set whose periodic advertising parameters are being configured.
2397 * @param[in]       params : periodic adv parameters
2398 *
2399 * @return            - ESP_OK : success
2400 *                    - other  : failed
2401 *
2402 */
2403 esp_err_t esp_ble_gap_periodic_adv_set_params(uint8_t instance, const esp_ble_gap_periodic_adv_params_t *params);
2404 
2405 #if (CONFIG_BT_BLE_FEAT_PERIODIC_ADV_ENH)
2406 /**
2407 * @brief           This function is used to set the data used in periodic advertising PDUs.
2408 *
2409 * @param[in]       instance : identifies the advertising set whose periodic advertising parameters are being configured.
2410 * @param[in]       length : the length of periodic data
2411 * @param[in]       data : periodic data information
2412 * @param[in]       only_update_did : If true, only the Advertising DID of the periodic advertising will be updated, and the length and data parameters will be ignored.
2413 *
2414 * @return            - ESP_OK : success
2415 *                    - other  : failed
2416 *
2417 */
2418 esp_err_t esp_ble_gap_config_periodic_adv_data_raw(uint8_t instance, uint16_t length,
2419                                                                            const uint8_t *data, bool only_update_did);
2420 #else
2421 /**
2422 * @brief           This function is used to set the data used in periodic advertising PDUs.
2423 *
2424 * @param[in]       instance : identifies the advertising set whose periodic advertising parameters are being configured.
2425 * @param[in]       length : the length of periodic data
2426 * @param[in]       data : periodic data information
2427 *
2428 * @return            - ESP_OK : success
2429 *                    - other  : failed
2430 *
2431 */
2432 esp_err_t esp_ble_gap_config_periodic_adv_data_raw(uint8_t instance, uint16_t length,
2433                                                                            const uint8_t *data);
2434 #endif
2435 
2436 #if (CONFIG_BT_BLE_FEAT_PERIODIC_ADV_ENH)
2437 /**
2438 * @brief           This function is used to request the Controller to enable the periodic advertising for the advertising set specified
2439 *
2440 * @param[in]       instance : Used to identify an advertising set
2441 * @param[in]       include_adi : If true, the ADI (Advertising Data Info) field will be included in AUX_SYNC_IND PDUs
2442 *
2443 * @return            - ESP_OK : success
2444 *                    - other  : failed
2445 *
2446 */
2447 esp_err_t esp_ble_gap_periodic_adv_start(uint8_t instance,bool include_adi);
2448 #else
2449 /**
2450 * @brief           This function is used to request the Controller to enable the periodic advertising for the advertising set specified
2451 *
2452 * @param[in]       instance : Used to identify an advertising set
2453 *
2454 * @return            - ESP_OK : success
2455 *                    - other  : failed
2456 *
2457 */
2458 esp_err_t esp_ble_gap_periodic_adv_start(uint8_t instance);
2459 #endif
2460 
2461 /**
2462 * @brief           This function is used to request the Controller to disable the periodic advertising for the advertising set specified
2463 *
2464 * @param[in]       instance : Used to identify an advertising set
2465 *
2466 * @return            - ESP_OK : success
2467 *                    - other  : failed
2468 *
2469 */
2470 esp_err_t esp_ble_gap_periodic_adv_stop(uint8_t instance);
2471 
2472 /**
2473 * @brief           This function is used to set the extended scan parameters to be used on the advertising channels.
2474 *
2475 * @param[in]       params : scan parameters
2476 *
2477 * @return            - ESP_OK : success
2478 *                    - other  : failed
2479 *
2480 */
2481 esp_err_t esp_ble_gap_set_ext_scan_params(const esp_ble_ext_scan_params_t *params);
2482 
2483 /**
2484 * @brief           This function is used to enable scanning.
2485 *
2486 * @param[in]       duration  Scan duration time, where Time = N * 10 ms. Range: 0x0001 to 0xFFFF.
2487 * @param[in]       period    Time interval from when the Controller started its last Scan Duration until it begins the subsequent Scan Duration.
2488 *                            Time = N * 1.28 sec. Range: 0x0001 to 0xFFFF.
2489 *
2490 * @return            - ESP_OK : success
2491 *                    - other  : failed
2492 *
2493 */
2494 esp_err_t esp_ble_gap_start_ext_scan(uint32_t duration, uint16_t period);
2495 
2496 /**
2497 * @brief           This function is used to disable scanning.
2498 *
2499 * @return            - ESP_OK : success
2500 *                    - other  : failed
2501 *
2502 */
2503 esp_err_t esp_ble_gap_stop_ext_scan(void);
2504 
2505 /**
2506 * @brief           This function is used to synchronize with periodic advertising from an advertiser and begin receiving periodic advertising packets.
2507 *
2508 * @param[in]       params : sync parameters
2509 *
2510 * @return            - ESP_OK : success
2511 *                    - other  : failed
2512 *
2513 */
2514 esp_err_t esp_ble_gap_periodic_adv_create_sync(const esp_ble_gap_periodic_adv_sync_params_t *params);
2515 
2516 /**
2517 * @brief           This function is used to cancel the LE_Periodic_Advertising_Create_Sync command while it is pending.
2518 *
2519 *
2520 * @return            - ESP_OK : success
2521 *                    - other  : failed
2522 *
2523 */
2524 esp_err_t esp_ble_gap_periodic_adv_sync_cancel(void);
2525 
2526 /**
2527 * @brief           This function is used to stop reception of the periodic advertising identified by the Sync Handle parameter.
2528 *
2529 * @param[in]       sync_handle : identify the periodic advertiser
2530 *
2531 * @return            - ESP_OK : success
2532 *                    - other  : failed
2533 *
2534 */
2535 esp_err_t esp_ble_gap_periodic_adv_sync_terminate(uint16_t sync_handle);
2536 
2537 /**
2538 * @brief           This function is used to add a single device to the Periodic Advertiser list stored in the Controller
2539 *
2540 * @param[in]       addr_type : address type
2541 * @param[in]       addr : Device Address
2542 * @param[in]       sid : Advertising SID subfield in the ADI field used to identify the Periodic Advertising
2543 *
2544 * @return            - ESP_OK : success
2545 *                    - other  : failed
2546 *
2547 */
2548 esp_err_t esp_ble_gap_periodic_adv_add_dev_to_list(esp_ble_addr_type_t addr_type,
2549                                                                          esp_bd_addr_t addr,
2550                                                                          uint8_t sid);
2551 
2552 /**
2553 * @brief           This function is used to remove one device from the list of Periodic Advertisers stored in the Controller.
2554 *                  Removals from the Periodic Advertisers List take effect immediately.
2555 *
2556 * @param[in]       addr_type : address type
2557 * @param[in]       addr : Device Address
2558 * @param[in]       sid : Advertising SID subfield in the ADI field used to identify the Periodic Advertising
2559 *
2560 * @return            - ESP_OK : success
2561 *                    - other  : failed
2562 *
2563 */
2564 esp_err_t esp_ble_gap_periodic_adv_remove_dev_from_list(esp_ble_addr_type_t addr_type,
2565                                                                          esp_bd_addr_t addr,
2566                                                                          uint8_t sid);
2567 /**
2568 * @brief           This function is used to remove all devices from the list of Periodic Advertisers in the Controller.
2569 *
2570 * @return            - ESP_OK : success
2571 *                    - other  : failed
2572 *
2573 */
2574 esp_err_t esp_ble_gap_periodic_adv_clear_dev(void);
2575 
2576 /**
2577 * @brief           This function is used to set aux connection parameters
2578 *
2579 * @param[in]       addr : device address
2580 * @param[in]       phy_mask : indicates the PHY(s) on which the advertising packets should be received on the primary advertising channel and the PHYs for which connection parameters have been specified.
2581 * @param[in]       phy_1m_conn_params : Scan connectable advertisements on the LE 1M PHY. Connection parameters for the LE 1M PHY are provided.
2582 * @param[in]       phy_2m_conn_params : Connection parameters for the LE 2M PHY are provided.
2583 * @param[in]       phy_coded_conn_params : Scan connectable advertisements on the LE Coded PHY. Connection parameters for the LE Coded PHY are provided.
2584 *
2585 * @return            - ESP_OK : success
2586 *                    - other  : failed
2587 *
2588 */
2589 esp_err_t esp_ble_gap_prefer_ext_connect_params_set(esp_bd_addr_t addr,
2590                                                     esp_ble_gap_phy_mask_t phy_mask,
2591                                                     const esp_ble_gap_conn_params_t *phy_1m_conn_params,
2592                                                     const esp_ble_gap_conn_params_t *phy_2m_conn_params,
2593                                                     const esp_ble_gap_conn_params_t *phy_coded_conn_params);
2594 
2595 #endif //#if (BLE_50_FEATURE_SUPPORT == TRUE)
2596 
2597 #if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
2598 /**
2599 * @brief           This function is used to set periodic advertising receive enable
2600 *
2601 * @param[in]       sync_handle : Handle of periodic advertising sync
2602 * @param[in]       enable : Determines whether reporting and duplicate filtering are enabled or disabled
2603 *
2604 * @return            - ESP_OK : success
2605 *                    - other  : failed
2606 *
2607 */
2608 esp_err_t esp_ble_gap_periodic_adv_recv_enable(uint16_t sync_handle, uint8_t enable);
2609 
2610 /**
2611 * @brief           This function is used to transfer periodic advertising sync
2612 *
2613 * @param[in]       addr : Peer device address
2614 * @param[in]       service_data : Service data used by Host
2615 * @param[in]       sync_handle : Handle of periodic advertising sync
2616 *
2617 * @return            - ESP_OK : success
2618 *                    - other  : failed
2619 *
2620 */
2621 esp_err_t esp_ble_gap_periodic_adv_sync_trans(esp_bd_addr_t addr,
2622                                               uint16_t service_data, uint16_t sync_handle);
2623 
2624 /**
2625 * @brief           This function is used to transfer periodic advertising set info
2626 *
2627 * @param[in]       addr : Peer device address
2628 * @param[in]       service_data : Service data used by Host
2629 * @param[in]       adv_handle : Handle of advertising set
2630 *
2631 * @return            - ESP_OK : success
2632 *                    - other  : failed
2633 *
2634 */
2635 esp_err_t esp_ble_gap_periodic_adv_set_info_trans(esp_bd_addr_t addr,
2636                                                   uint16_t service_data, uint8_t adv_handle);
2637 
2638 /**
2639 * @brief           This function is used to set periodic advertising sync transfer params
2640 *
2641 * @param[in]       addr : Peer device address
2642 * @param[in]       params : Params of periodic advertising sync transfer
2643 *
2644 * @return            - ESP_OK : success
2645 *                    - other  : failed
2646 *
2647 */
2648 esp_err_t esp_ble_gap_set_periodic_adv_sync_trans_params(esp_bd_addr_t addr,
2649                                                          const esp_ble_gap_past_params_t *params);
2650 #endif //#if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
2651 
2652 #if (BLE_42_FEATURE_SUPPORT == TRUE)
2653 
2654 /**
2655 * @brief           This function is used to start a test where the DUT generates reference packets
2656 *                  at a fixed interval.
2657 *
2658 * @param[in]       tx_params : DTM Transmitter parameters
2659 *
2660 * @return            - ESP_OK : success
2661 *                    - other  : failed
2662 *
2663 */
2664 esp_err_t esp_ble_dtm_tx_start(const esp_ble_dtm_tx_t *tx_params);
2665 
2666 /**
2667 * @brief           This function is used to start a test where the DUT receives test reference packets
2668 *                  at a fixed interval.
2669 *
2670 * @param[in]       rx_params : DTM Receiver parameters
2671 *
2672 * @return            - ESP_OK : success
2673 *                    - other  : failed
2674 *
2675 */
2676 esp_err_t esp_ble_dtm_rx_start(const esp_ble_dtm_rx_t *rx_params);
2677 #endif //#if (BLE_42_FEATURE_SUPPORT == TRUE)
2678 
2679 #if (BLE_50_FEATURE_SUPPORT == TRUE)
2680 
2681 /**
2682 * @brief           This function is used to start a test where the DUT generates reference packets
2683 *                  at a fixed interval.
2684 *
2685 * @param[in]       tx_params : DTM Transmitter parameters
2686 *
2687 * @return            - ESP_OK : success
2688 *                    - other  : failed
2689 *
2690 */
2691 esp_err_t esp_ble_dtm_enh_tx_start(const esp_ble_dtm_enh_tx_t *tx_params);
2692 
2693 /**
2694 * @brief           This function is used to start a test where the DUT receives test reference packets
2695 *                  at a fixed interval.
2696 *
2697 * @param[in]       rx_params : DTM Receiver parameters
2698 *
2699 * @return            - ESP_OK : success
2700 *                    - other  : failed
2701 *
2702 */
2703 esp_err_t esp_ble_dtm_enh_rx_start(const esp_ble_dtm_enh_rx_t *rx_params);
2704 #endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
2705 
2706 /**
2707 * @brief           This function is used to stop any test which is in progress
2708 *
2709 *
2710 * @return            - ESP_OK : success
2711 *                    - other  : failed
2712 *
2713 */
2714 esp_err_t esp_ble_dtm_stop(void);
2715 
2716 /**
2717 * @brief           This function is used to clear legacy advertising
2718 *
2719 *
2720 * @return           - ESP_OK : success
2721 *                   - other  : failed
2722 *
2723 */
2724 esp_err_t esp_ble_gap_clear_advertising(void);
2725 
2726 /**
2727  * @brief           This function is called to send vendor hci command.
2728  *
2729  *
2730  *
2731  * @param[in]       vendor_cmd_param: vendor hci command parameters
2732  *
2733  * @return
2734  *                  - ESP_OK : success
2735  *                  - other  : failed
2736  */
2737 esp_err_t esp_ble_gap_vendor_command_send(esp_ble_vendor_cmd_params_t *vendor_cmd_param);
2738 
2739 /**
2740  * @brief           This function set the privacy mode of the device in resolving list.
2741  *
2742  * @note            This feature is not supported on ESP32.
2743  *
2744  * @param[in]       addr_type: The address type of the peer identity address (BLE_ADDR_TYPE_PUBLIC or BLE_ADDR_TYPE_RANDOM).
2745  * @param[in]       addr: The peer identity address of the device.
2746  * @param[in]       mode: The privacy mode of the device.
2747  *
2748  * @return
2749  *                  - ESP_OK : success
2750  *                  - other  : failed
2751  */
2752 esp_err_t esp_ble_gap_set_privacy_mode(esp_ble_addr_type_t addr_type, esp_bd_addr_t addr, esp_ble_privacy_mode_t mode);
2753 
2754 /**
2755  * @brief           This function is used to set which channel selection algorithm(CSA) is supported.
2756  *
2757  * @note            - This function should only be used when there are BLE compatibility issues about channel hopping after connected.
2758  *                    For example, if the peer device only supports CSA#1, this function can be called to make the Controller use CSA#1.
2759  *                  - This function is not supported on ESP32.
2760  *
2761  * @param[in]       csa_select: 0: Channel Selection Algorighm will be selected by Controller
2762  *                              1: Select the LE Channel Selection Algorighm #1
2763  *                              2: Select the LE Channel Selection Algorighm #2
2764  *
2765  * @return
2766  *                  - ESP_OK : success
2767  *                  - other  : failed
2768  */
2769 esp_err_t esp_ble_gap_set_csa_support(uint8_t csa_select);
2770 
2771 #ifdef __cplusplus
2772 }
2773 #endif
2774 
2775 #endif /* __ESP_GAP_BLE_API_H__ */
2776