VCOM Linux Driver
Advantech Inc.
Loading...
Searching...
No Matches
vcom_proto_ioctl.h
Go to the documentation of this file.
1#ifndef __VCOM_PROTO_IOCTL_H
2#define __VCOM_PROTO_IOCTL_H
3
4#ifndef _BSD_SOURCE
5//this is needed to solve indianess issues
6// htole32
7#define _BSD_SOURCE
8#endif
9
10#include <endian.h>
11
12static inline int vc_pack_purge(struct vc_proto_packet * pbuf, unsigned int tid,
13 unsigned int pflags, int buflen)
14{
15 unsigned short len;
16 unsigned int cmd;
17 unsigned int p1;
18 unsigned int p2;
19 int plen;
20
22 plen = vc_pack_size(pbuf->attach.uint32);
24
25 if(plen > buflen ){
26 printf("%s(%d) wrong length\n", __func__, __LINE__);
27 return 0;
28 }
29
31 p2 = 0;
32
33 vc_init_hdr(&pbuf->hdr, tid, cmd, len);
34
35 pbuf->attach.param.p1 = htonl(p1);
36 pbuf->attach.param.p2 = htonl(p2);
37
38 pbuf->attach.uint32.uint = htole32(pflags); //little endian
39
40 return plen;
41}
42
43typedef int (*do_check)(struct vc_proto_packet *pbuf, int buflen, void *in);
44
45static inline int vc_check_ioctl(struct vc_proto_packet * pbuf, int buflen,
46 do_check func , void * in)
47{
48 int plen;
49
50 plen = vc_pack_size(pbuf->attach.param);
51
52 if(plen > buflen ){
53 printf("%s(%d) wrong length %d should be %d\n", __func__, __LINE__, plen, buflen);
54 return -1;
55 }
56
57 if(func > 0)
58 return func(pbuf, buflen, in);
59
60 return 0;
61}
62
63static inline int vc_pack_sbaud(struct vc_proto_packet * pbuf, unsigned int tid,
64 unsigned int baud, int buflen)
65{
66 unsigned short len;
67 unsigned int cmd;
68 unsigned int p1;
69 unsigned int p2;
70 int plen;
71
73 plen = vc_pack_size(pbuf->attach.uint32);
75
76 if(plen > buflen ){
77 printf("%s(%d) wrong length\n", __func__, __LINE__);
78 return 0;
79 }
80
82 p2 = 0;
83
84 vc_init_hdr(&pbuf->hdr, tid, cmd, len);
85
86 pbuf->attach.param.p1 = htonl(p1);
87 pbuf->attach.param.p2 = htonl(p2);
88
89 pbuf->attach.uint32.uint = htole32(baud); //little endian
90
91 return plen;
92}
93
94static inline int _pack_ioctl_param(struct vc_proto_packet *pbuf,
95 unsigned int tid, unsigned int subcmd, int buflen)
96{
97 unsigned short len;
98 unsigned int cmd;
99 unsigned int p1;
100 unsigned int p2;
101 int plen;
102
104 plen = vc_pack_size(pbuf->attach.param);
105 len = vc_ext_size(pbuf->attach.param);
106 if(plen > buflen ){
107 printf("%s(%d) wrong length\n", __func__, __LINE__);
108 return 0;
109 }
110
111 p1 = subcmd;
112 p2 = 0;
113
114 vc_init_hdr(&pbuf->hdr, tid, cmd, len);
115
116 pbuf->attach.param.p1 = htonl(p1);
117 pbuf->attach.param.p2 = htonl(p2);
118
119 return plen;
120
121}
122
123static inline int vc_pack_womask(struct vc_proto_packet *pbuf, unsigned int tid, int buflen)
124{
125 return _pack_ioctl_param(pbuf, tid, VCOM_IOCTL_WAIT_ON_MASK, buflen);
126}
127
128static inline int vc_pack_setrts(struct vc_proto_packet *pbuf, unsigned int tid, int buflen)
129{
130 return _pack_ioctl_param(pbuf, tid, VCOM_IOCTL_SET_RTS, buflen);
131}
132
133static inline int vc_pack_setdtr(struct vc_proto_packet *pbuf, unsigned int tid, int buflen)
134{
135 return _pack_ioctl_param(pbuf, tid, VCOM_IOCTL_SET_DTR, buflen);
136}
137
138static inline int vc_pack_clrrts(struct vc_proto_packet *pbuf, unsigned int tid, int buflen)
139{
140 return _pack_ioctl_param(pbuf, tid, VCOM_IOCTL_CLR_RTS, buflen);
141}
142
143static inline int vc_pack_clrdtr(struct vc_proto_packet *pbuf, unsigned int tid, int buflen)
144{
145 return _pack_ioctl_param(pbuf, tid, VCOM_IOCTL_CLR_DTR, buflen);
146}
147
148
149static inline int vc_pack_getmodem(struct vc_proto_packet *pbuf, unsigned int tid, int buflen)
150{
151 return _pack_ioctl_param(pbuf, tid, VCOM_IOCTL_GET_MODEMSTATUS, buflen);
152}
153
154static inline int vc_pack_hflow(struct vc_proto_packet *pbuf, unsigned int tid,
155 int chflow, int flowrep, int buflen)
156{
157 unsigned short len;
158 unsigned int cmd;
159 unsigned int p1;
160 unsigned int p2;
161 int plen;
162
164 plen = vc_pack_size(pbuf->attach.hflow);
165 len = vc_ext_size(pbuf->attach.hflow);
166 if(plen > buflen ){
167 printf("%s(%d) wrong length\n", __func__, __LINE__);
168 return 0;
169 }
170
172 p2 = 0;
173
174 vc_init_hdr(&pbuf->hdr, tid, cmd, len);
175
176 pbuf->attach.param.p1 = htonl(p1);
177 pbuf->attach.param.p2 = htonl(p2);
178
179 pbuf->attach.hflow.chflow = htonl(chflow);
180 pbuf->attach.hflow.flowrep = htonl(flowrep);
181
182 pbuf->attach.hflow.xonlimit = htonl(1024);
183 pbuf->attach.hflow.xonlimit = htonl(512);
184
185 return plen;
186}
187
188
189static inline int vc_pack_setwmask(struct vc_proto_packet * pbuf, unsigned int tid,
190 unsigned int mask, int buflen)
191{
192 unsigned short len;
193 unsigned int cmd;
194 unsigned int p1;
195 unsigned int p2;
196 int plen;
197
199 plen = vc_pack_size(pbuf->attach.uint32);
200 len = vc_ext_size(pbuf->attach.uint32);
201 if(plen > buflen ){
202 printf("%s(%d) wrong length\n", __func__, __LINE__);
203 return 0;
204 }
205
207 p2 = 0;
208
209 vc_init_hdr(&pbuf->hdr, tid, cmd, len);
210
211 pbuf->attach.param.p1 = htonl(p1);
212 pbuf->attach.param.p2 = htonl(p2);
213
214 pbuf->attach.uint32.uint = htonl(mask);
215
216 return plen;
217}
218
219static inline int vc_pack_getwmask(struct vc_proto_packet * pbuf, unsigned int tid, int buflen)
220{
221 unsigned short len;
222 unsigned int cmd;
223 unsigned int p1;
224 unsigned int p2;
225 int plen;
226
228 plen = vc_pack_size(pbuf->attach.param);
229 len = vc_ext_size(pbuf->attach.param);
230 if(plen > buflen ){
231 printf("%s(%d) wrong length\n", __func__, __LINE__);
232 return 0;
233 }
234
236 p2 = 0;
237
238 vc_init_hdr(&pbuf->hdr, tid, cmd, len);
239
240 pbuf->attach.param.p1 = htonl(p1);
241 pbuf->attach.param.p2 = htonl(p2);
242
243 return plen;
244}
245
246
247static inline int vc_pack_setlctl(struct vc_proto_packet * pbuf, unsigned int tid,
248 unsigned char pair, unsigned char dbit, unsigned char sbit, int buflen)
249{
250 unsigned short len;
251 unsigned int cmd;
252 unsigned int p1;
253 unsigned int p2;
254 int plen;
255
257 plen = vc_pack_size(pbuf->attach.lctrl);
258 len = vc_ext_size(pbuf->attach.lctrl);
259 if(plen > buflen ){
260 printf("%s(%d) wrong length\n", __func__, __LINE__);
261 return 0;
262 }
263
265 p2 = 0;
266
267 vc_init_hdr(&pbuf->hdr, tid, cmd, len);
268
269 pbuf->attach.param.p1 = htonl(p1);
270 pbuf->attach.param.p2 = htonl(p2);
271
272 pbuf->attach.lctrl.pair = pair;
273 pbuf->attach.lctrl.dbit = dbit;
274 pbuf->attach.lctrl.sbit = sbit;
275
276 return plen;
277}
278
279#endif
unsigned int chflow
Definition vcom_proto.h:23
unsigned int flowrep
Definition vcom_proto.h:24
unsigned int xonlimit
Definition vcom_proto.h:25
unsigned char sbit
Definition vcom_proto.h:32
unsigned char dbit
Definition vcom_proto.h:34
unsigned char pair
Definition vcom_proto.h:33
unsigned int p2
Definition vcom_proto.h:5
unsigned int p1
Definition vcom_proto.h:4
unsigned int uint
Definition vcom_proto.h:17
Definition vcom_proto.h:52
struct vc_attach_hflow hflow
Definition vcom_proto.h:58
struct vc_attach_lctrl lctrl
Definition vcom_proto.h:59
struct vc_attach_uint uint32
Definition vcom_proto.h:57
struct vc_attach_param param
Definition vcom_proto.h:55
struct vc_proto_hdr hdr
Definition vcom_proto.h:53
union vc_proto_packet::@0 attach
#define vc_ext_size(a)
Definition vcom_proto.h:50
unsigned int chflow
Definition vcom_proto.h:2
unsigned int p2
Definition vcom_proto.h:1
unsigned int flowrep
Definition vcom_proto.h:3
unsigned short cmd
Definition vcom_proto.h:2
unsigned int tid
Definition vcom_proto.h:1
@ VCOM_IOCTL_GET_MODEMSTATUS
Definition vcom_proto.h:109
@ VCOM_IOCTL_SET_HANDFLOW
Definition vcom_proto.h:108
@ VCOM_IOCTL_SET_WAIT_MASK
Definition vcom_proto.h:100
@ VCOM_IOCTL_SET_DTR
Definition vcom_proto.h:93
@ VCOM_IOCTL_WAIT_ON_MASK
Definition vcom_proto.h:101
@ VCOM_IOCTL_GET_WAIT_MASK
Definition vcom_proto.h:99
@ VCOM_IOCTL_SET_RTS
Definition vcom_proto.h:95
@ VCOM_IOCTL_PURGE
Definition vcom_proto.h:102
@ VCOM_IOCTL_CLR_RTS
Definition vcom_proto.h:96
@ VCOM_IOCTL_CLR_DTR
Definition vcom_proto.h:94
@ VCOM_IOCTL_SET_LINE_CONTROL
Definition vcom_proto.h:87
@ VCOM_IOCTL_SET_BAUD_RATE
Definition vcom_proto.h:86
unsigned char sbit
Definition vcom_proto.h:2
unsigned int p1
Definition vcom_proto.h:0
unsigned char dbit
Definition vcom_proto.h:4
unsigned char pair
Definition vcom_proto.h:3
@ VCOM_CMD_IOCTL
Definition vcom_proto.h:77
unsigned short len
Definition vcom_proto.h:3
#define vc_pack_size(a)
Definition vcom_proto.h:49
int(* do_check)(struct vc_proto_packet *pbuf, int buflen, void *in)
Definition vcom_proto_ioctl.h:43