| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1 | /* | 
 | 2 |  * include/net/tipc/tipc_msg.h: Include file for privileged access to TIPC message headers | 
 | 3 |  *  | 
| Per Liden | 9da1c8b | 2006-01-11 18:40:41 +0100 | [diff] [blame] | 4 |  * Copyright (c) 2003-2006, Ericsson AB | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 5 |  * Copyright (c) 2005, Wind River Systems | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 6 |  * All rights reserved. | 
 | 7 |  * | 
| Per Liden | 9ea1fd3 | 2006-01-11 13:30:43 +0100 | [diff] [blame] | 8 |  * Redistribution and use in source and binary forms, with or without | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 9 |  * modification, are permitted provided that the following conditions are met: | 
 | 10 |  * | 
| Per Liden | 9ea1fd3 | 2006-01-11 13:30:43 +0100 | [diff] [blame] | 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. | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 19 |  * | 
| Per Liden | 9ea1fd3 | 2006-01-11 13:30:43 +0100 | [diff] [blame] | 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. | 
 | 23 |  * | 
 | 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 | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 34 |  * POSSIBILITY OF SUCH DAMAGE. | 
 | 35 |  */ | 
 | 36 |  | 
 | 37 | #ifndef _NET_TIPC_MSG_H_ | 
 | 38 | #define _NET_TIPC_MSG_H_ | 
 | 39 |  | 
 | 40 | #ifdef __KERNEL__ | 
 | 41 |  | 
 | 42 | struct tipc_msg { | 
| Al Viro | 3e6c8cd | 2006-11-08 00:19:09 -0800 | [diff] [blame] | 43 | 	__be32 hdr[15]; | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 44 | }; | 
 | 45 |  | 
 | 46 |  | 
 | 47 | /* | 
 | 48 | 		TIPC user data message header format, version 2: | 
 | 49 |  | 
 | 50 |  | 
 | 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 |       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 
 | 59 |    w3:|                       previous node                           | | 
 | 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 |       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+     | 
 | 75 |       /                                                               / | 
 | 76 |       \                           options                             \ | 
 | 77 |       /                                                               / | 
 | 78 |       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 
 | 79 |  | 
 | 80 | */ | 
 | 81 |  | 
 | 82 | #define TIPC_CONN_MSG	0 | 
 | 83 | #define TIPC_MCAST_MSG	1 | 
 | 84 | #define TIPC_NAMED_MSG	2 | 
 | 85 | #define TIPC_DIRECT_MSG	3 | 
 | 86 |  | 
 | 87 |  | 
 | 88 | static inline u32 msg_word(struct tipc_msg *m, u32 pos) | 
 | 89 | { | 
 | 90 | 	return ntohl(m->hdr[pos]); | 
 | 91 | } | 
 | 92 |  | 
 | 93 | static inline u32 msg_bits(struct tipc_msg *m, u32 w, u32 pos, u32 mask) | 
 | 94 | { | 
 | 95 | 	return (msg_word(m, w) >> pos) & mask; | 
 | 96 | } | 
 | 97 |  | 
 | 98 | static inline u32 msg_importance(struct tipc_msg *m) | 
 | 99 | { | 
 | 100 | 	return msg_bits(m, 0, 25, 0xf); | 
 | 101 | } | 
 | 102 |  | 
 | 103 | static inline u32 msg_hdr_sz(struct tipc_msg *m) | 
 | 104 | { | 
 | 105 | 	return msg_bits(m, 0, 21, 0xf) << 2; | 
 | 106 | } | 
 | 107 |  | 
 | 108 | static inline int msg_short(struct tipc_msg *m) | 
 | 109 | { | 
 | 110 | 	return (msg_hdr_sz(m) == 24); | 
 | 111 | } | 
 | 112 |  | 
 | 113 | static inline u32 msg_size(struct tipc_msg *m) | 
 | 114 | { | 
 | 115 | 	return msg_bits(m, 0, 0, 0x1ffff); | 
 | 116 | } | 
 | 117 |  | 
 | 118 | static inline u32 msg_data_sz(struct tipc_msg *m) | 
 | 119 | { | 
 | 120 | 	return (msg_size(m) - msg_hdr_sz(m)); | 
 | 121 | } | 
 | 122 |  | 
 | 123 | static inline unchar *msg_data(struct tipc_msg *m) | 
 | 124 | { | 
 | 125 | 	return ((unchar *)m) + msg_hdr_sz(m); | 
 | 126 | } | 
 | 127 |  | 
 | 128 | static inline u32 msg_type(struct tipc_msg *m) | 
 | 129 | { | 
 | 130 | 	return msg_bits(m, 1, 29, 0x7); | 
 | 131 | } | 
 | 132 |  | 
 | 133 | static inline u32 msg_direct(struct tipc_msg *m) | 
 | 134 | { | 
 | 135 | 	return (msg_type(m) == TIPC_DIRECT_MSG); | 
 | 136 | } | 
 | 137 |  | 
 | 138 | static inline u32 msg_named(struct tipc_msg *m) | 
 | 139 | { | 
 | 140 | 	return (msg_type(m) == TIPC_NAMED_MSG); | 
 | 141 | } | 
 | 142 |  | 
 | 143 | static inline u32 msg_mcast(struct tipc_msg *m) | 
 | 144 | { | 
 | 145 | 	return (msg_type(m) == TIPC_MCAST_MSG); | 
 | 146 | } | 
 | 147 |  | 
 | 148 | static inline u32 msg_connected(struct tipc_msg *m) | 
 | 149 | { | 
 | 150 | 	return (msg_type(m) == TIPC_CONN_MSG); | 
 | 151 | } | 
 | 152 |  | 
 | 153 | static inline u32 msg_errcode(struct tipc_msg *m) | 
 | 154 | { | 
 | 155 | 	return msg_bits(m, 1, 25, 0xf); | 
 | 156 | } | 
 | 157 |  | 
 | 158 | static inline u32 msg_prevnode(struct tipc_msg *m) | 
 | 159 | { | 
 | 160 | 	return msg_word(m, 3); | 
 | 161 | } | 
 | 162 |  | 
 | 163 | static inline u32 msg_origport(struct tipc_msg *m) | 
 | 164 | { | 
 | 165 | 	return msg_word(m, 4); | 
 | 166 | } | 
 | 167 |  | 
 | 168 | static inline u32 msg_destport(struct tipc_msg *m) | 
 | 169 | { | 
 | 170 | 	return msg_word(m, 5); | 
 | 171 | } | 
 | 172 |  | 
 | 173 | static inline u32 msg_mc_netid(struct tipc_msg *m) | 
 | 174 | { | 
 | 175 | 	return msg_word(m, 5); | 
 | 176 | } | 
 | 177 |  | 
 | 178 | static inline u32 msg_orignode(struct tipc_msg *m) | 
 | 179 | { | 
 | 180 | 	if (likely(msg_short(m))) | 
 | 181 | 		return msg_prevnode(m); | 
 | 182 | 	return msg_word(m, 6); | 
 | 183 | } | 
 | 184 |  | 
 | 185 | static inline u32 msg_destnode(struct tipc_msg *m) | 
 | 186 | { | 
 | 187 | 	return msg_word(m, 7); | 
 | 188 | } | 
 | 189 |  | 
 | 190 | static inline u32 msg_nametype(struct tipc_msg *m) | 
 | 191 | { | 
 | 192 | 	return msg_word(m, 8); | 
 | 193 | } | 
 | 194 |  | 
 | 195 | static inline u32 msg_nameinst(struct tipc_msg *m) | 
 | 196 | { | 
 | 197 | 	return msg_word(m, 9); | 
 | 198 | } | 
 | 199 |  | 
 | 200 | static inline u32 msg_namelower(struct tipc_msg *m) | 
 | 201 | { | 
 | 202 | 	return msg_nameinst(m); | 
 | 203 | } | 
 | 204 |  | 
 | 205 | static inline u32 msg_nameupper(struct tipc_msg *m) | 
 | 206 | { | 
 | 207 | 	return msg_word(m, 10); | 
 | 208 | } | 
 | 209 |  | 
 | 210 | static inline char *msg_options(struct tipc_msg *m, u32 *len) | 
 | 211 | { | 
 | 212 | 	u32 pos = msg_bits(m, 1, 16, 0x7); | 
 | 213 |  | 
 | 214 | 	if (!pos) | 
 | 215 | 		return 0; | 
 | 216 | 	pos = (pos * 4) + 28; | 
 | 217 | 	*len = msg_hdr_sz(m) - pos; | 
 | 218 | 	return (char *)&m->hdr[pos/4]; | 
 | 219 | } | 
 | 220 |  | 
 | 221 | #endif | 
 | 222 |  | 
 | 223 | #endif |