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) {
85 /*** we gave an exclusive channel (or if we are done) ***/
87 /* if not first reply, we are done */
88 if (p_state != PORT_STATE_OUT_SETUP)
91 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
92 add_trace("channel", "request", "%d (forced)", p_m_b_channel);
93 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
95 /* if give channel not accepted or not equal */
96 if (channel!=-1 && p_m_b_channel!=channel) {
97 add_trace("conclusion", NULL, "forced channel not accepted");
103 add_trace("conclusion", NULL, "channel was accepted");
104 add_trace("connect", "channel", "%d", p_m_b_channel);
107 /* activate our exclusive channel */
108 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
111 /*** we gave a non-exclusive channel ***/
113 /* if not first reply, we are done */
114 if (p_state != PORT_STATE_OUT_SETUP)
117 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
118 add_trace("channel", "request", "%d (suggest)", p_m_b_channel);
119 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
121 /* if channel was accepted as given */
122 if (channel==-1 || p_m_b_channel==channel) {
123 add_trace("conclusion", NULL, "channel was accepted as given");
124 add_trace("connect", "channel", "%d", p_m_b_channel);
126 p_m_b_exclusive = 1; // we are done
127 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
131 /* if channel value is faulty */
133 add_trace("conclusion", NULL, "illegal reply");
135 ret = -111; // protocol error
139 /* if channel was not accepted, try to get it */
140 ret = seize_bchannel(channel, 1); // exclusively
141 add_trace("channel", "available", ret<0?"no":"yes");
143 add_trace("conclusion", NULL, "replied channel not available");
147 add_trace("conclusion", NULL, "replied channel accepted");
148 add_trace("connect", "channel", "%d", p_m_b_channel);
151 /* activate channel given by remote */
152 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
155 /*** we sent 'any channel acceptable' ***/
157 /* if not first reply, we are done */
158 if (p_state != PORT_STATE_OUT_SETUP)
161 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
162 add_trace("channel", "request", "any");
163 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
164 /* if no channel was replied */
166 add_trace("conclusion", NULL, "no channel, protocol error");
168 ret = -111; // protocol error
172 /* we will see, if our received channel is available */
173 ret = seize_bchannel(channel, 1); // exclusively
174 add_trace("channel", "available", ret<0?"no":"yes");
176 add_trace("conclusion", NULL, "replied channel not available");
180 add_trace("conclusion", NULL, "replied channel accepted");
181 add_trace("connect", "channel", "%d", p_m_b_channel);
184 /* activate channel given by remote */
185 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
187 /*** we sent 'no channel available' ***/
189 /* if not the first reply, but a connect, we are forced */
190 if (cmd==MT_CONNECT && p_state!=PORT_STATE_OUT_SETUP) {
191 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (connect)", DIRECTION_NONE);
192 add_trace("channel", "request", "no-channel");
193 add_trace("channel", "reply", (channel>=0)?"%d%s":"(none)", channel, exclusive?" (forced)":"");
195 goto use_from_connect;
197 ret = seize_bchannel(CHANNEL_ANY, 0); // any channel
198 add_trace("channel", "available", ret<0?"no":"yes");
200 add_trace("conclusion", NULL, "no channel available during call-waiting");
204 add_trace("conclusion", NULL, "using channel %d", p_m_b_channel);
205 add_trace("connect", "channel", "%d", p_m_b_channel);
207 p_m_b_exclusive = 1; // we are done
209 /* activate channel given by remote */
210 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
214 /* if not first reply, we are done */
215 if (p_state != PORT_STATE_OUT_SETUP)
218 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
219 add_trace("channel", "request", "no-channel");
220 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
221 /* if first reply has no channel, we are done */
223 add_trace("conclusion", NULL, "no channel until connect");
228 /* we will see, if our received channel is available */
230 ret = seize_bchannel(channel, exclusive);
231 add_trace("channel", "available", ret<0?"no":"yes");
233 add_trace("conclusion", NULL, "replied channel not available");
237 add_trace("conclusion", NULL, "replied channel accepted");
238 add_trace("connect", "channel", "%d", p_m_b_channel);
240 p_m_b_exclusive = 1; // we are done
242 /* activate channel given by remote */
243 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
249 * NOTE: we send MT_RELEASE_COMPLETE to "REJECT" the channel
250 * in response to the setup reply
252 l3m = create_l3msg();
253 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
254 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
256 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
257 new_state(PORT_STATE_RELEASE);
259 return(-34); /* to epoint: no channel available */
264 * hunt bchannel for incoming setup or retrieve or resume
266 int Pdss1::hunt_bchannel(int channel, int exclusive)
268 struct select_channel *selchannel;
269 struct interface_port *ifport = p_m_mISDNport->ifport;
272 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (setup)", DIRECTION_NONE);
275 if (channel == CHANNEL_NO)
276 add_trace("channel", "request", "no-channel");
278 add_trace("channel", "request", (channel>0)?"%d%s":"any", channel, exclusive?" (forced)":"");
279 if (channel==CHANNEL_NO && p_type==PORT_TYPE_DSS1_TE_IN) {
280 add_trace("conclusion", NULL, "incoming call-waiting not supported for TE-mode");
282 return(-6); // channel unacceptable
284 if (channel <= 0) /* not given, no channel, whatever.. */
285 channel = CHANNEL_ANY; /* any channel */
286 add_trace("channel", "reserved", "%d", p_m_mISDNport->b_reserved);
287 if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num) { // of out chan..
288 add_trace("conclusion", NULL, "all channels are reserved");
290 return(-34); // no channel
292 if (channel == CHANNEL_ANY)
295 /* check for given channel in selection list */
296 selchannel = ifport->in_channel;
298 if (selchannel->channel == channel || selchannel->channel == CHANNEL_FREE)
300 selchannel = selchannel->next;
305 /* exclusive channel requests must be in the list */
307 /* no exclusive channel */
309 add_trace("conclusion", NULL, "exclusively requested channel not in list");
311 return(-6); // channel unacceptable
313 /* get index for channel */
314 i = channel-1-(channel>=17);
315 if (i < 0 || i >= p_m_mISDNport->b_num || channel == 16) {
316 add_trace("conclusion", NULL, "exclusively requested channel outside interface range");
318 return(-6); // channel unacceptable
321 if (p_m_mISDNport->b_port[i] == NULL)
323 add_trace("conclusion", NULL, "exclusively requested channel is busy");
325 return(-6); // channel unacceptable
328 /* requested channels in list will be used */
330 /* get index for channel */
331 i = channel-1-(channel>=17);
332 if (i < 0 || i >= p_m_mISDNport->b_num || channel == 16) {
333 add_trace("info", NULL, "requested channel %d outside interface range", channel);
334 } else /* if inside range (else) check if available */
335 if (p_m_mISDNport->b_port[i] == NULL)
339 /* if channel is not available or not in list, it must be searched */
341 /* check for first free channel in list */
343 selchannel = ifport->in_channel;
345 switch(selchannel->channel) {
346 case CHANNEL_FREE: /* free channel */
347 add_trace("hunting", "channel", "free");
348 if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num)
349 break; /* all channel in use or reserverd */
352 while(i < p_m_mISDNport->b_num) {
353 if (p_m_mISDNport->b_port[i] == NULL) {
354 channel = i+1+(i>=15);
362 add_trace("hunting", "channel", "%d", selchannel->channel);
363 if (selchannel->channel<1 || selchannel->channel==16)
364 break; /* invalid channels */
365 i = selchannel->channel-1-(selchannel->channel>=17);
366 if (i >= p_m_mISDNport->b_num)
367 break; /* channel not in port */
368 if (p_m_mISDNport->b_port[i] == NULL) {
369 channel = selchannel->channel;
375 break; /* found channel */
376 selchannel = selchannel->next;
379 add_trace("conclusion", NULL, "no channel available");
381 return(-6); // channel unacceptable
385 add_trace("conclusion", NULL, "channel available");
386 add_trace("connect", "channel", "%d", channel);
392 * handles all indications
394 /* CC_SETUP INDICATION */
395 void Pdss1::setup_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
397 int calling_type, calling_plan, calling_present, calling_screen;
398 int calling_type2, calling_plan2, calling_present2, calling_screen2;
399 int called_type, called_plan;
400 int redir_type, redir_plan, redir_present, redir_screen, redir_reason;
401 int hlc_coding, hlc_presentation, hlc_interpretation, hlc_hlc, hlc_exthlc;
402 int bearer_coding, bearer_capability, bearer_mode, bearer_rate, bearer_multi, bearer_user;
403 int exclusive, channel;
405 unsigned char keypad[32] = "";
406 unsigned char useruser[128];
407 int useruser_len = 0, useruser_protocol;
408 class Endpoint *epoint;
409 struct lcr_msg *message;
411 /* process given callref */
412 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_IND, DIRECTION_IN);
413 add_trace("callref", "new", "0x%x", pid);
415 /* release in case the ID is already in use */
416 add_trace("error", NULL, "callref already in use");
418 l3m = create_l3msg();
419 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
420 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47);
421 add_trace("reason", NULL, "callref already in use");
423 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, pid, l3m);
424 new_state(PORT_STATE_RELEASE);
429 p_m_d_ces = pid >> 16;
432 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_IND, DIRECTION_IN);
433 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));
434 dec_ie_called_pn(l3m, &called_type, &called_plan, (unsigned char *)p_dialinginfo.id, sizeof(p_dialinginfo.id));
435 dec_ie_keypad(l3m, (unsigned char *)keypad, sizeof(keypad));
436 /* te-mode: CNIP (calling name identification presentation) */
437 dec_facility_centrex(l3m, (unsigned char *)p_callerinfo.name, sizeof(p_callerinfo.name));
438 dec_ie_useruser(l3m, &useruser_protocol, useruser, &useruser_len);
439 dec_ie_complete(l3m, &p_dialinginfo.sending_complete);
440 dec_ie_redir_nr(l3m, &redir_type, &redir_plan, &redir_present, &redir_screen, &redir_reason, (unsigned char *)p_redirinfo.id, sizeof(p_redirinfo.id));
441 dec_ie_channel_id(l3m, &exclusive, &channel);
442 dec_ie_hlc(l3m, &hlc_coding, &hlc_interpretation, &hlc_presentation, &hlc_hlc, &hlc_exthlc);
443 dec_ie_bearer(l3m, &bearer_coding, &bearer_capability, &bearer_mode, &bearer_rate, &bearer_multi, &bearer_user);
444 dec_ie_display(l3m, (unsigned char *)p_dialinginfo.display, sizeof(p_dialinginfo.display));
447 /* if blocked, release call with MT_RELEASE_COMPLETE */
448 if (p_m_mISDNport->ifport->block) {
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, 27); /* temporary unavailable */
452 add_trace("reason", NULL, "port blocked");
454 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
455 new_state(PORT_STATE_RELEASE);
461 switch (calling_present) {
463 p_callerinfo.present = INFO_PRESENT_RESTRICTED;
466 p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
469 p_callerinfo.present = INFO_PRESENT_ALLOWED;
472 switch (calling_screen) {
474 p_callerinfo.screen = INFO_SCREEN_USER;
477 p_callerinfo.screen = INFO_SCREEN_NETWORK;
480 switch (calling_type) {
482 p_callerinfo.ntype = INFO_NTYPE_NOTPRESENT;
485 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
488 p_callerinfo.ntype = INFO_NTYPE_INTERNATIONAL;
491 p_callerinfo.ntype = INFO_NTYPE_NATIONAL;
494 p_callerinfo.ntype = INFO_NTYPE_SUBSCRIBER;
497 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
500 p_callerinfo.isdn_port = p_m_portnum;
501 SCPY(p_callerinfo.interface, p_m_mISDNport->ifport->interface->name);
504 switch (calling_present2) {
506 p_callerinfo.present2 = INFO_PRESENT_RESTRICTED;
509 p_callerinfo.present2 = INFO_PRESENT_NOTAVAIL;
512 p_callerinfo.present2 = INFO_PRESENT_ALLOWED;
515 switch (calling_screen2) {
517 p_callerinfo.screen2 = INFO_SCREEN_USER;
520 p_callerinfo.screen2 = INFO_SCREEN_NETWORK;
523 switch (calling_type2) {
525 p_callerinfo.ntype2 = INFO_NTYPE_NOTPRESENT;
528 p_callerinfo.ntype2 = INFO_NTYPE_UNKNOWN;
531 p_callerinfo.ntype2 = INFO_NTYPE_INTERNATIONAL;
534 p_callerinfo.ntype2 = INFO_NTYPE_NATIONAL;
537 p_callerinfo.ntype2 = INFO_NTYPE_SUBSCRIBER;
540 p_callerinfo.ntype2 = INFO_NTYPE_UNKNOWN;
544 /* dialing information */
545 SCAT(p_dialinginfo.id, (char *)keypad);
546 switch (called_type) {
548 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
551 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
554 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
557 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
562 switch (redir_present) {
564 p_redirinfo.present = INFO_PRESENT_RESTRICTED;
567 p_redirinfo.present = INFO_PRESENT_NOTAVAIL;
570 p_redirinfo.present = INFO_PRESENT_ALLOWED;
573 switch (redir_screen) {
575 p_redirinfo.screen = INFO_SCREEN_USER;
578 p_redirinfo.screen = INFO_SCREEN_NETWORK;
581 switch (redir_reason) {
583 p_redirinfo.reason = INFO_REDIR_BUSY;
586 p_redirinfo.reason = INFO_REDIR_NORESPONSE;
589 p_redirinfo.reason = INFO_REDIR_UNCONDITIONAL;
592 p_redirinfo.reason = INFO_REDIR_CALLDEFLECT;
595 p_redirinfo.reason = INFO_REDIR_OUTOFORDER;
598 p_redirinfo.reason = INFO_REDIR_UNKNOWN;
601 switch (redir_type) {
603 p_redirinfo.ntype = INFO_NTYPE_NOTPRESENT;
606 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
609 p_redirinfo.ntype = INFO_NTYPE_INTERNATIONAL;
612 p_redirinfo.ntype = INFO_NTYPE_NATIONAL;
615 p_redirinfo.ntype = INFO_NTYPE_SUBSCRIBER;
618 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
621 p_redirinfo.isdn_port = p_m_portnum;
623 /* bearer capability */
624 switch (bearer_capability) {
626 p_capainfo.bearer_capa = INFO_BC_AUDIO;
627 bearer_user = (options.law=='a')?3:2;
630 p_capainfo.bearer_capa = bearer_capability;
633 switch (bearer_mode) {
635 p_capainfo.bearer_mode = INFO_BMODE_PACKET;
638 p_capainfo.bearer_mode = INFO_BMODE_CIRCUIT;
641 switch (bearer_user) {
643 p_capainfo.bearer_info1 = INFO_INFO1_NONE;
646 p_capainfo.bearer_info1 = bearer_user + 0x80;
653 p_capainfo.hlc = INFO_HLC_NONE;
656 p_capainfo.hlc = hlc_hlc + 0x80;
659 switch (hlc_exthlc) {
661 p_capainfo.exthlc = INFO_HLC_NONE;
664 p_capainfo.exthlc = hlc_exthlc + 0x80;
668 /* set bchannel mode */
669 if (p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED
670 || p_capainfo.bearer_capa==INFO_BC_DATARESTRICTED
671 || p_capainfo.bearer_capa==INFO_BC_VIDEO)
672 p_capainfo.source_mode = B_MODE_HDLC;
674 p_capainfo.source_mode = B_MODE_TRANSPARENT;
675 p_m_b_mode = p_capainfo.source_mode;
678 ret = channel = hunt_bchannel(channel, exclusive);
683 ret = seize_bchannel(channel, 1);
687 * NOTE: we send MT_RELEASE_COMPLETE to "REJECT" the channel
688 * in response to the setup
690 l3m = create_l3msg();
691 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
692 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
694 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
695 new_state(PORT_STATE_RELEASE);
699 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
701 /* create endpoint */
703 FATAL("Incoming call but already got an endpoint.\n");
704 if (!(epoint = new Endpoint(p_serial, 0)))
705 FATAL("No memory for Endpoint instance\n");
706 if (!(epoint->ep_app = new DEFAULT_ENDPOINT_APP(epoint, 0))) //incoming
707 FATAL("No memory for Endpoint Application instance\n");
708 epointlist_new(epoint->ep_serial);
710 /* send setup message to endpoit */
711 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_SETUP);
712 message->param.setup.isdn_port = p_m_portnum;
713 message->param.setup.port_type = p_type;
714 // message->param.setup.dtmf = !p_m_mISDNport->ifport->nodtmf;
715 memcpy(&message->param.setup.dialinginfo, &p_dialinginfo, sizeof(struct dialing_info));
716 memcpy(&message->param.setup.callerinfo, &p_callerinfo, sizeof(struct caller_info));
717 memcpy(&message->param.setup.redirinfo, &p_redirinfo, sizeof(struct redir_info));
718 memcpy(&message->param.setup.capainfo, &p_capainfo, sizeof(struct capa_info));
719 memcpy(message->param.setup.useruser.data, &useruser, useruser_len);
720 message->param.setup.useruser.len = useruser_len;
721 message->param.setup.useruser.protocol = useruser_protocol;
722 message_put(message);
724 new_state(PORT_STATE_IN_SETUP);
727 /* CC_INFORMATION INDICATION */
728 void Pdss1::information_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
731 unsigned char keypad[32] = "", display[128] = "";
732 struct lcr_msg *message;
734 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_IND, DIRECTION_IN);
735 dec_ie_called_pn(l3m, &type, &plan, (unsigned char *)p_dialinginfo.id, sizeof(p_dialinginfo.id));
736 dec_ie_keypad(l3m, (unsigned char *)keypad, sizeof(keypad));
737 dec_ie_display(l3m, (unsigned char *)display, sizeof(display));
738 dec_ie_complete(l3m, &p_dialinginfo.sending_complete);
741 SCAT(p_dialinginfo.id, (char *)keypad);
744 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
747 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
750 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
753 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
756 SCAT(p_dialinginfo.display, (char *)display);
757 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_INFORMATION);
758 memcpy(&message->param.information, &p_dialinginfo, sizeof(struct dialing_info));
759 message_put(message);
760 /* reset overlap timeout */
764 /* CC_SETUP_ACCNOWLEDGE INDICATION */
765 void Pdss1::setup_acknowledge_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
767 int exclusive, channel;
768 int coding, location, progress;
770 struct lcr_msg *message;
771 int max = p_m_mISDNport->ifport->dialmax;
775 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_ACKNOWLEDGE_IND, DIRECTION_IN);
776 dec_ie_channel_id(l3m, &exclusive, &channel);
777 dec_ie_progress(l3m, &coding, &location, &progress);
780 /* process channel */
781 ret = received_first_reply_to_setup(cmd, channel, exclusive);
783 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
784 message->param.disconnectinfo.cause = -ret;
785 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
786 message_put(message);
787 new_state(PORT_STATE_RELEASE);
792 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_OVERLAP);
793 message_put(message);
795 new_state(PORT_STATE_OUT_OVERLAP);
797 number = p_m_d_queue;
798 while (number[0]) { /* as long we have something to dial */
799 if (max > (int)strlen(number) || max == 0)
800 max = (int)strlen(number);
802 nl3m = create_l3msg();
803 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
804 enc_ie_called_pn(nl3m, 0, 1, (unsigned char *)number, max);
806 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, nl3m);
809 p_m_d_queue[0] = '\0';
812 /* CC_PROCEEDING INDICATION */
813 void Pdss1::proceeding_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
815 int exclusive, channel;
816 int coding, location, progress;
818 struct lcr_msg *message;
819 int notify = -1, type, plan, present;
822 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_IND, DIRECTION_IN);
823 dec_ie_channel_id(l3m, &exclusive, &channel);
824 dec_ie_progress(l3m, &coding, &location, &progress);
825 dec_ie_notify(l3m, ¬ify);
826 dec_ie_redir_dn(l3m, &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
829 ret = received_first_reply_to_setup(cmd, channel, exclusive);
831 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
832 message->param.disconnectinfo.cause = -ret;
833 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
834 message_put(message);
835 new_state(PORT_STATE_RELEASE);
839 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROCEEDING);
840 message_put(message);
842 new_state(PORT_STATE_OUT_PROCEEDING);
848 if (type >= 0 || notify) {
849 if (!notify && type >= 0)
851 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
852 message->param.notifyinfo.notify = notify;
853 SCPY(message->param.notifyinfo.id, redir);
854 /* redirection number */
857 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
860 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
863 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
868 message->param.notifyinfo.ntype = INFO_NTYPE_NOTPRESENT;
871 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
874 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
877 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
880 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
883 message->param.notifyinfo.isdn_port = p_m_portnum;
884 message_put(message);
888 /* CC_ALERTING INDICATION */
889 void Pdss1::alerting_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
891 int exclusive, channel;
892 int coding, location, progress;
894 struct lcr_msg *message;
895 int notify = -1, type, plan, present;
898 l1l2l3_trace_header(p_m_mISDNport, this, L3_ALERTING_IND, DIRECTION_IN);
899 dec_ie_channel_id(l3m, &exclusive, &channel);
900 dec_ie_progress(l3m, &coding, &location, &progress);
901 dec_ie_notify(l3m, ¬ify);
902 dec_ie_redir_dn(l3m, &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
905 /* process channel */
906 ret = received_first_reply_to_setup(cmd, channel, exclusive);
908 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
909 message->param.disconnectinfo.cause = -ret;
910 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
911 message_put(message);
912 new_state(PORT_STATE_RELEASE);
916 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_ALERTING);
917 message_put(message);
919 new_state(PORT_STATE_OUT_ALERTING);
925 if (type >= 0 || notify) {
926 if (!notify && type >= 0)
928 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
929 message->param.notifyinfo.notify = notify;
930 SCPY(message->param.notifyinfo.id, redir);
933 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
936 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
939 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
944 message->param.notifyinfo.ntype = INFO_NTYPE_NOTPRESENT;
947 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
950 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
953 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
956 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
959 message->param.notifyinfo.isdn_port = p_m_portnum;
960 message_put(message);
964 /* CC_CONNECT INDICATION */
965 void Pdss1::connect_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
967 int exclusive, channel;
968 int type, plan, present, screen;
970 struct lcr_msg *message;
973 l1l2l3_trace_header(p_m_mISDNport, this, L3_CONNECT_IND, DIRECTION_IN);
974 dec_ie_channel_id(l3m, &exclusive, &channel);
975 dec_ie_connected_pn(l3m, &type, &plan, &present, &screen, (unsigned char *)p_connectinfo.id, sizeof(p_connectinfo.id));
976 dec_ie_display(l3m, (unsigned char *)p_connectinfo.display, sizeof(p_connectinfo.display));
977 /* te-mode: CONP (connected name identification presentation) */
978 dec_facility_centrex(l3m, (unsigned char *)p_connectinfo.name, sizeof(p_connectinfo.name));
982 bchannel_before = p_m_b_channel;
983 ret = received_first_reply_to_setup(cmd, channel, exclusive);
985 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
986 message->param.disconnectinfo.cause = -ret;
987 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
988 message_put(message);
989 new_state(PORT_STATE_RELEASE);
994 /* connect information */
997 p_connectinfo.present = INFO_PRESENT_RESTRICTED;
1000 p_connectinfo.present = INFO_PRESENT_NOTAVAIL;
1003 p_connectinfo.present = INFO_PRESENT_ALLOWED;
1008 p_connectinfo.screen = INFO_SCREEN_USER;
1011 p_connectinfo.screen = INFO_SCREEN_NETWORK;
1016 p_connectinfo.ntype = INFO_NTYPE_NOTPRESENT;
1019 p_connectinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1022 p_connectinfo.ntype = INFO_NTYPE_NATIONAL;
1025 p_connectinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1028 p_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1031 p_connectinfo.isdn_port = p_m_portnum;
1032 SCPY(p_connectinfo.interface, p_m_mISDNport->ifport->interface->name);
1034 /* only in nt-mode we send connect ack. in te-mode it is done by stack itself or optional */
1036 /* send connect acknowledge */
1037 l3m = create_l3msg();
1038 l1l2l3_trace_header(p_m_mISDNport, this, L3_CONNECT_RES, DIRECTION_OUT);
1039 /* if we had no bchannel before, we send it now */
1040 if (!bchannel_before && p_m_b_channel)
1041 enc_ie_channel_id(l3m, 1, p_m_b_channel);
1043 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CONNECT_ACKNOWLEDGE, p_m_d_l3id, l3m);
1046 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CONNECT);
1047 memcpy(&message->param.connectinfo, &p_connectinfo, sizeof(struct connect_info));
1048 message_put(message);
1050 new_state(PORT_STATE_CONNECT);
1053 /* CC_DISCONNECT INDICATION */
1054 void Pdss1::disconnect_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1056 int location, cause;
1057 int coding, proglocation, progress;
1058 struct lcr_msg *message;
1059 unsigned char display[128] = "";
1061 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_IND, DIRECTION_IN);
1062 dec_ie_progress(l3m, &coding, &proglocation, &progress);
1063 dec_ie_cause(l3m, &location, &cause);
1064 dec_ie_display(l3m, (unsigned char *)display, sizeof(display));
1070 /* release if remote sends us no tones */
1071 if (!p_m_mISDNport->earlyb) {
1074 l3m = create_l3msg();
1075 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_REQ, DIRECTION_OUT);
1076 enc_ie_cause(l3m, location, cause); /* normal */
1077 add_trace("reason", NULL, "no remote patterns");
1079 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE, p_m_d_l3id, l3m);
1081 /* sending release to endpoint */
1082 if (location == LOCATION_PRIVATE_LOCAL)
1083 location = LOCATION_PRIVATE_REMOTE;
1084 while(p_epointlist) {
1085 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1086 message->param.disconnectinfo.cause = cause;
1087 message->param.disconnectinfo.location = location;
1088 SCAT(message->param.disconnectinfo.display, (char *)display);
1089 message_put(message);
1091 free_epointlist(p_epointlist);
1093 new_state(PORT_STATE_RELEASE);
1098 /* sending disconnect to active endpoint and release to inactive endpoints */
1099 if (location == LOCATION_PRIVATE_LOCAL)
1100 location = LOCATION_PRIVATE_REMOTE;
1101 if (ACTIVE_EPOINT(p_epointlist)) {
1102 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DISCONNECT);
1103 message->param.disconnectinfo.location = location;
1104 message->param.disconnectinfo.cause = cause;
1105 SCAT(message->param.disconnectinfo.display, (char *)display);
1106 message_put(message);
1108 while(INACTIVE_EPOINT(p_epointlist)) {
1109 message = message_create(p_serial, INACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1110 message->param.disconnectinfo.location = location;
1111 message->param.disconnectinfo.cause = cause;
1112 SCAT(message->param.disconnectinfo.display, (char *)display);
1113 message_put(message);
1115 free_epointid(INACTIVE_EPOINT(p_epointlist));
1117 new_state(PORT_STATE_IN_DISCONNECT);
1120 /* CC_DISCONNECT INDICATION */
1121 void Pdss1::disconnect_ind_i(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1123 int location, cause;
1126 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_IND, DIRECTION_IN);
1127 if (p_m_d_collect_cause > 0) {
1128 add_trace("old-cause", "location", "%d", p_m_d_collect_location);
1129 add_trace("old-cause", "value", "%d", p_m_d_collect_cause);
1131 dec_ie_cause(l3m, &location, &cause);
1132 if (location == LOCATION_PRIVATE_LOCAL)
1133 location = LOCATION_PRIVATE_REMOTE;
1136 collect_cause(&p_m_d_collect_cause, &p_m_d_collect_location, cause, location);
1137 add_trace("new-cause", "location", "%d", p_m_d_collect_location);
1138 add_trace("new-cause", "value", "%d", p_m_d_collect_cause);
1143 /* CC_RELEASE INDICATION */
1144 void Pdss1::release_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1146 int location, cause;
1147 struct lcr_msg *message;
1148 unsigned char display[128] = "";
1150 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_IND, DIRECTION_IN);
1151 dec_ie_cause(l3m, &location, &cause);
1152 dec_ie_display(l3m, (unsigned char *)display, sizeof(display));
1158 /* sending release to endpoint */
1159 if (location == LOCATION_PRIVATE_LOCAL)
1160 location = LOCATION_PRIVATE_REMOTE;
1161 while(p_epointlist) {
1162 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1163 message->param.disconnectinfo.cause = cause;
1164 message->param.disconnectinfo.location = location;
1165 SCAT(message->param.disconnectinfo.display, (char *)display);
1166 message_put(message);
1168 free_epointlist(p_epointlist);
1171 new_state(PORT_STATE_RELEASE);
1175 /* CC_RESTART INDICATION */
1176 void Pdss1::restart_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1178 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESTART_IND, DIRECTION_IN);
1181 // L3 process is not toucht. (not even by network stack)
1184 /* CC_RELEASE_COMPLETE INDICATION (a reject) */
1185 void Pdss1::release_complete_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1187 int location, cause;
1188 struct lcr_msg *message;
1190 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_IND, DIRECTION_IN);
1191 /* in case layer 2 is down during setup, we send cause 27 loc 5 */
1192 if (p_state == PORT_STATE_OUT_SETUP && p_m_mISDNport->l1link == 0) {
1196 dec_ie_cause(l3m, &location, &cause);
1197 if (p_m_mISDNport->l1link < 0)
1198 add_trace("layer 1", NULL, "unknown");
1200 add_trace("layer 1", NULL, (p_m_mISDNport->l1link)?"up":"down");
1203 if (location == LOCATION_PRIVATE_LOCAL)
1204 location = LOCATION_PRIVATE_REMOTE;
1209 /* sending release to endpoint */
1210 while(p_epointlist) {
1211 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1212 message->param.disconnectinfo.cause = cause;
1213 message->param.disconnectinfo.location = location;
1214 message_put(message);
1216 free_epointlist(p_epointlist);
1219 new_state(PORT_STATE_RELEASE);
1224 void Pdss1::t312_timeout_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1226 // not required, release is performed with MT_FREE
1229 /* CC_NOTIFY INDICATION */
1230 void Pdss1::notify_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1232 struct lcr_msg *message;
1233 int notify, type, plan, present;
1234 unsigned char notifyid[sizeof(message->param.notifyinfo.id)];
1235 unsigned char display[128] = "";
1237 l1l2l3_trace_header(p_m_mISDNport, this, L3_NOTIFY_IND, DIRECTION_IN);
1238 dec_ie_notify(l3m, ¬ify);
1239 dec_ie_redir_dn(l3m, &type, &plan, &present, notifyid, sizeof(notifyid));
1240 dec_ie_display(l3m, (unsigned char *)display, sizeof(display));
1243 if (!ACTIVE_EPOINT(p_epointlist))
1245 /* notification indicator */
1249 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1250 message->param.notifyinfo.notify = notify;
1251 SCPY(message->param.notifyinfo.id, (char *)notifyid);
1252 /* redirection number */
1255 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1258 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1261 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1266 message->param.notifyinfo.ntype = INFO_NTYPE_NOTPRESENT;
1269 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1272 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1275 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1278 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1281 SCAT(message->param.notifyinfo.display, (char *)display);
1282 message->param.notifyinfo.isdn_port = p_m_portnum;
1283 message_put(message);
1287 /* CC_HOLD INDICATION */
1288 struct lcr_msg *message;
1289 void Pdss1::hold_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1291 // class Endpoint *epoint;
1293 l1l2l3_trace_header(p_m_mISDNport, this, L3_HOLD_IND, DIRECTION_IN);
1296 if (!ACTIVE_EPOINT(p_epointlist) || p_m_hold) {
1297 l3m = create_l3msg();
1298 l1l2l3_trace_header(p_m_mISDNport, this, L3_HOLD_REJECT_REQ, DIRECTION_OUT);
1299 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, p_m_hold?101:31); /* normal unspecified / incompatible state */
1300 add_trace("reason", NULL, "no endpoint");
1302 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_HOLD_REJECT, p_m_d_l3id, l3m);
1307 /* notify the hold of call */
1308 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1309 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_HOLD;
1310 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1311 message_put(message);
1313 /* deactivate bchannel */
1314 chan_trace_header(p_m_mISDNport, this, "CHANNEL RELEASE (hold)", DIRECTION_NONE);
1315 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1319 /* set hold state */
1322 epoint = find_epoint_id(ACTIVE_EPOINT(p_epointlist));
1323 if (epoint && p_m_d_ntmode) {
1324 p_m_timeout = p_settings.tout_hold;
1329 /* acknowledge hold */
1330 l3m = create_l3msg();
1331 l1l2l3_trace_header(p_m_mISDNport, this, L3_HOLD_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1333 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_HOLD_ACKNOWLEDGE, p_m_d_l3id, l3m);
1337 /* CC_RETRIEVE INDICATION */
1338 void Pdss1::retrieve_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1340 struct lcr_msg *message;
1341 int channel, exclusive, cause;
1344 l1l2l3_trace_header(p_m_mISDNport, this, L3_RETRIEVE_IND, DIRECTION_IN);
1345 dec_ie_channel_id(l3m, &exclusive, &channel);
1349 cause = 101; /* incompatible state */
1352 l3m = create_l3msg();
1353 l1l2l3_trace_header(p_m_mISDNport, this, L3_RETRIEVE_REJECT_REQ, DIRECTION_OUT);
1354 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, cause);
1356 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RETRIEVE_REJECT, p_m_d_l3id, l3m);
1361 /* notify the retrieve of call */
1362 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1363 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_RETRIEVAL;
1364 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1365 message_put(message);
1368 ret = channel = hunt_bchannel(channel, exclusive);
1373 ret = seize_bchannel(channel, 1);
1379 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
1381 /* set hold state */
1385 /* acknowledge retrieve */
1386 l3m = create_l3msg();
1387 l1l2l3_trace_header(p_m_mISDNport, this, L3_RETRIEVE_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1388 enc_ie_channel_id(l3m, 1, p_m_b_channel);
1390 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RETRIEVE_ACKNOWLEDGE, p_m_d_l3id, l3m);
1393 /* CC_SUSPEND INDICATION */
1394 void Pdss1::suspend_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1396 struct lcr_msg *message;
1397 class Endpoint *epoint;
1398 unsigned char callid[8];
1400 int ret = -31; /* normal, unspecified */
1402 l1l2l3_trace_header(p_m_mISDNport, this, L3_SUSPEND_IND, DIRECTION_IN);
1403 dec_ie_call_id(l3m, callid, &len);
1406 if (!ACTIVE_EPOINT(p_epointlist)) {
1408 l3m = create_l3msg();
1409 l1l2l3_trace_header(p_m_mISDNport, this, L3_SUSPEND_REJECT_REQ, DIRECTION_OUT);
1410 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1412 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SUSPEND_REJECT, p_m_d_l3id, l3m);
1419 /* check if call id is in use */
1420 epoint = epoint_first;
1422 if (epoint->ep_park) {
1423 if (epoint->ep_park_len == len)
1424 if (!memcmp(epoint->ep_park_callid, callid, len)) {
1425 ret = -84; /* call id in use */
1429 epoint = epoint->next;
1432 /* notify the hold of call */
1433 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1434 message->param.notifyinfo.notify = INFO_NOTIFY_USER_SUSPENDED;
1435 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1436 message_put(message);
1438 /* deactivate bchannel */
1439 chan_trace_header(p_m_mISDNport, this, "CHANNEL RELEASE (suspend)", DIRECTION_NONE);
1440 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1444 /* sending suspend to endpoint */
1445 while (p_epointlist) {
1446 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_SUSPEND);
1447 memcpy(message->param.parkinfo.callid, callid, sizeof(message->param.parkinfo.callid));
1448 message->param.parkinfo.len = len;
1449 message_put(message);
1451 free_epointlist(p_epointlist);
1454 /* sending SUSPEND_ACKNOWLEDGE */
1455 l3m = create_l3msg();
1456 l1l2l3_trace_header(p_m_mISDNport, this, L3_SUSPEND_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1458 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SUSPEND_ACKNOWLEDGE, p_m_d_l3id, l3m);
1460 new_state(PORT_STATE_RELEASE);
1464 /* CC_RESUME INDICATION */
1465 void Pdss1::resume_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1467 unsigned char callid[8];
1469 int channel, exclusive;
1470 class Endpoint *epoint;
1471 struct lcr_msg *message;
1474 /* process given callref */
1475 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_IND, DIRECTION_IN);
1476 add_trace("callref", "new", "0x%x", pid);
1478 /* release is case the ID is already in use */
1479 add_trace("error", NULL, "callref already in use");
1481 l3m = create_l3msg();
1482 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_REJECT_REQ, DIRECTION_OUT);
1483 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47);
1484 add_trace("reason", NULL, "callref already in use");
1486 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RESUME_REJECT, pid, l3m);
1487 new_state(PORT_STATE_RELEASE);
1492 p_m_d_ces = pid >> 16;
1495 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_IND, DIRECTION_IN);
1496 dec_ie_call_id(l3m, callid, &len);
1499 /* if blocked, release call */
1500 if (p_m_mISDNport->ifport->block) {
1508 /* channel_id (no channel is possible in message) */
1510 channel = -1; /* any channel */
1513 ret = channel = hunt_bchannel(channel, exclusive);
1517 // mode (if hdlc parked) to be done. never mind, this is almost never requested
1519 ret = seize_bchannel(channel, 1);
1523 l3m = create_l3msg();
1524 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_REJECT_REQ, DIRECTION_OUT);
1525 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1527 add_trace("reason", NULL, "port blocked");
1529 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RESUME_REJECT, p_m_d_l3id, l3m);
1530 new_state(PORT_STATE_RELEASE);
1534 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
1536 /* create endpoint */
1538 FATAL("Incoming resume but already got an endpoint.\n");
1539 ret = -85; /* no call suspended */
1540 epoint = epoint_first;
1542 if (epoint->ep_park) {
1543 ret = -83; /* suspended call exists, but this not */
1544 if (epoint->ep_park_len == len)
1545 if (!memcmp(epoint->ep_park_callid, callid, len))
1548 epoint = epoint->next;
1553 epointlist_new(epoint->ep_serial);
1554 if (!(epoint->portlist_new(p_serial, p_type, p_m_mISDNport->earlyb)))
1555 FATAL("No memory for portlist\n");
1556 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RESUME);
1557 message_put(message);
1559 /* notify the resume of call */
1560 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1561 message->param.notifyinfo.notify = INFO_NOTIFY_USER_RESUMED;
1562 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1563 message_put(message);
1565 /* sending RESUME_ACKNOWLEDGE */
1566 l3m = create_l3msg();
1567 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1568 enc_ie_channel_id(l3m, 1, p_m_b_channel);
1570 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RESUME_ACKNOWLEDGE, p_m_d_l3id, l3m);
1572 new_state(PORT_STATE_CONNECT);
1576 /* CC_FACILITY INDICATION */
1577 void Pdss1::facility_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1579 unsigned char facil[256];
1581 struct lcr_msg *message;
1583 l1l2l3_trace_header(p_m_mISDNport, this, L3_FACILITY_IND, DIRECTION_IN);
1584 dec_ie_facility(l3m, facil, &facil_len);
1591 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_FACILITY);
1592 message->param.facilityinfo.len = facil_len;
1593 memcpy(message->param.facilityinfo.data, facil, facil_len);
1594 message_put(message);
1598 /* CC_PROGRESS INDICATION */
1599 void Pdss1::progress_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1601 int coding, location, progress;
1603 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROGRESS_IND, DIRECTION_IN);
1604 dec_ie_progress(l3m, &coding, &location, &progress);
1610 * handler for isdn connections
1611 * incoming information are parsed and sent via message to the endpoint
1613 void Pdss1::message_isdn(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1620 PERROR("Pdss1(%s) timeout without cause.\n", p_name);
1623 if (l3m->cause[0] != 5) {
1624 PERROR("Pdss1(%s) expecting timeout with timer diagnostic. (got len=%d)\n", p_name, l3m->cause[0]);
1627 timer = (l3m->cause[3]-'0')*100;
1628 timer += (l3m->cause[4]-'0')*10;
1629 timer += (l3m->cause[5]-'0');
1630 l1l2l3_trace_header(p_m_mISDNport, this, L3_TIMEOUT_IND, DIRECTION_IN);
1631 add_trace("timer", NULL, "%d", timer);
1634 t312_timeout_ind(cmd, pid, l3m);
1638 if (p_state != PORT_STATE_IDLE)
1640 setup_ind(cmd, pid, l3m);
1643 case MT_INFORMATION:
1644 information_ind(cmd, pid, l3m);
1647 case MT_SETUP_ACKNOWLEDGE:
1648 if (p_state != PORT_STATE_OUT_SETUP) {
1649 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received setup_acknowledge, but we are not in outgoing setup state, IGNORING.\n", p_name);
1652 setup_acknowledge_ind(cmd, pid, l3m);
1655 case MT_CALL_PROCEEDING:
1656 if (p_state != PORT_STATE_OUT_SETUP
1657 && p_state != PORT_STATE_OUT_OVERLAP) {
1658 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received proceeding, but we are not in outgoing setup OR overlap state, IGNORING.\n", p_name);
1661 proceeding_ind(cmd, pid, l3m);
1665 if (p_state != PORT_STATE_OUT_SETUP
1666 && p_state != PORT_STATE_OUT_OVERLAP
1667 && p_state != PORT_STATE_OUT_PROCEEDING) {
1668 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding state, IGNORING.\n", p_name);
1671 alerting_ind(cmd, pid, l3m);
1675 if (p_state != PORT_STATE_OUT_SETUP
1676 && p_state != PORT_STATE_OUT_OVERLAP
1677 && p_state != PORT_STATE_OUT_PROCEEDING
1678 && p_state != PORT_STATE_OUT_ALERTING) {
1679 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);
1682 connect_ind(cmd, pid, l3m);
1683 if (p_m_d_notify_pending) {
1684 /* send pending notify message during connect */
1685 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
1686 message_free(p_m_d_notify_pending);
1687 p_m_d_notify_pending = NULL;
1691 case MT_CONNECT_ACKNOWLEDGE:
1692 if (p_state == PORT_STATE_CONNECT_WAITING)
1693 new_state(PORT_STATE_CONNECT);
1694 if (p_m_d_notify_pending) {
1695 /* send pending notify message during connect-ack */
1696 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
1697 message_free(p_m_d_notify_pending);
1698 p_m_d_notify_pending = NULL;
1703 disconnect_ind(cmd, pid, l3m);
1707 release_ind(cmd, pid, l3m);
1710 case MT_RELEASE_COMPLETE:
1711 release_complete_ind(cmd, pid, l3m);
1715 restart_ind(cmd, pid, l3m);
1719 notify_ind(cmd, pid, l3m);
1723 hold_ind(cmd, pid, l3m);
1727 retrieve_ind(cmd, pid, l3m);
1731 suspend_ind(cmd, pid, l3m);
1735 resume_ind(cmd, pid, l3m);
1739 facility_ind(cmd, pid, l3m);
1743 progress_ind(cmd, pid, l3m);
1747 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_L3ID_IND, DIRECTION_IN);
1748 add_trace("callref", NULL, "0x%x", p_m_d_l3id);
1753 /* sending release to endpoint in case we still have an endpoint
1754 * this is because we don't get any response if a release_complete is received (or a release in release state)
1756 while(p_epointlist) { // only if not already released
1757 struct lcr_msg *message;
1758 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1759 if (p_m_d_collect_cause) {
1760 message->param.disconnectinfo.cause = p_m_d_collect_cause;
1761 message->param.disconnectinfo.location = p_m_d_collect_location;
1763 message->param.disconnectinfo.cause = CAUSE_NOUSER;
1764 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1766 message_put(message);
1768 free_epointlist(p_epointlist);
1770 new_state(PORT_STATE_RELEASE);
1775 l1l2l3_trace_header(p_m_mISDNport, this, L3_UNKNOWN_IND, DIRECTION_IN);
1776 add_trace("unhandled", "cmd", "0x%x", cmd);
1781 void Pdss1::new_state(int state)
1783 // class Endpoint *epoint;
1786 if (state == PORT_STATE_IN_OVERLAP) {
1787 p_m_timeout = p_m_mISDNport->ifport->tout_dialing;
1790 if (state != p_state) {
1791 if (state == PORT_STATE_IN_SETUP
1792 || state == PORT_STATE_OUT_SETUP
1793 || state == PORT_STATE_IN_OVERLAP
1794 || state == PORT_STATE_OUT_OVERLAP) {
1795 p_m_timeout = p_m_mISDNport->ifport->tout_setup;
1798 if (state == PORT_STATE_IN_PROCEEDING
1799 || state == PORT_STATE_OUT_PROCEEDING) {
1800 p_m_timeout = p_m_mISDNport->ifport->tout_proceeding;
1803 if (state == PORT_STATE_IN_ALERTING
1804 || state == PORT_STATE_OUT_ALERTING) {
1805 p_m_timeout = p_m_mISDNport->ifport->tout_alerting;
1808 if (state == PORT_STATE_CONNECT
1809 || state == PORT_STATE_CONNECT_WAITING) {
1812 if (state == PORT_STATE_IN_DISCONNECT
1813 || state == PORT_STATE_OUT_DISCONNECT) {
1814 p_m_timeout = p_m_mISDNport->ifport->tout_disconnect;
1819 Port::new_state(state);
1826 int Pdss1::handler(void)
1830 if ((ret = PmISDN::handler()))
1833 /* handle destruction */
1834 if (p_m_delete && p_m_d_l3id==0) {
1844 * handles all messages from endpoint
1846 /* MESSAGE_INFORMATION */
1847 void Pdss1::message_information(unsigned int epoint_id, int message_id, union parameter *param)
1850 char *display = param->information.display;
1851 char *number = param->information.id;
1852 int max = p_m_mISDNport->ifport->dialmax;
1854 while (number[0]) { /* as long we have something to dial */
1855 if (max > (int)strlen(number) || max == 0)
1856 max = (int)strlen(number);
1858 l3m = create_l3msg();
1859 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
1860 enc_ie_called_pn(l3m, 0, 1, (unsigned char *)number, max);
1861 if ((p_m_d_ntmode || p_m_d_tespecial) && display[0]) {
1862 enc_ie_display(l3m, (unsigned char *)display);
1866 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
1876 void Pdss1::message_setup(unsigned int epoint_id, int message_id, union parameter *param)
1880 int plan, type, screen, present, reason;
1881 int plan2, type2, screen2, present2;
1882 int capability, mode, rate, coding, user, presentation, interpretation, hlc, exthlc;
1883 int channel, exclusive;
1884 struct epoint_list *epointlist;
1885 int max = p_m_mISDNport->ifport->dialmax;
1887 /* release if port is blocked */
1888 if (p_m_mISDNport->ifport->block) {
1889 struct lcr_msg *message;
1891 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1892 message->param.disconnectinfo.cause = 27; // temp. unavail.
1893 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1894 message_put(message);
1895 new_state(PORT_STATE_RELEASE);
1900 /* copy setup infos to port */
1901 memcpy(&p_callerinfo, ¶m->setup.callerinfo, sizeof(p_callerinfo));
1902 memcpy(&p_dialinginfo, ¶m->setup.dialinginfo, sizeof(p_dialinginfo));
1903 memcpy(&p_capainfo, ¶m->setup.capainfo, sizeof(p_capainfo));
1904 memcpy(&p_redirinfo, ¶m->setup.redirinfo, sizeof(p_redirinfo));
1905 // SCPY(&p_m_tones_dir, param->setup.ext.tones_dir);
1906 /* screen outgoing caller id */
1907 do_screen(1, p_callerinfo.id, sizeof(p_callerinfo.id), &p_callerinfo.ntype, &p_callerinfo.present, p_m_mISDNport->ifport->interface);
1908 do_screen(1, p_callerinfo.id2, sizeof(p_callerinfo.id2), &p_callerinfo.ntype2, &p_callerinfo.present2, p_m_mISDNport->ifport->interface);
1910 /* only display at connect state: this case happens if endpoint is in connected mode */
1911 if (p_state==PORT_STATE_CONNECT) {
1912 if (p_type!=PORT_TYPE_DSS1_NT_OUT
1913 && p_type!=PORT_TYPE_DSS1_NT_IN)
1915 if (p_callerinfo.display[0]) {
1916 /* sending information */
1917 l3m = create_l3msg();
1918 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
1919 if (p_m_d_ntmode || p_m_d_tespecial)
1920 enc_ie_display(l3m, (unsigned char *)p_callerinfo.display);
1922 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
1927 /* attach only if not already */
1928 epointlist = p_epointlist;
1930 if (epointlist->epoint_id == epoint_id)
1932 epointlist = epointlist->next;
1935 epointlist_new(epoint_id);
1939 if (p_m_b_channel) {
1940 channel = p_m_b_channel;
1941 exclusive = p_m_b_exclusive;
1943 channel = CHANNEL_ANY;
1944 /* nt-port with no channel, not reserverd */
1945 if (!p_m_b_channel && !p_m_b_reserve && p_type==PORT_TYPE_DSS1_NT_OUT)
1946 channel = CHANNEL_NO;
1949 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_REQ, DIRECTION_OUT);
1950 /* see MT_ASSIGN notes at do_layer3() */
1952 ret = p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_ASSIGN, 0, NULL);
1953 if (mt_assign_pid == 0 || ret < 0) {
1954 struct lcr_msg *message;
1956 add_trace("callref", NULL, "no free id");
1958 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1959 message->param.disconnectinfo.cause = 47;
1960 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1961 message_put(message);
1962 new_state(PORT_STATE_RELEASE);
1966 p_m_d_l3id = mt_assign_pid;
1968 add_trace("callref", "new", "0x%x", p_m_d_l3id);
1971 /* preparing setup message */
1972 l3m = create_l3msg();
1973 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_REQ, DIRECTION_OUT);
1974 /* channel information */
1975 if (channel >= 0) /* it should */
1976 enc_ie_channel_id(l3m, exclusive, channel);
1977 /* caller information */
1979 switch (p_callerinfo.ntype) {
1980 case INFO_NTYPE_UNKNOWN:
1983 case INFO_NTYPE_INTERNATIONAL:
1986 case INFO_NTYPE_NATIONAL:
1989 case INFO_NTYPE_SUBSCRIBER:
1992 default: /* INFO_NTYPE_NOTPRESENT */
1996 switch (p_callerinfo.screen) {
1997 case INFO_SCREEN_USER:
2000 default: /* INFO_SCREEN_NETWORK */
2004 switch (p_callerinfo.present) {
2005 case INFO_PRESENT_ALLOWED:
2008 case INFO_PRESENT_RESTRICTED:
2011 default: /* INFO_PRESENT_NOTAVAIL */
2015 /* caller information 2 */
2017 switch (p_callerinfo.ntype2) {
2018 case INFO_NTYPE_UNKNOWN:
2021 case INFO_NTYPE_INTERNATIONAL:
2024 case INFO_NTYPE_NATIONAL:
2027 case INFO_NTYPE_SUBSCRIBER:
2030 default: /* INFO_NTYPE_NOTPRESENT */
2034 switch (p_callerinfo.screen2) {
2035 case INFO_SCREEN_USER:
2038 default: /* INFO_SCREEN_NETWORK */
2042 switch (p_callerinfo.present2) {
2043 case INFO_PRESENT_ALLOWED:
2046 case INFO_PRESENT_RESTRICTED:
2049 default: /* INFO_PRESENT_NOTAVAIL */
2054 enc_ie_calling_pn(l3m, type, plan, present, screen, (unsigned char *)p_callerinfo.id, type2, plan2, present2, screen2, (unsigned char *)p_callerinfo.id2);
2055 /* dialing information */
2056 if (p_dialinginfo.id[0]) { /* only if we have something to dial */
2057 if (max > (int)strlen(p_dialinginfo.id) || max == 0)
2058 max = (int)strlen(p_dialinginfo.id);
2059 enc_ie_called_pn(l3m, 0, 1, (unsigned char *)p_dialinginfo.id, max);
2060 SCPY(p_m_d_queue, p_dialinginfo.id + max);
2062 /* sending complete */
2063 if (p_dialinginfo.sending_complete)
2064 enc_ie_complete(l3m, 1);
2065 /* sending user-user */
2066 if (param->setup.useruser.len) {
2067 enc_ie_useruser(l3m, param->setup.useruser.protocol, param->setup.useruser.data, param->setup.useruser.len);
2069 /* redirecting number */
2071 switch (p_redirinfo.ntype) {
2072 case INFO_NTYPE_UNKNOWN:
2075 case INFO_NTYPE_INTERNATIONAL:
2078 case INFO_NTYPE_NATIONAL:
2081 case INFO_NTYPE_SUBSCRIBER:
2084 default: /* INFO_NTYPE_NOTPRESENT */
2088 switch (p_redirinfo.screen) {
2089 case INFO_SCREEN_USER:
2092 default: /* INFO_SCREE_NETWORK */
2096 switch (p_redirinfo.reason) {
2097 case INFO_REDIR_BUSY:
2100 case INFO_REDIR_NORESPONSE:
2103 case INFO_REDIR_UNCONDITIONAL:
2106 case INFO_REDIR_CALLDEFLECT:
2109 case INFO_REDIR_OUTOFORDER:
2112 default: /* INFO_REDIR_UNKNOWN */
2116 switch (p_redirinfo.present) {
2117 case INFO_PRESENT_ALLOWED:
2120 case INFO_PRESENT_RESTRICTED:
2123 default: /* INFO_PRESENT_NOTAVAIL */
2127 /* sending redirecting number only in ntmode */
2128 if (type >= 0 && (p_m_d_ntmode || p_m_d_tespecial))
2129 enc_ie_redir_nr(l3m, type, plan, present, screen, reason, (unsigned char *)p_redirinfo.id);
2130 /* bearer capability */
2131 //printf("hlc=%d\n",p_capainfo.hlc);
2133 capability = p_capainfo.bearer_capa;
2134 mode = p_capainfo.bearer_mode;
2135 rate = (mode==INFO_BMODE_CIRCUIT)?0x10:0x00;
2136 switch (p_capainfo.bearer_info1) {
2137 case INFO_INFO1_NONE:
2141 user = p_capainfo.bearer_info1 & 0x7f;
2144 enc_ie_bearer(l3m, coding, capability, mode, rate, -1, user);
2146 if (p_capainfo.hlc) {
2150 hlc = p_capainfo.hlc & 0x7f;
2152 if (p_capainfo.exthlc)
2153 exthlc = p_capainfo.exthlc & 0x7f;
2154 enc_ie_hlc(l3m, coding, interpretation, presentation, hlc, exthlc);
2158 if (p_callerinfo.display[0] && (p_m_d_ntmode || p_m_d_tespecial))
2159 enc_ie_display(l3m, (unsigned char *)p_callerinfo.display);
2160 /* nt-mode: CNIP (calling name identification presentation) */
2161 // if (p_callerinfo.name[0] && (p_m_d_ntmode || p_m_d_tespecial))
2162 // enc_facility_centrex(&setup->FACILITY, dmsg, (unsigned char *)p_callerinfo.name, 1);
2165 /* send setup message now */
2166 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SETUP, p_m_d_l3id, l3m);
2168 new_state(PORT_STATE_OUT_SETUP);
2171 /* MESSAGE_FACILITY */
2172 void Pdss1::message_facility(unsigned int epoint_id, int message_id, union parameter *param)
2176 /* facility will not be sent to external lines */
2177 if (!p_m_d_ntmode && !p_m_d_tespecial)
2180 /* sending facility */
2181 l3m = create_l3msg();
2182 l1l2l3_trace_header(p_m_mISDNport, this, L3_FACILITY_REQ, DIRECTION_OUT);
2183 enc_ie_facility(l3m, (unsigned char *)param->facilityinfo.data, param->facilityinfo.len);
2185 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_FACILITY, p_m_d_l3id, l3m);
2188 /* MESSAGE_NOTIFY */
2189 void Pdss1::message_notify(unsigned int epoint_id, int message_id, union parameter *param)
2193 int plan = 0, type = -1, present = 0;
2195 printf("if = %d\n", param->notifyinfo.notify);
2196 if (param->notifyinfo.notify>INFO_NOTIFY_NONE)
2197 notify = param->notifyinfo.notify & 0x7f;
2202 switch (param->notifyinfo.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_UNKNOWN */
2219 switch (param->notifyinfo.present) {
2220 case INFO_PRESENT_ALLOWED:
2223 case INFO_PRESENT_RESTRICTED:
2226 default: /* INFO_PRESENT_NOTAVAIL */
2232 if (notify<0 && !param->notifyinfo.display[0]) {
2233 /* nothing to notify, nothing to display */
2238 if (p_state!=PORT_STATE_CONNECT && p_state!=PORT_STATE_IN_PROCEEDING && p_state!=PORT_STATE_IN_ALERTING) {
2239 /* queue notification */
2240 if (p_m_d_notify_pending)
2241 message_free(p_m_d_notify_pending);
2242 p_m_d_notify_pending = message_create(ACTIVE_EPOINT(p_epointlist), p_serial, EPOINT_TO_PORT, message_id);
2243 memcpy(&p_m_d_notify_pending->param, param, sizeof(union parameter));
2245 /* sending notification */
2246 l3m = create_l3msg();
2247 l1l2l3_trace_header(p_m_mISDNport, this, L3_NOTIFY_REQ, DIRECTION_OUT);
2248 enc_ie_notify(l3m, notify);
2249 /* sending redirection number only in ntmode */
2250 if (type >= 0 && (p_m_d_ntmode || p_m_d_tespecial))
2251 enc_ie_redir_dn(l3m, type, plan, present, (unsigned char *)param->notifyinfo.id);
2252 if (param->notifyinfo.display[0] && (p_m_d_ntmode || p_m_d_tespecial))
2253 enc_ie_display(l3m, (unsigned char *)param->notifyinfo.display);
2255 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_NOTIFY, p_m_d_l3id, l3m);
2257 } else if (p_m_d_ntmode || p_m_d_tespecial) {
2258 /* sending information */
2259 l3m = create_l3msg();
2260 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
2261 enc_ie_display(l3m, (unsigned char *)param->notifyinfo.display);
2263 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
2267 /* MESSAGE_OVERLAP */
2268 void Pdss1::message_overlap(unsigned int epoint_id, int message_id, union parameter *param)
2272 /* in case of sending complete, we proceed */
2273 if (p_dialinginfo.sending_complete) {
2274 PDEBUG(DEBUG_ISDN, "sending proceeding instead of setup_acknowledge, because address is complete.\n");
2275 message_proceeding(epoint_id, message_id, param);
2279 /* sending setup_acknowledge */
2280 l3m = create_l3msg();
2281 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_ACKNOWLEDGE_REQ, DIRECTION_OUT);
2282 /* channel information */
2283 if (p_state == PORT_STATE_IN_SETUP)
2284 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2285 /* progress information */
2286 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2287 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2288 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2289 if (p_m_mISDNport->tones)
2290 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2292 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SETUP_ACKNOWLEDGE, p_m_d_l3id, l3m);
2294 new_state(PORT_STATE_IN_OVERLAP);
2297 /* MESSAGE_PROCEEDING */
2298 void Pdss1::message_proceeding(unsigned int epoint_id, int message_id, union parameter *param)
2302 /* sending proceeding */
2303 l3m = create_l3msg();
2304 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2305 /* channel information */
2306 if (p_state == PORT_STATE_IN_SETUP)
2307 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2308 /* progress information */
2309 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2310 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2311 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2312 if (p_m_mISDNport->tones)
2313 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2315 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2317 new_state(PORT_STATE_IN_PROCEEDING);
2320 /* MESSAGE_ALERTING */
2321 void Pdss1::message_alerting(unsigned int epoint_id, int message_id, union parameter *param)
2325 /* NT-MODE in setup state we must send PROCEEDING first */
2326 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP) {
2327 /* sending proceeding */
2328 l3m = create_l3msg();
2329 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2330 /* channel information */
2331 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2332 /* progress information */
2333 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2334 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2335 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2336 if (p_m_mISDNport->tones)
2337 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2339 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2340 new_state(PORT_STATE_IN_PROCEEDING);
2343 /* sending alerting */
2344 l3m = create_l3msg();
2345 l1l2l3_trace_header(p_m_mISDNport, this, L3_ALERTING_REQ, DIRECTION_OUT);
2346 /* channel information */
2347 if (p_state == PORT_STATE_IN_SETUP)
2348 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2349 /* progress information */
2350 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2351 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2352 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2353 if (p_m_mISDNport->tones)
2354 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2356 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_ALERTING, p_m_d_l3id, l3m);
2358 new_state(PORT_STATE_IN_ALERTING);
2361 /* MESSAGE_CONNECT */
2362 void Pdss1::message_connect(unsigned int epoint_id, int message_id, union parameter *param)
2365 int type, plan, present, screen;
2366 class Endpoint *epoint;
2368 /* NT-MODE in setup state we must send PROCEEDING first */
2369 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP) {
2370 /* sending proceeding */
2371 l3m = create_l3msg();
2372 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2373 /* channel information */
2374 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2376 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2377 new_state(PORT_STATE_IN_PROCEEDING);
2380 /* copy connected information */
2381 memcpy(&p_connectinfo, ¶m->connectinfo, sizeof(p_connectinfo));
2382 /* screen outgoing caller id */
2383 do_screen(1, p_connectinfo.id, sizeof(p_connectinfo.id), &p_connectinfo.ntype, &p_connectinfo.present, p_m_mISDNport->ifport->interface);
2385 /* only display at connect state */
2386 if (p_state == PORT_STATE_CONNECT)
2387 if (p_connectinfo.display[0]) {
2388 /* sending information */
2389 l3m = create_l3msg();
2390 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
2391 if (p_m_d_ntmode || p_m_d_tespecial)
2392 enc_ie_display(l3m, (unsigned char *)p_connectinfo.display);
2394 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
2398 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) {
2399 /* connect command only possible in setup, proceeding or alerting state */
2403 /* preparing connect message */
2404 l3m = create_l3msg();
2405 l1l2l3_trace_header(p_m_mISDNport, this, L3_CONNECT_REQ, DIRECTION_OUT);
2406 /* connect information */
2408 switch (p_connectinfo.ntype) {
2409 case INFO_NTYPE_UNKNOWN:
2412 case INFO_NTYPE_INTERNATIONAL:
2415 case INFO_NTYPE_NATIONAL:
2418 case INFO_NTYPE_SUBSCRIBER:
2421 default: /* INFO_NTYPE_NOTPRESENT */
2425 switch (param->connectinfo.screen) {
2426 case INFO_SCREEN_USER:
2429 default: /* INFO_SCREE_NETWORK */
2433 switch (p_connectinfo.present) {
2434 case INFO_PRESENT_ALLOWED:
2437 case INFO_PRESENT_RESTRICTED:
2440 default: /* INFO_PRESENT_NOTAVAIL */
2445 enc_ie_connected_pn(l3m, type, plan, present, screen, (unsigned char *)p_connectinfo.id);
2447 if (p_connectinfo.display[0] && (p_m_d_ntmode || p_m_d_tespecial))
2448 enc_ie_display(l3m, (unsigned char *)p_connectinfo.display);
2449 /* nt-mode: CONP (connected name identification presentation) */
2450 // if (p_connectinfo.name[0] && (p_m_d_ntmode || p_m_d_tespecial))
2451 // enc_facility_centrex(&connect->FACILITY, dmsg, (unsigned char *)p_connectinfo.name, 0);
2453 if (p_m_d_ntmode || p_m_d_tespecial) {
2454 epoint = find_epoint_id(epoint_id);
2455 enc_ie_date(l3m, now, p_settings.no_seconds);
2458 /* finally send message */
2459 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CONNECT, p_m_d_l3id, l3m);
2462 new_state(PORT_STATE_CONNECT);
2464 new_state(PORT_STATE_CONNECT_WAITING);
2468 /* MESSAGE_DISCONNECT */
2469 void Pdss1::message_disconnect(unsigned int epoint_id, int message_id, union parameter *param)
2472 struct lcr_msg *message;
2475 /* we reject during incoming setup when we have no tones. also if we are in outgoing setup state */
2476 // if ((p_state==PORT_STATE_IN_SETUP && !p_m_mISDNport->tones)
2477 if (/* ||*/ p_state==PORT_STATE_OUT_SETUP) {
2478 /* sending release to endpoint */
2479 while(p_epointlist) {
2480 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
2481 memcpy(&message->param, param, sizeof(union parameter));
2482 message_put(message);
2484 free_epointlist(p_epointlist);
2486 /* sending release */
2487 l3m = create_l3msg();
2488 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
2490 enc_ie_cause(l3m, (!p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_REMOTE:param->disconnectinfo.location, param->disconnectinfo.cause);
2492 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
2493 new_state(PORT_STATE_RELEASE);
2498 /* workarround: NT-MODE in setup state we must send PROCEEDING first to make it work */
2499 if (p_state==PORT_STATE_IN_SETUP) {
2500 /* sending proceeding */
2501 l3m = create_l3msg();
2502 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2503 /* channel information */
2504 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2505 /* progress information */
2506 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2507 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2508 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2509 if (p_m_mISDNport->tones)
2510 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2512 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2513 new_state(PORT_STATE_IN_PROCEEDING);
2516 /* sending disconnect */
2517 l3m = create_l3msg();
2518 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_REQ, DIRECTION_OUT);
2519 /* progress information */
2520 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2521 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2522 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2523 if (p_m_mISDNport->tones)
2524 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2526 enc_ie_cause(l3m, (!p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_REMOTE:param->disconnectinfo.location, param->disconnectinfo.cause);
2528 if (param->disconnectinfo.display[0])
2529 p = param->disconnectinfo.display;
2530 if (p) if (*p && (p_m_d_ntmode || p_m_d_tespecial))
2531 enc_ie_display(l3m, (unsigned char *)p);
2533 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_DISCONNECT, p_m_d_l3id, l3m);
2534 new_state(PORT_STATE_OUT_DISCONNECT);
2537 /* MESSAGE_RELEASE */
2538 void Pdss1::message_release(unsigned int epoint_id, int message_id, union parameter *param)
2541 class Endpoint *epoint;
2545 * we may only release during incoming disconnect state.
2546 * this means that the endpoint doesnt require audio anymore
2548 if (p_state == PORT_STATE_IN_DISCONNECT
2549 || p_state == PORT_STATE_OUT_DISCONNECT) {
2550 /* sending release */
2551 l3m = create_l3msg();
2552 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_REQ, DIRECTION_OUT);
2554 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2556 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE, p_m_d_l3id, l3m);
2557 new_state(PORT_STATE_RELEASE);
2559 free_epointid(epoint_id);
2560 // wait for callref to be released
2565 * if we are on incoming call setup, we may reject by sending a release_complete
2566 * also on outgoing call setup, we send a release complete, BUT this is not conform. (i don't know any other way)
2568 if (p_state==PORT_STATE_IN_SETUP
2569 || p_state==PORT_STATE_OUT_SETUP) {
2570 //#warning remove me
2571 //PDEBUG(DEBUG_LOG, "JOLLY sending release complete %d\n", p_serial);
2572 /* sending release complete */
2573 l3m = create_l3msg();
2574 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_REQ, DIRECTION_OUT);
2576 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2578 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
2579 new_state(PORT_STATE_RELEASE);
2581 free_epointid(epoint_id);
2582 // wait for callref to be released
2587 wirklich erst proceeding?:
2588 /* NT-MODE in setup state we must send PROCEEDING first */
2589 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP) {
2590 CALL_PROCEEDING_t *proceeding;
2592 /* sending proceeding */
2593 l3m = create_l3msg();
2594 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2595 /* channel information */
2596 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2597 /* progress information */
2598 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2599 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2600 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2601 if (p_m_mISDNport->tones)
2602 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2604 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2608 /* sending disconnect */
2609 l3m = create_l3msg();
2610 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_REQ, DIRECTION_OUT);
2611 /* progress information */
2612 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2613 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2614 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2615 if (p_m_mISDNport->tones)
2616 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2618 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2620 epoint = find_epoint_id(epoint_id);
2621 if (param->disconnectinfo.display[0])
2622 p = param->disconnectinfo.display;
2623 if (p) if (*p && (p_m_d_ntmode || p_m_d_tespecial))
2624 enc_ie_display(l3m, (unsigned char *)p);
2626 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_DISCONNECT, p_m_d_l3id, l3m);
2627 new_state(PORT_STATE_OUT_DISCONNECT);
2629 free_epointid(epoint_id);
2630 // wait for release and callref to be released
2631 //#warning remove me
2632 //PDEBUG(DEBUG_LOG, "JOLLY sending disconnect %d\n", p_serial);
2637 * endpoint sends messages to the port
2639 int Pdss1::message_epoint(unsigned int epoint_id, int message_id, union parameter *param)
2641 if (PmISDN::message_epoint(epoint_id, message_id, param))
2644 switch(message_id) {
2645 case MESSAGE_INFORMATION: /* overlap dialing */
2646 if (p_type==PORT_TYPE_DSS1_NT_OUT
2647 && p_state!=PORT_STATE_OUT_OVERLAP
2648 && p_state!=PORT_STATE_CONNECT
2649 && p_state!=PORT_STATE_OUT_DISCONNECT
2650 && p_state!=PORT_STATE_IN_DISCONNECT) {
2653 if (p_type==PORT_TYPE_DSS1_TE_OUT
2654 && p_state!=PORT_STATE_OUT_OVERLAP
2655 && p_state!=PORT_STATE_OUT_PROCEEDING
2656 && p_state!=PORT_STATE_OUT_ALERTING
2657 && p_state!=PORT_STATE_CONNECT
2658 && p_state!=PORT_STATE_OUT_DISCONNECT
2659 && p_state!=PORT_STATE_IN_DISCONNECT) {
2662 if ((p_type==PORT_TYPE_DSS1_NT_IN || p_type==PORT_TYPE_DSS1_TE_IN)
2663 && p_state!=PORT_STATE_IN_OVERLAP
2664 && p_state!=PORT_STATE_IN_PROCEEDING
2665 && p_state!=PORT_STATE_IN_ALERTING
2666 && p_state!=PORT_STATE_CONNECT
2667 && p_state!=PORT_STATE_CONNECT_WAITING
2668 && p_state!=PORT_STATE_OUT_DISCONNECT
2669 && p_state!=PORT_STATE_IN_DISCONNECT) {
2672 message_information(epoint_id, message_id, param);
2675 case MESSAGE_SETUP: /* dial-out command received from epoint */
2676 if (p_state!=PORT_STATE_IDLE
2677 && p_state!=PORT_STATE_CONNECT) {
2678 PERROR("Pdss1(%s) ignoring setup because isdn port is not in idle state (or connected for sending display info).\n", p_name);
2681 if (p_epointlist && p_state==PORT_STATE_IDLE)
2682 FATAL("Pdss1(%s): epoint pointer is set in idle state, how bad!!\n", p_name);
2683 message_setup(epoint_id, message_id, param);
2686 case MESSAGE_NOTIFY: /* display and notifications */
2687 message_notify(epoint_id, message_id, param);
2690 case MESSAGE_FACILITY: /* facility message */
2691 message_facility(epoint_id, message_id, param);
2694 case MESSAGE_OVERLAP: /* more information is needed */
2695 if (p_state!=PORT_STATE_IN_SETUP) {
2698 message_overlap(epoint_id, message_id, param);
2701 case MESSAGE_PROCEEDING: /* call of endpoint is proceeding */
2702 if (p_state!=PORT_STATE_IN_SETUP
2703 && p_state!=PORT_STATE_IN_OVERLAP) {
2706 message_proceeding(epoint_id, message_id, param);
2707 if (p_m_d_notify_pending) {
2708 /* send pending notify message during connect */
2709 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2710 message_free(p_m_d_notify_pending);
2711 p_m_d_notify_pending = NULL;
2715 case MESSAGE_ALERTING: /* call of endpoint is ringing */
2716 if (p_state!=PORT_STATE_IN_SETUP
2717 && p_state!=PORT_STATE_IN_OVERLAP
2718 && p_state!=PORT_STATE_IN_PROCEEDING) {
2721 message_alerting(epoint_id, message_id, param);
2722 if (p_m_d_notify_pending) {
2723 /* send pending notify message during connect */
2724 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2725 message_free(p_m_d_notify_pending);
2726 p_m_d_notify_pending = NULL;
2730 case MESSAGE_CONNECT: /* call of endpoint is connected */
2731 if (p_state!=PORT_STATE_IN_SETUP
2732 && p_state!=PORT_STATE_IN_OVERLAP
2733 && p_state!=PORT_STATE_IN_PROCEEDING
2734 && p_state!=PORT_STATE_IN_ALERTING
2735 && !(p_state==PORT_STATE_CONNECT && p_m_d_ntmode)) {
2738 message_connect(epoint_id, message_id, param);
2739 if (p_m_d_notify_pending) {
2740 /* send pending notify message during connect */
2741 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2742 message_free(p_m_d_notify_pending);
2743 p_m_d_notify_pending = NULL;
2747 case MESSAGE_DISCONNECT: /* call has been disconnected */
2748 if (p_state!=PORT_STATE_IN_SETUP
2749 && p_state!=PORT_STATE_IN_OVERLAP
2750 && p_state!=PORT_STATE_IN_PROCEEDING
2751 && p_state!=PORT_STATE_IN_ALERTING
2752 && p_state!=PORT_STATE_OUT_SETUP
2753 && p_state!=PORT_STATE_OUT_OVERLAP
2754 && p_state!=PORT_STATE_OUT_PROCEEDING
2755 && p_state!=PORT_STATE_OUT_ALERTING
2756 && p_state!=PORT_STATE_CONNECT
2757 && p_state!=PORT_STATE_CONNECT_WAITING) {
2760 message_disconnect(epoint_id, message_id, param);
2763 case MESSAGE_RELEASE: /* release isdn port */
2764 if (p_state==PORT_STATE_RELEASE) {
2767 message_release(epoint_id, message_id, param);
2771 PERROR("Pdss1(%s) isdn port with (caller id %s) received a wrong message: %d\n", p_name, p_callerinfo.id, message_id);
2780 * data from isdn-stack (layer-3) to pbx (port class)
2782 int stack2manager(struct mISDNport *mISDNport, unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
2788 PDEBUG(DEBUG_ISDN, "cmd(0x%x) pid(0x%x)\n", cmd, pid);
2791 PDEBUG(DEBUG_ISDN, "ignoring dummy process from phone.\n");
2795 /* find Port object of type ISDN */
2799 if ((port->p_type & PORT_CLASS_mISDN_MASK) == PORT_CLASS_mISDN_DSS1) {
2800 pdss1 = (class Pdss1 *)port;
2801 /* check out correct stack and id */
2802 if (pdss1->p_m_mISDNport == mISDNport) {
2803 if (pdss1->p_m_d_l3id & MISDN_PID_CR_FLAG) {
2804 /* local callref, so match value only */
2805 if ((pdss1->p_m_d_l3id & MISDN_PID_CRVAL_MASK) == (pid & MISDN_PID_CRVAL_MASK))
2808 /* remote callref, ref + channel id */
2809 if (pdss1->p_m_d_l3id == pid)
2817 /* aktueller prozess */
2819 if (cmd == MT_ASSIGN) {
2820 /* stack gives us new layer 3 id (during connect) */
2821 l1l2l3_trace_header(mISDNport, pdss1, L3_NEW_L3ID_IND, DIRECTION_IN);
2822 add_trace("callref", "old", "0x%x", pdss1->p_m_d_l3id);
2823 /* nt-library now gives us a new id via CC_SETUP_CONFIRM */
2824 if ((pdss1->p_m_d_l3id&MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER)
2825 PERROR(" strange setup-procid 0x%x\n", pdss1->p_m_d_l3id);
2826 pdss1->p_m_d_l3id = pid;
2827 if (port->p_state == PORT_STATE_CONNECT)
2828 pdss1->p_m_d_ces = pid >> 16;
2829 add_trace("callref", "new", "0x%x", pdss1->p_m_d_l3id);
2833 /* if process id is master process, but a child disconnects */
2834 if (mISDNport->ntmode
2835 && (pid & MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER
2836 && (pdss1->p_m_d_l3id & MISDN_PID_CRTYPE_MASK) == MISDN_PID_MASTER) {
2837 if (cmd == MT_DISCONNECT
2838 || cmd == MT_RELEASE) {
2839 /* send special indication for child disconnect */
2840 pdss1->disconnect_ind_i(cmd, pid, l3m);
2843 if (cmd == MT_RELEASE_COMPLETE)
2846 /* if we have child pid and got different child pid message, ignore */
2847 if (mISDNport->ntmode
2848 && (pid & MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER
2849 && (pdss1->p_m_d_l3id & MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER
2850 && pid != pdss1->p_m_d_l3id)
2853 /* process message */
2854 pdss1->message_isdn(cmd, pid, l3m);
2861 /* creating port object, transparent until setup with hdlc */
2862 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
2863 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0, B_MODE_TRANSPARENT)))
2865 FATAL("Cannot create Port instance.\n");
2866 pdss1->message_isdn(cmd, pid, l3m);
2870 /* creating port object, transparent until setup with hdlc */
2871 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
2872 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0, B_MODE_TRANSPARENT)))
2873 FATAL("Cannot create Port instance.\n");
2874 pdss1->message_isdn(cmd, pid, l3m);
2878 PDEBUG(DEBUG_ISDN, "unused call ref released (l3id=0x%x)\n", pid);
2881 case MT_RELEASE_COMPLETE:
2882 PERROR("must be ignored by stack, not sent to app\n");
2886 // facility als broadcast
2890 PERROR("unhandled message: cmd(0x%x) pid(0x%x)\n", cmd, pid);
2893 if (port->p_type == PORT_TYPE_DSS1_NT_IN || port->p_type == PORT_TYPE_DSS1_NT_OUT) {
2894 pdss1 = (class Pdss1 *)port;
2895 /* check out correct stack */
2896 if (pdss1->p_m_mISDNport == mISDNport)
2897 /* check out correct id */
2898 PERROR("unhandled message: pid=%x is not associated with port-dinfo=%x\n", pid, pdss1->p_m_d_l3id);