2 * include/net/tipc/tipc_msg.h: Include file for privileged access to TIPC message headers
4 * Copyright (c) 2003-2005, Ericsson Research Canada
5 * Copyright (c) 2005, Wind River Systems
6 * Copyright (c) 2005-2006, Ericsson AB
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this
13 * list of conditions and the following disclaimer.
14 * Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
17 * Neither the names of the copyright holders nor the names of its
18 * contributors may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
34 #ifndef _NET_TIPC_MSG_H_
35 #define _NET_TIPC_MSG_H_
45 TIPC user data message header format, version 2:
48 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
49 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
50 w0:|vers | user |hdr sz |n|d|s|-| message size |
51 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
52 w1:|mstyp| error |rer cnt|lsc|opt p| broadcast ack no |
53 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
54 w2:| link level ack no | broadcast/link level seq no |
55 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
57 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
58 w4:| originating port |
59 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
60 w5:| destination port |
61 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
62 w6:| originating node |
63 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
64 w7:| destination node |
65 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
66 w8:| name type / transport sequence number |
67 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
68 w9:| name instance/multicast lower bound |
69 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
70 wA:| multicast upper bound |
71 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
75 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
79 #define TIPC_CONN_MSG 0
80 #define TIPC_MCAST_MSG 1
81 #define TIPC_NAMED_MSG 2
82 #define TIPC_DIRECT_MSG 3
85 static inline u32 msg_word(struct tipc_msg *m, u32 pos)
87 return ntohl(m->hdr[pos]);
90 static inline u32 msg_bits(struct tipc_msg *m, u32 w, u32 pos, u32 mask)
92 return (msg_word(m, w) >> pos) & mask;
95 static inline u32 msg_importance(struct tipc_msg *m)
97 return msg_bits(m, 0, 25, 0xf);
100 static inline u32 msg_hdr_sz(struct tipc_msg *m)
102 return msg_bits(m, 0, 21, 0xf) << 2;
105 static inline int msg_short(struct tipc_msg *m)
107 return (msg_hdr_sz(m) == 24);
110 static inline u32 msg_size(struct tipc_msg *m)
112 return msg_bits(m, 0, 0, 0x1ffff);
115 static inline u32 msg_data_sz(struct tipc_msg *m)
117 return (msg_size(m) - msg_hdr_sz(m));
120 static inline unchar *msg_data(struct tipc_msg *m)
122 return ((unchar *)m) + msg_hdr_sz(m);
125 static inline u32 msg_type(struct tipc_msg *m)
127 return msg_bits(m, 1, 29, 0x7);
130 static inline u32 msg_direct(struct tipc_msg *m)
132 return (msg_type(m) == TIPC_DIRECT_MSG);
135 static inline u32 msg_named(struct tipc_msg *m)
137 return (msg_type(m) == TIPC_NAMED_MSG);
140 static inline u32 msg_mcast(struct tipc_msg *m)
142 return (msg_type(m) == TIPC_MCAST_MSG);
145 static inline u32 msg_connected(struct tipc_msg *m)
147 return (msg_type(m) == TIPC_CONN_MSG);
150 static inline u32 msg_errcode(struct tipc_msg *m)
152 return msg_bits(m, 1, 25, 0xf);
155 static inline u32 msg_prevnode(struct tipc_msg *m)
157 return msg_word(m, 3);
160 static inline u32 msg_origport(struct tipc_msg *m)
162 return msg_word(m, 4);
165 static inline u32 msg_destport(struct tipc_msg *m)
167 return msg_word(m, 5);
170 static inline u32 msg_mc_netid(struct tipc_msg *m)
172 return msg_word(m, 5);
175 static inline u32 msg_orignode(struct tipc_msg *m)
177 if (likely(msg_short(m)))
178 return msg_prevnode(m);
179 return msg_word(m, 6);
182 static inline u32 msg_destnode(struct tipc_msg *m)
184 return msg_word(m, 7);
187 static inline u32 msg_nametype(struct tipc_msg *m)
189 return msg_word(m, 8);
192 static inline u32 msg_nameinst(struct tipc_msg *m)
194 return msg_word(m, 9);
197 static inline u32 msg_namelower(struct tipc_msg *m)
199 return msg_nameinst(m);
202 static inline u32 msg_nameupper(struct tipc_msg *m)
204 return msg_word(m, 10);
207 static inline char *msg_options(struct tipc_msg *m, u32 *len)
209 u32 pos = msg_bits(m, 1, 16, 0x7);
213 pos = (pos * 4) + 28;
214 *len = msg_hdr_sz(m) - pos;
215 return (char *)&m->hdr[pos/4];