{
/* init trace with given values */
start_trace(mISDNport?mISDNport->portnum:0,
- mISDNport?mISDNport->ifport->interface:NULL,
+ (mISDNport)?((mISDNport->ifport)?mISDNport->ifport->interface:NULL):NULL,
port?numberrize_callerinfo(port->p_callerinfo.id, port->p_callerinfo.ntype):NULL,
- port?port->p_dialinginfo.number:NULL,
+ port?port->p_dialinginfo.id:NULL,
direction,
CATEGORY_CH,
port?port->p_serial:0,
start_trace(mISDNport?mISDNport->portnum:0,
mISDNport?mISDNport->ifport->interface:NULL,
port?numberrize_callerinfo(port->p_callerinfo.id, port->p_callerinfo.ntype):NULL,
- port?port->p_dialinginfo.number:NULL,
+ port?port->p_dialinginfo.id:NULL,
direction,
CATEGORY_CH,
port?port->p_serial:0,
mISDN_pid_t pid;
int ret;
- if (mISDNport->b_stid[i])
+ if (!mISDNport->b_stid[i])
{
- PERROR("Error: no stack for index");
- return(-1);
+ PERROR("Error: no stack for index %d\n", i);
+ return(0);
}
if (mISDNport->b_addr[i])
{
- PERROR("Error: stack already created");
- return(-1);
+ PERROR("Error: stack already created for index %d\n", i);
+ return(0);
}
/* create new layer */
goto stack_error;
chan_trace_header(mISDNport, mISDNport->b_port[i], "BCHANNEL create stack", DIRECTION_OUT);
add_trace("channel", NULL, "%d", i+1+(i>=15));
- add_trace("stack", "id", "%d", mISDNport->b_stid[i]);
- add_trace("stack", "address", "%d", mISDNport->b_addr[i]);
+ add_trace("stack", "id", "0x%8x", mISDNport->b_stid[i]);
+ add_trace("stack", "address", "0x%8x", mISDNport->b_addr[i]);
end_trace();
- return(0);
+ return(1);
failed:
mISDNport->b_addr[i] = 0;
- return(-1);
+ return(0);
}
chan_trace_header(mISDNport, mISDNport->b_port[i], "BCHANNEL remove stack", DIRECTION_OUT);
add_trace("channel", NULL, "%d", i+1+(i>=15));
- add_trace("stack", "id", "%d", mISDNport->b_stid[i]);
- add_trace("stack", "address", "%d", mISDNport->b_addr[i]);
+ add_trace("stack", "id", "0x%8x", mISDNport->b_stid[i]);
+ add_trace("stack", "address", "0x%8x", mISDNport->b_addr[i]);
end_trace();
/* remove our stack only if set */
PDEBUG(DEBUG_BCHANNEL, "free stack (b_addr=0x%x)\n", mISDNport->b_addr[i]);
void bchannel_event(struct mISDNport *mISDNport, int i, int event)
{
int state = mISDNport->b_state[i];
-
+
+printf("event=%d state=%d\n", event, state);
switch(event)
{
case B_EVENT_ACTIVATE:
- /* port may not be used by any other bchannel */
- if (mISDNport->b_port[i])
+ /* port must be linked in order to allow activation */
+ if (!mISDNport->b_port[i])
{
- PERROR("SOFTWARE ERROR: bchannel must not be linked to a Port class\n");
+ PERROR("SOFTWARE ERROR: bchannel must be linked to a Port class\n");
exit(-1);
}
switch(state)
inbuffer = (p_m_fromup_buffer_writep - p_m_fromup_buffer_readp) & FROMUP_BUFFER_MASK;
/* send tone data to isdn device only if we have data */
- if (p_tone_fh>=0 || p_tone_fetched || p_m_crypt_msg_loops || inbuffer)
+ if (p_tone_name[0] || p_m_crypt_msg_loops || inbuffer)
{
/* calculate how much to transmit */
if (!p_last_tv_sec)
}
if (elapsed >= ISDN_TRANSMIT)
{
- unsigned char buf[mISDN_HEADER_LEN+ISDN_PRELOAD], *p = buf;
+ unsigned char buf[mISDN_HEADER_LEN+ISDN_PRELOAD];
iframe_t *frm = (iframe_t *)buf;
+ unsigned char *p = buf+mISDN_HEADER_LEN;
p_last_tv_sec = now_tv.tv_sec;
p_last_tv_msec = now_tv.tv_usec/1000;
- /* read tones */
+ /* read tones or fill with silence */
length = read_audio(p, elapsed);
/*
*/
if (inbuffer)
{
+ printf("nix\n");
/* inbuffer might be less than we skip due to audio */
if (inbuffer <= length)
{
/* overwrite buffer with crypto stuff */
if (p_m_crypt_msg_loops)
{
+ printf("nix2\n");
/* send pending message */
int tosend;
length = tosend;
/* copy message (part) to buffer */
- memcpy(buf, p_m_crypt_msg+p_m_crypt_msg_current, tosend);
+ memcpy(p, p_m_crypt_msg+p_m_crypt_msg_current, tosend);
p_m_crypt_msg_current += tosend;
if (p_m_crypt_msg_current == p_m_crypt_msg_len)
{
frm->addr = p_m_mISDNport->b_addr[p_m_b_index] | FLG_MSG_DOWN;
frm->dinfo = 0;
frm->len = length;
- memcpy(&frm->data.p, buf, length);
mISDN_write(mISDNdevice, frm, mISDN_HEADER_LEN+frm->len, TIMEOUT_1SEC);
if (p_debug_nothingtosend)
* the call is connected OR tones feature is enabled.
*/
if (p_state!=PORT_STATE_CONNECT
- && !p_m_mISDNport->is_tones)
+ && !p_m_mISDNport->tones)
return;
#if 0
mISDNport = mISDNport->next;
}
+ /* no device, no read */
+ if (mISDNdevice < 0)
+ return(0);
+
/* get message from kernel */
if (!(msg = alloc_msg(MAX_MSG_SIZE)))
return(1);
/* global prim */
switch(frm->prim)
{
+ case MGR_DELLAYER | CONFIRM:
case MGR_INITTIMER | CONFIRM:
case MGR_ADDTIMER | CONFIRM:
case MGR_DELTIMER | CONFIRM:
/*
* global function to add a new card (port)
*/
-struct mISDNport *mISDNport_open(int port, int ptp, int ptmp)
+struct mISDNport *mISDNport_open(int port, int ptp, int ptmp, struct interface *interface)
{
int ret;
unsigned char buff[1025];
/* add mISDNport structure */
mISDNportp = &mISDNport_first;
while(*mISDNportp)
- mISDNportp = &mISDNport->next;
+ mISDNportp = &((*mISDNportp)->next);
mISDNport = (struct mISDNport *)calloc(1, sizeof(struct mISDNport));
if (!mISDNport)
{
PDEBUG(DEBUG_BCHANNEL, "using 'mISDN_dsp.o' module\n");
start_trace(mISDNport->portnum,
- mISDNport->ifport->interface,
+ interface,
NULL,
NULL,
DIRECTION_NONE,
port = port->next;
}
- start_trace(mISDNport->portnum,
- mISDNport->ifport->interface,
- NULL,
- NULL,
- DIRECTION_NONE,
- CATEGORY_CH,
- 0,
- "PORT (close)");
- end_trace();
+ /* only if we are already part of interface */
+ if (mISDNport->ifport)
+ {
+ start_trace(mISDNport->portnum,
+ mISDNport->ifport->interface,
+ NULL,
+ NULL,
+ DIRECTION_NONE,
+ CATEGORY_CH,
+ 0,
+ "PORT (close)");
+ end_trace();
+ }
/* free bchannels */
i = 0;
while(i < mISDNport->b_num)
{
- if (mISDNport->b_stid[i])
+ if (mISDNport->b_addr[i])
{
_bchannel_destroy(mISDNport, i);
PDEBUG(DEBUG_BCHANNEL, "freeing %s port %d bchannel (index %d).\n", (mISDNport->ntmode)?"NT":"TE", mISDNport->portnum, i);
PDEBUG(DEBUG_BCHANNEL, "freeing d-stack.\n");
if (mISDNport->d_stid)
{
-// mISDN_clear_stack(mISDNdevice, mISDNport->d_stid);
- if (mISDNport->lower_id)
- mISDN_write_frame(mISDNdevice, buf, mISDNport->lower_id, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
+ if (mISDNport->upper_id)
+ mISDN_write_frame(mISDNdevice, buf, mISDNport->upper_id | FLG_MSG_DOWN, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
}
/* remove from list */
if (*mISDNportp == mISDNport)
{
*mISDNportp = (*mISDNportp)->next;
+ mISDNportp = NULL;
break;
}
mISDNportp = &((*mISDNportp)->next);
}
- if (!(*mISDNportp))
+ if (mISDNportp)
{
PERROR("software error, mISDNport not in list\n");
exit(-1);