isdn_msg_parser.c

来自「一个非常美妙的proxy。功能强大。基于sip的协议。如果还要的话」· C语言 代码 · 共 1,357 行 · 第 1/3 页

C
1,357
字号
/* * 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 */#include "isdn_lib.h"#include "ie.c"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);				if (channel==0xff) /* any channel */			channel=-1;    		/*  ALERT: is that everytime true ?  */		if (channel > 0 && stack->mode == NT_MODE) 			bc->channel = channel;	}		dec_ie_progress(proceeding->PROGRESS, (Q931_info_t *)proceeding, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);	#if DEBUG 	printf("Parsing PROCEEDING Msg\n"); #endif}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);  #if DEBUG 	printf("Building PROCEEDING Msg\n"); #endif	return msg; }void print_proceeding (struct isdn_msg msgs[]) {}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);	#if DEBUG 	printf("Parsing ALERTING Msg\n"); #endif }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);#if DEBUG 	printf("Building ALERTING Msg\n"); #endif	return msg; }void print_alerting (struct isdn_msg msgs[]) {}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);	#if DEBUG 	printf("Parsing PROGRESS Msg\n"); #endif}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)); #if DEBUG 	printf("Building PROGRESS Msg\n"); #endif	return msg; }void print_progress (struct isdn_msg msgs[]) {}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);#if 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, (unsigned char *)id, sizeof(id), nt,bc);		bc->onumplan=type; 		strcpy(bc->oad, id);		switch (present) {		case 0://			cb_log(3, bc->stack->port, " --> Pres:0\n");			bc->pres=0; /* screened */			break;		case 1://			cb_log(3, bc->stack->port, " --> Pres:1\n");			bc->pres=1; /* not screened */			break;		default://			cb_log(3, bc->stack->port, " --> Pres:%d\n",present);			bc->pres=0;		}		switch (screen) {		case 0://			cb_log(4, bc->stack->port, " --> Screen:0\n");			break;		default://			cb_log(4, bc->stack->port, " --> Screen:%d\n",screen);			;		} 	}	{		int  type, plan;		char number[32]; 		dec_ie_called_pn(setup->CALLED_PN, (Q931_info_t *)setup, &type, &plan, (unsigned char *)number, sizeof(number), nt,bc);		strcpy(bc->dad, number);		bc->dnumplan=type; 	}	{		char keypad[32];		dec_ie_keypad(setup->KEYPAD, (Q931_info_t *)setup, (unsigned char *)keypad, sizeof(keypad), nt,bc);		strcpy(bc->keypad, keypad);	}	{		int  sending_complete;		dec_ie_complete(setup->COMPLETE, (Q931_info_t *)setup, &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, (unsigned char *)id, sizeof(id), nt,bc);    		strcpy(bc->rad, id);		bc->rnumplan=type; //		cb_log(3, bc->stack->port, " --> Redirecting number (REDIR_NR): '%s'\n", id);	}	{		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; //			cb_log(2, bc->stack->port, " --> cap -1 -> digital\n");			break;		case 0: bc->capability=INFO_CAPABILITY_SPEECH;//			cb_log(2, bc->stack->port, " --> cap speech\n");			break;		case 8: bc->capability=INFO_CAPABILITY_DIGITAL_UNRESTRICTED;			bc->user1 = user;			bc->async = async;			bc->urate = urate;						bc->rate = rate;			bc->mode = mode;			//			cb_log(2, bc->stack->port, " --> cap unres Digital (user l1 %d, async %d, user rate %d\n", user, async, urate);			break;		case 9: bc->capability=INFO_CAPABILITY_DIGITAL_RESTRICTED;//			cb_log(2, bc->stack->port, " --> cap res Digital\n");			break;		default://			cb_log(2, bc->stack->port, " --> cap Else\n");			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);		if (channel==0xff) /* any channel */			channel=-1;		if (channel > 0) 			bc->channel = channel;	}		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' */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));   //	cb_log(2, bc->stack->port, " --> oad %s dad %s channel %d\n",bc->oad, bc->dad,bc->channel);	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->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;			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 DEBUG 	printf("Building SETUP Msg\n"); #endif	return msg; }void print_setup (struct isdn_msg msgs[]) {}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));  	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);	#if DEBUG 	printf("Parsing CONNECT Msg\n"); #endif}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);   	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=0, plan=1, present=2, screen=0;		enc_ie_connected_pn(&connect->CONNECT_PN, msg, type,plan, present, screen, (unsigned char*) bc->dad , nt , bc);	}#if DEBUG 	printf("Building CONNECT Msg\n"); #endif	return msg; }void print_connect (struct isdn_msg msgs[]) {}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);		if (channel==0xff) /* any channel */			channel=-1;		if (channel > 0) 			bc->channel = channel;	}		dec_ie_progress(setup_acknowledge->PROGRESS, (Q931_info_t *)setup_acknowledge, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);#if DEBUG 	printf("Parsing SETUP_ACKNOWLEDGE Msg\n"); #endif }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);  #if DEBUG 	printf("Building SETUP_ACKNOWLEDGE Msg\n"); #endif	return msg; }void print_setup_acknowledge (struct isdn_msg msgs[]) {}void parse_connect_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) {#if DEBUG 	printf("Parsing CONNECT_ACKNOWLEDGE Msg\n"); #endif }msg_t *build_connect_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) {	int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;	CONNECT_ACKNOWLEDGE_t *connect_acknowledge;	msg_t *msg =(msg_t*)create_l3msg(CC_CONNECT | RESPONSE, MT_CONNECT,  bc?bc->l3_id:-1, sizeof(CONNECT_ACKNOWLEDGE_t) ,nt);  	connect_acknowledge=(CONNECT_ACKNOWLEDGE_t*)((msg->data+HEADER_LEN));   	enc_ie_channel_id(&connect_acknowledge->CHANNEL_ID, msg, 1, bc->channel, nt,bc);  #if DEBUG 	printf("Building CONNECT_ACKNOWLEDGE Msg\n"); #endif	return msg; }void print_connect_acknowledge (struct isdn_msg msgs[]) {}void parse_user_information (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) {#if DEBUG 	printf("Parsing USER_INFORMATION Msg\n"); #endif }msg_t *build_user_information (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) {	int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;	USER_INFORMATION_t *user_information;

⌨️ 快捷键说明

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