* Copyright (c) 1988 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
"@(#) Copyright (c) 1988 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)dlmpcc.c 5.2 (Berkeley) %G%";
* MPCC Download and Configuration Program.
#include <tahoevba/mpreg.h>
char *MPCCTAB
= "/etc/mpcctab";
for (bd
= 0; bd
< MAXMPCC
; bd
++)
for (argc
--, argv
++; argc
> 0; argc
--, argv
++) {
if (strcmp(argv
[0], "-r") == 0) {
if (bd
> MAXMPCC
|| bd
< 0) {
printf("Illegal Board Number=> %d\n", bd
);
int dlbd
; /* board to be downloaded */
char *bdstr
, *strtok(), protocol
, line
[LINESIZE
];
char *lptr
, *lptr1
, *lptr2
;
/* open the configuration file for reading */
if ((tabfp
= fopen(MPCCTAB
, "r")) == NULL
) {
printf("No Configuration File: %s\n", MPCCTAB
);
if (fgets(&line
[0], LINESIZE
-1, tabfp
) == NULL
) {
line
[strlen(line
)-1] = '\0';
lptr
= strtok(line
, ':');
if (tolower(*lptr
) != 'm')
lptr
= strtok((char *)0, ':');
cf
.fccstimer
= 20; /* default to 1 sec (20 * 50ms) */
cf
.fccsports
= 0; /* no ports are fccs */
cf
.fccssoc
= 0; /* no ports switch on close */
for (port
= 0; port
< MPMAXPORT
; port
++)
cf
.protoports
[port
] = MPPROTO_UNUSED
;
/* check for the keywords following the board number */
lptr
= strtok((char *)0, ':');
if (!strncmp(lptr
, "FCCS", 4)) {
if (!strncmp(lptr
, "SOC", 3)) {
/* process the board and port characteristics */
while (fgets(&line
[0], LINESIZE
-1, tabfp
) != NULL
) {
line
[strlen(line
)-1] = '\0';
if (!line
[0]) /* if newline only */
lptr
= strtok(line
, ':');
if (tolower(*lptr
) == 'm')
if (*lptr
== '#') /* ignore comment */
if (tolower(*lptr
) == 'p' && tolower(*(lptr
+1)) == 'o') {
port
= atoi(lptr
= strtok((char *)0, ':'));
protocol
= *(lptr
= strtok((char *)0, ':'));
switch (cf
.protoports
[port
] = protocol
) {
case '3' : /* ASYNCH 32 port */
"No protocol specified on PROTOCOL line in configuration file %s:%d: %s\n",
if (tolower(*lptr
) == 'p' && tolower(*(lptr
+1)) == 'r') {
"second protocol specified on PROTOCOL line in configuration file %s:%d: %s\n",
lptr
= strtok((char *) 0, ':');
switch (protocol
= *lptr
) {
case '3': /* ASYNCH 32 port */
"No protocol specified on PROTOCOL line in configuration file %s:%d: %s\n",
printf("Error in configuration file %s,line %d, %s\n",
* decode x25 arguments for board
* for X.25, the arguments are N1, N2, T1, T2, T3, T4, K).
* decode sna arguments for board
* for SNA, the arguments are N1, N2, T1, T2, T3, T4, K).
* decode async arguments for board
bdasy
.xmtbsz
= atoi(strtok((char *)0, ':'));
* decode x25 arguments for port
* decode sna arguments for port
for (i
= MPMAXPORT
-1; i
>= 0 && cf
.protoports
[i
] == 0; i
--)
for (i
= 0; i
< MPMAXPORT
&& cf
.protoports
[i
] == 0; i
++)
printf("\nMPCC #: %d\n", board
);
for (j
= 0; j
< MPMAXPORT
; j
++) {
printf("port: %d %c", j
, cf
.protoports
[j
]);
switch (cf
.protoports
[j
]) {
printf("ldname: %s, ", cf
.loadname
);
printf("hiport: %d, loport: %d\n", gethi(), getlo());
switch (cf
.protoports
[0]) {
printf("xmtsize: %d\n", bdasy
.xmtbsz
);
printf("protoports: %s\n", cf
.protoports
);
* if any port is 'ASYNCH"
* add 'a' to load module name
* if any port is 'BISYNCH'
* add 'b' to load module name
* add 's' to load module name
* add 'x' to load module name
static char *pcols
= "ABSX3";
for (proto
= pcols
; *proto
; proto
++) {
for (j
= 0; j
< MPMAXPORT
; j
++) {
if (cf
.protoports
[j
] == *proto
) {
cf
.loadname
[offset
] = '3';
cf
.loadname
[offset
] = tolower(*proto
);
cf
.loadname
[offset
] = '\0';
* if a string is passed as an argument,
* save it in the local string area
* set the local index to the start of the string
* set start to the current character in the string
* while the character is not the separator,
* and the character is not NULL
static char locals
[LINESIZE
];
for (start
= &locals
[i
] ; locals
[i
] && locals
[i
] != c
; i
++)
short bits
[] = { 1, 2, 4, 8, 16, 32, 64, 128 };
char *line
, *tptr
, *pptr
;
u_short ports
, num
, time
;
line
= strtok(line
, ',');
while (*(line
= strtok((char *) 0, ',')) != '\0') {
num
= (short) atoi(line
);
else if (num
>= 50 && num
< 6400)
printf("bad value for FCCS: %d\n", num
);
line
= strtok(line
, ',');
while (*(line
= strtok((char *) 0, ',')) != '\0') {
printf("bad value for SOC: %d\n",num
);
char buffer
[MPDLBUFSIZE
];
char dlname
[LINESIZE
], fullname
[LINESIZE
];
sprintf(dlname
, "/dev/mpcc%d", mpccnum
);
sprintf(fullname
, "/etc/mpcc32");
sprintf(fullname
, "/etc/mpcc%s", cf
.loadname
);
if ((cf
.loadname
[0]) == '\0')
if ((dlfd
= open(dlname
, O_RDWR
)) == MP_DLERROR
) {
printf("Can not open %s\n",dlname
);
if ((ldfd
= open(fullname
, O_RDONLY
)) == MP_DLERROR
) {
printf("Can not access protocol code file: %s\n", fullname
);
if (dlokay(dlfd
,mpccnum
) == MP_DLERROR
) {
printf("Downloading MPCC #%x\n", mpccnum
);
/* read executable file header */
if (read(ldfd
, &header1
, sizeof(header1
)) != sizeof(header1
)) {
printf("Can not read %s\n", fullname
);
/* place at start of text space */
if (lseek(ldfd
, header1
.text
.s_scnptr
, (int) 0) == -1) {
printf("lseek error(text): %d", errno
);
realsize
= header1
.data
.s_paddr
- header1
.text
.s_paddr
;
if (dl(ldfd
, dlfd
, realsize
) == -1) {
ioctl(dlfd
, MPIORESETBOARD
, 0L);
/* place at start of data space */
if (lseek(ldfd
, header1
.data
.s_scnptr
, (int) 0) == -1) {
printf("lseek error(data): %d", errno
);
/* send initialized data */
realsize
= header1
.bss
.s_paddr
- header1
.data
.s_paddr
;
if (dl(ldfd
, dlfd
, realsize
) == -1) {
ioctl(dlfd
, MPIORESETBOARD
, 0L);
if (ioctl(dlfd
, MPIOENDCODE
, (char *) 0) == MP_DLERROR
) {
printf("MPIOENDCODE ioctl failed\n");
ioctl(dlfd
, MPIORESETBOARD
, 0L);
/* download configuration information */
if (config(dlfd
) == -1) {
ioctl(dlfd
, MPIORESETBOARD
, 0L);
/* write port/protocol map */
ppmap
= (char *)&cf
.protoports
[0];
if (ioctl(dlfd
, MPIOPORTMAP
, ppmap
) == MP_DLERROR
) {
printf("MPIOPORTMAP ioctl failed\n");
ioctl(dlfd
, MPIORESETBOARD
, 0L);
/* signal end of download */
if (ioctl(dlfd
, MPIOENDDL
, (char *) 0) == MP_DLERROR
) {
printf("MPIOENDDL ioctl failed\n");
ioctl(dlfd
, MPIORESETBOARD
, 0L);
printf("Download Complete and Successful\n");
printf("Reseting MPCC #%x\n",mpccnum
);
ioctl(bdfd
, MPIORESETBOARD
, 0L);
if (ioctl(bdfd
, MPIOSTARTDL
, 0) == MP_DLERROR
) {
printf("MPCC #%x has already been downloaded.\n",
printf("Do you want to re-download it?: ");
fscanf(stdin
,"%c",&answer
);
while (getchar() != '\n')
if ((answer
| 0x60) != 'y')
ioctl(bdfd
, MPIORESETBOARD
, 0L);
if (ioctl(bdfd
, MPIOSTARTDL
, (char *) 0) == MP_DLERROR
) {
printf("Can't download MPCC #%x\n", mpccnum
);
printf("MPCC #%x not in system\n", mpccnum
);
printf("Download area in use, try later\n");
printf("MPCC #%x already being downloaded\n",
printf("Unknown response from MPCC #%x\n",
bytes
= (size
< MPDLBUFSIZE
) ? (int) size
: MPDLBUFSIZE
;
if ((bytes
= read(dskfd
, buffer
, bytes
)) == MP_DLERROR
) {
printf("Download-Can't read buffer\n");
if (write(bdfd
, buffer
, bytes
) == MP_DLERROR
) {
printf("Download-Can't write buffer\n");
* download each protocol's configuration data
* and the configuration data for tboard.
for (ldname
= cf
.loadname
; *ldname
; ldname
++) {
if (ioctl(dlfd
, MPIOASYNCNF
, &bdasy
) == MP_DLERROR
) {
printf("async ioctl failed\n");
* tokenize the protoport string,
* (change from the letter to the corresponding number).
for (i
= 0; i
< MPMAXPORT
; i
++) {
case '3' : *map
= MPPROTO_ASYNC
; break;
case 'A' : *map
= MPPROTO_ASYNC
; break;
case 'B' : *map
= MPPROTO_BISYNC
; break;
case 'S' : *map
= MPPROTO_SNA
; break;
case 'X' : *map
= MPPROTO_X25
; break;
default: *map
= MPPROTO_UNUSED
; break;