1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
10 \*****************************************************************************/
15 //#include <sys/socket.h>
18 #include <mISDN/q931.h>
20 extern unsigned int mt_assign_pid;
25 static int delete_event(struct lcr_work *work, void *instance, int index);
30 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)
32 p_callerinfo.itype = (mISDNport->ifport->interface->extension)?INFO_ITYPE_ISDN_EXTENSION:INFO_ITYPE_ISDN;
33 p_m_d_ntmode = mISDNport->ntmode;
34 p_m_d_tespecial = mISDNport->tespecial;
36 memset(&p_m_d_delete, 0, sizeof(p_m_d_delete));
37 add_work(&p_m_d_delete, delete_event, this, 0);
39 p_m_d_queue[0] = '\0';
40 p_m_d_notify_pending = NULL;
41 p_m_d_collect_cause = 0;
42 p_m_d_collect_location = 0;
44 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);
53 del_work(&p_m_d_delete);
55 /* remove queued message */
56 if (p_m_d_notify_pending)
57 message_free(p_m_d_notify_pending);
62 * create layer 3 message
64 static struct l3_msg *create_l3msg(void)
72 FATAL("Cannot allocate memory, system overloaded.\n");
73 exit(0); // make gcc happy
77 * if we received a first reply to the setup message,
78 * we will check if we have now channel information
79 * return: <0: error, call is released, -cause is given
80 * 0: ok, nothing to do
82 int Pdss1::received_first_reply_to_setup(unsigned int cmd, int channel, int exclusive)
87 /* correct exclusive to 0, if no explicit channel was given */
88 if (exclusive<0 || channel<=0)
92 if (p_m_b_channel && p_m_b_exclusive) {
93 /*** we gave an exclusive channel (or if we are done) ***/
95 /* if not first reply, we are done */
96 if (p_state != PORT_STATE_OUT_SETUP)
99 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
100 add_trace("channel", "request", "%d (forced)", p_m_b_channel);
101 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
103 /* if give channel not accepted or not equal */
104 if (channel!=-1 && p_m_b_channel!=channel) {
105 add_trace("conclusion", NULL, "forced channel not accepted");
111 add_trace("conclusion", NULL, "channel was accepted");
112 add_trace("connect", "channel", "%d", p_m_b_channel);
115 /* activate our exclusive channel */
116 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
119 /*** we gave a non-exclusive channel ***/
121 /* if not first reply, we are done */
122 if (p_state != PORT_STATE_OUT_SETUP)
125 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
126 add_trace("channel", "request", "%d (suggest)", p_m_b_channel);
127 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
129 /* if channel was accepted as given */
130 if (channel==-1 || p_m_b_channel==channel) {
131 add_trace("conclusion", NULL, "channel was accepted as given");
132 add_trace("connect", "channel", "%d", p_m_b_channel);
134 p_m_b_exclusive = 1; // we are done
135 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
139 /* if channel value is faulty */
141 add_trace("conclusion", NULL, "illegal reply");
143 ret = -111; // protocol error
147 /* if channel was not accepted, try to get it */
148 ret = seize_bchannel(channel, 1); // exclusively
149 add_trace("channel", "available", ret<0?"no":"yes");
151 add_trace("conclusion", NULL, "replied channel not available");
155 add_trace("conclusion", NULL, "replied channel accepted");
156 add_trace("connect", "channel", "%d", p_m_b_channel);
159 /* activate channel given by remote */
160 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
163 /*** we sent 'any channel acceptable' ***/
165 /* if not first reply, we are done */
166 if (p_state != PORT_STATE_OUT_SETUP)
169 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
170 add_trace("channel", "request", "any");
171 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
172 /* if no channel was replied */
174 add_trace("conclusion", NULL, "no channel, protocol error");
176 ret = -111; // protocol error
180 /* we will see, if our received channel is available */
181 ret = seize_bchannel(channel, 1); // exclusively
182 add_trace("channel", "available", ret<0?"no":"yes");
184 add_trace("conclusion", NULL, "replied channel not available");
188 add_trace("conclusion", NULL, "replied channel accepted");
189 add_trace("connect", "channel", "%d", p_m_b_channel);
192 /* activate channel given by remote */
193 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
195 /*** we sent 'no channel available' ***/
197 /* if not the first reply, but a connect, we are forced */
198 if (cmd==MT_CONNECT && p_state!=PORT_STATE_OUT_SETUP) {
199 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (connect)", DIRECTION_NONE);
200 add_trace("channel", "request", "no-channel");
201 add_trace("channel", "reply", (channel>=0)?"%d%s":"(none)", channel, exclusive?" (forced)":"");
203 goto use_from_connect;
205 ret = seize_bchannel(CHANNEL_ANY, 0); // any channel
206 add_trace("channel", "available", ret<0?"no":"yes");
208 add_trace("conclusion", NULL, "no channel available during call-waiting");
212 add_trace("conclusion", NULL, "using channel %d", p_m_b_channel);
213 add_trace("connect", "channel", "%d", p_m_b_channel);
215 p_m_b_exclusive = 1; // we are done
217 /* activate channel given by remote */
218 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
222 /* if not first reply, we are done */
223 if (p_state != PORT_STATE_OUT_SETUP)
226 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
227 add_trace("channel", "request", "no-channel");
228 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
229 /* if first reply has no channel, we are done */
231 add_trace("conclusion", NULL, "no channel until connect");
236 /* we will see, if our received channel is available */
238 ret = seize_bchannel(channel, exclusive);
239 add_trace("channel", "available", ret<0?"no":"yes");
241 add_trace("conclusion", NULL, "replied channel not available");
245 add_trace("conclusion", NULL, "replied channel accepted");
246 add_trace("connect", "channel", "%d", p_m_b_channel);
248 p_m_b_exclusive = 1; // we are done
250 /* activate channel given by remote */
251 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
257 * NOTE: we send MT_RELEASE_COMPLETE to "REJECT" the channel
258 * in response to the setup reply
260 l3m = create_l3msg();
261 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
262 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
264 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
265 new_state(PORT_STATE_RELEASE);
266 trigger_work(&p_m_d_delete);
267 return(-34); /* to epoint: no channel available */
272 * hunt bchannel for incoming setup or retrieve or resume
274 int Pdss1::hunt_bchannel(int channel, int exclusive)
276 struct select_channel *selchannel;
277 struct interface_port *ifport = p_m_mISDNport->ifport;
280 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (setup)", DIRECTION_NONE);
283 if (channel == CHANNEL_NO)
284 add_trace("channel", "request", "no-channel");
286 add_trace("channel", "request", (channel>0)?"%d%s":"any", channel, exclusive?" (forced)":"");
287 if (channel==CHANNEL_NO && p_type==PORT_TYPE_DSS1_TE_IN) {
288 add_trace("conclusion", NULL, "incoming call-waiting not supported for TE-mode");
290 return(-6); // channel unacceptable
292 if (channel <= 0) /* not given, no channel, whatever.. */
293 channel = CHANNEL_ANY; /* any channel */
294 add_trace("channel", "reserved", "%d", p_m_mISDNport->b_reserved);
295 if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num) { // of out chan..
296 add_trace("conclusion", NULL, "all channels are reserved");
298 return(-34); // no channel
300 if (channel == CHANNEL_ANY)
303 /* check for given channel in selection list */
304 selchannel = ifport->in_channel;
306 if (selchannel->channel == channel || selchannel->channel == CHANNEL_FREE)
308 selchannel = selchannel->next;
313 /* exclusive channel requests must be in the list */
315 /* no exclusive channel */
317 add_trace("conclusion", NULL, "exclusively requested channel not in list");
319 return(-6); // channel unacceptable
321 /* get index for channel */
322 i = channel-1-(channel>=17);
323 if (i < 0 || i >= p_m_mISDNport->b_num || channel == 16) {
324 add_trace("conclusion", NULL, "exclusively requested channel outside interface range");
326 return(-6); // channel unacceptable
329 if (p_m_mISDNport->b_port[i] == NULL)
331 add_trace("conclusion", NULL, "exclusively requested channel is busy");
333 return(-6); // channel unacceptable
336 /* requested channels in list will be used */
338 /* get index for channel */
339 i = channel-1-(channel>=17);
340 if (i < 0 || i >= p_m_mISDNport->b_num || channel == 16) {
341 add_trace("info", NULL, "requested channel %d outside interface range", channel);
342 } else /* if inside range (else) check if available */
343 if (p_m_mISDNport->b_port[i] == NULL)
347 /* if channel is not available or not in list, it must be searched */
349 /* check for first free channel in list */
351 selchannel = ifport->in_channel;
353 switch(selchannel->channel) {
354 case CHANNEL_FREE: /* free channel */
355 add_trace("hunting", "channel", "free");
356 if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num)
357 break; /* all channel in use or reserverd */
360 while(i < p_m_mISDNport->b_num) {
361 if (p_m_mISDNport->b_port[i] == NULL) {
362 channel = i+1+(i>=15);
370 add_trace("hunting", "channel", "%d", selchannel->channel);
371 if (selchannel->channel<1 || selchannel->channel==16)
372 break; /* invalid channels */
373 i = selchannel->channel-1-(selchannel->channel>=17);
374 if (i >= p_m_mISDNport->b_num)
375 break; /* channel not in port */
376 if (p_m_mISDNport->b_port[i] == NULL) {
377 channel = selchannel->channel;
383 break; /* found channel */
384 selchannel = selchannel->next;
387 add_trace("conclusion", NULL, "no channel available");
389 return(-6); // channel unacceptable
393 add_trace("conclusion", NULL, "channel available");
394 add_trace("connect", "channel", "%d", channel);
400 * handles all indications
402 /* CC_SETUP INDICATION */
403 void Pdss1::setup_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
405 int calling_type, calling_plan, calling_present, calling_screen;
406 int calling_type2, calling_plan2, calling_present2, calling_screen2;
407 int called_type, called_plan;
408 int redir_type, redir_plan, redir_present, redir_screen, redir_reason;
409 int hlc_coding, hlc_presentation, hlc_interpretation, hlc_hlc, hlc_exthlc;
410 int bearer_coding, bearer_capability, bearer_mode, bearer_rate, bearer_multi, bearer_user;
411 int exclusive, channel;
413 unsigned char keypad[33] = "";
414 unsigned char useruser[128];
415 int useruser_len = 0, useruser_protocol;
416 class Endpoint *epoint;
417 struct lcr_msg *message;
419 /* process given callref */
420 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_IND, DIRECTION_IN);
421 add_trace("callref", "new", "0x%x", pid);
423 /* release in case the ID is already in use */
424 add_trace("error", NULL, "callref already in use");
426 l3m = create_l3msg();
427 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
428 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47);
429 add_trace("reason", NULL, "callref already in use");
431 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, pid, l3m);
432 new_state(PORT_STATE_RELEASE);
433 trigger_work(&p_m_d_delete);
437 p_m_d_ces = pid >> 16;
440 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_IND, DIRECTION_IN);
441 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));
442 dec_ie_called_pn(l3m, &called_type, &called_plan, (unsigned char *)p_dialinginfo.id, sizeof(p_dialinginfo.id));
443 dec_ie_keypad(l3m, (unsigned char *)keypad, sizeof(keypad));
444 /* te-mode: CNIP (calling name identification presentation) */
445 dec_facility_centrex(l3m, (unsigned char *)p_callerinfo.name, sizeof(p_callerinfo.name));
446 dec_ie_useruser(l3m, &useruser_protocol, useruser, &useruser_len);
447 dec_ie_complete(l3m, &p_dialinginfo.sending_complete);
448 dec_ie_redir_nr(l3m, &redir_type, &redir_plan, &redir_present, &redir_screen, &redir_reason, (unsigned char *)p_redirinfo.id, sizeof(p_redirinfo.id));
449 dec_ie_channel_id(l3m, &exclusive, &channel);
450 dec_ie_hlc(l3m, &hlc_coding, &hlc_interpretation, &hlc_presentation, &hlc_hlc, &hlc_exthlc);
451 dec_ie_bearer(l3m, &bearer_coding, &bearer_capability, &bearer_mode, &bearer_rate, &bearer_multi, &bearer_user);
452 dec_ie_display(l3m, (unsigned char *)p_dialinginfo.display, sizeof(p_dialinginfo.display));
455 /* if blocked, release call with MT_RELEASE_COMPLETE */
456 if (p_m_mISDNport->ifport->block) {
457 l3m = create_l3msg();
458 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
459 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 27); /* temporary unavailable */
460 add_trace("reason", NULL, "port blocked");
462 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
463 new_state(PORT_STATE_RELEASE);
464 trigger_work(&p_m_d_delete);
469 switch (calling_present) {
471 p_callerinfo.present = INFO_PRESENT_RESTRICTED;
474 p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
477 p_callerinfo.present = INFO_PRESENT_ALLOWED;
480 switch (calling_screen) {
482 p_callerinfo.screen = INFO_SCREEN_USER;
485 p_callerinfo.screen = INFO_SCREEN_USER_VERIFIED_PASSED;
488 p_callerinfo.screen = INFO_SCREEN_USER_VERIFIED_FAILED;
491 p_callerinfo.screen = INFO_SCREEN_NETWORK;
494 switch (calling_type) {
496 p_callerinfo.ntype = INFO_NTYPE_NOTPRESENT;
499 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
502 p_callerinfo.ntype = INFO_NTYPE_INTERNATIONAL;
505 p_callerinfo.ntype = INFO_NTYPE_NATIONAL;
508 p_callerinfo.ntype = INFO_NTYPE_SUBSCRIBER;
511 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
514 p_callerinfo.isdn_port = p_m_portnum;
515 SCPY(p_callerinfo.interface, p_m_mISDNport->ifport->interface->name);
518 switch (calling_present2) {
520 p_callerinfo.present2 = INFO_PRESENT_RESTRICTED;
523 p_callerinfo.present2 = INFO_PRESENT_NOTAVAIL;
526 p_callerinfo.present2 = INFO_PRESENT_ALLOWED;
529 switch (calling_screen2) {
531 p_callerinfo.screen2 = INFO_SCREEN_USER;
534 p_callerinfo.screen2 = INFO_SCREEN_USER_VERIFIED_PASSED;
537 p_callerinfo.screen2 = INFO_SCREEN_USER_VERIFIED_FAILED;
540 p_callerinfo.screen2 = INFO_SCREEN_NETWORK;
543 switch (calling_type2) {
545 p_callerinfo.ntype2 = INFO_NTYPE_NOTPRESENT;
548 p_callerinfo.ntype2 = INFO_NTYPE_UNKNOWN;
551 p_callerinfo.ntype2 = INFO_NTYPE_INTERNATIONAL;
554 p_callerinfo.ntype2 = INFO_NTYPE_NATIONAL;
557 p_callerinfo.ntype2 = INFO_NTYPE_SUBSCRIBER;
560 p_callerinfo.ntype2 = INFO_NTYPE_UNKNOWN;
564 /* dialing information */
565 SCAT(p_dialinginfo.id, (char *)keypad);
566 switch (called_type) {
568 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
571 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
574 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
577 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
582 switch (redir_present) {
584 p_redirinfo.present = INFO_PRESENT_RESTRICTED;
587 p_redirinfo.present = INFO_PRESENT_NOTAVAIL;
590 p_redirinfo.present = INFO_PRESENT_ALLOWED;
593 switch (redir_screen) {
595 p_redirinfo.screen = INFO_SCREEN_USER;
598 p_redirinfo.screen = INFO_SCREEN_USER_VERIFIED_PASSED;
601 p_redirinfo.screen = INFO_SCREEN_USER_VERIFIED_FAILED;
604 p_redirinfo.screen = INFO_SCREEN_NETWORK;
607 switch (redir_reason) {
609 p_redirinfo.reason = INFO_REDIR_BUSY;
612 p_redirinfo.reason = INFO_REDIR_NORESPONSE;
615 p_redirinfo.reason = INFO_REDIR_UNCONDITIONAL;
618 p_redirinfo.reason = INFO_REDIR_CALLDEFLECT;
621 p_redirinfo.reason = INFO_REDIR_OUTOFORDER;
624 p_redirinfo.reason = INFO_REDIR_UNKNOWN;
627 switch (redir_type) {
629 p_redirinfo.ntype = INFO_NTYPE_NOTPRESENT;
632 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
635 p_redirinfo.ntype = INFO_NTYPE_INTERNATIONAL;
638 p_redirinfo.ntype = INFO_NTYPE_NATIONAL;
641 p_redirinfo.ntype = INFO_NTYPE_SUBSCRIBER;
644 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
647 p_redirinfo.isdn_port = p_m_portnum;
649 /* bearer capability */
650 switch (bearer_capability) {
652 p_capainfo.bearer_capa = INFO_BC_AUDIO;
653 bearer_user = (options.law=='a')?3:2;
656 p_capainfo.bearer_capa = bearer_capability;
659 switch (bearer_mode) {
661 p_capainfo.bearer_mode = INFO_BMODE_PACKET;
664 p_capainfo.bearer_mode = INFO_BMODE_CIRCUIT;
667 switch (bearer_user) {
669 p_capainfo.bearer_info1 = INFO_INFO1_NONE;
672 p_capainfo.bearer_info1 = bearer_user + 0x80;
679 p_capainfo.hlc = INFO_HLC_NONE;
682 p_capainfo.hlc = hlc_hlc + 0x80;
685 switch (hlc_exthlc) {
687 p_capainfo.exthlc = INFO_HLC_NONE;
690 p_capainfo.exthlc = hlc_exthlc + 0x80;
694 /* set bchannel mode */
695 if (p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED
696 || p_capainfo.bearer_capa==INFO_BC_DATARESTRICTED
697 || p_capainfo.bearer_capa==INFO_BC_VIDEO)
698 p_capainfo.source_mode = B_MODE_HDLC;
700 p_capainfo.source_mode = B_MODE_TRANSPARENT;
701 p_m_b_mode = p_capainfo.source_mode;
704 ret = channel = hunt_bchannel(channel, exclusive);
709 ret = seize_bchannel(channel, 1);
713 * NOTE: we send MT_RELEASE_COMPLETE to "REJECT" the channel
714 * in response to the setup
716 l3m = create_l3msg();
717 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
718 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
720 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
721 new_state(PORT_STATE_RELEASE);
722 trigger_work(&p_m_d_delete);
725 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
727 /* create endpoint */
729 FATAL("Incoming call but already got an endpoint.\n");
730 if (!(epoint = new Endpoint(p_serial, 0)))
731 FATAL("No memory for Endpoint instance\n");
732 epoint->ep_app = new_endpointapp(epoint, 0, p_m_mISDNport->ifport->interface->app); //incoming
733 epointlist_new(epoint->ep_serial);
735 /* send setup message to endpoit */
736 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_SETUP);
737 message->param.setup.isdn_port = p_m_portnum;
738 message->param.setup.port_type = p_type;
739 // message->param.setup.dtmf = !p_m_mISDNport->ifport->nodtmf;
740 memcpy(&message->param.setup.dialinginfo, &p_dialinginfo, sizeof(struct dialing_info));
741 memcpy(&message->param.setup.callerinfo, &p_callerinfo, sizeof(struct caller_info));
742 memcpy(&message->param.setup.redirinfo, &p_redirinfo, sizeof(struct redir_info));
743 memcpy(&message->param.setup.capainfo, &p_capainfo, sizeof(struct capa_info));
744 memcpy(message->param.setup.useruser.data, &useruser, useruser_len);
745 message->param.setup.useruser.len = useruser_len;
746 message->param.setup.useruser.protocol = useruser_protocol;
747 message_put(message);
749 new_state(PORT_STATE_IN_SETUP);
752 /* CC_INFORMATION INDICATION */
753 void Pdss1::information_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
756 unsigned char keypad[33] = "", display[128] = "";
757 struct lcr_msg *message;
759 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_IND, DIRECTION_IN);
760 dec_ie_called_pn(l3m, &type, &plan, (unsigned char *)p_dialinginfo.id, sizeof(p_dialinginfo.id));
761 dec_ie_keypad(l3m, (unsigned char *)keypad, sizeof(keypad));
762 dec_ie_display(l3m, (unsigned char *)display, sizeof(display));
763 dec_ie_complete(l3m, &p_dialinginfo.sending_complete);
766 SCAT(p_dialinginfo.id, (char *)keypad);
769 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
772 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
775 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
778 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
781 SCPY(p_dialinginfo.display, (char *)display);
782 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_INFORMATION);
783 memcpy(&message->param.information, &p_dialinginfo, sizeof(struct dialing_info));
784 message_put(message);
785 /* reset overlap timeout */
789 /* CC_SETUP_ACCNOWLEDGE INDICATION */
790 void Pdss1::setup_acknowledge_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
792 int exclusive, channel;
793 int coding, location, progress;
795 struct lcr_msg *message;
796 int max = p_m_mISDNport->ifport->dialmax;
800 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_ACKNOWLEDGE_IND, DIRECTION_IN);
801 dec_ie_channel_id(l3m, &exclusive, &channel);
802 dec_ie_progress(l3m, &coding, &location, &progress);
806 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROGRESS);
807 message->param.progressinfo.progress = progress;
808 message->param.progressinfo.location = location;
809 message_put(message);
812 /* process channel */
813 ret = received_first_reply_to_setup(cmd, channel, exclusive);
815 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
816 message->param.disconnectinfo.cause = -ret;
817 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
818 message_put(message);
819 new_state(PORT_STATE_RELEASE);
820 trigger_work(&p_m_d_delete);
824 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_OVERLAP);
825 message_put(message);
827 new_state(PORT_STATE_OUT_OVERLAP);
829 number = p_m_d_queue;
830 while (number[0]) { /* as long we have something to dial */
831 if (max > (int)strlen(number) || max == 0)
832 max = (int)strlen(number);
834 nl3m = create_l3msg();
835 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
836 enc_ie_called_pn(nl3m, 0, 1, (unsigned char *)number, max);
838 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, nl3m);
841 p_m_d_queue[0] = '\0';
844 /* CC_PROCEEDING INDICATION */
845 void Pdss1::proceeding_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
847 int exclusive, channel;
848 int coding, location, progress;
850 struct lcr_msg *message;
851 int notify = -1, type, plan, present;
854 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_IND, DIRECTION_IN);
855 dec_ie_channel_id(l3m, &exclusive, &channel);
856 dec_ie_progress(l3m, &coding, &location, &progress);
857 dec_ie_notify(l3m, ¬ify);
858 dec_ie_redir_dn(l3m, &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
862 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROGRESS);
863 message->param.progressinfo.progress = progress;
864 message->param.progressinfo.location = location;
865 message_put(message);
868 ret = received_first_reply_to_setup(cmd, channel, exclusive);
870 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
871 message->param.disconnectinfo.cause = -ret;
872 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
873 message_put(message);
874 new_state(PORT_STATE_RELEASE);
875 trigger_work(&p_m_d_delete);
878 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROCEEDING);
879 message_put(message);
881 new_state(PORT_STATE_OUT_PROCEEDING);
887 if (type >= 0 || notify) {
888 if (!notify && type >= 0)
890 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
891 message->param.notifyinfo.notify = notify;
892 SCPY(message->param.notifyinfo.id, redir);
893 /* redirection number */
896 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
899 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
902 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
907 message->param.notifyinfo.ntype = INFO_NTYPE_NOTPRESENT;
910 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
913 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
916 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
919 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
922 message->param.notifyinfo.isdn_port = p_m_portnum;
923 message_put(message);
927 /* CC_ALERTING INDICATION */
928 void Pdss1::alerting_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
930 int exclusive, channel;
931 int coding, location, progress;
933 struct lcr_msg *message;
934 int notify = -1, type, plan, present;
937 l1l2l3_trace_header(p_m_mISDNport, this, L3_ALERTING_IND, DIRECTION_IN);
938 dec_ie_channel_id(l3m, &exclusive, &channel);
939 dec_ie_progress(l3m, &coding, &location, &progress);
940 dec_ie_notify(l3m, ¬ify);
941 dec_ie_redir_dn(l3m, &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
945 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROGRESS);
946 message->param.progressinfo.progress = progress;
947 message->param.progressinfo.location = location;
948 message_put(message);
951 /* process channel */
952 ret = received_first_reply_to_setup(cmd, channel, exclusive);
954 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
955 message->param.disconnectinfo.cause = -ret;
956 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
957 message_put(message);
958 new_state(PORT_STATE_RELEASE);
959 trigger_work(&p_m_d_delete);
962 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_ALERTING);
963 message_put(message);
965 new_state(PORT_STATE_OUT_ALERTING);
971 if (type >= 0 || notify) {
972 if (!notify && type >= 0)
974 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
975 message->param.notifyinfo.notify = notify;
976 SCPY(message->param.notifyinfo.id, redir);
979 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
982 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
985 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
990 message->param.notifyinfo.ntype = INFO_NTYPE_NOTPRESENT;
993 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
996 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
999 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1002 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1005 message->param.notifyinfo.isdn_port = p_m_portnum;
1006 message_put(message);
1010 /* CC_CONNECT INDICATION */
1011 void Pdss1::connect_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1013 int exclusive, channel;
1014 int type, plan, present, screen;
1016 struct lcr_msg *message;
1017 int bchannel_before;
1019 l1l2l3_trace_header(p_m_mISDNport, this, L3_CONNECT_IND, DIRECTION_IN);
1020 dec_ie_channel_id(l3m, &exclusive, &channel);
1021 dec_ie_connected_pn(l3m, &type, &plan, &present, &screen, (unsigned char *)p_connectinfo.id, sizeof(p_connectinfo.id));
1022 dec_ie_display(l3m, (unsigned char *)p_connectinfo.display, sizeof(p_connectinfo.display));
1023 /* te-mode: CONP (connected name identification presentation) */
1024 dec_facility_centrex(l3m, (unsigned char *)p_connectinfo.name, sizeof(p_connectinfo.name));
1027 /* select channel */
1028 bchannel_before = p_m_b_channel;
1029 ret = received_first_reply_to_setup(cmd, channel, exclusive);
1031 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1032 message->param.disconnectinfo.cause = -ret;
1033 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1034 message_put(message);
1035 new_state(PORT_STATE_RELEASE);
1036 trigger_work(&p_m_d_delete);
1040 /* connect information */
1043 p_connectinfo.present = INFO_PRESENT_RESTRICTED;
1046 p_connectinfo.present = INFO_PRESENT_NOTAVAIL;
1049 p_connectinfo.present = INFO_PRESENT_ALLOWED;
1054 p_connectinfo.screen = INFO_SCREEN_USER;
1057 p_connectinfo.screen = INFO_SCREEN_USER_VERIFIED_PASSED;
1060 p_connectinfo.screen = INFO_SCREEN_USER_VERIFIED_FAILED;
1063 p_connectinfo.screen = INFO_SCREEN_NETWORK;
1068 p_connectinfo.ntype = INFO_NTYPE_NOTPRESENT;
1071 p_connectinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1074 p_connectinfo.ntype = INFO_NTYPE_NATIONAL;
1077 p_connectinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1080 p_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1083 p_connectinfo.isdn_port = p_m_portnum;
1084 SCPY(p_connectinfo.interface, p_m_mISDNport->ifport->interface->name);
1086 /* only in nt-mode we send connect ack. in te-mode it is done by stack itself or optional */
1088 /* send connect acknowledge */
1089 l3m = create_l3msg();
1090 l1l2l3_trace_header(p_m_mISDNport, this, L3_CONNECT_RES, DIRECTION_OUT);
1091 /* if we had no bchannel before, we send it now */
1092 if (!bchannel_before && p_m_b_channel)
1093 enc_ie_channel_id(l3m, 1, p_m_b_channel);
1095 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CONNECT_ACKNOWLEDGE, p_m_d_l3id, l3m);
1098 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CONNECT);
1099 memcpy(&message->param.connectinfo, &p_connectinfo, sizeof(struct connect_info));
1100 message_put(message);
1102 new_state(PORT_STATE_CONNECT);
1105 /* CC_DISCONNECT INDICATION */
1106 void Pdss1::disconnect_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1108 int location, cause;
1109 int coding, proglocation, progress;
1110 struct lcr_msg *message;
1111 unsigned char display[128] = "";
1113 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_IND, DIRECTION_IN);
1114 dec_ie_progress(l3m, &coding, &proglocation, &progress);
1115 dec_ie_cause(l3m, &location, &cause);
1116 dec_ie_display(l3m, (unsigned char *)display, sizeof(display));
1121 location = LOCATION_PRIVATE_LOCAL;
1124 if (progress >= 0) {
1125 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROGRESS);
1126 message->param.progressinfo.progress = progress;
1127 message->param.progressinfo.location = proglocation;
1128 message_put(message);
1131 /* release if remote sends us no tones */
1132 if (!p_m_mISDNport->earlyb) {
1135 l3m = create_l3msg();
1136 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_REQ, DIRECTION_OUT);
1137 enc_ie_cause(l3m, location, cause); /* normal */
1138 add_trace("reason", NULL, "no remote patterns");
1140 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE, p_m_d_l3id, l3m);
1142 /* sending release to endpoint */
1143 if (location == LOCATION_PRIVATE_LOCAL)
1144 location = LOCATION_PRIVATE_REMOTE;
1145 while(p_epointlist) {
1146 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1147 message->param.disconnectinfo.cause = cause;
1148 message->param.disconnectinfo.location = location;
1149 SCAT(message->param.disconnectinfo.display, (char *)display);
1150 message_put(message);
1152 free_epointlist(p_epointlist);
1154 new_state(PORT_STATE_RELEASE);
1155 trigger_work(&p_m_d_delete);
1159 /* sending disconnect to active endpoint and release to inactive endpoints */
1160 if (location == LOCATION_PRIVATE_LOCAL)
1161 location = LOCATION_PRIVATE_REMOTE;
1162 if (ACTIVE_EPOINT(p_epointlist)) {
1163 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DISCONNECT);
1164 message->param.disconnectinfo.location = location;
1165 message->param.disconnectinfo.cause = cause;
1166 SCAT(message->param.disconnectinfo.display, (char *)display);
1167 message_put(message);
1169 while(INACTIVE_EPOINT(p_epointlist)) {
1170 message = message_create(p_serial, INACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1171 message->param.disconnectinfo.location = location;
1172 message->param.disconnectinfo.cause = cause;
1173 SCAT(message->param.disconnectinfo.display, (char *)display);
1174 message_put(message);
1176 free_epointid(INACTIVE_EPOINT(p_epointlist));
1178 new_state(PORT_STATE_IN_DISCONNECT);
1181 /* CC_DISCONNECT INDICATION */
1182 void Pdss1::disconnect_ind_i(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1184 int location, cause;
1187 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_IND, DIRECTION_IN);
1188 if (p_m_d_collect_cause > 0) {
1189 add_trace("old-cause", "location", "%d", p_m_d_collect_location);
1190 add_trace("old-cause", "value", "%d", p_m_d_collect_cause);
1192 dec_ie_cause(l3m, &location, &cause);
1193 if (location == LOCATION_PRIVATE_LOCAL)
1194 location = LOCATION_PRIVATE_REMOTE;
1197 collect_cause(&p_m_d_collect_cause, &p_m_d_collect_location, cause, location);
1198 add_trace("new-cause", "location", "%d", p_m_d_collect_location);
1199 add_trace("new-cause", "value", "%d", p_m_d_collect_cause);
1204 /* CC_RELEASE INDICATION */
1205 void Pdss1::release_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1207 int location, cause;
1208 struct lcr_msg *message;
1209 unsigned char display[128] = "";
1211 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_IND, DIRECTION_IN);
1212 dec_ie_cause(l3m, &location, &cause);
1213 dec_ie_display(l3m, (unsigned char *)display, sizeof(display));
1218 location = LOCATION_PRIVATE_LOCAL;
1221 /* sending release to endpoint */
1222 if (location == LOCATION_PRIVATE_LOCAL)
1223 location = LOCATION_PRIVATE_REMOTE;
1224 while(p_epointlist) {
1225 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1226 message->param.disconnectinfo.cause = cause;
1227 message->param.disconnectinfo.location = location;
1228 SCAT(message->param.disconnectinfo.display, (char *)display);
1229 message_put(message);
1231 free_epointlist(p_epointlist);
1234 new_state(PORT_STATE_RELEASE);
1235 trigger_work(&p_m_d_delete);
1238 /* CC_RESTART INDICATION */
1239 void Pdss1::restart_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1241 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESTART_IND, DIRECTION_IN);
1244 // L3 process is not toucht. (not even by network stack)
1247 /* CC_RELEASE_COMPLETE INDICATION (a reject) */
1248 void Pdss1::release_complete_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1250 int location, cause;
1251 struct lcr_msg *message;
1253 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_IND, DIRECTION_IN);
1254 /* in case layer 2 is down during setup, we send cause 27 loc 5 */
1255 if (p_state == PORT_STATE_OUT_SETUP && p_m_mISDNport->l1link == 0) {
1259 dec_ie_cause(l3m, &location, &cause);
1260 if (p_m_mISDNport->l1link < 0)
1261 add_trace("layer 1", NULL, "unknown");
1263 add_trace("layer 1", NULL, (p_m_mISDNport->l1link)?"up":"down");
1266 if (location == LOCATION_PRIVATE_LOCAL)
1267 location = LOCATION_PRIVATE_REMOTE;
1271 location = LOCATION_PRIVATE_LOCAL;
1274 /* sending release to endpoint */
1275 while(p_epointlist) {
1276 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1277 message->param.disconnectinfo.cause = cause;
1278 message->param.disconnectinfo.location = location;
1279 message_put(message);
1281 free_epointlist(p_epointlist);
1284 new_state(PORT_STATE_RELEASE);
1285 trigger_work(&p_m_d_delete);
1289 void Pdss1::t312_timeout_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1291 // not required, release is performed with MT_FREE
1294 /* CC_NOTIFY INDICATION */
1295 void Pdss1::notify_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1297 struct lcr_msg *message;
1298 int notify, type, plan, present;
1299 unsigned char notifyid[sizeof(message->param.notifyinfo.id)];
1300 unsigned char display[128] = "";
1302 l1l2l3_trace_header(p_m_mISDNport, this, L3_NOTIFY_IND, DIRECTION_IN);
1303 dec_ie_notify(l3m, ¬ify);
1304 dec_ie_redir_dn(l3m, &type, &plan, &present, notifyid, sizeof(notifyid));
1305 dec_ie_display(l3m, (unsigned char *)display, sizeof(display));
1308 if (!ACTIVE_EPOINT(p_epointlist))
1310 /* notification indicator */
1314 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1315 message->param.notifyinfo.notify = notify;
1316 SCPY(message->param.notifyinfo.id, (char *)notifyid);
1317 /* redirection number */
1320 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1323 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1326 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1331 message->param.notifyinfo.ntype = INFO_NTYPE_NOTPRESENT;
1334 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1337 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1340 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1343 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1346 SCAT(message->param.notifyinfo.display, (char *)display);
1347 message->param.notifyinfo.isdn_port = p_m_portnum;
1348 message_put(message);
1352 /* CC_HOLD INDICATION */
1353 struct lcr_msg *message;
1354 void Pdss1::hold_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1356 // class Endpoint *epoint;
1358 l1l2l3_trace_header(p_m_mISDNport, this, L3_HOLD_IND, DIRECTION_IN);
1361 if (!ACTIVE_EPOINT(p_epointlist) || p_m_hold) {
1362 l3m = create_l3msg();
1363 l1l2l3_trace_header(p_m_mISDNport, this, L3_HOLD_REJECT_REQ, DIRECTION_OUT);
1364 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, p_m_hold?101:31); /* normal unspecified / incompatible state */
1365 add_trace("reason", NULL, "no endpoint");
1367 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_HOLD_REJECT, p_m_d_l3id, l3m);
1372 /* notify the hold of call */
1373 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1374 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_HOLD;
1375 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1376 message_put(message);
1378 /* deactivate bchannel */
1379 chan_trace_header(p_m_mISDNport, this, "CHANNEL RELEASE (hold)", DIRECTION_NONE);
1380 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1384 /* set hold state */
1387 epoint = find_epoint_id(ACTIVE_EPOINT(p_epointlist));
1388 if (epoint && p_m_d_ntmode) {
1389 if (p_settings.tout_hold)
1390 schedule_timer(&p_m_timeout, p_settings.tout_hold, 0);
1394 /* acknowledge hold */
1395 l3m = create_l3msg();
1396 l1l2l3_trace_header(p_m_mISDNport, this, L3_HOLD_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1398 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_HOLD_ACKNOWLEDGE, p_m_d_l3id, l3m);
1402 /* CC_RETRIEVE INDICATION */
1403 void Pdss1::retrieve_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1405 struct lcr_msg *message;
1406 int channel, exclusive, cause;
1409 l1l2l3_trace_header(p_m_mISDNport, this, L3_RETRIEVE_IND, DIRECTION_IN);
1410 dec_ie_channel_id(l3m, &exclusive, &channel);
1414 cause = 101; /* incompatible state */
1417 l3m = create_l3msg();
1418 l1l2l3_trace_header(p_m_mISDNport, this, L3_RETRIEVE_REJECT_REQ, DIRECTION_OUT);
1419 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, cause);
1421 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RETRIEVE_REJECT, p_m_d_l3id, l3m);
1426 /* notify the retrieve of call */
1427 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1428 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_RETRIEVAL;
1429 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1430 message_put(message);
1433 ret = channel = hunt_bchannel(channel, exclusive);
1438 ret = seize_bchannel(channel, 1);
1444 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
1446 /* set hold state */
1448 unsched_timer(&p_m_timeout);
1450 /* acknowledge retrieve */
1451 l3m = create_l3msg();
1452 l1l2l3_trace_header(p_m_mISDNport, this, L3_RETRIEVE_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1453 enc_ie_channel_id(l3m, 1, p_m_b_channel);
1455 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RETRIEVE_ACKNOWLEDGE, p_m_d_l3id, l3m);
1458 /* CC_SUSPEND INDICATION */
1459 void Pdss1::suspend_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1461 struct lcr_msg *message;
1462 class Endpoint *epoint;
1463 unsigned char callid[8];
1465 int ret = -31; /* normal, unspecified */
1467 l1l2l3_trace_header(p_m_mISDNport, this, L3_SUSPEND_IND, DIRECTION_IN);
1468 dec_ie_call_id(l3m, callid, &len);
1471 if (!ACTIVE_EPOINT(p_epointlist)) {
1473 l3m = create_l3msg();
1474 l1l2l3_trace_header(p_m_mISDNport, this, L3_SUSPEND_REJECT_REQ, DIRECTION_OUT);
1475 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1477 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SUSPEND_REJECT, p_m_d_l3id, l3m);
1484 /* check if call id is in use */
1485 epoint = epoint_first;
1487 if (epoint->ep_park) {
1488 if (epoint->ep_park_len == len)
1489 if (!memcmp(epoint->ep_park_callid, callid, len)) {
1490 ret = -84; /* call id in use */
1494 epoint = epoint->next;
1497 /* notify the hold of call */
1498 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1499 message->param.notifyinfo.notify = INFO_NOTIFY_USER_SUSPENDED;
1500 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1501 message_put(message);
1503 /* deactivate bchannel */
1504 chan_trace_header(p_m_mISDNport, this, "CHANNEL RELEASE (suspend)", DIRECTION_NONE);
1505 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1509 /* sending suspend to endpoint */
1510 while (p_epointlist) {
1511 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_SUSPEND);
1512 memcpy(message->param.parkinfo.callid, callid, sizeof(message->param.parkinfo.callid));
1513 message->param.parkinfo.len = len;
1514 message_put(message);
1516 free_epointlist(p_epointlist);
1519 /* sending SUSPEND_ACKNOWLEDGE */
1520 l3m = create_l3msg();
1521 l1l2l3_trace_header(p_m_mISDNport, this, L3_SUSPEND_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1523 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SUSPEND_ACKNOWLEDGE, p_m_d_l3id, l3m);
1525 new_state(PORT_STATE_RELEASE);
1526 trigger_work(&p_m_d_delete);
1529 /* CC_RESUME INDICATION */
1530 void Pdss1::resume_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1532 unsigned char callid[8];
1534 int channel, exclusive;
1535 class Endpoint *epoint;
1536 struct lcr_msg *message;
1539 /* process given callref */
1540 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_IND, DIRECTION_IN);
1541 add_trace("callref", "new", "0x%x", pid);
1543 /* release is case the ID is already in use */
1544 add_trace("error", NULL, "callref already in use");
1546 l3m = create_l3msg();
1547 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_REJECT_REQ, DIRECTION_OUT);
1548 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47);
1549 add_trace("reason", NULL, "callref already in use");
1551 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RESUME_REJECT, pid, l3m);
1552 new_state(PORT_STATE_RELEASE);
1553 trigger_work(&p_m_d_delete);
1557 p_m_d_ces = pid >> 16;
1560 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_IND, DIRECTION_IN);
1561 dec_ie_call_id(l3m, callid, &len);
1564 /* if blocked, release call */
1565 if (p_m_mISDNport->ifport->block) {
1573 /* channel_id (no channel is possible in message) */
1575 channel = -1; /* any channel */
1578 ret = channel = hunt_bchannel(channel, exclusive);
1582 // mode (if hdlc parked) to be done. never mind, this is almost never requested
1584 ret = seize_bchannel(channel, 1);
1588 l3m = create_l3msg();
1589 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_REJECT_REQ, DIRECTION_OUT);
1590 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1592 add_trace("reason", NULL, "port blocked");
1594 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RESUME_REJECT, p_m_d_l3id, l3m);
1595 new_state(PORT_STATE_RELEASE);
1596 trigger_work(&p_m_d_delete);
1599 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
1601 /* create endpoint */
1603 FATAL("Incoming resume but already got an endpoint.\n");
1604 ret = -85; /* no call suspended */
1605 epoint = epoint_first;
1607 if (epoint->ep_park) {
1608 ret = -83; /* suspended call exists, but this not */
1609 if (epoint->ep_park_len == len)
1610 if (!memcmp(epoint->ep_park_callid, callid, len))
1613 epoint = epoint->next;
1618 epointlist_new(epoint->ep_serial);
1619 if (!(epoint->portlist_new(p_serial, p_type, p_m_mISDNport->earlyb)))
1620 FATAL("No memory for portlist\n");
1621 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RESUME);
1622 message_put(message);
1624 /* notify the resume of call */
1625 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1626 message->param.notifyinfo.notify = INFO_NOTIFY_USER_RESUMED;
1627 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1628 message_put(message);
1630 /* sending RESUME_ACKNOWLEDGE */
1631 l3m = create_l3msg();
1632 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1633 enc_ie_channel_id(l3m, 1, p_m_b_channel);
1635 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RESUME_ACKNOWLEDGE, p_m_d_l3id, l3m);
1637 new_state(PORT_STATE_CONNECT);
1641 /* CC_FACILITY INDICATION */
1642 void Pdss1::facility_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1644 unsigned char facil[256];
1646 struct lcr_msg *message;
1648 l1l2l3_trace_header(p_m_mISDNport, this, L3_FACILITY_IND, DIRECTION_IN);
1649 dec_ie_facility(l3m, facil, &facil_len);
1656 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_FACILITY);
1657 message->param.facilityinfo.len = facil_len;
1658 memcpy(message->param.facilityinfo.data, facil, facil_len);
1659 message_put(message);
1663 /* CC_PROGRESS INDICATION */
1664 void Pdss1::progress_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1666 int coding, location, progress;
1668 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROGRESS_IND, DIRECTION_IN);
1669 dec_ie_progress(l3m, &coding, &location, &progress);
1672 if (progress >= 0) {
1673 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROGRESS);
1674 message->param.progressinfo.progress = progress;
1675 message->param.progressinfo.location = location;
1676 message_put(message);
1682 * handler for isdn connections
1683 * incoming information are parsed and sent via message to the endpoint
1685 void Pdss1::message_isdn(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1692 PERROR("Pdss1(%s) timeout without cause.\n", p_name);
1695 if (l3m->cause[0] != 5) {
1696 PERROR("Pdss1(%s) expecting timeout with timer diagnostic. (got len=%d)\n", p_name, l3m->cause[0]);
1699 timer = (l3m->cause[3]-'0')*100;
1700 timer += (l3m->cause[4]-'0')*10;
1701 timer += (l3m->cause[5]-'0');
1702 l1l2l3_trace_header(p_m_mISDNport, this, L3_TIMEOUT_IND, DIRECTION_IN);
1703 add_trace("timer", NULL, "%d", timer);
1706 t312_timeout_ind(cmd, pid, l3m);
1710 if (p_state != PORT_STATE_IDLE)
1712 setup_ind(cmd, pid, l3m);
1715 case MT_INFORMATION:
1716 information_ind(cmd, pid, l3m);
1719 case MT_SETUP_ACKNOWLEDGE:
1720 if (p_state != PORT_STATE_OUT_SETUP) {
1721 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received setup_acknowledge, but we are not in outgoing setup state, IGNORING.\n", p_name);
1724 setup_acknowledge_ind(cmd, pid, l3m);
1727 case MT_CALL_PROCEEDING:
1728 if (p_state != PORT_STATE_OUT_SETUP
1729 && p_state != PORT_STATE_OUT_OVERLAP) {
1730 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received proceeding, but we are not in outgoing setup OR overlap state, IGNORING.\n", p_name);
1733 proceeding_ind(cmd, pid, l3m);
1737 if (p_state != PORT_STATE_OUT_SETUP
1738 && p_state != PORT_STATE_OUT_OVERLAP
1739 && p_state != PORT_STATE_OUT_PROCEEDING) {
1740 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding state, IGNORING.\n", p_name);
1743 alerting_ind(cmd, pid, l3m);
1747 if (p_state != PORT_STATE_OUT_SETUP
1748 && p_state != PORT_STATE_OUT_OVERLAP
1749 && p_state != PORT_STATE_OUT_PROCEEDING
1750 && p_state != PORT_STATE_OUT_ALERTING) {
1751 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);
1754 connect_ind(cmd, pid, l3m);
1755 if (p_m_d_notify_pending) {
1756 /* send pending notify message during connect */
1757 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
1758 message_free(p_m_d_notify_pending);
1759 p_m_d_notify_pending = NULL;
1763 case MT_CONNECT_ACKNOWLEDGE:
1764 if (p_state == PORT_STATE_CONNECT_WAITING)
1765 new_state(PORT_STATE_CONNECT);
1766 if (p_m_d_notify_pending) {
1767 /* send pending notify message during connect-ack */
1768 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
1769 message_free(p_m_d_notify_pending);
1770 p_m_d_notify_pending = NULL;
1775 disconnect_ind(cmd, pid, l3m);
1779 release_ind(cmd, pid, l3m);
1782 case MT_RELEASE_COMPLETE:
1783 release_complete_ind(cmd, pid, l3m);
1787 restart_ind(cmd, pid, l3m);
1791 notify_ind(cmd, pid, l3m);
1795 hold_ind(cmd, pid, l3m);
1799 retrieve_ind(cmd, pid, l3m);
1803 suspend_ind(cmd, pid, l3m);
1807 resume_ind(cmd, pid, l3m);
1811 facility_ind(cmd, pid, l3m);
1815 progress_ind(cmd, pid, l3m);
1819 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_L3ID_IND, DIRECTION_IN);
1820 add_trace("callref", NULL, "0x%x", p_m_d_l3id);
1823 trigger_work(&p_m_d_delete);
1825 /* sending release to endpoint in case we still have an endpoint
1826 * this is because we don't get any response if a release_complete is received (or a release in release state)
1828 while(p_epointlist) { // only if not already released
1829 struct lcr_msg *message;
1830 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1831 if (p_m_d_collect_cause) {
1832 message->param.disconnectinfo.cause = p_m_d_collect_cause;
1833 message->param.disconnectinfo.location = p_m_d_collect_location;
1835 message->param.disconnectinfo.cause = CAUSE_NOUSER;
1836 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1838 message_put(message);
1840 free_epointlist(p_epointlist);
1842 new_state(PORT_STATE_RELEASE);
1847 l1l2l3_trace_header(p_m_mISDNport, this, L3_UNKNOWN_IND, DIRECTION_IN);
1848 add_trace("unhandled", "cmd", "0x%x", cmd);
1853 void Pdss1::new_state(int state)
1855 // class Endpoint *epoint;
1858 if (state == PORT_STATE_IN_OVERLAP) {
1859 if (p_m_mISDNport->ifport->tout_dialing)
1860 schedule_timer(&p_m_timeout, p_m_mISDNport->ifport->tout_dialing, 0);
1862 if (state != p_state) {
1863 unsched_timer(&p_m_timeout);
1864 if (state == PORT_STATE_IN_SETUP
1865 || state == PORT_STATE_OUT_SETUP
1866 || state == PORT_STATE_IN_OVERLAP
1867 || state == PORT_STATE_OUT_OVERLAP) {
1868 if (p_m_mISDNport->ifport->tout_setup)
1869 schedule_timer(&p_m_timeout, p_m_mISDNport->ifport->tout_setup, 0);
1871 if (state == PORT_STATE_IN_PROCEEDING
1872 || state == PORT_STATE_OUT_PROCEEDING) {
1873 if (p_m_mISDNport->ifport->tout_proceeding)
1874 schedule_timer(&p_m_timeout, p_m_mISDNport->ifport->tout_proceeding, 0);
1876 if (state == PORT_STATE_IN_ALERTING
1877 || state == PORT_STATE_OUT_ALERTING) {
1878 if (p_m_mISDNport->ifport->tout_alerting)
1879 schedule_timer(&p_m_timeout, p_m_mISDNport->ifport->tout_alerting, 0);
1882 if (state == PORT_STATE_CONNECT
1883 || state == PORT_STATE_CONNECT_WAITING) {
1884 if (p_m_mISDNport->ifport->tout_connect)
1885 schedule_timer(&p_m_timeout, p_m_mISDNport->ifport->tout_connect, 0);
1888 if (state == PORT_STATE_IN_DISCONNECT
1889 || state == PORT_STATE_OUT_DISCONNECT) {
1890 if (p_m_mISDNport->ifport->tout_disconnect)
1891 schedule_timer(&p_m_timeout, p_m_mISDNport->ifport->tout_disconnect, 0);
1895 Port::new_state(state);
1899 /* deletes only if l3id is release, otherwhise it will be triggered then */
1900 static int delete_event(struct lcr_work *work, void *instance, int index)
1902 class Pdss1 *isdnport = (class Pdss1 *)instance;
1904 if (!isdnport->p_m_d_l3id)
1912 * handles all messages from endpoint
1914 /* MESSAGE_INFORMATION */
1915 void Pdss1::message_information(unsigned int epoint_id, int message_id, union parameter *param)
1918 char *display = param->information.display;
1919 char *number = param->information.id;
1920 int max = p_m_mISDNport->ifport->dialmax;
1922 while (number[0]) { /* as long we have something to dial */
1923 if (max > (int)strlen(number) || max == 0)
1924 max = (int)strlen(number);
1926 l3m = create_l3msg();
1927 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
1928 enc_ie_called_pn(l3m, 0, 1, (unsigned char *)number, max);
1929 if ((p_m_d_ntmode || p_m_d_tespecial) && display[0]) {
1930 enc_ie_display(l3m, (unsigned char *)display);
1931 display = (char *)"";
1934 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
1942 void Pdss1::message_setup(unsigned int epoint_id, int message_id, union parameter *param)
1945 #ifdef OLD_MT_ASSIGN
1948 int plan, type, screen, present, reason;
1949 int plan2, type2, screen2, present2;
1950 int capability, mode, rate, coding, user, presentation, interpretation, hlc, exthlc;
1951 int channel, exclusive;
1952 struct epoint_list *epointlist;
1953 int max = p_m_mISDNport->ifport->dialmax;
1955 /* release if port is blocked */
1956 if (p_m_mISDNport->ifport->block) {
1957 struct lcr_msg *message;
1959 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1960 message->param.disconnectinfo.cause = 27; // temp. unavail.
1961 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1962 message_put(message);
1963 new_state(PORT_STATE_RELEASE);
1964 trigger_work(&p_m_d_delete);
1968 /* copy setup infos to port */
1969 memcpy(&p_callerinfo, ¶m->setup.callerinfo, sizeof(p_callerinfo));
1970 memcpy(&p_dialinginfo, ¶m->setup.dialinginfo, sizeof(p_dialinginfo));
1971 memcpy(&p_capainfo, ¶m->setup.capainfo, sizeof(p_capainfo));
1972 memcpy(&p_redirinfo, ¶m->setup.redirinfo, sizeof(p_redirinfo));
1973 /* screen outgoing caller id */
1974 do_screen(1, p_callerinfo.id, sizeof(p_callerinfo.id), &p_callerinfo.ntype, &p_callerinfo.present, p_m_mISDNport->ifport->interface->name);
1975 do_screen(1, p_callerinfo.id2, sizeof(p_callerinfo.id2), &p_callerinfo.ntype2, &p_callerinfo.present2, p_m_mISDNport->ifport->interface->name);
1976 do_screen(1, p_redirinfo.id, sizeof(p_redirinfo.id), &p_redirinfo.ntype, &p_redirinfo.present, p_m_mISDNport->ifport->interface->name);
1978 /* only display at connect state: this case happens if endpoint is in connected mode */
1979 if (p_state==PORT_STATE_CONNECT) {
1980 if (p_type!=PORT_TYPE_DSS1_NT_OUT
1981 && p_type!=PORT_TYPE_DSS1_NT_IN)
1983 if (p_callerinfo.display[0]) {
1984 /* sending information */
1985 l3m = create_l3msg();
1986 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
1987 if (p_m_d_ntmode || p_m_d_tespecial)
1988 enc_ie_display(l3m, (unsigned char *)p_callerinfo.display);
1990 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
1995 /* attach only if not already */
1996 epointlist = p_epointlist;
1998 if (epointlist->epoint_id == epoint_id)
2000 epointlist = epointlist->next;
2003 epointlist_new(epoint_id);
2007 if (p_m_b_channel) {
2008 channel = p_m_b_channel;
2009 exclusive = p_m_b_exclusive;
2011 channel = CHANNEL_ANY;
2012 /* nt-port with no channel, not reserverd */
2013 if (!p_m_b_channel && !p_m_b_reserve && p_type==PORT_TYPE_DSS1_NT_OUT)
2014 channel = CHANNEL_NO;
2017 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_REQ, DIRECTION_OUT);
2018 #ifdef OLD_MT_ASSIGN
2019 /* see MT_ASSIGN notes at do_layer3() */
2021 ret = p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_ASSIGN, 0, NULL);
2022 if (mt_assign_pid == 0 || ret < 0)
2023 p_m_d_l3id = mt_assign_pid;
2026 p_m_d_l3id = request_new_pid(p_m_mISDNport->ml3);
2027 if (p_m_d_l3id == MISDN_PID_NONE)
2030 struct lcr_msg *message;
2032 add_trace("callref", NULL, "no free id");
2034 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2035 message->param.disconnectinfo.cause = 47;
2036 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2037 message_put(message);
2038 new_state(PORT_STATE_RELEASE);
2039 trigger_work(&p_m_d_delete);
2042 #ifdef OLD_MT_ASSIGN
2043 p_m_d_l3id = mt_assign_pid;
2046 add_trace("callref", "new", "0x%x", p_m_d_l3id);
2049 /* preparing setup message */
2050 l3m = create_l3msg();
2051 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_REQ, DIRECTION_OUT);
2052 /* channel information */
2053 if (p_m_d_ntmode || channel != CHANNEL_ANY) /* only omit channel id in te-mode/any channel */
2054 enc_ie_channel_id(l3m, exclusive, channel);
2055 /* caller information */
2057 switch (p_callerinfo.ntype) {
2058 case INFO_NTYPE_UNKNOWN:
2061 case INFO_NTYPE_INTERNATIONAL:
2064 case INFO_NTYPE_NATIONAL:
2067 case INFO_NTYPE_SUBSCRIBER:
2070 default: /* INFO_NTYPE_NOTPRESENT */
2074 switch (p_callerinfo.screen) {
2075 case INFO_SCREEN_USER:
2078 case INFO_SCREEN_USER_VERIFIED_PASSED:
2081 case INFO_SCREEN_USER_VERIFIED_FAILED:
2084 default: /* INFO_SCREEN_NETWORK */
2088 switch (p_callerinfo.present) {
2089 case INFO_PRESENT_ALLOWED:
2092 case INFO_PRESENT_RESTRICTED:
2095 default: /* INFO_PRESENT_NOTAVAIL */
2099 /* caller information 2 */
2101 switch (p_callerinfo.ntype2) {
2102 case INFO_NTYPE_UNKNOWN:
2105 case INFO_NTYPE_INTERNATIONAL:
2108 case INFO_NTYPE_NATIONAL:
2111 case INFO_NTYPE_SUBSCRIBER:
2114 default: /* INFO_NTYPE_NOTPRESENT */
2118 switch (p_callerinfo.screen2) {
2119 case INFO_SCREEN_USER:
2122 case INFO_SCREEN_USER_VERIFIED_PASSED:
2125 case INFO_SCREEN_USER_VERIFIED_FAILED:
2128 default: /* INFO_SCREEN_NETWORK */
2132 switch (p_callerinfo.present2) {
2133 case INFO_PRESENT_ALLOWED:
2136 case INFO_PRESENT_RESTRICTED:
2139 default: /* INFO_PRESENT_NOTAVAIL */
2144 enc_ie_calling_pn(l3m, type, plan, present, screen, (unsigned char *)p_callerinfo.id, type2, plan2, present2, screen2, (unsigned char *)p_callerinfo.id2);
2145 /* dialing information */
2146 if (p_dialinginfo.id[0]) { /* only if we have something to dial */
2147 if (max > (int)strlen(p_dialinginfo.id) || max == 0)
2148 max = (int)strlen(p_dialinginfo.id);
2149 enc_ie_called_pn(l3m, 0, 1, (unsigned char *)p_dialinginfo.id, max);
2150 SCPY(p_m_d_queue, p_dialinginfo.id + max);
2153 if (p_dialinginfo.keypad[0])
2154 enc_ie_keypad(l3m, (unsigned char *)p_dialinginfo.keypad);
2155 /* sending complete */
2156 if (p_dialinginfo.sending_complete)
2157 enc_ie_complete(l3m, 1);
2158 /* sending user-user */
2159 if (param->setup.useruser.len) {
2160 enc_ie_useruser(l3m, param->setup.useruser.protocol, param->setup.useruser.data, param->setup.useruser.len);
2162 /* redirecting number */
2164 switch (p_redirinfo.ntype) {
2165 case INFO_NTYPE_UNKNOWN:
2168 case INFO_NTYPE_INTERNATIONAL:
2171 case INFO_NTYPE_NATIONAL:
2174 case INFO_NTYPE_SUBSCRIBER:
2177 default: /* INFO_NTYPE_NOTPRESENT */
2181 switch (p_redirinfo.screen) {
2182 case INFO_SCREEN_USER:
2185 case INFO_SCREEN_USER_VERIFIED_PASSED:
2188 case INFO_SCREEN_USER_VERIFIED_FAILED:
2191 default: /* INFO_SCREE_NETWORK */
2195 switch (p_redirinfo.reason) {
2196 case INFO_REDIR_BUSY:
2199 case INFO_REDIR_NORESPONSE:
2202 case INFO_REDIR_UNCONDITIONAL:
2205 case INFO_REDIR_CALLDEFLECT:
2208 case INFO_REDIR_OUTOFORDER:
2211 default: /* INFO_REDIR_UNKNOWN */
2215 switch (p_redirinfo.present) {
2216 case INFO_PRESENT_ALLOWED:
2219 case INFO_PRESENT_RESTRICTED:
2222 default: /* INFO_PRESENT_NOTAVAIL */
2226 /* sending redirecting number only in ntmode */
2227 if (type >= 0 && (p_m_d_ntmode || p_m_d_tespecial))
2228 enc_ie_redir_nr(l3m, type, plan, present, screen, reason, (unsigned char *)p_redirinfo.id);
2229 /* bearer capability */
2230 //printf("hlc=%d\n",p_capainfo.hlc);
2232 capability = p_capainfo.bearer_capa;
2233 mode = p_capainfo.bearer_mode;
2234 rate = (mode==INFO_BMODE_CIRCUIT)?0x10:0x00;
2235 switch (p_capainfo.bearer_info1) {
2236 case INFO_INFO1_NONE:
2240 user = p_capainfo.bearer_info1 & 0x7f;
2243 enc_ie_bearer(l3m, coding, capability, mode, rate, -1, user);
2245 if (p_capainfo.hlc) {
2249 hlc = p_capainfo.hlc & 0x7f;
2251 if (p_capainfo.exthlc)
2252 exthlc = p_capainfo.exthlc & 0x7f;
2253 enc_ie_hlc(l3m, coding, interpretation, presentation, hlc, exthlc);
2257 if (p_callerinfo.display[0] && (p_m_d_ntmode || p_m_d_tespecial))
2258 enc_ie_display(l3m, (unsigned char *)p_callerinfo.display);
2259 /* nt-mode: CNIP (calling name identification presentation) */
2260 // if (p_callerinfo.name[0] && (p_m_d_ntmode || p_m_d_tespecial))
2261 // enc_facility_centrex(&setup->FACILITY, dmsg, (unsigned char *)p_callerinfo.name, 1);
2264 /* send setup message now */
2265 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SETUP, p_m_d_l3id, l3m);
2267 new_state(PORT_STATE_OUT_SETUP);
2270 /* MESSAGE_FACILITY */
2271 void Pdss1::message_facility(unsigned int epoint_id, int message_id, union parameter *param)
2275 /* facility will not be sent to external lines */
2276 if (!p_m_d_ntmode && !p_m_d_tespecial)
2279 /* sending facility */
2280 l3m = create_l3msg();
2281 l1l2l3_trace_header(p_m_mISDNport, this, L3_FACILITY_REQ, DIRECTION_OUT);
2282 enc_ie_facility(l3m, (unsigned char *)param->facilityinfo.data, param->facilityinfo.len);
2284 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_FACILITY, p_m_d_l3id, l3m);
2287 /* MESSAGE_NOTIFY */
2288 void Pdss1::message_notify(unsigned int epoint_id, int message_id, union parameter *param)
2292 int plan = 0, type = -1, present = 0;
2294 if (p_m_mISDNport->ifport->nonotify) {
2295 l1l2l3_trace_header(p_m_mISDNport, this, L3_NOTIFY_REQ, DIRECTION_OUT);
2296 add_trace("info", NULL, "blocked by config");
2301 // printf("if = %d\n", param->notifyinfo.notify);
2302 if (param->notifyinfo.notify>INFO_NOTIFY_NONE)
2303 notify = param->notifyinfo.notify & 0x7f;
2308 switch (param->notifyinfo.ntype) {
2309 case INFO_NTYPE_UNKNOWN:
2312 case INFO_NTYPE_INTERNATIONAL:
2315 case INFO_NTYPE_NATIONAL:
2318 case INFO_NTYPE_SUBSCRIBER:
2321 default: /* INFO_NTYPE_UNKNOWN */
2325 switch (param->notifyinfo.present) {
2326 case INFO_PRESENT_ALLOWED:
2329 case INFO_PRESENT_RESTRICTED:
2332 default: /* INFO_PRESENT_NOTAVAIL */
2338 if (notify<0 && !param->notifyinfo.display[0]) {
2339 /* nothing to notify, nothing to display */
2344 if (p_state!=PORT_STATE_CONNECT && p_state!=PORT_STATE_IN_PROCEEDING && p_state!=PORT_STATE_IN_ALERTING) {
2345 /* queue notification */
2346 if (p_m_d_notify_pending)
2347 message_free(p_m_d_notify_pending);
2348 p_m_d_notify_pending = message_create(ACTIVE_EPOINT(p_epointlist), p_serial, EPOINT_TO_PORT, message_id);
2349 memcpy(&p_m_d_notify_pending->param, param, sizeof(union parameter));
2351 /* sending notification */
2352 l3m = create_l3msg();
2353 l1l2l3_trace_header(p_m_mISDNport, this, L3_NOTIFY_REQ, DIRECTION_OUT);
2354 enc_ie_notify(l3m, notify);
2355 /* sending redirection number only in ntmode */
2356 if (type >= 0 && (p_m_d_ntmode || p_m_d_tespecial))
2357 enc_ie_redir_dn(l3m, type, plan, present, (unsigned char *)param->notifyinfo.id);
2358 if (param->notifyinfo.display[0] && (p_m_d_ntmode || p_m_d_tespecial))
2359 enc_ie_display(l3m, (unsigned char *)param->notifyinfo.display);
2361 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_NOTIFY, p_m_d_l3id, l3m);
2363 } else if (p_m_d_ntmode || p_m_d_tespecial) {
2364 /* sending information */
2365 l3m = create_l3msg();
2366 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
2367 enc_ie_display(l3m, (unsigned char *)param->notifyinfo.display);
2369 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
2373 /* MESSAGE_OVERLAP */
2374 void Pdss1::message_overlap(unsigned int epoint_id, int message_id, union parameter *param)
2378 /* in case of sending complete, we proceed */
2379 if (p_dialinginfo.sending_complete) {
2380 PDEBUG(DEBUG_ISDN, "sending proceeding instead of setup_acknowledge, because address is complete.\n");
2381 message_proceeding(epoint_id, message_id, param);
2385 /* sending setup_acknowledge */
2386 l3m = create_l3msg();
2387 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_ACKNOWLEDGE_REQ, DIRECTION_OUT);
2388 /* channel information */
2389 if (p_state == PORT_STATE_IN_SETUP)
2390 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2391 /* progress information */
2392 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2393 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2394 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2395 if (p_m_mISDNport->tones)
2396 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2398 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SETUP_ACKNOWLEDGE, p_m_d_l3id, l3m);
2400 new_state(PORT_STATE_IN_OVERLAP);
2403 /* MESSAGE_PROCEEDING */
2404 void Pdss1::message_proceeding(unsigned int epoint_id, int message_id, union parameter *param)
2408 /* sending proceeding */
2409 l3m = create_l3msg();
2410 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2411 /* channel information */
2412 if (p_state == PORT_STATE_IN_SETUP)
2413 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2414 /* progress information */
2415 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2416 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2417 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2418 if (p_m_mISDNport->tones)
2419 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2421 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2423 new_state(PORT_STATE_IN_PROCEEDING);
2426 /* MESSAGE_ALERTING */
2427 void Pdss1::message_alerting(unsigned int epoint_id, int message_id, union parameter *param)
2431 /* NT-MODE in setup state we must send PROCEEDING first */
2432 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP) {
2433 /* sending proceeding */
2434 l3m = create_l3msg();
2435 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2436 /* channel information */
2437 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2438 /* progress information */
2439 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2440 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2441 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2442 if (p_m_mISDNport->tones)
2443 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2445 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2446 new_state(PORT_STATE_IN_PROCEEDING);
2449 /* sending alerting */
2450 l3m = create_l3msg();
2451 l1l2l3_trace_header(p_m_mISDNport, this, L3_ALERTING_REQ, DIRECTION_OUT);
2452 /* channel information */
2453 if (p_state == PORT_STATE_IN_SETUP)
2454 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2455 /* progress information */
2456 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2457 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2458 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2459 if (p_m_mISDNport->tones)
2460 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2462 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_ALERTING, p_m_d_l3id, l3m);
2464 new_state(PORT_STATE_IN_ALERTING);
2467 /* MESSAGE_CONNECT */
2468 void Pdss1::message_connect(unsigned int epoint_id, int message_id, union parameter *param)
2471 int type, plan, present, screen;
2472 class Endpoint *epoint;
2473 time_t current_time;
2475 /* NT-MODE in setup state we must send PROCEEDING first */
2476 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP) {
2477 /* sending proceeding */
2478 l3m = create_l3msg();
2479 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2480 /* channel information */
2481 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2483 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2484 new_state(PORT_STATE_IN_PROCEEDING);
2487 /* copy connected information */
2488 memcpy(&p_connectinfo, ¶m->connectinfo, sizeof(p_connectinfo));
2489 /* screen outgoing caller id */
2490 do_screen(1, p_connectinfo.id, sizeof(p_connectinfo.id), &p_connectinfo.ntype, &p_connectinfo.present, p_m_mISDNport->ifport->interface->name);
2492 /* only display at connect state */
2493 if (p_state == PORT_STATE_CONNECT)
2494 if (p_connectinfo.display[0]) {
2495 /* sending information */
2496 l3m = create_l3msg();
2497 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
2498 if (p_m_d_ntmode || p_m_d_tespecial)
2499 enc_ie_display(l3m, (unsigned char *)p_connectinfo.display);
2501 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
2505 if (p_state!=PORT_STATE_IN_SETUP && p_state!=PORT_STATE_IN_OVERLAP && p_state!=PORT_STATE_IN_PROCEEDING && p_state!=PORT_STATE_IN_ALERTING) {
2506 /* connect command only possible in setup, proceeding or alerting state */
2510 /* preparing connect message */
2511 l3m = create_l3msg();
2512 l1l2l3_trace_header(p_m_mISDNport, this, L3_CONNECT_REQ, DIRECTION_OUT);
2513 /* connect information */
2515 switch (p_connectinfo.ntype) {
2516 case INFO_NTYPE_UNKNOWN:
2519 case INFO_NTYPE_INTERNATIONAL:
2522 case INFO_NTYPE_NATIONAL:
2525 case INFO_NTYPE_SUBSCRIBER:
2528 default: /* INFO_NTYPE_NOTPRESENT */
2532 switch (param->connectinfo.screen) {
2533 case INFO_SCREEN_USER:
2536 case INFO_SCREEN_USER_VERIFIED_PASSED:
2539 case INFO_SCREEN_USER_VERIFIED_FAILED:
2542 default: /* INFO_SCREE_NETWORK */
2546 switch (p_connectinfo.present) {
2547 case INFO_PRESENT_ALLOWED:
2550 case INFO_PRESENT_RESTRICTED:
2553 default: /* INFO_PRESENT_NOTAVAIL */
2558 enc_ie_connected_pn(l3m, type, plan, present, screen, (unsigned char *)p_connectinfo.id);
2560 if (p_connectinfo.display[0] && (p_m_d_ntmode || p_m_d_tespecial))
2561 enc_ie_display(l3m, (unsigned char *)p_connectinfo.display);
2562 /* nt-mode: CONP (connected name identification presentation) */
2563 // if (p_connectinfo.name[0] && (p_m_d_ntmode || p_m_d_tespecial))
2564 // enc_facility_centrex(&connect->FACILITY, dmsg, (unsigned char *)p_connectinfo.name, 0);
2566 if (p_m_d_ntmode || p_m_d_tespecial) {
2567 epoint = find_epoint_id(epoint_id);
2568 time(¤t_time);
2569 enc_ie_date(l3m, current_time, p_settings.no_seconds);
2572 /* finally send message */
2573 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CONNECT, p_m_d_l3id, l3m);
2576 new_state(PORT_STATE_CONNECT);
2578 new_state(PORT_STATE_CONNECT_WAITING);
2582 /* MESSAGE_DISCONNECT */
2583 void Pdss1::message_disconnect(unsigned int epoint_id, int message_id, union parameter *param)
2586 struct lcr_msg *message;
2589 /* we reject during incoming setup when we have no tones. also if we are in outgoing setup state */
2590 // if ((p_state==PORT_STATE_IN_SETUP && !p_m_mISDNport->tones)
2591 if (/* ||*/ p_state==PORT_STATE_OUT_SETUP) {
2592 /* sending release to endpoint */
2593 while(p_epointlist) {
2594 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
2595 memcpy(&message->param, param, sizeof(union parameter));
2596 message_put(message);
2598 free_epointlist(p_epointlist);
2600 /* sending release */
2601 l3m = create_l3msg();
2602 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
2604 enc_ie_cause(l3m, (!p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_REMOTE:param->disconnectinfo.location, param->disconnectinfo.cause);
2606 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
2607 new_state(PORT_STATE_RELEASE);
2608 trigger_work(&p_m_d_delete);
2612 /* workarround: NT-MODE in setup state we must send PROCEEDING first to make it work */
2613 if (p_state==PORT_STATE_IN_SETUP) {
2614 /* sending proceeding */
2615 l3m = create_l3msg();
2616 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2617 /* channel information */
2618 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2619 /* progress information */
2620 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2621 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2622 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2623 if (p_m_mISDNport->tones)
2624 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2626 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2627 new_state(PORT_STATE_IN_PROCEEDING);
2630 /* sending disconnect */
2631 l3m = create_l3msg();
2632 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_REQ, DIRECTION_OUT);
2633 /* progress information */
2634 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2635 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2636 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2637 if (p_m_mISDNport->tones)
2638 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2640 enc_ie_cause(l3m, (!p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_REMOTE:param->disconnectinfo.location, param->disconnectinfo.cause);
2642 if (param->disconnectinfo.display[0])
2643 p = param->disconnectinfo.display;
2644 if (p) if (*p && (p_m_d_ntmode || p_m_d_tespecial))
2645 enc_ie_display(l3m, (unsigned char *)p);
2647 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_DISCONNECT, p_m_d_l3id, l3m);
2648 new_state(PORT_STATE_OUT_DISCONNECT);
2651 /* MESSAGE_RELEASE */
2652 void Pdss1::message_release(unsigned int epoint_id, int message_id, union parameter *param)
2655 class Endpoint *epoint;
2659 * if we are on incoming call setup, we may reject by sending a release_complete
2660 * also on outgoing call setup, we send a release complete, BUT this is not conform. (i don't know any other way)
2662 if (p_state==PORT_STATE_IN_SETUP
2663 || p_state==PORT_STATE_OUT_SETUP) {
2664 //#warning remove me
2665 //PDEBUG(DEBUG_LOG, "JOLLY sending release complete %d\n", p_serial);
2666 /* sending release complete */
2667 l3m = create_l3msg();
2668 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_REQ, DIRECTION_OUT);
2670 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2672 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
2673 new_state(PORT_STATE_RELEASE);
2675 free_epointid(epoint_id);
2676 // wait for callref to be released
2680 * we may only release during incoming disconnect state.
2681 * this means that the endpoint doesnt require audio anymore
2683 if (p_state == PORT_STATE_IN_DISCONNECT
2684 || p_state == PORT_STATE_OUT_DISCONNECT
2685 || param->disconnectinfo.force) {
2686 /* sending release */
2687 l3m = create_l3msg();
2688 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_REQ, DIRECTION_OUT);
2690 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2692 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE, p_m_d_l3id, l3m);
2693 new_state(PORT_STATE_RELEASE);
2695 free_epointid(epoint_id);
2696 // wait for callref to be released
2702 wirklich erst proceeding?:
2703 /* NT-MODE in setup state we must send PROCEEDING first */
2704 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP) {
2705 CALL_PROCEEDING_t *proceeding;
2707 /* sending proceeding */
2708 l3m = create_l3msg();
2709 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2710 /* channel information */
2711 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2712 /* progress information */
2713 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2714 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2715 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2716 if (p_m_mISDNport->tones)
2717 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2719 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2723 /* sending disconnect */
2724 l3m = create_l3msg();
2725 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_REQ, DIRECTION_OUT);
2726 /* progress information */
2727 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2728 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2729 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2730 if (p_m_mISDNport->tones)
2731 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2733 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2735 epoint = find_epoint_id(epoint_id);
2736 if (param->disconnectinfo.display[0])
2737 p = param->disconnectinfo.display;
2738 if (p) if (*p && (p_m_d_ntmode || p_m_d_tespecial))
2739 enc_ie_display(l3m, (unsigned char *)p);
2741 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_DISCONNECT, p_m_d_l3id, l3m);
2742 new_state(PORT_STATE_OUT_DISCONNECT);
2744 free_epointid(epoint_id);
2745 // wait for release and callref to be released
2746 //#warning remove me
2747 //PDEBUG(DEBUG_LOG, "JOLLY sending disconnect %d\n", p_serial);
2752 * endpoint sends messages to the port
2754 int Pdss1::message_epoint(unsigned int epoint_id, int message_id, union parameter *param)
2756 if (PmISDN::message_epoint(epoint_id, message_id, param))
2759 switch(message_id) {
2760 case MESSAGE_INFORMATION: /* overlap dialing */
2761 if (p_type==PORT_TYPE_DSS1_NT_OUT
2762 && p_state!=PORT_STATE_OUT_OVERLAP
2763 && p_state!=PORT_STATE_CONNECT
2764 && p_state!=PORT_STATE_OUT_DISCONNECT
2765 && p_state!=PORT_STATE_IN_DISCONNECT) {
2768 if (p_type==PORT_TYPE_DSS1_TE_OUT
2769 && p_state!=PORT_STATE_OUT_OVERLAP
2770 && p_state!=PORT_STATE_OUT_PROCEEDING
2771 && p_state!=PORT_STATE_OUT_ALERTING
2772 && p_state!=PORT_STATE_CONNECT
2773 && p_state!=PORT_STATE_OUT_DISCONNECT
2774 && p_state!=PORT_STATE_IN_DISCONNECT) {
2777 if ((p_type==PORT_TYPE_DSS1_NT_IN || p_type==PORT_TYPE_DSS1_TE_IN)
2778 && p_state!=PORT_STATE_IN_OVERLAP
2779 && p_state!=PORT_STATE_IN_PROCEEDING
2780 && p_state!=PORT_STATE_IN_ALERTING
2781 && p_state!=PORT_STATE_CONNECT
2782 && p_state!=PORT_STATE_CONNECT_WAITING
2783 && p_state!=PORT_STATE_OUT_DISCONNECT
2784 && p_state!=PORT_STATE_IN_DISCONNECT) {
2787 message_information(epoint_id, message_id, param);
2790 case MESSAGE_SETUP: /* dial-out command received from epoint */
2791 if (p_state!=PORT_STATE_IDLE
2792 && p_state!=PORT_STATE_CONNECT) {
2793 PERROR("Pdss1(%s) ignoring setup because isdn port is not in idle state (or connected for sending display info).\n", p_name);
2796 if (p_epointlist && p_state==PORT_STATE_IDLE)
2797 FATAL("Pdss1(%s): epoint pointer is set in idle state, how bad!!\n", p_name);
2798 message_setup(epoint_id, message_id, param);
2801 case MESSAGE_NOTIFY: /* display and notifications */
2802 message_notify(epoint_id, message_id, param);
2805 case MESSAGE_FACILITY: /* facility message */
2806 message_facility(epoint_id, message_id, param);
2809 case MESSAGE_OVERLAP: /* more information is needed */
2810 if (p_state!=PORT_STATE_IN_SETUP) {
2813 message_overlap(epoint_id, message_id, param);
2816 case MESSAGE_PROCEEDING: /* call of endpoint is proceeding */
2817 if (p_state!=PORT_STATE_IN_SETUP
2818 && p_state!=PORT_STATE_IN_OVERLAP) {
2821 message_proceeding(epoint_id, message_id, param);
2822 if (p_m_d_notify_pending) {
2823 /* send pending notify message during connect */
2824 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2825 message_free(p_m_d_notify_pending);
2826 p_m_d_notify_pending = NULL;
2830 case MESSAGE_ALERTING: /* call of endpoint is ringing */
2831 if (p_state!=PORT_STATE_IN_SETUP
2832 && p_state!=PORT_STATE_IN_OVERLAP
2833 && p_state!=PORT_STATE_IN_PROCEEDING) {
2836 message_alerting(epoint_id, message_id, param);
2837 if (p_m_d_notify_pending) {
2838 /* send pending notify message during connect */
2839 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2840 message_free(p_m_d_notify_pending);
2841 p_m_d_notify_pending = NULL;
2845 case MESSAGE_CONNECT: /* call of endpoint is connected */
2846 if (p_state!=PORT_STATE_IN_SETUP
2847 && p_state!=PORT_STATE_IN_OVERLAP
2848 && p_state!=PORT_STATE_IN_PROCEEDING
2849 && p_state!=PORT_STATE_IN_ALERTING
2850 && !(p_state==PORT_STATE_CONNECT && p_m_d_ntmode)) {
2853 message_connect(epoint_id, message_id, param);
2854 if (p_m_d_notify_pending) {
2855 /* send pending notify message during connect */
2856 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2857 message_free(p_m_d_notify_pending);
2858 p_m_d_notify_pending = NULL;
2862 case MESSAGE_DISCONNECT: /* call has been disconnected */
2863 if (p_state!=PORT_STATE_IN_SETUP
2864 && p_state!=PORT_STATE_IN_OVERLAP
2865 && p_state!=PORT_STATE_IN_PROCEEDING
2866 && p_state!=PORT_STATE_IN_ALERTING
2867 && p_state!=PORT_STATE_OUT_SETUP
2868 && p_state!=PORT_STATE_OUT_OVERLAP
2869 && p_state!=PORT_STATE_OUT_PROCEEDING
2870 && p_state!=PORT_STATE_OUT_ALERTING
2871 && p_state!=PORT_STATE_CONNECT
2872 && p_state!=PORT_STATE_CONNECT_WAITING) {
2875 message_disconnect(epoint_id, message_id, param);
2878 case MESSAGE_RELEASE: /* release isdn port */
2879 if (p_state==PORT_STATE_RELEASE) {
2882 message_release(epoint_id, message_id, param);
2886 PERROR("Pdss1(%s) isdn port with (caller id %s) received a wrong message: %d\n", p_name, p_callerinfo.id, message_id);
2895 * data from isdn-stack (layer-3) to pbx (port class)
2897 int stack2manager(struct mISDNport *mISDNport, unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
2903 PDEBUG(DEBUG_ISDN, "cmd(0x%x) pid(0x%x)\n", cmd, pid);
2906 PDEBUG(DEBUG_ISDN, "ignoring dummy process from phone.\n");
2910 /* find Port object of type ISDN */
2914 if ((port->p_type & PORT_CLASS_mISDN_MASK) == PORT_CLASS_DSS1) {
2915 pdss1 = (class Pdss1 *)port;
2916 /* check out correct stack and id */
2917 if (pdss1->p_m_mISDNport == mISDNport) {
2918 if (pdss1->p_m_d_l3id & MISDN_PID_CR_FLAG) {
2919 /* local callref, so match value only */
2920 if ((pdss1->p_m_d_l3id & MISDN_PID_CRVAL_MASK) == (pid & MISDN_PID_CRVAL_MASK))
2923 /* remote callref, ref + channel id */
2924 if (pdss1->p_m_d_l3id == pid)
2932 /* aktueller prozess */
2934 if (cmd == MT_ASSIGN) {
2935 /* stack gives us new layer 3 id (during connect) */
2936 l1l2l3_trace_header(mISDNport, pdss1, L3_NEW_L3ID_IND, DIRECTION_IN);
2937 add_trace("callref", "old", "0x%x", pdss1->p_m_d_l3id);
2938 /* nt-library now gives us a new id via CC_SETUP_CONFIRM */
2939 if ((pdss1->p_m_d_l3id&MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER)
2940 PERROR(" strange setup-procid 0x%x\n", pdss1->p_m_d_l3id);
2941 pdss1->p_m_d_l3id = pid;
2942 if (port->p_state == PORT_STATE_CONNECT)
2943 pdss1->p_m_d_ces = pid >> 16;
2944 add_trace("callref", "new", "0x%x", pdss1->p_m_d_l3id);
2948 /* if process id is master process, but a child disconnects */
2949 if (mISDNport->ntmode
2950 && (pid & MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER
2951 && (pdss1->p_m_d_l3id & MISDN_PID_CRTYPE_MASK) == MISDN_PID_MASTER) {
2952 if (cmd == MT_DISCONNECT
2953 || cmd == MT_RELEASE) {
2954 /* send special indication for child disconnect */
2955 pdss1->disconnect_ind_i(cmd, pid, l3m);
2958 if (cmd == MT_RELEASE_COMPLETE)
2961 /* if we have child pid and got different child pid message, ignore */
2962 if (mISDNport->ntmode
2963 && (pid & MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER
2964 && (pdss1->p_m_d_l3id & MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER
2965 && pid != pdss1->p_m_d_l3id)
2968 /* process message */
2969 pdss1->message_isdn(cmd, pid, l3m);
2976 /* creating port object, transparent until setup with hdlc */
2977 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
2978 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0, B_MODE_TRANSPARENT)))
2980 FATAL("Cannot create Port instance.\n");
2981 pdss1->message_isdn(cmd, pid, l3m);
2985 /* creating port object, transparent until setup with hdlc */
2986 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
2987 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0, B_MODE_TRANSPARENT)))
2988 FATAL("Cannot create Port instance.\n");
2989 pdss1->message_isdn(cmd, pid, l3m);
2993 PDEBUG(DEBUG_ISDN, "unused call ref released (l3id=0x%x)\n", pid);
2996 case MT_RELEASE_COMPLETE:
2997 PERROR("must be ignored by stack, not sent to app\n");
3001 // facility als broadcast
3005 // L2 became idle - we could sent a MT_L2RELEASE if we are the L2 master
3006 PDEBUG(DEBUG_ISDN, "Got L2 idle\n");
3010 PERROR("unhandled message: cmd(0x%x) pid(0x%x)\n", cmd, pid);
3013 if (port->p_type == PORT_TYPE_DSS1_NT_IN || port->p_type == PORT_TYPE_DSS1_NT_OUT) {
3014 pdss1 = (class Pdss1 *)port;
3015 /* check out correct stack */
3016 if (pdss1->p_m_mISDNport == mISDNport)
3017 /* check out correct id */
3018 PERROR("unhandled message: pid=%x is not associated with port-dinfo=%x\n", pid, pdss1->p_m_d_l3id);