2 EIBD client library - internals
3 Copyright (C) 2005-2007 Martin Koegler <mkoegler@auto.tuwien.ac.at>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 In addition to the permissions in the GNU General Public License,
11 you may link the compiled version of this file into combinations
12 with other programs, and distribute those combinations without any
13 restriction coming from the use of this file. (The General Public
14 License restrictions do apply in other respects; for example, they
15 cover modification of the file, and distribution when not linked into
16 a combine executable.)
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #ifndef EIBCLIENT_INT_H
29 #define EIBCLIENT_INT_H
39 typedef uint8_t uchar
;
41 /** EIB Connection internal */
44 int (*complete
) (EIBConnection
*);
45 /** file descriptor */
67 /** extracts TYPE code of an eibd packet */
68 #define EIBTYPE(con) (((con)->buf[0]<<8)|((con)->buf[1]))
69 /** sets TYPE code for an eibd packet*/
70 #define EIBSETTYPE(buf,type) do{(buf)[0]=(type>>8)&0xff;(buf)[1]=(type)&0xff;}while(0)
72 /** set EIB address */
73 #define EIBSETADDR(buf,type) do{(buf)[0]=(type>>8)&0xff;(buf)[1]=(type)&0xff;}while(0)
75 int _EIB_SendRequest (EIBConnection
* con
, unsigned int size
, uchar
* data
);
76 int _EIB_CheckRequest (EIBConnection
* con
, int block
);
77 int _EIB_GetRequest (EIBConnection
* con
);
79 #define EIBC_GETREQUEST \
81 i = _EIB_GetRequest (con); \
85 #define EIBC_RETURNERROR(msg, error) \
86 if (EIBTYPE (con) == msg) \
92 #define EIBC_RETURNERROR_UINT16(offset, error) \
93 if (!con->buf[offset] && !con->buf[offset+1]) \
99 #define EIBC_RETURNERROR_SIZE(length, error) \
100 if (con->size <= length) \
106 #define EIBC_CHECKRESULT(msg, msgsize) \
107 if (EIBTYPE (con) != msg || con->size < msgsize) \
109 errno = ECONNRESET; \
113 #define EIBC_RETURN_BUF(offset) \
114 i = con->size - offset; \
115 if (i > con->req.len) \
117 memcpy (con->req.buf, con->buf + offset, i); \
120 #define EIBC_RETURN_OK \
123 #define EIBC_RETURN_LEN \
126 #define EIBC_RETURN_UINT8(offset) \
127 return con->buf[offset];
129 #define EIBC_RETURN_UINT16(offset) \
130 return (con->buf[offset] << 8) | (con->buf[offset+1]);
132 #define EIBC_RETURN_PTR1(offset) \
134 *con->req.ptr1 = (con->buf[offset] << 8) | (con->buf[offset+1]);
136 #define EIBC_RETURN_PTR2(offset) \
138 *con->req.ptr2 = con->buf[offset];
140 #define EIBC_RETURN_PTR3(offset) \
142 *con->req.ptr3 = con->buf[offset];
144 #define EIBC_RETURN_PTR4(offset) \
146 *con->req.ptr4 = (con->buf[offset] << 8) | (con->buf[offset+1]);
148 #define EIBC_RETURN_PTR5(offset) \
150 *con->req.ptr5 = (con->buf[offset] << 8) | (con->buf[offset+1]);
152 #define EIBC_RETURN_PTR6(offset) \
154 *con->req.ptr6 = (con->buf[offset] << 8) | (con->buf[offset+1]);
156 #define EIBC_COMPLETE(name, body) \
158 name ## _complete (EIBConnection * con) \
163 #define EIBC_INIT_COMPLETE(name) \
164 con->complete = name ## _complete; \
167 #define EIBC_INIT_SEND(length) \
168 uchar head[length]; \
169 uchar *ibuf = head; \
170 unsigned int ilen = length; \
179 #define EIBC_SEND_BUF(name) EIBC_SEND_BUF_LEN (name, 0)
181 #define EIBC_SEND_BUF_LEN(name, length) \
182 if (!name || name ## _len < length) \
187 con->req.len = name ## _len; \
189 ibuf = (uchar *) malloc (ilen + name ## _len); \
195 memcpy (ibuf, head, ilen); \
196 memcpy (ibuf + ilen, name, name ## _len); \
197 ilen = ilen + name ## _len;
199 #define EIBC_SEND_LEN(name) (name ## _len)
201 #define EIBC_SEND(msg) \
202 EIBSETTYPE (ibuf, msg); \
203 i = _EIB_SendRequest (con, ilen, ibuf); \
209 #define EIBC_READ_BUF(buffer) \
210 if (!buffer || buffer ## _maxlen < 0) \
217 con->req.buf = buffer; \
218 con->req.len = buffer ## _maxlen;
220 #define EIBC_READ_LEN(buffer) (buffer ## _maxlen)
222 #define EIBC_PTR1(name) \
223 con->req.ptr1 = name;
225 #define EIBC_PTR2(name) \
226 con->req.ptr2 = name;
228 #define EIBC_PTR3(name) \
229 con->req.ptr3 = name;
231 #define EIBC_PTR4(name) \
232 con->req.ptr4 = name;
234 #define EIBC_PTR5(name) \
235 con->req.ptr5 = name;
237 #define EIBC_PTR6(name) \
238 con->req.ptr6 = name;
240 #define EIBC_SETADDR(name, offset) \
241 EIBSETADDR (ibuf + offset, name);
243 #define EIBC_SETUINT8(value, offset) \
244 ibuf[offset] = value;
246 #define EIBC_SETUINT16(value, offset) \
247 ibuf[offset] = ((value) >> 8) & 0xff; \
248 ibuf[offset + 1] = ((value)) & 0xff;
250 #define EIBC_SETBOOL(value, offset) \
251 ibuf[offset] = ((value) ? 0xff : 0);
253 #define EIBC_SETKEY(value, offset) \
254 memcpy (ibuf + offset, value, 4);
256 #define EIBC_ASYNC(name, args, body) \
258 name ##_async (EIBConnection * con AG##args) \
264 name (EIBConnection * con AG##args) \
266 if (name ## _async (con AL##args) == -1) \
268 return EIBComplete (con); \
272 #define AGARG_BOOL(name, args) , int name AG##args
273 #define AGARG_UINT8(name, args) , uint8_t name AG##args
274 #define AGARG_UINT8a(name, args) , uint8_t name AG##args
275 #define AGARG_UINT8b(name, args) , uint8_t name AG##args
276 #define AGARG_UINT16(name, args) , uint16_t name AG##args
277 #define AGARG_ADDR(name, args) , eibaddr_t name AG##args
278 #define AGARG_INBUF(name, args) , int name##_len, const uint8_t *name AG##args
279 #define AGARG_OUTBUF(name, args) , int name##_maxlen, uint8_t *name AG##args
282 #define ALARG_BOOL(name, args) , name AL##args
283 #define ALARG_UINT8(name, args) , name AL##args
284 #define ALARG_UINT8a(name, args) , name AL##args
285 #define ALARG_UINT8b(name, args) , name AL##args
286 #define ALARG_UINT16(name, args) , name AL##args
287 #define ALARG_ADDR(name, args) , name AL##args
288 #define ALARG_INBUF(name, args) , name##_len, name AL##args
289 #define ALARG_OUTBUF(name, args) , name##_maxlen, name AL##args