VCOM Linux Driver
Advantech Inc.
Loading...
Searching...
No Matches
vcom_proto_cmd.h
Go to the documentation of this file.
1#ifndef __VCOM_PROTO_CMD_H
2#define __VCOM_PROTO_CMD_H
3
4static inline int vc_pack_qfsize(struct vc_proto_packet * pbuf, unsigned int tid,
5 int fsize, int buflen)
6{
7 unsigned short len;
8 unsigned int p1;
9 unsigned int p2;
10 unsigned int cmd;
11 int plen;
12
14 plen = vc_pack_size(pbuf->attach.param);
15 len = vc_ext_size(pbuf->attach.param);
16
17 if(plen > buflen ){
18 printf("%s(%d) wrong length\n", __func__, __LINE__);
19 return 0;
20 }
21
22 vc_init_hdr(&pbuf->hdr, tid, cmd, len);
23
24 p1 = 0;
25 p2 = (unsigned int)fsize;
26
27 pbuf->attach.param.p1 = htonl(p1);
28 pbuf->attach.param.p2 = htonl(p2);
29
30 return plen;
31}
32
33static inline int vc_pack_close(struct vc_proto_packet * pbuf, unsigned int tid, int buflen)
34{
35 unsigned short len;
36 unsigned int p1;
37 unsigned int p2;
38 unsigned int cmd;
39 int plen;
40
42 plen = vc_pack_size(pbuf->attach.param);
43 len = vc_ext_size(pbuf->attach.param);
44
45 if(plen > buflen ){
46 printf("%s(%d) wrong length\n", __func__, __LINE__);
47 return 0;
48 }
49
50 vc_init_hdr(&pbuf->hdr, tid, cmd, len);
51
52 p1 = 0;
53 p2 = 0;
54
55 pbuf->attach.param.p1 = htonl(p1);
56 pbuf->attach.param.p2 = htonl(p2);
57
58 return plen;
59}
60
61static inline int vc_pack_xmit(struct vc_proto_packet * pbuf, unsigned int tid,
62 int datalen, char *data, int buflen)
63{
64 unsigned short len;
65 unsigned int p1;
66 unsigned int p2;
67 unsigned int cmd;
68 int plen;
69
71 plen = vc_pack_size(pbuf->attach.param) + datalen;
72 len = (unsigned short)datalen;
73
74 if(plen > buflen ){
75 printf("%s(%d) wrong length\n", __func__, __LINE__);
76 return 0;
77 }
78
79 vc_init_hdr(&pbuf->hdr, tid, cmd, len);
80
81 p1 = (unsigned int)datalen;
82 p2 = 0;
83
84 pbuf->attach.param.p1 = htonl(p1);
85 pbuf->attach.param.p2 = htonl(p2);
86
87 if(data > 0){
88 memcpy(pbuf->attach.data.ptr, data, datalen);
89 }
90
91 return plen;
92}
93
94static inline int vc_check_xmit(struct vc_proto_packet *pbuf, int datalen,
95 unsigned int stat, int buflen)
96{
97 unsigned short len;
98 unsigned int p1;
99 unsigned int p2;
100 unsigned int cmd;
101 int plen;
102
104 plen = vc_pack_size(pbuf->attach.param);
105 len = vc_ext_size(pbuf->attach.param);
106
107// p1 = STATUS_SUCCESS;
108 p1 = stat;
109 p2 = datalen;
110
111 if(plen > buflen ){
112 printf("%s(%d) wrong length\n", __func__, __LINE__);
113 return -1;
114 }
115 if(vc_check_hdr(&pbuf->hdr, cmd, len)){
116 printf("%s(%d)\n", __func__, __LINE__);
117 return -1;
118 }
119
120 if(pbuf->attach.param.p1 != htonl(p1)){
121 printf("%s(%d)\n", __func__, __LINE__);
122 return -1;
123 }
124
125 if(pbuf->attach.param.p2 != htonl(p2)){
126 printf("%s(%d)\n", __func__, __LINE__);
127 return -1;
128 }
129
130
131 return 0;
132}
133
134static inline int vc_check_recv(struct vc_proto_packet *pbuf, int *datalen, int buflen)
135{
136 int alen;
137 int plen;
138 int status;
139
140 plen = (int)ntohs(pbuf->hdr.len);
141 status = (int)ntohl(pbuf->attach.data.p1);
142 alen = (int)ntohl(pbuf->attach.data.p2);
143
144 if(status != STATUS_SUCCESS){
145 printf("%s(%d)\n", __func__, __LINE__);
146 return -1;
147 }
148 if(plen != alen){
149 printf("%s(%d)\n", __func__, __LINE__);
150 return -1;
151 }
152
153 *datalen = alen;
154
155 return 0;
156}
157
158
159static inline int vc_pack_open(struct vc_proto_packet * pbuf, unsigned int tid,
160 unsigned short dev, unsigned int port, int buflen)
161{
162 unsigned short len;
163 unsigned int p1;
164 unsigned int p2;
165 unsigned int cmd;
166 int plen;
167
169 plen = vc_pack_size(pbuf->attach.param);
170 len = vc_ext_size(pbuf->attach.param);
171
172 if(plen > buflen ){
173 printf("%s(%d) wrong length\n", __func__, __LINE__);
174 return 0;
175 }
176
177 vc_init_hdr(&pbuf->hdr, tid, cmd, len);
178
179 p1 = dev;
180 p1 = p1 << 16;
181 p2 = port;
182
183 pbuf->attach.param.p1 = htonl(p1);
184 pbuf->attach.param.p2 = htonl(p2);
185
186 return plen;
187}
188
189static inline int vc_check_open(struct vc_proto_packet * pbuf,
190 unsigned short dev, unsigned int port, int buflen)
191{
192 unsigned short len;
193 unsigned int p1;
194 unsigned int p2;
195 unsigned int cmd;
196 int plen;
197
199 plen = vc_pack_size(pbuf->attach.param);
200 len = vc_ext_size(pbuf->attach.param);
201
203 p2 = port;
204
205 if(plen > buflen ){
206 printf("%s(%d) wrong length\n", __func__, __LINE__);
207 return -1;
208 }
209 if(vc_check_hdr(&pbuf->hdr, cmd, len)){
210 printf("%s(%d)\n", __func__, __LINE__);
211 return -1;
212 }
213
214 if(pbuf->attach.param.p1 != htonl(p1)){
215 printf("%s(%d)\n", __func__, __LINE__);
216 return -1;
217 }
218
219 if(pbuf->attach.param.p2 != htonl(p2)){
220 printf("%s(%d)\n", __func__, __LINE__);
221 return -1;
222 }
223
224 return 0;
225}
226
227#endif
unsigned int p2
Definition vcom_proto.h:10
unsigned int p1
Definition vcom_proto.h:9
char ptr[4]
Definition vcom_proto.h:11
unsigned int p2
Definition vcom_proto.h:5
unsigned int p1
Definition vcom_proto.h:4
unsigned short len
Definition vcom_proto.h:45
Definition vcom_proto.h:52
struct vc_attach_data data
Definition vcom_proto.h:56
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
struct vc_attach_data data
Definition vcom_proto.h:3
unsigned int p2
Definition vcom_proto.h:1
unsigned short cmd
Definition vcom_proto.h:2
unsigned int tid
Definition vcom_proto.h:1
unsigned int p1
Definition vcom_proto.h:0
@ VCOM_CMD_CLOSE
Definition vcom_proto.h:75
@ VCOM_CMD_QUEUEFREE
Definition vcom_proto.h:79
@ VCOM_CMD_WRITE
Definition vcom_proto.h:76
@ VCOM_CMD_CREATE
Definition vcom_proto.h:74
@ STATUS_SUCCESS
Definition vcom_proto.h:67
unsigned short len
Definition vcom_proto.h:3
#define vc_pack_size(a)
Definition vcom_proto.h:49