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);
1688 /* CC_PROGRESS INDICATION */
1689 void Pdss1::progress_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1691 unsigned char facil[256];
1693 struct lcr_msg *message;
1694 int coding, location, progress;
1696 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROGRESS_IND, DIRECTION_IN);
1697 dec_ie_progress(l3m, &coding, &location, &progress);
1703 * handler for isdn connections
1704 * incoming information are parsed and sent via message to the endpoint
1706 void Pdss1::message_isdn(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1715 PERROR("Pdss1(%s) timeout without cause.\n", p_name);
1718 if (l3m->cause[0] != 5)
1720 PERROR("Pdss1(%s) expecting timeout with timer diagnostic. (got len=%d)\n", p_name, l3m->cause[0]);
1723 timer = (l3m->cause[3]-'0')*100;
1724 timer += (l3m->cause[4]-'0')*10;
1725 timer += (l3m->cause[5]-'0');
1726 l1l2l3_trace_header(p_m_mISDNport, this, L3_TIMEOUT_IND, DIRECTION_IN);
1727 add_trace("timer", NULL, "%d", timer);
1730 t312_timeout_ind(cmd, pid, l3m);
1734 if (p_state != PORT_STATE_IDLE)
1736 setup_ind(cmd, pid, l3m);
1739 case MT_INFORMATION:
1740 information_ind(cmd, pid, l3m);
1743 case MT_SETUP_ACKNOWLEDGE:
1744 if (p_state != PORT_STATE_OUT_SETUP)
1746 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received setup_acknowledge, but we are not in outgoing setup state, IGNORING.\n", p_name);
1749 setup_acknowledge_ind(cmd, pid, l3m);
1752 case MT_CALL_PROCEEDING:
1753 if (p_state != PORT_STATE_OUT_SETUP
1754 && p_state != PORT_STATE_OUT_OVERLAP)
1756 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received proceeding, but we are not in outgoing setup OR overlap state, IGNORING.\n", p_name);
1759 proceeding_ind(cmd, pid, l3m);
1763 if (p_state != PORT_STATE_OUT_SETUP
1764 && p_state != PORT_STATE_OUT_OVERLAP
1765 && p_state != PORT_STATE_OUT_PROCEEDING)
1767 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding state, IGNORING.\n", p_name);
1770 alerting_ind(cmd, pid, l3m);
1774 if (p_state != PORT_STATE_OUT_SETUP
1775 && p_state != PORT_STATE_OUT_OVERLAP
1776 && p_state != PORT_STATE_OUT_PROCEEDING
1777 && p_state != PORT_STATE_OUT_ALERTING)
1779 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);
1782 connect_ind(cmd, pid, l3m);
1783 if (p_m_d_notify_pending)
1785 /* send pending notify message during connect */
1786 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
1787 message_free(p_m_d_notify_pending);
1788 p_m_d_notify_pending = NULL;
1792 case MT_CONNECT_ACKNOWLEDGE:
1793 if (p_state == PORT_STATE_CONNECT_WAITING)
1794 new_state(PORT_STATE_CONNECT);
1795 if (p_m_d_notify_pending)
1797 /* send pending notify message during connect-ack */
1798 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
1799 message_free(p_m_d_notify_pending);
1800 p_m_d_notify_pending = NULL;
1805 disconnect_ind(cmd, pid, l3m);
1809 release_ind(cmd, pid, l3m);
1812 case MT_RELEASE_COMPLETE:
1813 release_complete_ind(cmd, pid, l3m);
1817 restart_ind(cmd, pid, l3m);
1821 notify_ind(cmd, pid, l3m);
1825 hold_ind(cmd, pid, l3m);
1829 retrieve_ind(cmd, pid, l3m);
1833 suspend_ind(cmd, pid, l3m);
1837 resume_ind(cmd, pid, l3m);
1841 facility_ind(cmd, pid, l3m);
1845 progress_ind(cmd, pid, l3m);
1849 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_L3ID_IND, DIRECTION_IN);
1850 add_trace("callref", NULL, "0x%x", p_m_d_l3id);
1855 /* sending release to endpoint in case we still have an endpoint
1856 * this is because we don't get any response if a release_complete is received (or a release in release state)
1858 while(p_epointlist) // only if not already released
1860 struct lcr_msg *message;
1861 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1862 if (p_m_d_collect_cause)
1864 message->param.disconnectinfo.cause = p_m_d_collect_cause;
1865 message->param.disconnectinfo.location = p_m_d_collect_location;
1868 message->param.disconnectinfo.cause = CAUSE_NOUSER;
1869 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1871 message_put(message);
1873 free_epointlist(p_epointlist);
1875 new_state(PORT_STATE_RELEASE);
1880 l1l2l3_trace_header(p_m_mISDNport, this, L3_UNKNOWN_IND, DIRECTION_IN);
1881 add_trace("unhandled", "cmd", "0x%x", cmd);
1886 void Pdss1::new_state(int state)
1888 // class Endpoint *epoint;
1891 if (state == PORT_STATE_IN_OVERLAP)
1893 p_m_timeout = p_m_mISDNport->ifport->tout_dialing;
1896 if (state != p_state)
1898 if (state == PORT_STATE_IN_SETUP
1899 || state == PORT_STATE_OUT_SETUP
1900 || state == PORT_STATE_IN_OVERLAP
1901 || state == PORT_STATE_OUT_OVERLAP)
1903 p_m_timeout = p_m_mISDNport->ifport->tout_setup;
1906 if (state == PORT_STATE_IN_PROCEEDING
1907 || state == PORT_STATE_OUT_PROCEEDING)
1909 p_m_timeout = p_m_mISDNport->ifport->tout_proceeding;
1912 if (state == PORT_STATE_IN_ALERTING
1913 || state == PORT_STATE_OUT_ALERTING)
1915 p_m_timeout = p_m_mISDNport->ifport->tout_alerting;
1918 if (state == PORT_STATE_CONNECT
1919 || state == PORT_STATE_CONNECT_WAITING)
1923 if (state == PORT_STATE_IN_DISCONNECT
1924 || state == PORT_STATE_OUT_DISCONNECT)
1926 p_m_timeout = p_m_mISDNport->ifport->tout_disconnect;
1931 Port::new_state(state);
1938 int Pdss1::handler(void)
1942 if ((ret = PmISDN::handler()))
1945 /* handle destruction */
1946 if (p_m_delete && p_m_d_l3id==0)
1957 * handles all messages from endpoint
1959 /* MESSAGE_INFORMATION */
1960 void Pdss1::message_information(unsigned int epoint_id, int message_id, union parameter *param)
1963 char *display = param->information.display;
1964 char *number = param->information.id;
1965 int max = p_m_mISDNport->ifport->dialmax;
1967 while (number[0]) /* as long we have something to dial */
1969 if (max > strlen(number) || max == 0)
1970 max = strlen(number);
1972 l3m = create_l3msg();
1973 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
1974 enc_ie_called_pn(l3m, 0, 1, (unsigned char *)number, max);
1975 if ((p_m_d_ntmode || p_m_d_tespecial) && display[0]) {
1976 enc_ie_display(l3m, (unsigned char *)display);
1980 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
1990 void Pdss1::message_setup(unsigned int epoint_id, int message_id, union parameter *param)
1994 int plan, type, screen, present, reason;
1995 int plan2, type2, screen2, present2;
1996 int capability, mode, rate, coding, user, presentation, interpretation, hlc, exthlc;
1997 int channel, exclusive;
1998 struct epoint_list *epointlist;
1999 int max = p_m_mISDNport->ifport->dialmax;
2001 /* release if port is blocked */
2002 if (p_m_mISDNport->ifport->block)
2004 struct lcr_msg *message;
2006 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2007 message->param.disconnectinfo.cause = 27; // temp. unavail.
2008 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2009 message_put(message);
2010 new_state(PORT_STATE_RELEASE);
2015 /* copy setup infos to port */
2016 memcpy(&p_callerinfo, ¶m->setup.callerinfo, sizeof(p_callerinfo));
2017 memcpy(&p_dialinginfo, ¶m->setup.dialinginfo, sizeof(p_dialinginfo));
2018 memcpy(&p_capainfo, ¶m->setup.capainfo, sizeof(p_capainfo));
2019 memcpy(&p_redirinfo, ¶m->setup.redirinfo, sizeof(p_redirinfo));
2020 // SCPY(&p_m_tones_dir, param->setup.ext.tones_dir);
2021 /* screen outgoing caller id */
2022 do_screen(1, p_callerinfo.id, sizeof(p_callerinfo.id), &p_callerinfo.ntype, &p_callerinfo.present, p_m_mISDNport->ifport->interface);
2023 do_screen(1, p_callerinfo.id2, sizeof(p_callerinfo.id2), &p_callerinfo.ntype2, &p_callerinfo.present2, p_m_mISDNport->ifport->interface);
2025 /* only display at connect state: this case happens if endpoint is in connected mode */
2026 if (p_state==PORT_STATE_CONNECT)
2028 if (p_type!=PORT_TYPE_DSS1_NT_OUT
2029 && p_type!=PORT_TYPE_DSS1_NT_IN)
2031 if (p_callerinfo.display[0])
2033 /* sending information */
2034 l3m = create_l3msg();
2035 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
2036 if (p_m_d_ntmode || p_m_d_tespecial)
2037 enc_ie_display(l3m, (unsigned char *)p_callerinfo.display);
2039 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
2044 /* attach only if not already */
2045 epointlist = p_epointlist;
2048 if (epointlist->epoint_id == epoint_id)
2050 epointlist = epointlist->next;
2053 epointlist_new(epoint_id);
2059 channel = p_m_b_channel;
2060 exclusive = p_m_b_exclusive;
2062 channel = CHANNEL_ANY;
2063 /* nt-port with no channel, not reserverd */
2064 if (!p_m_b_channel && !p_m_b_reserve && p_type==PORT_TYPE_DSS1_NT_OUT)
2065 channel = CHANNEL_NO;
2068 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_REQ, DIRECTION_OUT);
2069 /* see MT_ASSIGN notes at do_layer3() */
2071 ret = p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_ASSIGN, 0, NULL);
2072 if (mt_assign_pid == 0 || ret < 0)
2074 struct lcr_msg *message;
2076 add_trace("callref", NULL, "no free id");
2078 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2079 message->param.disconnectinfo.cause = 47;
2080 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2081 message_put(message);
2082 new_state(PORT_STATE_RELEASE);
2086 p_m_d_l3id = mt_assign_pid;
2088 add_trace("callref", "new", "0x%x", p_m_d_l3id);
2091 /* preparing setup message */
2092 l3m = create_l3msg();
2093 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_REQ, DIRECTION_OUT);
2094 /* channel information */
2095 if (channel >= 0) /* it should */
2097 enc_ie_channel_id(l3m, exclusive, channel);
2099 /* caller information */
2101 switch (p_callerinfo.ntype)
2103 case INFO_NTYPE_UNKNOWN:
2106 case INFO_NTYPE_INTERNATIONAL:
2109 case INFO_NTYPE_NATIONAL:
2112 case INFO_NTYPE_SUBSCRIBER:
2115 default: /* INFO_NTYPE_NOTPRESENT */
2119 switch (p_callerinfo.screen)
2121 case INFO_SCREEN_USER:
2124 default: /* INFO_SCREEN_NETWORK */
2128 switch (p_callerinfo.present)
2130 case INFO_PRESENT_ALLOWED:
2133 case INFO_PRESENT_RESTRICTED:
2136 default: /* INFO_PRESENT_NOTAVAIL */
2140 /* caller information 2 */
2142 switch (p_callerinfo.ntype2)
2144 case INFO_NTYPE_UNKNOWN:
2147 case INFO_NTYPE_INTERNATIONAL:
2150 case INFO_NTYPE_NATIONAL:
2153 case INFO_NTYPE_SUBSCRIBER:
2156 default: /* INFO_NTYPE_NOTPRESENT */
2160 switch (p_callerinfo.screen2)
2162 case INFO_SCREEN_USER:
2165 default: /* INFO_SCREEN_NETWORK */
2169 switch (p_callerinfo.present2)
2171 case INFO_PRESENT_ALLOWED:
2174 case INFO_PRESENT_RESTRICTED:
2177 default: /* INFO_PRESENT_NOTAVAIL */
2182 enc_ie_calling_pn(l3m, type, plan, present, screen, (unsigned char *)p_callerinfo.id, type2, plan2, present2, screen2, (unsigned char *)p_callerinfo.id2);
2183 /* dialing information */
2184 if (p_dialinginfo.id[0]) /* only if we have something to dial */
2186 if (max > strlen(p_dialinginfo.id) || max == 0)
2187 max = strlen(p_dialinginfo.id);
2188 enc_ie_called_pn(l3m, 0, 1, (unsigned char *)p_dialinginfo.id, max);
2189 SCPY(p_m_d_queue, p_dialinginfo.id + max);
2191 /* sending complete */
2192 if (p_dialinginfo.sending_complete)
2193 enc_ie_complete(l3m, 1);
2194 /* sending user-user */
2195 if (param->setup.useruser.len)
2197 enc_ie_useruser(l3m, param->setup.useruser.protocol, param->setup.useruser.data, param->setup.useruser.len);
2199 /* redirecting number */
2201 switch (p_redirinfo.ntype)
2203 case INFO_NTYPE_UNKNOWN:
2206 case INFO_NTYPE_INTERNATIONAL:
2209 case INFO_NTYPE_NATIONAL:
2212 case INFO_NTYPE_SUBSCRIBER:
2215 default: /* INFO_NTYPE_NOTPRESENT */
2219 switch (p_redirinfo.screen)
2221 case INFO_SCREEN_USER:
2224 default: /* INFO_SCREE_NETWORK */
2228 switch (p_redirinfo.reason)
2230 case INFO_REDIR_BUSY:
2233 case INFO_REDIR_NORESPONSE:
2236 case INFO_REDIR_UNCONDITIONAL:
2239 case INFO_REDIR_CALLDEFLECT:
2242 case INFO_REDIR_OUTOFORDER:
2245 default: /* INFO_REDIR_UNKNOWN */
2249 switch (p_redirinfo.present)
2251 case INFO_PRESENT_ALLOWED:
2254 case INFO_PRESENT_RESTRICTED:
2257 default: /* INFO_PRESENT_NOTAVAIL */
2261 /* sending redirecting number only in ntmode */
2262 if (type >= 0 && (p_m_d_ntmode || p_m_d_tespecial))
2263 enc_ie_redir_nr(l3m, type, plan, present, screen, reason, (unsigned char *)p_redirinfo.id);
2264 /* bearer capability */
2265 //printf("hlc=%d\n",p_capainfo.hlc);
2267 capability = p_capainfo.bearer_capa;
2268 mode = p_capainfo.bearer_mode;
2269 rate = (mode==INFO_BMODE_CIRCUIT)?0x10:0x00;
2270 switch (p_capainfo.bearer_info1)
2272 case INFO_INFO1_NONE:
2276 user = p_capainfo.bearer_info1 & 0x7f;
2279 enc_ie_bearer(l3m, coding, capability, mode, rate, -1, user);
2286 hlc = p_capainfo.hlc & 0x7f;
2288 if (p_capainfo.exthlc)
2289 exthlc = p_capainfo.exthlc & 0x7f;
2290 enc_ie_hlc(l3m, coding, interpretation, presentation, hlc, exthlc);
2294 if (p_callerinfo.display[0] && (p_m_d_ntmode || p_m_d_tespecial))
2295 enc_ie_display(l3m, (unsigned char *)p_callerinfo.display);
2296 /* nt-mode: CNIP (calling name identification presentation) */
2297 // if (p_callerinfo.name[0] && (p_m_d_ntmode || p_m_d_tespecial))
2298 // enc_facility_centrex(&setup->FACILITY, dmsg, (unsigned char *)p_callerinfo.name, 1);
2301 /* send setup message now */
2302 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SETUP, p_m_d_l3id, l3m);
2304 new_state(PORT_STATE_OUT_SETUP);
2307 /* MESSAGE_FACILITY */
2308 void Pdss1::message_facility(unsigned int epoint_id, int message_id, union parameter *param)
2312 /* facility will not be sent to external lines */
2313 if (!p_m_d_ntmode && !p_m_d_tespecial)
2316 /* sending facility */
2317 l3m = create_l3msg();
2318 l1l2l3_trace_header(p_m_mISDNport, this, L3_FACILITY_REQ, DIRECTION_OUT);
2319 enc_ie_facility(l3m, (unsigned char *)param->facilityinfo.data, param->facilityinfo.len);
2321 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_FACILITY, p_m_d_l3id, l3m);
2324 /* MESSAGE_NOTIFY */
2325 void Pdss1::message_notify(unsigned int epoint_id, int message_id, union parameter *param)
2329 int plan = 0, type = -1, present = 0;
2331 printf("if = %d\n", param->notifyinfo.notify);
2332 if (param->notifyinfo.notify>INFO_NOTIFY_NONE)
2333 notify = param->notifyinfo.notify & 0x7f;
2339 switch (param->notifyinfo.ntype)
2341 case INFO_NTYPE_UNKNOWN:
2344 case INFO_NTYPE_INTERNATIONAL:
2347 case INFO_NTYPE_NATIONAL:
2350 case INFO_NTYPE_SUBSCRIBER:
2353 default: /* INFO_NTYPE_UNKNOWN */
2357 switch (param->notifyinfo.present)
2359 case INFO_PRESENT_ALLOWED:
2362 case INFO_PRESENT_RESTRICTED:
2365 default: /* INFO_PRESENT_NOTAVAIL */
2371 if (notify<0 && !param->notifyinfo.display[0])
2373 /* nothing to notify, nothing to display */
2379 if (p_state!=PORT_STATE_CONNECT && p_state!=PORT_STATE_IN_PROCEEDING && p_state!=PORT_STATE_IN_ALERTING)
2381 /* queue notification */
2382 if (p_m_d_notify_pending)
2383 message_free(p_m_d_notify_pending);
2384 p_m_d_notify_pending = message_create(ACTIVE_EPOINT(p_epointlist), p_serial, EPOINT_TO_PORT, message_id);
2385 memcpy(&p_m_d_notify_pending->param, param, sizeof(union parameter));
2388 /* sending notification */
2389 l3m = create_l3msg();
2390 l1l2l3_trace_header(p_m_mISDNport, this, L3_NOTIFY_REQ, DIRECTION_OUT);
2391 enc_ie_notify(l3m, notify);
2392 /* sending redirection number only in ntmode */
2393 if (type >= 0 && (p_m_d_ntmode || p_m_d_tespecial))
2394 enc_ie_redir_dn(l3m, type, plan, present, (unsigned char *)param->notifyinfo.id);
2395 if (param->notifyinfo.display[0] && (p_m_d_ntmode || p_m_d_tespecial))
2396 enc_ie_display(l3m, (unsigned char *)param->notifyinfo.display);
2398 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_NOTIFY, p_m_d_l3id, l3m);
2400 } else if (p_m_d_ntmode || p_m_d_tespecial)
2402 /* sending information */
2403 l3m = create_l3msg();
2404 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
2405 enc_ie_display(l3m, (unsigned char *)param->notifyinfo.display);
2407 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
2411 /* MESSAGE_OVERLAP */
2412 void Pdss1::message_overlap(unsigned int epoint_id, int message_id, union parameter *param)
2416 /* in case of sending complete, we proceed */
2417 if (p_dialinginfo.sending_complete)
2419 PDEBUG(DEBUG_ISDN, "sending proceeding instead of setup_acknowledge, because address is complete.\n");
2420 message_proceeding(epoint_id, message_id, param);
2424 /* sending setup_acknowledge */
2425 l3m = create_l3msg();
2426 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_ACKNOWLEDGE_REQ, DIRECTION_OUT);
2427 /* channel information */
2428 if (p_state == PORT_STATE_IN_SETUP)
2429 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2430 /* progress information */
2431 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2432 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2433 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2434 if (p_m_mISDNport->tones)
2435 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2437 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SETUP_ACKNOWLEDGE, p_m_d_l3id, l3m);
2439 new_state(PORT_STATE_IN_OVERLAP);
2442 /* MESSAGE_PROCEEDING */
2443 void Pdss1::message_proceeding(unsigned int epoint_id, int message_id, union parameter *param)
2447 /* sending proceeding */
2448 l3m = create_l3msg();
2449 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2450 /* channel information */
2451 if (p_state == PORT_STATE_IN_SETUP)
2452 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2453 /* progress information */
2454 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2455 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2456 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2457 if (p_m_mISDNport->tones)
2458 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2460 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2462 new_state(PORT_STATE_IN_PROCEEDING);
2465 /* MESSAGE_ALERTING */
2466 void Pdss1::message_alerting(unsigned int epoint_id, int message_id, union parameter *param)
2470 /* NT-MODE in setup state we must send PROCEEDING first */
2471 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2473 /* sending proceeding */
2474 l3m = create_l3msg();
2475 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2476 /* channel information */
2477 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2478 /* progress information */
2479 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2480 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2481 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2482 if (p_m_mISDNport->tones)
2483 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2485 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2486 new_state(PORT_STATE_IN_PROCEEDING);
2489 /* sending alerting */
2490 l3m = create_l3msg();
2491 l1l2l3_trace_header(p_m_mISDNport, this, L3_ALERTING_REQ, DIRECTION_OUT);
2492 /* channel information */
2493 if (p_state == PORT_STATE_IN_SETUP)
2494 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2495 /* progress information */
2496 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2497 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2498 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2499 if (p_m_mISDNport->tones)
2500 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2502 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_ALERTING, p_m_d_l3id, l3m);
2504 new_state(PORT_STATE_IN_ALERTING);
2507 /* MESSAGE_CONNECT */
2508 void Pdss1::message_connect(unsigned int epoint_id, int message_id, union parameter *param)
2511 int type, plan, present, screen;
2512 class Endpoint *epoint;
2514 /* NT-MODE in setup state we must send PROCEEDING first */
2515 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2517 /* sending proceeding */
2518 l3m = create_l3msg();
2519 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2520 /* channel information */
2521 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2523 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2524 new_state(PORT_STATE_IN_PROCEEDING);
2527 /* copy connected information */
2528 memcpy(&p_connectinfo, ¶m->connectinfo, sizeof(p_connectinfo));
2529 /* screen outgoing caller id */
2530 do_screen(1, p_connectinfo.id, sizeof(p_connectinfo.id), &p_connectinfo.ntype, &p_connectinfo.present, p_m_mISDNport->ifport->interface);
2532 /* only display at connect state */
2533 if (p_state == PORT_STATE_CONNECT)
2534 if (p_connectinfo.display[0])
2536 /* sending information */
2537 l3m = create_l3msg();
2538 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
2539 if (p_m_d_ntmode || p_m_d_tespecial)
2540 enc_ie_display(l3m, (unsigned char *)p_connectinfo.display);
2542 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
2546 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)
2548 /* connect command only possible in setup, proceeding or alerting state */
2552 /* preparing connect message */
2553 l3m = create_l3msg();
2554 l1l2l3_trace_header(p_m_mISDNport, this, L3_CONNECT_REQ, DIRECTION_OUT);
2555 /* connect information */
2557 switch (p_connectinfo.ntype)
2559 case INFO_NTYPE_UNKNOWN:
2562 case INFO_NTYPE_INTERNATIONAL:
2565 case INFO_NTYPE_NATIONAL:
2568 case INFO_NTYPE_SUBSCRIBER:
2571 default: /* INFO_NTYPE_NOTPRESENT */
2575 switch (param->connectinfo.screen)
2577 case INFO_SCREEN_USER:
2580 default: /* INFO_SCREE_NETWORK */
2584 switch (p_connectinfo.present)
2586 case INFO_PRESENT_ALLOWED:
2589 case INFO_PRESENT_RESTRICTED:
2592 default: /* INFO_PRESENT_NOTAVAIL */
2597 enc_ie_connected_pn(l3m, type, plan, present, screen, (unsigned char *)p_connectinfo.id);
2599 if (p_connectinfo.display[0] && (p_m_d_ntmode || p_m_d_tespecial))
2600 enc_ie_display(l3m, (unsigned char *)p_connectinfo.display);
2601 /* nt-mode: CONP (connected name identification presentation) */
2602 // if (p_connectinfo.name[0] && (p_m_d_ntmode || p_m_d_tespecial))
2603 // enc_facility_centrex(&connect->FACILITY, dmsg, (unsigned char *)p_connectinfo.name, 0);
2605 if (p_m_d_ntmode || p_m_d_tespecial)
2607 epoint = find_epoint_id(epoint_id);
2608 enc_ie_date(l3m, now, p_settings.no_seconds);
2611 /* finally send message */
2612 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CONNECT, p_m_d_l3id, l3m);
2615 new_state(PORT_STATE_CONNECT);
2617 new_state(PORT_STATE_CONNECT_WAITING);
2621 /* MESSAGE_DISCONNECT */
2622 void Pdss1::message_disconnect(unsigned int epoint_id, int message_id, union parameter *param)
2625 struct lcr_msg *message;
2628 /* we reject during incoming setup when we have no tones. also if we are in outgoing setup state */
2629 // if ((p_state==PORT_STATE_IN_SETUP && !p_m_mISDNport->tones)
2630 if (/* ||*/ p_state==PORT_STATE_OUT_SETUP)
2632 /* sending release to endpoint */
2635 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
2636 memcpy(&message->param, param, sizeof(union parameter));
2637 message_put(message);
2639 free_epointlist(p_epointlist);
2641 /* sending release */
2642 l3m = create_l3msg();
2643 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
2645 enc_ie_cause(l3m, (!p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_REMOTE:param->disconnectinfo.location, param->disconnectinfo.cause);
2647 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
2648 new_state(PORT_STATE_RELEASE);
2653 /* workarround: NT-MODE in setup state we must send PROCEEDING first to make it work */
2654 if (p_state==PORT_STATE_IN_SETUP)
2656 /* sending proceeding */
2657 l3m = create_l3msg();
2658 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2659 /* channel information */
2660 enc_ie_channel_id(l3m, 1, p_m_b_channel);
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 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2669 new_state(PORT_STATE_IN_PROCEEDING);
2672 /* sending disconnect */
2673 l3m = create_l3msg();
2674 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_REQ, DIRECTION_OUT);
2675 /* progress information */
2676 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2677 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2678 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2679 if (p_m_mISDNport->tones)
2680 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2682 enc_ie_cause(l3m, (!p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_REMOTE:param->disconnectinfo.location, param->disconnectinfo.cause);
2684 if (param->disconnectinfo.display[0])
2685 p = param->disconnectinfo.display;
2686 if (p) if (*p && (p_m_d_ntmode || p_m_d_tespecial))
2687 enc_ie_display(l3m, (unsigned char *)p);
2689 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_DISCONNECT, p_m_d_l3id, l3m);
2690 new_state(PORT_STATE_OUT_DISCONNECT);
2693 /* MESSAGE_RELEASE */
2694 void Pdss1::message_release(unsigned int epoint_id, int message_id, union parameter *param)
2697 class Endpoint *epoint;
2701 * we may only release during incoming disconnect state.
2702 * this means that the endpoint doesnt require audio anymore
2704 if (p_state == PORT_STATE_IN_DISCONNECT
2705 || p_state == PORT_STATE_OUT_DISCONNECT)
2707 /* sending release */
2708 l3m = create_l3msg();
2709 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_REQ, DIRECTION_OUT);
2711 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2713 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE, p_m_d_l3id, l3m);
2714 new_state(PORT_STATE_RELEASE);
2716 free_epointid(epoint_id);
2717 // wait for callref to be released
2722 * if we are on incoming call setup, we may reject by sending a release_complete
2723 * also on outgoing call setup, we send a release complete, BUT this is not conform. (i don't know any other way)
2725 if (p_state==PORT_STATE_IN_SETUP
2726 || p_state==PORT_STATE_OUT_SETUP)
2728 //#warning remove me
2729 //PDEBUG(DEBUG_LOG, "JOLLY sending release complete %d\n", p_serial);
2730 /* sending release complete */
2731 l3m = create_l3msg();
2732 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_REQ, DIRECTION_OUT);
2734 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2736 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
2737 new_state(PORT_STATE_RELEASE);
2739 free_epointid(epoint_id);
2740 // wait for callref to be released
2745 wirklich erst proceeding?:
2746 /* NT-MODE in setup state we must send PROCEEDING first */
2747 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2749 CALL_PROCEEDING_t *proceeding;
2751 /* sending proceeding */
2752 l3m = create_l3msg();
2753 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2754 /* channel information */
2755 enc_ie_channel_id(l3m, 1, p_m_b_channel);
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 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2767 /* sending disconnect */
2768 l3m = create_l3msg();
2769 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_REQ, DIRECTION_OUT);
2770 /* progress information */
2771 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2772 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2773 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2774 if (p_m_mISDNport->tones)
2775 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2777 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2779 epoint = find_epoint_id(epoint_id);
2780 if (param->disconnectinfo.display[0])
2781 p = param->disconnectinfo.display;
2782 if (p) if (*p && (p_m_d_ntmode || p_m_d_tespecial))
2783 enc_ie_display(l3m, (unsigned char *)p);
2785 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_DISCONNECT, p_m_d_l3id, l3m);
2786 new_state(PORT_STATE_OUT_DISCONNECT);
2788 free_epointid(epoint_id);
2789 // wait for release and callref to be released
2790 //#warning remove me
2791 //PDEBUG(DEBUG_LOG, "JOLLY sending disconnect %d\n", p_serial);
2796 * endpoint sends messages to the port
2798 int Pdss1::message_epoint(unsigned int epoint_id, int message_id, union parameter *param)
2800 if (PmISDN::message_epoint(epoint_id, message_id, param))
2805 case MESSAGE_INFORMATION: /* overlap dialing */
2806 if (p_type==PORT_TYPE_DSS1_NT_OUT
2807 && p_state!=PORT_STATE_OUT_OVERLAP
2808 && p_state!=PORT_STATE_CONNECT
2809 && p_state!=PORT_STATE_OUT_DISCONNECT
2810 && p_state!=PORT_STATE_IN_DISCONNECT)
2814 if (p_type==PORT_TYPE_DSS1_TE_OUT
2815 && p_state!=PORT_STATE_OUT_OVERLAP
2816 && p_state!=PORT_STATE_OUT_PROCEEDING
2817 && p_state!=PORT_STATE_OUT_ALERTING
2818 && p_state!=PORT_STATE_CONNECT
2819 && p_state!=PORT_STATE_OUT_DISCONNECT
2820 && p_state!=PORT_STATE_IN_DISCONNECT)
2824 if ((p_type==PORT_TYPE_DSS1_NT_IN || p_type==PORT_TYPE_DSS1_TE_IN)
2825 && p_state!=PORT_STATE_IN_OVERLAP
2826 && p_state!=PORT_STATE_IN_PROCEEDING
2827 && p_state!=PORT_STATE_IN_ALERTING
2828 && p_state!=PORT_STATE_CONNECT
2829 && p_state!=PORT_STATE_CONNECT_WAITING
2830 && p_state!=PORT_STATE_OUT_DISCONNECT
2831 && p_state!=PORT_STATE_IN_DISCONNECT)
2835 message_information(epoint_id, message_id, param);
2838 case MESSAGE_SETUP: /* dial-out command received from epoint */
2839 if (p_state!=PORT_STATE_IDLE
2840 && p_state!=PORT_STATE_CONNECT)
2842 PERROR("Pdss1(%s) ignoring setup because isdn port is not in idle state (or connected for sending display info).\n", p_name);
2845 if (p_epointlist && p_state==PORT_STATE_IDLE)
2846 FATAL("Pdss1(%s): epoint pointer is set in idle state, how bad!!\n", p_name);
2847 message_setup(epoint_id, message_id, param);
2850 case MESSAGE_NOTIFY: /* display and notifications */
2851 message_notify(epoint_id, message_id, param);
2854 case MESSAGE_FACILITY: /* facility message */
2855 message_facility(epoint_id, message_id, param);
2858 case MESSAGE_OVERLAP: /* more information is needed */
2859 if (p_state!=PORT_STATE_IN_SETUP)
2863 message_overlap(epoint_id, message_id, param);
2866 case MESSAGE_PROCEEDING: /* call of endpoint is proceeding */
2867 if (p_state!=PORT_STATE_IN_SETUP
2868 && p_state!=PORT_STATE_IN_OVERLAP)
2872 message_proceeding(epoint_id, message_id, param);
2873 if (p_m_d_notify_pending)
2875 /* send pending notify message during connect */
2876 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2877 message_free(p_m_d_notify_pending);
2878 p_m_d_notify_pending = NULL;
2882 case MESSAGE_ALERTING: /* call of endpoint is ringing */
2883 if (p_state!=PORT_STATE_IN_SETUP
2884 && p_state!=PORT_STATE_IN_OVERLAP
2885 && p_state!=PORT_STATE_IN_PROCEEDING)
2889 message_alerting(epoint_id, message_id, param);
2890 if (p_m_d_notify_pending)
2892 /* send pending notify message during connect */
2893 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2894 message_free(p_m_d_notify_pending);
2895 p_m_d_notify_pending = NULL;
2899 case MESSAGE_CONNECT: /* call of endpoint is connected */
2900 if (p_state!=PORT_STATE_IN_SETUP
2901 && p_state!=PORT_STATE_IN_OVERLAP
2902 && p_state!=PORT_STATE_IN_PROCEEDING
2903 && p_state!=PORT_STATE_IN_ALERTING
2904 && !(p_state==PORT_STATE_CONNECT && p_m_d_ntmode))
2908 message_connect(epoint_id, message_id, param);
2909 if (p_m_d_notify_pending)
2911 /* send pending notify message during connect */
2912 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2913 message_free(p_m_d_notify_pending);
2914 p_m_d_notify_pending = NULL;
2918 case MESSAGE_DISCONNECT: /* call has been disconnected */
2919 if (p_state!=PORT_STATE_IN_SETUP
2920 && p_state!=PORT_STATE_IN_OVERLAP
2921 && p_state!=PORT_STATE_IN_PROCEEDING
2922 && p_state!=PORT_STATE_IN_ALERTING
2923 && p_state!=PORT_STATE_OUT_SETUP
2924 && p_state!=PORT_STATE_OUT_OVERLAP
2925 && p_state!=PORT_STATE_OUT_PROCEEDING
2926 && p_state!=PORT_STATE_OUT_ALERTING
2927 && p_state!=PORT_STATE_CONNECT
2928 && p_state!=PORT_STATE_CONNECT_WAITING)
2932 message_disconnect(epoint_id, message_id, param);
2935 case MESSAGE_RELEASE: /* release isdn port */
2936 if (p_state==PORT_STATE_RELEASE)
2940 message_release(epoint_id, message_id, param);
2944 PERROR("Pdss1(%s) isdn port with (caller id %s) received a wrong message: %d\n", p_name, p_callerinfo.id, message_id);
2953 * data from isdn-stack (layer-3) to pbx (port class)
2955 int stack2manager(struct mISDNport *mISDNport, unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
2961 PDEBUG(DEBUG_ISDN, "cmd(0x%x) pid(0x%x)\n", cmd, pid);
2965 PDEBUG(DEBUG_ISDN, "ignoring dummy process from phone.\n");
2969 /* find Port object of type ISDN */
2974 if ((port->p_type & PORT_CLASS_mISDN_MASK) == PORT_CLASS_mISDN_DSS1)
2976 pdss1 = (class Pdss1 *)port;
2977 /* check out correct stack and id */
2978 if (pdss1->p_m_mISDNport == mISDNport)
2980 if (pdss1->p_m_d_l3id & MISDN_PID_CR_FLAG)
2982 /* local callref, so match value only */
2983 if ((pdss1->p_m_d_l3id & MISDN_PID_CRVAL_MASK) == (pid & MISDN_PID_CRVAL_MASK))
2987 /* remote callref, ref + channel id */
2988 if (pdss1->p_m_d_l3id == pid)
2996 /* aktueller prozess */
2999 if (cmd == MT_ASSIGN)
3001 /* stack gives us new layer 3 id (during connect) */
3002 l1l2l3_trace_header(mISDNport, pdss1, L3_NEW_L3ID_IND, DIRECTION_IN);
3003 add_trace("callref", "old", "0x%x", pdss1->p_m_d_l3id);
3004 /* nt-library now gives us a new id via CC_SETUP_CONFIRM */
3005 if ((pdss1->p_m_d_l3id&MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER)
3006 PERROR(" strange setup-procid 0x%x\n", pdss1->p_m_d_l3id);
3007 pdss1->p_m_d_l3id = pid;
3008 if (port->p_state == PORT_STATE_CONNECT)
3009 pdss1->p_m_d_ces = pid >> 16;
3010 add_trace("callref", "new", "0x%x", pdss1->p_m_d_l3id);
3014 /* if process id is master process, but a child disconnects */
3015 if (mISDNport->ntmode
3016 && (pid & MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER
3017 && (pdss1->p_m_d_l3id & MISDN_PID_CRTYPE_MASK) == MISDN_PID_MASTER)
3019 if (cmd == MT_DISCONNECT
3020 || cmd == MT_RELEASE)
3022 /* send special indication for child disconnect */
3023 pdss1->disconnect_ind_i(cmd, pid, l3m);
3026 if (cmd == MT_RELEASE_COMPLETE)
3029 /* if we have child pid and got different child pid message, ignore */
3030 if (mISDNport->ntmode
3031 && (pid & MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER
3032 && (pdss1->p_m_d_l3id & MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER
3033 && pid != pdss1->p_m_d_l3id)
3036 /* process message */
3037 pdss1->message_isdn(cmd, pid, l3m);
3045 /* creating port object, transparent until setup with hdlc */
3046 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3047 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0, B_MODE_TRANSPARENT)))
3049 FATAL("Cannot create Port instance.\n");
3050 pdss1->message_isdn(cmd, pid, l3m);
3054 /* creating port object, transparent until setup with hdlc */
3055 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3056 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0, B_MODE_TRANSPARENT)))
3057 FATAL("Cannot create Port instance.\n");
3058 pdss1->message_isdn(cmd, pid, l3m);
3062 PDEBUG(DEBUG_ISDN, "unused call ref released (l3id=0x%x)\n", pid);
3065 case MT_RELEASE_COMPLETE:
3066 PERROR("must be ignored by stack, not sent to app\n");
3070 // facility als broadcast
3074 PERROR("unhandled message: cmd(0x%x) pid(0x%x)\n", cmd, pid);
3078 if (port->p_type == PORT_TYPE_DSS1_NT_IN || port->p_type == PORT_TYPE_DSS1_NT_OUT)
3080 pdss1 = (class Pdss1 *)port;
3081 /* check out correct stack */
3082 if (pdss1->p_m_mISDNport == mISDNport)
3083 /* check out correct id */
3084 PERROR("unhandled message: pid=%x is not associated with port-dinfo=%x\n", pid, pdss1->p_m_d_l3id);