xref: /csrg-svn/old/dlmpcc/dlmpcc.c (revision 32618)
1*32618Ssam #ifndef lint
2*32618Ssam static char sccsid[] = "@(#)dlmpcc.c	5.1 (Berkeley from CCI) 11/15/87";
3*32618Ssam #endif
4*32618Ssam 
5*32618Ssam /*
6*32618Ssam  * MPCC Download and Configuration Program.
7*32618Ssam  */
8*32618Ssam #include <stdio.h>
9*32618Ssam #include <ctype.h>
10*32618Ssam #include <fcntl.h>
11*32618Ssam #include <sys/ioctl.h>
12*32618Ssam #include <errno.h>
13*32618Ssam 
14*32618Ssam #include <sys/types.h>
15*32618Ssam #include <tahoevba/mpreg.h>
16*32618Ssam #include <stdio.h>
17*32618Ssam 
18*32618Ssam #include "scnhdr.h"
19*32618Ssam 
20*32618Ssam #define MAXMPCC 16
21*32618Ssam 
22*32618Ssam char	*MPCCTAB = "/etc/mpcctab";
23*32618Ssam int	resetflg = 0;
24*32618Ssam 
25*32618Ssam main(argc, argv)
26*32618Ssam 	char *argv[];
27*32618Ssam {
28*32618Ssam 	int bd;
29*32618Ssam 
30*32618Ssam 	if (argc == 1) {
31*32618Ssam 		for (bd = 0; bd < MAXMPCC; bd++)
32*32618Ssam 			if (bldmap(bd) != -1)
33*32618Ssam 				download(bd);
34*32618Ssam 		exit(0);
35*32618Ssam 	}
36*32618Ssam 	for (argc--, argv++; argc > 0; argc--, argv++) {
37*32618Ssam 		bd = atoi(argv[0]);
38*32618Ssam 		if (strcmp(argv[0], "-r") == 0) {
39*32618Ssam 			resetflg = 1;
40*32618Ssam 			continue;
41*32618Ssam 		}
42*32618Ssam 		if (bd > MAXMPCC || bd < 0) {
43*32618Ssam 			printf("Illegal Board Number=> %d\n", bd);
44*32618Ssam 			continue;
45*32618Ssam 		}
46*32618Ssam 		if (bldmap(bd) == -1)
47*32618Ssam 			continue;
48*32618Ssam 		download(bd);
49*32618Ssam 	}
50*32618Ssam 	exit(0);
51*32618Ssam }
52*32618Ssam 
53*32618Ssam /*
54*32618Ssam  * Build Load Module Map
55*32618Ssam  */
56*32618Ssam struct  bdcf cf;
57*32618Ssam struct	abdcf bdasy;
58*32618Ssam 
59*32618Ssam #define LINESIZE 128
60*32618Ssam 
61*32618Ssam bldmap(dlbd)
62*32618Ssam 	int dlbd;		/* board to be downloaded */
63*32618Ssam {
64*32618Ssam 	FILE *tabfp;
65*32618Ssam 	int bd, port, count;
66*32618Ssam 	char *bdstr, *strtok(), protocol, line[LINESIZE];
67*32618Ssam 	char *lptr, *lptr1, *lptr2;
68*32618Ssam 
69*32618Ssam 	protocol = '\0';
70*32618Ssam 	/* open the configuration file for reading */
71*32618Ssam 	if ((tabfp = fopen(MPCCTAB, "r")) == NULL) {
72*32618Ssam 		printf("No Configuration File: %s\n", MPCCTAB);
73*32618Ssam 		return (-1);
74*32618Ssam 	}
75*32618Ssam 	for (;;) {
76*32618Ssam 		if (fgets(&line[0], LINESIZE-1, tabfp) == NULL) {
77*32618Ssam 			fclose(tabfp);
78*32618Ssam 			return (-1);
79*32618Ssam 		}
80*32618Ssam 		count++;
81*32618Ssam 		line[strlen(line)-1] = '\0';
82*32618Ssam 		lptr = strtok(line, ':');
83*32618Ssam 		if (tolower(*lptr) != 'm')
84*32618Ssam 			continue;
85*32618Ssam 		lptr = strtok((char *)0, ':');
86*32618Ssam 		bd = atoi(lptr);
87*32618Ssam 		if (bd == dlbd)
88*32618Ssam 			break;
89*32618Ssam 	}
90*32618Ssam 	cf.fccstimer = 20;      /* default to 1 sec (20 * 50ms) */
91*32618Ssam 	cf.fccsports = 0;       /* no ports are fccs */
92*32618Ssam 	cf.fccssoc = 0;         /* no ports switch on close */
93*32618Ssam 	for (port = 0; port < MPMAXPORT; port++)
94*32618Ssam 		cf.protoports[port] = MPPROTO_UNUSED;
95*32618Ssam 	/* check for the keywords following the board number */
96*32618Ssam 	lptr1 = (char *)0;
97*32618Ssam 	lptr2 = (char *)0;
98*32618Ssam 	while (*lptr) {
99*32618Ssam 		lptr = strtok((char *)0, ':');
100*32618Ssam 		if (!strncmp(lptr, "FCCS", 4)) {
101*32618Ssam 			lptr1 = lptr;
102*32618Ssam 			continue;
103*32618Ssam 		}
104*32618Ssam 		if (!strncmp(lptr, "SOC", 3)) {
105*32618Ssam 			lptr2 = lptr;
106*32618Ssam 			continue;
107*32618Ssam 		}
108*32618Ssam 	}
109*32618Ssam 	/* process the board and port characteristics */
110*32618Ssam 	while (fgets(&line[0], LINESIZE-1, tabfp) != NULL) {
111*32618Ssam 		count++;
112*32618Ssam 		line[strlen(line)-1] = '\0';
113*32618Ssam 		if (!line[0])		/* if newline only */
114*32618Ssam 			continue;
115*32618Ssam 		lptr = strtok(line, ':');
116*32618Ssam 		if (tolower(*lptr) == 'm')
117*32618Ssam 			break;
118*32618Ssam 		if (*lptr == '#')	/* ignore comment */
119*32618Ssam 			continue;
120*32618Ssam 		if (tolower(*lptr) == 'p' && tolower(*(lptr+1)) == 'o') {
121*32618Ssam 			/* PORT */
122*32618Ssam 			port = atoi(lptr = strtok((char *)0, ':'));
123*32618Ssam 			protocol = *(lptr = strtok((char *)0, ':'));
124*32618Ssam 			switch (cf.protoports[port] = protocol) {
125*32618Ssam 			case '3' :		/* ASYNCH 32 port */
126*32618Ssam 			case 'A' :		/* ASYNCH */
127*32618Ssam 				break;
128*32618Ssam 			case 'B':		/* BISYNCH */
129*32618Ssam 				break;
130*32618Ssam 			case 'S':		/* SDLC */
131*32618Ssam 				snapargs(port, lptr);
132*32618Ssam 				break;
133*32618Ssam 			case 'X':		/* X25 */
134*32618Ssam 				x25pargs(port, lptr);
135*32618Ssam 				break;
136*32618Ssam 			default:
137*32618Ssam 				printf(
138*32618Ssam "No protocol specified on PROTOCOL line in configuration file %s:%d: %s\n",
139*32618Ssam 				    MPCCTAB, count, line);
140*32618Ssam 				protocol = 'A';
141*32618Ssam 				break;
142*32618Ssam 			}
143*32618Ssam 			continue;
144*32618Ssam 		}
145*32618Ssam 		if (tolower(*lptr) == 'p' && tolower(*(lptr+1)) == 'r') {
146*32618Ssam 			/* PROTOCOL */
147*32618Ssam #ifdef notdef
148*32618Ssam 			if(protocol) {
149*32618Ssam 				printf(
150*32618Ssam "second protocol specified on PROTOCOL line in configuration file %s:%d: %s\n",
151*32618Ssam 				    MPCCTAB, count, line);
152*32618Ssam 				continue;
153*32618Ssam 			}
154*32618Ssam #endif
155*32618Ssam 			lptr = strtok((char *) 0, ':');
156*32618Ssam 			switch (protocol = *lptr) {
157*32618Ssam 			case '3':		/* ASYNCH 32 port */
158*32618Ssam 			case 'A':		/* ASYNCH */
159*32618Ssam 				asybargs(lptr);
160*32618Ssam 				break;
161*32618Ssam 			case 'B':		/* BISYNCH */
162*32618Ssam 				break;
163*32618Ssam 			case 'S':		/* SDLC */
164*32618Ssam 				snabargs(lptr);
165*32618Ssam 				break;
166*32618Ssam 			case 'X':		/* X25 */
167*32618Ssam 				x25bargs(lptr);
168*32618Ssam 				break;
169*32618Ssam 			default:
170*32618Ssam 				printf(
171*32618Ssam "No protocol specified on PROTOCOL line in configuration file %s:%d: %s\n",
172*32618Ssam 				    MPCCTAB, count, line);
173*32618Ssam 				protocol = 'A';
174*32618Ssam 				break;
175*32618Ssam 			}
176*32618Ssam 			continue;
177*32618Ssam 		}
178*32618Ssam 		printf("Error in configuration file %s,line %d, %s\n",
179*32618Ssam 		    MPCCTAB, count, line);
180*32618Ssam 	}
181*32618Ssam 	fclose(tabfp);
182*32618Ssam 	mkldnm();
183*32618Ssam 	return (0);
184*32618Ssam }
185*32618Ssam 
186*32618Ssam /*
187*32618Ssam  * decode x25 arguments for board
188*32618Ssam  *
189*32618Ssam  * for X.25, the arguments are N1, N2, T1, T2, T3, T4, K).
190*32618Ssam  */
191*32618Ssam x25bargs(args)
192*32618Ssam 	char *args;
193*32618Ssam {
194*32618Ssam }
195*32618Ssam 
196*32618Ssam /*
197*32618Ssam  * decode sna arguments for board
198*32618Ssam  * for SNA, the arguments are N1, N2, T1, T2, T3, T4, K).
199*32618Ssam  */
200*32618Ssam snabargs(args)
201*32618Ssam 	char *args;
202*32618Ssam {
203*32618Ssam }
204*32618Ssam 
205*32618Ssam /*
206*32618Ssam  * decode async arguments for board
207*32618Ssam  */
208*32618Ssam asybargs(args)
209*32618Ssam char *args;
210*32618Ssam {
211*32618Ssam 
212*32618Ssam 	bdasy.xmtbsz = atoi(strtok((char *)0, ':'));
213*32618Ssam }
214*32618Ssam 
215*32618Ssam /*
216*32618Ssam  * decode x25 arguments for port
217*32618Ssam  */
218*32618Ssam x25pargs(port,args)
219*32618Ssam 	int port;
220*32618Ssam 	char *args;
221*32618Ssam {
222*32618Ssam }
223*32618Ssam 
224*32618Ssam /*
225*32618Ssam  * decode sna arguments for port
226*32618Ssam  */
227*32618Ssam snapargs(port, args)
228*32618Ssam 	int port;
229*32618Ssam 	char *args;
230*32618Ssam {
231*32618Ssam }
232*32618Ssam 
233*32618Ssam gethi()
234*32618Ssam {
235*32618Ssam 	int i;
236*32618Ssam 
237*32618Ssam 	for (i = MPMAXPORT-1; i >= 0 && cf.protoports[i] == 0; i--)
238*32618Ssam 		;
239*32618Ssam 	return (i);
240*32618Ssam }
241*32618Ssam 
242*32618Ssam getlo()
243*32618Ssam {
244*32618Ssam 	int i;
245*32618Ssam 
246*32618Ssam 	for (i = 0; i < MPMAXPORT && cf.protoports[i] == 0; i++)
247*32618Ssam 		;
248*32618Ssam 	return (i);
249*32618Ssam }
250*32618Ssam 
251*32618Ssam prntmap(board)
252*32618Ssam 	int board;
253*32618Ssam {
254*32618Ssam 	int j;
255*32618Ssam 
256*32618Ssam 	printf("\nMPCC #: %d\n", board);
257*32618Ssam 	for (j = 0; j < MPMAXPORT; j++) {
258*32618Ssam 		printf("port: %d  %c", j, cf.protoports[j]);
259*32618Ssam 		switch (cf.protoports[j]) {
260*32618Ssam 		case '3': case 'A':
261*32618Ssam 			printf("\n");
262*32618Ssam 			break;
263*32618Ssam 		case 'B':
264*32618Ssam 			break;
265*32618Ssam 		case 'S':
266*32618Ssam 			break;
267*32618Ssam 		case 'X':
268*32618Ssam 			break;
269*32618Ssam 		default:
270*32618Ssam 			printf("Unused\n");
271*32618Ssam 			break;
272*32618Ssam 		}
273*32618Ssam 	}
274*32618Ssam 	printf("ldname: %s, ", cf.loadname);
275*32618Ssam 	printf("hiport: %d, loport: %d\n", gethi(), getlo());
276*32618Ssam 	if (cf.fccsports != 0)
277*32618Ssam 		printf("FCCS\n");
278*32618Ssam 	switch (cf.protoports[0]) {
279*32618Ssam 	case '3': case 'A':
280*32618Ssam 		printf("xmtsize: %d\n", bdasy.xmtbsz);
281*32618Ssam 		break;
282*32618Ssam 	case 'B':
283*32618Ssam 		break;
284*32618Ssam 	case 'S':
285*32618Ssam 		break;
286*32618Ssam 	case 'X':
287*32618Ssam 		break;
288*32618Ssam 	}
289*32618Ssam 	printf("protoports: %s\n", cf.protoports);
290*32618Ssam }
291*32618Ssam 
292*32618Ssam /*
293*32618Ssam  * Make Load Module Name
294*32618Ssam  *
295*32618Ssam  * if any port is 'ASYNCH"
296*32618Ssam  * 	add 'a' to load module name
297*32618Ssam  * if any port is 'BISYNCH'
298*32618Ssam  * 	add 'b' to load module name
299*32618Ssam  * if any port is 'SDLC'
300*32618Ssam  * 	add 's' to load module name
301*32618Ssam  * if any port is 'X25'
302*32618Ssam  * 	add 'x' to load module name
303*32618Ssam  */
304*32618Ssam mkldnm()
305*32618Ssam {
306*32618Ssam 	static char *pcols = "ABSX3";
307*32618Ssam 	char *proto;
308*32618Ssam 	int j, offset;
309*32618Ssam 
310*32618Ssam 	offset = 0;
311*32618Ssam 	for (proto = pcols; *proto; proto++) {
312*32618Ssam 		for (j = 0; j < MPMAXPORT; j++) {
313*32618Ssam 			if (cf.protoports[j] == *proto) {
314*32618Ssam 				if (*proto == '3')
315*32618Ssam 					cf.loadname[offset] = '3';
316*32618Ssam 				else
317*32618Ssam 					cf.loadname[offset] = tolower(*proto);
318*32618Ssam 				offset++;
319*32618Ssam 				break;
320*32618Ssam 			}
321*32618Ssam 		}
322*32618Ssam 		cf.loadname[offset] = '\0';
323*32618Ssam 	}
324*32618Ssam }
325*32618Ssam 
326*32618Ssam /*
327*32618Ssam  * if a string is passed as an argument,
328*32618Ssam  * 	save it in the local string area
329*32618Ssam  * 	set the local index to the start of the string
330*32618Ssam  * else
331*32618Ssam  * 	set start to the current character in the string
332*32618Ssam  * 	while the character is not the separator,
333*32618Ssam  * 		and the character is not NULL
334*32618Ssam  * 			skip the character
335*32618Ssam  */
336*32618Ssam static
337*32618Ssam char *
338*32618Ssam strtok(s, c)
339*32618Ssam 	char *s, c;
340*32618Ssam {
341*32618Ssam 	static char locals[LINESIZE];
342*32618Ssam 	static int i;
343*32618Ssam 	char *start;
344*32618Ssam 
345*32618Ssam 	if (s != 0) {
346*32618Ssam 		strcpy(locals, s);
347*32618Ssam 		i = 0;
348*32618Ssam 	}
349*32618Ssam 	for (start = &locals[i] ; locals[i] && locals[i] != c; i++)
350*32618Ssam 		;
351*32618Ssam 	if (locals[i]) {
352*32618Ssam 		locals[i] = '\0';
353*32618Ssam 		i++;
354*32618Ssam 	}
355*32618Ssam 	while (*start == ' ')
356*32618Ssam 		start++;
357*32618Ssam 	return (start);
358*32618Ssam }
359*32618Ssam 
360*32618Ssam short	bits[] = { 1, 2, 4, 8, 16, 32, 64, 128 };
361*32618Ssam fccs(line, tptr, pptr)
362*32618Ssam 	char *line, *tptr, *pptr;
363*32618Ssam {
364*32618Ssam 	u_short ports, num, time;
365*32618Ssam 
366*32618Ssam 	ports = 0;
367*32618Ssam 	line = strtok(line, ',');
368*32618Ssam 	while (*(line = strtok((char *) 0, ',')) != '\0') {
369*32618Ssam 		num = (short) atoi(line);
370*32618Ssam 		if (num >= 0 && num < 8)
371*32618Ssam 			ports |= bits[num];
372*32618Ssam 		else if (num >= 50 && num < 6400)
373*32618Ssam 			time = num / 50;
374*32618Ssam 		else
375*32618Ssam 			printf("bad value for FCCS: %d\n", num);
376*32618Ssam 	}
377*32618Ssam 	*pptr = ports;
378*32618Ssam 	*tptr = time;
379*32618Ssam }
380*32618Ssam 
381*32618Ssam soc(line, sptr)
382*32618Ssam 	char *line, *sptr;
383*32618Ssam {
384*32618Ssam 	u_short ports, num;
385*32618Ssam 
386*32618Ssam 	ports = 0;
387*32618Ssam 	line = strtok(line, ',');
388*32618Ssam 	while (*(line = strtok((char *) 0, ',')) != '\0') {
389*32618Ssam 		num = atoi(line);
390*32618Ssam 		if (num >= 0 && num < 8)
391*32618Ssam 			ports |= bits[num];
392*32618Ssam 		else
393*32618Ssam 			printf("bad value for SOC: %d\n",num);
394*32618Ssam 	}
395*32618Ssam 	*sptr = ports;
396*32618Ssam }
397*32618Ssam 
398*32618Ssam char	buffer[MPDLBUFSIZE];
399*32618Ssam extern	int errno;
400*32618Ssam struct head1 {
401*32618Ssam 	long	magic;
402*32618Ssam 	long	fill[12];
403*32618Ssam 	struct	scnhdr text;
404*32618Ssam 	struct	scnhdr data;
405*32618Ssam 	struct	scnhdr bss;
406*32618Ssam } header1;
407*32618Ssam 
408*32618Ssam download(mpccnum)
409*32618Ssam 	int mpccnum;
410*32618Ssam {
411*32618Ssam 	char dlname[LINESIZE], fullname[LINESIZE];
412*32618Ssam 	char *ldname, *ppmap;
413*32618Ssam 	int dlfd, ldfd;
414*32618Ssam 	char *it;
415*32618Ssam 	short i;
416*32618Ssam 	char hilo[2];
417*32618Ssam 	long realsize;
418*32618Ssam 
419*32618Ssam 	sprintf(dlname, "/dev/mpcc%d", mpccnum);
420*32618Ssam 	if (*cf.loadname == '3')
421*32618Ssam 		sprintf(fullname, "/etc/mpcc32");
422*32618Ssam 	else
423*32618Ssam 		sprintf(fullname, "/etc/mpcc%s", cf.loadname);
424*32618Ssam 	if ((cf.loadname[0]) == '\0')
425*32618Ssam 		return (-1);
426*32618Ssam 	if ((dlfd = open(dlname, O_RDWR)) == MP_DLERROR) {
427*32618Ssam 		printf("Can not open %s\n",dlname);
428*32618Ssam 		return (-1);
429*32618Ssam 	}
430*32618Ssam 	if ((ldfd = open(fullname, O_RDONLY)) == MP_DLERROR) {
431*32618Ssam 		close(dlfd);
432*32618Ssam 		printf("Can not access protocol code file: %s\n", fullname);
433*32618Ssam 		return (-1);
434*32618Ssam 	}
435*32618Ssam 	if (dlokay(dlfd,mpccnum) == MP_DLERROR) {
436*32618Ssam 		close(ldfd);
437*32618Ssam 		close(dlfd);
438*32618Ssam 		return (-1);
439*32618Ssam 	}
440*32618Ssam 	printf("Downloading MPCC #%x\n", mpccnum);
441*32618Ssam 	/* read executable file header */
442*32618Ssam 	if (read(ldfd, &header1, sizeof(header1)) != sizeof(header1)) {
443*32618Ssam 		printf("Can not read %s\n", fullname);
444*32618Ssam 		return (-1);
445*32618Ssam 	}
446*32618Ssam 	/* place at start of text space */
447*32618Ssam 	if (lseek(ldfd, header1.text.s_scnptr , (int) 0) == -1) {
448*32618Ssam 		printf("lseek error(text): %d", errno);
449*32618Ssam 		return (-1);
450*32618Ssam 	}
451*32618Ssam 	/* send text */
452*32618Ssam 	realsize = header1.data.s_paddr - header1.text.s_paddr;
453*32618Ssam 	if (dl(ldfd, dlfd, realsize) == -1) {
454*32618Ssam 		ioctl(dlfd, MPIORESETBOARD, 0L);
455*32618Ssam 		return (-1);
456*32618Ssam 	}
457*32618Ssam 	/* place at start of data space	*/
458*32618Ssam 	if (lseek(ldfd, header1.data.s_scnptr , (int) 0) == -1) {
459*32618Ssam 		printf("lseek error(data): %d", errno);
460*32618Ssam 		return (-1);
461*32618Ssam 	}
462*32618Ssam 	/* send initialized data */
463*32618Ssam 	realsize = header1.bss.s_paddr - header1.data.s_paddr;
464*32618Ssam 	if (dl(ldfd, dlfd, realsize) == -1) {
465*32618Ssam 		ioctl(dlfd, MPIORESETBOARD, 0L);
466*32618Ssam 		return (-1);
467*32618Ssam 	}
468*32618Ssam 	/* signal end of code */
469*32618Ssam 	if (ioctl(dlfd, MPIOENDCODE, (char *) 0) == MP_DLERROR) {
470*32618Ssam 		printf("MPIOENDCODE ioctl failed\n");
471*32618Ssam 		ioctl(dlfd, MPIORESETBOARD, 0L);
472*32618Ssam 		return (-1);
473*32618Ssam 	}
474*32618Ssam 	/* download configuration information	*/
475*32618Ssam 	if (config(dlfd) == -1) {
476*32618Ssam 		ioctl(dlfd, MPIORESETBOARD, 0L);
477*32618Ssam 		return (-1);
478*32618Ssam 	}
479*32618Ssam 	/* write port/protocol map */
480*32618Ssam 	ppmap = (char *)&cf.protoports[0];
481*32618Ssam 	tknzmap(ppmap);
482*32618Ssam 	if (ioctl(dlfd, MPIOPORTMAP, ppmap) == MP_DLERROR) {
483*32618Ssam 		printf("MPIOPORTMAP ioctl failed\n");
484*32618Ssam 		ioctl(dlfd, MPIORESETBOARD, 0L);
485*32618Ssam 		return (-1);
486*32618Ssam 	}
487*32618Ssam 	/* signal end of download */
488*32618Ssam 	if (ioctl(dlfd, MPIOENDDL, (char *) 0) == MP_DLERROR) {
489*32618Ssam 		printf("MPIOENDDL ioctl failed\n");
490*32618Ssam 		ioctl(dlfd, MPIORESETBOARD, 0L);
491*32618Ssam 		return (-1);
492*32618Ssam 	}
493*32618Ssam 	close(dlfd);
494*32618Ssam 	close(ldfd);
495*32618Ssam 	printf("Download Complete and Successful\n");
496*32618Ssam 	return (0);
497*32618Ssam }
498*32618Ssam 
499*32618Ssam dlokay(bdfd, mpccnum)
500*32618Ssam 	int bdfd, mpccnum;
501*32618Ssam {
502*32618Ssam 	char answer;
503*32618Ssam 
504*32618Ssam 	if (resetflg) {
505*32618Ssam 		printf("Reseting MPCC #%x\n",mpccnum);
506*32618Ssam 		ioctl(bdfd, MPIORESETBOARD, 0L);
507*32618Ssam 		sleep(10);
508*32618Ssam 	}
509*32618Ssam 	if (ioctl(bdfd, MPIOSTARTDL, 0) == MP_DLERROR) {
510*32618Ssam 		if (errno == EBUSY) {
511*32618Ssam 			printf("MPCC #%x has already been downloaded.\n",
512*32618Ssam 			    mpccnum);
513*32618Ssam 			printf("Do you want to re-download it?: ");
514*32618Ssam 			fscanf(stdin,"%c",&answer);
515*32618Ssam 			while (getchar() != '\n')
516*32618Ssam 				;
517*32618Ssam 			if ((answer | 0x60) != 'y')
518*32618Ssam 				return (MP_DLERROR);
519*32618Ssam 			ioctl(bdfd, MPIORESETBOARD, 0L);
520*32618Ssam 			sleep(10);
521*32618Ssam 			if (ioctl(bdfd, MPIOSTARTDL, (char *) 0) == MP_DLERROR) {
522*32618Ssam 				printf("Can't download MPCC #%x\n", mpccnum);
523*32618Ssam 				return (MP_DLERROR);
524*32618Ssam 			}
525*32618Ssam 		} else {
526*32618Ssam 			switch (errno) {
527*32618Ssam 			case ENODEV:
528*32618Ssam 				printf("MPCC #%x not in system\n", mpccnum);
529*32618Ssam 				break;
530*32618Ssam 			case EACCES:
531*32618Ssam 				printf("Download area in use, try later\n");
532*32618Ssam 				break;
533*32618Ssam 			case ENOSPC:
534*32618Ssam 				printf("MPCC #%x already being downloaded\n",
535*32618Ssam 				    mpccnum);
536*32618Ssam 				break;
537*32618Ssam 			default:
538*32618Ssam 				printf("Unknown response from MPCC #%x\n",
539*32618Ssam 				    mpccnum);
540*32618Ssam 				break;
541*32618Ssam 			}
542*32618Ssam 			return (MP_DLERROR);
543*32618Ssam 		}
544*32618Ssam 	}
545*32618Ssam 	return (0);
546*32618Ssam }
547*32618Ssam 
548*32618Ssam dl(dskfd, bdfd, size)
549*32618Ssam 	int dskfd, bdfd;
550*32618Ssam 	long size;
551*32618Ssam {
552*32618Ssam 	int bytes;
553*32618Ssam 
554*32618Ssam 	while (size > 0) {
555*32618Ssam 		bytes = (size < MPDLBUFSIZE) ? (int) size : MPDLBUFSIZE;
556*32618Ssam 		if ((bytes = read(dskfd, buffer, bytes)) == MP_DLERROR) {
557*32618Ssam 			close(dskfd);
558*32618Ssam 			close(bdfd);
559*32618Ssam 			printf("Download-Can't read buffer\n");
560*32618Ssam 			return (-1);
561*32618Ssam 		}
562*32618Ssam 		if (write(bdfd, buffer, bytes) == MP_DLERROR) {
563*32618Ssam 			close(dskfd);
564*32618Ssam 			close(bdfd);
565*32618Ssam 			printf("Download-Can't write buffer\n");
566*32618Ssam 			return (-1);
567*32618Ssam 		}
568*32618Ssam 		size -= bytes;
569*32618Ssam 	}
570*32618Ssam 	return (0);
571*32618Ssam }
572*32618Ssam 
573*32618Ssam /*
574*32618Ssam  * download each protocol's configuration data
575*32618Ssam  * and the configuration data for tboard.
576*32618Ssam  */
577*32618Ssam config(dlfd)
578*32618Ssam 	int dlfd;
579*32618Ssam {
580*32618Ssam 	register int i;
581*32618Ssam 	char *ldname;
582*32618Ssam 
583*32618Ssam 	for (ldname = cf.loadname; *ldname; ldname++) {
584*32618Ssam 		switch (*ldname) {
585*32618Ssam 		case '3': case 'a':
586*32618Ssam 			if (ioctl(dlfd, MPIOASYNCNF, &bdasy) == MP_DLERROR) {
587*32618Ssam 				printf("async ioctl failed\n");
588*32618Ssam 				return (-1);
589*32618Ssam 			}
590*32618Ssam 			break;
591*32618Ssam 		case 'b':
592*32618Ssam 			break;
593*32618Ssam 		case 'x':
594*32618Ssam 			break;
595*32618Ssam 
596*32618Ssam 		case 's':
597*32618Ssam 			break;
598*32618Ssam 		}
599*32618Ssam 	}
600*32618Ssam }
601*32618Ssam 
602*32618Ssam /*
603*32618Ssam  * tokenize the protoport string,
604*32618Ssam  * (change from the letter to the corresponding number).
605*32618Ssam  */
606*32618Ssam tknzmap(map)
607*32618Ssam 	char *map;
608*32618Ssam {
609*32618Ssam 	short i;
610*32618Ssam 
611*32618Ssam 	for (i = 0; i < MPMAXPORT; i++) {
612*32618Ssam 		switch (*map) {
613*32618Ssam 		case '3' :	*map = MPPROTO_ASYNC; break;
614*32618Ssam 		case 'A' :	*map = MPPROTO_ASYNC; break;
615*32618Ssam 		case 'B' :	*map = MPPROTO_BISYNC; break;
616*32618Ssam 		case 'S' :	*map = MPPROTO_SNA; break;
617*32618Ssam 		case 'X' :	*map = MPPROTO_X25; break;
618*32618Ssam 		default:	*map = MPPROTO_UNUSED; break;
619*32618Ssam 		}
620*32618Ssam 		map++;
621*32618Ssam 	}
622*32618Ssam }
623