[asterisk-commits] branch crichter/0.3.0 - r7381 in /team/crichter/0.3.0/channels: ./ misdn/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Dec 7 14:09:37 CST 2005


Author: crichter
Date: Wed Dec  7 14:09:32 2005
New Revision: 7381

URL: http://svn.digium.com/view/asterisk?rev=7381&view=rev
Log:
added facility parser/encoder and misdn-init script

Added:
    team/crichter/0.3.0/channels/misdn/README.misdn-init
    team/crichter/0.3.0/channels/misdn/fac.c
    team/crichter/0.3.0/channels/misdn/fac.h
    team/crichter/0.3.0/channels/misdn/misdn-init   (with props)
Modified:
    team/crichter/0.3.0/channels/chan_misdn.c

Modified: team/crichter/0.3.0/channels/chan_misdn.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.3.0/channels/chan_misdn.c?rev=7381&r1=7380&r2=7381&view=diff
==============================================================================
--- team/crichter/0.3.0/channels/chan_misdn.c (original)
+++ team/crichter/0.3.0/channels/chan_misdn.c Wed Dec  7 14:09:32 2005
@@ -59,8 +59,6 @@
 #include <asterisk/app.h>
 #include <asterisk/features.h>
 
-#include "misdn/jitterbuffer.h"
-
 #include "chan_misdn_config.h"
 #include "isdn_lib.h"
 
@@ -72,6 +70,36 @@
 
 
 char global_tracefile[BUFFERSIZE];
+
+
+struct misdn_jb{
+	int size;
+	int upper_threshold;
+	char *samples, *ok;
+	int wp,rp;
+	int state_empty;
+	int state_full;
+	int state_buffer;
+	int bytes_wrote;
+	ast_mutex_t mutexjb;
+};
+
+/* allocates the jb-structure and initialise the elements*/
+struct misdn_jb *misdn_jb_init(int size, int upper_threshold);
+
+/* frees the data and destroys the given jitterbuffer struct */
+void misdn_jb_destroy(struct misdn_jb *jb);
+
+/* fills the jitterbuffer with len data returns < 0 if there was an
+error (bufferoverun). */
+int misdn_jb_fill(struct misdn_jb *jb, const char *data, int len);
+
+/* gets len bytes out of the jitterbuffer if available, else only the
+available data is returned and the return value indicates the number
+of data. */
+int misdn_jb_empty(struct misdn_jb *jb, char *data, int len);
+
+
 
 /* BEGIN: chan_misdn.h */
 

Added: team/crichter/0.3.0/channels/misdn/README.misdn-init
URL: http://svn.digium.com/view/asterisk/team/crichter/0.3.0/channels/misdn/README.misdn-init?rev=7381&view=auto
==============================================================================
--- team/crichter/0.3.0/channels/misdn/README.misdn-init (added)
+++ team/crichter/0.3.0/channels/misdn/README.misdn-init Wed Dec  7 14:09:32 2005
@@ -1,0 +1,54 @@
+misdn-init: init-script to auto-configure and load the mISDN kernel drivers
+===========================================================================
+
+This script makes it easy to configure and activate mISDN compatible 
+adapter cards. It scans an eyecandy config file named misdn-init.conf
+for your card and port settings, then it loads the driver modules properly.
+The misdn-init.conf can also be autogenerated by the misdn-init script.
+
+---------------------------------------------------------------------------
+Usage: /etc/init.d/misdn-init start|stop|restart|config|scan|help
+
+  --start      scan /etc/misdn-init.conf and load the mISDN drivers
+  --stop       unload the mISDN drivers
+  --restart    see stop, then start
+  --config     scan your PCI bus for mISDN compatible hardware and generate
+               a /etc/misdn-init.conf
+  --scan       scan your PCI bus for mISDN compatible hardware and print
+               the results to the console
+  --help       print the usage info
+---------------------------------------------------------------------------
+
+
+* Here is a quick overview on how to use misdn-init:
+
+1) Get and install misdn-init:
+   $ wget http://www.beronet.com/downloads/chan_misdn/stable/chan_misdn.tar.gz
+   $ tar zxf chan_misdn.tar.gz
+   $ (as root) cp chan_misdn/misdn-init /etc/init.d/misdn-init
+   
+2) Let misdn-init scan your PCI bus for mISDN compatible hardware and write
+   the results into /etc/misdn-init.conf:
+   $ (as root) /etc/init.d/misdn-init config
+ 
+3) (optional) Edit /etc/misdn-init.conf and set everything the way you want it.
+   This file is heavily commented, hence it should be self-explaining.
+
+4) (optional, but recommended) Add misdn-init to your run level.
+   This is distribution dependend. Here an example for a debian system:
+   ATTENTION: If you have services in your runlevels that depend
+              on mISDN, make sure that misdn-init starts before, and
+              stops after them (this is done by changing the values
+              that are set to 60 in this example, more info: read the 
+              manpage for update-rc.d).
+   $ (as root) update-rc.d misdn-init start 60 2 3 4 5 . stop 60 0 1 6 .
+
+5) Run the following to start mISDN:
+   $ (as root) /etc/init.d/misdn-init start
+
+
+
+---------------------------------------------------------------------------
+* Report Bugs:
+If you experience any bugs or have a feature request, please drop a us mail:
+bugs at beronet.com

Added: team/crichter/0.3.0/channels/misdn/fac.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.3.0/channels/misdn/fac.c?rev=7381&view=auto
==============================================================================
--- team/crichter/0.3.0/channels/misdn/fac.c (added)
+++ team/crichter/0.3.0/channels/misdn/fac.c Wed Dec  7 14:09:32 2005
@@ -1,0 +1,313 @@
+
+#include "isdn_lib_intern.h"
+#include "isdn_lib.h"
+
+#include "string.h"
+
+
+
+
+#define CENTREX_ID      0xa1
+#define CALLDEFLECT_ID      0xa1
+
+/**
+   This file covers the encoding and decoding of facility messages and
+   facility information elements.
+
+   There will be 2 Functions as Interface:
+   
+   fac_enc( char **ntmsg, msg_t * msg, enum facility_type type,  union facility fac, struct misdn_bchannel *bc)
+   fac_dec( unsigned char *p, Q931_info_t *qi, enum facility_type *type,  union facility *fac, struct misdn_bchannel *bc);
+
+   Those will either read the union facility or fill it.
+
+   internally, we will have deconding and encoding functions for each facility
+   IE.
+   
+**/
+
+
+/* support stuff */
+static void strnncpy(unsigned char *dest, unsigned 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';
+}
+
+
+
+
+/**********************/
+/*** FACILITY STUFF ***/
+/**********************/
+
+
+/* IE_FACILITY */
+void enc_ie_facility(unsigned char **ntmode, msg_t *msg, unsigned char *facility, int facility_len, int nt, struct misdn_bchannel *bc)
+{
+	unsigned char *p;
+	Q931_info_t *qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
+	int l;
+
+
+	if (!facility || facility_len<=0)
+	{
+		return;
+	}
+
+	
+	l = facility_len;
+	p = msg_put(msg, l+2);
+	if (nt)
+		*ntmode = p+1;
+	else
+		qi->QI_ELEMENT(facility) = p - (unsigned char *)qi - sizeof(Q931_info_t);
+	p[0] = IE_FACILITY;
+	p[1] = l;
+	memcpy(p+2, facility, facility_len);
+}
+
+
+/* facility for siemens CENTEX (known parts implemented only) */
+void enc_ie_facility_centrex(unsigned char **ntmode, msg_t *msg, unsigned char *cnip, int setup, int nt, struct misdn_bchannel *bc)
+{
+	unsigned char centrex[256];
+	int i = 0;
+
+	if (!cnip)
+		return;
+
+	/* centrex facility */
+	centrex[i++] = FACILITY_CENTREX;
+	centrex[i++] = CENTREX_ID;
+
+	/* cnip */
+	if (strlen((char *)cnip) > 15)
+	{
+/* 		if (options.deb & DEBUG_PORT) */
+		cb_log(1,0,"%s: CNIP/CONP text too long (max 13 chars), cutting.\n", __FUNCTION__);
+		cnip[15] = '\0';
+	}
+	/*  dunno what the 8 bytes mean */
+	if (setup)
+	{
+		centrex[i++] = 0x17;
+		centrex[i++] = 0x02;
+		centrex[i++] = 0x02;
+		centrex[i++] = 0x44;
+		centrex[i++] = 0x18;
+		centrex[i++] = 0x02;
+		centrex[i++] = 0x01;
+		centrex[i++] = 0x09;
+	} else
+	{
+		centrex[i++] = 0x18;
+		centrex[i++] = 0x02;
+		centrex[i++] = 0x02;
+		centrex[i++] = 0x81;
+		centrex[i++] = 0x09;
+		centrex[i++] = 0x02;
+		centrex[i++] = 0x01;
+		centrex[i++] = 0x0a;
+	}
+
+	centrex[i++] = 0x80;
+	centrex[i++] = strlen((char *)cnip);
+	strcpy((char *)(&centrex[i]), (char *)cnip);
+	i += strlen((char *)cnip);
+	cb_log(4,0,"    cnip='%s'\n", cnip);
+
+	/* encode facility */
+	enc_ie_facility(ntmode, msg, centrex, i, nt , bc);
+}
+
+void dec_ie_facility_centrex(unsigned char *p, Q931_info_t *qi, unsigned char *centrex, int facility_len, unsigned char *cnip, int cnip_len, int nt, struct misdn_bchannel *bc)
+{
+
+	int i = 0;
+	*cnip = '\0';
+	
+	if (facility_len >= 2)
+	{
+		if (centrex[i++] != FACILITY_CENTREX)
+			return;
+		if (centrex[i++] != CENTREX_ID)
+			return;
+	}
+
+	/* loop sub IEs of facility */
+	while(facility_len > i+1)
+	{
+		if (centrex[i+1]+i+1 > facility_len)
+		{
+			printf("%s: ERROR: short read of centrex facility.\n", __FUNCTION__);
+			return;
+		}
+		switch(centrex[i])
+		{
+		case 0x80:
+			strnncpy(cnip, &centrex[i+2], centrex[i+1], cnip_len);
+			cb_log(4,0,"    CENTREX cnip='%s'\n", cnip);
+			break;
+		}
+		i += 1+centrex[i+1];
+	}
+}
+
+
+
+
+/* facility for CALL Deflect (known parts implemented only) */
+void enc_ie_facility_calldeflect(unsigned char **ntmode, msg_t *msg, unsigned char *nr, int nt, struct misdn_bchannel *bc)
+{
+	unsigned char fac[256];
+	
+	if (!nr)
+		return;
+
+	int len = strlen(nr);
+	/* calldeflect facility */
+	
+	/* cnip */
+	if (strlen((char *)nr) > 15)
+	{
+/* 		if (options.deb & DEBUG_PORT) */
+		cb_log(1,0,"%s: NR text too long (max 13 chars), cutting.\n", __FUNCTION__);
+		nr[15] = '\0';
+	}
+	
+	fac[0]=FACILITY_CALLDEFLECT;	// ..
+	fac[1]=CALLDEFLECT_ID;
+	fac[2]=0x0f + len;	// strlen destination + 15 = 26
+	fac[3]=0x02;
+	fac[4]=0x01;
+	//fac[5]=0x70;
+	fac[5]=0x09;
+	fac[6]=0x02;
+	fac[7]=0x01;
+	fac[8]=0x0d;
+	fac[9]=0x30;
+	fac[10]=0x07 + len;	// strlen destination + 7 = 18
+	fac[11]=0x30;	// ...hm 0x30
+	fac[12]=0x02+ len;	// strlen destination + 2	
+	fac[13]=0x80;	// CLIP
+	fac[14]= len;	//  strlen destination 
+	
+	memcpy((unsigned char *)fac+15,nr,len);
+	fac[15+len]=0x01; //sending complete
+	fac[16+len]=0x01;
+	fac[17+len]=0x80;
+	
+	enc_ie_facility(ntmode, msg, fac, 17+len +1 , nt , bc);
+}
+
+
+void dec_ie_facility_calldeflect(unsigned char *p, Q931_info_t *qi, unsigned char *fac, int fac_len, unsigned char *cd_nr,  int nt, struct misdn_bchannel *bc)
+{
+	*cd_nr = '\0';
+	
+	if (fac_len >= 15)
+	{
+		if (fac[0] != FACILITY_CALLDEFLECT)
+			return;
+		if (fac[1] != CALLDEFLECT_ID)
+			return;
+	} else {
+		cb_log(1,bc->port, "IE too short: FAC_CALLDEFLECT\n");
+		return ;
+	}
+	
+	
+	
+	{
+		int dest_len=fac[2]-0x0f;
+		
+		if (dest_len <0 || dest_len > 15) {
+			cb_log(1,bc->port, "IE is garbage: FAC_CALLDEFLECT\n");
+			return ;
+		}
+		
+		if (fac_len < 15+dest_len) {
+			cb_log(1,bc->port, "IE too short: FAC_CALLDEFLECT\n");
+			return ;
+		}
+		
+		memcpy(cd_nr, &fac[15],dest_len);
+		cd_nr[dest_len]=0;
+		
+		cb_log(5,bc->port, "--> IE CALLDEFLECT NR: %s\n",cd_nr);
+	}
+}
+
+
+
+void fac_enc( unsigned char **ntmsg, msg_t * msg, enum facility_type type,  union facility fac, struct misdn_bchannel *bc)
+{
+	switch (type) {
+	case FACILITY_CENTREX:
+	{
+		int setup=0;
+		enc_ie_facility_centrex(ntmsg, msg, fac.cnip, setup, bc->nt, bc);
+	}
+		break;
+	case FACILITY_CALLDEFLECT:
+		enc_ie_facility_calldeflect(ntmsg, msg, fac.calldeflect_nr, bc->nt, bc);
+		break;
+	default:
+		cb_log(1,0,"Don't know how handle this facility: %d\n", type);
+	}
+}
+
+void fac_dec( unsigned char *p, Q931_info_t *qi, enum facility_type *type,  union facility *fac, struct misdn_bchannel *bc)
+{
+	int i, fac_len=0;
+	unsigned char facility[256];
+	
+	if (! (bc->nt) )
+	{
+		p = NULL;
+		if (qi->QI_ELEMENT(facility))
+			p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->QI_ELEMENT(facility) + 1;
+	}
+	if (!p)
+		return;
+	
+	fac_len = p[0];
+	memcpy(facility, p+1, fac_len);
+	
+	
+	switch(facility[0]) {
+	case FACILITY_CENTREX:
+	{
+		int cnip_len=15;
+		
+		dec_ie_facility_centrex(p, qi,facility, fac_len, fac->cnip, cnip_len, bc->nt, bc);
+		
+		*type=FACILITY_CENTREX;
+	}
+	break;
+	case FACILITY_CALLDEFLECT:
+		dec_ie_facility_calldeflect(p, qi,facility, fac_len, fac->calldeflect_nr,  bc->nt, bc);
+		
+		*type=FACILITY_CALLDEFLECT;
+		break;
+	default:
+		cb_log(3, bc->port, "Unknown Facility received: ");
+		i = 0;
+		while(i < fac_len)
+		{
+			cb_log(3, bc->port, " %02x", facility[i]);
+			i++;
+		}
+		cb_log(3, bc->port, "    facility\n");
+		
+		*type=FACILITY_NONE;
+	}
+	
+	
+}
+
+/*** FACILITY END **/
+

Added: team/crichter/0.3.0/channels/misdn/fac.h
URL: http://svn.digium.com/view/asterisk/team/crichter/0.3.0/channels/misdn/fac.h?rev=7381&view=auto
==============================================================================
--- team/crichter/0.3.0/channels/misdn/fac.h (added)
+++ team/crichter/0.3.0/channels/misdn/fac.h Wed Dec  7 14:09:32 2005
@@ -1,0 +1,8 @@
+#ifndef FAC_H
+#define FAC_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);
+
+#endif

Added: team/crichter/0.3.0/channels/misdn/misdn-init
URL: http://svn.digium.com/view/asterisk/team/crichter/0.3.0/channels/misdn/misdn-init?rev=7381&view=auto
==============================================================================
--- team/crichter/0.3.0/channels/misdn/misdn-init (added)
+++ team/crichter/0.3.0/channels/misdn/misdn-init Wed Dec  7 14:09:32 2005
@@ -1,0 +1,527 @@
+#!/bin/bash
+
+################################################################################
+#
+# misdn-init init script
+#
+# Copyright (C) 2005, Nadi Sarrar
+#
+# Nadi Sarrar <nadi at beronet.com>
+#
+# This program is free software, distributed under the terms of
+# the GNU General Public License
+#
+
+#
+# USAGE:
+#
+#   /etc/init.d/misdn-init start|stop|restart|config|scan|help
+#
+
+#
+# CONFIGURATION:
+#
+# Path to your misdn-init.conf:
+#
+misdn_init_conf="/etc/misdn-init.conf"
+#
+################################################################################
+
+
+MODPROBE=modprobe
+RMMOD=rmmod
+INSMOD=insmod
+LSPCI=lspci
+MKNOD=mknod
+
+# HFC 8/4 (S0) Options
+master_clock=16
+
+# HFC-E1 Options
+optical=16
+los=18
+ais=19
+slip=20
+
+# Card Settings
+ulaw=8
+dtmf=9
+pcm_slave=11
+
+
+function expand_port_line {
+	expval=""
+	result=""
+	IFS=$','
+	for str in ${1};
+	do
+		if [ "$(echo "${str}" | grep "-")" != "" ]; then
+			from="$(echo ${str} | sed -e 's/^\([0-9]\+\)-[0-9]\+$/\1/')"
+			to="$(echo ${str} | sed -e 's/^[0-9]\+-\([0-9]\+\)$/\1/')"
+			while [ "${from}" -le "${to}" ]; do
+				result="${result}${from},"
+				let "from = ${from} + 1"
+			done
+		else
+			result="${result}${str},"
+		fi
+	done
+	IFS=$'\n'
+	expval="$(echo ${result} | sed -e 's/^\(.*\),$/\1/')"
+}
+
+function load_card_modules {
+
+	IFS=$'\n'
+
+	for line in $(sed -n -e '/^[^#]/p' ${misdn_init_conf});
+	do
+		var=`echo "${line}" | sed -e "s/^\(.*\)=.*/\1/"`
+		val=`echo "${line}" | sed -e "s/^.*=\(.*\)/\1/"`
+		
+		case "${var}" in
+			card)
+				nr=`echo "${val}" | sed -e "s/^\([0-9]*\),.*/\1/"`
+				mod=`echo "${val}" | sed -e "s/^[^,]*,\([^,]*\).*/\1/"`
+				if [ ${#val} -gt $(echo "obase=10;${#nr}+${#mod}+1" | bc) ]; then
+					opns=`echo "${val}" | sed -e "s/^[^,]*,[^,]*,\(.*\)/\1/"`
+				else
+					opns=""
+				fi
+				case "${mod}" in
+					0x*)
+						hfcmulti[${nr}]=$(echo ${mod} | sed -e "s/^0x\([0-9]*\)/\1/")
+						let "hfcports = ${hfcports} + ${hfcmulti[${nr}]}"
+						IFS=$','
+						for li in ${opns}; do
+							hfcmulti[${nr}]=$(echo "obase=10;2^(${!li}-1)+${hfcmulti[${nr}]}" | bc)
+						done
+						IFS=$'\n'
+						;;
+					*)
+						other_card[${nr}]=${mod}
+						;;
+				esac
+				;;
+			te_ptp)
+				expand_port_line "${val}"
+				IFS=$','
+				for li in ${expval}; do
+					layermask[${li}]="0xf"
+					protocol[${li}]=34 # 0x22 == 34
+				done
+				IFS=$'\n'
+				;;
+			te_ptmp)
+				expand_port_line "${val}"
+				IFS=$','
+				for li in ${expval}; do
+					layermask[${li}]="0xf"
+					protocol[${li}]=2 # 0x2 == 2
+				done
+				IFS=$'\n'
+				;;
+			nt_*)
+				expand_port_line "${val}"
+				IFS=$','
+				for li in ${expval}; do
+					layermask[${li}]="0x3"
+					protocol[${li}]=18 # 0x12 == 18
+				done
+				IFS=$'\n'
+				;;
+			option)
+				port=`echo "${val}" | sed -e "s/^\([0-9]*\),.*/\1/"`
+				opt=`echo "${val}" | sed -e "s/^[0-9]*,\(.*\)/\1/"`
+
+				if [ -z ${protocol[${port}]} ]; then
+					protocol[${port}]="0"
+				fi
+				
+				IFS=$','
+				for li in ${opt}; do
+					protocol[${port}]=$(echo "obase=10;2^(${!li}-1)+${protocol[${port}]}" | bc)
+				done
+				IFS=$'\n'
+				;;
+			poll)
+				poll=${val}
+				;;
+			pcm)
+				pcm=${val}
+				;;
+			debug)
+				debug=${val}
+				;;
+			*)
+				echo "unknown variable: ${var}"
+				;;
+		esac
+		
+	done
+
+	echo "-----------------------------------------"
+	echo " Loading module(s) for your misdn-cards:"
+	echo "-----------------------------------------"
+
+	card_index=1
+	port_index=1
+	while [ ! -z ${hfcmulti[${card_index}]} ] || [ ! -z ${other_card[${card_index}]} ];
+	do
+		if [ ! -z ${hfcmulti[${card_index}]} ]; then
+	# MODPROBE COMMAND FOR hfcmulti CARD
+			hfcmulti_type="type="
+			hfcmulti_prot="protocol="
+			hfcmulti_layer="layermask="
+			while [ ! -z ${hfcmulti[${card_index}]} ];
+			do
+				hfcmulti_type="${hfcmulti_type}$(echo "obase=16;\"0x\";${hfcmulti[${card_index}]}" | bc ),"
+				let "card_index = ${card_index} + 1"
+			done
+			while [ ${hfcports} -gt 0 ];
+			do
+				if [ ! -z ${protocol[${port_index}]} ]; then
+					hfcmulti_prot="${hfcmulti_prot}$(echo "obase=16;\"0x\";${protocol[${port_index}]}" | bc),"
+				else
+					hfcmulti_prot="${hfcmulti_prot}0x2,"
+				fi
+				if [ ! -z ${layermask[${port_index}]} ]; then
+					hfcmulti_layer="${hfcmulti_layer}${layermask[${port_index}]},"
+				else
+					hfcmulti_layer="${hfcmulti_layer}0xf,"
+				fi
+				let "port_index = ${port_index} + 1"
+				let "hfcports = ${hfcports} - 1"
+			done
+			hfcmulti_type="$(echo ${hfcmulti_type} | sed -e 's/^\(.*\),$/\1/')"
+			hfcmulti_prot="$(echo ${hfcmulti_prot} | sed -e 's/^\(.*\),$/\1/')"
+			hfcmulti_layer="$(echo ${hfcmulti_layer} | sed -e 's/^\(.*\),$/\1/')"
+			hfcmulti_cmd="modprobe hfcmulti ${hfcmulti_type} ${hfcmulti_prot} ${hfcmulti_layer}"
+			if [ ! -z ${poll} ]; then
+				hfcmulti_cmd="${hfcmulti_cmd} poll=${poll}"
+			fi
+			if [ ! -z ${pcm} ]; then
+				hfcmulti_cmd="${hfcmulti_cmd} pcm=${pcm}"
+			fi
+			if [ ! -z ${debug} ]; then
+				hfcmulti_cmd="${hfcmulti_cmd} debug=${debug}"
+			fi
+
+			echo ${hfcmulti_cmd}
+			eval ${hfcmulti_cmd}
+		else
+	# MODPROBE COMMAND FOR _NON_ hfcmulti CARD
+			other_cmd="modprobe ${other_card[${card_index}]}"
+			if [ ! -z ${protocol[${port_index}]} ]; then
+				other_prot="protocol=$(echo "obase=16;\"0x\";${protocol[${port_index}]}" | bc),"
+			else
+				other_prot="protocol=0x2,"
+			fi
+			if [ ! -z ${layermask[${port_index}]} ]; then
+				other_layer="layermask=${layermask[${port_index}]},"
+			else
+				other_layer="layermask=0xf,"
+			fi
+
+			let "prev = ${card_index}"
+			let "card_index = ${card_index} + 1"
+			let "port_index = ${port_index} + 1"
+			while [ "${other_card[${card_index}]}" == "${other_card[${prev}]}" ];
+			do
+				if [ ! -z ${protocol[${port_index}]} ]; then
+					other_prot="${other_prot}$(echo "obase=16;\"0x\";${protocol[${port_index}]}" | bc),"
+				else
+					other_prot="${other_prot}0x2,"
+				fi
+				if [ ! -z ${layermask[${port_index}]} ]; then
+					other_layer="${other_layer}${layermask[${port_index}]},"
+				else
+					other_layer="${other_layer}0xf,"
+				fi
+				let "prev = ${card_index}"
+				let "card_index = ${card_index} + 1"
+				let "port_index = ${port_index} + 1"
+			done
+			
+			other_prot="$(echo ${other_prot} | sed -e 's/^\(.*\),$/\1/')"
+			other_layer="$(echo ${other_layer} | sed -e 's/^\(.*\),$/\1/')"
+			other_cmd="${other_cmd} ${other_prot} ${other_layer}"
+			echo "${other_cmd}"
+			eval ${other_cmd}
+		fi
+	done
+}
+
+function unload_card_modules {
+
+	IFS=$'\n'
+
+	for line in $(sed -ne '/^[^#]/p' ${misdn_init_conf});
+	do
+		var=`echo "${line}" | sed -e "s/^\(.*\)=.*/\1/"`
+		val=`echo "${line}" | sed -e "s/^.*=\(.*\)/\1/"`
+		
+		case "${var}" in
+			card)
+				nr=`echo "${val}" | sed -e "s/^\([0-9]*\),.*/\1/"`
+				mod=`echo "${val}" | sed -e "s/^[^,]*,\([^,]*\).*/\1/"`
+				case "${mod}" in
+					0x*)
+						modulelist[${nr}]=hfcmulti
+						;;
+					*)
+						modulelist[${nr}]=${mod}
+						;;
+				esac
+				;;
+		esac
+		
+	done
+
+	echo "-------------------------------------------"
+	echo " Unloading module(s) for your misdn-cards:"
+	echo "-------------------------------------------"
+
+	rmmod_cmd="${RMMOD} ${modulelist[1]}"
+	echo "${rmmod_cmd}"
+	eval ${rmmod_cmd}
+	
+	index=2
+	prev=1
+	while [ ! -z ${modulelist[${index}]} ];
+	do
+		if [ ${modulelist[${index}]} != ${modulelist[${prev}]} ]; then
+			rmmod_cmd="${RMMOD} ${modulelist[${index}]}"
+			echo "${rmmod_cmd}"
+			eval ${rmmod_cmd}
+		fi
+		let "prev = ${index}"
+		let "index = ${index} + 1"
+	done
+}
+
+function create_misdn_init_conf {
+	
+	cardcount=1
+	cardconf=""
+	IFS=$'\n'
+	NL="
+"
+
+	function die {
+		echo "[!!] ${1}"
+		exit 1
+	}
+	
+	function addcard {
+		cardline="${cardline}card=${cardcount},${1}${NL}"
+		let "cardcount = ${cardcount} + 1"
+	}
+
+	function addport {
+		let "portcount = ${portcount} + ${1}"
+	}
+
+	portcount=0
+
+	for line in $(${LSPCI} -n -d 1397:30b1); do
+		addcard "0x1"
+		addport 1
+	done
+	for line in $(${LSPCI} -n -d 1397:08b4); do
+		addcard "0x4"
+		addport 4
+	done
+	for line in $(${LSPCI} -n -d 1397:16b8); do
+		addcard "0x8"
+		addport 8
+	done
+	for line in $(${LSPCI} -n | grep "1397:\(2bd\(0\|6\|7\|8\|9\|a\|b\|c\)\|b100\)\|1043:0675\|0871:ffa\(1\|2\)\|1051:0100\|15b0:2bd0\|114f:007\(0\|1\|2\|3\)\|13d1:2bd1\|182d:3069"); do
+		addcard "hfcpci"
+		addport 1
+	done
+	for line in $(${LSPCI} -n -d 1244:0xa00); do
+		addcard "avmfritz"
+		addport 1
+	done
+	
+	if [ "${1}" == "scan" ]; then
+		echo "[OK] found the following devices:"
+		echo "${cardline}[ii] run \"/etc/init.d/misdn-init config\" to store this information to ${misdn_init_conf}"
+	else
+		
+		index=1
+		portline="te_ptmp="
+		while [ ${index} -le ${portcount} ]; do
+			portline="${portline}${index},"
+			let "index = ${index} + 1"
+		done
+		portline="$(echo ${portline} | sed -e 's/^\(.*\),$/\1/')"
+
+		misdn_cfg_pt1="#
+# Configuration file for your misdn hardware
+#
+# Usage: /etc/init.d/misdn-init start|stop|restart|config|scan|help
+#
+
+#
+# Card Settings
+#
+# Syntax: card=<number>,<type>[,<option>...]
+#
+#    <number>   count your cards beginning with 1
+#    <type>     either 0x1,0x4 or 0x8 for your hfcmulti hardware,
+#               or the name of your card driver module.
+#    <option>	ulaw       - uLaw (instead of aLaw)
+#               dtmf       - enable DTMF detection on all B-channels
+#               pcm_slave  - set PCM bus into slave mode
+#"
+		misdn_cfg_pt2="#
+# Port settings
+#
+# Syntax: <port_type>=<port_number>[,<port_number>...]
+#
+#    <port_type>    te_ptp   - TE-Mode, PTP
+#                   te_ptmp  - TE-Mode, PTMP
+#                   nt_ptp   - NT-Mode, PTP
+#                   nt_ptmp  - NT-Mode, PTMP
+#    <port_number>  port that should be considered
+#"
+		misdn_cfg_pt3="#
+# Port Options
+#
+# Syntax: option=<port_number>,<option>[,<option>...]
+#
+#    <option>  master_clock  - use master clock for this S/T interface
+#                              (only once per chip, only for HFC 8/4)
+#              optical       - optical (only HFC-E1)
+#              los           - report LOS (only HFC-E1)
+#              ais           - report AIS (only HFC-E1)
+#              slip          - report SLIP (only HFC-E1)
+#
+#option=1,master_clock
+#option=2,ais
+#option=3,optical,los,ais,slip
+
+#
+# General Options for your hfcmulti hardware
+#
+# poll=<number>
+#
+#        Only one poll value must be given for all cards.
+#        Give the number of samples for each fifo process.
+#        By default 128 is used. Decrease to reduce delay, increase to
+#        reduce cpu load. If unsure, don't mess with it!!!
+#        Valid is 32, 64, 128, 256.
+#
+# pcm=<number>
+#        
+#        Give the id of the PCM bus. All PCM busses with the same ID
+#        are expected to be connected and have equal slots.
+#        Only one chip of the PCM bus must be master, the others slave.
+#        -1 means no support of PCM bus.
+#
+# debug=<number>
+#
+#        Enable debugging (see hfc_multi.h for debug options).
+#
+poll=64
+#pcm=1
+debug=0"
+
+		if [ -f ${misdn_init_conf} ]; then
+			cp "${misdn_init_conf}" "${misdn_init_conf}.save" || die "could not backup your existing ${misdn_init_conf}!"
+			echo "[OK] ${misdn_init_conf} already present. backing it up to ${misdn_init_conf}.save"
+		fi
+		echo "${misdn_cfg_pt1}${NL}${cardline}${NL}${misdn_cfg_pt2}${NL}${portline}${NL}${NL}${misdn_cfg_pt3}" > ${misdn_init_conf} || die "could not write to /etc/misdn-init.conf!"
+#echo "${misdn_cfg_pt1}${NL}${cardline}${NL}${misdn_cfg_pt2}${NL}${portline}${NL}${NL}${misdn_cfg_pt3}" > testconf || die "could not write to /etc/misdn-init.conf!"
+
+		echo "[OK] ${misdn_init_conf} created. It's now safe to run \"/etc/init.d/misdn-init start\""
+		if [ ${portcount} -gt 1 ]; then
+			echo "[ii] make your ports (1-${portcount}) available in asterisk by editing \"/etc/asterisk/misdn.conf\""
+		elif [ ${portcount} -eq 1 ]; then
+			echo "[ii] make your port (1) available in asterisk by editing \"/etc/asterisk/misdn.conf\""
+		fi
+	fi
+}
+
+function check_cfg_file {
+	if [ ! -f ${misdn_init_conf} ]; then
+		echo "[!!] failed to load: ${misdn_init_conf}"
+		echo "run \"/etc/init.d/misdn-init config\" to scan your devices and generate a basic config file."
+		exit 1
+	fi
+}
+
+# MAIN #############
+
+case "$1" in
+	start|--start)
+
+		check_cfg_file
+	
+		$MODPROBE mISDN_core debug=0
+		$MODPROBE mISDN_l1 debug=0
+		$MODPROBE mISDN_l2 debug=0
+		$MODPROBE l3udss1 debug=0
+		$MODPROBE mISDN_dsp debug=0xf options=0x0
+		
+		load_card_modules
+		
+		sleep 1
+		
+		if [ ! -e /dev/mISDN ]; then
+			$MKNOD /dev/mISDN c 46 0
+			echo "[i] creating device node: /dev/mISDN"
+		fi
+		;;
+
+	stop|--stop)
+		
+		check_cfg_file
+
+		unload_card_modules
+		
+		for mod in $(lsmod | sed -ne '/Module/!{s/\([^ ]*\).*/\1/;p}');
+		do
+			case "${mod}" in
+				mISDN_dsp | l3udss1 | mISDN_l2 | mISDN_l1 | mISDN_isac | mISDN_core)
+					eval "${RMMOD} ${mod}"
+					;;
+			esac
+		done
+		;;
+
+	restart|--restart)
+		
+		check_cfg_file
+
+		sh $0 stop
+		sleep 2 # some phones will release tei when layer 1 is down
+		sh $0 start
+		;;
+
+	config|--config)
+
+		create_misdn_init_conf
+
+		;;
+
+	scan|--scan)
+
+		create_misdn_init_conf scan
+
+		;;
+
+	help|--help)
+		echo "Usage: $0 {start|stop|restart|config|scan|help}"
+		exit 0
+		;;
+
+	*)
+		echo "Usage: $0 {start|stop|restart|config|scan|help}"
+		exit 2
+		;;
+
+esac
+

Propchange: team/crichter/0.3.0/channels/misdn/misdn-init
------------------------------------------------------------------------------
    svn:executable = *



More information about the asterisk-commits mailing list