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 typedef enum { 28 SOFTBUS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE = 0x00, 29 SOFTBUS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE_DIRECTED = 0x04, 30 SOFTBUS_BLE_EVT_CONNECTABLE = 0x01, 31 SOFTBUS_BLE_EVT_CONNECTABLE_DIRECTED = 0x05, 32 SOFTBUS_BLE_EVT_SCANNABLE = 0x02, 33 SOFTBUS_BLE_EVT_SCANNABLE_DIRECTED = 0x06, 34 SOFTBUS_BLE_EVT_LEGACY_NON_CONNECTABLE = 0x10, 35 SOFTBUS_BLE_EVT_LEGACY_SCANNABLE = 0x12, 36 SOFTBUS_BLE_EVT_LEGACY_CONNECTABLE = 0x13, 37 SOFTBUS_BLE_EVT_LEGACY_CONNECTABLE_DIRECTED = 0x15, 38 SOFTBUS_BLE_EVT_LEGACY_SCAN_RSP_TO_ADV_SCAN = 0x1A, 39 SOFTBUS_BLE_EVT_LEGACY_SCAN_RSP_TO_ADV = 0x1B 40 } SoftBusBleScanResultEvtType; 41 42 typedef enum { 43 SOFTBUS_BLE_PUBLIC_DEVICE_ADDRESS = 0x00, 44 SOFTBUS_BLE_RANDOM_DEVICE_ADDRESS = 0x01, 45 SOFTBUS_BLE_PUBLIC_IDENTITY_ADDRESS = 0x02, 46 SOFTBUS_BLE_RANDOM_STATIC_IDENTITY_ADDRESS = 0x03, 47 SOFTBUS_BLE_UNRESOLVABLE_RANDOM_DEVICE_ADDRESS = 0xFE, 48 SOFTBUS_BLE_NO_ADDRESS = 0xFF, 49 } SoftBusBleScanResultAddrType; 50 51 typedef enum { 52 SOFTBUS_BLE_SCAN_TYPE_PASSIVE = 0x00, 53 SOFTBUS_BLE_SCAN_TYPE_ACTIVE, 54 } SoftBusBleScanType; 55 56 typedef enum { 57 SOFTBUS_BLE_SCAN_PHY_NO_PACKET = 0x00, 58 SOFTBUS_BLE_SCAN_PHY_1M = 0x01, 59 SOFTBUS_BLE_SCAN_PHY_2M = 0x02, 60 SOFTBUS_BLE_SCAN_PHY_CODED = 0x03 61 } SoftBusBleScanResultPhyType; 62 63 typedef enum { 64 SOFTBUS_BLE_SCAN_FILTER_POLICY_ACCEPT_ALL = 0x00, 65 SOFTBUS_BLE_SCAN_FILTER_POLICY_ONLY_WHITE_LIST, 66 SOFTBUS_BLE_SCAN_FILTER_POLICY_ACCEPT_ALL_AND_RPA, 67 SOFTBUS_BLE_SCAN_FILTER_POLICY_ONLY_WHITE_LIST_AND_RPA 68 } SoftBusBleScanFilterPolicy; 69 70 typedef enum { 71 SOFTBUS_BLE_ADV_IND = 0x00, 72 SOFTBUS_BLE_ADV_DIRECT_IND_HIGH = 0x01, 73 SOFTBUS_BLE_ADV_SCAN_IND = 0x02, 74 SOFTBUS_BLE_ADV_NONCONN_IND = 0x03, 75 SOFTBUS_BLE_ADV_DIRECT_IND_LOW = 0x04, 76 } SoftBusBleAdvType; 77 78 typedef enum { 79 SOFTBUS_BLE_ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY = 0x00, 80 SOFTBUS_BLE_ADV_FILTER_ALLOW_SCAN_WLST_CON_ANY = 0x01, 81 SOFTBUS_BLE_ADV_FILTER_ALLOW_SCAN_ANY_CON_WLST = 0x02, 82 SOFTBUS_BLE_ADV_FILTER_ALLOW_SCAN_WLST_CON_WLST = 0x03, 83 } SoftBusBleAdvFilter; 84 85 typedef struct { 86 unsigned short scanInterval; 87 unsigned short scanWindow; 88 unsigned char scanType; 89 unsigned char scanPhy; 90 unsigned char scanFilterPolicy; 91 } SoftBusBleScanParams; 92 93 typedef enum { 94 SOFTBUS_BLE_DATA_COMPLETE = 0x00, 95 SOFTBUS_BLE_DATA_INCOMPLETE_MORE_TO_COME = 0x01, 96 SOFTBUS_BLE_DATA_INCOMPLETE_TRUNCATED = 0x02, 97 } SoftBusScanResultDataStatus; 98 99 typedef struct { 100 unsigned char eventType; 101 unsigned char dataStatus; 102 unsigned char addrType; 103 SoftBusBtAddr addr; 104 unsigned char primaryPhy; 105 unsigned char secondaryPhy; 106 unsigned char advSid; 107 char txPower; 108 char rssi; 109 unsigned short periodicAdvInterval; 110 unsigned char directAddrType; 111 SoftBusBtAddr directAddr; 112 unsigned char advLen; 113 unsigned char *advData; 114 } SoftBusBleScanResult; 115 116 typedef struct { 117 void (*OnScanStart)(int listenerId, int status); 118 void (*OnScanStop)(int listenerId, int status); 119 void (*OnScanResult)(int listenerId, const SoftBusBleScanResult *scanResultdata); 120 } SoftBusScanListener; 121 122 typedef struct { 123 unsigned short advLength; 124 char *advData; 125 unsigned short scanRspLength; 126 char *scanRspData; 127 } SoftBusBleAdvData; 128 129 typedef struct { 130 int minInterval; 131 int maxInterval; 132 unsigned char advType; 133 unsigned char ownAddrType; 134 unsigned char peerAddrType; 135 SoftBusBtAddr peerAddr; 136 int channelMap; 137 unsigned char advFilterPolicy; 138 int txPower; 139 int duration; 140 } SoftBusBleAdvParams; 141 142 typedef struct { 143 void (*AdvEnableCallback)(int advId, int status); 144 void (*AdvDisableCallback)(int advId, int status); 145 void (*AdvDataCallback)(int advId, int status); 146 void (*AdvUpdateCallback)(int advId, int status); 147 } SoftBusAdvCallback; 148 149 int BleGattLockInit(void); 150 151 int SoftBusAddScanListener(const SoftBusScanListener *listener); 152 153 int SoftBusRemoveScanListener(int listenerId); 154 155 int SoftBusStartScan(int listnerId, const SoftBusBleScanParams *param); 156 157 int SoftBusStopScan(int listenerId); 158 159 int SoftBusGetAdvChannel(const SoftBusAdvCallback *callback); 160 161 int SoftBusReleaseAdvChannel(int advId); 162 163 int SoftBusSetAdvData(int advId, const SoftBusBleAdvData *data); 164 165 int SoftBusStartAdv(int advId, const SoftBusBleAdvParams *param); 166 167 int SoftBusStopAdv(int advId); 168 169 int SoftBusUpdateAdv(int advId, const SoftBusBleAdvData *data, const SoftBusBleAdvParams *param); 170 171 #ifdef __cplusplus 172 #if __cplusplus 173 } 174 #endif /* __cplusplus */ 175 #endif /* __cplusplus */ 176 #endif