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 BT_VENDOR_LIB_H 17 #define BT_VENDOR_LIB_H 18 19 #include <stdint.h> 20 21 #ifdef __cplusplus 22 extern "C" { 23 #endif 24 25 /** 26 * Define HCI channel descriptors array used in BT_OP_HCI_CHANNEL_OPEN operation. 27 */ 28 typedef enum { 29 HCI_CMD, // HCI Command channel 30 HCI_EVT, // HCI Event channel 31 HCI_ACL_OUT, // HCI ACL downstream channel 32 HCI_ACL_IN, // HCI ACL upstream channel 33 HCI_MAX_CHANNEL // Total channels 34 } hci_channels_t; 35 36 typedef enum { 37 BTC_OP_RESULT_SUCCESS, 38 BTC_OP_RESULT_FAIL, 39 } bt_op_result_t; 40 41 /** 42 * BT vendor lib cmd. 43 */ 44 typedef enum { 45 /** 46 * Power on the BT Controller. 47 * @return 0 if success. 48 */ 49 BT_OP_POWER_ON, 50 51 /** 52 * Power off the BT Controller. 53 * @return 0 if success. 54 */ 55 BT_OP_POWER_OFF, 56 57 /** 58 * Establish hci channels. it will be called after BT_OP_POWER_ON. 59 * @param int (*)[HCI_MAX_CHANNEL]. 60 * @return fd count. 61 */ 62 BT_OP_HCI_CHANNEL_OPEN, 63 64 /** 65 * Close all the hci channels which is opened. 66 */ 67 BT_OP_HCI_CHANNEL_CLOSE, 68 69 /** 70 * initialization the BT Controller. it will be called after BT_OP_HCI_CHANNEL_OPEN. 71 * Controller Must call init_cb to notify the host once it has been done. 72 */ 73 BT_OP_INIT, 74 75 /** 76 * Get the LPM idle timeout in milliseconds. 77 * @param (uint_32 *)milliseconds, btc will return the value of lpm timer. 78 * @return 0 if success. 79 */ 80 BT_OP_GET_LPM_TIMER, 81 82 /** 83 * Enable LPM mode on BT Controller. 84 */ 85 BT_OP_LPM_ENABLE, 86 87 /** 88 * Disable LPM mode on BT Controller. 89 */ 90 BT_OP_LPM_DISABLE, 91 92 /** 93 * Wakeup lock the BTC. 94 */ 95 BT_OP_WAKEUP_LOCK, 96 97 /** 98 * Wakeup unlock the BTC. 99 */ 100 BT_OP_WAKEUP_UNLOCK, 101 102 /** 103 * transmit event response to vendor lib. 104 * @param (void *)buf, struct of HC_BT_HDR. 105 */ 106 BT_OP_EVENT_CALLBACK 107 } bt_opcode_t; 108 109 /** 110 * initialization callback. 111 */ 112 typedef void (*init_callback)(bt_op_result_t result); 113 114 /** 115 * call the callback to malloc a size of buf. 116 */ 117 typedef void* (*malloc_callback)(int size); 118 119 /** 120 * call the callback to free buf 121 */ 122 typedef void (*free_callback)(void* buf); 123 124 /** 125 * hci command packet transmit callback 126 * Vendor lib calls cmd_xmit_cb function in order to send a HCI Command 127 * packet to BT Controller. 128 * 129 * The opcode parameter gives the HCI OpCode (combination of OGF and OCF) of 130 * HCI Command packet. For example, opcode = 0x0c03 for the HCI_RESET command 131 * packet. 132 */ 133 typedef size_t (*cmd_xmit_callback)(uint16_t opcode, void* p_buf); 134 135 typedef struct { 136 /** 137 * set to sizeof(bt_vendor_callbacks_t) 138 */ 139 size_t size; 140 141 /* notifies caller result of init request */ 142 init_callback init_cb; 143 144 /* buffer allocation request */ 145 malloc_callback alloc; 146 147 /* buffer free request */ 148 free_callback dealloc; 149 150 /* hci command packet transmit request */ 151 cmd_xmit_callback xmit_cb; 152 } bt_vendor_callbacks_t; 153 154 /** 155 * Bluetooth Host/Controller VENDOR Interface 156 */ 157 typedef struct { 158 /** 159 * Set to sizeof(bt_vndor_interface_t) 160 */ 161 size_t size; 162 163 /** 164 * Caller will open the interface and pass in the callback routines 165 * to the implemenation of this interface. 166 */ 167 int (*init)(const bt_vendor_callbacks_t* p_cb, unsigned char* local_bdaddr); 168 169 /** 170 * Vendor specific operations 171 */ 172 int (*op)(bt_opcode_t opcode, void* param); 173 174 /** 175 * Closes the interface 176 */ 177 void (*close)(void); 178 } bt_vendor_interface_t; 179 180 typedef struct { 181 uint16_t event; 182 uint16_t len; 183 uint16_t offset; 184 uint16_t layer_specific; 185 uint8_t data[]; 186 } HC_BT_HDR; 187 188 #ifdef __cplusplus 189 } 190 #endif 191 192 #endif /* BT_VENDOR_LIB_H */ 193