blob: a5c7ed598fc148c88bc481baa3a84fad71ed35ce [file] [log] [blame]
Per Lidenb97bf3f2006-01-02 19:04:38 +01001/*
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 *
Per Liden9ea1fd32006-01-11 13:30:43 +01009 * Redistribution and use in source and binary forms, with or without
Per Lidenb97bf3f2006-01-02 19:04:38 +010010 * modification, are permitted provided that the following conditions are met:
11 *
Per Liden9ea1fd32006-01-11 13:30:43 +010012 * 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.
Per Lidenb97bf3f2006-01-02 19:04:38 +010020 *
Per Liden9ea1fd32006-01-11 13:30:43 +010021 * 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
Per Lidenb97bf3f2006-01-02 19:04:38 +010035 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#ifndef _NET_TIPC_MSG_H_
39#define _NET_TIPC_MSG_H_
40
41#ifdef __KERNEL__
42
43struct 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
89static inline u32 msg_word(struct tipc_msg *m, u32 pos)
90{
91 return ntohl(m->hdr[pos]);
92}
93
94static 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
99static inline u32 msg_importance(struct tipc_msg *m)
100{
101 return msg_bits(m, 0, 25, 0xf);
102}
103
104static inline u32 msg_hdr_sz(struct tipc_msg *m)
105{
106 return msg_bits(m, 0, 21, 0xf) << 2;
107}
108
109static inline int msg_short(struct tipc_msg *m)
110{
111 return (msg_hdr_sz(m) == 24);
112}
113
114static inline u32 msg_size(struct tipc_msg *m)
115{
116 return msg_bits(m, 0, 0, 0x1ffff);
117}
118
119static inline u32 msg_data_sz(struct tipc_msg *m)
120{
121 return (msg_size(m) - msg_hdr_sz(m));
122}
123
124static inline unchar *msg_data(struct tipc_msg *m)
125{
126 return ((unchar *)m) + msg_hdr_sz(m);
127}
128
129static inline u32 msg_type(struct tipc_msg *m)
130{
131 return msg_bits(m, 1, 29, 0x7);
132}
133
134static inline u32 msg_direct(struct tipc_msg *m)
135{
136 return (msg_type(m) == TIPC_DIRECT_MSG);
137}
138
139static inline u32 msg_named(struct tipc_msg *m)
140{
141 return (msg_type(m) == TIPC_NAMED_MSG);
142}
143
144static inline u32 msg_mcast(struct tipc_msg *m)
145{
146 return (msg_type(m) == TIPC_MCAST_MSG);
147}
148
149static inline u32 msg_connected(struct tipc_msg *m)
150{
151 return (msg_type(m) == TIPC_CONN_MSG);
152}
153
154static inline u32 msg_errcode(struct tipc_msg *m)
155{
156 return msg_bits(m, 1, 25, 0xf);
157}
158
159static inline u32 msg_prevnode(struct tipc_msg *m)
160{
161 return msg_word(m, 3);
162}
163
164static inline u32 msg_origport(struct tipc_msg *m)
165{
166 return msg_word(m, 4);
167}
168
169static inline u32 msg_destport(struct tipc_msg *m)
170{
171 return msg_word(m, 5);
172}
173
174static inline u32 msg_mc_netid(struct tipc_msg *m)
175{
176 return msg_word(m, 5);
177}
178
179static 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
186static inline u32 msg_destnode(struct tipc_msg *m)
187{
188 return msg_word(m, 7);
189}
190
191static inline u32 msg_nametype(struct tipc_msg *m)
192{
193 return msg_word(m, 8);
194}
195
196static inline u32 msg_nameinst(struct tipc_msg *m)
197{
198 return msg_word(m, 9);
199}
200
201static inline u32 msg_namelower(struct tipc_msg *m)
202{
203 return msg_nameinst(m);
204}
205
206static inline u32 msg_nameupper(struct tipc_msg *m)
207{
208 return msg_word(m, 10);
209}
210
211static 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