[svn-commits] branch crichter/0.3.0 r35240 - in /team/crichter/0.3.0: ./ channels/ channels...

svn-commits at lists.digium.com svn-commits at lists.digium.com
Wed Jun 21 08:19:04 MST 2006


Author: crichter
Date: Wed Jun 21 10:19:03 2006
New Revision: 35240

URL: http://svn.digium.com/view/asterisk?rev=35240&view=rev
Log:
* added support for PID export/import to identify bridging in misdn_call already
* fixed a few inband Alerting issues, sometimes we need to create alerting, sometimes it's inband
* beautified the state debugging of misdn_hangup
* removed "real"  bchannel activating/deactivating in chan_misdn.c
* fixed "round_robin" bug when there's only 1 port
* added more informative prints when channel could not be created
* changed some warnings to notices
* reworked the whole bchannel state machine stuff, 
  it is now like in the examples of mISDNuser and therefore a lot easier, 
  and it is now harder to create bugs
* bchannel_activate/deactivate is now only called in setup/cleanup bc, 
  they may merge sometime
* it is very important to setup/cleanup the bchannels under the correct 
  conditions, especially in the NT Side we can only setup the bchannels 
  when we send a Message! 
  In the TE side we can only setup the bchannel when we received the channel 
  of course



Modified:
    team/crichter/0.3.0/Makefile
    team/crichter/0.3.0/channels/chan_misdn.c
    team/crichter/0.3.0/channels/misdn/isdn_lib.c

Modified: team/crichter/0.3.0/Makefile
URL: http://svn.digium.com/view/asterisk/team/crichter/0.3.0/Makefile?rev=35240&r1=35239&r2=35240&view=diff
==============================================================================
--- team/crichter/0.3.0/Makefile (original)
+++ team/crichter/0.3.0/Makefile Wed Jun 21 10:19:03 2006
@@ -906,13 +906,14 @@
 chan_misdn.so:
 	make -C . SUBDIRS=channels CHANNEL_LIBS=chan_misdn.so
 
-cm-install: chan_misdn.so
+cm-install: cm-clean chan_misdn.so
 	install -m 644 channels/chan_misdn.so /usr/lib/asterisk/modules/
 
 cm-clean:
+	make -C channels/misdn clean
+	
+cm-cleaner: cm-clean
 	rm -f channels/chan_misdn_config.o
 	rm -f channels/chan_misdn.o
 	rm -f channels/chan_misdn.so
 
-cm-cleaner:	cm-clean
-	make -C channels/misdn clean

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=35240&r1=35239&r2=35240&view=diff
==============================================================================
--- team/crichter/0.3.0/channels/chan_misdn.c (original)
+++ team/crichter/0.3.0/channels/chan_misdn.c Wed Jun 21 10:19:03 2006
@@ -121,6 +121,7 @@
 	MISDN_CONNECTED, /*!<  when connected */
 	MISDN_PRECONNECTED, /*!<  when connected */
 	MISDN_DISCONNECTED, /*!<  when connected */
+	MISDN_RELEASED, /*!<  when connected */
 	MISDN_BRIDGED, /*!<  when bridged */
 	MISDN_CLEANING, /*!< when hangup from * but we were connected before */
 	MISDN_HUNGUP_FROM_MISDN, /*!< when DISCONNECT/RELEASE/REL_COMP  cam from misdn */
@@ -631,6 +632,8 @@
 	{MISDN_ALERTING,"ALERTING"}, /*  when Alerting */
 	{MISDN_BUSY,"BUSY"}, /*  when BUSY */
 	{MISDN_CONNECTED,"CONNECTED"}, /*  when connected */
+	{MISDN_DISCONNECTED,"DISCONNECTED"}, /*  when connected */
+	{MISDN_RELEASED,"RELEASED"}, /*  when connected */
 	{MISDN_BRIDGED,"BRIDGED"}, /*  when bridged */
 	{MISDN_CLEANING,"CLEANING"}, /* when hangup from * but we were connected before */
 	{MISDN_HUNGUP_FROM_MISDN,"HUNGUP_FROM_MISDN"}, /* when DISCONNECT/RELEASE/REL_COMP  cam from misdn */
@@ -1802,14 +1805,29 @@
 				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->other_ch && p->other_ch->bc) {
+					if (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->other_ch->bc->nt) {
+						chan_misdn_log(1,p->bc->port, " --> other End is mISDN TE so it has inband info for sure (?)\n");
+						break;
+					}
+#if 0
+					if (p->other_ch->bc->nt) {
+						chan_misdn_log(1,p->bc->port, " --> other End is mISDN NT .. \n");
+						break;
+					}
+#endif
+
 				}
+
 			
 				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 
+				else 
 					 tone_indicate(p, TONE_ALERTING);
 				chan_misdn_log(1, p->bc->port, " --> * SEND: State Ring pid:%d\n",p->bc?p->bc->pid:-1);
 				ast_setstate(ast,AST_STATE_RINGING);
@@ -1868,7 +1886,7 @@
 		chan_misdn_log(1, p->bc->port, " --> *\tUNHOLD pid:%d\n",p->bc?p->bc->pid:-1);
 		break;
 	default:
-		ast_log(LOG_WARNING, " --> * Unknown Indication:%d pid:%d\n",cond,p->bc?p->bc->pid:-1);
+		ast_log(LOG_NOTICE, " --> * Unknown Indication:%d pid:%d\n",cond,p->bc?p->bc->pid:-1);
 	}
   
 	return 0;
@@ -1940,6 +1958,7 @@
 		chan_misdn_log(2, bc->port, " --> l3id:%x\n",p->l3id);
 		chan_misdn_log(1, bc->port, " --> cause:%d\n",bc->cause);
 		chan_misdn_log(1, bc->port, " --> out_cause:%d\n",bc->out_cause);
+		chan_misdn_log(1, bc->port, " --> state:%s\n", misdn_get_ch_state(p));
 		
 		switch (p->state) {
 		case MISDN_CALLING:
@@ -1962,8 +1981,6 @@
 		case MISDN_ALERTING:
 		case MISDN_PROGRESS:
 		case MISDN_PROCEEDING:
-			chan_misdn_log(2, bc->port, " --> * State Alerting\n");
-
 			if (p->orginator != ORG_AST) 
 				tone_indicate(p, TONE_HANGUP);
       
@@ -1972,7 +1989,6 @@
 			break;
 		case MISDN_CONNECTED:
 			/*  Alerting or Disconect */
-			chan_misdn_log(2, bc->port, " --> * State Connected\n");
 			start_bc_tones(p);
 			tone_indicate(p, TONE_HANGUP);
 			misdn_lib_send_event( bc, EVENT_DISCONNECT);
@@ -1980,17 +1996,16 @@
 			p->state=MISDN_CLEANING; /* MISDN_HUNGUP_FROM_AST; */
 			break;
 		case MISDN_DISCONNECTED:
-			chan_misdn_log(2, bc->port, " --> * State Disconnected\n");
 			misdn_lib_send_event( bc, EVENT_RELEASE);
 			p->state=MISDN_CLEANING; /* MISDN_HUNGUP_FROM_AST; */
 			break;
 
+		case MISDN_RELEASED:
 		case MISDN_CLEANING:
 			break;
       
 		case MISDN_HOLD_DISCONNECT:
 			/* need to send release here */
-			chan_misdn_log(2, bc->port, " --> state HOLD_DISC\n");
 			chan_misdn_log(1, bc->port, " --> cause %d\n",bc->cause);
 			chan_misdn_log(1, bc->port, " --> out_cause %d\n",bc->out_cause);
 			
@@ -2260,7 +2275,7 @@
 	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");
+		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);
 		return 0;
@@ -2309,7 +2324,7 @@
 
 static int start_bc_tones(struct chan_list* cl)
 {
-	manager_bchannel_activate(cl->bc);
+/*	manager_bchannel_activate(cl->bc); */
 	misdn_lib_tone_generator_stop(cl->bc);
 	cl->notxtone=0;
 	cl->norxtone=0;
@@ -2318,9 +2333,10 @@
 
 static int stop_bc_tones(struct chan_list *cl)
 {
-	if (cl->bc) {
+/*	if (cl->bc) {
 		manager_bchannel_deactivate(cl->bc);
 	}
+*/
 	cl->notxtone=1;
 	cl->norxtone=1;
 	
@@ -2416,7 +2432,7 @@
 					if (port >= port_start)
 						next_chan = 1;
 					
-					if (port < port_start && next_chan) {
+					if (port <= port_start && next_chan) {
 						if (++robin_channel >= MAX_BCHANS) {
 							robin_channel = 1;
 						}
@@ -2430,13 +2446,17 @@
 						int check;
 						misdn_cfg_get(port, MISDN_CFG_PMP_L1_CHECK, &check, sizeof(int));
 						port_up = misdn_lib_port_up(port, check);
+
+						if (check && !port_up) 
+							chan_misdn_log(1,port,"L1 is not Up on this Port\n");
+						
 						
 						if ( port_up )	{
 							newbc = misdn_lib_get_free_bc(port, robin_channel);
 							if (newbc) {
 								chan_misdn_log(4, port, " Success! Found port:%d channel:%d\n", newbc->port, newbc->channel);
 								if (port_up)
-									chan_misdn_log(4, port, "ortup:%d\n",  port_up);
+									chan_misdn_log(4, port, "portup:%d\n",  port_up);
 								rr->port = newbc->port;
 								rr->channel = newbc->channel;
 								break;
@@ -2481,8 +2501,7 @@
 	}
 	
 	if (!newbc) {
-		chan_misdn_log(-1, 0, " --> ! No free channel chan ext:%s even after Group Call\n",ext);
-		chan_misdn_log(-1, 0, " --> SEND: State Down\n");
+		chan_misdn_log(-1, 0, "Could not create channel on port:%d with extensions:%s\n",port,ext);
 		return NULL;
 	}
 
@@ -3046,7 +3065,7 @@
 		ch=find_chan_by_l3id(cl_te, bc->l3_id);
 	
 	if (event != EVENT_BCHAN_DATA && event != EVENT_TONE_GENERATE) { /*  Debug Only Non-Bchan */
-		chan_misdn_log(1, bc->port, "I IND :%s oad:%s dad:%s\n", manager_isdn_get_info(event), bc->oad, bc->dad);
+		chan_misdn_log(1, bc->port, "I IND :%s oad:%s dad:%s pid:%d\n", manager_isdn_get_info(event), bc->oad, bc->dad, bc->pid);
 		misdn_lib_log_ies(bc);
 		chan_misdn_log(2,bc->port," --> bc_state:%s\n",bc_state2str(bc->bc_state));
 	}
@@ -3054,7 +3073,7 @@
 	if (event != EVENT_SETUP) {
 		if (!ch) {
 			if (event != EVENT_CLEANUP )
-				ast_log(LOG_WARNING, "Chan not existing at the moment bc->l3id:%x bc:%p event:%s port:%d channel:%d\n",bc->l3_id, bc, manager_isdn_get_info( event), bc->port,bc->channel);
+				ast_log(LOG_NOTICE, "Chan not existing at the moment bc->l3id:%x bc:%p event:%s port:%d channel:%d\n",bc->l3_id, bc, manager_isdn_get_info( event), bc->port,bc->channel);
 			return -1;
 		}
 	}
@@ -3066,12 +3085,13 @@
 		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));
+			if (!ch->ast)
+				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)) {
 				if (event!=EVENT_BCHAN_DATA)
-					ast_log(LOG_WARNING, "No Ast or No private Pointer in Event (%d:%s)\n", event, manager_isdn_get_info(event));
+					ast_log(LOG_NOTICE, "No Ast or No private Pointer in Event (%d:%s)\n", event, manager_isdn_get_info(event));
 				return -1;
 			}
 		}
@@ -3561,7 +3581,7 @@
 			   alternative number, then play it instead of
 			   immediately releasing the call */
 			chan_misdn_log(0,bc->port, " --> Inband Info Avail, not sending RELEASE\n");
-			ch->state = MISDN_DISCONNECTED;
+			ch->state=MISDN_DISCONNECTED;
 			start_bc_tones(ch);
 			break;
 		}
@@ -3586,6 +3606,9 @@
 		*/
 		
 		misdn_lib_send_event(bc,EVENT_RELEASE);
+
+		if (ch->state == MISDN_CONNECTED)
+			ch->state=MISDN_RELEASED;
 	}
 	break;
 	
@@ -3612,7 +3635,10 @@
 			/*stop_bc_tones(ch);
 			  release_chan(bc);*/
 			
+			if (!bc->nt) release_chan(bc);
+			
 			misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE);
+
 		}
 		break;
 	case EVENT_RELEASE_COMPLETE:
@@ -3642,7 +3668,7 @@
 		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);
+			ast_log(LOG_NOTICE, "TONE_GEN: len was %d, set to 128\n",tone_len);
 			tone_len=128;
 		}
 
@@ -3837,7 +3863,7 @@
 		break;
 				
 	default:
-		ast_log(LOG_WARNING, "Got Unknown Event\n");
+		ast_log(LOG_NOTICE, "Got Unknown Event\n");
 		break;
 	}
 	

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=35240&r1=35239&r2=35240&view=diff
==============================================================================
--- team/crichter/0.3.0/channels/misdn/isdn_lib.c (original)
+++ team/crichter/0.3.0/channels/misdn/isdn_lib.c Wed Jun 21 10:19:03 2006
@@ -359,7 +359,7 @@
 	int i;
 
 	for (i=0; i <stack->b_num; i++) {
-		cb_log(8, stack->port, "Idx:%d stack->cchan:%d Chan:%d\n",i,stack->channels[i], i+1);
+		cb_log(6, stack->port, "Idx:%d stack->cchan:%d Chan:%d\n",i,stack->channels[i], i+1);
 	}
 }
 
@@ -544,14 +544,6 @@
 	bc->te_choose_channel = 0;
 
 	bc->holded_bc=NULL;
-	
-	
-	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);
-	}
 }
 
 
@@ -561,7 +553,7 @@
 	unsigned char buff[32];
 	struct misdn_stack * stack;
 
-	cb_log(3, 0, "$$$ CLEANUP CALLED\n");
+	cb_log(3, bc?bc->port:0, "$$$ CLEANUP CALLED pid:%d\n", bc?bc->pid:-1);
 	
 	if (!bc  ) return -1;
 	stack=get_stack_by_bc(bc);
@@ -569,44 +561,27 @@
 	if (!stack) return -1;
 	
 	switch (bc->bc_state ) {
-		
 	case BCHAN_CLEANED:
 		cb_log(5, stack->port, "$$$ Already cleaned up bc with stid :%x\n", bc->b_stid);
 		return -1;
 		
-	case BCHAN_ACTIVATED:
-		cb_log(2, stack->port, "$$$ bc still active, deactivatiing .. stid :%x\n", bc->b_stid);
-		manager_bchannel_deactivate(bc);
-		break;
-		
-	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;
 	}
 	
-	cb_log(5, stack->port, "$$$ Cleaning up bc with stid :%x\n", bc->b_stid);
-	
+	cb_log(2, stack->port, "$$$ Cleaning up bc with stid :%x pid:%d\n", bc->b_stid, bc->pid);
+	
+	manager_bchannel_deactivate(bc);
+
 	if ( misdn_cap_is_speech(bc->capability) && bc->ec_enable) {
 		manager_ec_disable(bc);
 	}
 
-	
-	mISDN_write_frame(stack->midev, buff, bc->layer_id|FLG_MSG_DOWN, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
-
-#if 0
-	cb_log(3, stack->port, "$$$ CLEARING STACK\n");
-	ret=mISDN_clear_stack(stack->midev,bc->b_stid);
-	if (ret<0 && errno) {
-		cb_log(-1,stack->port,"clear stack failed [%s]\n",strerror(errno));
-	}
-#endif
+	mISDN_write_frame(stack->midev, buff, bc->layer_id|FLG_MSG_TARGET|FLG_MSG_DOWN, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
+	
+	/*mISDN_clear_stack(stack->midev, bc->b_stid);*/
+
+	
 
 	bc->b_stid = 0;
 	bc_state_change(bc, BCHAN_CLEANED);
@@ -881,9 +856,12 @@
 	int b_stid=stack->b_stids[channel>=0?channel:0];
 
 
-	if ( bc->bc_state != BCHAN_CLEANED) {
-		cb_log(4, stack->port, "$$$ bc already upsetted stid :%x (state:%s)\n", b_stid, bc_state2str(bc->bc_state) );
-		return -1;
+	switch (bc->bc_state) {
+		case BCHAN_CLEANED:
+			break;
+		default:
+			cb_log(4, stack->port, "$$$ bc already upsetted stid :%x (state:%s)\n", b_stid, bc_state2str(bc->bc_state) );
+			return -1;
 	}
 	
 	cb_log(5, stack->port, "$$$ Setting up bc with stid :%x\n", b_stid);
@@ -994,9 +972,32 @@
 		return(-EINVAL);
 	}
 
-	bc_state_change(bc,BCHAN_SETUP);
-
-	
+
+	ret = mISDN_get_setstack_ind(midev, bc->layer_id);
+
+	if (ret) {
+		cb_log(-1, stack->port,"$$$ Set StackIND Err: %d %s\n",ret,strerror(errno));
+		mISDN_write_frame(midev, buff, bc->layer_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
+		
+		bc_state_change(bc,BCHAN_ERROR);
+		return(-EINVAL);
+	}
+
+	ret = mISDN_get_layerid(midev, bc->b_stid, bc->layer) ;
+
+	bc->addr = ret>0? ret : 0;
+
+	if (!bc->addr) {
+		cb_log(-1, stack->port,"$$$ Get Layerid Err: %d %s\n",ret,strerror(errno));
+		mISDN_write_frame(midev, buff, bc->layer_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
+		
+		bc_state_change(bc,BCHAN_ERROR);
+	}
+
+	manager_bchannel_activate(bc);
+	
+	bc_state_change(bc,BCHAN_ACTIVATED);
+
 	return 0;
 }
 
@@ -1384,15 +1385,14 @@
 		switch (event) {
 
 		case EVENT_CONNECT_ACKNOWLEDGE:
-			
+#if 0
 			if ( !misdn_cap_is_speech(bc->capability)) {
 				int ret=setup_bc(bc);
 				if (ret == -EINVAL){
 					cb_log(-1,bc->port,"send_event: setup_bc failed\n");
 				}
 			}
-			
-			manager_bchannel_activate(bc);
+#endif	
 			break;
 		case EVENT_CONNECT:
 
@@ -1400,14 +1400,14 @@
 				cb_log(4, stack->port, "ENABLING BLOWFISH channel:%d oad%d:%s dad%d:%s\n", bc->channel, bc->onumplan,bc->oad, bc->dnumplan,bc->dad);
 				manager_ph_control_block(bc,  BF_ENABLE_KEY, bc->crypt_key, strlen(bc->crypt_key) );
 			}
-		case EVENT_SETUP:
-			if (bc->channel>0 && bc->channel<255)
-				set_chan_in_stack(stack, bc->channel);
-			break;
 		case EVENT_ALERTING:
 		case EVENT_PROGRESS:
 		case EVENT_PROCEEDING:
 		case EVENT_SETUP_ACKNOWLEDGE:
+
+		setup_bc(bc);
+		
+		case EVENT_SETUP:
 			
 		{
 			if (bc->channel == 0xff) {
@@ -1416,17 +1416,23 @@
 					cb_log(-1, stack->port, "Any Channel Requested, but we have no more!!\n");
 					break;
 				}
-			} 
-			
-			if (!stack->nt) {
-				int ret=setup_bc(bc);
-				if (ret == -EINVAL){
-					cb_log(-1,bc->port,"handle_event: setup_bc failed\n");
-					misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE);
-				}
-			}
-		}
-		
+			}  	
+#if 0
+			int ret=setup_bc(bc);
+			if (ret == -EINVAL){
+				cb_log(-1,bc->port,"handle_event: setup_bc failed\n");
+				misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE);
+			}
+#endif
+		}
+		break;
+
+		case EVENT_RELEASE_COMPLETE:
+		case EVENT_RELEASE:
+			empty_chan_in_stack(stack,bc->channel);
+			empty_bc(bc);
+			clean_up_bc(bc);
+			break;
 		default:
 			break;
 		}
@@ -1492,11 +1498,10 @@
 				empty_chan_in_stack(stack,bc->channel);
 				empty_bc(bc);
 				
-				bc_state_change(bc, BCHAN_EMPTY);
-
 				clean_up_bc(bc);
+				
 				dump_chan_list(stack);
-				bc->pid = 0;
+				/*bc->pid = 0;*/
 				cb_event(EVENT_CLEANUP, bc, glob_mgr->user_data);
 				if (bc->stack_holder) {
 					cb_log(4,stack->port, "REMOVEING Holder\n");
@@ -1715,8 +1720,6 @@
 						
 					}
 				}
-				
-				manager_bchannel_activate(bc);
 			}
 		}
 #endif
@@ -1728,6 +1731,7 @@
 			if(!stack->ptp) break;	
 		case CC_CONNECT|INDICATION:
 		{
+#if 0
 			struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo);
 			
 			if (!bc) {
@@ -1746,6 +1750,7 @@
 				cb_log(-1,bc->port,"handle_event_nt: setup_bc failed\n");
 				misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE);
 			}
+#endif
 		}
 		break;
 		case CC_DISCONNECT|INDICATION:
@@ -1864,6 +1869,7 @@
 		}
 		break;
 
+
 		case DL_RELEASE | INDICATION:
 		case DL_RELEASE | CONFIRM:
 		{
@@ -1896,6 +1902,45 @@
 		}
 		if (bc ) {
 			isdn_msg_parse_event(msgs_g,msg,bc, 1);
+
+			switch (event) {
+				case EVENT_SETUP:
+					if (bc->channel>0 && bc->channel<255) {
+
+						if (stack->ptp) 
+							set_chan_in_stack(stack, bc->channel);
+						else 
+							cb_log(-1,stack->port," --> PTMP but channel requested\n");
+
+					} else {
+
+						bc->channel = find_free_chan_in_stack(stack, 0);
+						if (!bc->channel) {
+							cb_log(-1, stack->port, " No free channel at the moment\n");
+					
+							msg_t *dmsg;
+				
+							cb_log(-1, stack->port, "Releaseing call %x (No free Chan for you..)\n", hh->dinfo);
+								dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST,MT_RELEASE_COMPLETE, hh->dinfo,sizeof(RELEASE_COMPLETE_t), 1);
+							stack->nst.manager_l3(&stack->nst, dmsg);
+							free_msg(msg);
+							return 0;
+						}
+						
+					}
+#if 0
+					setup_bc(bc);
+#endif
+
+					break;
+				case EVENT_RELEASE:
+				case EVENT_RELEASE_COMPLETE:
+					clean_up_bc(bc);
+					break;
+
+				default:
+				break;
+			}
 			
 			if(!isdn_get_info(msgs_g,event,1)) {
 				cb_log(4, stack->port, "Unknown Event Ind: prim %x dinfo %x\n",hh->prim, hh->dinfo);
@@ -2067,9 +2112,9 @@
 int handle_bchan(msg_t *msg)
 {
 	iframe_t *frm= (iframe_t*)msg->data;
-	struct misdn_bchannel *bc;
-
-	bc=find_bc_by_addr(frm->addr);
+
+
+	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);
@@ -2086,12 +2131,13 @@
 	switch (frm->prim) {
 
 	case MGR_SETSTACK| CONFIRM:
-		cb_log(2, stack->port, "BCHAN: MGR_SETSTACK|CONFIRM \n");
+		cb_log(2, stack->port, "BCHAN: MGR_SETSTACK|CONFIRM pid:%d\n",bc->pid);
 		break;
 		
 	case MGR_SETSTACK| INDICATION:
-		cb_log(2, stack->port, "BCHAN: MGR_SETSTACK|IND \n");
-		
+		cb_log(2, stack->port, "BCHAN: MGR_SETSTACK|IND pid:%d\n",bc->pid);
+	break;
+#if 0
 	AGAIN:
 		bc->addr = mISDN_get_layerid(stack->midev, bc->b_stid, bc->layer);
 		if (!bc->addr) {
@@ -2119,60 +2165,71 @@
 		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));
+			cb_log(-1, stack->port," --> STATE WASN'T SETUP (but %s) in SETSTACK|IND pid:%d\n",bc_state2str(bc->bc_state), bc->pid);
 			clean_up_bc(bc);
 		}
 		return 1;
+#endif
 
 	case MGR_DELLAYER| INDICATION:
-		cb_log(2, stack->port, "BCHAN: MGR_DELLAYER|IND\n");
+		cb_log(2, stack->port, "BCHAN: MGR_DELLAYER|IND pid:%d\n",bc->pid);
 		break;
 		
 	case MGR_DELLAYER| CONFIRM:
-		cb_log(2, stack->port, "BCHAN: MGR_DELLAYER|CNF \n");
-		
-		bc_state_change(bc,BCHAN_CLEANED);
+		cb_log(2, stack->port, "BCHAN: MGR_DELLAYER|CNF pid:%d\n",bc->pid);
+		
+		bc->pid=0;
+		bc->addr=0;
 		
 		free_msg(msg);
 		return 1;
 		
 	case PH_ACTIVATE | INDICATION:
 	case DL_ESTABLISH | INDICATION:
-		cb_log(4, stack->port, "BCHAN: ACT Ind\n");
-
-		bc_state_change(bc,BCHAN_ACTIVATED);
-		
+		cb_log(2, stack->port, "BCHAN: ACT Ind pid:%d\n", bc->pid);
+
 		free_msg(msg);
 		return 1;    
 
 	case PH_ACTIVATE | CONFIRM:
 	case DL_ESTABLISH | CONFIRM:
 		
-		bc_state_change(bc,BCHAN_ACTIVATED);
-		
-		cb_log(4, stack->port, "BCHAN: bchan ACT Confirm\n");
+		cb_log(2, stack->port, "BCHAN: bchan ACT Confirm pid:%d\n",bc->pid);
 		free_msg(msg);
 		
 		return 1;    
+
+	case DL_ESTABLISH | REQUEST:
+		{
+			char buf[128];
+			mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_TARGET | FLG_MSG_DOWN,  DL_ESTABLISH | CONFIRM, 0,0, NULL, TIMEOUT_1SEC);
+		}
+		free_msg(msg);
+		return 1;
+
+	case DL_RELEASE|REQUEST:
+		{
+			char buf[128];
+			mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_TARGET | FLG_MSG_DOWN,  DL_RELEASE| CONFIRM, 0,0, NULL, TIMEOUT_1SEC);
+		}
+		free_msg(msg);
+		return 1;
 		
 	case PH_DEACTIVATE | INDICATION:
 	case DL_RELEASE | INDICATION:
-		cb_log (4, stack->port, "BCHAN: DeACT Ind\n");
-		
-		bc_state_change(bc,BCHAN_RELEASED);
+		cb_log (2, stack->port, "BCHAN: DeACT Ind pid:%d\n",bc->pid);
+		
 		free_msg(msg);
 		return 1;
     
 	case PH_DEACTIVATE | CONFIRM:
 	case DL_RELEASE | CONFIRM:
-		cb_log(4, stack->port, "BCHAN: DeACT Conf\n");
-		
-		bc_state_change(bc,BCHAN_RELEASED);
+		cb_log(4, stack->port, "BCHAN: DeACT Conf pid:%d\n",bc->pid);
+		
 		free_msg(msg);
 		return 1;
     
@@ -2638,13 +2695,14 @@
 {
 	msg_t *msg=alloc_msg(MAX_MSG_SIZE);
 	int r;
-	fd_set rdfs;
+/*	fd_set rdfs; */
 
 	if (!msg) {
 		cb_log(-1, 0, "fetch_msg: alloc msg failed !!");
 		return NULL;
 	}
-	
+
+#if 0
 	FD_ZERO(&rdfs);
 	FD_SET(midev,&rdfs);
   
@@ -2652,14 +2710,15 @@
 	//select(FD_SETSIZE, &rdfs, NULL, NULL, NULL);
   
 	if (FD_ISSET(midev, &rdfs)) {
+#endif
 
 	AGAIN:
-		r=mISDN_read(midev,msg->data,MAX_MSG_SIZE, 5000);
+		r=mISDN_read(midev,msg->data,MAX_MSG_SIZE, TIMEOUT_10SEC);
 		msg->len=r;
     
 		if (r==0) {
 			free_msg(msg); /* danger, cauz usualy freeing in main_loop */
-			printf ("Got empty Msg?\n");
+			cb_log(6,0,"Got empty Msg..\n");
 			return NULL;
 		}
 
@@ -2675,9 +2734,12 @@
 		}
 
 		return msg;
+
+#if 0
 	} else {
 		printf ("Select timeout\n");
 	}
+#endif
   
 	return NULL;
 }
@@ -2805,8 +2867,10 @@
 	struct misdn_stack *stack;
 	int i;
 	
-	if (channel < 0 || channel > MAX_BCHANS)
+	if (channel < 0 || channel > MAX_BCHANS) {
+		cb_log(-1,port,"Requested channel out of bounds (%d)\n",channel);
 		return NULL;
+	}
 
 	for (stack=glob_mgr->stack_list; stack; stack=stack->next) {
     
@@ -2815,11 +2879,14 @@
 				if (channel <= stack->b_num) {
 					for (i = 0; i < stack->b_num; i++) {
 						if (stack->bc[i].in_use && stack->bc[i].channel == channel) {
+							cb_log(-1,port,"Requested channel:%d on port:%d is already in use\n",channel, port);
 							return NULL;
 						}
 					}
-				} else
+				} else {
+					cb_log(-1,port,"Requested channel:%d is out of bounds on port:%d\n",channel, port);
 					return NULL;
+				}
 			}
 			for (i = 0; i < stack->b_num; i++) {
 				if (!stack->bc[i].in_use) {
@@ -2829,9 +2896,13 @@
 					return &stack->bc[i];
 				}
 			}
+
+			cb_log(-1,port,"There is no free channel on port (%d)\n",port);
 			return NULL;
 		}
 	}
+
+	cb_log(-1,port,"Port is not configured (%d)\n",port);
 	return NULL;
 }
 
@@ -2891,6 +2962,7 @@
 {
 	msg_t *msg; 
 	int err = -1 ;
+	int ret=0;
   
 	if (!bc) goto ERR; 
 	
@@ -2911,7 +2983,7 @@
 		return 0;
 	}
 	
-	cb_log(1, stack->port, "I SEND:%s oad:%s dad:%s \n", isdn_get_info(msgs_g, event, 0), bc->oad, bc->dad);
+	cb_log(1, stack->port, "I SEND:%s oad:%s dad:%s pid:%d\n", isdn_get_info(msgs_g, event, 0), bc->oad, bc->dad, bc->pid);
 	cb_log(1, stack->port, " --> bc_state:%s\n",bc_state2str(bc->bc_state));
 	misdn_lib_log_ies(bc);
 	
@@ -2923,6 +2995,12 @@
 			err=-ENOCHAN;
 			goto ERR;
 		}
+#if 0
+		ret=setup_bc(bc);
+		if (ret == -EINVAL) {
+			cb_log(-1,bc->port,"send_event: setup_bc failed\n");
+		}
+#endif
 		break;
 
 	case EVENT_PROGRESS:
@@ -2946,13 +3024,10 @@
 			/* Its that i generate channels */
 		}
 		
-		if ( bc->nt || misdn_cap_is_speech(bc->capability)) {
-			int ret=setup_bc(bc);
-			if (ret == -EINVAL){
-				cb_log(-1,bc->port,"send_event: setup_bc failed\n");
-				
-			}
-		} 
+		ret=setup_bc(bc);
+		if (ret == -EINVAL) {
+			cb_log(-1,bc->port,"send_event: setup_bc failed\n");
+		}
 		
 		if ( (event == EVENT_CONNECT ) && misdn_cap_is_speech(bc->capability) ) {
 			if ( *bc->crypt_key ) {
@@ -2978,7 +3053,7 @@
 		}
 		
 		if (event == EVENT_RETRIEVE_ACKNOWLEDGE) {
-			manager_bchannel_activate(bc);
+			cb_log(0,bc->port,"DO WE NEED TO DO SOMETHING HERE WITH THE BC ?\n");
 		}
 		break;
 
@@ -2993,8 +3068,6 @@
 			if (bc->bc_state == BCHAN_BRIDGED) {
 				misdn_split_conf(bc,bc->conf_id);
 				misdn_split_conf(bc->holded_bc,bc->holded_bc->conf_id);
-				/*bc_state_change(bc,BCHAN_SETUPED);
-				manager_bchannel_activate(bc);*/
 			}
 
 			empty_chan_in_stack(stack,bc->channel);
@@ -3012,13 +3085,21 @@
 	break;
 	
 	case EVENT_RELEASE:
-		break;
-		
 	case EVENT_RELEASE_COMPLETE:
 		/*we do the cleanup in EVENT_CLEANUP*/
+		/*clean_up_bc(bc);*/
 		break;
     
 	case EVENT_CONNECT_ACKNOWLEDGE:
+
+		if ( bc->nt || misdn_cap_is_speech(bc->capability)) {
+			int ret=setup_bc(bc);
+			if (ret == -EINVAL){
+				cb_log(-1,bc->port,"send_event: setup_bc failed\n");
+				
+			}
+		}
+	
 		
 		if (misdn_cap_is_speech(bc->capability)) {
 			if (  !bc->nodsp) manager_ph_control(bc,  DTMF_TONE_START, 0);
@@ -3434,7 +3515,7 @@
 				} else {
 					iframe_t *frm = (iframe_t *)msg->data;
 					struct misdn_bchannel *bc = find_bc_by_l3id(stack, frm->dinfo);
-					cb_log(0,stack->port,"Sending msg, prim:%x addr:%x dinfo:%x\n",frm->prim,frm->addr,frm->dinfo);
+					cb_log(4,stack->port,"Sending msg, prim:%x addr:%x dinfo:%x\n",frm->prim,frm->addr,frm->dinfo);
 					if (bc) send_msg(glob_mgr->midev, bc, msg);
 				}
 			}
@@ -3623,9 +3704,10 @@
 
 void manager_bchannel_activate(struct misdn_bchannel *bc)
 {
-	msg_t *msg=alloc_msg(MAX_MSG_SIZE);
-	iframe_t *frm;
-	
+	char buf[128];
+	iframe_t *ifrm;
+	int ret;
+
 	struct misdn_stack *stack=get_stack_by_bc(bc);
 
 	if (!stack) {
@@ -3633,43 +3715,23 @@
 		return ;
 	}
 	
-	if (!msg) {
-		cb_log(-1, stack->port, "bchannel_activate: alloc_msg failed !");
-
-		return ;
-	}
-
-
-	switch (bc->bc_state) {
-
-	case BCHAN_SETUPED:
-		break;
-		
-	default:
-		cb_log(1, stack->port, "bchannel_activate: BC Not properly upsetted (state:%s) addr:%x\n", bc_state2str(bc->bc_state), bc->addr);
-
-		
-		return;
-	}
-	
-
-	
-	frm=(iframe_t*)msg->data;
 	/* we must activate if we are deactivated */
 	clear_ibuffer(bc->astbuf);
 	
 	cb_log(5, stack->port, "$$$ Bchan Activated addr %x\n", bc->addr);
 	
-	/* activate bchannel */
-	frm->prim = DL_ESTABLISH | REQUEST;
-	frm->addr = bc->addr | FLG_MSG_DOWN ;
-	frm->dinfo = 0;
-	frm->len = 0;
-	
-	msg_queue_tail(&glob_mgr->activatequeue, msg);
-	sem_post(&glob_mgr->new_msg);
-	
-	bc_state_change(bc, BCHAN_ACTIVE);
+	mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_DOWN,  DL_ESTABLISH | REQUEST, 0,0, NULL, TIMEOUT_1SEC);
+
+	ret=mISDN_read(stack->midev,buf,128,TIMEOUT_10SEC);
+
+	ifrm=(iframe_t*)buf;
+	
+	if (ret>0) {
+		if (ifrm->prim== (DL_ESTABLISH|CONFIRM)) {
+			cb_log(2,stack->port,"bchan: DL_ESTABLISH|CNF\n");
+		}
+	}
+	
 	
 	return ;
   
@@ -3704,7 +3766,7 @@
 	dact.dinfo = 0;
 	dact.len = 0;
 	char buf[128];	
-	mISDN_write_frame(stack->midev, buf, bc->addr| FLG_MSG_DOWN, DL_RELEASE|REQUEST,0,0,NULL, TIMEOUT_1SEC);
+	mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_DOWN, DL_RELEASE|REQUEST,0,0,NULL, TIMEOUT_1SEC);
 
 	mISDN_read(stack->midev, buf, 128, TIMEOUT_1SEC);
 
@@ -3908,6 +3970,16 @@
 		manager_ph_control(bc, TONE_PATT_OFF, TONE_GERMAN_HANGUP);	
 	}
 
+	char buf[mISDN_HEADER_LEN+128];
+	iframe_t *frm=(iframe_t*)buf;
+	memset(buf,0,mISDN_HEADER_LEN+128);
+
+	frm->prim=DL_DATA|REQUEST;
+	frm->addr=bc->addr|FLG_MSG_DOWN;
+	frm->dinfo=0;
+	frm->len=128;
+	
+	mISDN_write(glob_mgr->midev, frm, mISDN_HEADER_LEN+frm->len, TIMEOUT_1SEC);
 }
 
 



More information about the svn-commits mailing list