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));
1069 location = LOCATION_PRIVATE_LOCAL;
1072 /* release if remote sends us no tones */
1073 if (!p_m_mISDNport->earlyb) {
1076 l3m = create_l3msg();
1077 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_REQ, DIRECTION_OUT);
1078 enc_ie_cause(l3m, location, cause); /* normal */
1079 add_trace("reason", NULL, "no remote patterns");
1081 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE, p_m_d_l3id, l3m);
1083 /* sending release to endpoint */
1084 if (location == LOCATION_PRIVATE_LOCAL)
1085 location = LOCATION_PRIVATE_REMOTE;
1086 while(p_epointlist) {
1087 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1088 message->param.disconnectinfo.cause = cause;
1089 message->param.disconnectinfo.location = location;
1090 SCAT(message->param.disconnectinfo.display, (char *)display);
1091 message_put(message);
1093 free_epointlist(p_epointlist);
1095 new_state(PORT_STATE_RELEASE);
1100 /* sending disconnect to active endpoint and release to inactive endpoints */
1101 if (location == LOCATION_PRIVATE_LOCAL)
1102 location = LOCATION_PRIVATE_REMOTE;
1103 if (ACTIVE_EPOINT(p_epointlist)) {
1104 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DISCONNECT);
1105 message->param.disconnectinfo.location = location;
1106 message->param.disconnectinfo.cause = cause;
1107 SCAT(message->param.disconnectinfo.display, (char *)display);
1108 message_put(message);
1110 while(INACTIVE_EPOINT(p_epointlist)) {
1111 message = message_create(p_serial, INACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1112 message->param.disconnectinfo.location = location;
1113 message->param.disconnectinfo.cause = cause;
1114 SCAT(message->param.disconnectinfo.display, (char *)display);
1115 message_put(message);
1117 free_epointid(INACTIVE_EPOINT(p_epointlist));
1119 new_state(PORT_STATE_IN_DISCONNECT);
1122 /* CC_DISCONNECT INDICATION */
1123 void Pdss1::disconnect_ind_i(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1125 int location, cause;
1128 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_IND, DIRECTION_IN);
1129 if (p_m_d_collect_cause > 0) {
1130 add_trace("old-cause", "location", "%d", p_m_d_collect_location);
1131 add_trace("old-cause", "value", "%d", p_m_d_collect_cause);
1133 dec_ie_cause(l3m, &location, &cause);
1134 if (location == LOCATION_PRIVATE_LOCAL)
1135 location = LOCATION_PRIVATE_REMOTE;
1138 collect_cause(&p_m_d_collect_cause, &p_m_d_collect_location, cause, location);
1139 add_trace("new-cause", "location", "%d", p_m_d_collect_location);
1140 add_trace("new-cause", "value", "%d", p_m_d_collect_cause);
1145 /* CC_RELEASE INDICATION */
1146 void Pdss1::release_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1148 int location, cause;
1149 struct lcr_msg *message;
1150 unsigned char display[128] = "";
1152 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_IND, DIRECTION_IN);
1153 dec_ie_cause(l3m, &location, &cause);
1154 dec_ie_display(l3m, (unsigned char *)display, sizeof(display));
1159 location = LOCATION_PRIVATE_LOCAL;
1162 /* sending release to endpoint */
1163 if (location == LOCATION_PRIVATE_LOCAL)
1164 location = LOCATION_PRIVATE_REMOTE;
1165 while(p_epointlist) {
1166 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1167 message->param.disconnectinfo.cause = cause;
1168 message->param.disconnectinfo.location = location;
1169 SCAT(message->param.disconnectinfo.display, (char *)display);
1170 message_put(message);
1172 free_epointlist(p_epointlist);
1175 new_state(PORT_STATE_RELEASE);
1179 /* CC_RESTART INDICATION */
1180 void Pdss1::restart_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1182 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESTART_IND, DIRECTION_IN);
1185 // L3 process is not toucht. (not even by network stack)
1188 /* CC_RELEASE_COMPLETE INDICATION (a reject) */
1189 void Pdss1::release_complete_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1191 int location, cause;
1192 struct lcr_msg *message;
1194 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_IND, DIRECTION_IN);
1195 /* in case layer 2 is down during setup, we send cause 27 loc 5 */
1196 if (p_state == PORT_STATE_OUT_SETUP && p_m_mISDNport->l1link == 0) {
1200 dec_ie_cause(l3m, &location, &cause);
1201 if (p_m_mISDNport->l1link < 0)
1202 add_trace("layer 1", NULL, "unknown");
1204 add_trace("layer 1", NULL, (p_m_mISDNport->l1link)?"up":"down");
1207 if (location == LOCATION_PRIVATE_LOCAL)
1208 location = LOCATION_PRIVATE_REMOTE;
1212 location = LOCATION_PRIVATE_LOCAL;
1215 /* sending release to endpoint */
1216 while(p_epointlist) {
1217 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1218 message->param.disconnectinfo.cause = cause;
1219 message->param.disconnectinfo.location = location;
1220 message_put(message);
1222 free_epointlist(p_epointlist);
1225 new_state(PORT_STATE_RELEASE);
1230 void Pdss1::t312_timeout_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1232 // not required, release is performed with MT_FREE
1235 /* CC_NOTIFY INDICATION */
1236 void Pdss1::notify_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1238 struct lcr_msg *message;
1239 int notify, type, plan, present;
1240 unsigned char notifyid[sizeof(message->param.notifyinfo.id)];
1241 unsigned char display[128] = "";
1243 l1l2l3_trace_header(p_m_mISDNport, this, L3_NOTIFY_IND, DIRECTION_IN);
1244 dec_ie_notify(l3m, ¬ify);
1245 dec_ie_redir_dn(l3m, &type, &plan, &present, notifyid, sizeof(notifyid));
1246 dec_ie_display(l3m, (unsigned char *)display, sizeof(display));
1249 if (!ACTIVE_EPOINT(p_epointlist))
1251 /* notification indicator */
1255 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1256 message->param.notifyinfo.notify = notify;
1257 SCPY(message->param.notifyinfo.id, (char *)notifyid);
1258 /* redirection number */
1261 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1264 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1267 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1272 message->param.notifyinfo.ntype = INFO_NTYPE_NOTPRESENT;
1275 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1278 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1281 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1284 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1287 SCAT(message->param.notifyinfo.display, (char *)display);
1288 message->param.notifyinfo.isdn_port = p_m_portnum;
1289 message_put(message);
1293 /* CC_HOLD INDICATION */
1294 struct lcr_msg *message;
1295 void Pdss1::hold_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1297 // class Endpoint *epoint;
1299 l1l2l3_trace_header(p_m_mISDNport, this, L3_HOLD_IND, DIRECTION_IN);
1302 if (!ACTIVE_EPOINT(p_epointlist) || p_m_hold) {
1303 l3m = create_l3msg();
1304 l1l2l3_trace_header(p_m_mISDNport, this, L3_HOLD_REJECT_REQ, DIRECTION_OUT);
1305 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, p_m_hold?101:31); /* normal unspecified / incompatible state */
1306 add_trace("reason", NULL, "no endpoint");
1308 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_HOLD_REJECT, p_m_d_l3id, l3m);
1313 /* notify the hold of call */
1314 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1315 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_HOLD;
1316 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1317 message_put(message);
1319 /* deactivate bchannel */
1320 chan_trace_header(p_m_mISDNport, this, "CHANNEL RELEASE (hold)", DIRECTION_NONE);
1321 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1325 /* set hold state */
1328 epoint = find_epoint_id(ACTIVE_EPOINT(p_epointlist));
1329 if (epoint && p_m_d_ntmode) {
1330 p_m_timeout = p_settings.tout_hold;
1335 /* acknowledge hold */
1336 l3m = create_l3msg();
1337 l1l2l3_trace_header(p_m_mISDNport, this, L3_HOLD_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1339 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_HOLD_ACKNOWLEDGE, p_m_d_l3id, l3m);
1343 /* CC_RETRIEVE INDICATION */
1344 void Pdss1::retrieve_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1346 struct lcr_msg *message;
1347 int channel, exclusive, cause;
1350 l1l2l3_trace_header(p_m_mISDNport, this, L3_RETRIEVE_IND, DIRECTION_IN);
1351 dec_ie_channel_id(l3m, &exclusive, &channel);
1355 cause = 101; /* incompatible state */
1358 l3m = create_l3msg();
1359 l1l2l3_trace_header(p_m_mISDNport, this, L3_RETRIEVE_REJECT_REQ, DIRECTION_OUT);
1360 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, cause);
1362 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RETRIEVE_REJECT, p_m_d_l3id, l3m);
1367 /* notify the retrieve of call */
1368 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1369 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_RETRIEVAL;
1370 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1371 message_put(message);
1374 ret = channel = hunt_bchannel(channel, exclusive);
1379 ret = seize_bchannel(channel, 1);
1385 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
1387 /* set hold state */
1391 /* acknowledge retrieve */
1392 l3m = create_l3msg();
1393 l1l2l3_trace_header(p_m_mISDNport, this, L3_RETRIEVE_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1394 enc_ie_channel_id(l3m, 1, p_m_b_channel);
1396 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RETRIEVE_ACKNOWLEDGE, p_m_d_l3id, l3m);
1399 /* CC_SUSPEND INDICATION */
1400 void Pdss1::suspend_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1402 struct lcr_msg *message;
1403 class Endpoint *epoint;
1404 unsigned char callid[8];
1406 int ret = -31; /* normal, unspecified */
1408 l1l2l3_trace_header(p_m_mISDNport, this, L3_SUSPEND_IND, DIRECTION_IN);
1409 dec_ie_call_id(l3m, callid, &len);
1412 if (!ACTIVE_EPOINT(p_epointlist)) {
1414 l3m = create_l3msg();
1415 l1l2l3_trace_header(p_m_mISDNport, this, L3_SUSPEND_REJECT_REQ, DIRECTION_OUT);
1416 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1418 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SUSPEND_REJECT, p_m_d_l3id, l3m);
1425 /* check if call id is in use */
1426 epoint = epoint_first;
1428 if (epoint->ep_park) {
1429 if (epoint->ep_park_len == len)
1430 if (!memcmp(epoint->ep_park_callid, callid, len)) {
1431 ret = -84; /* call id in use */
1435 epoint = epoint->next;
1438 /* notify the hold of call */
1439 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1440 message->param.notifyinfo.notify = INFO_NOTIFY_USER_SUSPENDED;
1441 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1442 message_put(message);
1444 /* deactivate bchannel */
1445 chan_trace_header(p_m_mISDNport, this, "CHANNEL RELEASE (suspend)", DIRECTION_NONE);
1446 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1450 /* sending suspend to endpoint */
1451 while (p_epointlist) {
1452 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_SUSPEND);
1453 memcpy(message->param.parkinfo.callid, callid, sizeof(message->param.parkinfo.callid));
1454 message->param.parkinfo.len = len;
1455 message_put(message);
1457 free_epointlist(p_epointlist);
1460 /* sending SUSPEND_ACKNOWLEDGE */
1461 l3m = create_l3msg();
1462 l1l2l3_trace_header(p_m_mISDNport, this, L3_SUSPEND_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1464 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SUSPEND_ACKNOWLEDGE, p_m_d_l3id, l3m);
1466 new_state(PORT_STATE_RELEASE);
1470 /* CC_RESUME INDICATION */
1471 void Pdss1::resume_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1473 unsigned char callid[8];
1475 int channel, exclusive;
1476 class Endpoint *epoint;
1477 struct lcr_msg *message;
1480 /* process given callref */
1481 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_IND, DIRECTION_IN);
1482 add_trace("callref", "new", "0x%x", pid);
1484 /* release is case the ID is already in use */
1485 add_trace("error", NULL, "callref already in use");
1487 l3m = create_l3msg();
1488 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_REJECT_REQ, DIRECTION_OUT);
1489 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47);
1490 add_trace("reason", NULL, "callref already in use");
1492 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RESUME_REJECT, pid, l3m);
1493 new_state(PORT_STATE_RELEASE);
1498 p_m_d_ces = pid >> 16;
1501 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_IND, DIRECTION_IN);
1502 dec_ie_call_id(l3m, callid, &len);
1505 /* if blocked, release call */
1506 if (p_m_mISDNport->ifport->block) {
1514 /* channel_id (no channel is possible in message) */
1516 channel = -1; /* any channel */
1519 ret = channel = hunt_bchannel(channel, exclusive);
1523 // mode (if hdlc parked) to be done. never mind, this is almost never requested
1525 ret = seize_bchannel(channel, 1);
1529 l3m = create_l3msg();
1530 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_REJECT_REQ, DIRECTION_OUT);
1531 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1533 add_trace("reason", NULL, "port blocked");
1535 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RESUME_REJECT, p_m_d_l3id, l3m);
1536 new_state(PORT_STATE_RELEASE);
1540 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
1542 /* create endpoint */
1544 FATAL("Incoming resume but already got an endpoint.\n");
1545 ret = -85; /* no call suspended */
1546 epoint = epoint_first;
1548 if (epoint->ep_park) {
1549 ret = -83; /* suspended call exists, but this not */
1550 if (epoint->ep_park_len == len)
1551 if (!memcmp(epoint->ep_park_callid, callid, len))
1554 epoint = epoint->next;
1559 epointlist_new(epoint->ep_serial);
1560 if (!(epoint->portlist_new(p_serial, p_type, p_m_mISDNport->earlyb)))
1561 FATAL("No memory for portlist\n");
1562 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RESUME);
1563 message_put(message);
1565 /* notify the resume of call */
1566 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1567 message->param.notifyinfo.notify = INFO_NOTIFY_USER_RESUMED;
1568 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1569 message_put(message);
1571 /* sending RESUME_ACKNOWLEDGE */
1572 l3m = create_l3msg();
1573 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1574 enc_ie_channel_id(l3m, 1, p_m_b_channel);
1576 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RESUME_ACKNOWLEDGE, p_m_d_l3id, l3m);
1578 new_state(PORT_STATE_CONNECT);
1582 /* CC_FACILITY INDICATION */
1583 void Pdss1::facility_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1585 unsigned char facil[256];
1587 struct lcr_msg *message;
1589 l1l2l3_trace_header(p_m_mISDNport, this, L3_FACILITY_IND, DIRECTION_IN);
1590 dec_ie_facility(l3m, facil, &facil_len);
1597 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_FACILITY);
1598 message->param.facilityinfo.len = facil_len;
1599 memcpy(message->param.facilityinfo.data, facil, facil_len);
1600 message_put(message);
1604 /* CC_PROGRESS INDICATION */
1605 void Pdss1::progress_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1607 int coding, location, progress;
1609 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROGRESS_IND, DIRECTION_IN);
1610 dec_ie_progress(l3m, &coding, &location, &progress);
1616 * handler for isdn connections
1617 * incoming information are parsed and sent via message to the endpoint
1619 void Pdss1::message_isdn(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1626 PERROR("Pdss1(%s) timeout without cause.\n", p_name);
1629 if (l3m->cause[0] != 5) {
1630 PERROR("Pdss1(%s) expecting timeout with timer diagnostic. (got len=%d)\n", p_name, l3m->cause[0]);
1633 timer = (l3m->cause[3]-'0')*100;
1634 timer += (l3m->cause[4]-'0')*10;
1635 timer += (l3m->cause[5]-'0');
1636 l1l2l3_trace_header(p_m_mISDNport, this, L3_TIMEOUT_IND, DIRECTION_IN);
1637 add_trace("timer", NULL, "%d", timer);
1640 t312_timeout_ind(cmd, pid, l3m);
1644 if (p_state != PORT_STATE_IDLE)
1646 setup_ind(cmd, pid, l3m);
1649 case MT_INFORMATION:
1650 information_ind(cmd, pid, l3m);
1653 case MT_SETUP_ACKNOWLEDGE:
1654 if (p_state != PORT_STATE_OUT_SETUP) {
1655 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received setup_acknowledge, but we are not in outgoing setup state, IGNORING.\n", p_name);
1658 setup_acknowledge_ind(cmd, pid, l3m);
1661 case MT_CALL_PROCEEDING:
1662 if (p_state != PORT_STATE_OUT_SETUP
1663 && p_state != PORT_STATE_OUT_OVERLAP) {
1664 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received proceeding, but we are not in outgoing setup OR overlap state, IGNORING.\n", p_name);
1667 proceeding_ind(cmd, pid, l3m);
1671 if (p_state != PORT_STATE_OUT_SETUP
1672 && p_state != PORT_STATE_OUT_OVERLAP
1673 && p_state != PORT_STATE_OUT_PROCEEDING) {
1674 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding state, IGNORING.\n", p_name);
1677 alerting_ind(cmd, pid, l3m);
1681 if (p_state != PORT_STATE_OUT_SETUP
1682 && p_state != PORT_STATE_OUT_OVERLAP
1683 && p_state != PORT_STATE_OUT_PROCEEDING
1684 && p_state != PORT_STATE_OUT_ALERTING) {
1685 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);
1688 connect_ind(cmd, pid, l3m);
1689 if (p_m_d_notify_pending) {
1690 /* send pending notify message during connect */
1691 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
1692 message_free(p_m_d_notify_pending);
1693 p_m_d_notify_pending = NULL;
1697 case MT_CONNECT_ACKNOWLEDGE:
1698 if (p_state == PORT_STATE_CONNECT_WAITING)
1699 new_state(PORT_STATE_CONNECT);
1700 if (p_m_d_notify_pending) {
1701 /* send pending notify message during connect-ack */
1702 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
1703 message_free(p_m_d_notify_pending);
1704 p_m_d_notify_pending = NULL;
1709 disconnect_ind(cmd, pid, l3m);
1713 release_ind(cmd, pid, l3m);
1716 case MT_RELEASE_COMPLETE:
1717 release_complete_ind(cmd, pid, l3m);
1721 restart_ind(cmd, pid, l3m);
1725 notify_ind(cmd, pid, l3m);
1729 hold_ind(cmd, pid, l3m);
1733 retrieve_ind(cmd, pid, l3m);
1737 suspend_ind(cmd, pid, l3m);
1741 resume_ind(cmd, pid, l3m);
1745 facility_ind(cmd, pid, l3m);
1749 progress_ind(cmd, pid, l3m);
1753 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_L3ID_IND, DIRECTION_IN);
1754 add_trace("callref", NULL, "0x%x", p_m_d_l3id);
1759 /* sending release to endpoint in case we still have an endpoint
1760 * this is because we don't get any response if a release_complete is received (or a release in release state)
1762 while(p_epointlist) { // only if not already released
1763 struct lcr_msg *message;
1764 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1765 if (p_m_d_collect_cause) {
1766 message->param.disconnectinfo.cause = p_m_d_collect_cause;
1767 message->param.disconnectinfo.location = p_m_d_collect_location;
1769 message->param.disconnectinfo.cause = CAUSE_NOUSER;
1770 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1772 message_put(message);
1774 free_epointlist(p_epointlist);
1776 new_state(PORT_STATE_RELEASE);
1781 l1l2l3_trace_header(p_m_mISDNport, this, L3_UNKNOWN_IND, DIRECTION_IN);
1782 add_trace("unhandled", "cmd", "0x%x", cmd);
1787 void Pdss1::new_state(int state)
1789 // class Endpoint *epoint;
1792 if (state == PORT_STATE_IN_OVERLAP) {
1793 p_m_timeout = p_m_mISDNport->ifport->tout_dialing;
1796 if (state != p_state) {
1797 if (state == PORT_STATE_IN_SETUP
1798 || state == PORT_STATE_OUT_SETUP
1799 || state == PORT_STATE_IN_OVERLAP
1800 || state == PORT_STATE_OUT_OVERLAP) {
1801 p_m_timeout = p_m_mISDNport->ifport->tout_setup;
1804 if (state == PORT_STATE_IN_PROCEEDING
1805 || state == PORT_STATE_OUT_PROCEEDING) {
1806 p_m_timeout = p_m_mISDNport->ifport->tout_proceeding;
1809 if (state == PORT_STATE_IN_ALERTING
1810 || state == PORT_STATE_OUT_ALERTING) {
1811 p_m_timeout = p_m_mISDNport->ifport->tout_alerting;
1814 if (state == PORT_STATE_CONNECT
1815 || state == PORT_STATE_CONNECT_WAITING) {
1818 if (state == PORT_STATE_IN_DISCONNECT
1819 || state == PORT_STATE_OUT_DISCONNECT) {
1820 p_m_timeout = p_m_mISDNport->ifport->tout_disconnect;
1825 Port::new_state(state);
1832 int Pdss1::handler(void)
1836 if ((ret = PmISDN::handler()))
1839 /* handle destruction */
1840 if (p_m_delete && p_m_d_l3id==0) {
1850 * handles all messages from endpoint
1852 /* MESSAGE_INFORMATION */
1853 void Pdss1::message_information(unsigned int epoint_id, int message_id, union parameter *param)
1856 char *display = param->information.display;
1857 char *number = param->information.id;
1858 int max = p_m_mISDNport->ifport->dialmax;
1860 while (number[0]) { /* as long we have something to dial */
1861 if (max > (int)strlen(number) || max == 0)
1862 max = (int)strlen(number);
1864 l3m = create_l3msg();
1865 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
1866 enc_ie_called_pn(l3m, 0, 1, (unsigned char *)number, max);
1867 if ((p_m_d_ntmode || p_m_d_tespecial) && display[0]) {
1868 enc_ie_display(l3m, (unsigned char *)display);
1872 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
1882 void Pdss1::message_setup(unsigned int epoint_id, int message_id, union parameter *param)
1886 int plan, type, screen, present, reason;
1887 int plan2, type2, screen2, present2;
1888 int capability, mode, rate, coding, user, presentation, interpretation, hlc, exthlc;
1889 int channel, exclusive;
1890 struct epoint_list *epointlist;
1891 int max = p_m_mISDNport->ifport->dialmax;
1893 /* release if port is blocked */
1894 if (p_m_mISDNport->ifport->block) {
1895 struct lcr_msg *message;
1897 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1898 message->param.disconnectinfo.cause = 27; // temp. unavail.
1899 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1900 message_put(message);
1901 new_state(PORT_STATE_RELEASE);
1906 /* copy setup infos to port */
1907 memcpy(&p_callerinfo, ¶m->setup.callerinfo, sizeof(p_callerinfo));
1908 memcpy(&p_dialinginfo, ¶m->setup.dialinginfo, sizeof(p_dialinginfo));
1909 memcpy(&p_capainfo, ¶m->setup.capainfo, sizeof(p_capainfo));
1910 memcpy(&p_redirinfo, ¶m->setup.redirinfo, sizeof(p_redirinfo));
1911 /* screen outgoing caller id */
1912 do_screen(1, p_callerinfo.id, sizeof(p_callerinfo.id), &p_callerinfo.ntype, &p_callerinfo.present, p_m_mISDNport->ifport->interface);
1913 do_screen(1, p_callerinfo.id2, sizeof(p_callerinfo.id2), &p_callerinfo.ntype2, &p_callerinfo.present2, p_m_mISDNport->ifport->interface);
1915 /* only display at connect state: this case happens if endpoint is in connected mode */
1916 if (p_state==PORT_STATE_CONNECT) {
1917 if (p_type!=PORT_TYPE_DSS1_NT_OUT
1918 && p_type!=PORT_TYPE_DSS1_NT_IN)
1920 if (p_callerinfo.display[0]) {
1921 /* sending information */
1922 l3m = create_l3msg();
1923 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
1924 if (p_m_d_ntmode || p_m_d_tespecial)
1925 enc_ie_display(l3m, (unsigned char *)p_callerinfo.display);
1927 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
1932 /* attach only if not already */
1933 epointlist = p_epointlist;
1935 if (epointlist->epoint_id == epoint_id)
1937 epointlist = epointlist->next;
1940 epointlist_new(epoint_id);
1944 if (p_m_b_channel) {
1945 channel = p_m_b_channel;
1946 exclusive = p_m_b_exclusive;
1948 channel = CHANNEL_ANY;
1949 /* nt-port with no channel, not reserverd */
1950 if (!p_m_b_channel && !p_m_b_reserve && p_type==PORT_TYPE_DSS1_NT_OUT)
1951 channel = CHANNEL_NO;
1954 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_REQ, DIRECTION_OUT);
1955 /* see MT_ASSIGN notes at do_layer3() */
1957 ret = p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_ASSIGN, 0, NULL);
1958 if (mt_assign_pid == 0 || ret < 0) {
1959 struct lcr_msg *message;
1961 add_trace("callref", NULL, "no free id");
1963 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1964 message->param.disconnectinfo.cause = 47;
1965 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1966 message_put(message);
1967 new_state(PORT_STATE_RELEASE);
1971 p_m_d_l3id = mt_assign_pid;
1973 add_trace("callref", "new", "0x%x", p_m_d_l3id);
1976 /* preparing setup message */
1977 l3m = create_l3msg();
1978 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_REQ, DIRECTION_OUT);
1979 /* channel information */
1980 if (channel >= 0) /* it should */
1981 enc_ie_channel_id(l3m, exclusive, channel);
1982 /* caller information */
1984 switch (p_callerinfo.ntype) {
1985 case INFO_NTYPE_UNKNOWN:
1988 case INFO_NTYPE_INTERNATIONAL:
1991 case INFO_NTYPE_NATIONAL:
1994 case INFO_NTYPE_SUBSCRIBER:
1997 default: /* INFO_NTYPE_NOTPRESENT */
2001 switch (p_callerinfo.screen) {
2002 case INFO_SCREEN_USER:
2005 default: /* INFO_SCREEN_NETWORK */
2009 switch (p_callerinfo.present) {
2010 case INFO_PRESENT_ALLOWED:
2013 case INFO_PRESENT_RESTRICTED:
2016 default: /* INFO_PRESENT_NOTAVAIL */
2020 /* caller information 2 */
2022 switch (p_callerinfo.ntype2) {
2023 case INFO_NTYPE_UNKNOWN:
2026 case INFO_NTYPE_INTERNATIONAL:
2029 case INFO_NTYPE_NATIONAL:
2032 case INFO_NTYPE_SUBSCRIBER:
2035 default: /* INFO_NTYPE_NOTPRESENT */
2039 switch (p_callerinfo.screen2) {
2040 case INFO_SCREEN_USER:
2043 default: /* INFO_SCREEN_NETWORK */
2047 switch (p_callerinfo.present2) {
2048 case INFO_PRESENT_ALLOWED:
2051 case INFO_PRESENT_RESTRICTED:
2054 default: /* INFO_PRESENT_NOTAVAIL */
2059 enc_ie_calling_pn(l3m, type, plan, present, screen, (unsigned char *)p_callerinfo.id, type2, plan2, present2, screen2, (unsigned char *)p_callerinfo.id2);
2060 /* dialing information */
2061 if (p_dialinginfo.id[0]) { /* only if we have something to dial */
2062 if (max > (int)strlen(p_dialinginfo.id) || max == 0)
2063 max = (int)strlen(p_dialinginfo.id);
2064 enc_ie_called_pn(l3m, 0, 1, (unsigned char *)p_dialinginfo.id, max);
2065 SCPY(p_m_d_queue, p_dialinginfo.id + max);
2067 /* sending complete */
2068 if (p_dialinginfo.sending_complete)
2069 enc_ie_complete(l3m, 1);
2070 /* sending user-user */
2071 if (param->setup.useruser.len) {
2072 enc_ie_useruser(l3m, param->setup.useruser.protocol, param->setup.useruser.data, param->setup.useruser.len);
2074 /* redirecting number */
2076 switch (p_redirinfo.ntype) {
2077 case INFO_NTYPE_UNKNOWN:
2080 case INFO_NTYPE_INTERNATIONAL:
2083 case INFO_NTYPE_NATIONAL:
2086 case INFO_NTYPE_SUBSCRIBER:
2089 default: /* INFO_NTYPE_NOTPRESENT */
2093 switch (p_redirinfo.screen) {
2094 case INFO_SCREEN_USER:
2097 default: /* INFO_SCREE_NETWORK */
2101 switch (p_redirinfo.reason) {
2102 case INFO_REDIR_BUSY:
2105 case INFO_REDIR_NORESPONSE:
2108 case INFO_REDIR_UNCONDITIONAL:
2111 case INFO_REDIR_CALLDEFLECT:
2114 case INFO_REDIR_OUTOFORDER:
2117 default: /* INFO_REDIR_UNKNOWN */
2121 switch (p_redirinfo.present) {
2122 case INFO_PRESENT_ALLOWED:
2125 case INFO_PRESENT_RESTRICTED:
2128 default: /* INFO_PRESENT_NOTAVAIL */
2132 /* sending redirecting number only in ntmode */
2133 if (type >= 0 && (p_m_d_ntmode || p_m_d_tespecial))
2134 enc_ie_redir_nr(l3m, type, plan, present, screen, reason, (unsigned char *)p_redirinfo.id);
2135 /* bearer capability */
2136 //printf("hlc=%d\n",p_capainfo.hlc);
2138 capability = p_capainfo.bearer_capa;
2139 mode = p_capainfo.bearer_mode;
2140 rate = (mode==INFO_BMODE_CIRCUIT)?0x10:0x00;
2141 switch (p_capainfo.bearer_info1) {
2142 case INFO_INFO1_NONE:
2146 user = p_capainfo.bearer_info1 & 0x7f;
2149 enc_ie_bearer(l3m, coding, capability, mode, rate, -1, user);
2151 if (p_capainfo.hlc) {
2155 hlc = p_capainfo.hlc & 0x7f;
2157 if (p_capainfo.exthlc)
2158 exthlc = p_capainfo.exthlc & 0x7f;
2159 enc_ie_hlc(l3m, coding, interpretation, presentation, hlc, exthlc);
2163 if (p_callerinfo.display[0] && (p_m_d_ntmode || p_m_d_tespecial))
2164 enc_ie_display(l3m, (unsigned char *)p_callerinfo.display);
2165 /* nt-mode: CNIP (calling name identification presentation) */
2166 // if (p_callerinfo.name[0] && (p_m_d_ntmode || p_m_d_tespecial))
2167 // enc_facility_centrex(&setup->FACILITY, dmsg, (unsigned char *)p_callerinfo.name, 1);
2170 /* send setup message now */
2171 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SETUP, p_m_d_l3id, l3m);
2173 new_state(PORT_STATE_OUT_SETUP);
2176 /* MESSAGE_FACILITY */
2177 void Pdss1::message_facility(unsigned int epoint_id, int message_id, union parameter *param)
2181 /* facility will not be sent to external lines */
2182 if (!p_m_d_ntmode && !p_m_d_tespecial)
2185 /* sending facility */
2186 l3m = create_l3msg();
2187 l1l2l3_trace_header(p_m_mISDNport, this, L3_FACILITY_REQ, DIRECTION_OUT);
2188 enc_ie_facility(l3m, (unsigned char *)param->facilityinfo.data, param->facilityinfo.len);
2190 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_FACILITY, p_m_d_l3id, l3m);
2193 /* MESSAGE_NOTIFY */
2194 void Pdss1::message_notify(unsigned int epoint_id, int message_id, union parameter *param)
2198 int plan = 0, type = -1, present = 0;
2200 printf("if = %d\n", param->notifyinfo.notify);
2201 if (param->notifyinfo.notify>INFO_NOTIFY_NONE)
2202 notify = param->notifyinfo.notify & 0x7f;
2207 switch (param->notifyinfo.ntype) {
2208 case INFO_NTYPE_UNKNOWN:
2211 case INFO_NTYPE_INTERNATIONAL:
2214 case INFO_NTYPE_NATIONAL:
2217 case INFO_NTYPE_SUBSCRIBER:
2220 default: /* INFO_NTYPE_UNKNOWN */
2224 switch (param->notifyinfo.present) {
2225 case INFO_PRESENT_ALLOWED:
2228 case INFO_PRESENT_RESTRICTED:
2231 default: /* INFO_PRESENT_NOTAVAIL */
2237 if (notify<0 && !param->notifyinfo.display[0]) {
2238 /* nothing to notify, nothing to display */
2243 if (p_state!=PORT_STATE_CONNECT && p_state!=PORT_STATE_IN_PROCEEDING && p_state!=PORT_STATE_IN_ALERTING) {
2244 /* queue notification */
2245 if (p_m_d_notify_pending)
2246 message_free(p_m_d_notify_pending);
2247 p_m_d_notify_pending = message_create(ACTIVE_EPOINT(p_epointlist), p_serial, EPOINT_TO_PORT, message_id);
2248 memcpy(&p_m_d_notify_pending->param, param, sizeof(union parameter));
2250 /* sending notification */
2251 l3m = create_l3msg();
2252 l1l2l3_trace_header(p_m_mISDNport, this, L3_NOTIFY_REQ, DIRECTION_OUT);
2253 enc_ie_notify(l3m, notify);
2254 /* sending redirection number only in ntmode */
2255 if (type >= 0 && (p_m_d_ntmode || p_m_d_tespecial))
2256 enc_ie_redir_dn(l3m, type, plan, present, (unsigned char *)param->notifyinfo.id);
2257 if (param->notifyinfo.display[0] && (p_m_d_ntmode || p_m_d_tespecial))
2258 enc_ie_display(l3m, (unsigned char *)param->notifyinfo.display);
2260 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_NOTIFY, p_m_d_l3id, l3m);
2262 } else if (p_m_d_ntmode || p_m_d_tespecial) {
2263 /* sending information */
2264 l3m = create_l3msg();
2265 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
2266 enc_ie_display(l3m, (unsigned char *)param->notifyinfo.display);
2268 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
2272 /* MESSAGE_OVERLAP */
2273 void Pdss1::message_overlap(unsigned int epoint_id, int message_id, union parameter *param)
2277 /* in case of sending complete, we proceed */
2278 if (p_dialinginfo.sending_complete) {
2279 PDEBUG(DEBUG_ISDN, "sending proceeding instead of setup_acknowledge, because address is complete.\n");
2280 message_proceeding(epoint_id, message_id, param);
2284 /* sending setup_acknowledge */
2285 l3m = create_l3msg();
2286 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_ACKNOWLEDGE_REQ, DIRECTION_OUT);
2287 /* channel information */
2288 if (p_state == PORT_STATE_IN_SETUP)
2289 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2290 /* progress information */
2291 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2292 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2293 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2294 if (p_m_mISDNport->tones)
2295 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2297 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SETUP_ACKNOWLEDGE, p_m_d_l3id, l3m);
2299 new_state(PORT_STATE_IN_OVERLAP);
2302 /* MESSAGE_PROCEEDING */
2303 void Pdss1::message_proceeding(unsigned int epoint_id, int message_id, union parameter *param)
2307 /* sending proceeding */
2308 l3m = create_l3msg();
2309 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2310 /* channel information */
2311 if (p_state == PORT_STATE_IN_SETUP)
2312 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2313 /* progress information */
2314 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2315 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2316 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2317 if (p_m_mISDNport->tones)
2318 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2320 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2322 new_state(PORT_STATE_IN_PROCEEDING);
2325 /* MESSAGE_ALERTING */
2326 void Pdss1::message_alerting(unsigned int epoint_id, int message_id, union parameter *param)
2330 /* NT-MODE in setup state we must send PROCEEDING first */
2331 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP) {
2332 /* sending proceeding */
2333 l3m = create_l3msg();
2334 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2335 /* channel information */
2336 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2337 /* progress information */
2338 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2339 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2340 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2341 if (p_m_mISDNport->tones)
2342 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2344 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2345 new_state(PORT_STATE_IN_PROCEEDING);
2348 /* sending alerting */
2349 l3m = create_l3msg();
2350 l1l2l3_trace_header(p_m_mISDNport, this, L3_ALERTING_REQ, DIRECTION_OUT);
2351 /* channel information */
2352 if (p_state == PORT_STATE_IN_SETUP)
2353 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2354 /* progress information */
2355 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2356 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2357 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2358 if (p_m_mISDNport->tones)
2359 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2361 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_ALERTING, p_m_d_l3id, l3m);
2363 new_state(PORT_STATE_IN_ALERTING);
2366 /* MESSAGE_CONNECT */
2367 void Pdss1::message_connect(unsigned int epoint_id, int message_id, union parameter *param)
2370 int type, plan, present, screen;
2371 class Endpoint *epoint;
2373 /* NT-MODE in setup state we must send PROCEEDING first */
2374 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP) {
2375 /* sending proceeding */
2376 l3m = create_l3msg();
2377 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2378 /* channel information */
2379 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2381 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2382 new_state(PORT_STATE_IN_PROCEEDING);
2385 /* copy connected information */
2386 memcpy(&p_connectinfo, ¶m->connectinfo, sizeof(p_connectinfo));
2387 /* screen outgoing caller id */
2388 do_screen(1, p_connectinfo.id, sizeof(p_connectinfo.id), &p_connectinfo.ntype, &p_connectinfo.present, p_m_mISDNport->ifport->interface);
2390 /* only display at connect state */
2391 if (p_state == PORT_STATE_CONNECT)
2392 if (p_connectinfo.display[0]) {
2393 /* sending information */
2394 l3m = create_l3msg();
2395 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
2396 if (p_m_d_ntmode || p_m_d_tespecial)
2397 enc_ie_display(l3m, (unsigned char *)p_connectinfo.display);
2399 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
2403 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) {
2404 /* connect command only possible in setup, proceeding or alerting state */
2408 /* preparing connect message */
2409 l3m = create_l3msg();
2410 l1l2l3_trace_header(p_m_mISDNport, this, L3_CONNECT_REQ, DIRECTION_OUT);
2411 /* connect information */
2413 switch (p_connectinfo.ntype) {
2414 case INFO_NTYPE_UNKNOWN:
2417 case INFO_NTYPE_INTERNATIONAL:
2420 case INFO_NTYPE_NATIONAL:
2423 case INFO_NTYPE_SUBSCRIBER:
2426 default: /* INFO_NTYPE_NOTPRESENT */
2430 switch (param->connectinfo.screen) {
2431 case INFO_SCREEN_USER:
2434 default: /* INFO_SCREE_NETWORK */
2438 switch (p_connectinfo.present) {
2439 case INFO_PRESENT_ALLOWED:
2442 case INFO_PRESENT_RESTRICTED:
2445 default: /* INFO_PRESENT_NOTAVAIL */
2450 enc_ie_connected_pn(l3m, type, plan, present, screen, (unsigned char *)p_connectinfo.id);
2452 if (p_connectinfo.display[0] && (p_m_d_ntmode || p_m_d_tespecial))
2453 enc_ie_display(l3m, (unsigned char *)p_connectinfo.display);
2454 /* nt-mode: CONP (connected name identification presentation) */
2455 // if (p_connectinfo.name[0] && (p_m_d_ntmode || p_m_d_tespecial))
2456 // enc_facility_centrex(&connect->FACILITY, dmsg, (unsigned char *)p_connectinfo.name, 0);
2458 if (p_m_d_ntmode || p_m_d_tespecial) {
2459 epoint = find_epoint_id(epoint_id);
2460 enc_ie_date(l3m, now, p_settings.no_seconds);
2463 /* finally send message */
2464 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CONNECT, p_m_d_l3id, l3m);
2467 new_state(PORT_STATE_CONNECT);
2469 new_state(PORT_STATE_CONNECT_WAITING);
2473 /* MESSAGE_DISCONNECT */
2474 void Pdss1::message_disconnect(unsigned int epoint_id, int message_id, union parameter *param)
2477 struct lcr_msg *message;
2480 /* we reject during incoming setup when we have no tones. also if we are in outgoing setup state */
2481 // if ((p_state==PORT_STATE_IN_SETUP && !p_m_mISDNport->tones)
2482 if (/* ||*/ p_state==PORT_STATE_OUT_SETUP) {
2483 /* sending release to endpoint */
2484 while(p_epointlist) {
2485 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
2486 memcpy(&message->param, param, sizeof(union parameter));
2487 message_put(message);
2489 free_epointlist(p_epointlist);
2491 /* sending release */
2492 l3m = create_l3msg();
2493 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
2495 enc_ie_cause(l3m, (!p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_REMOTE:param->disconnectinfo.location, param->disconnectinfo.cause);
2497 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
2498 new_state(PORT_STATE_RELEASE);
2503 /* workarround: NT-MODE in setup state we must send PROCEEDING first to make it work */
2504 if (p_state==PORT_STATE_IN_SETUP) {
2505 /* sending proceeding */
2506 l3m = create_l3msg();
2507 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2508 /* channel information */
2509 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2510 /* progress information */
2511 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2512 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2513 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2514 if (p_m_mISDNport->tones)
2515 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2517 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2518 new_state(PORT_STATE_IN_PROCEEDING);
2521 /* sending disconnect */
2522 l3m = create_l3msg();
2523 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_REQ, DIRECTION_OUT);
2524 /* progress information */
2525 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2526 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2527 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2528 if (p_m_mISDNport->tones)
2529 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2531 enc_ie_cause(l3m, (!p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_REMOTE:param->disconnectinfo.location, param->disconnectinfo.cause);
2533 if (param->disconnectinfo.display[0])
2534 p = param->disconnectinfo.display;
2535 if (p) if (*p && (p_m_d_ntmode || p_m_d_tespecial))
2536 enc_ie_display(l3m, (unsigned char *)p);
2538 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_DISCONNECT, p_m_d_l3id, l3m);
2539 new_state(PORT_STATE_OUT_DISCONNECT);
2542 /* MESSAGE_RELEASE */
2543 void Pdss1::message_release(unsigned int epoint_id, int message_id, union parameter *param)
2546 class Endpoint *epoint;
2550 * we may only release during incoming disconnect state.
2551 * this means that the endpoint doesnt require audio anymore
2553 if (p_state == PORT_STATE_IN_DISCONNECT
2554 || p_state == PORT_STATE_OUT_DISCONNECT) {
2555 /* sending release */
2556 l3m = create_l3msg();
2557 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_REQ, DIRECTION_OUT);
2559 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2561 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE, p_m_d_l3id, l3m);
2562 new_state(PORT_STATE_RELEASE);
2564 free_epointid(epoint_id);
2565 // wait for callref to be released
2570 * if we are on incoming call setup, we may reject by sending a release_complete
2571 * also on outgoing call setup, we send a release complete, BUT this is not conform. (i don't know any other way)
2573 if (p_state==PORT_STATE_IN_SETUP
2574 || p_state==PORT_STATE_OUT_SETUP) {
2575 //#warning remove me
2576 //PDEBUG(DEBUG_LOG, "JOLLY sending release complete %d\n", p_serial);
2577 /* sending release complete */
2578 l3m = create_l3msg();
2579 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_REQ, DIRECTION_OUT);
2581 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2583 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
2584 new_state(PORT_STATE_RELEASE);
2586 free_epointid(epoint_id);
2587 // wait for callref to be released
2592 wirklich erst proceeding?:
2593 /* NT-MODE in setup state we must send PROCEEDING first */
2594 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP) {
2595 CALL_PROCEEDING_t *proceeding;
2597 /* sending proceeding */
2598 l3m = create_l3msg();
2599 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2600 /* channel information */
2601 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2602 /* progress information */
2603 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2604 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2605 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2606 if (p_m_mISDNport->tones)
2607 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2609 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2613 /* sending disconnect */
2614 l3m = create_l3msg();
2615 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_REQ, DIRECTION_OUT);
2616 /* progress information */
2617 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2618 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2619 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2620 if (p_m_mISDNport->tones)
2621 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2623 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2625 epoint = find_epoint_id(epoint_id);
2626 if (param->disconnectinfo.display[0])
2627 p = param->disconnectinfo.display;
2628 if (p) if (*p && (p_m_d_ntmode || p_m_d_tespecial))
2629 enc_ie_display(l3m, (unsigned char *)p);
2631 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_DISCONNECT, p_m_d_l3id, l3m);
2632 new_state(PORT_STATE_OUT_DISCONNECT);
2634 free_epointid(epoint_id);
2635 // wait for release and callref to be released
2636 //#warning remove me
2637 //PDEBUG(DEBUG_LOG, "JOLLY sending disconnect %d\n", p_serial);
2642 * endpoint sends messages to the port
2644 int Pdss1::message_epoint(unsigned int epoint_id, int message_id, union parameter *param)
2646 if (PmISDN::message_epoint(epoint_id, message_id, param))
2649 switch(message_id) {
2650 case MESSAGE_INFORMATION: /* overlap dialing */
2651 if (p_type==PORT_TYPE_DSS1_NT_OUT
2652 && p_state!=PORT_STATE_OUT_OVERLAP
2653 && p_state!=PORT_STATE_CONNECT
2654 && p_state!=PORT_STATE_OUT_DISCONNECT
2655 && p_state!=PORT_STATE_IN_DISCONNECT) {
2658 if (p_type==PORT_TYPE_DSS1_TE_OUT
2659 && p_state!=PORT_STATE_OUT_OVERLAP
2660 && p_state!=PORT_STATE_OUT_PROCEEDING
2661 && p_state!=PORT_STATE_OUT_ALERTING
2662 && p_state!=PORT_STATE_CONNECT
2663 && p_state!=PORT_STATE_OUT_DISCONNECT
2664 && p_state!=PORT_STATE_IN_DISCONNECT) {
2667 if ((p_type==PORT_TYPE_DSS1_NT_IN || p_type==PORT_TYPE_DSS1_TE_IN)
2668 && p_state!=PORT_STATE_IN_OVERLAP
2669 && p_state!=PORT_STATE_IN_PROCEEDING
2670 && p_state!=PORT_STATE_IN_ALERTING
2671 && p_state!=PORT_STATE_CONNECT
2672 && p_state!=PORT_STATE_CONNECT_WAITING
2673 && p_state!=PORT_STATE_OUT_DISCONNECT
2674 && p_state!=PORT_STATE_IN_DISCONNECT) {
2677 message_information(epoint_id, message_id, param);
2680 case MESSAGE_SETUP: /* dial-out command received from epoint */
2681 if (p_state!=PORT_STATE_IDLE
2682 && p_state!=PORT_STATE_CONNECT) {
2683 PERROR("Pdss1(%s) ignoring setup because isdn port is not in idle state (or connected for sending display info).\n", p_name);
2686 if (p_epointlist && p_state==PORT_STATE_IDLE)
2687 FATAL("Pdss1(%s): epoint pointer is set in idle state, how bad!!\n", p_name);
2688 message_setup(epoint_id, message_id, param);
2691 case MESSAGE_NOTIFY: /* display and notifications */
2692 message_notify(epoint_id, message_id, param);
2695 case MESSAGE_FACILITY: /* facility message */
2696 message_facility(epoint_id, message_id, param);
2699 case MESSAGE_OVERLAP: /* more information is needed */
2700 if (p_state!=PORT_STATE_IN_SETUP) {
2703 message_overlap(epoint_id, message_id, param);
2706 case MESSAGE_PROCEEDING: /* call of endpoint is proceeding */
2707 if (p_state!=PORT_STATE_IN_SETUP
2708 && p_state!=PORT_STATE_IN_OVERLAP) {
2711 message_proceeding(epoint_id, message_id, param);
2712 if (p_m_d_notify_pending) {
2713 /* send pending notify message during connect */
2714 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2715 message_free(p_m_d_notify_pending);
2716 p_m_d_notify_pending = NULL;
2720 case MESSAGE_ALERTING: /* call of endpoint is ringing */
2721 if (p_state!=PORT_STATE_IN_SETUP
2722 && p_state!=PORT_STATE_IN_OVERLAP
2723 && p_state!=PORT_STATE_IN_PROCEEDING) {
2726 message_alerting(epoint_id, message_id, param);
2727 if (p_m_d_notify_pending) {
2728 /* send pending notify message during connect */
2729 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2730 message_free(p_m_d_notify_pending);
2731 p_m_d_notify_pending = NULL;
2735 case MESSAGE_CONNECT: /* call of endpoint is connected */
2736 if (p_state!=PORT_STATE_IN_SETUP
2737 && p_state!=PORT_STATE_IN_OVERLAP
2738 && p_state!=PORT_STATE_IN_PROCEEDING
2739 && p_state!=PORT_STATE_IN_ALERTING
2740 && !(p_state==PORT_STATE_CONNECT && p_m_d_ntmode)) {
2743 message_connect(epoint_id, message_id, param);
2744 if (p_m_d_notify_pending) {
2745 /* send pending notify message during connect */
2746 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2747 message_free(p_m_d_notify_pending);
2748 p_m_d_notify_pending = NULL;
2752 case MESSAGE_DISCONNECT: /* call has been disconnected */
2753 if (p_state!=PORT_STATE_IN_SETUP
2754 && p_state!=PORT_STATE_IN_OVERLAP
2755 && p_state!=PORT_STATE_IN_PROCEEDING
2756 && p_state!=PORT_STATE_IN_ALERTING
2757 && p_state!=PORT_STATE_OUT_SETUP
2758 && p_state!=PORT_STATE_OUT_OVERLAP
2759 && p_state!=PORT_STATE_OUT_PROCEEDING
2760 && p_state!=PORT_STATE_OUT_ALERTING
2761 && p_state!=PORT_STATE_CONNECT
2762 && p_state!=PORT_STATE_CONNECT_WAITING) {
2765 message_disconnect(epoint_id, message_id, param);
2768 case MESSAGE_RELEASE: /* release isdn port */
2769 if (p_state==PORT_STATE_RELEASE) {
2772 message_release(epoint_id, message_id, param);
2776 PERROR("Pdss1(%s) isdn port with (caller id %s) received a wrong message: %d\n", p_name, p_callerinfo.id, message_id);
2785 * data from isdn-stack (layer-3) to pbx (port class)
2787 int stack2manager(struct mISDNport *mISDNport, unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
2793 PDEBUG(DEBUG_ISDN, "cmd(0x%x) pid(0x%x)\n", cmd, pid);
2796 PDEBUG(DEBUG_ISDN, "ignoring dummy process from phone.\n");
2800 /* find Port object of type ISDN */
2804 if ((port->p_type & PORT_CLASS_mISDN_MASK) == PORT_CLASS_mISDN_DSS1) {
2805 pdss1 = (class Pdss1 *)port;
2806 /* check out correct stack and id */
2807 if (pdss1->p_m_mISDNport == mISDNport) {
2808 if (pdss1->p_m_d_l3id & MISDN_PID_CR_FLAG) {
2809 /* local callref, so match value only */
2810 if ((pdss1->p_m_d_l3id & MISDN_PID_CRVAL_MASK) == (pid & MISDN_PID_CRVAL_MASK))
2813 /* remote callref, ref + channel id */
2814 if (pdss1->p_m_d_l3id == pid)
2822 /* aktueller prozess */
2824 if (cmd == MT_ASSIGN) {
2825 /* stack gives us new layer 3 id (during connect) */
2826 l1l2l3_trace_header(mISDNport, pdss1, L3_NEW_L3ID_IND, DIRECTION_IN);
2827 add_trace("callref", "old", "0x%x", pdss1->p_m_d_l3id);
2828 /* nt-library now gives us a new id via CC_SETUP_CONFIRM */
2829 if ((pdss1->p_m_d_l3id&MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER)
2830 PERROR(" strange setup-procid 0x%x\n", pdss1->p_m_d_l3id);
2831 pdss1->p_m_d_l3id = pid;
2832 if (port->p_state == PORT_STATE_CONNECT)
2833 pdss1->p_m_d_ces = pid >> 16;
2834 add_trace("callref", "new", "0x%x", pdss1->p_m_d_l3id);
2838 /* if process id is master process, but a child disconnects */
2839 if (mISDNport->ntmode
2840 && (pid & MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER
2841 && (pdss1->p_m_d_l3id & MISDN_PID_CRTYPE_MASK) == MISDN_PID_MASTER) {
2842 if (cmd == MT_DISCONNECT
2843 || cmd == MT_RELEASE) {
2844 /* send special indication for child disconnect */
2845 pdss1->disconnect_ind_i(cmd, pid, l3m);
2848 if (cmd == MT_RELEASE_COMPLETE)
2851 /* if we have child pid and got different child pid message, ignore */
2852 if (mISDNport->ntmode
2853 && (pid & MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER
2854 && (pdss1->p_m_d_l3id & MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER
2855 && pid != pdss1->p_m_d_l3id)
2858 /* process message */
2859 pdss1->message_isdn(cmd, pid, l3m);
2866 /* creating port object, transparent until setup with hdlc */
2867 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
2868 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0, B_MODE_TRANSPARENT)))
2870 FATAL("Cannot create Port instance.\n");
2871 pdss1->message_isdn(cmd, pid, l3m);
2875 /* creating port object, transparent until setup with hdlc */
2876 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
2877 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0, B_MODE_TRANSPARENT)))
2878 FATAL("Cannot create Port instance.\n");
2879 pdss1->message_isdn(cmd, pid, l3m);
2883 PDEBUG(DEBUG_ISDN, "unused call ref released (l3id=0x%x)\n", pid);
2886 case MT_RELEASE_COMPLETE:
2887 PERROR("must be ignored by stack, not sent to app\n");
2891 // facility als broadcast
2895 PERROR("unhandled message: cmd(0x%x) pid(0x%x)\n", cmd, pid);
2898 if (port->p_type == PORT_TYPE_DSS1_NT_IN || port->p_type == PORT_TYPE_DSS1_NT_OUT) {
2899 pdss1 = (class Pdss1 *)port;
2900 /* check out correct stack */
2901 if (pdss1->p_m_mISDNport == mISDNport)
2902 /* check out correct id */
2903 PERROR("unhandled message: pid=%x is not associated with port-dinfo=%x\n", pid, pdss1->p_m_d_l3id);