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

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Dec 6 05:14:44 CST 2005


Author: crichter
Date: Tue Dec  6 05:11:06 2005
New Revision: 7361

URL: http://svn.digium.com/view/asterisk?rev=7361&view=rev
Log:
first import head of chan_misdn

Modified:
    team/crichter/0.3.0/   (props changed)
    team/crichter/0.3.0/channels/Makefile
    team/crichter/0.3.0/channels/chan_misdn.c
    team/crichter/0.3.0/channels/chan_misdn_config.c
    team/crichter/0.3.0/channels/misdn/Makefile
    team/crichter/0.3.0/channels/misdn/chan_misdn_config.h
    team/crichter/0.3.0/channels/misdn/ie.c
    team/crichter/0.3.0/channels/misdn/isdn_lib.c
    team/crichter/0.3.0/channels/misdn/isdn_lib.h
    team/crichter/0.3.0/channels/misdn/isdn_lib_intern.h
    team/crichter/0.3.0/channels/misdn/isdn_msg_parser.c

Propchange: team/crichter/0.3.0/
------------------------------------------------------------------------------
    svnmerge-integrated = /trunk:1-7357

Modified: team/crichter/0.3.0/channels/Makefile
URL: http://svn.digium.com/view/asterisk/team/crichter/0.3.0/channels/Makefile?rev=7361&r1=7360&r2=7361&view=diff
==============================================================================
--- team/crichter/0.3.0/channels/Makefile (original)
+++ team/crichter/0.3.0/channels/Makefile Tue Dec  6 05:11:06 2005
@@ -63,7 +63,7 @@
     ifneq (${OSARCH},CYGWIN)
 # the ISDN4Linux channel driver is probably broken on all modern kernels,
 # but if you wish to try to use it, uncomment the line below
-#      CHANNEL_LIBS+=chan_modem_i4l.so 
+#      CHANNEL_LIBS+=chan_modem_i4l.so
        CHANNEL_LIBS+=chan_oss.so
     endif
   endif
@@ -83,6 +83,7 @@
 
 ifneq ($(wildcard misdn/chan_misdn_lib.a),)
   CHANNEL_LIBS+=chan_misdn.so
+  CFLAGS+=-Imisdn 
 endif
 
 CFLAGS+=-Wno-missing-prototypes -Wno-missing-declarations
@@ -234,11 +235,10 @@
 endif
 
 chan_misdn.so: chan_misdn.o chan_misdn_config.o misdn/chan_misdn_lib.a
-	$(CC) -shared -Xlinker -x -o $@ $^ $(MISDNUSER)/i4lnet/libisdnnet.a $(MISDNUSER)/lib/libmISDN.a 
-
-chan_misdn_config.o: chan_misdn_config.c
-	$(CC) $(CFLAGS) -c chan_misdn_config.c
-
+	$(CC) -shared -Xlinker -x -L/usr/lib -o $@ $^ -lisdnnet -lmISDN
+
+chan_misdn.o: chan_misdn.c
+	$(CC) $(CFLAGS) -DCHAN_MISDN_VERSION=\"0.2.1\" -c $< -o $@
 
 #chan_modem.so : chan_modem.o
 #	$(CC) -rdynamic -shared -Xlinker -x -o $@ $<

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=7361&r1=7360&r2=7361&view=diff
==============================================================================
--- team/crichter/0.3.0/channels/chan_misdn.c (original)
+++ team/crichter/0.3.0/channels/chan_misdn.c Tue Dec  6 05:11:06 2005
@@ -59,14 +59,19 @@
 #include <asterisk/app.h>
 #include <asterisk/features.h>
 
+#include "misdn/jitterbuffer.h"
+
 #include "chan_misdn_config.h"
 #include "isdn_lib.h"
 
+
 ast_mutex_t release_lock_mutex;
 
 #define release_lock ast_mutex_lock(&release_lock_mutex)
 #define release_unlock ast_mutex_unlock(&release_lock_mutex)
 
+
+char global_tracefile[BUFFERSIZE];
 
 /* BEGIN: chan_misdn.h */
 
@@ -113,6 +118,8 @@
 	int faxhandled;
 
 	int ast_dsp;
+
+	struct misdn_jb *jb;
 	
 	struct ast_dsp *dsp;
 	struct ast_trans_pvt *trans;
@@ -124,6 +131,8 @@
 
 	unsigned int l3id;
 	int addr;
+
+	char context[BUFFERSIZE];
 	
 	struct chan_list *peer;
 	struct chan_list *next;
@@ -142,11 +151,11 @@
 
 static inline void free_robin_list_r (struct robin_list *r)
 {
-	if (r) {
-		if (r->next) free_robin_list_r(r->next);
-		if (r->group) free(r->group);
-		free(r);
-	}
+        if (r) {
+                if (r->next) free_robin_list_r(r->next);
+                if (r->group) free(r->group);
+                free(r);
+        }
 }
 
 static void free_robin_list ( void )
@@ -155,7 +164,7 @@
 	robin = NULL;
 }
 
-struct robin_list* get_robin_position (char *group) 
+static struct robin_list* get_robin_position (char *group) 
 {
 	struct robin_list *iter = robin;
 	for (; iter; iter = iter->next) {
@@ -173,8 +182,11 @@
 	return robin;
 }
 
-struct ast_channel *misdn_new(struct chan_list *cl, int state, char * name, char * context, char *exten, char *callerid, int format, int port, int c);
-void send_digit_to_chan(struct chan_list *cl, char digit );
+
+static void chan_misdn_log(int level, int port, char *tmpl, ...);
+
+static struct ast_channel *misdn_new(struct chan_list *cl, int state,  char *exten, char *callerid, int format, int port, int c);
+static void send_digit_to_chan(struct chan_list *cl, char digit );
 
 
 #define AST_CID_P(ast) ast->cid.cid_num
@@ -186,46 +198,46 @@
 #define MISDN_ASTERISK_PVT(ast) 1
 #define MISDN_ASTERISK_TYPE(ast) ast->tech->type
 
-/* END: chan_misdn.h */
-
 #include <asterisk/strings.h>
 
 /* #define MISDN_DEBUG 1 */
 
 static  char *desc = "Channel driver for mISDN Support (Bri/Pri)";
-static  char *type = "mISDN";
-
-int tracing = 0 ;
+char *misdn_type = "mISDN";
+
+static int tracing = 0 ;
 
 static int usecnt=0;
 
-char **misdn_key_vector=NULL;
-int misdn_key_vector_size=0;
+static char **misdn_key_vector=NULL;
+static int misdn_key_vector_size=0;
 
 /* Only alaw and mulaw is allowed for now */
 static int prefformat =  AST_FORMAT_ALAW ; /*  AST_FORMAT_SLINEAR ;  AST_FORMAT_ULAW | */
 
 static ast_mutex_t usecnt_lock; 
 
-int *misdn_debug;
-int *misdn_debug_only;
-int max_ports;
+static int *misdn_debug;
+static int *misdn_debug_only;
+static int max_ports;
 
 struct chan_list dummy_cl;
 
 struct chan_list *cl_te=NULL;
 ast_mutex_t cl_te_lock;
 
-enum event_response_e
+static enum event_response_e
 cb_events(enum event_e event, struct misdn_bchannel *bc, void *user_data);
 
-void send_cause2ast(struct ast_channel *ast, struct misdn_bchannel*bc);
-
-void cl_queue_chan(struct chan_list **list, struct chan_list *chan);
-void cl_dequeue_chan(struct chan_list **list, struct chan_list *chan);
-struct chan_list *find_chan_by_bc(struct chan_list *list, struct misdn_bchannel *bc);
-void chan_misdn_log(int level, int port, char *tmpl, ...);
-void chan_misdn_trace_call(struct ast_channel *chan, int debug, char *tmpl, ...);
+static void send_cause2ast(struct ast_channel *ast, struct misdn_bchannel*bc);
+
+static void cl_queue_chan(struct chan_list **list, struct chan_list *chan);
+static void cl_dequeue_chan(struct chan_list **list, struct chan_list *chan);
+static struct chan_list *find_chan_by_bc(struct chan_list *list, struct misdn_bchannel *bc);
+
+
+
+
 
 static int start_bc_tones(struct chan_list *cl);
 static int stop_bc_tones(struct chan_list *cl);
@@ -233,6 +245,8 @@
 
 static int misdn_set_opt_exec(struct ast_channel *chan, void *data);
 static int misdn_facility_exec(struct ast_channel *chan, void *data);
+
+int chan_misdn_jb_empty(struct misdn_bchannel *bc, char *buf, int len);
 
 /*************** Helpers *****************/
 
@@ -306,6 +320,24 @@
 	}
 }
 
+
+static void print_facility( struct misdn_bchannel *bc)
+{
+	switch (bc->fac_type) {
+	case FACILITY_CALLDEFLECT:
+		chan_misdn_log(2,bc->port," --> calldeflect: %s\n",
+			       bc->fac.calldeflect_nr);
+		break;
+	case FACILITY_CENTREX:
+		chan_misdn_log(2,bc->port," --> centrex: %s\n",
+			       bc->fac.cnip);
+		break;
+	default:
+		chan_misdn_log(2,bc->port," --> unknown\n");
+		
+	}
+}
+
 static void print_bearer(struct misdn_bchannel *bc) 
 {
 	
@@ -322,7 +354,7 @@
 }
 /*************** Helpers END *************/
 
-void send_digit_to_chan(struct chan_list *cl, char digit )
+static void send_digit_to_chan(struct chan_list *cl, char digit )
 {
 	static const char* dtmf_tones[] = {
 		"!941+1336/100,!0/100",	/* 0 */
@@ -416,10 +448,9 @@
 	return 0;
 }
 
-
 static int misdn_set_crypt_debug(int fd, int argc, char *argv[])
 {
-	if (argc != 5 )return RESULT_SHOWUSAGE; 
+	if (argc != 5) return RESULT_SHOWUSAGE; 
 
 	return 0;
 }
@@ -505,14 +536,12 @@
 	return 0;
 }
 
-
-
 struct state_struct {
 	enum misdn_chan_state state;
 	char txt[255] ;
 } ;
 
-struct state_struct state_array[] = {
+static struct state_struct state_array[] = {
 	{MISDN_NOTHING,"NOTHING"}, /* at beginning */
 	{MISDN_WAITING4DIGS,"WAITING4DIGS"}, /*  when waiting for infos */
 	{MISDN_EXTCANTMATCH,"EXTCANTMATCH"}, /*  when asterisk couldnt match our ext */
@@ -531,10 +560,7 @@
 	/* misdn_hangup */
 };
 
-
-
-
-char *misdn_get_ch_state(struct chan_list *p) 
+static char *misdn_get_ch_state(struct chan_list *p) 
 {
 	int i;
 	if( !p) return NULL;
@@ -551,19 +577,14 @@
 	int i, cfg_debug;
 	
 	ast_cli(fd, "Reloading mISDN Config\n");
-	chan_misdn_log(0, 0, "Dynamic Crypting Activation is not support during reload at the moment\n");
+	chan_misdn_log(-1, 0, "Dynamic Crypting Activation is not support during reload at the moment\n");
 	
 	free_robin_list();
 
 	misdn_cfg_reload();
-
-	{
-		char tempbuf[BUFFERSIZE];
-		misdn_cfg_get( 0, MISDN_GEN_TRACEFILE, tempbuf, BUFFERSIZE);
-		if (strlen(tempbuf))
-			tracing = 1;
-	}
-
+	
+	misdn_cfg_get( 0, MISDN_GEN_TRACEFILE, global_tracefile, BUFFERSIZE);
+	
 	misdn_cfg_get( 0, MISDN_GEN_DEBUG, &cfg_debug, sizeof(int));
 	for (i = 0;  i <= max_ports; i++) {
 		misdn_debug[i] = cfg_debug;
@@ -578,6 +599,7 @@
 	struct ast_channel *ast=help->ast;
 	ast_cli(fd,
 		"* Pid:%d Prt:%d Ch:%d Mode:%s Org:%s dad:%s oad:%s ctx:%s state:%s\n",
+
 		bc->pid, bc->port, bc->channel,
 		bc->nt?"NT":"TE",
 		help->orginator == ORG_AST?"*":"I",
@@ -617,7 +639,6 @@
   
 }
 
-
 static int misdn_show_cls (int fd, int argc, char *argv[])
 {
 	struct chan_list *help=cl_te;
@@ -642,8 +663,6 @@
 	return 0;
 }
 
-
-
 static int misdn_show_cl (int fd, int argc, char *argv[])
 {
 	struct chan_list *help=cl_te;
@@ -680,13 +699,12 @@
 	return 0;
 }
 
-
-
 static int misdn_show_stacks (int fd, int argc, char *argv[])
 {
 	int port;
 	
 	ast_cli(fd, "BEGIN STACK_LIST:\n");
+
 	for (port=misdn_cfg_get_next_port(0); port > 0;
 	     port=misdn_cfg_get_next_port(port)) {
 		char buf[128];
@@ -745,8 +763,6 @@
   
 	return 0; 
 }
-
-
 
 static int misdn_send_digit (int fd, int argc, char *argv[])
 {
@@ -819,8 +835,6 @@
 	return 0; 
 }
 
-
-
 static int misdn_send_display (int fd, int argc, char *argv[])
 {
 	char *channame; 
@@ -851,9 +865,6 @@
 	return RESULT_SUCCESS ;
 }
 
-
-
-
 static char *complete_ch_helper(char *line, char *word, int pos, int state, int rpos)
 {
 	struct ast_channel *c;
@@ -909,7 +920,6 @@
   complete_ch
 };
 
-
 static struct ast_cli_entry cli_send_digit =
 { {"misdn","send","digit", NULL},
   misdn_send_digit,
@@ -920,7 +930,6 @@
   complete_ch
 };
 
-
 static struct ast_cli_entry cli_toggle_echocancel =
 { {"misdn","toggle","echocancel", NULL},
   misdn_toggle_echocancel,
@@ -928,8 +937,6 @@
   "Usage: misdn toggle echocancel <channel>\n", 
   complete_ch
 };
-
-
 
 static struct ast_cli_entry cli_send_display =
 { {"misdn","send","display", NULL},
@@ -941,7 +948,6 @@
   complete_ch
 };
 
-
 static struct ast_cli_entry cli_show_config =
 { {"misdn","show","config", NULL},
   misdn_show_config,
@@ -949,7 +955,6 @@
   "Usage: misdn show config [port | 0]\n       use 0 to only print the general config.\n"
 };
  
-
 static struct ast_cli_entry cli_reload =
 { {"misdn","reload", NULL},
   misdn_reload,
@@ -963,7 +968,6 @@
   "", 
   "\n"
 };
-
 
 static struct ast_cli_entry cli_show_cls =
 { {"misdn","show","channels", NULL},
@@ -989,7 +993,6 @@
   "Usage: misdn restart port\n"
 };
 
-
 static struct ast_cli_entry cli_port_up =
 { {"misdn","port","up", NULL},
   misdn_port_up,
@@ -997,7 +1000,6 @@
   "Usage: misdn port up <port>\n"
 };
 
-
 static struct ast_cli_entry cli_show_stacks =
 { {"misdn","show","stacks", NULL},
   misdn_show_stacks,
@@ -1011,8 +1013,6 @@
   "Shows detailed information for given port", 
   "Usage: misdn show port <port>\n"
 };
-
-
 
 static struct ast_cli_entry cli_set_debug =
 { {"misdn","set","debug", NULL},
@@ -1031,6 +1031,325 @@
 /*** CLI END ***/
 
 
+
+static int read_config(struct chan_list *ch, int orig) {
+
+	if (!ch) {
+		ast_log(LOG_WARNING, "Cannot configure without chanlist\n");
+		return -1;
+	}
+
+	struct ast_channel *ast=ch->ast;
+	struct misdn_bchannel *bc=ch->bc;
+	if (! ast || ! bc ) {
+		ast_log(LOG_WARNING, "Cannot configure without ast || bc\n");
+		return -1;
+	}
+	
+	int port=bc->port;
+	
+	chan_misdn_log(1,port,"read_config: Getting Config\n");
+
+	char lang[BUFFERSIZE];
+	
+
+	misdn_cfg_get( port, MISDN_CFG_LANGUAGE, lang, BUFFERSIZE);
+	ast_copy_string(ast->language, lang, sizeof(ast->language));
+	ast->language[sizeof(ast->language)]=0;
+
+
+	char musicclass[BUFFERSIZE];
+	
+	misdn_cfg_get( port, MISDN_CFG_MUSICCLASS, musicclass, BUFFERSIZE);
+	ast_copy_string(ast->musicclass, musicclass, sizeof(ast->musicclass));
+	ast->musicclass[sizeof(ast->musicclass)]=0;
+	
+	
+	misdn_cfg_get( port, MISDN_CFG_TXGAIN, &bc->txgain, sizeof(int));
+	misdn_cfg_get( port, MISDN_CFG_RXGAIN, &bc->rxgain, sizeof(int));
+	
+	misdn_cfg_get( port, MISDN_CFG_SENDDTMF, &bc->send_dtmf, sizeof(int));
+	
+
+	/*Initialize new Jitterbuffer*/
+	{
+		int jb_len,jb_upper_threshold;
+		misdn_cfg_get( port, MISDN_CFG_JITTERBUFFER, &jb_len, sizeof(int));
+		misdn_cfg_get( port, MISDN_CFG_JITTERBUFFER_UPPER_THRESHOLD, &jb_upper_threshold, sizeof(int));
+
+		if ( ! jb_len ) {
+			chan_misdn_log(1,bc->port, "read_config: Deactivating Jitterbuffer\n");
+			bc->nojitter=1;
+		} else {
+		
+			if (jb_len <=100 || jb_len > 8000) {
+				chan_misdn_log(-1,bc->port,"read_config: Jitterbuffer out of Bounds, setting to 1000\n");
+				jb_len=1000;
+			}
+			
+			if ( jb_upper_threshold > jb_len ) {
+				chan_misdn_log(-1,bc->port,"read_config: Jitterbuffer Threshold > Jitterbuffer setting to Jitterbuffer -1\n");
+			}
+			
+			
+			if ( ch->jb) {
+				cb_log(0,bc->port,"read_config: We've got a Jitterbuffer Already on this port.\n");
+				misdn_jb_destroy(ch->jb);
+				ch->jb=NULL;
+			}
+			
+			ch->jb=misdn_jb_init(jb_len, jb_upper_threshold);
+		}
+	}
+	
+	misdn_cfg_get( bc->port, MISDN_CFG_CONTEXT, ch->context, sizeof(ch->context));
+	strncpy(ast->context,ch->context,sizeof(ast->context)-1);
+	
+	{
+		int ec, ectr;
+		
+		misdn_cfg_get( port, MISDN_CFG_ECHOCANCEL, &ec, sizeof(int));
+		
+		misdn_cfg_get( port, MISDN_CFG_ECHOTRAINING, &ectr, sizeof(int));
+		if (ec == 1 ) {
+			bc->ec_enable=1;
+		} else if ( ec > 1 ) {
+			bc->ec_enable=1;
+			bc->ec_deftaps=ec;
+		}
+		
+		if ( ectr >= 0 ) {
+			bc->ec_training=ectr;
+		}
+	}
+	
+	
+	{
+		int eb3;
+		
+		misdn_cfg_get( bc->port, MISDN_CFG_EARLY_BCONNECT, &eb3, sizeof(int));
+		bc->early_bconnect=eb3;
+	}
+	
+	port=bc->port;
+	
+
+	{
+		char buf[256];
+		ast_group_t pg,cg;
+		
+		misdn_cfg_get(port, MISDN_CFG_PICKUPGROUP, &pg, sizeof(pg));
+		misdn_cfg_get(port, MISDN_CFG_CALLGROUP, &cg, sizeof(cg));
+		
+		chan_misdn_log(2, port, " --> * CallGrp:%s PickupGrp:%s\n",ast_print_group(buf,sizeof(buf),cg),ast_print_group(buf,sizeof(buf),pg));
+		ast->pickupgroup=pg;
+		ast->callgroup=cg;
+	}
+	
+	
+	if ( orig  == ORG_AST) {
+		misdn_cfg_get( port, MISDN_CFG_TE_CHOOSE_CHANNEL, &(bc->te_choose_channel), sizeof(int));
+		
+		
+		{
+			char callerid[BUFFERSIZE];
+			misdn_cfg_get( port, MISDN_CFG_CALLERID, callerid, BUFFERSIZE);
+			if ( ! ast_strlen_zero(callerid) ) {
+				chan_misdn_log(1, port, " --> * Setting Cid to %s\n", callerid);
+				{
+					int l = sizeof(bc->oad);
+					strncpy(bc->oad,callerid, l);
+					bc->oad[l-1] = 0;
+				}
+
+			}
+
+			
+			misdn_cfg_get( port, MISDN_CFG_DIALPLAN, &bc->dnumplan, sizeof(int));
+			switch (bc->dnumplan) {
+			case NUMPLAN_INTERNATIONAL:
+				chan_misdn_log(2, port, " --> TON: International\n");
+				break;
+			case NUMPLAN_NATIONAL:
+				chan_misdn_log(2, port, " --> TON: National\n");
+				break;
+			case NUMPLAN_SUBSCRIBER:
+				chan_misdn_log(2, port, " --> TON: Subscriber\n");
+				break;
+			case NUMPLAN_UNKNOWN:
+				chan_misdn_log(2, port, " --> TON: Unknown\n");
+				break;
+				/* Maybe we should cut off the prefix if present ? */
+			default:
+				chan_misdn_log(0, port, " --> !!!! Wrong dialplan setting, please see the misdn.conf sample file\n ");
+				break;
+			}
+
+
+			misdn_cfg_get( port, MISDN_CFG_LOCALDIALPLAN, &bc->onumplan, sizeof(int));
+			switch (bc->onumplan) {
+			case NUMPLAN_INTERNATIONAL:
+				chan_misdn_log(2, port, " --> TON: International\n");
+				break;
+			case NUMPLAN_NATIONAL:
+				chan_misdn_log(2, port, " --> TON: National\n");
+				break;
+			case NUMPLAN_SUBSCRIBER:
+				chan_misdn_log(2, port, " --> TON: Subscriber\n");
+				break;
+			case NUMPLAN_UNKNOWN:
+				chan_misdn_log(2, port, " --> TON: Unknown\n");
+				break;
+				/* Maybe we should cut off the prefix if present ? */
+			default:
+					chan_misdn_log(0, port, " --> !!!! Wrong dialplan setting, please see the misdn.conf sample file\n ");
+					break;
+			}
+		}
+
+		
+		/* Will be overridden by asterisk in head! */
+		{
+			int pres;
+			
+			misdn_cfg_get( port, MISDN_CFG_PRES, &pres, sizeof(int));
+			bc->pres=pres?0:1;
+			
+		}
+		
+		int def_callingpres;
+		misdn_cfg_get( port, MISDN_CFG_USE_CALLINGPRES, &def_callingpres, sizeof(int));
+		if ( def_callingpres) {
+			
+			switch (ast->cid.cid_pres & 0x60){
+				
+			case AST_PRES_RESTRICTED:
+				bc->pres=1;
+				chan_misdn_log(2, port, " --> PRES: Restricted (0x1)\n");
+				break;
+				
+				
+			case AST_PRES_UNAVAILABLE:
+				bc->pres=2;
+				chan_misdn_log(2, port, " --> PRES: Unavailable (0x2)\n");
+				break;
+				
+			default:
+				bc->pres=0;
+				chan_misdn_log(2, port, " --> PRES: Allowed (0x0)\n");
+			}
+			
+			switch (ast->cid.cid_pres & 0x3){
+				
+			case AST_PRES_USER_NUMBER_UNSCREENED:
+				bc->screen=0;
+				chan_misdn_log(2, port, " --> SCREEN: Unscreened (0x0)\n");
+				break;
+
+			case AST_PRES_USER_NUMBER_PASSED_SCREEN:
+				bc->screen=1;
+				chan_misdn_log(2, port, " --> SCREEN: Passed Screen (0x1)\n");
+				break;
+			case AST_PRES_USER_NUMBER_FAILED_SCREEN:
+				bc->screen=2;
+				chan_misdn_log(2, port, " --> SCREEN: Failed Screen (0x2)\n");
+				break;
+				
+			case AST_PRES_NETWORK_NUMBER:
+				bc->screen=3;
+				chan_misdn_log(2, port, " --> SCREEN: Network Nr. (0x3)\n");
+				break;
+				
+			default:
+				bc->screen=0;
+				chan_misdn_log(2, port, " --> SCREEN: Unscreened (0x0)\n");
+			}
+
+			
+		}
+
+		
+		
+	} else { /** ORIGINATOR MISDN **/
+		
+		char prefix[BUFFERSIZE]="";
+		switch( bc->onumplan ) {
+		case NUMPLAN_INTERNATIONAL:
+			misdn_cfg_get( bc->port, MISDN_CFG_INTERNATPREFIX, prefix, BUFFERSIZE);
+			break;
+			
+		case NUMPLAN_NATIONAL:
+			misdn_cfg_get( bc->port, MISDN_CFG_NATPREFIX, prefix, BUFFERSIZE);
+			break;
+			
+			
+		case NUMPLAN_SUBSCRIBER:
+			/* dunno what to do here ? */
+			break;
+			
+		case NUMPLAN_UNKNOWN:
+				break;
+		default:
+			break;
+		}
+		
+		{
+			int l = strlen(prefix) + strlen(bc->oad);
+			char tmp[l+1];
+			strcpy(tmp,prefix);
+			strcat(tmp,bc->oad);
+			strcpy(bc->oad,tmp);
+		}
+		
+		
+		if (!ast_strlen_zero(bc->dad)) {
+			strncpy(bc->orig_dad,bc->dad, sizeof(bc->orig_dad));
+			bc->orig_dad[sizeof(bc->orig_dad)-1] = 0;
+		}
+		
+		if ( ast_strlen_zero(bc->dad) && !ast_strlen_zero(bc->keypad)) {
+			strncpy(bc->dad,bc->keypad, sizeof(bc->dad));
+			bc->dad[sizeof(bc->dad)-1] = 0;
+		}
+		prefix[0] = 0;
+		
+		switch( bc->dnumplan ) {
+		case NUMPLAN_INTERNATIONAL:
+			misdn_cfg_get( bc->port, MISDN_CFG_INTERNATPREFIX, prefix, BUFFERSIZE);
+			break;
+			
+			case NUMPLAN_NATIONAL:
+				misdn_cfg_get( bc->port, MISDN_CFG_NATPREFIX, prefix, BUFFERSIZE);
+				break;
+				
+				
+		case NUMPLAN_SUBSCRIBER:
+				/* dunno what to do here ? */
+			break;
+			
+		case NUMPLAN_UNKNOWN:
+			break;
+		default:
+			break;
+		}
+		
+		{
+			int l = strlen(prefix) + strlen(bc->dad);
+			char tmp[l+1];
+			strcpy(tmp,prefix);
+			strcat(tmp,bc->dad);
+			strcpy(bc->dad,tmp);
+		}
+		
+		
+		
+		pbx_builtin_setvar_helper(ch->ast,"REDIRECTING_NUMBER",bc->rad);
+	}
+	
+	return 0;
+}
+
+
 /*****************************/
 /*** AST Indications Start ***/
 /*****************************/
@@ -1041,9 +1360,8 @@
 	int r;
 	struct chan_list *ch=MISDN_ASTERISK_TECH_PVT(ast);
 	struct misdn_bchannel *newbc;
-	char *opts=NULL, *ext=NULL;
+	char *opts=NULL, *ext,*tokb;
 	char dest_cp[256];
-	char *tokb;
 	
 	{
 		strncpy(dest_cp,dest,sizeof(dest_cp)-1);
@@ -1059,6 +1377,7 @@
 				chan_misdn_log(-1,0,"misdn_call: No Extension given!\n");
 				return -1;
 			}
+			
 		}
 		
 		
@@ -1094,128 +1413,15 @@
 	}
 	
 	port=newbc->port;
-	
-	ast_copy_string(newbc->dad, ext, sizeof(newbc->dad));
-	ast_copy_string(ast->exten, ext, sizeof(ast->exten));
+	strncpy(newbc->dad,ext,sizeof( newbc->dad));
+	strncpy(ast->exten,ext,sizeof(ast->exten));
 	
 	
 	chan_misdn_log(1, 0, "* CALL: %s\n",dest);
 	
 	chan_misdn_log(1, port, " --> * dad:%s tech:%s ctx:%s\n",ast->exten,ast->name, ast->context);
 	
-	{
-		char context[BUFFERSIZE];
-		
-		misdn_cfg_get( port, MISDN_CFG_CONTEXT, context, sizeof(ast->context));
-		{
-			int l = sizeof(ast->context);
-			strncpy(ast->context,context, l);
-			ast->context[l-1] = 0;
-		}
-		chan_misdn_log(2, port, " --> * Setting Context to %s\n",context);
-		misdn_cfg_get( port, MISDN_CFG_LANGUAGE, ast->language, BUFFERSIZE);
-		
-		misdn_cfg_get( port, MISDN_CFG_TXGAIN, &newbc->txgain, sizeof(int));
-		misdn_cfg_get( port, MISDN_CFG_RXGAIN, &newbc->rxgain, sizeof(int));
-		
-		misdn_cfg_get( port, MISDN_CFG_TE_CHOOSE_CHANNEL, &(newbc->te_choose_channel), sizeof(int));
-		
-
-		{
-			char callerid[BUFFERSIZE];
-			misdn_cfg_get( port, MISDN_CFG_CALLERID, callerid, BUFFERSIZE);
-			if ( ! ast_strlen_zero(callerid) ) {
-				chan_misdn_log(1, port, " --> * Setting Cid to %s\n", callerid);
-				{
-					int l = sizeof(newbc->oad);
-					strncpy(newbc->oad,callerid, l);
-					newbc->oad[l-1] = 0;
-				}
-				
-				misdn_cfg_get( port, MISDN_CFG_DIALPLAN, &newbc->dnumplan, sizeof(int));
-				switch (newbc->dnumplan) {
-				case NUMPLAN_INTERNATIONAL:
-				case NUMPLAN_NATIONAL:
-				case NUMPLAN_SUBSCRIBER:
-				case NUMPLAN_UNKNOWN:
-					/* Maybe we should cut off the prefix if present ? */
-					break;
-				default:
-					chan_misdn_log(0, port, " --> !!!! Wrong dialplan setting, please see the misdn.conf sample file\n ");
-					break;
-				}
-				
-			}
-		}
-		
-		/* Will be overridden by asterisk in head! */
-		{
-			int pres;
-			
-			misdn_cfg_get( port, MISDN_CFG_PRES, &pres, sizeof(int));
-			newbc->pres=pres?0:1;
-			
-		}
-		
-		int def_callingpres;
-		misdn_cfg_get( port, MISDN_CFG_USE_CALLINGPRES, &def_callingpres, sizeof(int));
-		if ( def_callingpres) {
-			switch (ast->cid.cid_pres & 0x60){
-				
-			case AST_PRES_RESTRICTED:
-				newbc->pres=1;
-				break;
-				
-			case AST_PRES_UNAVAILABLE:
-				newbc->pres=2;
-				break;
-			
-			default:
-				newbc->pres=0;
-			}
-			
-			switch (ast->cid.cid_pres & 0x3){
-				
-			case AST_PRES_USER_NUMBER_UNSCREENED:
-				newbc->screen=0;
-				break;
-
-			case AST_PRES_USER_NUMBER_PASSED_SCREEN:
-				newbc->screen=1;
-				break;
-			case AST_PRES_USER_NUMBER_FAILED_SCREEN:
-				newbc->screen=2;
-				break;
-				
-			case AST_PRES_NETWORK_NUMBER:
-				newbc->screen=3;
-				break;
-				
-			default:
-				newbc->screen=0;
-			}
-		}
-
-		
-		{
-			int ec, ectr;
-			
-			misdn_cfg_get( port, MISDN_CFG_ECHOCANCEL, &ec, sizeof(int));
-			
-			misdn_cfg_get( port, MISDN_CFG_ECHOTRAINING, &ectr, sizeof(int));
-			if (ec == 1 ) {
-				newbc->ec_enable=1;
-			} else if ( ec > 1 ) {
-				newbc->ec_enable=1;
-				newbc->ec_deftaps=ec;
-			}
-
-			if ( !ectr ) {
-				newbc->ec_training=0;
-			}
-		}
-		
-	} 
+	
 	
 	chan_misdn_log(3, port, " --> * adding2newbc ext %s\n",ast->exten);
 	if (ast->exten) {
@@ -1226,6 +1432,7 @@
 	newbc->rad[0]=0;
 	chan_misdn_log(3, port, " --> * adding2newbc callerid %s\n",AST_CID_P(ast));
 	if (ast_strlen_zero(newbc->oad) && AST_CID_P(ast) ) {
+
 		if (AST_CID_P(ast)) {
 			int l = sizeof(newbc->oad);
 			strncpy(newbc->oad,AST_CID_P(ast), l);
@@ -1236,21 +1443,14 @@
 	{
 		struct chan_list *ch=MISDN_ASTERISK_TECH_PVT(ast);
 		if (!ch) { ast_verbose("No chan_list in misdn_call"); return -1;}
-		ch->bc = newbc;
-		ch->orginator=ORG_AST;
-		ch->ast = ast;
-		
-		MISDN_ASTERISK_TECH_PVT(ast) = ch ;
-		
-		
-      
+		
 		newbc->capability=ast->transfercapability;
 		pbx_builtin_setvar_helper(ast,"TRANSFERCAPABILITY",ast_transfercapability2str(newbc->capability));
 		if ( ast->transfercapability == INFO_CAPABILITY_DIGITAL_UNRESTRICTED) {
 			chan_misdn_log(2, port, " --> * Call with flag Digital\n");
 		}
 		
-
+		
 		/* Finally The Options Override Everything */
 		if (opts)
 			misdn_set_opt_exec(ast,opts);
@@ -1258,10 +1458,9 @@
 			chan_misdn_log(1,0,"NO OPTS GIVEN\n");
 		
 		
-		cl_queue_chan(&cl_te, ch) ;
+		
 		ch->state=MISDN_CALLING;
 
-		chan_misdn_trace_call(ast,1,"*->I: EVENT_CALL\n" );
 		
 		r=misdn_lib_send_event( newbc, EVENT_SETUP );
 		
@@ -1286,7 +1485,7 @@
 }
 
 
-int misdn_answer(struct ast_channel *ast)
+static int misdn_answer(struct ast_channel *ast)
 {
 	struct chan_list *p;
 
@@ -1294,7 +1493,6 @@
 	if (!ast || ! MISDN_ASTERISK_PVT(ast)) return -1;
 	p = MISDN_ASTERISK_TECH_PVT(ast) ;
 	
-	chan_misdn_trace_call(ast,1,"*->I: EVENT_ANSWER\n");
 	
 	chan_misdn_log(1, p? (p->bc? p->bc->port : 0) : 0, "* ANSWER:\n");
 	
@@ -1340,7 +1538,7 @@
 	return 0;
 }
 
-int misdn_digit(struct ast_channel *ast, char digit )
+static int misdn_digit(struct ast_channel *ast, char digit )
 {
 	struct chan_list *p;
 	
@@ -1400,7 +1598,7 @@
 }
 
 
-int misdn_fixup(struct ast_channel *oldast, struct ast_channel *ast)
+static int misdn_fixup(struct ast_channel *oldast, struct ast_channel *ast)
 {
 	struct chan_list *p;
 	
@@ -1416,20 +1614,8 @@
 }
 
 
-int misdn_transfer (struct ast_channel *ast, char *dest)
-{
-	struct chan_list *p;
-	
-	if (!ast || ! MISDN_ASTERISK_PVT(ast)) return -1;
-	p = MISDN_ASTERISK_TECH_PVT(ast) ;
-
-	chan_misdn_log(1, p->bc?p->bc->port:0, "* IND : Got Transfer %s\n",dest);
-	return 0;
-}
-
-
-
-int misdn_indication(struct ast_channel *ast, int cond)
+
+static int misdn_indication(struct ast_channel *ast, int cond)
 {
 	struct chan_list *p;
 
@@ -1459,8 +1645,8 @@
 			misdn_lib_send_event( p->bc, EVENT_DISCONNECT);
 			manager_send_tone(p->bc, TONE_BUSY);
 		} else {
-			chan_misdn_log(0, p->bc->port, " --> !! Got Busy in Connected State !?! port:%d ast:%s\n",
-				       p->bc->port, ast->name);
+
+			chan_misdn_log(-1, p->bc->port, " --> !! Got Busy in Connected State !?! ast:%s\n", ast->name);
 		}
 		break;
 	case AST_CONTROL_RING:
@@ -1498,16 +1684,17 @@
 		chan_misdn_log(1, p->bc->port, " --> * IND :\tprogress pid:%d\n",p->bc?p->bc->pid:-1);
 		break;
 	case AST_CONTROL_CONGESTION:
+
 		chan_misdn_log(1, p->bc->port, " --> * IND :\tcongestion pid:%d\n",p->bc?p->bc->pid:-1);
 
 		p->bc->out_cause=42;
 		if (p->state != MISDN_CONNECTED) {
 			start_bc_tones(p);
-			//misdn_lib_send_event( p->bc, EVENT_RELEASE_COMPLETE);
 			misdn_lib_send_event( p->bc, EVENT_RELEASE);
 		} else {
 			misdn_lib_send_event( p->bc, EVENT_DISCONNECT);
 		}
+
 		if (p->bc->nt) {
 			manager_send_tone(p->bc, TONE_BUSY);
 		}
@@ -1515,6 +1702,7 @@
 	case -1 :
 		chan_misdn_log(1, p->bc->port, " --> * IND :\t-1! pid:%d\n",p->bc?p->bc->pid:-1);
 		break;
+
 	case AST_CONTROL_HOLD:
 		chan_misdn_log(1, p->bc->port, " --> *\tHOLD pid:%d\n",p->bc?p->bc->pid:-1);
 		break;
@@ -1528,17 +1716,15 @@
 	return 0;
 }
 
-int misdn_hangup(struct ast_channel *ast)
+static int misdn_hangup(struct ast_channel *ast)
 {
 	struct chan_list *p;
 	struct misdn_bchannel *bc=NULL;
 	
-	if (!ast || ! MISDN_ASTERISK_PVT(ast)) return -1;
-	p = MISDN_ASTERISK_TECH_PVT(ast) ;
-
+	if (!ast || ! (p=MISDN_ASTERISK_TECH_PVT(ast) ) ) return -1;
+	
 	release_lock;
 
-	chan_misdn_trace_call(ast,1,"*->I: EVENT_HANGUP cause=%d\n",ast->hangupcause);
 	
 	ast_log(LOG_DEBUG, "misdn_hangup(%s)\n", ast->name);
 	
@@ -1560,6 +1746,8 @@
 	MISDN_ASTERISK_TECH_PVT(ast)=NULL;
 	p->ast=NULL;
 
+	bc=p->bc;
+	
 	if (ast->_state == AST_STATE_RESERVED) {
 		/* between request and call */
 		MISDN_ASTERISK_TECH_PVT(ast)=NULL;
@@ -1567,8 +1755,9 @@
 		
 		cl_dequeue_chan(&cl_te, p);
 		free(p);
-
-		misdn_lib_release(bc);
+		
+		if (bc)
+			misdn_lib_release(bc);
 		
 		return 0;
 	}
@@ -1576,10 +1765,6 @@
 	stop_bc_tones(p);
 	
 	release_unlock;
-	
-	
-	
-	
 	
 	
 	{
@@ -1644,6 +1829,7 @@
 			break;
 		default:
 			/*  Alerting or Disconect */
+
 			if (bc->nt)
 				misdn_lib_send_event(bc, EVENT_RELEASE);
 			else
@@ -1658,7 +1844,7 @@
 	return 0;
 }
 
-struct ast_frame  *misdn_read(struct ast_channel *ast)
+static struct ast_frame  *misdn_read(struct ast_channel *ast)
 {
 	struct chan_list *tmp;
 	
@@ -1666,8 +1852,7 @@
 	int len =0 ;
 	
 	if (!ast) return NULL;
-	tmp = MISDN_ASTERISK_TECH_PVT(ast);
-	if (!tmp) return NULL;
+	if (! (tmp=MISDN_ASTERISK_TECH_PVT(ast)) ) return NULL;
 	if (!tmp->bc) return NULL;
 	
 	
@@ -1690,39 +1875,41 @@
 	tmp->frame.src = NULL;
 	tmp->frame.data = tmp->ast_rd_buf ;
 
-	chan_misdn_trace_call(tmp->ast,3,"*->I: EVENT_READ len=%d\n",len);
 	return &tmp->frame;
 }
 
-int misdn_write(struct ast_channel *ast, struct ast_frame *frame)
-{
-	struct chan_list *p;
+
+
+
+static int misdn_write(struct ast_channel *ast, struct ast_frame *frame)
+{
+	struct chan_list *ch;
 	int i  = 0;
 	
-	if (!ast || ! MISDN_ASTERISK_PVT(ast)) return -1;
-	p = MISDN_ASTERISK_TECH_PVT(ast) ;
-	
-	if (!p->bc ) {
+	if (!ast || ! (ch=MISDN_ASTERISK_TECH_PVT(ast)) ) return -1;
+	
+	if (!ch->bc ) {
 		ast_log(LOG_WARNING, "private but no bc\n");
 		return -1;
 	}
 	
-	if (p->bc->tone != TONE_NONE)
-		manager_send_tone(p->bc,TONE_NONE);
-	
-	
-	if (p->holded ) {
-		chan_misdn_log(5, p->bc->port, "misdn_write: Returning because holded\n");
+	if (ch->bc->tone != TONE_NONE)
+		manager_send_tone(ch->bc,TONE_NONE);
+	
+	
+	if (ch->holded ) {
+		chan_misdn_log(5, ch->bc->port, "misdn_write: Returning because holded\n");
 		return 0;
 	}
 	
-	if (p->notxtone) {
-		chan_misdn_log(5, p->bc->port, "misdn_write: Returning because notxone\n");
+	if (ch->notxtone) {
+		chan_misdn_log(5, ch->bc->port, "misdn_write: Returning because notxone\n");
 		return 0;
 	}
 	
 	if ( !(frame->subclass & prefformat)) {
-		chan_misdn_log(0, p->bc->port, "Got Unsupported Frame with Format:%d\n", frame->subclass);
+
+		chan_misdn_log(-1, ch->bc->port, "Got Unsupported Frame with Format:%d\n", frame->subclass);
 	}
 	
 	
@@ -1736,11 +1923,30 @@
 		printf ("\n");
 	}
 #endif
-	chan_misdn_trace_call(ast,3,"*->I: EVENT_WRITE len=%d\n",frame->samples);
-	i= manager_tx2misdn_frm(p->bc, frame->data, frame->samples);
+
+	/*if speech flip bits*/
+	if ( misdn_cap_is_speech(ch->bc->capability) )
+		flip_buf_bits(frame->data,frame->samples);
+	
+	
+	if ( !ch->bc->nojitter && misdn_cap_is_speech(ch->bc->capability) ) {
+		/* Buffered Transmit (triggert by read from isdn side)*/
+		if (misdn_jb_fill(ch->jb,frame->data,frame->samples) < 0) {
+			if (ch->bc->active)
+				cb_log(0,ch->bc->port,"Misdn Jitterbuffer Overflow.\n");
+		}
+		
+	} else {
+		/*transmit without jitterbuffer*/
+		i=misdn_lib_tx2misdn_frm(ch->bc, frame->data, frame->samples);
+	}
+
+	
 	
 	return 0;
 }
+
+
 
 
 enum ast_bridge_result  misdn_bridge (struct ast_channel *c0,
@@ -1850,12 +2056,12 @@
 }
 
 
-struct chan_list *init_chan_list(void)
+static struct chan_list *init_chan_list(void)
 {
 	struct chan_list *cl=malloc(sizeof(struct chan_list));
 	
 	if (!cl) {
-		chan_misdn_log(0, 0, "misdn_request: malloc failed!");
+		chan_misdn_log(-1, 0, "misdn_request: malloc failed!");
 		return NULL;
 	}
 	
@@ -1878,7 +2084,7 @@
 	
 	struct chan_list *cl=init_chan_list();
 	
-	sprintf(buf,"%s/%s",type,(char*)data);
+	sprintf(buf,"%s/%s",misdn_type,(char*)data);
 	strncpy(buf2,data, 128);
 	buf2[127] = 0;
 	port_str=strtok_r(buf2,"/", &tokb);
@@ -1906,7 +2112,7 @@
 			*p = 0;
 			channel = atoi(++p);
 			port = atoi(port_str);
-			chan_misdn_log(2, port, " --> Call on preselected Channel (%d) on Port %d\n", channel, port);
+			chan_misdn_log(2, port, " --> Call on preselected Channel (%d).\n", channel);
 		}
 		else {
 			port = atoi(port_str);
@@ -2012,16 +2218,25 @@
 		chan_misdn_log(1, 0, " --> SEND: State Down\n");
 		return NULL;
 	}
-	
+
+	/* create ast_channel and link all the objects together */
 	cl->bc=newbc;
 	
-	tmp = misdn_new(cl, AST_STATE_RESERVED, buf, "default", ext, ext, format, port, channel);
+	tmp = misdn_new(cl, AST_STATE_RESERVED, ext, NULL, format, port, channel);
+	cl->ast=tmp;
+	
+	/* register chan in local list */
+	cl_queue_chan(&cl_te, cl) ;
+	
+	/* fill in the config into the objects */
+	read_config(cl, ORG_AST);
+	
 	
 	return tmp;
 }
 
 
-struct ast_channel_tech misdn_tech = {
+static struct ast_channel_tech misdn_tech = {
 	.type="mISDN",
 	.description="Channel driver for mISDN Support (Bri/Pri)",
 	.capabilities= AST_FORMAT_ALAW ,
@@ -2036,10 +2251,9 @@
 	.indicate=misdn_indication,
 	.fixup=misdn_fixup,
 	.properties=0
-	/* .transfer=misdn_transfer */
 };
 
-struct ast_channel_tech misdn_tech_wo_bridge = {
+static struct ast_channel_tech misdn_tech_wo_bridge = {
 	.type="mISDN",
 	.description="Channel driver for mISDN Support (Bri/Pri)",
 	.capabilities=AST_FORMAT_ALAW ,
@@ -2053,61 +2267,55 @@
 	.indicate=misdn_indication,
 	.fixup=misdn_fixup,
 	.properties=0
-	/* .transfer=misdn_transfer */
 };
 
 
-unsigned long glob_channel=0;
-
-struct ast_channel *misdn_new(struct chan_list *chlist, int state, char * name, char * context, char *exten, char *callerid, int format, int port, int c)
+static unsigned long glob_channel=0;
+
+static struct ast_channel *misdn_new(struct chan_list *chlist, int state,  char *exten, char *callerid, int format, int port, int c)
 {
 	struct ast_channel *tmp;
 	
 	tmp = ast_channel_alloc(1);
 	
 	if (tmp) {
-		chan_misdn_log(2, 0, " --> * NEW CHANNEL dad:%s oad:%s ctx:%s\n",exten,callerid, context);
+		chan_misdn_log(2, 0, " --> * NEW CHANNEL dad:%s oad:%s\n",exten,callerid);
 		
 		
 		if (c<=0) {
 			c=glob_channel++;
 			snprintf(tmp->name, sizeof(tmp->name), "%s/%d-u%d",
-				 type, port, c);
+				 misdn_type, port, c);
 		} else {
 			snprintf(tmp->name, sizeof(tmp->name), "%s/%d-%d",
-				 type, port, c);
-		}
-		
-		tmp->type = type;
-    
+				 misdn_type, port, c);
+		}
+		
+		tmp->type = misdn_type;
+		
 		tmp->nativeformats = prefformat;
+
 		tmp->readformat = format;
 		tmp->writeformat = format;
     
 		tmp->tech_pvt = chlist;
-
+		
 		int bridging;
 		misdn_cfg_get( 0, MISDN_GEN_BRIDGING, &bridging, sizeof(int));
 		if (bridging)
 			tmp->tech = &misdn_tech;
 		else
 			tmp->tech = &misdn_tech_wo_bridge;
-    
-    
+		
 		tmp->writeformat = format;
 		tmp->readformat = format;
 		tmp->priority=1;
-    
-		
-		if (context)
-			ast_copy_string(tmp->context, context, sizeof(tmp->context));
-		else
-			chan_misdn_log(1,0,"misdn_new: no context given.\n");
+		
 		if (exten) 
-			ast_copy_string(tmp->exten, exten, sizeof(tmp->exten));
+			ast_copy_string(tmp->exten, exten,  sizeof(tmp->exten));
 		else
 			chan_misdn_log(1,0,"misdn_new: no exten given.\n");
-
+		
 		if (callerid) {
 			char *cid_name, *cid_num;
       
@@ -2126,37 +2334,15 @@
 			
 		}
 		
-		if (chlist->bc) {
-			int port=chlist->bc->port;
-			misdn_cfg_get( port, MISDN_CFG_LANGUAGE, tmp->language, sizeof(tmp->language));
-			
-			{
-				char buf[256];
-				ast_group_t pg,cg;
-				
-				misdn_cfg_get(port, MISDN_CFG_PICKUPGROUP, &pg, sizeof(pg));
-				misdn_cfg_get(port, MISDN_CFG_CALLGROUP, &cg, sizeof(cg));
-				
-				chan_misdn_log(2, port, " --> * CallGrp:%s PickupGrp:%s\n",ast_print_group(buf,sizeof(buf),cg),ast_print_group(buf,sizeof(buf),pg));
-				tmp->pickupgroup=pg;
-				tmp->callgroup=cg;
-			}
-			misdn_cfg_get(port, MISDN_CFG_TXGAIN, &chlist->bc->txgain, sizeof(int));
-			misdn_cfg_get(port, MISDN_CFG_RXGAIN, &chlist->bc->rxgain, sizeof(int));
-			chan_misdn_log(2, port, " --> rxgain:%d txgain:%d\n",chlist->bc->rxgain,chlist->bc->txgain);
-			
-		} else {
-			chan_misdn_log(3, 0, " --> Not Setting Pickupgroup, we have no bc yet\n");
-		}
-		
 		ast_setstate(tmp, state);
 		if (state == AST_STATE_RING)
 			tmp->rings = 1;
 		else
 			tmp->rings = 0;
+		
+		
 	} else {
-		ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
-		chan_misdn_log(0,0,"Unable to allocate channel structure\n");
+		chan_misdn_log(-1,0,"Unable to allocate channel structure\n");
 	}
 	
 	return tmp;
@@ -2164,7 +2350,7 @@
 
 
 
-int misdn_tx2ast_frm(struct chan_list * tmp, char * buf,  int len )
+static int misdn_tx2ast_frm(struct chan_list * tmp, char * buf,  int len )
 {
 	struct ast_frame frame;
 	
@@ -2271,7 +2457,7 @@
 
 /** Channel Queue ***/
 
-struct chan_list *find_chan_by_l3id(struct chan_list *list, unsigned long l3id)
+static struct chan_list *find_chan_by_l3id(struct chan_list *list, unsigned long l3id)
 {
 	struct chan_list *help=list;
 	for (;help; help=help->next) {
@@ -2283,7 +2469,7 @@
 	return NULL;
 }
 
-struct chan_list *find_chan_by_bc(struct chan_list *list, struct misdn_bchannel *bc)
+static struct chan_list *find_chan_by_bc(struct chan_list *list, struct misdn_bchannel *bc)
 {
 	struct chan_list *help=list;
 	for (;help; help=help->next) {
@@ -2296,7 +2482,7 @@
 }
 
 
-struct chan_list *find_holded(struct chan_list *list, struct misdn_bchannel *bc)
+static struct chan_list *find_holded(struct chan_list *list, struct misdn_bchannel *bc)
 {
 	struct chan_list *help=list;
 	
@@ -2312,7 +2498,7 @@
 	return NULL;
 }
 
-void cl_queue_chan(struct chan_list **list, struct chan_list *chan)
+static void cl_queue_chan(struct chan_list **list, struct chan_list *chan)
 {
 	chan_misdn_log(4, chan->bc? chan->bc->port : 0, "* Queuing chan %p\n",chan);
   
@@ -2328,12 +2514,13 @@
 	ast_mutex_unlock(&cl_te_lock);
 }
 
-void cl_dequeue_chan(struct chan_list **list, struct chan_list *chan) 
+static void cl_dequeue_chan(struct chan_list **list, struct chan_list *chan) 
 {
 	if (chan->dsp) 
 		ast_dsp_free(chan->dsp);
 	if (chan->trans)
 		ast_translator_free_path(chan->trans);
+
 	
 
 	ast_mutex_lock(&cl_te_lock);
@@ -2381,9 +2568,17 @@
 		release_unlock;
 		
 		chan_misdn_log(1, bc->port, "Trying to Release bc with l3id: %x\n",bc->l3_id);
+
+		//releaseing jitterbuffer
+		if (ch->jb ) {
+			misdn_jb_destroy(ch->jb);
+			ch->jb=NULL;
+		} else {
+			if (!bc->nojitter)
+				chan_misdn_log(5,bc->port,"Jitterbuffer already destroyed.\n");
+		}
+		
 		if (ch) {
-			if (ast)
-				chan_misdn_trace_call(ast,1,"I->*: EVENT_RELEASE\n");
 			
 			close(ch->pipe[0]);
 			close(ch->pipe[1]);
@@ -2463,7 +2658,7 @@
 }
 /*** release end **/
 
-void misdn_transfer_bc(struct chan_list *tmp_ch, struct chan_list *holded_chan)
+static void misdn_transfer_bc(struct chan_list *tmp_ch, struct chan_list *holded_chan)
 {
 	chan_misdn_log(4,0,"TRANSFERING %s to %s\n",holded_chan->ast->name, tmp_ch->ast->name);
 	
@@ -2479,7 +2674,7 @@
 }
 
 
-void do_immediate_setup(struct misdn_bchannel *bc,struct chan_list *ch , struct ast_channel *ast)
+static void do_immediate_setup(struct misdn_bchannel *bc,struct chan_list *ch , struct ast_channel *ast)
 {
 	char predial[256]="";
 	char *p = predial;
@@ -2490,6 +2685,7 @@
   
 	ch->state=MISDN_DIALING;
 	
+
 	if (bc->nt) {
 		int ret; 
 		ret = misdn_lib_send_event(bc, EVENT_SETUP_ACKNOWLEDGE );
@@ -2511,6 +2707,7 @@
 	if (ast_pbx_start(ast)<0) {
 		ast=NULL;
 		manager_send_tone(bc,TONE_BUSY);
+
 		if (bc->nt)
 			misdn_lib_send_event(bc, EVENT_RELEASE_COMPLETE );
 		else
@@ -2537,7 +2734,7 @@
 
 
 
-void send_cause2ast(struct ast_channel *ast, struct misdn_bchannel*bc) {
+static void send_cause2ast(struct ast_channel *ast, struct misdn_bchannel*bc) {
 	
 	ast->hangupcause=bc->cause;
 	
@@ -2567,7 +2764,7 @@
 /************************************************************/
 /*  Receive Events from isdn_lib  here                     */
 /************************************************************/
-enum event_response_e
+static enum event_response_e
 cb_events(enum event_e event, struct misdn_bchannel *bc, void *user_data)
 {
 	struct chan_list *ch=find_chan_by_bc(cl_te, bc);
@@ -2576,7 +2773,7 @@
 		ch=find_chan_by_l3id(cl_te, bc->l3_id);
 	
 	if (event != EVENT_BCHAN_DATA) { /*  Debug Only Non-Bchan */

[... 5135 lines stripped ...]


More information about the asterisk-commits mailing list