1 // Copyright (C) 2022 Beken Corporation 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 INCLUDE_MODULES_BK_BLE_API_H_ 16 #define INCLUDE_MODULES_BK_BLE_API_H_ 17 18 19 #include <modules/ble_types.h> 20 21 #ifdef __cplusplus 22 extern"C" { 23 #endif 24 25 /** 26 * @brief ble APIs Version 1.0 27 * @defgroup bk_ble_api_v1 New ble api group 28 * @{ 29 */ 30 31 /** 32 * @brief Register a gatt service 33 * @param 34 * - ble_db_cfg: service param 35 * 36 * User example: 37 * First we must build test_service_db 38 * test_service_db is a database for att, which used in ble discovery. reading writing and other operation is used on a att database. 39 * 40 * 41 * @code 42 * enum { 43 * TEST_IDX_SVC, 44 * TEST_IDX_CHAR_DECL, 45 * TEST_IDX_CHAR_VALUE, 46 * TEST_IDX_CHAR_DESC, 47 * 48 * TEST_IDX_CHAR_DATALEN_DECL, 49 * TEST_IDX_CHAR_DATALEN_VALUE, 50 * 51 * TEST_IDX_CHAR_INTER_DECL, 52 * TEST_IDX_CHAR_INTER_VALUE, 53 * 54 * TEST_IDX_NB, 55 * }; 56 * 57 * //att records database. 58 * 59 * ble_attm_desc_t test_service_db[TEST_IDX_NB] = { 60 * // Service Declaration 61 * [TEST_IDX_SVC] = {DECL_PRIMARY_SERVICE_128, BK_BLE_PERM_SET(RD, ENABLE), 0, 0}, 62 * // Characteristic declare 63 * [TEST_IDX_CHAR_DECL] = {DECL_CHARACTERISTIC_128, BK_BLE_PERM_SET(RD, ENABLE), 0, 0}, 64 * // Characteristic Value 65 * [TEST_IDX_CHAR_VALUE] = {{0x34, 0x12, 0}, BK_BLE_PERM_SET(NTF, ENABLE), BK_BLE_PERM_SET(RI, ENABLE) | BK_BLE_PERM_SET(UUID_LEN, UUID_16), 128}, 66 * //Client Characteristic Configuration Descriptor 67 * [TEST_IDX_CHAR_DESC] = {DESC_CLIENT_CHAR_CFG_128, BK_BLE_PERM_SET(RD, ENABLE) | BK_BLE_PERM_SET(WRITE_REQ, ENABLE), 0, 0}, 68 * }; 69 * @endcode 70 * TEST_IDX_SVC is nessecery, is declare a primary att service. The macro define is: 71 * 72 * @code 73 * #define DECL_PRIMARY_SERVICE_128 {0x00,0x28,0} 74 * @endcode 75 * 76 * which is an UUID say it is a "primary service" 77 * BK_BLE_PERM_SET(RD, ENABLE) means it can be read, and must be read, so it can be discove by peer master. 78 * 79 * TEST_IDX_CHAR_DECL declare a characteristic as a element in service, it must be BK_BLE_PERM_SET(RD, ENABLE) 80 * 81 * @code 82 * #define DECL_CHARACTERISTIC_128 {0x03,0x28,0} 83 * @endcode 84 * show it's a "characteristic" 85 * 86 * BK_BLE_PERM_SET(RD, ENABLE) means it can be read, and must be read, so it can be discove by peer master. 87 * 88 * 89 * TEST_IDX_CHAR_VALUE is the real value of TEST_IDX_CHAR_DECL, 90 * {0x34, 0x12, 0} means it's type is 0x1234, you can determine by you self 91 * BK_BLE_PERM_SET(NTF, ENABLE) means it cant notify peer, such as value change. For exzample, BLE mouse report pos by "notify" peer. 92 * BK_BLE_PERM_SET(RI, ENABLE) means if peer read this att record, it will enable notification. 93 * BK_BLE_PERM_SET(UUID_LEN, UUID_16) means the first elem's max len of TEST_IDX_CHAR_VALUE. 94 * 95 * TEST_IDX_CHAR_DESC is a Client Characteristic Configuration Descriptor for TEST_IDX_CHAR_VALUE, it used by peer master as know as a client. 96 * As common usage, it config TEST_IDX_CHAR_VALUE indication or notification. Peer can write this att handle to triggle it. 97 * Must be BK_BLE_PERM_SET(RD, ENABLE) | BK_BLE_PERM_SET(WRITE_REQ, ENABLE) 98 * 99 * Now, you have a basic database for peer, in this case, peer write TEST_IDX_CHAR_DESC or read TEST_IDX_CHAR_VALUE to enable notification, and then we notify peer by TEST_IDX_CHAR_VALUE 100 * 101 * 102 * Secondlly, we build ble_db_cfg 103 * @code 104 * struct bk_ble_db_cfg ble_db_cfg; 105 * 106 * ble_db_cfg.att_db = (ble_attm_desc_t *)test_service_db; 107 * ble_db_cfg.att_db_nb = TEST_IDX_NB; 108 * ble_db_cfg.prf_task_id = g_test_prf_task_id; 109 * ble_db_cfg.start_hdl = 0; 110 * ble_db_cfg.svc_perm = BK_BLE_PERM_SET(SVC_UUID_LEN, UUID_16); 111 * @endcode 112 * prf_task_id is app handle. If you have multi att service, used prf_task_id to distinguish it. 113 * svc_perm show TEST_IDX_SVC UUID type's len. 114 * @return 115 * - BK_ERR_BLE_SUCCESS: succeed 116 * - others: other errors. 117 */ 118 ble_err_t bk_ble_create_db (struct bk_ble_db_cfg* ble_db_cfg); 119 120 /** 121 * @brief Register ble event notification callback 122 * 123 * @param 124 * - func: event callback 125 * 126 * @attention 1. you must regist it, otherwise you cant get any event ! 127 * @attention 2. you must regist it before bk_ble_create_db, otherwise you cant get BLE_5_CREATE_DB event 128 * 129 * User example: 130 * @code 131 * void ble_at_notice_cb(ble_notice_t notice, void *param) 132 { 133 switch (notice) { 134 135 case BLE_5_WRITE_EVENT: { 136 137 if (w_req->prf_id == g_test_prf_task_id) 138 { 139 switch(w_req->att_idx) 140 { 141 case TEST_IDX_CHAR_DECL: 142 break; 143 case TEST_IDX_CHAR_VALUE: 144 break; 145 case TEST_IDX_CHAR_DESC: 146 //when peer enable notification, we create time and notify peer, such as 147 //write_buffer = (uint8_t *)os_malloc(s_test_data_len); 148 //bk_ble_send_noti_value(s_test_data_len, write_buffer, g_test_prf_task_id, TEST_IDX_CHAR_VALUE); 149 break; 150 151 default: 152 break; 153 } 154 } 155 break; 156 } 157 case BLE_5_CREATE_DB: 158 //bk_ble_create_db success here 159 break; 160 } 161 } 162 163 bk_ble_set_notice_cb(ble_at_notice_cb); 164 * @endcode 165 * @return 166 * - void 167 */ 168 void bk_ble_set_notice_cb(ble_notice_cb_t func); 169 170 /** 171 * @brief Get device name 172 * 173 * @param 174 * - name: store the device name 175 * - buf_len: the length of buf to store the device name 176 * 177 * @return 178 * - length: the length of device name 179 */ 180 uint8_t bk_ble_appm_get_dev_name(uint8_t* name, uint32_t buf_len); 181 182 /** 183 * @brief Set device name 184 * 185 * @param 186 * - len: the length of device name 187 * - name: the device name to be set 188 * 189 * @return 190 * - length: the length of device name 191 */ 192 uint8_t bk_ble_appm_set_dev_name(uint8_t len, uint8_t* name); 193 194 /** 195 * @brief Create a ble advertising activity 196 * 197 * @param 198 * - actv_idx: the index of activity 199 * - adv_param: the advertising parameter 200 * - callback: register a callback for this action, ble_cmd_t: BLE_CREATE_ADV 201 * @attention 1.you must wait callback status, 0 mean success. 202 * 203 * User example: 204 * @code 205 * ble_adv_param_t adv_param; 206 * 207 * adv_param.own_addr_type = 0;//BLE_STATIC_ADDR 208 * adv_param.adv_type = 0; //ADV_IND 209 * adv_param.chnl_map = 7; 210 * adv_param.adv_prop = 3; 211 * adv_param.adv_intv_min = 0x120; //min 212 * adv_param.adv_intv_max = 0x160; //max 213 * adv_param.prim_phy = 1;// 1M 214 * adv_param.second_phy = 1;// 1M 215 * actv_idx = bk_ble_get_idle_actv_idx_handle(); 216 * if (actv_idx != UNKNOW_ACT_IDX) { 217 * bk_ble_create_advertising(actv_idx, &adv_param, ble_at_cmd_cb); 218 * } 219 * @endcode 220 * @return 221 * - BK_ERR_BLE_SUCCESS: succeed 222 * - others: other errors. 223 */ 224 ble_err_t bk_ble_create_advertising(uint8_t actv_idx, ble_adv_param_t *adv_param, ble_cmd_cb_t callback); 225 226 /** 227 * @brief Start a ble advertising 228 * 229 * @param 230 * - actv_idx: the index of activity 231 * - duration: Advertising duration (in unit of 10ms). 0 means that advertising continues 232 * - callback: register a callback for this action, ble_cmd_t: BLE_START_ADV 233 * 234 * @attention 1.you must wait callback status, 0 mean success. 235 * @attention 2.must used after bk_ble_create_advertising 236 * @return 237 * - BK_ERR_BLE_SUCCESS: succeed 238 * - others: other errors. 239 */ 240 ble_err_t bk_ble_start_advertising(uint8_t actv_idx, uint16 duration, ble_cmd_cb_t callback); 241 242 /** 243 * @brief Stop the advertising that has been started 244 * 245 * @param 246 * - actv_idx: the index of activity 247 * - callback: register a callback for this action, ble_cmd_t: BLE_STOP_ADV 248 * @attention 1.you must wait callback status, 0 mean success. 249 * @attention 2.must used after bk_ble_start_advertising 250 * @return 251 * - BK_ERR_BLE_SUCCESS: succeed 252 * - others: other errors. 253 */ 254 ble_err_t bk_ble_stop_advertising(uint8_t actv_idx, ble_cmd_cb_t callback); 255 256 /** 257 * @brief Delete the advertising that has been created 258 * 259 * @param 260 * - actv_idx: the index of activity 261 * - callback: register a callback for this action, ble_cmd_t: BLE_DELETE_ADV 262 * @attention 1.you must wait callback status, 0 mean success. 263 * @attention 2.must used after bk_ble_create_advertising 264 * @return 265 * - BK_ERR_BLE_SUCCESS: succeed 266 * - others: other errors. 267 */ 268 ble_err_t bk_ble_delete_advertising(uint8_t actv_idx, ble_cmd_cb_t callback); 269 270 /** 271 * @brief Set the advertising data 272 * 273 * @param 274 * - actv_idx: the index of activity 275 * - adv_buff: advertising data 276 * - adv_len: the length of advertising data 277 * - callback: register a callback for this action, ble_cmd_t: BLE_SET_ADV_DATA 278 * @attention 1.you must wait callback status, 0 mean success. 279 * @attention 2.must used after bk_ble_create_advertising 280 * 281 * 282 * User example: 283 * @code 284 * const uint8_t adv_data[] = {0x02, 0x01, 0x06, 0x0A, 0x09, 0x37 0x32, 0x33, 0x31, 0x4e, 0x5f, 0x42, 0x4c, 0x45}; 285 * bk_ble_set_adv_data(actv_idx, adv_data, sizeof(adv_data), ble_at_cmd_cb); 286 * @endcode 287 * @return 288 * - BK_ERR_BLE_SUCCESS: succeed 289 * - others: other errors. 290 */ 291 ble_err_t bk_ble_set_adv_data(uint8_t actv_idx, uint8_t* adv_buff, uint8_t adv_len, ble_cmd_cb_t callback); 292 293 /** 294 * @brief Set the scan response data 295 * 296 * @param 297 * - actv_idx: the index of activity 298 * - scan_buff: scan response data 299 * - scan_len: the length of scan response data 300 * - callback: register a callback for this action, ble_cmd_t: BLE_SET_RSP_DATA 301 * @attention 1.you must wait callback status, 0 mean success. 302 * @attention 2.scan rsp data similaly to adv data 303 * @attention 3.must used after bk_ble_create_advertising 304 * 305 * 306 * User example: 307 * @code 308 * const uint8_t scan_data[] = {0x02, 0x01, 0x06, 0x0A, 0x09, 0x37 0x32, 0x33, 0x31, 0x4e, 0x5f, 0x42, 0x4c, 0x45}; 309 * bk_ble_set_scan_rsp_data(actv_idx, scan_data, sizeof(scan_data), ble_at_cmd_cb); 310 * @endcode 311 * @return 312 * - BK_ERR_BLE_SUCCESS: succeed 313 * - others: other errors. 314 */ 315 ble_err_t bk_ble_set_scan_rsp_data(uint8_t actv_idx, uint8_t* scan_buff, uint8_t scan_len, ble_cmd_cb_t callback); 316 317 /** 318 * @brief Set the periodic advertising data 319 * 320 * @param 321 * - actv_idx: the index of activity 322 * - per_adv_buff: periodic advertising data 323 * - per_adv_len: the length of periodic advertising data 324 * - callback: register a callback for this action, ble_cmd_t: BLE_SET_ADV_DATA???? 325 * @attention 1.you must wait callback status, 0 mean success. 326 * @attention 2.must used after bk_ble_create_advertising 327 * 328 * User example: 329 * @code 330 * const uint8_t adv_data[] = {0x02, 0x01, 0x06, 0x0A, 0x09, 0x37 0x32, 0x33, 0x31, 0x4e, 0x5f, 0x42, 0x4c, 0x45}; 331 * bk_ble_set_per_adv_data(actv_idx, adv_data, sizeof(adv_data), ble_at_cmd_cb); 332 * @endcode 333 * 334 * @return 335 * - BK_ERR_BLE_SUCCESS: succeed 336 * - others: other errors. 337 */ 338 ble_err_t bk_ble_set_per_adv_data(uint8_t actv_idx, uint8_t* per_adv_buff, uint8_t per_adv_len, ble_cmd_cb_t callback); 339 340 /** 341 * @brief Read the phy of connection device 342 * 343 * @param 344 * - conn_idx: the index of connection device 345 * - callback: register a callback for this action, ble_cmd_t: BLE_CONN_READ_PHY 346 * @attention 1.you must wait callback status, 0 mean success. 347 * @attention 2.must used after after connected 348 * 349 * User example: 350 * @code 351 * bk_ble_read_phy(conn_idx, ble_at_cmd_cb); 352 * @endcode 353 * 354 * @return 355 * - BK_ERR_BLE_SUCCESS: succeed 356 * - others: other errors. 357 */ 358 ble_err_t bk_ble_read_phy(uint8_t conn_idx, ble_cmd_cb_t callback); 359 360 361 /** 362 * @brief Set the phy of connection device 363 * 364 * @param 365 * - conn_idx: the index of connection device 366 * - phy_info: phy parameters 367 * - callback: register a callback for this action, ble_cmd_t: BLE_CONN_SET_PHY 368 * @attention 1.you must wait callback status, 0 mean success. 369 * @attention 2.must used after after connected 370 * 371 * User example: 372 * @code 373 * ble_set_phy_t * phy = {0x04, 0x01, 0x01}; 374 * //set tx phy to s2 coded phy, and set rx phy to 1M phy 375 * bk_ble_set_phy(1, phy, ble_at_cmd_cb); 376 * @endcode 377 * 378 * @return 379 * - BK_ERR_BLE_SUCCESS: succeed 380 * - others: other errors. 381 */ 382 ble_err_t bk_ble_set_phy(uint8_t conn_idx, ble_set_phy_t * phy_info, ble_cmd_cb_t callback); 383 384 /** 385 * @brief Update connection parameters 386 * 387 * @param 388 * - conn_idx: the index of connection 389 * - conn_param: connection parameters 390 * - callback: register a callback for this action, ble_cmd_t: BLE_CONN_UPDATE_PARAM 391 * @attention 1.you must wait callback status, 0 mean success. 392 * @attention 2.must used after connected 393 * 394 * @return 395 * - BK_ERR_BLE_SUCCESS: succeed 396 * - others: other errors. 397 */ 398 ble_err_t bk_ble_update_param(uint8_t conn_idx, ble_conn_param_t *conn_param, ble_cmd_cb_t callback); 399 400 /** 401 * @brief Disconnect a ble connection 402 * 403 * @param 404 * - conn_idx: the index of connection 405 * - callback: register a callback for this action, ble_cmd_t: BLE_CONN_DIS_CONN 406 * 407 * @attention 1.you must wait callback status, 0 mean success. 408 * @attention 2.must used after connected 409 * 410 * @return 411 * - BK_ERR_BLE_SUCCESS: succeed 412 * - others: other errors. 413 */ 414 ble_err_t bk_ble_disconnect(uint8_t conn_idx, ble_cmd_cb_t callback); 415 416 /** 417 * @brief Exchange MTU 418 * 419 * @param 420 * - conn_idx: the index of connection 421 * - callback: register a callback for this action, ble_cmd_t: BLE_CONN_UPDATE_MTU 422 * @attention 1.you must wait callback status, 0 mean success. 423 * @attention 2.must used after connected 424 * 425 * @return 426 * - BK_ERR_BLE_SUCCESS: succeed 427 * - others: other errors. 428 */ 429 ble_err_t bk_ble_gatt_mtu_change(uint8_t conn_idx, ble_cmd_cb_t callback); 430 431 /** 432 * @brief Set maximal Exchange MTU 433 * 434 * @param 435 * - max_mtu: the value to set 436 * @attention 1.you must wait callback status, 0 mean success. 437 * @attention 2.must used before connected 438 * 439 * @return 440 * - BK_ERR_BLE_SUCCESS: succeed 441 * - others: other errors. 442 */ 443 ble_err_t bk_ble_set_max_mtu(uint16_t max_mtu); 444 445 /** 446 * @brief Create a ble scan activity 447 * 448 * @param 449 * - actv_idx: the index of activity 450 * - scan_param: the scan parameter 451 * - callback: register a callback for this action, ble_cmd_t: BLE_CREATE_SCAN 452 * 453 * @attention 1.you must wait callback status, 0 mean success. 454 * 455 * User exzample: 456 * @code 457 ble_scan_param_t scan_param; 458 459 scan_param.own_addr_type = 0;//BLE_STATIC_ADDR 460 scan_param.scan_phy = 5; 461 scan_param.scan_intv = 0x64; //interval 462 scan_param.scan_wd = 0x1e; //windows 463 bk_ble_create_scaning(actv_idx, &, ble_at_cmd); 464 * 465 * @endcode 466 * 467 * @return 468 * - BK_ERR_BLE_SUCCESS: succeed 469 * - others: other errors. 470 */ 471 ble_err_t bk_ble_create_scaning(uint8_t actv_idx, ble_scan_param_t *scan_param, ble_cmd_cb_t callback); 472 473 /** 474 * @brief Start a ble scan 475 * 476 * @param 477 * - actv_idx: the index of activity 478 * - callback: register a callback for this action, ble_cmd_t: BLE_START_SCAN 479 * 480 * @attention 1.you must wait callback status, 0 mean success. 481 * @attention 2.must used after bk_ble_create_scaning 482 * @attention 3.adv will report in ble_notice_cb_t as BLE_5_REPORT_ADV 483 * 484 * @return 485 * - BK_ERR_BLE_SUCCESS: succeed 486 * - others: other errors. 487 */ 488 ble_err_t bk_ble_start_scaning(uint8_t actv_idx, ble_cmd_cb_t callback); 489 490 ble_err_t bk_ble_start_scaning_ex(uint8_t actv_idx, uint8_t filt_duplicate, uint16_t duration, uint16_t period, ble_cmd_cb_t callback); 491 492 493 /** 494 * @brief Stop the scan that has been started 495 * 496 * @param 497 * - actv_idx: the index of activity 498 * - callback: register a callback for this action, ble_cmd_t: BLE_STOP_SCAN 499 * 500 * @attention 1.you must wait callback status, 0 mean success. 501 * @attention 2.must used after bk_ble_start_scaning 502 * 503 * @return 504 * - BK_ERR_BLE_SUCCESS: succeed 505 * - others: other errors. 506 */ 507 ble_err_t bk_ble_stop_scaning(uint8_t actv_idx, ble_cmd_cb_t callback); 508 509 /** 510 * @brief Delete the scan that has been created 511 * 512 * @param 513 * - actv_idx: the index of activity 514 * - callback: register a callback for this action, ble_cmd_t: BLE_DELETE_SCAN 515 * 516 * @attention 1.you must wait callback status, 0 mean success. 517 * @attention 2.must used after bk_ble_create_scaning 518 * 519 * @return 520 * - BK_ERR_BLE_SUCCESS: succeed 521 * - others: other errors. 522 */ 523 ble_err_t bk_ble_delete_scaning(uint8_t actv_idx, ble_cmd_cb_t callback); 524 525 /** 526 * @brief Create a activity for initiating a connection 527 * 528 * @param 529 * - con_idx: the index of connection 530 * - conn_param: the connection parameter 531 * - callback: register a callback for this action, ble_cmd_t: BLE_INIT_CREATE 532 * 533 * @attention 1.you must wait callback status, 0 mean success. 534 * 535 * User example: 536 * @code 537 * 538 * ble_conn_param_t conn_param; 539 conn_param.intv_min = 0x40; //interval 540 conn_param.intv_max = 0x40; //interval 541 conn_param.con_latency = 0; 542 conn_param.sup_to = 0x200;//supervision timeout 543 conn_param.init_phys = 1;// 1M 544 bk_ble_create_init(con_idx, &conn_param, ble_at_cmd); 545 * @endcode 546 * 547 * @return 548 * - BK_ERR_BLE_SUCCESS: succeed 549 * - others: other errors. 550 */ 551 ble_err_t bk_ble_create_init(uint8_t con_idx, ble_conn_param_t *conn_param, ble_cmd_cb_t callback); 552 553 /** 554 * @brief Initiate a connection 555 * 556 * @param 557 * - con_idx: the index of connection 558 * - callback: register a callback for this action, ble_cmd_t: BLE_INIT_START_CONN 559 * 560 * @attention 1.you must wait callback status, 0 mean success. 561 * @attention 2.must used after bk_ble_create_init 562 * @attention 3.when connect result, will recv BLE_5_INIT_CONNECT_EVENT in ble_notice_cb_t 563 * 564 * @return 565 * - BK_ERR_BLE_SUCCESS: succeed 566 * - others: other errors. 567 */ 568 ble_err_t bk_ble_init_start_conn(uint8_t con_idx, ble_cmd_cb_t callback); 569 570 /** 571 * @brief Stop a connection 572 * 573 * @param 574 * - con_idx: the index of connection 575 * - callback: register a callback for this action, ble_cmd_t: BLE_INIT_STOP_CONN 576 * 577 * @attention 1.you must wait callback status, 0 mean success. 578 * @attention 2.must used after bk_ble_init_start_conn 579 * 580 * @return 581 * - BK_ERR_BLE_SUCCESS: succeed 582 * - others: other errors. 583 */ 584 ble_err_t bk_ble_init_stop_conn(uint8_t con_idx,ble_cmd_cb_t callback);//todo: upper feature 585 586 /** 587 * @brief Set the address of the device to be connected 588 * 589 * @param 590 * - connidx: the index of connection 591 * - bdaddr: the address of the device to be connected 592 * - addr_type: the address type of the device to be connected, 1: public 0: random 593 * 594 * 595 * @attention 1.you must wait callback status, 0 mean success. 596 * @attention 2.must used after bk_ble_create_init 597 * @attention 3.addr_type must right, if wrong, cant connect 598 * 599 * @return 600 * - BK_ERR_BLE_SUCCESS: succeed 601 * - others: other errors. 602 */ 603 ble_err_t bk_ble_init_set_connect_dev_addr(uint8_t connidx, bd_addr_t *bdaddr, uint8_t addr_type); 604 605 606 607 ble_err_t bk_ble_create_periodic_sync(uint8_t actv_idx, ble_cmd_cb_t callback); 608 ble_err_t bk_ble_start_periodic_sync(uint8_t actv_idx, ble_periodic_param_t *param, ble_cmd_cb_t callback); 609 ble_err_t bk_ble_stop_periodic_sync(uint8_t actv_idx, ble_cmd_cb_t callback); 610 ble_err_t bk_ble_delete_periodic_sync(uint8_t actv_idx, ble_cmd_cb_t callback); 611 612 /** 613 * @brief Get an idle activity 614 * 615 * @return 616 * - xx: the idle activity's index 617 */ 618 uint8_t bk_ble_get_idle_actv_idx_handle(void); 619 620 /** 621 * @brief Get the maximum count of activities 622 * 623 * @return 624 * - xx: the maximum count of activities 625 */ 626 uint8_t bk_ble_get_max_actv_idx_count(void); 627 628 /** 629 * @brief Get the maximum count of supported connections 630 * 631 * @return 632 * - xx: the maximum count of supported connections 633 */ 634 uint8_t bk_ble_get_max_conn_idx_count(void); 635 636 637 /** 638 * @brief Get an idle connection activity 639 * 640 * @return 641 * - xx: the idle connection activity's index 642 */ 643 uint8_t bk_ble_get_idle_conn_idx_handle(void); 644 645 646 /** 647 * @brief Find the specific connection activity by address 648 * 649 * @param 650 * - connt_addr: the address of the connected device 651 * 652 * @return 653 * - xx: the index of the connection activity meeting the address 654 */ 655 uint8_t bk_ble_find_conn_idx_from_addr(bd_addr_t *connt_addr); 656 657 658 /** 659 * @brief Get the connection state of the specific device 660 * 661 * @param 662 * - connt_addr: the device's address 663 * 664 * @return 665 * - 1: this device is connected 666 * - 0: this device is disconnected 667 */ 668 uint8_t bk_ble_get_connect_state(bd_addr_t * connt_addr); 669 670 /** 671 * @brief get ble mac addr 672 * 673 * @attention 1. return mac is 6 bytes. 674 * @return 675 * - BK_ERR_BLE_SUCCESS: succeed 676 * - others: other errors. 677 */ 678 ble_err_t bk_ble_get_mac(uint8_t *mac); 679 680 /** 681 * @brief set ble mac addr 682 * 683 * @param 684 * - actv_idx: actv_idx: the index of activity 685 * - mac: the device's address 686 * - callback: register a callback for this action 687 * 688 * @attention 1. This API is not ready yet. 689 * @return 690 * - BK_ERR_BLE_SUCCESS: succeed 691 * - others: other errors. 692 */ 693 ble_err_t bk_ble_set_mac(uint8_t actv_idx, uint8_t *mac, ble_cmd_cb_t callback); 694 695 /** 696 * @brief As slaver, send a notification of an attribute's value 697 * 698 * @param 699 * - con_idx: the index of connection 700 * - len: the length of attribute's value 701 * - buf: attribute's value 702 * - prf_id: The id of the profile 703 * - att_idx: The index of the attribute 704 * 705 * @return 706 * - BK_ERR_BLE_SUCCESS: succeed 707 * - others: other errors. 708 */ 709 ble_err_t bk_ble_send_noti_value(uint8_t con_idx,uint32_t len, uint8_t *buf, uint16_t prf_id, uint16_t att_idx); 710 711 /** 712 * @brief As slaver, send an indication of an attribute's value 713 * 714 * @param 715 * - con_idx: the index of connection 716 * - len: the length of attribute's value 717 * - buf: attribute's value 718 * - prf_id: The id of the profile 719 * - att_idx: The index of the attribute 720 * 721 * @return 722 * - BK_ERR_BLE_SUCCESS: succeed 723 * - others: other errors. 724 */ 725 ble_err_t bk_ble_send_ind_value(uint8_t con_idx,uint32_t len, uint8_t *buf, uint16_t prf_id, uint16_t att_idx); 726 727 /** 728 * @brief reg hci recv callback 729 * 730 * @param 731 * - evt_cb: evt callback function 732 * - acl_cb: acl callback function 733 * 734 * @attention 1. you must call this after recv BLE_5_STACK_OK evt ! 735 * 736 * @return 737 * - BK_ERR_BLE_SUCCESS: succeed 738 * - others: other errors. 739 */ 740 ble_err_t bk_ble_reg_hci_recv_callback(ble_hci_to_host_cb evt_cb, ble_hci_to_host_cb acl_cb); 741 742 /** 743 * @brief send hci to controller. 744 * 745 * 746 * @param 747 * - type: see BK_BLE_HCI_TYPE. 748 * - buf: payload 749 * - len: buf's len 750 * 751 * @attention 1. you must call this after bk_ble_reg_hci_recv_callback ! 752 * 753 * @return 754 * - BK_ERR_BLE_SUCCESS: succeed 755 **/ 756 ble_err_t bk_ble_hci_to_controller(uint8_t type, uint8_t *buf, uint16_t len); 757 758 759 760 /** 761 * @brief send hci cmd to controller. 762 * 763 * 764 * @param 765 * - buf: payload 766 * - len: buf's len 767 * 768 * @attention 1. you must call this after bk_ble_reg_hci_recv_callback ! 769 * 770 * @return 771 * - BK_ERR_BLE_SUCCESS: succeed 772 **/ 773 ble_err_t bk_ble_hci_cmd_to_controller(uint8_t *buf, uint16_t len); 774 775 /** 776 * @brief send hci acl to controller. 777 * 778 * 779 * @param 780 * - buf: payload 781 * - len: buf's len 782 * 783 * @attention 1. you must call this after bk_ble_reg_hci_recv_callback ! 784 * 785 * @return 786 * - BK_ERR_BLE_SUCCESS: succeed 787 **/ 788 ble_err_t bk_ble_hci_acl_to_controller(uint8_t *buf, uint16_t len); 789 790 791 792 /* 793 * @brief get if stack support central and link count 794 * 795 * @param 796 * - count: if return true, show how many central link can be support, otherwise not used. 797 * 798 * @return 799 * - 1: support 800 * - 0: not support. 801 */ 802 uint8_t bk_ble_if_support_central(uint8_t *count); 803 804 /* 805 * @brief get controller stack type 806 * 807 * @return 808 * enum BK_BLE_CONTROLLER_STACK_TYPE 809 */ 810 811 BK_BLE_CONTROLLER_STACK_TYPE bk_ble_get_controller_stack_type(void); 812 813 814 /* 815 * @brief get host stack type 816 * 817 * @return 818 * enum BK_BLE_HOST_STACK_TYPE 819 */ 820 BK_BLE_HOST_STACK_TYPE bk_ble_get_host_stack_type(void); 821 822 823 /* 824 * @brief get ble environment state 825 * 826 * @return 827 * - 1: ready 828 * - 0: not ready 829 */ 830 uint8_t bk_ble_get_env_state(void); 831 832 /* 833 * @brief set ble task stack size, default is 3072 834 * 835 * @param 836 * - size: stack size 837 * 838 * 839 * @attention 1.you must call it before app_ble_init !!!! 840 * @return 841 * - BK_ERR_BLE_SUCCESS: succeed 842 * - BK_ERR_BLE_FAIL: fail, because you call this func before app_ble_init !!! 843 */ 844 ble_err_t bk_ble_set_task_stack_size(uint16_t size); 845 846 /* 847 * @brief register a callback that will report the action of notification/indication/read/write 848 * 849 * @param 850 * - cb: callback 851 * 852 * @return 853 * - void 854 */ 855 void bk_ble_register_app_sdp_charac_callback(app_sdp_charac_callback cb); 856 857 /* 858 * @brief register a callback that will report the result of gatt operation 859 * 860 * @param 861 * - cb: callback 862 * 863 * @return 864 * - void 865 */ 866 void bk_ble_register_app_sdp_common_callback(app_sdp_comm_callback cb); 867 868 /** 869 * @brief As master, enable notification or indication 870 * 871 * @param 872 * - con_idx: the index of connection 873 * - ccc_handle: the handle of Client Characteristic Configuration descriptor 874 * - ccc_value: descriptor value, 0x01 means notification ,0x02 means indication 875 * 876 * @return 877 * - 0: succeed 878 * - others: errors. 879 */ 880 uint8_t bk_ble_gatt_write_ccc(uint8_t con_idx,uint16_t ccc_handle,uint16_t ccc_value); 881 882 /** 883 * @brief As master, write attribute value 884 * 885 * @param 886 * - con_idx: the index of connection 887 * - att_handle: the handle of attribute value 888 * - data: value data 889 * - len: the length of attribute value 890 * 891 * @return 892 * - BK_ERR_BLE_SUCCESS: succeed 893 * - others: fail 894 */ 895 ble_err_t bk_ble_gatt_write_value(uint8_t con_idx, uint16_t att_handle, uint16_t len, uint8_t *data); 896 897 /** 898 * @brief As slaver, send response value 899 * 900 * @param 901 * - len: the length of attribute's value 902 * - buf: attribute's value 903 * - prf_id: The id of the profile 904 * - att_idx: The index of the attribute 905 * 906 * @return 907 * - BK_ERR_BLE_SUCCESS: succeed 908 * - others: fail 909 */ 910 ble_err_t bk_ble_read_response_value(uint32_t len, uint8_t *buf, uint16_t prf_id, uint16_t att_idx); 911 912 /** 913 * @brief As master, configure attribute value 914 * 915 * @param 916 * - con_idx: the index of connection 917 * - mode: authentication features 918 * - iocap: IO Capability Values 919 * - sec_req: Security Defines 920 * - oob: OOB Data Present Flag Values 921 * 922 * @return 923 * - BK_ERR_BLE_SUCCESS: succeed 924 * - others: fail 925 */ 926 ble_err_t bk_ble_sec_send_auth_mode(uint8_t con_idx, uint8_t mode, uint8_t iocap, uint8_t sec_req, uint8_t oob); 927 928 /** 929 * @brief ble init function 930 * 931 * @param 932 * 933 * @return 934 * - BK_ERR_BLE_SUCCESS: succeed 935 * - others: fail 936 */ 937 ble_err_t bk_ble_init(void); 938 939 /** 940 * @brief ble deinit function 941 * 942 * @param 943 * 944 * @return 945 * - BK_ERR_BLE_SUCCESS: succeed 946 * - others: fail 947 */ 948 ble_err_t bk_ble_deinit(void); 949 950 /* 951 * @} 952 */ 953 #ifdef __cplusplus 954 } 955 #endif 956 957 //#endif 958 959 #endif 960