1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
10 \*****************************************************************************/
15 #include <sys/socket.h>
19 extern unsigned int mt_assign_pid;
26 Pdss1::Pdss1(int type, struct mISDNport *mISDNport, char *portname, struct port_settings *settings, int channel, int exclusive, int mode) : PmISDN(type, mISDNport, portname, settings, channel, exclusive, mode)
28 p_callerinfo.itype = (mISDNport->ifport->interface->extension)?INFO_ITYPE_ISDN_EXTENSION:INFO_ITYPE_ISDN;
29 p_m_d_ntmode = mISDNport->ntmode;
30 p_m_d_tespecial = mISDNport->tespecial;
33 p_m_d_queue[0] = '\0';
34 p_m_d_notify_pending = NULL;
35 p_m_d_collect_cause = 0;
36 p_m_d_collect_location = 0;
38 PDEBUG(DEBUG_ISDN, "Created new mISDNPort(%s). Currently %d objects use, %s%s port #%d\n", portname, mISDNport->use, (mISDNport->ntmode)?"NT":"TE", (mISDNport->tespecial)?" (special)":"", p_m_portnum);
47 /* remove queued message */
48 if (p_m_d_notify_pending)
49 message_free(p_m_d_notify_pending);
54 * create layer 3 message
56 static struct l3_msg *create_l3msg(void)
64 FATAL("Cannot allocate memory, system overloaded.\n");
65 exit(0); // make gcc happy
69 * if we received a first reply to the setup message,
70 * we will check if we have now channel information
71 * return: <0: error, call is released, -cause is given
72 * 0: ok, nothing to do
74 int Pdss1::received_first_reply_to_setup(unsigned int cmd, int channel, int exclusive)
79 /* correct exclusive to 0, if no explicit channel was given */
80 if (exclusive<0 || channel<=0)
84 if (p_m_b_channel && p_m_b_exclusive)
86 /*** we gave an exclusive channel (or if we are done) ***/
88 /* if not first reply, we are done */
89 if (p_state != PORT_STATE_OUT_SETUP)
92 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
93 add_trace("channel", "request", "%d (forced)", p_m_b_channel);
94 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
96 /* if give channel not accepted or not equal */
97 if (channel!=-1 && p_m_b_channel!=channel)
99 add_trace("conclusion", NULL, "forced channel not accepted");
105 add_trace("conclusion", NULL, "channel was accepted");
106 add_trace("connect", "channel", "%d", p_m_b_channel);
109 /* activate our exclusive channel */
110 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
114 /*** we gave a non-exclusive channel ***/
116 /* if not first reply, we are done */
117 if (p_state != PORT_STATE_OUT_SETUP)
120 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
121 add_trace("channel", "request", "%d (suggest)", p_m_b_channel);
122 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
124 /* if channel was accepted as given */
125 if (channel==-1 || p_m_b_channel==channel)
127 add_trace("conclusion", NULL, "channel was accepted as given");
128 add_trace("connect", "channel", "%d", p_m_b_channel);
130 p_m_b_exclusive = 1; // we are done
131 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
135 /* if channel value is faulty */
138 add_trace("conclusion", NULL, "illegal reply");
140 ret = -111; // protocol error
144 /* if channel was not accepted, try to get it */
145 ret = seize_bchannel(channel, 1); // exclusively
146 add_trace("channel", "available", ret<0?"no":"yes");
149 add_trace("conclusion", NULL, "replied channel not available");
153 add_trace("conclusion", NULL, "replied channel accepted");
154 add_trace("connect", "channel", "%d", p_m_b_channel);
157 /* activate channel given by remote */
158 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
162 /*** we sent 'any channel acceptable' ***/
164 /* if not first reply, we are done */
165 if (p_state != PORT_STATE_OUT_SETUP)
168 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
169 add_trace("channel", "request", "any");
170 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
171 /* if no channel was replied */
174 add_trace("conclusion", NULL, "no channel, protocol error");
176 ret = -111; // protocol error
180 /* we will see, if our received channel is available */
181 ret = seize_bchannel(channel, 1); // exclusively
182 add_trace("channel", "available", ret<0?"no":"yes");
185 add_trace("conclusion", NULL, "replied channel not available");
189 add_trace("conclusion", NULL, "replied channel accepted");
190 add_trace("connect", "channel", "%d", p_m_b_channel);
193 /* activate channel given by remote */
194 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
197 /*** we sent 'no channel available' ***/
199 /* if not the first reply, but a connect, we are forced */
200 if (cmd==MT_CONNECT && p_state!=PORT_STATE_OUT_SETUP)
202 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (connect)", DIRECTION_NONE);
203 add_trace("channel", "request", "no-channel");
204 add_trace("channel", "reply", (channel>=0)?"%d%s":"(none)", channel, exclusive?" (forced)":"");
207 goto use_from_connect;
209 ret = seize_bchannel(CHANNEL_ANY, 0); // any channel
210 add_trace("channel", "available", ret<0?"no":"yes");
213 add_trace("conclusion", NULL, "no channel available during call-waiting");
217 add_trace("conclusion", NULL, "using channel %d", p_m_b_channel);
218 add_trace("connect", "channel", "%d", p_m_b_channel);
220 p_m_b_exclusive = 1; // we are done
222 /* activate channel given by remote */
223 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
227 /* if not first reply, we are done */
228 if (p_state != PORT_STATE_OUT_SETUP)
231 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
232 add_trace("channel", "request", "no-channel");
233 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
234 /* if first reply has no channel, we are done */
237 add_trace("conclusion", NULL, "no channel until connect");
242 /* we will see, if our received channel is available */
244 ret = seize_bchannel(channel, exclusive);
245 add_trace("channel", "available", ret<0?"no":"yes");
248 add_trace("conclusion", NULL, "replied channel not available");
252 add_trace("conclusion", NULL, "replied channel accepted");
253 add_trace("connect", "channel", "%d", p_m_b_channel);
255 p_m_b_exclusive = 1; // we are done
257 /* activate channel given by remote */
258 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
264 * NOTE: we send MT_RELEASE_COMPLETE to "REJECT" the channel
265 * in response to the setup reply
267 l3m = create_l3msg();
268 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
269 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
271 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
272 new_state(PORT_STATE_RELEASE);
274 return(-34); /* to epoint: no channel available */
279 * hunt bchannel for incoming setup or retrieve or resume
281 int Pdss1::hunt_bchannel(int channel, int exclusive)
283 struct select_channel *selchannel;
284 struct interface_port *ifport = p_m_mISDNport->ifport;
287 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (setup)", DIRECTION_NONE);
290 if (channel == CHANNEL_NO)
291 add_trace("channel", "request", "no-channel");
293 add_trace("channel", "request", (channel>0)?"%d%s":"any", channel, exclusive?" (forced)":"");
294 if (channel==CHANNEL_NO && p_type==PORT_TYPE_DSS1_TE_IN)
296 add_trace("conclusion", NULL, "incoming call-waiting not supported for TE-mode");
298 return(-6); // channel unacceptable
300 if (channel <= 0) /* not given, no channel, whatever.. */
301 channel = CHANNEL_ANY; /* any channel */
302 add_trace("channel", "reserved", "%d", p_m_mISDNport->b_reserved);
303 if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num) // of out chan..
305 add_trace("conclusion", NULL, "all channels are reserved");
307 return(-34); // no channel
309 if (channel == CHANNEL_ANY)
313 /* check for given channel in selection list */
314 selchannel = ifport->in_channel;
317 if (selchannel->channel == channel || selchannel->channel == CHANNEL_FREE)
319 selchannel = selchannel->next;
324 /* exclusive channel requests must be in the list */
327 /* no exclusive channel */
330 add_trace("conclusion", NULL, "exclusively requested channel not in list");
332 return(-6); // channel unacceptable
334 /* get index for channel */
335 i = channel-1-(channel>=17);
336 if (i < 0 || i >= p_m_mISDNport->b_num || channel == 16)
338 add_trace("conclusion", NULL, "exclusively requested channel outside interface range");
340 return(-6); // channel unacceptable
343 if (p_m_mISDNport->b_port[i] == NULL)
345 add_trace("conclusion", NULL, "exclusively requested channel is busy");
347 return(-6); // channel unacceptable
350 /* requested channels in list will be used */
353 /* get index for channel */
354 i = channel-1-(channel>=17);
355 if (i < 0 || i >= p_m_mISDNport->b_num || channel == 16)
357 add_trace("info", NULL, "requested channel %d outside interface range", channel);
358 } else /* if inside range (else) check if available */
359 if (p_m_mISDNport->b_port[i] == NULL)
363 /* if channel is not available or not in list, it must be searched */
365 /* check for first free channel in list */
367 selchannel = ifport->in_channel;
370 switch(selchannel->channel)
372 case CHANNEL_FREE: /* free channel */
373 add_trace("hunting", "channel", "free");
374 if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num)
375 break; /* all channel in use or reserverd */
378 while(i < p_m_mISDNport->b_num)
380 if (p_m_mISDNport->b_port[i] == NULL)
382 channel = i+1+(i>=15);
390 add_trace("hunting", "channel", "%d", selchannel->channel);
391 if (selchannel->channel<1 || selchannel->channel==16)
392 break; /* invalid channels */
393 i = selchannel->channel-1-(selchannel->channel>=17);
394 if (i >= p_m_mISDNport->b_num)
395 break; /* channel not in port */
396 if (p_m_mISDNport->b_port[i] == NULL)
398 channel = selchannel->channel;
404 break; /* found channel */
405 selchannel = selchannel->next;
409 add_trace("conclusion", NULL, "no channel available");
411 return(-6); // channel unacceptable
415 add_trace("conclusion", NULL, "channel available");
416 add_trace("connect", "channel", "%d", channel);
422 * handles all indications
424 /* CC_SETUP INDICATION */
425 void Pdss1::setup_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
427 int calling_type, calling_plan, calling_present, calling_screen;
428 int calling_type2, calling_plan2, calling_present2, calling_screen2;
429 int called_type, called_plan;
430 int redir_type, redir_plan, redir_present, redir_screen, redir_reason;
431 int hlc_coding, hlc_presentation, hlc_interpretation, hlc_hlc, hlc_exthlc;
432 int bearer_coding, bearer_capability, bearer_mode, bearer_rate, bearer_multi, bearer_user;
433 int exclusive, channel;
435 unsigned char keypad[32] = "";
436 unsigned char useruser[128];
437 int useruser_len = 0, useruser_protocol;
438 class Endpoint *epoint;
439 struct lcr_msg *message;
441 /* process given callref */
442 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_IND, DIRECTION_IN);
443 add_trace("callref", "new", "0x%x", pid);
446 /* release in case the ID is already in use */
447 add_trace("error", NULL, "callref already in use");
449 l3m = create_l3msg();
450 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
451 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47);
452 add_trace("reason", NULL, "callref already in use");
454 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, pid, l3m);
455 new_state(PORT_STATE_RELEASE);
460 p_m_d_ces = pid >> 16;
463 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_IND, DIRECTION_IN);
464 dec_ie_calling_pn(l3m, &calling_type, &calling_plan, &calling_present, &calling_screen, (unsigned char *)p_callerinfo.id, sizeof(p_callerinfo.id), &calling_type2, &calling_plan2, &calling_present2, &calling_screen2, (unsigned char *)p_callerinfo.id2, sizeof(p_callerinfo.id2));
465 dec_ie_called_pn(l3m, &called_type, &called_plan, (unsigned char *)p_dialinginfo.id, sizeof(p_dialinginfo.id));
466 dec_ie_keypad(l3m, (unsigned char *)keypad, sizeof(keypad));
467 /* te-mode: CNIP (calling name identification presentation) */
468 dec_facility_centrex(l3m, (unsigned char *)p_callerinfo.name, sizeof(p_callerinfo.name));
469 dec_ie_useruser(l3m, &useruser_protocol, useruser, &useruser_len);
470 dec_ie_complete(l3m, &p_dialinginfo.sending_complete);
471 dec_ie_redir_nr(l3m, &redir_type, &redir_plan, &redir_present, &redir_screen, &redir_reason, (unsigned char *)p_redirinfo.id, sizeof(p_redirinfo.id));
472 dec_ie_channel_id(l3m, &exclusive, &channel);
473 dec_ie_hlc(l3m, &hlc_coding, &hlc_interpretation, &hlc_presentation, &hlc_hlc, &hlc_exthlc);
474 dec_ie_bearer(l3m, &bearer_coding, &bearer_capability, &bearer_mode, &bearer_rate, &bearer_multi, &bearer_user);
475 dec_ie_display(l3m, (unsigned char *)p_dialinginfo.display, sizeof(p_dialinginfo.display));
478 /* if blocked, release call with MT_RELEASE_COMPLETE */
479 if (p_m_mISDNport->ifport->block)
481 l3m = create_l3msg();
482 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
483 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 27); /* temporary unavailable */
484 add_trace("reason", NULL, "port blocked");
486 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
487 new_state(PORT_STATE_RELEASE);
493 switch (calling_present)
496 p_callerinfo.present = INFO_PRESENT_RESTRICTED;
499 p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
502 p_callerinfo.present = INFO_PRESENT_ALLOWED;
505 switch (calling_screen)
508 p_callerinfo.screen = INFO_SCREEN_USER;
511 p_callerinfo.screen = INFO_SCREEN_NETWORK;
514 switch (calling_type)
517 p_callerinfo.ntype = INFO_NTYPE_NOTPRESENT;
520 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
523 p_callerinfo.ntype = INFO_NTYPE_INTERNATIONAL;
526 p_callerinfo.ntype = INFO_NTYPE_NATIONAL;
529 p_callerinfo.ntype = INFO_NTYPE_SUBSCRIBER;
532 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
535 p_callerinfo.isdn_port = p_m_portnum;
536 SCPY(p_callerinfo.interface, p_m_mISDNport->ifport->interface->name);
539 switch (calling_present2)
542 p_callerinfo.present2 = INFO_PRESENT_RESTRICTED;
545 p_callerinfo.present2 = INFO_PRESENT_NOTAVAIL;
548 p_callerinfo.present2 = INFO_PRESENT_ALLOWED;
551 switch (calling_screen2)
554 p_callerinfo.screen2 = INFO_SCREEN_USER;
557 p_callerinfo.screen2 = INFO_SCREEN_NETWORK;
560 switch (calling_type2)
563 p_callerinfo.ntype2 = INFO_NTYPE_NOTPRESENT;
566 p_callerinfo.ntype2 = INFO_NTYPE_UNKNOWN;
569 p_callerinfo.ntype2 = INFO_NTYPE_INTERNATIONAL;
572 p_callerinfo.ntype2 = INFO_NTYPE_NATIONAL;
575 p_callerinfo.ntype2 = INFO_NTYPE_SUBSCRIBER;
578 p_callerinfo.ntype2 = INFO_NTYPE_UNKNOWN;
582 /* dialing information */
583 SCAT(p_dialinginfo.id, (char *)keypad);
587 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
590 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
593 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
596 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
601 switch (redir_present)
604 p_redirinfo.present = INFO_PRESENT_RESTRICTED;
607 p_redirinfo.present = INFO_PRESENT_NOTAVAIL;
610 p_redirinfo.present = INFO_PRESENT_ALLOWED;
613 switch (redir_screen)
616 p_redirinfo.screen = INFO_SCREEN_USER;
619 p_redirinfo.screen = INFO_SCREEN_NETWORK;
622 switch (redir_reason)
625 p_redirinfo.reason = INFO_REDIR_BUSY;
628 p_redirinfo.reason = INFO_REDIR_NORESPONSE;
631 p_redirinfo.reason = INFO_REDIR_UNCONDITIONAL;
634 p_redirinfo.reason = INFO_REDIR_CALLDEFLECT;
637 p_redirinfo.reason = INFO_REDIR_OUTOFORDER;
640 p_redirinfo.reason = INFO_REDIR_UNKNOWN;
646 p_redirinfo.ntype = INFO_NTYPE_NOTPRESENT;
649 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
652 p_redirinfo.ntype = INFO_NTYPE_INTERNATIONAL;
655 p_redirinfo.ntype = INFO_NTYPE_NATIONAL;
658 p_redirinfo.ntype = INFO_NTYPE_SUBSCRIBER;
661 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
664 p_redirinfo.isdn_port = p_m_portnum;
666 /* bearer capability */
667 switch (bearer_capability)
670 p_capainfo.bearer_capa = INFO_BC_AUDIO;
671 bearer_user = (options.law=='a')?3:2;
674 p_capainfo.bearer_capa = bearer_capability;
680 p_capainfo.bearer_mode = INFO_BMODE_PACKET;
683 p_capainfo.bearer_mode = INFO_BMODE_CIRCUIT;
689 p_capainfo.bearer_info1 = INFO_INFO1_NONE;
692 p_capainfo.bearer_info1 = bearer_user + 0x80;
700 p_capainfo.hlc = INFO_HLC_NONE;
703 p_capainfo.hlc = hlc_hlc + 0x80;
709 p_capainfo.exthlc = INFO_HLC_NONE;
712 p_capainfo.exthlc = hlc_exthlc + 0x80;
716 /* set bchannel mode */
717 if (p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED
718 || p_capainfo.bearer_capa==INFO_BC_DATARESTRICTED
719 || p_capainfo.bearer_capa==INFO_BC_VIDEO)
720 p_capainfo.source_mode = B_MODE_HDLC;
722 p_capainfo.source_mode = B_MODE_TRANSPARENT;
723 p_m_b_mode = p_capainfo.source_mode;
726 ret = channel = hunt_bchannel(channel, exclusive);
731 ret = seize_bchannel(channel, 1);
736 * NOTE: we send MT_RELEASE_COMPLETE to "REJECT" the channel
737 * in response to the setup
739 l3m = create_l3msg();
740 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
741 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
743 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
744 new_state(PORT_STATE_RELEASE);
748 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
750 /* create endpoint */
752 FATAL("Incoming call but already got an endpoint.\n");
753 if (!(epoint = new Endpoint(p_serial, 0)))
754 FATAL("No memory for Endpoint instance\n");
755 if (!(epoint->ep_app = new DEFAULT_ENDPOINT_APP(epoint, 0))) //incoming
756 FATAL("No memory for Endpoint Application instance\n");
757 epointlist_new(epoint->ep_serial);
759 /* send setup message to endpoit */
760 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_SETUP);
761 message->param.setup.isdn_port = p_m_portnum;
762 message->param.setup.port_type = p_type;
763 // message->param.setup.dtmf = !p_m_mISDNport->ifport->nodtmf;
764 memcpy(&message->param.setup.dialinginfo, &p_dialinginfo, sizeof(struct dialing_info));
765 memcpy(&message->param.setup.callerinfo, &p_callerinfo, sizeof(struct caller_info));
766 memcpy(&message->param.setup.redirinfo, &p_redirinfo, sizeof(struct redir_info));
767 memcpy(&message->param.setup.capainfo, &p_capainfo, sizeof(struct capa_info));
768 memcpy(message->param.setup.useruser.data, &useruser, useruser_len);
769 message->param.setup.useruser.len = useruser_len;
770 message->param.setup.useruser.protocol = useruser_protocol;
771 message_put(message);
773 new_state(PORT_STATE_IN_SETUP);
776 /* CC_INFORMATION INDICATION */
777 void Pdss1::information_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
780 unsigned char keypad[32] = "", display[128] = "";
781 struct lcr_msg *message;
783 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_IND, DIRECTION_IN);
784 dec_ie_called_pn(l3m, &type, &plan, (unsigned char *)p_dialinginfo.id, sizeof(p_dialinginfo.id));
785 dec_ie_keypad(l3m, (unsigned char *)keypad, sizeof(keypad));
786 dec_ie_display(l3m, (unsigned char *)display, sizeof(display));
787 dec_ie_complete(l3m, &p_dialinginfo.sending_complete);
790 SCAT(p_dialinginfo.id, (char *)keypad);
794 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
797 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
800 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
803 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
806 SCAT(p_dialinginfo.display, (char *)display);
807 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_INFORMATION);
808 memcpy(&message->param.information, &p_dialinginfo, sizeof(struct dialing_info));
809 message_put(message);
810 /* reset overlap timeout */
814 /* CC_SETUP_ACCNOWLEDGE INDICATION */
815 void Pdss1::setup_acknowledge_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
817 int exclusive, channel;
818 int coding, location, progress;
820 struct lcr_msg *message;
821 int max = p_m_mISDNport->ifport->dialmax;
825 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_ACKNOWLEDGE_IND, DIRECTION_IN);
826 dec_ie_channel_id(l3m, &exclusive, &channel);
827 dec_ie_progress(l3m, &coding, &location, &progress);
830 /* process channel */
831 ret = received_first_reply_to_setup(cmd, channel, exclusive);
834 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
835 message->param.disconnectinfo.cause = -ret;
836 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
837 message_put(message);
838 new_state(PORT_STATE_RELEASE);
843 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_OVERLAP);
844 message_put(message);
846 new_state(PORT_STATE_OUT_OVERLAP);
848 number = p_m_d_queue;
849 while (number[0]) /* as long we have something to dial */
851 if (max > strlen(number) || max == 0)
852 max = strlen(number);
854 nl3m = create_l3msg();
855 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
856 enc_ie_called_pn(nl3m, 0, 1, (unsigned char *)number, max);
858 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, nl3m);
861 p_m_d_queue[0] = '\0';
864 /* CC_PROCEEDING INDICATION */
865 void Pdss1::proceeding_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
867 int exclusive, channel;
868 int coding, location, progress;
870 struct lcr_msg *message;
871 int notify = -1, type, plan, present;
874 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_IND, DIRECTION_IN);
875 dec_ie_channel_id(l3m, &exclusive, &channel);
876 dec_ie_progress(l3m, &coding, &location, &progress);
877 dec_ie_notify(l3m, ¬ify);
878 dec_ie_redir_dn(l3m, &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
881 ret = received_first_reply_to_setup(cmd, channel, exclusive);
884 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
885 message->param.disconnectinfo.cause = -ret;
886 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
887 message_put(message);
888 new_state(PORT_STATE_RELEASE);
892 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROCEEDING);
893 message_put(message);
895 new_state(PORT_STATE_OUT_PROCEEDING);
901 if (type >= 0 || notify)
903 if (!notify && type >= 0)
905 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
906 message->param.notifyinfo.notify = notify;
907 SCPY(message->param.notifyinfo.id, redir);
908 /* redirection number */
912 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
915 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
918 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
924 message->param.notifyinfo.ntype = INFO_NTYPE_NOTPRESENT;
927 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
930 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
933 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
936 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
939 message->param.notifyinfo.isdn_port = p_m_portnum;
940 message_put(message);
944 /* CC_ALERTING INDICATION */
945 void Pdss1::alerting_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
947 int exclusive, channel;
948 int coding, location, progress;
950 struct lcr_msg *message;
951 int notify = -1, type, plan, present;
954 l1l2l3_trace_header(p_m_mISDNport, this, L3_ALERTING_IND, DIRECTION_IN);
955 dec_ie_channel_id(l3m, &exclusive, &channel);
956 dec_ie_progress(l3m, &coding, &location, &progress);
957 dec_ie_notify(l3m, ¬ify);
958 dec_ie_redir_dn(l3m, &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
961 /* process channel */
962 ret = received_first_reply_to_setup(cmd, channel, exclusive);
965 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
966 message->param.disconnectinfo.cause = -ret;
967 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
968 message_put(message);
969 new_state(PORT_STATE_RELEASE);
973 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_ALERTING);
974 message_put(message);
976 new_state(PORT_STATE_OUT_ALERTING);
982 if (type >= 0 || notify)
984 if (!notify && type >= 0)
986 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
987 message->param.notifyinfo.notify = notify;
988 SCPY(message->param.notifyinfo.id, redir);
992 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
995 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
998 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1004 message->param.notifyinfo.ntype = INFO_NTYPE_NOTPRESENT;
1007 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1010 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1013 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1016 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1019 message->param.notifyinfo.isdn_port = p_m_portnum;
1020 message_put(message);
1024 /* CC_CONNECT INDICATION */
1025 void Pdss1::connect_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1027 int exclusive, channel;
1028 int type, plan, present, screen;
1030 struct lcr_msg *message;
1031 int bchannel_before;
1033 l1l2l3_trace_header(p_m_mISDNport, this, L3_CONNECT_IND, DIRECTION_IN);
1034 dec_ie_channel_id(l3m, &exclusive, &channel);
1035 dec_ie_connected_pn(l3m, &type, &plan, &present, &screen, (unsigned char *)p_connectinfo.id, sizeof(p_connectinfo.id));
1036 dec_ie_display(l3m, (unsigned char *)p_connectinfo.display, sizeof(p_connectinfo.display));
1037 /* te-mode: CONP (connected name identification presentation) */
1038 dec_facility_centrex(l3m, (unsigned char *)p_connectinfo.name, sizeof(p_connectinfo.name));
1041 /* select channel */
1042 bchannel_before = p_m_b_channel;
1043 ret = received_first_reply_to_setup(cmd, channel, exclusive);
1046 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1047 message->param.disconnectinfo.cause = -ret;
1048 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1049 message_put(message);
1050 new_state(PORT_STATE_RELEASE);
1055 /* connect information */
1059 p_connectinfo.present = INFO_PRESENT_RESTRICTED;
1062 p_connectinfo.present = INFO_PRESENT_NOTAVAIL;
1065 p_connectinfo.present = INFO_PRESENT_ALLOWED;
1071 p_connectinfo.screen = INFO_SCREEN_USER;
1074 p_connectinfo.screen = INFO_SCREEN_NETWORK;
1080 p_connectinfo.ntype = INFO_NTYPE_NOTPRESENT;
1083 p_connectinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1086 p_connectinfo.ntype = INFO_NTYPE_NATIONAL;
1089 p_connectinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1092 p_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1095 p_connectinfo.isdn_port = p_m_portnum;
1096 SCPY(p_connectinfo.interface, p_m_mISDNport->ifport->interface->name);
1098 /* only in nt-mode we send connect ack. in te-mode it is done by stack itself or optional */
1101 /* send connect acknowledge */
1102 l3m = create_l3msg();
1103 l1l2l3_trace_header(p_m_mISDNport, this, L3_CONNECT_RES, DIRECTION_OUT);
1104 /* if we had no bchannel before, we send it now */
1105 if (!bchannel_before && p_m_b_channel)
1106 enc_ie_channel_id(l3m, 1, p_m_b_channel);
1108 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CONNECT_ACKNOWLEDGE, p_m_d_l3id, l3m);
1111 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CONNECT);
1112 memcpy(&message->param.connectinfo, &p_connectinfo, sizeof(struct connect_info));
1113 message_put(message);
1115 new_state(PORT_STATE_CONNECT);
1118 /* CC_DISCONNECT INDICATION */
1119 void Pdss1::disconnect_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1121 int location, cause;
1122 int coding, proglocation, progress;
1123 struct lcr_msg *message;
1124 unsigned char display[128] = "";
1126 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_IND, DIRECTION_IN);
1127 dec_ie_progress(l3m, &coding, &proglocation, &progress);
1128 dec_ie_cause(l3m, &location, &cause);
1129 dec_ie_display(l3m, (unsigned char *)display, sizeof(display));
1135 /* release if remote sends us no tones */
1136 if (!p_m_mISDNport->earlyb)
1140 l3m = create_l3msg();
1141 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_REQ, DIRECTION_OUT);
1142 enc_ie_cause(l3m, location, cause); /* normal */
1143 add_trace("reason", NULL, "no remote patterns");
1145 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE, p_m_d_l3id, l3m);
1147 /* sending release to endpoint */
1148 if (location == LOCATION_PRIVATE_LOCAL)
1149 location = LOCATION_PRIVATE_REMOTE;
1152 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1153 message->param.disconnectinfo.cause = cause;
1154 message->param.disconnectinfo.location = location;
1155 SCAT(message->param.disconnectinfo.display, (char *)display);
1156 message_put(message);
1158 free_epointlist(p_epointlist);
1160 new_state(PORT_STATE_RELEASE);
1165 /* sending disconnect to active endpoint and release to inactive endpoints */
1166 if (location == LOCATION_PRIVATE_LOCAL)
1167 location = LOCATION_PRIVATE_REMOTE;
1168 if (ACTIVE_EPOINT(p_epointlist))
1170 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DISCONNECT);
1171 message->param.disconnectinfo.location = location;
1172 message->param.disconnectinfo.cause = cause;
1173 SCAT(message->param.disconnectinfo.display, (char *)display);
1174 message_put(message);
1176 while(INACTIVE_EPOINT(p_epointlist))
1178 message = message_create(p_serial, INACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1179 message->param.disconnectinfo.location = location;
1180 message->param.disconnectinfo.cause = cause;
1181 SCAT(message->param.disconnectinfo.display, (char *)display);
1182 message_put(message);
1184 free_epointid(INACTIVE_EPOINT(p_epointlist));
1186 new_state(PORT_STATE_IN_DISCONNECT);
1189 /* CC_DISCONNECT INDICATION */
1190 void Pdss1::disconnect_ind_i(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1192 int location, cause;
1195 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_IND, DIRECTION_IN);
1196 if (p_m_d_collect_cause > 0)
1198 add_trace("old-cause", "location", "%d", p_m_d_collect_location);
1199 add_trace("old-cause", "value", "%d", p_m_d_collect_cause);
1201 dec_ie_cause(l3m, &location, &cause);
1202 if (location == LOCATION_PRIVATE_LOCAL)
1203 location = LOCATION_PRIVATE_REMOTE;
1206 collect_cause(&p_m_d_collect_cause, &p_m_d_collect_location, cause, location);
1207 add_trace("new-cause", "location", "%d", p_m_d_collect_location);
1208 add_trace("new-cause", "value", "%d", p_m_d_collect_cause);
1213 /* CC_RELEASE INDICATION */
1214 void Pdss1::release_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1216 int location, cause;
1217 struct lcr_msg *message;
1218 unsigned char display[128] = "";
1220 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_IND, DIRECTION_IN);
1221 dec_ie_cause(l3m, &location, &cause);
1222 dec_ie_display(l3m, (unsigned char *)display, sizeof(display));
1228 /* sending release to endpoint */
1229 if (location == LOCATION_PRIVATE_LOCAL)
1230 location = LOCATION_PRIVATE_REMOTE;
1233 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1234 message->param.disconnectinfo.cause = cause;
1235 message->param.disconnectinfo.location = location;
1236 SCAT(message->param.disconnectinfo.display, (char *)display);
1237 message_put(message);
1239 free_epointlist(p_epointlist);
1242 new_state(PORT_STATE_RELEASE);
1246 /* CC_RESTART INDICATION */
1247 void Pdss1::restart_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1249 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESTART_IND, DIRECTION_IN);
1252 // L3 process is not toucht. (not even by network stack)
1255 /* CC_RELEASE_COMPLETE INDICATION (a reject) */
1256 void Pdss1::release_complete_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1258 int location, cause;
1259 struct lcr_msg *message;
1261 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_IND, DIRECTION_IN);
1262 /* in case layer 2 is down during setup, we send cause 27 loc 5 */
1263 if (p_state == PORT_STATE_OUT_SETUP && p_m_mISDNport->l1link == 0)
1269 dec_ie_cause(l3m, &location, &cause);
1270 if (p_m_mISDNport->l1link < 0)
1271 add_trace("layer 1", NULL, "unknown");
1273 add_trace("layer 1", NULL, (p_m_mISDNport->l1link)?"up":"down");
1276 if (location == LOCATION_PRIVATE_LOCAL)
1277 location = LOCATION_PRIVATE_REMOTE;
1282 /* sending release to endpoint */
1285 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1286 message->param.disconnectinfo.cause = cause;
1287 message->param.disconnectinfo.location = location;
1288 message_put(message);
1290 free_epointlist(p_epointlist);
1293 new_state(PORT_STATE_RELEASE);
1298 void Pdss1::t312_timeout_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1300 // not required, release is performed with MT_FREE
1303 /* CC_NOTIFY INDICATION */
1304 void Pdss1::notify_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1306 struct lcr_msg *message;
1307 int notify, type, plan, present;
1308 unsigned char notifyid[sizeof(message->param.notifyinfo.id)];
1309 unsigned char display[128] = "";
1311 l1l2l3_trace_header(p_m_mISDNport, this, L3_NOTIFY_IND, DIRECTION_IN);
1312 dec_ie_notify(l3m, ¬ify);
1313 dec_ie_redir_dn(l3m, &type, &plan, &present, notifyid, sizeof(notifyid));
1314 dec_ie_display(l3m, (unsigned char *)display, sizeof(display));
1317 if (!ACTIVE_EPOINT(p_epointlist))
1319 /* notification indicator */
1323 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1324 message->param.notifyinfo.notify = notify;
1325 SCPY(message->param.notifyinfo.id, (char *)notifyid);
1326 /* redirection number */
1330 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1333 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1336 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1342 message->param.notifyinfo.ntype = INFO_NTYPE_NOTPRESENT;
1345 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1348 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1351 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1354 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1357 SCAT(message->param.notifyinfo.display, (char *)display);
1358 message->param.notifyinfo.isdn_port = p_m_portnum;
1359 message_put(message);
1363 /* CC_HOLD INDICATION */
1364 struct lcr_msg *message;
1365 void Pdss1::hold_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1367 // class Endpoint *epoint;
1369 l1l2l3_trace_header(p_m_mISDNport, this, L3_HOLD_IND, DIRECTION_IN);
1372 if (!ACTIVE_EPOINT(p_epointlist) || p_m_hold)
1374 l3m = create_l3msg();
1375 l1l2l3_trace_header(p_m_mISDNport, this, L3_HOLD_REJECT_REQ, DIRECTION_OUT);
1376 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, p_m_hold?101:31); /* normal unspecified / incompatible state */
1377 add_trace("reason", NULL, "no endpoint");
1379 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_HOLD_REJECT, p_m_d_l3id, l3m);
1384 /* notify the hold of call */
1385 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1386 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_HOLD;
1387 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1388 message_put(message);
1390 /* deactivate bchannel */
1391 chan_trace_header(p_m_mISDNport, this, "CHANNEL RELEASE (hold)", DIRECTION_NONE);
1392 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1396 /* set hold state */
1399 epoint = find_epoint_id(ACTIVE_EPOINT(p_epointlist));
1400 if (epoint && p_m_d_ntmode)
1402 p_m_timeout = p_settings.tout_hold;
1407 /* acknowledge hold */
1408 l3m = create_l3msg();
1409 l1l2l3_trace_header(p_m_mISDNport, this, L3_HOLD_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1411 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_HOLD_ACKNOWLEDGE, p_m_d_l3id, l3m);
1415 /* CC_RETRIEVE INDICATION */
1416 void Pdss1::retrieve_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1418 struct lcr_msg *message;
1419 int channel, exclusive, cause;
1422 l1l2l3_trace_header(p_m_mISDNport, this, L3_RETRIEVE_IND, DIRECTION_IN);
1423 dec_ie_channel_id(l3m, &exclusive, &channel);
1428 cause = 101; /* incompatible state */
1431 l3m = create_l3msg();
1432 l1l2l3_trace_header(p_m_mISDNport, this, L3_RETRIEVE_REJECT_REQ, DIRECTION_OUT);
1433 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, cause);
1435 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RETRIEVE_REJECT, p_m_d_l3id, l3m);
1440 /* notify the retrieve of call */
1441 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1442 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_RETRIEVAL;
1443 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1444 message_put(message);
1447 ret = channel = hunt_bchannel(channel, exclusive);
1452 ret = seize_bchannel(channel, 1);
1459 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
1461 /* set hold state */
1465 /* acknowledge retrieve */
1466 l3m = create_l3msg();
1467 l1l2l3_trace_header(p_m_mISDNport, this, L3_RETRIEVE_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1468 enc_ie_channel_id(l3m, 1, p_m_b_channel);
1470 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RETRIEVE_ACKNOWLEDGE, p_m_d_l3id, l3m);
1473 /* CC_SUSPEND INDICATION */
1474 void Pdss1::suspend_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1476 struct lcr_msg *message;
1477 class Endpoint *epoint;
1478 unsigned char callid[8];
1480 int ret = -31; /* normal, unspecified */
1482 l1l2l3_trace_header(p_m_mISDNport, this, L3_SUSPEND_IND, DIRECTION_IN);
1483 dec_ie_call_id(l3m, callid, &len);
1486 if (!ACTIVE_EPOINT(p_epointlist))
1489 l3m = create_l3msg();
1490 l1l2l3_trace_header(p_m_mISDNport, this, L3_SUSPEND_REJECT_REQ, DIRECTION_OUT);
1491 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1493 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SUSPEND_REJECT, p_m_d_l3id, l3m);
1500 /* check if call id is in use */
1501 epoint = epoint_first;
1504 if (epoint->ep_park)
1506 if (epoint->ep_park_len == len)
1507 if (!memcmp(epoint->ep_park_callid, callid, len))
1509 ret = -84; /* call id in use */
1513 epoint = epoint->next;
1516 /* notify the hold of call */
1517 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1518 message->param.notifyinfo.notify = INFO_NOTIFY_USER_SUSPENDED;
1519 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1520 message_put(message);
1522 /* deactivate bchannel */
1523 chan_trace_header(p_m_mISDNport, this, "CHANNEL RELEASE (suspend)", DIRECTION_NONE);
1524 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1528 /* sending suspend to endpoint */
1529 while (p_epointlist)
1531 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_SUSPEND);
1532 memcpy(message->param.parkinfo.callid, callid, sizeof(message->param.parkinfo.callid));
1533 message->param.parkinfo.len = len;
1534 message_put(message);
1536 free_epointlist(p_epointlist);
1539 /* sending SUSPEND_ACKNOWLEDGE */
1540 l3m = create_l3msg();
1541 l1l2l3_trace_header(p_m_mISDNport, this, L3_SUSPEND_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1543 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SUSPEND_ACKNOWLEDGE, p_m_d_l3id, l3m);
1545 new_state(PORT_STATE_RELEASE);
1549 /* CC_RESUME INDICATION */
1550 void Pdss1::resume_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1552 unsigned char callid[8];
1554 int channel, exclusive;
1555 class Endpoint *epoint;
1556 struct lcr_msg *message;
1559 /* process given callref */
1560 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_IND, DIRECTION_IN);
1561 add_trace("callref", "new", "0x%x", pid);
1564 /* release is case the ID is already in use */
1565 add_trace("error", NULL, "callref already in use");
1567 l3m = create_l3msg();
1568 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_REJECT_REQ, DIRECTION_OUT);
1569 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47);
1570 add_trace("reason", NULL, "callref already in use");
1572 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RESUME_REJECT, pid, l3m);
1573 new_state(PORT_STATE_RELEASE);
1578 p_m_d_ces = pid >> 16;
1581 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_IND, DIRECTION_IN);
1582 dec_ie_call_id(l3m, callid, &len);
1585 /* if blocked, release call */
1586 if (p_m_mISDNport->ifport->block)
1595 /* channel_id (no channel is possible in message) */
1597 channel = -1; /* any channel */
1600 ret = channel = hunt_bchannel(channel, exclusive);
1604 // mode (if hdlc parked) to be done. never mind, this is almost never requested
1606 ret = seize_bchannel(channel, 1);
1611 l3m = create_l3msg();
1612 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_REJECT_REQ, DIRECTION_OUT);
1613 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1615 add_trace("reason", NULL, "port blocked");
1617 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RESUME_REJECT, p_m_d_l3id, l3m);
1618 new_state(PORT_STATE_RELEASE);
1622 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
1624 /* create endpoint */
1626 FATAL("Incoming resume but already got an endpoint.\n");
1627 ret = -85; /* no call suspended */
1628 epoint = epoint_first;
1631 if (epoint->ep_park)
1633 ret = -83; /* suspended call exists, but this not */
1634 if (epoint->ep_park_len == len)
1635 if (!memcmp(epoint->ep_park_callid, callid, len))
1638 epoint = epoint->next;
1643 epointlist_new(epoint->ep_serial);
1644 if (!(epoint->portlist_new(p_serial, p_type, p_m_mISDNport->earlyb)))
1645 FATAL("No memory for portlist\n");
1646 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RESUME);
1647 message_put(message);
1649 /* notify the resume of call */
1650 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1651 message->param.notifyinfo.notify = INFO_NOTIFY_USER_RESUMED;
1652 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1653 message_put(message);
1655 /* sending RESUME_ACKNOWLEDGE */
1656 l3m = create_l3msg();
1657 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1658 enc_ie_channel_id(l3m, 1, p_m_b_channel);
1660 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RESUME_ACKNOWLEDGE, p_m_d_l3id, l3m);
1662 new_state(PORT_STATE_CONNECT);
1666 /* CC_FACILITY INDICATION */
1667 void Pdss1::facility_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1669 unsigned char facil[256];
1671 struct lcr_msg *message;
1673 l1l2l3_trace_header(p_m_mISDNport, this, L3_FACILITY_IND, DIRECTION_IN);
1674 dec_ie_facility(l3m, facil, &facil_len);
1681 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_FACILITY);
1682 message->param.facilityinfo.len = facil_len;
1683 memcpy(message->param.facilityinfo.data, facil, facil_len);
1684 message_put(message);
1689 * handler for isdn connections
1690 * incoming information are parsed and sent via message to the endpoint
1692 void Pdss1::message_isdn(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1701 PERROR("Pdss1(%s) timeout without cause.\n", p_name);
1704 if (l3m->cause[0] != 5)
1706 PERROR("Pdss1(%s) expecting timeout with timer diagnostic. (got len=%d)\n", p_name, l3m->cause[0]);
1709 timer = (l3m->cause[3]-'0')*100;
1710 timer += (l3m->cause[4]-'0')*10;
1711 timer += (l3m->cause[5]-'0');
1712 l1l2l3_trace_header(p_m_mISDNport, this, L3_TIMEOUT_IND, DIRECTION_IN);
1713 add_trace("timer", NULL, "%d", timer);
1716 t312_timeout_ind(cmd, pid, l3m);
1720 if (p_state != PORT_STATE_IDLE)
1722 setup_ind(cmd, pid, l3m);
1725 case MT_INFORMATION:
1726 information_ind(cmd, pid, l3m);
1729 case MT_SETUP_ACKNOWLEDGE:
1730 if (p_state != PORT_STATE_OUT_SETUP)
1732 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received setup_acknowledge, but we are not in outgoing setup state, IGNORING.\n", p_name);
1735 setup_acknowledge_ind(cmd, pid, l3m);
1738 case MT_CALL_PROCEEDING:
1739 if (p_state != PORT_STATE_OUT_SETUP
1740 && p_state != PORT_STATE_OUT_OVERLAP)
1742 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received proceeding, but we are not in outgoing setup OR overlap state, IGNORING.\n", p_name);
1745 proceeding_ind(cmd, pid, l3m);
1749 if (p_state != PORT_STATE_OUT_SETUP
1750 && p_state != PORT_STATE_OUT_OVERLAP
1751 && p_state != PORT_STATE_OUT_PROCEEDING)
1753 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding state, IGNORING.\n", p_name);
1756 alerting_ind(cmd, pid, l3m);
1760 if (p_state != PORT_STATE_OUT_SETUP
1761 && p_state != PORT_STATE_OUT_OVERLAP
1762 && p_state != PORT_STATE_OUT_PROCEEDING
1763 && p_state != PORT_STATE_OUT_ALERTING)
1765 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding OR ALERTING state, IGNORING.\n", p_name);
1768 connect_ind(cmd, pid, l3m);
1769 if (p_m_d_notify_pending)
1771 /* send pending notify message during connect */
1772 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
1773 message_free(p_m_d_notify_pending);
1774 p_m_d_notify_pending = NULL;
1778 case MT_CONNECT_ACKNOWLEDGE:
1779 if (p_state == PORT_STATE_CONNECT_WAITING)
1780 new_state(PORT_STATE_CONNECT);
1781 if (p_m_d_notify_pending)
1783 /* send pending notify message during connect-ack */
1784 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
1785 message_free(p_m_d_notify_pending);
1786 p_m_d_notify_pending = NULL;
1791 disconnect_ind(cmd, pid, l3m);
1795 release_ind(cmd, pid, l3m);
1798 case MT_RELEASE_COMPLETE:
1799 release_complete_ind(cmd, pid, l3m);
1803 restart_ind(cmd, pid, l3m);
1807 notify_ind(cmd, pid, l3m);
1811 hold_ind(cmd, pid, l3m);
1815 retrieve_ind(cmd, pid, l3m);
1819 suspend_ind(cmd, pid, l3m);
1823 resume_ind(cmd, pid, l3m);
1827 facility_ind(cmd, pid, l3m);
1831 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_L3ID_IND, DIRECTION_IN);
1832 add_trace("callref", NULL, "0x%x", p_m_d_l3id);
1837 /* sending release to endpoint in case we still have an endpoint
1838 * this is because we don't get any response if a release_complete is received (or a release in release state)
1840 while(p_epointlist) // only if not already released
1842 struct lcr_msg *message;
1843 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1844 if (p_m_d_collect_cause)
1846 message->param.disconnectinfo.cause = p_m_d_collect_cause;
1847 message->param.disconnectinfo.location = p_m_d_collect_location;
1850 message->param.disconnectinfo.cause = CAUSE_NOUSER;
1851 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1853 message_put(message);
1855 free_epointlist(p_epointlist);
1857 new_state(PORT_STATE_RELEASE);
1862 l1l2l3_trace_header(p_m_mISDNport, this, L3_UNKNOWN, DIRECTION_IN);
1863 add_trace("unhandled", "cmd", "0x%x", cmd);
1868 void Pdss1::new_state(int state)
1870 // class Endpoint *epoint;
1873 if (state == PORT_STATE_IN_OVERLAP)
1875 p_m_timeout = p_m_mISDNport->ifport->tout_dialing;
1878 if (state != p_state)
1880 if (state == PORT_STATE_IN_SETUP
1881 || state == PORT_STATE_OUT_SETUP
1882 || state == PORT_STATE_IN_OVERLAP
1883 || state == PORT_STATE_OUT_OVERLAP)
1885 p_m_timeout = p_m_mISDNport->ifport->tout_setup;
1888 if (state == PORT_STATE_IN_PROCEEDING
1889 || state == PORT_STATE_OUT_PROCEEDING)
1891 p_m_timeout = p_m_mISDNport->ifport->tout_proceeding;
1894 if (state == PORT_STATE_IN_ALERTING
1895 || state == PORT_STATE_OUT_ALERTING)
1897 p_m_timeout = p_m_mISDNport->ifport->tout_alerting;
1900 if (state == PORT_STATE_CONNECT
1901 || state == PORT_STATE_CONNECT_WAITING)
1905 if (state == PORT_STATE_IN_DISCONNECT
1906 || state == PORT_STATE_OUT_DISCONNECT)
1908 p_m_timeout = p_m_mISDNport->ifport->tout_disconnect;
1913 Port::new_state(state);
1920 int Pdss1::handler(void)
1924 if ((ret = PmISDN::handler()))
1927 /* handle destruction */
1928 if (p_m_delete && p_m_d_l3id==0)
1939 * handles all messages from endpoint
1941 /* MESSAGE_INFORMATION */
1942 void Pdss1::message_information(unsigned int epoint_id, int message_id, union parameter *param)
1945 char *display = param->information.display;
1946 char *number = param->information.id;
1947 int max = p_m_mISDNport->ifport->dialmax;
1949 while (number[0]) /* as long we have something to dial */
1951 if (max > strlen(number) || max == 0)
1952 max = strlen(number);
1954 l3m = create_l3msg();
1955 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
1956 enc_ie_called_pn(l3m, 0, 1, (unsigned char *)number, max);
1957 if ((p_m_d_ntmode || p_m_d_tespecial) && display[0]) {
1958 enc_ie_display(l3m, (unsigned char *)display);
1962 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
1972 void Pdss1::message_setup(unsigned int epoint_id, int message_id, union parameter *param)
1976 int plan, type, screen, present, reason;
1977 int plan2, type2, screen2, present2;
1978 int capability, mode, rate, coding, user, presentation, interpretation, hlc, exthlc;
1979 int channel, exclusive;
1980 struct epoint_list *epointlist;
1981 int max = p_m_mISDNport->ifport->dialmax;
1983 /* release if port is blocked */
1984 if (p_m_mISDNport->ifport->block)
1986 struct lcr_msg *message;
1988 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1989 message->param.disconnectinfo.cause = 27; // temp. unavail.
1990 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1991 message_put(message);
1992 new_state(PORT_STATE_RELEASE);
1997 /* copy setup infos to port */
1998 memcpy(&p_callerinfo, ¶m->setup.callerinfo, sizeof(p_callerinfo));
1999 memcpy(&p_dialinginfo, ¶m->setup.dialinginfo, sizeof(p_dialinginfo));
2000 memcpy(&p_capainfo, ¶m->setup.capainfo, sizeof(p_capainfo));
2001 memcpy(&p_redirinfo, ¶m->setup.redirinfo, sizeof(p_redirinfo));
2002 // SCPY(&p_m_tones_dir, param->setup.ext.tones_dir);
2003 /* screen outgoing caller id */
2004 do_screen(1, p_callerinfo.id, sizeof(p_callerinfo.id), &p_callerinfo.ntype, &p_callerinfo.present, p_m_mISDNport->ifport->interface);
2005 do_screen(1, p_callerinfo.id2, sizeof(p_callerinfo.id2), &p_callerinfo.ntype2, &p_callerinfo.present2, p_m_mISDNport->ifport->interface);
2007 /* only display at connect state: this case happens if endpoint is in connected mode */
2008 if (p_state==PORT_STATE_CONNECT)
2010 if (p_type!=PORT_TYPE_DSS1_NT_OUT
2011 && p_type!=PORT_TYPE_DSS1_NT_IN)
2013 if (p_callerinfo.display[0])
2015 /* sending information */
2016 l3m = create_l3msg();
2017 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
2018 if (p_m_d_ntmode || p_m_d_tespecial)
2019 enc_ie_display(l3m, (unsigned char *)p_callerinfo.display);
2021 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
2026 /* attach only if not already */
2027 epointlist = p_epointlist;
2030 if (epointlist->epoint_id == epoint_id)
2032 epointlist = epointlist->next;
2035 epointlist_new(epoint_id);
2041 channel = p_m_b_channel;
2042 exclusive = p_m_b_exclusive;
2044 channel = CHANNEL_ANY;
2045 /* nt-port with no channel, not reserverd */
2046 if (!p_m_b_channel && !p_m_b_reserve && p_type==PORT_TYPE_DSS1_NT_OUT)
2047 channel = CHANNEL_NO;
2050 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_REQ, DIRECTION_OUT);
2051 /* see MT_ASSIGN notes at do_layer3() */
2053 ret = p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_ASSIGN, 0, NULL);
2054 if (mt_assign_pid == 0 || ret < 0)
2056 struct lcr_msg *message;
2058 add_trace("callref", NULL, "no free id");
2060 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2061 message->param.disconnectinfo.cause = 47;
2062 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2063 message_put(message);
2064 new_state(PORT_STATE_RELEASE);
2068 p_m_d_l3id = mt_assign_pid;
2070 add_trace("callref", "new", "0x%x", p_m_d_l3id);
2073 /* preparing setup message */
2074 l3m = create_l3msg();
2075 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_REQ, DIRECTION_OUT);
2076 /* channel information */
2077 if (channel >= 0) /* it should */
2079 enc_ie_channel_id(l3m, exclusive, channel);
2081 /* caller information */
2083 switch (p_callerinfo.ntype)
2085 case INFO_NTYPE_UNKNOWN:
2088 case INFO_NTYPE_INTERNATIONAL:
2091 case INFO_NTYPE_NATIONAL:
2094 case INFO_NTYPE_SUBSCRIBER:
2097 default: /* INFO_NTYPE_NOTPRESENT */
2101 switch (p_callerinfo.screen)
2103 case INFO_SCREEN_USER:
2106 default: /* INFO_SCREEN_NETWORK */
2110 switch (p_callerinfo.present)
2112 case INFO_PRESENT_ALLOWED:
2115 case INFO_PRESENT_RESTRICTED:
2118 default: /* INFO_PRESENT_NOTAVAIL */
2122 /* caller information 2 */
2124 switch (p_callerinfo.ntype2)
2126 case INFO_NTYPE_UNKNOWN:
2129 case INFO_NTYPE_INTERNATIONAL:
2132 case INFO_NTYPE_NATIONAL:
2135 case INFO_NTYPE_SUBSCRIBER:
2138 default: /* INFO_NTYPE_NOTPRESENT */
2142 switch (p_callerinfo.screen2)
2144 case INFO_SCREEN_USER:
2147 default: /* INFO_SCREEN_NETWORK */
2151 switch (p_callerinfo.present2)
2153 case INFO_PRESENT_ALLOWED:
2156 case INFO_PRESENT_RESTRICTED:
2159 default: /* INFO_PRESENT_NOTAVAIL */
2164 enc_ie_calling_pn(l3m, type, plan, present, screen, (unsigned char *)p_callerinfo.id, type2, plan2, present2, screen2, (unsigned char *)p_callerinfo.id2);
2165 /* dialing information */
2166 if (p_dialinginfo.id[0]) /* only if we have something to dial */
2168 if (max > strlen(p_dialinginfo.id) || max == 0)
2169 max = strlen(p_dialinginfo.id);
2170 enc_ie_called_pn(l3m, 0, 1, (unsigned char *)p_dialinginfo.id, max);
2171 SCPY(p_m_d_queue, p_dialinginfo.id + max);
2173 /* sending complete */
2174 if (p_dialinginfo.sending_complete)
2175 enc_ie_complete(l3m, 1);
2176 /* sending user-user */
2177 if (param->setup.useruser.len)
2179 enc_ie_useruser(l3m, param->setup.useruser.protocol, param->setup.useruser.data, param->setup.useruser.len);
2181 /* redirecting number */
2183 switch (p_redirinfo.ntype)
2185 case INFO_NTYPE_UNKNOWN:
2188 case INFO_NTYPE_INTERNATIONAL:
2191 case INFO_NTYPE_NATIONAL:
2194 case INFO_NTYPE_SUBSCRIBER:
2197 default: /* INFO_NTYPE_NOTPRESENT */
2201 switch (p_redirinfo.screen)
2203 case INFO_SCREEN_USER:
2206 default: /* INFO_SCREE_NETWORK */
2210 switch (p_redirinfo.reason)
2212 case INFO_REDIR_BUSY:
2215 case INFO_REDIR_NORESPONSE:
2218 case INFO_REDIR_UNCONDITIONAL:
2221 case INFO_REDIR_CALLDEFLECT:
2224 case INFO_REDIR_OUTOFORDER:
2227 default: /* INFO_REDIR_UNKNOWN */
2231 switch (p_redirinfo.present)
2233 case INFO_PRESENT_ALLOWED:
2236 case INFO_PRESENT_RESTRICTED:
2239 default: /* INFO_PRESENT_NOTAVAIL */
2243 /* sending redirecting number only in ntmode */
2244 if (type >= 0 && (p_m_d_ntmode || p_m_d_tespecial))
2245 enc_ie_redir_nr(l3m, type, plan, present, screen, reason, (unsigned char *)p_redirinfo.id);
2246 /* bearer capability */
2247 //printf("hlc=%d\n",p_capainfo.hlc);
2249 capability = p_capainfo.bearer_capa;
2250 mode = p_capainfo.bearer_mode;
2251 rate = (mode==INFO_BMODE_CIRCUIT)?0x10:0x00;
2252 switch (p_capainfo.bearer_info1)
2254 case INFO_INFO1_NONE:
2258 user = p_capainfo.bearer_info1 & 0x7f;
2261 enc_ie_bearer(l3m, coding, capability, mode, rate, -1, user);
2268 hlc = p_capainfo.hlc & 0x7f;
2270 if (p_capainfo.exthlc)
2271 exthlc = p_capainfo.exthlc & 0x7f;
2272 enc_ie_hlc(l3m, coding, interpretation, presentation, hlc, exthlc);
2276 if (p_callerinfo.display[0] && (p_m_d_ntmode || p_m_d_tespecial))
2277 enc_ie_display(l3m, (unsigned char *)p_callerinfo.display);
2278 /* nt-mode: CNIP (calling name identification presentation) */
2279 // if (p_callerinfo.name[0] && (p_m_d_ntmode || p_m_d_tespecial))
2280 // enc_facility_centrex(&setup->FACILITY, dmsg, (unsigned char *)p_callerinfo.name, 1);
2283 /* send setup message now */
2284 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SETUP, p_m_d_l3id, l3m);
2286 new_state(PORT_STATE_OUT_SETUP);
2289 /* MESSAGE_FACILITY */
2290 void Pdss1::message_facility(unsigned int epoint_id, int message_id, union parameter *param)
2294 /* facility will not be sent to external lines */
2295 if (!p_m_d_ntmode && !p_m_d_tespecial)
2298 /* sending facility */
2299 l3m = create_l3msg();
2300 l1l2l3_trace_header(p_m_mISDNport, this, L3_FACILITY_REQ, DIRECTION_OUT);
2301 enc_ie_facility(l3m, (unsigned char *)param->facilityinfo.data, param->facilityinfo.len);
2303 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_FACILITY, p_m_d_l3id, l3m);
2306 /* MESSAGE_NOTIFY */
2307 void Pdss1::message_notify(unsigned int epoint_id, int message_id, union parameter *param)
2311 int plan = 0, type = -1, present = 0;
2313 if (param->notifyinfo.notify>INFO_NOTIFY_NONE)
2314 notify = param->notifyinfo.notify & 0x7f;
2317 if (p_state != PORT_STATE_CONNECT)
2319 /* notify only allowed in active state */
2325 switch (param->notifyinfo.ntype)
2327 case INFO_NTYPE_UNKNOWN:
2330 case INFO_NTYPE_INTERNATIONAL:
2333 case INFO_NTYPE_NATIONAL:
2336 case INFO_NTYPE_SUBSCRIBER:
2339 default: /* INFO_NTYPE_UNKNOWN */
2343 switch (param->notifyinfo.present)
2345 case INFO_PRESENT_ALLOWED:
2348 case INFO_PRESENT_RESTRICTED:
2351 default: /* INFO_PRESENT_NOTAVAIL */
2357 if (notify<0 && !param->notifyinfo.display[0])
2359 /* nothing to notify, nothing to display */
2365 if (p_state!=PORT_STATE_CONNECT)
2367 /* queue notification */
2368 if (p_m_d_notify_pending)
2369 message_free(p_m_d_notify_pending);
2370 p_m_d_notify_pending = message_create(ACTIVE_EPOINT(p_epointlist), p_serial, EPOINT_TO_PORT, message_id);
2371 memcpy(&p_m_d_notify_pending->param, param, sizeof(union parameter));
2374 /* sending notification */
2375 l3m = create_l3msg();
2376 l1l2l3_trace_header(p_m_mISDNport, this, L3_NOTIFY_REQ, DIRECTION_OUT);
2377 enc_ie_notify(l3m, notify);
2378 /* sending redirection number only in ntmode */
2379 if (type >= 0 && (p_m_d_ntmode || p_m_d_tespecial))
2380 enc_ie_redir_dn(l3m, type, plan, present, (unsigned char *)param->notifyinfo.id);
2381 if (param->notifyinfo.display[0] && (p_m_d_ntmode || p_m_d_tespecial))
2382 enc_ie_display(l3m, (unsigned char *)param->notifyinfo.display);
2384 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_NOTIFY, p_m_d_l3id, l3m);
2386 } else if (p_m_d_ntmode || p_m_d_tespecial)
2388 /* sending information */
2389 l3m = create_l3msg();
2390 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
2391 enc_ie_display(l3m, (unsigned char *)param->notifyinfo.display);
2393 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
2397 /* MESSAGE_OVERLAP */
2398 void Pdss1::message_overlap(unsigned int epoint_id, int message_id, union parameter *param)
2402 /* in case of sending complete, we proceed */
2403 if (p_dialinginfo.sending_complete)
2405 PDEBUG(DEBUG_ISDN, "sending proceeding instead of setup_acknowledge, because address is complete.\n");
2406 message_proceeding(epoint_id, message_id, param);
2410 /* sending setup_acknowledge */
2411 l3m = create_l3msg();
2412 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_ACKNOWLEDGE_REQ, DIRECTION_OUT);
2413 /* channel information */
2414 if (p_state == PORT_STATE_IN_SETUP)
2415 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2416 /* progress information */
2417 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2418 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2419 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2420 if (p_m_mISDNport->tones)
2421 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2423 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SETUP_ACKNOWLEDGE, p_m_d_l3id, l3m);
2425 new_state(PORT_STATE_IN_OVERLAP);
2428 /* MESSAGE_PROCEEDING */
2429 void Pdss1::message_proceeding(unsigned int epoint_id, int message_id, union parameter *param)
2433 /* sending proceeding */
2434 l3m = create_l3msg();
2435 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2436 /* channel information */
2437 if (p_state == PORT_STATE_IN_SETUP)
2438 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2439 /* progress information */
2440 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2441 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2442 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2443 if (p_m_mISDNport->tones)
2444 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2446 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2448 new_state(PORT_STATE_IN_PROCEEDING);
2451 /* MESSAGE_ALERTING */
2452 void Pdss1::message_alerting(unsigned int epoint_id, int message_id, union parameter *param)
2456 /* NT-MODE in setup state we must send PROCEEDING first */
2457 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2459 /* sending proceeding */
2460 l3m = create_l3msg();
2461 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2462 /* channel information */
2463 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2464 /* progress information */
2465 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2466 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2467 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2468 if (p_m_mISDNport->tones)
2469 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2471 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2472 new_state(PORT_STATE_IN_PROCEEDING);
2475 /* sending alerting */
2476 l3m = create_l3msg();
2477 l1l2l3_trace_header(p_m_mISDNport, this, L3_ALERTING_REQ, DIRECTION_OUT);
2478 /* channel information */
2479 if (p_state == PORT_STATE_IN_SETUP)
2480 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2481 /* progress information */
2482 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2483 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2484 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2485 if (p_m_mISDNport->tones)
2486 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2488 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_ALERTING, p_m_d_l3id, l3m);
2490 new_state(PORT_STATE_IN_ALERTING);
2493 /* MESSAGE_CONNECT */
2494 void Pdss1::message_connect(unsigned int epoint_id, int message_id, union parameter *param)
2497 int type, plan, present, screen;
2498 class Endpoint *epoint;
2500 /* NT-MODE in setup state we must send PROCEEDING first */
2501 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2503 /* sending proceeding */
2504 l3m = create_l3msg();
2505 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2506 /* channel information */
2507 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2509 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2510 new_state(PORT_STATE_IN_PROCEEDING);
2513 /* copy connected information */
2514 memcpy(&p_connectinfo, ¶m->connectinfo, sizeof(p_connectinfo));
2515 /* screen outgoing caller id */
2516 do_screen(1, p_connectinfo.id, sizeof(p_connectinfo.id), &p_connectinfo.ntype, &p_connectinfo.present, p_m_mISDNport->ifport->interface);
2518 /* only display at connect state */
2519 if (p_state == PORT_STATE_CONNECT)
2520 if (p_connectinfo.display[0])
2522 /* sending information */
2523 l3m = create_l3msg();
2524 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
2525 if (p_m_d_ntmode || p_m_d_tespecial)
2526 enc_ie_display(l3m, (unsigned char *)p_connectinfo.display);
2528 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
2532 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)
2534 /* connect command only possible in setup, proceeding or alerting state */
2538 /* preparing connect message */
2539 l3m = create_l3msg();
2540 l1l2l3_trace_header(p_m_mISDNport, this, L3_CONNECT_REQ, DIRECTION_OUT);
2541 /* connect information */
2543 switch (p_connectinfo.ntype)
2545 case INFO_NTYPE_UNKNOWN:
2548 case INFO_NTYPE_INTERNATIONAL:
2551 case INFO_NTYPE_NATIONAL:
2554 case INFO_NTYPE_SUBSCRIBER:
2557 default: /* INFO_NTYPE_NOTPRESENT */
2561 switch (param->connectinfo.screen)
2563 case INFO_SCREEN_USER:
2566 default: /* INFO_SCREE_NETWORK */
2570 switch (p_connectinfo.present)
2572 case INFO_PRESENT_ALLOWED:
2575 case INFO_PRESENT_RESTRICTED:
2578 default: /* INFO_PRESENT_NOTAVAIL */
2583 enc_ie_connected_pn(l3m, type, plan, present, screen, (unsigned char *)p_connectinfo.id);
2585 if (p_connectinfo.display[0] && (p_m_d_ntmode || p_m_d_tespecial))
2586 enc_ie_display(l3m, (unsigned char *)p_connectinfo.display);
2587 /* nt-mode: CONP (connected name identification presentation) */
2588 // if (p_connectinfo.name[0] && (p_m_d_ntmode || p_m_d_tespecial))
2589 // enc_facility_centrex(&connect->FACILITY, dmsg, (unsigned char *)p_connectinfo.name, 0);
2591 if (p_m_d_ntmode || p_m_d_tespecial)
2593 epoint = find_epoint_id(epoint_id);
2594 enc_ie_date(l3m, now, p_settings.no_seconds);
2597 /* finally send message */
2598 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CONNECT, p_m_d_l3id, l3m);
2601 new_state(PORT_STATE_CONNECT);
2603 new_state(PORT_STATE_CONNECT_WAITING);
2607 /* MESSAGE_DISCONNECT */
2608 void Pdss1::message_disconnect(unsigned int epoint_id, int message_id, union parameter *param)
2611 struct lcr_msg *message;
2614 /* we reject during incoming setup when we have no tones. also if we are in outgoing setup state */
2615 // if ((p_state==PORT_STATE_IN_SETUP && !p_m_mISDNport->tones)
2616 if (/* ||*/ p_state==PORT_STATE_OUT_SETUP)
2618 /* sending release to endpoint */
2621 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
2622 memcpy(&message->param, param, sizeof(union parameter));
2623 message_put(message);
2625 free_epointlist(p_epointlist);
2627 /* sending release */
2628 l3m = create_l3msg();
2629 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
2631 enc_ie_cause(l3m, (!p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_REMOTE:param->disconnectinfo.location, param->disconnectinfo.cause);
2633 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
2634 new_state(PORT_STATE_RELEASE);
2639 /* workarround: NT-MODE in setup state we must send PROCEEDING first to make it work */
2640 if (p_state==PORT_STATE_IN_SETUP)
2642 /* sending proceeding */
2643 l3m = create_l3msg();
2644 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2645 /* channel information */
2646 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2647 /* progress information */
2648 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2649 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2650 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2651 if (p_m_mISDNport->tones)
2652 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2654 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2655 new_state(PORT_STATE_IN_PROCEEDING);
2658 /* sending disconnect */
2659 l3m = create_l3msg();
2660 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_REQ, DIRECTION_OUT);
2661 /* progress information */
2662 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2663 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2664 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2665 if (p_m_mISDNport->tones)
2666 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2668 enc_ie_cause(l3m, (!p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_REMOTE:param->disconnectinfo.location, param->disconnectinfo.cause);
2670 if (param->disconnectinfo.display[0])
2671 p = param->disconnectinfo.display;
2672 if (p) if (*p && (p_m_d_ntmode || p_m_d_tespecial))
2673 enc_ie_display(l3m, (unsigned char *)p);
2675 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_DISCONNECT, p_m_d_l3id, l3m);
2676 new_state(PORT_STATE_OUT_DISCONNECT);
2679 /* MESSAGE_RELEASE */
2680 void Pdss1::message_release(unsigned int epoint_id, int message_id, union parameter *param)
2683 class Endpoint *epoint;
2687 * we may only release during incoming disconnect state.
2688 * this means that the endpoint doesnt require audio anymore
2690 if (p_state == PORT_STATE_IN_DISCONNECT
2691 || p_state == PORT_STATE_OUT_DISCONNECT)
2693 /* sending release */
2694 l3m = create_l3msg();
2695 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_REQ, DIRECTION_OUT);
2697 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2699 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE, p_m_d_l3id, l3m);
2700 new_state(PORT_STATE_RELEASE);
2702 free_epointid(epoint_id);
2703 // wait for callref to be released
2708 * if we are on incoming call setup, we may reject by sending a release_complete
2709 * also on outgoing call setup, we send a release complete, BUT this is not conform. (i don't know any other way)
2711 if (p_state==PORT_STATE_IN_SETUP
2712 || p_state==PORT_STATE_OUT_SETUP)
2714 //#warning remove me
2715 //PDEBUG(DEBUG_LOG, "JOLLY sending release complete %d\n", p_serial);
2716 /* sending release complete */
2717 l3m = create_l3msg();
2718 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_REQ, DIRECTION_OUT);
2720 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2722 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
2723 new_state(PORT_STATE_RELEASE);
2725 free_epointid(epoint_id);
2726 // wait for callref to be released
2731 wirklich erst proceeding?:
2732 /* NT-MODE in setup state we must send PROCEEDING first */
2733 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2735 CALL_PROCEEDING_t *proceeding;
2737 /* sending proceeding */
2738 l3m = create_l3msg();
2739 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2740 /* channel information */
2741 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2742 /* progress information */
2743 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2744 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2745 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2746 if (p_m_mISDNport->tones)
2747 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2749 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2753 /* sending disconnect */
2754 l3m = create_l3msg();
2755 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_REQ, DIRECTION_OUT);
2756 /* progress information */
2757 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2758 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2759 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2760 if (p_m_mISDNport->tones)
2761 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2763 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2765 epoint = find_epoint_id(epoint_id);
2766 if (param->disconnectinfo.display[0])
2767 p = param->disconnectinfo.display;
2768 if (p) if (*p && (p_m_d_ntmode || p_m_d_tespecial))
2769 enc_ie_display(l3m, (unsigned char *)p);
2771 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_DISCONNECT, p_m_d_l3id, l3m);
2772 new_state(PORT_STATE_OUT_DISCONNECT);
2774 free_epointid(epoint_id);
2775 // wait for release and callref to be released
2776 //#warning remove me
2777 //PDEBUG(DEBUG_LOG, "JOLLY sending disconnect %d\n", p_serial);
2782 * endpoint sends messages to the port
2784 int Pdss1::message_epoint(unsigned int epoint_id, int message_id, union parameter *param)
2786 if (PmISDN::message_epoint(epoint_id, message_id, param))
2791 case MESSAGE_INFORMATION: /* overlap dialing */
2792 if (p_type==PORT_TYPE_DSS1_NT_OUT
2793 && p_state!=PORT_STATE_OUT_OVERLAP
2794 && p_state!=PORT_STATE_CONNECT
2795 && p_state!=PORT_STATE_OUT_DISCONNECT
2796 && p_state!=PORT_STATE_IN_DISCONNECT)
2800 if (p_type==PORT_TYPE_DSS1_TE_OUT
2801 && p_state!=PORT_STATE_OUT_OVERLAP
2802 && p_state!=PORT_STATE_OUT_PROCEEDING
2803 && p_state!=PORT_STATE_OUT_ALERTING
2804 && p_state!=PORT_STATE_CONNECT
2805 && p_state!=PORT_STATE_OUT_DISCONNECT
2806 && p_state!=PORT_STATE_IN_DISCONNECT)
2810 if ((p_type==PORT_TYPE_DSS1_NT_IN || p_type==PORT_TYPE_DSS1_TE_IN)
2811 && p_state!=PORT_STATE_IN_OVERLAP
2812 && p_state!=PORT_STATE_IN_PROCEEDING
2813 && p_state!=PORT_STATE_IN_ALERTING
2814 && p_state!=PORT_STATE_CONNECT
2815 && p_state!=PORT_STATE_CONNECT_WAITING
2816 && p_state!=PORT_STATE_OUT_DISCONNECT
2817 && p_state!=PORT_STATE_IN_DISCONNECT)
2821 message_information(epoint_id, message_id, param);
2824 case MESSAGE_SETUP: /* dial-out command received from epoint */
2825 if (p_state!=PORT_STATE_IDLE
2826 && p_state!=PORT_STATE_CONNECT)
2828 PERROR("Pdss1(%s) ignoring setup because isdn port is not in idle state (or connected for sending display info).\n", p_name);
2831 if (p_epointlist && p_state==PORT_STATE_IDLE)
2832 FATAL("Pdss1(%s): epoint pointer is set in idle state, how bad!!\n", p_name);
2833 message_setup(epoint_id, message_id, param);
2836 case MESSAGE_NOTIFY: /* display and notifications */
2837 message_notify(epoint_id, message_id, param);
2840 case MESSAGE_FACILITY: /* facility message */
2841 message_facility(epoint_id, message_id, param);
2844 case MESSAGE_OVERLAP: /* more information is needed */
2845 if (p_state!=PORT_STATE_IN_SETUP)
2849 message_overlap(epoint_id, message_id, param);
2852 case MESSAGE_PROCEEDING: /* call of endpoint is proceeding */
2853 if (p_state!=PORT_STATE_IN_SETUP
2854 && p_state!=PORT_STATE_IN_OVERLAP)
2858 message_proceeding(epoint_id, message_id, param);
2861 case MESSAGE_ALERTING: /* call of endpoint is ringing */
2862 if (p_state!=PORT_STATE_IN_SETUP
2863 && p_state!=PORT_STATE_IN_OVERLAP
2864 && p_state!=PORT_STATE_IN_PROCEEDING)
2868 message_alerting(epoint_id, message_id, param);
2871 case MESSAGE_CONNECT: /* call of endpoint is connected */
2872 if (p_state!=PORT_STATE_IN_SETUP
2873 && p_state!=PORT_STATE_IN_OVERLAP
2874 && p_state!=PORT_STATE_IN_PROCEEDING
2875 && p_state!=PORT_STATE_IN_ALERTING
2876 && !(p_state==PORT_STATE_CONNECT && p_m_d_ntmode))
2880 message_connect(epoint_id, message_id, param);
2883 case MESSAGE_DISCONNECT: /* call has been disconnected */
2884 if (p_state!=PORT_STATE_IN_SETUP
2885 && p_state!=PORT_STATE_IN_OVERLAP
2886 && p_state!=PORT_STATE_IN_PROCEEDING
2887 && p_state!=PORT_STATE_IN_ALERTING
2888 && p_state!=PORT_STATE_OUT_SETUP
2889 && p_state!=PORT_STATE_OUT_OVERLAP
2890 && p_state!=PORT_STATE_OUT_PROCEEDING
2891 && p_state!=PORT_STATE_OUT_ALERTING
2892 && p_state!=PORT_STATE_CONNECT
2893 && p_state!=PORT_STATE_CONNECT_WAITING)
2897 message_disconnect(epoint_id, message_id, param);
2900 case MESSAGE_RELEASE: /* release isdn port */
2901 if (p_state==PORT_STATE_RELEASE)
2905 message_release(epoint_id, message_id, param);
2909 PERROR("Pdss1(%s) isdn port with (caller id %s) received a wrong message: %d\n", p_name, p_callerinfo.id, message_id);
2918 * data from isdn-stack (layer-3) to pbx (port class)
2920 int stack2manager(struct mISDNport *mISDNport, unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
2926 PDEBUG(DEBUG_ISDN, "cmd(0x%x) pid(0x%x)\n", cmd, pid);
2930 PDEBUG(DEBUG_ISDN, "ignoring dummy process from phone.\n");
2934 /* find Port object of type ISDN */
2939 if ((port->p_type & PORT_CLASS_mISDN_MASK) == PORT_CLASS_mISDN_DSS1)
2941 pdss1 = (class Pdss1 *)port;
2942 /* check out correct stack and id */
2943 if (pdss1->p_m_mISDNport == mISDNport)
2945 if (pdss1->p_m_d_l3id & MISDN_PID_CR_FLAG)
2947 /* local callref, so match value only */
2948 if ((pdss1->p_m_d_l3id & MISDN_PID_CRVAL_MASK) == (pid & MISDN_PID_CRVAL_MASK))
2952 /* remote callref, ref + channel id */
2953 if (pdss1->p_m_d_l3id == pid)
2961 /* aktueller prozess */
2964 if (cmd == MT_ASSIGN)
2966 /* stack gives us new layer 3 id (during connect) */
2967 l1l2l3_trace_header(mISDNport, pdss1, L3_NEW_L3ID_IND, DIRECTION_IN);
2968 add_trace("callref", "old", "0x%x", pdss1->p_m_d_l3id);
2969 /* nt-library now gives us a new id via CC_SETUP_CONFIRM */
2970 if ((pdss1->p_m_d_l3id&MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER)
2971 PERROR(" strange setup-procid 0x%x\n", pdss1->p_m_d_l3id);
2972 pdss1->p_m_d_l3id = pid;
2973 if (port->p_state == PORT_STATE_CONNECT)
2974 pdss1->p_m_d_ces = pid >> 16;
2975 add_trace("callref", "new", "0x%x", pdss1->p_m_d_l3id);
2979 /* if process id is master process, but a child disconnects */
2980 if (mISDNport->ntmode
2981 && (pid & MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER
2982 && (pdss1->p_m_d_l3id & MISDN_PID_CRTYPE_MASK) == MISDN_PID_MASTER)
2984 if (cmd == MT_DISCONNECT
2985 || cmd == MT_RELEASE)
2987 /* send special indication for child disconnect */
2988 pdss1->disconnect_ind_i(cmd, pid, l3m);
2991 if (cmd == MT_RELEASE_COMPLETE)
2994 /* if we have child pid and got different child pid message, ignore */
2995 if (mISDNport->ntmode
2996 && (pid & MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER
2997 && (pdss1->p_m_d_l3id & MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER
2998 && pid != pdss1->p_m_d_l3id)
3001 /* process message */
3002 pdss1->message_isdn(cmd, pid, l3m);
3010 /* creating port object, transparent until setup with hdlc */
3011 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3012 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0, B_MODE_TRANSPARENT)))
3014 FATAL("Cannot create Port instance.\n");
3015 pdss1->message_isdn(cmd, pid, l3m);
3019 /* creating port object, transparent until setup with hdlc */
3020 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3021 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0, B_MODE_TRANSPARENT)))
3022 FATAL("Cannot create Port instance.\n");
3023 pdss1->message_isdn(cmd, pid, l3m);
3027 PDEBUG(DEBUG_ISDN, "unused call ref released (l3id=0x%x)\n", pid);
3030 case MT_RELEASE_COMPLETE:
3031 PERROR("must be ignored by stack, not sent to app\n");
3035 // facility als broadcast
3039 PERROR("unhandled message: cmd(0x%x) pid(0x%x)\n", cmd, pid);
3043 if (port->p_type == PORT_TYPE_DSS1_NT_IN || port->p_type == PORT_TYPE_DSS1_NT_OUT)
3045 pdss1 = (class Pdss1 *)port;
3046 /* check out correct stack */
3047 if (pdss1->p_m_mISDNport == mISDNport)
3048 /* check out correct id */
3049 PERROR("unhandled message: pid=%x is not associated with port-dinfo=%x\n", pid, pdss1->p_m_d_l3id);