Home | History | Annotate | Line # | Download | only in common
      1 /*	$NetBSD: rc.c,v 1.8 2016/06/08 01:11:49 christos Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1993-95 Mats O Jansson.  All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  *
     15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25  */
     26 
     27 #include "port.h"
     28 #ifndef lint
     29 __RCSID("$NetBSD: rc.c,v 1.8 2016/06/08 01:11:49 christos Exp $");
     30 #endif
     31 
     32 #include "os.h"
     33 #include "get.h"
     34 #include "mopdef.h"
     35 #include "print.h"
     36 #include "rc.h"
     37 
     38 void
     39 mopDumpRC(FILE *fd, const u_char *pkt, int trans)
     40 {
     41 	int	i,idx = 0;
     42 	int32_t	tmpl;
     43 	u_char	tmpc,code,control;
     44 	u_short	len,tmps,moplen;
     45 
     46 	len = mopGetLength(pkt, trans);
     47 
     48 	switch (trans) {
     49 	case TRANS_8023:
     50 		idx = 22;
     51 		moplen = len - 8;
     52 		break;
     53 	default:
     54 		idx = 16;
     55 		moplen = len;
     56 	}
     57 	code = mopGetChar(pkt,&idx);
     58 
     59 	switch (code) {
     60 	case MOP_K_CODE_RID:
     61 
     62 		tmpc = mopGetChar(pkt,&idx);
     63 		(void)fprintf(fd,"Reserved     :   %02x\n",tmpc);
     64 
     65 		tmps = mopGetShort(pkt,&idx);
     66 		(void)fprintf(fd,"Receipt Nbr  : %04x\n",tmps);
     67 
     68 		break;
     69 	case MOP_K_CODE_BOT:
     70 
     71 		if (moplen == 5) {
     72 			tmps = mopGetShort(pkt,&idx);
     73 			(void)fprintf(fd,"Verification : %04x\n",tmps);
     74 		} else {
     75 
     76 			tmpl = mopGetLong(pkt,&idx);
     77 			(void)fprintf(fd,"Verification : %08x\n",tmpl);
     78 
     79 			tmpc = mopGetChar(pkt,&idx);	/* Processor */
     80 			(void)fprintf(fd,"Processor    :   %02x ",tmpc);
     81 			mopPrintBPTY(fd, tmpc);  (void)fprintf(fd, "\n");
     82 
     83 			control = mopGetChar(pkt,&idx);	/* Control */
     84 			(void)fprintf(fd,"Control    :   %02x ",control);
     85 			if ((control & (1>>MOP_K_BOT_CNTL_SERVER))) {
     86 				(void)fprintf(fd,
     87 					      "Bootserver Requesting system ");
     88 			} else {
     89 				(void)fprintf(fd,
     90 					      "Bootserver System default ");
     91 			}
     92 			if ((control & (1>>MOP_K_BOT_CNTL_DEVICE))) {
     93 				(void)fprintf(fd,
     94 					      "Bootdevice Specified device");
     95 			} else {
     96 				(void)fprintf(fd,
     97 					      "Bootdevice System default");
     98 			}
     99 			(void)fprintf(fd,"\n");
    100 
    101 			if ((control & (1>>MOP_K_BOT_CNTL_DEVICE))) {
    102 				tmpc = mopGetChar(pkt,&idx);/* Device ID */
    103 				(void)fprintf(fd,
    104 					      "Device ID    :   %02x '",tmpc);
    105 				for (i = 0; i < ((int) tmpc); i++) {
    106 				  (void)fprintf(fd,"%c",
    107 						mopGetChar(pkt,&idx));
    108 				}
    109 				(void)fprintf(fd,"'\n");
    110 			}
    111 
    112 			tmpc = mopGetChar(pkt,&idx);      /* Software ID */
    113 			(void)fprintf(fd,"Software ID  :   %02x ",tmpc);
    114 			if (tmpc == 0) {
    115 				(void)fprintf(fd,"No software id");
    116 			}
    117 			if (tmpc == 254) {
    118 				(void)fprintf(fd,"Maintenance system");
    119 				tmpc = 0;
    120 			}
    121 			if (tmpc == 255) {
    122 				(void)fprintf(fd,"Standard operating system");
    123 				tmpc = 0;
    124 			}
    125 			if (tmpc > 0) {
    126 				(void)fprintf(fd,"'");
    127 				for (i = 0; i < ((int) tmpc); i++) {
    128 					(void)fprintf(fd,"%c",
    129 						     mopGetChar(pkt,&idx));
    130 				}
    131 				(void)fprintf(fd,"'");
    132 			}
    133 			(void)fprintf(fd,"'\n");
    134 
    135 		}
    136 		break;
    137 	case MOP_K_CODE_SID:
    138 
    139 		tmpc = mopGetChar(pkt,&idx);		/* Reserved */
    140 		(void)fprintf(fd, "Reserved     :   %02x\n",tmpc);
    141 
    142 		tmps = mopGetShort(pkt,&idx);		/* Receipt # */
    143 		(void)fprintf(fd, "Receipt Nbr  : %04x\n",tmpc);
    144 
    145 		mopPrintInfo(fd, pkt, &idx, moplen, code, trans);
    146 
    147 		break;
    148 	case MOP_K_CODE_RQC:
    149 
    150 		tmps = mopGetShort(pkt,&idx);
    151 		(void)fprintf(fd,"Receipt Nbr  : %04x\n",tmps);
    152 
    153 		break;
    154 	case MOP_K_CODE_CNT:
    155 
    156 		tmps = mopGetShort(pkt,&idx);
    157 		(void)fprintf(fd,"Receipt Nbr  : %04x %d\n",tmps,tmps);
    158 
    159 		tmps = mopGetShort(pkt,&idx);
    160 		(void)fprintf(fd,"Last Zeroed  : %04x %d\n",tmps,tmps);
    161 
    162 		tmpl = mopGetLong(pkt,&idx);
    163 		(void)fprintf(fd,"Bytes rec    : %08x %d\n",tmpl,tmpl);
    164 
    165 		tmpl = mopGetLong(pkt,&idx);
    166 		(void)fprintf(fd,"Bytes snd    : %08x %d\n",tmpl,tmpl);
    167 
    168 		tmpl = mopGetLong(pkt,&idx);
    169 		(void)fprintf(fd,"Frames rec   : %08x %d\n",tmpl,tmpl);
    170 
    171 		tmpl = mopGetLong(pkt,&idx);
    172 		(void)fprintf(fd,"Frames snd   : %08x %d\n",tmpl,tmpl);
    173 
    174 		tmpl = mopGetLong(pkt,&idx);
    175 		(void)fprintf(fd,"Mcst Bytes re: %08x %d\n",tmpl,tmpl);
    176 
    177 		tmpl = mopGetLong(pkt,&idx);
    178 		(void)fprintf(fd,"Mcst Frame re: %08x %d\n",tmpl,tmpl);
    179 
    180 		tmpl = mopGetLong(pkt,&idx);
    181 		(void)fprintf(fd,"Frame snd,def: %08x %d\n",tmpl,tmpl);
    182 
    183 		tmpl = mopGetLong(pkt,&idx);
    184 		(void)fprintf(fd,"Frame snd,col: %08x %d\n",tmpl,tmpl);
    185 
    186 		tmpl = mopGetLong(pkt,&idx);
    187 		(void)fprintf(fd,"Frame snd,mcl: %08x %d\n",tmpl,tmpl);
    188 
    189 		tmps = mopGetShort(pkt,&idx);
    190 		(void)fprintf(fd,"Snd failure  : %04x %d\n",tmps,tmps);
    191 
    192 		tmps = mopGetShort(pkt,&idx);
    193 		(void)fprintf(fd,"Snd fail reas: %04x ",tmps);
    194 		if ((tmps &  1)) (void)fprintf(fd,"Excess col  ");
    195 		if ((tmps &  2)) (void)fprintf(fd,"Carrier chk fail  ");
    196 		if ((tmps &  4)) (void)fprintf(fd,"Short circ  ");
    197 		if ((tmps &  8)) (void)fprintf(fd,"Open circ  ");
    198 		if ((tmps & 16)) (void)fprintf(fd,"Frm to long  ");
    199 		if ((tmps & 32)) (void)fprintf(fd,"Rem fail to defer  ");
    200 		(void)fprintf(fd,"\n");
    201 
    202 		tmps = mopGetShort(pkt,&idx);
    203 		(void)fprintf(fd,"Rec failure  : %04x %d\n",tmps,tmps);
    204 
    205 		tmps = mopGetShort(pkt,&idx);
    206 		(void)fprintf(fd,"Rec fail reas: %04x ",tmps);
    207 		if ((tmps &  1)) (void)fprintf(fd,"Block chk err  ");
    208 		if ((tmps &  2)) (void)fprintf(fd,"Framing err  ");
    209 		if ((tmps &  4)) (void)fprintf(fd,"Frm to long  ");
    210 		(void)fprintf(fd,"\n");
    211 
    212 		tmps = mopGetShort(pkt,&idx);
    213 		(void)fprintf(fd,"Unrec frm dst: %04x %d\n",tmps,tmps);
    214 
    215 		tmps = mopGetShort(pkt,&idx);
    216 		(void)fprintf(fd,"Data overrun : %04x %d\n",tmps,tmps);
    217 
    218 		tmps = mopGetShort(pkt,&idx);
    219 		(void)fprintf(fd,"Sys Buf Unava: %04x %d\n",tmps,tmps);
    220 
    221 		tmps = mopGetShort(pkt,&idx);
    222 		(void)fprintf(fd,"Usr Buf Unava: %04x %d\n",tmps,tmps);
    223 
    224 		break;
    225 	case MOP_K_CODE_RVC:
    226 
    227 		tmpl = mopGetLong(pkt,&idx);
    228 		(void)fprintf(fd,"Verification : %08x\n",tmpl);
    229 
    230 		break;
    231 	case MOP_K_CODE_RLC:
    232 
    233 		/* Empty message */
    234 
    235 		break;
    236 	case MOP_K_CODE_CCP:
    237 
    238 		tmpc = mopGetChar(pkt,&idx);
    239 		(void)fprintf(fd,
    240 			      "Control Flags: %02x Message %d ",tmpc,tmpc & 1);
    241 		if ((tmpc & 2))
    242 			(void)fprintf(fd,"Break");
    243 		(void)fprintf(fd,"\n");
    244 
    245 		if (moplen > 2) {
    246 #ifndef SHORT_PRINT
    247 			for (i = 0; i < (moplen - 2); i++) {
    248 		  		if ((i % 16) == 0) {
    249 					if ((i / 16) == 0) {
    250 						(void)fprintf(fd,
    251 							"Image Data   : %04x ",
    252 							      moplen-2);
    253 					} else {
    254 						(void)fprintf(fd,
    255 						       "                    ");
    256 				        }
    257 				}
    258 				(void)fprintf(fd,"%02x ",
    259 					      mopGetChar(pkt,&idx));
    260 				if ((i % 16) == 15)
    261 					(void)fprintf(fd,"\n");
    262 			}
    263 			if ((i % 16) != 15)
    264 				(void)fprintf(fd,"\n");
    265 #else
    266 			idx = idx + moplen - 2;
    267 #endif
    268 		}
    269 
    270 		break;
    271 	case MOP_K_CODE_CRA:
    272 
    273 		tmpc = mopGetChar(pkt,&idx);
    274 		(void)fprintf(fd,
    275 			      "Control Flags: %02x Message %d ",tmpc,tmpc & 1);
    276 		if ((tmpc & 2))
    277 			(void)fprintf(fd,"Cmd Data Lost ");
    278 		if ((tmpc & 4))
    279 			(void)fprintf(fd,"Resp Data Lost ");
    280 		(void)fprintf(fd,"\n");
    281 
    282 		if (moplen > 2) {
    283 #ifndef SHORT_PRINT
    284 			for (i = 0; i < (moplen - 2); i++) {
    285 				if ((i % 16) == 0) {
    286 					if ((i / 16) == 0) {
    287 						(void)fprintf(fd,
    288 							"Image Data   : %04x ",
    289 							      moplen-2);
    290 					} else {
    291 						(void)fprintf(fd,
    292 						       "                    ");
    293 					}
    294 				}
    295 				(void)fprintf(fd,"%02x ",
    296 					      mopGetChar(pkt,&idx));
    297 				if ((i % 16) == 15)
    298 					(void)fprintf(fd,"\n");
    299 			}
    300 			if ((i % 16) != 15)
    301 				(void)fprintf(fd,"\n");
    302 #else
    303 			idx = idx + moplen - 2;
    304 #endif
    305 		}
    306 
    307 		break;
    308 	default:
    309 		break;
    310 	}
    311 }
    312 
    313