[asterisk-commits] nadi: branch crichter/0.4.0 r39352 - in /team/crichter/0.4.0/channels: ./ misdn/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Aug 8 10:15:14 MST 2006


Author: nadi
Date: Tue Aug  8 12:15:13 2006
New Revision: 39352

URL: http://svn.digium.com/view/asterisk?rev=39352&view=rev
Log:
first bits of decoding facility information elements.

Modified:
    team/crichter/0.4.0/channels/chan_misdn.c
    team/crichter/0.4.0/channels/misdn/asn1.c
    team/crichter/0.4.0/channels/misdn/asn1.h
    team/crichter/0.4.0/channels/misdn/fac.c
    team/crichter/0.4.0/channels/misdn/fac.h
    team/crichter/0.4.0/channels/misdn/isdn_lib.c
    team/crichter/0.4.0/channels/misdn/isdn_msg_parser.c
    team/crichter/0.4.0/channels/misdn_config.c

Modified: team/crichter/0.4.0/channels/chan_misdn.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.4.0/channels/chan_misdn.c?rev=39352&r1=39351&r2=39352&view=diff
==============================================================================
--- team/crichter/0.4.0/channels/chan_misdn.c (original)
+++ team/crichter/0.4.0/channels/chan_misdn.c Tue Aug  8 12:15:13 2006
@@ -408,15 +408,15 @@
 {
 	switch (bc->fac_type) {
 	case FACILITY_CALLDEFLECT:
-		chan_misdn_log(2,bc->port," --> calldeflect: %s\n",
+		chan_misdn_log(0,bc->port," --> calldeflect: %s\n",
 			       bc->fac.calldeflect_nr);
 		break;
 	case FACILITY_CENTREX:
-		chan_misdn_log(2,bc->port," --> centrex: %s\n",
+		chan_misdn_log(0,bc->port," --> centrex: %s\n",
 			       bc->fac.cnip);
 		break;
 	default:
-		chan_misdn_log(2,bc->port," --> unknown\n");
+		chan_misdn_log(0,bc->port," --> unknown\n");
 		
 	}
 }
@@ -4470,6 +4470,8 @@
 			struct ast_channel *bridged=AST_BRIDGED_P(ch->ast);
 			struct chan_list *ch;
 			
+			misdn_lib_send_event(bc, EVENT_DISCONNECT);
+
 			if (bridged && MISDN_ASTERISK_TECH_PVT(bridged)) {
 				ch=MISDN_ASTERISK_TECH_PVT(bridged);
 				/*ch->state=MISDN_FACILITY_DEFLECTED;*/
@@ -4483,7 +4485,7 @@
 		
 		break;
 		default:
-			chan_misdn_log(1, bc->port," --> not yet handled: facility type:%p\n", bc->fac_type);
+			chan_misdn_log(0, bc->port," --> not yet handled: facility type:%p\n", bc->fac_type);
 		}
 		
 		break;

Modified: team/crichter/0.4.0/channels/misdn/asn1.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.4.0/channels/misdn/asn1.c?rev=39352&r1=39351&r2=39352&view=diff
==============================================================================
--- team/crichter/0.4.0/channels/misdn/asn1.c (original)
+++ team/crichter/0.4.0/channels/misdn/asn1.c Tue Aug  8 12:15:13 2006
@@ -1,6 +1,10 @@
 
 #include "asn1.h"
 #include <string.h>
+
+/*
+** ASN.1 Encoding
+*/
 
 int _enc_null (__u8 *dest, int tag)
 {
@@ -70,3 +74,108 @@
 	return 0;
 }
 
+/*
+** ASN.1 Decoding
+*/
+
+#define CHECK_P 						\
+	do { \
+		if (p >= end) \
+			return -1; \
+	} while (0) 
+
+#define CallASN1(ret, p, end, todo)		\
+	do { \
+		ret = todo; \
+		if (ret < 0) { \
+			return -1; \
+		} \
+		p += ret; \
+	} while (0)
+
+#define INIT 							\
+	int len, ret; \
+	__u8 *begin = p; \
+	if (tag) \
+		*tag = *p; \
+	p++; \
+	CallASN1(ret, p, end, dec_len(p, &len)); \
+	if (len >= 0) { \
+		if (p + len > end) \
+			return -1; \
+		end = p + len; \
+	}
+
+int _dec_null (__u8 *p, __u8 *end, int *tag)
+{
+	INIT;
+	return p - begin;
+}
+
+int _dec_bool (__u8 *p, __u8 *end, int *i, int *tag)
+{
+	INIT;
+	*i = 0;
+	while (len--) {
+		CHECK_P;
+		*i = (*i >> 8) + *p;
+		p++;
+	}
+	return p - begin;
+}
+
+int _dec_int (__u8 *p, __u8 *end, int *i, int *tag)
+{
+	INIT;
+
+	*i = 0;
+	while (len--) {
+		CHECK_P;
+		*i = (*i << 8) + *p;
+		p++;
+	}
+	return p - begin;
+}
+
+int _dec_enum (__u8 *p, __u8 *end, int *i, int *tag)
+{
+	INIT;
+
+	*i = 0;
+	while (len--) {
+		CHECK_P;
+		*i = (*i << 8) + *p;
+		p++;
+	}
+	return p - begin;
+}
+
+int _dec_num_string (__u8 *p, __u8 *end, char *str, int *tag)
+{
+	INIT;
+
+	while (len--) {
+		CHECK_P;
+		*str++ = *p;
+		p++;
+	}
+	*str = 0;
+	return p - begin;
+}
+
+int _dec_octet_string (__u8 *p, __u8 *end, char *str, int *tag)
+{
+	return _dec_num_string(p, end, str, tag);
+}
+
+int _dec_sequence (__u8 *p, __u8 *end, int *tag)
+{
+	INIT;
+	return p - begin;
+}
+
+int dec_len (__u8 *p, int *len)
+{
+	*len = *p;
+	return 1;
+}

Modified: team/crichter/0.4.0/channels/misdn/asn1.h
URL: http://svn.digium.com/view/asterisk/team/crichter/0.4.0/channels/misdn/asn1.h?rev=39352&r1=39351&r2=39352&view=diff
==============================================================================
--- team/crichter/0.4.0/channels/misdn/asn1.h (original)
+++ team/crichter/0.4.0/channels/misdn/asn1.h Tue Aug  8 12:15:13 2006
@@ -2,6 +2,10 @@
 #define __ASN1_H__
 
 #include <asm/types.h>
+
+/*
+** ASN.1 Tags
+*/
 
 #define ASN1_TAG_BOOLEAN           (0x01)
 #define ASN1_TAG_INTEGER           (0x02)
@@ -22,6 +26,10 @@
 #define ASN1_TAG_OPT               (0x200)
 #define ASN1_NOT_TAGGED            (0x400)
 
+/*
+** ASN.1 Encoding
+*/
+
 #define enc_null(dest) _enc_null(dest,ASN1_TAG_NULL)
 #define enc_bool(dest,i) _enc_bool(dest,i,ASN1_TAG_BOOLEAN)
 #define enc_int(dest,i) _enc_int(dest,i,ASN1_TAG_INTEGER)
@@ -38,5 +46,27 @@
 int _enc_sequence_start (__u8 *dest, __u8 **id, int tag);
 int _enc_sequence_end (__u8 *dest, __u8 *id, int tag_dummy);
 
+/*
+** ASN.1 Decoding
+*/
+
+#define dec_null(p, end) _dec_null (p, end, NULL);
+#define dec_bool(p, end,i) _dec_bool (p, end, i, NULL)
+#define dec_int(p, end,i) _dec_int (p, end, i, NULL)
+#define dec_enum(p, end,i) _dec_enum (p, end, i, NULL)
+#define dec_num_string(p, end,str) _dec_num_string (p, end, str, NULL)
+#define dec_octet_string(p, end,str) _dec_octet_string (p, end, str, NULL)
+#define dec_sequence(p, end) _dec_sequence (p, end, NULL)
+
+int _dec_null (__u8 *p, __u8 *end, int *tag);
+int _dec_bool (__u8 *p, __u8 *end, int *i, int *tag);
+int _dec_int (__u8 *p, __u8 *end, int *i, int *tag);
+int _dec_enum (__u8 *p, __u8 *end, int *i, int *tag);
+int _dec_num_string (__u8 *p, __u8 *end, char *str, int *tag);
+int _dec_octet_string (__u8 *p, __u8 *end, char *str, int *tag);
+int _dec_sequence (__u8 *p, __u8 *end, int *tag);
+
+int dec_len (__u8 *p, int *len);
+
 #endif
 

Modified: team/crichter/0.4.0/channels/misdn/fac.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.4.0/channels/misdn/fac.c?rev=39352&r1=39351&r2=39352&view=diff
==============================================================================
--- team/crichter/0.4.0/channels/misdn/fac.c (original)
+++ team/crichter/0.4.0/channels/misdn/fac.c Tue Aug  8 12:15:13 2006
@@ -69,6 +69,7 @@
 
 	/* not from document */
 	CALL_DEFLECT 			= 0x0d,
+	AOC 					= 0x22,
 } OPERATION_CODE;
 
 enum {
@@ -77,13 +78,13 @@
 
 #ifdef FACILITY_DEBUG
 #define FAC_DUMP(fac,len,bc) fac_dump(fac,len,bc)
-static void fac_dump (unsigned char *facility, unsigned int fac_len, struct misdn_bchannel *bc)
+#include <ctype.h>
+static void fac_dump (__u8 *facility, unsigned int fac_len, struct misdn_bchannel *bc)
 {
 	int i;
-	cb_log(0, bc->port, "    --- facility dump start\n");
+	cb_log(0, bc->port, "    --- facility dump start. length:%d\n", fac_len);
 	for (i = 0; i < fac_len; ++i)
-		if ((facility[i] >= 'a' && facility[i] <= 'z') || (facility[i] >= 'A' && facility[i] <= 'Z') ||
-			(facility[i] >= '0' && facility[i] <= '9'))
+		if (isprint(facility[i]))
 			cb_log(0, bc->port, "    --- %d: %04p (char:%c)\n", i, facility[i], facility[i]);
 		else
 			cb_log(0, bc->port, "    --- %d: %04p\n", i, facility[i]);
@@ -92,6 +93,10 @@
 #else
 #define FAC_DUMP(fac,len,bc)
 #endif
+
+/*
+** Facility Encoding
+*/
 
 static int enc_fac_calldeflect (__u8 *dest, char *number, int pres)
 {
@@ -118,7 +123,7 @@
 	return p - dest;
 }
 
-static void enc_ie_facility (unsigned char **ntmode, msg_t *msg, unsigned char *facility, int facility_len, struct misdn_bchannel *bc)
+static void enc_ie_facility (__u8 **ntmode, msg_t *msg, __u8 *facility, int facility_len, struct misdn_bchannel *bc)
 {
 	__u8 *ie_fac;
 	
@@ -129,7 +134,7 @@
 		*ntmode = ie_fac + 1;
 	} else {
 		qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
-		qi->QI_ELEMENT(facility) = ie_fac - (unsigned char *)qi - sizeof(Q931_info_t);
+		qi->QI_ELEMENT(facility) = ie_fac - (__u8 *)qi - sizeof(Q931_info_t);
 	}
 
 	ie_fac[0] = IE_FACILITY;
@@ -139,7 +144,7 @@
 	FAC_DUMP(ie_fac, facility_len + 2, bc);
 }
 
-void fac_enc (unsigned char **ntmsg, msg_t * msg, enum facility_type type,  union facility fac, struct misdn_bchannel *bc)
+void fac_enc (__u8 **ntmsg, msg_t *msg, enum facility_type type,  union facility fac, struct misdn_bchannel *bc)
 {
 	__u8 facility[256];
 	int len;
@@ -155,5 +160,108 @@
 	}
 }
 
-void fac_dec (unsigned char *p, Q931_info_t *qi, enum facility_type *type,  union facility *fac, struct misdn_bchannel *bc)
-{}
+/*
+** Facility Decoding
+*/
+
+static int dec_fac_calldeflect (__u8 *p, int len, struct misdn_bchannel *bc)
+{
+	__u8 *end = p + len;
+	int offset,
+		pres;
+
+	if ((offset = dec_sequence(p, end)) < 0)
+		return -1;
+	p += offset;
+
+	if ((offset = dec_sequence(p, end)) < 0)
+		return -1;
+	p += offset;
+	
+	if ((offset = dec_num_string(p, end, bc->fac.calldeflect_nr)) < 0)
+		return -1;
+	p += offset;
+
+	if ((offset = dec_bool(p, end, &pres)) < 0)
+		return -1;
+
+	cb_log(0, 0, "CALLDEFLECT: dest:%s pres:%s (not implemented yet)\n", bc->fac.calldeflect_nr, pres ? "yes" : "no");
+	bc->fac_type = FACILITY_CALLDEFLECT;
+
+	return 0;
+}
+
+void fac_dec (__u8 *p, Q931_info_t *qi, enum facility_type *type,  union facility *fac, struct misdn_bchannel *bc)
+{
+	int len,
+		offset,
+		inner_len,
+		invoke_id,
+		op_tag,
+		op_val;
+	__u8 *end,
+				  *begin = p;
+
+	if (!bc->nt) {
+		if (qi->QI_ELEMENT(facility))
+			p = (__u8 *)qi + sizeof(Q931_info_t) + qi->QI_ELEMENT(facility) + 1;
+		else
+			p = NULL;
+	}
+	if (!p)
+		return;
+
+	offset = dec_len (p, &len);
+	if (offset < 0) {
+		cb_log(0, bc->port, "Could not decode FACILITY: dec_len failed!\n");
+		return;
+	}
+	p += offset;
+	end = p + len;
+
+	FAC_DUMP(p, len, bc);
+
+	if (len < 3 || p[0] != SUPPLEMENTARY_SERVICE || p[1] != INVOKE) {
+		cb_log(0, bc->port, "Could not decode FACILITY: invalid or not supported!\n");
+		return;
+	}
+	p += 2;
+
+	offset = dec_len (p, &inner_len);
+	if (offset < 0) {
+		cb_log(0, bc->port, "Could not decode FACILITY: failed parsing inner length!\n");
+		return;
+	}
+	p += offset;
+
+	offset = dec_int (p, end, &invoke_id);
+	if (offset < 0) {
+		cb_log(0, bc->port, "Could not decode FACILITY: failed parsing invoke identifier!\n");
+		return;
+	}
+	p += offset;
+
+	offset = _dec_int (p, end, &op_val, &op_tag);
+	if (offset < 0) {
+		cb_log(0, bc->port, "Could not decode FACILITY: failed parsing operation value!\n");
+		return;
+	}
+	p += offset;
+
+	if (op_tag != OPERATION_VALUE || offset != 3) {
+		cb_log(0, bc->port, "Could not decode FACILITY: operation value tag 0x%x unknown!\n", op_tag);
+		return;
+	}
+
+	switch (op_val) {
+	case CALL_DEFLECT:
+		cb_log(0, bc->port, "FACILITY: Call Deflect\n");
+		dec_fac_calldeflect(p, len - (p - begin) + 1, bc);
+		break;
+	case AOC:
+		cb_log(0, bc->port, "FACILITY: AOC\n");
+		break;
+	default:
+		cb_log(0, bc->port, "FACILITY unknown: operation value 0x%x, ignoring ...\n", op_val);
+	}
+}

Modified: team/crichter/0.4.0/channels/misdn/fac.h
URL: http://svn.digium.com/view/asterisk/team/crichter/0.4.0/channels/misdn/fac.h?rev=39352&r1=39351&r2=39352&view=diff
==============================================================================
--- team/crichter/0.4.0/channels/misdn/fac.h (original)
+++ team/crichter/0.4.0/channels/misdn/fac.h Tue Aug  8 12:15:13 2006
@@ -3,8 +3,8 @@
 
 #include "isdn_lib_intern.h"
 
-void fac_enc (unsigned char **ntmsg, msg_t *msg, enum facility_type type, union facility fac, struct misdn_bchannel *bc);
-void fac_dec (unsigned char *p, Q931_info_t *qi, enum facility_type *type, union facility *fac, struct misdn_bchannel *bc);
+void fac_enc (__u8 **ntmsg, msg_t *msg, enum facility_type type, union facility fac, struct misdn_bchannel *bc);
+void fac_dec (__u8 *p, Q931_info_t *qi, enum facility_type *type, union facility *fac, struct misdn_bchannel *bc);
 
 #endif
 

Modified: team/crichter/0.4.0/channels/misdn/isdn_lib.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.4.0/channels/misdn/isdn_lib.c?rev=39352&r1=39351&r2=39352&view=diff
==============================================================================
--- team/crichter/0.4.0/channels/misdn/isdn_lib.c (original)
+++ team/crichter/0.4.0/channels/misdn/isdn_lib.c Tue Aug  8 12:15:13 2006
@@ -2579,6 +2579,7 @@
     
 		bc=find_bc_by_l3id(stack, frm->dinfo);
     
+handle_frm_bc:
 		if (bc ) {
 			enum event_e event = isdn_msg_get_event(msgs_g, msg, 0);
 			enum event_response_e response=RESPONSE_OK;
@@ -2592,7 +2593,7 @@
       
 			if(!isdn_get_info(msgs_g,event,0)) 
 				cb_log(0, stack->port, "Unknown Event Ind: Addr:%x prim %x dinfo %x\n",frm->addr, frm->prim, frm->dinfo);
-			else 
+			else
 				response=cb_event(event, bc, glob_mgr->user_data);
 #if 1
 			if (event == EVENT_SETUP) {
@@ -2634,7 +2635,13 @@
 #endif
       
 		} else {
-			cb_log(0, stack->port, "NO BC FOR STACK\n");		
+			cb_log(0, stack->port, " --> Didn't find BC so temporarly creating dummy BC (l3id:%x) on this port.\n", frm->dinfo);
+			struct misdn_bchannel dummybc;
+			memset (&dummybc,0,sizeof(dummybc));
+			dummybc.port=stack->port;
+			dummybc.l3_id=frm->dinfo;
+			bc=&dummybc; 
+			goto handle_frm_bc;
 		}
 	}
 

Modified: team/crichter/0.4.0/channels/misdn/isdn_msg_parser.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.4.0/channels/misdn/isdn_msg_parser.c?rev=39352&r1=39351&r2=39352&view=diff
==============================================================================
--- team/crichter/0.4.0/channels/misdn/isdn_msg_parser.c (original)
+++ team/crichter/0.4.0/channels/misdn/isdn_msg_parser.c Tue Aug  8 12:15:13 2006
@@ -879,21 +879,15 @@
 
 void parse_facility (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt) 
 {
-//#define FACILITY_DECODE
 #ifdef FACILITY_DEBUG
 	int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
 	FACILITY_t *facility=(FACILITY_t*)((unsigned long)(msg->data+HEADER_LEN)); 
 	Q931_info_t *qi=(Q931_info_t*)(msg->data+HEADER_LEN);  
-
 #if DEBUG 
 	printf("Parsing FACILITY Msg\n"); 
 #endif
-
-	{
-		fac_dec(facility->FACILITY, qi, &bc->fac_type, &bc->fac, bc);
-	}
+	fac_dec(facility->FACILITY, qi, &bc->fac_type, &bc->fac, bc);
 #endif	
-
 }
 
 msg_t *build_facility (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt) 

Modified: team/crichter/0.4.0/channels/misdn_config.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.4.0/channels/misdn_config.c?rev=39352&r1=39351&r2=39352&view=diff
==============================================================================
--- team/crichter/0.4.0/channels/misdn_config.c (original)
+++ team/crichter/0.4.0/channels/misdn_config.c Tue Aug  8 12:15:13 2006
@@ -108,7 +108,7 @@
 		"\tas well, since chan_misdn has no chance to distinguish if the L1 is down\n"
 		"\tbecause of a lost Link or because the Provider shut it down..." },
 	{ "block_on_alarm", MISDN_CFG_ALARM_BLOCK, MISDN_CTYPE_BOOL, "yes", NONE,
-		"If the port should be blocked, whenever an Alarm comes up\n"},
+		"If the port should be blocked, whenever an Alarm comes up."},
 	{ "hdlc", MISDN_CFG_HDLC, MISDN_CTYPE_BOOL, "no", NONE,
 		"Set this to yes, if you want to bridge a mISDN data channel to\n"
 		"\tanother channel type or to an application." },



More information about the asterisk-commits mailing list