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
23 #include <netinet/in.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 */
68 struct sockaddr_in src
;
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
84 EIBnet_ConnectRequest ();
85 struct sockaddr_in caddr
;
86 struct sockaddr_in daddr
;
88 EIBNetIPPacket
ToPacket () const;
91 int parseEIBnet_ConnectRequest (const EIBNetIPPacket
& p
,
92 EIBnet_ConnectRequest
& r
);
94 class EIBnet_ConnectResponse
97 EIBnet_ConnectResponse ();
100 struct sockaddr_in daddr
;
102 EIBNetIPPacket
ToPacket () const;
105 int parseEIBnet_ConnectResponse (const EIBNetIPPacket
& p
,
106 EIBnet_ConnectResponse
& r
);
108 class EIBnet_ConnectionStateRequest
111 EIBnet_ConnectionStateRequest ();
114 struct sockaddr_in caddr
;
115 EIBNetIPPacket
ToPacket () const;
118 int parseEIBnet_ConnectionStateRequest (const EIBNetIPPacket
& p
,
119 EIBnet_ConnectionStateRequest
& r
);
121 class EIBnet_ConnectionStateResponse
124 EIBnet_ConnectionStateResponse ();
127 EIBNetIPPacket
ToPacket () const;
130 int parseEIBnet_ConnectionStateResponse (const EIBNetIPPacket
& p
,
131 EIBnet_ConnectionStateResponse
& r
);
133 class EIBnet_DisconnectRequest
136 EIBnet_DisconnectRequest ();
137 struct sockaddr_in caddr
;
139 EIBNetIPPacket
ToPacket () const;
142 int parseEIBnet_DisconnectRequest (const EIBNetIPPacket
& p
,
143 EIBnet_DisconnectRequest
& r
);
145 class EIBnet_DisconnectResponse
148 EIBnet_DisconnectResponse ();
151 EIBNetIPPacket
ToPacket () const;
154 int parseEIBnet_DisconnectResponse (const EIBNetIPPacket
& p
,
155 EIBnet_DisconnectResponse
& r
);
157 class EIBnet_TunnelRequest
160 EIBnet_TunnelRequest ();
164 EIBNetIPPacket
ToPacket () const;
167 int parseEIBnet_TunnelRequest (const EIBNetIPPacket
& p
,
168 EIBnet_TunnelRequest
& r
);
170 class EIBnet_TunnelACK
177 EIBNetIPPacket
ToPacket () const;
180 int parseEIBnet_TunnelACK (const EIBNetIPPacket
& p
, EIBnet_TunnelACK
& r
);
188 class EIBnet_DescriptionRequest
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
202 EIBnet_DescriptionResponse ();
205 eibaddr_t individual_addr
;
207 serialnumber_t serial
;
208 Array
< DIB_service_Entry
> services
;
209 struct in_addr multicastaddr
;
213 EIBNetIPPacket
ToPacket () const;
216 int parseEIBnet_DescriptionResponse (const EIBNetIPPacket
& p
,
217 EIBnet_DescriptionResponse
& r
);
219 class EIBnet_SearchRequest
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
233 EIBnet_SearchResponse ();
236 eibaddr_t individual_addr
;
238 serialnumber_t serial
;
239 Array
< DIB_service_Entry
> services
;
240 struct in_addr multicastaddr
;
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
256 /** destination address */
257 struct sockaddr_in addr
;
260 /** EIBnet/IP socket */
261 class EIBNetIPSocket
:private Thread
266 Queue
< struct _EIBNetIP_Send
>inqueue
;
268 Queue
< EIBNetIPPacket
> outqueue
;
269 /** semaphore for inqueue */
271 /** semaphore for outqueue */
273 /** event to wait for outqueue */
275 /** multicast address */
276 struct ip_mreq maddr
;
277 /** file descriptor */
279 /** multicast in use */
282 void Run (pth_sem_t
* stop
);
284 EIBNetIPSocket (struct sockaddr_in bindaddr
, bool reuseaddr
, Trace
* tr
);
285 virtual ~ EIBNetIPSocket ();
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*/