sync
[external/uim.git] / uim.h
1 /*
2  *  User Mode Init manager - For shared transport
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program;if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 #ifndef UIM_H
20 #define UIM_H
21
22 /* Paramaters to set the baud rate*/
23 #define  FLOW_CTL       0x0001
24 #define  BOTHER         0x00001000
25 #define  ARM_NCCS       19
26
27 #define TCGETS2      _IOR('T',0x2A, struct termios2)
28 #define TCSETS2      _IOW('T',0x2B, struct termios2)
29
30 /*HCI Command and Event information*/
31 #define HCI_HDR_OPCODE          0xff36
32 #define WRITE_BD_ADDR_OPCODE    0xFC06
33 #define RESP_PREFIX             0x04
34 #define MAX_TRY                 10
35
36 /* HCI Packet types */
37 #define HCI_COMMAND_PKT         0x01
38 #define HCI_EVENT_PKT           0x04
39
40 /* HCI command macros*/
41 #define HCI_EVENT_HDR_SIZE              2
42 #define HCI_COMMAND_HDR_SIZE            3
43 #define UIM_WRITE_BD_ADDR_CP_SIZE       6
44
45
46 /* HCI event macros*/
47 #define EVT_CMD_COMPLETE_SIZE   3
48 #define EVT_CMD_STATUS_SIZE     4
49 #define EVT_CMD_COMPLETE        0x0E
50 #define EVT_CMD_STATUS          0x0F
51
52
53 #define VERBOSE
54 #ifdef ANDROID
55 #define LOG_TAG "uim-sysfs"
56 #define UIM_ERR(fmt, arg...)  ALOGE("uim:"fmt"\n" , ##arg)
57 #if defined(UIM_DEBUG)          /* limited debug messages */
58 #define UIM_START_FUNC()      ALOGE("uim: Inside %s", __FUNCTION__)
59 #define UIM_DBG(fmt, arg...)  ALOGE("uim:"fmt"\n" , ## arg)
60 #define UIM_VER(fmt, arg...)
61 #elif defined(VERBOSE)          /* very verbose */
62 #define UIM_START_FUNC()      ALOGE("uim: Inside %s", __FUNCTION__)
63 #define UIM_DBG(fmt, arg...)  ALOGE("uim:"fmt"\n" , ## arg)
64 #define UIM_VER(fmt, arg...)  ALOGE("uim:"fmt"\n" , ## arg)
65 #else /* error msgs only */
66 #define UIM_START_FUNC()
67 #define UIM_DBG(fmt, arg...)
68 #define UIM_VER(fmt, arg...)
69 #endif
70 #else
71 #define UIM_START_FUNC()
72 #define UIM_DBG(fmt, arg...)
73 #define UIM_VER(fmt, arg...)
74 #define UIM_ERR(fmt, arg...)
75 #endif  /* ANDROID */
76
77 /*Termios2 structure for setting the Custom baud rate*/
78 struct termios2 {
79         tcflag_t c_iflag;       /* input mode flags */
80         tcflag_t c_oflag;       /* output mode flags */
81         tcflag_t c_cflag;       /* control mode flags */
82         tcflag_t c_lflag;       /* local mode flags */
83         cc_t c_line;            /* line discipline */
84         cc_t c_cc[ARM_NCCS];    /* control characters */
85         speed_t c_ispeed;       /* input speed */
86         speed_t c_ospeed;       /* output speed */
87 };
88
89 /* HCI command header*/
90 typedef struct {
91         uint16_t        opcode;         /* OCF & OGF */
92         uint8_t         plen;
93 } __attribute__ ((packed))      hci_command_hdr;
94
95 /* HCI event header*/
96 typedef struct {
97         uint8_t         evt;
98         uint8_t         plen;
99 } __attribute__ ((packed))      hci_event_hdr;
100
101 /* HCI command complete event*/
102 typedef struct {
103         uint8_t         ncmd;
104         uint16_t        opcode;
105 } __attribute__ ((packed)) evt_cmd_complete;
106
107 /* HCI event status*/
108 typedef struct {
109         uint8_t         status;
110         uint8_t         ncmd;
111         uint16_t        opcode;
112 } __attribute__ ((packed)) evt_cmd_status;
113
114 /* HCI Event structure to set the cusrom baud rate*/
115 typedef struct {
116         uint8_t uart_prefix;
117         hci_event_hdr hci_hdr;
118         evt_cmd_complete cmd_complete;
119         uint8_t status;
120         uint8_t data[16];
121 } __attribute__ ((packed)) command_complete_t;
122
123 /* HCI Command structure to set the cusrom baud rate*/
124 typedef struct {
125         uint8_t uart_prefix;
126         hci_command_hdr hci_hdr;
127         uint32_t speed;
128 } __attribute__ ((packed)) uim_speed_change_cmd;
129
130 /* BD address structure to set the uim BD address*/
131 typedef struct {
132         unsigned char b[6];
133 } __attribute__((packed)) bdaddr_t;
134
135 /* HCI Command structure to set the uim BD address*/
136 typedef struct {
137         uint8_t uart_prefix;
138         hci_command_hdr hci_hdr;
139         bdaddr_t addr;
140 } __attribute__ ((packed)) uim_bdaddr_change_cmd;
141
142 #define INSTALL_SYSFS_ENTRY     "/sys/devices/platform/kim/install"
143 #define DEV_NAME_SYSFS          "/sys/devices/platform/kim/dev_name"
144 #define BAUD_RATE_SYSFS         "/sys/devices/platform/kim/baud_rate"
145 #define FLOW_CTRL_SYSFS         "/sys/devices/platform/kim/flow_cntrl"
146
147 /* Functions to insert and remove the kernel modules from the system*/
148 extern int init_module(void *, unsigned int, const char *);
149 extern int delete_module(const char *, unsigned int);
150 extern int load_file(const char *, unsigned int *);
151
152 #endif /* UIM_H */