• 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_BLE_GATT_SERVER_H
17 #define SOFTBUS_ADAPTER_BLE_GATT_SERVER_H
18 
19 #include "stdbool.h"
20 #include "stdint.h"
21 #include "softbus_adapter_bt_common.h"
22 
23 #ifdef __cplusplus
24 #if __cplusplus
25 extern "C" {
26 #endif
27 #endif
28 
29 typedef enum {
30     SOFTBUS_GATT_SUCCESS = 0x00,
31     SOFTBUS_GATT_INVALID_HANDLE = 0x01,
32     SOFTBUS_GATT_READ_NOT_PERMITTED = 0x02,
33     SOFTBUS_GATT_WRITE_NOT_PERMITTED = 0x03,
34     SOFTBUS_GATT_INVALID_PDU = 0x04,
35     SOFTBUS_GATT_INSUFFICIENT_AUTHENTICATION = 0x05,
36     SOFTBUS_GATT_REQUEST_NOT_SUPPORTED = 0x06,
37     SOFTBUS_GATT_INVALID_OFFSET = 0x07,
38     SOFTBUS_GATT_INSUFFICIENT_AUTHORIZATION = 0x08,
39     SOFTBUS_GATT_PREPARE_QUEUE_FULL = 0x09,
40     SOFTBUS_GATT_ATTRIBUTE_NOT_FOUND = 0x0A,
41     SOFTBUS_GATT_ATTRIBUTE_NOT_LONG = 0x0B,
42     SOFTBUS_GATT_INSUFFICIENT_ENCRYPTION_KEY_SIZE = 0x0C,
43     SOFTBUS_GATT_INVALID_ATTRIBUTE_VALUE_LENGTH = 0x0D,
44     SOFTBUS_GATT_UNLIKELY_ERROR = 0x0E,
45     SOFTBUS_GATT_INSUFFICIENT_ENCRYPTION = 0x0F,
46     SOFTBUS_GATT_UNSUPPORTED_GROUP_TYPE = 0x10,
47     SOFTBUS_GATT_INSUFFICIENT_RESOURCES = 0x11,
48     SOFTBUS_GATT_DATABASE_OUT_OF_SYNC = 0x12,
49     SOFTBUS_GATT_VALUE_NOT_ALLOWED = 0x13,
50 } SoftBusGattStatus;
51 
52 typedef enum {
53     SOFTBUS_GATT_CHARACTER_PROPERTY_BIT_BROADCAST = 0x01,
54     SOFTBUS_GATT_CHARACTER_PROPERTY_BIT_READ = 0x02,
55     SOFTBUS_GATT_CHARACTER_PROPERTY_BIT_WRITE_NO_RSP = 0x04,
56     SOFTBUS_GATT_CHARACTER_PROPERTY_BIT_WRITE = 0x08,
57     SOFTBUS_GATT_CHARACTER_PROPERTY_BIT_NOTIFY = 0x10,
58     SOFTBUS_GATT_CHARACTER_PROPERTY_BIT_INDICATE = 0x20,
59     SOFTBUS_GATT_CHARACTER_PROPERTY_BIT_SIGNED_WRITE = 0x40,
60     SOFTBUS_GATT_CHARACTER_PROPERTY_BIT_EXTENDED_PROPERTY = 0x80
61 } SoftBusGattCharaProperty;
62 
63 typedef enum {
64     SOFTBUS_GATT_PERMISSION_READ = 0x01,
65     SOFTBUS_GATT_PERMISSION_READ_ENCRYPTED = 0x02,
66     SOFTBUS_GATT_PERMISSION_READ_ENCRYPTED_MITM = 0x04,
67     SOFTBUS_GATT_PERMISSION_WRITE = 0x10,
68     SOFTBUS_GATT_PERMISSION_WRITE_ENCRYPTED = 0x20,
69     SOFTBUS_GATT_PERMISSION_WRITE_ENCRYPTED_MITM = 0x40,
70     SOFTBUS_GATT_PERMISSION_WRITE_SIGNED = 0x80,
71     SOFTBUS_GATT_PERMISSION_WRITE_SIGNED_MITM = 0x100
72 } SoftBusGattAttrPermission;
73 
74 typedef struct {
75     int connId;
76     int transId;
77     SoftBusBtAddr *btAddr;
78     int attrHandle;
79     int offset;
80     bool isLong;
81 } SoftBusGattReadRequest;
82 
83 typedef struct {
84     int connId;
85     int transId;
86     SoftBusBtAddr *btAddr;
87     int attrHandle;
88     int offset;
89     int length;
90     bool needRsp;
91     bool isPrep;
92     unsigned char *value;
93 } SoftBusGattWriteRequest;
94 
95 
96 typedef struct {
97     void (*ServiceAddCallback)(int status, SoftBusBtUuid *uuid, int srvcHandle);
98     void (*CharacteristicAddCallback)(int status, SoftBusBtUuid *uuid, int srvcHandle, int characteristicHandle);
99     void (*DescriptorAddCallback)(int status, SoftBusBtUuid *uuid, int srvcHandle, int descriptorHandle);
100     void (*ServiceStartCallback)(int status, int srvcHandle);
101     void (*ServiceStopCallback)(int status, int srvcHandle);
102     void (*ServiceDeleteCallback)(int status, int srvcHandle);
103     void (*ConnectServerCallback)(int connId, const SoftBusBtAddr *btAddr);
104     void (*DisconnectServerCallback)(int connId, const SoftBusBtAddr *btAddr);
105     void (*RequestReadCallback)(SoftBusGattReadRequest readCbPara);
106     void (*RequestWriteCallback)(SoftBusGattWriteRequest writeCbPara);
107     void (*ResponseConfirmationCallback)(int status, int handle);
108     void (*NotifySentCallback)(int connId, int status);
109     void (*MtuChangeCallback)(int connId, int mtu);
110 } SoftBusGattsCallback;
111 
112 typedef struct {
113     int connectId;
114     int transId;
115     int status;
116     int attrHandle;
117     int offset;
118     int valueLen;
119     char *value;
120 } SoftBusGattsResponse;
121 
122 typedef struct {
123     int connectId;
124     int attrHandle;
125     int confirm;
126     int valueLen;
127     char *value;
128 } SoftBusGattsNotify;
129 
130 int SoftBusRegisterGattsCallbacks(SoftBusGattsCallback *callback);
131 void SoftBusUnRegisterGattsCallbacks(void);
132 int SoftBusGattsAddService(SoftBusBtUuid srvcUuid, bool isPrimary, int number);
133 int SoftBusGattsAddCharacteristic(int srvcHandle, SoftBusBtUuid characUuid, int properties, int permissions);
134 int SoftBusGattsAddDescriptor(int srvcHandle, SoftBusBtUuid descUuid, int permissions);
135 int SoftBusGattsStartService(int srvcHandle);
136 int SoftBusGattsStopService(int srvcHandle);
137 int SoftBusGattsDeleteService(int srvcHandle);
138 int SoftBusGattsConnect(int connId);
139 int SoftBusGattsDisconnect(SoftBusBtAddr btAddr, int connId);
140 int SoftBusGattsSendResponse(SoftBusGattsResponse *param);
141 int SoftBusGattsSendNotify(SoftBusGattsNotify *param);
142 
143 #ifdef __cplusplus
144 #if __cplusplus
145 }
146 #endif /* __cplusplus */
147 #endif /* __cplusplus */
148 #endif
149