1995-09-12 03:07:18 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* ISDN loader for intelligent cards.
|
|
|
|
*
|
|
|
|
* Copyright (c) 1993-1995 Matthias Urlichs <urlichs@noris.de>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "master.h"
|
|
|
|
|
1995-10-22 10:59:20 +00:00
|
|
|
#if 0 /* master.h */
|
1995-09-12 03:07:18 +00:00
|
|
|
struct loader {
|
|
|
|
char *card;
|
|
|
|
FILE *file;
|
|
|
|
long seqnum; /* number in config file */
|
|
|
|
int nrfile; /* number loaded to card */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* cf_LF: num2: sequence number; num: block size */
|
|
|
|
#endif
|
|
|
|
|
1995-10-22 10:59:20 +00:00
|
|
|
static void
|
|
|
|
card_load_close(struct loader *ld)
|
|
|
|
{
|
|
|
|
if(ld->name != NULL)
|
|
|
|
ld->card->name = ld->name;
|
|
|
|
if(ld->file != NULL)
|
|
|
|
fclose(ld->file);
|
|
|
|
if(ld->timer)
|
|
|
|
untimeout(card_load,ld);
|
|
|
|
{
|
|
|
|
struct loader **ldp = &isdn4_loader;
|
|
|
|
while(*ldp != NULL) {
|
|
|
|
if(*ldp == ld) {
|
|
|
|
*ldp = ld->next;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ldp = &(*ldp)->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(ld);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
card_load_fail(struct loader *ld, int err)
|
|
|
|
{
|
|
|
|
mblk_t *mj = allocb (32, BPRI_LO);
|
|
|
|
int len;
|
|
|
|
|
|
|
|
syslog(LOG_ERR,"Card %s was not loaded: Error at file %d, pos %d\n",ld->card,ld->nrfile,ld->foffset);
|
|
|
|
|
|
|
|
/* Tell lower layer to forget the thing */
|
|
|
|
|
|
|
|
if (mj != NULL) {
|
|
|
|
m_putid (mj, CMD_NOCARD);
|
|
|
|
m_putsx (mj, ARG_CARD);
|
|
|
|
m_putsz (mj, ld->name);
|
|
|
|
len = mj->b_wptr - mj->b_rptr;
|
|
|
|
DUMPW (mj->b_rptr, len);
|
|
|
|
(void) strwrite (xs_mon, (uchar_t *) mj->b_rptr, len, 1);
|
|
|
|
freeb (mj);
|
|
|
|
}
|
|
|
|
|
|
|
|
card_load_close(ld);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
card_load(struct loader *ld)
|
1995-09-12 03:07:18 +00:00
|
|
|
{
|
|
|
|
cf dl,lf;
|
|
|
|
int do_again;
|
|
|
|
|
1995-10-22 10:59:20 +00:00
|
|
|
ld->timer = 0;
|
1995-09-12 03:07:18 +00:00
|
|
|
again:
|
|
|
|
do_again = 0;
|
1995-10-22 10:59:20 +00:00
|
|
|
for(lf = cf_LF; lf != NULL; lf = lf->next) {
|
|
|
|
if(!wildmatch(ld->name,lf->card))
|
1995-09-12 03:07:18 +00:00
|
|
|
continue;
|
|
|
|
if(ld->seqnum != 0 && ld->seqnum != lf->num2) {
|
|
|
|
if(ld->seqnum < lf->num2 && (do_again == 0 || do_again > lf->num2))
|
|
|
|
do_again = ld->seqnum;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(lf == NULL) {
|
|
|
|
if(ld->seqnum == 0) {
|
1995-10-22 10:59:20 +00:00
|
|
|
syslog(LOG_ERR, "Card loader for %s has a config problem (seq %d)!\n",ld->card,ld->seqnum);
|
1995-09-12 03:07:18 +00:00
|
|
|
goto ex_load;
|
|
|
|
}
|
|
|
|
if(do_again) {
|
|
|
|
ld->seqnum = do_again;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
do_again = 1;
|
|
|
|
if(!do_again || (ld->file != NULL)) {
|
|
|
|
char *buf = NULL; /* shut up GCC */
|
|
|
|
int len, xlen, foffset;
|
|
|
|
mblk_t xx;
|
|
|
|
struct datab db;
|
|
|
|
struct iovec io[3];
|
1995-10-22 10:59:20 +00:00
|
|
|
streamchar ans[50];
|
1995-09-12 03:07:18 +00:00
|
|
|
|
|
|
|
if(ld->file != NULL) {
|
|
|
|
buf = malloc(lf->num);
|
|
|
|
if(buf == NULL) {
|
|
|
|
syslog(LOG_ERR, "Card loader for %s !\n",ld->card);
|
|
|
|
goto ex_load;
|
|
|
|
}
|
|
|
|
|
1995-10-22 10:59:20 +00:00
|
|
|
if(fseek(ld->file,ld->foffset,0) < 0) {
|
|
|
|
syslog(LOG_ERR, "Card loader for %s: fseek returned %m\n",ld->card);
|
1995-09-12 03:07:18 +00:00
|
|
|
goto ex_load;
|
|
|
|
}
|
|
|
|
len = fread(buf,1,lf->num,ld->file);
|
|
|
|
if(len < 0) {
|
|
|
|
syslog(LOG_ERR, "Card loader for %s: read returned %m\n",ld->card);
|
|
|
|
free(buf);
|
|
|
|
goto ex_load;
|
|
|
|
}
|
1995-10-22 10:59:20 +00:00
|
|
|
foffset = ld->foffset;
|
|
|
|
ld->foffset += len;
|
1995-09-12 03:07:18 +00:00
|
|
|
} else {
|
|
|
|
len = 0;
|
|
|
|
foffset = 0;
|
1995-10-22 10:59:20 +00:00
|
|
|
ld->foffset = 0;
|
1995-09-12 03:07:18 +00:00
|
|
|
}
|
1995-10-22 10:59:20 +00:00
|
|
|
if(!do_again && (ld->file == NULL))
|
|
|
|
++ld->nrfile; /* last file; we're finished */
|
1995-09-12 03:07:18 +00:00
|
|
|
xx.b_rptr = xx.b_wptr = ans;
|
1995-10-22 10:59:20 +00:00
|
|
|
xx.b_datap = &db;
|
1995-09-12 03:07:18 +00:00
|
|
|
db.db_base = ans;
|
|
|
|
db.db_lim = ans + sizeof (ans);
|
|
|
|
m_putid (&xx, CMD_LOADFILE);
|
|
|
|
m_putsx(&xx,ARG_CARD);
|
1995-10-22 10:59:20 +00:00
|
|
|
m_putsz(&xx,ld->name);
|
1995-09-12 03:07:18 +00:00
|
|
|
m_putsx(&xx,ARG_SEQNUM);
|
1995-10-22 10:59:20 +00:00
|
|
|
m_puti(&xx,ld->nrfile);
|
1995-09-12 03:07:18 +00:00
|
|
|
m_putsx(&xx,ARG_OFFSET);
|
|
|
|
m_puti(&xx,foffset);
|
|
|
|
|
|
|
|
*xx.b_wptr++ = ' ';
|
|
|
|
xlen = xx.b_wptr - xx.b_rptr;
|
|
|
|
DUMPW (ans, xlen);
|
|
|
|
io[0].iov_base = ans;
|
|
|
|
io[0].iov_len = xlen;
|
1995-10-22 10:59:20 +00:00
|
|
|
io[1].iov_base = "::";
|
|
|
|
io[1].iov_len = 2;
|
1995-09-12 03:07:18 +00:00
|
|
|
if(len > 0) {
|
|
|
|
io[2].iov_base = buf;
|
|
|
|
io[2].iov_len = len;
|
|
|
|
len = 3;
|
|
|
|
} else {
|
|
|
|
len = 2;
|
|
|
|
if(ld->file != NULL) {
|
|
|
|
fclose(ld->file);
|
|
|
|
ld->file = NULL;
|
1995-10-22 10:59:20 +00:00
|
|
|
ld->seqnum++;
|
1995-09-12 03:07:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
(void) strwritev (xs_mon, io,len, 1);
|
|
|
|
free(buf);
|
|
|
|
if(do_again) {
|
1995-10-22 10:59:20 +00:00
|
|
|
ld->timer = 1;
|
|
|
|
timeout(card_load,ld,ld->file ? HZ : HZ*(ld->nrfile+2));
|
1995-09-12 03:07:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ld->seqnum = lf->num2;
|
|
|
|
ld->nrfile++;
|
|
|
|
ld->file = fopen(lf->arg,"r");
|
1995-10-22 10:59:20 +00:00
|
|
|
ld->foffset = 0;
|
1995-09-12 03:07:18 +00:00
|
|
|
if(ld->file == NULL) {
|
|
|
|
syslog(LOG_ERR, "Card loader for %s: file %s: %m\n",ld->card,lf->arg);
|
|
|
|
goto ex_load;
|
|
|
|
}
|
1995-10-22 10:59:20 +00:00
|
|
|
ld->timer = 1;
|
|
|
|
timeout(card_load,ld,HZ*2);
|
1995-09-12 03:07:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(dl = cf_DL; dl != NULL; dl = dl->next) {
|
|
|
|
struct iovec io[3];
|
|
|
|
int len;
|
|
|
|
mblk_t xx;
|
|
|
|
struct datab db;
|
|
|
|
streamchar ans[30];
|
|
|
|
|
1995-10-22 10:59:20 +00:00
|
|
|
if(!wildmatch(dl->card,ld->name))
|
1995-09-12 03:07:18 +00:00
|
|
|
continue;
|
|
|
|
xx.b_rptr = xx.b_wptr = ans;
|
1995-10-22 10:59:20 +00:00
|
|
|
xx.b_datap = &db;
|
1995-09-12 03:07:18 +00:00
|
|
|
db.db_base = ans;
|
|
|
|
db.db_lim = ans + sizeof (ans);
|
|
|
|
m_putid (&xx, CMD_DOCARD);
|
|
|
|
m_putsx(&xx,ARG_CARD);
|
1995-10-22 10:59:20 +00:00
|
|
|
m_putsz(&xx,ld->name);
|
1995-09-12 03:07:18 +00:00
|
|
|
|
|
|
|
*xx.b_wptr++ = ' ';
|
|
|
|
len = xx.b_wptr - xx.b_rptr;
|
|
|
|
DUMPW (ans, len);
|
|
|
|
io[0].iov_base = ans;
|
|
|
|
io[0].iov_len = len;
|
|
|
|
len = 1;
|
|
|
|
if(dl->args != NULL) {
|
|
|
|
printf ("+ ");
|
1995-10-22 10:59:20 +00:00
|
|
|
io[len].iov_base = "::";
|
|
|
|
io[len].iov_len = 2;
|
1995-09-12 03:07:18 +00:00
|
|
|
len++;
|
|
|
|
io[len].iov_base = dl->args;
|
|
|
|
io[len].iov_len = strlen(dl->args);
|
|
|
|
DUMPW (dl->args,io[len].iov_len);
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
(void) strwritev (xs_mon, io,len, 1);
|
1995-10-22 10:59:20 +00:00
|
|
|
card_load_close(ld);
|
|
|
|
|
|
|
|
do_run_now++;
|
|
|
|
timeout(run_now,NULL,HZ/3);
|
|
|
|
return;
|
1995-09-12 03:07:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ex_load:
|
1995-10-22 10:59:20 +00:00
|
|
|
card_load_fail(ld,-EIO);
|
1995-09-12 03:07:18 +00:00
|
|
|
return;
|
|
|
|
}
|