• 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 GATT_PROFLIE_DEFINES_H
17 #define GATT_PROFLIE_DEFINES_H
18 
19 #include "bt_uuid.h"
20 #include "gatt_defines.h"
21 #include "packet.h"
22 
23 namespace bluetooth {
24 enum ResponesType {
25     NONE,
26     DISCOVER_ALL_PRIMARY_SERVICE,
27     DISCOVER_SERVICE_BY_UUID,
28     FIND_INCLUDE_SERVICE,
29     DISCOVER_ALL_CHARACTERISTIC,
30     DISCOVER_CHARACTERISTIC_BY_UUID,
31     DISCOVER_ALL_CHARACTERISTIC_DESCRIPTOR,
32     READ_CHARACTERISTIC_VALUE,
33     READ_LONG_CHARACTERISTIC_VALUE,
34     READ_USING_CHARACTERISTIC_UUID,
35     READ_MULTIPLE_CHARACTERISTIC,
36     READ_CHARACTERISTIC_DESCRIPTOR,
37     READ_LONG_CHARACTERISTIC_DESCRIPTOR,
38     WRITE_WITHOUT_RESPONSE,
39     SIGNED_WRITE_WITHOUT_RESPONSE,
40     WRITE_CHARACTERISTIC_VALUE,
41     WRITE_CHARACTERISTIC_DESCRIPTOR,
42     WRITE_LONG_CHARACTERISTIC_VALUE,
43     RELIABLE_WRITE_VALUE,
44     EXECUTE_WRITE_VALUE,
45     EXCHANGE_MTU,
46     SEND_INDICATION
47 };
48 
49 enum ReadByTypeResponseLen {
50     READ_USING_CHARACTERISTIC_BY_UUID_LENGTH = 0x04,
51     DISCOVER_CHARACTERISTIC_LENGTH_16BIT = 0x07,
52     DISCOVER_CHARACTERISTIC_LENGTH_128BIT = 0x15,
53     FIND_INCLUDE_SERVICE_LENGTH_16BIT = 0x08,
54     FIND_INCLUDE_SERVICE_LENGTH_128BIT = 0x06,
55 };
56 
57 enum UuidLength {
58     UUID_16BIT_LEN = 0x02,
59     UUID_32BIT_LEN = 0x04,
60     UUID_128BIT_LEN = 0x10,
61 };
62 
63 enum UuidFormat {
64     UUID_16BIT_FORMAT = 0x01,
65     UUID_128BIT_FORMAT = 0x02,
66 };
67 
68 enum RetVal {
69     RET_NORMAL,
70     RET_BREAK,
71     RET_RETURN,
72     RET_CONTINUE,
73 };
74 
75 struct MtuInfo {
76     bool isExchanged_ = false;
77     uint16_t mtu_ = GATT_DEFAULT_MTU;
78 
MtuInfoMtuInfo79     MtuInfo(bool isExchanged, uint16_t mtu) : isExchanged_(isExchanged), mtu_(mtu)
80     {}
81 };
82 
83 struct CccdInfo {
84     uint16_t valHandle_ = 0;
85     uint16_t value_ = 0;
86 };
87 
88 struct DeviceInfo {
89     GattDevice device_;
90     CccdInfo cccd_[GATT_CCCD_NUM_MAX] = {};
91 
DeviceInfoDeviceInfo92     explicit DeviceInfo(GattDevice dev) : device_(dev)
93     {}
94 };
95 
96 struct GattResponesInfor {
97     ResponesType respType_ = NONE;
98     uint16_t value_ = 0;
99     GattValue data_ = nullptr;
100 
GattResponesInforGattResponesInfor101     GattResponesInfor(ResponesType respType, uint16_t value) : respType_(respType), value_(value)
102     {}
GattResponesInforGattResponesInfor103     GattResponesInfor(ResponesType respType, uint16_t value, GattValue data)
104         : respType_(respType), value_(value), data_(data)
105     {}
106 };
107 struct GattRequestInfo {
108     uint16_t startHandle_ = 0;
109     uint16_t endHandle_ = 0;
110     uint16_t valHandle_ = 0;
111     GattValue data_ = nullptr;
112     ResponesType reqType_ = NONE;
113     Uuid uuid_ = {};
114     int reqId_ = 0;
115 
GattRequestInfoGattRequestInfo116     GattRequestInfo(ResponesType reqType, uint16_t starthandle, uint16_t endHandle, const Uuid &uuid, int reqId)
117         : startHandle_(starthandle), endHandle_(endHandle), reqType_(reqType), uuid_(uuid), reqId_(reqId)
118     {}
GattRequestInfoGattRequestInfo119     GattRequestInfo(
120         ResponesType reqType, uint16_t starthandle, uint16_t endHandle, uint16_t valHandle, const Uuid &uuid, int reqId)
121         : startHandle_(starthandle),
122           endHandle_(endHandle),
123           valHandle_(valHandle),
124           reqType_(reqType),
125           uuid_(uuid),
126           reqId_(reqId)
127     {}
GattRequestInfoGattRequestInfo128     GattRequestInfo(ResponesType reqType, uint16_t starthandle, uint16_t endHandle, int reqId)
129         : startHandle_(starthandle), endHandle_(endHandle), reqType_(reqType), reqId_(reqId)
130     {}
GattRequestInfoGattRequestInfo131     GattRequestInfo(ResponesType reqType, uint16_t starthandle, uint16_t endHandle, uint16_t valHandle, int reqId)
132         : startHandle_(starthandle), endHandle_(endHandle), valHandle_(valHandle), reqType_(reqType), reqId_(reqId)
133     {}
GattRequestInfoGattRequestInfo134     GattRequestInfo(ResponesType reqType, int reqId) : reqType_(reqType), reqId_(reqId)
135     {}
GattRequestInfoGattRequestInfo136     GattRequestInfo(const Uuid &uuid, ResponesType reqType, int reqId) : reqType_(reqType), uuid_(uuid), reqId_(reqId)
137     {}
GattRequestInfoGattRequestInfo138     GattRequestInfo(ResponesType reqType, uint16_t handle, int reqId)
139         : startHandle_(handle), reqType_(reqType), reqId_(reqId)
140     {}
GattRequestInfoGattRequestInfo141     GattRequestInfo(ResponesType reqType, uint16_t handle, uint16_t offset, uint16_t len, GattValue data, int reqId)
142         : startHandle_(handle), endHandle_(len), valHandle_(offset), data_(data), reqType_(reqType), reqId_(reqId)
143     {}
144 };
145 struct ReadValCache {
146     uint16_t handle_ = 0;
147     uint16_t offset_ = 0;
148     Packet *data_ = nullptr;
149 
ReadValCacheReadValCache150     ReadValCache(uint16_t handle, uint16_t offset, Packet *data) : handle_(handle), offset_(offset), data_(data)
151     {
152         data_ = PacketMalloc(0, 0, 0);
153         PacketPayloadAddLast(data_, PacketContinuousPayload(data));
154     }
155 };
156 struct PrepareWriteParam {
157     uint16_t connectHandle_ = 0;
158     uint16_t handle_ = 0;
159     uint16_t offset_ = 0;
160 };
161 }  // namespace bluetooth
162 #endif  // GATT_PROFLIE_DEFINES_H