1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
10 \*****************************************************************************/
20 #include <sys/ioctl.h>
21 #include <sys/types.h>
25 #include <mISDNuser/net_l2.h>
37 Pdss1::Pdss1(int type, struct mISDNport *mISDNport, char *portname, struct port_settings *settings, int channel, int exclusive) : PmISDN(type, mISDNport, portname, settings, channel, exclusive)
39 p_callerinfo.itype = (mISDNport->ifport->interface->extension)?INFO_ITYPE_ISDN_EXTENSION:INFO_ITYPE_ISDN;
40 p_m_d_ntmode = mISDNport->ntmode;
44 p_m_d_notify_pending = NULL;
45 p_m_d_collect_cause = 0;
46 p_m_d_collect_location = 0;
48 PDEBUG(DEBUG_ISDN, "Created new mISDNPort(%s). Currently %d objects use, %s port #%d\n", portname, mISDNport->use, (mISDNport->ntmode)?"NT":"TE", p_m_portnum);
57 /* remove queued message */
59 message_free(p_m_d_queue);
61 if (p_m_d_notify_pending)
62 message_free(p_m_d_notify_pending);
64 /* check how many processes are left */
65 if (p_m_d_ntmode == 1)
67 if (p_m_mISDNport->nst.layer3->proc)
68 PDEBUG(DEBUG_ISDN, "destroyed mISDNPort(%s). WARNING: There is still a layer 3 process left. Ignore this, if currently are other calls. This message is not an error!\n", p_name);
74 * create layer 3 message
76 static msg_t *create_l3msg(int prim, int mt, int dinfo, int size, int ntmode)
83 size = sizeof(Q931_info_t)+2;
87 dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL);
94 dmsg = alloc_msg(size+256+mISDN_HEADER_LEN+DEFAULT_HEADROOM);
97 memset(msg_put(dmsg,size+mISDN_HEADER_LEN), 0, size+mISDN_HEADER_LEN);
98 frm = (iframe_t *)dmsg->data;
101 qi = (Q931_info_t *)(dmsg->data + mISDN_HEADER_LEN);
107 FATAL("Cannot allocate memory, system overloaded.\n");
108 exit(0); // make gcc happy
111 msg_t *create_l2msg(int prim, int dinfo, int size) /* NT only */
115 dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL);
119 FATAL("Cannot allocate memory, system overloaded.\n");
120 exit(0); // make gcc happy
124 * if we received a first reply to the setup message,
125 * we will check if we have now channel information
126 * return: <0: error, call is released, -cause is given
127 * 0: ok, nothing to do
129 int Pdss1::received_first_reply_to_setup(unsigned long prim, int channel, int exclusive)
132 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
133 RELEASE_COMPLETE_t *release_complete;
136 /* correct exclusive to 0, if no explicit channel was given */
137 if (exclusive<0 || channel<=0)
140 /* select scenario */
141 if (p_m_b_channel && p_m_b_exclusive)
143 /*** we gave an exclusive channel (or if we are done) ***/
145 /* if not first reply, we are done */
146 if (p_state != PORT_STATE_OUT_SETUP)
149 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
150 add_trace("channel", "request", "%d (forced)", p_m_b_channel);
151 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
153 /* if give channel not accepted or not equal */
154 if (channel!=-1 && p_m_b_channel!=channel)
156 add_trace("conclusion", NULL, "forced channel not accepted");
162 add_trace("conclusion", NULL, "channel was accepted");
163 add_trace("connect", "channel", "%d", p_m_b_channel);
166 /* activate our exclusive channel */
167 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
171 /*** we gave a non-exclusive channel ***/
173 /* if not first reply, we are done */
174 if (p_state != PORT_STATE_OUT_SETUP)
177 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
178 add_trace("channel", "request", "%d (suggest)", p_m_b_channel);
179 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
181 /* if channel was accepted as given */
182 if (channel==-1 || p_m_b_channel==channel)
184 add_trace("conclusion", NULL, "channel was accepted as given");
185 add_trace("connect", "channel", "%d", p_m_b_channel);
187 p_m_b_exclusive = 1; // we are done
188 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
192 /* if channel value is faulty */
195 add_trace("conclusion", NULL, "illegal reply");
197 ret = -111; // protocol error
201 /* if channel was not accepted, try to get it */
202 ret = seize_bchannel(channel, 1); // exclusively
203 add_trace("channel", "available", ret<0?"no":"yes");
206 add_trace("conclusion", NULL, "replied channel not available");
210 add_trace("conclusion", NULL, "replied channel accepted");
211 add_trace("connect", "channel", "%d", p_m_b_channel);
214 /* activate channel given by remote */
215 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
219 /*** we sent 'any channel acceptable' ***/
221 /* if not first reply, we are done */
222 if (p_state != PORT_STATE_OUT_SETUP)
225 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
226 add_trace("channel", "request", "any");
227 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
228 /* if no channel was replied */
231 add_trace("conclusion", NULL, "no channel, protocol error");
233 ret = -111; // protocol error
237 /* we will see, if our received channel is available */
238 ret = seize_bchannel(channel, 1); // exclusively
239 add_trace("channel", "available", ret<0?"no":"yes");
242 add_trace("conclusion", NULL, "replied channel not available");
246 add_trace("conclusion", NULL, "replied channel accepted");
247 add_trace("connect", "channel", "%d", p_m_b_channel);
250 /* activate channel given by remote */
251 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
254 /*** we sent 'no channel available' ***/
256 /* if not the first reply, but a connect, we are forced */
257 if (prim==(CC_CONNECT | INDICATION) && p_state!=PORT_STATE_OUT_SETUP)
259 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (connect)", DIRECTION_NONE);
260 add_trace("channel", "request", "no-channel");
261 add_trace("channel", "reply", (channel>=0)?"%d%s":"(none)", channel, exclusive?" (forced)":"");
264 goto use_from_connect;
266 ret = seize_bchannel(CHANNEL_ANY, 0); // any channel
267 add_trace("channel", "available", ret<0?"no":"yes");
270 add_trace("conclusion", NULL, "no channel available during call-waiting");
274 add_trace("conclusion", NULL, "using channel %d", p_m_b_channel);
275 add_trace("connect", "channel", "%d", p_m_b_channel);
277 p_m_b_exclusive = 1; // we are done
279 /* activate channel given by remote */
280 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
284 /* if not first reply, we are done */
285 if (p_state != PORT_STATE_OUT_SETUP)
288 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
289 add_trace("channel", "request", "no-channel");
290 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
291 /* if first reply has no channel, we are done */
294 add_trace("conclusion", NULL, "no channel until connect");
299 /* we will see, if our received channel is available */
301 ret = seize_bchannel(channel, exclusive);
302 add_trace("channel", "available", ret<0?"no":"yes");
305 add_trace("conclusion", NULL, "replied channel not available");
309 add_trace("conclusion", NULL, "replied channel accepted");
310 add_trace("connect", "channel", "%d", p_m_b_channel);
312 p_m_b_exclusive = 1; // we are done
314 /* activate channel given by remote */
315 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
320 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
321 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
322 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
323 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
325 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
326 new_state(PORT_STATE_RELEASE);
328 return(-34); /* to epoint: no channel available */
333 * hunt bchannel for incomming setup or retrieve or resume
335 int Pdss1::hunt_bchannel(int channel, int exclusive)
337 struct select_channel *selchannel;
338 struct interface_port *ifport = p_m_mISDNport->ifport;
341 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (setup)", DIRECTION_NONE);
344 if (channel == CHANNEL_NO)
345 add_trace("channel", "request", "no-channel");
347 add_trace("channel", "request", (channel>0)?"%d%s":"any", channel, exclusive?" (forced)":"");
348 if (channel==CHANNEL_NO && p_type==PORT_TYPE_DSS1_TE_IN)
350 add_trace("conclusion", NULL, "incoming call-waiting not supported for TE-mode");
352 return(-6); // channel unacceptable
354 if (channel <= 0) /* not given, no channel, whatever.. */
355 channel = CHANNEL_ANY; /* any channel */
356 add_trace("channel", "reserved", "%d", p_m_mISDNport->b_reserved);
357 if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num) // of out chan..
359 add_trace("conclusion", NULL, "all channels are reserved");
361 return(-34); // no channel
363 if (channel == CHANNEL_ANY)
367 /* check for given channel in selection list */
368 selchannel = ifport->in_channel;
371 if (selchannel->channel == channel || selchannel->channel == CHANNEL_FREE)
373 selchannel = selchannel->next;
378 /* exclusive channel requests must be in the list */
383 add_trace("conclusion", NULL, "exclusively requested channel not in list");
385 return(-6); // channel unacceptable
387 i = selchannel->channel-1-(selchannel->channel>=17);
388 if (p_m_mISDNport->b_port[i] == NULL)
390 add_trace("conclusion", NULL, "exclusively requested channel is busy");
392 return(-6); // channel unacceptable
395 /* requested channels in list will be used */
398 i = selchannel->channel-1-(selchannel->channel>=17);
399 if (p_m_mISDNport->b_port[i] == NULL)
403 /* if channel is not available or not in list, it must be searched */
405 /* check for first free channel in list */
407 selchannel = ifport->in_channel;
410 switch(selchannel->channel)
412 case CHANNEL_FREE: /* free channel */
413 add_trace("hunting", "channel", "free");
414 if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num)
415 break; /* all channel in use or reserverd */
418 while(i < p_m_mISDNport->b_num)
420 if (p_m_mISDNport->b_port[i] == NULL)
422 channel = i+1+(i>=15);
430 add_trace("hunting", "channel", "%d", selchannel->channel);
431 if (selchannel->channel<1 || selchannel->channel==16)
432 break; /* invalid channels */
433 i = selchannel->channel-1-(selchannel->channel>=17);
434 if (i >= p_m_mISDNport->b_num)
435 break; /* channel not in port */
436 if (p_m_mISDNport->b_port[i] == NULL)
438 channel = selchannel->channel;
444 break; /* found channel */
445 selchannel = selchannel->next;
449 add_trace("conclusion", NULL, "no channel available");
451 return(-6); // channel unacceptable
455 add_trace("conclusion", NULL, "channel available");
456 add_trace("connect", "channel", "%d", channel);
462 * handles all indications
464 /* CC_SETUP INDICATION */
465 void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
467 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
468 SETUP_t *setup = (SETUP_t *)((unsigned long)data + headerlen);
469 int calling_type, calling_plan, calling_present, calling_screen;
470 int called_type, called_plan;
471 int redir_type, redir_plan, redir_present, redir_screen, redir_reason;
472 int hlc_coding, hlc_presentation, hlc_interpretation, hlc_hlc, hlc_exthlc;
473 int bearer_coding, bearer_capability, bearer_mode, bearer_rate, bearer_multi, bearer_user;
474 int exclusive, channel;
477 unsigned char keypad[32] = "";
478 unsigned char useruser[128];
479 int useruser_len = 0, useruser_protocol;
480 class Endpoint *epoint;
481 struct message *message;
483 /* callref from nt-lib */
486 /* nt-library now gives us the id via CC_SETUP */
487 if (dinfo&(~0xff) == 0xff00)
488 FATAL("l3-stack gives us a process id 0xff00-0xffff\n");
489 l1l2l3_trace_header(p_m_mISDNport, this, CC_NEW_CR | INDICATION, DIRECTION_IN);
491 add_trace("callref", "old", "0x%x", p_m_d_l3id);
492 add_trace("callref", "new", "0x%x", dinfo);
494 if (p_m_d_l3id&(~0xff) == 0xff00)
495 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
497 p_m_d_ces = setup->ces;
500 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
501 dec_ie_calling_pn(setup->CALLING_PN, (Q931_info_t *)((unsigned long)data+headerlen), &calling_type, &calling_plan, &calling_present, &calling_screen, (unsigned char *)p_callerinfo.id, sizeof(p_callerinfo.id));
502 dec_ie_called_pn(setup->CALLED_PN, (Q931_info_t *)((unsigned long)data+headerlen), &called_type, &called_plan, (unsigned char *)p_dialinginfo.id, sizeof(p_dialinginfo.id));
503 dec_ie_keypad(setup->KEYPAD, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)keypad, sizeof(keypad));
505 /* te-mode: CNIP (calling name identification presentation) */
507 dec_facility_centrex(setup->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)p_callerinfo.name, sizeof(p_callerinfo.name));
509 dec_ie_useruser(setup->USER_USER, (Q931_info_t *)((unsigned long)data+headerlen), &useruser_protocol, useruser, &useruser_len);
510 dec_ie_complete(setup->COMPLETE, (Q931_info_t *)((unsigned long)data+headerlen), &p_dialinginfo.sending_complete);
511 dec_ie_redir_nr(setup->REDIR_NR, (Q931_info_t *)((unsigned long)data+headerlen), &redir_type, &redir_plan, &redir_present, &redir_screen, &redir_reason, (unsigned char *)p_redirinfo.id, sizeof(p_redirinfo.id));
512 dec_ie_channel_id(setup->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
513 dec_ie_hlc(setup->HLC, (Q931_info_t *)((unsigned long)data+headerlen), &hlc_coding, &hlc_interpretation, &hlc_presentation, &hlc_hlc, &hlc_exthlc);
514 dec_ie_bearer(setup->BEARER, (Q931_info_t *)((unsigned long)data+headerlen), &bearer_coding, &bearer_capability, &bearer_mode, &bearer_rate, &bearer_multi, &bearer_user);
517 /* if blocked, release call */
518 if (p_m_mISDNport->ifport->block)
520 RELEASE_COMPLETE_t *release_complete;
522 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
523 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
524 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
525 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 27); /* temporary unavailable */
526 add_trace("reason", NULL, "port blocked");
528 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
529 new_state(PORT_STATE_RELEASE);
535 switch (calling_present)
538 p_callerinfo.present = INFO_PRESENT_RESTRICTED;
541 p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
544 p_callerinfo.present = INFO_PRESENT_ALLOWED;
547 switch (calling_screen)
550 p_callerinfo.screen = INFO_SCREEN_USER;
553 p_callerinfo.screen = INFO_SCREEN_NETWORK;
556 switch (calling_type)
559 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
560 p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
561 p_callerinfo.screen = INFO_SCREEN_NETWORK;
564 p_callerinfo.ntype = INFO_NTYPE_INTERNATIONAL;
567 p_callerinfo.ntype = INFO_NTYPE_NATIONAL;
570 p_callerinfo.ntype = INFO_NTYPE_SUBSCRIBER;
573 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
576 p_callerinfo.isdn_port = p_m_portnum;
577 SCPY(p_callerinfo.interface, p_m_mISDNport->ifport->interface->name);
579 /* dialing information */
580 SCAT(p_dialinginfo.id, (char *)keypad);
584 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
587 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
590 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
593 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
598 switch (redir_present)
601 p_redirinfo.present = INFO_PRESENT_RESTRICTED;
604 p_redirinfo.present = INFO_PRESENT_NOTAVAIL;
607 p_redirinfo.present = INFO_PRESENT_ALLOWED;
610 switch (redir_screen)
613 p_redirinfo.screen = INFO_SCREEN_USER;
616 p_redirinfo.screen = INFO_SCREEN_NETWORK;
619 switch (redir_reason)
622 p_redirinfo.reason = INFO_REDIR_BUSY;
625 p_redirinfo.reason = INFO_REDIR_NORESPONSE;
628 p_redirinfo.reason = INFO_REDIR_UNCONDITIONAL;
631 p_redirinfo.reason = INFO_REDIR_CALLDEFLECT;
634 p_redirinfo.reason = INFO_REDIR_OUTOFORDER;
637 p_redirinfo.reason = INFO_REDIR_UNKNOWN;
643 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
644 p_redirinfo.present = INFO_PRESENT_NULL; /* not redirecting */
645 p_redirinfo.reason = INFO_REDIR_UNKNOWN;
648 p_redirinfo.ntype = INFO_NTYPE_INTERNATIONAL;
651 p_redirinfo.ntype = INFO_NTYPE_NATIONAL;
654 p_redirinfo.ntype = INFO_NTYPE_SUBSCRIBER;
657 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
660 p_redirinfo.isdn_port = p_m_portnum;
662 /* bearer capability */
663 switch (bearer_capability)
666 p_capainfo.bearer_capa = INFO_BC_AUDIO;
667 bearer_user = (options.law=='a')?3:2;
670 p_capainfo.bearer_capa = bearer_capability;
676 p_capainfo.bearer_mode = INFO_BMODE_PACKET;
679 p_capainfo.bearer_mode = INFO_BMODE_CIRCUIT;
685 p_capainfo.bearer_info1 = INFO_INFO1_NONE;
688 p_capainfo.bearer_info1 = bearer_user + 0x80;
696 p_capainfo.hlc = INFO_HLC_NONE;
699 p_capainfo.hlc = hlc_hlc + 0x80;
705 p_capainfo.exthlc = INFO_HLC_NONE;
708 p_capainfo.exthlc = hlc_exthlc + 0x80;
713 ret = channel = hunt_bchannel(channel, exclusive);
718 ret = seize_bchannel(channel, 1);
722 RELEASE_COMPLETE_t *release_complete;
724 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
725 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
726 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
727 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
729 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
730 new_state(PORT_STATE_RELEASE);
734 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
736 /* create endpoint */
738 FATAL("Incoming call but already got an endpoint.\n");
739 if (!(epoint = new Endpoint(p_serial, 0)))
740 FATAL("No memory for Endpoint instance\n");
741 if (!(epoint->ep_app = new DEFAULT_ENDPOINT_APP(epoint, 0))) //incomming
742 FATAL("No memory for Endpoint Application instance\n");
743 epointlist_new(epoint->ep_serial);
745 /* send setup message to endpoit */
746 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_SETUP);
747 message->param.setup.isdn_port = p_m_portnum;
748 message->param.setup.port_type = p_type;
749 message->param.setup.dtmf = !p_m_mISDNport->ifport->nodtmf;
750 memcpy(&message->param.setup.dialinginfo, &p_dialinginfo, sizeof(struct dialing_info));
751 memcpy(&message->param.setup.callerinfo, &p_callerinfo, sizeof(struct caller_info));
752 memcpy(&message->param.setup.redirinfo, &p_redirinfo, sizeof(struct redir_info));
753 memcpy(&message->param.setup.capainfo, &p_capainfo, sizeof(struct capa_info));
754 memcpy(message->param.setup.useruser.data, &useruser, useruser_len);
755 message->param.setup.useruser.len = useruser_len;
756 message->param.setup.useruser.protocol = useruser_protocol;
757 message_put(message);
759 new_state(PORT_STATE_IN_SETUP);
762 /* CC_INFORMATION INDICATION */
763 void Pdss1::information_ind(unsigned long prim, unsigned long dinfo, void *data)
765 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
766 INFORMATION_t *information = (INFORMATION_t *)((unsigned long)data + headerlen);
768 unsigned char keypad[32] = "";
769 struct message *message;
771 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
772 dec_ie_called_pn(information->CALLED_PN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, (unsigned char *)p_dialinginfo.id, sizeof(p_dialinginfo.id));
773 dec_ie_keypad(information->KEYPAD, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)keypad, sizeof(keypad));
774 dec_ie_complete(information->COMPLETE, (Q931_info_t *)((unsigned long)data+headerlen), &p_dialinginfo.sending_complete);
777 SCAT(p_dialinginfo.id, (char *)keypad);
781 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
784 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
787 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
790 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
793 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_INFORMATION);
794 memcpy(&message->param.information, &p_dialinginfo, sizeof(struct dialing_info));
795 message_put(message);
796 /* reset overlap timeout */
800 /* CC_SETUP_ACCNOWLEDGE INDICATION */
801 void Pdss1::setup_acknowledge_ind(unsigned long prim, unsigned long dinfo, void *data)
803 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
804 SETUP_ACKNOWLEDGE_t *setup_acknowledge = (SETUP_ACKNOWLEDGE_t *)((unsigned long)data + headerlen);
805 int exclusive, channel;
806 int coding, location, progress;
808 struct message *message;
810 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
811 dec_ie_channel_id(setup_acknowledge->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
812 dec_ie_progress(setup_acknowledge->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
815 /* process channel */
816 ret = received_first_reply_to_setup(prim, channel, exclusive);
819 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
820 message->param.disconnectinfo.cause = -ret;
821 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
822 message_put(message);
823 new_state(PORT_STATE_RELEASE);
828 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_OVERLAP);
829 message_put(message);
831 new_state(PORT_STATE_OUT_OVERLAP);
834 /* CC_PROCEEDING INDICATION */
835 void Pdss1::proceeding_ind(unsigned long prim, unsigned long dinfo, void *data)
837 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
838 CALL_PROCEEDING_t *proceeding = (CALL_PROCEEDING_t *)((unsigned long)data + headerlen);
839 int exclusive, channel;
840 int coding, location, progress;
842 struct message *message;
843 int notify = -1, type, plan, present;
846 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
847 dec_ie_channel_id(proceeding->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
848 dec_ie_progress(proceeding->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
849 dec_ie_notify(NULL/*proceeding->NOTIFY*/, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
850 dec_ie_redir_dn(proceeding->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
853 ret = received_first_reply_to_setup(prim, channel, exclusive);
856 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
857 message->param.disconnectinfo.cause = -ret;
858 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
859 message_put(message);
860 new_state(PORT_STATE_RELEASE);
864 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROCEEDING);
865 message_put(message);
867 new_state(PORT_STATE_OUT_PROCEEDING);
873 if (type >= 0 || notify)
875 if (!notify && type >= 0)
877 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
878 message->param.notifyinfo.notify = notify;
879 SCPY(message->param.notifyinfo.id, redir);
880 /* redirection number */
884 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
887 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
890 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
896 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
897 message->param.notifyinfo.present = INFO_PRESENT_NULL;
900 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
903 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
906 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
909 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
912 message->param.notifyinfo.isdn_port = p_m_portnum;
913 message_put(message);
917 /* CC_ALERTING INDICATION */
918 void Pdss1::alerting_ind(unsigned long prim, unsigned long dinfo, void *data)
920 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
921 ALERTING_t *alerting = (ALERTING_t *)((unsigned long)data + headerlen);
922 int exclusive, channel;
923 int coding, location, progress;
925 struct message *message;
926 int notify = -1, type, plan, present;
929 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
930 dec_ie_channel_id(alerting->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
931 dec_ie_progress(alerting->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
932 dec_ie_notify(NULL/*alerting->NOTIFY*/, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
933 dec_ie_redir_dn(alerting->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
936 /* process channel */
937 ret = received_first_reply_to_setup(prim, channel, exclusive);
940 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
941 message->param.disconnectinfo.cause = -ret;
942 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
943 message_put(message);
944 new_state(PORT_STATE_RELEASE);
948 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_ALERTING);
949 message_put(message);
951 new_state(PORT_STATE_OUT_ALERTING);
957 if (type >= 0 || notify)
959 if (!notify && type >= 0)
961 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
962 message->param.notifyinfo.notify = notify;
963 SCPY(message->param.notifyinfo.id, redir);
967 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
970 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
973 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
979 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
980 message->param.notifyinfo.present = INFO_PRESENT_NULL;
983 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
986 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
989 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
992 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
995 message->param.notifyinfo.isdn_port = p_m_portnum;
996 message_put(message);
1000 /* CC_CONNECT INDICATION */
1001 void Pdss1::connect_ind(unsigned long prim, unsigned long dinfo, void *data)
1003 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1004 CONNECT_t *connect = (CONNECT_t *)((unsigned long)data + headerlen);
1005 int exclusive, channel;
1006 int type, plan, present, screen;
1009 struct message *message;
1010 int bchannel_before;
1011 CONNECT_ACKNOWLEDGE_t *connect_acknowledge;
1014 p_m_d_ces = connect->ces;
1016 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1017 dec_ie_channel_id(connect->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
1018 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));
1020 /* te-mode: CONP (connected name identification presentation) */
1022 dec_facility_centrex(connect->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)p_connectinfo.name, sizeof(p_connectinfo.name));
1026 /* select channel */
1027 bchannel_before = p_m_b_channel;
1028 ret = received_first_reply_to_setup(prim, channel, exclusive);
1031 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1032 message->param.disconnectinfo.cause = -ret;
1033 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1034 message_put(message);
1035 new_state(PORT_STATE_RELEASE);
1040 /* connect information */
1044 p_connectinfo.present = INFO_PRESENT_RESTRICTED;
1047 p_connectinfo.present = INFO_PRESENT_NOTAVAIL;
1050 p_connectinfo.present = INFO_PRESENT_ALLOWED;
1056 p_connectinfo.screen = INFO_SCREEN_USER;
1059 p_connectinfo.screen = INFO_SCREEN_NETWORK;
1065 p_connectinfo.present = INFO_PRESENT_NULL; /* no COLP info */
1066 p_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1069 p_connectinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1072 p_connectinfo.ntype = INFO_NTYPE_NATIONAL;
1075 p_connectinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1078 p_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1081 p_connectinfo.isdn_port = p_m_portnum;
1082 SCPY(p_connectinfo.interface, p_m_mISDNport->ifport->interface->name);
1084 /* only in nt-mode we send connect ack. in te-mode it is done by stack itself or optional */
1087 /* send connect acknowledge */
1088 dmsg = create_l3msg(CC_CONNECT | RESPONSE, MT_CONNECT, dinfo, sizeof(CONNECT_ACKNOWLEDGE_t), p_m_d_ntmode);
1089 connect_acknowledge = (CONNECT_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1090 l1l2l3_trace_header(p_m_mISDNport, this, CC_CONNECT | RESPONSE, DIRECTION_OUT);
1091 /* if we had no bchannel before, we send it now */
1092 if (!bchannel_before && p_m_b_channel)
1093 enc_ie_channel_id(&connect_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
1095 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1098 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CONNECT);
1099 memcpy(&message->param.connectinfo, &p_connectinfo, sizeof(struct connect_info));
1100 message_put(message);
1102 new_state(PORT_STATE_CONNECT);
1105 /* CC_DISCONNECT INDICATION */
1106 void Pdss1::disconnect_ind(unsigned long prim, unsigned long dinfo, void *data)
1108 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1109 DISCONNECT_t *disconnect = (DISCONNECT_t *)((unsigned long)data + headerlen);
1110 int location, cause;
1111 int coding, proglocation, progress;
1112 struct message *message;
1114 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1115 dec_ie_progress(disconnect->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &proglocation, &progress);
1116 dec_ie_cause(disconnect->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1118 if (location == LOCATION_PRIVATE_LOCAL)
1119 location = LOCATION_PRIVATE_REMOTE;
1124 /* release if remote sends us no tones */
1125 if (!p_m_mISDNport->earlyb)
1130 dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, dinfo, sizeof(RELEASE_t), p_m_d_ntmode);
1131 release = (RELEASE_t *)(dmsg->data + headerlen);
1132 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE | REQUEST, DIRECTION_OUT);
1133 enc_ie_cause(&release->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16); /* normal */
1134 add_trace("reason", NULL, "no remote patterns");
1136 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1138 /* sending release to endpoint */
1141 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1142 message->param.disconnectinfo.cause = cause;
1143 message->param.disconnectinfo.location = location;
1144 message_put(message);
1146 free_epointlist(p_epointlist);
1148 new_state(PORT_STATE_RELEASE);
1153 /* sending disconnect to active endpoint and release to inactive endpoints */
1154 if (ACTIVE_EPOINT(p_epointlist))
1156 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DISCONNECT);
1157 message->param.disconnectinfo.location = location;
1158 message->param.disconnectinfo.cause = cause;
1159 message_put(message);
1161 while(INACTIVE_EPOINT(p_epointlist))
1163 message = message_create(p_serial, INACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1164 message->param.disconnectinfo.location = location;
1165 message->param.disconnectinfo.cause = cause;
1166 message_put(message);
1168 free_epointid(INACTIVE_EPOINT(p_epointlist));
1170 new_state(PORT_STATE_IN_DISCONNECT);
1173 /* CC_DISCONNECT INDICATION */
1174 void Pdss1::disconnect_ind_i(unsigned long prim, unsigned long dinfo, void *data)
1176 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1177 DISCONNECT_t *disconnect = (DISCONNECT_t *)((unsigned long)data + headerlen);
1178 int location, cause;
1181 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1182 if (p_m_d_collect_cause > 0)
1184 add_trace("old-cause", "location", "%d", p_m_d_collect_location);
1185 add_trace("old-cause", "value", "%d", p_m_d_collect_cause);
1187 dec_ie_cause(disconnect->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1188 if (location == LOCATION_PRIVATE_LOCAL)
1189 location = LOCATION_PRIVATE_REMOTE;
1192 collect_cause(&p_m_d_collect_cause, &p_m_d_collect_location, cause, location);
1193 add_trace("new-cause", "location", "%d", p_m_d_collect_location);
1194 add_trace("new-cause", "value", "%d", p_m_d_collect_cause);
1199 /* CC_RELEASE INDICATION */
1200 void Pdss1::release_ind(unsigned long prim, unsigned long dinfo, void *data)
1202 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1203 RELEASE_t *release = (RELEASE_t *)((unsigned long)data + headerlen);
1205 int location, cause;
1206 struct message *message;
1208 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1209 dec_ie_cause(release->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1211 if (location == LOCATION_PRIVATE_LOCAL)
1212 location = LOCATION_PRIVATE_REMOTE;
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);
1228 /* only in NT mode we must send release_complete, if we got a release confirm */
1229 if (prim == (CC_RELEASE | CONFIRM))
1231 /* sending release complete */
1232 RELEASE_COMPLETE_t *release_complete;
1234 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
1235 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
1236 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
1237 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16);
1239 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1242 new_state(PORT_STATE_RELEASE);
1246 /* CC_RELEASE_COMPLETE INDICATION (a reject) */
1247 void Pdss1::release_complete_ind(unsigned long prim, unsigned long dinfo, void *data)
1249 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1250 RELEASE_COMPLETE_t *release_complete = (RELEASE_COMPLETE_t *)((unsigned long)data + headerlen);
1251 int location, cause;
1252 struct message *message;
1254 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1255 dec_ie_cause(release_complete->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1257 if (location == LOCATION_PRIVATE_LOCAL)
1258 location = LOCATION_PRIVATE_REMOTE;
1263 /* sending release to endpoint */
1266 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1267 message->param.disconnectinfo.cause = cause;
1268 message->param.disconnectinfo.location = location;
1269 message_put(message);
1271 free_epointlist(p_epointlist);
1274 new_state(PORT_STATE_RELEASE);
1279 void Pdss1::t312_timeout(unsigned long prim, unsigned long dinfo, void *data)
1281 struct message *message;
1283 // trace is done at message_isdn()
1285 /* sending release to endpoint */
1288 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1289 if (p_m_d_collect_cause)
1291 message->param.disconnectinfo.cause = p_m_d_collect_cause;
1292 message->param.disconnectinfo.location = p_m_d_collect_location;
1295 message->param.disconnectinfo.cause = CAUSE_NOUSER;
1296 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1298 message_put(message);
1300 free_epointlist(p_epointlist);
1303 new_state(PORT_STATE_RELEASE);
1307 /* CC_NOTIFY INDICATION */
1308 void Pdss1::notify_ind(unsigned long prim, unsigned long dinfo, void *data)
1310 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1311 NOTIFY_t *notifying = (NOTIFY_t *)((unsigned long)data + headerlen);
1312 struct message *message;
1313 int notify, type, plan, present;
1314 unsigned char notifyid[sizeof(message->param.notifyinfo.id)];
1316 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1317 dec_ie_notify(notifying->NOTIFY, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
1318 dec_ie_redir_dn(notifying->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, notifyid, sizeof(notifyid));
1321 if (!ACTIVE_EPOINT(p_epointlist))
1323 /* notification indicator */
1327 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1328 message->param.notifyinfo.notify = notify;
1329 SCPY(message->param.notifyinfo.id, (char *)notifyid);
1330 /* redirection number */
1334 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1337 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1340 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1346 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1347 message->param.notifyinfo.present = INFO_PRESENT_NULL;
1350 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1353 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1356 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1359 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1362 message->param.notifyinfo.isdn_port = p_m_portnum;
1363 message_put(message);
1367 /* CC_HOLD INDICATION */
1368 void Pdss1::hold_ind(unsigned long prim, unsigned long dinfo, void *data)
1370 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1371 // HOLD_t *hold = (HOLD_t *)((unsigned long)data + headerlen);
1372 struct message *message;
1373 HOLD_REJECT_t *hold_reject;
1374 HOLD_ACKNOWLEDGE_t *hold_acknowledge;
1376 // class Endpoint *epoint;
1378 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1381 if (!ACTIVE_EPOINT(p_epointlist) || p_m_hold)
1383 dmsg = create_l3msg(CC_HOLD_REJECT | REQUEST, MT_HOLD_REJECT, dinfo, sizeof(HOLD_REJECT_t), p_m_d_ntmode);
1384 hold_reject = (HOLD_REJECT_t *)(dmsg->data + headerlen);
1385 l1l2l3_trace_header(p_m_mISDNport, this, CC_HOLD_REJECT | REQUEST, DIRECTION_OUT);
1386 enc_ie_cause(&hold_reject->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, p_m_hold?101:31); /* normal unspecified / incompatible state */
1387 add_trace("reason", NULL, "no endpoint");
1389 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1394 /* notify the hold of call */
1395 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1396 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_HOLD;
1397 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1398 message_put(message);
1400 /* deactivate bchannel */
1401 chan_trace_header(p_m_mISDNport, this, "CHANNEL RELEASE (hold)", DIRECTION_NONE);
1402 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1406 /* set hold state */
1409 epoint = find_epoint_id(ACTIVE_EPOINT(p_epointlist));
1410 if (epoint && p_m_d_ntmode)
1412 p_m_timeout = p_settings.tout_hold;
1417 /* acknowledge hold */
1418 dmsg = create_l3msg(CC_HOLD_ACKNOWLEDGE | REQUEST, MT_HOLD_ACKNOWLEDGE, dinfo, sizeof(HOLD_ACKNOWLEDGE_t), p_m_d_ntmode);
1419 hold_acknowledge = (HOLD_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1420 l1l2l3_trace_header(p_m_mISDNport, this, CC_HOLD_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1422 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1426 /* CC_RETRIEVE INDICATION */
1427 void Pdss1::retrieve_ind(unsigned long prim, unsigned long dinfo, void *data)
1429 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1430 RETRIEVE_t *retrieve = (RETRIEVE_t *)((unsigned long)data + headerlen);
1431 RETRIEVE_REJECT_t *retrieve_reject;
1432 RETRIEVE_ACKNOWLEDGE_t *retrieve_acknowledge;
1433 struct message *message;
1434 int channel, exclusive, cause;
1438 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1439 dec_ie_channel_id(retrieve->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
1444 cause = 101; /* incompatible state */
1447 dmsg = create_l3msg(CC_RETRIEVE_REJECT | REQUEST, MT_RETRIEVE_REJECT, dinfo, sizeof(RETRIEVE_REJECT_t), p_m_d_ntmode);
1448 retrieve_reject = (RETRIEVE_REJECT_t *)(dmsg->data + headerlen);
1449 l1l2l3_trace_header(p_m_mISDNport, this, CC_RETRIEVE_REJECT | REQUEST, DIRECTION_OUT);
1450 enc_ie_cause(&retrieve_reject->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, cause);
1452 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1457 /* notify the retrieve of call */
1458 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1459 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_RETRIEVAL;
1460 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1461 message_put(message);
1464 ret = channel = hunt_bchannel(channel, exclusive);
1469 ret = seize_bchannel(channel, 1);
1476 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
1478 /* set hold state */
1482 /* acknowledge retrieve */
1483 dmsg = create_l3msg(CC_RETRIEVE_ACKNOWLEDGE | REQUEST, MT_RETRIEVE_ACKNOWLEDGE, dinfo, sizeof(RETRIEVE_ACKNOWLEDGE_t), p_m_d_ntmode);
1484 retrieve_acknowledge = (RETRIEVE_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1485 l1l2l3_trace_header(p_m_mISDNport, this, CC_RETRIEVE_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1486 enc_ie_channel_id(&retrieve_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
1488 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1491 /* CC_SUSPEND INDICATION */
1492 void Pdss1::suspend_ind(unsigned long prim, unsigned long dinfo, void *data)
1494 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1495 SUSPEND_t *suspend = (SUSPEND_t *)((unsigned long)data + headerlen);
1496 SUSPEND_ACKNOWLEDGE_t *suspend_acknowledge;
1497 SUSPEND_REJECT_t *suspend_reject;
1498 struct message *message;
1499 class Endpoint *epoint;
1500 unsigned char callid[8];
1503 int ret = -31; /* normal, unspecified */
1505 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1506 dec_ie_call_id(suspend->CALL_ID, (Q931_info_t *)((unsigned long)data+headerlen), callid, &len);
1509 if (!ACTIVE_EPOINT(p_epointlist))
1512 dmsg = create_l3msg(CC_SUSPEND_REJECT | REQUEST, MT_SUSPEND_REJECT, dinfo, sizeof(SUSPEND_REJECT_t), p_m_d_ntmode);
1513 suspend_reject = (SUSPEND_REJECT_t *)(dmsg->data + headerlen);
1514 l1l2l3_trace_header(p_m_mISDNport, this, CC_SUSPEND_REJECT | REQUEST, DIRECTION_OUT);
1515 enc_ie_cause(&suspend_reject->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1517 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1525 /* check if call id is in use */
1526 epoint = epoint_first;
1529 if (epoint->ep_park)
1531 if (epoint->ep_park_len == len)
1532 if (!memcmp(epoint->ep_park_callid, callid, len))
1534 ret = -84; /* call id in use */
1538 epoint = epoint->next;
1541 /* notify the hold of call */
1542 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1543 message->param.notifyinfo.notify = INFO_NOTIFY_USER_SUSPENDED;
1544 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1545 message_put(message);
1547 /* deactivate bchannel */
1548 chan_trace_header(p_m_mISDNport, this, "CHANNEL RELEASE (suspend)", DIRECTION_NONE);
1549 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1553 /* sending suspend to endpoint */
1554 while (p_epointlist)
1556 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_SUSPEND);
1557 memcpy(message->param.parkinfo.callid, callid, sizeof(message->param.parkinfo.callid));
1558 message->param.parkinfo.len = len;
1559 message_put(message);
1561 free_epointlist(p_epointlist);
1564 /* sending SUSPEND_ACKNOWLEDGE */
1565 dmsg = create_l3msg(CC_SUSPEND_ACKNOWLEDGE | REQUEST, MT_SUSPEND_ACKNOWLEDGE, dinfo, sizeof(SUSPEND_ACKNOWLEDGE_t), p_m_d_ntmode);
1566 suspend_acknowledge = (SUSPEND_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1567 l1l2l3_trace_header(p_m_mISDNport, this, CC_SUSPEND_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1569 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1571 new_state(PORT_STATE_RELEASE);
1575 /* CC_RESUME INDICATION */
1576 void Pdss1::resume_ind(unsigned long prim, unsigned long dinfo, void *data)
1578 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1579 RESUME_t *resume = (RESUME_t *)((unsigned long)data + headerlen);
1580 RESUME_REJECT_t *resume_reject;
1581 RESUME_ACKNOWLEDGE_t *resume_acknowledge;
1582 unsigned char callid[8];
1584 int channel, exclusive;
1586 class Endpoint *epoint;
1587 struct message *message;
1590 /* callref from nt-lib */
1593 /* nt-library now gives us the id via CC_RESUME */
1594 if (dinfo&(~0xff) == 0xff00)
1595 FATAL("l3-stack gives us a process id 0xff00-0xffff\n");
1596 l1l2l3_trace_header(p_m_mISDNport, this, CC_NEW_CR | INDICATION, DIRECTION_IN);
1598 add_trace("callref", "old", "0x%x", p_m_d_l3id);
1599 add_trace("callref", "new", "0x%x", dinfo);
1601 if (p_m_d_l3id&(~0xff) == 0xff00)
1602 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
1604 p_m_d_ces = resume->ces;
1607 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1608 dec_ie_call_id(resume->CALL_ID, (Q931_info_t *)((unsigned long)data+headerlen), callid, &len);
1611 /* if blocked, release call */
1612 if (p_m_mISDNport->ifport->block)
1621 /* channel_id (no channel is possible in message) */
1623 channel = -1; /* any channel */
1626 ret = channel = hunt_bchannel(channel, exclusive);
1631 ret = seize_bchannel(channel, 1);
1636 dmsg = create_l3msg(CC_RESUME_REJECT | REQUEST, MT_RESUME_REJECT, dinfo, sizeof(RESUME_REJECT_t), p_m_d_ntmode);
1637 resume_reject = (RESUME_REJECT_t *)(dmsg->data + headerlen);
1638 l1l2l3_trace_header(p_m_mISDNport, this, CC_RESUME_REJECT | REQUEST, DIRECTION_OUT);
1639 enc_ie_cause(&resume_reject->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1641 add_trace("reason", NULL, "port blocked");
1643 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1644 new_state(PORT_STATE_RELEASE);
1648 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
1650 /* create endpoint */
1652 FATAL("Incoming resume but already got an endpoint.\n");
1653 ret = -85; /* no call suspended */
1654 epoint = epoint_first;
1657 if (epoint->ep_park)
1659 ret = -83; /* suspended call exists, but this not */
1660 if (epoint->ep_park_len == len)
1661 if (!memcmp(epoint->ep_park_callid, callid, len))
1664 epoint = epoint->next;
1669 epointlist_new(epoint->ep_serial);
1670 if (!(epoint->portlist_new(p_serial, p_type, p_m_mISDNport->earlyb)))
1671 FATAL("No memory for portlist\n");
1672 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RESUME);
1673 message_put(message);
1675 /* notify the resume of call */
1676 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1677 message->param.notifyinfo.notify = INFO_NOTIFY_USER_RESUMED;
1678 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1679 message_put(message);
1681 /* sending RESUME_ACKNOWLEDGE */
1682 dmsg = create_l3msg(CC_RESUME_ACKNOWLEDGE | REQUEST, MT_RESUME_ACKNOWLEDGE, dinfo, sizeof(RESUME_ACKNOWLEDGE_t), p_m_d_ntmode);
1683 resume_acknowledge = (RESUME_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1684 l1l2l3_trace_header(p_m_mISDNport, this, CC_RESUME_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1685 enc_ie_channel_id(&resume_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
1687 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1689 new_state(PORT_STATE_CONNECT);
1693 /* CC_FACILITY INDICATION */
1694 void Pdss1::facility_ind(unsigned long prim, unsigned long dinfo, void *data)
1696 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1697 FACILITY_t *facility = (FACILITY_t *)((unsigned long)data + headerlen);
1698 unsigned char facil[256];
1700 struct message *message;
1702 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1703 dec_ie_facility(facility->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), facil, &facil_len);
1710 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_FACILITY);
1711 message->param.facilityinfo.len = facil_len;
1712 memcpy(message->param.facilityinfo.data, facil, facil_len);
1713 message_put(message);
1718 * handler for isdn connections
1719 * incoming information are parsed and sent via message to the endpoint
1721 void Pdss1::message_isdn(unsigned long prim, unsigned long dinfo, void *data)
1728 case CC_TIMEOUT | INDICATION:
1731 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1732 timer_hex = *((int *)(((char *)data)+headerlen));
1734 if (timer_hex==0x312 && p_m_d_ntmode)
1736 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1737 add_trace("timer", NULL, "%x", timer_hex);
1739 t312_timeout(prim, dinfo, data);
1743 case CC_SETUP | INDICATION:
1744 if (p_state != PORT_STATE_IDLE)
1746 setup_ind(prim, dinfo, data);
1749 case CC_SETUP | CONFIRM:
1752 l1l2l3_trace_header(p_m_mISDNport, this, CC_NEW_CR | INDICATION, DIRECTION_IN);
1753 add_trace("callref", "old", "0x%x", p_m_d_l3id);
1754 /* nt-library now gives us a new id via CC_SETUP_CONFIRM */
1755 if ((p_m_d_l3id&0xff00) != 0xff00)
1756 PERROR(" strange setup-procid 0x%x\n", p_m_d_l3id);
1757 p_m_d_l3id = *((int *)(((u_char *)data)+ mISDNUSER_HEAD_SIZE));
1758 add_trace("callref", "new", "0x%x", p_m_d_l3id);
1763 case CC_INFORMATION | INDICATION:
1764 information_ind(prim, dinfo, data);
1767 case CC_SETUP_ACKNOWLEDGE | INDICATION:
1768 if (p_state != PORT_STATE_OUT_SETUP)
1770 PERROR("Pdss1(%s) received setup_acknowledge, but we are not in outgoing setup state, IGNORING.\n", p_name);
1773 setup_acknowledge_ind(prim, dinfo, data);
1776 case CC_PROCEEDING | INDICATION:
1777 if (p_state != PORT_STATE_OUT_SETUP
1778 && p_state != PORT_STATE_OUT_OVERLAP)
1780 PERROR("Pdss1(%s) received proceeding, but we are not in outgoing setup OR overlap state, IGNORING.\n", p_name);
1783 proceeding_ind(prim, dinfo, data);
1786 case CC_ALERTING | INDICATION:
1787 if (p_state != PORT_STATE_OUT_SETUP
1788 && p_state != PORT_STATE_OUT_OVERLAP
1789 && p_state != PORT_STATE_OUT_PROCEEDING)
1791 PERROR("Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding state, IGNORING.\n", p_name);
1794 alerting_ind(prim, dinfo, data);
1797 case CC_CONNECT | INDICATION:
1798 if (p_state != PORT_STATE_OUT_SETUP
1799 && p_state != PORT_STATE_OUT_OVERLAP
1800 && p_state != PORT_STATE_OUT_PROCEEDING
1801 && p_state != PORT_STATE_OUT_ALERTING)
1803 PERROR("Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding OR ALERTING state, IGNORING.\n", p_name);
1806 connect_ind(prim, dinfo, data);
1807 if (p_m_d_notify_pending)
1809 /* send pending notify message during connect */
1810 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
1811 message_free(p_m_d_notify_pending);
1812 p_m_d_notify_pending = NULL;
1816 case CC_CONNECT_ACKNOWLEDGE | INDICATION:
1817 case CC_CONNECT | CONFIRM:
1818 if (p_state == PORT_STATE_CONNECT_WAITING)
1819 new_state(PORT_STATE_CONNECT);
1820 if (p_m_d_notify_pending)
1822 /* send pending notify message during connect-ack */
1823 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
1824 message_free(p_m_d_notify_pending);
1825 p_m_d_notify_pending = NULL;
1829 case CC_DISCONNECT | INDICATION:
1830 disconnect_ind(prim, dinfo, data);
1833 case CC_RELEASE | CONFIRM:
1834 case CC_RELEASE | INDICATION:
1835 release_ind(prim, dinfo, data);
1838 case CC_RELEASE_COMPLETE | INDICATION:
1839 release_complete_ind(prim, dinfo, data);
1842 case CC_RELEASE_COMPLETE | CONFIRM:
1845 case CC_NOTIFY | INDICATION:
1846 notify_ind(prim, dinfo, data);
1849 case CC_HOLD | INDICATION:
1850 hold_ind(prim, dinfo, data);
1853 case CC_RETRIEVE | INDICATION:
1854 retrieve_ind(prim, dinfo, data);
1857 case CC_SUSPEND | INDICATION:
1858 suspend_ind(prim, dinfo, data);
1861 case CC_RESUME | INDICATION:
1862 resume_ind(prim, dinfo, data);
1865 case CC_FACILITY | INDICATION:
1866 facility_ind(prim, dinfo, data);
1869 case CC_RELEASE_CR | INDICATION:
1870 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_CR | INDICATION, DIRECTION_IN);
1871 add_trace("callref", NULL, "0x%x", p_m_d_l3id);
1875 if ((p_m_d_l3id&0xff00) == 0xff00)
1876 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
1880 //#warning remove me
1881 //PDEBUG(DEBUG_LOG, "JOLLY release cr %d\n", p_serial);
1882 /* sending release to endpoint in case we still have an endpoint
1883 * this is because we don't get any response if a release_complete is received (or a release in release state)
1887 struct message *message;
1888 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1889 message->param.disconnectinfo.cause = (p_m_d_collect_cause!=CAUSE_NOUSER)?p_m_d_collect_cause:CAUSE_UNSPECIFIED;
1890 message->param.disconnectinfo.location = (p_m_d_collect_cause!=CAUSE_NOUSER)?p_m_d_collect_location:LOCATION_PRIVATE_LOCAL;
1891 message_put(message);
1893 free_epointlist(p_epointlist);
1895 new_state(PORT_STATE_RELEASE);
1899 case CC_NEW_CR | INDICATION:
1900 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1902 add_trace("callref", "old", "0x%x", p_m_d_l3id);
1905 new_l3id = *((int *)(((u_char *)data+mISDNUSER_HEAD_SIZE)));
1906 if (((new_l3id&0xff00)!=0xff00) && ((p_m_d_l3id&0xff00)==0xff00))
1907 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
1912 p_m_d_l3id = new_l3id;
1913 add_trace("callref", "new", "0x%x", p_m_d_l3id);
1918 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1919 add_trace("unhandled", "prim", "0x%x", prim);
1924 void Pdss1::new_state(int state)
1926 class Endpoint *epoint;
1929 if (state == PORT_STATE_IN_OVERLAP)
1931 p_m_timeout = p_m_mISDNport->ifport->tout_dialing;
1934 if (state != p_state)
1936 if (state == PORT_STATE_IN_SETUP
1937 || state == PORT_STATE_OUT_SETUP
1938 || state == PORT_STATE_IN_OVERLAP
1939 || state == PORT_STATE_OUT_OVERLAP)
1941 p_m_timeout = p_m_mISDNport->ifport->tout_setup;
1944 if (state == PORT_STATE_IN_PROCEEDING
1945 || state == PORT_STATE_OUT_PROCEEDING)
1947 p_m_timeout = p_m_mISDNport->ifport->tout_proceeding;
1950 if (state == PORT_STATE_IN_ALERTING
1951 || state == PORT_STATE_OUT_ALERTING)
1953 p_m_timeout = p_m_mISDNport->ifport->tout_alerting;
1956 if (state == PORT_STATE_CONNECT
1957 || state == PORT_STATE_CONNECT_WAITING)
1961 if (state == PORT_STATE_IN_DISCONNECT
1962 || state == PORT_STATE_OUT_DISCONNECT)
1964 p_m_timeout = p_m_mISDNport->ifport->tout_disconnect;
1969 Port::new_state(state);
1976 int Pdss1::handler(void)
1980 //if (p_m_delete && p_m_d_l3id==0)
1981 // printf("ping! %d", p_serial);
1982 if ((ret = PmISDN::handler()))
1985 /* handle destruction */
1986 if (p_m_delete && p_m_d_l3id==0)
1989 //PDEBUG(DEBUG_LOG, "JOLLY destroy object %d\n", p_serial);
2000 * handles all messages from endpoint
2002 /* MESSAGE_INFORMATION */
2003 void Pdss1::message_information(unsigned long epoint_id, int message_id, union parameter *param)
2005 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2006 INFORMATION_t *information;
2009 if (param->information.id[0]) /* only if we have something to dial */
2011 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2012 information = (INFORMATION_t *)(dmsg->data + headerlen);
2013 l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT);
2014 enc_ie_called_pn(&information->CALLED_PN, dmsg, 0, 1, (unsigned char *)param->information.id);
2016 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2025 void Pdss1::message_setup(unsigned long epoint_id, int message_id, union parameter *param)
2027 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2028 INFORMATION_t *information;
2031 int plan, type, screen, present, reason;
2032 int capability, mode, rate, coding, user, presentation, interpretation, hlc, exthlc;
2033 int channel, exclusive;
2035 struct epoint_list *epointlist;
2037 /* release if port is blocked */
2038 if (p_m_mISDNport->ifport->block)
2040 struct message *message;
2042 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2043 message->param.disconnectinfo.cause = 27; // temp. unavail.
2044 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2045 message_put(message);
2046 new_state(PORT_STATE_RELEASE);
2051 /* copy setup infos to port */
2052 memcpy(&p_callerinfo, ¶m->setup.callerinfo, sizeof(p_callerinfo));
2053 memcpy(&p_dialinginfo, ¶m->setup.dialinginfo, sizeof(p_dialinginfo));
2054 memcpy(&p_capainfo, ¶m->setup.capainfo, sizeof(p_capainfo));
2055 memcpy(&p_redirinfo, ¶m->setup.redirinfo, sizeof(p_redirinfo));
2056 // SCPY(&p_m_tones_dir, param->setup.ext.tones_dir);
2057 /* screen outgoing caller id */
2058 do_screen(1, p_callerinfo.id, sizeof(p_callerinfo.id), &p_callerinfo.ntype, &p_callerinfo.present, p_m_mISDNport->ifport->interface);
2060 /* only display at connect state: this case happens if endpoint is in connected mode */
2061 if (p_state==PORT_STATE_CONNECT)
2063 if (p_type!=PORT_TYPE_DSS1_NT_OUT
2064 && p_type!=PORT_TYPE_DSS1_NT_IN)
2066 if (p_callerinfo.display[0])
2068 /* sending information */
2069 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2070 information = (INFORMATION_t *)(dmsg->data + headerlen);
2071 l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT);
2073 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_callerinfo.display);
2075 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2080 /* attach only if not already */
2081 epointlist = p_epointlist;
2084 if (epointlist->epoint_id == epoint_id)
2086 epointlist = epointlist->next;
2089 epointlist_new(epoint_id);
2095 channel = p_m_b_channel;
2096 exclusive = p_m_b_exclusive;
2098 channel = CHANNEL_ANY;
2099 /* nt-port with no channel, not reserverd */
2100 if (!p_m_b_channel && !p_m_b_reserve && p_type==PORT_TYPE_DSS1_NT_OUT)
2101 channel = CHANNEL_NO;
2104 l1l2l3_trace_header(p_m_mISDNport, this, CC_NEW_CR | REQUEST, DIRECTION_OUT);
2110 if (p_m_mISDNport->procids[i] == 0)
2116 struct message *message;
2118 add_trace("callref", NULL, "no free id");
2120 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2121 message->param.disconnectinfo.cause = 47;
2122 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2123 message_put(message);
2124 new_state(PORT_STATE_RELEASE);
2128 p_m_mISDNport->procids[i] = 1;
2129 p_m_d_l3id = 0xff00 | i;
2133 /* if we are in te-mode, we need to create a process first */
2134 if (newteid++ > 0x7fff)
2136 p_m_d_l3id = (entity<<16) | newteid;
2137 /* preparing message */
2138 ncr.prim = CC_NEW_CR | REQUEST;
2139 ncr.addr = p_m_mISDNport->upper_id | FLG_MSG_DOWN;
2140 ncr.dinfo = p_m_d_l3id;
2143 mISDN_write(mISDNdevice, &ncr, mISDN_HEADER_LEN+ncr.len, TIMEOUT_1SEC);
2147 add_trace("callref", "new", "0x%x", p_m_d_l3id);
2150 /* preparing setup message */
2151 dmsg = create_l3msg(CC_SETUP | REQUEST, MT_SETUP, p_m_d_l3id, sizeof(SETUP_t), p_m_d_ntmode);
2152 setup = (SETUP_t *)(dmsg->data + headerlen);
2153 l1l2l3_trace_header(p_m_mISDNport, this, CC_SETUP | REQUEST, DIRECTION_OUT);
2154 /* channel information */
2155 if (channel >= 0) /* it should */
2157 enc_ie_channel_id(&setup->CHANNEL_ID, dmsg, exclusive, channel);
2159 /* caller information */
2161 switch (p_callerinfo.ntype)
2163 case INFO_NTYPE_INTERNATIONAL:
2166 case INFO_NTYPE_NATIONAL:
2169 case INFO_NTYPE_SUBSCRIBER:
2172 default: /* INFO_NTYPE_UNKNOWN */
2176 switch (p_callerinfo.screen)
2178 case INFO_SCREEN_USER:
2181 default: /* INFO_SCREEN_NETWORK */
2185 switch (p_callerinfo.present)
2187 case INFO_PRESENT_RESTRICTED:
2190 case INFO_PRESENT_NOTAVAIL:
2193 default: /* INFO_PRESENT_ALLOWED */
2198 enc_ie_calling_pn(&setup->CALLING_PN, dmsg, type, plan, present, screen, (unsigned char *)p_callerinfo.id);
2199 /* dialing information */
2200 if (p_dialinginfo.id[0]) /* only if we have something to dial */
2202 enc_ie_called_pn(&setup->CALLED_PN, dmsg, 0, 1, (unsigned char *)p_dialinginfo.id);
2204 /* sending complete */
2205 if (p_dialinginfo.sending_complete)
2206 enc_ie_complete(&setup->COMPLETE, dmsg, 1);
2207 /* sending user-user */
2208 if (param->setup.useruser.len)
2210 enc_ie_useruser(&setup->USER_USER, dmsg, param->setup.useruser.protocol, param->setup.useruser.data, param->setup.useruser.len);
2212 /* redirecting number */
2214 switch (p_redirinfo.ntype)
2216 case INFO_NTYPE_INTERNATIONAL:
2219 case INFO_NTYPE_NATIONAL:
2222 case INFO_NTYPE_SUBSCRIBER:
2225 default: /* INFO_NTYPE_UNKNOWN */
2229 switch (p_redirinfo.screen)
2231 case INFO_SCREEN_USER:
2234 default: /* INFO_SCREE_NETWORK */
2238 switch (p_redirinfo.reason)
2240 case INFO_REDIR_BUSY:
2243 case INFO_REDIR_NORESPONSE:
2246 case INFO_REDIR_UNCONDITIONAL:
2249 case INFO_REDIR_CALLDEFLECT:
2252 case INFO_REDIR_OUTOFORDER:
2255 default: /* INFO_REDIR_UNKNOWN */
2259 switch (p_redirinfo.present)
2261 case INFO_PRESENT_NULL: /* no redir at all */
2268 case INFO_PRESENT_RESTRICTED:
2271 case INFO_PRESENT_NOTAVAIL:
2274 default: /* INFO_PRESENT_ALLOWED */
2278 /* sending redirecting number only in ntmode */
2279 if (type >= 0 && p_m_d_ntmode)
2280 enc_ie_redir_nr(&setup->REDIR_NR, dmsg, type, plan, present, screen, reason, (unsigned char *)p_redirinfo.id);
2281 /* bearer capability */
2282 //printf("hlc=%d\n",p_capainfo.hlc);
2284 capability = p_capainfo.bearer_capa;
2285 mode = p_capainfo.bearer_mode;
2286 rate = (mode==INFO_BMODE_CIRCUIT)?0x10:0x00;
2287 switch (p_capainfo.bearer_info1)
2289 case INFO_INFO1_NONE:
2293 user = p_capainfo.bearer_info1 & 0x7f;
2296 enc_ie_bearer(&setup->BEARER, dmsg, coding, capability, mode, rate, -1, user);
2303 hlc = p_capainfo.hlc & 0x7f;
2305 if (p_capainfo.exthlc)
2306 exthlc = p_capainfo.exthlc & 0x7f;
2307 enc_ie_hlc(&setup->HLC, dmsg, coding, interpretation, presentation, hlc, exthlc);
2311 if (p_callerinfo.display[0] && p_m_d_ntmode)
2312 enc_ie_display(&setup->DISPLAY, dmsg, (unsigned char *)p_callerinfo.display);
2314 /* nt-mode: CNIP (calling name identification presentation) */
2315 if (p_callerinfo.name[0] && p_m_d_ntmode)
2316 enc_facility_centrex(&setup->FACILITY, dmsg, (unsigned char *)p_callerinfo.name, 1);
2320 /* send setup message now */
2321 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2323 new_state(PORT_STATE_OUT_SETUP);
2326 /* MESSAGE_FACILITY */
2327 void Pdss1::message_facility(unsigned long epoint_id, int message_id, union parameter *param)
2329 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2330 FACILITY_t *facility;
2333 /* facility will not be sent to external lines */
2337 /* sending facility */
2338 dmsg = create_l3msg(CC_FACILITY | REQUEST, MT_FACILITY, p_m_d_l3id, sizeof(FACILITY_t), p_m_d_ntmode);
2339 facility = (FACILITY_t *)(dmsg->data + headerlen);
2340 l1l2l3_trace_header(p_m_mISDNport, this, CC_FACILITY | REQUEST, DIRECTION_OUT);
2341 enc_ie_facility(&facility->FACILITY, dmsg, (unsigned char *)param->facilityinfo.data, param->facilityinfo.len);
2343 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2346 /* MESSAGE_NOTIFY */
2347 void Pdss1::message_notify(unsigned long epoint_id, int message_id, union parameter *param)
2349 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2350 INFORMATION_t *information;
2351 NOTIFY_t *notification;
2353 int plan, type = -1, present;
2356 if (param->notifyinfo.notify>INFO_NOTIFY_NONE)
2357 notify = param->notifyinfo.notify & 0x7f;
2360 if (p_state != PORT_STATE_CONNECT)
2362 /* notify only allowed in active state */
2368 switch (param->notifyinfo.ntype)
2370 case INFO_NTYPE_INTERNATIONAL:
2373 case INFO_NTYPE_NATIONAL:
2376 case INFO_NTYPE_SUBSCRIBER:
2379 default: /* INFO_NTYPE_UNKNOWN */
2383 switch (param->notifyinfo.present)
2385 case INFO_PRESENT_NULL: /* no redir at all */
2390 case INFO_PRESENT_RESTRICTED:
2393 case INFO_PRESENT_NOTAVAIL:
2396 default: /* INFO_PRESENT_ALLOWED */
2402 if (notify<0 && !param->notifyinfo.display[0])
2404 /* nothing to notify, nothing to display */
2410 if (p_state!=PORT_STATE_CONNECT)
2412 /* queue notification */
2413 if (p_m_d_notify_pending)
2414 message_free(p_m_d_notify_pending);
2415 p_m_d_notify_pending = message_create(ACTIVE_EPOINT(p_epointlist), p_serial, EPOINT_TO_PORT, message_id);
2416 memcpy(&p_m_d_notify_pending->param, param, sizeof(union parameter));
2419 /* sending notification */
2420 dmsg = create_l3msg(CC_NOTIFY | REQUEST, MT_NOTIFY, p_m_d_l3id, sizeof(NOTIFY_t), p_m_d_ntmode);
2421 notification = (NOTIFY_t *)(dmsg->data + headerlen);
2422 l1l2l3_trace_header(p_m_mISDNport, this, CC_NOTIFY | REQUEST, DIRECTION_OUT);
2423 enc_ie_notify(¬ification->NOTIFY, dmsg, notify);
2424 /* sending redirection number only in ntmode */
2425 if (type >= 0 && p_m_d_ntmode)
2426 enc_ie_redir_dn(¬ification->REDIR_DN, dmsg, type, plan, present, (unsigned char *)param->notifyinfo.id);
2427 if (param->notifyinfo.display[0] && p_m_d_ntmode)
2428 enc_ie_display(¬ification->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display);
2430 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2432 } else if (p_m_d_ntmode)
2434 /* sending information */
2435 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2436 information = (INFORMATION_t *)(dmsg->data + headerlen);
2437 l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT);
2438 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display);
2440 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2444 /* MESSAGE_OVERLAP */
2445 void Pdss1::message_overlap(unsigned long epoint_id, int message_id, union parameter *param)
2447 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2448 SETUP_ACKNOWLEDGE_t *setup_acknowledge;
2451 /* sending setup_acknowledge */
2452 dmsg = create_l3msg(CC_SETUP_ACKNOWLEDGE | REQUEST, MT_SETUP_ACKNOWLEDGE, p_m_d_l3id, sizeof(SETUP_ACKNOWLEDGE_t), p_m_d_ntmode);
2453 setup_acknowledge = (SETUP_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
2454 l1l2l3_trace_header(p_m_mISDNport, this, CC_SETUP_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
2455 /* channel information */
2456 if (p_state == PORT_STATE_IN_SETUP)
2457 enc_ie_channel_id(&setup_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2458 /* progress information */
2459 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2460 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2461 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2462 if (p_m_mISDNport->tones)
2463 enc_ie_progress(&setup_acknowledge->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2465 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2467 new_state(PORT_STATE_IN_OVERLAP);
2470 /* MESSAGE_PROCEEDING */
2471 void Pdss1::message_proceeding(unsigned long epoint_id, int message_id, union parameter *param)
2473 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2474 CALL_PROCEEDING_t *proceeding;
2477 /* sending proceeding */
2478 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2479 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2480 l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2481 /* channel information */
2482 if (p_state == PORT_STATE_IN_SETUP)
2483 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2484 /* progress information */
2485 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2486 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2487 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2488 if (p_m_mISDNport->tones)
2489 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2491 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2493 new_state(PORT_STATE_IN_PROCEEDING);
2496 /* MESSAGE_ALERTING */
2497 void Pdss1::message_alerting(unsigned long epoint_id, int message_id, union parameter *param)
2499 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2500 ALERTING_t *alerting;
2503 /* NT-MODE in setup state we must send PROCEEDING first */
2504 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2506 CALL_PROCEEDING_t *proceeding;
2508 /* sending proceeding */
2509 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2510 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2511 l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2512 /* channel information */
2513 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2514 /* progress information */
2515 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2516 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2517 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2518 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2520 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2521 new_state(PORT_STATE_IN_PROCEEDING);
2524 /* sending alerting */
2525 dmsg = create_l3msg(CC_ALERTING | REQUEST, MT_ALERTING, p_m_d_l3id, sizeof(ALERTING_t), p_m_d_ntmode);
2526 alerting = (ALERTING_t *)(dmsg->data + headerlen);
2527 l1l2l3_trace_header(p_m_mISDNport, this, CC_ALERTING | REQUEST, DIRECTION_OUT);
2528 /* channel information */
2529 if (p_state == PORT_STATE_IN_SETUP)
2530 enc_ie_channel_id(&alerting->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2531 /* progress information */
2532 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2533 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2534 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2535 if (p_m_mISDNport->tones)
2536 enc_ie_progress(&alerting->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2538 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2540 new_state(PORT_STATE_IN_ALERTING);
2543 /* MESSAGE_CONNECT */
2544 void Pdss1::message_connect(unsigned long epoint_id, int message_id, union parameter *param)
2546 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2547 INFORMATION_t *information;
2549 int type, plan, present, screen;
2551 class Endpoint *epoint;
2553 /* NT-MODE in setup state we must send PROCEEDING first */
2554 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2556 CALL_PROCEEDING_t *proceeding;
2558 /* sending proceeding */
2559 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2560 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2561 l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2562 /* channel information */
2563 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2564 // /* progress information */
2565 // if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2566 // || p_capainfo.bearer_capa==INFO_BC_AUDIO
2567 // || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2568 // enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2570 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2571 new_state(PORT_STATE_IN_PROCEEDING);
2574 /* copy connected information */
2575 memcpy(&p_connectinfo, ¶m->connectinfo, sizeof(p_connectinfo));
2576 /* screen outgoing caller id */
2577 do_screen(1, p_connectinfo.id, sizeof(p_connectinfo.id), &p_connectinfo.ntype, &p_connectinfo.present, p_m_mISDNport->ifport->interface);
2579 /* only display at connect state */
2580 if (p_state == PORT_STATE_CONNECT)
2581 if (p_connectinfo.display[0])
2583 /* sending information */
2584 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2585 information = (INFORMATION_t *)(dmsg->data + headerlen);
2586 l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT);
2588 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_connectinfo.display);
2590 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2594 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)
2596 /* connect command only possible in setup, proceeding or alerting state */
2600 /* preparing connect message */
2601 dmsg = create_l3msg(CC_CONNECT | REQUEST, MT_CONNECT, p_m_d_l3id, sizeof(CONNECT_t), p_m_d_ntmode);
2602 connect = (CONNECT_t *)(dmsg->data + headerlen);
2603 l1l2l3_trace_header(p_m_mISDNport, this, CC_CONNECT | REQUEST, DIRECTION_OUT);
2604 /* connect information */
2606 switch (p_connectinfo.ntype)
2608 case INFO_NTYPE_INTERNATIONAL:
2611 case INFO_NTYPE_NATIONAL:
2614 case INFO_NTYPE_SUBSCRIBER:
2617 default: /* INFO_NTYPE_UNKNOWN */
2621 switch (param->connectinfo.screen)
2623 case INFO_SCREEN_USER:
2626 default: /* INFO_SCREE_NETWORK */
2630 switch (p_connectinfo.present)
2632 case INFO_PRESENT_NULL: /* no colp at all */
2638 case INFO_PRESENT_RESTRICTED:
2641 case INFO_PRESENT_NOTAVAIL:
2644 default: /* INFO_PRESENT_ALLOWED */
2649 enc_ie_connected_pn(&connect->CONNECT_PN, dmsg, type, plan, present, screen, (unsigned char *)p_connectinfo.id);
2651 if (p_connectinfo.display[0] && p_m_d_ntmode)
2652 enc_ie_display(&connect->DISPLAY, dmsg, (unsigned char *)p_connectinfo.display);
2654 /* nt-mode: CONP (connected name identification presentation) */
2655 if (p_connectinfo.name[0] && p_m_d_ntmode)
2656 enc_facility_centrex(&connect->FACILITY, dmsg, (unsigned char *)p_connectinfo.name, 0);
2661 epoint = find_epoint_id(epoint_id);
2662 enc_ie_date(&connect->DATE, dmsg, now, p_settings.no_seconds);
2665 /* finally send message */
2666 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2669 new_state(PORT_STATE_CONNECT);
2671 new_state(PORT_STATE_CONNECT_WAITING);
2675 /* MESSAGE_DISCONNECT */
2676 void Pdss1::message_disconnect(unsigned long epoint_id, int message_id, union parameter *param)
2678 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2679 DISCONNECT_t *disconnect;
2680 RELEASE_COMPLETE_t *release_complete;
2682 struct message *message;
2685 /* we reject during incoming setup when we have no tones. also if we are in outgoing setup state */
2686 // if ((p_state==PORT_STATE_IN_SETUP && !p_m_mISDNport->tones)
2687 if (/* ||*/ p_state==PORT_STATE_OUT_SETUP)
2689 /* sending release to endpoint */
2692 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
2693 message->param.disconnectinfo.cause = 16;
2694 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2695 message_put(message);
2697 free_epointlist(p_epointlist);
2699 /* sending release */
2700 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
2701 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
2702 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
2704 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2706 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2707 new_state(PORT_STATE_RELEASE);
2712 /* workarround: NT-MODE in setup state we must send PROCEEDING first to make it work */
2713 if (p_state==PORT_STATE_IN_SETUP)
2715 CALL_PROCEEDING_t *proceeding;
2717 /* sending proceeding */
2718 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2719 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2720 l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2721 /* channel information */
2722 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2723 /* progress information */
2724 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2725 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2726 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2727 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2729 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2730 new_state(PORT_STATE_IN_PROCEEDING);
2733 /* sending disconnect */
2734 dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode);
2735 disconnect = (DISCONNECT_t *)(dmsg->data + headerlen);
2736 l1l2l3_trace_header(p_m_mISDNport, this, CC_DISCONNECT | REQUEST, DIRECTION_OUT);
2737 /* progress information */
2738 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2739 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2740 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2741 if (p_m_mISDNport->tones)
2742 enc_ie_progress(&disconnect->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2744 enc_ie_cause(&disconnect->CAUSE, dmsg, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2746 if (param->disconnectinfo.display[0])
2747 p = param->disconnectinfo.display;
2748 if (p) if (*p && p_m_d_ntmode)
2749 enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p);
2751 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2752 new_state(PORT_STATE_OUT_DISCONNECT);
2755 /* MESSAGE_RELEASE */
2756 void Pdss1::message_release(unsigned long epoint_id, int message_id, union parameter *param)
2758 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2760 RELEASE_COMPLETE_t *release_complete;
2761 DISCONNECT_t *disconnect;
2763 class Endpoint *epoint;
2767 * we may only release during incomming disconnect state.
2768 * this means that the endpoint doesnt require audio anymore
2770 if (p_state == PORT_STATE_IN_DISCONNECT
2771 || p_state == PORT_STATE_OUT_DISCONNECT)
2773 /* sending release */
2774 dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, p_m_d_l3id, sizeof(RELEASE_t), p_m_d_ntmode);
2775 release = (RELEASE_t *)(dmsg->data + headerlen);
2776 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE | REQUEST, DIRECTION_OUT);
2778 enc_ie_cause(&release->CAUSE, dmsg, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2780 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2781 new_state(PORT_STATE_RELEASE);
2783 free_epointid(epoint_id);
2784 // wait for callref to be released
2789 * if we are on incoming call setup, we may reject by sending a release_complete
2790 * also on outgoing call setup, we send a release complete, BUT this is not conform. (i don't know any other way)
2792 if (p_state==PORT_STATE_IN_SETUP
2793 || p_state==PORT_STATE_OUT_SETUP)
2794 // // NOTE: a bug in mISDNuser (see disconnect_req_out !!!)
2795 // || p_state==PORT_STATE_OUT_DISCO)
2797 //#warning remove me
2798 //PDEBUG(DEBUG_LOG, "JOLLY sending release complete %d\n", p_serial);
2799 /* sending release complete */
2800 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
2801 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
2802 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE | REQUEST, DIRECTION_OUT);
2804 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2806 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2807 new_state(PORT_STATE_RELEASE);
2809 free_epointid(epoint_id);
2811 /* remove process */
2812 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_CR | REQUEST, DIRECTION_OUT);
2813 add_trace("callref", NULL, "0x%x", p_m_d_l3id);
2817 if ((p_m_d_l3id&0xff00) == 0xff00)
2818 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
2823 // wait for callref to be released
2828 wirklich erst proceeding?:
2829 /* NT-MODE in setup state we must send PROCEEDING first */
2830 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2832 CALL_PROCEEDING_t *proceeding;
2834 /* sending proceeding */
2835 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2836 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2837 l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2838 /* channel information */
2839 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2840 /* progress information */
2841 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2842 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2843 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2844 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2846 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2850 /* sending disconnect */
2851 dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode);
2852 disconnect = (DISCONNECT_t *)(dmsg->data + headerlen);
2853 l1l2l3_trace_header(p_m_mISDNport, this, CC_DISCONNECT | REQUEST, DIRECTION_OUT);
2854 /* progress information */
2855 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2856 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2857 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2858 if (p_m_mISDNport->tones)
2859 enc_ie_progress(&disconnect->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2861 enc_ie_cause(&disconnect->CAUSE, dmsg, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
2863 epoint = find_epoint_id(epoint_id);
2864 if (param->disconnectinfo.display[0])
2865 p = param->disconnectinfo.display;
2866 if (p) if (*p && p_m_d_ntmode)
2867 enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p);
2869 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2870 new_state(PORT_STATE_OUT_DISCONNECT);
2872 free_epointid(epoint_id);
2873 // wait for release and callref to be released
2874 //#warning remove me
2875 //PDEBUG(DEBUG_LOG, "JOLLY sending disconnect %d\n", p_serial);
2880 * endpoint sends messages to the port
2882 int Pdss1::message_epoint(unsigned long epoint_id, int message_id, union parameter *param)
2884 struct message *message;
2886 if (PmISDN::message_epoint(epoint_id, message_id, param))
2891 case MESSAGE_INFORMATION: /* overlap dialing */
2892 if (p_type==PORT_TYPE_DSS1_NT_OUT
2893 && p_state!=PORT_STATE_OUT_OVERLAP
2894 && p_state!=PORT_STATE_CONNECT
2895 && p_state!=PORT_STATE_OUT_DISCONNECT
2896 && p_state!=PORT_STATE_IN_DISCONNECT)
2900 if (p_type==PORT_TYPE_DSS1_TE_OUT
2901 && p_state!=PORT_STATE_OUT_OVERLAP
2902 && p_state!=PORT_STATE_OUT_PROCEEDING
2903 && p_state!=PORT_STATE_OUT_ALERTING
2904 && p_state!=PORT_STATE_CONNECT
2905 && p_state!=PORT_STATE_OUT_DISCONNECT
2906 && p_state!=PORT_STATE_IN_DISCONNECT)
2910 if ((p_type==PORT_TYPE_DSS1_NT_IN || p_type==PORT_TYPE_DSS1_TE_IN)
2911 && p_state!=PORT_STATE_IN_OVERLAP
2912 && p_state!=PORT_STATE_IN_PROCEEDING
2913 && p_state!=PORT_STATE_IN_ALERTING
2914 && p_state!=PORT_STATE_CONNECT
2915 && p_state!=PORT_STATE_CONNECT_WAITING
2916 && p_state!=PORT_STATE_OUT_DISCONNECT
2917 && p_state!=PORT_STATE_IN_DISCONNECT)
2921 message_information(epoint_id, message_id, param);
2924 case MESSAGE_SETUP: /* dial-out command received from epoint */
2925 if (p_state!=PORT_STATE_IDLE
2926 && p_state!=PORT_STATE_CONNECT)
2928 PERROR("Pdss1(%s) ignoring setup because isdn port is not in idle state (or connected for sending display info).\n", p_name);
2931 if (p_epointlist && p_state==PORT_STATE_IDLE)
2932 FATAL("Pdss1(%s): epoint pointer is set in idle state, how bad!!\n", p_name);
2933 /* note: pri is a special case, because links must be up for pri */
2934 if (p_m_mISDNport->l1link || p_m_mISDNport->pri || !p_m_mISDNport->ntmode || p_state!=PORT_STATE_IDLE)
2936 /* LAYER 1 is up, or we may send */
2937 message_setup(epoint_id, message_id, param);
2940 /* LAYER 1 id down, so we queue */
2941 p_m_d_queue = message_create(epoint_id, p_serial, EPOINT_TO_PORT, message_id);
2942 memcpy(&p_m_d_queue->param, param, sizeof(union parameter));
2944 if (!(epointlist_new(epoint_id)))
2945 FATAL("No memory for epointlist\n");
2947 PDEBUG(DEBUG_ISDN, "the L1 is down, we try to establish the link NT portnum=%d (%s).\n", p_m_mISDNport->portnum, p_name);
2948 act.prim = PH_ACTIVATE | REQUEST;
2949 act.addr = p_m_mISDNport->upper_id | FLG_MSG_DOWN;
2952 mISDN_write(mISDNdevice, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
2953 l1l2l3_trace_header(p_m_mISDNport, this, act.prim, DIRECTION_OUT);
2955 // /* set timeout */
2956 // p_m_mISDNport->l1timeout = now+3;
2960 case MESSAGE_NOTIFY: /* display and notifications */
2961 message_notify(epoint_id, message_id, param);
2964 case MESSAGE_FACILITY: /* facility message */
2965 message_facility(epoint_id, message_id, param);
2968 case MESSAGE_OVERLAP: /* more information is needed */
2969 if (p_state!=PORT_STATE_IN_SETUP)
2973 message_overlap(epoint_id, message_id, param);
2976 case MESSAGE_PROCEEDING: /* call of endpoint is proceeding */
2977 if (p_state!=PORT_STATE_IN_SETUP
2978 && p_state!=PORT_STATE_IN_OVERLAP)
2982 message_proceeding(epoint_id, message_id, param);
2985 case MESSAGE_ALERTING: /* call of endpoint is ringing */
2986 if (p_state!=PORT_STATE_IN_SETUP
2987 && p_state!=PORT_STATE_IN_OVERLAP
2988 && p_state!=PORT_STATE_IN_PROCEEDING)
2992 message_alerting(epoint_id, message_id, param);
2995 case MESSAGE_CONNECT: /* call of endpoint is connected */
2996 if (p_state!=PORT_STATE_IN_SETUP
2997 && p_state!=PORT_STATE_IN_OVERLAP
2998 && p_state!=PORT_STATE_IN_PROCEEDING
2999 && p_state!=PORT_STATE_IN_ALERTING
3000 && !(p_state==PORT_STATE_CONNECT && p_m_d_ntmode))
3004 message_connect(epoint_id, message_id, param);
3007 case MESSAGE_DISCONNECT: /* call has been disconnected */
3008 if (p_state!=PORT_STATE_IN_SETUP
3009 && p_state!=PORT_STATE_IN_OVERLAP
3010 && p_state!=PORT_STATE_IN_PROCEEDING
3011 && p_state!=PORT_STATE_IN_ALERTING
3012 && p_state!=PORT_STATE_OUT_SETUP
3013 && p_state!=PORT_STATE_OUT_OVERLAP
3014 && p_state!=PORT_STATE_OUT_PROCEEDING
3015 && p_state!=PORT_STATE_OUT_ALERTING
3016 && p_state!=PORT_STATE_CONNECT
3017 && p_state!=PORT_STATE_CONNECT_WAITING)
3021 message_disconnect(epoint_id, message_id, param);
3024 case MESSAGE_RELEASE: /* release isdn port */
3025 if (p_state==PORT_STATE_RELEASE)
3029 message_release(epoint_id, message_id, param);
3033 PERROR("Pdss1(%s) isdn port with (caller id %s) received a wrong message: %d\n", p_name, p_callerinfo.id, message);
3042 * data from isdn-stack (layer-3) to pbx (port class)
3044 /* NOTE: nt mode use mISDNuser_head_t as header */
3045 int stack2manager_nt(void *dat, void *arg)
3049 manager_t *mgr = (manager_t *)dat;
3050 msg_t *msg = (msg_t *)arg;
3051 mISDNuser_head_t *hh;
3052 struct mISDNport *mISDNport;
3058 /* note: nst is the first data feld of mISDNport */
3059 mISDNport = (struct mISDNport *)mgr->nst;
3061 hh = (mISDNuser_head_t *)msg->data;
3062 PDEBUG(DEBUG_ISDN, "prim(0x%x) dinfo(0x%x) msg->len(%d)\n", hh->prim, hh->dinfo, msg->len);
3064 /* find Port object of type ISDN */
3068 if (port->p_type == PORT_TYPE_DSS1_NT_IN || port->p_type == PORT_TYPE_DSS1_NT_OUT)
3070 pdss1 = (class Pdss1 *)port;
3071 //PDEBUG(DEBUG_ISDN, "comparing dinfo = 0x%x with l3id 0x%x\n", hh->dinfo, pdss1->p_m_d_l3id);
3072 /* check out correct stack */
3073 if (pdss1->p_m_mISDNport == mISDNport)
3074 /* check out correct id */
3075 if ((pdss1->p_m_d_l3id&0x0000ff00) != 0x000ff00)
3077 /* a single process */
3078 if (hh->dinfo == pdss1->p_m_d_l3id)
3080 /* found port, the message belongs to */
3085 /* a broadcast process */
3086 if ((hh->dinfo&0xffff0000) == (pdss1->p_m_d_l3id&0xffff0000))
3088 /* found port, the message belongs to */
3097 //printf("%x %x\n", hh->dinfo, pdss1->p_m_d_l3id);
3098 /* if process id is master process, but a child disconnects */
3099 if ((hh->dinfo&0x0000ff00)!=0x0000ff00 && (pdss1->p_m_d_l3id&0x0000ff00)==0x0000ff00)
3101 if (hh->prim == (CC_DISCONNECT|INDICATION))
3103 /* send special indication for child disconnect */
3104 pdss1->disconnect_ind_i(hh->prim, hh->dinfo, msg->data);
3108 // ignoring other messages from child processes
3112 /* if process id and layer 3 id matches */
3113 if (hh->dinfo == pdss1->p_m_d_l3id)
3115 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
3124 case MGR_SHORTSTATUS | INDICATION:
3125 case MGR_SHORTSTATUS | CONFIRM:
3127 case SSTATUS_L2_ESTABLISHED:
3129 case SSTATUS_L2_RELEASED:
3134 case DL_ESTABLISH | INDICATION:
3135 case DL_ESTABLISH | CONFIRM:
3137 l1l2l3_trace_header(mISDNport, NULL, hh->prim, DIRECTION_IN);
3138 add_trace("tei", NULL, "%d", hh->dinfo);
3140 if (mISDNport->ptp && hh->dinfo == 0)
3142 if (mISDNport->l2establish)
3144 mISDNport->l2establish = 0;
3145 PDEBUG(DEBUG_ISDN, "the link became active before l2establish timer expiry.\n");
3147 mISDNport->l2link = 1;
3148 if (mISDNport->pri);
3149 mISDNport->l1link = 1; /* this is a hack, we also assume L1 to be active */
3153 case DL_RELEASE | INDICATION:
3154 case DL_RELEASE | CONFIRM:
3156 l1l2l3_trace_header(mISDNport, NULL, hh->prim, DIRECTION_IN);
3157 add_trace("tei", NULL, "%d", hh->dinfo);
3159 if (mISDNport->ptp && hh->dinfo == 0)
3161 mISDNport->l2link = 0;
3162 time(&mISDNport->l2establish);
3163 PDEBUG(DEBUG_ISDN, "because we are ptp, we set a l2establish timer.\n");
3165 //#warning debugging usleep crash
3166 // printf("JOLLY release port %d\n", mISDNport->portnum);
3170 case CC_SETUP | INDICATION:
3171 /* creating port object */
3172 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3173 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0)))
3175 FATAL("Cannot create Port instance.\n");
3176 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
3179 case CC_RESUME | INDICATION:
3180 /* creating port object */
3181 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3182 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0)))
3183 FATAL("Cannot create Port instance.\n");
3184 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
3187 case CC_RELEASE_CR | INDICATION:
3188 PERROR("unhandled message from stack: call ref released (l3id=0x%x)\n", hh->dinfo);
3191 case CC_RELEASE_COMPLETE | INDICATION:
3194 case CC_FACILITY | INDICATION:
3198 PERROR("unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", hh->prim, hh->dinfo, msg->len);
3202 if (port->p_type == PORT_TYPE_DSS1_NT_IN || port->p_type == PORT_TYPE_DSS1_NT_OUT)
3204 pdss1 = (class Pdss1 *)port;
3205 //PDEBUG(DEBUG_ISDN, "comparing dinfo = 0x%x with l3id 0x%x\n", hh->dinfo, pdss1->p_m_d_l3id);
3206 /* check out correct stack */
3207 if (pdss1->p_m_mISDNport == mISDNport)
3208 /* check out correct id */
3209 PERROR("unhandled message: dinfo=%x is not associated with port-dinfo=%x\n",hh->dinfo,pdss1->p_m_d_l3id);
3219 /* NOTE: te mode use iframe_t as header */
3220 int stack2manager_te(struct mISDNport *mISDNport, msg_t *msg)
3227 if (!msg || !mISDNport)
3229 frm = (iframe_t *)msg->data;
3230 PDEBUG(DEBUG_ISDN, "prim(0x%x) dinfo(0x%x) msg->len(%d)\n", frm->prim, frm->dinfo, msg->len);
3232 /* find Port object of type ISDN */
3236 if (port->p_type == PORT_TYPE_DSS1_TE_IN || port->p_type == PORT_TYPE_DSS1_TE_OUT)
3238 pdss1 = (class Pdss1 *)port;
3239 /* check out correct stack */
3240 if (pdss1->p_m_mISDNport == mISDNport)
3241 /* check out correct id */
3242 if (frm->dinfo == pdss1->p_m_d_l3id)
3244 /* found port, the message belongs to */
3252 pdss1->message_isdn(frm->prim, frm->dinfo, msg->data);
3257 /* process new cr (before setup indication) */
3258 //printf("prim = 0x%x, looking for 0x%x\n",frm->prim, (CC_NEW_CR | INDICATION));
3259 if (frm->prim == (CC_NEW_CR | INDICATION))
3262 /* creating port object */
3263 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3264 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_TE_IN, mISDNport, name, NULL, 0, 0)))
3265 FATAL("Cannot create Port instance.\n");
3266 /* l3id will be set from dinfo at message_isdn */
3267 pdss1->message_isdn(frm->prim, frm->dinfo, msg->data);
3272 if (frm->prim == (CC_RELEASE_CR | INDICATION))
3274 PERROR("unhandled message from stack: call ref released (l3id=0x%x)\n", frm->dinfo);
3278 PERROR("unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", frm->prim, frm->dinfo, msg->len);
3284 * sending message that were queued during L1 activation
3285 * or releasing port if link is down
3287 void setup_queue(struct mISDNport *mISDNport, int link)
3291 struct message *message;
3293 if (!mISDNport->ntmode)
3296 /* check all port objects for pending message */
3300 if ((port->p_type&PORT_CLASS_mISDN_MASK) == PORT_CLASS_mISDN_DSS1)
3302 pdss1 = (class Pdss1 *)port;
3303 if (pdss1->p_m_mISDNport == mISDNport)
3305 if (pdss1->p_m_d_queue)
3309 PDEBUG(DEBUG_ISDN, "the L1 became active, so we send queued message for portnum=%d (%s).\n", mISDNport->portnum, pdss1->p_name);
3310 /* LAYER 1 is up, so we send */
3311 pdss1->message_setup(pdss1->p_m_d_queue->id_from, pdss1->p_m_d_queue->type, &pdss1->p_m_d_queue->param);
3312 message_free(pdss1->p_m_d_queue);
3313 pdss1->p_m_d_queue = NULL;
3316 PDEBUG(DEBUG_ISDN, "the L1 became NOT active, so we release port for portnum=%d (%s).\n", mISDNport->portnum, pdss1->p_name);
3317 message = message_create(pdss1->p_serial, pdss1->p_m_d_queue->id_from, PORT_TO_EPOINT, MESSAGE_RELEASE);
3318 message->param.disconnectinfo.cause = 27;
3319 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
3320 message_put(message);
3321 pdss1->new_state(PORT_STATE_RELEASE);
3322 pdss1->p_m_delete = 1;