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

📄 ie.c

📁 Asterisk中信道部分的源码 。。。。
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * Chan_Misdn -- Channel Driver for Asterisk * * Interface to mISDN * * Copyright (C) 2005, Christian Richter * * Christian Richter <crich@beronet.com> * * heaviliy patched from jollys ie.cpp, jolly gave me ALL * rights for this code, i can even have my own copyright on it. * * This program is free software, distributed under the terms of * the GNU General Public License *//*  the pointer of enc_ie_* always points to the IE itself  if qi is not NULL (TE-mode), offset is set*/#include <string.h>#include <mISDNuser/mISDNlib.h>#include <mISDNuser/isdn_net.h>#include <mISDNuser/l3dss1.h>#include <mISDNuser/net_l3.h>#define MISDN_IE_DEBG 0/* support stuff */static void strnncpy(char *dest, char *src, int len, int dst_len){	if (len > dst_len-1)		len = dst_len-1;	strncpy((char *)dest, (char *)src, len);	dest[len] = '\0';}/* IE_COMPLETE */static void enc_ie_complete(unsigned char **ntmode, msg_t *msg, int complete, int nt, struct misdn_bchannel *bc){	unsigned char *p;	Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);	if (complete<0 || complete>1)	{		printf("%s: ERROR: complete(%d) is out of range.\n", __FUNCTION__, complete);		return;	}	if (complete)		if (MISDN_IE_DEBG) printf("    complete=%d\n", complete);	if (complete)	{		p = msg_put(msg, 1);		if (nt)		{			*ntmode = p;		} else			qi->QI_ELEMENT(sending_complete) = p - (unsigned char *)qi - sizeof(Q931_info_t);		p[0] = IE_COMPLETE;	}}static void dec_ie_complete(unsigned char *p, Q931_info_t *qi, int *complete, int nt, struct misdn_bchannel *bc){	*complete = 0;	if (!nt)	{		if (qi->QI_ELEMENT(sending_complete))			*complete = 1;	} else		if (p)			*complete = 1;	if (*complete)		if (MISDN_IE_DEBG) printf("    complete=%d\n", *complete);}/* IE_BEARER */static void enc_ie_bearer(unsigned char **ntmode, msg_t *msg, int coding, int capability, int mode, int rate, int multi, int user, int nt, struct misdn_bchannel *bc){	unsigned char *p;	Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);	int l;	if (coding<0 || coding>3)	{		printf("%s: ERROR: coding(%d) is out of range.\n", __FUNCTION__, coding);		return;	}	if (capability<0 || capability>31)	{		printf("%s: ERROR: capability(%d) is out of range.\n", __FUNCTION__, capability);		return;	}	if (mode<0 || mode>3)	{		printf("%s: ERROR: mode(%d) is out of range.\n", __FUNCTION__, mode);		return;	}	if (rate<0 || rate>31)	{		printf("%s: ERROR: rate(%d) is out of range.\n", __FUNCTION__, rate);		return;	}	if (multi>127)	{		printf("%s: ERROR: multi(%d) is out of range.\n", __FUNCTION__, multi);		return;	}	if (user>31)	{		printf("%s: ERROR: user L1(%d) is out of range.\n", __FUNCTION__, rate);		return;	}	if (rate!=24 && multi>=0)	{		printf("%s: WARNING: multi(%d) is only possible if rate(%d) would be 24.\n", __FUNCTION__, multi, rate);		multi = -1;	}	if (MISDN_IE_DEBG) printf("    coding=%d capability=%d mode=%d rate=%d multi=%d user=%d\n", coding, capability, mode, rate, multi, user);	l = 2 + (multi>=0) + (user>=0);	p = msg_put(msg, l+2);	if (nt)		*ntmode = p+1;	else		qi->QI_ELEMENT(bearer_capability) = p - (unsigned char *)qi - sizeof(Q931_info_t);	p[0] = IE_BEARER;	p[1] = l;	p[2] = 0x80 + (coding<<5) + capability;	p[3] = 0x80 + (mode<<5) + rate;	if (multi >= 0)		p[4] = 0x80 + multi;	if (user >= 0)		p[4+(multi>=0)] = 0xa0 + user;}static void dec_ie_bearer(unsigned char *p, Q931_info_t *qi, int *coding, int *capability, int *mode, int *rate, int *multi, int *user, 		   int *async, int *urate, int *stopbits, int *dbits, int *parity, int nt, struct misdn_bchannel *bc){	int octet;	*coding = -1;	*capability = -1;	*mode = -1;	*rate = -1;	*multi = -1;	*user = -1;	*async = -1;	*urate = -1;	*stopbits = -1;	*dbits = -1;	*parity = -1;		if (!nt)	{		p = NULL;#ifdef LLC_SUPPORT		if (qi->QI_ELEMENT(llc)) {						p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->QI_ELEMENT(llc) + 1;		}#endif		if (qi->QI_ELEMENT(bearer_capability))			p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->QI_ELEMENT(bearer_capability) + 1;	}	if (!p)		return;	if (p[0] < 2)	{		printf("%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);		return;	}		*coding = (p[1]&0x60) >> 5;	*capability = p[1] & 0x1f;	octet = 2;	if (!(p[1] & 0x80))		octet++;	if (p[0] < octet)		goto done;	*mode = (p[octet]&0x60) >> 5;	*rate = p[octet] & 0x1f;	octet++;	if (p[0] < octet)		goto done;	if (*rate == 0x18) {		/* Rate multiplier only present if 64Kb/s base rate */		*multi = p[octet++] & 0x7f;	}	if (p[0] < octet)		goto done;	/* Start L1 info */	if ((p[octet] & 0x60) == 0x20) {		*user = p[octet] & 0x1f;		if (p[0] <= octet)			goto done;				if (p[octet++] & 0x80)			goto l2;		*async = !!(p[octet] & 0x40);		/* 0x20 is inband negotiation */		*urate = p[octet] & 0x1f;		if (p[0] <= octet)			goto done;				if (p[octet++] & 0x80)			goto l2;		/* Ignore next byte for now: Intermediate rate, NIC, flow control */		if (p[0] <= octet)			goto done;				if (p[octet++] & 0x80)			goto l2;		/* And the next one. Header, multiframe, mode, assignor/ee, negotiation */		if (p[0] <= octet)			goto done;				if (!p[octet++] & 0x80)			goto l2;		/* Wheee. V.110 speed information */		*stopbits = (p[octet] & 0x60) >> 5;		*dbits = (p[octet] & 0x18) >> 3; 		*parity = p[octet] & 7;		octet++;	} l2: /* Nobody seems to want the rest so we don't bother (yet) */ done:			if (MISDN_IE_DEBG) printf("    coding=%d capability=%d mode=%d rate=%d multi=%d user=%d async=%d urate=%d stopbits=%d dbits=%d parity=%d\n", *coding, *capability, *mode, *rate, *multi, *user, *async, *urate, *stopbits, *dbits, *parity);}/* IE_CALL_ID */#if 0static void enc_ie_call_id(unsigned char **ntmode, msg_t *msg, char *callid, int callid_len, int nt, struct misdn_bchannel *bc){	unsigned char *p;	Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);	int l;	char debug[25];	int i;	if (!callid || callid_len<=0)	{		return;	}	if (callid_len>8)	{		printf("%s: ERROR: callid_len(%d) is out of range.\n", __FUNCTION__, callid_len);		return;	}	i = 0;	while(i < callid_len)	{		if (MISDN_IE_DEBG) printf(debug+(i*3), " %02x", callid[i]);		i++;	}			if (MISDN_IE_DEBG) printf("    callid%s\n", debug);	l = callid_len;	p = msg_put(msg, l+2);	if (nt)		*ntmode = p+1;	else		qi->QI_ELEMENT(call_id) = p - (unsigned char *)qi - sizeof(Q931_info_t);	p[0] = IE_CALL_ID;	p[1] = l;	memcpy(p+2, callid, callid_len);}#endif#if 0static void dec_ie_call_id(unsigned char *p, Q931_info_t *qi, char *callid, int *callid_len, int nt, struct misdn_bchannel *bc){	char debug[25];	int i;	*callid_len = -1;	if (!nt)	{		p = NULL;		if (qi->QI_ELEMENT(call_id))			p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->QI_ELEMENT(call_id) + 1;	}	if (!p)		return;	if (p[0] > 8)	{		printf("%s: ERROR: IE too long (%d).\n", __FUNCTION__, p[0]);		return;	}	*callid_len = p[0];	memcpy(callid, p+1, *callid_len);	i = 0;	while(i < *callid_len)	{		if (MISDN_IE_DEBG) printf(debug+(i*3), " %02x", callid[i]);		i++;	}			if (MISDN_IE_DEBG) printf("    callid%s\n", debug);}#endif/* IE_CALLED_PN */static void enc_ie_called_pn(unsigned char **ntmode, msg_t *msg, int type, int plan, char *number, int nt, struct misdn_bchannel *bc){	unsigned char *p;	Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);	int l;	if (type<0 || type>7)	{		printf("%s: ERROR: type(%d) is out of range.\n", __FUNCTION__, type);		return;	}	if (plan<0 || plan>15)	{		printf("%s: ERROR: plan(%d) is out of range.\n", __FUNCTION__, plan);		return;	}	if (!number[0])	{		printf("%s: ERROR: number is not given.\n", __FUNCTION__);		return;	}	if (MISDN_IE_DEBG) printf("    type=%d plan=%d number='%s'\n", type, plan, number);	l = 1+strlen((char *)number);	p = msg_put(msg, l+2);	if (nt)		*ntmode = p+1;	else		qi->QI_ELEMENT(called_nr) = p - (unsigned char *)qi - sizeof(Q931_info_t);	p[0] = IE_CALLED_PN;	p[1] = l;	p[2] = 0x80 + (type<<4) + plan;	strncpy((char *)p+3, (char *)number, strlen((char *)number));}static void dec_ie_called_pn(unsigned char *p, Q931_info_t *qi, int *type, int *plan, char *number, int number_len, int nt, struct misdn_bchannel *bc){	*type = -1;	*plan = -1;	*number = '\0';	if (!nt)	{		p = NULL;		if (qi->QI_ELEMENT(called_nr))			p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->QI_ELEMENT(called_nr) + 1;	}	if (!p)		return;	if (p[0] < 2)	{		printf("%s: ERROR: IE too short (%d).\n", __FUNCTION__, p[0]);		return;	}	*type = (p[1]&0x70) >> 4;	*plan = p[1] & 0xf;	strnncpy(number, (char *)p+2, p[0]-1, number_len);	if (MISDN_IE_DEBG) printf("    type=%d plan=%d number='%s'\n", *type, *plan, number);}/* IE_CALLING_PN */static void enc_ie_calling_pn(unsigned char **ntmode, msg_t *msg, int type, int plan, int present, int screen, char *number, int nt, struct misdn_bchannel *bc){	unsigned char *p;	Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);	int l;	if (type<0 || type>7)	{		printf("%s: ERROR: type(%d) is out of range.\n", __FUNCTION__, type);		return;	}	if (plan<0 || plan>15)	{		printf("%s: ERROR: plan(%d) is out of range.\n", __FUNCTION__, plan);		return;	}	if (present>3)	{		printf("%s: ERROR: present(%d) is out of range.\n", __FUNCTION__, present);		return;	}	if (present >= 0) if (screen<0 || screen>3)	{		printf("%s: ERROR: screen(%d) is out of range.\n", __FUNCTION__, screen);		return;	}	if (MISDN_IE_DEBG) printf("    type=%d plan=%d present=%d screen=%d number='%s'\n", type, plan, present, screen, number);	l = 1;	if (number) if (number[0])		l += strlen((char *)number);	if (present >= 0)		l += 1;	p = msg_put(msg, l+2);	if (nt)		*ntmode = p+1;	else		qi->QI_ELEMENT(calling_nr) = p - (unsigned char *)qi - sizeof(Q931_info_t);	p[0] = IE_CALLING_PN;	p[1] = l;	if (present >= 0)	{		p[2] = 0x00 + (type<<4) + plan;		p[3] = 0x80 + (present<<5) + screen;		if (number) if (number[0])			strncpy((char *)p+4, (char *)number, strlen((char *)number));	} else	{		p[2] = 0x80 + (type<<4) + plan;		if (number) if (number[0])			strncpy((char *)p+3, (char *)number, strlen((char *)number));	}}static void dec_ie_calling_pn(unsigned char *p, Q931_info_t *qi, int *type, int *plan, int *present, int *screen, char *number, int number_len, int nt, struct misdn_bchannel *bc){	*type = -1;	*plan = -1;	*present = -1;	*screen = -1;	*number = '\0';	if (!nt)	{		p = NULL;		if (qi->QI_ELEMENT(calling_nr))			p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->QI_ELEMENT(calling_nr) + 1;	}	if (!p)

⌨️ 快捷键说明

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