|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1982, 1986 Regents of the University of California. ! 3: * All rights reserved. The Berkeley software License Agreement ! 4: * specifies the terms and conditions for redistribution. ! 5: * ! 6: * @(#)imptst.c 6.2 (Berkeley) 6/8/85 ! 7: */ ! 8: #include "machine/pte.h" ! 9: ! 10: #include "param.h" ! 11: ! 12: #include "../vaxuba/ubareg.h" ! 13: ! 14: #include "../netinet/in.h" ! 15: #include "../netinet/in_systm.h" ! 16: #define IMPLEADERS ! 17: #include "../netimp/if_imp.h" ! 18: #include "../vaxif/if_accreg.h" ! 19: ! 20: #include "saio.h" ! 21: #include "savax.h" ! 22: ! 23: #define min(a,b) (a<b ? a : b) ! 24: #define BUFSIZ (1006+sizeof(struct imp_leader)) ! 25: ! 26: char input[132]; ! 27: char inbuf[BUFSIZ]; ! 28: char outbuf[BUFSIZ]; ! 29: struct imp_leader *oip = (struct imp_leader *)outbuf; ! 30: struct imp_leader *iip = (struct imp_leader *)inbuf; ! 31: int verbose = 1; ! 32: int datalen = 0; ! 33: ! 34: main() ! 35: { ! 36: register error = 0, i, len; ! 37: short type, host, impno, link; ! 38: register struct accdevice *addr = ! 39: (struct accdevice *)ubamem(0, 0767700); ! 40: register char *p, pattern = 0; ! 41: ! 42: printf("imp interface loopback diagnostic\n"); ! 43: printf("verbose(y or n)? "); ! 44: gets(input); ! 45: verbose = (*input != 'n'); ! 46: printf("enter destination host number: "); ! 47: gets(input); ! 48: while ((host = (short)atol(input)) < 0 || host > 255) { ! 49: printf("range [0, 255], re-enter: "); ! 50: gets(input); ! 51: } ! 52: printf("imp number: "); ! 53: gets(input); ! 54: while ((impno = (short)atol(input)) < 0 || impno > 32767) { ! 55: printf("range [0, 32767], re-enter: "); ! 56: gets(input); ! 57: } ! 58: printf("link number: "); ! 59: gets(input); ! 60: while ((link = (short)atol(input)) < 0 || link > 255) { ! 61: printf("range [0, 255], re-enter: "); ! 62: gets(input); ! 63: } ! 64: printf("initialization starting...\n"); ! 65: impinit(); ! 66: oip->il_format = IMP_NFF; ! 67: oip->il_mtype = IMPTYPE_NOOP; ! 68: #define noop ! 69: #ifdef noop ! 70: /* send 3 noops and init imp leader buffer */ ! 71: impnoops((struct control_leader *)oip); ! 72: #endif ! 73: printf("initialization complete\n"); ! 74: while (1) { ! 75: if (verbose) ! 76: printf("starting write test...\n"); ! 77: oip->il_host = host; ! 78: oip->il_imp = htons((u_short)impno); ! 79: oip->il_link = link; ! 80: for (p = (char *)(oip + 1), i = datalen; i--; ) ! 81: *p = pattern++; ! 82: error = impwrite(oip, datalen + sizeof (*oip)); ! 83: if (error) ! 84: printf("imp write error, ocsr=%b\n", (short)error, ! 85: ACC_OUTBITS); ! 86: ! 87: if (verbose) ! 88: printf("starting read test...\n"); ! 89: if (verbose) ! 90: printf("impread(%d)\n", sizeof (*iip)); ! 91: bzero(inbuf, sizeof(inbuf)); ! 92: error = impread(iip, sizeof (inbuf)); ! 93: if (verbose) ! 94: printf("impread, error=%b\n", error, ACC_INBITS); ! 95: if (verbose) ! 96: printleader(iip); ! 97: if (bcmp(iip, oip, sizeof(*iip) != 0)) ! 98: printf("leader data error\n"); ! 99: len = ntohs(iip->il_length); ! 100: if (len != datalen) ! 101: printf("length mismatch, got %d instead of %d\n", ! 102: len, datalen); ! 103: /* read any data */ ! 104: p = (char *)(iip + 1); ! 105: while ((error & IN_EOM) == 0 && ! 106: (error & ~IN_EOM) == 0 && len > 0) { ! 107: i = min(len, BUFSIZ); ! 108: printf("impread(%d)\n", i); ! 109: error = impread(p, i); ! 110: len -= i; ! 111: p += i; ! 112: printf("error=%b, len=%d\n", error, ACC_INBITS, len); ! 113: } ! 114: error &= ~IN_EOM; ! 115: if (error == 0 && (len > 0 || addr->iwc)) ! 116: printf("imp input length mismatch\n"); ! 117: if (error) ! 118: printf("imp read error, icsr=%b\n", ! 119: (short)error, ACC_INBITS); ! 120: else if (bcmp(iip + 1, oip + 1, datalen)) ! 121: printf("data comparison error\n"); ! 122: } ! 123: } ! 124: ! 125: impnoops(cp) ! 126: register struct control_leader *cp; ! 127: { ! 128: register i, error; ! 129: ! 130: bzero((caddr_t)cp, sizeof (struct control_leader)); ! 131: cp->dl_format = IMP_NFF; ! 132: cp->dl_mtype = IMPTYPE_NOOP; ! 133: for (i = 0; i < IMP_DROPCNT + 1; i++ ) { ! 134: cp->dl_link = i; ! 135: if ((error = impwrite(cp, sizeof (*cp))) != 0) { ! 136: printf("imp init error, ocsr=%b\n", (short)error, ! 137: ACC_OUTBITS); ! 138: _stop(); ! 139: } ! 140: } ! 141: for (i = 0; i < IMP_DROPCNT + 1; i++ ) { ! 142: bzero((caddr_t)iip, sizeof(*iip)); ! 143: error = impread(iip, sizeof (inbuf)); ! 144: if (verbose) ! 145: printf("impread, error=%b\n", error, ACC_INBITS); ! 146: if (verbose) ! 147: printleader(iip); ! 148: } ! 149: } ! 150: ! 151: impwrite(buf, len) ! 152: register struct imp *buf; ! 153: register len; ! 154: { ! 155: register uba, error; ! 156: struct iob io; ! 157: register struct accdevice *addr = ! 158: (struct accdevice *)ubamem(0, 0767600); ! 159: ! 160: /* set up uba mapping */ ! 161: io.i_ma = (caddr_t)buf; ! 162: io.i_cc = len; ! 163: uba = ubasetup(&io, 0); ! 164: ! 165: /* set regs and perform i/o */ ! 166: addr->oba = (u_short)uba; ! 167: addr->owc = -((io.i_cc + 1) >> 1); ! 168: addr->ocsr = ((short) ((uba & 0x30000) >> 12) | OUT_ENLB | ACC_GO); ! 169: while ((addr->ocsr & ACC_RDY) == 0) ! 170: ; ! 171: error = addr->ocsr & (ACC_NXM|ACC_ERR); ! 172: ubafree(uba); ! 173: return(error); ! 174: } ! 175: ! 176: impread(buf, len) ! 177: register struct imp *buf; ! 178: register len; ! 179: { ! 180: register uba, error; ! 181: struct iob io; ! 182: register struct accdevice *addr = ! 183: (struct accdevice *)ubamem(0, 0767600); ! 184: ! 185: /* set up uba mapping */ ! 186: io.i_ma = (caddr_t)buf; ! 187: io.i_cc = len; ! 188: uba = ubasetup(&io, 0); ! 189: /* set regs and perform i/o */ ! 190: addr->iba = (u_short)uba; ! 191: addr->iwc = -(io.i_cc >> 1); ! 192: addr->icsr = IN_MRDY | IN_WEN | ((uba & 0x30000) >> 12) | ACC_GO; ! 193: while ((addr->icsr & ACC_RDY) == 0) ! 194: ; ! 195: error = addr->icsr & (IN_EOM|ACC_ERR|IN_RMR|ACC_NXM); ! 196: ubafree(uba); ! 197: return(error); ! 198: } ! 199: ! 200: impinit() ! 201: { ! 202: register struct accdevice *addr = ! 203: (struct accdevice *)ubamem(0, 0767600); ! 204: register int i; ! 205: ! 206: /* ! 207: * Reset the imp interface; ! 208: * the delays are pure guesswork. ! 209: */ ! 210: addr->icsr = ACC_RESET; DELAY(5000); ! 211: addr->ocsr = ACC_RESET; DELAY(5000); ! 212: addr->ocsr = OUT_BBACK; DELAY(5000); /* reset host master ready */ ! 213: addr->ocsr = 0; ! 214: addr->icsr = IN_MRDY | IN_WEN; /* close the relay */ ! 215: DELAY(10000); ! 216: /* YECH!!! */ ! 217: for (i = 0; i < 500; i++) { ! 218: if ((addr->icsr & IN_HRDY) && ! 219: (addr->icsr & (IN_RMR | IN_IMPBSY)) == 0) ! 220: return; ! 221: addr->icsr = IN_MRDY | IN_WEN; DELAY(10000); ! 222: /* keep turning IN_RMR off */ ! 223: } ! 224: printf("impinit: imp doesn't respond, icsr=%b, ocsr=%b\n", ! 225: addr->icsr, ACC_INBITS, addr->ocsr, ACC_OUTBITS); ! 226: } ! 227: ! 228: /* ! 229: * Convert null-terminated ascii string to binary ! 230: * and return value. ! 231: * 1st char in string : ! 232: * 0 -> octal ! 233: * x -> hex ! 234: * else decimal ! 235: */ ! 236: atol(as) ! 237: register char *as; ! 238: { ! 239: register value = 0; ! 240: register base = 10; ! 241: register sign = 1; ! 242: register digit = 0; ! 243: ! 244: aloop : ! 245: if ((digit = (*as++)) == 0) ! 246: return(value) ; /* null */ ! 247: if (digit == '-') { ! 248: sign = -sign; ! 249: goto aloop ; ! 250: } ! 251: if (digit == '0') ! 252: base = 8 ; ! 253: else if (digit == 'x') ! 254: base = 16 ; ! 255: else ! 256: value = digit - '0'; ! 257: while (digit = (*as++)) { ! 258: if (digit < '0') ! 259: return(0); ! 260: switch (base) { ! 261: ! 262: case 8 : ! 263: if (digit > '7') ! 264: return(0); ! 265: digit -= '0'; ! 266: break; ! 267: ! 268: case 10 : ! 269: if (digit > '9') ! 270: return(0); ! 271: digit -= '0'; ! 272: break; ! 273: ! 274: case 16 : ! 275: if (digit <= '9') { ! 276: digit -= 060 ; ! 277: break; ! 278: } ! 279: if ((digit >= 'A') && (digit <= 'F')) { ! 280: digit -= 'A' + 10; ! 281: break; ! 282: } ! 283: if ((digit >= 'a') && (digit <= 'f')) { ! 284: digit -= 'a' + 10 ; ! 285: break; ! 286: } ! 287: return(0); ! 288: } ! 289: value = (value * base) + digit; ! 290: } ! 291: return (value * sign); ! 292: } ! 293: ! 294: printleader(ip) ! 295: register struct imp_leader *ip; ! 296: { ! 297: printbyte((char *)ip, 12); ! 298: printf("<fmt=%x,net=%x,flags=%x,mtype=", ip->il_format, ip->il_network, ! 299: ip->il_flags); ! 300: if (ip->il_mtype <= IMPTYPE_READY) ! 301: printf("%s,", impleaders[ip->il_mtype]); ! 302: else ! 303: printf("%x,", ip->il_mtype); ! 304: printf("htype=%x,host=%x,imp=%x,link=", ip->il_htype, ip->il_host, ! 305: ntohs(ip->il_imp)); ! 306: if (ip->il_link == IMPLINK_IP) ! 307: printf("ip,"); ! 308: else ! 309: printf("%x,", ip->il_link); ! 310: printf("subtype=%x,len=%x>\n",ip->il_subtype,ntohs(ip->il_length)>>3); ! 311: } ! 312: ! 313: printbyte(cp, n) ! 314: register char *cp; ! 315: int n; ! 316: { ! 317: register i, j, c; ! 318: ! 319: for (i=0; i<n; i++) { ! 320: c = *cp++; ! 321: for (j=0; j<2; j++) ! 322: putchar("0123456789abcdef"[(c>>((1-j)*4))&0xf]); ! 323: putchar(' '); ! 324: } ! 325: putchar('\n'); ! 326: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.