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

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Jun 26 10:33:52 MST 2006


Author: crichter
Date: Mon Jun 26 12:33:51 2006
New Revision: 36081

URL: http://svn.digium.com/view/asterisk?rev=36081&view=rev
Log:
* fixed the busy state
* fixed tone handling after ast_hangup was called
* optimized the tone_indication function
* removed warnings in favour of log debugs
* improved the round_robin method
* added logs for channel setting/emptying
* fixed channel forgot to set bug


Modified:
    team/crichter/0.3.0/channels/chan_misdn.c
    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

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=36081&r1=36080&r2=36081&view=diff
==============================================================================
--- team/crichter/0.3.0/channels/chan_misdn.c (original)
+++ team/crichter/0.3.0/channels/chan_misdn.c Mon Jun 26 12:33:51 2006
@@ -294,7 +294,7 @@
 static enum event_response_e
 cb_events(enum event_e event, struct misdn_bchannel *bc, void *user_data);
 
-static void send_cause2ast(struct ast_channel *ast, struct misdn_bchannel*bc);
+static void send_cause2ast(struct ast_channel *ast, struct misdn_bchannel*bc, struct chan_list *ch);
 
 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);
@@ -628,7 +628,9 @@
 	{MISDN_EXTCANTMATCH,"EXTCANTMATCH"}, /*  when asterisk couldnt match our ext */
 	{MISDN_DIALING,"DIALING"}, /*  when pbx_start */
 	{MISDN_PROGRESS,"PROGRESS"}, /*  when pbx_start */
+	{MISDN_PROCEEDING,"PROCEEDING"}, /*  when pbx_start */
 	{MISDN_CALLING,"CALLING"}, /*  when misdn_call is called */
+	{MISDN_CALLING_ACKNOWLEDGE,"CALLING_ACKNOWLEDGE"}, /*  when misdn_call is called */
 	{MISDN_ALERTING,"ALERTING"}, /*  when Alerting */
 	{MISDN_BUSY,"BUSY"}, /*  when BUSY */
 	{MISDN_CONNECTED,"CONNECTED"}, /*  when connected */
@@ -646,13 +648,17 @@
 static char *misdn_get_ch_state(struct chan_list *p) 
 {
 	int i;
+	static char state[8];
+	
 	if( !p) return NULL;
   
 	for (i=0; i< sizeof(state_array)/sizeof(struct state_struct); i++) {
 		if ( state_array[i].state == p->state) return state_array[i].txt; 
 	}
-  
-	return NULL;
+
+ 	sprintf(state,"%d",p->state) ;
+
+	return state;
 }
 
 
@@ -1778,7 +1784,7 @@
 		chan_misdn_log(1, p->bc->port, "* IND :\tbusy\n");
 		chan_misdn_log(1, p->bc->port, " --> * SEND: State Busy pid:%d\n",p->bc?p->bc->pid:-1);
 		ast_setstate(ast,AST_STATE_BUSY);
-		
+
 		p->bc->out_cause=17;
 		if (p->state != MISDN_CONNECTED) {
 			misdn_lib_send_event( p->bc, EVENT_DISCONNECT);
@@ -1946,7 +1952,7 @@
 	
 	{
 		const char *varcause=NULL;
-		bc->cause=ast->hangupcause?ast->hangupcause:16;
+		bc->out_cause=ast->hangupcause?ast->hangupcause:16;
 		
 		if ( (varcause=pbx_builtin_getvar_helper(ast, "HANGUPCAUSE")) ||
 		     (varcause=pbx_builtin_getvar_helper(ast, "PRI_CAUSE"))) {
@@ -1967,15 +1973,16 @@
 			break;
 		case MISDN_HOLDED:
 		case MISDN_DIALING:
+		case MISDN_CALLING_ACKNOWLEDGE:
 			start_bc_tones(p);
 			tone_indicate(p, TONE_HANGUP);
-			p->state=MISDN_CLEANING;
-		
-			if (bc->nt)
+		
+			if (bc->nt) {
 				misdn_lib_send_event( bc, EVENT_DISCONNECT);
-			else
+			} else {
 				misdn_lib_send_event( bc, EVENT_RELEASE_COMPLETE);
-      
+				p->state=MISDN_CLEANING;
+			}
 			break;
       
 		case MISDN_ALERTING:
@@ -1984,16 +1991,19 @@
 			if (p->orginator != ORG_AST) 
 				tone_indicate(p, TONE_HANGUP);
       
-			p->state=MISDN_CLEANING;
+			/*p->state=MISDN_CLEANING;*/
 			misdn_lib_send_event( bc, EVENT_DISCONNECT);
 			break;
 		case MISDN_CONNECTED:
 			/*  Alerting or Disconect */
-			start_bc_tones(p);
-			tone_indicate(p, TONE_HANGUP);
+			if (p->bc->nt) {
+				start_bc_tones(p);
+				tone_indicate(p, TONE_HANGUP);
+				p->bc->progress_indicator=8;
+			}
 			misdn_lib_send_event( bc, EVENT_DISCONNECT);
-      
-			p->state=MISDN_CLEANING; /* MISDN_HUNGUP_FROM_AST; */
+
+			/*p->state=MISDN_CLEANING;*/
 			break;
 		case MISDN_DISCONNECTED:
 			misdn_lib_send_event( bc, EVENT_RELEASE);
@@ -2002,6 +2012,10 @@
 
 		case MISDN_RELEASED:
 		case MISDN_CLEANING:
+			p->state=MISDN_CLEANING;
+			break;
+
+		case MISDN_BUSY:
 			break;
       
 		case MISDN_HOLD_DISCONNECT:
@@ -2011,22 +2025,22 @@
 			
 			bc->out_cause=-1;
 			misdn_lib_send_event(bc,EVENT_RELEASE);
+			p->state=MISDN_CLEANING;
 			break;
 		default:
-			/*  Alerting or Disconect */
-
 			if (bc->nt) {
 				bc->out_cause=-1;
 				misdn_lib_send_event(bc, EVENT_RELEASE);
-			} else
+				p->state=MISDN_CLEANING; 
+			} else {
 				misdn_lib_send_event(bc, EVENT_DISCONNECT);
-			p->state=MISDN_CLEANING; /* MISDN_HUNGUP_FROM_AST; */
+			}
 		}
     
 	}
 	
 
-	chan_misdn_log(1, bc->port, "Channel: %s hanguped\n",ast->name);
+	chan_misdn_log(1, bc->port, "Channel: %s hanguped new state:%s\n",ast->name,misdn_get_ch_state(p));
 	
 	return 0;
 }
@@ -2278,6 +2292,7 @@
 		chan_misdn_log(3,cl->bc->port,"Ast Ptr Not existing anymore.. we need to generate tones ourselves now (tbd)\n");
 		
 		misdn_lib_send_tone(cl->bc,tone);
+		misdn_lib_tone_generator_start(cl->bc);
 		return 0;
 	}
 	
@@ -2285,24 +2300,20 @@
 	case TONE_DIAL:
 		chan_misdn_log(3,cl->bc->port," --> Dial\n");
 		ts=ast_get_indication_tone(ast->zone,"dial");
-		misdn_lib_tone_generator_start(cl->bc);
 		break;
 	case TONE_ALERTING:
 		chan_misdn_log(3,cl->bc->port," --> Ring\n");
 		ts=ast_get_indication_tone(ast->zone,"ring");
-		misdn_lib_tone_generator_start(cl->bc);
 		break;
 	case TONE_FAR_ALERTING:
 	/* VERY UGLY HACK, BECAUSE CHAN_SIP DOES NOT GENERATE TONES */
 		chan_misdn_log(3,cl->bc->port," --> Ring\n");
 		ts=ast_get_indication_tone(ast->zone,"ring");
-		misdn_lib_tone_generator_start(cl->bc);
 		misdn_lib_echo(cl->bc,1);
 		break;
 	case TONE_BUSY:
 		chan_misdn_log(3,cl->bc->port," --> Busy\n");
 		ts=ast_get_indication_tone(ast->zone,"busy");
-		misdn_lib_tone_generator_start(cl->bc);
 		break;
 	case TONE_FILE:
 		break;
@@ -2317,7 +2328,13 @@
 	
 	cl->ts=ts;	
 	
-	if (ts) ast_playtones_start(ast,0, ts->data, 0);
+	if (ts) {
+		cl->notxtone=0;
+		cl->norxtone=0;
+		ast_playtones_start(ast,0, ts->data, 0);
+		chan_misdn_log(4,cl->bc->port,"Starting Playtones\n");
+		misdn_lib_tone_generator_start(cl->bc);
+	}
 	
 	return 0;
 }
@@ -2433,7 +2450,8 @@
 						next_chan = 1;
 					
 					if (port <= port_start && next_chan) {
-						if (++robin_channel >= MAX_BCHANS) {
+						int maxbchans=misdn_lib_get_maxchans(port);
+						if (++robin_channel >= maxbchans) {
 							robin_channel = 1;
 						}
 						next_chan = 0;
@@ -2850,7 +2868,7 @@
 				chan_misdn_log(1, bc->port, "* RELEASING CHANNEL pid:%d ctx:%s dad:%s oad:%s state: %s\n",bc?bc->pid:-1, ast->context, ast->exten,AST_CID_P(ast),misdn_get_ch_state(ch));
 				chan_misdn_log(3, bc->port, " --> * State Down\n");
 				/* copy cause */
-				send_cause2ast(ast,bc);
+				send_cause2ast(ast,bc,ch);
 				
 				MISDN_ASTERISK_TECH_PVT(ast)=NULL;
 				
@@ -2872,11 +2890,13 @@
 				case MISDN_DIALING:
 				case MISDN_CALLING_ACKNOWLEDGE:
 				case MISDN_PROGRESS:
+				case MISDN_PROCEEDING:
 					chan_misdn_log(2,  bc->port, "* --> In State Dialin\n");
 					chan_misdn_log(2,  bc->port, "* --> Queue Hangup\n");
 					
-
+					ch->state=MISDN_CLEANING;
 					ast_queue_hangup(ast);
+					
 					break;
 				case MISDN_CALLING:
 					
@@ -2995,7 +3015,7 @@
 
 
 
-static void send_cause2ast(struct ast_channel *ast, struct misdn_bchannel*bc) {
+static void send_cause2ast(struct ast_channel *ast, struct misdn_bchannel*bc, struct chan_list *ch) {
 	
 	ast->hangupcause=bc->cause;
 	
@@ -3012,6 +3032,7 @@
 		 * the inband message
 		 *
 		chan_misdn_log(1, bc?bc->port:0, " --> * SEND: Queue Congestion pid:%d\n", bc?bc->pid:-1);
+		ch->state=MISDN_BUSY;
 		
 		ast_queue_control(ast, AST_CONTROL_CONGESTION);
 		*/
@@ -3020,7 +3041,8 @@
 	case 21:
 	case 17: /* user busy */
 		chan_misdn_log(1,  bc?bc->port:0, " --> * SEND: Queue Busy pid:%d\n", bc?bc->pid:-1);
-		
+	
+		ch->state=MISDN_BUSY;
 		ast_queue_control(ast, AST_CONTROL_BUSY);
 		
 		break;
@@ -3080,6 +3102,8 @@
 	
 	if (ch ) {
 		switch (event) {
+		case EVENT_TONE_GENERATE:
+		break;
 		case EVENT_DISCONNECT:
 		case EVENT_RELEASE:
 		case EVENT_RELEASE_COMPLETE:
@@ -3196,10 +3220,8 @@
 				ch->state=MISDN_EXTCANTMATCH;
 				bc->out_cause=1;
 
-				if (bc->nt)
-					misdn_lib_send_event(bc, EVENT_RELEASE_COMPLETE );
-				else
-					misdn_lib_send_event(bc, EVENT_DISCONNECT );
+				misdn_lib_send_event(bc, EVENT_DISCONNECT );
+
 				break;
 			}
 			if (ast_exists_extension(ch->ast, ch->context, bc->dad, 1, bc->oad)) {
@@ -3212,10 +3234,7 @@
 					chan_misdn_log(-1, bc->port, "ast_pbx_start returned < 0 in INFO\n");
 					tone_indicate(ch,TONE_BUSY);
 
-					if (bc->nt)
-						misdn_lib_send_event(bc, EVENT_RELEASE_COMPLETE );
-					else
-						misdn_lib_send_event(bc, EVENT_DISCONNECT );
+					misdn_lib_send_event(bc, EVENT_DISCONNECT );
 				}
 			}
 	
@@ -3570,8 +3589,7 @@
 		struct chan_list *holded_ch=find_holded(cl_te, bc);
 		
 		if (ch->ast)	
-			send_cause2ast(ch->ast,bc);
-
+			send_cause2ast(ch->ast,bc,ch);
 
 		chan_misdn_log(3,bc->port," --> org:%d nt:%d, inbandavail:%d state:%d\n", ch->orginator, bc->nt, misdn_inband_avail(bc), ch->state);
 		if ( ch->orginator==ORG_AST && !bc->nt && misdn_inband_avail(bc) && ch->state != MISDN_CONNECTED) {
@@ -3596,19 +3614,9 @@
 		}
 		
 		stop_bc_tones(ch);
-		/*bc->out_cause=16;*/
 		bc->out_cause=-1;
 		
-		/*if (ch->state == MISDN_CONNECTED) 
 		misdn_lib_send_event(bc,EVENT_RELEASE);
-		else
-		misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE);
-		*/
-		
-		misdn_lib_send_event(bc,EVENT_RELEASE);
-
-		if (ch->state == MISDN_CONNECTED)
-			ch->state=MISDN_RELEASED;
 	}
 	break;
 	
@@ -3658,6 +3666,8 @@
 		int (*generate)(struct ast_channel *chan, void *tmp, int datalen, int samples);
 
 		chan_misdn_log(9,bc->port,"TONE_GEN: len:%d\n");
+
+		if (!ast) break;
 
 		if (!ast->generator) break;
 	
@@ -3735,6 +3745,9 @@
 	break;
 	case EVENT_TIMEOUT:
 		{
+		if (ch && bc)
+			chan_misdn_log(1,bc->port,"--> state: %s\n",misdn_get_ch_state(ch));
+
 		switch (ch->state) {
 			case MISDN_WAITING4DIGS:
 			case MISDN_CALLING:

Modified: team/crichter/0.3.0/channels/misdn/ie.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.3.0/channels/misdn/ie.c?rev=36081&r1=36080&r2=36081&view=diff
==============================================================================
--- team/crichter/0.3.0/channels/misdn/ie.c (original)
+++ team/crichter/0.3.0/channels/misdn/ie.c Mon Jun 26 12:33:51 2006
@@ -1093,8 +1093,7 @@
 	*location = p[1] & 0x0f;
 	*progress = p[2] & 0x7f;
 
-	//if (MISDN_IE_DEBG) printf("    coding=%d location=%d progress=%d\n", *coding, *location, *progress);
-	if (1) printf("    coding=%d location=%d progress=%d\n", *coding, *location, *progress);
+	if (MISDN_IE_DEBG) printf("    coding=%d location=%d progress=%d\n", *coding, *location, *progress);
 }
 
 

Modified: team/crichter/0.3.0/channels/misdn/isdn_lib.c
URL: http://svn.digium.com/view/asterisk/team/crichter/0.3.0/channels/misdn/isdn_lib.c?rev=36081&r1=36080&r2=36081&view=diff
==============================================================================
--- team/crichter/0.3.0/channels/misdn/isdn_lib.c (original)
+++ team/crichter/0.3.0/channels/misdn/isdn_lib.c Mon Jun 26 12:33:51 2006
@@ -29,6 +29,20 @@
 	struct misdn_stack *stack=get_misdn_stack();
 	for ( ; stack; stack=stack->next) {
 		if (stack->port == port) return stack->ptp;
+	}
+	return -1;
+}
+
+int misdn_lib_get_maxchans(int port) 
+{
+	struct misdn_stack *stack=get_misdn_stack();
+	for ( ; stack; stack=stack->next) {
+		if (stack->port == port) {
+			if (stack->pri) 
+				return 30;
+			else
+				return 2;
+		}
 	}
 	return -1;
 }
@@ -370,6 +384,8 @@
 {
 	int i;
 
+	cb_log(1,stack->port,"find_free_chan: req_chan:%d\n",channel);
+
 	if (channel < 0 || channel > MAX_BCHANS) {
 		cb_log(4, stack->port, " !! out of bound call to find_free_chan_in_stack! (ch:%d)\n", channel);
 		return 0;
@@ -380,7 +396,7 @@
 	for (i = 0; i < stack->b_num; i++) {
 		if (i != 15 && (channel < 0 || i == channel)) { /* skip E1 Dchannel ;) and work with chan preselection */
 			if (!stack->channels[i]) {
-				cb_log (4, stack->port, " --> found chan%s: %d\n", channel>=0?" (preselected)":"", i+1);
+				cb_log (1, stack->port, " --> found chan%s: %d\n", channel>=0?" (preselected)":"", i+1);
 				stack->channels[i] = 1;
 				return i+1;
 			}
@@ -395,7 +411,7 @@
 
 int empty_chan_in_stack(struct misdn_stack *stack, int channel)
 {
-	cb_log (4, stack?stack->port:0, " --> empty chan %d\n",channel); 
+	cb_log (1, stack?stack->port:0, "empty_chan_in_stack: %d\n",channel); 
 	stack->channels[channel-1] = 0;
 	dump_chan_list(stack);
 	return 0;
@@ -607,7 +623,13 @@
 
 int set_chan_in_stack(struct misdn_stack *stack, int channel)
 {
-	stack->channels[channel-1] = 1;
+
+	cb_log(1,stack->port,"set_chan_in_stack: %d\n",channel);
+	if (channel >=1 ) {
+		stack->channels[channel-1] = 1;
+	} else {
+		cb_log(-1,stack->port,"couldn't set channel %d in\n", channel );
+	}
   
 	return 0;
 }
@@ -796,7 +818,7 @@
 			free_chan = find_free_chan_in_stack(stack, bc->channel_preselected?bc->channel:0);
 			if (!free_chan) return -1;
 			bc->channel=free_chan;
-			cb_log(0,stack->port, " -->  found channel: %d\n",free_chan);
+			cb_log(2,stack->port, " -->  found channel: %d\n",free_chan);
 		} else {
 			/* other phones could have made a call also on this port (ptmp) */
 			bc->channel=0xff;
@@ -1416,7 +1438,12 @@
 					cb_log(-1, stack->port, "Any Channel Requested, but we have no more!!\n");
 					break;
 				}
-			}  	
+			}  
+
+			if (bc->channel >0 && bc->channel<255) {
+				set_chan_in_stack(stack ,bc->channel);
+			}
+
 #if 0
 			int ret=setup_bc(bc);
 			if (ret == -EINVAL){
@@ -2081,6 +2108,7 @@
 		
 		r=mISDN_write( glob_mgr->midev, buf, txfrm->len + mISDN_HEADER_LEN, 8000 );
 	} else {
+#define MISDN_GEN_SILENCE
 #ifdef MISDN_GEN_SILENCE
 		int cnt=len/TONE_SILENCE_SIZE;
 		int rest=len%TONE_SILENCE_SIZE;
@@ -2117,7 +2145,7 @@
 	struct misdn_bchannel *bc=find_bc_by_addr(frm->addr);
 	
 	if (!bc) {
-		cb_log(0,0,"handle_bchan: BC not found for prim:%x with addr:%x dinfo:%x\n", frm->prim, frm->addr, frm->dinfo);
+		cb_log(1,0,"handle_bchan: BC not found for prim:%x with addr:%x dinfo:%x\n", frm->prim, frm->addr, frm->dinfo);
 		return 0 ;
 	}
 	
@@ -2268,7 +2296,8 @@
 		
 		free_msg(msg);
 		return 1;
-		
+	
+	
 	case PH_DATA|INDICATION:
 	case DL_DATA|INDICATION:
 	{
@@ -3161,6 +3190,16 @@
 			free_msg(msg) ; 
 			return 1;
 		break;
+
+		case DL_DATA|CONFIRM:
+			cb_log(4,0,"DL_DATA|CONFIRM\n");
+			free_msg(msg);
+			return 1;
+
+		case PH_CONTROL|CONFIRM:
+			cb_log(4,0,"PH_CONTROL|CONFIRM\n");
+			free_msg(msg);
+			return 1;
 
 		case DL_DATA|INDICATION:
 		{
@@ -3952,6 +3991,7 @@
 
 void misdn_lib_send_tone(struct misdn_bchannel *bc, enum tone_e tone) 
 {
+
 	switch(tone) {
 	case TONE_DIAL:
 		manager_ph_control(bc, TONE_PATT_ON, TONE_GERMAN_DIALTONE);	

Modified: team/crichter/0.3.0/channels/misdn/isdn_lib.h
URL: http://svn.digium.com/view/asterisk/team/crichter/0.3.0/channels/misdn/isdn_lib.h?rev=36081&r1=36080&r2=36081&view=diff
==============================================================================
--- team/crichter/0.3.0/channels/misdn/isdn_lib.h (original)
+++ team/crichter/0.3.0/channels/misdn/isdn_lib.h Mon Jun 26 12:33:51 2006
@@ -403,6 +403,7 @@
 void misdn_lib_echo(struct misdn_bchannel *bc, int onoff);
 
 int misdn_lib_is_ptp(int port);
+int misdn_lib_get_maxchans(int port);
 
 #define PRI_TRANS_CAP_SPEECH                                    0x0
 #define PRI_TRANS_CAP_DIGITAL                                   0x08



More information about the asterisk-commits mailing list