1/* 2 * Copyright (c) 2013, The Linux Foundation. All rights reserved. 3 * Not a Contribution. 4 * Copyright (C) 2009-2012 Broadcom Corporation 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19#ifndef HCI_UART_H 20#define HCI_UART_H 21 22/* Variables to identify the platform */ 23/*BT HS UART TTY DEVICE */ 24#define BT_HS_UART_DEVICE "/dev/ttyHS0" 25 26/**** baud rates ****/ 27#define USERIAL_BAUD_300 0 28#define USERIAL_BAUD_600 1 29#define USERIAL_BAUD_1200 2 30#define USERIAL_BAUD_2400 3 31#define USERIAL_BAUD_9600 4 32#define USERIAL_BAUD_19200 5 33#define USERIAL_BAUD_57600 6 34#define USERIAL_BAUD_115200 7 35#define USERIAL_BAUD_230400 8 36#define USERIAL_BAUD_460800 9 37#define USERIAL_BAUD_921600 10 38#define USERIAL_BAUD_1M 11 39#define USERIAL_BAUD_1_5M 12 40#define USERIAL_BAUD_2M 13 41#define USERIAL_BAUD_3M 14 42#define USERIAL_BAUD_4M 15 43#define USERIAL_BAUD_AUTO 16 44 45/**** Data Format ****/ 46/* Stop Bits */ 47#define USERIAL_STOPBITS_1 1 48#define USERIAL_STOPBITS_1_5 (1<<1) 49#define USERIAL_STOPBITS_2 (1<<2) 50 51/* Parity Bits */ 52#define USERIAL_PARITY_NONE (1<<3) 53#define USERIAL_PARITY_EVEN (1<<4) 54#define USERIAL_PARITY_ODD (1<<5) 55 56/* Data Bits */ 57#define USERIAL_DATABITS_5 (1<<6) 58#define USERIAL_DATABITS_6 (1<<7) 59#define USERIAL_DATABITS_7 (1<<8) 60#define USERIAL_DATABITS_8 (1<<9) 61 62/* HCI Packet types */ 63#define HCI_COMMAND_PKT 0x01 64#define HCI_ACLDATA_PKT 0x02 65#define HCI_SCODATA_PKT 0x03 66#define HCI_EVENT_PKT 0x04 67#define HCI_VENDOR_PKT 0xff 68 69/* HCI Command/Event Opcode */ 70#define HCI_RESET 0x0C03 71#define EVT_CMD_COMPLETE 0x0E 72 73/* Command opcode pack/unpack */ 74#define cmd_opcode_pack(ogf, ocf) (uint16_t)((ocf & 0x03ff)|(ogf << 10)) 75 76#if (BT_WAKE_VIA_USERIAL_IOCTL==TRUE) 77/* These are the ioctl values used for bt_wake ioctl via UART driver. you may 78 * need to redefine them on you platform! 79 * Logically they need to be unique and not colide with existing uart ioctl's. 80 */ 81#ifndef USERIAL_IOCTL_BT_WAKE_ASSERT 82#define USERIAL_IOCTL_BT_WAKE_ASSERT 0x8003 83#endif 84#ifndef USERIAL_IOCTL_BT_WAKE_DEASSERT 85#define USERIAL_IOCTL_BT_WAKE_DEASSERT 0x8004 86#endif 87#ifndef USERIAL_IOCTL_BT_WAKE_GET_ST 88#define USERIAL_IOCTL_BT_WAKE_GET_ST 0x8005 89#endif 90#endif // (BT_WAKE_VIA_USERIAL_IOCTL==TRUE) 91 92/* UART CLOCK IOCTLS*/ 93#define USERIAL_OP_CLK_ON 0x5441 94#define USERIAL_OP_CLK_OFF 0x5442 95#define USERIAL_OP_CLK_STATE 0x5443 96/****************************************************************************** 97** Type definitions 98******************************************************************************/ 99 100/* Structure used to configure serial port during open */ 101typedef struct 102{ 103 uint16_t fmt; /* Data format */ 104 uint8_t baud; /* Baud rate */ 105} tUSERIAL_CFG; 106 107typedef enum { 108#if (BT_WAKE_VIA_USERIAL_IOCTL==TRUE) 109 USERIAL_OP_ASSERT_BT_WAKE, 110 USERIAL_OP_DEASSERT_BT_WAKE, 111 USERIAL_OP_GET_BT_WAKE_STATE, 112#endif 113 USERIAL_OP_FLOW_ON, 114 USERIAL_OP_FLOW_OFF, 115 USERIAL_OP_NOP, 116} userial_vendor_ioctl_op_t; 117 118/* UPIO signals */ 119enum { 120 UPIO_BT_WAKE = 0, 121 UPIO_HOST_WAKE, 122 UPIO_LPM_MODE, 123 UPIO_MAX_COUNT 124}; 125 126/* UPIO assertion/deassertion */ 127enum { 128 UPIO_UNKNOWN = 0, 129 UPIO_DEASSERT, 130 UPIO_ASSERT 131}; 132 133#define VND_PORT_NAME_MAXLEN 256 134 135/* vendor serial control block */ 136typedef struct 137{ 138 int fd; /* fd to Bluetooth device */ 139 struct termios termios; /* serial terminal of BT port */ 140 char port_name[VND_PORT_NAME_MAXLEN]; 141} vnd_userial_cb_t; 142 143typedef struct { 144 uint8_t ncmd; 145 uint16_t opcode; 146} __attribute__ ((packed)) evt_cmd_complete; 147 148typedef struct { 149 uint8_t status; 150 uint8_t ncmd; 151 uint16_t opcode; 152} __attribute__ ((packed)) evt_cmd_status; 153 154typedef struct { 155 uint16_t opcode; 156 uint8_t plen; 157} __attribute__ ((packed)) hci_command_hdr; 158 159typedef struct { 160 uint8_t evt; 161 uint8_t plen; 162} __attribute__ ((packed)) hci_event_hdr; 163 164/****************************************************************************** 165** Extern 166******************************************************************************/ 167extern vnd_userial_cb_t vnd_userial; 168 169 170/******************************************************************************* 171** 172** Function userial_vendor_init 173** 174** Description Initialize userial vendor-specific control block 175** 176** Returns None 177** 178*******************************************************************************/ 179void userial_vendor_init(void); 180 181/******************************************************************************* 182** 183** Function userial_vendor_open 184** 185** Description Open the serial port with the given configuration 186** 187** Returns device fd 188** 189*******************************************************************************/ 190int userial_vendor_open(tUSERIAL_CFG *p_cfg); 191 192/******************************************************************************* 193** 194** Function userial_vendor_close 195** 196** Description Conduct vendor-specific close work 197** 198** Returns None 199** 200*******************************************************************************/ 201void userial_vendor_close(void); 202 203/******************************************************************************* 204** 205** Function userial_vendor_set_baud 206** 207** Description Set new baud rate 208** 209** Returns None 210** 211*******************************************************************************/ 212void userial_vendor_set_baud(uint8_t userial_baud); 213 214/******************************************************************************* 215** 216** Function userial_vendor_ioctl 217** 218** Description ioctl inteface 219** 220** Returns int error 221** 222*******************************************************************************/ 223int userial_vendor_ioctl(userial_vendor_ioctl_op_t op, int *p_data); 224 225/******************************************************************************* 226** 227** Function read_hci_event 228** 229** Description Read HCI event during vendor initialization 230** 231** Returns int: size to read 232** 233*******************************************************************************/ 234int read_hci_event(int fd, unsigned char* buf, int size); 235 236#endif /* HCI_UART_H */ 237