plan 9 kernel history: overview | file list | diff list

1990/0312/port/devdk.c (diff list | history)

1990/0312/sys/src/9/port/devdk.c:112,1181990/0315/sys/src/9/port/devdk.c:112,118 (short | long)
1990/0312    
 
/* 
 *  a dkmux dk.  one exists for every stream that a  
 *  dkmux line disilpline is pushed onto. 
1990/0315    
 *  dkmux line discipline is pushed onto. 
1990/0312    
 */ 
struct Dk { 
	QLock; 
1990/0312/sys/src/9/port/devdk.c:284,2921990/0315/sys/src/9/port/devdk.c:284,293
1990/0312    
		return; 
	} 
 
	line = *bp->rptr++ | (*bp->rptr++<<8); 
1990/0315    
	line = bp->rptr[0] | (bp->rptr[1]<<8); 
	bp->rptr += 2; 
1990/0312    
	if(line<0 || line>=dp->lines){ 
		print("dkmuxiput bad line %d\n", line); 
1990/0315    
		DPRINT("dkmuxiput bad line %d\n", line); 
1990/0312    
		freeb(bp); 
		return; 
	} 
1990/0312/sys/src/9/port/devdk.c:296,3071990/0315/sys/src/9/port/devdk.c:297,308
1990/0312    
		if(lp->rq) 
			PUTNEXT(lp->rq, bp); 
		else{ 
			print("dkmuxiput unopened line %d\n", line); 
1990/0315    
			DPRINT("dkmuxiput unopened line %d\n", line); 
1990/0312    
			freeb(bp); 
		} 
		qunlock(lp); 
	} else { 
		print("dkmuxiput unopened line %d\n", line); 
1990/0315    
		DPRINT("dkmuxiput unopened line %d\n", line); 
1990/0312    
		freeb(bp); 
	} 
} 
1990/0312/sys/src/9/port/devdk.c:411,4161990/0315/sys/src/9/port/devdk.c:412,419
1990/0312    
 
	if(bp->base && bp->rptr - bp->base >= 2) 
		bp->rptr -= 2; 
1990/0315    
	else 
		panic("dkoput"); 
1990/0312    
	bp->rptr[0] = line; 
	bp->rptr[1] = line>>8; 
 
1990/0312/sys/src/9/port/devdk.c:590,5961990/0315/sys/src/9/port/devdk.c:593,598
1990/0312    
		error(0, Enoifc); 
	c = devattach('k', spec); 
	c->dev = dp - dk; 
                 
	return c; 
} 
 
1990/0312/sys/src/9/port/devdk.c:1112,11241990/0315/sys/src/9/port/devdk.c:1114,1126
1990/0312    
		 *  for the call to come in on). 
		 */ 
		if(!canqlock(lp)){ 
			print("DKbusy1\n"); 
1990/0315    
			DPRINT("DKbusy1\n"); 
1990/0312    
			dkanswer(c, lineno, DKbusy); 
			continue; 
		} else { 
			if(lp->state != Lclosed){ 
				qunlock(lp); 
				print("DKbusy2 %ux\n", lp->state); 
1990/0315    
				DPRINT("DKbusy2 %ux\n", lp->state); 
1990/0312    
				dkanswer(c, lineno, DKbusy); 
				continue; 
			} 
1990/0315/sys/src/9/port/devdk.c:644,6511990/0319/sys/src/9/port/devdk.c:644,658 (short | long)
1990/0312    
	Dk *dp; 
	int line; 
 
	if(c->qid == Dcloneqid){ 
1990/0319    
	if(c->qid & CHDIR){ 
1990/0312    
		/* 
1990/0319    
		 *  directories are read only 
		 */ 
		if(omode != OREAD) 
			error(0, Ebadarg); 
	} else switch(STREAMTYPE(c->qid)){ 
	case Dcloneqid: 
		/* 
1990/0312    
		 *  get an unused device and open it's control file 
		 */ 
		dp = &dk[c->dev]; 
1990/0315/sys/src/9/port/devdk.c:665,6711990/0319/sys/src/9/port/devdk.c:672,679
1990/0312    
			error(0, Enodev); 
		streamopen(c, &dkinfo); 
		pushq(c->stream, &urpinfo); 
	} else if(STREAMTYPE(c->qid) == Dlistenqid){ 
1990/0319    
		break; 
	case Dlistenqid: 
1990/0312    
		/* 
		 *  listen for a call and open the control file for the 
		 *  channel on which the call arrived. 
1990/0315/sys/src/9/port/devdk.c:675,6871990/0319/sys/src/9/port/devdk.c:683,707
1990/0312    
		streamopen(c, &dkinfo); 
		pushq(c->stream, &urpinfo); 
		dkwindow(c); 
	} else if(c->qid != CHDIR){ 
1990/0319    
		break; 
	case Daddrqid: 
	case Draddrqid: 
	case Duserqid: 
	case Dotherqid: 
1990/0312    
		/* 
1990/0319    
		 *  read only files 
		 */ 
		if(omode != OREAD) 
			error(0, Ebadarg); 
		break; 
	default: 
		/* 
1990/0312    
		 *  open whatever c points to, make sure it has an urp 
		 */ 
		streamopen(c, &dkinfo); 
		if(strcmp(c->stream->procq->next->info->name, "urp")!=0) 
			pushq(c->stream, &urpinfo); 
1990/0319    
		break; 
1990/0312    
	} 
 
	c->mode = openmode(omode); 
1990/0315/sys/src/9/port/devdk.c:702,7081990/0319/sys/src/9/port/devdk.c:722,728
1990/0312    
	Dk *dp; 
 
	/* real closing happens in lancestclose */ 
	if(c->qid != CHDIR) 
1990/0319    
	if(c->stream) 
1990/0312    
		streamclose(c); 
 
	dp = &dk[c->dev]; 
1990/0315/sys/src/9/port/devdk.c:714,7301990/0319/sys/src/9/port/devdk.c:734,753
1990/0312    
long	  
dkread(Chan *c, void *a, long n) 
{ 
	int t; 
	Line *lp; 
 
	t = STREAMTYPE(c->qid); 
	if(t>=Slowqid || t==Dlineqid) 
1990/0319    
	if(c->stream) 
1990/0312    
		return streamread(c, a, n); 
	if(c->qid == CHDIR) 
		return devdirread(c, a, n, dkdir, dk[c->dev].lines, devgen); 
 
1990/0319    
	if(c->qid & CHDIR){ 
		if(c->qid == CHDIR) 
			return devdirread(c, a, n, dkdir, dk[c->dev].lines, devgen); 
		else 
			return devdirread(c, a, n, dksubdir, Nsubdir, streamgen); 
	} 
 
1990/0312    
	lp = &dk[c->dev].line[STREAMID(c->qid)]; 
	switch(t){ 
1990/0319    
	switch(STREAMTYPE(c->qid)){ 
1990/0312    
	case Daddrqid: 
		return stringread(c, a, n, lp->addr); 
	case Draddrqid: 
1990/0315/sys/src/9/port/devdk.c:781,7891990/0319/sys/src/9/port/devdk.c:804,809
1990/0312    
			return streamwrite(c, a, n, 0); 
		return n; 
	} 
                 
	if(t >= Slowqid) 
		return streamwrite(c, a, n, 0); 
 
	error(0, Eperm); 
} 
1990/0319/sys/src/9/port/devdk.c:538,5431990/0321/sys/src/9/port/devdk.c:538,545 (short | long)
1990/0312    
void 
dkreset(void) 
{ 
1990/0321    
	newqinfo(&dkmuxinfo); 
	newqinfo(&urpinfo); 
1990/0312    
} 
 
/* 
1990/0321/sys/src/9/port/devdk.c:1128,11331990/0403/sys/src/9/port/devdk.c:1128,1135 (short | long)
1990/0312    
		 */ 
		if(ts == lp->timestamp){ 
			print("dklisten: repeat timestamp %d\n", lineno); 
1990/0403    
			if(lp->state != Lconnected) 
				dkanswer(c, lineno, DKbusy); 
1990/0312    
			continue; 
		} 
	 
1990/0403/sys/src/9/port/devdk.c:417,4231990/0509/sys/src/9/port/devdk.c:417,427 (short | long)
1990/0312    
	bp->rptr[0] = line; 
	bp->rptr[1] = line>>8; 
 
	PUTNEXT(dp->wq, bp); 
1990/0509    
	if(QFULL(dp->wq->next)){ 
		print("dk wq full\n"); 
		freeb(bp); 
	} else 
		PUTNEXT(dp->wq, bp); 
1990/0312    
} 
 
/* 
1990/0509/sys/src/9/port/devdk.c:329,3341990/0511/sys/src/9/port/devdk.c:329,336 (short | long)
1990/0312    
	q->other->ptr = q->ptr = lp = &dp->line[s->id]; 
	lp->dp = dp; 
	lp->rq = q; 
1990/0511    
	if(lp->state == Lclosed) 
		lp->state = Lopened; 
1990/0312    
} 
 
/* 
1990/0509/sys/src/9/port/devdk.c:670,6761990/0511/sys/src/9/port/devdk.c:672,677
1990/0312    
					continue; 
				} 
				c->qid = STREAMQID(lp-dp->line, Sctlqid); 
				qunlock(lp); 
				break; 
			} 
		} 
1990/0509/sys/src/9/port/devdk.c:678,6831990/0511/sys/src/9/port/devdk.c:679,685
1990/0312    
			error(0, Enodev); 
		streamopen(c, &dkinfo); 
		pushq(c->stream, &urpinfo); 
1990/0511    
		qunlock(lp); 
1990/0319    
		break; 
	case Dlistenqid: 
1990/0312    
		/* 
1990/0509/sys/src/9/port/devdk.c:727,7331990/0511/sys/src/9/port/devdk.c:729,735
1990/0312    
{ 
	Dk *dp; 
 
	/* real closing happens in lancestclose */ 
1990/0511    
	/* real closing happens in dkstclose */ 
1990/0319    
	if(c->stream) 
1990/0312    
		streamclose(c); 
 
1990/0509/sys/src/9/port/devdk.c:899,9051990/0511/sys/src/9/port/devdk.c:901,907
1990/0312    
	/* 
	 *  only dial on virgin lines 
	 */ 
	if(lp->state != Lclosed) 
1990/0511    
	if(lp->state != Lopened) 
1990/0312    
		error(0, Ebadarg); 
 
	DPRINT("dkcall(line=%d, type=%d, dest=%s)\n", line, type, addr); 
1990/0509/sys/src/9/port/devdk.c:1202,12071990/0511/sys/src/9/port/devdk.c:1204,1210
1990/0312    
		DPRINT("dklisten returns %d\n", lineno); 
		return lineno; 
	} 
1990/0511    
	panic("dklisten terminates strangely\n"); 
1990/0312    
} 
 
/* 
1990/0511/sys/src/9/port/devdk.c:66,721990/0617/sys/src/9/port/devdk.c:66,72 (short | long)
1990/0312    
#define	  D_OK		1		/* not used */ 
#define	  D_OPEN	2		/* (dkmux to host) connection established */ 
#define	  D_FAIL	3		/* (dkmux to host) connection failed */ 
#define	T_CHG	3		/* linege the status of a connection */ 
1990/0617    
#define	T_CHG	3		/* change the status of a connection */ 
1990/0312    
#define	  D_CLOSE	1		/* close the connection */ 
#define	  D_ISCLOSED	2		/* (dkmux to host) confirm a close */ 
#define	  D_CLOSEALL	3		/* (dkmux to host) close all connections */ 
1990/0511/sys/src/9/port/devdk.c:1003,10091990/0617/sys/src/9/port/devdk.c:1003,1009
1990/0312    
	} 
 
	/* 
	 *  linege state if serving 
1990/0617    
	 *  change state if serving 
1990/0312    
	 */ 
	if(type == D_SERV){ 
		lp->state = Llistening; 
1990/0511/sys/src/9/port/devdk.c:1075,10811990/0617/sys/src/9/port/devdk.c:1075,1083
1990/0312    
		n = streamread(dc, dialstr, sizeof(dialstr)-1); 
		DPRINT("returns %d\n", n); 
		if(n <= 0) 
1990/0617    
{print("bad n\n"); 
1990/0312    
			error(0, Eio); 
1990/0617    
} 
1990/0312    
		dialstr[n] = 0; 
		DPRINT("dialstr = %s\n", dialstr); 
 
1990/0511/sys/src/9/port/devdk.c:1085,10901990/0617/sys/src/9/port/devdk.c:1087,1093
1990/0312    
		n = getfields(dialstr, line, 12, '\n'); 
		if (n < 2) { 
			DPRINT("bad dialstr from dk (1 line)\n"); 
1990/0617    
print("bad dialstr %d '%s'\n", n, dialstr); 
1990/0312    
			error(0, Eio); 
		} 
 
1990/0511/sys/src/9/port/devdk.c:1289,12941990/0617/sys/src/9/port/devdk.c:1292,1303
1990/0312    
	int i; 
 
	dp = (Dk *)a; 
1990/0617    
 
	/* 
	 *  tell datakit we've rebooted. It should close all channels. 
	 */ 
	dkmesg(dp, T_ALIVE, D_RESTART, 0, 0);	/* do this on mips but not 68020 */ 
	dkmesg(dp, T_CHG, D_CLOSEALL, 0, 0); 
1990/0312    
 
	/* 
	 *  loop forever listening 
1990/0617/sys/src/9/port/devdk.c:123,1281990/0707/sys/src/9/port/devdk.c:123,129 (short | long)
1990/0312    
	int	ncsc;		/* csc line number */ 
	Chan	*csc;		/* common signalling line */ 
	Line	line[Nline]; 
1990/0707    
	int	restart; 
1990/0312    
}; 
static Dk dk[Ndk]; 
 
1990/0617/sys/src/9/port/devdk.c:427,4361990/0707/sys/src/9/port/devdk.c:428,438
1990/0312    
} 
 
/* 
 *  configure a datakit multiplexor.  this takes 3 arguments separated 
1990/0707    
 *  configure a datakit multiplexor.  this takes 4 arguments separated 
1990/0312    
 *  by spaces: 
 *	the line number of the common signalling channel (must be > 0) 
 *	the number of lines in the device (optional) 
1990/0707    
 *	the word `restart' or `norestart' (optional/default==restart) 
1990/0312    
 *	the name of the dk (optional) 
 * 
 *  we can configure only once 
1990/0617/sys/src/9/port/devdk.c:439,4451990/0707/sys/src/9/port/devdk.c:441,447
1990/0312    
dkmuxconfig(Dk *dp, Block *bp) 
{ 
	Chan *c; 
	char *fields[3]; 
1990/0707    
	char *fields[4]; 
1990/0312    
	int n; 
	char buf[64]; 
	static int dktimeron; 
1990/0617/sys/src/9/port/devdk.c:452,4611990/0707/sys/src/9/port/devdk.c:454,467
1990/0312    
	/* 
	 *  parse 
	 */ 
	n = getfields((char *)bp->rptr, fields, 3, ' '); 
1990/0707    
	dp->restart = 1; 
	n = getfields((char *)bp->rptr, fields, 4, ' '); 
1990/0312    
	switch(n){ 
1990/0707    
	case 4: 
		strncpy(dp->name, fields[3], sizeof(dp->name)); 
1990/0312    
	case 3: 
		strncpy(dp->name, fields[2], sizeof(dp->name)); 
1990/0707    
		if(strcmp(fields[2], "restart")!=0) 
			dp->restart = 0; 
1990/0312    
	case 2: 
		dp->lines = strtoul(fields[1], 0, 0); 
	case 1: 
1990/0617/sys/src/9/port/devdk.c:893,8981990/0707/sys/src/9/port/devdk.c:899,905
1990/0312    
	Dk *dp; 
	Line *lp; 
	Chan *dc; 
1990/0707    
	char *bang, *dot; 
1990/0312    
 
	line = STREAMID(c->qid); 
	dp = &dk[c->dev]; 
1990/0617/sys/src/9/port/devdk.c:907,9131990/0707/sys/src/9/port/devdk.c:914,922
1990/0312    
	DPRINT("dkcall(line=%d, type=%d, dest=%s)\n", line, type, addr); 
 
	/* 
	 *  build dial string (guard against new lines) 
1990/0707    
	 *  build dial string 
	 *	- guard against new lines 
	 *	- change ! into . to delimit service 
1990/0312    
	 */ 
	if(strchr(addr, '\n')) 
		error(0, Ebadarg); 
1990/0617/sys/src/9/port/devdk.c:914,9191990/0707/sys/src/9/port/devdk.c:923,934
1990/0312    
	if(strlen(addr)+strlen(u->p->pgrp->user)+2 >= sizeof(dialstr)) 
		error(0, Ebadarg); 
	strcpy(dialstr, addr); 
1990/0707    
	bang = strchr(dialstr, '!'); 
	if(bang){ 
		dot = strchr(dialstr, '.'); 
		if(dot==0 || dot > bang) 
			*bang = '.'; 
	} 
1990/0312    
	switch(type){ 
	case Dial: 
		t_val = T_SRV; 
1990/0617/sys/src/9/port/devdk.c:1296,13021990/0707/sys/src/9/port/devdk.c:1311,1318
1990/0617    
	/* 
	 *  tell datakit we've rebooted. It should close all channels. 
	 */ 
	dkmesg(dp, T_ALIVE, D_RESTART, 0, 0);	/* do this on mips but not 68020 */ 
1990/0707    
	if(dp->restart) 
		dkmesg(dp, T_ALIVE, D_RESTART, 0, 0); 
1990/0617    
	dkmesg(dp, T_CHG, D_CLOSEALL, 0, 0); 
1990/0312    
 
	/* 
1990/0707/sys/src/9/port/devdk.c:551,5571990/0717/sys/src/9/port/devdk.c:551,557 (short | long)
1990/0312    
dkreset(void) 
{ 
1990/0321    
	newqinfo(&dkmuxinfo); 
	newqinfo(&urpinfo); 
1990/0717    
	urpreset(); 
1990/0312    
} 
 
/* 
1990/0717/sys/src/9/port/devdk.c:456,4611990/0722/sys/src/9/port/devdk.c:456,462 (short | long)
1990/0312    
	 */ 
1990/0707    
	dp->restart = 1; 
	n = getfields((char *)bp->rptr, fields, 4, ' '); 
1990/0722    
	strcpy(dp->name, "dk"); 
1990/0312    
	switch(n){ 
1990/0707    
	case 4: 
		strncpy(dp->name, fields[3], sizeof(dp->name)); 
1990/0717/sys/src/9/port/devdk.c:494,5001990/0722/sys/src/9/port/devdk.c:495,501
1990/0312    
	/* 
	 *  start a process to deal with it 
	 */ 
	sprint(buf, "**csckproc%d**", dp->ncsc); 
1990/0722    
	sprint(buf, "csckproc%d", dp->ncsc); 
1990/0312    
	kproc(buf, dkcsckproc, dp); 
	poperror(); 
 
1990/0717/sys/src/9/port/devdk.c:503,5091990/0722/sys/src/9/port/devdk.c:504,510
1990/0312    
	 */ 
	if(dktimeron == 0){ 
		dktimeron = 1; 
		kproc("**dktimer**", dktimer, 0); 
1990/0722    
		kproc("dktimer", dktimer, 0); 
1990/0312    
	} 
} 
 
1990/0717/sys/src/9/port/devdk.c:592,5991990/0722/sys/src/9/port/devdk.c:593,602
1990/0312    
	Dk *dp; 
 
	/* 
	 *  find a multiplexor with the same name 
1990/0722    
	 *  find a multiplexor with the same name (default dk) 
1990/0312    
	 */ 
1990/0722    
	if(*spec == 0) 
		spec = "dk"; 
1990/0312    
	for(dp = dk; dp < &dk[Ndk]; dp++){ 
		qlock(dp); 
		if(dp->wq && strcmp(spec, dp->name)==0) { 
1990/0722/sys/src/9/port/devdk.c:415,4221990/0830/sys/src/9/port/devdk.c:415,426 (short | long)
1990/0312    
 
	if(bp->base && bp->rptr - bp->base >= 2) 
		bp->rptr -= 2; 
1990/0315    
	else 
		panic("dkoput"); 
1990/0830    
	else { 
		print("dkoput l %d b %ux r %ux w %ux\n", line, bp->base, bp->rptr, 
			bp->wptr); 
		freeb(bp); 
		return; 
	} 
1990/0312    
	bp->rptr[0] = line; 
	bp->rptr[1] = line>>8; 
 
1990/0830/sys/src/9/port/devdk.c:6,141990/0911/sys/src/9/port/devdk.c:6,15 (short | long)
1990/0312    
#include	"io.h" 
#include	"errno.h" 
 
#define NOW (MACHP(0)->ticks) 
#define DPRINT if(0) 
1990/0911    
#define	DPRINT	if(0)	/*kprint*/ 
1990/0312    
 
1990/0911    
#define	NOW	(MACHP(0)->ticks) 
 
1990/0312    
enum { 
	/* 
	 *  configuration parameters 
1990/0830/sys/src/9/port/devdk.c:124,1291990/0911/sys/src/9/port/devdk.c:125,131
1990/0312    
	Chan	*csc;		/* common signalling line */ 
	Line	line[Nline]; 
1990/0707    
	int	restart; 
1990/0911    
	int	urpwindow; 
1990/0312    
}; 
static Dk dk[Ndk]; 
 
1990/0830/sys/src/9/port/devdk.c:395,4011990/0911/sys/src/9/port/devdk.c:397,404
1990/0312    
/* 
 *  we assume that each put is a message. 
 * 
 *  add a 2 byte channel number to the start of each message 
1990/0911    
 *  add a 2 byte channel number to the start of each message, 
 *  low order byte first. 
1990/0312    
 */ 
static void 
dkoput(Queue *q, Block *bp) 
1990/0830/sys/src/9/port/devdk.c:413,4261990/0911/sys/src/9/port/devdk.c:416,422
1990/0312    
	dp = lp->dp; 
	line = lp - dp->line; 
 
	if(bp->base && bp->rptr - bp->base >= 2) 
		bp->rptr -= 2; 
1990/0830    
	else { 
		print("dkoput l %d b %ux r %ux w %ux\n", line, bp->base, bp->rptr, 
			bp->wptr); 
		freeb(bp); 
		return; 
	} 
1990/0911    
	bp = padb(bp, 2); 
1990/0312    
	bp->rptr[0] = line; 
	bp->rptr[1] = line>>8; 
 
1990/0830/sys/src/9/port/devdk.c:432,4431990/0911/sys/src/9/port/devdk.c:428,440
1990/0312    
} 
 
/* 
1990/0707    
 *  configure a datakit multiplexor.  this takes 4 arguments separated 
1990/0911    
 *  configure a datakit multiplexor.  this takes 5 arguments separated 
1990/0312    
 *  by spaces: 
 *	the line number of the common signalling channel (must be > 0) 
 *	the number of lines in the device (optional) 
1990/0707    
 *	the word `restart' or `norestart' (optional/default==restart) 
1990/0312    
 *	the name of the dk (optional) 
1990/0911    
 *	the name of the dk (default==dk) 
 *	the urp window size (default==WS_2K) 
1990/0312    
 * 
 *  we can configure only once 
 */ 
1990/0830/sys/src/9/port/devdk.c:445,4511990/0911/sys/src/9/port/devdk.c:442,448
1990/0312    
dkmuxconfig(Dk *dp, Block *bp) 
{ 
	Chan *c; 
1990/0707    
	char *fields[4]; 
1990/0911    
	char *fields[5]; 
1990/0312    
	int n; 
	char buf[64]; 
	static int dktimeron; 
1990/0830/sys/src/9/port/devdk.c:459,4671990/0911/sys/src/9/port/devdk.c:456,467
1990/0312    
	 *  parse 
	 */ 
1990/0707    
	dp->restart = 1; 
	n = getfields((char *)bp->rptr, fields, 4, ' '); 
1990/0911    
	n = getfields((char *)bp->rptr, fields, 5, ' '); 
1990/0722    
	strcpy(dp->name, "dk"); 
1990/0911    
	dp->urpwindow = WS_2K; 
1990/0312    
	switch(n){ 
1990/0911    
	case 5: 
		dp->urpwindow = strtoul(fields[4], 0, 0); 
1990/0707    
	case 4: 
		strncpy(dp->name, fields[3], sizeof(dp->name)); 
1990/0312    
	case 3: 
1990/0830/sys/src/9/port/devdk.c:481,4861990/0911/sys/src/9/port/devdk.c:481,488
1990/0312    
		dp->lines = 16; 
		error(0, Ebadarg); 
	} 
1990/0911    
	DPRINT("dkmuxconfig: ncsc=%d, lines=%d, restart=%d, name=\"%s\"\n", 
		dp->ncsc, dp->lines, dp->restart, dp->name); 
1990/0312    
 
	/* 
	 *  open a stream for the csc and push urp onto it 
1990/0830/sys/src/9/port/devdk.c:499,5051990/0911/sys/src/9/port/devdk.c:501,507
1990/0312    
	/* 
	 *  start a process to deal with it 
	 */ 
1990/0722    
	sprint(buf, "csckproc%d", dp->ncsc); 
1990/0911    
	sprint(buf, "csc.%s.%d", dp->name, dp->ncsc); 
1990/0312    
	kproc(buf, dkcsckproc, dp); 
	poperror(); 
 
1990/0830/sys/src/9/port/devdk.c:556,5621990/0911/sys/src/9/port/devdk.c:558,563
1990/0312    
dkreset(void) 
{ 
1990/0321    
	newqinfo(&dkmuxinfo); 
1990/0717    
	urpreset(); 
1990/0312    
} 
 
/* 
1990/0830/sys/src/9/port/devdk.c:866,8731990/0911/sys/src/9/port/devdk.c:867,876
1990/0312    
 
	if(dp->csc == 0) 
		return -1; 
	if(waserror()) 
1990/0911    
	if(waserror()){ 
		print("dkmesg: error\n"); 
1990/0312    
		return -1; 
1990/0911    
	} 
1990/0312    
	d.type = type; 
	d.srv = srv; 
	d.param0l = p0; 
1990/0830/sys/src/9/port/devdk.c:977,9831990/0911/sys/src/9/port/devdk.c:980,986
1990/0312    
	 *  tell the controller we want to make a call 
	 */ 
	DPRINT("dialout\n"); 
	dkmesg(dp, t_val, d_val, line, W_WINDOW(WS_2K,WS_2K,2)); 
1990/0911    
	dkmesg(dp, t_val, d_val, line, W_WINDOW(dp->urpwindow,dp->urpwindow,2)); 
1990/0312    
 
	/* 
	 *  if redial, wait for a dial tone (otherwise we might send 
1990/0830/sys/src/9/port/devdk.c:1318,13251990/0911/sys/src/9/port/devdk.c:1321,1331
1990/0617    
	/* 
	 *  tell datakit we've rebooted. It should close all channels. 
	 */ 
1990/0707    
	if(dp->restart) 
1990/0911    
	if(dp->restart) { 
		DPRINT("dkcsckproc: restart %s\n", dp->name); 
1990/0707    
		dkmesg(dp, T_ALIVE, D_RESTART, 0, 0); 
1990/0911    
	} 
	DPRINT("dkcsckproc: closeall %s\n", dp->name); 
1990/0617    
	dkmesg(dp, T_CHG, D_CLOSEALL, 0, 0); 
1990/0312    
 
	/* 
1990/0830/sys/src/9/port/devdk.c:1484,14901990/0911/sys/src/9/port/devdk.c:1490,1497
1990/0312    
	Dk *dp; 
	Line *lp; 
 
	waserror(); 
1990/0911    
	while(waserror()) 
		print("dktimer: error\n"); 
1990/0312    
 
	for(;;){ 
		/* 
1990/0911/sys/src/9/port/devdk.c:1100,11081990/0925/sys/src/9/port/devdk.c:1100,1106 (short | long)
1990/0312    
		n = streamread(dc, dialstr, sizeof(dialstr)-1); 
		DPRINT("returns %d\n", n); 
		if(n <= 0) 
1990/0617    
{print("bad n\n"); 
1990/0312    
			error(0, Eio); 
1990/0617    
} 
1990/0312    
		dialstr[n] = 0; 
		DPRINT("dialstr = %s\n", dialstr); 
 
1990/0911/sys/src/9/port/devdk.c:1112,11181990/0925/sys/src/9/port/devdk.c:1110,1115
1990/0312    
		n = getfields(dialstr, line, 12, '\n'); 
		if (n < 2) { 
			DPRINT("bad dialstr from dk (1 line)\n"); 
1990/0617    
print("bad dialstr %d '%s'\n", n, dialstr); 
1990/0312    
			error(0, Eio); 
		} 
 
1990/0925/sys/src/9/port/devdk.c:499,5041990/1004/sys/src/9/port/devdk.c:499,512 (short | long)
1990/0312    
	dp->csc = c; 
 
	/* 
1990/1004    
	 *  tell datakit we've rebooted. It should close all channels. 
	 */ 
	if(dp->restart) { 
		DPRINT("dkmuxconfig: restart %s\n", dp->name); 
		dkmesg(dp, T_ALIVE, D_RESTART, 0, 0); 
	} 
 
	/* 
1990/0312    
	 *  start a process to deal with it 
	 */ 
1990/0911    
	sprint(buf, "csc.%s.%d", dp->name, dp->ncsc); 
1990/0925/sys/src/9/port/devdk.c:1314,13291990/1004/sys/src/9/port/devdk.c:1322,1327
1990/0312    
	int i; 
 
	dp = (Dk *)a; 
1990/0617    
                 
	/* 
	 *  tell datakit we've rebooted. It should close all channels. 
	 */ 
1990/0911    
	if(dp->restart) { 
		DPRINT("dkcsckproc: restart %s\n", dp->name); 
1990/0707    
		dkmesg(dp, T_ALIVE, D_RESTART, 0, 0); 
1990/0911    
	} 
	DPRINT("dkcsckproc: closeall %s\n", dp->name); 
1990/0617    
	dkmesg(dp, T_CHG, D_CLOSEALL, 0, 0); 
1990/0312    
 
	/* 
	 *  loop forever listening 
1990/1004/sys/src/9/port/devdk.c:421,4271990/1011/sys/src/9/port/devdk.c:421,427 (short | long)
1990/0312    
	bp->rptr[1] = line>>8; 
 
1990/0509    
	if(QFULL(dp->wq->next)){ 
		print("dk wq full\n"); 
1990/1011    
/*		print("dk wq full\n");/**/ 
1990/0509    
		freeb(bp); 
	} else 
		PUTNEXT(dp->wq, bp); 
1990/1011/sys/src/9/port/devdk.c:118,1241990/1018/sys/src/9/port/devdk.c:118,124 (short | long)
1990/0312    
struct Dk { 
	QLock; 
	int	ref; 
	char	name[64];	/* dk name */	 
1990/1018    
	char	name[64];	/* dk name */ 
1990/0312    
	Queue	*wq;		/* dk output queue */ 
	int	lines;		/* number of lines */ 
	int	ncsc;		/* csc line number */ 
1990/1011/sys/src/9/port/devdk.c:420,4301990/1018/sys/src/9/port/devdk.c:420,427
1990/0312    
	bp->rptr[0] = line; 
	bp->rptr[1] = line>>8; 
 
1990/0509    
	if(QFULL(dp->wq->next)){ 
1990/1011    
/*		print("dk wq full\n");/**/ 
1990/0509    
		freeb(bp); 
	} else 
		PUTNEXT(dp->wq, bp); 
1990/1018    
	FLOWCTL(dp->wq); 
	PUTNEXT(dp->wq, bp); 
1990/0312    
} 
 
/* 
1990/1018/sys/src/9/port/devdk.c:206,2111990/1022/sys/src/9/port/devdk.c:206,212 (short | long)
1990/0312    
dkmuxopen(Queue *q, Stream *s) 
{ 
	Dk *dp; 
1990/1022    
	Line *lp; 
1990/0312    
	int i; 
 
	for(dp = dk; dp < &dk[Ndk]; dp++){ 
1990/1018/sys/src/9/port/devdk.c:222,2271990/1022/sys/src/9/port/devdk.c:223,231
1990/0312    
			dp->lines = 16; 
			dp->name[0] = 0; 
			dp->wq = WR(q); 
1990/1022    
			for(lp = dp->line; lp < &dp->line[Nline]; lp++) 
				if(lp->state != 0) 
					panic("dkmuxopen l %d s %lux", lp-dp->line, lp->state); 
1990/0312    
			qunlock(dp); 
			return; 
		} 
1990/1018/sys/src/9/port/devdk.c:1368,13821990/1022/sys/src/9/port/devdk.c:1372,1386
1990/0312    
{ 
	Line *lp; 
 
	if (line <= 0 || line >= dp->lines) { 
		/* tell controller this line is not in use */ 
		dkmesg(dp, T_CHG, D_CLOSE, line, 0); 
		return; 
	} 
	lp = &dp->line[line]; 
	switch (dialp->srv) { 
 
	case D_CLOSE:		/* remote shutdown */ 
1990/1022    
		if (line <= 0 || line >= dp->lines) { 
			/* tell controller this line is not in use */ 
			dkmesg(dp, T_CHG, D_CLOSE, line, 0); 
			return; 
		} 
		lp = &dp->line[line]; 
1990/0312    
		switch (lp->state) { 
 
		case Ldialing: 
1990/1018/sys/src/9/port/devdk.c:1407,14121990/1022/sys/src/9/port/devdk.c:1411,1422
1990/0312    
		break; 
	 
	case D_ISCLOSED:	/* acknowledging a local shutdown */ 
1990/1022    
		if (line <= 0 || line >= dp->lines) { 
			/* tell controller this line is not in use */ 
			dkmesg(dp, T_CHG, D_CLOSE, line, 0); 
			return; 
		} 
		lp = &dp->line[line]; 
1990/0312    
		switch (lp->state) { 
		case Llclose: 
		case Lclosed: 
1990/1018/sys/src/9/port/devdk.c:1421,14261990/1022/sys/src/9/port/devdk.c:1431,1466
1990/0312    
		} 
		break; 
 
1990/1022    
	case D_CLOSEALL: 
		for(line = dp->ncsc+1; line < dp->lines; line++){ 
			lp = &dp->line[line]; 
			switch (lp->state) { 
	 
			case Ldialing: 
				/* simulate a failed connection */ 
				dkreplymesg(dp, (Dkmsg *)0, line); 
				lp->state = Lrclose; 
				break; 
	 
			case Lrclose: 
			case Lconnected: 
			case Llistening: 
			case Lackwait: 
				dkhangup(lp); 
				lp->state = Lrclose; 
				break; 
	 
			case Lopened: 
				break; 
	 
			case Llclose: 
			case Lclosed: 
				lp->state = Lclosed; 
				break; 
			} 
		} 
		break; 
 
1990/0312    
	default: 
		print("unrecognized T_CHG\n"); 
	} 
1990/1018/sys/src/9/port/devdk.c:1503,15091990/1022/sys/src/9/port/devdk.c:1543,1549
1990/0312    
			 *  remind controller of dead lines and 
			 *  timeout calls that take to long 
			 */ 
			for (i=0; i<dp->lines; i++){ 
1990/1022    
			for (i=dp->ncsc+1; i<dp->lines; i++){ 
1990/0312    
				lp = &dp->line[i]; 
				switch(lp->state){ 
				case Llclose: 
1990/1022/sys/src/9/port/devdk.c:206,2121990/1024/sys/src/9/port/devdk.c:206,211 (short | long)
1990/0312    
dkmuxopen(Queue *q, Stream *s) 
{ 
	Dk *dp; 
1990/1022    
	Line *lp; 
1990/0312    
	int i; 
 
	for(dp = dk; dp < &dk[Ndk]; dp++){ 
1990/1022/sys/src/9/port/devdk.c:223,2311990/1024/sys/src/9/port/devdk.c:222,227
1990/0312    
			dp->lines = 16; 
			dp->name[0] = 0; 
			dp->wq = WR(q); 
1990/1022    
			for(lp = dp->line; lp < &dp->line[Nline]; lp++) 
				if(lp->state != 0) 
					panic("dkmuxopen l %d s %lux", lp-dp->line, lp->state); 
1990/0312    
			qunlock(dp); 
			return; 
		} 
1990/1024/sys/src/9/port/devdk.c:116,1331990/1101/sys/src/9/port/devdk.c:116,136 (short | long)
1990/0315    
 *  dkmux line discipline is pushed onto. 
1990/0312    
 */ 
struct Dk { 
	QLock; 
	int	ref; 
1990/1101    
	Lock; 
	int	opened; 
1990/1018    
	char	name[64];	/* dk name */ 
1990/0312    
	Queue	*wq;		/* dk output queue */ 
1990/1101    
	Stream	*s; 
1990/0312    
	int	lines;		/* number of lines */ 
	int	ncsc;		/* csc line number */ 
	Chan	*csc;		/* common signalling line */ 
1990/1101    
	Chan	*csc; 
1990/0312    
	Line	line[Nline]; 
1990/0707    
	int	restart; 
1990/0911    
	int	urpwindow; 
1990/1101    
	Rendez	timer; 
1990/0312    
}; 
static Dk dk[Ndk]; 
1990/1101    
static Lock dklock; 
1990/0312    
 
/* 
 *  conversation states (for Line.state) 
1990/1024/sys/src/9/port/devdk.c:178,1851990/1101/sys/src/9/port/devdk.c:181,189
1990/0312    
 *  predeclared 
 */ 
Chan*		dkattach(char*); 
static void	dkmuxconfig(Dk*, Block*); 
static int	dkmesg(Dk*, int, int, int, int); 
1990/1101    
static void	dkmuxconfig(Queue*, Block*); 
static Chan*	dkopenline(Dk*, int); 
static int	dkmesg(Chan*, int, int, int, int); 
1990/0312    
static void	dkcsckproc(void*); 
static int	dklisten(Chan*); 
static void	dkanswer(Chan*, int, int); 
1990/1024/sys/src/9/port/devdk.c:186,1941990/1101/sys/src/9/port/devdk.c:190,199
1990/0312    
static void	dkwindow(Chan*); 
static void	dkcall(int, Chan*, char*, char*, char*); 
static void	dktimer(void*); 
static void	dkchgmesg(Dk*, Dkmsg*, int); 
1990/1101    
static void	dkchgmesg(Chan*, Dk*, Dkmsg*, int); 
1990/0312    
static void	dkreplymesg(Dk*, Dkmsg*, int); 
Chan*		dkopen(Chan*, int); 
1990/1101    
static void	dkhangup(Line*); 
1990/0312    
 
/* 
 *  the datakit multiplexor stream module definition 
1990/1024/sys/src/9/port/devdk.c:200,2351990/1101/sys/src/9/port/devdk.c:205,253
1990/0312    
Qinfo dkmuxinfo = { dkmuxiput, dkmuxoput, dkmuxopen, dkmuxclose, "dkmux" }; 
 
/* 
 *  a new dkmux.  find a free dk structure and assign it to this queue. 
 */ 
static void 
dkmuxopen(Queue *q, Stream *s) 
1990/1101    
 *  Look for a dk struct with a name.  If none exists,  create one. 
 */  
static Dk * 
dkalloc(char *name) 
1990/0312    
{ 
	Dk *dp; 
	int i; 
1990/1101    
	Dk *freep; 
1990/0312    
 
1990/1101    
	lock(&dklock); 
	freep = 0; 
1990/0312    
	for(dp = dk; dp < &dk[Ndk]; dp++){ 
		if(dp->wq == 0){ 
			qlock(dp); 
			if(dp->wq) { 
				/* someone was faster than us */ 
				qunlock(dp); 
				continue; 
			} 
			q->ptr = q->other->ptr = (void *)dp; 
			dp->csc = 0; 
			dp->ncsc = 4; 
			dp->lines = 16; 
			dp->name[0] = 0; 
			dp->wq = WR(q); 
			qunlock(dp); 
			return; 
1990/1101    
		if(strcmp(name, dp->name) == 0){ 
			unlock(&dklock); 
			return dp; 
1990/0312    
		} 
1990/1101    
		if(dp->name[0] == 0) 
			freep = dp; 
1990/0312    
	} 
	error(0, Enoifc); 
1990/1101    
	if(freep == 0){ 
		unlock(&dklock); 
		error(0, Enoifc); 
	} 
	dp = freep; 
	dp->opened = 0; 
	dp->s = 0; 
	dp->ncsc = 1; 
	strncpy(dp->name, name, sizeof(freep->name)); 
	unlock(&dklock); 
	return dp; 
1990/0312    
} 
 
/* 
1990/1101    
 *  a new dkmux.  find a free dk structure and assign it to this queue. 
 *  when we get though here dp->s is meaningful and the name is set to "/". 
 */ 
static void 
dkmuxopen(Queue *q, Stream *s) 
{ 
	RD(q)->ptr = s; 
	WR(q)->ptr = 0; 
} 
 
/* 
1990/0312    
 *  close down a dkmux 
 */ 
static void 
1990/1024/sys/src/9/port/devdk.c:236,2481990/1101/sys/src/9/port/devdk.c:254,283
1990/0312    
dkmuxclose(Queue *q) 
{ 
	Dk *dp; 
1990/1101    
	int i; 
1990/0312    
 
	dp = (Dk *)q->ptr; 
	qlock(dp); 
	if(dp->csc) 
		close(dp->csc); 
	dp->wq = 0; 
	qunlock(dp); 
1990/1101    
	dp = WR(q)->ptr; 
	if(dp == 0) 
		return; 
 
	/* 
	 *  disallow new dkstopens() on this line. 
	 *  the lock syncs with dkstopen(). 
	 */ 
	lock(dp); 
	dp->opened = 0; 
	unlock(dp); 
 
	/* 
	 *  hang up all datakit connections 
	 */ 
	for(i=dp->ncsc; i < dp->lines; i++) 
		dkhangup(&dp->line[i]); 
 
	/* 
	 *  wakeup the timer so it can die 
	 */ 
	wakeup(&dp->timer); 
1990/0312    
} 
 
/* 
1990/1024/sys/src/9/port/devdk.c:251,2621990/1101/sys/src/9/port/devdk.c:286,294
1990/0312    
static void 
dkmuxoput(Queue *q, Block *bp) 
{ 
	Dk *dp; 
                 
	dp = (Dk *)q->ptr; 
	if(bp->type != M_DATA){ 
		if(streamparse("config", bp)) 
			dkmuxconfig(dp, bp); 
1990/1101    
			dkmuxconfig(q, bp); 
1990/0312    
		else 
			PUTNEXT(q, bp); 
		return; 
1990/1024/sys/src/9/port/devdk.c:272,2781990/1101/sys/src/9/port/devdk.c:304,310
1990/0312    
 * 
 *  Simplifying assumption:  one put == one message && the channel number 
 *	is in the first block.  If this isn't true, demultiplexing will not 
  *	work. 
1990/1101    
 *	work. 
1990/0312    
 */ 
static void 
dkmuxiput(Queue *q, Block *bp) 
1990/1024/sys/src/9/port/devdk.c:281,2861990/1101/sys/src/9/port/devdk.c:313,326
1990/0312    
	Line *lp; 
	int line; 
 
1990/1101    
	/* 
	 *  not configured yet 
	 */ 
	if(q->other->ptr == 0){ 
		freeb(bp); 
		return; 
	} 
 
1990/0312    
	dp = (Dk *)q->ptr; 
	if(bp->type != M_DATA){ 
		PUTNEXT(q, bp); 
1990/1024/sys/src/9/port/devdk.c:331,3391990/1101/sys/src/9/port/devdk.c:371,385
1990/0312    
	dp = &dk[s->dev]; 
	q->other->ptr = q->ptr = lp = &dp->line[s->id]; 
	lp->dp = dp; 
	lp->rq = q; 
1990/0511    
	if(lp->state == Lclosed) 
1990/1101    
	lock(dp); 
	if(dp->opened==0 || streamenter(dp->s)<0){ 
		unlock(dp); 
		error(0, Ehungup); 
	} 
	unlock(dp); 
	if(lp->state==Lclosed) 
1990/0511    
		lp->state = Lopened; 
1990/1101    
	lp->rq = q; 
1990/0312    
} 
 
/* 
1990/1024/sys/src/9/port/devdk.c:344,3851990/1101/sys/src/9/port/devdk.c:390,461
1990/0312    
{ 
	Dk *dp; 
	Line *lp; 
1990/1101    
	Chan *c; 
1990/0312    
 
	lp = (Line *)q->ptr; 
	dp = lp->dp; 
 
	/* 
	 *  shake hands with dk 
1990/1101    
	 *  if we never got going, we're done 
1990/0312    
	 */ 
1990/1101    
	if(lp->rq == 0){ 
		lp->state = Lclosed;  
		return; 
	} 
 
	/* 
	 *  decrement ref count on mux'd line 
	 */ 
	streamexit(dp->s, 0); 
 
	/* 
	 *  these states don't need the datakit 
	 */ 
1990/0312    
	switch(lp->state){ 
	case Lclosed: 
	case Llclose: 
		break; 
1990/1101    
	case Lopened: 
		lp->state = Lclosed; 
		goto out; 
	} 
1990/0312    
 
1990/1101    
	c = 0; 
	if(waserror()){ 
		lp->state = Lclosed; 
		if(c) 
			close(c); 
		goto out; 
	}	 
	c = dkopenline(dp, dp->ncsc); 
 
	/* 
	 *  shake hands with dk 
	 */ 
	switch(lp->state){ 
1990/0312    
	case Lrclose: 
		dkmesg(dp, T_CHG, D_CLOSE, lp - dp->line, 0); 
1990/1101    
		dkmesg(c, T_CHG, D_CLOSE, lp - dp->line, 0); 
1990/0312    
		lp->state = Lclosed; 
		break; 
 
	case Lackwait: 
		dkmesg(dp, T_CHG, D_CLOSE, lp - dp->line, 0); 
1990/1101    
		dkmesg(c, T_CHG, D_CLOSE, lp - dp->line, 0); 
1990/0312    
		lp->state = Llclose; 
		break; 
 
	case Llistening: 
		dkmesg(dp, T_CHG, D_CLOSE, lp - dp->line, 0); 
1990/1101    
		dkmesg(c, T_CHG, D_CLOSE, lp - dp->line, 0); 
1990/0312    
		lp->state = Llclose; 
		break; 
 
	case Lconnected: 
		dkmesg(dp, T_CHG, D_CLOSE, lp - dp->line, 0); 
1990/1101    
		dkmesg(c, T_CHG, D_CLOSE, lp - dp->line, 0); 
1990/0312    
		lp->state = Llclose; 
		break; 
                 
	case Lopened: 
		lp->state = Lclosed; 
	} 
1990/1101    
	poperror(); 
	close(c); 
1990/0312    
 
1990/1101    
out: 
1990/0312    
	qlock(lp); 
	lp->rq = 0; 
	qunlock(lp); 
1990/1024/sys/src/9/port/devdk.c:436,4731990/1101/sys/src/9/port/devdk.c:512,559
1990/0312    
 *  we can configure only once 
 */ 
static void 
dkmuxconfig(Dk *dp, Block *bp) 
1990/1101    
dkmuxconfig(Queue *q, Block *bp) 
1990/0312    
{ 
	Chan *c; 
1990/1101    
	Dk *dp; 
1990/0911    
	char *fields[5]; 
1990/0312    
	int n; 
	char buf[64]; 
	static int dktimeron; 
1990/1101    
	char name[NAMELEN]; 
	int lines; 
	int ncsc; 
	int restart; 
	int window; 
1990/0312    
 
	if(dp->csc != 0){ 
1990/1101    
	if(WR(q)->ptr){ 
1990/0312    
		freeb(bp); 
		error(0, Ebadarg); 
1990/1101    
		error(0, Egreg); 
1990/0312    
	} 
 
	/* 
1990/1101    
	 *  defaults 
	 */ 
	ncsc = 1; 
	restart = 1; 
	lines = 16; 
	window = WS_2K; 
	strcpy(name, "dk"); 
 
	/* 
1990/0312    
	 *  parse 
	 */ 
1990/0707    
	dp->restart = 1; 
1990/0911    
	n = getfields((char *)bp->rptr, fields, 5, ' '); 
1990/0722    
	strcpy(dp->name, "dk"); 
1990/0911    
	dp->urpwindow = WS_2K; 
1990/0312    
	switch(n){ 
1990/0911    
	case 5: 
		dp->urpwindow = strtoul(fields[4], 0, 0); 
1990/1101    
		window = strtoul(fields[4], 0, 0); 
1990/0707    
	case 4: 
		strncpy(dp->name, fields[3], sizeof(dp->name)); 
1990/1101    
		strncpy(name, fields[3], sizeof(name)); 
1990/0312    
	case 3: 
1990/0707    
		if(strcmp(fields[2], "restart")!=0) 
			dp->restart = 0; 
1990/1101    
			restart = 0; 
1990/0312    
	case 2: 
		dp->lines = strtoul(fields[1], 0, 0); 
1990/1101    
		lines = strtoul(fields[1], 0, 0); 
1990/0312    
	case 1: 
		dp->ncsc = strtoul(fields[0], 0, 0); 
1990/1101    
		ncsc = strtoul(fields[0], 0, 0); 
1990/0312    
		break; 
	default: 
		freeb(bp); 
1990/1024/sys/src/9/port/devdk.c:474,5221990/1101/sys/src/9/port/devdk.c:560,613
1990/0312    
		error(0, Ebadarg); 
	} 
	freeb(bp); 
	if(dp->ncsc <= 0 || dp->lines <= dp->ncsc){ 
		dp->lines = 16; 
1990/1101    
	if(ncsc <= 0 || lines <= ncsc) 
1990/0312    
		error(0, Ebadarg); 
	} 
1990/0911    
	DPRINT("dkmuxconfig: ncsc=%d, lines=%d, restart=%d, name=\"%s\"\n", 
		dp->ncsc, dp->lines, dp->restart, dp->name); 
1990/0312    
 
	/* 
	 *  open a stream for the csc and push urp onto it 
1990/1101    
	 *  set up 
1990/0312    
	 */ 
	c = 0; 
	if(waserror()){ 
		if(c) 
			close(c); 
		nexterror(); 
1990/1101    
	dp = dkalloc(name); 
	lock(dp); 
	if(dp->opened){ 
		unlock(dp); 
		error(0, Ebadarg); 
1990/0312    
	} 
	c = dkattach(dp->name); 
	c->qid = STREAMQID(dp->ncsc, Sdataqid); 
	dkopen(c, ORDWR); 
	dp->csc = c; 
1990/1101    
	dp->ncsc = ncsc; 
	dp->lines = lines; 
	dp->restart = restart; 
	dp->urpwindow = window; 
	dp->s = RD(q)->ptr; 
	q->ptr = q->other->ptr = dp; 
	dp->opened = 1; 
	dp->wq = WR(q); 
	unlock(dp); 
1990/0312    
 
	/* 
1990/1101    
	 *  open csc here so that boot, dktimer, and dkcsckproc aren't 
	 *  all fighting for it at once. 
	 */ 
	dp->csc = dkopenline(dp, dp->ncsc); 
 
	/* 
1990/1004    
	 *  tell datakit we've rebooted. It should close all channels. 
1990/1101    
	 *  do this here to get it done before trying to open a channel. 
1990/1004    
	 */ 
	if(dp->restart) { 
		DPRINT("dkmuxconfig: restart %s\n", dp->name); 
		dkmesg(dp, T_ALIVE, D_RESTART, 0, 0); 
1990/1101    
		DPRINT("dktimer: restart %s\n", dp->name); 
		dkmesg(dp->csc, T_ALIVE, D_RESTART, 0, 0); 
1990/1004    
	} 
 
	/* 
1990/0312    
	 *  start a process to deal with it 
1990/1101    
	 *  start a process to listen to csc messages 
1990/0312    
	 */ 
1990/0911    
	sprint(buf, "csc.%s.%d", dp->name, dp->ncsc); 
1990/0312    
	kproc(buf, dkcsckproc, dp); 
	poperror(); 
 
	/* 
	 *  start a keepalive process if one doesn't exist 
1990/1101    
	 *  start a keepalive process 
1990/0312    
	 */ 
	if(dktimeron == 0){ 
		dktimeron = 1; 
1990/0722    
		kproc("dktimer", dktimer, 0); 
1990/0312    
	} 
1990/1101    
	sprint(buf, "timer.%s.%d", dp->name, dp->ncsc); 
	kproc(buf, dktimer, dp); 
1990/0312    
} 
 
/* 
1990/1024/sys/src/9/port/devdk.c:607,6231990/1101/sys/src/9/port/devdk.c:698,708
1990/0312    
	 */ 
1990/0722    
	if(*spec == 0) 
		spec = "dk"; 
1990/0312    
	for(dp = dk; dp < &dk[Ndk]; dp++){ 
		qlock(dp); 
		if(dp->wq && strcmp(spec, dp->name)==0) { 
			dp->ref++; 
			qunlock(dp); 
			break; 
		} 
		qunlock(dp); 
	} 
	if(dp == &dk[Ndk]) 
		error(0, Enoifc); 
1990/1101    
	dp = dkalloc(spec); 
 
	/* 
	 *  return the new channel 
	 */ 
1990/0312    
	c = devattach('k', spec); 
	c->dev = dp - dk; 
	return c; 
1990/1024/sys/src/9/port/devdk.c:626,6371990/1101/sys/src/9/port/devdk.c:711,716
1990/0312    
Chan* 
dkclone(Chan *c, Chan *nc) 
{ 
	Dk *dp; 
                 
	dp = &dk[c->dev]; 
	qlock(dp); 
	dp->ref++; 
	qunlock(dp); 
	return devclone(c, nc); 
} 
 
1990/1024/sys/src/9/port/devdk.c:679,6881990/1101/sys/src/9/port/devdk.c:758,767
1990/0319    
			error(0, Ebadarg); 
	} else switch(STREAMTYPE(c->qid)){ 
	case Dcloneqid: 
1990/1101    
		dp = &dk[c->dev]; 
1990/0319    
		/* 
1990/0312    
		 *  get an unused device and open it's control file 
		 */ 
		dp = &dk[c->dev]; 
		end = &dp->line[dp->lines]; 
		for(lp = &dp->line[dp->ncsc+1]; lp < end; lp++){ 
			if(lp->state == Lclosed && canqlock(lp)){ 
1990/1024/sys/src/9/port/devdk.c:696,7041990/1101/sys/src/9/port/devdk.c:775,784
1990/0312    
		} 
		if(lp == end) 
			error(0, Enodev); 
1990/1101    
		lp->state = Lopened; 
		qunlock(lp); 
1990/0312    
		streamopen(c, &dkinfo); 
		pushq(c->stream, &urpinfo); 
1990/0511    
		qunlock(lp); 
1990/0319    
		break; 
	case Dlistenqid: 
1990/0312    
		/* 
1990/1024/sys/src/9/port/devdk.c:746,7611990/1101/sys/src/9/port/devdk.c:826,833
1990/0312    
void	  
dkclose(Chan *c) 
{ 
	Dk *dp; 
                 
1990/0511    
	/* real closing happens in dkstclose */ 
1990/0319    
	if(c->stream) 
1990/0312    
		streamclose(c); 
                 
	dp = &dk[c->dev]; 
	qlock(dp); 
	dp->ref--; 
	qunlock(dp); 
} 
 
long	  
1990/1024/sys/src/9/port/devdk.c:862,8771990/1101/sys/src/9/port/devdk.c:934,968
1990/0312    
} 
 
/* 
1990/1101    
 *  open the common signalling channel 
 */ 
static Chan* 
dkopenline(Dk *dp, int line) 
{ 
	Chan *c; 
 
	c = 0; 
	if(waserror()){ 
		if(c) 
			close(c); 
		nexterror(); 
	} 
	c = dkattach(dp->name); 
	c->qid = STREAMQID(line, Sdataqid); 
	dkopen(c, ORDWR); 
	poperror(); 
 
	return c; 
} 
 
/* 
1990/0312    
 *  send a message to the datakit on the common signaling line 
 */ 
static int 
dkmesg(Dk *dp, int type, int srv, int p0, int p1) 
1990/1101    
dkmesg(Chan *c, int type, int srv, int p0, int p1) 
1990/0312    
{ 
	Dkmsg d; 
	Block *bp; 
 
	if(dp->csc == 0) 
		return -1; 
1990/0911    
	if(waserror()){ 
		print("dkmesg: error\n"); 
1990/0312    
		return -1; 
1990/1024/sys/src/9/port/devdk.c:888,8941990/1101/sys/src/9/port/devdk.c:979,985
1990/0312    
	d.param3h = 0; 
	d.param4l = 0; 
	d.param4h = 0; 
	streamwrite(dp->csc, (char *)&d, sizeof(Dkmsg), 1); 
1990/1101    
	streamwrite(c, (char *)&d, sizeof(Dkmsg), 1); 
1990/0312    
	poperror(); 
	return 0; 
} 
1990/1024/sys/src/9/port/devdk.c:914,9211990/1101/sys/src/9/port/devdk.c:1005,1013
1990/0312    
	Dk *dp; 
	Line *lp; 
	Chan *dc; 
1990/1101    
	Chan *csc; 
1990/0707    
	char *bang, *dot; 
1990/0312    
                 
1990/1101    
	 
1990/0312    
	line = STREAMID(c->qid); 
	dp = &dk[c->dev]; 
	lp = &dp->line[line]; 
1990/1024/sys/src/9/port/devdk.c:968,9831990/1101/sys/src/9/port/devdk.c:1060,1081
1990/0312    
	} 
 
	/* 
	 *  open the data file 
1990/1101    
	 *  close temporary channels on error 
1990/0312    
	 */ 
	dc = dkattach(dp->name); 
1990/1101    
	dc = 0; 
	csc = 0; 
1990/0312    
	if(waserror()){ 
		close(dc); 
1990/1101    
		if(csc) 
			close(csc); 
		if(dc) 
			close(dc); 
1990/0312    
		nexterror(); 
	} 
	dc->qid = STREAMQID(line, Sdataqid); 
	dkopen(dc, ORDWR); 
 
1990/1101    
	/* 
	 *  open the data file 
	 */ 
	dc = dkopenline(dp, line); 
1990/0312    
	lp->calltolive = 4; 
	lp->state = Ldialing; 
 
1990/1024/sys/src/9/port/devdk.c:985,9911990/1101/sys/src/9/port/devdk.c:1083,1092
1990/0312    
	 *  tell the controller we want to make a call 
	 */ 
	DPRINT("dialout\n"); 
1990/0911    
	dkmesg(dp, t_val, d_val, line, W_WINDOW(dp->urpwindow,dp->urpwindow,2)); 
1990/1101    
	csc = dkopenline(dp, dp->ncsc); 
	dkmesg(csc, t_val, d_val, line, W_WINDOW(dp->urpwindow,dp->urpwindow,2)); 
	close(csc); 
	csc = 0; 
1990/0312    
 
	/* 
	 *  if redial, wait for a dial tone (otherwise we might send 
1990/1024/sys/src/9/port/devdk.c:1087,10991990/1101/sys/src/9/port/devdk.c:1188,1198
1990/0312    
	/* 
	 *  open the data file 
	 */ 
	dc = dkattach(dp->name); 
1990/1101    
	dc = dkopenline(dp, STREAMID(c->qid)); 
1990/0312    
	if(waserror()){ 
		close(dc); 
		nexterror(); 
	} 
	dc->qid = STREAMQID(STREAMID(c->qid), Sdataqid); 
	dkopen(dc, ORDWR); 
 
	/* 
	 *  wait for a call in 
1990/1024/sys/src/9/port/devdk.c:1316,13251990/1101/sys/src/9/port/devdk.c:1415,1428
1990/0312    
	Dk *dp; 
	Dkmsg d; 
	int line; 
	int i; 
 
	dp = (Dk *)a; 
1990/1101    
	dp = a; 
1990/0312    
 
1990/1101    
	if(waserror()){ 
		close(dp->csc); 
		return; 
	} 
 
1990/0312    
	/* 
	 *  loop forever listening 
	 */ 
1990/1024/sys/src/9/port/devdk.c:1326,13311990/1101/sys/src/9/port/devdk.c:1429,1436
1990/0312    
	for(;;){ 
		n = streamread(dp->csc, (char *)&d, (long)sizeof(d)); 
		if(n != sizeof(d)){ 
1990/1101    
			if(n == 0) 
				error(0, Ehungup); 
1990/0312    
			print("strange csc message %d\n", n); 
			continue; 
		} 
1990/1024/sys/src/9/port/devdk.c:1334,13401990/1101/sys/src/9/port/devdk.c:1439,1445
1990/0312    
		switch (d.type) { 
 
		case T_CHG:	/* controller wants to close a line */ 
			dkchgmesg(dp, &d, line); 
1990/1101    
			dkchgmesg(dp->csc, dp, &d, line); 
1990/0312    
			break; 
		 
		case T_REPLY:	/* reply to a dial request */ 
1990/1024/sys/src/9/port/devdk.c:1346,13561990/1101/sys/src/9/port/devdk.c:1451,1458
1990/0312    
			break; 
		 
		case T_RESTART:	/* datakit reboot */ 
			print("dk restart\n"); 
			if(line >=0 && line<dp->lines){ 
				print("maxlines=%d\n", line+1); 
1990/1101    
			if(line >=0 && line<dp->lines) 
1990/0312    
				dp->lines=line+1; 
			} 
			break; 
		 
		default: 
1990/1024/sys/src/9/port/devdk.c:1364,13701990/1101/sys/src/9/port/devdk.c:1466,1472
1990/0312    
 *  datakit requests or confirms closing a line 
 */ 
static void 
dkchgmesg(Dk *dp, Dkmsg *dialp, int line) 
1990/1101    
dkchgmesg(Chan *c, Dk *dp, Dkmsg *dialp, int line) 
1990/0312    
{ 
	Line *lp; 
 
1990/1024/sys/src/9/port/devdk.c:1373,13791990/1101/sys/src/9/port/devdk.c:1475,1481
1990/0312    
	case D_CLOSE:		/* remote shutdown */ 
1990/1022    
		if (line <= 0 || line >= dp->lines) { 
			/* tell controller this line is not in use */ 
			dkmesg(dp, T_CHG, D_CLOSE, line, 0); 
1990/1101    
			dkmesg(c, T_CHG, D_CLOSE, line, 0); 
1990/1022    
			return; 
		} 
		lp = &dp->line[line]; 
1990/1024/sys/src/9/port/devdk.c:1394,14061990/1101/sys/src/9/port/devdk.c:1496,1508
1990/0312    
			break; 
 
		case Lopened: 
			dkmesg(dp, T_CHG, D_CLOSE, line, 0); 
1990/1101    
			dkmesg(c, T_CHG, D_CLOSE, line, 0); 
1990/0312    
			break; 
 
		case Llclose: 
		case Lclosed: 
			dkhangup(lp); 
			dkmesg(dp, T_CHG, D_CLOSE, line, 0); 
1990/1101    
			dkmesg(c, T_CHG, D_CLOSE, line, 0); 
1990/0312    
			lp->state = Lclosed; 
			break; 
		} 
1990/1024/sys/src/9/port/devdk.c:1409,14151990/1101/sys/src/9/port/devdk.c:1511,1517
1990/0312    
	case D_ISCLOSED:	/* acknowledging a local shutdown */ 
1990/1022    
		if (line <= 0 || line >= dp->lines) { 
			/* tell controller this line is not in use */ 
			dkmesg(dp, T_CHG, D_CLOSE, line, 0); 
1990/1101    
			dkmesg(c, T_CHG, D_CLOSE, line, 0); 
1990/1022    
			return; 
		} 
		lp = &dp->line[line]; 
1990/1024/sys/src/9/port/devdk.c:1428,14331990/1101/sys/src/9/port/devdk.c:1530,1538
1990/0312    
		break; 
 
1990/1022    
	case D_CLOSEALL: 
1990/1101    
		/* 
		 *  datakit wants us to close all lines 
		 */ 
1990/1022    
		for(line = dp->ncsc+1; line < dp->lines; line++){ 
			lp = &dp->line[line]; 
			switch (lp->state) { 
1990/1024/sys/src/9/port/devdk.c:1442,14491990/1101/sys/src/9/port/devdk.c:1547,1554
1990/1022    
			case Lconnected: 
			case Llistening: 
			case Lackwait: 
				dkhangup(lp); 
				lp->state = Lrclose; 
1990/1101    
				dkhangup(lp); 
1990/1022    
				break; 
	 
			case Lopened: 
1990/1024/sys/src/9/port/devdk.c:1503,15161990/1101/sys/src/9/port/devdk.c:1608,1616
1990/0312    
} 
 
/* 
 *  15-second timer for all interfaces 
1990/1101    
 *  send a I'm alive message every 7.5 seconds and remind the dk of 
 *  any closed channels it hasn't acknowledged. 
1990/0312    
 */ 
static Rendez dkt; 
static int 
fuckit(void *a) 
{ 
	return 0; 
} 
static void 
dktimer(void *a) 
{ 
1990/1024/sys/src/9/port/devdk.c:1517,15591990/1101/sys/src/9/port/devdk.c:1617,1679
1990/0312    
	int dki, i; 
	Dk *dp; 
	Line *lp; 
1990/1101    
	Chan *c; 
1990/0312    
 
1990/0911    
	while(waserror()) 
		print("dktimer: error\n"); 
1990/1101    
	c = 0; 
	if(waserror()){ 
		/* 
		 *  hang up any calls waiting for the dk 
		 */ 
		for (i=dp->ncsc+1; i<dp->lines; i++){ 
			lp = &dp->line[i]; 
			switch(lp->state){ 
			case Llclose: 
				lp->state = Lclosed; 
				break; 
1990/0312    
 
1990/1101    
			case Ldialing: 
				dkreplymesg(dp, (Dkmsg *)0, i); 
				break; 
			} 
		} 
		if(c) 
			close(c); 
		return; 
	} 
 
	/* 
	 *  open csc 
	 */ 
	dp = (Dk *)a; 
	c = dkopenline(dp, dp->ncsc); 
 
1990/0312    
	for(;;){ 
1990/1101    
		if(dp->opened==0) 
			error(0, Ehungup); 
 
1990/0312    
		/* 
		 *  loop through the active dks 
1990/1101    
		 * send keep alive 
1990/0312    
		 */ 
		for(dki=0; dki<Ndk; dki++){ 
			dp = &dk[dki]; 
			if(dp->csc==0) 
				continue; 
1990/1101    
		dkmesg(c, T_ALIVE, D_CONTINUE, 0, 0); 
1990/0312    
 
			/* 
			 * send keep alive 
			 */ 
			dkmesg(dp, T_ALIVE, D_CONTINUE, 0, 0); 
1990/1101    
		/* 
		 *  remind controller of dead lines and 
		 *  timeout calls that take to long 
		 */ 
		for (i=dp->ncsc+1; i<dp->lines; i++){ 
			lp = &dp->line[i]; 
			switch(lp->state){ 
			case Llclose: 
				dkmesg(c, T_CHG, D_CLOSE, i, 0); 
				break; 
1990/0312    
 
			/* 
			 *  remind controller of dead lines and 
			 *  timeout calls that take to long 
			 */ 
1990/1022    
			for (i=dp->ncsc+1; i<dp->lines; i++){ 
1990/0312    
				lp = &dp->line[i]; 
				switch(lp->state){ 
				case Llclose: 
					dkmesg(dp, T_CHG, D_CLOSE, i, 0); 
1990/1101    
			case Ldialing: 
				if(lp->calltolive==0 || --lp->calltolive!=0) 
1990/0312    
					break; 
                 
				case Ldialing: 
					if(lp->calltolive==0 || --lp->calltolive!=0) 
						break; 
					dkreplymesg(dp, (Dkmsg *)0, i); 
					break; 
				} 
1990/1101    
				dkreplymesg(dp, (Dkmsg *)0, i); 
				break; 
1990/0312    
			} 
		} 
		tsleep(&dkt, fuckit, 0, 7500); 
1990/1101    
		tsleep(&dp->timer, return0, 0, 7500); 
1990/0312    
	} 
} 
1990/1101/sys/src/9/port/devdk.c:377,3851990/1104/sys/src/9/port/devdk.c:377,385 (short | long)
1990/1101    
		error(0, Ehungup); 
	} 
	unlock(dp); 
1990/1104    
	lp->rq = q; 
1990/1101    
	if(lp->state==Lclosed) 
1990/0511    
		lp->state = Lopened; 
1990/1101    
	lp->rq = q; 
1990/0312    
} 
 
/* 
1990/1104/sys/src/9/port/devdk.c:202,2081990/1113/sys/src/9/port/devdk.c:202,215 (short | long)
1990/0312    
static void dkmuxclose(Queue *); 
static void dkmuxoput(Queue *, Block *); 
static void dkmuxiput(Queue *, Block *); 
Qinfo dkmuxinfo = { dkmuxiput, dkmuxoput, dkmuxopen, dkmuxclose, "dkmux" }; 
1990/1113    
Qinfo dkmuxinfo = 
{ 
	dkmuxiput, 
	dkmuxoput, 
	dkmuxopen, 
	dkmuxclose, 
	"dkmux" 
}; 
1990/0312    
 
/* 
1990/1101    
 *  Look for a dk struct with a name.  If none exists,  create one. 
1990/1104/sys/src/9/port/devdk.c:357,3631990/1113/sys/src/9/port/devdk.c:364,377
1990/0312    
static void dkstclose(Queue *); 
static void dkoput(Queue *, Block *); 
static void dkiput(Queue *, Block *); 
Qinfo dkinfo = { dkiput, dkoput, dkstopen, dkstclose, "dk" }; 
1990/1113    
Qinfo dkinfo = 
{ 
	dkiput, 
	dkoput, 
	dkstopen, 
	dkstclose, 
	"dk" 
}; 
1990/0312    
 
/* 
 *  open and save a pointer to the conversation 
1990/1113/sys/src/9/port/devdk.c:6,121990/11161/sys/src/9/port/devdk.c:6,12 (short | long)
1990/0312    
#include	"io.h" 
#include	"errno.h" 
 
1990/0911    
#define	DPRINT	if(0)	/*kprint*/ 
1990/11161    
#define	DPRINT	if(0) print 
1990/0312    
 
1990/0911    
#define	NOW	(MACHP(0)->ticks) 
 
1990/1113/sys/src/9/port/devdk.c:1668,16731990/11161/sys/src/9/port/devdk.c:1668,1674
1990/0312    
		/* 
1990/1101    
		 * send keep alive 
1990/0312    
		 */ 
1990/11161    
		DPRINT("keep alive\n"); 
1990/1101    
		dkmesg(c, T_ALIVE, D_CONTINUE, 0, 0); 
1990/0312    
 
1990/1101    
		/* 
1990/11161/sys/src/9/port/devdk.c:232,2381990/11211/sys/src/9/port/devdk.c:232,238 (short | long)
1990/0312    
	} 
1990/1101    
	if(freep == 0){ 
		unlock(&dklock); 
		error(0, Enoifc); 
1990/11211    
		error(Enoifc); 
1990/1101    
	} 
	dp = freep; 
	dp->opened = 0; 
1990/11161/sys/src/9/port/devdk.c:388,3941990/11211/sys/src/9/port/devdk.c:388,394
1990/1101    
	lock(dp); 
	if(dp->opened==0 || streamenter(dp->s)<0){ 
		unlock(dp); 
		error(0, Ehungup); 
1990/11211    
		error(Ehungup); 
1990/1101    
	} 
	unlock(dp); 
1990/1104    
	lp->rq = q; 
1990/11161/sys/src/9/port/devdk.c:499,5051990/11211/sys/src/9/port/devdk.c:499,505
1990/0312    
 
	if(bp->type != M_DATA){ 
		freeb(bp); 
		error(0, Ebadarg); 
1990/11211    
		error(Ebadarg); 
1990/0312    
	} 
 
	lp = (Line *)q->ptr; 
1990/11161/sys/src/9/port/devdk.c:540,5461990/11211/sys/src/9/port/devdk.c:540,546
1990/0312    
 
1990/1101    
	if(WR(q)->ptr){ 
1990/0312    
		freeb(bp); 
1990/1101    
		error(0, Egreg); 
1990/11211    
		error(Egreg); 
1990/0312    
	} 
 
	/* 
1990/11161/sys/src/9/port/devdk.c:571,5811990/11211/sys/src/9/port/devdk.c:571,581
1990/0312    
		break; 
	default: 
		freeb(bp); 
		error(0, Ebadarg); 
1990/11211    
		error(Ebadarg); 
1990/0312    
	} 
	freeb(bp); 
1990/1101    
	if(ncsc <= 0 || lines <= ncsc) 
1990/0312    
		error(0, Ebadarg); 
1990/11211    
		error(Ebadarg); 
1990/0312    
 
	/* 
1990/1101    
	 *  set up 
1990/11161/sys/src/9/port/devdk.c:584,5901990/11211/sys/src/9/port/devdk.c:584,590
1990/1101    
	lock(dp); 
	if(dp->opened){ 
		unlock(dp); 
		error(0, Ebadarg); 
1990/11211    
		error(Ebadarg); 
1990/0312    
	} 
1990/1101    
	dp->ncsc = ncsc; 
	dp->lines = lines; 
1990/11161/sys/src/9/port/devdk.c:653,6631990/11211/sys/src/9/port/devdk.c:653,663
1990/0312    
 *  the per stream directory structure 
 */ 
Dirtab dksubdir[]={ 
	"addr",		Daddrqid,	0,	0600, 
	"listen",	Dlistenqid,	0,	0600, 
	"other",	Dotherqid,	0,	0600, 
	"raddr",	Draddrqid,	0, 	0600, 
	"ruser",	Duserqid,	0, 	0600, 
1990/11211    
	"addr",		{Daddrqid},	0,	0600, 
	"listen",	{Dlistenqid},	0,	0600, 
	"other",	{Dotherqid},	0,	0600, 
	"raddr",	{Draddrqid},	0, 	0600, 
	"ruser",	{Duserqid},	0, 	0600, 
1990/0312    
}; 
 
/* 
1990/11161/sys/src/9/port/devdk.c:687,6931990/11211/sys/src/9/port/devdk.c:687,694
1990/0312    
	 */ 
	for(i = 1; i < Nline; i++) { 
		sprint(dkdir[i].name, "%d", i); 
		dkdir[i].qid = CHDIR|STREAMQID(i, Dlineqid); 
1990/11211    
		dkdir[i].qid.path = CHDIR|STREAMQID(i, Dlineqid); 
		dkdir[i].qid.vers = 0; 
1990/0312    
		dkdir[i].length = 0; 
		dkdir[i].perm = 0600; 
	} 
1990/11161/sys/src/9/port/devdk.c:696,7021990/11211/sys/src/9/port/devdk.c:697,704
1990/0312    
	 *  the clone device 
	 */ 
	strcpy(dkdir[0].name, "clone"); 
	dkdir[0].qid = Dcloneqid; 
1990/11211    
	dkdir[0].qid.path = Dcloneqid; 
	dkdir[0].qid.vers = 0; 
1990/0312    
	dkdir[0].length = 0; 
	dkdir[0].perm = 0600; 
} 
1990/11161/sys/src/9/port/devdk.c:731,7371990/11211/sys/src/9/port/devdk.c:733,739
1990/0312    
int	  
dkwalk(Chan *c, char *name) 
{ 
	if(c->qid == CHDIR) 
1990/11211    
	if(c->qid.path == CHDIR) 
1990/0312    
		return devwalk(c, name, dkdir, dk[c->dev].lines, devgen); 
	else 
		return devwalk(c, name, dksubdir, Nsubdir, streamgen); 
1990/11161/sys/src/9/port/devdk.c:740,7461990/11211/sys/src/9/port/devdk.c:742,748
1990/0312    
void	  
dkstat(Chan *c, char *dp) 
{ 
	if(c->qid == CHDIR) 
1990/11211    
	if(c->qid.path == CHDIR) 
1990/0312    
		devstat(c, dp, dkdir, dk[c->dev].lines, devgen); 
	else 
		devstat(c, dp, dksubdir, Nsubdir, streamgen); 
1990/11161/sys/src/9/port/devdk.c:764,7761990/11211/sys/src/9/port/devdk.c:766,778
1990/0312    
	Dk *dp; 
	int line; 
 
1990/0319    
	if(c->qid & CHDIR){ 
1990/11211    
	if(c->qid.path & CHDIR){ 
1990/0312    
		/* 
1990/0319    
		 *  directories are read only 
		 */ 
		if(omode != OREAD) 
			error(0, Ebadarg); 
	} else switch(STREAMTYPE(c->qid)){ 
1990/11211    
			error(Ebadarg); 
	} else switch(STREAMTYPE(c->qid.path)){ 
1990/0319    
	case Dcloneqid: 
1990/1101    
		dp = &dk[c->dev]; 
1990/0319    
		/* 
1990/11161/sys/src/9/port/devdk.c:783,7941990/11211/sys/src/9/port/devdk.c:785,796
1990/0312    
					qunlock(lp); 
					continue; 
				} 
				c->qid = STREAMQID(lp-dp->line, Sctlqid); 
1990/11211    
				c->qid.path = STREAMQID(lp-dp->line, Sctlqid); 
1990/0312    
				break; 
			} 
		} 
		if(lp == end) 
			error(0, Enodev); 
1990/11211    
			error(Enodev); 
1990/1101    
		lp->state = Lopened; 
		qunlock(lp); 
1990/0312    
		streamopen(c, &dkinfo); 
1990/11161/sys/src/9/port/devdk.c:800,8061990/11211/sys/src/9/port/devdk.c:802,808
1990/0312    
		 *  channel on which the call arrived. 
		 */ 
		line = dklisten(c); 
		c->qid = STREAMQID(line, Sctlqid); 
1990/11211    
		c->qid.path = STREAMQID(line, Sctlqid); 
1990/0312    
		streamopen(c, &dkinfo); 
		pushq(c->stream, &urpinfo); 
		dkwindow(c); 
1990/11161/sys/src/9/port/devdk.c:813,8191990/11211/sys/src/9/port/devdk.c:815,821
1990/0319    
		 *  read only files 
		 */ 
		if(omode != OREAD) 
			error(0, Ebadarg); 
1990/11211    
			error(Ebadarg); 
1990/0319    
		break; 
	default: 
		/* 
1990/11161/sys/src/9/port/devdk.c:834,8401990/11211/sys/src/9/port/devdk.c:836,842
1990/0312    
void	  
dkcreate(Chan *c, char *name, int omode, ulong perm) 
{ 
	error(0, Eperm); 
1990/11211    
	error(Eperm); 
1990/0312    
} 
 
void	  
1990/11161/sys/src/9/port/devdk.c:852,8661990/11211/sys/src/9/port/devdk.c:854,868
1990/0319    
	if(c->stream) 
1990/0312    
		return streamread(c, a, n); 
 
1990/0319    
	if(c->qid & CHDIR){ 
		if(c->qid == CHDIR) 
1990/11211    
	if(c->qid.path & CHDIR){ 
		if(c->qid.path == CHDIR) 
1990/0319    
			return devdirread(c, a, n, dkdir, dk[c->dev].lines, devgen); 
		else 
			return devdirread(c, a, n, dksubdir, Nsubdir, streamgen); 
	} 
 
1990/0312    
	lp = &dk[c->dev].line[STREAMID(c->qid)]; 
1990/0319    
	switch(STREAMTYPE(c->qid)){ 
1990/11211    
	lp = &dk[c->dev].line[STREAMID(c->qid.path)]; 
	switch(STREAMTYPE(c->qid.path)){ 
1990/0312    
	case Daddrqid: 
		return stringread(c, a, n, lp->addr); 
	case Draddrqid: 
1990/11161/sys/src/9/port/devdk.c:868,8741990/11211/sys/src/9/port/devdk.c:870,876
1990/0312    
	case Duserqid: 
		return stringread(c, a, n, lp->ruser); 
	} 
	error(0, Eperm); 
1990/11211    
	error(Eperm); 
1990/0312    
} 
 
long	  
1990/11161/sys/src/9/port/devdk.c:879,8851990/11211/sys/src/9/port/devdk.c:881,887
1990/0312    
	char *field[5]; 
	int m; 
 
	t = STREAMTYPE(c->qid); 
1990/11211    
	t = STREAMTYPE(c->qid.path); 
1990/0312    
 
	/* 
	 *  get data dispatched as quickly as possible 
1990/11161/sys/src/9/port/devdk.c:895,9171990/11211/sys/src/9/port/devdk.c:897,919
1990/0312    
		m = getfields(buf, field, 5, ' '); 
		if(strcmp(field[0], "connect")==0){ 
			if(m < 2) 
				error(0, Ebadarg); 
1990/11211    
				error(Ebadarg); 
1990/0312    
			dkcall(Dial, c, field[1], 0, 0); 
		} else if(strcmp(field[0], "announce")==0){ 
			if(m < 2) 
				error(0, Ebadarg); 
1990/11211    
				error(Ebadarg); 
1990/0312    
			dkcall(Announce, c, field[1], 0, 0); 
		} else if(strcmp(field[0], "redial")==0){ 
			if(m < 4) 
				error(0, Ebadarg); 
1990/11211    
				error(Ebadarg); 
1990/0312    
			dkcall(Redial, c, field[1], field[2], field[3]); 
		} else if(strcmp(field[0], "accept")==0){ 
			if(m < 2) 
				error(0, Ebadarg); 
1990/11211    
				error(Ebadarg); 
1990/0312    
			dkanswer(c, strtoul(field[1], 0, 0), 0); 
		} else if(strcmp(field[0], "reject")==0){ 
			if(m < 3) 
				error(0, Ebadarg); 
1990/11211    
				error(Ebadarg); 
1990/0312    
			dkanswer(c, strtoul(field[1], 0, 0), strtoul(field[2], 0, 0)); 
		} else 
			return streamwrite(c, a, n, 0); 
1990/11161/sys/src/9/port/devdk.c:918,9521990/11211/sys/src/9/port/devdk.c:920,940
1990/0312    
		return n; 
	} 
 
	error(0, Eperm); 
1990/11211    
	error(Eperm); 
1990/0312    
} 
 
void	  
dkremove(Chan *c) 
{ 
	error(0, Eperm); 
1990/11211    
	error(Eperm); 
1990/0312    
} 
 
void	  
dkwstat(Chan *c, char *dp) 
{ 
	error(0, Eperm); 
1990/11211    
	error(Eperm); 
1990/0312    
} 
 
void	  
dkerrstr(Error *e, char *buf) 
{ 
	rooterrstr(e, buf); 
} 
                 
void	  
dkuserstr(Error *e, char *buf) 
{ 
	extern consuserstr(Error *, char *); 
                 
	consuserstr(e, buf); 
} 
                 
/* 
1990/1101    
 *  open the common signalling channel 
 */ 
1990/11161/sys/src/9/port/devdk.c:962,9681990/11211/sys/src/9/port/devdk.c:950,956
1990/1101    
		nexterror(); 
	} 
	c = dkattach(dp->name); 
	c->qid = STREAMQID(line, Sdataqid); 
1990/11211    
	c->qid.path = STREAMQID(line, Sdataqid); 
1990/1101    
	dkopen(c, ORDWR); 
	poperror(); 
 
1990/11161/sys/src/9/port/devdk.c:1022,10281990/11211/sys/src/9/port/devdk.c:1010,1016
1990/1101    
	Chan *csc; 
1990/0707    
	char *bang, *dot; 
1990/1101    
	 
1990/0312    
	line = STREAMID(c->qid); 
1990/11211    
	line = STREAMID(c->qid.path); 
1990/0312    
	dp = &dk[c->dev]; 
	lp = &dp->line[line]; 
 
1990/11161/sys/src/9/port/devdk.c:1030,10361990/11211/sys/src/9/port/devdk.c:1018,1024
1990/0312    
	 *  only dial on virgin lines 
	 */ 
1990/0511    
	if(lp->state != Lopened) 
1990/0312    
		error(0, Ebadarg); 
1990/11211    
		error(Ebadarg); 
1990/0312    
 
	DPRINT("dkcall(line=%d, type=%d, dest=%s)\n", line, type, addr); 
 
1990/11161/sys/src/9/port/devdk.c:1040,10481990/11211/sys/src/9/port/devdk.c:1028,1036
1990/0707    
	 *	- change ! into . to delimit service 
1990/0312    
	 */ 
	if(strchr(addr, '\n')) 
		error(0, Ebadarg); 
1990/11211    
		error(Ebadarg); 
1990/0312    
	if(strlen(addr)+strlen(u->p->pgrp->user)+2 >= sizeof(dialstr)) 
		error(0, Ebadarg); 
1990/11211    
		error(Ebadarg); 
1990/0312    
	strcpy(dialstr, addr); 
1990/0707    
	bang = strchr(dialstr, '!'); 
	if(bang){ 
1990/11161/sys/src/9/port/devdk.c:1109,11151990/11211/sys/src/9/port/devdk.c:1097,1103
1990/0312    
	if(type==Redial){ 
		if(streamread(dc, &dialtone, 1L) != 1L){ 
			lp->state = Lconnected; 
			error(0, Ebadarg); 
1990/11211    
			error(Ebadarg); 
1990/0312    
		} 
	} 
 
1990/11161/sys/src/9/port/devdk.c:1142,11501990/11211/sys/src/9/port/devdk.c:1130,1138
1990/0312    
	DPRINT("got reply %d\n", lp->state); 
	if(lp->state != Lconnected) { 
		if(lp->err >= DKERRS) 
			error(0, dkerr[0]); 
1990/11211    
			error(dkerr[0]); 
1990/0312    
		else 
			error(0, dkerr[lp->err]); 
1990/11211    
			error(dkerr[lp->err]); 
1990/0312    
	} 
 
	/* 
1990/11161/sys/src/9/port/devdk.c:1202,12081990/11211/sys/src/9/port/devdk.c:1190,1196
1990/0312    
	/* 
	 *  open the data file 
	 */ 
1990/1101    
	dc = dkopenline(dp, STREAMID(c->qid)); 
1990/11211    
	dc = dkopenline(dp, STREAMID(c->qid.path)); 
1990/0312    
	if(waserror()){ 
		close(dc); 
		nexterror(); 
1990/11161/sys/src/9/port/devdk.c:1218,12241990/11211/sys/src/9/port/devdk.c:1206,1212
1990/0312    
		n = streamread(dc, dialstr, sizeof(dialstr)-1); 
		DPRINT("returns %d\n", n); 
		if(n <= 0) 
			error(0, Eio); 
1990/11211    
			error(Eio); 
1990/0312    
		dialstr[n] = 0; 
		DPRINT("dialstr = %s\n", dialstr); 
 
1990/11161/sys/src/9/port/devdk.c:1228,12341990/11211/sys/src/9/port/devdk.c:1216,1222
1990/0312    
		n = getfields(dialstr, line, 12, '\n'); 
		if (n < 2) { 
			DPRINT("bad dialstr from dk (1 line)\n"); 
			error(0, Eio); 
1990/11211    
			error(Eio); 
1990/0312    
		} 
 
		/* 
1990/11161/sys/src/9/port/devdk.c:1332,13381990/11211/sys/src/9/port/devdk.c:1320,1326
1990/0312    
		default: 
			print("bad message from dk(>4 line)\n"); 
			qunlock(lp); 
			error(0, Ebadarg); 
1990/11211    
			error(Ebadarg); 
1990/0312    
		} 
 
		sprint(lp->other, "w(%d)", W_TRAF(lp->window)); 
1990/11161/sys/src/9/port/devdk.c:1372,13781990/11211/sys/src/9/port/devdk.c:1360,1366
1990/0312    
		close(dc); 
		nexterror(); 
	} 
	dc->qid = STREAMQID(STREAMID(c->qid), Sdataqid); 
1990/11211    
	dc->qid.path = STREAMQID(STREAMID(c->qid.path), Sdataqid); 
1990/0312    
	dkopen(dc, ORDWR); 
 
	/* 
1990/11161/sys/src/9/port/devdk.c:1395,14011990/11211/sys/src/9/port/devdk.c:1383,1389
1990/0312    
	long wins; 
	Line *lp; 
 
	lp = &dk[c->dev].line[STREAMID(c->qid)]; 
1990/11211    
	lp = &dk[c->dev].line[STREAMID(c->qid.path)]; 
1990/0312    
	if(lp->window == 0) 
		lp->window = 64; 
	sprint(buf, "init %d %d", lp->window, Streamhi); 
1990/11161/sys/src/9/port/devdk.c:1444,14501990/11211/sys/src/9/port/devdk.c:1432,1438
1990/0312    
		n = streamread(dp->csc, (char *)&d, (long)sizeof(d)); 
		if(n != sizeof(d)){ 
1990/1101    
			if(n == 0) 
				error(0, Ehungup); 
1990/11211    
				error(Ehungup); 
1990/0312    
			print("strange csc message %d\n", n); 
			continue; 
		} 
1990/11161/sys/src/9/port/devdk.c:1663,16691990/11211/sys/src/9/port/devdk.c:1651,1657
1990/1101    
 
1990/0312    
	for(;;){ 
1990/1101    
		if(dp->opened==0) 
			error(0, Ehungup); 
1990/11211    
			error(Ehungup); 
1990/1101    
 
1990/0312    
		/* 
1990/1101    
		 * send keep alive 
1990/11211/sys/src/9/port/devdk.c:744,7491990/1126/sys/src/9/port/devdk.c:744,751 (short | long)
1990/0312    
{ 
1990/11211    
	if(c->qid.path == CHDIR) 
1990/0312    
		devstat(c, dp, dkdir, dk[c->dev].lines, devgen); 
1990/1126    
	else if(c->qid.path == Dcloneqid) 
		devstat(c, dp, dkdir, 1, devgen); 
1990/0312    
	else 
		devstat(c, dp, dksubdir, Nsubdir, streamgen); 
} 
1990/11211/sys/src/9/port/devdk.c:776,7821990/1126/sys/src/9/port/devdk.c:778,784
1990/0319    
	case Dcloneqid: 
1990/1101    
		dp = &dk[c->dev]; 
1990/0319    
		/* 
1990/0312    
		 *  get an unused device and open it's control file 
1990/1126    
		 *  get an unused device and open its control file 
1990/0312    
		 */ 
		end = &dp->line[dp->lines]; 
		for(lp = &dp->line[dp->ncsc+1]; lp < end; lp++){ 
1990/1126/sys/src/9/port/devdk.c:128,1331990/1202/sys/src/9/port/devdk.c:128,135 (short | long)
1990/0707    
	int	restart; 
1990/0911    
	int	urpwindow; 
1990/1101    
	Rendez	timer; 
1990/1202    
	Rendez	rallclosed; 
	int	allclosedp;	/* true once a closeall has been seen */ 
1990/0312    
}; 
static Dk dk[Ndk]; 
1990/1101    
static Lock dklock; 
1990/1126/sys/src/9/port/devdk.c:525,5301990/1202/sys/src/9/port/devdk.c:527,540
1990/0312    
 * 
 *  we can configure only once 
 */ 
1990/1202    
static int 
allclosed(void *arg) 
{ 
	Dk *dp; 
 
	dp = arg; 
	return dp->allclosedp; 
} 
1990/0312    
static void 
1990/1101    
dkmuxconfig(Queue *q, Block *bp) 
1990/0312    
{ 
1990/1126/sys/src/9/port/devdk.c:603,6081990/1202/sys/src/9/port/devdk.c:613,629
1990/1101    
	dp->csc = dkopenline(dp, dp->ncsc); 
 
	/* 
1990/1202    
	 *  start a process to listen to csc messages 
	 */ 
	sprint(buf, "csc.%s.%d", dp->name, dp->ncsc); 
	kproc(buf, dkcsckproc, dp); 
 
	/* 
	 *  wait for first possible closeall (may not come) 
	 */ 
	tsleep(&dp->rallclosed, allclosed, dp, 2000); 
 
	/* 
1990/1004    
	 *  tell datakit we've rebooted. It should close all channels. 
1990/1101    
	 *  do this here to get it done before trying to open a channel. 
1990/1004    
	 */ 
1990/1126/sys/src/9/port/devdk.c:612,6271990/1202/sys/src/9/port/devdk.c:633,648
1990/1004    
	} 
 
	/* 
1990/1101    
	 *  start a process to listen to csc messages 
1990/0312    
	 */ 
1990/0911    
	sprint(buf, "csc.%s.%d", dp->name, dp->ncsc); 
1990/0312    
	kproc(buf, dkcsckproc, dp); 
                 
	/* 
1990/1101    
	 *  start a keepalive process 
1990/0312    
	 */ 
1990/1101    
	sprint(buf, "timer.%s.%d", dp->name, dp->ncsc); 
	kproc(buf, dktimer, dp); 
1990/1202    
 
	/* 
	 *  wait for closeall in response to D_RESTART 
	 */ 
	if(dp->restart) 
		tsleep(&dp->rallclosed, allclosed, dp, 10000); 
1990/0312    
} 
 
/* 
1990/1126/sys/src/9/port/devdk.c:1564,15691990/1202/sys/src/9/port/devdk.c:1585,1592
1990/1022    
				break; 
			} 
		} 
1990/1202    
		dp->allclosedp = 1; 
		wakeup(&dp->rallclosed); 
1990/1022    
		break; 
 
1990/0312    
	default: 
Too many diffs (26 > 25). Stopping.


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)