1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
10 \*****************************************************************************/
15 //#include <sys/socket.h>
18 #include <mISDN/q931.h>
19 extern unsigned int mt_assign_pid;
23 static int delete_event(struct lcr_work *work, void *instance, int index);
28 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)
30 p_callerinfo.itype = (mISDNport->ifport->interface->extension)?INFO_ITYPE_ISDN_EXTENSION:INFO_ITYPE_ISDN;
31 p_m_d_ntmode = mISDNport->ntmode;
32 p_m_d_tespecial = mISDNport->tespecial;
34 memset(&p_m_d_delete, 0, sizeof(p_m_d_delete));
35 add_work(&p_m_d_delete, delete_event, this, 0);
37 p_m_d_queue[0] = '\0';
38 p_m_d_notify_pending = NULL;
39 p_m_d_collect_cause = 0;
40 p_m_d_collect_location = 0;
42 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);
51 del_work(&p_m_d_delete);
53 /* remove queued message */
54 if (p_m_d_notify_pending)
55 message_free(p_m_d_notify_pending);
60 * create layer 3 message
62 static struct l3_msg *create_l3msg(void)
70 FATAL("Cannot allocate memory, system overloaded.\n");
71 exit(0); // make gcc happy
75 * if we received a first reply to the setup message,
76 * we will check if we have now channel information
77 * return: <0: error, call is released, -cause is given
78 * 0: ok, nothing to do
80 int Pdss1::received_first_reply_to_setup(unsigned int cmd, int channel, int exclusive)
85 /* correct exclusive to 0, if no explicit channel was given */
86 if (exclusive<0 || channel<=0)
90 if (p_m_b_channel && p_m_b_exclusive) {
91 /*** we gave an exclusive channel (or if we are done) ***/
93 /* if not first reply, we are done */
94 if (p_state != PORT_STATE_OUT_SETUP)
97 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
98 add_trace("channel", "request", "%d (forced)", p_m_b_channel);
99 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
101 /* if give channel not accepted or not equal */
102 if (channel!=-1 && p_m_b_channel!=channel) {
103 add_trace("conclusion", NULL, "forced channel not accepted");
109 add_trace("conclusion", NULL, "channel was accepted");
110 add_trace("connect", "channel", "%d", p_m_b_channel);
113 /* activate our exclusive channel */
114 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
117 /*** we gave a non-exclusive channel ***/
119 /* if not first reply, we are done */
120 if (p_state != PORT_STATE_OUT_SETUP)
123 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
124 add_trace("channel", "request", "%d (suggest)", p_m_b_channel);
125 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
127 /* if channel was accepted as given */
128 if (channel==-1 || p_m_b_channel==channel) {
129 add_trace("conclusion", NULL, "channel was accepted as given");
130 add_trace("connect", "channel", "%d", p_m_b_channel);
132 p_m_b_exclusive = 1; // we are done
133 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
137 /* if channel value is faulty */
139 add_trace("conclusion", NULL, "illegal reply");
141 ret = -111; // protocol error
145 /* if channel was not accepted, try to get it */
146 ret = seize_bchannel(channel, 1); // exclusively
147 add_trace("channel", "available", ret<0?"no":"yes");
149 add_trace("conclusion", NULL, "replied channel not available");
153 add_trace("conclusion", NULL, "replied channel accepted");
154 add_trace("connect", "channel", "%d", p_m_b_channel);
157 /* activate channel given by remote */
158 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
161 /*** we sent 'any channel acceptable' ***/
163 /* if not first reply, we are done */
164 if (p_state != PORT_STATE_OUT_SETUP)
167 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
168 add_trace("channel", "request", "any");
169 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
170 /* if no channel was replied */
172 add_trace("conclusion", NULL, "no channel, protocol error");
174 ret = -111; // protocol error
178 /* we will see, if our received channel is available */
179 ret = seize_bchannel(channel, 1); // exclusively
180 add_trace("channel", "available", ret<0?"no":"yes");
182 add_trace("conclusion", NULL, "replied channel not available");
186 add_trace("conclusion", NULL, "replied channel accepted");
187 add_trace("connect", "channel", "%d", p_m_b_channel);
190 /* activate channel given by remote */
191 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
193 /*** we sent 'no channel available' ***/
195 /* if not the first reply, but a connect, we are forced */
196 if (cmd==MT_CONNECT && p_state!=PORT_STATE_OUT_SETUP) {
197 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (connect)", DIRECTION_NONE);
198 add_trace("channel", "request", "no-channel");
199 add_trace("channel", "reply", (channel>=0)?"%d%s":"(none)", channel, exclusive?" (forced)":"");
201 goto use_from_connect;
203 ret = seize_bchannel(CHANNEL_ANY, 0); // any channel
204 add_trace("channel", "available", ret<0?"no":"yes");
206 add_trace("conclusion", NULL, "no channel available during call-waiting");
210 add_trace("conclusion", NULL, "using channel %d", p_m_b_channel);
211 add_trace("connect", "channel", "%d", p_m_b_channel);
213 p_m_b_exclusive = 1; // we are done
215 /* activate channel given by remote */
216 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
220 /* if not first reply, we are done */
221 if (p_state != PORT_STATE_OUT_SETUP)
224 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
225 add_trace("channel", "request", "no-channel");
226 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
227 /* if first reply has no channel, we are done */
229 add_trace("conclusion", NULL, "no channel until connect");
234 /* we will see, if our received channel is available */
236 ret = seize_bchannel(channel, exclusive);
237 add_trace("channel", "available", ret<0?"no":"yes");
239 add_trace("conclusion", NULL, "replied channel not available");
243 add_trace("conclusion", NULL, "replied channel accepted");
244 add_trace("connect", "channel", "%d", p_m_b_channel);
246 p_m_b_exclusive = 1; // we are done
248 /* activate channel given by remote */
249 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
255 * NOTE: we send MT_RELEASE_COMPLETE to "REJECT" the channel
256 * in response to the setup reply
258 l3m = create_l3msg();
259 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
260 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
262 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
263 new_state(PORT_STATE_RELEASE);
264 trigger_work(&p_m_d_delete);
265 return(-34); /* to epoint: no channel available */
270 * hunt bchannel for incoming setup or retrieve or resume
272 int Pdss1::hunt_bchannel(int channel, int exclusive)
274 struct select_channel *selchannel;
275 struct interface_port *ifport = p_m_mISDNport->ifport;
278 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (setup)", DIRECTION_NONE);
281 if (channel == CHANNEL_NO)
282 add_trace("channel", "request", "no-channel");
284 add_trace("channel", "request", (channel>0)?"%d%s":"any", channel, exclusive?" (forced)":"");
285 if (channel==CHANNEL_NO && p_type==PORT_TYPE_DSS1_TE_IN) {
286 add_trace("conclusion", NULL, "incoming call-waiting not supported for TE-mode");
288 return(-6); // channel unacceptable
290 if (channel <= 0) /* not given, no channel, whatever.. */
291 channel = CHANNEL_ANY; /* any channel */
292 add_trace("channel", "reserved", "%d", p_m_mISDNport->b_reserved);
293 if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num) { // of out chan..
294 add_trace("conclusion", NULL, "all channels are reserved");
296 return(-34); // no channel
298 if (channel == CHANNEL_ANY)
301 /* check for given channel in selection list */
302 selchannel = ifport->in_channel;
304 if (selchannel->channel == channel || selchannel->channel == CHANNEL_FREE)
306 selchannel = selchannel->next;
311 /* exclusive channel requests must be in the list */
313 /* no exclusive channel */
315 add_trace("conclusion", NULL, "exclusively requested channel not in list");
317 return(-6); // channel unacceptable
319 /* get index for channel */
320 i = channel-1-(channel>=17);
321 if (i < 0 || i >= p_m_mISDNport->b_num || channel == 16) {
322 add_trace("conclusion", NULL, "exclusively requested channel outside interface range");
324 return(-6); // channel unacceptable
327 if (p_m_mISDNport->b_port[i] == NULL)
329 add_trace("conclusion", NULL, "exclusively requested channel is busy");
331 return(-6); // channel unacceptable
334 /* requested channels in list will be used */
336 /* get index for channel */
337 i = channel-1-(channel>=17);
338 if (i < 0 || i >= p_m_mISDNport->b_num || channel == 16) {
339 add_trace("info", NULL, "requested channel %d outside interface range", channel);
340 } else /* if inside range (else) check if available */
341 if (p_m_mISDNport->b_port[i] == NULL)
345 /* if channel is not available or not in list, it must be searched */
347 /* check for first free channel in list */
349 selchannel = ifport->in_channel;
351 switch(selchannel->channel) {
352 case CHANNEL_FREE: /* free channel */
353 add_trace("hunting", "channel", "free");
354 if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num)
355 break; /* all channel in use or reserverd */
358 while(i < p_m_mISDNport->b_num) {
359 if (p_m_mISDNport->b_port[i] == NULL) {
360 channel = i+1+(i>=15);
368 add_trace("hunting", "channel", "%d", selchannel->channel);
369 if (selchannel->channel<1 || selchannel->channel==16)
370 break; /* invalid channels */
371 i = selchannel->channel-1-(selchannel->channel>=17);
372 if (i >= p_m_mISDNport->b_num)
373 break; /* channel not in port */
374 if (p_m_mISDNport->b_port[i] == NULL) {
375 channel = selchannel->channel;
381 break; /* found channel */
382 selchannel = selchannel->next;
385 add_trace("conclusion", NULL, "no channel available");
387 return(-6); // channel unacceptable
391 add_trace("conclusion", NULL, "channel available");
392 add_trace("connect", "channel", "%d", channel);
398 * handles all indications
400 /* CC_SETUP INDICATION */
401 void Pdss1::setup_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
403 int calling_type, calling_plan, calling_present, calling_screen;
404 int calling_type2, calling_plan2, calling_present2, calling_screen2;
405 int called_type, called_plan;
406 int redir_type, redir_plan, redir_present, redir_screen, redir_reason;
407 int hlc_coding, hlc_presentation, hlc_interpretation, hlc_hlc, hlc_exthlc;
408 int bearer_coding, bearer_capability, bearer_mode, bearer_rate, bearer_multi, bearer_user;
409 int exclusive, channel;
411 unsigned char keypad[33] = "";
412 unsigned char useruser[128];
413 int useruser_len = 0, useruser_protocol;
414 class Endpoint *epoint;
415 struct lcr_msg *message;
417 /* process given callref */
418 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_IND, DIRECTION_IN);
419 add_trace("callref", "new", "0x%x", pid);
421 /* release in case the ID is already in use */
422 add_trace("error", NULL, "callref already in use");
424 l3m = create_l3msg();
425 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
426 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47);
427 add_trace("reason", NULL, "callref already in use");
429 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, pid, l3m);
430 new_state(PORT_STATE_RELEASE);
431 trigger_work(&p_m_d_delete);
435 p_m_d_ces = pid >> 16;
438 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_IND, DIRECTION_IN);
439 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));
440 dec_ie_called_pn(l3m, &called_type, &called_plan, (unsigned char *)p_dialinginfo.id, sizeof(p_dialinginfo.id));
441 dec_ie_keypad(l3m, (unsigned char *)keypad, sizeof(keypad));
442 /* te-mode: CNIP (calling name identification presentation) */
443 dec_facility_centrex(l3m, (unsigned char *)p_callerinfo.name, sizeof(p_callerinfo.name));
444 dec_ie_useruser(l3m, &useruser_protocol, useruser, &useruser_len);
445 dec_ie_complete(l3m, &p_dialinginfo.sending_complete);
446 dec_ie_redir_nr(l3m, &redir_type, &redir_plan, &redir_present, &redir_screen, &redir_reason, (unsigned char *)p_redirinfo.id, sizeof(p_redirinfo.id));
447 dec_ie_channel_id(l3m, &exclusive, &channel);
448 dec_ie_hlc(l3m, &hlc_coding, &hlc_interpretation, &hlc_presentation, &hlc_hlc, &hlc_exthlc);
449 dec_ie_bearer(l3m, &bearer_coding, &bearer_capability, &bearer_mode, &bearer_rate, &bearer_multi, &bearer_user);
450 dec_ie_display(l3m, (unsigned char *)p_dialinginfo.display, sizeof(p_dialinginfo.display));
453 /* if blocked, release call with MT_RELEASE_COMPLETE */
454 if (p_m_mISDNport->ifport->block) {
455 l3m = create_l3msg();
456 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
457 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 27); /* temporary unavailable */
458 add_trace("reason", NULL, "port blocked");
460 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
461 new_state(PORT_STATE_RELEASE);
462 trigger_work(&p_m_d_delete);
467 switch (calling_present) {
469 p_callerinfo.present = INFO_PRESENT_RESTRICTED;
472 p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
475 p_callerinfo.present = INFO_PRESENT_ALLOWED;
478 switch (calling_screen) {
480 p_callerinfo.screen = INFO_SCREEN_USER;
483 p_callerinfo.screen = INFO_SCREEN_USER_VERIFIED_PASSED;
486 p_callerinfo.screen = INFO_SCREEN_USER_VERIFIED_FAILED;
489 p_callerinfo.screen = INFO_SCREEN_NETWORK;
492 switch (calling_type) {
494 p_callerinfo.ntype = INFO_NTYPE_NOTPRESENT;
497 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
500 p_callerinfo.ntype = INFO_NTYPE_INTERNATIONAL;
503 p_callerinfo.ntype = INFO_NTYPE_NATIONAL;
506 p_callerinfo.ntype = INFO_NTYPE_SUBSCRIBER;
509 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
512 p_callerinfo.isdn_port = p_m_portnum;
513 SCPY(p_callerinfo.interface, p_m_mISDNport->ifport->interface->name);
516 switch (calling_present2) {
518 p_callerinfo.present2 = INFO_PRESENT_RESTRICTED;
521 p_callerinfo.present2 = INFO_PRESENT_NOTAVAIL;
524 p_callerinfo.present2 = INFO_PRESENT_ALLOWED;
527 switch (calling_screen2) {
529 p_callerinfo.screen2 = INFO_SCREEN_USER;
532 p_callerinfo.screen2 = INFO_SCREEN_USER_VERIFIED_PASSED;
535 p_callerinfo.screen2 = INFO_SCREEN_USER_VERIFIED_FAILED;
538 p_callerinfo.screen2 = INFO_SCREEN_NETWORK;
541 switch (calling_type2) {
543 p_callerinfo.ntype2 = INFO_NTYPE_NOTPRESENT;
546 p_callerinfo.ntype2 = INFO_NTYPE_UNKNOWN;
549 p_callerinfo.ntype2 = INFO_NTYPE_INTERNATIONAL;
552 p_callerinfo.ntype2 = INFO_NTYPE_NATIONAL;
555 p_callerinfo.ntype2 = INFO_NTYPE_SUBSCRIBER;
558 p_callerinfo.ntype2 = INFO_NTYPE_UNKNOWN;
562 /* dialing information */
563 SCAT(p_dialinginfo.id, (char *)keypad);
564 switch (called_type) {
566 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
569 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
572 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
575 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
580 switch (redir_present) {
582 p_redirinfo.present = INFO_PRESENT_RESTRICTED;
585 p_redirinfo.present = INFO_PRESENT_NOTAVAIL;
588 p_redirinfo.present = INFO_PRESENT_ALLOWED;
591 switch (redir_screen) {
593 p_redirinfo.screen = INFO_SCREEN_USER;
596 p_redirinfo.screen = INFO_SCREEN_USER_VERIFIED_PASSED;
599 p_redirinfo.screen = INFO_SCREEN_USER_VERIFIED_FAILED;
602 p_redirinfo.screen = INFO_SCREEN_NETWORK;
605 switch (redir_reason) {
607 p_redirinfo.reason = INFO_REDIR_BUSY;
610 p_redirinfo.reason = INFO_REDIR_NORESPONSE;
613 p_redirinfo.reason = INFO_REDIR_UNCONDITIONAL;
616 p_redirinfo.reason = INFO_REDIR_CALLDEFLECT;
619 p_redirinfo.reason = INFO_REDIR_OUTOFORDER;
622 p_redirinfo.reason = INFO_REDIR_UNKNOWN;
625 switch (redir_type) {
627 p_redirinfo.ntype = INFO_NTYPE_NOTPRESENT;
630 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
633 p_redirinfo.ntype = INFO_NTYPE_INTERNATIONAL;
636 p_redirinfo.ntype = INFO_NTYPE_NATIONAL;
639 p_redirinfo.ntype = INFO_NTYPE_SUBSCRIBER;
642 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
645 p_redirinfo.isdn_port = p_m_portnum;
647 /* bearer capability */
648 switch (bearer_capability) {
650 p_capainfo.bearer_capa = INFO_BC_AUDIO;
651 bearer_user = (options.law=='a')?3:2;
654 p_capainfo.bearer_capa = bearer_capability;
657 switch (bearer_mode) {
659 p_capainfo.bearer_mode = INFO_BMODE_PACKET;
662 p_capainfo.bearer_mode = INFO_BMODE_CIRCUIT;
665 switch (bearer_user) {
667 p_capainfo.bearer_info1 = INFO_INFO1_NONE;
670 p_capainfo.bearer_info1 = bearer_user + 0x80;
677 p_capainfo.hlc = INFO_HLC_NONE;
680 p_capainfo.hlc = hlc_hlc + 0x80;
683 switch (hlc_exthlc) {
685 p_capainfo.exthlc = INFO_HLC_NONE;
688 p_capainfo.exthlc = hlc_exthlc + 0x80;
692 /* set bchannel mode */
693 if (p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED
694 || p_capainfo.bearer_capa==INFO_BC_DATARESTRICTED
695 || p_capainfo.bearer_capa==INFO_BC_VIDEO)
696 p_capainfo.source_mode = B_MODE_HDLC;
698 p_capainfo.source_mode = B_MODE_TRANSPARENT;
699 p_m_b_mode = p_capainfo.source_mode;
702 ret = channel = hunt_bchannel(channel, exclusive);
707 ret = seize_bchannel(channel, 1);
711 * NOTE: we send MT_RELEASE_COMPLETE to "REJECT" the channel
712 * in response to the setup
714 l3m = create_l3msg();
715 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
716 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
718 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
719 new_state(PORT_STATE_RELEASE);
720 trigger_work(&p_m_d_delete);
723 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
725 /* create endpoint */
727 FATAL("Incoming call but already got an endpoint.\n");
728 if (!(epoint = new Endpoint(p_serial, 0)))
729 FATAL("No memory for Endpoint instance\n");
730 if (!(epoint->ep_app = new DEFAULT_ENDPOINT_APP(epoint, 0))) //incoming
731 FATAL("No memory for Endpoint Application instance\n");
732 epointlist_new(epoint->ep_serial);
734 /* send setup message to endpoit */
735 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_SETUP);
736 message->param.setup.isdn_port = p_m_portnum;
737 message->param.setup.port_type = p_type;
738 // message->param.setup.dtmf = !p_m_mISDNport->ifport->nodtmf;
739 memcpy(&message->param.setup.dialinginfo, &p_dialinginfo, sizeof(struct dialing_info));
740 memcpy(&message->param.setup.callerinfo, &p_callerinfo, sizeof(struct caller_info));
741 memcpy(&message->param.setup.redirinfo, &p_redirinfo, sizeof(struct redir_info));
742 memcpy(&message->param.setup.capainfo, &p_capainfo, sizeof(struct capa_info));
743 memcpy(message->param.setup.useruser.data, &useruser, useruser_len);
744 message->param.setup.useruser.len = useruser_len;
745 message->param.setup.useruser.protocol = useruser_protocol;
746 message_put(message);
748 new_state(PORT_STATE_IN_SETUP);
751 /* CC_INFORMATION INDICATION */
752 void Pdss1::information_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
755 unsigned char keypad[33] = "", display[128] = "";
756 struct lcr_msg *message;
758 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_IND, DIRECTION_IN);
759 dec_ie_called_pn(l3m, &type, &plan, (unsigned char *)p_dialinginfo.id, sizeof(p_dialinginfo.id));
760 dec_ie_keypad(l3m, (unsigned char *)keypad, sizeof(keypad));
761 dec_ie_display(l3m, (unsigned char *)display, sizeof(display));
762 dec_ie_complete(l3m, &p_dialinginfo.sending_complete);
765 SCAT(p_dialinginfo.id, (char *)keypad);
768 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
771 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
774 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
777 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
780 SCPY(p_dialinginfo.display, (char *)display);
781 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_INFORMATION);
782 memcpy(&message->param.information, &p_dialinginfo, sizeof(struct dialing_info));
783 message_put(message);
784 /* reset overlap timeout */
788 /* CC_SETUP_ACCNOWLEDGE INDICATION */
789 void Pdss1::setup_acknowledge_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
791 int exclusive, channel;
792 int coding, location, progress;
794 struct lcr_msg *message;
795 int max = p_m_mISDNport->ifport->dialmax;
799 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_ACKNOWLEDGE_IND, DIRECTION_IN);
800 dec_ie_channel_id(l3m, &exclusive, &channel);
801 dec_ie_progress(l3m, &coding, &location, &progress);
805 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROGRESS);
806 message->param.progressinfo.progress = progress;
807 message->param.progressinfo.location = location;
808 message_put(message);
811 /* process channel */
812 ret = received_first_reply_to_setup(cmd, channel, exclusive);
814 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
815 message->param.disconnectinfo.cause = -ret;
816 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
817 message_put(message);
818 new_state(PORT_STATE_RELEASE);
819 trigger_work(&p_m_d_delete);
823 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_OVERLAP);
824 message_put(message);
826 new_state(PORT_STATE_OUT_OVERLAP);
828 number = p_m_d_queue;
829 while (number[0]) { /* as long we have something to dial */
830 if (max > (int)strlen(number) || max == 0)
831 max = (int)strlen(number);
833 nl3m = create_l3msg();
834 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
835 enc_ie_called_pn(nl3m, 0, 1, (unsigned char *)number, max);
837 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, nl3m);
840 p_m_d_queue[0] = '\0';
843 /* CC_PROCEEDING INDICATION */
844 void Pdss1::proceeding_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
846 int exclusive, channel;
847 int coding, location, progress;
849 struct lcr_msg *message;
850 int notify = -1, type, plan, present;
853 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_IND, DIRECTION_IN);
854 dec_ie_channel_id(l3m, &exclusive, &channel);
855 dec_ie_progress(l3m, &coding, &location, &progress);
856 dec_ie_notify(l3m, ¬ify);
857 dec_ie_redir_dn(l3m, &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
861 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROGRESS);
862 message->param.progressinfo.progress = progress;
863 message->param.progressinfo.location = location;
864 message_put(message);
867 ret = received_first_reply_to_setup(cmd, channel, exclusive);
869 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
870 message->param.disconnectinfo.cause = -ret;
871 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
872 message_put(message);
873 new_state(PORT_STATE_RELEASE);
874 trigger_work(&p_m_d_delete);
877 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROCEEDING);
878 message_put(message);
880 new_state(PORT_STATE_OUT_PROCEEDING);
886 if (type >= 0 || notify) {
887 if (!notify && type >= 0)
889 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
890 message->param.notifyinfo.notify = notify;
891 SCPY(message->param.notifyinfo.id, redir);
892 /* redirection number */
895 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
898 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
901 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
906 message->param.notifyinfo.ntype = INFO_NTYPE_NOTPRESENT;
909 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
912 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
915 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
918 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
921 message->param.notifyinfo.isdn_port = p_m_portnum;
922 message_put(message);
926 /* CC_ALERTING INDICATION */
927 void Pdss1::alerting_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
929 int exclusive, channel;
930 int coding, location, progress;
932 struct lcr_msg *message;
933 int notify = -1, type, plan, present;
936 l1l2l3_trace_header(p_m_mISDNport, this, L3_ALERTING_IND, DIRECTION_IN);
937 dec_ie_channel_id(l3m, &exclusive, &channel);
938 dec_ie_progress(l3m, &coding, &location, &progress);
939 dec_ie_notify(l3m, ¬ify);
940 dec_ie_redir_dn(l3m, &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
944 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROGRESS);
945 message->param.progressinfo.progress = progress;
946 message->param.progressinfo.location = location;
947 message_put(message);
950 /* process channel */
951 ret = received_first_reply_to_setup(cmd, channel, exclusive);
953 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
954 message->param.disconnectinfo.cause = -ret;
955 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
956 message_put(message);
957 new_state(PORT_STATE_RELEASE);
958 trigger_work(&p_m_d_delete);
961 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_ALERTING);
962 message_put(message);
964 new_state(PORT_STATE_OUT_ALERTING);
970 if (type >= 0 || notify) {
971 if (!notify && type >= 0)
973 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
974 message->param.notifyinfo.notify = notify;
975 SCPY(message->param.notifyinfo.id, redir);
978 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
981 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
984 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
989 message->param.notifyinfo.ntype = INFO_NTYPE_NOTPRESENT;
992 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
995 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
998 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1001 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1004 message->param.notifyinfo.isdn_port = p_m_portnum;
1005 message_put(message);
1009 /* CC_CONNECT INDICATION */
1010 void Pdss1::connect_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1012 int exclusive, channel;
1013 int type, plan, present, screen;
1015 struct lcr_msg *message;
1016 int bchannel_before;
1018 l1l2l3_trace_header(p_m_mISDNport, this, L3_CONNECT_IND, DIRECTION_IN);
1019 dec_ie_channel_id(l3m, &exclusive, &channel);
1020 dec_ie_connected_pn(l3m, &type, &plan, &present, &screen, (unsigned char *)p_connectinfo.id, sizeof(p_connectinfo.id));
1021 dec_ie_display(l3m, (unsigned char *)p_connectinfo.display, sizeof(p_connectinfo.display));
1022 /* te-mode: CONP (connected name identification presentation) */
1023 dec_facility_centrex(l3m, (unsigned char *)p_connectinfo.name, sizeof(p_connectinfo.name));
1026 /* select channel */
1027 bchannel_before = p_m_b_channel;
1028 ret = received_first_reply_to_setup(cmd, channel, exclusive);
1030 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1031 message->param.disconnectinfo.cause = -ret;
1032 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1033 message_put(message);
1034 new_state(PORT_STATE_RELEASE);
1035 trigger_work(&p_m_d_delete);
1039 /* connect information */
1042 p_connectinfo.present = INFO_PRESENT_RESTRICTED;
1045 p_connectinfo.present = INFO_PRESENT_NOTAVAIL;
1048 p_connectinfo.present = INFO_PRESENT_ALLOWED;
1053 p_connectinfo.screen = INFO_SCREEN_USER;
1056 p_connectinfo.screen = INFO_SCREEN_USER_VERIFIED_PASSED;
1059 p_connectinfo.screen = INFO_SCREEN_USER_VERIFIED_FAILED;
1062 p_connectinfo.screen = INFO_SCREEN_NETWORK;
1067 p_connectinfo.ntype = INFO_NTYPE_NOTPRESENT;
1070 p_connectinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1073 p_connectinfo.ntype = INFO_NTYPE_NATIONAL;
1076 p_connectinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1079 p_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1082 p_connectinfo.isdn_port = p_m_portnum;
1083 SCPY(p_connectinfo.interface, p_m_mISDNport->ifport->interface->name);
1085 /* only in nt-mode we send connect ack. in te-mode it is done by stack itself or optional */
1087 /* send connect acknowledge */
1088 l3m = create_l3msg();
1089 l1l2l3_trace_header(p_m_mISDNport, this, L3_CONNECT_RES, DIRECTION_OUT);
1090 /* if we had no bchannel before, we send it now */
1091 if (!bchannel_before && p_m_b_channel)
1092 enc_ie_channel_id(l3m, 1, p_m_b_channel);
1094 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CONNECT_ACKNOWLEDGE, p_m_d_l3id, l3m);
1097 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CONNECT);
1098 memcpy(&message->param.connectinfo, &p_connectinfo, sizeof(struct connect_info));
1099 message_put(message);
1101 new_state(PORT_STATE_CONNECT);
1104 /* CC_DISCONNECT INDICATION */
1105 void Pdss1::disconnect_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1107 int location, cause;
1108 int coding, proglocation, progress;
1109 struct lcr_msg *message;
1110 unsigned char display[128] = "";
1112 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_IND, DIRECTION_IN);
1113 dec_ie_progress(l3m, &coding, &proglocation, &progress);
1114 dec_ie_cause(l3m, &location, &cause);
1115 dec_ie_display(l3m, (unsigned char *)display, sizeof(display));
1120 location = LOCATION_PRIVATE_LOCAL;
1123 if (progress >= 0) {
1124 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROGRESS);
1125 message->param.progressinfo.progress = progress;
1126 message->param.progressinfo.location = proglocation;
1127 message_put(message);
1130 /* release if remote sends us no tones */
1131 if (!p_m_mISDNport->earlyb) {
1134 l3m = create_l3msg();
1135 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_REQ, DIRECTION_OUT);
1136 enc_ie_cause(l3m, location, cause); /* normal */
1137 add_trace("reason", NULL, "no remote patterns");
1139 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE, p_m_d_l3id, l3m);
1141 /* sending release to endpoint */
1142 if (location == LOCATION_PRIVATE_LOCAL)
1143 location = LOCATION_PRIVATE_REMOTE;
1144 while(p_epointlist) {
1145 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1146 message->param.disconnectinfo.cause = cause;
1147 message->param.disconnectinfo.location = location;
1148 SCAT(message->param.disconnectinfo.display, (char *)display);
1149 message_put(message);
1151 free_epointlist(p_epointlist);
1153 new_state(PORT_STATE_RELEASE);
1154 trigger_work(&p_m_d_delete);
1158 /* sending disconnect to active endpoint and release to inactive endpoints */
1159 if (location == LOCATION_PRIVATE_LOCAL)
1160 location = LOCATION_PRIVATE_REMOTE;
1161 if (ACTIVE_EPOINT(p_epointlist)) {
1162 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DISCONNECT);
1163 message->param.disconnectinfo.location = location;
1164 message->param.disconnectinfo.cause = cause;
1165 SCAT(message->param.disconnectinfo.display, (char *)display);
1166 message_put(message);
1168 while(INACTIVE_EPOINT(p_epointlist)) {
1169 message = message_create(p_serial, INACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1170 message->param.disconnectinfo.location = location;
1171 message->param.disconnectinfo.cause = cause;
1172 SCAT(message->param.disconnectinfo.display, (char *)display);
1173 message_put(message);
1175 free_epointid(INACTIVE_EPOINT(p_epointlist));
1177 new_state(PORT_STATE_IN_DISCONNECT);
1180 /* CC_DISCONNECT INDICATION */
1181 void Pdss1::disconnect_ind_i(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1183 int location, cause;
1186 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_IND, DIRECTION_IN);
1187 if (p_m_d_collect_cause > 0) {
1188 add_trace("old-cause", "location", "%d", p_m_d_collect_location);
1189 add_trace("old-cause", "value", "%d", p_m_d_collect_cause);
1191 dec_ie_cause(l3m, &location, &cause);
1192 if (location == LOCATION_PRIVATE_LOCAL)
1193 location = LOCATION_PRIVATE_REMOTE;
1196 collect_cause(&p_m_d_collect_cause, &p_m_d_collect_location, cause, location);
1197 add_trace("new-cause", "location", "%d", p_m_d_collect_location);
1198 add_trace("new-cause", "value", "%d", p_m_d_collect_cause);
1203 /* CC_RELEASE INDICATION */
1204 void Pdss1::release_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1206 int location, cause;
1207 struct lcr_msg *message;
1208 unsigned char display[128] = "";
1210 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_IND, DIRECTION_IN);
1211 dec_ie_cause(l3m, &location, &cause);
1212 dec_ie_display(l3m, (unsigned char *)display, sizeof(display));
1217 location = LOCATION_PRIVATE_LOCAL;
1220 /* sending release to endpoint */
1221 if (location == LOCATION_PRIVATE_LOCAL)
1222 location = LOCATION_PRIVATE_REMOTE;
1223 while(p_epointlist) {
1224 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1225 message->param.disconnectinfo.cause = cause;
1226 message->param.disconnectinfo.location = location;
1227 SCAT(message->param.disconnectinfo.display, (char *)display);
1228 message_put(message);
1230 free_epointlist(p_epointlist);
1233 new_state(PORT_STATE_RELEASE);
1234 trigger_work(&p_m_d_delete);
1237 /* CC_RESTART INDICATION */
1238 void Pdss1::restart_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1240 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESTART_IND, DIRECTION_IN);
1243 // L3 process is not toucht. (not even by network stack)
1246 /* CC_RELEASE_COMPLETE INDICATION (a reject) */
1247 void Pdss1::release_complete_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1249 int location, cause;
1250 struct lcr_msg *message;
1252 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_IND, DIRECTION_IN);
1253 /* in case layer 2 is down during setup, we send cause 27 loc 5 */
1254 if (p_state == PORT_STATE_OUT_SETUP && p_m_mISDNport->l1link == 0) {
1258 dec_ie_cause(l3m, &location, &cause);
1259 if (p_m_mISDNport->l1link < 0)
1260 add_trace("layer 1", NULL, "unknown");
1262 add_trace("layer 1", NULL, (p_m_mISDNport->l1link)?"up":"down");
1265 if (location == LOCATION_PRIVATE_LOCAL)
1266 location = LOCATION_PRIVATE_REMOTE;
1270 location = LOCATION_PRIVATE_LOCAL;
1273 /* sending release to endpoint */
1274 while(p_epointlist) {
1275 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1276 message->param.disconnectinfo.cause = cause;
1277 message->param.disconnectinfo.location = location;
1278 message_put(message);
1280 free_epointlist(p_epointlist);
1283 new_state(PORT_STATE_RELEASE);
1284 trigger_work(&p_m_d_delete);
1288 void Pdss1::t312_timeout_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1290 // not required, release is performed with MT_FREE
1293 /* CC_NOTIFY INDICATION */
1294 void Pdss1::notify_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1296 struct lcr_msg *message;
1297 int notify, type, plan, present;
1298 unsigned char notifyid[sizeof(message->param.notifyinfo.id)];
1299 unsigned char display[128] = "";
1301 l1l2l3_trace_header(p_m_mISDNport, this, L3_NOTIFY_IND, DIRECTION_IN);
1302 dec_ie_notify(l3m, ¬ify);
1303 dec_ie_redir_dn(l3m, &type, &plan, &present, notifyid, sizeof(notifyid));
1304 dec_ie_display(l3m, (unsigned char *)display, sizeof(display));
1307 if (!ACTIVE_EPOINT(p_epointlist))
1309 /* notification indicator */
1313 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1314 message->param.notifyinfo.notify = notify;
1315 SCPY(message->param.notifyinfo.id, (char *)notifyid);
1316 /* redirection number */
1319 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1322 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1325 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1330 message->param.notifyinfo.ntype = INFO_NTYPE_NOTPRESENT;
1333 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1336 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1339 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1342 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1345 SCAT(message->param.notifyinfo.display, (char *)display);
1346 message->param.notifyinfo.isdn_port = p_m_portnum;
1347 message_put(message);
1351 /* CC_HOLD INDICATION */
1352 struct lcr_msg *message;
1353 void Pdss1::hold_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1355 // class Endpoint *epoint;
1357 l1l2l3_trace_header(p_m_mISDNport, this, L3_HOLD_IND, DIRECTION_IN);
1360 if (!ACTIVE_EPOINT(p_epointlist) || p_m_hold) {
1361 l3m = create_l3msg();
1362 l1l2l3_trace_header(p_m_mISDNport, this, L3_HOLD_REJECT_REQ, DIRECTION_OUT);
1363 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, p_m_hold?101:31); /* normal unspecified / incompatible state */
1364 add_trace("reason", NULL, "no endpoint");
1366 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_HOLD_REJECT, p_m_d_l3id, l3m);
1371 /* notify the hold of call */
1372 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1373 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_HOLD;
1374 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1375 message_put(message);
1377 /* deactivate bchannel */
1378 chan_trace_header(p_m_mISDNport, this, "CHANNEL RELEASE (hold)", DIRECTION_NONE);
1379 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1383 /* set hold state */
1386 epoint = find_epoint_id(ACTIVE_EPOINT(p_epointlist));
1387 if (epoint && p_m_d_ntmode) {
1388 if (p_settings.tout_hold)
1389 schedule_timer(&p_m_timeout, p_settings.tout_hold, 0);
1393 /* acknowledge hold */
1394 l3m = create_l3msg();
1395 l1l2l3_trace_header(p_m_mISDNport, this, L3_HOLD_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1397 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_HOLD_ACKNOWLEDGE, p_m_d_l3id, l3m);
1401 /* CC_RETRIEVE INDICATION */
1402 void Pdss1::retrieve_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1404 struct lcr_msg *message;
1405 int channel, exclusive, cause;
1408 l1l2l3_trace_header(p_m_mISDNport, this, L3_RETRIEVE_IND, DIRECTION_IN);
1409 dec_ie_channel_id(l3m, &exclusive, &channel);
1413 cause = 101; /* incompatible state */
1416 l3m = create_l3msg();
1417 l1l2l3_trace_header(p_m_mISDNport, this, L3_RETRIEVE_REJECT_REQ, DIRECTION_OUT);
1418 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, cause);
1420 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RETRIEVE_REJECT, p_m_d_l3id, l3m);
1425 /* notify the retrieve of call */
1426 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1427 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_RETRIEVAL;
1428 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1429 message_put(message);
1432 ret = channel = hunt_bchannel(channel, exclusive);
1437 ret = seize_bchannel(channel, 1);
1443 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
1445 /* set hold state */
1447 unsched_timer(&p_m_timeout);
1449 /* acknowledge retrieve */
1450 l3m = create_l3msg();
1451 l1l2l3_trace_header(p_m_mISDNport, this, L3_RETRIEVE_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1452 enc_ie_channel_id(l3m, 1, p_m_b_channel);
1454 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RETRIEVE_ACKNOWLEDGE, p_m_d_l3id, l3m);
1457 /* CC_SUSPEND INDICATION */
1458 void Pdss1::suspend_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1460 struct lcr_msg *message;
1461 class Endpoint *epoint;
1462 unsigned char callid[8];
1464 int ret = -31; /* normal, unspecified */
1466 l1l2l3_trace_header(p_m_mISDNport, this, L3_SUSPEND_IND, DIRECTION_IN);
1467 dec_ie_call_id(l3m, callid, &len);
1470 if (!ACTIVE_EPOINT(p_epointlist)) {
1472 l3m = create_l3msg();
1473 l1l2l3_trace_header(p_m_mISDNport, this, L3_SUSPEND_REJECT_REQ, DIRECTION_OUT);
1474 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1476 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SUSPEND_REJECT, p_m_d_l3id, l3m);
1483 /* check if call id is in use */
1484 epoint = epoint_first;
1486 if (epoint->ep_park) {
1487 if (epoint->ep_park_len == len)
1488 if (!memcmp(epoint->ep_park_callid, callid, len)) {
1489 ret = -84; /* call id in use */
1493 epoint = epoint->next;
1496 /* notify the hold of call */
1497 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1498 message->param.notifyinfo.notify = INFO_NOTIFY_USER_SUSPENDED;
1499 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1500 message_put(message);
1502 /* deactivate bchannel */
1503 chan_trace_header(p_m_mISDNport, this, "CHANNEL RELEASE (suspend)", DIRECTION_NONE);
1504 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1508 /* sending suspend to endpoint */
1509 while (p_epointlist) {
1510 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_SUSPEND);
1511 memcpy(message->param.parkinfo.callid, callid, sizeof(message->param.parkinfo.callid));
1512 message->param.parkinfo.len = len;
1513 message_put(message);
1515 free_epointlist(p_epointlist);
1518 /* sending SUSPEND_ACKNOWLEDGE */
1519 l3m = create_l3msg();
1520 l1l2l3_trace_header(p_m_mISDNport, this, L3_SUSPEND_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1522 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SUSPEND_ACKNOWLEDGE, p_m_d_l3id, l3m);
1524 new_state(PORT_STATE_RELEASE);
1525 trigger_work(&p_m_d_delete);
1528 /* CC_RESUME INDICATION */
1529 void Pdss1::resume_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1531 unsigned char callid[8];
1533 int channel, exclusive;
1534 class Endpoint *epoint;
1535 struct lcr_msg *message;
1538 /* process given callref */
1539 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_IND, DIRECTION_IN);
1540 add_trace("callref", "new", "0x%x", pid);
1542 /* release is case the ID is already in use */
1543 add_trace("error", NULL, "callref already in use");
1545 l3m = create_l3msg();
1546 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_REJECT_REQ, DIRECTION_OUT);
1547 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47);
1548 add_trace("reason", NULL, "callref already in use");
1550 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RESUME_REJECT, pid, l3m);
1551 new_state(PORT_STATE_RELEASE);
1552 trigger_work(&p_m_d_delete);
1556 p_m_d_ces = pid >> 16;
1559 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_IND, DIRECTION_IN);
1560 dec_ie_call_id(l3m, callid, &len);
1563 /* if blocked, release call */
1564 if (p_m_mISDNport->ifport->block) {
1572 /* channel_id (no channel is possible in message) */
1574 channel = -1; /* any channel */
1577 ret = channel = hunt_bchannel(channel, exclusive);
1581 // mode (if hdlc parked) to be done. never mind, this is almost never requested
1583 ret = seize_bchannel(channel, 1);
1587 l3m = create_l3msg();
1588 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_REJECT_REQ, DIRECTION_OUT);
1589 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1591 add_trace("reason", NULL, "port blocked");
1593 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RESUME_REJECT, p_m_d_l3id, l3m);
1594 new_state(PORT_STATE_RELEASE);
1595 trigger_work(&p_m_d_delete);
1598 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
1600 /* create endpoint */
1602 FATAL("Incoming resume but already got an endpoint.\n");
1603 ret = -85; /* no call suspended */
1604 epoint = epoint_first;
1606 if (epoint->ep_park) {
1607 ret = -83; /* suspended call exists, but this not */
1608 if (epoint->ep_park_len == len)
1609 if (!memcmp(epoint->ep_park_callid, callid, len))
1612 epoint = epoint->next;
1617 epointlist_new(epoint->ep_serial);
1618 if (!(epoint->portlist_new(p_serial, p_type, p_m_mISDNport->earlyb)))
1619 FATAL("No memory for portlist\n");
1620 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RESUME);
1621 message_put(message);
1623 /* notify the resume of call */
1624 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1625 message->param.notifyinfo.notify = INFO_NOTIFY_USER_RESUMED;
1626 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1627 message_put(message);
1629 /* sending RESUME_ACKNOWLEDGE */
1630 l3m = create_l3msg();
1631 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1632 enc_ie_channel_id(l3m, 1, p_m_b_channel);
1634 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RESUME_ACKNOWLEDGE, p_m_d_l3id, l3m);
1636 new_state(PORT_STATE_CONNECT);
1640 /* CC_FACILITY INDICATION */
1641 void Pdss1::facility_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1643 unsigned char facil[256];
1645 struct lcr_msg *message;
1647 l1l2l3_trace_header(p_m_mISDNport, this, L3_FACILITY_IND, DIRECTION_IN);
1648 dec_ie_facility(l3m, facil, &facil_len);
1655 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_FACILITY);
1656 message->param.facilityinfo.len = facil_len;
1657 memcpy(message->param.facilityinfo.data, facil, facil_len);
1658 message_put(message);
1662 /* CC_PROGRESS INDICATION */
1663 void Pdss1::progress_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1665 int coding, location, progress;
1667 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROGRESS_IND, DIRECTION_IN);
1668 dec_ie_progress(l3m, &coding, &location, &progress);
1671 if (progress >= 0) {
1672 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROGRESS);
1673 message->param.progressinfo.progress = progress;
1674 message->param.progressinfo.location = location;
1675 message_put(message);
1681 * handler for isdn connections
1682 * incoming information are parsed and sent via message to the endpoint
1684 void Pdss1::message_isdn(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1691 PERROR("Pdss1(%s) timeout without cause.\n", p_name);
1694 if (l3m->cause[0] != 5) {
1695 PERROR("Pdss1(%s) expecting timeout with timer diagnostic. (got len=%d)\n", p_name, l3m->cause[0]);
1698 timer = (l3m->cause[3]-'0')*100;
1699 timer += (l3m->cause[4]-'0')*10;
1700 timer += (l3m->cause[5]-'0');
1701 l1l2l3_trace_header(p_m_mISDNport, this, L3_TIMEOUT_IND, DIRECTION_IN);
1702 add_trace("timer", NULL, "%d", timer);
1705 t312_timeout_ind(cmd, pid, l3m);
1709 if (p_state != PORT_STATE_IDLE)
1711 setup_ind(cmd, pid, l3m);
1714 case MT_INFORMATION:
1715 information_ind(cmd, pid, l3m);
1718 case MT_SETUP_ACKNOWLEDGE:
1719 if (p_state != PORT_STATE_OUT_SETUP) {
1720 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received setup_acknowledge, but we are not in outgoing setup state, IGNORING.\n", p_name);
1723 setup_acknowledge_ind(cmd, pid, l3m);
1726 case MT_CALL_PROCEEDING:
1727 if (p_state != PORT_STATE_OUT_SETUP
1728 && p_state != PORT_STATE_OUT_OVERLAP) {
1729 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received proceeding, but we are not in outgoing setup OR overlap state, IGNORING.\n", p_name);
1732 proceeding_ind(cmd, pid, l3m);
1736 if (p_state != PORT_STATE_OUT_SETUP
1737 && p_state != PORT_STATE_OUT_OVERLAP
1738 && p_state != PORT_STATE_OUT_PROCEEDING) {
1739 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding state, IGNORING.\n", p_name);
1742 alerting_ind(cmd, pid, l3m);
1746 if (p_state != PORT_STATE_OUT_SETUP
1747 && p_state != PORT_STATE_OUT_OVERLAP
1748 && p_state != PORT_STATE_OUT_PROCEEDING
1749 && p_state != PORT_STATE_OUT_ALERTING) {
1750 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding OR ALERTING state, IGNORING.\n", p_name);
1753 connect_ind(cmd, pid, l3m);
1754 if (p_m_d_notify_pending) {
1755 /* send pending notify message during connect */
1756 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
1757 message_free(p_m_d_notify_pending);
1758 p_m_d_notify_pending = NULL;
1762 case MT_CONNECT_ACKNOWLEDGE:
1763 if (p_state == PORT_STATE_CONNECT_WAITING)
1764 new_state(PORT_STATE_CONNECT);
1765 if (p_m_d_notify_pending) {
1766 /* send pending notify message during connect-ack */
1767 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
1768 message_free(p_m_d_notify_pending);
1769 p_m_d_notify_pending = NULL;
1774 disconnect_ind(cmd, pid, l3m);
1778 release_ind(cmd, pid, l3m);
1781 case MT_RELEASE_COMPLETE:
1782 release_complete_ind(cmd, pid, l3m);
1786 restart_ind(cmd, pid, l3m);
1790 notify_ind(cmd, pid, l3m);
1794 hold_ind(cmd, pid, l3m);
1798 retrieve_ind(cmd, pid, l3m);
1802 suspend_ind(cmd, pid, l3m);
1806 resume_ind(cmd, pid, l3m);
1810 facility_ind(cmd, pid, l3m);
1814 progress_ind(cmd, pid, l3m);
1818 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_L3ID_IND, DIRECTION_IN);
1819 add_trace("callref", NULL, "0x%x", p_m_d_l3id);
1822 trigger_work(&p_m_d_delete);
1824 /* sending release to endpoint in case we still have an endpoint
1825 * this is because we don't get any response if a release_complete is received (or a release in release state)
1827 while(p_epointlist) { // only if not already released
1828 struct lcr_msg *message;
1829 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1830 if (p_m_d_collect_cause) {
1831 message->param.disconnectinfo.cause = p_m_d_collect_cause;
1832 message->param.disconnectinfo.location = p_m_d_collect_location;
1834 message->param.disconnectinfo.cause = CAUSE_NOUSER;
1835 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1837 message_put(message);
1839 free_epointlist(p_epointlist);
1841 new_state(PORT_STATE_RELEASE);
1846 l1l2l3_trace_header(p_m_mISDNport, this, L3_UNKNOWN_IND, DIRECTION_IN);
1847 add_trace("unhandled", "cmd", "0x%x", cmd);
1852 void Pdss1::new_state(int state)
1854 // class Endpoint *epoint;
1857 if (state == PORT_STATE_IN_OVERLAP) {
1858 if (p_m_mISDNport->ifport->tout_dialing)
1859 schedule_timer(&p_m_timeout, p_m_mISDNport->ifport->tout_dialing, 0);
1861 if (state != p_state) {
1862 unsched_timer(&p_m_timeout);
1863 if (state == PORT_STATE_IN_SETUP
1864 || state == PORT_STATE_OUT_SETUP
1865 || state == PORT_STATE_IN_OVERLAP
1866 || state == PORT_STATE_OUT_OVERLAP) {
1867 if (p_m_mISDNport->ifport->tout_setup)
1868 schedule_timer(&p_m_timeout, p_m_mISDNport->ifport->tout_setup, 0);
1870 if (state == PORT_STATE_IN_PROCEEDING
1871 || state == PORT_STATE_OUT_PROCEEDING) {
1872 if (p_m_mISDNport->ifport->tout_proceeding)
1873 schedule_timer(&p_m_timeout, p_m_mISDNport->ifport->tout_proceeding, 0);
1875 if (state == PORT_STATE_IN_ALERTING
1876 || state == PORT_STATE_OUT_ALERTING) {
1877 if (p_m_mISDNport->ifport->tout_alerting)
1878 schedule_timer(&p_m_timeout, p_m_mISDNport->ifport->tout_alerting, 0);
1881 if (state == PORT_STATE_CONNECT
1882 || state == PORT_STATE_CONNECT_WAITING) {
1883 if (p_m_mISDNport->ifport->tout_connect)
1884 schedule_timer(&p_m_timeout, p_m_mISDNport->ifport->tout_connect, 0);
1887 if (state == PORT_STATE_IN_DISCONNECT
1888 || state == PORT_STATE_OUT_DISCONNECT) {
1889 if (p_m_mISDNport->ifport->tout_disconnect)
1890 schedule_timer(&p_m_timeout, p_m_mISDNport->ifport->tout_disconnect, 0);
1894 Port::new_state(state);
1898 /* deletes only if l3id is release, otherwhise it will be triggered then */
1899 static int delete_event(struct lcr_work *work, void *instance, int index)
1901 class Pdss1 *isdnport = (class Pdss1 *)instance;
1903 if (!isdnport->p_m_d_l3id)
1911 * handles all messages from endpoint
1913 /* MESSAGE_INFORMATION */
1914 void Pdss1::message_information(unsigned int epoint_id, int message_id, union parameter *param)
1917 char *display = param->information.display;
1918 char *number = param->information.id;
1919 int max = p_m_mISDNport->ifport->dialmax;
1921 while (number[0]) { /* as long we have something to dial */
1922 if (max > (int)strlen(number) || max == 0)
1923 max = (int)strlen(number);
1925 l3m = create_l3msg();
1926 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
1927 enc_ie_called_pn(l3m, 0, 1, (unsigned char *)number, max);
1928 if ((p_m_d_ntmode || p_m_d_tespecial) && display[0]) {
1929 enc_ie_display(l3m, (unsigned char *)display);
1930 display = (char *)"";
1933 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
1941 void Pdss1::message_setup(unsigned int epoint_id, int message_id, union parameter *param)
1945 int plan, type, screen, present, reason;
1946 int plan2, type2, screen2, present2;
1947 int capability, mode, rate, coding, user, presentation, interpretation, hlc, exthlc;
1948 int channel, exclusive;
1949 struct epoint_list *epointlist;
1950 int max = p_m_mISDNport->ifport->dialmax;
1952 /* release if port is blocked */
1953 if (p_m_mISDNport->ifport->block) {
1954 struct lcr_msg *message;
1956 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1957 message->param.disconnectinfo.cause = 27; // temp. unavail.
1958 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1959 message_put(message);
1960 new_state(PORT_STATE_RELEASE);
1961 trigger_work(&p_m_d_delete);
1965 /* copy setup infos to port */
1966 memcpy(&p_callerinfo, ¶m->setup.callerinfo, sizeof(p_callerinfo));
1967 memcpy(&p_dialinginfo, ¶m->setup.dialinginfo, sizeof(p_dialinginfo));
1968 memcpy(&p_capainfo, ¶m->setup.capainfo, sizeof(p_capainfo));
1969 memcpy(&p_redirinfo, ¶m->setup.redirinfo, sizeof(p_redirinfo));
1970 /* screen outgoing caller id */
1971 do_screen(1, p_callerinfo.id, sizeof(p_callerinfo.id), &p_callerinfo.ntype, &p_callerinfo.present, p_m_mISDNport->ifport->interface);
1972 do_screen(1, p_callerinfo.id2, sizeof(p_callerinfo.id2), &p_callerinfo.ntype2, &p_callerinfo.present2, p_m_mISDNport->ifport->interface);
1974 /* only display at connect state: this case happens if endpoint is in connected mode */
1975 if (p_state==PORT_STATE_CONNECT) {
1976 if (p_type!=PORT_TYPE_DSS1_NT_OUT
1977 && p_type!=PORT_TYPE_DSS1_NT_IN)
1979 if (p_callerinfo.display[0]) {
1980 /* sending information */
1981 l3m = create_l3msg();
1982 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
1983 if (p_m_d_ntmode || p_m_d_tespecial)
1984 enc_ie_display(l3m, (unsigned char *)p_callerinfo.display);
1986 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
1991 /* attach only if not already */
1992 epointlist = p_epointlist;
1994 if (epointlist->epoint_id == epoint_id)
1996 epointlist = epointlist->next;
1999 epointlist_new(epoint_id);
2003 if (p_m_b_channel) {
2004 channel = p_m_b_channel;
2005 exclusive = p_m_b_exclusive;
2007 channel = CHANNEL_ANY;
2008 /* nt-port with no channel, not reserverd */
2009 if (!p_m_b_channel && !p_m_b_reserve && p_type==PORT_TYPE_DSS1_NT_OUT)
2010 channel = CHANNEL_NO;
2013 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_REQ, DIRECTION_OUT);
2014 /* see MT_ASSIGN notes at do_layer3() */
2016 ret = p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_ASSIGN, 0, NULL);
2017 if (mt_assign_pid == 0 || ret < 0) {
2018 struct lcr_msg *message;
2020 add_trace("callref", NULL, "no free id");
2022 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2023 message->param.disconnectinfo.cause = 47;
2024 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2025 message_put(message);
2026 new_state(PORT_STATE_RELEASE);
2027 trigger_work(&p_m_d_delete);
2030 p_m_d_l3id = mt_assign_pid;
2032 add_trace("callref", "new", "0x%x", p_m_d_l3id);
2035 /* preparing setup message */
2036 l3m = create_l3msg();
2037 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_REQ, DIRECTION_OUT);
2038 /* channel information */
2039 if (channel >= 0) /* it should */
2040 enc_ie_channel_id(l3m, exclusive, channel);
2041 /* caller information */
2043 switch (p_callerinfo.ntype) {
2044 case INFO_NTYPE_UNKNOWN:
2047 case INFO_NTYPE_INTERNATIONAL:
2050 case INFO_NTYPE_NATIONAL:
2053 case INFO_NTYPE_SUBSCRIBER:
2056 default: /* INFO_NTYPE_NOTPRESENT */
2060 switch (p_callerinfo.screen) {
2061 case INFO_SCREEN_USER:
2064 case INFO_SCREEN_USER_VERIFIED_PASSED:
2067 case INFO_SCREEN_USER_VERIFIED_FAILED:
2070 default: /* INFO_SCREEN_NETWORK */
2074 switch (p_callerinfo.present) {
2075 case INFO_PRESENT_ALLOWED:
2078 case INFO_PRESENT_RESTRICTED:
2081 default: /* INFO_PRESENT_NOTAVAIL */
2085 /* caller information 2 */
2087 switch (p_callerinfo.ntype2) {
2088 case INFO_NTYPE_UNKNOWN:
2091 case INFO_NTYPE_INTERNATIONAL:
2094 case INFO_NTYPE_NATIONAL:
2097 case INFO_NTYPE_SUBSCRIBER:
2100 default: /* INFO_NTYPE_NOTPRESENT */
2104 switch (p_callerinfo.screen2) {
2105 case INFO_SCREEN_USER:
2108 case INFO_SCREEN_USER_VERIFIED_PASSED:
2111 case INFO_SCREEN_USER_VERIFIED_FAILED:
2114 default: /* INFO_SCREEN_NETWORK */
2118 switch (p_callerinfo.present2) {
2119 case INFO_PRESENT_ALLOWED:
2122 case INFO_PRESENT_RESTRICTED:
2125 default: /* INFO_PRESENT_NOTAVAIL */
2130 enc_ie_calling_pn(l3m, type, plan, present, screen, (unsigned char *)p_callerinfo.id, type2, plan2, present2, screen2, (unsigned char *)p_callerinfo.id2);
2131 /* dialing information */
2132 if (p_dialinginfo.id[0]) { /* only if we have something to dial */
2133 if (max > (int)strlen(p_dialinginfo.id) || max == 0)
2134 max = (int)strlen(p_dialinginfo.id);
2135 enc_ie_called_pn(l3m, 0, 1, (unsigned char *)p_dialinginfo.id, max);
2136 SCPY(p_m_d_queue, p_dialinginfo.id + max);
2139 if (p_dialinginfo.keypad[0])
2140 enc_ie_keypad(l3m, (unsigned char *)p_dialinginfo.keypad);
2141 /* sending complete */
2142 if (p_dialinginfo.sending_complete)
2143 enc_ie_complete(l3m, 1);
2144 /* sending user-user */
2145 if (param->setup.useruser.len) {
2146 enc_ie_useruser(l3m, param->setup.useruser.protocol, param->setup.useruser.data, param->setup.useruser.len);
2148 /* redirecting number */
2150 switch (p_redirinfo.ntype) {
2151 case INFO_NTYPE_UNKNOWN:
2154 case INFO_NTYPE_INTERNATIONAL:
2157 case INFO_NTYPE_NATIONAL:
2160 case INFO_NTYPE_SUBSCRIBER:
2163 default: /* INFO_NTYPE_NOTPRESENT */
2167 switch (p_redirinfo.screen) {
2168 case INFO_SCREEN_USER:
2171 case INFO_SCREEN_USER_VERIFIED_PASSED:
2174 case INFO_SCREEN_USER_VERIFIED_FAILED:
2177 default: /* INFO_SCREE_NETWORK */
2181 switch (p_redirinfo.reason) {
2182 case INFO_REDIR_BUSY:
2185 case INFO_REDIR_NORESPONSE:
2188 case INFO_REDIR_UNCONDITIONAL:
2191 case INFO_REDIR_CALLDEFLECT:
2194 case INFO_REDIR_OUTOFORDER:
2197 default: /* INFO_REDIR_UNKNOWN */
2201 switch (p_redirinfo.present) {
2202 case INFO_PRESENT_ALLOWED:
2205 case INFO_PRESENT_RESTRICTED:
2208 default: /* INFO_PRESENT_NOTAVAIL */
2212 /* sending redirecting number only in ntmode */
2213 if (type >= 0 && (p_m_d_ntmode || p_m_d_tespecial))
2214 enc_ie_redir_nr(l3m, type, plan, present, screen, reason, (unsigned char *)p_redirinfo.id);
2215 /* bearer capability */
2216 //printf("hlc=%d\n",p_capainfo.hlc);
2218 capability = p_capainfo.bearer_capa;
2219 mode = p_capainfo.bearer_mode;
2220 rate = (mode==INFO_BMODE_CIRCUIT)?0x10:0x00;
2221 switch (p_capainfo.bearer_info1) {
2222 case INFO_INFO1_NONE:
2226 user = p_capainfo.bearer_info1 & 0x7f;
2229 enc_ie_bearer(l3m, coding, capability, mode, rate, -1, user);
2231 if (p_capainfo.hlc) {
2235 hlc = p_capainfo.hlc & 0x7f;
2237 if (p_capainfo.exthlc)
2238 exthlc = p_capainfo.exthlc & 0x7f;
2239 enc_ie_hlc(l3m, coding, interpretation, presentation, hlc, exthlc);
2243 if (p_callerinfo.display[0] && (p_m_d_ntmode || p_m_d_tespecial))
2244 enc_ie_display(l3m, (unsigned char *)p_callerinfo.display);
2245 /* nt-mode: CNIP (calling name identification presentation) */
2246 // if (p_callerinfo.name[0] && (p_m_d_ntmode || p_m_d_tespecial))
2247 // enc_facility_centrex(&setup->FACILITY, dmsg, (unsigned char *)p_callerinfo.name, 1);
2250 /* send setup message now */
2251 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SETUP, p_m_d_l3id, l3m);
2253 new_state(PORT_STATE_OUT_SETUP);
2256 /* MESSAGE_FACILITY */
2257 void Pdss1::message_facility(unsigned int epoint_id, int message_id, union parameter *param)
2261 /* facility will not be sent to external lines */
2262 if (!p_m_d_ntmode && !p_m_d_tespecial)
2265 /* sending facility */
2266 l3m = create_l3msg();
2267 l1l2l3_trace_header(p_m_mISDNport, this, L3_FACILITY_REQ, DIRECTION_OUT);
2268 enc_ie_facility(l3m, (unsigned char *)param->facilityinfo.data, param->facilityinfo.len);
2270 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_FACILITY, p_m_d_l3id, l3m);
2273 /* MESSAGE_NOTIFY */
2274 void Pdss1::message_notify(unsigned int epoint_id, int message_id, union parameter *param)
2278 int plan = 0, type = -1, present = 0;
2280 if (p_m_mISDNport->ifport->nonotify) {
2281 l1l2l3_trace_header(p_m_mISDNport, this, L3_NOTIFY_REQ, DIRECTION_OUT);
2282 add_trace("info", NULL, "blocked by config");
2287 // printf("if = %d\n", param->notifyinfo.notify);
2288 if (param->notifyinfo.notify>INFO_NOTIFY_NONE)
2289 notify = param->notifyinfo.notify & 0x7f;
2294 switch (param->notifyinfo.ntype) {
2295 case INFO_NTYPE_UNKNOWN:
2298 case INFO_NTYPE_INTERNATIONAL:
2301 case INFO_NTYPE_NATIONAL:
2304 case INFO_NTYPE_SUBSCRIBER:
2307 default: /* INFO_NTYPE_UNKNOWN */
2311 switch (param->notifyinfo.present) {
2312 case INFO_PRESENT_ALLOWED:
2315 case INFO_PRESENT_RESTRICTED:
2318 default: /* INFO_PRESENT_NOTAVAIL */
2324 if (notify<0 && !param->notifyinfo.display[0]) {
2325 /* nothing to notify, nothing to display */
2330 if (p_state!=PORT_STATE_CONNECT && p_state!=PORT_STATE_IN_PROCEEDING && p_state!=PORT_STATE_IN_ALERTING) {
2331 /* queue notification */
2332 if (p_m_d_notify_pending)
2333 message_free(p_m_d_notify_pending);
2334 p_m_d_notify_pending = message_create(ACTIVE_EPOINT(p_epointlist), p_serial, EPOINT_TO_PORT, message_id);
2335 memcpy(&p_m_d_notify_pending->param, param, sizeof(union parameter));
2337 /* sending notification */
2338 l3m = create_l3msg();
2339 l1l2l3_trace_header(p_m_mISDNport, this, L3_NOTIFY_REQ, DIRECTION_OUT);
2340 enc_ie_notify(l3m, notify);
2341 /* sending redirection number only in ntmode */
2342 if (type >= 0 && (p_m_d_ntmode || p_m_d_tespecial))
2343 enc_ie_redir_dn(l3m, type, plan, present, (unsigned char *)param->notifyinfo.id);
2344 if (param->notifyinfo.display[0] && (p_m_d_ntmode || p_m_d_tespecial))
2345 enc_ie_display(l3m, (unsigned char *)param->notifyinfo.display);
2347 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_NOTIFY, p_m_d_l3id, l3m);
2349 } else if (p_m_d_ntmode || p_m_d_tespecial) {
2350 /* sending information */
2351 l3m = create_l3msg();
2352 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
2353 enc_ie_display(l3m, (unsigned char *)param->notifyinfo.display);
2355 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
2359 /* MESSAGE_OVERLAP */
2360 void Pdss1::message_overlap(unsigned int epoint_id, int message_id, union parameter *param)
2364 /* in case of sending complete, we proceed */
2365 if (p_dialinginfo.sending_complete) {
2366 PDEBUG(DEBUG_ISDN, "sending proceeding instead of setup_acknowledge, because address is complete.\n");
2367 message_proceeding(epoint_id, message_id, param);
2371 /* sending setup_acknowledge */
2372 l3m = create_l3msg();
2373 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_ACKNOWLEDGE_REQ, DIRECTION_OUT);
2374 /* channel information */
2375 if (p_state == PORT_STATE_IN_SETUP)
2376 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2377 /* progress information */
2378 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2379 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2380 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2381 if (p_m_mISDNport->tones)
2382 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2384 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SETUP_ACKNOWLEDGE, p_m_d_l3id, l3m);
2386 new_state(PORT_STATE_IN_OVERLAP);
2389 /* MESSAGE_PROCEEDING */
2390 void Pdss1::message_proceeding(unsigned int epoint_id, int message_id, union parameter *param)
2394 /* sending proceeding */
2395 l3m = create_l3msg();
2396 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2397 /* channel information */
2398 if (p_state == PORT_STATE_IN_SETUP)
2399 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2400 /* progress information */
2401 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2402 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2403 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2404 if (p_m_mISDNport->tones)
2405 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2407 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2409 new_state(PORT_STATE_IN_PROCEEDING);
2412 /* MESSAGE_ALERTING */
2413 void Pdss1::message_alerting(unsigned int epoint_id, int message_id, union parameter *param)
2417 /* NT-MODE in setup state we must send PROCEEDING first */
2418 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP) {
2419 /* sending proceeding */
2420 l3m = create_l3msg();
2421 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2422 /* channel information */
2423 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2424 /* progress information */
2425 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2426 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2427 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2428 if (p_m_mISDNport->tones)
2429 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2431 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2432 new_state(PORT_STATE_IN_PROCEEDING);
2435 /* sending alerting */
2436 l3m = create_l3msg();
2437 l1l2l3_trace_header(p_m_mISDNport, this, L3_ALERTING_REQ, DIRECTION_OUT);
2438 /* channel information */
2439 if (p_state == PORT_STATE_IN_SETUP)
2440 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2441 /* progress information */
2442 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2443 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2444 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2445 if (p_m_mISDNport->tones)
2446 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2448 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_ALERTING, p_m_d_l3id, l3m);
2450 new_state(PORT_STATE_IN_ALERTING);
2453 /* MESSAGE_CONNECT */
2454 void Pdss1::message_connect(unsigned int epoint_id, int message_id, union parameter *param)
2457 int type, plan, present, screen;
2458 class Endpoint *epoint;
2459 time_t current_time;
2461 /* NT-MODE in setup state we must send PROCEEDING first */
2462 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP) {
2463 /* sending proceeding */
2464 l3m = create_l3msg();
2465 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2466 /* channel information */
2467 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2469 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2470 new_state(PORT_STATE_IN_PROCEEDING);
2473 /* copy connected information */
2474 memcpy(&p_connectinfo, ¶m->connectinfo, sizeof(p_connectinfo));
2475 /* screen outgoing caller id */
2476 do_screen(1, p_connectinfo.id, sizeof(p_connectinfo.id), &p_connectinfo.ntype, &p_connectinfo.present, p_m_mISDNport->ifport->interface);
2478 /* only display at connect state */
2479 if (p_state == PORT_STATE_CONNECT)
2480 if (p_connectinfo.display[0]) {
2481 /* sending information */
2482 l3m = create_l3msg();
2483 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
2484 if (p_m_d_ntmode || p_m_d_tespecial)
2485 enc_ie_display(l3m, (unsigned char *)p_connectinfo.display);
2487 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
2491 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) {
2492 /* connect command only possible in setup, proceeding or alerting state */
2496 /* preparing connect message */
2497 l3m = create_l3msg();
2498 l1l2l3_trace_header(p_m_mISDNport, this, L3_CONNECT_REQ, DIRECTION_OUT);
2499 /* connect information */
2501 switch (p_connectinfo.ntype) {
2502 case INFO_NTYPE_UNKNOWN:
2505 case INFO_NTYPE_INTERNATIONAL:
2508 case INFO_NTYPE_NATIONAL:
2511 case INFO_NTYPE_SUBSCRIBER:
2514 default: /* INFO_NTYPE_NOTPRESENT */
2518 switch (param->connectinfo.screen) {
2519 case INFO_SCREEN_USER:
2522 case INFO_SCREEN_USER_VERIFIED_PASSED:
2525 case INFO_SCREEN_USER_VERIFIED_FAILED:
2528 default: /* INFO_SCREE_NETWORK */
2532 switch (p_connectinfo.present) {
2533 case INFO_PRESENT_ALLOWED:
2536 case INFO_PRESENT_RESTRICTED:
2539 default: /* INFO_PRESENT_NOTAVAIL */
2544 enc_ie_connected_pn(l3m, type, plan, present, screen, (unsigned char *)p_connectinfo.id);
2546 if (p_connectinfo.display[0] && (p_m_d_ntmode || p_m_d_tespecial))
2547 enc_ie_display(l3m, (unsigned char *)p_connectinfo.display);
2548 /* nt-mode: CONP (connected name identification presentation) */
2549 // if (p_connectinfo.name[0] && (p_m_d_ntmode || p_m_d_tespecial))
2550 // enc_facility_centrex(&connect->FACILITY, dmsg, (unsigned char *)p_connectinfo.name, 0);
2552 if (p_m_d_ntmode || p_m_d_tespecial) {
2553 epoint = find_epoint_id(epoint_id);
2554 time(¤t_time);
2555 enc_ie_date(l3m, current_time, p_settings.no_seconds);
2558 /* finally send message */
2559 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CONNECT, p_m_d_l3id, l3m);
2562 new_state(PORT_STATE_CONNECT);
2564 new_state(PORT_STATE_CONNECT_WAITING);
2568 /* MESSAGE_DISCONNECT */
2569 void Pdss1::message_disconnect(unsigned int epoint_id, int message_id, union parameter *param)
2572 struct lcr_msg *message;
2575 /* we reject during incoming setup when we have no tones. also if we are in outgoing setup state */
2576 // if ((p_state==PORT_STATE_IN_SETUP && !p_m_mISDNport->tones)
2577 if (/* ||*/ p_state==PORT_STATE_OUT_SETUP) {
2578 /* sending release to endpoint */
2579 while(p_epointlist) {
2580 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
2581 memcpy(&message->param, param, sizeof(union parameter));
2582 message_put(message);
2584 free_epointlist(p_epointlist);
2586 /* sending release */
2587 l3m = create_l3msg();
2588 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
2590 enc_ie_cause(l3m, (!p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_REMOTE:param->disconnectinfo.location, param->disconnectinfo.cause);
2592 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
2593 new_state(PORT_STATE_RELEASE);
2594 trigger_work(&p_m_d_delete);
2598 /* workarround: NT-MODE in setup state we must send PROCEEDING first to make it work */
2599 if (p_state==PORT_STATE_IN_SETUP) {
2600 /* sending proceeding */
2601 l3m = create_l3msg();
2602 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2603 /* channel information */
2604 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2605 /* progress information */
2606 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2607 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2608 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2609 if (p_m_mISDNport->tones)
2610 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2612 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2613 new_state(PORT_STATE_IN_PROCEEDING);
2616 /* sending disconnect */
2617 l3m = create_l3msg();
2618 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_REQ, DIRECTION_OUT);
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 enc_ie_cause(l3m, (!p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_REMOTE:param->disconnectinfo.location, param->disconnectinfo.cause);
2628 if (param->disconnectinfo.display[0])
2629 p = param->disconnectinfo.display;
2630 if (p) if (*p && (p_m_d_ntmode || p_m_d_tespecial))
2631 enc_ie_display(l3m, (unsigned char *)p);
2633 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_DISCONNECT, p_m_d_l3id, l3m);
2634 new_state(PORT_STATE_OUT_DISCONNECT);
2637 /* MESSAGE_RELEASE */
2638 void Pdss1::message_release(unsigned int epoint_id, int message_id, union parameter *param)
2641 class Endpoint *epoint;
2645 * if we are on incoming call setup, we may reject by sending a release_complete
2646 * also on outgoing call setup, we send a release complete, BUT this is not conform. (i don't know any other way)
2648 if (p_state==PORT_STATE_IN_SETUP
2649 || p_state==PORT_STATE_OUT_SETUP) {
2650 //#warning remove me
2651 //PDEBUG(DEBUG_LOG, "JOLLY sending release complete %d\n", p_serial);
2652 /* sending release complete */
2653 l3m = create_l3msg();
2654 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_REQ, DIRECTION_OUT);
2656 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2658 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
2659 new_state(PORT_STATE_RELEASE);
2661 free_epointid(epoint_id);
2662 // wait for callref to be released
2666 * we may only release during incoming disconnect state.
2667 * this means that the endpoint doesnt require audio anymore
2669 if (p_state == PORT_STATE_IN_DISCONNECT
2670 || p_state == PORT_STATE_OUT_DISCONNECT
2671 || param->disconnectinfo.force) {
2672 /* sending release */
2673 l3m = create_l3msg();
2674 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_REQ, DIRECTION_OUT);
2676 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2678 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE, p_m_d_l3id, l3m);
2679 new_state(PORT_STATE_RELEASE);
2681 free_epointid(epoint_id);
2682 // wait for callref to be released
2688 wirklich erst proceeding?:
2689 /* NT-MODE in setup state we must send PROCEEDING first */
2690 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP) {
2691 CALL_PROCEEDING_t *proceeding;
2693 /* sending proceeding */
2694 l3m = create_l3msg();
2695 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
2696 /* channel information */
2697 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2698 /* progress information */
2699 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2700 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2701 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2702 if (p_m_mISDNport->tones)
2703 enc_ie_progress(l3m, 0, (p_m_d_ntmode)?1:5, 8);
2705 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
2709 /* sending disconnect */
2710 l3m = create_l3msg();
2711 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_REQ, DIRECTION_OUT);
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 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2721 epoint = find_epoint_id(epoint_id);
2722 if (param->disconnectinfo.display[0])
2723 p = param->disconnectinfo.display;
2724 if (p) if (*p && (p_m_d_ntmode || p_m_d_tespecial))
2725 enc_ie_display(l3m, (unsigned char *)p);
2727 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_DISCONNECT, p_m_d_l3id, l3m);
2728 new_state(PORT_STATE_OUT_DISCONNECT);
2730 free_epointid(epoint_id);
2731 // wait for release and callref to be released
2732 //#warning remove me
2733 //PDEBUG(DEBUG_LOG, "JOLLY sending disconnect %d\n", p_serial);
2738 * endpoint sends messages to the port
2740 int Pdss1::message_epoint(unsigned int epoint_id, int message_id, union parameter *param)
2742 if (PmISDN::message_epoint(epoint_id, message_id, param))
2745 switch(message_id) {
2746 case MESSAGE_INFORMATION: /* overlap dialing */
2747 if (p_type==PORT_TYPE_DSS1_NT_OUT
2748 && p_state!=PORT_STATE_OUT_OVERLAP
2749 && p_state!=PORT_STATE_CONNECT
2750 && p_state!=PORT_STATE_OUT_DISCONNECT
2751 && p_state!=PORT_STATE_IN_DISCONNECT) {
2754 if (p_type==PORT_TYPE_DSS1_TE_OUT
2755 && p_state!=PORT_STATE_OUT_OVERLAP
2756 && p_state!=PORT_STATE_OUT_PROCEEDING
2757 && p_state!=PORT_STATE_OUT_ALERTING
2758 && p_state!=PORT_STATE_CONNECT
2759 && p_state!=PORT_STATE_OUT_DISCONNECT
2760 && p_state!=PORT_STATE_IN_DISCONNECT) {
2763 if ((p_type==PORT_TYPE_DSS1_NT_IN || p_type==PORT_TYPE_DSS1_TE_IN)
2764 && p_state!=PORT_STATE_IN_OVERLAP
2765 && p_state!=PORT_STATE_IN_PROCEEDING
2766 && p_state!=PORT_STATE_IN_ALERTING
2767 && p_state!=PORT_STATE_CONNECT
2768 && p_state!=PORT_STATE_CONNECT_WAITING
2769 && p_state!=PORT_STATE_OUT_DISCONNECT
2770 && p_state!=PORT_STATE_IN_DISCONNECT) {
2773 message_information(epoint_id, message_id, param);
2776 case MESSAGE_SETUP: /* dial-out command received from epoint */
2777 if (p_state!=PORT_STATE_IDLE
2778 && p_state!=PORT_STATE_CONNECT) {
2779 PERROR("Pdss1(%s) ignoring setup because isdn port is not in idle state (or connected for sending display info).\n", p_name);
2782 if (p_epointlist && p_state==PORT_STATE_IDLE)
2783 FATAL("Pdss1(%s): epoint pointer is set in idle state, how bad!!\n", p_name);
2784 message_setup(epoint_id, message_id, param);
2787 case MESSAGE_NOTIFY: /* display and notifications */
2788 message_notify(epoint_id, message_id, param);
2791 case MESSAGE_FACILITY: /* facility message */
2792 message_facility(epoint_id, message_id, param);
2795 case MESSAGE_OVERLAP: /* more information is needed */
2796 if (p_state!=PORT_STATE_IN_SETUP) {
2799 message_overlap(epoint_id, message_id, param);
2802 case MESSAGE_PROCEEDING: /* call of endpoint is proceeding */
2803 if (p_state!=PORT_STATE_IN_SETUP
2804 && p_state!=PORT_STATE_IN_OVERLAP) {
2807 message_proceeding(epoint_id, message_id, param);
2808 if (p_m_d_notify_pending) {
2809 /* send pending notify message during connect */
2810 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2811 message_free(p_m_d_notify_pending);
2812 p_m_d_notify_pending = NULL;
2816 case MESSAGE_ALERTING: /* call of endpoint is ringing */
2817 if (p_state!=PORT_STATE_IN_SETUP
2818 && p_state!=PORT_STATE_IN_OVERLAP
2819 && p_state!=PORT_STATE_IN_PROCEEDING) {
2822 message_alerting(epoint_id, message_id, param);
2823 if (p_m_d_notify_pending) {
2824 /* send pending notify message during connect */
2825 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2826 message_free(p_m_d_notify_pending);
2827 p_m_d_notify_pending = NULL;
2831 case MESSAGE_CONNECT: /* call of endpoint is connected */
2832 if (p_state!=PORT_STATE_IN_SETUP
2833 && p_state!=PORT_STATE_IN_OVERLAP
2834 && p_state!=PORT_STATE_IN_PROCEEDING
2835 && p_state!=PORT_STATE_IN_ALERTING
2836 && !(p_state==PORT_STATE_CONNECT && p_m_d_ntmode)) {
2839 message_connect(epoint_id, message_id, param);
2840 if (p_m_d_notify_pending) {
2841 /* send pending notify message during connect */
2842 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2843 message_free(p_m_d_notify_pending);
2844 p_m_d_notify_pending = NULL;
2848 case MESSAGE_DISCONNECT: /* call has been disconnected */
2849 if (p_state!=PORT_STATE_IN_SETUP
2850 && p_state!=PORT_STATE_IN_OVERLAP
2851 && p_state!=PORT_STATE_IN_PROCEEDING
2852 && p_state!=PORT_STATE_IN_ALERTING
2853 && p_state!=PORT_STATE_OUT_SETUP
2854 && p_state!=PORT_STATE_OUT_OVERLAP
2855 && p_state!=PORT_STATE_OUT_PROCEEDING
2856 && p_state!=PORT_STATE_OUT_ALERTING
2857 && p_state!=PORT_STATE_CONNECT
2858 && p_state!=PORT_STATE_CONNECT_WAITING) {
2861 message_disconnect(epoint_id, message_id, param);
2864 case MESSAGE_RELEASE: /* release isdn port */
2865 if (p_state==PORT_STATE_RELEASE) {
2868 message_release(epoint_id, message_id, param);
2872 PERROR("Pdss1(%s) isdn port with (caller id %s) received a wrong message: %d\n", p_name, p_callerinfo.id, message_id);
2881 * data from isdn-stack (layer-3) to pbx (port class)
2883 int stack2manager(struct mISDNport *mISDNport, unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
2889 PDEBUG(DEBUG_ISDN, "cmd(0x%x) pid(0x%x)\n", cmd, pid);
2892 PDEBUG(DEBUG_ISDN, "ignoring dummy process from phone.\n");
2896 /* find Port object of type ISDN */
2900 if ((port->p_type & PORT_CLASS_mISDN_MASK) == PORT_CLASS_DSS1) {
2901 pdss1 = (class Pdss1 *)port;
2902 /* check out correct stack and id */
2903 if (pdss1->p_m_mISDNport == mISDNport) {
2904 if (pdss1->p_m_d_l3id & MISDN_PID_CR_FLAG) {
2905 /* local callref, so match value only */
2906 if ((pdss1->p_m_d_l3id & MISDN_PID_CRVAL_MASK) == (pid & MISDN_PID_CRVAL_MASK))
2909 /* remote callref, ref + channel id */
2910 if (pdss1->p_m_d_l3id == pid)
2918 /* aktueller prozess */
2920 if (cmd == MT_ASSIGN) {
2921 /* stack gives us new layer 3 id (during connect) */
2922 l1l2l3_trace_header(mISDNport, pdss1, L3_NEW_L3ID_IND, DIRECTION_IN);
2923 add_trace("callref", "old", "0x%x", pdss1->p_m_d_l3id);
2924 /* nt-library now gives us a new id via CC_SETUP_CONFIRM */
2925 if ((pdss1->p_m_d_l3id&MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER)
2926 PERROR(" strange setup-procid 0x%x\n", pdss1->p_m_d_l3id);
2927 pdss1->p_m_d_l3id = pid;
2928 if (port->p_state == PORT_STATE_CONNECT)
2929 pdss1->p_m_d_ces = pid >> 16;
2930 add_trace("callref", "new", "0x%x", pdss1->p_m_d_l3id);
2934 /* if process id is master process, but a child disconnects */
2935 if (mISDNport->ntmode
2936 && (pid & MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER
2937 && (pdss1->p_m_d_l3id & MISDN_PID_CRTYPE_MASK) == MISDN_PID_MASTER) {
2938 if (cmd == MT_DISCONNECT
2939 || cmd == MT_RELEASE) {
2940 /* send special indication for child disconnect */
2941 pdss1->disconnect_ind_i(cmd, pid, l3m);
2944 if (cmd == MT_RELEASE_COMPLETE)
2947 /* if we have child pid and got different child pid message, ignore */
2948 if (mISDNport->ntmode
2949 && (pid & MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER
2950 && (pdss1->p_m_d_l3id & MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER
2951 && pid != pdss1->p_m_d_l3id)
2954 /* process message */
2955 pdss1->message_isdn(cmd, pid, l3m);
2962 /* creating port object, transparent until setup with hdlc */
2963 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
2964 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0, B_MODE_TRANSPARENT)))
2966 FATAL("Cannot create Port instance.\n");
2967 pdss1->message_isdn(cmd, pid, l3m);
2971 /* creating port object, transparent until setup with hdlc */
2972 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
2973 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0, B_MODE_TRANSPARENT)))
2974 FATAL("Cannot create Port instance.\n");
2975 pdss1->message_isdn(cmd, pid, l3m);
2979 PDEBUG(DEBUG_ISDN, "unused call ref released (l3id=0x%x)\n", pid);
2982 case MT_RELEASE_COMPLETE:
2983 PERROR("must be ignored by stack, not sent to app\n");
2987 // facility als broadcast
2991 PERROR("unhandled message: cmd(0x%x) pid(0x%x)\n", cmd, pid);
2994 if (port->p_type == PORT_TYPE_DSS1_NT_IN || port->p_type == PORT_TYPE_DSS1_NT_OUT) {
2995 pdss1 = (class Pdss1 *)port;
2996 /* check out correct stack */
2997 if (pdss1->p_m_mISDNport == mISDNport)
2998 /* check out correct id */
2999 PERROR("unhandled message: pid=%x is not associated with port-dinfo=%x\n", pid, pdss1->p_m_d_l3id);