[TIPC] Update of file headers
[linux-2.6.git] / net / tipc / msg.c
1 /*
2  * net/tipc/msg.c: TIPC message header routines
3  *     
4  * Copyright (c) 2003-2006, Ericsson AB
5  * Copyright (c) 2005, Wind River Systems
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
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.
19  *
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
34  * POSSIBILITY OF SUCH DAMAGE.
35  */
36
37 #include "core.h"
38 #include "addr.h"
39 #include "dbg.h"
40 #include "msg.h"
41 #include "bearer.h"
42
43
44 void msg_set_media_addr(struct tipc_msg *m, struct tipc_media_addr *a)
45 {
46         memcpy(&((int *)m)[5], a, sizeof(*a));
47 }
48
49 void msg_get_media_addr(struct tipc_msg *m, struct tipc_media_addr *a)
50 {
51         memcpy(a, &((int*)m)[5], sizeof(*a));
52 }
53
54
55 void msg_print(struct print_buf *buf, struct tipc_msg *msg, const char *str)
56 {
57         u32 usr = msg_user(msg);
58         tipc_printf(buf, str);
59
60         switch (usr) {
61         case MSG_BUNDLER:
62                 tipc_printf(buf, "BNDL::");
63                 tipc_printf(buf, "MSGS(%u):", msg_msgcnt(msg));
64                 break;
65         case BCAST_PROTOCOL:
66                 tipc_printf(buf, "BCASTP::");
67                 break;
68         case MSG_FRAGMENTER:
69                 tipc_printf(buf, "FRAGM::");
70                 switch (msg_type(msg)) {
71                 case FIRST_FRAGMENT:
72                         tipc_printf(buf, "FIRST:");
73                         break;
74                 case FRAGMENT:
75                         tipc_printf(buf, "BODY:");
76                         break;
77                 case LAST_FRAGMENT:
78                         tipc_printf(buf, "LAST:");
79                         break;
80                 default:
81                         tipc_printf(buf, "UNKNOWN:%x",msg_type(msg));
82
83                 }
84                 tipc_printf(buf, "NO(%u/%u):",msg_long_msgno(msg),
85                             msg_fragm_no(msg));
86                 break;
87         case DATA_LOW:
88         case DATA_MEDIUM:
89         case DATA_HIGH:
90         case DATA_CRITICAL:
91                 tipc_printf(buf, "DAT%u:", msg_user(msg));
92                 if (msg_short(msg)) {
93                         tipc_printf(buf, "CON:");
94                         break;
95                 }
96                 switch (msg_type(msg)) {
97                 case TIPC_CONN_MSG:
98                         tipc_printf(buf, "CON:");
99                         break;
100                 case TIPC_MCAST_MSG:
101                         tipc_printf(buf, "MCST:");
102                         break;
103                 case TIPC_NAMED_MSG:
104                         tipc_printf(buf, "NAM:");
105                         break;
106                 case TIPC_DIRECT_MSG:
107                         tipc_printf(buf, "DIR:");
108                         break;
109                 default:
110                         tipc_printf(buf, "UNKNOWN TYPE %u",msg_type(msg));
111                 }
112                 if (msg_routed(msg) && !msg_non_seq(msg))
113                         tipc_printf(buf, "ROUT:");
114                 if (msg_reroute_cnt(msg))
115                         tipc_printf(buf, "REROUTED(%u):",
116                                     msg_reroute_cnt(msg));
117                 break;
118         case NAME_DISTRIBUTOR:
119                 tipc_printf(buf, "NMD::");
120                 switch (msg_type(msg)) {
121                 case PUBLICATION:
122                         tipc_printf(buf, "PUBL(%u):", (msg_size(msg) - msg_hdr_sz(msg)) / 20);  /* Items */
123                         break;
124                 case WITHDRAWAL:
125                         tipc_printf(buf, "WDRW:");
126                         break;
127                 default:
128                         tipc_printf(buf, "UNKNOWN:%x",msg_type(msg));
129                 }
130                 if (msg_routed(msg))
131                         tipc_printf(buf, "ROUT:");
132                 if (msg_reroute_cnt(msg))
133                         tipc_printf(buf, "REROUTED(%u):",
134                                     msg_reroute_cnt(msg));
135                 break;
136         case CONN_MANAGER:
137                 tipc_printf(buf, "CONN_MNG:");
138                 switch (msg_type(msg)) {
139                 case CONN_PROBE:
140                         tipc_printf(buf, "PROBE:");
141                         break;
142                 case CONN_PROBE_REPLY:
143                         tipc_printf(buf, "PROBE_REPLY:");
144                         break;
145                 case CONN_ACK:
146                         tipc_printf(buf, "CONN_ACK:");
147                         tipc_printf(buf, "ACK(%u):",msg_msgcnt(msg));
148                         break;
149                 default:
150                         tipc_printf(buf, "UNKNOWN TYPE:%x",msg_type(msg));
151                 }
152                 if (msg_routed(msg))
153                         tipc_printf(buf, "ROUT:");
154                 if (msg_reroute_cnt(msg))
155                         tipc_printf(buf, "REROUTED(%u):",msg_reroute_cnt(msg));
156                 break;
157         case LINK_PROTOCOL:
158                 tipc_printf(buf, "PROT:TIM(%u):",msg_timestamp(msg));
159                 switch (msg_type(msg)) {
160                 case STATE_MSG:
161                         tipc_printf(buf, "STATE:");
162                         tipc_printf(buf, "%s:",msg_probe(msg) ? "PRB" :"");
163                         tipc_printf(buf, "NXS(%u):",msg_next_sent(msg));
164                         tipc_printf(buf, "GAP(%u):",msg_seq_gap(msg));
165                         tipc_printf(buf, "LSTBC(%u):",msg_last_bcast(msg));
166                         break;
167                 case RESET_MSG:
168                         tipc_printf(buf, "RESET:");
169                         if (msg_size(msg) != msg_hdr_sz(msg))
170                                 tipc_printf(buf, "BEAR:%s:",msg_data(msg));
171                         break;
172                 case ACTIVATE_MSG:
173                         tipc_printf(buf, "ACTIVATE:");
174                         break;
175                 default:
176                         tipc_printf(buf, "UNKNOWN TYPE:%x",msg_type(msg));
177                 }
178                 tipc_printf(buf, "PLANE(%c):",msg_net_plane(msg));
179                 tipc_printf(buf, "SESS(%u):",msg_session(msg));
180                 break;
181         case CHANGEOVER_PROTOCOL:
182                 tipc_printf(buf, "TUNL:");
183                 switch (msg_type(msg)) {
184                 case DUPLICATE_MSG:
185                         tipc_printf(buf, "DUPL:");
186                         break;
187                 case ORIGINAL_MSG:
188                         tipc_printf(buf, "ORIG:");
189                         tipc_printf(buf, "EXP(%u)",msg_msgcnt(msg));
190                         break;
191                 default:
192                         tipc_printf(buf, "UNKNOWN TYPE:%x",msg_type(msg));
193                 }
194                 break;
195         case ROUTE_DISTRIBUTOR:
196                 tipc_printf(buf, "ROUTING_MNG:");
197                 switch (msg_type(msg)) {
198                 case EXT_ROUTING_TABLE:
199                         tipc_printf(buf, "EXT_TBL:");
200                         tipc_printf(buf, "TO:%x:",msg_remote_node(msg));
201                         break;
202                 case LOCAL_ROUTING_TABLE:
203                         tipc_printf(buf, "LOCAL_TBL:");
204                         tipc_printf(buf, "TO:%x:",msg_remote_node(msg));
205                         break;
206                 case SLAVE_ROUTING_TABLE:
207                         tipc_printf(buf, "DP_TBL:");
208                         tipc_printf(buf, "TO:%x:",msg_remote_node(msg));
209                         break;
210                 case ROUTE_ADDITION:
211                         tipc_printf(buf, "ADD:");
212                         tipc_printf(buf, "TO:%x:",msg_remote_node(msg));
213                         break;
214                 case ROUTE_REMOVAL:
215                         tipc_printf(buf, "REMOVE:");
216                         tipc_printf(buf, "TO:%x:",msg_remote_node(msg));
217                         break;
218                 default:
219                         tipc_printf(buf, "UNKNOWN TYPE:%x",msg_type(msg));
220                 }
221                 break;
222         case LINK_CONFIG:
223                 tipc_printf(buf, "CFG:");
224                 switch (msg_type(msg)) {
225                 case DSC_REQ_MSG:
226                         tipc_printf(buf, "DSC_REQ:");
227                         break;
228                 case DSC_RESP_MSG:
229                         tipc_printf(buf, "DSC_RESP:");
230                         break;
231                 default:
232                         tipc_printf(buf, "UNKNOWN TYPE:%x:",msg_type(msg));
233                         break;
234                 }
235                 break;
236         default:
237                 tipc_printf(buf, "UNKNOWN USER:");
238         }
239
240         switch (usr) {
241         case CONN_MANAGER:
242         case NAME_DISTRIBUTOR:
243         case DATA_LOW:
244         case DATA_MEDIUM:
245         case DATA_HIGH:
246         case DATA_CRITICAL:
247                 if (msg_short(msg))
248                         break;  /* No error */
249                 switch (msg_errcode(msg)) {
250                 case TIPC_OK:
251                         break;
252                 case TIPC_ERR_NO_NAME:
253                         tipc_printf(buf, "NO_NAME:");
254                         break;
255                 case TIPC_ERR_NO_PORT:
256                         tipc_printf(buf, "NO_PORT:");
257                         break;
258                 case TIPC_ERR_NO_NODE:
259                         tipc_printf(buf, "NO_PROC:");
260                         break;
261                 case TIPC_ERR_OVERLOAD:
262                         tipc_printf(buf, "OVERLOAD:");
263                         break;
264                 case TIPC_CONN_SHUTDOWN:
265                         tipc_printf(buf, "SHUTDOWN:");
266                         break;
267                 default:
268                         tipc_printf(buf, "UNKNOWN ERROR(%x):",
269                                     msg_errcode(msg));
270                 }
271         default:{}
272         }
273
274         tipc_printf(buf, "HZ(%u):", msg_hdr_sz(msg));
275         tipc_printf(buf, "SZ(%u):", msg_size(msg));
276         tipc_printf(buf, "SQNO(%u):", msg_seqno(msg));
277
278         if (msg_non_seq(msg))
279                 tipc_printf(buf, "NOSEQ:");
280         else {
281                 tipc_printf(buf, "ACK(%u):", msg_ack(msg));
282         }
283         tipc_printf(buf, "BACK(%u):", msg_bcast_ack(msg));
284         tipc_printf(buf, "PRND(%x)", msg_prevnode(msg));
285
286         if (msg_isdata(msg)) {
287                 if (msg_named(msg)) {
288                         tipc_printf(buf, "NTYP(%u):", msg_nametype(msg));
289                         tipc_printf(buf, "NINST(%u)", msg_nameinst(msg));
290                 }
291         }
292
293         if ((usr != LINK_PROTOCOL) && (usr != LINK_CONFIG) &&
294             (usr != MSG_BUNDLER)) {
295                 if (!msg_short(msg)) {
296                         tipc_printf(buf, ":ORIG(%x:%u):",
297                                     msg_orignode(msg), msg_origport(msg));
298                         tipc_printf(buf, ":DEST(%x:%u):",
299                                     msg_destnode(msg), msg_destport(msg));
300                 } else {
301                         tipc_printf(buf, ":OPRT(%u):", msg_origport(msg));
302                         tipc_printf(buf, ":DPRT(%u):", msg_destport(msg));
303                 }
304                 if (msg_routed(msg) && !msg_non_seq(msg))
305                         tipc_printf(buf, ":TSEQN(%u)", msg_transp_seqno(msg));
306         }
307         if (msg_user(msg) == NAME_DISTRIBUTOR) {
308                 tipc_printf(buf, ":ONOD(%x):", msg_orignode(msg));
309                 tipc_printf(buf, ":DNOD(%x):", msg_destnode(msg));
310                 if (msg_routed(msg)) {
311                         tipc_printf(buf, ":CSEQN(%u)", msg_transp_seqno(msg));
312                 }
313         }
314
315         if (msg_user(msg) ==  LINK_CONFIG) {
316                 u32* raw = (u32*)msg;
317                 struct tipc_media_addr* orig = (struct tipc_media_addr*)&raw[5];
318                 tipc_printf(buf, ":REQL(%u):", msg_req_links(msg));
319                 tipc_printf(buf, ":DDOM(%x):", msg_dest_domain(msg));
320                 tipc_printf(buf, ":NETID(%u):", msg_bc_netid(msg));
321                 media_addr_printf(buf, orig);
322         }
323         if (msg_user(msg) == BCAST_PROTOCOL) {
324                 tipc_printf(buf, "BCNACK:AFTER(%u):", msg_bcgap_after(msg));
325                 tipc_printf(buf, "TO(%u):", msg_bcgap_to(msg));
326         }
327         tipc_printf(buf, "\n");
328         if ((usr == CHANGEOVER_PROTOCOL) && (msg_msgcnt(msg))) {
329                 msg_print(buf,msg_get_wrapped(msg),"      /");
330         }
331         if ((usr == MSG_FRAGMENTER) && (msg_type(msg) == FIRST_FRAGMENT)) {
332                 msg_print(buf,msg_get_wrapped(msg),"      /");
333         }
334 }