** **
\*****************************************************************************/
-
#include "main.h"
#include <poll.h>
#include <errno.h>
}
#endif
+#ifndef CMX_TXDATA_ON
+#define OLD_MISDN
+#endif
+#ifndef CMX_TXDATA_OFF
+#define OLD_MISDN
+#endif
+#ifndef CMX_DELAY
+#define OLD_MISDN
+#endif
+#ifndef PIPELINE_CFG
+#define OLD_MISDN
+#endif
+#ifndef CMX_TX_DATA
+#define OLD_MISDN
+#endif
+
+#ifdef OLD_MISDN
+#warning
+#warning *********************************************************
+#warning *
+#warning * It seems that you use an older version of mISDN.
+#warning * Features like voice recording or echo will not work.
+#warning * Also it causes problems with loading modules and may
+#warning * not work at all.
+#warning *
+#warning * Please upgrade to newer version. A working version can
+#warning * be found at www.linux-call-router.de.
+#warning *
+#warning * Do not use the mISDN_1_1 branch, it does not have all
+#warning * the features that are required. Use the master branch
+#warning * instead.
+#warning *
+#warning *********************************************************
+#warning
+#error
+#endif
+
#ifndef ISDN_PID_L4_B_USER
#define ISDN_PID_L4_B_USER 0x440000ff
#endif
+// timeouts if activating/deactivating response from mISDN got lost
+#define B_TIMER_ACTIVATING 1
+#define B_TIMER_DEACTIVATING 1
+
/* list of mISDN ports */
struct mISDNport *mISDNport_first;
return(-1);
}
- /* initialize stuff of the NT lib */
+ /* open debug, if enabled and not only stack debugging */
+ if (options.deb && (options.deb != DEBUG_STACK))
+ {
+ SPRINT(debug_log, "%s/debug.log", INSTALL_DATA);
+ debug_fp = fopen(debug_log, "a");
+ }
+
if (options.deb & DEBUG_STACK)
{
- global_debug = 0xffffffff & ~DBGM_MSG;
-// global_debug = DBGM_L3DATA;
+ SPRINT(debug_stack, "%s/debug_mISDN.log", INSTALL_DATA);
+ mISDN_debug_init(DBGM_ALL, debug_stack, debug_stack, debug_stack);
} else
- global_debug = DBGM_MAN;
- SPRINT(debug_log, "%s/debug.log", INSTALL_DATA);
- if (options.deb & DEBUG_LOG)
- mISDN_debug_init(global_debug, debug_log, debug_log, debug_log);
- else
- mISDN_debug_init(global_debug, NULL, NULL, NULL);
+ mISDN_debug_init(0, NULL, NULL, NULL);
/* init mlayer3 */
init_layer3(4); // buffer of 4
mISDN_debug_close();
+ if (debug_fp)
+ fclose(debug_fp);
+ debug_fp = NULL;
+
if (mISDNsocket > -1)
close(mISDNsocket);
}
unsigned char buff[1025];
debug_close();
+ global_debug = 0;
if (mISDNdevice >= 0)
{
/* trace */
chan_trace_header(mISDNport, mISDNport->b_port[i], activate?(char*)"BCHANNEL activate":(char*)"BCHANNEL deactivate", DIRECTION_OUT);
add_trace("channel", NULL, "%d", i+1+(i>=15));
+ if (mISDNport->b_timer[i])
+ add_trace("event", NULL, "timeout recovery");
end_trace();
}
}
/* set dsp features */
+#ifndef OLD_MISDN
if (port->p_m_txdata)
ph_control(mISDNport, port, handle, (port->p_m_txdata)?CMX_TXDATA_ON:CMX_TXDATA_OFF, 0, "DSP-TXDATA", port->p_m_txdata);
if (port->p_m_delay)
ph_control(mISDNport, port, handle, CMX_DELAY, port->p_m_delay, "DSP-DELAY", port->p_m_delay);
+#endif
if (port->p_m_tx_gain)
ph_control(mISDNport, port, handle, VOL_CHANGE_TX, port->p_m_tx_gain, "DSP-TX_GAIN", port->p_m_tx_gain);
if (port->p_m_rx_gain)
ph_control(mISDNport, port, handle, VOL_CHANGE_RX, port->p_m_rx_gain, "DSP-RX_GAIN", port->p_m_rx_gain);
+#ifndef OLD_MISDN
if (port->p_m_pipeline[0])
ph_control_block(mISDNport, port, handle, PIPELINE_CFG, port->p_m_pipeline, strlen(port->p_m_pipeline)+1, "DSP-PIPELINE", 0);
+#endif
if (port->p_m_conf)
ph_control(mISDNport, port, handle, CMX_CONF_JOIN, port->p_m_conf, "DSP-CONF", port->p_m_conf);
if (port->p_m_echo)
{
class PmISDN *b_port = mISDNport->b_port[i];
int state = mISDNport->b_state[i];
+ double timer = mISDNport->b_timer[i];
unsigned long p_m_remote_ref = 0;
unsigned long p_m_remote_id = 0;
int p_m_tx_gain = 0;
{
_bchannel_activate(mISDNport, i, 1);
state = B_STATE_ACTIVATING;
+ timer = now_d + B_TIMER_ACTIVATING;
}
}
break;
/* bchannel is active, so we deactivate */
_bchannel_activate(mISDNport, i, 0);
state = B_STATE_DEACTIVATING;
+ timer = now_d + B_TIMER_DEACTIVATING;
break;
default:
break;
case B_EVENT_ACTIVATED:
+ timer = 0;
switch(state)
{
case B_STATE_ACTIVATING:
/* bchannel is active, but exported OR not used anymore (or has wrong stack config), so we deactivate */
_bchannel_activate(mISDNport, i, 0);
state = B_STATE_DEACTIVATING;
+ timer = now_d + B_TIMER_DEACTIVATING;
}
break;
/* bchannel is active, so we deactivate */
_bchannel_activate(mISDNport, i, 0);
state = B_STATE_DEACTIVATING;
+ timer = now_d + B_TIMER_DEACTIVATING;
break;
case B_STATE_REMOTE:
break;
case B_EVENT_DEACTIVATED:
+ timer = 0;
switch(state)
{
case B_STATE_IDLE:
{
_bchannel_activate(mISDNport, i, 1);
state = B_STATE_ACTIVATING;
+ timer = now_d + B_TIMER_ACTIVATING;
}
}
}
{
_bchannel_activate(mISDNport, i, 1);
state = B_STATE_ACTIVATING;
+ timer = now_d + B_TIMER_ACTIVATING;
}
}
}
}
break;
+ case B_EVENT_TIMEOUT:
+ timer = 0;
+ switch(state)
+ {
+ case B_STATE_IDLE:
+ /* ignore due to deactivation confirm after unloading */
+ break;
+
+ case B_STATE_ACTIVATING:
+ _bchannel_activate(mISDNport, i, 1);
+ timer = now_d + B_TIMER_ACTIVATING;
+ break;
+
+ case B_STATE_DEACTIVATING:
+ _bchannel_activate(mISDNport, i, 0);
+ timer = now_d + B_TIMER_DEACTIVATING;
+ break;
+
+ default:
+ PERROR("Illegal event %d at state %d, please correct.\n", event, state);
+ }
+ break;
+
default:
PERROR("Illegal event %d, please correct.\n", event);
}
mISDNport->b_state[i] = state;
+ mISDNport->b_timer[i] = timer;
}
{
switch(frm->dinfo)
{
+#ifndef OLD_MISDN
case CMX_TX_DATA:
if (!p_m_txdata)
{
if (p_record)
record(data, len, 1); // from up
break;
+#endif
default:
chan_trace_header(p_m_mISDNport, this, "BCHANNEL signal", DIRECTION_IN);
{
p_m_delay = param->mISDNsignal.delay;
PDEBUG(DEBUG_BCHANNEL, "we change delay mode to delay=%d.\n", p_m_delay);
+#ifndef OLD_MISDN
if (p_m_b_index >= 0)
if (p_m_mISDNport->b_state[p_m_b_index] == B_STATE_ACTIVE)
#ifdef SOCKET_MISDN
#else
ph_control(p_m_mISDNport, this, p_m_mISDNport->b_addr[p_m_b_index], p_m_delay?CMX_DELAY:CMX_JITTER, p_m_delay, "DSP-DELAY", p_m_delay);
#endif
+#endif
} else
PDEBUG(DEBUG_BCHANNEL, "we already have delay=%d.\n", p_m_delay);
break;
i = 0;
while(i < mISDNport->b_num)
{
+ /* process timer events for bchannel handling */
+ if (mISDNport->b_timer[i])
+ {
+ if (mISDNport->b_timer[i] <= now_d)
+ bchannel_event(mISDNport, i, B_EVENT_TIMEOUT);
+ }
/* handle port of bchannel */
isdnport=mISDNport->b_port[i];
if (isdnport)
i = 0;
while(i < mISDNport->b_num)
{
+ /* process timer events for bchannel handling */
+ if (mISDNport->b_timer[i])
+ {
+ if (mISDNport->b_timer[i] <= now_d)
+ bchannel_event(mISDNport, i, B_EVENT_TIMEOUT);
+ }
isdnport=mISDNport->b_port[i];
if (isdnport)
{
/* turn on RX */
isdnport->p_m_txdata = 1;
PDEBUG(DEBUG_BCHANNEL, "%s: transmit data is required, so we turn them on\n");
+#ifndef OLD_MISDN
if (mISDNport->b_port[i] && mISDNport->b_state[i] == B_STATE_ACTIVE)
ph_control(mISDNport, isdnport, mISDNport->b_addr[isdnport->p_m_b_index], CMX_TXDATA_ON, 0, "DSP-TXDATA", 1);
+#endif
return(1);
}
} else
/* turn off RX */
isdnport->p_m_txdata = 0;
PDEBUG(DEBUG_BCHANNEL, "%s: transmit data is not required, so we turn them off\n");
+#ifndef OLD_MISDN
if (mISDNport->b_port[i] && mISDNport->b_state[i] == B_STATE_ACTIVE)
ph_control(mISDNport, isdnport, mISDNport->b_addr[isdnport->p_m_b_index], CMX_TXDATA_OFF, 0, "DSP-TXDATA", 0);
+#endif
return(1);
}
}
if (!mISDNport)
{
PERROR("message belongs to no mISDNport: prim(0x%x) addr(0x%x) msg->len(%d)\n", frm->prim, frm->addr, msg->len);
+ // show a list of all mISDNports and their address
+#if 0
+ mISDNport = mISDNport_first;
+ while(mISDNport)
+ {
+ PERROR(" port %s %x -> %x\n", mISDNport->name, (frm->addr&MASTER_ID_MASK), (unsigned int)(mISDNport->upper_id&MASTER_ID_MASK));
+ mISDNport = mISDNport->next;
+ }
+#endif
goto out;
}