1 // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef __ESP_GAP_BLE_API_H__
16 #define __ESP_GAP_BLE_API_H__
17 
18 #include <stdint.h>
19 #include <stdbool.h>
20 
21 #include "esp_err.h"
22 #include "esp_bt_defs.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /**@{
29  * BLE_ADV_DATA_FLAG data flag bit definition used for advertising data flag
30  */
31 #define ESP_BLE_ADV_FLAG_LIMIT_DISC         (0x01 << 0)
32 #define ESP_BLE_ADV_FLAG_GEN_DISC           (0x01 << 1)
33 #define ESP_BLE_ADV_FLAG_BREDR_NOT_SPT      (0x01 << 2)
34 #define ESP_BLE_ADV_FLAG_DMT_CONTROLLER_SPT (0x01 << 3)
35 #define ESP_BLE_ADV_FLAG_DMT_HOST_SPT       (0x01 << 4)
36 #define ESP_BLE_ADV_FLAG_NON_LIMIT_DISC     (0x00 )
37 /**
38  * @}
39  */
40 
41 /* relate to BTM_LE_KEY_xxx in stack/btm_api.h */
42 #define ESP_LE_KEY_NONE                    0                                                                         /* relate to BTM_LE_KEY_NONE in stack/btm_api.h */
43 #define ESP_LE_KEY_PENC                    (1 << 0)   /*!< encryption key, encryption information of peer device */  /* relate to BTM_LE_KEY_PENC in stack/btm_api.h */
44 #define ESP_LE_KEY_PID                     (1 << 1)   /*!< identity key of the peer device */                        /* relate to BTM_LE_KEY_PID in stack/btm_api.h */
45 #define ESP_LE_KEY_PCSRK                   (1 << 2)   /*!< peer SRK */                                               /* relate to BTM_LE_KEY_PCSRK in stack/btm_api.h */
46 #define ESP_LE_KEY_PLK                     (1 << 3)   /*!< Link key*/                                                /* relate to BTM_LE_KEY_PLK in stack/btm_api.h */
47 #define ESP_LE_KEY_LLK                     (ESP_LE_KEY_PLK << 4)                                                     /* relate to BTM_LE_KEY_LLK in stack/btm_api.h */
48 #define ESP_LE_KEY_LENC                    (ESP_LE_KEY_PENC << 4)   /*!< master role security information:div */     /* relate to BTM_LE_KEY_LENC in stack/btm_api.h */
49 #define ESP_LE_KEY_LID                     (ESP_LE_KEY_PID << 4)    /*!< master device ID key */                     /* relate to BTM_LE_KEY_LID in stack/btm_api.h */
50 #define ESP_LE_KEY_LCSRK                   (ESP_LE_KEY_PCSRK << 4)  /*!< local CSRK has been deliver to peer */      /* relate to BTM_LE_KEY_LCSRK in stack/btm_api.h */
51 typedef uint8_t esp_ble_key_type_t;
52 
53 /* relate to BTM_LE_AUTH_xxx in stack/btm_api.h */
54 #define ESP_LE_AUTH_NO_BOND                 0x00                                     /*!< 0*/                     /* relate to BTM_LE_AUTH_NO_BOND in stack/btm_api.h */
55 #define ESP_LE_AUTH_BOND                    0x01                                     /*!< 1 << 0 */               /* relate to BTM_LE_AUTH_BOND in stack/btm_api.h */
56 #define ESP_LE_AUTH_REQ_MITM                (1 << 2)                                 /*!< 1 << 2 */               /* relate to BTM_LE_AUTH_REQ_MITM in stack/btm_api.h */
57 #define ESP_LE_AUTH_REQ_BOND_MITM           (ESP_LE_AUTH_BOND | ESP_LE_AUTH_REQ_MITM)/*!< 0101*/
58 #define ESP_LE_AUTH_REQ_SC_ONLY             (1 << 3)                                 /*!< 1 << 3 */               /* relate to BTM_LE_AUTH_REQ_SC_ONLY in stack/btm_api.h */
59 #define ESP_LE_AUTH_REQ_SC_BOND             (ESP_LE_AUTH_BOND | ESP_LE_AUTH_REQ_SC_ONLY)            /*!< 1001 */  /* relate to BTM_LE_AUTH_REQ_SC_BOND in stack/btm_api.h */
60 #define ESP_LE_AUTH_REQ_SC_MITM             (ESP_LE_AUTH_REQ_MITM | ESP_LE_AUTH_REQ_SC_ONLY)        /*!< 1100 */  /* relate to BTM_LE_AUTH_REQ_SC_MITM in stack/btm_api.h */
61 #define ESP_LE_AUTH_REQ_SC_MITM_BOND        (ESP_LE_AUTH_REQ_MITM | ESP_LE_AUTH_REQ_SC_ONLY | ESP_LE_AUTH_BOND)   /*!< 1101 */  /* relate to BTM_LE_AUTH_REQ_SC_MITM_BOND in stack/btm_api.h */
62 typedef uint8_t   esp_ble_auth_req_t;         /*!< combination of the above bit pattern */
63 
64 #define ESP_BLE_ONLY_ACCEPT_SPECIFIED_AUTH_DISABLE 0
65 #define ESP_BLE_ONLY_ACCEPT_SPECIFIED_AUTH_ENABLE  1
66 
67 #define ESP_BLE_OOB_DISABLE 0
68 #define ESP_BLE_OOB_ENABLE  1
69 
70 /* relate to BTM_IO_CAP_xxx in stack/btm_api.h */
71 #define ESP_IO_CAP_OUT                      0   /*!< DisplayOnly */         /* relate to BTM_IO_CAP_OUT in stack/btm_api.h */
72 #define ESP_IO_CAP_IO                       1   /*!< DisplayYesNo */        /* relate to BTM_IO_CAP_IO in stack/btm_api.h */
73 #define ESP_IO_CAP_IN                       2   /*!< KeyboardOnly */        /* relate to BTM_IO_CAP_IN in stack/btm_api.h */
74 #define ESP_IO_CAP_NONE                     3   /*!< NoInputNoOutput */     /* relate to BTM_IO_CAP_NONE in stack/btm_api.h */
75 #define ESP_IO_CAP_KBDISP                   4   /*!< Keyboard display */    /* relate to BTM_IO_CAP_KBDISP in stack/btm_api.h */
76 
77 #define ESP_BLE_APPEARANCE_UNKNOWN                 0x0000 /* relate to BTM_BLE_APPEARANCE_UNKNOWN in stack/btm_ble_api.h */
78 #define ESP_BLE_APPEARANCE_GENERIC_PHONE           0x0040 /* relate to BTM_BLE_APPEARANCE_GENERIC_PHONE in stack/btm_ble_api.h */
79 #define ESP_BLE_APPEARANCE_GENERIC_COMPUTER        0x0080 /* relate to BTM_BLE_APPEARANCE_GENERIC_COMPUTER in stack/btm_ble_api.h */
80 #define ESP_BLE_APPEARANCE_GENERIC_WATCH           0x00C0 /* relate to BTM_BLE_APPEARANCE_GENERIC_WATCH in stack/btm_ble_api.h */
81 #define ESP_BLE_APPEARANCE_SPORTS_WATCH            0x00C1 /* relate to BTM_BLE_APPEARANCE_SPORTS_WATCH in stack/btm_ble_api.h */
82 #define ESP_BLE_APPEARANCE_GENERIC_CLOCK           0x0100 /* relate to BTM_BLE_APPEARANCE_GENERIC_CLOCK in stack/btm_ble_api.h */
83 #define ESP_BLE_APPEARANCE_GENERIC_DISPLAY         0x0140 /* relate to BTM_BLE_APPEARANCE_GENERIC_DISPLAY in stack/btm_ble_api.h */
84 #define ESP_BLE_APPEARANCE_GENERIC_REMOTE          0x0180 /* relate to BTM_BLE_APPEARANCE_GENERIC_REMOTE in stack/btm_ble_api.h */
85 #define ESP_BLE_APPEARANCE_GENERIC_EYEGLASSES      0x01C0 /* relate to BTM_BLE_APPEARANCE_GENERIC_EYEGLASSES in stack/btm_ble_api.h */
86 #define ESP_BLE_APPEARANCE_GENERIC_TAG             0x0200 /* relate to BTM_BLE_APPEARANCE_GENERIC_TAG in stack/btm_ble_api.h */
87 #define ESP_BLE_APPEARANCE_GENERIC_KEYRING         0x0240 /* relate to BTM_BLE_APPEARANCE_GENERIC_KEYRING in stack/btm_ble_api.h */
88 #define ESP_BLE_APPEARANCE_GENERIC_MEDIA_PLAYER    0x0280 /* relate to BTM_BLE_APPEARANCE_GENERIC_MEDIA_PLAYER in stack/btm_ble_api.h */
89 #define ESP_BLE_APPEARANCE_GENERIC_BARCODE_SCANNER 0x02C0 /* relate to BTM_BLE_APPEARANCE_GENERIC_BARCODE_SCANNER in stack/btm_ble_api.h */
90 #define ESP_BLE_APPEARANCE_GENERIC_THERMOMETER     0x0300 /* relate to BTM_BLE_APPEARANCE_GENERIC_THERMOMETER in stack/btm_ble_api.h */
91 #define ESP_BLE_APPEARANCE_THERMOMETER_EAR         0x0301 /* relate to BTM_BLE_APPEARANCE_THERMOMETER_EAR in stack/btm_ble_api.h */
92 #define ESP_BLE_APPEARANCE_GENERIC_HEART_RATE      0x0340 /* relate to BTM_BLE_APPEARANCE_GENERIC_HEART_RATE in stack/btm_ble_api.h */
93 #define ESP_BLE_APPEARANCE_HEART_RATE_BELT         0x0341 /* relate to BTM_BLE_APPEARANCE_HEART_RATE_BELT in stack/btm_ble_api.h */
94 #define ESP_BLE_APPEARANCE_GENERIC_BLOOD_PRESSURE  0x0380 /* relate to BTM_BLE_APPEARANCE_GENERIC_BLOOD_PRESSURE in stack/btm_ble_api.h */
95 #define ESP_BLE_APPEARANCE_BLOOD_PRESSURE_ARM      0x0381 /* relate to BTM_BLE_APPEARANCE_BLOOD_PRESSURE_ARM in stack/btm_ble_api.h */
96 #define ESP_BLE_APPEARANCE_BLOOD_PRESSURE_WRIST    0x0382 /* relate to BTM_BLE_APPEARANCE_BLOOD_PRESSURE_WRIST in stack/btm_ble_api.h */
97 #define ESP_BLE_APPEARANCE_GENERIC_HID             0x03C0 /* relate to BTM_BLE_APPEARANCE_GENERIC_HID in stack/btm_ble_api.h */
98 #define ESP_BLE_APPEARANCE_HID_KEYBOARD            0x03C1 /* relate to BTM_BLE_APPEARANCE_HID_KEYBOARD in stack/btm_ble_api.h */
99 #define ESP_BLE_APPEARANCE_HID_MOUSE               0x03C2 /* relate to BTM_BLE_APPEARANCE_HID_MOUSE in stack/btm_ble_api.h */
100 #define ESP_BLE_APPEARANCE_HID_JOYSTICK            0x03C3 /* relate to BTM_BLE_APPEARANCE_HID_JOYSTICK in stack/btm_ble_api.h */
101 #define ESP_BLE_APPEARANCE_HID_GAMEPAD             0x03C4 /* relate to BTM_BLE_APPEARANCE_HID_GAMEPAD in stack/btm_ble_api.h */
102 #define ESP_BLE_APPEARANCE_HID_DIGITIZER_TABLET    0x03C5 /* relate to BTM_BLE_APPEARANCE_HID_DIGITIZER_TABLET in stack/btm_ble_api.h */
103 #define ESP_BLE_APPEARANCE_HID_CARD_READER         0x03C6 /* relate to BTM_BLE_APPEARANCE_HID_CARD_READER in stack/btm_ble_api.h */
104 #define ESP_BLE_APPEARANCE_HID_DIGITAL_PEN         0x03C7 /* relate to BTM_BLE_APPEARANCE_HID_DIGITAL_PEN in stack/btm_ble_api.h */
105 #define ESP_BLE_APPEARANCE_HID_BARCODE_SCANNER     0x03C8 /* relate to BTM_BLE_APPEARANCE_HID_BARCODE_SCANNER in stack/btm_ble_api.h */
106 #define ESP_BLE_APPEARANCE_GENERIC_GLUCOSE         0x0400 /* relate to BTM_BLE_APPEARANCE_GENERIC_GLUCOSE in stack/btm_ble_api.h */
107 #define ESP_BLE_APPEARANCE_GENERIC_WALKING         0x0440 /* relate to BTM_BLE_APPEARANCE_GENERIC_WALKING in stack/btm_ble_api.h */
108 #define ESP_BLE_APPEARANCE_WALKING_IN_SHOE         0x0441 /* relate to BTM_BLE_APPEARANCE_WALKING_IN_SHOE in stack/btm_ble_api.h */
109 #define ESP_BLE_APPEARANCE_WALKING_ON_SHOE         0x0442 /* relate to BTM_BLE_APPEARANCE_WALKING_ON_SHOE in stack/btm_ble_api.h */
110 #define ESP_BLE_APPEARANCE_WALKING_ON_HIP          0x0443 /* relate to BTM_BLE_APPEARANCE_WALKING_ON_HIP in stack/btm_ble_api.h */
111 #define ESP_BLE_APPEARANCE_GENERIC_CYCLING         0x0480 /* relate to BTM_BLE_APPEARANCE_GENERIC_CYCLING in stack/btm_ble_api.h */
112 #define ESP_BLE_APPEARANCE_CYCLING_COMPUTER        0x0481 /* relate to BTM_BLE_APPEARANCE_CYCLING_COMPUTER in stack/btm_ble_api.h */
113 #define ESP_BLE_APPEARANCE_CYCLING_SPEED           0x0482 /* relate to BTM_BLE_APPEARANCE_CYCLING_SPEED in stack/btm_ble_api.h */
114 #define ESP_BLE_APPEARANCE_CYCLING_CADENCE         0x0483 /* relate to BTM_BLE_APPEARANCE_CYCLING_CADENCE in stack/btm_ble_api.h */
115 #define ESP_BLE_APPEARANCE_CYCLING_POWER           0x0484 /* relate to BTM_BLE_APPEARANCE_CYCLING_POWER in stack/btm_ble_api.h */
116 #define ESP_BLE_APPEARANCE_CYCLING_SPEED_CADENCE   0x0485 /* relate to BTM_BLE_APPEARANCE_CYCLING_SPEED_CADENCE in stack/btm_ble_api.h */
117 #define ESP_BLE_APPEARANCE_GENERIC_PULSE_OXIMETER  0x0C40 /* relate to BTM_BLE_APPEARANCE_GENERIC_PULSE_OXIMETER in stack/btm_ble_api.h */
118 #define ESP_BLE_APPEARANCE_PULSE_OXIMETER_FINGERTIP 0x0C41 /* relate to BTM_BLE_APPEARANCE_PULSE_OXIMETER_FINGERTIP in stack/btm_ble_api.h */
119 #define ESP_BLE_APPEARANCE_PULSE_OXIMETER_WRIST    0x0C42 /* relate to BTM_BLE_APPEARANCE_PULSE_OXIMETER_WRIST in stack/btm_ble_api.h */
120 #define ESP_BLE_APPEARANCE_GENERIC_WEIGHT          0x0C80 /* relate to BTM_BLE_APPEARANCE_GENERIC_WEIGHT in stack/btm_ble_api.h */
121 #define ESP_BLE_APPEARANCE_GENERIC_PERSONAL_MOBILITY_DEVICE    0x0CC0 /* relate to BTM_BLE_APPEARANCE_GENERIC_PERSONAL_MOBILITY_DEVICE in stack/btm_ble_api.h */
122 #define ESP_BLE_APPEARANCE_POWERED_WHEELCHAIR                  0x0CC1 /* relate to BTM_BLE_APPEARANCE_POWERED_WHEELCHAIR in stack/btm_ble_api.h */
123 #define ESP_BLE_APPEARANCE_MOBILITY_SCOOTER                    0x0CC2 /* relate to BTM_BLE_APPEARANCE_MOBILITY_SCOOTER in stack/btm_ble_api.h */
124 #define ESP_BLE_APPEARANCE_GENERIC_CONTINUOUS_GLUCOSE_MONITOR  0x0D00 /* relate to BTM_BLE_APPEARANCE_GENERIC_CONTINUOUS_GLUCOSE_MONITOR in stack/btm_ble_api.h */
125 #define ESP_BLE_APPEARANCE_GENERIC_INSULIN_PUMP                0x0D40 /* relate to BTM_BLE_APPEARANCE_GENERIC_INSULIN_PUMP in stack/btm_ble_api.h */
126 #define ESP_BLE_APPEARANCE_INSULIN_PUMP_DURABLE_PUMP           0x0D41 /* relate to BTM_BLE_APPEARANCE_INSULIN_PUMP_DURABLE_PUMP in stack/btm_ble_api.h */
127 #define ESP_BLE_APPEARANCE_INSULIN_PUMP_PATCH_PUMP             0x0D44 /* relate to BTM_BLE_APPEARANCE_INSULIN_PUMP_PATCH_PUMP in stack/btm_ble_api.h */
128 #define ESP_BLE_APPEARANCE_INSULIN_PEN                         0x0D48 /* relate to BTM_BLE_APPEARANCE_INSULIN_PEN in stack/btm_ble_api.h */
129 #define ESP_BLE_APPEARANCE_GENERIC_MEDICATION_DELIVERY         0x0D80 /* relate to BTM_BLE_APPEARANCE_GENERIC_MEDICATION_DELIVERY in stack/btm_ble_api.h */
130 #define ESP_BLE_APPEARANCE_GENERIC_OUTDOOR_SPORTS  0x1440             /* relate to BTM_BLE_APPEARANCE_GENERIC_OUTDOOR_SPORTS in stack/btm_ble_api.h */
131 #define ESP_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION 0x1441             /* relate to BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION in stack/btm_ble_api.h */
132 #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 */
133 #define ESP_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_POD         0x1443 /* relate to BTM_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_POD in stack/btm_ble_api.h */
134 #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 */
135 
136 typedef uint8_t esp_ble_io_cap_t;               /*!< combination of the io capability */
137 
138 /// GAP BLE callback event type
139 typedef enum {
140 #if (BLE_42_FEATURE_SUPPORT == TRUE)
141     ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT        = 0,       /*!< When advertising data set complete, the event comes */
142     ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT,             /*!< When scan response data set complete, the event comes */
143     ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT,                /*!< When scan parameters set complete, the event comes */
144     ESP_GAP_BLE_SCAN_RESULT_EVT,                            /*!< When one scan result ready, the event comes each time */
145     ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT,              /*!< When raw advertising data set complete, the event comes */
146     ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT,         /*!< When raw advertising data set complete, the event comes */
147     ESP_GAP_BLE_ADV_START_COMPLETE_EVT,                     /*!< When start advertising complete, the event comes */
148     ESP_GAP_BLE_SCAN_START_COMPLETE_EVT,                    /*!< When start scan complete, the event comes */
149 #endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
150     ESP_GAP_BLE_AUTH_CMPL_EVT = 8,                          /* Authentication complete indication. */
151     ESP_GAP_BLE_KEY_EVT,                                    /* BLE  key event for peer device keys */
152     ESP_GAP_BLE_SEC_REQ_EVT,                                /* BLE  security request */
153     ESP_GAP_BLE_PASSKEY_NOTIF_EVT,                          /* passkey notification event */
154     ESP_GAP_BLE_PASSKEY_REQ_EVT,                            /* passkey request event */
155     ESP_GAP_BLE_OOB_REQ_EVT,                                /* OOB request event */
156     ESP_GAP_BLE_LOCAL_IR_EVT,                               /* BLE local IR event */
157     ESP_GAP_BLE_LOCAL_ER_EVT,                               /* BLE local ER event */
158     ESP_GAP_BLE_NC_REQ_EVT,                                 /* Numeric Comparison request event */
159 #if (BLE_42_FEATURE_SUPPORT == TRUE)
160     ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT,                      /*!< When stop adv complete, the event comes */
161     ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT,                     /*!< When stop scan complete, the event comes */
162 #endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
163     ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT = 19,              /*!< When set the static rand address complete, the event comes */
164     ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT,                     /*!< When update connection parameters complete, the event comes */
165     ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT,                /*!< When set pkt length complete, the event comes */
166     ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT,             /*!< When  Enable/disable privacy on the local device complete, the event comes */
167     ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT,               /*!< When remove the bond device complete, the event comes */
168     ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT,                /*!< When clear the bond device clear complete, the event comes */
169     ESP_GAP_BLE_GET_BOND_DEV_COMPLETE_EVT,                  /*!< When get the bond device list complete, the event comes */
170     ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT,                     /*!< When read the rssi complete, the event comes */
171     ESP_GAP_BLE_UPDATE_WHITELIST_COMPLETE_EVT,              /*!< When add or remove whitelist complete, the event comes */
172 #if (BLE_42_FEATURE_SUPPORT == TRUE)
173     ESP_GAP_BLE_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_COMPLETE_EVT,  /*!< When update duplicate exceptional list complete, the event comes */
174 #endif //#if (BLE_42_FEATURE_SUPPORT == TRUE)
175     ESP_GAP_BLE_SET_CHANNELS_EVT = 29,                           /*!< When setting BLE channels complete, the event comes */
176 #if (BLE_50_FEATURE_SUPPORT == TRUE)
177     ESP_GAP_BLE_READ_PHY_COMPLETE_EVT,
178     ESP_GAP_BLE_SET_PREFERED_DEFAULT_PHY_COMPLETE_EVT,
179     ESP_GAP_BLE_SET_PREFERED_PHY_COMPLETE_EVT,
180     ESP_GAP_BLE_EXT_ADV_SET_RAND_ADDR_COMPLETE_EVT,
181     ESP_GAP_BLE_EXT_ADV_SET_PARAMS_COMPLETE_EVT,
182     ESP_GAP_BLE_EXT_ADV_DATA_SET_COMPLETE_EVT,
183     ESP_GAP_BLE_EXT_SCAN_RSP_DATA_SET_COMPLETE_EVT,
184     ESP_GAP_BLE_EXT_ADV_START_COMPLETE_EVT,
185     ESP_GAP_BLE_EXT_ADV_STOP_COMPLETE_EVT,
186     ESP_GAP_BLE_EXT_ADV_SET_REMOVE_COMPLETE_EVT,
187     ESP_GAP_BLE_EXT_ADV_SET_CLEAR_COMPLETE_EVT,
188     ESP_GAP_BLE_PERIODIC_ADV_SET_PARAMS_COMPLETE_EVT,
189     ESP_GAP_BLE_PERIODIC_ADV_DATA_SET_COMPLETE_EVT,
190     ESP_GAP_BLE_PERIODIC_ADV_START_COMPLETE_EVT,
191     ESP_GAP_BLE_PERIODIC_ADV_STOP_COMPLETE_EVT,
192     ESP_GAP_BLE_PERIODIC_ADV_CREATE_SYNC_COMPLETE_EVT,
193     ESP_GAP_BLE_PERIODIC_ADV_SYNC_CANCEL_COMPLETE_EVT,
194     ESP_GAP_BLE_PERIODIC_ADV_SYNC_TERMINATE_COMPLETE_EVT,
195     ESP_GAP_BLE_PERIODIC_ADV_ADD_DEV_COMPLETE_EVT,
196     ESP_GAP_BLE_PERIODIC_ADV_REMOVE_DEV_COMPLETE_EVT,
197     ESP_GAP_BLE_PERIODIC_ADV_CLEAR_DEV_COMPLETE_EVT,
198     ESP_GAP_BLE_SET_EXT_SCAN_PARAMS_COMPLETE_EVT,
199     ESP_GAP_BLE_EXT_SCAN_START_COMPLETE_EVT,
200     ESP_GAP_BLE_EXT_SCAN_STOP_COMPLETE_EVT,
201     ESP_GAP_BLE_PREFER_EXT_CONN_PARAMS_SET_COMPLETE_EVT,
202     ESP_GAP_BLE_PHY_UPDATE_COMPLETE_EVT,
203     ESP_GAP_BLE_EXT_ADV_REPORT_EVT,
204     ESP_GAP_BLE_SCAN_TIMEOUT_EVT,
205     ESP_GAP_BLE_ADV_TERMINATED_EVT,
206     ESP_GAP_BLE_SCAN_REQ_RECEIVED_EVT,
207     ESP_GAP_BLE_CHANNEL_SELETE_ALGORITHM_EVT,
208     ESP_GAP_BLE_PERIODIC_ADV_REPORT_EVT,
209     ESP_GAP_BLE_PERIODIC_ADV_SYNC_LOST_EVT,
210     ESP_GAP_BLE_PERIODIC_ADV_SYNC_ESTAB_EVT,
211 #endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
212     ESP_GAP_BLE_EVT_MAX,
213 } esp_gap_ble_cb_event_t;
214 
215 #define ESP_GAP_BLE_CHANNELS_LEN     5
216 typedef uint8_t esp_gap_ble_channels[ESP_GAP_BLE_CHANNELS_LEN];
217 
218 /// This is the old name, just for backwards compatibility
219 #define ESP_GAP_BLE_ADD_WHITELIST_COMPLETE_EVT ESP_GAP_BLE_UPDATE_WHITELIST_COMPLETE_EVT
220 
221 /// Advertising data maximum length
222 #define ESP_BLE_ADV_DATA_LEN_MAX               31
223 /// Scan response data maximum length
224 #define ESP_BLE_SCAN_RSP_DATA_LEN_MAX          31
225 
226 /* relate to BTM_BLE_AD_TYPE_xxx in stack/btm_ble_api.h */
227 /// The type of advertising data(not adv_type)
228 typedef enum {
229     ESP_BLE_AD_TYPE_FLAG                     = 0x01,    /* relate to BTM_BLE_AD_TYPE_FLAG in stack/btm_ble_api.h */
230     ESP_BLE_AD_TYPE_16SRV_PART               = 0x02,    /* relate to BTM_BLE_AD_TYPE_16SRV_PART in stack/btm_ble_api.h */
231     ESP_BLE_AD_TYPE_16SRV_CMPL               = 0x03,    /* relate to BTM_BLE_AD_TYPE_16SRV_CMPL in stack/btm_ble_api.h */
232     ESP_BLE_AD_TYPE_32SRV_PART               = 0x04,    /* relate to BTM_BLE_AD_TYPE_32SRV_PART in stack/btm_ble_api.h */
233     ESP_BLE_AD_TYPE_32SRV_CMPL               = 0x05,    /* relate to BTM_BLE_AD_TYPE_32SRV_CMPL in stack/btm_ble_api.h */
234     ESP_BLE_AD_TYPE_128SRV_PART              = 0x06,    /* relate to BTM_BLE_AD_TYPE_128SRV_PART in stack/btm_ble_api.h */
235     ESP_BLE_AD_TYPE_128SRV_CMPL              = 0x07,    /* relate to BTM_BLE_AD_TYPE_128SRV_CMPL in stack/btm_ble_api.h */
236     ESP_BLE_AD_TYPE_NAME_SHORT               = 0x08,    /* relate to BTM_BLE_AD_TYPE_NAME_SHORT in stack/btm_ble_api.h */
237     ESP_BLE_AD_TYPE_NAME_CMPL                = 0x09,    /* relate to BTM_BLE_AD_TYPE_NAME_CMPL in stack/btm_ble_api.h */
238     ESP_BLE_AD_TYPE_TX_PWR                   = 0x0A,    /* relate to BTM_BLE_AD_TYPE_TX_PWR in stack/btm_ble_api.h */
239     ESP_BLE_AD_TYPE_DEV_CLASS                = 0x0D,    /* relate to BTM_BLE_AD_TYPE_DEV_CLASS in stack/btm_ble_api.h */
240     ESP_BLE_AD_TYPE_SM_TK                    = 0x10,    /* relate to BTM_BLE_AD_TYPE_SM_TK in stack/btm_ble_api.h */
241     ESP_BLE_AD_TYPE_SM_OOB_FLAG              = 0x11,    /* relate to BTM_BLE_AD_TYPE_SM_OOB_FLAG in stack/btm_ble_api.h */
242     ESP_BLE_AD_TYPE_INT_RANGE                = 0x12,    /* relate to BTM_BLE_AD_TYPE_INT_RANGE in stack/btm_ble_api.h */
243     ESP_BLE_AD_TYPE_SOL_SRV_UUID             = 0x14,    /* relate to BTM_BLE_AD_TYPE_SOL_SRV_UUID in stack/btm_ble_api.h */
244     ESP_BLE_AD_TYPE_128SOL_SRV_UUID          = 0x15,    /* relate to BTM_BLE_AD_TYPE_128SOL_SRV_UUID in stack/btm_ble_api.h */
245     ESP_BLE_AD_TYPE_SERVICE_DATA             = 0x16,    /* relate to BTM_BLE_AD_TYPE_SERVICE_DATA in stack/btm_ble_api.h */
246     ESP_BLE_AD_TYPE_PUBLIC_TARGET            = 0x17,    /* relate to BTM_BLE_AD_TYPE_PUBLIC_TARGET in stack/btm_ble_api.h */
247     ESP_BLE_AD_TYPE_RANDOM_TARGET            = 0x18,    /* relate to BTM_BLE_AD_TYPE_RANDOM_TARGET in stack/btm_ble_api.h */
248     ESP_BLE_AD_TYPE_APPEARANCE               = 0x19,    /* relate to BTM_BLE_AD_TYPE_APPEARANCE in stack/btm_ble_api.h */
249     ESP_BLE_AD_TYPE_ADV_INT                  = 0x1A,    /* relate to BTM_BLE_AD_TYPE_ADV_INT in stack/btm_ble_api.h */
250     ESP_BLE_AD_TYPE_LE_DEV_ADDR              = 0x1b,    /* relate to BTM_BLE_AD_TYPE_LE_DEV_ADDR in stack/btm_ble_api.h */
251     ESP_BLE_AD_TYPE_LE_ROLE                  = 0x1c,    /* relate to BTM_BLE_AD_TYPE_LE_ROLE in stack/btm_ble_api.h */
252     ESP_BLE_AD_TYPE_SPAIR_C256               = 0x1d,    /* relate to BTM_BLE_AD_TYPE_SPAIR_C256 in stack/btm_ble_api.h */
253     ESP_BLE_AD_TYPE_SPAIR_R256               = 0x1e,    /* relate to BTM_BLE_AD_TYPE_SPAIR_R256 in stack/btm_ble_api.h */
254     ESP_BLE_AD_TYPE_32SOL_SRV_UUID           = 0x1f,    /* relate to BTM_BLE_AD_TYPE_32SOL_SRV_UUID in stack/btm_ble_api.h */
255     ESP_BLE_AD_TYPE_32SERVICE_DATA           = 0x20,    /* relate to BTM_BLE_AD_TYPE_32SERVICE_DATA in stack/btm_ble_api.h */
256     ESP_BLE_AD_TYPE_128SERVICE_DATA          = 0x21,    /* relate to BTM_BLE_AD_TYPE_128SERVICE_DATA in stack/btm_ble_api.h */
257     ESP_BLE_AD_TYPE_LE_SECURE_CONFIRM        = 0x22,    /* relate to BTM_BLE_AD_TYPE_LE_SECURE_CONFIRM in stack/btm_ble_api.h */
258     ESP_BLE_AD_TYPE_LE_SECURE_RANDOM         = 0x23,    /* relate to BTM_BLE_AD_TYPE_LE_SECURE_RANDOM in stack/btm_ble_api.h */
259     ESP_BLE_AD_TYPE_URI                      = 0x24,    /* relate to BTM_BLE_AD_TYPE_URI in stack/btm_ble_api.h */
260     ESP_BLE_AD_TYPE_INDOOR_POSITION          = 0x25,    /* relate to BTM_BLE_AD_TYPE_INDOOR_POSITION in stack/btm_ble_api.h */
261     ESP_BLE_AD_TYPE_TRANS_DISC_DATA          = 0x26,    /* relate to BTM_BLE_AD_TYPE_TRANS_DISC_DATA in stack/btm_ble_api.h */
262     ESP_BLE_AD_TYPE_LE_SUPPORT_FEATURE       = 0x27,    /* relate to BTM_BLE_AD_TYPE_LE_SUPPORT_FEATURE in stack/btm_ble_api.h */
263     ESP_BLE_AD_TYPE_CHAN_MAP_UPDATE          = 0x28,    /* relate to BTM_BLE_AD_TYPE_CHAN_MAP_UPDATE in stack/btm_ble_api.h */
264     ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE    = 0xFF,    /* relate to BTM_BLE_AD_MANUFACTURER_SPECIFIC_TYPE in stack/btm_ble_api.h */
265 } esp_ble_adv_data_type;
266 
267 /// Advertising mode
268 typedef enum {
269     ADV_TYPE_IND                = 0x00,
270     ADV_TYPE_DIRECT_IND_HIGH    = 0x01,
271     ADV_TYPE_SCAN_IND           = 0x02,
272     ADV_TYPE_NONCONN_IND        = 0x03,
273     ADV_TYPE_DIRECT_IND_LOW     = 0x04,
274 } esp_ble_adv_type_t;
275 
276 /// Advertising channel mask
277 typedef enum {
278     ADV_CHNL_37     = 0x01,
279     ADV_CHNL_38     = 0x02,
280     ADV_CHNL_39     = 0x04,
281     ADV_CHNL_ALL    = 0x07,
282 } esp_ble_adv_channel_t;
283 
284 typedef enum {
285     ///Allow both scan and connection requests from anyone
286     ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY  = 0x00,
287     ///Allow both scan req from White List devices only and connection req from anyone
288     ADV_FILTER_ALLOW_SCAN_WLST_CON_ANY,
289     ///Allow both scan req from anyone and connection req from White List devices only
290     ADV_FILTER_ALLOW_SCAN_ANY_CON_WLST,
291     ///Allow scan and connection requests from White List devices only
292     ADV_FILTER_ALLOW_SCAN_WLST_CON_WLST,
293     ///Enumeration end value for advertising filter policy value check
294 } esp_ble_adv_filter_t;
295 
296 
297 /* relate to BTA_DM_BLE_SEC_xxx in bta/bta_api.h */
298 typedef enum {
299     ESP_BLE_SEC_ENCRYPT = 1,            /* relate to BTA_DM_BLE_SEC_ENCRYPT in bta/bta_api.h. If the device has already
300                                            bonded, the stack will used LTK to encrypt with the remote device directly.
301                                            Else if the device hasn't bonded, the stack will used the default authentication request
302                                            used the esp_ble_gap_set_security_param function set by the user. */
303     ESP_BLE_SEC_ENCRYPT_NO_MITM,        /* relate to BTA_DM_BLE_SEC_ENCRYPT_NO_MITM in bta/bta_api.h. If the device has already
304                                            bonded, the stack will check the LTK Whether the authentication request has been met, if met, used the LTK
305                                            to encrypt with the remote device directly, else Re-pair with the remote device.
306                                            Else if the device hasn't bonded, the stack will used NO MITM authentication request in the current link instead of
307                                            used the authreq in the esp_ble_gap_set_security_param function set by the user. */
308     ESP_BLE_SEC_ENCRYPT_MITM,           /* relate to BTA_DM_BLE_SEC_ENCRYPT_MITM in bta/bta_api.h. If the device has already
309                                            bonded, the stack will check the LTK Whether the authentication request has been met, if met, used the LTK
310                                            to encrypt with the remote device directly, else Re-pair with the remote device.
311                                            Else if the device hasn't bonded, the stack will used MITM authentication request in the current link instead of
312                                            used the authreq in the esp_ble_gap_set_security_param function set by the user. */
313 }esp_ble_sec_act_t;
314 
315 typedef enum {
316     ESP_BLE_SM_PASSKEY = 0,
317     /* Authentication requirements of local device */
318     ESP_BLE_SM_AUTHEN_REQ_MODE,
319     /* The IO capability of local device */
320     ESP_BLE_SM_IOCAP_MODE,
321     /* Initiator Key Distribution/Generation */
322     ESP_BLE_SM_SET_INIT_KEY,
323     /* Responder Key Distribution/Generation */
324     ESP_BLE_SM_SET_RSP_KEY,
325     /* Maximum Encryption key size to support */
326     ESP_BLE_SM_MAX_KEY_SIZE,
327     /* Minimum Encryption key size requirement from Peer */
328     ESP_BLE_SM_MIN_KEY_SIZE,
329     /* Set static Passkey */
330     ESP_BLE_SM_SET_STATIC_PASSKEY,
331     /* Reset static Passkey */
332     ESP_BLE_SM_CLEAR_STATIC_PASSKEY,
333     /* Accept only specified SMP Authentication requirement */
334     ESP_BLE_SM_ONLY_ACCEPT_SPECIFIED_SEC_AUTH,
335     /* Enable/Disable OOB support */
336     ESP_BLE_SM_OOB_SUPPORT,
337     /* Appl encryption key size */
338     ESP_BLE_APP_ENC_KEY_SIZE,
339     ESP_BLE_SM_MAX_PARAM,
340 } esp_ble_sm_param_t;
341 
342 #if (BLE_42_FEATURE_SUPPORT == TRUE)
343 /// Advertising parameters
344 typedef struct {
345     uint16_t                adv_int_min;        /*!< Minimum advertising interval for
346                                                   undirected and low duty cycle directed advertising.
347                                                   Range: 0x0020 to 0x4000 Default: N = 0x0800 (1.28 second)
348                                                   Time = N * 0.625 msec Time Range: 20 ms to 10.24 sec */
349     uint16_t                adv_int_max;        /*!< Maximum advertising interval for
350                                                   undirected and low duty cycle directed advertising.
351                                                   Range: 0x0020 to 0x4000 Default: N = 0x0800 (1.28 second)
352                                                   Time = N * 0.625 msec Time Range: 20 ms to 10.24 sec Advertising max interval */
353     esp_ble_adv_type_t      adv_type;           /*!< Advertising type */
354     esp_ble_addr_type_t     own_addr_type;      /*!< Owner bluetooth device address type */
355     esp_bd_addr_t           peer_addr;          /*!< Peer device bluetooth device address */
356     esp_ble_addr_type_t     peer_addr_type;     /*!< Peer device bluetooth device address type, only support public address type and random address type */
357     esp_ble_adv_channel_t   channel_map;        /*!< Advertising channel map */
358     esp_ble_adv_filter_t    adv_filter_policy;  /*!< Advertising filter policy */
359 } esp_ble_adv_params_t;
360 
361 /// Advertising data content, according to "Supplement to the Bluetooth Core Specification"
362 typedef struct {
363     bool                    set_scan_rsp;           /*!< Set this advertising data as scan response or not*/
364     bool                    include_name;           /*!< Advertising data include device name or not */
365     bool                    include_txpower;        /*!< Advertising data include TX power */
366     int                     min_interval;           /*!< Advertising data show slave preferred connection min interval.
367                                                     The connection interval in the following manner:
368                                                     connIntervalmin = Conn_Interval_Min * 1.25 ms
369                                                     Conn_Interval_Min range: 0x0006 to 0x0C80
370                                                     Value of 0xFFFF indicates no specific minimum.
371                                                     Values not defined above are reserved for future use.*/
372 
373     int                     max_interval;           /*!< Advertising data show slave preferred connection max interval.
374                                                     The connection interval in the following manner:
375                                                     connIntervalmax = Conn_Interval_Max * 1.25 ms
376                                                     Conn_Interval_Max range: 0x0006 to 0x0C80
377                                                     Conn_Interval_Max shall be equal to or greater than the Conn_Interval_Min.
378                                                     Value of 0xFFFF indicates no specific maximum.
379                                                     Values not defined above are reserved for future use.*/
380 
381     int                     appearance;             /*!< External appearance of device */
382     uint16_t                manufacturer_len;       /*!< Manufacturer data length */
383     uint8_t                 *p_manufacturer_data;   /*!< Manufacturer data point */
384     uint16_t                service_data_len;       /*!< Service data length */
385     uint8_t                 *p_service_data;        /*!< Service data point */
386     uint16_t                service_uuid_len;       /*!< Service uuid length */
387     uint8_t                 *p_service_uuid;        /*!< Service uuid array point */
388     uint8_t                 flag;                   /*!< Advertising flag of discovery mode, see BLE_ADV_DATA_FLAG detail */
389 } esp_ble_adv_data_t;
390 
391 #endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
392 
393 /// Ble scan type
394 typedef enum {
395     BLE_SCAN_TYPE_PASSIVE   =   0x0,            /*!< Passive scan */
396     BLE_SCAN_TYPE_ACTIVE    =   0x1,            /*!< Active scan */
397 } esp_ble_scan_type_t;
398 
399 /// Ble scan filter type
400 typedef enum {
401     BLE_SCAN_FILTER_ALLOW_ALL           = 0x0,  /*!< Accept all :
402                                                   1. advertisement packets except directed advertising packets not addressed to this device (default). */
403     BLE_SCAN_FILTER_ALLOW_ONLY_WLST     = 0x1,  /*!< Accept only :
404                                                   1. advertisement packets from devices where the advertiser’s address is in the White list.
405                                                   2. Directed advertising packets which are not addressed for this device shall be ignored. */
406     BLE_SCAN_FILTER_ALLOW_UND_RPA_DIR   = 0x2,  /*!< Accept all :
407                                                   1. undirected advertisement packets, and
408                                                   2. directed advertising packets where the initiator address is a resolvable private address, and
409                                                   3. directed advertising packets addressed to this device. */
410     BLE_SCAN_FILTER_ALLOW_WLIST_RPA_DIR = 0x3,  /*!< Accept all :
411                                                   1. advertisement packets from devices where the advertiser’s address is in the White list, and
412                                                   2. directed advertising packets where the initiator address is a resolvable private address, and
413                                                   3. directed advertising packets addressed to this device.*/
414 } esp_ble_scan_filter_t;
415 
416 /// Ble scan duplicate type
417 typedef enum {
418     BLE_SCAN_DUPLICATE_DISABLE           = 0x0,  /*!< the Link Layer should generate advertising reports to the host for each packet received */
419     BLE_SCAN_DUPLICATE_ENABLE            = 0x1,  /*!< the Link Layer should filter out duplicate advertising reports to the Host */
420     BLE_SCAN_DUPLICATE_MAX               = 0x2,  /*!< 0x02 – 0xFF, Reserved for future use */
421 } esp_ble_scan_duplicate_t;
422 #if (BLE_42_FEATURE_SUPPORT == TRUE)
423 /// Ble scan parameters
424 typedef struct {
425     esp_ble_scan_type_t     scan_type;              /*!< Scan type */
426     esp_ble_addr_type_t     own_addr_type;          /*!< Owner address type */
427     esp_ble_scan_filter_t   scan_filter_policy;     /*!< Scan filter policy */
428     uint16_t                scan_interval;          /*!< Scan interval. This is defined as the time interval from
429                                                       when the Controller started its last LE scan until it begins the subsequent LE scan.
430                                                       Range: 0x0004 to 0x4000 Default: 0x0010 (10 ms)
431                                                       Time = N * 0.625 msec
432                                                       Time Range: 2.5 msec to 10.24 seconds*/
433     uint16_t                scan_window;            /*!< Scan window. The duration of the LE scan. LE_Scan_Window
434                                                       shall be less than or equal to LE_Scan_Interval
435                                                       Range: 0x0004 to 0x4000 Default: 0x0010 (10 ms)
436                                                       Time = N * 0.625 msec
437                                                       Time Range: 2.5 msec to 10240 msec */
438     esp_ble_scan_duplicate_t  scan_duplicate;       /*!< The Scan_Duplicates parameter controls whether the Link Layer should filter out
439                                                         duplicate advertising reports (BLE_SCAN_DUPLICATE_ENABLE) to the Host, or if the Link Layer should generate
440                                                         advertising reports for each packet received */
441 } esp_ble_scan_params_t;
442 #endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
443 /// connection parameters information
444 typedef struct {
445     uint16_t             interval;                  /*!< connection interval */
446     uint16_t             latency;                   /*!< Slave latency for the connection in number of connection events. Range: 0x0000 to 0x01F3 */
447     uint16_t             timeout;                   /*!< Supervision timeout for the LE Link. Range: 0x000A to 0x0C80.
448                                                       Mandatory Range: 0x000A to 0x0C80 Time = N * 10 msec
449                                                       Time Range: 100 msec to 32 seconds */
450 } esp_gap_conn_params_t;
451 
452 /// Connection update parameters
453 typedef struct {
454     esp_bd_addr_t bda;                              /*!< Bluetooth device address */
455     uint16_t min_int;                               /*!< Min connection interval */
456     uint16_t max_int;                               /*!< Max connection interval */
457     uint16_t latency;                               /*!< Slave latency for the connection in number of connection events. Range: 0x0000 to 0x01F3 */
458     uint16_t timeout;                               /*!< Supervision timeout for the LE Link. Range: 0x000A to 0x0C80.
459                                                       Mandatory Range: 0x000A to 0x0C80 Time = N * 10 msec
460                                                       Time Range: 100 msec to 32 seconds */
461 } esp_ble_conn_update_params_t;
462 
463 /**
464 * @brief BLE pkt date length keys
465 */
466 typedef struct
467 {
468     uint16_t rx_len;                   /*!< pkt rx data length value */
469     uint16_t tx_len;                   /*!< pkt tx data length value */
470 } esp_ble_pkt_data_length_params_t;
471 
472 /**
473 * @brief BLE encryption keys
474 */
475 typedef struct
476 {
477     esp_bt_octet16_t     ltk;          /*!< The long term key*/
478     esp_bt_octet8_t      rand;         /*!< The random number*/
479     uint16_t             ediv;         /*!< The ediv value*/
480     uint8_t              sec_level;    /*!< The security level of the security link*/
481     uint8_t              key_size;     /*!< The key size(7~16) of the security link*/
482 } esp_ble_penc_keys_t;                 /*!< The key type*/
483 
484 /**
485 * @brief  BLE CSRK keys
486 */
487 typedef struct
488 {
489     uint32_t            counter;      /*!< The counter */
490     esp_bt_octet16_t    csrk;         /*!< The csrk key */
491     uint8_t             sec_level;    /*!< The security level */
492 } esp_ble_pcsrk_keys_t;               /*!< The pcsrk key type */
493 
494 /**
495 * @brief  BLE pid keys
496 */
497 typedef struct
498 {
499     esp_bt_octet16_t          irk;           /*!< The irk value */
500     esp_ble_addr_type_t       addr_type;     /*!< The address type */
501     esp_bd_addr_t             static_addr;   /*!< The static address */
502 } esp_ble_pid_keys_t;                        /*!< The pid key type */
503 
504 /**
505 * @brief  BLE Encryption reproduction keys
506 */
507 typedef struct
508 {
509     esp_bt_octet16_t  ltk;                  /*!< The long term key */
510     uint16_t          div;                  /*!< The div value */
511     uint8_t           key_size;             /*!< The key size of the security link */
512     uint8_t           sec_level;            /*!< The security level of the security link */
513 } esp_ble_lenc_keys_t;                      /*!< The  key type */
514 
515 /**
516 * @brief  BLE SRK keys
517 */
518 typedef struct
519 {
520     uint32_t          counter;              /*!< The counter value */
521     uint16_t          div;                  /*!< The div value */
522     uint8_t           sec_level;            /*!< The security level of the security link */
523     esp_bt_octet16_t  csrk;                 /*!< The csrk key value */
524 } esp_ble_lcsrk_keys;                       /*!< The csrk key type */
525 
526 /**
527 * @brief  Structure associated with ESP_KEY_NOTIF_EVT
528 */
529 typedef struct
530 {
531     esp_bd_addr_t  bd_addr;        /*!< peer address */
532     uint32_t       passkey;        /*!< the numeric value for comparison. If just_works, do not show this number to UI */
533 } esp_ble_sec_key_notif_t;         /*!< BLE key notify type*/
534 
535 /**
536 * @brief  Structure of the security request
537 */
538 typedef struct
539 {
540     esp_bd_addr_t  bd_addr;        /*!< peer address */
541 } esp_ble_sec_req_t;               /*!< BLE security request type*/
542 
543 /**
544 * @brief  union type of the security key value
545 */
546 typedef union
547 {
548     esp_ble_penc_keys_t   penc_key;       /*!< received peer encryption key */
549     esp_ble_pcsrk_keys_t  pcsrk_key;      /*!< received peer device SRK */
550     esp_ble_pid_keys_t    pid_key;        /*!< peer device ID key */
551     esp_ble_lenc_keys_t   lenc_key;       /*!< local encryption reproduction keys LTK = = d1(ER,DIV,0)*/
552     esp_ble_lcsrk_keys    lcsrk_key;      /*!< local device CSRK = d1(ER,DIV,1)*/
553 } esp_ble_key_value_t;                    /*!< ble key value type*/
554 
555 /**
556 * @brief  struct type of the bond key information value
557 */
558 typedef struct
559 {
560     esp_ble_key_mask_t    key_mask;       /*!< the key mask to indicate witch key is present */
561     esp_ble_penc_keys_t   penc_key;       /*!< received peer encryption key */
562     esp_ble_pcsrk_keys_t  pcsrk_key;      /*!< received peer device SRK */
563     esp_ble_pid_keys_t    pid_key;        /*!< peer device ID key */
564 } esp_ble_bond_key_info_t;                /*!< ble bond key information value type */
565 
566 /**
567 * @brief  struct type of the bond device value
568 */
569 typedef struct
570 {
571     esp_bd_addr_t  bd_addr;               /*!< peer address */
572     esp_ble_bond_key_info_t bond_key;     /*!< the bond key information */
573 } esp_ble_bond_dev_t;                     /*!< the ble bond device type */
574 
575 
576 /**
577 * @brief  union type of the security key value
578 */
579 typedef struct
580 {
581     esp_bd_addr_t               bd_addr;        /*!< peer address */
582     esp_ble_key_type_t          key_type;       /*!< key type of the security link */
583     esp_ble_key_value_t         p_key_value;    /*!< the pointer to the key value */
584 } esp_ble_key_t;                                /*!< the union to the ble key value type*/
585 
586 /**
587 * @brief  structure type of the ble local id keys value
588 */
589 typedef struct {
590     esp_bt_octet16_t       ir;                  /*!< the 16 bits of the ir value */
591     esp_bt_octet16_t       irk;                 /*!< the 16 bits of the ir key value */
592     esp_bt_octet16_t       dhk;                 /*!< the 16 bits of the dh key value */
593 } esp_ble_local_id_keys_t;                      /*!< the structure of the ble local id keys value type*/
594 
595 
596 /**
597   * @brief Structure associated with ESP_AUTH_CMPL_EVT
598   */
599 typedef struct
600 {
601     esp_bd_addr_t         bd_addr;               /*!< BD address peer device. */
602     bool                  key_present;           /*!< Valid link key value in key element */
603     esp_link_key          key;                   /*!< Link key associated with peer device. */
604     uint8_t               key_type;              /*!< The type of Link Key */
605     bool                  success;               /*!< TRUE of authentication succeeded, FALSE if failed. */
606     uint8_t               fail_reason;           /*!< The HCI reason/error code for when success=FALSE */
607     esp_ble_addr_type_t   addr_type;             /*!< Peer device address type */
608     esp_bt_dev_type_t     dev_type;              /*!< Device type */
609     esp_ble_auth_req_t    auth_mode;             /*!< authentication mode */
610 } esp_ble_auth_cmpl_t;                           /*!< The ble authentication complete cb type */
611 
612 /**
613   * @brief union associated with ble security
614   */
615 typedef union
616 {
617     esp_ble_sec_key_notif_t    key_notif;      /*!< passkey notification */
618     esp_ble_sec_req_t          ble_req;        /*!< BLE SMP related request */
619     esp_ble_key_t              ble_key;        /*!< BLE SMP keys used when pairing */
620     esp_ble_local_id_keys_t    ble_id_keys;    /*!< BLE IR event */
621     esp_ble_auth_cmpl_t        auth_cmpl;      /*!< Authentication complete indication. */
622 } esp_ble_sec_t;                               /*!< BLE security type */
623 #if (BLE_42_FEATURE_SUPPORT == TRUE)
624 /// Sub Event of ESP_GAP_BLE_SCAN_RESULT_EVT
625 typedef enum {
626     ESP_GAP_SEARCH_INQ_RES_EVT             = 0,      /*!< Inquiry result for a peer device. */
627     ESP_GAP_SEARCH_INQ_CMPL_EVT            = 1,      /*!< Inquiry complete. */
628     ESP_GAP_SEARCH_DISC_RES_EVT            = 2,      /*!< Discovery result for a peer device. */
629     ESP_GAP_SEARCH_DISC_BLE_RES_EVT        = 3,      /*!< Discovery result for BLE GATT based service on a peer device. */
630     ESP_GAP_SEARCH_DISC_CMPL_EVT           = 4,      /*!< Discovery complete. */
631     ESP_GAP_SEARCH_DI_DISC_CMPL_EVT        = 5,      /*!< Discovery complete. */
632     ESP_GAP_SEARCH_SEARCH_CANCEL_CMPL_EVT  = 6,      /*!< Search cancelled */
633     ESP_GAP_SEARCH_INQ_DISCARD_NUM_EVT     = 7,      /*!< The number of pkt discarded by flow control */
634 } esp_gap_search_evt_t;
635 #endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
636 /**
637  * @brief Ble scan result event type, to indicate the
638  *        result is scan response or advertising data or other
639  */
640 typedef enum {
641     ESP_BLE_EVT_CONN_ADV         = 0x00,        /*!< Connectable undirected advertising (ADV_IND) */
642     ESP_BLE_EVT_CONN_DIR_ADV     = 0x01,        /*!< Connectable directed advertising (ADV_DIRECT_IND) */
643     ESP_BLE_EVT_DISC_ADV         = 0x02,        /*!< Scannable undirected advertising (ADV_SCAN_IND) */
644     ESP_BLE_EVT_NON_CONN_ADV     = 0x03,        /*!< Non connectable undirected advertising (ADV_NONCONN_IND) */
645     ESP_BLE_EVT_SCAN_RSP         = 0x04,        /*!< Scan Response (SCAN_RSP) */
646 } esp_ble_evt_type_t;
647 
648 typedef enum{
649     ESP_BLE_WHITELIST_REMOVE     = 0X00,    /*!< remove mac from whitelist */
650     ESP_BLE_WHITELIST_ADD        = 0X01,    /*!< add address to whitelist */
651 } esp_ble_wl_opration_t;
652 #if (BLE_42_FEATURE_SUPPORT == TRUE)
653 typedef enum {
654     ESP_BLE_DUPLICATE_EXCEPTIONAL_LIST_ADD      = 0,  /*!< Add device info into duplicate scan exceptional list */
655     ESP_BLE_DUPLICATE_EXCEPTIONAL_LIST_REMOVE,        /*!< Remove device info from duplicate scan exceptional list */
656     ESP_BLE_DUPLICATE_EXCEPTIONAL_LIST_CLEAN,         /*!< Clean duplicate scan exceptional list */
657 } esp_bt_duplicate_exceptional_subcode_type_t;
658 #endif //#if (BLE_42_FEATURE_SUPPORT == TRUE)
659 
660 #define BLE_BIT(n) (1UL<<(n))
661 #if (BLE_42_FEATURE_SUPPORT == TRUE)
662 typedef enum {
663     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 */
664     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 */
665     ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_INFO_MESH_BEACON_TYPE,    /*!< BLE mesh beacon AD type, the format is | Len | 0x2B | Beacon Type | Beacon Data | */
666     ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_INFO_MESH_PROV_SRV_ADV,   /*!< BLE mesh provisioning service uuid, the format is | 0x02 | 0x01 | flags | 0x03 | 0x03 | 0x1827 | .... |` */
667     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 | .... |` */
668 } esp_ble_duplicate_exceptional_info_type_t;
669 
670 typedef enum {
671     ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_ADDR_LIST                  = BLE_BIT(0),             /*!< duplicate scan exceptional addr list */
672     ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_MESH_LINK_ID_LIST          = BLE_BIT(1),             /*!< duplicate scan exceptional mesh link ID list */
673     ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_MESH_BEACON_TYPE_LIST      = BLE_BIT(2),             /*!< duplicate scan exceptional mesh beacon type list */
674     ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_MESH_PROV_SRV_ADV_LIST     = BLE_BIT(3),             /*!< duplicate scan exceptional mesh adv with provisioning service uuid */
675     ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_MESH_PROXY_SRV_ADV_LIST    = BLE_BIT(4),             /*!< duplicate scan exceptional mesh adv with provisioning service uuid */
676     ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_ALL_LIST                   = 0xFFFF,                 /*!< duplicate scan exceptional all list */
677 } esp_duplicate_scan_exceptional_list_type_t;
678 
679 typedef uint8_t esp_duplicate_info_t[ESP_BD_ADDR_LEN];
680 
681 #endif //#if (BLE_42_FEATURE_SUPPORT == TRUE)
682 
683 #if (BLE_50_FEATURE_SUPPORT == TRUE)
684 #define ESP_BLE_GAP_SET_EXT_ADV_PROP_NONCONN_NONSCANNABLE_UNDIRECTED      (0 << 0) // Non-Connectable and Non-Scannable Undirected advertising
685 #define ESP_BLE_GAP_SET_EXT_ADV_PROP_CONNECTABLE                          (1 << 0) // Connectable advertising
686 #define ESP_BLE_GAP_SET_EXT_ADV_PROP_SCANNABLE                            (1 << 1) // Scannable advertising
687 #define ESP_BLE_GAP_SET_EXT_ADV_PROP_DIRECTED                             (1 << 2) // Directed advertising
688 #define ESP_BLE_GAP_SET_EXT_ADV_PROP_HD_DIRECTED                          (1 << 3) // High Duty Cycle Directed Connectable advertising (<= 3.75 ms Advertis- ing Interval)
689 #define ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY                               (1 << 4) // Use legacy advertising PDUs
690 #define ESP_BLE_GAP_SET_EXT_ADV_PROP_ANON_ADV                             (1 << 5) // Omit advertiser's address from all PDUs ("anonymous advertising")
691 #define ESP_BLE_GAP_SET_EXT_ADV_PROP_INCLUDE_TX_PWR                       (1 << 6) // Include TxPower in the extended header of the advertising PDU
692 #define ESP_BLE_GAP_SET_EXT_ADV_PROP_MASK                                 (0x7F)   // Reserved for future use
693 
694 /*  If extended advertising PDU types are being used (bit 4 = 0) then:
695     The advertisement shall not be both connectable and scannable.
696     High duty cycle directed connectable advertising (<= 3.75 ms advertising interval) shall not be used (bit 3 = 0)
697 */
698 // ADV_IND
699 #define ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_IND        (ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY |\
700                                                         ESP_BLE_GAP_SET_EXT_ADV_PROP_CONNECTABLE |\
701                                                         ESP_BLE_GAP_SET_EXT_ADV_PROP_SCANNABLE)
702 // ADV_DIRECT_IND (low duty cycle)
703 #define ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_LD_DIR     (ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY |\
704                                                         ESP_BLE_GAP_SET_EXT_ADV_PROP_CONNECTABLE |\
705                                                         ESP_BLE_GAP_SET_EXT_ADV_PROP_DIRECTED)
706 // ADV_DIRECT_IND (high duty cycle)
707 #define ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_HD_DIR     (ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY |\
708                                                         ESP_BLE_GAP_SET_EXT_ADV_PROP_CONNECTABLE |\
709                                                         ESP_BLE_GAP_SET_EXT_ADV_PROP_HD_DIRECTED)
710 // ADV_SCAN_IND
711 #define ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_SCAN       (ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY |\
712                                                         ESP_BLE_GAP_SET_EXT_ADV_PROP_SCANNABLE)
713 // ADV_NONCONN_IND
714 #define ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_NONCONN    (ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY)
715 typedef uint16_t esp_ble_ext_adv_type_mask_t;
716 
717 #define ESP_BLE_GAP_PHY_1M                             1
718 #define ESP_BLE_GAP_PHY_2M                             2
719 #define ESP_BLE_GAP_PHY_CODED                          3
720 typedef uint8_t esp_ble_gap_phy_t;
721 
722 #define ESP_BLE_GAP_NO_PREFER_TRANSMIT_PHY     (1<<0)
723 #define ESP_BLE_GAP_NO_PREFER_RECEIVE_PHY      (1<<1)
724 typedef uint8_t esp_ble_gap_all_phys_t;
725 
726 // Primary phy only support 1M and LE coded phy
727 #define ESP_BLE_GAP_PRI_PHY_1M     ESP_BLE_GAP_PHY_1M
728 #define ESP_BLE_GAP_PRI_PHY_CODED  ESP_BLE_GAP_PHY_CODED
729 typedef uint8_t esp_ble_gap_pri_phy_t; // primary phy
730 
731 #define ESP_BLE_GAP_PHY_1M_PREF_MASK                   (1 << 0)
732 #define ESP_BLE_GAP_PHY_2M_PREF_MASK                   (1 << 1)
733 #define ESP_BLE_GAP_PHY_CODED_PREF_MASK                (1 << 2)
734 typedef uint8_t esp_ble_gap_phy_mask_t;
735 
736 #define ESP_BLE_GAP_PHY_OPTIONS_NO_PREF                  0 // The Host has no preferred coding when transmitting on the LE Coded PHY
737 #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
738 #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
739 typedef uint16_t esp_ble_gap_prefer_phy_options_t;
740 
741 #define ESP_BLE_GAP_EXT_SCAN_CFG_UNCODE_MASK           0x01
742 #define ESP_BLE_GAP_EXT_SCAN_CFG_CODE_MASK             0x02
743 typedef uint8_t esp_ble_ext_scan_cfg_mask_t;
744 
745 #define ESP_BLE_GAP_EXT_ADV_DATA_COMPLETE              0x00
746 #define ESP_BLE_GAP_EXT_ADV_DATA_INCOMPLETE            0x01
747 #define ESP_BLE_GAP_EXT_ADV_DATA_TRUNCATED             0x02
748 typedef uint8_t esp_ble_gap_ext_adv_data_status_t;
749 
750 #define ESP_BLE_GAP_SYNC_POLICY_BY_ADV_INFO       0
751 #define ESP_BLE_GAP_SYNC_POLICY_BY_PERIODIC_LIST  1
752 typedef uint8_t esp_ble_gap_sync_t;
753 
754 /* Advertising report */
755 #define ESP_BLE_ADV_REPORT_EXT_ADV_IND                    (1<<0)
756 #define ESP_BLE_ADV_REPORT_EXT_SCAN_IND                   (1<<1)
757 #define ESP_BLE_ADV_REPORT_EXT_DIRECT_ADV                 (1<<2)
758 #define ESP_BLE_ADV_REPORT_EXT_SCAN_RSP                   (1<<3)
759 /* Bluetooth 5.0, Vol 2, Part E, 7.7.65.13 */
760 #define ESP_BLE_LEGACY_ADV_TYPE_IND                       (0x13)
761 #define ESP_BLE_LEGACY_ADV_TYPE_DIRECT_IND                (0x15)
762 #define ESP_BLE_LEGACY_ADV_TYPE_SCAN_IND                  (0x12)
763 #define ESP_BLE_LEGACY_ADV_TYPE_NONCON_IND                (0x10)
764 #define ESP_BLE_LEGACY_ADV_TYPE_SCAN_RSP_TO_ADV_IND       (0x1b)
765 #define ESP_BLE_LEGACY_ADV_TYPE_SCAN_RSP_TO_ADV_SCAN_IND  (0x1a)
766 typedef uint8_t esp_ble_gap_adv_type_t;
767 
768 /**
769 * @brief ext adv parameters
770 */
771 typedef struct {
772     esp_ble_ext_adv_type_mask_t type;   /*!< ext adv type */
773     uint32_t interval_min;              /*!< ext adv minimum interval */
774     uint32_t interval_max;              /*!< ext adv maximum interval */
775     esp_ble_adv_channel_t channel_map;  /*!< ext adv channel map */
776     esp_ble_addr_type_t own_addr_type;  /*!< ext adv own addresss type */
777     esp_ble_addr_type_t peer_addr_type; /*!< ext adv peer address type */
778     esp_bd_addr_t peer_addr;            /*!< ext adv peer address */
779     esp_ble_adv_filter_t filter_policy; /*!< ext adv filter policy */
780     int8_t tx_power;                    /*!< ext adv tx power */
781     esp_ble_gap_pri_phy_t primary_phy;  /*!< ext adv primary phy */
782     uint8_t max_skip;                   /*!< ext adv maximum skip */
783     esp_ble_gap_phy_t secondary_phy;    /*!< ext adv secondary phy */
784     uint8_t sid;                        /*!< ext adv sid */
785     bool scan_req_notif;                /*!< ext adv sacn request event notify */
786 } esp_ble_gap_ext_adv_params_t;
787 
788 /**
789 * @brief ext scan config
790 */
791 typedef struct {
792     esp_ble_scan_type_t scan_type; /*!< ext scan type */
793     uint16_t scan_interval;        /*!< ext scan interval */
794     uint16_t scan_window;          /*!< ext scan window */
795 } esp_ble_ext_scan_cfg_t;
796 
797 /**
798 * @brief ext scan parameters
799 */
800 typedef struct {
801     esp_ble_addr_type_t own_addr_type;        /*!< ext scan own addresss type */
802     esp_ble_scan_filter_t filter_policy;      /*!< ext scan filter policy */
803     esp_ble_scan_duplicate_t  scan_duplicate; /*!< ext scan duplicate scan */
804     esp_ble_ext_scan_cfg_mask_t cfg_mask;     /*!< ext scan config mask */
805     esp_ble_ext_scan_cfg_t uncoded_cfg;       /*!< ext scan uncoded config parameters */
806     esp_ble_ext_scan_cfg_t coded_cfg;         /*!< ext scan coded config parameters */
807 } esp_ble_ext_scan_params_t;
808 
809 /**
810 * @brief create extend connection parameters
811 */
812 typedef struct {
813     uint16_t scan_interval;       /*!< init scan interval */
814     uint16_t scan_window;         /*!< init scan window */
815     uint16_t interval_min;        /*!< minimum interval */
816     uint16_t interval_max;        /*!< maximum interval */
817     uint16_t latency;             /*!< ext scan type */
818     uint16_t supervision_timeout; /*!< connection supervision timeout */
819     uint16_t min_ce_len;          /*!< minimum ce length */
820     uint16_t max_ce_len;          /*!< maximum ce length */
821 } esp_ble_gap_conn_params_t;
822 
823 /**
824 * @brief extend adv enable parameters
825 */
826 typedef struct {
827     uint8_t instance;        /*!< advertising handle */
828     int duration;            /*!< advertising duration */
829     int max_events;          /*!< maximum number of extended advertising events */
830 } esp_ble_gap_ext_adv_t;
831 
832 /**
833 * @brief periodic adv parameters
834 */
835 typedef struct {
836     uint16_t interval_min;     /*!< periodic advertising minimum interval */
837     uint16_t interval_max;     /*!< periodic advertising maximum interval */
838     uint8_t  properties;       /*!< periodic advertising properties */
839 } esp_ble_gap_periodic_adv_params_t;
840 
841 /**
842 * @brief periodic adv sync parameters
843 */
844 typedef struct {
845     esp_ble_gap_sync_t filter_policy;   /*!< periodic advertising sync filter policy */
846     uint8_t sid;                        /*!< periodic advertising sid */
847     esp_ble_addr_type_t addr_type;      /*!< periodic advertising address type */
848     esp_bd_addr_t addr;                 /*!< periodic advertising address */
849     uint16_t skip;                      /*!< the maximum number of periodic advertising events that can be skipped */
850     uint16_t sync_timeout;              /*!< synchronization timeout */
851 } esp_ble_gap_periodic_adv_sync_params_t;
852 
853 /**
854 * @brief extend adv report parameters
855 */
856 typedef struct {
857     // uint8_t props;
858     // uint8_t legacy_event_type;
859     esp_ble_gap_adv_type_t event_type;              /*!< extend advertising type */
860     uint8_t addr_type;                              /*!< extend advertising address type */
861     esp_bd_addr_t addr;                             /*!< extend advertising address */
862     esp_ble_gap_pri_phy_t primary_phy;              /*!< extend advertising primary phy */
863     esp_ble_gap_phy_t secondly_phy;                 /*!< extend advertising secondary phy */
864     uint8_t sid;                                    /*!< extend advertising sid */
865     uint8_t tx_power;                               /*!< extend advertising tx power */
866     int8_t rssi;                                    /*!< extend advertising rssi */
867     uint16_t per_adv_interval;                      /*!< periodic advertising interval */
868     uint8_t dir_addr_type;                          /*!< direct address type */
869     esp_bd_addr_t dir_addr;                         /*!< direct address */
870     esp_ble_gap_ext_adv_data_status_t data_status;  /*!< data type */
871     uint8_t adv_data_len;                           /*!< extend advertising data length */
872     uint8_t adv_data[251];                          /*!< extend advertising data */
873 } esp_ble_gap_ext_adv_reprot_t;
874 
875 /**
876 * @brief periodic adv report parameters
877 */
878 typedef struct {
879     uint16_t sync_handle;                          /*!< periodic advertising train handle */
880     uint8_t tx_power;                              /*!< periodic advertising tx power*/
881     int8_t rssi;                                   /*!< periodic advertising rssi */
882     esp_ble_gap_ext_adv_data_status_t data_status; /*!< periodic advertising data type*/
883     uint8_t data_length;                           /*!< periodic advertising data length */
884     uint8_t data[251];                             /*!< periodic advertising data */
885 } esp_ble_gap_periodic_adv_report_t;
886 
887 /**
888 * @brief perodic adv sync establish parameters
889 */
890 typedef struct {
891     uint8_t status;                               /*!< periodic advertising sync status */
892     uint16_t sync_handle;                         /*!< periodic advertising train handle */
893     uint8_t sid;                                  /*!< periodic advertising sid */
894     esp_ble_addr_type_t addr_type;                /*!< periodic advertising address type */
895     esp_bd_addr_t adv_addr;                       /*!< periodic advertising address */
896     esp_ble_gap_phy_t adv_phy;                    /*!< periodic advertising adv phy type */
897     uint16_t period_adv_interval;                 /*!< periodic advertising interval */
898     uint8_t adv_clk_accuracy;                     /*!< periodic advertising clock accuracy */
899 } esp_ble_gap_periodic_adv_sync_estab_t;
900 
901 #endif //#if (BLE_50_FEATURE_SUPPORT == TRUE)
902 
903 /**
904  * @brief Gap callback parameters union
905  */
906 typedef union {
907 #if (BLE_42_FEATURE_SUPPORT == TRUE)
908     /**
909      * @brief ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT
910      */
911     struct ble_adv_data_cmpl_evt_param {
912         esp_bt_status_t status;                     /*!< Indicate the set advertising data operation success status */
913     } adv_data_cmpl;                                /*!< Event parameter of ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT */
914     /**
915      * @brief ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT
916      */
917     struct ble_scan_rsp_data_cmpl_evt_param {
918         esp_bt_status_t status;                     /*!< Indicate the set scan response data operation success status */
919     } scan_rsp_data_cmpl;                           /*!< Event parameter of ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT */
920     /**
921      * @brief ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT
922      */
923     struct ble_scan_param_cmpl_evt_param {
924         esp_bt_status_t status;                     /*!< Indicate the set scan param operation success status */
925     } scan_param_cmpl;                              /*!< Event parameter of ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT */
926     /**
927      * @brief ESP_GAP_BLE_SCAN_RESULT_EVT
928      */
929     struct ble_scan_result_evt_param {
930         esp_gap_search_evt_t search_evt;            /*!< Search event type */
931         esp_bd_addr_t bda;                          /*!< Bluetooth device address which has been searched */
932         esp_bt_dev_type_t dev_type;                 /*!< Device type */
933         esp_ble_addr_type_t ble_addr_type;          /*!< Ble device address type */
934         esp_ble_evt_type_t ble_evt_type;            /*!< Ble scan result event type */
935         int rssi;                                   /*!< Searched device's RSSI */
936         uint8_t  ble_adv[ESP_BLE_ADV_DATA_LEN_MAX + ESP_BLE_SCAN_RSP_DATA_LEN_MAX];     /*!< Received EIR */
937         int flag;                                   /*!< Advertising data flag bit */
938         int num_resps;                              /*!< Scan result number */
939         uint8_t adv_data_len;                       /*!< Adv data length */
940         uint8_t scan_rsp_len;                       /*!< Scan response length */
941         uint32_t num_dis;                          /*!< The number of discard packets */
942     } scan_rst;                                     /*!< Event parameter of ESP_GAP_BLE_SCAN_RESULT_EVT */
943     /**
944      * @brief ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT
945      */
946     struct ble_adv_data_raw_cmpl_evt_param {
947         esp_bt_status_t status;                     /*!< Indicate the set raw advertising data operation success status */
948     } adv_data_raw_cmpl;                            /*!< Event parameter of ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT */
949     /**
950      * @brief ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT
951      */
952     struct ble_scan_rsp_data_raw_cmpl_evt_param {
953         esp_bt_status_t status;                     /*!< Indicate the set raw advertising data operation success status */
954     } scan_rsp_data_raw_cmpl;                       /*!< Event parameter of ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT */
955     /**
956      * @brief ESP_GAP_BLE_ADV_START_COMPLETE_EVT
957      */
958     struct ble_adv_start_cmpl_evt_param {
959         esp_bt_status_t status;                     /*!< Indicate advertising start operation success status */
960     } adv_start_cmpl;                               /*!< Event parameter of ESP_GAP_BLE_ADV_START_COMPLETE_EVT */
961     /**
962      * @brief ESP_GAP_BLE_SCAN_START_COMPLETE_EVT
963      */
964     struct ble_scan_start_cmpl_evt_param {
965         esp_bt_status_t status;                     /*!< Indicate scan start operation success status */
966     } scan_start_cmpl;                              /*!< Event parameter of ESP_GAP_BLE_SCAN_START_COMPLETE_EVT */
967 #endif //#if (BLE_42_FEATURE_SUPPORT == TRUE)
968     esp_ble_sec_t ble_security;                     /*!< ble gap security union type */
969 #if (BLE_42_FEATURE_SUPPORT == TRUE)
970     /**
971      * @brief ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT
972      */
973     struct ble_scan_stop_cmpl_evt_param {
974         esp_bt_status_t status;                     /*!< Indicate scan stop operation success status */
975     } scan_stop_cmpl;                               /*!< Event parameter of ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT */
976     /**
977      * @brief ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT
978      */
979     struct ble_adv_stop_cmpl_evt_param {
980         esp_bt_status_t status;                     /*!< Indicate adv stop operation success status */
981     } adv_stop_cmpl;                                /*!< Event parameter of ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT */
982 #endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
983     /**
984      * @brief ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT
985      */
986     struct ble_set_rand_cmpl_evt_param {
987         esp_bt_status_t status;                     /*!< Indicate set static rand address operation success status */
988     } set_rand_addr_cmpl;                           /*!< Event parameter of ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT */
989     /**
990      * @brief ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT
991      */
992     struct ble_update_conn_params_evt_param {
993         esp_bt_status_t status;                    /*!< Indicate update connection parameters success status */
994         esp_bd_addr_t bda;                         /*!< Bluetooth device address */
995         uint16_t min_int;                          /*!< Min connection interval */
996         uint16_t max_int;                          /*!< Max connection interval */
997         uint16_t latency;                          /*!< Slave latency for the connection in number of connection events. Range: 0x0000 to 0x01F3 */
998         uint16_t conn_int;                         /*!< Current connection interval */
999         uint16_t timeout;                          /*!< Supervision timeout for the LE Link. Range: 0x000A to 0x0C80.
1000                                                      Mandatory Range: 0x000A to 0x0C80 Time = N * 10 msec */
1001     } update_conn_params;                          /*!< Event parameter of ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT */
1002     /**
1003      * @brief ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT
1004      */
1005     struct ble_pkt_data_length_cmpl_evt_param {
1006         esp_bt_status_t status;                     /*!< Indicate the set pkt data length operation success status */
1007         esp_ble_pkt_data_length_params_t params;    /*!<  pkt data length value */
1008     } pkt_data_lenth_cmpl;                          /*!< Event parameter of ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT */
1009     /**
1010      * @brief ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT
1011      */
1012     struct ble_local_privacy_cmpl_evt_param {
1013         esp_bt_status_t status;                     /*!< Indicate the set local privacy operation success status */
1014     } local_privacy_cmpl;                           /*!< Event parameter of ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT */
1015     /**
1016      * @brief ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT
1017      */
1018     struct ble_remove_bond_dev_cmpl_evt_param {
1019         esp_bt_status_t status;                     /*!< Indicate the remove bond device operation success status */
1020         esp_bd_addr_t bd_addr;                      /*!< The device address which has been remove from the bond list */
1021     } remove_bond_dev_cmpl;                         /*!< Event parameter of ESP_GAP_BLE_REMOVE_BOND_DEV_COMPLETE_EVT */
1022     /**
1023      * @brief ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT
1024      */
1025     struct ble_clear_bond_dev_cmpl_evt_param {
1026         esp_bt_status_t status;                     /*!< Indicate the clear bond device operation success status */
1027     } clear_bond_dev_cmpl;                          /*!< Event parameter of ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT */
1028     /**
1029      * @brief ESP_GAP_BLE_GET_BOND_DEV_COMPLETE_EVT
1030      */
1031     struct ble_get_bond_dev_cmpl_evt_param {
1032         esp_bt_status_t status;                     /*!< Indicate the get bond device operation success status */
1033         uint8_t dev_num;                            /*!< Indicate the get number device in the bond list */
1034         esp_ble_bond_dev_t *bond_dev;               /*!< the pointer to the bond device Structure */
1035     } get_bond_dev_cmpl;                            /*!< Event parameter of ESP_GAP_BLE_GET_BOND_DEV_COMPLETE_EVT */
1036     /**
1037      * @brief ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT
1038      */
1039     struct ble_read_rssi_cmpl_evt_param {
1040         esp_bt_status_t status;                     /*!< Indicate the read adv tx power operation success status */
1041         int8_t rssi;                                /*!< The ble remote device rssi value, the range is from -127 to 20, the unit is dbm,
1042                                                          if the RSSI cannot be read, the RSSI metric shall be set to 127. */
1043         esp_bd_addr_t remote_addr;                  /*!< The remote device address */
1044     } read_rssi_cmpl;                               /*!< Event parameter of ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT */
1045     /**
1046      * @brief ESP_GAP_BLE_UPDATE_WHITELIST_COMPLETE_EVT
1047      */
1048     struct ble_update_whitelist_cmpl_evt_param {
1049         esp_bt_status_t status;                     /*!< Indicate the add or remove whitelist operation success status */
1050         esp_ble_wl_opration_t wl_opration;          /*!< 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 */
1051     } update_whitelist_cmpl;                        /*!< Event parameter of ESP_GAP_BLE_UPDATE_WHITELIST_COMPLETE_EVT */
1052 #if (BLE_42_FEATURE_SUPPORT == TRUE)
1053     /**
1054      * @brief ESP_GAP_BLE_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_COMPLETE_EVT
1055      */
1056     struct ble_update_duplicate_exceptional_list_cmpl_evt_param {
1057         esp_bt_status_t status;                     /*!< Indicate update duplicate scan exceptional list operation success status */
1058         uint8_t         subcode;                    /*!< Define in esp_bt_duplicate_exceptional_subcode_type_t */
1059         uint16_t         length;                     /*!< The length of device_info */
1060         esp_duplicate_info_t device_info;           /*!< device information, when subcode is ESP_BLE_DUPLICATE_EXCEPTIONAL_LIST_CLEAN, the value is invalid */
1061     } update_duplicate_exceptional_list_cmpl;       /*!< Event parameter of ESP_GAP_BLE_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_COMPLETE_EVT */
1062 #endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
1063     /**
1064      * @brief ESP_GAP_BLE_SET_CHANNELS_EVT
1065       */
1066     struct ble_set_channels_evt_param {
1067         esp_bt_status_t stat;                       /*!< BLE set channel status */
1068     } ble_set_channels;                             /*!< Event parameter of ESP_GAP_BLE_SET_CHANNELS_EVT */
1069 
1070 #if (BLE_50_FEATURE_SUPPORT == TRUE)
1071     /**
1072      * @brief ESP_GAP_BLE_READ_PHY_COMPLETE_EVT
1073      */
1074     struct ble_read_phy_cmpl_evt_param {
1075         esp_bt_status_t status;                   /*!< read phy complete status */
1076         esp_bd_addr_t bda;                        /*!< read phy address */
1077         esp_ble_gap_phy_t tx_phy;                 /*!< tx phy type */
1078         esp_ble_gap_phy_t rx_phy;                 /*!< rx phy type */
1079     } read_phy;                                   /*!< Event parameter of ESP_GAP_BLE_READ_PHY_COMPLETE_EVT */
1080     /**
1081      * @brief ESP_GAP_BLE_SET_PREFERED_DEFAULT_PHY_COMPLETE_EVT
1082      */
1083     struct ble_set_perf_def_phy_cmpl_evt_param {
1084         esp_bt_status_t status;                     /*!< Indicate perf default phy set status */
1085     } set_perf_def_phy;                             /*!< Event parameter of ESP_GAP_BLE_SET_PREFERED_DEFAULT_PHY_COMPLETE_EVT */
1086     /**
1087      * @brief ESP_GAP_BLE_SET_PREFERED_PHY_COMPLETE_EVT
1088      */
1089     struct ble_set_perf_phy_cmpl_evt_param {
1090         esp_bt_status_t status;                     /*!< Indicate perf phy set status */
1091     } set_perf_phy;                                  /*!< Event parameter of ESP_GAP_BLE_SET_PREFERED_PHY_COMPLETE_EVT */
1092     /**
1093      * @brief ESP_GAP_BLE_EXT_ADV_SET_RAND_ADDR_COMPLETE_EVT
1094      */
1095     struct ble_ext_adv_set_rand_addr_cmpl_evt_param {
1096         esp_bt_status_t status;                      /*!< Indicate extend advertising random address set status */
1097     } ext_adv_set_rand_addr;                         /*!< Event parameter of ESP_GAP_BLE_EXT_ADV_SET_RAND_ADDR_COMPLETE_EVT */
1098     /**
1099      * @brief ESP_GAP_BLE_EXT_ADV_SET_PARAMS_COMPLETE_EVT
1100      */
1101     struct ble_ext_adv_set_params_cmpl_evt_param {
1102         esp_bt_status_t status;                     /*!< Indicate extend advertising parameters set status */
1103     } ext_adv_set_params;                           /*!< Event parameter of ESP_GAP_BLE_EXT_ADV_SET_PARAMS_COMPLETE_EVT */
1104     /**
1105      * @brief ESP_GAP_BLE_EXT_ADV_DATA_SET_COMPLETE_EVT
1106      */
1107      struct ble_ext_adv_data_set_cmpl_evt_param {
1108         esp_bt_status_t status;                      /*!< Indicate extend advertising data set status */
1109     } ext_adv_data_set;                              /*!< Event parameter of ESP_GAP_BLE_EXT_ADV_DATA_SET_COMPLETE_EVT */
1110     /**
1111      * @brief ESP_GAP_BLE_EXT_SCAN_RSP_DATA_SET_COMPLETE_EVT
1112      */
1113     struct ble_ext_adv_scan_rsp_set_cmpl_evt_param {
1114         esp_bt_status_t status;                      /*!< Indicate extend advertising sacn response data set status */
1115     } scan_rsp_set;                                  /*!< Event parameter of ESP_GAP_BLE_EXT_SCAN_RSP_DATA_SET_COMPLETE_EVT */
1116     /**
1117      * @brief ESP_GAP_BLE_EXT_ADV_START_COMPLETE_EVT
1118      */
1119     struct ble_ext_adv_start_cmpl_evt_param {
1120         esp_bt_status_t status;                     /*!< Indicate advertising start operation success status */
1121     } ext_adv_start;                                /*!< Event parameter of ESP_GAP_BLE_EXT_ADV_START_COMPLETE_EVT */
1122     /**
1123      * @brief ESP_GAP_BLE_EXT_ADV_STOP_COMPLETE_EVT
1124      */
1125     struct ble_ext_adv_stop_cmpl_evt_param {
1126         esp_bt_status_t status;                     /*!< Indicate advertising stop operation success status */
1127     } ext_adv_stop;                                 /*!< Event parameter of ESP_GAP_BLE_EXT_ADV_STOP_COMPLETE_EVT */
1128     /**
1129      * @brief ESP_GAP_BLE_EXT_ADV_SET_REMOVE_COMPLETE_EVT
1130      */
1131     struct ble_ext_adv_set_remove_cmpl_evt_param {
1132         esp_bt_status_t status;                     /*!< Indicate advertising stop operation success status */
1133     } ext_adv_remove;                               /*!< Event parameter of ESP_GAP_BLE_EXT_ADV_SET_REMOVE_COMPLETE_EVT */
1134     /**
1135      * @brief ESP_GAP_BLE_EXT_ADV_SET_CLEAR_COMPLETE_EVT
1136      */
1137     struct ble_ext_adv_set_clear_cmpl_evt_param {
1138         esp_bt_status_t status;                     /*!< Indicate advertising stop operation success status */
1139     } ext_adv_clear;                                /*!< Event parameter of ESP_GAP_BLE_EXT_ADV_SET_CLEAR_COMPLETE_EVT */
1140     /**
1141      * @brief ESP_GAP_BLE_PERIODIC_ADV_SET_PARAMS_COMPLETE_EVT
1142      */
1143     struct ble_periodic_adv_set_params_cmpl_param {
1144         esp_bt_status_t status;                    /*!< Indicate periodic advertisingparameters set status */
1145     } peroid_adv_set_params;                       /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_SET_PARAMS_COMPLETE_EVT */
1146     /**
1147      * @brief ESP_GAP_BLE_PERIODIC_ADV_DATA_SET_COMPLETE_EVT
1148      */
1149     struct ble_periodic_adv_data_set_cmpl_param {
1150         esp_bt_status_t status;                    /*!< Indicate periodic advertising data set status */
1151     } period_adv_data_set;                         /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_DATA_SET_COMPLETE_EVT */
1152     /**
1153      * @brief ESP_GAP_BLE_PERIODIC_ADV_START_COMPLETE_EVT
1154      */
1155     struct ble_periodic_adv_start_cmpl_param {
1156         esp_bt_status_t status;                   /*!< Indicate periodic advertising start status */
1157     } period_adv_start;                           /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_START_COMPLETE_EVT */
1158     /**
1159      * @brief ESP_GAP_BLE_PERIODIC_ADV_STOP_COMPLETE_EVT
1160      */
1161     struct ble_periodic_adv_stop_cmpl_param {
1162         esp_bt_status_t status;                  /*!< Indicate periodic advertising stop status */
1163     } period_adv_stop;                           /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_STOP_COMPLETE_EVT */
1164     /**
1165      * @brief ESP_GAP_BLE_PERIODIC_ADV_CREATE_SYNC_COMPLETE_EVT
1166      */
1167     struct ble_period_adv_create_sync_cmpl_param {
1168         esp_bt_status_t status;                  /*!< Indicate periodic advertising create sync status */
1169     } period_adv_create_sync;                    /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_CREATE_SYNC_COMPLETE_EVT */
1170     /**
1171      * @brief ESP_GAP_BLE_PERIODIC_ADV_SYNC_CANCEL_COMPLETE_EVT
1172      */
1173     struct ble_period_adv_sync_cancel_cmpl_param {
1174         esp_bt_status_t status;                  /*!< Indicate periodic advertising sync cancle status */
1175     } period_adv_sync_cancel;                    /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_SYNC_CANCEL_COMPLETE_EVT */
1176      /**
1177      * @brief ESP_GAP_BLE_PERIODIC_ADV_SYNC_TERMINATE_COMPLETE_EVT
1178      */
1179     struct ble_period_adv_sync_terminate_cmpl_param {
1180         esp_bt_status_t status;                  /*!< Indicate periodic advertising sync terminate status */
1181     } period_adv_sync_term;                      /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_SYNC_TERMINATE_COMPLETE_EVT */
1182     /**
1183      * @brief ESP_GAP_BLE_PERIODIC_ADV_ADD_DEV_COMPLETE_EVT
1184      */
1185     struct ble_period_adv_add_dev_cmpl_param {
1186         esp_bt_status_t status;                 /*!< Indicate periodic advertising device list add status */
1187     } period_adv_add_dev;                       /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_ADD_DEV_COMPLETE_EVT */
1188     /**
1189      * @brief ESP_GAP_BLE_PERIODIC_ADV_REMOVE_DEV_COMPLETE_EVT
1190      */
1191     struct ble_period_adv_remove_dev_cmpl_param {
1192         esp_bt_status_t status;                /*!< Indicate periodic advertising device list remove status */
1193     } period_adv_remove_dev;                   /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_REMOVE_DEV_COMPLETE_EVT */
1194     /**
1195      * @brief ESP_GAP_BLE_PERIODIC_ADV_CLEAR_DEV_COMPLETE_EVT
1196      */
1197     struct ble_period_adv_clear_dev_cmpl_param {
1198         esp_bt_status_t status;               /*!< Indicate periodic advertising device list clean status */
1199     } period_adv_clear_dev;                   /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_CLEAR_DEV_COMPLETE_EVT */
1200     /**
1201      * @brief ESP_GAP_BLE_SET_EXT_SCAN_PARAMS_COMPLETE_EVT
1202      */
1203     struct ble_set_ext_scan_params_cmpl_param {
1204         esp_bt_status_t status;              /*!< Indicate extend advertising parameters set status */
1205     } set_ext_scan_params;                   /*!< Event parameter of ESP_GAP_BLE_SET_EXT_SCAN_PARAMS_COMPLETE_EVT */
1206     /**
1207      * @brief ESP_GAP_BLE_EXT_SCAN_START_COMPLETE_EVT
1208      */
1209     struct ble_ext_scan_start_cmpl_param {
1210         esp_bt_status_t status;             /*!< Indicate extend advertising start status */
1211     } ext_scan_start;                       /*!< Event parameter of ESP_GAP_BLE_EXT_SCAN_START_COMPLETE_EVT */
1212     /**
1213      * @brief ESP_GAP_BLE_EXT_SCAN_STOP_COMPLETE_EVT
1214      */
1215     struct ble_ext_scan_stop_cmpl_param {
1216         esp_bt_status_t status;            /*!< Indicate extend advertising stop status */
1217     } ext_scan_stop;                       /*!< Event parameter of ESP_GAP_BLE_EXT_SCAN_STOP_COMPLETE_EVT */
1218     /**
1219      * @brief ESP_GAP_BLE_PREFER_EXT_CONN_PARAMS_SET_COMPLETE_EVT
1220      */
1221     struct ble_ext_conn_params_set_cmpl_param {
1222         esp_bt_status_t status;            /*!< Indicate extend connection parameters set status */
1223     } ext_conn_params_set;                 /*!< Event parameter of ESP_GAP_BLE_PREFER_EXT_CONN_PARAMS_SET_COMPLETE_EVT */
1224     /**
1225      * @brief ESP_GAP_BLE_ADV_TERMINATED_EVT
1226      */
1227     struct ble_adv_terminate_param {
1228         uint8_t status;                   /*!< Indicate adv terminate status */
1229         /*  status 0x3c indicates that advertising for a fixed duration completed or,
1230             for directed advertising, that advertising completed without a connection
1231             being created;
1232             status 0x00 indicates that advertising successfully ended with a connection being created.
1233         */
1234         uint8_t adv_instance;           /*!< extend advertising handle */
1235         uint16_t conn_idx;              /*!< connection index */
1236         uint8_t completed_event;        /*!< the number of completed extend advertising events */
1237     } adv_terminate;                    /*!< Event parameter of ESP_GAP_BLE_ADV_TERMINATED_EVT */
1238     /**
1239      * @brief ESP_GAP_BLE_SCAN_REQ_RECEIVED_EVT
1240      */
1241     struct ble_scan_req_received_param {
1242         uint8_t adv_instance;                /*!< extend advertising handle */
1243         esp_ble_addr_type_t scan_addr_type;  /*!< scanner address type */
1244         esp_bd_addr_t scan_addr;             /*!< scanner address */
1245     } scan_req_received;                     /*!< Event parameter of ESP_GAP_BLE_SCAN_REQ_RECEIVED_EVT */
1246     /**
1247      * @brief ESP_GAP_BLE_CHANNEL_SELETE_ALGORITHM_EVT
1248      */
1249     struct ble_channel_sel_alg_param {
1250         uint16_t conn_handle;              /*!< connection handle */
1251         uint8_t channel_sel_alg;           /*!< channel selection algorithm */
1252     } channel_sel_alg;                     /*!< Event parameter of ESP_GAP_BLE_CHANNEL_SELETE_ALGORITHM_EVT */
1253     /**
1254      * @brief ESP_GAP_BLE_PERIODIC_ADV_SYNC_LOST_EVT
1255      */
1256     struct ble_periodic_adv_sync_lost_param {
1257         uint16_t sync_handle;                 /*!< sync handle */
1258     } periodic_adv_sync_lost;                 /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_SYNC_LOST_EVT */
1259     /**
1260      * @brief ESP_GAP_BLE_PERIODIC_ADV_SYNC_ESTAB_EVT
1261      */
1262     struct ble_periodic_adv_sync_estab_param {
1263         uint8_t status;                      /*!< periodic advertising sync status */
1264         uint16_t sync_handle;                /*!< periodic advertising sync handle */
1265         uint8_t sid;                         /*!< periodic advertising sid */
1266         esp_ble_addr_type_t adv_addr_type;   /*!< periodic advertising address type */
1267         esp_bd_addr_t adv_addr;              /*!< periodic advertising address */
1268         esp_ble_gap_phy_t adv_phy;           /*!< periodic advertising phy type */
1269         uint16_t period_adv_interval;        /*!< periodic advertising interval */
1270         uint8_t adv_clk_accuracy;            /*!< periodic advertising clock accuracy */
1271     } periodic_adv_sync_estab;               /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_SYNC_ESTAB_EVT */
1272     /**
1273      * @brief ESP_GAP_BLE_PHY_UPDATE_COMPLETE_EVT
1274      */
1275     struct ble_phy_update_cmpl_param {
1276         esp_bt_status_t status;             /*!< phy update status */
1277         esp_bd_addr_t bda;                  /*!< address */
1278         esp_ble_gap_phy_t tx_phy;           /*!< tx phy type */
1279         esp_ble_gap_phy_t rx_phy;           /*!< rx phy type */
1280     } phy_update;                           /*!< Event parameter of ESP_GAP_BLE_PHY_UPDATE_COMPLETE_EVT */
1281     /**
1282      * @brief ESP_GAP_BLE_EXT_ADV_REPORT_EVT
1283      */
1284     struct ble_ext_adv_report_param {
1285         esp_ble_gap_ext_adv_reprot_t params;   /*!< extend advertising report parameters */
1286     } ext_adv_report;                          /*!< Event parameter of ESP_GAP_BLE_EXT_ADV_REPORT_EVT */
1287     /**
1288      * @brief ESP_GAP_BLE_PERIODIC_ADV_REPORT_EVT
1289      */
1290     struct ble_periodic_adv_report_param {
1291         esp_ble_gap_periodic_adv_report_t params; /*!< periodic advertising report parameters */
1292     } period_adv_report;                          /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_REPORT_EVT */
1293 #endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
1294 } esp_ble_gap_cb_param_t;
1295 
1296 /**
1297  * @brief GAP callback function type
1298  * @param event : Event type
1299  * @param param : Point to callback parameter, currently is union type
1300  */
1301 typedef void (* esp_gap_ble_cb_t)(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param);
1302 
1303 /**
1304  * @brief           This function is called to occur gap event, such as scan result
1305  *
1306  * @param[in]       callback: callback function
1307  *
1308  * @return
1309  *                  - ESP_OK : success
1310  *                  - other  : failed
1311  *
1312  */
1313 esp_err_t esp_ble_gap_register_callback(esp_gap_ble_cb_t callback);
1314 
1315 #if (BLE_42_FEATURE_SUPPORT == TRUE)
1316 /**
1317  * @brief           This function is called to override the BTA default ADV parameters.
1318  *
1319  * @param[in]       adv_data: Pointer to User defined ADV data structure. This
1320  *                  memory space can not be freed until callback of config_adv_data
1321  *                  is received.
1322  *
1323  * @return
1324  *                  - ESP_OK : success
1325  *                  - other  : failed
1326  *
1327  */
1328 esp_err_t esp_ble_gap_config_adv_data (esp_ble_adv_data_t *adv_data);
1329 
1330 
1331 
1332 /**
1333  * @brief           This function is called to set scan parameters
1334  *
1335  * @param[in]       scan_params: Pointer to User defined scan_params data structure. This
1336  *                  memory space can not be freed until callback of set_scan_params
1337  *
1338  * @return
1339  *                  - ESP_OK : success
1340  *                  - other  : failed
1341  *
1342  */
1343 esp_err_t esp_ble_gap_set_scan_params(esp_ble_scan_params_t *scan_params);
1344 
1345 
1346 /**
1347  * @brief           This procedure keep the device scanning the peer device which advertising on the air
1348  *
1349  * @param[in]       duration: Keeping the scanning time, the unit is second.
1350  *
1351  * @return
1352  *                  - ESP_OK : success
1353  *                  - other  : failed
1354  *
1355  */
1356 esp_err_t esp_ble_gap_start_scanning(uint32_t duration);
1357 
1358 
1359 /**
1360  * @brief          This function call to stop the device scanning the peer device which advertising on the air
1361  * @return
1362  *                 - ESP_OK : success
1363  *                  - other  : failed
1364  *
1365  */
1366 esp_err_t esp_ble_gap_stop_scanning(void);
1367 
1368 /**
1369  * @brief           This function is called to start advertising.
1370  *
1371  * @param[in]       adv_params: pointer to User defined adv_params data structure.
1372 
1373  * @return
1374  *                  - ESP_OK : success
1375  *                  - other  : failed
1376  *
1377  */
1378 esp_err_t esp_ble_gap_start_advertising (esp_ble_adv_params_t *adv_params);
1379 
1380 
1381 
1382 /**
1383  * @brief           This function is called to stop advertising.
1384  *
1385  * @return
1386  *                  - ESP_OK : success
1387  *                  - other  : failed
1388  *
1389  */
1390 esp_err_t esp_ble_gap_stop_advertising(void);
1391 #endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
1392 
1393 
1394 /**
1395  * @brief           Update connection parameters, can only be used when connection is up.
1396  *
1397  * @param[in]       params   -  connection update parameters
1398  *
1399  * @return
1400  *                  - ESP_OK : success
1401  *                  - other  : failed
1402  *
1403  */
1404 esp_err_t esp_ble_gap_update_conn_params(esp_ble_conn_update_params_t *params);
1405 
1406 
1407 /**
1408  * @brief           This function is to set maximum LE data packet size
1409  *
1410  * @return
1411  *                  - ESP_OK : success
1412  *                  - other  : failed
1413  *
1414  */
1415 esp_err_t esp_ble_gap_set_pkt_data_len(esp_bd_addr_t remote_device, uint16_t tx_data_length);
1416 
1417 /**
1418  * @brief           This function sets the static Random Address and Non-Resolvable Private Address for the application
1419  *
1420  * @param[in]       rand_addr: the random address which should be setting
1421  *
1422  * @return
1423  *                  - ESP_OK : success
1424  *                  - other  : failed
1425  *
1426  */
1427 esp_err_t esp_ble_gap_set_rand_addr(esp_bd_addr_t rand_addr);
1428 
1429 /**
1430  * @brief           This function clears the random address for the application
1431  *
1432  * @return
1433  *                  - ESP_OK : success
1434  *                  - other  : failed
1435  *
1436  */
1437 esp_err_t esp_ble_gap_clear_rand_addr(void);
1438 
1439 
1440 
1441 /**
1442  * @brief           Enable/disable privacy on the local device
1443  *
1444  * @param[in]       privacy_enable   - enable/disable privacy on remote device.
1445  *
1446  * @return
1447  *                  - ESP_OK : success
1448  *                  - other  : failed
1449  *
1450  */
1451 esp_err_t esp_ble_gap_config_local_privacy (bool privacy_enable);
1452 
1453 /**
1454  * @brief           set local gap appearance icon
1455  *
1456  *
1457  * @param[in]       icon   - External appearance value, these values are defined by the Bluetooth SIG, please refer to
1458  *                  https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.gap.appearance.xml
1459  *
1460  * @return
1461  *                  - ESP_OK : success
1462  *                  - other  : failed
1463  *
1464  */
1465 esp_err_t esp_ble_gap_config_local_icon (uint16_t icon);
1466 
1467 /**
1468 * @brief            Add or remove device from white list
1469 *
1470 * @param[in]        add_remove: the value is true if added the ble device to the white list, and false remove to the white list.
1471 * @param[in]        remote_bda: the remote device address add/remove from the white list.
1472 * @param[in]        wl_addr_type: whitelist address type
1473 * @return
1474 *                     - ESP_OK : success
1475 *                     - other  : failed
1476 *
1477 */
1478 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);
1479 
1480 /**
1481 * @brief            Clear all white list
1482 *
1483 * @return
1484 *                     - ESP_OK : success
1485 *                     - other  : failed
1486 *
1487 */
1488 esp_err_t esp_ble_gap_clear_whitelist(void);
1489 
1490 /**
1491 * @brief            Get the whitelist size in the controller
1492 *
1493 * @param[out]       length: the white list length.
1494 * @return
1495 *                     - ESP_OK : success
1496 *                     - other  : failed
1497 *
1498 */
1499 esp_err_t esp_ble_gap_get_whitelist_size(uint16_t *length);
1500 #if (BLE_42_FEATURE_SUPPORT == TRUE)
1501 /**
1502 * @brief            This function is called to set the preferred connection
1503 *                   parameters when default connection parameter is not desired before connecting.
1504 *                   This API can only be used in the master role.
1505 *
1506 * @param[in]        bd_addr: BD address of the peripheral
1507 * @param[in]        min_conn_int: minimum preferred connection interval
1508 * @param[in]        max_conn_int: maximum preferred connection interval
1509 * @param[in]        slave_latency: preferred slave latency
1510 * @param[in]        supervision_tout: preferred supervision timeout
1511 *
1512 * @return
1513 *                   - ESP_OK : success
1514 *                   - other  : failed
1515 *
1516 */
1517 esp_err_t esp_ble_gap_set_prefer_conn_params(esp_bd_addr_t bd_addr,
1518                                                                  uint16_t min_conn_int, uint16_t max_conn_int,
1519                                                                  uint16_t slave_latency, uint16_t supervision_tout);
1520 #endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
1521 /**
1522  * @brief           Set device name to the local device
1523  *
1524  * @param[in]       name   -  device name.
1525  *
1526  * @return
1527  *                  - ESP_OK : success
1528  *                  - other  : failed
1529  *
1530  */
1531 esp_err_t esp_ble_gap_set_device_name(const char *name);
1532 
1533 /**
1534  * @brief          This function is called to get local used address and adress type.
1535  *                 uint8_t *esp_bt_dev_get_address(void) get the public address
1536  *
1537  * @param[in]       local_used_addr - current local used ble address (six bytes)
1538  * @param[in]       addr_type   - ble address type
1539  *
1540  * @return          - ESP_OK : success
1541  *                  - other  : failed
1542  *
1543  */
1544 esp_err_t esp_ble_gap_get_local_used_addr(esp_bd_addr_t local_used_addr, uint8_t * addr_type);
1545 /**
1546  * @brief          This function is called to get ADV data for a specific type.
1547  *
1548  * @param[in]       adv_data - pointer of ADV data which to be resolved
1549  * @param[in]       type   - finding ADV data type
1550  * @param[out]      length - return the length of ADV data not including type
1551  *
1552  * @return          pointer of ADV data
1553  *
1554  */
1555 uint8_t *esp_ble_resolve_adv_data(uint8_t *adv_data, uint8_t type, uint8_t *length);
1556 #if (BLE_42_FEATURE_SUPPORT == TRUE)
1557 /**
1558  * @brief           This function is called to set raw advertising data. User need to fill
1559  *                  ADV data by self.
1560  *
1561  * @param[in]       raw_data : raw advertising data
1562  * @param[in]       raw_data_len : raw advertising data length , less than 31 bytes
1563  *
1564  * @return
1565  *                  - ESP_OK : success
1566  *                  - other  : failed
1567  *
1568  */
1569 esp_err_t esp_ble_gap_config_adv_data_raw(uint8_t *raw_data, uint32_t raw_data_len);
1570 
1571 /**
1572  * @brief           This function is called to set raw scan response data. User need to fill
1573  *                  scan response data by self.
1574  *
1575  * @param[in]       raw_data : raw scan response data
1576  * @param[in]       raw_data_len : raw scan response data length , less than 31 bytes
1577  *
1578  * @return
1579  *                  - ESP_OK : success
1580  *                  - other  : failed
1581  */
1582 esp_err_t esp_ble_gap_config_scan_rsp_data_raw(uint8_t *raw_data, uint32_t raw_data_len);
1583 #endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
1584 
1585 /**
1586  * @brief           This function is called to read the RSSI of remote device.
1587  *                  The address of link policy results are returned in the gap callback function with
1588  *                  ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT event.
1589  *
1590  * @param[in]       remote_addr : The remote connection device address.
1591  *
1592  * @return
1593  *                  - ESP_OK : success
1594  *                  - other  : failed
1595  */
1596 esp_err_t esp_ble_gap_read_rssi(esp_bd_addr_t remote_addr);
1597 #if (BLE_42_FEATURE_SUPPORT == TRUE)
1598 /**
1599  * @brief           This function is called to add a device info into the duplicate scan exceptional list.
1600  *
1601  *
1602  * @param[in]       type: device info type, it is defined in esp_ble_duplicate_exceptional_info_type_t
1603  *                  when type is MESH_BEACON_TYPE, MESH_PROV_SRV_ADV or MESH_PROXY_SRV_ADV , device_info is invalid.
1604  * @param[in]       device_info: the device information.
1605  * @return
1606  *                  - ESP_OK : success
1607  *                  - other  : failed
1608  */
1609 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);
1610 
1611 /**
1612  * @brief           This function is called to remove a device info from the duplicate scan exceptional list.
1613  *
1614  *
1615  * @param[in]       type: device info type, it is defined in esp_ble_duplicate_exceptional_info_type_t
1616  *                  when type is MESH_BEACON_TYPE, MESH_PROV_SRV_ADV or MESH_PROXY_SRV_ADV , device_info is invalid.
1617  * @param[in]       device_info: the device information.
1618  * @return
1619  *                  - ESP_OK : success
1620  *                  - other  : failed
1621  */
1622 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);
1623 
1624 /**
1625  * @brief           This function is called to clean the duplicate scan exceptional list.
1626  *                  This API will delete all device information in the duplicate scan exceptional list.
1627  *
1628  *
1629  * @param[in]       list_type: duplicate scan exceptional list type, the value can be one or more of esp_duplicate_scan_exceptional_list_type_t.
1630  *
1631  * @return
1632  *                  - ESP_OK : success
1633  *                  - other  : failed
1634  */
1635 esp_err_t esp_ble_gap_clean_duplicate_scan_exceptional_list(esp_duplicate_scan_exceptional_list_type_t list_type);
1636 #endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
1637 
1638 #if (SMP_INCLUDED == TRUE)
1639 /**
1640 * @brief             Set a GAP security parameter value. Overrides the default value.
1641 *
1642 *                    Secure connection is highly recommended to avoid some major
1643 *                    vulnerabilities like 'Impersonation in the Pin Pairing Protocol'
1644 *                    (CVE-2020-26555) and 'Authentication of the LE Legacy Pairing
1645 *                    Protocol'.
1646 *
1647 *                    To accept only `secure connection mode`, it is necessary do as following:
1648 *
1649 *                    1. Set bit `ESP_LE_AUTH_REQ_SC_ONLY` (`param_type` is
1650 *                    `ESP_BLE_SM_AUTHEN_REQ_MODE`), bit `ESP_LE_AUTH_BOND` and bit
1651 *                    `ESP_LE_AUTH_REQ_MITM` is optional as required.
1652 *
1653 *                    2. Set to `ESP_BLE_ONLY_ACCEPT_SPECIFIED_AUTH_ENABLE` (`param_type` is
1654 *                    `ESP_BLE_SM_ONLY_ACCEPT_SPECIFIED_SEC_AUTH`).
1655 *
1656 * @param[in]       param_type : the type of the param which to be set
1657 * @param[in]       value  : the param value
1658 * @param[in]       len : the length of the param value
1659 *
1660 * @return            - ESP_OK : success
1661 *                       - other  : failed
1662 *
1663 */
1664 esp_err_t esp_ble_gap_set_security_param(esp_ble_sm_param_t param_type,
1665                                          void *value, uint8_t len);
1666 
1667 /**
1668 * @brief             Grant security request access.
1669 *
1670 * @param[in]       bd_addr : BD address of the peer
1671 * @param[in]       accept  :  accept the security request or not
1672 *
1673 * @return            - ESP_OK : success
1674 *                    - other  : failed
1675 *
1676 */
1677 esp_err_t esp_ble_gap_security_rsp(esp_bd_addr_t bd_addr,  bool accept);
1678 
1679 
1680 /**
1681 * @brief             Set a gap parameter value. Use this function to change
1682 *                    the default GAP parameter values.
1683 *
1684 * @param[in]       bd_addr : the address of the peer device need to encryption
1685 * @param[in]       sec_act  : This is the security action to indicate
1686 *                                   what kind of BLE security level is required for
1687 *                                   the BLE link if the BLE is supported
1688 *
1689 * @return            - ESP_OK : success
1690 *                       - other  : failed
1691 *
1692 */
1693 esp_err_t esp_ble_set_encryption(esp_bd_addr_t bd_addr, esp_ble_sec_act_t sec_act);
1694 
1695 /**
1696 * @brief          Reply the key value to the peer device in the legacy connection stage.
1697 *
1698 * @param[in]      bd_addr : BD address of the peer
1699 * @param[in]      accept : passkey entry successful or declined.
1700 * @param[in]      passkey : passkey value, must be a 6 digit number,
1701 *                                     can be lead by 0.
1702 *
1703 * @return            - ESP_OK : success
1704 *                  - other  : failed
1705 *
1706 */
1707 esp_err_t esp_ble_passkey_reply(esp_bd_addr_t bd_addr, bool accept, uint32_t passkey);
1708 
1709 
1710 /**
1711 * @brief           Reply the confirm value to the peer device in the secure connection stage.
1712 *
1713 * @param[in]       bd_addr : BD address of the peer device
1714 * @param[in]       accept : numbers to compare are the same or different.
1715 *
1716 * @return            - ESP_OK : success
1717 *                       - other  : failed
1718 *
1719 */
1720 esp_err_t esp_ble_confirm_reply(esp_bd_addr_t bd_addr, bool accept);
1721 
1722 /**
1723 * @brief           Removes a device from the security database list of
1724 *                  peer device. It manages unpairing event while connected.
1725 *
1726 * @param[in]       bd_addr : BD address of the peer device
1727 *
1728 * @return            - ESP_OK : success
1729 *                       - other  : failed
1730 *
1731 */
1732 esp_err_t esp_ble_remove_bond_device(esp_bd_addr_t bd_addr);
1733 
1734 /**
1735 * @brief           Get the device number from the security database list of peer device.
1736 *                  It will return the device bonded number immediately.
1737 *
1738 * @return          - >= 0 : bonded devices number.
1739 *                  - ESP_FAIL  : failed
1740 *
1741 */
1742 int esp_ble_get_bond_device_num(void);
1743 
1744 
1745 /**
1746 * @brief           Get the device from the security database list of peer device.
1747 *                  It will return the device bonded information immediately.
1748 * @param[inout]    dev_num: Indicate the dev_list array(buffer) size as input.
1749 *                           If dev_num is large enough, it means the actual number as output.
1750 *                           Suggest that dev_num value equal to esp_ble_get_bond_device_num().
1751 *
1752 * @param[out]      dev_list: an array(buffer) of `esp_ble_bond_dev_t` type. Use for storing the bonded devices address.
1753 *                            The dev_list should be allocated by who call this API.
1754 * @return          - ESP_OK : success
1755 *                  - other  : failed
1756 *
1757 */
1758 esp_err_t esp_ble_get_bond_device_list(int *dev_num, esp_ble_bond_dev_t *dev_list);
1759 
1760 /**
1761 * @brief           This function is called to provide the OOB data for
1762 *                  SMP in response to ESP_GAP_BLE_OOB_REQ_EVT
1763 *
1764 * @param[in]       bd_addr: BD address of the peer device.
1765 * @param[in]       TK: TK value, the TK value shall be a 128-bit random number
1766 * @param[in]       len: length of tk, should always be 128-bit
1767 *
1768 * @return          - ESP_OK : success
1769 *                  - other  : failed
1770 *
1771 */
1772 esp_err_t esp_ble_oob_req_reply(esp_bd_addr_t bd_addr, uint8_t *TK, uint8_t len);
1773 
1774 #endif /* #if (SMP_INCLUDED == TRUE) */
1775 
1776 /**
1777 * @brief           This function is to disconnect the physical connection of the peer device
1778 *                  gattc may have multiple virtual GATT server connections when multiple app_id registered.
1779 *                  esp_ble_gattc_close (esp_gatt_if_t gattc_if, uint16_t conn_id) only close one virtual GATT server connection.
1780 *                  if there exist other virtual GATT server connections, it does not disconnect the physical connection.
1781 *                  esp_ble_gap_disconnect(esp_bd_addr_t remote_device) disconnect the physical connection directly.
1782 *
1783 *
1784 *
1785 * @param[in]       remote_device : BD address of the peer device
1786 *
1787 * @return            - ESP_OK : success
1788 *                    - other  : failed
1789 *
1790 */
1791 esp_err_t esp_ble_gap_disconnect(esp_bd_addr_t remote_device);
1792 
1793 /**
1794 * @brief           This function is called to read the connection
1795 *                  parameters information of the device
1796 *
1797 * @param[in]       bd_addr: BD address of the peer device.
1798 * @param[out]      conn_params: the connection parameters information
1799 *
1800 * @return          - ESP_OK : success
1801 *                  - other  : failed
1802 *
1803 */
1804 esp_err_t esp_ble_get_current_conn_params(esp_bd_addr_t bd_addr, esp_gap_conn_params_t *conn_params);
1805 
1806 /**
1807 * @brief            BLE set channels
1808 *
1809 * @param[in]        channels :   The n th such field (in the range 0 to 36) contains the value for the link layer channel index n.
1810 *                                0 means channel n is bad.
1811 *                                1 means channel n is unknown.
1812 *                                The most significant bits are reserved and shall be set to 0.
1813 *                                At least one channel shall be marked as unknown.
1814 *
1815 * @return           - ESP_OK : success
1816 *                   - ESP_ERR_INVALID_STATE: if bluetooth stack is not yet enabled
1817 *                   - other  : failed
1818 *
1819 */
1820 esp_err_t esp_gap_ble_set_channels(esp_gap_ble_channels channels);
1821 
1822 /**
1823 * @brief           This function is called to authorized a link after Authentication(MITM protection)
1824 *
1825 * @param[in]       bd_addr: BD address of the peer device.
1826 * @param[out]      authorize: Authorized the link or not.
1827 *
1828 * @return          - ESP_OK : success
1829 *                  - other  : failed
1830 *
1831 */
1832 esp_err_t esp_gap_ble_set_authorization(esp_bd_addr_t bd_addr, bool authorize);
1833 
1834 #if (BLE_50_FEATURE_SUPPORT == TRUE)
1835 
1836 /**
1837 * @brief           This function is used to read the current transmitter PHY
1838 *                  and receiver PHY on the connection identified by remote address.
1839 *
1840 * @param[in]       bd_addr : BD address of the peer device
1841 *
1842 * @return            - ESP_OK : success
1843 *                    - other  : failed
1844 *
1845 */
1846 esp_err_t esp_ble_gap_read_phy(esp_bd_addr_t bd_addr);
1847 
1848 /**
1849 * @brief           This function is used to allows the Host to specify its preferred values
1850 *                  for the transmitter PHY and receiver PHY to be used for all subsequent connections
1851 *                  over the LE transport.
1852 *
1853 * @param[in]       tx_phy_mask : indicates the transmitter PHYs that the Host prefers the Controller to use
1854 * @param[in]       rx_phy_mask : indicates the receiver PHYs that the Host prefers the Controller to use
1855 *
1856 * @return            - ESP_OK : success
1857 *                    - other  : failed
1858 *
1859 */
1860 esp_err_t esp_ble_gap_set_prefered_default_phy(esp_ble_gap_phy_mask_t tx_phy_mask, esp_ble_gap_phy_mask_t rx_phy_mask);
1861 /**
1862 * @brief           This function is used to set the PHY preferences for the connection identified by the remote address.
1863 *                  The Controller might not be able to make the change (e.g. because the peer does not support the requested PHY)
1864 *                  or may decide that the current PHY is preferable.
1865 *
1866 * @param[in]       bd_addr : remote address
1867 * @param[in]       all_phys_mask : a bit field that allows the Host to specify
1868 * @param[in]       tx_phy_mask : a bit field that indicates the transmitter PHYs that the Host prefers the Controller to use
1869 * @param[in]       rx_phy_mask : a bit field that indicates the receiver PHYs that the Host prefers the Controller to use
1870 * @param[in]       phy_options : a bit field that allows the Host to specify options for PHYs
1871 *
1872 * @return            - ESP_OK : success
1873 *                    - other  : failed
1874 *
1875 */
1876 esp_err_t esp_ble_gap_set_prefered_phy(esp_bd_addr_t bd_addr,
1877                                        esp_ble_gap_all_phys_t all_phys_mask,
1878                                        esp_ble_gap_phy_mask_t tx_phy_mask,
1879                                        esp_ble_gap_phy_mask_t rx_phy_mask,
1880                                        esp_ble_gap_prefer_phy_options_t phy_options);
1881 
1882 /**
1883 * @brief           This function is used by the Host to set the random device address specified by the Random_Address parameter.
1884 *
1885 * @param[in]       instance  : Used to identify an advertising set
1886 * @param[in]       rand_addr : Random Device Address
1887 *
1888 * @return            - ESP_OK : success
1889 *                    - other  : failed
1890 *
1891 */
1892 esp_err_t esp_ble_gap_ext_adv_set_rand_addr(uint8_t instance, esp_bd_addr_t rand_addr);
1893 
1894 /**
1895 * @brief           This function is used by the Host to set the advertising parameters.
1896 *
1897 * @param[in]       instance : identifies the advertising set whose parameters are being configured.
1898 * @param[in]       params   : advertising parameters
1899 *
1900 * @return            - ESP_OK : success
1901 *                    - other  : failed
1902 *
1903 */
1904 esp_err_t esp_ble_gap_ext_adv_set_params(uint8_t instance, const esp_ble_gap_ext_adv_params_t *params);
1905 
1906 /**
1907 * @brief           This function is used to set the data used in advertising PDUs that have a data field
1908 *
1909 * @param[in]       instance : identifies the advertising set whose data are being configured
1910 * @param[in]       length   : data length
1911 * @param[in]       data     : data information
1912 *
1913 * @return            - ESP_OK : success
1914 *                    - other  : failed
1915 *
1916 */
1917 esp_err_t esp_ble_gap_config_ext_adv_data_raw(uint8_t instance, uint16_t length, const uint8_t *data);
1918 
1919 /**
1920 * @brief           This function is used to provide scan response data used in scanning response PDUs
1921 *
1922 * @param[in]       instance : identifies the advertising set whose response data are being configured.
1923 * @param[in]       length : responsedata length
1924 * @param[in]       scan_rsp_data : response data information
1925 *
1926 * @return            - ESP_OK : success
1927 *                    - other  : failed
1928 *
1929 */
1930 esp_err_t esp_ble_gap_config_ext_scan_rsp_data_raw(uint8_t instance, uint16_t length,
1931                                                                    const uint8_t *scan_rsp_data);
1932 /**
1933 * @brief           This function is used to request the Controller to enable one or more
1934 *                  advertising sets using the advertising sets identified by the instance parameter.
1935 *
1936 * @param[in]       num_adv : Number of advertising sets to enable or disable
1937 * @param[in]       ext_adv : adv parameters
1938 *
1939 * @return            - ESP_OK : success
1940 *                    - other  : failed
1941 *
1942 */
1943 esp_err_t esp_ble_gap_ext_adv_start(uint8_t num_adv, const esp_ble_gap_ext_adv_t *ext_adv);
1944 
1945 /**
1946 * @brief           This function is used to request the Controller to disable one or more
1947 *                  advertising sets using the advertising sets identified by the instance parameter.
1948 *
1949 * @param[in]       num_adv : Number of advertising sets to enable or disable
1950 * @param[in]       ext_adv_inst : ext adv instance
1951 *
1952 * @return            - ESP_OK : success
1953 *                    - other  : failed
1954 *
1955 */
1956 esp_err_t esp_ble_gap_ext_adv_stop(uint8_t num_adv, const uint8_t *ext_adv_inst);
1957 
1958 /**
1959 * @brief           This function is used to remove an advertising set from the Controller.
1960 *
1961 * @param[in]       instance : Used to identify an advertising set
1962 *
1963 * @return            - ESP_OK : success
1964 *                    - other  : failed
1965 *
1966 */
1967 esp_err_t esp_ble_gap_ext_adv_set_remove(uint8_t instance);
1968 
1969 /**
1970 * @brief           This function is used to remove all existing advertising sets from the Controller.
1971 *
1972 *
1973 * @return            - ESP_OK : success
1974 *                    - other  : failed
1975 *
1976 */
1977 esp_err_t esp_ble_gap_ext_adv_set_clear(void);
1978 
1979 /**
1980 * @brief           This function is used by the Host to set the parameters for periodic advertising.
1981 *
1982 * @param[in]       instance : identifies the advertising set whose periodic advertising parameters are being configured.
1983 * @param[in]       params : periodic adv parameters
1984 *
1985 * @return            - ESP_OK : success
1986 *                    - other  : failed
1987 *
1988 */
1989 esp_err_t esp_ble_gap_periodic_adv_set_params(uint8_t instance, const esp_ble_gap_periodic_adv_params_t *params);
1990 
1991 /**
1992 * @brief           This function is used to set the data used in periodic advertising PDUs.
1993 *
1994 * @param[in]       instance : identifies the advertising set whose periodic advertising parameters are being configured.
1995 * @param[in]       length : the length of periodic data
1996 * @param[in]       data : periodic data information
1997 *
1998 * @return            - ESP_OK : success
1999 *                    - other  : failed
2000 *
2001 */
2002 esp_err_t esp_ble_gap_config_periodic_adv_data_raw(uint8_t instance, uint16_t length,
2003                                                                            const uint8_t *data);
2004 /**
2005 * @brief           This function is used to request the Controller to enable the periodic advertising for the advertising set specified
2006 *
2007 * @param[in]       instance : Used to identify an advertising set
2008 *
2009 * @return            - ESP_OK : success
2010 *                    - other  : failed
2011 *
2012 */
2013 esp_err_t esp_ble_gap_periodic_adv_start(uint8_t instance);
2014 
2015 /**
2016 * @brief           This function is used to request the Controller to disable the periodic advertising for the advertising set specified
2017 *
2018 * @param[in]       instance : Used to identify an advertising set
2019 *
2020 * @return            - ESP_OK : success
2021 *                    - other  : failed
2022 *
2023 */
2024 esp_err_t esp_ble_gap_periodic_adv_stop(uint8_t instance);
2025 
2026 /**
2027 * @brief           This function is used to set the extended scan parameters to be used on the advertising channels.
2028 *
2029 * @param[in]       params : scan parameters
2030 *
2031 * @return            - ESP_OK : success
2032 *                    - other  : failed
2033 *
2034 */
2035 esp_err_t esp_ble_gap_set_ext_scan_params(const esp_ble_ext_scan_params_t *params);
2036 
2037 /**
2038 * @brief           This function is used to enable scanning.
2039 *
2040 * @param[in]       duration : Scan duration
2041 * @param[in]       period  : Time interval from when the Controller started its last Scan Duration until it begins the subsequent Scan Duration.
2042 *
2043 * @return            - ESP_OK : success
2044 *                    - other  : failed
2045 *
2046 */
2047 esp_err_t esp_ble_gap_start_ext_scan(uint32_t duration, uint16_t period);
2048 
2049 /**
2050 * @brief           This function is used to disable scanning.
2051 *
2052 * @return            - ESP_OK : success
2053 *                    - other  : failed
2054 *
2055 */
2056 esp_err_t esp_ble_gap_stop_ext_scan(void);
2057 
2058 /**
2059 * @brief           This function is used to synchronize with periodic advertising from an advertiser and begin receiving periodic advertising packets.
2060 *
2061 * @param[in]       params : sync parameters
2062 *
2063 * @return            - ESP_OK : success
2064 *                    - other  : failed
2065 *
2066 */
2067 esp_err_t esp_ble_gap_periodic_adv_create_sync(const esp_ble_gap_periodic_adv_sync_params_t *params);
2068 
2069 /**
2070 * @brief           This function is used to cancel the LE_Periodic_Advertising_Create_Sync command while it is pending.
2071 *
2072 *
2073 * @return            - ESP_OK : success
2074 *                    - other  : failed
2075 *
2076 */
2077 esp_err_t esp_ble_gap_periodic_adv_sync_cancel(void);
2078 
2079 /**
2080 * @brief           This function is used to stop reception of the periodic advertising identified by the Sync Handle parameter.
2081 *
2082 * @param[in]       sync_handle : identify the periodic advertiser
2083 *
2084 * @return            - ESP_OK : success
2085 *                    - other  : failed
2086 *
2087 */
2088 esp_err_t esp_ble_gap_periodic_adv_sync_terminate(uint16_t sync_handle);
2089 
2090 /**
2091 * @brief           This function is used to add a single device to the Periodic Advertiser list stored in the Controller
2092 *
2093 * @param[in]       addr_type : address type
2094 * @param[in]       addr : Device Address
2095 * @param[in]       sid : Advertising SID subfield in the ADI field used to identify the Periodic Advertising
2096 *
2097 * @return            - ESP_OK : success
2098 *                    - other  : failed
2099 *
2100 */
2101 esp_err_t esp_ble_gap_periodic_adv_add_dev_to_list(esp_ble_addr_type_t addr_type,
2102                                                                          esp_bd_addr_t addr,
2103                                                                          uint8_t sid);
2104 
2105 /**
2106 * @brief           This function is used to remove one device from the list of Periodic Advertisers stored in the Controller.
2107 *                  Removals from the Periodic Advertisers List take effect immediately.
2108 *
2109 * @param[in]       addr_type : address type
2110 * @param[in]       addr : Device Address
2111 * @param[in]       sid : Advertising SID subfield in the ADI field used to identify the Periodic Advertising
2112 *
2113 * @return            - ESP_OK : success
2114 *                    - other  : failed
2115 *
2116 */
2117 esp_err_t esp_ble_gap_periodic_adv_remove_dev_from_list(esp_ble_addr_type_t addr_type,
2118                                                                          esp_bd_addr_t addr,
2119                                                                          uint8_t sid);
2120 /**
2121 * @brief           This function is used to remove all devices from the list of Periodic Advertisers in the Controller.
2122 *
2123 * @return            - ESP_OK : success
2124 *                    - other  : failed
2125 *
2126 */
2127 esp_err_t esp_ble_gap_periodic_adv_clear_dev(void);
2128 
2129 /**
2130 * @brief           This function is used to set aux connection parameters
2131 *
2132 * @param[in]       addr : device address
2133 * @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.
2134 * @param[in]       phy_1m_conn_params : Scan connectable advertisements on the LE 1M PHY. Connection parameters for the LE 1M PHY are provided.
2135 * @param[in]       phy_2m_conn_params : Connection parameters for the LE 2M PHY are provided.
2136 * @param[in]       phy_coded_conn_params : Scan connectable advertisements on the LE Coded PHY. Connection parameters for the LE Coded PHY are provided.
2137 *
2138 * @return            - ESP_OK : success
2139 *                    - other  : failed
2140 *
2141 */
2142 esp_err_t esp_ble_gap_prefer_ext_connect_params_set(esp_bd_addr_t addr,
2143                                                     esp_ble_gap_phy_mask_t phy_mask,
2144                                                     const esp_ble_gap_conn_params_t *phy_1m_conn_params,
2145                                                     const esp_ble_gap_conn_params_t *phy_2m_conn_params,
2146                                                     const esp_ble_gap_conn_params_t *phy_coded_conn_params);
2147 
2148 #endif //#if (BLE_50_FEATURE_SUPPORT == TRUE)
2149 
2150 #ifdef __cplusplus
2151 }
2152 #endif
2153 
2154 #endif /* __ESP_GAP_BLE_API_H__ */
2155