⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 isdnloop.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 3 页
字号:
 * Parameter: *   card = pointer to card struct. */static voidisdnloop_fake_err(isdnloop_card * card){	char buf[60];	sprintf(buf, "E%s", card->omsg);	isdnloop_fake(card, buf, -1);	isdnloop_fake(card, "NAK", -1);}static u_char ctable_eu[] ={0x00, 0x11, 0x01, 0x12};static u_char ctable_1t[] ={0x00, 0x3b, 0x01, 0x3a};/* * Assemble a simplified cause message depending on the * D-channel protocol used. * * Parameter: *   card = pointer to card struct. *   loc  = location: 0 = local, 1 = remote. *   cau  = cause: 1 = busy, 2 = nonexistent callerid, 3 = no user responding. * Return: *   Pointer to buffer containing the assembled message. */static char *isdnloop_unicause(isdnloop_card * card, int loc, int cau){	static char buf[6];	switch (card->ptype) {		case ISDN_PTYPE_EURO:			sprintf(buf, "E%02X%02X", (loc) ? 4 : 2, ctable_eu[cau]);			break;		case ISDN_PTYPE_1TR6:			sprintf(buf, "%02X44", ctable_1t[cau]);			break;		default:			return ("0000");	}	return (buf);}/* * Release a virtual connection. Called from timer interrupt, when * called party did not respond. * * Parameter: *   card = pointer to card struct. *   ch   = channel (0-based) */static voidisdnloop_atimeout(isdnloop_card * card, int ch){	unsigned long flags;	char buf[60];	save_flags(flags);	cli();	if (card->rcard) {		isdnloop_fake(card->rcard[ch], "DDIS_I", card->rch[ch] + 1);		card->rcard[ch]->rcard[card->rch[ch]] = NULL;		card->rcard[ch] = NULL;	}	isdnloop_fake(card, "DDIS_I", ch + 1);	/* No user responding */	sprintf(buf, "CAU%s", isdnloop_unicause(card, 1, 3));	isdnloop_fake(card, buf, ch + 1);	restore_flags(flags);}/* * Wrapper for isdnloop_atimeout(). */static voidisdnloop_atimeout0(unsigned long data){	isdnloop_card *card = (isdnloop_card *) data;	isdnloop_atimeout(card, 0);}/* * Wrapper for isdnloop_atimeout(). */static voidisdnloop_atimeout1(unsigned long data){	isdnloop_card *card = (isdnloop_card *) data;	isdnloop_atimeout(card, 1);}/* * Install a watchdog for a user, not responding. * * Parameter: *   card = pointer to card struct. *   ch   = channel to watch for. */static voidisdnloop_start_ctimer(isdnloop_card * card, int ch){	unsigned long flags;	save_flags(flags);	cli();	init_timer(&card->c_timer[ch]);	card->c_timer[ch].expires = jiffies + ISDNLOOP_TIMER_ALERTWAIT;	if (ch)		card->c_timer[ch].function = isdnloop_atimeout1;	else		card->c_timer[ch].function = isdnloop_atimeout0;	card->c_timer[ch].data = (unsigned long) card;	add_timer(&card->c_timer[ch]);	restore_flags(flags);}/* * Kill a pending channel watchdog. * * Parameter: *   card = pointer to card struct. *   ch   = channel (0-based). */static voidisdnloop_kill_ctimer(isdnloop_card * card, int ch){	unsigned long flags;	save_flags(flags);	cli();	del_timer(&card->c_timer[ch]);	restore_flags(flags);}static u_char si2bit[] ={0, 1, 0, 0, 0, 2, 0, 4, 0, 0};static u_char bit2si[] ={1, 5, 7};/* * Try finding a listener for an outgoing call. * * Parameter: *   card = pointer to calling card. *   p    = pointer to ICN-type setup-string. *   lch  = channel of calling card. *   cmd  = pointer to struct to be filled when parsing setup. * Return: *   0 = found match, alerting should happen. *   1 = found matching number but it is busy. *   2 = no matching listener. *   3 = found matching number but SI does not match. */static intisdnloop_try_call(isdnloop_card * card, char *p, int lch, isdn_ctrl * cmd){	isdnloop_card *cc = cards;	unsigned long flags;	int ch;	int num_match;	int i;	char *e;	char nbuf[32];	isdnloop_parse_setup(p, cmd);	while (cc) {		for (ch = 0; ch < 2; ch++) {			/* Exclude ourself */			if ((cc == card) && (ch == lch))				continue;			num_match = 0;			switch (cc->ptype) {				case ISDN_PTYPE_EURO:					for (i = 0; i < 3; i++)						if (!(strcmp(cc->s0num[i], cmd->parm.setup.phone)))							num_match = 1;					break;				case ISDN_PTYPE_1TR6:					e = cc->eazlist[ch];					while (*e) {						sprintf(nbuf, "%s%c", cc->s0num[0], *e);						if (!(strcmp(nbuf, cmd->parm.setup.phone)))							num_match = 1;						e++;					}			}			if (num_match) {				save_flags(flags);				cli();				/* channel idle? */				if (!(cc->rcard[ch])) {					/* Check SI */					if (!(si2bit[cmd->parm.setup.si1] & cc->sil[ch])) {						restore_flags(flags);						return 3;					}					/* ch is idle, si and number matches */					cc->rcard[ch] = card;					cc->rch[ch] = lch;					card->rcard[lch] = cc;					card->rch[lch] = ch;					restore_flags(flags);					return 0;				} else {					restore_flags(flags);					/* num matches, but busy */					if (ch == 1)						return 1;				}			}		}		cc = cc->next;	}	return 2;}/* * Depending on D-channel protocol and caller/called, modify * phone number. * * Parameter: *   card   = pointer to card struct. *   phone  = pointer phone number. *   caller = flag: 1 = caller, 0 = called. * Return: *   pointer to new phone number. */static char *isdnloop_vstphone(isdnloop_card * card, char *phone, int caller){	int i;	static char nphone[30];	if (!card) {		printk("BUG!!!\n");		return "";	}	switch (card->ptype) {		case ISDN_PTYPE_EURO:			if (caller) {				for (i = 0; i < 2; i++)					if (!(strcmp(card->s0num[i], phone)))						return (phone);				return (card->s0num[0]);			}			return (phone);			break;		case ISDN_PTYPE_1TR6:			if (caller) {				sprintf(nphone, "%s%c", card->s0num[0], phone[0]);				return (nphone);			} else				return (&phone[strlen(phone) - 1]);			break;	}	return "";}/* * Parse an ICN-type command string sent to the 'card'. * Perform misc. actions depending on the command. * * Parameter: *   card = pointer to card struct. */static voidisdnloop_parse_cmd(isdnloop_card * card){	char *p = card->omsg;	isdn_ctrl cmd;	char buf[60];	isdnloop_stat *s = isdnloop_cmd_table;	int action = -1;	int i;	int ch;	if ((card->omsg[0] != '0') && (card->omsg[2] != ';')) {		isdnloop_fake_err(card);		return;	}	ch = card->omsg[1] - '0';	if ((ch < 0) || (ch > 2)) {		isdnloop_fake_err(card);		return;	}	p += 3;	while (s->statstr) {		if (!strncmp(p, s->statstr, strlen(s->statstr))) {			action = s->action;			if (s->command && (ch != 0)) {				isdnloop_fake_err(card);				return;			}			break;		}		s++;	}	if (action == -1)		return;	switch (action) {		case 1:			/* 0x;BCON_R */			if (card->rcard[ch - 1]) {				isdnloop_fake(card->rcard[ch - 1], "BCON_I",					      card->rch[ch - 1] + 1);				isdnloop_fake(card, "BCON_C", ch);			}			break;		case 17:			/* 0x;BCON_I */			if (card->rcard[ch - 1]) {				isdnloop_fake(card->rcard[ch - 1], "BCON_C",					      card->rch[ch - 1] + 1);			}			break;		case 2:			/* 0x;BDIS_R */			isdnloop_fake(card, "BDIS_C", ch);			if (card->rcard[ch - 1]) {				isdnloop_fake(card->rcard[ch - 1], "BDIS_I",					      card->rch[ch - 1] + 1);			}			break;		case 16:			/* 0x;DCON_R */			isdnloop_kill_ctimer(card, ch - 1);			if (card->rcard[ch - 1]) {				isdnloop_kill_ctimer(card->rcard[ch - 1], card->rch[ch - 1]);				isdnloop_fake(card->rcard[ch - 1], "DCON_C",					      card->rch[ch - 1] + 1);				isdnloop_fake(card, "DCON_C", ch);			}			break;		case 3:			/* 0x;DDIS_R */			isdnloop_kill_ctimer(card, ch - 1);			if (card->rcard[ch - 1]) {				isdnloop_kill_ctimer(card->rcard[ch - 1], card->rch[ch - 1]);				isdnloop_fake(card->rcard[ch - 1], "DDIS_I",					      card->rch[ch - 1] + 1);				card->rcard[ch - 1] = NULL;			}			isdnloop_fake(card, "DDIS_C", ch);			break;		case 4:			/* 0x;DSCA_Rdd,yy,zz,oo */			if (card->ptype != ISDN_PTYPE_1TR6) {				isdnloop_fake_err(card);				return;			}			/* Fall through */		case 5:			/* 0x;DCAL_Rdd,yy,zz,oo */			p += 6;			switch (isdnloop_try_call(card, p, ch - 1, &cmd)) {				case 0:					/* Alerting */					sprintf(buf, "D%s_I%s,%02d,%02d,%s",					   (action == 4) ? "SCA" : "CAL",						isdnloop_vstphone(card, cmd.parm.setup.eazmsn, 1),						cmd.parm.setup.si1,						cmd.parm.setup.si2,					isdnloop_vstphone(card->rcard[ch - 1],					       cmd.parm.setup.phone, 0));					isdnloop_fake(card->rcard[ch - 1], buf, card->rch[ch - 1] + 1);					/* Fall through */				case 3:					/* si1 does not match, don't alert but start timer */					isdnloop_start_ctimer(card, ch - 1);					break;				case 1:					/* Remote busy */					isdnloop_fake(card, "DDIS_I", ch);					sprintf(buf, "CAU%s", isdnloop_unicause(card, 1, 1));					isdnloop_fake(card, buf, ch);					break;				case 2:					/* No such user */					isdnloop_fake(card, "DDIS_I", ch);					sprintf(buf, "CAU%s", isdnloop_unicause(card, 1, 2));					isdnloop_fake(card, buf, ch);					break;			}			break;		case 6:			/* 0x;EAZC */			card->eazlist[ch - 1][0] = '\0';			break;		case 7:			/* 0x;EAZ */			p += 3;			strcpy(card->eazlist[ch - 1], p);			break;		case 8:			/* 0x;SEEAZ */			sprintf(buf, "EAZ-LIST: %s", card->eazlist[ch - 1]);			isdnloop_fake(card, buf, ch + 1);			break;		case 9:			/* 0x;MSN */			break;		case 10:			/* 0x;MSNALL */			break;		case 11:			/* 0x;SETSIL */			p += 6;			i = 0;			while (strchr("0157", *p)) {				if (i)					card->sil[ch - 1] |= si2bit[*p - '0'];				i = (*p++ == '0');			}			if (*p)				isdnloop_fake_err(card);			break;		case 12:			/* 0x;SEESIL */			sprintf(buf, "SIN-LIST: ");			p = buf + 10;			for (i = 0; i < 3; i++)				if (card->sil[ch - 1] & (1 << i))					p += sprintf(p, "%02d", bit2si[i]);			isdnloop_fake(card, buf, ch + 1);			break;		case 13:			/* 0x;SILC */			card->sil[ch - 1] = 0;			break;		case 14:			/* 00;FV2ON */			break;		case 15:			/* 00;FV2OFF */			break;	}}/* * Put command-strings into the of the 'card'. In reality, execute them * right in place by calling isdnloop_parse_cmd(). Also copy every * command to the read message ringbuffer, preceeding it with a '>'. * These mesagges can be read at /dev/isdnctrl. * * Parameter: *   buf  = pointer to command buffer. *   len  = length of buffer data. *   user = flag: 1 = called form userlevel, 0 called from kernel. *   card = pointer to card struct. * Return: *   number of bytes transferred (currently always equals len). */static intisdnloop_writecmd(const u_char * buf, int len, int user, isdnloop_card * card){	int xcount = 0;	int ocount = 1;	isdn_ctrl cmd;	while (len) {		int count = len;		u_char *p;		u_char msg[0x100];		if (count > 255)			count = 255;		if (user) {			if (copy_from_user(msg, buf, count))				return -EFAULT;		} else			memcpy(msg, buf, count);		isdnloop_putmsg(card, '>');		for (p = msg; count > 0; count--, p++) {			len--;			xcount++;			isdnloop_putmsg(card, *p);			card->omsg[card->optr] = *p;			if (*p == '\n') {				card->omsg[card->optr] = '\0';				card->optr = 0;				isdnloop_parse_cmd(card);				if (len) {					isdnloop_putmsg(card, '>');					ocount++;				}			} else {				if (card->optr < 59)					card->optr++;			}			ocount++;		}	}	cmd.command = ISDN_STAT_STAVAIL;	cmd.driver = card->myid;	cmd.arg = ocount;	card->interface.statcallb(&cmd);	return xcount;}/* * Delete card's pending timers, send STOP to linklevel */static voidisdnloop_stopcard(isdnloop_card * card){	unsigned long flags;	isdn_ctrl cmd;	save_flags(flags);	cli();	if (card->flags & ISDNLOOP_FLAGS_RUNNING) {		card->flags &= ~ISDNLOOP_FLAGS_RUNNING;		del_timer(&card->st_timer);		del_timer(&card->rb_timer);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -