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 #include <string.h>
16 #include "esp_bt_device.h"
17 #include "esp_bt_main.h"
18 #include "esp_gap_ble_api.h"
19 #include "bta/bta_api.h"
20 #include "common/bt_trace.h"
21 #include "btc/btc_manage.h"
22 #include "btc_gap_ble.h"
23 #include "btc/btc_ble_storage.h"
24
25
esp_ble_gap_register_callback(esp_gap_ble_cb_t callback)26 esp_err_t esp_ble_gap_register_callback(esp_gap_ble_cb_t callback)
27 {
28 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
29
30 return (btc_profile_cb_set(BTC_PID_GAP_BLE, callback) == 0 ? ESP_OK : ESP_FAIL);
31 }
32
33 #if (BLE_42_FEATURE_SUPPORT == TRUE)
esp_ble_gap_config_adv_data(esp_ble_adv_data_t * adv_data)34 esp_err_t esp_ble_gap_config_adv_data(esp_ble_adv_data_t *adv_data)
35 {
36 btc_msg_t msg = {0};
37 btc_ble_gap_args_t arg;
38
39 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
40
41 if (adv_data == NULL) {
42 return ESP_ERR_INVALID_ARG;
43 }
44
45 if (adv_data->service_uuid_len & 0xf) { //not 16*n
46 return ESP_ERR_INVALID_ARG;
47 }
48
49 msg.sig = BTC_SIG_API_CALL;
50 msg.pid = BTC_PID_GAP_BLE;
51 msg.act = BTC_GAP_BLE_ACT_CFG_ADV_DATA;
52 memcpy(&arg.cfg_adv_data.adv_data, adv_data, sizeof(esp_ble_adv_data_t));
53
54 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), btc_gap_ble_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
55
56 }
57
58
esp_ble_gap_set_scan_params(esp_ble_scan_params_t * scan_params)59 esp_err_t esp_ble_gap_set_scan_params(esp_ble_scan_params_t *scan_params)
60 {
61 btc_msg_t msg = {0};
62 btc_ble_gap_args_t arg;
63
64 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
65
66 if (scan_params == NULL) {
67 return ESP_ERR_INVALID_ARG;
68 }
69
70 msg.sig = BTC_SIG_API_CALL;
71 msg.pid = BTC_PID_GAP_BLE;
72 msg.act = BTC_GAP_BLE_ACT_SET_SCAN_PARAM;
73 memcpy(&arg.set_scan_param.scan_params, scan_params, sizeof(esp_ble_scan_params_t));
74
75 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
76 }
77
esp_ble_gap_start_scanning(uint32_t duration)78 esp_err_t esp_ble_gap_start_scanning(uint32_t duration)
79 {
80 btc_msg_t msg = {0};
81 btc_ble_gap_args_t arg;
82
83 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
84
85 msg.sig = BTC_SIG_API_CALL;
86 msg.pid = BTC_PID_GAP_BLE;
87 msg.act = BTC_GAP_BLE_ACT_START_SCAN;
88 arg.start_scan.duration = duration;
89
90 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
91 }
92
93
esp_ble_gap_stop_scanning(void)94 esp_err_t esp_ble_gap_stop_scanning(void)
95 {
96 btc_msg_t msg;
97
98 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
99
100 msg.sig = BTC_SIG_API_CALL;
101 msg.pid = BTC_PID_GAP_BLE;
102 msg.act = BTC_GAP_BLE_ACT_STOP_SCAN;
103 return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
104 }
105
esp_ble_gap_start_advertising(esp_ble_adv_params_t * adv_params)106 esp_err_t esp_ble_gap_start_advertising(esp_ble_adv_params_t *adv_params)
107 {
108 btc_msg_t msg = {0};
109 btc_ble_gap_args_t arg;
110
111 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
112
113 msg.sig = BTC_SIG_API_CALL;
114 msg.pid = BTC_PID_GAP_BLE;
115 msg.act = BTC_GAP_BLE_ACT_START_ADV;
116 memcpy(&arg.start_adv.adv_params, adv_params, sizeof(esp_ble_adv_params_t));
117
118 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
119 }
120
esp_ble_gap_stop_advertising(void)121 esp_err_t esp_ble_gap_stop_advertising(void)
122 {
123 btc_msg_t msg;
124
125 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
126
127 msg.sig = BTC_SIG_API_CALL;
128 msg.pid = BTC_PID_GAP_BLE;
129 msg.act = BTC_GAP_BLE_ACT_STOP_ADV;
130
131 return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
132 }
133 #endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
134
esp_ble_gap_update_conn_params(esp_ble_conn_update_params_t * params)135 esp_err_t esp_ble_gap_update_conn_params(esp_ble_conn_update_params_t *params)
136 {
137 btc_msg_t msg = {0};
138 btc_ble_gap_args_t arg;
139
140 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
141 if(!params) {
142 LOG_ERROR("%s,params is NULL", __func__);
143 return ESP_FAIL;
144 }
145
146 if (ESP_BLE_IS_VALID_PARAM(params->min_int, ESP_BLE_CONN_INT_MIN, ESP_BLE_CONN_INT_MAX) &&
147 ESP_BLE_IS_VALID_PARAM(params->max_int, ESP_BLE_CONN_INT_MIN, ESP_BLE_CONN_INT_MAX) &&
148 ESP_BLE_IS_VALID_PARAM(params->timeout, ESP_BLE_CONN_SUP_TOUT_MIN, ESP_BLE_CONN_SUP_TOUT_MAX) &&
149 (params->latency <= ESP_BLE_CONN_LATENCY_MAX || params->latency == ESP_BLE_CONN_PARAM_UNDEF) &&
150 ((params->timeout * 10) >= ((1 + params->latency) * ((params->max_int * 5) >> 1))) && params->min_int <= params->max_int) {
151
152 msg.sig = BTC_SIG_API_CALL;
153 msg.pid = BTC_PID_GAP_BLE;
154 msg.act = BTC_GAP_BLE_ACT_UPDATE_CONN_PARAM;
155 memcpy(&arg.conn_update_params.conn_params, params, sizeof(esp_ble_conn_update_params_t));
156
157 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
158 } else {
159 LOG_ERROR("%s,invalid connection params:min_int = %d, max_int = %d, latency = %d, timeout = %d",\
160 __func__, params->min_int, params->max_int, params->latency, params->timeout);
161 return ESP_FAIL;
162 }
163 }
164
esp_ble_gap_set_pkt_data_len(esp_bd_addr_t remote_device,uint16_t tx_data_length)165 esp_err_t esp_ble_gap_set_pkt_data_len(esp_bd_addr_t remote_device, uint16_t tx_data_length)
166 {
167 btc_msg_t msg = {0};
168 btc_ble_gap_args_t arg;
169
170 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
171
172 msg.sig = BTC_SIG_API_CALL;
173 msg.pid = BTC_PID_GAP_BLE;
174 msg.act = BTC_GAP_BLE_ACT_SET_PKT_DATA_LEN;
175 arg.set_pkt_data_len.tx_data_length = tx_data_length;
176 memcpy(arg.set_pkt_data_len.remote_device, remote_device, ESP_BD_ADDR_LEN);
177
178 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
179 }
180
181
esp_ble_gap_set_rand_addr(esp_bd_addr_t rand_addr)182 esp_err_t esp_ble_gap_set_rand_addr(esp_bd_addr_t rand_addr)
183 {
184 btc_msg_t msg = {0};
185 btc_ble_gap_args_t arg;
186
187 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
188
189 msg.sig = BTC_SIG_API_CALL;
190 msg.pid = BTC_PID_GAP_BLE;
191 msg.act = BTC_GAP_BLE_ACT_SET_RAND_ADDRESS;
192 memcpy(arg.set_rand_addr.rand_addr, rand_addr, ESP_BD_ADDR_LEN);
193
194 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
195 }
196
esp_ble_gap_clear_rand_addr(void)197 esp_err_t esp_ble_gap_clear_rand_addr(void)
198 {
199 btc_msg_t msg;
200
201 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
202
203 msg.sig = BTC_SIG_API_CALL;
204 msg.pid = BTC_PID_GAP_BLE;
205 msg.act = BTC_GAP_BLE_ACT_CLEAR_RAND_ADDRESS;
206
207 return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
208 }
209
esp_ble_gap_config_local_privacy(bool privacy_enable)210 esp_err_t esp_ble_gap_config_local_privacy (bool privacy_enable)
211 {
212 btc_msg_t msg = {0};
213 btc_ble_gap_args_t arg;
214
215 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
216
217 msg.sig = BTC_SIG_API_CALL;
218 msg.pid = BTC_PID_GAP_BLE;
219 msg.act = BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY;
220 arg.cfg_local_privacy.privacy_enable = privacy_enable;
221
222 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
223 }
224
esp_ble_gap_config_local_icon(uint16_t icon)225 esp_err_t esp_ble_gap_config_local_icon (uint16_t icon)
226 {
227 esp_err_t ret;
228 btc_msg_t msg = {0};
229 btc_ble_gap_args_t arg;
230
231 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
232
233 switch (icon) {
234 case ESP_BLE_APPEARANCE_GENERIC_PHONE:
235 case ESP_BLE_APPEARANCE_GENERIC_COMPUTER:
236 case ESP_BLE_APPEARANCE_GENERIC_REMOTE:
237 case ESP_BLE_APPEARANCE_GENERIC_THERMOMETER:
238 case ESP_BLE_APPEARANCE_THERMOMETER_EAR:
239 case ESP_BLE_APPEARANCE_GENERIC_HEART_RATE:
240 case ESP_BLE_APPEARANCE_HEART_RATE_BELT:
241 case ESP_BLE_APPEARANCE_GENERIC_BLOOD_PRESSURE:
242 case ESP_BLE_APPEARANCE_BLOOD_PRESSURE_ARM:
243 case ESP_BLE_APPEARANCE_BLOOD_PRESSURE_WRIST:
244 case ESP_BLE_APPEARANCE_GENERIC_PULSE_OXIMETER:
245 case ESP_BLE_APPEARANCE_PULSE_OXIMETER_FINGERTIP:
246 case ESP_BLE_APPEARANCE_PULSE_OXIMETER_WRIST:
247 case ESP_BLE_APPEARANCE_GENERIC_GLUCOSE:
248 case ESP_BLE_APPEARANCE_GENERIC_WEIGHT:
249 case ESP_BLE_APPEARANCE_GENERIC_WALKING:
250 case ESP_BLE_APPEARANCE_WALKING_IN_SHOE:
251 case ESP_BLE_APPEARANCE_WALKING_ON_SHOE:
252 case ESP_BLE_APPEARANCE_WALKING_ON_HIP:
253 case ESP_BLE_APPEARANCE_GENERIC_WATCH:
254 case ESP_BLE_APPEARANCE_SPORTS_WATCH:
255 case ESP_BLE_APPEARANCE_GENERIC_EYEGLASSES:
256 case ESP_BLE_APPEARANCE_GENERIC_DISPLAY:
257 case ESP_BLE_APPEARANCE_GENERIC_MEDIA_PLAYER:
258 case ESP_BLE_APPEARANCE_GENERIC_BARCODE_SCANNER:
259 case ESP_BLE_APPEARANCE_HID_BARCODE_SCANNER:
260 case ESP_BLE_APPEARANCE_GENERIC_HID:
261 case ESP_BLE_APPEARANCE_HID_KEYBOARD:
262 case ESP_BLE_APPEARANCE_HID_MOUSE:
263 case ESP_BLE_APPEARANCE_HID_JOYSTICK:
264 case ESP_BLE_APPEARANCE_HID_GAMEPAD:
265 case ESP_BLE_APPEARANCE_HID_DIGITIZER_TABLET:
266 case ESP_BLE_APPEARANCE_HID_CARD_READER:
267 case ESP_BLE_APPEARANCE_HID_DIGITAL_PEN:
268 case ESP_BLE_APPEARANCE_UNKNOWN:
269 case ESP_BLE_APPEARANCE_GENERIC_CLOCK:
270 case ESP_BLE_APPEARANCE_GENERIC_TAG:
271 case ESP_BLE_APPEARANCE_GENERIC_KEYRING:
272 case ESP_BLE_APPEARANCE_GENERIC_CYCLING:
273 case ESP_BLE_APPEARANCE_CYCLING_COMPUTER:
274 case ESP_BLE_APPEARANCE_CYCLING_SPEED:
275 case ESP_BLE_APPEARANCE_CYCLING_CADENCE:
276 case ESP_BLE_APPEARANCE_CYCLING_POWER:
277 case ESP_BLE_APPEARANCE_CYCLING_SPEED_CADENCE:
278 case ESP_BLE_APPEARANCE_GENERIC_PERSONAL_MOBILITY_DEVICE:
279 case ESP_BLE_APPEARANCE_POWERED_WHEELCHAIR:
280 case ESP_BLE_APPEARANCE_MOBILITY_SCOOTER:
281 case ESP_BLE_APPEARANCE_GENERIC_CONTINUOUS_GLUCOSE_MONITOR:
282 case ESP_BLE_APPEARANCE_GENERIC_INSULIN_PUMP:
283 case ESP_BLE_APPEARANCE_INSULIN_PUMP_DURABLE_PUMP:
284 case ESP_BLE_APPEARANCE_INSULIN_PUMP_PATCH_PUMP:
285 case ESP_BLE_APPEARANCE_INSULIN_PEN:
286 case ESP_BLE_APPEARANCE_GENERIC_MEDICATION_DELIVERY:
287 case ESP_BLE_APPEARANCE_GENERIC_OUTDOOR_SPORTS:
288 case ESP_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION:
289 case ESP_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_AND_NAV:
290 case ESP_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_POD:
291 case ESP_BLE_APPEARANCE_OUTDOOR_SPORTS_LOCATION_POD_AND_NAV:
292 msg.sig = BTC_SIG_API_CALL;
293 msg.pid = BTC_PID_GAP_BLE;
294 msg.act = BTC_GAP_BLE_ACT_CONFIG_LOCAL_ICON;
295 arg.cfg_local_icon.icon = icon;
296 ret = (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
297 break;
298 default:
299 ret = ESP_ERR_INVALID_ARG;
300 break;
301 }
302 return ret;
303 }
304
esp_ble_gap_update_whitelist(bool add_remove,esp_bd_addr_t remote_bda,esp_ble_wl_addr_type_t wl_addr_type)305 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)
306 {
307 btc_msg_t msg = {0};
308 btc_ble_gap_args_t arg;
309
310 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
311 return ESP_ERR_INVALID_STATE;
312 }
313 if (!remote_bda){
314 return ESP_ERR_INVALID_SIZE;
315 }
316 msg.sig = BTC_SIG_API_CALL;
317 msg.pid = BTC_PID_GAP_BLE;
318 msg.act = BTC_GAP_BLE_ACT_UPDATE_WHITE_LIST;
319 arg.update_white_list.add_remove = add_remove;
320 arg.update_white_list.wl_addr_type = wl_addr_type;
321 memcpy(arg.update_white_list.remote_bda, remote_bda, sizeof(esp_bd_addr_t));
322
323 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL)
324 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
325 }
326
esp_ble_gap_clear_whitelist(void)327 esp_err_t esp_ble_gap_clear_whitelist(void)
328 {
329 btc_msg_t msg;
330
331 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
332 return ESP_ERR_INVALID_STATE;
333 }
334 msg.sig = BTC_SIG_API_CALL;
335 msg.pid = BTC_PID_GAP_BLE;
336 msg.act = BTC_GAP_BLE_ACT_CLEAR_WHITE_LIST;
337
338 return (btc_transfer_context(&msg, NULL, 0, NULL)
339 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
340 }
341
esp_ble_gap_get_whitelist_size(uint16_t * length)342 esp_err_t esp_ble_gap_get_whitelist_size(uint16_t *length)
343 {
344 if (length == NULL) {
345 return ESP_FAIL;
346 }
347 btc_get_whitelist_size(length);
348
349 return ESP_OK;
350 }
351 #if (BLE_42_FEATURE_SUPPORT == TRUE)
esp_ble_gap_set_prefer_conn_params(esp_bd_addr_t bd_addr,uint16_t min_conn_int,uint16_t max_conn_int,uint16_t slave_latency,uint16_t supervision_tout)352 esp_err_t esp_ble_gap_set_prefer_conn_params(esp_bd_addr_t bd_addr,
353 uint16_t min_conn_int, uint16_t max_conn_int,
354 uint16_t slave_latency, uint16_t supervision_tout)
355 {
356 btc_msg_t msg = {0};
357 btc_ble_gap_args_t arg;
358
359 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
360 return ESP_ERR_INVALID_STATE;
361 }
362
363 if (ESP_BLE_IS_VALID_PARAM(min_conn_int, ESP_BLE_CONN_INT_MIN, ESP_BLE_CONN_INT_MAX) &&
364 ESP_BLE_IS_VALID_PARAM(max_conn_int, ESP_BLE_CONN_INT_MIN, ESP_BLE_CONN_INT_MAX) &&
365 ESP_BLE_IS_VALID_PARAM(supervision_tout, ESP_BLE_CONN_SUP_TOUT_MIN, ESP_BLE_CONN_SUP_TOUT_MAX) &&
366 (slave_latency <= ESP_BLE_CONN_LATENCY_MAX || slave_latency == ESP_BLE_CONN_PARAM_UNDEF) &&
367 ((supervision_tout * 10) >= ((1 + slave_latency) * ((max_conn_int * 5) >> 1))) && min_conn_int <= max_conn_int) {
368
369 msg.sig = BTC_SIG_API_CALL;
370 msg.pid = BTC_PID_GAP_BLE;
371 msg.act = BTC_GAP_BLE_ACT_SET_CONN_PARAMS;
372 arg.set_conn_params.min_conn_int = min_conn_int;
373 arg.set_conn_params.max_conn_int = max_conn_int;
374 arg.set_conn_params.slave_latency = slave_latency;
375 arg.set_conn_params.supervision_tout = supervision_tout;
376 memcpy(arg.set_conn_params.bd_addr, bd_addr, sizeof(esp_bd_addr_t));
377
378 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL)
379 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
380 } else {
381 LOG_ERROR("%s,invalid connection params:min_int = %d, max_int = %d, latency = %d, timeout = %d",\
382 __func__, min_conn_int, max_conn_int, slave_latency, supervision_tout);
383 return ESP_FAIL;
384 }
385 }
386 #endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
387
esp_ble_gap_set_device_name(const char * name)388 esp_err_t esp_ble_gap_set_device_name(const char *name)
389 {
390 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
391
392 return esp_bt_dev_set_device_name(name);
393 }
394
esp_ble_gap_get_local_used_addr(esp_bd_addr_t local_used_addr,uint8_t * addr_type)395 esp_err_t esp_ble_gap_get_local_used_addr(esp_bd_addr_t local_used_addr, uint8_t * addr_type)
396 {
397 if(esp_bluedroid_get_status() != (ESP_BLUEDROID_STATUS_ENABLED)) {
398 LOG_ERROR("%s, bluedroid status error", __func__);
399 return ESP_FAIL;
400 }
401 if(!BTM_BleGetCurrentAddress(local_used_addr, addr_type)) {
402 return ESP_FAIL;
403 }
404 return ESP_OK;
405 }
406
esp_ble_resolve_adv_data(uint8_t * adv_data,uint8_t type,uint8_t * length)407 uint8_t *esp_ble_resolve_adv_data( uint8_t *adv_data, uint8_t type, uint8_t *length)
408 {
409 if (((type < ESP_BLE_AD_TYPE_FLAG) || (type > ESP_BLE_AD_TYPE_128SERVICE_DATA)) &&
410 (type != ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE)) {
411 LOG_ERROR("the eir type not define, type = %x\n", type);
412 return NULL;
413 }
414
415 if (adv_data == NULL) {
416 LOG_ERROR("Invalid p_eir data.\n");
417 return NULL;
418 }
419
420 return (BTM_CheckAdvData( adv_data, type, length));
421 }
422 #if (BLE_42_FEATURE_SUPPORT == TRUE)
esp_ble_gap_config_adv_data_raw(uint8_t * raw_data,uint32_t raw_data_len)423 esp_err_t esp_ble_gap_config_adv_data_raw(uint8_t *raw_data, uint32_t raw_data_len)
424 {
425 btc_msg_t msg = {0};
426 btc_ble_gap_args_t arg;
427
428 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
429
430 if (raw_data == NULL
431 || (raw_data_len <= 0 || raw_data_len > ESP_BLE_ADV_DATA_LEN_MAX)) {
432 return ESP_ERR_INVALID_ARG;
433 }
434
435 msg.sig = BTC_SIG_API_CALL;
436 msg.pid = BTC_PID_GAP_BLE;
437 msg.act = BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW;
438 arg.cfg_adv_data_raw.raw_adv = raw_data;
439 arg.cfg_adv_data_raw.raw_adv_len = raw_data_len;
440
441 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), btc_gap_ble_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
442
443 }
444 #endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
esp_ble_gap_read_rssi(esp_bd_addr_t remote_addr)445 esp_err_t esp_ble_gap_read_rssi(esp_bd_addr_t remote_addr)
446 {
447 btc_msg_t msg = {0};
448 btc_ble_gap_args_t arg;
449
450 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
451 return ESP_ERR_INVALID_STATE;
452 }
453
454 msg.sig = BTC_SIG_API_CALL;
455 msg.pid = BTC_PID_GAP_BLE;
456 msg.act = BTC_GAP_BLE_ACT_READ_RSSI;
457 memcpy(arg.read_rssi.remote_addr, remote_addr, sizeof(esp_bd_addr_t));
458
459 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
460 }
461 #if (BLE_42_FEATURE_SUPPORT == TRUE)
esp_ble_gap_config_scan_rsp_data_raw(uint8_t * raw_data,uint32_t raw_data_len)462 esp_err_t esp_ble_gap_config_scan_rsp_data_raw(uint8_t *raw_data, uint32_t raw_data_len)
463 {
464 btc_msg_t msg = {0};
465 btc_ble_gap_args_t arg;
466
467 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
468
469 if (raw_data == NULL
470 || (raw_data_len <= 0 || raw_data_len > ESP_BLE_SCAN_RSP_DATA_LEN_MAX)) {
471 return ESP_ERR_INVALID_ARG;
472 }
473
474 msg.sig = BTC_SIG_API_CALL;
475 msg.pid = BTC_PID_GAP_BLE;
476 msg.act = BTC_GAP_BLE_ACT_CFG_SCAN_RSP_DATA_RAW;
477 arg.cfg_scan_rsp_data_raw.raw_scan_rsp = raw_data;
478 arg.cfg_scan_rsp_data_raw.raw_scan_rsp_len = raw_data_len;
479
480 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), btc_gap_ble_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
481
482 }
483
esp_ble_gap_add_duplicate_scan_exceptional_device(esp_ble_duplicate_exceptional_info_type_t type,esp_duplicate_info_t device_info)484 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)
485 {
486 btc_msg_t msg = {0};
487 btc_ble_gap_args_t arg;
488
489 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
490 return ESP_ERR_INVALID_STATE;
491 }
492 if (!device_info && type <= ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_INFO_MESH_LINK_ID) {
493 return ESP_ERR_INVALID_SIZE;
494 }
495 msg.sig = BTC_SIG_API_CALL;
496 msg.pid = BTC_PID_GAP_BLE;
497 msg.act = BTC_GAP_BLE_UPDATE_DUPLICATE_SCAN_EXCEPTIONAL_LIST;
498 arg.update_duplicate_exceptional_list.subcode = ESP_BLE_DUPLICATE_EXCEPTIONAL_LIST_ADD;
499 arg.update_duplicate_exceptional_list.info_type = type;
500 if (device_info) {
501 memcpy(arg.update_duplicate_exceptional_list.device_info, device_info, sizeof(esp_bd_addr_t));
502 }
503
504 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL)
505 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
506 }
507
esp_ble_gap_remove_duplicate_scan_exceptional_device(esp_ble_duplicate_exceptional_info_type_t type,esp_duplicate_info_t device_info)508 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)
509 {
510 btc_msg_t msg = {0};
511 btc_ble_gap_args_t arg;
512
513 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
514 return ESP_ERR_INVALID_STATE;
515 }
516 if (!device_info && type <= ESP_BLE_DUPLICATE_SCAN_EXCEPTIONAL_INFO_MESH_LINK_ID) {
517 return ESP_ERR_INVALID_SIZE;
518 }
519 msg.sig = BTC_SIG_API_CALL;
520 msg.pid = BTC_PID_GAP_BLE;
521 msg.act = BTC_GAP_BLE_UPDATE_DUPLICATE_SCAN_EXCEPTIONAL_LIST;
522 arg.update_duplicate_exceptional_list.subcode = ESP_BLE_DUPLICATE_EXCEPTIONAL_LIST_REMOVE;
523 arg.update_duplicate_exceptional_list.info_type = type;
524 if (device_info) {
525 memcpy(arg.update_duplicate_exceptional_list.device_info, device_info, sizeof(esp_bd_addr_t));
526 }
527
528 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL)
529 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
530 }
531
esp_ble_gap_clean_duplicate_scan_exceptional_list(esp_duplicate_scan_exceptional_list_type_t list_type)532 esp_err_t esp_ble_gap_clean_duplicate_scan_exceptional_list(esp_duplicate_scan_exceptional_list_type_t list_type)
533 {
534 btc_msg_t msg = {0};
535 btc_ble_gap_args_t arg;
536
537 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
538 return ESP_ERR_INVALID_STATE;
539 }
540
541 msg.sig = BTC_SIG_API_CALL;
542 msg.pid = BTC_PID_GAP_BLE;
543 msg.act = BTC_GAP_BLE_UPDATE_DUPLICATE_SCAN_EXCEPTIONAL_LIST;
544 arg.update_duplicate_exceptional_list.subcode = ESP_BLE_DUPLICATE_EXCEPTIONAL_LIST_CLEAN;
545 arg.update_duplicate_exceptional_list.info_type = list_type;
546
547 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL)
548 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
549 }
550 #endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
551 #if (SMP_INCLUDED == TRUE)
esp_ble_gap_set_security_param(esp_ble_sm_param_t param_type,void * value,uint8_t len)552 esp_err_t esp_ble_gap_set_security_param(esp_ble_sm_param_t param_type,
553 void *value, uint8_t len)
554 {
555 if(param_type >= ESP_BLE_SM_MAX_PARAM) {
556 return ESP_ERR_INVALID_ARG;
557 }
558 if((param_type != ESP_BLE_SM_CLEAR_STATIC_PASSKEY) && ( value == NULL || len < sizeof(uint8_t) || len > sizeof(uint32_t))) {
559 return ESP_ERR_INVALID_ARG;
560 }
561 if((param_type == ESP_BLE_SM_SET_STATIC_PASSKEY)) {
562 uint32_t passkey = 0;
563 for(uint8_t i = 0; i < len; i++)
564 {
565 passkey += (((uint8_t *)value)[i]<<(8*i));
566 }
567 if(passkey > 999999) {
568 return ESP_ERR_INVALID_ARG;
569 }
570 }
571
572 btc_msg_t msg = {0};
573 btc_ble_gap_args_t arg;
574
575 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
576
577 msg.sig = BTC_SIG_API_CALL;
578 msg.pid = BTC_PID_GAP_BLE;
579 msg.act = BTC_GAP_BLE_SET_SECURITY_PARAM_EVT;
580 arg.set_security_param.param_type = param_type;
581 arg.set_security_param.len = len;
582 arg.set_security_param.value = value;
583
584 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), btc_gap_ble_arg_deep_copy)
585 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
586 }
587
esp_ble_set_encryption(esp_bd_addr_t bd_addr,esp_ble_sec_act_t sec_act)588 esp_err_t esp_ble_set_encryption(esp_bd_addr_t bd_addr, esp_ble_sec_act_t sec_act)
589 {
590 btc_msg_t msg = {0};
591 btc_ble_gap_args_t arg;
592
593 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
594
595 msg.sig = BTC_SIG_API_CALL;
596 msg.pid = BTC_PID_GAP_BLE;
597 msg.act = BTC_GAP_BLE_SET_ENCRYPTION_EVT;
598 arg.set_encryption.sec_act = sec_act;
599 memcpy(arg.set_encryption.bd_addr, bd_addr, ESP_BD_ADDR_LEN);
600
601 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL)
602 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
603 }
604
esp_ble_gap_security_rsp(esp_bd_addr_t bd_addr,bool accept)605 esp_err_t esp_ble_gap_security_rsp(esp_bd_addr_t bd_addr, bool accept)
606 {
607 btc_msg_t msg = {0};
608 btc_ble_gap_args_t arg;
609
610 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
611
612 msg.sig = BTC_SIG_API_CALL;
613 msg.pid = BTC_PID_GAP_BLE;
614 msg.act = BTC_GAP_BLE_SECURITY_RSP_EVT;
615 arg.sec_rsp.accept = accept;
616 memcpy(arg.sec_rsp.bd_addr, bd_addr, ESP_BD_ADDR_LEN);
617
618 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL)
619 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
620
621 }
622
esp_ble_passkey_reply(esp_bd_addr_t bd_addr,bool accept,uint32_t passkey)623 esp_err_t esp_ble_passkey_reply(esp_bd_addr_t bd_addr, bool accept, uint32_t passkey)
624 {
625 btc_msg_t msg = {0};
626 btc_ble_gap_args_t arg;
627
628 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
629
630 msg.sig = BTC_SIG_API_CALL;
631 msg.pid = BTC_PID_GAP_BLE;
632 msg.act = BTC_GAP_BLE_PASSKEY_REPLY_EVT;
633 arg.enc_passkey_replay.accept = accept;
634 arg.enc_passkey_replay.passkey = passkey;
635 memcpy(arg.enc_passkey_replay.bd_addr, bd_addr, ESP_BD_ADDR_LEN);
636
637 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL)
638 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
639 }
640
esp_ble_confirm_reply(esp_bd_addr_t bd_addr,bool accept)641 esp_err_t esp_ble_confirm_reply(esp_bd_addr_t bd_addr, bool accept)
642 {
643 btc_msg_t msg = {0};
644 btc_ble_gap_args_t arg;
645
646 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
647
648 msg.sig = BTC_SIG_API_CALL;
649 msg.pid = BTC_PID_GAP_BLE;
650 msg.act = BTC_GAP_BLE_CONFIRM_REPLY_EVT;
651 arg.enc_comfirm_replay.accept = accept;
652 memcpy(arg.enc_comfirm_replay.bd_addr, bd_addr, ESP_BD_ADDR_LEN);
653
654 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL)
655 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
656 }
657
esp_ble_remove_bond_device(esp_bd_addr_t bd_addr)658 esp_err_t esp_ble_remove_bond_device(esp_bd_addr_t bd_addr)
659 {
660 btc_msg_t msg = {0};
661 btc_ble_gap_args_t arg;
662 msg.sig = BTC_SIG_API_CALL;
663 msg.pid = BTC_PID_GAP_BLE;
664 msg.act = BTC_GAP_BLE_REMOVE_BOND_DEV_EVT;
665 memcpy(arg.remove_bond_device.bd_addr, bd_addr, ESP_BD_ADDR_LEN);
666
667 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL)
668 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
669 }
670
esp_ble_get_bond_device_num(void)671 int esp_ble_get_bond_device_num(void)
672 {
673 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
674 return ESP_FAIL;
675 }
676
677 return btc_storage_get_num_ble_bond_devices();
678 }
679
esp_ble_get_bond_device_list(int * dev_num,esp_ble_bond_dev_t * dev_list)680 esp_err_t esp_ble_get_bond_device_list(int *dev_num, esp_ble_bond_dev_t *dev_list)
681 {
682 int ret;
683 int dev_num_total;
684
685 if (dev_num == NULL || dev_list == NULL) {
686 return ESP_ERR_INVALID_ARG;
687 }
688
689 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
690
691 dev_num_total = btc_storage_get_num_ble_bond_devices();
692 if (*dev_num > dev_num_total) {
693 *dev_num = dev_num_total;
694 }
695
696 ret = btc_storage_get_bonded_ble_devices_list(dev_list, *dev_num);
697
698 return (ret == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
699 }
700
esp_ble_oob_req_reply(esp_bd_addr_t bd_addr,uint8_t * TK,uint8_t len)701 esp_err_t esp_ble_oob_req_reply(esp_bd_addr_t bd_addr, uint8_t *TK, uint8_t len)
702 {
703 if(len != ESP_BT_OCTET16_LEN) {
704 return ESP_ERR_INVALID_ARG;
705 }
706
707 btc_msg_t msg = {0};
708 btc_ble_gap_args_t arg;
709
710 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
711
712 msg.sig = BTC_SIG_API_CALL;
713 msg.pid = BTC_PID_GAP_BLE;
714 msg.act = BTC_GAP_BLE_OOB_REQ_REPLY_EVT;
715 memcpy(arg.oob_req_reply.bd_addr, bd_addr, ESP_BD_ADDR_LEN);
716 arg.oob_req_reply.len = len;
717 arg.oob_req_reply.p_value = TK;
718
719 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), btc_gap_ble_arg_deep_copy)
720 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
721 }
722
723 #endif /* #if (SMP_INCLUDED == TRUE) */
724
esp_ble_gap_disconnect(esp_bd_addr_t remote_device)725 esp_err_t esp_ble_gap_disconnect(esp_bd_addr_t remote_device)
726 {
727 btc_msg_t msg = {0};
728 btc_ble_gap_args_t arg;
729
730 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
731
732 msg.sig = BTC_SIG_API_CALL;
733 msg.pid = BTC_PID_GAP_BLE;
734 msg.act = BTC_GAP_BLE_DISCONNECT_EVT;
735 memcpy(arg.disconnect.remote_device, remote_device, ESP_BD_ADDR_LEN);
736
737 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
738 }
739
esp_ble_get_current_conn_params(esp_bd_addr_t bd_addr,esp_gap_conn_params_t * conn_params)740 esp_err_t esp_ble_get_current_conn_params(esp_bd_addr_t bd_addr, esp_gap_conn_params_t *conn_params)
741 {
742 if(!bd_addr || !conn_params) {
743 return ESP_ERR_INVALID_ARG;
744 }
745 if(BTM_GetCurrentConnParams(bd_addr, &conn_params->interval, &conn_params->latency, &conn_params->timeout)) {
746 return ESP_OK;
747 }
748 return ESP_ERR_NOT_FOUND;
749 }
750
esp_gap_ble_set_channels(esp_gap_ble_channels channels)751 esp_err_t esp_gap_ble_set_channels(esp_gap_ble_channels channels)
752 {
753 btc_msg_t msg = {0};
754 btc_ble_gap_args_t arg;
755
756 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
757 return ESP_ERR_INVALID_STATE;
758 }
759
760 msg.sig = BTC_SIG_API_CALL;
761 msg.pid = BTC_PID_GAP_BLE;
762 msg.act = BTC_GAP_BLE_SET_AFH_CHANNELS;
763
764 memcpy(&arg.set_channels.channels, channels, ESP_GAP_BLE_CHANNELS_LEN);
765 arg.set_channels.channels[ESP_GAP_BLE_CHANNELS_LEN -1] &= 0x1F;
766 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
767 }
768
esp_gap_ble_set_authorization(esp_bd_addr_t bd_addr,bool authorize)769 esp_err_t esp_gap_ble_set_authorization(esp_bd_addr_t bd_addr, bool authorize)
770 {
771 if (!bd_addr) {
772 return ESP_ERR_INVALID_ARG;
773 }
774 if (BTM_Ble_Authorization(bd_addr, authorize)) {
775 return ESP_OK;
776 }
777 return ESP_FAIL;
778 }
779
780 #if (BLE_50_FEATURE_SUPPORT == TRUE)
781
esp_ble_gap_read_phy(esp_bd_addr_t bd_addr)782 esp_err_t esp_ble_gap_read_phy(esp_bd_addr_t bd_addr)
783 {
784 btc_msg_t msg;
785 btc_ble_5_gap_args_t arg;
786
787 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
788
789 msg.sig = BTC_SIG_API_CALL;
790 msg.pid = BTC_PID_GAP_BLE;
791 msg.act = BTC_GAP_BLE_READ_PHY;
792
793 memcpy(arg.read_phy.bd_addr, bd_addr, ESP_BD_ADDR_LEN);
794 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL)
795 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
796 }
797
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)798 esp_err_t esp_ble_gap_set_prefered_default_phy(esp_ble_gap_phy_mask_t tx_phy_mask,
799 esp_ble_gap_phy_mask_t rx_phy_mask)
800 {
801 btc_msg_t msg;
802 btc_ble_5_gap_args_t arg;
803
804 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
805
806 msg.sig = BTC_SIG_API_CALL;
807 msg.pid = BTC_PID_GAP_BLE;
808 msg.act = BTC_GAP_BLE_SET_PREFERED_DEF_PHY;
809 arg.set_perf_def_phy.tx_phy_mask = tx_phy_mask;
810 arg.set_perf_def_phy.rx_phy_mask = rx_phy_mask;
811
812 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL)
813 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
814 }
815
esp_ble_gap_set_prefered_phy(esp_bd_addr_t bd_addr,esp_ble_gap_all_phys_t all_phys_mask,esp_ble_gap_phy_mask_t tx_phy_mask,esp_ble_gap_phy_mask_t rx_phy_mask,esp_ble_gap_prefer_phy_options_t phy_options)816 esp_err_t esp_ble_gap_set_prefered_phy(esp_bd_addr_t bd_addr,
817 esp_ble_gap_all_phys_t all_phys_mask,
818 esp_ble_gap_phy_mask_t tx_phy_mask,
819 esp_ble_gap_phy_mask_t rx_phy_mask,
820 esp_ble_gap_prefer_phy_options_t phy_options)
821 {
822 btc_msg_t msg;
823 btc_ble_5_gap_args_t arg;
824
825 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
826
827 msg.sig = BTC_SIG_API_CALL;
828 msg.pid = BTC_PID_GAP_BLE;
829 msg.act = BTC_GAP_BLE_SET_DEF_PHY;
830 memcpy(arg.set_def_phy.bd_addr, bd_addr, ESP_BD_ADDR_LEN);
831 arg.set_def_phy.all_phys_mask = all_phys_mask;
832 arg.set_def_phy.tx_phy_mask = tx_phy_mask;
833 arg.set_def_phy.rx_phy_mask = rx_phy_mask;
834 arg.set_def_phy.phy_options = phy_options;
835 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL)
836 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
837 }
838
esp_ble_gap_ext_adv_set_rand_addr(uint8_t instance,esp_bd_addr_t rand_addr)839 esp_err_t esp_ble_gap_ext_adv_set_rand_addr(uint8_t instance, esp_bd_addr_t rand_addr)
840 {
841 btc_msg_t msg;
842 btc_ble_5_gap_args_t arg;
843
844 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
845
846 msg.sig = BTC_SIG_API_CALL;
847 msg.pid = BTC_PID_GAP_BLE;
848 msg.act = BTC_GAP_BLE_SET_EXT_ADV_RAND_ADDR;
849 arg.ext_adv_set_rand_addr.instance = instance;
850 memcpy(arg.ext_adv_set_rand_addr.rand_addr, rand_addr, BD_ADDR_LEN);
851
852 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL)
853 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
854
855 }
856
esp_ble_gap_ext_adv_set_params(uint8_t instance,const esp_ble_gap_ext_adv_params_t * params)857 esp_err_t esp_ble_gap_ext_adv_set_params(uint8_t instance,
858 const esp_ble_gap_ext_adv_params_t *params)
859 {
860 btc_msg_t msg;
861 btc_ble_5_gap_args_t arg;
862
863 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
864
865 msg.sig = BTC_SIG_API_CALL;
866 msg.pid = BTC_PID_GAP_BLE;
867 msg.act = BTC_GAP_BLE_SET_EXT_ADV_PARAMS;
868
869 arg.ext_adv_set_params.instance = instance;
870
871 memcpy(&arg.ext_adv_set_params.params, params, sizeof(esp_ble_gap_ext_adv_params_t));
872
873 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL)
874 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
875 }
876
esp_ble_gap_config_ext_adv_data_raw(uint8_t instance,uint16_t length,const uint8_t * data)877 esp_err_t esp_ble_gap_config_ext_adv_data_raw(uint8_t instance, uint16_t length,
878 const uint8_t *data)
879 {
880 btc_msg_t msg;
881 btc_ble_5_gap_args_t arg;
882
883 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
884
885 msg.sig = BTC_SIG_API_CALL;
886 msg.pid = BTC_PID_GAP_BLE;
887 msg.act = BTC_GAP_BLE_CFG_EXT_ADV_DATA_RAW;
888
889 arg.ext_adv_cfg_data.instance = instance;
890 arg.ext_adv_cfg_data.length = length;
891 arg.ext_adv_cfg_data.data = (uint8_t *)data;
892
893 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), btc_gap_ble_arg_deep_copy)
894 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
895 }
896
esp_ble_gap_config_ext_scan_rsp_data_raw(uint8_t instance,uint16_t length,const uint8_t * scan_rsp_data)897 esp_err_t esp_ble_gap_config_ext_scan_rsp_data_raw(uint8_t instance, uint16_t length,
898 const uint8_t *scan_rsp_data)
899 {
900 btc_msg_t msg;
901 btc_ble_5_gap_args_t arg;
902
903 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
904
905 msg.sig = BTC_SIG_API_CALL;
906 msg.pid = BTC_PID_GAP_BLE;
907 msg.act = BTC_GAP_BLE_CFG_EXT_SCAN_RSP_DATA_RAW;
908
909 arg.cfg_scan_rsp.instance = instance;
910 arg.cfg_scan_rsp.length = length;
911 arg.cfg_scan_rsp.data = (uint8_t *)scan_rsp_data;
912
913 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), btc_gap_ble_arg_deep_copy)
914 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
915 }
916
esp_ble_gap_ext_adv_start(uint8_t num_adv,const esp_ble_gap_ext_adv_t * ext_adv)917 esp_err_t esp_ble_gap_ext_adv_start(uint8_t num_adv, const esp_ble_gap_ext_adv_t *ext_adv)
918 {
919 btc_msg_t msg;
920 btc_ble_5_gap_args_t arg;
921
922 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
923
924 msg.sig = BTC_SIG_API_CALL;
925 msg.pid = BTC_PID_GAP_BLE;
926 msg.act = BTC_GAP_BLE_EXT_ADV_START;
927
928 arg.ext_adv_start.num_adv = num_adv;
929 arg.ext_adv_start.ext_adv = (esp_ble_gap_ext_adv_t *)ext_adv;
930
931 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), btc_gap_ble_arg_deep_copy)
932 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
933 }
934
esp_ble_gap_ext_adv_stop(uint8_t num_adv,const uint8_t * ext_adv_inst)935 esp_err_t esp_ble_gap_ext_adv_stop(uint8_t num_adv, const uint8_t *ext_adv_inst)
936 {
937 btc_msg_t msg;
938 btc_ble_5_gap_args_t arg;
939
940 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
941
942 msg.sig = BTC_SIG_API_CALL;
943 msg.pid = BTC_PID_GAP_BLE;
944 msg.act = BTC_GAP_BLE_EXT_ADV_STOP;
945 arg.ext_adv_stop.num_adv = num_adv;
946 arg.ext_adv_stop.ext_adv_inst = (uint8_t *)ext_adv_inst;
947
948 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), btc_gap_ble_arg_deep_copy)
949 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
950
951 }
952
esp_ble_gap_ext_adv_set_remove(uint8_t instance)953 esp_err_t esp_ble_gap_ext_adv_set_remove(uint8_t instance)
954 {
955 btc_msg_t msg;
956 btc_ble_5_gap_args_t arg;
957
958 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
959
960 msg.sig = BTC_SIG_API_CALL;
961 msg.pid = BTC_PID_GAP_BLE;
962 msg.act = BTC_GAP_BLE_EXT_ADV_SET_REMOVE;
963 arg.ext_adv_set_remove.instance = instance;
964
965 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL)
966 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
967 }
968
esp_ble_gap_ext_adv_set_clear(void)969 esp_err_t esp_ble_gap_ext_adv_set_clear(void)
970 {
971 btc_msg_t msg;
972
973 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
974
975 msg.sig = BTC_SIG_API_CALL;
976 msg.pid = BTC_PID_GAP_BLE;
977 msg.act = BTC_GAP_BLE_EXT_ADV_SET_CLEAR;
978
979 return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
980 }
981
esp_ble_gap_periodic_adv_set_params(uint8_t instance,const esp_ble_gap_periodic_adv_params_t * params)982 esp_err_t esp_ble_gap_periodic_adv_set_params(uint8_t instance, const esp_ble_gap_periodic_adv_params_t *params)
983 {
984 btc_msg_t msg;
985 btc_ble_5_gap_args_t arg;
986
987 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
988
989 msg.sig = BTC_SIG_API_CALL;
990 msg.pid = BTC_PID_GAP_BLE;
991 msg.act = BTC_GAP_BLE_SET_PERIODIC_ADV_PARAMS;
992
993 arg.peridic_adv_set_params.instance = instance;
994 memcpy(&arg.peridic_adv_set_params.params, params, sizeof(esp_ble_gap_periodic_adv_params_t));
995
996 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL)
997 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
998
999 }
1000
esp_ble_gap_config_periodic_adv_data_raw(uint8_t instance,uint16_t length,const uint8_t * data)1001 esp_err_t esp_ble_gap_config_periodic_adv_data_raw(uint8_t instance, uint16_t length,
1002 const uint8_t *data)
1003 {
1004 btc_msg_t msg;
1005 btc_ble_5_gap_args_t arg;
1006
1007 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
1008
1009 msg.sig = BTC_SIG_API_CALL;
1010 msg.pid = BTC_PID_GAP_BLE;
1011 msg.act = BTC_GAP_BLE_CFG_PERIODIC_ADV_DATA_RAW;
1012
1013 arg.periodic_adv_cfg_data.instance = instance;
1014 arg.periodic_adv_cfg_data.len = length;
1015 arg.periodic_adv_cfg_data.data = (uint8_t *)data;
1016
1017 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), btc_gap_ble_arg_deep_copy)
1018 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
1019
1020 }
1021
esp_ble_gap_periodic_adv_start(uint8_t instance)1022 esp_err_t esp_ble_gap_periodic_adv_start(uint8_t instance)
1023 {
1024 btc_msg_t msg;
1025 btc_ble_5_gap_args_t arg;
1026
1027 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
1028
1029 msg.sig = BTC_SIG_API_CALL;
1030 msg.pid = BTC_PID_GAP_BLE;
1031 msg.act = BTC_GAP_BLE_PERIODIC_ADV_START;
1032
1033 arg.periodic_adv_start.instance = instance;
1034
1035 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL)
1036 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
1037
1038 }
1039
esp_ble_gap_periodic_adv_stop(uint8_t instance)1040 esp_err_t esp_ble_gap_periodic_adv_stop(uint8_t instance)
1041 {
1042 btc_msg_t msg;
1043 btc_ble_5_gap_args_t arg;
1044
1045 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
1046
1047 msg.sig = BTC_SIG_API_CALL;
1048 msg.pid = BTC_PID_GAP_BLE;
1049 msg.act = BTC_GAP_BLE_PERIODIC_ADV_STOP;
1050
1051 arg.periodic_adv_stop.instance = instance;
1052
1053 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL)
1054 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
1055
1056 }
1057
esp_ble_gap_periodic_adv_create_sync(const esp_ble_gap_periodic_adv_sync_params_t * params)1058 esp_err_t esp_ble_gap_periodic_adv_create_sync(const esp_ble_gap_periodic_adv_sync_params_t *params)
1059 {
1060 btc_msg_t msg;
1061 btc_ble_5_gap_args_t arg;
1062
1063 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
1064
1065 msg.sig = BTC_SIG_API_CALL;
1066 msg.pid = BTC_PID_GAP_BLE;
1067 msg.act = BTC_GAP_BLE_PERIODIC_ADV_CREATE_SYNC;
1068
1069 memcpy(&arg.periodic_adv_create_sync.params, params, sizeof(esp_ble_gap_periodic_adv_sync_params_t));
1070
1071 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL)
1072 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
1073
1074 }
1075
esp_ble_gap_periodic_adv_sync_cancel(void)1076 esp_err_t esp_ble_gap_periodic_adv_sync_cancel(void)
1077 {
1078 btc_msg_t msg;
1079
1080 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
1081
1082 msg.sig = BTC_SIG_API_CALL;
1083 msg.pid = BTC_PID_GAP_BLE;
1084 msg.act = BTC_GAP_BLE_PERIODIC_ADV_SYNC_CANCEL;
1085
1086 return (btc_transfer_context(&msg, NULL, 0, NULL)
1087 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
1088
1089 }
1090
esp_ble_gap_periodic_adv_sync_terminate(uint16_t sync_handle)1091 esp_err_t esp_ble_gap_periodic_adv_sync_terminate(uint16_t sync_handle)
1092 {
1093 btc_msg_t msg;
1094 btc_ble_5_gap_args_t arg;
1095
1096 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
1097
1098 msg.sig = BTC_SIG_API_CALL;
1099 msg.pid = BTC_PID_GAP_BLE;
1100 msg.act = BTC_GAP_BLE_PERIODIC_ADV_SYNC_TERMINATE;
1101
1102 arg.periodic_adv_sync_term.sync_handle = sync_handle;
1103
1104 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL)
1105 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
1106 }
1107
esp_ble_gap_periodic_adv_add_dev_to_list(esp_ble_addr_type_t addr_type,esp_bd_addr_t addr,uint8_t sid)1108 esp_err_t esp_ble_gap_periodic_adv_add_dev_to_list(esp_ble_addr_type_t addr_type,
1109 esp_bd_addr_t addr,
1110 uint8_t sid)
1111 {
1112 btc_msg_t msg;
1113 btc_ble_5_gap_args_t arg;
1114
1115 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
1116
1117 msg.sig = BTC_SIG_API_CALL;
1118 msg.pid = BTC_PID_GAP_BLE;
1119 msg.act = BTC_GAP_BLE_PERIODIC_ADV_ADD_DEV_TO_LIST;
1120
1121 arg.periodic_adv_add_dev.addr_type = addr_type;
1122 arg.periodic_adv_add_dev.sid = sid;
1123
1124
1125 memcpy(arg.periodic_adv_add_dev.addr, addr, sizeof(esp_bd_addr_t));
1126
1127 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL)
1128 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
1129
1130 }
1131
esp_ble_gap_periodic_adv_remove_dev_from_list(esp_ble_addr_type_t addr_type,esp_bd_addr_t addr,uint8_t sid)1132 esp_err_t esp_ble_gap_periodic_adv_remove_dev_from_list(esp_ble_addr_type_t addr_type,
1133 esp_bd_addr_t addr,
1134 uint8_t sid)
1135 {
1136 btc_msg_t msg;
1137 btc_ble_5_gap_args_t arg;
1138
1139 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
1140
1141 msg.sig = BTC_SIG_API_CALL;
1142 msg.pid = BTC_PID_GAP_BLE;
1143 msg.act = BTC_GAP_BLE_PERIODIC_REMOVE_ADD_DEV_FROM_LIST;
1144
1145 arg.periodic_adv_remove_dev.addr_type = addr_type;
1146 arg.periodic_adv_remove_dev.sid = sid;
1147
1148
1149 memcpy(arg.periodic_adv_remove_dev.addr, addr, sizeof(esp_bd_addr_t));
1150
1151 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL)
1152 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
1153
1154 }
1155
esp_ble_gap_periodic_adv_clear_dev(void)1156 esp_err_t esp_ble_gap_periodic_adv_clear_dev(void)
1157 {
1158 btc_msg_t msg;
1159
1160 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
1161
1162 msg.sig = BTC_SIG_API_CALL;
1163 msg.pid = BTC_PID_GAP_BLE;
1164 msg.act = BTC_GAP_BLE_PERIODIC_CLEAR_DEV;
1165
1166 return (btc_transfer_context(&msg, NULL, 0, NULL)
1167 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
1168
1169 }
1170
esp_ble_gap_set_ext_scan_params(const esp_ble_ext_scan_params_t * params)1171 esp_err_t esp_ble_gap_set_ext_scan_params(const esp_ble_ext_scan_params_t *params)
1172 {
1173 btc_msg_t msg;
1174 btc_ble_5_gap_args_t arg;
1175
1176 if (!params) {
1177 return ESP_ERR_INVALID_ARG;
1178 }
1179
1180 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
1181
1182 msg.sig = BTC_SIG_API_CALL;
1183 msg.pid = BTC_PID_GAP_BLE;
1184 msg.act = BTC_GAP_BLE_SET_EXT_SCAN_PARAMS;
1185
1186 memcpy(&arg.set_ext_scan_params.params, params, sizeof(esp_ble_ext_scan_params_t));
1187
1188 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL)
1189 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
1190 }
1191
esp_ble_gap_start_ext_scan(uint32_t duration,uint16_t period)1192 esp_err_t esp_ble_gap_start_ext_scan(uint32_t duration, uint16_t period)
1193 {
1194 btc_msg_t msg;
1195 btc_ble_5_gap_args_t arg;
1196
1197 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
1198
1199 msg.sig = BTC_SIG_API_CALL;
1200 msg.pid = BTC_PID_GAP_BLE;
1201 msg.act = BTC_GAP_BLE_START_EXT_SCAN;
1202
1203 arg.start_ext_scan.duration = duration;
1204 arg.start_ext_scan.period = period;
1205
1206 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL)
1207 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
1208 }
1209
esp_ble_gap_stop_ext_scan(void)1210 esp_err_t esp_ble_gap_stop_ext_scan(void)
1211 {
1212 btc_msg_t msg;
1213
1214 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
1215
1216 msg.sig = BTC_SIG_API_CALL;
1217 msg.pid = BTC_PID_GAP_BLE;
1218 msg.act = BTC_GAP_BLE_STOP_EXT_SCAN;
1219
1220 return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
1221 }
1222
esp_ble_gap_prefer_ext_connect_params_set(esp_bd_addr_t addr,esp_ble_gap_phy_mask_t phy_mask,const esp_ble_gap_conn_params_t * phy_1m_conn_params,const esp_ble_gap_conn_params_t * phy_2m_conn_params,const esp_ble_gap_conn_params_t * phy_coded_conn_params)1223 esp_err_t esp_ble_gap_prefer_ext_connect_params_set(esp_bd_addr_t addr,
1224 esp_ble_gap_phy_mask_t phy_mask,
1225 const esp_ble_gap_conn_params_t *phy_1m_conn_params,
1226 const esp_ble_gap_conn_params_t *phy_2m_conn_params,
1227 const esp_ble_gap_conn_params_t *phy_coded_conn_params)
1228 {
1229 btc_msg_t msg;
1230 btc_ble_5_gap_args_t arg;
1231
1232 ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
1233
1234 msg.sig = BTC_SIG_API_CALL;
1235 msg.pid = BTC_PID_GAP_BLE;
1236 msg.act = BTC_GAP_BLE_SET_EXT_PEFER_CONNET_PARAMS;
1237
1238 arg.set_ext_conn_params.phy_mask = phy_mask;
1239 if (phy_mask & ESP_BLE_GAP_PHY_1M_PREF_MASK) {
1240 if (!phy_1m_conn_params) {
1241 return BT_STATUS_PARM_INVALID;
1242 }
1243
1244 if (ESP_BLE_IS_VALID_PARAM(phy_1m_conn_params->interval_min, ESP_BLE_CONN_INT_MIN, ESP_BLE_CONN_INT_MAX) &&
1245 ESP_BLE_IS_VALID_PARAM(phy_1m_conn_params->interval_max, ESP_BLE_CONN_INT_MIN, ESP_BLE_CONN_INT_MAX) &&
1246 ESP_BLE_IS_VALID_PARAM(phy_1m_conn_params->supervision_timeout, ESP_BLE_CONN_SUP_TOUT_MIN, ESP_BLE_CONN_SUP_TOUT_MAX) &&
1247 (phy_1m_conn_params->latency <= ESP_BLE_CONN_LATENCY_MAX || phy_1m_conn_params->latency == ESP_BLE_CONN_PARAM_UNDEF) &&
1248 ((phy_1m_conn_params->supervision_timeout * 10) >= ((1 + phy_1m_conn_params->latency) * ((phy_1m_conn_params->interval_max * 5) >> 1))) &&
1249 (phy_1m_conn_params->interval_min <= phy_1m_conn_params->interval_max)) {
1250
1251 memcpy(&arg.set_ext_conn_params.phy_1m_conn_params, phy_1m_conn_params, sizeof(esp_ble_gap_conn_params_t));
1252 } else {
1253 LOG_ERROR("%s,invalid connection params:min_int = %d, max_int = %d, latency = %d, timeout = %d", __func__,
1254 phy_1m_conn_params->interval_min,
1255 phy_1m_conn_params->interval_max,
1256 phy_1m_conn_params->latency,
1257 phy_1m_conn_params->supervision_timeout);
1258
1259 return ESP_ERR_INVALID_ARG;
1260 }
1261 }
1262
1263 if (phy_mask & ESP_BLE_GAP_PHY_2M_PREF_MASK) {
1264 if (!phy_2m_conn_params) {
1265 return BT_STATUS_PARM_INVALID;
1266 }
1267
1268 if (ESP_BLE_IS_VALID_PARAM(phy_2m_conn_params->interval_min, ESP_BLE_CONN_INT_MIN, ESP_BLE_CONN_INT_MAX) &&
1269 ESP_BLE_IS_VALID_PARAM(phy_2m_conn_params->interval_max, ESP_BLE_CONN_INT_MIN, ESP_BLE_CONN_INT_MAX) &&
1270 ESP_BLE_IS_VALID_PARAM(phy_2m_conn_params->supervision_timeout, ESP_BLE_CONN_SUP_TOUT_MIN, ESP_BLE_CONN_SUP_TOUT_MAX) &&
1271 (phy_2m_conn_params->latency <= ESP_BLE_CONN_LATENCY_MAX || phy_2m_conn_params->latency == ESP_BLE_CONN_PARAM_UNDEF) &&
1272 ((phy_2m_conn_params->supervision_timeout * 10) >= ((1 + phy_2m_conn_params->latency) * ((phy_2m_conn_params->interval_max * 5) >> 1))) &&
1273 (phy_2m_conn_params->interval_min <= phy_2m_conn_params->interval_max)) {
1274
1275 memcpy(&arg.set_ext_conn_params.phy_2m_conn_params, phy_2m_conn_params, sizeof(esp_ble_gap_conn_params_t));
1276 } else {
1277 LOG_ERROR("%s,invalid connection params:min_int = %d, max_int = %d, latency = %d, timeout = %d", __func__,
1278 phy_2m_conn_params->interval_min,
1279 phy_2m_conn_params->interval_max,
1280 phy_2m_conn_params->latency,
1281 phy_2m_conn_params->supervision_timeout);
1282
1283 return ESP_ERR_INVALID_ARG;
1284 }
1285 }
1286
1287 if (phy_mask & ESP_BLE_GAP_PHY_CODED_PREF_MASK) {
1288 if (!phy_coded_conn_params) {
1289 return BT_STATUS_PARM_INVALID;
1290 }
1291
1292 if (ESP_BLE_IS_VALID_PARAM(phy_coded_conn_params->interval_min, ESP_BLE_CONN_INT_MIN, ESP_BLE_CONN_INT_MAX) &&
1293 ESP_BLE_IS_VALID_PARAM(phy_coded_conn_params->interval_max, ESP_BLE_CONN_INT_MIN, ESP_BLE_CONN_INT_MAX) &&
1294 ESP_BLE_IS_VALID_PARAM(phy_coded_conn_params->supervision_timeout, ESP_BLE_CONN_SUP_TOUT_MIN, ESP_BLE_CONN_SUP_TOUT_MAX) &&
1295 (phy_coded_conn_params->latency <= ESP_BLE_CONN_LATENCY_MAX || phy_coded_conn_params->latency == ESP_BLE_CONN_PARAM_UNDEF) &&
1296 ((phy_coded_conn_params->supervision_timeout * 10) >= ((1 + phy_coded_conn_params->latency) * ((phy_coded_conn_params->interval_max * 5) >> 1))) &&
1297 (phy_coded_conn_params->interval_min <= phy_coded_conn_params->interval_max)) {
1298
1299 memcpy(&arg.set_ext_conn_params.phy_coded_conn_params, phy_coded_conn_params, sizeof(esp_ble_gap_conn_params_t));
1300 } else {
1301 LOG_ERROR("%s,invalid connection params:min_int = %d, max_int = %d, latency = %d, timeout = %d", __func__,
1302 phy_coded_conn_params->interval_min,
1303 phy_coded_conn_params->interval_max,
1304 phy_coded_conn_params->latency,
1305 phy_coded_conn_params->supervision_timeout);
1306
1307 return ESP_ERR_INVALID_ARG;
1308 }
1309 }
1310
1311 memcpy(arg.set_ext_conn_params.addr, addr, sizeof(esp_bd_addr_t));
1312
1313 return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL)
1314 == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
1315
1316 }
1317
1318 #endif //#if (BLE_50_FEATURE_SUPPORT == TRUE)
1319