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
);
57 /** represents a EIBnet/IP packet */
67 struct sockaddr_in src
;
70 /** create from character array */
71 static EIBNetIPPacket
*fromPacket (const CArray
& c
,
72 const struct sockaddr_in src
);
73 /** convert to character array */
74 CArray
ToPacket () const;
75 virtual ~ EIBNetIPPacket ()
80 class EIBnet_ConnectRequest
83 EIBnet_ConnectRequest ();
84 struct sockaddr_in caddr
;
85 struct sockaddr_in daddr
;
87 EIBNetIPPacket
ToPacket () const;
90 int parseEIBnet_ConnectRequest (const EIBNetIPPacket
& p
,
91 EIBnet_ConnectRequest
& r
);
93 class EIBnet_ConnectResponse
96 EIBnet_ConnectResponse ();
99 struct sockaddr_in daddr
;
101 EIBNetIPPacket
ToPacket () const;
104 int parseEIBnet_ConnectResponse (const EIBNetIPPacket
& p
,
105 EIBnet_ConnectResponse
& r
);
107 class EIBnet_ConnectionStateRequest
110 EIBnet_ConnectionStateRequest ();
113 struct sockaddr_in caddr
;
114 EIBNetIPPacket
ToPacket () const;
117 int parseEIBnet_ConnectionStateRequest (const EIBNetIPPacket
& p
,
118 EIBnet_ConnectionStateRequest
& r
);
120 class EIBnet_ConnectionStateResponse
123 EIBnet_ConnectionStateResponse ();
126 EIBNetIPPacket
ToPacket () const;
129 int parseEIBnet_ConnectionStateResponse (const EIBNetIPPacket
& p
,
130 EIBnet_ConnectionStateResponse
& r
);
132 class EIBnet_DisconnectRequest
135 EIBnet_DisconnectRequest ();
136 struct sockaddr_in caddr
;
138 EIBNetIPPacket
ToPacket () const;
141 int parseEIBnet_DisconnectRequest (const EIBNetIPPacket
& p
,
142 EIBnet_DisconnectRequest
& r
);
144 class EIBnet_DisconnectResponse
147 EIBnet_DisconnectResponse ();
150 EIBNetIPPacket
ToPacket () const;
153 int parseEIBnet_DisconnectResponse (const EIBNetIPPacket
& p
,
154 EIBnet_DisconnectResponse
& r
);
156 class EIBnet_TunnelRequest
159 EIBnet_TunnelRequest ();
163 EIBNetIPPacket
ToPacket () const;
166 int parseEIBnet_TunnelRequest (const EIBNetIPPacket
& p
,
167 EIBnet_TunnelRequest
& r
);
169 class EIBnet_TunnelACK
176 EIBNetIPPacket
ToPacket () const;
179 int parseEIBnet_TunnelACK (const EIBNetIPPacket
& p
, EIBnet_TunnelACK
& r
);
187 class EIBnet_DescriptionRequest
190 EIBnet_DescriptionRequest ();
191 struct sockaddr_in caddr
;
192 EIBNetIPPacket
ToPacket () const;
195 int parseEIBnet_DescriptionRequest (const EIBNetIPPacket
& p
,
196 EIBnet_DescriptionRequest
& r
);
198 class EIBnet_DescriptionResponse
201 EIBnet_DescriptionResponse ();
204 eibaddr_t individual_addr
;
206 serialnumber_t serial
;
207 Array
< DIB_service_Entry
> services
;
208 struct in_addr multicastaddr
;
212 EIBNetIPPacket
ToPacket () const;
215 int parseEIBnet_DescriptionResponse (const EIBNetIPPacket
& p
,
216 EIBnet_DescriptionResponse
& r
);
218 class EIBnet_SearchRequest
221 EIBnet_SearchRequest ();
222 struct sockaddr_in caddr
;
223 EIBNetIPPacket
ToPacket () const;
226 int parseEIBnet_SearchRequest (const EIBNetIPPacket
& p
,
227 EIBnet_SearchRequest
& r
);
229 class EIBnet_SearchResponse
232 EIBnet_SearchResponse ();
235 eibaddr_t individual_addr
;
237 serialnumber_t serial
;
238 Array
< DIB_service_Entry
> services
;
239 struct in_addr multicastaddr
;
242 struct sockaddr_in caddr
;
243 EIBNetIPPacket
ToPacket () const;
246 int parseEIBnet_SearchResponse (const EIBNetIPPacket
& p
,
247 EIBnet_SearchResponse
& r
);
250 /** represents a EIBnet/IP packet to send*/
251 struct _EIBNetIP_Send
255 /** destination address */
256 struct sockaddr_in addr
;
259 /** EIBnet/IP socket */
260 class EIBNetIPSocket
:private Thread
265 Queue
< struct _EIBNetIP_Send
>inqueue
;
267 Queue
< EIBNetIPPacket
> outqueue
;
268 /** semaphore for inqueue */
270 /** semaphore for outqueue */
272 /** event to wait for outqueue */
274 /** multicast address */
275 struct ip_mreq maddr
;
276 /** file descriptor */
278 /** multicast in use */
281 void Run (pth_sem_t
* stop
);
283 EIBNetIPSocket (struct sockaddr_in bindaddr
, bool reuseaddr
, Trace
* tr
);
284 virtual ~ EIBNetIPSocket ();
287 /** enables multicast */
288 bool SetMulticast (struct ip_mreq multicastaddr
);
289 /** sends a packet */
290 void Send (EIBNetIPPacket p
);
291 /** waits for an packet; aborts if stop occurs */
292 EIBNetIPPacket
*Get (pth_event_t stop
);
294 /** default send address */
295 struct sockaddr_in sendaddr
;
296 /** addres to accept packets from */
297 struct sockaddr_in recvaddr
;
298 /** addres to accept packets from */
299 struct sockaddr_in localaddr
;
300 /** accept all packets*/