10b966c5eSopenharmony_ci/*
20b966c5eSopenharmony_ci * Copyright (C) 2021 Huawei Device Co., Ltd.
30b966c5eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
40b966c5eSopenharmony_ci * you may not use this file except in compliance with the License.
50b966c5eSopenharmony_ci * You may obtain a copy of the License at
60b966c5eSopenharmony_ci *
70b966c5eSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
80b966c5eSopenharmony_ci *
90b966c5eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
100b966c5eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
110b966c5eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
120b966c5eSopenharmony_ci * See the License for the specific language governing permissions and
130b966c5eSopenharmony_ci * limitations under the License.
140b966c5eSopenharmony_ci */
150b966c5eSopenharmony_ci
160b966c5eSopenharmony_ci#ifndef BT_VENDOR_LIB_H
170b966c5eSopenharmony_ci#define BT_VENDOR_LIB_H
180b966c5eSopenharmony_ci
190b966c5eSopenharmony_ci#include <stdint.h>
200b966c5eSopenharmony_ci
210b966c5eSopenharmony_ci#ifdef __cplusplus
220b966c5eSopenharmony_ciextern "C" {
230b966c5eSopenharmony_ci#endif
240b966c5eSopenharmony_ci
250b966c5eSopenharmony_ci/**
260b966c5eSopenharmony_ci * Define HCI channel descriptors array used in BT_OP_HCI_CHANNEL_OPEN operation.
270b966c5eSopenharmony_ci */
280b966c5eSopenharmony_citypedef enum {
290b966c5eSopenharmony_ci    HCI_CMD,        // HCI Command channel
300b966c5eSopenharmony_ci    HCI_EVT,        // HCI Event channel
310b966c5eSopenharmony_ci    HCI_ACL_OUT,    // HCI ACL downstream channel
320b966c5eSopenharmony_ci    HCI_ACL_IN,     // HCI ACL upstream channel
330b966c5eSopenharmony_ci    HCI_MAX_CHANNEL // Total channels
340b966c5eSopenharmony_ci} hci_channels_t;
350b966c5eSopenharmony_ci
360b966c5eSopenharmony_citypedef enum {
370b966c5eSopenharmony_ci    BTC_OP_RESULT_SUCCESS,
380b966c5eSopenharmony_ci    BTC_OP_RESULT_FAIL,
390b966c5eSopenharmony_ci} bt_op_result_t;
400b966c5eSopenharmony_ci
410b966c5eSopenharmony_ci/**
420b966c5eSopenharmony_ci * BT vendor lib cmd.
430b966c5eSopenharmony_ci */
440b966c5eSopenharmony_citypedef enum {
450b966c5eSopenharmony_ci    /**
460b966c5eSopenharmony_ci     * Power on the BT Controller.
470b966c5eSopenharmony_ci     * @return 0 if success.
480b966c5eSopenharmony_ci     */
490b966c5eSopenharmony_ci    BT_OP_POWER_ON,
500b966c5eSopenharmony_ci
510b966c5eSopenharmony_ci    /**
520b966c5eSopenharmony_ci     * Power off the BT Controller.
530b966c5eSopenharmony_ci     * @return 0 if success.
540b966c5eSopenharmony_ci     */
550b966c5eSopenharmony_ci    BT_OP_POWER_OFF,
560b966c5eSopenharmony_ci
570b966c5eSopenharmony_ci    /**
580b966c5eSopenharmony_ci     * Establish hci channels. it will be called after BT_OP_POWER_ON.
590b966c5eSopenharmony_ci     * @param int (*)[HCI_MAX_CHANNEL].
600b966c5eSopenharmony_ci     * @return fd count.
610b966c5eSopenharmony_ci     */
620b966c5eSopenharmony_ci    BT_OP_HCI_CHANNEL_OPEN,
630b966c5eSopenharmony_ci
640b966c5eSopenharmony_ci    /**
650b966c5eSopenharmony_ci     * Close all the hci channels which is opened.
660b966c5eSopenharmony_ci     */
670b966c5eSopenharmony_ci    BT_OP_HCI_CHANNEL_CLOSE,
680b966c5eSopenharmony_ci
690b966c5eSopenharmony_ci    /**
700b966c5eSopenharmony_ci     * initialization the BT Controller. it will be called after BT_OP_HCI_CHANNEL_OPEN.
710b966c5eSopenharmony_ci     * Controller Must call init_cb to notify the host once it has been done.
720b966c5eSopenharmony_ci     */
730b966c5eSopenharmony_ci    BT_OP_INIT,
740b966c5eSopenharmony_ci
750b966c5eSopenharmony_ci    /**
760b966c5eSopenharmony_ci     * Get the LPM idle timeout in milliseconds.
770b966c5eSopenharmony_ci     * @param (uint_32 *)milliseconds, btc will return the value of lpm timer.
780b966c5eSopenharmony_ci     * @return 0 if success.
790b966c5eSopenharmony_ci     */
800b966c5eSopenharmony_ci    BT_OP_GET_LPM_TIMER,
810b966c5eSopenharmony_ci
820b966c5eSopenharmony_ci    /**
830b966c5eSopenharmony_ci     * Enable LPM mode on BT Controller.
840b966c5eSopenharmony_ci     */
850b966c5eSopenharmony_ci    BT_OP_LPM_ENABLE,
860b966c5eSopenharmony_ci
870b966c5eSopenharmony_ci    /**
880b966c5eSopenharmony_ci     * Disable LPM mode on BT Controller.
890b966c5eSopenharmony_ci     */
900b966c5eSopenharmony_ci    BT_OP_LPM_DISABLE,
910b966c5eSopenharmony_ci
920b966c5eSopenharmony_ci    /**
930b966c5eSopenharmony_ci     * Wakeup lock the BTC.
940b966c5eSopenharmony_ci     */
950b966c5eSopenharmony_ci    BT_OP_WAKEUP_LOCK,
960b966c5eSopenharmony_ci
970b966c5eSopenharmony_ci    /**
980b966c5eSopenharmony_ci     * Wakeup unlock the BTC.
990b966c5eSopenharmony_ci     */
1000b966c5eSopenharmony_ci    BT_OP_WAKEUP_UNLOCK,
1010b966c5eSopenharmony_ci
1020b966c5eSopenharmony_ci    /**
1030b966c5eSopenharmony_ci     * transmit event response to vendor lib.
1040b966c5eSopenharmony_ci     * @param (void *)buf, struct of HC_BT_HDR.
1050b966c5eSopenharmony_ci     */
1060b966c5eSopenharmony_ci    BT_OP_EVENT_CALLBACK
1070b966c5eSopenharmony_ci} bt_opcode_t;
1080b966c5eSopenharmony_ci
1090b966c5eSopenharmony_ci/**
1100b966c5eSopenharmony_ci * initialization callback.
1110b966c5eSopenharmony_ci */
1120b966c5eSopenharmony_citypedef void (*init_callback)(bt_op_result_t result);
1130b966c5eSopenharmony_ci
1140b966c5eSopenharmony_ci/**
1150b966c5eSopenharmony_ci * call the callback to malloc a size of buf.
1160b966c5eSopenharmony_ci */
1170b966c5eSopenharmony_citypedef void* (*malloc_callback)(int size);
1180b966c5eSopenharmony_ci
1190b966c5eSopenharmony_ci/**
1200b966c5eSopenharmony_ci * call the callback to free buf
1210b966c5eSopenharmony_ci */
1220b966c5eSopenharmony_citypedef void (*free_callback)(void* buf);
1230b966c5eSopenharmony_ci
1240b966c5eSopenharmony_ci/**
1250b966c5eSopenharmony_ci *  hci command packet transmit callback
1260b966c5eSopenharmony_ci *  Vendor lib calls cmd_xmit_cb function in order to send a HCI Command
1270b966c5eSopenharmony_ci *  packet to BT Controller.
1280b966c5eSopenharmony_ci *
1290b966c5eSopenharmony_ci *  The opcode parameter gives the HCI OpCode (combination of OGF and OCF) of
1300b966c5eSopenharmony_ci *  HCI Command packet. For example, opcode = 0x0c03 for the HCI_RESET command
1310b966c5eSopenharmony_ci *  packet.
1320b966c5eSopenharmony_ci */
1330b966c5eSopenharmony_citypedef size_t (*cmd_xmit_callback)(uint16_t opcode, void* p_buf);
1340b966c5eSopenharmony_ci
1350b966c5eSopenharmony_citypedef struct {
1360b966c5eSopenharmony_ci    /**
1370b966c5eSopenharmony_ci     * set to sizeof(bt_vendor_callbacks_t)
1380b966c5eSopenharmony_ci     */
1390b966c5eSopenharmony_ci    size_t size;
1400b966c5eSopenharmony_ci
1410b966c5eSopenharmony_ci    /* notifies caller result of init request */
1420b966c5eSopenharmony_ci    init_callback init_cb;
1430b966c5eSopenharmony_ci
1440b966c5eSopenharmony_ci    /* buffer allocation request */
1450b966c5eSopenharmony_ci    malloc_callback alloc;
1460b966c5eSopenharmony_ci
1470b966c5eSopenharmony_ci    /* buffer free request */
1480b966c5eSopenharmony_ci    free_callback dealloc;
1490b966c5eSopenharmony_ci
1500b966c5eSopenharmony_ci    /* hci command packet transmit request */
1510b966c5eSopenharmony_ci    cmd_xmit_callback xmit_cb;
1520b966c5eSopenharmony_ci} bt_vendor_callbacks_t;
1530b966c5eSopenharmony_ci
1540b966c5eSopenharmony_ci/**
1550b966c5eSopenharmony_ci * Bluetooth Host/Controller VENDOR Interface
1560b966c5eSopenharmony_ci */
1570b966c5eSopenharmony_citypedef struct {
1580b966c5eSopenharmony_ci    /**
1590b966c5eSopenharmony_ci     * Set to sizeof(bt_vndor_interface_t)
1600b966c5eSopenharmony_ci     */
1610b966c5eSopenharmony_ci    size_t size;
1620b966c5eSopenharmony_ci
1630b966c5eSopenharmony_ci    /**
1640b966c5eSopenharmony_ci     * Caller will open the interface and pass in the callback routines
1650b966c5eSopenharmony_ci     * to the implemenation of this interface.
1660b966c5eSopenharmony_ci     */
1670b966c5eSopenharmony_ci    int (*init)(const bt_vendor_callbacks_t* p_cb, unsigned char* local_bdaddr);
1680b966c5eSopenharmony_ci
1690b966c5eSopenharmony_ci    /**
1700b966c5eSopenharmony_ci     * Vendor specific operations
1710b966c5eSopenharmony_ci     */
1720b966c5eSopenharmony_ci    int (*op)(bt_opcode_t opcode, void* param);
1730b966c5eSopenharmony_ci
1740b966c5eSopenharmony_ci    /**
1750b966c5eSopenharmony_ci     * Closes the interface
1760b966c5eSopenharmony_ci     */
1770b966c5eSopenharmony_ci    void (*close)(void);
1780b966c5eSopenharmony_ci} bt_vendor_interface_t;
1790b966c5eSopenharmony_ci
1800b966c5eSopenharmony_citypedef struct {
1810b966c5eSopenharmony_ci    uint16_t event;
1820b966c5eSopenharmony_ci    uint16_t len;
1830b966c5eSopenharmony_ci    uint16_t offset;
1840b966c5eSopenharmony_ci    uint16_t layer_specific;
1850b966c5eSopenharmony_ci    uint8_t data[];
1860b966c5eSopenharmony_ci} HC_BT_HDR;
1870b966c5eSopenharmony_ci
1880b966c5eSopenharmony_ci#ifdef __cplusplus
1890b966c5eSopenharmony_ci}
1900b966c5eSopenharmony_ci#endif
1910b966c5eSopenharmony_ci
1920b966c5eSopenharmony_ci#endif /* BT_VENDOR_LIB_H */
193