Path: blob/next/external/cache/sources/rtk_hciattach/hciattach.h
18115 views
/*1*2* BlueZ - Bluetooth protocol stack for Linux3*4* Copyright (C) 2003-2009 Marcel Holtmann <[email protected]>5*6*7* This program is free software; you can redistribute it and/or modify8* it under the terms of the GNU General Public License as published by9* the Free Software Foundation; either version 2 of the License, or10* (at your option) any later version.11*12* This program is distributed in the hope that it will be useful,13* but WITHOUT ANY WARRANTY; without even the implied warranty of14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15* GNU General Public License for more details.16*17* You should have received a copy of the GNU General Public License18* along with this program; if not, write to the Free Software19* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA20*21*/2223#include <termios.h>24#include <stdint.h>25#include <syslog.h>2627#if __BYTE_ORDER == __LITTLE_ENDIAN28#define cpu_to_le16(d) (d)29#define cpu_to_le32(d) (d)30#define le16_to_cpu(d) (d)31#define le32_to_cpu(d) (d)32#elif __BYTE_ORDER == __BIG_ENDIAN33#define cpu_to_le16(d) bswap_16(d)34#define cpu_to_le32(d) bswap_32(d)35#define le16_to_cpu(d) bswap_16(d)36#define le32_to_cpu(d) bswap_32(d)37#else38#error "Unknown byte order"39#endif4041#ifndef N_HCI42#define N_HCI 1543#endif4445#define HCIUARTSETPROTO _IOW('U', 200, int)46#define HCIUARTGETPROTO _IOR('U', 201, int)47#define HCIUARTGETDEVICE _IOR('U', 202, int)48#define HCIUARTSETFLAGS _IOW('U', 203, int)49#define HCIUARTGETFLAGS _IOR('U', 204, int)5051#define HCI_UART_H4 052#define HCI_UART_BCSP 153#define HCI_UART_3WIRE 254#define HCI_UART_H4DS 355#define HCI_UART_LL 456#define HCI_UART_RAW_DEVICE 05758extern uint8_t DBG_ON;5960/* #define SYSLOG */6162#define LOG_STR "Realtek Bluetooth"63#ifdef SYSLOG64#define RS_DBG(fmt, arg...) \65do{ \66if (DBG_ON) \67syslog(LOG_DEBUG, "%s :" fmt "\n" , LOG_STR, ##arg); \68}while(0)6970#define RS_INFO(fmt, arg...) \71do{ \72syslog(LOG_INFO, "%s :" fmt "\n", LOG_STR, ##arg); \73}while(0)7475#define RS_WARN(fmt, arg...) \76do{ \77syslog(LOG_WARNING, "%s WARN: " fmt "\n", LOG_STR, ##arg); \78}while(0)7980#define RS_ERR(fmt, arg...) \81do{ \82syslog(LOG_ERR, "%s ERROR: " fmt "\n", LOG_STR, ##arg); \83}while(0)84#else85#define RS_DBG(fmt, arg...) \86do{ \87if (DBG_ON) \88printf("%s :" fmt "\n" , LOG_STR, ##arg); \89}while(0)9091#define RS_INFO(fmt, arg...) \92do{ \93printf("%s :" fmt "\n", LOG_STR, ##arg); \94}while(0)9596#define RS_WARN(fmt, arg...) \97do{ \98printf("%s WARN: " fmt "\n", LOG_STR, ##arg); \99}while(0)100101#define RS_ERR(fmt, arg...) \102do{ \103printf("%s ERROR: " fmt "\n", LOG_STR, ##arg); \104}while(0)105#endif106107typedef enum _H5_RX_STATE {108H5_W4_PKT_DELIMITER,109H5_W4_PKT_START,110H5_W4_HDR,111H5_W4_DATA,112H5_W4_CRC113} H5_RX_STATE;114115typedef enum _H5_RX_ESC_STATE {116H5_ESCSTATE_NOESC,117H5_ESCSTATE_ESC118} H5_RX_ESC_STATE;119120typedef enum _H5_LINK_STATE {121H5_SYNC,122H5_CONFIG,123H5_INIT,124H5_PATCH,125H5_HCI_RESET,126H5_ACTIVE127} H5_LINK_STATE;128129struct patch_info;130typedef struct rtb_struct {131/* three wire releated */132uint8_t rxseq_txack; /* expected rx seq number */133uint8_t rxack; /* last packet that the peer ack'ed */134uint8_t use_crc;135uint8_t is_txack_req; /* txack required */136uint8_t msgq_txseq; /* next pkt seq */137uint16_t message_crc;138uint32_t rx_count; /* expected pkts to recv */139140H5_RX_STATE rx_state;141H5_RX_ESC_STATE rx_esc_state;142H5_LINK_STATE link_estab_state;143144struct sk_buff *rx_skb;145146uint16_t num_of_cmd_sent;147uint16_t lmp_subver;148uint16_t hci_rev;149uint8_t hci_ver;150uint8_t eversion;151uint8_t chip_type;152153uint32_t vendor_baud;154uint8_t dl_fw_flag;155int serial_fd;156int uart_flow_ctrl;157uint32_t parenb: 16;158uint32_t pareven: 16;159int final_speed;160int total_num; /* total pkt number */161int tx_index; /* current sending pkt number */162int rx_index; /* ack index from board */163int fw_len; /* fw patch file len */164int config_len; /* config patch file len */165int total_len; /* fw & config extracted buf len */166uint8_t *fw_buf; /* fw patch file buf */167uint8_t *config_buf; /* config patch file buf */168uint8_t *total_buf; /* fw & config extracted buf */169#define CMD_STATE_UNKNOWN 0x00170#define CMD_STATE_SUCCESS 0x01171struct __cmd_state {172uint16_t opcode;173uint16_t state;174} cmd_state;175176struct patch_info *patch_ent;177178int proto;179int timerfd;180int epollfd;181} rtb_struct_t;182extern struct rtb_struct rtb_cfg;183int timeout_set(int fd, unsigned int msec);184int set_speed(int fd, struct termios *ti, int speed);185int rtb_init(int fd, int proto, int speed, struct termios *ti);186int rtb_post(int fd, int proto, struct termios *ti);187void util_hexdump(const uint8_t *buf, size_t len);188189190