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_CLIENT_H 17 #define SOFTBUS_ADAPTER_BLE_GATT_CLIENT_H 18 19 #include "stdbool.h" 20 #include "stdint.h" 21 22 #include "softbus_adapter_bt_common.h" 23 #include "common_list.h" 24 25 #ifdef __cplusplus 26 #if __cplusplus 27 extern "C" { 28 #endif 29 #endif 30 31 typedef struct { 32 SoftBusBtUuid charaUuid; 33 uint32_t dataLen; 34 uint8_t *data; 35 } SoftBusGattcNotify; 36 37 typedef enum { 38 SOFTBUS_GATT_WRITE_NO_RSP = 0x1, 39 SOFTBUS_GATT_WRITE_DEFAULT, 40 SOFTBUS_GATT_WRITE_PREPARE, 41 SOFTBUS_GATT_WRITE_SIGNED, 42 SOFTBUS_GATT_WRITE_TYPE_UNKNOWN, 43 } SoftBusGattWriteType; 44 45 typedef struct { 46 SoftBusBtUuid serviceUuid; 47 SoftBusBtUuid characterUuid; 48 uint32_t valueLen; 49 const uint8_t *value; 50 SoftBusGattWriteType writeType; 51 } SoftBusGattcData; 52 53 typedef struct { 54 void (*ConnectionStateCallback)(int32_t clientId, int32_t connState, int32_t status); 55 void (*ServiceCompleteCallback)(int32_t clientId, int32_t status); 56 void (*RegistNotificationCallback)(int32_t clientId, int status); 57 void (*NotificationReceiveCallback)(int32_t clientId, SoftBusGattcNotify *param, int32_t status); 58 void (*ConfigureMtuSizeCallback)(int clientId, int mtuSize, int status); 59 } SoftBusGattcCallback; 60 61 typedef enum { 62 SOFTBUS_GATT_PRIORITY_BALANCED = 0x0, 63 SOFTBUS_GATT_PRIORITY_HIGH, 64 SOFTBUS_GATT_PRIORITY_LOW_POWER, 65 } SoftbusBleGattPriority; 66 67 typedef struct { 68 SoftBusGattcCallback callback; 69 ListNode node; 70 int32_t clientId; 71 } SoftBusGattcManager; 72 73 int32_t SoftbusGattcRegisterCallback(SoftBusGattcCallback *cb, int32_t clientId); 74 int32_t SoftbusGattcRegister(void); 75 int32_t SoftbusGattcUnRegister(int32_t clientId); 76 int32_t SoftbusGattcConnect(int32_t clientId, SoftBusBtAddr *addr); 77 int32_t SoftbusBleGattcDisconnect(int32_t clientId, bool refreshGatt); 78 int32_t SoftbusGattcSearchServices(int32_t clientId); 79 int32_t SoftbusGattcRefreshServices(int32_t clientId); 80 int32_t SoftbusGattcGetService(int32_t clientId, SoftBusBtUuid *serverUuid); 81 int32_t SoftbusGattcRegisterNotification( 82 int32_t clientId, SoftBusBtUuid *serverUuid, SoftBusBtUuid *charaUuid, SoftBusBtUuid *descriptorUuid); 83 int32_t SoftbusGattcWriteCharacteristic(int32_t clientId, SoftBusGattcData *clientData); 84 int32_t SoftbusGattcConfigureMtuSize(int32_t clientId, int mtuSize); 85 86 int32_t SoftbusGattcSetFastestConn(int32_t clientId); 87 int32_t SoftbusGattcSetPriority(int32_t clientId, SoftBusBtAddr *addr, SoftbusBleGattPriority priority); 88 89 bool SoftbusGattcCheckExistConnectionByAddr(const SoftBusBtAddr *btAddr); 90 91 int32_t InitSoftbusAdapterClient(void); 92 #ifdef __cplusplus 93 #if __cplusplus 94 } 95 #endif /* __cplusplus */ 96 #endif /* __cplusplus */ 97 #endif /* SOFTBUS_ADAPTER_BLE_GATT_CLIENT_H */