2 * include/net/tipc/tipc_msg.h: Include file for privileged access to TIPC message headers
4 * Copyright (c) 2003-2006, Ericsson AB
5 * Copyright (c) 2005, Wind River Systems
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the names of the copyright holders 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.
20 * Alternatively, this software may be distributed under the terms of the
21 * GNU General Public License ("GPL") version 2 as published by the Free
22 * Software Foundation.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
37 #ifndef _NET_TIPC_MSG_H_
38 #define _NET_TIPC_MSG_H_
48 TIPC user data message header format, version 2:
51 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
52 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
53 w0:|vers | user |hdr sz |n|d|s|-| message size |
54 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
55 w1:|mstyp| error |rer cnt|lsc|opt p| broadcast ack no |
56 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
57 w2:| link level ack no | broadcast/link level seq no |
58 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
60 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
61 w4:| originating port |
62 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
63 w5:| destination port |
64 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
65 w6:| originating node |
66 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
67 w7:| destination node |
68 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
69 w8:| name type / transport sequence number |
70 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
71 w9:| name instance/multicast lower bound |
72 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
73 wA:| multicast upper bound |
74 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
78 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
82 #define TIPC_CONN_MSG 0
83 #define TIPC_MCAST_MSG 1
84 #define TIPC_NAMED_MSG 2
85 #define TIPC_DIRECT_MSG 3
88 static inline u32 msg_word(struct tipc_msg *m, u32 pos)
90 return ntohl(m->hdr[pos]);
93 static inline u32 msg_bits(struct tipc_msg *m, u32 w, u32 pos, u32 mask)
95 return (msg_word(m, w) >> pos) & mask;
98 static inline u32 msg_importance(struct tipc_msg *m)
100 return msg_bits(m, 0, 25, 0xf);
103 static inline u32 msg_hdr_sz(struct tipc_msg *m)
105 return msg_bits(m, 0, 21, 0xf) << 2;
108 static inline int msg_short(struct tipc_msg *m)
110 return (msg_hdr_sz(m) == 24);
113 static inline u32 msg_size(struct tipc_msg *m)
115 return msg_bits(m, 0, 0, 0x1ffff);
118 static inline u32 msg_data_sz(struct tipc_msg *m)
120 return (msg_size(m) - msg_hdr_sz(m));
123 static inline unchar *msg_data(struct tipc_msg *m)
125 return ((unchar *)m) + msg_hdr_sz(m);
128 static inline u32 msg_type(struct tipc_msg *m)
130 return msg_bits(m, 1, 29, 0x7);
133 static inline u32 msg_named(struct tipc_msg *m)
135 return (msg_type(m) == TIPC_NAMED_MSG);
138 static inline u32 msg_mcast(struct tipc_msg *m)
140 return (msg_type(m) == TIPC_MCAST_MSG);
143 static inline u32 msg_connected(struct tipc_msg *m)
145 return (msg_type(m) == TIPC_CONN_MSG);
148 static inline u32 msg_errcode(struct tipc_msg *m)
150 return msg_bits(m, 1, 25, 0xf);
153 static inline u32 msg_prevnode(struct tipc_msg *m)
155 return msg_word(m, 3);
158 static inline u32 msg_origport(struct tipc_msg *m)
160 return msg_word(m, 4);
163 static inline u32 msg_destport(struct tipc_msg *m)
165 return msg_word(m, 5);
168 static inline u32 msg_mc_netid(struct tipc_msg *m)
170 return msg_word(m, 5);
173 static inline u32 msg_orignode(struct tipc_msg *m)
175 if (likely(msg_short(m)))
176 return msg_prevnode(m);
177 return msg_word(m, 6);
180 static inline u32 msg_destnode(struct tipc_msg *m)
182 return msg_word(m, 7);
185 static inline u32 msg_nametype(struct tipc_msg *m)
187 return msg_word(m, 8);
190 static inline u32 msg_nameinst(struct tipc_msg *m)
192 return msg_word(m, 9);
195 static inline u32 msg_namelower(struct tipc_msg *m)
197 return msg_nameinst(m);
200 static inline u32 msg_nameupper(struct tipc_msg *m)
202 return msg_word(m, 10);