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