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:INFO_ITYPE_ISDN_EXTENSION;
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", p_m_b_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.number, sizeof(p_dialinginfo.number));
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.number, (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.number, sizeof(p_dialinginfo.number));
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.number, (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 /* send connect acknowledge */
1124 dmsg = create_l3msg(CC_CONNECT | RESPONSE, MT_CONNECT, dinfo, sizeof(CONNECT_ACKNOWLEDGE_t), p_m_d_ntmode);
1125 connect_acknowledge = (CONNECT_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1126 l1l2l3_trace_header(p_m_mISDNport, this, CC_CONNECT | RESPONSE, DIRECTION_OUT);
1127 /* if we had no bchannel before, we send it now */
1128 if (!bchannel_before && p_m_b_channel)
1129 enc_ie_channel_id(&connect_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
1131 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1133 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CONNECT);
1134 memcpy(&message->param.connectinfo, &p_connectinfo, sizeof(struct connect_info));
1135 message_put(message);
1137 new_state(PORT_STATE_CONNECT);
1140 /* CC_DISCONNECT INDICATION */
1141 void Pdss1::disconnect_ind(unsigned long prim, unsigned long dinfo, void *data)
1143 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1144 DISCONNECT_t *disconnect = (DISCONNECT_t *)((unsigned long)data + headerlen);
1145 int location, cause;
1146 int coding, proglocation, progress;
1147 struct message *message;
1149 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1150 dec_ie_progress(disconnect->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &proglocation, &progress);
1151 dec_ie_cause(disconnect->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1157 /* release if we are remote sends us no tones */
1158 if (p_m_mISDNport->is_earlyb)
1163 dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, dinfo, sizeof(RELEASE_t), p_m_d_ntmode);
1164 release = (RELEASE_t *)(dmsg->data + headerlen);
1165 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE | REQUEST, DIRECTION_OUT);
1166 enc_ie_cause(&release->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16); /* normal */
1167 add_trace("reason", NULL, "no remote patterns");
1169 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1171 /* sending release to endpoint */
1174 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1175 message->param.disconnectinfo.cause = cause;
1176 message->param.disconnectinfo.location = location;
1177 message_put(message);
1179 free_epointlist(p_epointlist);
1181 new_state(PORT_STATE_RELEASE);
1186 /* sending disconnect to active endpoint and release to inactive endpoints */
1187 if (ACTIVE_EPOINT(p_epointlist))
1189 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DISCONNECT);
1190 message->param.disconnectinfo.location = location;
1191 message->param.disconnectinfo.cause = cause;
1192 message_put(message);
1194 while(INACTIVE_EPOINT(p_epointlist))
1196 message = message_create(p_serial, INACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1197 message->param.disconnectinfo.location = location;
1198 message->param.disconnectinfo.cause = cause;
1199 message_put(message);
1201 free_epointid(INACTIVE_EPOINT(p_epointlist));
1203 new_state(PORT_STATE_IN_DISCONNECT);
1206 /* CC_DISCONNECT INDICATION */
1207 void Pdss1::disconnect_ind_i(unsigned long prim, unsigned long dinfo, void *data)
1209 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1210 DISCONNECT_t *disconnect = (DISCONNECT_t *)((unsigned long)data + headerlen);
1211 int location, cause;
1214 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1215 if (p_m_d_collect_cause > 0)
1217 add_trace("old-cause", "location", "%d", p_m_d_collect_location);
1218 add_trace("old-cause", "value", "%d", p_m_d_collect_cause);
1220 dec_ie_cause(disconnect->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1224 if (cause == CAUSE_REJECTED) /* call rejected */
1226 p_m_d_collect_cause = CAUSE_REJECTED;
1227 p_m_d_collect_location = location;
1229 if (cause==CAUSE_NORMAL && p_m_d_collect_cause!=CAUSE_REJECTED) /* reject via hangup */
1231 p_m_d_collect_cause = CAUSE_NORMAL;
1232 p_m_d_collect_location = location;
1234 if (cause==CAUSE_BUSY && p_m_d_collect_cause!=CAUSE_REJECTED && p_m_d_collect_cause!=CAUSE_NORMAL) /* busy */
1236 p_m_d_collect_cause = CAUSE_BUSY;
1237 p_m_d_collect_location = location;
1239 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 */
1241 p_m_d_collect_cause = CAUSE_OUTOFORDER;
1242 p_m_d_collect_location = location;
1244 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 */
1246 p_m_d_collect_cause = cause;
1247 p_m_d_collect_location = location;
1249 add_trace("new-cause", "location", "%d", p_m_d_collect_location);
1250 add_trace("new-cause", "value", "%d", p_m_d_collect_cause);
1254 /* CC_RELEASE INDICATION */
1255 void Pdss1::release_ind(unsigned long prim, unsigned long dinfo, void *data)
1257 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1258 RELEASE_t *release = (RELEASE_t *)((unsigned long)data + headerlen);
1260 int location, cause;
1261 struct message *message;
1263 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1264 dec_ie_cause(release->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1270 /* sending release to endpoint */
1273 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1274 message->param.disconnectinfo.cause = cause;
1275 message->param.disconnectinfo.location = location;
1276 message_put(message);
1278 free_epointlist(p_epointlist);
1281 /* only in NT mode we must send release_complete, if we got a release confirm */
1282 if (prim == (CC_RELEASE | CONFIRM))
1284 /* sending release complete */
1285 RELEASE_COMPLETE_t *release_complete;
1287 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
1288 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
1289 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
1290 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16);
1292 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1295 new_state(PORT_STATE_RELEASE);
1299 /* CC_RELEASE_COMPLETE INDICATION */
1300 void Pdss1::release_complete_ind(unsigned long prim, unsigned long dinfo, void *data)
1302 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1303 RELEASE_COMPLETE_t *release_complete = (RELEASE_COMPLETE_t *)((unsigned long)data + headerlen);
1304 int location, cause;
1305 struct message *message;
1307 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1308 dec_ie_cause(release_complete->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1314 /* sending release to endpoint */
1317 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1318 message->param.disconnectinfo.cause = cause;
1319 message->param.disconnectinfo.location = location;
1320 message_put(message);
1322 free_epointlist(p_epointlist);
1325 new_state(PORT_STATE_RELEASE);
1330 void Pdss1::t312_timeout(unsigned long prim, unsigned long dinfo, void *data)
1332 struct message *message;
1334 // trace is done at message_isdn()
1336 /* sending release to endpoint */
1339 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1340 message->param.disconnectinfo.cause = p_m_d_collect_cause;
1341 message->param.disconnectinfo.location = p_m_d_collect_location;
1342 message_put(message);
1344 free_epointlist(p_epointlist);
1347 new_state(PORT_STATE_RELEASE);
1351 /* CC_NOTIFY INDICATION */
1352 void Pdss1::notify_ind(unsigned long prim, unsigned long dinfo, void *data)
1354 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1355 NOTIFY_t *notifying = (NOTIFY_t *)((unsigned long)data + headerlen);
1356 struct message *message;
1357 int notify, type, plan, present;
1359 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1360 dec_ie_notify(notifying->NOTIFY, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
1361 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));
1364 if (!ACTIVE_EPOINT(p_epointlist))
1366 /* notification indicator */
1370 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1371 message->param.notifyinfo.notify = notify;
1372 /* redirection number */
1376 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1379 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1382 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1388 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1389 message->param.notifyinfo.present = INFO_PRESENT_NULL;
1392 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1395 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1398 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1401 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1404 message->param.notifyinfo.isdn_port = p_m_portnum;
1405 message_put(message);
1409 /* CC_HOLD INDICATION */
1410 void Pdss1::hold_ind(unsigned long prim, unsigned long dinfo, void *data)
1412 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1413 // HOLD_t *hold = (HOLD_t *)((unsigned long)data + headerlen);
1414 struct message *message;
1415 HOLD_REJECT_t *hold_reject;
1416 HOLD_ACKNOWLEDGE_t *hold_acknowledge;
1418 // class Endpoint *epoint;
1420 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1423 if (!ACTIVE_EPOINT(p_epointlist) || p_m_hold)
1425 dmsg = create_l3msg(CC_HOLD_REJECT | REQUEST, MT_HOLD_REJECT, dinfo, sizeof(HOLD_REJECT_t), p_m_d_ntmode);
1426 hold_reject = (HOLD_REJECT_t *)(dmsg->data + headerlen);
1427 l1l2l3_trace_header(p_m_mISDNport, this, CC_HOLD_REJECT | REQUEST, DIRECTION_OUT);
1428 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 */
1429 add_trace("reason", NULL, "no endpoint");
1431 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1436 /* notify the hold of call */
1437 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1438 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_HOLD;
1439 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1440 message_put(message);
1442 /* deactivate bchannel */
1443 chan_trace_header(p_m_mISDNport, this, "CHANNEL RELEASE (hold)", DIRECTION_NONE);
1444 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1448 /* set hold state */
1451 epoint = find_epoint_id(ACTIVE_EPOINT(p_epointlist));
1452 if (epoint && p_m_d_ntmode)
1454 p_m_timeout = p_settings.tout_hold;
1459 /* acknowledge hold */
1460 dmsg = create_l3msg(CC_HOLD_ACKNOWLEDGE | REQUEST, MT_HOLD_ACKNOWLEDGE, dinfo, sizeof(HOLD_ACKNOWLEDGE_t), p_m_d_ntmode);
1461 hold_acknowledge = (HOLD_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1462 l1l2l3_trace_header(p_m_mISDNport, this, CC_HOLD_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1464 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1468 /* CC_RETRIEVE INDICATION */
1469 void Pdss1::retrieve_ind(unsigned long prim, unsigned long dinfo, void *data)
1471 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1472 RETRIEVE_t *retrieve = (RETRIEVE_t *)((unsigned long)data + headerlen);
1473 RETRIEVE_REJECT_t *retrieve_reject;
1474 RETRIEVE_ACKNOWLEDGE_t *retrieve_acknowledge;
1475 struct message *message;
1476 int channel, exclusive, cause;
1480 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1481 dec_ie_channel_id(retrieve->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
1486 cause = 101; /* incompatible state */
1489 dmsg = create_l3msg(CC_RETRIEVE_REJECT | REQUEST, MT_RETRIEVE_REJECT, dinfo, sizeof(RETRIEVE_REJECT_t), p_m_d_ntmode);
1490 retrieve_reject = (RETRIEVE_REJECT_t *)(dmsg->data + headerlen);
1491 l1l2l3_trace_header(p_m_mISDNport, this, CC_RETRIEVE_REJECT | REQUEST, DIRECTION_OUT);
1492 enc_ie_cause(&retrieve_reject->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, cause);
1494 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1499 /* notify the retrieve of call */
1500 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1501 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_RETRIEVAL;
1502 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1503 message_put(message);
1506 ret = channel = hunt_bchannel(channel, exclusive);
1511 ret = seize_bchannel(channel, 1);
1518 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_ACTIVATE);
1520 /* set hold state */
1524 /* acknowledge retrieve */
1525 dmsg = create_l3msg(CC_RETRIEVE_ACKNOWLEDGE | REQUEST, MT_RETRIEVE_ACKNOWLEDGE, dinfo, sizeof(RETRIEVE_ACKNOWLEDGE_t), p_m_d_ntmode);
1526 retrieve_acknowledge = (RETRIEVE_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1527 l1l2l3_trace_header(p_m_mISDNport, this, CC_RETRIEVE_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1528 enc_ie_channel_id(&retrieve_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
1530 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1533 /* CC_SUSPEND INDICATION */
1534 void Pdss1::suspend_ind(unsigned long prim, unsigned long dinfo, void *data)
1536 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1537 SUSPEND_t *suspend = (SUSPEND_t *)((unsigned long)data + headerlen);
1538 SUSPEND_ACKNOWLEDGE_t *suspend_acknowledge;
1539 SUSPEND_REJECT_t *suspend_reject;
1540 struct message *message;
1541 class Endpoint *epoint;
1542 unsigned char callid[8];
1545 int ret = -31; /* normal, unspecified */
1547 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1548 dec_ie_call_id(suspend->CALL_ID, (Q931_info_t *)((unsigned long)data+headerlen), callid, &len);
1551 if (!ACTIVE_EPOINT(p_epointlist))
1554 dmsg = create_l3msg(CC_SUSPEND_REJECT | REQUEST, MT_SUSPEND_REJECT, dinfo, sizeof(SUSPEND_REJECT_t), p_m_d_ntmode);
1555 suspend_reject = (SUSPEND_REJECT_t *)(dmsg->data + headerlen);
1556 l1l2l3_trace_header(p_m_mISDNport, this, CC_SUSPEND_REJECT | REQUEST, DIRECTION_OUT);
1557 enc_ie_cause(&suspend_reject->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1559 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1567 /* check if call id is in use */
1568 epoint = epoint_first;
1571 if (epoint->ep_park)
1573 if (epoint->ep_park_len == len)
1574 if (!memcmp(epoint->ep_park_callid, callid, len))
1576 ret = -84; /* call id in use */
1580 epoint = epoint->next;
1583 /* notify the hold of call */
1584 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1585 message->param.notifyinfo.notify = INFO_NOTIFY_USER_SUSPENDED;
1586 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1587 message_put(message);
1589 /* deactivate bchannel */
1590 chan_trace_header(p_m_mISDNport, this, "CHANNEL RELEASE (suspend)", DIRECTION_NONE);
1591 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1595 /* sending suspend to endpoint */
1596 while (p_epointlist)
1598 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_SUSPEND);
1599 memcpy(message->param.parkinfo.callid, callid, sizeof(message->param.parkinfo.callid));
1600 message->param.parkinfo.len = len;
1601 message_put(message);
1603 free_epointlist(p_epointlist);
1606 /* sending SUSPEND_ACKNOWLEDGE */
1607 dmsg = create_l3msg(CC_SUSPEND_ACKNOWLEDGE | REQUEST, MT_SUSPEND_ACKNOWLEDGE, dinfo, sizeof(SUSPEND_ACKNOWLEDGE_t), p_m_d_ntmode);
1608 suspend_acknowledge = (SUSPEND_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1609 l1l2l3_trace_header(p_m_mISDNport, this, CC_SUSPEND_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1611 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1613 new_state(PORT_STATE_RELEASE);
1617 /* CC_RESUME INDICATION */
1618 void Pdss1::resume_ind(unsigned long prim, unsigned long dinfo, void *data)
1620 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1621 RESUME_t *resume = (RESUME_t *)((unsigned long)data + headerlen);
1622 RESUME_REJECT_t *resume_reject;
1623 RESUME_ACKNOWLEDGE_t *resume_acknowledge;
1624 unsigned char callid[8];
1626 int channel, exclusive;
1628 class Endpoint *epoint;
1629 struct message *message;
1632 /* callref from nt-lib */
1635 /* nt-library now gives us the id via CC_RESUME */
1636 if (dinfo&(~0xff) == 0xff00)
1638 PERROR("fatal software error: l3-stack gives us a process id 0xff00-0xffff\n");
1641 l1l2l3_trace_header(p_m_mISDNport, this, CC_NEW_CR | INDICATION, DIRECTION_IN);
1643 add_trace("callref", "old", "0x%x", p_m_d_l3id);
1644 add_trace("callref", "new", "0x%x", dinfo);
1646 if (p_m_d_l3id&(~0xff) == 0xff00)
1647 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
1649 p_m_d_ces = resume->ces;
1652 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1653 dec_ie_call_id(resume->CALL_ID, (Q931_info_t *)((unsigned long)data+headerlen), callid, &len);
1656 /* if blocked, release call */
1657 if (p_m_mISDNport->ifport->block)
1666 /* channel_id (no channel is possible in message) */
1668 channel = -1; /* any channel */
1671 ret = channel = hunt_bchannel(channel, exclusive);
1676 ret = seize_bchannel(channel, 1);
1681 dmsg = create_l3msg(CC_RESUME_REJECT | REQUEST, MT_RESUME_REJECT, dinfo, sizeof(RESUME_REJECT_t), p_m_d_ntmode);
1682 resume_reject = (RESUME_REJECT_t *)(dmsg->data + headerlen);
1683 l1l2l3_trace_header(p_m_mISDNport, this, CC_RESUME_REJECT | REQUEST, DIRECTION_OUT);
1684 enc_ie_cause(&resume_reject->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1686 add_trace("reason", NULL, "port blocked");
1688 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1689 new_state(PORT_STATE_RELEASE);
1693 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_ACTIVATE);
1695 /* create endpoint */
1698 PERROR("SOFTWARE ERROR: incoming resume but already got an endpoint, exitting...\n");
1701 ret = -85; /* no call suspended */
1702 epoint = epoint_first;
1705 if (epoint->ep_park)
1707 ret = -83; /* suspended call exists, but this not */
1708 if (epoint->ep_park_len == len)
1709 if (!memcmp(epoint->ep_park_callid, callid, len))
1712 epoint = epoint->next;
1717 if (!(epointlist_new(epoint->ep_serial)))
1719 PERROR("no memory for epointlist\n");
1722 if (!(epoint->portlist_new(p_serial, p_type, p_m_mISDNport->is_earlyb)))
1724 PERROR("no memory for portlist\n");
1727 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RESUME);
1728 message_put(message);
1730 /* notify the resume of call */
1731 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1732 message->param.notifyinfo.notify = INFO_NOTIFY_USER_RESUMED;
1733 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1734 message_put(message);
1736 /* sending RESUME_ACKNOWLEDGE */
1737 dmsg = create_l3msg(CC_RESUME_ACKNOWLEDGE | REQUEST, MT_RESUME_ACKNOWLEDGE, dinfo, sizeof(RESUME_ACKNOWLEDGE_t), p_m_d_ntmode);
1738 resume_acknowledge = (RESUME_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1739 l1l2l3_trace_header(p_m_mISDNport, this, CC_RESUME_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1740 enc_ie_channel_id(&resume_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
1742 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1744 new_state(PORT_STATE_CONNECT);
1748 /* CC_FACILITY INDICATION */
1749 void Pdss1::facility_ind(unsigned long prim, unsigned long dinfo, void *data)
1751 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1752 FACILITY_t *facility = (FACILITY_t *)((unsigned long)data + headerlen);
1753 unsigned char facil[256];
1755 struct message *message;
1757 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1758 dec_ie_facility(facility->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), facil, &facil_len);
1765 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_FACILITY);
1766 message->param.facilityinfo.len = facil_len;
1767 memcpy(message->param.facilityinfo.data, facil, facil_len);
1768 message_put(message);
1773 * handler for isdn connections
1774 * incoming information are parsed and sent via message to the endpoint
1776 void Pdss1::message_isdn(unsigned long prim, unsigned long dinfo, void *data)
1783 case CC_TIMEOUT | INDICATION:
1784 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1787 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1788 timer_hex = *((int *)(((char *)data)+headerlen));
1791 add_trace("timer", NULL, "%x", timer_hex);
1793 if (timer_hex==0x312 && p_m_d_ntmode)
1794 t312_timeout(prim, dinfo, data);
1797 case CC_SETUP | INDICATION:
1798 if (p_state != PORT_STATE_IDLE)
1800 setup_ind(prim, dinfo, data);
1803 case CC_SETUP | CONFIRM:
1806 l1l2l3_trace_header(p_m_mISDNport, this, CC_NEW_CR | INDICATION, DIRECTION_IN);
1807 add_trace("callref", "old", "0x%x", p_m_d_l3id);
1808 /* nt-library now gives us a new id via CC_SETUP_CONFIRM */
1809 if ((p_m_d_l3id&0xff00) != 0xff00)
1810 PERROR(" strange setup-procid 0x%x\n", p_m_d_l3id);
1811 p_m_d_l3id = *((int *)(((u_char *)data)+ mISDNUSER_HEAD_SIZE));
1812 add_trace("callref", "new", "0x%x", p_m_d_l3id);
1817 case CC_INFORMATION | INDICATION:
1818 information_ind(prim, dinfo, data);
1821 case CC_SETUP_ACKNOWLEDGE | INDICATION:
1822 if (p_state != PORT_STATE_OUT_SETUP)
1824 PERROR("Pdss1(%s) received setup_acknowledge, but we are not in outgoing setup state, IGNORING.\n", p_name);
1827 setup_acknowledge_ind(prim, dinfo, data);
1830 case CC_PROCEEDING | INDICATION:
1831 if (p_state != PORT_STATE_OUT_SETUP
1832 && p_state != PORT_STATE_OUT_OVERLAP)
1834 PERROR("Pdss1(%s) received proceeding, but we are not in outgoing setup OR overlap state, IGNORING.\n", p_name);
1837 proceeding_ind(prim, dinfo, data);
1840 case CC_ALERTING | INDICATION:
1841 if (p_state != PORT_STATE_OUT_SETUP
1842 && p_state != PORT_STATE_OUT_OVERLAP
1843 && p_state != PORT_STATE_OUT_PROCEEDING)
1845 PERROR("Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding state, IGNORING.\n", p_name);
1848 alerting_ind(prim, dinfo, data);
1851 case CC_CONNECT | INDICATION:
1852 if (p_state != PORT_STATE_OUT_SETUP
1853 && p_state != PORT_STATE_OUT_OVERLAP
1854 && p_state != PORT_STATE_OUT_PROCEEDING
1855 && p_state != PORT_STATE_OUT_ALERTING)
1857 PERROR("Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding OR ALERTING state, IGNORING.\n", p_name);
1860 connect_ind(prim, dinfo, data);
1861 if (p_m_d_notify_pending)
1863 /* send pending notify message during connect */
1864 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
1865 message_free(p_m_d_notify_pending);
1866 p_m_d_notify_pending = NULL;
1870 case CC_CONNECT_ACKNOWLEDGE | INDICATION:
1871 case CC_CONNECT | CONFIRM:
1872 if (p_state == PORT_STATE_CONNECT_WAITING)
1873 new_state(PORT_STATE_CONNECT);
1874 if (p_m_d_notify_pending)
1876 /* send pending notify message during connect-ack */
1877 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
1878 message_free(p_m_d_notify_pending);
1879 p_m_d_notify_pending = NULL;
1883 case CC_DISCONNECT | INDICATION:
1884 disconnect_ind(prim, dinfo, data);
1887 case CC_RELEASE | CONFIRM:
1888 case CC_RELEASE | INDICATION:
1889 release_ind(prim, dinfo, data);
1892 case CC_RELEASE_COMPLETE | INDICATION:
1893 release_complete_ind(prim, dinfo, data);
1896 case CC_RELEASE_COMPLETE | CONFIRM:
1899 case CC_NOTIFY | INDICATION:
1900 notify_ind(prim, dinfo, data);
1903 case CC_HOLD | INDICATION:
1904 hold_ind(prim, dinfo, data);
1907 case CC_RETRIEVE | INDICATION:
1908 retrieve_ind(prim, dinfo, data);
1911 case CC_SUSPEND | INDICATION:
1912 suspend_ind(prim, dinfo, data);
1915 case CC_RESUME | INDICATION:
1916 resume_ind(prim, dinfo, data);
1919 case CC_FACILITY | INDICATION:
1920 facility_ind(prim, dinfo, data);
1923 case CC_RELEASE_CR | INDICATION:
1924 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_CR | INDICATION, DIRECTION_IN);
1925 add_trace("callref", NULL, "0x%x", p_m_d_l3id);
1929 if ((p_m_d_l3id&0xff00) == 0xff00)
1930 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
1934 /* sending release to endpoint in case we still have an endpoint
1935 * NOTE: this only happens if the stack releases due to layer1
1936 * or layer2 breakdown. otherwhise a release is received first.
1940 struct message *message;
1941 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1942 message->param.disconnectinfo.cause = (p_m_d_collect_cause!=CAUSE_NOUSER)?p_m_d_collect_cause:CAUSE_UNSPECIFIED;
1943 message->param.disconnectinfo.location = (p_m_d_collect_cause!=CAUSE_NOUSER)?p_m_d_collect_location:LOCATION_PRIVATE_LOCAL;
1944 message_put(message);
1946 free_epointlist(p_epointlist);
1948 new_state(PORT_STATE_RELEASE);
1952 case CC_NEW_CR | INDICATION:
1953 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1955 add_trace("callref", "old", "0x%x", p_m_d_l3id);
1958 new_l3id = *((int *)(((u_char *)data+mISDNUSER_HEAD_SIZE)));
1959 if (((new_l3id&0xff00)!=0xff00) && ((p_m_d_l3id&0xff00)==0xff00))
1960 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
1965 p_m_d_l3id = new_l3id;
1966 add_trace("callref", "new", "0x%x", p_m_d_l3id);
1971 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1972 add_trace("unhandled", "prim", "0x%x", prim);
1977 void Pdss1::new_state(int state)
1979 class Endpoint *epoint;
1982 epoint = find_epoint_id(ACTIVE_EPOINT(p_epointlist));
1983 if (epoint && p_m_d_ntmode)
1985 if (state == PORT_STATE_IN_OVERLAP)
1987 p_m_timeout = p_settings.tout_dialing;
1990 if (state != p_state)
1992 if (state == PORT_STATE_IN_SETUP
1993 || state == PORT_STATE_IN_OVERLAP)
1995 p_m_timeout = p_settings.tout_setup;
1998 if (state == PORT_STATE_IN_PROCEEDING
1999 || state == PORT_STATE_OUT_PROCEEDING)
2001 p_m_timeout = p_settings.tout_proceeding;
2004 if (state == PORT_STATE_IN_ALERTING
2005 || state == PORT_STATE_OUT_ALERTING)
2007 p_m_timeout = p_settings.tout_alerting;
2010 if (state == PORT_STATE_CONNECT
2011 || state == PORT_STATE_CONNECT_WAITING)
2015 if (state == PORT_STATE_IN_DISCONNECT
2016 || state == PORT_STATE_OUT_DISCONNECT)
2018 p_m_timeout = p_settings.tout_disconnect;
2024 Port::new_state(state);
2031 int Pdss1::handler(void)
2035 if ((ret = Port::handler()))
2038 /* handle destruction */
2039 if (p_m_delete && p_m_d_l3id==0)
2050 * handles all messages from endpoint
2052 /* MESSAGE_INFORMATION */
2053 void Pdss1::message_information(unsigned long epoint_id, int message_id, union parameter *param)
2055 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2056 INFORMATION_t *information;
2059 if (param->information.number[0]) /* only if we have something to dial */
2061 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2062 information = (INFORMATION_t *)(dmsg->data + headerlen);
2063 l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT);
2064 enc_ie_called_pn(&information->CALLED_PN, dmsg, 0, 1, (unsigned char *)param->information.number);
2066 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2075 void Pdss1::message_setup(unsigned long epoint_id, int message_id, union parameter *param)
2077 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2078 INFORMATION_t *information;
2081 int plan, type, screen, present, reason;
2082 int capability, mode, rate, coding, user, presentation, interpretation, hlc, exthlc;
2083 int channel, exclusive;
2085 struct epoint_list *epointlist;
2087 /* release if port is blocked */
2088 if (p_m_mISDNport->ifport->block)
2090 struct message *message;
2092 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2093 message->param.disconnectinfo.cause = 27; // temp. unavail.
2094 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2095 message_put(message);
2096 new_state(PORT_STATE_RELEASE);
2101 /* copy setup infos to port */
2102 memcpy(&p_callerinfo, ¶m->setup.callerinfo, sizeof(p_callerinfo));
2103 memcpy(&p_dialinginfo, ¶m->setup.dialinginfo, sizeof(p_dialinginfo));
2104 memcpy(&p_capainfo, ¶m->setup.capainfo, sizeof(p_capainfo));
2105 memcpy(&p_redirinfo, ¶m->setup.redirinfo, sizeof(p_redirinfo));
2106 // SCPY(&p_m_tones_dir, param->setup.ext.tones_dir);
2108 /* only display at connect state: this case happens if endpoint is in connected mode */
2109 if (p_state==PORT_STATE_CONNECT)
2111 if (p_type!=PORT_TYPE_DSS1_NT_OUT
2112 && p_type!=PORT_TYPE_DSS1_NT_IN)
2114 if (p_callerinfo.display[0])
2116 /* sending information */
2117 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2118 information = (INFORMATION_t *)(dmsg->data + headerlen);
2119 l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT);
2121 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_callerinfo.display);
2123 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2128 /* attach only if not already */
2129 epointlist = p_epointlist;
2132 if (epointlist->epoint_id == epoint_id)
2134 epointlist = epointlist->next;
2138 if (!(epointlist_new(epoint_id)))
2140 PERROR("no memory for epointlist\n");
2149 channel = p_m_b_channel;
2150 exclusive = p_m_b_exclusive;
2152 channel = CHANNEL_ANY;
2153 /* nt-port with no channel, not reserverd */
2154 if (!p_m_b_channel && !p_m_b_reserve && p_type==PORT_TYPE_DSS1_NT_OUT)
2155 channel = CHANNEL_NO;
2158 l1l2l3_trace_header(p_m_mISDNport, this, CC_NEW_CR | REQUEST, DIRECTION_OUT);
2164 if (p_m_mISDNport->procids[i] == 0)
2170 struct message *message;
2172 add_trace("callref", NULL, "no free id");
2174 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2175 message->param.disconnectinfo.cause = 47;
2176 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2177 message_put(message);
2178 new_state(PORT_STATE_RELEASE);
2182 p_m_mISDNport->procids[i] = 1;
2183 p_m_d_l3id = 0xff00 | i;
2187 /* if we are in te-mode, we need to create a process first */
2188 if (newteid++ > 0x7fff)
2190 p_m_d_l3id = (entity<<16) | newteid;
2191 /* preparing message */
2192 ncr.prim = CC_NEW_CR | REQUEST;
2193 ncr.addr = p_m_mISDNport->upper_id | FLG_MSG_DOWN;
2194 ncr.dinfo = p_m_d_l3id;
2197 mISDN_write(mISDNdevice, &ncr, mISDN_HEADER_LEN+ncr.len, TIMEOUT_1SEC);
2201 add_trace("callref", "new", "0x%x", p_m_d_l3id);
2204 /* preparing setup message */
2205 dmsg = create_l3msg(CC_SETUP | REQUEST, MT_SETUP, p_m_d_l3id, sizeof(SETUP_t), p_m_d_ntmode);
2206 setup = (SETUP_t *)(dmsg->data + headerlen);
2207 l1l2l3_trace_header(p_m_mISDNport, this, CC_SETUP | REQUEST, DIRECTION_OUT);
2208 /* channel information */
2209 if (channel >= 0) /* it should */
2211 enc_ie_channel_id(&setup->CHANNEL_ID, dmsg, exclusive, channel);
2213 /* caller information */
2215 switch (p_callerinfo.ntype)
2217 case INFO_NTYPE_INTERNATIONAL:
2220 case INFO_NTYPE_NATIONAL:
2223 case INFO_NTYPE_SUBSCRIBER:
2226 default: /* INFO_NTYPE_UNKNOWN */
2230 switch (p_callerinfo.screen)
2232 case INFO_SCREEN_USER:
2235 default: /* INFO_SCREEN_NETWORK */
2239 switch (p_callerinfo.present)
2241 case INFO_PRESENT_RESTRICTED:
2244 case INFO_PRESENT_NOTAVAIL:
2247 default: /* INFO_PRESENT_ALLOWED */
2252 enc_ie_calling_pn(&setup->CALLING_PN, dmsg, type, plan, present, screen, (unsigned char *)p_callerinfo.id);
2253 /* dialing information */
2254 if (p_dialinginfo.number[0]) /* only if we have something to dial */
2256 enc_ie_called_pn(&setup->CALLED_PN, dmsg, 0, 1, (unsigned char *)p_dialinginfo.number);
2258 /* sending complete */
2259 if (p_dialinginfo.sending_complete)
2260 enc_ie_complete(&setup->COMPLETE, dmsg, 1);
2261 /* sending user-user */
2262 if (param->setup.useruser.len)
2264 enc_ie_useruser(&setup->USER_USER, dmsg, param->setup.useruser.protocol, param->setup.useruser.data, param->setup.useruser.len);
2266 /* redirecting number */
2268 switch (p_redirinfo.ntype)
2270 case INFO_NTYPE_INTERNATIONAL:
2273 case INFO_NTYPE_NATIONAL:
2276 case INFO_NTYPE_SUBSCRIBER:
2279 default: /* INFO_NTYPE_UNKNOWN */
2283 switch (p_redirinfo.screen)
2285 case INFO_SCREEN_USER:
2288 default: /* INFO_SCREE_NETWORK */
2292 switch (p_redirinfo.reason)
2294 case INFO_REDIR_BUSY:
2297 case INFO_REDIR_NORESPONSE:
2300 case INFO_REDIR_UNCONDITIONAL:
2303 case INFO_REDIR_CALLDEFLECT:
2306 case INFO_REDIR_OUTOFORDER:
2309 default: /* INFO_REDIR_UNKNOWN */
2313 switch (p_redirinfo.present)
2315 case INFO_PRESENT_NULL: /* no redir at all */
2322 case INFO_PRESENT_RESTRICTED:
2325 case INFO_PRESENT_NOTAVAIL:
2328 default: /* INFO_PRESENT_ALLOWED */
2332 /* sending redirecting number only in ntmode */
2333 if (type >= 0 && p_m_d_ntmode)
2334 enc_ie_redir_nr(&setup->REDIR_NR, dmsg, type, plan, present, screen, reason, (unsigned char *)p_redirinfo.id);
2335 /* bearer capability */
2336 //printf("hlc=%d\n",p_capainfo.hlc);
2338 capability = p_capainfo.bearer_capa;
2339 mode = p_capainfo.bearer_mode;
2340 rate = (mode==INFO_BMODE_CIRCUIT)?0x10:0x00;
2341 switch (p_capainfo.bearer_info1)
2343 case INFO_INFO1_NONE:
2347 user = p_capainfo.bearer_info1 & 0x7f;
2350 enc_ie_bearer(&setup->BEARER, dmsg, coding, capability, mode, rate, -1, user);
2357 hlc = p_capainfo.hlc & 0x7f;
2359 if (p_capainfo.exthlc)
2360 exthlc = p_capainfo.exthlc & 0x7f;
2361 enc_ie_hlc(&setup->HLC, dmsg, coding, interpretation, presentation, hlc, exthlc);
2365 if (p_callerinfo.display[0] && p_m_d_ntmode)
2366 enc_ie_display(&setup->DISPLAY, dmsg, (unsigned char *)p_callerinfo.display);
2368 /* nt-mode: CNIP (calling name identification presentation) */
2369 if (p_callerinfo.name[0] && p_m_d_ntmode)
2370 enc_facility_centrex(&setup->FACILITY, dmsg, (unsigned char *)p_callerinfo.name, 1);
2374 /* send setup message now */
2375 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2377 new_state(PORT_STATE_OUT_SETUP);
2380 /* MESSAGE_FACILITY */
2381 void Pdss1::message_facility(unsigned long epoint_id, int message_id, union parameter *param)
2383 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2384 FACILITY_t *facility;
2387 /* facility will not be sent to external lines */
2391 /* sending facility */
2392 dmsg = create_l3msg(CC_FACILITY | REQUEST, MT_FACILITY, p_m_d_l3id, sizeof(FACILITY_t), p_m_d_ntmode);
2393 facility = (FACILITY_t *)(dmsg->data + headerlen);
2394 l1l2l3_trace_header(p_m_mISDNport, this, CC_FACILITY | REQUEST, DIRECTION_OUT);
2395 enc_ie_facility(&facility->FACILITY, dmsg, (unsigned char *)param->facilityinfo.data, param->facilityinfo.len);
2397 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2400 /* MESSAGE_NOTIFY */
2401 void Pdss1::message_notify(unsigned long epoint_id, int message_id, union parameter *param)
2403 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2404 INFORMATION_t *information;
2405 NOTIFY_t *notification;
2407 int plan, type = -1, present;
2410 if (param->notifyinfo.notify>INFO_NOTIFY_NONE)
2411 notify = param->notifyinfo.notify & 0x7f;
2414 if (p_state != PORT_STATE_CONNECT)
2416 /* notify only allowed in active state */
2422 switch (param->notifyinfo.ntype)
2424 case INFO_NTYPE_INTERNATIONAL:
2427 case INFO_NTYPE_NATIONAL:
2430 case INFO_NTYPE_SUBSCRIBER:
2433 default: /* INFO_NTYPE_UNKNOWN */
2437 switch (param->notifyinfo.present)
2439 case INFO_PRESENT_NULL: /* no redir at all */
2444 case INFO_PRESENT_RESTRICTED:
2447 case INFO_PRESENT_NOTAVAIL:
2450 default: /* INFO_PRESENT_ALLOWED */
2456 if (notify<0 && !param->notifyinfo.display[0])
2458 /* nothing to notify, nothing to display */
2464 if (p_state!=PORT_STATE_CONNECT)
2466 /* queue notification */
2467 if (p_m_d_notify_pending)
2468 message_free(p_m_d_notify_pending);
2469 p_m_d_notify_pending = message_create(ACTIVE_EPOINT(p_epointlist), p_serial, EPOINT_TO_PORT, message_id);
2470 memcpy(&p_m_d_notify_pending->param, param, sizeof(union parameter));
2473 /* sending notification */
2474 dmsg = create_l3msg(CC_NOTIFY | REQUEST, MT_NOTIFY, p_m_d_l3id, sizeof(NOTIFY_t), p_m_d_ntmode);
2475 notification = (NOTIFY_t *)(dmsg->data + headerlen);
2476 l1l2l3_trace_header(p_m_mISDNport, this, CC_NOTIFY | REQUEST, DIRECTION_OUT);
2477 enc_ie_notify(¬ification->NOTIFY, dmsg, notify);
2478 /* sending redirection number only in ntmode */
2479 if (type >= 0 && p_m_d_ntmode)
2480 enc_ie_redir_dn(¬ification->REDIR_DN, dmsg, type, plan, present, (unsigned char *)param->notifyinfo.id);
2481 if (param->notifyinfo.display[0] && p_m_d_ntmode)
2482 enc_ie_display(¬ification->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display);
2484 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2486 } else if (p_m_d_ntmode)
2488 /* sending information */
2489 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2490 information = (INFORMATION_t *)(dmsg->data + headerlen);
2491 l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT);
2492 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display);
2494 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2498 /* MESSAGE_OVERLAP */
2499 void Pdss1::message_overlap(unsigned long epoint_id, int message_id, union parameter *param)
2501 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2502 SETUP_ACKNOWLEDGE_t *setup_acknowledge;
2505 /* sending setup_acknowledge */
2506 dmsg = create_l3msg(CC_SETUP_ACKNOWLEDGE | REQUEST, MT_SETUP_ACKNOWLEDGE, p_m_d_l3id, sizeof(SETUP_ACKNOWLEDGE_t), p_m_d_ntmode);
2507 setup_acknowledge = (SETUP_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
2508 l1l2l3_trace_header(p_m_mISDNport, this, CC_SETUP_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
2509 /* channel information */
2510 if (p_state == PORT_STATE_IN_SETUP)
2511 enc_ie_channel_id(&setup_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2512 /* progress information */
2513 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2514 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2515 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2516 if (p_m_mISDNport->is_tones)
2517 enc_ie_progress(&setup_acknowledge->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2519 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2521 new_state(PORT_STATE_IN_OVERLAP);
2524 /* MESSAGE_PROCEEDING */
2525 void Pdss1::message_proceeding(unsigned long epoint_id, int message_id, union parameter *param)
2527 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2528 CALL_PROCEEDING_t *proceeding;
2531 /* sending proceeding */
2532 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2533 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2534 l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2535 /* channel information */
2536 if (p_state == PORT_STATE_IN_SETUP)
2537 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2538 /* progress information */
2539 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2540 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2541 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2542 if (p_m_mISDNport->is_tones)
2543 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2545 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2547 new_state(PORT_STATE_IN_PROCEEDING);
2550 /* MESSAGE_ALERTING */
2551 void Pdss1::message_alerting(unsigned long epoint_id, int message_id, union parameter *param)
2553 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2554 ALERTING_t *alerting;
2557 /* NT-MODE in setup state we must send PROCEEDING first */
2558 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2560 CALL_PROCEEDING_t *proceeding;
2562 /* sending proceeding */
2563 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2564 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2565 l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2566 /* channel information */
2567 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2568 /* progress information */
2569 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2570 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2571 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2572 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2574 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2575 new_state(PORT_STATE_IN_PROCEEDING);
2578 /* sending alerting */
2579 dmsg = create_l3msg(CC_ALERTING | REQUEST, MT_ALERTING, p_m_d_l3id, sizeof(ALERTING_t), p_m_d_ntmode);
2580 alerting = (ALERTING_t *)(dmsg->data + headerlen);
2581 l1l2l3_trace_header(p_m_mISDNport, this, CC_ALERTING | REQUEST, DIRECTION_OUT);
2582 /* channel information */
2583 if (p_state == PORT_STATE_IN_SETUP)
2584 enc_ie_channel_id(&alerting->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2585 /* progress information */
2586 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2587 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2588 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2589 if (p_m_mISDNport->is_tones)
2590 enc_ie_progress(&alerting->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2592 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2594 new_state(PORT_STATE_IN_ALERTING);
2597 /* MESSAGE_CONNECT */
2598 void Pdss1::message_connect(unsigned long epoint_id, int message_id, union parameter *param)
2600 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2601 INFORMATION_t *information;
2603 int type, plan, present, screen;
2605 class Endpoint *epoint;
2607 /* NT-MODE in setup state we must send PROCEEDING first */
2608 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2610 CALL_PROCEEDING_t *proceeding;
2612 /* sending proceeding */
2613 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2614 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2615 l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2616 /* channel information */
2617 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2618 // /* progress information */
2619 // if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2620 // || p_capainfo.bearer_capa==INFO_BC_AUDIO
2621 // || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2622 // enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2624 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2625 new_state(PORT_STATE_IN_PROCEEDING);
2628 /* copy connected information */
2629 memcpy(&p_connectinfo, ¶m->connectinfo, sizeof(p_connectinfo));
2631 /* only display at connect state */
2632 if (p_state == PORT_STATE_CONNECT)
2633 if (p_connectinfo.display[0])
2635 /* sending information */
2636 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2637 information = (INFORMATION_t *)(dmsg->data + headerlen);
2638 l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT);
2640 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_connectinfo.display);
2642 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2646 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)
2648 /* connect command only possible in setup, proceeding or alerting state */
2652 /* preparing connect message */
2653 dmsg = create_l3msg(CC_CONNECT | REQUEST, MT_CONNECT, p_m_d_l3id, sizeof(CONNECT_t), p_m_d_ntmode);
2654 connect = (CONNECT_t *)(dmsg->data + headerlen);
2655 l1l2l3_trace_header(p_m_mISDNport, this, CC_CONNECT | REQUEST, DIRECTION_OUT);
2656 /* connect information */
2658 switch (p_connectinfo.ntype)
2660 case INFO_NTYPE_INTERNATIONAL:
2663 case INFO_NTYPE_NATIONAL:
2666 case INFO_NTYPE_SUBSCRIBER:
2669 default: /* INFO_NTYPE_UNKNOWN */
2673 switch (param->connectinfo.screen)
2675 case INFO_SCREEN_USER:
2678 default: /* INFO_SCREE_NETWORK */
2682 switch (p_connectinfo.present)
2684 case INFO_PRESENT_NULL: /* no colp at all */
2690 case INFO_PRESENT_RESTRICTED:
2693 case INFO_PRESENT_NOTAVAIL:
2696 default: /* INFO_PRESENT_ALLOWED */
2701 enc_ie_connected_pn(&connect->CONNECT_PN, dmsg, type, plan, present, screen, (unsigned char *)p_connectinfo.id);
2703 if (p_connectinfo.display[0] && p_m_d_ntmode)
2704 enc_ie_display(&connect->DISPLAY, dmsg, (unsigned char *)p_connectinfo.display);
2706 /* nt-mode: CONP (connected name identification presentation) */
2707 if (p_connectinfo.name[0] && p_m_d_ntmode)
2708 enc_facility_centrex(&connect->FACILITY, dmsg, (unsigned char *)p_connectinfo.name, 0);
2713 epoint = find_epoint_id(epoint_id);
2714 enc_ie_date(&connect->DATE, dmsg, now, p_settings.no_seconds);
2717 /* finally send message */
2718 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2721 new_state(PORT_STATE_CONNECT);
2723 new_state(PORT_STATE_CONNECT_WAITING);
2727 /* MESSAGE_DISCONNECT */
2728 void Pdss1::message_disconnect(unsigned long epoint_id, int message_id, union parameter *param)
2730 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2731 DISCONNECT_t *disconnect;
2732 RELEASE_COMPLETE_t *release_complete;
2734 struct message *message;
2737 /* we reject during incoming setup when we have no tones. also if we are in outgoing setup state */
2738 if ((p_state==PORT_STATE_IN_SETUP && !p_m_mISDNport->is_tones)
2739 || p_state==PORT_STATE_OUT_SETUP)
2741 /* sending release to endpoint */
2744 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
2745 message->param.disconnectinfo.cause = 16;
2746 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2747 message_put(message);
2749 free_epointlist(p_epointlist);
2751 /* sending release */
2752 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
2753 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
2754 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
2756 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);
2758 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2759 new_state(PORT_STATE_RELEASE);
2764 /* NT-MODE in setup state we must send PROCEEDING first */
2765 if (p_state==PORT_STATE_IN_SETUP)
2767 CALL_PROCEEDING_t *proceeding;
2769 /* sending proceeding */
2770 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2771 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2772 l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2773 /* channel information */
2774 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2775 /* progress information */
2776 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2777 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2778 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2779 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2781 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2782 new_state(PORT_STATE_IN_PROCEEDING);
2785 /* sending disconnect */
2786 dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode);
2787 disconnect = (DISCONNECT_t *)(dmsg->data + headerlen);
2788 l1l2l3_trace_header(p_m_mISDNport, this, CC_DISCONNECT | REQUEST, DIRECTION_OUT);
2789 /* progress information */
2790 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2791 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2792 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2793 if (p_m_mISDNport->is_tones)
2794 enc_ie_progress(&disconnect->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2796 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);
2798 if (param->disconnectinfo.display[0])
2799 p = param->disconnectinfo.display;
2800 if (p) if (*p && p_m_d_ntmode)
2801 enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p);
2803 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2804 new_state(PORT_STATE_OUT_DISCONNECT);
2807 /* MESSAGE_RELEASE */
2808 void Pdss1::message_release(unsigned long epoint_id, int message_id, union parameter *param)
2810 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2812 RELEASE_COMPLETE_t *release_complete;
2813 DISCONNECT_t *disconnect;
2815 class Endpoint *epoint;
2818 /* if we have incoming disconnected, we may release */
2819 if (p_state==PORT_STATE_IN_DISCONNECT
2820 || p_state==PORT_STATE_OUT_DISCONNECT)
2822 /* sending release */
2823 dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, p_m_d_l3id, sizeof(RELEASE_t), p_m_d_ntmode);
2824 release = (RELEASE_t *)(dmsg->data + headerlen);
2825 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE | REQUEST, DIRECTION_OUT);
2827 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);
2829 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2830 new_state(PORT_STATE_RELEASE);
2833 free_epointid(epoint_id);
2834 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_CR | REQUEST, DIRECTION_OUT);
2835 add_trace("callref", "new", "0x%x", p_m_d_l3id);
2839 if ((p_m_d_l3id&0xff00) == 0xff00)
2840 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
2846 /* if we are on outgoing/incoming call setup, we may release complete */
2847 if (p_state==PORT_STATE_OUT_SETUP
2848 || p_state==PORT_STATE_IN_SETUP
2849 // NOTE: a bug in mISDNuser (see disconnect_req_out !!!)
2850 || p_state==PORT_STATE_OUT_PROCEEDING)
2852 /* sending release */
2853 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
2854 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
2855 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE | REQUEST, DIRECTION_OUT);
2857 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);
2859 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2860 new_state(PORT_STATE_RELEASE);
2861 goto remove_endpoint;
2864 /* NT-MODE in setup state we must send PROCEEDING first */
2865 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2867 CALL_PROCEEDING_t *proceeding;
2869 /* sending proceeding */
2870 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2871 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2872 l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2873 /* channel information */
2874 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2875 /* progress information */
2876 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2877 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2878 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2879 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2881 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2884 /* sending disconnect */
2885 dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode);
2886 disconnect = (DISCONNECT_t *)(dmsg->data + headerlen);
2887 l1l2l3_trace_header(p_m_mISDNport, this, CC_DISCONNECT | REQUEST, DIRECTION_OUT);
2888 /* progress information */
2889 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2890 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2891 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2892 if (p_m_mISDNport->is_tones)
2893 enc_ie_progress(&disconnect->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2895 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);
2897 epoint = find_epoint_id(epoint_id);
2898 if (param->disconnectinfo.display[0])
2899 p = param->disconnectinfo.display;
2900 if (p) if (*p && p_m_d_ntmode)
2901 enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p);
2903 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2904 new_state(PORT_STATE_RELEASE);
2905 free_epointid(epoint_id);
2911 * endpoint sends messages to the port
2913 int Pdss1::message_epoint(unsigned long epoint_id, int message_id, union parameter *param)
2915 struct message *message;
2917 if (PmISDN::message_epoint(epoint_id, message_id, param))
2922 case MESSAGE_INFORMATION: /* overlap dialing */
2923 if (p_type==PORT_TYPE_DSS1_NT_OUT
2924 && p_state!=PORT_STATE_OUT_OVERLAP
2925 && p_state!=PORT_STATE_CONNECT
2926 && p_state!=PORT_STATE_OUT_DISCONNECT
2927 && p_state!=PORT_STATE_IN_DISCONNECT)
2931 if (p_type==PORT_TYPE_DSS1_TE_OUT
2932 && p_state!=PORT_STATE_OUT_OVERLAP
2933 && p_state!=PORT_STATE_OUT_PROCEEDING
2934 && p_state!=PORT_STATE_OUT_ALERTING
2935 && p_state!=PORT_STATE_CONNECT
2936 && p_state!=PORT_STATE_OUT_DISCONNECT
2937 && p_state!=PORT_STATE_IN_DISCONNECT)
2941 if ((p_type==PORT_TYPE_DSS1_NT_IN || p_type==PORT_TYPE_DSS1_TE_IN)
2942 && p_state!=PORT_STATE_IN_OVERLAP
2943 && p_state!=PORT_STATE_IN_PROCEEDING
2944 && p_state!=PORT_STATE_IN_ALERTING
2945 && p_state!=PORT_STATE_CONNECT
2946 && p_state!=PORT_STATE_CONNECT_WAITING
2947 && p_state!=PORT_STATE_OUT_DISCONNECT
2948 && p_state!=PORT_STATE_IN_DISCONNECT)
2952 message_information(epoint_id, message_id, param);
2955 case MESSAGE_SETUP: /* dial-out command received from epoint */
2956 if (p_state!=PORT_STATE_IDLE
2957 && p_state!=PORT_STATE_CONNECT)
2959 PERROR("Pdss1(%s) ignoring setup because isdn port is not in idle state (or connected for sending display info).\n", p_name);
2962 if (p_epointlist && p_state==PORT_STATE_IDLE)
2964 PERROR("Pdss1(%s): software error: epoint pointer is set in idle state, how bad!! exitting.\n", p_name);
2967 /* note: pri is a special case, because links must be up for pri */
2968 if (p_m_mISDNport->l1link || p_m_mISDNport->pri || !p_m_mISDNport->ntmode || p_state!=PORT_STATE_IDLE)
2970 /* LAYER 1 is up, or we may send */
2971 message_setup(epoint_id, message_id, param);
2974 /* LAYER 1 id down, so we queue */
2975 p_m_d_queue = message_create(epoint_id, p_serial, EPOINT_TO_PORT, message_id);
2976 memcpy(&p_m_d_queue->param, param, sizeof(union parameter));
2978 if (!(epointlist_new(epoint_id)))
2980 PERROR("no memory for epointlist\n");
2984 PDEBUG(DEBUG_ISDN, "the L1 is down, we try to establish the link NT portnum=%d (%s).\n", p_m_mISDNport->portnum, p_name);
2985 act.prim = PH_ACTIVATE | REQUEST;
2986 act.addr = p_m_mISDNport->upper_id | FLG_MSG_DOWN;
2989 mISDN_write(mISDNdevice, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
2990 l1l2l3_trace_header(p_m_mISDNport, this, act.prim, DIRECTION_OUT);
2992 // /* set timeout */
2993 // p_m_mISDNport->l1timeout = now+3;
2997 case MESSAGE_NOTIFY: /* display and notifications */
2998 message_notify(epoint_id, message_id, param);
3001 case MESSAGE_FACILITY: /* facility message */
3002 message_facility(epoint_id, message_id, param);
3005 case MESSAGE_OVERLAP: /* more information is needed */
3006 if (p_state!=PORT_STATE_IN_SETUP)
3010 message_overlap(epoint_id, message_id, param);
3013 case MESSAGE_PROCEEDING: /* call of endpoint is proceeding */
3014 if (p_state!=PORT_STATE_IN_SETUP
3015 && p_state!=PORT_STATE_IN_OVERLAP)
3019 message_proceeding(epoint_id, message_id, param);
3022 case MESSAGE_ALERTING: /* call of endpoint is ringing */
3023 if (p_state!=PORT_STATE_IN_SETUP
3024 && p_state!=PORT_STATE_IN_OVERLAP
3025 && p_state!=PORT_STATE_IN_PROCEEDING)
3029 message_alerting(epoint_id, message_id, param);
3032 case MESSAGE_CONNECT: /* call of endpoint is connected */
3033 if (p_state!=PORT_STATE_IN_SETUP
3034 && p_state!=PORT_STATE_IN_OVERLAP
3035 && p_state!=PORT_STATE_IN_PROCEEDING
3036 && p_state!=PORT_STATE_IN_ALERTING
3037 && !(p_state==PORT_STATE_CONNECT && p_m_d_ntmode))
3041 message_connect(epoint_id, message_id, param);
3044 case MESSAGE_DISCONNECT: /* call has been disconnected */
3045 if (p_state!=PORT_STATE_IN_SETUP
3046 && p_state!=PORT_STATE_IN_OVERLAP
3047 && p_state!=PORT_STATE_IN_PROCEEDING
3048 && p_state!=PORT_STATE_IN_ALERTING
3049 && p_state!=PORT_STATE_OUT_SETUP
3050 && p_state!=PORT_STATE_OUT_OVERLAP
3051 && p_state!=PORT_STATE_OUT_PROCEEDING
3052 && p_state!=PORT_STATE_OUT_ALERTING
3053 && p_state!=PORT_STATE_CONNECT
3054 && p_state!=PORT_STATE_CONNECT_WAITING)
3058 message_disconnect(epoint_id, message_id, param);
3061 case MESSAGE_RELEASE: /* release isdn port */
3062 if (p_state==PORT_STATE_RELEASE)
3066 message_release(epoint_id, message_id, param);
3070 PERROR("Pdss1(%s) isdn port with (caller id %s) received a wrong message: %d\n", p_name, p_callerinfo.id, message);
3079 * data from isdn-stack (layer-3) to pbx (port class)
3081 /* NOTE: nt mode use mISDNuser_head_t as header */
3082 int stack2manager_nt(void *dat, void *arg)
3086 manager_t *mgr = (manager_t *)dat;
3087 msg_t *msg = (msg_t *)arg;
3088 mISDNuser_head_t *hh;
3089 struct mISDNport *mISDNport;
3095 /* note: nst is the first data feld of mISDNport */
3096 mISDNport = (struct mISDNport *)mgr->nst;
3098 hh = (mISDNuser_head_t *)msg->data;
3099 PDEBUG(DEBUG_ISDN, "prim(0x%x) dinfo(0x%x) msg->len(%d)\n", hh->prim, hh->dinfo, msg->len);
3101 /* find Port object of type ISDN */
3105 if (port->p_type == PORT_TYPE_DSS1_NT_IN || port->p_type == PORT_TYPE_DSS1_NT_OUT)
3107 pdss1 = (class Pdss1 *)port;
3108 //PDEBUG(DEBUG_ISDN, "comparing dinfo = 0x%x with l3id 0x%x\n", hh->dinfo, pdss1->p_m_d_l3id);
3109 /* check out correct stack */
3110 if (pdss1->p_m_mISDNport == mISDNport)
3111 /* check out correct id */
3112 if ((hh->dinfo&0xffff0000) == (pdss1->p_m_d_l3id&0xffff0000))
3114 /* found port, the message belongs to */
3122 /* if process id is master process, but a child disconnects */
3123 if ((hh->dinfo&0x0000ff00)!=0x0000ff00 && (pdss1->p_m_d_l3id&0x0000ff00)==0x0000ff00 && hh->prim==(CC_DISCONNECT|INDICATION))
3125 /* send special indication for child disconnect */
3126 pdss1->disconnect_ind_i(hh->prim, hh->dinfo, msg->data);
3130 /* if process id and layer 3 id matches */
3131 if (hh->dinfo == pdss1->p_m_d_l3id)
3133 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
3142 case MGR_SHORTSTATUS | INDICATION:
3143 case MGR_SHORTSTATUS | CONFIRM:
3145 case SSTATUS_L2_ESTABLISHED:
3147 case SSTATUS_L2_RELEASED:
3152 case DL_ESTABLISH | INDICATION:
3153 case DL_ESTABLISH | CONFIRM:
3155 l1l2l3_trace_header(mISDNport, NULL, hh->prim, DIRECTION_IN);
3156 add_trace("tei", NULL, "%d", hh->dinfo);
3158 if (mISDNport->ptp && hh->dinfo == 0)
3160 if (mISDNport->l2establish)
3162 mISDNport->l2establish = 0;
3163 PDEBUG(DEBUG_ISDN, "the link became active before l2establish timer expiry.\n");
3165 mISDNport->l2link = 1;
3166 if (mISDNport->pri);
3167 mISDNport->l1link = 1; /* this is a hack, we also assume L1 to be active */
3171 case DL_RELEASE | INDICATION:
3172 case DL_RELEASE | CONFIRM:
3174 l1l2l3_trace_header(mISDNport, NULL, hh->prim, DIRECTION_IN);
3175 add_trace("tei", NULL, "%d", hh->dinfo);
3177 if (mISDNport->ptp && hh->dinfo == 0)
3179 mISDNport->l2link = 0;
3180 time(&mISDNport->l2establish);
3181 PDEBUG(DEBUG_ISDN, "because we are ptp, we set a l2establish timer.\n");
3185 case CC_SETUP | INDICATION:
3186 /* creating port object */
3187 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3188 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0)))
3190 RELEASE_COMPLETE_t *release_complete;
3193 PERROR("FATAL ERROR: cannot create port object.\n");
3194 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, hh->dinfo, sizeof(RELEASE_COMPLETE_t), mISDNport->ntmode);
3195 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + mISDN_HEADER_LEN);
3196 l1l2l3_trace_header(mISDNport, NULL, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
3197 enc_ie_cause_standalone(mISDNport->ntmode?&release_complete->CAUSE:NULL, dmsg, (mISDNport->ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47);
3199 msg_queue_tail(&mISDNport->downqueue, dmsg);
3202 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
3205 case CC_RESUME | INDICATION:
3206 /* creating port object */
3207 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3208 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0)))
3210 SUSPEND_REJECT_t *suspend_reject;
3213 PERROR("FATAL ERROR: cannot create port object.\n");
3214 dmsg = create_l3msg(CC_SUSPEND_REJECT | REQUEST, MT_SUSPEND_REJECT, hh->dinfo, sizeof(SUSPEND_REJECT_t), mISDNport->ntmode);
3215 suspend_reject = (SUSPEND_REJECT_t *)(dmsg->data + mISDN_HEADER_LEN);
3216 l1l2l3_trace_header(mISDNport, NULL, CC_SUSPEND_REJECT | REQUEST, DIRECTION_OUT);
3217 enc_ie_cause_standalone(mISDNport->ntmode?&suspend_reject->CAUSE:NULL, dmsg, (mISDNport->ntmode)?1:0, 47);
3219 msg_queue_tail(&mISDNport->downqueue, dmsg);
3222 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
3225 case CC_RELEASE_CR | INDICATION:
3226 PERROR("unhandled message from stack: call ref released (l3id=0x%x)\n", hh->dinfo);
3229 case CC_DISCONNECT | INDICATION:
3233 PERROR("unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", hh->prim, hh->dinfo, msg->len);
3240 /* NOTE: te mode use iframe_t as header */
3241 int stack2manager_te(struct mISDNport *mISDNport, msg_t *msg)
3248 if (!msg || !mISDNport)
3250 frm = (iframe_t *)msg->data;
3251 PDEBUG(DEBUG_ISDN, "prim(0x%x) dinfo(0x%x) msg->len(%d)\n", frm->prim, frm->dinfo, msg->len);
3253 /* find Port object of type ISDN */
3257 if (port->p_type == PORT_TYPE_DSS1_TE_IN || port->p_type == PORT_TYPE_DSS1_TE_OUT)
3259 pdss1 = (class Pdss1 *)port;
3260 /* check out correct stack */
3261 if (pdss1->p_m_mISDNport == mISDNport)
3262 /* check out correct id */
3263 if (frm->dinfo == pdss1->p_m_d_l3id)
3265 /* found port, the message belongs to */
3273 pdss1->message_isdn(frm->prim, frm->dinfo, msg->data);
3278 /* process new cr (before setup indication) */
3279 //printf("prim = 0x%x, looking for 0x%x\n",frm->prim, (CC_NEW_CR | INDICATION));
3280 if (frm->prim == (CC_NEW_CR | INDICATION))
3283 /* creating port object */
3284 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3285 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0)))
3287 RELEASE_COMPLETE_t *release_complete;
3290 PERROR("FATAL ERROR: cannot create port object.\n");
3291 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, frm->dinfo, sizeof(RELEASE_COMPLETE_t), mISDNport->ntmode);
3292 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + mISDN_HEADER_LEN);
3293 l1l2l3_trace_header(mISDNport, NULL, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
3294 enc_ie_cause_standalone(mISDNport->ntmode?&release_complete->CAUSE:NULL, dmsg, (mISDNport->ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47);
3296 msg_queue_tail(&mISDNport->downqueue, dmsg);
3300 /* l3id will be set from dinfo at message_isdn */
3301 pdss1->message_isdn(frm->prim, frm->dinfo, msg->data);
3306 if (frm->prim == (CC_RELEASE_CR | INDICATION))
3308 PERROR("unhandled message from stack: call ref released (l3id=0x%x)\n", frm->dinfo);
3312 PERROR("unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", frm->prim, frm->dinfo, msg->len);
3318 * sending message that were queued during L1 activation
3319 * or releasing port if link is down
3321 void setup_queue(struct mISDNport *mISDNport, int link)
3325 struct message *message;
3327 if (!mISDNport->ntmode)
3330 /* check all port objects for pending message */
3334 if ((port->p_type&PORT_CLASS_mISDN_MASK) == PORT_CLASS_mISDN_DSS1)
3336 pdss1 = (class Pdss1 *)port;
3337 if (pdss1->p_m_mISDNport == mISDNport)
3339 if (pdss1->p_m_d_queue)
3343 PDEBUG(DEBUG_ISDN, "the L1 became active, so we send queued message for portnum=%d (%s).\n", mISDNport->portnum, pdss1->p_name);
3344 /* LAYER 1 is up, so we send */
3345 pdss1->message_setup(pdss1->p_m_d_queue->id_from, pdss1->p_m_d_queue->type, &pdss1->p_m_d_queue->param);
3346 message_free(pdss1->p_m_d_queue);
3347 pdss1->p_m_d_queue = NULL;
3350 PDEBUG(DEBUG_ISDN, "the L1 became NOT active, so we release port for portnum=%d (%s).\n", mISDNport->portnum, pdss1->p_name);
3351 message = message_create(pdss1->p_serial, pdss1->p_m_d_queue->id_from, PORT_TO_EPOINT, MESSAGE_RELEASE);
3352 message->param.disconnectinfo.cause = 27;
3353 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
3354 message_put(message);
3355 pdss1->new_state(PORT_STATE_RELEASE);
3356 pdss1->p_m_delete = 1;