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;
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 */
49 message_free(p_m_d_queue);
51 if (p_m_d_notify_pending)
52 message_free(p_m_d_notify_pending);
57 * create layer 3 message
59 static struct l3_msg *create_l3msg(void)
67 FATAL("Cannot allocate memory, system overloaded.\n");
68 exit(0); // make gcc happy
72 * if we received a first reply to the setup message,
73 * we will check if we have now channel information
74 * return: <0: error, call is released, -cause is given
75 * 0: ok, nothing to do
77 int Pdss1::received_first_reply_to_setup(unsigned int cmd, int channel, int exclusive)
82 /* correct exclusive to 0, if no explicit channel was given */
83 if (exclusive<0 || channel<=0)
87 if (p_m_b_channel && p_m_b_exclusive)
89 /*** we gave an exclusive channel (or if we are done) ***/
91 /* if not first reply, we are done */
92 if (p_state != PORT_STATE_OUT_SETUP)
95 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
96 add_trace("channel", "request", "%d (forced)", p_m_b_channel);
97 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
99 /* if give channel not accepted or not equal */
100 if (channel!=-1 && p_m_b_channel!=channel)
102 add_trace("conclusion", NULL, "forced channel not accepted");
108 add_trace("conclusion", NULL, "channel was accepted");
109 add_trace("connect", "channel", "%d", p_m_b_channel);
112 /* activate our exclusive channel */
113 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
117 /*** we gave a non-exclusive channel ***/
119 /* if not first reply, we are done */
120 if (p_state != PORT_STATE_OUT_SETUP)
123 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
124 add_trace("channel", "request", "%d (suggest)", p_m_b_channel);
125 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
127 /* if channel was accepted as given */
128 if (channel==-1 || p_m_b_channel==channel)
130 add_trace("conclusion", NULL, "channel was accepted as given");
131 add_trace("connect", "channel", "%d", p_m_b_channel);
133 p_m_b_exclusive = 1; // we are done
134 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
138 /* if channel value is faulty */
141 add_trace("conclusion", NULL, "illegal reply");
143 ret = -111; // protocol error
147 /* if channel was not accepted, try to get it */
148 ret = seize_bchannel(channel, 1); // exclusively
149 add_trace("channel", "available", ret<0?"no":"yes");
152 add_trace("conclusion", NULL, "replied channel not available");
156 add_trace("conclusion", NULL, "replied channel accepted");
157 add_trace("connect", "channel", "%d", p_m_b_channel);
160 /* activate channel given by remote */
161 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
165 /*** we sent 'any channel acceptable' ***/
167 /* if not first reply, we are done */
168 if (p_state != PORT_STATE_OUT_SETUP)
171 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
172 add_trace("channel", "request", "any");
173 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
174 /* if no channel was replied */
177 add_trace("conclusion", NULL, "no channel, protocol error");
179 ret = -111; // protocol error
183 /* we will see, if our received channel is available */
184 ret = seize_bchannel(channel, 1); // exclusively
185 add_trace("channel", "available", ret<0?"no":"yes");
188 add_trace("conclusion", NULL, "replied channel not available");
192 add_trace("conclusion", NULL, "replied channel accepted");
193 add_trace("connect", "channel", "%d", p_m_b_channel);
196 /* activate channel given by remote */
197 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
200 /*** we sent 'no channel available' ***/
202 /* if not the first reply, but a connect, we are forced */
203 if (cmd==MT_CONNECT && p_state!=PORT_STATE_OUT_SETUP)
205 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (connect)", DIRECTION_NONE);
206 add_trace("channel", "request", "no-channel");
207 add_trace("channel", "reply", (channel>=0)?"%d%s":"(none)", channel, exclusive?" (forced)":"");
210 goto use_from_connect;
212 ret = seize_bchannel(CHANNEL_ANY, 0); // any channel
213 add_trace("channel", "available", ret<0?"no":"yes");
216 add_trace("conclusion", NULL, "no channel available during call-waiting");
220 add_trace("conclusion", NULL, "using channel %d", p_m_b_channel);
221 add_trace("connect", "channel", "%d", p_m_b_channel);
223 p_m_b_exclusive = 1; // we are done
225 /* activate channel given by remote */
226 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
230 /* if not first reply, we are done */
231 if (p_state != PORT_STATE_OUT_SETUP)
234 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
235 add_trace("channel", "request", "no-channel");
236 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
237 /* if first reply has no channel, we are done */
240 add_trace("conclusion", NULL, "no channel until connect");
245 /* we will see, if our received channel is available */
247 ret = seize_bchannel(channel, exclusive);
248 add_trace("channel", "available", ret<0?"no":"yes");
251 add_trace("conclusion", NULL, "replied channel not available");
255 add_trace("conclusion", NULL, "replied channel accepted");
256 add_trace("connect", "channel", "%d", p_m_b_channel);
258 p_m_b_exclusive = 1; // we are done
260 /* activate channel given by remote */
261 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
267 * NOTE: we send MT_RELEASE_COMPLETE to "REJECT" the channel
268 * in response to the setup reply
270 l3m = create_l3msg();
271 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
272 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
274 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
275 new_state(PORT_STATE_RELEASE);
277 return(-34); /* to epoint: no channel available */
282 * hunt bchannel for incoming setup or retrieve or resume
284 int Pdss1::hunt_bchannel(int channel, int exclusive)
286 struct select_channel *selchannel;
287 struct interface_port *ifport = p_m_mISDNport->ifport;
290 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (setup)", DIRECTION_NONE);
293 if (channel == CHANNEL_NO)
294 add_trace("channel", "request", "no-channel");
296 add_trace("channel", "request", (channel>0)?"%d%s":"any", channel, exclusive?" (forced)":"");
297 if (channel==CHANNEL_NO && p_type==PORT_TYPE_DSS1_TE_IN)
299 add_trace("conclusion", NULL, "incoming call-waiting not supported for TE-mode");
301 return(-6); // channel unacceptable
303 if (channel <= 0) /* not given, no channel, whatever.. */
304 channel = CHANNEL_ANY; /* any channel */
305 add_trace("channel", "reserved", "%d", p_m_mISDNport->b_reserved);
306 if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num) // of out chan..
308 add_trace("conclusion", NULL, "all channels are reserved");
310 return(-34); // no channel
312 if (channel == CHANNEL_ANY)
316 /* check for given channel in selection list */
317 selchannel = ifport->in_channel;
320 if (selchannel->channel == channel || selchannel->channel == CHANNEL_FREE)
322 selchannel = selchannel->next;
327 /* exclusive channel requests must be in the list */
330 /* no exclusive channel */
333 add_trace("conclusion", NULL, "exclusively requested channel not in list");
335 return(-6); // channel unacceptable
337 /* get index for channel */
338 i = channel-1-(channel>=17);
339 if (i < 0 || i >= p_m_mISDNport->b_num || channel == 16)
341 add_trace("conclusion", NULL, "exclusively requested channel outside interface range");
343 return(-6); // channel unacceptable
346 if (p_m_mISDNport->b_port[i] == NULL)
348 add_trace("conclusion", NULL, "exclusively requested channel is busy");
350 return(-6); // channel unacceptable
353 /* requested channels in list will be used */
356 /* get index for channel */
357 i = channel-1-(channel>=17);
358 if (i < 0 || i >= p_m_mISDNport->b_num || channel == 16)
360 add_trace("info", NULL, "requested channel %d outside interface range", channel);
361 } else /* if inside range (else) check if available */
362 if (p_m_mISDNport->b_port[i] == NULL)
366 /* if channel is not available or not in list, it must be searched */
368 /* check for first free channel in list */
370 selchannel = ifport->in_channel;
373 switch(selchannel->channel)
375 case CHANNEL_FREE: /* free channel */
376 add_trace("hunting", "channel", "free");
377 if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num)
378 break; /* all channel in use or reserverd */
381 while(i < p_m_mISDNport->b_num)
383 if (p_m_mISDNport->b_port[i] == NULL)
385 channel = i+1+(i>=15);
393 add_trace("hunting", "channel", "%d", selchannel->channel);
394 if (selchannel->channel<1 || selchannel->channel==16)
395 break; /* invalid channels */
396 i = selchannel->channel-1-(selchannel->channel>=17);
397 if (i >= p_m_mISDNport->b_num)
398 break; /* channel not in port */
399 if (p_m_mISDNport->b_port[i] == NULL)
401 channel = selchannel->channel;
407 break; /* found channel */
408 selchannel = selchannel->next;
412 add_trace("conclusion", NULL, "no channel available");
414 return(-6); // channel unacceptable
418 add_trace("conclusion", NULL, "channel available");
419 add_trace("connect", "channel", "%d", channel);
425 * handles all indications
427 /* CC_SETUP INDICATION */
428 void Pdss1::setup_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
430 int calling_type, calling_plan, calling_present, calling_screen;
431 int calling_type2, calling_plan2, calling_present2, calling_screen2;
432 int called_type, called_plan;
433 int redir_type, redir_plan, redir_present, redir_screen, redir_reason;
434 int hlc_coding, hlc_presentation, hlc_interpretation, hlc_hlc, hlc_exthlc;
435 int bearer_coding, bearer_capability, bearer_mode, bearer_rate, bearer_multi, bearer_user;
436 int exclusive, channel;
438 unsigned char keypad[32] = "";
439 unsigned char useruser[128];
440 int useruser_len = 0, useruser_protocol;
441 class Endpoint *epoint;
442 struct lcr_msg *message;
444 /* process given callref */
445 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_IND, DIRECTION_IN);
446 add_trace("callref", "new", "0x%x", pid);
449 /* release in case the ID is already in use */
450 add_trace("error", NULL, "callref already in use");
452 l3m = create_l3msg();
453 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
454 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47);
455 add_trace("reason", NULL, "callref already in use");
457 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, pid, l3m);
458 new_state(PORT_STATE_RELEASE);
463 p_m_d_ces = pid >> 16;
466 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_IND, DIRECTION_IN);
467 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));
468 dec_ie_called_pn(l3m, &called_type, &called_plan, (unsigned char *)p_dialinginfo.id, sizeof(p_dialinginfo.id));
469 dec_ie_keypad(l3m, (unsigned char *)keypad, sizeof(keypad));
470 /* te-mode: CNIP (calling name identification presentation) */
471 dec_facility_centrex(l3m, (unsigned char *)p_callerinfo.name, sizeof(p_callerinfo.name));
472 dec_ie_useruser(l3m, &useruser_protocol, useruser, &useruser_len);
473 dec_ie_complete(l3m, &p_dialinginfo.sending_complete);
474 dec_ie_redir_nr(l3m, &redir_type, &redir_plan, &redir_present, &redir_screen, &redir_reason, (unsigned char *)p_redirinfo.id, sizeof(p_redirinfo.id));
475 dec_ie_channel_id(l3m, &exclusive, &channel);
476 dec_ie_hlc(l3m, &hlc_coding, &hlc_interpretation, &hlc_presentation, &hlc_hlc, &hlc_exthlc);
477 dec_ie_bearer(l3m, &bearer_coding, &bearer_capability, &bearer_mode, &bearer_rate, &bearer_multi, &bearer_user);
478 dec_ie_display(l3m, (unsigned char *)p_dialinginfo.display, sizeof(p_dialinginfo.display));
481 /* if blocked, release call with MT_RELEASE_COMPLETE */
482 if (p_m_mISDNport->ifport->block)
484 l3m = create_l3msg();
485 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
486 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 27); /* temporary unavailable */
487 add_trace("reason", NULL, "port blocked");
489 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
490 new_state(PORT_STATE_RELEASE);
496 switch (calling_present)
499 p_callerinfo.present = INFO_PRESENT_RESTRICTED;
502 p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
505 p_callerinfo.present = INFO_PRESENT_ALLOWED;
508 switch (calling_screen)
511 p_callerinfo.screen = INFO_SCREEN_USER;
514 p_callerinfo.screen = INFO_SCREEN_NETWORK;
517 switch (calling_type)
520 p_callerinfo.ntype = INFO_NTYPE_NOTPRESENT;
523 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
526 p_callerinfo.ntype = INFO_NTYPE_INTERNATIONAL;
529 p_callerinfo.ntype = INFO_NTYPE_NATIONAL;
532 p_callerinfo.ntype = INFO_NTYPE_SUBSCRIBER;
535 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
538 p_callerinfo.isdn_port = p_m_portnum;
539 SCPY(p_callerinfo.interface, p_m_mISDNport->ifport->interface->name);
542 switch (calling_present2)
545 p_callerinfo.present2 = INFO_PRESENT_RESTRICTED;
548 p_callerinfo.present2 = INFO_PRESENT_NOTAVAIL;
551 p_callerinfo.present2 = INFO_PRESENT_ALLOWED;
554 switch (calling_screen2)
557 p_callerinfo.screen2 = INFO_SCREEN_USER;
560 p_callerinfo.screen2 = INFO_SCREEN_NETWORK;
563 switch (calling_type2)
566 p_callerinfo.ntype2 = INFO_NTYPE_NOTPRESENT;
569 p_callerinfo.ntype2 = INFO_NTYPE_UNKNOWN;
572 p_callerinfo.ntype2 = INFO_NTYPE_INTERNATIONAL;
575 p_callerinfo.ntype2 = INFO_NTYPE_NATIONAL;
578 p_callerinfo.ntype2 = INFO_NTYPE_SUBSCRIBER;
581 p_callerinfo.ntype2 = INFO_NTYPE_UNKNOWN;
585 /* dialing information */
586 SCAT(p_dialinginfo.id, (char *)keypad);
590 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
593 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
596 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
599 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
604 switch (redir_present)
607 p_redirinfo.present = INFO_PRESENT_RESTRICTED;
610 p_redirinfo.present = INFO_PRESENT_NOTAVAIL;
613 p_redirinfo.present = INFO_PRESENT_ALLOWED;
616 switch (redir_screen)
619 p_redirinfo.screen = INFO_SCREEN_USER;
622 p_redirinfo.screen = INFO_SCREEN_NETWORK;
625 switch (redir_reason)
628 p_redirinfo.reason = INFO_REDIR_BUSY;
631 p_redirinfo.reason = INFO_REDIR_NORESPONSE;
634 p_redirinfo.reason = INFO_REDIR_UNCONDITIONAL;
637 p_redirinfo.reason = INFO_REDIR_CALLDEFLECT;
640 p_redirinfo.reason = INFO_REDIR_OUTOFORDER;
643 p_redirinfo.reason = INFO_REDIR_UNKNOWN;
649 p_redirinfo.ntype = INFO_NTYPE_NOTPRESENT;
652 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
655 p_redirinfo.ntype = INFO_NTYPE_INTERNATIONAL;
658 p_redirinfo.ntype = INFO_NTYPE_NATIONAL;
661 p_redirinfo.ntype = INFO_NTYPE_SUBSCRIBER;
664 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
667 p_redirinfo.isdn_port = p_m_portnum;
669 /* bearer capability */
670 switch (bearer_capability)
673 p_capainfo.bearer_capa = INFO_BC_AUDIO;
674 bearer_user = (options.law=='a')?3:2;
677 p_capainfo.bearer_capa = bearer_capability;
683 p_capainfo.bearer_mode = INFO_BMODE_PACKET;
686 p_capainfo.bearer_mode = INFO_BMODE_CIRCUIT;
692 p_capainfo.bearer_info1 = INFO_INFO1_NONE;
695 p_capainfo.bearer_info1 = bearer_user + 0x80;
703 p_capainfo.hlc = INFO_HLC_NONE;
706 p_capainfo.hlc = hlc_hlc + 0x80;
712 p_capainfo.exthlc = INFO_HLC_NONE;
715 p_capainfo.exthlc = hlc_exthlc + 0x80;
719 /* set bchannel mode */
720 if (p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED
721 || p_capainfo.bearer_capa==INFO_BC_DATARESTRICTED
722 || p_capainfo.bearer_capa==INFO_BC_VIDEO)
723 p_capainfo.source_mode = B_MODE_HDLC;
725 p_capainfo.source_mode = B_MODE_TRANSPARENT;
726 p_m_b_mode = p_capainfo.source_mode;
729 ret = channel = hunt_bchannel(channel, exclusive);
734 ret = seize_bchannel(channel, 1);
739 * NOTE: we send MT_RELEASE_COMPLETE to "REJECT" the channel
740 * in response to the setup
742 l3m = create_l3msg();
743 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
744 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
746 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
747 new_state(PORT_STATE_RELEASE);
751 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
753 /* create endpoint */
755 FATAL("Incoming call but already got an endpoint.\n");
756 if (!(epoint = new Endpoint(p_serial, 0)))
757 FATAL("No memory for Endpoint instance\n");
758 if (!(epoint->ep_app = new DEFAULT_ENDPOINT_APP(epoint, 0))) //incoming
759 FATAL("No memory for Endpoint Application instance\n");
760 epointlist_new(epoint->ep_serial);
762 /* send setup message to endpoit */
763 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_SETUP);
764 message->param.setup.isdn_port = p_m_portnum;
765 message->param.setup.port_type = p_type;
766 // message->param.setup.dtmf = !p_m_mISDNport->ifport->nodtmf;
767 memcpy(&message->param.setup.dialinginfo, &p_dialinginfo, sizeof(struct dialing_info));
768 memcpy(&message->param.setup.callerinfo, &p_callerinfo, sizeof(struct caller_info));
769 memcpy(&message->param.setup.redirinfo, &p_redirinfo, sizeof(struct redir_info));
770 memcpy(&message->param.setup.capainfo, &p_capainfo, sizeof(struct capa_info));
771 memcpy(message->param.setup.useruser.data, &useruser, useruser_len);
772 message->param.setup.useruser.len = useruser_len;
773 message->param.setup.useruser.protocol = useruser_protocol;
774 message_put(message);
776 new_state(PORT_STATE_IN_SETUP);
779 /* CC_INFORMATION INDICATION */
780 void Pdss1::information_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
783 unsigned char keypad[32] = "", display[128] = "";
784 struct lcr_msg *message;
786 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_IND, DIRECTION_IN);
787 dec_ie_called_pn(l3m, &type, &plan, (unsigned char *)p_dialinginfo.id, sizeof(p_dialinginfo.id));
788 dec_ie_keypad(l3m, (unsigned char *)keypad, sizeof(keypad));
789 dec_ie_display(l3m, (unsigned char *)display, sizeof(display));
790 dec_ie_complete(l3m, &p_dialinginfo.sending_complete);
793 SCAT(p_dialinginfo.id, (char *)keypad);
797 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
800 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
803 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
806 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
809 SCAT(p_dialinginfo.display, (char *)display);
810 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_INFORMATION);
811 memcpy(&message->param.information, &p_dialinginfo, sizeof(struct dialing_info));
812 message_put(message);
813 /* reset overlap timeout */
817 /* CC_SETUP_ACCNOWLEDGE INDICATION */
818 void Pdss1::setup_acknowledge_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
820 int exclusive, channel;
821 int coding, location, progress;
823 struct lcr_msg *message;
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);
849 /* CC_PROCEEDING INDICATION */
850 void Pdss1::proceeding_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
852 int exclusive, channel;
853 int coding, location, progress;
855 struct lcr_msg *message;
856 int notify = -1, type, plan, present;
859 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_IND, DIRECTION_IN);
860 dec_ie_channel_id(l3m, &exclusive, &channel);
861 dec_ie_progress(l3m, &coding, &location, &progress);
862 dec_ie_notify(l3m, ¬ify);
863 dec_ie_redir_dn(l3m, &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
866 ret = received_first_reply_to_setup(cmd, channel, exclusive);
869 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
870 message->param.disconnectinfo.cause = -ret;
871 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
872 message_put(message);
873 new_state(PORT_STATE_RELEASE);
877 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROCEEDING);
878 message_put(message);
880 new_state(PORT_STATE_OUT_PROCEEDING);
886 if (type >= 0 || notify)
888 if (!notify && type >= 0)
890 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
891 message->param.notifyinfo.notify = notify;
892 SCPY(message->param.notifyinfo.id, redir);
893 /* redirection number */
897 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
900 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
903 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
909 message->param.notifyinfo.ntype = INFO_NTYPE_NOTPRESENT;
912 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
915 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
918 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
921 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
924 message->param.notifyinfo.isdn_port = p_m_portnum;
925 message_put(message);
929 /* CC_ALERTING INDICATION */
930 void Pdss1::alerting_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
932 int exclusive, channel;
933 int coding, location, progress;
935 struct lcr_msg *message;
936 int notify = -1, type, plan, present;
939 l1l2l3_trace_header(p_m_mISDNport, this, L3_ALERTING_IND, DIRECTION_IN);
940 dec_ie_channel_id(l3m, &exclusive, &channel);
941 dec_ie_progress(l3m, &coding, &location, &progress);
942 dec_ie_notify(l3m, ¬ify);
943 dec_ie_redir_dn(l3m, &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
946 /* process channel */
947 ret = received_first_reply_to_setup(cmd, channel, exclusive);
950 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
951 message->param.disconnectinfo.cause = -ret;
952 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
953 message_put(message);
954 new_state(PORT_STATE_RELEASE);
958 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_ALERTING);
959 message_put(message);
961 new_state(PORT_STATE_OUT_ALERTING);
967 if (type >= 0 || notify)
969 if (!notify && type >= 0)
971 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
972 message->param.notifyinfo.notify = notify;
973 SCPY(message->param.notifyinfo.id, redir);
977 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
980 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
983 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
989 message->param.notifyinfo.ntype = INFO_NTYPE_NOTPRESENT;
992 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
995 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
998 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1001 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1004 message->param.notifyinfo.isdn_port = p_m_portnum;
1005 message_put(message);
1009 /* CC_CONNECT INDICATION */
1010 void Pdss1::connect_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1012 int exclusive, channel;
1013 int type, plan, present, screen;
1015 struct lcr_msg *message;
1016 int bchannel_before;
1018 l1l2l3_trace_header(p_m_mISDNport, this, L3_CONNECT_IND, DIRECTION_IN);
1019 dec_ie_channel_id(l3m, &exclusive, &channel);
1020 dec_ie_connected_pn(l3m, &type, &plan, &present, &screen, (unsigned char *)p_connectinfo.id, sizeof(p_connectinfo.id));
1021 dec_ie_display(l3m, (unsigned char *)p_connectinfo.display, sizeof(p_connectinfo.display));
1022 /* te-mode: CONP (connected name identification presentation) */
1023 dec_facility_centrex(l3m, (unsigned char *)p_connectinfo.name, sizeof(p_connectinfo.name));
1026 /* select channel */
1027 bchannel_before = p_m_b_channel;
1028 ret = received_first_reply_to_setup(cmd, channel, exclusive);
1031 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1032 message->param.disconnectinfo.cause = -ret;
1033 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1034 message_put(message);
1035 new_state(PORT_STATE_RELEASE);
1040 /* connect information */
1044 p_connectinfo.present = INFO_PRESENT_RESTRICTED;
1047 p_connectinfo.present = INFO_PRESENT_NOTAVAIL;
1050 p_connectinfo.present = INFO_PRESENT_ALLOWED;
1056 p_connectinfo.screen = INFO_SCREEN_USER;
1059 p_connectinfo.screen = INFO_SCREEN_NETWORK;
1065 p_connectinfo.ntype = INFO_NTYPE_NOTPRESENT;
1068 p_connectinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1071 p_connectinfo.ntype = INFO_NTYPE_NATIONAL;
1074 p_connectinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1077 p_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1080 p_connectinfo.isdn_port = p_m_portnum;
1081 SCPY(p_connectinfo.interface, p_m_mISDNport->ifport->interface->name);
1083 /* only in nt-mode we send connect ack. in te-mode it is done by stack itself or optional */
1086 /* send connect acknowledge */
1087 l3m = create_l3msg();
1088 l1l2l3_trace_header(p_m_mISDNport, this, L3_CONNECT_RES, DIRECTION_OUT);
1089 /* if we had no bchannel before, we send it now */
1090 if (!bchannel_before && p_m_b_channel)
1091 enc_ie_channel_id(l3m, 1, p_m_b_channel);
1093 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CONNECT_ACKNOWLEDGE, p_m_d_l3id, l3m);
1096 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CONNECT);
1097 memcpy(&message->param.connectinfo, &p_connectinfo, sizeof(struct connect_info));
1098 message_put(message);
1100 new_state(PORT_STATE_CONNECT);
1103 /* CC_DISCONNECT INDICATION */
1104 void Pdss1::disconnect_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1106 int location, cause;
1107 int coding, proglocation, progress;
1108 struct lcr_msg *message;
1109 unsigned char display[128] = "";
1111 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_IND, DIRECTION_IN);
1112 dec_ie_progress(l3m, &coding, &proglocation, &progress);
1113 dec_ie_cause(l3m, &location, &cause);
1114 dec_ie_display(l3m, (unsigned char *)display, sizeof(display));
1120 /* release if remote sends us no tones */
1121 if (!p_m_mISDNport->earlyb)
1125 l3m = create_l3msg();
1126 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_REQ, DIRECTION_OUT);
1127 enc_ie_cause(l3m, location, cause); /* normal */
1128 add_trace("reason", NULL, "no remote patterns");
1130 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE, p_m_d_l3id, l3m);
1132 /* sending release to endpoint */
1133 if (location == LOCATION_PRIVATE_LOCAL)
1134 location = LOCATION_PRIVATE_REMOTE;
1137 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1138 message->param.disconnectinfo.cause = cause;
1139 message->param.disconnectinfo.location = location;
1140 SCAT(message->param.disconnectinfo.display, (char *)display);
1141 message_put(message);
1143 free_epointlist(p_epointlist);
1145 new_state(PORT_STATE_RELEASE);
1150 /* sending disconnect to active endpoint and release to inactive endpoints */
1151 if (location == LOCATION_PRIVATE_LOCAL)
1152 location = LOCATION_PRIVATE_REMOTE;
1153 if (ACTIVE_EPOINT(p_epointlist))
1155 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DISCONNECT);
1156 message->param.disconnectinfo.location = location;
1157 message->param.disconnectinfo.cause = cause;
1158 SCAT(message->param.disconnectinfo.display, (char *)display);
1159 message_put(message);
1161 while(INACTIVE_EPOINT(p_epointlist))
1163 message = message_create(p_serial, INACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1164 message->param.disconnectinfo.location = location;
1165 message->param.disconnectinfo.cause = cause;
1166 SCAT(message->param.disconnectinfo.display, (char *)display);
1167 message_put(message);
1169 free_epointid(INACTIVE_EPOINT(p_epointlist));
1171 new_state(PORT_STATE_IN_DISCONNECT);
1174 /* CC_DISCONNECT INDICATION */
1175 void Pdss1::disconnect_ind_i(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1177 int location, cause;
1180 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_IND, DIRECTION_IN);
1181 if (p_m_d_collect_cause > 0)
1183 add_trace("old-cause", "location", "%d", p_m_d_collect_location);
1184 add_trace("old-cause", "value", "%d", p_m_d_collect_cause);
1186 dec_ie_cause(l3m, &location, &cause);
1187 if (location == LOCATION_PRIVATE_LOCAL)
1188 location = LOCATION_PRIVATE_REMOTE;
1191 collect_cause(&p_m_d_collect_cause, &p_m_d_collect_location, cause, location);
1192 add_trace("new-cause", "location", "%d", p_m_d_collect_location);
1193 add_trace("new-cause", "value", "%d", p_m_d_collect_cause);
1198 /* CC_RELEASE INDICATION */
1199 void Pdss1::release_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1201 int location, cause;
1202 struct lcr_msg *message;
1203 unsigned char display[128] = "";
1205 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_IND, DIRECTION_IN);
1206 dec_ie_cause(l3m, &location, &cause);
1207 dec_ie_display(l3m, (unsigned char *)display, sizeof(display));
1213 /* sending release to endpoint */
1214 if (location == LOCATION_PRIVATE_LOCAL)
1215 location = LOCATION_PRIVATE_REMOTE;
1218 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1219 message->param.disconnectinfo.cause = cause;
1220 message->param.disconnectinfo.location = location;
1221 SCAT(message->param.disconnectinfo.display, (char *)display);
1222 message_put(message);
1224 free_epointlist(p_epointlist);
1227 new_state(PORT_STATE_RELEASE);
1231 /* CC_RESTART INDICATION */
1232 void Pdss1::restart_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1234 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESTART_IND, DIRECTION_IN);
1237 // L3 process is not toucht. (not even by network stack)
1240 /* CC_RELEASE_COMPLETE INDICATION (a reject) */
1241 void Pdss1::release_complete_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1243 int location, cause;
1244 struct lcr_msg *message;
1246 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_IND, DIRECTION_IN);
1247 /* in case layer 2 is down during setup, we send cause 27 loc 5 */
1248 if (p_state == PORT_STATE_OUT_SETUP && p_m_mISDNport->l1link == 0)
1254 dec_ie_cause(l3m, &location, &cause);
1255 if (p_m_mISDNport->l1link < 0)
1256 add_trace("layer 1", NULL, "unknown");
1258 add_trace("layer 1", NULL, (p_m_mISDNport->l1link)?"up":"down");
1261 if (location == LOCATION_PRIVATE_LOCAL)
1262 location = LOCATION_PRIVATE_REMOTE;
1267 /* sending release to endpoint */
1270 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1271 message->param.disconnectinfo.cause = cause;
1272 message->param.disconnectinfo.location = location;
1273 message_put(message);
1275 free_epointlist(p_epointlist);
1278 new_state(PORT_STATE_RELEASE);
1283 void Pdss1::t312_timeout_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1285 // not required, release is performed with MT_FREE
1288 /* CC_NOTIFY INDICATION */
1289 void Pdss1::notify_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1291 struct lcr_msg *message;
1292 int notify, type, plan, present;
1293 unsigned char notifyid[sizeof(message->param.notifyinfo.id)];
1294 unsigned char display[128] = "";
1296 l1l2l3_trace_header(p_m_mISDNport, this, L3_NOTIFY_IND, DIRECTION_IN);
1297 dec_ie_notify(l3m, ¬ify);
1298 dec_ie_redir_dn(l3m, &type, &plan, &present, notifyid, sizeof(notifyid));
1299 dec_ie_display(l3m, (unsigned char *)display, sizeof(display));
1302 if (!ACTIVE_EPOINT(p_epointlist))
1304 /* notification indicator */
1308 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1309 message->param.notifyinfo.notify = notify;
1310 SCPY(message->param.notifyinfo.id, (char *)notifyid);
1311 /* redirection number */
1315 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1318 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1321 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1327 message->param.notifyinfo.ntype = INFO_NTYPE_NOTPRESENT;
1330 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1333 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1336 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1339 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1342 SCAT(message->param.notifyinfo.display, (char *)display);
1343 message->param.notifyinfo.isdn_port = p_m_portnum;
1344 message_put(message);
1348 /* CC_HOLD INDICATION */
1349 struct lcr_msg *message;
1350 void Pdss1::hold_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1352 // class Endpoint *epoint;
1354 l1l2l3_trace_header(p_m_mISDNport, this, L3_HOLD_IND, DIRECTION_IN);
1357 if (!ACTIVE_EPOINT(p_epointlist) || p_m_hold)
1359 l3m = create_l3msg();
1360 l1l2l3_trace_header(p_m_mISDNport, this, L3_HOLD_REJECT_REQ, DIRECTION_OUT);
1361 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, p_m_hold?101:31); /* normal unspecified / incompatible state */
1362 add_trace("reason", NULL, "no endpoint");
1364 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_HOLD_REJECT, p_m_d_l3id, l3m);
1369 /* notify the hold of call */
1370 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1371 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_HOLD;
1372 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1373 message_put(message);
1375 /* deactivate bchannel */
1376 chan_trace_header(p_m_mISDNport, this, "CHANNEL RELEASE (hold)", DIRECTION_NONE);
1377 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1381 /* set hold state */
1384 epoint = find_epoint_id(ACTIVE_EPOINT(p_epointlist));
1385 if (epoint && p_m_d_ntmode)
1387 p_m_timeout = p_settings.tout_hold;
1392 /* acknowledge hold */
1393 l3m = create_l3msg();
1394 l1l2l3_trace_header(p_m_mISDNport, this, L3_HOLD_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1396 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_HOLD_ACKNOWLEDGE, p_m_d_l3id, l3m);
1400 /* CC_RETRIEVE INDICATION */
1401 void Pdss1::retrieve_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1403 struct lcr_msg *message;
1404 int channel, exclusive, cause;
1407 l1l2l3_trace_header(p_m_mISDNport, this, L3_RETRIEVE_IND, DIRECTION_IN);
1408 dec_ie_channel_id(l3m, &exclusive, &channel);
1413 cause = 101; /* incompatible state */
1416 l3m = create_l3msg();
1417 l1l2l3_trace_header(p_m_mISDNport, this, L3_RETRIEVE_REJECT_REQ, DIRECTION_OUT);
1418 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, cause);
1420 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RETRIEVE_REJECT, p_m_d_l3id, l3m);
1425 /* notify the retrieve of call */
1426 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1427 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_RETRIEVAL;
1428 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1429 message_put(message);
1432 ret = channel = hunt_bchannel(channel, exclusive);
1437 ret = seize_bchannel(channel, 1);
1444 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
1446 /* set hold state */
1450 /* acknowledge retrieve */
1451 l3m = create_l3msg();
1452 l1l2l3_trace_header(p_m_mISDNport, this, L3_RETRIEVE_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1453 enc_ie_channel_id(l3m, 1, p_m_b_channel);
1455 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RETRIEVE_ACKNOWLEDGE, p_m_d_l3id, l3m);
1458 /* CC_SUSPEND INDICATION */
1459 void Pdss1::suspend_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1461 struct lcr_msg *message;
1462 class Endpoint *epoint;
1463 unsigned char callid[8];
1465 int ret = -31; /* normal, unspecified */
1467 l1l2l3_trace_header(p_m_mISDNport, this, L3_SUSPEND_IND, DIRECTION_IN);
1468 dec_ie_call_id(l3m, callid, &len);
1471 if (!ACTIVE_EPOINT(p_epointlist))
1474 l3m = create_l3msg();
1475 l1l2l3_trace_header(p_m_mISDNport, this, L3_SUSPEND_REJECT_REQ, DIRECTION_OUT);
1476 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1478 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SUSPEND_REJECT, p_m_d_l3id, l3m);
1485 /* check if call id is in use */
1486 epoint = epoint_first;
1489 if (epoint->ep_park)
1491 if (epoint->ep_park_len == len)
1492 if (!memcmp(epoint->ep_park_callid, callid, len))
1494 ret = -84; /* call id in use */
1498 epoint = epoint->next;
1501 /* notify the hold of call */
1502 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1503 message->param.notifyinfo.notify = INFO_NOTIFY_USER_SUSPENDED;
1504 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1505 message_put(message);
1507 /* deactivate bchannel */
1508 chan_trace_header(p_m_mISDNport, this, "CHANNEL RELEASE (suspend)", DIRECTION_NONE);
1509 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1513 /* sending suspend to endpoint */
1514 while (p_epointlist)
1516 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_SUSPEND);
1517 memcpy(message->param.parkinfo.callid, callid, sizeof(message->param.parkinfo.callid));
1518 message->param.parkinfo.len = len;
1519 message_put(message);
1521 free_epointlist(p_epointlist);
1524 /* sending SUSPEND_ACKNOWLEDGE */
1525 l3m = create_l3msg();
1526 l1l2l3_trace_header(p_m_mISDNport, this, L3_SUSPEND_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1528 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SUSPEND_ACKNOWLEDGE, p_m_d_l3id, l3m);
1530 new_state(PORT_STATE_RELEASE);
1534 /* CC_RESUME INDICATION */
1535 void Pdss1::resume_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1537 unsigned char callid[8];
1539 int channel, exclusive;
1540 class Endpoint *epoint;
1541 struct lcr_msg *message;
1544 /* process given callref */
1545 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_IND, DIRECTION_IN);
1546 add_trace("callref", "new", "0x%x", pid);
1549 /* release is case the ID is already in use */
1550 add_trace("error", NULL, "callref already in use");
1552 l3m = create_l3msg();
1553 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_REJECT_REQ, DIRECTION_OUT);
1554 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47);
1555 add_trace("reason", NULL, "callref already in use");
1557 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RESUME_REJECT, pid, l3m);
1558 new_state(PORT_STATE_RELEASE);
1563 p_m_d_ces = pid >> 16;
1566 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_IND, DIRECTION_IN);
1567 dec_ie_call_id(l3m, callid, &len);
1570 /* if blocked, release call */
1571 if (p_m_mISDNport->ifport->block)
1580 /* channel_id (no channel is possible in message) */
1582 channel = -1; /* any channel */
1585 ret = channel = hunt_bchannel(channel, exclusive);
1589 // mode (if hdlc parked) to be done. never mind, this is almost never requested
1591 ret = seize_bchannel(channel, 1);
1596 l3m = create_l3msg();
1597 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_REJECT_REQ, DIRECTION_OUT);
1598 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1600 add_trace("reason", NULL, "port blocked");
1602 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RESUME_REJECT, p_m_d_l3id, l3m);
1603 new_state(PORT_STATE_RELEASE);
1607 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
1609 /* create endpoint */
1611 FATAL("Incoming resume but already got an endpoint.\n");
1612 ret = -85; /* no call suspended */
1613 epoint = epoint_first;
1616 if (epoint->ep_park)
1618 ret = -83; /* suspended call exists, but this not */
1619 if (epoint->ep_park_len == len)
1620 if (!memcmp(epoint->ep_park_callid, callid, len))
1623 epoint = epoint->next;
1628 epointlist_new(epoint->ep_serial);
1629 if (!(epoint->portlist_new(p_serial, p_type, p_m_mISDNport->earlyb)))
1630 FATAL("No memory for portlist\n");
1631 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RESUME);
1632 message_put(message);
1634 /* notify the resume of call */
1635 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1636 message->param.notifyinfo.notify = INFO_NOTIFY_USER_RESUMED;
1637 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1638 message_put(message);
1640 /* sending RESUME_ACKNOWLEDGE */
1641 l3m = create_l3msg();
1642 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1643 enc_ie_channel_id(l3m, 1, p_m_b_channel);
1645 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RESUME_ACKNOWLEDGE, p_m_d_l3id, l3m);
1647 new_state(PORT_STATE_CONNECT);
1651 /* CC_FACILITY INDICATION */
1652 void Pdss1::facility_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1654 unsigned char facil[256];
1656 struct lcr_msg *message;
1658 l1l2l3_trace_header(p_m_mISDNport, this, L3_FACILITY_IND, DIRECTION_IN);
1659 dec_ie_facility(l3m, facil, &facil_len);
1666 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_FACILITY);
1667 message->param.facilityinfo.len = facil_len;
1668 memcpy(message->param.facilityinfo.data, facil, facil_len);
1669 message_put(message);
1674 * handler for isdn connections
1675 * incoming information are parsed and sent via message to the endpoint
1677 void Pdss1::message_isdn(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1686 PERROR("Pdss1(%s) timeout without cause.\n", p_name);
1689 if (l3m->cause[0] != 5)
1691 PERROR("Pdss1(%s) expecting timeout with timer diagnostic. (got len=%d)\n", p_name, l3m->cause[0]);
1694 timer = (l3m->cause[3]-'0')*100;
1695 timer += (l3m->cause[4]-'0')*10;
1696 timer += (l3m->cause[5]-'0');
1697 l1l2l3_trace_header(p_m_mISDNport, this, L3_TIMEOUT_IND, DIRECTION_IN);
1698 add_trace("timer", NULL, "%d", timer);
1701 t312_timeout_ind(cmd, pid, l3m);
1705 if (p_state != PORT_STATE_IDLE)
1707 setup_ind(cmd, pid, l3m);
1710 case MT_INFORMATION:
1711 information_ind(cmd, pid, l3m);
1714 case MT_SETUP_ACKNOWLEDGE:
1715 if (p_state != PORT_STATE_OUT_SETUP)
1717 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received setup_acknowledge, but we are not in outgoing setup state, IGNORING.\n", p_name);
1720 setup_acknowledge_ind(cmd, pid, l3m);
1723 case MT_CALL_PROCEEDING:
1724 if (p_state != PORT_STATE_OUT_SETUP
1725 && p_state != PORT_STATE_OUT_OVERLAP)
1727 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received proceeding, but we are not in outgoing setup OR overlap state, IGNORING.\n", p_name);
1730 proceeding_ind(cmd, pid, l3m);
1734 if (p_state != PORT_STATE_OUT_SETUP
1735 && p_state != PORT_STATE_OUT_OVERLAP
1736 && p_state != PORT_STATE_OUT_PROCEEDING)
1738 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding state, IGNORING.\n", p_name);
1741 alerting_ind(cmd, pid, l3m);
1745 if (p_state != PORT_STATE_OUT_SETUP
1746 && p_state != PORT_STATE_OUT_OVERLAP
1747 && p_state != PORT_STATE_OUT_PROCEEDING
1748 && p_state != PORT_STATE_OUT_ALERTING)
1750 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);
1753 connect_ind(cmd, pid, l3m);
1754 if (p_m_d_notify_pending)
1756 /* send pending notify message during connect */
1757 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
1758 message_free(p_m_d_notify_pending);
1759 p_m_d_notify_pending = NULL;
1763 case MT_CONNECT_ACKNOWLEDGE:
1764 if (p_state == PORT_STATE_CONNECT_WAITING)
1765 new_state(PORT_STATE_CONNECT);
1766 if (p_m_d_notify_pending)
1768 /* send pending notify message during connect-ack */
1769 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
1770 message_free(p_m_d_notify_pending);
1771 p_m_d_notify_pending = NULL;
1776 disconnect_ind(cmd, pid, l3m);
1780 release_ind(cmd, pid, l3m);
1783 case MT_RELEASE_COMPLETE:
1784 release_complete_ind(cmd, pid, l3m);
1788 restart_ind(cmd, pid, l3m);
1792 notify_ind(cmd, pid, l3m);
1796 hold_ind(cmd, pid, l3m);
1800 retrieve_ind(cmd, pid, l3m);
1804 suspend_ind(cmd, pid, l3m);
1808 resume_ind(cmd, pid, l3m);
1812 facility_ind(cmd, pid, l3m);
1816 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_L3ID_IND, DIRECTION_IN);
1817 add_trace("callref", NULL, "0x%x", p_m_d_l3id);
1822 /* sending release to endpoint in case we still have an endpoint
1823 * this is because we don't get any response if a release_complete is received (or a release in release state)
1825 while(p_epointlist) // only if not already released
1827 struct lcr_msg *message;
1828 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1829 if (p_m_d_collect_cause)
1831 message->param.disconnectinfo.cause = p_m_d_collect_cause;
1832 message->param.disconnectinfo.location = p_m_d_collect_location;
1835 message->param.disconnectinfo.cause = CAUSE_NOUSER;
1836 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1838 message_put(message);
1840 free_epointlist(p_epointlist);
1842 new_state(PORT_STATE_RELEASE);
1847 l1l2l3_trace_header(p_m_mISDNport, this, L3_UNKNOWN, DIRECTION_IN);
1848 add_trace("unhandled", "cmd", "0x%x", cmd);
1853 void Pdss1::new_state(int state)
1855 // class Endpoint *epoint;
1858 if (state == PORT_STATE_IN_OVERLAP)
1860 p_m_timeout = p_m_mISDNport->ifport->tout_dialing;
1863 if (state != p_state)
1865 if (state == PORT_STATE_IN_SETUP
1866 || state == PORT_STATE_OUT_SETUP
1867 || state == PORT_STATE_IN_OVERLAP
1868 || state == PORT_STATE_OUT_OVERLAP)
1870 p_m_timeout = p_m_mISDNport->ifport->tout_setup;
1873 if (state == PORT_STATE_IN_PROCEEDING
1874 || state == PORT_STATE_OUT_PROCEEDING)
1876 p_m_timeout = p_m_mISDNport->ifport->tout_proceeding;
1879 if (state == PORT_STATE_IN_ALERTING
1880 || state == PORT_STATE_OUT_ALERTING)
1882 p_m_timeout = p_m_mISDNport->ifport->tout_alerting;
1885 if (state == PORT_STATE_CONNECT
1886 || state == PORT_STATE_CONNECT_WAITING)
1890 if (state == PORT_STATE_IN_DISCONNECT
1891 || state == PORT_STATE_OUT_DISCONNECT)
1893 p_m_timeout = p_m_mISDNport->ifport->tout_disconnect;
1898 Port::new_state(state);
1905 int Pdss1::handler(void)
1909 if ((ret = PmISDN::handler()))
1912 /* handle destruction */
1913 if (p_m_delete && p_m_d_l3id==0)
1924 * handles all messages from endpoint
1926 /* MESSAGE_INFORMATION */
1927 void Pdss1::message_information(unsigned int epoint_id, int message_id, union parameter *param)
1931 if (param->information.id[0]) /* only if we have something to dial */
1933 l3m = create_l3msg();
1934 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
1935 enc_ie_called_pn(l3m, 0, 1, (unsigned char *)param->information.id);
1936 if (p_m_d_ntmode || p_m_d_tespecial)
1937 enc_ie_display(l3m, (unsigned char *)param->information.display);
1939 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
1948 void Pdss1::message_setup(unsigned int epoint_id, int message_id, union parameter *param)
1952 int plan, type, screen, present, reason;
1953 int plan2, type2, screen2, present2;
1954 int capability, mode, rate, coding, user, presentation, interpretation, hlc, exthlc;
1955 int channel, exclusive;
1956 struct epoint_list *epointlist;
1958 /* release if port is blocked */
1959 if (p_m_mISDNport->ifport->block)
1961 struct lcr_msg *message;
1963 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1964 message->param.disconnectinfo.cause = 27; // temp. unavail.
1965 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1966 message_put(message);
1967 new_state(PORT_STATE_RELEASE);
1972 /* copy setup infos to port */
1973 memcpy(&p_callerinfo, ¶m->setup.callerinfo, sizeof(p_callerinfo));
1974 memcpy(&p_dialinginfo, ¶m->setup.dialinginfo, sizeof(p_dialinginfo));
1975 memcpy(&p_capainfo, ¶m->setup.capainfo, sizeof(p_capainfo));
1976 memcpy(&p_redirinfo, ¶m->setup.redirinfo, sizeof(p_redirinfo));
1977 // SCPY(&p_m_tones_dir, param->setup.ext.tones_dir);
1978 /* screen outgoing caller id */
1979 do_screen(1, p_callerinfo.id, sizeof(p_callerinfo.id), &p_callerinfo.ntype, &p_callerinfo.present, p_m_mISDNport->ifport->interface);
1980 do_screen(1, p_callerinfo.id2, sizeof(p_callerinfo.id2), &p_callerinfo.ntype2, &p_callerinfo.present2, p_m_mISDNport->ifport->interface);
1982 /* only display at connect state: this case happens if endpoint is in connected mode */
1983 if (p_state==PORT_STATE_CONNECT)
1985 if (p_type!=PORT_TYPE_DSS1_NT_OUT
1986 && p_type!=PORT_TYPE_DSS1_NT_IN)
1988 if (p_callerinfo.display[0])
1990 /* sending information */
1991 l3m = create_l3msg();
1992 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
1993 if (p_m_d_ntmode || p_m_d_tespecial)
1994 enc_ie_display(l3m, (unsigned char *)p_callerinfo.display);
1996 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
2001 /* attach only if not already */
2002 epointlist = p_epointlist;
2005 if (epointlist->epoint_id == epoint_id)
2007 epointlist = epointlist->next;
2010 epointlist_new(epoint_id);
2016 channel = p_m_b_channel;
2017 exclusive = p_m_b_exclusive;
2019 channel = CHANNEL_ANY;
2020 /* nt-port with no channel, not reserverd */
2021 if (!p_m_b_channel && !p_m_b_reserve && p_type==PORT_TYPE_DSS1_NT_OUT)
2022 channel = CHANNEL_NO;
2025 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_REQ, DIRECTION_OUT);
2026 /* see MT_ASSIGN notes at do_layer3() */
2028 ret = p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_ASSIGN, 0, NULL);
2029 if (mt_assign_pid == 0 || ret < 0)
2031 struct lcr_msg *message;
2033 add_trace("callref", NULL, "no free id");
2035 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2036 message->param.disconnectinfo.cause = 47;
2037 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2038 message_put(message);
2039 new_state(PORT_STATE_RELEASE);
2043 p_m_d_l3id = mt_assign_pid;
2045 add_trace("callref", "new", "0x%x", p_m_d_l3id);
2048 /* preparing setup message */
2049 l3m = create_l3msg();
2050 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_REQ, DIRECTION_OUT);
2051 /* channel information */
2052 if (channel >= 0) /* it should */
2054 enc_ie_channel_id(l3m, exclusive, channel);
2056 /* caller information */
2058 switch (p_callerinfo.ntype)
2060 case INFO_NTYPE_UNKNOWN:
2063 case INFO_NTYPE_INTERNATIONAL:
2066 case INFO_NTYPE_NATIONAL:
2069 case INFO_NTYPE_SUBSCRIBER:
2072 default: /* INFO_NTYPE_NOTPRESENT */
2076 switch (p_callerinfo.screen)
2078 case INFO_SCREEN_USER:
2081 default: /* INFO_SCREEN_NETWORK */
2085 switch (p_callerinfo.present)
2087 case INFO_PRESENT_ALLOWED:
2090 case INFO_PRESENT_RESTRICTED:
2093 default: /* INFO_PRESENT_NOTAVAIL */
2097 /* caller information 2 */
2099 switch (p_callerinfo.ntype2)
2101 case INFO_NTYPE_UNKNOWN:
2104 case INFO_NTYPE_INTERNATIONAL:
2107 case INFO_NTYPE_NATIONAL:
2110 case INFO_NTYPE_SUBSCRIBER:
2113 default: /* INFO_NTYPE_NOTPRESENT */
2117 switch (p_callerinfo.screen2)
2119 case INFO_SCREEN_USER:
2122 default: /* INFO_SCREEN_NETWORK */
2126 switch (p_callerinfo.present2)
2128 case INFO_PRESENT_ALLOWED:
2131 case INFO_PRESENT_RESTRICTED:
2134 default: /* INFO_PRESENT_NOTAVAIL */
2139 enc_ie_calling_pn(l3m, type, plan, present, screen, (unsigned char *)p_callerinfo.id, type2, plan2, present2, screen2, (unsigned char *)p_callerinfo.id2);
2140 /* dialing information */
2141 if (p_dialinginfo.id[0]) /* only if we have something to dial */
2143 enc_ie_called_pn(l3m, 0, 1, (unsigned char *)p_dialinginfo.id);
2145 /* sending complete */
2146 if (p_dialinginfo.sending_complete)
2147 enc_ie_complete(l3m, 1);
2148 /* sending user-user */
2149 if (param->setup.useruser.len)
2151 enc_ie_useruser(l3m, param->setup.useruser.protocol, param->setup.useruser.data, param->setup.useruser.len);
2153 /* redirecting number */
2155 switch (p_redirinfo.ntype)
2157 case INFO_NTYPE_UNKNOWN:
2160 case INFO_NTYPE_INTERNATIONAL:
2163 case INFO_NTYPE_NATIONAL:
2166 case INFO_NTYPE_SUBSCRIBER:
2169 default: /* INFO_NTYPE_NOTPRESENT */
2173 switch (p_redirinfo.screen)
2175 case INFO_SCREEN_USER:
2178 default: /* INFO_SCREE_NETWORK */
2182 switch (p_redirinfo.reason)
2184 case INFO_REDIR_BUSY:
2187 case INFO_REDIR_NORESPONSE:
2190 case INFO_REDIR_UNCONDITIONAL:
2193 case INFO_REDIR_CALLDEFLECT:
2196 case INFO_REDIR_OUTOFORDER:
2199 default: /* INFO_REDIR_UNKNOWN */
2203 switch (p_redirinfo.present)
2205 case INFO_PRESENT_ALLOWED:
2208 case INFO_PRESENT_RESTRICTED:
2211 default: /* INFO_PRESENT_NOTAVAIL */
2215 /* sending redirecting number only in ntmode */
2216 if (type >= 0 && (p_m_d_ntmode || p_m_d_tespecial))
2217 enc_ie_redir_nr(l3m, type, plan, present, screen, reason, (unsigned char *)p_redirinfo.id);
2218 /* bearer capability */
2219 //printf("hlc=%d\n",p_capainfo.hlc);
2221 capability = p_capainfo.bearer_capa;
2222 mode = p_capainfo.bearer_mode;
2223 rate = (mode==INFO_BMODE_CIRCUIT)?0x10:0x00;
2224 switch (p_capainfo.bearer_info1)
2226 case INFO_INFO1_NONE:
2230 user = p_capainfo.bearer_info1 & 0x7f;
2233 enc_ie_bearer(l3m, coding, capability, mode, rate, -1, user);
2240 hlc = p_capainfo.hlc & 0x7f;
2242 if (p_capainfo.exthlc)
2243 exthlc = p_capainfo.exthlc & 0x7f;
2244 enc_ie_hlc(l3m, coding, interpretation, presentation, hlc, exthlc);
2248 if (p_callerinfo.display[0] && (p_m_d_ntmode || p_m_d_tespecial))
2249 enc_ie_display(l3m, (unsigned char *)p_callerinfo.display);
2250 /* nt-mode: CNIP (calling name identification presentation) */
2251 // if (p_callerinfo.name[0] && (p_m_d_ntmode || p_m_d_tespecial))
2252 // enc_facility_centrex(&setup->FACILITY, dmsg, (unsigned char *)p_callerinfo.name, 1);
2255 /* send setup message now */
2256 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SETUP, p_m_d_l3id, l3m);
2258 new_state(PORT_STATE_OUT_SETUP);
2261 /* MESSAGE_FACILITY */
2262 void Pdss1::message_facility(unsigned int epoint_id, int message_id, union parameter *param)
2266 /* facility will not be sent to external lines */
2267 if (!p_m_d_ntmode && !p_m_d_tespecial)
2270 /* sending facility */
2271 l3m = create_l3msg();
2272 l1l2l3_trace_header(p_m_mISDNport, this, L3_FACILITY_REQ, DIRECTION_OUT);
2273 enc_ie_facility(l3m, (unsigned char *)param->facilityinfo.data, param->facilityinfo.len);
2275 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_FACILITY, p_m_d_l3id, l3m);
2278 /* MESSAGE_NOTIFY */
2279 void Pdss1::message_notify(unsigned int epoint_id, int message_id, union parameter *param)
2283 int plan = 0, type = -1, present = 0;
2285 if (param->notifyinfo.notify>INFO_NOTIFY_NONE)
2286 notify = param->notifyinfo.notify & 0x7f;
2289 if (p_state != PORT_STATE_CONNECT)
2291 /* notify only allowed in active state */
2297 switch (param->notifyinfo.ntype)
2299 case INFO_NTYPE_UNKNOWN:
2302 case INFO_NTYPE_INTERNATIONAL:
2305 case INFO_NTYPE_NATIONAL:
2308 case INFO_NTYPE_SUBSCRIBER:
2311 default: /* INFO_NTYPE_UNKNOWN */
2315 switch (param->notifyinfo.present)
2317 case INFO_PRESENT_ALLOWED:
2320 case INFO_PRESENT_RESTRICTED:
2323 default: /* INFO_PRESENT_NOTAVAIL */
2329 if (notify<0 && !param->notifyinfo.display[0])
2331 /* nothing to notify, nothing to display */
2337 if (p_state!=PORT_STATE_CONNECT)
2339 /* queue notification */
2340 if (p_m_d_notify_pending)
2341 message_free(p_m_d_notify_pending);
2342 p_m_d_notify_pending = message_create(ACTIVE_EPOINT(p_epointlist), p_serial, EPOINT_TO_PORT, message_id);
2343 memcpy(&p_m_d_notify_pending->param, param, sizeof(union parameter));
2346 /* sending notification */
2347 l3m = create_l3msg();
2348 l1l2l3_trace_header(p_m_mISDNport, this, L3_NOTIFY_REQ, DIRECTION_OUT);
2349 enc_ie_notify(l3m, notify);
2350 /* sending redirection number only in ntmode */
2351 if (type >= 0 && (p_m_d_ntmode || p_m_d_tespecial))
2352 enc_ie_redir_dn(l3m, type, plan, present, (unsigned char *)param->notifyinfo.id);
2353 if (param->notifyinfo.display[0] && (p_m_d_ntmode || p_m_d_tespecial))
2354 enc_ie_display(l3m, (unsigned char *)param->notifyinfo.display);
2356 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_NOTIFY, p_m_d_l3id, l3m);
2358 } else if (p_m_d_ntmode || p_m_d_tespecial)
2360 /* sending information */
2361 l3m = create_l3msg();
2362 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
2363 enc_ie_display(l3m, (unsigned char *)param->notifyinfo.display);
2365 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
2369 /* MESSAGE_OVERLAP */
2370 void Pdss1::message_overlap(unsigned int epoint_id, int message_id, union parameter *param)
2374 /* in case of sending complete, we proceed */
2375 if (p_dialinginfo.sending_complete)
2377 PDEBUG(DEBUG_ISDN, "sending proceeding instead of setup_acknowledge, because address is complete.\n");
2378 message_proceeding(epoint_id, message_id, param);
2382 /* sending setup_acknowledge */
2383 l3m = create_l3msg();
2384 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_ACKNOWLEDGE_REQ, DIRECTION_OUT);
2385 /* channel information */
2386 if (p_state == PORT_STATE_IN_SETUP)
2387 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2388 /* progress information */
2389 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2390 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2391 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2392 if (p_m_mISDNport->tones)
2393 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2395 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SETUP_ACKNOWLEDGE, p_m_d_l3id, l3m);
2397 new_state(PORT_STATE_IN_OVERLAP);
2400 /* MESSAGE_PROCEEDING */
2401 void Pdss1::message_proceeding(unsigned int epoint_id, int message_id, union parameter *param)
2405 /* sending proceeding */
2406 l3m = create_l3msg();
2407 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2408 /* channel information */
2409 if (p_state == PORT_STATE_IN_SETUP)
2410 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2411 /* progress information */
2412 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2413 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2414 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2415 if (p_m_mISDNport->tones)
2416 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2418 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2420 new_state(PORT_STATE_IN_PROCEEDING);
2423 /* MESSAGE_ALERTING */
2424 void Pdss1::message_alerting(unsigned int epoint_id, int message_id, union parameter *param)
2428 /* NT-MODE in setup state we must send PROCEEDING first */
2429 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2431 /* sending proceeding */
2432 l3m = create_l3msg();
2433 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2434 /* channel information */
2435 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2436 /* progress information */
2437 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2438 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2439 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2440 if (p_m_mISDNport->tones)
2441 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2443 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2444 new_state(PORT_STATE_IN_PROCEEDING);
2447 /* sending alerting */
2448 l3m = create_l3msg();
2449 l1l2l3_trace_header(p_m_mISDNport, this, L3_ALERTING_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_ALERTING, p_m_d_l3id, l3m);
2462 new_state(PORT_STATE_IN_ALERTING);
2465 /* MESSAGE_CONNECT */
2466 void Pdss1::message_connect(unsigned int epoint_id, int message_id, union parameter *param)
2469 int type, plan, present, screen;
2470 class Endpoint *epoint;
2472 /* NT-MODE in setup state we must send PROCEEDING first */
2473 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2475 /* sending proceeding */
2476 l3m = create_l3msg();
2477 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2478 /* channel information */
2479 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2481 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2482 new_state(PORT_STATE_IN_PROCEEDING);
2485 /* copy connected information */
2486 memcpy(&p_connectinfo, ¶m->connectinfo, sizeof(p_connectinfo));
2487 /* screen outgoing caller id */
2488 do_screen(1, p_connectinfo.id, sizeof(p_connectinfo.id), &p_connectinfo.ntype, &p_connectinfo.present, p_m_mISDNport->ifport->interface);
2490 /* only display at connect state */
2491 if (p_state == PORT_STATE_CONNECT)
2492 if (p_connectinfo.display[0])
2494 /* sending information */
2495 l3m = create_l3msg();
2496 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
2497 if (p_m_d_ntmode || p_m_d_tespecial)
2498 enc_ie_display(l3m, (unsigned char *)p_connectinfo.display);
2500 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
2504 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)
2506 /* connect command only possible in setup, proceeding or alerting state */
2510 /* preparing connect message */
2511 l3m = create_l3msg();
2512 l1l2l3_trace_header(p_m_mISDNport, this, L3_CONNECT_REQ, DIRECTION_OUT);
2513 /* connect information */
2515 switch (p_connectinfo.ntype)
2517 case INFO_NTYPE_UNKNOWN:
2520 case INFO_NTYPE_INTERNATIONAL:
2523 case INFO_NTYPE_NATIONAL:
2526 case INFO_NTYPE_SUBSCRIBER:
2529 default: /* INFO_NTYPE_NOTPRESENT */
2533 switch (param->connectinfo.screen)
2535 case INFO_SCREEN_USER:
2538 default: /* INFO_SCREE_NETWORK */
2542 switch (p_connectinfo.present)
2544 case INFO_PRESENT_ALLOWED:
2547 case INFO_PRESENT_RESTRICTED:
2550 default: /* INFO_PRESENT_NOTAVAIL */
2555 enc_ie_connected_pn(l3m, type, plan, present, screen, (unsigned char *)p_connectinfo.id);
2557 if (p_connectinfo.display[0] && (p_m_d_ntmode || p_m_d_tespecial))
2558 enc_ie_display(l3m, (unsigned char *)p_connectinfo.display);
2559 /* nt-mode: CONP (connected name identification presentation) */
2560 // if (p_connectinfo.name[0] && (p_m_d_ntmode || p_m_d_tespecial))
2561 // enc_facility_centrex(&connect->FACILITY, dmsg, (unsigned char *)p_connectinfo.name, 0);
2563 if (p_m_d_ntmode || p_m_d_tespecial)
2565 epoint = find_epoint_id(epoint_id);
2566 enc_ie_date(l3m, now, p_settings.no_seconds);
2569 /* finally send message */
2570 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CONNECT, p_m_d_l3id, l3m);
2573 new_state(PORT_STATE_CONNECT);
2575 new_state(PORT_STATE_CONNECT_WAITING);
2579 /* MESSAGE_DISCONNECT */
2580 void Pdss1::message_disconnect(unsigned int epoint_id, int message_id, union parameter *param)
2583 struct lcr_msg *message;
2586 /* we reject during incoming setup when we have no tones. also if we are in outgoing setup state */
2587 // if ((p_state==PORT_STATE_IN_SETUP && !p_m_mISDNport->tones)
2588 if (/* ||*/ p_state==PORT_STATE_OUT_SETUP)
2590 /* sending release to endpoint */
2593 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
2594 memcpy(&message->param, param, sizeof(union parameter));
2595 message_put(message);
2597 free_epointlist(p_epointlist);
2599 /* sending release */
2600 l3m = create_l3msg();
2601 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
2603 enc_ie_cause(l3m, (!p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_REMOTE:param->disconnectinfo.location, param->disconnectinfo.cause);
2605 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
2606 new_state(PORT_STATE_RELEASE);
2611 /* workarround: NT-MODE in setup state we must send PROCEEDING first to make it work */
2612 if (p_state==PORT_STATE_IN_SETUP)
2614 /* sending proceeding */
2615 l3m = create_l3msg();
2616 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2617 /* channel information */
2618 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2619 /* progress information */
2620 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2621 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2622 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2623 if (p_m_mISDNport->tones)
2624 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2626 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2627 new_state(PORT_STATE_IN_PROCEEDING);
2630 /* sending disconnect */
2631 l3m = create_l3msg();
2632 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_REQ, DIRECTION_OUT);
2633 /* progress information */
2634 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2635 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2636 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2637 if (p_m_mISDNport->tones)
2638 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2640 enc_ie_cause(l3m, (!p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_REMOTE:param->disconnectinfo.location, param->disconnectinfo.cause);
2642 if (param->disconnectinfo.display[0])
2643 p = param->disconnectinfo.display;
2644 if (p) if (*p && (p_m_d_ntmode || p_m_d_tespecial))
2645 enc_ie_display(l3m, (unsigned char *)p);
2647 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_DISCONNECT, p_m_d_l3id, l3m);
2648 new_state(PORT_STATE_OUT_DISCONNECT);
2651 /* MESSAGE_RELEASE */
2652 void Pdss1::message_release(unsigned int epoint_id, int message_id, union parameter *param)
2655 class Endpoint *epoint;
2659 * we may only release during incoming disconnect state.
2660 * this means that the endpoint doesnt require audio anymore
2662 if (p_state == PORT_STATE_IN_DISCONNECT
2663 || p_state == PORT_STATE_OUT_DISCONNECT)
2665 /* sending release */
2666 l3m = create_l3msg();
2667 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_REQ, DIRECTION_OUT);
2669 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2671 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE, p_m_d_l3id, l3m);
2672 new_state(PORT_STATE_RELEASE);
2674 free_epointid(epoint_id);
2675 // wait for callref to be released
2680 * if we are on incoming call setup, we may reject by sending a release_complete
2681 * also on outgoing call setup, we send a release complete, BUT this is not conform. (i don't know any other way)
2683 if (p_state==PORT_STATE_IN_SETUP
2684 || p_state==PORT_STATE_OUT_SETUP)
2686 //#warning remove me
2687 //PDEBUG(DEBUG_LOG, "JOLLY sending release complete %d\n", p_serial);
2688 /* sending release complete */
2689 l3m = create_l3msg();
2690 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_REQ, DIRECTION_OUT);
2692 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2694 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
2695 new_state(PORT_STATE_RELEASE);
2697 free_epointid(epoint_id);
2698 // wait for callref to be released
2703 wirklich erst proceeding?:
2704 /* NT-MODE in setup state we must send PROCEEDING first */
2705 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2707 CALL_PROCEEDING_t *proceeding;
2709 /* sending proceeding */
2710 l3m = create_l3msg();
2711 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2712 /* channel information */
2713 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2714 /* progress information */
2715 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2716 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2717 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2718 if (p_m_mISDNport->tones)
2719 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2721 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2725 /* sending disconnect */
2726 l3m = create_l3msg();
2727 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_REQ, DIRECTION_OUT);
2728 /* progress information */
2729 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2730 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2731 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2732 if (p_m_mISDNport->tones)
2733 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2735 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2737 epoint = find_epoint_id(epoint_id);
2738 if (param->disconnectinfo.display[0])
2739 p = param->disconnectinfo.display;
2740 if (p) if (*p && (p_m_d_ntmode || p_m_d_tespecial))
2741 enc_ie_display(l3m, (unsigned char *)p);
2743 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_DISCONNECT, p_m_d_l3id, l3m);
2744 new_state(PORT_STATE_OUT_DISCONNECT);
2746 free_epointid(epoint_id);
2747 // wait for release and callref to be released
2748 //#warning remove me
2749 //PDEBUG(DEBUG_LOG, "JOLLY sending disconnect %d\n", p_serial);
2754 * endpoint sends messages to the port
2756 int Pdss1::message_epoint(unsigned int epoint_id, int message_id, union parameter *param)
2758 if (PmISDN::message_epoint(epoint_id, message_id, param))
2763 case MESSAGE_INFORMATION: /* overlap dialing */
2764 if (p_type==PORT_TYPE_DSS1_NT_OUT
2765 && p_state!=PORT_STATE_OUT_OVERLAP
2766 && p_state!=PORT_STATE_CONNECT
2767 && p_state!=PORT_STATE_OUT_DISCONNECT
2768 && p_state!=PORT_STATE_IN_DISCONNECT)
2772 if (p_type==PORT_TYPE_DSS1_TE_OUT
2773 && p_state!=PORT_STATE_OUT_OVERLAP
2774 && p_state!=PORT_STATE_OUT_PROCEEDING
2775 && p_state!=PORT_STATE_OUT_ALERTING
2776 && p_state!=PORT_STATE_CONNECT
2777 && p_state!=PORT_STATE_OUT_DISCONNECT
2778 && p_state!=PORT_STATE_IN_DISCONNECT)
2782 if ((p_type==PORT_TYPE_DSS1_NT_IN || p_type==PORT_TYPE_DSS1_TE_IN)
2783 && p_state!=PORT_STATE_IN_OVERLAP
2784 && p_state!=PORT_STATE_IN_PROCEEDING
2785 && p_state!=PORT_STATE_IN_ALERTING
2786 && p_state!=PORT_STATE_CONNECT
2787 && p_state!=PORT_STATE_CONNECT_WAITING
2788 && p_state!=PORT_STATE_OUT_DISCONNECT
2789 && p_state!=PORT_STATE_IN_DISCONNECT)
2793 message_information(epoint_id, message_id, param);
2796 case MESSAGE_SETUP: /* dial-out command received from epoint */
2797 if (p_state!=PORT_STATE_IDLE
2798 && p_state!=PORT_STATE_CONNECT)
2800 PERROR("Pdss1(%s) ignoring setup because isdn port is not in idle state (or connected for sending display info).\n", p_name);
2803 if (p_epointlist && p_state==PORT_STATE_IDLE)
2804 FATAL("Pdss1(%s): epoint pointer is set in idle state, how bad!!\n", p_name);
2805 message_setup(epoint_id, message_id, param);
2808 case MESSAGE_NOTIFY: /* display and notifications */
2809 message_notify(epoint_id, message_id, param);
2812 case MESSAGE_FACILITY: /* facility message */
2813 message_facility(epoint_id, message_id, param);
2816 case MESSAGE_OVERLAP: /* more information is needed */
2817 if (p_state!=PORT_STATE_IN_SETUP)
2821 message_overlap(epoint_id, message_id, param);
2824 case MESSAGE_PROCEEDING: /* call of endpoint is proceeding */
2825 if (p_state!=PORT_STATE_IN_SETUP
2826 && p_state!=PORT_STATE_IN_OVERLAP)
2830 message_proceeding(epoint_id, message_id, param);
2833 case MESSAGE_ALERTING: /* call of endpoint is ringing */
2834 if (p_state!=PORT_STATE_IN_SETUP
2835 && p_state!=PORT_STATE_IN_OVERLAP
2836 && p_state!=PORT_STATE_IN_PROCEEDING)
2840 message_alerting(epoint_id, message_id, param);
2843 case MESSAGE_CONNECT: /* call of endpoint is connected */
2844 if (p_state!=PORT_STATE_IN_SETUP
2845 && p_state!=PORT_STATE_IN_OVERLAP
2846 && p_state!=PORT_STATE_IN_PROCEEDING
2847 && p_state!=PORT_STATE_IN_ALERTING
2848 && !(p_state==PORT_STATE_CONNECT && p_m_d_ntmode))
2852 message_connect(epoint_id, message_id, param);
2855 case MESSAGE_DISCONNECT: /* call has been disconnected */
2856 if (p_state!=PORT_STATE_IN_SETUP
2857 && p_state!=PORT_STATE_IN_OVERLAP
2858 && p_state!=PORT_STATE_IN_PROCEEDING
2859 && p_state!=PORT_STATE_IN_ALERTING
2860 && p_state!=PORT_STATE_OUT_SETUP
2861 && p_state!=PORT_STATE_OUT_OVERLAP
2862 && p_state!=PORT_STATE_OUT_PROCEEDING
2863 && p_state!=PORT_STATE_OUT_ALERTING
2864 && p_state!=PORT_STATE_CONNECT
2865 && p_state!=PORT_STATE_CONNECT_WAITING)
2869 message_disconnect(epoint_id, message_id, param);
2872 case MESSAGE_RELEASE: /* release isdn port */
2873 if (p_state==PORT_STATE_RELEASE)
2877 message_release(epoint_id, message_id, param);
2881 PERROR("Pdss1(%s) isdn port with (caller id %s) received a wrong message: %d\n", p_name, p_callerinfo.id, message_id);
2890 * data from isdn-stack (layer-3) to pbx (port class)
2892 int stack2manager(struct mISDNport *mISDNport, unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
2898 PDEBUG(DEBUG_ISDN, "cmd(0x%x) pid(0x%x)\n", cmd, pid);
2902 PDEBUG(DEBUG_ISDN, "ignoring dummy process from phone.\n");
2906 /* find Port object of type ISDN */
2911 if ((port->p_type & PORT_CLASS_mISDN_MASK) == PORT_CLASS_mISDN_DSS1)
2913 pdss1 = (class Pdss1 *)port;
2914 /* check out correct stack and id */
2915 if (pdss1->p_m_mISDNport == mISDNport)
2917 if (pdss1->p_m_d_l3id & MISDN_PID_CR_FLAG)
2919 /* local callref, so match value only */
2920 if ((pdss1->p_m_d_l3id & MISDN_PID_CRVAL_MASK) == (pid & MISDN_PID_CRVAL_MASK))
2924 /* remote callref, ref + channel id */
2925 if (pdss1->p_m_d_l3id == pid)
2933 /* aktueller prozess */
2936 if (cmd == MT_ASSIGN)
2938 /* stack gives us new layer 3 id (during connect) */
2939 l1l2l3_trace_header(mISDNport, pdss1, L3_NEW_L3ID_IND, DIRECTION_IN);
2940 add_trace("callref", "old", "0x%x", pdss1->p_m_d_l3id);
2941 /* nt-library now gives us a new id via CC_SETUP_CONFIRM */
2942 if ((pdss1->p_m_d_l3id&MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER)
2943 PERROR(" strange setup-procid 0x%x\n", pdss1->p_m_d_l3id);
2944 pdss1->p_m_d_l3id = pid;
2945 if (port->p_state == PORT_STATE_CONNECT)
2946 pdss1->p_m_d_ces = pid >> 16;
2947 add_trace("callref", "new", "0x%x", pdss1->p_m_d_l3id);
2951 /* if process id is master process, but a child disconnects */
2952 if (mISDNport->ntmode
2953 && (pid & MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER
2954 && (pdss1->p_m_d_l3id & MISDN_PID_CRTYPE_MASK) == MISDN_PID_MASTER)
2956 if (cmd == MT_DISCONNECT
2957 || cmd == MT_RELEASE)
2959 /* send special indication for child disconnect */
2960 pdss1->disconnect_ind_i(cmd, pid, l3m);
2963 if (cmd == MT_RELEASE_COMPLETE)
2966 /* if we have child pid and got different child pid message, ignore */
2967 if (mISDNport->ntmode
2968 && (pid & MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER
2969 && (pdss1->p_m_d_l3id & MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER
2970 && pid != pdss1->p_m_d_l3id)
2973 /* process message */
2974 pdss1->message_isdn(cmd, pid, l3m);
2982 /* creating port object, transparent until setup with hdlc */
2983 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
2984 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0, B_MODE_TRANSPARENT)))
2986 FATAL("Cannot create Port instance.\n");
2987 pdss1->message_isdn(cmd, pid, l3m);
2991 /* creating port object, transparent until setup with hdlc */
2992 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
2993 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0, B_MODE_TRANSPARENT)))
2994 FATAL("Cannot create Port instance.\n");
2995 pdss1->message_isdn(cmd, pid, l3m);
2999 PDEBUG(DEBUG_ISDN, "unused call ref released (l3id=0x%x)\n", pid);
3002 case MT_RELEASE_COMPLETE:
3003 PERROR("must be ignored by stack, not sent to app\n");
3007 // facility als broadcast
3011 PERROR("unhandled message: cmd(0x%x) pid(0x%x)\n", cmd, pid);
3015 if (port->p_type == PORT_TYPE_DSS1_NT_IN || port->p_type == PORT_TYPE_DSS1_NT_OUT)
3017 pdss1 = (class Pdss1 *)port;
3018 /* check out correct stack */
3019 if (pdss1->p_m_mISDNport == mISDNport)
3020 /* check out correct id */
3021 PERROR("unhandled message: pid=%x is not associated with port-dinfo=%x\n", pid, pdss1->p_m_d_l3id);
3033 * sending message that were queued during L1 activation
3034 * or releasing port if link is down
3036 void setup_queue(struct mISDNport *mISDNport, int link)
3040 struct lcr_msg *message;
3042 if (!mISDNport->ntmode)
3045 /* check all port objects for pending message */
3049 if ((port->p_type&PORT_CLASS_mISDN_MASK) == PORT_CLASS_mISDN_DSS1)
3051 pdss1 = (class Pdss1 *)port;
3052 if (pdss1->p_m_mISDNport == mISDNport)
3054 if (pdss1->p_m_d_queue)
3058 PDEBUG(DEBUG_ISDN, "the L1 became active, so we send queued message for portnum=%d (%s).\n", mISDNport->portnum, pdss1->p_name);
3059 /* LAYER 1 is up, so we send */
3060 pdss1->message_setup(pdss1->p_m_d_queue->id_from, pdss1->p_m_d_queue->type, &pdss1->p_m_d_queue->param);
3061 message_free(pdss1->p_m_d_queue);
3062 pdss1->p_m_d_queue = NULL;
3065 PDEBUG(DEBUG_ISDN, "the L1 became NOT active, so we release port for portnum=%d (%s).\n", mISDNport->portnum, pdss1->p_name);
3066 message = message_create(pdss1->p_serial, pdss1->p_m_d_queue->id_from, PORT_TO_EPOINT, MESSAGE_RELEASE);
3067 message->param.disconnectinfo.cause = 27;
3068 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
3069 message_put(message);
3070 pdss1->new_state(PORT_STATE_RELEASE);
3071 pdss1->p_m_delete = 1;