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

📄 chan_misdn.c

📁 Asterisk中信道部分的源码 。。。。
💻 C
📖 第 1 页 / 共 5 页
字号:
		"Usage: misdn show config [<port> | description <config element> | descriptions [general|ports]]\n"		"       Use 0 for <port> to only print the general config.\n", complete_show_config },	{ {"misdn","reload", NULL}, misdn_reload, "Reloads internal mISDN config, read from cfg-file",		"Usage: misdn reload\n" },	{ {"misdn","set","tics", NULL}, misdn_set_tics, "", 		"\n" },	{ {"misdn","show","channels", NULL}, misdn_show_cls, "Shows internal mISDN chan_list",		"Usage: misdn show channels\n" },	{ {"misdn","show","channel", NULL}, misdn_show_cl, "Shows internal mISDN chan_list",		"Usage: misdn show channels\n", complete_ch },	{ {"misdn","port","block", NULL}, misdn_port_block, "Blocks the given port",		"Usage: misdn port block\n" },	{ {"misdn","port","unblock", NULL}, misdn_port_unblock, "Unblocks the given port",		"Usage: misdn port unblock\n" },	{ {"misdn","restart","port", NULL}, misdn_restart_port, "Restarts the given port",		"Usage: misdn restart port\n" },	{ {"misdn","restart","pid", NULL}, misdn_restart_pid, "Restarts the given pid",		"Usage: misdn restart pid\n" },	{ {"misdn","send","restart", NULL},  misdn_send_restart, 	  "Sends a restart for every bchannel on the given port", 	  "Usage: misdn send restart <port>\n"},	{ {"misdn","port","up", NULL}, misdn_port_up, "Tries to establish L1 on the given port",		"Usage: misdn port up <port>\n" },	{ {"misdn","port","down", NULL}, misdn_port_down, "Tries to deactivate the L1 on the given port",		"Usage: misdn port down <port>\n" },	{ {"misdn","show","stacks", NULL}, misdn_show_stacks, "Shows internal mISDN stack_list",		"Usage: misdn show stacks\n" },	{ {"misdn","show","ports","stats", NULL}, misdn_show_ports_stats, "Shows chan_misdns call statistics per port",		"Usage: misdn show port stats\n" },	{ {"misdn","show","port", NULL}, misdn_show_port, "Shows detailed information for given port",		"Usage: misdn show port <port>\n" },	{ {"misdn","set","debug", NULL}, misdn_set_debug, "Sets Debuglevel of chan_misdn",		"Usage: misdn set debug <level> [only] | [port <port> [only]]\n", complete_debug_port },	{ {"misdn","set","crypt","debug", NULL}, misdn_set_crypt_debug, "Sets CryptDebuglevel of chan_misdn, at the moment, level={1,2}",		"Usage: misdn set crypt debug <level>\n" }};static int update_config (struct chan_list *ch, int orig) {	struct ast_channel *ast=ch->ast;	struct misdn_bchannel *bc=ch->bc;	int port;	int pres, screen;	int hdlc=0;	if (!ch) {		ast_log(LOG_WARNING, "Cannot configure without chanlist\n");		return -1;	}		ast=ch->ast;	bc=ch->bc;	if (! ast || ! bc ) {		ast_log(LOG_WARNING, "Cannot configure without ast || bc\n");		return -1;	}		port=bc->port;		chan_misdn_log(7,port,"update_config: Getting Config\n");	misdn_cfg_get( port, MISDN_CFG_HDLC, &hdlc, sizeof(int));		if (hdlc) {		switch (bc->capability) {		case INFO_CAPABILITY_DIGITAL_UNRESTRICTED:		case INFO_CAPABILITY_DIGITAL_RESTRICTED:			chan_misdn_log(1,bc->port," --> CONF HDLC\n");			bc->hdlc=1;			break;		}			}		misdn_cfg_get( port, MISDN_CFG_PRES, &pres, sizeof(int));	misdn_cfg_get( port, MISDN_CFG_SCREEN, &screen, sizeof(int));	chan_misdn_log(2,port," --> pres: %d screen: %d\n",pres, screen);			if ( (pres + screen) < 0 ) {		chan_misdn_log(2,port," --> pres: %x\n", ast->cid.cid_pres);					switch (ast->cid.cid_pres & 0x60){						case AST_PRES_RESTRICTED:			bc->pres=1;			chan_misdn_log(2, port, " --> PRES: Restricted (0x1)\n");			break;										case AST_PRES_UNAVAILABLE:			bc->pres=2;			chan_misdn_log(2, port, " --> PRES: Unavailable (0x2)\n");			break;						default:			bc->pres=0;			chan_misdn_log(2, port, " --> PRES: Allowed (0x0)\n");		}					switch (ast->cid.cid_pres & 0x3){						case AST_PRES_USER_NUMBER_UNSCREENED:			bc->screen=0;			chan_misdn_log(2, port, " --> SCREEN: Unscreened (0x0)\n");			break;		case AST_PRES_USER_NUMBER_PASSED_SCREEN:			bc->screen=1;			chan_misdn_log(2, port, " --> SCREEN: Passed Screen (0x1)\n");			break;		case AST_PRES_USER_NUMBER_FAILED_SCREEN:			bc->screen=2;			chan_misdn_log(2, port, " --> SCREEN: Failed Screen (0x2)\n");			break;						case AST_PRES_NETWORK_NUMBER:			bc->screen=3;			chan_misdn_log(2, port, " --> SCREEN: Network Nr. (0x3)\n");			break;						default:			bc->screen=0;			chan_misdn_log(2, port, " --> SCREEN: Unscreened (0x0)\n");		}				} else {		bc->screen=screen;		bc->pres=pres;	}	return 0;	}static void config_jitterbuffer(struct chan_list *ch){	struct misdn_bchannel *bc=ch->bc;	int len=ch->jb_len, threshold=ch->jb_upper_threshold;		chan_misdn_log(5,bc->port, "config_jb: Called\n");		if ( ! len ) {		chan_misdn_log(1,bc->port, "config_jb: Deactivating Jitterbuffer\n");		bc->nojitter=1;	} else {				if (len <=100 || len > 8000) {			chan_misdn_log(0,bc->port,"config_jb: Jitterbuffer out of Bounds, setting to 1000\n");			len=1000;		}				if ( threshold > len ) {			chan_misdn_log(0,bc->port,"config_jb: Jitterbuffer Threshold > Jitterbuffer setting to Jitterbuffer -1\n");		}				if ( ch->jb) {			cb_log(0,bc->port,"config_jb: We've got a Jitterbuffer Already on this port.\n");			misdn_jb_destroy(ch->jb);			ch->jb=NULL;		}				ch->jb=misdn_jb_init(len, threshold);		if (!ch->jb ) 			bc->nojitter=1;	}}void debug_numplan(int port, int numplan, char *type){	switch (numplan) {	case NUMPLAN_INTERNATIONAL:		chan_misdn_log(2, port, " --> %s: International\n",type);		break;	case NUMPLAN_NATIONAL:		chan_misdn_log(2, port, " --> %s: National\n",type);		break;	case NUMPLAN_SUBSCRIBER:		chan_misdn_log(2, port, " --> %s: Subscriber\n",type);		break;	case NUMPLAN_UNKNOWN:		chan_misdn_log(2, port, " --> %s: Unknown\n",type);		break;		/* Maybe we should cut off the prefix if present ? */	default:		chan_misdn_log(0, port, " --> !!!! Wrong dialplan setting, please see the misdn.conf sample file\n ");		break;	}}#ifdef MISDN_1_2static int update_pipeline_config(struct misdn_bchannel *bc){	int ec;	misdn_cfg_get(bc->port, MISDN_CFG_PIPELINE, bc->pipeline, sizeof(bc->pipeline));	if (*bc->pipeline)		return 0;	misdn_cfg_get(bc->port, MISDN_CFG_ECHOCANCEL, &ec, sizeof(int));	if (ec == 1)		snprintf(bc->pipeline, sizeof(bc->pipeline) - 1, "mg2ec");	else if (ec > 1)		snprintf(bc->pipeline, sizeof(bc->pipeline) - 1, "mg2ec(deftaps=%d)", ec);	return 0;}#elsestatic int update_ec_config(struct misdn_bchannel *bc){	int ec;	int port=bc->port;			misdn_cfg_get( port, MISDN_CFG_ECHOCANCEL, &ec, sizeof(int));		if (ec == 1 ) {		bc->ec_enable=1;	} else if ( ec > 1 ) {		bc->ec_enable=1;		bc->ec_deftaps=ec;	}	return 0;}#endifstatic int read_config(struct chan_list *ch, int orig) {	struct ast_channel *ast;	struct misdn_bchannel *bc;	int port;	char lang[BUFFERSIZE+1];	char localmusicclass[BUFFERSIZE+1];  	char faxdetect[BUFFERSIZE+1];	int hdlc = 0;	if (!ch) {		ast_log(LOG_WARNING, "Cannot configure without chanlist\n");		return -1;	}	ast=ch->ast;	bc=ch->bc;	if (! ast || ! bc ) {		ast_log(LOG_WARNING, "Cannot configure without ast || bc\n");		return -1;	}		port=bc->port;		chan_misdn_log(1,port,"read_config: Getting Config\n");	misdn_cfg_get( port, MISDN_CFG_LANGUAGE, lang, BUFFERSIZE);	ast_string_field_set(ast, language, lang);	misdn_cfg_get( port, MISDN_CFG_MUSICCLASS, localmusicclass, BUFFERSIZE);	ast_string_field_set(ast, musicclass, localmusicclass);			misdn_cfg_get( port, MISDN_CFG_TXGAIN, &bc->txgain, sizeof(int));	misdn_cfg_get( port, MISDN_CFG_RXGAIN, &bc->rxgain, sizeof(int));		misdn_cfg_get( port, MISDN_CFG_INCOMING_EARLY_AUDIO, &ch->incoming_early_audio, sizeof(int));		misdn_cfg_get( port, MISDN_CFG_SENDDTMF, &bc->send_dtmf, sizeof(int));	misdn_cfg_get( port, MISDN_CFG_ASTDTMF, &ch->ast_dsp, sizeof(int));	if (ch->ast_dsp) {		ch->ignore_dtmf=1;	}	misdn_cfg_get( port, MISDN_CFG_NEED_MORE_INFOS, &bc->need_more_infos, sizeof(int));	misdn_cfg_get( port, MISDN_CFG_NTTIMEOUT, &ch->nttimeout, sizeof(int));		misdn_cfg_get( port, MISDN_CFG_NOAUTORESPOND_ON_SETUP, &ch->noautorespond_on_setup, sizeof(int));		misdn_cfg_get( port, MISDN_CFG_FAR_ALERTING, &ch->far_alerting, sizeof(int));	misdn_cfg_get( port, MISDN_CFG_ALLOWED_BEARERS, &ch->allowed_bearers, BUFFERSIZE);	  	misdn_cfg_get( port, MISDN_CFG_FAXDETECT, faxdetect, BUFFERSIZE);		misdn_cfg_get( port, MISDN_CFG_HDLC, &hdlc, sizeof(int));		if (hdlc) {		switch (bc->capability) {		case INFO_CAPABILITY_DIGITAL_UNRESTRICTED:		case INFO_CAPABILITY_DIGITAL_RESTRICTED:			chan_misdn_log(1,bc->port," --> CONF HDLC\n");			bc->hdlc=1;			break;		}			}	/*Initialize new Jitterbuffer*/	{		misdn_cfg_get( port, MISDN_CFG_JITTERBUFFER, &ch->jb_len, sizeof(int));		misdn_cfg_get( port, MISDN_CFG_JITTERBUFFER_UPPER_THRESHOLD, &ch->jb_upper_threshold, sizeof(int));				config_jitterbuffer(ch);	}		misdn_cfg_get( bc->port, MISDN_CFG_CONTEXT, ch->context, sizeof(ch->context));		ast_copy_string (ast->context,ch->context,sizeof(ast->context));	#ifdef MISDN_1_2	update_pipeline_config(bc);#else	update_ec_config(bc);#endif	{		int eb3;				misdn_cfg_get( bc->port, MISDN_CFG_EARLY_BCONNECT, &eb3, sizeof(int));		bc->early_bconnect=eb3;	}		port=bc->port;		{		char buf[256];		ast_group_t pg,cg;				misdn_cfg_get(port, MISDN_CFG_PICKUPGROUP, &pg, sizeof(pg));		misdn_cfg_get(port, MISDN_CFG_CALLGROUP, &cg, sizeof(cg));				chan_misdn_log(5, port, " --> * CallGrp:%s PickupGrp:%s\n",ast_print_group(buf,sizeof(buf),cg),ast_print_group(buf,sizeof(buf),pg));		ast->pickupgroup=pg;		ast->callgroup=cg;	}		if ( orig  == ORG_AST) {		misdn_cfg_get( port, MISDN_CFG_TE_CHOOSE_CHANNEL, &(bc->te_choose_channel), sizeof(int));		 		if (strstr(faxdetect, "outgoing") || strstr(faxdetect, "both")) { 			if (strstr(faxdetect, "nojump")) 				ch->faxdetect=2; 			else 				ch->faxdetect=1; 		}		{			char callerid[BUFFERSIZE+1];			misdn_cfg_get( port, MISDN_CFG_CALLERID, callerid, BUFFERSIZE);			if ( ! ast_strlen_zero(callerid) ) {				chan_misdn_log(1, port, " --> * Setting Cid to %s\n", callerid);				{					int l = sizeof(bc->oad);					strncpy(bc->oad,callerid, l);					bc->oad[l-1] = 0;				}			}						misdn_cfg_get( port, MISDN_CFG_DIALPLAN, &bc->dnumplan, sizeof(int));			misdn_cfg_get( port, MISDN_CFG_LOCALDIALPLAN, &bc->onumplan, sizeof(int));			misdn_cfg_get( port, MISDN_CFG_CPNDIALPLAN, &bc->cpnnumplan, sizeof(int));			debug_numplan(port, bc->dnumplan,"TON");			debug_numplan(port, bc->onumplan,"LTON");			debug_numplan(port, bc->cpnnumplan,"CTON");		}		ch->overlap_dial = 0;	} else { /** ORIGINATOR MISDN **/		char prefix[BUFFERSIZE+1]=""; 		if (strstr(faxdetect, "incoming") || strstr(faxdetect, "both")) { 			if (strstr(faxdetect, "nojump")) 				ch->faxdetect=2; 			else 				ch->faxdetect=1; 		}			misdn_cfg_get( port, MISDN_CFG_CPNDIALPLAN, &bc->cpnnumplan, sizeof(int));		debug_numplan(port, bc->cpnnumplan,"CTON");				switch( bc->onumplan ) {		case NUMPLAN_INTERNATIONAL:			misdn_cfg_get( bc->port, MISDN_CFG_INTERNATPREFIX, prefix, BUFFERSIZE);			break;					case NUMPLAN_NATIONAL:			misdn_cfg_get( bc->port, MISDN_CFG_NATPREFIX, prefix, BUFFERSIZE);			break;		default:			break;		}				{			int l = strlen(prefix) + strlen(bc->oad);			char *tmp = alloca(l+1);			strcpy(tmp,prefix);			strcat(tmp,bc->oad);			strcpy(bc->oad,tmp);		}				if (!ast_strlen_zero(bc->dad)) {			ast_copy_string(bc->orig_dad,bc->dad, sizeof(bc->orig_dad));		}				if ( ast_strlen_zero(bc->dad) && !ast_strlen_zero(bc->keypad)) {			ast_copy_string(bc->dad,bc->keypad, sizeof(bc->dad));		}		prefix[0] = 0;				switch( bc->dnumplan ) {		case NUMPLAN_INTERNATIONAL:			misdn_cfg_get( bc->port, MISDN_CFG_INTERNATPREFIX, prefix, BUFFERSIZE);			break;		case NUMPLAN_NATIONAL:			misdn_cfg_get( bc->port, MISDN_CFG_NATPREFIX, prefix, BUFFERSIZE);			break;		default:			break;		}				{			int l = strlen(prefix) + strlen(bc->dad);			char *tmp = alloca(l+1);			strcpy(tmp,prefix);			strcat(tmp,bc->dad);			strcpy(bc->dad,tmp);		}				if ( strcmp(bc->dad,ast->exten)) {			ast_copy_string(ast->exten, bc->dad, sizeof(ast->exten));		}				ast_set_callerid(ast, bc->oad, NULL, bc->oad);				if ( !ast_strlen_zero(bc->rad) ) {			if (ast->cid.cid_rdnis)				free(ast->cid.cid_rdnis);			ast->cid.cid_rdnis = strdup(bc->rad);		}			misdn_cfg_get(bc->port, MISDN_CFG_OVERLAP_DIAL, &ch->overlap_dial, sizeof(ch->overlap_dial));		ast_mutex_init(&ch->overlap_tv_lock);	} /* ORIG MISDN END */	ch->overlap_dial_task = -1;		if (ch->faxdetect  || ch->ast_dsp) {		misdn_cfg_get( port, MISDN_CFG_FAXDETECT_TIMEOUT, &ch->faxdetect_timeout, sizeof(ch->faxdetect_timeout));		if (!ch->dsp)			ch->dsp = ast_dsp_new();		if (ch->dsp) {			if (ch->faxdetect) 				ast_dsp_set_features(ch->dsp, DSP_FEATURE_DTMF_DETECT | DSP_FEATURE_FAX_DETECT);			else 				ast_dsp_set_features(ch->dsp, DSP_FEATURE_DTMF_DETECT );		}		if (!ch->trans)			ch->trans=ast_translator_build_path(AST_FORMAT_SLINEAR, AST_FORMAT_ALAW);	}	/* AOCD initialization */	bc->AOCDtype = Fac_None;	return 0;}/*****************************//*** AST Indications Start ***//*****************************/static int misdn_call(struct ast_channel *ast, char *dest, int timeout){	int port=0;	int r;	int exceed;	struct chan_list *ch=MISDN_ASTERISK_TECH_PVT(ast);	struct misdn_bchannel *newbc;	char *opts=NULL, *ext;	{		ext = ast_strdupa(dest);		strsep(&ext,"/");		if (ext) {			opts=ext;			strsep(&opts,"/");		}  else {			ast_log(LOG_WARNING, "Malformed dialstring\n");			return -1;		}	}	if (!ast) {

⌨️ 快捷键说明

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