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;
48 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);
57 /* remove queued message */
59 message_free(p_m_d_queue);
61 if (p_m_d_notify_pending)
62 message_free(p_m_d_notify_pending);
64 /* check how many processes are left */
65 if (p_m_d_ntmode == 1)
67 if (p_m_mISDNport->nst.layer3->proc)
68 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);
74 * create layer 3 message
76 static msg_t *create_l3msg(int prim, int mt, int dinfo, int size, int ntmode)
84 size = sizeof(Q931_info_t)+2;
90 dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL);
97 dmsg = alloc_msg(size+256+mISDN_HEADER_LEN+DEFAULT_HEADROOM);
100 memset(msg_put(dmsg,size+mISDN_HEADER_LEN), 0, size+mISDN_HEADER_LEN);
101 frm = (iframe_t *)dmsg->data;
104 qi = (Q931_info_t *)(dmsg->data + mISDN_HEADER_LEN);
111 PERROR("cannot allocate memory, trying again...\n");
115 PERROR("cannot allocate memory, system overloaded.\n");
119 msg_t *create_l2msg(int prim, int dinfo, int size) /* NT only */
126 dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL);
131 PERROR("cannot allocate memory, trying again...\n");
135 PERROR("cannot allocate memory, system overloaded.\n");
140 static struct isdn_message {
144 {"TIMEOUT", CC_TIMEOUT},
146 {"SETUP_ACK", CC_SETUP_ACKNOWLEDGE},
147 {"PROCEEDING", CC_PROCEEDING},
148 {"ALERTING", CC_ALERTING},
149 {"CONNECT", CC_CONNECT},
150 {"CONNECT RES", CC_CONNECT},
151 {"CONNECT_ACK", CC_CONNECT_ACKNOWLEDGE},
152 {"DISCONNECT", CC_DISCONNECT},
153 {"RELEASE", CC_RELEASE},
154 {"RELEASE_COMP", CC_RELEASE_COMPLETE},
155 {"INFORMATION", CC_INFORMATION},
156 {"PROGRESS", CC_PROGRESS},
157 {"NOTIFY", CC_NOTIFY},
158 {"SUSPEND", CC_SUSPEND},
159 {"SUSPEND_ACK", CC_SUSPEND_ACKNOWLEDGE},
160 {"SUSPEND_REJ", CC_SUSPEND_REJECT},
161 {"RESUME", CC_RESUME},
162 {"RESUME_ACK", CC_RESUME_ACKNOWLEDGE},
163 {"RESUME_REJ", CC_RESUME_REJECT},
165 {"HOLD_ACK", CC_HOLD_ACKNOWLEDGE},
166 {"HOLD_REJ", CC_HOLD_REJECT},
167 {"RETRIEVE", CC_RETRIEVE},
168 {"RETRIEVE_ACK", CC_RETRIEVE_ACKNOWLEDGE},
169 {"RETRIEVE_REJ", CC_RETRIEVE_REJECT},
170 {"FACILITY", CC_FACILITY},
171 {"STATUS", CC_STATUS},
172 {"RESTART", CC_RESTART},
173 {"RELEASE_CR", CC_RELEASE_CR},
174 {"NEW_CR", CC_NEW_CR},
175 {"DL_ESTABLSIH", DL_ESTABLSIH},
176 {"DL_RELEASE", DL_RELEASE},
177 {"PH_ACTICATIE", PH_ACTICATIE},
178 {"PH_DEACTICATIE", PH_DEACTICATIE},
183 static char *isdn_prim[4] = {
194 void Pdss1::l1l2l3_trace_header(unsigned long prim, int direction_out)
197 char msgtext[64] = "<<UNKNOWN MESSAGE>>";
199 /* select message and primitive text */
201 while(isdn_message[i].name)
203 if (isdn_message[i].value == (prim&0xffffff00))
205 SCPY(msgtext, isdn_message[i].name);
210 SCAT(msgtext, isdn_prim[prim&0x00000003]);
213 if (direction && (prim&0xffffff00)!=CC_NEW_CR && (prim&0xffffff00)!=CC_RELEASE_CR)
217 if (direction == DIRECTION_OUT)
218 SCAT(msgtext, " N->U");
220 SCAT(msgtext, " N<-U");
223 if (direction == DIRECTION_OUT)
224 SCAT(msgtext, " U->N");
226 SCAT(msgtext, " U<-N");
230 /* init trace with given values */
231 start_trace(p_m_mISDNport->portnum,
232 p_m_mISDNport->ifport->interface,
233 nationalize(p_callerinfo.id, p_callerinfo.ntype),
234 p_dialinginfo.number,
242 void Pdss1::chan_trace_header(char *msgtext)
247 /* init trace with given values */
248 start_trace(p_m_mISDNport->portnum,
249 p_m_mISDNport->ifport->interface,
250 nationalize(p_callerinfo.id, p_callerinfo.ntype),
251 p_dialinginfo.number,
260 * if we received a first reply to the setup message,
261 * we will check if we have now channel information
262 * return: <0: error, call is released, -cause is given
263 * 0: ok, nothing to do
265 int Pdss1::received_first_reply_to_setup(unsigned long prim, int channel, int exclusive)
268 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
269 RELEASE_COMPLETE_t *release_complete;
272 /* correct exclusive to 0, if no explicit channel was given */
273 if (exclusive<0 || channel<=0)
276 /* select scenario */
277 if (p_m_b_channel && p_m_b_exclusive)
279 /*** we gave an exclusive channel (or if we are done) ***/
281 /* if not first reply, we are done */
282 if (p_state != PORT_STATE_OUT_SETUP)
285 chan_trace_header("CHANNEL SELECTION (first reply to setup)");
286 add_trace("channel", "request", "%d (forced)", p_m_b_channel);
287 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
289 /* if give channel not accepted or not equal */
290 if (channel!=-1 && p_m_b_channel!=channel)
292 add_trace("conclusion", NULL, "forced channel not accepted");
298 add_trace("conclusion", NULL, "channel was accepted");
299 add_trace("connect", "channel", "%d", p_m_b_channel);
302 /* activate our exclusive channel */
303 bchannel_activate(p_m_mISDNport, p_m_b_index);
307 /*** we gave a non-exclusive channel ***/
309 /* if not first reply, we are done */
310 if (p_state != PORT_STATE_OUT_SETUP)
313 chan_trace_header("CHANNEL SELECTION (first reply to setup)");
314 add_trace("channel", "request", "%d (suggest)", p_m_b_channel);
315 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
317 /* if channel was accepted as given */
318 if (channel==-1 || p_m_b_channel==channel)
320 add_trace("conclusion", NULL, "channel was accepted as given");
321 add_trace("connect", "channel", "%d", p_m_b_channel);
323 p_m_b_exclusive = 1; // we are done
324 bchannel_activate(p_m_mISDNport, p_m_b_index);
328 /* if channel value is faulty */
331 add_trace("conclusion", NULL, "illegal reply");
333 ret = -111; // protocol error
337 /* if channel was not accepted, try to get it */
338 ret = seize_bchannel(channel, 1); // exclusively
339 add_trace("channel", "available", ret<0?"no":"yes");
342 add_trace("conclusion", NULL, "replied channel not available");
346 add_trace("conclusion", NULL, "replied channel accepted");
347 add_trace("connect", "channel", "%d", p_m_b_channel);
350 /* activate channel given by remote */
351 bchannel_activate(p_m_mISDNport, p_m_b_index);
355 /*** we sent 'any channel acceptable' ***/
357 /* if not first reply, we are done */
358 if (p_state != PORT_STATE_OUT_SETUP)
361 chan_trace_header("CHANNEL SELECTION (first reply to setup)");
362 add_trace("channel", "request", "any");
363 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
364 /* if no channel was replied */
367 add_trace("conclusion", NULL, "no channel, protocol error");
369 ret = -111; // protocol error
373 /* we will see, if our received channel is available */
374 ret = seize_bchannel(channel, 1); // exclusively
375 add_trace("channel", "available", ret<0?"no":"yes");
378 add_trace("conclusion", NULL, "replied channel not available");
382 add_trace("conclusion", NULL, "replied channel accepted");
383 add_trace("connect", "channel", "%d", p_m_b_channel);
386 /* activate channel given by remote */
387 bchannel_activate(p_m_mISDNport, p_m_b_index);
390 /*** we sent 'no channel available' ***/
392 /* if not the first reply, but a connect, we are forced */
393 if (prim==(CC_CONNECT | INDICATION) && p_state!=PORT_STATE_OUT_SETUP)
395 chan_trace_header("CHANNEL SELECTION (connect)");
396 add_trace("channel", "request", "no-channel");
397 add_trace("channel", "reply", (channel>=0)?"%d%s":"(none)", channel, exclusive?" (forced)":"");
400 goto use_from_connect;
402 ret = seize_bchannel(CHANNEL_ANY, 0); // any channel
403 add_trace("channel", "available", ret<0?"no":"yes");
406 add_trace("conclusion", NULL, "no channel available during call-waiting");
410 add_trace("conclusion", NULL, "using channel %d", p_m_b_channel);
411 add_trace("connect", "channel", "%d", p_m_b_channel);
413 p_m_b_exclusive = 1; // we are done
415 /* activate channel given by remote */
416 bchannel_activate(p_m_mISDNport, p_m_b_index);
420 /* if not first reply, we are done */
421 if (p_state != PORT_STATE_OUT_SETUP)
424 chan_trace_header("CHANNEL SELECTION (first reply to setup)");
425 add_trace("channel", "request", "no-channel");
426 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
427 /* if first reply has no channel, we are done */
430 add_trace("conclusion", NULL, "no channel until connect");
435 /* we will see, if our received channel is available */
437 ret = seize_bchannel(channel, exclusive);
438 add_trace("channel", "available", ret<0?"no":"yes");
441 add_trace("conclusion", NULL, "replied channel not available");
445 add_trace("conclusion", NULL, "replied channel accepted");
446 add_trace("connect", "channel", "%d", p_m_b_channel);
448 p_m_b_exclusive = 1; // we are done
450 /* activate channel given by remote */
451 bchannel_activate(p_m_mISDNport, p_m_b_index);
456 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
457 l1l2l3_trace_header(CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
459 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
460 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
462 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
463 new_state(PORT_STATE_RELEASE);
465 return(-34); /* to epoint: no channel available */
470 * handles all indications
472 /* CC_SETUP INDICATION */
473 void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
475 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
476 SETUP_t *setup = (SETUP_t *)((unsigned long)data + headerlen);
477 int type, plan, present, screen, reason;
478 int coding, capability, mode, rate, multi, user, presentation, interpretation, hlc, exthlc;
479 int exclusive, channel;
482 unsigned char keypad[32] = "";
483 unsigned char useruser[128];
484 int useruser_len = 0, useruser_protocol;
485 class Endpoint *epoint;
486 struct message *message;
488 /* callref from nt-lib */
491 /* nt-library now gives us the id via CC_SETUP */
492 if (dinfo&(~0xff) == 0xff00)
494 PERROR("fatal software error: l3-stack gives us a process id 0xff00-0xffff\n");
497 l1l2l3_trace_header(CC_NEW_CR | INDICATION, DIRECTION_IN);
499 add_trace("callref", "old", "0x%x", p_m_d_l3id);
500 add_trace("callref", "new", "0x%x", dinfo);
502 if (p_m_d_l3id&(~0xff) == 0xff00)
503 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
505 p_m_d_ces = setup->ces;
508 l1l2l3_trace_header(prim, DIRECTION_IN);
509 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));
510 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));
511 dec_ie_keypad(setup->KEYPAD, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)keypad, sizeof(keypad));
513 /* te-mode: CNIP (calling name identification presentation) */
515 dec_facility_centrex(setup->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)p_callerinfo.name, sizeof(p_callerinfo.name));
517 dec_ie_useruser(setup->USER_USER, (Q931_info_t *)((unsigned long)data+headerlen), &useruser_protocol, useruser, &useruser_len);
518 dec_ie_complete(setup->COMPLETE, (Q931_info_t *)((unsigned long)data+headerlen), &p_dialinginfo.sending_complete);
519 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));
520 dec_ie_channel_id(setup->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
521 dec_ie_hlc(setup->HLC, (Q931_info_t *)((unsigned long)data+headerlen), &hlc_coding, &interpretation, &presentation, &hlc, &exthlc);
522 dec_ie_bearer(setup->BEARER, (Q931_info_t *)((unsigned long)data+headerlen), &bearer_coding, &capability, &mode, &rate, &multi, &user);
525 /* if blocked, release call */
526 if (p_m_mISDNport->ifport->block)
528 RELEASE_COMPLETE_t *release_complete;
530 printlog("--- port#%d is blocked.\n", mISDNport->ifport->portnum);
531 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
532 l1l2l3_trace_header(CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
533 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
534 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 27); /* temporary unavailable */
535 add_trace("reason", NULL, "port blocked");
537 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
538 new_state(PORT_STATE_RELEASE);
547 p_callerinfo.present = INFO_PRESENT_RESTRICTED;
550 p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
553 p_callerinfo.present = INFO_PRESENT_ALLOWED;
559 p_callerinfo.screen = INFO_SCREEN_USER;
562 p_callerinfo.screen = INFO_SCREEN_NETWORK;
568 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
569 p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
570 p_callerinfo.screen = INFO_SCREEN_NETWORK;
573 p_callerinfo.ntype = INFO_NTYPE_INTERNATIONAL;
576 p_callerinfo.ntype = INFO_NTYPE_NATIONAL;
579 p_callerinfo.ntype = INFO_NTYPE_SUBSCRIBER;
582 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
585 p_callerinfo.isdn_port = p_m_portnum;
586 SCPY(p_callerinfo.interface, p_m_mISDNport->ifport->interface->name);
588 /* dialing information */
589 SCAT(p_dialinginfo.number, (char *)keypad);
593 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
596 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
599 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
602 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
608 p_redirinfo.present = INFO_PRESENT_RESTRICTED;
611 p_redirinfo.present = INFO_PRESENT_NOTAVAIL;
614 p_redirinfo.present = INFO_PRESENT_ALLOWED;
620 p_redirinfo.screen = INFO_SCREEN_USER;
623 p_redirinfo.screen = INFO_SCREEN_NETWORK;
629 p_redirinfo.reason = INFO_REDIR_BUSY;
632 p_redirinfo.reason = INFO_REDIR_NORESPONSE;
635 p_redirinfo.reason = INFO_REDIR_UNCONDITIONAL;
638 p_redirinfo.reason = INFO_REDIR_CALLDEFLECT;
641 p_redirinfo.reason = INFO_REDIR_OUTOFORDER;
644 p_redirinfo.reason = INFO_REDIR_UNKNOWN;
650 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
651 p_redirinfo.present = INFO_PRESENT_NULL; /* not redirecting */
652 p_redirinfo.reason = INFO_REDIR_UNKNOWN;
655 p_redirinfo.ntype = INFO_NTYPE_INTERNATIONAL;
658 p_redirinfo.ntype = INFO_NTYPE_NATIONAL;
661 p_redirinfo.ntype = INFO_NTYPE_SUBSCRIBER;
664 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
667 p_redirinfo.isdn_port = p_m_portnum;
669 /* bearer capability */
673 p_capainfo.bearer_capa = INFO_BC_AUDIO;
674 user = (options.law=='a')?3:2;
677 p_capainfo.bearer_capa = capability;
683 p_capainfo.bearer_mode = INFO_BMODE_PACKET;
686 p_capainfo.bearer_mode = INFO_BMODE_CIRCUIT;
692 p_capainfo.bearer_info1 = INFO_INFO1_NONE;
695 p_capainfo.bearer_info1 = user + 0x80;
703 p_capainfo.hlc = INFO_HLC_NONE;
706 p_capainfo.hlc = hlc + 0x80;
712 p_capainfo.exthlc = INFO_HLC_NONE;
715 p_capainfo.exthlc = exthlc + 0x80;
719 /* process channel */
720 chan_trace_header("CHANNEL SELECTION (setup)");
723 if (channel == CHANNEL_NO)
724 add_trace("channel", "request", "no-channel");
726 add_trace("channel", "request", (channel>0)?"%d%s":"any", channel, exclusive?" (forced)":"");
727 if (channel==CHANNEL_NO && p_type==PORT_TYPE_DSS1_TE_IN)
729 add_trace("conclusion", NULL, "incoming call-waiting not supported for TE-mode");
731 ret = -6; // channel unacceptable
734 if (channel <= 0) /* not given, no channel, whatever.. */
735 channel = CHANNEL_ANY; /* any channel */
736 if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num) // of out chan..
738 add_trace("channel", "reserved", "%d", p_m_mISDNport->b_reserved);
739 add_trace("conclusion", NULL, "all channels are reserved");
741 ret = -34; // no channel
744 if (channel == CHANNEL_ANY)
748 /* check for given channel in selection list */
749 selchannel = ifport->channel_in;
752 if (selchannel->channel == channel || selchannel->channel == CHANNEL_FREE)
754 selchannel = selchannel->next;
759 /* exclusive channel requests must be in the list */
764 add_trace("conclusion", NULL, "exclusively requested channel not in list");
766 ret = 6; // unacceptable
769 i = selchannel->channel-1-(selchannel->channel>=17);
770 if (mISDNport->b_port[i] == NULL)
772 add_trace("conclusion", NULL, "exclusively requested channel is busy");
774 ret = 6; // unacceptable
778 /* requested channels in list will be used */
781 i = selchannel->channel-1-(selchannel->channel>=17);
782 if (mISDNport->b_port[i] == NULL)
786 /* if channel is not available or not in list, it must be searched */
788 /* check for first free channel in list */
790 selchannel = ifport->channel_in;
793 switch(selchannel->channel)
795 case CHANNEL_FREE: /* free channel */
796 add_trace("hunting", "channel", "free");
797 if (mISDNport->b_inuse >= mISDNport->b_num)
798 break; /* all channel in use or reserverd */
801 while(i < mISDNport->b_num)
803 if (mISDNport->b_port[i] == NULL)
805 channel = i+1+(i>=15);
813 add_trace("hunting", "channel", "%d", selchannel->channel);
814 if (selchannel->channel<1 || selchannel->channel==16)
815 break; /* invalid channels */
816 i = selchannel->channel-1-(selchannel->channel>=17);
817 if (i >= mISDNport->b_num)
818 break; /* channel not in port */
819 if (mISDNport->b_port[i] == NULL)
821 channel = selchannel->channel;
827 break; /* found channel */
828 selchannel = selchannel->next;
832 add_trace("conclusion", NULL, "no channel available");
834 ret = 6; // unacceptable
841 ret = seize_bchannel(channel, 1);
844 add_trace("conclusion", NULL, "channel not available");
847 RELEASE_COMPLETE_t *release_complete;
849 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
850 l1l2l3_trace_header(CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
851 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
852 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
854 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
855 new_state(PORT_STATE_RELEASE);
859 add_trace("conclusion", NULL, "channel available");
860 add_trace("connect", "channel", "%d", p_m_b_channel);
862 bchannel_activate(p_m_mISDNport, p_m_b_index);
864 /* create endpoint */
867 PERROR("SOFTWARE ERROR: incoming call but already got an endpoint, exitting...\n");
870 if (!(epoint = new Endpoint(p_serial, 0)))
872 RELEASE_COMPLETE_t *release_complete;
874 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
875 l1l2l3_trace_header(CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
876 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
877 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 41); /* temporary failure */
879 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
880 new_state(PORT_STATE_RELEASE);
884 if (!(epoint->ep_app = new DEFAULT_ENDPOINT_APP(epoint)))
886 PERROR("no memory for application\n");
889 if (!(epointlist_new(epoint->ep_serial)))
891 PERROR("no memory for epointlist\n");
894 /* send setup message to endpoit */
895 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_SETUP);
896 message->param.setup.isdn_port = p_m_portnum;
897 message->param.setup.port_type = p_type;
898 memcpy(&message->param.setup.dialinginfo, &p_dialinginfo, sizeof(struct dialing_info));
899 memcpy(&message->param.setup.callerinfo, &p_callerinfo, sizeof(struct caller_info));
900 memcpy(&message->param.setup.redirinfo, &p_redirinfo, sizeof(struct redir_info));
901 memcpy(&message->param.setup.capainfo, &p_capainfo, sizeof(struct capa_info));
902 memcpy(message->param.setup.useruser.data, &useruser, useruser_len);
903 message->param.setup.useruser.len = useruser_len;
904 message->param.setup.useruser.protocol = useruser_protocol;
905 message_put(message);
907 new_state(PORT_STATE_IN_SETUP);
910 /* CC_INFORMATION INDICATION */
911 void Pdss1::information_ind(unsigned long prim, unsigned long dinfo, void *data)
913 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
914 INFORMATION_t *information = (INFORMATION_t *)((unsigned long)data + headerlen);
916 unsigned char keypad[32] = "";
917 struct message *message;
919 l1l2l3_trace_header(prim, DIRECTION_IN);
920 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));
921 dec_ie_keypad(information->KEYPAD, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)keypad, sizeof(keypad));
922 dec_ie_complete(information->COMPLETE, (Q931_info_t *)((unsigned long)data+headerlen), &p_dialinginfo.sending_complete);
925 SCAT(p_dialinginfo.number, (char *)keypad);
929 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
932 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
935 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
938 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
941 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_INFORMATION);
942 memcpy(&message->param.information, &p_dialinginfo, sizeof(struct dialing_info));
943 message_put(message);
944 /* reset overlap timeout */
948 /* CC_SETUP_ACCNOWLEDGE INDICATION */
949 void Pdss1::setup_acknowledge_ind(unsigned long prim, unsigned long dinfo, void *data)
951 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
952 SETUP_ACKNOWLEDGE_t *setup_acknowledge = (SETUP_ACKNOWLEDGE_t *)((unsigned long)data + headerlen);
953 int exclusive, channel;
954 int coding, location, progress;
956 struct message *message;
958 l1l2l3_trace_header(prim, DIRECTION_IN);
959 dec_ie_channel_id(setup_acknowledge->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
960 dec_ie_progress(setup_acknowledge->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
963 /* process channel */
964 ret = received_first_reply_to_setup(prim, exclusive, channel);
967 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
968 message->param.disconnectinfo.cause = -ret;
969 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
970 message_put(message);
971 new_state(PORT_STATE_RELEASE);
976 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_OVERLAP);
977 message_put(message);
979 new_state(PORT_STATE_OUT_OVERLAP);
982 /* CC_PROCEEDING INDICATION */
983 void Pdss1::proceeding_ind(unsigned long prim, unsigned long dinfo, void *data)
985 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
986 CALL_PROCEEDING_t *proceeding = (CALL_PROCEEDING_t *)((unsigned long)data + headerlen);
987 int exclusive, channel;
988 int coding, location, progress;
990 struct message *message;
991 int notify = -1, type, plan, present;
994 l1l2l3_trace_header(prim, DIRECTION_IN);
995 dec_ie_channel_id(proceeding->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
996 dec_ie_progress(proceeding->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
997 dec_ie_notify(NULL/*proceeding->NOTIFY*/, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
998 dec_ie_redir_dn(proceeding->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
1001 ret = received_first_reply_to_setup(prim, exclusive, channel);
1004 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1005 message->param.disconnectinfo.cause = -ret;
1006 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1007 message_put(message);
1008 new_state(PORT_STATE_RELEASE);
1012 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROCEEDING);
1013 message_put(message);
1015 new_state(PORT_STATE_OUT_PROCEEDING);
1021 if (type >= 0 || notify)
1023 if (!notify && type >= 0)
1025 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1026 message->param.notifyinfo.notify = notify;
1027 SCPY(message->param.notifyinfo.id, redir);
1028 /* redirection number */
1032 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1035 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1038 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1044 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1045 message->param.notifyinfo.present = INFO_PRESENT_NULL;
1048 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1051 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1054 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1057 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1060 message->param.notifyinfo.isdn_port = p_m_portnum;
1061 message_put(message);
1065 /* CC_ALERTING INDICATION */
1066 void Pdss1::alerting_ind(unsigned long prim, unsigned long dinfo, void *data)
1068 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1069 ALERTING_t *alerting = (ALERTING_t *)((unsigned long)data + headerlen);
1070 int exclusive, channel;
1071 int coding, location, progress;
1073 struct message *message;
1074 int notify = -1, type, plan, present;
1077 l1l2l3_trace_header(prim, DIRECTION_IN);
1078 dec_ie_channel_id(alerting->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
1079 dec_ie_progress(alerting->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
1080 dec_ie_notify(NULL/*alerting->NOTIFY*/, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
1081 dec_ie_redir_dn(alerting->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
1084 /* process channel */
1085 ret = received_first_reply_to_setup(prim, exclusive, channel);
1088 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1089 message->param.disconnectinfo.cause = -ret;
1090 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1091 message_put(message);
1092 new_state(PORT_STATE_RELEASE);
1096 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_ALERTING);
1097 message_put(message);
1099 new_state(PORT_STATE_OUT_ALERTING);
1105 if (type >= 0 || notify)
1107 if (!notify && type >= 0)
1109 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1110 message->param.notifyinfo.notify = notify;
1111 SCPY(message->param.notifyinfo.id, redir);
1115 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1118 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1121 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1127 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1128 message->param.notifyinfo.present = INFO_PRESENT_NULL;
1131 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1134 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1137 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1140 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1143 message->param.notifyinfo.isdn_port = p_m_portnum;
1144 message_put(message);
1148 /* CC_CONNECT INDICATION */
1149 void Pdss1::connect_ind(unsigned long prim, unsigned long dinfo, void *data)
1151 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1152 CONNECT_t *connect = (CONNECT_t *)((unsigned long)data + headerlen);
1153 int exclusive, channel;
1154 int type, plan, present, screen;
1157 struct message *message;
1158 int bchannel_before;
1159 CONNECT_ACKNOWLEDGE_t *connect_acknowledge;
1162 p_m_d_ces = connect->ces;
1164 l1l2l3_trace_header(prim, DIRECTION_IN);
1165 dec_ie_channel_id(connect->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
1166 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));
1168 /* te-mode: CONP (connected name identification presentation) */
1170 dec_facility_centrex(connect->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)p_connectinfo.name, sizeof(p_connectinfo.name));
1174 /* select channel */
1175 bchannel_before = p_m_b_channel;
1176 ret = received_first_reply_to_setup(prim, exclusive, channel);
1179 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1180 message->param.disconnectinfo.cause = -ret;
1181 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1182 message_put(message);
1183 new_state(PORT_STATE_RELEASE);
1188 /* connect information */
1192 p_connectinfo.present = INFO_PRESENT_RESTRICTED;
1195 p_connectinfo.present = INFO_PRESENT_NOTAVAIL;
1198 p_connectinfo.present = INFO_PRESENT_ALLOWED;
1204 p_connectinfo.screen = INFO_SCREEN_USER;
1207 p_connectinfo.screen = INFO_SCREEN_NETWORK;
1213 p_connectinfo.present = INFO_PRESENT_NULL; /* no COLP info */
1214 p_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1217 p_connectinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1220 p_connectinfo.ntype = INFO_NTYPE_NATIONAL;
1223 p_connectinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1226 p_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1229 p_connectinfo.isdn_port = p_m_portnum;
1230 SCPY(p_connectingo.interface, p_m_mISDNport->ifport->interface->name);
1232 /* send connect acknowledge */
1233 dmsg = create_l3msg(CC_CONNECT | RESPONSE, MT_CONNECT, dinfo, sizeof(CONNECT_ACKNOWLEDGE_t), p_m_d_ntmode);
1234 l1l2l3_trace_header(CC_CONNECT | RESPONSE, DIRECTION_OUT);
1235 connect_acknowledge = (CONNECT_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1236 /* if we had no bchannel before, we send it now */
1237 if (!bchannel_before && p_m_b_channel)
1238 enc_ie_channel_id(&connect_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
1240 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1242 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CONNECT);
1243 memcpy(&message->param.connectinfo, &p_connectinfo, sizeof(struct connect_info));
1244 message_put(message);
1246 new_state(PORT_STATE_CONNECT);
1249 /* CC_DISCONNECT INDICATION */
1250 void Pdss1::disconnect_ind(unsigned long prim, unsigned long dinfo, void *data)
1252 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1253 DISCONNECT_t *disconnect = (DISCONNECT_t *)((unsigned long)data + headerlen);
1254 int location, cause;
1255 int coding, proglocation, progress;
1256 struct message *message;
1258 l1l2l3_trace_header(prim, DIRECTION_IN);
1259 dec_ie_progress(disconnect->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &proglocation, &progress);
1260 dec_ie_cause(disconnect->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1266 /* release if we are remote sends us no tones */
1267 if (p_m_mISDNport->is_earlyb)
1272 dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, dinfo, sizeof(RELEASE_t), p_m_d_ntmode);
1273 release = (RELEASE_t *)(dmsg->data + headerlen);
1274 l1l2l3_trace_header(CC_RELEASE | REQUEST, DIRECTION_OUT);
1275 enc_ie_cause(&release->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16); /* normal */
1276 add_trace("reason", NULL, "no remote patterns");
1278 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1280 /* sending release to endpoint */
1283 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1284 message->param.disconnectinfo.cause = cause;
1285 message->param.disconnectinfo.location = location;
1286 message_put(message);
1288 free_epointlist(p_epointlist);
1290 new_state(PORT_STATE_RELEASE);
1295 /* sending disconnect to active endpoint and release to inactive endpoints */
1296 if (ACTIVE_EPOINT(p_epointlist))
1298 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DISCONNECT);
1299 message->param.disconnectinfo.location = location;
1300 message->param.disconnectinfo.cause = cause;
1301 message_put(message);
1303 while(INACTIVE_EPOINT(p_epointlist))
1305 message = message_create(p_serial, INACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1306 message->param.disconnectinfo.location = location;
1307 message->param.disconnectinfo.cause = cause;
1308 message_put(message);
1310 free_epointid(INACTIVE_EPOINT(p_epointlist));
1312 new_state(PORT_STATE_IN_DISCONNECT);
1315 /* CC_DISCONNECT INDICATION */
1316 void Pdss1::disconnect_ind_i(unsigned long prim, unsigned long dinfo, void *data)
1318 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1319 DISCONNECT_t *disconnect = (DISCONNECT_t *)((unsigned long)data + headerlen);
1320 int location, cause;
1323 l1l2l3_trace_header(prim, DIRECTION_IN);
1324 if (p_m_d_collect_cause > 0)
1326 add_trace("old-cause", "location", "%d", p_m_d_collect_location);
1327 add_trace("old-cause", "value", "%d", p_m_d_collect_cause);
1329 dec_ie_cause(disconnect->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1333 if (cause == CAUSE_REJECTED) /* call rejected */
1335 p_m_d_collect_cause = CAUSE_REJECTED;
1336 p_m_d_collect_location = location;
1338 if (cause==CAUSE_NORMAL && p_m_d_collect_cause!=CAUSE_REJECTED) /* reject via hangup */
1340 p_m_d_collect_cause = CAUSE_NORMAL;
1341 p_m_d_collect_location = location;
1343 if (cause==CAUSE_BUSY && p_m_d_collect_cause!=CAUSE_REJECTED && p_m_d_collect_cause!=CAUSE_NORMAL) /* busy */
1345 p_m_d_collect_cause = CAUSE_BUSY;
1346 p_m_d_collect_location = location;
1348 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 */
1350 p_m_d_collect_cause = CAUSE_OUTOFORDER;
1351 p_m_d_collect_location = location;
1353 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 */
1355 p_m_d_collect_cause = cause;
1356 p_m_d_collect_location = location;
1358 add_trace("new-cause", "location", "%d", p_m_d_collect_location);
1359 add_trace("new-cause", "value", "%d", p_m_d_collect_cause);
1363 /* CC_RELEASE INDICATION */
1364 void Pdss1::release_ind(unsigned long prim, unsigned long dinfo, void *data)
1366 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1367 RELEASE_t *release = (RELEASE_t *)((unsigned long)data + headerlen);
1369 int location, cause;
1370 struct message *message;
1372 l1l2l3_trace_header(prim, DIRECTION_IN);
1373 dec_ie_cause(release->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1379 /* sending release to endpoint */
1382 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1383 message->param.disconnectinfo.cause = cause;
1384 message->param.disconnectinfo.location = location;
1385 message_put(message);
1387 free_epointlist(p_epointlist);
1390 /* only in NT mode we must send release_complete, if we got a release confirm */
1391 if (prim == (CC_RELEASE | CONFIRM))
1393 /* sending release complete */
1394 RELEASE_COMPLETE_t *release_complete;
1396 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
1397 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
1398 l1l2l3_trace_header(CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
1399 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16);
1401 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1404 new_state(PORT_STATE_RELEASE);
1408 /* CC_RELEASE_COMPLETE INDICATION */
1409 void Pdss1::release_complete_ind(unsigned long prim, unsigned long dinfo, void *data)
1411 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1412 RELEASE_COMPLETE_t *release_complete = (RELEASE_COMPLETE_t *)((unsigned long)data + headerlen);
1413 int location, cause;
1414 struct message *message;
1416 l1l2l3_trace_header(prim, DIRECTION_IN);
1417 dec_ie_cause(release_complete->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1423 /* sending release to endpoint */
1426 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1427 message->param.disconnectinfo.cause = cause;
1428 message->param.disconnectinfo.location = location;
1429 message_put(message);
1431 free_epointlist(p_epointlist);
1434 new_state(PORT_STATE_RELEASE);
1439 void Pdss1::t312_timeout(unsigned long prim, unsigned long dinfo, void *data)
1441 struct message *message;
1443 // trace is done at message_isdn()
1445 /* sending release to endpoint */
1448 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1449 message->param.disconnectinfo.cause = p_m_d_collect_cause;
1450 message->param.disconnectinfo.location = p_m_d_collect_location;
1451 message_put(message);
1453 free_epointlist(p_epointlist);
1456 new_state(PORT_STATE_RELEASE);
1460 /* CC_NOTIFY INDICATION */
1461 void Pdss1::notify_ind(unsigned long prim, unsigned long dinfo, void *data)
1463 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1464 NOTIFY_t *notifying = (NOTIFY_t *)((unsigned long)data + headerlen);
1465 struct message *message;
1466 int notify, type, plan, present;
1468 l1l2l3_trace_header(prim, DIRECTION_IN);
1469 dec_ie_notify(notifying->NOTIFY, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
1470 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));
1473 if (!ACTIVE_EPOINT(p_epointlist))
1475 /* notification indicator */
1479 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1480 message->param.notifyinfo.notify = notify;
1481 /* redirection number */
1485 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1488 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1491 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1497 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1498 message->param.notifyinfo.present = INFO_PRESENT_NULL;
1501 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1504 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1507 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1510 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1513 message->param.notifyinfo.isdn_port = p_m_portnum;
1514 message_put(message);
1518 /* CC_HOLD INDICATION */
1519 void Pdss1::hold_ind(unsigned long prim, unsigned long dinfo, void *data)
1521 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1522 // HOLD_t *hold = (HOLD_t *)((unsigned long)data + headerlen);
1523 struct message *message;
1524 HOLD_REJECT_t *hold_reject;
1525 HOLD_ACKNOWLEDGE_t *hold_acknowledge;
1527 // class Endpoint *epoint;
1529 l1l2l3_trace_header(prim, DIRECTION_IN);
1532 if (!ACTIVE_EPOINT(p_epointlist) || p_m_hold)
1534 dmsg = create_l3msg(CC_HOLD_REJECT | REQUEST, MT_HOLD_REJECT, dinfo, sizeof(HOLD_REJECT_t), p_m_d_ntmode);
1535 hold_reject = (HOLD_REJECT_t *)(dmsg->data + headerlen);
1536 l1l2l3_trace_header(CC_HOLD_REJECT | REQUEST, DIRECTION_OUT);
1537 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 */
1538 add_trace("reason", NULL, "no endpoint");
1540 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1545 /* notify the hold of call */
1546 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1547 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_HOLD;
1548 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1549 message_put(message);
1551 /* deactivate bchannel */
1552 chan_trace_header("CHANNEL RELEASE (hold)");
1553 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1556 prüfen, ob bei allen alloc_bchannel/free_bchannel ein trace erfolgt
1558 /* set hold state */
1561 epoint = find_epoint_id(ACTIVE_EPOINT(p_epointlist));
1562 if (epoint && p_m_d_ntmode)
1564 p_m_timeout = p_settings.tout_hold;
1569 /* acknowledge hold */
1570 dmsg = create_l3msg(CC_HOLD_ACKNOWLEDGE | REQUEST, MT_HOLD_ACKNOWLEDGE, dinfo, sizeof(HOLD_ACKNOWLEDGE_t), p_m_d_ntmode);
1571 hold_acknowledge = (HOLD_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1572 l1l2l3_trace_header(CC_HOLD_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1574 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1578 /* CC_RETRIEVE INDICATION */
1579 void Pdss1::retrieve_ind(unsigned long prim, unsigned long dinfo, void *data)
1581 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1582 RETRIEVE_t *retrieve = (RETRIEVE_t *)((unsigned long)data + headerlen);
1583 RETRIEVE_REJECT_t *retrieve_reject;
1584 RETRIEVE_ACKNOWLEDGE_t *retrieve_acknowledge;
1585 struct message *message;
1586 int channel, exclusive, cause;
1590 l1l2l3_trace_header(prim, DIRECTION_IN);
1591 dec_ie_channel_id(retrieve->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
1596 cause = 101; /* incompatible state */
1599 dmsg = create_l3msg(CC_RETRIEVE_REJECT | REQUEST, MT_RETRIEVE_REJECT, dinfo, sizeof(RETRIEVE_REJECT_t), p_m_d_ntmode);
1600 retrieve_reject = (RETRIEVE_REJECT_t *)(dmsg->data + headerlen);
1601 l1l2l3_trace_header(CC_RETRIEVE_REJECT | REQUEST, DIRECTION_OUT);
1602 enc_ie_cause(&retrieve_reject->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, cause);
1604 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1609 /* notify the retrieve of call */
1610 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1611 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_RETRIEVAL;
1612 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1613 message_put(message);
1617 mach den channel-kram, wie beim setup
1628 chan_trace_header("CHANNEL RELEASE (retrieve)");
1631 alle channels richtig convertieren
1633 channel = -1; /* any channel */
1634 if (channel == ANY_CHANNEL)
1635 channel = -1; /* any channel */
1636 if (channel == CHANNEL_NO)
1637 add_trace("channel", "request", "no-channel");
1639 add_trace("channel", "request", (channel>0)?"%d%s":"any", channel, exclusive?" (forced)":"");
1641 if (channel==CHANNEL_NO && (p_type==PORT_TYPE_DSS1_TE_IN||p_type==PORT_TYPE_DSS1_TE_OUT))
1643 add_trace("conclusion", NULL, "incoming call-waiting not supported for TE-mode");
1649 ret = alloc_bchannel(channel, exclusive);
1652 PDEBUG(DEBUG_BCHANNEL, "- channel is not available (cause=%d), so we send a retrieve_reject.\n", -ret);
1672 /* set hold state */
1676 /* acknowledge retrieve */
1677 dmsg = create_l3msg(CC_RETRIEVE_ACKNOWLEDGE | REQUEST, MT_RETRIEVE_ACKNOWLEDGE, dinfo, sizeof(RETRIEVE_ACKNOWLEDGE_t), p_m_d_ntmode);
1678 retrieve_acknowledge = (RETRIEVE_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1679 l1l2l3_trace_header(CC_RETRIEVE_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1680 enc_ie_channel_id(&retrieve_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
1682 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1685 /* CC_SUSPEND INDICATION */
1686 void Pdss1::suspend_ind(unsigned long prim, unsigned long dinfo, void *data)
1688 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1689 SUSPEND_t *suspend = (SUSPEND_t *)((unsigned long)data + headerlen);
1690 SUSPEND_ACKNOWLEDGE_t *suspend_acknowledge;
1691 SUSPEND_REJECT_t *suspend_reject;
1692 struct message *message;
1693 class Endpoint *epoint;
1694 unsigned char callid[8];
1697 int ret = -31; /* normal, unspecified */
1699 l1l2l3_trace_header(prim, DIRECTION_IN);
1700 dec_ie_call_id(suspend->CALL_ID, (Q931_info_t *)((unsigned long)data+headerlen), callid, &len);
1703 if (!ACTIVE_EPOINT(p_epointlist))
1706 dmsg = create_l3msg(CC_SUSPEND_REJECT | REQUEST, MT_SUSPEND_REJECT, dinfo, sizeof(SUSPEND_REJECT_t), p_m_d_ntmode);
1707 suspend_reject = (SUSPEND_REJECT_t *)(dmsg->data + headerlen);
1708 l1l2l3_trace_header(CC_SUSPEND_REJECT | REQUEST, DIRECTION_OUT);
1709 enc_ie_cause(&suspend_reject->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1711 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1719 /* check if call id is in use */
1720 epoint = epoint_first;
1723 if (epoint->ep_park)
1725 if (epoint->ep_park_len == len)
1726 if (!memcmp(epoint->ep_park_callid, callid, len))
1728 ret = -84; /* call id in use */
1732 epoint = epoint->next;
1735 /* notify the hold of call */
1736 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1737 message->param.notifyinfo.notify = INFO_NOTIFY_USER_SUSPENDED;
1738 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1739 message_put(message);
1741 /* deactivate bchannel */
1742 chan_trace_header("CHANNEL RELEASE (suspend)");
1743 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1747 /* sending suspend to endpoint */
1748 while (p_epointlist)
1750 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_SUSPEND);
1751 memcpy(message->param.parkinfo.callid, callid, sizeof(message->param.parkinfo.callid));
1752 message->param.parkinfo.len = len;
1753 message_put(message);
1755 free_epointlist(p_epointlist);
1758 /* sending SUSPEND_ACKNOWLEDGE */
1759 dmsg = create_l3msg(CC_SUSPEND_ACKNOWLEDGE | REQUEST, MT_SUSPEND_ACKNOWLEDGE, dinfo, sizeof(SUSPEND_ACKNOWLEDGE_t), p_m_d_ntmode);
1760 suspend_acknowledge = (SUSPEND_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1761 l1l2l3_trace_header(CC_SUSPEND_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1763 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1765 new_state(PORT_STATE_RELEASE);
1769 /* CC_RESUME INDICATION */
1770 void Pdss1::resume_ind(unsigned long prim, unsigned long dinfo, void *data)
1772 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1773 RESUME_t *resume = (RESUME_t *)((unsigned long)data + headerlen);
1774 RESUME_REJECT_t *resume_reject;
1775 RESUME_ACKNOWLEDGE_t *resume_acknowledge;
1776 unsigned char callid[8];
1778 int channel, exclusive;
1780 class Endpoint *epoint;
1781 struct message *message;
1784 /* callref from nt-lib */
1787 /* nt-library now gives us the id via CC_RESUME */
1788 if (dinfo&(~0xff) == 0xff00)
1790 PERROR("fatal software error: l3-stack gives us a process id 0xff00-0xffff\n");
1793 l1l2l3_trace_header(CC_NEW_CR | INDICATION, DIRECTION_IN);
1795 add_trace("callref", "old", "0x%x", p_m_d_l3id);
1796 add_trace("callref", "new", "0x%x", dinfo);
1798 if (p_m_d_l3id&(~0xff) == 0xff00)
1799 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
1801 p_m_d_ces = setup->ces;
1804 l1l2l3_trace_header(prim, DIRECTION_IN);
1805 dec_ie_call_id(resume->CALL_ID, (Q931_info_t *)((unsigned long)data+headerlen), callid, &len);
1808 /* if blocked, release call */
1809 if (p_m_mISDNport->ifport->block)
1811 RELEASE_COMPLETE_t *release_complete;
1813 printlog("--- port#%d is blocked.\n", mISDNport->ifport->portnum);
1823 channel = -1; /* any channel */
1826 ret = hunt_bchannel(channel, exclusive);
1830 dmsg = create_l3msg(CC_RESUME_REJECT | REQUEST, MT_RESUME_REJECT, dinfo, sizeof(RESUME_REJECT_t), p_m_d_ntmode);
1831 resume_reject = (RESUME_REJECT_t *)(dmsg->data + headerlen);
1832 l1l2l3_trace_header(CC_RESUME_REJECT | REQUEST, DIRECTION_OUT);
1833 enc_ie_cause(&resume_reject->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1835 add_trace("reason", NULL, "port blocked");
1837 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1838 new_state(PORT_STATE_RELEASE);
1843 /* create endpoint */
1846 PERROR("SOFTWARE ERROR: incoming resume but already got an endpoint, exitting...\n");
1849 ret = -85; /* no call suspended */
1850 epoint = epoint_first;
1853 if (epoint->ep_park)
1855 ret = -83; /* suspended call exists, but this not */
1856 if (epoint->ep_park_len == len)
1857 if (!memcmp(epoint->ep_park_callid, callid, len))
1860 epoint = epoint->next;
1865 if (!(epointlist_new(epoint->ep_serial)))
1867 PERROR("no memory for epointlist\n");
1870 if (!(epoint->portlist_new(p_serial, p_type, p_m_mISDNport->is_earlyb)))
1872 PERROR("no memory for portlist\n");
1875 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RESUME);
1876 message_put(message);
1878 /* notify the resume of call */
1879 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1880 message->param.notifyinfo.notify = INFO_NOTIFY_USER_RESUMED;
1881 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1882 message_put(message);
1884 /* sending RESUME_ACKNOWLEDGE */
1885 dmsg = create_l3msg(CC_RESUME_ACKNOWLEDGE | REQUEST, MT_RESUME_ACKNOWLEDGE, dinfo, sizeof(RESUME_ACKNOWLEDGE_t), p_m_d_ntmode);
1886 resume_acknowledge = (RESUME_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1887 l1l2l3_trace_header(CC_RESUME_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1888 enc_ie_channel_id(&resume_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
1890 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1892 new_state(PORT_STATE_CONNECT);
1896 /* CC_FACILITY INDICATION */
1897 void Pdss1::facility_ind(unsigned long prim, unsigned long dinfo, void *data)
1899 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1900 FACILITY_t *facility = (FACILITY_t *)((unsigned long)data + headerlen);
1901 unsigned char facil[256];
1903 struct message *message;
1905 l1l2l3_trace_header(prim, DIRECTION_IN);
1906 dec_ie_facility(facility->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), facil, &facil_len);
1913 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_FACILITY);
1914 message->param.facilityinfo.len = facil_len;
1915 memcpy(message->param.facilityinfo.data, facil, facil_len);
1916 message_put(message);
1921 * handler for isdn connections
1922 * incoming information are parsed and sent via message to the endpoint
1924 void Pdss1::message_isdn(unsigned long prim, unsigned long dinfo, void *data)
1932 case CC_TIMEOUT | INDICATION:
1933 l1l2l3_trace_header(prim, DIRECTION_IN);
1936 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1937 timer_hex = *((int *)(((char *)data)+headerlen));
1940 add_trace("timer", NULL, "%x", timer_hex);
1942 if (timer_hex==0x312 && p_m_d_ntmode)
1943 t312_timeout(prim, dinfo, data);
1946 case CC_SETUP | INDICATION:
1947 if (p_state != PORT_STATE_IDLE)
1949 setup_ind(prim, dinfo, data);
1952 case CC_SETUP | CONFIRM:
1955 l1l2l3_trace_header(CC_NEW_CR | INDICATION, DIRECTION_IN);
1956 add_trace("callref", "old", "0x%x", p_m_d_l3id);
1957 /* nt-library now gives us a new id via CC_SETUP_CONFIRM */
1958 if ((p_m_d_l3id&0xff00) != 0xff00)
1959 PERROR(" strange setup-procid 0x%x\n", p_m_d_l3id);
1960 p_m_d_l3id = *((int *)(((u_char *)data)+ mISDNUSER_HEAD_SIZE));
1961 add_trace("callref", "new", "0x%x", p_m_d_l3id);
1967 case CC_INFORMATION | INDICATION:
1968 information_ind(prim, dinfo, data);
1971 case CC_SETUP_ACKNOWLEDGE | INDICATION:
1972 if (p_state != PORT_STATE_OUT_SETUP)
1974 PERROR("Pdss1(%s) received setup_acknowledge, but we are not in outgoing setup state, IGNORING.\n", p_name);
1977 setup_acknowledge_ind(prim, dinfo, data);
1980 case CC_PROCEEDING | INDICATION:
1981 if (p_state != PORT_STATE_OUT_SETUP
1982 && p_state != PORT_STATE_OUT_OVERLAP)
1984 PERROR("Pdss1(%s) received proceeding, but we are not in outgoing setup OR overlap state, IGNORING.\n", p_name);
1987 proceeding_ind(prim, dinfo, data);
1990 case CC_ALERTING | INDICATION:
1991 if (p_state != PORT_STATE_OUT_SETUP
1992 && p_state != PORT_STATE_OUT_OVERLAP
1993 && p_state != PORT_STATE_OUT_PROCEEDING)
1995 PERROR("Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding state, IGNORING.\n", p_name);
1998 alerting_ind(prim, dinfo, data);
2001 case CC_CONNECT | INDICATION:
2002 if (p_state != PORT_STATE_OUT_SETUP
2003 && p_state != PORT_STATE_OUT_OVERLAP
2004 && p_state != PORT_STATE_OUT_PROCEEDING
2005 && p_state != PORT_STATE_OUT_ALERTING)
2007 PERROR("Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding OR ALERTING state, IGNORING.\n", p_name);
2010 connect_ind(prim, dinfo, data);
2011 if (p_m_d_notify_pending)
2013 /* send pending notify message during connect */
2014 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2015 message_free(p_m_d_notify_pending);
2016 p_m_d_notify_pending = NULL;
2020 case CC_CONNECT_ACKNOWLEDGE | INDICATION:
2021 case CC_CONNECT | CONFIRM:
2022 if (p_state == PORT_STATE_CONNECT_WAITING)
2023 new_state(PORT_STATE_CONNECT);
2024 if (p_m_d_notify_pending)
2026 /* send pending notify message during connect-ack */
2027 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2028 message_free(p_m_d_notify_pending);
2029 p_m_d_notify_pending = NULL;
2033 case CC_DISCONNECT | INDICATION:
2034 disconnect_ind(prim, dinfo, data);
2037 case CC_RELEASE | CONFIRM:
2038 case CC_RELEASE | INDICATION:
2039 release_ind(prim, dinfo, data);
2042 case CC_RELEASE_COMPLETE | INDICATION:
2043 release_complete_ind(prim, dinfo, data);
2046 case CC_RELEASE_COMPLETE | CONFIRM:
2049 case CC_NOTIFY | INDICATION:
2050 notify_ind(prim, dinfo, data);
2053 case CC_HOLD | INDICATION:
2054 hold_ind(prim, dinfo, data);
2057 case CC_RETRIEVE | INDICATION:
2058 retrieve_ind(prim, dinfo, data);
2061 case CC_SUSPEND | INDICATION:
2062 suspend_ind(prim, dinfo, data);
2065 case CC_RESUME | INDICATION:
2066 resume_ind(prim, dinfo, data);
2069 case CC_FACILITY | INDICATION:
2070 facility_ind(prim, dinfo, data);
2073 case CC_RELEASE_CR | INDICATION:
2074 l1l2l3_trace_header(CC_RELEASE_CR | INDICATION, DIRECTION_IN);
2075 add_trace("callref", NULL, "0x%x", p_m_d_l3id);
2079 if ((p_m_d_l3id&0xff00) == 0xff00)
2080 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
2084 /* sending release to endpoint in case we still have an endpoint
2085 * NOTE: this only happens if the stack releases due to layer1
2086 * or layer2 breakdown. otherwhise a release is received first.
2090 struct message *message;
2091 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
2092 message->param.disconnectinfo.cause = (p_m_d_collect_cause!=CAUSE_NOUSER)?p_m_d_collect_cause:CAUSE_UNSPECIFIED;
2093 message->param.disconnectinfo.location = (p_m_d_collect_cause!=CAUSE_NOUSER)?p_m_d_collect_location:LOCATION_PRIVATE_LOCAL;
2094 message_put(message);
2096 free_epointlist(p_epointlist);
2098 new_state(PORT_STATE_RELEASE);
2102 case CC_NEW_CR | INDICATION:
2103 l1l2l3_trace_header(prim, DIRECTION_IN);
2105 add_trace("callref", "old", "0x%x", p_m_d_l3id);
2108 new_l3id = *((int *)(((u_char *)data+mISDNUSER_HEAD_SIZE)));
2109 if (((new_l3id&0xff00)!=0xff00) && ((p_m_d_l3id&0xff00)==0xff00))
2110 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
2115 p_m_d_l3id = new_l3id;
2116 add_trace("callref", "new", "0x%x", p_m_d_l3id);
2121 l1l2l3_trace_header(prim, DIRECTION_IN);
2122 add_trace("unhandled", "prim", "0x%x", prim);
2127 void Pdss1::new_state(int state)
2129 class Endpoint *epoint;
2132 epoint = find_epoint_id(ACTIVE_EPOINT(p_epointlist));
2133 if (epoint && p_m_d_ntmode)
2135 if (state == PORT_STATE_IN_OVERLAP)
2137 p_m_timeout = p_settings.tout_dialing;
2140 if (state != p_state)
2142 if (state == PORT_STATE_IN_SETUP
2143 || state == PORT_STATE_IN_OVERLAP)
2145 p_m_timeout = p_settings.tout_setup;
2148 if (state == PORT_STATE_IN_PROCEEDING
2149 || state == PORT_STATE_OUT_PROCEEDING)
2151 p_m_timeout = p_settings.tout_proceeding;
2154 if (state == PORT_STATE_IN_ALERTING
2155 || state == PORT_STATE_OUT_ALERTING)
2157 p_m_timeout = p_settings.tout_alerting;
2160 if (state == PORT_STATE_CONNECT
2161 || state == PORT_STATE_CONNECT_WAITING)
2165 if (state == PORT_STATE_IN_DISCONNECT
2166 || state == PORT_STATE_OUT_DISCONNECT)
2168 p_m_timeout = p_settings.tout_disconnect;
2174 Port::new_state(state);
2181 int Pdss1::handler(void)
2185 if ((ret = Port::handler()))
2188 /* handle destruction */
2189 if (p_m_delete && p_m_d_l3id==0)
2200 * handles all messages from endpoint
2202 /* MESSAGE_INFORMATION */
2203 void Pdss1::message_information(unsigned long epoint_id, int message_id, union parameter *param)
2205 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2206 INFORMATION_t *information;
2209 if (param->information.number[0]) /* only if we have something to dial */
2211 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2212 l1l2l3_trace_header(CC_INFORMATION | REQUEST, DIRECTION_OUT);
2213 information = (INFORMATION_t *)(dmsg->data + headerlen);
2214 enc_ie_called_pn(&information->CALLED_PN, dmsg, 0, 1, (unsigned char *)param->information.number);
2216 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2225 void Pdss1::message_setup(unsigned long epoint_id, int message_id, union parameter *param)
2227 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2228 INFORMATION_t *information;
2231 int plan, type, screen, present, reason;
2232 int capability, mode, rate, coding, user, presentation, interpretation, hlc, exthlc;
2233 int channel, exclusive;
2235 struct epoint_list *epointlist;
2237 /* release if port is blocked */
2238 if (p_m_mISDNport->ifport->block)
2240 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2241 message->param.disconnectinfo.cause = 27; // temp. unavail.
2242 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2243 message_put(message);
2244 new_state(PORT_STATE_RELEASE);
2249 /* copy setup infos to port */
2250 memcpy(&p_callerinfo, ¶m->setup.callerinfo, sizeof(p_callerinfo));
2251 memcpy(&p_dialinginfo, ¶m->setup.dialinginfo, sizeof(p_dialinginfo));
2252 memcpy(&p_capainfo, ¶m->setup.capainfo, sizeof(p_capainfo));
2253 memcpy(&p_redirinfo, ¶m->setup.redirinfo, sizeof(p_redirinfo));
2254 // SCPY(&p_m_tones_dir, param->setup.ext.tones_dir);
2256 /* only display at connect state: this case happens if endpoint is in connected mode */
2257 if (p_state==PORT_STATE_CONNECT)
2259 if (p_type!=PORT_TYPE_DSS1_NT_OUT
2260 && p_type!=PORT_TYPE_DSS1_NT_IN)
2262 if (p_callerinfo.display[0])
2264 /* sending information */
2265 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2266 information = (INFORMATION_t *)(dmsg->data + headerlen);
2267 l1l2l3_trace_header(CC_INFORMATION | REQUEST, DIRECTION_OUT);
2269 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_callerinfo.display);
2271 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2276 /* attach only if not already */
2277 epointlist = p_epointlist;
2280 if (epointlist->epoint_id == epoint_id)
2282 epointlist = epointlist->next;
2286 if (!(epointlist_new(epoint_id)))
2288 PERROR("no memory for epointlist\n");
2297 channel = p_m_b_channel;
2298 exclusive = p_m_b_exclusive;
2300 channel = CHANNEL_ANY;
2301 /* nt-port with no channel, not reserverd */
2302 if (!p_m_b_channel && !p_m_b_reserve && p_type==PORT_TYPE_DSS1_NT_OUT)
2303 channel = CHANNEL_NO;
2306 l1l2l3_trace_header(CC_NEW_CR | REQUEST, DIRECTION_OUT);
2312 if (p_m_mISDNport->procids[i] == 0)
2318 struct message *message;
2320 add_trace("callref", NULL, "no free id");
2322 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2323 message->param.disconnectinfo.cause = 47;
2324 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2325 message_put(message);
2326 new_state(PORT_STATE_RELEASE);
2330 p_m_mISDNport->procids[i] = 1;
2331 p_m_d_l3id = 0xff00 | i;
2335 /* if we are in te-mode, we need to create a process first */
2336 if (newteid++ > 0x7fff)
2338 p_m_d_l3id = (entity<<16) | newteid;
2339 /* preparing message */
2340 ncr.prim = CC_NEW_CR | REQUEST;
2341 ncr.addr = p_m_mISDNport->upper_id | FLG_MSG_DOWN;
2342 ncr.dinfo = p_m_d_l3id;
2345 mISDN_write(mISDNdevice, &ncr, mISDN_HEADER_LEN+ncr.len, TIMEOUT_1SEC);
2349 add_trace("callref", "new", "0x%x", p_m_d_l3id);
2352 /* preparing setup message */
2353 dmsg = create_l3msg(CC_SETUP | REQUEST, MT_SETUP, p_m_d_l3id, sizeof(SETUP_t), p_m_d_ntmode);
2354 l1l2l3_trace_header(CC_SETUP | REQUEST, DIRECTION_OUT);
2355 setup = (SETUP_t *)(dmsg->data + headerlen);
2356 /* channel information */
2357 if (channel >= 0) /* it should */
2359 enc_ie_channel_id(&setup->CHANNEL_ID, dmsg, exclusive, channel);
2361 /* caller information */
2363 switch (p_callerinfo.ntype)
2365 case INFO_NTYPE_INTERNATIONAL:
2368 case INFO_NTYPE_NATIONAL:
2371 case INFO_NTYPE_SUBSCRIBER:
2374 default: /* INFO_NTYPE_UNKNOWN */
2378 switch (p_callerinfo.screen)
2380 case INFO_SCREEN_USER:
2383 default: /* INFO_SCREEN_NETWORK */
2387 switch (p_callerinfo.present)
2389 case INFO_PRESENT_RESTRICTED:
2392 case INFO_PRESENT_NOTAVAIL:
2395 default: /* INFO_PRESENT_ALLOWED */
2400 enc_ie_calling_pn(&setup->CALLING_PN, dmsg, type, plan, present, screen, (unsigned char *)p_callerinfo.id);
2401 /* dialing information */
2402 if (p_dialinginfo.number[0]) /* only if we have something to dial */
2404 enc_ie_called_pn(&setup->CALLED_PN, dmsg, 0, 1, (unsigned char *)p_dialinginfo.number);
2406 /* sending complete */
2407 if (p_dialinginfo.sending_complete)
2408 enc_ie_complete(&setup->COMPLETE, dmsg, 1);
2409 /* sending user-user */
2410 if (param->setup.useruser.len)
2412 enc_ie_useruser(&setup->USER_USER, dmsg, param->setup.useruser.protocol, param->setup.useruser.data, param->setup.useruser.len);
2414 /* redirecting number */
2416 switch (p_redirinfo.ntype)
2418 case INFO_NTYPE_INTERNATIONAL:
2421 case INFO_NTYPE_NATIONAL:
2424 case INFO_NTYPE_SUBSCRIBER:
2427 default: /* INFO_NTYPE_UNKNOWN */
2431 switch (p_redirinfo.screen)
2433 case INFO_SCREEN_USER:
2436 default: /* INFO_SCREE_NETWORK */
2440 switch (p_redirinfo.reason)
2442 case INFO_REDIR_BUSY:
2445 case INFO_REDIR_NORESPONSE:
2448 case INFO_REDIR_UNCONDITIONAL:
2451 case INFO_REDIR_CALLDEFLECT:
2454 case INFO_REDIR_OUTOFORDER:
2457 default: /* INFO_REDIR_UNKNOWN */
2461 switch (p_redirinfo.present)
2463 case INFO_PRESENT_NULL: /* no redir at all */
2470 case INFO_PRESENT_RESTRICTED:
2473 case INFO_PRESENT_NOTAVAIL:
2476 default: /* INFO_PRESENT_ALLOWED */
2480 /* sending redirecting number only in ntmode */
2481 if (type >= 0 && p_m_d_ntmode)
2482 enc_ie_redir_nr(&setup->REDIR_NR, dmsg, type, plan, present, screen, reason, (unsigned char *)p_redirinfo.id);
2483 /* bearer capability */
2484 //printf("hlc=%d\n",p_capainfo.hlc);
2486 capability = p_capainfo.bearer_capa;
2487 mode = p_capainfo.bearer_mode;
2488 rate = (mode==INFO_BMODE_CIRCUIT)?0x10:0x00;
2489 switch (p_capainfo.bearer_info1)
2491 case INFO_INFO1_NONE:
2495 user = p_capainfo.bearer_info1 & 0x7f;
2498 enc_ie_bearer(&setup->BEARER, dmsg, coding, capability, mode, rate, -1, user);
2505 hlc = p_capainfo.hlc & 0x7f;
2507 if (p_capainfo.exthlc)
2508 exthlc = p_capainfo.exthlc & 0x7f;
2509 enc_ie_hlc(&setup->HLC, dmsg, coding, interpretation, presentation, hlc, exthlc);
2513 if (p_callerinfo.display[0] && p_m_d_ntmode)
2514 enc_ie_display(&setup->DISPLAY, dmsg, (unsigned char *)p_callerinfo.display);
2516 /* nt-mode: CNIP (calling name identification presentation) */
2517 if (p_callerinfo.name[0] && p_m_d_ntmode)
2518 enc_facility_centrex(&setup->FACILITY, dmsg, (unsigned char *)p_callerinfo.name, 1);
2522 /* send setup message now */
2523 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2525 new_state(PORT_STATE_OUT_SETUP);
2528 /* MESSAGE_FACILITY */
2529 void Pdss1::message_facility(unsigned long epoint_id, int message_id, union parameter *param)
2531 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2532 FACILITY_t *facility;
2535 /* facility will not be sent to external lines */
2539 /* sending facility */
2540 dmsg = create_l3msg(CC_FACILITY | REQUEST, MT_FACILITY, p_m_d_l3id, sizeof(FACILITY_t), p_m_d_ntmode);
2541 facility = (FACILITY_t *)(dmsg->data + headerlen);
2542 l1l2l3_trace_header(CC_FACILITY | REQUEST, DIRECTION_OUT);
2543 enc_ie_facility(&facility->FACILITY, dmsg, (unsigned char *)param->facilityinfo.data, param->facilityinfo.len);
2545 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2548 /* MESSAGE_NOTIFY */
2549 void Pdss1::message_notify(unsigned long epoint_id, int message_id, union parameter *param)
2551 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2552 INFORMATION_t *information;
2553 NOTIFY_t *notification;
2555 int plan, type = -1, present;
2558 if (param->notifyinfo.notify>INFO_NOTIFY_NONE)
2559 notify = param->notifyinfo.notify & 0x7f;
2562 if (p_state != PORT_STATE_CONNECT)
2564 /* notify only allowed in active state */
2570 switch (param->notifyinfo.ntype)
2572 case INFO_NTYPE_INTERNATIONAL:
2575 case INFO_NTYPE_NATIONAL:
2578 case INFO_NTYPE_SUBSCRIBER:
2581 default: /* INFO_NTYPE_UNKNOWN */
2585 switch (param->notifyinfo.present)
2587 case INFO_PRESENT_NULL: /* no redir at all */
2592 case INFO_PRESENT_RESTRICTED:
2595 case INFO_PRESENT_NOTAVAIL:
2598 default: /* INFO_PRESENT_ALLOWED */
2604 if (notify<0 && !param->notifyinfo.display[0])
2606 /* nothing to notify, nothing to display */
2612 if (p_state!=PORT_STATE_CONNECT)
2614 /* queue notification */
2615 if (p_m_d_notify_pending)
2616 message_free(p_m_d_notify_pending);
2617 p_m_d_notify_pending = message_create(ACTIVE_EPOINT(p_epointlist), p_serial, EPOINT_TO_PORT, message_id);
2618 memcpy(&p_m_d_notify_pending->param, param, sizeof(union parameter));
2621 /* sending notification */
2622 dmsg = create_l3msg(CC_NOTIFY | REQUEST, MT_NOTIFY, p_m_d_l3id, sizeof(NOTIFY_t), p_m_d_ntmode);
2623 notification = (NOTIFY_t *)(dmsg->data + headerlen);
2624 l1l2l3_trace_header(CC_NOTIFY | REQUEST, DIRECTION_OUT);
2625 enc_ie_notify(¬ification->NOTIFY, dmsg, notify);
2626 /* sending redirection number only in ntmode */
2627 if (type >= 0 && p_m_d_ntmode)
2628 enc_ie_redir_dn(¬ification->REDIR_DN, dmsg, type, plan, present, (unsigned char *)param->notifyinfo.id);
2629 if (param->notifyinfo.display[0] && p_m_d_ntmode)
2630 enc_ie_display(¬ification->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display);
2632 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2634 } else if (p_m_d_ntmode)
2636 /* sending information */
2637 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2638 information = (INFORMATION_t *)(dmsg->data + headerlen);
2639 l1l2l3_trace_header(CC_INFORMATION | REQUEST, DIRECTION_OUT);
2640 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display);
2642 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2646 /* MESSAGE_OVERLAP */
2647 void Pdss1::message_overlap(unsigned long epoint_id, int message_id, union parameter *param)
2649 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2650 SETUP_ACKNOWLEDGE_t *setup_acknowledge;
2653 /* sending setup_acknowledge */
2654 dmsg = create_l3msg(CC_SETUP_ACKNOWLEDGE | REQUEST, MT_SETUP_ACKNOWLEDGE, p_m_d_l3id, sizeof(SETUP_ACKNOWLEDGE_t), p_m_d_ntmode);
2655 setup_acknowledge = (SETUP_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
2656 l1l2l3_trace_header(CC_SETUP_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
2657 /* channel information */
2658 if (p_state == PORT_STATE_IN_SETUP)
2659 enc_ie_channel_id(&setup_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2660 /* progress information */
2661 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2662 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2663 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2664 if (p_m_mISDNport->is_tones)
2665 enc_ie_progress(&setup_acknowledge->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2667 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2669 new_state(PORT_STATE_IN_OVERLAP);
2672 /* MESSAGE_PROCEEDING */
2673 void Pdss1::message_proceeding(unsigned long epoint_id, int message_id, union parameter *param)
2675 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2676 CALL_PROCEEDING_t *proceeding;
2679 /* sending proceeding */
2680 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2681 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2682 l1l2l3_trace_header(CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2683 /* channel information */
2684 if (p_state == PORT_STATE_IN_SETUP)
2685 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2686 /* progress information */
2687 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2688 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2689 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2690 if (p_m_mISDNport->is_tones)
2691 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2693 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2695 new_state(PORT_STATE_IN_PROCEEDING);
2698 /* MESSAGE_ALERTING */
2699 void Pdss1::message_alerting(unsigned long epoint_id, int message_id, union parameter *param)
2701 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2702 ALERTING_t *alerting;
2705 /* NT-MODE in setup state we must send PROCEEDING first */
2706 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2708 CALL_PROCEEDING_t *proceeding;
2710 /* sending proceeding */
2711 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2712 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2713 l1l2l3_trace_header(CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2714 /* channel information */
2715 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2716 /* progress information */
2717 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2718 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2719 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2720 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2722 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2723 new_state(PORT_STATE_IN_PROCEEDING);
2726 /* sending alerting */
2727 dmsg = create_l3msg(CC_ALERTING | REQUEST, MT_ALERTING, p_m_d_l3id, sizeof(ALERTING_t), p_m_d_ntmode);
2728 alerting = (ALERTING_t *)(dmsg->data + headerlen);
2729 l1l2l3_trace_header(CC_ALERTING | REQUEST, DIRECTION_OUT);
2730 /* channel information */
2731 if (p_state == PORT_STATE_IN_SETUP)
2732 enc_ie_channel_id(&alerting->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2733 /* progress information */
2734 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2735 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2736 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2737 if (p_m_mISDNport->is_tones)
2738 enc_ie_progress(&alerting->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2740 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2742 new_state(PORT_STATE_IN_ALERTING);
2745 /* MESSAGE_CONNECT */
2746 void Pdss1::message_connect(unsigned long epoint_id, int message_id, union parameter *param)
2748 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2749 INFORMATION_t *information;
2751 int type, plan, present, screen;
2753 class Endpoint *epoint;
2755 /* NT-MODE in setup state we must send PROCEEDING first */
2756 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2758 CALL_PROCEEDING_t *proceeding;
2760 /* sending proceeding */
2761 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2762 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2763 l1l2l3_trace_header(CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2764 /* channel information */
2765 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2766 // /* progress information */
2767 // if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2768 // || p_capainfo.bearer_capa==INFO_BC_AUDIO
2769 // || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_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);
2773 new_state(PORT_STATE_IN_PROCEEDING);
2776 /* copy connected information */
2777 memcpy(&p_connectinfo, ¶m->connectinfo, sizeof(p_connectinfo));
2779 /* only display at connect state */
2780 if (p_state == PORT_STATE_CONNECT)
2781 if (p_connectinfo.display[0])
2783 /* sending information */
2784 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2785 information = (INFORMATION_t *)(dmsg->data + headerlen);
2786 l1l2l3_trace_header(CC_INFORMATION | REQUEST, DIRECTION_OUT);
2788 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_connectinfo.display);
2790 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2794 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)
2796 /* connect command only possible in setup, proceeding or alerting state */
2800 /* preparing connect message */
2801 dmsg = create_l3msg(CC_CONNECT | REQUEST, MT_CONNECT, p_m_d_l3id, sizeof(CONNECT_t), p_m_d_ntmode);
2802 connect = (CONNECT_t *)(dmsg->data + headerlen);
2803 l1l2l3_trace_header(CC_CONNECT | REQUEST, DIRECTION_OUT);
2804 /* connect information */
2806 switch (p_connectinfo.ntype)
2808 case INFO_NTYPE_INTERNATIONAL:
2811 case INFO_NTYPE_NATIONAL:
2814 case INFO_NTYPE_SUBSCRIBER:
2817 default: /* INFO_NTYPE_UNKNOWN */
2821 switch (param->connectinfo.screen)
2823 case INFO_SCREEN_USER:
2826 default: /* INFO_SCREE_NETWORK */
2830 switch (p_connectinfo.present)
2832 case INFO_PRESENT_NULL: /* no colp at all */
2838 case INFO_PRESENT_RESTRICTED:
2841 case INFO_PRESENT_NOTAVAIL:
2844 default: /* INFO_PRESENT_ALLOWED */
2849 enc_ie_connected_pn(&connect->CONNECT_PN, dmsg, type, plan, present, screen, (unsigned char *)p_connectinfo.id);
2851 if (p_connectinfo.display[0] && p_m_d_ntmode)
2852 enc_ie_display(&connect->DISPLAY, dmsg, (unsigned char *)p_connectinfo.display);
2854 /* nt-mode: CONP (connected name identification presentation) */
2855 if (p_connectinfo.name[0] && p_m_d_ntmode)
2856 enc_facility_centrex(&connect->FACILITY, dmsg, (unsigned char *)p_connectinfo.name, 0);
2861 epoint = find_epoint_id(epoint_id);
2862 enc_ie_date(&connect->DATE, dmsg, now, p_settings.no_seconds);
2865 /* finally send message */
2866 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2869 new_state(PORT_STATE_CONNECT);
2871 new_state(PORT_STATE_CONNECT_WAITING);
2875 /* MESSAGE_DISCONNECT */
2876 void Pdss1::message_disconnect(unsigned long epoint_id, int message_id, union parameter *param)
2878 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2879 DISCONNECT_t *disconnect;
2880 RELEASE_COMPLETE_t *release_complete;
2882 struct message *message;
2885 /* we reject during incoming setup when we have no tones. also if we are in outgoing setup state */
2886 if ((p_state==PORT_STATE_IN_SETUP && !p_m_mISDNport->is_tones)
2887 || p_state==PORT_STATE_OUT_SETUP)
2889 /* sending release to endpoint */
2892 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
2893 message->param.disconnectinfo.cause = 16;
2894 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2895 message_put(message);
2897 free_epointlist(p_epointlist);
2899 /* sending release */
2900 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
2901 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
2902 l1l2l3_trace_header(CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
2904 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);
2906 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2907 new_state(PORT_STATE_RELEASE);
2912 /* NT-MODE in setup state we must send PROCEEDING first */
2913 if (p_state==PORT_STATE_IN_SETUP)
2915 CALL_PROCEEDING_t *proceeding;
2917 /* sending proceeding */
2918 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2919 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2920 l1l2l3_trace_header(CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2921 /* channel information */
2922 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2923 /* progress information */
2924 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2925 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2926 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2927 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2929 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2930 new_state(PORT_STATE_IN_PROCEEDING);
2933 /* sending disconnect */
2934 dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode);
2935 disconnect = (DISCONNECT_t *)(dmsg->data + headerlen);
2936 l1l2l3_trace_header(CC_DISCONNECT | REQUEST, DIRECTION_OUT);
2937 /* progress information */
2938 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2939 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2940 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2941 if (p_m_mISDNport->is_tones)
2942 enc_ie_progress(&disconnect->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2944 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);
2946 if (param->disconnectinfo.display[0])
2947 p = param->disconnectinfo.display;
2948 if (p) if (*p && p_m_d_ntmode)
2949 enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p);
2951 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2952 new_state(PORT_STATE_OUT_DISCONNECT);
2955 /* MESSAGE_RELEASE */
2956 void Pdss1::message_release(unsigned long epoint_id, int message_id, union parameter *param)
2958 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2960 RELEASE_COMPLETE_t *release_complete;
2961 DISCONNECT_t *disconnect;
2963 class Endpoint *epoint;
2966 /* if we have incoming disconnected, we may release */
2967 if (p_state==PORT_STATE_IN_DISCONNECT
2968 || p_state==PORT_STATE_OUT_DISCONNECT)
2970 /* sending release */
2971 dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, p_m_d_l3id, sizeof(RELEASE_t), p_m_d_ntmode);
2972 release = (RELEASE_t *)(dmsg->data + headerlen);
2973 l1l2l3_trace_header(CC_RELEASE | REQUEST, DIRECTION_OUT);
2975 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);
2977 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2978 new_state(PORT_STATE_RELEASE);
2981 free_epointid(epoint_id);
2982 l1l2l3_trace_header(CC_RELEASE_CR | REQUEST, DIRECTION_OUT);
2983 add_trace("callref", "new", "0x%x", p_m_d_l3id);
2987 if ((p_m_d_l3id&0xff00) == 0xff00)
2988 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
2994 /* if we are on outgoing/incoming call setup, we may release complete */
2995 if (p_state==PORT_STATE_OUT_SETUP
2996 || p_state==PORT_STATE_IN_SETUP
2997 // NOTE: a bug in mISDNuser (see disconnect_req_out !!!)
2998 || p_state==PORT_STATE_OUT_PROCEEDING)
3000 /* sending release */
3001 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
3002 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
3003 l1l2l3_trace_header(CC_RELEASE | REQUEST, DIRECTION_OUT);
3005 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);
3007 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3008 new_state(PORT_STATE_RELEASE);
3009 goto remove_endpoint;
3012 /* NT-MODE in setup state we must send PROCEEDING first */
3013 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
3015 CALL_PROCEEDING_t *proceeding;
3017 /* sending proceeding */
3018 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
3019 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
3020 l1l2l3_trace_header(CC_PROCEEDING | REQUEST, DIRECTION_OUT);
3021 /* channel information */
3022 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
3023 /* progress information */
3024 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
3025 || p_capainfo.bearer_capa==INFO_BC_AUDIO
3026 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
3027 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
3029 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3032 /* sending disconnect */
3033 dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode);
3034 disconnect = (DISCONNECT_t *)(dmsg->data + headerlen);
3035 l1l2l3_trace_header(CC_DISCONNECT | REQUEST, DIRECTION_OUT);
3036 /* progress information */
3037 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
3038 || p_capainfo.bearer_capa==INFO_BC_AUDIO
3039 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
3040 if (p_m_mISDNport->is_tones)
3041 enc_ie_progress(&disconnect->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
3043 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);
3045 epoint = find_epoint_id(epoint_id);
3046 if (param->disconnectinfo.display[0])
3047 p = param->disconnectinfo.display;
3048 if (p) if (*p && p_m_d_ntmode)
3049 enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p);
3051 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3052 new_state(PORT_STATE_RELEASE);
3053 free_epointid(epoint_id);
3059 * endpoint sends messages to the port
3061 int Pdss1::message_epoint(unsigned long epoint_id, int message_id, union parameter *param)
3063 struct message *message;
3065 if (PmISDN::message_epoint(epoint_id, message_id, param))
3070 case MESSAGE_INFORMATION: /* overlap dialing */
3071 if (p_type==PORT_TYPE_DSS1_NT_OUT
3072 && p_state!=PORT_STATE_OUT_OVERLAP
3073 && p_state!=PORT_STATE_CONNECT
3074 && p_state!=PORT_STATE_OUT_DISCONNECT
3075 && p_state!=PORT_STATE_IN_DISCONNECT)
3079 if (p_type==PORT_TYPE_DSS1_TE_OUT
3080 && p_state!=PORT_STATE_OUT_OVERLAP
3081 && p_state!=PORT_STATE_OUT_PROCEEDING
3082 && p_state!=PORT_STATE_OUT_ALERTING
3083 && p_state!=PORT_STATE_CONNECT
3084 && p_state!=PORT_STATE_OUT_DISCONNECT
3085 && p_state!=PORT_STATE_IN_DISCONNECT)
3089 if ((p_type==PORT_TYPE_DSS1_NT_IN || p_type==PORT_TYPE_DSS1_TE_IN)
3090 && p_state!=PORT_STATE_IN_OVERLAP
3091 && p_state!=PORT_STATE_IN_PROCEEDING
3092 && p_state!=PORT_STATE_IN_ALERTING
3093 && p_state!=PORT_STATE_CONNECT
3094 && p_state!=PORT_STATE_CONNECT_WAITING
3095 && p_state!=PORT_STATE_OUT_DISCONNECT
3096 && p_state!=PORT_STATE_IN_DISCONNECT)
3100 message_information(epoint_id, message_id, param);
3103 case MESSAGE_SETUP: /* dial-out command received from epoint */
3104 if (p_state!=PORT_STATE_IDLE
3105 && p_state!=PORT_STATE_CONNECT)
3107 PERROR("Pdss1(%s) ignoring setup because isdn port is not in idle state (or connected for sending display info).\n", p_name);
3110 if (p_epointlist && p_state==PORT_STATE_IDLE)
3112 PERROR("Pdss1(%s): software error: epoint pointer is set in idle state, how bad!! exitting.\n", p_name);
3115 /* note: pri is a special case, because links must be up for pri */
3116 if (p_m_mISDNport->l1link || p_m_mISDNport->pri || !p_m_mISDNport->ntmode || p_state!=PORT_STATE_IDLE)
3118 /* LAYER 1 is up, or we may send */
3119 message_setup(epoint_id, message_id, param);
3122 /* LAYER 1 id down, so we queue */
3123 p_m_d_queue = message_create(epoint_id, p_serial, EPOINT_TO_PORT, message_id);
3124 memcpy(&p_m_d_queue->param, param, sizeof(union parameter));
3126 if (!(epointlist_new(epoint_id)))
3128 PERROR("no memory for epointlist\n");
3132 PDEBUG(DEBUG_ISDN, "the L1 is down, we try to establish the link NT portnum=%d (%s).\n", p_m_mISDNport->portnum, p_name);
3133 act.prim = PH_ACTIVATE | REQUEST;
3134 act.addr = p_m_mISDNport->upper_id | FLG_MSG_DOWN;
3137 mISDN_write(mISDNdevice, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
3138 l1l2l3_trace_header(act.prim, DIRECTION_OUT);
3140 // /* set timeout */
3141 // p_m_mISDNport->l1timeout = now+3;
3145 case MESSAGE_NOTIFY: /* display and notifications */
3146 message_notify(epoint_id, message_id, param);
3149 case MESSAGE_FACILITY: /* facility message */
3150 message_facility(epoint_id, message_id, param);
3153 case MESSAGE_OVERLAP: /* more information is needed */
3154 if (p_state!=PORT_STATE_IN_SETUP)
3158 message_overlap(epoint_id, message_id, param);
3161 case MESSAGE_PROCEEDING: /* call of endpoint is proceeding */
3162 if (p_state!=PORT_STATE_IN_SETUP
3163 && p_state!=PORT_STATE_IN_OVERLAP)
3167 message_proceeding(epoint_id, message_id, param);
3170 case MESSAGE_ALERTING: /* call of endpoint is ringing */
3171 if (p_state!=PORT_STATE_IN_SETUP
3172 && p_state!=PORT_STATE_IN_OVERLAP
3173 && p_state!=PORT_STATE_IN_PROCEEDING)
3177 message_alerting(epoint_id, message_id, param);
3180 case MESSAGE_CONNECT: /* call of endpoint is connected */
3181 if (p_state!=PORT_STATE_IN_SETUP
3182 && p_state!=PORT_STATE_IN_OVERLAP
3183 && p_state!=PORT_STATE_IN_PROCEEDING
3184 && p_state!=PORT_STATE_IN_ALERTING
3185 && !(p_state==PORT_STATE_CONNECT && p_m_d_ntmode))
3189 message_connect(epoint_id, message_id, param);
3192 case MESSAGE_DISCONNECT: /* call has been disconnected */
3193 if (p_state!=PORT_STATE_IN_SETUP
3194 && p_state!=PORT_STATE_IN_OVERLAP
3195 && p_state!=PORT_STATE_IN_PROCEEDING
3196 && p_state!=PORT_STATE_IN_ALERTING
3197 && p_state!=PORT_STATE_OUT_SETUP
3198 && p_state!=PORT_STATE_OUT_OVERLAP
3199 && p_state!=PORT_STATE_OUT_PROCEEDING
3200 && p_state!=PORT_STATE_OUT_ALERTING
3201 && p_state!=PORT_STATE_CONNECT
3202 && p_state!=PORT_STATE_CONNECT_WAITING)
3206 message_disconnect(epoint_id, message_id, param);
3209 case MESSAGE_RELEASE: /* release isdn port */
3210 if (p_state==PORT_STATE_RELEASE)
3214 message_release(epoint_id, message_id, param);
3218 PERROR("Pdss1(%s) isdn port with (caller id %s) received a wrong message: %d\n", p_name, p_callerinfo.id, message);
3227 * data from isdn-stack (layer-3) to pbx (port class)
3229 /* NOTE: nt mode use mISDNuser_head_t as header */
3230 int stack2manager_nt(void *dat, void *arg)
3234 manager_t *mgr = (manager_t *)dat;
3235 msg_t *msg = (msg_t *)arg;
3236 mISDNuser_head_t *hh;
3237 struct mISDNport *mISDNport;
3243 /* note: nst is the first data feld of mISDNport */
3244 mISDNport = (struct mISDNport *)mgr->nst;
3246 hh = (mISDNuser_head_t *)msg->data;
3247 PDEBUG(DEBUG_ISDN, "prim(0x%x) dinfo(0x%x) msg->len(%d)\n", hh->prim, hh->dinfo, msg->len);
3249 /* find Port object of type ISDN */
3253 if (port->p_type == PORT_TYPE_DSS1_NT_IN || port->p_type == PORT_TYPE_DSS1_NT_OUT)
3255 pdss1 = (class Pdss1 *)port;
3256 //PDEBUG(DEBUG_ISDN, "comparing dinfo = 0x%x with l3id 0x%x\n", hh->dinfo, pdss1->p_m_d_l3id);
3257 /* check out correct stack */
3258 if (pdss1->p_m_mISDNport == mISDNport)
3259 /* check out correct id */
3260 if ((hh->dinfo&0xffff0000) == (pdss1->p_m_d_l3id&0xffff0000))
3262 /* found port, the message belongs to */
3270 /* if process id is master process, but a child disconnects */
3271 if ((hh->dinfo&0x0000ff00)!=0x0000ff00 && (pdss1->p_m_d_l3id&0x0000ff00)==0x0000ff00 && hh->prim==(CC_DISCONNECT|INDICATION))
3273 /* send special indication for child disconnect */
3274 pdss1->disconnect_ind_i(hh->prim, hh->dinfo, msg->data);
3278 /* if process id and layer 3 id matches */
3279 if (hh->dinfo == pdss1->p_m_d_l3id)
3281 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
3290 case MGR_SHORTSTATUS | INDICATION:
3291 case MGR_SHORTSTATUS | CONFIRM:
3293 case SSTATUS_L2_ESTABLISHED:
3295 case SSTATUS_L2_RELEASED:
3300 case DL_ESTABLISH | INDICATION:
3301 case DL_ESTABLISH | CONFIRM:
3303 l1l2l3_trace_header(prim, DIRECTION_IN);
3304 add_trace("tei", NULL, "%d", hh->dinfo);
3306 if (mISDNport->ptp && hh->dinfo == 0)
3308 if (mISDNport->l2establish)
3310 mISDNport->l2establish = 0;
3311 PDEBUG(DEBUG_ISDN, "the link became active before l2establish timer expiry.\n");
3313 mISDNport->l2link = 1;
3314 if (mISDNport->pri);
3315 mISDNport->l1link = 1; /* this is a hack, we also assume L1 to be active */
3319 case DL_RELEASE | INDICATION:
3320 case DL_RELEASE | CONFIRM:
3322 l1l2l3_trace_header(prim, DIRECTION_IN);
3323 add_trace("tei", NULL, "%d", hh->dinfo);
3325 if (mISDNport->ptp && hh->dinfo == 0)
3327 mISDNport->l2link = 0;
3328 time(&mISDNport->l2establish);
3329 PDEBUG(DEBUG_ISDN, "because we are ptp, we set a l2establish timer.\n");
3333 case CC_SETUP | INDICATION:
3334 /* creating port object */
3335 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3336 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0)))
3338 RELEASE_COMPLETE_t *release_complete;
3341 PERROR("FATAL ERROR: cannot create port object.\n");
3342 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, hh->dinfo, sizeof(RELEASE_COMPLETE_t), mISDNport->ntmode);
3343 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + mISDN_HEADER_LEN);
3344 enc_ie_cause_standalone(mISDNport->ntmode?&release_complete->CAUSE:NULL, dmsg, (mISDNport->ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47);
3345 msg_queue_tail(&mISDNport->downqueue, dmsg);
3348 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
3351 case CC_RESUME | INDICATION:
3352 /* creating port object */
3353 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3354 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL)))
3356 SUSPEND_REJECT_t *suspend_reject;
3359 PERROR("FATAL ERROR: cannot create port object.\n");
3360 dmsg = create_l3msg(CC_SUSPEND_REJECT | REQUEST, MT_SUSPEND_REJECT, hh->dinfo, sizeof(SUSPEND_REJECT_t), mISDNport->ntmode);
3361 suspend_reject = (SUSPEND_REJECT_t *)(dmsg->data + mISDN_HEADER_LEN);
3362 enc_ie_cause_standalone(mISDNport->ntmode?&suspend_reject->CAUSE:NULL, dmsg, (mISDNport->ntmode)?1:0, 47);
3363 msg_queue_tail(&mISDNport->downqueue, dmsg);
3366 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
3369 case CC_RELEASE_CR | INDICATION:
3370 PERROR("unhandled message from stack: call ref released (l3id=0x%x)\n", hh->dinfo);
3373 case CC_DISCONNECT | INDICATION:
3377 PERROR("unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", hh->prim, hh->dinfo, msg->len);
3384 /* NOTE: te mode use iframe_t as header */
3385 int stack2manager_te(struct mISDNport *mISDNport, msg_t *msg)
3392 if (!msg || !mISDNport)
3394 frm = (iframe_t *)msg->data;
3395 PDEBUG(DEBUG_ISDN, "prim(0x%x) dinfo(0x%x) msg->len(%d)\n", frm->prim, frm->dinfo, msg->len);
3397 /* find Port object of type ISDN */
3401 if (port->p_type == PORT_TYPE_DSS1_TE_IN || port->p_type == PORT_TYPE_DSS1_TE_OUT)
3403 pdss1 = (class Pdss1 *)port;
3404 /* check out correct stack */
3405 if (pdss1->p_m_mISDNport == mISDNport)
3406 /* check out correct id */
3407 if (frm->dinfo == pdss1->p_m_d_l3id)
3409 /* found port, the message belongs to */
3417 pdss1->message_isdn(frm->prim, frm->dinfo, msg->data);
3422 /* process new cr (before setup indication) */
3423 //printf("prim = 0x%x, looking for 0x%x\n",frm->prim, (CC_NEW_CR | INDICATION));
3424 if (frm->prim == (CC_NEW_CR | 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_TE_IN, mISDNport, name, NULL)))
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, frm->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);
3442 /* l3id will be set from dinfo at message_isdn */
3443 pdss1->message_isdn(frm->prim, frm->dinfo, msg->data);
3448 if (frm->prim == (CC_RELEASE_CR | INDICATION))
3450 PERROR("unhandled message from stack: call ref released (l3id=0x%x)\n", frm->dinfo);
3454 PERROR("unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", frm->prim, frm->dinfo, msg->len);
3460 * sending message that were queued during L1 activation
3461 * or releasing port if link is down
3463 void setup_queue(struct mISDNport *mISDNport, int link)
3467 struct message *message;
3469 if (!mISDNport->ntmode)
3472 /* check all port objects for pending message */
3476 if ((port->p_type&PORT_CLASS_mISDN_MASK) == PORT_CLASS_mISDN_DSS1)
3478 pdss1 = (class Pdss1 *)port;
3479 if (pdss1->p_m_mISDNport == mISDNport)
3481 if (pdss1->p_m_d_queue)
3485 PDEBUG(DEBUG_ISDN, "the L1 became active, so we send queued message for portnum=%d (%s).\n", mISDNport->portnum, pdss1->p_name);
3486 /* LAYER 1 is up, so we send */
3487 pdss1->message_setup(pdss1->p_m_d_queue->id_from, pdss1->p_m_d_queue->type, &pdss1->p_m_d_queue->param);
3488 message_free(pdss1->p_m_d_queue);
3489 pdss1->p_m_d_queue = NULL;
3492 PDEBUG(DEBUG_ISDN, "the L1 became NOT active, so we release port for portnum=%d (%s).\n", mISDNport->portnum, pdss1->p_name);
3493 message = message_create(pdss1->p_serial, pdss1->p_m_d_queue->id_from, PORT_TO_EPOINT, MESSAGE_RELEASE);
3494 message->param.disconnectinfo.cause = 27;
3495 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
3496 message_put(message);
3497 pdss1->new_state(PORT_STATE_RELEASE);
3498 pdss1->p_m_delete = 1;