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 if (!(epoint->ep_app = new DEFAULT_ENDPOINT_APP(epoint, 0))) //incoming
733 FATAL("No memory for Endpoint Application instance\n");
734 epointlist_new(epoint->ep_serial);
736 /* send setup message to endpoit */
737 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_SETUP);
738 message->param.setup.isdn_port = p_m_portnum;
739 message->param.setup.port_type = p_type;
740 // message->param.setup.dtmf = !p_m_mISDNport->ifport->nodtmf;
741 memcpy(&message->param.setup.dialinginfo, &p_dialinginfo, sizeof(struct dialing_info));
742 memcpy(&message->param.setup.callerinfo, &p_callerinfo, sizeof(struct caller_info));
743 memcpy(&message->param.setup.redirinfo, &p_redirinfo, sizeof(struct redir_info));
744 memcpy(&message->param.setup.capainfo, &p_capainfo, sizeof(struct capa_info));
745 memcpy(message->param.setup.useruser.data, &useruser, useruser_len);
746 message->param.setup.useruser.len = useruser_len;
747 message->param.setup.useruser.protocol = useruser_protocol;
748 message_put(message);
750 new_state(PORT_STATE_IN_SETUP);
753 /* CC_INFORMATION INDICATION */
754 void Pdss1::information_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
757 unsigned char keypad[33] = "", display[128] = "";
758 struct lcr_msg *message;
760 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_IND, DIRECTION_IN);
761 dec_ie_called_pn(l3m, &type, &plan, (unsigned char *)p_dialinginfo.id, sizeof(p_dialinginfo.id));
762 dec_ie_keypad(l3m, (unsigned char *)keypad, sizeof(keypad));
763 dec_ie_display(l3m, (unsigned char *)display, sizeof(display));
764 dec_ie_complete(l3m, &p_dialinginfo.sending_complete);
767 SCAT(p_dialinginfo.id, (char *)keypad);
770 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
773 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
776 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
779 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
782 SCPY(p_dialinginfo.display, (char *)display);
783 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_INFORMATION);
784 memcpy(&message->param.information, &p_dialinginfo, sizeof(struct dialing_info));
785 message_put(message);
786 /* reset overlap timeout */
790 /* CC_SETUP_ACCNOWLEDGE INDICATION */
791 void Pdss1::setup_acknowledge_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
793 int exclusive, channel;
794 int coding, location, progress;
796 struct lcr_msg *message;
797 int max = p_m_mISDNport->ifport->dialmax;
801 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_ACKNOWLEDGE_IND, DIRECTION_IN);
802 dec_ie_channel_id(l3m, &exclusive, &channel);
803 dec_ie_progress(l3m, &coding, &location, &progress);
807 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROGRESS);
808 message->param.progressinfo.progress = progress;
809 message->param.progressinfo.location = location;
810 message_put(message);
813 /* process channel */
814 ret = received_first_reply_to_setup(cmd, channel, exclusive);
816 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
817 message->param.disconnectinfo.cause = -ret;
818 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
819 message_put(message);
820 new_state(PORT_STATE_RELEASE);
821 trigger_work(&p_m_d_delete);
825 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_OVERLAP);
826 message_put(message);
828 new_state(PORT_STATE_OUT_OVERLAP);
830 number = p_m_d_queue;
831 while (number[0]) { /* as long we have something to dial */
832 if (max > (int)strlen(number) || max == 0)
833 max = (int)strlen(number);
835 nl3m = create_l3msg();
836 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
837 enc_ie_called_pn(nl3m, 0, 1, (unsigned char *)number, max);
839 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, nl3m);
842 p_m_d_queue[0] = '\0';
845 /* CC_PROCEEDING INDICATION */
846 void Pdss1::proceeding_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
848 int exclusive, channel;
849 int coding, location, progress;
851 struct lcr_msg *message;
852 int notify = -1, type, plan, present;
855 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_IND, DIRECTION_IN);
856 dec_ie_channel_id(l3m, &exclusive, &channel);
857 dec_ie_progress(l3m, &coding, &location, &progress);
858 dec_ie_notify(l3m, ¬ify);
859 dec_ie_redir_dn(l3m, &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
863 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROGRESS);
864 message->param.progressinfo.progress = progress;
865 message->param.progressinfo.location = location;
866 message_put(message);
869 ret = received_first_reply_to_setup(cmd, channel, exclusive);
871 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
872 message->param.disconnectinfo.cause = -ret;
873 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
874 message_put(message);
875 new_state(PORT_STATE_RELEASE);
876 trigger_work(&p_m_d_delete);
879 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROCEEDING);
880 message_put(message);
882 new_state(PORT_STATE_OUT_PROCEEDING);
888 if (type >= 0 || notify) {
889 if (!notify && type >= 0)
891 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
892 message->param.notifyinfo.notify = notify;
893 SCPY(message->param.notifyinfo.id, redir);
894 /* redirection number */
897 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
900 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
903 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
908 message->param.notifyinfo.ntype = INFO_NTYPE_NOTPRESENT;
911 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
914 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
917 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
920 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
923 message->param.notifyinfo.isdn_port = p_m_portnum;
924 message_put(message);
928 /* CC_ALERTING INDICATION */
929 void Pdss1::alerting_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
931 int exclusive, channel;
932 int coding, location, progress;
934 struct lcr_msg *message;
935 int notify = -1, type, plan, present;
938 l1l2l3_trace_header(p_m_mISDNport, this, L3_ALERTING_IND, DIRECTION_IN);
939 dec_ie_channel_id(l3m, &exclusive, &channel);
940 dec_ie_progress(l3m, &coding, &location, &progress);
941 dec_ie_notify(l3m, ¬ify);
942 dec_ie_redir_dn(l3m, &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
946 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROGRESS);
947 message->param.progressinfo.progress = progress;
948 message->param.progressinfo.location = location;
949 message_put(message);
952 /* process channel */
953 ret = received_first_reply_to_setup(cmd, channel, exclusive);
955 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
956 message->param.disconnectinfo.cause = -ret;
957 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
958 message_put(message);
959 new_state(PORT_STATE_RELEASE);
960 trigger_work(&p_m_d_delete);
963 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_ALERTING);
964 message_put(message);
966 new_state(PORT_STATE_OUT_ALERTING);
972 if (type >= 0 || notify) {
973 if (!notify && type >= 0)
975 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
976 message->param.notifyinfo.notify = notify;
977 SCPY(message->param.notifyinfo.id, redir);
980 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
983 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
986 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
991 message->param.notifyinfo.ntype = INFO_NTYPE_NOTPRESENT;
994 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
997 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1000 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1003 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1006 message->param.notifyinfo.isdn_port = p_m_portnum;
1007 message_put(message);
1011 /* CC_CONNECT INDICATION */
1012 void Pdss1::connect_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1014 int exclusive, channel;
1015 int type, plan, present, screen;
1017 struct lcr_msg *message;
1018 int bchannel_before;
1020 l1l2l3_trace_header(p_m_mISDNport, this, L3_CONNECT_IND, DIRECTION_IN);
1021 dec_ie_channel_id(l3m, &exclusive, &channel);
1022 dec_ie_connected_pn(l3m, &type, &plan, &present, &screen, (unsigned char *)p_connectinfo.id, sizeof(p_connectinfo.id));
1023 dec_ie_display(l3m, (unsigned char *)p_connectinfo.display, sizeof(p_connectinfo.display));
1024 /* te-mode: CONP (connected name identification presentation) */
1025 dec_facility_centrex(l3m, (unsigned char *)p_connectinfo.name, sizeof(p_connectinfo.name));
1028 /* select channel */
1029 bchannel_before = p_m_b_channel;
1030 ret = received_first_reply_to_setup(cmd, channel, exclusive);
1032 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1033 message->param.disconnectinfo.cause = -ret;
1034 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1035 message_put(message);
1036 new_state(PORT_STATE_RELEASE);
1037 trigger_work(&p_m_d_delete);
1041 /* connect information */
1044 p_connectinfo.present = INFO_PRESENT_RESTRICTED;
1047 p_connectinfo.present = INFO_PRESENT_NOTAVAIL;
1050 p_connectinfo.present = INFO_PRESENT_ALLOWED;
1055 p_connectinfo.screen = INFO_SCREEN_USER;
1058 p_connectinfo.screen = INFO_SCREEN_USER_VERIFIED_PASSED;
1061 p_connectinfo.screen = INFO_SCREEN_USER_VERIFIED_FAILED;
1064 p_connectinfo.screen = INFO_SCREEN_NETWORK;
1069 p_connectinfo.ntype = INFO_NTYPE_NOTPRESENT;
1072 p_connectinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1075 p_connectinfo.ntype = INFO_NTYPE_NATIONAL;
1078 p_connectinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1081 p_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1084 p_connectinfo.isdn_port = p_m_portnum;
1085 SCPY(p_connectinfo.interface, p_m_mISDNport->ifport->interface->name);
1087 /* only in nt-mode we send connect ack. in te-mode it is done by stack itself or optional */
1089 /* send connect acknowledge */
1090 l3m = create_l3msg();
1091 l1l2l3_trace_header(p_m_mISDNport, this, L3_CONNECT_RES, DIRECTION_OUT);
1092 /* if we had no bchannel before, we send it now */
1093 if (!bchannel_before && p_m_b_channel)
1094 enc_ie_channel_id(l3m, 1, p_m_b_channel);
1096 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CONNECT_ACKNOWLEDGE, p_m_d_l3id, l3m);
1099 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CONNECT);
1100 memcpy(&message->param.connectinfo, &p_connectinfo, sizeof(struct connect_info));
1101 message_put(message);
1103 new_state(PORT_STATE_CONNECT);
1106 /* CC_DISCONNECT INDICATION */
1107 void Pdss1::disconnect_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1109 int location, cause;
1110 int coding, proglocation, progress;
1111 struct lcr_msg *message;
1112 unsigned char display[128] = "";
1114 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_IND, DIRECTION_IN);
1115 dec_ie_progress(l3m, &coding, &proglocation, &progress);
1116 dec_ie_cause(l3m, &location, &cause);
1117 dec_ie_display(l3m, (unsigned char *)display, sizeof(display));
1122 location = LOCATION_PRIVATE_LOCAL;
1125 if (progress >= 0) {
1126 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROGRESS);
1127 message->param.progressinfo.progress = progress;
1128 message->param.progressinfo.location = proglocation;
1129 message_put(message);
1132 /* release if remote sends us no tones */
1133 if (!p_m_mISDNport->earlyb) {
1136 l3m = create_l3msg();
1137 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_REQ, DIRECTION_OUT);
1138 enc_ie_cause(l3m, location, cause); /* normal */
1139 add_trace("reason", NULL, "no remote patterns");
1141 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE, p_m_d_l3id, l3m);
1143 /* sending release to endpoint */
1144 if (location == LOCATION_PRIVATE_LOCAL)
1145 location = LOCATION_PRIVATE_REMOTE;
1146 while(p_epointlist) {
1147 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1148 message->param.disconnectinfo.cause = cause;
1149 message->param.disconnectinfo.location = location;
1150 SCAT(message->param.disconnectinfo.display, (char *)display);
1151 message_put(message);
1153 free_epointlist(p_epointlist);
1155 new_state(PORT_STATE_RELEASE);
1156 trigger_work(&p_m_d_delete);
1160 /* sending disconnect to active endpoint and release to inactive endpoints */
1161 if (location == LOCATION_PRIVATE_LOCAL)
1162 location = LOCATION_PRIVATE_REMOTE;
1163 if (ACTIVE_EPOINT(p_epointlist)) {
1164 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DISCONNECT);
1165 message->param.disconnectinfo.location = location;
1166 message->param.disconnectinfo.cause = cause;
1167 SCAT(message->param.disconnectinfo.display, (char *)display);
1168 message_put(message);
1170 while(INACTIVE_EPOINT(p_epointlist)) {
1171 message = message_create(p_serial, INACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1172 message->param.disconnectinfo.location = location;
1173 message->param.disconnectinfo.cause = cause;
1174 SCAT(message->param.disconnectinfo.display, (char *)display);
1175 message_put(message);
1177 free_epointid(INACTIVE_EPOINT(p_epointlist));
1179 new_state(PORT_STATE_IN_DISCONNECT);
1182 /* CC_DISCONNECT INDICATION */
1183 void Pdss1::disconnect_ind_i(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1185 int location, cause;
1188 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_IND, DIRECTION_IN);
1189 if (p_m_d_collect_cause > 0) {
1190 add_trace("old-cause", "location", "%d", p_m_d_collect_location);
1191 add_trace("old-cause", "value", "%d", p_m_d_collect_cause);
1193 dec_ie_cause(l3m, &location, &cause);
1194 if (location == LOCATION_PRIVATE_LOCAL)
1195 location = LOCATION_PRIVATE_REMOTE;
1198 collect_cause(&p_m_d_collect_cause, &p_m_d_collect_location, cause, location);
1199 add_trace("new-cause", "location", "%d", p_m_d_collect_location);
1200 add_trace("new-cause", "value", "%d", p_m_d_collect_cause);
1205 /* CC_RELEASE INDICATION */
1206 void Pdss1::release_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1208 int location, cause;
1209 struct lcr_msg *message;
1210 unsigned char display[128] = "";
1212 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_IND, DIRECTION_IN);
1213 dec_ie_cause(l3m, &location, &cause);
1214 dec_ie_display(l3m, (unsigned char *)display, sizeof(display));
1219 location = LOCATION_PRIVATE_LOCAL;
1222 /* sending release to endpoint */
1223 if (location == LOCATION_PRIVATE_LOCAL)
1224 location = LOCATION_PRIVATE_REMOTE;
1225 while(p_epointlist) {
1226 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1227 message->param.disconnectinfo.cause = cause;
1228 message->param.disconnectinfo.location = location;
1229 SCAT(message->param.disconnectinfo.display, (char *)display);
1230 message_put(message);
1232 free_epointlist(p_epointlist);
1235 new_state(PORT_STATE_RELEASE);
1236 trigger_work(&p_m_d_delete);
1239 /* CC_RESTART INDICATION */
1240 void Pdss1::restart_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1242 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESTART_IND, DIRECTION_IN);
1245 // L3 process is not toucht. (not even by network stack)
1248 /* CC_RELEASE_COMPLETE INDICATION (a reject) */
1249 void Pdss1::release_complete_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1251 int location, cause;
1252 struct lcr_msg *message;
1254 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_IND, DIRECTION_IN);
1255 /* in case layer 2 is down during setup, we send cause 27 loc 5 */
1256 if (p_state == PORT_STATE_OUT_SETUP && p_m_mISDNport->l1link == 0) {
1260 dec_ie_cause(l3m, &location, &cause);
1261 if (p_m_mISDNport->l1link < 0)
1262 add_trace("layer 1", NULL, "unknown");
1264 add_trace("layer 1", NULL, (p_m_mISDNport->l1link)?"up":"down");
1267 if (location == LOCATION_PRIVATE_LOCAL)
1268 location = LOCATION_PRIVATE_REMOTE;
1272 location = LOCATION_PRIVATE_LOCAL;
1275 /* sending release to endpoint */
1276 while(p_epointlist) {
1277 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1278 message->param.disconnectinfo.cause = cause;
1279 message->param.disconnectinfo.location = location;
1280 message_put(message);
1282 free_epointlist(p_epointlist);
1285 new_state(PORT_STATE_RELEASE);
1286 trigger_work(&p_m_d_delete);
1290 void Pdss1::t312_timeout_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1292 // not required, release is performed with MT_FREE
1295 /* CC_NOTIFY INDICATION */
1296 void Pdss1::notify_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1298 struct lcr_msg *message;
1299 int notify, type, plan, present;
1300 unsigned char notifyid[sizeof(message->param.notifyinfo.id)];
1301 unsigned char display[128] = "";
1303 l1l2l3_trace_header(p_m_mISDNport, this, L3_NOTIFY_IND, DIRECTION_IN);
1304 dec_ie_notify(l3m, ¬ify);
1305 dec_ie_redir_dn(l3m, &type, &plan, &present, notifyid, sizeof(notifyid));
1306 dec_ie_display(l3m, (unsigned char *)display, sizeof(display));
1309 if (!ACTIVE_EPOINT(p_epointlist))
1311 /* notification indicator */
1315 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1316 message->param.notifyinfo.notify = notify;
1317 SCPY(message->param.notifyinfo.id, (char *)notifyid);
1318 /* redirection number */
1321 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1324 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1327 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1332 message->param.notifyinfo.ntype = INFO_NTYPE_NOTPRESENT;
1335 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1338 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1341 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1344 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1347 SCAT(message->param.notifyinfo.display, (char *)display);
1348 message->param.notifyinfo.isdn_port = p_m_portnum;
1349 message_put(message);
1353 /* CC_HOLD INDICATION */
1354 struct lcr_msg *message;
1355 void Pdss1::hold_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1357 // class Endpoint *epoint;
1359 l1l2l3_trace_header(p_m_mISDNport, this, L3_HOLD_IND, DIRECTION_IN);
1362 if (!ACTIVE_EPOINT(p_epointlist) || p_m_hold) {
1363 l3m = create_l3msg();
1364 l1l2l3_trace_header(p_m_mISDNport, this, L3_HOLD_REJECT_REQ, DIRECTION_OUT);
1365 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, p_m_hold?101:31); /* normal unspecified / incompatible state */
1366 add_trace("reason", NULL, "no endpoint");
1368 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_HOLD_REJECT, p_m_d_l3id, l3m);
1373 /* notify the hold of call */
1374 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1375 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_HOLD;
1376 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1377 message_put(message);
1379 /* deactivate bchannel */
1380 chan_trace_header(p_m_mISDNport, this, "CHANNEL RELEASE (hold)", DIRECTION_NONE);
1381 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1385 /* set hold state */
1388 epoint = find_epoint_id(ACTIVE_EPOINT(p_epointlist));
1389 if (epoint && p_m_d_ntmode) {
1390 if (p_settings.tout_hold)
1391 schedule_timer(&p_m_timeout, p_settings.tout_hold, 0);
1395 /* acknowledge hold */
1396 l3m = create_l3msg();
1397 l1l2l3_trace_header(p_m_mISDNport, this, L3_HOLD_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1399 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_HOLD_ACKNOWLEDGE, p_m_d_l3id, l3m);
1403 /* CC_RETRIEVE INDICATION */
1404 void Pdss1::retrieve_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1406 struct lcr_msg *message;
1407 int channel, exclusive, cause;
1410 l1l2l3_trace_header(p_m_mISDNport, this, L3_RETRIEVE_IND, DIRECTION_IN);
1411 dec_ie_channel_id(l3m, &exclusive, &channel);
1415 cause = 101; /* incompatible state */
1418 l3m = create_l3msg();
1419 l1l2l3_trace_header(p_m_mISDNport, this, L3_RETRIEVE_REJECT_REQ, DIRECTION_OUT);
1420 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, cause);
1422 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RETRIEVE_REJECT, p_m_d_l3id, l3m);
1427 /* notify the retrieve of call */
1428 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1429 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_RETRIEVAL;
1430 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1431 message_put(message);
1434 ret = channel = hunt_bchannel(channel, exclusive);
1439 ret = seize_bchannel(channel, 1);
1445 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
1447 /* set hold state */
1449 unsched_timer(&p_m_timeout);
1451 /* acknowledge retrieve */
1452 l3m = create_l3msg();
1453 l1l2l3_trace_header(p_m_mISDNport, this, L3_RETRIEVE_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1454 enc_ie_channel_id(l3m, 1, p_m_b_channel);
1456 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RETRIEVE_ACKNOWLEDGE, p_m_d_l3id, l3m);
1459 /* CC_SUSPEND INDICATION */
1460 void Pdss1::suspend_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1462 struct lcr_msg *message;
1463 class Endpoint *epoint;
1464 unsigned char callid[8];
1466 int ret = -31; /* normal, unspecified */
1468 l1l2l3_trace_header(p_m_mISDNport, this, L3_SUSPEND_IND, DIRECTION_IN);
1469 dec_ie_call_id(l3m, callid, &len);
1472 if (!ACTIVE_EPOINT(p_epointlist)) {
1474 l3m = create_l3msg();
1475 l1l2l3_trace_header(p_m_mISDNport, this, L3_SUSPEND_REJECT_REQ, DIRECTION_OUT);
1476 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1478 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SUSPEND_REJECT, p_m_d_l3id, l3m);
1485 /* check if call id is in use */
1486 epoint = epoint_first;
1488 if (epoint->ep_park) {
1489 if (epoint->ep_park_len == len)
1490 if (!memcmp(epoint->ep_park_callid, callid, len)) {
1491 ret = -84; /* call id in use */
1495 epoint = epoint->next;
1498 /* notify the hold of call */
1499 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1500 message->param.notifyinfo.notify = INFO_NOTIFY_USER_SUSPENDED;
1501 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1502 message_put(message);
1504 /* deactivate bchannel */
1505 chan_trace_header(p_m_mISDNport, this, "CHANNEL RELEASE (suspend)", DIRECTION_NONE);
1506 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1510 /* sending suspend to endpoint */
1511 while (p_epointlist) {
1512 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_SUSPEND);
1513 memcpy(message->param.parkinfo.callid, callid, sizeof(message->param.parkinfo.callid));
1514 message->param.parkinfo.len = len;
1515 message_put(message);
1517 free_epointlist(p_epointlist);
1520 /* sending SUSPEND_ACKNOWLEDGE */
1521 l3m = create_l3msg();
1522 l1l2l3_trace_header(p_m_mISDNport, this, L3_SUSPEND_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1524 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SUSPEND_ACKNOWLEDGE, p_m_d_l3id, l3m);
1526 new_state(PORT_STATE_RELEASE);
1527 trigger_work(&p_m_d_delete);
1530 /* CC_RESUME INDICATION */
1531 void Pdss1::resume_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1533 unsigned char callid[8];
1535 int channel, exclusive;
1536 class Endpoint *epoint;
1537 struct lcr_msg *message;
1540 /* process given callref */
1541 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_IND, DIRECTION_IN);
1542 add_trace("callref", "new", "0x%x", pid);
1544 /* release is case the ID is already in use */
1545 add_trace("error", NULL, "callref already in use");
1547 l3m = create_l3msg();
1548 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_REJECT_REQ, DIRECTION_OUT);
1549 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47);
1550 add_trace("reason", NULL, "callref already in use");
1552 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RESUME_REJECT, pid, l3m);
1553 new_state(PORT_STATE_RELEASE);
1554 trigger_work(&p_m_d_delete);
1558 p_m_d_ces = pid >> 16;
1561 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_IND, DIRECTION_IN);
1562 dec_ie_call_id(l3m, callid, &len);
1565 /* if blocked, release call */
1566 if (p_m_mISDNport->ifport->block) {
1574 /* channel_id (no channel is possible in message) */
1576 channel = -1; /* any channel */
1579 ret = channel = hunt_bchannel(channel, exclusive);
1583 // mode (if hdlc parked) to be done. never mind, this is almost never requested
1585 ret = seize_bchannel(channel, 1);
1589 l3m = create_l3msg();
1590 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_REJECT_REQ, DIRECTION_OUT);
1591 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1593 add_trace("reason", NULL, "port blocked");
1595 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RESUME_REJECT, p_m_d_l3id, l3m);
1596 new_state(PORT_STATE_RELEASE);
1597 trigger_work(&p_m_d_delete);
1600 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
1602 /* create endpoint */
1604 FATAL("Incoming resume but already got an endpoint.\n");
1605 ret = -85; /* no call suspended */
1606 epoint = epoint_first;
1608 if (epoint->ep_park) {
1609 ret = -83; /* suspended call exists, but this not */
1610 if (epoint->ep_park_len == len)
1611 if (!memcmp(epoint->ep_park_callid, callid, len))
1614 epoint = epoint->next;
1619 epointlist_new(epoint->ep_serial);
1620 if (!(epoint->portlist_new(p_serial, p_type, p_m_mISDNport->earlyb)))
1621 FATAL("No memory for portlist\n");
1622 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RESUME);
1623 message_put(message);
1625 /* notify the resume of call */
1626 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1627 message->param.notifyinfo.notify = INFO_NOTIFY_USER_RESUMED;
1628 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1629 message_put(message);
1631 /* sending RESUME_ACKNOWLEDGE */
1632 l3m = create_l3msg();
1633 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1634 enc_ie_channel_id(l3m, 1, p_m_b_channel);
1636 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RESUME_ACKNOWLEDGE, p_m_d_l3id, l3m);
1638 new_state(PORT_STATE_CONNECT);
1642 /* CC_FACILITY INDICATION */
1643 void Pdss1::facility_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1645 unsigned char facil[256];
1647 struct lcr_msg *message;
1649 l1l2l3_trace_header(p_m_mISDNport, this, L3_FACILITY_IND, DIRECTION_IN);
1650 dec_ie_facility(l3m, facil, &facil_len);
1657 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_FACILITY);
1658 message->param.facilityinfo.len = facil_len;
1659 memcpy(message->param.facilityinfo.data, facil, facil_len);
1660 message_put(message);
1664 /* CC_PROGRESS INDICATION */
1665 void Pdss1::progress_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1667 int coding, location, progress;
1669 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROGRESS_IND, DIRECTION_IN);
1670 dec_ie_progress(l3m, &coding, &location, &progress);
1673 if (progress >= 0) {
1674 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROGRESS);
1675 message->param.progressinfo.progress = progress;
1676 message->param.progressinfo.location = location;
1677 message_put(message);
1683 * handler for isdn connections
1684 * incoming information are parsed and sent via message to the endpoint
1686 void Pdss1::message_isdn(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1693 PERROR("Pdss1(%s) timeout without cause.\n", p_name);
1696 if (l3m->cause[0] != 5) {
1697 PERROR("Pdss1(%s) expecting timeout with timer diagnostic. (got len=%d)\n", p_name, l3m->cause[0]);
1700 timer = (l3m->cause[3]-'0')*100;
1701 timer += (l3m->cause[4]-'0')*10;
1702 timer += (l3m->cause[5]-'0');
1703 l1l2l3_trace_header(p_m_mISDNport, this, L3_TIMEOUT_IND, DIRECTION_IN);
1704 add_trace("timer", NULL, "%d", timer);
1707 t312_timeout_ind(cmd, pid, l3m);
1711 if (p_state != PORT_STATE_IDLE)
1713 setup_ind(cmd, pid, l3m);
1716 case MT_INFORMATION:
1717 information_ind(cmd, pid, l3m);
1720 case MT_SETUP_ACKNOWLEDGE:
1721 if (p_state != PORT_STATE_OUT_SETUP) {
1722 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received setup_acknowledge, but we are not in outgoing setup state, IGNORING.\n", p_name);
1725 setup_acknowledge_ind(cmd, pid, l3m);
1728 case MT_CALL_PROCEEDING:
1729 if (p_state != PORT_STATE_OUT_SETUP
1730 && p_state != PORT_STATE_OUT_OVERLAP) {
1731 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received proceeding, but we are not in outgoing setup OR overlap state, IGNORING.\n", p_name);
1734 proceeding_ind(cmd, pid, l3m);
1738 if (p_state != PORT_STATE_OUT_SETUP
1739 && p_state != PORT_STATE_OUT_OVERLAP
1740 && p_state != PORT_STATE_OUT_PROCEEDING) {
1741 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding state, IGNORING.\n", p_name);
1744 alerting_ind(cmd, pid, l3m);
1748 if (p_state != PORT_STATE_OUT_SETUP
1749 && p_state != PORT_STATE_OUT_OVERLAP
1750 && p_state != PORT_STATE_OUT_PROCEEDING
1751 && p_state != PORT_STATE_OUT_ALERTING) {
1752 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);
1755 connect_ind(cmd, pid, l3m);
1756 if (p_m_d_notify_pending) {
1757 /* send pending notify message during connect */
1758 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
1759 message_free(p_m_d_notify_pending);
1760 p_m_d_notify_pending = NULL;
1764 case MT_CONNECT_ACKNOWLEDGE:
1765 if (p_state == PORT_STATE_CONNECT_WAITING)
1766 new_state(PORT_STATE_CONNECT);
1767 if (p_m_d_notify_pending) {
1768 /* send pending notify message during connect-ack */
1769 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
1770 message_free(p_m_d_notify_pending);
1771 p_m_d_notify_pending = NULL;
1776 disconnect_ind(cmd, pid, l3m);
1780 release_ind(cmd, pid, l3m);
1783 case MT_RELEASE_COMPLETE:
1784 release_complete_ind(cmd, pid, l3m);
1788 restart_ind(cmd, pid, l3m);
1792 notify_ind(cmd, pid, l3m);
1796 hold_ind(cmd, pid, l3m);
1800 retrieve_ind(cmd, pid, l3m);
1804 suspend_ind(cmd, pid, l3m);
1808 resume_ind(cmd, pid, l3m);
1812 facility_ind(cmd, pid, l3m);
1816 progress_ind(cmd, pid, l3m);
1820 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_L3ID_IND, DIRECTION_IN);
1821 add_trace("callref", NULL, "0x%x", p_m_d_l3id);
1824 trigger_work(&p_m_d_delete);
1826 /* sending release to endpoint in case we still have an endpoint
1827 * this is because we don't get any response if a release_complete is received (or a release in release state)
1829 while(p_epointlist) { // only if not already released
1830 struct lcr_msg *message;
1831 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1832 if (p_m_d_collect_cause) {
1833 message->param.disconnectinfo.cause = p_m_d_collect_cause;
1834 message->param.disconnectinfo.location = p_m_d_collect_location;
1836 message->param.disconnectinfo.cause = CAUSE_NOUSER;
1837 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1839 message_put(message);
1841 free_epointlist(p_epointlist);
1843 new_state(PORT_STATE_RELEASE);
1848 l1l2l3_trace_header(p_m_mISDNport, this, L3_UNKNOWN_IND, DIRECTION_IN);
1849 add_trace("unhandled", "cmd", "0x%x", cmd);
1854 void Pdss1::new_state(int state)
1856 // class Endpoint *epoint;
1859 if (state == PORT_STATE_IN_OVERLAP) {
1860 if (p_m_mISDNport->ifport->tout_dialing)
1861 schedule_timer(&p_m_timeout, p_m_mISDNport->ifport->tout_dialing, 0);
1863 if (state != p_state) {
1864 unsched_timer(&p_m_timeout);
1865 if (state == PORT_STATE_IN_SETUP
1866 || state == PORT_STATE_OUT_SETUP
1867 || state == PORT_STATE_IN_OVERLAP
1868 || state == PORT_STATE_OUT_OVERLAP) {
1869 if (p_m_mISDNport->ifport->tout_setup)
1870 schedule_timer(&p_m_timeout, p_m_mISDNport->ifport->tout_setup, 0);
1872 if (state == PORT_STATE_IN_PROCEEDING
1873 || state == PORT_STATE_OUT_PROCEEDING) {
1874 if (p_m_mISDNport->ifport->tout_proceeding)
1875 schedule_timer(&p_m_timeout, p_m_mISDNport->ifport->tout_proceeding, 0);
1877 if (state == PORT_STATE_IN_ALERTING
1878 || state == PORT_STATE_OUT_ALERTING) {
1879 if (p_m_mISDNport->ifport->tout_alerting)
1880 schedule_timer(&p_m_timeout, p_m_mISDNport->ifport->tout_alerting, 0);
1883 if (state == PORT_STATE_CONNECT
1884 || state == PORT_STATE_CONNECT_WAITING) {
1885 if (p_m_mISDNport->ifport->tout_connect)
1886 schedule_timer(&p_m_timeout, p_m_mISDNport->ifport->tout_connect, 0);
1889 if (state == PORT_STATE_IN_DISCONNECT
1890 || state == PORT_STATE_OUT_DISCONNECT) {
1891 if (p_m_mISDNport->ifport->tout_disconnect)
1892 schedule_timer(&p_m_timeout, p_m_mISDNport->ifport->tout_disconnect, 0);
1896 Port::new_state(state);
1900 /* deletes only if l3id is release, otherwhise it will be triggered then */
1901 static int delete_event(struct lcr_work *work, void *instance, int index)
1903 class Pdss1 *isdnport = (class Pdss1 *)instance;
1905 if (!isdnport->p_m_d_l3id)
1913 * handles all messages from endpoint
1915 /* MESSAGE_INFORMATION */
1916 void Pdss1::message_information(unsigned int epoint_id, int message_id, union parameter *param)
1919 char *display = param->information.display;
1920 char *number = param->information.id;
1921 int max = p_m_mISDNport->ifport->dialmax;
1923 while (number[0]) { /* as long we have something to dial */
1924 if (max > (int)strlen(number) || max == 0)
1925 max = (int)strlen(number);
1927 l3m = create_l3msg();
1928 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
1929 enc_ie_called_pn(l3m, 0, 1, (unsigned char *)number, max);
1930 if ((p_m_d_ntmode || p_m_d_tespecial) && display[0]) {
1931 enc_ie_display(l3m, (unsigned char *)display);
1932 display = (char *)"";
1935 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
1943 void Pdss1::message_setup(unsigned int epoint_id, int message_id, union parameter *param)
1947 int plan, type, screen, present, reason;
1948 int plan2, type2, screen2, present2;
1949 int capability, mode, rate, coding, user, presentation, interpretation, hlc, exthlc;
1950 int channel, exclusive;
1951 struct epoint_list *epointlist;
1952 int max = p_m_mISDNport->ifport->dialmax;
1954 /* release if port is blocked */
1955 if (p_m_mISDNport->ifport->block) {
1956 struct lcr_msg *message;
1958 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1959 message->param.disconnectinfo.cause = 27; // temp. unavail.
1960 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1961 message_put(message);
1962 new_state(PORT_STATE_RELEASE);
1963 trigger_work(&p_m_d_delete);
1967 /* copy setup infos to port */
1968 memcpy(&p_callerinfo, ¶m->setup.callerinfo, sizeof(p_callerinfo));
1969 memcpy(&p_dialinginfo, ¶m->setup.dialinginfo, sizeof(p_dialinginfo));
1970 memcpy(&p_capainfo, ¶m->setup.capainfo, sizeof(p_capainfo));
1971 memcpy(&p_redirinfo, ¶m->setup.redirinfo, sizeof(p_redirinfo));
1972 /* screen outgoing caller id */
1973 do_screen(1, p_callerinfo.id, sizeof(p_callerinfo.id), &p_callerinfo.ntype, &p_callerinfo.present, p_m_mISDNport->ifport->interface);
1974 do_screen(1, p_callerinfo.id2, sizeof(p_callerinfo.id2), &p_callerinfo.ntype2, &p_callerinfo.present2, p_m_mISDNport->ifport->interface);
1976 /* only display at connect state: this case happens if endpoint is in connected mode */
1977 if (p_state==PORT_STATE_CONNECT) {
1978 if (p_type!=PORT_TYPE_DSS1_NT_OUT
1979 && p_type!=PORT_TYPE_DSS1_NT_IN)
1981 if (p_callerinfo.display[0]) {
1982 /* sending information */
1983 l3m = create_l3msg();
1984 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
1985 if (p_m_d_ntmode || p_m_d_tespecial)
1986 enc_ie_display(l3m, (unsigned char *)p_callerinfo.display);
1988 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
1993 /* attach only if not already */
1994 epointlist = p_epointlist;
1996 if (epointlist->epoint_id == epoint_id)
1998 epointlist = epointlist->next;
2001 epointlist_new(epoint_id);
2005 if (p_m_b_channel) {
2006 channel = p_m_b_channel;
2007 exclusive = p_m_b_exclusive;
2009 channel = CHANNEL_ANY;
2010 /* nt-port with no channel, not reserverd */
2011 if (!p_m_b_channel && !p_m_b_reserve && p_type==PORT_TYPE_DSS1_NT_OUT)
2012 channel = CHANNEL_NO;
2015 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_REQ, DIRECTION_OUT);
2016 #ifdef OLD_MT_ASSIGN
2017 /* see MT_ASSIGN notes at do_layer3() */
2019 ret = p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_ASSIGN, 0, NULL);
2020 if (mt_assign_pid == 0 || ret < 0)
2021 p_m_d_l3id = mt_assign_pid;
2024 p_m_d_l3id = request_new_pid(p_m_mISDNport->ml3);
2025 if (p_m_d_l3id == MISDN_PID_NONE)
2028 struct lcr_msg *message;
2030 add_trace("callref", NULL, "no free id");
2032 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2033 message->param.disconnectinfo.cause = 47;
2034 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2035 message_put(message);
2036 new_state(PORT_STATE_RELEASE);
2037 trigger_work(&p_m_d_delete);
2040 #ifdef OLD_MT_ASSIGN
2041 p_m_d_l3id = mt_assign_pid;
2044 add_trace("callref", "new", "0x%x", p_m_d_l3id);
2047 /* preparing setup message */
2048 l3m = create_l3msg();
2049 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_REQ, DIRECTION_OUT);
2050 /* channel information */
2051 if (p_m_d_ntmode || channel != CHANNEL_ANY) /* only omit channel id in te-mode/any channel */
2052 enc_ie_channel_id(l3m, exclusive, channel);
2053 /* caller information */
2055 switch (p_callerinfo.ntype) {
2056 case INFO_NTYPE_UNKNOWN:
2059 case INFO_NTYPE_INTERNATIONAL:
2062 case INFO_NTYPE_NATIONAL:
2065 case INFO_NTYPE_SUBSCRIBER:
2068 default: /* INFO_NTYPE_NOTPRESENT */
2072 switch (p_callerinfo.screen) {
2073 case INFO_SCREEN_USER:
2076 case INFO_SCREEN_USER_VERIFIED_PASSED:
2079 case INFO_SCREEN_USER_VERIFIED_FAILED:
2082 default: /* INFO_SCREEN_NETWORK */
2086 switch (p_callerinfo.present) {
2087 case INFO_PRESENT_ALLOWED:
2090 case INFO_PRESENT_RESTRICTED:
2093 default: /* INFO_PRESENT_NOTAVAIL */
2097 /* caller information 2 */
2099 switch (p_callerinfo.ntype2) {
2100 case INFO_NTYPE_UNKNOWN:
2103 case INFO_NTYPE_INTERNATIONAL:
2106 case INFO_NTYPE_NATIONAL:
2109 case INFO_NTYPE_SUBSCRIBER:
2112 default: /* INFO_NTYPE_NOTPRESENT */
2116 switch (p_callerinfo.screen2) {
2117 case INFO_SCREEN_USER:
2120 case INFO_SCREEN_USER_VERIFIED_PASSED:
2123 case INFO_SCREEN_USER_VERIFIED_FAILED:
2126 default: /* INFO_SCREEN_NETWORK */
2130 switch (p_callerinfo.present2) {
2131 case INFO_PRESENT_ALLOWED:
2134 case INFO_PRESENT_RESTRICTED:
2137 default: /* INFO_PRESENT_NOTAVAIL */
2142 enc_ie_calling_pn(l3m, type, plan, present, screen, (unsigned char *)p_callerinfo.id, type2, plan2, present2, screen2, (unsigned char *)p_callerinfo.id2);
2143 /* dialing information */
2144 if (p_dialinginfo.id[0]) { /* only if we have something to dial */
2145 if (max > (int)strlen(p_dialinginfo.id) || max == 0)
2146 max = (int)strlen(p_dialinginfo.id);
2147 enc_ie_called_pn(l3m, 0, 1, (unsigned char *)p_dialinginfo.id, max);
2148 SCPY(p_m_d_queue, p_dialinginfo.id + max);
2151 if (p_dialinginfo.keypad[0])
2152 enc_ie_keypad(l3m, (unsigned char *)p_dialinginfo.keypad);
2153 /* sending complete */
2154 if (p_dialinginfo.sending_complete)
2155 enc_ie_complete(l3m, 1);
2156 /* sending user-user */
2157 if (param->setup.useruser.len) {
2158 enc_ie_useruser(l3m, param->setup.useruser.protocol, param->setup.useruser.data, param->setup.useruser.len);
2160 /* redirecting number */
2162 switch (p_redirinfo.ntype) {
2163 case INFO_NTYPE_UNKNOWN:
2166 case INFO_NTYPE_INTERNATIONAL:
2169 case INFO_NTYPE_NATIONAL:
2172 case INFO_NTYPE_SUBSCRIBER:
2175 default: /* INFO_NTYPE_NOTPRESENT */
2179 switch (p_redirinfo.screen) {
2180 case INFO_SCREEN_USER:
2183 case INFO_SCREEN_USER_VERIFIED_PASSED:
2186 case INFO_SCREEN_USER_VERIFIED_FAILED:
2189 default: /* INFO_SCREE_NETWORK */
2193 switch (p_redirinfo.reason) {
2194 case INFO_REDIR_BUSY:
2197 case INFO_REDIR_NORESPONSE:
2200 case INFO_REDIR_UNCONDITIONAL:
2203 case INFO_REDIR_CALLDEFLECT:
2206 case INFO_REDIR_OUTOFORDER:
2209 default: /* INFO_REDIR_UNKNOWN */
2213 switch (p_redirinfo.present) {
2214 case INFO_PRESENT_ALLOWED:
2217 case INFO_PRESENT_RESTRICTED:
2220 default: /* INFO_PRESENT_NOTAVAIL */
2224 /* sending redirecting number only in ntmode */
2225 if (type >= 0 && (p_m_d_ntmode || p_m_d_tespecial))
2226 enc_ie_redir_nr(l3m, type, plan, present, screen, reason, (unsigned char *)p_redirinfo.id);
2227 /* bearer capability */
2228 //printf("hlc=%d\n",p_capainfo.hlc);
2230 capability = p_capainfo.bearer_capa;
2231 mode = p_capainfo.bearer_mode;
2232 rate = (mode==INFO_BMODE_CIRCUIT)?0x10:0x00;
2233 switch (p_capainfo.bearer_info1) {
2234 case INFO_INFO1_NONE:
2238 user = p_capainfo.bearer_info1 & 0x7f;
2241 enc_ie_bearer(l3m, coding, capability, mode, rate, -1, user);
2243 if (p_capainfo.hlc) {
2247 hlc = p_capainfo.hlc & 0x7f;
2249 if (p_capainfo.exthlc)
2250 exthlc = p_capainfo.exthlc & 0x7f;
2251 enc_ie_hlc(l3m, coding, interpretation, presentation, hlc, exthlc);
2255 if (p_callerinfo.display[0] && (p_m_d_ntmode || p_m_d_tespecial))
2256 enc_ie_display(l3m, (unsigned char *)p_callerinfo.display);
2257 /* nt-mode: CNIP (calling name identification presentation) */
2258 // if (p_callerinfo.name[0] && (p_m_d_ntmode || p_m_d_tespecial))
2259 // enc_facility_centrex(&setup->FACILITY, dmsg, (unsigned char *)p_callerinfo.name, 1);
2262 /* send setup message now */
2263 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SETUP, p_m_d_l3id, l3m);
2265 new_state(PORT_STATE_OUT_SETUP);
2268 /* MESSAGE_FACILITY */
2269 void Pdss1::message_facility(unsigned int epoint_id, int message_id, union parameter *param)
2273 /* facility will not be sent to external lines */
2274 if (!p_m_d_ntmode && !p_m_d_tespecial)
2277 /* sending facility */
2278 l3m = create_l3msg();
2279 l1l2l3_trace_header(p_m_mISDNport, this, L3_FACILITY_REQ, DIRECTION_OUT);
2280 enc_ie_facility(l3m, (unsigned char *)param->facilityinfo.data, param->facilityinfo.len);
2282 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_FACILITY, p_m_d_l3id, l3m);
2285 /* MESSAGE_NOTIFY */
2286 void Pdss1::message_notify(unsigned int epoint_id, int message_id, union parameter *param)
2290 int plan = 0, type = -1, present = 0;
2292 if (p_m_mISDNport->ifport->nonotify) {
2293 l1l2l3_trace_header(p_m_mISDNport, this, L3_NOTIFY_REQ, DIRECTION_OUT);
2294 add_trace("info", NULL, "blocked by config");
2299 // printf("if = %d\n", param->notifyinfo.notify);
2300 if (param->notifyinfo.notify>INFO_NOTIFY_NONE)
2301 notify = param->notifyinfo.notify & 0x7f;
2306 switch (param->notifyinfo.ntype) {
2307 case INFO_NTYPE_UNKNOWN:
2310 case INFO_NTYPE_INTERNATIONAL:
2313 case INFO_NTYPE_NATIONAL:
2316 case INFO_NTYPE_SUBSCRIBER:
2319 default: /* INFO_NTYPE_UNKNOWN */
2323 switch (param->notifyinfo.present) {
2324 case INFO_PRESENT_ALLOWED:
2327 case INFO_PRESENT_RESTRICTED:
2330 default: /* INFO_PRESENT_NOTAVAIL */
2336 if (notify<0 && !param->notifyinfo.display[0]) {
2337 /* nothing to notify, nothing to display */
2342 if (p_state!=PORT_STATE_CONNECT && p_state!=PORT_STATE_IN_PROCEEDING && p_state!=PORT_STATE_IN_ALERTING) {
2343 /* queue notification */
2344 if (p_m_d_notify_pending)
2345 message_free(p_m_d_notify_pending);
2346 p_m_d_notify_pending = message_create(ACTIVE_EPOINT(p_epointlist), p_serial, EPOINT_TO_PORT, message_id);
2347 memcpy(&p_m_d_notify_pending->param, param, sizeof(union parameter));
2349 /* sending notification */
2350 l3m = create_l3msg();
2351 l1l2l3_trace_header(p_m_mISDNport, this, L3_NOTIFY_REQ, DIRECTION_OUT);
2352 enc_ie_notify(l3m, notify);
2353 /* sending redirection number only in ntmode */
2354 if (type >= 0 && (p_m_d_ntmode || p_m_d_tespecial))
2355 enc_ie_redir_dn(l3m, type, plan, present, (unsigned char *)param->notifyinfo.id);
2356 if (param->notifyinfo.display[0] && (p_m_d_ntmode || p_m_d_tespecial))
2357 enc_ie_display(l3m, (unsigned char *)param->notifyinfo.display);
2359 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_NOTIFY, p_m_d_l3id, l3m);
2361 } else if (p_m_d_ntmode || p_m_d_tespecial) {
2362 /* sending information */
2363 l3m = create_l3msg();
2364 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
2365 enc_ie_display(l3m, (unsigned char *)param->notifyinfo.display);
2367 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
2371 /* MESSAGE_OVERLAP */
2372 void Pdss1::message_overlap(unsigned int epoint_id, int message_id, union parameter *param)
2376 /* in case of sending complete, we proceed */
2377 if (p_dialinginfo.sending_complete) {
2378 PDEBUG(DEBUG_ISDN, "sending proceeding instead of setup_acknowledge, because address is complete.\n");
2379 message_proceeding(epoint_id, message_id, param);
2383 /* sending setup_acknowledge */
2384 l3m = create_l3msg();
2385 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_ACKNOWLEDGE_REQ, DIRECTION_OUT);
2386 /* channel information */
2387 if (p_state == PORT_STATE_IN_SETUP)
2388 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2389 /* progress information */
2390 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2391 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2392 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2393 if (p_m_mISDNport->tones)
2394 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2396 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SETUP_ACKNOWLEDGE, p_m_d_l3id, l3m);
2398 new_state(PORT_STATE_IN_OVERLAP);
2401 /* MESSAGE_PROCEEDING */
2402 void Pdss1::message_proceeding(unsigned int epoint_id, int message_id, union parameter *param)
2406 /* sending proceeding */
2407 l3m = create_l3msg();
2408 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2409 /* channel information */
2410 if (p_state == PORT_STATE_IN_SETUP)
2411 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2412 /* progress information */
2413 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2414 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2415 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2416 if (p_m_mISDNport->tones)
2417 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2419 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2421 new_state(PORT_STATE_IN_PROCEEDING);
2424 /* MESSAGE_ALERTING */
2425 void Pdss1::message_alerting(unsigned int epoint_id, int message_id, union parameter *param)
2429 /* NT-MODE in setup state we must send PROCEEDING first */
2430 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP) {
2431 /* sending proceeding */
2432 l3m = create_l3msg();
2433 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2434 /* channel information */
2435 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2436 /* progress information */
2437 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2438 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2439 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2440 if (p_m_mISDNport->tones)
2441 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2443 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2444 new_state(PORT_STATE_IN_PROCEEDING);
2447 /* sending alerting */
2448 l3m = create_l3msg();
2449 l1l2l3_trace_header(p_m_mISDNport, this, L3_ALERTING_REQ, DIRECTION_OUT);
2450 /* channel information */
2451 if (p_state == PORT_STATE_IN_SETUP)
2452 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2453 /* progress information */
2454 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2455 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2456 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2457 if (p_m_mISDNport->tones)
2458 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2460 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_ALERTING, p_m_d_l3id, l3m);
2462 new_state(PORT_STATE_IN_ALERTING);
2465 /* MESSAGE_CONNECT */
2466 void Pdss1::message_connect(unsigned int epoint_id, int message_id, union parameter *param)
2469 int type, plan, present, screen;
2470 class Endpoint *epoint;
2471 time_t current_time;
2473 /* NT-MODE in setup state we must send PROCEEDING first */
2474 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP) {
2475 /* sending proceeding */
2476 l3m = create_l3msg();
2477 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2478 /* channel information */
2479 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2481 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2482 new_state(PORT_STATE_IN_PROCEEDING);
2485 /* copy connected information */
2486 memcpy(&p_connectinfo, ¶m->connectinfo, sizeof(p_connectinfo));
2487 /* screen outgoing caller id */
2488 do_screen(1, p_connectinfo.id, sizeof(p_connectinfo.id), &p_connectinfo.ntype, &p_connectinfo.present, p_m_mISDNport->ifport->interface);
2490 /* only display at connect state */
2491 if (p_state == PORT_STATE_CONNECT)
2492 if (p_connectinfo.display[0]) {
2493 /* sending information */
2494 l3m = create_l3msg();
2495 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
2496 if (p_m_d_ntmode || p_m_d_tespecial)
2497 enc_ie_display(l3m, (unsigned char *)p_connectinfo.display);
2499 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
2503 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) {
2504 /* connect command only possible in setup, proceeding or alerting state */
2508 /* preparing connect message */
2509 l3m = create_l3msg();
2510 l1l2l3_trace_header(p_m_mISDNport, this, L3_CONNECT_REQ, DIRECTION_OUT);
2511 /* connect information */
2513 switch (p_connectinfo.ntype) {
2514 case INFO_NTYPE_UNKNOWN:
2517 case INFO_NTYPE_INTERNATIONAL:
2520 case INFO_NTYPE_NATIONAL:
2523 case INFO_NTYPE_SUBSCRIBER:
2526 default: /* INFO_NTYPE_NOTPRESENT */
2530 switch (param->connectinfo.screen) {
2531 case INFO_SCREEN_USER:
2534 case INFO_SCREEN_USER_VERIFIED_PASSED:
2537 case INFO_SCREEN_USER_VERIFIED_FAILED:
2540 default: /* INFO_SCREE_NETWORK */
2544 switch (p_connectinfo.present) {
2545 case INFO_PRESENT_ALLOWED:
2548 case INFO_PRESENT_RESTRICTED:
2551 default: /* INFO_PRESENT_NOTAVAIL */
2556 enc_ie_connected_pn(l3m, type, plan, present, screen, (unsigned char *)p_connectinfo.id);
2558 if (p_connectinfo.display[0] && (p_m_d_ntmode || p_m_d_tespecial))
2559 enc_ie_display(l3m, (unsigned char *)p_connectinfo.display);
2560 /* nt-mode: CONP (connected name identification presentation) */
2561 // if (p_connectinfo.name[0] && (p_m_d_ntmode || p_m_d_tespecial))
2562 // enc_facility_centrex(&connect->FACILITY, dmsg, (unsigned char *)p_connectinfo.name, 0);
2564 if (p_m_d_ntmode || p_m_d_tespecial) {
2565 epoint = find_epoint_id(epoint_id);
2566 time(¤t_time);
2567 enc_ie_date(l3m, current_time, p_settings.no_seconds);
2570 /* finally send message */
2571 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CONNECT, p_m_d_l3id, l3m);
2574 new_state(PORT_STATE_CONNECT);
2576 new_state(PORT_STATE_CONNECT_WAITING);
2580 /* MESSAGE_DISCONNECT */
2581 void Pdss1::message_disconnect(unsigned int epoint_id, int message_id, union parameter *param)
2584 struct lcr_msg *message;
2587 /* we reject during incoming setup when we have no tones. also if we are in outgoing setup state */
2588 // if ((p_state==PORT_STATE_IN_SETUP && !p_m_mISDNport->tones)
2589 if (/* ||*/ p_state==PORT_STATE_OUT_SETUP) {
2590 /* sending release to endpoint */
2591 while(p_epointlist) {
2592 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
2593 memcpy(&message->param, param, sizeof(union parameter));
2594 message_put(message);
2596 free_epointlist(p_epointlist);
2598 /* sending release */
2599 l3m = create_l3msg();
2600 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
2602 enc_ie_cause(l3m, (!p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_REMOTE:param->disconnectinfo.location, param->disconnectinfo.cause);
2604 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
2605 new_state(PORT_STATE_RELEASE);
2606 trigger_work(&p_m_d_delete);
2610 /* workarround: NT-MODE in setup state we must send PROCEEDING first to make it work */
2611 if (p_state==PORT_STATE_IN_SETUP) {
2612 /* sending proceeding */
2613 l3m = create_l3msg();
2614 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2615 /* channel information */
2616 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2617 /* progress information */
2618 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2619 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2620 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2621 if (p_m_mISDNport->tones)
2622 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2624 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2625 new_state(PORT_STATE_IN_PROCEEDING);
2628 /* sending disconnect */
2629 l3m = create_l3msg();
2630 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_REQ, DIRECTION_OUT);
2631 /* progress information */
2632 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2633 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2634 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2635 if (p_m_mISDNport->tones)
2636 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2638 enc_ie_cause(l3m, (!p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_REMOTE:param->disconnectinfo.location, param->disconnectinfo.cause);
2640 if (param->disconnectinfo.display[0])
2641 p = param->disconnectinfo.display;
2642 if (p) if (*p && (p_m_d_ntmode || p_m_d_tespecial))
2643 enc_ie_display(l3m, (unsigned char *)p);
2645 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_DISCONNECT, p_m_d_l3id, l3m);
2646 new_state(PORT_STATE_OUT_DISCONNECT);
2649 /* MESSAGE_RELEASE */
2650 void Pdss1::message_release(unsigned int epoint_id, int message_id, union parameter *param)
2653 class Endpoint *epoint;
2657 * if we are on incoming call setup, we may reject by sending a release_complete
2658 * also on outgoing call setup, we send a release complete, BUT this is not conform. (i don't know any other way)
2660 if (p_state==PORT_STATE_IN_SETUP
2661 || p_state==PORT_STATE_OUT_SETUP) {
2662 //#warning remove me
2663 //PDEBUG(DEBUG_LOG, "JOLLY sending release complete %d\n", p_serial);
2664 /* sending release complete */
2665 l3m = create_l3msg();
2666 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_REQ, DIRECTION_OUT);
2668 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2670 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
2671 new_state(PORT_STATE_RELEASE);
2673 free_epointid(epoint_id);
2674 // wait for callref to be released
2678 * we may only release during incoming disconnect state.
2679 * this means that the endpoint doesnt require audio anymore
2681 if (p_state == PORT_STATE_IN_DISCONNECT
2682 || p_state == PORT_STATE_OUT_DISCONNECT
2683 || param->disconnectinfo.force) {
2684 /* sending release */
2685 l3m = create_l3msg();
2686 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_REQ, DIRECTION_OUT);
2688 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2690 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE, p_m_d_l3id, l3m);
2691 new_state(PORT_STATE_RELEASE);
2693 free_epointid(epoint_id);
2694 // wait for callref to be released
2700 wirklich erst proceeding?:
2701 /* NT-MODE in setup state we must send PROCEEDING first */
2702 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP) {
2703 CALL_PROCEEDING_t *proceeding;
2705 /* sending proceeding */
2706 l3m = create_l3msg();
2707 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2708 /* channel information */
2709 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2710 /* progress information */
2711 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2712 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2713 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2714 if (p_m_mISDNport->tones)
2715 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2717 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2721 /* sending disconnect */
2722 l3m = create_l3msg();
2723 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_REQ, DIRECTION_OUT);
2724 /* progress information */
2725 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2726 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2727 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2728 if (p_m_mISDNport->tones)
2729 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2731 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2733 epoint = find_epoint_id(epoint_id);
2734 if (param->disconnectinfo.display[0])
2735 p = param->disconnectinfo.display;
2736 if (p) if (*p && (p_m_d_ntmode || p_m_d_tespecial))
2737 enc_ie_display(l3m, (unsigned char *)p);
2739 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_DISCONNECT, p_m_d_l3id, l3m);
2740 new_state(PORT_STATE_OUT_DISCONNECT);
2742 free_epointid(epoint_id);
2743 // wait for release and callref to be released
2744 //#warning remove me
2745 //PDEBUG(DEBUG_LOG, "JOLLY sending disconnect %d\n", p_serial);
2750 * endpoint sends messages to the port
2752 int Pdss1::message_epoint(unsigned int epoint_id, int message_id, union parameter *param)
2754 if (PmISDN::message_epoint(epoint_id, message_id, param))
2757 switch(message_id) {
2758 case MESSAGE_INFORMATION: /* overlap dialing */
2759 if (p_type==PORT_TYPE_DSS1_NT_OUT
2760 && p_state!=PORT_STATE_OUT_OVERLAP
2761 && p_state!=PORT_STATE_CONNECT
2762 && p_state!=PORT_STATE_OUT_DISCONNECT
2763 && p_state!=PORT_STATE_IN_DISCONNECT) {
2766 if (p_type==PORT_TYPE_DSS1_TE_OUT
2767 && p_state!=PORT_STATE_OUT_OVERLAP
2768 && p_state!=PORT_STATE_OUT_PROCEEDING
2769 && p_state!=PORT_STATE_OUT_ALERTING
2770 && p_state!=PORT_STATE_CONNECT
2771 && p_state!=PORT_STATE_OUT_DISCONNECT
2772 && p_state!=PORT_STATE_IN_DISCONNECT) {
2775 if ((p_type==PORT_TYPE_DSS1_NT_IN || p_type==PORT_TYPE_DSS1_TE_IN)
2776 && p_state!=PORT_STATE_IN_OVERLAP
2777 && p_state!=PORT_STATE_IN_PROCEEDING
2778 && p_state!=PORT_STATE_IN_ALERTING
2779 && p_state!=PORT_STATE_CONNECT
2780 && p_state!=PORT_STATE_CONNECT_WAITING
2781 && p_state!=PORT_STATE_OUT_DISCONNECT
2782 && p_state!=PORT_STATE_IN_DISCONNECT) {
2785 message_information(epoint_id, message_id, param);
2788 case MESSAGE_SETUP: /* dial-out command received from epoint */
2789 if (p_state!=PORT_STATE_IDLE
2790 && p_state!=PORT_STATE_CONNECT) {
2791 PERROR("Pdss1(%s) ignoring setup because isdn port is not in idle state (or connected for sending display info).\n", p_name);
2794 if (p_epointlist && p_state==PORT_STATE_IDLE)
2795 FATAL("Pdss1(%s): epoint pointer is set in idle state, how bad!!\n", p_name);
2796 message_setup(epoint_id, message_id, param);
2799 case MESSAGE_NOTIFY: /* display and notifications */
2800 message_notify(epoint_id, message_id, param);
2803 case MESSAGE_FACILITY: /* facility message */
2804 message_facility(epoint_id, message_id, param);
2807 case MESSAGE_OVERLAP: /* more information is needed */
2808 if (p_state!=PORT_STATE_IN_SETUP) {
2811 message_overlap(epoint_id, message_id, param);
2814 case MESSAGE_PROCEEDING: /* call of endpoint is proceeding */
2815 if (p_state!=PORT_STATE_IN_SETUP
2816 && p_state!=PORT_STATE_IN_OVERLAP) {
2819 message_proceeding(epoint_id, message_id, param);
2820 if (p_m_d_notify_pending) {
2821 /* send pending notify message during connect */
2822 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2823 message_free(p_m_d_notify_pending);
2824 p_m_d_notify_pending = NULL;
2828 case MESSAGE_ALERTING: /* call of endpoint is ringing */
2829 if (p_state!=PORT_STATE_IN_SETUP
2830 && p_state!=PORT_STATE_IN_OVERLAP
2831 && p_state!=PORT_STATE_IN_PROCEEDING) {
2834 message_alerting(epoint_id, message_id, param);
2835 if (p_m_d_notify_pending) {
2836 /* send pending notify message during connect */
2837 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2838 message_free(p_m_d_notify_pending);
2839 p_m_d_notify_pending = NULL;
2843 case MESSAGE_CONNECT: /* call of endpoint is connected */
2844 if (p_state!=PORT_STATE_IN_SETUP
2845 && p_state!=PORT_STATE_IN_OVERLAP
2846 && p_state!=PORT_STATE_IN_PROCEEDING
2847 && p_state!=PORT_STATE_IN_ALERTING
2848 && !(p_state==PORT_STATE_CONNECT && p_m_d_ntmode)) {
2851 message_connect(epoint_id, message_id, param);
2852 if (p_m_d_notify_pending) {
2853 /* send pending notify message during connect */
2854 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2855 message_free(p_m_d_notify_pending);
2856 p_m_d_notify_pending = NULL;
2860 case MESSAGE_DISCONNECT: /* call has been disconnected */
2861 if (p_state!=PORT_STATE_IN_SETUP
2862 && p_state!=PORT_STATE_IN_OVERLAP
2863 && p_state!=PORT_STATE_IN_PROCEEDING
2864 && p_state!=PORT_STATE_IN_ALERTING
2865 && p_state!=PORT_STATE_OUT_SETUP
2866 && p_state!=PORT_STATE_OUT_OVERLAP
2867 && p_state!=PORT_STATE_OUT_PROCEEDING
2868 && p_state!=PORT_STATE_OUT_ALERTING
2869 && p_state!=PORT_STATE_CONNECT
2870 && p_state!=PORT_STATE_CONNECT_WAITING) {
2873 message_disconnect(epoint_id, message_id, param);
2876 case MESSAGE_RELEASE: /* release isdn port */
2877 if (p_state==PORT_STATE_RELEASE) {
2880 message_release(epoint_id, message_id, param);
2884 PERROR("Pdss1(%s) isdn port with (caller id %s) received a wrong message: %d\n", p_name, p_callerinfo.id, message_id);
2893 * data from isdn-stack (layer-3) to pbx (port class)
2895 int stack2manager(struct mISDNport *mISDNport, unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
2901 PDEBUG(DEBUG_ISDN, "cmd(0x%x) pid(0x%x)\n", cmd, pid);
2904 PDEBUG(DEBUG_ISDN, "ignoring dummy process from phone.\n");
2908 /* find Port object of type ISDN */
2912 if ((port->p_type & PORT_CLASS_mISDN_MASK) == PORT_CLASS_DSS1) {
2913 pdss1 = (class Pdss1 *)port;
2914 /* check out correct stack and id */
2915 if (pdss1->p_m_mISDNport == mISDNport) {
2916 if (pdss1->p_m_d_l3id & MISDN_PID_CR_FLAG) {
2917 /* local callref, so match value only */
2918 if ((pdss1->p_m_d_l3id & MISDN_PID_CRVAL_MASK) == (pid & MISDN_PID_CRVAL_MASK))
2921 /* remote callref, ref + channel id */
2922 if (pdss1->p_m_d_l3id == pid)
2930 /* aktueller prozess */
2932 if (cmd == MT_ASSIGN) {
2933 /* stack gives us new layer 3 id (during connect) */
2934 l1l2l3_trace_header(mISDNport, pdss1, L3_NEW_L3ID_IND, DIRECTION_IN);
2935 add_trace("callref", "old", "0x%x", pdss1->p_m_d_l3id);
2936 /* nt-library now gives us a new id via CC_SETUP_CONFIRM */
2937 if ((pdss1->p_m_d_l3id&MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER)
2938 PERROR(" strange setup-procid 0x%x\n", pdss1->p_m_d_l3id);
2939 pdss1->p_m_d_l3id = pid;
2940 if (port->p_state == PORT_STATE_CONNECT)
2941 pdss1->p_m_d_ces = pid >> 16;
2942 add_trace("callref", "new", "0x%x", pdss1->p_m_d_l3id);
2946 /* if process id is master process, but a child disconnects */
2947 if (mISDNport->ntmode
2948 && (pid & MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER
2949 && (pdss1->p_m_d_l3id & MISDN_PID_CRTYPE_MASK) == MISDN_PID_MASTER) {
2950 if (cmd == MT_DISCONNECT
2951 || cmd == MT_RELEASE) {
2952 /* send special indication for child disconnect */
2953 pdss1->disconnect_ind_i(cmd, pid, l3m);
2956 if (cmd == MT_RELEASE_COMPLETE)
2959 /* if we have child pid and got different child pid message, ignore */
2960 if (mISDNport->ntmode
2961 && (pid & MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER
2962 && (pdss1->p_m_d_l3id & MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER
2963 && pid != pdss1->p_m_d_l3id)
2966 /* process message */
2967 pdss1->message_isdn(cmd, pid, l3m);
2974 /* creating port object, transparent until setup with hdlc */
2975 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
2976 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0, B_MODE_TRANSPARENT)))
2978 FATAL("Cannot create Port instance.\n");
2979 pdss1->message_isdn(cmd, pid, l3m);
2983 /* creating port object, transparent until setup with hdlc */
2984 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
2985 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0, B_MODE_TRANSPARENT)))
2986 FATAL("Cannot create Port instance.\n");
2987 pdss1->message_isdn(cmd, pid, l3m);
2991 PDEBUG(DEBUG_ISDN, "unused call ref released (l3id=0x%x)\n", pid);
2994 case MT_RELEASE_COMPLETE:
2995 PERROR("must be ignored by stack, not sent to app\n");
2999 // facility als broadcast
3003 PERROR("unhandled message: cmd(0x%x) pid(0x%x)\n", cmd, pid);
3006 if (port->p_type == PORT_TYPE_DSS1_NT_IN || port->p_type == PORT_TYPE_DSS1_NT_OUT) {
3007 pdss1 = (class Pdss1 *)port;
3008 /* check out correct stack */
3009 if (pdss1->p_m_mISDNport == mISDNport)
3010 /* check out correct id */
3011 PERROR("unhandled message: pid=%x is not associated with port-dinfo=%x\n", pid, pdss1->p_m_d_l3id);