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_H 17 #define SOFTBUS_ADAPTER_BLE_GATT_H 18 19 #include "softbus_adapter_bt_common.h" 20 21 #ifdef __cplusplus 22 #if __cplusplus 23 extern "C" { 24 #endif 25 #endif 26 27 // max adv and scan limit 28 #define ADV_MAX_NUM 9 29 #define SCAN_MAX_NUM 8 30 31 // Bluetooth scan duty cycle, unit: ms 32 #define SOFTBUS_BLE_SCAN_INTERVAL_P2 3000 33 #define SOFTBUS_BLE_SCAN_INTERVAL_P10 600 34 #define SOFTBUS_BLE_SCAN_INTERVAL_P25 240 35 #define SOFTBUS_BLE_SCAN_INTERVAL_P100 1000 36 #define SOFTBUS_BLE_SCAN_WINDOW_P2 60 37 #define SOFTBUS_BLE_SCAN_WINDOW_P10 60 38 #define SOFTBUS_BLE_SCAN_WINDOW_P25 60 39 #define SOFTBUS_BLE_SCAN_WINDOW_P100 1000 40 41 typedef enum { 42 SOFTBUS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE = 0x00, 43 SOFTBUS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE_DIRECTED = 0x04, 44 SOFTBUS_BLE_EVT_CONNECTABLE = 0x01, 45 SOFTBUS_BLE_EVT_CONNECTABLE_DIRECTED = 0x05, 46 SOFTBUS_BLE_EVT_SCANNABLE = 0x02, 47 SOFTBUS_BLE_EVT_SCANNABLE_DIRECTED = 0x06, 48 SOFTBUS_BLE_EVT_LEGACY_NON_CONNECTABLE = 0x10, 49 SOFTBUS_BLE_EVT_LEGACY_SCANNABLE = 0x12, 50 SOFTBUS_BLE_EVT_LEGACY_CONNECTABLE = 0x13, 51 SOFTBUS_BLE_EVT_LEGACY_CONNECTABLE_DIRECTED = 0x15, 52 SOFTBUS_BLE_EVT_LEGACY_SCAN_RSP_TO_ADV_SCAN = 0x1A, 53 SOFTBUS_BLE_EVT_LEGACY_SCAN_RSP_TO_ADV = 0x1B 54 } SoftBusBleScanResultEvtType; 55 56 typedef enum { 57 SOFTBUS_BLE_PUBLIC_DEVICE_ADDRESS = 0x00, 58 SOFTBUS_BLE_RANDOM_DEVICE_ADDRESS = 0x01, 59 SOFTBUS_BLE_PUBLIC_IDENTITY_ADDRESS = 0x02, 60 SOFTBUS_BLE_RANDOM_STATIC_IDENTITY_ADDRESS = 0x03, 61 SOFTBUS_BLE_UNRESOLVABLE_RANDOM_DEVICE_ADDRESS = 0xFE, 62 SOFTBUS_BLE_NO_ADDRESS = 0xFF, 63 } SoftBusBleScanResultAddrType; 64 65 typedef enum { 66 SOFTBUS_BLE_SCAN_TYPE_PASSIVE = 0x00, 67 SOFTBUS_BLE_SCAN_TYPE_ACTIVE, 68 } SoftBusBleScanType; 69 70 typedef enum { 71 SOFTBUS_BLE_SCAN_PHY_NO_PACKET = 0x00, 72 SOFTBUS_BLE_SCAN_PHY_1M = 0x01, 73 SOFTBUS_BLE_SCAN_PHY_2M = 0x02, 74 SOFTBUS_BLE_SCAN_PHY_CODED = 0x03 75 } SoftBusBleScanResultPhyType; 76 77 typedef enum { 78 SOFTBUS_BLE_SCAN_FILTER_POLICY_ACCEPT_ALL = 0x00, 79 SOFTBUS_BLE_SCAN_FILTER_POLICY_ONLY_WHITE_LIST, 80 SOFTBUS_BLE_SCAN_FILTER_POLICY_ACCEPT_ALL_AND_RPA, 81 SOFTBUS_BLE_SCAN_FILTER_POLICY_ONLY_WHITE_LIST_AND_RPA 82 } SoftBusBleScanFilterPolicy; 83 84 typedef enum { 85 SOFTBUS_BLE_ADV_IND = 0x00, 86 SOFTBUS_BLE_ADV_DIRECT_IND_HIGH = 0x01, 87 SOFTBUS_BLE_ADV_SCAN_IND = 0x02, 88 SOFTBUS_BLE_ADV_NONCONN_IND = 0x03, 89 SOFTBUS_BLE_ADV_DIRECT_IND_LOW = 0x04, 90 } SoftBusBleAdvType; 91 92 typedef enum { 93 SOFTBUS_BLE_ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY = 0x00, 94 SOFTBUS_BLE_ADV_FILTER_ALLOW_SCAN_WLST_CON_ANY = 0x01, 95 SOFTBUS_BLE_ADV_FILTER_ALLOW_SCAN_ANY_CON_WLST = 0x02, 96 SOFTBUS_BLE_ADV_FILTER_ALLOW_SCAN_WLST_CON_WLST = 0x03, 97 } SoftBusBleAdvFilter; 98 99 typedef struct { 100 unsigned short scanInterval; 101 unsigned short scanWindow; 102 unsigned char scanType; 103 unsigned char scanPhy; 104 unsigned char scanFilterPolicy; 105 } SoftBusBleScanParams; 106 107 typedef struct { 108 char *address; 109 char *deviceName; 110 unsigned int serviceUuidLength; 111 unsigned char *serviceUuid; 112 unsigned char *serviceUuidMask; 113 unsigned int serviceDataLength; 114 unsigned char *serviceData; 115 unsigned char *serviceDataMask; 116 unsigned int manufactureDataLength; 117 unsigned char *manufactureData; 118 unsigned char *manufactureDataMask; 119 unsigned short manufactureId; 120 } SoftBusBleScanFilter; 121 122 typedef enum { 123 SOFTBUS_BLE_DATA_COMPLETE = 0x00, 124 SOFTBUS_BLE_DATA_INCOMPLETE_MORE_TO_COME = 0x01, 125 SOFTBUS_BLE_DATA_INCOMPLETE_TRUNCATED = 0x02, 126 } SoftBusScanResultDataStatus; 127 128 typedef struct { 129 unsigned char eventType; 130 unsigned char dataStatus; 131 unsigned char addrType; 132 SoftBusBtAddr addr; 133 unsigned char primaryPhy; 134 unsigned char secondaryPhy; 135 unsigned char advSid; 136 char txPower; 137 char rssi; 138 unsigned short periodicAdvInterval; 139 unsigned char directAddrType; 140 SoftBusBtAddr directAddr; 141 unsigned char advLen; 142 unsigned char *advData; 143 char *deviceName; 144 unsigned char rspDataLen; 145 unsigned char *rspData; 146 } SoftBusBleScanResult; 147 148 typedef struct { 149 void (*OnScanStart)(int listenerId, int status); 150 void (*OnScanStop)(int listenerId, int status); 151 void (*OnScanResult)(int listenerId, const SoftBusBleScanResult *scanResultdata); 152 void (*OnScanStateChanged)(int32_t resultCode, bool isStartScan); 153 } SoftBusScanListener; 154 155 typedef struct { 156 int minInterval; 157 int maxInterval; 158 unsigned char advType; 159 unsigned char ownAddrType; 160 unsigned char peerAddrType; 161 SoftBusBtAddr peerAddr; 162 int channelMap; 163 unsigned char advFilterPolicy; 164 int8_t txPower; 165 int duration; 166 } SoftBusBleAdvParams; 167 168 typedef struct { 169 void (*AdvEnableCallback)(int advId, int status); 170 void (*AdvDisableCallback)(int advId, int status); 171 void (*AdvDataCallback)(int advId, int status); 172 void (*AdvUpdateCallback)(int advId, int status); 173 void (*LpDeviceInfoCallback)(SoftBusBtUuid *uuid, int32_t type, uint8_t *data, uint32_t dataSize); 174 } SoftBusAdvCallback; 175 176 int BleGattLockInit(void); 177 178 int SoftBusAddScanListener(const SoftBusScanListener *listener, int *scannerId, bool isLpDeviceScan); 179 180 int SoftBusRemoveScanListener(int listenerId); 181 182 int SoftBusSetScanFilter(int listenerId, SoftBusBleScanFilter *filter, uint8_t filterSize); 183 184 int SoftBusStartScan(int listenerId, int scannerId, const SoftBusBleScanParams *param); 185 186 int SoftBusStopScan(int listenerId, int scannerId); 187 188 int SoftBusGetAdvChannel(const SoftBusAdvCallback *callback, int *scannerId, bool isLpDeviceScan); 189 190 int SoftBusReleaseAdvChannel(int advId); 191 192 int SoftBusSetAdvData(int advId, const SoftBusBleAdvData *data); 193 194 int SoftBusStartAdv(int advId, const SoftBusBleAdvParams *param); 195 196 int SoftBusStopAdv(int advId); 197 198 int SoftBusUpdateAdv(int advId, const SoftBusBleAdvData *data, const SoftBusBleAdvParams *param); 199 200 int SoftBusReplaceAdvertisingAdv(int advId, const SoftBusBleAdvData *data); 201 202 bool SoftBusIsLpDeviceAvailable(void); 203 204 bool SoftBusSetAdvFilterParam(int advHandle, int advId, SoftBusBleAdvParams *advParam, 205 int listenerId, SoftBusBleScanParams *scanParam); 206 207 int32_t SoftBusGetAdvHandle(int32_t advId, int32_t *advHandle); 208 209 int32_t SoftBusEnableSyncDataToLpDevice(void); 210 211 int32_t SoftBusDisableSyncDataToLpDevice(void); 212 213 int32_t SoftBusDeregisterScanCallbacks(int32_t scannerId); 214 215 int32_t SoftBusSetScanReportChannelToLpDevice(int32_t scannerId, bool enable); 216 217 int32_t SoftBusSetLpDeviceParam(int duration, int maxExtAdvEvents, int window, 218 int interval, int advHandle); 219 #ifdef __cplusplus 220 #if __cplusplus 221 } 222 #endif /* __cplusplus */ 223 #endif /* __cplusplus */ 224 #endif