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

📄 isdn_msg_parser.c

📁 asterisk 是一个很有知名度开源软件
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * Chan_Misdn -- Channel Driver for Asterisk * * Interface to mISDN * * Copyright (C) 2004, Christian Richter * * Christian Richter <crich@beronet.com> * * This program is free software, distributed under the terms of * the GNU General Public License *//*! \file  * \brief Interface to mISDN - message parser * \author Christian Richter <crich@beronet.com> */#include "isdn_lib_intern.h"#include "isdn_lib.h"#include "ie.c"static void set_channel(struct misdn_bchannel *bc, int channel){	cb_log(3,bc->port,"set_channel: bc->channel:%d channel:%d\n", bc->channel, channel);			if (channel==0xff) {		/* any channel */		channel=-1;	}		/*  ALERT: is that everytime true ?  */	if (channel > 0 && bc->nt ) {				if (bc->channel && ( bc->channel != 0xff) ) {			cb_log(0,bc->port,"We already have a channel (%d)\n", bc->channel);		} else {			bc->channel = channel;			cb_event(EVENT_NEW_CHANNEL,bc,NULL);		}	}		if (channel > 0 && !bc->nt ) {		bc->channel = channel;		cb_event(EVENT_NEW_CHANNEL,bc,NULL);	}}static void parse_proceeding (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) {	int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;	CALL_PROCEEDING_t *proceeding=(CALL_PROCEEDING_t*)((unsigned long)msg->data+ HEADER_LEN);	//struct misdn_stack *stack=get_stack_by_bc(bc);		{		int  exclusive, channel;		dec_ie_channel_id(proceeding->CHANNEL_ID, (Q931_info_t *)proceeding, &exclusive, &channel, nt,bc);		set_channel(bc,channel);			}		dec_ie_progress(proceeding->PROGRESS, (Q931_info_t *)proceeding, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);		#ifdef DEBUG 	printf("Parsing PROCEEDING Msg\n"); #endif}static msg_t *build_proceeding (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt){	int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;	CALL_PROCEEDING_t *proceeding;	msg_t *msg =(msg_t*)create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING,  bc?bc->l3_id:-1, sizeof(CALL_PROCEEDING_t) ,nt);   	proceeding=(CALL_PROCEEDING_t*)((msg->data+HEADER_LEN));	enc_ie_channel_id(&proceeding->CHANNEL_ID, msg, 1,bc->channel, nt,bc);  	if (nt) 		enc_ie_progress(&proceeding->PROGRESS, msg, 0, nt?1:5, 8, nt,bc);  #ifdef DEBUG 	printf("Building PROCEEDING Msg\n"); #endif	return msg; }static void parse_alerting (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) {	int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN; 	ALERTING_t *alerting=(ALERTING_t*)((unsigned long)(msg->data+HEADER_LEN));	//Q931_info_t *qi=(Q931_info_t*)(msg->data+HEADER_LEN);		dec_ie_progress(alerting->PROGRESS, (Q931_info_t *)alerting, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);	#ifdef DEBUG 	printf("Parsing ALERTING Msg\n"); #endif }static msg_t *build_alerting (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) {	int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;	ALERTING_t *alerting;	msg_t *msg =(msg_t*)create_l3msg(CC_ALERTING | REQUEST, MT_ALERTING,  bc?bc->l3_id:-1, sizeof(ALERTING_t) ,nt);   	alerting=(ALERTING_t*)((msg->data+HEADER_LEN));   	enc_ie_channel_id(&alerting->CHANNEL_ID, msg, 1,bc->channel, nt,bc);		if (nt) 		enc_ie_progress(&alerting->PROGRESS, msg, 0, nt?1:5, 8, nt,bc);#ifdef DEBUG 	printf("Building ALERTING Msg\n"); #endif	return msg; }static void parse_progress (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) {	int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;	PROGRESS_t *progress=(PROGRESS_t*)((unsigned long)(msg->data+HEADER_LEN)); 	//Q931_info_t *qi=(Q931_info_t*)(msg->data+HEADER_LEN);  		dec_ie_progress(progress->PROGRESS, (Q931_info_t *)progress, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);	#ifdef DEBUG 	printf("Parsing PROGRESS Msg\n"); #endif}static msg_t *build_progress (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) {	int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;	PROGRESS_t *progress;	msg_t *msg =(msg_t*)create_l3msg(CC_PROGRESS | REQUEST, MT_PROGRESS,  bc?bc->l3_id:-1, sizeof(PROGRESS_t) ,nt);  	progress=(PROGRESS_t*)((msg->data+HEADER_LEN)); #ifdef DEBUG 	printf("Building PROGRESS Msg\n"); #endif	return msg; }static void parse_setup (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) { 	int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;	SETUP_t *setup= (SETUP_t*)((unsigned long)msg->data+HEADER_LEN);	Q931_info_t *qi=(Q931_info_t*)((unsigned long)msg->data+HEADER_LEN);#ifdef DEBUG 	printf("Parsing SETUP Msg\n"); #endif	{		int type,plan,present, screen;		char id[32];		dec_ie_calling_pn(setup->CALLING_PN, qi, &type, &plan, &present, &screen, id, sizeof(id)-1, nt,bc);		bc->onumplan=type; 		strcpy(bc->oad, id);		switch (present) {		case 0:			bc->pres=0; /* screened */			break;		case 1:			bc->pres=1; /* not screened */			break;		default:			bc->pres=0;		}		switch (screen) {		case 0:			break;		default:			;		} 	}	{		int  type, plan;		char number[32]; 		dec_ie_called_pn(setup->CALLED_PN, (Q931_info_t *)setup, &type, &plan, number, sizeof(number)-1, nt,bc);		strcpy(bc->dad, number);		bc->dnumplan=type; 	}	{		char keypad[32];		dec_ie_keypad(setup->KEYPAD, (Q931_info_t *)setup, keypad, sizeof(keypad)-1, nt,bc);		strcpy(bc->keypad, keypad);	}	{		dec_ie_complete(setup->COMPLETE, (Q931_info_t *)setup, &bc->sending_complete, nt,bc);			}  	{		int  type, plan, present, screen, reason;		char id[32]; 		dec_ie_redir_nr(setup->REDIR_NR, (Q931_info_t *)setup, &type, &plan, &present, &screen, &reason, id, sizeof(id)-1, nt,bc);    		strcpy(bc->rad, id);		bc->rnumplan=type; 	}	{		int  coding, capability, mode, rate, multi, user, async, urate, stopbits, dbits, parity;		dec_ie_bearer(setup->BEARER, (Q931_info_t *)setup, &coding, &capability, &mode, &rate, &multi, &user, &async, &urate, &stopbits, &dbits, &parity, nt,bc);		switch (capability) {		case -1: bc->capability=INFO_CAPABILITY_DIGITAL_UNRESTRICTED; 			break;		case 0: bc->capability=INFO_CAPABILITY_SPEECH;			break;		case 18: bc->capability=INFO_CAPABILITY_VIDEO;			break;		case 8: bc->capability=INFO_CAPABILITY_DIGITAL_UNRESTRICTED;			bc->user1 = user;			bc->urate = urate;						bc->rate = rate;			bc->mode = mode;			break;		case 9: bc->capability=INFO_CAPABILITY_DIGITAL_RESTRICTED;			break;		default:			break;		}				switch(user) {		case 2:			bc->law=INFO_CODEC_ULAW;			break;		case 3:			bc->law=INFO_CODEC_ALAW;			break;		default:			bc->law=INFO_CODEC_ALAW;					}				bc->capability=capability; 	}	{		int  exclusive, channel;		dec_ie_channel_id(setup->CHANNEL_ID, (Q931_info_t *)setup, &exclusive, &channel, nt,bc);				set_channel(bc,channel);	}	{		int  protocol ;		dec_ie_useruser(setup->USER_USER, (Q931_info_t *)setup, &protocol, bc->uu, &bc->uulen, nt,bc);		if (bc->uulen) cb_log(1,bc->port,"USERUESRINFO:%s\n",bc->uu);		else		cb_log(1,bc->port,"NO USERUESRINFO\n");	}		dec_ie_progress(setup->PROGRESS, (Q931_info_t *)setup, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);	}#define ANY_CHANNEL 0xff /* IE attribut for 'any channel' */static msg_t *build_setup (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) {	int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;	SETUP_t *setup;	msg_t *msg =(msg_t*)create_l3msg(CC_SETUP | REQUEST, MT_SETUP,  bc?bc->l3_id:-1, sizeof(SETUP_t) ,nt);   	setup=(SETUP_t*)((msg->data+HEADER_LEN));   	if (bc->channel == 0 || bc->channel == ANY_CHANNEL || bc->channel==-1)		enc_ie_channel_id(&setup->CHANNEL_ID, msg, 0, bc->channel, nt,bc);	else 		enc_ie_channel_id(&setup->CHANNEL_ID, msg, 1, bc->channel, nt,bc);			{		int type=bc->onumplan,plan=1,present=bc->pres,screen=bc->screen;		enc_ie_calling_pn(&setup->CALLING_PN, msg, type, plan, present,				  screen, bc->oad, nt, bc);	}  	{		if (bc->dad[0])			enc_ie_called_pn(&setup->CALLED_PN, msg, bc->dnumplan, 1, bc->dad, nt,bc);	}	{		if (bc->rad[0])			enc_ie_redir_nr(&setup->REDIR_NR, msg, 1, 1,  bc->pres, bc->screen, 0, bc->rad, nt,bc);	}	{		if (bc->keypad[0])			enc_ie_keypad(&setup->KEYPAD, msg, bc->keypad, nt,bc);	}	  	if (*bc->display) {		enc_ie_display(&setup->DISPLAY, msg, bc->display, nt,bc);	}  	{		int coding=0, capability, mode=0 /*  2 for packet ! */			,user, rate=0x10;		switch (bc->law) {		case INFO_CODEC_ULAW: user=2;			break;		case INFO_CODEC_ALAW: user=3;			break;		default:			user=3;		}				switch (bc->capability) {		case INFO_CAPABILITY_SPEECH: capability = 0;			break;		case INFO_CAPABILITY_DIGITAL_UNRESTRICTED: capability = 8;			user=-1;			mode=bc->mode;			rate=bc->rate;			break;		case INFO_CAPABILITY_DIGITAL_RESTRICTED: capability = 9;			user=-1;			break;		default:			capability=bc->capability; 		}				    		enc_ie_bearer(&setup->BEARER, msg, coding, capability, mode, rate, -1, user, nt,bc);	}	if (bc->sending_complete) {		enc_ie_complete(&setup->COMPLETE,msg, bc->sending_complete, nt, bc);	}  	if (bc->uulen) {		int  protocol=4;		enc_ie_useruser(&setup->USER_USER, msg, protocol, bc->uu, bc->uulen, nt,bc);		cb_log(1,bc->port,"ENCODING USERUESRINFO:%s\n",bc->uu);	}#ifdef DEBUG 	printf("Building SETUP Msg\n"); #endif	return msg; }static void parse_connect (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) {	int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;	CONNECT_t *connect=(CONNECT_t*)((unsigned long)(msg->data+HEADER_LEN));  	int plan,pres,screen;		bc->ces = connect->ces;	bc->ces = connect->ces;	dec_ie_progress(connect->PROGRESS, (Q931_info_t *)connect, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);	dec_ie_connected_pn(connect->CONNECT_PN,(Q931_info_t *)connect, &bc->cpnnumplan, &plan, &pres, &screen, bc->cad, 31, nt, bc);	/*		cb_log(1,bc->port,"CONNETED PN: %s cpn_dialplan:%d\n", connected_pn, type);	*/	#ifdef DEBUG 	printf("Parsing CONNECT Msg\n"); #endif}static msg_t *build_connect (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) {	int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;	CONNECT_t *connect;	msg_t *msg =(msg_t*)create_l3msg(CC_CONNECT | REQUEST, MT_CONNECT,  bc?bc->l3_id:-1, sizeof(CONNECT_t) ,nt); 		cb_log(6,bc->port,"BUILD_CONNECT: bc:%p bc->l3id:%d, nt:%d\n",bc,bc->l3_id,nt);	connect=(CONNECT_t*)((msg->data+HEADER_LEN)); 	if (nt) {		time_t now;		time(&now);		enc_ie_date(&connect->DATE, msg, now, nt,bc);	}  	{		int type=bc->cpnnumplan, plan=1, present=2, screen=0;		enc_ie_connected_pn(&connect->CONNECT_PN, msg, type,plan, present, screen, bc->cad, nt , bc);	}#ifdef DEBUG 	printf("Building CONNECT Msg\n"); #endif	return msg; }static void parse_setup_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) {	int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;	SETUP_ACKNOWLEDGE_t *setup_acknowledge=(SETUP_ACKNOWLEDGE_t*)((unsigned long)(msg->data+HEADER_LEN));	{		int  exclusive, channel;		dec_ie_channel_id(setup_acknowledge->CHANNEL_ID, (Q931_info_t *)setup_acknowledge, &exclusive, &channel, nt,bc);		set_channel(bc, channel);	}		dec_ie_progress(setup_acknowledge->PROGRESS, (Q931_info_t *)setup_acknowledge, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);#ifdef DEBUG 	printf("Parsing SETUP_ACKNOWLEDGE Msg\n"); #endif }static msg_t *build_setup_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) {	int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;	SETUP_ACKNOWLEDGE_t *setup_acknowledge;	msg_t *msg =(msg_t*)create_l3msg(CC_SETUP_ACKNOWLEDGE | REQUEST, MT_SETUP_ACKNOWLEDGE,  bc?bc->l3_id:-1, sizeof(SETUP_ACKNOWLEDGE_t) ,nt);  	setup_acknowledge=(SETUP_ACKNOWLEDGE_t*)((msg->data+HEADER_LEN));   	enc_ie_channel_id(&setup_acknowledge->CHANNEL_ID, msg, 1,bc->channel, nt,bc);  	if (nt) 		enc_ie_progress(&setup_acknowledge->PROGRESS, msg, 0, nt?1:5, 8, nt,bc);  #ifdef DEBUG 	printf("Building SETUP_ACKNOWLEDGE Msg\n"); #endif	return msg; }

⌨️ 快捷键说明

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