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 WRAPPER_BR_INTERFACE_H
17 #define WRAPPER_BR_INTERFACE_H
18 
19 #include <stdbool.h>
20 #include <stdint.h>
21 
22 #include "softbus_adapter_bt_common.h"
23 #include "softbus_def.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 #define BR_NAME_LEN 16
30 #define BT_ADDR_LEN 6
31 #define BT_UUID_LEN 16
32 
33 typedef uint8_t BT_UUIDL[BT_UUID_LEN];
34 typedef uint8_t BT_ADDR[BT_ADDR_LEN];
35 
36 #define BR_READ_SOCKET_CLOSED 0
37 #define BR_READ_FAILED (-1)
38 
39 typedef struct {
40     BT_UUIDL uuid;
41     BT_ADDR mac;
42     char name[BR_NAME_LEN];
43 } BluetoothRemoteDevice;
44 
45 typedef struct tagSppSocketDriver {
46     void (*Init)(const struct tagSppSocketDriver* this_p);
47     int32_t (*OpenSppServer)(const char *name, int32_t nameLen, const char *uuid, int32_t isSecure);
48     int32_t (*GetSppServerPort)(int serverId);
49     void (*CloseSppServer)(int32_t serverFd);
50     int32_t (*ConnectByPort)(const char *uuid, const BT_ADDR mac,const int32_t socketPsmValue, void *connectCallback);
51     int32_t (*Connect)(const char *uuid, const BT_ADDR mac, void *connectCallback);
52     int32_t (*DisConnect)(int32_t clientFd);
53     bool (*IsConnected)(int32_t clientFd);
54     int32_t (*Accept)(int32_t serverFd);
55     int32_t (*Write)(int32_t clientFd, const uint8_t *buf, const int32_t length);
56     int32_t (*Read)(int32_t clientFd, uint8_t *buf, const int32_t length);
57     int32_t (*GetRemoteDeviceInfo)(int32_t clientFd, const BluetoothRemoteDevice* device);
58 } SppSocketDriver;
59 
60 typedef struct {
61     ListNode node;
62     int32_t result;
63     int32_t status;
64 } BrUnderlayerStatus;
65 
66 typedef enum {
67     CONN_BR_CONNECT_UNDERLAYER_CONNECTION_OK = 0x00,
68     CONN_BR_CONNECT_UNDERLAYER_ERROR_ILLEGAL_COMMAND = 0x01,
69     CONN_BR_CONNECT_UNDERLAYER_ERROR_NO_CONNECTION = 0x02,
70     CONN_BR_CONNECT_UNDERLAYER_ERROR_HW_FAILURE = 0x03,
71     CONN_BR_CONNECT_UNDERLAYER_ERROR_PAGE_TIMEOUT = 0x04,
72     CONN_BR_CONNECT_UNDERLAYER_ERROR_AUTH_FAILURE = 0x05,
73     CONN_BR_CONNECT_UNDERLAYER_ERROR_KEY_MISSING = 0x06,
74     CONN_BR_CONNECT_UNDERLAYER_ERROR_MEMORY_FULL = 0x07,
75     CONN_BR_CONNECT_UNDERLAYER_ERROR_CONNECTION_TOUT = 0x08,
76     CONN_BR_CONNECT_UNDERLAYER_ERROR_MAX_NUM_OF_CONNECTIONS = 0x09,
77     CONN_BR_CONNECT_UNDERLAYER_ERROR_MAX_NUM_OF_SCOS = 0x0A,
78     CONN_BR_CONNECT_UNDERLAYER_ERROR_CONNECTION_EXISTS = 0x0B,
79     CONN_BR_CONNECT_UNDERLAYER_ERROR_COMMAND_DISALLOWED = 0x0C,
80     CONN_BR_CONNECT_UNDERLAYER_ERROR_HOST_REJECT_RESOURCES = 0x0D,
81     CONN_BR_CONNECT_UNDERLAYER_ERROR_HOST_REJECT_SECURITY = 0x0E,
82     CONN_BR_CONNECT_UNDERLAYER_ERROR_HOST_REJECT_DEVICE = 0x0F,
83     CONN_BR_CONNECT_UNDERLAYER_ERROR_HOST_TIMEOUT = 0x10,
84     CONN_BR_CONNECT_UNDERLAYER_ERROR_ILLEGAL_PARAMETER_FMT = 0x12,
85     CONN_BR_CONNECT_UNDERLAYER_ERROR_PEER_USER = 0x13,
86     CONN_BR_CONNECT_UNDERLAYER_ERROR_PEER_LOW_RESOURCES = 0x14,
87     CONN_BR_CONNECT_UNDERLAYER_ERROR_CONN_CAUSE_LOCAL_HOST = 0x16,
88     CONN_BR_CONNECT_UNDERLAYER_ERROR_REPEATED_ATTEMPTS = 0x17,
89     CONN_BR_CONNECT_UNDERLAYER_ERROR_PAIRING_NOT_ALLOWED = 0x18,
90     CONN_BR_CONNECT_UNDERLAYER_ERROR_UNSUPPORTED_REM_FEATURE = 0x1A,
91     CONN_BR_CONNECT_UNDERLAYER_ERROR_UNSPECIFIED = 0x1F,
92     CONN_BR_CONNECT_UNDERLAYER_ERROR_LMP_RESPONSE_TIMEOUT = 0x22,
93     CONN_BR_CONNECT_UNDERLAYER_ERROR_LMP_ERR_TRANS_COLLISION = 0x23,
94     CONN_BR_CONNECT_UNDERLAYER_ERROR_ENCRY_MODE_NOT_ACCEPTABLE = 0x25,
95     CONN_BR_CONNECT_UNDERLAYER_ERROR_UNIT_KEY_USED = 0x26,
96     CONN_BR_CONNECT_UNDERLAYER_ERROR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED = 0x29,
97     CONN_BR_CONNECT_UNDERLAYER_ERROR_DIFF_TRANSACTION_COLLISION = 0x2A,
98     CONN_BR_CONNECT_UNDERLAYER_ERROR_INSUFFCIENT_SECURITY = 0x2F,
99     CONN_BR_CONNECT_UNDERLAYER_ERROR_ROLE_SWITCH_PENDING = 0x32,
100     CONN_BR_CONNECT_UNDERLAYER_ERROR_ROLE_SWITCH_FAILED = 0x35,
101     CONN_BR_CONNECT_UNDERLAYER_ERROR_HOST_BUSY_PAIRING = 0x38,
102     CONN_BR_CONNECT_UNDERLAYER_ERROR_CONTROLLER_BUSY = 0x3A,
103     CONN_BR_CONNECT_UNDERLAYER_ERROR_UNACCEPT_CONN_INTERVAL = 0x3B,
104     CONN_BR_CONNECT_UNDERLAYER_ERROR_ADVERTISING_TIMEOUT = 0x3C,
105     CONN_BR_CONNECT_UNDERLAYER_ERROR_CONN_FAILED_ESTABLISHMENT = 0x3E,
106     CONN_BR_CONNECT_UNDERLAYER_ERROR_LIMIT_REACHED = 0x43,
107     CONN_BR_CONNECT_UNDERLAYER_ERROR_CONN_START_PEND = 0x50,
108     CONN_BR_CONNECT_UNDERLAYER_ERROR_CONN_END_PEND = 0x51,
109     CONN_BR_CONNECT_UNDERLAYER_ERROR_CONN_SDP_BUSY = 0x52,
110     CONN_BR_CONNECT_UNDERLAYER_ERROR_CONN_L2CAP_TIMEOUT = 0x53,
111     CONN_BR_CONNECT_UNDERLAYER_ERROR_CONN_PEER_NOT_SUPPORT_SDP_RECORD = 0x54,
112     CONN_BR_CONNECT_UNDERLAYER_ERROR_CONN_RFCOMM_NO_PORT = 0x55,
113     CONN_BR_CONNECT_UNDERLAYER_ERROR_CONN_AUTH_FAILED = 0x56,
114     CONN_BR_CONNECT_UNDERLAYER_ERROR_CONN_RFCOM_DM = 0x58,
115     CONN_BR_CONNECT_UNDERLAYER_ERROR_UNDEFINED = 0xff,
116 } ConnBrConnectUnderlayerResult;
117 
118 typedef enum {
119     CONN_BR_CONNECT_UNDERLAYER_UNKNOWN = 0,
120     CONN_BR_CONNECT_UNDERLAYER_START,
121     CONN_BR_CONNECT_UNDERLAYER_ACL_PAGING,
122     CONN_BR_CONNECT_UNDERLAYER_ACL_PAGED,
123     CONN_BR_CONNECT_UNDERLAYER_AUTH,
124     CONN_BR_CONNECT_UNDERLAYER_ENCRYPT,
125     CONN_BR_CONNECT_UNDERLAYER_L2CAP_SDP,
126     CONN_BR_CONNECT_UNDERLAYER_SDP_SEARCH,
127     CONN_BR_CONNECT_UNDERLAYER_L2CAP_RFCOMM,
128     CONN_BR_CONNECT_UNDERLAYER_RFCOMM,
129     CONN_BR_CONNECT_UNDERLAYER_COMPLETED,
130 } ConnBrConnectUnderlayerStatusType;
131 
132 SppSocketDriver *InitSppSocketDriver();
133 bool IsAclConnected(const BT_ADDR mac);
134 #ifdef __cplusplus
135 }
136 #endif
137 #endif /* WRAPPER_BR_INTERFACE_H */