| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Chan_Misdn -- Channel Driver for Asterisk | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Interface to mISDN | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (C) 2004, Christian Richter | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Christian Richter <crich@beronet.com> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software, distributed under the terms of | 
					
						
							|  |  |  |  * the GNU General Public License | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | /*! \file
 | 
					
						
							| 
									
										
										
										
											2008-02-15 17:29:08 +00:00
										 |  |  |  * \brief Interface to mISDN | 
					
						
							| 
									
										
										
										
											2007-12-11 22:20:22 +00:00
										 |  |  |  * \author Christian Richter <crich@beronet.com> | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <syslog.h>
 | 
					
						
							| 
									
										
										
										
											2008-06-02 08:46:23 +00:00
										 |  |  | #include <sys/time.h>
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | #include <mISDNuser/isdn_debug.h>
 | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | #include "isdn_lib_intern.h"
 | 
					
						
							|  |  |  | #include "isdn_lib.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | enum event_response_e (*cb_event)(enum event_e event, struct misdn_bchannel *bc, void *user_data); | 
					
						
							| 
									
										
										
										
											2008-10-30 16:49:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | void (*cb_log)(int level, int port, char *tmpl, ...) | 
					
						
							| 
									
										
										
										
											2008-10-30 16:49:02 +00:00
										 |  |  | 	__attribute__ ((format (printf, 3, 4))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int (*cb_jb_empty)(struct misdn_bchannel *bc, char *buffer, int len); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  |  * Define ARRAY_LEN() because I cannot | 
					
						
							|  |  |  |  * #include "asterisk/utils.h" | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #define ARRAY_LEN(a) (sizeof(a) / sizeof(a[0]))
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "asterisk/causes.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | void misdn_join_conf(struct misdn_bchannel *bc, int conf_id); | 
					
						
							|  |  |  | void misdn_split_conf(struct misdn_bchannel *bc, int conf_id); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-05-23 12:38:06 +00:00
										 |  |  | int queue_cleanup_bc(struct misdn_bchannel *bc) ; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-29 20:12:19 +00:00
										 |  |  | int misdn_lib_get_l2_up(struct misdn_stack *stack); | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | struct misdn_stack *get_misdn_stack(void); | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-07 09:09:17 +00:00
										 |  |  | int misdn_lib_port_is_pri(int port) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct misdn_stack *stack=get_misdn_stack(); | 
					
						
							|  |  |  | 	for ( ; stack; stack=stack->next) { | 
					
						
							|  |  |  | 		if (stack->port == port) { | 
					
						
							|  |  |  | 			return stack->pri; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-07 09:09:17 +00:00
										 |  |  | 	return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-10-22 10:04:04 +00:00
										 |  |  | int misdn_lib_port_is_nt(int port) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct misdn_stack *stack=get_misdn_stack(); | 
					
						
							|  |  |  | 	for ( ; stack; stack=stack->next) { | 
					
						
							|  |  |  | 		if (stack->port == port) { | 
					
						
							|  |  |  | 			return stack->nt; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-10-22 10:04:04 +00:00
										 |  |  | 	return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | void misdn_make_dummy(struct misdn_bchannel *dummybc, int port, int l3id, int nt, int channel) | 
					
						
							| 
									
										
										
										
											2007-07-02 09:23:08 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	memset (dummybc,0,sizeof(struct misdn_bchannel)); | 
					
						
							|  |  |  | 	dummybc->port=port; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 	if (l3id==0) | 
					
						
							| 
									
										
										
										
											2007-10-22 10:04:04 +00:00
										 |  |  | 		dummybc->l3_id = MISDN_ID_DUMMY; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		dummybc->l3_id=l3id; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-02 09:23:08 +00:00
										 |  |  | 	dummybc->nt=nt; | 
					
						
							|  |  |  | 	dummybc->dummy=1; | 
					
						
							|  |  |  | 	dummybc->channel=channel; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | int misdn_lib_port_block(int port) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct misdn_stack *stack=get_misdn_stack(); | 
					
						
							|  |  |  | 	for ( ; stack; stack=stack->next) { | 
					
						
							|  |  |  | 		if (stack->port == port) { | 
					
						
							|  |  |  | 			stack->blocked=1; | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int misdn_lib_port_unblock(int port) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct misdn_stack *stack=get_misdn_stack(); | 
					
						
							|  |  |  | 	for ( ; stack; stack=stack->next) { | 
					
						
							|  |  |  | 		if (stack->port == port) { | 
					
						
							|  |  |  | 			stack->blocked=0; | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | int misdn_lib_is_port_blocked(int port) | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | 	struct misdn_stack *stack=get_misdn_stack(); | 
					
						
							|  |  |  | 	for ( ; stack; stack=stack->next) { | 
					
						
							|  |  |  | 		if (stack->port == port) { | 
					
						
							|  |  |  | 			return stack->blocked; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | int misdn_lib_is_ptp(int port) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct misdn_stack *stack=get_misdn_stack(); | 
					
						
							|  |  |  | 	for ( ; stack; stack=stack->next) { | 
					
						
							|  |  |  | 		if (stack->port == port) return stack->ptp; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | int misdn_lib_get_maxchans(int port) | 
					
						
							| 
									
										
										
										
											2006-06-26 17:37:11 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct misdn_stack *stack=get_misdn_stack(); | 
					
						
							|  |  |  | 	for ( ; stack; stack=stack->next) { | 
					
						
							|  |  |  | 		if (stack->port == port) { | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 			if (stack->pri) | 
					
						
							| 
									
										
										
										
											2006-06-26 17:37:11 +00:00
										 |  |  | 				return 30; | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				return 2; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | struct misdn_stack *get_stack_by_bc(struct misdn_bchannel *bc) | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 	struct misdn_stack *stack = get_misdn_stack(); | 
					
						
							| 
									
										
										
										
											2005-11-15 20:20:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 	if (!bc) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 	for ( ; stack; stack = stack->next) { | 
					
						
							|  |  |  | 		if (bc->port == stack->port) | 
					
						
							|  |  |  | 			return stack; | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void get_show_stack_details(int port, char *buf) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-04-03 22:41:46 +00:00
										 |  |  | 	struct misdn_stack *stack = get_misdn_stack(); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-03 22:41:46 +00:00
										 |  |  | 	for (; stack; stack = stack->next) { | 
					
						
							|  |  |  | 		if (stack->port == port) { | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	if (stack) { | 
					
						
							| 
									
										
										
										
											2009-04-03 22:41:46 +00:00
										 |  |  | 		sprintf(buf, "* Port %2d Type %s Prot. %s L2Link %s L1Link:%s Blocked:%d", | 
					
						
							|  |  |  | 			stack->port, | 
					
						
							|  |  |  | 			stack->nt ? "NT" : "TE", | 
					
						
							|  |  |  | 			stack->ptp ? "PTP" : "PMP", | 
					
						
							|  |  |  | 			stack->l2link ? "UP  " : "DOWN", | 
					
						
							|  |  |  | 			stack->l1link ? "UP  " : "DOWN", | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 			stack->blocked); | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2009-04-03 22:41:46 +00:00
										 |  |  | 		buf[0] = 0; | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | static int nt_err_cnt =0 ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | enum global_states { | 
					
						
							|  |  |  | 	MISDN_INITIALIZING, | 
					
						
							|  |  |  | 	MISDN_INITIALIZED | 
					
						
							|  |  |  | } ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static enum global_states  global_state=MISDN_INITIALIZING; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | #include <mISDNuser/net_l2.h>
 | 
					
						
							|  |  |  | #include <mISDNuser/tone.h>
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | #include <unistd.h>
 | 
					
						
							|  |  |  | #include <semaphore.h>
 | 
					
						
							|  |  |  | #include <pthread.h>
 | 
					
						
							|  |  |  | #include <signal.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "isdn_lib.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct misdn_lib { | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 	/*! \brief mISDN device handle returned by mISDN_open() */ | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	int midev; | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 	int midev_nt;	/* Not used */ | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	pthread_t event_thread; | 
					
						
							|  |  |  | 	pthread_t event_handler_thread; | 
					
						
							| 
									
										
										
										
											2006-05-23 19:40:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	void *user_data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	msg_queue_t upqueue; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 	msg_queue_t activatequeue; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	sem_t new_msg; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	struct misdn_stack *stack_list; | 
					
						
							|  |  |  | } ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef ECHOCAN_ON
 | 
					
						
							|  |  |  | #define ECHOCAN_ON 123
 | 
					
						
							|  |  |  | #define ECHOCAN_OFF 124
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define MISDN_DEBUG 0
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | void misdn_tx_jitter(struct misdn_bchannel *bc, int len); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | struct misdn_bchannel *find_bc_by_l3id(struct misdn_stack *stack, unsigned long l3id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int setup_bc(struct misdn_bchannel *bc); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int manager_isdn_handler(iframe_t *frm ,msg_t *msg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int misdn_lib_port_restart(int port); | 
					
						
							| 
									
										
											  
											
												Merged revisions 49313 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r49313 | crichter | 2007-01-03 10:06:50 +0100 (Mi, 03 Jan 2007) | 41 lines
Merged revisions 48319,48321,48467,48552,48576,49135,49303 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r48319 | crichter | 2006-12-06 15:35:25 +0100 (Mi, 06 Dez 2006) | 1 line
changed a few debugs to higher debug levels
........
r48321 | crichter | 2006-12-06 16:48:45 +0100 (Mi, 06 Dez 2006) | 1 line
added the export and import of the MISDN_ADDRESS_COMPLETE Variable to inidcate wether the extension is already completely dialed or if there might come additional digits by information elements. also added some docs for that.
........
r48467 | crichter | 2006-12-14 14:03:49 +0100 (Do, 14 Dez 2006) | 1 line
removed FIXUP state. added check for channel allocation conflict when we create a setup while the other site creates a setup on the same channel, besides the check we resolve this conflict.
........
r48552 | crichter | 2006-12-18 11:19:39 +0100 (Mo, 18 Dez 2006) | 1 line
when our PTP Partner sends us a SETUP with a preselected channel we just accept it, even when we're NT. added some checks for segfaults.
........
r48576 | crichter | 2006-12-19 14:08:51 +0100 (Di, 19 Dez 2006) | 1 line
when we reject a channel, because it's in use already, we shouldn't process the setup anymore. made the channel allocation a bit easier and more understandable, removed a few unused lines
........
r49135 | crichter | 2007-01-02 11:07:22 +0100 (Di, 02 Jan 2007) | 1 line
added check for channel ranges in the set/empty channel functions. set pmp_l1_check default to no. added misdn restart pid cli command. added cleaning of channel when we send a RELEASE_COMPLETE. 
........
r49303 | crichter | 2007-01-03 09:24:00 +0100 (Mi, 03 Jan 2007) | 9 lines
* Added check for bridging in misdn_call to avoid setting echocancellation
  when 2 mISDN channels are involved and when bridging is set. That lead
  to a kernel panic before under different situations, because we switched 
  about 2 times between hardware bridging and echocancelation
* readded MISDN_URATE variable which got lost before, this should make app_v110
  work again
* fixed typo
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@49321 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-01-03 11:15:02 +00:00
										 |  |  | int misdn_lib_pid_restart(int pid); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | extern struct isdn_msg msgs_g[]; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define ISDN_PID_L3_B_USER 0x430000ff
 | 
					
						
							|  |  |  | #define ISDN_PID_L4_B_USER 0x440000ff
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* #define MISDN_IBUF_SIZE 1024 */ | 
					
						
							|  |  |  | #define MISDN_IBUF_SIZE 512
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*  Fine Tuning of Inband  Signalling time */ | 
					
						
							|  |  |  | #define TONE_ALERT_CNT 41 /*  1 Sec  */
 | 
					
						
							|  |  |  | #define TONE_ALERT_SILENCE_CNT 200 /*  4 Sec */
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define TONE_BUSY_CNT 20 /*  ? */
 | 
					
						
							|  |  |  | #define TONE_BUSY_SILENCE_CNT 48 /*  ? */
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | static int entity; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static struct misdn_lib *glob_mgr; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-30 16:49:02 +00:00
										 |  |  | static char tone_425_flip[TONE_425_SIZE]; | 
					
						
							|  |  |  | static char tone_silence_flip[TONE_SILENCE_SIZE]; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static void misdn_lib_isdn_event_catcher(void *arg); | 
					
						
							|  |  |  | static int handle_event_nt(void *dat, void *arg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void stack_holder_add(struct misdn_stack *stack, struct misdn_bchannel *holder); | 
					
						
							|  |  |  | void stack_holder_remove(struct misdn_stack *stack, struct misdn_bchannel *holder); | 
					
						
							|  |  |  | struct misdn_bchannel *stack_holder_find(struct misdn_stack *stack, unsigned long l3id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* from isdn_lib.h */ | 
					
						
							|  |  |  | 	/* user iface */ | 
					
						
							|  |  |  | void te_lib_destroy(int midev) ; | 
					
						
							|  |  |  | struct misdn_bchannel *manager_find_bc_by_pid(int pid); | 
					
						
							| 
									
										
										
										
											2006-06-01 16:25:04 +00:00
										 |  |  | void manager_ph_control_block(struct misdn_bchannel *bc, int c1, void *c2, int c2_len); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | void manager_clean_bc(struct misdn_bchannel *bc ); | 
					
						
							|  |  |  | void manager_bchannel_setup (struct misdn_bchannel *bc); | 
					
						
							|  |  |  | void manager_bchannel_cleanup (struct misdn_bchannel *bc); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ec_chunk( struct misdn_bchannel *bc, unsigned char *rxchunk, unsigned char *txchunk, int chunk_size); | 
					
						
							|  |  |  | 	/* end */ | 
					
						
							|  |  |  | int bchdev_echocancel_activate(struct misdn_bchannel* dev); | 
					
						
							|  |  |  | void bchdev_echocancel_deactivate(struct misdn_bchannel* dev); | 
					
						
							|  |  |  | /* end */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char *bearer2str(int cap) { | 
					
						
							|  |  |  | 	static char *bearers[]={ | 
					
						
							|  |  |  | 		"Speech", | 
					
						
							|  |  |  | 		"Audio 3.1k", | 
					
						
							|  |  |  | 		"Unres Digital", | 
					
						
							|  |  |  | 		"Res Digital", | 
					
						
							|  |  |  | 		"Unknown Bearer" | 
					
						
							|  |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	switch (cap) { | 
					
						
							|  |  |  | 	case INFO_CAPABILITY_SPEECH: | 
					
						
							|  |  |  | 		return bearers[0]; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case INFO_CAPABILITY_AUDIO_3_1K: | 
					
						
							|  |  |  | 		return bearers[1]; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case INFO_CAPABILITY_DIGITAL_UNRESTRICTED: | 
					
						
							|  |  |  | 		return bearers[2]; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case INFO_CAPABILITY_DIGITAL_RESTRICTED: | 
					
						
							|  |  |  | 		return bearers[3]; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		return bearers[4]; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char flip_table[256]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static void init_flip_bits(void) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int i,k; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	for (i = 0 ; i < 256 ; i++) { | 
					
						
							|  |  |  | 		unsigned char sample = 0 ; | 
					
						
							|  |  |  | 		for (k = 0; k<8; k++) { | 
					
						
							|  |  |  | 			if ( i & 1 << k ) sample |= 0x80 >>  k; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		flip_table[i] = sample; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static char * flip_buf_bits ( char * buf , int len) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	char * start = buf; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	for (i = 0 ; i < len; i++) { | 
					
						
							| 
									
										
										
										
											2006-08-09 09:24:21 +00:00
										 |  |  | 		buf[i] = flip_table[(unsigned char)buf[i]]; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	return start; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static msg_t *create_l2msg(int prim, int dinfo, int size) /* NT only */ | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int i = 0; | 
					
						
							|  |  |  | 	msg_t *dmsg; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	while(i < 10) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL); | 
					
						
							|  |  |  | 		if (dmsg) | 
					
						
							|  |  |  | 			return(dmsg); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		if (!i) | 
					
						
							|  |  |  | 			printf("cannot allocate memory, trying again...\n"); | 
					
						
							|  |  |  | 		i++; | 
					
						
							|  |  |  | 		usleep(300000); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	printf("cannot allocate memory, system overloaded.\n"); | 
					
						
							|  |  |  | 	exit(-1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | msg_t *create_l3msg(int prim, int mt, int dinfo, int size, int ntmode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i = 0; | 
					
						
							|  |  |  | 	msg_t *dmsg; | 
					
						
							|  |  |  | 	Q931_info_t *qi; | 
					
						
							|  |  |  | 	iframe_t *frm; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	if (!ntmode) | 
					
						
							|  |  |  | 		size = sizeof(Q931_info_t)+2; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	while(i < 10) { | 
					
						
							|  |  |  | 		if (ntmode) { | 
					
						
							|  |  |  | 			dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL); | 
					
						
							|  |  |  | 			if (dmsg) { | 
					
						
							|  |  |  | 				return(dmsg); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			dmsg = alloc_msg(size+256+mISDN_HEADER_LEN+DEFAULT_HEADROOM); | 
					
						
							|  |  |  | 			if (dmsg) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				memset(msg_put(dmsg,size+mISDN_HEADER_LEN), 0, size+mISDN_HEADER_LEN); | 
					
						
							|  |  |  | 				frm = (iframe_t *)dmsg->data; | 
					
						
							|  |  |  | 				frm->prim = prim; | 
					
						
							|  |  |  | 				frm->dinfo = dinfo; | 
					
						
							|  |  |  | 				qi = (Q931_info_t *)(dmsg->data + mISDN_HEADER_LEN); | 
					
						
							|  |  |  | 				qi->type = mt; | 
					
						
							|  |  |  | 				return(dmsg); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		if (!i) printf("cannot allocate memory, trying again...\n"); | 
					
						
							|  |  |  | 		i++; | 
					
						
							|  |  |  | 		usleep(300000); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	printf("cannot allocate memory, system overloaded.\n"); | 
					
						
							|  |  |  | 	exit(-1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int send_msg (int midev, struct misdn_bchannel *bc, msg_t *dmsg) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 	iframe_t *frm = (iframe_t *)dmsg->data; | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	struct misdn_stack *stack=get_stack_by_bc(bc); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!stack) { | 
					
						
							| 
									
										
										
										
											2006-02-08 16:10:21 +00:00
										 |  |  | 		cb_log(0,bc->port,"send_msg: IEK!! no stack\n "); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	frm->addr = (stack->upper_id | FLG_MSG_DOWN); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	frm->dinfo = bc->l3_id; | 
					
						
							|  |  |  | 	frm->len = (dmsg->len) - mISDN_HEADER_LEN; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | 	cb_log(4,stack->port,"Sending msg, prim:%x addr:%x dinfo:%x\n",frm->prim,frm->addr,frm->dinfo); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	mISDN_write(midev, dmsg->data, dmsg->len, TIMEOUT_1SEC); | 
					
						
							|  |  |  | 	free_msg(dmsg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-17 10:37:35 +00:00
										 |  |  | static int mypid=1; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | int misdn_cap_is_speech(int cap) | 
					
						
							|  |  |  | /** Poor mans version **/ | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-15 20:20:45 +00:00
										 |  |  | 	if ( (cap != INFO_CAPABILITY_DIGITAL_UNRESTRICTED) && | 
					
						
							|  |  |  | 	     (cap != INFO_CAPABILITY_DIGITAL_RESTRICTED) ) return 1; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int misdn_inband_avail(struct misdn_bchannel *bc) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 	if (!bc->early_bconnect) { | 
					
						
							|  |  |  | 		/* We have opted to never receive any available inband recorded messages */ | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	switch (bc->progress_indicator) { | 
					
						
							|  |  |  | 	case INFO_PI_INBAND_AVAILABLE: | 
					
						
							|  |  |  | 	case INFO_PI_CALL_NOT_E2E_ISDN: | 
					
						
							| 
									
										
										
										
											2005-11-15 20:20:45 +00:00
										 |  |  | 	case INFO_PI_CALLED_NOT_ISDN: | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		return 1; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static void dump_chan_list(struct misdn_stack *stack) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 	for (i = 0; i <= stack->b_num; ++i) { | 
					
						
							|  |  |  | 		cb_log(6, stack->port, "Idx:%d stack->cchan:%d in_use:%d Chan:%d\n", | 
					
						
							|  |  |  | 			i, stack->channels[i], stack->bc[i].in_use, i + 1); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | #if defined(AST_MISDN_ENHANCEMENTS)
 | 
					
						
							|  |  |  | 	for (i = MAX_BCHANS + 1; i < ARRAY_LEN(stack->bc); ++i) { | 
					
						
							|  |  |  | 		if (stack->bc[i].in_use) { | 
					
						
							|  |  |  | 			cb_log(6, stack->port, "Idx:%d stack->cchan:%d REGISTER Chan:%d in_use\n", | 
					
						
							|  |  |  | 				i, stack->channels[i], i + 1); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif	/* defined(AST_MISDN_ENHANCEMENTS) */
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-30 16:49:02 +00:00
										 |  |  | void misdn_dump_chanlist(void) | 
					
						
							| 
									
										
										
										
											2007-06-25 09:46:18 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct misdn_stack *stack=get_misdn_stack(); | 
					
						
							|  |  |  | 	for ( ; stack; stack=stack->next) { | 
					
						
							|  |  |  | 		dump_chan_list(stack); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-06-25 09:46:18 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-30 16:49:02 +00:00
										 |  |  | static int set_chan_in_stack(struct misdn_stack *stack, int channel) | 
					
						
							| 
									
										
										
										
											2007-07-02 09:17:07 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	cb_log(4,stack->port,"set_chan_in_stack: %d\n",channel); | 
					
						
							|  |  |  | 	dump_chan_list(stack); | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	if (1 <= channel && channel <= ARRAY_LEN(stack->channels)) { | 
					
						
							| 
									
										
										
										
											2007-07-02 09:17:07 +00:00
										 |  |  | 		if (!stack->channels[channel-1]) | 
					
						
							|  |  |  | 			stack->channels[channel-1] = 1; | 
					
						
							|  |  |  | 		else { | 
					
						
							|  |  |  | 			cb_log(4,stack->port,"channel already in use:%d\n", channel ); | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		cb_log(0,stack->port,"couldn't set channel %d in\n", channel ); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-02 09:17:07 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-05-18 09:36:16 +00:00
										 |  |  | static int find_free_chan_in_stack(struct misdn_stack *stack, struct misdn_bchannel *bc, int channel, int dec) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 	int chan = 0; | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	int bnums; | 
					
						
							| 
									
										
										
										
											2007-07-02 09:17:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 	if (bc->channel_found) { | 
					
						
							| 
									
										
										
										
											2007-07-02 09:17:07 +00:00
										 |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 	bc->channel_found = 1; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | #if defined(AST_MISDN_ENHANCEMENTS)
 | 
					
						
							|  |  |  | 	if (bc->is_register_pool) { | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 		pthread_mutex_lock(&stack->st_lock); | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		for (i = MAX_BCHANS + 1; i < ARRAY_LEN(stack->channels); ++i) { | 
					
						
							|  |  |  | 			if (!stack->channels[i]) { | 
					
						
							|  |  |  | 				chan = i + 1; | 
					
						
							|  |  |  | 				cb_log(3, stack->port, " --> found REGISTER chan: %d\n", chan); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else | 
					
						
							|  |  |  | #endif	/* defined(AST_MISDN_ENHANCEMENTS) */
 | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		cb_log(5, stack->port, "find_free_chan: req_chan:%d\n", channel); | 
					
						
							| 
									
										
										
										
											2006-06-26 17:37:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		if (channel < 0 || channel > MAX_BCHANS) { | 
					
						
							|  |  |  | 			cb_log(0, stack->port, " !! out of bound call to find_free_chan_in_stack! (ch:%d)\n", channel); | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		--channel; | 
					
						
							| 
									
										
										
										
											2007-05-18 09:47:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 		pthread_mutex_lock(&stack->st_lock); | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		bnums = stack->pri ? stack->b_num : stack->b_num - 1; | 
					
						
							|  |  |  | 		if (dec) { | 
					
						
							|  |  |  | 			for (i = bnums; i >= 0; --i) { | 
					
						
							|  |  |  | 				if (i != 15 && (channel < 0 || i == channel)) { /* skip E1 D channel ;) and work with chan preselection */ | 
					
						
							|  |  |  | 					if (!stack->channels[i]) { | 
					
						
							|  |  |  | 						chan = i + 1; | 
					
						
							|  |  |  | 						cb_log(3, stack->port, " --> found chan%s: %d\n", channel >= 0 ? " (preselected)" : "", chan); | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2007-05-18 09:36:16 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			for (i = 0; i <= bnums; ++i) { | 
					
						
							|  |  |  | 				if (i != 15 && (channel < 0 || i == channel)) { /* skip E1 D channel ;) and work with chan preselection */ | 
					
						
							|  |  |  | 					if (!stack->channels[i]) { | 
					
						
							|  |  |  | 						chan = i + 1; | 
					
						
							|  |  |  | 						cb_log(3, stack->port, " --> found chan%s: %d\n", channel >= 0 ? " (preselected)" : "", chan); | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2007-05-18 09:36:16 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-02 09:17:07 +00:00
										 |  |  | 	if (!chan) { | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 		pthread_mutex_unlock(&stack->st_lock); | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 		cb_log(1, stack->port, " !! NO FREE CHAN IN STACK\n"); | 
					
						
							| 
									
										
										
										
											2007-07-02 09:17:07 +00:00
										 |  |  | 		dump_chan_list(stack); | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 		bc->out_cause = AST_CAUSE_NORMAL_CIRCUIT_CONGESTION; | 
					
						
							| 
									
										
										
										
											2007-07-02 09:17:07 +00:00
										 |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-07-02 09:17:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 	if (set_chan_in_stack(stack, chan) < 0) { | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 		pthread_mutex_unlock(&stack->st_lock); | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 		cb_log(0, stack->port, "Channel Already in use:%d\n", chan); | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 		bc->out_cause = AST_CAUSE_REQUESTED_CHAN_UNAVAIL; | 
					
						
							| 
									
										
										
										
											2007-07-02 09:17:07 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 	pthread_mutex_unlock(&stack->st_lock); | 
					
						
							| 
									
										
										
										
											2007-07-02 09:17:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 	bc->channel = chan; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-18 16:29:47 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Release a B channel to the allocation pool. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param stack Which port stack B channel belongs. | 
					
						
							|  |  |  |  * \param channel B channel to release. (Range 1-MAX_BCHANS representing B1-Bn) | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \return Nothing | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \note | 
					
						
							|  |  |  |  * Must be called after clean_up_bc() to make sure that the media stream is | 
					
						
							|  |  |  |  * no longer connected. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | static void empty_chan_in_stack(struct misdn_stack *stack, int channel) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	if (channel < 1 || ARRAY_LEN(stack->channels) < channel) { | 
					
						
							|  |  |  | 		cb_log(0, stack->port, "empty_chan_in_stack: cannot empty channel %d\n", channel); | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2006-07-06 15:11:40 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	cb_log(4, stack->port, "empty_chan_in_stack: %d\n", channel); | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 	stack->channels[channel - 1] = 0; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	dump_chan_list(stack); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | char *bc_state2str(enum bchannel_state state) { | 
					
						
							|  |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 	struct bchan_state_s { | 
					
						
							|  |  |  | 		char *n; | 
					
						
							|  |  |  | 		enum bchannel_state s; | 
					
						
							|  |  |  | 	} states[] = { | 
					
						
							|  |  |  | 		{"BCHAN_CLEANED", BCHAN_CLEANED }, | 
					
						
							|  |  |  | 		{"BCHAN_EMPTY", BCHAN_EMPTY}, | 
					
						
							|  |  |  | 		{"BCHAN_SETUP", BCHAN_SETUP}, | 
					
						
							|  |  |  | 		{"BCHAN_SETUPED", BCHAN_SETUPED}, | 
					
						
							|  |  |  | 		{"BCHAN_ACTIVE", BCHAN_ACTIVE}, | 
					
						
							|  |  |  | 		{"BCHAN_ACTIVATED", BCHAN_ACTIVATED}, | 
					
						
							|  |  |  | 		{"BCHAN_BRIDGE",  BCHAN_BRIDGE}, | 
					
						
							|  |  |  | 		{"BCHAN_BRIDGED", BCHAN_BRIDGED}, | 
					
						
							|  |  |  | 		{"BCHAN_RELEASE", BCHAN_RELEASE}, | 
					
						
							|  |  |  | 		{"BCHAN_RELEASED", BCHAN_RELEASED}, | 
					
						
							|  |  |  | 		{"BCHAN_CLEAN", BCHAN_CLEAN}, | 
					
						
							| 
									
										
										
										
											2006-06-17 10:37:35 +00:00
										 |  |  | 		{"BCHAN_CLEAN_REQUEST", BCHAN_CLEAN_REQUEST}, | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 		{"BCHAN_ERROR", BCHAN_ERROR} | 
					
						
							|  |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 	for (i=0; i< sizeof(states)/sizeof(struct bchan_state_s); i++) | 
					
						
							|  |  |  | 		if ( states[i].s == state) | 
					
						
							|  |  |  | 			return states[i].n; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return "UNKNOWN"; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void bc_state_change(struct misdn_bchannel *bc, enum bchannel_state state) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-10-11 08:23:16 +00:00
										 |  |  | 	cb_log(5,bc->port,"BC_STATE_CHANGE: l3id:%x from:%s to:%s\n", | 
					
						
							|  |  |  | 		bc->l3_id, | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 	       bc_state2str(bc->bc_state), | 
					
						
							|  |  |  | 	       bc_state2str(state) ); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 	switch (state) { | 
					
						
							|  |  |  | 		case BCHAN_ACTIVATED: | 
					
						
							|  |  |  | 			if (bc->next_bc_state ==  BCHAN_BRIDGED) { | 
					
						
							|  |  |  | 				misdn_join_conf(bc, bc->conf_id); | 
					
						
							|  |  |  | 				bc->next_bc_state = BCHAN_EMPTY; | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			bc->bc_state=state; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static void bc_next_state_change(struct misdn_bchannel *bc, enum bchannel_state state) | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 	cb_log(5,bc->port,"BC_NEXT_STATE_CHANGE: from:%s to:%s\n", | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 	       bc_state2str(bc->next_bc_state), | 
					
						
							|  |  |  | 	       bc_state2str(state) ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bc->next_bc_state=state; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-18 16:29:47 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Empty the B channel record of most call data. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param bc B channel record to empty of most call data. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \return Nothing | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \note | 
					
						
							|  |  |  |  * Sets the last_used time and must be called before clearing bc->in_use. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static void empty_bc(struct misdn_bchannel *bc) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-04-03 22:41:46 +00:00
										 |  |  | 	bc->caller.presentation = 0;	/* allowed */ | 
					
						
							|  |  |  | 	bc->caller.number_plan = NUMPLAN_ISDN; | 
					
						
							|  |  |  | 	bc->caller.number_type = NUMTYPE_UNKNOWN; | 
					
						
							|  |  |  | 	bc->caller.name[0] = 0; | 
					
						
							|  |  |  | 	bc->caller.number[0] = 0; | 
					
						
							|  |  |  | 	bc->caller.subaddress[0] = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bc->connected.presentation = 0;	/* allowed */ | 
					
						
							|  |  |  | 	bc->connected.number_plan = NUMPLAN_ISDN; | 
					
						
							|  |  |  | 	bc->connected.number_type = NUMTYPE_UNKNOWN; | 
					
						
							|  |  |  | 	bc->connected.name[0] = 0; | 
					
						
							|  |  |  | 	bc->connected.number[0] = 0; | 
					
						
							|  |  |  | 	bc->connected.subaddress[0] = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bc->redirecting.from.presentation = 0;	/* allowed */ | 
					
						
							|  |  |  | 	bc->redirecting.from.number_plan = NUMPLAN_ISDN; | 
					
						
							|  |  |  | 	bc->redirecting.from.number_type = NUMTYPE_UNKNOWN; | 
					
						
							|  |  |  | 	bc->redirecting.from.name[0] = 0; | 
					
						
							|  |  |  | 	bc->redirecting.from.number[0] = 0; | 
					
						
							|  |  |  | 	bc->redirecting.from.subaddress[0] = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	bc->redirecting.to.presentation = 0;	/* allowed */ | 
					
						
							|  |  |  | 	bc->redirecting.to.number_plan = NUMPLAN_ISDN; | 
					
						
							|  |  |  | 	bc->redirecting.to.number_type = NUMTYPE_UNKNOWN; | 
					
						
							|  |  |  | 	bc->redirecting.to.name[0] = 0; | 
					
						
							|  |  |  | 	bc->redirecting.to.number[0] = 0; | 
					
						
							|  |  |  | 	bc->redirecting.to.subaddress[0] = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-03 22:41:46 +00:00
										 |  |  | 	bc->redirecting.reason = mISDN_REDIRECTING_REASON_UNKNOWN; | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	bc->redirecting.count = 0; | 
					
						
							|  |  |  | 	bc->redirecting.to_changed = 0; | 
					
						
							| 
									
										
										
										
											2009-04-03 22:41:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-02 09:23:08 +00:00
										 |  |  | 	bc->dummy=0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	bc->bframe_len=0; | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-11 08:34:03 +00:00
										 |  |  | 	bc->cw= 0; | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-05-18 09:36:16 +00:00
										 |  |  | 	bc->dec=0; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	bc->channel = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-01 12:51:41 +00:00
										 |  |  | 	bc->sending_complete = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bc->restart_channel=0; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 	bc->conf_id = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	bc->need_more_infos = 0; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	bc->send_dtmf=0; | 
					
						
							|  |  |  | 	bc->nodsp=0; | 
					
						
							|  |  |  | 	bc->nojitter=0; | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	bc->time_usec=0; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	bc->rxgain=0; | 
					
						
							|  |  |  | 	bc->txgain=0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bc->crypt=0; | 
					
						
							|  |  |  | 	bc->curptx=0; bc->curprx=0; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	bc->crypt_key[0] = 0; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	bc->generate_tone=0; | 
					
						
							|  |  |  | 	bc->tone_cnt=0; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	bc->active = 0; | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	bc->early_bconnect = 1; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-03-26 15:59:56 +00:00
										 |  |  | #ifdef MISDN_1_2
 | 
					
						
							|  |  |  | 	*bc->pipeline = 0; | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	bc->ec_enable = 0; | 
					
						
							|  |  |  | 	bc->ec_deftaps = 128; | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2007-03-26 15:59:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-04-11 15:48:54 +00:00
										 |  |  | 	bc->AOCD_need_export = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	bc->orig=0; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 	bc->cause = AST_CAUSE_NORMAL_CLEARING; | 
					
						
							|  |  |  | 	bc->out_cause = AST_CAUSE_NORMAL_CLEARING; | 
					
						
							| 
									
										
										
										
											2009-04-03 22:41:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	bc->display_connected = 0;	/* none */ | 
					
						
							|  |  |  | 	bc->display_setup = 0;	/* none */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-14 22:03:49 +00:00
										 |  |  | 	bc->outgoing_colp = 0;/* pass */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-03 22:41:46 +00:00
										 |  |  | 	bc->presentation = 0;	/* allowed */ | 
					
						
							|  |  |  | 	bc->set_presentation = 0; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	bc->notify_description_code = mISDN_NOTIFY_CODE_INVALID; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	bc->evq=EVENT_NOTHING; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bc->progress_coding=0; | 
					
						
							|  |  |  | 	bc->progress_location=0; | 
					
						
							|  |  |  | 	bc->progress_indicator=0; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-27 20:03:49 +00:00
										 |  |  | #if defined(AST_MISDN_ENHANCEMENTS)
 | 
					
						
							|  |  |  | 	bc->div_leg_3_rx_wanted = 0; | 
					
						
							|  |  |  | 	bc->div_leg_3_tx_pending = 0; | 
					
						
							|  |  |  | #endif	/* defined(AST_MISDN_ENHANCEMENTS) */
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | /** Set Default Bearer Caps **/ | 
					
						
							|  |  |  | 	bc->capability=INFO_CAPABILITY_SPEECH; | 
					
						
							|  |  |  | 	bc->law=INFO_CODEC_ALAW; | 
					
						
							|  |  |  | 	bc->mode=0; | 
					
						
							| 
									
										
										
										
											2006-02-22 21:59:46 +00:00
										 |  |  | 	bc->rate=0x10; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	bc->user1=0; | 
					
						
							|  |  |  | 	bc->urate=0; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	bc->hdlc=0; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-03 22:41:46 +00:00
										 |  |  | 	bc->dialed.number_plan = NUMPLAN_ISDN; | 
					
						
							|  |  |  | 	bc->dialed.number_type = NUMTYPE_UNKNOWN; | 
					
						
							|  |  |  | 	bc->dialed.number[0] = 0; | 
					
						
							|  |  |  | 	bc->dialed.subaddress[0] = 0; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	bc->info_dad[0] = 0; | 
					
						
							|  |  |  | 	bc->display[0] = 0; | 
					
						
							|  |  |  | 	bc->infos_pending[0] = 0; | 
					
						
							| 
									
										
											  
											
												Merged revisions 58825-58826 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r58825 | crichter | 2007-03-12 13:43:24 +0100 (Mo, 12 Mär 2007) | 1 line
added UU transceiving and corect handling for rdnis
................
r58826 | crichter | 2007-03-12 14:08:06 +0100 (Mo, 12 Mär 2007) | 21 lines
Merged revisions 57034,57523,57753,58558 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r57034 | crichter | 2007-02-28 17:09:27 +0100 (Mi, 28 Feb 2007) | 1 line
fixed bugs.digium.com bugs: #9157 and bugs.beronet.com bugs: #302, #303, #304
........
r57523 | crichter | 2007-03-02 19:32:51 +0100 (Fr, 02 Mar 2007) | 1 line
fixed typo
........
r57753 | crichter | 2007-03-04 11:39:50 +0100 (So, 04 Mar 2007) | 1 line
fixed another place where the out_cause was hardcoded to 16
........
r58558 | crichter | 2007-03-09 15:43:58 +0100 (Fr, 09 Mar 2007) | 1 line
we can free channel 31 as well, since we can occupy it
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@64951 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-05-18 09:31:27 +00:00
										 |  |  | 	bc->uu[0]=0; | 
					
						
							|  |  |  | 	bc->uulen=0; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-16 13:19:54 +00:00
										 |  |  | 	bc->fac_in.Function = Fac_None; | 
					
						
							|  |  |  | 	bc->fac_out.Function = Fac_None; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	bc->te_choose_channel = 0; | 
					
						
							| 
									
										
										
										
											2007-07-02 09:17:07 +00:00
										 |  |  | 	bc->channel_found= 0; | 
					
						
							| 
									
										
										
										
											2008-06-02 08:46:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	gettimeofday(&bc->last_used, NULL); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int clean_up_bc(struct misdn_bchannel *bc) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int ret=0; | 
					
						
							|  |  |  | 	unsigned char buff[32]; | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	struct misdn_stack * stack; | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 	cb_log(3, bc?bc->port:0, "$$$ CLEANUP CALLED pid:%d\n", bc?bc->pid:-1); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	if (!bc  ) return -1; | 
					
						
							|  |  |  | 	stack=get_stack_by_bc(bc); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	if (!stack) return -1; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 	switch (bc->bc_state ) { | 
					
						
							|  |  |  | 	case BCHAN_CLEANED: | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 		cb_log(5, stack->port, "$$$ Already cleaned up bc with stid :%x\n", bc->b_stid); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 	default: | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 	cb_log(2, stack->port, "$$$ Cleaning up bc with stid :%x pid:%d\n", bc->b_stid, bc->pid); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | 	manager_ec_disable(bc); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-27 11:18:32 +00:00
										 |  |  | 	manager_bchannel_deactivate(bc); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 	mISDN_write_frame(stack->midev, buff, bc->layer_id|FLG_MSG_TARGET|FLG_MSG_DOWN, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	bc->b_stid = 0; | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 	bc_state_change(bc, BCHAN_CLEANED); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static void clear_l3(struct misdn_stack *stack) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	if (global_state == MISDN_INITIALIZED) { | 
					
						
							|  |  |  | 		for (i = 0; i <= stack->b_num; ++i) { | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 			cb_event(EVENT_CLEANUP, &stack->bc[i], NULL); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			empty_bc(&stack->bc[i]); | 
					
						
							| 
									
										
										
										
											2006-06-01 12:51:41 +00:00
										 |  |  | 			clean_up_bc(&stack->bc[i]); | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 			empty_chan_in_stack(stack, i + 1); | 
					
						
							| 
									
										
										
										
											2007-06-25 09:46:18 +00:00
										 |  |  | 			stack->bc[i].in_use = 0; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | #if defined(AST_MISDN_ENHANCEMENTS)
 | 
					
						
							|  |  |  | 		for (i = MAX_BCHANS + 1; i < ARRAY_LEN(stack->bc); ++i) { | 
					
						
							|  |  |  | 			empty_bc(&stack->bc[i]); | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 			empty_chan_in_stack(stack, i + 1); | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 			stack->bc[i].in_use = 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | #endif	/* defined(AST_MISDN_ENHANCEMENTS) */
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-14 21:51:06 +00:00
										 |  |  | static int new_te_id = 0; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int misdn_lib_get_l1_down(struct misdn_stack *stack) | 
					
						
							| 
									
										
										
										
											2006-03-07 11:16:56 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 	/* Pull Up L1 */ | 
					
						
							| 
									
										
										
										
											2006-03-07 11:16:56 +00:00
										 |  |  | 	iframe_t act; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 	act.prim = PH_DEACTIVATE | REQUEST; | 
					
						
							| 
									
										
										
										
											2007-11-12 13:33:13 +00:00
										 |  |  | 	act.addr = stack->lower_id|FLG_MSG_DOWN; | 
					
						
							| 
									
										
										
										
											2006-03-07 11:16:56 +00:00
										 |  |  | 	act.dinfo = 0; | 
					
						
							|  |  |  | 	act.len = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-12 13:33:13 +00:00
										 |  |  | 	cb_log(1, stack->port, "SENDING PH_DEACTIVATE | REQ\n"); | 
					
						
							| 
									
										
										
										
											2006-03-07 11:16:56 +00:00
										 |  |  | 	return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int misdn_lib_get_l2_down(struct misdn_stack *stack) | 
					
						
							| 
									
										
										
										
											2006-03-07 11:16:56 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-07 11:16:56 +00:00
										 |  |  | 	if (stack->ptp && (stack->nt) ) { | 
					
						
							|  |  |  | 		msg_t *dmsg; | 
					
						
							|  |  |  | 		/* L2 */ | 
					
						
							|  |  |  | 		dmsg = create_l2msg(DL_RELEASE| REQUEST, 0, 0); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-15 21:14:41 +00:00
										 |  |  | 		pthread_mutex_lock(&stack->nstlock); | 
					
						
							| 
									
										
										
										
											2006-03-07 11:16:56 +00:00
										 |  |  | 		if (stack->nst.manager_l3(&stack->nst, dmsg)) | 
					
						
							|  |  |  | 			free_msg(dmsg); | 
					
						
							| 
									
										
										
										
											2009-07-15 21:14:41 +00:00
										 |  |  | 		pthread_mutex_unlock(&stack->nstlock); | 
					
						
							| 
									
										
										
										
											2006-03-07 11:16:56 +00:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		iframe_t act; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-07 11:16:56 +00:00
										 |  |  | 		act.prim = DL_RELEASE| REQUEST; | 
					
						
							|  |  |  | 		act.addr = (stack->upper_id |FLG_MSG_DOWN)  ; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-07 11:16:56 +00:00
										 |  |  | 		act.dinfo = 0; | 
					
						
							|  |  |  | 		act.len = 0; | 
					
						
							|  |  |  | 		return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-07 11:16:56 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int misdn_lib_get_l1_up(struct misdn_stack *stack) | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 	/* Pull Up L1 */ | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	iframe_t act; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 	act.prim = PH_ACTIVATE | REQUEST; | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	act.addr = (stack->upper_id | FLG_MSG_DOWN)  ; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	act.dinfo = 0; | 
					
						
							|  |  |  | 	act.len = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int misdn_lib_get_l2_up(struct misdn_stack *stack) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	if (stack->ptp && (stack->nt) ) { | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 		msg_t *dmsg; | 
					
						
							|  |  |  | 		/* L2 */ | 
					
						
							|  |  |  | 		dmsg = create_l2msg(DL_ESTABLISH | REQUEST, 0, 0); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-15 21:14:41 +00:00
										 |  |  | 		pthread_mutex_lock(&stack->nstlock); | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 		if (stack->nst.manager_l3(&stack->nst, dmsg)) | 
					
						
							|  |  |  | 			free_msg(dmsg); | 
					
						
							| 
									
										
										
										
											2009-07-15 21:14:41 +00:00
										 |  |  | 		pthread_mutex_unlock(&stack->nstlock); | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		iframe_t act; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 		act.prim = DL_ESTABLISH | REQUEST; | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		act.addr = (stack->upper_id |FLG_MSG_DOWN)  ; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 		act.dinfo = 0; | 
					
						
							|  |  |  | 		act.len = 0; | 
					
						
							|  |  |  | 		return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | #if 0
 | 
					
						
							|  |  |  | static int misdn_lib_get_l2_te_ptp_up(struct misdn_stack *stack) | 
					
						
							| 
									
										
										
										
											2006-02-08 19:39:37 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	iframe_t act; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-08 19:39:37 +00:00
										 |  |  | 	act.prim = DL_ESTABLISH | REQUEST; | 
					
						
							|  |  |  | 	act.addr = (stack->upper_id  & ~LAYER_ID_MASK) | 3 | FLG_MSG_DOWN; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-08 19:39:37 +00:00
										 |  |  | 	act.dinfo = 0; | 
					
						
							|  |  |  | 	act.len = 0; | 
					
						
							|  |  |  | 	return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int misdn_lib_get_short_status(struct misdn_stack *stack) | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	iframe_t act; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	act.prim = MGR_SHORTSTATUS | REQUEST; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-08 19:39:37 +00:00
										 |  |  | 	act.addr = (stack->upper_id | MSG_BROADCAST)  ; | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-08 19:39:37 +00:00
										 |  |  | 	act.dinfo = SSTATUS_BROADCAST_BIT | SSTATUS_ALL; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	act.len = 0; | 
					
						
							|  |  |  | 	return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-14 21:51:06 +00:00
										 |  |  | static int create_process(int midev, struct misdn_bchannel *bc) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	iframe_t ncr; | 
					
						
							|  |  |  | 	int l3_id; | 
					
						
							| 
									
										
										
										
											2009-01-14 21:51:06 +00:00
										 |  |  | 	int proc_id; | 
					
						
							|  |  |  | 	struct misdn_stack *stack; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	stack = get_stack_by_bc(bc); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	if (stack->nt) { | 
					
						
							| 
									
										
										
										
											2009-01-14 21:51:06 +00:00
										 |  |  | 		if (find_free_chan_in_stack(stack, bc, bc->channel_preselected ? bc->channel : 0, 0) < 0) { | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			return -1; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-01-14 21:51:06 +00:00
										 |  |  | 		cb_log(4, stack->port, " -->  found channel: %d\n", bc->channel); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-14 21:51:06 +00:00
										 |  |  | 		for (proc_id = 0; proc_id < MAXPROCS; ++proc_id) { | 
					
						
							|  |  |  | 			if (stack->procids[proc_id] == 0) { | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-04-03 22:41:46 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-01-14 21:51:06 +00:00
										 |  |  | 		if (proc_id == MAXPROCS) { | 
					
						
							|  |  |  | 			cb_log(0, stack->port, "Couldn't Create New ProcId.\n"); | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-14 21:51:06 +00:00
										 |  |  | 		stack->procids[proc_id] = 1; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-14 21:51:06 +00:00
										 |  |  | 		l3_id = 0xff00 | proc_id; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		bc->l3_id = l3_id; | 
					
						
							| 
									
										
										
										
											2009-01-14 21:51:06 +00:00
										 |  |  | 		cb_log(3, stack->port, " --> new_l3id %x\n", l3_id); | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2009-03-30 20:41:24 +00:00
										 |  |  | 		if ((stack->pri && stack->ptp) || bc->te_choose_channel) { | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			/* we know exactly which channels are in use */ | 
					
						
							| 
									
										
										
										
											2009-01-14 21:51:06 +00:00
										 |  |  | 			if (find_free_chan_in_stack(stack, bc, bc->channel_preselected ? bc->channel : 0, bc->dec) < 0) { | 
					
						
							|  |  |  | 				return -1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			cb_log(2, stack->port, " -->  found channel: %d\n", bc->channel); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			/* other phones could have made a call also on this port (ptmp) */ | 
					
						
							| 
									
										
										
										
											2009-01-14 21:51:06 +00:00
										 |  |  | 			bc->channel = 0xff; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-01-14 21:51:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		/* if we are in te-mode, we need to create a process first */ | 
					
						
							| 
									
										
										
										
											2009-01-14 21:51:06 +00:00
										 |  |  | 		if (++new_te_id > 0xffff) { | 
					
						
							|  |  |  | 			new_te_id = 0x0001; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-14 21:51:06 +00:00
										 |  |  | 		l3_id = (entity << 16) | new_te_id; | 
					
						
							|  |  |  | 		bc->l3_id = l3_id; | 
					
						
							|  |  |  | 		cb_log(3, stack->port, "--> new_l3id %x\n", l3_id); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		/* send message */ | 
					
						
							| 
									
										
										
										
											2009-01-14 21:51:06 +00:00
										 |  |  | 		ncr.prim = CC_NEW_CR | REQUEST; | 
					
						
							|  |  |  | 		ncr.addr = (stack->upper_id | FLG_MSG_DOWN); | 
					
						
							|  |  |  | 		ncr.dinfo = l3_id; | 
					
						
							|  |  |  | 		ncr.len = 0; | 
					
						
							|  |  |  | 		mISDN_write(midev, &ncr, mISDN_HEADER_LEN + ncr.len, TIMEOUT_1SEC); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-01-14 21:51:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	return l3_id; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-15 20:20:45 +00:00
										 |  |  | void misdn_lib_setup_bc(struct misdn_bchannel *bc) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-10-10 14:54:58 +00:00
										 |  |  | 	clean_up_bc(bc); | 
					
						
							| 
									
										
										
										
											2005-11-15 20:20:45 +00:00
										 |  |  | 	setup_bc(bc); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | int setup_bc(struct misdn_bchannel *bc) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned char buff[1025]; | 
					
						
							| 
									
										
										
										
											2008-09-30 21:00:54 +00:00
										 |  |  | 	int midev; | 
					
						
							|  |  |  | 	int channel; | 
					
						
							|  |  |  | 	int b_stid; | 
					
						
							|  |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	mISDN_pid_t pid; | 
					
						
							|  |  |  | 	int ret; | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	struct misdn_stack *stack=get_stack_by_bc(bc); | 
					
						
							| 
									
										
										
										
											2006-04-04 19:09:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!stack) { | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(0, bc->port, "setup_bc: NO STACK FOUND!!\n"); | 
					
						
							| 
									
										
										
										
											2006-04-04 19:09:26 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 	midev = stack->midev; | 
					
						
							|  |  |  | 	channel = bc->channel - 1 - (bc->channel > 16); | 
					
						
							|  |  |  | 	b_stid = stack->b_stids[channel >= 0 ? channel : 0]; | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 	switch (bc->bc_state) { | 
					
						
							|  |  |  | 		case BCHAN_CLEANED: | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 			cb_log(4, stack->port, "$$$ bc already setup stid :%x (state:%s)\n", b_stid, bc_state2str(bc->bc_state) ); | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 			return -1; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	cb_log(5, stack->port, "$$$ Setting up bc with stid :%x\n", b_stid); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 	/*check if the b_stid is already initialized*/ | 
					
						
							| 
									
										
										
										
											2007-07-02 09:34:19 +00:00
										 |  |  | 	for (i=0; i <= stack->b_num; i++) { | 
					
						
							|  |  |  | 		if (stack->bc[i].b_stid == b_stid) { | 
					
						
							|  |  |  | 			cb_log(0, bc->port, "setup_bc: b_stid:%x already in use !!!\n", b_stid); | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	if (b_stid <= 0) { | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(0, stack->port," -- Stid <=0 at the moment in channel:%d\n",channel); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 		bc_state_change(bc,BCHAN_ERROR); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	bc->b_stid = b_stid; | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		layer_info_t li; | 
					
						
							|  |  |  | 		memset(&li, 0, sizeof(li)); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		li.object_id = -1; | 
					
						
							|  |  |  | 		li.extentions = 0; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		li.st = bc->b_stid; /*  given idx */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | #define MISDN_DSP
 | 
					
						
							|  |  |  | #ifndef MISDN_DSP
 | 
					
						
							|  |  |  | 		bc->nodsp=1; | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 		if ( bc->hdlc || bc->nodsp) { | 
					
						
							|  |  |  | 			cb_log(4, stack->port,"setup_bc: without dsp\n"); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 				int l = sizeof(li.name); | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 				strncpy(li.name, "B L3", l); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 				li.name[l-1] = 0; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 			li.pid.layermask = ISDN_LAYER((3)); | 
					
						
							|  |  |  | 			li.pid.protocol[3] = ISDN_PID_L3_B_USER; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 			bc->layer=3; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 			cb_log(4, stack->port,"setup_bc: with dsp\n"); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 				int l = sizeof(li.name); | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 				strncpy(li.name, "B L4", l); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 				li.name[l-1] = 0; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 			li.pid.layermask = ISDN_LAYER((4)); | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 			li.pid.protocol[4] = ISDN_PID_L4_B_USER; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 			bc->layer=4; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		ret = mISDN_new_layer(midev, &li); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		if (ret ) { | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 			cb_log(0, stack->port,"New Layer Err: %d %s\n",ret,strerror(errno)); | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			bc_state_change(bc,BCHAN_ERROR); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			return(-EINVAL); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		bc->layer_id = li.id; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	memset(&pid, 0, sizeof(pid)); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	cb_log(4, stack->port," --> Channel is %d\n", bc->channel); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	if (bc->nodsp) { | 
					
						
							|  |  |  | 		cb_log(2, stack->port," --> TRANSPARENT Mode (no DSP, no HDLC)\n"); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		pid.protocol[1] = ISDN_PID_L1_B_64TRANS; | 
					
						
							|  |  |  | 		pid.protocol[2] = ISDN_PID_L2_B_TRANS; | 
					
						
							|  |  |  | 		pid.protocol[3] = ISDN_PID_L3_B_USER; | 
					
						
							|  |  |  | 		pid.layermask = ISDN_LAYER((1)) | ISDN_LAYER((2)) | ISDN_LAYER((3)); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	} else if ( bc->hdlc ) { | 
					
						
							|  |  |  | 		cb_log(2, stack->port," --> HDLC Mode\n"); | 
					
						
							|  |  |  | 		pid.protocol[1] = ISDN_PID_L1_B_64HDLC ; | 
					
						
							|  |  |  | 		pid.protocol[2] = ISDN_PID_L2_B_TRANS  ; | 
					
						
							|  |  |  | 		pid.protocol[3] = ISDN_PID_L3_B_USER; | 
					
						
							|  |  |  | 		pid.layermask = ISDN_LAYER((1)) | ISDN_LAYER((2)) | ISDN_LAYER((3)) ; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		cb_log(2, stack->port," --> TRANSPARENT Mode\n"); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		pid.protocol[1] = ISDN_PID_L1_B_64TRANS; | 
					
						
							|  |  |  | 		pid.protocol[2] = ISDN_PID_L2_B_TRANS; | 
					
						
							|  |  |  | 		pid.protocol[3] = ISDN_PID_L3_B_DSP; | 
					
						
							|  |  |  | 		pid.protocol[4] = ISDN_PID_L4_B_USER; | 
					
						
							|  |  |  | 		pid.layermask = ISDN_LAYER((1)) | ISDN_LAYER((2)) | ISDN_LAYER((3)) | ISDN_LAYER((4)); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-06-01 12:51:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	ret = mISDN_set_stack(midev, bc->b_stid, &pid); | 
					
						
							| 
									
										
										
										
											2006-06-01 12:51:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	if (ret){ | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(0, stack->port,"$$$ Set Stack Err: %d %s\n",ret,strerror(errno)); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		mISDN_write_frame(midev, buff, bc->layer_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 		bc_state_change(bc,BCHAN_ERROR); | 
					
						
							| 
									
										
										
										
											2006-10-27 11:18:32 +00:00
										 |  |  | 		cb_event(EVENT_BCHAN_ERROR, bc, glob_mgr->user_data); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		return(-EINVAL); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 	ret = mISDN_get_setstack_ind(midev, bc->layer_id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ret) { | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(0, stack->port,"$$$ Set StackIND Err: %d %s\n",ret,strerror(errno)); | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 		mISDN_write_frame(midev, buff, bc->layer_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 		bc_state_change(bc,BCHAN_ERROR); | 
					
						
							| 
									
										
										
										
											2006-10-27 11:18:32 +00:00
										 |  |  | 		cb_event(EVENT_BCHAN_ERROR, bc, glob_mgr->user_data); | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 		return(-EINVAL); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ret = mISDN_get_layerid(midev, bc->b_stid, bc->layer) ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bc->addr = ret>0? ret : 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!bc->addr) { | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(0, stack->port,"$$$ Get Layerid Err: %d %s\n",ret,strerror(errno)); | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 		mISDN_write_frame(midev, buff, bc->layer_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 		bc_state_change(bc,BCHAN_ERROR); | 
					
						
							| 
									
										
										
										
											2006-10-27 11:18:32 +00:00
										 |  |  | 		cb_event(EVENT_BCHAN_ERROR, bc, glob_mgr->user_data); | 
					
						
							|  |  |  | 		return (-EINVAL); | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	manager_bchannel_activate(bc); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 	bc_state_change(bc,BCHAN_ACTIVATED); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** IFACE **/ | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | static int init_bc(struct misdn_stack *stack, struct misdn_bchannel *bc, int midev, int port, int bidx) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 	if (!bc) { | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 	cb_log(8, port, "Init.BC %d.\n",bidx); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Merged revisions 62912 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r62912 | crichter | 2007-05-03 16:36:32 +0200 (Do, 03 Mai 2007) | 17 lines
Merged revisions 61357,61770,62885 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r61357 | crichter | 2007-04-11 14:05:57 +0200 (Mi, 11 Apr 2007) | 1 line
some fixes for PMP Hold/Retrieve, it should work now, when briding=no
........
r61770 | crichter | 2007-04-24 15:50:05 +0200 (Di, 24 Apr 2007) | 1 line
added lock for sending messages to avoid double sending. shuffled some empty_chans after the cb_event calls, this avoids that a release_complete from a quite different call releases a fresh created setup by accident.
........
r62885 | crichter | 2007-05-03 15:59:00 +0200 (Do, 03 Mai 2007) | 1 line
fixed the problem that misdn_write did not return -1 when called with 0 samples in a frame this resultet in a deadlock in some circumstances, when the call ended because of a busy extension.  added encoding of keypad.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@64955 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-05-18 09:50:33 +00:00
										 |  |  | 	bc->send_lock=malloc(sizeof(struct send_lock)); | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 	if (!bc->send_lock) { | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
											  
											
												Merged revisions 62912 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r62912 | crichter | 2007-05-03 16:36:32 +0200 (Do, 03 Mai 2007) | 17 lines
Merged revisions 61357,61770,62885 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r61357 | crichter | 2007-04-11 14:05:57 +0200 (Mi, 11 Apr 2007) | 1 line
some fixes for PMP Hold/Retrieve, it should work now, when briding=no
........
r61770 | crichter | 2007-04-24 15:50:05 +0200 (Di, 24 Apr 2007) | 1 line
added lock for sending messages to avoid double sending. shuffled some empty_chans after the cb_event calls, this avoids that a release_complete from a quite different call releases a fresh created setup by accident.
........
r62885 | crichter | 2007-05-03 15:59:00 +0200 (Do, 03 Mai 2007) | 1 line
fixed the problem that misdn_write did not return -1 when called with 0 samples in a frame this resultet in a deadlock in some circumstances, when the call ended because of a busy extension.  added encoding of keypad.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@64955 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-05-18 09:50:33 +00:00
										 |  |  | 	pthread_mutex_init(&bc->send_lock->lock, NULL); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	empty_bc(bc); | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 	bc_state_change(bc, BCHAN_CLEANED); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	bc->port=stack->port; | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	bc->nt=stack->nt?1:0; | 
					
						
							| 
									
										
										
										
											2007-06-25 09:37:49 +00:00
										 |  |  | 	bc->pri=stack->pri; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		ibuffer_t* ibuf= init_ibuffer(MISDN_IBUF_SIZE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!ibuf) return -1; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 		clear_ibuffer( ibuf); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 		ibuf->rsem=malloc(sizeof(sem_t)); | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 		if (!ibuf->rsem) { | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 		bc->astbuf=ibuf; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (sem_init(ibuf->rsem,1,0)<0) | 
					
						
							|  |  |  | 			sem_init(ibuf->rsem,0,0); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | #if 0	/* This code does not seem to do anything useful */
 | 
					
						
							|  |  |  | 	if (bidx <= stack->b_num) { | 
					
						
							|  |  |  | 		unsigned char buff[1025]; | 
					
						
							|  |  |  | 		iframe_t *frm = (iframe_t *) buff; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		stack_info_t *stinf; | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		int ret; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 		ret = mISDN_get_stack_info(midev, stack->port, buff, sizeof(buff)); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		if (ret < 0) { | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 			cb_log(0, port, "%s: Cannot get stack info for this port. (ret=%d)\n", __FUNCTION__, ret); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			return -1; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		stinf = (stack_info_t *)&frm->data.p; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(8, port, " --> Child %x\n",stinf->child[bidx]); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | static struct misdn_stack *stack_init(int midev, int port, int ptp) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int ret; | 
					
						
							|  |  |  | 	unsigned char buff[1025]; | 
					
						
							|  |  |  | 	iframe_t *frm = (iframe_t *)buff; | 
					
						
							|  |  |  | 	stack_info_t *stinf; | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	struct misdn_stack *stack; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	layer_info_t li; | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	stack = calloc(1, sizeof(struct misdn_stack)); | 
					
						
							|  |  |  | 	if (!stack) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 	cb_log(8, port, "Init. Stack.\n"); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	stack->port=port; | 
					
						
							|  |  |  | 	stack->midev=midev; | 
					
						
							|  |  |  | 	stack->ptp=ptp; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	stack->holding=NULL; | 
					
						
							|  |  |  | 	stack->pri=0; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	msg_queue_init(&stack->downqueue); | 
					
						
							| 
									
										
										
										
											2006-04-29 22:56:00 +00:00
										 |  |  | 	msg_queue_init(&stack->upqueue); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 	pthread_mutex_init(&stack->st_lock, NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	/* query port's requirements */ | 
					
						
							|  |  |  | 	ret = mISDN_get_stack_info(midev, port, buff, sizeof(buff)); | 
					
						
							|  |  |  | 	if (ret < 0) { | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(0, port, "%s: Cannot get stack info for this port. (ret=%d)\n", __FUNCTION__, ret); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		return(NULL); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	stinf = (stack_info_t *)&frm->data.p; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	stack->d_stid = stinf->id; | 
					
						
							|  |  |  | 	stack->b_num = stinf->childcnt; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-11 08:34:03 +00:00
										 |  |  | 	for (i=0; i<=stinf->childcnt; i++) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		stack->b_stids[i] = stinf->child[i]; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	switch(stinf->pid.protocol[0] & ~ISDN_PID_FEATURE_MASK) { | 
					
						
							|  |  |  | 	case ISDN_PID_L0_TE_S0: | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		stack->nt=0; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case ISDN_PID_L0_NT_S0: | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(8, port, "NT Stack\n"); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		stack->nt=1; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case ISDN_PID_L0_TE_E1: | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(8, port, "TE S2M Stack\n"); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		stack->nt=0; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		stack->pri=1; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case ISDN_PID_L0_NT_E1: | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(8, port, "TE S2M Stack\n"); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		stack->nt=1; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		stack->pri=1; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(0, port, "this is a unknown port type 0x%08x\n", stinf->pid.protocol[0]); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	if (!stack->nt) { | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 		if (stinf->pid.protocol[2] & ISDN_PID_L2_DF_PTP ) { | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 			stack->ptp = 1; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			stack->ptp = 0; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		int ret; | 
					
						
							|  |  |  | 		int nt=stack->nt; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(8, port, "Init. Stack.\n"); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		memset(&li, 0, sizeof(li)); | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			int l = sizeof(li.name); | 
					
						
							|  |  |  | 			strncpy(li.name,nt?"net l2":"user l4", l); | 
					
						
							|  |  |  | 			li.name[l-1] = 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		li.object_id = -1; | 
					
						
							|  |  |  | 		li.extentions = 0; | 
					
						
							|  |  |  | 		li.pid.protocol[nt?2:4] = nt?ISDN_PID_L2_LAPD_NET:ISDN_PID_L4_CAPI20; | 
					
						
							|  |  |  | 		li.pid.layermask = ISDN_LAYER((nt?2:4)); | 
					
						
							|  |  |  | 		li.st = stack->d_stid; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		ret = mISDN_new_layer(midev, &li); | 
					
						
							|  |  |  | 		if (ret) { | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 			cb_log(0, port, "%s: Cannot add layer %d to this port.\n", __FUNCTION__, nt?2:4); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 			return(NULL); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		stack->upper_id = li.id; | 
					
						
							|  |  |  | 		ret = mISDN_register_layer(midev, stack->d_stid, stack->upper_id); | 
					
						
							|  |  |  | 		if (ret) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 			cb_log(0,port,"Cannot register layer %d of this port.\n", nt?2:4); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 			return(NULL); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		stack->lower_id = mISDN_get_layerid(midev, stack->d_stid, nt?1:3); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		if (stack->lower_id < 0) { | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 			cb_log(0, port, "%s: Cannot get layer(%d) id of this port.\n", __FUNCTION__, nt?1:3); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 			return(NULL); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		stack->upper_id = mISDN_get_layerid(midev, stack->d_stid, nt?2:4); | 
					
						
							|  |  |  | 		if (stack->upper_id < 0) { | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 			cb_log(0, port, "%s: Cannot get layer(%d) id of this port.\n", __FUNCTION__, 2); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 			return(NULL); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(8, port, "NT Stacks upper_id %x\n",stack->upper_id); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		/* create nst (nt-mode only) */ | 
					
						
							|  |  |  | 		if (nt) { | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 			memset(&stack->nst, 0, sizeof(net_stack_t)); | 
					
						
							|  |  |  | 			memset(&stack->mgr, 0, sizeof(manager_t)); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 			stack->mgr.nst = &stack->nst; | 
					
						
							|  |  |  | 			stack->nst.manager = &stack->mgr; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 			stack->nst.l3_manager = handle_event_nt; | 
					
						
							|  |  |  | 			stack->nst.device = midev; | 
					
						
							|  |  |  | 			stack->nst.cardnr = port; | 
					
						
							|  |  |  | 			stack->nst.d_stid = stack->d_stid; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 			stack->nst.feature = FEATURE_NET_HOLD; | 
					
						
							|  |  |  | 			if (stack->ptp) | 
					
						
							|  |  |  | 				stack->nst.feature |= FEATURE_NET_PTP; | 
					
						
							|  |  |  | 			if (stack->pri) | 
					
						
							|  |  |  | 				stack->nst.feature |= FEATURE_NET_CRLEN2 | FEATURE_NET_EXTCID; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 			stack->nst.l1_id = stack->lower_id; | 
					
						
							|  |  |  | 			stack->nst.l2_id = stack->upper_id; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 			msg_queue_init(&stack->nst.down_queue); | 
					
						
							| 
									
										
										
										
											2009-07-15 21:14:41 +00:00
										 |  |  | 			pthread_mutex_init(&stack->nstlock, NULL); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 			Isdnl2Init(&stack->nst); | 
					
						
							|  |  |  | 			Isdnl3Init(&stack->nst); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  |  		stack->l1link=0; | 
					
						
							|  |  |  |  		stack->l2link=0; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | 		if (!stack->nt) { | 
					
						
							|  |  |  |  			misdn_lib_get_short_status(stack); | 
					
						
							|  |  |  |  		} else { | 
					
						
							|  |  |  |  			misdn_lib_get_l1_up(stack); | 
					
						
							|  |  |  |  			if (!stack->ptp) misdn_lib_get_l1_up(stack); | 
					
						
							|  |  |  |  			misdn_lib_get_l2_up(stack); | 
					
						
							|  |  |  |  		} | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-08 19:39:37 +00:00
										 |  |  | 		misdn_lib_get_short_status(stack); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		misdn_lib_get_l1_up(stack); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 		misdn_lib_get_l2_up(stack); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 	cb_log(8,0,"stack_init: port:%d lowerId:%x  upperId:%x\n",stack->port,stack->lower_id, stack->upper_id); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	return stack; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | static void stack_destroy(struct misdn_stack *stack) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	char buf[1024]; | 
					
						
							|  |  |  | 	if (!stack) return; | 
					
						
							| 
									
										
										
										
											2006-06-30 14:05:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (stack->nt) { | 
					
						
							| 
									
										
										
										
											2009-07-15 21:14:41 +00:00
										 |  |  | 		pthread_mutex_destroy(&stack->nstlock); | 
					
						
							| 
									
										
										
										
											2006-06-30 14:05:42 +00:00
										 |  |  | 		cleanup_Isdnl2(&stack->nst); | 
					
						
							|  |  |  | 		cleanup_Isdnl3(&stack->nst); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (stack->lower_id) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		mISDN_write_frame(stack->midev, buf, stack->lower_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 	if (stack->upper_id) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		mISDN_write_frame(stack->midev, buf, stack->upper_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC); | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	pthread_mutex_destroy(&stack->st_lock); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static struct misdn_stack * find_stack_by_addr(int  addr) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct misdn_stack *stack; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 	for (stack = glob_mgr->stack_list; stack; stack = stack->next) { | 
					
						
							|  |  |  | 		if ((stack->upper_id & STACK_ID_MASK) == (addr & STACK_ID_MASK)) { | 
					
						
							|  |  |  | 			/* Found the stack */ | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 	return stack; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | static struct misdn_stack *find_stack_by_port(int port) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct misdn_stack *stack; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 	for (stack = glob_mgr->stack_list; stack; stack = stack->next) { | 
					
						
							|  |  |  | 		if (stack->port == port) { | 
					
						
							|  |  |  | 			/* Found the stack */ | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 	return stack; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | static struct misdn_stack *find_stack_by_mgr(manager_t *mgr_nt) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct misdn_stack *stack; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 	for (stack = glob_mgr->stack_list; stack; stack = stack->next) { | 
					
						
							|  |  |  | 		if (&stack->mgr == mgr_nt) { | 
					
						
							|  |  |  | 			/* Found the stack */ | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 	return stack; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static struct misdn_bchannel *find_bc_by_masked_l3id(struct misdn_stack *stack, unsigned long l3id, unsigned long mask) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i <= stack->b_num; ++i) { | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 		if (stack->bc[i].in_use && (stack->bc[i].l3_id & mask) == (l3id & mask)) { | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 			return &stack->bc[i]; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | #if defined(AST_MISDN_ENHANCEMENTS)
 | 
					
						
							|  |  |  | 	/* Search the B channel records for a REGISTER signaling link. */ | 
					
						
							|  |  |  | 	for (i = MAX_BCHANS + 1; i < ARRAY_LEN(stack->bc); ++i) { | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 		if (stack->bc[i].in_use && (stack->bc[i].l3_id & mask) == (l3id & mask)) { | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 			return &stack->bc[i]; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif	/* defined(AST_MISDN_ENHANCEMENTS) */
 | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 	return stack_holder_find(stack, l3id); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct misdn_bchannel *find_bc_by_l3id(struct misdn_stack *stack, unsigned long l3id) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i <= stack->b_num; ++i) { | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 		if (stack->bc[i].in_use && stack->bc[i].l3_id == l3id) { | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 			return &stack->bc[i]; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | #if defined(AST_MISDN_ENHANCEMENTS)
 | 
					
						
							|  |  |  | 	/* Search the B channel records for a REGISTER signaling link. */ | 
					
						
							|  |  |  | 	for (i = MAX_BCHANS + 1; i < ARRAY_LEN(stack->bc); ++i) { | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 		if (stack->bc[i].in_use && stack->bc[i].l3_id == l3id) { | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 			return &stack->bc[i]; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif	/* defined(AST_MISDN_ENHANCEMENTS) */
 | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 	return stack_holder_find(stack, l3id); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static struct misdn_bchannel *find_bc_by_addr(unsigned long addr) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-08-18 16:29:47 +00:00
										 |  |  | 	struct misdn_stack *stack; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 	for (stack = glob_mgr->stack_list; stack; stack = stack->next) { | 
					
						
							|  |  |  | 		for (i = 0; i <= stack->b_num; i++) { | 
					
						
							|  |  |  | 			if (stack->bc[i].in_use | 
					
						
							|  |  |  | 				&& ((stack->bc[i].addr & STACK_ID_MASK) == (addr & STACK_ID_MASK) | 
					
						
							|  |  |  | 					|| stack->bc[i].layer_id == addr)) { | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 				return &stack->bc[i]; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-11 08:23:16 +00:00
										 |  |  | 	return NULL; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-08-18 16:29:47 +00:00
										 |  |  | static struct misdn_bchannel *find_bc_by_confid(unsigned long confid) | 
					
						
							| 
									
										
										
										
											2006-10-11 08:23:16 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-08-18 16:29:47 +00:00
										 |  |  | 	struct misdn_stack *stack; | 
					
						
							| 
									
										
										
										
											2006-10-11 08:23:16 +00:00
										 |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 	for (stack = glob_mgr->stack_list; stack; stack = stack->next) { | 
					
						
							|  |  |  | 		for (i = 0; i <= stack->b_num; i++) { | 
					
						
							|  |  |  | 			if (stack->bc[i].in_use && stack->bc[i].conf_id == confid) { | 
					
						
							| 
									
										
										
										
											2006-10-11 08:23:16 +00:00
										 |  |  | 				return &stack->bc[i]; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static struct misdn_bchannel *find_bc_by_channel(int port, int channel) | 
					
						
							| 
									
										
										
										
											2006-04-05 14:51:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-08-18 16:29:47 +00:00
										 |  |  | 	struct misdn_stack *stack = find_stack_by_port(port); | 
					
						
							| 
									
										
										
										
											2006-04-05 14:51:48 +00:00
										 |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 	if (!stack) { | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 	for (i = 0; i <= stack->b_num; i++) { | 
					
						
							|  |  |  | 		if (stack->bc[i].in_use && stack->bc[i].channel == channel) { | 
					
						
							| 
									
										
										
										
											2006-04-05 14:51:48 +00:00
										 |  |  | 			return &stack->bc[i]; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-05 14:51:48 +00:00
										 |  |  | 	return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int handle_event ( struct misdn_bchannel *bc, enum event_e event, iframe_t *frm) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	struct misdn_stack *stack=get_stack_by_bc(bc); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	if (!stack->nt) { | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		switch (event) { | 
					
						
							| 
									
										
										
										
											2005-11-15 20:20:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		case EVENT_CONNECT_ACKNOWLEDGE: | 
					
						
							| 
									
										
										
										
											2007-06-27 08:08:58 +00:00
										 |  |  | 			setup_bc(bc); | 
					
						
							| 
									
										
										
										
											2007-07-04 14:58:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if ( *bc->crypt_key ) { | 
					
						
							| 
									
										
										
										
											2009-04-03 22:41:46 +00:00
										 |  |  | 				cb_log(4, stack->port, | 
					
						
							|  |  |  | 					"ENABLING BLOWFISH channel:%d caller%d:\"%s\" <%s> dialed%d:%s\n", | 
					
						
							|  |  |  | 					bc->channel, | 
					
						
							|  |  |  | 					bc->caller.number_type, | 
					
						
							|  |  |  | 					bc->caller.name, | 
					
						
							|  |  |  | 					bc->caller.number, | 
					
						
							|  |  |  | 					bc->dialed.number_type, | 
					
						
							|  |  |  | 					bc->dialed.number); | 
					
						
							| 
									
										
										
										
											2007-07-04 14:58:58 +00:00
										 |  |  | 				manager_ph_control_block(bc,  BF_ENABLE_KEY, bc->crypt_key, strlen(bc->crypt_key) ); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (misdn_cap_is_speech(bc->capability)) { | 
					
						
							|  |  |  | 				if (  !bc->nodsp) manager_ph_control(bc,  DTMF_TONE_START, 0); | 
					
						
							|  |  |  | 				manager_ec_enable(bc); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if ( bc->txgain != 0 ) { | 
					
						
							|  |  |  | 					cb_log(4, stack->port, "--> Changing txgain to %d\n", bc->txgain); | 
					
						
							|  |  |  | 					manager_ph_control(bc, VOL_CHANGE_TX, bc->txgain); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				if ( bc->rxgain != 0 ) { | 
					
						
							|  |  |  | 					cb_log(4, stack->port, "--> Changing rxgain to %d\n", bc->rxgain); | 
					
						
							|  |  |  | 					manager_ph_control(bc, VOL_CHANGE_RX, bc->rxgain); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-15 20:20:45 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		case EVENT_CONNECT: | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			if ( *bc->crypt_key ) { | 
					
						
							| 
									
										
										
										
											2009-04-03 22:41:46 +00:00
										 |  |  | 				cb_log(4, stack->port, | 
					
						
							|  |  |  | 					"ENABLING BLOWFISH channel:%d caller%d:\"%s\" <%s> dialed%d:%s\n", | 
					
						
							|  |  |  | 					bc->channel, | 
					
						
							|  |  |  | 					bc->caller.number_type, | 
					
						
							|  |  |  | 					bc->caller.name, | 
					
						
							|  |  |  | 					bc->caller.number, | 
					
						
							|  |  |  | 					bc->dialed.number_type, | 
					
						
							|  |  |  | 					bc->dialed.number); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 				manager_ph_control_block(bc,  BF_ENABLE_KEY, bc->crypt_key, strlen(bc->crypt_key) ); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		case EVENT_ALERTING: | 
					
						
							|  |  |  | 		case EVENT_PROGRESS: | 
					
						
							|  |  |  | 		case EVENT_PROCEEDING: | 
					
						
							|  |  |  | 		case EVENT_SETUP_ACKNOWLEDGE: | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 		case EVENT_SETUP: | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2007-07-02 09:17:07 +00:00
										 |  |  | 			if (bc->channel == 0xff || bc->channel<=0) | 
					
						
							|  |  |  | 				bc->channel=0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (find_free_chan_in_stack(stack, bc, bc->channel, 0)<0){ | 
					
						
							| 
									
										
										
										
											2007-11-12 13:03:00 +00:00
										 |  |  | 				if (!stack->pri && !stack->ptp)  { | 
					
						
							|  |  |  | 					bc->cw=1; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 				if (!bc->channel) { | 
					
						
							| 
									
										
										
										
											2008-06-02 08:46:23 +00:00
										 |  |  | 					cb_log(0, stack->port, "Any Channel Requested, but we have no more!!\n"); | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 					cb_log(0, stack->port, | 
					
						
							|  |  |  | 						"Requested Channel Already in Use releasing this call with cause %d!!!!\n", | 
					
						
							|  |  |  | 						bc->out_cause); | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2008-06-02 08:46:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				/* when the channel is already in use, we can't
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 				 * simply clear it, we need to make sure that | 
					
						
							|  |  |  | 				 * it will still be marked as in_use in the | 
					
						
							| 
									
										
										
										
											2008-06-02 08:46:23 +00:00
										 |  |  | 				 * available channels list.*/ | 
					
						
							|  |  |  | 				bc->channel=0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-02 09:17:07 +00:00
										 |  |  | 				misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE); | 
					
						
							|  |  |  | 				return -1; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2007-08-30 08:50:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 			setup_bc(bc); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		case EVENT_RELEASE_COMPLETE: | 
					
						
							|  |  |  | 		case EVENT_RELEASE: | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		default: | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else {    /** NT MODE **/ | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int handle_cr ( struct misdn_stack *stack, iframe_t *frm) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	struct misdn_bchannel dummybc; | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 	struct misdn_bchannel *bc; | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	int channel; | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	if (!stack) return -1; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	switch (frm->prim) { | 
					
						
							|  |  |  | 	case CC_NEW_CR|INDICATION: | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 		cb_log(7, stack->port, " --> lib: NEW_CR Ind with l3id:%x on this port.\n",frm->dinfo); | 
					
						
							| 
									
										
										
										
											2006-10-27 11:18:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 		bc = misdn_lib_get_free_bc(stack->port, 0, 1, 0); | 
					
						
							| 
									
										
										
										
											2006-10-27 11:18:32 +00:00
										 |  |  | 		if (!bc) { | 
					
						
							|  |  |  | 			cb_log(0, stack->port, " --> !! lib: No free channel!\n"); | 
					
						
							| 
									
										
										
										
											2006-04-10 16:50:20 +00:00
										 |  |  | 			return -1; | 
					
						
							| 
									
										
										
										
											2006-10-11 08:34:03 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-27 11:18:32 +00:00
										 |  |  | 		cb_log(7, stack->port, " --> new_process: New L3Id: %x\n",frm->dinfo); | 
					
						
							|  |  |  | 		bc->l3_id=frm->dinfo; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		return 1; | 
					
						
							|  |  |  | 	case CC_NEW_CR|CONFIRM: | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	case CC_NEW_CR|REQUEST: | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	case CC_RELEASE_CR|REQUEST: | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	case CC_RELEASE_CR|CONFIRM: | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case CC_RELEASE_CR|INDICATION: | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 		cb_log(4, stack->port, " --> lib: RELEASE_CR Ind with l3id:%x\n", frm->dinfo); | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		bc = find_bc_by_l3id(stack, frm->dinfo); | 
					
						
							|  |  |  | 		if (!bc) { | 
					
						
							|  |  |  | 			cb_log(4, stack->port, " --> Didn't find BC so temporarily creating dummy BC (l3id:%x) on this port.\n", frm->dinfo); | 
					
						
							|  |  |  | 			misdn_make_dummy(&dummybc, stack->port, frm->dinfo, stack->nt, 0); | 
					
						
							|  |  |  | 			bc = &dummybc; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2007-06-25 09:37:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		channel = bc->channel; | 
					
						
							|  |  |  | 		cb_log(4, stack->port, " --> lib: CLEANING UP l3id: %x\n", frm->dinfo); | 
					
						
							| 
									
										
											  
											
												Merged revisions 62912 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r62912 | crichter | 2007-05-03 16:36:32 +0200 (Do, 03 Mai 2007) | 17 lines
Merged revisions 61357,61770,62885 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r61357 | crichter | 2007-04-11 14:05:57 +0200 (Mi, 11 Apr 2007) | 1 line
some fixes for PMP Hold/Retrieve, it should work now, when briding=no
........
r61770 | crichter | 2007-04-24 15:50:05 +0200 (Di, 24 Apr 2007) | 1 line
added lock for sending messages to avoid double sending. shuffled some empty_chans after the cb_event calls, this avoids that a release_complete from a quite different call releases a fresh created setup by accident.
........
r62885 | crichter | 2007-05-03 15:59:00 +0200 (Do, 03 Mai 2007) | 1 line
fixed the problem that misdn_write did not return -1 when called with 0 samples in a frame this resultet in a deadlock in some circumstances, when the call ended because of a busy extension.  added encoding of keypad.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@64955 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-05-18 09:50:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		/* bc->pid = 0; */ | 
					
						
							|  |  |  | 		bc->need_disconnect = 0; | 
					
						
							|  |  |  | 		bc->need_release = 0; | 
					
						
							|  |  |  | 		bc->need_release_complete = 0; | 
					
						
							| 
									
										
											  
											
												Merged revisions 62912 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r62912 | crichter | 2007-05-03 16:36:32 +0200 (Do, 03 Mai 2007) | 17 lines
Merged revisions 61357,61770,62885 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r61357 | crichter | 2007-04-11 14:05:57 +0200 (Mi, 11 Apr 2007) | 1 line
some fixes for PMP Hold/Retrieve, it should work now, when briding=no
........
r61770 | crichter | 2007-04-24 15:50:05 +0200 (Di, 24 Apr 2007) | 1 line
added lock for sending messages to avoid double sending. shuffled some empty_chans after the cb_event calls, this avoids that a release_complete from a quite different call releases a fresh created setup by accident.
........
r62885 | crichter | 2007-05-03 15:59:00 +0200 (Do, 03 Mai 2007) | 1 line
fixed the problem that misdn_write did not return -1 when called with 0 samples in a frame this resultet in a deadlock in some circumstances, when the call ended because of a busy extension.  added encoding of keypad.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@64955 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-05-18 09:50:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		cb_event(EVENT_CLEANUP, bc, glob_mgr->user_data); | 
					
						
							| 
									
										
										
										
											2007-06-25 09:37:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		empty_bc(bc); | 
					
						
							|  |  |  | 		clean_up_bc(bc); | 
					
						
							| 
									
										
										
										
											2007-06-25 09:37:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		if (channel > 0) | 
					
						
							|  |  |  | 			empty_chan_in_stack(stack, channel); | 
					
						
							|  |  |  | 		bc->in_use = 0; | 
					
						
							| 
									
										
											  
											
												Merged revisions 62912 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r62912 | crichter | 2007-05-03 16:36:32 +0200 (Do, 03 Mai 2007) | 17 lines
Merged revisions 61357,61770,62885 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r61357 | crichter | 2007-04-11 14:05:57 +0200 (Mi, 11 Apr 2007) | 1 line
some fixes for PMP Hold/Retrieve, it should work now, when briding=no
........
r61770 | crichter | 2007-04-24 15:50:05 +0200 (Di, 24 Apr 2007) | 1 line
added lock for sending messages to avoid double sending. shuffled some empty_chans after the cb_event calls, this avoids that a release_complete from a quite different call releases a fresh created setup by accident.
........
r62885 | crichter | 2007-05-03 15:59:00 +0200 (Do, 03 Mai 2007) | 1 line
fixed the problem that misdn_write did not return -1 when called with 0 samples in a frame this resultet in a deadlock in some circumstances, when the call ended because of a busy extension.  added encoding of keypad.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@64955 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-05-18 09:50:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		dump_chan_list(stack); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		if (bc->stack_holder) { | 
					
						
							|  |  |  | 			cb_log(4, stack->port, "REMOVING Holder\n"); | 
					
						
							|  |  |  | 			stack_holder_remove(stack, bc); | 
					
						
							|  |  |  | 			free(bc); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | /* Empties bc if it's reserved (no SETUP out yet) */ | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | void misdn_lib_release(struct misdn_bchannel *bc) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 	int channel; | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	struct misdn_stack *stack=get_stack_by_bc(bc); | 
					
						
							| 
									
										
										
										
											2005-11-15 20:20:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!stack) { | 
					
						
							|  |  |  | 		cb_log(1,0,"misdn_release: No Stack found\n"); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 	channel = bc->channel; | 
					
						
							| 
									
										
										
										
											2006-07-06 15:11:40 +00:00
										 |  |  | 	empty_bc(bc); | 
					
						
							| 
									
										
										
										
											2006-06-01 12:51:41 +00:00
										 |  |  | 	clean_up_bc(bc); | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 	if (channel > 0) { | 
					
						
							|  |  |  | 		empty_chan_in_stack(stack, channel); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-06-25 09:46:18 +00:00
										 |  |  | 	bc->in_use=0; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | int misdn_lib_get_port_up (int port) | 
					
						
							|  |  |  | { /* Pull Up L1 */ | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	struct misdn_stack *stack; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	for (stack=glob_mgr->stack_list; | 
					
						
							|  |  |  | 	     stack; | 
					
						
							|  |  |  | 	     stack=stack->next) { | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		if (stack->port == port) { | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if (!stack->l1link) | 
					
						
							|  |  |  | 				misdn_lib_get_l1_up(stack); | 
					
						
							|  |  |  | 			if (!stack->l2link) | 
					
						
							|  |  |  | 				misdn_lib_get_l2_up(stack); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | int misdn_lib_get_port_down (int port) | 
					
						
							|  |  |  | { /* Pull Down L1 */ | 
					
						
							| 
									
										
										
										
											2006-03-07 11:16:56 +00:00
										 |  |  | 	struct misdn_stack *stack; | 
					
						
							|  |  |  | 	for (stack=glob_mgr->stack_list; | 
					
						
							|  |  |  | 	     stack; | 
					
						
							|  |  |  | 	     stack=stack->next) { | 
					
						
							|  |  |  | 		if (stack->port == port) { | 
					
						
							|  |  |  | 				if (stack->l2link) | 
					
						
							|  |  |  | 					misdn_lib_get_l2_down(stack); | 
					
						
							|  |  |  | 				misdn_lib_get_l1_down(stack); | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-15 19:32:45 +00:00
										 |  |  | int misdn_lib_port_up(int port, int check) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct misdn_stack *stack; | 
					
						
							| 
									
										
										
										
											2006-02-15 19:32:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	for (stack=glob_mgr->stack_list; | 
					
						
							|  |  |  | 	     stack; | 
					
						
							|  |  |  | 	     stack=stack->next) { | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		if (stack->port == port) { | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if (stack->blocked) { | 
					
						
							|  |  |  | 				cb_log(0,port, "Port Blocked:%d L2:%d L1:%d\n", stack->blocked, stack->l2link, stack->l1link); | 
					
						
							|  |  |  | 				return -1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-29 20:12:19 +00:00
										 |  |  | 			if (stack->ptp ) { | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				if (stack->l1link && stack->l2link) { | 
					
						
							| 
									
										
										
										
											2006-06-29 20:12:19 +00:00
										 |  |  | 					return 1; | 
					
						
							|  |  |  | 				} else { | 
					
						
							| 
									
										
											  
											
												Merged revisions 63534 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r63534 | crichter | 2007-05-09 15:17:10 +0200 (Mi, 09 Mai 2007) | 17 lines
Merged revisions 62945,63402,63519 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r62945 | crichter | 2007-05-03 17:39:21 +0200 (Do, 03 Mai 2007) | 1 line
when we're in state WAITING4DIGS, we use the asterisk tone-generator which prods us, so we can't just return -1 in misdn_write in this case. Added a MISDN_KEYPAD channel variable, and fixed the sending of keypad. this enables us to modify the call forward parameters in the switch.
........
r63402 | crichter | 2007-05-08 17:07:37 +0200 (Di, 08 Mai 2007) | 1 line
added application misdn_check_l2l1 which tries to pull up the L1/L2 on all ports that have the layers down in a group. It waits then for a timeout. This helps for scenarios where multiple PMP BRIs are grouped together, or where a provider has a faulty PTP Implementation, that looses the L2 after a while.
........
r63519 | crichter | 2007-05-09 13:26:16 +0200 (Mi, 09 Mai 2007) | 1 line
release_chan frees ch, so we should never touch ch after release_chan, this may cause segfaults.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@64957 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-05-18 10:00:21 +00:00
										 |  |  | 					cb_log(1,port, "Port Down L2:%d L1:%d\n", | 
					
						
							| 
									
										
										
										
											2006-06-29 20:12:19 +00:00
										 |  |  | 						stack->l2link, stack->l1link); | 
					
						
							|  |  |  | 					return 0; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2007-01-03 11:03:57 +00:00
										 |  |  | 				if ( !check || stack->l1link ) | 
					
						
							| 
									
										
										
										
											2006-06-29 20:12:19 +00:00
										 |  |  | 					return 1; | 
					
						
							|  |  |  | 				else { | 
					
						
							| 
									
										
											  
											
												Merged revisions 63534 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r63534 | crichter | 2007-05-09 15:17:10 +0200 (Mi, 09 Mai 2007) | 17 lines
Merged revisions 62945,63402,63519 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r62945 | crichter | 2007-05-03 17:39:21 +0200 (Do, 03 Mai 2007) | 1 line
when we're in state WAITING4DIGS, we use the asterisk tone-generator which prods us, so we can't just return -1 in misdn_write in this case. Added a MISDN_KEYPAD channel variable, and fixed the sending of keypad. this enables us to modify the call forward parameters in the switch.
........
r63402 | crichter | 2007-05-08 17:07:37 +0200 (Di, 08 Mai 2007) | 1 line
added application misdn_check_l2l1 which tries to pull up the L1/L2 on all ports that have the layers down in a group. It waits then for a timeout. This helps for scenarios where multiple PMP BRIs are grouped together, or where a provider has a faulty PTP Implementation, that looses the L2 after a while.
........
r63519 | crichter | 2007-05-09 13:26:16 +0200 (Mi, 09 Mai 2007) | 1 line
release_chan frees ch, so we should never touch ch after release_chan, this may cause segfaults.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@64957 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-05-18 10:00:21 +00:00
										 |  |  | 					cb_log(1,port, "Port down PMP\n"); | 
					
						
							| 
									
										
										
										
											2006-06-29 20:12:19 +00:00
										 |  |  | 					return 0; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | static int release_cr(struct misdn_stack *stack, mISDNuser_head_t *hh) | 
					
						
							| 
									
										
										
										
											2007-11-12 13:22:17 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct misdn_bchannel *bc=find_bc_by_l3id(stack, hh->dinfo); | 
					
						
							|  |  |  | 	struct misdn_bchannel dummybc; | 
					
						
							|  |  |  | 	iframe_t frm; /* fake te frm to remove callref from global callreflist */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 	frm.dinfo = hh->dinfo; | 
					
						
							| 
									
										
										
										
											2007-11-12 13:22:17 +00:00
										 |  |  | 	frm.addr=stack->upper_id | FLG_MSG_DOWN; | 
					
						
							|  |  |  | 	frm.prim = CC_RELEASE_CR|INDICATION; | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 	cb_log(4, stack->port, " --> CC_RELEASE_CR: Faking Release_cr for %x l3id:%x\n",frm.addr, frm.dinfo); | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-12 13:22:17 +00:00
										 |  |  | 	/** removing procid **/ | 
					
						
							|  |  |  | 	if (!bc) { | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 		cb_log(4, stack->port, " --> Didn't find BC so temporarily creating dummy BC (l3id:%x) on this port.\n", hh->dinfo); | 
					
						
							| 
									
										
										
										
											2007-11-12 13:22:17 +00:00
										 |  |  | 		misdn_make_dummy(&dummybc, stack->port, hh->dinfo, stack->nt, 0); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 		bc=&dummybc; | 
					
						
							| 
									
										
										
										
											2007-11-12 13:22:17 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	if ((bc->l3_id & 0xff00) == 0xff00) { | 
					
						
							|  |  |  | 		cb_log(4, stack->port, " --> Removing Process Id:%x on this port.\n", bc->l3_id & 0xff); | 
					
						
							|  |  |  | 		stack->procids[bc->l3_id & 0xff] = 0; | 
					
						
							| 
									
										
										
										
											2007-11-12 13:22:17 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (handle_cr(stack, &frm)<0) { | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0 ; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | static int handle_event_nt(void *dat, void *arg) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	struct misdn_bchannel dummybc; | 
					
						
							|  |  |  | 	struct misdn_bchannel *bc; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	manager_t *mgr = (manager_t *)dat; | 
					
						
							|  |  |  | 	msg_t *msg = (msg_t *)arg; | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	msg_t *dmsg; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	mISDNuser_head_t *hh; | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	struct misdn_stack *stack; | 
					
						
							|  |  |  | 	enum event_e event; | 
					
						
							| 
									
										
										
										
											2006-03-27 10:13:11 +00:00
										 |  |  | 	int reject=0; | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	int l3id; | 
					
						
							|  |  |  | 	int channel; | 
					
						
							|  |  |  | 	int tmpcause; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!msg || !mgr) | 
					
						
							|  |  |  | 		return(-EINVAL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	stack = find_stack_by_mgr(mgr); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	hh=(mISDNuser_head_t*)msg->data; | 
					
						
							| 
									
										
										
										
											2009-07-15 21:14:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * When we are called from the mISDNuser lib, the nstlock is held and it | 
					
						
							|  |  |  | 	 * must be held when we return.  We unlock here because the lib may be | 
					
						
							|  |  |  | 	 * entered again recursively. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	pthread_mutex_unlock(&stack->nstlock); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 	cb_log(5, stack->port, " --> lib: prim %x dinfo %x\n",hh->prim, hh->dinfo); | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	switch(hh->prim) { | 
					
						
							|  |  |  | 	case CC_RETRIEVE|INDICATION: | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		struct misdn_bchannel *hold_bc; | 
					
						
							|  |  |  | 		iframe_t frm; /* fake te frm to add callref to global callreflist */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		frm.dinfo = hh->dinfo; | 
					
						
							|  |  |  | 		frm.addr=stack->upper_id | FLG_MSG_DOWN; | 
					
						
							|  |  |  | 		frm.prim = CC_NEW_CR|INDICATION; | 
					
						
							|  |  |  | 		if (handle_cr( stack, &frm)< 0) { | 
					
						
							|  |  |  | 			goto ERR_NO_CHANNEL; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		bc = find_bc_by_l3id(stack, hh->dinfo); | 
					
						
							|  |  |  | 		hold_bc = stack_holder_find(stack, bc->l3_id); | 
					
						
							|  |  |  | 		cb_log(4, stack->port, "bc_l3id:%x holded_bc_l3id:%x\n",bc->l3_id, hold_bc->l3_id); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		if (hold_bc) { | 
					
						
							|  |  |  | 			cb_log(4, stack->port, "REMOVING Holder\n"); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 			/* swap the backup to our new channel back */ | 
					
						
							|  |  |  | 			stack_holder_remove(stack, hold_bc); | 
					
						
							|  |  |  | 			memcpy(bc, hold_bc, sizeof(*bc)); | 
					
						
							|  |  |  | 			free(hold_bc); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 			bc->holded=0; | 
					
						
							|  |  |  | 			bc->b_stid=0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	case CC_SETUP | CONFIRM: | 
					
						
							|  |  |  | 		l3id = *((int *) (msg->data + mISDNUSER_HEAD_SIZE)); | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		cb_log(4, stack->port, " --> lib: Event_ind:SETUP CONFIRM [NT] : new L3ID is %x\n", l3id); | 
					
						
							| 
									
										
										
										
											2006-10-11 08:23:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		bc = find_bc_by_l3id(stack, hh->dinfo); | 
					
						
							|  |  |  | 		if (bc) { | 
					
						
							|  |  |  | 			cb_log (2, bc->port, "I IND :CC_SETUP|CONFIRM: old l3id:%x new l3id:%x\n", bc->l3_id, l3id); | 
					
						
							|  |  |  | 			bc->l3_id = l3id; | 
					
						
							|  |  |  | 			cb_event(EVENT_NEW_L3ID, bc, glob_mgr->user_data); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			cb_log(4, stack->port, "Bc Not found (after SETUP CONFIRM)\n"); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		free_msg(msg); | 
					
						
							| 
									
										
										
										
											2009-07-15 21:14:41 +00:00
										 |  |  | 		pthread_mutex_lock(&stack->nstlock); | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	case CC_SETUP | INDICATION: | 
					
						
							|  |  |  | 		bc = misdn_lib_get_free_bc(stack->port, 0, 1, 0); | 
					
						
							|  |  |  | 		if (!bc) { | 
					
						
							|  |  |  | 			goto ERR_NO_CHANNEL; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		cb_log(4, stack->port, " --> new_process: New L3Id: %x\n",hh->dinfo); | 
					
						
							|  |  |  | 		bc->l3_id=hh->dinfo; | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | #if defined(AST_MISDN_ENHANCEMENTS)
 | 
					
						
							|  |  |  | 	case CC_REGISTER | CONFIRM: | 
					
						
							|  |  |  | 		l3id = *((int *) (msg->data + mISDNUSER_HEAD_SIZE)); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		cb_log(4, stack->port, " --> lib: Event_ind:REGISTER CONFIRM [NT] : new L3ID is %x\n", l3id); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		bc = find_bc_by_l3id(stack, hh->dinfo); | 
					
						
							|  |  |  | 		if (bc) { | 
					
						
							|  |  |  | 			cb_log (2, bc->port, "I IND :CC_REGISTER|CONFIRM: old l3id:%x new l3id:%x\n", bc->l3_id, l3id); | 
					
						
							|  |  |  | 			bc->l3_id = l3id; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			cb_log(4, stack->port, "Bc Not found (after REGISTER CONFIRM)\n"); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		free_msg(msg); | 
					
						
							| 
									
										
										
										
											2009-07-15 21:14:41 +00:00
										 |  |  | 		pthread_mutex_lock(&stack->nstlock); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | #endif	/* defined(AST_MISDN_ENHANCEMENTS) */
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | #if defined(AST_MISDN_ENHANCEMENTS)
 | 
					
						
							|  |  |  | 	case CC_REGISTER | INDICATION: | 
					
						
							|  |  |  | 		bc = misdn_lib_get_register_bc(stack->port); | 
					
						
							|  |  |  | 		if (!bc) { | 
					
						
							|  |  |  | 			goto ERR_NO_CHANNEL; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		cb_log(4, stack->port, " --> new_process: New L3Id: %x\n",hh->dinfo); | 
					
						
							|  |  |  | 		bc->l3_id=hh->dinfo; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | #endif	/* defined(AST_MISDN_ENHANCEMENTS) */
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	case CC_CONNECT_ACKNOWLEDGE|INDICATION: | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	case CC_ALERTING|INDICATION: | 
					
						
							|  |  |  | 	case CC_PROCEEDING|INDICATION: | 
					
						
							|  |  |  | 	case CC_SETUP_ACKNOWLEDGE|INDICATION: | 
					
						
							|  |  |  | 	case CC_CONNECT|INDICATION: | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	case CC_DISCONNECT|INDICATION: | 
					
						
							|  |  |  | 		bc = find_bc_by_l3id(stack, hh->dinfo); | 
					
						
							|  |  |  | 		if (!bc) { | 
					
						
							|  |  |  | 			bc=find_bc_by_masked_l3id(stack, hh->dinfo, 0xffff0000); | 
					
						
							|  |  |  | 			if (bc) { | 
					
						
							|  |  |  | 				int myprocid=bc->l3_id&0x0000ffff; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				hh->dinfo=(hh->dinfo&0xffff0000)|myprocid; | 
					
						
							|  |  |  | 				cb_log(3,stack->port,"Reject dinfo: %x cause:%d\n",hh->dinfo,bc->cause); | 
					
						
							|  |  |  | 				reject=1; | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	case CC_FACILITY|INDICATION: | 
					
						
							|  |  |  | 		bc = find_bc_by_l3id(stack, hh->dinfo); | 
					
						
							|  |  |  | 		if (!bc) { | 
					
						
							|  |  |  | 			bc=find_bc_by_masked_l3id(stack, hh->dinfo, 0xffff0000); | 
					
						
							|  |  |  | 			if (bc) { | 
					
						
							|  |  |  | 				int myprocid=bc->l3_id&0x0000ffff; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				hh->dinfo=(hh->dinfo&0xffff0000)|myprocid; | 
					
						
							|  |  |  | 				cb_log(4,bc->port,"Repaired reject Bug, new dinfo: %x\n",hh->dinfo); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	case CC_RELEASE_COMPLETE|INDICATION: | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	case CC_SUSPEND|INDICATION: | 
					
						
							|  |  |  | 		cb_log(4, stack->port, " --> Got Suspend, sending Reject for now\n"); | 
					
						
							|  |  |  | 		dmsg = create_l3msg(CC_SUSPEND_REJECT | REQUEST,MT_SUSPEND_REJECT, hh->dinfo,sizeof(RELEASE_COMPLETE_t), 1); | 
					
						
							| 
									
										
										
										
											2009-07-15 21:14:41 +00:00
										 |  |  | 		pthread_mutex_lock(&stack->nstlock); | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		stack->nst.manager_l3(&stack->nst, dmsg); | 
					
						
							|  |  |  | 		free_msg(msg); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2007-11-12 13:22:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	case CC_RESUME|INDICATION: | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	case CC_RELEASE|CONFIRM: | 
					
						
							|  |  |  | 		bc = find_bc_by_l3id(stack, hh->dinfo); | 
					
						
							|  |  |  | 		if (bc) { | 
					
						
							|  |  |  | 			cb_log(1, stack->port, "CC_RELEASE|CONFIRM (l3id:%x), sending RELEASE_COMPLETE\n", hh->dinfo); | 
					
						
							|  |  |  | 			misdn_lib_send_event(bc, EVENT_RELEASE_COMPLETE); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	case CC_RELEASE|INDICATION: | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	case CC_RELEASE_CR|INDICATION: | 
					
						
							|  |  |  | 		release_cr(stack, hh); | 
					
						
							|  |  |  | 		free_msg(msg); | 
					
						
							| 
									
										
										
										
											2009-07-15 21:14:41 +00:00
										 |  |  | 		pthread_mutex_lock(&stack->nstlock); | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	case CC_NEW_CR|INDICATION: | 
					
						
							|  |  |  | 		/*  Got New CR for bchan, for now I handle this one in */ | 
					
						
							|  |  |  | 		/*  connect_ack, Need to be changed */ | 
					
						
							|  |  |  | 		l3id = *((int *) (msg->data + mISDNUSER_HEAD_SIZE)); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		bc = find_bc_by_l3id(stack, hh->dinfo); | 
					
						
							|  |  |  | 		if (!bc) { | 
					
						
							|  |  |  | 			cb_log(0, stack->port, " --> In NEW_CR: didn't found bc ??\n"); | 
					
						
							| 
									
										
										
										
											2009-07-15 21:14:41 +00:00
										 |  |  | 			pthread_mutex_lock(&stack->nstlock); | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 			return -1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (((l3id&0xff00)!=0xff00) && ((bc->l3_id&0xff00)==0xff00)) { | 
					
						
							|  |  |  | 			cb_log(4, stack->port, " --> Removing Process Id:%x on this port.\n", 0xff&bc->l3_id); | 
					
						
							|  |  |  | 			stack->procids[bc->l3_id&0xff] = 0 ; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		cb_log(4, stack->port, "lib: Event_ind:CC_NEW_CR : very new L3ID  is %x\n",l3id ); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		bc->l3_id =l3id; | 
					
						
							|  |  |  | 		if (!bc->is_register_pool) { | 
					
						
							|  |  |  | 			cb_event(EVENT_NEW_L3ID, bc, glob_mgr->user_data); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		free_msg(msg); | 
					
						
							| 
									
										
										
										
											2009-07-15 21:14:41 +00:00
										 |  |  | 		pthread_mutex_lock(&stack->nstlock); | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2007-11-12 13:33:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	case DL_ESTABLISH | INDICATION: | 
					
						
							|  |  |  | 	case DL_ESTABLISH | CONFIRM: | 
					
						
							|  |  |  | 		cb_log(3, stack->port, "%% GOT L2 Activate Info.\n"); | 
					
						
							| 
									
										
										
										
											2007-11-12 13:33:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		if (stack->ptp && stack->l2link) { | 
					
						
							|  |  |  | 			cb_log(0, stack->port, "%% GOT L2 Activate Info. but we're activated already.. this l2 is faulty, blocking port\n"); | 
					
						
							|  |  |  | 			cb_event(EVENT_PORT_ALARM, &stack->bc[0], glob_mgr->user_data); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		if (stack->ptp && !stack->restart_sent) { | 
					
						
							|  |  |  | 			/* make sure we restart the interface of the
 | 
					
						
							|  |  |  | 			 * other side */ | 
					
						
							|  |  |  | 			stack->restart_sent=1; | 
					
						
							|  |  |  | 			misdn_lib_send_restart(stack->port, -1); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		/* when we get the L2 UP, the L1 is UP definitely too*/ | 
					
						
							|  |  |  | 		stack->l2link = 1; | 
					
						
							|  |  |  | 		stack->l2upcnt=0; | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		free_msg(msg); | 
					
						
							| 
									
										
										
										
											2009-07-15 21:14:41 +00:00
										 |  |  | 		pthread_mutex_lock(&stack->nstlock); | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2006-06-30 14:05:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	case DL_RELEASE | INDICATION: | 
					
						
							|  |  |  | 	case DL_RELEASE | CONFIRM: | 
					
						
							|  |  |  | 		if (stack->ptp) { | 
					
						
							|  |  |  | 			cb_log(3 , stack->port, "%% GOT L2 DeActivate Info.\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (stack->l2upcnt>3) { | 
					
						
							|  |  |  | 				cb_log(0 , stack->port, "!!! Could not Get the L2 up after 3 Attempts!!!\n"); | 
					
						
							|  |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2006-07-10 11:06:47 +00:00
										 |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 				if (stack->nt) | 
					
						
							|  |  |  | 					misdn_lib_reinit_nt_stack(stack->port); | 
					
						
							| 
									
										
										
										
											2006-07-10 11:06:47 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 				if (stack->l1link) { | 
					
						
							|  |  |  | 					misdn_lib_get_l2_up(stack); | 
					
						
							|  |  |  | 					stack->l2upcnt++; | 
					
						
							| 
									
										
										
										
											2006-06-29 20:12:19 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		} else | 
					
						
							|  |  |  | 			cb_log(3, stack->port, "%% GOT L2 DeActivate Info.\n"); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		stack->l2link = 0; | 
					
						
							|  |  |  | 		free_msg(msg); | 
					
						
							| 
									
										
										
										
											2009-07-15 21:14:41 +00:00
										 |  |  | 		pthread_mutex_lock(&stack->nstlock); | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	/*  Parse Events and fire_up to App. */ | 
					
						
							|  |  |  | 	event = isdn_msg_get_event(msgs_g, msg, 1); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	bc = find_bc_by_l3id(stack, hh->dinfo); | 
					
						
							|  |  |  | 	if (!bc) { | 
					
						
							|  |  |  | 		cb_log(4, stack->port, " --> Didn't find BC so temporarily creating dummy BC (l3id:%x).\n", hh->dinfo); | 
					
						
							|  |  |  | 		misdn_make_dummy(&dummybc, stack->port,  hh->dinfo, stack->nt, 0); | 
					
						
							|  |  |  | 		bc = &dummybc; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	isdn_msg_parse_event(msgs_g, msg, bc, 1); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	switch (event) { | 
					
						
							|  |  |  | 	case EVENT_SETUP: | 
					
						
							|  |  |  | 		if (bc->channel <= 0 || bc->channel == 0xff) { | 
					
						
							|  |  |  | 			bc->channel = 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (find_free_chan_in_stack(stack, bc, bc->channel, 0) < 0) { | 
					
						
							|  |  |  | 			goto ERR_NO_CHANNEL; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case EVENT_RELEASE: | 
					
						
							|  |  |  | 	case EVENT_RELEASE_COMPLETE: | 
					
						
							|  |  |  | 		channel = bc->channel; | 
					
						
							|  |  |  | 		tmpcause = bc->cause; | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		empty_bc(bc); | 
					
						
							|  |  |  | 		bc->cause = tmpcause; | 
					
						
							|  |  |  | 		clean_up_bc(bc); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		if (channel > 0) | 
					
						
							|  |  |  | 			empty_chan_in_stack(stack, channel); | 
					
						
							|  |  |  | 		bc->in_use = 0; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	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); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		if (reject) { | 
					
						
							|  |  |  | 			switch(bc->cause) { | 
					
						
							|  |  |  | 			case AST_CAUSE_USER_BUSY: | 
					
						
							|  |  |  | 				cb_log(1, stack->port, "Siemens Busy reject..\n"); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			default: | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		cb_event(event, bc, glob_mgr->user_data); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	free_msg(msg); | 
					
						
							| 
									
										
										
										
											2009-07-15 21:14:41 +00:00
										 |  |  | 	pthread_mutex_lock(&stack->nstlock); | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | ERR_NO_CHANNEL: | 
					
						
							|  |  |  | 	cb_log(4, stack->port, "Patch from MEIDANIS:Sending RELEASE_COMPLETE %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); | 
					
						
							| 
									
										
										
										
											2009-07-15 21:14:41 +00:00
										 |  |  | 	pthread_mutex_lock(&stack->nstlock); | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	stack->nst.manager_l3(&stack->nst, dmsg); | 
					
						
							|  |  |  | 	free_msg(msg); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int handle_timers(msg_t* msg) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	iframe_t *frm= (iframe_t*)msg->data; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 	struct misdn_stack *stack; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	/* Timer Stuff */ | 
					
						
							|  |  |  | 	switch (frm->prim) { | 
					
						
							|  |  |  | 	case MGR_INITTIMER | CONFIRM: | 
					
						
							|  |  |  | 	case MGR_ADDTIMER | CONFIRM: | 
					
						
							|  |  |  | 	case MGR_DELTIMER | CONFIRM: | 
					
						
							|  |  |  | 	case MGR_REMOVETIMER | CONFIRM: | 
					
						
							|  |  |  | 		free_msg(msg); | 
					
						
							|  |  |  | 		return(1); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	if (frm->prim==(MGR_TIMER | INDICATION) ) { | 
					
						
							|  |  |  | 		for (stack = glob_mgr->stack_list; | 
					
						
							|  |  |  | 		     stack; | 
					
						
							|  |  |  | 		     stack = stack->next) { | 
					
						
							|  |  |  | 			itimer_t *it; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 			if (!stack->nt) continue; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			it = stack->nst.tlist; | 
					
						
							|  |  |  | 			/* find timer */ | 
					
						
							|  |  |  | 			for(it=stack->nst.tlist; | 
					
						
							|  |  |  | 			    it; | 
					
						
							|  |  |  | 			    it=it->next) { | 
					
						
							|  |  |  | 				if (it->id == (int)frm->addr) | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (it) { | 
					
						
							|  |  |  | 				int ret; | 
					
						
							|  |  |  | 				ret = mISDN_write_frame(stack->midev, msg->data, frm->addr, | 
					
						
							|  |  |  | 							MGR_TIMER | RESPONSE, 0, 0, NULL, TIMEOUT_1SEC); | 
					
						
							|  |  |  | 				test_and_clear_bit(FLG_TIMER_RUNING, (long unsigned int *)&it->Flags); | 
					
						
							| 
									
										
										
										
											2009-07-15 21:14:41 +00:00
										 |  |  | 				pthread_mutex_lock(&stack->nstlock); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 				ret = it->function(it->data); | 
					
						
							| 
									
										
										
										
											2009-07-15 21:14:41 +00:00
										 |  |  | 				pthread_mutex_unlock(&stack->nstlock); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 				free_msg(msg); | 
					
						
							|  |  |  | 				return 1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(0, 0, "Timer Msg without Timer ??\n"); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		free_msg(msg); | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | void misdn_lib_tone_generator_start(struct misdn_bchannel *bc) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	bc->generate_tone=1; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | void misdn_lib_tone_generator_stop(struct misdn_bchannel *bc) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	bc->generate_tone=0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | static int do_tone(struct misdn_bchannel *bc, int len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	bc->tone_cnt=len; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	if (bc->generate_tone) { | 
					
						
							|  |  |  | 		cb_event(EVENT_TONE_GENERATE, bc, glob_mgr->user_data); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 		if ( !bc->nojitter ) { | 
					
						
							|  |  |  | 			misdn_tx_jitter(bc,len); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 		return 1; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-11 08:34:03 +00:00
										 |  |  | #ifdef MISDN_SAVE_DATA
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | static void misdn_save_data(int id, char *p1, int l1, char *p2, int l2) | 
					
						
							| 
									
										
										
										
											2006-10-11 08:34:03 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	char n1[32],n2[32]; | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 	FILE *rx, *tx; | 
					
						
							| 
									
										
										
										
											2006-10-11 08:34:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	sprintf(n1,"/tmp/misdn-rx-%d.raw",id); | 
					
						
							|  |  |  | 	sprintf(n2,"/tmp/misdn-tx-%d.raw",id); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 	rx = fopen(n1,"a+"); | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 	tx = fopen(n2,"a+"); | 
					
						
							| 
									
										
										
										
											2006-10-11 08:34:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!rx || !tx) { | 
					
						
							|  |  |  | 		cb_log(0,0,"Couldn't open files: %s\n",strerror(errno)); | 
					
						
							| 
									
										
										
										
											2009-06-18 16:37:42 +00:00
										 |  |  | 		if (rx) | 
					
						
							|  |  |  | 			fclose(rx); | 
					
						
							|  |  |  | 		if (tx) | 
					
						
							|  |  |  | 			fclose(tx); | 
					
						
							| 
									
										
										
										
											2006-10-11 08:34:03 +00:00
										 |  |  | 		return ; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-11 08:34:03 +00:00
										 |  |  | 	fwrite(p1,1,l1,rx); | 
					
						
							|  |  |  | 	fwrite(p2,1,l2,tx); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-11 08:34:03 +00:00
										 |  |  | 	fclose(rx); | 
					
						
							|  |  |  | 	fclose(tx); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | void misdn_tx_jitter(struct misdn_bchannel *bc, int len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	char buf[4096 + mISDN_HEADER_LEN]; | 
					
						
							| 
									
										
										
										
											2006-06-06 09:40:41 +00:00
										 |  |  | 	char *data=&buf[mISDN_HEADER_LEN]; | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	iframe_t *txfrm= (iframe_t*)buf; | 
					
						
							|  |  |  | 	int jlen, r; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-06 09:40:41 +00:00
										 |  |  | 	jlen=cb_jb_empty(bc,data,len); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	if (jlen) { | 
					
						
							| 
									
										
										
										
											2006-10-11 08:34:03 +00:00
										 |  |  | #ifdef MISDN_SAVE_DATA
 | 
					
						
							|  |  |  | 		misdn_save_data((bc->port*100+bc->channel), data, jlen, bc->bframe, bc->bframe_len); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2006-06-06 09:40:41 +00:00
										 |  |  | 		flip_buf_bits( data, jlen); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 		if (jlen < len) { | 
					
						
							| 
									
										
										
										
											2009-04-17 21:48:10 +00:00
										 |  |  | 			cb_log(1, bc->port, "Jitterbuffer Underrun. Got %d of expected %d\n", jlen, len); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 		txfrm->prim = DL_DATA|REQUEST; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 		txfrm->dinfo = 0; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 		txfrm->addr = bc->addr|FLG_MSG_DOWN; /*  | IF_DOWN; */ | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 		txfrm->len =jlen; | 
					
						
							|  |  |  | 		cb_log(9, bc->port, "Transmitting %d samples 2 misdn\n", txfrm->len); | 
					
						
							| 
									
										
										
										
											2006-10-11 08:34:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 		r=mISDN_write( glob_mgr->midev, buf, txfrm->len + mISDN_HEADER_LEN, 8000 ); | 
					
						
							| 
									
										
										
										
											2006-06-06 09:40:41 +00:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2006-06-26 17:37:11 +00:00
										 |  |  | #define MISDN_GEN_SILENCE
 | 
					
						
							| 
									
										
										
										
											2006-06-06 09:40:41 +00:00
										 |  |  | #ifdef MISDN_GEN_SILENCE
 | 
					
						
							|  |  |  | 		int cnt=len/TONE_SILENCE_SIZE; | 
					
						
							|  |  |  | 		int rest=len%TONE_SILENCE_SIZE; | 
					
						
							|  |  |  | 		int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (i=0; i<cnt; i++) { | 
					
						
							|  |  |  | 			memcpy(data, tone_silence_flip, TONE_SILENCE_SIZE ); | 
					
						
							|  |  |  | 			data +=TONE_SILENCE_SIZE; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (rest) { | 
					
						
							|  |  |  | 			memcpy(data, tone_silence_flip, rest); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		txfrm->prim = DL_DATA|REQUEST; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		txfrm->dinfo = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		txfrm->addr = bc->addr|FLG_MSG_DOWN; /*  | IF_DOWN; */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		txfrm->len =len; | 
					
						
							| 
									
										
										
										
											2009-04-17 21:48:10 +00:00
										 |  |  | 		cb_log(5, bc->port, "Transmitting %d samples of silence to misdn\n", len); | 
					
						
							| 
									
										
										
										
											2006-06-06 09:40:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		r=mISDN_write( glob_mgr->midev, buf, txfrm->len + mISDN_HEADER_LEN, 8000 ); | 
					
						
							| 
									
										
										
										
											2009-04-17 21:48:10 +00:00
										 |  |  | #else
 | 
					
						
							|  |  |  | 		r = 0; | 
					
						
							| 
									
										
										
										
											2006-06-06 09:40:41 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-04-17 21:48:10 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-06-06 09:40:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-17 21:48:10 +00:00
										 |  |  | 	if (r < 0) { | 
					
						
							|  |  |  | 		cb_log(1, bc->port, "Error in mISDN_write (%s)\n", strerror(errno)); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int handle_bchan(msg_t *msg) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	iframe_t *frm= (iframe_t*)msg->data; | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 	struct misdn_bchannel *bc=find_bc_by_addr(frm->addr); | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 	struct misdn_stack *stack; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	if (!bc) { | 
					
						
							| 
									
										
										
										
											2006-06-26 17:37:11 +00:00
										 |  |  | 		cb_log(1,0,"handle_bchan: BC not found for prim:%x with addr:%x dinfo:%x\n", frm->prim, frm->addr, frm->dinfo); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		return 0 ; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 	stack = get_stack_by_bc(bc); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	if (!stack) { | 
					
						
							| 
									
										
										
										
											2006-02-08 16:10:21 +00:00
										 |  |  | 		cb_log(0, bc->port,"handle_bchan: STACK not found for prim:%x with addr:%x dinfo:%x\n", frm->prim, frm->addr, frm->dinfo); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	switch (frm->prim) { | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	case MGR_SETSTACK| CONFIRM: | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(3, stack->port, "BCHAN: MGR_SETSTACK|CONFIRM pid:%d\n",bc->pid); | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	case MGR_SETSTACK| INDICATION: | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(3, stack->port, "BCHAN: MGR_SETSTACK|IND pid:%d\n",bc->pid); | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 	break; | 
					
						
							|  |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2006-04-29 22:56:00 +00:00
										 |  |  | 	AGAIN: | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		bc->addr = mISDN_get_layerid(stack->midev, bc->b_stid, bc->layer); | 
					
						
							|  |  |  | 		if (!bc->addr) { | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-29 22:56:00 +00:00
										 |  |  | 			if (errno == EAGAIN) { | 
					
						
							|  |  |  | 				usleep(1000); | 
					
						
							|  |  |  | 				goto AGAIN; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-29 22:56:00 +00:00
										 |  |  | 			cb_log(0,stack->port,"$$$ Get Layer (%d) Id Error: %s\n",bc->layer,strerror(errno)); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 			/* we kill the channel later, when we received some
 | 
					
						
							|  |  |  | 			   data. */ | 
					
						
							|  |  |  | 			bc->addr= frm->addr; | 
					
						
							| 
									
										
										
										
											2006-05-23 12:38:06 +00:00
										 |  |  | 		} else if ( bc->addr < 0) { | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 			cb_log(0, stack->port,"$$$ bc->addr <0 Error:%s\n",strerror(errno)); | 
					
						
							| 
									
										
										
										
											2006-05-23 12:38:06 +00:00
										 |  |  | 			bc->addr=0; | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		cb_log(4, stack->port," --> Got Adr %x\n", bc->addr); | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		free_msg(msg); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-17 10:37:35 +00:00
										 |  |  | 		switch(bc->bc_state) { | 
					
						
							|  |  |  | 		case BCHAN_SETUP: | 
					
						
							|  |  |  | 			bc_state_change(bc,BCHAN_SETUPED); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		case BCHAN_CLEAN_REQUEST: | 
					
						
							|  |  |  | 		default: | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 			cb_log(0, stack->port," --> STATE WASN'T SETUP (but %s) in SETSTACK|IND pid:%d\n",bc_state2str(bc->bc_state), bc->pid); | 
					
						
							| 
									
										
										
										
											2006-06-17 10:37:35 +00:00
										 |  |  | 			clean_up_bc(bc); | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		return 1; | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	case MGR_DELLAYER| INDICATION: | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(3, stack->port, "BCHAN: MGR_DELLAYER|IND pid:%d\n",bc->pid); | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	case MGR_DELLAYER| CONFIRM: | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(3, stack->port, "BCHAN: MGR_DELLAYER|CNF pid:%d\n",bc->pid); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 		bc->pid=0; | 
					
						
							|  |  |  | 		bc->addr=0; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		free_msg(msg); | 
					
						
							|  |  |  | 		return 1; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	case PH_ACTIVATE | INDICATION: | 
					
						
							|  |  |  | 	case DL_ESTABLISH | INDICATION: | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(3, stack->port, "BCHAN: ACT Ind pid:%d\n", bc->pid); | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		free_msg(msg); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 		return 1; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	case PH_ACTIVATE | CONFIRM: | 
					
						
							|  |  |  | 	case DL_ESTABLISH | CONFIRM: | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(3, stack->port, "BCHAN: bchan ACT Confirm pid:%d\n",bc->pid); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		free_msg(msg); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return 1; | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	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; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	case PH_DEACTIVATE | INDICATION: | 
					
						
							|  |  |  | 	case DL_RELEASE | INDICATION: | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log (3, stack->port, "BCHAN: DeACT Ind pid:%d\n",bc->pid); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		free_msg(msg); | 
					
						
							|  |  |  | 		return 1; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	case PH_DEACTIVATE | CONFIRM: | 
					
						
							|  |  |  | 	case DL_RELEASE | CONFIRM: | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(3, stack->port, "BCHAN: DeACT Conf pid:%d\n",bc->pid); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		free_msg(msg); | 
					
						
							|  |  |  | 		return 1; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	case PH_CONTROL|INDICATION: | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2008-03-11 15:13:38 +00:00
										 |  |  | 		unsigned int *cont = (unsigned int *) &frm->data.p; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-03 22:41:46 +00:00
										 |  |  | 		cb_log(4, stack->port, | 
					
						
							|  |  |  | 			"PH_CONTROL: channel:%d caller%d:\"%s\" <%s> dialed%d:%s \n", | 
					
						
							|  |  |  | 			bc->channel, | 
					
						
							|  |  |  | 			bc->caller.number_type, | 
					
						
							|  |  |  | 			bc->caller.name, | 
					
						
							|  |  |  | 			bc->caller.number, | 
					
						
							|  |  |  | 			bc->dialed.number_type, | 
					
						
							|  |  |  | 			bc->dialed.number); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-11 15:13:38 +00:00
										 |  |  | 		if ((*cont & ~DTMF_TONE_MASK) == DTMF_TONE_VAL) { | 
					
						
							|  |  |  | 			int dtmf = *cont & DTMF_TONE_MASK; | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 			cb_log(4, stack->port, " --> DTMF TONE: %c\n",dtmf); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			bc->dtmf=dtmf; | 
					
						
							|  |  |  | 			cb_event(EVENT_DTMF_TONE, bc, glob_mgr->user_data); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			free_msg(msg); | 
					
						
							|  |  |  | 			return 1; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-03-11 15:13:38 +00:00
										 |  |  | 		if (*cont == BF_REJECT) { | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 			cb_log(4, stack->port, " --> BF REJECT\n"); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			free_msg(msg); | 
					
						
							|  |  |  | 			return 1; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-03-11 15:13:38 +00:00
										 |  |  | 		if (*cont == BF_ACCEPT) { | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 			cb_log(4, stack->port, " --> BF ACCEPT\n"); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			free_msg(msg); | 
					
						
							|  |  |  | 			return 1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	break; | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	case PH_DATA|REQUEST: | 
					
						
							|  |  |  | 	case DL_DATA|REQUEST: | 
					
						
							|  |  |  | 		cb_log(0, stack->port, "DL_DATA REQUEST \n"); | 
					
						
							|  |  |  | 		do_tone(bc, 64); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		free_msg(msg); | 
					
						
							|  |  |  | 		return 1; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	case PH_DATA|INDICATION: | 
					
						
							|  |  |  | 	case DL_DATA|INDICATION: | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		bc->bframe = (void*)&frm->data.i; | 
					
						
							|  |  |  | 		bc->bframe_len = frm->len; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/** Anyway flip the bufbits **/ | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 		if ( misdn_cap_is_speech(bc->capability) ) | 
					
						
							| 
									
										
										
										
											2005-11-15 20:20:45 +00:00
										 |  |  | 			flip_buf_bits(bc->bframe, bc->bframe_len); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (!bc->bframe_len) { | 
					
						
							|  |  |  | 			cb_log(2, stack->port, "DL_DATA INDICATION bc->addr:%x frm->addr:%x\n", bc->addr, frm->addr); | 
					
						
							|  |  |  | 			free_msg(msg); | 
					
						
							|  |  |  | 			return 1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if ( (bc->addr&STACK_ID_MASK) != (frm->addr&STACK_ID_MASK) ) { | 
					
						
							|  |  |  | 			cb_log(2, stack->port, "DL_DATA INDICATION bc->addr:%x frm->addr:%x\n", bc->addr, frm->addr); | 
					
						
							|  |  |  | 			free_msg(msg); | 
					
						
							|  |  |  | 			return 1; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | #if MISDN_DEBUG
 | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(0, stack->port, "DL_DATA INDICATION Len %d\n", frm->len); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 		if ( (bc->bc_state == BCHAN_ACTIVATED) && frm->len > 0) { | 
					
						
							| 
									
										
										
										
											2006-06-06 09:40:41 +00:00
										 |  |  | 			int t; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef MISDN_B_DEBUG
 | 
					
						
							|  |  |  | 			cb_log(0,bc->port,"do_tone START\n"); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 			t=do_tone(bc,frm->len); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef MISDN_B_DEBUG
 | 
					
						
							|  |  |  | 			cb_log(0,bc->port,"do_tone STOP (%d)\n",t); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 			if (  !t ) { | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 				int i; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 				if ( misdn_cap_is_speech(bc->capability)) { | 
					
						
							|  |  |  | 					if ( !bc->nojitter ) { | 
					
						
							| 
									
										
										
										
											2006-06-06 09:40:41 +00:00
										 |  |  | #ifdef MISDN_B_DEBUG
 | 
					
						
							|  |  |  | 						cb_log(0,bc->port,"tx_jitter START\n"); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 						misdn_tx_jitter(bc,frm->len); | 
					
						
							| 
									
										
										
										
											2006-06-06 09:40:41 +00:00
										 |  |  | #ifdef MISDN_B_DEBUG
 | 
					
						
							|  |  |  | 						cb_log(0,bc->port,"tx_jitter STOP\n"); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2006-06-06 09:40:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | #ifdef MISDN_B_DEBUG
 | 
					
						
							| 
									
										
										
										
											2006-06-06 09:40:41 +00:00
										 |  |  | 				cb_log(0,bc->port,"EVENT_B_DATA START\n"); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 				i = cb_event(EVENT_BCHAN_DATA, bc, glob_mgr->user_data); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | #ifdef MISDN_B_DEBUG
 | 
					
						
							| 
									
										
										
										
											2006-06-06 09:40:41 +00:00
										 |  |  | 				cb_log(0,bc->port,"EVENT_B_DATA STOP\n"); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 				if (i<0) { | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 					cb_log(10,stack->port,"cb_event returned <0\n"); | 
					
						
							| 
									
										
										
										
											2006-02-14 10:44:00 +00:00
										 |  |  | 					/*clean_up_bc(bc);*/ | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		free_msg(msg); | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	case PH_CONTROL | CONFIRM: | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(4, stack->port, "PH_CONTROL|CNF bc->addr:%x\n", frm->addr); | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 		free_msg(msg); | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	case PH_DATA | CONFIRM: | 
					
						
							|  |  |  | 	case DL_DATA|CONFIRM: | 
					
						
							|  |  |  | #if MISDN_DEBUG
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(0, stack->port, "Data confirmed\n"); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 		free_msg(msg); | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	case DL_DATA|RESPONSE: | 
					
						
							|  |  |  | #if MISDN_DEBUG
 | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(0, stack->port, "Data response\n"); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int handle_frm_nt(msg_t *msg) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	iframe_t *frm= (iframe_t*)msg->data; | 
					
						
							|  |  |  | 	struct misdn_stack *stack; | 
					
						
							|  |  |  | 	int err=0; | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	stack=find_stack_by_addr( frm->addr ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	if (!stack || !stack->nt) { | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-06-06 09:40:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-15 21:14:41 +00:00
										 |  |  | 	pthread_mutex_lock(&stack->nstlock); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	if ((err=stack->nst.l1_l2(&stack->nst,msg))) { | 
					
						
							| 
									
										
										
										
											2009-07-15 21:14:41 +00:00
										 |  |  | 		pthread_mutex_unlock(&stack->nstlock); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		if (nt_err_cnt > 0 ) { | 
					
						
							|  |  |  | 			if (nt_err_cnt < 100) { | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 				nt_err_cnt++; | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 				cb_log(0, stack->port, "NT Stack sends us error: %d \n", err); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			} else if (nt_err_cnt < 105){ | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 				cb_log(0, stack->port, "NT Stack sends us error: %d over 100 times, so I'll stop this message\n", err); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 				nt_err_cnt = - 1; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		free_msg(msg); | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-07-15 21:14:41 +00:00
										 |  |  | 	pthread_mutex_unlock(&stack->nstlock); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int handle_frm(msg_t *msg) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	struct misdn_bchannel dummybc; | 
					
						
							|  |  |  | 	struct misdn_bchannel *bc; | 
					
						
							|  |  |  | 	iframe_t *frm; | 
					
						
							|  |  |  | 	struct misdn_stack *stack; | 
					
						
							|  |  |  | 	enum event_e event; | 
					
						
							|  |  |  | 	enum event_response_e response; | 
					
						
							|  |  |  | 	int ret; | 
					
						
							|  |  |  | 	int channel; | 
					
						
							|  |  |  | 	int tmpcause; | 
					
						
							|  |  |  | 	int tmp_out_cause; | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	frm = (iframe_t*) msg->data; | 
					
						
							|  |  |  | 	stack = find_stack_by_addr(frm->addr); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	if (!stack || stack->nt) { | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 	cb_log(4, stack ? stack->port : 0, "handle_frm: frm->addr:%x frm->prim:%x\n", frm->addr, frm->prim); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	ret = handle_cr(stack, frm); | 
					
						
							|  |  |  | 	if (ret < 0) { | 
					
						
							|  |  |  | 		cb_log(3, stack ? stack->port : 0, "handle_frm: handle_cr <0 prim:%x addr:%x\n", frm->prim, frm->addr); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (ret) { | 
					
						
							|  |  |  | 		free_msg(msg); | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-07-23 12:07:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	bc = find_bc_by_l3id(stack, frm->dinfo); | 
					
						
							|  |  |  | 	if (!bc) { | 
					
						
							|  |  |  | 		misdn_make_dummy(&dummybc, stack->port, 0, stack->nt, 0); | 
					
						
							|  |  |  | 		switch (frm->prim) { | 
					
						
							|  |  |  | 		case CC_RESTART | CONFIRM: | 
					
						
							|  |  |  | 			dummybc.l3_id = MISDN_ID_GLOBAL; | 
					
						
							|  |  |  | 			bc = &dummybc; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case CC_SETUP | INDICATION: | 
					
						
							|  |  |  | 			dummybc.l3_id = frm->dinfo; | 
					
						
							|  |  |  | 			bc = &dummybc; | 
					
						
							| 
									
										
										
										
											2008-07-23 12:07:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 			misdn_lib_send_event(bc, EVENT_RELEASE_COMPLETE); | 
					
						
							| 
									
										
										
										
											2008-07-23 12:07:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			free_msg(msg); | 
					
						
							|  |  |  | 			return 1; | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		default: | 
					
						
							|  |  |  | 			if (frm->prim == (CC_FACILITY | INDICATION)) { | 
					
						
							|  |  |  | 				cb_log(5, stack->port, " --> Using Dummy BC for FACILITY\n"); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				cb_log(0, stack->port, " --> Didn't find BC so temporarily creating dummy BC (l3id:%x) on this port.\n", frm->dinfo); | 
					
						
							|  |  |  | 				dummybc.l3_id = frm->dinfo; | 
					
						
							| 
									
										
											  
											
												Merged revisions 49313 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r49313 | crichter | 2007-01-03 10:06:50 +0100 (Mi, 03 Jan 2007) | 41 lines
Merged revisions 48319,48321,48467,48552,48576,49135,49303 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r48319 | crichter | 2006-12-06 15:35:25 +0100 (Mi, 06 Dez 2006) | 1 line
changed a few debugs to higher debug levels
........
r48321 | crichter | 2006-12-06 16:48:45 +0100 (Mi, 06 Dez 2006) | 1 line
added the export and import of the MISDN_ADDRESS_COMPLETE Variable to inidcate wether the extension is already completely dialed or if there might come additional digits by information elements. also added some docs for that.
........
r48467 | crichter | 2006-12-14 14:03:49 +0100 (Do, 14 Dez 2006) | 1 line
removed FIXUP state. added check for channel allocation conflict when we create a setup while the other site creates a setup on the same channel, besides the check we resolve this conflict.
........
r48552 | crichter | 2006-12-18 11:19:39 +0100 (Mo, 18 Dez 2006) | 1 line
when our PTP Partner sends us a SETUP with a preselected channel we just accept it, even when we're NT. added some checks for segfaults.
........
r48576 | crichter | 2006-12-19 14:08:51 +0100 (Di, 19 Dez 2006) | 1 line
when we reject a channel, because it's in use already, we shouldn't process the setup anymore. made the channel allocation a bit easier and more understandable, removed a few unused lines
........
r49135 | crichter | 2007-01-02 11:07:22 +0100 (Di, 02 Jan 2007) | 1 line
added check for channel ranges in the set/empty channel functions. set pmp_l1_check default to no. added misdn restart pid cli command. added cleaning of channel when we send a RELEASE_COMPLETE. 
........
r49303 | crichter | 2007-01-03 09:24:00 +0100 (Mi, 03 Jan 2007) | 9 lines
* Added check for bridging in misdn_call to avoid setting echocancellation
  when 2 mISDN channels are involved and when bridging is set. That lead
  to a kernel panic before under different situations, because we switched 
  about 2 times between hardware bridging and echocancelation
* readded MISDN_URATE variable which got lost before, this should make app_v110
  work again
* fixed typo
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@49321 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-01-03 11:15:02 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 			bc = &dummybc; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	event = isdn_msg_get_event(msgs_g, msg, 0); | 
					
						
							|  |  |  | 	isdn_msg_parse_event(msgs_g, msg, bc, 0); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	/* Preprocess some Events */ | 
					
						
							|  |  |  | 	ret = handle_event(bc, event, frm); | 
					
						
							|  |  |  | 	if (ret < 0) { | 
					
						
							|  |  |  | 		cb_log(0, stack->port, "couldn't handle event\n"); | 
					
						
							|  |  |  | 		free_msg(msg); | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	/* shoot up event to App: */ | 
					
						
							|  |  |  | 	cb_log(5, stack->port, "lib Got Prim: Addr %x prim %x dinfo %x\n", frm->addr, frm->prim, frm->dinfo); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	if (!isdn_get_info(msgs_g, event, 0)) { | 
					
						
							|  |  |  | 		cb_log(0, stack->port, "Unknown Event Ind: Addr:%x prim %x dinfo %x\n", frm->addr, frm->prim, frm->dinfo); | 
					
						
							|  |  |  | 		response = RESPONSE_OK; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		response = cb_event(event, bc, glob_mgr->user_data); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
											  
											
												Merged revisions 62912 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r62912 | crichter | 2007-05-03 16:36:32 +0200 (Do, 03 Mai 2007) | 17 lines
Merged revisions 61357,61770,62885 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r61357 | crichter | 2007-04-11 14:05:57 +0200 (Mi, 11 Apr 2007) | 1 line
some fixes for PMP Hold/Retrieve, it should work now, when briding=no
........
r61770 | crichter | 2007-04-24 15:50:05 +0200 (Di, 24 Apr 2007) | 1 line
added lock for sending messages to avoid double sending. shuffled some empty_chans after the cb_event calls, this avoids that a release_complete from a quite different call releases a fresh created setup by accident.
........
r62885 | crichter | 2007-05-03 15:59:00 +0200 (Do, 03 Mai 2007) | 1 line
fixed the problem that misdn_write did not return -1 when called with 0 samples in a frame this resultet in a deadlock in some circumstances, when the call ended because of a busy extension.  added encoding of keypad.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@64955 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-05-18 09:50:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	switch (event) { | 
					
						
							|  |  |  | 	case EVENT_SETUP: | 
					
						
							|  |  |  | 		switch (response) { | 
					
						
							|  |  |  | 		case RESPONSE_IGNORE_SETUP_WITHOUT_CLOSE: | 
					
						
							|  |  |  | 			cb_log(0, stack->port, "TOTALLY IGNORING SETUP\n"); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case RESPONSE_IGNORE_SETUP: | 
					
						
							|  |  |  | 			/* I think we should send CC_RELEASE_CR, but am not sure*/ | 
					
						
							|  |  |  | 			bc->out_cause = AST_CAUSE_NORMAL_CLEARING; | 
					
						
							|  |  |  | 			/* fall through */ | 
					
						
							|  |  |  | 		case RESPONSE_RELEASE_SETUP: | 
					
						
							|  |  |  | 			misdn_lib_send_event(bc, EVENT_RELEASE_COMPLETE); | 
					
						
							|  |  |  | 			if (bc->channel > 0) { | 
					
						
							|  |  |  | 				empty_chan_in_stack(stack, bc->channel); | 
					
						
							| 
									
										
										
										
											2007-07-02 09:23:08 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 			empty_bc(bc); | 
					
						
							|  |  |  | 			bc_state_change(bc, BCHAN_CLEANED); | 
					
						
							|  |  |  | 			bc->in_use = 0; | 
					
						
							| 
									
										
										
										
											2007-07-02 09:23:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 			cb_log(0, stack->port, "GOT IGNORE SETUP\n"); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case RESPONSE_OK: | 
					
						
							|  |  |  | 			cb_log(4, stack->port, "GOT SETUP OK\n"); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case EVENT_RELEASE_COMPLETE: | 
					
						
							|  |  |  | 		/* release bchannel only after we've announced the RELEASE_COMPLETE */ | 
					
						
							|  |  |  | 		channel = bc->channel; | 
					
						
							|  |  |  | 		tmpcause = bc->cause; | 
					
						
							|  |  |  | 		tmp_out_cause = bc->out_cause; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		empty_bc(bc); | 
					
						
							|  |  |  | 		bc->cause = tmpcause; | 
					
						
							|  |  |  | 		bc->out_cause = tmp_out_cause; | 
					
						
							|  |  |  | 		clean_up_bc(bc); | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 		bc->in_use = 0; | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (tmpcause == AST_CAUSE_REQUESTED_CHAN_UNAVAIL) { | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 			cb_log(0, stack->port, "**** Received CAUSE:%d, restarting channel %d\n", AST_CAUSE_REQUESTED_CHAN_UNAVAIL, channel); | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 			misdn_lib_send_restart(stack->port, channel); | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if (channel > 0) { | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 			empty_chan_in_stack(stack, channel); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case EVENT_RESTART: | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 		cb_log(0, stack->port, "**** Received RESTART channel:%d\n", bc->restart_channel); | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		empty_chan_in_stack(stack, bc->restart_channel); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	cb_log(5, stack->port, "Freeing Msg on prim:%x \n", frm->prim); | 
					
						
							|  |  |  | 	free_msg(msg); | 
					
						
							|  |  |  | 	return 1; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int handle_l1(msg_t *msg) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	iframe_t *frm = (iframe_t*) msg->data; | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	struct misdn_stack *stack = find_stack_by_addr(frm->addr); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	int i ; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	if (!stack) return 0 ; | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	switch (frm->prim) { | 
					
						
							|  |  |  | 	case PH_ACTIVATE | CONFIRM: | 
					
						
							|  |  |  | 	case PH_ACTIVATE | INDICATION: | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log (3, stack->port, "L1: PH L1Link Up!\n"); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		stack->l1link=1; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		if (stack->nt) { | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-15 21:14:41 +00:00
										 |  |  | 			pthread_mutex_lock(&stack->nstlock); | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 			if (stack->nst.l1_l2(&stack->nst, msg)) | 
					
						
							|  |  |  | 				free_msg(msg); | 
					
						
							| 
									
										
										
										
											2009-07-15 21:14:41 +00:00
										 |  |  | 			pthread_mutex_unlock(&stack->nstlock); | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if (stack->ptp) | 
					
						
							|  |  |  | 				misdn_lib_get_l2_up(stack); | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			free_msg(msg); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-11 08:34:03 +00:00
										 |  |  | 		for (i=0;i<=stack->b_num; i++) { | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			if (stack->bc[i].evq != EVENT_NOTHING) { | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 				cb_log(4, stack->port, "Firing Queued Event %s because L1 got up\n", isdn_get_info(msgs_g, stack->bc[i].evq, 0)); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 				misdn_lib_send_event(&stack->bc[i],stack->bc[i].evq); | 
					
						
							|  |  |  | 				stack->bc[i].evq=EVENT_NOTHING; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		return 1; | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	case PH_ACTIVATE | REQUEST: | 
					
						
							|  |  |  | 		free_msg(msg); | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(3,stack->port,"L1: PH_ACTIVATE|REQUEST \n"); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		return 1; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	case PH_DEACTIVATE | REQUEST: | 
					
						
							|  |  |  | 		free_msg(msg); | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(3,stack->port,"L1: PH_DEACTIVATE|REQUEST \n"); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		return 1; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	case PH_DEACTIVATE | CONFIRM: | 
					
						
							|  |  |  | 	case PH_DEACTIVATE | INDICATION: | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log (3, stack->port, "L1: PH L1Link Down! \n"); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-12 12:49:19 +00:00
										 |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2006-10-11 08:34:03 +00:00
										 |  |  | 		for (i=0; i<=stack->b_num; i++) { | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			if (global_state == MISDN_INITIALIZED)  { | 
					
						
							|  |  |  | 				cb_event(EVENT_CLEANUP, &stack->bc[i], glob_mgr->user_data); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2007-11-12 12:49:19 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		if (stack->nt) { | 
					
						
							| 
									
										
										
										
											2009-07-15 21:14:41 +00:00
										 |  |  | 			pthread_mutex_lock(&stack->nstlock); | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 			if (stack->nst.l1_l2(&stack->nst, msg)) | 
					
						
							|  |  |  | 				free_msg(msg); | 
					
						
							| 
									
										
										
										
											2009-07-15 21:14:41 +00:00
										 |  |  | 			pthread_mutex_unlock(&stack->nstlock); | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			free_msg(msg); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 		stack->l1link=0; | 
					
						
							|  |  |  | 		stack->l2link=0; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int handle_l2(msg_t *msg) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	iframe_t *frm = (iframe_t*) msg->data; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	struct misdn_stack *stack = find_stack_by_addr(frm->addr); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	if (!stack) { | 
					
						
							|  |  |  | 		return 0 ; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	switch(frm->prim) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	case DL_ESTABLISH | REQUEST: | 
					
						
							|  |  |  | 		cb_log(1,stack->port,"DL_ESTABLISH|REQUEST \n"); | 
					
						
							| 
									
										
										
										
											2009-07-14 00:48:59 +00:00
										 |  |  | 		free_msg(msg); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		return 1; | 
					
						
							|  |  |  | 	case DL_RELEASE | REQUEST: | 
					
						
							|  |  |  | 		cb_log(1,stack->port,"DL_RELEASE|REQUEST \n"); | 
					
						
							| 
									
										
										
										
											2009-07-14 00:48:59 +00:00
										 |  |  | 		free_msg(msg); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		return 1; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	case DL_ESTABLISH | INDICATION: | 
					
						
							|  |  |  | 	case DL_ESTABLISH | CONFIRM: | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		cb_log (3, stack->port, "L2: L2Link Up! \n"); | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		if (stack->ptp && stack->l2link) { | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 			cb_log (-1, stack->port, "L2: L2Link Up! but it's already UP.. must be faulty, blocking port\n"); | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 			cb_event(EVENT_PORT_ALARM, &stack->bc[0], glob_mgr->user_data); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		stack->l2link=1; | 
					
						
							|  |  |  | 		free_msg(msg); | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	break; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	case DL_RELEASE | INDICATION: | 
					
						
							|  |  |  | 	case DL_RELEASE | CONFIRM: | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		cb_log (3, stack->port, "L2: L2Link Down! \n"); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		stack->l2link=0; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		free_msg(msg); | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int handle_mgmt(msg_t *msg) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	iframe_t *frm = (iframe_t*) msg->data; | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 	struct misdn_stack *stack; | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if ( (frm->addr == 0) && (frm->prim == (MGR_DELLAYER|CONFIRM)) ) { | 
					
						
							|  |  |  | 		cb_log(2, 0, "MGMT: DELLAYER|CONFIRM Addr: 0 !\n") ; | 
					
						
							| 
									
										
										
										
											2006-04-11 08:31:19 +00:00
										 |  |  | 		free_msg(msg); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 	stack = find_stack_by_addr(frm->addr); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	if (!stack) { | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 		if (frm->prim == (MGR_DELLAYER|CONFIRM)) { | 
					
						
							|  |  |  | 			cb_log(2, 0, "MGMT: DELLAYER|CONFIRM Addr: %x !\n", | 
					
						
							|  |  |  | 					frm->addr) ; | 
					
						
							| 
									
										
										
										
											2006-04-11 08:31:19 +00:00
										 |  |  | 			free_msg(msg); | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 			return 1; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	switch(frm->prim) { | 
					
						
							|  |  |  | 	case MGR_SHORTSTATUS | INDICATION: | 
					
						
							| 
									
										
										
										
											2006-02-08 19:51:53 +00:00
										 |  |  | 	case MGR_SHORTSTATUS | CONFIRM: | 
					
						
							| 
									
										
										
										
											2009-07-15 21:14:41 +00:00
										 |  |  | 		cb_log(5, stack->port, "MGMT: Short status dinfo %x\n",frm->dinfo); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		switch (frm->dinfo) { | 
					
						
							|  |  |  | 		case SSTATUS_L1_ACTIVATED: | 
					
						
							| 
									
										
										
										
											2009-07-15 21:14:41 +00:00
										 |  |  | 			cb_log(3, stack->port, "MGMT: SSTATUS: L1_ACTIVATED \n"); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 			stack->l1link=1; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case SSTATUS_L1_DEACTIVATED: | 
					
						
							| 
									
										
										
										
											2009-07-15 21:14:41 +00:00
										 |  |  | 			cb_log(3, stack->port, "MGMT: SSTATUS: L1_DEACTIVATED \n"); | 
					
						
							| 
									
										
										
										
											2006-05-23 19:40:16 +00:00
										 |  |  | 			stack->l1link=0; | 
					
						
							| 
									
										
										
										
											2007-11-12 12:49:19 +00:00
										 |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2006-06-06 09:40:41 +00:00
										 |  |  | 			clear_l3(stack); | 
					
						
							| 
									
										
										
										
											2007-11-12 12:49:19 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2006-02-08 16:10:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		case SSTATUS_L2_ESTABLISHED: | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 			cb_log(3, stack->port, "MGMT: SSTATUS: L2_ESTABLISH \n"); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 			stack->l2link=1; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		case SSTATUS_L2_RELEASED: | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 			cb_log(3, stack->port, "MGMT: SSTATUS: L2_RELEASED \n"); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 			stack->l2link=0; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		free_msg(msg); | 
					
						
							|  |  |  | 		return 1; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	case MGR_SETSTACK | INDICATION: | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(4, stack->port, "MGMT: SETSTACK|IND dinfo %x\n",frm->dinfo); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		free_msg(msg); | 
					
						
							|  |  |  | 		return 1; | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	case MGR_DELLAYER | CONFIRM: | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(4, stack->port, "MGMT: DELLAYER|CNF dinfo %x\n",frm->dinfo) ; | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		free_msg(msg); | 
					
						
							|  |  |  | 		return 1; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	if ( (frm->prim & 0x0f0000) ==  0x0f0000) { | 
					
						
							|  |  |  | 	cb_log(5, 0, "$$$ MGMT FRAME: prim %x addr %x dinfo %x\n",frm->prim, frm->addr, frm->dinfo) ; | 
					
						
							|  |  |  | 	free_msg(msg); | 
					
						
							|  |  |  | 	return 1; | 
					
						
							|  |  |  | 	} */ | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | static msg_t *fetch_msg(int midev) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	msg_t *msg=alloc_msg(MAX_MSG_SIZE); | 
					
						
							|  |  |  | 	int r; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!msg) { | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(0, 0, "fetch_msg: alloc msg failed !!"); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-29 22:56:00 +00:00
										 |  |  | 	AGAIN: | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 		r=mISDN_read(midev,msg->data,MAX_MSG_SIZE, TIMEOUT_10SEC); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		msg->len=r; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		if (r==0) { | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 			free_msg(msg); /* danger, cause usually freeing in main_loop */ | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 			cb_log(6,0,"Got empty Msg..\n"); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			return NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-29 22:56:00 +00:00
										 |  |  | 		if (r<0) { | 
					
						
							|  |  |  | 			if (errno == EAGAIN) { | 
					
						
							|  |  |  | 				/*we wait for mISDN here*/ | 
					
						
							| 
									
										
										
										
											2006-05-18 08:45:43 +00:00
										 |  |  | 				cb_log(4,0,"mISDN_read wants us to wait\n"); | 
					
						
							| 
									
										
										
										
											2006-04-29 22:56:00 +00:00
										 |  |  | 				usleep(5000); | 
					
						
							|  |  |  | 				goto AGAIN; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			cb_log(0,0,"mISDN_read returned :%d error:%s (%d)\n",r,strerror(errno),errno); | 
					
						
							| 
									
										
										
										
											2006-04-29 22:56:00 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2007-02-07 09:51:06 +00:00
										 |  |  |                if  (!(frm->prim == (DL_DATA|INDICATION) )|| (frm->prim == (PH_DATA|INDICATION))) | 
					
						
							|  |  |  |                        cb_log(0,0,"prim: %x dinfo:%x addr:%x msglen:%d frm->len:%d\n",frm->prim, frm->dinfo, frm->addr, msg->len,frm->len ); | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2007-02-07 09:51:06 +00:00
										 |  |  | 		return msg; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-11 19:30:35 +00:00
										 |  |  | void misdn_lib_isdn_l1watcher(int port) | 
					
						
							| 
									
										
										
										
											2006-05-23 19:40:16 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct misdn_stack *stack; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-11 19:30:35 +00:00
										 |  |  | 	for (stack = glob_mgr->stack_list; stack && (stack->port != port); stack = stack->next) | 
					
						
							|  |  |  | 		; | 
					
						
							| 
									
										
										
										
											2006-05-23 19:40:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-11 19:30:35 +00:00
										 |  |  | 	if (stack) { | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 		cb_log(4, port, "Checking L1 State\n"); | 
					
						
							| 
									
										
										
										
											2006-07-11 19:30:35 +00:00
										 |  |  | 		if (!stack->l1link) { | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 			cb_log(4, port, "L1 State Down, trying to get it up again\n"); | 
					
						
							| 
									
										
										
										
											2006-07-11 19:30:35 +00:00
										 |  |  | 			misdn_lib_get_short_status(stack); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 			misdn_lib_get_l1_up(stack); | 
					
						
							|  |  |  | 			misdn_lib_get_l2_up(stack); | 
					
						
							| 
									
										
										
										
											2006-05-23 19:40:16 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | /* This is a thread */ | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | static void misdn_lib_isdn_event_catcher(void *arg) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct misdn_lib *mgr = arg; | 
					
						
							|  |  |  | 	int zero_frm=0 , fff_frm=0 ; | 
					
						
							|  |  |  | 	int midev= mgr->midev; | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	int port=0; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	while (1) { | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 		msg_t *msg = fetch_msg(midev); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		iframe_t *frm; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		if (!msg) continue; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		frm = (iframe_t*) msg->data; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 		/** When we make a call from NT2Ast we get these frames **/ | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		if (frm->len == 0 && frm->addr == 0 && frm->dinfo == 0 && frm->prim == 0 ) { | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 			zero_frm++; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			free_msg(msg); | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			if (zero_frm) { | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 				cb_log(0, port, "*** Alert: %d zero_frms caught\n", zero_frm); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 				zero_frm = 0 ; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		/** I get this sometimes after setup_bc **/ | 
					
						
							|  |  |  | 		if (frm->len == 0 &&  frm->dinfo == 0 && frm->prim == 0xffffffff ) { | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 			fff_frm++; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			free_msg(msg); | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			if (fff_frm) { | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 				cb_log(0, port, "*** Alert: %d fff_frms caught\n", fff_frm); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 				fff_frm = 0 ; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		manager_isdn_handler(frm, msg); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** App Interface **/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | static int te_lib_init(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 	char buff[1025] = ""; | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 	iframe_t *frm = (iframe_t *) buff; | 
					
						
							|  |  |  | 	int midev; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	int ret; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 	midev = mISDN_open(); | 
					
						
							|  |  |  | 	if (midev <= 0) { | 
					
						
							|  |  |  | 		return midev; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 	/* create entity for layer 3 TE-mode */ | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	mISDN_write_frame(midev, buff, 0, MGR_NEWENTITY | REQUEST, 0, 0, NULL, TIMEOUT_1SEC); | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	ret = mISDN_read_frame(midev, frm, sizeof(iframe_t), 0, MGR_NEWENTITY | CONFIRM, TIMEOUT_1SEC); | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	entity = frm->dinfo & 0xffff; | 
					
						
							|  |  |  | 	if (ret < mISDN_HEADER_LEN || !entity) { | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 		fprintf(stderr, "cannot request MGR_NEWENTITY from mISDN: %s\n", strerror(errno)); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		exit(-1); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	return midev; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void te_lib_destroy(int midev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	char buf[1024]; | 
					
						
							|  |  |  | 	mISDN_write_frame(midev, buf, 0, MGR_DELENTITY | REQUEST, entity, 0, NULL, TIMEOUT_1SEC); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 	cb_log(4, 0, "Entity deleted\n"); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	mISDN_close(midev); | 
					
						
							|  |  |  | 	cb_log(4, 0, "midev closed\n"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct misdn_bchannel *manager_find_bc_by_pid(int pid) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct misdn_stack *stack; | 
					
						
							|  |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 	for (stack = glob_mgr->stack_list; stack; stack = stack->next) { | 
					
						
							|  |  |  | 		for (i = 0; i <= stack->b_num; i++) { | 
					
						
							|  |  |  | 			if (stack->bc[i].in_use && stack->bc[i].pid == pid) { | 
					
						
							|  |  |  | 				return &stack->bc[i]; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-02 09:35:04 +00:00
										 |  |  | static int test_inuse(struct misdn_bchannel *bc) | 
					
						
							| 
									
										
										
										
											2008-06-02 08:46:23 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct timeval now; | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-02 08:46:23 +00:00
										 |  |  | 	if (!bc->in_use) { | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		gettimeofday(&now, NULL); | 
					
						
							|  |  |  | 		if (bc->last_used.tv_sec == now.tv_sec | 
					
						
							|  |  |  | 			&& misdn_lib_port_is_pri(bc->port)) { | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 			cb_log(2, bc->port, "channel with stid:%x for one second still in use! (n:%d lu:%d)\n", | 
					
						
							|  |  |  | 				bc->b_stid, (int) now.tv_sec, (int) bc->last_used.tv_sec); | 
					
						
							| 
									
										
										
										
											2008-06-02 08:46:23 +00:00
										 |  |  | 			return 1; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-11 11:52:18 +00:00
										 |  |  | 		cb_log(3,bc->port, "channel with stid:%x not in use!\n", bc->b_stid); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2008-06-02 08:46:23 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-11 11:52:18 +00:00
										 |  |  | 	cb_log(2,bc->port, "channel with stid:%x in use!\n", bc->b_stid); | 
					
						
							|  |  |  | 	return 1; | 
					
						
							| 
									
										
										
										
											2008-06-02 08:46:23 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static void prepare_bc(struct misdn_bchannel*bc, int channel) | 
					
						
							| 
									
										
										
										
											2006-07-06 15:11:40 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	bc->channel = channel; | 
					
						
							|  |  |  | 	bc->channel_preselected = channel?1:0; | 
					
						
							|  |  |  | 	bc->need_disconnect=1; | 
					
						
							|  |  |  | 	bc->need_release=1; | 
					
						
							|  |  |  | 	bc->need_release_complete=1; | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 	bc->cause = AST_CAUSE_NORMAL_CLEARING; | 
					
						
							| 
									
										
										
										
											2006-07-06 15:11:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (++mypid>5000) mypid=1; | 
					
						
							|  |  |  | 	bc->pid=mypid; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if 0
 | 
					
						
							|  |  |  | 	bc->addr=0; | 
					
						
							|  |  |  | 	bc->b_stid=0; | 
					
						
							|  |  |  | 	bc->layer_id=0; | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	bc->in_use = 1; | 
					
						
							| 
									
										
										
										
											2006-07-06 15:11:40 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | struct misdn_bchannel *misdn_lib_get_free_bc(int port, int channel, int inout, int dec) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct misdn_stack *stack; | 
					
						
							|  |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	int maxnum; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 	if (channel < 0 || channel > MAX_BCHANS) { | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 		cb_log(0, port, "Requested channel out of bounds (%d)\n", channel); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	/* Find the port stack structure */ | 
					
						
							|  |  |  | 	stack = find_stack_by_port(port); | 
					
						
							|  |  |  | 	if (!stack) { | 
					
						
							|  |  |  | 		cb_log(0, port, "Port is not configured (%d)\n", port); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	if (stack->blocked) { | 
					
						
							|  |  |  | 		cb_log(0, port, "Port is blocked\n"); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-02 01:49:25 +00:00
										 |  |  | 	pthread_mutex_lock(&stack->st_lock); | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	if (channel > 0) { | 
					
						
							|  |  |  | 		if (channel <= stack->b_num) { | 
					
						
							|  |  |  | 			for (i = 0; i < stack->b_num; i++) { | 
					
						
							|  |  |  | 				if (stack->bc[i].channel == channel) { | 
					
						
							|  |  |  | 					if (test_inuse(&stack->bc[i])) { | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 						pthread_mutex_unlock(&stack->st_lock); | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 						cb_log(0, port, "Requested channel:%d on port:%d is already in use\n", channel, port); | 
					
						
							|  |  |  | 						return NULL; | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						prepare_bc(&stack->bc[i], channel); | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 						pthread_mutex_unlock(&stack->st_lock); | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 						return &stack->bc[i]; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 			pthread_mutex_unlock(&stack->st_lock); | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 			cb_log(0, port, "Requested channel:%d is out of bounds on port:%d\n", channel, port); | 
					
						
							|  |  |  | 			return NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-10-11 08:34:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	/* Note: channel == 0 here */ | 
					
						
							|  |  |  | 	maxnum = (inout && !stack->pri && !stack->ptp) ? stack->b_num + 1 : stack->b_num; | 
					
						
							|  |  |  | 	if (dec) { | 
					
						
							|  |  |  | 		for (i = maxnum - 1; i >= 0; --i) { | 
					
						
							|  |  |  | 			if (!test_inuse(&stack->bc[i])) { | 
					
						
							|  |  |  | 				/* 3. channel on bri means CW*/ | 
					
						
							|  |  |  | 				if (!stack->pri && i == stack->b_num) { | 
					
						
							|  |  |  | 					stack->bc[i].cw = 1; | 
					
						
							| 
									
										
										
										
											2007-05-18 09:36:16 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 				prepare_bc(&stack->bc[i], channel); | 
					
						
							|  |  |  | 				stack->bc[i].dec = 1; | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 				pthread_mutex_unlock(&stack->st_lock); | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 				return &stack->bc[i]; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		for (i = 0; i < maxnum; ++i) { | 
					
						
							|  |  |  | 			if (!test_inuse(&stack->bc[i])) { | 
					
						
							|  |  |  | 				/* 3. channel on bri means CW */ | 
					
						
							|  |  |  | 				if (!stack->pri && i == stack->b_num) { | 
					
						
							|  |  |  | 					stack->bc[i].cw = 1; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				prepare_bc(&stack->bc[i], channel); | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 				pthread_mutex_unlock(&stack->st_lock); | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 				return &stack->bc[i]; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 	pthread_mutex_unlock(&stack->st_lock); | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	cb_log(1, port, "There is no free channel on port (%d)\n", port); | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if defined(AST_MISDN_ENHANCEMENTS)
 | 
					
						
							|  |  |  | /*!
 | 
					
						
							|  |  |  |  * \brief Allocate a B channel struct from the REGISTER pool | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param port Logical port number | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \retval B channel struct on success. | 
					
						
							|  |  |  |  * \retval NULL on error. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | struct misdn_bchannel *misdn_lib_get_register_bc(int port) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct misdn_stack *stack; | 
					
						
							|  |  |  | 	struct misdn_bchannel *bc; | 
					
						
							|  |  |  | 	unsigned index; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Find the port stack structure */ | 
					
						
							|  |  |  | 	stack = find_stack_by_port(port); | 
					
						
							|  |  |  | 	if (!stack) { | 
					
						
							|  |  |  | 		cb_log(0, port, "Port is not configured (%d)\n", port); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (stack->blocked) { | 
					
						
							|  |  |  | 		cb_log(0, port, "Port is blocked\n"); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-02 01:46:51 +00:00
										 |  |  | 	pthread_mutex_lock(&stack->st_lock); | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	for (index = MAX_BCHANS + 1; index < ARRAY_LEN(stack->bc); ++index) { | 
					
						
							|  |  |  | 		bc = &stack->bc[index]; | 
					
						
							|  |  |  | 		if (!test_inuse(bc)) { | 
					
						
							|  |  |  | 			prepare_bc(bc, 0); | 
					
						
							|  |  |  | 			bc->need_disconnect = 0; | 
					
						
							|  |  |  | 			bc->need_release = 0; | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 			pthread_mutex_unlock(&stack->st_lock); | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 			return bc; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 	pthread_mutex_unlock(&stack->st_lock); | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	cb_log(1, port, "There is no free REGISTER link on port (%d)\n", port); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	return NULL; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | #endif	/* defined(AST_MISDN_ENHANCEMENTS) */
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \internal | 
					
						
							|  |  |  |  * \brief Convert the facility function enum value into a string. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \return String version of the enum value | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static const char *fac2str(enum FacFunction facility) | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 	static const struct { | 
					
						
							|  |  |  | 		enum FacFunction facility; | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 		char *name; | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	} arr[] = { | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | /* *INDENT-OFF* */ | 
					
						
							| 
									
										
										
										
											2006-08-16 13:19:54 +00:00
										 |  |  | 		{ Fac_None, "Fac_None" }, | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | #if defined(AST_MISDN_ENHANCEMENTS)
 | 
					
						
							|  |  |  | 		{ Fac_ERROR, "Fac_ERROR" }, | 
					
						
							|  |  |  | 		{ Fac_RESULT, "Fac_RESULT" }, | 
					
						
							|  |  |  | 		{ Fac_REJECT, "Fac_REJECT" }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		{ Fac_ActivationDiversion, "Fac_ActivationDiversion" }, | 
					
						
							|  |  |  | 		{ Fac_DeactivationDiversion, "Fac_DeactivationDiversion" }, | 
					
						
							|  |  |  | 		{ Fac_ActivationStatusNotificationDiv, "Fac_ActivationStatusNotificationDiv" }, | 
					
						
							|  |  |  | 		{ Fac_DeactivationStatusNotificationDiv, "Fac_DeactivationStatusNotificationDiv" }, | 
					
						
							|  |  |  | 		{ Fac_InterrogationDiversion, "Fac_InterrogationDiversion" }, | 
					
						
							|  |  |  | 		{ Fac_DiversionInformation, "Fac_DiversionInformation" }, | 
					
						
							|  |  |  | 		{ Fac_CallDeflection, "Fac_CallDeflection" }, | 
					
						
							|  |  |  | 		{ Fac_CallRerouteing, "Fac_CallRerouteing" }, | 
					
						
							|  |  |  | 		{ Fac_DivertingLegInformation2, "Fac_DivertingLegInformation2" }, | 
					
						
							|  |  |  | 		{ Fac_InterrogateServedUserNumbers, "Fac_InterrogateServedUserNumbers" }, | 
					
						
							|  |  |  | 		{ Fac_DivertingLegInformation1, "Fac_DivertingLegInformation1" }, | 
					
						
							|  |  |  | 		{ Fac_DivertingLegInformation3, "Fac_DivertingLegInformation3" }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		{ Fac_EctExecute, "Fac_EctExecute" }, | 
					
						
							|  |  |  | 		{ Fac_ExplicitEctExecute, "Fac_ExplicitEctExecute" }, | 
					
						
							|  |  |  | 		{ Fac_RequestSubaddress, "Fac_RequestSubaddress" }, | 
					
						
							|  |  |  | 		{ Fac_SubaddressTransfer, "Fac_SubaddressTransfer" }, | 
					
						
							|  |  |  | 		{ Fac_EctLinkIdRequest, "Fac_EctLinkIdRequest" }, | 
					
						
							|  |  |  | 		{ Fac_EctInform, "Fac_EctInform" }, | 
					
						
							|  |  |  | 		{ Fac_EctLoopTest, "Fac_EctLoopTest" }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		{ Fac_ChargingRequest, "Fac_ChargingRequest" }, | 
					
						
							|  |  |  | 		{ Fac_AOCSCurrency, "Fac_AOCSCurrency" }, | 
					
						
							|  |  |  | 		{ Fac_AOCSSpecialArr, "Fac_AOCSSpecialArr" }, | 
					
						
							|  |  |  | 		{ Fac_AOCDCurrency, "Fac_AOCDCurrency" }, | 
					
						
							|  |  |  | 		{ Fac_AOCDChargingUnit, "Fac_AOCDChargingUnit" }, | 
					
						
							|  |  |  | 		{ Fac_AOCECurrency, "Fac_AOCECurrency" }, | 
					
						
							|  |  |  | 		{ Fac_AOCEChargingUnit, "Fac_AOCEChargingUnit" }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		{ Fac_StatusRequest, "Fac_StatusRequest" }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		{ Fac_CallInfoRetain, "Fac_CallInfoRetain" }, | 
					
						
							|  |  |  | 		{ Fac_EraseCallLinkageID, "Fac_EraseCallLinkageID" }, | 
					
						
							|  |  |  | 		{ Fac_CCBSDeactivate, "Fac_CCBSDeactivate" }, | 
					
						
							|  |  |  | 		{ Fac_CCBSErase, "Fac_CCBSErase" }, | 
					
						
							|  |  |  | 		{ Fac_CCBSRemoteUserFree, "Fac_CCBSRemoteUserFree" }, | 
					
						
							|  |  |  | 		{ Fac_CCBSCall, "Fac_CCBSCall" }, | 
					
						
							|  |  |  | 		{ Fac_CCBSStatusRequest, "Fac_CCBSStatusRequest" }, | 
					
						
							|  |  |  | 		{ Fac_CCBSBFree, "Fac_CCBSBFree" }, | 
					
						
							|  |  |  | 		{ Fac_CCBSStopAlerting, "Fac_CCBSStopAlerting" }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		{ Fac_CCBSRequest, "Fac_CCBSRequest" }, | 
					
						
							|  |  |  | 		{ Fac_CCBSInterrogate, "Fac_CCBSInterrogate" }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		{ Fac_CCNRRequest, "Fac_CCNRRequest" }, | 
					
						
							|  |  |  | 		{ Fac_CCNRInterrogate, "Fac_CCNRInterrogate" }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		{ Fac_CCBS_T_Call, "Fac_CCBS_T_Call" }, | 
					
						
							|  |  |  | 		{ Fac_CCBS_T_Suspend, "Fac_CCBS_T_Suspend" }, | 
					
						
							|  |  |  | 		{ Fac_CCBS_T_Resume, "Fac_CCBS_T_Resume" }, | 
					
						
							|  |  |  | 		{ Fac_CCBS_T_RemoteUserFree, "Fac_CCBS_T_RemoteUserFree" }, | 
					
						
							|  |  |  | 		{ Fac_CCBS_T_Available, "Fac_CCBS_T_Available" }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		{ Fac_CCBS_T_Request, "Fac_CCBS_T_Request" }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		{ Fac_CCNR_T_Request, "Fac_CCNR_T_Request" }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 		{ Fac_CFActivate, "Fac_CFActivate" }, | 
					
						
							|  |  |  | 		{ Fac_CFDeactivate, "Fac_CFDeactivate" }, | 
					
						
							|  |  |  | 		{ Fac_CD, "Fac_CD" }, | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 		{ Fac_AOCDCurrency, "Fac_AOCDCurrency" }, | 
					
						
							|  |  |  | 		{ Fac_AOCDChargingUnit, "Fac_AOCDChargingUnit" }, | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | #endif	/* defined(AST_MISDN_ENHANCEMENTS) */
 | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | /* *INDENT-ON* */ | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 	unsigned index; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 	for (index = 0; index < ARRAY_LEN(arr); ++index) { | 
					
						
							|  |  |  | 		if (arr[index].facility == facility) { | 
					
						
							|  |  |  | 			return arr[index].name; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-04-03 22:41:46 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-15 16:49:26 +00:00
										 |  |  | 	return "unknown"; | 
					
						
							| 
									
										
										
										
											2009-04-03 22:41:46 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | void misdn_lib_log_ies(struct misdn_bchannel *bc) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 	struct misdn_stack *stack; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	if (!bc) return; | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 	stack = get_stack_by_bc(bc); | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!stack) return; | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-03 22:41:46 +00:00
										 |  |  | 	cb_log(2, stack->port, | 
					
						
							|  |  |  | 		" --> channel:%d mode:%s cause:%d ocause:%d\n", | 
					
						
							|  |  |  | 		bc->channel, | 
					
						
							|  |  |  | 		stack->nt ? "NT" : "TE", | 
					
						
							|  |  |  | 		bc->cause, | 
					
						
							|  |  |  | 		bc->out_cause); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cb_log(2, stack->port, | 
					
						
							|  |  |  | 		" --> info_dad:%s dialed numtype:%d plan:%d\n", | 
					
						
							|  |  |  | 		bc->info_dad, | 
					
						
							|  |  |  | 		bc->dialed.number_type, | 
					
						
							|  |  |  | 		bc->dialed.number_plan); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cb_log(2, stack->port, | 
					
						
							|  |  |  | 		" --> caller:\"%s\" <%s> type:%d plan:%d pres:%d screen:%d\n", | 
					
						
							|  |  |  | 		bc->caller.name, | 
					
						
							|  |  |  | 		bc->caller.number, | 
					
						
							|  |  |  | 		bc->caller.number_type, | 
					
						
							|  |  |  | 		bc->caller.number_plan, | 
					
						
							|  |  |  | 		bc->caller.presentation, | 
					
						
							|  |  |  | 		bc->caller.screening); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cb_log(2, stack->port, | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		" --> redirecting-from:\"%s\" <%s> type:%d plan:%d pres:%d screen:%d\n", | 
					
						
							| 
									
										
										
										
											2009-04-03 22:41:46 +00:00
										 |  |  | 		bc->redirecting.from.name, | 
					
						
							|  |  |  | 		bc->redirecting.from.number, | 
					
						
							|  |  |  | 		bc->redirecting.from.number_type, | 
					
						
							|  |  |  | 		bc->redirecting.from.number_plan, | 
					
						
							|  |  |  | 		bc->redirecting.from.presentation, | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		bc->redirecting.from.screening); | 
					
						
							|  |  |  | 	cb_log(2, stack->port, | 
					
						
							|  |  |  | 		" --> redirecting-to:\"%s\" <%s> type:%d plan:%d pres:%d screen:%d\n", | 
					
						
							|  |  |  | 		bc->redirecting.to.name, | 
					
						
							|  |  |  | 		bc->redirecting.to.number, | 
					
						
							|  |  |  | 		bc->redirecting.to.number_type, | 
					
						
							|  |  |  | 		bc->redirecting.to.number_plan, | 
					
						
							|  |  |  | 		bc->redirecting.to.presentation, | 
					
						
							|  |  |  | 		bc->redirecting.to.screening); | 
					
						
							|  |  |  | 	cb_log(2, stack->port, | 
					
						
							|  |  |  | 		" --> redirecting reason:%d count:%d\n", | 
					
						
							|  |  |  | 		bc->redirecting.reason, | 
					
						
							|  |  |  | 		bc->redirecting.count); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	cb_log(2, stack->port, | 
					
						
							| 
									
										
										
										
											2009-04-03 22:41:46 +00:00
										 |  |  | 		" --> connected:\"%s\" <%s> type:%d plan:%d pres:%d screen:%d\n", | 
					
						
							|  |  |  | 		bc->connected.name, | 
					
						
							|  |  |  | 		bc->connected.number, | 
					
						
							|  |  |  | 		bc->connected.number_type, | 
					
						
							|  |  |  | 		bc->connected.number_plan, | 
					
						
							|  |  |  | 		bc->connected.presentation, | 
					
						
							|  |  |  | 		bc->connected.screening); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 	cb_log(3, stack->port, " --> caps:%s pi:%x keypad:%s sending_complete:%d\n", bearer2str(bc->capability),bc->progress_indicator, bc->keypad, bc->sending_complete); | 
					
						
							| 
									
										
										
										
											2009-04-03 22:41:46 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	cb_log(4, stack->port, " --> set_pres:%d pres:%d\n", bc->set_presentation, bc->presentation); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | 	cb_log(4, stack->port, " --> addr:%x l3id:%x b_stid:%x layer_id:%x\n", bc->addr, bc->l3_id, bc->b_stid, bc->layer_id); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	cb_log(4, stack->port, " --> facility in:%s out:%s\n", fac2str(bc->fac_in.Function), fac2str(bc->fac_out.Function)); | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	cb_log(5, stack->port, " --> urate:%d rate:%d mode:%d user1:%d\n", bc->urate, bc->rate, bc->mode,bc->user1); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-18 16:23:05 +00:00
										 |  |  | 	cb_log(5, stack->port, " --> bc:%p h:%d sh:%d\n", bc, bc->holded, bc->stack_holder); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Merged revisions 62912 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r62912 | crichter | 2007-05-03 16:36:32 +0200 (Do, 03 Mai 2007) | 17 lines
Merged revisions 61357,61770,62885 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r61357 | crichter | 2007-04-11 14:05:57 +0200 (Mi, 11 Apr 2007) | 1 line
some fixes for PMP Hold/Retrieve, it should work now, when briding=no
........
r61770 | crichter | 2007-04-24 15:50:05 +0200 (Di, 24 Apr 2007) | 1 line
added lock for sending messages to avoid double sending. shuffled some empty_chans after the cb_event calls, this avoids that a release_complete from a quite different call releases a fresh created setup by accident.
........
r62885 | crichter | 2007-05-03 15:59:00 +0200 (Do, 03 Mai 2007) | 1 line
fixed the problem that misdn_write did not return -1 when called with 0 samples in a frame this resultet in a deadlock in some circumstances, when the call ended because of a busy extension.  added encoding of keypad.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@64955 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-05-18 09:50:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define RETURN(a,b) {retval=a; goto b;}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | static void misdn_send_lock(struct misdn_bchannel *bc) | 
					
						
							| 
									
										
											  
											
												Merged revisions 62912 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r62912 | crichter | 2007-05-03 16:36:32 +0200 (Do, 03 Mai 2007) | 17 lines
Merged revisions 61357,61770,62885 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r61357 | crichter | 2007-04-11 14:05:57 +0200 (Mi, 11 Apr 2007) | 1 line
some fixes for PMP Hold/Retrieve, it should work now, when briding=no
........
r61770 | crichter | 2007-04-24 15:50:05 +0200 (Di, 24 Apr 2007) | 1 line
added lock for sending messages to avoid double sending. shuffled some empty_chans after the cb_event calls, this avoids that a release_complete from a quite different call releases a fresh created setup by accident.
........
r62885 | crichter | 2007-05-03 15:59:00 +0200 (Do, 03 Mai 2007) | 1 line
fixed the problem that misdn_write did not return -1 when called with 0 samples in a frame this resultet in a deadlock in some circumstances, when the call ended because of a busy extension.  added encoding of keypad.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@64955 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-05-18 09:50:33 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	//cb_log(0,bc->port,"Locking bc->pid:%d\n", bc->pid);
 | 
					
						
							| 
									
										
										
										
											2007-06-11 11:40:21 +00:00
										 |  |  | 	if (bc->send_lock) | 
					
						
							|  |  |  | 		pthread_mutex_lock(&bc->send_lock->lock); | 
					
						
							| 
									
										
											  
											
												Merged revisions 62912 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r62912 | crichter | 2007-05-03 16:36:32 +0200 (Do, 03 Mai 2007) | 17 lines
Merged revisions 61357,61770,62885 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r61357 | crichter | 2007-04-11 14:05:57 +0200 (Mi, 11 Apr 2007) | 1 line
some fixes for PMP Hold/Retrieve, it should work now, when briding=no
........
r61770 | crichter | 2007-04-24 15:50:05 +0200 (Di, 24 Apr 2007) | 1 line
added lock for sending messages to avoid double sending. shuffled some empty_chans after the cb_event calls, this avoids that a release_complete from a quite different call releases a fresh created setup by accident.
........
r62885 | crichter | 2007-05-03 15:59:00 +0200 (Do, 03 Mai 2007) | 1 line
fixed the problem that misdn_write did not return -1 when called with 0 samples in a frame this resultet in a deadlock in some circumstances, when the call ended because of a busy extension.  added encoding of keypad.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@64955 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-05-18 09:50:33 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | static void misdn_send_unlock(struct misdn_bchannel *bc) | 
					
						
							| 
									
										
											  
											
												Merged revisions 62912 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r62912 | crichter | 2007-05-03 16:36:32 +0200 (Do, 03 Mai 2007) | 17 lines
Merged revisions 61357,61770,62885 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r61357 | crichter | 2007-04-11 14:05:57 +0200 (Mi, 11 Apr 2007) | 1 line
some fixes for PMP Hold/Retrieve, it should work now, when briding=no
........
r61770 | crichter | 2007-04-24 15:50:05 +0200 (Di, 24 Apr 2007) | 1 line
added lock for sending messages to avoid double sending. shuffled some empty_chans after the cb_event calls, this avoids that a release_complete from a quite different call releases a fresh created setup by accident.
........
r62885 | crichter | 2007-05-03 15:59:00 +0200 (Do, 03 Mai 2007) | 1 line
fixed the problem that misdn_write did not return -1 when called with 0 samples in a frame this resultet in a deadlock in some circumstances, when the call ended because of a busy extension.  added encoding of keypad.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@64955 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-05-18 09:50:33 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	//cb_log(0,bc->port,"UnLocking bc->pid:%d\n", bc->pid);
 | 
					
						
							| 
									
										
										
										
											2007-06-11 11:40:21 +00:00
										 |  |  | 	if (bc->send_lock) | 
					
						
							|  |  |  | 		pthread_mutex_unlock(&bc->send_lock->lock); | 
					
						
							| 
									
										
											  
											
												Merged revisions 62912 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r62912 | crichter | 2007-05-03 16:36:32 +0200 (Do, 03 Mai 2007) | 17 lines
Merged revisions 61357,61770,62885 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r61357 | crichter | 2007-04-11 14:05:57 +0200 (Mi, 11 Apr 2007) | 1 line
some fixes for PMP Hold/Retrieve, it should work now, when briding=no
........
r61770 | crichter | 2007-04-24 15:50:05 +0200 (Di, 24 Apr 2007) | 1 line
added lock for sending messages to avoid double sending. shuffled some empty_chans after the cb_event calls, this avoids that a release_complete from a quite different call releases a fresh created setup by accident.
........
r62885 | crichter | 2007-05-03 15:59:00 +0200 (Do, 03 Mai 2007) | 1 line
fixed the problem that misdn_write did not return -1 when called with 0 samples in a frame this resultet in a deadlock in some circumstances, when the call ended because of a busy extension.  added encoding of keypad.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@64955 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-05-18 09:50:33 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | int misdn_lib_send_event(struct misdn_bchannel *bc, enum event_e event ) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 	msg_t *msg; | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	struct misdn_bchannel *bc2; | 
					
						
							| 
									
										
										
										
											2009-07-14 17:01:48 +00:00
										 |  |  | 	struct misdn_bchannel *held_bc; | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 	struct misdn_stack *stack; | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	int retval = 0; | 
					
						
							|  |  |  | 	int channel; | 
					
						
							|  |  |  | 	int tmpcause; | 
					
						
							|  |  |  | 	int tmp_out_cause; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 	if (!bc) | 
					
						
							|  |  |  | 		RETURN(-1,OUT_POST_UNLOCK); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 	stack = get_stack_by_bc(bc); | 
					
						
							| 
									
										
										
										
											2006-04-04 19:09:26 +00:00
										 |  |  | 	if (!stack) { | 
					
						
							| 
									
										
										
										
											2009-04-03 22:41:46 +00:00
										 |  |  | 		cb_log(0,bc->port, | 
					
						
							|  |  |  | 			"SENDEVENT: no Stack for event:%s caller:\"%s\" <%s> dialed:%s \n", | 
					
						
							|  |  |  | 			isdn_get_info(msgs_g, event, 0), | 
					
						
							|  |  |  | 			bc->caller.name, | 
					
						
							|  |  |  | 			bc->caller.number, | 
					
						
							|  |  |  | 			bc->dialed.number); | 
					
						
							| 
									
										
											  
											
												Merged revisions 62912 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r62912 | crichter | 2007-05-03 16:36:32 +0200 (Do, 03 Mai 2007) | 17 lines
Merged revisions 61357,61770,62885 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r61357 | crichter | 2007-04-11 14:05:57 +0200 (Mi, 11 Apr 2007) | 1 line
some fixes for PMP Hold/Retrieve, it should work now, when briding=no
........
r61770 | crichter | 2007-04-24 15:50:05 +0200 (Di, 24 Apr 2007) | 1 line
added lock for sending messages to avoid double sending. shuffled some empty_chans after the cb_event calls, this avoids that a release_complete from a quite different call releases a fresh created setup by accident.
........
r62885 | crichter | 2007-05-03 15:59:00 +0200 (Do, 03 Mai 2007) | 1 line
fixed the problem that misdn_write did not return -1 when called with 0 samples in a frame this resultet in a deadlock in some circumstances, when the call ended because of a busy extension.  added encoding of keypad.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@64955 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-05-18 09:50:33 +00:00
										 |  |  | 		RETURN(-1,OUT); | 
					
						
							| 
									
										
										
										
											2006-04-04 19:09:26 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Merged revisions 62912 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r62912 | crichter | 2007-05-03 16:36:32 +0200 (Do, 03 Mai 2007) | 17 lines
Merged revisions 61357,61770,62885 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r61357 | crichter | 2007-04-11 14:05:57 +0200 (Mi, 11 Apr 2007) | 1 line
some fixes for PMP Hold/Retrieve, it should work now, when briding=no
........
r61770 | crichter | 2007-04-24 15:50:05 +0200 (Di, 24 Apr 2007) | 1 line
added lock for sending messages to avoid double sending. shuffled some empty_chans after the cb_event calls, this avoids that a release_complete from a quite different call releases a fresh created setup by accident.
........
r62885 | crichter | 2007-05-03 15:59:00 +0200 (Do, 03 Mai 2007) | 1 line
fixed the problem that misdn_write did not return -1 when called with 0 samples in a frame this resultet in a deadlock in some circumstances, when the call ended because of a busy extension.  added encoding of keypad.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@64955 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-05-18 09:50:33 +00:00
										 |  |  | 	misdn_send_lock(bc); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 	cb_log(6,stack->port,"SENDEVENT: stack->nt:%d stack->upperid:%x\n",stack->nt, stack->upper_id); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if ( stack->nt && !stack->l1link) { | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		/** Queue Event **/ | 
					
						
							|  |  |  | 		bc->evq=event; | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 		cb_log(1, stack->port, "Queueing Event %s because L1 is down (btw. Activating L1)\n", isdn_get_info(msgs_g, event, 0)); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		misdn_lib_get_l1_up(stack); | 
					
						
							| 
									
										
											  
											
												Merged revisions 62912 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r62912 | crichter | 2007-05-03 16:36:32 +0200 (Do, 03 Mai 2007) | 17 lines
Merged revisions 61357,61770,62885 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r61357 | crichter | 2007-04-11 14:05:57 +0200 (Mi, 11 Apr 2007) | 1 line
some fixes for PMP Hold/Retrieve, it should work now, when briding=no
........
r61770 | crichter | 2007-04-24 15:50:05 +0200 (Di, 24 Apr 2007) | 1 line
added lock for sending messages to avoid double sending. shuffled some empty_chans after the cb_event calls, this avoids that a release_complete from a quite different call releases a fresh created setup by accident.
........
r62885 | crichter | 2007-05-03 15:59:00 +0200 (Do, 03 Mai 2007) | 1 line
fixed the problem that misdn_write did not return -1 when called with 0 samples in a frame this resultet in a deadlock in some circumstances, when the call ended because of a busy extension.  added encoding of keypad.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@64955 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-05-18 09:50:33 +00:00
										 |  |  | 		RETURN(0,OUT); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-03 22:41:46 +00:00
										 |  |  | 	cb_log(1, stack->port, | 
					
						
							|  |  |  | 		"I SEND:%s caller:\"%s\" <%s> dialed:%s pid:%d\n", | 
					
						
							|  |  |  | 		isdn_get_info(msgs_g, event, 0), | 
					
						
							|  |  |  | 		bc->caller.name, | 
					
						
							|  |  |  | 		bc->caller.number, | 
					
						
							|  |  |  | 		bc->dialed.number, | 
					
						
							|  |  |  | 		bc->pid); | 
					
						
							| 
									
										
										
										
											2007-01-03 11:03:57 +00:00
										 |  |  | 	cb_log(4, stack->port, " --> bc_state:%s\n",bc_state2str(bc->bc_state)); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	misdn_lib_log_ies(bc); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	switch (event) { | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	case EVENT_REGISTER: | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	case EVENT_SETUP: | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 		if (create_process(glob_mgr->midev, bc) < 0) { | 
					
						
							|  |  |  | 			cb_log(0, stack->port, " No free channel at the moment @ send_event\n"); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Merged revisions 62912 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r62912 | crichter | 2007-05-03 16:36:32 +0200 (Do, 03 Mai 2007) | 17 lines
Merged revisions 61357,61770,62885 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r61357 | crichter | 2007-04-11 14:05:57 +0200 (Mi, 11 Apr 2007) | 1 line
some fixes for PMP Hold/Retrieve, it should work now, when briding=no
........
r61770 | crichter | 2007-04-24 15:50:05 +0200 (Di, 24 Apr 2007) | 1 line
added lock for sending messages to avoid double sending. shuffled some empty_chans after the cb_event calls, this avoids that a release_complete from a quite different call releases a fresh created setup by accident.
........
r62885 | crichter | 2007-05-03 15:59:00 +0200 (Do, 03 Mai 2007) | 1 line
fixed the problem that misdn_write did not return -1 when called with 0 samples in a frame this resultet in a deadlock in some circumstances, when the call ended because of a busy extension.  added encoding of keypad.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@64955 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-05-18 09:50:33 +00:00
										 |  |  | 			RETURN(-ENOCHAN,OUT); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case EVENT_PROGRESS: | 
					
						
							|  |  |  | 	case EVENT_ALERTING: | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	case EVENT_PROCEEDING: | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	case EVENT_SETUP_ACKNOWLEDGE: | 
					
						
							| 
									
										
										
										
											2007-06-27 08:08:58 +00:00
										 |  |  | 	case EVENT_CONNECT: | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 		if (!stack->nt) | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2007-06-25 09:44:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	case EVENT_RETRIEVE_ACKNOWLEDGE: | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		if (stack->nt) { | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			if (bc->channel <=0 ) { /*  else we have the channel already */ | 
					
						
							| 
									
										
										
										
											2007-07-02 09:17:07 +00:00
										 |  |  | 				if (find_free_chan_in_stack(stack, bc, 0, 0)<0) { | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 					cb_log(0, stack->port, " No free channel at the moment\n"); | 
					
						
							| 
									
										
											  
											
												Merged revisions 49313 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r49313 | crichter | 2007-01-03 10:06:50 +0100 (Mi, 03 Jan 2007) | 41 lines
Merged revisions 48319,48321,48467,48552,48576,49135,49303 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r48319 | crichter | 2006-12-06 15:35:25 +0100 (Mi, 06 Dez 2006) | 1 line
changed a few debugs to higher debug levels
........
r48321 | crichter | 2006-12-06 16:48:45 +0100 (Mi, 06 Dez 2006) | 1 line
added the export and import of the MISDN_ADDRESS_COMPLETE Variable to inidcate wether the extension is already completely dialed or if there might come additional digits by information elements. also added some docs for that.
........
r48467 | crichter | 2006-12-14 14:03:49 +0100 (Do, 14 Dez 2006) | 1 line
removed FIXUP state. added check for channel allocation conflict when we create a setup while the other site creates a setup on the same channel, besides the check we resolve this conflict.
........
r48552 | crichter | 2006-12-18 11:19:39 +0100 (Mo, 18 Dez 2006) | 1 line
when our PTP Partner sends us a SETUP with a preselected channel we just accept it, even when we're NT. added some checks for segfaults.
........
r48576 | crichter | 2006-12-19 14:08:51 +0100 (Di, 19 Dez 2006) | 1 line
when we reject a channel, because it's in use already, we shouldn't process the setup anymore. made the channel allocation a bit easier and more understandable, removed a few unused lines
........
r49135 | crichter | 2007-01-02 11:07:22 +0100 (Di, 02 Jan 2007) | 1 line
added check for channel ranges in the set/empty channel functions. set pmp_l1_check default to no. added misdn restart pid cli command. added cleaning of channel when we send a RELEASE_COMPLETE. 
........
r49303 | crichter | 2007-01-03 09:24:00 +0100 (Mi, 03 Jan 2007) | 9 lines
* Added check for bridging in misdn_call to avoid setting echocancellation
  when 2 mISDN channels are involved and when bridging is set. That lead
  to a kernel panic before under different situations, because we switched 
  about 2 times between hardware bridging and echocancelation
* readded MISDN_URATE variable which got lost before, this should make app_v110
  work again
* fixed typo
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@49321 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-01-03 11:15:02 +00:00
										 |  |  | 					/*FIXME: add disconnect*/ | 
					
						
							| 
									
										
											  
											
												Merged revisions 62912 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r62912 | crichter | 2007-05-03 16:36:32 +0200 (Do, 03 Mai 2007) | 17 lines
Merged revisions 61357,61770,62885 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r61357 | crichter | 2007-04-11 14:05:57 +0200 (Mi, 11 Apr 2007) | 1 line
some fixes for PMP Hold/Retrieve, it should work now, when briding=no
........
r61770 | crichter | 2007-04-24 15:50:05 +0200 (Di, 24 Apr 2007) | 1 line
added lock for sending messages to avoid double sending. shuffled some empty_chans after the cb_event calls, this avoids that a release_complete from a quite different call releases a fresh created setup by accident.
........
r62885 | crichter | 2007-05-03 15:59:00 +0200 (Do, 03 Mai 2007) | 1 line
fixed the problem that misdn_write did not return -1 when called with 0 samples in a frame this resultet in a deadlock in some circumstances, when the call ended because of a busy extension.  added encoding of keypad.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@64955 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-05-18 09:50:33 +00:00
										 |  |  | 					RETURN(-ENOCHAN,OUT); | 
					
						
							| 
									
										
											  
											
												Merged revisions 49313 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r49313 | crichter | 2007-01-03 10:06:50 +0100 (Mi, 03 Jan 2007) | 41 lines
Merged revisions 48319,48321,48467,48552,48576,49135,49303 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r48319 | crichter | 2006-12-06 15:35:25 +0100 (Mi, 06 Dez 2006) | 1 line
changed a few debugs to higher debug levels
........
r48321 | crichter | 2006-12-06 16:48:45 +0100 (Mi, 06 Dez 2006) | 1 line
added the export and import of the MISDN_ADDRESS_COMPLETE Variable to inidcate wether the extension is already completely dialed or if there might come additional digits by information elements. also added some docs for that.
........
r48467 | crichter | 2006-12-14 14:03:49 +0100 (Do, 14 Dez 2006) | 1 line
removed FIXUP state. added check for channel allocation conflict when we create a setup while the other site creates a setup on the same channel, besides the check we resolve this conflict.
........
r48552 | crichter | 2006-12-18 11:19:39 +0100 (Mo, 18 Dez 2006) | 1 line
when our PTP Partner sends us a SETUP with a preselected channel we just accept it, even when we're NT. added some checks for segfaults.
........
r48576 | crichter | 2006-12-19 14:08:51 +0100 (Di, 19 Dez 2006) | 1 line
when we reject a channel, because it's in use already, we shouldn't process the setup anymore. made the channel allocation a bit easier and more understandable, removed a few unused lines
........
r49135 | crichter | 2007-01-02 11:07:22 +0100 (Di, 02 Jan 2007) | 1 line
added check for channel ranges in the set/empty channel functions. set pmp_l1_check default to no. added misdn restart pid cli command. added cleaning of channel when we send a RELEASE_COMPLETE. 
........
r49303 | crichter | 2007-01-03 09:24:00 +0100 (Mi, 03 Jan 2007) | 9 lines
* Added check for bridging in misdn_call to avoid setting echocancellation
  when 2 mISDN channels are involved and when bridging is set. That lead
  to a kernel panic before under different situations, because we switched 
  about 2 times between hardware bridging and echocancelation
* readded MISDN_URATE variable which got lost before, this should make app_v110
  work again
* fixed typo
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@49321 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-01-03 11:15:02 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			/* Its that i generate channels */ | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Merged revisions 62912 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r62912 | crichter | 2007-05-03 16:36:32 +0200 (Do, 03 Mai 2007) | 17 lines
Merged revisions 61357,61770,62885 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r61357 | crichter | 2007-04-11 14:05:57 +0200 (Mi, 11 Apr 2007) | 1 line
some fixes for PMP Hold/Retrieve, it should work now, when briding=no
........
r61770 | crichter | 2007-04-24 15:50:05 +0200 (Di, 24 Apr 2007) | 1 line
added lock for sending messages to avoid double sending. shuffled some empty_chans after the cb_event calls, this avoids that a release_complete from a quite different call releases a fresh created setup by accident.
........
r62885 | crichter | 2007-05-03 15:59:00 +0200 (Do, 03 Mai 2007) | 1 line
fixed the problem that misdn_write did not return -1 when called with 0 samples in a frame this resultet in a deadlock in some circumstances, when the call ended because of a busy extension.  added encoding of keypad.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@64955 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-05-18 09:50:33 +00:00
										 |  |  | 		retval=setup_bc(bc); | 
					
						
							|  |  |  | 		if (retval == -EINVAL) { | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 			cb_log(0,bc->port,"send_event: setup_bc failed\n"); | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | 		if (misdn_cap_is_speech(bc->capability)) { | 
					
						
							|  |  |  | 			if ((event==EVENT_CONNECT)||(event==EVENT_RETRIEVE_ACKNOWLEDGE)) { | 
					
						
							|  |  |  | 				if ( *bc->crypt_key ) { | 
					
						
							| 
									
										
										
										
											2009-04-03 22:41:46 +00:00
										 |  |  | 					cb_log(4, stack->port, | 
					
						
							|  |  |  | 						" --> ENABLING BLOWFISH channel:%d caller%d:\"%s\" <%s> dialed%d:%s\n", | 
					
						
							|  |  |  | 						bc->channel, | 
					
						
							|  |  |  | 						bc->caller.number_type, | 
					
						
							|  |  |  | 						bc->caller.name, | 
					
						
							|  |  |  | 						bc->caller.number, | 
					
						
							|  |  |  | 						bc->dialed.number_type, | 
					
						
							|  |  |  | 						bc->dialed.number); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | 					manager_ph_control_block(bc,  BF_ENABLE_KEY, bc->crypt_key, strlen(bc->crypt_key) ); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | 				if (!bc->nodsp) manager_ph_control(bc,  DTMF_TONE_START, 0); | 
					
						
							|  |  |  | 				manager_ec_enable(bc); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | 				if (bc->txgain != 0) { | 
					
						
							|  |  |  | 					cb_log(4, stack->port,  "--> Changing txgain to %d\n", bc->txgain); | 
					
						
							|  |  |  | 					manager_ph_control(bc, VOL_CHANGE_TX, bc->txgain); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | 				if ( bc->rxgain != 0 ) { | 
					
						
							|  |  |  | 					cb_log(4, stack->port,  "--> Changing rxgain to %d\n", bc->rxgain); | 
					
						
							|  |  |  | 					manager_ph_control(bc, VOL_CHANGE_RX, bc->rxgain); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	case EVENT_HOLD_ACKNOWLEDGE: | 
					
						
							| 
									
										
										
										
											2009-07-14 17:01:48 +00:00
										 |  |  | 		held_bc = malloc(sizeof(struct misdn_bchannel)); | 
					
						
							|  |  |  | 		if (!held_bc) { | 
					
						
							|  |  |  | 			cb_log(0, bc->port, "Could not allocate held_bc!!!\n"); | 
					
						
							| 
									
										
											  
											
												Merged revisions 62912 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r62912 | crichter | 2007-05-03 16:36:32 +0200 (Do, 03 Mai 2007) | 17 lines
Merged revisions 61357,61770,62885 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r61357 | crichter | 2007-04-11 14:05:57 +0200 (Mi, 11 Apr 2007) | 1 line
some fixes for PMP Hold/Retrieve, it should work now, when briding=no
........
r61770 | crichter | 2007-04-24 15:50:05 +0200 (Di, 24 Apr 2007) | 1 line
added lock for sending messages to avoid double sending. shuffled some empty_chans after the cb_event calls, this avoids that a release_complete from a quite different call releases a fresh created setup by accident.
........
r62885 | crichter | 2007-05-03 15:59:00 +0200 (Do, 03 Mai 2007) | 1 line
fixed the problem that misdn_write did not return -1 when called with 0 samples in a frame this resultet in a deadlock in some circumstances, when the call ended because of a busy extension.  added encoding of keypad.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@64955 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-05-18 09:50:33 +00:00
										 |  |  | 			RETURN(-1,OUT); | 
					
						
							| 
									
										
										
										
											2006-10-11 08:23:16 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-14 17:01:48 +00:00
										 |  |  | 		/* backup the bc and put it in storage */ | 
					
						
							|  |  |  | 		*held_bc = *bc; | 
					
						
							|  |  |  | 		held_bc->holded = 1; | 
					
						
							|  |  |  | 		held_bc->channel = 0;/* A held call does not have a channel anymore. */ | 
					
						
							|  |  |  | 		held_bc->channel_preselected = 0; | 
					
						
							|  |  |  | 		held_bc->channel_found = 0; | 
					
						
							|  |  |  | 		bc_state_change(held_bc, BCHAN_CLEANED); | 
					
						
							|  |  |  | 		stack_holder_add(stack, held_bc); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-14 17:01:48 +00:00
										 |  |  | 		/* kill the bridge and clean the real b-channel record */ | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		if (stack->nt) { | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 			if (bc->bc_state == BCHAN_BRIDGED) { | 
					
						
							|  |  |  | 				misdn_split_conf(bc,bc->conf_id); | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 				bc2 = find_bc_by_confid(bc->conf_id); | 
					
						
							| 
									
										
											  
											
												Merged revisions 62912 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r62912 | crichter | 2007-05-03 16:36:32 +0200 (Do, 03 Mai 2007) | 17 lines
Merged revisions 61357,61770,62885 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r61357 | crichter | 2007-04-11 14:05:57 +0200 (Mi, 11 Apr 2007) | 1 line
some fixes for PMP Hold/Retrieve, it should work now, when briding=no
........
r61770 | crichter | 2007-04-24 15:50:05 +0200 (Di, 24 Apr 2007) | 1 line
added lock for sending messages to avoid double sending. shuffled some empty_chans after the cb_event calls, this avoids that a release_complete from a quite different call releases a fresh created setup by accident.
........
r62885 | crichter | 2007-05-03 15:59:00 +0200 (Do, 03 Mai 2007) | 1 line
fixed the problem that misdn_write did not return -1 when called with 0 samples in a frame this resultet in a deadlock in some circumstances, when the call ended because of a busy extension.  added encoding of keypad.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@64955 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-05-18 09:50:33 +00:00
										 |  |  | 				if (!bc2) { | 
					
						
							| 
									
										
										
										
											2006-10-11 08:23:16 +00:00
										 |  |  | 					cb_log(0,bc->port,"We have no second bc in bridge???\n"); | 
					
						
							| 
									
										
											  
											
												Merged revisions 62912 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r62912 | crichter | 2007-05-03 16:36:32 +0200 (Do, 03 Mai 2007) | 17 lines
Merged revisions 61357,61770,62885 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r61357 | crichter | 2007-04-11 14:05:57 +0200 (Mi, 11 Apr 2007) | 1 line
some fixes for PMP Hold/Retrieve, it should work now, when briding=no
........
r61770 | crichter | 2007-04-24 15:50:05 +0200 (Di, 24 Apr 2007) | 1 line
added lock for sending messages to avoid double sending. shuffled some empty_chans after the cb_event calls, this avoids that a release_complete from a quite different call releases a fresh created setup by accident.
........
r62885 | crichter | 2007-05-03 15:59:00 +0200 (Do, 03 Mai 2007) | 1 line
fixed the problem that misdn_write did not return -1 when called with 0 samples in a frame this resultet in a deadlock in some circumstances, when the call ended because of a busy extension.  added encoding of keypad.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@64955 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-05-18 09:50:33 +00:00
										 |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2006-10-11 08:23:16 +00:00
										 |  |  | 					misdn_split_conf(bc2,bc->conf_id); | 
					
						
							| 
									
										
											  
											
												Merged revisions 62912 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r62912 | crichter | 2007-05-03 16:36:32 +0200 (Do, 03 Mai 2007) | 17 lines
Merged revisions 61357,61770,62885 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r61357 | crichter | 2007-04-11 14:05:57 +0200 (Mi, 11 Apr 2007) | 1 line
some fixes for PMP Hold/Retrieve, it should work now, when briding=no
........
r61770 | crichter | 2007-04-24 15:50:05 +0200 (Di, 24 Apr 2007) | 1 line
added lock for sending messages to avoid double sending. shuffled some empty_chans after the cb_event calls, this avoids that a release_complete from a quite different call releases a fresh created setup by accident.
........
r62885 | crichter | 2007-05-03 15:59:00 +0200 (Do, 03 Mai 2007) | 1 line
fixed the problem that misdn_write did not return -1 when called with 0 samples in a frame this resultet in a deadlock in some circumstances, when the call ended because of a busy extension.  added encoding of keypad.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@64955 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-05-18 09:50:33 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 			channel = bc->channel; | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			empty_bc(bc); | 
					
						
							| 
									
										
										
										
											2006-06-01 12:51:41 +00:00
										 |  |  | 			clean_up_bc(bc); | 
					
						
							| 
									
										
										
										
											2007-06-25 09:37:49 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if (channel>0) | 
					
						
							| 
									
										
										
										
											2007-06-25 09:46:18 +00:00
										 |  |  | 				empty_chan_in_stack(stack,channel); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 			bc->in_use=0; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2006-07-06 15:11:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* finishing the channel eh ? */ | 
					
						
							|  |  |  | 	case EVENT_DISCONNECT: | 
					
						
							|  |  |  | 		if (!bc->need_disconnect) { | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 			cb_log(0, bc->port, " --> we have already sent DISCONNECT\n"); | 
					
						
							| 
									
										
											  
											
												Merged revisions 62912 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r62912 | crichter | 2007-05-03 16:36:32 +0200 (Do, 03 Mai 2007) | 17 lines
Merged revisions 61357,61770,62885 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r61357 | crichter | 2007-04-11 14:05:57 +0200 (Mi, 11 Apr 2007) | 1 line
some fixes for PMP Hold/Retrieve, it should work now, when briding=no
........
r61770 | crichter | 2007-04-24 15:50:05 +0200 (Di, 24 Apr 2007) | 1 line
added lock for sending messages to avoid double sending. shuffled some empty_chans after the cb_event calls, this avoids that a release_complete from a quite different call releases a fresh created setup by accident.
........
r62885 | crichter | 2007-05-03 15:59:00 +0200 (Do, 03 Mai 2007) | 1 line
fixed the problem that misdn_write did not return -1 when called with 0 samples in a frame this resultet in a deadlock in some circumstances, when the call ended because of a busy extension.  added encoding of keypad.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@64955 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-05-18 09:50:33 +00:00
										 |  |  | 			RETURN(-1,OUT); | 
					
						
							| 
									
										
										
										
											2006-07-06 15:11:40 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-06 15:11:40 +00:00
										 |  |  | 		bc->need_disconnect=0; | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	case EVENT_RELEASE: | 
					
						
							| 
									
										
										
										
											2006-07-06 15:11:40 +00:00
										 |  |  | 		if (!bc->need_release) { | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 			cb_log(0, bc->port, " --> we have already sent RELEASE\n"); | 
					
						
							| 
									
										
											  
											
												Merged revisions 62912 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r62912 | crichter | 2007-05-03 16:36:32 +0200 (Do, 03 Mai 2007) | 17 lines
Merged revisions 61357,61770,62885 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r61357 | crichter | 2007-04-11 14:05:57 +0200 (Mi, 11 Apr 2007) | 1 line
some fixes for PMP Hold/Retrieve, it should work now, when briding=no
........
r61770 | crichter | 2007-04-24 15:50:05 +0200 (Di, 24 Apr 2007) | 1 line
added lock for sending messages to avoid double sending. shuffled some empty_chans after the cb_event calls, this avoids that a release_complete from a quite different call releases a fresh created setup by accident.
........
r62885 | crichter | 2007-05-03 15:59:00 +0200 (Do, 03 Mai 2007) | 1 line
fixed the problem that misdn_write did not return -1 when called with 0 samples in a frame this resultet in a deadlock in some circumstances, when the call ended because of a busy extension.  added encoding of keypad.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@64955 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-05-18 09:50:33 +00:00
										 |  |  | 			RETURN(-1,OUT); | 
					
						
							| 
									
										
										
										
											2006-07-06 15:11:40 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2006-07-13 14:13:24 +00:00
										 |  |  | 		bc->need_disconnect=0; | 
					
						
							| 
									
										
										
										
											2006-07-06 15:11:40 +00:00
										 |  |  | 		bc->need_release=0; | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	case EVENT_RELEASE_COMPLETE: | 
					
						
							| 
									
										
										
										
											2006-07-06 15:11:40 +00:00
										 |  |  | 		if (!bc->need_release_complete) { | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 			cb_log(0, bc->port, " --> we have already sent RELEASE_COMPLETE\n"); | 
					
						
							| 
									
										
											  
											
												Merged revisions 62912 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r62912 | crichter | 2007-05-03 16:36:32 +0200 (Do, 03 Mai 2007) | 17 lines
Merged revisions 61357,61770,62885 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r61357 | crichter | 2007-04-11 14:05:57 +0200 (Mi, 11 Apr 2007) | 1 line
some fixes for PMP Hold/Retrieve, it should work now, when briding=no
........
r61770 | crichter | 2007-04-24 15:50:05 +0200 (Di, 24 Apr 2007) | 1 line
added lock for sending messages to avoid double sending. shuffled some empty_chans after the cb_event calls, this avoids that a release_complete from a quite different call releases a fresh created setup by accident.
........
r62885 | crichter | 2007-05-03 15:59:00 +0200 (Do, 03 Mai 2007) | 1 line
fixed the problem that misdn_write did not return -1 when called with 0 samples in a frame this resultet in a deadlock in some circumstances, when the call ended because of a busy extension.  added encoding of keypad.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@64955 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-05-18 09:50:33 +00:00
										 |  |  | 			RETURN(-1,OUT); | 
					
						
							| 
									
										
										
										
											2006-07-06 15:11:40 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2006-07-13 14:13:24 +00:00
										 |  |  | 		bc->need_disconnect=0; | 
					
						
							|  |  |  | 		bc->need_release=0; | 
					
						
							| 
									
										
										
										
											2006-07-06 15:11:40 +00:00
										 |  |  | 		bc->need_release_complete=0; | 
					
						
							| 
									
										
											  
											
												Merged revisions 49313 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r49313 | crichter | 2007-01-03 10:06:50 +0100 (Mi, 03 Jan 2007) | 41 lines
Merged revisions 48319,48321,48467,48552,48576,49135,49303 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r48319 | crichter | 2006-12-06 15:35:25 +0100 (Mi, 06 Dez 2006) | 1 line
changed a few debugs to higher debug levels
........
r48321 | crichter | 2006-12-06 16:48:45 +0100 (Mi, 06 Dez 2006) | 1 line
added the export and import of the MISDN_ADDRESS_COMPLETE Variable to inidcate wether the extension is already completely dialed or if there might come additional digits by information elements. also added some docs for that.
........
r48467 | crichter | 2006-12-14 14:03:49 +0100 (Do, 14 Dez 2006) | 1 line
removed FIXUP state. added check for channel allocation conflict when we create a setup while the other site creates a setup on the same channel, besides the check we resolve this conflict.
........
r48552 | crichter | 2006-12-18 11:19:39 +0100 (Mo, 18 Dez 2006) | 1 line
when our PTP Partner sends us a SETUP with a preselected channel we just accept it, even when we're NT. added some checks for segfaults.
........
r48576 | crichter | 2006-12-19 14:08:51 +0100 (Di, 19 Dez 2006) | 1 line
when we reject a channel, because it's in use already, we shouldn't process the setup anymore. made the channel allocation a bit easier and more understandable, removed a few unused lines
........
r49135 | crichter | 2007-01-02 11:07:22 +0100 (Di, 02 Jan 2007) | 1 line
added check for channel ranges in the set/empty channel functions. set pmp_l1_check default to no. added misdn restart pid cli command. added cleaning of channel when we send a RELEASE_COMPLETE. 
........
r49303 | crichter | 2007-01-03 09:24:00 +0100 (Mi, 03 Jan 2007) | 9 lines
* Added check for bridging in misdn_call to avoid setting echocancellation
  when 2 mISDN channels are involved and when bridging is set. That lead
  to a kernel panic before under different situations, because we switched 
  about 2 times between hardware bridging and echocancelation
* readded MISDN_URATE variable which got lost before, this should make app_v110
  work again
* fixed typo
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@49321 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-01-03 11:15:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (!stack->nt) { | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 			/* create cleanup in TE */ | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 			channel = bc->channel; | 
					
						
							|  |  |  | 			tmpcause = bc->cause; | 
					
						
							|  |  |  | 			tmp_out_cause = bc->out_cause; | 
					
						
							| 
									
										
										
										
											2007-06-25 09:37:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Merged revisions 49313 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r49313 | crichter | 2007-01-03 10:06:50 +0100 (Mi, 03 Jan 2007) | 41 lines
Merged revisions 48319,48321,48467,48552,48576,49135,49303 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r48319 | crichter | 2006-12-06 15:35:25 +0100 (Mi, 06 Dez 2006) | 1 line
changed a few debugs to higher debug levels
........
r48321 | crichter | 2006-12-06 16:48:45 +0100 (Mi, 06 Dez 2006) | 1 line
added the export and import of the MISDN_ADDRESS_COMPLETE Variable to inidcate wether the extension is already completely dialed or if there might come additional digits by information elements. also added some docs for that.
........
r48467 | crichter | 2006-12-14 14:03:49 +0100 (Do, 14 Dez 2006) | 1 line
removed FIXUP state. added check for channel allocation conflict when we create a setup while the other site creates a setup on the same channel, besides the check we resolve this conflict.
........
r48552 | crichter | 2006-12-18 11:19:39 +0100 (Mo, 18 Dez 2006) | 1 line
when our PTP Partner sends us a SETUP with a preselected channel we just accept it, even when we're NT. added some checks for segfaults.
........
r48576 | crichter | 2006-12-19 14:08:51 +0100 (Di, 19 Dez 2006) | 1 line
when we reject a channel, because it's in use already, we shouldn't process the setup anymore. made the channel allocation a bit easier and more understandable, removed a few unused lines
........
r49135 | crichter | 2007-01-02 11:07:22 +0100 (Di, 02 Jan 2007) | 1 line
added check for channel ranges in the set/empty channel functions. set pmp_l1_check default to no. added misdn restart pid cli command. added cleaning of channel when we send a RELEASE_COMPLETE. 
........
r49303 | crichter | 2007-01-03 09:24:00 +0100 (Mi, 03 Jan 2007) | 9 lines
* Added check for bridging in misdn_call to avoid setting echocancellation
  when 2 mISDN channels are involved and when bridging is set. That lead
  to a kernel panic before under different situations, because we switched 
  about 2 times between hardware bridging and echocancelation
* readded MISDN_URATE variable which got lost before, this should make app_v110
  work again
* fixed typo
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@49321 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-01-03 11:15:02 +00:00
										 |  |  | 			empty_bc(bc); | 
					
						
							|  |  |  | 			bc->cause=tmpcause; | 
					
						
							| 
									
										
											  
											
												Merged revisions 58825-58826 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r58825 | crichter | 2007-03-12 13:43:24 +0100 (Mo, 12 Mär 2007) | 1 line
added UU transceiving and corect handling for rdnis
................
r58826 | crichter | 2007-03-12 14:08:06 +0100 (Mo, 12 Mär 2007) | 21 lines
Merged revisions 57034,57523,57753,58558 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r57034 | crichter | 2007-02-28 17:09:27 +0100 (Mi, 28 Feb 2007) | 1 line
fixed bugs.digium.com bugs: #9157 and bugs.beronet.com bugs: #302, #303, #304
........
r57523 | crichter | 2007-03-02 19:32:51 +0100 (Fr, 02 Mar 2007) | 1 line
fixed typo
........
r57753 | crichter | 2007-03-04 11:39:50 +0100 (So, 04 Mar 2007) | 1 line
fixed another place where the out_cause was hardcoded to 16
........
r58558 | crichter | 2007-03-09 15:43:58 +0100 (Fr, 09 Mar 2007) | 1 line
we can free channel 31 as well, since we can occupy it
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@64951 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-05-18 09:31:27 +00:00
										 |  |  | 			bc->out_cause=tmp_out_cause; | 
					
						
							| 
									
										
											  
											
												Merged revisions 49313 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r49313 | crichter | 2007-01-03 10:06:50 +0100 (Mi, 03 Jan 2007) | 41 lines
Merged revisions 48319,48321,48467,48552,48576,49135,49303 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r48319 | crichter | 2006-12-06 15:35:25 +0100 (Mi, 06 Dez 2006) | 1 line
changed a few debugs to higher debug levels
........
r48321 | crichter | 2006-12-06 16:48:45 +0100 (Mi, 06 Dez 2006) | 1 line
added the export and import of the MISDN_ADDRESS_COMPLETE Variable to inidcate wether the extension is already completely dialed or if there might come additional digits by information elements. also added some docs for that.
........
r48467 | crichter | 2006-12-14 14:03:49 +0100 (Do, 14 Dez 2006) | 1 line
removed FIXUP state. added check for channel allocation conflict when we create a setup while the other site creates a setup on the same channel, besides the check we resolve this conflict.
........
r48552 | crichter | 2006-12-18 11:19:39 +0100 (Mo, 18 Dez 2006) | 1 line
when our PTP Partner sends us a SETUP with a preselected channel we just accept it, even when we're NT. added some checks for segfaults.
........
r48576 | crichter | 2006-12-19 14:08:51 +0100 (Di, 19 Dez 2006) | 1 line
when we reject a channel, because it's in use already, we shouldn't process the setup anymore. made the channel allocation a bit easier and more understandable, removed a few unused lines
........
r49135 | crichter | 2007-01-02 11:07:22 +0100 (Di, 02 Jan 2007) | 1 line
added check for channel ranges in the set/empty channel functions. set pmp_l1_check default to no. added misdn restart pid cli command. added cleaning of channel when we send a RELEASE_COMPLETE. 
........
r49303 | crichter | 2007-01-03 09:24:00 +0100 (Mi, 03 Jan 2007) | 9 lines
* Added check for bridging in misdn_call to avoid setting echocancellation
  when 2 mISDN channels are involved and when bridging is set. That lead
  to a kernel panic before under different situations, because we switched 
  about 2 times between hardware bridging and echocancelation
* readded MISDN_URATE variable which got lost before, this should make app_v110
  work again
* fixed typo
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@49321 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-01-03 11:15:02 +00:00
										 |  |  | 			clean_up_bc(bc); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-06-25 09:37:49 +00:00
										 |  |  | 			if (channel>0) | 
					
						
							| 
									
										
										
										
											2007-06-25 09:42:15 +00:00
										 |  |  | 				empty_chan_in_stack(stack,channel); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-06-25 09:46:18 +00:00
										 |  |  | 			bc->in_use=0; | 
					
						
							| 
									
										
											  
											
												Merged revisions 49313 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r49313 | crichter | 2007-01-03 10:06:50 +0100 (Mi, 03 Jan 2007) | 41 lines
Merged revisions 48319,48321,48467,48552,48576,49135,49303 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r48319 | crichter | 2006-12-06 15:35:25 +0100 (Mi, 06 Dez 2006) | 1 line
changed a few debugs to higher debug levels
........
r48321 | crichter | 2006-12-06 16:48:45 +0100 (Mi, 06 Dez 2006) | 1 line
added the export and import of the MISDN_ADDRESS_COMPLETE Variable to inidcate wether the extension is already completely dialed or if there might come additional digits by information elements. also added some docs for that.
........
r48467 | crichter | 2006-12-14 14:03:49 +0100 (Do, 14 Dez 2006) | 1 line
removed FIXUP state. added check for channel allocation conflict when we create a setup while the other site creates a setup on the same channel, besides the check we resolve this conflict.
........
r48552 | crichter | 2006-12-18 11:19:39 +0100 (Mo, 18 Dez 2006) | 1 line
when our PTP Partner sends us a SETUP with a preselected channel we just accept it, even when we're NT. added some checks for segfaults.
........
r48576 | crichter | 2006-12-19 14:08:51 +0100 (Di, 19 Dez 2006) | 1 line
when we reject a channel, because it's in use already, we shouldn't process the setup anymore. made the channel allocation a bit easier and more understandable, removed a few unused lines
........
r49135 | crichter | 2007-01-02 11:07:22 +0100 (Di, 02 Jan 2007) | 1 line
added check for channel ranges in the set/empty channel functions. set pmp_l1_check default to no. added misdn restart pid cli command. added cleaning of channel when we send a RELEASE_COMPLETE. 
........
r49303 | crichter | 2007-01-03 09:24:00 +0100 (Mi, 03 Jan 2007) | 9 lines
* Added check for bridging in misdn_call to avoid setting echocancellation
  when 2 mISDN channels are involved and when bridging is set. That lead
  to a kernel panic before under different situations, because we switched 
  about 2 times between hardware bridging and echocancelation
* readded MISDN_URATE variable which got lost before, this should make app_v110
  work again
* fixed typo
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@49321 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-01-03 11:15:02 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	case EVENT_CONNECT_ACKNOWLEDGE: | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 		if ( bc->nt || misdn_cap_is_speech(bc->capability)) { | 
					
						
							| 
									
										
											  
											
												Merged revisions 62912 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r62912 | crichter | 2007-05-03 16:36:32 +0200 (Do, 03 Mai 2007) | 17 lines
Merged revisions 61357,61770,62885 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r61357 | crichter | 2007-04-11 14:05:57 +0200 (Mi, 11 Apr 2007) | 1 line
some fixes for PMP Hold/Retrieve, it should work now, when briding=no
........
r61770 | crichter | 2007-04-24 15:50:05 +0200 (Di, 24 Apr 2007) | 1 line
added lock for sending messages to avoid double sending. shuffled some empty_chans after the cb_event calls, this avoids that a release_complete from a quite different call releases a fresh created setup by accident.
........
r62885 | crichter | 2007-05-03 15:59:00 +0200 (Do, 03 Mai 2007) | 1 line
fixed the problem that misdn_write did not return -1 when called with 0 samples in a frame this resultet in a deadlock in some circumstances, when the call ended because of a busy extension.  added encoding of keypad.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@64955 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-05-18 09:50:33 +00:00
										 |  |  | 			int retval=setup_bc(bc); | 
					
						
							|  |  |  | 			if (retval == -EINVAL){ | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 				cb_log(0,bc->port,"send_event: setup_bc failed\n"); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		if (misdn_cap_is_speech(bc->capability)) { | 
					
						
							|  |  |  | 			if (  !bc->nodsp) manager_ph_control(bc,  DTMF_TONE_START, 0); | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | 			manager_ec_enable(bc); | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			if ( bc->txgain != 0 ) { | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 				cb_log(4, stack->port, "--> Changing txgain to %d\n", bc->txgain); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 				manager_ph_control(bc, VOL_CHANGE_TX, bc->txgain); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if ( bc->rxgain != 0 ) { | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 				cb_log(4, stack->port, "--> Changing rxgain to %d\n", bc->rxgain); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 				manager_ph_control(bc, VOL_CHANGE_RX, bc->rxgain); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	default: | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	/* Later we should think about sending bchannel data directly to misdn. */ | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	msg = isdn_msg_build_event(msgs_g, bc, event, stack->nt); | 
					
						
							| 
									
										
										
										
											2009-04-03 22:41:46 +00:00
										 |  |  | 	if (!msg) { | 
					
						
							|  |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * The message was not built. | 
					
						
							|  |  |  | 		 * | 
					
						
							|  |  |  | 		 * NOTE:  The only time that the message will fail to build | 
					
						
							|  |  |  | 		 * is because the requested FACILITY message is not supported. | 
					
						
							|  |  |  | 		 * A failed malloc() results in exit() being called. | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		RETURN(-1, OUT); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		msg_queue_tail(&stack->downqueue, msg); | 
					
						
							|  |  |  | 		sem_post(&glob_mgr->new_msg); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Merged revisions 62912 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r62912 | crichter | 2007-05-03 16:36:32 +0200 (Do, 03 Mai 2007) | 17 lines
Merged revisions 61357,61770,62885 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r61357 | crichter | 2007-04-11 14:05:57 +0200 (Mi, 11 Apr 2007) | 1 line
some fixes for PMP Hold/Retrieve, it should work now, when briding=no
........
r61770 | crichter | 2007-04-24 15:50:05 +0200 (Di, 24 Apr 2007) | 1 line
added lock for sending messages to avoid double sending. shuffled some empty_chans after the cb_event calls, this avoids that a release_complete from a quite different call releases a fresh created setup by accident.
........
r62885 | crichter | 2007-05-03 15:59:00 +0200 (Do, 03 Mai 2007) | 1 line
fixed the problem that misdn_write did not return -1 when called with 0 samples in a frame this resultet in a deadlock in some circumstances, when the call ended because of a busy extension.  added encoding of keypad.
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@64955 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-05-18 09:50:33 +00:00
										 |  |  | OUT: | 
					
						
							|  |  |  | 	misdn_send_unlock(bc); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | OUT_POST_UNLOCK: | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 	return retval; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int handle_err(msg_t *msg) | 
					
						
							| 
									
										
										
										
											2006-04-04 19:09:26 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	iframe_t *frm = (iframe_t*) msg->data; | 
					
						
							| 
									
										
										
										
											2006-04-29 22:56:00 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!frm->addr) { | 
					
						
							|  |  |  | 		static int cnt=0; | 
					
						
							|  |  |  | 		if (!cnt) | 
					
						
							|  |  |  | 			cb_log(0,0,"mISDN Msg without Address pr:%x dinfo:%x\n",frm->prim,frm->dinfo); | 
					
						
							|  |  |  | 		cnt++; | 
					
						
							|  |  |  | 		if (cnt>100) { | 
					
						
							|  |  |  | 			cb_log(0,0,"mISDN Msg without Address pr:%x dinfo:%x (already more than 100 of them)\n",frm->prim,frm->dinfo); | 
					
						
							|  |  |  | 			cnt=0; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-29 22:56:00 +00:00
										 |  |  | 		free_msg(msg); | 
					
						
							|  |  |  | 		return 1; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-29 22:56:00 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-04 19:09:26 +00:00
										 |  |  | 	switch (frm->prim) { | 
					
						
							| 
									
										
										
										
											2006-05-23 12:38:06 +00:00
										 |  |  | 		case MGR_SETSTACK|INDICATION: | 
					
						
							|  |  |  | 			return handle_bchan(msg); | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2006-06-01 12:51:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		case MGR_SETSTACK|CONFIRM: | 
					
						
							|  |  |  | 		case MGR_CLEARSTACK|CONFIRM: | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 			free_msg(msg) ; | 
					
						
							| 
									
										
										
										
											2006-06-01 12:51:41 +00:00
										 |  |  | 			return 1; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-26 17:37:11 +00:00
										 |  |  | 		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; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-04 19:09:26 +00:00
										 |  |  | 		case DL_DATA|INDICATION: | 
					
						
							| 
									
										
										
										
											2006-04-05 14:51:48 +00:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			int port=(frm->addr&MASTER_ID_MASK) >> 8; | 
					
						
							|  |  |  | 			int channel=(frm->addr&CHILD_ID_MASK) >> 16; | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 			struct misdn_bchannel *bc; | 
					
						
							| 
									
										
										
										
											2006-04-04 19:09:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-29 22:56:00 +00:00
										 |  |  | 			/*we flush the read buffer here*/ | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-29 22:56:00 +00:00
										 |  |  | 			cb_log(9,0,"BCHAN DATA without BC: addr:%x port:%d channel:%d\n",frm->addr, port,channel); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			free_msg(msg); | 
					
						
							| 
									
										
										
										
											2006-04-29 22:56:00 +00:00
										 |  |  | 			return 1; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 			bc = find_bc_by_channel(port, channel); | 
					
						
							| 
									
										
										
										
											2006-04-04 19:09:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-05 14:51:48 +00:00
										 |  |  | 			if (!bc) { | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 				struct misdn_stack *stack = find_stack_by_port(port); | 
					
						
							| 
									
										
										
										
											2006-04-05 14:51:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				if (!stack) { | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 					cb_log(0,0," --> stack not found\n"); | 
					
						
							| 
									
										
										
										
											2006-04-05 14:51:48 +00:00
										 |  |  | 					free_msg(msg); | 
					
						
							|  |  |  | 					return 1; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 				cb_log(0,0," --> bc not found by channel\n"); | 
					
						
							| 
									
										
										
										
											2006-04-05 14:51:48 +00:00
										 |  |  | 				if (stack->l2link) | 
					
						
							|  |  |  | 					misdn_lib_get_l2_down(stack); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (stack->l1link) | 
					
						
							|  |  |  | 					misdn_lib_get_l1_down(stack); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				free_msg(msg); | 
					
						
							|  |  |  | 				return 1; | 
					
						
							| 
									
										
										
										
											2006-04-04 19:09:26 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-05 14:51:48 +00:00
										 |  |  | 			cb_log(3,port," --> BC in state:%s\n", bc_state2str(bc->bc_state)); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2006-04-04 19:09:26 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | #if 0
 | 
					
						
							|  |  |  | static int queue_l2l3(msg_t *msg) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-04-29 22:56:00 +00:00
										 |  |  | 	iframe_t *frm= (iframe_t*)msg->data; | 
					
						
							|  |  |  | 	struct misdn_stack *stack; | 
					
						
							|  |  |  | 	stack=find_stack_by_addr( frm->addr ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-29 22:56:00 +00:00
										 |  |  | 	if (!stack) { | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	msg_queue_tail(&stack->upqueue, msg); | 
					
						
							|  |  |  | 	sem_post(&glob_mgr->new_msg); | 
					
						
							|  |  |  | 	return 1; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2006-04-29 22:56:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | int manager_isdn_handler(iframe_t *frm ,msg_t *msg) | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-11-15 00:06:37 +00:00
										 |  |  | 	if (frm->dinfo==0xffffffff && frm->prim==(PH_DATA|CONFIRM)) { | 
					
						
							| 
									
										
										
										
											2006-04-29 22:56:00 +00:00
										 |  |  | 		cb_log(0,0,"SERIOUS BUG, dinfo == 0xffffffff, prim == PH_DATA | CONFIRM !!!!\n"); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	if ( ((frm->addr | ISDN_PID_BCHANNEL_BIT )>> 28 ) == 0x5) { | 
					
						
							| 
									
										
										
										
											2008-06-02 08:46:23 +00:00
										 |  |  | 		static int unhandled_bmsg_count=1000; | 
					
						
							| 
									
										
										
										
											2006-06-06 09:40:41 +00:00
										 |  |  | 		if (handle_bchan(msg)) { | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 			return 0 ; | 
					
						
							| 
									
										
										
										
											2006-06-06 09:40:41 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-02 08:46:23 +00:00
										 |  |  | 		if (unhandled_bmsg_count==1000) { | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 			cb_log(0, 0, "received 1k Unhandled Bchannel Messages: prim %x len %d from addr %x, dinfo %x on this port.\n",frm->prim, frm->len, frm->addr, frm->dinfo); | 
					
						
							| 
									
										
										
										
											2008-06-02 08:46:23 +00:00
										 |  |  | 			unhandled_bmsg_count=0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		unhandled_bmsg_count++; | 
					
						
							|  |  |  | 		free_msg(msg); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef RECV_FRM_SYSLOG_DEBUG
 | 
					
						
							|  |  |  | 	syslog(LOG_NOTICE,"mISDN recv: P(%02d): ADDR:%x PRIM:%x DINFO:%x\n",stack->port, frm->addr, frm->prim, frm->dinfo); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 	if (handle_timers(msg)) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		return 0 ; | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (handle_mgmt(msg)) | 
					
						
							|  |  |  | 		return 0 ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (handle_l2(msg)) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		return 0 ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Its important to handle l1 AFTER l2  */ | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 	if (handle_l1(msg)) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		return 0 ; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-06 09:40:41 +00:00
										 |  |  | 	if (handle_frm_nt(msg)) { | 
					
						
							| 
									
										
										
										
											2006-06-01 12:51:41 +00:00
										 |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2006-06-06 09:40:41 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-06 09:40:41 +00:00
										 |  |  | 	if (handle_frm(msg)) { | 
					
						
							| 
									
										
										
										
											2006-04-29 22:56:00 +00:00
										 |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2006-06-06 09:40:41 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-06 09:40:41 +00:00
										 |  |  | 	if (handle_err(msg)) { | 
					
						
							| 
									
										
										
										
											2006-04-04 19:09:26 +00:00
										 |  |  | 		return 0 ; | 
					
						
							| 
									
										
										
										
											2006-06-06 09:40:41 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-04-29 22:56:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 	cb_log(0, 0, "Unhandled Message: prim %x len %d from addr %x, dinfo %x on this port.\n",frm->prim, frm->len, frm->addr, frm->dinfo); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	free_msg(msg); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int misdn_lib_get_port_info(int port) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	msg_t *msg=alloc_msg(MAX_MSG_SIZE); | 
					
						
							|  |  |  | 	iframe_t *frm; | 
					
						
							|  |  |  | 	struct misdn_stack *stack=find_stack_by_port(port); | 
					
						
							|  |  |  | 	if (!msg) { | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 		cb_log(0, port, "misdn_lib_get_port_info: alloc_msg failed!\n"); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	frm=(iframe_t*)msg->data; | 
					
						
							|  |  |  | 	if (!stack ) { | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(0, port, "There is no Stack for this port.\n"); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	/* activate bchannel */ | 
					
						
							|  |  |  | 	frm->prim = CC_STATUS_ENQUIRY | REQUEST; | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	frm->addr = stack->upper_id| FLG_MSG_DOWN; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	frm->dinfo = 0; | 
					
						
							|  |  |  | 	frm->len = 0; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	msg_queue_tail(&glob_mgr->activatequeue, msg); | 
					
						
							|  |  |  | 	sem_post(&glob_mgr->new_msg); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-05-23 12:38:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | int queue_cleanup_bc(struct misdn_bchannel *bc) | 
					
						
							| 
									
										
										
										
											2006-05-23 12:38:06 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	msg_t *msg=alloc_msg(MAX_MSG_SIZE); | 
					
						
							|  |  |  | 	iframe_t *frm; | 
					
						
							|  |  |  | 	if (!msg) { | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 		cb_log(0, bc->port, "queue_cleanup_bc: alloc_msg failed!\n"); | 
					
						
							| 
									
										
										
										
											2006-05-23 12:38:06 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	frm=(iframe_t*)msg->data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* activate bchannel */ | 
					
						
							|  |  |  | 	frm->prim = MGR_CLEARSTACK| REQUEST; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	frm->addr = bc->l3_id; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	frm->dinfo = bc->port; | 
					
						
							|  |  |  | 	frm->len = 0; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-05-23 12:38:06 +00:00
										 |  |  | 	msg_queue_tail(&glob_mgr->activatequeue, msg); | 
					
						
							|  |  |  | 	sem_post(&glob_mgr->new_msg); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2006-05-23 12:38:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | int misdn_lib_pid_restart(int pid) | 
					
						
							| 
									
										
											  
											
												Merged revisions 49313 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
................
r49313 | crichter | 2007-01-03 10:06:50 +0100 (Mi, 03 Jan 2007) | 41 lines
Merged revisions 48319,48321,48467,48552,48576,49135,49303 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r48319 | crichter | 2006-12-06 15:35:25 +0100 (Mi, 06 Dez 2006) | 1 line
changed a few debugs to higher debug levels
........
r48321 | crichter | 2006-12-06 16:48:45 +0100 (Mi, 06 Dez 2006) | 1 line
added the export and import of the MISDN_ADDRESS_COMPLETE Variable to inidcate wether the extension is already completely dialed or if there might come additional digits by information elements. also added some docs for that.
........
r48467 | crichter | 2006-12-14 14:03:49 +0100 (Do, 14 Dez 2006) | 1 line
removed FIXUP state. added check for channel allocation conflict when we create a setup while the other site creates a setup on the same channel, besides the check we resolve this conflict.
........
r48552 | crichter | 2006-12-18 11:19:39 +0100 (Mo, 18 Dez 2006) | 1 line
when our PTP Partner sends us a SETUP with a preselected channel we just accept it, even when we're NT. added some checks for segfaults.
........
r48576 | crichter | 2006-12-19 14:08:51 +0100 (Di, 19 Dez 2006) | 1 line
when we reject a channel, because it's in use already, we shouldn't process the setup anymore. made the channel allocation a bit easier and more understandable, removed a few unused lines
........
r49135 | crichter | 2007-01-02 11:07:22 +0100 (Di, 02 Jan 2007) | 1 line
added check for channel ranges in the set/empty channel functions. set pmp_l1_check default to no. added misdn restart pid cli command. added cleaning of channel when we send a RELEASE_COMPLETE. 
........
r49303 | crichter | 2007-01-03 09:24:00 +0100 (Mi, 03 Jan 2007) | 9 lines
* Added check for bridging in misdn_call to avoid setting echocancellation
  when 2 mISDN channels are involved and when bridging is set. That lead
  to a kernel panic before under different situations, because we switched 
  about 2 times between hardware bridging and echocancelation
* readded MISDN_URATE variable which got lost before, this should make app_v110
  work again
* fixed typo
........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@49321 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-01-03 11:15:02 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct misdn_bchannel *bc=manager_find_bc_by_pid(pid); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (bc) { | 
					
						
							|  |  |  | 		manager_clean_bc(bc); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | /*Sends Restart message for every bchannel*/ | 
					
						
							| 
									
										
										
										
											2007-06-11 11:40:21 +00:00
										 |  |  | int misdn_lib_send_restart(int port, int channel) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct misdn_stack *stack=find_stack_by_port(port); | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 	struct misdn_bchannel dummybc; | 
					
						
							|  |  |  | 	/*default is all channels*/ | 
					
						
							| 
									
										
										
										
											2007-06-11 11:40:21 +00:00
										 |  |  | 	cb_log(0, port, "Sending Restarts on this port.\n"); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-10-22 10:04:04 +00:00
										 |  |  | 	misdn_make_dummy(&dummybc, stack->port, MISDN_ID_GLOBAL, stack->nt, 0); | 
					
						
							| 
									
										
										
										
											2007-06-11 11:40:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-12 13:33:13 +00:00
										 |  |  | 	/*default is all channels*/ | 
					
						
							|  |  |  | 	if (channel <0) { | 
					
						
							|  |  |  | 		dummybc.channel=-1; | 
					
						
							|  |  |  | 		cb_log(0, port, "Restarting and all Interfaces\n"); | 
					
						
							|  |  |  | 		misdn_lib_send_event(&dummybc, EVENT_RESTART); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2007-06-11 11:40:21 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-12 13:33:13 +00:00
										 |  |  | 	/*if a channel is specified we restart only this one*/ | 
					
						
							|  |  |  | 	if (channel >0) { | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 		int cnt; | 
					
						
							| 
									
										
										
										
											2007-11-12 13:33:13 +00:00
										 |  |  | 		dummybc.channel=channel; | 
					
						
							|  |  |  | 		cb_log(0, port, "Restarting and cleaning channel %d\n",channel); | 
					
						
							| 
									
										
										
										
											2007-06-11 11:40:21 +00:00
										 |  |  | 		misdn_lib_send_event(&dummybc, EVENT_RESTART); | 
					
						
							| 
									
										
										
										
											2007-06-25 09:37:49 +00:00
										 |  |  | 		/* clean up chan in stack, to be sure we don't think it's
 | 
					
						
							|  |  |  | 		 * in use anymore */ | 
					
						
							|  |  |  | 		for (cnt=0; cnt<=stack->b_num; cnt++) { | 
					
						
							| 
									
										
										
										
											2009-10-02 01:09:31 +00:00
										 |  |  | 			if (stack->bc[cnt].in_use && stack->bc[cnt].channel == channel) { | 
					
						
							| 
									
										
										
										
											2007-06-25 09:37:49 +00:00
										 |  |  | 				empty_bc(&stack->bc[cnt]); | 
					
						
							|  |  |  | 				clean_up_bc(&stack->bc[cnt]); | 
					
						
							| 
									
										
										
										
											2007-06-25 09:46:18 +00:00
										 |  |  | 				stack->bc[cnt].in_use=0; | 
					
						
							| 
									
										
										
										
											2007-06-25 09:37:49 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2007-06-11 11:40:21 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*reinitializes the L2/L3*/ | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | int misdn_lib_port_restart(int port) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct misdn_stack *stack=find_stack_by_port(port); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	cb_log(0, port, "Restarting this port.\n"); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	if (stack) { | 
					
						
							|  |  |  | 		cb_log(0, port, "Stack:%p\n",stack); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		clear_l3(stack); | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			msg_t *msg=alloc_msg(MAX_MSG_SIZE); | 
					
						
							|  |  |  | 			iframe_t *frm; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (!msg) { | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 				cb_log(0, port, "port_restart: alloc_msg failed\n"); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 				return -1; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			frm=(iframe_t*)msg->data; | 
					
						
							|  |  |  | 			/* we must activate if we are deactivated */ | 
					
						
							|  |  |  | 			/* activate bchannel */ | 
					
						
							|  |  |  | 			frm->prim = DL_RELEASE | REQUEST; | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 			frm->addr = stack->upper_id | FLG_MSG_DOWN; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			frm->dinfo = 0; | 
					
						
							|  |  |  | 			frm->len = 0; | 
					
						
							|  |  |  | 			msg_queue_tail(&glob_mgr->activatequeue, msg); | 
					
						
							|  |  |  | 			sem_post(&glob_mgr->new_msg); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-30 14:05:42 +00:00
										 |  |  | 		if (stack->nt) | 
					
						
							|  |  |  | 			misdn_lib_reinit_nt_stack(stack->port); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | static sem_t handler_started; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | /* This is a thread */ | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static void manager_event_handler(void *arg) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 	sem_post(&handler_started); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	while (1) { | 
					
						
							|  |  |  | 		struct misdn_stack *stack; | 
					
						
							|  |  |  | 		msg_t *msg; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		/** wait for events **/ | 
					
						
							|  |  |  | 		sem_wait(&glob_mgr->new_msg); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		for (msg=msg_dequeue(&glob_mgr->activatequeue); | 
					
						
							|  |  |  | 		     msg; | 
					
						
							|  |  |  | 		     msg=msg_dequeue(&glob_mgr->activatequeue) | 
					
						
							|  |  |  | 			) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			iframe_t *frm =  (iframe_t*) msg->data ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			switch ( frm->prim) { | 
					
						
							| 
									
										
										
										
											2006-05-23 12:38:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			case MGR_CLEARSTACK | REQUEST: | 
					
						
							|  |  |  | 				/*a queued bchannel cleanup*/ | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					struct misdn_stack *stack=find_stack_by_port(frm->dinfo); | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 					struct misdn_bchannel *bc; | 
					
						
							| 
									
										
										
										
											2006-05-23 12:38:06 +00:00
										 |  |  | 					if (!stack) { | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 						cb_log(0,0,"no stack found with port [%d]!! so we cannot cleanup the bc\n",frm->dinfo); | 
					
						
							| 
									
										
										
										
											2006-05-23 12:38:06 +00:00
										 |  |  | 						free_msg(msg); | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 					bc = find_bc_by_l3id(stack, frm->addr); | 
					
						
							| 
									
										
										
										
											2006-05-23 12:38:06 +00:00
										 |  |  | 					if (bc) { | 
					
						
							|  |  |  | 						cb_log(1,bc->port,"CLEARSTACK queued, cleaning up\n"); | 
					
						
							|  |  |  | 						clean_up_bc(bc); | 
					
						
							|  |  |  | 					} else { | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 						cb_log(0,stack->port,"bc could not be cleaned correctly !! addr [%x]\n",frm->addr); | 
					
						
							| 
									
										
										
										
											2006-05-23 12:38:06 +00:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 				free_msg(msg); | 
					
						
							| 
									
										
										
										
											2006-05-23 12:38:06 +00:00
										 |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			case MGR_SETSTACK | REQUEST : | 
					
						
							| 
									
										
										
										
											2009-07-14 00:48:59 +00:00
										 |  |  | 				free_msg(msg); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			default: | 
					
						
							|  |  |  | 				mISDN_write(glob_mgr->midev, frm, mISDN_HEADER_LEN+frm->len, TIMEOUT_1SEC); | 
					
						
							|  |  |  | 				free_msg(msg); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (stack=glob_mgr->stack_list; | 
					
						
							|  |  |  | 		     stack; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 		     stack=stack->next ) { | 
					
						
							| 
									
										
										
										
											2006-04-29 22:56:00 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			while ( (msg=msg_dequeue(&stack->upqueue)) ) { | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 				/** Handle L2/3 Signalling after bchans **/ | 
					
						
							| 
									
										
										
										
											2006-04-29 22:56:00 +00:00
										 |  |  | 				if (!handle_frm_nt(msg)) { | 
					
						
							|  |  |  | 					/* Maybe it's TE */ | 
					
						
							|  |  |  | 					if (!handle_frm(msg)) { | 
					
						
							|  |  |  | 						/* wow none! */ | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 						cb_log(0,stack->port,"Wow we've got a strange issue while dequeueing a Frame\n"); | 
					
						
							| 
									
										
										
										
											2006-04-29 22:56:00 +00:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 			/* Here we should check if we really want to
 | 
					
						
							|  |  |  | 				send all the messages we've queued, lets | 
					
						
							|  |  |  | 				assume we've queued a Disconnect, but | 
					
						
							| 
									
										
										
										
											2006-04-29 22:56:00 +00:00
										 |  |  | 				received it already from the other side!*/ | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			while ( (msg=msg_dequeue(&stack->downqueue)) ) { | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 				if (stack->nt ) { | 
					
						
							| 
									
										
										
										
											2009-07-15 21:14:41 +00:00
										 |  |  | 					pthread_mutex_lock(&stack->nstlock); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 					if (stack->nst.manager_l3(&stack->nst, msg)) | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 						cb_log(0, stack->port, "Error@ Sending Message in NT-Stack.\n"); | 
					
						
							| 
									
										
										
										
											2009-07-15 21:14:41 +00:00
										 |  |  | 					pthread_mutex_unlock(&stack->nstlock); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 					iframe_t *frm = (iframe_t *)msg->data; | 
					
						
							|  |  |  | 					struct misdn_bchannel *bc = find_bc_by_l3id(stack, frm->dinfo); | 
					
						
							| 
									
										
										
										
											2008-09-30 21:00:54 +00:00
										 |  |  | 					if (bc) | 
					
						
							| 
									
										
										
										
											2007-06-11 11:40:21 +00:00
										 |  |  | 						send_msg(glob_mgr->midev, bc, msg); | 
					
						
							|  |  |  | 					else  { | 
					
						
							| 
									
										
										
										
											2007-10-22 10:04:04 +00:00
										 |  |  | 						if (frm->dinfo == MISDN_ID_GLOBAL || frm->dinfo == MISDN_ID_DUMMY ) { | 
					
						
							| 
									
										
										
										
											2007-06-11 11:40:21 +00:00
										 |  |  | 							struct misdn_bchannel dummybc; | 
					
						
							| 
									
										
										
										
											2007-10-22 10:04:04 +00:00
										 |  |  | 							cb_log(5,0," --> GLOBAL/DUMMY\n"); | 
					
						
							|  |  |  | 							misdn_make_dummy(&dummybc, stack->port, frm->dinfo, stack->nt, 0); | 
					
						
							| 
									
										
										
										
											2007-06-11 11:40:21 +00:00
										 |  |  | 							send_msg(glob_mgr->midev, &dummybc, msg); | 
					
						
							| 
									
										
										
										
											2007-10-22 10:04:04 +00:00
										 |  |  | 						} else { | 
					
						
							|  |  |  | 							cb_log(0,0,"No bc for Message\n"); | 
					
						
							| 
									
										
										
										
											2007-06-11 11:40:21 +00:00
										 |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | int misdn_lib_maxports_get(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* BE AWARE WE HAVE NO cb_log() HERE! */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	int i = mISDN_open(); | 
					
						
							|  |  |  | 	int max=0; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	if (i<0) | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	max = mISDN_get_stack_count(i); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	mISDN_close(i); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	return max; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-29 20:12:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-12 12:49:19 +00:00
										 |  |  | void misdn_lib_nt_keepcalls( int kc) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | #ifdef FEATURE_NET_KEEPCALLS
 | 
					
						
							|  |  |  | 	if (kc) { | 
					
						
							|  |  |  | 		struct misdn_stack *stack=get_misdn_stack(); | 
					
						
							|  |  |  | 		for ( ; stack; stack=stack->next) { | 
					
						
							|  |  |  | 			stack->nst.feature |= FEATURE_NET_KEEPCALLS; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | void misdn_lib_nt_debug_init( int flags, char *file ) | 
					
						
							| 
									
										
										
										
											2006-06-29 20:12:19 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2008-07-14 15:44:07 +00:00
										 |  |  | 	static int init=0; | 
					
						
							| 
									
										
										
										
											2006-06-30 14:05:42 +00:00
										 |  |  | 	char *f; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!flags) | 
					
						
							| 
									
										
										
										
											2006-06-30 14:05:42 +00:00
										 |  |  | 		f=NULL; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		f=file; | 
					
						
							| 
									
										
										
										
											2006-06-29 20:12:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!init) { | 
					
						
							| 
									
										
										
										
											2006-06-30 14:05:42 +00:00
										 |  |  | 		debug_init( flags , f, f, f); | 
					
						
							| 
									
										
										
										
											2006-06-29 20:12:19 +00:00
										 |  |  | 		init=1; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		debug_close(); | 
					
						
							| 
									
										
										
										
											2006-06-30 14:05:42 +00:00
										 |  |  | 		debug_init( flags , f, f, f); | 
					
						
							| 
									
										
										
										
											2006-06-29 20:12:19 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | int misdn_lib_init(char *portlist, struct misdn_lib_iface *iface, void *user_data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct misdn_lib *mgr=calloc(1, sizeof(struct misdn_lib)); | 
					
						
							|  |  |  | 	char *tok, *tokb; | 
					
						
							|  |  |  | 	char plist[1024]; | 
					
						
							|  |  |  | 	int midev; | 
					
						
							|  |  |  | 	int port_count=0; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	cb_log = iface->cb_log; | 
					
						
							|  |  |  | 	cb_event = iface->cb_event; | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	cb_jb_empty = iface->cb_jb_empty; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	glob_mgr = mgr; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	msg_init(); | 
					
						
							| 
									
										
										
										
											2006-06-29 20:12:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	misdn_lib_nt_debug_init(0,NULL); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	if (!portlist || (*portlist == 0) ) return 1; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	init_flip_bits(); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		strncpy(plist,portlist, 1024); | 
					
						
							|  |  |  | 		plist[1023] = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	memcpy(tone_425_flip,tone_425,TONE_425_SIZE); | 
					
						
							|  |  |  | 	flip_buf_bits(tone_425_flip,TONE_425_SIZE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	memcpy(tone_silence_flip,tone_SILENCE,TONE_SILENCE_SIZE); | 
					
						
							|  |  |  | 	flip_buf_bits(tone_silence_flip,TONE_SILENCE_SIZE); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	midev=te_lib_init(); | 
					
						
							|  |  |  | 	mgr->midev=midev; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	port_count=mISDN_get_stack_count(midev); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	msg_queue_init(&mgr->activatequeue); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	if (sem_init(&mgr->new_msg, 1, 0)<0) | 
					
						
							|  |  |  | 		sem_init(&mgr->new_msg, 0, 0); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	for (tok=strtok_r(plist," ,",&tokb ); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 	     tok; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	     tok=strtok_r(NULL," ,",&tokb)) { | 
					
						
							|  |  |  | 		int port = atoi(tok); | 
					
						
							|  |  |  | 		struct misdn_stack *stack; | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		struct misdn_stack *help; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		int ptp=0; | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		int i; | 
					
						
							|  |  |  | 		int r; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		if (strstr(tok, "ptp")) | 
					
						
							|  |  |  | 			ptp=1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (port > port_count) { | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 			cb_log(0, port, "Couldn't Initialize this port since we have only %d ports\n", port_count); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			exit(1); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 		stack = stack_init(midev, port, ptp); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		if (!stack) { | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | 			perror("stack_init"); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			exit(1); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		/* Initialize the B channel records for real B channels. */ | 
					
						
							|  |  |  | 		for (i = 0; i <= stack->b_num; i++) { | 
					
						
							|  |  |  | 			r = init_bc(stack, &stack->bc[i], stack->midev, port, i); | 
					
						
							|  |  |  | 			if (r < 0) { | 
					
						
							|  |  |  | 				cb_log(0, port, "Got Err @ init_bc :%d\n", r); | 
					
						
							|  |  |  | 				exit(1); | 
					
						
							| 
									
										
										
										
											2006-07-11 19:30:35 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | #if defined(AST_MISDN_ENHANCEMENTS)
 | 
					
						
							|  |  |  | 		/* Initialize the B channel records for REGISTER signaling links. */ | 
					
						
							|  |  |  | 		for (i = MAX_BCHANS + 1; i < ARRAY_LEN(stack->bc); ++i) { | 
					
						
							|  |  |  | 			r = init_bc(stack, &stack->bc[i], stack->midev, port, i); | 
					
						
							|  |  |  | 			if (r < 0) { | 
					
						
							|  |  |  | 				cb_log(0, port, "Got Err @ init_bc :%d\n", r); | 
					
						
							|  |  |  | 				exit(1); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			stack->bc[i].is_register_pool = 1; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | #endif	/* defined(AST_MISDN_ENHANCEMENTS) */
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 		/* Add the new stack to the end of the list */ | 
					
						
							|  |  |  | 		help = mgr->stack_list; | 
					
						
							|  |  |  | 		if (!help) { | 
					
						
							|  |  |  | 			mgr->stack_list = stack; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			while (help->next) { | 
					
						
							|  |  |  | 				help = help->next; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | 			help->next = stack; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	if (sem_init(&handler_started, 1, 0)<0) | 
					
						
							|  |  |  | 		sem_init(&handler_started, 0, 0); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 	cb_log(8, 0, "Starting Event Handler\n"); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	pthread_create( &mgr->event_handler_thread, NULL,(void*)manager_event_handler, mgr); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	sem_wait(&handler_started) ; | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 	cb_log(8, 0, "Starting Event Catcher\n"); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	pthread_create( &mgr->event_thread, NULL, (void*)misdn_lib_isdn_event_catcher, mgr); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 	cb_log(8, 0, "Event Catcher started\n"); | 
					
						
							| 
									
										
										
										
											2006-05-23 19:40:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 	global_state= MISDN_INITIALIZED; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	return (mgr == NULL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-18 21:07:28 +00:00
										 |  |  | void misdn_lib_destroy(void) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct misdn_stack *help; | 
					
						
							|  |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	for ( help=glob_mgr->stack_list; help; help=help->next ) { | 
					
						
							| 
									
										
										
										
											2006-10-11 08:34:03 +00:00
										 |  |  | 		for(i=0;i<=help->b_num; i++) { | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 			char buf[1024]; | 
					
						
							|  |  |  | 			mISDN_write_frame(help->midev, buf, help->bc[i].addr, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC); | 
					
						
							|  |  |  | 			help->bc[i].addr = 0; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		cb_log (1, help->port, "Destroying this port.\n"); | 
					
						
							| 
									
										
										
										
											2006-06-30 14:05:42 +00:00
										 |  |  | 		stack_destroy(help); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	if (global_state == MISDN_INITIALIZED) { | 
					
						
							|  |  |  | 		cb_log(4, 0, "Killing Handler Thread\n"); | 
					
						
							|  |  |  | 		if ( pthread_cancel(glob_mgr->event_handler_thread) == 0 ) { | 
					
						
							|  |  |  | 			cb_log(4, 0, "Joining Handler Thread\n"); | 
					
						
							|  |  |  | 			pthread_join(glob_mgr->event_handler_thread, NULL); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		cb_log(4, 0, "Killing Main Thread\n"); | 
					
						
							|  |  |  | 		if ( pthread_cancel(glob_mgr->event_thread) == 0 ) { | 
					
						
							|  |  |  | 			cb_log(4, 0, "Joining Main Thread\n"); | 
					
						
							|  |  |  | 			pthread_join(glob_mgr->event_thread, NULL); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	cb_log(1, 0, "Closing mISDN device\n"); | 
					
						
							|  |  |  | 	te_lib_destroy(glob_mgr->midev); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | char *manager_isdn_get_info(enum event_e event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return isdn_get_info(msgs_g , event, 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void manager_bchannel_activate(struct misdn_bchannel *bc) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 	char buf[128]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	struct misdn_stack *stack=get_stack_by_bc(bc); | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!stack) { | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		cb_log(0, bc->port, "bchannel_activate: Stack not found !"); | 
					
						
							| 
									
										
										
										
											2006-04-04 19:09:26 +00:00
										 |  |  | 		return ; | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	/* we must activate if we are deactivated */ | 
					
						
							|  |  |  | 	clear_ibuffer(bc->astbuf); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	cb_log(5, stack->port, "$$$ Bchan Activated addr %x\n", bc->addr); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 	mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_DOWN,  DL_ESTABLISH | REQUEST, 0,0, NULL, TIMEOUT_1SEC); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	return ; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void manager_bchannel_deactivate(struct misdn_bchannel * bc) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	struct misdn_stack *stack=get_stack_by_bc(bc); | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 	iframe_t dact; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 	char buf[128]; | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	switch (bc->bc_state) { | 
					
						
							|  |  |  | 		case BCHAN_ACTIVATED: | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case BCHAN_BRIDGED: | 
					
						
							|  |  |  | 			misdn_split_conf(bc,bc->conf_id); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			cb_log( 4, bc->port,"bchan_deactivate: called but not activated\n"); | 
					
						
							|  |  |  | 			return ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	cb_log(5, stack->port, "$$$ Bchan deActivated addr %x\n", bc->addr); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	bc->generate_tone=0; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	dact.prim = DL_RELEASE | REQUEST; | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	dact.addr = bc->addr | FLG_MSG_DOWN; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	dact.dinfo = 0; | 
					
						
							|  |  |  | 	dact.len = 0; | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 	mISDN_write_frame(stack->midev, buf, bc->addr | FLG_MSG_DOWN, DL_RELEASE|REQUEST,0,0,NULL, TIMEOUT_1SEC); | 
					
						
							| 
									
										
										
										
											2006-05-23 12:38:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	clear_ibuffer(bc->astbuf); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 	bc_state_change(bc,BCHAN_RELEASE); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	return; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | int misdn_lib_tx2misdn_frm(struct misdn_bchannel *bc, void *data, int len) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	struct misdn_stack *stack=get_stack_by_bc(bc); | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 	char buf[4096 + mISDN_HEADER_LEN]; | 
					
						
							|  |  |  | 	iframe_t *frm = (iframe_t*)buf; | 
					
						
							|  |  |  | 	int r; | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	switch (bc->bc_state) { | 
					
						
							|  |  |  | 		case BCHAN_ACTIVATED: | 
					
						
							|  |  |  | 		case BCHAN_BRIDGED: | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			cb_log(3, bc->port, "BC not yet activated (state:%s)\n",bc_state2str(bc->bc_state)); | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	frm->prim = DL_DATA|REQUEST; | 
					
						
							|  |  |  | 	frm->dinfo = 0; | 
					
						
							|  |  |  | 	frm->addr = bc->addr | FLG_MSG_DOWN ; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	frm->len = len; | 
					
						
							|  |  |  | 	memcpy(&buf[mISDN_HEADER_LEN], data,len); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if ( misdn_cap_is_speech(bc->capability) ) | 
					
						
							| 
									
										
										
										
											2006-05-16 14:34:21 +00:00
										 |  |  | 		flip_buf_bits( &buf[mISDN_HEADER_LEN], len); | 
					
						
							|  |  |  | 	else | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		cb_log(6, stack->port, "Writing %d data bytes\n",len); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	cb_log(9, stack->port, "Writing %d bytes 2 mISDN\n",len); | 
					
						
							|  |  |  | 	r=mISDN_write(stack->midev, buf, frm->len + mISDN_HEADER_LEN, TIMEOUT_INFINIT); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * send control information to the channel (dsp-module) | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2006-06-01 16:25:04 +00:00
										 |  |  | void manager_ph_control(struct misdn_bchannel *bc, int c1, int c2) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-06-01 16:25:04 +00:00
										 |  |  | 	unsigned char buffer[mISDN_HEADER_LEN+2*sizeof(int)]; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	iframe_t *ctrl = (iframe_t *)buffer; /* preload data */ | 
					
						
							| 
									
										
										
										
											2006-06-01 16:25:04 +00:00
										 |  |  | 	unsigned int *d = (unsigned int*)&ctrl->data.p; | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 	/*struct misdn_stack *stack=get_stack_by_bc(bc);*/ | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-18 19:09:32 +00:00
										 |  |  | 	cb_log(4,bc->port,"ph_control: c1:%x c2:%x\n",c1,c2); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	ctrl->prim = PH_CONTROL | REQUEST; | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	ctrl->addr = bc->addr | FLG_MSG_DOWN; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	ctrl->dinfo = 0; | 
					
						
							| 
									
										
										
										
											2006-06-01 16:25:04 +00:00
										 |  |  | 	ctrl->len = sizeof(unsigned int)*2; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	*d++ = c1; | 
					
						
							|  |  |  | 	*d++ = c2; | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 	mISDN_write(glob_mgr->midev, ctrl, mISDN_HEADER_LEN+ctrl->len, TIMEOUT_1SEC); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-08 18:13:40 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * allow live control of channel parameters | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | void isdn_lib_update_rxgain (struct misdn_bchannel *bc) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	manager_ph_control(bc, VOL_CHANGE_RX, bc->rxgain); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void isdn_lib_update_txgain (struct misdn_bchannel *bc) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	manager_ph_control(bc, VOL_CHANGE_TX, bc->txgain); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void isdn_lib_update_ec (struct misdn_bchannel *bc) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2007-03-26 15:59:56 +00:00
										 |  |  | #ifdef MISDN_1_2
 | 
					
						
							|  |  |  | 	if (*bc->pipeline) | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2006-08-08 18:13:40 +00:00
										 |  |  | 	if (bc->ec_enable) | 
					
						
							| 
									
										
										
										
											2007-03-26 15:59:56 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2006-08-08 18:13:40 +00:00
										 |  |  | 		manager_ec_enable(bc); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		manager_ec_disable(bc); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void isdn_lib_stop_dtmf (struct misdn_bchannel *bc) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	manager_ph_control(bc, DTMF_TONE_STOP, 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * send control information to the channel (dsp-module) | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2006-06-01 16:25:04 +00:00
										 |  |  | void manager_ph_control_block(struct misdn_bchannel *bc, int c1, void *c2, int c2_len) | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-06-01 16:25:04 +00:00
										 |  |  | 	unsigned char buffer[mISDN_HEADER_LEN+sizeof(int)+c2_len]; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	iframe_t *ctrl = (iframe_t *)buffer; | 
					
						
							| 
									
										
										
										
											2006-06-01 16:25:04 +00:00
										 |  |  | 	unsigned int *d = (unsigned int *)&ctrl->data.p; | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 	/*struct misdn_stack *stack=get_stack_by_bc(bc);*/ | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	ctrl->prim = PH_CONTROL | REQUEST; | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 	ctrl->addr = bc->addr | FLG_MSG_DOWN; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	ctrl->dinfo = 0; | 
					
						
							| 
									
										
										
										
											2006-06-01 16:25:04 +00:00
										 |  |  | 	ctrl->len = sizeof(unsigned int) + c2_len; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	*d++ = c1; | 
					
						
							|  |  |  | 	memcpy(d, c2, c2_len); | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 	mISDN_write(glob_mgr->midev, ctrl, mISDN_HEADER_LEN+ctrl->len, TIMEOUT_1SEC); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void manager_clean_bc(struct misdn_bchannel *bc ) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	struct misdn_stack *stack=get_stack_by_bc(bc); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	if (stack && bc->channel > 0) { | 
					
						
							| 
									
										
										
										
											2006-07-06 15:11:40 +00:00
										 |  |  | 		empty_chan_in_stack(stack, bc->channel); | 
					
						
							| 
									
										
										
										
											2009-04-21 17:44:01 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	empty_bc(bc); | 
					
						
							| 
									
										
										
										
											2007-06-25 09:46:18 +00:00
										 |  |  |  	bc->in_use=0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 	cb_event(EVENT_CLEANUP, bc, NULL); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void stack_holder_add(struct misdn_stack *stack, struct misdn_bchannel *holder) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct misdn_bchannel *help; | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	cb_log(4,stack->port, "*HOLDER: add %x\n",holder->l3_id); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	holder->stack_holder=1; | 
					
						
							|  |  |  | 	holder->next=NULL; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	if (!stack->holding) { | 
					
						
							|  |  |  | 		stack->holding = holder; | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	for (help=stack->holding; | 
					
						
							|  |  |  | 	     help; | 
					
						
							|  |  |  | 	     help=help->next) { | 
					
						
							|  |  |  | 		if (!help->next) { | 
					
						
							|  |  |  | 			help->next=holder; | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void stack_holder_remove(struct misdn_stack *stack, struct misdn_bchannel *holder) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct misdn_bchannel *h1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!holder->stack_holder) return; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | 	holder->stack_holder=0; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	cb_log(4,stack->port, "*HOLDER: remove %x\n",holder->l3_id); | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	if (!stack || ! stack->holding) return; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	if (holder == stack->holding) { | 
					
						
							|  |  |  | 		stack->holding = stack->holding->next; | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	for (h1=stack->holding; | 
					
						
							|  |  |  | 	     h1; | 
					
						
							|  |  |  | 	     h1=h1->next) { | 
					
						
							|  |  |  | 		if (h1->next == holder) { | 
					
						
							|  |  |  | 			h1->next=h1->next->next; | 
					
						
							|  |  |  | 			return ; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct misdn_bchannel *stack_holder_find(struct misdn_stack *stack, unsigned long l3id) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct misdn_bchannel *help; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-03-18 16:23:05 +00:00
										 |  |  | 	cb_log(4,stack?stack->port:0, "*HOLDER: find %lx\n",l3id); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	if (!stack) return NULL; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	for (help=stack->holding; | 
					
						
							|  |  |  | 	     help; | 
					
						
							|  |  |  | 	     help=help->next) { | 
					
						
							|  |  |  | 		if (help->l3_id == l3id) { | 
					
						
							|  |  |  | 			cb_log(4,stack->port, "*HOLDER: found bc\n"); | 
					
						
							|  |  |  | 			return help; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	cb_log(4,stack->port, "*HOLDER: find nothing\n"); | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-14 17:01:48 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \brief Find a held call's B channel record. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \param port Port the call is on. | 
					
						
							|  |  |  |  * \param l3_id mISDN Layer 3 ID of held call. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \return Found bc-record or NULL. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | struct misdn_bchannel *misdn_lib_find_held_bc(int port, int l3_id) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct misdn_bchannel *bc; | 
					
						
							|  |  |  | 	struct misdn_stack *stack; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bc = NULL; | 
					
						
							|  |  |  | 	for (stack = get_misdn_stack(); stack; stack = stack->next) { | 
					
						
							|  |  |  | 		if (stack->port == port) { | 
					
						
							|  |  |  | 			bc = stack_holder_find(stack, l3_id); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-14 17:01:48 +00:00
										 |  |  | 	return bc; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | void misdn_lib_send_tone(struct misdn_bchannel *bc, enum tone_e tone) | 
					
						
							| 
									
										
										
										
											2006-06-18 19:09:32 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 	char buf[mISDN_HEADER_LEN + 128] = ""; | 
					
						
							|  |  |  | 	iframe_t *frm = (iframe_t*)buf; | 
					
						
							| 
									
										
										
										
											2006-06-26 17:37:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-18 19:09:32 +00:00
										 |  |  | 	switch(tone) { | 
					
						
							|  |  |  | 	case TONE_DIAL: | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 		manager_ph_control(bc, TONE_PATT_ON, TONE_GERMAN_DIALTONE); | 
					
						
							| 
									
										
										
										
											2006-06-18 19:09:32 +00:00
										 |  |  | 	break; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-18 19:09:32 +00:00
										 |  |  | 	case TONE_ALERTING: | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 		manager_ph_control(bc, TONE_PATT_ON, TONE_GERMAN_RINGING); | 
					
						
							| 
									
										
										
										
											2006-06-18 19:09:32 +00:00
										 |  |  | 	break; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-18 19:09:32 +00:00
										 |  |  | 	case TONE_HANGUP: | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 		manager_ph_control(bc, TONE_PATT_ON, TONE_GERMAN_HANGUP); | 
					
						
							| 
									
										
										
										
											2006-06-18 19:09:32 +00:00
										 |  |  | 	break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case TONE_NONE: | 
					
						
							|  |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 		manager_ph_control(bc, TONE_PATT_OFF, TONE_GERMAN_HANGUP); | 
					
						
							| 
									
										
										
										
											2006-06-18 19:09:32 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 	frm->prim=DL_DATA|REQUEST; | 
					
						
							|  |  |  | 	frm->addr=bc->addr|FLG_MSG_DOWN; | 
					
						
							|  |  |  | 	frm->dinfo=0; | 
					
						
							|  |  |  | 	frm->len=128; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-21 15:21:46 +00:00
										 |  |  | 	mISDN_write(glob_mgr->midev, frm, mISDN_HEADER_LEN+frm->len, TIMEOUT_1SEC); | 
					
						
							| 
									
										
										
										
											2006-06-18 19:09:32 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | void manager_ec_enable(struct misdn_bchannel *bc) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	struct misdn_stack *stack=get_stack_by_bc(bc); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-01-03 11:03:57 +00:00
										 |  |  | 	cb_log(4, stack?stack->port:0,"ec_enable\n"); | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!misdn_cap_is_speech(bc->capability)) { | 
					
						
							|  |  |  | 		cb_log(1, stack?stack->port:0, " --> no speech? cannot enable EC\n"); | 
					
						
							| 
									
										
										
										
											2007-03-26 15:59:56 +00:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef MISDN_1_2
 | 
					
						
							|  |  |  | 	if (*bc->pipeline) { | 
					
						
							|  |  |  | 		cb_log(3, stack?stack->port:0,"Sending Control PIPELINE_CFG %s\n",bc->pipeline); | 
					
						
							|  |  |  | 		manager_ph_control_block(bc, PIPELINE_CFG, bc->pipeline, strlen(bc->pipeline) + 1); | 
					
						
							|  |  |  |  	} | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 	int ec_arr[2]; | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | 	if (bc->ec_enable) { | 
					
						
							| 
									
										
										
										
											2007-03-26 15:59:56 +00:00
										 |  |  | 		cb_log(3, stack?stack->port:0,"Sending Control ECHOCAN_ON taps:%d\n",bc->ec_deftaps); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | 		switch (bc->ec_deftaps) { | 
					
						
							|  |  |  | 		case 4: | 
					
						
							|  |  |  | 		case 8: | 
					
						
							|  |  |  | 		case 16: | 
					
						
							|  |  |  | 		case 32: | 
					
						
							|  |  |  | 		case 64: | 
					
						
							|  |  |  | 		case 128: | 
					
						
							|  |  |  | 		case 256: | 
					
						
							|  |  |  | 		case 512: | 
					
						
							|  |  |  | 		case 1024: | 
					
						
							|  |  |  | 			cb_log(4, stack->port, "Taps is %d\n",bc->ec_deftaps); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			cb_log(0, stack->port, "Taps should be power of 2\n"); | 
					
						
							|  |  |  | 			bc->ec_deftaps=128; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | 		ec_arr[0]=bc->ec_deftaps; | 
					
						
							|  |  |  | 		ec_arr[1]=0; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | 		manager_ph_control_block(bc,  ECHOCAN_ON,  ec_arr, sizeof(ec_arr)); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-03-26 15:59:56 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | void manager_ec_disable(struct misdn_bchannel *bc) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 	struct misdn_stack *stack=get_stack_by_bc(bc); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-01-03 11:03:57 +00:00
										 |  |  | 	cb_log(4, stack?stack->port:0," --> ec_disable\n"); | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!misdn_cap_is_speech(bc->capability)) { | 
					
						
							|  |  |  | 		cb_log(1, stack?stack->port:0, " --> no speech? cannot disable EC\n"); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-03-26 15:59:56 +00:00
										 |  |  | #ifdef MISDN_1_2
 | 
					
						
							|  |  |  | 	manager_ph_control_block(bc, PIPELINE_CFG, "", 0); | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2006-10-13 15:42:09 +00:00
										 |  |  | 	if ( ! bc->ec_enable) { | 
					
						
							| 
									
										
										
										
											2007-01-03 11:03:57 +00:00
										 |  |  | 		cb_log(3, stack?stack->port:0, "Sending Control ECHOCAN_OFF\n"); | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | 		manager_ph_control(bc,  ECHOCAN_OFF, 0); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-03-26 15:59:56 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-10 14:53:59 +00:00
										 |  |  | struct misdn_stack *get_misdn_stack(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-10-31 23:30:09 +00:00
										 |  |  | 	return glob_mgr->stack_list; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | void misdn_join_conf(struct misdn_bchannel *bc, int conf_id) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 	char data[16] = ""; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 	bc_state_change(bc,BCHAN_BRIDGED); | 
					
						
							|  |  |  | 	manager_ph_control(bc, CMX_RECEIVE_OFF, 0); | 
					
						
							|  |  |  | 	manager_ph_control(bc, CMX_CONF_JOIN, conf_id); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-01-03 11:03:57 +00:00
										 |  |  | 	cb_log(3,bc->port, "Joining bc:%x in conf:%d\n",bc->addr,conf_id); | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 	misdn_lib_tx2misdn_frm(bc, data, sizeof(data) - 1); | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | void misdn_split_conf(struct misdn_bchannel *bc, int conf_id) | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 	bc_state_change(bc,BCHAN_ACTIVATED); | 
					
						
							|  |  |  | 	manager_ph_control(bc, CMX_RECEIVE_ON, 0); | 
					
						
							|  |  |  | 	manager_ph_control(bc, CMX_CONF_SPLIT, conf_id); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-01-03 11:03:57 +00:00
										 |  |  | 	cb_log(4,bc->port, "Splitting bc:%x in conf:%d\n",bc->addr,conf_id); | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-30 21:00:54 +00:00
										 |  |  | void misdn_lib_bridge( struct misdn_bchannel * bc1, struct misdn_bchannel *bc2) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 	int conf_id = bc1->pid + 1; | 
					
						
							|  |  |  | 	struct misdn_bchannel *bc_list[] = { bc1, bc2, NULL }; | 
					
						
							|  |  |  | 	struct misdn_bchannel **bc; | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-01-03 11:03:57 +00:00
										 |  |  | 	cb_log(4, bc1->port, "I Send: BRIDGE from:%d to:%d\n",bc1->port,bc2->port); | 
					
						
							| 
									
										
										
										
											2007-07-19 04:45:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 	for (bc=bc_list; *bc;  bc++) { | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 		(*bc)->conf_id=conf_id; | 
					
						
							| 
									
										
										
										
											2007-01-03 11:03:57 +00:00
										 |  |  | 		cb_log(4, (*bc)->port, " --> bc_addr:%x\n",(*bc)->addr); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 		switch((*bc)->bc_state) { | 
					
						
							|  |  |  | 			case BCHAN_ACTIVATED: | 
					
						
							|  |  |  | 				misdn_join_conf(*bc,conf_id); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			default: | 
					
						
							|  |  |  | 				bc_next_state_change(*bc,BCHAN_BRIDGED); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void misdn_lib_split_bridge( struct misdn_bchannel * bc1, struct misdn_bchannel *bc2) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct misdn_bchannel *bc_list[]={ | 
					
						
							|  |  |  | 		bc1,bc2,NULL | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	struct misdn_bchannel **bc; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (bc=bc_list; *bc;  bc++) { | 
					
						
							| 
									
										
										
										
											2006-04-03 19:17:59 +00:00
										 |  |  | 		if ( (*bc)->bc_state == BCHAN_BRIDGED){ | 
					
						
							|  |  |  | 			misdn_split_conf( *bc, (*bc)->conf_id); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			cb_log( 2, (*bc)->port, "BC not bridged (state:%s) so not splitting it\n",bc_state2str((*bc)->bc_state)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-01 22:04:14 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2006-05-05 16:38:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void misdn_lib_echo(struct misdn_bchannel *bc, int onoff) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2007-01-03 11:03:57 +00:00
										 |  |  | 	cb_log(3,bc->port, " --> ECHO %s\n", onoff?"ON":"OFF"); | 
					
						
							| 
									
										
										
										
											2006-05-05 16:38:15 +00:00
										 |  |  | 	manager_ph_control(bc, onoff?CMX_ECHO_ON:CMX_ECHO_OFF, 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-30 14:05:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | void misdn_lib_reinit_nt_stack(int port) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct misdn_stack *stack=find_stack_by_port(port); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-30 14:05:42 +00:00
										 |  |  | 	if (stack) { | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 		stack->l2link=0; | 
					
						
							|  |  |  | 		stack->blocked=0; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-30 14:05:42 +00:00
										 |  |  | 		cleanup_Isdnl3(&stack->nst); | 
					
						
							|  |  |  | 		cleanup_Isdnl2(&stack->nst); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		memset(&stack->nst, 0, sizeof(net_stack_t)); | 
					
						
							|  |  |  | 		memset(&stack->mgr, 0, sizeof(manager_t)); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-30 14:05:42 +00:00
										 |  |  | 		stack->mgr.nst = &stack->nst; | 
					
						
							|  |  |  | 		stack->nst.manager = &stack->mgr; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-30 14:05:42 +00:00
										 |  |  | 		stack->nst.l3_manager = handle_event_nt; | 
					
						
							|  |  |  | 		stack->nst.device = glob_mgr->midev; | 
					
						
							|  |  |  | 		stack->nst.cardnr = port; | 
					
						
							|  |  |  | 		stack->nst.d_stid = stack->d_stid; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-30 14:05:42 +00:00
										 |  |  | 		stack->nst.feature = FEATURE_NET_HOLD; | 
					
						
							|  |  |  | 		if (stack->ptp) | 
					
						
							|  |  |  | 			stack->nst.feature |= FEATURE_NET_PTP; | 
					
						
							|  |  |  | 		if (stack->pri) | 
					
						
							|  |  |  | 			stack->nst.feature |= FEATURE_NET_CRLEN2 | FEATURE_NET_EXTCID; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-30 14:05:42 +00:00
										 |  |  | 		stack->nst.l1_id = stack->lower_id; | 
					
						
							|  |  |  | 		stack->nst.l2_id = stack->upper_id; | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-30 14:05:42 +00:00
										 |  |  | 		msg_queue_init(&stack->nst.down_queue); | 
					
						
							| 
									
										
										
										
											2009-03-23 22:35:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-30 14:05:42 +00:00
										 |  |  | 		Isdnl2Init(&stack->nst); | 
					
						
							|  |  |  | 		Isdnl3Init(&stack->nst); | 
					
						
							| 
									
										
										
										
											2006-08-08 09:19:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (!stack->ptp) | 
					
						
							|  |  |  | 			misdn_lib_get_l1_up(stack); | 
					
						
							|  |  |  | 		misdn_lib_get_l2_up(stack); | 
					
						
							| 
									
										
										
										
											2006-06-30 14:05:42 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 |