Line data Source code
1 1 : /** @file 2 : * @brief Bluetooth HCI RAW channel handling 3 : */ 4 : 5 : /* 6 : * Copyright (c) 2016 Intel Corporation 7 : * 8 : * SPDX-License-Identifier: Apache-2.0 9 : */ 10 : #ifndef ZEPHYR_INCLUDE_BLUETOOTH_HCI_RAW_H_ 11 : #define ZEPHYR_INCLUDE_BLUETOOTH_HCI_RAW_H_ 12 : 13 : /** 14 : * @brief HCI RAW channel 15 : * @defgroup hci_raw HCI RAW channel 16 : * @ingroup bluetooth 17 : * @{ 18 : */ 19 : 20 : #include <stdint.h> 21 : 22 : #ifdef __cplusplus 23 : extern "C" { 24 : #endif 25 : 26 : /** @brief Send packet to the Bluetooth controller 27 : * 28 : * Send packet to the Bluetooth controller. Caller needs to 29 : * implement netbuf pool. 30 : * 31 : * @param buf netbuf packet to be send 32 : * 33 : * @return Zero on success or (negative) error code otherwise. 34 : */ 35 1 : int bt_send(struct net_buf *buf); 36 : 37 0 : enum { 38 : /** Passthrough mode 39 : * 40 : * While in this mode the buffers are passed as is between the stack 41 : * and the driver. 42 : */ 43 : BT_HCI_RAW_MODE_PASSTHROUGH = 0x00, 44 : 45 : /** H:4 mode 46 : * 47 : * While in this mode H:4 headers will added into the buffers 48 : * according to the buffer type when coming from the stack and will be 49 : * removed and used to set the buffer type. 50 : */ 51 : BT_HCI_RAW_MODE_H4 = 0x01, 52 : }; 53 : 54 : /** @brief Set Bluetooth RAW channel mode 55 : * 56 : * Set access mode of Bluetooth RAW channel. 57 : * 58 : * @param mode Access mode. 59 : * 60 : * @return Zero on success or (negative) error code otherwise. 61 : */ 62 1 : int bt_hci_raw_set_mode(uint8_t mode); 63 : 64 : /** @brief Get Bluetooth RAW channel mode 65 : * 66 : * Get access mode of Bluetooth RAW channel. 67 : * 68 : * @return Access mode. 69 : */ 70 1 : uint8_t bt_hci_raw_get_mode(void); 71 : 72 0 : #define BT_HCI_ERR_EXT_HANDLED 0xff 73 : 74 : /** Helper macro to define a command extension 75 : * 76 : * @param _op Opcode of the command. 77 : * @param _min_len Minimal length of the command. 78 : * @param _func Handler function to be called. 79 : */ 80 1 : #define BT_HCI_RAW_CMD_EXT(_op, _min_len, _func) \ 81 : { \ 82 : .op = _op, \ 83 : .min_len = _min_len, \ 84 : .func = _func, \ 85 : } 86 : 87 0 : struct bt_hci_raw_cmd_ext { 88 : /** Opcode of the command */ 89 1 : uint16_t op; 90 : 91 : /** Minimal length of the command */ 92 1 : size_t min_len; 93 : 94 : /** Handler function. 95 : * 96 : * Handler function to be called when a command is intercepted. 97 : * 98 : * @param buf Buffer containing the command. 99 : * 100 : * @return HCI Status code or BT_HCI_ERR_EXT_HANDLED if command has 101 : * been handled already and a response has been sent as oppose to 102 : * BT_HCI_ERR_SUCCESS which just indicates that the command can be 103 : * sent to the controller to be processed. 104 : */ 105 1 : uint8_t (*func)(struct net_buf *buf); 106 : }; 107 : 108 : /** @brief Register Bluetooth RAW command extension table 109 : * 110 : * Register Bluetooth RAW channel command extension table, opcodes in this 111 : * table are intercepted to sent to the handler function. 112 : * 113 : * @param cmds Pointer to the command extension table. 114 : * @param size Size of the command extension table. 115 : */ 116 1 : void bt_hci_raw_cmd_ext_register(struct bt_hci_raw_cmd_ext *cmds, size_t size); 117 : 118 : /** @brief Enable Bluetooth RAW channel: 119 : * 120 : * Enable Bluetooth RAW HCI channel. 121 : * 122 : * @param rx_queue netbuf queue where HCI packets received from the Bluetooth 123 : * controller are to be queued. The queue is defined in the caller while 124 : * the available buffers pools are handled in the stack. 125 : * 126 : * @return Zero on success or (negative) error code otherwise. 127 : */ 128 1 : int bt_enable_raw(struct k_fifo *rx_queue); 129 : 130 : #ifdef __cplusplus 131 : } 132 : #endif 133 : /** 134 : * @} 135 : */ 136 : 137 : #endif /* ZEPHYR_INCLUDE_BLUETOOTH_HCI_RAW_H_ */