1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
10 \*****************************************************************************/
20 #include <sys/ioctl.h>
21 #include <sys/types.h>
25 #include <mISDNuser/net_l2.h>
35 Pdss1::Pdss1(int type, struct mISDNport *mISDNport, char *portname, struct port_settings *settings, int channel, int exclusive) : PmISDN(type, mISDNport, portname, settings, channel, exclusive)
37 p_callerinfo.itype = (mISDNport->ifport->interface->extension)?INFO_ITYPE_ISDN_EXTENSION:INFO_ITYPE_ISDN;
38 p_m_d_ntmode = mISDNport->ntmode;
42 p_m_d_notify_pending = NULL;
43 p_m_d_collect_cause = 0;
44 p_m_d_collect_location = 0;
46 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);
55 /* remove queued message */
57 message_free(p_m_d_queue);
59 if (p_m_d_notify_pending)
60 message_free(p_m_d_notify_pending);
62 /* check how many processes are left */
63 if (p_m_d_ntmode == 1)
65 if (p_m_mISDNport->nst.layer3->proc)
66 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);
72 * create layer 3 message
74 static msg_t *create_l3msg(int prim, int mt, int dinfo, int size, int ntmode)
81 size = sizeof(Q931_info_t)+2;
85 dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL);
92 dmsg = alloc_msg(size+256+mISDN_HEADER_LEN+DEFAULT_HEADROOM);
95 memset(msg_put(dmsg,size+mISDN_HEADER_LEN), 0, size+mISDN_HEADER_LEN);
96 frm = (iframe_t *)dmsg->data;
99 qi = (Q931_info_t *)(dmsg->data + mISDN_HEADER_LEN);
105 FATAL("Cannot allocate memory, system overloaded.\n");
106 exit(0); // make gcc happy
109 msg_t *create_l2msg(int prim, int dinfo, int size) /* NT only */
113 dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL);
117 FATAL("Cannot allocate memory, system overloaded.\n");
118 exit(0); // make gcc happy
122 * if we received a first reply to the setup message,
123 * we will check if we have now channel information
124 * return: <0: error, call is released, -cause is given
125 * 0: ok, nothing to do
127 int Pdss1::received_first_reply_to_setup(unsigned long prim, int channel, int exclusive)
130 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
131 RELEASE_COMPLETE_t *release_complete;
134 /* correct exclusive to 0, if no explicit channel was given */
135 if (exclusive<0 || channel<=0)
138 /* select scenario */
139 if (p_m_b_channel && p_m_b_exclusive)
141 /*** we gave an exclusive channel (or if we are done) ***/
143 /* if not first reply, we are done */
144 if (p_state != PORT_STATE_OUT_SETUP)
147 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
148 add_trace("channel", "request", "%d (forced)", p_m_b_channel);
149 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
151 /* if give channel not accepted or not equal */
152 if (channel!=-1 && p_m_b_channel!=channel)
154 add_trace("conclusion", NULL, "forced channel not accepted");
160 add_trace("conclusion", NULL, "channel was accepted");
161 add_trace("connect", "channel", "%d", p_m_b_channel);
164 /* activate our exclusive channel */
165 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
169 /*** we gave a non-exclusive channel ***/
171 /* if not first reply, we are done */
172 if (p_state != PORT_STATE_OUT_SETUP)
175 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
176 add_trace("channel", "request", "%d (suggest)", p_m_b_channel);
177 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
179 /* if channel was accepted as given */
180 if (channel==-1 || p_m_b_channel==channel)
182 add_trace("conclusion", NULL, "channel was accepted as given");
183 add_trace("connect", "channel", "%d", p_m_b_channel);
185 p_m_b_exclusive = 1; // we are done
186 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
190 /* if channel value is faulty */
193 add_trace("conclusion", NULL, "illegal reply");
195 ret = -111; // protocol error
199 /* if channel was not accepted, try to get it */
200 ret = seize_bchannel(channel, 1); // exclusively
201 add_trace("channel", "available", ret<0?"no":"yes");
204 add_trace("conclusion", NULL, "replied channel not available");
208 add_trace("conclusion", NULL, "replied channel accepted");
209 add_trace("connect", "channel", "%d", p_m_b_channel);
212 /* activate channel given by remote */
213 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
217 /*** we sent 'any channel acceptable' ***/
219 /* if not first reply, we are done */
220 if (p_state != PORT_STATE_OUT_SETUP)
223 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
224 add_trace("channel", "request", "any");
225 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
226 /* if no channel was replied */
229 add_trace("conclusion", NULL, "no channel, protocol error");
231 ret = -111; // protocol error
235 /* we will see, if our received channel is available */
236 ret = seize_bchannel(channel, 1); // exclusively
237 add_trace("channel", "available", ret<0?"no":"yes");
240 add_trace("conclusion", NULL, "replied channel not available");
244 add_trace("conclusion", NULL, "replied channel accepted");
245 add_trace("connect", "channel", "%d", p_m_b_channel);
248 /* activate channel given by remote */
249 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
252 /*** we sent 'no channel available' ***/
254 /* if not the first reply, but a connect, we are forced */
255 if (prim==(CC_CONNECT | INDICATION) && p_state!=PORT_STATE_OUT_SETUP)
257 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (connect)", DIRECTION_NONE);
258 add_trace("channel", "request", "no-channel");
259 add_trace("channel", "reply", (channel>=0)?"%d%s":"(none)", channel, exclusive?" (forced)":"");
262 goto use_from_connect;
264 ret = seize_bchannel(CHANNEL_ANY, 0); // any channel
265 add_trace("channel", "available", ret<0?"no":"yes");
268 add_trace("conclusion", NULL, "no channel available during call-waiting");
272 add_trace("conclusion", NULL, "using channel %d", p_m_b_channel);
273 add_trace("connect", "channel", "%d", p_m_b_channel);
275 p_m_b_exclusive = 1; // we are done
277 /* activate channel given by remote */
278 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
282 /* if not first reply, we are done */
283 if (p_state != PORT_STATE_OUT_SETUP)
286 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
287 add_trace("channel", "request", "no-channel");
288 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
289 /* if first reply has no channel, we are done */
292 add_trace("conclusion", NULL, "no channel until connect");
297 /* we will see, if our received channel is available */
299 ret = seize_bchannel(channel, exclusive);
300 add_trace("channel", "available", ret<0?"no":"yes");
303 add_trace("conclusion", NULL, "replied channel not available");
307 add_trace("conclusion", NULL, "replied channel accepted");
308 add_trace("connect", "channel", "%d", p_m_b_channel);
310 p_m_b_exclusive = 1; // we are done
312 /* activate channel given by remote */
313 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
318 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
319 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
320 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
321 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
323 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
324 new_state(PORT_STATE_RELEASE);
326 return(-34); /* to epoint: no channel available */
331 * hunt bchannel for incoming setup or retrieve or resume
333 int Pdss1::hunt_bchannel(int channel, int exclusive)
335 struct select_channel *selchannel;
336 struct interface_port *ifport = p_m_mISDNport->ifport;
339 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (setup)", DIRECTION_NONE);
342 if (channel == CHANNEL_NO)
343 add_trace("channel", "request", "no-channel");
345 add_trace("channel", "request", (channel>0)?"%d%s":"any", channel, exclusive?" (forced)":"");
346 if (channel==CHANNEL_NO && p_type==PORT_TYPE_DSS1_TE_IN)
348 add_trace("conclusion", NULL, "incoming call-waiting not supported for TE-mode");
350 return(-6); // channel unacceptable
352 if (channel <= 0) /* not given, no channel, whatever.. */
353 channel = CHANNEL_ANY; /* any channel */
354 add_trace("channel", "reserved", "%d", p_m_mISDNport->b_reserved);
355 if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num) // of out chan..
357 add_trace("conclusion", NULL, "all channels are reserved");
359 return(-34); // no channel
361 if (channel == CHANNEL_ANY)
365 /* check for given channel in selection list */
366 selchannel = ifport->in_channel;
369 if (selchannel->channel == channel || selchannel->channel == CHANNEL_FREE)
371 selchannel = selchannel->next;
376 /* exclusive channel requests must be in the list */
381 add_trace("conclusion", NULL, "exclusively requested channel not in list");
383 return(-6); // channel unacceptable
385 i = selchannel->channel-1-(selchannel->channel>=17);
386 if (p_m_mISDNport->b_port[i] == NULL)
388 add_trace("conclusion", NULL, "exclusively requested channel is busy");
390 return(-6); // channel unacceptable
393 /* requested channels in list will be used */
396 i = selchannel->channel-1-(selchannel->channel>=17);
397 if (p_m_mISDNport->b_port[i] == NULL)
401 /* if channel is not available or not in list, it must be searched */
403 /* check for first free channel in list */
405 selchannel = ifport->in_channel;
408 switch(selchannel->channel)
410 case CHANNEL_FREE: /* free channel */
411 add_trace("hunting", "channel", "free");
412 if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num)
413 break; /* all channel in use or reserverd */
416 while(i < p_m_mISDNport->b_num)
418 if (p_m_mISDNport->b_port[i] == NULL)
420 channel = i+1+(i>=15);
428 add_trace("hunting", "channel", "%d", selchannel->channel);
429 if (selchannel->channel<1 || selchannel->channel==16)
430 break; /* invalid channels */
431 i = selchannel->channel-1-(selchannel->channel>=17);
432 if (i >= p_m_mISDNport->b_num)
433 break; /* channel not in port */
434 if (p_m_mISDNport->b_port[i] == NULL)
436 channel = selchannel->channel;
442 break; /* found channel */
443 selchannel = selchannel->next;
447 add_trace("conclusion", NULL, "no channel available");
449 return(-6); // channel unacceptable
453 add_trace("conclusion", NULL, "channel available");
454 add_trace("connect", "channel", "%d", channel);
460 * handles all indications
462 /* CC_SETUP INDICATION */
463 void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
465 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
466 SETUP_t *setup = (SETUP_t *)((unsigned long)data + headerlen);
467 int calling_type, calling_plan, calling_present, calling_screen;
468 int called_type, called_plan;
469 int redir_type, redir_plan, redir_present, redir_screen, redir_reason;
470 int hlc_coding, hlc_presentation, hlc_interpretation, hlc_hlc, hlc_exthlc;
471 int bearer_coding, bearer_capability, bearer_mode, bearer_rate, bearer_multi, bearer_user;
472 int exclusive, channel;
475 unsigned char keypad[32] = "";
476 unsigned char useruser[128];
477 int useruser_len = 0, useruser_protocol;
478 class Endpoint *epoint;
479 struct message *message;
481 /* callref from nt-lib */
484 /* nt-library now gives us the id via CC_SETUP */
485 if (dinfo&(~0xff) == 0xff00)
486 FATAL("l3-stack gives us a process id 0xff00-0xffff\n");
487 l1l2l3_trace_header(p_m_mISDNport, this, CC_NEW_CR | INDICATION, DIRECTION_IN);
489 add_trace("callref", "old", "0x%x", p_m_d_l3id);
490 add_trace("callref", "new", "0x%x", dinfo);
492 if (p_m_d_l3id&(~0xff) == 0xff00)
493 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
495 p_m_d_ces = setup->ces;
498 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
499 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));
500 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));
501 dec_ie_keypad(setup->KEYPAD, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)keypad, sizeof(keypad));
502 /* te-mode: CNIP (calling name identification presentation) */
504 dec_facility_centrex(setup->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)p_callerinfo.name, sizeof(p_callerinfo.name));
505 dec_ie_useruser(setup->USER_USER, (Q931_info_t *)((unsigned long)data+headerlen), &useruser_protocol, useruser, &useruser_len);
506 dec_ie_complete(setup->COMPLETE, (Q931_info_t *)((unsigned long)data+headerlen), &p_dialinginfo.sending_complete);
507 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));
508 dec_ie_channel_id(setup->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
509 dec_ie_hlc(setup->HLC, (Q931_info_t *)((unsigned long)data+headerlen), &hlc_coding, &hlc_interpretation, &hlc_presentation, &hlc_hlc, &hlc_exthlc);
510 dec_ie_bearer(setup->BEARER, (Q931_info_t *)((unsigned long)data+headerlen), &bearer_coding, &bearer_capability, &bearer_mode, &bearer_rate, &bearer_multi, &bearer_user);
513 /* if blocked, release call */
514 if (p_m_mISDNport->ifport->block)
516 RELEASE_COMPLETE_t *release_complete;
518 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
519 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
520 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
521 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 27); /* temporary unavailable */
522 add_trace("reason", NULL, "port blocked");
524 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
525 new_state(PORT_STATE_RELEASE);
531 switch (calling_present)
534 p_callerinfo.present = INFO_PRESENT_RESTRICTED;
537 p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
540 p_callerinfo.present = INFO_PRESENT_ALLOWED;
543 switch (calling_screen)
546 p_callerinfo.screen = INFO_SCREEN_USER;
549 p_callerinfo.screen = INFO_SCREEN_NETWORK;
552 switch (calling_type)
555 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
556 p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
557 p_callerinfo.screen = INFO_SCREEN_NETWORK;
560 p_callerinfo.ntype = INFO_NTYPE_INTERNATIONAL;
563 p_callerinfo.ntype = INFO_NTYPE_NATIONAL;
566 p_callerinfo.ntype = INFO_NTYPE_SUBSCRIBER;
569 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
572 p_callerinfo.isdn_port = p_m_portnum;
573 SCPY(p_callerinfo.interface, p_m_mISDNport->ifport->interface->name);
575 /* dialing information */
576 SCAT(p_dialinginfo.id, (char *)keypad);
580 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
583 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
586 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
589 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
594 switch (redir_present)
597 p_redirinfo.present = INFO_PRESENT_RESTRICTED;
600 p_redirinfo.present = INFO_PRESENT_NOTAVAIL;
603 p_redirinfo.present = INFO_PRESENT_ALLOWED;
606 switch (redir_screen)
609 p_redirinfo.screen = INFO_SCREEN_USER;
612 p_redirinfo.screen = INFO_SCREEN_NETWORK;
615 switch (redir_reason)
618 p_redirinfo.reason = INFO_REDIR_BUSY;
621 p_redirinfo.reason = INFO_REDIR_NORESPONSE;
624 p_redirinfo.reason = INFO_REDIR_UNCONDITIONAL;
627 p_redirinfo.reason = INFO_REDIR_CALLDEFLECT;
630 p_redirinfo.reason = INFO_REDIR_OUTOFORDER;
633 p_redirinfo.reason = INFO_REDIR_UNKNOWN;
639 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
640 p_redirinfo.present = INFO_PRESENT_NULL; /* not redirecting */
641 p_redirinfo.reason = INFO_REDIR_UNKNOWN;
644 p_redirinfo.ntype = INFO_NTYPE_INTERNATIONAL;
647 p_redirinfo.ntype = INFO_NTYPE_NATIONAL;
650 p_redirinfo.ntype = INFO_NTYPE_SUBSCRIBER;
653 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
656 p_redirinfo.isdn_port = p_m_portnum;
658 /* bearer capability */
659 switch (bearer_capability)
662 p_capainfo.bearer_capa = INFO_BC_AUDIO;
663 bearer_user = (options.law=='a')?3:2;
666 p_capainfo.bearer_capa = bearer_capability;
672 p_capainfo.bearer_mode = INFO_BMODE_PACKET;
675 p_capainfo.bearer_mode = INFO_BMODE_CIRCUIT;
681 p_capainfo.bearer_info1 = INFO_INFO1_NONE;
684 p_capainfo.bearer_info1 = bearer_user + 0x80;
692 p_capainfo.hlc = INFO_HLC_NONE;
695 p_capainfo.hlc = hlc_hlc + 0x80;
701 p_capainfo.exthlc = INFO_HLC_NONE;
704 p_capainfo.exthlc = hlc_exthlc + 0x80;
709 ret = channel = hunt_bchannel(channel, exclusive);
714 ret = seize_bchannel(channel, 1);
718 RELEASE_COMPLETE_t *release_complete;
720 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
721 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
722 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
723 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
725 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
726 new_state(PORT_STATE_RELEASE);
730 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
732 /* create endpoint */
734 FATAL("Incoming call but already got an endpoint.\n");
735 if (!(epoint = new Endpoint(p_serial, 0)))
736 FATAL("No memory for Endpoint instance\n");
737 if (!(epoint->ep_app = new DEFAULT_ENDPOINT_APP(epoint, 0))) //incoming
738 FATAL("No memory for Endpoint Application instance\n");
739 epointlist_new(epoint->ep_serial);
741 /* send setup message to endpoit */
742 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_SETUP);
743 message->param.setup.isdn_port = p_m_portnum;
744 message->param.setup.port_type = p_type;
745 message->param.setup.dtmf = !p_m_mISDNport->ifport->nodtmf;
746 memcpy(&message->param.setup.dialinginfo, &p_dialinginfo, sizeof(struct dialing_info));
747 memcpy(&message->param.setup.callerinfo, &p_callerinfo, sizeof(struct caller_info));
748 memcpy(&message->param.setup.redirinfo, &p_redirinfo, sizeof(struct redir_info));
749 memcpy(&message->param.setup.capainfo, &p_capainfo, sizeof(struct capa_info));
750 memcpy(message->param.setup.useruser.data, &useruser, useruser_len);
751 message->param.setup.useruser.len = useruser_len;
752 message->param.setup.useruser.protocol = useruser_protocol;
753 message_put(message);
755 new_state(PORT_STATE_IN_SETUP);
758 /* CC_INFORMATION INDICATION */
759 void Pdss1::information_ind(unsigned long prim, unsigned long dinfo, void *data)
761 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
762 INFORMATION_t *information = (INFORMATION_t *)((unsigned long)data + headerlen);
764 unsigned char keypad[32] = "";
765 struct message *message;
767 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
768 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));
769 dec_ie_keypad(information->KEYPAD, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)keypad, sizeof(keypad));
770 dec_ie_complete(information->COMPLETE, (Q931_info_t *)((unsigned long)data+headerlen), &p_dialinginfo.sending_complete);
773 SCAT(p_dialinginfo.id, (char *)keypad);
777 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
780 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
783 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
786 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
789 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_INFORMATION);
790 memcpy(&message->param.information, &p_dialinginfo, sizeof(struct dialing_info));
791 message_put(message);
792 /* reset overlap timeout */
796 /* CC_SETUP_ACCNOWLEDGE INDICATION */
797 void Pdss1::setup_acknowledge_ind(unsigned long prim, unsigned long dinfo, void *data)
799 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
800 SETUP_ACKNOWLEDGE_t *setup_acknowledge = (SETUP_ACKNOWLEDGE_t *)((unsigned long)data + headerlen);
801 int exclusive, channel;
802 int coding, location, progress;
804 struct message *message;
806 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
807 dec_ie_channel_id(setup_acknowledge->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
808 dec_ie_progress(setup_acknowledge->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
811 /* process channel */
812 ret = received_first_reply_to_setup(prim, channel, exclusive);
815 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
816 message->param.disconnectinfo.cause = -ret;
817 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
818 message_put(message);
819 new_state(PORT_STATE_RELEASE);
824 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_OVERLAP);
825 message_put(message);
827 new_state(PORT_STATE_OUT_OVERLAP);
830 /* CC_PROCEEDING INDICATION */
831 void Pdss1::proceeding_ind(unsigned long prim, unsigned long dinfo, void *data)
833 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
834 CALL_PROCEEDING_t *proceeding = (CALL_PROCEEDING_t *)((unsigned long)data + headerlen);
835 int exclusive, channel;
836 int coding, location, progress;
838 struct message *message;
839 int notify = -1, type, plan, present;
842 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
843 dec_ie_channel_id(proceeding->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
844 dec_ie_progress(proceeding->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
845 dec_ie_notify(NULL/*proceeding->NOTIFY*/, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
846 dec_ie_redir_dn(proceeding->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
849 ret = received_first_reply_to_setup(prim, channel, exclusive);
852 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
853 message->param.disconnectinfo.cause = -ret;
854 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
855 message_put(message);
856 new_state(PORT_STATE_RELEASE);
860 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROCEEDING);
861 message_put(message);
863 new_state(PORT_STATE_OUT_PROCEEDING);
869 if (type >= 0 || notify)
871 if (!notify && type >= 0)
873 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
874 message->param.notifyinfo.notify = notify;
875 SCPY(message->param.notifyinfo.id, redir);
876 /* redirection number */
880 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
883 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
886 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
892 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
893 message->param.notifyinfo.present = INFO_PRESENT_NULL;
896 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
899 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
902 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
905 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
908 message->param.notifyinfo.isdn_port = p_m_portnum;
909 message_put(message);
913 /* CC_ALERTING INDICATION */
914 void Pdss1::alerting_ind(unsigned long prim, unsigned long dinfo, void *data)
916 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
917 ALERTING_t *alerting = (ALERTING_t *)((unsigned long)data + headerlen);
918 int exclusive, channel;
919 int coding, location, progress;
921 struct message *message;
922 int notify = -1, type, plan, present;
925 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
926 dec_ie_channel_id(alerting->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
927 dec_ie_progress(alerting->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
928 dec_ie_notify(NULL/*alerting->NOTIFY*/, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
929 dec_ie_redir_dn(alerting->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
932 /* process channel */
933 ret = received_first_reply_to_setup(prim, channel, exclusive);
936 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
937 message->param.disconnectinfo.cause = -ret;
938 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
939 message_put(message);
940 new_state(PORT_STATE_RELEASE);
944 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_ALERTING);
945 message_put(message);
947 new_state(PORT_STATE_OUT_ALERTING);
953 if (type >= 0 || notify)
955 if (!notify && type >= 0)
957 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
958 message->param.notifyinfo.notify = notify;
959 SCPY(message->param.notifyinfo.id, redir);
963 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
966 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
969 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
975 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
976 message->param.notifyinfo.present = INFO_PRESENT_NULL;
979 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
982 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
985 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
988 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
991 message->param.notifyinfo.isdn_port = p_m_portnum;
992 message_put(message);
996 /* CC_CONNECT INDICATION */
997 void Pdss1::connect_ind(unsigned long prim, unsigned long dinfo, void *data)
999 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1000 CONNECT_t *connect = (CONNECT_t *)((unsigned long)data + headerlen);
1001 int exclusive, channel;
1002 int type, plan, present, screen;
1005 struct message *message;
1006 int bchannel_before;
1007 CONNECT_ACKNOWLEDGE_t *connect_acknowledge;
1010 p_m_d_ces = connect->ces;
1012 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1013 dec_ie_channel_id(connect->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
1014 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));
1015 /* te-mode: CONP (connected name identification presentation) */
1017 dec_facility_centrex(connect->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)p_connectinfo.name, sizeof(p_connectinfo.name));
1020 /* select channel */
1021 bchannel_before = p_m_b_channel;
1022 ret = received_first_reply_to_setup(prim, channel, exclusive);
1025 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1026 message->param.disconnectinfo.cause = -ret;
1027 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1028 message_put(message);
1029 new_state(PORT_STATE_RELEASE);
1034 /* connect information */
1038 p_connectinfo.present = INFO_PRESENT_RESTRICTED;
1041 p_connectinfo.present = INFO_PRESENT_NOTAVAIL;
1044 p_connectinfo.present = INFO_PRESENT_ALLOWED;
1050 p_connectinfo.screen = INFO_SCREEN_USER;
1053 p_connectinfo.screen = INFO_SCREEN_NETWORK;
1059 p_connectinfo.present = INFO_PRESENT_NULL; /* no COLP info */
1060 p_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1063 p_connectinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1066 p_connectinfo.ntype = INFO_NTYPE_NATIONAL;
1069 p_connectinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1072 p_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1075 p_connectinfo.isdn_port = p_m_portnum;
1076 SCPY(p_connectinfo.interface, p_m_mISDNport->ifport->interface->name);
1078 /* only in nt-mode we send connect ack. in te-mode it is done by stack itself or optional */
1081 /* send connect acknowledge */
1082 dmsg = create_l3msg(CC_CONNECT | RESPONSE, MT_CONNECT, dinfo, sizeof(CONNECT_ACKNOWLEDGE_t), p_m_d_ntmode);
1083 connect_acknowledge = (CONNECT_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1084 l1l2l3_trace_header(p_m_mISDNport, this, CC_CONNECT | RESPONSE, DIRECTION_OUT);
1085 /* if we had no bchannel before, we send it now */
1086 if (!bchannel_before && p_m_b_channel)
1087 enc_ie_channel_id(&connect_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
1089 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1092 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CONNECT);
1093 memcpy(&message->param.connectinfo, &p_connectinfo, sizeof(struct connect_info));
1094 message_put(message);
1096 new_state(PORT_STATE_CONNECT);
1099 /* CC_DISCONNECT INDICATION */
1100 void Pdss1::disconnect_ind(unsigned long prim, unsigned long dinfo, void *data)
1102 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1103 DISCONNECT_t *disconnect = (DISCONNECT_t *)((unsigned long)data + headerlen);
1104 int location, cause;
1105 int coding, proglocation, progress;
1106 struct message *message;
1108 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1109 dec_ie_progress(disconnect->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &proglocation, &progress);
1110 dec_ie_cause(disconnect->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1112 if (location == LOCATION_PRIVATE_LOCAL)
1113 location = LOCATION_PRIVATE_REMOTE;
1118 /* release if remote sends us no tones */
1119 if (!p_m_mISDNport->earlyb)
1124 dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, dinfo, sizeof(RELEASE_t), p_m_d_ntmode);
1125 release = (RELEASE_t *)(dmsg->data + headerlen);
1126 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE | REQUEST, DIRECTION_OUT);
1127 enc_ie_cause(&release->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16); /* normal */
1128 add_trace("reason", NULL, "no remote patterns");
1130 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1132 /* sending release to endpoint */
1135 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1136 message->param.disconnectinfo.cause = cause;
1137 message->param.disconnectinfo.location = location;
1138 message_put(message);
1140 free_epointlist(p_epointlist);
1142 new_state(PORT_STATE_RELEASE);
1147 /* sending disconnect to active endpoint and release to inactive endpoints */
1148 if (ACTIVE_EPOINT(p_epointlist))
1150 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DISCONNECT);
1151 message->param.disconnectinfo.location = location;
1152 message->param.disconnectinfo.cause = cause;
1153 message_put(message);
1155 while(INACTIVE_EPOINT(p_epointlist))
1157 message = message_create(p_serial, INACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1158 message->param.disconnectinfo.location = location;
1159 message->param.disconnectinfo.cause = cause;
1160 message_put(message);
1162 free_epointid(INACTIVE_EPOINT(p_epointlist));
1164 new_state(PORT_STATE_IN_DISCONNECT);
1167 /* CC_DISCONNECT INDICATION */
1168 void Pdss1::disconnect_ind_i(unsigned long prim, unsigned long dinfo, void *data)
1170 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1171 DISCONNECT_t *disconnect = (DISCONNECT_t *)((unsigned long)data + headerlen);
1172 int location, cause;
1175 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1176 if (p_m_d_collect_cause > 0)
1178 add_trace("old-cause", "location", "%d", p_m_d_collect_location);
1179 add_trace("old-cause", "value", "%d", p_m_d_collect_cause);
1181 dec_ie_cause(disconnect->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1182 if (location == LOCATION_PRIVATE_LOCAL)
1183 location = LOCATION_PRIVATE_REMOTE;
1186 collect_cause(&p_m_d_collect_cause, &p_m_d_collect_location, cause, location);
1187 add_trace("new-cause", "location", "%d", p_m_d_collect_location);
1188 add_trace("new-cause", "value", "%d", p_m_d_collect_cause);
1193 /* CC_RELEASE INDICATION */
1194 void Pdss1::release_ind(unsigned long prim, unsigned long dinfo, void *data)
1196 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1197 RELEASE_t *release = (RELEASE_t *)((unsigned long)data + headerlen);
1199 int location, cause;
1200 struct message *message;
1202 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1203 dec_ie_cause(release->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1205 if (location == LOCATION_PRIVATE_LOCAL)
1206 location = LOCATION_PRIVATE_REMOTE;
1211 /* sending release to endpoint */
1214 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1215 message->param.disconnectinfo.cause = cause;
1216 message->param.disconnectinfo.location = location;
1217 message_put(message);
1219 free_epointlist(p_epointlist);
1222 /* only in NT mode we must send release_complete, if we got a release confirm */
1223 if (prim == (CC_RELEASE | CONFIRM))
1225 /* sending release complete */
1226 RELEASE_COMPLETE_t *release_complete;
1228 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
1229 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
1230 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
1231 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16);
1233 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1236 new_state(PORT_STATE_RELEASE);
1240 /* CC_RELEASE_COMPLETE INDICATION (a reject) */
1241 void Pdss1::release_complete_ind(unsigned long prim, unsigned long dinfo, void *data)
1243 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1244 RELEASE_COMPLETE_t *release_complete = (RELEASE_COMPLETE_t *)((unsigned long)data + headerlen);
1245 int location, cause;
1246 struct message *message;
1248 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1249 dec_ie_cause(release_complete->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1251 if (location == LOCATION_PRIVATE_LOCAL)
1252 location = LOCATION_PRIVATE_REMOTE;
1257 /* sending release to endpoint */
1260 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1261 message->param.disconnectinfo.cause = cause;
1262 message->param.disconnectinfo.location = location;
1263 message_put(message);
1265 free_epointlist(p_epointlist);
1268 new_state(PORT_STATE_RELEASE);
1273 void Pdss1::t312_timeout(unsigned long prim, unsigned long dinfo, void *data)
1275 struct message *message;
1277 // trace is done at message_isdn()
1279 /* sending release to endpoint */
1282 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1283 if (p_m_d_collect_cause)
1285 message->param.disconnectinfo.cause = p_m_d_collect_cause;
1286 message->param.disconnectinfo.location = p_m_d_collect_location;
1289 message->param.disconnectinfo.cause = CAUSE_NOUSER;
1290 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1292 message_put(message);
1294 free_epointlist(p_epointlist);
1297 new_state(PORT_STATE_RELEASE);
1301 /* CC_NOTIFY INDICATION */
1302 void Pdss1::notify_ind(unsigned long prim, unsigned long dinfo, void *data)
1304 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1305 NOTIFY_t *notifying = (NOTIFY_t *)((unsigned long)data + headerlen);
1306 struct message *message;
1307 int notify, type, plan, present;
1308 unsigned char notifyid[sizeof(message->param.notifyinfo.id)];
1310 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1311 dec_ie_notify(notifying->NOTIFY, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
1312 dec_ie_redir_dn(notifying->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, notifyid, sizeof(notifyid));
1315 if (!ACTIVE_EPOINT(p_epointlist))
1317 /* notification indicator */
1321 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1322 message->param.notifyinfo.notify = notify;
1323 SCPY(message->param.notifyinfo.id, (char *)notifyid);
1324 /* redirection number */
1328 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1331 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1334 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1340 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1341 message->param.notifyinfo.present = INFO_PRESENT_NULL;
1344 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1347 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1350 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1353 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1356 message->param.notifyinfo.isdn_port = p_m_portnum;
1357 message_put(message);
1361 /* CC_HOLD INDICATION */
1362 void Pdss1::hold_ind(unsigned long prim, unsigned long dinfo, void *data)
1364 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1365 // HOLD_t *hold = (HOLD_t *)((unsigned long)data + headerlen);
1366 struct message *message;
1367 HOLD_REJECT_t *hold_reject;
1368 HOLD_ACKNOWLEDGE_t *hold_acknowledge;
1370 // class Endpoint *epoint;
1372 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1375 if (!ACTIVE_EPOINT(p_epointlist) || p_m_hold)
1377 dmsg = create_l3msg(CC_HOLD_REJECT | REQUEST, MT_HOLD_REJECT, dinfo, sizeof(HOLD_REJECT_t), p_m_d_ntmode);
1378 hold_reject = (HOLD_REJECT_t *)(dmsg->data + headerlen);
1379 l1l2l3_trace_header(p_m_mISDNport, this, CC_HOLD_REJECT | REQUEST, DIRECTION_OUT);
1380 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 */
1381 add_trace("reason", NULL, "no endpoint");
1383 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1388 /* notify the hold of call */
1389 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1390 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_HOLD;
1391 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1392 message_put(message);
1394 /* deactivate bchannel */
1395 chan_trace_header(p_m_mISDNport, this, "CHANNEL RELEASE (hold)", DIRECTION_NONE);
1396 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1400 /* set hold state */
1403 epoint = find_epoint_id(ACTIVE_EPOINT(p_epointlist));
1404 if (epoint && p_m_d_ntmode)
1406 p_m_timeout = p_settings.tout_hold;
1411 /* acknowledge hold */
1412 dmsg = create_l3msg(CC_HOLD_ACKNOWLEDGE | REQUEST, MT_HOLD_ACKNOWLEDGE, dinfo, sizeof(HOLD_ACKNOWLEDGE_t), p_m_d_ntmode);
1413 hold_acknowledge = (HOLD_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1414 l1l2l3_trace_header(p_m_mISDNport, this, CC_HOLD_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1416 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1420 /* CC_RETRIEVE INDICATION */
1421 void Pdss1::retrieve_ind(unsigned long prim, unsigned long dinfo, void *data)
1423 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1424 RETRIEVE_t *retrieve = (RETRIEVE_t *)((unsigned long)data + headerlen);
1425 RETRIEVE_REJECT_t *retrieve_reject;
1426 RETRIEVE_ACKNOWLEDGE_t *retrieve_acknowledge;
1427 struct message *message;
1428 int channel, exclusive, cause;
1432 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1433 dec_ie_channel_id(retrieve->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
1438 cause = 101; /* incompatible state */
1441 dmsg = create_l3msg(CC_RETRIEVE_REJECT | REQUEST, MT_RETRIEVE_REJECT, dinfo, sizeof(RETRIEVE_REJECT_t), p_m_d_ntmode);
1442 retrieve_reject = (RETRIEVE_REJECT_t *)(dmsg->data + headerlen);
1443 l1l2l3_trace_header(p_m_mISDNport, this, CC_RETRIEVE_REJECT | REQUEST, DIRECTION_OUT);
1444 enc_ie_cause(&retrieve_reject->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, cause);
1446 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1451 /* notify the retrieve of call */
1452 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1453 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_RETRIEVAL;
1454 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1455 message_put(message);
1458 ret = channel = hunt_bchannel(channel, exclusive);
1463 ret = seize_bchannel(channel, 1);
1470 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
1472 /* set hold state */
1476 /* acknowledge retrieve */
1477 dmsg = create_l3msg(CC_RETRIEVE_ACKNOWLEDGE | REQUEST, MT_RETRIEVE_ACKNOWLEDGE, dinfo, sizeof(RETRIEVE_ACKNOWLEDGE_t), p_m_d_ntmode);
1478 retrieve_acknowledge = (RETRIEVE_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1479 l1l2l3_trace_header(p_m_mISDNport, this, CC_RETRIEVE_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1480 enc_ie_channel_id(&retrieve_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
1482 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1485 /* CC_SUSPEND INDICATION */
1486 void Pdss1::suspend_ind(unsigned long prim, unsigned long dinfo, void *data)
1488 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1489 SUSPEND_t *suspend = (SUSPEND_t *)((unsigned long)data + headerlen);
1490 SUSPEND_ACKNOWLEDGE_t *suspend_acknowledge;
1491 SUSPEND_REJECT_t *suspend_reject;
1492 struct message *message;
1493 class Endpoint *epoint;
1494 unsigned char callid[8];
1497 int ret = -31; /* normal, unspecified */
1499 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1500 dec_ie_call_id(suspend->CALL_ID, (Q931_info_t *)((unsigned long)data+headerlen), callid, &len);
1503 if (!ACTIVE_EPOINT(p_epointlist))
1506 dmsg = create_l3msg(CC_SUSPEND_REJECT | REQUEST, MT_SUSPEND_REJECT, dinfo, sizeof(SUSPEND_REJECT_t), p_m_d_ntmode);
1507 suspend_reject = (SUSPEND_REJECT_t *)(dmsg->data + headerlen);
1508 l1l2l3_trace_header(p_m_mISDNport, this, CC_SUSPEND_REJECT | REQUEST, DIRECTION_OUT);
1509 enc_ie_cause(&suspend_reject->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1511 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1519 /* check if call id is in use */
1520 epoint = epoint_first;
1523 if (epoint->ep_park)
1525 if (epoint->ep_park_len == len)
1526 if (!memcmp(epoint->ep_park_callid, callid, len))
1528 ret = -84; /* call id in use */
1532 epoint = epoint->next;
1535 /* notify the hold of call */
1536 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1537 message->param.notifyinfo.notify = INFO_NOTIFY_USER_SUSPENDED;
1538 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1539 message_put(message);
1541 /* deactivate bchannel */
1542 chan_trace_header(p_m_mISDNport, this, "CHANNEL RELEASE (suspend)", DIRECTION_NONE);
1543 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1547 /* sending suspend to endpoint */
1548 while (p_epointlist)
1550 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_SUSPEND);
1551 memcpy(message->param.parkinfo.callid, callid, sizeof(message->param.parkinfo.callid));
1552 message->param.parkinfo.len = len;
1553 message_put(message);
1555 free_epointlist(p_epointlist);
1558 /* sending SUSPEND_ACKNOWLEDGE */
1559 dmsg = create_l3msg(CC_SUSPEND_ACKNOWLEDGE | REQUEST, MT_SUSPEND_ACKNOWLEDGE, dinfo, sizeof(SUSPEND_ACKNOWLEDGE_t), p_m_d_ntmode);
1560 suspend_acknowledge = (SUSPEND_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1561 l1l2l3_trace_header(p_m_mISDNport, this, CC_SUSPEND_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1563 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1565 new_state(PORT_STATE_RELEASE);
1569 /* CC_RESUME INDICATION */
1570 void Pdss1::resume_ind(unsigned long prim, unsigned long dinfo, void *data)
1572 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1573 RESUME_t *resume = (RESUME_t *)((unsigned long)data + headerlen);
1574 RESUME_REJECT_t *resume_reject;
1575 RESUME_ACKNOWLEDGE_t *resume_acknowledge;
1576 unsigned char callid[8];
1578 int channel, exclusive;
1580 class Endpoint *epoint;
1581 struct message *message;
1584 /* callref from nt-lib */
1587 /* nt-library now gives us the id via CC_RESUME */
1588 if (dinfo&(~0xff) == 0xff00)
1589 FATAL("l3-stack gives us a process id 0xff00-0xffff\n");
1590 l1l2l3_trace_header(p_m_mISDNport, this, CC_NEW_CR | INDICATION, DIRECTION_IN);
1592 add_trace("callref", "old", "0x%x", p_m_d_l3id);
1593 add_trace("callref", "new", "0x%x", dinfo);
1595 if (p_m_d_l3id&(~0xff) == 0xff00)
1596 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
1598 p_m_d_ces = resume->ces;
1601 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1602 dec_ie_call_id(resume->CALL_ID, (Q931_info_t *)((unsigned long)data+headerlen), callid, &len);
1605 /* if blocked, release call */
1606 if (p_m_mISDNport->ifport->block)
1615 /* channel_id (no channel is possible in message) */
1617 channel = -1; /* any channel */
1620 ret = channel = hunt_bchannel(channel, exclusive);
1625 ret = seize_bchannel(channel, 1);
1630 dmsg = create_l3msg(CC_RESUME_REJECT | REQUEST, MT_RESUME_REJECT, dinfo, sizeof(RESUME_REJECT_t), p_m_d_ntmode);
1631 resume_reject = (RESUME_REJECT_t *)(dmsg->data + headerlen);
1632 l1l2l3_trace_header(p_m_mISDNport, this, CC_RESUME_REJECT | REQUEST, DIRECTION_OUT);
1633 enc_ie_cause(&resume_reject->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1635 add_trace("reason", NULL, "port blocked");
1637 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1638 new_state(PORT_STATE_RELEASE);
1642 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
1644 /* create endpoint */
1646 FATAL("Incoming resume but already got an endpoint.\n");
1647 ret = -85; /* no call suspended */
1648 epoint = epoint_first;
1651 if (epoint->ep_park)
1653 ret = -83; /* suspended call exists, but this not */
1654 if (epoint->ep_park_len == len)
1655 if (!memcmp(epoint->ep_park_callid, callid, len))
1658 epoint = epoint->next;
1663 epointlist_new(epoint->ep_serial);
1664 if (!(epoint->portlist_new(p_serial, p_type, p_m_mISDNport->earlyb)))
1665 FATAL("No memory for portlist\n");
1666 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RESUME);
1667 message_put(message);
1669 /* notify the resume of call */
1670 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1671 message->param.notifyinfo.notify = INFO_NOTIFY_USER_RESUMED;
1672 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1673 message_put(message);
1675 /* sending RESUME_ACKNOWLEDGE */
1676 dmsg = create_l3msg(CC_RESUME_ACKNOWLEDGE | REQUEST, MT_RESUME_ACKNOWLEDGE, dinfo, sizeof(RESUME_ACKNOWLEDGE_t), p_m_d_ntmode);
1677 resume_acknowledge = (RESUME_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1678 l1l2l3_trace_header(p_m_mISDNport, this, CC_RESUME_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1679 enc_ie_channel_id(&resume_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
1681 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1683 new_state(PORT_STATE_CONNECT);
1687 /* CC_FACILITY INDICATION */
1688 void Pdss1::facility_ind(unsigned long prim, unsigned long dinfo, void *data)
1690 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1691 FACILITY_t *facility = (FACILITY_t *)((unsigned long)data + headerlen);
1692 unsigned char facil[256];
1694 struct message *message;
1696 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1697 dec_ie_facility(facility->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), facil, &facil_len);
1704 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_FACILITY);
1705 message->param.facilityinfo.len = facil_len;
1706 memcpy(message->param.facilityinfo.data, facil, facil_len);
1707 message_put(message);
1712 * handler for isdn connections
1713 * incoming information are parsed and sent via message to the endpoint
1715 void Pdss1::message_isdn(unsigned long prim, unsigned long dinfo, void *data)
1722 case CC_TIMEOUT | INDICATION:
1725 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1726 timer_hex = *((int *)(((char *)data)+headerlen));
1728 if (timer_hex==0x312 && p_m_d_ntmode)
1730 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1731 add_trace("timer", NULL, "%x", timer_hex);
1733 t312_timeout(prim, dinfo, data);
1737 case CC_SETUP | INDICATION:
1738 if (p_state != PORT_STATE_IDLE)
1740 setup_ind(prim, dinfo, data);
1743 case CC_SETUP | CONFIRM:
1746 l1l2l3_trace_header(p_m_mISDNport, this, CC_NEW_CR | INDICATION, DIRECTION_IN);
1747 add_trace("callref", "old", "0x%x", p_m_d_l3id);
1748 /* nt-library now gives us a new id via CC_SETUP_CONFIRM */
1749 if ((p_m_d_l3id&0xff00) != 0xff00)
1750 PERROR(" strange setup-procid 0x%x\n", p_m_d_l3id);
1751 p_m_d_l3id = *((int *)(((u_char *)data)+ mISDNUSER_HEAD_SIZE));
1752 add_trace("callref", "new", "0x%x", p_m_d_l3id);
1757 case CC_INFORMATION | INDICATION:
1758 information_ind(prim, dinfo, data);
1761 case CC_SETUP_ACKNOWLEDGE | INDICATION:
1762 if (p_state != PORT_STATE_OUT_SETUP)
1764 PERROR("Pdss1(%s) received setup_acknowledge, but we are not in outgoing setup state, IGNORING.\n", p_name);
1767 setup_acknowledge_ind(prim, dinfo, data);
1770 case CC_PROCEEDING | INDICATION:
1771 if (p_state != PORT_STATE_OUT_SETUP
1772 && p_state != PORT_STATE_OUT_OVERLAP)
1774 PERROR("Pdss1(%s) received proceeding, but we are not in outgoing setup OR overlap state, IGNORING.\n", p_name);
1777 proceeding_ind(prim, dinfo, data);
1780 case CC_ALERTING | INDICATION:
1781 if (p_state != PORT_STATE_OUT_SETUP
1782 && p_state != PORT_STATE_OUT_OVERLAP
1783 && p_state != PORT_STATE_OUT_PROCEEDING)
1785 PERROR("Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding state, IGNORING.\n", p_name);
1788 alerting_ind(prim, dinfo, data);
1791 case CC_CONNECT | INDICATION:
1792 if (p_state != PORT_STATE_OUT_SETUP
1793 && p_state != PORT_STATE_OUT_OVERLAP
1794 && p_state != PORT_STATE_OUT_PROCEEDING
1795 && p_state != PORT_STATE_OUT_ALERTING)
1797 PERROR("Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding OR ALERTING state, IGNORING.\n", p_name);
1800 connect_ind(prim, dinfo, data);
1801 if (p_m_d_notify_pending)
1803 /* send pending notify message during connect */
1804 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
1805 message_free(p_m_d_notify_pending);
1806 p_m_d_notify_pending = NULL;
1810 case CC_CONNECT_ACKNOWLEDGE | INDICATION:
1811 case CC_CONNECT | CONFIRM:
1812 if (p_state == PORT_STATE_CONNECT_WAITING)
1813 new_state(PORT_STATE_CONNECT);
1814 if (p_m_d_notify_pending)
1816 /* send pending notify message during connect-ack */
1817 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
1818 message_free(p_m_d_notify_pending);
1819 p_m_d_notify_pending = NULL;
1823 case CC_DISCONNECT | INDICATION:
1824 disconnect_ind(prim, dinfo, data);
1827 case CC_RELEASE | CONFIRM:
1828 case CC_RELEASE | INDICATION:
1829 release_ind(prim, dinfo, data);
1832 case CC_RELEASE_COMPLETE | INDICATION:
1833 release_complete_ind(prim, dinfo, data);
1836 case CC_RELEASE_COMPLETE | CONFIRM:
1839 case CC_NOTIFY | INDICATION:
1840 notify_ind(prim, dinfo, data);
1843 case CC_HOLD | INDICATION:
1844 hold_ind(prim, dinfo, data);
1847 case CC_RETRIEVE | INDICATION:
1848 retrieve_ind(prim, dinfo, data);
1851 case CC_SUSPEND | INDICATION:
1852 suspend_ind(prim, dinfo, data);
1855 case CC_RESUME | INDICATION:
1856 resume_ind(prim, dinfo, data);
1859 case CC_FACILITY | INDICATION:
1860 facility_ind(prim, dinfo, data);
1863 case CC_RELEASE_CR | INDICATION:
1864 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_CR | INDICATION, DIRECTION_IN);
1865 add_trace("callref", NULL, "0x%x", p_m_d_l3id);
1869 if ((p_m_d_l3id&0xff00) == 0xff00)
1870 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
1874 //#warning remove me
1875 //PDEBUG(DEBUG_LOG, "JOLLY release cr %d\n", p_serial);
1876 /* sending release to endpoint in case we still have an endpoint
1877 * this is because we don't get any response if a release_complete is received (or a release in release state)
1881 struct message *message;
1882 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1883 message->param.disconnectinfo.cause = (p_m_d_collect_cause!=CAUSE_NOUSER)?p_m_d_collect_cause:CAUSE_UNSPECIFIED;
1884 message->param.disconnectinfo.location = (p_m_d_collect_cause!=CAUSE_NOUSER)?p_m_d_collect_location:LOCATION_PRIVATE_LOCAL;
1885 message_put(message);
1887 free_epointlist(p_epointlist);
1889 new_state(PORT_STATE_RELEASE);
1893 case CC_NEW_CR | INDICATION:
1894 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1896 add_trace("callref", "old", "0x%x", p_m_d_l3id);
1899 new_l3id = *((int *)(((u_char *)data+mISDNUSER_HEAD_SIZE)));
1900 if (((new_l3id&0xff00)!=0xff00) && ((p_m_d_l3id&0xff00)==0xff00))
1901 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
1906 p_m_d_l3id = new_l3id;
1907 add_trace("callref", "new", "0x%x", p_m_d_l3id);
1912 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1913 add_trace("unhandled", "prim", "0x%x", prim);
1918 void Pdss1::new_state(int state)
1920 class Endpoint *epoint;
1923 if (state == PORT_STATE_IN_OVERLAP)
1925 p_m_timeout = p_m_mISDNport->ifport->tout_dialing;
1928 if (state != p_state)
1930 if (state == PORT_STATE_IN_SETUP
1931 || state == PORT_STATE_OUT_SETUP
1932 || state == PORT_STATE_IN_OVERLAP
1933 || state == PORT_STATE_OUT_OVERLAP)
1935 p_m_timeout = p_m_mISDNport->ifport->tout_setup;
1938 if (state == PORT_STATE_IN_PROCEEDING
1939 || state == PORT_STATE_OUT_PROCEEDING)
1941 p_m_timeout = p_m_mISDNport->ifport->tout_proceeding;
1944 if (state == PORT_STATE_IN_ALERTING
1945 || state == PORT_STATE_OUT_ALERTING)
1947 p_m_timeout = p_m_mISDNport->ifport->tout_alerting;
1950 if (state == PORT_STATE_CONNECT
1951 || state == PORT_STATE_CONNECT_WAITING)
1955 if (state == PORT_STATE_IN_DISCONNECT
1956 || state == PORT_STATE_OUT_DISCONNECT)
1958 p_m_timeout = p_m_mISDNport->ifport->tout_disconnect;
1963 Port::new_state(state);
1970 int Pdss1::handler(void)
1974 //if (p_m_delete && p_m_d_l3id==0)
1975 // printf("ping! %d", p_serial);
1976 if ((ret = PmISDN::handler()))
1979 /* handle destruction */
1980 if (p_m_delete && p_m_d_l3id==0)
1983 //PDEBUG(DEBUG_LOG, "JOLLY destroy object %d\n", p_serial);
1994 * handles all messages from endpoint
1996 /* MESSAGE_INFORMATION */
1997 void Pdss1::message_information(unsigned long epoint_id, int message_id, union parameter *param)
1999 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2000 INFORMATION_t *information;
2003 if (param->information.id[0]) /* only if we have something to dial */
2005 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2006 information = (INFORMATION_t *)(dmsg->data + headerlen);
2007 l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT);
2008 enc_ie_called_pn(&information->CALLED_PN, dmsg, 0, 1, (unsigned char *)param->information.id);
2010 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2019 void Pdss1::message_setup(unsigned long epoint_id, int message_id, union parameter *param)
2021 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2022 INFORMATION_t *information;
2025 int plan, type, screen, present, reason;
2026 int capability, mode, rate, coding, user, presentation, interpretation, hlc, exthlc;
2027 int channel, exclusive;
2029 struct epoint_list *epointlist;
2031 /* release if port is blocked */
2032 if (p_m_mISDNport->ifport->block)
2034 struct message *message;
2036 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2037 message->param.disconnectinfo.cause = 27; // temp. unavail.
2038 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2039 message_put(message);
2040 new_state(PORT_STATE_RELEASE);
2045 /* copy setup infos to port */
2046 memcpy(&p_callerinfo, ¶m->setup.callerinfo, sizeof(p_callerinfo));
2047 memcpy(&p_dialinginfo, ¶m->setup.dialinginfo, sizeof(p_dialinginfo));
2048 memcpy(&p_capainfo, ¶m->setup.capainfo, sizeof(p_capainfo));
2049 memcpy(&p_redirinfo, ¶m->setup.redirinfo, sizeof(p_redirinfo));
2050 // SCPY(&p_m_tones_dir, param->setup.ext.tones_dir);
2051 /* screen outgoing caller id */
2052 do_screen(1, p_callerinfo.id, sizeof(p_callerinfo.id), &p_callerinfo.ntype, &p_callerinfo.present, p_m_mISDNport->ifport->interface);
2054 /* only display at connect state: this case happens if endpoint is in connected mode */
2055 if (p_state==PORT_STATE_CONNECT)
2057 if (p_type!=PORT_TYPE_DSS1_NT_OUT
2058 && p_type!=PORT_TYPE_DSS1_NT_IN)
2060 if (p_callerinfo.display[0])
2062 /* sending information */
2063 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2064 information = (INFORMATION_t *)(dmsg->data + headerlen);
2065 l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT);
2067 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_callerinfo.display);
2069 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2074 /* attach only if not already */
2075 epointlist = p_epointlist;
2078 if (epointlist->epoint_id == epoint_id)
2080 epointlist = epointlist->next;
2083 epointlist_new(epoint_id);
2089 channel = p_m_b_channel;
2090 exclusive = p_m_b_exclusive;
2092 channel = CHANNEL_ANY;
2093 /* nt-port with no channel, not reserverd */
2094 if (!p_m_b_channel && !p_m_b_reserve && p_type==PORT_TYPE_DSS1_NT_OUT)
2095 channel = CHANNEL_NO;
2098 l1l2l3_trace_header(p_m_mISDNport, this, CC_NEW_CR | REQUEST, DIRECTION_OUT);
2104 if (p_m_mISDNport->procids[i] == 0)
2110 struct message *message;
2112 add_trace("callref", NULL, "no free id");
2114 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2115 message->param.disconnectinfo.cause = 47;
2116 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2117 message_put(message);
2118 new_state(PORT_STATE_RELEASE);
2122 p_m_mISDNport->procids[i] = 1;
2123 p_m_d_l3id = 0xff00 | i;
2127 /* if we are in te-mode, we need to create a process first */
2128 if (newteid++ > 0x7fff)
2130 p_m_d_l3id = (entity<<16) | newteid;
2131 /* preparing message */
2132 ncr.prim = CC_NEW_CR | REQUEST;
2133 ncr.addr = p_m_mISDNport->upper_id | FLG_MSG_DOWN;
2134 ncr.dinfo = p_m_d_l3id;
2137 mISDN_write(mISDNdevice, &ncr, mISDN_HEADER_LEN+ncr.len, TIMEOUT_1SEC);
2141 add_trace("callref", "new", "0x%x", p_m_d_l3id);
2144 /* preparing setup message */
2145 dmsg = create_l3msg(CC_SETUP | REQUEST, MT_SETUP, p_m_d_l3id, sizeof(SETUP_t), p_m_d_ntmode);
2146 setup = (SETUP_t *)(dmsg->data + headerlen);
2147 l1l2l3_trace_header(p_m_mISDNport, this, CC_SETUP | REQUEST, DIRECTION_OUT);
2148 /* channel information */
2149 if (channel >= 0) /* it should */
2151 enc_ie_channel_id(&setup->CHANNEL_ID, dmsg, exclusive, channel);
2153 /* caller information */
2155 switch (p_callerinfo.ntype)
2157 case INFO_NTYPE_INTERNATIONAL:
2160 case INFO_NTYPE_NATIONAL:
2163 case INFO_NTYPE_SUBSCRIBER:
2166 default: /* INFO_NTYPE_UNKNOWN */
2170 switch (p_callerinfo.screen)
2172 case INFO_SCREEN_USER:
2175 default: /* INFO_SCREEN_NETWORK */
2179 switch (p_callerinfo.present)
2181 case INFO_PRESENT_RESTRICTED:
2184 case INFO_PRESENT_NOTAVAIL:
2187 default: /* INFO_PRESENT_ALLOWED */
2192 enc_ie_calling_pn(&setup->CALLING_PN, dmsg, type, plan, present, screen, (unsigned char *)p_callerinfo.id);
2193 /* dialing information */
2194 if (p_dialinginfo.id[0]) /* only if we have something to dial */
2196 enc_ie_called_pn(&setup->CALLED_PN, dmsg, 0, 1, (unsigned char *)p_dialinginfo.id);
2198 /* sending complete */
2199 if (p_dialinginfo.sending_complete)
2200 enc_ie_complete(&setup->COMPLETE, dmsg, 1);
2201 /* sending user-user */
2202 if (param->setup.useruser.len)
2204 enc_ie_useruser(&setup->USER_USER, dmsg, param->setup.useruser.protocol, param->setup.useruser.data, param->setup.useruser.len);
2206 /* redirecting number */
2208 switch (p_redirinfo.ntype)
2210 case INFO_NTYPE_INTERNATIONAL:
2213 case INFO_NTYPE_NATIONAL:
2216 case INFO_NTYPE_SUBSCRIBER:
2219 default: /* INFO_NTYPE_UNKNOWN */
2223 switch (p_redirinfo.screen)
2225 case INFO_SCREEN_USER:
2228 default: /* INFO_SCREE_NETWORK */
2232 switch (p_redirinfo.reason)
2234 case INFO_REDIR_BUSY:
2237 case INFO_REDIR_NORESPONSE:
2240 case INFO_REDIR_UNCONDITIONAL:
2243 case INFO_REDIR_CALLDEFLECT:
2246 case INFO_REDIR_OUTOFORDER:
2249 default: /* INFO_REDIR_UNKNOWN */
2253 switch (p_redirinfo.present)
2255 case INFO_PRESENT_NULL: /* no redir at all */
2262 case INFO_PRESENT_RESTRICTED:
2265 case INFO_PRESENT_NOTAVAIL:
2268 default: /* INFO_PRESENT_ALLOWED */
2272 /* sending redirecting number only in ntmode */
2273 if (type >= 0 && p_m_d_ntmode)
2274 enc_ie_redir_nr(&setup->REDIR_NR, dmsg, type, plan, present, screen, reason, (unsigned char *)p_redirinfo.id);
2275 /* bearer capability */
2276 //printf("hlc=%d\n",p_capainfo.hlc);
2278 capability = p_capainfo.bearer_capa;
2279 mode = p_capainfo.bearer_mode;
2280 rate = (mode==INFO_BMODE_CIRCUIT)?0x10:0x00;
2281 switch (p_capainfo.bearer_info1)
2283 case INFO_INFO1_NONE:
2287 user = p_capainfo.bearer_info1 & 0x7f;
2290 enc_ie_bearer(&setup->BEARER, dmsg, coding, capability, mode, rate, -1, user);
2297 hlc = p_capainfo.hlc & 0x7f;
2299 if (p_capainfo.exthlc)
2300 exthlc = p_capainfo.exthlc & 0x7f;
2301 enc_ie_hlc(&setup->HLC, dmsg, coding, interpretation, presentation, hlc, exthlc);
2305 if (p_callerinfo.display[0] && p_m_d_ntmode)
2306 enc_ie_display(&setup->DISPLAY, dmsg, (unsigned char *)p_callerinfo.display);
2307 /* nt-mode: CNIP (calling name identification presentation) */
2308 // if (p_callerinfo.name[0] && p_m_d_ntmode)
2309 // enc_facility_centrex(&setup->FACILITY, dmsg, (unsigned char *)p_callerinfo.name, 1);
2312 /* send setup message now */
2313 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2315 new_state(PORT_STATE_OUT_SETUP);
2318 /* MESSAGE_FACILITY */
2319 void Pdss1::message_facility(unsigned long epoint_id, int message_id, union parameter *param)
2321 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2322 FACILITY_t *facility;
2325 /* facility will not be sent to external lines */
2329 /* sending facility */
2330 dmsg = create_l3msg(CC_FACILITY | REQUEST, MT_FACILITY, p_m_d_l3id, sizeof(FACILITY_t), p_m_d_ntmode);
2331 facility = (FACILITY_t *)(dmsg->data + headerlen);
2332 l1l2l3_trace_header(p_m_mISDNport, this, CC_FACILITY | REQUEST, DIRECTION_OUT);
2333 enc_ie_facility(&facility->FACILITY, dmsg, (unsigned char *)param->facilityinfo.data, param->facilityinfo.len);
2335 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2338 /* MESSAGE_NOTIFY */
2339 void Pdss1::message_notify(unsigned long epoint_id, int message_id, union parameter *param)
2341 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2342 INFORMATION_t *information;
2343 NOTIFY_t *notification;
2345 int plan, type = -1, present;
2348 if (param->notifyinfo.notify>INFO_NOTIFY_NONE)
2349 notify = param->notifyinfo.notify & 0x7f;
2352 if (p_state != PORT_STATE_CONNECT)
2354 /* notify only allowed in active state */
2360 switch (param->notifyinfo.ntype)
2362 case INFO_NTYPE_INTERNATIONAL:
2365 case INFO_NTYPE_NATIONAL:
2368 case INFO_NTYPE_SUBSCRIBER:
2371 default: /* INFO_NTYPE_UNKNOWN */
2375 switch (param->notifyinfo.present)
2377 case INFO_PRESENT_NULL: /* no redir at all */
2382 case INFO_PRESENT_RESTRICTED:
2385 case INFO_PRESENT_NOTAVAIL:
2388 default: /* INFO_PRESENT_ALLOWED */
2394 if (notify<0 && !param->notifyinfo.display[0])
2396 /* nothing to notify, nothing to display */
2402 if (p_state!=PORT_STATE_CONNECT)
2404 /* queue notification */
2405 if (p_m_d_notify_pending)
2406 message_free(p_m_d_notify_pending);
2407 p_m_d_notify_pending = message_create(ACTIVE_EPOINT(p_epointlist), p_serial, EPOINT_TO_PORT, message_id);
2408 memcpy(&p_m_d_notify_pending->param, param, sizeof(union parameter));
2411 /* sending notification */
2412 dmsg = create_l3msg(CC_NOTIFY | REQUEST, MT_NOTIFY, p_m_d_l3id, sizeof(NOTIFY_t), p_m_d_ntmode);
2413 notification = (NOTIFY_t *)(dmsg->data + headerlen);
2414 l1l2l3_trace_header(p_m_mISDNport, this, CC_NOTIFY | REQUEST, DIRECTION_OUT);
2415 enc_ie_notify(¬ification->NOTIFY, dmsg, notify);
2416 /* sending redirection number only in ntmode */
2417 if (type >= 0 && p_m_d_ntmode)
2418 enc_ie_redir_dn(¬ification->REDIR_DN, dmsg, type, plan, present, (unsigned char *)param->notifyinfo.id);
2419 if (param->notifyinfo.display[0] && p_m_d_ntmode)
2420 enc_ie_display(¬ification->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display);
2422 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2424 } else if (p_m_d_ntmode)
2426 /* sending information */
2427 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2428 information = (INFORMATION_t *)(dmsg->data + headerlen);
2429 l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT);
2430 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display);
2432 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2436 /* MESSAGE_OVERLAP */
2437 void Pdss1::message_overlap(unsigned long epoint_id, int message_id, union parameter *param)
2439 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2440 SETUP_ACKNOWLEDGE_t *setup_acknowledge;
2443 /* sending setup_acknowledge */
2444 dmsg = create_l3msg(CC_SETUP_ACKNOWLEDGE | REQUEST, MT_SETUP_ACKNOWLEDGE, p_m_d_l3id, sizeof(SETUP_ACKNOWLEDGE_t), p_m_d_ntmode);
2445 setup_acknowledge = (SETUP_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
2446 l1l2l3_trace_header(p_m_mISDNport, this, CC_SETUP_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
2447 /* channel information */
2448 if (p_state == PORT_STATE_IN_SETUP)
2449 enc_ie_channel_id(&setup_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2450 /* progress information */
2451 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2452 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2453 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2454 if (p_m_mISDNport->tones)
2455 enc_ie_progress(&setup_acknowledge->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2457 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2459 new_state(PORT_STATE_IN_OVERLAP);
2462 /* MESSAGE_PROCEEDING */
2463 void Pdss1::message_proceeding(unsigned long epoint_id, int message_id, union parameter *param)
2465 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2466 CALL_PROCEEDING_t *proceeding;
2469 /* sending proceeding */
2470 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2471 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2472 l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2473 /* channel information */
2474 if (p_state == PORT_STATE_IN_SETUP)
2475 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2476 /* progress information */
2477 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2478 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2479 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2480 if (p_m_mISDNport->tones)
2481 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2483 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2485 new_state(PORT_STATE_IN_PROCEEDING);
2488 /* MESSAGE_ALERTING */
2489 void Pdss1::message_alerting(unsigned long epoint_id, int message_id, union parameter *param)
2491 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2492 ALERTING_t *alerting;
2495 /* NT-MODE in setup state we must send PROCEEDING first */
2496 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2498 CALL_PROCEEDING_t *proceeding;
2500 /* sending proceeding */
2501 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2502 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2503 l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2504 /* channel information */
2505 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2506 /* progress information */
2507 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2508 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2509 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2510 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2512 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2513 new_state(PORT_STATE_IN_PROCEEDING);
2516 /* sending alerting */
2517 dmsg = create_l3msg(CC_ALERTING | REQUEST, MT_ALERTING, p_m_d_l3id, sizeof(ALERTING_t), p_m_d_ntmode);
2518 alerting = (ALERTING_t *)(dmsg->data + headerlen);
2519 l1l2l3_trace_header(p_m_mISDNport, this, CC_ALERTING | REQUEST, DIRECTION_OUT);
2520 /* channel information */
2521 if (p_state == PORT_STATE_IN_SETUP)
2522 enc_ie_channel_id(&alerting->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2523 /* progress information */
2524 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2525 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2526 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2527 if (p_m_mISDNport->tones)
2528 enc_ie_progress(&alerting->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2530 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2532 new_state(PORT_STATE_IN_ALERTING);
2535 /* MESSAGE_CONNECT */
2536 void Pdss1::message_connect(unsigned long epoint_id, int message_id, union parameter *param)
2538 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2539 INFORMATION_t *information;
2541 int type, plan, present, screen;
2543 class Endpoint *epoint;
2545 /* NT-MODE in setup state we must send PROCEEDING first */
2546 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2548 CALL_PROCEEDING_t *proceeding;
2550 /* sending proceeding */
2551 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2552 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2553 l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2554 /* channel information */
2555 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2556 // /* progress information */
2557 // if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2558 // || p_capainfo.bearer_capa==INFO_BC_AUDIO
2559 // || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2560 // enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2562 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2563 new_state(PORT_STATE_IN_PROCEEDING);
2566 /* copy connected information */
2567 memcpy(&p_connectinfo, ¶m->connectinfo, sizeof(p_connectinfo));
2568 /* screen outgoing caller id */
2569 do_screen(1, p_connectinfo.id, sizeof(p_connectinfo.id), &p_connectinfo.ntype, &p_connectinfo.present, p_m_mISDNport->ifport->interface);
2571 /* only display at connect state */
2572 if (p_state == PORT_STATE_CONNECT)
2573 if (p_connectinfo.display[0])
2575 /* sending information */
2576 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2577 information = (INFORMATION_t *)(dmsg->data + headerlen);
2578 l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT);
2580 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_connectinfo.display);
2582 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2586 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)
2588 /* connect command only possible in setup, proceeding or alerting state */
2592 /* preparing connect message */
2593 dmsg = create_l3msg(CC_CONNECT | REQUEST, MT_CONNECT, p_m_d_l3id, sizeof(CONNECT_t), p_m_d_ntmode);
2594 connect = (CONNECT_t *)(dmsg->data + headerlen);
2595 l1l2l3_trace_header(p_m_mISDNport, this, CC_CONNECT | REQUEST, DIRECTION_OUT);
2596 /* connect information */
2598 switch (p_connectinfo.ntype)
2600 case INFO_NTYPE_INTERNATIONAL:
2603 case INFO_NTYPE_NATIONAL:
2606 case INFO_NTYPE_SUBSCRIBER:
2609 default: /* INFO_NTYPE_UNKNOWN */
2613 switch (param->connectinfo.screen)
2615 case INFO_SCREEN_USER:
2618 default: /* INFO_SCREE_NETWORK */
2622 switch (p_connectinfo.present)
2624 case INFO_PRESENT_NULL: /* no colp at all */
2630 case INFO_PRESENT_RESTRICTED:
2633 case INFO_PRESENT_NOTAVAIL:
2636 default: /* INFO_PRESENT_ALLOWED */
2641 enc_ie_connected_pn(&connect->CONNECT_PN, dmsg, type, plan, present, screen, (unsigned char *)p_connectinfo.id);
2643 if (p_connectinfo.display[0] && p_m_d_ntmode)
2644 enc_ie_display(&connect->DISPLAY, dmsg, (unsigned char *)p_connectinfo.display);
2645 /* nt-mode: CONP (connected name identification presentation) */
2646 // if (p_connectinfo.name[0] && p_m_d_ntmode)
2647 // enc_facility_centrex(&connect->FACILITY, dmsg, (unsigned char *)p_connectinfo.name, 0);
2651 epoint = find_epoint_id(epoint_id);
2652 enc_ie_date(&connect->DATE, dmsg, now, p_settings.no_seconds);
2655 /* finally send message */
2656 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2659 new_state(PORT_STATE_CONNECT);
2661 new_state(PORT_STATE_CONNECT_WAITING);
2665 /* MESSAGE_DISCONNECT */
2666 void Pdss1::message_disconnect(unsigned long epoint_id, int message_id, union parameter *param)
2668 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2669 DISCONNECT_t *disconnect;
2670 RELEASE_COMPLETE_t *release_complete;
2672 struct message *message;
2675 /* we reject during incoming setup when we have no tones. also if we are in outgoing setup state */
2676 // if ((p_state==PORT_STATE_IN_SETUP && !p_m_mISDNport->tones)
2677 if (/* ||*/ p_state==PORT_STATE_OUT_SETUP)
2679 /* sending release to endpoint */
2682 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
2683 message->param.disconnectinfo.cause = 16;
2684 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2685 message_put(message);
2687 free_epointlist(p_epointlist);
2689 /* sending release */
2690 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
2691 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
2692 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
2694 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);
2696 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2697 new_state(PORT_STATE_RELEASE);
2702 /* workarround: NT-MODE in setup state we must send PROCEEDING first to make it work */
2703 if (p_state==PORT_STATE_IN_SETUP)
2705 CALL_PROCEEDING_t *proceeding;
2707 /* sending proceeding */
2708 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2709 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2710 l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2711 /* channel information */
2712 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2713 /* progress information */
2714 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2715 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2716 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2717 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2719 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2720 new_state(PORT_STATE_IN_PROCEEDING);
2723 /* sending disconnect */
2724 dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode);
2725 disconnect = (DISCONNECT_t *)(dmsg->data + headerlen);
2726 l1l2l3_trace_header(p_m_mISDNport, this, CC_DISCONNECT | REQUEST, DIRECTION_OUT);
2727 /* progress information */
2728 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2729 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2730 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2731 if (p_m_mISDNport->tones)
2732 enc_ie_progress(&disconnect->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2734 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);
2736 if (param->disconnectinfo.display[0])
2737 p = param->disconnectinfo.display;
2738 if (p) if (*p && p_m_d_ntmode)
2739 enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p);
2741 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2742 new_state(PORT_STATE_OUT_DISCONNECT);
2745 /* MESSAGE_RELEASE */
2746 void Pdss1::message_release(unsigned long epoint_id, int message_id, union parameter *param)
2748 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2750 RELEASE_COMPLETE_t *release_complete;
2751 DISCONNECT_t *disconnect;
2753 class Endpoint *epoint;
2757 * we may only release during incoming disconnect state.
2758 * this means that the endpoint doesnt require audio anymore
2760 if (p_state == PORT_STATE_IN_DISCONNECT
2761 || p_state == PORT_STATE_OUT_DISCONNECT)
2763 /* sending release */
2764 dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, p_m_d_l3id, sizeof(RELEASE_t), p_m_d_ntmode);
2765 release = (RELEASE_t *)(dmsg->data + headerlen);
2766 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE | REQUEST, DIRECTION_OUT);
2768 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);
2770 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2771 new_state(PORT_STATE_RELEASE);
2773 free_epointid(epoint_id);
2774 // wait for callref to be released
2779 * if we are on incoming call setup, we may reject by sending a release_complete
2780 * also on outgoing call setup, we send a release complete, BUT this is not conform. (i don't know any other way)
2782 if (p_state==PORT_STATE_IN_SETUP
2783 || p_state==PORT_STATE_OUT_SETUP)
2784 // // NOTE: a bug in mISDNuser (see disconnect_req_out !!!)
2785 // || p_state==PORT_STATE_OUT_DISCO)
2787 //#warning remove me
2788 //PDEBUG(DEBUG_LOG, "JOLLY sending release complete %d\n", p_serial);
2789 /* sending release complete */
2790 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
2791 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
2792 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE | REQUEST, DIRECTION_OUT);
2794 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);
2796 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2797 new_state(PORT_STATE_RELEASE);
2799 free_epointid(epoint_id);
2801 /* remove process */
2802 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_CR | REQUEST, DIRECTION_OUT);
2803 add_trace("callref", NULL, "0x%x", p_m_d_l3id);
2807 if ((p_m_d_l3id&0xff00) == 0xff00)
2808 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
2813 // wait for callref to be released
2818 wirklich erst proceeding?:
2819 /* NT-MODE in setup state we must send PROCEEDING first */
2820 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2822 CALL_PROCEEDING_t *proceeding;
2824 /* sending proceeding */
2825 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2826 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2827 l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2828 /* channel information */
2829 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2830 /* progress information */
2831 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2832 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2833 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2834 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2836 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2840 /* sending disconnect */
2841 dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode);
2842 disconnect = (DISCONNECT_t *)(dmsg->data + headerlen);
2843 l1l2l3_trace_header(p_m_mISDNport, this, CC_DISCONNECT | REQUEST, DIRECTION_OUT);
2844 /* progress information */
2845 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2846 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2847 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2848 if (p_m_mISDNport->tones)
2849 enc_ie_progress(&disconnect->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2851 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);
2853 epoint = find_epoint_id(epoint_id);
2854 if (param->disconnectinfo.display[0])
2855 p = param->disconnectinfo.display;
2856 if (p) if (*p && p_m_d_ntmode)
2857 enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p);
2859 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2860 new_state(PORT_STATE_OUT_DISCONNECT);
2862 free_epointid(epoint_id);
2863 // wait for release and callref to be released
2864 //#warning remove me
2865 //PDEBUG(DEBUG_LOG, "JOLLY sending disconnect %d\n", p_serial);
2870 * endpoint sends messages to the port
2872 int Pdss1::message_epoint(unsigned long epoint_id, int message_id, union parameter *param)
2874 struct message *message;
2876 if (PmISDN::message_epoint(epoint_id, message_id, param))
2881 case MESSAGE_INFORMATION: /* overlap dialing */
2882 if (p_type==PORT_TYPE_DSS1_NT_OUT
2883 && p_state!=PORT_STATE_OUT_OVERLAP
2884 && p_state!=PORT_STATE_CONNECT
2885 && p_state!=PORT_STATE_OUT_DISCONNECT
2886 && p_state!=PORT_STATE_IN_DISCONNECT)
2890 if (p_type==PORT_TYPE_DSS1_TE_OUT
2891 && p_state!=PORT_STATE_OUT_OVERLAP
2892 && p_state!=PORT_STATE_OUT_PROCEEDING
2893 && p_state!=PORT_STATE_OUT_ALERTING
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_NT_IN || p_type==PORT_TYPE_DSS1_TE_IN)
2901 && p_state!=PORT_STATE_IN_OVERLAP
2902 && p_state!=PORT_STATE_IN_PROCEEDING
2903 && p_state!=PORT_STATE_IN_ALERTING
2904 && p_state!=PORT_STATE_CONNECT
2905 && p_state!=PORT_STATE_CONNECT_WAITING
2906 && p_state!=PORT_STATE_OUT_DISCONNECT
2907 && p_state!=PORT_STATE_IN_DISCONNECT)
2911 message_information(epoint_id, message_id, param);
2914 case MESSAGE_SETUP: /* dial-out command received from epoint */
2915 if (p_state!=PORT_STATE_IDLE
2916 && p_state!=PORT_STATE_CONNECT)
2918 PERROR("Pdss1(%s) ignoring setup because isdn port is not in idle state (or connected for sending display info).\n", p_name);
2921 if (p_epointlist && p_state==PORT_STATE_IDLE)
2922 FATAL("Pdss1(%s): epoint pointer is set in idle state, how bad!!\n", p_name);
2923 /* note: pri is a special case, because links must be up for pri */
2924 if (p_m_mISDNport->l1link || p_m_mISDNport->pri || !p_m_mISDNport->ntmode || p_state!=PORT_STATE_IDLE)
2926 /* LAYER 1 is up, or we may send */
2927 message_setup(epoint_id, message_id, param);
2930 /* LAYER 1 id down, so we queue */
2931 p_m_d_queue = message_create(epoint_id, p_serial, EPOINT_TO_PORT, message_id);
2932 memcpy(&p_m_d_queue->param, param, sizeof(union parameter));
2934 if (!(epointlist_new(epoint_id)))
2935 FATAL("No memory for epointlist\n");
2937 PDEBUG(DEBUG_ISDN, "the L1 is down, we try to establish the link NT portnum=%d (%s).\n", p_m_mISDNport->portnum, p_name);
2938 act.prim = PH_ACTIVATE | REQUEST;
2939 act.addr = p_m_mISDNport->upper_id | FLG_MSG_DOWN;
2942 mISDN_write(mISDNdevice, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
2943 l1l2l3_trace_header(p_m_mISDNport, this, act.prim, DIRECTION_OUT);
2945 // /* set timeout */
2946 // p_m_mISDNport->l1timeout = now+3;
2950 case MESSAGE_NOTIFY: /* display and notifications */
2951 message_notify(epoint_id, message_id, param);
2954 case MESSAGE_FACILITY: /* facility message */
2955 message_facility(epoint_id, message_id, param);
2958 case MESSAGE_OVERLAP: /* more information is needed */
2959 if (p_state!=PORT_STATE_IN_SETUP)
2963 message_overlap(epoint_id, message_id, param);
2966 case MESSAGE_PROCEEDING: /* call of endpoint is proceeding */
2967 if (p_state!=PORT_STATE_IN_SETUP
2968 && p_state!=PORT_STATE_IN_OVERLAP)
2972 message_proceeding(epoint_id, message_id, param);
2975 case MESSAGE_ALERTING: /* call of endpoint is ringing */
2976 if (p_state!=PORT_STATE_IN_SETUP
2977 && p_state!=PORT_STATE_IN_OVERLAP
2978 && p_state!=PORT_STATE_IN_PROCEEDING)
2982 message_alerting(epoint_id, message_id, param);
2985 case MESSAGE_CONNECT: /* call of endpoint is connected */
2986 if (p_state!=PORT_STATE_IN_SETUP
2987 && p_state!=PORT_STATE_IN_OVERLAP
2988 && p_state!=PORT_STATE_IN_PROCEEDING
2989 && p_state!=PORT_STATE_IN_ALERTING
2990 && !(p_state==PORT_STATE_CONNECT && p_m_d_ntmode))
2994 message_connect(epoint_id, message_id, param);
2997 case MESSAGE_DISCONNECT: /* call has been disconnected */
2998 if (p_state!=PORT_STATE_IN_SETUP
2999 && p_state!=PORT_STATE_IN_OVERLAP
3000 && p_state!=PORT_STATE_IN_PROCEEDING
3001 && p_state!=PORT_STATE_IN_ALERTING
3002 && p_state!=PORT_STATE_OUT_SETUP
3003 && p_state!=PORT_STATE_OUT_OVERLAP
3004 && p_state!=PORT_STATE_OUT_PROCEEDING
3005 && p_state!=PORT_STATE_OUT_ALERTING
3006 && p_state!=PORT_STATE_CONNECT
3007 && p_state!=PORT_STATE_CONNECT_WAITING)
3011 message_disconnect(epoint_id, message_id, param);
3014 case MESSAGE_RELEASE: /* release isdn port */
3015 if (p_state==PORT_STATE_RELEASE)
3019 message_release(epoint_id, message_id, param);
3023 PERROR("Pdss1(%s) isdn port with (caller id %s) received a wrong message: %d\n", p_name, p_callerinfo.id, message);
3032 * data from isdn-stack (layer-3) to pbx (port class)
3034 /* NOTE: nt mode use mISDNuser_head_t as header */
3035 int stack2manager_nt(void *dat, void *arg)
3039 manager_t *mgr = (manager_t *)dat;
3040 msg_t *msg = (msg_t *)arg;
3041 mISDNuser_head_t *hh;
3042 struct mISDNport *mISDNport;
3048 /* note: nst is the first data feld of mISDNport */
3049 mISDNport = (struct mISDNport *)mgr->nst;
3051 hh = (mISDNuser_head_t *)msg->data;
3052 PDEBUG(DEBUG_ISDN, "prim(0x%x) dinfo(0x%x) msg->len(%d)\n", hh->prim, hh->dinfo, msg->len);
3054 /* find Port object of type ISDN */
3058 if (port->p_type == PORT_TYPE_DSS1_NT_IN || port->p_type == PORT_TYPE_DSS1_NT_OUT)
3060 pdss1 = (class Pdss1 *)port;
3061 //PDEBUG(DEBUG_ISDN, "comparing dinfo = 0x%x with l3id 0x%x\n", hh->dinfo, pdss1->p_m_d_l3id);
3062 /* check out correct stack */
3063 if (pdss1->p_m_mISDNport == mISDNport)
3064 /* check out correct id */
3065 if ((pdss1->p_m_d_l3id&0x0000ff00) != 0x000ff00)
3067 /* a single process */
3068 if (hh->dinfo == pdss1->p_m_d_l3id)
3070 /* found port, the message belongs to */
3075 /* a broadcast process */
3076 if ((hh->dinfo&0xffff0000) == (pdss1->p_m_d_l3id&0xffff0000))
3078 /* found port, the message belongs to */
3087 //printf("%x %x\n", hh->dinfo, pdss1->p_m_d_l3id);
3088 /* if process id is master process, but a child disconnects */
3089 if ((hh->dinfo&0x0000ff00)!=0x0000ff00 && (pdss1->p_m_d_l3id&0x0000ff00)==0x0000ff00)
3091 if (hh->prim == (CC_DISCONNECT|INDICATION))
3093 /* send special indication for child disconnect */
3094 pdss1->disconnect_ind_i(hh->prim, hh->dinfo, msg->data);
3098 // ignoring other messages from child processes
3102 /* if process id and layer 3 id matches */
3103 if (hh->dinfo == pdss1->p_m_d_l3id)
3105 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
3114 case MGR_SHORTSTATUS | INDICATION:
3115 case MGR_SHORTSTATUS | CONFIRM:
3117 case SSTATUS_L2_ESTABLISHED:
3119 case SSTATUS_L2_RELEASED:
3124 case DL_ESTABLISH | INDICATION:
3125 case DL_ESTABLISH | CONFIRM:
3127 l1l2l3_trace_header(mISDNport, NULL, hh->prim, DIRECTION_IN);
3128 add_trace("tei", NULL, "%d", hh->dinfo);
3130 if (mISDNport->ptp && hh->dinfo == 0)
3132 if (mISDNport->l2establish)
3134 mISDNport->l2establish = 0;
3135 PDEBUG(DEBUG_ISDN, "the link became active before l2establish timer expiry.\n");
3137 mISDNport->l2link = 1;
3138 if (mISDNport->pri);
3139 mISDNport->l1link = 1; /* this is a hack, we also assume L1 to be active */
3143 case DL_RELEASE | INDICATION:
3144 case DL_RELEASE | CONFIRM:
3146 l1l2l3_trace_header(mISDNport, NULL, hh->prim, DIRECTION_IN);
3147 add_trace("tei", NULL, "%d", hh->dinfo);
3149 if (mISDNport->ptp && hh->dinfo == 0)
3151 mISDNport->l2link = 0;
3152 time(&mISDNport->l2establish);
3153 PDEBUG(DEBUG_ISDN, "because we are ptp, we set a l2establish timer.\n");
3155 //#warning debugging usleep crash
3156 // printf("JOLLY release port %d\n", mISDNport->portnum);
3160 case CC_SETUP | INDICATION:
3161 /* creating port object */
3162 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3163 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0)))
3165 FATAL("Cannot create Port instance.\n");
3166 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
3169 case CC_RESUME | INDICATION:
3170 /* creating port object */
3171 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3172 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0)))
3173 FATAL("Cannot create Port instance.\n");
3174 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
3177 case CC_RELEASE_CR | INDICATION:
3178 PERROR("unhandled message from stack: call ref released (l3id=0x%x)\n", hh->dinfo);
3181 case CC_RELEASE_COMPLETE | INDICATION:
3184 case CC_FACILITY | INDICATION:
3188 PERROR("unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", hh->prim, hh->dinfo, msg->len);
3192 if (port->p_type == PORT_TYPE_DSS1_NT_IN || port->p_type == PORT_TYPE_DSS1_NT_OUT)
3194 pdss1 = (class Pdss1 *)port;
3195 //PDEBUG(DEBUG_ISDN, "comparing dinfo = 0x%x with l3id 0x%x\n", hh->dinfo, pdss1->p_m_d_l3id);
3196 /* check out correct stack */
3197 if (pdss1->p_m_mISDNport == mISDNport)
3198 /* check out correct id */
3199 PERROR("unhandled message: dinfo=%x is not associated with port-dinfo=%x\n",hh->dinfo,pdss1->p_m_d_l3id);
3209 /* NOTE: te mode use iframe_t as header */
3210 int stack2manager_te(struct mISDNport *mISDNport, msg_t *msg)
3217 if (!msg || !mISDNport)
3219 frm = (iframe_t *)msg->data;
3220 PDEBUG(DEBUG_ISDN, "prim(0x%x) dinfo(0x%x) msg->len(%d)\n", frm->prim, frm->dinfo, msg->len);
3222 /* find Port object of type ISDN */
3226 if (port->p_type == PORT_TYPE_DSS1_TE_IN || port->p_type == PORT_TYPE_DSS1_TE_OUT)
3228 pdss1 = (class Pdss1 *)port;
3229 /* check out correct stack */
3230 if (pdss1->p_m_mISDNport == mISDNport)
3231 /* check out correct id */
3232 if (frm->dinfo == pdss1->p_m_d_l3id)
3234 /* found port, the message belongs to */
3242 pdss1->message_isdn(frm->prim, frm->dinfo, msg->data);
3247 /* process new cr (before setup indication) */
3248 //printf("prim = 0x%x, looking for 0x%x\n",frm->prim, (CC_NEW_CR | INDICATION));
3249 if (frm->prim == (CC_NEW_CR | INDICATION))
3252 /* creating port object */
3253 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3254 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_TE_IN, mISDNport, name, NULL, 0, 0)))
3255 FATAL("Cannot create Port instance.\n");
3256 /* l3id will be set from dinfo at message_isdn */
3257 pdss1->message_isdn(frm->prim, frm->dinfo, msg->data);
3262 if (frm->prim == (CC_RELEASE_CR | INDICATION))
3264 PDEBUG(DEBUG_ISDN, "unhandled message from stack: call ref released (l3id=0x%x)\n", frm->dinfo);
3268 PERROR("unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", frm->prim, frm->dinfo, msg->len);
3274 * sending message that were queued during L1 activation
3275 * or releasing port if link is down
3277 void setup_queue(struct mISDNport *mISDNport, int link)
3281 struct message *message;
3283 if (!mISDNport->ntmode)
3286 /* check all port objects for pending message */
3290 if ((port->p_type&PORT_CLASS_mISDN_MASK) == PORT_CLASS_mISDN_DSS1)
3292 pdss1 = (class Pdss1 *)port;
3293 if (pdss1->p_m_mISDNport == mISDNport)
3295 if (pdss1->p_m_d_queue)
3299 PDEBUG(DEBUG_ISDN, "the L1 became active, so we send queued message for portnum=%d (%s).\n", mISDNport->portnum, pdss1->p_name);
3300 /* LAYER 1 is up, so we send */
3301 pdss1->message_setup(pdss1->p_m_d_queue->id_from, pdss1->p_m_d_queue->type, &pdss1->p_m_d_queue->param);
3302 message_free(pdss1->p_m_d_queue);
3303 pdss1->p_m_d_queue = NULL;
3306 PDEBUG(DEBUG_ISDN, "the L1 became NOT active, so we release port for portnum=%d (%s).\n", mISDNport->portnum, pdss1->p_name);
3307 message = message_create(pdss1->p_serial, pdss1->p_m_d_queue->id_from, PORT_TO_EPOINT, MESSAGE_RELEASE);
3308 message->param.disconnectinfo.cause = 27;
3309 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
3310 message_put(message);
3311 pdss1->new_state(PORT_STATE_RELEASE);
3312 pdss1->p_m_delete = 1;