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_BT_COMMON_H 17 #define SOFTBUS_ADAPTER_BT_COMMON_H 18 19 #include "softbus_adapter_thread.h" 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 #define BT_ADDR_LEN 6 26 #define BT_UUID_LEN 16 27 28 #define MAC_FIRST_INDEX 0 29 #define MAC_ONE_INDEX 1 30 #define MAC_FIVE_INDEX 5 31 #define BLE_WRITE_TIMEOUT_IN_MS 500 32 33 typedef enum { 34 BLE_DISABLE = 0, 35 BLE_ENABLE = 1, 36 BLE_STATE_BUTT, 37 } SoftBusBleState; 38 39 typedef enum { 40 BR_DISABLE = 0, 41 BR_ENABLE = 1, 42 BR_STATE_BUTT, 43 } SoftBusBrState; 44 45 typedef enum { 46 SOFTBUS_BT_STATUS_SUCCESS = 0x00, 47 SOFTBUS_BT_STATUS_FAIL, 48 SOFTBUS_BT_STATUS_NOT_READY, 49 SOFTBUS_BT_STATUS_NOMEM, 50 SOFTBUS_BT_STATUS_BUSY, 51 SOFTBUS_BT_STATUS_DONE, 52 SOFTBUS_BT_STATUS_UNSUPPORTED, 53 SOFTBUS_BT_STATUS_PARM_INVALID, 54 SOFTBUS_BT_STATUS_UNHANDLED, 55 SOFTBUS_BT_STATUS_AUTH_FAILURE, 56 SOFTBUS_BT_STATUS_RMT_DEV_DOWN, 57 SOFTBUS_BT_STATUS_AUTH_REJECTED 58 } SoftBusBtStatus; 59 60 typedef enum { 61 SOFTBUS_BLE_STATE_TURNING_ON = 0x0, 62 SOFTBUS_BLE_STATE_TURN_ON, 63 SOFTBUS_BLE_STATE_TURNING_OFF, 64 SOFTBUS_BLE_STATE_TURN_OFF, 65 SOFTBUS_BR_STATE_TURNING_ON, 66 SOFTBUS_BR_STATE_TURN_ON, 67 SOFTBUS_BR_STATE_TURNING_OFF, 68 SOFTBUS_BR_STATE_TURN_OFF 69 } SoftBusBtStackState; 70 71 typedef enum { 72 SOFTBUS_ACL_STATE_CONNECTED = 0x0, 73 SOFTBUS_ACL_STATE_DISCONNECTED, 74 SOFTBUS_ACL_STATE_LE_CONNECTED, 75 SOFTBUS_ACL_STATE_LE_DISCONNECTED, 76 } SoftBusAclState; 77 78 typedef struct { 79 unsigned char addr[BT_ADDR_LEN]; 80 } SoftBusBtAddr; 81 82 typedef struct { 83 unsigned char uuidLen; 84 char *uuid; 85 } SoftBusBtUuid; 86 87 typedef enum { 88 SOFTBUS_BT_CONNECT = 0x01, 89 SOFTBUS_BT_DISCONNECT = 0x03 90 } SoftBusBtConnectState; 91 92 typedef struct { 93 unsigned short advLength; 94 uint8_t *advData; 95 unsigned short scanRspLength; 96 uint8_t *scanRspData; 97 } SoftBusBleAdvData; 98 99 typedef struct { 100 void (*OnBtStateChanged)(int listenerId, int state); 101 void (*OnBtAclStateChanged)(int32_t listenerId, const SoftBusBtAddr *addr, int32_t aclState, int32_t hciReason); 102 } SoftBusBtStateListener; 103 104 typedef struct { 105 bool isWriteAvailable; 106 SoftBusCond sendCond; 107 SoftBusMutex sendCondLock; 108 } SoftBusBleSendSignal; 109 110 int SoftBusEnableBt(void); 111 112 int SoftBusDisableBt(void); 113 114 int SoftBusGetBtState(void); 115 116 int SoftBusGetBrState(void); 117 118 int SoftBusGetBtMacAddr(SoftBusBtAddr *mac); 119 120 int SoftBusGetBtName(unsigned char *name, unsigned int *len); 121 122 int SoftBusSetBtName(const char *name); 123 124 int SoftBusAddBtStateListener(const SoftBusBtStateListener *listener, int *listenerId); 125 126 int SoftBusRemoveBtStateListener(int listenerId); 127 128 void SoftBusComputeWaitBleSendDataTime(uint32_t waitMillis, SoftBusSysTime *outtime); 129 130 int SoftBusBtInit(void); 131 132 #ifdef __cplusplus 133 } 134 #endif /* __cplusplus */ 135 136 #endif /* SOFTBUS_ADAPTER_BT_COMMON_H */