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