mrpd: comment cleanup
[profile/ivi/OpenAVB.git] / daemons / mrpd / msrp.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 #define MSRP_ETYPE      0x22EA
35 #define MSRP_PROT_VER   0x00
36 #define MSRP_SR_PVID_DEFAULT    2
37
38 /*
39  * PortMediaType = either AccessControlPort (the case for wired) or
40  * Non-DMN shared medium port - we are assuming wired-LAN for this daemon
41  */
42
43 #define MSRP_TALKER_ADV_TYPE    1       /* with AttributeLength = 25 */
44 #define MSRP_TALKER_FAILED_TYPE 2       /* with AttributeLength = 34 */
45 #define MSRP_LISTENER_TYPE      3       /* with AttributeLength = 8 */
46 #define MSRP_DOMAIN_TYPE        4       /* with AttributeLength = 4 */
47
48 /* encodings for the Listener related FourPackedEvents field */
49 #define MSRP_LISTENER_IGNORE    0
50 #define MSRP_LISTENER_ASKFAILED 1
51 #define MSRP_LISTENER_READY     2
52 #define MSRP_LISTENER_READYFAIL 3
53
54 /*
55  * FirstValue structure definition for MSRP Attributes
56  */
57 typedef struct msrpdu_listen {
58         uint8_t StreamID[8];    /* MSB bytes are talker MAC address */
59 } msrpdu_listen_t;
60
61 #if 0
62 typedef struct msrpdu_talker_advertise {
63         uint8_t StreamID[8];
64         struct {
65                 uint8_t Dest_Addr[6];
66                 uint16_t Vlan_ID;
67         } DataFrameParameters;
68         struct {
69                 uint16_t MaxFrameSize;
70                 uint16_t MaxIntervalFrames;
71         } TSpec;
72         uint8_t PriorityAndRank;
73         /*
74          * PriorityAndRank := (3-bit priority | 1 bit rank | 4-bits reserved)
75          * 'rank=0 means emergency traffic, =1 otherwise
76          */
77         unsigned AccumulatedLatency;    /* unsigned 32 bit nsec latency */
78 } msrpdu_talker_advertise_t;
79 #endif
80
81 typedef struct msrpdu_talker_fail {
82         uint8_t StreamID[8];
83         struct {
84                 uint8_t Dest_Addr[6];
85                 uint16_t Vlan_ID;
86         } DataFrameParameters;
87         struct {
88                 uint16_t MaxFrameSize;
89                 uint16_t MaxIntervalFrames;
90         } TSpec;
91         uint8_t PriorityAndRank;
92         unsigned AccumulatedLatency;
93         struct {
94                 uint8_t BridgeID[8];
95                 uint8_t FailureCode;
96         } FailureInformation;
97 } msrpdu_talker_fail_t;
98
99 /* Failure Code definitions */
100
101 #define MSRP_FAIL_BANDWIDTH     1
102 #define MSRP_FAIL_BRIDGE        2
103 #define MSRP_FAIL_TC_BANDWIDTH  3
104 #define MSRP_FAIL_ID_BUSY       4
105 #define MSRP_FAIL_DSTADDR_BUSY  5
106 #define MSRP_FAIL_PREEMPTED     6
107 #define MSRP_FAIL_LATENCY_CHNG  7
108 #define MSRP_FAIL_PORT_NOT_AVB  8
109 #define MSRP_FAIL_DSTADDR_FULL  9
110 #define MSRP_FAIL_MSRP_RESOURCE 10
111 #define MSRP_FAIL_MMRP_RESOURCE 11
112 #define MSRP_FAIL_DSTADDR_FAIL  12
113 #define MSRP_FAIL_PRIO_NOT_SR   13
114 #define MSRP_FAIL_FRAME_SIZE    14
115 #define MSRP_FAIL_FANIN_EXCEED  15
116 #define MSRP_FAIL_STREAM_CHANGE 16
117 #define MSRP_FAIL_VLAN_BLOCKED  17
118 #define MSRP_FAIL_VLAN_DISABLED 18
119 #define MSRP_FAIL_SR_PRIO_ERR   19
120
121 /* Domain Discovery FirstValue definition */
122 typedef struct msrpdu_domain {
123         uint8_t SRclassID;
124         uint8_t SRclassPriority;
125         uint16_t SRclassVID;
126 } msrpdu_domain_t;
127
128 /* Class ID defitions */
129 #define MSRP_SR_CLASS_A 6
130 #define MSRP_SR_CLASS_B 5
131
132 /* default values for class priorities */
133 #define MSRP_SR_CLASS_A_PRIO    3
134 #define MSRP_SR_CLASS_B_PRIO    2
135
136 #define MSRP_DIRECTION_TALKER   0
137 #define MSRP_DIRECTION_LISTENER 1
138
139 struct msrp_attribute {
140         struct msrp_attribute *prev;
141         struct msrp_attribute *next;
142         uint32_t type;
143         union {
144                 msrpdu_talker_fail_t talk_listen;
145                 msrpdu_domain_t domain;
146         } attribute;
147         uint32_t substate;      /*for listener events */
148         uint32_t direction;     /*for listener events */
149         mrp_applicant_attribute_t applicant;
150         mrp_registrar_attribute_t registrar;
151 };
152
153 struct msrp_database {
154         struct mrp_database mrp_db;
155         struct msrp_attribute *attrib_list;
156 };
157
158 int msrp_init(int msrp_enable);
159 int msrp_event(int event, struct msrp_attribute *rattrib);
160 int msrp_recv_cmd(char *buf, int buflen, struct sockaddr_in *client);
161 int msrp_send_notifications(struct msrp_attribute *attrib, int notify);
162 int msrp_reclaim(void);
163 void msrp_bye(struct sockaddr_in *client);
164 int msrp_recv_msg(void);