1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
10 \*****************************************************************************/
20 #include <sys/ioctl.h>
21 #include <sys/types.h>
37 Pdss1::Pdss1(int type, struct mISDNport *mISDNport, char *portname, struct port_settings *settings, int channel, int exclusive) : PmISDN(type, mISDNport, portname, settings, channel, exclusive)
39 p_callerinfo.itype = (mISDNport->ifport->interface->extension)?INFO_ITYPE_ISDN_EXTENSION:INFO_ITYPE_ISDN;
40 p_m_d_ntmode = mISDNport->ntmode;
44 p_m_d_notify_pending = NULL;
45 p_m_d_collect_cause = CAUSE_NOUSER;
46 p_m_d_collect_location = LOCATION_PRIVATE_LOCAL;
48 PDEBUG(DEBUG_ISDN, "Created new mISDNPort(%s). Currently %d objects use, %s port #%d\n", portname, mISDNport->use, (mISDNport->ntmode)?"NT":"TE", p_m_portnum);
57 /* remove queued message */
59 message_free(p_m_d_queue);
61 if (p_m_d_notify_pending)
62 message_free(p_m_d_notify_pending);
64 /* check how many processes are left */
65 if (p_m_d_ntmode == 1)
67 if (p_m_mISDNport->nst.layer3->proc)
68 PDEBUG(DEBUG_ISDN, "destroyed mISDNPort(%s). WARNING: There is still a layer 3 process left. Ignore this, if currently are other calls. This message is not an error!\n", p_name);
74 * create layer 3 message
76 static msg_t *create_l3msg(int prim, int mt, int dinfo, int size, int ntmode)
84 size = sizeof(Q931_info_t)+2;
90 dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL);
97 dmsg = alloc_msg(size+256+mISDN_HEADER_LEN+DEFAULT_HEADROOM);
100 memset(msg_put(dmsg,size+mISDN_HEADER_LEN), 0, size+mISDN_HEADER_LEN);
101 frm = (iframe_t *)dmsg->data;
104 qi = (Q931_info_t *)(dmsg->data + mISDN_HEADER_LEN);
111 PERROR("cannot allocate memory, trying again...\n");
115 PERROR("cannot allocate memory, system overloaded.\n");
119 msg_t *create_l2msg(int prim, int dinfo, int size) /* NT only */
126 dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL);
131 PERROR("cannot allocate memory, trying again...\n");
135 PERROR("cannot allocate memory, system overloaded.\n");
140 * if we received a first reply to the setup message,
141 * we will check if we have now channel information
142 * return: <0: error, call is released, -cause is given
143 * 0: ok, nothing to do
145 int Pdss1::received_first_reply_to_setup(unsigned long prim, int channel, int exclusive)
148 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
149 RELEASE_COMPLETE_t *release_complete;
152 /* correct exclusive to 0, if no explicit channel was given */
153 if (exclusive<0 || channel<=0)
156 /* select scenario */
157 if (p_m_b_channel && p_m_b_exclusive)
159 /*** we gave an exclusive channel (or if we are done) ***/
161 /* if not first reply, we are done */
162 if (p_state != PORT_STATE_OUT_SETUP)
165 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
166 add_trace("channel", "request", "%d (forced)", p_m_b_channel);
167 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
169 /* if give channel not accepted or not equal */
170 if (channel!=-1 && p_m_b_channel!=channel)
172 add_trace("conclusion", NULL, "forced channel not accepted");
178 add_trace("conclusion", NULL, "channel was accepted");
179 add_trace("connect", "channel", "%d", p_m_b_channel);
182 /* activate our exclusive channel */
183 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_ACTIVATE);
187 /*** we gave a non-exclusive channel ***/
189 /* if not first reply, we are done */
190 if (p_state != PORT_STATE_OUT_SETUP)
193 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
194 add_trace("channel", "request", "%d (suggest)", p_m_b_channel);
195 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
197 /* if channel was accepted as given */
198 if (channel==-1 || p_m_b_channel==channel)
200 add_trace("conclusion", NULL, "channel was accepted as given");
201 add_trace("connect", "channel", "%d", p_m_b_channel);
203 p_m_b_exclusive = 1; // we are done
204 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_ACTIVATE);
208 /* if channel value is faulty */
211 add_trace("conclusion", NULL, "illegal reply");
213 ret = -111; // protocol error
217 /* if channel was not accepted, try to get it */
218 ret = seize_bchannel(channel, 1); // exclusively
219 add_trace("channel", "available", ret<0?"no":"yes");
222 add_trace("conclusion", NULL, "replied channel not available");
226 add_trace("conclusion", NULL, "replied channel accepted");
227 add_trace("connect", "channel", "%d", p_m_b_channel);
230 /* activate channel given by remote */
231 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_ACTIVATE);
235 /*** we sent 'any channel acceptable' ***/
237 /* if not first reply, we are done */
238 if (p_state != PORT_STATE_OUT_SETUP)
241 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
242 add_trace("channel", "request", "any");
243 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
244 /* if no channel was replied */
247 add_trace("conclusion", NULL, "no channel, protocol error");
249 ret = -111; // protocol error
253 /* we will see, if our received channel is available */
254 ret = seize_bchannel(channel, 1); // exclusively
255 add_trace("channel", "available", ret<0?"no":"yes");
258 add_trace("conclusion", NULL, "replied channel not available");
262 add_trace("conclusion", NULL, "replied channel accepted");
263 add_trace("connect", "channel", "%d", p_m_b_channel);
266 /* activate channel given by remote */
267 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_ACTIVATE);
270 /*** we sent 'no channel available' ***/
272 /* if not the first reply, but a connect, we are forced */
273 if (prim==(CC_CONNECT | INDICATION) && p_state!=PORT_STATE_OUT_SETUP)
275 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (connect)", DIRECTION_NONE);
276 add_trace("channel", "request", "no-channel");
277 add_trace("channel", "reply", (channel>=0)?"%d%s":"(none)", channel, exclusive?" (forced)":"");
280 goto use_from_connect;
282 ret = seize_bchannel(CHANNEL_ANY, 0); // any channel
283 add_trace("channel", "available", ret<0?"no":"yes");
286 add_trace("conclusion", NULL, "no channel available during call-waiting");
290 add_trace("conclusion", NULL, "using channel %d", p_m_b_channel);
291 add_trace("connect", "channel", "%d", p_m_b_channel);
293 p_m_b_exclusive = 1; // we are done
295 /* activate channel given by remote */
296 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_ACTIVATE);
300 /* if not first reply, we are done */
301 if (p_state != PORT_STATE_OUT_SETUP)
304 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
305 add_trace("channel", "request", "no-channel");
306 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
307 /* if first reply has no channel, we are done */
310 add_trace("conclusion", NULL, "no channel until connect");
315 /* we will see, if our received channel is available */
317 ret = seize_bchannel(channel, exclusive);
318 add_trace("channel", "available", ret<0?"no":"yes");
321 add_trace("conclusion", NULL, "replied channel not available");
325 add_trace("conclusion", NULL, "replied channel accepted");
326 add_trace("connect", "channel", "%d", p_m_b_channel);
328 p_m_b_exclusive = 1; // we are done
330 /* activate channel given by remote */
331 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_ACTIVATE);
336 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
337 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
338 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
339 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
341 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
342 new_state(PORT_STATE_RELEASE);
344 return(-34); /* to epoint: no channel available */
349 * hunt bchannel for incomming setup or retrieve or resume
351 int Pdss1::hunt_bchannel(int channel, int exclusive)
353 struct select_channel *selchannel;
354 struct interface_port *ifport = p_m_mISDNport->ifport;
357 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (setup)", DIRECTION_NONE);
360 if (channel == CHANNEL_NO)
361 add_trace("channel", "request", "no-channel");
363 add_trace("channel", "request", (channel>0)?"%d%s":"any", channel, exclusive?" (forced)":"");
364 if (channel==CHANNEL_NO && p_type==PORT_TYPE_DSS1_TE_IN)
366 add_trace("conclusion", NULL, "incoming call-waiting not supported for TE-mode");
368 return(-6); // channel unacceptable
370 if (channel <= 0) /* not given, no channel, whatever.. */
371 channel = CHANNEL_ANY; /* any channel */
372 if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num) // of out chan..
374 add_trace("channel", "reserved", "%d", p_m_mISDNport->b_reserved);
375 add_trace("conclusion", NULL, "all channels are reserved");
377 return(-34); // no channel
379 if (channel == CHANNEL_ANY)
383 /* check for given channel in selection list */
384 selchannel = ifport->in_channel;
387 if (selchannel->channel == channel || selchannel->channel == CHANNEL_FREE)
389 selchannel = selchannel->next;
394 /* exclusive channel requests must be in the list */
399 add_trace("conclusion", NULL, "exclusively requested channel not in list");
401 return(-6); // channel unacceptable
403 i = selchannel->channel-1-(selchannel->channel>=17);
404 if (p_m_mISDNport->b_port[i] == NULL)
406 add_trace("conclusion", NULL, "exclusively requested channel is busy");
408 return(-6); // channel unacceptable
411 /* requested channels in list will be used */
414 i = selchannel->channel-1-(selchannel->channel>=17);
415 if (p_m_mISDNport->b_port[i] == NULL)
419 /* if channel is not available or not in list, it must be searched */
421 /* check for first free channel in list */
423 selchannel = ifport->in_channel;
426 switch(selchannel->channel)
428 case CHANNEL_FREE: /* free channel */
429 add_trace("hunting", "channel", "free");
430 if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num)
431 break; /* all channel in use or reserverd */
434 while(i < p_m_mISDNport->b_num)
436 if (p_m_mISDNport->b_port[i] == NULL)
438 channel = i+1+(i>=15);
446 add_trace("hunting", "channel", "%d", selchannel->channel);
447 if (selchannel->channel<1 || selchannel->channel==16)
448 break; /* invalid channels */
449 i = selchannel->channel-1-(selchannel->channel>=17);
450 if (i >= p_m_mISDNport->b_num)
451 break; /* channel not in port */
452 if (p_m_mISDNport->b_port[i] == NULL)
454 channel = selchannel->channel;
460 break; /* found channel */
461 selchannel = selchannel->next;
465 add_trace("conclusion", NULL, "no channel available");
467 return(-6); // channel unacceptable
471 add_trace("conclusion", NULL, "channel available");
472 add_trace("connect", "channel", "%d", channel);
478 * handles all indications
480 /* CC_SETUP INDICATION */
481 void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
483 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
484 SETUP_t *setup = (SETUP_t *)((unsigned long)data + headerlen);
485 int calling_type, calling_plan, calling_present, calling_screen;
486 int called_type, called_plan;
487 int redir_type, redir_plan, redir_present, redir_screen, redir_reason;
488 int hlc_coding, hlc_presentation, hlc_interpretation, hlc_hlc, hlc_exthlc;
489 int bearer_coding, bearer_capability, bearer_mode, bearer_rate, bearer_multi, bearer_user;
490 int exclusive, channel;
493 unsigned char keypad[32] = "";
494 unsigned char useruser[128];
495 int useruser_len = 0, useruser_protocol;
496 class Endpoint *epoint;
497 struct message *message;
499 /* callref from nt-lib */
502 /* nt-library now gives us the id via CC_SETUP */
503 if (dinfo&(~0xff) == 0xff00)
505 PERROR("fatal software error: l3-stack gives us a process id 0xff00-0xffff\n");
508 l1l2l3_trace_header(p_m_mISDNport, this, CC_NEW_CR | INDICATION, DIRECTION_IN);
510 add_trace("callref", "old", "0x%x", p_m_d_l3id);
511 add_trace("callref", "new", "0x%x", dinfo);
513 if (p_m_d_l3id&(~0xff) == 0xff00)
514 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
516 p_m_d_ces = setup->ces;
519 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
520 dec_ie_calling_pn(setup->CALLING_PN, (Q931_info_t *)((unsigned long)data+headerlen), &calling_type, &calling_plan, &calling_present, &calling_screen, (unsigned char *)p_callerinfo.id, sizeof(p_callerinfo.id));
521 dec_ie_called_pn(setup->CALLED_PN, (Q931_info_t *)((unsigned long)data+headerlen), &called_type, &called_plan, (unsigned char *)p_dialinginfo.id, sizeof(p_dialinginfo.id));
522 dec_ie_keypad(setup->KEYPAD, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)keypad, sizeof(keypad));
524 /* te-mode: CNIP (calling name identification presentation) */
526 dec_facility_centrex(setup->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)p_callerinfo.name, sizeof(p_callerinfo.name));
528 dec_ie_useruser(setup->USER_USER, (Q931_info_t *)((unsigned long)data+headerlen), &useruser_protocol, useruser, &useruser_len);
529 dec_ie_complete(setup->COMPLETE, (Q931_info_t *)((unsigned long)data+headerlen), &p_dialinginfo.sending_complete);
530 dec_ie_redir_nr(setup->REDIR_NR, (Q931_info_t *)((unsigned long)data+headerlen), &redir_type, &redir_plan, &redir_present, &redir_screen, &redir_reason, (unsigned char *)p_redirinfo.id, sizeof(p_redirinfo.id));
531 dec_ie_channel_id(setup->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
532 dec_ie_hlc(setup->HLC, (Q931_info_t *)((unsigned long)data+headerlen), &hlc_coding, &hlc_interpretation, &hlc_presentation, &hlc_hlc, &hlc_exthlc);
533 dec_ie_bearer(setup->BEARER, (Q931_info_t *)((unsigned long)data+headerlen), &bearer_coding, &bearer_capability, &bearer_mode, &bearer_rate, &bearer_multi, &bearer_user);
536 /* if blocked, release call */
537 if (p_m_mISDNport->ifport->block)
539 RELEASE_COMPLETE_t *release_complete;
541 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
542 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
543 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
544 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 27); /* temporary unavailable */
545 add_trace("reason", NULL, "port blocked");
547 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
548 new_state(PORT_STATE_RELEASE);
554 switch (calling_present)
557 p_callerinfo.present = INFO_PRESENT_RESTRICTED;
560 p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
563 p_callerinfo.present = INFO_PRESENT_ALLOWED;
566 switch (calling_screen)
569 p_callerinfo.screen = INFO_SCREEN_USER;
572 p_callerinfo.screen = INFO_SCREEN_NETWORK;
575 switch (calling_type)
578 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
579 p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
580 p_callerinfo.screen = INFO_SCREEN_NETWORK;
583 p_callerinfo.ntype = INFO_NTYPE_INTERNATIONAL;
586 p_callerinfo.ntype = INFO_NTYPE_NATIONAL;
589 p_callerinfo.ntype = INFO_NTYPE_SUBSCRIBER;
592 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
595 p_callerinfo.isdn_port = p_m_portnum;
596 SCPY(p_callerinfo.interface, p_m_mISDNport->ifport->interface->name);
598 /* dialing information */
599 SCAT(p_dialinginfo.id, (char *)keypad);
603 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
606 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
609 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
612 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
617 switch (redir_present)
620 p_redirinfo.present = INFO_PRESENT_RESTRICTED;
623 p_redirinfo.present = INFO_PRESENT_NOTAVAIL;
626 p_redirinfo.present = INFO_PRESENT_ALLOWED;
629 switch (redir_screen)
632 p_redirinfo.screen = INFO_SCREEN_USER;
635 p_redirinfo.screen = INFO_SCREEN_NETWORK;
638 switch (redir_reason)
641 p_redirinfo.reason = INFO_REDIR_BUSY;
644 p_redirinfo.reason = INFO_REDIR_NORESPONSE;
647 p_redirinfo.reason = INFO_REDIR_UNCONDITIONAL;
650 p_redirinfo.reason = INFO_REDIR_CALLDEFLECT;
653 p_redirinfo.reason = INFO_REDIR_OUTOFORDER;
656 p_redirinfo.reason = INFO_REDIR_UNKNOWN;
662 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
663 p_redirinfo.present = INFO_PRESENT_NULL; /* not redirecting */
664 p_redirinfo.reason = INFO_REDIR_UNKNOWN;
667 p_redirinfo.ntype = INFO_NTYPE_INTERNATIONAL;
670 p_redirinfo.ntype = INFO_NTYPE_NATIONAL;
673 p_redirinfo.ntype = INFO_NTYPE_SUBSCRIBER;
676 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
679 p_redirinfo.isdn_port = p_m_portnum;
681 /* bearer capability */
682 switch (bearer_capability)
685 p_capainfo.bearer_capa = INFO_BC_AUDIO;
686 bearer_user = (options.law=='a')?3:2;
689 p_capainfo.bearer_capa = bearer_capability;
695 p_capainfo.bearer_mode = INFO_BMODE_PACKET;
698 p_capainfo.bearer_mode = INFO_BMODE_CIRCUIT;
704 p_capainfo.bearer_info1 = INFO_INFO1_NONE;
707 p_capainfo.bearer_info1 = bearer_user + 0x80;
715 p_capainfo.hlc = INFO_HLC_NONE;
718 p_capainfo.hlc = hlc_hlc + 0x80;
724 p_capainfo.exthlc = INFO_HLC_NONE;
727 p_capainfo.exthlc = hlc_exthlc + 0x80;
732 ret = channel = hunt_bchannel(channel, exclusive);
737 ret = seize_bchannel(channel, 1);
741 RELEASE_COMPLETE_t *release_complete;
743 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
744 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
745 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
746 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
748 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
749 new_state(PORT_STATE_RELEASE);
753 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_ACTIVATE);
755 /* create endpoint */
758 PERROR("SOFTWARE ERROR: incoming call but already got an endpoint, exitting...\n");
761 if (!(epoint = new Endpoint(p_serial, 0)))
763 RELEASE_COMPLETE_t *release_complete;
765 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
766 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
767 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
768 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 41); /* temporary failure */
770 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
771 new_state(PORT_STATE_RELEASE);
775 if (!(epoint->ep_app = new DEFAULT_ENDPOINT_APP(epoint)))
777 PERROR("no memory for application\n");
780 if (!(epointlist_new(epoint->ep_serial)))
782 PERROR("no memory for epointlist\n");
785 /* send setup message to endpoit */
786 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_SETUP);
787 message->param.setup.isdn_port = p_m_portnum;
788 message->param.setup.port_type = p_type;
789 memcpy(&message->param.setup.dialinginfo, &p_dialinginfo, sizeof(struct dialing_info));
790 memcpy(&message->param.setup.callerinfo, &p_callerinfo, sizeof(struct caller_info));
791 memcpy(&message->param.setup.redirinfo, &p_redirinfo, sizeof(struct redir_info));
792 memcpy(&message->param.setup.capainfo, &p_capainfo, sizeof(struct capa_info));
793 memcpy(message->param.setup.useruser.data, &useruser, useruser_len);
794 message->param.setup.useruser.len = useruser_len;
795 message->param.setup.useruser.protocol = useruser_protocol;
796 message_put(message);
798 new_state(PORT_STATE_IN_SETUP);
801 /* CC_INFORMATION INDICATION */
802 void Pdss1::information_ind(unsigned long prim, unsigned long dinfo, void *data)
804 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
805 INFORMATION_t *information = (INFORMATION_t *)((unsigned long)data + headerlen);
807 unsigned char keypad[32] = "";
808 struct message *message;
810 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
811 dec_ie_called_pn(information->CALLED_PN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, (unsigned char *)p_dialinginfo.id, sizeof(p_dialinginfo.id));
812 dec_ie_keypad(information->KEYPAD, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)keypad, sizeof(keypad));
813 dec_ie_complete(information->COMPLETE, (Q931_info_t *)((unsigned long)data+headerlen), &p_dialinginfo.sending_complete);
816 SCAT(p_dialinginfo.id, (char *)keypad);
820 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
823 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
826 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
829 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
832 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_INFORMATION);
833 memcpy(&message->param.information, &p_dialinginfo, sizeof(struct dialing_info));
834 message_put(message);
835 /* reset overlap timeout */
839 /* CC_SETUP_ACCNOWLEDGE INDICATION */
840 void Pdss1::setup_acknowledge_ind(unsigned long prim, unsigned long dinfo, void *data)
842 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
843 SETUP_ACKNOWLEDGE_t *setup_acknowledge = (SETUP_ACKNOWLEDGE_t *)((unsigned long)data + headerlen);
844 int exclusive, channel;
845 int coding, location, progress;
847 struct message *message;
849 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
850 dec_ie_channel_id(setup_acknowledge->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
851 dec_ie_progress(setup_acknowledge->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
854 /* process channel */
855 ret = received_first_reply_to_setup(prim, exclusive, channel);
858 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
859 message->param.disconnectinfo.cause = -ret;
860 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
861 message_put(message);
862 new_state(PORT_STATE_RELEASE);
867 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_OVERLAP);
868 message_put(message);
870 new_state(PORT_STATE_OUT_OVERLAP);
873 /* CC_PROCEEDING INDICATION */
874 void Pdss1::proceeding_ind(unsigned long prim, unsigned long dinfo, void *data)
876 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
877 CALL_PROCEEDING_t *proceeding = (CALL_PROCEEDING_t *)((unsigned long)data + headerlen);
878 int exclusive, channel;
879 int coding, location, progress;
881 struct message *message;
882 int notify = -1, type, plan, present;
885 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
886 dec_ie_channel_id(proceeding->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
887 dec_ie_progress(proceeding->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
888 dec_ie_notify(NULL/*proceeding->NOTIFY*/, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
889 dec_ie_redir_dn(proceeding->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
892 ret = received_first_reply_to_setup(prim, exclusive, channel);
895 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
896 message->param.disconnectinfo.cause = -ret;
897 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
898 message_put(message);
899 new_state(PORT_STATE_RELEASE);
903 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROCEEDING);
904 message_put(message);
906 new_state(PORT_STATE_OUT_PROCEEDING);
912 if (type >= 0 || notify)
914 if (!notify && type >= 0)
916 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
917 message->param.notifyinfo.notify = notify;
918 SCPY(message->param.notifyinfo.id, redir);
919 /* redirection number */
923 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
926 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
929 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
935 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
936 message->param.notifyinfo.present = INFO_PRESENT_NULL;
939 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
942 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
945 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
948 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
951 message->param.notifyinfo.isdn_port = p_m_portnum;
952 message_put(message);
956 /* CC_ALERTING INDICATION */
957 void Pdss1::alerting_ind(unsigned long prim, unsigned long dinfo, void *data)
959 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
960 ALERTING_t *alerting = (ALERTING_t *)((unsigned long)data + headerlen);
961 int exclusive, channel;
962 int coding, location, progress;
964 struct message *message;
965 int notify = -1, type, plan, present;
968 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
969 dec_ie_channel_id(alerting->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
970 dec_ie_progress(alerting->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
971 dec_ie_notify(NULL/*alerting->NOTIFY*/, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
972 dec_ie_redir_dn(alerting->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
975 /* process channel */
976 ret = received_first_reply_to_setup(prim, exclusive, channel);
979 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
980 message->param.disconnectinfo.cause = -ret;
981 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
982 message_put(message);
983 new_state(PORT_STATE_RELEASE);
987 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_ALERTING);
988 message_put(message);
990 new_state(PORT_STATE_OUT_ALERTING);
996 if (type >= 0 || notify)
998 if (!notify && type >= 0)
1000 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1001 message->param.notifyinfo.notify = notify;
1002 SCPY(message->param.notifyinfo.id, redir);
1006 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1009 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1012 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1018 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1019 message->param.notifyinfo.present = INFO_PRESENT_NULL;
1022 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1025 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1028 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1031 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1034 message->param.notifyinfo.isdn_port = p_m_portnum;
1035 message_put(message);
1039 /* CC_CONNECT INDICATION */
1040 void Pdss1::connect_ind(unsigned long prim, unsigned long dinfo, void *data)
1042 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1043 CONNECT_t *connect = (CONNECT_t *)((unsigned long)data + headerlen);
1044 int exclusive, channel;
1045 int type, plan, present, screen;
1048 struct message *message;
1049 int bchannel_before;
1050 CONNECT_ACKNOWLEDGE_t *connect_acknowledge;
1053 p_m_d_ces = connect->ces;
1055 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1056 dec_ie_channel_id(connect->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
1057 dec_ie_connected_pn(connect->CONNECT_PN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, &screen, (unsigned char *)p_connectinfo.id, sizeof(p_connectinfo.id));
1059 /* te-mode: CONP (connected name identification presentation) */
1061 dec_facility_centrex(connect->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)p_connectinfo.name, sizeof(p_connectinfo.name));
1065 /* select channel */
1066 bchannel_before = p_m_b_channel;
1067 ret = received_first_reply_to_setup(prim, exclusive, channel);
1070 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1071 message->param.disconnectinfo.cause = -ret;
1072 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1073 message_put(message);
1074 new_state(PORT_STATE_RELEASE);
1079 /* connect information */
1083 p_connectinfo.present = INFO_PRESENT_RESTRICTED;
1086 p_connectinfo.present = INFO_PRESENT_NOTAVAIL;
1089 p_connectinfo.present = INFO_PRESENT_ALLOWED;
1095 p_connectinfo.screen = INFO_SCREEN_USER;
1098 p_connectinfo.screen = INFO_SCREEN_NETWORK;
1104 p_connectinfo.present = INFO_PRESENT_NULL; /* no COLP info */
1105 p_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1108 p_connectinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1111 p_connectinfo.ntype = INFO_NTYPE_NATIONAL;
1114 p_connectinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1117 p_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1120 p_connectinfo.isdn_port = p_m_portnum;
1121 SCPY(p_connectinfo.interfaces, p_m_mISDNport->ifport->interface->name);
1123 /* only in nt-mode we send connect ack. in te-mode it is done by stack itself or optional */
1126 /* send connect acknowledge */
1127 dmsg = create_l3msg(CC_CONNECT | RESPONSE, MT_CONNECT, dinfo, sizeof(CONNECT_ACKNOWLEDGE_t), p_m_d_ntmode);
1128 connect_acknowledge = (CONNECT_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1129 l1l2l3_trace_header(p_m_mISDNport, this, CC_CONNECT | RESPONSE, DIRECTION_OUT);
1130 /* if we had no bchannel before, we send it now */
1131 if (!bchannel_before && p_m_b_channel)
1132 enc_ie_channel_id(&connect_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
1134 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1137 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CONNECT);
1138 memcpy(&message->param.connectinfo, &p_connectinfo, sizeof(struct connect_info));
1139 message_put(message);
1141 new_state(PORT_STATE_CONNECT);
1144 /* CC_DISCONNECT INDICATION */
1145 void Pdss1::disconnect_ind(unsigned long prim, unsigned long dinfo, void *data)
1147 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1148 DISCONNECT_t *disconnect = (DISCONNECT_t *)((unsigned long)data + headerlen);
1149 int location, cause;
1150 int coding, proglocation, progress;
1151 struct message *message;
1153 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1154 dec_ie_progress(disconnect->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &proglocation, &progress);
1155 dec_ie_cause(disconnect->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1161 /* release if we are remote sends us no tones */
1162 if (p_m_mISDNport->earlyb)
1167 dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, dinfo, sizeof(RELEASE_t), p_m_d_ntmode);
1168 release = (RELEASE_t *)(dmsg->data + headerlen);
1169 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE | REQUEST, DIRECTION_OUT);
1170 enc_ie_cause(&release->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16); /* normal */
1171 add_trace("reason", NULL, "no remote patterns");
1173 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1175 /* sending release to endpoint */
1178 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1179 message->param.disconnectinfo.cause = cause;
1180 message->param.disconnectinfo.location = location;
1181 message_put(message);
1183 free_epointlist(p_epointlist);
1185 new_state(PORT_STATE_RELEASE);
1190 /* sending disconnect to active endpoint and release to inactive endpoints */
1191 if (ACTIVE_EPOINT(p_epointlist))
1193 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DISCONNECT);
1194 message->param.disconnectinfo.location = location;
1195 message->param.disconnectinfo.cause = cause;
1196 message_put(message);
1198 while(INACTIVE_EPOINT(p_epointlist))
1200 message = message_create(p_serial, INACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1201 message->param.disconnectinfo.location = location;
1202 message->param.disconnectinfo.cause = cause;
1203 message_put(message);
1205 free_epointid(INACTIVE_EPOINT(p_epointlist));
1207 new_state(PORT_STATE_IN_DISCONNECT);
1210 /* CC_DISCONNECT INDICATION */
1211 void Pdss1::disconnect_ind_i(unsigned long prim, unsigned long dinfo, void *data)
1213 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1214 DISCONNECT_t *disconnect = (DISCONNECT_t *)((unsigned long)data + headerlen);
1215 int location, cause;
1218 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1219 if (p_m_d_collect_cause > 0)
1221 add_trace("old-cause", "location", "%d", p_m_d_collect_location);
1222 add_trace("old-cause", "value", "%d", p_m_d_collect_cause);
1224 dec_ie_cause(disconnect->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1228 if (cause == CAUSE_REJECTED) /* call rejected */
1230 p_m_d_collect_cause = CAUSE_REJECTED;
1231 p_m_d_collect_location = location;
1233 if (cause==CAUSE_NORMAL && p_m_d_collect_cause!=CAUSE_REJECTED) /* reject via hangup */
1235 p_m_d_collect_cause = CAUSE_NORMAL;
1236 p_m_d_collect_location = location;
1238 if (cause==CAUSE_BUSY && p_m_d_collect_cause!=CAUSE_REJECTED && p_m_d_collect_cause!=CAUSE_NORMAL) /* busy */
1240 p_m_d_collect_cause = CAUSE_BUSY;
1241 p_m_d_collect_location = location;
1243 if (cause==CAUSE_OUTOFORDER && p_m_d_collect_cause!=CAUSE_BUSY && p_m_d_collect_cause!=CAUSE_REJECTED && p_m_d_collect_cause!=CAUSE_NORMAL) /* no L1 */
1245 p_m_d_collect_cause = CAUSE_OUTOFORDER;
1246 p_m_d_collect_location = location;
1248 if (cause!=0 && cause!=CAUSE_NOUSER && p_m_d_collect_cause!=CAUSE_OUTOFORDER && p_m_d_collect_cause!=CAUSE_BUSY && p_m_d_collect_cause!=CAUSE_REJECTED && p_m_d_collect_cause!=CAUSE_NORMAL) /* anything if cause exists and not 18 */
1250 p_m_d_collect_cause = cause;
1251 p_m_d_collect_location = location;
1253 add_trace("new-cause", "location", "%d", p_m_d_collect_location);
1254 add_trace("new-cause", "value", "%d", p_m_d_collect_cause);
1258 /* CC_RELEASE INDICATION */
1259 void Pdss1::release_ind(unsigned long prim, unsigned long dinfo, void *data)
1261 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1262 RELEASE_t *release = (RELEASE_t *)((unsigned long)data + headerlen);
1264 int location, cause;
1265 struct message *message;
1267 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1268 dec_ie_cause(release->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1274 /* sending release to endpoint */
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 /* only in NT mode we must send release_complete, if we got a release confirm */
1286 if (prim == (CC_RELEASE | CONFIRM))
1288 /* sending release complete */
1289 RELEASE_COMPLETE_t *release_complete;
1291 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
1292 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
1293 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
1294 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16);
1296 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1299 new_state(PORT_STATE_RELEASE);
1303 /* CC_RELEASE_COMPLETE INDICATION */
1304 void Pdss1::release_complete_ind(unsigned long prim, unsigned long dinfo, void *data)
1306 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1307 RELEASE_COMPLETE_t *release_complete = (RELEASE_COMPLETE_t *)((unsigned long)data + headerlen);
1308 int location, cause;
1309 struct message *message;
1311 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1312 dec_ie_cause(release_complete->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1318 /* sending release to endpoint */
1321 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1322 message->param.disconnectinfo.cause = cause;
1323 message->param.disconnectinfo.location = location;
1324 message_put(message);
1326 free_epointlist(p_epointlist);
1329 new_state(PORT_STATE_RELEASE);
1334 void Pdss1::t312_timeout(unsigned long prim, unsigned long dinfo, void *data)
1336 struct message *message;
1338 // trace is done at message_isdn()
1340 /* sending release to endpoint */
1343 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1344 message->param.disconnectinfo.cause = p_m_d_collect_cause;
1345 message->param.disconnectinfo.location = p_m_d_collect_location;
1346 message_put(message);
1348 free_epointlist(p_epointlist);
1351 new_state(PORT_STATE_RELEASE);
1355 /* CC_NOTIFY INDICATION */
1356 void Pdss1::notify_ind(unsigned long prim, unsigned long dinfo, void *data)
1358 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1359 NOTIFY_t *notifying = (NOTIFY_t *)((unsigned long)data + headerlen);
1360 struct message *message;
1361 int notify, type, plan, present;
1363 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1364 dec_ie_notify(notifying->NOTIFY, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
1365 dec_ie_redir_dn(notifying->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)message->param.notifyinfo.id, sizeof(message->param.notifyinfo.id));
1368 if (!ACTIVE_EPOINT(p_epointlist))
1370 /* notification indicator */
1374 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1375 message->param.notifyinfo.notify = notify;
1376 /* redirection number */
1380 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1383 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1386 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1392 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1393 message->param.notifyinfo.present = INFO_PRESENT_NULL;
1396 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1399 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1402 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1405 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1408 message->param.notifyinfo.isdn_port = p_m_portnum;
1409 message_put(message);
1413 /* CC_HOLD INDICATION */
1414 void Pdss1::hold_ind(unsigned long prim, unsigned long dinfo, void *data)
1416 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1417 // HOLD_t *hold = (HOLD_t *)((unsigned long)data + headerlen);
1418 struct message *message;
1419 HOLD_REJECT_t *hold_reject;
1420 HOLD_ACKNOWLEDGE_t *hold_acknowledge;
1422 // class Endpoint *epoint;
1424 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1427 if (!ACTIVE_EPOINT(p_epointlist) || p_m_hold)
1429 dmsg = create_l3msg(CC_HOLD_REJECT | REQUEST, MT_HOLD_REJECT, dinfo, sizeof(HOLD_REJECT_t), p_m_d_ntmode);
1430 hold_reject = (HOLD_REJECT_t *)(dmsg->data + headerlen);
1431 l1l2l3_trace_header(p_m_mISDNport, this, CC_HOLD_REJECT | REQUEST, DIRECTION_OUT);
1432 enc_ie_cause(&hold_reject->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, p_m_hold?101:31); /* normal unspecified / incompatible state */
1433 add_trace("reason", NULL, "no endpoint");
1435 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1440 /* notify the hold of call */
1441 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1442 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_HOLD;
1443 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1444 message_put(message);
1446 /* deactivate bchannel */
1447 chan_trace_header(p_m_mISDNport, this, "CHANNEL RELEASE (hold)", DIRECTION_NONE);
1448 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1452 /* set hold state */
1455 epoint = find_epoint_id(ACTIVE_EPOINT(p_epointlist));
1456 if (epoint && p_m_d_ntmode)
1458 p_m_timeout = p_settings.tout_hold;
1463 /* acknowledge hold */
1464 dmsg = create_l3msg(CC_HOLD_ACKNOWLEDGE | REQUEST, MT_HOLD_ACKNOWLEDGE, dinfo, sizeof(HOLD_ACKNOWLEDGE_t), p_m_d_ntmode);
1465 hold_acknowledge = (HOLD_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1466 l1l2l3_trace_header(p_m_mISDNport, this, CC_HOLD_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1468 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1472 /* CC_RETRIEVE INDICATION */
1473 void Pdss1::retrieve_ind(unsigned long prim, unsigned long dinfo, void *data)
1475 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1476 RETRIEVE_t *retrieve = (RETRIEVE_t *)((unsigned long)data + headerlen);
1477 RETRIEVE_REJECT_t *retrieve_reject;
1478 RETRIEVE_ACKNOWLEDGE_t *retrieve_acknowledge;
1479 struct message *message;
1480 int channel, exclusive, cause;
1484 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1485 dec_ie_channel_id(retrieve->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
1490 cause = 101; /* incompatible state */
1493 dmsg = create_l3msg(CC_RETRIEVE_REJECT | REQUEST, MT_RETRIEVE_REJECT, dinfo, sizeof(RETRIEVE_REJECT_t), p_m_d_ntmode);
1494 retrieve_reject = (RETRIEVE_REJECT_t *)(dmsg->data + headerlen);
1495 l1l2l3_trace_header(p_m_mISDNport, this, CC_RETRIEVE_REJECT | REQUEST, DIRECTION_OUT);
1496 enc_ie_cause(&retrieve_reject->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, cause);
1498 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1503 /* notify the retrieve of call */
1504 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1505 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_RETRIEVAL;
1506 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1507 message_put(message);
1510 ret = channel = hunt_bchannel(channel, exclusive);
1515 ret = seize_bchannel(channel, 1);
1522 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_ACTIVATE);
1524 /* set hold state */
1528 /* acknowledge retrieve */
1529 dmsg = create_l3msg(CC_RETRIEVE_ACKNOWLEDGE | REQUEST, MT_RETRIEVE_ACKNOWLEDGE, dinfo, sizeof(RETRIEVE_ACKNOWLEDGE_t), p_m_d_ntmode);
1530 retrieve_acknowledge = (RETRIEVE_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1531 l1l2l3_trace_header(p_m_mISDNport, this, CC_RETRIEVE_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1532 enc_ie_channel_id(&retrieve_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
1534 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1537 /* CC_SUSPEND INDICATION */
1538 void Pdss1::suspend_ind(unsigned long prim, unsigned long dinfo, void *data)
1540 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1541 SUSPEND_t *suspend = (SUSPEND_t *)((unsigned long)data + headerlen);
1542 SUSPEND_ACKNOWLEDGE_t *suspend_acknowledge;
1543 SUSPEND_REJECT_t *suspend_reject;
1544 struct message *message;
1545 class Endpoint *epoint;
1546 unsigned char callid[8];
1549 int ret = -31; /* normal, unspecified */
1551 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1552 dec_ie_call_id(suspend->CALL_ID, (Q931_info_t *)((unsigned long)data+headerlen), callid, &len);
1555 if (!ACTIVE_EPOINT(p_epointlist))
1558 dmsg = create_l3msg(CC_SUSPEND_REJECT | REQUEST, MT_SUSPEND_REJECT, dinfo, sizeof(SUSPEND_REJECT_t), p_m_d_ntmode);
1559 suspend_reject = (SUSPEND_REJECT_t *)(dmsg->data + headerlen);
1560 l1l2l3_trace_header(p_m_mISDNport, this, CC_SUSPEND_REJECT | REQUEST, DIRECTION_OUT);
1561 enc_ie_cause(&suspend_reject->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1563 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1571 /* check if call id is in use */
1572 epoint = epoint_first;
1575 if (epoint->ep_park)
1577 if (epoint->ep_park_len == len)
1578 if (!memcmp(epoint->ep_park_callid, callid, len))
1580 ret = -84; /* call id in use */
1584 epoint = epoint->next;
1587 /* notify the hold of call */
1588 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1589 message->param.notifyinfo.notify = INFO_NOTIFY_USER_SUSPENDED;
1590 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1591 message_put(message);
1593 /* deactivate bchannel */
1594 chan_trace_header(p_m_mISDNport, this, "CHANNEL RELEASE (suspend)", DIRECTION_NONE);
1595 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1599 /* sending suspend to endpoint */
1600 while (p_epointlist)
1602 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_SUSPEND);
1603 memcpy(message->param.parkinfo.callid, callid, sizeof(message->param.parkinfo.callid));
1604 message->param.parkinfo.len = len;
1605 message_put(message);
1607 free_epointlist(p_epointlist);
1610 /* sending SUSPEND_ACKNOWLEDGE */
1611 dmsg = create_l3msg(CC_SUSPEND_ACKNOWLEDGE | REQUEST, MT_SUSPEND_ACKNOWLEDGE, dinfo, sizeof(SUSPEND_ACKNOWLEDGE_t), p_m_d_ntmode);
1612 suspend_acknowledge = (SUSPEND_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1613 l1l2l3_trace_header(p_m_mISDNport, this, CC_SUSPEND_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1615 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1617 new_state(PORT_STATE_RELEASE);
1621 /* CC_RESUME INDICATION */
1622 void Pdss1::resume_ind(unsigned long prim, unsigned long dinfo, void *data)
1624 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1625 RESUME_t *resume = (RESUME_t *)((unsigned long)data + headerlen);
1626 RESUME_REJECT_t *resume_reject;
1627 RESUME_ACKNOWLEDGE_t *resume_acknowledge;
1628 unsigned char callid[8];
1630 int channel, exclusive;
1632 class Endpoint *epoint;
1633 struct message *message;
1636 /* callref from nt-lib */
1639 /* nt-library now gives us the id via CC_RESUME */
1640 if (dinfo&(~0xff) == 0xff00)
1642 PERROR("fatal software error: l3-stack gives us a process id 0xff00-0xffff\n");
1645 l1l2l3_trace_header(p_m_mISDNport, this, CC_NEW_CR | INDICATION, DIRECTION_IN);
1647 add_trace("callref", "old", "0x%x", p_m_d_l3id);
1648 add_trace("callref", "new", "0x%x", dinfo);
1650 if (p_m_d_l3id&(~0xff) == 0xff00)
1651 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
1653 p_m_d_ces = resume->ces;
1656 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1657 dec_ie_call_id(resume->CALL_ID, (Q931_info_t *)((unsigned long)data+headerlen), callid, &len);
1660 /* if blocked, release call */
1661 if (p_m_mISDNport->ifport->block)
1670 /* channel_id (no channel is possible in message) */
1672 channel = -1; /* any channel */
1675 ret = channel = hunt_bchannel(channel, exclusive);
1680 ret = seize_bchannel(channel, 1);
1685 dmsg = create_l3msg(CC_RESUME_REJECT | REQUEST, MT_RESUME_REJECT, dinfo, sizeof(RESUME_REJECT_t), p_m_d_ntmode);
1686 resume_reject = (RESUME_REJECT_t *)(dmsg->data + headerlen);
1687 l1l2l3_trace_header(p_m_mISDNport, this, CC_RESUME_REJECT | REQUEST, DIRECTION_OUT);
1688 enc_ie_cause(&resume_reject->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1690 add_trace("reason", NULL, "port blocked");
1692 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1693 new_state(PORT_STATE_RELEASE);
1697 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_ACTIVATE);
1699 /* create endpoint */
1702 PERROR("SOFTWARE ERROR: incoming resume but already got an endpoint, exitting...\n");
1705 ret = -85; /* no call suspended */
1706 epoint = epoint_first;
1709 if (epoint->ep_park)
1711 ret = -83; /* suspended call exists, but this not */
1712 if (epoint->ep_park_len == len)
1713 if (!memcmp(epoint->ep_park_callid, callid, len))
1716 epoint = epoint->next;
1721 if (!(epointlist_new(epoint->ep_serial)))
1723 PERROR("no memory for epointlist\n");
1726 if (!(epoint->portlist_new(p_serial, p_type, p_m_mISDNport->earlyb)))
1728 PERROR("no memory for portlist\n");
1731 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RESUME);
1732 message_put(message);
1734 /* notify the resume of call */
1735 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1736 message->param.notifyinfo.notify = INFO_NOTIFY_USER_RESUMED;
1737 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1738 message_put(message);
1740 /* sending RESUME_ACKNOWLEDGE */
1741 dmsg = create_l3msg(CC_RESUME_ACKNOWLEDGE | REQUEST, MT_RESUME_ACKNOWLEDGE, dinfo, sizeof(RESUME_ACKNOWLEDGE_t), p_m_d_ntmode);
1742 resume_acknowledge = (RESUME_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1743 l1l2l3_trace_header(p_m_mISDNport, this, CC_RESUME_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1744 enc_ie_channel_id(&resume_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
1746 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1748 new_state(PORT_STATE_CONNECT);
1752 /* CC_FACILITY INDICATION */
1753 void Pdss1::facility_ind(unsigned long prim, unsigned long dinfo, void *data)
1755 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1756 FACILITY_t *facility = (FACILITY_t *)((unsigned long)data + headerlen);
1757 unsigned char facil[256];
1759 struct message *message;
1761 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1762 dec_ie_facility(facility->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), facil, &facil_len);
1769 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_FACILITY);
1770 message->param.facilityinfo.len = facil_len;
1771 memcpy(message->param.facilityinfo.data, facil, facil_len);
1772 message_put(message);
1777 * handler for isdn connections
1778 * incoming information are parsed and sent via message to the endpoint
1780 void Pdss1::message_isdn(unsigned long prim, unsigned long dinfo, void *data)
1787 case CC_TIMEOUT | INDICATION:
1790 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1791 timer_hex = *((int *)(((char *)data)+headerlen));
1793 if (timer_hex==0x312 && p_m_d_ntmode)
1795 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1796 add_trace("timer", NULL, "%x", timer_hex);
1798 t312_timeout(prim, dinfo, data);
1802 case CC_SETUP | INDICATION:
1803 if (p_state != PORT_STATE_IDLE)
1805 setup_ind(prim, dinfo, data);
1808 case CC_SETUP | CONFIRM:
1811 l1l2l3_trace_header(p_m_mISDNport, this, CC_NEW_CR | INDICATION, DIRECTION_IN);
1812 add_trace("callref", "old", "0x%x", p_m_d_l3id);
1813 /* nt-library now gives us a new id via CC_SETUP_CONFIRM */
1814 if ((p_m_d_l3id&0xff00) != 0xff00)
1815 PERROR(" strange setup-procid 0x%x\n", p_m_d_l3id);
1816 p_m_d_l3id = *((int *)(((u_char *)data)+ mISDNUSER_HEAD_SIZE));
1817 add_trace("callref", "new", "0x%x", p_m_d_l3id);
1822 case CC_INFORMATION | INDICATION:
1823 information_ind(prim, dinfo, data);
1826 case CC_SETUP_ACKNOWLEDGE | INDICATION:
1827 if (p_state != PORT_STATE_OUT_SETUP)
1829 PERROR("Pdss1(%s) received setup_acknowledge, but we are not in outgoing setup state, IGNORING.\n", p_name);
1832 setup_acknowledge_ind(prim, dinfo, data);
1835 case CC_PROCEEDING | INDICATION:
1836 if (p_state != PORT_STATE_OUT_SETUP
1837 && p_state != PORT_STATE_OUT_OVERLAP)
1839 PERROR("Pdss1(%s) received proceeding, but we are not in outgoing setup OR overlap state, IGNORING.\n", p_name);
1842 proceeding_ind(prim, dinfo, data);
1845 case CC_ALERTING | INDICATION:
1846 if (p_state != PORT_STATE_OUT_SETUP
1847 && p_state != PORT_STATE_OUT_OVERLAP
1848 && p_state != PORT_STATE_OUT_PROCEEDING)
1850 PERROR("Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding state, IGNORING.\n", p_name);
1853 alerting_ind(prim, dinfo, data);
1856 case CC_CONNECT | INDICATION:
1857 if (p_state != PORT_STATE_OUT_SETUP
1858 && p_state != PORT_STATE_OUT_OVERLAP
1859 && p_state != PORT_STATE_OUT_PROCEEDING
1860 && p_state != PORT_STATE_OUT_ALERTING)
1862 PERROR("Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding OR ALERTING state, IGNORING.\n", p_name);
1865 connect_ind(prim, dinfo, data);
1866 if (p_m_d_notify_pending)
1868 /* send pending notify message during connect */
1869 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
1870 message_free(p_m_d_notify_pending);
1871 p_m_d_notify_pending = NULL;
1875 case CC_CONNECT_ACKNOWLEDGE | INDICATION:
1876 case CC_CONNECT | CONFIRM:
1877 if (p_state == PORT_STATE_CONNECT_WAITING)
1878 new_state(PORT_STATE_CONNECT);
1879 if (p_m_d_notify_pending)
1881 /* send pending notify message during connect-ack */
1882 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
1883 message_free(p_m_d_notify_pending);
1884 p_m_d_notify_pending = NULL;
1888 case CC_DISCONNECT | INDICATION:
1889 disconnect_ind(prim, dinfo, data);
1892 case CC_RELEASE | CONFIRM:
1893 case CC_RELEASE | INDICATION:
1894 release_ind(prim, dinfo, data);
1897 case CC_RELEASE_COMPLETE | INDICATION:
1898 release_complete_ind(prim, dinfo, data);
1901 case CC_RELEASE_COMPLETE | CONFIRM:
1904 case CC_NOTIFY | INDICATION:
1905 notify_ind(prim, dinfo, data);
1908 case CC_HOLD | INDICATION:
1909 hold_ind(prim, dinfo, data);
1912 case CC_RETRIEVE | INDICATION:
1913 retrieve_ind(prim, dinfo, data);
1916 case CC_SUSPEND | INDICATION:
1917 suspend_ind(prim, dinfo, data);
1920 case CC_RESUME | INDICATION:
1921 resume_ind(prim, dinfo, data);
1924 case CC_FACILITY | INDICATION:
1925 facility_ind(prim, dinfo, data);
1928 case CC_RELEASE_CR | INDICATION:
1929 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_CR | INDICATION, DIRECTION_IN);
1930 add_trace("callref", NULL, "0x%x", p_m_d_l3id);
1934 if ((p_m_d_l3id&0xff00) == 0xff00)
1935 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
1939 /* sending release to endpoint in case we still have an endpoint
1940 * NOTE: this only happens if the stack releases due to layer1
1941 * or layer2 breakdown. otherwhise a release is received first.
1945 struct message *message;
1946 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1947 message->param.disconnectinfo.cause = (p_m_d_collect_cause!=CAUSE_NOUSER)?p_m_d_collect_cause:CAUSE_UNSPECIFIED;
1948 message->param.disconnectinfo.location = (p_m_d_collect_cause!=CAUSE_NOUSER)?p_m_d_collect_location:LOCATION_PRIVATE_LOCAL;
1949 message_put(message);
1951 free_epointlist(p_epointlist);
1953 new_state(PORT_STATE_RELEASE);
1957 case CC_NEW_CR | INDICATION:
1958 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1960 add_trace("callref", "old", "0x%x", p_m_d_l3id);
1963 new_l3id = *((int *)(((u_char *)data+mISDNUSER_HEAD_SIZE)));
1964 if (((new_l3id&0xff00)!=0xff00) && ((p_m_d_l3id&0xff00)==0xff00))
1965 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
1970 p_m_d_l3id = new_l3id;
1971 add_trace("callref", "new", "0x%x", p_m_d_l3id);
1976 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1977 add_trace("unhandled", "prim", "0x%x", prim);
1982 void Pdss1::new_state(int state)
1984 class Endpoint *epoint;
1987 epoint = find_epoint_id(ACTIVE_EPOINT(p_epointlist));
1988 if (epoint && p_m_d_ntmode)
1990 if (state == PORT_STATE_IN_OVERLAP)
1992 p_m_timeout = p_settings.tout_dialing;
1995 if (state != p_state)
1997 if (state == PORT_STATE_IN_SETUP
1998 || state == PORT_STATE_IN_OVERLAP)
2000 p_m_timeout = p_settings.tout_setup;
2003 if (state == PORT_STATE_IN_PROCEEDING
2004 || state == PORT_STATE_OUT_PROCEEDING)
2006 p_m_timeout = p_settings.tout_proceeding;
2009 if (state == PORT_STATE_IN_ALERTING
2010 || state == PORT_STATE_OUT_ALERTING)
2012 p_m_timeout = p_settings.tout_alerting;
2015 if (state == PORT_STATE_CONNECT
2016 || state == PORT_STATE_CONNECT_WAITING)
2020 if (state == PORT_STATE_IN_DISCONNECT
2021 || state == PORT_STATE_OUT_DISCONNECT)
2023 p_m_timeout = p_settings.tout_disconnect;
2029 Port::new_state(state);
2036 int Pdss1::handler(void)
2040 if ((ret = PmISDN::handler()))
2043 /* handle destruction */
2044 if (p_m_delete && p_m_d_l3id==0)
2055 * handles all messages from endpoint
2057 /* MESSAGE_INFORMATION */
2058 void Pdss1::message_information(unsigned long epoint_id, int message_id, union parameter *param)
2060 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2061 INFORMATION_t *information;
2064 if (param->information.id[0]) /* only if we have something to dial */
2066 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2067 information = (INFORMATION_t *)(dmsg->data + headerlen);
2068 l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT);
2069 enc_ie_called_pn(&information->CALLED_PN, dmsg, 0, 1, (unsigned char *)param->information.id);
2071 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2080 void Pdss1::message_setup(unsigned long epoint_id, int message_id, union parameter *param)
2082 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2083 INFORMATION_t *information;
2086 int plan, type, screen, present, reason;
2087 int capability, mode, rate, coding, user, presentation, interpretation, hlc, exthlc;
2088 int channel, exclusive;
2090 struct epoint_list *epointlist;
2092 /* release if port is blocked */
2093 if (p_m_mISDNport->ifport->block)
2095 struct message *message;
2097 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2098 message->param.disconnectinfo.cause = 27; // temp. unavail.
2099 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2100 message_put(message);
2101 new_state(PORT_STATE_RELEASE);
2106 /* copy setup infos to port */
2107 memcpy(&p_callerinfo, ¶m->setup.callerinfo, sizeof(p_callerinfo));
2108 memcpy(&p_dialinginfo, ¶m->setup.dialinginfo, sizeof(p_dialinginfo));
2109 memcpy(&p_capainfo, ¶m->setup.capainfo, sizeof(p_capainfo));
2110 memcpy(&p_redirinfo, ¶m->setup.redirinfo, sizeof(p_redirinfo));
2111 // SCPY(&p_m_tones_dir, param->setup.ext.tones_dir);
2113 /* only display at connect state: this case happens if endpoint is in connected mode */
2114 if (p_state==PORT_STATE_CONNECT)
2116 if (p_type!=PORT_TYPE_DSS1_NT_OUT
2117 && p_type!=PORT_TYPE_DSS1_NT_IN)
2119 if (p_callerinfo.display[0])
2121 /* sending information */
2122 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2123 information = (INFORMATION_t *)(dmsg->data + headerlen);
2124 l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT);
2126 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_callerinfo.display);
2128 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2133 /* attach only if not already */
2134 epointlist = p_epointlist;
2137 if (epointlist->epoint_id == epoint_id)
2139 epointlist = epointlist->next;
2143 if (!(epointlist_new(epoint_id)))
2145 PERROR("no memory for epointlist\n");
2154 channel = p_m_b_channel;
2155 exclusive = p_m_b_exclusive;
2157 channel = CHANNEL_ANY;
2158 /* nt-port with no channel, not reserverd */
2159 if (!p_m_b_channel && !p_m_b_reserve && p_type==PORT_TYPE_DSS1_NT_OUT)
2160 channel = CHANNEL_NO;
2163 l1l2l3_trace_header(p_m_mISDNport, this, CC_NEW_CR | REQUEST, DIRECTION_OUT);
2169 if (p_m_mISDNport->procids[i] == 0)
2175 struct message *message;
2177 add_trace("callref", NULL, "no free id");
2179 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2180 message->param.disconnectinfo.cause = 47;
2181 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2182 message_put(message);
2183 new_state(PORT_STATE_RELEASE);
2187 p_m_mISDNport->procids[i] = 1;
2188 p_m_d_l3id = 0xff00 | i;
2192 /* if we are in te-mode, we need to create a process first */
2193 if (newteid++ > 0x7fff)
2195 p_m_d_l3id = (entity<<16) | newteid;
2196 /* preparing message */
2197 ncr.prim = CC_NEW_CR | REQUEST;
2198 ncr.addr = p_m_mISDNport->upper_id | FLG_MSG_DOWN;
2199 ncr.dinfo = p_m_d_l3id;
2202 mISDN_write(mISDNdevice, &ncr, mISDN_HEADER_LEN+ncr.len, TIMEOUT_1SEC);
2206 add_trace("callref", "new", "0x%x", p_m_d_l3id);
2209 /* preparing setup message */
2210 dmsg = create_l3msg(CC_SETUP | REQUEST, MT_SETUP, p_m_d_l3id, sizeof(SETUP_t), p_m_d_ntmode);
2211 setup = (SETUP_t *)(dmsg->data + headerlen);
2212 l1l2l3_trace_header(p_m_mISDNport, this, CC_SETUP | REQUEST, DIRECTION_OUT);
2213 /* channel information */
2214 if (channel >= 0) /* it should */
2216 enc_ie_channel_id(&setup->CHANNEL_ID, dmsg, exclusive, channel);
2218 /* caller information */
2220 switch (p_callerinfo.ntype)
2222 case INFO_NTYPE_INTERNATIONAL:
2225 case INFO_NTYPE_NATIONAL:
2228 case INFO_NTYPE_SUBSCRIBER:
2231 default: /* INFO_NTYPE_UNKNOWN */
2235 switch (p_callerinfo.screen)
2237 case INFO_SCREEN_USER:
2240 default: /* INFO_SCREEN_NETWORK */
2244 switch (p_callerinfo.present)
2246 case INFO_PRESENT_RESTRICTED:
2249 case INFO_PRESENT_NOTAVAIL:
2252 default: /* INFO_PRESENT_ALLOWED */
2257 enc_ie_calling_pn(&setup->CALLING_PN, dmsg, type, plan, present, screen, (unsigned char *)p_callerinfo.id);
2258 /* dialing information */
2259 if (p_dialinginfo.id[0]) /* only if we have something to dial */
2261 enc_ie_called_pn(&setup->CALLED_PN, dmsg, 0, 1, (unsigned char *)p_dialinginfo.id);
2263 /* sending complete */
2264 if (p_dialinginfo.sending_complete)
2265 enc_ie_complete(&setup->COMPLETE, dmsg, 1);
2266 /* sending user-user */
2267 if (param->setup.useruser.len)
2269 enc_ie_useruser(&setup->USER_USER, dmsg, param->setup.useruser.protocol, param->setup.useruser.data, param->setup.useruser.len);
2271 /* redirecting number */
2273 switch (p_redirinfo.ntype)
2275 case INFO_NTYPE_INTERNATIONAL:
2278 case INFO_NTYPE_NATIONAL:
2281 case INFO_NTYPE_SUBSCRIBER:
2284 default: /* INFO_NTYPE_UNKNOWN */
2288 switch (p_redirinfo.screen)
2290 case INFO_SCREEN_USER:
2293 default: /* INFO_SCREE_NETWORK */
2297 switch (p_redirinfo.reason)
2299 case INFO_REDIR_BUSY:
2302 case INFO_REDIR_NORESPONSE:
2305 case INFO_REDIR_UNCONDITIONAL:
2308 case INFO_REDIR_CALLDEFLECT:
2311 case INFO_REDIR_OUTOFORDER:
2314 default: /* INFO_REDIR_UNKNOWN */
2318 switch (p_redirinfo.present)
2320 case INFO_PRESENT_NULL: /* no redir at all */
2327 case INFO_PRESENT_RESTRICTED:
2330 case INFO_PRESENT_NOTAVAIL:
2333 default: /* INFO_PRESENT_ALLOWED */
2337 /* sending redirecting number only in ntmode */
2338 if (type >= 0 && p_m_d_ntmode)
2339 enc_ie_redir_nr(&setup->REDIR_NR, dmsg, type, plan, present, screen, reason, (unsigned char *)p_redirinfo.id);
2340 /* bearer capability */
2341 //printf("hlc=%d\n",p_capainfo.hlc);
2343 capability = p_capainfo.bearer_capa;
2344 mode = p_capainfo.bearer_mode;
2345 rate = (mode==INFO_BMODE_CIRCUIT)?0x10:0x00;
2346 switch (p_capainfo.bearer_info1)
2348 case INFO_INFO1_NONE:
2352 user = p_capainfo.bearer_info1 & 0x7f;
2355 enc_ie_bearer(&setup->BEARER, dmsg, coding, capability, mode, rate, -1, user);
2362 hlc = p_capainfo.hlc & 0x7f;
2364 if (p_capainfo.exthlc)
2365 exthlc = p_capainfo.exthlc & 0x7f;
2366 enc_ie_hlc(&setup->HLC, dmsg, coding, interpretation, presentation, hlc, exthlc);
2370 if (p_callerinfo.display[0] && p_m_d_ntmode)
2371 enc_ie_display(&setup->DISPLAY, dmsg, (unsigned char *)p_callerinfo.display);
2373 /* nt-mode: CNIP (calling name identification presentation) */
2374 if (p_callerinfo.name[0] && p_m_d_ntmode)
2375 enc_facility_centrex(&setup->FACILITY, dmsg, (unsigned char *)p_callerinfo.name, 1);
2379 /* send setup message now */
2380 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2382 new_state(PORT_STATE_OUT_SETUP);
2385 /* MESSAGE_FACILITY */
2386 void Pdss1::message_facility(unsigned long epoint_id, int message_id, union parameter *param)
2388 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2389 FACILITY_t *facility;
2392 /* facility will not be sent to external lines */
2396 /* sending facility */
2397 dmsg = create_l3msg(CC_FACILITY | REQUEST, MT_FACILITY, p_m_d_l3id, sizeof(FACILITY_t), p_m_d_ntmode);
2398 facility = (FACILITY_t *)(dmsg->data + headerlen);
2399 l1l2l3_trace_header(p_m_mISDNport, this, CC_FACILITY | REQUEST, DIRECTION_OUT);
2400 enc_ie_facility(&facility->FACILITY, dmsg, (unsigned char *)param->facilityinfo.data, param->facilityinfo.len);
2402 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2405 /* MESSAGE_NOTIFY */
2406 void Pdss1::message_notify(unsigned long epoint_id, int message_id, union parameter *param)
2408 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2409 INFORMATION_t *information;
2410 NOTIFY_t *notification;
2412 int plan, type = -1, present;
2415 if (param->notifyinfo.notify>INFO_NOTIFY_NONE)
2416 notify = param->notifyinfo.notify & 0x7f;
2419 if (p_state != PORT_STATE_CONNECT)
2421 /* notify only allowed in active state */
2427 switch (param->notifyinfo.ntype)
2429 case INFO_NTYPE_INTERNATIONAL:
2432 case INFO_NTYPE_NATIONAL:
2435 case INFO_NTYPE_SUBSCRIBER:
2438 default: /* INFO_NTYPE_UNKNOWN */
2442 switch (param->notifyinfo.present)
2444 case INFO_PRESENT_NULL: /* no redir at all */
2449 case INFO_PRESENT_RESTRICTED:
2452 case INFO_PRESENT_NOTAVAIL:
2455 default: /* INFO_PRESENT_ALLOWED */
2461 if (notify<0 && !param->notifyinfo.display[0])
2463 /* nothing to notify, nothing to display */
2469 if (p_state!=PORT_STATE_CONNECT)
2471 /* queue notification */
2472 if (p_m_d_notify_pending)
2473 message_free(p_m_d_notify_pending);
2474 p_m_d_notify_pending = message_create(ACTIVE_EPOINT(p_epointlist), p_serial, EPOINT_TO_PORT, message_id);
2475 memcpy(&p_m_d_notify_pending->param, param, sizeof(union parameter));
2478 /* sending notification */
2479 dmsg = create_l3msg(CC_NOTIFY | REQUEST, MT_NOTIFY, p_m_d_l3id, sizeof(NOTIFY_t), p_m_d_ntmode);
2480 notification = (NOTIFY_t *)(dmsg->data + headerlen);
2481 l1l2l3_trace_header(p_m_mISDNport, this, CC_NOTIFY | REQUEST, DIRECTION_OUT);
2482 enc_ie_notify(¬ification->NOTIFY, dmsg, notify);
2483 /* sending redirection number only in ntmode */
2484 if (type >= 0 && p_m_d_ntmode)
2485 enc_ie_redir_dn(¬ification->REDIR_DN, dmsg, type, plan, present, (unsigned char *)param->notifyinfo.id);
2486 if (param->notifyinfo.display[0] && p_m_d_ntmode)
2487 enc_ie_display(¬ification->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display);
2489 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2491 } else if (p_m_d_ntmode)
2493 /* sending information */
2494 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2495 information = (INFORMATION_t *)(dmsg->data + headerlen);
2496 l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT);
2497 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display);
2499 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2503 /* MESSAGE_OVERLAP */
2504 void Pdss1::message_overlap(unsigned long epoint_id, int message_id, union parameter *param)
2506 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2507 SETUP_ACKNOWLEDGE_t *setup_acknowledge;
2510 /* sending setup_acknowledge */
2511 dmsg = create_l3msg(CC_SETUP_ACKNOWLEDGE | REQUEST, MT_SETUP_ACKNOWLEDGE, p_m_d_l3id, sizeof(SETUP_ACKNOWLEDGE_t), p_m_d_ntmode);
2512 setup_acknowledge = (SETUP_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
2513 l1l2l3_trace_header(p_m_mISDNport, this, CC_SETUP_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
2514 /* channel information */
2515 if (p_state == PORT_STATE_IN_SETUP)
2516 enc_ie_channel_id(&setup_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2517 /* progress information */
2518 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2519 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2520 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2521 if (p_m_mISDNport->tones)
2522 enc_ie_progress(&setup_acknowledge->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2524 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2526 new_state(PORT_STATE_IN_OVERLAP);
2529 /* MESSAGE_PROCEEDING */
2530 void Pdss1::message_proceeding(unsigned long epoint_id, int message_id, union parameter *param)
2532 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2533 CALL_PROCEEDING_t *proceeding;
2536 /* sending proceeding */
2537 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2538 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2539 l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2540 /* channel information */
2541 if (p_state == PORT_STATE_IN_SETUP)
2542 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2543 /* progress information */
2544 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2545 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2546 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2547 if (p_m_mISDNport->tones)
2548 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2550 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2552 new_state(PORT_STATE_IN_PROCEEDING);
2555 /* MESSAGE_ALERTING */
2556 void Pdss1::message_alerting(unsigned long epoint_id, int message_id, union parameter *param)
2558 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2559 ALERTING_t *alerting;
2562 /* NT-MODE in setup state we must send PROCEEDING first */
2563 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2565 CALL_PROCEEDING_t *proceeding;
2567 /* sending proceeding */
2568 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2569 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2570 l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2571 /* channel information */
2572 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2573 /* progress information */
2574 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2575 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2576 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2577 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2579 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2580 new_state(PORT_STATE_IN_PROCEEDING);
2583 /* sending alerting */
2584 dmsg = create_l3msg(CC_ALERTING | REQUEST, MT_ALERTING, p_m_d_l3id, sizeof(ALERTING_t), p_m_d_ntmode);
2585 alerting = (ALERTING_t *)(dmsg->data + headerlen);
2586 l1l2l3_trace_header(p_m_mISDNport, this, CC_ALERTING | REQUEST, DIRECTION_OUT);
2587 /* channel information */
2588 if (p_state == PORT_STATE_IN_SETUP)
2589 enc_ie_channel_id(&alerting->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2590 /* progress information */
2591 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2592 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2593 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2594 if (p_m_mISDNport->tones)
2595 enc_ie_progress(&alerting->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2597 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2599 new_state(PORT_STATE_IN_ALERTING);
2602 /* MESSAGE_CONNECT */
2603 void Pdss1::message_connect(unsigned long epoint_id, int message_id, union parameter *param)
2605 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2606 INFORMATION_t *information;
2608 int type, plan, present, screen;
2610 class Endpoint *epoint;
2612 /* NT-MODE in setup state we must send PROCEEDING first */
2613 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2615 CALL_PROCEEDING_t *proceeding;
2617 /* sending proceeding */
2618 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2619 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2620 l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2621 /* channel information */
2622 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2623 // /* progress information */
2624 // if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2625 // || p_capainfo.bearer_capa==INFO_BC_AUDIO
2626 // || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2627 // enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2629 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2630 new_state(PORT_STATE_IN_PROCEEDING);
2633 /* copy connected information */
2634 memcpy(&p_connectinfo, ¶m->connectinfo, sizeof(p_connectinfo));
2636 /* only display at connect state */
2637 if (p_state == PORT_STATE_CONNECT)
2638 if (p_connectinfo.display[0])
2640 /* sending information */
2641 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2642 information = (INFORMATION_t *)(dmsg->data + headerlen);
2643 l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT);
2645 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_connectinfo.display);
2647 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2651 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)
2653 /* connect command only possible in setup, proceeding or alerting state */
2657 /* preparing connect message */
2658 dmsg = create_l3msg(CC_CONNECT | REQUEST, MT_CONNECT, p_m_d_l3id, sizeof(CONNECT_t), p_m_d_ntmode);
2659 connect = (CONNECT_t *)(dmsg->data + headerlen);
2660 l1l2l3_trace_header(p_m_mISDNport, this, CC_CONNECT | REQUEST, DIRECTION_OUT);
2661 /* connect information */
2663 switch (p_connectinfo.ntype)
2665 case INFO_NTYPE_INTERNATIONAL:
2668 case INFO_NTYPE_NATIONAL:
2671 case INFO_NTYPE_SUBSCRIBER:
2674 default: /* INFO_NTYPE_UNKNOWN */
2678 switch (param->connectinfo.screen)
2680 case INFO_SCREEN_USER:
2683 default: /* INFO_SCREE_NETWORK */
2687 switch (p_connectinfo.present)
2689 case INFO_PRESENT_NULL: /* no colp at all */
2695 case INFO_PRESENT_RESTRICTED:
2698 case INFO_PRESENT_NOTAVAIL:
2701 default: /* INFO_PRESENT_ALLOWED */
2706 enc_ie_connected_pn(&connect->CONNECT_PN, dmsg, type, plan, present, screen, (unsigned char *)p_connectinfo.id);
2708 if (p_connectinfo.display[0] && p_m_d_ntmode)
2709 enc_ie_display(&connect->DISPLAY, dmsg, (unsigned char *)p_connectinfo.display);
2711 /* nt-mode: CONP (connected name identification presentation) */
2712 if (p_connectinfo.name[0] && p_m_d_ntmode)
2713 enc_facility_centrex(&connect->FACILITY, dmsg, (unsigned char *)p_connectinfo.name, 0);
2718 epoint = find_epoint_id(epoint_id);
2719 enc_ie_date(&connect->DATE, dmsg, now, p_settings.no_seconds);
2722 /* finally send message */
2723 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2726 new_state(PORT_STATE_CONNECT);
2728 new_state(PORT_STATE_CONNECT_WAITING);
2732 /* MESSAGE_DISCONNECT */
2733 void Pdss1::message_disconnect(unsigned long epoint_id, int message_id, union parameter *param)
2735 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2736 DISCONNECT_t *disconnect;
2737 RELEASE_COMPLETE_t *release_complete;
2739 struct message *message;
2742 /* we reject during incoming setup when we have no tones. also if we are in outgoing setup state */
2743 if ((p_state==PORT_STATE_IN_SETUP && !p_m_mISDNport->tones)
2744 || p_state==PORT_STATE_OUT_SETUP)
2746 /* sending release to endpoint */
2749 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
2750 message->param.disconnectinfo.cause = 16;
2751 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2752 message_put(message);
2754 free_epointlist(p_epointlist);
2756 /* sending release */
2757 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
2758 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
2759 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
2761 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2763 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2764 new_state(PORT_STATE_RELEASE);
2769 /* NT-MODE in setup state we must send PROCEEDING first */
2770 if (p_state==PORT_STATE_IN_SETUP)
2772 CALL_PROCEEDING_t *proceeding;
2774 /* sending proceeding */
2775 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2776 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2777 l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2778 /* channel information */
2779 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2780 /* progress information */
2781 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2782 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2783 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2784 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2786 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2787 new_state(PORT_STATE_IN_PROCEEDING);
2790 /* sending disconnect */
2791 dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode);
2792 disconnect = (DISCONNECT_t *)(dmsg->data + headerlen);
2793 l1l2l3_trace_header(p_m_mISDNport, this, CC_DISCONNECT | REQUEST, DIRECTION_OUT);
2794 /* progress information */
2795 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2796 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2797 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2798 if (p_m_mISDNport->tones)
2799 enc_ie_progress(&disconnect->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2801 enc_ie_cause(&disconnect->CAUSE, dmsg, (p_m_d_ntmode && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2803 if (param->disconnectinfo.display[0])
2804 p = param->disconnectinfo.display;
2805 if (p) if (*p && p_m_d_ntmode)
2806 enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p);
2808 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2809 new_state(PORT_STATE_OUT_DISCONNECT);
2812 /* MESSAGE_RELEASE */
2813 void Pdss1::message_release(unsigned long epoint_id, int message_id, union parameter *param)
2815 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2817 RELEASE_COMPLETE_t *release_complete;
2818 DISCONNECT_t *disconnect;
2820 class Endpoint *epoint;
2823 /* if we have incoming disconnected, we may release */
2824 if (p_state==PORT_STATE_IN_DISCONNECT
2825 || p_state==PORT_STATE_OUT_DISCONNECT)
2827 /* sending release */
2828 dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, p_m_d_l3id, sizeof(RELEASE_t), p_m_d_ntmode);
2829 release = (RELEASE_t *)(dmsg->data + headerlen);
2830 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE | REQUEST, DIRECTION_OUT);
2832 enc_ie_cause(&release->CAUSE, dmsg, (p_m_d_ntmode && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2834 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2835 new_state(PORT_STATE_RELEASE);
2839 /* if we are on outgoing/incoming call setup, we may release complete */
2840 if (p_state==PORT_STATE_OUT_SETUP
2841 || p_state==PORT_STATE_IN_SETUP
2842 // NOTE: a bug in mISDNuser (see disconnect_req_out !!!)
2843 || p_state==PORT_STATE_OUT_PROCEEDING)
2845 /* sending release */
2846 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
2847 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
2848 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE | REQUEST, DIRECTION_OUT);
2850 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2852 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2853 new_state(PORT_STATE_RELEASE);
2856 free_epointid(epoint_id);
2857 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_CR | REQUEST, DIRECTION_OUT);
2858 add_trace("callref", NULL, "0x%x", p_m_d_l3id);
2862 if ((p_m_d_l3id&0xff00) == 0xff00)
2863 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
2870 /* NT-MODE in setup state we must send PROCEEDING first */
2871 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2873 CALL_PROCEEDING_t *proceeding;
2875 /* sending proceeding */
2876 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2877 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2878 l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2879 /* channel information */
2880 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2881 /* progress information */
2882 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2883 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2884 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2885 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2887 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2890 /* sending disconnect */
2891 dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode);
2892 disconnect = (DISCONNECT_t *)(dmsg->data + headerlen);
2893 l1l2l3_trace_header(p_m_mISDNport, this, CC_DISCONNECT | REQUEST, DIRECTION_OUT);
2894 /* progress information */
2895 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2896 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2897 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2898 if (p_m_mISDNport->tones)
2899 enc_ie_progress(&disconnect->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2901 enc_ie_cause(&disconnect->CAUSE, dmsg, (p_m_d_ntmode && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2903 epoint = find_epoint_id(epoint_id);
2904 if (param->disconnectinfo.display[0])
2905 p = param->disconnectinfo.display;
2906 if (p) if (*p && p_m_d_ntmode)
2907 enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p);
2909 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2910 new_state(PORT_STATE_RELEASE);
2911 free_epointid(epoint_id);
2917 * endpoint sends messages to the port
2919 int Pdss1::message_epoint(unsigned long epoint_id, int message_id, union parameter *param)
2921 struct message *message;
2923 if (PmISDN::message_epoint(epoint_id, message_id, param))
2928 case MESSAGE_INFORMATION: /* overlap dialing */
2929 if (p_type==PORT_TYPE_DSS1_NT_OUT
2930 && p_state!=PORT_STATE_OUT_OVERLAP
2931 && p_state!=PORT_STATE_CONNECT
2932 && p_state!=PORT_STATE_OUT_DISCONNECT
2933 && p_state!=PORT_STATE_IN_DISCONNECT)
2937 if (p_type==PORT_TYPE_DSS1_TE_OUT
2938 && p_state!=PORT_STATE_OUT_OVERLAP
2939 && p_state!=PORT_STATE_OUT_PROCEEDING
2940 && p_state!=PORT_STATE_OUT_ALERTING
2941 && p_state!=PORT_STATE_CONNECT
2942 && p_state!=PORT_STATE_OUT_DISCONNECT
2943 && p_state!=PORT_STATE_IN_DISCONNECT)
2947 if ((p_type==PORT_TYPE_DSS1_NT_IN || p_type==PORT_TYPE_DSS1_TE_IN)
2948 && p_state!=PORT_STATE_IN_OVERLAP
2949 && p_state!=PORT_STATE_IN_PROCEEDING
2950 && p_state!=PORT_STATE_IN_ALERTING
2951 && p_state!=PORT_STATE_CONNECT
2952 && p_state!=PORT_STATE_CONNECT_WAITING
2953 && p_state!=PORT_STATE_OUT_DISCONNECT
2954 && p_state!=PORT_STATE_IN_DISCONNECT)
2958 message_information(epoint_id, message_id, param);
2961 case MESSAGE_SETUP: /* dial-out command received from epoint */
2962 if (p_state!=PORT_STATE_IDLE
2963 && p_state!=PORT_STATE_CONNECT)
2965 PERROR("Pdss1(%s) ignoring setup because isdn port is not in idle state (or connected for sending display info).\n", p_name);
2968 if (p_epointlist && p_state==PORT_STATE_IDLE)
2970 PERROR("Pdss1(%s): software error: epoint pointer is set in idle state, how bad!! exitting.\n", p_name);
2973 /* note: pri is a special case, because links must be up for pri */
2974 if (p_m_mISDNport->l1link || p_m_mISDNport->pri || !p_m_mISDNport->ntmode || p_state!=PORT_STATE_IDLE)
2976 /* LAYER 1 is up, or we may send */
2977 message_setup(epoint_id, message_id, param);
2980 /* LAYER 1 id down, so we queue */
2981 p_m_d_queue = message_create(epoint_id, p_serial, EPOINT_TO_PORT, message_id);
2982 memcpy(&p_m_d_queue->param, param, sizeof(union parameter));
2984 if (!(epointlist_new(epoint_id)))
2986 PERROR("no memory for epointlist\n");
2990 PDEBUG(DEBUG_ISDN, "the L1 is down, we try to establish the link NT portnum=%d (%s).\n", p_m_mISDNport->portnum, p_name);
2991 act.prim = PH_ACTIVATE | REQUEST;
2992 act.addr = p_m_mISDNport->upper_id | FLG_MSG_DOWN;
2995 mISDN_write(mISDNdevice, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
2996 l1l2l3_trace_header(p_m_mISDNport, this, act.prim, DIRECTION_OUT);
2998 // /* set timeout */
2999 // p_m_mISDNport->l1timeout = now+3;
3003 case MESSAGE_NOTIFY: /* display and notifications */
3004 message_notify(epoint_id, message_id, param);
3007 case MESSAGE_FACILITY: /* facility message */
3008 message_facility(epoint_id, message_id, param);
3011 case MESSAGE_OVERLAP: /* more information is needed */
3012 if (p_state!=PORT_STATE_IN_SETUP)
3016 message_overlap(epoint_id, message_id, param);
3019 case MESSAGE_PROCEEDING: /* call of endpoint is proceeding */
3020 if (p_state!=PORT_STATE_IN_SETUP
3021 && p_state!=PORT_STATE_IN_OVERLAP)
3025 message_proceeding(epoint_id, message_id, param);
3028 case MESSAGE_ALERTING: /* call of endpoint is ringing */
3029 if (p_state!=PORT_STATE_IN_SETUP
3030 && p_state!=PORT_STATE_IN_OVERLAP
3031 && p_state!=PORT_STATE_IN_PROCEEDING)
3035 message_alerting(epoint_id, message_id, param);
3038 case MESSAGE_CONNECT: /* call of endpoint is connected */
3039 if (p_state!=PORT_STATE_IN_SETUP
3040 && p_state!=PORT_STATE_IN_OVERLAP
3041 && p_state!=PORT_STATE_IN_PROCEEDING
3042 && p_state!=PORT_STATE_IN_ALERTING
3043 && !(p_state==PORT_STATE_CONNECT && p_m_d_ntmode))
3047 message_connect(epoint_id, message_id, param);
3050 case MESSAGE_DISCONNECT: /* call has been disconnected */
3051 if (p_state!=PORT_STATE_IN_SETUP
3052 && p_state!=PORT_STATE_IN_OVERLAP
3053 && p_state!=PORT_STATE_IN_PROCEEDING
3054 && p_state!=PORT_STATE_IN_ALERTING
3055 && p_state!=PORT_STATE_OUT_SETUP
3056 && p_state!=PORT_STATE_OUT_OVERLAP
3057 && p_state!=PORT_STATE_OUT_PROCEEDING
3058 && p_state!=PORT_STATE_OUT_ALERTING
3059 && p_state!=PORT_STATE_CONNECT
3060 && p_state!=PORT_STATE_CONNECT_WAITING)
3064 message_disconnect(epoint_id, message_id, param);
3067 case MESSAGE_RELEASE: /* release isdn port */
3068 if (p_state==PORT_STATE_RELEASE)
3072 message_release(epoint_id, message_id, param);
3076 PERROR("Pdss1(%s) isdn port with (caller id %s) received a wrong message: %d\n", p_name, p_callerinfo.id, message);
3085 * data from isdn-stack (layer-3) to pbx (port class)
3087 /* NOTE: nt mode use mISDNuser_head_t as header */
3088 int stack2manager_nt(void *dat, void *arg)
3092 manager_t *mgr = (manager_t *)dat;
3093 msg_t *msg = (msg_t *)arg;
3094 mISDNuser_head_t *hh;
3095 struct mISDNport *mISDNport;
3101 /* note: nst is the first data feld of mISDNport */
3102 mISDNport = (struct mISDNport *)mgr->nst;
3104 hh = (mISDNuser_head_t *)msg->data;
3105 PDEBUG(DEBUG_ISDN, "prim(0x%x) dinfo(0x%x) msg->len(%d)\n", hh->prim, hh->dinfo, msg->len);
3107 /* find Port object of type ISDN */
3111 if (port->p_type == PORT_TYPE_DSS1_NT_IN || port->p_type == PORT_TYPE_DSS1_NT_OUT)
3113 pdss1 = (class Pdss1 *)port;
3114 //PDEBUG(DEBUG_ISDN, "comparing dinfo = 0x%x with l3id 0x%x\n", hh->dinfo, pdss1->p_m_d_l3id);
3115 /* check out correct stack */
3116 if (pdss1->p_m_mISDNport == mISDNport)
3117 /* check out correct id */
3118 if ((hh->dinfo&0xffff0000) == (pdss1->p_m_d_l3id&0xffff0000))
3120 /* found port, the message belongs to */
3128 /* if process id is master process, but a child disconnects */
3129 if ((hh->dinfo&0x0000ff00)!=0x0000ff00 && (pdss1->p_m_d_l3id&0x0000ff00)==0x0000ff00 && hh->prim==(CC_DISCONNECT|INDICATION))
3131 /* send special indication for child disconnect */
3132 pdss1->disconnect_ind_i(hh->prim, hh->dinfo, msg->data);
3136 /* if process id and layer 3 id matches */
3137 if (hh->dinfo == pdss1->p_m_d_l3id)
3139 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
3148 case MGR_SHORTSTATUS | INDICATION:
3149 case MGR_SHORTSTATUS | CONFIRM:
3151 case SSTATUS_L2_ESTABLISHED:
3153 case SSTATUS_L2_RELEASED:
3158 case DL_ESTABLISH | INDICATION:
3159 case DL_ESTABLISH | CONFIRM:
3161 l1l2l3_trace_header(mISDNport, NULL, hh->prim, DIRECTION_IN);
3162 add_trace("tei", NULL, "%d", hh->dinfo);
3164 if (mISDNport->ptp && hh->dinfo == 0)
3166 if (mISDNport->l2establish)
3168 mISDNport->l2establish = 0;
3169 PDEBUG(DEBUG_ISDN, "the link became active before l2establish timer expiry.\n");
3171 mISDNport->l2link = 1;
3172 if (mISDNport->pri);
3173 mISDNport->l1link = 1; /* this is a hack, we also assume L1 to be active */
3177 case DL_RELEASE | INDICATION:
3178 case DL_RELEASE | CONFIRM:
3180 l1l2l3_trace_header(mISDNport, NULL, hh->prim, DIRECTION_IN);
3181 add_trace("tei", NULL, "%d", hh->dinfo);
3183 if (mISDNport->ptp && hh->dinfo == 0)
3185 mISDNport->l2link = 0;
3186 time(&mISDNport->l2establish);
3187 PDEBUG(DEBUG_ISDN, "because we are ptp, we set a l2establish timer.\n");
3191 case CC_SETUP | INDICATION:
3192 /* creating port object */
3193 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3194 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0)))
3196 RELEASE_COMPLETE_t *release_complete;
3199 PERROR("FATAL ERROR: cannot create port object.\n");
3200 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, hh->dinfo, sizeof(RELEASE_COMPLETE_t), mISDNport->ntmode);
3201 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + mISDN_HEADER_LEN);
3202 l1l2l3_trace_header(mISDNport, NULL, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
3203 enc_ie_cause_standalone(mISDNport->ntmode?&release_complete->CAUSE:NULL, dmsg, (mISDNport->ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47);
3205 msg_queue_tail(&mISDNport->downqueue, dmsg);
3208 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
3211 case CC_RESUME | INDICATION:
3212 /* creating port object */
3213 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3214 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0)))
3216 SUSPEND_REJECT_t *suspend_reject;
3219 PERROR("FATAL ERROR: cannot create port object.\n");
3220 dmsg = create_l3msg(CC_SUSPEND_REJECT | REQUEST, MT_SUSPEND_REJECT, hh->dinfo, sizeof(SUSPEND_REJECT_t), mISDNport->ntmode);
3221 suspend_reject = (SUSPEND_REJECT_t *)(dmsg->data + mISDN_HEADER_LEN);
3222 l1l2l3_trace_header(mISDNport, NULL, CC_SUSPEND_REJECT | REQUEST, DIRECTION_OUT);
3223 enc_ie_cause_standalone(mISDNport->ntmode?&suspend_reject->CAUSE:NULL, dmsg, (mISDNport->ntmode)?1:0, 47);
3225 msg_queue_tail(&mISDNport->downqueue, dmsg);
3228 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
3231 case CC_RELEASE_CR | INDICATION:
3232 PERROR("unhandled message from stack: call ref released (l3id=0x%x)\n", hh->dinfo);
3235 case CC_DISCONNECT | INDICATION:
3239 PERROR("unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", hh->prim, hh->dinfo, msg->len);
3246 /* NOTE: te mode use iframe_t as header */
3247 int stack2manager_te(struct mISDNport *mISDNport, msg_t *msg)
3254 if (!msg || !mISDNport)
3256 frm = (iframe_t *)msg->data;
3257 PDEBUG(DEBUG_ISDN, "prim(0x%x) dinfo(0x%x) msg->len(%d)\n", frm->prim, frm->dinfo, msg->len);
3259 /* find Port object of type ISDN */
3263 if (port->p_type == PORT_TYPE_DSS1_TE_IN || port->p_type == PORT_TYPE_DSS1_TE_OUT)
3265 pdss1 = (class Pdss1 *)port;
3266 /* check out correct stack */
3267 if (pdss1->p_m_mISDNport == mISDNport)
3268 /* check out correct id */
3269 if (frm->dinfo == pdss1->p_m_d_l3id)
3271 /* found port, the message belongs to */
3279 pdss1->message_isdn(frm->prim, frm->dinfo, msg->data);
3284 /* process new cr (before setup indication) */
3285 //printf("prim = 0x%x, looking for 0x%x\n",frm->prim, (CC_NEW_CR | INDICATION));
3286 if (frm->prim == (CC_NEW_CR | INDICATION))
3289 /* creating port object */
3290 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3291 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_TE_IN, mISDNport, name, NULL, 0, 0)))
3293 RELEASE_COMPLETE_t *release_complete;
3296 PERROR("FATAL ERROR: cannot create port object.\n");
3297 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, frm->dinfo, sizeof(RELEASE_COMPLETE_t), mISDNport->ntmode);
3298 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + mISDN_HEADER_LEN);
3299 l1l2l3_trace_header(mISDNport, NULL, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
3300 enc_ie_cause_standalone(mISDNport->ntmode?&release_complete->CAUSE:NULL, dmsg, (mISDNport->ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47);
3302 msg_queue_tail(&mISDNport->downqueue, dmsg);
3306 /* l3id will be set from dinfo at message_isdn */
3307 pdss1->message_isdn(frm->prim, frm->dinfo, msg->data);
3312 if (frm->prim == (CC_RELEASE_CR | INDICATION))
3314 PERROR("unhandled message from stack: call ref released (l3id=0x%x)\n", frm->dinfo);
3318 PERROR("unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", frm->prim, frm->dinfo, msg->len);
3324 * sending message that were queued during L1 activation
3325 * or releasing port if link is down
3327 void setup_queue(struct mISDNport *mISDNport, int link)
3331 struct message *message;
3333 if (!mISDNport->ntmode)
3336 /* check all port objects for pending message */
3340 if ((port->p_type&PORT_CLASS_mISDN_MASK) == PORT_CLASS_mISDN_DSS1)
3342 pdss1 = (class Pdss1 *)port;
3343 if (pdss1->p_m_mISDNport == mISDNport)
3345 if (pdss1->p_m_d_queue)
3349 PDEBUG(DEBUG_ISDN, "the L1 became active, so we send queued message for portnum=%d (%s).\n", mISDNport->portnum, pdss1->p_name);
3350 /* LAYER 1 is up, so we send */
3351 pdss1->message_setup(pdss1->p_m_d_queue->id_from, pdss1->p_m_d_queue->type, &pdss1->p_m_d_queue->param);
3352 message_free(pdss1->p_m_d_queue);
3353 pdss1->p_m_d_queue = NULL;
3356 PDEBUG(DEBUG_ISDN, "the L1 became NOT active, so we release port for portnum=%d (%s).\n", mISDNport->portnum, pdss1->p_name);
3357 message = message_create(pdss1->p_serial, pdss1->p_m_d_queue->id_from, PORT_TO_EPOINT, MESSAGE_RELEASE);
3358 message->param.disconnectinfo.cause = 27;
3359 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
3360 message_put(message);
3361 pdss1->new_state(PORT_STATE_RELEASE);
3362 pdss1->p_m_delete = 1;