[TIPC] License header update
[powerpc.git] / include / net / tipc / tipc_msg.h
1 /*
2  * include/net/tipc/tipc_msg.h: Include file for privileged access to TIPC message headers
3  * 
4  * Copyright (c) 2003-2005, Ericsson Research Canada
5  * Copyright (c) 2005, Wind River Systems
6  * Copyright (c) 2005-2006, Ericsson AB
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. Neither the names of the copyright holders nor the names of its
18  *    contributors may be used to endorse or promote products derived from
19  *    this software without specific prior written permission.
20  *
21  * Alternatively, this software may be distributed under the terms of the
22  * GNU General Public License ("GPL") version 2 as published by the Free
23  * Software Foundation.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  */
37
38 #ifndef _NET_TIPC_MSG_H_
39 #define _NET_TIPC_MSG_H_
40
41 #ifdef __KERNEL__
42
43 struct tipc_msg {
44         u32 hdr[15];
45 };
46
47
48 /*
49                 TIPC user data message header format, version 2:
50
51
52        1 0 9 8 7 6 5 4|3 2 1 0 9 8 7 6|5 4 3 2 1 0 9 8|7 6 5 4 3 2 1 0 
53       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
54    w0:|vers | user  |hdr sz |n|d|s|-|          message size           |
55       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
56    w1:|mstyp| error |rer cnt|lsc|opt p|      broadcast ack no         |
57       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
58    w2:|        link level ack no      |   broadcast/link level seq no |
59       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
60    w3:|                       previous node                           |
61       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
62    w4:|                      originating port                         |
63       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
64    w5:|                      destination port                         |
65       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+    
66    w6:|                      originating node                         |
67       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
68    w7:|                      destination node                         |
69       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
70    w8:|            name type / transport sequence number              |
71       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
72    w9:|              name instance/multicast lower bound              |
73       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+    
74    wA:|                    multicast upper bound                      |
75       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+    
76       /                                                               /
77       \                           options                             \
78       /                                                               /
79       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
80
81 */
82
83 #define TIPC_CONN_MSG   0
84 #define TIPC_MCAST_MSG  1
85 #define TIPC_NAMED_MSG  2
86 #define TIPC_DIRECT_MSG 3
87
88
89 static inline u32 msg_word(struct tipc_msg *m, u32 pos)
90 {
91         return ntohl(m->hdr[pos]);
92 }
93
94 static inline u32 msg_bits(struct tipc_msg *m, u32 w, u32 pos, u32 mask)
95 {
96         return (msg_word(m, w) >> pos) & mask;
97 }
98
99 static inline u32 msg_importance(struct tipc_msg *m)
100 {
101         return msg_bits(m, 0, 25, 0xf);
102 }
103
104 static inline u32 msg_hdr_sz(struct tipc_msg *m)
105 {
106         return msg_bits(m, 0, 21, 0xf) << 2;
107 }
108
109 static inline int msg_short(struct tipc_msg *m)
110 {
111         return (msg_hdr_sz(m) == 24);
112 }
113
114 static inline u32 msg_size(struct tipc_msg *m)
115 {
116         return msg_bits(m, 0, 0, 0x1ffff);
117 }
118
119 static inline u32 msg_data_sz(struct tipc_msg *m)
120 {
121         return (msg_size(m) - msg_hdr_sz(m));
122 }
123
124 static inline unchar *msg_data(struct tipc_msg *m)
125 {
126         return ((unchar *)m) + msg_hdr_sz(m);
127 }
128
129 static inline u32 msg_type(struct tipc_msg *m)
130 {
131         return msg_bits(m, 1, 29, 0x7);
132 }
133
134 static inline u32 msg_direct(struct tipc_msg *m)
135 {
136         return (msg_type(m) == TIPC_DIRECT_MSG);
137 }
138
139 static inline u32 msg_named(struct tipc_msg *m)
140 {
141         return (msg_type(m) == TIPC_NAMED_MSG);
142 }
143
144 static inline u32 msg_mcast(struct tipc_msg *m)
145 {
146         return (msg_type(m) == TIPC_MCAST_MSG);
147 }
148
149 static inline u32 msg_connected(struct tipc_msg *m)
150 {
151         return (msg_type(m) == TIPC_CONN_MSG);
152 }
153
154 static inline u32 msg_errcode(struct tipc_msg *m)
155 {
156         return msg_bits(m, 1, 25, 0xf);
157 }
158
159 static inline u32 msg_prevnode(struct tipc_msg *m)
160 {
161         return msg_word(m, 3);
162 }
163
164 static inline u32 msg_origport(struct tipc_msg *m)
165 {
166         return msg_word(m, 4);
167 }
168
169 static inline u32 msg_destport(struct tipc_msg *m)
170 {
171         return msg_word(m, 5);
172 }
173
174 static inline u32 msg_mc_netid(struct tipc_msg *m)
175 {
176         return msg_word(m, 5);
177 }
178
179 static inline u32 msg_orignode(struct tipc_msg *m)
180 {
181         if (likely(msg_short(m)))
182                 return msg_prevnode(m);
183         return msg_word(m, 6);
184 }
185
186 static inline u32 msg_destnode(struct tipc_msg *m)
187 {
188         return msg_word(m, 7);
189 }
190
191 static inline u32 msg_nametype(struct tipc_msg *m)
192 {
193         return msg_word(m, 8);
194 }
195
196 static inline u32 msg_nameinst(struct tipc_msg *m)
197 {
198         return msg_word(m, 9);
199 }
200
201 static inline u32 msg_namelower(struct tipc_msg *m)
202 {
203         return msg_nameinst(m);
204 }
205
206 static inline u32 msg_nameupper(struct tipc_msg *m)
207 {
208         return msg_word(m, 10);
209 }
210
211 static inline char *msg_options(struct tipc_msg *m, u32 *len)
212 {
213         u32 pos = msg_bits(m, 1, 16, 0x7);
214
215         if (!pos)
216                 return 0;
217         pos = (pos * 4) + 28;
218         *len = msg_hdr_sz(m) - pos;
219         return (char *)&m->hdr[pos/4];
220 }
221
222 #endif
223
224 #endif