[svn-commits] nadi: branch group/trunk-cm-csel-hash r47091 - in /team/group/trunk-cm-csel-h...

svn-commits at lists.digium.com svn-commits at lists.digium.com
Fri Nov 3 09:04:02 MST 2006


Author: nadi
Date: Fri Nov  3 10:04:01 2006
New Revision: 47091

URL: http://svn.digium.com/view/asterisk?rev=47091&view=rev
Log:
state machine is taking over chan_misdn

Modified:
    team/group/trunk-cm-csel-hash/channels/chan_misdn.c
    team/group/trunk-cm-csel-hash/channels/misdn/isdn_lib.c
    team/group/trunk-cm-csel-hash/channels/misdn/isdn_lib.h
    team/group/trunk-cm-csel-hash/channels/misdn/isdn_lib_intern.h
    team/group/trunk-cm-csel-hash/channels/misdn/isdn_msg_parser.c
    team/group/trunk-cm-csel-hash/channels/misdn/portinfo.c

Modified: team/group/trunk-cm-csel-hash/channels/chan_misdn.c
URL: http://svn.digium.com/view/asterisk/team/group/trunk-cm-csel-hash/channels/chan_misdn.c?rev=47091&r1=47090&r2=47091&view=diff
==============================================================================
--- team/group/trunk-cm-csel-hash/channels/chan_misdn.c (original)
+++ team/group/trunk-cm-csel-hash/channels/chan_misdn.c Fri Nov  3 10:04:01 2006
@@ -107,6 +107,8 @@
 	AEVENT_CCONGESTION,
 	AEVENT_CHOLD,
 	AEVENT_CUNHOLD,
+
+	AEVENT_UNKNOWN,
 };
 
 enum misdn_chan_state {
@@ -610,7 +612,7 @@
 	FILE *fp;
 
 	if (!((0 <= port) && (port <= max_ports))) {
-		ast_log(LOG_WARNING, "cb_log called with out-of-range port number! (%d)\n", port);
+		ast_log(LOG_WARNING, "chan_misdn_log called with out-of-range port number! (%d)\n", port);
 		port = 0;
 		level = -1;
 	}
@@ -654,8 +656,9 @@
 }
 
 /* State Machine: Generic */
-#define STATE_CONTINUE  -1 /*!< use this in state_next, if there exists a following transition */
-#define STATE_ANY       -2 /*!< wildcard for the state field in struct state_machine_transision */
+#define STATE_CONTINUE  -1 /*!< use this in state_next if there exists a following transition */
+#define STATE_KEEP      -2 /*!< use this in state_next if you want to keep the current state */
+#define STATE_ANY       -3 /*!< wildcard for the state field in struct state_machine_transision */
 
 #define EVENT_DEFAULT   -1 /*!< return value of handle(): statemachine will send the event as read from the transition table */
 #define EVENT_BREAK     -2 /*!< return value of handle(): no event will be sent out, state_machine_run returns success */
@@ -670,7 +673,7 @@
 {
 	struct state_machine *sm = malloc(sizeof(struct state_machine));
 
-	chan_misdn_log(0, 0, "state_machine_create: Creating with state %d ...\n", state);
+	chan_misdn_log(1, 0, "state_machine_create: Creating with state %d ...\n", state);
 
 	if (sm) {
 		sm->p = p;
@@ -685,10 +688,10 @@
 
 static void state_machine_destroy (struct state_machine *sm)
 {
-	chan_misdn_log(0, 0, "state_machine_destroy: Freeing at state %d ...\n", sm ? sm->state : -99 );
-
-	if (sm)
+	if (sm) {
+		chan_misdn_log(1, 0, "state_machine_destroy: Freeing at state %d ...\n", sm->state);
 		free(sm);
+	}
 }
 
 static int state_machine_run (struct state_machine *sm, int event)
@@ -699,7 +702,7 @@
 		err,
 		retval = -1;
 
-	chan_misdn_log(0, 0, "state_machine_run: Running event %d at state %d ...\n", event, sm->state);
+	chan_misdn_log(1, 0, "state_machine_run: Running event %d at state %d ...\n", event, sm->state);
 
 	for (; i < sm->num_rows; ++i) {
 		t = &sm->table[i];
@@ -707,18 +710,18 @@
 			(t->event == event || t->event == EVENT_ANY)) {
 			if (t->handle)
 				event_out = t->handle(sm->p, sm->state, event);
+			if (event_out == EVENT_DEFAULT)
+				event_out = t->event_out;
 			switch (event_out) {
 			case EVENT_BREAK:
 				retval = 0;
 				goto out;
 			case EVENT_NONE:
 				break;
-			case EVENT_DEFAULT:
-				event_out = t->event_out;
 			default:
-				chan_misdn_log(0, 0, "state_machine_run:   -> Sending event %d ...\n", event_out);
+				chan_misdn_log(1, 0, "state_machine_run:   -> Sending event %d ...\n", event_out);
 				err = sm->send_event(sm->p, event_out);
-				chan_misdn_log(0, 0, "state_machine_run:   -> Finished event %d, retval: %d ...\n", event_out, err);
+				chan_misdn_log(1, 0, "state_machine_run:   -> Finished event %d, retval: %d ...\n", event_out, err);
 				if (err) {
 					retval = err;
 					goto out;
@@ -727,14 +730,15 @@
 			event_out = EVENT_DEFAULT;
 			if (t->state_next == STATE_CONTINUE)
 				continue;
-			sm->state = t->state_next;
+			if (t->state_next != STATE_KEEP)
+				sm->state = t->state_next;
 			retval = 0;
 			goto out;
 		}
 	}
 
 out:
-	chan_misdn_log(0, 0, "state_machine_run: Returning with value %d ...\n", retval);
+	chan_misdn_log(1, 0, "state_machine_run: Returning with value %d ...\n", retval);
 	return retval;
 }
 
@@ -751,38 +755,163 @@
 /* State Machine: mISDN */
 static int handle_aevent_hangup (void *p, int state, int event);
 static int handle_mevent_proceeding_progress (void *p, int state, int event);
+static int handle_mevent_port_alarm (void *p, int state, int event);
+static int handle_mevent_new_channel (void *p, int state, int event);
+static int handle_mevent_new_l3id (void *p, int state, int event);
+static int handle_mevent_dtmf_tone (void *p, int state, int event);
+static int handle_mevent_setup_acknowledge (void *p, int state, int event);
+static int handle_mevent_alerting (void *p, int state, int event);
+static int handle_mevent_connect_acknowledge (void *p, int state, int event);
+static int handle_mevent_release (void *p, int state, int event);
+static int handle_mevent_release_complete (void *p, int state, int event);
+static int handle_mevent_cleanup (void *p, int state, int event);
 
 static struct state_machine_transition misdn_state_table[] = {
-	{ MISDN_NOTHING,              AEVENT_CALL,   MISDN_CALLING,  EVENT_SETUP,            NULL },
-
-	{ MISDN_CALLING,              AEVENT_HANGUP, MISDN_CLEANING, EVENT_RELEASE_COMPLETE, NULL },
-	{ MISDN_DISCONNECTED,         AEVENT_HANGUP, MISDN_CLEANING, EVENT_RELEASE,          NULL },
-	{ MISDN_RELEASED,             AEVENT_HANGUP, MISDN_CLEANING, EVENT_NONE,             NULL },
-	{ MISDN_CLEANING,             AEVENT_HANGUP, MISDN_CLEANING, EVENT_NONE,             NULL },
-	{ MISDN_BUSY,                 AEVENT_HANGUP, MISDN_CLEANING, EVENT_NONE,             NULL },
-	{ MISDN_HOLD_DISCONNECT,      AEVENT_HANGUP, MISDN_CLEANING, EVENT_RELEASE,          handle_aevent_hangup },
-	{ MISDN_CLEANING,             AEVENT_HANGUP, MISDN_CLEANING, EVENT_NONE,             handle_aevent_hangup },
-	{ STATE_ANY,                  AEVENT_HANGUP, MISDN_CLEANING, EVENT_DISCONNECT,       handle_aevent_hangup },
-
-	{ STATE_ANY,                  AEVENT_ANSWER, MISDN_CONNECTED, EVENT_CONNECT,         NULL },
-
-	{ STATE_ANY,                  AEVENT_CBUSY,  MISDN_CLEANING, EVENT_DISCONNECT,       NULL },
-
-	{ STATE_ANY,                  EVENT_PROCEEDING, MISDN_PROCEEDING, 127 + AST_CONTROL_PROCEEDING, handle_mevent_proceeding_progress },
-	{ STATE_ANY,                  EVENT_PROGRESS, MISDN_PROGRESS, 127 + AST_CONTROL_PROGRESS, handle_mevent_proceeding_progress },
+	/*
+	 * ASTERISK EVENTS
+	 */
+	{ MISDN_NOTHING,              AEVENT_CALL,             MISDN_CALLING,               EVENT_SETUP,                 NULL },
+
+	{ MISDN_CALLING,              AEVENT_HANGUP,           MISDN_CLEANING,              EVENT_RELEASE_COMPLETE,      NULL },
+	{ MISDN_DISCONNECTED,         AEVENT_HANGUP,           MISDN_CLEANING,              EVENT_RELEASE,               NULL },
+	{ MISDN_RELEASED,             AEVENT_HANGUP,           MISDN_CLEANING,              EVENT_NONE,                  NULL },
+	{ MISDN_CLEANING,             AEVENT_HANGUP,           MISDN_CLEANING,              EVENT_NONE,                  NULL },
+	{ MISDN_BUSY,                 AEVENT_HANGUP,           MISDN_CLEANING,              EVENT_NONE,                  NULL },
+	{ MISDN_HOLD_DISCONNECT,      AEVENT_HANGUP,           MISDN_CLEANING,              EVENT_RELEASE,               handle_aevent_hangup },
+	{ MISDN_CLEANING,             AEVENT_HANGUP,           MISDN_CLEANING,              EVENT_NONE,                  handle_aevent_hangup },
+	{ STATE_ANY,                  AEVENT_HANGUP,           MISDN_CLEANING,              EVENT_DISCONNECT,            handle_aevent_hangup },
+
+	{ STATE_ANY,                  AEVENT_ANSWER,           MISDN_CONNECTED,             EVENT_CONNECT,               NULL },
+
+	{ STATE_ANY,                  AEVENT_CBUSY,            MISDN_CLEANING,              EVENT_DISCONNECT,            NULL },
+
+	/*
+	 * MISDN EVENTS
+	 */
+	{ STATE_ANY,                  EVENT_PROCEEDING,        MISDN_PROCEEDING,            AEVENT_CPROCEEDING,          handle_mevent_proceeding_progress },
+	{ STATE_ANY,                  EVENT_PROGRESS,          MISDN_PROGRESS,              AEVENT_CPROGRESS,            handle_mevent_proceeding_progress },
+	{ STATE_ANY,                  EVENT_SETUP_ACKNOWLEDGE, MISDN_CALLING_ACKNOWLEDGE,   EVENT_NONE,                  handle_mevent_setup_acknowledge },
+	{ STATE_ANY,                  EVENT_ALERTING,          MISDN_ALERTING,              AEVENT_CRINGING,             handle_mevent_alerting },
+	{ STATE_ANY,                  EVENT_CONNECT_ACKNOWLEDGE, MISDN_CONNECTED,           AEVENT_CANSWER,              handle_mevent_connect_acknowledge },
+	{ STATE_ANY,                  EVENT_RELEASE_COMPLETE,  MISDN_CLEANING,              EVENT_NONE,                  handle_mevent_release_complete },
+
+	/* state keeping events */
+	{ STATE_ANY,                  EVENT_PORT_ALARM,        STATE_KEEP,                  EVENT_NONE,                  handle_mevent_port_alarm },
+	{ STATE_ANY,                  EVENT_NEW_CHANNEL,       STATE_KEEP,                  EVENT_NONE,                  handle_mevent_new_channel },
+	{ STATE_ANY,                  EVENT_NEW_L3ID,          STATE_KEEP,                  EVENT_NONE,                  handle_mevent_new_l3id },
+	{ STATE_ANY,                  EVENT_DTMF_TONE,         STATE_KEEP,                  EVENT_NONE,                  handle_mevent_dtmf_tone },
+	{ STATE_ANY,                  EVENT_RELEASE,           STATE_KEEP,                  EVENT_RELEASE_COMPLETE,      handle_mevent_release },
+	{ STATE_ANY,                  EVENT_CLEANUP,           STATE_KEEP,                  EVENT_NONE,                  handle_mevent_cleanup },
+
+	/* noop events */
+	{ STATE_ANY,                  EVENT_BCHAN_ACTIVATED,   STATE_KEEP,                  EVENT_NONE,                  NULL},
+	{ STATE_ANY,                  EVENT_STATUS,            STATE_KEEP,                  EVENT_NONE,                  NULL},
 };
 
+static const char * event2str (int event)
+{
+	static char *mevents[] = {
+		"EVENT_NOTHING",
+		"EVENT_TONE_GENERATE",
+		"EVENT_BCHAN_DATA",
+		"EVENT_BCHAN_ACTIVATED",
+		"EVENT_BCHAN_ERROR",
+		"EVENT_CLEANUP",
+		"EVENT_PROCEEDING",
+		"EVENT_PROGRESS",
+		"EVENT_SETUP",
+		"EVENT_ALERTING",
+		"EVENT_CONNECT",
+		"EVENT_SETUP_ACKNOWLEDGE",
+		"EVENT_CONNECT_ACKNOWLEDGE ",
+		"EVENT_USER_INFORMATION",
+		"EVENT_SUSPEND_REJECT",
+		"EVENT_RESUME_REJECT",
+		"EVENT_HOLD",
+		"EVENT_SUSPEND",
+		"EVENT_RESUME",
+		"EVENT_HOLD_ACKNOWLEDGE",
+		"EVENT_SUSPEND_ACKNOWLEDGE",
+		"EVENT_RESUME_ACKNOWLEDGE",
+		"EVENT_HOLD_REJECT",
+		"EVENT_RETRIEVE",
+		"EVENT_RETRIEVE_ACKNOWLEDGE",
+		"EVENT_RETRIEVE_REJECT",
+		"EVENT_DISCONNECT",
+		"EVENT_RESTART",
+		"EVENT_RELEASE",
+		"EVENT_RELEASE_COMPLETE",
+		"EVENT_FACILITY",
+		"EVENT_NOTIFY",
+		"EVENT_STATUS_ENQUIRY",
+		"EVENT_INFORMATION",
+		"EVENT_STATUS",
+		"EVENT_TIMEOUT",
+		"EVENT_DTMF_TONE",
+		"EVENT_NEW_L3ID",
+		"EVENT_NEW_BC",
+		"EVENT_PORT_ALARM",
+		"EVENT_NEW_CHANNEL",
+		"EVENT_UNKNOWN"
+	};
+
+	static char *aevents[] = {
+		"AEVENT_NOTHING",
+		"AEVENT_CALL",
+		"AEVENT_HANGUP",
+		"AEVENT_ANSWER",
+		"AEVENT_CBUSY",
+		"AEVENT_CRING",
+		"AEVENT_CRINGING",
+		"AEVENT_CANSWER",
+		"AEVENT_CTAKEOFFHOOK",
+		"AEVENT_COFFHOOK",
+		"AEVENT_CFLASH",
+		"AEVENT_CPROGRESS",
+		"AEVENT_CPROCEEDING",
+		"AEVENT_CCONGESTION",
+		"AEVENT_CHOLD",
+		"AEVENT_CUNHOLD",
+		"AEVENT_UNKNOWN",
+	};
+
+	static char unknown[] = "<UNKNOWN>";
+
+	if (event >= EVENT_NOTHING && event <= EVENT_UNKNOWN)
+		return mevents[event];
+	else if (event >= AEVENT_NOTHING && event <= AEVENT_UNKNOWN)
+		return aevents[event - AEVENT_NOTHING];
+	else
+		return unknown;
+}
+
 static int send_event (void *p, int event)
 {
-	int re = -1;
 	struct chan_list *ch = p;
+	int re = 0;
 
 	if (event > EVENT_NOTHING && event < EVENT_UNKNOWN) {
+		chan_misdn_log(0, ch->bc->port, "--> I: %s\n", event2str(event));
 		misdn_lib_send_event(ch->bc, event);
-		re = 0;
 	} else {
-		ast_queue_control(ch->ast, event - 127);
-		re = 0;
+		chan_misdn_log(0, ch->bc->port, "--> *: %s\n", event2str(event));
+		switch (event) {
+		case AEVENT_CPROCEEDING:
+			ast_queue_control(ch->ast, AST_CONTROL_PROCEEDING);
+			break;
+		case AEVENT_CPROGRESS:
+			ast_queue_control(ch->ast, AST_CONTROL_PROGRESS);
+			break;
+		case AEVENT_CRINGING:
+			ast_queue_control(ch->ast, AST_CONTROL_RINGING);
+			ast_setstate(ch->ast, AST_STATE_RINGING);
+			break;
+		case AEVENT_CANSWER:
+			ast_queue_control(ch->ast, AST_CONTROL_ANSWER);
+			break;
+		default:
+			re = -1;
+		}
 	}
 
 	return re;
@@ -1470,7 +1599,7 @@
 	if (misdn_tasks) {
 		chan_misdn_log(4, 0, "Killing misdn_tasks thread\n");
 		if (pthread_cancel(misdn_tasks_thread) == 0) {
-			cb_log(4, 0, "Joining misdn_tasks thread\n");
+			chan_misdn_log(4, 0, "Joining misdn_tasks thread\n");
 			pthread_join(misdn_tasks_thread, NULL);
 		}
 		sched_context_destroy(misdn_tasks);
@@ -1649,15 +1778,15 @@
 	int port;
 
 	if (!ch || !ch->bc) {
-		cb_log(1, 0, "Cannot hangup chan, no ch or no ch->bc!\n");
+		chan_misdn_log(1, 0, "Cannot hangup chan, no ch or no ch->bc!\n");
 		return;
 	}
 	
 	port = ch->bc ? ch->bc->port : 0;
-	cb_log(1, port, "hangup_chan\n");
+	chan_misdn_log(1, port, "hangup_chan\n");
 
 	if (ch->need_hangup) {
-		cb_log(1, port, "-> hangup\n");
+		chan_misdn_log(1, port, "-> hangup\n");
 		send_cause_to_ast(ch->ast, ch->bc, ch);
 		ch->need_hangup = ch->need_queue_hangup = 0;
 		if (ch->ast)
@@ -1666,16 +1795,16 @@
 	}
 
 	if (!ch->need_queue_hangup) {
-		cb_log(1, port, "No need to queue hangup\n");
+		chan_misdn_log(1, port, "No need to queue hangup\n");
 	}
 
 	ch->need_queue_hangup = 0;
 	if (ch->ast) {
 		send_cause_to_ast(ch->ast, ch->bc, ch);
 		ast_queue_hangup(ch->ast);
-		cb_log(1, port, "-> queue_hangup\n");
+		chan_misdn_log(1, port, "-> queue_hangup\n");
 	} else
-		cb_log(1, port, "Cannot hangup chan, no ast\n");
+		chan_misdn_log(1, port, "Cannot hangup chan, no ast\n");
 }
 
 /* Isdn asks us to release channel, pendant to misdn_hangup */
@@ -2383,7 +2512,7 @@
 		if (threshold > len)
 			chan_misdn_log(0, bc->port, "config_ch_jitterbuffer: Jitterbuffer Threshold > Jitterbuffer setting to Jitterbuffer -1\n");
 		if (ch->jb) {
-			cb_log(0, bc->port, "config_ch_jitterbuffer: We've got a Jitterbuffer Already on this port.\n");
+			chan_misdn_log(0, bc->port, "config_ch_jitterbuffer: We've got a Jitterbuffer Already on this port.\n");
 			misdn_jb_destroy(ch->jb);
 			ch->jb = NULL;
 		}
@@ -2801,6 +2930,7 @@
 	else
 		chan_misdn_log(2, port, "NO OPTS GIVEN\n");
 
+	chan_misdn_log(0, port, "<-- *: %s\n", event2str(AEVENT_CALL));
 	if ((r = state_machine_run(ch->sm, AEVENT_CALL)))
 		chan_misdn_log(0, port, "state_machine_run failed on AEVENT_CALL: %d!\n", r);
 
@@ -2966,6 +3096,7 @@
 				   p->bc ? p->bc->pid : -1, ast->context, ast->exten, AST_CID_P(ast), get_ch_state(p),
 				   p->l3id, bc->cause, bc->out_cause, get_ch_state(p));
 
+	chan_misdn_log(0, bc->port, "<-- *: %s\n", event2str(AEVENT_HANGUP));
 	if ((re = state_machine_run(p->sm, AEVENT_HANGUP))) {
 		chan_misdn_log(0, bc->port, "state_machine_run failed on AEVENT_HANGUP: %d!\n", re);
 		return -1;
@@ -3059,6 +3190,7 @@
 		ast_copy_string(p->bc->cad, p->bc->dad, sizeof(p->bc->cad));
 	}
 
+	chan_misdn_log(0, p->bc->port, "<-- *: %s\n", event2str(AEVENT_ANSWER));
 	state_machine_run(p->sm, AEVENT_ANSWER);
 	
 	start_bc_tones(p);
@@ -3245,7 +3377,7 @@
 	if (!ch->bc->nojitter && misdn_cap_is_speech(ch->bc->capability)) {
 		/* Buffered Transmit (triggert by read from isdn side) */
 		if (misdn_jb_fill(ch->jb, frame->data, frame->samples) < 0)
-			cb_log(0, ch->bc->port, "Misdn Jitterbuffer Overflow.\n");
+			chan_misdn_log(0, ch->bc->port, "Misdn Jitterbuffer Overflow.\n");
 	} else
 		/*transmit without jitterbuffer*/
 		i = misdn_lib_tx2misdn_frm(ch->bc, frame->data, frame->samples);
@@ -3388,6 +3520,7 @@
 	return 0;
 }
 
+/* misdn event handler functions, called by state machine on event */
 static int handle_mevent_proceeding_progress (void *p, int state, int event)
 {
 	struct chan_list *ch = p;
@@ -3398,7 +3531,137 @@
 	return EVENT_DEFAULT;
 }
 
-/* The big event handler for events from mISDN (isdn_lib) */
+static int handle_mevent_port_alarm (void *p, int state, int event)
+{
+	struct chan_list *ch = p;
+	int boa;
+
+	if (cm_get_int(misdn_cm, boa, PORT, MCFG_BLOCK_ON_ALARM, ch->bc->port))
+		boa = 0;
+	if (boa > 0) {
+		chan_misdn_log(1, ch->bc->port, " --> blocking\n");
+		misdn_lib_port_block(ch->bc->port); 
+	}
+
+	return EVENT_DEFAULT;
+}
+
+static int handle_mevent_new_channel (void *p, int state, int event)
+{
+	struct chan_list *ch = p;
+	update_name(ch->ast, ch->bc->port, ch->bc->channel);
+	return EVENT_DEFAULT;
+}
+
+static int handle_mevent_new_l3id (void *p, int state, int event)
+{
+	struct chan_list *ch = p;
+
+	ch->l3id = ch->bc->l3_id;
+	ch->addr = ch->bc->addr;
+
+	return EVENT_DEFAULT;
+}
+
+static int handle_mevent_dtmf_tone (void *p, int state, int event)
+{
+	struct chan_list *ch = p;
+	struct ast_frame fr;
+
+	if (!ch->ignore_dtmf) {
+		memset(&fr, 0, sizeof(fr));
+		fr.frametype = AST_FRAME_DTMF;
+		fr.subclass = ch->bc->dtmf;
+		fr.delivery = ast_tv(0, 0);
+		chan_misdn_log(2, ch->bc->port, " --> DTMF:%c\n", ch->bc->dtmf);
+		ast_queue_frame(ch->ast, &fr);
+	} else
+		chan_misdn_log(2, ch->bc->port, " --> Ingoring DTMF:%c due to bridge flags\n", ch->bc->dtmf);
+
+	return EVENT_DEFAULT;
+}
+
+static int handle_mevent_setup_acknowledge (void *p, int state, int event)
+{
+	struct chan_list *ch = p;
+	struct misdn_bchannel *bc = ch->bc;
+	
+	if (bc->channel) 
+		update_name(ch->ast, bc->port, bc->channel);
+
+	if (!ast_strlen_zero(bc->infos_pending)) {
+		strncat(bc->dad, bc->infos_pending, sizeof(bc->dad) - strlen(bc->dad));
+		bc->dad[sizeof(bc->dad) - 1] = 0;
+		strncpy(ch->ast->exten, bc->dad, sizeof(ch->ast->exten));
+		ch->ast->exten[sizeof(ch->ast->exten) - 1] = 0;
+		strncpy(bc->info_dad, bc->infos_pending, sizeof(bc->info_dad));
+		bc->info_dad[sizeof(bc->info_dad) - 1] = 0;
+		*bc->infos_pending = 0;
+		return EVENT_INFORMATION;
+	}
+
+	return EVENT_DEFAULT;
+}
+
+static int handle_mevent_alerting (void *p, int state, int event)
+{
+	struct chan_list *ch = p;
+	struct misdn_bchannel *bc = ch->bc;
+	
+	chan_misdn_log(1, bc->port, "Set State Ringing\n");
+	if (misdn_cap_is_speech(bc->capability) && misdn_inband_avail(bc)) {
+		chan_misdn_log(1, bc->port, "Starting tones, we have inband data.\n");
+		start_bc_tones(ch);
+	} else
+		chan_misdn_log(1, bc->port, "We have no inband Data, the other end must create ringing.\n");
+
+	return EVENT_DEFAULT;
+}
+
+static int handle_mevent_connect_acknowledge (void *p, int state, int event)
+{
+	struct chan_list *ch = p;
+
+	ch->l3id = ch->bc->l3_id;
+	ch->addr = ch->bc->addr;
+	start_bc_tones(ch);
+
+	return EVENT_DEFAULT;
+}
+
+static int handle_mevent_release (void *p, int state, int event)
+{
+	struct chan_list *ch = p;
+
+	ch->bc->out_cause = 16;
+	hangup_chan(ch);
+
+	return ch->bc->need_release_complete ? EVENT_DEFAULT : EVENT_NONE;
+}
+
+static int handle_mevent_release_complete (void *p, int state, int event)
+{
+	struct chan_list *ch = p;
+	
+	stop_bc_tones(ch);
+	hangup_chan(ch);
+	
+	return EVENT_DEFAULT;
+}
+
+static int handle_mevent_cleanup (void *p, int state, int event)
+{
+	struct chan_list *ch = p;
+
+	stop_bc_tones(ch);
+	if (state == MISDN_CALLING)
+		ch->bc->cause = 27; /* Destination out of order */
+	hangup_chan(ch);
+
+	return EVENT_DEFAULT;
+}
+
+/* The big event handler for all events from mISDN (isdn_lib) */
 static enum event_response_e cb_events (enum event_e event, struct misdn_bchannel *bc, void *user_data)
 {
 	struct chan_list *ch = find_chan_by_bc(cl_te, bc);
@@ -3518,51 +3781,28 @@
 			bc->tone_cnt = 0;
 		return RESPONSE_OK;
 	}
-	
-	if (ch && !state_machine_run(ch->sm, event))
+
+	/*
+	 * run the state machine and return if the event could be handled
+	 */
+	chan_misdn_log(0, bc->port, "<-- I: %s\n", event2str(event));
+	if (ch && !state_machine_run(ch->sm, event)) {
+		if (event == EVENT_RELEASE || event == EVENT_RELEASE_COMPLETE || event == EVENT_CLEANUP)
+			release_chan(ch->bc);
 		return RESPONSE_OK;
-
+	}
+
+	/*
+	 * this is for events not (yet) handled by our state machine
+	 */
 	switch (event) {
-	case EVENT_PORT_ALARM:
-		{
-			int boa = 0;
-			cm_get_int(misdn_cm, boa, PORT, MCFG_BLOCK_ON_ALARM, bc->port);
-			if (boa > 0) {
-				cb_log(1, bc->port, " --> blocking\n");
-				misdn_lib_port_block(bc->port); 
-			}
-		}
-		break;
-	case EVENT_BCHAN_ACTIVATED:
-		break;
-	case EVENT_NEW_CHANNEL:
-		update_name(ch->ast, bc->port, bc->channel);
-		break;
-	case EVENT_NEW_L3ID:
-		ch->l3id = bc->l3_id;
-		ch->addr = bc->addr;
-		break;
 	case EVENT_NEW_BC:
 		if (!ch)
 			ch = find_holded(cl_te, bc);
 		if (!ch)
 			ast_log(LOG_WARNING, "NEW_BC without chan_list?\n");
 		else if (bc)
-			ch->bc = (struct misdn_bchannel *)user_data;
-		break;
-	case EVENT_DTMF_TONE:
-		if (!ch->ignore_dtmf) {
-			struct ast_frame fr;
-			memset(&fr, 0, sizeof(fr));
-			fr.frametype = AST_FRAME_DTMF;
-			fr.subclass = bc->dtmf;
-			fr.delivery = ast_tv(0, 0);
-			chan_misdn_log(2, bc->port, " --> DTMF:%c\n", bc->dtmf);
-			ast_queue_frame(ch->ast, &fr);
-		} else
-			chan_misdn_log(2, bc->port, " --> Ingoring DTMF:%c due to bridge flags\n", bc->dtmf);
-		break;
-	case EVENT_STATUS:
+			ch->bc = user_data;
 		break;
 	case EVENT_INFORMATION:
 		{
@@ -3810,32 +4050,6 @@
 			}
 		}
 		break;
-	case EVENT_SETUP_ACKNOWLEDGE:
-		state_machine_set_state(ch->sm, MISDN_CALLING_ACKNOWLEDGE);
-		if (bc->channel) 
-			update_name(ch->ast, bc->port, bc->channel);
-		if (!ast_strlen_zero(bc->infos_pending)) {
-			strncat(bc->dad, bc->infos_pending, sizeof(bc->dad) - strlen(bc->dad));
-			bc->dad[sizeof(bc->dad) - 1] = 0;
-			strncpy(ch->ast->exten, bc->dad, sizeof(ch->ast->exten));
-			ch->ast->exten[sizeof(ch->ast->exten) - 1] = 0;
-			strncpy(bc->info_dad, bc->infos_pending, sizeof(bc->info_dad));
-			bc->info_dad[sizeof(bc->info_dad) - 1] = 0;
-			strncpy(bc->infos_pending, "", 1);
-			misdn_lib_send_event(bc, EVENT_INFORMATION);
-		}
-		break;
-	case EVENT_ALERTING:
-		state_machine_set_state(ch->sm, MISDN_ALERTING);
-		ast_queue_control(ch->ast, AST_CONTROL_RINGING);
-		ast_setstate(ch->ast, AST_STATE_RINGING);
-		cb_log(1, bc->port, "Set State Ringing\n");
-		if (misdn_cap_is_speech(bc->capability) && misdn_inband_avail(bc)) {
-			cb_log(1, bc->port, "Starting tones, we have inband data.\n");
-			start_bc_tones(ch);
-		} else
-			cb_log(1, bc->port, "We have no inband Data, the other end must create ringing.\n");
-		break;
 	case EVENT_CONNECT:
 		{
 			struct ast_channel *bridged;
@@ -3855,13 +4069,6 @@
 			}
 		}
 		/* notice that we don't break here!*/
-	case EVENT_CONNECT_ACKNOWLEDGE:
-		ch->l3id = bc->l3_id;
-		ch->addr = bc->addr;
-		start_bc_tones(ch);
-		state_machine_set_state(ch->sm, MISDN_CONNECTED);
-		ast_queue_control(ch->ast, AST_CONTROL_ANSWER);
-		break;
 	case EVENT_DISCONNECT:
 		{
 			struct chan_list *holded_ch;
@@ -3881,7 +4088,7 @@
 				/* Check for holded channel, to implement transfer */
 				holded_ch = find_holded(cl_te, bc);
 				if (holded_ch && holded_ch != ch && ch->ast && state_machine_get_state(ch->sm) == MISDN_CONNECTED) {
-					cb_log(1, bc->port, " --> found holded ch\n");
+					chan_misdn_log(1, bc->port, " --> found holded ch\n");
 					misdn_transfer_bc(ch, holded_ch) ;
 				}
 				stop_bc_tones(ch);
@@ -3889,26 +4096,6 @@
 			}
 			bc->out_cause = -1;
 		}
-		break;
-	case EVENT_RELEASE:
-		bc->out_cause = 16;
-		hangup_chan(ch);
-		release_chan(bc);
-		if (bc->need_release_complete) 
-			misdn_lib_send_event(bc, EVENT_RELEASE_COMPLETE);
-		break;
-	case EVENT_RELEASE_COMPLETE:
-		stop_bc_tones(ch);
-		hangup_chan(ch);
-		release_chan(bc);
-		state_machine_set_state(ch->sm, MISDN_CLEANING);
-		break;
-	case EVENT_CLEANUP:
-		stop_bc_tones(ch);
-		if (state_machine_get_state(ch->sm) == MISDN_CALLING)
-			bc->cause = 27; /* Destination out of order */
-		hangup_chan(ch);
-		release_chan(bc);
 		break;
 	case EVENT_BCHAN_ERROR:
 	case EVENT_TIMEOUT:

Modified: team/group/trunk-cm-csel-hash/channels/misdn/isdn_lib.c
URL: http://svn.digium.com/view/asterisk/team/group/trunk-cm-csel-hash/channels/misdn/isdn_lib.c?rev=47091&r1=47090&r2=47091&view=diff
==============================================================================
--- team/group/trunk-cm-csel-hash/channels/misdn/isdn_lib.c (original)
+++ team/group/trunk-cm-csel-hash/channels/misdn/isdn_lib.c Fri Nov  3 10:04:01 2006
@@ -16,7 +16,6 @@
 #include <mISDNuser/isdn_debug.h>
 
 #include "isdn_lib_intern.h"
-#include "isdn_lib.h"
 
 void misdn_join_conf(struct misdn_bchannel *bc, int conf_id);
 void misdn_split_conf(struct misdn_bchannel *bc, int conf_id);
@@ -152,9 +151,6 @@
 #include <semaphore.h>
 #include <pthread.h>
 #include <signal.h>
-
-#include "isdn_lib.h"
-
 
 struct misdn_lib {
 	int midev;

Modified: team/group/trunk-cm-csel-hash/channels/misdn/isdn_lib.h
URL: http://svn.digium.com/view/asterisk/team/group/trunk-cm-csel-hash/channels/misdn/isdn_lib.h?rev=47091&r1=47090&r2=47091&view=diff
==============================================================================
--- team/group/trunk-cm-csel-hash/channels/misdn/isdn_lib.h (original)
+++ team/group/trunk-cm-csel-hash/channels/misdn/isdn_lib.h Fri Nov  3 10:04:01 2006
@@ -294,10 +294,6 @@
 };
 
 
-enum event_response_e (*cb_event) (enum event_e event, struct misdn_bchannel *bc, void *user_data);
-void (*cb_log) (int level, int port, char *tmpl, ...);
-int (*cb_jb_empty)(struct misdn_bchannel *bc, char *buffer, int len);
-
 struct misdn_lib_iface {
 	enum event_response_e (*cb_event)(enum event_e event, struct misdn_bchannel *bc, void *user_data);
 	void (*cb_log)(int level, int port, char *tmpl, ...);

Modified: team/group/trunk-cm-csel-hash/channels/misdn/isdn_lib_intern.h
URL: http://svn.digium.com/view/asterisk/team/group/trunk-cm-csel-hash/channels/misdn/isdn_lib_intern.h?rev=47091&r1=47090&r2=47091&view=diff
==============================================================================
--- team/group/trunk-cm-csel-hash/channels/misdn/isdn_lib_intern.h (original)
+++ team/group/trunk-cm-csel-hash/channels/misdn/isdn_lib_intern.h Fri Nov  3 10:04:01 2006
@@ -45,7 +45,9 @@
 /* for isdn_msg_parser.c */
 msg_t *create_l3msg(int prim, int mt, int dinfo , int size, int nt);
 
-
+enum event_response_e (*cb_event) (enum event_e event, struct misdn_bchannel *bc, void *user_data);
+void (*cb_log) (int level, int port, char *tmpl, ...);
+int (*cb_jb_empty)(struct misdn_bchannel *bc, char *buffer, int len);
 
 struct misdn_stack {
 	/** is first element because &nst equals &mISDNlist **/

Modified: team/group/trunk-cm-csel-hash/channels/misdn/isdn_msg_parser.c
URL: http://svn.digium.com/view/asterisk/team/group/trunk-cm-csel-hash/channels/misdn/isdn_msg_parser.c?rev=47091&r1=47090&r2=47091&view=diff
==============================================================================
--- team/group/trunk-cm-csel-hash/channels/misdn/isdn_msg_parser.c (original)
+++ team/group/trunk-cm-csel-hash/channels/misdn/isdn_msg_parser.c Fri Nov  3 10:04:01 2006
@@ -13,9 +13,6 @@
 
 
 #include "isdn_lib_intern.h"
-
-
-#include "isdn_lib.h"
 
 #include "ie.c"
 

Modified: team/group/trunk-cm-csel-hash/channels/misdn/portinfo.c
URL: http://svn.digium.com/view/asterisk/team/group/trunk-cm-csel-hash/channels/misdn/portinfo.c?rev=47091&r1=47090&r2=47091&view=diff
==============================================================================
--- team/group/trunk-cm-csel-hash/channels/misdn/portinfo.c (original)
+++ team/group/trunk-cm-csel-hash/channels/misdn/portinfo.c Fri Nov  3 10:04:01 2006
@@ -1,6 +1,5 @@
 
 
-#include "isdn_lib.h"
 #include "isdn_lib_intern.h"
 
 



More information about the svn-commits mailing list