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
75 static struct l3_msg *create_l3msg(void)
77 static msg_t *create_l3msg(int prim, int mt, int dinfo, int size, int ntmode)
92 size = sizeof(Q931_info_t)+2;
96 dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL);
103 dmsg = alloc_msg(size+256+mISDN_HEADER_LEN+DEFAULT_HEADROOM);
106 memset(msg_put(dmsg,size+mISDN_HEADER_LEN), 0, size+mISDN_HEADER_LEN);
107 frm = (iframe_t *)dmsg->data;
110 qi = (Q931_info_t *)(dmsg->data + mISDN_HEADER_LEN);
117 FATAL("Cannot allocate memory, system overloaded.\n");
118 exit(0); // make gcc happy
122 msg_t *create_l2msg(int prim, int dinfo, int size) /* NT only */
126 dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL);
130 FATAL("Cannot allocate memory, system overloaded.\n");
131 exit(0); // make gcc happy
136 * if we received a first reply to the setup message,
137 * we will check if we have now channel information
138 * return: <0: error, call is released, -cause is given
139 * 0: ok, nothing to do
141 int Pdss1::received_first_reply_to_setup(unsigned long prim, int channel, int exclusive)
147 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
148 RELEASE_COMPLETE_t *release_complete;
152 /* correct exclusive to 0, if no explicit channel was given */
153 if (exclusive<0 || channel<=0)
156 /* select scenario */
157 if (p_m_b_channel && p_m_b_exclusive)
159 /*** we gave an exclusive channel (or if we are done) ***/
161 /* if not first reply, we are done */
162 if (p_state != PORT_STATE_OUT_SETUP)
165 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
166 add_trace("channel", "request", "%d (forced)", p_m_b_channel);
167 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
169 /* if give channel not accepted or not equal */
170 if (channel!=-1 && p_m_b_channel!=channel)
172 add_trace("conclusion", NULL, "forced channel not accepted");
178 add_trace("conclusion", NULL, "channel was accepted");
179 add_trace("connect", "channel", "%d", p_m_b_channel);
182 /* activate our exclusive channel */
183 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
187 /*** we gave a non-exclusive channel ***/
189 /* if not first reply, we are done */
190 if (p_state != PORT_STATE_OUT_SETUP)
193 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
194 add_trace("channel", "request", "%d (suggest)", p_m_b_channel);
195 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
197 /* if channel was accepted as given */
198 if (channel==-1 || p_m_b_channel==channel)
200 add_trace("conclusion", NULL, "channel was accepted as given");
201 add_trace("connect", "channel", "%d", p_m_b_channel);
203 p_m_b_exclusive = 1; // we are done
204 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
208 /* if channel value is faulty */
211 add_trace("conclusion", NULL, "illegal reply");
213 ret = -111; // protocol error
217 /* if channel was not accepted, try to get it */
218 ret = seize_bchannel(channel, 1); // exclusively
219 add_trace("channel", "available", ret<0?"no":"yes");
222 add_trace("conclusion", NULL, "replied channel not available");
226 add_trace("conclusion", NULL, "replied channel accepted");
227 add_trace("connect", "channel", "%d", p_m_b_channel);
230 /* activate channel given by remote */
231 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
235 /*** we sent 'any channel acceptable' ***/
237 /* if not first reply, we are done */
238 if (p_state != PORT_STATE_OUT_SETUP)
241 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
242 add_trace("channel", "request", "any");
243 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
244 /* if no channel was replied */
247 add_trace("conclusion", NULL, "no channel, protocol error");
249 ret = -111; // protocol error
253 /* we will see, if our received channel is available */
254 ret = seize_bchannel(channel, 1); // exclusively
255 add_trace("channel", "available", ret<0?"no":"yes");
258 add_trace("conclusion", NULL, "replied channel not available");
262 add_trace("conclusion", NULL, "replied channel accepted");
263 add_trace("connect", "channel", "%d", p_m_b_channel);
266 /* activate channel given by remote */
267 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
270 /*** we sent 'no channel available' ***/
272 /* if not the first reply, but a connect, we are forced */
273 if (prim==(CC_CONNECT | INDICATION) && p_state!=PORT_STATE_OUT_SETUP)
275 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (connect)", DIRECTION_NONE);
276 add_trace("channel", "request", "no-channel");
277 add_trace("channel", "reply", (channel>=0)?"%d%s":"(none)", channel, exclusive?" (forced)":"");
280 goto use_from_connect;
282 ret = seize_bchannel(CHANNEL_ANY, 0); // any channel
283 add_trace("channel", "available", ret<0?"no":"yes");
286 add_trace("conclusion", NULL, "no channel available during call-waiting");
290 add_trace("conclusion", NULL, "using channel %d", p_m_b_channel);
291 add_trace("connect", "channel", "%d", p_m_b_channel);
293 p_m_b_exclusive = 1; // we are done
295 /* activate channel given by remote */
296 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
300 /* if not first reply, we are done */
301 if (p_state != PORT_STATE_OUT_SETUP)
304 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
305 add_trace("channel", "request", "no-channel");
306 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
307 /* if first reply has no channel, we are done */
310 add_trace("conclusion", NULL, "no channel until connect");
315 /* we will see, if our received channel is available */
317 ret = seize_bchannel(channel, exclusive);
318 add_trace("channel", "available", ret<0?"no":"yes");
321 add_trace("conclusion", NULL, "replied channel not available");
325 add_trace("conclusion", NULL, "replied channel accepted");
326 add_trace("connect", "channel", "%d", p_m_b_channel);
328 p_m_b_exclusive = 1; // we are done
330 /* activate channel given by remote */
331 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
337 * NOTE: we send MT_RELEASE_COMPLETE to "REJECT" the channel
338 * in response to the setup reply
341 l3m = create_l3msg();
343 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
344 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
346 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
348 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
350 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
354 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_RELEASE_COMPLETE, l3m);
356 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
358 new_state(PORT_STATE_RELEASE);
360 return(-34); /* to epoint: no channel available */
365 * hunt bchannel for incoming setup or retrieve or resume
367 int Pdss1::hunt_bchannel(int channel, int exclusive)
369 struct select_channel *selchannel;
370 struct interface_port *ifport = p_m_mISDNport->ifport;
373 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (setup)", DIRECTION_NONE);
376 if (channel == CHANNEL_NO)
377 add_trace("channel", "request", "no-channel");
379 add_trace("channel", "request", (channel>0)?"%d%s":"any", channel, exclusive?" (forced)":"");
380 if (channel==CHANNEL_NO && p_type==PORT_TYPE_DSS1_TE_IN)
382 add_trace("conclusion", NULL, "incoming call-waiting not supported for TE-mode");
384 return(-6); // channel unacceptable
386 if (channel <= 0) /* not given, no channel, whatever.. */
387 channel = CHANNEL_ANY; /* any channel */
388 add_trace("channel", "reserved", "%d", p_m_mISDNport->b_reserved);
389 if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num) // of out chan..
391 add_trace("conclusion", NULL, "all channels are reserved");
393 return(-34); // no channel
395 if (channel == CHANNEL_ANY)
399 /* check for given channel in selection list */
400 selchannel = ifport->in_channel;
403 if (selchannel->channel == channel || selchannel->channel == CHANNEL_FREE)
405 selchannel = selchannel->next;
410 /* exclusive channel requests must be in the list */
415 add_trace("conclusion", NULL, "exclusively requested channel not in list");
417 return(-6); // channel unacceptable
419 i = selchannel->channel-1-(selchannel->channel>=17);
420 if (p_m_mISDNport->b_port[i] == NULL)
422 add_trace("conclusion", NULL, "exclusively requested channel is busy");
424 return(-6); // channel unacceptable
427 /* requested channels in list will be used */
430 i = selchannel->channel-1-(selchannel->channel>=17);
431 if (p_m_mISDNport->b_port[i] == NULL)
435 /* if channel is not available or not in list, it must be searched */
437 /* check for first free channel in list */
439 selchannel = ifport->in_channel;
442 switch(selchannel->channel)
444 case CHANNEL_FREE: /* free channel */
445 add_trace("hunting", "channel", "free");
446 if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num)
447 break; /* all channel in use or reserverd */
450 while(i < p_m_mISDNport->b_num)
452 if (p_m_mISDNport->b_port[i] == NULL)
454 channel = i+1+(i>=15);
462 add_trace("hunting", "channel", "%d", selchannel->channel);
463 if (selchannel->channel<1 || selchannel->channel==16)
464 break; /* invalid channels */
465 i = selchannel->channel-1-(selchannel->channel>=17);
466 if (i >= p_m_mISDNport->b_num)
467 break; /* channel not in port */
468 if (p_m_mISDNport->b_port[i] == NULL)
470 channel = selchannel->channel;
476 break; /* found channel */
477 selchannel = selchannel->next;
481 add_trace("conclusion", NULL, "no channel available");
483 return(-6); // channel unacceptable
487 add_trace("conclusion", NULL, "channel available");
488 add_trace("connect", "channel", "%d", channel);
494 * handles all indications
496 /* CC_SETUP INDICATION */
497 void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
502 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
504 SETUP_t *setup = (SETUP_t *)((unsigned long)data + headerlen);
506 int calling_type, calling_plan, calling_present, calling_screen;
507 int called_type, called_plan;
508 int redir_type, redir_plan, redir_present, redir_screen, redir_reason;
509 int hlc_coding, hlc_presentation, hlc_interpretation, hlc_hlc, hlc_exthlc;
510 int bearer_coding, bearer_capability, bearer_mode, bearer_rate, bearer_multi, bearer_user;
511 int exclusive, channel;
513 unsigned char keypad[32] = "";
514 unsigned char useruser[128];
515 int useruser_len = 0, useruser_protocol;
516 class Endpoint *epoint;
517 struct message *message;
519 /* callref from nt-lib */
522 /* nt-library now gives us the id via CC_SETUP */
523 if (dinfo&(~0xff) == 0xff00)
524 FATAL("l3-stack gives us a process id 0xff00-0xffff\n");
525 l1l2l3_trace_header(p_m_mISDNport, this, CC_NEW_CR | INDICATION, DIRECTION_IN);
527 add_trace("callref", "old", "0x%x", p_m_d_l3id);
528 add_trace("callref", "new", "0x%x", dinfo);
530 if (p_m_d_l3id&(~0xff) == 0xff00)
531 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
533 p_m_d_ces = setup->ces;
536 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
537 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));
538 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));
539 dec_ie_keypad(setup->KEYPAD, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)keypad, sizeof(keypad));
540 /* te-mode: CNIP (calling name identification presentation) */
542 dec_facility_centrex(setup->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)p_callerinfo.name, sizeof(p_callerinfo.name));
543 dec_ie_useruser(setup->USER_USER, (Q931_info_t *)((unsigned long)data+headerlen), &useruser_protocol, useruser, &useruser_len);
544 dec_ie_complete(setup->COMPLETE, (Q931_info_t *)((unsigned long)data+headerlen), &p_dialinginfo.sending_complete);
545 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));
546 dec_ie_channel_id(setup->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
547 dec_ie_hlc(setup->HLC, (Q931_info_t *)((unsigned long)data+headerlen), &hlc_coding, &hlc_interpretation, &hlc_presentation, &hlc_hlc, &hlc_exthlc);
548 dec_ie_bearer(setup->BEARER, (Q931_info_t *)((unsigned long)data+headerlen), &bearer_coding, &bearer_capability, &bearer_mode, &bearer_rate, &bearer_multi, &bearer_user);
551 /* if blocked, release call with MT_RELEASE_COMPLETE */
552 if (p_m_mISDNport->ifport->block)
554 RELEASE_COMPLETE_t *release_complete;
557 l3m = create_l3msg();
559 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
560 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
562 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
564 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 27); /* temporary unavailable */
566 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 27); /* temporary unavailable */
568 add_trace("reason", NULL, "port blocked");
571 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_RELEASE_COMPLETE, l3m);
573 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
575 new_state(PORT_STATE_RELEASE);
581 switch (calling_present)
584 p_callerinfo.present = INFO_PRESENT_RESTRICTED;
587 p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
590 p_callerinfo.present = INFO_PRESENT_ALLOWED;
593 switch (calling_screen)
596 p_callerinfo.screen = INFO_SCREEN_USER;
599 p_callerinfo.screen = INFO_SCREEN_NETWORK;
602 switch (calling_type)
605 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
606 p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
607 p_callerinfo.screen = INFO_SCREEN_NETWORK;
610 p_callerinfo.ntype = INFO_NTYPE_INTERNATIONAL;
613 p_callerinfo.ntype = INFO_NTYPE_NATIONAL;
616 p_callerinfo.ntype = INFO_NTYPE_SUBSCRIBER;
619 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
622 p_callerinfo.isdn_port = p_m_portnum;
623 SCPY(p_callerinfo.interface, p_m_mISDNport->ifport->interface->name);
625 /* dialing information */
626 SCAT(p_dialinginfo.id, (char *)keypad);
630 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
633 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
636 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
639 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
644 switch (redir_present)
647 p_redirinfo.present = INFO_PRESENT_RESTRICTED;
650 p_redirinfo.present = INFO_PRESENT_NOTAVAIL;
653 p_redirinfo.present = INFO_PRESENT_ALLOWED;
656 switch (redir_screen)
659 p_redirinfo.screen = INFO_SCREEN_USER;
662 p_redirinfo.screen = INFO_SCREEN_NETWORK;
665 switch (redir_reason)
668 p_redirinfo.reason = INFO_REDIR_BUSY;
671 p_redirinfo.reason = INFO_REDIR_NORESPONSE;
674 p_redirinfo.reason = INFO_REDIR_UNCONDITIONAL;
677 p_redirinfo.reason = INFO_REDIR_CALLDEFLECT;
680 p_redirinfo.reason = INFO_REDIR_OUTOFORDER;
683 p_redirinfo.reason = INFO_REDIR_UNKNOWN;
689 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
690 p_redirinfo.present = INFO_PRESENT_NULL; /* not redirecting */
691 p_redirinfo.reason = INFO_REDIR_UNKNOWN;
694 p_redirinfo.ntype = INFO_NTYPE_INTERNATIONAL;
697 p_redirinfo.ntype = INFO_NTYPE_NATIONAL;
700 p_redirinfo.ntype = INFO_NTYPE_SUBSCRIBER;
703 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
706 p_redirinfo.isdn_port = p_m_portnum;
708 /* bearer capability */
709 switch (bearer_capability)
712 p_capainfo.bearer_capa = INFO_BC_AUDIO;
713 bearer_user = (options.law=='a')?3:2;
716 p_capainfo.bearer_capa = bearer_capability;
722 p_capainfo.bearer_mode = INFO_BMODE_PACKET;
725 p_capainfo.bearer_mode = INFO_BMODE_CIRCUIT;
731 p_capainfo.bearer_info1 = INFO_INFO1_NONE;
734 p_capainfo.bearer_info1 = bearer_user + 0x80;
742 p_capainfo.hlc = INFO_HLC_NONE;
745 p_capainfo.hlc = hlc_hlc + 0x80;
751 p_capainfo.exthlc = INFO_HLC_NONE;
754 p_capainfo.exthlc = hlc_exthlc + 0x80;
759 ret = channel = hunt_bchannel(channel, exclusive);
764 ret = seize_bchannel(channel, 1);
769 * NOTE: we send MT_RELEASE_COMPLETE to "REJECT" the channel
770 * in response to the setup
773 l3m = create_l3msg();
775 RELEASE_COMPLETE_t *release_complete;
776 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
777 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
779 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
781 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
783 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
787 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_RELEASE_COMPLETE, l3m);
789 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
791 new_state(PORT_STATE_RELEASE);
795 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
797 /* create endpoint */
799 FATAL("Incoming call but already got an endpoint.\n");
800 if (!(epoint = new Endpoint(p_serial, 0)))
801 FATAL("No memory for Endpoint instance\n");
802 if (!(epoint->ep_app = new DEFAULT_ENDPOINT_APP(epoint, 0))) //incoming
803 FATAL("No memory for Endpoint Application instance\n");
804 epointlist_new(epoint->ep_serial);
806 /* send setup message to endpoit */
807 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_SETUP);
808 message->param.setup.isdn_port = p_m_portnum;
809 message->param.setup.port_type = p_type;
810 message->param.setup.dtmf = !p_m_mISDNport->ifport->nodtmf;
811 memcpy(&message->param.setup.dialinginfo, &p_dialinginfo, sizeof(struct dialing_info));
812 memcpy(&message->param.setup.callerinfo, &p_callerinfo, sizeof(struct caller_info));
813 memcpy(&message->param.setup.redirinfo, &p_redirinfo, sizeof(struct redir_info));
814 memcpy(&message->param.setup.capainfo, &p_capainfo, sizeof(struct capa_info));
815 memcpy(message->param.setup.useruser.data, &useruser, useruser_len);
816 message->param.setup.useruser.len = useruser_len;
817 message->param.setup.useruser.protocol = useruser_protocol;
818 message_put(message);
820 new_state(PORT_STATE_IN_SETUP);
823 /* CC_INFORMATION INDICATION */
824 void Pdss1::information_ind(unsigned long prim, unsigned long dinfo, void *data)
826 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
827 INFORMATION_t *information = (INFORMATION_t *)((unsigned long)data + headerlen);
829 unsigned char keypad[32] = "";
830 struct message *message;
832 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
833 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));
834 dec_ie_keypad(information->KEYPAD, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)keypad, sizeof(keypad));
835 dec_ie_complete(information->COMPLETE, (Q931_info_t *)((unsigned long)data+headerlen), &p_dialinginfo.sending_complete);
838 SCAT(p_dialinginfo.id, (char *)keypad);
842 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
845 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
848 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
851 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
854 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_INFORMATION);
855 memcpy(&message->param.information, &p_dialinginfo, sizeof(struct dialing_info));
856 message_put(message);
857 /* reset overlap timeout */
861 /* CC_SETUP_ACCNOWLEDGE INDICATION */
862 void Pdss1::setup_acknowledge_ind(unsigned long prim, unsigned long dinfo, void *data)
864 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
865 SETUP_ACKNOWLEDGE_t *setup_acknowledge = (SETUP_ACKNOWLEDGE_t *)((unsigned long)data + headerlen);
866 int exclusive, channel;
867 int coding, location, progress;
869 struct message *message;
871 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
872 dec_ie_channel_id(setup_acknowledge->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
873 dec_ie_progress(setup_acknowledge->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
876 /* process channel */
877 ret = received_first_reply_to_setup(prim, channel, exclusive);
880 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
881 message->param.disconnectinfo.cause = -ret;
882 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
883 message_put(message);
884 new_state(PORT_STATE_RELEASE);
889 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_OVERLAP);
890 message_put(message);
892 new_state(PORT_STATE_OUT_OVERLAP);
895 /* CC_PROCEEDING INDICATION */
896 void Pdss1::proceeding_ind(unsigned long prim, unsigned long dinfo, void *data)
898 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
899 CALL_PROCEEDING_t *proceeding = (CALL_PROCEEDING_t *)((unsigned long)data + headerlen);
900 int exclusive, channel;
901 int coding, location, progress;
903 struct message *message;
904 int notify = -1, type, plan, present;
907 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
908 dec_ie_channel_id(proceeding->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
909 dec_ie_progress(proceeding->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
910 dec_ie_notify(NULL/*proceeding->NOTIFY*/, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
911 dec_ie_redir_dn(proceeding->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
914 ret = received_first_reply_to_setup(prim, channel, exclusive);
917 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
918 message->param.disconnectinfo.cause = -ret;
919 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
920 message_put(message);
921 new_state(PORT_STATE_RELEASE);
925 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROCEEDING);
926 message_put(message);
928 new_state(PORT_STATE_OUT_PROCEEDING);
934 if (type >= 0 || notify)
936 if (!notify && type >= 0)
938 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
939 message->param.notifyinfo.notify = notify;
940 SCPY(message->param.notifyinfo.id, redir);
941 /* redirection number */
945 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
948 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
951 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
957 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
958 message->param.notifyinfo.present = INFO_PRESENT_NULL;
961 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
964 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
967 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
970 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
973 message->param.notifyinfo.isdn_port = p_m_portnum;
974 message_put(message);
978 /* CC_ALERTING INDICATION */
979 void Pdss1::alerting_ind(unsigned long prim, unsigned long dinfo, void *data)
981 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
982 ALERTING_t *alerting = (ALERTING_t *)((unsigned long)data + headerlen);
983 int exclusive, channel;
984 int coding, location, progress;
986 struct message *message;
987 int notify = -1, type, plan, present;
990 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
991 dec_ie_channel_id(alerting->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
992 dec_ie_progress(alerting->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
993 dec_ie_notify(NULL/*alerting->NOTIFY*/, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
994 dec_ie_redir_dn(alerting->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
997 /* process channel */
998 ret = received_first_reply_to_setup(prim, channel, exclusive);
1001 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1002 message->param.disconnectinfo.cause = -ret;
1003 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1004 message_put(message);
1005 new_state(PORT_STATE_RELEASE);
1009 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_ALERTING);
1010 message_put(message);
1012 new_state(PORT_STATE_OUT_ALERTING);
1018 if (type >= 0 || notify)
1020 if (!notify && type >= 0)
1022 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1023 message->param.notifyinfo.notify = notify;
1024 SCPY(message->param.notifyinfo.id, redir);
1028 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1031 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1034 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1040 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1041 message->param.notifyinfo.present = INFO_PRESENT_NULL;
1044 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1047 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1050 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1053 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1056 message->param.notifyinfo.isdn_port = p_m_portnum;
1057 message_put(message);
1061 /* CC_CONNECT INDICATION */
1062 void Pdss1::connect_ind(unsigned long prim, unsigned long dinfo, void *data)
1067 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1069 CONNECT_t *connect = (CONNECT_t *)((unsigned long)data + headerlen);
1070 CONNECT_ACKNOWLEDGE_t *connect_acknowledge;
1072 int exclusive, channel;
1073 int type, plan, present, screen;
1075 struct message *message;
1076 int bchannel_before;
1079 p_m_d_ces = connect->ces;
1081 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1082 dec_ie_channel_id(connect->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
1083 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));
1084 /* te-mode: CONP (connected name identification presentation) */
1086 dec_facility_centrex(connect->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)p_connectinfo.name, sizeof(p_connectinfo.name));
1089 /* select channel */
1090 bchannel_before = p_m_b_channel;
1091 ret = received_first_reply_to_setup(prim, channel, exclusive);
1094 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1095 message->param.disconnectinfo.cause = -ret;
1096 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1097 message_put(message);
1098 new_state(PORT_STATE_RELEASE);
1103 /* connect information */
1107 p_connectinfo.present = INFO_PRESENT_RESTRICTED;
1110 p_connectinfo.present = INFO_PRESENT_NOTAVAIL;
1113 p_connectinfo.present = INFO_PRESENT_ALLOWED;
1119 p_connectinfo.screen = INFO_SCREEN_USER;
1122 p_connectinfo.screen = INFO_SCREEN_NETWORK;
1128 p_connectinfo.present = INFO_PRESENT_NULL; /* no COLP info */
1129 p_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1132 p_connectinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1135 p_connectinfo.ntype = INFO_NTYPE_NATIONAL;
1138 p_connectinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1141 p_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1144 p_connectinfo.isdn_port = p_m_portnum;
1145 SCPY(p_connectinfo.interface, p_m_mISDNport->ifport->interface->name);
1147 /* only in nt-mode we send connect ack. in te-mode it is done by stack itself or optional */
1150 /* send connect acknowledge */
1152 l3m = create_l3msg();
1154 dmsg = create_l3msg(CC_CONNECT | RESPONSE, MT_CONNECT, dinfo, sizeof(CONNECT_ACKNOWLEDGE_t), p_m_d_ntmode);
1155 connect_acknowledge = (CONNECT_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1157 l1l2l3_trace_header(p_m_mISDNport, this, CC_CONNECT | RESPONSE, DIRECTION_OUT);
1158 /* if we had no bchannel before, we send it now */
1159 if (!bchannel_before && p_m_b_channel)
1161 enc_ie_channel_id(l3m, 1, p_m_b_channel);
1163 enc_ie_channel_id(&connect_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
1167 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_CONNECT, l3m);
1169 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1173 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CONNECT);
1174 memcpy(&message->param.connectinfo, &p_connectinfo, sizeof(struct connect_info));
1175 message_put(message);
1177 new_state(PORT_STATE_CONNECT);
1180 /* CC_DISCONNECT INDICATION */
1181 void Pdss1::disconnect_ind(unsigned long prim, unsigned long dinfo, void *data)
1183 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1184 DISCONNECT_t *disconnect = (DISCONNECT_t *)((unsigned long)data + headerlen);
1185 int location, cause;
1186 int coding, proglocation, progress;
1187 struct message *message;
1189 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1190 dec_ie_progress(disconnect->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &proglocation, &progress);
1191 dec_ie_cause(disconnect->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1193 if (location == LOCATION_PRIVATE_LOCAL)
1194 location = LOCATION_PRIVATE_REMOTE;
1199 /* release if remote sends us no tones */
1200 if (!p_m_mISDNport->earlyb)
1210 l3m = create_l3msg();
1212 dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, dinfo, sizeof(RELEASE_t), p_m_d_ntmode);
1213 release = (RELEASE_t *)(dmsg->data + headerlen);
1215 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE | REQUEST, DIRECTION_OUT);
1217 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16); /* normal */
1219 enc_ie_cause(&release->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16); /* normal */
1221 add_trace("reason", NULL, "no remote patterns");
1224 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_RELEASE, l3m);
1226 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1229 /* sending release to endpoint */
1232 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1233 message->param.disconnectinfo.cause = cause;
1234 message->param.disconnectinfo.location = location;
1235 message_put(message);
1237 free_epointlist(p_epointlist);
1239 new_state(PORT_STATE_RELEASE);
1244 /* sending disconnect to active endpoint and release to inactive endpoints */
1245 if (ACTIVE_EPOINT(p_epointlist))
1247 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DISCONNECT);
1248 message->param.disconnectinfo.location = location;
1249 message->param.disconnectinfo.cause = cause;
1250 message_put(message);
1252 while(INACTIVE_EPOINT(p_epointlist))
1254 message = message_create(p_serial, INACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1255 message->param.disconnectinfo.location = location;
1256 message->param.disconnectinfo.cause = cause;
1257 message_put(message);
1259 free_epointid(INACTIVE_EPOINT(p_epointlist));
1261 new_state(PORT_STATE_IN_DISCONNECT);
1264 /* CC_DISCONNECT INDICATION */
1265 void Pdss1::disconnect_ind_i(unsigned long prim, unsigned long dinfo, void *data)
1267 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1268 DISCONNECT_t *disconnect = (DISCONNECT_t *)((unsigned long)data + headerlen);
1269 int location, cause;
1272 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1273 if (p_m_d_collect_cause > 0)
1275 add_trace("old-cause", "location", "%d", p_m_d_collect_location);
1276 add_trace("old-cause", "value", "%d", p_m_d_collect_cause);
1278 dec_ie_cause(disconnect->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1279 if (location == LOCATION_PRIVATE_LOCAL)
1280 location = LOCATION_PRIVATE_REMOTE;
1283 collect_cause(&p_m_d_collect_cause, &p_m_d_collect_location, cause, location);
1284 add_trace("new-cause", "location", "%d", p_m_d_collect_location);
1285 add_trace("new-cause", "value", "%d", p_m_d_collect_cause);
1290 /* CC_RELEASE INDICATION */
1291 void Pdss1::release_ind(unsigned long prim, unsigned long dinfo, void *data)
1296 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1298 RELEASE_t *release = (RELEASE_t *)((unsigned long)data + headerlen);
1300 int location, cause;
1301 struct message *message;
1303 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1304 dec_ie_cause(release->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1306 if (location == LOCATION_PRIVATE_LOCAL)
1307 location = LOCATION_PRIVATE_REMOTE;
1312 /* sending release to endpoint */
1315 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1316 message->param.disconnectinfo.cause = cause;
1317 message->param.disconnectinfo.location = location;
1318 message_put(message);
1320 free_epointlist(p_epointlist);
1323 /* only in NT mode we must send release_complete, if we got a release confirm */
1324 if (prim == (CC_RELEASE | CONFIRM))
1326 /* sending release complete */
1327 RELEASE_COMPLETE_t *release_complete;
1330 l3m = create_l3msg();
1332 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
1333 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
1335 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
1337 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16);
1339 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16);
1343 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_RELEASE_COMPLETE, l3m);
1345 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1349 new_state(PORT_STATE_RELEASE);
1353 /* CC_RELEASE_COMPLETE INDICATION (a reject) */
1354 void Pdss1::release_complete_ind(unsigned long prim, unsigned long dinfo, void *data)
1356 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1357 RELEASE_COMPLETE_t *release_complete = (RELEASE_COMPLETE_t *)((unsigned long)data + headerlen);
1358 int location, cause;
1359 struct message *message;
1361 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1362 dec_ie_cause(release_complete->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1364 if (location == LOCATION_PRIVATE_LOCAL)
1365 location = LOCATION_PRIVATE_REMOTE;
1370 /* sending release to endpoint */
1373 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1374 message->param.disconnectinfo.cause = cause;
1375 message->param.disconnectinfo.location = location;
1376 message_put(message);
1378 free_epointlist(p_epointlist);
1381 new_state(PORT_STATE_RELEASE);
1386 void Pdss1::t312_timeout(unsigned long prim, unsigned long dinfo, void *data)
1388 struct message *message;
1390 // trace is done at message_isdn()
1392 /* sending release to endpoint */
1395 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1396 if (p_m_d_collect_cause)
1398 message->param.disconnectinfo.cause = p_m_d_collect_cause;
1399 message->param.disconnectinfo.location = p_m_d_collect_location;
1402 message->param.disconnectinfo.cause = CAUSE_NOUSER;
1403 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1405 message_put(message);
1407 free_epointlist(p_epointlist);
1410 new_state(PORT_STATE_RELEASE);
1414 /* CC_NOTIFY INDICATION */
1415 void Pdss1::notify_ind(unsigned long prim, unsigned long dinfo, void *data)
1417 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1418 NOTIFY_t *notifying = (NOTIFY_t *)((unsigned long)data + headerlen);
1419 struct message *message;
1420 int notify, type, plan, present;
1421 unsigned char notifyid[sizeof(message->param.notifyinfo.id)];
1423 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1424 dec_ie_notify(notifying->NOTIFY, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
1425 dec_ie_redir_dn(notifying->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, notifyid, sizeof(notifyid));
1428 if (!ACTIVE_EPOINT(p_epointlist))
1430 /* notification indicator */
1434 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1435 message->param.notifyinfo.notify = notify;
1436 SCPY(message->param.notifyinfo.id, (char *)notifyid);
1437 /* redirection number */
1441 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1444 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1447 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1453 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1454 message->param.notifyinfo.present = INFO_PRESENT_NULL;
1457 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1460 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1463 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1466 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1469 message->param.notifyinfo.isdn_port = p_m_portnum;
1470 message_put(message);
1474 /* CC_HOLD INDICATION */
1475 void Pdss1::hold_ind(unsigned long prim, unsigned long dinfo, void *data)
1477 struct message *message;
1481 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1483 // HOLD_t *hold = (HOLD_t *)((unsigned long)data + headerlen);
1484 HOLD_REJECT_t *hold_reject;
1485 HOLD_ACKNOWLEDGE_t *hold_acknowledge;
1487 // class Endpoint *epoint;
1489 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1492 if (!ACTIVE_EPOINT(p_epointlist) || p_m_hold)
1495 l3m = create_l3msg();
1497 dmsg = create_l3msg(CC_HOLD_REJECT | REQUEST, MT_HOLD_REJECT, dinfo, sizeof(HOLD_REJECT_t), p_m_d_ntmode);
1498 hold_reject = (HOLD_REJECT_t *)(dmsg->data + headerlen);
1500 l1l2l3_trace_header(p_m_mISDNport, this, CC_HOLD_REJECT | REQUEST, DIRECTION_OUT);
1502 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, p_m_hold?101:31); /* normal unspecified / incompatible state */
1504 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 */
1506 add_trace("reason", NULL, "no endpoint");
1509 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_HOLD_REJECT, l3m);
1511 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1517 /* notify the hold of call */
1518 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1519 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_HOLD;
1520 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1521 message_put(message);
1523 /* deactivate bchannel */
1524 chan_trace_header(p_m_mISDNport, this, "CHANNEL RELEASE (hold)", DIRECTION_NONE);
1525 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1529 /* set hold state */
1532 epoint = find_epoint_id(ACTIVE_EPOINT(p_epointlist));
1533 if (epoint && p_m_d_ntmode)
1535 p_m_timeout = p_settings.tout_hold;
1540 /* acknowledge hold */
1542 l3m = create_l3msg();
1544 dmsg = create_l3msg(CC_HOLD_ACKNOWLEDGE | REQUEST, MT_HOLD_ACKNOWLEDGE, dinfo, sizeof(HOLD_ACKNOWLEDGE_t), p_m_d_ntmode);
1545 hold_acknowledge = (HOLD_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1547 l1l2l3_trace_header(p_m_mISDNport, this, CC_HOLD_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1550 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_HOLD_ACKNOWLEDGE, l3m);
1552 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1557 /* CC_RETRIEVE INDICATION */
1558 void Pdss1::retrieve_ind(unsigned long prim, unsigned long dinfo, void *data)
1563 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1565 RETRIEVE_t *retrieve = (RETRIEVE_t *)((unsigned long)data + headerlen);
1566 RETRIEVE_REJECT_t *retrieve_reject;
1567 RETRIEVE_ACKNOWLEDGE_t *retrieve_acknowledge;
1569 struct message *message;
1570 int channel, exclusive, cause;
1573 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1574 dec_ie_channel_id(retrieve->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
1579 cause = 101; /* incompatible state */
1583 l3m = create_l3msg();
1585 dmsg = create_l3msg(CC_RETRIEVE_REJECT | REQUEST, MT_RETRIEVE_REJECT, dinfo, sizeof(RETRIEVE_REJECT_t), p_m_d_ntmode);
1586 retrieve_reject = (RETRIEVE_REJECT_t *)(dmsg->data + headerlen);
1588 l1l2l3_trace_header(p_m_mISDNport, this, CC_RETRIEVE_REJECT | REQUEST, DIRECTION_OUT);
1590 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, cause);
1592 enc_ie_cause(&retrieve_reject->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, cause);
1596 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_RETRIEVE_REJECT, l3m);
1598 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1604 /* notify the retrieve of call */
1605 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1606 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_RETRIEVAL;
1607 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1608 message_put(message);
1611 ret = channel = hunt_bchannel(channel, exclusive);
1616 ret = seize_bchannel(channel, 1);
1623 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
1625 /* set hold state */
1629 /* acknowledge retrieve */
1631 l3m = create_l3msg();
1633 dmsg = create_l3msg(CC_RETRIEVE_ACKNOWLEDGE | REQUEST, MT_RETRIEVE_ACKNOWLEDGE, dinfo, sizeof(RETRIEVE_ACKNOWLEDGE_t), p_m_d_ntmode);
1634 retrieve_acknowledge = (RETRIEVE_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1636 l1l2l3_trace_header(p_m_mISDNport, this, CC_RETRIEVE_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1638 enc_ie_channel_id(l3m, 1, p_m_b_channel);
1640 enc_ie_channel_id(&retrieve_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
1644 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_RETRIEVE_ACKNOWLEDGE, l3m);
1646 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1650 /* CC_SUSPEND INDICATION */
1651 void Pdss1::suspend_ind(unsigned long prim, unsigned long dinfo, void *data)
1656 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1658 SUSPEND_t *suspend = (SUSPEND_t *)((unsigned long)data + headerlen);
1659 SUSPEND_ACKNOWLEDGE_t *suspend_acknowledge;
1660 SUSPEND_REJECT_t *suspend_reject;
1662 struct message *message;
1663 class Endpoint *epoint;
1664 unsigned char callid[8];
1666 int ret = -31; /* normal, unspecified */
1668 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1669 dec_ie_call_id(suspend->CALL_ID, (Q931_info_t *)((unsigned long)data+headerlen), callid, &len);
1672 if (!ACTIVE_EPOINT(p_epointlist))
1676 l3m = create_l3msg();
1678 dmsg = create_l3msg(CC_SUSPEND_REJECT | REQUEST, MT_SUSPEND_REJECT, dinfo, sizeof(SUSPEND_REJECT_t), p_m_d_ntmode);
1679 suspend_reject = (SUSPEND_REJECT_t *)(dmsg->data + headerlen);
1681 l1l2l3_trace_header(p_m_mISDNport, this, CC_SUSPEND_REJECT | REQUEST, DIRECTION_OUT);
1683 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1685 enc_ie_cause(&suspend_reject->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1689 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_SUSPEND_REJECT, l3m);
1691 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1700 /* check if call id is in use */
1701 epoint = epoint_first;
1704 if (epoint->ep_park)
1706 if (epoint->ep_park_len == len)
1707 if (!memcmp(epoint->ep_park_callid, callid, len))
1709 ret = -84; /* call id in use */
1713 epoint = epoint->next;
1716 /* notify the hold of call */
1717 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1718 message->param.notifyinfo.notify = INFO_NOTIFY_USER_SUSPENDED;
1719 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1720 message_put(message);
1722 /* deactivate bchannel */
1723 chan_trace_header(p_m_mISDNport, this, "CHANNEL RELEASE (suspend)", DIRECTION_NONE);
1724 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1728 /* sending suspend to endpoint */
1729 while (p_epointlist)
1731 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_SUSPEND);
1732 memcpy(message->param.parkinfo.callid, callid, sizeof(message->param.parkinfo.callid));
1733 message->param.parkinfo.len = len;
1734 message_put(message);
1736 free_epointlist(p_epointlist);
1739 /* sending SUSPEND_ACKNOWLEDGE */
1741 l3m = create_l3msg();
1743 dmsg = create_l3msg(CC_SUSPEND_ACKNOWLEDGE | REQUEST, MT_SUSPEND_ACKNOWLEDGE, dinfo, sizeof(SUSPEND_ACKNOWLEDGE_t), p_m_d_ntmode);
1744 suspend_acknowledge = (SUSPEND_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1746 l1l2l3_trace_header(p_m_mISDNport, this, CC_SUSPEND_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1749 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_SUSPEND_ACKNOWLEDGE, l3m);
1751 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1754 new_state(PORT_STATE_RELEASE);
1758 /* CC_RESUME INDICATION */
1759 void Pdss1::resume_ind(unsigned long prim, unsigned long dinfo, void *data)
1764 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1766 RESUME_t *resume = (RESUME_t *)((unsigned long)data + headerlen);
1767 RESUME_REJECT_t *resume_reject;
1768 RESUME_ACKNOWLEDGE_t *resume_acknowledge;
1770 unsigned char callid[8];
1772 int channel, exclusive;
1773 class Endpoint *epoint;
1774 struct message *message;
1777 /* callref from nt-lib */
1780 /* nt-library now gives us the id via CC_RESUME */
1781 if (dinfo&(~0xff) == 0xff00)
1782 FATAL("l3-stack gives us a process id 0xff00-0xffff\n");
1783 l1l2l3_trace_header(p_m_mISDNport, this, CC_NEW_CR | INDICATION, DIRECTION_IN);
1785 add_trace("callref", "old", "0x%x", p_m_d_l3id);
1786 add_trace("callref", "new", "0x%x", dinfo);
1788 if (p_m_d_l3id&(~0xff) == 0xff00)
1789 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
1791 p_m_d_ces = resume->ces;
1794 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1795 dec_ie_call_id(resume->CALL_ID, (Q931_info_t *)((unsigned long)data+headerlen), callid, &len);
1798 /* if blocked, release call */
1799 if (p_m_mISDNport->ifport->block)
1808 /* channel_id (no channel is possible in message) */
1810 channel = -1; /* any channel */
1813 ret = channel = hunt_bchannel(channel, exclusive);
1818 ret = seize_bchannel(channel, 1);
1824 l3m = create_l3msg();
1826 dmsg = create_l3msg(CC_RESUME_REJECT | REQUEST, MT_RESUME_REJECT, dinfo, sizeof(RESUME_REJECT_t), p_m_d_ntmode);
1827 resume_reject = (RESUME_REJECT_t *)(dmsg->data + headerlen);
1829 l1l2l3_trace_header(p_m_mISDNport, this, CC_RESUME_REJECT | REQUEST, DIRECTION_OUT);
1831 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1833 enc_ie_cause(&resume_reject->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1836 add_trace("reason", NULL, "port blocked");
1839 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_RESUME_REJECT, l3m);
1841 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1843 new_state(PORT_STATE_RELEASE);
1847 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
1849 /* create endpoint */
1851 FATAL("Incoming resume but already got an endpoint.\n");
1852 ret = -85; /* no call suspended */
1853 epoint = epoint_first;
1856 if (epoint->ep_park)
1858 ret = -83; /* suspended call exists, but this not */
1859 if (epoint->ep_park_len == len)
1860 if (!memcmp(epoint->ep_park_callid, callid, len))
1863 epoint = epoint->next;
1868 epointlist_new(epoint->ep_serial);
1869 if (!(epoint->portlist_new(p_serial, p_type, p_m_mISDNport->earlyb)))
1870 FATAL("No memory for portlist\n");
1871 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RESUME);
1872 message_put(message);
1874 /* notify the resume of call */
1875 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1876 message->param.notifyinfo.notify = INFO_NOTIFY_USER_RESUMED;
1877 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1878 message_put(message);
1880 /* sending RESUME_ACKNOWLEDGE */
1882 l3m = create_l3msg();
1884 dmsg = create_l3msg(CC_RESUME_ACKNOWLEDGE | REQUEST, MT_RESUME_ACKNOWLEDGE, dinfo, sizeof(RESUME_ACKNOWLEDGE_t), p_m_d_ntmode);
1885 resume_acknowledge = (RESUME_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1887 l1l2l3_trace_header(p_m_mISDNport, this, CC_RESUME_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
1889 enc_ie_channel_id(l3m, 1, p_m_b_channel);
1891 enc_ie_channel_id(&resume_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
1895 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_RESUME_ACKNOWDGE, l3m);
1897 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1900 new_state(PORT_STATE_CONNECT);
1904 /* CC_FACILITY INDICATION */
1905 void Pdss1::facility_ind(unsigned long prim, unsigned long dinfo, void *data)
1907 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1908 FACILITY_t *facility = (FACILITY_t *)((unsigned long)data + headerlen);
1909 unsigned char facil[256];
1911 struct message *message;
1913 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1914 dec_ie_facility(facility->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), facil, &facil_len);
1921 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_FACILITY);
1922 message->param.facilityinfo.len = facil_len;
1923 memcpy(message->param.facilityinfo.data, facil, facil_len);
1924 message_put(message);
1929 * handler for isdn connections
1930 * incoming information are parsed and sent via message to the endpoint
1932 void Pdss1::message_isdn(unsigned long prim, unsigned long dinfo, void *data)
1939 case CC_TIMEOUT | INDICATION:
1942 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1943 timer_hex = *((int *)(((char *)data)+headerlen));
1945 if (timer_hex==0x312 && p_m_d_ntmode)
1947 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
1948 add_trace("timer", NULL, "%x", timer_hex);
1950 t312_timeout(prim, dinfo, data);
1954 case CC_SETUP | INDICATION:
1955 if (p_state != PORT_STATE_IDLE)
1957 setup_ind(prim, dinfo, data);
1960 case CC_SETUP | CONFIRM:
1963 l1l2l3_trace_header(p_m_mISDNport, this, CC_NEW_CR | INDICATION, DIRECTION_IN);
1964 add_trace("callref", "old", "0x%x", p_m_d_l3id);
1965 /* nt-library now gives us a new id via CC_SETUP_CONFIRM */
1966 if ((p_m_d_l3id&0xff00) != 0xff00)
1967 PERROR(" strange setup-procid 0x%x\n", p_m_d_l3id);
1968 p_m_d_l3id = *((int *)(((u_char *)data)+ mISDNUSER_HEAD_SIZE));
1969 add_trace("callref", "new", "0x%x", p_m_d_l3id);
1974 case CC_INFORMATION | INDICATION:
1975 information_ind(prim, dinfo, data);
1978 case CC_SETUP_ACKNOWLEDGE | INDICATION:
1979 if (p_state != PORT_STATE_OUT_SETUP)
1981 PERROR("Pdss1(%s) received setup_acknowledge, but we are not in outgoing setup state, IGNORING.\n", p_name);
1984 setup_acknowledge_ind(prim, dinfo, data);
1987 case CC_PROCEEDING | INDICATION:
1988 if (p_state != PORT_STATE_OUT_SETUP
1989 && p_state != PORT_STATE_OUT_OVERLAP)
1991 PERROR("Pdss1(%s) received proceeding, but we are not in outgoing setup OR overlap state, IGNORING.\n", p_name);
1994 proceeding_ind(prim, dinfo, data);
1997 case CC_ALERTING | INDICATION:
1998 if (p_state != PORT_STATE_OUT_SETUP
1999 && p_state != PORT_STATE_OUT_OVERLAP
2000 && p_state != PORT_STATE_OUT_PROCEEDING)
2002 PERROR("Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding state, IGNORING.\n", p_name);
2005 alerting_ind(prim, dinfo, data);
2008 case CC_CONNECT | INDICATION:
2009 if (p_state != PORT_STATE_OUT_SETUP
2010 && p_state != PORT_STATE_OUT_OVERLAP
2011 && p_state != PORT_STATE_OUT_PROCEEDING
2012 && p_state != PORT_STATE_OUT_ALERTING)
2014 PERROR("Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding OR ALERTING state, IGNORING.\n", p_name);
2017 connect_ind(prim, dinfo, data);
2018 if (p_m_d_notify_pending)
2020 /* send pending notify message during connect */
2021 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2022 message_free(p_m_d_notify_pending);
2023 p_m_d_notify_pending = NULL;
2027 case CC_CONNECT_ACKNOWLEDGE | INDICATION:
2028 case CC_CONNECT | CONFIRM:
2029 if (p_state == PORT_STATE_CONNECT_WAITING)
2030 new_state(PORT_STATE_CONNECT);
2031 if (p_m_d_notify_pending)
2033 /* send pending notify message during connect-ack */
2034 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2035 message_free(p_m_d_notify_pending);
2036 p_m_d_notify_pending = NULL;
2040 case CC_DISCONNECT | INDICATION:
2041 disconnect_ind(prim, dinfo, data);
2044 case CC_RELEASE | CONFIRM:
2045 case CC_RELEASE | INDICATION:
2046 release_ind(prim, dinfo, data);
2049 case CC_RELEASE_COMPLETE | INDICATION:
2050 release_complete_ind(prim, dinfo, data);
2053 case CC_RELEASE_COMPLETE | CONFIRM:
2056 case CC_NOTIFY | INDICATION:
2057 notify_ind(prim, dinfo, data);
2060 case CC_HOLD | INDICATION:
2061 hold_ind(prim, dinfo, data);
2064 case CC_RETRIEVE | INDICATION:
2065 retrieve_ind(prim, dinfo, data);
2068 case CC_SUSPEND | INDICATION:
2069 suspend_ind(prim, dinfo, data);
2072 case CC_RESUME | INDICATION:
2073 resume_ind(prim, dinfo, data);
2076 case CC_FACILITY | INDICATION:
2077 facility_ind(prim, dinfo, data);
2080 case CC_RELEASE_CR | INDICATION:
2081 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_CR | INDICATION, DIRECTION_IN);
2082 add_trace("callref", NULL, "0x%x", p_m_d_l3id);
2086 if ((p_m_d_l3id&0xff00) == 0xff00)
2087 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
2091 //#warning remove me
2092 //PDEBUG(DEBUG_LOG, "JOLLY release cr %d\n", p_serial);
2093 /* sending release to endpoint in case we still have an endpoint
2094 * this is because we don't get any response if a release_complete is received (or a release in release state)
2098 struct message *message;
2099 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
2100 message->param.disconnectinfo.cause = (p_m_d_collect_cause!=CAUSE_NOUSER)?p_m_d_collect_cause:CAUSE_UNSPECIFIED;
2101 message->param.disconnectinfo.location = (p_m_d_collect_cause!=CAUSE_NOUSER)?p_m_d_collect_location:LOCATION_PRIVATE_LOCAL;
2102 message_put(message);
2104 free_epointlist(p_epointlist);
2106 new_state(PORT_STATE_RELEASE);
2110 case CC_NEW_CR | INDICATION:
2111 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
2113 add_trace("callref", "old", "0x%x", p_m_d_l3id);
2116 new_l3id = *((int *)(((u_char *)data+mISDNUSER_HEAD_SIZE)));
2117 if (((new_l3id&0xff00)!=0xff00) && ((p_m_d_l3id&0xff00)==0xff00))
2118 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
2123 p_m_d_l3id = new_l3id;
2124 add_trace("callref", "new", "0x%x", p_m_d_l3id);
2129 l1l2l3_trace_header(p_m_mISDNport, this, prim, DIRECTION_IN);
2130 add_trace("unhandled", "prim", "0x%x", prim);
2135 void Pdss1::new_state(int state)
2137 // class Endpoint *epoint;
2140 if (state == PORT_STATE_IN_OVERLAP)
2142 p_m_timeout = p_m_mISDNport->ifport->tout_dialing;
2145 if (state != p_state)
2147 if (state == PORT_STATE_IN_SETUP
2148 || state == PORT_STATE_OUT_SETUP
2149 || state == PORT_STATE_IN_OVERLAP
2150 || state == PORT_STATE_OUT_OVERLAP)
2152 p_m_timeout = p_m_mISDNport->ifport->tout_setup;
2155 if (state == PORT_STATE_IN_PROCEEDING
2156 || state == PORT_STATE_OUT_PROCEEDING)
2158 p_m_timeout = p_m_mISDNport->ifport->tout_proceeding;
2161 if (state == PORT_STATE_IN_ALERTING
2162 || state == PORT_STATE_OUT_ALERTING)
2164 p_m_timeout = p_m_mISDNport->ifport->tout_alerting;
2167 if (state == PORT_STATE_CONNECT
2168 || state == PORT_STATE_CONNECT_WAITING)
2172 if (state == PORT_STATE_IN_DISCONNECT
2173 || state == PORT_STATE_OUT_DISCONNECT)
2175 p_m_timeout = p_m_mISDNport->ifport->tout_disconnect;
2180 Port::new_state(state);
2187 int Pdss1::handler(void)
2191 //if (p_m_delete && p_m_d_l3id==0)
2192 // printf("ping! %d", p_serial);
2193 if ((ret = PmISDN::handler()))
2196 /* handle destruction */
2197 if (p_m_delete && p_m_d_l3id==0)
2200 //PDEBUG(DEBUG_LOG, "JOLLY destroy object %d\n", p_serial);
2211 * handles all messages from endpoint
2213 /* MESSAGE_INFORMATION */
2214 void Pdss1::message_information(unsigned long epoint_id, int message_id, union parameter *param)
2219 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2221 INFORMATION_t *information;
2224 if (param->information.id[0]) /* only if we have something to dial */
2227 l3m = create_l3msg();
2229 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2230 information = (INFORMATION_t *)(dmsg->data + headerlen);
2232 l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT);
2234 enc_ie_called_pn(l3m, 0, 1, (unsigned char *)param->information.id);
2236 enc_ie_called_pn(&information->CALLED_PN, dmsg, 0, 1, (unsigned char *)param->information.id);
2240 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_INFORMATION, l3m);
2242 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2252 void Pdss1::message_setup(unsigned long epoint_id, int message_id, union parameter *param)
2257 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2259 INFORMATION_t *information;
2262 int plan, type, screen, present, reason;
2263 int capability, mode, rate, coding, user, presentation, interpretation, hlc, exthlc;
2264 int channel, exclusive;
2266 struct epoint_list *epointlist;
2268 /* release if port is blocked */
2269 if (p_m_mISDNport->ifport->block)
2271 struct message *message;
2273 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2274 message->param.disconnectinfo.cause = 27; // temp. unavail.
2275 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2276 message_put(message);
2277 new_state(PORT_STATE_RELEASE);
2282 /* copy setup infos to port */
2283 memcpy(&p_callerinfo, ¶m->setup.callerinfo, sizeof(p_callerinfo));
2284 memcpy(&p_dialinginfo, ¶m->setup.dialinginfo, sizeof(p_dialinginfo));
2285 memcpy(&p_capainfo, ¶m->setup.capainfo, sizeof(p_capainfo));
2286 memcpy(&p_redirinfo, ¶m->setup.redirinfo, sizeof(p_redirinfo));
2287 // SCPY(&p_m_tones_dir, param->setup.ext.tones_dir);
2288 /* screen outgoing caller id */
2289 do_screen(1, p_callerinfo.id, sizeof(p_callerinfo.id), &p_callerinfo.ntype, &p_callerinfo.present, p_m_mISDNport->ifport->interface);
2291 /* only display at connect state: this case happens if endpoint is in connected mode */
2292 if (p_state==PORT_STATE_CONNECT)
2294 if (p_type!=PORT_TYPE_DSS1_NT_OUT
2295 && p_type!=PORT_TYPE_DSS1_NT_IN)
2297 if (p_callerinfo.display[0])
2299 /* sending information */
2301 l3m = create_l3msg();
2303 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2304 information = (INFORMATION_t *)(dmsg->data + headerlen);
2306 l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT);
2309 enc_ie_display(l3m, (unsigned char *)p_callerinfo.display);
2311 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_callerinfo.display);
2315 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_INFORMATION, l3m);
2317 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2323 /* attach only if not already */
2324 epointlist = p_epointlist;
2327 if (epointlist->epoint_id == epoint_id)
2329 epointlist = epointlist->next;
2332 epointlist_new(epoint_id);
2338 channel = p_m_b_channel;
2339 exclusive = p_m_b_exclusive;
2341 channel = CHANNEL_ANY;
2342 /* nt-port with no channel, not reserverd */
2343 if (!p_m_b_channel && !p_m_b_reserve && p_type==PORT_TYPE_DSS1_NT_OUT)
2344 channel = CHANNEL_NO;
2347 l1l2l3_trace_header(p_m_mISDNport, this, CC_NEW_CR | REQUEST, DIRECTION_OUT);
2353 if (p_m_mISDNport->procids[i] == 0)
2359 struct message *message;
2361 add_trace("callref", NULL, "no free id");
2363 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2364 message->param.disconnectinfo.cause = 47;
2365 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2366 message_put(message);
2367 new_state(PORT_STATE_RELEASE);
2371 p_m_mISDNport->procids[i] = 1;
2372 p_m_d_l3id = 0xff00 | i;
2376 /* if we are in te-mode, we need to create a process first */
2377 if (newteid++ > 0x7fff)
2379 p_m_d_l3id = (entity<<16) | newteid;
2380 /* preparing message */
2381 ncr.prim = CC_NEW_CR | REQUEST;
2382 ncr.addr = p_m_mISDNport->upper_id | FLG_MSG_DOWN;
2383 ncr.dinfo = p_m_d_l3id;
2386 mISDN_write(mISDNdevice, &ncr, mISDN_HEADER_LEN+ncr.len, TIMEOUT_1SEC);
2390 add_trace("callref", "new", "0x%x", p_m_d_l3id);
2393 /* preparing setup message */
2395 l3m = create_l3msg();
2397 dmsg = create_l3msg(CC_SETUP | REQUEST, MT_SETUP, p_m_d_l3id, sizeof(SETUP_t), p_m_d_ntmode);
2398 setup = (SETUP_t *)(dmsg->data + headerlen);
2400 l1l2l3_trace_header(p_m_mISDNport, this, CC_SETUP | REQUEST, DIRECTION_OUT);
2401 /* channel information */
2402 if (channel >= 0) /* it should */
2405 enc_ie_channel_id(l3m, exclusive, channel);
2407 enc_ie_channel_id(&setup->CHANNEL_ID, dmsg, exclusive, channel);
2410 /* caller information */
2412 switch (p_callerinfo.ntype)
2414 case INFO_NTYPE_INTERNATIONAL:
2417 case INFO_NTYPE_NATIONAL:
2420 case INFO_NTYPE_SUBSCRIBER:
2423 default: /* INFO_NTYPE_UNKNOWN */
2427 switch (p_callerinfo.screen)
2429 case INFO_SCREEN_USER:
2432 default: /* INFO_SCREEN_NETWORK */
2436 switch (p_callerinfo.present)
2438 case INFO_PRESENT_RESTRICTED:
2441 case INFO_PRESENT_NOTAVAIL:
2444 default: /* INFO_PRESENT_ALLOWED */
2450 enc_ie_calling_pn(l3m, type, plan, present, screen, (unsigned char *)p_callerinfo.id);
2452 enc_ie_calling_pn(&setup->CALLING_PN, dmsg, type, plan, present, screen, (unsigned char *)p_callerinfo.id);
2454 /* dialing information */
2455 if (p_dialinginfo.id[0]) /* only if we have something to dial */
2458 enc_ie_called_pn(l3m, 0, 1, (unsigned char *)p_dialinginfo.id);
2460 enc_ie_called_pn(&setup->CALLED_PN, dmsg, 0, 1, (unsigned char *)p_dialinginfo.id);
2463 /* sending complete */
2464 if (p_dialinginfo.sending_complete)
2466 enc_ie_complete(l3m, 1);
2468 enc_ie_complete(&setup->COMPLETE, dmsg, 1);
2470 /* sending user-user */
2471 if (param->setup.useruser.len)
2474 enc_ie_useruser(l3m, param->setup.useruser.protocol, param->setup.useruser.data, param->setup.useruser.len);
2476 enc_ie_useruser(&setup->USER_USER, dmsg, param->setup.useruser.protocol, param->setup.useruser.data, param->setup.useruser.len);
2479 /* redirecting number */
2481 switch (p_redirinfo.ntype)
2483 case INFO_NTYPE_INTERNATIONAL:
2486 case INFO_NTYPE_NATIONAL:
2489 case INFO_NTYPE_SUBSCRIBER:
2492 default: /* INFO_NTYPE_UNKNOWN */
2496 switch (p_redirinfo.screen)
2498 case INFO_SCREEN_USER:
2501 default: /* INFO_SCREE_NETWORK */
2505 switch (p_redirinfo.reason)
2507 case INFO_REDIR_BUSY:
2510 case INFO_REDIR_NORESPONSE:
2513 case INFO_REDIR_UNCONDITIONAL:
2516 case INFO_REDIR_CALLDEFLECT:
2519 case INFO_REDIR_OUTOFORDER:
2522 default: /* INFO_REDIR_UNKNOWN */
2526 switch (p_redirinfo.present)
2528 case INFO_PRESENT_NULL: /* no redir at all */
2535 case INFO_PRESENT_RESTRICTED:
2538 case INFO_PRESENT_NOTAVAIL:
2541 default: /* INFO_PRESENT_ALLOWED */
2545 /* sending redirecting number only in ntmode */
2546 if (type >= 0 && p_m_d_ntmode)
2548 enc_ie_redir_nr(l3m, type, plan, present, screen, reason, (unsigned char *)p_redirinfo.id);
2550 enc_ie_redir_nr(&setup->REDIR_NR, dmsg, type, plan, present, screen, reason, (unsigned char *)p_redirinfo.id);
2552 /* bearer capability */
2553 //printf("hlc=%d\n",p_capainfo.hlc);
2555 capability = p_capainfo.bearer_capa;
2556 mode = p_capainfo.bearer_mode;
2557 rate = (mode==INFO_BMODE_CIRCUIT)?0x10:0x00;
2558 switch (p_capainfo.bearer_info1)
2560 case INFO_INFO1_NONE:
2564 user = p_capainfo.bearer_info1 & 0x7f;
2568 enc_ie_bearer(l3m, coding, capability, mode, rate, -1, user);
2570 enc_ie_bearer(&setup->BEARER, dmsg, coding, capability, mode, rate, -1, user);
2578 hlc = p_capainfo.hlc & 0x7f;
2580 if (p_capainfo.exthlc)
2581 exthlc = p_capainfo.exthlc & 0x7f;
2583 enc_ie_hlc(l3m, coding, interpretation, presentation, hlc, exthlc);
2585 enc_ie_hlc(&setup->HLC, dmsg, coding, interpretation, presentation, hlc, exthlc);
2590 if (p_callerinfo.display[0] && p_m_d_ntmode)
2592 enc_ie_display(l3m, (unsigned char *)p_callerinfo.display);
2594 enc_ie_display(&setup->DISPLAY, dmsg, (unsigned char *)p_callerinfo.display);
2596 /* nt-mode: CNIP (calling name identification presentation) */
2597 // if (p_callerinfo.name[0] && p_m_d_ntmode)
2598 // enc_facility_centrex(&setup->FACILITY, dmsg, (unsigned char *)p_callerinfo.name, 1);
2601 /* send setup message now */
2603 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_SETUP, l3m);
2605 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2608 new_state(PORT_STATE_OUT_SETUP);
2611 /* MESSAGE_FACILITY */
2612 void Pdss1::message_facility(unsigned long epoint_id, int message_id, union parameter *param)
2617 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2619 FACILITY_t *facility;
2622 /* facility will not be sent to external lines */
2626 /* sending facility */
2628 l3m = create_l3msg();
2630 dmsg = create_l3msg(CC_FACILITY | REQUEST, MT_FACILITY, p_m_d_l3id, sizeof(FACILITY_t), p_m_d_ntmode);
2631 facility = (FACILITY_t *)(dmsg->data + headerlen);
2633 l1l2l3_trace_header(p_m_mISDNport, this, CC_FACILITY | REQUEST, DIRECTION_OUT);
2635 enc_ie_facility(l3m, (unsigned char *)param->facilityinfo.data, param->facilityinfo.len);
2637 enc_ie_facility(&facility->FACILITY, dmsg, (unsigned char *)param->facilityinfo.data, param->facilityinfo.len);
2641 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_FACILITY, l3m);
2643 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2647 /* MESSAGE_NOTIFY */
2648 void Pdss1::message_notify(unsigned long epoint_id, int message_id, union parameter *param)
2653 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2655 INFORMATION_t *information;
2656 NOTIFY_t *notification;
2659 int plan, type = -1, present;
2661 if (param->notifyinfo.notify>INFO_NOTIFY_NONE)
2662 notify = param->notifyinfo.notify & 0x7f;
2665 if (p_state != PORT_STATE_CONNECT)
2667 /* notify only allowed in active state */
2673 switch (param->notifyinfo.ntype)
2675 case INFO_NTYPE_INTERNATIONAL:
2678 case INFO_NTYPE_NATIONAL:
2681 case INFO_NTYPE_SUBSCRIBER:
2684 default: /* INFO_NTYPE_UNKNOWN */
2688 switch (param->notifyinfo.present)
2690 case INFO_PRESENT_NULL: /* no redir at all */
2695 case INFO_PRESENT_RESTRICTED:
2698 case INFO_PRESENT_NOTAVAIL:
2701 default: /* INFO_PRESENT_ALLOWED */
2707 if (notify<0 && !param->notifyinfo.display[0])
2709 /* nothing to notify, nothing to display */
2715 if (p_state!=PORT_STATE_CONNECT)
2717 /* queue notification */
2718 if (p_m_d_notify_pending)
2719 message_free(p_m_d_notify_pending);
2720 p_m_d_notify_pending = message_create(ACTIVE_EPOINT(p_epointlist), p_serial, EPOINT_TO_PORT, message_id);
2721 memcpy(&p_m_d_notify_pending->param, param, sizeof(union parameter));
2724 /* sending notification */
2726 l3m = create_l3msg();
2728 dmsg = create_l3msg(CC_NOTIFY | REQUEST, MT_NOTIFY, p_m_d_l3id, sizeof(NOTIFY_t), p_m_d_ntmode);
2729 notification = (NOTIFY_t *)(dmsg->data + headerlen);
2731 l1l2l3_trace_header(p_m_mISDNport, this, CC_NOTIFY | REQUEST, DIRECTION_OUT);
2733 enc_ie_notify(l3m, notify);
2735 enc_ie_notify(¬ification->NOTIFY, dmsg, notify);
2737 /* sending redirection number only in ntmode */
2738 if (type >= 0 && p_m_d_ntmode)
2740 enc_ie_redir_dn(l3m, type, plan, present, (unsigned char *)param->notifyinfo.id);
2742 enc_ie_redir_dn(¬ification->REDIR_DN, dmsg, type, plan, present, (unsigned char *)param->notifyinfo.id);
2744 if (param->notifyinfo.display[0] && p_m_d_ntmode)
2746 enc_ie_display(l3m, (unsigned char *)param->notifyinfo.display);
2748 enc_ie_display(¬ification->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display);
2752 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_NOTIFICATION, l3m);
2754 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2757 } else if (p_m_d_ntmode)
2759 /* sending information */
2761 l3m = create_l3msg();
2763 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2764 information = (INFORMATION_t *)(dmsg->data + headerlen);
2766 l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT);
2768 enc_ie_display(l3m, (unsigned char *)param->notifyinfo.display);
2770 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display);
2774 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_INFORMATION, l3m);
2776 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2781 /* MESSAGE_OVERLAP */
2782 void Pdss1::message_overlap(unsigned long epoint_id, int message_id, union parameter *param)
2787 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2789 SETUP_ACKNOWLEDGE_t *setup_acknowledge;
2792 /* sending setup_acknowledge */
2794 l3m = create_l3msg();
2796 dmsg = create_l3msg(CC_SETUP_ACKNOWLEDGE | REQUEST, MT_SETUP_ACKNOWLEDGE, p_m_d_l3id, sizeof(SETUP_ACKNOWLEDGE_t), p_m_d_ntmode);
2797 setup_acknowledge = (SETUP_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
2799 l1l2l3_trace_header(p_m_mISDNport, this, CC_SETUP_ACKNOWLEDGE | REQUEST, DIRECTION_OUT);
2800 /* channel information */
2801 if (p_state == PORT_STATE_IN_SETUP)
2803 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2805 enc_ie_channel_id(&setup_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2807 /* progress information */
2808 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2809 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2810 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2811 if (p_m_mISDNport->tones)
2813 enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
2815 enc_ie_progress(&setup_acknowledge->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2819 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_SETUP_ACKNOWLEDGE, l3m);
2821 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2824 new_state(PORT_STATE_IN_OVERLAP);
2827 /* MESSAGE_PROCEEDING */
2828 void Pdss1::message_proceeding(unsigned long epoint_id, int message_id, union parameter *param)
2833 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2835 CALL_PROCEEDING_t *proceeding;
2838 /* sending proceeding */
2840 l3m = create_l3msg();
2842 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2843 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2845 l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2846 /* channel information */
2847 if (p_state == PORT_STATE_IN_SETUP)
2849 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2851 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2853 /* progress information */
2854 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2855 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2856 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2857 if (p_m_mISDNport->tones)
2859 enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
2861 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2865 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_PROCEEDING, l3m);
2867 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2870 new_state(PORT_STATE_IN_PROCEEDING);
2873 /* MESSAGE_ALERTING */
2874 void Pdss1::message_alerting(unsigned long epoint_id, int message_id, union parameter *param)
2879 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2881 ALERTING_t *alerting;
2884 /* NT-MODE in setup state we must send PROCEEDING first */
2885 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2887 CALL_PROCEEDING_t *proceeding;
2889 /* sending proceeding */
2891 l3m = create_l3msg();
2893 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2894 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2896 l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2897 /* channel information */
2899 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2901 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2903 /* progress information */
2904 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2905 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2906 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2908 enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
2910 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2914 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_PROCEEDING, l3m);
2916 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2918 new_state(PORT_STATE_IN_PROCEEDING);
2921 /* sending alerting */
2923 l3m = create_l3msg();
2925 dmsg = create_l3msg(CC_ALERTING | REQUEST, MT_ALERTING, p_m_d_l3id, sizeof(ALERTING_t), p_m_d_ntmode);
2926 alerting = (ALERTING_t *)(dmsg->data + headerlen);
2928 l1l2l3_trace_header(p_m_mISDNport, this, CC_ALERTING | REQUEST, DIRECTION_OUT);
2929 /* channel information */
2930 if (p_state == PORT_STATE_IN_SETUP)
2932 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2934 enc_ie_channel_id(&alerting->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2936 /* progress information */
2937 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2938 || p_capainfo.bearer_capa==INFO_BC_AUDIO
2939 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2940 if (p_m_mISDNport->tones)
2942 enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
2944 enc_ie_progress(&alerting->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
2948 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_ALERTING, l3m);
2950 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2953 new_state(PORT_STATE_IN_ALERTING);
2956 /* MESSAGE_CONNECT */
2957 void Pdss1::message_connect(unsigned long epoint_id, int message_id, union parameter *param)
2962 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2964 INFORMATION_t *information;
2967 int type, plan, present, screen;
2968 class Endpoint *epoint;
2970 /* NT-MODE in setup state we must send PROCEEDING first */
2971 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
2973 CALL_PROCEEDING_t *proceeding;
2975 /* sending proceeding */
2977 l3m = create_l3msg();
2979 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
2980 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
2982 l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
2983 /* channel information */
2985 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2987 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2989 // /* progress information */
2990 // if (p_capainfo.bearer_capa==INFO_BC_SPEECH
2991 // || p_capainfo.bearer_capa==INFO_BC_AUDIO
2992 // || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
2994 // enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
2996 // enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
3000 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_PROCEEDING, l3m);
3002 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3004 new_state(PORT_STATE_IN_PROCEEDING);
3007 /* copy connected information */
3008 memcpy(&p_connectinfo, ¶m->connectinfo, sizeof(p_connectinfo));
3009 /* screen outgoing caller id */
3010 do_screen(1, p_connectinfo.id, sizeof(p_connectinfo.id), &p_connectinfo.ntype, &p_connectinfo.present, p_m_mISDNport->ifport->interface);
3012 /* only display at connect state */
3013 if (p_state == PORT_STATE_CONNECT)
3014 if (p_connectinfo.display[0])
3016 /* sending information */
3018 l3m = create_l3msg();
3020 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
3021 information = (INFORMATION_t *)(dmsg->data + headerlen);
3023 l1l2l3_trace_header(p_m_mISDNport, this, CC_INFORMATION | REQUEST, DIRECTION_OUT);
3026 enc_ie_display(l3m, (unsigned char *)p_connectinfo.display);
3028 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_connectinfo.display);
3032 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_INFORMATION, l3m);
3034 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3039 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)
3041 /* connect command only possible in setup, proceeding or alerting state */
3045 /* preparing connect message */
3047 l3m = create_l3msg();
3049 dmsg = create_l3msg(CC_CONNECT | REQUEST, MT_CONNECT, p_m_d_l3id, sizeof(CONNECT_t), p_m_d_ntmode);
3050 connect = (CONNECT_t *)(dmsg->data + headerlen);
3052 l1l2l3_trace_header(p_m_mISDNport, this, CC_CONNECT | REQUEST, DIRECTION_OUT);
3053 /* connect information */
3055 switch (p_connectinfo.ntype)
3057 case INFO_NTYPE_INTERNATIONAL:
3060 case INFO_NTYPE_NATIONAL:
3063 case INFO_NTYPE_SUBSCRIBER:
3066 default: /* INFO_NTYPE_UNKNOWN */
3070 switch (param->connectinfo.screen)
3072 case INFO_SCREEN_USER:
3075 default: /* INFO_SCREE_NETWORK */
3079 switch (p_connectinfo.present)
3081 case INFO_PRESENT_NULL: /* no colp at all */
3087 case INFO_PRESENT_RESTRICTED:
3090 case INFO_PRESENT_NOTAVAIL:
3093 default: /* INFO_PRESENT_ALLOWED */
3099 enc_ie_connected_pn(l3m, type, plan, present, screen, (unsigned char *)p_connectinfo.id);
3101 enc_ie_connected_pn(&connect->CONNECT_PN, dmsg, type, plan, present, screen, (unsigned char *)p_connectinfo.id);
3104 if (p_connectinfo.display[0] && p_m_d_ntmode)
3106 enc_ie_display(l3m, (unsigned char *)p_connectinfo.display);
3108 enc_ie_display(&connect->DISPLAY, dmsg, (unsigned char *)p_connectinfo.display);
3110 /* nt-mode: CONP (connected name identification presentation) */
3111 // if (p_connectinfo.name[0] && p_m_d_ntmode)
3112 // enc_facility_centrex(&connect->FACILITY, dmsg, (unsigned char *)p_connectinfo.name, 0);
3116 epoint = find_epoint_id(epoint_id);
3118 enc_ie_date(l3m, now, p_settings.no_seconds);
3120 enc_ie_date(&connect->DATE, dmsg, now, p_settings.no_seconds);
3124 /* finally send message */
3126 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_CONNECT, l3m);
3128 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3132 new_state(PORT_STATE_CONNECT);
3134 new_state(PORT_STATE_CONNECT_WAITING);
3138 /* MESSAGE_DISCONNECT */
3139 void Pdss1::message_disconnect(unsigned long epoint_id, int message_id, union parameter *param)
3144 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
3146 DISCONNECT_t *disconnect;
3147 RELEASE_COMPLETE_t *release_complete;
3149 struct message *message;
3152 /* we reject during incoming setup when we have no tones. also if we are in outgoing setup state */
3153 // if ((p_state==PORT_STATE_IN_SETUP && !p_m_mISDNport->tones)
3154 if (/* ||*/ p_state==PORT_STATE_OUT_SETUP)
3156 /* sending release to endpoint */
3159 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
3160 message->param.disconnectinfo.cause = 16;
3161 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
3162 message_put(message);
3164 free_epointlist(p_epointlist);
3166 /* sending release */
3168 l3m = create_l3msg();
3170 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
3171 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
3173 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_COMPLETE | REQUEST, DIRECTION_OUT);
3176 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
3178 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);
3182 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_RELEASE_COMPLETE, l3m);
3184 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3186 new_state(PORT_STATE_RELEASE);
3191 /* workarround: NT-MODE in setup state we must send PROCEEDING first to make it work */
3192 if (p_state==PORT_STATE_IN_SETUP)
3194 CALL_PROCEEDING_t *proceeding;
3196 /* sending proceeding */
3198 l3m = create_l3msg();
3200 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
3201 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
3203 l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
3204 /* channel information */
3206 enc_ie_channel_id(l3m, 1, p_m_b_channel);
3208 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
3210 /* progress information */
3211 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
3212 || p_capainfo.bearer_capa==INFO_BC_AUDIO
3213 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
3215 enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
3217 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
3221 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_PROCEEDING, l3m);
3223 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3225 new_state(PORT_STATE_IN_PROCEEDING);
3228 /* sending disconnect */
3230 l3m = create_l3msg();
3232 dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode);
3233 disconnect = (DISCONNECT_t *)(dmsg->data + headerlen);
3235 l1l2l3_trace_header(p_m_mISDNport, this, CC_DISCONNECT | REQUEST, DIRECTION_OUT);
3236 /* progress information */
3237 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
3238 || p_capainfo.bearer_capa==INFO_BC_AUDIO
3239 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
3240 if (p_m_mISDNport->tones)
3242 enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
3244 enc_ie_progress(&disconnect->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
3248 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
3250 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);
3253 if (param->disconnectinfo.display[0])
3254 p = param->disconnectinfo.display;
3255 if (p) if (*p && p_m_d_ntmode)
3257 enc_ie_display(l3m, (unsigned char *)p);
3259 enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p);
3263 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_DISCONNECT, l3m);
3265 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3267 new_state(PORT_STATE_OUT_DISCONNECT);
3270 /* MESSAGE_RELEASE */
3271 void Pdss1::message_release(unsigned long epoint_id, int message_id, union parameter *param)
3276 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
3279 RELEASE_COMPLETE_t *release_complete;
3280 DISCONNECT_t *disconnect;
3282 class Endpoint *epoint;
3286 * we may only release during incoming disconnect state.
3287 * this means that the endpoint doesnt require audio anymore
3289 if (p_state == PORT_STATE_IN_DISCONNECT
3290 || p_state == PORT_STATE_OUT_DISCONNECT)
3292 /* sending release */
3294 l3m = create_l3msg();
3296 dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, p_m_d_l3id, sizeof(RELEASE_t), p_m_d_ntmode);
3297 release = (RELEASE_t *)(dmsg->data + headerlen);
3299 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE | REQUEST, DIRECTION_OUT);
3302 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
3304 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);
3308 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_RELEASE, l3m);
3310 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3312 new_state(PORT_STATE_RELEASE);
3314 free_epointid(epoint_id);
3315 // wait for callref to be released
3320 * if we are on incoming call setup, we may reject by sending a release_complete
3321 * also on outgoing call setup, we send a release complete, BUT this is not conform. (i don't know any other way)
3323 if (p_state==PORT_STATE_IN_SETUP
3324 || p_state==PORT_STATE_OUT_SETUP)
3325 // // NOTE: a bug in mISDNuser (see disconnect_req_out !!!)
3326 // || p_state==PORT_STATE_OUT_DISCO)
3328 //#warning remove me
3329 //PDEBUG(DEBUG_LOG, "JOLLY sending release complete %d\n", p_serial);
3330 /* sending release complete */
3332 l3m = create_l3msg();
3334 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
3335 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
3337 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE | REQUEST, DIRECTION_OUT);
3340 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
3342 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);
3346 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_RELEASE_COMPLETE, l3m);
3348 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3350 new_state(PORT_STATE_RELEASE);
3352 free_epointid(epoint_id);
3354 /* remove process */
3355 l1l2l3_trace_header(p_m_mISDNport, this, CC_RELEASE_CR | REQUEST, DIRECTION_OUT);
3356 add_trace("callref", NULL, "0x%x", p_m_d_l3id);
3360 if ((p_m_d_l3id&0xff00) == 0xff00)
3361 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
3366 // wait for callref to be released
3371 wirklich erst proceeding?:
3372 /* NT-MODE in setup state we must send PROCEEDING first */
3373 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
3375 CALL_PROCEEDING_t *proceeding;
3377 /* sending proceeding */
3379 l3m = create_l3msg();
3381 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
3382 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
3384 l1l2l3_trace_header(p_m_mISDNport, this, CC_PROCEEDING | REQUEST, DIRECTION_OUT);
3385 /* channel information */
3387 enc_ie_channel_id(l3m, 1, p_m_b_channel);
3389 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
3391 /* progress information */
3392 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
3393 || p_capainfo.bearer_capa==INFO_BC_AUDIO
3394 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
3396 enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
3398 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
3402 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_PROCEEDING, l3m);
3404 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3409 /* sending disconnect */
3411 l3m = create_l3msg();
3413 dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode);
3414 disconnect = (DISCONNECT_t *)(dmsg->data + headerlen);
3416 l1l2l3_trace_header(p_m_mISDNport, this, CC_DISCONNECT | REQUEST, DIRECTION_OUT);
3417 /* progress information */
3418 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
3419 || p_capainfo.bearer_capa==INFO_BC_AUDIO
3420 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
3421 if (p_m_mISDNport->tones)
3423 enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
3425 enc_ie_progress(&disconnect->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
3429 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
3431 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);
3434 epoint = find_epoint_id(epoint_id);
3435 if (param->disconnectinfo.display[0])
3436 p = param->disconnectinfo.display;
3437 if (p) if (*p && p_m_d_ntmode)
3439 enc_ie_display(l3m, (unsigned char *)p);
3441 enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p);
3445 p_m_mISDNport->layer3->to_layer3(p_m_mISDNport->layer3, MT_DISCONNECT, l3m);
3447 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3449 new_state(PORT_STATE_OUT_DISCONNECT);
3451 free_epointid(epoint_id);
3452 // wait for release and callref to be released
3453 //#warning remove me
3454 //PDEBUG(DEBUG_LOG, "JOLLY sending disconnect %d\n", p_serial);
3459 * endpoint sends messages to the port
3461 int Pdss1::message_epoint(unsigned long epoint_id, int message_id, union parameter *param)
3463 struct message *message;
3465 if (PmISDN::message_epoint(epoint_id, message_id, param))
3470 case MESSAGE_INFORMATION: /* overlap dialing */
3471 if (p_type==PORT_TYPE_DSS1_NT_OUT
3472 && p_state!=PORT_STATE_OUT_OVERLAP
3473 && p_state!=PORT_STATE_CONNECT
3474 && p_state!=PORT_STATE_OUT_DISCONNECT
3475 && p_state!=PORT_STATE_IN_DISCONNECT)
3479 if (p_type==PORT_TYPE_DSS1_TE_OUT
3480 && p_state!=PORT_STATE_OUT_OVERLAP
3481 && p_state!=PORT_STATE_OUT_PROCEEDING
3482 && p_state!=PORT_STATE_OUT_ALERTING
3483 && p_state!=PORT_STATE_CONNECT
3484 && p_state!=PORT_STATE_OUT_DISCONNECT
3485 && p_state!=PORT_STATE_IN_DISCONNECT)
3489 if ((p_type==PORT_TYPE_DSS1_NT_IN || p_type==PORT_TYPE_DSS1_TE_IN)
3490 && p_state!=PORT_STATE_IN_OVERLAP
3491 && p_state!=PORT_STATE_IN_PROCEEDING
3492 && p_state!=PORT_STATE_IN_ALERTING
3493 && p_state!=PORT_STATE_CONNECT
3494 && p_state!=PORT_STATE_CONNECT_WAITING
3495 && p_state!=PORT_STATE_OUT_DISCONNECT
3496 && p_state!=PORT_STATE_IN_DISCONNECT)
3500 message_information(epoint_id, message_id, param);
3503 case MESSAGE_SETUP: /* dial-out command received from epoint */
3504 if (p_state!=PORT_STATE_IDLE
3505 && p_state!=PORT_STATE_CONNECT)
3507 PERROR("Pdss1(%s) ignoring setup because isdn port is not in idle state (or connected for sending display info).\n", p_name);
3510 if (p_epointlist && p_state==PORT_STATE_IDLE)
3511 FATAL("Pdss1(%s): epoint pointer is set in idle state, how bad!!\n", p_name);
3512 /* note: pri is a special case, because links must be up for pri */
3513 if (p_m_mISDNport->l1link || p_m_mISDNport->pri || !p_m_mISDNport->ntmode || p_state!=PORT_STATE_IDLE)
3515 /* LAYER 1 is up, or we may send */
3516 message_setup(epoint_id, message_id, param);
3519 /* LAYER 1 id down, so we queue */
3520 p_m_d_queue = message_create(epoint_id, p_serial, EPOINT_TO_PORT, message_id);
3521 memcpy(&p_m_d_queue->param, param, sizeof(union parameter));
3523 if (!(epointlist_new(epoint_id)))
3524 FATAL("No memory for epointlist\n");
3526 PDEBUG(DEBUG_ISDN, "the L1 is down, we try to establish the link NT portnum=%d (%s).\n", p_m_mISDNport->portnum, p_name);
3527 act.prim = PH_ACTIVATE | REQUEST;
3528 act.addr = p_m_mISDNport->upper_id | FLG_MSG_DOWN;
3531 mISDN_write(mISDNdevice, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
3532 l1l2l3_trace_header(p_m_mISDNport, this, act.prim, DIRECTION_OUT);
3534 // /* set timeout */
3535 // p_m_mISDNport->l1timeout = now+3;
3539 case MESSAGE_NOTIFY: /* display and notifications */
3540 message_notify(epoint_id, message_id, param);
3543 case MESSAGE_FACILITY: /* facility message */
3544 message_facility(epoint_id, message_id, param);
3547 case MESSAGE_OVERLAP: /* more information is needed */
3548 if (p_state!=PORT_STATE_IN_SETUP)
3552 message_overlap(epoint_id, message_id, param);
3555 case MESSAGE_PROCEEDING: /* call of endpoint is proceeding */
3556 if (p_state!=PORT_STATE_IN_SETUP
3557 && p_state!=PORT_STATE_IN_OVERLAP)
3561 message_proceeding(epoint_id, message_id, param);
3564 case MESSAGE_ALERTING: /* call of endpoint is ringing */
3565 if (p_state!=PORT_STATE_IN_SETUP
3566 && p_state!=PORT_STATE_IN_OVERLAP
3567 && p_state!=PORT_STATE_IN_PROCEEDING)
3571 message_alerting(epoint_id, message_id, param);
3574 case MESSAGE_CONNECT: /* call of endpoint is connected */
3575 if (p_state!=PORT_STATE_IN_SETUP
3576 && p_state!=PORT_STATE_IN_OVERLAP
3577 && p_state!=PORT_STATE_IN_PROCEEDING
3578 && p_state!=PORT_STATE_IN_ALERTING
3579 && !(p_state==PORT_STATE_CONNECT && p_m_d_ntmode))
3583 message_connect(epoint_id, message_id, param);
3586 case MESSAGE_DISCONNECT: /* call has been disconnected */
3587 if (p_state!=PORT_STATE_IN_SETUP
3588 && p_state!=PORT_STATE_IN_OVERLAP
3589 && p_state!=PORT_STATE_IN_PROCEEDING
3590 && p_state!=PORT_STATE_IN_ALERTING
3591 && p_state!=PORT_STATE_OUT_SETUP
3592 && p_state!=PORT_STATE_OUT_OVERLAP
3593 && p_state!=PORT_STATE_OUT_PROCEEDING
3594 && p_state!=PORT_STATE_OUT_ALERTING
3595 && p_state!=PORT_STATE_CONNECT
3596 && p_state!=PORT_STATE_CONNECT_WAITING)
3600 message_disconnect(epoint_id, message_id, param);
3603 case MESSAGE_RELEASE: /* release isdn port */
3604 if (p_state==PORT_STATE_RELEASE)
3608 message_release(epoint_id, message_id, param);
3612 PERROR("Pdss1(%s) isdn port with (caller id %s) received a wrong message: %d\n", p_name, p_callerinfo.id, message);
3621 * data from isdn-stack (layer-3) to pbx (port class)
3623 /* NOTE: nt mode use mISDNuser_head_t as header */
3624 int stack2manager_nt(void *dat, void *arg)
3628 manager_t *mgr = (manager_t *)dat;
3629 msg_t *msg = (msg_t *)arg;
3630 mISDNuser_head_t *hh;
3631 struct mISDNport *mISDNport;
3637 /* note: nst is the first data feld of mISDNport */
3638 mISDNport = (struct mISDNport *)mgr->nst;
3640 hh = (mISDNuser_head_t *)msg->data;
3641 PDEBUG(DEBUG_ISDN, "prim(0x%x) dinfo(0x%x) msg->len(%d)\n", hh->prim, hh->dinfo, msg->len);
3643 /* find Port object of type ISDN */
3647 if (port->p_type == PORT_TYPE_DSS1_NT_IN || port->p_type == PORT_TYPE_DSS1_NT_OUT)
3649 pdss1 = (class Pdss1 *)port;
3650 //PDEBUG(DEBUG_ISDN, "comparing dinfo = 0x%x with l3id 0x%x\n", hh->dinfo, pdss1->p_m_d_l3id);
3651 /* check out correct stack */
3652 if (pdss1->p_m_mISDNport == mISDNport)
3653 /* check out correct id */
3654 if ((pdss1->p_m_d_l3id&0x0000ff00) != 0x000ff00)
3656 /* a single process */
3657 if (hh->dinfo == pdss1->p_m_d_l3id)
3659 /* found port, the message belongs to */
3664 /* a broadcast process */
3665 if ((hh->dinfo&0xffff0000) == (pdss1->p_m_d_l3id&0xffff0000))
3667 /* found port, the message belongs to */
3676 //printf("%x %x\n", hh->dinfo, pdss1->p_m_d_l3id);
3677 /* if process id is master process, but a child disconnects */
3678 if ((hh->dinfo&0x0000ff00)!=0x0000ff00 && (pdss1->p_m_d_l3id&0x0000ff00)==0x0000ff00)
3680 if (hh->prim == (CC_DISCONNECT|INDICATION))
3682 /* send special indication for child disconnect */
3683 pdss1->disconnect_ind_i(hh->prim, hh->dinfo, msg->data);
3687 // ignoring other messages from child processes
3691 /* if process id and layer 3 id matches */
3692 if (hh->dinfo == pdss1->p_m_d_l3id)
3694 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
3703 case MGR_SHORTSTATUS | INDICATION:
3704 case MGR_SHORTSTATUS | CONFIRM:
3706 case SSTATUS_L2_ESTABLISHED:
3708 case SSTATUS_L2_RELEASED:
3713 case DL_ESTABLISH | INDICATION:
3714 case DL_ESTABLISH | CONFIRM:
3716 l1l2l3_trace_header(mISDNport, NULL, hh->prim, DIRECTION_IN);
3717 add_trace("tei", NULL, "%d", hh->dinfo);
3719 if (mISDNport->ptp && hh->dinfo == 0)
3721 if (mISDNport->l2establish)
3723 mISDNport->l2establish = 0;
3724 PDEBUG(DEBUG_ISDN, "the link became active before l2establish timer expiry.\n");
3726 mISDNport->l2link = 1;
3727 if (mISDNport->pri);
3728 mISDNport->l1link = 1; /* this is a hack, we also assume L1 to be active */
3732 case DL_RELEASE | INDICATION:
3733 case DL_RELEASE | CONFIRM:
3735 l1l2l3_trace_header(mISDNport, NULL, hh->prim, DIRECTION_IN);
3736 add_trace("tei", NULL, "%d", hh->dinfo);
3738 if (mISDNport->ptp && hh->dinfo == 0)
3740 mISDNport->l2link = 0;
3741 time(&mISDNport->l2establish);
3742 PDEBUG(DEBUG_ISDN, "because we are ptp, we set a l2establish timer.\n");
3744 //#warning debugging usleep crash
3745 // printf("JOLLY release port %d\n", mISDNport->portnum);
3749 case CC_SETUP | INDICATION:
3750 /* creating port object */
3751 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3752 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0)))
3754 FATAL("Cannot create Port instance.\n");
3755 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
3758 case CC_RESUME | INDICATION:
3759 /* creating port object */
3760 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3761 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0)))
3762 FATAL("Cannot create Port instance.\n");
3763 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
3766 case CC_RELEASE_CR | INDICATION:
3767 PERROR("unhandled message from stack: call ref released (l3id=0x%x)\n", hh->dinfo);
3770 case CC_RELEASE_COMPLETE | INDICATION:
3773 case CC_FACILITY | INDICATION:
3777 PERROR("unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", hh->prim, hh->dinfo, msg->len);
3781 if (port->p_type == PORT_TYPE_DSS1_NT_IN || port->p_type == PORT_TYPE_DSS1_NT_OUT)
3783 pdss1 = (class Pdss1 *)port;
3784 //PDEBUG(DEBUG_ISDN, "comparing dinfo = 0x%x with l3id 0x%x\n", hh->dinfo, pdss1->p_m_d_l3id);
3785 /* check out correct stack */
3786 if (pdss1->p_m_mISDNport == mISDNport)
3787 /* check out correct id */
3788 PERROR("unhandled message: dinfo=%x is not associated with port-dinfo=%x\n",hh->dinfo,pdss1->p_m_d_l3id);
3798 /* NOTE: te mode use iframe_t as header */
3799 int stack2manager_te(struct mISDNport *mISDNport, msg_t *msg)
3806 if (!msg || !mISDNport)
3808 frm = (iframe_t *)msg->data;
3809 PDEBUG(DEBUG_ISDN, "prim(0x%x) dinfo(0x%x) msg->len(%d)\n", frm->prim, frm->dinfo, msg->len);
3811 /* find Port object of type ISDN */
3815 if (port->p_type == PORT_TYPE_DSS1_TE_IN || port->p_type == PORT_TYPE_DSS1_TE_OUT)
3817 pdss1 = (class Pdss1 *)port;
3818 /* check out correct stack */
3819 if (pdss1->p_m_mISDNport == mISDNport)
3820 /* check out correct id */
3821 if (frm->dinfo == pdss1->p_m_d_l3id)
3823 /* found port, the message belongs to */
3831 pdss1->message_isdn(frm->prim, frm->dinfo, msg->data);
3836 /* process new cr (before setup indication) */
3837 //printf("prim = 0x%x, looking for 0x%x\n",frm->prim, (CC_NEW_CR | INDICATION));
3838 if (frm->prim == (CC_NEW_CR | INDICATION))
3841 /* creating port object */
3842 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
3843 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_TE_IN, mISDNport, name, NULL, 0, 0)))
3844 FATAL("Cannot create Port instance.\n");
3845 /* l3id will be set from dinfo at message_isdn */
3846 pdss1->message_isdn(frm->prim, frm->dinfo, msg->data);
3851 if (frm->prim == (CC_RELEASE_CR | INDICATION))
3853 PDEBUG(DEBUG_ISDN, "unhandled message from stack: call ref released (l3id=0x%x)\n", frm->dinfo);
3857 PERROR("unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", frm->prim, frm->dinfo, msg->len);
3863 * sending message that were queued during L1 activation
3864 * or releasing port if link is down
3866 void setup_queue(struct mISDNport *mISDNport, int link)
3870 struct message *message;
3872 if (!mISDNport->ntmode)
3875 /* check all port objects for pending message */
3879 if ((port->p_type&PORT_CLASS_mISDN_MASK) == PORT_CLASS_mISDN_DSS1)
3881 pdss1 = (class Pdss1 *)port;
3882 if (pdss1->p_m_mISDNport == mISDNport)
3884 if (pdss1->p_m_d_queue)
3888 PDEBUG(DEBUG_ISDN, "the L1 became active, so we send queued message for portnum=%d (%s).\n", mISDNport->portnum, pdss1->p_name);
3889 /* LAYER 1 is up, so we send */
3890 pdss1->message_setup(pdss1->p_m_d_queue->id_from, pdss1->p_m_d_queue->type, &pdss1->p_m_d_queue->param);
3891 message_free(pdss1->p_m_d_queue);
3892 pdss1->p_m_d_queue = NULL;
3895 PDEBUG(DEBUG_ISDN, "the L1 became NOT active, so we release port for portnum=%d (%s).\n", mISDNport->portnum, pdss1->p_name);
3896 message = message_create(pdss1->p_serial, pdss1->p_m_d_queue->id_from, PORT_TO_EPOINT, MESSAGE_RELEASE);
3897 message->param.disconnectinfo.cause = 27;
3898 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
3899 message_put(message);
3900 pdss1->new_state(PORT_STATE_RELEASE);
3901 pdss1->p_m_delete = 1;