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

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sat Jun 17 03:32:21 MST 2006


Author: crichter
Date: Sat Jun 17 05:32:20 2006
New Revision: 34551

URL: http://svn.digium.com/view/asterisk?rev=34551&view=rev
Log:
* fixed bchannel cleaning race condition with new bchannel state (CLEAN_REQUEST)
* added early bridge-hook, so we know if we need to generate ringing or 
  can take it from the far end chan_misdn channel (if available)



Modified:
    team/crichter/0.3.0/channels/chan_misdn.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=34551&r1=34550&r2=34551&view=diff
==============================================================================
--- team/crichter/0.3.0/channels/chan_misdn.c (original)
+++ team/crichter/0.3.0/channels/chan_misdn.c Sat Jun 17 05:32:20 2006
@@ -83,8 +83,6 @@
 	ast_mutex_t mutexjb;
 };
 
-void export_ies(struct ast_channel *chan, struct misdn_bchannel *bc);
-void import_ies(struct ast_channel *chan, struct misdn_bchannel *bc);
 
 
 /* allocates the jb-structure and initialise the elements*/
@@ -180,6 +178,8 @@
 	struct ast_trans_pvt *trans;
   
 	struct ast_channel * ast;
+
+	int dummy;
   
 	struct misdn_bchannel *bc;
 	struct misdn_bchannel *holded_bc;
@@ -193,6 +193,8 @@
 	int dropped_frame_cnt;
 
 	int far_alerting;
+	int other_pid;
+	struct chan_list *other_ch;
 
 	const struct tone_zone_sound *ts;
 	
@@ -201,6 +203,11 @@
 	struct chan_list *prev;
 	struct chan_list *first;
 };
+
+
+
+void export_ch(struct ast_channel *chan, struct misdn_bchannel *bc, struct chan_list *ch);
+void import_ch(struct ast_channel *chan, struct misdn_bchannel *bc, struct chan_list *ch);
 
 struct robin_list {
 	char *group;
@@ -301,6 +308,7 @@
 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 struct chan_list *find_chan_by_pid(struct chan_list *list, int pid);
 
 
 
@@ -1587,7 +1595,7 @@
 		update_config(ch,ORG_AST);
 		
 		/* fill in some ies from channel vary*/
-		import_ies(ast, newbc);
+		import_ch(ast, newbc, ch);
 		
 		/* Finally The Options Override Everything */
 		if (opts)
@@ -1803,7 +1811,12 @@
 				p->state=MISDN_ALERTING;
 				chan_misdn_log(1, p->bc->port, " --> * IND :\tringing pid:%d\n",p->bc?p->bc->pid:-1);
 				misdn_lib_send_event( p->bc, EVENT_ALERTING);
-				
+			
+				if (p->other_ch && p->other_ch->bc && misdn_inband_avail(p->other_ch->bc)) {
+					chan_misdn_log(1,p->bc->port, " --> other End is mISDN and has inband info available\n");
+					break;
+				}
+			
 				if ( !p->bc->nt && (p->orginator==ORG_MISDN) && !p->incoming_early_audio ) 
 					chan_misdn_log(1,p->bc->port, " --> incoming_early_audio off\n");
 				 else 
@@ -1851,10 +1864,11 @@
 	case -1 :
 		chan_misdn_log(1, p->bc->port, " --> * IND :\t-1! (stop indication) pid:%d\n",p->bc?p->bc->pid:-1);
 		
-		if (p->state == MISDN_CONNECTED)
+		tone_indicate(p, TONE_NONE);
+
+		if (p->state == MISDN_CONNECTED) 
 			start_bc_tones(p);
-		else 
-			tone_indicate(p, TONE_NONE);
+
 		break;
 
 	case AST_CONTROL_HOLD:
@@ -1945,8 +1959,11 @@
 			start_bc_tones(p);
 			tone_indicate(p, TONE_BUSY);
 			p->state=MISDN_CLEANING;
-			
-			misdn_lib_send_event( bc, EVENT_RELEASE_COMPLETE);
+		
+			if (bc->nt)
+				misdn_lib_send_event( bc, EVENT_RELEASE);
+			else
+				misdn_lib_send_event( bc, EVENT_RELEASE_COMPLETE);
       
 			break;
       
@@ -2251,7 +2268,15 @@
 	chan_misdn_log(3,cl->bc->port,"Tone Indicate:\n");
 	
 	if (!cl->ast) {
+		chan_misdn_log(-1,cl->bc->port,"Ast Ptr Not existing anymore.. we need to generate tones ourselves now (tbd)\n");
 		return 0;
+#if 0
+		struct ast_channel *dummy=misdn_new(cl, AST_STATE_RESERVED, cl->bc->dad, cl->bc->oad, AST_FORMAT_ALAW, cl->bc->port, 99);
+		cl->ast=dummy;
+		/* return 0; */
+		cl->dummy=1;
+		ast=cl->ast;
+#endif
 	}
 	
 	switch (tone) {
@@ -2263,7 +2288,7 @@
 	case TONE_ALERTING:
 		chan_misdn_log(3,cl->bc->port," --> Ring\n");
 		ts=ast_get_indication_tone(ast->zone,"ring");
-		misdn_lib_tone_generator_stop(cl->bc);
+		misdn_lib_tone_generator_start(cl->bc);
 		break;
 	case TONE_FAR_ALERTING:
 	/* VERY UGLY HACK, BECAUSE CHAN_SIP DOES NOT GENERATE TONES */
@@ -2275,7 +2300,7 @@
 	case TONE_BUSY:
 		chan_misdn_log(3,cl->bc->port," --> Busy\n");
 		ts=ast_get_indication_tone(ast->zone,"busy");
-		misdn_lib_tone_generator_stop(cl->bc);
+		misdn_lib_tone_generator_start(cl->bc);
 		break;
 	case TONE_FILE:
 		break;
@@ -2362,7 +2387,7 @@
 			chan_misdn_log(2, 0, " --> Group Call group: %s\n",group);
 		} 
 		else if ((p = strchr(port_str, ':'))) {
-			// we have a preselected channel
+			/* we have a preselected channel */
 			*p = 0;
 			channel = atoi(++p);
 			port = atoi(port_str);
@@ -2691,6 +2716,17 @@
 	return NULL;
 }
 
+static struct chan_list *find_chan_by_pid(struct chan_list *list, int pid)
+{
+	struct chan_list *help=list;
+	for (;help; help=help->next) {
+		if (help->bc->pid == pid) return help;
+	}
+  
+	chan_misdn_log(6, 0, "$$$ find_chan: No channel found for pid:%d\n",pid);
+  
+	return NULL;
+}
 
 static struct chan_list *find_holded(struct chan_list *list, struct misdn_bchannel *bc)
 {
@@ -2782,8 +2818,15 @@
 		release_unlock;
 		
 		chan_misdn_log(1, bc->port, "release_chan: bc with l3id: %x\n",bc->l3_id);
-		
-		//releaseing jitterbuffer
+#if 0
+		if (ch->dummy) {
+			ast_hangup(ast);
+			ch->ast=NULL;
+			ast=NULL;
+		}
+#endif
+		
+		/*releaseing jitterbuffer*/
 		if (ch->jb ) {
 			misdn_jb_destroy(ch->jb);
 			ch->jb=NULL;
@@ -2978,43 +3021,28 @@
 	}
 }
 
-void import_ies(struct ast_channel *chan, struct misdn_bchannel *bc)
+void import_ch(struct ast_channel *chan, struct misdn_bchannel *bc, struct chan_list *ch)
 {
 	char *tmp;
-	
-	tmp=pbx_builtin_getvar_helper(chan,"PRI_MODE");
-	if (tmp) bc->mode=atoi(tmp);
-	tmp=pbx_builtin_getvar_helper(chan,"PRI_URATE");
-	if (tmp) bc->urate=atoi(tmp);
-	
-	tmp=pbx_builtin_getvar_helper(chan,"PRI_RATE");
-	if (tmp) bc->rate=atoi(tmp);
-	
-	tmp=pbx_builtin_getvar_helper(chan,"PRI_USER1");
-	if (tmp) bc->user1=atoi(tmp);
-
-	tmp=pbx_builtin_getvar_helper(chan,"PRI_PROGRESS_INDICATOR");
-	if (tmp) bc->progress_indicator=atoi(tmp);
+	tmp=pbx_builtin_getvar_helper(chan,"MISDN_PID");
+	if (tmp) {
+		ch->other_pid=atoi(tmp);
+		chan_misdn_log(1,bc->port,"IMPORT_PID: importing pid:%s\n",tmp);
+
+		if (ch->other_pid >0) {
+			ch->other_ch=find_chan_by_pid(cl_te,ch->other_pid);
+			if (ch->other_ch) ch->other_ch->other_ch=ch;
+		}
+	}
 }
  
-void export_ies(struct ast_channel *chan, struct misdn_bchannel *bc)
+void export_ch(struct ast_channel *chan, struct misdn_bchannel *bc, struct chan_list *ch)
 {
 	char tmp[32];
-	
-	sprintf(tmp,"%d",bc->mode);
-	pbx_builtin_setvar_helper(chan,"_PRI_MODE",tmp);
-	
-	sprintf(tmp,"%d",bc->urate);
-	pbx_builtin_setvar_helper(chan,"_PRI_URATE",tmp);
-	
-	sprintf(tmp,"%d",bc->rate);
-	pbx_builtin_setvar_helper(chan,"_PRI_RATE",tmp);
-	
-	sprintf(tmp,"%d",bc->user1);
-	pbx_builtin_setvar_helper(chan,"_PRI_USER1",tmp);
-
-	sprintf(tmp,"%d",bc->progress_indicator);
-	pbx_builtin_setvar_helper(chan,"_PRI_PROGRESS_INDICATOR",tmp);
+
+	chan_misdn_log(1,bc->port,"EXPORT_PID: pid:%d\n",bc->pid);
+	sprintf(tmp,"%d",bc->pid);
+	pbx_builtin_setvar_helper(chan,"_MISDN_PID",tmp);
 }
 
 
@@ -3046,9 +3074,12 @@
 	
 	if (ch ) {
 		switch (event) {
+		case EVENT_DISCONNECT:
 		case EVENT_RELEASE:
 		case EVENT_RELEASE_COMPLETE:
 		case EVENT_CLEANUP:
+		case EVENT_TIMEOUT:
+			chan_misdn_log(3,bc->port,"ast_hangup already called, so we have no ast ptr anymore in event(%s)\n",manager_isdn_get_info(event));
 			break;
 		default:
 			if ( !ch->ast  || !MISDN_ASTERISK_PVT(ch->ast) || !MISDN_ASTERISK_TECH_PVT(ch->ast)) {
@@ -3247,8 +3278,8 @@
 
 		read_config(ch, ORG_MISDN);
 		
-		export_ies(chan, bc);
-		
+		export_ch(chan, bc, ch);
+
 		ch->ast->rings=1;
 		ast_setstate(ch->ast, AST_STATE_RINGING);
 
@@ -3373,10 +3404,18 @@
 			}
 		} else {
 
-
 			if (bc->sending_complete) {
+				ch->state=MISDN_EXTCANTMATCH;
 				bc->out_cause=1;
-				misdn_lib_send_event(bc, EVENT_RELEASE);
+
+				if (bc->nt)  {
+					chan_misdn_log(0,bc->port," --> sending_complete so we never match ..\n");
+					misdn_lib_send_event(bc, EVENT_RELEASE_COMPLETE);
+				} else {
+					chan_misdn_log(0,bc->port," --> sending_complete so we never match ..\n");
+					misdn_lib_send_event(bc, EVENT_RELEASE);
+				}
+
 			} else {
 				
 				int ret= misdn_lib_send_event(bc, EVENT_SETUP_ACKNOWLEDGE );
@@ -3519,12 +3558,12 @@
 	}
 	break;
 	case EVENT_DISCONNECT:
+	/*we might not have an ch->ast ptr here anymore*/
 	{
-		
 		struct chan_list *holded_ch=find_holded(cl_te, bc);
 		
-		
-		send_cause2ast(ch->ast,bc);
+		if (ch->ast)	
+			send_cause2ast(ch->ast,bc);
 
 
 		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);
@@ -3541,7 +3580,7 @@
 		}
 		
 		/*Check for holded channel, to implement transfer*/
-		if (holded_ch ) {
+		if (holded_ch && ch->ast ) {
 			if  (ch->state == MISDN_CONNECTED ) {
 				misdn_transfer_bc(ch, holded_ch) ;
 				misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE);
@@ -3608,10 +3647,18 @@
 		chan_misdn_log(9,bc->port,"TONE_GEN: len:%d\n");
 
 		if (!ast->generator) break;
-		
+	
+		
+	
 		tmp = ast->generatordata;
 		ast->generatordata = NULL;
 		generate = ast->generator->generate;
+
+		if (tone_len <0 || tone_len > 512 ) {
+			ast_log(LOG_WARNING, "TONE_GEN: len was %d, set to 128\n",tone_len);
+			tone_len=128;
+		}
+
 		res = generate(ast, tmp, tone_len, tone_len);
 		ast->generatordata = tmp;
 		
@@ -3674,18 +3721,26 @@
 	}
 	break;
 	case EVENT_TIMEOUT:
-
-		misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE);
-		break;
 		{
-			switch (ch->state) {
+		switch (ch->state) {
+			case MISDN_WAITING4DIGS:
 			case MISDN_CALLING:
-
-				chan_misdn_log(-1, bc?bc->port:0, "GOT TIMOUT AT CALING pid:%d\n", bc?bc->pid:-1);
-					break;
 			case MISDN_DIALING:
 			case MISDN_PROGRESS:
-				break;
+				
+				if (bc->nt) {
+					bc->progress_indicator=8;
+					tone_indicate(ch, TONE_BUSY);
+				}
+				
+				bc->out_cause=1;
+				misdn_lib_send_event(bc,EVENT_DISCONNECT);
+			break;
+
+			case MISDN_CLEANING: 
+				chan_misdn_log(1,bc->port," --> in state cleaning .. so ingoring, the stack should clean it for us\n");
+			break;
+
 			default:
 				misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE);
 			}
@@ -3769,7 +3824,7 @@
 			
 			if (bridged && MISDN_ASTERISK_TECH_PVT(bridged)) {
 				ch=MISDN_ASTERISK_TECH_PVT(bridged);
-				//ch->state=MISDN_FACILITY_DEFLECTED;
+				/*ch->state=MISDN_FACILITY_DEFLECTED;*/
 				if (ch->bc) {
 					/* todo */
 				}

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=34551&r1=34550&r2=34551&view=diff
==============================================================================
--- team/crichter/0.3.0/channels/misdn/isdn_lib.c (original)
+++ team/crichter/0.3.0/channels/misdn/isdn_lib.c Sat Jun 17 05:32:20 2006
@@ -61,7 +61,7 @@
 	
 	if (stack) {
 		sprintf(buf, "* Stack Addr:%x Port %d Type %s Prot. %s L2Link %s L1Link:%s", stack->upper_id, stack->port, stack->nt?"NT":"TE", stack->ptp?"PTP":"PMP", stack->l2link?"UP":"DOWN", stack->l1link?"UP":"DOWN");
-		
+
 	} else {
 		buf[0]=0;
 	}
@@ -325,7 +325,7 @@
 }
 
 
-static int mypid=0;
+static int mypid=1;
 
 
 int misdn_cap_is_speech(int cap)
@@ -419,6 +419,7 @@
 		{"BCHAN_RELEASE", BCHAN_RELEASE},
 		{"BCHAN_RELEASED", BCHAN_RELEASED},
 		{"BCHAN_CLEAN", BCHAN_CLEAN},
+		{"BCHAN_CLEAN_REQUEST", BCHAN_CLEAN_REQUEST},
 		{"BCHAN_ERROR", BCHAN_ERROR}
 	};
 	
@@ -544,8 +545,13 @@
 
 	bc->holded_bc=NULL;
 	
-	bc_state_change(bc,BCHAN_EMPTY);
-	bc_next_state_change(bc,BCHAN_EMPTY);
+	
+	if (bc->bc_state != BCHAN_SETUP) {
+		bc_state_change(bc,BCHAN_EMPTY);
+		bc_next_state_change(bc,BCHAN_EMPTY);
+	} else {
+		cb_log(-1,bc->port,"Emptying bc(%x) within SETSTACK!\n",bc->addr);
+	}
 }
 
 
@@ -575,6 +581,12 @@
 		
 	case BCHAN_BRIDGED:
 		cb_log(2, stack->port, "$$$ bc still bridged\n");
+		break;
+
+
+	case BCHAN_SETUP:
+		bc_state_change(bc,BCHAN_CLEAN_REQUEST);
+		return -1;
 	default:
 		break;
 	}
@@ -798,7 +810,7 @@
 		ncr.len = 0;
 
 		bc->l3_id = l3_id;
-		if (mypid>5000) mypid=0;
+		if (mypid>5000) mypid=1;
 		bc->pid=mypid++;
       
 		cb_log(3, stack->port, " --> new_l3id %x\n",l3_id);
@@ -831,7 +843,7 @@
 		/* send message */
 
 		bc->l3_id = l3_id;
-		if (mypid>5000) mypid=0;
+		if (mypid>5000) mypid=1;
 		bc->pid=mypid++;
     
 		cb_log(3, stack->port, "--> new_l3id %x\n",l3_id);
@@ -1438,7 +1450,7 @@
 	cb_log(7, stack->port, " --> new_process: New L3Id: %x\n",frm->dinfo);
 	bc->l3_id=frm->dinfo;
 	
-	if (mypid>5000) mypid=0;
+	if (mypid>5000) mypid=1;
 	bc->pid=mypid++;
 	return 0;
 }
@@ -1707,11 +1719,11 @@
 #endif
 		break;
 		
-		case CC_CONNECT|INDICATION:
 		case CC_ALERTING|INDICATION:
 		case CC_PROCEEDING|INDICATION:
 		case CC_SETUP_ACKNOWLEDGE|INDICATION:
-
+			if(!stack->ptp) break;	
+		case CC_CONNECT|INDICATION:
 		{
 			struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo);
 			
@@ -2099,16 +2111,19 @@
 		cb_log(4, stack->port," --> Got Adr %x\n", bc->addr);
 
 		free_msg(msg);
-		
-		if (bc->bc_state !=  BCHAN_SETUP) {
-			cb_log(4, stack->port," --> STATE WASN'T SETUP in SETSTACK|IND\n");
-		}
-		
-		bc_state_change(bc,BCHAN_SETUPED);
-		
-		
-		manager_bchannel_activate(bc);
-				
+	
+		
+		switch(bc->bc_state) {
+		case BCHAN_SETUP:
+			bc_state_change(bc,BCHAN_SETUPED);
+			manager_bchannel_activate(bc);
+		break;
+
+		case BCHAN_CLEAN_REQUEST:
+		default:
+			cb_log(-1, stack->port," --> STATE WASN'T SETUP (but %s) in SETSTACK|IND\n",bc_state2str(bc->bc_state));
+			clean_up_bc(bc);
+		}
 		return 1;
 
 	case MGR_DELLAYER| INDICATION:
@@ -2859,7 +2874,7 @@
 	cb_log(3, stack->port, " --> screen:%d --> pres:%d\n",
 			bc->screen, bc->pres);
 	
-	cb_log(2, stack->port, " --> channel:%d caps:%s pi:%x keypad:%s\n", bc->channel, bearer2str(bc->capability),bc->progress_indicator, bc->keypad);
+	cb_log(2, stack->port, " --> channel:%d caps:%s pi:%x keypad:%s sending_complete:%d\n", bc->channel, bearer2str(bc->capability),bc->progress_indicator, bc->keypad, bc->sending_complete);
 
 	cb_log(3, stack->port, " --> urate:%d rate:%d mode:%d user1:%d\n", bc->urate, bc->rate, bc->mode,bc->user1);
 	
@@ -2907,11 +2922,13 @@
 		}
 		break;
 
-	case EVENT_CONNECT:
 	case EVENT_PROGRESS:
 	case EVENT_ALERTING:
 	case EVENT_PROCEEDING:
 	case EVENT_SETUP_ACKNOWLEDGE:
+		if (!bc->nt && !stack->ptp) break;
+
+	case EVENT_CONNECT:
 	case EVENT_RETRIEVE_ACKNOWLEDGE:
 		if (stack->nt) {
 			if (bc->channel <=0 ) { /*  else we have the channel already */

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=34551&r1=34550&r2=34551&view=diff
==============================================================================
--- team/crichter/0.3.0/channels/misdn/isdn_lib.h (original)
+++ team/crichter/0.3.0/channels/misdn/isdn_lib.h Sat Jun 17 05:32:20 2006
@@ -35,6 +35,7 @@
 	BCHAN_RELEASE,
 	BCHAN_RELEASED,
 	BCHAN_CLEAN,
+	BCHAN_CLEAN_REQUEST,
 	BCHAN_ERROR
 };
 



More information about the asterisk-commits mailing list