1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
10 \*****************************************************************************/
20 #include <sys/ioctl.h>
21 #include <sys/types.h>
37 Pdss1::Pdss1(int type, mISDNport *mISDNport, char *portname, struct port_settings *settings, int channel, int exclusive) : PmISDN(type, mISDNport, portname, settings, channel, exclusive)
39 p_callerinfo.itype = (mISDNport->ifport->interface->extension)?INFO_ITYPE_ISDN:INFO_ITYPE_ISDN_EXTENSION;
40 p_m_d_ntmode = mISDNport->ntmode;
44 p_m_d_notify_pending = NULL;
45 p_m_d_collect_cause = CAUSE_NOUSER;
46 p_m_d_collect_location = LOCATION_PRIVATE_LOCAL;
49 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);
58 /* remove queued message */
60 message_free(p_m_d_queue);
62 if (p_m_d_notify_pending)
63 message_free(p_m_d_notify_pending);
65 /* check how many processes are left */
66 if (p_m_d_ntmode == 1)
68 if (p_m_mISDNport->nst.layer3->proc)
69 PDEBUG(DEBUG_ISDN, "destroyed mISDNPort(%s). WARNING: There is still a layer 3 process left. Ignore this, if currently are other calls. This message is not an error!\n", p_name);
75 * create layer 3 message
77 static msg_t *create_l3msg(int prim, int mt, int dinfo, int size, int ntmode)
85 size = sizeof(Q931_info_t)+2;
91 dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL);
98 dmsg = alloc_msg(size+256+mISDN_HEADER_LEN+DEFAULT_HEADROOM);
101 memset(msg_put(dmsg,size+mISDN_HEADER_LEN), 0, size+mISDN_HEADER_LEN);
102 frm = (iframe_t *)dmsg->data;
105 qi = (Q931_info_t *)(dmsg->data + mISDN_HEADER_LEN);
112 PERROR("cannot allocate memory, trying again...\n");
116 PERROR("cannot allocate memory, system overloaded.\n");
120 msg_t *create_l2msg(int prim, int dinfo, int size) /* NT only */
127 dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL);
132 PERROR("cannot allocate memory, trying again...\n");
136 PERROR("cannot allocate memory, system overloaded.\n");
141 static struct isdn_message {
145 {"TIMEOUT", CC_TIMEOUT},
147 {"SETUP_ACK", CC_SETUP_ACKNOWLEDGE},
148 {"PROCEEDING", CC_PROCEEDING},
149 {"ALERTING", CC_ALERTING},
150 {"CONNECT", CC_CONNECT},
151 {"CONNECT RES", CC_CONNECT},
152 {"CONNECT_ACK", CC_CONNECT_ACKNOWLEDGE},
153 {"DISCONNECT", CC_DISCONNECT},
154 {"RELEASE", CC_RELEASE},
155 {"RELEASE_COMP", CC_RELEASE_COMPLETE},
156 {"INFORMATION", CC_INFORMATION},
157 {"PROGRESS", CC_PROGRESS},
158 {"NOTIFY", CC_NOTIFY},
159 {"SUSPEND", CC_SUSPEND},
160 {"SUSPEND_ACK", CC_SUSPEND_ACKNOWLEDGE},
161 {"SUSPEND_REJ", CC_SUSPEND_REJECT},
162 {"RESUME", CC_RESUME},
163 {"RESUME_ACK", CC_RESUME_ACKNOWLEDGE},
164 {"RESUME_REJ", CC_RESUME_REJECT},
166 {"HOLD_ACK", CC_HOLD_ACKNOWLEDGE},
167 {"HOLD_REJ", CC_HOLD_REJECT},
168 {"RETRIEVE", CC_RETRIEVE},
169 {"RETRIEVE_ACK", CC_RETRIEVE_ACKNOWLEDGE},
170 {"RETRIEVE_REJ", CC_RETRIEVE_REJECT},
171 {"FACILITY", CC_FACILITY},
172 {"STATUS", CC_STATUS},
173 {"RESTART", CC_RESTART},
174 {"RELEASE_CR", CC_RELEASE_CR},
175 {"NEW_CR", CC_NEW_CR},
180 static char *isdn_prim[4] = {
191 void Pdss1::l3_trace_header(unsigned long prim, int direction_out)
194 char msgtext[64] = "<<UNKNOWN MESSAGE>>";
196 /* select message and primitive text */
198 while(isdn_message[i].name)
200 if (isdn_message[i].value == (prim&0xffffff00))
202 SCPY(msgtext, isdn_message[i].name);
207 SCAT(msgtext, isdn_prim[prim&0x00000003]);
210 if (direction && (prim&0xffffff00)!=CC_NEW_CR && (prim&0xffffff00)!=CC_RELEASE_CR)
214 if (direction == DIRECTION_OUT)
215 SCAT(msgtext, " N->U");
217 SCAT(msgtext, " N<-U");
220 if (direction == DIRECTION_OUT)
221 SCAT(msgtext, " U->N");
223 SCAT(msgtext, " U<-N");
227 /* init trace with given values */
228 start_trace(p_m_mISDNport->portnum,
229 p_m_mISDNport->ifport->interface,
230 nationalize(p_callerinfo.id, p_callerinfo.ntype),
231 p_dialinginfo.number,
239 * if we received a first reply to the setup message,
240 * we will check if we have now channel information
241 * return: <0: error, call is released, -cause is given
242 * 0: ok, nothing to do
244 int Pdss1::received_first_reply_to_setup(unsigned long prim, int channel, int exclusive)
247 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
248 RELEASE_COMPLETE_t *release_complete;
251 /* correct exclusive to 0, if no explicit channel was given */
252 if (exclusive<0 || channel<=0)
255 /* select scenario */
256 if (p_m_b_channel && p_m_b_exclusive)
258 /*** we gave an exclusive channel (or if we are done) ***/
260 /* if not first reply, we are done */
261 if (p_state != PORT_STATE_OUT_SETUP)
264 start_trace(p_m_mISDNport->portnum,
265 p_m_mISDNport->ifport->interface,
266 nationalize(p_callerinfo.id, p_callerinfo.ntype),
267 p_dialinginfo.number,
270 "CHANNEL SELECTION (first reply to setup)");
271 add_trace("channel", "request", "%d (forced)", p_m_b_channel);
272 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
274 /* if give channel not accepted or not equal */
275 if (channel!=-1 && p_m_b_channel!=channel)
277 add_trace("conclusion", NULL, "forced channel not accepted");
283 add_trace("conclusion", NULL, "channel was accepted");
284 add_trace("connect", "channel", "%d", p_m_b_channel);
287 /* activate our exclusive channel */
288 bchannel_activate(p_m_mISDNport, p_m_b_index);
292 /*** we gave a non-exclusive channel ***/
294 /* if not first reply, we are done */
295 if (p_state != PORT_STATE_OUT_SETUP)
298 start_trace(p_m_mISDNport->portnum,
299 p_m_mISDNport->ifport->interface,
300 nationalize(p_callerinfo.id, p_callerinfo.ntype),
301 p_dialinginfo.number,
304 "CHANNEL SELECTION (first reply to setup)");
305 add_trace("channel", "request", "%d (suggest)", p_m_b_channel);
306 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
308 /* if channel was accepted as given */
309 if (channel==-1 || p_m_b_channel==channel)
311 add_trace("conclusion", NULL, "channel was accepted as given");
312 add_trace("connect", "channel", "%d", p_m_b_channel);
314 p_m_b_exclusive = 1; // we are done
315 bchannel_activate(p_m_mISDNport, p_m_b_index);
319 /* if channel value is faulty */
322 add_trace("conclusion", NULL, "illegal reply");
324 ret = -111; // protocol error
328 /* if channel was not accepted, try to get it */
329 PDEBUG(DEBUG_BCHANNEL, "- our suggested channel %d was not accepted, but %d was given.\n", p_m_b_channel, channel);
330 ret = seize_bchannel(channel, 1); // exclusively
331 add_trace("channel", "available", ret<0?"no":"yes");
334 add_trace("conclusion", NULL, "replied channel not available");
336 PDEBUG(DEBUG_BCHANNEL, "- the replied channel %d is not available (cause %d).\n", channel, -ret);
339 add_trace("conclusion", NULL, "replied channel accepted");
340 add_trace("connect", "channel", "%d", p_m_b_channel);
343 /* activate channel given by remote */
344 bchannel_activate(p_m_mISDNport, p_m_b_index);
348 /*** we sent 'any channel acceptable' ***/
350 /* if not first reply, we are done */
351 if (p_state != PORT_STATE_OUT_SETUP)
354 start_trace(p_m_mISDNport->portnum,
355 p_m_mISDNport->ifport->interface,
356 nationalize(p_callerinfo.id, p_callerinfo.ntype),
357 p_dialinginfo.number,
360 "CHANNEL SELECTION (first reply to setup)");
361 add_trace("channel", "request", "any");
362 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
363 /* if no channel was replied */
366 add_trace("conclusion", NULL, "no channel, protocol error");
368 ret = -111; // protocol error
372 /* we will see, if our received channel is available */
373 ret = seize_bchannel(channel, 1); // exclusively
374 add_trace("channel", "available", ret<0?"no":"yes");
377 add_trace("conclusion", NULL, "replied channel not available");
381 add_trace("conclusion", NULL, "replied channel accepted");
382 add_trace("connect", "channel", "%d", p_m_b_channel);
385 /* activate channel given by remote */
386 bchannel_activate(p_m_mISDNport, p_m_b_index);
389 /*** we sent 'no channel available' ***/
391 /* if not the first reply, but a connect, we are forced */
392 if (prim==(CC_CONNECT | INDICATION) && p_state!=PORT_STATE_OUT_SETUP)
394 start_trace(p_m_mISDNport->portnum,
395 p_m_mISDNport->ifport->interface,
396 nationalize(p_callerinfo.id, p_callerinfo.ntype),
397 p_dialinginfo.number,
400 "CHANNEL SELECTION (connect)");
401 add_trace("channel", "request", "no-channel");
402 add_trace("channel", "reply", (channel>=0)?"%d%s":"(none)", channel, exclusive?" (forced)":"");
405 goto use_from_connect;
407 ret = seize_bchannel(CHANNEL_ANY, 0); // any channel
408 add_trace("channel", "available", ret<0?"no":"yes");
411 add_trace("conclusion", NULL, "no channel available during call-waiting");
415 add_trace("conclusion", NULL, "using channel %d", p_m_b_channel);
416 add_trace("connect", "channel", "%d", p_m_b_channel);
418 p_m_b_exclusive = 1; // we are done
420 /* activate channel given by remote */
421 bchannel_activate(p_m_mISDNport, p_m_b_index);
425 /* if not first reply, we are done */
426 if (p_state != PORT_STATE_OUT_SETUP)
429 start_trace(p_m_mISDNport->portnum,
430 p_m_mISDNport->ifport->interface,
431 nationalize(p_callerinfo.id, p_callerinfo.ntype),
432 p_dialinginfo.number,
435 "CHANNEL SELECTION (first reply to setup)");
436 add_trace("channel", "request", "no-channel");
437 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
438 /* if first reply has no channel, we are done */
441 add_trace("conclusion", NULL, "no channel until connect");
446 /* we will see, if our received channel is available */
447 PDEBUG(DEBUG_BCHANNEL, "- our during call-waiting, we get channel %d as first reply.\n", channel);
449 ret = seize_bchannel(channel, exclusive);
450 add_trace("channel", "available", ret<0?"no":"yes");
453 add_trace("conclusion", NULL, "replied channel not available");
457 add_trace("conclusion", NULL, "replied channel accepted");
458 add_trace("connect", "channel", "%d", p_m_b_channel);
460 p_m_b_exclusive = 1; // we are done
462 /* activate channel given by remote */
463 bchannel_activate(p_m_mISDNport, p_m_b_index);
468 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
469 l3_trace_header(CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
471 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
472 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
474 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
475 new_state(PORT_STATE_RELEASE);
477 return(-34); /* to epoint: no channel available */
482 * handles all indications
484 /* CC_SETUP INDICATION */
485 void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
487 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
488 SETUP_t *setup = (SETUP_t *)((unsigned long)data + headerlen);
489 int type, plan, present, screen, reason;
490 int coding, capability, mode, rate, multi, user, presentation, interpretation, hlc, exthlc;
491 int exclusive, channel;
494 unsigned char keypad[32] = "";
495 unsigned char useruser[128];
496 int useruser_len = 0, useruser_protocol;
497 class Endpoint *epoint;
498 struct message *message;
500 /* callref from nt-lib */
503 /* nt-library now gives us the id via CC_SETUP */
504 if (dinfo&(~0xff) == 0xff00)
506 PERROR("fatal software error: l3-stack gives us a process id 0xff00-0xffff\n");
509 l3_trace_header(CC_NEW_CR | INDICATION, DIRECTION_IN);
511 add_trace("callref", "old", "0x%x", p_m_d_l3id);
512 add_trace("callref", "new", "0x%x", dinfo);
514 if (p_m_d_l3id&(~0xff) == 0xff00)
515 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
517 p_m_d_ces = setup->ces;
520 l3_trace_header(prim, DIRECTION_IN);
521 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));
522 dec_ie_called_pn(setup->CALLED_PN, (Q931_info_t *)((unsigned long)data+headerlen), &called_type, &called_plan, (unsigned char *)p_dialinginfo.number, sizeof(p_dialinginfo.number));
523 dec_ie_keypad(setup->KEYPAD, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)keypad, sizeof(keypad));
525 /* te-mode: CNIP (calling name identification presentation) */
527 dec_facility_centrex(setup->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)p_callerinfo.name, sizeof(p_callerinfo.name));
529 dec_ie_useruser(setup->USER_USER, (Q931_info_t *)((unsigned long)data+headerlen), &useruser_protocol, useruser, &useruser_len);
530 dec_ie_complete(setup->COMPLETE, (Q931_info_t *)((unsigned long)data+headerlen), &p_dialinginfo.sending_complete);
531 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));
532 dec_ie_channel_id(setup->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
533 dec_ie_hlc(setup->HLC, (Q931_info_t *)((unsigned long)data+headerlen), &hlc_coding, &interpretation, &presentation, &hlc, &exthlc);
534 dec_ie_bearer(setup->BEARER, (Q931_info_t *)((unsigned long)data+headerlen), &bearer_coding, &capability, &mode, &rate, &multi, &user);
537 /* if blocked, release call */
538 if (p_m_mISDNport->ifport->block)
540 RELEASE_COMPLETE_t *release_complete;
542 printlog("--- port#%d is blocked.\n", mISDNport->ifport->portnum);
543 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
544 l3_trace_header(CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
545 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
546 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 27); /* temporary unavailable */
547 add_trace("reason", NULL, "port blocked");
549 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
550 new_state(PORT_STATE_RELEASE);
559 p_callerinfo.present = INFO_PRESENT_RESTRICTED;
562 p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
565 p_callerinfo.present = INFO_PRESENT_ALLOWED;
571 p_callerinfo.screen = INFO_SCREEN_USER;
574 p_callerinfo.screen = INFO_SCREEN_NETWORK;
580 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
581 p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
582 p_callerinfo.screen = INFO_SCREEN_NETWORK;
585 p_callerinfo.ntype = INFO_NTYPE_INTERNATIONAL;
588 p_callerinfo.ntype = INFO_NTYPE_NATIONAL;
591 p_callerinfo.ntype = INFO_NTYPE_SUBSCRIBER;
594 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
597 p_callerinfo.isdn_port = p_m_portnum;
598 SCPY(p_callerinfo.interface, p_m_mISDNport->ifport->interface->name);
600 /* dialing information */
601 SCAT(p_dialinginfo.number, (char *)keypad);
605 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
608 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
611 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
614 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
620 p_redirinfo.present = INFO_PRESENT_RESTRICTED;
623 p_redirinfo.present = INFO_PRESENT_NOTAVAIL;
626 p_redirinfo.present = INFO_PRESENT_ALLOWED;
632 p_redirinfo.screen = INFO_SCREEN_USER;
635 p_redirinfo.screen = INFO_SCREEN_NETWORK;
641 p_redirinfo.reason = INFO_REDIR_BUSY;
644 p_redirinfo.reason = INFO_REDIR_NORESPONSE;
647 p_redirinfo.reason = INFO_REDIR_UNCONDITIONAL;
650 p_redirinfo.reason = INFO_REDIR_CALLDEFLECT;
653 p_redirinfo.reason = INFO_REDIR_OUTOFORDER;
656 p_redirinfo.reason = INFO_REDIR_UNKNOWN;
662 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
663 p_redirinfo.present = INFO_PRESENT_NULL; /* not redirecting */
664 p_redirinfo.reason = INFO_REDIR_UNKNOWN;
667 p_redirinfo.ntype = INFO_NTYPE_INTERNATIONAL;
670 p_redirinfo.ntype = INFO_NTYPE_NATIONAL;
673 p_redirinfo.ntype = INFO_NTYPE_SUBSCRIBER;
676 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
679 p_redirinfo.isdn_port = p_m_portnum;
681 /* bearer capability */
685 p_capainfo.bearer_capa = INFO_BC_AUDIO;
686 user = (options.law=='a')?3:2;
689 p_capainfo.bearer_capa = capability;
695 p_capainfo.bearer_mode = INFO_BMODE_PACKET;
698 p_capainfo.bearer_mode = INFO_BMODE_CIRCUIT;
704 p_capainfo.bearer_info1 = INFO_INFO1_NONE;
707 p_capainfo.bearer_info1 = user + 0x80;
715 p_capainfo.hlc = INFO_HLC_NONE;
718 p_capainfo.hlc = hlc + 0x80;
724 p_capainfo.exthlc = INFO_HLC_NONE;
727 p_capainfo.exthlc = exthlc + 0x80;
731 /* process channel */
732 start_trace(p_m_mISDNport->portnum,
733 p_m_mISDNport->ifport->interface,
734 nationalize(p_callerinfo.id, p_callerinfo.ntype),
735 p_dialinginfo.number,
738 "CHANNEL SELECTION (setup)");
741 if (channel == CHANNEL_NO)
742 add_trace("channel", "request", "no-channel");
744 add_trace("channel", "request", (channel>0)?"%d%s":"any", channel, exclusive?" (forced)":"");
745 if (channel==CHANNEL_NO && p_type==PORT_TYPE_DSS1_TE_IN)
747 add_trace("conclusion", NULL, "incoming call-waiting not supported for TE-mode");
749 ret = -6; // channel unacceptable
752 if (channel <= 0) /* not given, no channel, whatever.. */
753 channel = CHANNEL_ANY; /* any channel */
754 if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num) // of out chan..
756 add_trace("channel", "reserved", "%d", p_m_mISDNport->b_reserved);
757 add_trace("conclusion", NULL, "all channels are reserved");
759 ret = -34; // no channel
762 if (channel == CHANNEL_ANY)
766 /* check for given channel in selection list */
767 selchannel = ifport->channel_in;
770 if (selchannel->channel == channel || selchannel->channel == CHANNEL_FREE)
772 selchannel = selchannel->next;
777 /* exclusive channel requests must be in the list */
782 add_trace("conclusion", NULL, "exclusively requested channel not in list");
784 ret = 6; // unacceptable
787 i = selchannel->channel-1-(selchannel->channel>=17);
788 if (mISDNport->b_port[i] == NULL)
790 add_trace("conclusion", NULL, "exclusively requested channel is busy");
792 ret = 6; // unacceptable
796 /* requested channels in list will be used */
799 i = selchannel->channel-1-(selchannel->channel>=17);
800 if (mISDNport->b_port[i] == NULL)
804 /* if channel is not available or not in list, it must be searched */
806 /* check for first free channel in list */
808 selchannel = ifport->channel_in;
811 switch(selchannel->channel)
813 case CHANNEL_FREE: /* free channel */
814 add_trace("hunting", "channel", "free");
815 if (mISDNport->b_inuse >= mISDNport->b_num)
816 break; /* all channel in use or reserverd */
819 while(i < mISDNport->b_num)
821 if (mISDNport->b_port[i] == NULL)
823 channel = i+1+(i>=15);
831 add_trace("hunting", "channel", "%d", selchannel->channel);
832 if (selchannel->channel<1 || selchannel->channel==16)
833 break; /* invalid channels */
834 i = selchannel->channel-1-(selchannel->channel>=17);
835 if (i >= mISDNport->b_num)
836 break; /* channel not in port */
837 if (mISDNport->b_port[i] == NULL)
839 channel = selchannel->channel;
845 break; /* found channel */
846 selchannel = selchannel->next;
850 add_trace("conclusion", NULL, "no channel available");
852 ret = 6; // unacceptable
859 ret = seize_bchannel(channel, 1);
862 add_trace("conclusion", NULL, "channel not available");
865 RELEASE_COMPLETE_t *release_complete;
867 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
868 l3_trace_header(CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
869 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
870 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
872 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
873 new_state(PORT_STATE_RELEASE);
877 add_trace("conclusion", NULL, "channel available");
878 add_trace("connect", "channel", "%d", p_m_b_channel);
880 bchannel_activate(p_m_mISDNport, p_m_b_index);
882 /* create endpoint */
885 PERROR("SOFTWARE ERROR: incoming call but already got an endpoint, exitting...\n");
888 if (!(epoint = new Endpoint(p_serial, 0)))
890 RELEASE_COMPLETE_t *release_complete;
892 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
893 l3_trace_header(CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
894 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
895 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 41); /* temporary failure */
897 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
898 new_state(PORT_STATE_RELEASE);
902 if (!(epoint->ep_app = new DEFAULT_ENDPOINT_APP(epoint)))
904 PERROR("no memory for application\n");
907 if (!(epointlist_new(epoint->ep_serial)))
909 PERROR("no memory for epointlist\n");
912 /* send setup message to endpoit */
913 PDEBUG(DEBUG_ISDN, "Pdss1(%s) setup: %s->%s\n", p_name, p_callerinfo.id, p_dialinginfo.number);
914 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_SETUP);
915 message->param.setup.isdn_port = p_m_portnum;
916 message->param.setup.port_type = p_type;
917 memcpy(&message->param.setup.dialinginfo, &p_dialinginfo, sizeof(struct dialing_info));
918 memcpy(&message->param.setup.callerinfo, &p_callerinfo, sizeof(struct caller_info));
919 memcpy(&message->param.setup.redirinfo, &p_redirinfo, sizeof(struct redir_info));
920 memcpy(&message->param.setup.capainfo, &p_capainfo, sizeof(struct capa_info));
921 memcpy(message->param.setup.useruser.data, &useruser, useruser_len);
922 message->param.setup.useruser.len = useruser_len;
923 message->param.setup.useruser.protocol = useruser_protocol;
924 message_put(message);
926 new_state(PORT_STATE_IN_SETUP);
929 /* CC_INFORMATION INDICATION */
930 void Pdss1::information_ind(unsigned long prim, unsigned long dinfo, void *data)
932 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
933 INFORMATION_t *information = (INFORMATION_t *)((unsigned long)data + headerlen);
935 unsigned char keypad[32] = "";
936 struct message *message;
938 l3_trace_header(prim, DIRECTION_IN);
939 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));
940 dec_ie_keypad(information->KEYPAD, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)keypad, sizeof(keypad));
941 dec_ie_complete(information->COMPLETE, (Q931_info_t *)((unsigned long)data+headerlen), &p_dialinginfo.sending_complete);
944 SCAT(p_dialinginfo.number, (char *)keypad);
948 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
951 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
954 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
957 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
960 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_INFORMATION);
961 memcpy(&message->param.information, &p_dialinginfo, sizeof(struct dialing_info));
962 message_put(message);
963 /* reset overlap timeout */
967 /* CC_SETUP_ACCNOWLEDGE INDICATION */
968 void Pdss1::setup_acknowledge_ind(unsigned long prim, unsigned long dinfo, void *data)
970 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
971 SETUP_ACKNOWLEDGE_t *setup_acknowledge = (SETUP_ACKNOWLEDGE_t *)((unsigned long)data + headerlen);
972 int exclusive, channel;
973 int coding, location, progress;
975 struct message *message;
977 l3_trace_header(prim, DIRECTION_IN);
978 dec_ie_channel_id(setup_acknowledge->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
979 dec_ie_progress(setup_acknowledge->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
982 /* process channel */
983 ret = received_first_reply_to_setup(prim, exclusive, channel);
986 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
987 message->param.disconnectinfo.cause = -ret;
988 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
989 message_put(message);
990 new_state(PORT_STATE_RELEASE);
995 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_OVERLAP);
996 message_put(message);
998 new_state(PORT_STATE_OUT_OVERLAP);
1001 /* CC_PROCEEDING INDICATION */
1002 void Pdss1::proceeding_ind(unsigned long prim, unsigned long dinfo, void *data)
1004 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1005 CALL_PROCEEDING_t *proceeding = (CALL_PROCEEDING_t *)((unsigned long)data + headerlen);
1006 int exclusive, channel;
1007 int coding, location, progress;
1009 struct message *message;
1010 int notify = -1, type, plan, present;
1013 l3_trace_header(prim, DIRECTION_IN);
1014 dec_ie_channel_id(proceeding->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
1015 dec_ie_progress(proceeding->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
1016 dec_ie_notify(NULL/*proceeding->NOTIFY*/, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
1017 dec_ie_redir_dn(proceeding->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
1020 ret = received_first_reply_to_setup(prim, exclusive, channel);
1023 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1024 message->param.disconnectinfo.cause = -ret;
1025 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1026 message_put(message);
1027 new_state(PORT_STATE_RELEASE);
1031 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROCEEDING);
1032 message_put(message);
1034 new_state(PORT_STATE_OUT_PROCEEDING);
1040 if (type >= 0 || notify)
1042 if (!notify && type >= 0)
1044 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1045 message->param.notifyinfo.notify = notify;
1046 SCPY(message->param.notifyinfo.id, redir);
1047 /* redirection number */
1051 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1054 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1057 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1063 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1064 message->param.notifyinfo.present = INFO_PRESENT_NULL;
1067 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1070 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1073 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1076 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1079 message->param.notifyinfo.isdn_port = p_m_portnum;
1080 message_put(message);
1084 /* CC_ALERTING INDICATION */
1085 void Pdss1::alerting_ind(unsigned long prim, unsigned long dinfo, void *data)
1087 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1088 ALERTING_t *alerting = (ALERTING_t *)((unsigned long)data + headerlen);
1089 int exclusive, channel;
1090 int coding, location, progress;
1092 struct message *message;
1093 int notify = -1, type, plan, present;
1096 l3_trace_header(prim, DIRECTION_IN);
1097 dec_ie_channel_id(alerting->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
1098 dec_ie_progress(alerting->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
1099 dec_ie_notify(NULL/*alerting->NOTIFY*/, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
1100 dec_ie_redir_dn(alerting->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
1103 /* process channel */
1104 ret = received_first_reply_to_setup(prim, exclusive, channel);
1107 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1108 message->param.disconnectinfo.cause = -ret;
1109 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1110 message_put(message);
1111 new_state(PORT_STATE_RELEASE);
1115 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_ALERTING);
1116 message_put(message);
1118 new_state(PORT_STATE_OUT_ALERTING);
1124 if (type >= 0 || notify)
1126 if (!notify && type >= 0)
1128 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1129 message->param.notifyinfo.notify = notify;
1130 SCPY(message->param.notifyinfo.id, redir);
1134 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1137 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1140 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1146 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1147 message->param.notifyinfo.present = INFO_PRESENT_NULL;
1150 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1153 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1156 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1159 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1162 message->param.notifyinfo.isdn_port = p_m_portnum;
1163 message_put(message);
1167 /* CC_CONNECT INDICATION */
1168 void Pdss1::connect_ind(unsigned long prim, unsigned long dinfo, void *data)
1170 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1171 CONNECT_t *connect = (CONNECT_t *)((unsigned long)data + headerlen);
1172 int exclusive, channel;
1173 int type, plan, present, screen;
1176 struct message *message;
1177 int bchannel_before;
1178 CONNECT_ACKNOWLEDGE_t *connect_acknowledge;
1181 p_m_d_ces = connect->ces;
1183 l3_trace_header(prim, DIRECTION_IN);
1184 dec_ie_channel_id(connect->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
1185 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));
1187 /* te-mode: CONP (connected name identification presentation) */
1189 dec_facility_centrex(connect->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)p_connectinfo.name, sizeof(p_connectinfo.name));
1193 /* select channel */
1194 bchannel_before = p_m_b_channel;
1195 ret = received_first_reply_to_setup(prim, exclusive, channel);
1198 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1199 message->param.disconnectinfo.cause = -ret;
1200 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1201 message_put(message);
1202 new_state(PORT_STATE_RELEASE);
1207 /* connect information */
1211 p_connectinfo.present = INFO_PRESENT_RESTRICTED;
1214 p_connectinfo.present = INFO_PRESENT_NOTAVAIL;
1217 p_connectinfo.present = INFO_PRESENT_ALLOWED;
1223 p_connectinfo.screen = INFO_SCREEN_USER;
1226 p_connectinfo.screen = INFO_SCREEN_NETWORK;
1232 p_connectinfo.present = INFO_PRESENT_NULL; /* no COLP info */
1233 p_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1236 p_connectinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1239 p_connectinfo.ntype = INFO_NTYPE_NATIONAL;
1242 p_connectinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1245 p_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1248 p_connectinfo.isdn_port = p_m_portnum;
1249 SCPY(p_connectingo.interface, p_m_mISDNport->ifport->interface->name);
1251 /* send connect acknowledge */
1252 dmsg = create_l3msg(CC_CONNECT | RESPONSE, MT_CONNECT, dinfo, sizeof(CONNECT_ACKNOWLEDGE_t), p_m_d_ntmode);
1253 l3_trace_header(CC_CONNECT | RESPONSE, DIRECTION_OUT);
1254 connect_acknowledge = (CONNECT_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1255 /* if we had no bchannel before, we send it now */
1256 if (!bchannel_before && p_m_b_channel)
1257 enc_ie_channel_id(&connect_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
1259 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1261 PDEBUG(DEBUG_ISDN, "Pdss1(%s) connect (to '%s' COLP: '%s')\n", p_name, p_dialinginfo.number, p_connectinfo.id);
1262 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CONNECT);
1263 memcpy(&message->param.connectinfo, &p_connectinfo, sizeof(struct connect_info));
1264 message_put(message);
1266 new_state(PORT_STATE_CONNECT);
1269 /* CC_DISCONNECT INDICATION */
1270 void Pdss1::disconnect_ind(unsigned long prim, unsigned long dinfo, void *data)
1272 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1273 DISCONNECT_t *disconnect = (DISCONNECT_t *)((unsigned long)data + headerlen);
1274 int location, cause;
1275 int coding, proglocation, progress;
1276 struct message *message;
1278 l3_trace_header(prim, DIRECTION_IN);
1279 dec_ie_progress(disconnect->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &proglocation, &progress);
1280 dec_ie_cause(disconnect->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1286 /* release if we are remote sends us no tones */
1287 if (p_m_mISDNport->is_earlyb)
1292 PDEBUG(DEBUG_ISDN, "Pdss1(%s) send release because remote disconnects AND provides no patterns (earlyb).\n", p_name);
1293 dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, dinfo, sizeof(RELEASE_t), p_m_d_ntmode);
1294 release = (RELEASE_t *)(dmsg->data + headerlen);
1295 l3_trace_header(CC_RELEASE | REQUEST, DIRECTION_OUT);
1296 enc_ie_cause(&release->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16); /* normal */
1298 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1300 /* sending release to endpoint */
1303 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1304 message->param.disconnectinfo.cause = cause;
1305 message->param.disconnectinfo.location = location;
1306 message_put(message);
1308 free_epointlist(p_epointlist);
1310 new_state(PORT_STATE_RELEASE);
1315 /* sending disconnect to active endpoint and release to inactive endpoints */
1316 if (ACTIVE_EPOINT(p_epointlist))
1318 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DISCONNECT);
1319 message->param.disconnectinfo.location = location;
1320 message->param.disconnectinfo.cause = cause;
1321 message_put(message);
1323 while(INACTIVE_EPOINT(p_epointlist))
1325 message = message_create(p_serial, INACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1326 message->param.disconnectinfo.location = location;
1327 message->param.disconnectinfo.cause = cause;
1328 message_put(message);
1330 free_epointid(INACTIVE_EPOINT(p_epointlist));
1332 new_state(PORT_STATE_IN_DISCONNECT);
1335 /* CC_DISCONNECT INDICATION */
1336 void Pdss1::disconnect_ind_i(unsigned long prim, unsigned long dinfo, void *data)
1338 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1339 DISCONNECT_t *disconnect = (DISCONNECT_t *)((unsigned long)data + headerlen);
1340 int location, cause;
1343 l3_trace_header(prim, DIRECTION_IN);
1344 if (p_m_d_collect_cause > 0)
1346 add_trace("old-cause", "location", "%d", p_m_d_collect_location);
1347 add_trace("old-cause", "value", "%d", p_m_d_collect_cause);
1349 dec_ie_cause(disconnect->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1353 if (cause == CAUSE_REJECTED) /* call rejected */
1355 p_m_d_collect_cause = CAUSE_REJECTED;
1356 p_m_d_collect_location = location;
1358 if (cause==CAUSE_NORMAL && p_m_d_collect_cause!=CAUSE_REJECTED) /* reject via hangup */
1360 p_m_d_collect_cause = CAUSE_NORMAL;
1361 p_m_d_collect_location = location;
1363 if (cause==CAUSE_BUSY && p_m_d_collect_cause!=CAUSE_REJECTED && p_m_d_collect_cause!=CAUSE_NORMAL) /* busy */
1365 p_m_d_collect_cause = CAUSE_BUSY;
1366 p_m_d_collect_location = location;
1368 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 */
1370 p_m_d_collect_cause = CAUSE_OUTOFORDER;
1371 p_m_d_collect_location = location;
1373 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 */
1375 p_m_d_collect_cause = cause;
1376 p_m_d_collect_location = location;
1378 add_trace("new-cause", "location", "%d", p_m_d_collect_location);
1379 add_trace("new-cause", "value", "%d", p_m_d_collect_cause);
1383 /* CC_RELEASE INDICATION */
1384 void Pdss1::release_ind(unsigned long prim, unsigned long dinfo, void *data)
1386 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1387 RELEASE_t *release = (RELEASE_t *)((unsigned long)data + headerlen);
1389 int location, cause;
1390 struct message *message;
1392 l3_trace_header(prim, DIRECTION_IN);
1393 dec_ie_cause(release->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1399 /* sending release to endpoint */
1402 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1403 message->param.disconnectinfo.cause = cause;
1404 message->param.disconnectinfo.location = location;
1405 message_put(message);
1407 free_epointlist(p_epointlist);
1410 /* only in NT mode we must send release_complete, if we got a release confirm */
1411 if (prim == (CC_RELEASE | CONFIRM))
1413 /* sending release complete */
1414 RELEASE_COMPLETE_t *release_complete;
1416 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
1417 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
1418 l3_trace_header(CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
1419 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16);
1421 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1424 new_state(PORT_STATE_RELEASE);
1428 /* CC_RELEASE_COMPLETE INDICATION */
1429 void Pdss1::release_complete_ind(unsigned long prim, unsigned long dinfo, void *data)
1431 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1432 RELEASE_COMPLETE_t *release_complete = (RELEASE_COMPLETE_t *)((unsigned long)data + headerlen);
1433 int location, cause;
1434 struct message *message;
1436 l3_trace_header(prim, DIRECTION_IN);
1437 dec_ie_cause(release_complete->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1443 /* sending release to endpoint */
1446 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1447 message->param.disconnectinfo.cause = cause;
1448 message->param.disconnectinfo.location = location;
1449 message_put(message);
1451 free_epointlist(p_epointlist);
1454 PDEBUG(DEBUG_ISDN, "Pdss1(%s) release_complete (cause %d)\n", p_name, cause);
1455 new_state(PORT_STATE_RELEASE);
1460 void Pdss1::t312_timeout(unsigned long prim, unsigned long dinfo, void *data)
1462 struct message *message;
1464 // trace is done at message_isdn()
1466 /* sending release to endpoint */
1469 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1470 message->param.disconnectinfo.cause = p_m_d_collect_cause;
1471 message->param.disconnectinfo.location = p_m_d_collect_location;
1472 message_put(message);
1474 free_epointlist(p_epointlist);
1477 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);
1478 new_state(PORT_STATE_RELEASE);
1482 /* CC_NOTIFY INDICATION */
1483 void Pdss1::notify_ind(unsigned long prim, unsigned long dinfo, void *data)
1485 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1486 NOTIFY_t *notifying = (NOTIFY_t *)((unsigned long)data + headerlen);
1487 struct message *message;
1488 int notify, type, plan, present;
1490 l3_trace_header(prim, DIRECTION_IN);
1491 dec_ie_notify(notifying->NOTIFY, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
1492 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));
1495 if (!ACTIVE_EPOINT(p_epointlist))
1497 PDEBUG(DEBUG_ISDN, "Pdss1(%s) there is no active endpoint to notify to.\n", p_name);
1500 /* notification indicator */
1504 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1505 message->param.notifyinfo.notify = notify;
1506 /* redirection number */
1510 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1513 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1516 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1522 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1523 message->param.notifyinfo.present = INFO_PRESENT_NULL;
1526 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1529 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1532 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1535 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1538 message->param.notifyinfo.isdn_port = p_m_portnum;
1539 message_put(message);
1543 /* CC_HOLD INDICATION */
1544 void Pdss1::hold_ind(unsigned long prim, unsigned long dinfo, void *data)
1546 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1547 // HOLD_t *hold = (HOLD_t *)((unsigned long)data + headerlen);
1548 struct message *message;
1549 HOLD_REJECT_t *hold_reject;
1550 HOLD_ACKNOWLEDGE_t *hold_acknowledge;
1552 // class Endpoint *epoint;
1554 l3_trace_header(prim, DIRECTION_IN);
1557 if (!ACTIVE_EPOINT(p_epointlist) || p_m_hold)
1560 PDEBUG(DEBUG_ISDN, "Pdss1(%s) there is no endpoint to notify hold OR we are already on hold, so we reject.\n", p_name);
1562 dmsg = create_l3msg(CC_HOLD_REJECT | REQUEST, MT_HOLD_REJECT, dinfo, sizeof(HOLD_REJECT_t), p_m_d_ntmode);
1563 hold_reject = (HOLD_REJECT_t *)(dmsg->data + headerlen);
1564 l3_trace_header(CC_HOLD_REJECT | REQUEST, DIRECTION_OUT);
1565 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 */
1567 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1572 /* notify the hold of call */
1573 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1574 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_HOLD;
1575 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1576 message_put(message);
1578 /* deactivate bchannel */
1579 start_trace(p_m_mISDNport->portnum,
1580 p_m_mISDNport->ifport->interface,
1581 nationalize(p_callerinfo.id, p_callerinfo.ntype),
1582 p_dialinginfo.number,
1585 "CHANNEL RELEASE (hold)");
1586 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1589 prüfen, ob bei allen alloc_bchannel/free_bchannel ein trace erfolgt
1591 /* set hold state */
1594 epoint = find_epoint_id(ACTIVE_EPOINT(p_epointlist));
1595 if (epoint && p_m_d_ntmode)
1597 p_m_timeout = p_settings.tout_hold;
1602 /* acknowledge hold */
1603 dmsg = create_l3msg(CC_HOLD_ACKNOWLEDGE | REQUEST, MT_HOLD_ACKNOWLEDGE, dinfo, sizeof(HOLD_ACKNOWLEDGE_t), p_m_d_ntmode);
1604 hold_acknowledge = (HOLD_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1605 l3_trace_header(CC_HOLD_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1607 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1611 /* CC_RETRIEVE INDICATION */
1612 void Pdss1::retrieve_ind(unsigned long prim, unsigned long dinfo, void *data)
1614 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1615 RETRIEVE_t *retrieve = (RETRIEVE_t *)((unsigned long)data + headerlen);
1616 RETRIEVE_REJECT_t *retrieve_reject;
1617 RETRIEVE_ACKNOWLEDGE_t *retrieve_acknowledge;
1618 struct message *message;
1619 int channel, exclusive, cause;
1623 l3_trace_header(prim, DIRECTION_IN);
1624 dec_ie_channel_id(retrieve->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
1629 cause = 101; /* incompatible state */
1631 PDEBUG(DEBUG_ISDN, "Pdss1(%s) we are not on hold, so we reject (cazse %d).\n", p_name, cause);
1633 dmsg = create_l3msg(CC_RETRIEVE_REJECT | REQUEST, MT_RETRIEVE_REJECT, dinfo, sizeof(RETRIEVE_REJECT_t), p_m_d_ntmode);
1634 retrieve_reject = (RETRIEVE_REJECT_t *)(dmsg->data + headerlen);
1635 l3_trace_header(CC_RETRIEVE_REJECT | REQUEST, DIRECTION_OUT);
1636 enc_ie_cause(&retrieve_reject->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, cause);
1638 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1643 /* notify the retrieve of call */
1644 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1645 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_RETRIEVAL;
1646 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1647 message_put(message);
1651 mach den channel-kram, wie beim setup
1662 start_trace(p_m_mISDNport->portnum,
1663 p_m_mISDNport->ifport->interface,
1664 nationalize(p_callerinfo.id, p_callerinfo.ntype),
1665 p_dialinginfo.number,
1668 "CHANNEL SELECTION (retrieve)");
1671 alle channels richtig convertieren
1673 channel = -1; /* any channel */
1674 if (channel == ANY_CHANNEL)
1675 channel = -1; /* any channel */
1676 if (channel == CHANNEL_NO)
1677 add_trace("channel", "request", "no-channel");
1679 add_trace("channel", "request", (channel>0)?"%d%s":"any", channel, exclusive?" (forced)":"");
1681 if (channel==CHANNEL_NO && (p_type==PORT_TYPE_DSS1_TE_IN||p_type==PORT_TYPE_DSS1_TE_OUT))
1683 add_trace("conclusion", NULL, "incoming call-waiting not supported for TE-mode");
1689 ret = alloc_bchannel(channel, exclusive);
1692 PDEBUG(DEBUG_BCHANNEL, "- channel is not available (cause=%d), so we send a retrieve_reject.\n", -ret);
1712 /* set hold state */
1716 /* acknowledge retrieve */
1717 dmsg = create_l3msg(CC_RETRIEVE_ACKNOWLEDGE | REQUEST, MT_RETRIEVE_ACKNOWLEDGE, dinfo, sizeof(RETRIEVE_ACKNOWLEDGE_t), p_m_d_ntmode);
1718 retrieve_acknowledge = (RETRIEVE_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1719 l3_trace_header(CC_RETRIEVE_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1720 enc_ie_channel_id(&retrieve_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
1722 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1725 /* CC_SUSPEND INDICATION */
1726 void Pdss1::suspend_ind(unsigned long prim, unsigned long dinfo, void *data)
1728 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1729 SUSPEND_t *suspend = (SUSPEND_t *)((unsigned long)data + headerlen);
1730 SUSPEND_ACKNOWLEDGE_t *suspend_acknowledge;
1731 SUSPEND_REJECT_t *suspend_reject;
1732 struct message *message;
1733 class Endpoint *epoint;
1734 unsigned char callid[8];
1737 int ret = -31; /* normal, unspecified */
1739 l3_trace_header(prim, DIRECTION_IN);
1740 dec_ie_call_id(suspend->CALL_ID, (Q931_info_t *)((unsigned long)data+headerlen), callid, &len);
1743 if (!ACTIVE_EPOINT(p_epointlist))
1746 dmsg = create_l3msg(CC_SUSPEND_REJECT | REQUEST, MT_SUSPEND_REJECT, dinfo, sizeof(SUSPEND_REJECT_t), p_m_d_ntmode);
1747 suspend_reject = (SUSPEND_REJECT_t *)(dmsg->data + headerlen);
1748 l3_trace_header(CC_SUSPEND_REJECT | REQUEST, DIRECTION_OUT);
1749 enc_ie_cause(&suspend_reject->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1751 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1759 /* check if call id is in use */
1760 epoint = epoint_first;
1763 if (epoint->ep_park)
1765 if (epoint->ep_park_len == len)
1766 if (!memcmp(epoint->ep_park_callid, callid, len))
1768 PDEBUG(DEBUG_ISDN, "Pdss1(%s) call id is in use, so we reject.\n", p_name);
1769 ret = -84; /* call id in use */
1773 epoint = epoint->next;
1776 /* notify the hold of call */
1777 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1778 message->param.notifyinfo.notify = INFO_NOTIFY_USER_SUSPENDED;
1779 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1780 message_put(message);
1782 /* deactivate bchannel */
1783 start_trace(p_m_mISDNport->portnum,
1784 p_m_mISDNport->ifport->interface,
1785 nationalize(p_callerinfo.id, p_callerinfo.ntype),
1786 p_dialinginfo.number,
1789 "CHANNEL RELEASE (suspend)");
1790 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1794 /* sending suspend to endpoint */
1795 while (p_epointlist)
1797 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_SUSPEND);
1798 memcpy(message->param.parkinfo.callid, callid, sizeof(message->param.parkinfo.callid));
1799 message->param.parkinfo.len = len;
1800 message_put(message);
1802 free_epointlist(p_epointlist);
1805 /* sending SUSPEND_ACKNOWLEDGE */
1806 dmsg = create_l3msg(CC_SUSPEND_ACKNOWLEDGE | REQUEST, MT_SUSPEND_ACKNOWLEDGE, dinfo, sizeof(SUSPEND_ACKNOWLEDGE_t), p_m_d_ntmode);
1807 suspend_acknowledge = (SUSPEND_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1808 l3_trace_header(CC_SUSPEND_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1810 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1812 new_state(PORT_STATE_RELEASE);
1816 /* CC_RESUME INDICATION */
1817 void Pdss1::resume_ind(unsigned long prim, unsigned long dinfo, void *data)
1819 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1820 RESUME_t *resume = (RESUME_t *)((unsigned long)data + headerlen);
1821 RESUME_REJECT_t *resume_reject;
1822 RESUME_ACKNOWLEDGE_t *resume_acknowledge;
1823 unsigned char callid[8];
1825 int channel, exclusive;
1827 class Endpoint *epoint;
1828 struct message *message;
1831 /* callref from nt-lib */
1834 /* nt-library now gives us the id via CC_RESUME */
1835 if (dinfo&(~0xff) == 0xff00)
1837 PERROR("fatal software error: l3-stack gives us a process id 0xff00-0xffff\n");
1840 l3_trace_header(CC_NEW_CR | INDICATION, DIRECTION_IN);
1842 add_trace("callref", "old", "0x%x", p_m_d_l3id);
1843 add_trace("callref", "new", "0x%x", dinfo);
1845 if (p_m_d_l3id&(~0xff) == 0xff00)
1846 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
1848 p_m_d_ces = setup->ces;
1851 l3_trace_header(prim, DIRECTION_IN);
1852 dec_ie_call_id(resume->CALL_ID, (Q931_info_t *)((unsigned long)data+headerlen), callid, &len);
1855 /* if blocked, release call */
1856 if (p_m_mISDNport->ifport->block)
1858 RELEASE_COMPLETE_t *release_complete;
1860 printlog("--- port#%d is blocked.\n", mISDNport->ifport->portnum);
1870 channel = -1; /* any channel */
1873 ret = hunt_bchannel(channel, exclusive);
1877 dmsg = create_l3msg(CC_RESUME_REJECT | REQUEST, MT_RESUME_REJECT, dinfo, sizeof(RESUME_REJECT_t), p_m_d_ntmode);
1878 resume_reject = (RESUME_REJECT_t *)(dmsg->data + headerlen);
1879 l3_trace_header(CC_RESUME_REJECT | REQUEST, DIRECTION_OUT);
1880 enc_ie_cause(&resume_reject->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1882 add_trace("reason", NULL, "port blocked");
1884 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1885 new_state(PORT_STATE_RELEASE);
1890 /* create endpoint */
1893 PERROR("SOFTWARE ERROR: incoming resume but already got an endpoint, exitting...\n");
1896 ret = -85; /* no call suspended */
1897 epoint = epoint_first;
1900 if (epoint->ep_park)
1902 ret = -83; /* suspended call exists, but this not */
1903 if (epoint->ep_park_len == len)
1904 if (!memcmp(epoint->ep_park_callid, callid, len))
1907 epoint = epoint->next;
1911 PDEBUG(DEBUG_ISDN, "Pdss1(%s) no suspended call, so we reject with cause %d.\n", p_name, ret);
1915 if (!(epointlist_new(epoint->ep_serial)))
1917 PERROR("no memory for epointlist\n");
1920 if (!(epoint->portlist_new(p_serial, p_type, p_m_mISDNport->is_earlyb)))
1922 PERROR("no memory for portlist\n");
1925 PDEBUG(DEBUG_ISDN, "Pdss1(%s) resume\n", p_name);
1926 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RESUME);
1927 message_put(message);
1929 /* notify the resume of call */
1930 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1931 message->param.notifyinfo.notify = INFO_NOTIFY_USER_RESUMED;
1932 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1933 message_put(message);
1935 /* sending RESUME_ACKNOWLEDGE */
1936 dmsg = create_l3msg(CC_RESUME_ACKNOWLEDGE | REQUEST, MT_RESUME_ACKNOWLEDGE, dinfo, sizeof(RESUME_ACKNOWLEDGE_t), p_m_d_ntmode);
1937 resume_acknowledge = (RESUME_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1938 l3_trace_header(CC_RESUME_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1939 enc_ie_channel_id(&resume_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
1941 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1943 new_state(PORT_STATE_CONNECT);
1947 /* CC_FACILITY INDICATION */
1948 void Pdss1::facility_ind(unsigned long prim, unsigned long dinfo, void *data)
1950 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1951 FACILITY_t *facility = (FACILITY_t *)((unsigned long)data + headerlen);
1952 unsigned char facil[256];
1954 struct message *message;
1956 l3_trace_header(prim, DIRECTION_IN);
1957 dec_ie_facility(facility->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), facil, &facil_len);
1964 PDEBUG(DEBUG_ISDN, "Pdss1(%s) facility\n", p_name);
1965 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_FACILITY);
1966 message->param.facilityinfo.len = facil_len;
1967 memcpy(message->param.facilityinfo.data, facil, facil_len);
1968 message_put(message);
1973 * handler for isdn connections
1974 * incoming information are parsed and sent via message to the endpoint
1976 void Pdss1::message_isdn(unsigned long prim, unsigned long dinfo, void *data)
1984 case CC_TIMEOUT | INDICATION:
1985 l3_trace_header(prim, DIRECTION_IN);
1988 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1989 timer_hex = *((int *)(((char *)data)+headerlen));
1992 add_trace("timer", NULL, "%x", timer_hex);
1994 if (timer_hex==0x312 && p_m_d_ntmode)
1995 t312_timeout(prim, dinfo, data);
1998 case CC_SETUP | INDICATION:
1999 PDEBUG((DEBUG_BCHANNEL|DEBUG_ISDN), "Pdss1(%s) setup\n", p_name);
2000 if (p_state != PORT_STATE_IDLE)
2002 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received setup again, IGNORING.\n", p_name);
2005 setup_ind(prim, dinfo, data);
2008 case CC_SETUP | CONFIRM:
2011 l3_trace_header(CC_NEW_CR | INDICATION, DIRECTION_IN);
2012 add_trace("callref", "old", "0x%x", p_m_d_l3id);
2013 /* nt-library now gives us a new id via CC_SETUP_CONFIRM */
2014 if ((p_m_d_l3id&0xff00) != 0xff00)
2015 PERROR(" strange setup-procid 0x%x\n", p_m_d_l3id);
2016 p_m_d_l3id = *((int *)(((u_char *)data)+ mISDNUSER_HEAD_SIZE));
2017 add_trace("callref", "new", "0x%x", p_m_d_l3id);
2021 PDEBUG(DEBUG_ISDN, "Pdss1(%s) setup confirm (l3id=0x%x)\n", p_name, p_m_d_l3id);
2024 case CC_INFORMATION | INDICATION:
2025 PDEBUG(DEBUG_ISDN, "Pdss1(%s) information\n", p_name);
2026 information_ind(prim, dinfo, data);
2029 case CC_SETUP_ACKNOWLEDGE | INDICATION:
2030 PDEBUG(DEBUG_ISDN, "Pdss1(%s) setup acknowledge\n", p_name);
2031 if (p_state != PORT_STATE_OUT_SETUP)
2033 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received setup_acknowledge, but we are not in outgoing setup state, IGNORING.\n", p_name);
2036 setup_acknowledge_ind(prim, dinfo, data);
2039 case CC_PROCEEDING | INDICATION:
2040 PDEBUG(DEBUG_ISDN, "Pdss1(%s) proceeding\n", p_name);
2041 if (p_state != PORT_STATE_OUT_SETUP
2042 && p_state != PORT_STATE_OUT_OVERLAP)
2044 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received proceeding, but we are not in outgoing setup OR overlap state, IGNORING.\n", p_name);
2047 proceeding_ind(prim, dinfo, data);
2050 case CC_ALERTING | INDICATION:
2051 PDEBUG(DEBUG_ISDN, "Pdss1(%s) alerting\n", p_name);
2052 if (p_state != PORT_STATE_OUT_SETUP
2053 && p_state != PORT_STATE_OUT_OVERLAP
2054 && p_state != PORT_STATE_OUT_PROCEEDING)
2056 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding state, IGNORING.\n", p_name);
2059 alerting_ind(prim, dinfo, data);
2062 case CC_CONNECT | INDICATION:
2063 PDEBUG(DEBUG_ISDN, "Pdss1(%s) connect\n", p_name);
2064 if (p_state != PORT_STATE_OUT_SETUP
2065 && p_state != PORT_STATE_OUT_OVERLAP
2066 && p_state != PORT_STATE_OUT_PROCEEDING
2067 && p_state != PORT_STATE_OUT_ALERTING)
2069 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);
2072 connect_ind(prim, dinfo, data);
2073 if (p_m_d_notify_pending)
2075 PDEBUG(DEBUG_ISDN, "received or connect, so we send pending notify message.\n");
2076 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2077 message_free(p_m_d_notify_pending);
2078 p_m_d_notify_pending = NULL;
2082 case CC_CONNECT_ACKNOWLEDGE | INDICATION:
2083 case CC_CONNECT | CONFIRM:
2084 PDEBUG(DEBUG_ISDN, "Pdss1(%s) connect_acknowlege.\n", p_name);
2085 if (p_state == PORT_STATE_CONNECT_WAITING)
2086 new_state(PORT_STATE_CONNECT);
2087 if (p_m_d_notify_pending)
2089 PDEBUG(DEBUG_ISDN, "received or connect-ack, so we send pending notify message.\n");
2090 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2091 message_free(p_m_d_notify_pending);
2092 p_m_d_notify_pending = NULL;
2096 case CC_DISCONNECT | INDICATION:
2097 PDEBUG(DEBUG_ISDN, "Pdss1(%s) disconnect\n", p_name);
2098 disconnect_ind(prim, dinfo, data);
2101 case CC_RELEASE | CONFIRM:
2102 PDEBUG(DEBUG_ISDN, "Pdss1(%s) release confirm\n", p_name);
2103 case CC_RELEASE | INDICATION:
2104 PDEBUG(DEBUG_ISDN, "Pdss1(%s) release\n", p_name);
2105 release_ind(prim, dinfo, data);
2108 case CC_RELEASE_COMPLETE | INDICATION:
2109 PDEBUG(DEBUG_ISDN, "Pdss1(%s) release_complete.\n", p_name);
2110 release_complete_ind(prim, dinfo, data);
2113 case CC_RELEASE_COMPLETE | CONFIRM:
2114 PDEBUG(DEBUG_ISDN, "Pdss1(%s) release_complete (confirm).\n", p_name);
2117 case CC_NOTIFY | INDICATION:
2118 PDEBUG(DEBUG_ISDN, "Pdss1(%s) notify\n", p_name);
2119 notify_ind(prim, dinfo, data);
2122 case CC_HOLD | INDICATION:
2123 PDEBUG(DEBUG_ISDN, "Pdss1(%s) hold\n", p_name);
2124 hold_ind(prim, dinfo, data);
2127 case CC_RETRIEVE | INDICATION:
2128 PDEBUG(DEBUG_ISDN, "Pdss1(%s) retrieve\n", p_name);
2129 retrieve_ind(prim, dinfo, data);
2132 case CC_SUSPEND | INDICATION:
2133 PDEBUG(DEBUG_ISDN, "Pdss1(%s) suspend\n", p_name);
2134 suspend_ind(prim, dinfo, data);
2137 case CC_RESUME | INDICATION:
2138 PDEBUG(DEBUG_ISDN, "Pdss1(%s) resume\n", p_name);
2139 resume_ind(prim, dinfo, data);
2142 case CC_FACILITY | INDICATION:
2143 PDEBUG(DEBUG_ISDN, "Pdss1(%s) facility\n", p_name);
2144 facility_ind(prim, dinfo, data);
2147 case CC_RELEASE_CR | INDICATION:
2148 l3_trace_header(CC_RELEASE_CR | INDICATION, DIRECTION_IN);
2149 add_trace("callref", NULL, "0x%x", p_m_d_l3id);
2153 if ((p_m_d_l3id&0xff00) == 0xff00)
2154 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
2158 /* sending release to endpoint in case we still have an endpoint
2159 * NOTE: this only happens if the stack releases due to layer1
2160 * or layer2 breakdown. otherwhise a release is received first.
2164 struct message *message;
2165 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
2166 message->param.disconnectinfo.cause = (p_m_d_collect_cause!=CAUSE_NOUSER)?p_m_d_collect_cause:CAUSE_UNSPECIFIED;
2167 message->param.disconnectinfo.location = (p_m_d_collect_cause!=CAUSE_NOUSER)?p_m_d_collect_location:LOCATION_PRIVATE_LOCAL;
2168 message_put(message);
2170 free_epointlist(p_epointlist);
2172 new_state(PORT_STATE_RELEASE);
2176 case CC_NEW_CR | INDICATION:
2177 l3_trace_header(prim, DIRECTION_IN);
2179 add_trace("callref", "old", "0x%x", p_m_d_l3id);
2182 new_l3id = *((int *)(((u_char *)data+mISDNUSER_HEAD_SIZE)));
2183 if (((new_l3id&0xff00)!=0xff00) && ((p_m_d_l3id&0xff00)==0xff00))
2184 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
2189 p_m_d_l3id = new_l3id;
2190 add_trace("callref", "new", "0x%x", p_m_d_l3id);
2195 l3_trace_header(prim, DIRECTION_IN);
2196 add_trace("unhandled", "prim", "0x%x", prim);
2201 void Pdss1::new_state(int state)
2203 class Endpoint *epoint;
2206 epoint = find_epoint_id(ACTIVE_EPOINT(p_epointlist));
2207 if (epoint && p_m_d_ntmode)
2209 if (state == PORT_STATE_IN_OVERLAP)
2211 p_m_timeout = p_settings.tout_dialing;
2214 if (state != p_state)
2216 if (state == PORT_STATE_IN_SETUP
2217 || state == PORT_STATE_IN_OVERLAP)
2219 p_m_timeout = p_settings.tout_setup;
2222 if (state == PORT_STATE_IN_PROCEEDING
2223 || state == PORT_STATE_OUT_PROCEEDING)
2225 p_m_timeout = p_settings.tout_proceeding;
2228 if (state == PORT_STATE_IN_ALERTING
2229 || state == PORT_STATE_OUT_ALERTING)
2231 p_m_timeout = p_settings.tout_alerting;
2234 if (state == PORT_STATE_CONNECT
2235 || state == PORT_STATE_CONNECT_WAITING)
2239 if (state == PORT_STATE_IN_DISCONNECT
2240 || state == PORT_STATE_OUT_DISCONNECT)
2242 p_m_timeout = p_settings.tout_disconnect;
2248 Port::new_state(state);
2255 int Pdss1::handler(void)
2259 if ((ret = Port::handler()))
2262 /* handle destruction */
2263 if (p_m_delete && p_m_d_l3id==0)
2265 PDEBUG(DEBUG_ISDN, "Pdss1(%s) doing pending release.\n", p_name);
2275 * handles all messages from endpoint
2277 /* MESSAGE_INFORMATION */
2278 void Pdss1::message_information(unsigned long epoint_id, int message_id, union parameter *param)
2280 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2281 INFORMATION_t *information;
2284 if (param->information.number[0]) /* only if we have something to dial */
2286 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2287 l3_trace_header(CC_INFORMATION | REQUEST, DIRECTION_OUT);
2288 information = (INFORMATION_t *)(dmsg->data + headerlen);
2289 enc_ie_called_pn(&information->CALLED_PN, dmsg, 0, 1, (unsigned char *)param->information.number);
2291 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2300 void Pdss1::message_setup(unsigned long epoint_id, int message_id, union parameter *param)
2302 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2303 INFORMATION_t *information;
2306 int plan, type, screen, present, reason;
2307 int capability, mode, rate, coding, user, presentation, interpretation, hlc, exthlc;
2308 int channel, exclusive;
2310 struct epoint_list *epointlist;
2312 /* release if port is blocked */
2313 if (p_m_mISDNport->ifport->block)
2315 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2316 message->param.disconnectinfo.cause = 27; // temp. unavail.
2317 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2318 message_put(message);
2319 new_state(PORT_STATE_RELEASE);
2324 /* copy setup infos to port */
2325 memcpy(&p_callerinfo, ¶m->setup.callerinfo, sizeof(p_callerinfo));
2326 memcpy(&p_dialinginfo, ¶m->setup.dialinginfo, sizeof(p_dialinginfo));
2327 memcpy(&p_capainfo, ¶m->setup.capainfo, sizeof(p_capainfo));
2328 memcpy(&p_redirinfo, ¶m->setup.redirinfo, sizeof(p_redirinfo));
2329 // SCPY(&p_m_tones_dir, param->setup.ext.tones_dir);
2331 /* only display at connect state: this case happens if endpoint is in connected mode */
2332 if (p_state==PORT_STATE_CONNECT)
2334 if (p_type!=PORT_TYPE_DSS1_NT_OUT
2335 && p_type!=PORT_TYPE_DSS1_NT_IN)
2337 if (p_callerinfo.display[0])
2339 /* sending information */
2340 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2341 information = (INFORMATION_t *)(dmsg->data + headerlen);
2342 l3_trace_header(CC_INFORMATION | REQUEST, DIRECTION_OUT);
2344 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_callerinfo.display);
2346 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2351 /* attach only if not already */
2352 epointlist = p_epointlist;
2355 if (epointlist->epoint_id == epoint_id)
2357 epointlist = epointlist->next;
2361 if (!(epointlist_new(epoint_id)))
2363 PERROR("no memory for epointlist\n");
2372 channel = p_m_b_channel;
2373 exclusive = p_m_b_exclusive;
2375 channel = CHANNEL_ANY;
2376 /* nt-port with no channel, not reserverd */
2377 if (!p_m_b_channel && !p_m_b_reserve && p_type==PORT_TYPE_DSS1_NT_OUT)
2378 channel = CHANNEL_NO;
2381 l3_trace_header(CC_NEW_CR | REQUEST, DIRECTION_OUT);
2387 if (p_m_mISDNport->procids[i] == 0)
2393 struct message *message;
2395 add_trace("callref", NULL, "no free id");
2397 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2398 message->param.disconnectinfo.cause = 47;
2399 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2400 message_put(message);
2401 new_state(PORT_STATE_RELEASE);
2405 p_m_mISDNport->procids[i] = 1;
2406 p_m_d_l3id = 0xff00 | i;
2410 /* if we are in te-mode, we need to create a process first */
2411 if (newteid++ > 0x7fff)
2413 p_m_d_l3id = (entity<<16) | newteid;
2414 /* preparing message */
2415 ncr.prim = CC_NEW_CR | REQUEST;
2416 ncr.addr = p_m_mISDNport->upper_id | FLG_MSG_DOWN;
2417 ncr.dinfo = p_m_d_l3id;
2420 mISDN_write(mISDNdevice, &ncr, mISDN_HEADER_LEN+ncr.len, TIMEOUT_1SEC);
2424 add_trace("callref", "new", "0x%x", p_m_d_l3id);
2427 /* preparing setup message */
2428 dmsg = create_l3msg(CC_SETUP | REQUEST, MT_SETUP, p_m_d_l3id, sizeof(SETUP_t), p_m_d_ntmode);
2429 l3_trace_header(CC_SETUP | REQUEST, DIRECTION_OUT);
2430 setup = (SETUP_t *)(dmsg->data + headerlen);
2431 /* channel information */
2432 if (channel >= 0) /* it should */
2434 enc_ie_channel_id(&setup->CHANNEL_ID, dmsg, exclusive, channel);
2436 /* caller information */
2438 switch (p_callerinfo.ntype)
2440 case INFO_NTYPE_INTERNATIONAL:
2443 case INFO_NTYPE_NATIONAL:
2446 case INFO_NTYPE_SUBSCRIBER:
2449 default: /* INFO_NTYPE_UNKNOWN */
2453 switch (p_callerinfo.screen)
2455 case INFO_SCREEN_USER:
2458 default: /* INFO_SCREEN_NETWORK */
2462 switch (p_callerinfo.present)
2464 case INFO_PRESENT_RESTRICTED:
2467 case INFO_PRESENT_NOTAVAIL:
2470 default: /* INFO_PRESENT_ALLOWED */
2475 enc_ie_calling_pn(&setup->CALLING_PN, dmsg, type, plan, present, screen, (unsigned char *)p_callerinfo.id);
2476 /* dialing information */
2477 if (p_dialinginfo.number[0]) /* only if we have something to dial */
2479 enc_ie_called_pn(&setup->CALLED_PN, dmsg, 0, 1, (unsigned char *)p_dialinginfo.number);
2481 /* sending complete */
2482 if (p_dialinginfo.sending_complete)
2483 enc_ie_complete(&setup->COMPLETE, dmsg, 1);
2484 /* sending user-user */
2485 if (param->setup.useruser.len)
2487 enc_ie_useruser(&setup->USER_USER, dmsg, param->setup.useruser.protocol, param->setup.useruser.data, param->setup.useruser.len);
2489 /* redirecting number */
2491 switch (p_redirinfo.ntype)
2493 case INFO_NTYPE_INTERNATIONAL:
2496 case INFO_NTYPE_NATIONAL:
2499 case INFO_NTYPE_SUBSCRIBER:
2502 default: /* INFO_NTYPE_UNKNOWN */
2506 switch (p_redirinfo.screen)
2508 case INFO_SCREEN_USER:
2511 default: /* INFO_SCREE_NETWORK */
2515 switch (p_redirinfo.reason)
2517 case INFO_REDIR_BUSY:
2520 case INFO_REDIR_NORESPONSE:
2523 case INFO_REDIR_UNCONDITIONAL:
2526 case INFO_REDIR_CALLDEFLECT:
2529 case INFO_REDIR_OUTOFORDER:
2532 default: /* INFO_REDIR_UNKNOWN */
2536 switch (p_redirinfo.present)
2538 case INFO_PRESENT_NULL: /* no redir at all */
2545 case INFO_PRESENT_RESTRICTED:
2548 case INFO_PRESENT_NOTAVAIL:
2551 default: /* INFO_PRESENT_ALLOWED */
2555 /* sending redirecting number only in ntmode */
2556 if (type >= 0 && p_m_d_ntmode)
2557 enc_ie_redir_nr(&setup->REDIR_NR, dmsg, type, plan, present, screen, reason, (unsigned char *)p_redirinfo.id);
2558 /* bearer capability */
2559 //printf("hlc=%d\n",p_capainfo.hlc);
2561 capability = p_capainfo.bearer_capa;
2562 mode = p_capainfo.bearer_mode;
2563 rate = (mode==INFO_BMODE_CIRCUIT)?0x10:0x00;
2564 switch (p_capainfo.bearer_info1)
2566 case INFO_INFO1_NONE:
2570 user = p_capainfo.bearer_info1 & 0x7f;
2573 enc_ie_bearer(&setup->BEARER, dmsg, coding, capability, mode, rate, -1, user);
2580 hlc = p_capainfo.hlc & 0x7f;
2582 if (p_capainfo.exthlc)
2583 exthlc = p_capainfo.exthlc & 0x7f;
2584 enc_ie_hlc(&setup->HLC, dmsg, coding, interpretation, presentation, hlc, exthlc);
2588 if (p_callerinfo.display[0] && p_m_d_ntmode)
2589 enc_ie_display(&setup->DISPLAY, dmsg, (unsigned char *)p_callerinfo.display);
2591 /* nt-mode: CNIP (calling name identification presentation) */
2592 if (p_callerinfo.name[0] && p_m_d_ntmode)
2593 enc_facility_centrex(&setup->FACILITY, dmsg, (unsigned char *)p_callerinfo.name, 1);
2597 /* send setup message now */
2598 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2600 new_state(PORT_STATE_OUT_SETUP);
2603 /* MESSAGE_FACILITY */
2604 void Pdss1::message_facility(unsigned long epoint_id, int message_id, union parameter *param)
2606 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2607 FACILITY_t *facility;
2610 /* facility will not be sent to external lines */
2614 PDEBUG(DEBUG_ISDN, "Pdss1(%s) sending facility message\n", p_name);
2616 /* sending facility */
2617 dmsg = create_l3msg(CC_FACILITY | REQUEST, MT_FACILITY, p_m_d_l3id, sizeof(FACILITY_t), p_m_d_ntmode);
2618 facility = (FACILITY_t *)(dmsg->data + headerlen);
2619 l3_trace_header(CC_FACILITY | REQUEST, DIRECTION_OUT);
2620 enc_ie_facility(&facility->FACILITY, dmsg, (unsigned char *)param->facilityinfo.data, param->facilityinfo.len);
2622 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2625 /* MESSAGE_NOTIFY */
2626 void Pdss1::message_notify(unsigned long epoint_id, int message_id, union parameter *param)
2628 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2629 INFORMATION_t *information;
2630 NOTIFY_t *notification;
2632 int plan, type = -1, present;
2635 PDEBUG(DEBUG_ISDN, "Pdss1(%s) sending information message\n", p_name);
2636 if (param->notifyinfo.notify>INFO_NOTIFY_NONE)
2637 notify = param->notifyinfo.notify & 0x7f;
2640 if (p_state != PORT_STATE_CONNECT)
2642 /* notify only allowed in active state */
2648 switch (param->notifyinfo.ntype)
2650 case INFO_NTYPE_INTERNATIONAL:
2653 case INFO_NTYPE_NATIONAL:
2656 case INFO_NTYPE_SUBSCRIBER:
2659 default: /* INFO_NTYPE_UNKNOWN */
2663 switch (param->notifyinfo.present)
2665 case INFO_PRESENT_NULL: /* no redir at all */
2670 case INFO_PRESENT_RESTRICTED:
2673 case INFO_PRESENT_NOTAVAIL:
2676 default: /* INFO_PRESENT_ALLOWED */
2682 if (notify<0 && !param->notifyinfo.display[0])
2684 PDEBUG(DEBUG_ISDN, "Pdss1(%s) nothing to notify, nothing to display\n", p_name);
2690 if (p_state!=PORT_STATE_CONNECT)
2692 /* queue notification */
2693 PDEBUG(DEBUG_ISDN, "Pdss1(%s) queueing notification because isdn port is not active state.\n", p_name);
2694 if (p_m_d_notify_pending)
2695 message_free(p_m_d_notify_pending);
2696 p_m_d_notify_pending = message_create(ACTIVE_EPOINT(p_epointlist), p_serial, EPOINT_TO_PORT, message_id);
2697 memcpy(&p_m_d_notify_pending->param, param, sizeof(union parameter));
2700 /* sending notification */
2701 dmsg = create_l3msg(CC_NOTIFY | REQUEST, MT_NOTIFY, p_m_d_l3id, sizeof(NOTIFY_t), p_m_d_ntmode);
2702 notification = (NOTIFY_t *)(dmsg->data + headerlen);
2703 l3_trace_header(CC_NOTIFY | REQUEST, DIRECTION_OUT);
2704 enc_ie_notify(¬ification->NOTIFY, dmsg, notify);
2705 /* sending redirection number only in ntmode */
2706 if (type >= 0 && p_m_d_ntmode)
2707 enc_ie_redir_dn(¬ification->REDIR_DN, dmsg, type, plan, present, (unsigned char *)param->notifyinfo.id);
2708 if (param->notifyinfo.display[0] && p_m_d_ntmode)
2709 enc_ie_display(¬ification->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display);
2711 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2713 } else if (p_m_d_ntmode)
2715 /* sending information */
2716 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2717 information = (INFORMATION_t *)(dmsg->data + headerlen);
2718 l3_trace_header(CC_INFORMATION | REQUEST, DIRECTION_OUT);
2719 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display);
2721 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2725 /* MESSAGE_OVERLAP */
2726 void Pdss1::message_overlap(unsigned long epoint_id, int message_id, union parameter *param)
2728 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2729 SETUP_ACKNOWLEDGE_t *setup_acknowledge;
2732 /* sending setup_acknowledge */
2733 dmsg = create_l3msg(CC_SETUP_ACKNOWLEDGE | REQUEST, MT_SETUP_ACKNOWLEDGE, p_m_d_l3id, sizeof(SETUP_ACKNOWLEDGE_t), p_m_d_ntmode);
2734 setup_acknowledge = (SETUP_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
2735 l3_trace_header(CC_SETUP_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
2736 /* channel information */
2737 if (p_state == PORT_STATE_IN_SETUP)
2738 enc_ie_channel_id(&setup_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2739 /* progress information */
2740 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2741 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2742 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2743 if (p_m_mISDNport->is_tones)
2744 enc_ie_progress(&setup_acknowledge->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2746 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2748 new_state(PORT_STATE_IN_OVERLAP);
2751 /* MESSAGE_PROCEEDING */
2752 void Pdss1::message_proceeding(unsigned long epoint_id, int message_id, union parameter *param)
2754 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2755 CALL_PROCEEDING_t *proceeding;
2758 /* sending proceeding */
2759 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2760 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2761 l3_trace_header(CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2762 /* channel information */
2763 if (p_state == PORT_STATE_IN_SETUP)
2764 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2765 /* progress information */
2766 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2767 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2768 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2769 if (p_m_mISDNport->is_tones)
2770 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2772 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2774 new_state(PORT_STATE_IN_PROCEEDING);
2777 /* MESSAGE_ALERTING */
2778 void Pdss1::message_alerting(unsigned long epoint_id, int message_id, union parameter *param)
2780 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2781 ALERTING_t *alerting;
2784 /* NT-MODE in setup state we must send PROCEEDING first */
2785 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2787 CALL_PROCEEDING_t *proceeding;
2789 /* sending proceeding */
2790 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2791 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2792 l3_trace_header(CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2793 /* channel information */
2794 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2795 /* progress information */
2796 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2797 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2798 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2799 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2801 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2802 new_state(PORT_STATE_IN_PROCEEDING);
2805 /* sending alerting */
2806 dmsg = create_l3msg(CC_ALERTING | REQUEST, MT_ALERTING, p_m_d_l3id, sizeof(ALERTING_t), p_m_d_ntmode);
2807 alerting = (ALERTING_t *)(dmsg->data + headerlen);
2808 l3_trace_header(CC_ALERTING | REQUEST, DIRECTION_OUT);
2809 /* channel information */
2810 if (p_state == PORT_STATE_IN_SETUP)
2811 enc_ie_channel_id(&alerting->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2812 /* progress information */
2813 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2814 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2815 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2816 if (p_m_mISDNport->is_tones)
2817 enc_ie_progress(&alerting->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2819 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2821 new_state(PORT_STATE_IN_ALERTING);
2824 /* MESSAGE_CONNECT */
2825 void Pdss1::message_connect(unsigned long epoint_id, int message_id, union parameter *param)
2827 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2828 INFORMATION_t *information;
2830 int type, plan, present, screen;
2832 class Endpoint *epoint;
2834 /* NT-MODE in setup state we must send PROCEEDING first */
2835 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2837 CALL_PROCEEDING_t *proceeding;
2839 /* sending proceeding */
2840 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2841 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2842 l3_trace_header(CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2843 /* channel information */
2844 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2845 // /* progress information */
2846 // if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2847 // || p_capainfo.bearer_capa==INFO_BC_AUDIO
2848 // || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2849 // enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2851 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2852 new_state(PORT_STATE_IN_PROCEEDING);
2855 /* copy connected information */
2856 memcpy(&p_connectinfo, ¶m->connectinfo, sizeof(p_connectinfo));
2858 /* only display at connect state */
2859 if (p_state == PORT_STATE_CONNECT)
2860 if (p_connectinfo.display[0])
2862 /* sending information */
2863 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2864 information = (INFORMATION_t *)(dmsg->data + headerlen);
2865 l3_trace_header(CC_INFORMATION | REQUEST, DIRECTION_OUT);
2867 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_connectinfo.display);
2869 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2873 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)
2875 PDEBUG(DEBUG_ISDN, "Pdss1(%s) connect command only possible in setup, proceeding or alerting state.\n", p_name);
2879 /* preparing connect message */
2880 dmsg = create_l3msg(CC_CONNECT | REQUEST, MT_CONNECT, p_m_d_l3id, sizeof(CONNECT_t), p_m_d_ntmode);
2881 connect = (CONNECT_t *)(dmsg->data + headerlen);
2882 l3_trace_header(CC_CONNECT | REQUEST, DIRECTION_OUT);
2883 /* connect information */
2885 switch (p_connectinfo.ntype)
2887 case INFO_NTYPE_INTERNATIONAL:
2890 case INFO_NTYPE_NATIONAL:
2893 case INFO_NTYPE_SUBSCRIBER:
2896 default: /* INFO_NTYPE_UNKNOWN */
2900 switch (param->connectinfo.screen)
2902 case INFO_SCREEN_USER:
2905 default: /* INFO_SCREE_NETWORK */
2909 switch (p_connectinfo.present)
2911 case INFO_PRESENT_NULL: /* no colp at all */
2917 case INFO_PRESENT_RESTRICTED:
2920 case INFO_PRESENT_NOTAVAIL:
2923 default: /* INFO_PRESENT_ALLOWED */
2928 enc_ie_connected_pn(&connect->CONNECT_PN, dmsg, type, plan, present, screen, (unsigned char *)p_connectinfo.id);
2930 if (p_connectinfo.display[0] && p_m_d_ntmode)
2931 enc_ie_display(&connect->DISPLAY, dmsg, (unsigned char *)p_connectinfo.display);
2933 /* nt-mode: CONP (connected name identification presentation) */
2934 if (p_connectinfo.name[0] && p_m_d_ntmode)
2935 enc_facility_centrex(&connect->FACILITY, dmsg, (unsigned char *)p_connectinfo.name, 0);
2940 epoint = find_epoint_id(epoint_id);
2941 enc_ie_date(&connect->DATE, dmsg, now, p_settings.no_seconds);
2944 /* finally send message */
2945 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2948 new_state(PORT_STATE_CONNECT);
2950 new_state(PORT_STATE_CONNECT_WAITING);
2954 /* MESSAGE_DISCONNECT */
2955 void Pdss1::message_disconnect(unsigned long epoint_id, int message_id, union parameter *param)
2957 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2958 DISCONNECT_t *disconnect;
2959 RELEASE_COMPLETE_t *release_complete;
2961 struct message *message;
2964 /* we reject during incoming setup when we have no tones. also if we are in outgoing setup state */
2965 if ((p_state==PORT_STATE_IN_SETUP && !p_m_mISDNport->is_tones)
2966 || p_state==PORT_STATE_OUT_SETUP)
2968 /* sending release to endpoint */
2971 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
2972 message->param.disconnectinfo.cause = 16;
2973 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2974 message_put(message);
2976 free_epointlist(p_epointlist);
2978 /* sending release */
2979 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
2980 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
2981 l3_trace_header(CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
2983 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);
2985 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2986 new_state(PORT_STATE_RELEASE);
2991 /* NT-MODE in setup state we must send PROCEEDING first */
2992 if (p_state==PORT_STATE_IN_SETUP)
2994 CALL_PROCEEDING_t *proceeding;
2996 /* sending proceeding */
2997 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2998 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2999 l3_trace_header(CC_PROCEEDING | REQUEST, DIRECTION_OUT);
3000 /* channel information */
3001 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
3002 /* progress information */
3003 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
3004 || p_capainfo.bearer_capa==INFO_BC_AUDIO
3005 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
3006 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
3008 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3009 new_state(PORT_STATE_IN_PROCEEDING);
3012 /* sending disconnect */
3013 dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode);
3014 disconnect = (DISCONNECT_t *)(dmsg->data + headerlen);
3015 l3_trace_header(CC_DISCONNECT | REQUEST, DIRECTION_OUT);
3016 /* progress information */
3017 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
3018 || p_capainfo.bearer_capa==INFO_BC_AUDIO
3019 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
3020 if (p_m_mISDNport->is_tones)
3021 enc_ie_progress(&disconnect->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
3023 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);
3025 if (param->disconnectinfo.display[0])
3026 p = param->disconnectinfo.display;
3027 if (p) if (*p && p_m_d_ntmode)
3028 enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p);
3030 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3031 new_state(PORT_STATE_OUT_DISCONNECT);
3034 /* MESSAGE_RELEASE */
3035 void Pdss1::message_release(unsigned long epoint_id, int message_id, union parameter *param)
3037 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
3039 RELEASE_COMPLETE_t *release_complete;
3040 DISCONNECT_t *disconnect;
3042 class Endpoint *epoint;
3045 /* if we have incoming disconnected, we may release */
3046 if (p_state==PORT_STATE_IN_DISCONNECT
3047 || p_state==PORT_STATE_OUT_DISCONNECT)
3049 /* sending release */
3050 dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, p_m_d_l3id, sizeof(RELEASE_t), p_m_d_ntmode);
3051 release = (RELEASE_t *)(dmsg->data + headerlen);
3052 l3_trace_header(CC_RELEASE | REQUEST, DIRECTION_OUT);
3054 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);
3056 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3057 new_state(PORT_STATE_RELEASE);
3060 free_epointid(epoint_id);
3061 l3_trace_header(CC_RELEASE_CR | REQUEST, DIRECTION_OUT);
3062 add_trace("callref", "new", "0x%x", p_m_d_l3id);
3066 if ((p_m_d_l3id&0xff00) == 0xff00)
3067 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
3073 /* if we are on outgoing/incoming call setup, we may release complete */
3074 if (p_state==PORT_STATE_OUT_SETUP
3075 || p_state==PORT_STATE_IN_SETUP
3076 // NOTE: a bug in mISDNuser (see disconnect_req_out !!!)
3077 || p_state==PORT_STATE_OUT_PROCEEDING)
3079 /* sending release */
3080 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
3081 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
3082 l3_trace_header(CC_RELEASE | REQUEST, DIRECTION_OUT);
3084 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);
3086 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3087 new_state(PORT_STATE_RELEASE);
3088 goto remove_endpoint;
3091 /* NT-MODE in setup state we must send PROCEEDING first */
3092 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
3094 CALL_PROCEEDING_t *proceeding;
3096 /* sending proceeding */
3097 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
3098 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
3099 l3_trace_header(CC_PROCEEDING | REQUEST, DIRECTION_OUT);
3100 /* channel information */
3101 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
3102 /* progress information */
3103 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
3104 || p_capainfo.bearer_capa==INFO_BC_AUDIO
3105 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
3106 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
3108 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3111 /* sending disconnect */
3112 dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode);
3113 disconnect = (DISCONNECT_t *)(dmsg->data + headerlen);
3114 l3_trace_header(CC_DISCONNECT | REQUEST, DIRECTION_OUT);
3115 /* progress information */
3116 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
3117 || p_capainfo.bearer_capa==INFO_BC_AUDIO
3118 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
3119 if (p_m_mISDNport->is_tones)
3120 enc_ie_progress(&disconnect->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
3122 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);
3124 epoint = find_epoint_id(epoint_id);
3125 if (param->disconnectinfo.display[0])
3126 p = param->disconnectinfo.display;
3127 if (p) if (*p && p_m_d_ntmode)
3128 enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p);
3130 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3131 new_state(PORT_STATE_RELEASE);
3132 free_epointid(epoint_id);
3138 * endpoint sends messages to the port
3140 int Pdss1::message_epoint(unsigned long epoint_id, int message_id, union parameter *param)
3142 struct message *message;
3144 if (PmISDN::message_epoint(epoint_id, message_id, param))
3149 case MESSAGE_INFORMATION: /* overlap dialing */
3150 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received dialing info '%s'.\n", p_name, param->information.number);
3151 if (p_type==PORT_TYPE_DSS1_NT_OUT
3152 && p_state!=PORT_STATE_OUT_OVERLAP
3153 && p_state!=PORT_STATE_CONNECT
3154 && p_state!=PORT_STATE_OUT_DISCONNECT
3155 && p_state!=PORT_STATE_IN_DISCONNECT)
3157 PDEBUG(DEBUG_ISDN, "Pdss1(%s) (internal outgoing) ignoring information, invalid state.\n", p_name);
3160 if (p_type==PORT_TYPE_DSS1_TE_OUT
3161 && p_state!=PORT_STATE_OUT_OVERLAP
3162 && p_state!=PORT_STATE_OUT_PROCEEDING
3163 && p_state!=PORT_STATE_OUT_ALERTING
3164 && p_state!=PORT_STATE_CONNECT
3165 && p_state!=PORT_STATE_OUT_DISCONNECT
3166 && p_state!=PORT_STATE_IN_DISCONNECT)
3168 if (options.deb & DEBUG_ISDN)
3169 PERROR("Pdss1(%s) (external outgoing) ignoring information, invalid state.\n", p_name);
3172 if ((p_type==PORT_TYPE_DSS1_NT_IN || p_type==PORT_TYPE_DSS1_TE_IN)
3173 && p_state!=PORT_STATE_IN_OVERLAP
3174 && p_state!=PORT_STATE_IN_PROCEEDING
3175 && p_state!=PORT_STATE_IN_ALERTING
3176 && p_state!=PORT_STATE_CONNECT
3177 && p_state!=PORT_STATE_CONNECT_WAITING
3178 && p_state!=PORT_STATE_OUT_DISCONNECT
3179 && p_state!=PORT_STATE_IN_DISCONNECT)
3181 PDEBUG(DEBUG_ISDN, "Pdss1(%s) (incoming) ignoring information, invalid state.\n", p_name);
3184 message_information(epoint_id, message_id, param);
3187 case MESSAGE_SETUP: /* dial-out command received from epoint */
3188 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);
3189 if (p_state!=PORT_STATE_IDLE
3190 && p_state!=PORT_STATE_CONNECT)
3192 PERROR("Pdss1(%s) ignoring setup because isdn port is not in idle state (or connected for sending display info).\n", p_name);
3195 if (p_epointlist && p_state==PORT_STATE_IDLE)
3197 PERROR("Pdss1(%s): software error: epoint pointer is set in idle state, how bad!! exitting.\n", p_name);
3200 /* note: pri is a special case, because links must be up for pri */
3201 if (p_m_mISDNport->l1link || p_m_mISDNport->pri || !p_m_mISDNport->ntmode || p_state!=PORT_STATE_IDLE)
3203 /* LAYER 1 is up, or we may send */
3204 message_setup(epoint_id, message_id, param);
3207 /* LAYER 1 id down, so we queue */
3208 p_m_d_queue = message_create(epoint_id, p_serial, EPOINT_TO_PORT, message_id);
3209 memcpy(&p_m_d_queue->param, param, sizeof(union parameter));
3211 if (!(epointlist_new(epoint_id)))
3213 PERROR("no memory for epointlist\n");
3217 PDEBUG(DEBUG_ISDN, "the L1 is down, we try to establish the link NT portnum=%d (%s).\n", p_m_mISDNport->portnum, p_name);
3218 act.prim = PH_ACTIVATE | REQUEST;
3219 act.addr = p_m_mISDNport->upper_id | FLG_MSG_DOWN;
3222 mISDN_write(mISDNdevice, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
3223 // /* set timeout */
3224 // p_m_mISDNport->l1timeout = now+3;
3228 case MESSAGE_NOTIFY: /* display and notifications */
3229 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);
3230 message_notify(epoint_id, message_id, param);
3233 case MESSAGE_FACILITY: /* facility message */
3234 PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received facility.\n", p_name, p_callerinfo.id);
3235 message_facility(epoint_id, message_id, param);
3238 case MESSAGE_OVERLAP: /* more information is needed */
3239 PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received setup acknowledge\n", p_name, p_callerinfo.id);
3240 if (p_state!=PORT_STATE_IN_SETUP)
3242 PDEBUG(DEBUG_ISDN, "Pdss1(%s) ignoring setup acknowledge because isdn port is not incoming setup state.\n", p_name);
3245 message_overlap(epoint_id, message_id, param);
3248 case MESSAGE_PROCEEDING: /* call of endpoint is proceeding */
3249 PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received proceeding\n", p_name, p_callerinfo.id);
3250 if (p_state!=PORT_STATE_IN_SETUP
3251 && p_state!=PORT_STATE_IN_OVERLAP)
3253 PDEBUG(DEBUG_ISDN, "Pdss1(%s) ignoring: proceeding command not possible in current state.\n", p_name);
3256 message_proceeding(epoint_id, message_id, param);
3259 case MESSAGE_ALERTING: /* call of endpoint is ringing */
3260 PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received alerting\n", p_name, p_callerinfo.id);
3261 if (p_state!=PORT_STATE_IN_SETUP
3262 && p_state!=PORT_STATE_IN_OVERLAP
3263 && p_state!=PORT_STATE_IN_PROCEEDING)
3265 PDEBUG(DEBUG_ISDN, "Pdss1(%s) ignoring: alerting command not possible in current state.\n", p_name);
3268 message_alerting(epoint_id, message_id, param);
3271 case MESSAGE_CONNECT: /* call of endpoint is connected */
3272 PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received connect\n", p_name, p_callerinfo.id);
3273 if (p_state!=PORT_STATE_IN_SETUP
3274 && p_state!=PORT_STATE_IN_OVERLAP
3275 && p_state!=PORT_STATE_IN_PROCEEDING
3276 && p_state!=PORT_STATE_IN_ALERTING
3277 && !(p_state==PORT_STATE_CONNECT && p_m_d_ntmode))
3279 PDEBUG(DEBUG_ISDN, "Pdss1(%s) ignoring: connect command not possible in current state.\n", p_name);
3282 message_connect(epoint_id, message_id, param);
3285 case MESSAGE_DISCONNECT: /* call has been disconnected */
3286 PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received disconnect cause=%d\n", p_name, p_callerinfo.id, param->disconnectinfo.cause);
3287 if (p_state!=PORT_STATE_IN_SETUP
3288 && p_state!=PORT_STATE_IN_OVERLAP
3289 && p_state!=PORT_STATE_IN_PROCEEDING
3290 && p_state!=PORT_STATE_IN_ALERTING
3291 && p_state!=PORT_STATE_OUT_SETUP
3292 && p_state!=PORT_STATE_OUT_OVERLAP
3293 && p_state!=PORT_STATE_OUT_PROCEEDING
3294 && p_state!=PORT_STATE_OUT_ALERTING
3295 && p_state!=PORT_STATE_CONNECT
3296 && p_state!=PORT_STATE_CONNECT_WAITING)
3298 PDEBUG(DEBUG_ISDN, "Pdss1(%s) ignoring: disconnect command not possible in current state.\n", p_name);
3301 message_disconnect(epoint_id, message_id, param);
3304 case MESSAGE_RELEASE: /* release isdn port */
3305 PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received release cause=%d\n", p_name, p_callerinfo.id, param->disconnectinfo.cause);
3306 if (p_state==PORT_STATE_RELEASE)
3308 PDEBUG(DEBUG_ISDN, "Pdss1(%s) ignoring: release command not possible in RELEASE state.\n", p_name);
3311 message_release(epoint_id, message_id, param);
3315 PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received a wrong message: %d\n", p_name, p_callerinfo.id, message);
3324 * data from isdn-stack (layer-3) to pbx (port class)
3326 /* NOTE: nt mode use mISDNuser_head_t as header */
3327 int stack2manager_nt(void *dat, void *arg)
3331 manager_t *mgr = (manager_t *)dat;
3332 msg_t *msg = (msg_t *)arg;
3333 mISDNuser_head_t *hh;
3334 struct mISDNport *mISDNport;
3340 /* note: nst is the first data feld of mISDNport */
3341 mISDNport = (struct mISDNport *)mgr->nst;
3343 hh = (mISDNuser_head_t *)msg->data;
3344 PDEBUG(DEBUG_ISDN, "prim(0x%x) dinfo(0x%x) msg->len(%d)\n", hh->prim, hh->dinfo, msg->len);
3346 /* find Port object of type ISDN */
3350 if (port->p_type == PORT_TYPE_DSS1_NT_IN || port->p_type == PORT_TYPE_DSS1_NT_OUT)
3352 pdss1 = (class Pdss1 *)port;
3353 //PDEBUG(DEBUG_ISDN, "comparing dinfo = 0x%x with l3id 0x%x\n", hh->dinfo, pdss1->p_m_d_l3id);
3354 /* check out correct stack */
3355 if (pdss1->p_m_mISDNport == mISDNport)
3356 /* check out correct id */
3357 if ((hh->dinfo&0xffff0000) == (pdss1->p_m_d_l3id&0xffff0000))
3359 /* found port, the message belongs to */
3367 /* if process id is master process, but a child disconnects */
3368 if ((hh->dinfo&0x0000ff00)!=0x0000ff00 && (pdss1->p_m_d_l3id&0x0000ff00)==0x0000ff00 && hh->prim==(CC_DISCONNECT|INDICATION))
3370 /* send special indication for child disconnect */
3371 pdss1->disconnect_ind_i(hh->prim, hh->dinfo, msg->data);
3375 /* if process id and layer 3 id matches */
3376 if (hh->dinfo == pdss1->p_m_d_l3id)
3378 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
3387 case MGR_SHORTSTATUS | INDICATION:
3388 case MGR_SHORTSTATUS | CONFIRM:
3390 case SSTATUS_L2_ESTABLISHED:
3392 case SSTATUS_L2_RELEASED:
3397 case DL_ESTABLISH | INDICATION:
3398 case DL_ESTABLISH | CONFIRM:
3400 PDEBUG(DEBUG_ISDN, "establish data link (DL) NT portnum=%d TEI=%d\n", mISDNport->portnum, hh->dinfo);
3401 if (mISDNport->ptp && hh->dinfo == 0)
3403 if (mISDNport->l2establish)
3405 mISDNport->l2establish = 0;
3406 PDEBUG(DEBUG_ISDN, "the link became active before l2establish timer expiry.\n");
3408 mISDNport->l2link = 1;
3409 if (mISDNport->pri);
3410 mISDNport->l1link = 1; /* this is a hack, we also assume L1 to be active */
3414 case DL_RELEASE | INDICATION:
3415 case DL_RELEASE | CONFIRM:
3417 PDEBUG(DEBUG_ISDN, "release data link (DL) NT portnum=%d TEI=%d\n", mISDNport->portnum, hh->dinfo);
3418 if (mISDNport->ptp && hh->dinfo == 0)
3420 mISDNport->l2link = 0;
3421 time(&mISDNport->l2establish);
3422 PDEBUG(DEBUG_ISDN, "because we are ptp, we set a l2establish timer.\n");
3426 case CC_SETUP | INDICATION:
3427 /* creating port object */
3428 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3429 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0)))
3431 RELEASE_COMPLETE_t *release_complete;
3434 PERROR("FATAL ERROR: cannot create port object.\n");
3435 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, hh->dinfo, sizeof(RELEASE_COMPLETE_t), mISDNport->ntmode);
3436 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + mISDN_HEADER_LEN);
3437 enc_ie_cause_standalone(mISDNport->ntmode?&release_complete->CAUSE:NULL, dmsg, (mISDNport->ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47);
3438 msg_queue_tail(&mISDNport->downqueue, dmsg);
3441 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
3444 case CC_RESUME | INDICATION:
3445 /* creating port object */
3446 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3447 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL)))
3449 SUSPEND_REJECT_t *suspend_reject;
3452 PERROR("FATAL ERROR: cannot create port object.\n");
3453 dmsg = create_l3msg(CC_SUSPEND_REJECT | REQUEST, MT_SUSPEND_REJECT, hh->dinfo, sizeof(SUSPEND_REJECT_t), mISDNport->ntmode);
3454 suspend_reject = (SUSPEND_REJECT_t *)(dmsg->data + mISDN_HEADER_LEN);
3455 enc_ie_cause_standalone(mISDNport->ntmode?&suspend_reject->CAUSE:NULL, dmsg, (mISDNport->ntmode)?1:0, 47);
3456 msg_queue_tail(&mISDNport->downqueue, dmsg);
3459 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
3462 case CC_RELEASE_CR | INDICATION:
3463 PDEBUG(DEBUG_ISDN, "%s: unhandled message from stack: call ref released (l3id=0x%x)\n", __FUNCTION__, hh->dinfo);
3466 case CC_DISCONNECT | INDICATION:
3470 PDEBUG(DEBUG_ISDN, "%s: unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", __FUNCTION__, hh->prim, hh->dinfo, msg->len);
3477 /* NOTE: te mode use iframe_t as header */
3478 int stack2manager_te(struct mISDNport *mISDNport, msg_t *msg)
3485 if (!msg || !mISDNport)
3487 frm = (iframe_t *)msg->data;
3488 PDEBUG(DEBUG_ISDN, "prim(0x%x) dinfo(0x%x) msg->len(%d)\n", frm->prim, frm->dinfo, msg->len);
3490 /* find Port object of type ISDN */
3494 if (port->p_type == PORT_TYPE_DSS1_TE_IN || port->p_type == PORT_TYPE_DSS1_TE_OUT)
3496 pdss1 = (class Pdss1 *)port;
3497 //PDEBUG(DEBUG_ISDN, "comparing dinfo = 0x%x with l3id 0x%x\n", frm->dinfo, pdss1->p_m_d_l3id);
3498 /* check out correct stack */
3499 if (pdss1->p_m_mISDNport == mISDNport)
3500 /* check out correct id */
3501 if (frm->dinfo == pdss1->p_m_d_l3id)
3503 /* found port, the message belongs to */
3511 pdss1->message_isdn(frm->prim, frm->dinfo, msg->data);
3516 /* process new cr (before setup indication) */
3517 //printf("prim = 0x%x, looking for 0x%x\n",frm->prim, (CC_NEW_CR | INDICATION));
3518 if (frm->prim == (CC_NEW_CR | INDICATION))
3521 /* creating port object */
3522 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3523 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_TE_IN, mISDNport, name, NULL)))
3525 RELEASE_COMPLETE_t *release_complete;
3528 PERROR("FATAL ERROR: cannot create port object.\n");
3529 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, frm->dinfo, sizeof(RELEASE_COMPLETE_t), mISDNport->ntmode);
3530 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + mISDN_HEADER_LEN);
3531 enc_ie_cause_standalone(mISDNport->ntmode?&release_complete->CAUSE:NULL, dmsg, (mISDNport->ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47);
3532 msg_queue_tail(&mISDNport->downqueue, dmsg);
3536 /* l3id will be set from dinfo at message_isdn */
3537 pdss1->message_isdn(frm->prim, frm->dinfo, msg->data);
3542 if (frm->prim == (CC_RELEASE_CR | INDICATION))
3544 PDEBUG(DEBUG_ISDN, "unhandled message from stack: call ref released (l3id=0x%x)\n", frm->dinfo);
3548 PDEBUG(DEBUG_ISDN, "unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", frm->prim, frm->dinfo, msg->len);
3554 * sending message that were queued during L1 activation
3555 * or releasing port if link is down
3557 void setup_queue(struct mISDNport *mISDNport, int link)
3561 struct message *message;
3563 if (!mISDNport->ntmode)
3566 /* check all port objects for pending message */
3570 if ((port->p_type&PORT_CLASS_mISDN_MASK) == PORT_CLASS_mISDN_DSS1)
3572 pdss1 = (class Pdss1 *)port;
3573 if (pdss1->p_m_mISDNport == mISDNport)
3575 if (pdss1->p_m_d_queue)
3579 PDEBUG(DEBUG_ISDN, "the L1 became active, so we send queued message for portnum=%d (%s).\n", mISDNport->portnum, pdss1->p_name);
3580 /* LAYER 1 is up, so we send */
3581 pdss1->message_setup(pdss1->p_m_d_queue->id_from, pdss1->p_m_d_queue->type, &pdss1->p_m_d_queue->param);
3582 message_free(pdss1->p_m_d_queue);
3583 pdss1->p_m_d_queue = NULL;
3586 PDEBUG(DEBUG_ISDN, "the L1 became NOT active, so we release port for portnum=%d (%s).\n", mISDNport->portnum, pdss1->p_name);
3587 message = message_create(pdss1->p_serial, pdss1->p_m_d_queue->id_from, PORT_TO_EPOINT, MESSAGE_RELEASE);
3588 message->param.disconnectinfo.cause = 27;
3589 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
3590 message_put(message);
3591 pdss1->new_state(PORT_STATE_RELEASE);
3592 pdss1->p_m_delete = 1;