1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
10 \*****************************************************************************/
20 #include <sys/ioctl.h>
21 #include <sys/types.h>
37 Pdss1::Pdss1(int type, 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;
49 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);
58 /* remove queued message */
60 message_free(p_m_d_queue);
62 if (p_m_d_notify_pending)
63 message_free(p_m_d_notify_pending);
65 /* check how many processes are left */
66 if (p_m_d_ntmode == 1)
68 if (p_m_mISDNport->nst.layer3->proc)
69 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);
75 * create layer 3 message
77 static msg_t *create_l3msg(int prim, int mt, int dinfo, int size, int ntmode)
85 size = sizeof(Q931_info_t)+2;
91 dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL);
98 dmsg = alloc_msg(size+256+mISDN_HEADER_LEN+DEFAULT_HEADROOM);
101 memset(msg_put(dmsg,size+mISDN_HEADER_LEN), 0, size+mISDN_HEADER_LEN);
102 frm = (iframe_t *)dmsg->data;
105 qi = (Q931_info_t *)(dmsg->data + mISDN_HEADER_LEN);
112 PERROR("cannot allocate memory, trying again...\n");
116 PERROR("cannot allocate memory, system overloaded.\n");
120 msg_t *create_l2msg(int prim, int dinfo, int size) /* NT only */
127 dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL);
132 PERROR("cannot allocate memory, trying again...\n");
136 PERROR("cannot allocate memory, system overloaded.\n");
142 static struct isdn_message {
146 {"TIMEOUT", CC_TIMEOUT},
148 {"SETUP_ACKNOWLEDGE", CC_SETUP_ACKNOWLEDGE},
149 {"PROCEEDING", CC_PROCEEDING},
150 {"ALERTING", CC_ALERTING},
151 {"CONNECT", CC_CONNECT},
152 {"CONNECT RESPONSE", CC_CONNECT},
153 {"CONNECT_ACKNOWLEDGE", CC_CONNECT_ACKNOWLEDGE},
154 {"DISCONNECT", CC_DISCONNECT},
155 {"RELEASE", CC_RELEASE},
156 {"RELEASE_COMPLETE", CC_RELEASE_COMPLETE},
157 {"INFORMATION", CC_INFORMATION},
158 {"PROGRESS", CC_PROGRESS},
159 {"NOTIFY", CC_NOTIFY},
160 {"SUSPEND", CC_SUSPEND},
161 {"SUSPEND_ACKNOWLEDGE", CC_SUSPEND_ACKNOWLEDGE},
162 {"SUSPEND_REJECT", CC_SUSPEND_REJECT},
163 {"RESUME", CC_RESUME},
164 {"RESUME_ACKNOWLEDGE", CC_RESUME_ACKNOWLEDGE},
165 {"RESUME_REJECTE", CC_RESUME_REJECT},
167 {"HOLD_ACKNOWLEDGE", CC_HOLD_ACKNOWLEDGE},
168 {"HOLD_REJECT", CC_HOLD_REJECT},
169 {"RETRIEVE", CC_RETRIEVE},
170 {"RETRIEVE_ACKNOWLEDGE", CC_RETRIEVE_ACKNOWLEDGE},
171 {"RETRIEVE_REJECTE", CC_RETRIEVE_REJECT},
172 {"FACILITY", CC_FACILITY},
173 {"STATUS", CC_STATUS},
174 {"RESTART", CC_RESTART},
175 {"RELEASE_CR", CC_RELEASE_CR},
176 {"NEW_CR", CC_NEW_CR},
181 static char *isdn_prim[4] = {
190 * show message to debug
192 void Pdss1::isdn_show_send_message(unsigned long prim, msg_t *msg)
195 char *msgtext = "<<UNKNOWN MESSAGE>>";
199 while(isdn_message[i].name)
201 if (isdn_message[i].value == (prim&0xffffff00))
203 msgtext = isdn_message[i].name;
208 primtext = isdn_prim[prim&0x00000003];
209 printisdn(">>> outgoing prim: %s %s (0x%x)\n", msgtext, primtext, prim);
214 * if we received a first reply to the setup message,
215 * we will check if we have now channel information
216 * return: <0: error, call is released, -cause is given
217 * 0: ok, nothing to do
219 int Pdss1::received_first_reply_to_setup(unsigned long prim, int channel, int exclusive)
222 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
223 RELEASE_COMPLETE_t *release_complete;
226 /* corret exclusive to 0, if no explicit channel was given */
227 if (exclusive<0 || channel<=0)
230 /* select scenario */
231 if (p_m_b_channel && p_m_b_exclusive)
233 /*** we gave an exclusive channel (or if we are done) ***/
235 /* if not first reply, we are done */
236 if (p_state != PORT_STATE_OUT_SETUP)
239 /* if give channel not accepted or not equal */
240 if (channel!=-1 && p_m_b_channel!=channel)
242 PDEBUG(DEBUG_BCHANNEL, "- our forced channel %d was not accepted\n", p_m_b_channel);
247 /* activate our exclusive channel */
248 bchannel_activate(p_m_mISDNport, p_m_b_index);
252 /*** we gave a non-exclusive channel ***/
254 /* if not first reply, we are done */
255 if (p_state != PORT_STATE_OUT_SETUP)
258 /* if channel was accepted as given */
259 if (channel==-1 || p_m_b_channel==channel)
261 PDEBUG(DEBUG_BCHANNEL, "- our suggested channel %d was accpted\n", p_m_b_channel);
262 p_m_b_exclusive = 1; // we are done
263 bchannel_activate(p_m_mISDNport, p_m_b_index);
267 /* if channel value is faulty */
270 PDEBUG(DEBUG_BCHANNEL, "- our suggested channel %d was replied with no channel value.\n", p_m_b_channel);
271 ret = -111; // protocol error
275 /* if channel was not accepted, try to get it */
276 PDEBUG(DEBUG_BCHANNEL, "- our suggested channel %d was not accepted, but %d was given.\n", p_m_b_channel, channel);
277 ret = seize_bchannel(channel, 1); // exclusively
280 PDEBUG(DEBUG_BCHANNEL, "- the replied channel %d is not available (cause %d).\n", channel, -ret);
283 PDEBUG(DEBUG_BCHANNEL, "- we accepted channel %d.\n", channel);
285 /* activate channel given by remote */
286 bchannel_activate(p_m_mISDNport, p_m_b_index);
290 /*** we sent 'any channel acceptable' ***/
292 /* if not first reply, we are done */
293 if (p_state != PORT_STATE_OUT_SETUP)
296 /* if no channel was given */
299 PDEBUG(DEBUG_BCHANNEL, "- our channel request was not replied by a channel.\n", p_m_b_channel);
300 ret = -111; // protocol error
304 /* we will see, if our received channel is available */
305 PDEBUG(DEBUG_BCHANNEL, "- our channel request was replied with channel %d.\n", channel);
306 ret = seize_bchannel(channel, 1); // exclusively
309 PDEBUG(DEBUG_BCHANNEL, "- the replied channel %d is not available (cause %d).\n", channel, -ret);
312 PDEBUG(DEBUG_BCHANNEL, "- we accepted channel %d.\n", channel);
314 /* activate channel given by remote */
315 bchannel_activate(p_m_mISDNport, p_m_b_index);
318 /*** we sent 'no channel available' ***/
320 /* if not the first reply, but a connect, we are forced */
321 if (prim==(CC_CONNECT | INDICATION) && p_state!=PORT_STATE_OUT_SETUP)
325 PDEBUG(DEBUG_BCHANNEL, "- while call-waiting, we get a channel inside connect message, so we use it.\n", p_m_b_channel);
326 goto use_from_connect;
328 PDEBUG(DEBUG_BCHANNEL, "- there is no channel inside connect message during call-waiting, so we request one.\n", p_m_b_channel);
329 ret = seize_bchannel(CHANNEL_ANY, 0); // any channel
332 PDEBUG(DEBUG_BCHANNEL, "- during call-waiting, we got a connect, but no available channel (cause=%d).\n", -ret);
335 p_m_b_exclusive = 1; // we are done
337 /* activate channel given by remote */
338 bchannel_activate(p_m_mISDNport, p_m_b_index);
342 /* if not first reply, we are done */
343 if (p_state != PORT_STATE_OUT_SETUP)
346 /* if first reply has no channel, we are done */
349 PDEBUG(DEBUG_BCHANNEL, "- while call-waiting, we got no channel as first reply, this is good.\n");
353 /* we will see, if our received channel is available */
354 PDEBUG(DEBUG_BCHANNEL, "- our during call-waiting, we get channel %d as first reply.\n", channel);
356 ret = seize_bchannel(channel, exclusive);
359 PDEBUG(DEBUG_BCHANNEL, "- the given channel %d is not available (cause %d).\n", channel, -ret);
362 PDEBUG(DEBUG_BCHANNEL, "- we accepted channel %d.\n", channel);
363 p_m_b_exclusive = 1; // we are done
365 /* activate channel given by remote */
366 bchannel_activate(p_m_mISDNport, p_m_b_index);
371 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
372 isdn_show_send_message(CC_RELEASE_COMPLETE | REQUEST, dmsg);
374 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
375 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
376 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
377 new_state(PORT_STATE_RELEASE);
379 return(-34); /* to epoint: no channel available */
384 * handles all indications
386 /* CC_SETUP INDICATION */
387 void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
389 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
390 SETUP_t *setup = (SETUP_t *)((unsigned long)data + headerlen);
391 int type, plan, present, screen, reason;
392 int coding, capability, mode, rate, multi, user, presentation, interpretation, hlc, exthlc;
393 int exclusive, channel;
396 unsigned char keypad[32] = "";
397 unsigned char useruser[128];
398 int useruser_len = 0, useruser_protocol;
399 class Endpoint *epoint;
400 struct message *message;
402 /* if blocked, release call */
403 if (p_m_mISDNport->ifport->block)
405 RELEASE_COMPLETE_t *release_complete;
407 printlog("--- port#%d is blocked.\n", mISDNport->ifport->portnum);
408 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
409 isdn_show_send_message(CC_RELEASE_COMPLETE | REQUEST, dmsg);
410 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
411 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 27); /* temporary unavailable */
412 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
413 new_state(PORT_STATE_RELEASE);
418 /* caller information */
419 dec_ie_calling_pn(setup->CALLING_PN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, &screen, (unsigned char *)p_callerinfo.id, sizeof(p_callerinfo.id));
423 p_callerinfo.present = INFO_PRESENT_RESTRICTED;
426 p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
429 p_callerinfo.present = INFO_PRESENT_ALLOWED;
435 p_callerinfo.screen = INFO_SCREEN_USER;
438 p_callerinfo.screen = INFO_SCREEN_NETWORK;
444 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
445 p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
446 p_callerinfo.screen = INFO_SCREEN_NETWORK;
449 p_callerinfo.ntype = INFO_NTYPE_INTERNATIONAL;
452 p_callerinfo.ntype = INFO_NTYPE_NATIONAL;
455 p_callerinfo.ntype = INFO_NTYPE_SUBSCRIBER;
458 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
461 p_callerinfo.isdn_port = p_m_portnum;
462 SCPY(p_callerinfo.interface, p_m_mISDNport->ifport->interface->name);
463 /* dialing information */
464 dec_ie_called_pn(setup->CALLED_PN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, (unsigned char *)p_dialinginfo.number, sizeof(p_dialinginfo.number));
465 dec_ie_keypad(setup->KEYPAD, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)keypad, sizeof(keypad));
466 SCAT(p_dialinginfo.number, (char *)keypad);
470 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
473 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
476 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
479 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
483 /* te-mode: CNIP (calling name identification presentation) */
485 dec_facility_centrex(setup->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)p_callerinfo.name, sizeof(p_callerinfo.name));
489 dec_ie_useruser(setup->USER_USER, (Q931_info_t *)((unsigned long)data+headerlen), &useruser_protocol, useruser, &useruser_len);
491 /* sending complete */
492 dec_ie_complete(setup->COMPLETE, (Q931_info_t *)((unsigned long)data+headerlen), &p_dialinginfo.sending_complete);
493 /* redirecting number */
494 dec_ie_redir_nr(setup->REDIR_NR, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, &screen, &reason, (unsigned char *)p_redirinfo.id, sizeof(p_redirinfo.id));
498 p_redirinfo.present = INFO_PRESENT_RESTRICTED;
501 p_redirinfo.present = INFO_PRESENT_NOTAVAIL;
504 p_redirinfo.present = INFO_PRESENT_ALLOWED;
510 p_redirinfo.screen = INFO_SCREEN_USER;
513 p_redirinfo.screen = INFO_SCREEN_NETWORK;
519 p_redirinfo.reason = INFO_REDIR_BUSY;
522 p_redirinfo.reason = INFO_REDIR_NORESPONSE;
525 p_redirinfo.reason = INFO_REDIR_UNCONDITIONAL;
528 p_redirinfo.reason = INFO_REDIR_CALLDEFLECT;
531 p_redirinfo.reason = INFO_REDIR_OUTOFORDER;
534 p_redirinfo.reason = INFO_REDIR_UNKNOWN;
540 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
541 p_redirinfo.present = INFO_PRESENT_NULL; /* not redirecting */
542 p_redirinfo.reason = INFO_REDIR_UNKNOWN;
545 p_redirinfo.ntype = INFO_NTYPE_INTERNATIONAL;
548 p_redirinfo.ntype = INFO_NTYPE_NATIONAL;
551 p_redirinfo.ntype = INFO_NTYPE_SUBSCRIBER;
554 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
557 p_redirinfo.isdn_port = p_m_portnum;
558 /* bearer capability */
559 dec_ie_bearer(setup->BEARER, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &capability, &mode, &rate, &multi, &user);
563 p_capainfo.bearer_capa = INFO_BC_AUDIO;
564 user = (options.law=='a')?3:2;
567 p_capainfo.bearer_capa = capability;
573 p_capainfo.bearer_mode = INFO_BMODE_PACKET;
576 p_capainfo.bearer_mode = INFO_BMODE_CIRCUIT;
582 p_capainfo.bearer_info1 = INFO_INFO1_NONE;
585 p_capainfo.bearer_info1 = user + 0x80;
590 dec_ie_hlc(setup->HLC, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &interpretation, &presentation, &hlc, &exthlc);
594 p_capainfo.hlc = INFO_HLC_NONE;
597 p_capainfo.hlc = hlc + 0x80;
603 p_capainfo.exthlc = INFO_HLC_NONE;
606 p_capainfo.exthlc = exthlc + 0x80;
611 dec_ie_channel_id(setup->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
614 if (channel==CHANNEL_NO && p_type==PORT_TYPE_DSS1_TE_IN)
615 PDEBUG(DEBUG_BCHANNEL, "- no channel is given by the network, causing to fail, since CW is not possible for external lines\n");
616 if (channel <= 0) /* not given, no channel, whatever.. */
617 channel = CHANNEL_ANY; /* any channel */
618 if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num) // of out chan..
620 printlog("--- port#%d all channels are used/reserved.\n", ifport->portnum);
621 ret = -34; // no channel
624 if (channel == CHANNE_ANY)
626 PDEBUG(DEBUG_BCHANNEL, "- any channel is assumed from the %s, so we need to return the a channel from our list\n", (p_m_d_ntmode)?"user":"network");
627 /* check for any channel form selection list */
629 selchannel = ifport->channel_in;
632 switch(selchannel->channel)
634 case CHANNEL_FREE: /* free channel */
635 if (mISDNport->b_inuse >= mISDNport->b_num)
636 break; /* all channel in use or reserverd */
639 while(i < mISDNport->b_num)
641 if (mISDNport->b_port[i] == NULL)
643 channel = i+1+(i>=15);
644 printlog("--- port#%d no channel given, so selecting free channel %d\n", ifport->portnum, channel);
652 if (selchannel->channel<1 || selchannel->channel==16)
653 break; /* invalid channels */
654 i = selchannel->channel-1-(selchannel->channel>=17);
655 if (i >= mISDNport->b_num)
656 break; /* channel not in port */
657 if (mISDNport->b_port[i] == NULL)
659 channel = selchannel->channel;
660 printlog("--- port#%d no channel given, so selecting channel %d from list\n", ifport->portnum, channel);
666 break; /* found channel */
667 selchannel = selchannel->next;
671 printlog("--- port#%d no channel found.\n", ifport->portnum);
672 ret = -34; // no channel
679 /* check for given channel in selection list */
680 selchannel = ifport->channel_in;
683 if (selchannel->channel == channel || selchannel->channel == CHANNEL_FREE)
685 selchannel = selchannel->next;
690 /* exclusive channel requests must be in the list */
695 PDEBUG(DEBUG_BCHANNEL, "- exclusive channel %d is selected, but not in list of incomming channel.\n", channel);
696 printlog("--- port#%d channel %d given exclusively, it is accepted.\n", ifport->portnum, channel);
697 ret = 6; // unacceptable
700 PDEBUG(DEBUG_BCHANNEL, "- exclusive channel %d is selected, as in list of incomming channels.\n", channel);
701 i = selchannel->channel-1-(selchannel->channel>=17);
702 if (mISDNport->b_port[i] == NULL)
704 printlog("--- port#%d channel %d given exclusively, it is accepted and free.\n", ifport->portnum, channel);
707 printlog("--- port#%d channel %d given exclusively, it is accepted, but busy.\n", ifport->portnum, channel);
708 ret = 6; // unacceptable
712 /* requested channels in list will be used */
715 PDEBUG(DEBUG_BCHANNEL, "- channel %d given, found in list.\n", channel);
716 i = selchannel->channel-1-(selchannel->channel>=17);
717 if (mISDNport->b_port[i] == NULL)
719 printlog("--- port#%d channel %d given, it is accepted and free.\n", ifport->portnum, channel);
724 /* if channel is not available or not in list, it must be searched */
725 PDEBUG(DEBUG_BCHANNEL, "- channel %d given, but not in list of incomming channels.\n", channel);
727 /* check for first free channel in list */
729 selchannel = ifport->channel_in;
732 switch(selchannel->channel)
734 case CHANNEL_FREE: /* free channel */
735 if (mISDNport->b_inuse >= mISDNport->b_num)
736 break; /* all channel in use or reserverd */
739 while(i < mISDNport->b_num)
741 if (mISDNport->b_port[i] == NULL)
743 channel = i+1+(i>=15);
744 printlog("--- port#%d requested channel was not in list, so using free channel %d from list.\n", ifport->portnum, channel);
752 if (selchannel->channel<1 || selchannel->channel==16)
753 break; /* invalid channels */
754 i = selchannel->channel-1-(selchannel->channel>=17);
755 if (i >= mISDNport->b_num)
756 break; /* channel not in port */
757 if (mISDNport->b_port[i] == NULL)
759 channel = selchannel->channel;
760 printlog("--- port#%d requested channel was not in list, so using free channel %d from list.\n", ifport->portnum, channel);
766 break; /* found channel */
767 selchannel = selchannel->next;
771 printlog("--- port#%d no channel found.\n", ifport->portnum);
772 ret = 6; // unacceptable
779 ret = seize_bchannel(channel, 1);
783 PDEBUG(DEBUG_BCHANNEL, "- channel is not available (cause=%d), so we send a release_complete.\n", -ret);
784 RELEASE_COMPLETE_t *release_complete;
786 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
787 isdn_show_send_message(CC_RELEASE_COMPLETE | REQUEST, dmsg);
788 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
789 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
790 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
791 new_state(PORT_STATE_RELEASE);
795 PDEBUG(DEBUG_BCHANNEL, "- channel is available, we open channel %d.\n", ret);
796 bchannel_activate(p_m_mISDNport, p_m_b_index);
798 /* create endpoint */
801 PERROR("SOFTWARE ERROR: incoming call but already got an endpoint, exitting...\n");
804 if (!(epoint = new Endpoint(p_serial, 0)))
806 RELEASE_COMPLETE_t *release_complete;
808 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
809 isdn_show_send_message(CC_RELEASE_COMPLETE | REQUEST, dmsg);
810 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
811 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 41); /* temporary failure */
812 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
813 new_state(PORT_STATE_RELEASE);
817 if (!(epoint->ep_app = new DEFAULT_ENDPOINT_APP(epoint)))
819 PERROR("no memory for application\n");
822 if (!(epointlist_new(epoint->ep_serial)))
824 PERROR("no memory for epointlist\n");
829 /* nt-library now gives us the id via CC_SETUP */
830 if (dinfo&(~0xff) == 0xff00)
832 PERROR("fatal software error: l3-stack gives us a process id 0xff00-0xffff\n");
835 printisdn(" l3id 0x%x changes to 0x%x\n", p_m_d_l3id, dinfo);
836 if (p_m_d_l3id&(~0xff) == 0xff00)
837 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
839 p_m_d_ces = setup->ces;
840 PDEBUG(DEBUG_ISDN, "Pdss1(%s) nt-mode gives us new l3id via setup ind: 0x%x\n", p_name, p_m_d_l3id);
843 /* send setup message to endpoit */
844 PDEBUG(DEBUG_ISDN, "Pdss1(%s) setup: %s->%s\n", p_name, p_callerinfo.id, p_dialinginfo.number);
845 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_SETUP);
846 message->param.setup.isdn_port = p_m_portnum;
847 message->param.setup.port_type = p_type;
848 memcpy(&message->param.setup.dialinginfo, &p_dialinginfo, sizeof(struct dialing_info));
849 memcpy(&message->param.setup.callerinfo, &p_callerinfo, sizeof(struct caller_info));
850 memcpy(&message->param.setup.redirinfo, &p_redirinfo, sizeof(struct redir_info));
851 memcpy(&message->param.setup.capainfo, &p_capainfo, sizeof(struct capa_info));
852 memcpy(message->param.setup.useruser.data, &useruser, useruser_len);
853 message->param.setup.useruser.len = useruser_len;
854 message->param.setup.useruser.protocol = useruser_protocol;
855 message_put(message);
857 new_state(PORT_STATE_IN_SETUP);
860 /* CC_INFORMATION INDICATION */
861 void Pdss1::information_ind(unsigned long prim, unsigned long dinfo, void *data)
863 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
864 INFORMATION_t *information = (INFORMATION_t *)((unsigned long)data + headerlen);
866 unsigned char keypad[32] = "";
867 struct message *message;
869 /* dialing information */
870 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));
871 dec_ie_keypad(information->KEYPAD, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)keypad, sizeof(keypad));
872 SCAT(p_dialinginfo.number, (char *)keypad);
876 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
879 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
882 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
885 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
888 /* sending complete */
889 dec_ie_complete(information->COMPLETE, (Q931_info_t *)((unsigned long)data+headerlen), &p_dialinginfo.sending_complete);;
890 PDEBUG(DEBUG_ISDN, "Pdss1(%s) more digits: %s\n", p_name,p_dialinginfo.number);
891 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_INFORMATION);
892 memcpy(&message->param.information, &p_dialinginfo, sizeof(struct dialing_info));
893 message_put(message);
894 /* reset overlap timeout */
898 /* CC_SETUP_ACCNOWLEDGE INDICATION */
899 void Pdss1::setup_acknowledge_ind(unsigned long prim, unsigned long dinfo, void *data)
901 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
902 SETUP_ACKNOWLEDGE_t *setup_acknowledge = (SETUP_ACKNOWLEDGE_t *)((unsigned long)data + headerlen);
903 int exclusive, channel;
904 int coding, location, progress;
906 struct message *message;
909 dec_ie_channel_id(setup_acknowledge->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
910 dec_ie_progress(setup_acknowledge->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
911 ret = received_first_reply_to_setup(prim, exclusive, channel);
914 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
915 message->param.disconnectinfo.cause = -ret;
916 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
917 message_put(message);
918 new_state(PORT_STATE_RELEASE);
922 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_OVERLAP);
923 message_put(message);
925 new_state(PORT_STATE_OUT_OVERLAP);
928 /* CC_PROCEEDING INDICATION */
929 void Pdss1::proceeding_ind(unsigned long prim, unsigned long dinfo, void *data)
931 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
932 CALL_PROCEEDING_t *proceeding = (CALL_PROCEEDING_t *)((unsigned long)data + headerlen);
933 int exclusive, channel;
934 int coding, location, progress;
936 struct message *message;
937 int notify = -1, type, plan, present;
941 dec_ie_channel_id(proceeding->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
942 dec_ie_progress(proceeding->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
943 ret = received_first_reply_to_setup(prim, exclusive, channel);
946 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
947 message->param.disconnectinfo.cause = -ret;
948 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
949 message_put(message);
950 new_state(PORT_STATE_RELEASE);
954 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROCEEDING);
955 message_put(message);
957 new_state(PORT_STATE_OUT_PROCEEDING);
959 dec_ie_notify(NULL/*proceeding->NOTIFY*/, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
964 dec_ie_redir_dn(proceeding->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
965 if (type >= 0 || notify)
967 if (!notify && type >= 0)
969 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
970 message->param.notifyinfo.notify = notify;
971 SCPY(message->param.notifyinfo.id, redir);
972 /* redirection number */
976 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
979 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
982 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
988 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
989 message->param.notifyinfo.present = INFO_PRESENT_NULL;
992 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
995 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
998 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1001 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1004 message->param.notifyinfo.isdn_port = p_m_portnum;
1005 message_put(message);
1009 /* CC_ALERTING INDICATION */
1010 void Pdss1::alerting_ind(unsigned long prim, unsigned long dinfo, void *data)
1012 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1013 ALERTING_t *alerting = (ALERTING_t *)((unsigned long)data + headerlen);
1014 int exclusive, channel;
1015 int coding, location, progress;
1017 struct message *message;
1018 int notify = -1, type, plan, present;
1022 dec_ie_channel_id(alerting->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
1023 dec_ie_progress(alerting->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
1024 ret = received_first_reply_to_setup(prim, exclusive, channel);
1027 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1028 message->param.disconnectinfo.cause = -ret;
1029 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1030 message_put(message);
1031 new_state(PORT_STATE_RELEASE);
1035 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_ALERTING);
1036 message_put(message);
1038 new_state(PORT_STATE_OUT_ALERTING);
1040 dec_ie_notify(NULL/*alerting->NOTIFY*/, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
1045 dec_ie_redir_dn(alerting->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
1046 if (type >= 0 || notify)
1048 if (!notify && type >= 0)
1050 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1051 message->param.notifyinfo.notify = notify;
1052 SCPY(message->param.notifyinfo.id, redir);
1056 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1059 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1062 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1068 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1069 message->param.notifyinfo.present = INFO_PRESENT_NULL;
1072 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1075 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1078 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1081 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1084 message->param.notifyinfo.isdn_port = p_m_portnum;
1085 message_put(message);
1089 /* CC_CONNECT INDICATION */
1090 void Pdss1::connect_ind(unsigned long prim, unsigned long dinfo, void *data)
1092 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1093 CONNECT_t *connect = (CONNECT_t *)((unsigned long)data + headerlen);
1094 int exclusive, channel;
1095 int type, plan, present, screen;
1098 struct message *message;
1099 int bchannel_before;
1102 p_m_d_ces = connect->ces;
1104 /* NOTE: we do not check the connected channel, since we
1105 * ready sent a channel to the remote side
1108 dec_ie_channel_id(connect->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
1109 bchannel_before = p_m_b_channel;
1110 ret = received_first_reply_to_setup(prim, exclusive, channel);
1113 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1114 message->param.disconnectinfo.cause = -ret;
1115 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1116 message_put(message);
1117 new_state(PORT_STATE_RELEASE);
1121 /* connect information */
1122 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));
1126 p_connectinfo.present = INFO_PRESENT_RESTRICTED;
1129 p_connectinfo.present = INFO_PRESENT_NOTAVAIL;
1132 p_connectinfo.present = INFO_PRESENT_ALLOWED;
1138 p_connectinfo.screen = INFO_SCREEN_USER;
1141 p_connectinfo.screen = INFO_SCREEN_NETWORK;
1147 p_connectinfo.present = INFO_PRESENT_NULL; /* no COLP info */
1148 p_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1151 p_connectinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1154 p_connectinfo.ntype = INFO_NTYPE_NATIONAL;
1157 p_connectinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1160 p_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1163 p_connectinfo.isdn_port = p_m_portnum;
1164 SCPY(p_connectingo.interface, p_m_mISDNport->ifport->interface->name);
1166 /* te-mode: CONP (connected name identification presentation) */
1168 dec_facility_centrex(connect->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)p_connectinfo.name, sizeof(p_connectinfo.name));
1170 /* send connect acknowledge */
1171 CONNECT_ACKNOWLEDGE_t *connect_acknowledge;
1173 dmsg = create_l3msg(CC_CONNECT | RESPONSE, MT_CONNECT, dinfo, sizeof(CONNECT_ACKNOWLEDGE_t), p_m_d_ntmode);
1174 isdn_show_send_message(CC_CONNECT | RESPONSE, dmsg);
1175 connect_acknowledge = (CONNECT_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1176 /* if we had no bchannel before, we send it now */
1177 if (!bchannel_before && p_m_b_channel)
1178 enc_ie_channel_id(&connect_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
1179 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1181 PDEBUG(DEBUG_ISDN, "Pdss1(%s) connect (to '%s' COLP: '%s')\n", p_name, p_dialinginfo.number, p_connectinfo.id);
1182 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CONNECT);
1183 memcpy(&message->param.connectinfo, &p_connectinfo, sizeof(struct connect_info));
1184 message_put(message);
1186 new_state(PORT_STATE_CONNECT);
1189 /* CC_DISCONNECT INDICATION */
1190 void Pdss1::disconnect_ind(unsigned long prim, unsigned long dinfo, void *data)
1192 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1193 DISCONNECT_t *disconnect = (DISCONNECT_t *)((unsigned long)data + headerlen);
1194 int location, cause;
1195 int coding, proglocation, progress;
1196 struct message *message;
1199 dec_ie_progress(disconnect->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &proglocation, &progress);
1200 dec_ie_cause(disconnect->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1204 /* release if we are remote sends us no tones */
1205 if (p_m_mISDNport->is_earlyb)
1210 PDEBUG(DEBUG_ISDN, "Pdss1(%s) send release because remote disconnects AND provides no patterns (earlyb).\n", p_name);
1211 dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, dinfo, sizeof(RELEASE_t), p_m_d_ntmode);
1212 isdn_show_send_message(CC_RELEASE | REQUEST, dmsg);
1213 release = (RELEASE_t *)(dmsg->data + headerlen);
1214 enc_ie_cause(&release->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16); /* normal */
1215 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1217 /* sending release to endpoint */
1220 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1221 message->param.disconnectinfo.cause = cause;
1222 message->param.disconnectinfo.location = location;
1223 message_put(message);
1225 free_epointlist(p_epointlist);
1227 new_state(PORT_STATE_RELEASE);
1232 /* sending disconnect to active endpoint and release to inactive endpoints */
1233 if (ACTIVE_EPOINT(p_epointlist))
1235 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DISCONNECT);
1236 message->param.disconnectinfo.location = location;
1237 message->param.disconnectinfo.cause = cause;
1238 message_put(message);
1240 while(INACTIVE_EPOINT(p_epointlist))
1242 message = message_create(p_serial, INACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1243 message->param.disconnectinfo.location = location;
1244 message->param.disconnectinfo.cause = cause;
1245 message_put(message);
1247 free_epointid(INACTIVE_EPOINT(p_epointlist));
1249 new_state(PORT_STATE_IN_DISCONNECT);
1252 /* CC_DISCONNECT INDICATION */
1253 void Pdss1::disconnect_ind_i(unsigned long prim, unsigned long dinfo, void *data)
1255 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1256 DISCONNECT_t *disconnect = (DISCONNECT_t *)((unsigned long)data + headerlen);
1257 int location, cause;
1260 dec_ie_cause(disconnect->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1263 PDEBUG(DEBUG_ISDN, "PORT(%d) collecting cause %d location %d.\n", p_serial, cause, location);
1264 if (cause == CAUSE_REJECTED) /* call rejected */
1266 p_m_d_collect_cause = CAUSE_REJECTED;
1267 p_m_d_collect_location = location;
1269 if (cause==CAUSE_NORMAL && p_m_d_collect_cause!=CAUSE_REJECTED) /* reject via hangup */
1271 p_m_d_collect_cause = CAUSE_NORMAL;
1272 p_m_d_collect_location = location;
1274 if (cause==CAUSE_BUSY && p_m_d_collect_cause!=CAUSE_REJECTED && p_m_d_collect_cause!=CAUSE_NORMAL) /* busy */
1276 p_m_d_collect_cause = CAUSE_BUSY;
1277 p_m_d_collect_location = location;
1279 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 */
1281 p_m_d_collect_cause = CAUSE_OUTOFORDER;
1282 p_m_d_collect_location = location;
1284 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 */
1286 p_m_d_collect_cause = cause;
1287 p_m_d_collect_location = location;
1289 PDEBUG(DEBUG_ISDN, "PORT(%d) new multipoint cause %d location %d.\n", p_serial, p_m_d_collect_cause, p_m_d_collect_location);
1293 /* CC_RELEASE INDICATION */
1294 void Pdss1::release_ind(unsigned long prim, unsigned long dinfo, void *data)
1296 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1297 RELEASE_t *release = (RELEASE_t *)((unsigned long)data + headerlen);
1299 int location, cause;
1300 struct message *message;
1303 dec_ie_cause(release->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1307 /* sending release to endpoint */
1310 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1311 message->param.disconnectinfo.cause = cause;
1312 message->param.disconnectinfo.location = location;
1313 message_put(message);
1315 free_epointlist(p_epointlist);
1318 /* only in NT mode we must send release_complete, if we got a release confirm */
1319 if (prim == (CC_RELEASE | CONFIRM))
1321 /* sending release complete */
1322 RELEASE_COMPLETE_t *release_complete;
1324 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
1325 isdn_show_send_message(CC_RELEASE_COMPLETE | REQUEST, dmsg);
1326 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
1327 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16);
1328 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1331 new_state(PORT_STATE_RELEASE);
1335 /* CC_RELEASE_COMPLETE INDICATION */
1336 void Pdss1::release_complete_ind(unsigned long prim, unsigned long dinfo, void *data)
1338 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1339 RELEASE_COMPLETE_t *release_complete = (RELEASE_COMPLETE_t *)((unsigned long)data + headerlen);
1340 int location, cause;
1341 struct message *message;
1344 dec_ie_cause(release_complete->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1348 /* sending release to endpoint */
1351 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1352 message->param.disconnectinfo.cause = cause;
1353 message->param.disconnectinfo.location = location;
1354 message_put(message);
1356 free_epointlist(p_epointlist);
1359 PDEBUG(DEBUG_ISDN, "Pdss1(%s) release_complete (cause %d)\n", p_name, cause);
1360 new_state(PORT_STATE_RELEASE);
1365 void Pdss1::t312_timeout(unsigned long prim, unsigned long dinfo, void *data)
1367 struct message *message;
1369 /* sending release to endpoint */
1372 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1373 message->param.disconnectinfo.cause = p_m_d_collect_cause;
1374 message->param.disconnectinfo.location = p_m_d_collect_location;
1375 message_put(message);
1377 free_epointlist(p_epointlist);
1380 PDEBUG(DEBUG_ISDN, "Pdss1(%s) t312_timeout (collected cause %d location %d)\n", p_name, p_m_d_collect_cause, p_m_d_collect_location);
1381 new_state(PORT_STATE_RELEASE);
1385 /* CC_NOTIFY INDICATION */
1386 void Pdss1::notify_ind(unsigned long prim, unsigned long dinfo, void *data)
1388 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1389 NOTIFY_t *notifying = (NOTIFY_t *)((unsigned long)data + headerlen);
1390 struct message *message;
1391 int notify, type, plan, present;
1393 if (!ACTIVE_EPOINT(p_epointlist))
1395 PDEBUG(DEBUG_ISDN, "Pdss1(%s) there is no active endpoint to notify to.\n", p_name);
1398 /* notification indicator */
1399 dec_ie_notify(notifying->NOTIFY, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
1403 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1404 message->param.notifyinfo.notify = notify;
1405 /* redirection number */
1406 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));
1410 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1413 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1416 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1422 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1423 message->param.notifyinfo.present = INFO_PRESENT_NULL;
1426 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1429 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1432 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1435 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1438 message->param.notifyinfo.isdn_port = p_m_portnum;
1439 message_put(message);
1443 /* CC_HOLD INDICATION */
1444 void Pdss1::hold_ind(unsigned long prim, unsigned long dinfo, void *data)
1446 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1447 // HOLD_t *hold = (HOLD_t *)((unsigned long)data + headerlen);
1448 struct message *message;
1449 HOLD_REJECT_t *hold_reject;
1450 HOLD_ACKNOWLEDGE_t *hold_acknowledge;
1452 // class Endpoint *epoint;
1454 if (!ACTIVE_EPOINT(p_epointlist) || p_m_hold)
1457 PDEBUG(DEBUG_ISDN, "Pdss1(%s) there is no endpoint to notify hold OR we are already on hold, so we reject.\n", p_name);
1459 dmsg = create_l3msg(CC_HOLD_REJECT | REQUEST, MT_HOLD_REJECT, dinfo, sizeof(HOLD_REJECT_t), p_m_d_ntmode);
1460 isdn_show_send_message(CC_HOLD_REJECT | REQUEST, dmsg);
1461 hold_reject = (HOLD_REJECT_t *)(dmsg->data + headerlen);
1462 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 */
1463 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1468 /* notify the hold of call */
1469 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1470 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_HOLD;
1471 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1472 message_put(message);
1474 /* deactivate bchannel */
1477 /* set hold state */
1480 epoint = find_epoint_id(ACTIVE_EPOINT(p_epointlist));
1481 if (epoint && p_m_d_ntmode)
1483 p_m_timeout = p_settings.tout_hold;
1488 /* acknowledge hold */
1489 dmsg = create_l3msg(CC_HOLD_ACKNOWLEDGE | REQUEST, MT_HOLD_ACKNOWLEDGE, dinfo, sizeof(HOLD_ACKNOWLEDGE_t), p_m_d_ntmode);
1490 isdn_show_send_message(CC_HOLD_ACKNOWLEDGE | REQUEST, dmsg);
1491 hold_acknowledge = (HOLD_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1492 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1496 /* CC_RETRIEVE INDICATION */
1497 void Pdss1::retrieve_ind(unsigned long prim, unsigned long dinfo, void *data)
1499 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1500 RETRIEVE_t *retrieve = (RETRIEVE_t *)((unsigned long)data + headerlen);
1501 RETRIEVE_REJECT_t *retrieve_reject;
1502 RETRIEVE_ACKNOWLEDGE_t *retrieve_acknowledge;
1503 struct message *message;
1504 int channel, exclusive, cause;
1510 cause = 101; /* incompatible state */
1512 PDEBUG(DEBUG_ISDN, "Pdss1(%s) we are not on hold, so we reject (cazse %d).\n", p_name, cause);
1514 dmsg = create_l3msg(CC_RETRIEVE_REJECT | REQUEST, MT_RETRIEVE_REJECT, dinfo, sizeof(RETRIEVE_REJECT_t), p_m_d_ntmode);
1515 isdn_show_send_message(CC_RETRIEVE_REJECT | REQUEST, dmsg);
1516 retrieve_reject = (RETRIEVE_REJECT_t *)(dmsg->data + headerlen);
1517 enc_ie_cause(&retrieve_reject->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, cause);
1518 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1523 /* notify the retrieve of call */
1524 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1525 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_RETRIEVAL;
1526 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1527 message_put(message);
1530 dec_ie_channel_id(retrieve->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
1534 channel = -1; /* any channel */
1535 if (channel == ANY_CHANNEL)
1536 channel = -1; /* any channel */
1539 PDEBUG(DEBUG_BCHANNEL, "- any channel is selected the %s, so we need to return the selected channel\n", (p_m_d_ntmode)?"user":"network");
1540 if (channel==0 && (p_type==PORT_TYPE_DSS1_TE_IN||p_type==PORT_TYPE_DSS1_TE_OUT))
1541 PDEBUG(DEBUG_BCHANNEL, "- no channel is given by the network, causing to fail, since CW is not possible for external lines\n");
1544 PDEBUG(DEBUG_BCHANNEL, "- exclusive channel(%d) is selected.\n", channel);
1546 PDEBUG(DEBUG_BCHANNEL, "- channel(%d) given, but we select a different channel if not available.\n", channel);
1548 ret = alloc_bchannel(channel, exclusive);
1551 PDEBUG(DEBUG_BCHANNEL, "- channel is not available (cause=%d), so we send a retrieve_reject.\n", -ret);
1556 /* set hold state */
1560 /* acknowledge retrieve */
1561 dmsg = create_l3msg(CC_RETRIEVE_ACKNOWLEDGE | REQUEST, MT_RETRIEVE_ACKNOWLEDGE, dinfo, sizeof(RETRIEVE_ACKNOWLEDGE_t), p_m_d_ntmode);
1562 isdn_show_send_message(CC_RETRIEVE_ACKNOWLEDGE | REQUEST, dmsg);
1563 retrieve_acknowledge = (RETRIEVE_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1564 /* channel information */
1565 enc_ie_channel_id(&retrieve_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
1566 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1569 /* CC_SUSPEND INDICATION */
1570 void Pdss1::suspend_ind(unsigned long prim, unsigned long dinfo, void *data)
1572 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1573 SUSPEND_t *suspend = (SUSPEND_t *)((unsigned long)data + headerlen);
1574 SUSPEND_ACKNOWLEDGE_t *suspend_acknowledge;
1575 SUSPEND_REJECT_t *suspend_reject;
1576 struct message *message;
1577 class Endpoint *epoint;
1578 unsigned char callid[8];
1581 int ret = -31; /* normal, unspecified */
1583 if (!ACTIVE_EPOINT(p_epointlist))
1585 PDEBUG(DEBUG_ISDN, "Pdss1(%s) there is no endpoint to notify suspend, so we reject.\n", p_name);
1588 dmsg = create_l3msg(CC_SUSPEND_REJECT | REQUEST, MT_SUSPEND_REJECT, dinfo, sizeof(SUSPEND_REJECT_t), p_m_d_ntmode);
1589 isdn_show_send_message(CC_SUSPEND_REJECT | REQUEST, dmsg);
1590 suspend_reject = (SUSPEND_REJECT_t *)(dmsg->data + headerlen);
1591 enc_ie_cause(&suspend_reject->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1592 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1598 dec_ie_call_id(suspend->CALL_ID, (Q931_info_t *)((unsigned long)data+headerlen), callid, &len);
1601 /* check if call id is in use */
1602 epoint = epoint_first;
1605 if (epoint->ep_park)
1607 if (epoint->ep_park_len == len)
1608 if (!memcmp(epoint->ep_park_callid, callid, len))
1610 PDEBUG(DEBUG_ISDN, "Pdss1(%s) call id is in use, so we reject.\n", p_name);
1611 ret = -84; /* call id in use */
1615 epoint = epoint->next;
1618 /* notify the hold of call */
1619 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1620 message->param.notifyinfo.notify = INFO_NOTIFY_USER_SUSPENDED;
1621 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1622 message_put(message);
1624 /* deactivate bchannel */
1627 /* sending suspend to endpoint */
1628 while (p_epointlist)
1630 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_SUSPEND);
1631 memcpy(message->param.parkinfo.callid, callid, sizeof(message->param.parkinfo.callid));
1632 message->param.parkinfo.len = len;
1633 message_put(message);
1635 free_epointlist(p_epointlist);
1638 /* sending SUSPEND_ACKNOWLEDGE */
1639 dmsg = create_l3msg(CC_SUSPEND_ACKNOWLEDGE | REQUEST, MT_SUSPEND_ACKNOWLEDGE, dinfo, sizeof(SUSPEND_ACKNOWLEDGE_t), p_m_d_ntmode);
1640 isdn_show_send_message(CC_SUSPEND_ACKNOWLEDGE | REQUEST, dmsg);
1641 suspend_acknowledge = (SUSPEND_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1642 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1644 new_state(PORT_STATE_RELEASE);
1648 /* CC_RESUME INDICATION */
1649 void Pdss1::resume_ind(unsigned long prim, unsigned long dinfo, void *data)
1651 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1652 RESUME_t *resume = (RESUME_t *)((unsigned long)data + headerlen);
1653 RESUME_REJECT_t *resume_reject;
1654 RESUME_ACKNOWLEDGE_t *resume_acknowledge;
1655 unsigned char callid[8];
1657 int channel, exclusive;
1659 class Endpoint *epoint;
1660 struct message *message;
1663 /* if blocked, release call */
1664 if (p_m_mISDNport->ifport->block)
1666 RELEASE_COMPLETE_t *release_complete;
1668 printlog("--- port#%d is blocked.\n", mISDNport->ifport->portnum);
1674 dec_ie_call_id(resume->CALL_ID, (Q931_info_t *)((unsigned long)data+headerlen), callid, &len);
1679 channel = -1; /* any channel */
1680 PDEBUG(DEBUG_BCHANNEL, "- any channel is selected the %s, so we need to return the selected channel\n", (p_m_d_ntmode)?"user":"network");
1682 ret = alloc_bchannel(channel, exclusive);
1685 PDEBUG(DEBUG_BCHANNEL, "- channel is not available (cause=%d), so we send a RESUME_REJECT.\n", -ret);
1688 dmsg = create_l3msg(CC_RESUME_REJECT | REQUEST, MT_RESUME_REJECT, dinfo, sizeof(RESUME_REJECT_t), p_m_d_ntmode);
1689 isdn_show_send_message(CC_RESUME_REJECT | REQUEST, dmsg);
1690 resume_reject = (RESUME_REJECT_t *)(dmsg->data + headerlen);
1691 enc_ie_cause(&resume_reject->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1692 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1693 new_state(PORT_STATE_RELEASE);
1697 PDEBUG(DEBUG_BCHANNEL, "- channel is available, we selected channel %d.\n", ret);
1698 /* create endpoint */
1701 PERROR("SOFTWARE ERROR: incoming resume but already got an endpoint, exitting...\n");
1704 ret = -85; /* no call suspended */
1705 epoint = epoint_first;
1708 if (epoint->ep_park)
1710 ret = -83; /* suspended call exists, but this not */
1711 if (epoint->ep_park_len == len)
1712 if (!memcmp(epoint->ep_park_callid, callid, len))
1715 epoint = epoint->next;
1719 PDEBUG(DEBUG_ISDN, "Pdss1(%s) no suspended call, so we reject with cause %d.\n", p_name, ret);
1723 if (!(epointlist_new(epoint->ep_serial)))
1725 PERROR("no memory for epointlist\n");
1728 if (!(epoint->portlist_new(p_serial, p_type, p_m_mISDNport->is_earlyb)))
1730 PERROR("no memory for portlist\n");
1735 /* nt-library now gives us the id via CC_RESUME */
1736 if (dinfo&(~0xff) == 0xff00)
1738 PERROR("fatal software error: l3-stack gives us a process id 0xff00-0xffff\n");
1741 printisdn(" l3id 0x%x changes to 0x%x\n", p_m_d_l3id, dinfo);
1742 if (p_m_d_l3id&(~0xff) == 0xff00)
1743 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
1745 p_m_d_ces = resume->ces;
1746 PDEBUG(DEBUG_ISDN, "Pdss1(%s: nt-mode gives us new l3id via resume ind: 0x%x\n", p_name, p_m_d_l3id);
1749 PDEBUG(DEBUG_ISDN, "Pdss1(%s) resume\n", p_name);
1750 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RESUME);
1751 message_put(message);
1753 /* notify the resume of call */
1754 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1755 message->param.notifyinfo.notify = INFO_NOTIFY_USER_RESUMED;
1756 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1757 message_put(message);
1759 /* sending RESUME_ACKNOWLEDGE */
1760 dmsg = create_l3msg(CC_RESUME_ACKNOWLEDGE | REQUEST, MT_RESUME_ACKNOWLEDGE, dinfo, sizeof(RESUME_ACKNOWLEDGE_t), p_m_d_ntmode);
1761 isdn_show_send_message(CC_RESUME_ACKNOWLEDGE | REQUEST, dmsg);
1762 resume_acknowledge = (RESUME_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1763 /* channel information */
1764 enc_ie_channel_id(&resume_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
1765 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1767 new_state(PORT_STATE_CONNECT);
1771 /* CC_FACILITY INDICATION */
1772 void Pdss1::facility_ind(unsigned long prim, unsigned long dinfo, void *data)
1774 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1775 FACILITY_t *facility = (FACILITY_t *)((unsigned long)data + headerlen);
1776 unsigned char facil[256];
1778 struct message *message;
1781 dec_ie_facility(facility->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), facil, &facil_len);
1785 PDEBUG(DEBUG_ISDN, "Pdss1(%s) facility\n", p_name);
1786 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_FACILITY);
1787 message->param.facilityinfo.len = facil_len;
1788 memcpy(message->param.facilityinfo.data, facil, facil_len);
1789 message_put(message);
1794 * handler for isdn connections
1795 * incoming information are parsed and sent via message to the endpoint
1797 void Pdss1::message_isdn(unsigned long prim, unsigned long dinfo, void *data)
1799 char *msgtext = "<<UNKNOWN MESSAGE>>";
1805 while(isdn_message[i].name)
1807 if (isdn_message[i].value == (prim&0xffffff00))
1809 msgtext = isdn_message[i].name;
1814 primtext = isdn_prim[prim&0x00000003];
1815 printisdn("<<< incoming prim: %s %s (0x%x)\n", msgtext, primtext, prim);
1818 case CC_TIMEOUT | INDICATION:
1821 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1822 int t = *((int *)(((char *)data)+headerlen));
1823 PDEBUG(DEBUG_ISDN, "Pdss1(%s) timeout (t%x in NT-mode)\n", p_name, t);
1825 t312_timeout(prim, dinfo, data);
1827 PDEBUG(DEBUG_ISDN, "Pdss1(%s) timeout (ignoring)\n", p_name);
1831 case CC_SETUP | INDICATION:
1832 PDEBUG((DEBUG_BCHANNEL|DEBUG_ISDN), "Pdss1(%s) setup\n", p_name);
1833 if (p_state != PORT_STATE_IDLE)
1835 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received setup again, IGNORING.\n", p_name);
1838 setup_ind(prim, dinfo, data);
1841 case CC_SETUP | CONFIRM:
1844 /* nt-library now gives us a new id via CC_SETUP_CONFIRM */
1845 if ((p_m_d_l3id&0xff00) == 0xff00)
1847 // p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
1848 // printisdn(" procid 0x%x freed\n", p_m_d_l3id&0xff);
1849 printisdn(" procid 0x%x still in use\n", p_m_d_l3id&0xff);
1852 printisdn(" strange setup-procid 0x%x\n", p_m_d_l3id);
1854 p_m_d_l3id = *((int *)(((u_char *)data)+ mISDNUSER_HEAD_SIZE));
1855 printisdn(" l3id changes to 0x%x\n", p_m_d_l3id);
1857 PDEBUG(DEBUG_ISDN, "Pdss1(%s) setup confirm (l3id=0x%x)\n", p_name, p_m_d_l3id);
1860 case CC_INFORMATION | INDICATION:
1861 PDEBUG(DEBUG_ISDN, "Pdss1(%s) information\n", p_name);
1862 information_ind(prim, dinfo, data);
1865 case CC_SETUP_ACKNOWLEDGE | INDICATION:
1866 PDEBUG(DEBUG_ISDN, "Pdss1(%s) setup acknowledge\n", p_name);
1867 if (p_state != PORT_STATE_OUT_SETUP)
1869 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received setup_acknowledge, but we are not in outgoing setup state, IGNORING.\n", p_name);
1872 setup_acknowledge_ind(prim, dinfo, data);
1875 case CC_PROCEEDING | INDICATION:
1876 PDEBUG(DEBUG_ISDN, "Pdss1(%s) proceeding\n", p_name);
1877 if (p_state != PORT_STATE_OUT_SETUP
1878 && p_state != PORT_STATE_OUT_OVERLAP)
1880 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received proceeding, but we are not in outgoing setup OR overlap state, IGNORING.\n", p_name);
1883 proceeding_ind(prim, dinfo, data);
1886 case CC_ALERTING | INDICATION:
1887 PDEBUG(DEBUG_ISDN, "Pdss1(%s) alerting\n", p_name);
1888 if (p_state != PORT_STATE_OUT_SETUP
1889 && p_state != PORT_STATE_OUT_OVERLAP
1890 && p_state != PORT_STATE_OUT_PROCEEDING)
1892 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding state, IGNORING.\n", p_name);
1895 alerting_ind(prim, dinfo, data);
1898 case CC_CONNECT | INDICATION:
1899 PDEBUG(DEBUG_ISDN, "Pdss1(%s) connect\n", p_name);
1900 if (p_state != PORT_STATE_OUT_SETUP
1901 && p_state != PORT_STATE_OUT_OVERLAP
1902 && p_state != PORT_STATE_OUT_PROCEEDING
1903 && p_state != PORT_STATE_OUT_ALERTING)
1905 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding OR ALERTING state, IGNORING.\n", p_name);
1908 connect_ind(prim, dinfo, data);
1909 if (p_m_d_notify_pending)
1911 PDEBUG(DEBUG_ISDN, "received or connect, so we send pending notify message.\n");
1912 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
1913 message_free(p_m_d_notify_pending);
1914 p_m_d_notify_pending = NULL;
1918 case CC_CONNECT_ACKNOWLEDGE | INDICATION:
1919 case CC_CONNECT | CONFIRM:
1920 PDEBUG(DEBUG_ISDN, "Pdss1(%s) connect_acknowlege.\n", p_name);
1921 if (p_state == PORT_STATE_CONNECT_WAITING)
1922 new_state(PORT_STATE_CONNECT);
1923 if (p_m_d_notify_pending)
1925 PDEBUG(DEBUG_ISDN, "received or connect-ack, so we send pending notify message.\n");
1926 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
1927 message_free(p_m_d_notify_pending);
1928 p_m_d_notify_pending = NULL;
1932 case CC_DISCONNECT | INDICATION:
1933 PDEBUG(DEBUG_ISDN, "Pdss1(%s) disconnect\n", p_name);
1934 disconnect_ind(prim, dinfo, data);
1937 case CC_RELEASE | CONFIRM:
1938 PDEBUG(DEBUG_ISDN, "Pdss1(%s) release confirm\n", p_name);
1939 case CC_RELEASE | INDICATION:
1940 PDEBUG(DEBUG_ISDN, "Pdss1(%s) release\n", p_name);
1941 release_ind(prim, dinfo, data);
1944 case CC_RELEASE_COMPLETE | INDICATION:
1945 PDEBUG(DEBUG_ISDN, "Pdss1(%s) release_complete.\n", p_name);
1946 release_complete_ind(prim, dinfo, data);
1949 case CC_RELEASE_COMPLETE | CONFIRM:
1950 PDEBUG(DEBUG_ISDN, "Pdss1(%s) release_complete (confirm).\n", p_name);
1953 case CC_NOTIFY | INDICATION:
1954 PDEBUG(DEBUG_ISDN, "Pdss1(%s) notify\n", p_name);
1955 notify_ind(prim, dinfo, data);
1958 case CC_HOLD | INDICATION:
1959 PDEBUG(DEBUG_ISDN, "Pdss1(%s) hold\n", p_name);
1960 hold_ind(prim, dinfo, data);
1963 case CC_RETRIEVE | INDICATION:
1964 PDEBUG(DEBUG_ISDN, "Pdss1(%s) retrieve\n", p_name);
1965 retrieve_ind(prim, dinfo, data);
1968 case CC_SUSPEND | INDICATION:
1969 PDEBUG(DEBUG_ISDN, "Pdss1(%s) suspend\n", p_name);
1970 suspend_ind(prim, dinfo, data);
1973 case CC_RESUME | INDICATION:
1974 PDEBUG(DEBUG_ISDN, "Pdss1(%s) resume\n", p_name);
1975 resume_ind(prim, dinfo, data);
1978 case CC_FACILITY | INDICATION:
1979 PDEBUG(DEBUG_ISDN, "Pdss1(%s) facility\n", p_name);
1980 facility_ind(prim, dinfo, data);
1983 case CC_RELEASE_CR | INDICATION:
1984 PDEBUG(DEBUG_ISDN, "Pdss1(%s) call ref is released (l3id=0x%x)\n", p_name, p_m_d_l3id);
1985 printisdn(" process 0x%x released\n", p_m_d_l3id);
1988 if ((p_m_d_l3id&0xff00) == 0xff00)
1990 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
1991 printisdn(" procid 0x%x freed\n", p_m_d_l3id&0xff);
1996 /* sending release to endpoint in case we still have an endpoint
1997 * NOTE: this only happens if the stack releases due to layer1
1998 * or layer2 breakdown. otherwhise a release is received first.
2002 struct message *message;
2003 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
2004 message->param.disconnectinfo.cause = (p_m_d_collect_cause!=CAUSE_NOUSER)?p_m_d_collect_cause:CAUSE_UNSPECIFIED;
2005 message->param.disconnectinfo.location = (p_m_d_collect_cause!=CAUSE_NOUSER)?p_m_d_collect_location:LOCATION_PRIVATE_LOCAL;
2006 message_put(message);
2008 free_epointlist(p_epointlist);
2010 PDEBUG(DEBUG_ISDN, "Pdss1(%s) release due to breakdown of l3-process.\n", p_name);
2011 new_state(PORT_STATE_RELEASE);
2015 case CC_NEW_CR | INDICATION:
2018 new_l3id = *((int *)(((u_char *)data+mISDNUSER_HEAD_SIZE)));
2019 printisdn(" process 0x%x received\n", new_l3id);
2020 if (((new_l3id&0xff00)!=0xff00) && ((p_m_d_l3id&0xff00)==0xff00))
2022 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
2023 printisdn(" procid 0x%x freed\n", p_m_d_l3id&0xff);
2028 printisdn(" process 0x%x received\n", new_l3id);
2030 p_m_d_l3id = new_l3id;
2031 PDEBUG(DEBUG_ISDN, "Pdss1(%s) call ref is created (l3id=0x%x)\n", p_name, p_m_d_l3id);
2035 PDEBUG(DEBUG_ISDN, "Pdss1(%s) unhandled prim: 0x%x\n", p_name, prim);
2039 void Pdss1::new_state(int state)
2041 class Endpoint *epoint;
2044 epoint = find_epoint_id(ACTIVE_EPOINT(p_epointlist));
2045 if (epoint && p_m_d_ntmode)
2047 if (state == PORT_STATE_IN_OVERLAP)
2049 p_m_timeout = p_settings.tout_dialing;
2052 if (state != p_state)
2055 if (state == PORT_STATE_OUT_SETUP
2056 || state == PORT_STATE_OUT_OVERLAP)
2062 if (state == PORT_STATE_IN_SETUP
2063 || state == PORT_STATE_IN_OVERLAP)
2065 p_m_timeout = p_settings.tout_setup;
2068 if (state == PORT_STATE_IN_PROCEEDING
2069 || state == PORT_STATE_OUT_PROCEEDING)
2071 p_m_timeout = p_settings.tout_proceeding;
2074 if (state == PORT_STATE_IN_ALERTING
2075 || state == PORT_STATE_OUT_ALERTING)
2077 p_m_timeout = p_settings.tout_alerting;
2080 if (state == PORT_STATE_CONNECT
2081 || state == PORT_STATE_CONNECT_WAITING)
2085 if (state == PORT_STATE_IN_DISCONNECT
2086 || state == PORT_STATE_OUT_DISCONNECT)
2088 p_m_timeout = p_settings.tout_disconnect;
2094 Port::new_state(state);
2101 int Pdss1::handler(void)
2105 if ((ret = Port::handler()))
2108 /* handle destruction */
2109 if (p_m_delete && p_m_d_l3id==0)
2111 PDEBUG(DEBUG_ISDN, "Pdss1(%s) doing pending release.\n", p_name);
2121 * handles all messages from endpoint
2123 /* MESSAGE_INFORMATION */
2124 void Pdss1::message_information(unsigned long epoint_id, int message_id, union parameter *param)
2126 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2127 INFORMATION_t *information;
2130 if (param->information.number[0]) /* only if we have something to dial */
2132 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2133 isdn_show_send_message(CC_INFORMATION | REQUEST, dmsg);
2134 information = (INFORMATION_t *)(dmsg->data + headerlen);
2135 enc_ie_called_pn(&information->CALLED_PN, dmsg, 0, 1, (unsigned char *)param->information.number);
2136 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2145 void Pdss1::message_setup(unsigned long epoint_id, int message_id, union parameter *param)
2147 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2148 INFORMATION_t *information;
2151 int plan, type, screen, present, reason;
2152 int capability, mode, rate, coding, user, presentation, interpretation, hlc, exthlc;
2153 int channel, exclusive;
2155 struct epoint_list *epointlist;
2157 /* release if port is blocked */
2158 if (p_m_mISDNport->ifport->block)
2160 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2161 message->param.disconnectinfo.cause = 27; // temp. unavail.
2162 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2163 message_put(message);
2164 new_state(PORT_STATE_RELEASE);
2169 /* copy setup infos to port */
2170 memcpy(&p_callerinfo, ¶m->setup.callerinfo, sizeof(p_callerinfo));
2171 memcpy(&p_dialinginfo, ¶m->setup.dialinginfo, sizeof(p_dialinginfo));
2172 memcpy(&p_capainfo, ¶m->setup.capainfo, sizeof(p_capainfo));
2173 memcpy(&p_redirinfo, ¶m->setup.redirinfo, sizeof(p_redirinfo));
2174 // SCPY(&p_m_tones_dir, param->setup.ext.tones_dir);
2176 /* only display at connect state: this case happens if endpoint is in connected mode */
2177 if (p_state==PORT_STATE_CONNECT)
2179 if (p_type!=PORT_TYPE_DSS1_NT_OUT
2180 && p_type!=PORT_TYPE_DSS1_NT_IN)
2182 if (p_callerinfo.display[0])
2184 /* sending information */
2185 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2186 isdn_show_send_message(CC_INFORMATION | REQUEST, dmsg);
2187 information = (INFORMATION_t *)(dmsg->data + headerlen);
2189 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_callerinfo.display);
2190 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2195 /* attach only if not already */
2196 epointlist = p_epointlist;
2199 if (epointlist->epoint_id == epoint_id)
2201 epointlist = epointlist->next;
2205 if (!(epointlist_new(epoint_id)))
2207 PERROR("no memory for epointlist\n");
2216 channel = p_m_b_channel;
2217 exclusive = p_m_b_exclusive;
2219 channel = CHANNEL_ANY;
2220 /* nt-port with no channel, not reserverd */
2221 if (!p_m_b_channel && !p_m_b_reserve && p_type==PORT_TYPE_DSS1_NT_OUT)
2222 channel = CHANNEL_NO;
2230 if (p_m_mISDNport->procids[i] == 0)
2236 struct message *message;
2238 printisdn(" no free process id\n");
2239 PDEBUG(DEBUG_ISDN, "no more free process ID for port.\n");
2240 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2241 message->param.disconnectinfo.cause = 47;
2242 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2243 message_put(message);
2244 new_state(PORT_STATE_RELEASE);
2248 p_m_mISDNport->procids[i] = 1;
2249 printisdn(" procid 0x%x allocated\n", i);
2250 p_m_d_l3id = 0xff00 | i;
2251 printisdn(" l3id is now 0x%x\n", p_m_d_l3id);
2255 /* if we are in te-mode, we need to create a process first */
2256 if (newteid++ > 0x7fff)
2258 p_m_d_l3id = (entity<<16) | newteid;
2259 /* preparing message */
2260 ncr.prim = CC_NEW_CR | REQUEST;
2261 ncr.addr = p_m_mISDNport->upper_id | FLG_MSG_DOWN;
2262 ncr.dinfo = p_m_d_l3id;
2264 isdn_show_send_message(CC_NEW_CR | REQUEST, NULL);
2266 mISDN_write(mISDNdevice, &ncr, mISDN_HEADER_LEN+ncr.len, TIMEOUT_1SEC);
2271 /* preparing setup message */
2272 dmsg = create_l3msg(CC_SETUP | REQUEST, MT_SETUP, p_m_d_l3id, sizeof(SETUP_t), p_m_d_ntmode);
2273 isdn_show_send_message(CC_SETUP | REQUEST, dmsg);
2274 setup = (SETUP_t *)(dmsg->data + headerlen);
2275 /* channel information */
2276 if (channel >= 0) /* it should */
2278 enc_ie_channel_id(&setup->CHANNEL_ID, dmsg, exclusive, channel);
2280 /* caller information */
2282 switch (p_callerinfo.ntype)
2284 case INFO_NTYPE_INTERNATIONAL:
2287 case INFO_NTYPE_NATIONAL:
2290 case INFO_NTYPE_SUBSCRIBER:
2293 default: /* INFO_NTYPE_UNKNOWN */
2297 switch (p_callerinfo.screen)
2299 case INFO_SCREEN_USER:
2302 default: /* INFO_SCREEN_NETWORK */
2306 switch (p_callerinfo.present)
2308 case INFO_PRESENT_RESTRICTED:
2311 case INFO_PRESENT_NOTAVAIL:
2314 default: /* INFO_PRESENT_ALLOWED */
2319 enc_ie_calling_pn(&setup->CALLING_PN, dmsg, type, plan, present, screen, (unsigned char *)p_callerinfo.id);
2320 /* dialing information */
2321 if (p_dialinginfo.number[0]) /* only if we have something to dial */
2323 enc_ie_called_pn(&setup->CALLED_PN, dmsg, 0, 1, (unsigned char *)p_dialinginfo.number);
2325 /* sending complete */
2326 if (p_dialinginfo.sending_complete)
2327 enc_ie_complete(&setup->COMPLETE, dmsg, 1);
2328 /* sending user-user */
2329 if (param->setup.useruser.len)
2331 enc_ie_useruser(&setup->USER_USER, dmsg, param->setup.useruser.protocol, param->setup.useruser.data, param->setup.useruser.len);
2333 /* redirecting number */
2335 switch (p_redirinfo.ntype)
2337 case INFO_NTYPE_INTERNATIONAL:
2340 case INFO_NTYPE_NATIONAL:
2343 case INFO_NTYPE_SUBSCRIBER:
2346 default: /* INFO_NTYPE_UNKNOWN */
2350 switch (p_redirinfo.screen)
2352 case INFO_SCREEN_USER:
2355 default: /* INFO_SCREE_NETWORK */
2359 switch (p_redirinfo.reason)
2361 case INFO_REDIR_BUSY:
2364 case INFO_REDIR_NORESPONSE:
2367 case INFO_REDIR_UNCONDITIONAL:
2370 case INFO_REDIR_CALLDEFLECT:
2373 case INFO_REDIR_OUTOFORDER:
2376 default: /* INFO_REDIR_UNKNOWN */
2380 switch (p_redirinfo.present)
2382 case INFO_PRESENT_NULL: /* no redir at all */
2389 case INFO_PRESENT_RESTRICTED:
2392 case INFO_PRESENT_NOTAVAIL:
2395 default: /* INFO_PRESENT_ALLOWED */
2399 /* sending redirecting number only in ntmode */
2400 if (type >= 0 && p_m_d_ntmode)
2401 enc_ie_redir_nr(&setup->REDIR_NR, dmsg, type, plan, present, screen, reason, (unsigned char *)p_redirinfo.id);
2402 /* bearer capability */
2403 //printf("hlc=%d\n",p_capainfo.hlc);
2405 capability = p_capainfo.bearer_capa;
2406 mode = p_capainfo.bearer_mode;
2407 rate = (mode==INFO_BMODE_CIRCUIT)?0x10:0x00;
2408 switch (p_capainfo.bearer_info1)
2410 case INFO_INFO1_NONE:
2414 user = p_capainfo.bearer_info1 & 0x7f;
2417 enc_ie_bearer(&setup->BEARER, dmsg, coding, capability, mode, rate, -1, user);
2424 hlc = p_capainfo.hlc & 0x7f;
2426 if (p_capainfo.exthlc)
2427 exthlc = p_capainfo.exthlc & 0x7f;
2428 enc_ie_hlc(&setup->HLC, dmsg, coding, interpretation, presentation, hlc, exthlc);
2432 if (p_callerinfo.display[0] && p_m_d_ntmode)
2433 enc_ie_display(&setup->DISPLAY, dmsg, (unsigned char *)p_callerinfo.display);
2435 /* nt-mode: CNIP (calling name identification presentation) */
2436 if (p_callerinfo.name[0] && p_m_d_ntmode)
2437 enc_facility_centrex(&setup->FACILITY, dmsg, (unsigned char *)p_callerinfo.name, 1);
2440 /* send setup message now */
2441 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2443 new_state(PORT_STATE_OUT_SETUP);
2446 /* MESSAGE_FACILITY */
2447 void Pdss1::message_facility(unsigned long epoint_id, int message_id, union parameter *param)
2449 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2450 FACILITY_t *facility;
2453 /* facility will not be sent to external lines */
2457 PDEBUG(DEBUG_ISDN, "Pdss1(%s) sending facility message\n", p_name);
2459 /* sending facility */
2460 dmsg = create_l3msg(CC_FACILITY | REQUEST, MT_FACILITY, p_m_d_l3id, sizeof(FACILITY_t), p_m_d_ntmode);
2461 isdn_show_send_message(CC_FACILITY | REQUEST, dmsg);
2462 facility = (FACILITY_t *)(dmsg->data + headerlen);
2463 enc_ie_facility(&facility->FACILITY, dmsg, (unsigned char *)param->facilityinfo.data, param->facilityinfo.len);
2464 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2467 /* MESSAGE_NOTIFY */
2468 void Pdss1::message_notify(unsigned long epoint_id, int message_id, union parameter *param)
2470 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2471 INFORMATION_t *information;
2472 NOTIFY_t *notification;
2474 int plan, type = -1, present;
2477 PDEBUG(DEBUG_ISDN, "Pdss1(%s) sending information message\n", p_name);
2478 if (param->notifyinfo.notify>INFO_NOTIFY_NONE)
2479 notify = param->notifyinfo.notify & 0x7f;
2482 if (p_state != PORT_STATE_CONNECT)
2484 /* notify only allowed in active state */
2490 switch (param->notifyinfo.ntype)
2492 case INFO_NTYPE_INTERNATIONAL:
2495 case INFO_NTYPE_NATIONAL:
2498 case INFO_NTYPE_SUBSCRIBER:
2501 default: /* INFO_NTYPE_UNKNOWN */
2505 switch (param->notifyinfo.present)
2507 case INFO_PRESENT_NULL: /* no redir at all */
2512 case INFO_PRESENT_RESTRICTED:
2515 case INFO_PRESENT_NOTAVAIL:
2518 default: /* INFO_PRESENT_ALLOWED */
2524 if (notify<0 && !param->notifyinfo.display[0])
2526 PDEBUG(DEBUG_ISDN, "Pdss1(%s) nothing to notify, nothing to display\n", p_name);
2532 if (p_state!=PORT_STATE_CONNECT)
2534 /* queue notification */
2535 PDEBUG(DEBUG_ISDN, "Pdss1(%s) queueing notification because isdn port is not active state.\n", p_name);
2536 if (p_m_d_notify_pending)
2537 message_free(p_m_d_notify_pending);
2538 p_m_d_notify_pending = message_create(ACTIVE_EPOINT(p_epointlist), p_serial, EPOINT_TO_PORT, message_id);
2539 memcpy(&p_m_d_notify_pending->param, param, sizeof(union parameter));
2542 /* sending notification */
2543 dmsg = create_l3msg(CC_NOTIFY | REQUEST, MT_NOTIFY, p_m_d_l3id, sizeof(NOTIFY_t), p_m_d_ntmode);
2544 isdn_show_send_message(CC_NOTIFY | REQUEST, dmsg);
2545 notification = (NOTIFY_t *)(dmsg->data + headerlen);
2546 enc_ie_notify(¬ification->NOTIFY, dmsg, notify);
2547 /* sending redirection number only in ntmode */
2548 if (type >= 0 && p_m_d_ntmode)
2549 enc_ie_redir_dn(¬ification->REDIR_DN, dmsg, type, plan, present, (unsigned char *)param->notifyinfo.id);
2550 if (param->notifyinfo.display[0] && p_m_d_ntmode)
2551 enc_ie_display(¬ification->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display);
2552 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2554 } else if (p_m_d_ntmode)
2556 /* sending information */
2557 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2558 isdn_show_send_message(CC_INFORMATION | REQUEST, dmsg);
2559 information = (INFORMATION_t *)(dmsg->data + headerlen);
2560 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display);
2561 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2565 /* MESSAGE_OVERLAP */
2566 void Pdss1::message_overlap(unsigned long epoint_id, int message_id, union parameter *param)
2568 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2569 SETUP_ACKNOWLEDGE_t *setup_acknowledge;
2572 /* sending setup_acknowledge */
2573 dmsg = create_l3msg(CC_SETUP_ACKNOWLEDGE | REQUEST, MT_SETUP_ACKNOWLEDGE, p_m_d_l3id, sizeof(SETUP_ACKNOWLEDGE_t), p_m_d_ntmode);
2574 isdn_show_send_message(CC_SETUP_ACKNOWLEDGE | REQUEST, dmsg);
2575 setup_acknowledge = (SETUP_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
2576 /* channel information */
2577 if (p_state == PORT_STATE_IN_SETUP)
2578 enc_ie_channel_id(&setup_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2579 /* progress information */
2580 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2581 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2582 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2583 if (p_m_mISDNport->is_tones)
2584 enc_ie_progress(&setup_acknowledge->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2585 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2587 new_state(PORT_STATE_IN_OVERLAP);
2590 /* MESSAGE_PROCEEDING */
2591 void Pdss1::message_proceeding(unsigned long epoint_id, int message_id, union parameter *param)
2593 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2594 CALL_PROCEEDING_t *proceeding;
2597 /* sending proceeding */
2598 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2599 isdn_show_send_message(CC_PROCEEDING | REQUEST, dmsg);
2600 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2601 /* channel information */
2602 if (p_state == PORT_STATE_IN_SETUP)
2603 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2604 /* progress information */
2605 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2606 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2607 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2608 if (p_m_mISDNport->is_tones)
2609 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2610 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2612 new_state(PORT_STATE_IN_PROCEEDING);
2615 /* MESSAGE_ALERTING */
2616 void Pdss1::message_alerting(unsigned long epoint_id, int message_id, union parameter *param)
2618 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2619 ALERTING_t *alerting;
2622 /* NT-MODE in setup state we must send PROCEEDING first */
2623 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2625 CALL_PROCEEDING_t *proceeding;
2627 /* sending proceeding */
2628 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2629 isdn_show_send_message(CC_PROCEEDING | REQUEST, dmsg);
2630 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2631 /* channel information */
2632 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2633 /* progress information */
2634 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2635 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2636 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2637 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2638 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2639 new_state(PORT_STATE_IN_PROCEEDING);
2642 /* sending alerting */
2643 dmsg = create_l3msg(CC_ALERTING | REQUEST, MT_ALERTING, p_m_d_l3id, sizeof(ALERTING_t), p_m_d_ntmode);
2644 isdn_show_send_message(CC_ALERTING | REQUEST, dmsg);
2645 alerting = (ALERTING_t *)(dmsg->data + headerlen);
2646 /* channel information */
2647 if (p_state == PORT_STATE_IN_SETUP)
2648 enc_ie_channel_id(&alerting->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2649 /* progress information */
2650 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2651 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2652 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2653 if (p_m_mISDNport->is_tones)
2654 enc_ie_progress(&alerting->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2655 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2657 new_state(PORT_STATE_IN_ALERTING);
2660 /* MESSAGE_CONNECT */
2661 void Pdss1::message_connect(unsigned long epoint_id, int message_id, union parameter *param)
2663 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2664 INFORMATION_t *information;
2666 int type, plan, present, screen;
2668 class Endpoint *epoint;
2670 /* NT-MODE in setup state we must send PROCEEDING first */
2671 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2673 CALL_PROCEEDING_t *proceeding;
2675 /* sending proceeding */
2676 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2677 isdn_show_send_message(CC_PROCEEDING | REQUEST, dmsg);
2678 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2679 /* channel information */
2680 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2681 // /* progress information */
2682 // if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2683 // || p_capainfo.bearer_capa==INFO_BC_AUDIO
2684 // || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2685 // enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2686 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2687 new_state(PORT_STATE_IN_PROCEEDING);
2690 /* copy connected information */
2691 memcpy(&p_connectinfo, ¶m->connectinfo, sizeof(p_connectinfo));
2693 /* only display at connect state */
2694 if (p_state == PORT_STATE_CONNECT)
2695 if (p_connectinfo.display[0])
2697 /* sending information */
2698 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2699 isdn_show_send_message(CC_INFORMATION | REQUEST, dmsg);
2700 information = (INFORMATION_t *)(dmsg->data + headerlen);
2702 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_connectinfo.display);
2703 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2707 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)
2709 PDEBUG(DEBUG_ISDN, "Pdss1(%s) connect command only possible in setup, proceeding or alerting state.\n", p_name);
2713 /* preparing connect message */
2714 dmsg = create_l3msg(CC_CONNECT | REQUEST, MT_CONNECT, p_m_d_l3id, sizeof(CONNECT_t), p_m_d_ntmode);
2715 isdn_show_send_message(CC_CONNECT | REQUEST, dmsg);
2716 connect = (CONNECT_t *)(dmsg->data + headerlen);
2717 /* connect information */
2719 switch (p_connectinfo.ntype)
2721 case INFO_NTYPE_INTERNATIONAL:
2724 case INFO_NTYPE_NATIONAL:
2727 case INFO_NTYPE_SUBSCRIBER:
2730 default: /* INFO_NTYPE_UNKNOWN */
2734 switch (param->connectinfo.screen)
2736 case INFO_SCREEN_USER:
2739 default: /* INFO_SCREE_NETWORK */
2743 switch (p_connectinfo.present)
2745 case INFO_PRESENT_NULL: /* no colp at all */
2751 case INFO_PRESENT_RESTRICTED:
2754 case INFO_PRESENT_NOTAVAIL:
2757 default: /* INFO_PRESENT_ALLOWED */
2762 enc_ie_connected_pn(&connect->CONNECT_PN, dmsg, type, plan, present, screen, (unsigned char *)p_connectinfo.id);
2764 if (p_connectinfo.display[0] && p_m_d_ntmode)
2765 enc_ie_display(&connect->DISPLAY, dmsg, (unsigned char *)p_connectinfo.display);
2767 /* nt-mode: CONP (connected name identification presentation) */
2768 if (p_connectinfo.name[0] && p_m_d_ntmode)
2769 enc_facility_centrex(&connect->FACILITY, dmsg, (unsigned char *)p_connectinfo.name, 0);
2774 epoint = find_epoint_id(epoint_id);
2775 enc_ie_date(&connect->DATE, dmsg, now, p_settings.no_seconds);
2777 /* finally send message */
2778 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2781 new_state(PORT_STATE_CONNECT);
2783 new_state(PORT_STATE_CONNECT_WAITING);
2787 /* MESSAGE_DISCONNECT */
2788 void Pdss1::message_disconnect(unsigned long epoint_id, int message_id, union parameter *param)
2790 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2791 DISCONNECT_t *disconnect;
2792 RELEASE_COMPLETE_t *release_complete;
2794 struct message *message;
2797 /* we reject during incoming setup when we have no tones. also if we are in outgoing setup state */
2798 if ((p_state==PORT_STATE_IN_SETUP && !p_m_mISDNport->is_tones)
2799 || p_state==PORT_STATE_OUT_SETUP)
2801 /* sending release to endpoint */
2804 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
2805 message->param.disconnectinfo.cause = 16;
2806 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2807 message_put(message);
2809 free_epointlist(p_epointlist);
2811 /* sending release */
2812 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
2813 isdn_show_send_message(CC_RELEASE_COMPLETE | REQUEST, dmsg);
2814 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
2816 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);
2817 new_state(PORT_STATE_RELEASE);
2818 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2823 /* NT-MODE in setup state we must send PROCEEDING first */
2824 if (p_state==PORT_STATE_IN_SETUP)
2826 CALL_PROCEEDING_t *proceeding;
2828 /* sending proceeding */
2829 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2830 isdn_show_send_message(CC_PROCEEDING | REQUEST, dmsg);
2831 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2832 /* channel information */
2833 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2834 /* progress information */
2835 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2836 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2837 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2838 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2839 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2840 new_state(PORT_STATE_IN_PROCEEDING);
2843 /* sending disconnect */
2844 dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode);
2845 isdn_show_send_message(CC_DISCONNECT | REQUEST, dmsg);
2846 disconnect = (DISCONNECT_t *)(dmsg->data + headerlen);
2847 /* progress information */
2848 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2849 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2850 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2851 if (p_m_mISDNport->is_tones)
2852 enc_ie_progress(&disconnect->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2854 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);
2856 if (param->disconnectinfo.display[0])
2857 p = param->disconnectinfo.display;
2858 if (p) if (*p && p_m_d_ntmode)
2859 enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p);
2860 new_state(PORT_STATE_OUT_DISCONNECT);
2861 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2864 /* MESSAGE_RELEASE */
2865 void Pdss1::message_release(unsigned long epoint_id, int message_id, union parameter *param)
2867 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2869 RELEASE_COMPLETE_t *release_complete;
2870 DISCONNECT_t *disconnect;
2872 class Endpoint *epoint;
2875 /* if we have incoming disconnected, we may release */
2876 if (p_state==PORT_STATE_IN_DISCONNECT
2877 || p_state==PORT_STATE_OUT_DISCONNECT)
2879 /* sending release */
2880 dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, p_m_d_l3id, sizeof(RELEASE_t), p_m_d_ntmode);
2881 isdn_show_send_message(CC_RELEASE | REQUEST, dmsg);
2882 release = (RELEASE_t *)(dmsg->data + headerlen);
2884 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);
2885 new_state(PORT_STATE_RELEASE);
2886 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2889 free_epointid(epoint_id);
2892 if ((p_m_d_l3id&0xff00) == 0xff00)
2894 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
2895 printisdn(" procid 0x%x freed\n", p_m_d_l3id&0xff);
2902 /* if we are on outgoing/incoming call setup, we may release complete */
2903 if (p_state==PORT_STATE_OUT_SETUP
2904 || p_state==PORT_STATE_IN_SETUP
2905 // NOTE: a bug in mISDNuser (see disconnect_req_out !!!)
2906 || p_state==PORT_STATE_OUT_PROCEEDING)
2908 /* sending release */
2909 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
2910 isdn_show_send_message(CC_RELEASE_COMPLETE | REQUEST, dmsg);
2911 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
2913 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);
2914 new_state(PORT_STATE_RELEASE);
2915 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2916 goto remove_endpoint;
2919 /* NT-MODE in setup state we must send PROCEEDING first */
2920 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2922 CALL_PROCEEDING_t *proceeding;
2924 /* sending proceeding */
2925 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2926 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2927 /* channel information */
2928 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2929 /* progress information */
2930 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2931 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2932 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2933 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2934 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2937 /* sending disconnect */
2938 dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode);
2939 isdn_show_send_message(CC_DISCONNECT | REQUEST, dmsg);
2940 disconnect = (DISCONNECT_t *)(dmsg->data + headerlen);
2941 /* progress information */
2942 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2943 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2944 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2945 if (p_m_mISDNport->is_tones)
2946 enc_ie_progress(&disconnect->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2948 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);
2950 epoint = find_epoint_id(epoint_id);
2951 if (param->disconnectinfo.display[0])
2952 p = param->disconnectinfo.display;
2953 if (p) if (*p && p_m_d_ntmode)
2954 enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p);
2956 /* sending release */
2957 dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, p_m_d_l3id, sizeof(RELEASE_t), p_m_d_ntmode);
2958 isdn_show_send_message(CC_RELEASE | REQUEST, dmsg);
2959 release = (RELEASE_t *)(dmsg->data + headerlen);
2961 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);
2963 new_state(PORT_STATE_RELEASE);
2964 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2965 free_epointid(epoint_id);
2971 * endpoint sends messages to the port
2973 int Pdss1::message_epoint(unsigned long epoint_id, int message_id, union parameter *param)
2975 struct message *message;
2977 if (PmISDN::message_epoint(epoint_id, message_id, param))
2982 case MESSAGE_INFORMATION: /* overlap dialing */
2983 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received dialing info '%s'.\n", p_name, param->information.number);
2984 if (p_type==PORT_TYPE_DSS1_NT_OUT
2985 && p_state!=PORT_STATE_OUT_OVERLAP
2986 && p_state!=PORT_STATE_CONNECT
2987 && p_state!=PORT_STATE_OUT_DISCONNECT
2988 && p_state!=PORT_STATE_IN_DISCONNECT)
2990 PDEBUG(DEBUG_ISDN, "Pdss1(%s) (internal outgoing) ignoring information, invalid state.\n", p_name);
2993 if (p_type==PORT_TYPE_DSS1_TE_OUT
2994 && p_state!=PORT_STATE_OUT_OVERLAP
2995 && p_state!=PORT_STATE_OUT_PROCEEDING
2996 && p_state!=PORT_STATE_OUT_ALERTING
2997 && p_state!=PORT_STATE_CONNECT
2998 && p_state!=PORT_STATE_OUT_DISCONNECT
2999 && p_state!=PORT_STATE_IN_DISCONNECT)
3001 if (options.deb & DEBUG_ISDN)
3002 PERROR("Pdss1(%s) (external outgoing) ignoring information, invalid state.\n", p_name);
3005 if ((p_type==PORT_TYPE_DSS1_NT_IN || p_type==PORT_TYPE_DSS1_TE_IN)
3006 && p_state!=PORT_STATE_IN_OVERLAP
3007 && p_state!=PORT_STATE_IN_PROCEEDING
3008 && p_state!=PORT_STATE_IN_ALERTING
3009 && p_state!=PORT_STATE_CONNECT
3010 && p_state!=PORT_STATE_CONNECT_WAITING
3011 && p_state!=PORT_STATE_OUT_DISCONNECT
3012 && p_state!=PORT_STATE_IN_DISCONNECT)
3014 PDEBUG(DEBUG_ISDN, "Pdss1(%s) (incoming) ignoring information, invalid state.\n", p_name);
3017 message_information(epoint_id, message_id, param);
3020 case MESSAGE_SETUP: /* dial-out command received from epoint */
3021 PDEBUG((DEBUG_ISDN | DEBUG_BCHANNEL), "Pdss1(%s) isdn port received setup from '%s' to '%s'\n", p_name, param->setup.callerinfo.id, param->setup.dialinginfo.number);
3022 if (p_state!=PORT_STATE_IDLE
3023 && p_state!=PORT_STATE_CONNECT)
3025 PERROR("Pdss1(%s) ignoring setup because isdn port is not in idle state (or connected for sending display info).\n", p_name);
3028 if (p_epointlist && p_state==PORT_STATE_IDLE)
3030 PERROR("Pdss1(%s): software error: epoint pointer is set in idle state, how bad!! exitting.\n", p_name);
3033 /* note: pri is a special case, because links must be up for pri */
3034 if (p_m_mISDNport->l1link || p_m_mISDNport->pri || !p_m_mISDNport->ntmode || p_state!=PORT_STATE_IDLE)
3036 /* LAYER 1 is up, or we may send */
3037 message_setup(epoint_id, message_id, param);
3040 /* LAYER 1 id down, so we queue */
3041 p_m_d_queue = message_create(epoint_id, p_serial, EPOINT_TO_PORT, message_id);
3042 memcpy(&p_m_d_queue->param, param, sizeof(union parameter));
3044 if (!(epointlist_new(epoint_id)))
3046 PERROR("no memory for epointlist\n");
3050 PDEBUG(DEBUG_ISDN, "the L1 is down, we try to establish the link NT portnum=%d (%s).\n", p_m_mISDNport->portnum, p_name);
3051 act.prim = PH_ACTIVATE | REQUEST;
3052 act.addr = p_m_mISDNport->upper_id | FLG_MSG_DOWN;
3055 mISDN_write(mISDNdevice, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
3056 // /* set timeout */
3057 // p_m_mISDNport->l1timeout = now+3;
3061 case MESSAGE_NOTIFY: /* display and notifications */
3062 PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received notification: display='%s' notify=%d phone=%s\n", p_name, p_callerinfo.id, param->notifyinfo.display, param->notifyinfo.notify, param->notifyinfo.id);
3063 message_notify(epoint_id, message_id, param);
3066 case MESSAGE_FACILITY: /* facility message */
3067 PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received facility.\n", p_name, p_callerinfo.id);
3068 message_facility(epoint_id, message_id, param);
3071 case MESSAGE_OVERLAP: /* more information is needed */
3072 PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received setup acknowledge\n", p_name, p_callerinfo.id);
3073 if (p_state!=PORT_STATE_IN_SETUP)
3075 PDEBUG(DEBUG_ISDN, "Pdss1(%s) ignoring setup acknowledge because isdn port is not incoming setup state.\n", p_name);
3078 message_overlap(epoint_id, message_id, param);
3081 case MESSAGE_PROCEEDING: /* call of endpoint is proceeding */
3082 PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received proceeding\n", p_name, p_callerinfo.id);
3083 if (p_state!=PORT_STATE_IN_SETUP
3084 && p_state!=PORT_STATE_IN_OVERLAP)
3086 PDEBUG(DEBUG_ISDN, "Pdss1(%s) ignoring: proceeding command not possible in current state.\n", p_name);
3089 message_proceeding(epoint_id, message_id, param);
3092 case MESSAGE_ALERTING: /* call of endpoint is ringing */
3093 PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received alerting\n", p_name, p_callerinfo.id);
3094 if (p_state!=PORT_STATE_IN_SETUP
3095 && p_state!=PORT_STATE_IN_OVERLAP
3096 && p_state!=PORT_STATE_IN_PROCEEDING)
3098 PDEBUG(DEBUG_ISDN, "Pdss1(%s) ignoring: alerting command not possible in current state.\n", p_name);
3101 message_alerting(epoint_id, message_id, param);
3104 case MESSAGE_CONNECT: /* call of endpoint is connected */
3105 PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received connect\n", p_name, p_callerinfo.id);
3106 if (p_state!=PORT_STATE_IN_SETUP
3107 && p_state!=PORT_STATE_IN_OVERLAP
3108 && p_state!=PORT_STATE_IN_PROCEEDING
3109 && p_state!=PORT_STATE_IN_ALERTING
3110 && !(p_state==PORT_STATE_CONNECT && p_m_d_ntmode))
3112 PDEBUG(DEBUG_ISDN, "Pdss1(%s) ignoring: connect command not possible in current state.\n", p_name);
3115 message_connect(epoint_id, message_id, param);
3118 case MESSAGE_DISCONNECT: /* call has been disconnected */
3119 PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received disconnect cause=%d\n", p_name, p_callerinfo.id, param->disconnectinfo.cause);
3120 if (p_state!=PORT_STATE_IN_SETUP
3121 && p_state!=PORT_STATE_IN_OVERLAP
3122 && p_state!=PORT_STATE_IN_PROCEEDING
3123 && p_state!=PORT_STATE_IN_ALERTING
3124 && p_state!=PORT_STATE_OUT_SETUP
3125 && p_state!=PORT_STATE_OUT_OVERLAP
3126 && p_state!=PORT_STATE_OUT_PROCEEDING
3127 && p_state!=PORT_STATE_OUT_ALERTING
3128 && p_state!=PORT_STATE_CONNECT
3129 && p_state!=PORT_STATE_CONNECT_WAITING)
3131 PDEBUG(DEBUG_ISDN, "Pdss1(%s) ignoring: disconnect command not possible in current state.\n", p_name);
3134 message_disconnect(epoint_id, message_id, param);
3137 case MESSAGE_RELEASE: /* release isdn port */
3138 PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received release cause=%d\n", p_name, p_callerinfo.id, param->disconnectinfo.cause);
3139 if (p_state==PORT_STATE_RELEASE)
3141 PDEBUG(DEBUG_ISDN, "Pdss1(%s) ignoring: release command not possible in RELEASE state.\n", p_name);
3144 message_release(epoint_id, message_id, param);
3148 PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received a wrong message: %d\n", p_name, p_callerinfo.id, message);
3157 * data from isdn-stack (layer-3) to pbx (port class)
3159 /* NOTE: nt mode use mISDNuser_head_t as header */
3160 int stack2manager_nt(void *dat, void *arg)
3164 manager_t *mgr = (manager_t *)dat;
3165 msg_t *msg = (msg_t *)arg;
3166 mISDNuser_head_t *hh;
3167 struct mISDNport *mISDNport;
3173 /* note: nst is the first data feld of mISDNport */
3174 mISDNport = (struct mISDNport *)mgr->nst;
3176 hh = (mISDNuser_head_t *)msg->data;
3177 PDEBUG(DEBUG_ISDN, "prim(0x%x) dinfo(0x%x) msg->len(%d)\n", hh->prim, hh->dinfo, msg->len);
3179 /* find Port object of type ISDN */
3183 if (port->p_type == PORT_TYPE_DSS1_NT_IN || port->p_type == PORT_TYPE_DSS1_NT_OUT)
3185 pdss1 = (class Pdss1 *)port;
3186 //PDEBUG(DEBUG_ISDN, "comparing dinfo = 0x%x with l3id 0x%x\n", hh->dinfo, pdss1->p_m_d_l3id);
3187 /* check out correct stack */
3188 if (pdss1->p_m_mISDNport == mISDNport)
3189 /* check out correct id */
3190 if ((hh->dinfo&0xffff0000) == (pdss1->p_m_d_l3id&0xffff0000))
3192 /* found port, the message belongs to */
3200 /* if process id is master process, but a child disconnects */
3201 if ((hh->dinfo&0x0000ff00)!=0x0000ff00 && (pdss1->p_m_d_l3id&0x0000ff00)==0x0000ff00 && hh->prim==(CC_DISCONNECT|INDICATION))
3203 /* send special indication for child disconnect */
3204 pdss1->disconnect_ind_i(hh->prim, hh->dinfo, msg->data);
3208 /* if process id and layer 3 id matches */
3209 if (hh->dinfo == pdss1->p_m_d_l3id)
3211 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
3220 case MGR_SHORTSTATUS | INDICATION:
3221 case MGR_SHORTSTATUS | CONFIRM:
3223 case SSTATUS_L2_ESTABLISHED:
3225 case SSTATUS_L2_RELEASED:
3230 case DL_ESTABLISH | INDICATION:
3231 case DL_ESTABLISH | CONFIRM:
3233 PDEBUG(DEBUG_ISDN, "establish data link (DL) NT portnum=%d TEI=%d\n", mISDNport->portnum, hh->dinfo);
3234 if (mISDNport->ptp && hh->dinfo == 0)
3236 if (mISDNport->l2establish)
3238 mISDNport->l2establish = 0;
3239 PDEBUG(DEBUG_ISDN, "the link became active before l2establish timer expiry.\n");
3241 mISDNport->l2link = 1;
3242 if (mISDNport->pri);
3243 mISDNport->l1link = 1; /* this is a hack, we also assume L1 to be active */
3247 case DL_RELEASE | INDICATION:
3248 case DL_RELEASE | CONFIRM:
3250 PDEBUG(DEBUG_ISDN, "release data link (DL) NT portnum=%d TEI=%d\n", mISDNport->portnum, hh->dinfo);
3251 if (mISDNport->ptp && hh->dinfo == 0)
3253 mISDNport->l2link = 0;
3254 time(&mISDNport->l2establish);
3255 PDEBUG(DEBUG_ISDN, "because we are ptp, we set a l2establish timer.\n");
3259 case CC_SETUP | INDICATION:
3260 /* creating port object */
3261 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3262 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0)))
3264 RELEASE_COMPLETE_t *release_complete;
3267 fprintf(stderr, "FATAL ERROR: cannot create port object.\n");
3268 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, hh->dinfo, sizeof(RELEASE_COMPLETE_t), mISDNport->ntmode);
3269 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + mISDN_HEADER_LEN);
3270 enc_ie_cause_standalone(mISDNport->ntmode?&release_complete->CAUSE:NULL, dmsg, (mISDNport->ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47);
3271 msg_queue_tail(&mISDNport->downqueue, dmsg);
3274 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
3277 case CC_RESUME | INDICATION:
3278 /* creating port object */
3279 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3280 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL)))
3282 SUSPEND_REJECT_t *suspend_reject;
3285 fprintf(stderr, "FATAL ERROR: cannot create port object.\n");
3286 dmsg = create_l3msg(CC_SUSPEND_REJECT | REQUEST, MT_SUSPEND_REJECT, hh->dinfo, sizeof(SUSPEND_REJECT_t), mISDNport->ntmode);
3287 suspend_reject = (SUSPEND_REJECT_t *)(dmsg->data + mISDN_HEADER_LEN);
3288 enc_ie_cause_standalone(mISDNport->ntmode?&suspend_reject->CAUSE:NULL, dmsg, (mISDNport->ntmode)?1:0, 47);
3289 msg_queue_tail(&mISDNport->downqueue, dmsg);
3292 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
3295 case CC_RELEASE_CR | INDICATION:
3296 PDEBUG(DEBUG_ISDN, "%s: unhandled message from stack: call ref released (l3id=0x%x)\n", __FUNCTION__, hh->dinfo);
3299 case CC_DISCONNECT | INDICATION:
3303 PDEBUG(DEBUG_ISDN, "%s: unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", __FUNCTION__, hh->prim, hh->dinfo, msg->len);
3310 /* NOTE: te mode use iframe_t as header */
3311 int stack2manager_te(struct mISDNport *mISDNport, msg_t *msg)
3318 if (!msg || !mISDNport)
3320 frm = (iframe_t *)msg->data;
3321 PDEBUG(DEBUG_ISDN, "prim(0x%x) dinfo(0x%x) msg->len(%d)\n", frm->prim, frm->dinfo, msg->len);
3323 /* find Port object of type ISDN */
3327 if (port->p_type == PORT_TYPE_DSS1_TE_IN || port->p_type == PORT_TYPE_DSS1_TE_OUT)
3329 pdss1 = (class Pdss1 *)port;
3330 //PDEBUG(DEBUG_ISDN, "comparing dinfo = 0x%x with l3id 0x%x\n", frm->dinfo, pdss1->p_m_d_l3id);
3331 /* check out correct stack */
3332 if (pdss1->p_m_mISDNport == mISDNport)
3333 /* check out correct id */
3334 if (frm->dinfo == pdss1->p_m_d_l3id)
3336 /* found port, the message belongs to */
3344 pdss1->message_isdn(frm->prim, frm->dinfo, msg->data);
3349 /* process new cr (before setup indication) */
3350 //printf("prim = 0x%x, looking for 0x%x\n",frm->prim, (CC_NEW_CR | INDICATION));
3351 if (frm->prim == (CC_NEW_CR | INDICATION))
3354 /* creating port object */
3355 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3356 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_TE_IN, mISDNport, name, NULL)))
3358 RELEASE_COMPLETE_t *release_complete;
3361 fprintf(stderr, "FATAL ERROR: cannot create port object.\n");
3362 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, frm->dinfo, sizeof(RELEASE_COMPLETE_t), mISDNport->ntmode);
3363 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + mISDN_HEADER_LEN);
3364 enc_ie_cause_standalone(mISDNport->ntmode?&release_complete->CAUSE:NULL, dmsg, (mISDNport->ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47);
3365 msg_queue_tail(&mISDNport->downqueue, dmsg);
3369 /* l3id will be set from dinfo at message_isdn */
3370 pdss1->message_isdn(frm->prim, frm->dinfo, msg->data);
3375 if (frm->prim == (CC_RELEASE_CR | INDICATION))
3377 PDEBUG(DEBUG_ISDN, "unhandled message from stack: call ref released (l3id=0x%x)\n", frm->dinfo);
3381 PDEBUG(DEBUG_ISDN, "unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", frm->prim, frm->dinfo, msg->len);
3387 * sending message that were queued during L1 activation
3388 * or releasing port if link is down
3390 void setup_queue(struct mISDNport *mISDNport, int link)
3394 struct message *message;
3396 if (!mISDNport->ntmode)
3399 /* check all port objects for pending message */
3403 if ((port->p_type&PORT_CLASS_mISDN_MASK) == PORT_CLASS_mISDN_DSS1)
3405 pdss1 = (class Pdss1 *)port;
3406 if (pdss1->p_m_mISDNport == mISDNport)
3408 if (pdss1->p_m_d_queue)
3412 PDEBUG(DEBUG_ISDN, "the L1 became active, so we send queued message for portnum=%d (%s).\n", mISDNport->portnum, pdss1->p_name);
3413 /* LAYER 1 is up, so we send */
3414 pdss1->message_setup(pdss1->p_m_d_queue->id_from, pdss1->p_m_d_queue->type, &pdss1->p_m_d_queue->param);
3415 message_free(pdss1->p_m_d_queue);
3416 pdss1->p_m_d_queue = NULL;
3419 PDEBUG(DEBUG_ISDN, "the L1 became NOT active, so we release port for portnum=%d (%s).\n", mISDNport->portnum, pdss1->p_name);
3420 message = message_create(pdss1->p_serial, pdss1->p_m_d_queue->id_from, PORT_TO_EPOINT, MESSAGE_RELEASE);
3421 message->param.disconnectinfo.cause = 27;
3422 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
3423 message_put(message);
3424 pdss1->new_state(PORT_STATE_RELEASE);
3425 pdss1->p_m_delete = 1;