mrpd: comment cleanup
[profile/ivi/OpenAVB.git] / daemons / mrpd / mrpd.h
1 /******************************************************************************
2
3   Copyright (c) 2012, Intel Corporation 
4   All rights reserved.
5   
6   Redistribution and use in source and binary forms, with or without 
7   modification, are permitted provided that the following conditions are met:
8   
9    1. Redistributions of source code must retain the above copyright notice, 
10       this list of conditions and the following disclaimer.
11   
12    2. Redistributions in binary form must reproduce the above copyright 
13       notice, this list of conditions and the following disclaimer in the 
14       documentation and/or other materials provided with the distribution.
15   
16    3. Neither the name of the Intel Corporation nor the names of its 
17       contributors may be used to endorse or promote products derived from 
18       this software without specific prior written permission.
19   
20   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
22   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
23   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
24   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
25   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
26   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
27   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
28   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
29   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   POSSIBILITY OF SUCH DAMAGE.
31
32 ******************************************************************************/
33 /*
34  * an endpoint implementation of 802.1Q-2011 MRP (MMRP, MVRP, MSRP)
35  */
36
37 /* Operating specific defines */
38 #if defined WIN32
39 #include <winsock2.h>
40 typedef int socklen_t;
41 typedef void *HTIMER;
42 #define snprintf _snprintf
43 #define random rand
44 size_t mrpd_send(SOCKET sockfd, const void *buf, size_t len, int flags);
45 #elif defined __linux__
46 #include <unistd.h>
47 #include <sys/socket.h>
48 #include <netinet/in.h>
49 #include <arpa/inet.h>
50 typedef int SOCKET;
51 typedef int HTIMER;
52 #define INVALID_SOCKET -1
53 #define SOCKET_ERROR   -1
54 #define closesocket(s) close(s);
55 #define mrpd_send send
56 #endif
57
58 #ifdef __cplusplus
59 #define __STDC_CONSTANT_MACROS
60 #ifdef _STDINT_H
61 #undef _STDINT_H
62 #endif
63 #endif
64
65 #include <stdint.h>             // for uint8_t etc
66
67 typedef struct eth_hdr {
68         uint8_t destaddr[6];
69         uint8_t srcaddr[6];
70         uint16_t typelen;
71 } eth_hdr_t;
72
73 /*
74  * NumberOfValues is the number of EVENTS encoded in the various 
75  * 3/4 PACK Bytes.  Non-multiples of (3) [ for 3-packed ] or (4) 
76  * [ for 4-packed ] indicates the trailing events are transmitted 
77  * as -0- and should be ignored (and NOT interpreted as an ENDMARK)
78  * A value of -0- indicates there are no events to report (a NULL).
79  *
80  * furthermore, the events are 'vector' operations - the first encoded event
81  * operates on the (FirstEvent) attribute, the second encoded event
82  * operates on the (FirstEvent+1) attribute, and so forth.
83  */
84 typedef struct mrpdu_message {
85         uint8_t AttributeType;
86         uint8_t AttributeLength;        /* length of FirstValue */
87         uint8_t      Data[0];
88         /*
89          * parsing of the data field is application specific - either
90          * a ushort with an attribute list length followed by vector
91          * attributes, or just a list of vector attributes ...
92          */
93
94         /* table should have a trailing NULL (0x0000) indicating the ENDMARK */
95 } mrpdu_message_t;
96
97 typedef struct mrpdu {
98         uint8_t ProtocolVersion;
99         /* Microsoft does not support embedded arrays of 0 length
100          * mrpdu_message_t      MessageList[];
101          * mrpdu should have trailing NULL (0x0000) indicating the ENDMARK */
102 } mrpdu_t;
103
104 #define MRPD_GET_MRPDU_MESSAGE_LIST(a) ((unsigned char *)&((a)->ProtocolVersion) + 1)
105 #define MRPD_OFFSETOF_MRPD_GET_MRPDU_MESSAGE_LIST (1)
106
107 #define MAX_FRAME_SIZE          2000
108 #define MRPD_PORT_DEFAULT       7500
109 #define MAX_MRPD_CMDSZ          (1500)
110
111 /* forward declare */
112 struct mrp_database;
113
114 int mrpd_init_timers(struct mrp_database *mrp_db);
115 int mrpd_timer_start(HTIMER timerfd, unsigned long value_ms);
116 int mrpd_timer_stop(HTIMER timerfd);
117 int mrpd_send_ctl_msg(struct sockaddr_in *client_addr, char *notify_data,
118                       int notify_len);
119 int mrpd_init_protocol_socket(uint16_t etype, SOCKET * sock,
120                               unsigned char *multicast_addr);
121 int mrpd_close_socket(SOCKET sock);
122 int mrpd_recvmsgbuf(SOCKET sock, char **buf);