X-Git-Url: http://git.eversberg.eu/gitweb.cgi?p=lcr.git;a=blobdiff_plain;f=dss1.cpp;h=8f23c743db813282a6147f35106b64f022e074b1;hp=cbfc82238941272c0e871e24dea6df45d35fac69;hb=bf3c4d173ad6ecf845de2d9e6d11ab87769d0943;hpb=559ff64e3062b70f27ddceba825f40642a6c5725 diff --git a/dss1.cpp b/dss1.cpp index cbfc822..8f23c74 100644 --- a/dss1.cpp +++ b/dss1.cpp @@ -34,9 +34,9 @@ extern "C" { /* * constructor */ -Pdss1::Pdss1(int type, mISDNport *mISDNport, char *portname, struct port_settings *settings, int channel, int exclusive) : PmISDN(type, mISDNport, portname, settings, channel, exclusive) +Pdss1::Pdss1(int type, struct mISDNport *mISDNport, char *portname, struct port_settings *settings, int channel, int exclusive) : PmISDN(type, mISDNport, portname, settings, channel, exclusive) { - p_callerinfo.itype = (mISDNport->ifport->interface->extension)?INFO_ITYPE_ISDN:INFO_ITYPE_ISDN_EXTENSION; + p_callerinfo.itype = (mISDNport->ifport->interface->extension)?INFO_ITYPE_ISDN_EXTENSION:INFO_ITYPE_ISDN; p_m_d_ntmode = mISDNport->ntmode; p_m_d_l3id = 0; p_m_d_ces = -1; @@ -45,7 +45,6 @@ Pdss1::Pdss1(int type, mISDNport *mISDNport, char *portname, struct port_setting p_m_d_collect_cause = CAUSE_NOUSER; p_m_d_collect_location = LOCATION_PRIVATE_LOCAL; - PDEBUG(DEBUG_ISDN, "Created new mISDNPort(%s). Currently %d objects use, %s port #%d\n", portname, mISDNport->use, (mISDNport->ntmode)?"NT":"TE", p_m_portnum); } @@ -76,7 +75,6 @@ Pdss1::~Pdss1() */ static 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; @@ -84,132 +82,44 @@ static msg_t *create_l3msg(int prim, int mt, int dinfo, int size, int ntmode) if (!ntmode) size = sizeof(Q931_info_t)+2; - while(i < 10) + if (ntmode) { - if (ntmode) + dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL); + if (dmsg) { - dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL); - if (dmsg) - { - return(dmsg); - } - } else + return(dmsg); + } + } else + { + dmsg = alloc_msg(size+256+mISDN_HEADER_LEN+DEFAULT_HEADROOM); + if (dmsg) { - 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); - } + 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); } - - if (!i) - PERROR("cannot allocate memory, trying again...\n"); - i++; - usleep(50000); } - PERROR("cannot allocate memory, system overloaded.\n"); - exit(-1); + + FATAL("Cannot allocate memory, system overloaded.\n"); + exit(0); // make gcc happy } msg_t *create_l2msg(int prim, int dinfo, int size) /* NT only */ { - int i = 0; msg_t *dmsg; - while(i < 10) - { - dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL); - if (dmsg) - return(dmsg); - - if (!i) - PERROR("cannot allocate memory, trying again...\n"); - i++; - usleep(50000); - } - PERROR("cannot allocate memory, system overloaded.\n"); - exit(-1); -} - - -/* isdn messaging */ -static struct isdn_message { - char *name; - unsigned long value; -} isdn_message[] = { - {"TIMEOUT", CC_TIMEOUT}, - {"SETUP", CC_SETUP}, - {"SETUP_ACKNOWLEDGE", CC_SETUP_ACKNOWLEDGE}, - {"PROCEEDING", CC_PROCEEDING}, - {"ALERTING", CC_ALERTING}, - {"CONNECT", CC_CONNECT}, - {"CONNECT RESPONSE", CC_CONNECT}, - {"CONNECT_ACKNOWLEDGE", CC_CONNECT_ACKNOWLEDGE}, - {"DISCONNECT", CC_DISCONNECT}, - {"RELEASE", CC_RELEASE}, - {"RELEASE_COMPLETE", CC_RELEASE_COMPLETE}, - {"INFORMATION", CC_INFORMATION}, - {"PROGRESS", CC_PROGRESS}, - {"NOTIFY", CC_NOTIFY}, - {"SUSPEND", CC_SUSPEND}, - {"SUSPEND_ACKNOWLEDGE", CC_SUSPEND_ACKNOWLEDGE}, - {"SUSPEND_REJECT", CC_SUSPEND_REJECT}, - {"RESUME", CC_RESUME}, - {"RESUME_ACKNOWLEDGE", CC_RESUME_ACKNOWLEDGE}, - {"RESUME_REJECTE", CC_RESUME_REJECT}, - {"HOLD", CC_HOLD}, - {"HOLD_ACKNOWLEDGE", CC_HOLD_ACKNOWLEDGE}, - {"HOLD_REJECT", CC_HOLD_REJECT}, - {"RETRIEVE", CC_RETRIEVE}, - {"RETRIEVE_ACKNOWLEDGE", CC_RETRIEVE_ACKNOWLEDGE}, - {"RETRIEVE_REJECTE", CC_RETRIEVE_REJECT}, - {"FACILITY", CC_FACILITY}, - {"STATUS", CC_STATUS}, - {"RESTART", CC_RESTART}, - {"RELEASE_CR", CC_RELEASE_CR}, - {"NEW_CR", CC_NEW_CR}, - - {NULL, 0}, -}; - -static char *isdn_prim[4] = { - "REQUEST", - "CONFIRM", - "INDICATION", - "RESPONSE", -}; - - -/* - * show message to debug - */ -void Pdss1::isdn_show_send_message(unsigned long prim, msg_t *msg) -{ - int i; - char *msgtext = "<>"; - char *primtext; + dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL); + if (dmsg) + return(dmsg); - i = 0; - while(isdn_message[i].name) - { - if (isdn_message[i].value == (prim&0xffffff00)) - { - msgtext = isdn_message[i].name; - break; - } - i++; - } - primtext = isdn_prim[prim&0x00000003]; - printisdn(">>> outgoing prim: %s %s (0x%x)\n", msgtext, primtext, prim); + FATAL("Cannot allocate memory, system overloaded.\n"); + exit(0); // make gcc happy } - /* * if we received a first reply to the setup message, * we will check if we have now channel information @@ -223,7 +133,7 @@ int Pdss1::received_first_reply_to_setup(unsigned long prim, int channel, int ex RELEASE_COMPLETE_t *release_complete; msg_t *dmsg; - /* corret exclusive to 0, if no explicit channel was given */ + /* correct exclusive to 0, if no explicit channel was given */ if (exclusive<0 || channel<=0) exclusive = 0; @@ -236,16 +146,25 @@ int Pdss1::received_first_reply_to_setup(unsigned long prim, int channel, int ex if (p_state != PORT_STATE_OUT_SETUP) return(0); + chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE); + add_trace("channel", "request", "%d (forced)", p_m_b_channel); + add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel); + /* if give channel not accepted or not equal */ if (channel!=-1 && p_m_b_channel!=channel) { - PDEBUG(DEBUG_BCHANNEL, "- our forced channel %d was not accepted\n", p_m_b_channel); + add_trace("conclusion", NULL, "forced channel not accepted"); + end_trace(); ret = -44; goto channelerror; } + add_trace("conclusion", NULL, "channel was accepted"); + add_trace("connect", "channel", "%d", p_m_b_channel); + end_trace(); + /* activate our exclusive channel */ - bchannel_activate(p_m_mISDNport, p_m_b_index); + bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_ACTIVATE); } else if (p_m_b_channel) { @@ -255,35 +174,45 @@ int Pdss1::received_first_reply_to_setup(unsigned long prim, int channel, int ex if (p_state != PORT_STATE_OUT_SETUP) return(0); + chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE); + add_trace("channel", "request", "%d (suggest)", p_m_b_channel); + add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel); + /* if channel was accepted as given */ if (channel==-1 || p_m_b_channel==channel) { - PDEBUG(DEBUG_BCHANNEL, "- our suggested channel %d was accpted\n", p_m_b_channel); + add_trace("conclusion", NULL, "channel was accepted as given"); + add_trace("connect", "channel", "%d", p_m_b_channel); + end_trace(); p_m_b_exclusive = 1; // we are done - bchannel_activate(p_m_mISDNport, p_m_b_index); + bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_ACTIVATE); return(0); } /* if channel value is faulty */ if (channel <= 0) { - PDEBUG(DEBUG_BCHANNEL, "- our suggested channel %d was replied with no channel value.\n", p_m_b_channel); + add_trace("conclusion", NULL, "illegal reply"); + end_trace(); ret = -111; // protocol error goto channelerror; } /* if channel was not accepted, try to get it */ - PDEBUG(DEBUG_BCHANNEL, "- our suggested channel %d was not accepted, but %d was given.\n", p_m_b_channel, channel); ret = seize_bchannel(channel, 1); // exclusively + add_trace("channel", "available", ret<0?"no":"yes"); if (ret < 0) { - PDEBUG(DEBUG_BCHANNEL, "- the replied channel %d is not available (cause %d).\n", channel, -ret); + add_trace("conclusion", NULL, "replied channel not available"); + end_trace(); goto channelerror; } - PDEBUG(DEBUG_BCHANNEL, "- we accepted channel %d.\n", channel); + add_trace("conclusion", NULL, "replied channel accepted"); + add_trace("connect", "channel", "%d", p_m_b_channel); + end_trace(); /* activate channel given by remote */ - bchannel_activate(p_m_mISDNport, p_m_b_index); + bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_ACTIVATE); } else if (p_m_b_reserve) { @@ -293,26 +222,33 @@ int Pdss1::received_first_reply_to_setup(unsigned long prim, int channel, int ex if (p_state != PORT_STATE_OUT_SETUP) return(0); - /* if no channel was given */ + chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE); + add_trace("channel", "request", "any"); + add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel); + /* if no channel was replied */ if (channel <= 0) { - PDEBUG(DEBUG_BCHANNEL, "- our channel request was not replied by a channel.\n", p_m_b_channel); + add_trace("conclusion", NULL, "no channel, protocol error"); + end_trace(); ret = -111; // protocol error goto channelerror; } /* we will see, if our received channel is available */ - PDEBUG(DEBUG_BCHANNEL, "- our channel request was replied with channel %d.\n", channel); ret = seize_bchannel(channel, 1); // exclusively + add_trace("channel", "available", ret<0?"no":"yes"); if (ret < 0) { - PDEBUG(DEBUG_BCHANNEL, "- the replied channel %d is not available (cause %d).\n", channel, -ret); + add_trace("conclusion", NULL, "replied channel not available"); + end_trace(); goto channelerror; } - PDEBUG(DEBUG_BCHANNEL, "- we accepted channel %d.\n", channel); + add_trace("conclusion", NULL, "replied channel accepted"); + add_trace("connect", "channel", "%d", p_m_b_channel); + end_trace(); /* activate channel given by remote */ - bchannel_activate(p_m_mISDNport, p_m_b_index); + bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_ACTIVATE); } else { /*** we sent 'no channel available' ***/ @@ -320,22 +256,28 @@ int Pdss1::received_first_reply_to_setup(unsigned long prim, int channel, int ex /* if not the first reply, but a connect, we are forced */ if (prim==(CC_CONNECT | INDICATION) && p_state!=PORT_STATE_OUT_SETUP) { + chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (connect)", DIRECTION_NONE); + add_trace("channel", "request", "no-channel"); + add_trace("channel", "reply", (channel>=0)?"%d%s":"(none)", channel, exclusive?" (forced)":""); if (channel > 0) { - PDEBUG(DEBUG_BCHANNEL, "- while call-waiting, we get a channel inside connect message, so we use it.\n", p_m_b_channel); goto use_from_connect; } - PDEBUG(DEBUG_BCHANNEL, "- there is no channel inside connect message during call-waiting, so we request one.\n", p_m_b_channel); ret = seize_bchannel(CHANNEL_ANY, 0); // any channel + add_trace("channel", "available", ret<0?"no":"yes"); if (ret < 0) { - PDEBUG(DEBUG_BCHANNEL, "- during call-waiting, we got a connect, but no available channel (cause=%d).\n", -ret); + add_trace("conclusion", NULL, "no channel available during call-waiting"); + end_trace(); goto channelerror; } + add_trace("conclusion", NULL, "using channel %d", p_m_b_channel); + add_trace("connect", "channel", "%d", p_m_b_channel); + end_trace(); p_m_b_exclusive = 1; // we are done /* activate channel given by remote */ - bchannel_activate(p_m_mISDNport, p_m_b_index); + bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_ACTIVATE); return(0); } @@ -343,36 +285,43 @@ int Pdss1::received_first_reply_to_setup(unsigned long prim, int channel, int ex if (p_state != PORT_STATE_OUT_SETUP) return(0); + chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE); + add_trace("channel", "request", "no-channel"); + add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel); /* if first reply has no channel, we are done */ if (channel <= 0) { - PDEBUG(DEBUG_BCHANNEL, "- while call-waiting, we got no channel as first reply, this is good.\n"); + add_trace("conclusion", NULL, "no channel until connect"); + end_trace(); return(0); } /* we will see, if our received channel is available */ - PDEBUG(DEBUG_BCHANNEL, "- our during call-waiting, we get channel %d as first reply.\n", channel); use_from_connect: ret = seize_bchannel(channel, exclusive); - if (ret <= 0) + add_trace("channel", "available", ret<0?"no":"yes"); + if (ret < 0) { - PDEBUG(DEBUG_BCHANNEL, "- the given channel %d is not available (cause %d).\n", channel, -ret); + add_trace("conclusion", NULL, "replied channel not available"); + end_trace(); goto channelerror; } - PDEBUG(DEBUG_BCHANNEL, "- we accepted channel %d.\n", channel); + add_trace("conclusion", NULL, "replied channel accepted"); + add_trace("connect", "channel", "%d", p_m_b_channel); + end_trace(); p_m_b_exclusive = 1; // we are done /* activate channel given by remote */ - bchannel_activate(p_m_mISDNport, p_m_b_index); + bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_ACTIVATE); } return(0); channelerror: dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode); - isdn_show_send_message(CC_RELEASE_COMPLETE | REQUEST, dmsg); - release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen); - enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret); + l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT); + enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret); + end_trace(); msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); new_state(PORT_STATE_RELEASE); p_m_delete = 1; @@ -381,6 +330,135 @@ int Pdss1::received_first_reply_to_setup(unsigned long prim, int channel, int ex /* + * hunt bchannel for incomming setup or retrieve or resume + */ +int Pdss1::hunt_bchannel(int channel, int exclusive) +{ + struct select_channel *selchannel; + struct interface_port *ifport = p_m_mISDNport->ifport; + int i; + + chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (setup)", DIRECTION_NONE); + if (exclusive<0) + exclusive = 0; + if (channel == CHANNEL_NO) + add_trace("channel", "request", "no-channel"); + else + add_trace("channel", "request", (channel>0)?"%d%s":"any", channel, exclusive?" (forced)":""); + if (channel==CHANNEL_NO && p_type==PORT_TYPE_DSS1_TE_IN) + { + add_trace("conclusion", NULL, "incoming call-waiting not supported for TE-mode"); + end_trace(); + return(-6); // channel unacceptable + } + if (channel <= 0) /* not given, no channel, whatever.. */ + channel = CHANNEL_ANY; /* any channel */ + if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num) // of out chan.. + { + add_trace("channel", "reserved", "%d", p_m_mISDNport->b_reserved); + add_trace("conclusion", NULL, "all channels are reserved"); + end_trace(); + return(-34); // no channel + } + if (channel == CHANNEL_ANY) + goto get_from_list; + if (channel > 0) + { + /* check for given channel in selection list */ + selchannel = ifport->in_channel; + while(selchannel) + { + if (selchannel->channel == channel || selchannel->channel == CHANNEL_FREE) + break; + selchannel = selchannel->next; + } + if (!selchannel) + channel = 0; + + /* exclusive channel requests must be in the list */ + if (exclusive) + { + if (!channel) + { + add_trace("conclusion", NULL, "exclusively requested channel not in list"); + end_trace(); + return(-6); // channel unacceptable + } + i = selchannel->channel-1-(selchannel->channel>=17); + if (p_m_mISDNport->b_port[i] == NULL) + goto use_channel; + add_trace("conclusion", NULL, "exclusively requested channel is busy"); + end_trace(); + return(-6); // channel unacceptable + } + + /* requested channels in list will be used */ + if (channel) + { + i = selchannel->channel-1-(selchannel->channel>=17); + if (p_m_mISDNport->b_port[i] == NULL) + goto use_channel; + } + + /* if channel is not available or not in list, it must be searched */ + get_from_list: + /* check for first free channel in list */ + channel = 0; + selchannel = ifport->in_channel; + while(selchannel) + { + switch(selchannel->channel) + { + case CHANNEL_FREE: /* free channel */ + add_trace("hunting", "channel", "free"); + if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num) + break; /* all channel in use or reserverd */ + /* find channel */ + i = 0; + while(i < p_m_mISDNport->b_num) + { + if (p_m_mISDNport->b_port[i] == NULL) + { + channel = i+1+(i>=15); + break; + } + i++; + } + break; + + default: + add_trace("hunting", "channel", "%d", selchannel->channel); + if (selchannel->channel<1 || selchannel->channel==16) + break; /* invalid channels */ + i = selchannel->channel-1-(selchannel->channel>=17); + if (i >= p_m_mISDNport->b_num) + break; /* channel not in port */ + if (p_m_mISDNport->b_port[i] == NULL) + { + channel = selchannel->channel; + break; + } + break; + } + if (channel) + break; /* found channel */ + selchannel = selchannel->next; + } + if (!channel) + { + add_trace("conclusion", NULL, "no channel available"); + end_trace(); + return(-6); // channel unacceptable + } + } +use_channel: + add_trace("conclusion", NULL, "channel available"); + add_trace("connect", "channel", "%d", channel); + end_trace(); + return(channel); +} + +/* * handles all indications */ /* CC_SETUP INDICATION */ @@ -388,8 +466,11 @@ void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data) { int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN; SETUP_t *setup = (SETUP_t *)((unsigned long)data + headerlen); - int type, plan, present, screen, reason; - int coding, capability, mode, rate, multi, user, presentation, interpretation, hlc, exthlc; + int calling_type, calling_plan, calling_present, calling_screen; + int called_type, called_plan; + int redir_type, redir_plan, redir_present, redir_screen, redir_reason; + int hlc_coding, hlc_presentation, hlc_interpretation, hlc_hlc, hlc_exthlc; + int bearer_coding, bearer_capability, bearer_mode, bearer_rate, bearer_multi, bearer_user; int exclusive, channel; int ret; msg_t *dmsg; @@ -399,25 +480,59 @@ void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data) class Endpoint *epoint; struct message *message; + /* callref from nt-lib */ + if (p_m_d_ntmode) + { + /* nt-library now gives us the id via CC_SETUP */ + if (dinfo&(~0xff) == 0xff00) + FATAL("l3-stack gives us a process id 0xff00-0xffff\n"); + l1l2l3_trace_header(p_m_mISDNport, this, CC_NEW_CR | INDICATION, DIRECTION_IN); + if (p_m_d_l3id) + add_trace("callref", "old", "0x%x", p_m_d_l3id); + add_trace("callref", "new", "0x%x", dinfo); + end_trace(); + if (p_m_d_l3id&(~0xff) == 0xff00) + p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0; + p_m_d_l3id = dinfo; + p_m_d_ces = setup->ces; + } + + l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN); + dec_ie_calling_pn(setup->CALLING_PN, (Q931_info_t *)((unsigned long)data+headerlen), &calling_type, &calling_plan, &calling_present, &calling_screen, (unsigned char *)p_callerinfo.id, sizeof(p_callerinfo.id)); + dec_ie_called_pn(setup->CALLED_PN, (Q931_info_t *)((unsigned long)data+headerlen), &called_type, &called_plan, (unsigned char *)p_dialinginfo.id, sizeof(p_dialinginfo.id)); + dec_ie_keypad(setup->KEYPAD, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)keypad, sizeof(keypad)); +#ifdef CENTREX + /* te-mode: CNIP (calling name identification presentation) */ + if (!p_m_d_ntmode) + dec_facility_centrex(setup->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)p_callerinfo.name, sizeof(p_callerinfo.name)); +#endif + dec_ie_useruser(setup->USER_USER, (Q931_info_t *)((unsigned long)data+headerlen), &useruser_protocol, useruser, &useruser_len); + dec_ie_complete(setup->COMPLETE, (Q931_info_t *)((unsigned long)data+headerlen), &p_dialinginfo.sending_complete); + dec_ie_redir_nr(setup->REDIR_NR, (Q931_info_t *)((unsigned long)data+headerlen), &redir_type, &redir_plan, &redir_present, &redir_screen, &redir_reason, (unsigned char *)p_redirinfo.id, sizeof(p_redirinfo.id)); + dec_ie_channel_id(setup->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel); + dec_ie_hlc(setup->HLC, (Q931_info_t *)((unsigned long)data+headerlen), &hlc_coding, &hlc_interpretation, &hlc_presentation, &hlc_hlc, &hlc_exthlc); + dec_ie_bearer(setup->BEARER, (Q931_info_t *)((unsigned long)data+headerlen), &bearer_coding, &bearer_capability, &bearer_mode, &bearer_rate, &bearer_multi, &bearer_user); + end_trace(); + /* if blocked, release call */ if (p_m_mISDNport->ifport->block) { RELEASE_COMPLETE_t *release_complete; - printlog("--- port#%d is blocked.\n", mISDNport->ifport->portnum); dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode); - isdn_show_send_message(CC_RELEASE_COMPLETE | REQUEST, dmsg); release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen); - enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 27); /* temporary unavailable */ + l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT); + enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 27); /* temporary unavailable */ + add_trace("reason", NULL, "port blocked"); + end_trace(); msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); new_state(PORT_STATE_RELEASE); p_m_delete = 1; return; } - - /* caller information */ - dec_ie_calling_pn(setup->CALLING_PN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, &screen, (unsigned char *)p_callerinfo.id, sizeof(p_callerinfo.id)); - switch (present) + + /* caller info */ + switch (calling_present) { case 1: p_callerinfo.present = INFO_PRESENT_RESTRICTED; @@ -429,7 +544,7 @@ void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data) p_callerinfo.present = INFO_PRESENT_ALLOWED; break; } - switch (screen) + switch (calling_screen) { case 0: p_callerinfo.screen = INFO_SCREEN_USER; @@ -438,7 +553,7 @@ void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data) p_callerinfo.screen = INFO_SCREEN_NETWORK; break; } - switch (type) + switch (calling_type) { case -1: p_callerinfo.ntype = INFO_NTYPE_UNKNOWN; @@ -459,11 +574,11 @@ void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data) break; } p_callerinfo.isdn_port = p_m_portnum; + SCPY(p_callerinfo.interface, p_m_mISDNport->ifport->interface->name); + /* dialing information */ - dec_ie_called_pn(setup->CALLED_PN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, (unsigned char *)p_dialinginfo.number, sizeof(p_dialinginfo.number)); - dec_ie_keypad(setup->KEYPAD, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)keypad, sizeof(keypad)); - SCAT(p_dialinginfo.number, (char *)keypad); - switch (type) + SCAT(p_dialinginfo.id, (char *)keypad); + switch (called_type) { case 0x1: p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL; @@ -478,20 +593,9 @@ void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data) p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN; break; } -#ifdef CENTREX - /* te-mode: CNIP (calling name identification presentation) */ - if (!p_m_d_ntmode) - dec_facility_centrex(setup->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)p_callerinfo.name, sizeof(p_callerinfo.name)); -#endif - /* uus */ - dec_ie_useruser(setup->USER_USER, (Q931_info_t *)((unsigned long)data+headerlen), &useruser_protocol, useruser, &useruser_len); - - /* sending complete */ - dec_ie_complete(setup->COMPLETE, (Q931_info_t *)((unsigned long)data+headerlen), &p_dialinginfo.sending_complete); - /* redirecting number */ - dec_ie_redir_nr(setup->REDIR_NR, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, &screen, &reason, (unsigned char *)p_redirinfo.id, sizeof(p_redirinfo.id)); - switch (present) + /* redir info */ + switch (redir_present) { case 1: p_redirinfo.present = INFO_PRESENT_RESTRICTED; @@ -503,7 +607,7 @@ void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data) p_redirinfo.present = INFO_PRESENT_ALLOWED; break; } - switch (screen) + switch (redir_screen) { case 0: p_redirinfo.screen = INFO_SCREEN_USER; @@ -512,7 +616,7 @@ void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data) p_redirinfo.screen = INFO_SCREEN_NETWORK; break; } - switch (reason) + switch (redir_reason) { case 1: p_redirinfo.reason = INFO_REDIR_BUSY; @@ -533,7 +637,7 @@ void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data) p_redirinfo.reason = INFO_REDIR_UNKNOWN; break; } - switch (type) + switch (redir_type) { case -1: p_redirinfo.ntype = INFO_NTYPE_UNKNOWN; @@ -554,19 +658,19 @@ void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data) break; } p_redirinfo.isdn_port = p_m_portnum; + /* bearer capability */ - dec_ie_bearer(setup->BEARER, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &capability, &mode, &rate, &multi, &user); - switch (capability) + switch (bearer_capability) { case -1: p_capainfo.bearer_capa = INFO_BC_AUDIO; - user = (options.law=='a')?3:2; + bearer_user = (options.law=='a')?3:2; break; default: - p_capainfo.bearer_capa = capability; + p_capainfo.bearer_capa = bearer_capability; break; } - switch (mode) + switch (bearer_mode) { case 2: p_capainfo.bearer_mode = INFO_BMODE_PACKET; @@ -575,277 +679,73 @@ void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data) p_capainfo.bearer_mode = INFO_BMODE_CIRCUIT; break; } - switch (user) + switch (bearer_user) { case -1: p_capainfo.bearer_info1 = INFO_INFO1_NONE; break; default: - p_capainfo.bearer_info1 = user + 0x80; + p_capainfo.bearer_info1 = bearer_user + 0x80; break; } /* hlc */ - dec_ie_hlc(setup->HLC, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &interpretation, &presentation, &hlc, &exthlc); - switch (hlc) + switch (hlc_hlc) { case -1: p_capainfo.hlc = INFO_HLC_NONE; break; default: - p_capainfo.hlc = hlc + 0x80; + p_capainfo.hlc = hlc_hlc + 0x80; break; } - switch (exthlc) + switch (hlc_exthlc) { case -1: p_capainfo.exthlc = INFO_HLC_NONE; break; - default: - p_capainfo.exthlc = exthlc + 0x80; - break; - } - - /* channel_id */ - dec_ie_channel_id(setup->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel); - if (exclusive<0) - exclusive = 0; - if (channel==CHANNEL_NO && p_type==PORT_TYPE_DSS1_TE_IN) - PDEBUG(DEBUG_BCHANNEL, "- no channel is given by the network, causing to fail, since CW is not possible for external lines\n"); - if (channel <= 0) /* not given, no channel, whatever.. */ - channel = CHANNEL_ANY; /* any channel */ - if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num) // of out chan.. - { - printlog("--- port#%d all channels are used/reserved.\n", ifport->portnum); - ret = -34; // no channel - goto no_channel; - } - if (channel == CHANNE_ANY) - { - PDEBUG(DEBUG_BCHANNEL, "- any channel is assumed from the %s, so we need to return the a channel from our list\n", (p_m_d_ntmode)?"user":"network"); - /* check for any channel form selection list */ - channel = 0; - selchannel = ifport->channel_in; - while(selchannel) - { - switch(selchannel->channel) - { - case CHANNEL_FREE: /* free channel */ - if (mISDNport->b_inuse >= mISDNport->b_num) - break; /* all channel in use or reserverd */ - /* find channel */ - i = 0; - while(i < mISDNport->b_num) - { - if (mISDNport->b_port[i] == NULL) - { - channel = i+1+(i>=15); - printlog("--- port#%d no channel given, so selecting free channel %d\n", ifport->portnum, channel); - break; - } - i++; - } - break; - - default: - if (selchannel->channel<1 || selchannel->channel==16) - break; /* invalid channels */ - i = selchannel->channel-1-(selchannel->channel>=17); - if (i >= mISDNport->b_num) - break; /* channel not in port */ - if (mISDNport->b_port[i] == NULL) - { - channel = selchannel->channel; - printlog("--- port#%d no channel given, so selecting channel %d from list\n", ifport->portnum, channel); - break; - } - break; - } - if (channel) - break; /* found channel */ - selchannel = selchannel->next; - } - if (!channel) - { - printlog("--- port#%d no channel found.\n", ifport->portnum); - ret = -34; // no channel - goto no_channel; - } - goto use_channel; - } - if (channel > 0) - { - /* check for given channel in selection list */ - selchannel = ifport->channel_in; - while(selchannel) - { - if (selchannel->channel == channel || selchannel->channel == CHANNEL_FREE) - break; - selchannel = selchannel->next; - } - if (!selchannel) - channel = 0; - - /* exclusive channel requests must be in the list */ - if (exclusive) - { - if (!channel) - { - PDEBUG(DEBUG_BCHANNEL, "- exclusive channel %d is selected, but not in list of incomming channel.\n", channel); - printlog("--- port#%d channel %d given exclusively, it is accepted.\n", ifport->portnum, channel); - ret = 6; // unacceptable - goto no_channel; - } - PDEBUG(DEBUG_BCHANNEL, "- exclusive channel %d is selected, as in list of incomming channels.\n", channel); - i = selchannel->channel-1-(selchannel->channel>=17); - if (mISDNport->b_port[i] == NULL) - { - printlog("--- port#%d channel %d given exclusively, it is accepted and free.\n", ifport->portnum, channel); - goto use_channel; - } - printlog("--- port#%d channel %d given exclusively, it is accepted, but busy.\n", ifport->portnum, channel); - ret = 6; // unacceptable - goto no_channel; - } - - /* requested channels in list will be used */ - if (channel) - { - PDEBUG(DEBUG_BCHANNEL, "- channel %d given, found in list.\n", channel); - i = selchannel->channel-1-(selchannel->channel>=17); - if (mISDNport->b_port[i] == NULL) - { - printlog("--- port#%d channel %d given, it is accepted and free.\n", ifport->portnum, channel); - goto use_channel; - } - } - - /* if channel is not available or not in list, it must be searched */ - PDEBUG(DEBUG_BCHANNEL, "- channel %d given, but not in list of incomming channels.\n", channel); - - /* check for first free channel in list */ - channel = 0; - selchannel = ifport->channel_in; - while(selchannel) - { - switch(selchannel->channel) - { - case CHANNEL_FREE: /* free channel */ - if (mISDNport->b_inuse >= mISDNport->b_num) - break; /* all channel in use or reserverd */ - /* find channel */ - i = 0; - while(i < mISDNport->b_num) - { - if (mISDNport->b_port[i] == NULL) - { - channel = i+1+(i>=15); - printlog("--- port#%d requested channel was not in list, so using free channel %d from list.\n", ifport->portnum, channel); - break; - } - i++; - } - break; - - default: - if (selchannel->channel<1 || selchannel->channel==16) - break; /* invalid channels */ - i = selchannel->channel-1-(selchannel->channel>=17); - if (i >= mISDNport->b_num) - break; /* channel not in port */ - if (mISDNport->b_port[i] == NULL) - { - channel = selchannel->channel; - printlog("--- port#%d requested channel was not in list, so using free channel %d from list.\n", ifport->portnum, channel); - break; - } - break; - } - if (channel) - break; /* found channel */ - selchannel = selchannel->next; - } - if (!channel) - { - printlog("--- port#%d no channel found.\n", ifport->portnum); - ret = 6; // unacceptable - goto no_channel; - } + default: + p_capainfo.exthlc = hlc_exthlc + 0x80; + break; } + /* hunt channel */ + ret = channel = hunt_bchannel(channel, exclusive); + if (ret < 0) + goto no_channel; + /* open channel */ - use_channel: ret = seize_bchannel(channel, 1); if (ret < 0) { no_channel: - PDEBUG(DEBUG_BCHANNEL, "- channel is not available (cause=%d), so we send a release_complete.\n", -ret); RELEASE_COMPLETE_t *release_complete; dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode); - isdn_show_send_message(CC_RELEASE_COMPLETE | REQUEST, dmsg); release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen); - enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret); + l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT); + enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret); + end_trace(); msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); new_state(PORT_STATE_RELEASE); p_m_delete = 1; return; } - PDEBUG(DEBUG_BCHANNEL, "- channel is available, we open channel %d.\n", ret); - bchannel_activate(p_m_mISDNport, p_m_b_index); + bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_ACTIVATE); /* create endpoint */ if (p_epointlist) - { - PERROR("SOFTWARE ERROR: incoming call but already got an endpoint, exitting...\n"); - exit(-1); - } - if (!(epoint = new Endpoint(p_serial, 0))) - { - RELEASE_COMPLETE_t *release_complete; - - dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode); - isdn_show_send_message(CC_RELEASE_COMPLETE | REQUEST, dmsg); - release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen); - enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 41); /* temporary failure */ - msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); - new_state(PORT_STATE_RELEASE); - p_m_delete = 1; - return; - } + FATAL("Incoming call but already got an endpoint.\n"); + if (!(epoint = new Endpoint(p_serial, 0, 0))) + FATAL("No memory for Endpoint instance\n"); if (!(epoint->ep_app = new DEFAULT_ENDPOINT_APP(epoint))) - { - PERROR("no memory for application\n"); - exit(-1); - } - if (!(epointlist_new(epoint->ep_serial))) - { - PERROR("no memory for epointlist\n"); - exit(-1); - } - if (p_m_d_ntmode) - { - /* nt-library now gives us the id via CC_SETUP */ - if (dinfo&(~0xff) == 0xff00) - { - PERROR("fatal software error: l3-stack gives us a process id 0xff00-0xffff\n"); - exit(-1); - } - printisdn(" l3id 0x%x changes to 0x%x\n", p_m_d_l3id, dinfo); - if (p_m_d_l3id&(~0xff) == 0xff00) - p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0; - p_m_d_l3id = dinfo; - p_m_d_ces = setup->ces; - PDEBUG(DEBUG_ISDN, "Pdss1(%s) nt-mode gives us new l3id via setup ind: 0x%x\n", p_name, p_m_d_l3id); - } + FATAL("No memory for Endpoint Application instance\n"); + epointlist_new(epoint->ep_serial); /* send setup message to endpoit */ - PDEBUG(DEBUG_ISDN, "Pdss1(%s) setup: %s->%s\n", p_name, p_callerinfo.id, p_dialinginfo.number); message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_SETUP); message->param.setup.isdn_port = p_m_portnum; message->param.setup.port_type = p_type; - p_callerinfo.isdn_port = p_m_portnum; - SCPY(p_callerinfo.interface, p_m_mISDNport->ifport->interface->name);; memcpy(&message->param.setup.dialinginfo, &p_dialinginfo, sizeof(struct dialing_info)); memcpy(&message->param.setup.callerinfo, &p_callerinfo, sizeof(struct caller_info)); memcpy(&message->param.setup.redirinfo, &p_redirinfo, sizeof(struct redir_info)); @@ -867,10 +767,13 @@ void Pdss1::information_ind(unsigned long prim, unsigned long dinfo, void *data) unsigned char keypad[32] = ""; struct message *message; - /* dialing information */ - dec_ie_called_pn(information->CALLED_PN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, (unsigned char *)p_dialinginfo.number, sizeof(p_dialinginfo.number)); + l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN); + dec_ie_called_pn(information->CALLED_PN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, (unsigned char *)p_dialinginfo.id, sizeof(p_dialinginfo.id)); dec_ie_keypad(information->KEYPAD, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)keypad, sizeof(keypad)); - SCAT(p_dialinginfo.number, (char *)keypad); + dec_ie_complete(information->COMPLETE, (Q931_info_t *)((unsigned long)data+headerlen), &p_dialinginfo.sending_complete); + end_trace(); + + SCAT(p_dialinginfo.id, (char *)keypad); switch (type) { case 0x1: @@ -886,9 +789,6 @@ void Pdss1::information_ind(unsigned long prim, unsigned long dinfo, void *data) p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN; break; } - /* sending complete */ - dec_ie_complete(information->COMPLETE, (Q931_info_t *)((unsigned long)data+headerlen), &p_dialinginfo.sending_complete);; - PDEBUG(DEBUG_ISDN, "Pdss1(%s) more digits: %s\n", p_name,p_dialinginfo.number); message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_INFORMATION); memcpy(&message->param.information, &p_dialinginfo, sizeof(struct dialing_info)); message_put(message); @@ -906,9 +806,12 @@ void Pdss1::setup_acknowledge_ind(unsigned long prim, unsigned long dinfo, void int ret; struct message *message; - /* channel_id */ + l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN); dec_ie_channel_id(setup_acknowledge->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel); dec_ie_progress(setup_acknowledge->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress); + end_trace(); + + /* process channel */ ret = received_first_reply_to_setup(prim, exclusive, channel); if (ret < 0) { @@ -920,6 +823,7 @@ void Pdss1::setup_acknowledge_ind(unsigned long prim, unsigned long dinfo, void p_m_delete = 1; return; } + message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_OVERLAP); message_put(message); @@ -938,9 +842,13 @@ void Pdss1::proceeding_ind(unsigned long prim, unsigned long dinfo, void *data) int notify = -1, type, plan, present; char redir[32]; - /* channel id */ + l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN); dec_ie_channel_id(proceeding->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel); dec_ie_progress(proceeding->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress); + dec_ie_notify(NULL/*proceeding->NOTIFY*/, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify); + dec_ie_redir_dn(proceeding->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)redir, sizeof(redir)); + end_trace(); + ret = received_first_reply_to_setup(prim, exclusive, channel); if (ret < 0) { @@ -957,12 +865,10 @@ void Pdss1::proceeding_ind(unsigned long prim, unsigned long dinfo, void *data) new_state(PORT_STATE_OUT_PROCEEDING); - dec_ie_notify(NULL/*proceeding->NOTIFY*/, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify); if (notify >= 0) notify |= 0x80; else notify = 0; - dec_ie_redir_dn(proceeding->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)redir, sizeof(redir)); if (type >= 0 || notify) { if (!notify && type >= 0) @@ -1019,9 +925,14 @@ void Pdss1::alerting_ind(unsigned long prim, unsigned long dinfo, void *data) int notify = -1, type, plan, present; char redir[32]; - /* channel id */ + l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN); dec_ie_channel_id(alerting->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel); dec_ie_progress(alerting->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress); + dec_ie_notify(NULL/*alerting->NOTIFY*/, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify); + dec_ie_redir_dn(alerting->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)redir, sizeof(redir)); + end_trace(); + + /* process channel */ ret = received_first_reply_to_setup(prim, exclusive, channel); if (ret < 0) { @@ -1038,12 +949,10 @@ void Pdss1::alerting_ind(unsigned long prim, unsigned long dinfo, void *data) new_state(PORT_STATE_OUT_ALERTING); - dec_ie_notify(NULL/*alerting->NOTIFY*/, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify); if (notify >= 0) notify |= 0x80; else notify = 0; - dec_ie_redir_dn(alerting->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)redir, sizeof(redir)); if (type >= 0 || notify) { if (!notify && type >= 0) @@ -1098,15 +1007,22 @@ void Pdss1::connect_ind(unsigned long prim, unsigned long dinfo, void *data) msg_t *dmsg; struct message *message; int bchannel_before; + CONNECT_ACKNOWLEDGE_t *connect_acknowledge; if (p_m_d_ntmode) p_m_d_ces = connect->ces; - /* NOTE: we do not check the connected channel, since we - * ready sent a channel to the remote side - */ - /* channel id */ + l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN); dec_ie_channel_id(connect->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel); + dec_ie_connected_pn(connect->CONNECT_PN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, &screen, (unsigned char *)p_connectinfo.id, sizeof(p_connectinfo.id)); +#ifdef CENTREX + /* te-mode: CONP (connected name identification presentation) */ + if (!p_m_d_ntmode) + dec_facility_centrex(connect->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)p_connectinfo.name, sizeof(p_connectinfo.name)); +#endif + end_trace(); + + /* select channel */ bchannel_before = p_m_b_channel; ret = received_first_reply_to_setup(prim, exclusive, channel); if (ret < 0) @@ -1119,8 +1035,8 @@ void Pdss1::connect_ind(unsigned long prim, unsigned long dinfo, void *data) p_m_delete = 1; return; } + /* connect information */ - dec_ie_connected_pn(connect->CONNECT_PN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, &screen, (unsigned char *)p_connectinfo.id, sizeof(p_connectinfo.id)); switch (present) { case 1: @@ -1162,23 +1078,22 @@ void Pdss1::connect_ind(unsigned long prim, unsigned long dinfo, void *data) break; } p_connectinfo.isdn_port = p_m_portnum; -#ifdef CENTREX - /* te-mode: CONP (connected name identification presentation) */ - if (!p_m_d_ntmode) - dec_facility_centrex(connect->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)p_connectinfo.name, sizeof(p_connectinfo.name)); -#endif - /* send connect acknowledge */ - CONNECT_ACKNOWLEDGE_t *connect_acknowledge; - - dmsg = create_l3msg(CC_CONNECT | RESPONSE, MT_CONNECT, dinfo, sizeof(CONNECT_ACKNOWLEDGE_t), p_m_d_ntmode); - isdn_show_send_message(CC_CONNECT | RESPONSE, dmsg); - connect_acknowledge = (CONNECT_ACKNOWLEDGE_t *)(dmsg->data + headerlen); - /* if we had no bchannel before, we send it now */ - if (!bchannel_before && p_m_b_channel) - enc_ie_channel_id(&connect_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel); - msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); + SCPY(p_connectinfo.interface, p_m_mISDNport->ifport->interface->name); - PDEBUG(DEBUG_ISDN, "Pdss1(%s) connect (to '%s' COLP: '%s')\n", p_name, p_dialinginfo.number, p_connectinfo.id); + /* only in nt-mode we send connect ack. in te-mode it is done by stack itself or optional */ + if (p_m_d_ntmode) + { + /* send connect acknowledge */ + dmsg = create_l3msg(CC_CONNECT | RESPONSE, MT_CONNECT, dinfo, sizeof(CONNECT_ACKNOWLEDGE_t), p_m_d_ntmode); + connect_acknowledge = (CONNECT_ACKNOWLEDGE_t *)(dmsg->data + headerlen); + l1l2l3_trace_header(p_m_mISDNport, this, CC_CONNECT | RESPONSE, DIRECTION_OUT); + /* if we had no bchannel before, we send it now */ + if (!bchannel_before && p_m_b_channel) + enc_ie_channel_id(&connect_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel); + end_trace(); + msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); + } + message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CONNECT); memcpy(&message->param.connectinfo, &p_connectinfo, sizeof(struct connect_info)); message_put(message); @@ -1195,23 +1110,28 @@ void Pdss1::disconnect_ind(unsigned long prim, unsigned long dinfo, void *data) int coding, proglocation, progress; struct message *message; - /* cause */ + l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN); dec_ie_progress(disconnect->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &proglocation, &progress); dec_ie_cause(disconnect->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause); + end_trace(); + if (location == LOCATION_PRIVATE_LOCAL) + location = LOCATION_PRIVATE_REMOTE; + if (cause < 0) cause = 16; - /* release if we are remote sends us no tones */ - if (p_m_mISDNport->is_earlyb) + /* release if remote sends us no tones */ + if (!p_m_mISDNport->earlyb) { RELEASE_t *release; msg_t *dmsg; - PDEBUG(DEBUG_ISDN, "Pdss1(%s) send release because remote disconnects AND provides no patterns (earlyb).\n", p_name); dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, dinfo, sizeof(RELEASE_t), p_m_d_ntmode); - isdn_show_send_message(CC_RELEASE | REQUEST, dmsg); release = (RELEASE_t *)(dmsg->data + headerlen); - enc_ie_cause(&release->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16); /* normal */ + l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE | REQUEST, DIRECTION_OUT); + enc_ie_cause(&release->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16); /* normal */ + add_trace("reason", NULL, "no remote patterns"); + end_trace(); msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); /* sending release to endpoint */ @@ -1257,36 +1177,21 @@ void Pdss1::disconnect_ind_i(unsigned long prim, unsigned long dinfo, void *data int location, cause; /* cause */ + l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN); + if (p_m_d_collect_cause > 0) + { + add_trace("old-cause", "location", "%d", p_m_d_collect_location); + add_trace("old-cause", "value", "%d", p_m_d_collect_cause); + } dec_ie_cause(disconnect->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause); + end_trace(); + if (location == LOCATION_PRIVATE_LOCAL) + location = LOCATION_PRIVATE_REMOTE; /* collect cause */ - PDEBUG(DEBUG_ISDN, "PORT(%d) collecting cause %d location %d.\n", p_serial, cause, location); - if (cause == CAUSE_REJECTED) /* call rejected */ - { - p_m_d_collect_cause = CAUSE_REJECTED; - p_m_d_collect_location = location; - } else - if (cause==CAUSE_NORMAL && p_m_d_collect_cause!=CAUSE_REJECTED) /* reject via hangup */ - { - p_m_d_collect_cause = CAUSE_NORMAL; - p_m_d_collect_location = location; - } else - if (cause==CAUSE_BUSY && p_m_d_collect_cause!=CAUSE_REJECTED && p_m_d_collect_cause!=CAUSE_NORMAL) /* busy */ - { - p_m_d_collect_cause = CAUSE_BUSY; - p_m_d_collect_location = location; - } else - if (cause==CAUSE_OUTOFORDER && p_m_d_collect_cause!=CAUSE_BUSY && p_m_d_collect_cause!=CAUSE_REJECTED && p_m_d_collect_cause!=CAUSE_NORMAL) /* no L1 */ - { - p_m_d_collect_cause = CAUSE_OUTOFORDER; - p_m_d_collect_location = location; - } else - if (cause!=0 && cause!=CAUSE_NOUSER && p_m_d_collect_cause!=CAUSE_OUTOFORDER && p_m_d_collect_cause!=CAUSE_BUSY && p_m_d_collect_cause!=CAUSE_REJECTED && p_m_d_collect_cause!=CAUSE_NORMAL) /* anything if cause exists and not 18 */ - { - p_m_d_collect_cause = cause; - p_m_d_collect_location = location; - } - PDEBUG(DEBUG_ISDN, "PORT(%d) new multipoint cause %d location %d.\n", p_serial, p_m_d_collect_cause, p_m_d_collect_location); + collect_cause(&p_m_d_collect_cause, &p_m_d_collect_location, cause, location); + add_trace("new-cause", "location", "%d", p_m_d_collect_location); + add_trace("new-cause", "value", "%d", p_m_d_collect_cause); } @@ -1299,8 +1204,12 @@ void Pdss1::release_ind(unsigned long prim, unsigned long dinfo, void *data) int location, cause; struct message *message; - /* cause */ + l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN); dec_ie_cause(release->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause); + end_trace(); + if (location == LOCATION_PRIVATE_LOCAL) + location = LOCATION_PRIVATE_REMOTE; + if (cause < 0) cause = 16; @@ -1322,9 +1231,10 @@ void Pdss1::release_ind(unsigned long prim, unsigned long dinfo, void *data) RELEASE_COMPLETE_t *release_complete; dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode); - isdn_show_send_message(CC_RELEASE_COMPLETE | REQUEST, dmsg); release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen); - enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16); + l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT); + enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16); + end_trace(); msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); } @@ -1332,7 +1242,7 @@ void Pdss1::release_ind(unsigned long prim, unsigned long dinfo, void *data) p_m_delete = 1; } -/* CC_RELEASE_COMPLETE INDICATION */ +/* CC_RELEASE_COMPLETE INDICATION (a reject) */ void Pdss1::release_complete_ind(unsigned long prim, unsigned long dinfo, void *data) { int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN; @@ -1340,8 +1250,12 @@ void Pdss1::release_complete_ind(unsigned long prim, unsigned long dinfo, void * int location, cause; struct message *message; - /* cause */ + l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN); dec_ie_cause(release_complete->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause); + end_trace(); + if (location == LOCATION_PRIVATE_LOCAL) + location = LOCATION_PRIVATE_REMOTE; + if (cause < 0) cause = 16; @@ -1356,7 +1270,6 @@ void Pdss1::release_complete_ind(unsigned long prim, unsigned long dinfo, void * free_epointlist(p_epointlist); } - PDEBUG(DEBUG_ISDN, "Pdss1(%s) release_complete (cause %d)\n", p_name, cause); new_state(PORT_STATE_RELEASE); p_m_delete = 1; } @@ -1366,6 +1279,8 @@ void Pdss1::t312_timeout(unsigned long prim, unsigned long dinfo, void *data) { struct message *message; + // trace is done at message_isdn() + /* sending release to endpoint */ while(p_epointlist) { @@ -1377,7 +1292,6 @@ void Pdss1::t312_timeout(unsigned long prim, unsigned long dinfo, void *data) free_epointlist(p_epointlist); } - PDEBUG(DEBUG_ISDN, "Pdss1(%s) t312_timeout (collected cause %d location %d)\n", p_name, p_m_d_collect_cause, p_m_d_collect_location); new_state(PORT_STATE_RELEASE); p_m_delete = 1; } @@ -1390,20 +1304,20 @@ void Pdss1::notify_ind(unsigned long prim, unsigned long dinfo, void *data) struct message *message; int notify, type, plan, present; + l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN); + dec_ie_notify(notifying->NOTIFY, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify); + dec_ie_redir_dn(notifying->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)message->param.notifyinfo.id, sizeof(message->param.notifyinfo.id)); + end_trace(); + if (!ACTIVE_EPOINT(p_epointlist)) - { - PDEBUG(DEBUG_ISDN, "Pdss1(%s) there is no active endpoint to notify to.\n", p_name); return; - } /* notification indicator */ - dec_ie_notify(notifying->NOTIFY, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify); if (notify < 0) return; notify |= 0x80; message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY); message->param.notifyinfo.notify = notify; /* redirection number */ - dec_ie_redir_dn(notifying->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)message->param.notifyinfo.id, sizeof(message->param.notifyinfo.id)); switch (present) { case 1: @@ -1451,15 +1365,17 @@ void Pdss1::hold_ind(unsigned long prim, unsigned long dinfo, void *data) msg_t *dmsg; // class Endpoint *epoint; + l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN); + end_trace(); + if (!ACTIVE_EPOINT(p_epointlist) || p_m_hold) { - - PDEBUG(DEBUG_ISDN, "Pdss1(%s) there is no endpoint to notify hold OR we are already on hold, so we reject.\n", p_name); - dmsg = create_l3msg(CC_HOLD_REJECT | REQUEST, MT_HOLD_REJECT, dinfo, sizeof(HOLD_REJECT_t), p_m_d_ntmode); - isdn_show_send_message(CC_HOLD_REJECT | REQUEST, dmsg); hold_reject = (HOLD_REJECT_t *)(dmsg->data + headerlen); - enc_ie_cause(&hold_reject->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, p_m_hold?101:31); /* normal unspecified / incompatible state */ + l1l2l3_trace_header(p_m_mISDNport, this, CC_HOLD_REJECT | REQUEST, DIRECTION_OUT); + enc_ie_cause(&hold_reject->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, p_m_hold?101:31); /* normal unspecified / incompatible state */ + add_trace("reason", NULL, "no endpoint"); + end_trace(); msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); return; @@ -1472,7 +1388,10 @@ void Pdss1::hold_ind(unsigned long prim, unsigned long dinfo, void *data) message_put(message); /* deactivate bchannel */ - free_bchannel(); + chan_trace_header(p_m_mISDNport, this, "CHANNEL RELEASE (hold)", DIRECTION_NONE); + add_trace("disconnect", "channel", "%d", p_m_b_channel); + end_trace(); + drop_bchannel(); /* set hold state */ p_m_hold = 1; @@ -1487,8 +1406,9 @@ void Pdss1::hold_ind(unsigned long prim, unsigned long dinfo, void *data) /* acknowledge hold */ dmsg = create_l3msg(CC_HOLD_ACKNOWLEDGE | REQUEST, MT_HOLD_ACKNOWLEDGE, dinfo, sizeof(HOLD_ACKNOWLEDGE_t), p_m_d_ntmode); - isdn_show_send_message(CC_HOLD_ACKNOWLEDGE | REQUEST, dmsg); hold_acknowledge = (HOLD_ACKNOWLEDGE_t *)(dmsg->data + headerlen); + l1l2l3_trace_header(p_m_mISDNport, this, CC_HOLD_ACKNOWLEDGE | REQUEST, DIRECTION_OUT); + end_trace(); msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); } @@ -1505,16 +1425,20 @@ void Pdss1::retrieve_ind(unsigned long prim, unsigned long dinfo, void *data) msg_t *dmsg; int ret; + l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN); + dec_ie_channel_id(retrieve->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel); + end_trace(); + if (!p_m_hold) { cause = 101; /* incompatible state */ reject: - PDEBUG(DEBUG_ISDN, "Pdss1(%s) we are not on hold, so we reject (cazse %d).\n", p_name, cause); dmsg = create_l3msg(CC_RETRIEVE_REJECT | REQUEST, MT_RETRIEVE_REJECT, dinfo, sizeof(RETRIEVE_REJECT_t), p_m_d_ntmode); - isdn_show_send_message(CC_RETRIEVE_REJECT | REQUEST, dmsg); retrieve_reject = (RETRIEVE_REJECT_t *)(dmsg->data + headerlen); - enc_ie_cause(&retrieve_reject->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, cause); + l1l2l3_trace_header(p_m_mISDNport, this, CC_RETRIEVE_REJECT | REQUEST, DIRECTION_OUT); + enc_ie_cause(&retrieve_reject->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, cause); + end_trace(); msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); return; @@ -1526,32 +1450,20 @@ void Pdss1::retrieve_ind(unsigned long prim, unsigned long dinfo, void *data) message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */ message_put(message); - /* channel_id */ - dec_ie_channel_id(retrieve->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel); - if (exclusive<0) - exclusive = 0; - if (channel < 0) - channel = -1; /* any channel */ - if (channel == ANY_CHANNEL) - channel = -1; /* any channel */ - /* debug */ - if (channel < 0) - PDEBUG(DEBUG_BCHANNEL, "- any channel is selected the %s, so we need to return the selected channel\n", (p_m_d_ntmode)?"user":"network"); - if (channel==0 && (p_type==PORT_TYPE_DSS1_TE_IN||p_type==PORT_TYPE_DSS1_TE_OUT)) - PDEBUG(DEBUG_BCHANNEL, "- no channel is given by the network, causing to fail, since CW is not possible for external lines\n"); - if (channel >= 0) - if (exclusive) - PDEBUG(DEBUG_BCHANNEL, "- exclusive channel(%d) is selected.\n", channel); - else - PDEBUG(DEBUG_BCHANNEL, "- channel(%d) given, but we select a different channel if not available.\n", channel); + /* hunt channel */ + ret = channel = hunt_bchannel(channel, exclusive); + if (ret < 0) + goto no_channel; + /* open channel */ - ret = alloc_bchannel(channel, exclusive); + ret = seize_bchannel(channel, 1); if (ret < 0) { - PDEBUG(DEBUG_BCHANNEL, "- channel is not available (cause=%d), so we send a retrieve_reject.\n", -ret); + no_channel: cause = -ret; goto reject; } + bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_ACTIVATE); /* set hold state */ p_m_hold = 0; @@ -1559,10 +1471,10 @@ void Pdss1::retrieve_ind(unsigned long prim, unsigned long dinfo, void *data) /* acknowledge retrieve */ dmsg = create_l3msg(CC_RETRIEVE_ACKNOWLEDGE | REQUEST, MT_RETRIEVE_ACKNOWLEDGE, dinfo, sizeof(RETRIEVE_ACKNOWLEDGE_t), p_m_d_ntmode); - isdn_show_send_message(CC_RETRIEVE_ACKNOWLEDGE | REQUEST, dmsg); retrieve_acknowledge = (RETRIEVE_ACKNOWLEDGE_t *)(dmsg->data + headerlen); - /* channel information */ + l1l2l3_trace_header(p_m_mISDNport, this, CC_RETRIEVE_ACKNOWLEDGE | REQUEST, DIRECTION_OUT); enc_ie_channel_id(&retrieve_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel); + end_trace(); msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); } @@ -1580,22 +1492,24 @@ void Pdss1::suspend_ind(unsigned long prim, unsigned long dinfo, void *data) msg_t *dmsg; int ret = -31; /* normal, unspecified */ + l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN); + dec_ie_call_id(suspend->CALL_ID, (Q931_info_t *)((unsigned long)data+headerlen), callid, &len); + end_trace(); + if (!ACTIVE_EPOINT(p_epointlist)) { - PDEBUG(DEBUG_ISDN, "Pdss1(%s) there is no endpoint to notify suspend, so we reject.\n", p_name); - reject: dmsg = create_l3msg(CC_SUSPEND_REJECT | REQUEST, MT_SUSPEND_REJECT, dinfo, sizeof(SUSPEND_REJECT_t), p_m_d_ntmode); - isdn_show_send_message(CC_SUSPEND_REJECT | REQUEST, dmsg); suspend_reject = (SUSPEND_REJECT_t *)(dmsg->data + headerlen); - enc_ie_cause(&suspend_reject->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret); + l1l2l3_trace_header(p_m_mISDNport, this, CC_SUSPEND_REJECT | REQUEST, DIRECTION_OUT); + enc_ie_cause(&suspend_reject->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret); + end_trace(); msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); return; } /* call id */ - dec_ie_call_id(suspend->CALL_ID, (Q931_info_t *)((unsigned long)data+headerlen), callid, &len); if (len<0) len = 0; /* check if call id is in use */ @@ -1607,7 +1521,6 @@ void Pdss1::suspend_ind(unsigned long prim, unsigned long dinfo, void *data) if (epoint->ep_park_len == len) if (!memcmp(epoint->ep_park_callid, callid, len)) { - PDEBUG(DEBUG_ISDN, "Pdss1(%s) call id is in use, so we reject.\n", p_name); ret = -84; /* call id in use */ goto reject; } @@ -1622,7 +1535,10 @@ void Pdss1::suspend_ind(unsigned long prim, unsigned long dinfo, void *data) message_put(message); /* deactivate bchannel */ - free_bchannel(); + chan_trace_header(p_m_mISDNport, this, "CHANNEL RELEASE (suspend)", DIRECTION_NONE); + add_trace("disconnect", "channel", "%d", p_m_b_channel); + end_trace(); + drop_bchannel(); /* sending suspend to endpoint */ while (p_epointlist) @@ -1637,8 +1553,9 @@ void Pdss1::suspend_ind(unsigned long prim, unsigned long dinfo, void *data) /* sending SUSPEND_ACKNOWLEDGE */ dmsg = create_l3msg(CC_SUSPEND_ACKNOWLEDGE | REQUEST, MT_SUSPEND_ACKNOWLEDGE, dinfo, sizeof(SUSPEND_ACKNOWLEDGE_t), p_m_d_ntmode); - isdn_show_send_message(CC_SUSPEND_ACKNOWLEDGE | REQUEST, dmsg); suspend_acknowledge = (SUSPEND_ACKNOWLEDGE_t *)(dmsg->data + headerlen); + l1l2l3_trace_header(p_m_mISDNport, this, CC_SUSPEND_ACKNOWLEDGE | REQUEST, DIRECTION_OUT); + end_trace(); msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); new_state(PORT_STATE_RELEASE); @@ -1660,47 +1577,69 @@ void Pdss1::resume_ind(unsigned long prim, unsigned long dinfo, void *data) struct message *message; int ret; + /* callref from nt-lib */ + if (p_m_d_ntmode) + { + /* nt-library now gives us the id via CC_RESUME */ + if (dinfo&(~0xff) == 0xff00) + FATAL("l3-stack gives us a process id 0xff00-0xffff\n"); + l1l2l3_trace_header(p_m_mISDNport, this, CC_NEW_CR | INDICATION, DIRECTION_IN); + if (p_m_d_l3id) + add_trace("callref", "old", "0x%x", p_m_d_l3id); + add_trace("callref", "new", "0x%x", dinfo); + end_trace(); + if (p_m_d_l3id&(~0xff) == 0xff00) + p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0; + p_m_d_l3id = dinfo; + p_m_d_ces = resume->ces; + } + + l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN); + dec_ie_call_id(resume->CALL_ID, (Q931_info_t *)((unsigned long)data+headerlen), callid, &len); + end_trace(); + /* if blocked, release call */ if (p_m_mISDNport->ifport->block) { - RELEASE_COMPLETE_t *release_complete; - - printlog("--- port#%d is blocked.\n", mISDNport->ifport->portnum); ret = -27; goto reject; } /* call id */ - dec_ie_call_id(resume->CALL_ID, (Q931_info_t *)((unsigned long)data+headerlen), callid, &len); if (len<0) len = 0; - /* channel_id */ + /* channel_id (no channel is possible in message) */ exclusive = 0; channel = -1; /* any channel */ - PDEBUG(DEBUG_BCHANNEL, "- any channel is selected the %s, so we need to return the selected channel\n", (p_m_d_ntmode)?"user":"network"); + + /* hunt channel */ + ret = channel = hunt_bchannel(channel, exclusive); + if (ret < 0) + goto no_channel; + /* open channel */ - ret = alloc_bchannel(channel, exclusive); + ret = seize_bchannel(channel, 1); if (ret < 0) { - PDEBUG(DEBUG_BCHANNEL, "- channel is not available (cause=%d), so we send a RESUME_REJECT.\n", -ret); - + no_channel: reject: dmsg = create_l3msg(CC_RESUME_REJECT | REQUEST, MT_RESUME_REJECT, dinfo, sizeof(RESUME_REJECT_t), p_m_d_ntmode); - isdn_show_send_message(CC_RESUME_REJECT | REQUEST, dmsg); resume_reject = (RESUME_REJECT_t *)(dmsg->data + headerlen); - enc_ie_cause(&resume_reject->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret); + l1l2l3_trace_header(p_m_mISDNport, this, CC_RESUME_REJECT | REQUEST, DIRECTION_OUT); + enc_ie_cause(&resume_reject->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret); + if (ret == -27) + add_trace("reason", NULL, "port blocked"); + end_trace(); msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); new_state(PORT_STATE_RELEASE); p_m_delete = 1; return; } - PDEBUG(DEBUG_BCHANNEL, "- channel is available, we selected channel %d.\n", ret); + bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_ACTIVATE); + /* create endpoint */ if (p_epointlist) - { - PERROR("SOFTWARE ERROR: incoming resume but already got an endpoint, exitting...\n"); - exit(-1); - } + FATAL("Incoming resume but already got an endpoint.\n"); ret = -85; /* no call suspended */ epoint = epoint_first; while(epoint) @@ -1715,38 +1654,11 @@ void Pdss1::resume_ind(unsigned long prim, unsigned long dinfo, void *data) epoint = epoint->next; } if (!epoint) - { - PDEBUG(DEBUG_ISDN, "Pdss1(%s) no suspended call, so we reject with cause %d.\n", p_name, ret); goto reject; - } - - if (!(epointlist_new(epoint->ep_serial))) - { - PERROR("no memory for epointlist\n"); - exit(-1); - } - if (!(epoint->portlist_new(p_serial, p_type, p_m_mISDNport->is_earlyb))) - { - PERROR("no memory for portlist\n"); - exit(-1); - } - if (p_m_d_ntmode) - { - /* nt-library now gives us the id via CC_RESUME */ - if (dinfo&(~0xff) == 0xff00) - { - PERROR("fatal software error: l3-stack gives us a process id 0xff00-0xffff\n"); - exit(-1); - } - printisdn(" l3id 0x%x changes to 0x%x\n", p_m_d_l3id, dinfo); - if (p_m_d_l3id&(~0xff) == 0xff00) - p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0; - p_m_d_l3id = dinfo; - p_m_d_ces = resume->ces; - PDEBUG(DEBUG_ISDN, "Pdss1(%s: nt-mode gives us new l3id via resume ind: 0x%x\n", p_name, p_m_d_l3id); - } - PDEBUG(DEBUG_ISDN, "Pdss1(%s) resume\n", p_name); + epointlist_new(epoint->ep_serial); + if (!(epoint->portlist_new(p_serial, p_type, p_m_mISDNport->earlyb))) + FATAL("No memory for portlist\n"); message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RESUME); message_put(message); @@ -1758,10 +1670,10 @@ void Pdss1::resume_ind(unsigned long prim, unsigned long dinfo, void *data) /* sending RESUME_ACKNOWLEDGE */ dmsg = create_l3msg(CC_RESUME_ACKNOWLEDGE | REQUEST, MT_RESUME_ACKNOWLEDGE, dinfo, sizeof(RESUME_ACKNOWLEDGE_t), p_m_d_ntmode); - isdn_show_send_message(CC_RESUME_ACKNOWLEDGE | REQUEST, dmsg); resume_acknowledge = (RESUME_ACKNOWLEDGE_t *)(dmsg->data + headerlen); - /* channel information */ + l1l2l3_trace_header(p_m_mISDNport, this, CC_RESUME_ACKNOWLEDGE | REQUEST, DIRECTION_OUT); enc_ie_channel_id(&resume_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel); + end_trace(); msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); new_state(PORT_STATE_CONNECT); @@ -1777,12 +1689,14 @@ void Pdss1::facility_ind(unsigned long prim, unsigned long dinfo, void *data) int facil_len; struct message *message; - /* facility */ + l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN); dec_ie_facility(facility->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), facil, &facil_len); + end_trace(); + + /* facility */ if (facil_len<=0) return; - PDEBUG(DEBUG_ISDN, "Pdss1(%s) facility\n", p_name); message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_FACILITY); message->param.facilityinfo.len = facil_len; memcpy(message->param.facilityinfo.data, facil, facil_len); @@ -1796,119 +1710,93 @@ void Pdss1::facility_ind(unsigned long prim, unsigned long dinfo, void *data) */ void Pdss1::message_isdn(unsigned long prim, unsigned long dinfo, void *data) { - char *msgtext = "<>"; - char *primtext; - int i; int new_l3id; + int timer_hex=0; - i = 0; - while(isdn_message[i].name) - { - if (isdn_message[i].value == (prim&0xffffff00)) - { - msgtext = isdn_message[i].name; - break; - } - i++; - } - primtext = isdn_prim[prim&0x00000003]; - printisdn("<<< incoming prim: %s %s (0x%x)\n", msgtext, primtext, prim); switch (prim) { case CC_TIMEOUT | INDICATION: if (p_m_d_ntmode) { int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN; - int t = *((int *)(((char *)data)+headerlen)); - PDEBUG(DEBUG_ISDN, "Pdss1(%s) timeout (t%x in NT-mode)\n", p_name, t); - if (t == 0x312) - t312_timeout(prim, dinfo, data); - } else { - PDEBUG(DEBUG_ISDN, "Pdss1(%s) timeout (ignoring)\n", p_name); + timer_hex = *((int *)(((char *)data)+headerlen)); + } + if (timer_hex==0x312 && p_m_d_ntmode) + { + l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN); + add_trace("timer", NULL, "%x", timer_hex); + end_trace(); + t312_timeout(prim, dinfo, data); } break; case CC_SETUP | INDICATION: - PDEBUG((DEBUG_BCHANNEL|DEBUG_ISDN), "Pdss1(%s) setup\n", p_name); if (p_state != PORT_STATE_IDLE) - { - PDEBUG(DEBUG_ISDN, "Pdss1(%s) received setup again, IGNORING.\n", p_name); break; - } setup_ind(prim, dinfo, data); break; case CC_SETUP | CONFIRM: if (p_m_d_ntmode) { + l1l2l3_trace_header(p_m_mISDNport, this, CC_NEW_CR | INDICATION, DIRECTION_IN); + add_trace("callref", "old", "0x%x", p_m_d_l3id); /* nt-library now gives us a new id via CC_SETUP_CONFIRM */ - if ((p_m_d_l3id&0xff00) == 0xff00) - { -// p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0; -// printisdn(" procid 0x%x freed\n", p_m_d_l3id&0xff); - printisdn(" procid 0x%x still in use\n", p_m_d_l3id&0xff); - } else - { - printisdn(" strange setup-procid 0x%x\n", p_m_d_l3id); - } + if ((p_m_d_l3id&0xff00) != 0xff00) + PERROR(" strange setup-procid 0x%x\n", p_m_d_l3id); p_m_d_l3id = *((int *)(((u_char *)data)+ mISDNUSER_HEAD_SIZE)); - printisdn(" l3id changes to 0x%x\n", p_m_d_l3id); + add_trace("callref", "new", "0x%x", p_m_d_l3id); + end_trace(); } - PDEBUG(DEBUG_ISDN, "Pdss1(%s) setup confirm (l3id=0x%x)\n", p_name, p_m_d_l3id); break; case CC_INFORMATION | INDICATION: - PDEBUG(DEBUG_ISDN, "Pdss1(%s) information\n", p_name); information_ind(prim, dinfo, data); break; case CC_SETUP_ACKNOWLEDGE | INDICATION: - PDEBUG(DEBUG_ISDN, "Pdss1(%s) setup acknowledge\n", p_name); if (p_state != PORT_STATE_OUT_SETUP) { - PDEBUG(DEBUG_ISDN, "Pdss1(%s) received setup_acknowledge, but we are not in outgoing setup state, IGNORING.\n", p_name); + PERROR("Pdss1(%s) received setup_acknowledge, but we are not in outgoing setup state, IGNORING.\n", p_name); break; } setup_acknowledge_ind(prim, dinfo, data); break; case CC_PROCEEDING | INDICATION: - PDEBUG(DEBUG_ISDN, "Pdss1(%s) proceeding\n", p_name); if (p_state != PORT_STATE_OUT_SETUP && p_state != PORT_STATE_OUT_OVERLAP) { - PDEBUG(DEBUG_ISDN, "Pdss1(%s) received proceeding, but we are not in outgoing setup OR overlap state, IGNORING.\n", p_name); + PERROR("Pdss1(%s) received proceeding, but we are not in outgoing setup OR overlap state, IGNORING.\n", p_name); break; } proceeding_ind(prim, dinfo, data); break; case CC_ALERTING | INDICATION: - PDEBUG(DEBUG_ISDN, "Pdss1(%s) alerting\n", p_name); if (p_state != PORT_STATE_OUT_SETUP && p_state != PORT_STATE_OUT_OVERLAP && p_state != PORT_STATE_OUT_PROCEEDING) { - PDEBUG(DEBUG_ISDN, "Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding state, IGNORING.\n", p_name); + PERROR("Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding state, IGNORING.\n", p_name); break; } alerting_ind(prim, dinfo, data); break; case CC_CONNECT | INDICATION: - PDEBUG(DEBUG_ISDN, "Pdss1(%s) connect\n", p_name); if (p_state != PORT_STATE_OUT_SETUP && p_state != PORT_STATE_OUT_OVERLAP && p_state != PORT_STATE_OUT_PROCEEDING && p_state != PORT_STATE_OUT_ALERTING) { - PDEBUG(DEBUG_ISDN, "Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding OR ALERTING state, IGNORING.\n", p_name); + PERROR("Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding OR ALERTING state, IGNORING.\n", p_name); break; } connect_ind(prim, dinfo, data); if (p_m_d_notify_pending) { - PDEBUG(DEBUG_ISDN, "received or connect, so we send pending notify message.\n"); + /* send pending notify message during connect */ message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param); message_free(p_m_d_notify_pending); p_m_d_notify_pending = NULL; @@ -1917,12 +1805,11 @@ void Pdss1::message_isdn(unsigned long prim, unsigned long dinfo, void *data) case CC_CONNECT_ACKNOWLEDGE | INDICATION: case CC_CONNECT | CONFIRM: - PDEBUG(DEBUG_ISDN, "Pdss1(%s) connect_acknowlege.\n", p_name); if (p_state == PORT_STATE_CONNECT_WAITING) new_state(PORT_STATE_CONNECT); if (p_m_d_notify_pending) { - PDEBUG(DEBUG_ISDN, "received or connect-ack, so we send pending notify message.\n"); + /* send pending notify message during connect-ack */ message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param); message_free(p_m_d_notify_pending); p_m_d_notify_pending = NULL; @@ -1930,72 +1817,60 @@ void Pdss1::message_isdn(unsigned long prim, unsigned long dinfo, void *data) break; case CC_DISCONNECT | INDICATION: - PDEBUG(DEBUG_ISDN, "Pdss1(%s) disconnect\n", p_name); disconnect_ind(prim, dinfo, data); break; case CC_RELEASE | CONFIRM: - PDEBUG(DEBUG_ISDN, "Pdss1(%s) release confirm\n", p_name); case CC_RELEASE | INDICATION: - PDEBUG(DEBUG_ISDN, "Pdss1(%s) release\n", p_name); release_ind(prim, dinfo, data); break; case CC_RELEASE_COMPLETE | INDICATION: - PDEBUG(DEBUG_ISDN, "Pdss1(%s) release_complete.\n", p_name); release_complete_ind(prim, dinfo, data); break; case CC_RELEASE_COMPLETE | CONFIRM: - PDEBUG(DEBUG_ISDN, "Pdss1(%s) release_complete (confirm).\n", p_name); break; case CC_NOTIFY | INDICATION: - PDEBUG(DEBUG_ISDN, "Pdss1(%s) notify\n", p_name); notify_ind(prim, dinfo, data); break; case CC_HOLD | INDICATION: - PDEBUG(DEBUG_ISDN, "Pdss1(%s) hold\n", p_name); hold_ind(prim, dinfo, data); break; case CC_RETRIEVE | INDICATION: - PDEBUG(DEBUG_ISDN, "Pdss1(%s) retrieve\n", p_name); retrieve_ind(prim, dinfo, data); break; case CC_SUSPEND | INDICATION: - PDEBUG(DEBUG_ISDN, "Pdss1(%s) suspend\n", p_name); suspend_ind(prim, dinfo, data); break; case CC_RESUME | INDICATION: - PDEBUG(DEBUG_ISDN, "Pdss1(%s) resume\n", p_name); resume_ind(prim, dinfo, data); break; case CC_FACILITY | INDICATION: - PDEBUG(DEBUG_ISDN, "Pdss1(%s) facility\n", p_name); facility_ind(prim, dinfo, data); break; case CC_RELEASE_CR | INDICATION: - PDEBUG(DEBUG_ISDN, "Pdss1(%s) call ref is released (l3id=0x%x)\n", p_name, p_m_d_l3id); - printisdn(" process 0x%x released\n", p_m_d_l3id); + l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_CR | INDICATION, DIRECTION_IN); + add_trace("callref", NULL, "0x%x", p_m_d_l3id); + end_trace(); if (p_m_d_ntmode) { if ((p_m_d_l3id&0xff00) == 0xff00) - { p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0; - printisdn(" procid 0x%x freed\n", p_m_d_l3id&0xff); - } } p_m_d_l3id = 0; p_m_delete = 1; +#warning remove me +PDEBUG(DEBUG_LOG, "JOLLY release cr %d\n", p_serial); /* sending release to endpoint in case we still have an endpoint - * NOTE: this only happens if the stack releases due to layer1 - * or layer2 breakdown. otherwhise a release is received first. + * this is because we don't get any response if a release_complete is received (or a release in release state) */ while(p_epointlist) { @@ -2007,32 +1882,32 @@ void Pdss1::message_isdn(unsigned long prim, unsigned long dinfo, void *data) /* remove epoint */ free_epointlist(p_epointlist); - PDEBUG(DEBUG_ISDN, "Pdss1(%s) release due to breakdown of l3-process.\n", p_name); new_state(PORT_STATE_RELEASE); } break; case CC_NEW_CR | INDICATION: + l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN); + if (p_m_d_l3id) + add_trace("callref", "old", "0x%x", p_m_d_l3id); if (p_m_d_ntmode) { new_l3id = *((int *)(((u_char *)data+mISDNUSER_HEAD_SIZE))); - printisdn(" process 0x%x received\n", new_l3id); if (((new_l3id&0xff00)!=0xff00) && ((p_m_d_l3id&0xff00)==0xff00)) - { p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0; - printisdn(" procid 0x%x freed\n", p_m_d_l3id&0xff); - } } else { new_l3id = dinfo; - printisdn(" process 0x%x received\n", new_l3id); } p_m_d_l3id = new_l3id; - PDEBUG(DEBUG_ISDN, "Pdss1(%s) call ref is created (l3id=0x%x)\n", p_name, p_m_d_l3id); + add_trace("callref", "new", "0x%x", p_m_d_l3id); + end_trace(); break; default: - PDEBUG(DEBUG_ISDN, "Pdss1(%s) unhandled prim: 0x%x\n", p_name, prim); + l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN); + add_trace("unhandled", "prim", "0x%x", prim); + end_trace(); } } @@ -2051,14 +1926,6 @@ void Pdss1::new_state(int state) } if (state != p_state) { -#if 0 - if (state == PORT_STATE_OUT_SETUP - || state == PORT_STATE_OUT_OVERLAP) - { - p_m_timeout = 8; - time(&p_m_timer); - } -#endif if (state == PORT_STATE_IN_SETUP || state == PORT_STATE_IN_OVERLAP) { @@ -2100,15 +1967,24 @@ void Pdss1::new_state(int state) */ int Pdss1::handler(void) { + int ret; + +if (p_m_delete && p_m_d_l3id==0) + printf("ping! %d", p_serial); + if ((ret = PmISDN::handler())) + return(ret); + /* handle destruction */ if (p_m_delete && p_m_d_l3id==0) { - PDEBUG(DEBUG_ISDN, "Pdss1(%s) doing pending release.\n", p_name); +#warning remove +PDEBUG(DEBUG_LOG, "JOLLY destroy object %d\n", p_serial); + delete this; return(-1); } - return(PmISDN::handler()); + return(0); } @@ -2122,12 +1998,13 @@ void Pdss1::message_information(unsigned long epoint_id, int message_id, union p INFORMATION_t *information; msg_t *dmsg; - if (param->information.number[0]) /* only if we have something to dial */ + if (param->information.id[0]) /* only if we have something to dial */ { dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode); - isdn_show_send_message(CC_INFORMATION | REQUEST, dmsg); information = (INFORMATION_t *)(dmsg->data + headerlen); - enc_ie_called_pn(&information->CALLED_PN, dmsg, 0, 1, (unsigned char *)param->information.number); + l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT); + enc_ie_called_pn(&information->CALLED_PN, dmsg, 0, 1, (unsigned char *)param->information.id); + end_trace(); msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); } new_state(p_state); @@ -2152,6 +2029,8 @@ void Pdss1::message_setup(unsigned long epoint_id, int message_id, union paramet /* release if port is blocked */ if (p_m_mISDNport->ifport->block) { + struct message *message; + message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE); message->param.disconnectinfo.cause = 27; // temp. unavail. message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL; @@ -2178,10 +2057,11 @@ void Pdss1::message_setup(unsigned long epoint_id, int message_id, union paramet { /* sending information */ dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode); - isdn_show_send_message(CC_INFORMATION | REQUEST, dmsg); information = (INFORMATION_t *)(dmsg->data + headerlen); + l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT); if (p_m_d_ntmode) enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_callerinfo.display); + end_trace(); msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); return; } @@ -2196,13 +2076,7 @@ void Pdss1::message_setup(unsigned long epoint_id, int message_id, union paramet epointlist = epointlist->next; } if (!epointlist) - { - if (!(epointlist_new(epoint_id))) - { - PERROR("no memory for epointlist\n"); - exit(-1); - } - } + epointlist_new(epoint_id); /* get channel */ exclusive = 0; @@ -2217,6 +2091,7 @@ void Pdss1::message_setup(unsigned long epoint_id, int message_id, union paramet channel = CHANNEL_NO; /* creating l3id */ + l1l2l3_trace_header(p_m_mISDNport, this, CC_NEW_CR | REQUEST, DIRECTION_OUT); if (p_m_d_ntmode) { i = 0; @@ -2230,8 +2105,8 @@ void Pdss1::message_setup(unsigned long epoint_id, int message_id, union paramet { struct message *message; - printisdn(" no free process id\n"); - PDEBUG(DEBUG_ISDN, "no more free process ID for port.\n"); + add_trace("callref", NULL, "no free id"); + end_trace(); message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE); message->param.disconnectinfo.cause = 47; message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL; @@ -2241,9 +2116,7 @@ void Pdss1::message_setup(unsigned long epoint_id, int message_id, union paramet return; } p_m_mISDNport->procids[i] = 1; - printisdn(" procid 0x%x allocated\n", i); p_m_d_l3id = 0xff00 | i; - printisdn(" l3id is now 0x%x\n", p_m_d_l3id); } else { iframe_t ncr; @@ -2256,17 +2129,18 @@ void Pdss1::message_setup(unsigned long epoint_id, int message_id, union paramet ncr.addr = p_m_mISDNport->upper_id | FLG_MSG_DOWN; ncr.dinfo = p_m_d_l3id; ncr.len = 0; - isdn_show_send_message(CC_NEW_CR | REQUEST, NULL); /* send message */ mISDN_write(mISDNdevice, &ncr, mISDN_HEADER_LEN+ncr.len, TIMEOUT_1SEC); // if (!dmsg) // goto nomem; } + add_trace("callref", "new", "0x%x", p_m_d_l3id); + end_trace(); /* preparing setup message */ dmsg = create_l3msg(CC_SETUP | REQUEST, MT_SETUP, p_m_d_l3id, sizeof(SETUP_t), p_m_d_ntmode); - isdn_show_send_message(CC_SETUP | REQUEST, dmsg); setup = (SETUP_t *)(dmsg->data + headerlen); + l1l2l3_trace_header(p_m_mISDNport, this, CC_SETUP | REQUEST, DIRECTION_OUT); /* channel information */ if (channel >= 0) /* it should */ { @@ -2313,9 +2187,9 @@ void Pdss1::message_setup(unsigned long epoint_id, int message_id, union paramet if (type >= 0) enc_ie_calling_pn(&setup->CALLING_PN, dmsg, type, plan, present, screen, (unsigned char *)p_callerinfo.id); /* dialing information */ - if (p_dialinginfo.number[0]) /* only if we have something to dial */ + if (p_dialinginfo.id[0]) /* only if we have something to dial */ { - enc_ie_called_pn(&setup->CALLED_PN, dmsg, 0, 1, (unsigned char *)p_dialinginfo.number); + enc_ie_called_pn(&setup->CALLED_PN, dmsg, 0, 1, (unsigned char *)p_dialinginfo.id); } /* sending complete */ if (p_dialinginfo.sending_complete) @@ -2431,6 +2305,7 @@ void Pdss1::message_setup(unsigned long epoint_id, int message_id, union paramet if (p_callerinfo.name[0] && p_m_d_ntmode) enc_facility_centrex(&setup->FACILITY, dmsg, (unsigned char *)p_callerinfo.name, 1); #endif + end_trace(); /* send setup message now */ msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); @@ -2449,13 +2324,12 @@ void Pdss1::message_facility(unsigned long epoint_id, int message_id, union para if (!p_m_d_ntmode) return; - PDEBUG(DEBUG_ISDN, "Pdss1(%s) sending facility message\n", p_name); - /* sending facility */ dmsg = create_l3msg(CC_FACILITY | REQUEST, MT_FACILITY, p_m_d_l3id, sizeof(FACILITY_t), p_m_d_ntmode); - isdn_show_send_message(CC_FACILITY | REQUEST, dmsg); facility = (FACILITY_t *)(dmsg->data + headerlen); + l1l2l3_trace_header(p_m_mISDNport, this, CC_FACILITY | REQUEST, DIRECTION_OUT); enc_ie_facility(&facility->FACILITY, dmsg, (unsigned char *)param->facilityinfo.data, param->facilityinfo.len); + end_trace(); msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); } @@ -2469,7 +2343,6 @@ void Pdss1::message_notify(unsigned long epoint_id, int message_id, union parame int plan, type = -1, present; msg_t *dmsg; - PDEBUG(DEBUG_ISDN, "Pdss1(%s) sending information message\n", p_name); if (param->notifyinfo.notify>INFO_NOTIFY_NONE) notify = param->notifyinfo.notify & 0x7f; else @@ -2518,7 +2391,7 @@ void Pdss1::message_notify(unsigned long epoint_id, int message_id, union parame if (notify<0 && !param->notifyinfo.display[0]) { - PDEBUG(DEBUG_ISDN, "Pdss1(%s) nothing to notify, nothing to display\n", p_name); + /* nothing to notify, nothing to display */ return; } @@ -2527,7 +2400,6 @@ void Pdss1::message_notify(unsigned long epoint_id, int message_id, union parame if (p_state!=PORT_STATE_CONNECT) { /* queue notification */ - PDEBUG(DEBUG_ISDN, "Pdss1(%s) queueing notification because isdn port is not active state.\n", p_name); if (p_m_d_notify_pending) message_free(p_m_d_notify_pending); p_m_d_notify_pending = message_create(ACTIVE_EPOINT(p_epointlist), p_serial, EPOINT_TO_PORT, message_id); @@ -2536,23 +2408,25 @@ void Pdss1::message_notify(unsigned long epoint_id, int message_id, union parame { /* sending notification */ dmsg = create_l3msg(CC_NOTIFY | REQUEST, MT_NOTIFY, p_m_d_l3id, sizeof(NOTIFY_t), p_m_d_ntmode); - isdn_show_send_message(CC_NOTIFY | REQUEST, dmsg); notification = (NOTIFY_t *)(dmsg->data + headerlen); + l1l2l3_trace_header(p_m_mISDNport, this, CC_NOTIFY | REQUEST, DIRECTION_OUT); enc_ie_notify(¬ification->NOTIFY, dmsg, notify); /* sending redirection number only in ntmode */ if (type >= 0 && p_m_d_ntmode) enc_ie_redir_dn(¬ification->REDIR_DN, dmsg, type, plan, present, (unsigned char *)param->notifyinfo.id); if (param->notifyinfo.display[0] && p_m_d_ntmode) enc_ie_display(¬ification->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display); + end_trace(); msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); } } else if (p_m_d_ntmode) { /* sending information */ dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode); - isdn_show_send_message(CC_INFORMATION | REQUEST, dmsg); information = (INFORMATION_t *)(dmsg->data + headerlen); + l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT); enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display); + end_trace(); msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); } } @@ -2566,8 +2440,8 @@ void Pdss1::message_overlap(unsigned long epoint_id, int message_id, union param /* sending setup_acknowledge */ dmsg = create_l3msg(CC_SETUP_ACKNOWLEDGE | REQUEST, MT_SETUP_ACKNOWLEDGE, p_m_d_l3id, sizeof(SETUP_ACKNOWLEDGE_t), p_m_d_ntmode); - isdn_show_send_message(CC_SETUP_ACKNOWLEDGE | REQUEST, dmsg); setup_acknowledge = (SETUP_ACKNOWLEDGE_t *)(dmsg->data + headerlen); + l1l2l3_trace_header(p_m_mISDNport, this, CC_SETUP_ACKNOWLEDGE | REQUEST, DIRECTION_OUT); /* channel information */ if (p_state == PORT_STATE_IN_SETUP) enc_ie_channel_id(&setup_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel); @@ -2575,8 +2449,9 @@ void Pdss1::message_overlap(unsigned long epoint_id, int message_id, union param if (p_capainfo.bearer_capa==INFO_BC_SPEECH || p_capainfo.bearer_capa==INFO_BC_AUDIO || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES) - if (p_m_mISDNport->is_tones) + if (p_m_mISDNport->tones) enc_ie_progress(&setup_acknowledge->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8); + end_trace(); msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); new_state(PORT_STATE_IN_OVERLAP); @@ -2591,8 +2466,8 @@ void Pdss1::message_proceeding(unsigned long epoint_id, int message_id, union pa /* sending proceeding */ dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode); - isdn_show_send_message(CC_PROCEEDING | REQUEST, dmsg); proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen); + l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT); /* channel information */ if (p_state == PORT_STATE_IN_SETUP) enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel); @@ -2600,8 +2475,9 @@ void Pdss1::message_proceeding(unsigned long epoint_id, int message_id, union pa if (p_capainfo.bearer_capa==INFO_BC_SPEECH || p_capainfo.bearer_capa==INFO_BC_AUDIO || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES) - if (p_m_mISDNport->is_tones) + if (p_m_mISDNport->tones) enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8); + end_trace(); msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); new_state(PORT_STATE_IN_PROCEEDING); @@ -2621,8 +2497,8 @@ void Pdss1::message_alerting(unsigned long epoint_id, int message_id, union para /* sending proceeding */ dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode); - isdn_show_send_message(CC_PROCEEDING | REQUEST, dmsg); proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen); + l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT); /* channel information */ enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel); /* progress information */ @@ -2630,14 +2506,15 @@ void Pdss1::message_alerting(unsigned long epoint_id, int message_id, union para || p_capainfo.bearer_capa==INFO_BC_AUDIO || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES) enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8); + end_trace(); msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); new_state(PORT_STATE_IN_PROCEEDING); } /* sending alerting */ dmsg = create_l3msg(CC_ALERTING | REQUEST, MT_ALERTING, p_m_d_l3id, sizeof(ALERTING_t), p_m_d_ntmode); - isdn_show_send_message(CC_ALERTING | REQUEST, dmsg); alerting = (ALERTING_t *)(dmsg->data + headerlen); + l1l2l3_trace_header(p_m_mISDNport, this, CC_ALERTING | REQUEST, DIRECTION_OUT); /* channel information */ if (p_state == PORT_STATE_IN_SETUP) enc_ie_channel_id(&alerting->CHANNEL_ID, dmsg, 1, p_m_b_channel); @@ -2645,8 +2522,9 @@ void Pdss1::message_alerting(unsigned long epoint_id, int message_id, union para if (p_capainfo.bearer_capa==INFO_BC_SPEECH || p_capainfo.bearer_capa==INFO_BC_AUDIO || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES) - if (p_m_mISDNport->is_tones) + if (p_m_mISDNport->tones) enc_ie_progress(&alerting->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8); + end_trace(); msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); new_state(PORT_STATE_IN_ALERTING); @@ -2669,8 +2547,8 @@ void Pdss1::message_connect(unsigned long epoint_id, int message_id, union param /* sending proceeding */ dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode); - isdn_show_send_message(CC_PROCEEDING | REQUEST, dmsg); proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen); + l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT); /* channel information */ enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel); // /* progress information */ @@ -2678,6 +2556,7 @@ void Pdss1::message_connect(unsigned long epoint_id, int message_id, union param // || p_capainfo.bearer_capa==INFO_BC_AUDIO // || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES) // enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8); + end_trace(); msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); new_state(PORT_STATE_IN_PROCEEDING); } @@ -2691,24 +2570,25 @@ void Pdss1::message_connect(unsigned long epoint_id, int message_id, union param { /* sending information */ dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode); - isdn_show_send_message(CC_INFORMATION | REQUEST, dmsg); information = (INFORMATION_t *)(dmsg->data + headerlen); + l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT); if (p_m_d_ntmode) enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_connectinfo.display); + end_trace(); msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); return; } if (p_state!=PORT_STATE_IN_SETUP && p_state!=PORT_STATE_IN_OVERLAP && p_state!=PORT_STATE_IN_PROCEEDING && p_state!=PORT_STATE_IN_ALERTING) { - PDEBUG(DEBUG_ISDN, "Pdss1(%s) connect command only possible in setup, proceeding or alerting state.\n", p_name); + /* connect command only possible in setup, proceeding or alerting state */ return; } /* preparing connect message */ dmsg = create_l3msg(CC_CONNECT | REQUEST, MT_CONNECT, p_m_d_l3id, sizeof(CONNECT_t), p_m_d_ntmode); - isdn_show_send_message(CC_CONNECT | REQUEST, dmsg); connect = (CONNECT_t *)(dmsg->data + headerlen); + l1l2l3_trace_header(p_m_mISDNport, this, CC_CONNECT | REQUEST, DIRECTION_OUT); /* connect information */ plan = 1; switch (p_connectinfo.ntype) @@ -2769,6 +2649,7 @@ void Pdss1::message_connect(unsigned long epoint_id, int message_id, union param epoint = find_epoint_id(epoint_id); enc_ie_date(&connect->DATE, dmsg, now, p_settings.no_seconds); } + end_trace(); /* finally send message */ msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); @@ -2790,8 +2671,8 @@ void Pdss1::message_disconnect(unsigned long epoint_id, int message_id, union pa char *p = NULL; /* we reject during incoming setup when we have no tones. also if we are in outgoing setup state */ - if ((p_state==PORT_STATE_IN_SETUP && !p_m_mISDNport->is_tones) - || p_state==PORT_STATE_OUT_SETUP) +// if ((p_state==PORT_STATE_IN_SETUP && !p_m_mISDNport->tones) +if (/* ||*/ p_state==PORT_STATE_OUT_SETUP) { /* sending release to endpoint */ while(p_epointlist) @@ -2805,25 +2686,26 @@ void Pdss1::message_disconnect(unsigned long epoint_id, int message_id, union pa } /* sending release */ dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode); - isdn_show_send_message(CC_RELEASE_COMPLETE | REQUEST, dmsg); release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen); + l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT); /* send cause */ - enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause); - new_state(PORT_STATE_RELEASE); + enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause); + end_trace(); msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); + new_state(PORT_STATE_RELEASE); p_m_delete = 1; return; } - /* NT-MODE in setup state we must send PROCEEDING first */ + /* workarround: NT-MODE in setup state we must send PROCEEDING first to make it work */ if (p_state==PORT_STATE_IN_SETUP) { CALL_PROCEEDING_t *proceeding; /* sending proceeding */ dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode); - isdn_show_send_message(CC_PROCEEDING | REQUEST, dmsg); proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen); + l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT); /* channel information */ enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel); /* progress information */ @@ -2831,29 +2713,31 @@ void Pdss1::message_disconnect(unsigned long epoint_id, int message_id, union pa || p_capainfo.bearer_capa==INFO_BC_AUDIO || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES) enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8); + end_trace(); msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); new_state(PORT_STATE_IN_PROCEEDING); } /* sending disconnect */ dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode); - isdn_show_send_message(CC_DISCONNECT | REQUEST, dmsg); disconnect = (DISCONNECT_t *)(dmsg->data + headerlen); + l1l2l3_trace_header(p_m_mISDNport, this, CC_DISCONNECT | REQUEST, DIRECTION_OUT); /* progress information */ if (p_capainfo.bearer_capa==INFO_BC_SPEECH || p_capainfo.bearer_capa==INFO_BC_AUDIO || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES) - if (p_m_mISDNport->is_tones) + if (p_m_mISDNport->tones) enc_ie_progress(&disconnect->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8); /* send cause */ - enc_ie_cause(&disconnect->CAUSE, dmsg, (p_m_d_ntmode && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause); + enc_ie_cause(&disconnect->CAUSE, dmsg, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause); /* send display */ if (param->disconnectinfo.display[0]) p = param->disconnectinfo.display; if (p) if (*p && p_m_d_ntmode) enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p); - new_state(PORT_STATE_OUT_DISCONNECT); + end_trace(); msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); + new_state(PORT_STATE_OUT_DISCONNECT); } /* MESSAGE_RELEASE */ @@ -2867,50 +2751,68 @@ void Pdss1::message_release(unsigned long epoint_id, int message_id, union param class Endpoint *epoint; char *p = NULL; - /* if we have incoming disconnected, we may release */ - if (p_state==PORT_STATE_IN_DISCONNECT - || p_state==PORT_STATE_OUT_DISCONNECT) + /* + * we may only release during incomming disconnect state. + * this means that the endpoint doesnt require audio anymore + */ + if (p_state == PORT_STATE_IN_DISCONNECT) { /* sending release */ dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, p_m_d_l3id, sizeof(RELEASE_t), p_m_d_ntmode); - isdn_show_send_message(CC_RELEASE | REQUEST, dmsg); release = (RELEASE_t *)(dmsg->data + headerlen); + l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE | REQUEST, DIRECTION_OUT); /* send cause */ - enc_ie_cause(&release->CAUSE, dmsg, (p_m_d_ntmode && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause); + enc_ie_cause(&release->CAUSE, dmsg, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause); + end_trace(); + msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); new_state(PORT_STATE_RELEASE); + /* remove epoint */ + free_epointid(epoint_id); + // wait for callref to be released + return; + + } + /* + * if we are on incoming call setup, we may reject by sending a release_complete + * also on outgoing call setup, we send a release complete, BUT this is not conform. (i don't know any other way) + */ + if (p_state==PORT_STATE_IN_SETUP + || p_state==PORT_STATE_OUT_SETUP) +// // NOTE: a bug in mISDNuser (see disconnect_req_out !!!) +// || p_state==PORT_STATE_OUT_DISCO) + { +#warning remove me +PDEBUG(DEBUG_LOG, "JOLLY sending release complete %d\n", p_serial); + /* sending release complete */ + dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode); + release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen); + l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE | REQUEST, DIRECTION_OUT); + /* send cause */ + enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause); + end_trace(); msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); + new_state(PORT_STATE_RELEASE); /* remove epoint */ - remove_endpoint: free_epointid(epoint_id); +#if 0 + /* remove process */ + l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_CR | REQUEST, DIRECTION_OUT); + add_trace("callref", NULL, "0x%x", p_m_d_l3id); + end_trace(); if (p_m_d_ntmode) { if ((p_m_d_l3id&0xff00) == 0xff00) - { p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0; - printisdn(" procid 0x%x freed\n", p_m_d_l3id&0xff); - } } p_m_d_l3id = 0; p_m_delete = 1; +#endif + // wait for callref to be released return; } - /* if we are on outgoing/incoming call setup, we may release complete */ - if (p_state==PORT_STATE_OUT_SETUP - || p_state==PORT_STATE_IN_SETUP -// NOTE: a bug in mISDNuser (see disconnect_req_out !!!) - || p_state==PORT_STATE_OUT_PROCEEDING) - { - /* sending release */ - dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode); - isdn_show_send_message(CC_RELEASE_COMPLETE | REQUEST, dmsg); - release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen); - /* send cause */ - enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause); - new_state(PORT_STATE_RELEASE); - msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); - goto remove_endpoint; - } +#if 0 +wirklich erst proceeding?: /* NT-MODE in setup state we must send PROCEEDING first */ if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP) { @@ -2919,6 +2821,7 @@ void Pdss1::message_release(unsigned long epoint_id, int message_id, union param /* sending proceeding */ dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode); proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen); + l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT); /* channel information */ enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel); /* progress information */ @@ -2926,39 +2829,37 @@ void Pdss1::message_release(unsigned long epoint_id, int message_id, union param || p_capainfo.bearer_capa==INFO_BC_AUDIO || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES) enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8); + end_trace(); msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); } +#endif /* sending disconnect */ dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode); - isdn_show_send_message(CC_DISCONNECT | REQUEST, dmsg); disconnect = (DISCONNECT_t *)(dmsg->data + headerlen); + l1l2l3_trace_header(p_m_mISDNport, this, CC_DISCONNECT | REQUEST, DIRECTION_OUT); /* progress information */ if (p_capainfo.bearer_capa==INFO_BC_SPEECH || p_capainfo.bearer_capa==INFO_BC_AUDIO || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES) - if (p_m_mISDNport->is_tones) + if (p_m_mISDNport->tones) enc_ie_progress(&disconnect->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8); /* send cause */ - enc_ie_cause(&disconnect->CAUSE, dmsg, (p_m_d_ntmode && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause); + enc_ie_cause(&disconnect->CAUSE, dmsg, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause); /* send display */ epoint = find_epoint_id(epoint_id); if (param->disconnectinfo.display[0]) p = param->disconnectinfo.display; if (p) if (*p && p_m_d_ntmode) enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p); -#if 0 - /* sending release */ - dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, p_m_d_l3id, sizeof(RELEASE_t), p_m_d_ntmode); - isdn_show_send_message(CC_RELEASE | REQUEST, dmsg); - release = (RELEASE_t *)(dmsg->data + headerlen); - /* send cause */ - enc_ie_cause(&release->CAUSE, dmsg, (p_m_d_ntmode && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause); -#endif - new_state(PORT_STATE_RELEASE); + end_trace(); msg_queue_tail(&p_m_mISDNport->downqueue, dmsg); + new_state(PORT_STATE_OUT_DISCONNECT); + /* remove epoint */ free_epointid(epoint_id); -// p_m_delete = 1; + // wait for release and callref to be released +#warning remove me +PDEBUG(DEBUG_LOG, "JOLLY sending disconnect %d\n", p_serial); } @@ -2975,14 +2876,12 @@ int Pdss1::message_epoint(unsigned long epoint_id, int message_id, union paramet switch(message_id) { case MESSAGE_INFORMATION: /* overlap dialing */ - PDEBUG(DEBUG_ISDN, "Pdss1(%s) received dialing info '%s'.\n", p_name, param->information.number); if (p_type==PORT_TYPE_DSS1_NT_OUT && p_state!=PORT_STATE_OUT_OVERLAP && p_state!=PORT_STATE_CONNECT && p_state!=PORT_STATE_OUT_DISCONNECT && p_state!=PORT_STATE_IN_DISCONNECT) { - PDEBUG(DEBUG_ISDN, "Pdss1(%s) (internal outgoing) ignoring information, invalid state.\n", p_name); break; } if (p_type==PORT_TYPE_DSS1_TE_OUT @@ -2993,8 +2892,6 @@ int Pdss1::message_epoint(unsigned long epoint_id, int message_id, union paramet && p_state!=PORT_STATE_OUT_DISCONNECT && p_state!=PORT_STATE_IN_DISCONNECT) { - if (options.deb & DEBUG_ISDN) - PERROR("Pdss1(%s) (external outgoing) ignoring information, invalid state.\n", p_name); break; } if ((p_type==PORT_TYPE_DSS1_NT_IN || p_type==PORT_TYPE_DSS1_TE_IN) @@ -3006,14 +2903,12 @@ int Pdss1::message_epoint(unsigned long epoint_id, int message_id, union paramet && p_state!=PORT_STATE_OUT_DISCONNECT && p_state!=PORT_STATE_IN_DISCONNECT) { - PDEBUG(DEBUG_ISDN, "Pdss1(%s) (incoming) ignoring information, invalid state.\n", p_name); break; } message_information(epoint_id, message_id, param); break; case MESSAGE_SETUP: /* dial-out command received from epoint */ - PDEBUG((DEBUG_ISDN | DEBUG_BCHANNEL), "Pdss1(%s) isdn port received setup from '%s' to '%s'\n", p_name, param->setup.callerinfo.id, param->setup.dialinginfo.number); if (p_state!=PORT_STATE_IDLE && p_state!=PORT_STATE_CONNECT) { @@ -3021,10 +2916,7 @@ int Pdss1::message_epoint(unsigned long epoint_id, int message_id, union paramet break; } if (p_epointlist && p_state==PORT_STATE_IDLE) - { - PERROR("Pdss1(%s): software error: epoint pointer is set in idle state, how bad!! exitting.\n", p_name); - exit(-1); - } + FATAL("Pdss1(%s): epoint pointer is set in idle state, how bad!!\n", p_name); /* note: pri is a special case, because links must be up for pri */ if (p_m_mISDNport->l1link || p_m_mISDNport->pri || !p_m_mISDNport->ntmode || p_state!=PORT_STATE_IDLE) { @@ -3037,10 +2929,7 @@ int Pdss1::message_epoint(unsigned long epoint_id, int message_id, union paramet memcpy(&p_m_d_queue->param, param, sizeof(union parameter)); /* attach us */ if (!(epointlist_new(epoint_id))) - { - PERROR("no memory for epointlist\n"); - exit(-1); - } + FATAL("No memory for epointlist\n"); /* activate link */ PDEBUG(DEBUG_ISDN, "the L1 is down, we try to establish the link NT portnum=%d (%s).\n", p_m_mISDNport->portnum, p_name); act.prim = PH_ACTIVATE | REQUEST; @@ -3048,70 +2937,61 @@ int Pdss1::message_epoint(unsigned long epoint_id, int message_id, union paramet act.dinfo = 0; act.len = 0; mISDN_write(mISDNdevice, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC); + l1l2l3_trace_header(p_m_mISDNport, this, act.prim, DIRECTION_OUT); + end_trace(); // /* set timeout */ // p_m_mISDNport->l1timeout = now+3; } break; case MESSAGE_NOTIFY: /* display and notifications */ - PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received notification: display='%s' notify=%d phone=%s\n", p_name, p_callerinfo.id, param->notifyinfo.display, param->notifyinfo.notify, param->notifyinfo.id); message_notify(epoint_id, message_id, param); break; case MESSAGE_FACILITY: /* facility message */ - PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received facility.\n", p_name, p_callerinfo.id); message_facility(epoint_id, message_id, param); break; case MESSAGE_OVERLAP: /* more information is needed */ - PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received setup acknowledge\n", p_name, p_callerinfo.id); if (p_state!=PORT_STATE_IN_SETUP) { - PDEBUG(DEBUG_ISDN, "Pdss1(%s) ignoring setup acknowledge because isdn port is not incoming setup state.\n", p_name); break; } message_overlap(epoint_id, message_id, param); break; case MESSAGE_PROCEEDING: /* call of endpoint is proceeding */ - PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received proceeding\n", p_name, p_callerinfo.id); if (p_state!=PORT_STATE_IN_SETUP && p_state!=PORT_STATE_IN_OVERLAP) { - PDEBUG(DEBUG_ISDN, "Pdss1(%s) ignoring: proceeding command not possible in current state.\n", p_name); break; } message_proceeding(epoint_id, message_id, param); break; case MESSAGE_ALERTING: /* call of endpoint is ringing */ - PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received alerting\n", p_name, p_callerinfo.id); if (p_state!=PORT_STATE_IN_SETUP && p_state!=PORT_STATE_IN_OVERLAP && p_state!=PORT_STATE_IN_PROCEEDING) { - PDEBUG(DEBUG_ISDN, "Pdss1(%s) ignoring: alerting command not possible in current state.\n", p_name); break; } message_alerting(epoint_id, message_id, param); break; case MESSAGE_CONNECT: /* call of endpoint is connected */ - PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received connect\n", p_name, p_callerinfo.id); if (p_state!=PORT_STATE_IN_SETUP && p_state!=PORT_STATE_IN_OVERLAP && p_state!=PORT_STATE_IN_PROCEEDING && p_state!=PORT_STATE_IN_ALERTING && !(p_state==PORT_STATE_CONNECT && p_m_d_ntmode)) { - PDEBUG(DEBUG_ISDN, "Pdss1(%s) ignoring: connect command not possible in current state.\n", p_name); break; } message_connect(epoint_id, message_id, param); break; case MESSAGE_DISCONNECT: /* call has been disconnected */ - PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received disconnect cause=%d\n", p_name, p_callerinfo.id, param->disconnectinfo.cause); if (p_state!=PORT_STATE_IN_SETUP && p_state!=PORT_STATE_IN_OVERLAP && p_state!=PORT_STATE_IN_PROCEEDING @@ -3123,24 +3003,21 @@ int Pdss1::message_epoint(unsigned long epoint_id, int message_id, union paramet && p_state!=PORT_STATE_CONNECT && p_state!=PORT_STATE_CONNECT_WAITING) { - PDEBUG(DEBUG_ISDN, "Pdss1(%s) ignoring: disconnect command not possible in current state.\n", p_name); break; } message_disconnect(epoint_id, message_id, param); break; case MESSAGE_RELEASE: /* release isdn port */ - PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received release cause=%d\n", p_name, p_callerinfo.id, param->disconnectinfo.cause); if (p_state==PORT_STATE_RELEASE) { - PDEBUG(DEBUG_ISDN, "Pdss1(%s) ignoring: release command not possible in RELEASE state.\n", p_name); break; } message_release(epoint_id, message_id, param); break; default: - PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received a wrong message: %d\n", p_name, p_callerinfo.id, message); + PERROR("Pdss1(%s) isdn port with (caller id %s) received a wrong message: %d\n", p_name, p_callerinfo.id, message); } return(1); @@ -3225,7 +3102,9 @@ int stack2manager_nt(void *dat, void *arg) case DL_ESTABLISH | INDICATION: case DL_ESTABLISH | CONFIRM: ss_estab: - PDEBUG(DEBUG_ISDN, "establish data link (DL) NT portnum=%d TEI=%d\n", mISDNport->portnum, hh->dinfo); + l1l2l3_trace_header(mISDNport, NULL, hh->prim, DIRECTION_IN); + add_trace("tei", NULL, "%d", hh->dinfo); + end_trace(); if (mISDNport->ptp && hh->dinfo == 0) { if (mISDNport->l2establish) @@ -3242,7 +3121,9 @@ int stack2manager_nt(void *dat, void *arg) case DL_RELEASE | INDICATION: case DL_RELEASE | CONFIRM: ss_rel: - PDEBUG(DEBUG_ISDN, "release data link (DL) NT portnum=%d TEI=%d\n", mISDNport->portnum, hh->dinfo); + l1l2l3_trace_header(mISDNport, NULL, hh->prim, DIRECTION_IN); + add_trace("tei", NULL, "%d", hh->dinfo); + end_trace(); if (mISDNport->ptp && hh->dinfo == 0) { mISDNport->l2link = 0; @@ -3255,47 +3136,28 @@ int stack2manager_nt(void *dat, void *arg) /* creating port object */ SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum); if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0))) - { - RELEASE_COMPLETE_t *release_complete; - msg_t *dmsg; - fprintf(stderr, "FATAL ERROR: cannot create port object.\n"); - dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, hh->dinfo, sizeof(RELEASE_COMPLETE_t), mISDNport->ntmode); - release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + mISDN_HEADER_LEN); - enc_ie_cause_standalone(mISDNport->ntmode?&release_complete->CAUSE:NULL, dmsg, (mISDNport->ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47); - msg_queue_tail(&mISDNport->downqueue, dmsg); - break; - } + FATAL("Cannot create Port instance.\n"); pdss1->message_isdn(hh->prim, hh->dinfo, msg->data); break; case CC_RESUME | INDICATION: /* creating port object */ SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum); - if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL))) - { - SUSPEND_REJECT_t *suspend_reject; - msg_t *dmsg; - - fprintf(stderr, "FATAL ERROR: cannot create port object.\n"); - dmsg = create_l3msg(CC_SUSPEND_REJECT | REQUEST, MT_SUSPEND_REJECT, hh->dinfo, sizeof(SUSPEND_REJECT_t), mISDNport->ntmode); - suspend_reject = (SUSPEND_REJECT_t *)(dmsg->data + mISDN_HEADER_LEN); - enc_ie_cause_standalone(mISDNport->ntmode?&suspend_reject->CAUSE:NULL, dmsg, (mISDNport->ntmode)?1:0, 47); - msg_queue_tail(&mISDNport->downqueue, dmsg); - break; - } + if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0))) + FATAL("Cannot create Port instance.\n"); pdss1->message_isdn(hh->prim, hh->dinfo, msg->data); break; case CC_RELEASE_CR | INDICATION: - PDEBUG(DEBUG_ISDN, "%s: unhandled message from stack: call ref released (l3id=0x%x)\n", __FUNCTION__, hh->dinfo); + PERROR("unhandled message from stack: call ref released (l3id=0x%x)\n", hh->dinfo); break; case CC_DISCONNECT | INDICATION: // fall throug default: - PDEBUG(DEBUG_ISDN, "%s: unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", __FUNCTION__, hh->prim, hh->dinfo, msg->len); + PERROR("unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", hh->prim, hh->dinfo, msg->len); return(-EINVAL); } free_msg(msg); @@ -3322,7 +3184,6 @@ int stack2manager_te(struct mISDNport *mISDNport, msg_t *msg) if (port->p_type == PORT_TYPE_DSS1_TE_IN || port->p_type == PORT_TYPE_DSS1_TE_OUT) { pdss1 = (class Pdss1 *)port; -//PDEBUG(DEBUG_ISDN, "comparing dinfo = 0x%x with l3id 0x%x\n", frm->dinfo, pdss1->p_m_d_l3id); /* check out correct stack */ if (pdss1->p_m_mISDNport == mISDNport) /* check out correct id */ @@ -3348,19 +3209,8 @@ int stack2manager_te(struct mISDNport *mISDNport, msg_t *msg) /* creating port object */ SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum); - if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_TE_IN, mISDNport, name, NULL))) - { - RELEASE_COMPLETE_t *release_complete; - msg_t *dmsg; - - fprintf(stderr, "FATAL ERROR: cannot create port object.\n"); - dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, frm->dinfo, sizeof(RELEASE_COMPLETE_t), mISDNport->ntmode); - release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + mISDN_HEADER_LEN); - enc_ie_cause_standalone(mISDNport->ntmode?&release_complete->CAUSE:NULL, dmsg, (mISDNport->ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47); - msg_queue_tail(&mISDNport->downqueue, dmsg); - free_msg(msg); - return(0); - } + if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_TE_IN, mISDNport, name, NULL, 0, 0))) + FATAL("Cannot create Port instance.\n"); /* l3id will be set from dinfo at message_isdn */ pdss1->message_isdn(frm->prim, frm->dinfo, msg->data); free_msg(msg); @@ -3369,11 +3219,11 @@ int stack2manager_te(struct mISDNport *mISDNport, msg_t *msg) if (frm->prim == (CC_RELEASE_CR | INDICATION)) { - PDEBUG(DEBUG_ISDN, "unhandled message from stack: call ref released (l3id=0x%x)\n", frm->dinfo); + PERROR("unhandled message from stack: call ref released (l3id=0x%x)\n", frm->dinfo); free_msg(msg); return(0); } - PDEBUG(DEBUG_ISDN, "unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", frm->prim, frm->dinfo, msg->len); + PERROR("unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", frm->prim, frm->dinfo, msg->len); return(-EINVAL); }