• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
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 
16 #ifndef SOFTBUS_ADAPTER_BT_COMMON_H
17 #define SOFTBUS_ADAPTER_BT_COMMON_H
18 
19 #include <stdbool.h>
20 #include <stdint.h>
21 
22 #include "softbus_type_def.h"
23 
24 #ifdef __cplusplus
25 #if __cplusplus
26 extern "C" {
27 #endif
28 #endif
29 
30 #define BT_ADDR_LEN 6
31 #define BT_UUID_LEN 16
32 
33 #define BLE_DISABLE 0
34 #define BLE_ENABLE 1
35 
36 #define MAC_FIRST_INDEX 0
37 #define MAC_ONE_INDEX 1
38 #define MAC_FIVE_INDEX 5
39 
40 typedef enum {
41     SOFTBUS_BT_STATUS_SUCCESS = 0x00,
42     SOFTBUS_BT_STATUS_FAIL,
43     SOFTBUS_BT_STATUS_NOT_READY,
44     SOFTBUS_BT_STATUS_NOMEM,
45     SOFTBUS_BT_STATUS_BUSY,
46     SOFTBUS_BT_STATUS_DONE,
47     SOFTBUS_BT_STATUS_UNSUPPORTED,
48     SOFTBUS_BT_STATUS_PARM_INVALID,
49     SOFTBUS_BT_STATUS_UNHANDLED,
50     SOFTBUS_BT_STATUS_AUTH_FAILURE,
51     SOFTBUS_BT_STATUS_RMT_DEV_DOWN,
52     SOFTBUS_BT_STATUS_AUTH_REJECTED
53 } SoftBusBtStatus;
54 
55 typedef enum {
56     SOFTBUS_BT_STATE_TURNING_ON = 0x0,
57     SOFTBUS_BT_STATE_TURN_ON,
58     SOFTBUS_BT_STATE_TURNING_OFF,
59     SOFTBUS_BT_STATE_TURN_OFF,
60     SOFTBUS_BR_STATE_TURNING_ON,
61     SOFTBUS_BR_STATE_TURN_ON,
62     SOFTBUS_BR_STATE_TURNING_OFF,
63     SOFTBUS_BR_STATE_TURN_OFF
64 } SoftBusBtStackState;
65 
66 typedef enum {
67     SOFTBUS_ACL_STATE_CONNECTED = 0x0,
68     SOFTBUS_ACL_STATE_DISCONNECTED,
69     SOFTBUS_ACL_STATE_LE_CONNECTED,
70     SOFTBUS_ACL_STATE_LE_DISCONNECTED,
71 } SoftBusAclState;
72 
73 typedef struct {
74     unsigned char addr[BT_ADDR_LEN];
75 } SoftBusBtAddr;
76 
77 typedef struct {
78     unsigned char uuidLen;
79     char *uuid;
80 } SoftBusBtUuid;
81 
82 typedef enum {
83     SOFTBUS_BT_CONNECT = 0x01,
84     SOFTBUS_BT_DISCONNECT = 0x03
85 } SoftBusBtConnectState;
86 
87 typedef struct {
88     unsigned short advLength;
89     char *advData;
90     unsigned short scanRspLength;
91     char *scanRspData;
92 } SoftBusBleAdvData;
93 
94 typedef struct {
95     void (*OnBtStateChanged)(int listenerId, int state);
96     void (*OnBtAclStateChanged)(int32_t listenerId, const SoftBusBtAddr *addr, int32_t aclState, int32_t hciReason);
97 } SoftBusBtStateListener;
98 
99 int SoftBusEnableBt(void);
100 
101 int SoftBusDisableBt(void);
102 
103 int SoftBusGetBtState(void);
104 
105 int SoftBusGetBtMacAddr(SoftBusBtAddr *mac);
106 
107 int SoftBusGetBtName(unsigned char *name, unsigned int *len);
108 
109 int SoftBusSetBtName(const char *name);
110 
111 int SoftBusAddBtStateListener(const SoftBusBtStateListener *listener);
112 
113 int SoftBusRemoveBtStateListener(int listenerId);
114 
115 #ifdef __cplusplus
116 #if __cplusplus
117 }
118 #endif /* __cplusplus */
119 #endif /* __cplusplus */
120 #endif