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},
179 static char *isdn_prim[4] = {
190 void Pdss1::l3_trace_header(unsigned long prim, int direction_out)
193 char msgtext[64] = "<<UNKNOWN MESSAGE>>";
195 /* select message and primitive text */
197 while(isdn_message[i].name)
199 if (isdn_message[i].value == (prim&0xffffff00))
201 SCPY(msgtext, isdn_message[i].name);
206 SCAT(msgtext, isdn_prim[prim&0x00000003]);
209 if (direction && (prim&0xffffff00)!=CC_NEW_CR && (prim&0xffffff00)!=CC_RELEASE_CR)
213 if (direction == DIRECTION_OUT)
214 SCAT(msgtext, " N->U");
216 SCAT(msgtext, " N<-U");
219 if (direction == DIRECTION_OUT)
220 SCAT(msgtext, " U->N");
222 SCAT(msgtext, " U<-N");
226 /* init trace with given values */
227 start_trace(p_m_mISDNport->portnum,
228 p_m_mISDNport->ifport->interface,
229 nationalize(p_callerinfo.id, p_callerinfo.ntype),
230 p_dialinginfo.number,
238 * if we received a first reply to the setup message,
239 * we will check if we have now channel information
240 * return: <0: error, call is released, -cause is given
241 * 0: ok, nothing to do
243 int Pdss1::received_first_reply_to_setup(unsigned long prim, int channel, int exclusive)
246 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
247 RELEASE_COMPLETE_t *release_complete;
250 /* correct exclusive to 0, if no explicit channel was given */
251 if (exclusive<0 || channel<=0)
254 /* select scenario */
255 if (p_m_b_channel && p_m_b_exclusive)
257 /*** we gave an exclusive channel (or if we are done) ***/
259 /* if not first reply, we are done */
260 if (p_state != PORT_STATE_OUT_SETUP)
263 start_trace(p_m_mISDNport->portnum,
264 p_m_mISDNport->ifport->interface,
265 nationalize(p_callerinfo.id, p_callerinfo.ntype),
266 p_dialinginfo.number,
269 "CHANNEL SELECTION (first reply to setup)");
270 add_trace("channel", "request", "%d (forced)", p_m_b_channel);
271 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
273 /* if give channel not accepted or not equal */
274 if (channel!=-1 && p_m_b_channel!=channel)
276 add_trace("conclusion", NULL, "forced channel not accepted");
282 add_trace("conclusion", NULL, "channel was accepted");
283 add_trace("connect", "channel", "%d", p_m_b_channel);
286 /* activate our exclusive channel */
287 bchannel_activate(p_m_mISDNport, p_m_b_index);
291 /*** we gave a non-exclusive channel ***/
293 /* if not first reply, we are done */
294 if (p_state != PORT_STATE_OUT_SETUP)
297 start_trace(p_m_mISDNport->portnum,
298 p_m_mISDNport->ifport->interface,
299 nationalize(p_callerinfo.id, p_callerinfo.ntype),
300 p_dialinginfo.number,
303 "CHANNEL SELECTION (first reply to setup)");
304 add_trace("channel", "request", "%d (suggest)", p_m_b_channel);
305 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
307 /* if channel was accepted as given */
308 if (channel==-1 || p_m_b_channel==channel)
310 add_trace("conclusion", NULL, "channel was accepted as given");
311 add_trace("connect", "channel", "%d", p_m_b_channel);
313 p_m_b_exclusive = 1; // we are done
314 bchannel_activate(p_m_mISDNport, p_m_b_index);
318 /* if channel value is faulty */
321 add_trace("conclusion", NULL, "illegal reply");
323 ret = -111; // protocol error
327 /* if channel was not accepted, try to get it */
328 ret = seize_bchannel(channel, 1); // exclusively
329 add_trace("channel", "available", ret<0?"no":"yes");
332 add_trace("conclusion", NULL, "replied channel not available");
336 add_trace("conclusion", NULL, "replied channel accepted");
337 add_trace("connect", "channel", "%d", p_m_b_channel);
340 /* activate channel given by remote */
341 bchannel_activate(p_m_mISDNport, p_m_b_index);
345 /*** we sent 'any channel acceptable' ***/
347 /* if not first reply, we are done */
348 if (p_state != PORT_STATE_OUT_SETUP)
351 start_trace(p_m_mISDNport->portnum,
352 p_m_mISDNport->ifport->interface,
353 nationalize(p_callerinfo.id, p_callerinfo.ntype),
354 p_dialinginfo.number,
357 "CHANNEL SELECTION (first reply to setup)");
358 add_trace("channel", "request", "any");
359 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
360 /* if no channel was replied */
363 add_trace("conclusion", NULL, "no channel, protocol error");
365 ret = -111; // protocol error
369 /* we will see, if our received channel is available */
370 ret = seize_bchannel(channel, 1); // exclusively
371 add_trace("channel", "available", ret<0?"no":"yes");
374 add_trace("conclusion", NULL, "replied channel not available");
378 add_trace("conclusion", NULL, "replied channel accepted");
379 add_trace("connect", "channel", "%d", p_m_b_channel);
382 /* activate channel given by remote */
383 bchannel_activate(p_m_mISDNport, p_m_b_index);
386 /*** we sent 'no channel available' ***/
388 /* if not the first reply, but a connect, we are forced */
389 if (prim==(CC_CONNECT | INDICATION) && p_state!=PORT_STATE_OUT_SETUP)
391 start_trace(p_m_mISDNport->portnum,
392 p_m_mISDNport->ifport->interface,
393 nationalize(p_callerinfo.id, p_callerinfo.ntype),
394 p_dialinginfo.number,
397 "CHANNEL SELECTION (connect)");
398 add_trace("channel", "request", "no-channel");
399 add_trace("channel", "reply", (channel>=0)?"%d%s":"(none)", channel, exclusive?" (forced)":"");
402 goto use_from_connect;
404 ret = seize_bchannel(CHANNEL_ANY, 0); // any channel
405 add_trace("channel", "available", ret<0?"no":"yes");
408 add_trace("conclusion", NULL, "no channel available during call-waiting");
412 add_trace("conclusion", NULL, "using channel %d", p_m_b_channel);
413 add_trace("connect", "channel", "%d", p_m_b_channel);
415 p_m_b_exclusive = 1; // we are done
417 /* activate channel given by remote */
418 bchannel_activate(p_m_mISDNport, p_m_b_index);
422 /* if not first reply, we are done */
423 if (p_state != PORT_STATE_OUT_SETUP)
426 start_trace(p_m_mISDNport->portnum,
427 p_m_mISDNport->ifport->interface,
428 nationalize(p_callerinfo.id, p_callerinfo.ntype),
429 p_dialinginfo.number,
432 "CHANNEL SELECTION (first reply to setup)");
433 add_trace("channel", "request", "no-channel");
434 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
435 /* if first reply has no channel, we are done */
438 add_trace("conclusion", NULL, "no channel until connect");
443 /* we will see, if our received channel is available */
445 ret = seize_bchannel(channel, exclusive);
446 add_trace("channel", "available", ret<0?"no":"yes");
449 add_trace("conclusion", NULL, "replied channel not available");
453 add_trace("conclusion", NULL, "replied channel accepted");
454 add_trace("connect", "channel", "%d", p_m_b_channel);
456 p_m_b_exclusive = 1; // we are done
458 /* activate channel given by remote */
459 bchannel_activate(p_m_mISDNport, p_m_b_index);
464 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
465 l3_trace_header(CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
467 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
468 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
470 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
471 new_state(PORT_STATE_RELEASE);
473 return(-34); /* to epoint: no channel available */
478 * handles all indications
480 /* CC_SETUP INDICATION */
481 void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
483 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
484 SETUP_t *setup = (SETUP_t *)((unsigned long)data + headerlen);
485 int type, plan, present, screen, reason;
486 int coding, capability, mode, rate, multi, user, presentation, interpretation, hlc, exthlc;
487 int exclusive, channel;
490 unsigned char keypad[32] = "";
491 unsigned char useruser[128];
492 int useruser_len = 0, useruser_protocol;
493 class Endpoint *epoint;
494 struct message *message;
496 /* callref from nt-lib */
499 /* nt-library now gives us the id via CC_SETUP */
500 if (dinfo&(~0xff) == 0xff00)
502 PERROR("fatal software error: l3-stack gives us a process id 0xff00-0xffff\n");
505 l3_trace_header(CC_NEW_CR | INDICATION, DIRECTION_IN);
507 add_trace("callref", "old", "0x%x", p_m_d_l3id);
508 add_trace("callref", "new", "0x%x", dinfo);
510 if (p_m_d_l3id&(~0xff) == 0xff00)
511 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
513 p_m_d_ces = setup->ces;
516 l3_trace_header(prim, DIRECTION_IN);
517 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));
518 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));
519 dec_ie_keypad(setup->KEYPAD, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)keypad, sizeof(keypad));
521 /* te-mode: CNIP (calling name identification presentation) */
523 dec_facility_centrex(setup->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)p_callerinfo.name, sizeof(p_callerinfo.name));
525 dec_ie_useruser(setup->USER_USER, (Q931_info_t *)((unsigned long)data+headerlen), &useruser_protocol, useruser, &useruser_len);
526 dec_ie_complete(setup->COMPLETE, (Q931_info_t *)((unsigned long)data+headerlen), &p_dialinginfo.sending_complete);
527 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));
528 dec_ie_channel_id(setup->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
529 dec_ie_hlc(setup->HLC, (Q931_info_t *)((unsigned long)data+headerlen), &hlc_coding, &interpretation, &presentation, &hlc, &exthlc);
530 dec_ie_bearer(setup->BEARER, (Q931_info_t *)((unsigned long)data+headerlen), &bearer_coding, &capability, &mode, &rate, &multi, &user);
533 /* if blocked, release call */
534 if (p_m_mISDNport->ifport->block)
536 RELEASE_COMPLETE_t *release_complete;
538 printlog("--- port#%d is blocked.\n", mISDNport->ifport->portnum);
539 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
540 l3_trace_header(CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
541 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
542 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 27); /* temporary unavailable */
543 add_trace("reason", NULL, "port blocked");
545 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
546 new_state(PORT_STATE_RELEASE);
555 p_callerinfo.present = INFO_PRESENT_RESTRICTED;
558 p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
561 p_callerinfo.present = INFO_PRESENT_ALLOWED;
567 p_callerinfo.screen = INFO_SCREEN_USER;
570 p_callerinfo.screen = INFO_SCREEN_NETWORK;
576 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
577 p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
578 p_callerinfo.screen = INFO_SCREEN_NETWORK;
581 p_callerinfo.ntype = INFO_NTYPE_INTERNATIONAL;
584 p_callerinfo.ntype = INFO_NTYPE_NATIONAL;
587 p_callerinfo.ntype = INFO_NTYPE_SUBSCRIBER;
590 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
593 p_callerinfo.isdn_port = p_m_portnum;
594 SCPY(p_callerinfo.interface, p_m_mISDNport->ifport->interface->name);
596 /* dialing information */
597 SCAT(p_dialinginfo.number, (char *)keypad);
601 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
604 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
607 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
610 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
616 p_redirinfo.present = INFO_PRESENT_RESTRICTED;
619 p_redirinfo.present = INFO_PRESENT_NOTAVAIL;
622 p_redirinfo.present = INFO_PRESENT_ALLOWED;
628 p_redirinfo.screen = INFO_SCREEN_USER;
631 p_redirinfo.screen = INFO_SCREEN_NETWORK;
637 p_redirinfo.reason = INFO_REDIR_BUSY;
640 p_redirinfo.reason = INFO_REDIR_NORESPONSE;
643 p_redirinfo.reason = INFO_REDIR_UNCONDITIONAL;
646 p_redirinfo.reason = INFO_REDIR_CALLDEFLECT;
649 p_redirinfo.reason = INFO_REDIR_OUTOFORDER;
652 p_redirinfo.reason = INFO_REDIR_UNKNOWN;
658 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
659 p_redirinfo.present = INFO_PRESENT_NULL; /* not redirecting */
660 p_redirinfo.reason = INFO_REDIR_UNKNOWN;
663 p_redirinfo.ntype = INFO_NTYPE_INTERNATIONAL;
666 p_redirinfo.ntype = INFO_NTYPE_NATIONAL;
669 p_redirinfo.ntype = INFO_NTYPE_SUBSCRIBER;
672 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
675 p_redirinfo.isdn_port = p_m_portnum;
677 /* bearer capability */
681 p_capainfo.bearer_capa = INFO_BC_AUDIO;
682 user = (options.law=='a')?3:2;
685 p_capainfo.bearer_capa = capability;
691 p_capainfo.bearer_mode = INFO_BMODE_PACKET;
694 p_capainfo.bearer_mode = INFO_BMODE_CIRCUIT;
700 p_capainfo.bearer_info1 = INFO_INFO1_NONE;
703 p_capainfo.bearer_info1 = user + 0x80;
711 p_capainfo.hlc = INFO_HLC_NONE;
714 p_capainfo.hlc = hlc + 0x80;
720 p_capainfo.exthlc = INFO_HLC_NONE;
723 p_capainfo.exthlc = exthlc + 0x80;
727 /* process channel */
728 start_trace(p_m_mISDNport->portnum,
729 p_m_mISDNport->ifport->interface,
730 nationalize(p_callerinfo.id, p_callerinfo.ntype),
731 p_dialinginfo.number,
734 "CHANNEL SELECTION (setup)");
737 if (channel == CHANNEL_NO)
738 add_trace("channel", "request", "no-channel");
740 add_trace("channel", "request", (channel>0)?"%d%s":"any", channel, exclusive?" (forced)":"");
741 if (channel==CHANNEL_NO && p_type==PORT_TYPE_DSS1_TE_IN)
743 add_trace("conclusion", NULL, "incoming call-waiting not supported for TE-mode");
745 ret = -6; // channel unacceptable
748 if (channel <= 0) /* not given, no channel, whatever.. */
749 channel = CHANNEL_ANY; /* any channel */
750 if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num) // of out chan..
752 add_trace("channel", "reserved", "%d", p_m_mISDNport->b_reserved);
753 add_trace("conclusion", NULL, "all channels are reserved");
755 ret = -34; // no channel
758 if (channel == CHANNEL_ANY)
762 /* check for given channel in selection list */
763 selchannel = ifport->channel_in;
766 if (selchannel->channel == channel || selchannel->channel == CHANNEL_FREE)
768 selchannel = selchannel->next;
773 /* exclusive channel requests must be in the list */
778 add_trace("conclusion", NULL, "exclusively requested channel not in list");
780 ret = 6; // unacceptable
783 i = selchannel->channel-1-(selchannel->channel>=17);
784 if (mISDNport->b_port[i] == NULL)
786 add_trace("conclusion", NULL, "exclusively requested channel is busy");
788 ret = 6; // unacceptable
792 /* requested channels in list will be used */
795 i = selchannel->channel-1-(selchannel->channel>=17);
796 if (mISDNport->b_port[i] == NULL)
800 /* if channel is not available or not in list, it must be searched */
802 /* check for first free channel in list */
804 selchannel = ifport->channel_in;
807 switch(selchannel->channel)
809 case CHANNEL_FREE: /* free channel */
810 add_trace("hunting", "channel", "free");
811 if (mISDNport->b_inuse >= mISDNport->b_num)
812 break; /* all channel in use or reserverd */
815 while(i < mISDNport->b_num)
817 if (mISDNport->b_port[i] == NULL)
819 channel = i+1+(i>=15);
827 add_trace("hunting", "channel", "%d", selchannel->channel);
828 if (selchannel->channel<1 || selchannel->channel==16)
829 break; /* invalid channels */
830 i = selchannel->channel-1-(selchannel->channel>=17);
831 if (i >= mISDNport->b_num)
832 break; /* channel not in port */
833 if (mISDNport->b_port[i] == NULL)
835 channel = selchannel->channel;
841 break; /* found channel */
842 selchannel = selchannel->next;
846 add_trace("conclusion", NULL, "no channel available");
848 ret = 6; // unacceptable
855 ret = seize_bchannel(channel, 1);
858 add_trace("conclusion", NULL, "channel not available");
861 RELEASE_COMPLETE_t *release_complete;
863 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
864 l3_trace_header(CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
865 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
866 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
868 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
869 new_state(PORT_STATE_RELEASE);
873 add_trace("conclusion", NULL, "channel available");
874 add_trace("connect", "channel", "%d", p_m_b_channel);
876 bchannel_activate(p_m_mISDNport, p_m_b_index);
878 /* create endpoint */
881 PERROR("SOFTWARE ERROR: incoming call but already got an endpoint, exitting...\n");
884 if (!(epoint = new Endpoint(p_serial, 0)))
886 RELEASE_COMPLETE_t *release_complete;
888 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
889 l3_trace_header(CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
890 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
891 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 41); /* temporary failure */
893 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
894 new_state(PORT_STATE_RELEASE);
898 if (!(epoint->ep_app = new DEFAULT_ENDPOINT_APP(epoint)))
900 PERROR("no memory for application\n");
903 if (!(epointlist_new(epoint->ep_serial)))
905 PERROR("no memory for epointlist\n");
908 /* send setup message to endpoit */
909 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_SETUP);
910 message->param.setup.isdn_port = p_m_portnum;
911 message->param.setup.port_type = p_type;
912 memcpy(&message->param.setup.dialinginfo, &p_dialinginfo, sizeof(struct dialing_info));
913 memcpy(&message->param.setup.callerinfo, &p_callerinfo, sizeof(struct caller_info));
914 memcpy(&message->param.setup.redirinfo, &p_redirinfo, sizeof(struct redir_info));
915 memcpy(&message->param.setup.capainfo, &p_capainfo, sizeof(struct capa_info));
916 memcpy(message->param.setup.useruser.data, &useruser, useruser_len);
917 message->param.setup.useruser.len = useruser_len;
918 message->param.setup.useruser.protocol = useruser_protocol;
919 message_put(message);
921 new_state(PORT_STATE_IN_SETUP);
924 /* CC_INFORMATION INDICATION */
925 void Pdss1::information_ind(unsigned long prim, unsigned long dinfo, void *data)
927 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
928 INFORMATION_t *information = (INFORMATION_t *)((unsigned long)data + headerlen);
930 unsigned char keypad[32] = "";
931 struct message *message;
933 l3_trace_header(prim, DIRECTION_IN);
934 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));
935 dec_ie_keypad(information->KEYPAD, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)keypad, sizeof(keypad));
936 dec_ie_complete(information->COMPLETE, (Q931_info_t *)((unsigned long)data+headerlen), &p_dialinginfo.sending_complete);
939 SCAT(p_dialinginfo.number, (char *)keypad);
943 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
946 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
949 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
952 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
955 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_INFORMATION);
956 memcpy(&message->param.information, &p_dialinginfo, sizeof(struct dialing_info));
957 message_put(message);
958 /* reset overlap timeout */
962 /* CC_SETUP_ACCNOWLEDGE INDICATION */
963 void Pdss1::setup_acknowledge_ind(unsigned long prim, unsigned long dinfo, void *data)
965 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
966 SETUP_ACKNOWLEDGE_t *setup_acknowledge = (SETUP_ACKNOWLEDGE_t *)((unsigned long)data + headerlen);
967 int exclusive, channel;
968 int coding, location, progress;
970 struct message *message;
972 l3_trace_header(prim, DIRECTION_IN);
973 dec_ie_channel_id(setup_acknowledge->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
974 dec_ie_progress(setup_acknowledge->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
977 /* process channel */
978 ret = received_first_reply_to_setup(prim, exclusive, channel);
981 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
982 message->param.disconnectinfo.cause = -ret;
983 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
984 message_put(message);
985 new_state(PORT_STATE_RELEASE);
990 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_OVERLAP);
991 message_put(message);
993 new_state(PORT_STATE_OUT_OVERLAP);
996 /* CC_PROCEEDING INDICATION */
997 void Pdss1::proceeding_ind(unsigned long prim, unsigned long dinfo, void *data)
999 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1000 CALL_PROCEEDING_t *proceeding = (CALL_PROCEEDING_t *)((unsigned long)data + headerlen);
1001 int exclusive, channel;
1002 int coding, location, progress;
1004 struct message *message;
1005 int notify = -1, type, plan, present;
1008 l3_trace_header(prim, DIRECTION_IN);
1009 dec_ie_channel_id(proceeding->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
1010 dec_ie_progress(proceeding->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
1011 dec_ie_notify(NULL/*proceeding->NOTIFY*/, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
1012 dec_ie_redir_dn(proceeding->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
1015 ret = received_first_reply_to_setup(prim, exclusive, channel);
1018 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1019 message->param.disconnectinfo.cause = -ret;
1020 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1021 message_put(message);
1022 new_state(PORT_STATE_RELEASE);
1026 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROCEEDING);
1027 message_put(message);
1029 new_state(PORT_STATE_OUT_PROCEEDING);
1035 if (type >= 0 || notify)
1037 if (!notify && type >= 0)
1039 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1040 message->param.notifyinfo.notify = notify;
1041 SCPY(message->param.notifyinfo.id, redir);
1042 /* redirection number */
1046 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1049 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1052 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1058 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1059 message->param.notifyinfo.present = INFO_PRESENT_NULL;
1062 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1065 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1068 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1071 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1074 message->param.notifyinfo.isdn_port = p_m_portnum;
1075 message_put(message);
1079 /* CC_ALERTING INDICATION */
1080 void Pdss1::alerting_ind(unsigned long prim, unsigned long dinfo, void *data)
1082 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1083 ALERTING_t *alerting = (ALERTING_t *)((unsigned long)data + headerlen);
1084 int exclusive, channel;
1085 int coding, location, progress;
1087 struct message *message;
1088 int notify = -1, type, plan, present;
1091 l3_trace_header(prim, DIRECTION_IN);
1092 dec_ie_channel_id(alerting->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
1093 dec_ie_progress(alerting->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
1094 dec_ie_notify(NULL/*alerting->NOTIFY*/, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
1095 dec_ie_redir_dn(alerting->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
1098 /* process channel */
1099 ret = received_first_reply_to_setup(prim, exclusive, channel);
1102 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1103 message->param.disconnectinfo.cause = -ret;
1104 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1105 message_put(message);
1106 new_state(PORT_STATE_RELEASE);
1110 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_ALERTING);
1111 message_put(message);
1113 new_state(PORT_STATE_OUT_ALERTING);
1119 if (type >= 0 || notify)
1121 if (!notify && type >= 0)
1123 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1124 message->param.notifyinfo.notify = notify;
1125 SCPY(message->param.notifyinfo.id, redir);
1129 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1132 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1135 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1141 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1142 message->param.notifyinfo.present = INFO_PRESENT_NULL;
1145 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1148 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1151 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1154 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1157 message->param.notifyinfo.isdn_port = p_m_portnum;
1158 message_put(message);
1162 /* CC_CONNECT INDICATION */
1163 void Pdss1::connect_ind(unsigned long prim, unsigned long dinfo, void *data)
1165 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1166 CONNECT_t *connect = (CONNECT_t *)((unsigned long)data + headerlen);
1167 int exclusive, channel;
1168 int type, plan, present, screen;
1171 struct message *message;
1172 int bchannel_before;
1173 CONNECT_ACKNOWLEDGE_t *connect_acknowledge;
1176 p_m_d_ces = connect->ces;
1178 l3_trace_header(prim, DIRECTION_IN);
1179 dec_ie_channel_id(connect->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
1180 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));
1182 /* te-mode: CONP (connected name identification presentation) */
1184 dec_facility_centrex(connect->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)p_connectinfo.name, sizeof(p_connectinfo.name));
1188 /* select channel */
1189 bchannel_before = p_m_b_channel;
1190 ret = received_first_reply_to_setup(prim, exclusive, channel);
1193 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1194 message->param.disconnectinfo.cause = -ret;
1195 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1196 message_put(message);
1197 new_state(PORT_STATE_RELEASE);
1202 /* connect information */
1206 p_connectinfo.present = INFO_PRESENT_RESTRICTED;
1209 p_connectinfo.present = INFO_PRESENT_NOTAVAIL;
1212 p_connectinfo.present = INFO_PRESENT_ALLOWED;
1218 p_connectinfo.screen = INFO_SCREEN_USER;
1221 p_connectinfo.screen = INFO_SCREEN_NETWORK;
1227 p_connectinfo.present = INFO_PRESENT_NULL; /* no COLP info */
1228 p_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1231 p_connectinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1234 p_connectinfo.ntype = INFO_NTYPE_NATIONAL;
1237 p_connectinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1240 p_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1243 p_connectinfo.isdn_port = p_m_portnum;
1244 SCPY(p_connectingo.interface, p_m_mISDNport->ifport->interface->name);
1246 /* send connect acknowledge */
1247 dmsg = create_l3msg(CC_CONNECT | RESPONSE, MT_CONNECT, dinfo, sizeof(CONNECT_ACKNOWLEDGE_t), p_m_d_ntmode);
1248 l3_trace_header(CC_CONNECT | RESPONSE, DIRECTION_OUT);
1249 connect_acknowledge = (CONNECT_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1250 /* if we had no bchannel before, we send it now */
1251 if (!bchannel_before && p_m_b_channel)
1252 enc_ie_channel_id(&connect_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
1254 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1256 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CONNECT);
1257 memcpy(&message->param.connectinfo, &p_connectinfo, sizeof(struct connect_info));
1258 message_put(message);
1260 new_state(PORT_STATE_CONNECT);
1263 /* CC_DISCONNECT INDICATION */
1264 void Pdss1::disconnect_ind(unsigned long prim, unsigned long dinfo, void *data)
1266 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1267 DISCONNECT_t *disconnect = (DISCONNECT_t *)((unsigned long)data + headerlen);
1268 int location, cause;
1269 int coding, proglocation, progress;
1270 struct message *message;
1272 l3_trace_header(prim, DIRECTION_IN);
1273 dec_ie_progress(disconnect->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &proglocation, &progress);
1274 dec_ie_cause(disconnect->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1280 /* release if we are remote sends us no tones */
1281 if (p_m_mISDNport->is_earlyb)
1286 dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, dinfo, sizeof(RELEASE_t), p_m_d_ntmode);
1287 release = (RELEASE_t *)(dmsg->data + headerlen);
1288 l3_trace_header(CC_RELEASE | REQUEST, DIRECTION_OUT);
1289 enc_ie_cause(&release->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16); /* normal */
1290 add_trace("reason", NULL, "no remote patterns");
1292 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1294 /* sending release to endpoint */
1297 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1298 message->param.disconnectinfo.cause = cause;
1299 message->param.disconnectinfo.location = location;
1300 message_put(message);
1302 free_epointlist(p_epointlist);
1304 new_state(PORT_STATE_RELEASE);
1309 /* sending disconnect to active endpoint and release to inactive endpoints */
1310 if (ACTIVE_EPOINT(p_epointlist))
1312 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DISCONNECT);
1313 message->param.disconnectinfo.location = location;
1314 message->param.disconnectinfo.cause = cause;
1315 message_put(message);
1317 while(INACTIVE_EPOINT(p_epointlist))
1319 message = message_create(p_serial, INACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1320 message->param.disconnectinfo.location = location;
1321 message->param.disconnectinfo.cause = cause;
1322 message_put(message);
1324 free_epointid(INACTIVE_EPOINT(p_epointlist));
1326 new_state(PORT_STATE_IN_DISCONNECT);
1329 /* CC_DISCONNECT INDICATION */
1330 void Pdss1::disconnect_ind_i(unsigned long prim, unsigned long dinfo, void *data)
1332 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1333 DISCONNECT_t *disconnect = (DISCONNECT_t *)((unsigned long)data + headerlen);
1334 int location, cause;
1337 l3_trace_header(prim, DIRECTION_IN);
1338 if (p_m_d_collect_cause > 0)
1340 add_trace("old-cause", "location", "%d", p_m_d_collect_location);
1341 add_trace("old-cause", "value", "%d", p_m_d_collect_cause);
1343 dec_ie_cause(disconnect->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1347 if (cause == CAUSE_REJECTED) /* call rejected */
1349 p_m_d_collect_cause = CAUSE_REJECTED;
1350 p_m_d_collect_location = location;
1352 if (cause==CAUSE_NORMAL && p_m_d_collect_cause!=CAUSE_REJECTED) /* reject via hangup */
1354 p_m_d_collect_cause = CAUSE_NORMAL;
1355 p_m_d_collect_location = location;
1357 if (cause==CAUSE_BUSY && p_m_d_collect_cause!=CAUSE_REJECTED && p_m_d_collect_cause!=CAUSE_NORMAL) /* busy */
1359 p_m_d_collect_cause = CAUSE_BUSY;
1360 p_m_d_collect_location = location;
1362 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 */
1364 p_m_d_collect_cause = CAUSE_OUTOFORDER;
1365 p_m_d_collect_location = location;
1367 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 */
1369 p_m_d_collect_cause = cause;
1370 p_m_d_collect_location = location;
1372 add_trace("new-cause", "location", "%d", p_m_d_collect_location);
1373 add_trace("new-cause", "value", "%d", p_m_d_collect_cause);
1377 /* CC_RELEASE INDICATION */
1378 void Pdss1::release_ind(unsigned long prim, unsigned long dinfo, void *data)
1380 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1381 RELEASE_t *release = (RELEASE_t *)((unsigned long)data + headerlen);
1383 int location, cause;
1384 struct message *message;
1386 l3_trace_header(prim, DIRECTION_IN);
1387 dec_ie_cause(release->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1393 /* sending release to endpoint */
1396 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1397 message->param.disconnectinfo.cause = cause;
1398 message->param.disconnectinfo.location = location;
1399 message_put(message);
1401 free_epointlist(p_epointlist);
1404 /* only in NT mode we must send release_complete, if we got a release confirm */
1405 if (prim == (CC_RELEASE | CONFIRM))
1407 /* sending release complete */
1408 RELEASE_COMPLETE_t *release_complete;
1410 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
1411 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
1412 l3_trace_header(CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
1413 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16);
1415 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1418 new_state(PORT_STATE_RELEASE);
1422 /* CC_RELEASE_COMPLETE INDICATION */
1423 void Pdss1::release_complete_ind(unsigned long prim, unsigned long dinfo, void *data)
1425 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1426 RELEASE_COMPLETE_t *release_complete = (RELEASE_COMPLETE_t *)((unsigned long)data + headerlen);
1427 int location, cause;
1428 struct message *message;
1430 l3_trace_header(prim, DIRECTION_IN);
1431 dec_ie_cause(release_complete->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1437 /* sending release to endpoint */
1440 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1441 message->param.disconnectinfo.cause = cause;
1442 message->param.disconnectinfo.location = location;
1443 message_put(message);
1445 free_epointlist(p_epointlist);
1448 new_state(PORT_STATE_RELEASE);
1453 void Pdss1::t312_timeout(unsigned long prim, unsigned long dinfo, void *data)
1455 struct message *message;
1457 // trace is done at message_isdn()
1459 /* sending release to endpoint */
1462 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1463 message->param.disconnectinfo.cause = p_m_d_collect_cause;
1464 message->param.disconnectinfo.location = p_m_d_collect_location;
1465 message_put(message);
1467 free_epointlist(p_epointlist);
1470 new_state(PORT_STATE_RELEASE);
1474 /* CC_NOTIFY INDICATION */
1475 void Pdss1::notify_ind(unsigned long prim, unsigned long dinfo, void *data)
1477 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1478 NOTIFY_t *notifying = (NOTIFY_t *)((unsigned long)data + headerlen);
1479 struct message *message;
1480 int notify, type, plan, present;
1482 l3_trace_header(prim, DIRECTION_IN);
1483 dec_ie_notify(notifying->NOTIFY, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
1484 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));
1487 if (!ACTIVE_EPOINT(p_epointlist))
1489 /* notification indicator */
1493 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1494 message->param.notifyinfo.notify = notify;
1495 /* redirection number */
1499 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1502 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1505 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1511 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1512 message->param.notifyinfo.present = INFO_PRESENT_NULL;
1515 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1518 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1521 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1524 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1527 message->param.notifyinfo.isdn_port = p_m_portnum;
1528 message_put(message);
1532 /* CC_HOLD INDICATION */
1533 void Pdss1::hold_ind(unsigned long prim, unsigned long dinfo, void *data)
1535 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1536 // HOLD_t *hold = (HOLD_t *)((unsigned long)data + headerlen);
1537 struct message *message;
1538 HOLD_REJECT_t *hold_reject;
1539 HOLD_ACKNOWLEDGE_t *hold_acknowledge;
1541 // class Endpoint *epoint;
1543 l3_trace_header(prim, DIRECTION_IN);
1546 if (!ACTIVE_EPOINT(p_epointlist) || p_m_hold)
1548 dmsg = create_l3msg(CC_HOLD_REJECT | REQUEST, MT_HOLD_REJECT, dinfo, sizeof(HOLD_REJECT_t), p_m_d_ntmode);
1549 hold_reject = (HOLD_REJECT_t *)(dmsg->data + headerlen);
1550 l3_trace_header(CC_HOLD_REJECT | REQUEST, DIRECTION_OUT);
1551 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 */
1552 add_trace("reason", NULL, "no endpoint");
1554 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1559 /* notify the hold of call */
1560 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1561 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_HOLD;
1562 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1563 message_put(message);
1565 /* deactivate bchannel */
1566 start_trace(p_m_mISDNport->portnum,
1567 p_m_mISDNport->ifport->interface,
1568 nationalize(p_callerinfo.id, p_callerinfo.ntype),
1569 p_dialinginfo.number,
1572 "CHANNEL RELEASE (hold)");
1573 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1576 prüfen, ob bei allen alloc_bchannel/free_bchannel ein trace erfolgt
1578 /* set hold state */
1581 epoint = find_epoint_id(ACTIVE_EPOINT(p_epointlist));
1582 if (epoint && p_m_d_ntmode)
1584 p_m_timeout = p_settings.tout_hold;
1589 /* acknowledge hold */
1590 dmsg = create_l3msg(CC_HOLD_ACKNOWLEDGE | REQUEST, MT_HOLD_ACKNOWLEDGE, dinfo, sizeof(HOLD_ACKNOWLEDGE_t), p_m_d_ntmode);
1591 hold_acknowledge = (HOLD_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1592 l3_trace_header(CC_HOLD_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1594 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1598 /* CC_RETRIEVE INDICATION */
1599 void Pdss1::retrieve_ind(unsigned long prim, unsigned long dinfo, void *data)
1601 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1602 RETRIEVE_t *retrieve = (RETRIEVE_t *)((unsigned long)data + headerlen);
1603 RETRIEVE_REJECT_t *retrieve_reject;
1604 RETRIEVE_ACKNOWLEDGE_t *retrieve_acknowledge;
1605 struct message *message;
1606 int channel, exclusive, cause;
1610 l3_trace_header(prim, DIRECTION_IN);
1611 dec_ie_channel_id(retrieve->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
1616 cause = 101; /* incompatible state */
1619 dmsg = create_l3msg(CC_RETRIEVE_REJECT | REQUEST, MT_RETRIEVE_REJECT, dinfo, sizeof(RETRIEVE_REJECT_t), p_m_d_ntmode);
1620 retrieve_reject = (RETRIEVE_REJECT_t *)(dmsg->data + headerlen);
1621 l3_trace_header(CC_RETRIEVE_REJECT | REQUEST, DIRECTION_OUT);
1622 enc_ie_cause(&retrieve_reject->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, cause);
1624 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1629 /* notify the retrieve of call */
1630 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1631 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_RETRIEVAL;
1632 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1633 message_put(message);
1637 mach den channel-kram, wie beim setup
1648 start_trace(p_m_mISDNport->portnum,
1649 p_m_mISDNport->ifport->interface,
1650 nationalize(p_callerinfo.id, p_callerinfo.ntype),
1651 p_dialinginfo.number,
1654 "CHANNEL SELECTION (retrieve)");
1657 alle channels richtig convertieren
1659 channel = -1; /* any channel */
1660 if (channel == ANY_CHANNEL)
1661 channel = -1; /* any channel */
1662 if (channel == CHANNEL_NO)
1663 add_trace("channel", "request", "no-channel");
1665 add_trace("channel", "request", (channel>0)?"%d%s":"any", channel, exclusive?" (forced)":"");
1667 if (channel==CHANNEL_NO && (p_type==PORT_TYPE_DSS1_TE_IN||p_type==PORT_TYPE_DSS1_TE_OUT))
1669 add_trace("conclusion", NULL, "incoming call-waiting not supported for TE-mode");
1675 ret = alloc_bchannel(channel, exclusive);
1678 PDEBUG(DEBUG_BCHANNEL, "- channel is not available (cause=%d), so we send a retrieve_reject.\n", -ret);
1698 /* set hold state */
1702 /* acknowledge retrieve */
1703 dmsg = create_l3msg(CC_RETRIEVE_ACKNOWLEDGE | REQUEST, MT_RETRIEVE_ACKNOWLEDGE, dinfo, sizeof(RETRIEVE_ACKNOWLEDGE_t), p_m_d_ntmode);
1704 retrieve_acknowledge = (RETRIEVE_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1705 l3_trace_header(CC_RETRIEVE_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1706 enc_ie_channel_id(&retrieve_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
1708 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1711 /* CC_SUSPEND INDICATION */
1712 void Pdss1::suspend_ind(unsigned long prim, unsigned long dinfo, void *data)
1714 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1715 SUSPEND_t *suspend = (SUSPEND_t *)((unsigned long)data + headerlen);
1716 SUSPEND_ACKNOWLEDGE_t *suspend_acknowledge;
1717 SUSPEND_REJECT_t *suspend_reject;
1718 struct message *message;
1719 class Endpoint *epoint;
1720 unsigned char callid[8];
1723 int ret = -31; /* normal, unspecified */
1725 l3_trace_header(prim, DIRECTION_IN);
1726 dec_ie_call_id(suspend->CALL_ID, (Q931_info_t *)((unsigned long)data+headerlen), callid, &len);
1729 if (!ACTIVE_EPOINT(p_epointlist))
1732 dmsg = create_l3msg(CC_SUSPEND_REJECT | REQUEST, MT_SUSPEND_REJECT, dinfo, sizeof(SUSPEND_REJECT_t), p_m_d_ntmode);
1733 suspend_reject = (SUSPEND_REJECT_t *)(dmsg->data + headerlen);
1734 l3_trace_header(CC_SUSPEND_REJECT | REQUEST, DIRECTION_OUT);
1735 enc_ie_cause(&suspend_reject->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1737 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1745 /* check if call id is in use */
1746 epoint = epoint_first;
1749 if (epoint->ep_park)
1751 if (epoint->ep_park_len == len)
1752 if (!memcmp(epoint->ep_park_callid, callid, len))
1754 ret = -84; /* call id in use */
1758 epoint = epoint->next;
1761 /* notify the hold of call */
1762 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1763 message->param.notifyinfo.notify = INFO_NOTIFY_USER_SUSPENDED;
1764 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1765 message_put(message);
1767 /* deactivate bchannel */
1768 start_trace(p_m_mISDNport->portnum,
1769 p_m_mISDNport->ifport->interface,
1770 nationalize(p_callerinfo.id, p_callerinfo.ntype),
1771 p_dialinginfo.number,
1774 "CHANNEL RELEASE (suspend)");
1775 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1779 /* sending suspend to endpoint */
1780 while (p_epointlist)
1782 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_SUSPEND);
1783 memcpy(message->param.parkinfo.callid, callid, sizeof(message->param.parkinfo.callid));
1784 message->param.parkinfo.len = len;
1785 message_put(message);
1787 free_epointlist(p_epointlist);
1790 /* sending SUSPEND_ACKNOWLEDGE */
1791 dmsg = create_l3msg(CC_SUSPEND_ACKNOWLEDGE | REQUEST, MT_SUSPEND_ACKNOWLEDGE, dinfo, sizeof(SUSPEND_ACKNOWLEDGE_t), p_m_d_ntmode);
1792 suspend_acknowledge = (SUSPEND_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1793 l3_trace_header(CC_SUSPEND_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1795 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1797 new_state(PORT_STATE_RELEASE);
1801 /* CC_RESUME INDICATION */
1802 void Pdss1::resume_ind(unsigned long prim, unsigned long dinfo, void *data)
1804 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1805 RESUME_t *resume = (RESUME_t *)((unsigned long)data + headerlen);
1806 RESUME_REJECT_t *resume_reject;
1807 RESUME_ACKNOWLEDGE_t *resume_acknowledge;
1808 unsigned char callid[8];
1810 int channel, exclusive;
1812 class Endpoint *epoint;
1813 struct message *message;
1816 /* callref from nt-lib */
1819 /* nt-library now gives us the id via CC_RESUME */
1820 if (dinfo&(~0xff) == 0xff00)
1822 PERROR("fatal software error: l3-stack gives us a process id 0xff00-0xffff\n");
1825 l3_trace_header(CC_NEW_CR | INDICATION, DIRECTION_IN);
1827 add_trace("callref", "old", "0x%x", p_m_d_l3id);
1828 add_trace("callref", "new", "0x%x", dinfo);
1830 if (p_m_d_l3id&(~0xff) == 0xff00)
1831 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
1833 p_m_d_ces = setup->ces;
1836 l3_trace_header(prim, DIRECTION_IN);
1837 dec_ie_call_id(resume->CALL_ID, (Q931_info_t *)((unsigned long)data+headerlen), callid, &len);
1840 /* if blocked, release call */
1841 if (p_m_mISDNport->ifport->block)
1843 RELEASE_COMPLETE_t *release_complete;
1845 printlog("--- port#%d is blocked.\n", mISDNport->ifport->portnum);
1855 channel = -1; /* any channel */
1858 ret = hunt_bchannel(channel, exclusive);
1862 dmsg = create_l3msg(CC_RESUME_REJECT | REQUEST, MT_RESUME_REJECT, dinfo, sizeof(RESUME_REJECT_t), p_m_d_ntmode);
1863 resume_reject = (RESUME_REJECT_t *)(dmsg->data + headerlen);
1864 l3_trace_header(CC_RESUME_REJECT | REQUEST, DIRECTION_OUT);
1865 enc_ie_cause(&resume_reject->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1867 add_trace("reason", NULL, "port blocked");
1869 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1870 new_state(PORT_STATE_RELEASE);
1875 /* create endpoint */
1878 PERROR("SOFTWARE ERROR: incoming resume but already got an endpoint, exitting...\n");
1881 ret = -85; /* no call suspended */
1882 epoint = epoint_first;
1885 if (epoint->ep_park)
1887 ret = -83; /* suspended call exists, but this not */
1888 if (epoint->ep_park_len == len)
1889 if (!memcmp(epoint->ep_park_callid, callid, len))
1892 epoint = epoint->next;
1897 if (!(epointlist_new(epoint->ep_serial)))
1899 PERROR("no memory for epointlist\n");
1902 if (!(epoint->portlist_new(p_serial, p_type, p_m_mISDNport->is_earlyb)))
1904 PERROR("no memory for portlist\n");
1907 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RESUME);
1908 message_put(message);
1910 /* notify the resume of call */
1911 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1912 message->param.notifyinfo.notify = INFO_NOTIFY_USER_RESUMED;
1913 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1914 message_put(message);
1916 /* sending RESUME_ACKNOWLEDGE */
1917 dmsg = create_l3msg(CC_RESUME_ACKNOWLEDGE | REQUEST, MT_RESUME_ACKNOWLEDGE, dinfo, sizeof(RESUME_ACKNOWLEDGE_t), p_m_d_ntmode);
1918 resume_acknowledge = (RESUME_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1919 l3_trace_header(CC_RESUME_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1920 enc_ie_channel_id(&resume_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
1922 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1924 new_state(PORT_STATE_CONNECT);
1928 /* CC_FACILITY INDICATION */
1929 void Pdss1::facility_ind(unsigned long prim, unsigned long dinfo, void *data)
1931 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1932 FACILITY_t *facility = (FACILITY_t *)((unsigned long)data + headerlen);
1933 unsigned char facil[256];
1935 struct message *message;
1937 l3_trace_header(prim, DIRECTION_IN);
1938 dec_ie_facility(facility->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), facil, &facil_len);
1945 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_FACILITY);
1946 message->param.facilityinfo.len = facil_len;
1947 memcpy(message->param.facilityinfo.data, facil, facil_len);
1948 message_put(message);
1953 * handler for isdn connections
1954 * incoming information are parsed and sent via message to the endpoint
1956 void Pdss1::message_isdn(unsigned long prim, unsigned long dinfo, void *data)
1964 case CC_TIMEOUT | INDICATION:
1965 l3_trace_header(prim, DIRECTION_IN);
1968 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1969 timer_hex = *((int *)(((char *)data)+headerlen));
1972 add_trace("timer", NULL, "%x", timer_hex);
1974 if (timer_hex==0x312 && p_m_d_ntmode)
1975 t312_timeout(prim, dinfo, data);
1978 case CC_SETUP | INDICATION:
1979 if (p_state != PORT_STATE_IDLE)
1981 setup_ind(prim, dinfo, data);
1984 case CC_SETUP | CONFIRM:
1987 l3_trace_header(CC_NEW_CR | INDICATION, DIRECTION_IN);
1988 add_trace("callref", "old", "0x%x", p_m_d_l3id);
1989 /* nt-library now gives us a new id via CC_SETUP_CONFIRM */
1990 if ((p_m_d_l3id&0xff00) != 0xff00)
1991 PERROR(" strange setup-procid 0x%x\n", p_m_d_l3id);
1992 p_m_d_l3id = *((int *)(((u_char *)data)+ mISDNUSER_HEAD_SIZE));
1993 add_trace("callref", "new", "0x%x", p_m_d_l3id);
1999 case CC_INFORMATION | INDICATION:
2000 information_ind(prim, dinfo, data);
2003 case CC_SETUP_ACKNOWLEDGE | INDICATION:
2004 if (p_state != PORT_STATE_OUT_SETUP)
2006 PERROR("Pdss1(%s) received setup_acknowledge, but we are not in outgoing setup state, IGNORING.\n", p_name);
2009 setup_acknowledge_ind(prim, dinfo, data);
2012 case CC_PROCEEDING | INDICATION:
2013 if (p_state != PORT_STATE_OUT_SETUP
2014 && p_state != PORT_STATE_OUT_OVERLAP)
2016 PERROR("Pdss1(%s) received proceeding, but we are not in outgoing setup OR overlap state, IGNORING.\n", p_name);
2019 proceeding_ind(prim, dinfo, data);
2022 case CC_ALERTING | INDICATION:
2023 if (p_state != PORT_STATE_OUT_SETUP
2024 && p_state != PORT_STATE_OUT_OVERLAP
2025 && p_state != PORT_STATE_OUT_PROCEEDING)
2027 PERROR("Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding state, IGNORING.\n", p_name);
2030 alerting_ind(prim, dinfo, data);
2033 case CC_CONNECT | INDICATION:
2034 if (p_state != PORT_STATE_OUT_SETUP
2035 && p_state != PORT_STATE_OUT_OVERLAP
2036 && p_state != PORT_STATE_OUT_PROCEEDING
2037 && p_state != PORT_STATE_OUT_ALERTING)
2039 PERROR("Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding OR ALERTING state, IGNORING.\n", p_name);
2042 connect_ind(prim, dinfo, data);
2043 if (p_m_d_notify_pending)
2045 /* send pending notify message during connect */
2046 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2047 message_free(p_m_d_notify_pending);
2048 p_m_d_notify_pending = NULL;
2052 case CC_CONNECT_ACKNOWLEDGE | INDICATION:
2053 case CC_CONNECT | CONFIRM:
2054 if (p_state == PORT_STATE_CONNECT_WAITING)
2055 new_state(PORT_STATE_CONNECT);
2056 if (p_m_d_notify_pending)
2058 /* send pending notify message during connect-ack */
2059 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2060 message_free(p_m_d_notify_pending);
2061 p_m_d_notify_pending = NULL;
2065 case CC_DISCONNECT | INDICATION:
2066 disconnect_ind(prim, dinfo, data);
2069 case CC_RELEASE | CONFIRM:
2070 case CC_RELEASE | INDICATION:
2071 release_ind(prim, dinfo, data);
2074 case CC_RELEASE_COMPLETE | INDICATION:
2075 release_complete_ind(prim, dinfo, data);
2078 case CC_RELEASE_COMPLETE | CONFIRM:
2081 case CC_NOTIFY | INDICATION:
2082 notify_ind(prim, dinfo, data);
2085 case CC_HOLD | INDICATION:
2086 hold_ind(prim, dinfo, data);
2089 case CC_RETRIEVE | INDICATION:
2090 retrieve_ind(prim, dinfo, data);
2093 case CC_SUSPEND | INDICATION:
2094 suspend_ind(prim, dinfo, data);
2097 case CC_RESUME | INDICATION:
2098 resume_ind(prim, dinfo, data);
2101 case CC_FACILITY | INDICATION:
2102 facility_ind(prim, dinfo, data);
2105 case CC_RELEASE_CR | INDICATION:
2106 l3_trace_header(CC_RELEASE_CR | INDICATION, DIRECTION_IN);
2107 add_trace("callref", NULL, "0x%x", p_m_d_l3id);
2111 if ((p_m_d_l3id&0xff00) == 0xff00)
2112 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
2116 /* sending release to endpoint in case we still have an endpoint
2117 * NOTE: this only happens if the stack releases due to layer1
2118 * or layer2 breakdown. otherwhise a release is received first.
2122 struct message *message;
2123 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
2124 message->param.disconnectinfo.cause = (p_m_d_collect_cause!=CAUSE_NOUSER)?p_m_d_collect_cause:CAUSE_UNSPECIFIED;
2125 message->param.disconnectinfo.location = (p_m_d_collect_cause!=CAUSE_NOUSER)?p_m_d_collect_location:LOCATION_PRIVATE_LOCAL;
2126 message_put(message);
2128 free_epointlist(p_epointlist);
2130 new_state(PORT_STATE_RELEASE);
2134 case CC_NEW_CR | INDICATION:
2135 l3_trace_header(prim, DIRECTION_IN);
2137 add_trace("callref", "old", "0x%x", p_m_d_l3id);
2140 new_l3id = *((int *)(((u_char *)data+mISDNUSER_HEAD_SIZE)));
2141 if (((new_l3id&0xff00)!=0xff00) && ((p_m_d_l3id&0xff00)==0xff00))
2142 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
2147 p_m_d_l3id = new_l3id;
2148 add_trace("callref", "new", "0x%x", p_m_d_l3id);
2153 l3_trace_header(prim, DIRECTION_IN);
2154 add_trace("unhandled", "prim", "0x%x", prim);
2159 void Pdss1::new_state(int state)
2161 class Endpoint *epoint;
2164 epoint = find_epoint_id(ACTIVE_EPOINT(p_epointlist));
2165 if (epoint && p_m_d_ntmode)
2167 if (state == PORT_STATE_IN_OVERLAP)
2169 p_m_timeout = p_settings.tout_dialing;
2172 if (state != p_state)
2174 if (state == PORT_STATE_IN_SETUP
2175 || state == PORT_STATE_IN_OVERLAP)
2177 p_m_timeout = p_settings.tout_setup;
2180 if (state == PORT_STATE_IN_PROCEEDING
2181 || state == PORT_STATE_OUT_PROCEEDING)
2183 p_m_timeout = p_settings.tout_proceeding;
2186 if (state == PORT_STATE_IN_ALERTING
2187 || state == PORT_STATE_OUT_ALERTING)
2189 p_m_timeout = p_settings.tout_alerting;
2192 if (state == PORT_STATE_CONNECT
2193 || state == PORT_STATE_CONNECT_WAITING)
2197 if (state == PORT_STATE_IN_DISCONNECT
2198 || state == PORT_STATE_OUT_DISCONNECT)
2200 p_m_timeout = p_settings.tout_disconnect;
2206 Port::new_state(state);
2213 int Pdss1::handler(void)
2217 if ((ret = Port::handler()))
2220 /* handle destruction */
2221 if (p_m_delete && p_m_d_l3id==0)
2232 * handles all messages from endpoint
2234 /* MESSAGE_INFORMATION */
2235 void Pdss1::message_information(unsigned long epoint_id, int message_id, union parameter *param)
2237 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2238 INFORMATION_t *information;
2241 if (param->information.number[0]) /* only if we have something to dial */
2243 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2244 l3_trace_header(CC_INFORMATION | REQUEST, DIRECTION_OUT);
2245 information = (INFORMATION_t *)(dmsg->data + headerlen);
2246 enc_ie_called_pn(&information->CALLED_PN, dmsg, 0, 1, (unsigned char *)param->information.number);
2248 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2257 void Pdss1::message_setup(unsigned long epoint_id, int message_id, union parameter *param)
2259 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2260 INFORMATION_t *information;
2263 int plan, type, screen, present, reason;
2264 int capability, mode, rate, coding, user, presentation, interpretation, hlc, exthlc;
2265 int channel, exclusive;
2267 struct epoint_list *epointlist;
2269 /* release if port is blocked */
2270 if (p_m_mISDNport->ifport->block)
2272 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2273 message->param.disconnectinfo.cause = 27; // temp. unavail.
2274 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2275 message_put(message);
2276 new_state(PORT_STATE_RELEASE);
2281 /* copy setup infos to port */
2282 memcpy(&p_callerinfo, ¶m->setup.callerinfo, sizeof(p_callerinfo));
2283 memcpy(&p_dialinginfo, ¶m->setup.dialinginfo, sizeof(p_dialinginfo));
2284 memcpy(&p_capainfo, ¶m->setup.capainfo, sizeof(p_capainfo));
2285 memcpy(&p_redirinfo, ¶m->setup.redirinfo, sizeof(p_redirinfo));
2286 // SCPY(&p_m_tones_dir, param->setup.ext.tones_dir);
2288 /* only display at connect state: this case happens if endpoint is in connected mode */
2289 if (p_state==PORT_STATE_CONNECT)
2291 if (p_type!=PORT_TYPE_DSS1_NT_OUT
2292 && p_type!=PORT_TYPE_DSS1_NT_IN)
2294 if (p_callerinfo.display[0])
2296 /* sending information */
2297 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2298 information = (INFORMATION_t *)(dmsg->data + headerlen);
2299 l3_trace_header(CC_INFORMATION | REQUEST, DIRECTION_OUT);
2301 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_callerinfo.display);
2303 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2308 /* attach only if not already */
2309 epointlist = p_epointlist;
2312 if (epointlist->epoint_id == epoint_id)
2314 epointlist = epointlist->next;
2318 if (!(epointlist_new(epoint_id)))
2320 PERROR("no memory for epointlist\n");
2329 channel = p_m_b_channel;
2330 exclusive = p_m_b_exclusive;
2332 channel = CHANNEL_ANY;
2333 /* nt-port with no channel, not reserverd */
2334 if (!p_m_b_channel && !p_m_b_reserve && p_type==PORT_TYPE_DSS1_NT_OUT)
2335 channel = CHANNEL_NO;
2338 l3_trace_header(CC_NEW_CR | REQUEST, DIRECTION_OUT);
2344 if (p_m_mISDNport->procids[i] == 0)
2350 struct message *message;
2352 add_trace("callref", NULL, "no free id");
2354 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2355 message->param.disconnectinfo.cause = 47;
2356 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2357 message_put(message);
2358 new_state(PORT_STATE_RELEASE);
2362 p_m_mISDNport->procids[i] = 1;
2363 p_m_d_l3id = 0xff00 | i;
2367 /* if we are in te-mode, we need to create a process first */
2368 if (newteid++ > 0x7fff)
2370 p_m_d_l3id = (entity<<16) | newteid;
2371 /* preparing message */
2372 ncr.prim = CC_NEW_CR | REQUEST;
2373 ncr.addr = p_m_mISDNport->upper_id | FLG_MSG_DOWN;
2374 ncr.dinfo = p_m_d_l3id;
2377 mISDN_write(mISDNdevice, &ncr, mISDN_HEADER_LEN+ncr.len, TIMEOUT_1SEC);
2381 add_trace("callref", "new", "0x%x", p_m_d_l3id);
2384 /* preparing setup message */
2385 dmsg = create_l3msg(CC_SETUP | REQUEST, MT_SETUP, p_m_d_l3id, sizeof(SETUP_t), p_m_d_ntmode);
2386 l3_trace_header(CC_SETUP | REQUEST, DIRECTION_OUT);
2387 setup = (SETUP_t *)(dmsg->data + headerlen);
2388 /* channel information */
2389 if (channel >= 0) /* it should */
2391 enc_ie_channel_id(&setup->CHANNEL_ID, dmsg, exclusive, channel);
2393 /* caller information */
2395 switch (p_callerinfo.ntype)
2397 case INFO_NTYPE_INTERNATIONAL:
2400 case INFO_NTYPE_NATIONAL:
2403 case INFO_NTYPE_SUBSCRIBER:
2406 default: /* INFO_NTYPE_UNKNOWN */
2410 switch (p_callerinfo.screen)
2412 case INFO_SCREEN_USER:
2415 default: /* INFO_SCREEN_NETWORK */
2419 switch (p_callerinfo.present)
2421 case INFO_PRESENT_RESTRICTED:
2424 case INFO_PRESENT_NOTAVAIL:
2427 default: /* INFO_PRESENT_ALLOWED */
2432 enc_ie_calling_pn(&setup->CALLING_PN, dmsg, type, plan, present, screen, (unsigned char *)p_callerinfo.id);
2433 /* dialing information */
2434 if (p_dialinginfo.number[0]) /* only if we have something to dial */
2436 enc_ie_called_pn(&setup->CALLED_PN, dmsg, 0, 1, (unsigned char *)p_dialinginfo.number);
2438 /* sending complete */
2439 if (p_dialinginfo.sending_complete)
2440 enc_ie_complete(&setup->COMPLETE, dmsg, 1);
2441 /* sending user-user */
2442 if (param->setup.useruser.len)
2444 enc_ie_useruser(&setup->USER_USER, dmsg, param->setup.useruser.protocol, param->setup.useruser.data, param->setup.useruser.len);
2446 /* redirecting number */
2448 switch (p_redirinfo.ntype)
2450 case INFO_NTYPE_INTERNATIONAL:
2453 case INFO_NTYPE_NATIONAL:
2456 case INFO_NTYPE_SUBSCRIBER:
2459 default: /* INFO_NTYPE_UNKNOWN */
2463 switch (p_redirinfo.screen)
2465 case INFO_SCREEN_USER:
2468 default: /* INFO_SCREE_NETWORK */
2472 switch (p_redirinfo.reason)
2474 case INFO_REDIR_BUSY:
2477 case INFO_REDIR_NORESPONSE:
2480 case INFO_REDIR_UNCONDITIONAL:
2483 case INFO_REDIR_CALLDEFLECT:
2486 case INFO_REDIR_OUTOFORDER:
2489 default: /* INFO_REDIR_UNKNOWN */
2493 switch (p_redirinfo.present)
2495 case INFO_PRESENT_NULL: /* no redir at all */
2502 case INFO_PRESENT_RESTRICTED:
2505 case INFO_PRESENT_NOTAVAIL:
2508 default: /* INFO_PRESENT_ALLOWED */
2512 /* sending redirecting number only in ntmode */
2513 if (type >= 0 && p_m_d_ntmode)
2514 enc_ie_redir_nr(&setup->REDIR_NR, dmsg, type, plan, present, screen, reason, (unsigned char *)p_redirinfo.id);
2515 /* bearer capability */
2516 //printf("hlc=%d\n",p_capainfo.hlc);
2518 capability = p_capainfo.bearer_capa;
2519 mode = p_capainfo.bearer_mode;
2520 rate = (mode==INFO_BMODE_CIRCUIT)?0x10:0x00;
2521 switch (p_capainfo.bearer_info1)
2523 case INFO_INFO1_NONE:
2527 user = p_capainfo.bearer_info1 & 0x7f;
2530 enc_ie_bearer(&setup->BEARER, dmsg, coding, capability, mode, rate, -1, user);
2537 hlc = p_capainfo.hlc & 0x7f;
2539 if (p_capainfo.exthlc)
2540 exthlc = p_capainfo.exthlc & 0x7f;
2541 enc_ie_hlc(&setup->HLC, dmsg, coding, interpretation, presentation, hlc, exthlc);
2545 if (p_callerinfo.display[0] && p_m_d_ntmode)
2546 enc_ie_display(&setup->DISPLAY, dmsg, (unsigned char *)p_callerinfo.display);
2548 /* nt-mode: CNIP (calling name identification presentation) */
2549 if (p_callerinfo.name[0] && p_m_d_ntmode)
2550 enc_facility_centrex(&setup->FACILITY, dmsg, (unsigned char *)p_callerinfo.name, 1);
2554 /* send setup message now */
2555 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2557 new_state(PORT_STATE_OUT_SETUP);
2560 /* MESSAGE_FACILITY */
2561 void Pdss1::message_facility(unsigned long epoint_id, int message_id, union parameter *param)
2563 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2564 FACILITY_t *facility;
2567 /* facility will not be sent to external lines */
2571 /* sending facility */
2572 dmsg = create_l3msg(CC_FACILITY | REQUEST, MT_FACILITY, p_m_d_l3id, sizeof(FACILITY_t), p_m_d_ntmode);
2573 facility = (FACILITY_t *)(dmsg->data + headerlen);
2574 l3_trace_header(CC_FACILITY | REQUEST, DIRECTION_OUT);
2575 enc_ie_facility(&facility->FACILITY, dmsg, (unsigned char *)param->facilityinfo.data, param->facilityinfo.len);
2577 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2580 /* MESSAGE_NOTIFY */
2581 void Pdss1::message_notify(unsigned long epoint_id, int message_id, union parameter *param)
2583 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2584 INFORMATION_t *information;
2585 NOTIFY_t *notification;
2587 int plan, type = -1, present;
2590 if (param->notifyinfo.notify>INFO_NOTIFY_NONE)
2591 notify = param->notifyinfo.notify & 0x7f;
2594 if (p_state != PORT_STATE_CONNECT)
2596 /* notify only allowed in active state */
2602 switch (param->notifyinfo.ntype)
2604 case INFO_NTYPE_INTERNATIONAL:
2607 case INFO_NTYPE_NATIONAL:
2610 case INFO_NTYPE_SUBSCRIBER:
2613 default: /* INFO_NTYPE_UNKNOWN */
2617 switch (param->notifyinfo.present)
2619 case INFO_PRESENT_NULL: /* no redir at all */
2624 case INFO_PRESENT_RESTRICTED:
2627 case INFO_PRESENT_NOTAVAIL:
2630 default: /* INFO_PRESENT_ALLOWED */
2636 if (notify<0 && !param->notifyinfo.display[0])
2638 /* nothing to notify, nothing to display */
2644 if (p_state!=PORT_STATE_CONNECT)
2646 /* queue notification */
2647 if (p_m_d_notify_pending)
2648 message_free(p_m_d_notify_pending);
2649 p_m_d_notify_pending = message_create(ACTIVE_EPOINT(p_epointlist), p_serial, EPOINT_TO_PORT, message_id);
2650 memcpy(&p_m_d_notify_pending->param, param, sizeof(union parameter));
2653 /* sending notification */
2654 dmsg = create_l3msg(CC_NOTIFY | REQUEST, MT_NOTIFY, p_m_d_l3id, sizeof(NOTIFY_t), p_m_d_ntmode);
2655 notification = (NOTIFY_t *)(dmsg->data + headerlen);
2656 l3_trace_header(CC_NOTIFY | REQUEST, DIRECTION_OUT);
2657 enc_ie_notify(¬ification->NOTIFY, dmsg, notify);
2658 /* sending redirection number only in ntmode */
2659 if (type >= 0 && p_m_d_ntmode)
2660 enc_ie_redir_dn(¬ification->REDIR_DN, dmsg, type, plan, present, (unsigned char *)param->notifyinfo.id);
2661 if (param->notifyinfo.display[0] && p_m_d_ntmode)
2662 enc_ie_display(¬ification->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display);
2664 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2666 } else if (p_m_d_ntmode)
2668 /* sending information */
2669 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2670 information = (INFORMATION_t *)(dmsg->data + headerlen);
2671 l3_trace_header(CC_INFORMATION | REQUEST, DIRECTION_OUT);
2672 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display);
2674 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2678 /* MESSAGE_OVERLAP */
2679 void Pdss1::message_overlap(unsigned long epoint_id, int message_id, union parameter *param)
2681 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2682 SETUP_ACKNOWLEDGE_t *setup_acknowledge;
2685 /* sending setup_acknowledge */
2686 dmsg = create_l3msg(CC_SETUP_ACKNOWLEDGE | REQUEST, MT_SETUP_ACKNOWLEDGE, p_m_d_l3id, sizeof(SETUP_ACKNOWLEDGE_t), p_m_d_ntmode);
2687 setup_acknowledge = (SETUP_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
2688 l3_trace_header(CC_SETUP_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
2689 /* channel information */
2690 if (p_state == PORT_STATE_IN_SETUP)
2691 enc_ie_channel_id(&setup_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2692 /* progress information */
2693 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2694 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2695 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2696 if (p_m_mISDNport->is_tones)
2697 enc_ie_progress(&setup_acknowledge->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2699 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2701 new_state(PORT_STATE_IN_OVERLAP);
2704 /* MESSAGE_PROCEEDING */
2705 void Pdss1::message_proceeding(unsigned long epoint_id, int message_id, union parameter *param)
2707 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2708 CALL_PROCEEDING_t *proceeding;
2711 /* sending proceeding */
2712 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2713 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2714 l3_trace_header(CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2715 /* channel information */
2716 if (p_state == PORT_STATE_IN_SETUP)
2717 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2718 /* progress information */
2719 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2720 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2721 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2722 if (p_m_mISDNport->is_tones)
2723 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2725 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2727 new_state(PORT_STATE_IN_PROCEEDING);
2730 /* MESSAGE_ALERTING */
2731 void Pdss1::message_alerting(unsigned long epoint_id, int message_id, union parameter *param)
2733 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2734 ALERTING_t *alerting;
2737 /* NT-MODE in setup state we must send PROCEEDING first */
2738 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2740 CALL_PROCEEDING_t *proceeding;
2742 /* sending proceeding */
2743 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2744 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2745 l3_trace_header(CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2746 /* channel information */
2747 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2748 /* progress information */
2749 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2750 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2751 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2752 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2754 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2755 new_state(PORT_STATE_IN_PROCEEDING);
2758 /* sending alerting */
2759 dmsg = create_l3msg(CC_ALERTING | REQUEST, MT_ALERTING, p_m_d_l3id, sizeof(ALERTING_t), p_m_d_ntmode);
2760 alerting = (ALERTING_t *)(dmsg->data + headerlen);
2761 l3_trace_header(CC_ALERTING | REQUEST, DIRECTION_OUT);
2762 /* channel information */
2763 if (p_state == PORT_STATE_IN_SETUP)
2764 enc_ie_channel_id(&alerting->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2765 /* progress information */
2766 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2767 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2768 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2769 if (p_m_mISDNport->is_tones)
2770 enc_ie_progress(&alerting->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2772 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2774 new_state(PORT_STATE_IN_ALERTING);
2777 /* MESSAGE_CONNECT */
2778 void Pdss1::message_connect(unsigned long epoint_id, int message_id, union parameter *param)
2780 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2781 INFORMATION_t *information;
2783 int type, plan, present, screen;
2785 class Endpoint *epoint;
2787 /* NT-MODE in setup state we must send PROCEEDING first */
2788 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2790 CALL_PROCEEDING_t *proceeding;
2792 /* sending proceeding */
2793 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2794 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2795 l3_trace_header(CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2796 /* channel information */
2797 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2798 // /* progress information */
2799 // if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2800 // || p_capainfo.bearer_capa==INFO_BC_AUDIO
2801 // || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2802 // enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2804 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2805 new_state(PORT_STATE_IN_PROCEEDING);
2808 /* copy connected information */
2809 memcpy(&p_connectinfo, ¶m->connectinfo, sizeof(p_connectinfo));
2811 /* only display at connect state */
2812 if (p_state == PORT_STATE_CONNECT)
2813 if (p_connectinfo.display[0])
2815 /* sending information */
2816 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2817 information = (INFORMATION_t *)(dmsg->data + headerlen);
2818 l3_trace_header(CC_INFORMATION | REQUEST, DIRECTION_OUT);
2820 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_connectinfo.display);
2822 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2826 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)
2828 /* connect command only possible in setup, proceeding or alerting state */
2832 /* preparing connect message */
2833 dmsg = create_l3msg(CC_CONNECT | REQUEST, MT_CONNECT, p_m_d_l3id, sizeof(CONNECT_t), p_m_d_ntmode);
2834 connect = (CONNECT_t *)(dmsg->data + headerlen);
2835 l3_trace_header(CC_CONNECT | REQUEST, DIRECTION_OUT);
2836 /* connect information */
2838 switch (p_connectinfo.ntype)
2840 case INFO_NTYPE_INTERNATIONAL:
2843 case INFO_NTYPE_NATIONAL:
2846 case INFO_NTYPE_SUBSCRIBER:
2849 default: /* INFO_NTYPE_UNKNOWN */
2853 switch (param->connectinfo.screen)
2855 case INFO_SCREEN_USER:
2858 default: /* INFO_SCREE_NETWORK */
2862 switch (p_connectinfo.present)
2864 case INFO_PRESENT_NULL: /* no colp at all */
2870 case INFO_PRESENT_RESTRICTED:
2873 case INFO_PRESENT_NOTAVAIL:
2876 default: /* INFO_PRESENT_ALLOWED */
2881 enc_ie_connected_pn(&connect->CONNECT_PN, dmsg, type, plan, present, screen, (unsigned char *)p_connectinfo.id);
2883 if (p_connectinfo.display[0] && p_m_d_ntmode)
2884 enc_ie_display(&connect->DISPLAY, dmsg, (unsigned char *)p_connectinfo.display);
2886 /* nt-mode: CONP (connected name identification presentation) */
2887 if (p_connectinfo.name[0] && p_m_d_ntmode)
2888 enc_facility_centrex(&connect->FACILITY, dmsg, (unsigned char *)p_connectinfo.name, 0);
2893 epoint = find_epoint_id(epoint_id);
2894 enc_ie_date(&connect->DATE, dmsg, now, p_settings.no_seconds);
2897 /* finally send message */
2898 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2901 new_state(PORT_STATE_CONNECT);
2903 new_state(PORT_STATE_CONNECT_WAITING);
2907 /* MESSAGE_DISCONNECT */
2908 void Pdss1::message_disconnect(unsigned long epoint_id, int message_id, union parameter *param)
2910 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2911 DISCONNECT_t *disconnect;
2912 RELEASE_COMPLETE_t *release_complete;
2914 struct message *message;
2917 /* we reject during incoming setup when we have no tones. also if we are in outgoing setup state */
2918 if ((p_state==PORT_STATE_IN_SETUP && !p_m_mISDNport->is_tones)
2919 || p_state==PORT_STATE_OUT_SETUP)
2921 /* sending release to endpoint */
2924 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
2925 message->param.disconnectinfo.cause = 16;
2926 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2927 message_put(message);
2929 free_epointlist(p_epointlist);
2931 /* sending release */
2932 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
2933 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
2934 l3_trace_header(CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
2936 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);
2938 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2939 new_state(PORT_STATE_RELEASE);
2944 /* NT-MODE in setup state we must send PROCEEDING first */
2945 if (p_state==PORT_STATE_IN_SETUP)
2947 CALL_PROCEEDING_t *proceeding;
2949 /* sending proceeding */
2950 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2951 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2952 l3_trace_header(CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2953 /* channel information */
2954 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2955 /* progress information */
2956 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2957 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2958 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2959 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2961 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2962 new_state(PORT_STATE_IN_PROCEEDING);
2965 /* sending disconnect */
2966 dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode);
2967 disconnect = (DISCONNECT_t *)(dmsg->data + headerlen);
2968 l3_trace_header(CC_DISCONNECT | REQUEST, DIRECTION_OUT);
2969 /* progress information */
2970 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2971 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2972 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2973 if (p_m_mISDNport->is_tones)
2974 enc_ie_progress(&disconnect->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2976 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);
2978 if (param->disconnectinfo.display[0])
2979 p = param->disconnectinfo.display;
2980 if (p) if (*p && p_m_d_ntmode)
2981 enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p);
2983 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2984 new_state(PORT_STATE_OUT_DISCONNECT);
2987 /* MESSAGE_RELEASE */
2988 void Pdss1::message_release(unsigned long epoint_id, int message_id, union parameter *param)
2990 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2992 RELEASE_COMPLETE_t *release_complete;
2993 DISCONNECT_t *disconnect;
2995 class Endpoint *epoint;
2998 /* if we have incoming disconnected, we may release */
2999 if (p_state==PORT_STATE_IN_DISCONNECT
3000 || p_state==PORT_STATE_OUT_DISCONNECT)
3002 /* sending release */
3003 dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, p_m_d_l3id, sizeof(RELEASE_t), p_m_d_ntmode);
3004 release = (RELEASE_t *)(dmsg->data + headerlen);
3005 l3_trace_header(CC_RELEASE | REQUEST, DIRECTION_OUT);
3007 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);
3009 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3010 new_state(PORT_STATE_RELEASE);
3013 free_epointid(epoint_id);
3014 l3_trace_header(CC_RELEASE_CR | REQUEST, DIRECTION_OUT);
3015 add_trace("callref", "new", "0x%x", p_m_d_l3id);
3019 if ((p_m_d_l3id&0xff00) == 0xff00)
3020 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
3026 /* if we are on outgoing/incoming call setup, we may release complete */
3027 if (p_state==PORT_STATE_OUT_SETUP
3028 || p_state==PORT_STATE_IN_SETUP
3029 // NOTE: a bug in mISDNuser (see disconnect_req_out !!!)
3030 || p_state==PORT_STATE_OUT_PROCEEDING)
3032 /* sending release */
3033 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
3034 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
3035 l3_trace_header(CC_RELEASE | REQUEST, DIRECTION_OUT);
3037 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);
3039 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3040 new_state(PORT_STATE_RELEASE);
3041 goto remove_endpoint;
3044 /* NT-MODE in setup state we must send PROCEEDING first */
3045 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
3047 CALL_PROCEEDING_t *proceeding;
3049 /* sending proceeding */
3050 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
3051 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
3052 l3_trace_header(CC_PROCEEDING | REQUEST, DIRECTION_OUT);
3053 /* channel information */
3054 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
3055 /* progress information */
3056 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
3057 || p_capainfo.bearer_capa==INFO_BC_AUDIO
3058 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
3059 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
3061 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3064 /* sending disconnect */
3065 dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode);
3066 disconnect = (DISCONNECT_t *)(dmsg->data + headerlen);
3067 l3_trace_header(CC_DISCONNECT | REQUEST, DIRECTION_OUT);
3068 /* progress information */
3069 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
3070 || p_capainfo.bearer_capa==INFO_BC_AUDIO
3071 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
3072 if (p_m_mISDNport->is_tones)
3073 enc_ie_progress(&disconnect->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
3075 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);
3077 epoint = find_epoint_id(epoint_id);
3078 if (param->disconnectinfo.display[0])
3079 p = param->disconnectinfo.display;
3080 if (p) if (*p && p_m_d_ntmode)
3081 enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p);
3083 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3084 new_state(PORT_STATE_RELEASE);
3085 free_epointid(epoint_id);
3091 * endpoint sends messages to the port
3093 int Pdss1::message_epoint(unsigned long epoint_id, int message_id, union parameter *param)
3095 struct message *message;
3097 if (PmISDN::message_epoint(epoint_id, message_id, param))
3102 case MESSAGE_INFORMATION: /* overlap dialing */
3103 if (p_type==PORT_TYPE_DSS1_NT_OUT
3104 && p_state!=PORT_STATE_OUT_OVERLAP
3105 && p_state!=PORT_STATE_CONNECT
3106 && p_state!=PORT_STATE_OUT_DISCONNECT
3107 && p_state!=PORT_STATE_IN_DISCONNECT)
3111 if (p_type==PORT_TYPE_DSS1_TE_OUT
3112 && p_state!=PORT_STATE_OUT_OVERLAP
3113 && p_state!=PORT_STATE_OUT_PROCEEDING
3114 && p_state!=PORT_STATE_OUT_ALERTING
3115 && p_state!=PORT_STATE_CONNECT
3116 && p_state!=PORT_STATE_OUT_DISCONNECT
3117 && p_state!=PORT_STATE_IN_DISCONNECT)
3121 if ((p_type==PORT_TYPE_DSS1_NT_IN || p_type==PORT_TYPE_DSS1_TE_IN)
3122 && p_state!=PORT_STATE_IN_OVERLAP
3123 && p_state!=PORT_STATE_IN_PROCEEDING
3124 && p_state!=PORT_STATE_IN_ALERTING
3125 && p_state!=PORT_STATE_CONNECT
3126 && p_state!=PORT_STATE_CONNECT_WAITING
3127 && p_state!=PORT_STATE_OUT_DISCONNECT
3128 && p_state!=PORT_STATE_IN_DISCONNECT)
3132 message_information(epoint_id, message_id, param);
3135 case MESSAGE_SETUP: /* dial-out command received from epoint */
3136 if (p_state!=PORT_STATE_IDLE
3137 && p_state!=PORT_STATE_CONNECT)
3139 PERROR("Pdss1(%s) ignoring setup because isdn port is not in idle state (or connected for sending display info).\n", p_name);
3142 if (p_epointlist && p_state==PORT_STATE_IDLE)
3144 PERROR("Pdss1(%s): software error: epoint pointer is set in idle state, how bad!! exitting.\n", p_name);
3147 /* note: pri is a special case, because links must be up for pri */
3148 if (p_m_mISDNport->l1link || p_m_mISDNport->pri || !p_m_mISDNport->ntmode || p_state!=PORT_STATE_IDLE)
3150 /* LAYER 1 is up, or we may send */
3151 message_setup(epoint_id, message_id, param);
3154 /* LAYER 1 id down, so we queue */
3155 p_m_d_queue = message_create(epoint_id, p_serial, EPOINT_TO_PORT, message_id);
3156 memcpy(&p_m_d_queue->param, param, sizeof(union parameter));
3158 if (!(epointlist_new(epoint_id)))
3160 PERROR("no memory for epointlist\n");
3164 PDEBUG(DEBUG_ISDN, "the L1 is down, we try to establish the link NT portnum=%d (%s).\n", p_m_mISDNport->portnum, p_name);
3165 act.prim = PH_ACTIVATE | REQUEST;
3166 act.addr = p_m_mISDNport->upper_id | FLG_MSG_DOWN;
3169 mISDN_write(mISDNdevice, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
3170 // /* set timeout */
3171 // p_m_mISDNport->l1timeout = now+3;
3175 case MESSAGE_NOTIFY: /* display and notifications */
3176 message_notify(epoint_id, message_id, param);
3179 case MESSAGE_FACILITY: /* facility message */
3180 message_facility(epoint_id, message_id, param);
3183 case MESSAGE_OVERLAP: /* more information is needed */
3184 if (p_state!=PORT_STATE_IN_SETUP)
3188 message_overlap(epoint_id, message_id, param);
3191 case MESSAGE_PROCEEDING: /* call of endpoint is proceeding */
3192 if (p_state!=PORT_STATE_IN_SETUP
3193 && p_state!=PORT_STATE_IN_OVERLAP)
3197 message_proceeding(epoint_id, message_id, param);
3200 case MESSAGE_ALERTING: /* call of endpoint is ringing */
3201 if (p_state!=PORT_STATE_IN_SETUP
3202 && p_state!=PORT_STATE_IN_OVERLAP
3203 && p_state!=PORT_STATE_IN_PROCEEDING)
3207 message_alerting(epoint_id, message_id, param);
3210 case MESSAGE_CONNECT: /* call of endpoint is connected */
3211 if (p_state!=PORT_STATE_IN_SETUP
3212 && p_state!=PORT_STATE_IN_OVERLAP
3213 && p_state!=PORT_STATE_IN_PROCEEDING
3214 && p_state!=PORT_STATE_IN_ALERTING
3215 && !(p_state==PORT_STATE_CONNECT && p_m_d_ntmode))
3219 message_connect(epoint_id, message_id, param);
3222 case MESSAGE_DISCONNECT: /* call has been disconnected */
3223 if (p_state!=PORT_STATE_IN_SETUP
3224 && p_state!=PORT_STATE_IN_OVERLAP
3225 && p_state!=PORT_STATE_IN_PROCEEDING
3226 && p_state!=PORT_STATE_IN_ALERTING
3227 && p_state!=PORT_STATE_OUT_SETUP
3228 && p_state!=PORT_STATE_OUT_OVERLAP
3229 && p_state!=PORT_STATE_OUT_PROCEEDING
3230 && p_state!=PORT_STATE_OUT_ALERTING
3231 && p_state!=PORT_STATE_CONNECT
3232 && p_state!=PORT_STATE_CONNECT_WAITING)
3236 message_disconnect(epoint_id, message_id, param);
3239 case MESSAGE_RELEASE: /* release isdn port */
3240 if (p_state==PORT_STATE_RELEASE)
3244 message_release(epoint_id, message_id, param);
3248 PERROR("Pdss1(%s) isdn port with (caller id %s) received a wrong message: %d\n", p_name, p_callerinfo.id, message);
3257 * data from isdn-stack (layer-3) to pbx (port class)
3259 /* NOTE: nt mode use mISDNuser_head_t as header */
3260 int stack2manager_nt(void *dat, void *arg)
3264 manager_t *mgr = (manager_t *)dat;
3265 msg_t *msg = (msg_t *)arg;
3266 mISDNuser_head_t *hh;
3267 struct mISDNport *mISDNport;
3273 /* note: nst is the first data feld of mISDNport */
3274 mISDNport = (struct mISDNport *)mgr->nst;
3276 hh = (mISDNuser_head_t *)msg->data;
3277 PDEBUG(DEBUG_ISDN, "prim(0x%x) dinfo(0x%x) msg->len(%d)\n", hh->prim, hh->dinfo, msg->len);
3279 /* find Port object of type ISDN */
3283 if (port->p_type == PORT_TYPE_DSS1_NT_IN || port->p_type == PORT_TYPE_DSS1_NT_OUT)
3285 pdss1 = (class Pdss1 *)port;
3286 //PDEBUG(DEBUG_ISDN, "comparing dinfo = 0x%x with l3id 0x%x\n", hh->dinfo, pdss1->p_m_d_l3id);
3287 /* check out correct stack */
3288 if (pdss1->p_m_mISDNport == mISDNport)
3289 /* check out correct id */
3290 if ((hh->dinfo&0xffff0000) == (pdss1->p_m_d_l3id&0xffff0000))
3292 /* found port, the message belongs to */
3300 /* if process id is master process, but a child disconnects */
3301 if ((hh->dinfo&0x0000ff00)!=0x0000ff00 && (pdss1->p_m_d_l3id&0x0000ff00)==0x0000ff00 && hh->prim==(CC_DISCONNECT|INDICATION))
3303 /* send special indication for child disconnect */
3304 pdss1->disconnect_ind_i(hh->prim, hh->dinfo, msg->data);
3308 /* if process id and layer 3 id matches */
3309 if (hh->dinfo == pdss1->p_m_d_l3id)
3311 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
3320 case MGR_SHORTSTATUS | INDICATION:
3321 case MGR_SHORTSTATUS | CONFIRM:
3323 case SSTATUS_L2_ESTABLISHED:
3325 case SSTATUS_L2_RELEASED:
3330 case DL_ESTABLISH | INDICATION:
3331 case DL_ESTABLISH | CONFIRM:
3333 PDEBUG(DEBUG_ISDN, "establish data link (DL) NT portnum=%d TEI=%d\n", mISDNport->portnum, hh->dinfo);
3334 if (mISDNport->ptp && hh->dinfo == 0)
3336 if (mISDNport->l2establish)
3338 mISDNport->l2establish = 0;
3339 PDEBUG(DEBUG_ISDN, "the link became active before l2establish timer expiry.\n");
3341 mISDNport->l2link = 1;
3342 if (mISDNport->pri);
3343 mISDNport->l1link = 1; /* this is a hack, we also assume L1 to be active */
3347 case DL_RELEASE | INDICATION:
3348 case DL_RELEASE | CONFIRM:
3350 PDEBUG(DEBUG_ISDN, "release data link (DL) NT portnum=%d TEI=%d\n", mISDNport->portnum, hh->dinfo);
3351 if (mISDNport->ptp && hh->dinfo == 0)
3353 mISDNport->l2link = 0;
3354 time(&mISDNport->l2establish);
3355 PDEBUG(DEBUG_ISDN, "because we are ptp, we set a l2establish timer.\n");
3359 case CC_SETUP | INDICATION:
3360 /* creating port object */
3361 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3362 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0)))
3364 RELEASE_COMPLETE_t *release_complete;
3367 PERROR("FATAL ERROR: cannot create port object.\n");
3368 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, hh->dinfo, sizeof(RELEASE_COMPLETE_t), mISDNport->ntmode);
3369 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + mISDN_HEADER_LEN);
3370 enc_ie_cause_standalone(mISDNport->ntmode?&release_complete->CAUSE:NULL, dmsg, (mISDNport->ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47);
3371 msg_queue_tail(&mISDNport->downqueue, dmsg);
3374 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
3377 case CC_RESUME | INDICATION:
3378 /* creating port object */
3379 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3380 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL)))
3382 SUSPEND_REJECT_t *suspend_reject;
3385 PERROR("FATAL ERROR: cannot create port object.\n");
3386 dmsg = create_l3msg(CC_SUSPEND_REJECT | REQUEST, MT_SUSPEND_REJECT, hh->dinfo, sizeof(SUSPEND_REJECT_t), mISDNport->ntmode);
3387 suspend_reject = (SUSPEND_REJECT_t *)(dmsg->data + mISDN_HEADER_LEN);
3388 enc_ie_cause_standalone(mISDNport->ntmode?&suspend_reject->CAUSE:NULL, dmsg, (mISDNport->ntmode)?1:0, 47);
3389 msg_queue_tail(&mISDNport->downqueue, dmsg);
3392 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
3395 case CC_RELEASE_CR | INDICATION:
3396 PERROR("unhandled message from stack: call ref released (l3id=0x%x)\n", hh->dinfo);
3399 case CC_DISCONNECT | INDICATION:
3403 PERROR("unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", hh->prim, hh->dinfo, msg->len);
3410 /* NOTE: te mode use iframe_t as header */
3411 int stack2manager_te(struct mISDNport *mISDNport, msg_t *msg)
3418 if (!msg || !mISDNport)
3420 frm = (iframe_t *)msg->data;
3421 PDEBUG(DEBUG_ISDN, "prim(0x%x) dinfo(0x%x) msg->len(%d)\n", frm->prim, frm->dinfo, msg->len);
3423 /* find Port object of type ISDN */
3427 if (port->p_type == PORT_TYPE_DSS1_TE_IN || port->p_type == PORT_TYPE_DSS1_TE_OUT)
3429 pdss1 = (class Pdss1 *)port;
3430 /* check out correct stack */
3431 if (pdss1->p_m_mISDNport == mISDNport)
3432 /* check out correct id */
3433 if (frm->dinfo == pdss1->p_m_d_l3id)
3435 /* found port, the message belongs to */
3443 pdss1->message_isdn(frm->prim, frm->dinfo, msg->data);
3448 /* process new cr (before setup indication) */
3449 //printf("prim = 0x%x, looking for 0x%x\n",frm->prim, (CC_NEW_CR | INDICATION));
3450 if (frm->prim == (CC_NEW_CR | INDICATION))
3453 /* creating port object */
3454 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3455 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_TE_IN, mISDNport, name, NULL)))
3457 RELEASE_COMPLETE_t *release_complete;
3460 PERROR("FATAL ERROR: cannot create port object.\n");
3461 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, frm->dinfo, sizeof(RELEASE_COMPLETE_t), mISDNport->ntmode);
3462 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + mISDN_HEADER_LEN);
3463 enc_ie_cause_standalone(mISDNport->ntmode?&release_complete->CAUSE:NULL, dmsg, (mISDNport->ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47);
3464 msg_queue_tail(&mISDNport->downqueue, dmsg);
3468 /* l3id will be set from dinfo at message_isdn */
3469 pdss1->message_isdn(frm->prim, frm->dinfo, msg->data);
3474 if (frm->prim == (CC_RELEASE_CR | INDICATION))
3476 PERROR("unhandled message from stack: call ref released (l3id=0x%x)\n", frm->dinfo);
3480 PERROR("unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", frm->prim, frm->dinfo, msg->len);
3486 * sending message that were queued during L1 activation
3487 * or releasing port if link is down
3489 void setup_queue(struct mISDNport *mISDNport, int link)
3493 struct message *message;
3495 if (!mISDNport->ntmode)
3498 /* check all port objects for pending message */
3502 if ((port->p_type&PORT_CLASS_mISDN_MASK) == PORT_CLASS_mISDN_DSS1)
3504 pdss1 = (class Pdss1 *)port;
3505 if (pdss1->p_m_mISDNport == mISDNport)
3507 if (pdss1->p_m_d_queue)
3511 PDEBUG(DEBUG_ISDN, "the L1 became active, so we send queued message for portnum=%d (%s).\n", mISDNport->portnum, pdss1->p_name);
3512 /* LAYER 1 is up, so we send */
3513 pdss1->message_setup(pdss1->p_m_d_queue->id_from, pdss1->p_m_d_queue->type, &pdss1->p_m_d_queue->param);
3514 message_free(pdss1->p_m_d_queue);
3515 pdss1->p_m_d_queue = NULL;
3518 PDEBUG(DEBUG_ISDN, "the L1 became NOT active, so we release port for portnum=%d (%s).\n", mISDNport->portnum, pdss1->p_name);
3519 message = message_create(pdss1->p_serial, pdss1->p_m_d_queue->id_from, PORT_TO_EPOINT, MESSAGE_RELEASE);
3520 message->param.disconnectinfo.cause = 27;
3521 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
3522 message_put(message);
3523 pdss1->new_state(PORT_STATE_RELEASE);
3524 pdss1->p_m_delete = 1;