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