1 /** 2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 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 * Description: SLE Connection Manager module. 15 */ 16 17 /** 18 * @defgroup sle_connection_manager connection manager API 19 * @ingroup SLE 20 * @{ 21 */ 22 23 #ifndef SLE_CONNECTION_MANAGER 24 #define SLE_CONNECTION_MANAGER 25 26 #include <stdint.h> 27 #include "errcode.h" 28 #include "sle_common.h" 29 #include "sle_low_latency.h" 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 /** 36 * @if Eng 37 * @brief Enum of sle pairing state. 38 * @else 39 * @brief 星闪配对状态。 40 * @endif 41 */ 42 typedef enum { 43 SLE_PAIR_NONE = 0x01, /*!< @if Eng Pair state of none 44 @else 未配对状态 @endif */ 45 SLE_PAIR_PAIRING = 0x02, /*!< @if Eng Pair state of pairing 46 @else 正在配对 @endif */ 47 SLE_PAIR_PAIRED = 0x03 /*!< @if Eng Pair state of paired 48 @else 已完成配对 @endif */ 49 } sle_pair_state_t; 50 51 /** 52 * @if Eng 53 * @brief Enum of sle pairing state. 54 * @else 55 * @brief 星闪断链原因。 56 * @endif 57 */ 58 typedef enum { 59 SLE_DISCONNECT_BY_REMOTE = 0x10, /*!< @if Eng disconnect by remote 60 @else 远端断链 @endif */ 61 SLE_DISCONNECT_BY_LOCAL = 0x11, /*!< @if Eng disconnect by local 62 @else 本端断链 @endif */ 63 } sle_disc_reason_t; 64 65 /** 66 * @if Eng 67 * @brief Enum of sle ACB connection state. 68 * @else 69 * @brief SLE ACB连接状态。 70 * @endif 71 */ 72 typedef enum { 73 SLE_ACB_STATE_NONE = 0x00, /*!< @if Eng SLE ACB connect state of none 74 @else SLE ACB 未连接状态 @endif */ 75 SLE_ACB_STATE_CONNECTED = 0x01, /*!< @if Eng SLE ACB connect state of connected 76 @else SLE ACB 已连接 @endif */ 77 SLE_ACB_STATE_DISCONNECTED = 0x02, /*!< @if Eng SLE ACB connect state of disconnected 78 @else SLE ACB 已断接 @endif */ 79 } sle_acb_state_t; 80 81 /** 82 * @if Eng 83 * @brief Enum of sle crytography algorithm. 84 * @else 85 * @brief 星闪加密算法类型。 86 * @endif 87 */ 88 typedef enum { 89 SLE_CRYTO_ALGO_AC1 = 0x00, /*!< @if Eng crytography algorithm ac1 90 @else AC1加密算法类型 @endif */ 91 SLE_CRYTO_ALGO_AC2 = 0x01, /*!< @if Eng crytography algorithm ac2 92 @else AC2加密算法类型@endif */ 93 SLE_CRYTO_ALGO_EA1 = 0x02, /*!< @if Eng crytography algorithm ea1 94 @else EA1加密算法类型 @endif */ 95 SLE_CRYTO_ALGO_EA2 = 0x03, /*!< @if Eng crytography algorithm ea2 96 @else EA2加密算法类型 @endif */ 97 } sle_crypto_algo_t; 98 99 /** 100 * @if Eng 101 * @brief Enum of sle key derivation algorithm 102 * @else 103 * @brief 星闪秘钥分发算法类型。 104 * @endif 105 */ 106 typedef enum { 107 SLE_KEY_DERIV_ALGO_HA1 = 0x00, /*!< @if Eng key derivation algorithm ac1 108 @else HA1秘钥分发算法类型 @endif */ 109 SLE_KEY_DERIV_ALGO_HA2 = 0x01, /*!< @if Eng key derivation algorithm ac2 110 @else HA2秘钥分发算法类型 @endif */ 111 } sle_key_deriv_algo_t; 112 113 /** 114 * @if Eng 115 * @brief Enum of sle integrity check indicator 116 * @else 117 * @brief 星闪完整性校验指示类型。 118 * @endif 119 */ 120 typedef enum { 121 SLE_ENCRYPTION_ENABLE_INTEGRITY_CHK_ENABLE = 0x00, /*!< @if Eng Encryption and integrity check 122 are enabled at the same time. 123 @else 加密和完整性保护同时启动 @endif */ 124 SLE_ENCRYPTION_DISABLE_INTEGRITY_CHK_ENABLE = 0x01, /*!< @if Eng Do not enable encryption, but enable 125 integrity check. 126 @else 不启动加密,启动完整性保护 @endif */ 127 SLE_ENCRYPTION_ENABLE_INTEGRITY_CHK_DISABLE = 0x02, /*!< @if Eng Encryption is enabled, but integrity 128 check is disabled. 129 @else 启动加密,不启动完整性保护 @endif */ 130 SLE_ENCRYPTION_DISABLE_INTEGRITY_CHK_DISABLE = 0x03, /*!< @if Eng Encryption and integrity check 131 are not enabled. 132 @else 不启动加密,不启动完整性保护 @endif */ 133 } sle_integr_chk_ind_t; 134 135 /** 136 * @if Eng 137 * @brief Enum of sle logical link update parameters. 138 * @else 139 * @brief 星闪逻辑链路更新参数请求 140 * @endif 141 */ 142 typedef struct { 143 uint16_t interval_min; /*!< @if Eng minimum interval 144 @else 链路调度最小间隔,单位slot @endif */ 145 uint16_t interval_max; /*!< @if Eng maximum interval 146 @else 链路调度最大间隔,单位slot @endif */ 147 uint16_t max_latency; /*!< @if Eng maximum latency 148 @else 延迟周期,单位slot @endif */ 149 uint16_t supervision_timeout; /*!< @if Eng timeout 150 @else 超时时间,单位10ms @endif */ 151 } sle_connection_param_update_req_t; 152 153 /** 154 * @if Eng 155 * @brief Enum of sle logical link update parameters. 156 * @else 157 * @brief 星闪逻辑链路更新参数 158 * @endif 159 */ 160 typedef struct { 161 uint16_t conn_id; /*!< @if Eng connection ID 162 @else 连接ID @endif */ 163 uint16_t interval_min; /*!< @if Eng minimum interval 164 @else 链路调度最小间隔,单位slot @endif */ 165 uint16_t interval_max; /*!< @if Eng maximum interval 166 @else 链路调度最大间隔,单位slot @endif */ 167 uint16_t max_latency; /*!< @if Eng maximum latency 168 @else 延迟周期,单位slot @endif */ 169 uint16_t supervision_timeout; /*!< @if Eng timeout 170 @else 超时时间,单位10ms @endif */ 171 } sle_connection_param_update_t; 172 173 /** 174 * @if Eng 175 * @brief Enum of sle logical link update event parameters. 176 * @else 177 * @brief 星闪逻辑链路更新事件参数 178 * @endif 179 */ 180 typedef struct { 181 uint16_t interval; /*!< @if Eng interval 182 @else 链路调度间隔,单位slot @endif */ 183 uint16_t latency; /*!< @if Eng latency 184 @else 延迟周期,单位slot @endif */ 185 uint16_t supervision; /*!< @if Eng timeout 186 @else 超时时间,单位10ms @endif */ 187 } sle_connection_param_update_evt_t; 188 189 /** 190 * @if Eng 191 * @brief Enum of sle authentication result. 192 * @else 193 * @brief 星闪认证结果 194 * @endif 195 */ 196 typedef struct { 197 uint8_t link_key[SLE_LINK_KEY_LEN]; /*!< @if Eng link key 198 @else 链路密钥 @endif */ 199 uint8_t crypto_algo; /*!< @if Eng encryption algorithm type { @ref sle_crypto_algo_t } 200 @else 加密算法类型 { @ref sle_crypto_algo_t } @endif */ 201 uint8_t key_deriv_algo; /*!< @if Eng key distribution algorithm type { @ref sle_key_deriv_algo_t } 202 @else 秘钥分发算法类型 { @ref sle_key_deriv_algo_t } @endif */ 203 uint8_t integr_chk_ind; /*!< @if Eng integrity check indication { @ref sle_integr_chk_ind_t } 204 @else 完整性校验指示 { @ref sle_integr_chk_ind_t } @endif */ 205 } sle_auth_info_evt_t; 206 207 /** 208 * @brief 星闪无线帧类型,bitmap表示 209 */ 210 typedef enum { 211 SLE_RADIO_FRAME_1 = 0, /*!< @if Eng Radio frame type 1. 212 @else 无线帧类型1。 @endif */ 213 SLE_RADIO_FRAME_2 = 1, /*!< @if Eng Eng Radio frame type 2. 214 @else 无线帧类型2。 @endif */ 215 SLE_RADIO_FRAME_3_M0 = 2, /*!< @if Eng Radio frame type 3 and m sequence 0. 216 @else 无线帧类型3,m序列0。 @endif */ 217 SLE_RADIO_FRAME_3_M1 = 3, /*!< @if Eng Radio frame type 3 and m sequence 1. 218 @else 无线帧类型3,m序列1。 @endif */ 219 SLE_RADIO_FRAME_3_M2 = 4, /*!< @if Eng Radio frame type 3 and m sequence 2. 220 @else 无线帧类型3,m序列2。 @endif */ 221 SLE_RADIO_FRAME_3_M3 = 5, /*!< @if Eng Radio frame type 3 and m sequence 3. 222 @else 无线帧类型3,m序列3。 @endif */ 223 SLE_RADIO_FRAME_3_M4 = 6, /*!< @if Eng Radio frame type 3 and m sequence 4. 224 @else 无线帧类型3,m序列4。 @endif */ 225 SLE_RADIO_FRAME_3_M5 = 7, /*!< @if Eng Radio frame type 3 and m sequence 5. 226 @else 无线帧类型3,m序列5。 @endif */ 227 SLE_RADIO_FRAME_4_M0 = 8, /*!< @if Eng Radio frame type 4 and m sequence 0. 228 @else 无线帧类型4,m序列0 @endif */ 229 SLE_RADIO_FRAME_4_M1 = 9, /*!< @if Eng Radio frame type 4 and m sequence 1. 230 @else 无线帧类型4,m序列1 @endif */ 231 SLE_RADIO_FRAME_4_M2 = 10, /*!< @if Eng Radio frame type 4 and m sequence 2. 232 @else 无线帧类型4,m序列2。 @endif */ 233 SLE_RADIO_FRAME_4_M3 = 11, /*!< @if Eng Radio frame type 4 and m sequence 3. 234 @else 无线帧类型4,m序列3。 @endif */ 235 SLE_RADIO_FRAME_4_M4 = 12, /*!< @if Eng Radio frame type 4 and m sequence 4. 236 @else 无线帧类型4,m序列4。 @endif */ 237 SLE_RADIO_FRAME_4_M5 = 13, /*!< @if Eng Radio frame type 4 and m sequence 5. 238 @else 无线帧类型4,m序列5。 @endif */ 239 SLE_RADIO_FRAME_END 240 } sle_radio_frame_t; 241 242 /** 243 * @brief 星闪发送/接收PHY类型,bitmap表示 244 */ 245 typedef enum { 246 SLE_PHY_1M = 0x0, /*!< @if Eng 1M PHY 247 @else 1M PHY @endif */ 248 SLE_PHY_2M = 0x1, /*!< @if Eng 2M PHY 249 @else 2M PHY @endif */ 250 SLE_PHY_4M = 0x2, /*!< @if Eng 4M PHY 251 @else 4M PHY @endif */ 252 SLE_PHY_SUPPORT_NUM, 253 } sle_phy_tx_rx_t; 254 255 /** 256 * @brief 星闪发送/接收导频密度指示,bitmap表示 257 */ 258 typedef enum { 259 SLE_PHY_PILOT_DENSITY_4_TO_1 = 0x0, /*!< @if Eng The pilot density is 4:1. 260 @else 导频密度为4:1 @endif */ 261 SLE_PHY_PILOT_DENSITY_8_TO_1 = 0x1, /*!< @if Eng The pilot density is 8:1. 262 @else 导频密度为8:1 @endif */ 263 SLE_PHY_PILOT_DENSITY_16_TO_1 = 0x2, /*!< @if Eng The pilot density is 16:1. 264 @else 导频密度为16:1 @endif */ 265 SLE_PHY_PILOT_DENSITY_NUM, 266 } sle_phy_tx_rx_pilot_density_t; 267 268 /** 269 * @if Eng 270 * @brief Struct of sle phy parameter. 271 * @else 272 * @brief 星闪phy参数 273 * @endif 274 */ 275 typedef struct { 276 uint8_t tx_format; /*!< @if Eng Transmitted radio frame type, @ref sle_radio_frame_t 277 @else 发送无线帧类型,参考 { @ref sle_radio_frame_t }。 @endif */ 278 uint8_t rx_format; /*!< @if Eng Received radio frame type, @ref sle_radio_frame_t 279 @else 接收无线帧类型,参考 { @ref sle_radio_frame_t }。 @endif */ 280 uint8_t tx_phy; /*!< @if Eng Transmitted PHY, @ref sle_phy_tx_rx_t 281 @else 发送PHY,参考 { @ref sle_phy_tx_rx_t }。 @endif */ 282 uint8_t rx_phy; /*!< @if Eng Received PHY, @ref sle_phy_tx_rx_t 283 @else 接收PHY,参考 { @ref sle_phy_tx_rx_t }。 @endif */ 284 uint8_t tx_pilot_density; /*!< @if Eng Transmitted pilot density indicator, @ref sle_phy_tx_rx_pilot_density_t 285 @else 发送导频密度指示,参考 { @ref sle_phy_tx_rx_pilot_density_t }。 @endif */ 286 uint8_t rx_pilot_density; /*!< @if Eng Received pilot density indicator, @ref sle_phy_tx_rx_pilot_density_t 287 @else 接收导频密度指示,参考 { @ref sle_phy_tx_rx_pilot_density_t }。 @endif */ 288 uint8_t g_feedback; /*!< @if Eng Indicates the feedback type of the pre-transmitted link. 289 The value range is 0 to 63. 290 @else 先发链路反馈类型指示,取值范围0-63。 @endif */ 291 uint8_t t_feedback; /*!< @if Eng Indicates the feedback type of the post-transmit link. 292 The value range is 0-7. 293 @else 后发链路反馈类型指示,取值范围0-7。 @endif */ 294 } sle_set_phy_t; 295 296 /** 297 * @if Eng 298 * @brief Struct of Default sle connection parameter. 299 * @else 300 * @brief 星闪默认连接参数 301 * @endif 302 */ 303 typedef struct { 304 uint8_t enable_filter_policy; /*!< @if Eng Whether the filtering function is enabled on the link 305 @else 链路是否打开过滤功能 @endif */ 306 uint8_t initiate_phys; /*!< @if Eng Link scanning communication bandwidth: 1:1M, 2:2M 307 @else 链路扫描通信带宽: 1:1M, 2:2M @endif */ 308 uint8_t gt_negotiate; /*!< @if Eng Whether G-T interaction is performed during link establishment 309 @else 链路建立时是否进行G和T交互 @endif */ 310 uint16_t scan_interval; /*!< @if Eng Interval for scanning the peer 311 device during link establishment 312 @else 链路建立时扫描对端设备的interval @endif */ 313 uint16_t scan_window; /*!< @if Eng Scans the Windows operating system of the 314 peer device during link establishment. 315 @else 链路建立时扫描对端设备的windows @endif */ 316 uint16_t min_interval; /*!< @if Eng Minimum link scheduling interval 317 @else 链路调度最小interval @endif */ 318 uint16_t max_interval; /*!< @if Eng Maximum link scheduling interval 319 @else 链路调度最大interval @endif */ 320 uint16_t timeout; /*!< @if Eng Link Timeout Interval 321 @else 链路超时时间 @endif */ 322 } sle_default_connect_param_t; 323 324 /** 325 * @if Eng 326 * @brief Callback invoked when connect state changed. 327 * @par Callback invoked when connect state changed. 328 * @attention 1.This function is called in SLE service context,should not be blocked or do long time waiting. 329 * @attention 2.The memories of pointer are requested and freed by the SLE service automatically. 330 * @param [in] conn_id connection ID. 331 * @param [in] addr address. 332 * @param [in] conn_state connection state { @ref sle_acb_state_t }. 333 * @param [in] pair_state pairing state { @ref sle_pair_state_t }. 334 * @param [in] disc_reason the reason of disconnect { @ref sle_disc_reason_t }. 335 * @par Dependency: 336 * @li sle_common.h 337 * @see sle_connection_callbacks_t 338 * @else 339 * @brief 连接状态改变的回调函数。 340 * @par 连接状态改变的回调函数。 341 * @attention 1. 该回调函数运行于SLE service线程,不能阻塞或长时间等待。 342 * @attention 2. 指针由SLE service申请内存,也由SLE service释放,回调中不应释放。 343 * @param [in] conn_id 连接 ID。 344 * @param [in] addr 地址。 345 * @param [in] conn_state 连接状态 { @ref sle_acb_state_t }。 346 * @param [in] pair_state 配对状态 { @ref sle_pair_state_t }。 347 * @param [in] disc_reason 断链原因 { @ref sle_disc_reason_t }。 348 * @par 依赖: 349 * @li sle_common.h 350 * @see sle_connection_callbacks_t 351 * @endif 352 */ 353 typedef void (*sle_connect_state_changed_callback)(uint16_t conn_id, const sle_addr_t *addr, 354 sle_acb_state_t conn_state, sle_pair_state_t pair_state, sle_disc_reason_t disc_reason); 355 356 /** 357 * @if Eng 358 * @brief Callback invoked when connect parameter updated. 359 * @par Callback invoked when connect parameter updated. 360 * @attention 1.This function is called in SLE service context, should not be blocked or do long time waiting. 361 * @attention 2.The memories of pointer are requested and freed by the SLE service automatically. 362 * @param [in] conn_id connection ID. 363 * @param [in] addr address. 364 * @param [in] status error code. 365 * @param [in] param connection param. 366 * @par Dependency: 367 * @li sle_common.h 368 * @see sle_connection_callbacks_t 369 * @else 370 * @brief 连接参数更新的回调函数。 371 * @par 连接参数更新的回调函数。 372 * @attention 1. 该回调函数运行于SLE service线程,不能阻塞或长时间等待。 373 * @attention 2. 指针由SLE service申请内存,也由SLE service释放,回调中不应释放。 374 * @param [in] conn_id 连接 ID。 375 * @param [in] addr 地址。 376 * @param [in] status 执行结果错误码。 377 * @param [in] param 连接参数。 378 * @par 依赖: 379 * @li sle_common.h 380 * @see sle_connection_callbacks_t 381 * @endif 382 */ 383 typedef void (*sle_connect_param_update_callback)(uint16_t conn_id, errcode_t status, 384 const sle_connection_param_update_evt_t *param); 385 386 /** 387 * @if Eng 388 * @brief Callback invoked before the request for updating the connect parameter is complete. 389 * @par Callback invoked before the request for updating the connect parameter is complete. 390 * @attention 1.This function is called in SLE service context, should not be blocked or do long time waiting. 391 * @attention 2.The memories of pointer are requested and freed by the SLE service automatically. 392 * @param [in] conn_id connection ID. 393 * @param [in] status error code. 394 * @param [in] param connection param. 395 * @par Dependency: 396 * @li sle_common.h 397 * @see sle_connection_callbacks_t 398 * @else 399 * @brief 连接参数更新请求完成前的回调函数。 400 * @par 连接参数更新请求完成前的回调函数。 401 * @attention 1. 该回调函数运行于SLE service线程,不能阻塞或长时间等待。 402 * @attention 2. 指针由SLE service申请内存,也由SLE service释放,回调中不应释放。 403 * @param [in] conn_id 连接 ID。 404 * @param [in] status 执行结果错误码。 405 * @param [in] param 连接参数。 406 * @par 依赖: 407 * @li sle_common.h 408 * @see sle_connection_callbacks_t 409 * @endif 410 */ 411 typedef void (*sle_connect_param_update_req_callback)(uint16_t conn_id, errcode_t status, 412 const sle_connection_param_update_req_t *param); 413 414 /** 415 * @if Eng 416 * @brief Callback invoked when authentication complete. 417 * @par Callback invoked when authentication complete. 418 * @attention 1.This function is called in SLE service context,should not be blocked or do long time waiting. 419 * @attention 2.The memories of pointer are requested and freed by the SLE service automatically. 420 * @param [in] conn_id connection ID. 421 * @param [in] addr address. 422 * @param [in] status error code. 423 * @param [in] evt authentication event. 424 * @par Dependency: 425 * @li sle_common.h 426 * @see sle_connection_callbacks_t 427 * @else 428 * @brief 认证完成的回调函数。 429 * @par 认证完成的回调函数。 430 * @attention 1. 该回调函数运行于SLE service线程,不能阻塞或长时间等待。 431 * @attention 2. 指针由SLE service申请内存,也由SLE service释放,回调中不应释放。 432 * @param [in] conn_id 连接 ID。 433 * @param [in] addr 地址。 434 * @param [in] status 执行结果错误码。 435 * @param [in] evt 认证事件。 436 * @par 依赖: 437 * @li sle_common.h 438 * @see sle_connection_callbacks_t 439 * @endif 440 */ 441 typedef void (*sle_auth_complete_callback)(uint16_t conn_id, const sle_addr_t *addr, errcode_t status, 442 const sle_auth_info_evt_t* evt); 443 444 /** 445 * @if Eng 446 * @brief Callback invoked when pairing complete. 447 * @par Callback invoked when pairing complete. 448 * @attention 1.This function is called in SLE service context,should not be blocked or do long time waiting. 449 * @attention 2.The memories of pointer are requested and freed by the SLE service automatically. 450 * @param [in] conn_id connection ID. 451 * @param [in] addr address. 452 * @param [in] status error code. 453 * @par Dependency: 454 * @li sle_common.h 455 * @see sle_connection_callbacks_t 456 * @else 457 * @brief 配对完成的回调函数。 458 * @par 配对完成的回调函数。 459 * @attention 1. 该回调函数运行于SLE service线程,不能阻塞或长时间等待。 460 * @attention 2. 指针由SLE service申请内存,也由SLE service释放,回调中不应释放。 461 * @param [in] conn_id 连接 ID。 462 * @param [in] addr 地址。 463 * @param [in] status 执行结果错误码。 464 * @par 依赖: 465 * @li sle_common.h 466 * @see sle_connection_callbacks_t 467 * @endif 468 */ 469 typedef void (*sle_pair_complete_callback)(uint16_t conn_id, const sle_addr_t *addr, errcode_t status); 470 471 /** 472 * @if Eng 473 * @brief Callback invoked when rssi read complete. 474 * @par Callback invoked when rssi read complete. 475 * @attention 1.This function is called in SLE service context,should not be blocked or do long time waiting. 476 * @attention 2.The memories of pointer are requested and freed by the SLE service automatically. 477 * @param [in] conn_id connection ID. 478 * @param [in] rssi rssi. 479 * @param [in] status error code. 480 * @par Dependency: 481 * @li sle_common.h 482 * @see sle_connection_callbacks_t 483 * @else 484 * @brief 读取rssi的回调函数。 485 * @par 读取rssi的回调函数。 486 * @attention 1. 该回调函数运行于SLE service线程,不能阻塞或长时间等待。 487 * @attention 2. 指针由SLE service申请内存,也由SLE service释放,回调中不应释放。 488 * @param [in] conn_id 连接 ID。 489 * @param [in] rssi rssi。 490 * @param [in] status 执行结果错误码。 491 * @par 依赖: 492 * @li sle_common.h 493 * @see sle_connection_callbacks_t 494 * @endif 495 */ 496 typedef void (*sle_read_rssi_callback)(uint16_t conn_id, int8_t rssi, errcode_t status); 497 498 /** 499 * @if Eng 500 * @brief Callback invoked when set low latency complete. 501 * @par Callback invoked when set low latency complete. 502 * @attention 1.This function is called in SLE service context,should not be blocked or do long time waiting. 503 * @attention 2.The memories of pointer are requested and freed by the SLE service automatically. 504 * @param [in] status result of set low latency. 505 * @param [in] addr remote device address. 506 * @param [in] rate mouse report rate { @ref sle_low_latency_rate_t }. 507 * @par Dependency: 508 * @li sle_common.h 509 * @see sle_connection_callbacks_t 510 * @else 511 * @brief 设置low latency的回调函数。 512 * @par 设置low latency的回调函数。 513 * @attention 1. 该回调函数运行于SLE service线程,不能阻塞或长时间等待。 514 * @attention 2. 指针由SLE service申请内存,也由SLE service释放,回调中不应释放。 515 * @param [in] status 设置low latency结果。 516 * @param [in] addr 对端设备地址。 517 * @param [in] rate 鼠标回报率 { @ref sle_low_latency_rate_t }。 518 * @par 依赖: 519 * @li sle_common.h 520 * @see sle_connection_callbacks_t 521 * @endif 522 */ 523 typedef void (*sle_low_latency_callback)(uint8_t status, sle_addr_t *addr, uint8_t rate); 524 525 /** 526 * @if Eng 527 * @brief Callback invoked when set PHY complete. 528 * @par Callback invoked when set PHY complete. 529 * @attention 1.This function is called in SLE service context,should not be blocked or do long time waiting. 530 * @attention 2.The memories of pointer are requested and freed by the SLE service automatically. 531 * @param [in] conn_id connection ID. 532 * @param [in] status result of setting the PHY. 533 * @param [in] param current PHY parameters { @ref sle_set_phy_t }. 534 * @par Dependency: 535 * @li sle_common.h 536 * @see sle_connection_callbacks_t 537 * @else 538 * @brief 设置PHY的回调函数。 539 * @par 设置PHY的回调函数。 540 * @attention 1. 该回调函数运行于SLE service线程,不能阻塞或长时间等待。 541 * @attention 2. 指针由SLE service申请内存,也由SLE service释放,回调中不应释放。 542 * @param [in] conn_id 连接 ID。 543 * @param [in] status 设置PHY结果。 544 * @param [in] param 当前PHY参数 { @ref sle_set_phy_t }。 545 * @par 依赖: 546 * @li sle_common.h 547 * @see sle_connection_callbacks_t 548 * @endif 549 */ 550 typedef void (*sle_set_phy_callback)(uint16_t conn_id, errcode_t status, const sle_set_phy_t *param); 551 552 /** 553 * @if Eng 554 * @brief Struct of SLE connection manager callback function. 555 * @else 556 * @brief SLE连接管理回调函数接口定义。 557 * @endif 558 */ 559 typedef struct { 560 sle_connect_state_changed_callback connect_state_changed_cb; /*!< @if Eng Connect state changed callback. 561 @else 连接状态改变回调函数。 @endif */ 562 sle_connect_param_update_req_callback connect_param_update_req_cb; /*!< @if Eng Connect param updated callback. 563 @else 连接参数更新回调函数。 @endif */ 564 sle_connect_param_update_callback connect_param_update_cb; /*!< @if Eng Connect param updated callback. 565 @else 连接参数更新回调函数。 @endif */ 566 sle_auth_complete_callback auth_complete_cb; /*!< @if Eng Authentication complete callback. 567 @else 认证完成回调函数。 @endif */ 568 sle_pair_complete_callback pair_complete_cb; /*!< @if Eng Pairing complete callback. 569 @else 配对完成回调函数。 @endif */ 570 sle_read_rssi_callback read_rssi_cb; /*!< @if Eng Read rssi callback. 571 @else 读取rssi回调函数。 @endif */ 572 sle_low_latency_callback low_latency_cb; /*!< @if Eng Set low latency callback. 573 @else 设置low latency回调函数。 @endif */ 574 sle_set_phy_callback set_phy_cb; /*!< @if Eng Set PHY callback. 575 @else 设置PHY回调函数。 @endif */ 576 } sle_connection_callbacks_t; 577 578 /** 579 * @if Eng 580 * @brief Send connect request to remote device. 581 * @par Description: Send connect request to remote device. 582 * @param [in] addr address. 583 * @retval error code, connection state change result will be returned at { @ref sle_connect_state_changed_callback }. 584 * @par Depends: 585 * @li sle_common.h 586 * @else 587 * @brief 发送连接请求。 588 * @par Description: 发送连接请求。 589 * @param [in] addr 地址。 590 * @retval 执行结果错误码, 连接状态改变结果将在 { @ref sle_connect_state_changed_callback }中返回。 591 * @par 依赖: 592 * @li sle_common.h 593 * @endif 594 */ 595 errcode_t sle_connect_remote_device(const sle_addr_t *addr); 596 597 /** 598 * @if Eng 599 * @brief Send disconnect request to remote device. 600 * @par Description: Send disconnect request to remote device. 601 * @param [in] addr address. 602 * @retval error code, connection state change result will be returned at { @ref sle_connect_state_changed_callback }. 603 * @par Depends: 604 * @li sle_common.h 605 * @else 606 * @brief 发送断开连接请求。 607 * @par Description: 发送断开连接请求。 608 * @param [in] addr 地址。 609 * @retval 执行结果错误码, 连接状态改变结果将在 { @ref sle_connect_state_changed_callback }中返回。 610 * @par 依赖: 611 * @li sle_common.h 612 * @endif 613 */ 614 errcode_t sle_disconnect_remote_device(const sle_addr_t *addr); 615 616 /** 617 * @if Eng 618 * @brief Disconnect all connections. 619 * @par Description: Disconnect all connections. 620 * @retval ERRCODE_SUCC Success. 621 * @retval Other Failure. For details, see @ref errcode_t 622 * @par Depends: 623 * @li sle_common.h 624 * @else 625 * @brief 断开所有连接。 626 * @par Description: 断开所有连接。 627 * @retval ERRCODE_SUCC 成功。 628 * @retval Other 失败。参考 @ref errcode_t 629 * @par 依赖: 630 * @li sle_common.h 631 * @endif 632 */ 633 errcode_t sle_disconnect_all_remote_device(void); 634 635 /** 636 * @if Eng 637 * @brief Send connection parameter update request to remote device. 638 * @par Description: Send connection parameter update request to remote device. 639 * @param [in] params connection parameter. 640 * @retval ERRCODE_SUCC Success. 641 * @retval Other Failure. For details, see @ref errcode_t 642 * @par Depends: 643 * @li sle_common.h 644 * @else 645 * @brief 发送更新连接参数请求。 646 * @par Description: 发送更新连接参数请求。 647 * @param [in] params 连接参数。 648 * @retval ERRCODE_SUCC 成功。 649 * @retval Other 失败。参考 @ref errcode_t 650 * @par 依赖: 651 * @li sle_common.h 652 * @endif 653 */ 654 errcode_t sle_update_connect_param(sle_connection_param_update_t *params); 655 656 /** 657 * @if Eng 658 * @brief Send pairing request to remote device. 659 * @par Description: Send pairing request to remote device. 660 * @param [in] addr address. 661 * @retval ERRCODE_SUCC Success. 662 * @retval Other Failure. For details, see @ref errcode_t 663 * @par Depends: 664 * @li sle_common.h 665 * @else 666 * @brief 发送配对请求。 667 * @par Description: 发送配对请求。 668 * @param [in] addr 地址。 669 * @retval ERRCODE_SUCC 成功。 670 * @retval Other 失败。参考 @ref errcode_t 671 * @par 依赖: 672 * @li sle_common.h 673 * @endif 674 */ 675 errcode_t sle_pair_remote_device(const sle_addr_t *addr); 676 677 /** 678 * @if Eng 679 * @brief Remove pairing. 680 * @par Description: Remove pairing. 681 * @param [in] addr address. 682 * @retval ERRCODE_SUCC Success. 683 * @retval Other Failure. For details, see @ref errcode_t 684 * @par Depends: 685 * @li sle_common.h 686 * @else 687 * @brief 删除配对。 688 * @par Description: 删除配对。 689 * @param [in] addr 地址。 690 * @retval ERRCODE_SUCC 成功。 691 * @retval Other 失败。参考 @ref errcode_t 692 * @par 依赖: 693 * @li sle_common.h 694 * @endif 695 */ 696 errcode_t sle_remove_paired_remote_device(const sle_addr_t *addr); 697 698 /** 699 * @if Eng 700 * @brief Remove all pairing. 701 * @par Description: Remove all pairing. 702 * @retval ERRCODE_SUCC Success. 703 * @retval Other Failure. For details, see @ref errcode_t 704 * @par Depends: 705 * @li sle_common.h 706 * @else 707 * @brief 删除所有配对。 708 * @par Description: 删除所有配对。 709 * @retval ERRCODE_SUCC 成功。 710 * @retval Other 失败。参考 @ref errcode_t 711 * @par 依赖: 712 * @li sle_common.h 713 * @endif 714 */ 715 errcode_t sle_remove_all_pairs(void); 716 717 /** 718 * @if Eng 719 * @brief Get paired device number. 720 * @par Description: Get paired device number. 721 * @param [out] number device number. 722 * @retval ERRCODE_SUCC Success. 723 * @retval Other Failure. For details, see @ref errcode_t 724 * @par Depends: 725 * @li sle_common.h 726 * @else 727 * @brief 获取配对设备数量。 728 * @par Description: 获取配对设备数量。 729 * @param [out] number 设备数量。 730 * @retval ERRCODE_SUCC 成功。 731 * @retval Other 失败。参考 @ref errcode_t 732 * @par 依赖: 733 * @li sle_common.h 734 * @endif 735 */ 736 errcode_t sle_get_paired_devices_num(uint16_t *number); 737 738 /** 739 * @if Eng 740 * @brief Get paired device. 741 * @par Description: Get paired device. 742 * @param [out] addr linked list of device address. 743 * @param [inout] number device number. 744 * @retval ERRCODE_SUCC Success. 745 * @retval Other Failure. For details, see @ref errcode_t 746 * @par Depends: 747 * @li sle_common.h 748 * @else 749 * @brief 获取配对设备。 750 * @par Description: 获取配对设备。 751 * @param [out] addr 设备地址链表。 752 * @param [inout] number 设备数量。 753 * @retval ERRCODE_SUCC 成功。 754 * @retval Other 失败。参考 @ref errcode_t 755 * @par 依赖: 756 * @li sle_common.h 757 * @endif 758 */ 759 errcode_t sle_get_paired_devices(sle_addr_t *addr, uint16_t *number); 760 761 /** 762 * @if Eng 763 * @brief Get bonded device. 764 * @par Description: Get bonded device. 765 * @param [out] addr linked list of device address. 766 * @param [inout] number device number. 767 * @retval error code. 768 * @par Depends: 769 * @li sle_common.h 770 * @else 771 * @brief 获取绑定设备。 772 * @par Description: 获取绑定设备。 773 * @param [out] addr 设备地址链表。 774 * @param [inout] number 设备数量。 775 * @retval 执行结果错误码。 776 * @par 依赖: 777 * @li sle_common.h 778 * @endif 779 */ 780 errcode_t sle_get_bonded_devices(sle_addr_t *addr, uint16_t *number); 781 782 /** 783 * @if Eng 784 * @brief Get pair state. 785 * @par Description: Get pair state. 786 * @param [in] addr device address. 787 * @param [out] state pair state { @ref sle_pair_state_t }. 788 * @retval ERRCODE_SUCC Success. 789 * @retval Other Failure. For details, see @ref errcode_t 790 * @par Depends: 791 * @li sle_common.h 792 * @else 793 * @brief 获取配对状态。 794 * @par Description: 获取配对状态。 795 * @param [in] addr 设备地址。 796 * @param [out] state 配对状态 { @ref sle_pair_state_t }。 797 * @retval ERRCODE_SUCC 成功。 798 * @retval Other 失败。参考 @ref errcode_t 799 * @par 依赖: 800 * @li sle_common.h 801 * @endif 802 */ 803 errcode_t sle_get_pair_state(const sle_addr_t *addr, uint8_t *state); 804 805 /** 806 * @if Eng 807 * @brief Read remote device rssi value. 808 * @par Description: Read remote device rssi value. 809 * @param [in] conn_id connection ID. 810 * @retval ERRCODE_SUCC Success. 811 * @retval Other Failure. For details, see @ref errcode_t 812 * @par Depends: 813 * @li sle_common.h 814 * @else 815 * @brief 读取对端设备rssi值。 816 * @par Description: 读取对端设备rssi值。 817 * @param [in] conn_id 连接 ID。 818 * @retval ERRCODE_SUCC 成功。 819 * @retval Other 失败。参考 @ref errcode_t 820 * @par 依赖: 821 * @li sle_common.h 822 * @endif 823 */ 824 errcode_t sle_read_remote_device_rssi(uint16_t conn_id); 825 826 /** 827 * @if Eng 828 * @brief Set sle phy. 829 * @par Description: Set sle phy. 830 * @param [in] conn_id connection ID. 831 * @param [in] param sle phy param. 832 * @retval ERRCODE_SUCC Success. 833 * @retval Other Failure. For details, see @ref errcode_t 834 * @par Depends: 835 * @li sle_common.h 836 * @else 837 * @brief 设置PHY参数 838 * @par Description: 设置PHY参数。 839 * @param [in] conn_id 连接 ID。 840 * @param [in] param 星闪的PHY参数。 841 * @retval ERRCODE_SUCC 成功。 842 * @retval Other 失败。参考 @ref errcode_t 843 * @par 依赖: 844 * @li sle_common.h 845 * @endif 846 */ 847 errcode_t sle_set_phy_param(uint16_t conn_id, sle_set_phy_t *param); 848 849 /** 850 * @if Eng 851 * @brief Set Modulation and Coding Scheme. 852 * @par Description: Set Modulation and Coding Scheme. 853 * @param [in] conn_id connection ID. 854 * @param [in] mcs Modulation and Coding Scheme. 855 * @retval ERRCODE_SUCC Success. 856 * @retval Other Failure. For details, see @ref errcode_t 857 * @par Depends: 858 * @li sle_common.h 859 * @else 860 * @brief 设置调制与编码策略。 861 * @par Description: 设置调制与编码策略。 862 * @param [in] conn_id 连接 ID。 863 * @param [in] mcs 调制与编码策略索引值。 864 * @retval ERRCODE_SUCC 成功。 865 * @retval Other 失败。参考 @ref errcode_t 866 * @par 依赖: 867 * @li sle_common.h 868 * @endif 869 */ 870 errcode_t sle_set_mcs(uint16_t conn_id, uint8_t mcs); 871 872 /** 873 * @if Eng 874 * @brief Set Maximum number of preferred transmit payload bytes on the connected link. 875 * @par Description: Maximum number of preferred transmit payload bytes on the connected link. 876 * @param [in] conn_id connection ID. 877 * @param [in] tx_octets 连接链路上所偏好的最大传输payload字节数. 878 * @retval ERRCODE_SUCC Success. 879 * @retval Other Failure. For details, see @ref errcode_t 880 * @par Depends: 881 * @li sle_common.h 882 * @else 883 * @brief 设置连接链路上所偏好的最大传输payload字节数 884 * @par Description: 设置连接链路上所偏好的最大传输payload字节数。 885 * @param [in] conn_id 连接 ID。 886 * @param [in] tx_octets 连接链路上所偏好的最大传输payload字节数. 887 * @retval ERRCODE_SUCC 成功。 888 * @retval Other 失败。参考 @ref errcode_t 889 * @par 依赖: 890 * @li sle_common.h 891 * @endif 892 */ 893 errcode_t sle_set_data_len(uint16_t conn_id, uint16_t tx_octets); 894 895 /** 896 * @if Eng 897 * @brief use this function to set sle default connect param. 898 * @par Description: use this function to set sle default connect param. 899 * @param [in] set_param sle default connect param. 900 * @retval ERRCODE_SUCC Success. 901 * @retval Other Failure. For details, see @ref errcode_t 902 * @par Depends: 903 * @li sle_common.h 904 * @else 905 * @brief 设置 sle 默认连接参数 906 * @par Description: 设置 sle 默认连接参数。 907 * @param [in] set_param 星闪的默认连接参数。 908 * @retval ERRCODE_SUCC 成功。 909 * @retval Other 失败。参考 @ref errcode_t 910 * @par 依赖: 911 * @li sle_common.h 912 * @endif 913 */ 914 errcode_t sle_default_connection_param_set(sle_default_connect_param_t *set_param); 915 916 /** 917 * @if Eng 918 * @brief Register SLE connection manager callbacks. 919 * @par Description: Register SLE connection manager callbacks. 920 * @param [in] func Callback function. 921 * @retval ERRCODE_SUCC Success. 922 * @retval Other Failure. For details, see @ref errcode_t 923 * @else 924 * @brief 注册SLE连接管理回调函数。 925 * @par Description: 注册SLE连接管理回调函数。 926 * @param [in] func 回调函数。 927 * @retval ERRCODE_SUCC 成功。 928 * @retval Other 失败。参考 @ref errcode_t 929 * @endif 930 */ 931 errcode_t sle_connection_register_callbacks(sle_connection_callbacks_t *func); 932 933 /** 934 * @if Eng 935 * @brief Use this funtion to config customize information. 936 * @par Use this funtion to config customize information. 937 * @param [in] ble_pwr ble max power. 938 * @param [in] sle_pwr sle max power. 939 * @retval ERRCODE_SUCC Success. 940 * @retval Other Failure. For details, see @ref errcode_t 941 * @par Dependency: 942 * @li nv_common.h 943 * @else 944 * @brief 配置定制化信息 945 * @par 配置定制化信息 946 * @param [in] ble_pwr ble 最大功率 947 * @param [in] sle_pwr sle 最大功率. 948 * @retval ERRCODE_SUCC 成功。 949 * @retval Other 失败。参考 @ref errcode_t 950 * @par 依赖: 951 * @li bt_data_config.h 952 * @endif 953 */ 954 errcode_t sle_customize_max_pwr(int8_t ble_pwr, int8_t sle_pwr); 955 956 #ifdef __cplusplus 957 } 958 #endif 959 #endif /* SLE_CONNECTION_MANAGER */ 960 /** 961 * @} 962 */ 963