EIBnet/IP: support NAT Support
[bcusdk.git] / eibd / libserver / eibnetip.h
blobcbe0c9e9b1a5f1da26f780242e5d8c03b80ef134
1 /*
2 EIBD eib bus access and management daemon
3 Copyright (C) 2005-2009 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 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #ifndef EIBNETIP_H
21 #define EIBNETIP_H
23 #include <netinet/in.h>
24 #include "common.h"
25 #include "lpdu.h"
27 #define SEARCH_REQUEST 0x0201
28 #define SEARCH_RESPONSE 0x0202
29 #define DESCRIPTION_REQUEST 0x0203
30 #define DESCRIPTION_RESPONSE 0x0204
32 #define CONNECTION_REQUEST 0x0205
33 #define CONNECTION_RESPONSE 0x0206
34 #define CONNECTIONSTATE_REQUEST 0x0207
35 #define CONNECTIONSTATE_RESPONSE 0x0208
36 #define DISCONNECT_REQUEST 0x0209
37 #define DISCONNECT_RESPONSE 0x020A
39 #define TUNNEL_REQUEST 0x0420
40 #define TUNNEL_RESPONSE 0x0421
42 #define DEVICE_CONFIGURATION_REQUEST 0x0310
43 #define DEVICE_CONFIGURATION_RESPONSE 0x0311
45 #define ROUTING_INDICATION 0x0530
47 /** resolve host name */
48 int GetHostIP (struct sockaddr_in *sock, const char *Name);
49 /** gets source address for a route */
50 int GetSourceAddress (const struct sockaddr_in *dest,
51 struct sockaddr_in *src);
52 /** convert a to EIBnet/IP format */
53 CArray IPtoEIBNetIP (const struct sockaddr_in *a);
54 /** convert EIBnet/IP IP Address to a */
55 int EIBnettoIP (const CArray & buf, struct sockaddr_in *a,
56 const struct sockaddr_in *src);
58 /** represents a EIBnet/IP packet */
59 class EIBNetIPPacket
62 public:
63 /** service code*/
64 int service;
65 /** payload */
66 CArray data;
67 /** source address */
68 struct sockaddr_in src;
70 EIBNetIPPacket ();
71 /** create from character array */
72 static EIBNetIPPacket *fromPacket (const CArray & c,
73 const struct sockaddr_in src);
74 /** convert to character array */
75 CArray ToPacket () const;
76 virtual ~ EIBNetIPPacket ()
81 class EIBnet_ConnectRequest
83 public:
84 EIBnet_ConnectRequest ();
85 struct sockaddr_in caddr;
86 struct sockaddr_in daddr;
87 CArray CRI;
88 EIBNetIPPacket ToPacket () const;
91 int parseEIBnet_ConnectRequest (const EIBNetIPPacket & p,
92 EIBnet_ConnectRequest & r);
94 class EIBnet_ConnectResponse
96 public:
97 EIBnet_ConnectResponse ();
98 uchar channel;
99 uchar status;
100 struct sockaddr_in daddr;
101 CArray CRD;
102 EIBNetIPPacket ToPacket () const;
105 int parseEIBnet_ConnectResponse (const EIBNetIPPacket & p,
106 EIBnet_ConnectResponse & r);
108 class EIBnet_ConnectionStateRequest
110 public:
111 EIBnet_ConnectionStateRequest ();
112 uchar channel;
113 uchar status;
114 struct sockaddr_in caddr;
115 EIBNetIPPacket ToPacket () const;
118 int parseEIBnet_ConnectionStateRequest (const EIBNetIPPacket & p,
119 EIBnet_ConnectionStateRequest & r);
121 class EIBnet_ConnectionStateResponse
123 public:
124 EIBnet_ConnectionStateResponse ();
125 uchar channel;
126 uchar status;
127 EIBNetIPPacket ToPacket () const;
130 int parseEIBnet_ConnectionStateResponse (const EIBNetIPPacket & p,
131 EIBnet_ConnectionStateResponse & r);
133 class EIBnet_DisconnectRequest
135 public:
136 EIBnet_DisconnectRequest ();
137 struct sockaddr_in caddr;
138 uchar channel;
139 EIBNetIPPacket ToPacket () const;
142 int parseEIBnet_DisconnectRequest (const EIBNetIPPacket & p,
143 EIBnet_DisconnectRequest & r);
145 class EIBnet_DisconnectResponse
147 public:
148 EIBnet_DisconnectResponse ();
149 uchar channel;
150 uchar status;
151 EIBNetIPPacket ToPacket () const;
154 int parseEIBnet_DisconnectResponse (const EIBNetIPPacket & p,
155 EIBnet_DisconnectResponse & r);
157 class EIBnet_TunnelRequest
159 public:
160 EIBnet_TunnelRequest ();
161 uchar channel;
162 uchar seqno;
163 CArray CEMI;
164 EIBNetIPPacket ToPacket () const;
167 int parseEIBnet_TunnelRequest (const EIBNetIPPacket & p,
168 EIBnet_TunnelRequest & r);
170 class EIBnet_TunnelACK
172 public:
173 EIBnet_TunnelACK ();
174 uchar channel;
175 uchar seqno;
176 uchar status;
177 EIBNetIPPacket ToPacket () const;
180 int parseEIBnet_TunnelACK (const EIBNetIPPacket & p, EIBnet_TunnelACK & r);
182 typedef struct
184 uchar family;
185 uchar version;
186 } DIB_service_Entry;
188 class EIBnet_DescriptionRequest
190 public:
191 EIBnet_DescriptionRequest ();
192 struct sockaddr_in caddr;
193 EIBNetIPPacket ToPacket () const;
196 int parseEIBnet_DescriptionRequest (const EIBNetIPPacket & p,
197 EIBnet_DescriptionRequest & r);
199 class EIBnet_DescriptionResponse
201 public:
202 EIBnet_DescriptionResponse ();
203 uchar KNXmedium;
204 uchar devicestatus;
205 eibaddr_t individual_addr;
206 uint16_t installid;
207 serialnumber_t serial;
208 Array < DIB_service_Entry > services;
209 struct in_addr multicastaddr;
210 uchar MAC[6];
211 uchar name[30];
212 CArray optional;
213 EIBNetIPPacket ToPacket () const;
216 int parseEIBnet_DescriptionResponse (const EIBNetIPPacket & p,
217 EIBnet_DescriptionResponse & r);
219 class EIBnet_SearchRequest
221 public:
222 EIBnet_SearchRequest ();
223 struct sockaddr_in caddr;
224 EIBNetIPPacket ToPacket () const;
227 int parseEIBnet_SearchRequest (const EIBNetIPPacket & p,
228 EIBnet_SearchRequest & r);
230 class EIBnet_SearchResponse
232 public:
233 EIBnet_SearchResponse ();
234 uchar KNXmedium;
235 uchar devicestatus;
236 eibaddr_t individual_addr;
237 uint16_t installid;
238 serialnumber_t serial;
239 Array < DIB_service_Entry > services;
240 struct in_addr multicastaddr;
241 uchar MAC[6];
242 uchar name[30];
243 struct sockaddr_in caddr;
244 EIBNetIPPacket ToPacket () const;
247 int parseEIBnet_SearchResponse (const EIBNetIPPacket & p,
248 EIBnet_SearchResponse & r);
251 /** represents a EIBnet/IP packet to send*/
252 struct _EIBNetIP_Send
254 /** packat */
255 EIBNetIPPacket data;
256 /** destination address */
257 struct sockaddr_in addr;
260 /** EIBnet/IP socket */
261 class EIBNetIPSocket:private Thread
263 /** debug output */
264 Trace *t;
265 /** input queue */
266 Queue < struct _EIBNetIP_Send >inqueue;
267 /** output queue */
268 Queue < EIBNetIPPacket > outqueue;
269 /** semaphore for inqueue */
270 pth_sem_t insignal;
271 /** semaphore for outqueue */
272 pth_sem_t outsignal;
273 /** event to wait for outqueue */
274 pth_event_t getwait;
275 /** multicast address */
276 struct ip_mreq maddr;
277 /** file descriptor */
278 int fd;
279 /** multicast in use */
280 int multicast;
282 void Run (pth_sem_t * stop);
283 public:
284 EIBNetIPSocket (struct sockaddr_in bindaddr, bool reuseaddr, Trace * tr);
285 virtual ~ EIBNetIPSocket ();
286 bool init ();
288 /** enables multicast */
289 bool SetMulticast (struct ip_mreq multicastaddr);
290 /** sends a packet */
291 void Send (EIBNetIPPacket p);
292 /** waits for an packet; aborts if stop occurs */
293 EIBNetIPPacket *Get (pth_event_t stop);
295 /** default send address */
296 struct sockaddr_in sendaddr;
297 /** addres to accept packets from */
298 struct sockaddr_in recvaddr;
299 /** addres to accept packets from */
300 struct sockaddr_in localaddr;
301 /** accept all packets*/
302 uchar recvall;
305 #endif