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 OHOS { 24 namespace bluetooth { 25 enum ResponesType { 26 NONE, 27 DISCOVER_ALL_PRIMARY_SERVICE, 28 DISCOVER_SERVICE_BY_UUID, 29 FIND_INCLUDE_SERVICE, 30 DISCOVER_ALL_CHARACTERISTIC, 31 DISCOVER_CHARACTERISTIC_BY_UUID, 32 DISCOVER_ALL_CHARACTERISTIC_DESCRIPTOR, 33 READ_CHARACTERISTIC_VALUE, 34 READ_LONG_CHARACTERISTIC_VALUE, 35 READ_USING_CHARACTERISTIC_UUID, 36 READ_MULTIPLE_CHARACTERISTIC, 37 READ_CHARACTERISTIC_DESCRIPTOR, 38 READ_LONG_CHARACTERISTIC_DESCRIPTOR, 39 WRITE_WITHOUT_RESPONSE, 40 SIGNED_WRITE_WITHOUT_RESPONSE, 41 WRITE_CHARACTERISTIC_VALUE, 42 WRITE_CHARACTERISTIC_DESCRIPTOR, 43 WRITE_LONG_CHARACTERISTIC_VALUE, 44 RELIABLE_WRITE_VALUE, 45 EXECUTE_WRITE_VALUE, 46 EXCHANGE_MTU, 47 SEND_INDICATION 48 }; 49 50 enum ReadByTypeResponseLen { 51 READ_USING_CHARACTERISTIC_BY_UUID_LENGTH = 0x04, 52 DISCOVER_CHARACTERISTIC_LENGTH_16BIT = 0x07, 53 DISCOVER_CHARACTERISTIC_LENGTH_128BIT = 0x15, 54 FIND_INCLUDE_SERVICE_LENGTH_16BIT = 0x08, 55 FIND_INCLUDE_SERVICE_LENGTH_128BIT = 0x06, 56 }; 57 58 enum UuidLength { 59 UUID_16BIT_LEN = 0x02, 60 UUID_32BIT_LEN = 0x04, 61 UUID_128BIT_LEN = 0x10, 62 }; 63 64 enum UuidFormat { 65 UUID_16BIT_FORMAT = 0x01, 66 UUID_128BIT_FORMAT = 0x02, 67 }; 68 69 enum RetVal { 70 RET_NORMAL, 71 RET_BREAK, 72 RET_RETURN, 73 RET_CONTINUE, 74 }; 75 76 struct MtuInfo { 77 bool isExchanged_ = false; 78 uint16_t mtu_ = GATT_DEFAULT_MTU; 79 MtuInfoMtuInfo80 MtuInfo(bool isExchanged, uint16_t mtu) : isExchanged_(isExchanged), mtu_(mtu) 81 {} 82 }; 83 84 struct CccdInfo { 85 uint16_t valHandle_ = 0; 86 uint16_t value_ = 0; 87 }; 88 89 struct DeviceInfo { 90 GattDevice device_; 91 CccdInfo cccd_[GATT_CCCD_NUM_MAX] = {}; 92 DeviceInfoDeviceInfo93 explicit DeviceInfo(GattDevice dev) : device_(dev) 94 {} 95 }; 96 97 struct GattResponesInfor { 98 ResponesType respType_ = NONE; 99 uint16_t value_ = 0; 100 GattValue data_ = nullptr; 101 GattResponesInforGattResponesInfor102 GattResponesInfor(ResponesType respType, uint16_t value) : respType_(respType), value_(value) 103 {} GattResponesInforGattResponesInfor104 GattResponesInfor(ResponesType respType, uint16_t value, GattValue data) 105 : respType_(respType), value_(value), data_(data) 106 {} 107 }; 108 struct GattRequestInfo { 109 uint16_t startHandle_ = 0; 110 uint16_t endHandle_ = 0; 111 uint16_t valHandle_ = 0; 112 GattValue data_ = nullptr; 113 ResponesType reqType_ = NONE; 114 Uuid uuid_ = {}; 115 int reqId_ = 0; 116 GattRequestInfoGattRequestInfo117 GattRequestInfo(ResponesType reqType, uint16_t starthandle, uint16_t endHandle, const Uuid &uuid, int reqId) 118 : startHandle_(starthandle), endHandle_(endHandle), reqType_(reqType), uuid_(uuid), reqId_(reqId) 119 {} GattRequestInfoGattRequestInfo120 GattRequestInfo( 121 ResponesType reqType, uint16_t starthandle, uint16_t endHandle, uint16_t valHandle, const Uuid &uuid, int reqId) 122 : startHandle_(starthandle), 123 endHandle_(endHandle), 124 valHandle_(valHandle), 125 reqType_(reqType), 126 uuid_(uuid), 127 reqId_(reqId) 128 {} GattRequestInfoGattRequestInfo129 GattRequestInfo(ResponesType reqType, uint16_t starthandle, uint16_t endHandle, int reqId) 130 : startHandle_(starthandle), endHandle_(endHandle), reqType_(reqType), reqId_(reqId) 131 {} GattRequestInfoGattRequestInfo132 GattRequestInfo(ResponesType reqType, uint16_t starthandle, uint16_t endHandle, uint16_t valHandle, int reqId) 133 : startHandle_(starthandle), endHandle_(endHandle), valHandle_(valHandle), reqType_(reqType), reqId_(reqId) 134 {} GattRequestInfoGattRequestInfo135 GattRequestInfo(ResponesType reqType, int reqId) : reqType_(reqType), reqId_(reqId) 136 {} GattRequestInfoGattRequestInfo137 GattRequestInfo(const Uuid &uuid, ResponesType reqType, int reqId) : reqType_(reqType), uuid_(uuid), reqId_(reqId) 138 {} GattRequestInfoGattRequestInfo139 GattRequestInfo(ResponesType reqType, uint16_t handle, int reqId) 140 : startHandle_(handle), reqType_(reqType), reqId_(reqId) 141 {} GattRequestInfoGattRequestInfo142 GattRequestInfo(ResponesType reqType, uint16_t handle, uint16_t offset, uint16_t len, GattValue data, int reqId) 143 : startHandle_(handle), endHandle_(len), valHandle_(offset), data_(data), reqType_(reqType), reqId_(reqId) 144 {} 145 }; 146 struct ReadValCache { 147 uint16_t handle_ = 0; 148 uint16_t offset_ = 0; 149 Packet *data_ = nullptr; 150 ReadValCacheReadValCache151 ReadValCache(uint16_t handle, uint16_t offset, Packet *data) : handle_(handle), offset_(offset), data_(data) 152 { 153 data_ = PacketMalloc(0, 0, 0); 154 PacketPayloadAddLast(data_, PacketContinuousPayload(data)); 155 } 156 }; 157 struct PrepareWriteParam { 158 uint16_t connectHandle_ = 0; 159 uint16_t handle_ = 0; 160 uint16_t offset_ = 0; 161 }; 162 } // namespace bluetooth 163 } // namespace OHOS 164 #endif // GATT_PROFLIE_DEFINES_H