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 /* dialing information */
463 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));
464 dec_ie_keypad(setup->KEYPAD, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)keypad, sizeof(keypad));
465 SCAT(p_dialinginfo.number, (char *)keypad);
469 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
472 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
475 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
478 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
482 /* te-mode: CNIP (calling name identification presentation) */
484 dec_facility_centrex(setup->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)p_callerinfo.name, sizeof(p_callerinfo.name));
488 dec_ie_useruser(setup->USER_USER, (Q931_info_t *)((unsigned long)data+headerlen), &useruser_protocol, useruser, &useruser_len);
490 /* sending complete */
491 dec_ie_complete(setup->COMPLETE, (Q931_info_t *)((unsigned long)data+headerlen), &p_dialinginfo.sending_complete);
492 /* redirecting number */
493 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));
497 p_redirinfo.present = INFO_PRESENT_RESTRICTED;
500 p_redirinfo.present = INFO_PRESENT_NOTAVAIL;
503 p_redirinfo.present = INFO_PRESENT_ALLOWED;
509 p_redirinfo.screen = INFO_SCREEN_USER;
512 p_redirinfo.screen = INFO_SCREEN_NETWORK;
518 p_redirinfo.reason = INFO_REDIR_BUSY;
521 p_redirinfo.reason = INFO_REDIR_NORESPONSE;
524 p_redirinfo.reason = INFO_REDIR_UNCONDITIONAL;
527 p_redirinfo.reason = INFO_REDIR_CALLDEFLECT;
530 p_redirinfo.reason = INFO_REDIR_OUTOFORDER;
533 p_redirinfo.reason = INFO_REDIR_UNKNOWN;
539 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
540 p_redirinfo.present = INFO_PRESENT_NULL; /* not redirecting */
541 p_redirinfo.reason = INFO_REDIR_UNKNOWN;
544 p_redirinfo.ntype = INFO_NTYPE_INTERNATIONAL;
547 p_redirinfo.ntype = INFO_NTYPE_NATIONAL;
550 p_redirinfo.ntype = INFO_NTYPE_SUBSCRIBER;
553 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
556 p_redirinfo.isdn_port = p_m_portnum;
557 /* bearer capability */
558 dec_ie_bearer(setup->BEARER, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &capability, &mode, &rate, &multi, &user);
562 p_capainfo.bearer_capa = INFO_BC_AUDIO;
563 user = (options.law=='a')?3:2;
566 p_capainfo.bearer_capa = capability;
572 p_capainfo.bearer_mode = INFO_BMODE_PACKET;
575 p_capainfo.bearer_mode = INFO_BMODE_CIRCUIT;
581 p_capainfo.bearer_info1 = INFO_INFO1_NONE;
584 p_capainfo.bearer_info1 = user + 0x80;
589 dec_ie_hlc(setup->HLC, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &interpretation, &presentation, &hlc, &exthlc);
593 p_capainfo.hlc = INFO_HLC_NONE;
596 p_capainfo.hlc = hlc + 0x80;
602 p_capainfo.exthlc = INFO_HLC_NONE;
605 p_capainfo.exthlc = exthlc + 0x80;
610 dec_ie_channel_id(setup->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
613 if (channel==CHANNEL_NO && p_type==PORT_TYPE_DSS1_TE_IN)
614 PDEBUG(DEBUG_BCHANNEL, "- no channel is given by the network, causing to fail, since CW is not possible for external lines\n");
615 if (channel <= 0) /* not given, no channel, whatever.. */
616 channel = CHANNEL_ANY; /* any channel */
617 if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num) // of out chan..
619 printlog("--- port#%d all channels are used/reserved.\n", ifport->portnum);
620 ret = -34; // no channel
623 if (channel == CHANNE_ANY)
625 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");
626 /* check for any channel form selection list */
628 selchannel = ifport->channel_in;
631 switch(selchannel->channel)
633 case CHANNEL_FREE: /* free channel */
634 if (mISDNport->b_inuse >= mISDNport->b_num)
635 break; /* all channel in use or reserverd */
638 while(i < mISDNport->b_num)
640 if (mISDNport->b_port[i] == NULL)
642 channel = i+1+(i>=15);
643 printlog("--- port#%d no channel given, so selecting free channel %d\n", ifport->portnum, channel);
651 if (selchannel->channel<1 || selchannel->channel==16)
652 break; /* invalid channels */
653 i = selchannel->channel-1-(selchannel->channel>=17);
654 if (i >= mISDNport->b_num)
655 break; /* channel not in port */
656 if (mISDNport->b_port[i] == NULL)
658 channel = selchannel->channel;
659 printlog("--- port#%d no channel given, so selecting channel %d from list\n", ifport->portnum, channel);
665 break; /* found channel */
666 selchannel = selchannel->next;
670 printlog("--- port#%d no channel found.\n", ifport->portnum);
671 ret = -34; // no channel
678 /* check for given channel in selection list */
679 selchannel = ifport->channel_in;
682 if (selchannel->channel == channel || selchannel->channel == CHANNEL_FREE)
684 selchannel = selchannel->next;
689 /* exclusive channel requests must be in the list */
694 PDEBUG(DEBUG_BCHANNEL, "- exclusive channel %d is selected, but not in list of incomming channel.\n", channel);
695 printlog("--- port#%d channel %d given exclusively, it is accepted.\n", ifport->portnum, channel);
696 ret = 6; // unacceptable
699 PDEBUG(DEBUG_BCHANNEL, "- exclusive channel %d is selected, as in list of incomming channels.\n", channel);
700 i = selchannel->channel-1-(selchannel->channel>=17);
701 if (mISDNport->b_port[i] == NULL)
703 printlog("--- port#%d channel %d given exclusively, it is accepted and free.\n", ifport->portnum, channel);
706 printlog("--- port#%d channel %d given exclusively, it is accepted, but busy.\n", ifport->portnum, channel);
707 ret = 6; // unacceptable
711 /* requested channels in list will be used */
714 PDEBUG(DEBUG_BCHANNEL, "- channel %d given, found in list.\n", channel);
715 i = selchannel->channel-1-(selchannel->channel>=17);
716 if (mISDNport->b_port[i] == NULL)
718 printlog("--- port#%d channel %d given, it is accepted and free.\n", ifport->portnum, channel);
723 /* if channel is not available or not in list, it must be searched */
724 PDEBUG(DEBUG_BCHANNEL, "- channel %d given, but not in list of incomming channels.\n", channel);
726 /* check for first free channel in list */
728 selchannel = ifport->channel_in;
731 switch(selchannel->channel)
733 case CHANNEL_FREE: /* free channel */
734 if (mISDNport->b_inuse >= mISDNport->b_num)
735 break; /* all channel in use or reserverd */
738 while(i < mISDNport->b_num)
740 if (mISDNport->b_port[i] == NULL)
742 channel = i+1+(i>=15);
743 printlog("--- port#%d requested channel was not in list, so using free channel %d from list.\n", ifport->portnum, channel);
751 if (selchannel->channel<1 || selchannel->channel==16)
752 break; /* invalid channels */
753 i = selchannel->channel-1-(selchannel->channel>=17);
754 if (i >= mISDNport->b_num)
755 break; /* channel not in port */
756 if (mISDNport->b_port[i] == NULL)
758 channel = selchannel->channel;
759 printlog("--- port#%d requested channel was not in list, so using free channel %d from list.\n", ifport->portnum, channel);
765 break; /* found channel */
766 selchannel = selchannel->next;
770 printlog("--- port#%d no channel found.\n", ifport->portnum);
771 ret = 6; // unacceptable
778 ret = seize_bchannel(channel, 1);
782 PDEBUG(DEBUG_BCHANNEL, "- channel is not available (cause=%d), so we send a release_complete.\n", -ret);
783 RELEASE_COMPLETE_t *release_complete;
785 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
786 isdn_show_send_message(CC_RELEASE_COMPLETE | REQUEST, dmsg);
787 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
788 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
789 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
790 new_state(PORT_STATE_RELEASE);
794 PDEBUG(DEBUG_BCHANNEL, "- channel is available, we open channel %d.\n", ret);
795 bchannel_activate(p_m_mISDNport, p_m_b_index);
797 /* create endpoint */
800 PERROR("SOFTWARE ERROR: incoming call but already got an endpoint, exitting...\n");
803 if (!(epoint = new Endpoint(p_serial, 0)))
805 RELEASE_COMPLETE_t *release_complete;
807 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
808 isdn_show_send_message(CC_RELEASE_COMPLETE | REQUEST, dmsg);
809 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
810 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_d_ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 41); /* temporary failure */
811 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
812 new_state(PORT_STATE_RELEASE);
816 if (!(epoint->ep_app = new DEFAULT_ENDPOINT_APP(epoint)))
818 PERROR("no memory for application\n");
821 if (!(epointlist_new(epoint->ep_serial)))
823 PERROR("no memory for epointlist\n");
828 /* nt-library now gives us the id via CC_SETUP */
829 if (dinfo&(~0xff) == 0xff00)
831 PERROR("fatal software error: l3-stack gives us a process id 0xff00-0xffff\n");
834 printisdn(" l3id 0x%x changes to 0x%x\n", p_m_d_l3id, dinfo);
835 if (p_m_d_l3id&(~0xff) == 0xff00)
836 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
838 p_m_d_ces = setup->ces;
839 PDEBUG(DEBUG_ISDN, "Pdss1(%s) nt-mode gives us new l3id via setup ind: 0x%x\n", p_name, p_m_d_l3id);
842 /* send setup message to endpoit */
843 PDEBUG(DEBUG_ISDN, "Pdss1(%s) setup: %s->%s\n", p_name, p_callerinfo.id, p_dialinginfo.number);
844 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_SETUP);
845 message->param.setup.isdn_port = p_m_portnum;
846 message->param.setup.port_type = p_type;
847 p_callerinfo.isdn_port = p_m_portnum;
848 SCPY(p_callerinfo.interface, p_m_mISDNport->ifport->interface->name);;
849 memcpy(&message->param.setup.dialinginfo, &p_dialinginfo, sizeof(struct dialing_info));
850 memcpy(&message->param.setup.callerinfo, &p_callerinfo, sizeof(struct caller_info));
851 memcpy(&message->param.setup.redirinfo, &p_redirinfo, sizeof(struct redir_info));
852 memcpy(&message->param.setup.capainfo, &p_capainfo, sizeof(struct capa_info));
853 memcpy(message->param.setup.useruser.data, &useruser, useruser_len);
854 message->param.setup.useruser.len = useruser_len;
855 message->param.setup.useruser.protocol = useruser_protocol;
856 message_put(message);
858 new_state(PORT_STATE_IN_SETUP);
861 /* CC_INFORMATION INDICATION */
862 void Pdss1::information_ind(unsigned long prim, unsigned long dinfo, void *data)
864 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
865 INFORMATION_t *information = (INFORMATION_t *)((unsigned long)data + headerlen);
867 unsigned char keypad[32] = "";
868 struct message *message;
870 /* dialing information */
871 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));
872 dec_ie_keypad(information->KEYPAD, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)keypad, sizeof(keypad));
873 SCAT(p_dialinginfo.number, (char *)keypad);
877 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
880 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
883 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
886 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
889 /* sending complete */
890 dec_ie_complete(information->COMPLETE, (Q931_info_t *)((unsigned long)data+headerlen), &p_dialinginfo.sending_complete);;
891 PDEBUG(DEBUG_ISDN, "Pdss1(%s) more digits: %s\n", p_name,p_dialinginfo.number);
892 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_INFORMATION);
893 memcpy(&message->param.information, &p_dialinginfo, sizeof(struct dialing_info));
894 message_put(message);
895 /* reset overlap timeout */
899 /* CC_SETUP_ACCNOWLEDGE INDICATION */
900 void Pdss1::setup_acknowledge_ind(unsigned long prim, unsigned long dinfo, void *data)
902 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
903 SETUP_ACKNOWLEDGE_t *setup_acknowledge = (SETUP_ACKNOWLEDGE_t *)((unsigned long)data + headerlen);
904 int exclusive, channel;
905 int coding, location, progress;
907 struct message *message;
910 dec_ie_channel_id(setup_acknowledge->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
911 dec_ie_progress(setup_acknowledge->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
912 ret = received_first_reply_to_setup(prim, exclusive, channel);
915 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
916 message->param.disconnectinfo.cause = -ret;
917 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
918 message_put(message);
919 new_state(PORT_STATE_RELEASE);
923 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_OVERLAP);
924 message_put(message);
926 new_state(PORT_STATE_OUT_OVERLAP);
929 /* CC_PROCEEDING INDICATION */
930 void Pdss1::proceeding_ind(unsigned long prim, unsigned long dinfo, void *data)
932 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
933 CALL_PROCEEDING_t *proceeding = (CALL_PROCEEDING_t *)((unsigned long)data + headerlen);
934 int exclusive, channel;
935 int coding, location, progress;
937 struct message *message;
938 int notify = -1, type, plan, present;
942 dec_ie_channel_id(proceeding->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
943 dec_ie_progress(proceeding->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
944 ret = received_first_reply_to_setup(prim, exclusive, channel);
947 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
948 message->param.disconnectinfo.cause = -ret;
949 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
950 message_put(message);
951 new_state(PORT_STATE_RELEASE);
955 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROCEEDING);
956 message_put(message);
958 new_state(PORT_STATE_OUT_PROCEEDING);
960 dec_ie_notify(NULL/*proceeding->NOTIFY*/, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
965 dec_ie_redir_dn(proceeding->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
966 if (type >= 0 || notify)
968 if (!notify && type >= 0)
970 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
971 message->param.notifyinfo.notify = notify;
972 SCPY(message->param.notifyinfo.id, redir);
973 /* redirection number */
977 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
980 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
983 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
989 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
990 message->param.notifyinfo.present = INFO_PRESENT_NULL;
993 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
996 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
999 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1002 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1005 message->param.notifyinfo.isdn_port = p_m_portnum;
1006 message_put(message);
1010 /* CC_ALERTING INDICATION */
1011 void Pdss1::alerting_ind(unsigned long prim, unsigned long dinfo, void *data)
1013 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1014 ALERTING_t *alerting = (ALERTING_t *)((unsigned long)data + headerlen);
1015 int exclusive, channel;
1016 int coding, location, progress;
1018 struct message *message;
1019 int notify = -1, type, plan, present;
1023 dec_ie_channel_id(alerting->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
1024 dec_ie_progress(alerting->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
1025 ret = received_first_reply_to_setup(prim, exclusive, channel);
1028 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1029 message->param.disconnectinfo.cause = -ret;
1030 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1031 message_put(message);
1032 new_state(PORT_STATE_RELEASE);
1036 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_ALERTING);
1037 message_put(message);
1039 new_state(PORT_STATE_OUT_ALERTING);
1041 dec_ie_notify(NULL/*alerting->NOTIFY*/, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
1046 dec_ie_redir_dn(alerting->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
1047 if (type >= 0 || notify)
1049 if (!notify && type >= 0)
1051 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1052 message->param.notifyinfo.notify = notify;
1053 SCPY(message->param.notifyinfo.id, redir);
1057 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1060 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1063 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1069 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1070 message->param.notifyinfo.present = INFO_PRESENT_NULL;
1073 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1076 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1079 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1082 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1085 message->param.notifyinfo.isdn_port = p_m_portnum;
1086 message_put(message);
1090 /* CC_CONNECT INDICATION */
1091 void Pdss1::connect_ind(unsigned long prim, unsigned long dinfo, void *data)
1093 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1094 CONNECT_t *connect = (CONNECT_t *)((unsigned long)data + headerlen);
1095 int exclusive, channel;
1096 int type, plan, present, screen;
1099 struct message *message;
1100 int bchannel_before;
1103 p_m_d_ces = connect->ces;
1105 /* NOTE: we do not check the connected channel, since we
1106 * ready sent a channel to the remote side
1109 dec_ie_channel_id(connect->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
1110 bchannel_before = p_m_b_channel;
1111 ret = received_first_reply_to_setup(prim, exclusive, channel);
1114 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1115 message->param.disconnectinfo.cause = -ret;
1116 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1117 message_put(message);
1118 new_state(PORT_STATE_RELEASE);
1122 /* connect information */
1123 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));
1127 p_connectinfo.present = INFO_PRESENT_RESTRICTED;
1130 p_connectinfo.present = INFO_PRESENT_NOTAVAIL;
1133 p_connectinfo.present = INFO_PRESENT_ALLOWED;
1139 p_connectinfo.screen = INFO_SCREEN_USER;
1142 p_connectinfo.screen = INFO_SCREEN_NETWORK;
1148 p_connectinfo.present = INFO_PRESENT_NULL; /* no COLP info */
1149 p_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1152 p_connectinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1155 p_connectinfo.ntype = INFO_NTYPE_NATIONAL;
1158 p_connectinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1161 p_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1164 p_connectinfo.isdn_port = p_m_portnum;
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)
2103 /* handle destruction */
2104 if (p_m_delete && p_m_d_l3id==0)
2106 PDEBUG(DEBUG_ISDN, "Pdss1(%s) doing pending release.\n", p_name);
2111 return(PmISDN::handler());
2116 * handles all messages from endpoint
2118 /* MESSAGE_INFORMATION */
2119 void Pdss1::message_information(unsigned long epoint_id, int message_id, union parameter *param)
2121 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2122 INFORMATION_t *information;
2125 if (param->information.number[0]) /* only if we have something to dial */
2127 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2128 isdn_show_send_message(CC_INFORMATION | REQUEST, dmsg);
2129 information = (INFORMATION_t *)(dmsg->data + headerlen);
2130 enc_ie_called_pn(&information->CALLED_PN, dmsg, 0, 1, (unsigned char *)param->information.number);
2131 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2140 void Pdss1::message_setup(unsigned long epoint_id, int message_id, union parameter *param)
2142 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2143 INFORMATION_t *information;
2146 int plan, type, screen, present, reason;
2147 int capability, mode, rate, coding, user, presentation, interpretation, hlc, exthlc;
2148 int channel, exclusive;
2150 struct epoint_list *epointlist;
2152 /* release if port is blocked */
2153 if (p_m_mISDNport->ifport->block)
2155 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2156 message->param.disconnectinfo.cause = 27; // temp. unavail.
2157 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2158 message_put(message);
2159 new_state(PORT_STATE_RELEASE);
2164 /* copy setup infos to port */
2165 memcpy(&p_callerinfo, ¶m->setup.callerinfo, sizeof(p_callerinfo));
2166 memcpy(&p_dialinginfo, ¶m->setup.dialinginfo, sizeof(p_dialinginfo));
2167 memcpy(&p_capainfo, ¶m->setup.capainfo, sizeof(p_capainfo));
2168 memcpy(&p_redirinfo, ¶m->setup.redirinfo, sizeof(p_redirinfo));
2169 // SCPY(&p_m_tones_dir, param->setup.ext.tones_dir);
2171 /* only display at connect state: this case happens if endpoint is in connected mode */
2172 if (p_state==PORT_STATE_CONNECT)
2174 if (p_type!=PORT_TYPE_DSS1_NT_OUT
2175 && p_type!=PORT_TYPE_DSS1_NT_IN)
2177 if (p_callerinfo.display[0])
2179 /* sending information */
2180 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2181 isdn_show_send_message(CC_INFORMATION | REQUEST, dmsg);
2182 information = (INFORMATION_t *)(dmsg->data + headerlen);
2184 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_callerinfo.display);
2185 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2190 /* attach only if not already */
2191 epointlist = p_epointlist;
2194 if (epointlist->epoint_id == epoint_id)
2196 epointlist = epointlist->next;
2200 if (!(epointlist_new(epoint_id)))
2202 PERROR("no memory for epointlist\n");
2211 channel = p_m_b_channel;
2212 exclusive = p_m_b_exclusive;
2214 channel = CHANNEL_ANY;
2215 /* nt-port with no channel, not reserverd */
2216 if (!p_m_b_channel && !p_m_b_reserve && p_type==PORT_TYPE_DSS1_NT_OUT)
2217 channel = CHANNEL_NO;
2225 if (p_m_mISDNport->procids[i] == 0)
2231 struct message *message;
2233 printisdn(" no free process id\n");
2234 PDEBUG(DEBUG_ISDN, "no more free process ID for port.\n");
2235 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2236 message->param.disconnectinfo.cause = 47;
2237 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2238 message_put(message);
2239 new_state(PORT_STATE_RELEASE);
2243 p_m_mISDNport->procids[i] = 1;
2244 printisdn(" procid 0x%x allocated\n", i);
2245 p_m_d_l3id = 0xff00 | i;
2246 printisdn(" l3id is now 0x%x\n", p_m_d_l3id);
2250 /* if we are in te-mode, we need to create a process first */
2251 if (newteid++ > 0x7fff)
2253 p_m_d_l3id = (entity<<16) | newteid;
2254 /* preparing message */
2255 ncr.prim = CC_NEW_CR | REQUEST;
2256 ncr.addr = p_m_mISDNport->upper_id | FLG_MSG_DOWN;
2257 ncr.dinfo = p_m_d_l3id;
2259 isdn_show_send_message(CC_NEW_CR | REQUEST, NULL);
2261 mISDN_write(mISDNdevice, &ncr, mISDN_HEADER_LEN+ncr.len, TIMEOUT_1SEC);
2266 /* preparing setup message */
2267 dmsg = create_l3msg(CC_SETUP | REQUEST, MT_SETUP, p_m_d_l3id, sizeof(SETUP_t), p_m_d_ntmode);
2268 isdn_show_send_message(CC_SETUP | REQUEST, dmsg);
2269 setup = (SETUP_t *)(dmsg->data + headerlen);
2270 /* channel information */
2271 if (channel >= 0) /* it should */
2273 enc_ie_channel_id(&setup->CHANNEL_ID, dmsg, exclusive, channel);
2275 /* caller information */
2277 switch (p_callerinfo.ntype)
2279 case INFO_NTYPE_INTERNATIONAL:
2282 case INFO_NTYPE_NATIONAL:
2285 case INFO_NTYPE_SUBSCRIBER:
2288 default: /* INFO_NTYPE_UNKNOWN */
2292 switch (p_callerinfo.screen)
2294 case INFO_SCREEN_USER:
2297 default: /* INFO_SCREEN_NETWORK */
2301 switch (p_callerinfo.present)
2303 case INFO_PRESENT_RESTRICTED:
2306 case INFO_PRESENT_NOTAVAIL:
2309 default: /* INFO_PRESENT_ALLOWED */
2314 enc_ie_calling_pn(&setup->CALLING_PN, dmsg, type, plan, present, screen, (unsigned char *)p_callerinfo.id);
2315 /* dialing information */
2316 if (p_dialinginfo.number[0]) /* only if we have something to dial */
2318 enc_ie_called_pn(&setup->CALLED_PN, dmsg, 0, 1, (unsigned char *)p_dialinginfo.number);
2320 /* sending complete */
2321 if (p_dialinginfo.sending_complete)
2322 enc_ie_complete(&setup->COMPLETE, dmsg, 1);
2323 /* sending user-user */
2324 if (param->setup.useruser.len)
2326 enc_ie_useruser(&setup->USER_USER, dmsg, param->setup.useruser.protocol, param->setup.useruser.data, param->setup.useruser.len);
2328 /* redirecting number */
2330 switch (p_redirinfo.ntype)
2332 case INFO_NTYPE_INTERNATIONAL:
2335 case INFO_NTYPE_NATIONAL:
2338 case INFO_NTYPE_SUBSCRIBER:
2341 default: /* INFO_NTYPE_UNKNOWN */
2345 switch (p_redirinfo.screen)
2347 case INFO_SCREEN_USER:
2350 default: /* INFO_SCREE_NETWORK */
2354 switch (p_redirinfo.reason)
2356 case INFO_REDIR_BUSY:
2359 case INFO_REDIR_NORESPONSE:
2362 case INFO_REDIR_UNCONDITIONAL:
2365 case INFO_REDIR_CALLDEFLECT:
2368 case INFO_REDIR_OUTOFORDER:
2371 default: /* INFO_REDIR_UNKNOWN */
2375 switch (p_redirinfo.present)
2377 case INFO_PRESENT_NULL: /* no redir at all */
2384 case INFO_PRESENT_RESTRICTED:
2387 case INFO_PRESENT_NOTAVAIL:
2390 default: /* INFO_PRESENT_ALLOWED */
2394 /* sending redirecting number only in ntmode */
2395 if (type >= 0 && p_m_d_ntmode)
2396 enc_ie_redir_nr(&setup->REDIR_NR, dmsg, type, plan, present, screen, reason, (unsigned char *)p_redirinfo.id);
2397 /* bearer capability */
2398 //printf("hlc=%d\n",p_capainfo.hlc);
2400 capability = p_capainfo.bearer_capa;
2401 mode = p_capainfo.bearer_mode;
2402 rate = (mode==INFO_BMODE_CIRCUIT)?0x10:0x00;
2403 switch (p_capainfo.bearer_info1)
2405 case INFO_INFO1_NONE:
2409 user = p_capainfo.bearer_info1 & 0x7f;
2412 enc_ie_bearer(&setup->BEARER, dmsg, coding, capability, mode, rate, -1, user);
2419 hlc = p_capainfo.hlc & 0x7f;
2421 if (p_capainfo.exthlc)
2422 exthlc = p_capainfo.exthlc & 0x7f;
2423 enc_ie_hlc(&setup->HLC, dmsg, coding, interpretation, presentation, hlc, exthlc);
2427 if (p_callerinfo.display[0] && p_m_d_ntmode)
2428 enc_ie_display(&setup->DISPLAY, dmsg, (unsigned char *)p_callerinfo.display);
2430 /* nt-mode: CNIP (calling name identification presentation) */
2431 if (p_callerinfo.name[0] && p_m_d_ntmode)
2432 enc_facility_centrex(&setup->FACILITY, dmsg, (unsigned char *)p_callerinfo.name, 1);
2435 /* send setup message now */
2436 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2438 new_state(PORT_STATE_OUT_SETUP);
2441 /* MESSAGE_FACILITY */
2442 void Pdss1::message_facility(unsigned long epoint_id, int message_id, union parameter *param)
2444 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2445 FACILITY_t *facility;
2448 /* facility will not be sent to external lines */
2452 PDEBUG(DEBUG_ISDN, "Pdss1(%s) sending facility message\n", p_name);
2454 /* sending facility */
2455 dmsg = create_l3msg(CC_FACILITY | REQUEST, MT_FACILITY, p_m_d_l3id, sizeof(FACILITY_t), p_m_d_ntmode);
2456 isdn_show_send_message(CC_FACILITY | REQUEST, dmsg);
2457 facility = (FACILITY_t *)(dmsg->data + headerlen);
2458 enc_ie_facility(&facility->FACILITY, dmsg, (unsigned char *)param->facilityinfo.data, param->facilityinfo.len);
2459 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2462 /* MESSAGE_NOTIFY */
2463 void Pdss1::message_notify(unsigned long epoint_id, int message_id, union parameter *param)
2465 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2466 INFORMATION_t *information;
2467 NOTIFY_t *notification;
2469 int plan, type = -1, present;
2472 PDEBUG(DEBUG_ISDN, "Pdss1(%s) sending information message\n", p_name);
2473 if (param->notifyinfo.notify>INFO_NOTIFY_NONE)
2474 notify = param->notifyinfo.notify & 0x7f;
2477 if (p_state != PORT_STATE_CONNECT)
2479 /* notify only allowed in active state */
2485 switch (param->notifyinfo.ntype)
2487 case INFO_NTYPE_INTERNATIONAL:
2490 case INFO_NTYPE_NATIONAL:
2493 case INFO_NTYPE_SUBSCRIBER:
2496 default: /* INFO_NTYPE_UNKNOWN */
2500 switch (param->notifyinfo.present)
2502 case INFO_PRESENT_NULL: /* no redir at all */
2507 case INFO_PRESENT_RESTRICTED:
2510 case INFO_PRESENT_NOTAVAIL:
2513 default: /* INFO_PRESENT_ALLOWED */
2519 if (notify<0 && !param->notifyinfo.display[0])
2521 PDEBUG(DEBUG_ISDN, "Pdss1(%s) nothing to notify, nothing to display\n", p_name);
2527 if (p_state!=PORT_STATE_CONNECT)
2529 /* queue notification */
2530 PDEBUG(DEBUG_ISDN, "Pdss1(%s) queueing notification because isdn port is not active state.\n", p_name);
2531 if (p_m_d_notify_pending)
2532 message_free(p_m_d_notify_pending);
2533 p_m_d_notify_pending = message_create(ACTIVE_EPOINT(p_epointlist), p_serial, EPOINT_TO_PORT, message_id);
2534 memcpy(&p_m_d_notify_pending->param, param, sizeof(union parameter));
2537 /* sending notification */
2538 dmsg = create_l3msg(CC_NOTIFY | REQUEST, MT_NOTIFY, p_m_d_l3id, sizeof(NOTIFY_t), p_m_d_ntmode);
2539 isdn_show_send_message(CC_NOTIFY | REQUEST, dmsg);
2540 notification = (NOTIFY_t *)(dmsg->data + headerlen);
2541 enc_ie_notify(¬ification->NOTIFY, dmsg, notify);
2542 /* sending redirection number only in ntmode */
2543 if (type >= 0 && p_m_d_ntmode)
2544 enc_ie_redir_dn(¬ification->REDIR_DN, dmsg, type, plan, present, (unsigned char *)param->notifyinfo.id);
2545 if (param->notifyinfo.display[0] && p_m_d_ntmode)
2546 enc_ie_display(¬ification->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display);
2547 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2549 } else if (p_m_d_ntmode)
2551 /* sending information */
2552 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2553 isdn_show_send_message(CC_INFORMATION | REQUEST, dmsg);
2554 information = (INFORMATION_t *)(dmsg->data + headerlen);
2555 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display);
2556 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2560 /* MESSAGE_OVERLAP */
2561 void Pdss1::message_overlap(unsigned long epoint_id, int message_id, union parameter *param)
2563 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2564 SETUP_ACKNOWLEDGE_t *setup_acknowledge;
2567 /* sending setup_acknowledge */
2568 dmsg = create_l3msg(CC_SETUP_ACKNOWLEDGE | REQUEST, MT_SETUP_ACKNOWLEDGE, p_m_d_l3id, sizeof(SETUP_ACKNOWLEDGE_t), p_m_d_ntmode);
2569 isdn_show_send_message(CC_SETUP_ACKNOWLEDGE | REQUEST, dmsg);
2570 setup_acknowledge = (SETUP_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
2571 /* channel information */
2572 if (p_state == PORT_STATE_IN_SETUP)
2573 enc_ie_channel_id(&setup_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2574 /* progress information */
2575 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2576 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2577 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2578 if (p_m_mISDNport->is_tones)
2579 enc_ie_progress(&setup_acknowledge->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2580 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2582 new_state(PORT_STATE_IN_OVERLAP);
2585 /* MESSAGE_PROCEEDING */
2586 void Pdss1::message_proceeding(unsigned long epoint_id, int message_id, union parameter *param)
2588 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2589 CALL_PROCEEDING_t *proceeding;
2592 /* sending proceeding */
2593 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2594 isdn_show_send_message(CC_PROCEEDING | REQUEST, dmsg);
2595 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2596 /* channel information */
2597 if (p_state == PORT_STATE_IN_SETUP)
2598 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2599 /* progress information */
2600 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2601 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2602 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2603 if (p_m_mISDNport->is_tones)
2604 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2605 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2607 new_state(PORT_STATE_IN_PROCEEDING);
2610 /* MESSAGE_ALERTING */
2611 void Pdss1::message_alerting(unsigned long epoint_id, int message_id, union parameter *param)
2613 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2614 ALERTING_t *alerting;
2617 /* NT-MODE in setup state we must send PROCEEDING first */
2618 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2620 CALL_PROCEEDING_t *proceeding;
2622 /* sending proceeding */
2623 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2624 isdn_show_send_message(CC_PROCEEDING | REQUEST, dmsg);
2625 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2626 /* channel information */
2627 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2628 /* progress information */
2629 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2630 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2631 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2632 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2633 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2634 new_state(PORT_STATE_IN_PROCEEDING);
2637 /* sending alerting */
2638 dmsg = create_l3msg(CC_ALERTING | REQUEST, MT_ALERTING, p_m_d_l3id, sizeof(ALERTING_t), p_m_d_ntmode);
2639 isdn_show_send_message(CC_ALERTING | REQUEST, dmsg);
2640 alerting = (ALERTING_t *)(dmsg->data + headerlen);
2641 /* channel information */
2642 if (p_state == PORT_STATE_IN_SETUP)
2643 enc_ie_channel_id(&alerting->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2644 /* progress information */
2645 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2646 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2647 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2648 if (p_m_mISDNport->is_tones)
2649 enc_ie_progress(&alerting->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2650 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2652 new_state(PORT_STATE_IN_ALERTING);
2655 /* MESSAGE_CONNECT */
2656 void Pdss1::message_connect(unsigned long epoint_id, int message_id, union parameter *param)
2658 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2659 INFORMATION_t *information;
2661 int type, plan, present, screen;
2663 class Endpoint *epoint;
2665 /* NT-MODE in setup state we must send PROCEEDING first */
2666 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2668 CALL_PROCEEDING_t *proceeding;
2670 /* sending proceeding */
2671 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2672 isdn_show_send_message(CC_PROCEEDING | REQUEST, dmsg);
2673 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2674 /* channel information */
2675 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2676 // /* progress information */
2677 // if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2678 // || p_capainfo.bearer_capa==INFO_BC_AUDIO
2679 // || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2680 // enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2681 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2682 new_state(PORT_STATE_IN_PROCEEDING);
2685 /* copy connected information */
2686 memcpy(&p_connectinfo, ¶m->connectinfo, sizeof(p_connectinfo));
2688 /* only display at connect state */
2689 if (p_state == PORT_STATE_CONNECT)
2690 if (p_connectinfo.display[0])
2692 /* sending information */
2693 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2694 isdn_show_send_message(CC_INFORMATION | REQUEST, dmsg);
2695 information = (INFORMATION_t *)(dmsg->data + headerlen);
2697 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_connectinfo.display);
2698 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2702 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)
2704 PDEBUG(DEBUG_ISDN, "Pdss1(%s) connect command only possible in setup, proceeding or alerting state.\n", p_name);
2708 /* preparing connect message */
2709 dmsg = create_l3msg(CC_CONNECT | REQUEST, MT_CONNECT, p_m_d_l3id, sizeof(CONNECT_t), p_m_d_ntmode);
2710 isdn_show_send_message(CC_CONNECT | REQUEST, dmsg);
2711 connect = (CONNECT_t *)(dmsg->data + headerlen);
2712 /* connect information */
2714 switch (p_connectinfo.ntype)
2716 case INFO_NTYPE_INTERNATIONAL:
2719 case INFO_NTYPE_NATIONAL:
2722 case INFO_NTYPE_SUBSCRIBER:
2725 default: /* INFO_NTYPE_UNKNOWN */
2729 switch (param->connectinfo.screen)
2731 case INFO_SCREEN_USER:
2734 default: /* INFO_SCREE_NETWORK */
2738 switch (p_connectinfo.present)
2740 case INFO_PRESENT_NULL: /* no colp at all */
2746 case INFO_PRESENT_RESTRICTED:
2749 case INFO_PRESENT_NOTAVAIL:
2752 default: /* INFO_PRESENT_ALLOWED */
2757 enc_ie_connected_pn(&connect->CONNECT_PN, dmsg, type, plan, present, screen, (unsigned char *)p_connectinfo.id);
2759 if (p_connectinfo.display[0] && p_m_d_ntmode)
2760 enc_ie_display(&connect->DISPLAY, dmsg, (unsigned char *)p_connectinfo.display);
2762 /* nt-mode: CONP (connected name identification presentation) */
2763 if (p_connectinfo.name[0] && p_m_d_ntmode)
2764 enc_facility_centrex(&connect->FACILITY, dmsg, (unsigned char *)p_connectinfo.name, 0);
2769 epoint = find_epoint_id(epoint_id);
2770 enc_ie_date(&connect->DATE, dmsg, now, p_settings.no_seconds);
2772 /* finally send message */
2773 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2776 new_state(PORT_STATE_CONNECT);
2778 new_state(PORT_STATE_CONNECT_WAITING);
2782 /* MESSAGE_DISCONNECT */
2783 void Pdss1::message_disconnect(unsigned long epoint_id, int message_id, union parameter *param)
2785 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2786 DISCONNECT_t *disconnect;
2787 RELEASE_COMPLETE_t *release_complete;
2789 struct message *message;
2792 /* we reject during incoming setup when we have no tones. also if we are in outgoing setup state */
2793 if ((p_state==PORT_STATE_IN_SETUP && !p_m_mISDNport->is_tones)
2794 || p_state==PORT_STATE_OUT_SETUP)
2796 /* sending release to endpoint */
2799 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
2800 message->param.disconnectinfo.cause = 16;
2801 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2802 message_put(message);
2804 free_epointlist(p_epointlist);
2806 /* sending release */
2807 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
2808 isdn_show_send_message(CC_RELEASE_COMPLETE | REQUEST, dmsg);
2809 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
2811 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);
2812 new_state(PORT_STATE_RELEASE);
2813 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2818 /* NT-MODE in setup state we must send PROCEEDING first */
2819 if (p_state==PORT_STATE_IN_SETUP)
2821 CALL_PROCEEDING_t *proceeding;
2823 /* sending proceeding */
2824 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2825 isdn_show_send_message(CC_PROCEEDING | REQUEST, dmsg);
2826 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2827 /* channel information */
2828 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2829 /* progress information */
2830 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2831 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2832 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2833 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2834 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2835 new_state(PORT_STATE_IN_PROCEEDING);
2838 /* sending disconnect */
2839 dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode);
2840 isdn_show_send_message(CC_DISCONNECT | REQUEST, dmsg);
2841 disconnect = (DISCONNECT_t *)(dmsg->data + headerlen);
2842 /* progress information */
2843 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2844 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2845 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2846 if (p_m_mISDNport->is_tones)
2847 enc_ie_progress(&disconnect->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2849 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);
2851 if (param->disconnectinfo.display[0])
2852 p = param->disconnectinfo.display;
2853 if (p) if (*p && p_m_d_ntmode)
2854 enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p);
2855 new_state(PORT_STATE_OUT_DISCONNECT);
2856 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2859 /* MESSAGE_RELEASE */
2860 void Pdss1::message_release(unsigned long epoint_id, int message_id, union parameter *param)
2862 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2864 RELEASE_COMPLETE_t *release_complete;
2865 DISCONNECT_t *disconnect;
2867 class Endpoint *epoint;
2870 /* if we have incoming disconnected, we may release */
2871 if (p_state==PORT_STATE_IN_DISCONNECT
2872 || p_state==PORT_STATE_OUT_DISCONNECT)
2874 /* sending release */
2875 dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, p_m_d_l3id, sizeof(RELEASE_t), p_m_d_ntmode);
2876 isdn_show_send_message(CC_RELEASE | REQUEST, dmsg);
2877 release = (RELEASE_t *)(dmsg->data + headerlen);
2879 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);
2880 new_state(PORT_STATE_RELEASE);
2881 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2884 free_epointid(epoint_id);
2887 if ((p_m_d_l3id&0xff00) == 0xff00)
2889 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
2890 printisdn(" procid 0x%x freed\n", p_m_d_l3id&0xff);
2897 /* if we are on outgoing/incoming call setup, we may release complete */
2898 if (p_state==PORT_STATE_OUT_SETUP
2899 || p_state==PORT_STATE_IN_SETUP
2900 // NOTE: a bug in mISDNuser (see disconnect_req_out !!!)
2901 || p_state==PORT_STATE_OUT_PROCEEDING)
2903 /* sending release */
2904 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
2905 isdn_show_send_message(CC_RELEASE_COMPLETE | REQUEST, dmsg);
2906 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
2908 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);
2909 new_state(PORT_STATE_RELEASE);
2910 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2911 goto remove_endpoint;
2914 /* NT-MODE in setup state we must send PROCEEDING first */
2915 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2917 CALL_PROCEEDING_t *proceeding;
2919 /* sending proceeding */
2920 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2921 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2922 /* channel information */
2923 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2924 /* progress information */
2925 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2926 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2927 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2928 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2929 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2932 /* sending disconnect */
2933 dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode);
2934 isdn_show_send_message(CC_DISCONNECT | REQUEST, dmsg);
2935 disconnect = (DISCONNECT_t *)(dmsg->data + headerlen);
2936 /* progress information */
2937 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2938 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2939 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2940 if (p_m_mISDNport->is_tones)
2941 enc_ie_progress(&disconnect->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2943 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);
2945 epoint = find_epoint_id(epoint_id);
2946 if (param->disconnectinfo.display[0])
2947 p = param->disconnectinfo.display;
2948 if (p) if (*p && p_m_d_ntmode)
2949 enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p);
2951 /* sending release */
2952 dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, p_m_d_l3id, sizeof(RELEASE_t), p_m_d_ntmode);
2953 isdn_show_send_message(CC_RELEASE | REQUEST, dmsg);
2954 release = (RELEASE_t *)(dmsg->data + headerlen);
2956 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);
2958 new_state(PORT_STATE_RELEASE);
2959 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2960 free_epointid(epoint_id);
2966 * endpoint sends messages to the port
2968 int Pdss1::message_epoint(unsigned long epoint_id, int message_id, union parameter *param)
2970 struct message *message;
2972 if (PmISDN::message_epoint(epoint_id, message_id, param))
2977 case MESSAGE_INFORMATION: /* overlap dialing */
2978 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received dialing info '%s'.\n", p_name, param->information.number);
2979 if (p_type==PORT_TYPE_DSS1_NT_OUT
2980 && p_state!=PORT_STATE_OUT_OVERLAP
2981 && p_state!=PORT_STATE_CONNECT
2982 && p_state!=PORT_STATE_OUT_DISCONNECT
2983 && p_state!=PORT_STATE_IN_DISCONNECT)
2985 PDEBUG(DEBUG_ISDN, "Pdss1(%s) (internal outgoing) ignoring information, invalid state.\n", p_name);
2988 if (p_type==PORT_TYPE_DSS1_TE_OUT
2989 && p_state!=PORT_STATE_OUT_OVERLAP
2990 && p_state!=PORT_STATE_OUT_PROCEEDING
2991 && p_state!=PORT_STATE_OUT_ALERTING
2992 && p_state!=PORT_STATE_CONNECT
2993 && p_state!=PORT_STATE_OUT_DISCONNECT
2994 && p_state!=PORT_STATE_IN_DISCONNECT)
2996 if (options.deb & DEBUG_ISDN)
2997 PERROR("Pdss1(%s) (external outgoing) ignoring information, invalid state.\n", p_name);
3000 if ((p_type==PORT_TYPE_DSS1_NT_IN || p_type==PORT_TYPE_DSS1_TE_IN)
3001 && p_state!=PORT_STATE_IN_OVERLAP
3002 && p_state!=PORT_STATE_IN_PROCEEDING
3003 && p_state!=PORT_STATE_IN_ALERTING
3004 && p_state!=PORT_STATE_CONNECT
3005 && p_state!=PORT_STATE_CONNECT_WAITING
3006 && p_state!=PORT_STATE_OUT_DISCONNECT
3007 && p_state!=PORT_STATE_IN_DISCONNECT)
3009 PDEBUG(DEBUG_ISDN, "Pdss1(%s) (incoming) ignoring information, invalid state.\n", p_name);
3012 message_information(epoint_id, message_id, param);
3015 case MESSAGE_SETUP: /* dial-out command received from epoint */
3016 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);
3017 if (p_state!=PORT_STATE_IDLE
3018 && p_state!=PORT_STATE_CONNECT)
3020 PERROR("Pdss1(%s) ignoring setup because isdn port is not in idle state (or connected for sending display info).\n", p_name);
3023 if (p_epointlist && p_state==PORT_STATE_IDLE)
3025 PERROR("Pdss1(%s): software error: epoint pointer is set in idle state, how bad!! exitting.\n", p_name);
3028 /* note: pri is a special case, because links must be up for pri */
3029 if (p_m_mISDNport->l1link || p_m_mISDNport->pri || !p_m_mISDNport->ntmode || p_state!=PORT_STATE_IDLE)
3031 /* LAYER 1 is up, or we may send */
3032 message_setup(epoint_id, message_id, param);
3035 /* LAYER 1 id down, so we queue */
3036 p_m_d_queue = message_create(epoint_id, p_serial, EPOINT_TO_PORT, message_id);
3037 memcpy(&p_m_d_queue->param, param, sizeof(union parameter));
3039 if (!(epointlist_new(epoint_id)))
3041 PERROR("no memory for epointlist\n");
3045 PDEBUG(DEBUG_ISDN, "the L1 is down, we try to establish the link NT portnum=%d (%s).\n", p_m_mISDNport->portnum, p_name);
3046 act.prim = PH_ACTIVATE | REQUEST;
3047 act.addr = p_m_mISDNport->upper_id | FLG_MSG_DOWN;
3050 mISDN_write(mISDNdevice, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
3051 // /* set timeout */
3052 // p_m_mISDNport->l1timeout = now+3;
3056 case MESSAGE_NOTIFY: /* display and notifications */
3057 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);
3058 message_notify(epoint_id, message_id, param);
3061 case MESSAGE_FACILITY: /* facility message */
3062 PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received facility.\n", p_name, p_callerinfo.id);
3063 message_facility(epoint_id, message_id, param);
3066 case MESSAGE_OVERLAP: /* more information is needed */
3067 PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received setup acknowledge\n", p_name, p_callerinfo.id);
3068 if (p_state!=PORT_STATE_IN_SETUP)
3070 PDEBUG(DEBUG_ISDN, "Pdss1(%s) ignoring setup acknowledge because isdn port is not incoming setup state.\n", p_name);
3073 message_overlap(epoint_id, message_id, param);
3076 case MESSAGE_PROCEEDING: /* call of endpoint is proceeding */
3077 PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received proceeding\n", p_name, p_callerinfo.id);
3078 if (p_state!=PORT_STATE_IN_SETUP
3079 && p_state!=PORT_STATE_IN_OVERLAP)
3081 PDEBUG(DEBUG_ISDN, "Pdss1(%s) ignoring: proceeding command not possible in current state.\n", p_name);
3084 message_proceeding(epoint_id, message_id, param);
3087 case MESSAGE_ALERTING: /* call of endpoint is ringing */
3088 PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received alerting\n", p_name, p_callerinfo.id);
3089 if (p_state!=PORT_STATE_IN_SETUP
3090 && p_state!=PORT_STATE_IN_OVERLAP
3091 && p_state!=PORT_STATE_IN_PROCEEDING)
3093 PDEBUG(DEBUG_ISDN, "Pdss1(%s) ignoring: alerting command not possible in current state.\n", p_name);
3096 message_alerting(epoint_id, message_id, param);
3099 case MESSAGE_CONNECT: /* call of endpoint is connected */
3100 PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received connect\n", p_name, p_callerinfo.id);
3101 if (p_state!=PORT_STATE_IN_SETUP
3102 && p_state!=PORT_STATE_IN_OVERLAP
3103 && p_state!=PORT_STATE_IN_PROCEEDING
3104 && p_state!=PORT_STATE_IN_ALERTING
3105 && !(p_state==PORT_STATE_CONNECT && p_m_d_ntmode))
3107 PDEBUG(DEBUG_ISDN, "Pdss1(%s) ignoring: connect command not possible in current state.\n", p_name);
3110 message_connect(epoint_id, message_id, param);
3113 case MESSAGE_DISCONNECT: /* call has been disconnected */
3114 PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received disconnect cause=%d\n", p_name, p_callerinfo.id, param->disconnectinfo.cause);
3115 if (p_state!=PORT_STATE_IN_SETUP
3116 && p_state!=PORT_STATE_IN_OVERLAP
3117 && p_state!=PORT_STATE_IN_PROCEEDING
3118 && p_state!=PORT_STATE_IN_ALERTING
3119 && p_state!=PORT_STATE_OUT_SETUP
3120 && p_state!=PORT_STATE_OUT_OVERLAP
3121 && p_state!=PORT_STATE_OUT_PROCEEDING
3122 && p_state!=PORT_STATE_OUT_ALERTING
3123 && p_state!=PORT_STATE_CONNECT
3124 && p_state!=PORT_STATE_CONNECT_WAITING)
3126 PDEBUG(DEBUG_ISDN, "Pdss1(%s) ignoring: disconnect command not possible in current state.\n", p_name);
3129 message_disconnect(epoint_id, message_id, param);
3132 case MESSAGE_RELEASE: /* release isdn port */
3133 PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received release cause=%d\n", p_name, p_callerinfo.id, param->disconnectinfo.cause);
3134 if (p_state==PORT_STATE_RELEASE)
3136 PDEBUG(DEBUG_ISDN, "Pdss1(%s) ignoring: release command not possible in RELEASE state.\n", p_name);
3139 message_release(epoint_id, message_id, param);
3143 PDEBUG(DEBUG_ISDN, "Pdss1(%s) isdn port with (caller id %s) received a wrong message: %d\n", p_name, p_callerinfo.id, message);
3152 * data from isdn-stack (layer-3) to pbx (port class)
3154 /* NOTE: nt mode use mISDNuser_head_t as header */
3155 int stack2manager_nt(void *dat, void *arg)
3159 manager_t *mgr = (manager_t *)dat;
3160 msg_t *msg = (msg_t *)arg;
3161 mISDNuser_head_t *hh;
3162 struct mISDNport *mISDNport;
3168 /* note: nst is the first data feld of mISDNport */
3169 mISDNport = (struct mISDNport *)mgr->nst;
3171 hh = (mISDNuser_head_t *)msg->data;
3172 PDEBUG(DEBUG_ISDN, "prim(0x%x) dinfo(0x%x) msg->len(%d)\n", hh->prim, hh->dinfo, msg->len);
3174 /* find Port object of type ISDN */
3178 if (port->p_type == PORT_TYPE_DSS1_NT_IN || port->p_type == PORT_TYPE_DSS1_NT_OUT)
3180 pdss1 = (class Pdss1 *)port;
3181 //PDEBUG(DEBUG_ISDN, "comparing dinfo = 0x%x with l3id 0x%x\n", hh->dinfo, pdss1->p_m_d_l3id);
3182 /* check out correct stack */
3183 if (pdss1->p_m_mISDNport == mISDNport)
3184 /* check out correct id */
3185 if ((hh->dinfo&0xffff0000) == (pdss1->p_m_d_l3id&0xffff0000))
3187 /* found port, the message belongs to */
3195 /* if process id is master process, but a child disconnects */
3196 if ((hh->dinfo&0x0000ff00)!=0x0000ff00 && (pdss1->p_m_d_l3id&0x0000ff00)==0x0000ff00 && hh->prim==(CC_DISCONNECT|INDICATION))
3198 /* send special indication for child disconnect */
3199 pdss1->disconnect_ind_i(hh->prim, hh->dinfo, msg->data);
3203 /* if process id and layer 3 id matches */
3204 if (hh->dinfo == pdss1->p_m_d_l3id)
3206 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
3215 case MGR_SHORTSTATUS | INDICATION:
3216 case MGR_SHORTSTATUS | CONFIRM:
3218 case SSTATUS_L2_ESTABLISHED:
3220 case SSTATUS_L2_RELEASED:
3225 case DL_ESTABLISH | INDICATION:
3226 case DL_ESTABLISH | CONFIRM:
3228 PDEBUG(DEBUG_ISDN, "establish data link (DL) NT portnum=%d TEI=%d\n", mISDNport->portnum, hh->dinfo);
3229 if (mISDNport->ptp && hh->dinfo == 0)
3231 if (mISDNport->l2establish)
3233 mISDNport->l2establish = 0;
3234 PDEBUG(DEBUG_ISDN, "the link became active before l2establish timer expiry.\n");
3236 mISDNport->l2link = 1;
3237 if (mISDNport->pri);
3238 mISDNport->l1link = 1; /* this is a hack, we also assume L1 to be active */
3242 case DL_RELEASE | INDICATION:
3243 case DL_RELEASE | CONFIRM:
3245 PDEBUG(DEBUG_ISDN, "release data link (DL) NT portnum=%d TEI=%d\n", mISDNport->portnum, hh->dinfo);
3246 if (mISDNport->ptp && hh->dinfo == 0)
3248 mISDNport->l2link = 0;
3249 time(&mISDNport->l2establish);
3250 PDEBUG(DEBUG_ISDN, "because we are ptp, we set a l2establish timer.\n");
3254 case CC_SETUP | INDICATION:
3255 /* creating port object */
3256 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3257 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0)))
3259 RELEASE_COMPLETE_t *release_complete;
3262 fprintf(stderr, "FATAL ERROR: cannot create port object.\n");
3263 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, hh->dinfo, sizeof(RELEASE_COMPLETE_t), mISDNport->ntmode);
3264 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + mISDN_HEADER_LEN);
3265 enc_ie_cause_standalone(mISDNport->ntmode?&release_complete->CAUSE:NULL, dmsg, (mISDNport->ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47);
3266 msg_queue_tail(&mISDNport->downqueue, dmsg);
3269 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
3272 case CC_RESUME | INDICATION:
3273 /* creating port object */
3274 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3275 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL)))
3277 SUSPEND_REJECT_t *suspend_reject;
3280 fprintf(stderr, "FATAL ERROR: cannot create port object.\n");
3281 dmsg = create_l3msg(CC_SUSPEND_REJECT | REQUEST, MT_SUSPEND_REJECT, hh->dinfo, sizeof(SUSPEND_REJECT_t), mISDNport->ntmode);
3282 suspend_reject = (SUSPEND_REJECT_t *)(dmsg->data + mISDN_HEADER_LEN);
3283 enc_ie_cause_standalone(mISDNport->ntmode?&suspend_reject->CAUSE:NULL, dmsg, (mISDNport->ntmode)?1:0, 47);
3284 msg_queue_tail(&mISDNport->downqueue, dmsg);
3287 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
3290 case CC_RELEASE_CR | INDICATION:
3291 PDEBUG(DEBUG_ISDN, "%s: unhandled message from stack: call ref released (l3id=0x%x)\n", __FUNCTION__, hh->dinfo);
3294 case CC_DISCONNECT | INDICATION:
3298 PDEBUG(DEBUG_ISDN, "%s: unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", __FUNCTION__, hh->prim, hh->dinfo, msg->len);
3305 /* NOTE: te mode use iframe_t as header */
3306 int stack2manager_te(struct mISDNport *mISDNport, msg_t *msg)
3313 if (!msg || !mISDNport)
3315 frm = (iframe_t *)msg->data;
3316 PDEBUG(DEBUG_ISDN, "prim(0x%x) dinfo(0x%x) msg->len(%d)\n", frm->prim, frm->dinfo, msg->len);
3318 /* find Port object of type ISDN */
3322 if (port->p_type == PORT_TYPE_DSS1_TE_IN || port->p_type == PORT_TYPE_DSS1_TE_OUT)
3324 pdss1 = (class Pdss1 *)port;
3325 //PDEBUG(DEBUG_ISDN, "comparing dinfo = 0x%x with l3id 0x%x\n", frm->dinfo, pdss1->p_m_d_l3id);
3326 /* check out correct stack */
3327 if (pdss1->p_m_mISDNport == mISDNport)
3328 /* check out correct id */
3329 if (frm->dinfo == pdss1->p_m_d_l3id)
3331 /* found port, the message belongs to */
3339 pdss1->message_isdn(frm->prim, frm->dinfo, msg->data);
3344 /* process new cr (before setup indication) */
3345 //printf("prim = 0x%x, looking for 0x%x\n",frm->prim, (CC_NEW_CR | INDICATION));
3346 if (frm->prim == (CC_NEW_CR | INDICATION))
3349 /* creating port object */
3350 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3351 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_TE_IN, mISDNport, name, NULL)))
3353 RELEASE_COMPLETE_t *release_complete;
3356 fprintf(stderr, "FATAL ERROR: cannot create port object.\n");
3357 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, frm->dinfo, sizeof(RELEASE_COMPLETE_t), mISDNport->ntmode);
3358 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + mISDN_HEADER_LEN);
3359 enc_ie_cause_standalone(mISDNport->ntmode?&release_complete->CAUSE:NULL, dmsg, (mISDNport->ntmode)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47);
3360 msg_queue_tail(&mISDNport->downqueue, dmsg);
3364 /* l3id will be set from dinfo at message_isdn */
3365 pdss1->message_isdn(frm->prim, frm->dinfo, msg->data);
3370 if (frm->prim == (CC_RELEASE_CR | INDICATION))
3372 PDEBUG(DEBUG_ISDN, "unhandled message from stack: call ref released (l3id=0x%x)\n", frm->dinfo);
3376 PDEBUG(DEBUG_ISDN, "unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", frm->prim, frm->dinfo, msg->len);
3382 * sending message that were queued during L1 activation
3383 * or releasing port if link is down
3385 void setup_queue(struct mISDNport *mISDNport, int link)
3389 struct message *message;
3391 if (!mISDNport->ntmode)
3394 /* check all port objects for pending message */
3398 if ((port->p_type&PORT_CLASS_mISDN_MASK) == PORT_CLASS_mISDN_DSS1)
3400 pdss1 = (class Pdss1 *)port;
3401 if (pdss1->p_m_mISDNport == mISDNport)
3403 if (pdss1->p_m_d_queue)
3407 PDEBUG(DEBUG_ISDN, "the L1 became active, so we send queued message for portnum=%d (%s).\n", mISDNport->portnum, pdss1->p_name);
3408 /* LAYER 1 is up, so we send */
3409 pdss1->message_setup(pdss1->p_m_d_queue->id_from, pdss1->p_m_d_queue->type, &pdss1->p_m_d_queue->param);
3410 message_free(pdss1->p_m_d_queue);
3411 pdss1->p_m_d_queue = NULL;
3414 PDEBUG(DEBUG_ISDN, "the L1 became NOT active, so we release port for portnum=%d (%s).\n", mISDNport->portnum, pdss1->p_name);
3415 message = message_create(pdss1->p_serial, pdss1->p_m_d_queue->id_from, PORT_TO_EPOINT, MESSAGE_RELEASE);
3416 message->param.disconnectinfo.cause = 27;
3417 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
3418 message_put(message);
3419 pdss1->new_state(PORT_STATE_RELEASE);
3420 pdss1->p_m_delete = 1;