1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
10 \*****************************************************************************/
17 #include <mISDNuser/net_l2.h>
21 #include <sys/socket.h>
24 #include <mISDNuser/mISDNif.h>
25 #include <mISDNuser/q931.h>
26 #include <mISDNuser/mlayer3.h>
27 extern unsigned long mt_assign_pid;
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);
63 /* check how many processes are left */
64 if (p_m_d_ntmode == 1)
66 if (p_m_mISDNport->nst.layer3->proc)
67 PDEBUG(DEBUG_ISDN, "destroyed mISDNPort(%s). WARNING: There is still a layer 3 process left. Ignore this, if currently are other calls. This message is not an error!\n", p_name);
74 * create layer 3 message
77 static struct l3_msg *create_l3msg(void)
79 static msg_t *create_l3msg(int prim, int mt, int dinfo, int size, int ntmode)
94 size = sizeof(Q931_info_t)+2;
98 dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL);
105 dmsg = alloc_msg(size+256+mISDN_HEADER_LEN+DEFAULT_HEADROOM);
108 memset(msg_put(dmsg,size+mISDN_HEADER_LEN), 0, size+mISDN_HEADER_LEN);
109 frm = (iframe_t *)dmsg->data;
112 qi = (Q931_info_t *)(dmsg->data + mISDN_HEADER_LEN);
119 FATAL("Cannot allocate memory, system overloaded.\n");
120 exit(0); // make gcc happy
124 msg_t *create_l2msg(int prim, int dinfo, int size) /* NT only */
128 dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL);
132 FATAL("Cannot allocate memory, system overloaded.\n");
133 exit(0); // make gcc happy
138 * if we received a first reply to the setup message,
139 * we will check if we have now channel information
140 * return: <0: error, call is released, -cause is given
141 * 0: ok, nothing to do
144 int Pdss1::received_first_reply_to_setup(unsigned long cmd, int channel, int exclusive)
146 int Pdss1::received_first_reply_to_setup(unsigned long prim, int channel, int exclusive)
153 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
154 RELEASE_COMPLETE_t *release_complete;
158 /* correct exclusive to 0, if no explicit channel was given */
159 if (exclusive<0 || channel<=0)
162 /* select scenario */
163 if (p_m_b_channel && p_m_b_exclusive)
165 /*** we gave an exclusive channel (or if we are done) ***/
167 /* if not first reply, we are done */
168 if (p_state != PORT_STATE_OUT_SETUP)
171 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
172 add_trace("channel", "request", "%d (forced)", p_m_b_channel);
173 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
175 /* if give channel not accepted or not equal */
176 if (channel!=-1 && p_m_b_channel!=channel)
178 add_trace("conclusion", NULL, "forced channel not accepted");
184 add_trace("conclusion", NULL, "channel was accepted");
185 add_trace("connect", "channel", "%d", p_m_b_channel);
188 /* activate our exclusive channel */
189 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
193 /*** we gave a non-exclusive channel ***/
195 /* if not first reply, we are done */
196 if (p_state != PORT_STATE_OUT_SETUP)
199 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
200 add_trace("channel", "request", "%d (suggest)", p_m_b_channel);
201 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
203 /* if channel was accepted as given */
204 if (channel==-1 || p_m_b_channel==channel)
206 add_trace("conclusion", NULL, "channel was accepted as given");
207 add_trace("connect", "channel", "%d", p_m_b_channel);
209 p_m_b_exclusive = 1; // we are done
210 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
214 /* if channel value is faulty */
217 add_trace("conclusion", NULL, "illegal reply");
219 ret = -111; // protocol error
223 /* if channel was not accepted, try to get it */
224 ret = seize_bchannel(channel, 1); // exclusively
225 add_trace("channel", "available", ret<0?"no":"yes");
228 add_trace("conclusion", NULL, "replied channel not available");
232 add_trace("conclusion", NULL, "replied channel accepted");
233 add_trace("connect", "channel", "%d", p_m_b_channel);
236 /* activate channel given by remote */
237 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
241 /*** we sent 'any channel acceptable' ***/
243 /* if not first reply, we are done */
244 if (p_state != PORT_STATE_OUT_SETUP)
247 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
248 add_trace("channel", "request", "any");
249 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
250 /* if no channel was replied */
253 add_trace("conclusion", NULL, "no channel, protocol error");
255 ret = -111; // protocol error
259 /* we will see, if our received channel is available */
260 ret = seize_bchannel(channel, 1); // exclusively
261 add_trace("channel", "available", ret<0?"no":"yes");
264 add_trace("conclusion", NULL, "replied channel not available");
268 add_trace("conclusion", NULL, "replied channel accepted");
269 add_trace("connect", "channel", "%d", p_m_b_channel);
272 /* activate channel given by remote */
273 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
276 /*** we sent 'no channel available' ***/
278 /* if not the first reply, but a connect, we are forced */
280 if (cmd==MT_CONNECT && p_state!=PORT_STATE_OUT_SETUP)
282 if (prim==(CC_CONNECT | INDICATION) && p_state!=PORT_STATE_OUT_SETUP)
285 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (connect)", DIRECTION_NONE);
286 add_trace("channel", "request", "no-channel");
287 add_trace("channel", "reply", (channel>=0)?"%d%s":"(none)", channel, exclusive?" (forced)":"");
290 goto use_from_connect;
292 ret = seize_bchannel(CHANNEL_ANY, 0); // any channel
293 add_trace("channel", "available", ret<0?"no":"yes");
296 add_trace("conclusion", NULL, "no channel available during call-waiting");
300 add_trace("conclusion", NULL, "using channel %d", p_m_b_channel);
301 add_trace("connect", "channel", "%d", p_m_b_channel);
303 p_m_b_exclusive = 1; // we are done
305 /* activate channel given by remote */
306 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
310 /* if not first reply, we are done */
311 if (p_state != PORT_STATE_OUT_SETUP)
314 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
315 add_trace("channel", "request", "no-channel");
316 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
317 /* if first reply has no channel, we are done */
320 add_trace("conclusion", NULL, "no channel until connect");
325 /* we will see, if our received channel is available */
327 ret = seize_bchannel(channel, exclusive);
328 add_trace("channel", "available", ret<0?"no":"yes");
331 add_trace("conclusion", NULL, "replied channel not available");
335 add_trace("conclusion", NULL, "replied channel accepted");
336 add_trace("connect", "channel", "%d", p_m_b_channel);
338 p_m_b_exclusive = 1; // we are done
340 /* activate channel given by remote */
341 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
347 * NOTE: we send MT_RELEASE_COMPLETE to "REJECT" the channel
348 * in response to the setup reply
351 l3m = create_l3msg();
353 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
354 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
356 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
358 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
360 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
364 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
366 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
368 new_state(PORT_STATE_RELEASE);
370 return(-34); /* to epoint: no channel available */
375 * hunt bchannel for incoming setup or retrieve or resume
377 int Pdss1::hunt_bchannel(int channel, int exclusive)
379 struct select_channel *selchannel;
380 struct interface_port *ifport = p_m_mISDNport->ifport;
383 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (setup)", DIRECTION_NONE);
386 if (channel == CHANNEL_NO)
387 add_trace("channel", "request", "no-channel");
389 add_trace("channel", "request", (channel>0)?"%d%s":"any", channel, exclusive?" (forced)":"");
390 if (channel==CHANNEL_NO && p_type==PORT_TYPE_DSS1_TE_IN)
392 add_trace("conclusion", NULL, "incoming call-waiting not supported for TE-mode");
394 return(-6); // channel unacceptable
396 if (channel <= 0) /* not given, no channel, whatever.. */
397 channel = CHANNEL_ANY; /* any channel */
398 add_trace("channel", "reserved", "%d", p_m_mISDNport->b_reserved);
399 if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num) // of out chan..
401 add_trace("conclusion", NULL, "all channels are reserved");
403 return(-34); // no channel
405 if (channel == CHANNEL_ANY)
409 /* check for given channel in selection list */
410 selchannel = ifport->in_channel;
413 if (selchannel->channel == channel || selchannel->channel == CHANNEL_FREE)
415 selchannel = selchannel->next;
420 /* exclusive channel requests must be in the list */
425 add_trace("conclusion", NULL, "exclusively requested channel not in list");
427 return(-6); // channel unacceptable
429 i = selchannel->channel-1-(selchannel->channel>=17);
430 if (p_m_mISDNport->b_port[i] == NULL)
432 add_trace("conclusion", NULL, "exclusively requested channel is busy");
434 return(-6); // channel unacceptable
437 /* requested channels in list will be used */
440 i = selchannel->channel-1-(selchannel->channel>=17);
441 if (p_m_mISDNport->b_port[i] == NULL)
445 /* if channel is not available or not in list, it must be searched */
447 /* check for first free channel in list */
449 selchannel = ifport->in_channel;
452 switch(selchannel->channel)
454 case CHANNEL_FREE: /* free channel */
455 add_trace("hunting", "channel", "free");
456 if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num)
457 break; /* all channel in use or reserverd */
460 while(i < p_m_mISDNport->b_num)
462 if (p_m_mISDNport->b_port[i] == NULL)
464 channel = i+1+(i>=15);
472 add_trace("hunting", "channel", "%d", selchannel->channel);
473 if (selchannel->channel<1 || selchannel->channel==16)
474 break; /* invalid channels */
475 i = selchannel->channel-1-(selchannel->channel>=17);
476 if (i >= p_m_mISDNport->b_num)
477 break; /* channel not in port */
478 if (p_m_mISDNport->b_port[i] == NULL)
480 channel = selchannel->channel;
486 break; /* found channel */
487 selchannel = selchannel->next;
491 add_trace("conclusion", NULL, "no channel available");
493 return(-6); // channel unacceptable
497 add_trace("conclusion", NULL, "channel available");
498 add_trace("connect", "channel", "%d", channel);
504 * handles all indications
506 /* CC_SETUP INDICATION */
508 void Pdss1::setup_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
511 void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
513 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
515 SETUP_t *setup = (SETUP_t *)((unsigned long)data + headerlen);
517 int calling_type, calling_plan, calling_present, calling_screen;
518 int called_type, called_plan;
519 int redir_type, redir_plan, redir_present, redir_screen, redir_reason;
520 int hlc_coding, hlc_presentation, hlc_interpretation, hlc_hlc, hlc_exthlc;
521 int bearer_coding, bearer_capability, bearer_mode, bearer_rate, bearer_multi, bearer_user;
522 int exclusive, channel;
524 unsigned char keypad[32] = "";
525 unsigned char useruser[128];
526 int useruser_len = 0, useruser_protocol;
527 class Endpoint *epoint;
528 struct message *message;
531 /* process given callref */
532 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_IND, DIRECTION_IN);
533 add_trace("callref", "new", "0x%x", pid);
536 /* release is case the ID is already in use */
537 add_trace("error", NULL, "callref already in use");
539 l3m = create_l3msg();
540 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
541 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47);
542 add_trace("reason", NULL, "callref already in use");
544 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, pid, l3m);
545 new_state(PORT_STATE_RELEASE);
551 // soll die ces wirklich von der pid abgeleitet werden oder kommt da noch ein "l3m->ces" ?
552 p_m_d_ces = pid >> 16;
555 /* callref from nt-lib */
558 /* nt-library now gives us the id via CC_SETUP */
559 if (dinfo&(~0xff) == 0xff00)
560 FATAL("l3-stack gives us a process id 0xff00-0xffff\n");
561 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_CR_IND, DIRECTION_IN);
563 add_trace("callref", "old", "0x%x", p_m_d_l3id);
564 add_trace("callref", "new", "0x%x", dinfo);
566 if (p_m_d_l3id&(~0xff) == 0xff00)
567 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
569 p_m_d_ces = setup->ces;
573 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_IND, DIRECTION_IN);
575 dec_ie_calling_pn(l3m, &calling_type, &calling_plan, &calling_present, &calling_screen, (unsigned char *)p_callerinfo.id, sizeof(p_callerinfo.id));
576 dec_ie_called_pn(l3m, &called_type, &called_plan, (unsigned char *)p_dialinginfo.id, sizeof(p_dialinginfo.id));
577 dec_ie_keypad(l3m, (unsigned char *)keypad, sizeof(keypad));
578 /* te-mode: CNIP (calling name identification presentation) */
580 dec_facility_centrex(l3m, (unsigned char *)p_callerinfo.name, sizeof(p_callerinfo.name));
581 dec_ie_useruser(l3m, &useruser_protocol, useruser, &useruser_len);
582 dec_ie_complete(l3m, &p_dialinginfo.sending_complete);
583 dec_ie_redir_nr(l3m, &redir_type, &redir_plan, &redir_present, &redir_screen, &redir_reason, (unsigned char *)p_redirinfo.id, sizeof(p_redirinfo.id));
584 dec_ie_channel_id(l3m, &exclusive, &channel);
585 dec_ie_hlc(l3m, &hlc_coding, &hlc_interpretation, &hlc_presentation, &hlc_hlc, &hlc_exthlc);
586 dec_ie_bearer(l3m, &bearer_coding, &bearer_capability, &bearer_mode, &bearer_rate, &bearer_multi, &bearer_user);
588 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));
589 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));
590 dec_ie_keypad(setup->KEYPAD, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)keypad, sizeof(keypad));
591 /* te-mode: CNIP (calling name identification presentation) */
593 dec_facility_centrex(setup->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)p_callerinfo.name, sizeof(p_callerinfo.name));
594 dec_ie_useruser(setup->USER_USER, (Q931_info_t *)((unsigned long)data+headerlen), &useruser_protocol, useruser, &useruser_len);
595 dec_ie_complete(setup->COMPLETE, (Q931_info_t *)((unsigned long)data+headerlen), &p_dialinginfo.sending_complete);
596 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));
597 dec_ie_channel_id(setup->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
598 dec_ie_hlc(setup->HLC, (Q931_info_t *)((unsigned long)data+headerlen), &hlc_coding, &hlc_interpretation, &hlc_presentation, &hlc_hlc, &hlc_exthlc);
599 dec_ie_bearer(setup->BEARER, (Q931_info_t *)((unsigned long)data+headerlen), &bearer_coding, &bearer_capability, &bearer_mode, &bearer_rate, &bearer_multi, &bearer_user);
603 /* if blocked, release call with MT_RELEASE_COMPLETE */
604 if (p_m_mISDNport->ifport->block)
607 l3m = create_l3msg();
609 RELEASE_COMPLETE_t *release_complete;
610 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
611 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
613 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
615 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 27); /* temporary unavailable */
617 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 27); /* temporary unavailable */
619 add_trace("reason", NULL, "port blocked");
622 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
624 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
626 new_state(PORT_STATE_RELEASE);
632 switch (calling_present)
635 p_callerinfo.present = INFO_PRESENT_RESTRICTED;
638 p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
641 p_callerinfo.present = INFO_PRESENT_ALLOWED;
644 switch (calling_screen)
647 p_callerinfo.screen = INFO_SCREEN_USER;
650 p_callerinfo.screen = INFO_SCREEN_NETWORK;
653 switch (calling_type)
656 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
657 p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
658 p_callerinfo.screen = INFO_SCREEN_NETWORK;
661 p_callerinfo.ntype = INFO_NTYPE_INTERNATIONAL;
664 p_callerinfo.ntype = INFO_NTYPE_NATIONAL;
667 p_callerinfo.ntype = INFO_NTYPE_SUBSCRIBER;
670 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
673 p_callerinfo.isdn_port = p_m_portnum;
674 SCPY(p_callerinfo.interface, p_m_mISDNport->ifport->interface->name);
676 /* dialing information */
677 SCAT(p_dialinginfo.id, (char *)keypad);
681 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
684 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
687 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
690 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
695 switch (redir_present)
698 p_redirinfo.present = INFO_PRESENT_RESTRICTED;
701 p_redirinfo.present = INFO_PRESENT_NOTAVAIL;
704 p_redirinfo.present = INFO_PRESENT_ALLOWED;
707 switch (redir_screen)
710 p_redirinfo.screen = INFO_SCREEN_USER;
713 p_redirinfo.screen = INFO_SCREEN_NETWORK;
716 switch (redir_reason)
719 p_redirinfo.reason = INFO_REDIR_BUSY;
722 p_redirinfo.reason = INFO_REDIR_NORESPONSE;
725 p_redirinfo.reason = INFO_REDIR_UNCONDITIONAL;
728 p_redirinfo.reason = INFO_REDIR_CALLDEFLECT;
731 p_redirinfo.reason = INFO_REDIR_OUTOFORDER;
734 p_redirinfo.reason = INFO_REDIR_UNKNOWN;
740 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
741 p_redirinfo.present = INFO_PRESENT_NULL; /* not redirecting */
742 p_redirinfo.reason = INFO_REDIR_UNKNOWN;
745 p_redirinfo.ntype = INFO_NTYPE_INTERNATIONAL;
748 p_redirinfo.ntype = INFO_NTYPE_NATIONAL;
751 p_redirinfo.ntype = INFO_NTYPE_SUBSCRIBER;
754 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
757 p_redirinfo.isdn_port = p_m_portnum;
759 /* bearer capability */
760 switch (bearer_capability)
763 p_capainfo.bearer_capa = INFO_BC_AUDIO;
764 bearer_user = (options.law=='a')?3:2;
767 p_capainfo.bearer_capa = bearer_capability;
773 p_capainfo.bearer_mode = INFO_BMODE_PACKET;
776 p_capainfo.bearer_mode = INFO_BMODE_CIRCUIT;
782 p_capainfo.bearer_info1 = INFO_INFO1_NONE;
785 p_capainfo.bearer_info1 = bearer_user + 0x80;
793 p_capainfo.hlc = INFO_HLC_NONE;
796 p_capainfo.hlc = hlc_hlc + 0x80;
802 p_capainfo.exthlc = INFO_HLC_NONE;
805 p_capainfo.exthlc = hlc_exthlc + 0x80;
810 ret = channel = hunt_bchannel(channel, exclusive);
815 ret = seize_bchannel(channel, 1);
820 * NOTE: we send MT_RELEASE_COMPLETE to "REJECT" the channel
821 * in response to the setup
824 l3m = create_l3msg();
826 RELEASE_COMPLETE_t *release_complete;
827 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
828 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
830 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
832 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
834 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
838 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
840 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
842 new_state(PORT_STATE_RELEASE);
846 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
848 /* create endpoint */
850 FATAL("Incoming call but already got an endpoint.\n");
851 if (!(epoint = new Endpoint(p_serial, 0)))
852 FATAL("No memory for Endpoint instance\n");
853 if (!(epoint->ep_app = new DEFAULT_ENDPOINT_APP(epoint, 0))) //incoming
854 FATAL("No memory for Endpoint Application instance\n");
855 epointlist_new(epoint->ep_serial);
857 /* send setup message to endpoit */
858 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_SETUP);
859 message->param.setup.isdn_port = p_m_portnum;
860 message->param.setup.port_type = p_type;
861 message->param.setup.dtmf = !p_m_mISDNport->ifport->nodtmf;
862 memcpy(&message->param.setup.dialinginfo, &p_dialinginfo, sizeof(struct dialing_info));
863 memcpy(&message->param.setup.callerinfo, &p_callerinfo, sizeof(struct caller_info));
864 memcpy(&message->param.setup.redirinfo, &p_redirinfo, sizeof(struct redir_info));
865 memcpy(&message->param.setup.capainfo, &p_capainfo, sizeof(struct capa_info));
866 memcpy(message->param.setup.useruser.data, &useruser, useruser_len);
867 message->param.setup.useruser.len = useruser_len;
868 message->param.setup.useruser.protocol = useruser_protocol;
869 message_put(message);
871 new_state(PORT_STATE_IN_SETUP);
874 /* CC_INFORMATION INDICATION */
876 void Pdss1::information_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
879 void Pdss1::information_ind(unsigned long prim, unsigned long dinfo, void *data)
881 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
882 INFORMATION_t *information = (INFORMATION_t *)((unsigned long)data + headerlen);
885 unsigned char keypad[32] = "";
886 struct message *message;
888 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_IND, DIRECTION_IN);
890 dec_ie_called_pn(l3m, &type, &plan, (unsigned char *)p_dialinginfo.id, sizeof(p_dialinginfo.id));
891 dec_ie_keypad(l3m, (unsigned char *)keypad, sizeof(keypad));
892 dec_ie_complete(l3m, &p_dialinginfo.sending_complete);
894 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));
895 dec_ie_keypad(information->KEYPAD, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)keypad, sizeof(keypad));
896 dec_ie_complete(information->COMPLETE, (Q931_info_t *)((unsigned long)data+headerlen), &p_dialinginfo.sending_complete);
900 SCAT(p_dialinginfo.id, (char *)keypad);
904 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
907 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
910 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
913 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
916 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_INFORMATION);
917 memcpy(&message->param.information, &p_dialinginfo, sizeof(struct dialing_info));
918 message_put(message);
919 /* reset overlap timeout */
923 /* CC_SETUP_ACCNOWLEDGE INDICATION */
925 void Pdss1::setup_acknowledge_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
928 void Pdss1::setup_acknowledge_ind(unsigned long prim, unsigned long dinfo, void *data)
930 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
931 SETUP_ACKNOWLEDGE_t *setup_acknowledge = (SETUP_ACKNOWLEDGE_t *)((unsigned long)data + headerlen);
933 int exclusive, channel;
934 int coding, location, progress;
936 struct message *message;
938 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_ACKNOWLEDGE_IND, DIRECTION_IN);
940 dec_ie_channel_id(l3m, &exclusive, &channel);
941 dec_ie_progress(l3m, &coding, &location, &progress);
943 dec_ie_channel_id(setup_acknowledge->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
944 dec_ie_progress(setup_acknowledge->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
948 /* process channel */
950 ret = received_first_reply_to_setup(cmd, channel, exclusive);
952 ret = received_first_reply_to_setup(prim, channel, exclusive);
956 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
957 message->param.disconnectinfo.cause = -ret;
958 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
959 message_put(message);
960 new_state(PORT_STATE_RELEASE);
965 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_OVERLAP);
966 message_put(message);
968 new_state(PORT_STATE_OUT_OVERLAP);
971 /* CC_PROCEEDING INDICATION */
973 void Pdss1::proceeding_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
976 void Pdss1::proceeding_ind(unsigned long prim, unsigned long dinfo, void *data)
978 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
979 CALL_PROCEEDING_t *proceeding = (CALL_PROCEEDING_t *)((unsigned long)data + headerlen);
981 int exclusive, channel;
982 int coding, location, progress;
984 struct message *message;
985 int notify = -1, type, plan, present;
988 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_IND, DIRECTION_IN);
990 dec_ie_channel_id(l3m, &exclusive, &channel);
991 dec_ie_progress(l3m, &coding, &location, &progress);
992 dec_ie_notify(l3m, ¬ify);
993 dec_ie_redir_dn(l3m, &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
995 dec_ie_channel_id(proceeding->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
996 dec_ie_progress(proceeding->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
997 dec_ie_notify(NULL/*proceeding->NOTIFY*/, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
998 dec_ie_redir_dn(proceeding->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
1003 ret = received_first_reply_to_setup(cmd, channel, exclusive);
1005 ret = received_first_reply_to_setup(prim, channel, exclusive);
1009 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1010 message->param.disconnectinfo.cause = -ret;
1011 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1012 message_put(message);
1013 new_state(PORT_STATE_RELEASE);
1017 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROCEEDING);
1018 message_put(message);
1020 new_state(PORT_STATE_OUT_PROCEEDING);
1026 if (type >= 0 || notify)
1028 if (!notify && type >= 0)
1030 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1031 message->param.notifyinfo.notify = notify;
1032 SCPY(message->param.notifyinfo.id, redir);
1033 /* redirection number */
1037 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1040 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1043 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1049 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1050 message->param.notifyinfo.present = INFO_PRESENT_NULL;
1053 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1056 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1059 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1062 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1065 message->param.notifyinfo.isdn_port = p_m_portnum;
1066 message_put(message);
1070 /* CC_ALERTING INDICATION */
1072 void Pdss1::alerting_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1075 void Pdss1::alerting_ind(unsigned long prim, unsigned long dinfo, void *data)
1077 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1078 ALERTING_t *alerting = (ALERTING_t *)((unsigned long)data + headerlen);
1080 int exclusive, channel;
1081 int coding, location, progress;
1083 struct message *message;
1084 int notify = -1, type, plan, present;
1087 l1l2l3_trace_header(p_m_mISDNport, this, L3_ALERTING_IND, DIRECTION_IN);
1089 dec_ie_channel_id(l3m, &exclusive, &channel);
1090 dec_ie_progress(l3m, &coding, &location, &progress);
1091 dec_ie_notify(l3m, ¬ify);
1092 dec_ie_redir_dn(l3m, &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
1094 dec_ie_channel_id(alerting->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
1095 dec_ie_progress(alerting->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
1096 dec_ie_notify(NULL/*alerting->NOTIFY*/, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
1097 dec_ie_redir_dn(alerting->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
1101 /* process channel */
1103 ret = received_first_reply_to_setup(cmd, channel, exclusive);
1105 ret = received_first_reply_to_setup(prim, channel, exclusive);
1109 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1110 message->param.disconnectinfo.cause = -ret;
1111 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1112 message_put(message);
1113 new_state(PORT_STATE_RELEASE);
1117 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_ALERTING);
1118 message_put(message);
1120 new_state(PORT_STATE_OUT_ALERTING);
1126 if (type >= 0 || notify)
1128 if (!notify && type >= 0)
1130 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1131 message->param.notifyinfo.notify = notify;
1132 SCPY(message->param.notifyinfo.id, redir);
1136 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1139 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1142 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1148 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1149 message->param.notifyinfo.present = INFO_PRESENT_NULL;
1152 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1155 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1158 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1161 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1164 message->param.notifyinfo.isdn_port = p_m_portnum;
1165 message_put(message);
1169 /* CC_CONNECT INDICATION */
1171 void Pdss1::connect_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1174 void Pdss1::connect_ind(unsigned long prim, unsigned long dinfo, void *data)
1176 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1178 CONNECT_t *connect = (CONNECT_t *)((unsigned long)data + headerlen);
1179 CONNECT_ACKNOWLEDGE_t *connect_acknowledge;
1181 int exclusive, channel;
1182 int type, plan, present, screen;
1184 struct message *message;
1185 int bchannel_before;
1190 // p_m_d_ces = connect->ces;
1192 p_m_d_ces = connect->ces;
1195 l1l2l3_trace_header(p_m_mISDNport, this, L3_CONNECT_IND, DIRECTION_IN);
1197 dec_ie_channel_id(l3m, &exclusive, &channel);
1198 dec_ie_connected_pn(l3m, &type, &plan, &present, &screen, (unsigned char *)p_connectinfo.id, sizeof(p_connectinfo.id));
1199 /* te-mode: CONP (connected name identification presentation) */
1201 dec_facility_centrex(l3m, (unsigned char *)p_connectinfo.name, sizeof(p_connectinfo.name));
1203 dec_ie_channel_id(connect->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
1204 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));
1205 /* te-mode: CONP (connected name identification presentation) */
1207 dec_facility_centrex(connect->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)p_connectinfo.name, sizeof(p_connectinfo.name));
1211 /* select channel */
1212 bchannel_before = p_m_b_channel;
1214 ret = received_first_reply_to_setup(cmd, channel, exclusive);
1216 ret = received_first_reply_to_setup(prim, channel, exclusive);
1220 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1221 message->param.disconnectinfo.cause = -ret;
1222 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1223 message_put(message);
1224 new_state(PORT_STATE_RELEASE);
1229 /* connect information */
1233 p_connectinfo.present = INFO_PRESENT_RESTRICTED;
1236 p_connectinfo.present = INFO_PRESENT_NOTAVAIL;
1239 p_connectinfo.present = INFO_PRESENT_ALLOWED;
1245 p_connectinfo.screen = INFO_SCREEN_USER;
1248 p_connectinfo.screen = INFO_SCREEN_NETWORK;
1254 p_connectinfo.present = INFO_PRESENT_NULL; /* no COLP info */
1255 p_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1258 p_connectinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1261 p_connectinfo.ntype = INFO_NTYPE_NATIONAL;
1264 p_connectinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1267 p_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1270 p_connectinfo.isdn_port = p_m_portnum;
1271 SCPY(p_connectinfo.interface, p_m_mISDNport->ifport->interface->name);
1273 /* only in nt-mode we send connect ack. in te-mode it is done by stack itself or optional */
1276 /* send connect acknowledge */
1278 l3m = create_l3msg();
1280 dmsg = create_l3msg(CC_CONNECT | RESPONSE, MT_CONNECT, dinfo, sizeof(CONNECT_ACKNOWLEDGE_t), p_m_d_ntmode);
1281 connect_acknowledge = (CONNECT_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1283 l1l2l3_trace_header(p_m_mISDNport, this, L3_CONNECT_RES, DIRECTION_OUT);
1284 /* if we had no bchannel before, we send it now */
1285 if (!bchannel_before && p_m_b_channel)
1287 enc_ie_channel_id(l3m, 1, p_m_b_channel);
1289 enc_ie_channel_id(&connect_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
1293 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CONNECT, p_m_d_l3id, l3m);
1295 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1299 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CONNECT);
1300 memcpy(&message->param.connectinfo, &p_connectinfo, sizeof(struct connect_info));
1301 message_put(message);
1303 new_state(PORT_STATE_CONNECT);
1306 /* CC_DISCONNECT INDICATION */
1308 void Pdss1::disconnect_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1311 void Pdss1::disconnect_ind(unsigned long prim, unsigned long dinfo, void *data)
1313 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1314 DISCONNECT_t *disconnect = (DISCONNECT_t *)((unsigned long)data + headerlen);
1316 int location, cause;
1317 int coding, proglocation, progress;
1318 struct message *message;
1320 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_IND, DIRECTION_IN);
1322 dec_ie_progress(l3m, &coding, &proglocation, &progress);
1323 dec_ie_cause(l3m, &location, &cause);
1325 dec_ie_progress(disconnect->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &proglocation, &progress);
1326 dec_ie_cause(disconnect->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1329 if (location == LOCATION_PRIVATE_LOCAL)
1330 location = LOCATION_PRIVATE_REMOTE;
1335 /* release if remote sends us no tones */
1336 if (!p_m_mISDNport->earlyb)
1346 l3m = create_l3msg();
1348 dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, dinfo, sizeof(RELEASE_t), p_m_d_ntmode);
1349 release = (RELEASE_t *)(dmsg->data + headerlen);
1351 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_REQ, DIRECTION_OUT);
1353 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16); /* normal */
1355 enc_ie_cause(&release->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16); /* normal */
1357 add_trace("reason", NULL, "no remote patterns");
1360 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE, p_m_d_l3id, l3m);
1362 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1365 /* sending release to endpoint */
1368 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1369 message->param.disconnectinfo.cause = cause;
1370 message->param.disconnectinfo.location = location;
1371 message_put(message);
1373 free_epointlist(p_epointlist);
1375 new_state(PORT_STATE_RELEASE);
1380 /* sending disconnect to active endpoint and release to inactive endpoints */
1381 if (ACTIVE_EPOINT(p_epointlist))
1383 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DISCONNECT);
1384 message->param.disconnectinfo.location = location;
1385 message->param.disconnectinfo.cause = cause;
1386 message_put(message);
1388 while(INACTIVE_EPOINT(p_epointlist))
1390 message = message_create(p_serial, INACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1391 message->param.disconnectinfo.location = location;
1392 message->param.disconnectinfo.cause = cause;
1393 message_put(message);
1395 free_epointid(INACTIVE_EPOINT(p_epointlist));
1397 new_state(PORT_STATE_IN_DISCONNECT);
1400 /* CC_DISCONNECT INDICATION */
1402 void Pdss1::disconnect_ind_i(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1405 void Pdss1::disconnect_ind_i(unsigned long prim, unsigned long dinfo, void *data)
1407 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1408 DISCONNECT_t *disconnect = (DISCONNECT_t *)((unsigned long)data + headerlen);
1410 int location, cause;
1413 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_IND, DIRECTION_IN);
1414 if (p_m_d_collect_cause > 0)
1416 add_trace("old-cause", "location", "%d", p_m_d_collect_location);
1417 add_trace("old-cause", "value", "%d", p_m_d_collect_cause);
1420 dec_ie_cause(l3m, &location, &cause);
1422 dec_ie_cause(disconnect->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1424 if (location == LOCATION_PRIVATE_LOCAL)
1425 location = LOCATION_PRIVATE_REMOTE;
1428 collect_cause(&p_m_d_collect_cause, &p_m_d_collect_location, cause, location);
1429 add_trace("new-cause", "location", "%d", p_m_d_collect_location);
1430 add_trace("new-cause", "value", "%d", p_m_d_collect_cause);
1435 /* CC_RELEASE INDICATION */
1437 void Pdss1::release_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1440 void Pdss1::release_ind(unsigned long prim, unsigned long dinfo, void *data)
1442 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1444 RELEASE_t *release = (RELEASE_t *)((unsigned long)data + headerlen);
1446 int location, cause;
1447 struct message *message;
1449 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_IND, DIRECTION_IN);
1451 dec_ie_cause(l3m, &location, &cause);
1453 dec_ie_cause(release->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1456 if (location == LOCATION_PRIVATE_LOCAL)
1457 location = LOCATION_PRIVATE_REMOTE;
1462 /* sending release to endpoint */
1465 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1466 message->param.disconnectinfo.cause = cause;
1467 message->param.disconnectinfo.location = location;
1468 message_put(message);
1470 free_epointlist(p_epointlist);
1473 /* only in NT mode we must send release_complete, if we got a release confirm */
1475 if (cmd == MT_RELEASE)
1477 if (prim == (CC_RELEASE | CONFIRM))
1480 /* sending release complete */
1482 l3m = create_l3msg();
1484 RELEASE_COMPLETE_t *release_complete;
1485 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
1486 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
1488 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
1490 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16);
1492 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16);
1496 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
1498 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1502 new_state(PORT_STATE_RELEASE);
1506 /* CC_RELEASE_COMPLETE INDICATION (a reject) */
1508 void Pdss1::release_complete_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1511 void Pdss1::release_complete_ind(unsigned long prim, unsigned long dinfo, void *data)
1513 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1514 RELEASE_COMPLETE_t *release_complete = (RELEASE_COMPLETE_t *)((unsigned long)data + headerlen);
1516 int location, cause;
1517 struct message *message;
1519 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_IND, DIRECTION_IN);
1521 dec_ie_cause(l3m, &location, &cause);
1523 dec_ie_cause(release_complete->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1526 if (location == LOCATION_PRIVATE_LOCAL)
1527 location = LOCATION_PRIVATE_REMOTE;
1532 /* sending release to endpoint */
1535 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1536 message->param.disconnectinfo.cause = cause;
1537 message->param.disconnectinfo.location = location;
1538 message_put(message);
1540 free_epointlist(p_epointlist);
1543 new_state(PORT_STATE_RELEASE);
1549 void Pdss1::t312_timeout_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1552 void Pdss1::t312_timeout_ind(unsigned long prim, unsigned long dinfo, void *data)
1555 struct message *message;
1557 // trace is done at message_isdn()
1559 /* sending release to endpoint */
1562 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1563 if (p_m_d_collect_cause)
1565 message->param.disconnectinfo.cause = p_m_d_collect_cause;
1566 message->param.disconnectinfo.location = p_m_d_collect_location;
1569 message->param.disconnectinfo.cause = CAUSE_NOUSER;
1570 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1572 message_put(message);
1574 free_epointlist(p_epointlist);
1577 new_state(PORT_STATE_RELEASE);
1581 /* CC_NOTIFY INDICATION */
1583 void Pdss1::notify_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1586 void Pdss1::notify_ind(unsigned long prim, unsigned long dinfo, void *data)
1588 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1589 NOTIFY_t *notifying = (NOTIFY_t *)((unsigned long)data + headerlen);
1591 struct message *message;
1592 int notify, type, plan, present;
1593 unsigned char notifyid[sizeof(message->param.notifyinfo.id)];
1595 l1l2l3_trace_header(p_m_mISDNport, this, L3_NOTIFY_IND, DIRECTION_IN);
1597 dec_ie_notify(l3m, ¬ify);
1598 dec_ie_redir_dn(l3m, &type, &plan, &present, notifyid, sizeof(notifyid));
1600 dec_ie_notify(notifying->NOTIFY, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
1601 dec_ie_redir_dn(notifying->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, notifyid, sizeof(notifyid));
1605 if (!ACTIVE_EPOINT(p_epointlist))
1607 /* notification indicator */
1611 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1612 message->param.notifyinfo.notify = notify;
1613 SCPY(message->param.notifyinfo.id, (char *)notifyid);
1614 /* redirection number */
1618 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1621 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1624 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1630 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1631 message->param.notifyinfo.present = INFO_PRESENT_NULL;
1634 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1637 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1640 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1643 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1646 message->param.notifyinfo.isdn_port = p_m_portnum;
1647 message_put(message);
1651 /* CC_HOLD INDICATION */
1652 struct message *message;
1654 void Pdss1::hold_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1657 void Pdss1::hold_ind(unsigned long prim, unsigned long dinfo, void *data)
1659 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1661 // HOLD_t *hold = (HOLD_t *)((unsigned long)data + headerlen);
1662 HOLD_REJECT_t *hold_reject;
1663 HOLD_ACKNOWLEDGE_t *hold_acknowledge;
1665 // class Endpoint *epoint;
1667 l1l2l3_trace_header(p_m_mISDNport, this, L3_HOLD_IND, DIRECTION_IN);
1670 if (!ACTIVE_EPOINT(p_epointlist) || p_m_hold)
1673 l3m = create_l3msg();
1675 dmsg = create_l3msg(CC_HOLD_REJECT | REQUEST, MT_HOLD_REJECT, dinfo, sizeof(HOLD_REJECT_t), p_m_d_ntmode);
1676 hold_reject = (HOLD_REJECT_t *)(dmsg->data + headerlen);
1678 l1l2l3_trace_header(p_m_mISDNport, this, L3_HOLD_REJECT_REQ, DIRECTION_OUT);
1680 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, p_m_hold?101:31); /* normal unspecified / incompatible state */
1682 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 */
1684 add_trace("reason", NULL, "no endpoint");
1687 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_HOLD_REJECT, p_m_d_l3id, l3m);
1689 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1695 /* notify the hold of call */
1696 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1697 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_HOLD;
1698 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1699 message_put(message);
1701 /* deactivate bchannel */
1702 chan_trace_header(p_m_mISDNport, this, "CHANNEL RELEASE (hold)", DIRECTION_NONE);
1703 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1707 /* set hold state */
1710 epoint = find_epoint_id(ACTIVE_EPOINT(p_epointlist));
1711 if (epoint && p_m_d_ntmode)
1713 p_m_timeout = p_settings.tout_hold;
1718 /* acknowledge hold */
1720 l3m = create_l3msg();
1722 dmsg = create_l3msg(CC_HOLD_ACKNOWLEDGE | REQUEST, MT_HOLD_ACKNOWLEDGE, dinfo, sizeof(HOLD_ACKNOWLEDGE_t), p_m_d_ntmode);
1723 hold_acknowledge = (HOLD_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1725 l1l2l3_trace_header(p_m_mISDNport, this, L3_HOLD_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1728 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_HOLD_ACKNOWLEDGE, p_m_d_l3id, l3m);
1730 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1735 /* CC_RETRIEVE INDICATION */
1737 void Pdss1::retrieve_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1740 void Pdss1::retrieve_ind(unsigned long prim, unsigned long dinfo, void *data)
1742 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1744 RETRIEVE_t *retrieve = (RETRIEVE_t *)((unsigned long)data + headerlen);
1745 RETRIEVE_REJECT_t *retrieve_reject;
1746 RETRIEVE_ACKNOWLEDGE_t *retrieve_acknowledge;
1748 struct message *message;
1749 int channel, exclusive, cause;
1752 l1l2l3_trace_header(p_m_mISDNport, this, L3_RETRIEVE_IND, DIRECTION_IN);
1754 dec_ie_channel_id(l3m, &exclusive, &channel);
1756 dec_ie_channel_id(retrieve->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
1762 cause = 101; /* incompatible state */
1766 l3m = create_l3msg();
1768 dmsg = create_l3msg(CC_RETRIEVE_REJECT | REQUEST, MT_RETRIEVE_REJECT, dinfo, sizeof(RETRIEVE_REJECT_t), p_m_d_ntmode);
1769 retrieve_reject = (RETRIEVE_REJECT_t *)(dmsg->data + headerlen);
1771 l1l2l3_trace_header(p_m_mISDNport, this, L3_RETRIEVE_REJECT_REQ, DIRECTION_OUT);
1773 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, cause);
1775 enc_ie_cause(&retrieve_reject->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, cause);
1779 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RETRIEVE_REJECT, p_m_d_l3id, l3m);
1781 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1787 /* notify the retrieve of call */
1788 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1789 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_RETRIEVAL;
1790 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1791 message_put(message);
1794 ret = channel = hunt_bchannel(channel, exclusive);
1799 ret = seize_bchannel(channel, 1);
1806 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
1808 /* set hold state */
1812 /* acknowledge retrieve */
1814 l3m = create_l3msg();
1816 dmsg = create_l3msg(CC_RETRIEVE_ACKNOWLEDGE | REQUEST, MT_RETRIEVE_ACKNOWLEDGE, dinfo, sizeof(RETRIEVE_ACKNOWLEDGE_t), p_m_d_ntmode);
1817 retrieve_acknowledge = (RETRIEVE_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1819 l1l2l3_trace_header(p_m_mISDNport, this, L3_RETRIEVE_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1821 enc_ie_channel_id(l3m, 1, p_m_b_channel);
1823 enc_ie_channel_id(&retrieve_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
1827 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RETRIEVE_ACKNOWLEDGE, p_m_d_l3id, l3m);
1829 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1833 /* CC_SUSPEND INDICATION */
1835 void Pdss1::suspend_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1838 void Pdss1::suspend_ind(unsigned long prim, unsigned long dinfo, void *data)
1840 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1842 SUSPEND_t *suspend = (SUSPEND_t *)((unsigned long)data + headerlen);
1843 SUSPEND_ACKNOWLEDGE_t *suspend_acknowledge;
1844 SUSPEND_REJECT_t *suspend_reject;
1846 struct message *message;
1847 class Endpoint *epoint;
1848 unsigned char callid[8];
1850 int ret = -31; /* normal, unspecified */
1852 l1l2l3_trace_header(p_m_mISDNport, this, L3_SUSPEND_IND, DIRECTION_IN);
1854 dec_ie_call_id(l3m, callid, &len);
1856 dec_ie_call_id(suspend->CALL_ID, (Q931_info_t *)((unsigned long)data+headerlen), callid, &len);
1860 if (!ACTIVE_EPOINT(p_epointlist))
1864 l3m = create_l3msg();
1866 dmsg = create_l3msg(CC_SUSPEND_REJECT | REQUEST, MT_SUSPEND_REJECT, dinfo, sizeof(SUSPEND_REJECT_t), p_m_d_ntmode);
1867 suspend_reject = (SUSPEND_REJECT_t *)(dmsg->data + headerlen);
1869 l1l2l3_trace_header(p_m_mISDNport, this, L3_SUSPEND_REJECT_REQ, DIRECTION_OUT);
1871 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1873 enc_ie_cause(&suspend_reject->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1877 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SUSPEND_REJECT, p_m_d_l3id, l3m);
1879 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1888 /* check if call id is in use */
1889 epoint = epoint_first;
1892 if (epoint->ep_park)
1894 if (epoint->ep_park_len == len)
1895 if (!memcmp(epoint->ep_park_callid, callid, len))
1897 ret = -84; /* call id in use */
1901 epoint = epoint->next;
1904 /* notify the hold of call */
1905 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1906 message->param.notifyinfo.notify = INFO_NOTIFY_USER_SUSPENDED;
1907 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1908 message_put(message);
1910 /* deactivate bchannel */
1911 chan_trace_header(p_m_mISDNport, this, "CHANNEL RELEASE (suspend)", DIRECTION_NONE);
1912 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1916 /* sending suspend to endpoint */
1917 while (p_epointlist)
1919 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_SUSPEND);
1920 memcpy(message->param.parkinfo.callid, callid, sizeof(message->param.parkinfo.callid));
1921 message->param.parkinfo.len = len;
1922 message_put(message);
1924 free_epointlist(p_epointlist);
1927 /* sending SUSPEND_ACKNOWLEDGE */
1929 l3m = create_l3msg();
1931 dmsg = create_l3msg(CC_SUSPEND_ACKNOWLEDGE | REQUEST, MT_SUSPEND_ACKNOWLEDGE, dinfo, sizeof(SUSPEND_ACKNOWLEDGE_t), p_m_d_ntmode);
1932 suspend_acknowledge = (SUSPEND_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1934 l1l2l3_trace_header(p_m_mISDNport, this, L3_SUSPEND_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1937 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SUSPEND_ACKNOWLEDGE, p_m_d_l3id, l3m);
1939 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1942 new_state(PORT_STATE_RELEASE);
1946 /* CC_RESUME INDICATION */
1948 void Pdss1::resume_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1951 void Pdss1::resume_ind(unsigned long prim, unsigned long dinfo, void *data)
1953 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1955 RESUME_t *resume = (RESUME_t *)((unsigned long)data + headerlen);
1956 RESUME_REJECT_t *resume_reject;
1957 RESUME_ACKNOWLEDGE_t *resume_acknowledge;
1959 unsigned char callid[8];
1961 int channel, exclusive;
1962 class Endpoint *epoint;
1963 struct message *message;
1967 /* process given callref */
1968 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_IND, DIRECTION_IN);
1969 add_trace("callref", "new", "0x%x", pid);
1972 /* release is case the ID is already in use */
1973 add_trace("error", NULL, "callref already in use");
1975 l3m = create_l3msg();
1976 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_REJECT_REQ, DIRECTION_OUT);
1977 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47);
1978 add_trace("reason", NULL, "callref already in use");
1980 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RESUME_REJECT, pid, l3m);
1981 new_state(PORT_STATE_RELEASE);
1986 p_m_d_ces = pid >> 16;
1989 /* callref from nt-lib */
1992 /* nt-library now gives us the id via CC_RESUME */
1993 if (dinfo&(~0xff) == 0xff00)
1994 FATAL("l3-stack gives us a process id 0xff00-0xffff\n");
1995 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_CR_IND, DIRECTION_IN);
1997 add_trace("callref", "old", "0x%x", p_m_d_l3id);
1998 add_trace("callref", "new", "0x%x", dinfo);
2000 if (p_m_d_l3id&(~0xff) == 0xff00)
2001 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
2003 p_m_d_ces = resume->ces;
2007 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_IND, DIRECTION_IN);
2009 dec_ie_call_id(l3m, callid, &len);
2011 dec_ie_call_id(resume->CALL_ID, (Q931_info_t *)((unsigned long)data+headerlen), callid, &len);
2015 /* if blocked, release call */
2016 if (p_m_mISDNport->ifport->block)
2025 /* channel_id (no channel is possible in message) */
2027 channel = -1; /* any channel */
2030 ret = channel = hunt_bchannel(channel, exclusive);
2035 ret = seize_bchannel(channel, 1);
2041 l3m = create_l3msg();
2043 dmsg = create_l3msg(CC_RESUME_REJECT | REQUEST, MT_RESUME_REJECT, dinfo, sizeof(RESUME_REJECT_t), p_m_d_ntmode);
2044 resume_reject = (RESUME_REJECT_t *)(dmsg->data + headerlen);
2046 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_REJECT_REQ, DIRECTION_OUT);
2048 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
2050 enc_ie_cause(&resume_reject->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
2053 add_trace("reason", NULL, "port blocked");
2056 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RESUME_REJECT, p_m_d_l3id, l3m);
2058 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2060 new_state(PORT_STATE_RELEASE);
2064 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
2066 /* create endpoint */
2068 FATAL("Incoming resume but already got an endpoint.\n");
2069 ret = -85; /* no call suspended */
2070 epoint = epoint_first;
2073 if (epoint->ep_park)
2075 ret = -83; /* suspended call exists, but this not */
2076 if (epoint->ep_park_len == len)
2077 if (!memcmp(epoint->ep_park_callid, callid, len))
2080 epoint = epoint->next;
2085 epointlist_new(epoint->ep_serial);
2086 if (!(epoint->portlist_new(p_serial, p_type, p_m_mISDNport->earlyb)))
2087 FATAL("No memory for portlist\n");
2088 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RESUME);
2089 message_put(message);
2091 /* notify the resume of call */
2092 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
2093 message->param.notifyinfo.notify = INFO_NOTIFY_USER_RESUMED;
2094 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
2095 message_put(message);
2097 /* sending RESUME_ACKNOWLEDGE */
2099 l3m = create_l3msg();
2101 dmsg = create_l3msg(CC_RESUME_ACKNOWLEDGE | REQUEST, MT_RESUME_ACKNOWLEDGE, dinfo, sizeof(RESUME_ACKNOWLEDGE_t), p_m_d_ntmode);
2102 resume_acknowledge = (RESUME_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
2104 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_ACKNOWLEDGE_REQ, DIRECTION_OUT);
2106 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2108 enc_ie_channel_id(&resume_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2112 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RESUME_ACKNOWLEDGE, p_m_d_l3id, l3m);
2114 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2117 new_state(PORT_STATE_CONNECT);
2121 /* CC_FACILITY INDICATION */
2123 void Pdss1::facility_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
2126 void Pdss1::facility_ind(unsigned long prim, unsigned long dinfo, void *data)
2128 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2129 FACILITY_t *facility = (FACILITY_t *)((unsigned long)data + headerlen);
2131 unsigned char facil[256];
2133 struct message *message;
2135 l1l2l3_trace_header(p_m_mISDNport, this, L3_FACILITY_IND, DIRECTION_IN);
2137 dec_ie_facility(l3m, facil, &facil_len);
2139 dec_ie_facility(facility->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), facil, &facil_len);
2147 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_FACILITY);
2148 message->param.facilityinfo.len = facil_len;
2149 memcpy(message->param.facilityinfo.data, facil, facil_len);
2150 message_put(message);
2155 * handler for isdn connections
2156 * incoming information are parsed and sent via message to the endpoint
2159 void Pdss1::message_isdn(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
2167 // if (p_m_d_ntmode)
2168 // timer_hex = *((int *)(((char *)data)/*+headerlen*/));
2169 if (timer_hex==0x312)
2171 l1l2l3_trace_header(p_m_mISDNport, this, L3_TIMEOUT_IND, DIRECTION_IN);
2172 add_trace("timer", NULL, "%x", timer_hex);
2174 t312_timeout_ind(cmd, pid, l3m);
2179 if (p_state != PORT_STATE_IDLE)
2181 setup_ind(cmd, pid, l3m);
2184 case MT_INFORMATION:
2185 information_ind(cmd, pid, l3m);
2188 case MT_SETUP_ACKNOWLEDGE:
2189 if (p_state != PORT_STATE_OUT_SETUP)
2191 PERROR("Pdss1(%s) received setup_acknowledge, but we are not in outgoing setup state, IGNORING.\n", p_name);
2194 setup_acknowledge_ind(cmd, pid, l3m);
2197 case MT_CALL_PROCEEDING:
2198 if (p_state != PORT_STATE_OUT_SETUP
2199 && p_state != PORT_STATE_OUT_OVERLAP)
2201 PERROR("Pdss1(%s) received proceeding, but we are not in outgoing setup OR overlap state, IGNORING.\n", p_name);
2204 proceeding_ind(cmd, pid, l3m);
2208 if (p_state != PORT_STATE_OUT_SETUP
2209 && p_state != PORT_STATE_OUT_OVERLAP
2210 && p_state != PORT_STATE_OUT_PROCEEDING)
2212 PERROR("Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding state, IGNORING.\n", p_name);
2215 alerting_ind(cmd, pid, l3m);
2219 if (p_state != PORT_STATE_OUT_SETUP
2220 && p_state != PORT_STATE_OUT_OVERLAP
2221 && p_state != PORT_STATE_OUT_PROCEEDING
2222 && p_state != PORT_STATE_OUT_ALERTING)
2224 PERROR("Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding OR ALERTING state, IGNORING.\n", p_name);
2227 connect_ind(cmd, pid, l3m);
2228 if (p_m_d_notify_pending)
2230 /* send pending notify message during connect */
2231 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2232 message_free(p_m_d_notify_pending);
2233 p_m_d_notify_pending = NULL;
2237 case MT_CONNECT_ACKNOWLEDGE:
2238 if (p_state == PORT_STATE_CONNECT_WAITING)
2239 new_state(PORT_STATE_CONNECT);
2240 if (p_m_d_notify_pending)
2242 /* send pending notify message during connect-ack */
2243 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2244 message_free(p_m_d_notify_pending);
2245 p_m_d_notify_pending = NULL;
2250 disconnect_ind(cmd, pid, l3m);
2254 release_ind(cmd, pid, l3m);
2257 case MT_RELEASE_COMPLETE:
2258 release_complete_ind(cmd, pid, l3m);
2262 notify_ind(cmd, pid, l3m);
2266 hold_ind(cmd, pid, l3m);
2270 retrieve_ind(cmd, pid, l3m);
2274 suspend_ind(cmd, pid, l3m);
2278 resume_ind(cmd, pid, l3m);
2282 facility_ind(cmd, pid, l3m);
2286 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_L3ID_IND, DIRECTION_IN);
2287 add_trace("callref", NULL, "0x%x", p_m_d_l3id);
2292 //#warning remove me
2293 //PDEBUG(DEBUG_LOG, "JOLLY release cr %d\n", p_serial);
2294 /* sending release to endpoint in case we still have an endpoint
2295 * this is because we don't get any response if a release_complete is received (or a release in release state)
2299 struct message *message;
2300 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
2301 message->param.disconnectinfo.cause = (p_m_d_collect_cause!=CAUSE_NOUSER)?p_m_d_collect_cause:CAUSE_UNSPECIFIED;
2302 message->param.disconnectinfo.location = (p_m_d_collect_cause!=CAUSE_NOUSER)?p_m_d_collect_location:LOCATION_PRIVATE_LOCAL;
2303 message_put(message);
2305 free_epointlist(p_epointlist);
2307 new_state(PORT_STATE_RELEASE);
2312 l1l2l3_trace_header(p_m_mISDNport, this, L3_UNKNOWN, DIRECTION_IN);
2313 add_trace("unhandled", "cmd", "0x%x", cmd);
2318 void Pdss1::message_isdn(unsigned long prim, unsigned long dinfo, void *data)
2325 case CC_TIMEOUT | INDICATION:
2328 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2329 timer_hex = *((int *)(((char *)data)+headerlen));
2331 if (timer_hex==0x312 && p_m_d_ntmode)
2333 l1l2l3_trace_header(p_m_mISDNport, this, L3_TIMEOUT_IND, DIRECTION_IN);
2334 add_trace("timer", NULL, "%x", timer_hex);
2336 t312_timeout_ind(prim, dinfo, data);
2340 case CC_SETUP | INDICATION:
2341 if (p_state != PORT_STATE_IDLE)
2343 setup_ind(prim, dinfo, data);
2346 case CC_SETUP | CONFIRM:
2349 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_CR_IND, DIRECTION_IN);
2350 add_trace("callref", "old", "0x%x", p_m_d_l3id);
2351 /* nt-library now gives us a new id via CC_SETUP_CONFIRM */
2352 if ((p_m_d_l3id&0xff00) != 0xff00)
2353 PERROR(" strange setup-procid 0x%x\n", p_m_d_l3id);
2354 p_m_d_l3id = *((int *)(((u_char *)data)+ mISDNUSER_HEAD_SIZE));
2355 add_trace("callref", "new", "0x%x", p_m_d_l3id);
2360 case CC_INFORMATION | INDICATION:
2361 information_ind(prim, dinfo, data);
2364 case CC_SETUP_ACKNOWLEDGE | INDICATION:
2365 if (p_state != PORT_STATE_OUT_SETUP)
2367 PERROR("Pdss1(%s) received setup_acknowledge, but we are not in outgoing setup state, IGNORING.\n", p_name);
2370 setup_acknowledge_ind(prim, dinfo, data);
2373 case CC_PROCEEDING | INDICATION:
2374 if (p_state != PORT_STATE_OUT_SETUP
2375 && p_state != PORT_STATE_OUT_OVERLAP)
2377 PERROR("Pdss1(%s) received proceeding, but we are not in outgoing setup OR overlap state, IGNORING.\n", p_name);
2380 proceeding_ind(prim, dinfo, data);
2383 case CC_ALERTING | INDICATION:
2384 if (p_state != PORT_STATE_OUT_SETUP
2385 && p_state != PORT_STATE_OUT_OVERLAP
2386 && p_state != PORT_STATE_OUT_PROCEEDING)
2388 PERROR("Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding state, IGNORING.\n", p_name);
2391 alerting_ind(prim, dinfo, data);
2394 case CC_CONNECT | INDICATION:
2395 if (p_state != PORT_STATE_OUT_SETUP
2396 && p_state != PORT_STATE_OUT_OVERLAP
2397 && p_state != PORT_STATE_OUT_PROCEEDING
2398 && p_state != PORT_STATE_OUT_ALERTING)
2400 PERROR("Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding OR ALERTING state, IGNORING.\n", p_name);
2403 connect_ind(prim, dinfo, data);
2404 if (p_m_d_notify_pending)
2406 /* send pending notify message during connect */
2407 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2408 message_free(p_m_d_notify_pending);
2409 p_m_d_notify_pending = NULL;
2413 case CC_CONNECT_ACKNOWLEDGE | INDICATION:
2414 case CC_CONNECT | CONFIRM:
2415 if (p_state == PORT_STATE_CONNECT_WAITING)
2416 new_state(PORT_STATE_CONNECT);
2417 if (p_m_d_notify_pending)
2419 /* send pending notify message during connect-ack */
2420 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2421 message_free(p_m_d_notify_pending);
2422 p_m_d_notify_pending = NULL;
2426 case CC_DISCONNECT | INDICATION:
2427 disconnect_ind(prim, dinfo, data);
2430 case CC_RELEASE | CONFIRM:
2431 case CC_RELEASE | INDICATION:
2432 release_ind(prim, dinfo, data);
2435 case CC_RELEASE_COMPLETE | INDICATION:
2436 release_complete_ind(prim, dinfo, data);
2439 case CC_RELEASE_COMPLETE | CONFIRM:
2442 case CC_NOTIFY | INDICATION:
2443 notify_ind(prim, dinfo, data);
2446 case CC_HOLD | INDICATION:
2447 hold_ind(prim, dinfo, data);
2450 case CC_RETRIEVE | INDICATION:
2451 retrieve_ind(prim, dinfo, data);
2454 case CC_SUSPEND | INDICATION:
2455 suspend_ind(prim, dinfo, data);
2458 case CC_RESUME | INDICATION:
2459 resume_ind(prim, dinfo, data);
2462 case CC_FACILITY | INDICATION:
2463 facility_ind(prim, dinfo, data);
2466 case CC_RELEASE_CR | INDICATION:
2467 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_CR_IND, DIRECTION_IN);
2468 add_trace("callref", NULL, "0x%x", p_m_d_l3id);
2472 if ((p_m_d_l3id&0xff00) == 0xff00)
2473 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
2478 //#warning remove me
2479 //PDEBUG(DEBUG_LOG, "JOLLY release cr %d\n", p_serial);
2480 /* sending release to endpoint in case we still have an endpoint
2481 * this is because we don't get any response if a release_complete is received (or a release in release state)
2485 struct message *message;
2486 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
2487 message->param.disconnectinfo.cause = (p_m_d_collect_cause!=CAUSE_NOUSER)?p_m_d_collect_cause:CAUSE_UNSPECIFIED;
2488 message->param.disconnectinfo.location = (p_m_d_collect_cause!=CAUSE_NOUSER)?p_m_d_collect_location:LOCATION_PRIVATE_LOCAL;
2489 message_put(message);
2491 free_epointlist(p_epointlist);
2493 new_state(PORT_STATE_RELEASE);
2497 case CC_NEW_CR | INDICATION:
2498 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_CR_IND, DIRECTION_IN);
2500 add_trace("callref", "old", "0x%x", p_m_d_l3id);
2503 new_l3id = *((int *)(((u_char *)data+mISDNUSER_HEAD_SIZE)));
2504 if (((new_l3id&0xff00)!=0xff00) && ((p_m_d_l3id&0xff00)==0xff00))
2505 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
2510 p_m_d_l3id = new_l3id;
2511 add_trace("callref", "new", "0x%x", p_m_d_l3id);
2516 l1l2l3_trace_header(p_m_mISDNport, this, L3_UNKNOWN, DIRECTION_IN);
2517 add_trace("unhandled", "prim", "0x%x", prim);
2523 void Pdss1::new_state(int state)
2525 // class Endpoint *epoint;
2528 if (state == PORT_STATE_IN_OVERLAP)
2530 p_m_timeout = p_m_mISDNport->ifport->tout_dialing;
2533 if (state != p_state)
2535 if (state == PORT_STATE_IN_SETUP
2536 || state == PORT_STATE_OUT_SETUP
2537 || state == PORT_STATE_IN_OVERLAP
2538 || state == PORT_STATE_OUT_OVERLAP)
2540 p_m_timeout = p_m_mISDNport->ifport->tout_setup;
2543 if (state == PORT_STATE_IN_PROCEEDING
2544 || state == PORT_STATE_OUT_PROCEEDING)
2546 p_m_timeout = p_m_mISDNport->ifport->tout_proceeding;
2549 if (state == PORT_STATE_IN_ALERTING
2550 || state == PORT_STATE_OUT_ALERTING)
2552 p_m_timeout = p_m_mISDNport->ifport->tout_alerting;
2555 if (state == PORT_STATE_CONNECT
2556 || state == PORT_STATE_CONNECT_WAITING)
2560 if (state == PORT_STATE_IN_DISCONNECT
2561 || state == PORT_STATE_OUT_DISCONNECT)
2563 p_m_timeout = p_m_mISDNport->ifport->tout_disconnect;
2568 Port::new_state(state);
2575 int Pdss1::handler(void)
2579 if ((ret = PmISDN::handler()))
2582 /* handle destruction */
2583 if (p_m_delete && p_m_d_l3id==0)
2594 * handles all messages from endpoint
2596 /* MESSAGE_INFORMATION */
2597 void Pdss1::message_information(unsigned long epoint_id, int message_id, union parameter *param)
2602 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2604 INFORMATION_t *information;
2607 if (param->information.id[0]) /* only if we have something to dial */
2610 l3m = create_l3msg();
2612 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2613 information = (INFORMATION_t *)(dmsg->data + headerlen);
2615 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
2617 enc_ie_called_pn(l3m, 0, 1, (unsigned char *)param->information.id);
2619 enc_ie_called_pn(&information->CALLED_PN, dmsg, 0, 1, (unsigned char *)param->information.id);
2623 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
2625 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2635 void Pdss1::message_setup(unsigned long epoint_id, int message_id, union parameter *param)
2641 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2643 INFORMATION_t *information;
2647 int plan, type, screen, present, reason;
2648 int capability, mode, rate, coding, user, presentation, interpretation, hlc, exthlc;
2649 int channel, exclusive;
2650 struct epoint_list *epointlist;
2652 /* release if port is blocked */
2653 if (p_m_mISDNport->ifport->block)
2655 struct message *message;
2657 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2658 message->param.disconnectinfo.cause = 27; // temp. unavail.
2659 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2660 message_put(message);
2661 new_state(PORT_STATE_RELEASE);
2666 /* copy setup infos to port */
2667 memcpy(&p_callerinfo, ¶m->setup.callerinfo, sizeof(p_callerinfo));
2668 memcpy(&p_dialinginfo, ¶m->setup.dialinginfo, sizeof(p_dialinginfo));
2669 memcpy(&p_capainfo, ¶m->setup.capainfo, sizeof(p_capainfo));
2670 memcpy(&p_redirinfo, ¶m->setup.redirinfo, sizeof(p_redirinfo));
2671 // SCPY(&p_m_tones_dir, param->setup.ext.tones_dir);
2672 /* screen outgoing caller id */
2673 do_screen(1, p_callerinfo.id, sizeof(p_callerinfo.id), &p_callerinfo.ntype, &p_callerinfo.present, p_m_mISDNport->ifport->interface);
2675 /* only display at connect state: this case happens if endpoint is in connected mode */
2676 if (p_state==PORT_STATE_CONNECT)
2678 if (p_type!=PORT_TYPE_DSS1_NT_OUT
2679 && p_type!=PORT_TYPE_DSS1_NT_IN)
2681 if (p_callerinfo.display[0])
2683 /* sending information */
2685 l3m = create_l3msg();
2687 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2688 information = (INFORMATION_t *)(dmsg->data + headerlen);
2690 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
2693 enc_ie_display(l3m, (unsigned char *)p_callerinfo.display);
2695 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_callerinfo.display);
2699 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
2701 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2707 /* attach only if not already */
2708 epointlist = p_epointlist;
2711 if (epointlist->epoint_id == epoint_id)
2713 epointlist = epointlist->next;
2716 epointlist_new(epoint_id);
2722 channel = p_m_b_channel;
2723 exclusive = p_m_b_exclusive;
2725 channel = CHANNEL_ANY;
2726 /* nt-port with no channel, not reserverd */
2727 if (!p_m_b_channel && !p_m_b_reserve && p_type==PORT_TYPE_DSS1_NT_OUT)
2728 channel = CHANNEL_NO;
2732 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_REQ, DIRECTION_OUT);
2733 /* see MT_ASSIGN notes at do_layer3() */
2735 ret = p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_ASSIGN, 0, NULL);
2736 if (mt_assign_pid == 0 || ret < 0)
2738 struct message *message;
2740 add_trace("callref", NULL, "no free id");
2742 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2743 message->param.disconnectinfo.cause = 47;
2744 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2745 message_put(message);
2746 new_state(PORT_STATE_RELEASE);
2750 p_m_d_l3id = mt_assign_pid;
2754 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_CR_REQ, DIRECTION_OUT);
2760 if (p_m_mISDNport->procids[i] == 0)
2766 struct message *message;
2768 add_trace("callref", NULL, "no free id");
2770 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2771 message->param.disconnectinfo.cause = 47;
2772 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2773 message_put(message);
2774 new_state(PORT_STATE_RELEASE);
2778 p_m_mISDNport->procids[i] = 1;
2779 p_m_d_l3id = 0xff00 | i;
2783 /* if we are in te-mode, we need to create a process first */
2784 if (newteid++ > 0x7fff)
2786 p_m_d_l3id = (entity<<16) | newteid;
2787 /* preparing message */
2788 ncr.prim = CC_NEW_CR | REQUEST;
2789 ncr.addr = p_m_mISDNport->upper_id | FLG_MSG_DOWN;
2790 ncr.dinfo = p_m_d_l3id;
2793 mISDN_write(mISDNdevice, &ncr, mISDN_HEADER_LEN+ncr.len, TIMEOUT_1SEC);
2797 add_trace("callref", "new", "0x%x", p_m_d_l3id);
2801 /* preparing setup message */
2803 l3m = create_l3msg();
2805 dmsg = create_l3msg(CC_SETUP | REQUEST, MT_SETUP, p_m_d_l3id, sizeof(SETUP_t), p_m_d_ntmode);
2806 setup = (SETUP_t *)(dmsg->data + headerlen);
2808 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_REQ, DIRECTION_OUT);
2809 /* channel information */
2810 if (channel >= 0) /* it should */
2813 enc_ie_channel_id(l3m, exclusive, channel);
2815 enc_ie_channel_id(&setup->CHANNEL_ID, dmsg, exclusive, channel);
2818 /* caller information */
2820 switch (p_callerinfo.ntype)
2822 case INFO_NTYPE_INTERNATIONAL:
2825 case INFO_NTYPE_NATIONAL:
2828 case INFO_NTYPE_SUBSCRIBER:
2831 default: /* INFO_NTYPE_UNKNOWN */
2835 switch (p_callerinfo.screen)
2837 case INFO_SCREEN_USER:
2840 default: /* INFO_SCREEN_NETWORK */
2844 switch (p_callerinfo.present)
2846 case INFO_PRESENT_RESTRICTED:
2849 case INFO_PRESENT_NOTAVAIL:
2852 default: /* INFO_PRESENT_ALLOWED */
2858 enc_ie_calling_pn(l3m, type, plan, present, screen, (unsigned char *)p_callerinfo.id);
2860 enc_ie_calling_pn(&setup->CALLING_PN, dmsg, type, plan, present, screen, (unsigned char *)p_callerinfo.id);
2862 /* dialing information */
2863 if (p_dialinginfo.id[0]) /* only if we have something to dial */
2866 enc_ie_called_pn(l3m, 0, 1, (unsigned char *)p_dialinginfo.id);
2868 enc_ie_called_pn(&setup->CALLED_PN, dmsg, 0, 1, (unsigned char *)p_dialinginfo.id);
2871 /* sending complete */
2872 if (p_dialinginfo.sending_complete)
2874 enc_ie_complete(l3m, 1);
2876 enc_ie_complete(&setup->COMPLETE, dmsg, 1);
2878 /* sending user-user */
2879 if (param->setup.useruser.len)
2882 enc_ie_useruser(l3m, param->setup.useruser.protocol, param->setup.useruser.data, param->setup.useruser.len);
2884 enc_ie_useruser(&setup->USER_USER, dmsg, param->setup.useruser.protocol, param->setup.useruser.data, param->setup.useruser.len);
2887 /* redirecting number */
2889 switch (p_redirinfo.ntype)
2891 case INFO_NTYPE_INTERNATIONAL:
2894 case INFO_NTYPE_NATIONAL:
2897 case INFO_NTYPE_SUBSCRIBER:
2900 default: /* INFO_NTYPE_UNKNOWN */
2904 switch (p_redirinfo.screen)
2906 case INFO_SCREEN_USER:
2909 default: /* INFO_SCREE_NETWORK */
2913 switch (p_redirinfo.reason)
2915 case INFO_REDIR_BUSY:
2918 case INFO_REDIR_NORESPONSE:
2921 case INFO_REDIR_UNCONDITIONAL:
2924 case INFO_REDIR_CALLDEFLECT:
2927 case INFO_REDIR_OUTOFORDER:
2930 default: /* INFO_REDIR_UNKNOWN */
2934 switch (p_redirinfo.present)
2936 case INFO_PRESENT_NULL: /* no redir at all */
2943 case INFO_PRESENT_RESTRICTED:
2946 case INFO_PRESENT_NOTAVAIL:
2949 default: /* INFO_PRESENT_ALLOWED */
2953 /* sending redirecting number only in ntmode */
2954 if (type >= 0 && p_m_d_ntmode)
2956 enc_ie_redir_nr(l3m, type, plan, present, screen, reason, (unsigned char *)p_redirinfo.id);
2958 enc_ie_redir_nr(&setup->REDIR_NR, dmsg, type, plan, present, screen, reason, (unsigned char *)p_redirinfo.id);
2960 /* bearer capability */
2961 //printf("hlc=%d\n",p_capainfo.hlc);
2963 capability = p_capainfo.bearer_capa;
2964 mode = p_capainfo.bearer_mode;
2965 rate = (mode==INFO_BMODE_CIRCUIT)?0x10:0x00;
2966 switch (p_capainfo.bearer_info1)
2968 case INFO_INFO1_NONE:
2972 user = p_capainfo.bearer_info1 & 0x7f;
2976 enc_ie_bearer(l3m, coding, capability, mode, rate, -1, user);
2978 enc_ie_bearer(&setup->BEARER, dmsg, coding, capability, mode, rate, -1, user);
2986 hlc = p_capainfo.hlc & 0x7f;
2988 if (p_capainfo.exthlc)
2989 exthlc = p_capainfo.exthlc & 0x7f;
2991 enc_ie_hlc(l3m, coding, interpretation, presentation, hlc, exthlc);
2993 enc_ie_hlc(&setup->HLC, dmsg, coding, interpretation, presentation, hlc, exthlc);
2998 if (p_callerinfo.display[0] && p_m_d_ntmode)
3000 enc_ie_display(l3m, (unsigned char *)p_callerinfo.display);
3002 enc_ie_display(&setup->DISPLAY, dmsg, (unsigned char *)p_callerinfo.display);
3004 /* nt-mode: CNIP (calling name identification presentation) */
3005 // if (p_callerinfo.name[0] && p_m_d_ntmode)
3006 // enc_facility_centrex(&setup->FACILITY, dmsg, (unsigned char *)p_callerinfo.name, 1);
3009 /* send setup message now */
3011 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SETUP, p_m_d_l3id, l3m);
3013 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3016 new_state(PORT_STATE_OUT_SETUP);
3019 /* MESSAGE_FACILITY */
3020 void Pdss1::message_facility(unsigned long epoint_id, int message_id, union parameter *param)
3025 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
3027 FACILITY_t *facility;
3030 /* facility will not be sent to external lines */
3034 /* sending facility */
3036 l3m = create_l3msg();
3038 dmsg = create_l3msg(CC_FACILITY | REQUEST, MT_FACILITY, p_m_d_l3id, sizeof(FACILITY_t), p_m_d_ntmode);
3039 facility = (FACILITY_t *)(dmsg->data + headerlen);
3041 l1l2l3_trace_header(p_m_mISDNport, this, L3_FACILITY_REQ, DIRECTION_OUT);
3043 enc_ie_facility(l3m, (unsigned char *)param->facilityinfo.data, param->facilityinfo.len);
3045 enc_ie_facility(&facility->FACILITY, dmsg, (unsigned char *)param->facilityinfo.data, param->facilityinfo.len);
3049 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_FACILITY, p_m_d_l3id, l3m);
3051 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3055 /* MESSAGE_NOTIFY */
3056 void Pdss1::message_notify(unsigned long epoint_id, int message_id, union parameter *param)
3061 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
3063 INFORMATION_t *information;
3064 NOTIFY_t *notification;
3067 int plan, type = -1, present;
3069 if (param->notifyinfo.notify>INFO_NOTIFY_NONE)
3070 notify = param->notifyinfo.notify & 0x7f;
3073 if (p_state != PORT_STATE_CONNECT)
3075 /* notify only allowed in active state */
3081 switch (param->notifyinfo.ntype)
3083 case INFO_NTYPE_INTERNATIONAL:
3086 case INFO_NTYPE_NATIONAL:
3089 case INFO_NTYPE_SUBSCRIBER:
3092 default: /* INFO_NTYPE_UNKNOWN */
3096 switch (param->notifyinfo.present)
3098 case INFO_PRESENT_NULL: /* no redir at all */
3103 case INFO_PRESENT_RESTRICTED:
3106 case INFO_PRESENT_NOTAVAIL:
3109 default: /* INFO_PRESENT_ALLOWED */
3115 if (notify<0 && !param->notifyinfo.display[0])
3117 /* nothing to notify, nothing to display */
3123 if (p_state!=PORT_STATE_CONNECT)
3125 /* queue notification */
3126 if (p_m_d_notify_pending)
3127 message_free(p_m_d_notify_pending);
3128 p_m_d_notify_pending = message_create(ACTIVE_EPOINT(p_epointlist), p_serial, EPOINT_TO_PORT, message_id);
3129 memcpy(&p_m_d_notify_pending->param, param, sizeof(union parameter));
3132 /* sending notification */
3134 l3m = create_l3msg();
3136 dmsg = create_l3msg(CC_NOTIFY | REQUEST, MT_NOTIFY, p_m_d_l3id, sizeof(NOTIFY_t), p_m_d_ntmode);
3137 notification = (NOTIFY_t *)(dmsg->data + headerlen);
3139 l1l2l3_trace_header(p_m_mISDNport, this, L3_NOTIFY_REQ, DIRECTION_OUT);
3141 enc_ie_notify(l3m, notify);
3143 enc_ie_notify(¬ification->NOTIFY, dmsg, notify);
3145 /* sending redirection number only in ntmode */
3146 if (type >= 0 && p_m_d_ntmode)
3148 enc_ie_redir_dn(l3m, type, plan, present, (unsigned char *)param->notifyinfo.id);
3150 enc_ie_redir_dn(¬ification->REDIR_DN, dmsg, type, plan, present, (unsigned char *)param->notifyinfo.id);
3152 if (param->notifyinfo.display[0] && p_m_d_ntmode)
3154 enc_ie_display(l3m, (unsigned char *)param->notifyinfo.display);
3156 enc_ie_display(¬ification->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display);
3160 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_NOTIFY, p_m_d_l3id, l3m);
3162 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3165 } else if (p_m_d_ntmode)
3167 /* sending information */
3169 l3m = create_l3msg();
3171 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
3172 information = (INFORMATION_t *)(dmsg->data + headerlen);
3174 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
3176 enc_ie_display(l3m, (unsigned char *)param->notifyinfo.display);
3178 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display);
3182 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
3184 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3189 /* MESSAGE_OVERLAP */
3190 void Pdss1::message_overlap(unsigned long epoint_id, int message_id, union parameter *param)
3195 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
3197 SETUP_ACKNOWLEDGE_t *setup_acknowledge;
3200 /* sending setup_acknowledge */
3202 l3m = create_l3msg();
3204 dmsg = create_l3msg(CC_SETUP_ACKNOWLEDGE | REQUEST, MT_SETUP_ACKNOWLEDGE, p_m_d_l3id, sizeof(SETUP_ACKNOWLEDGE_t), p_m_d_ntmode);
3205 setup_acknowledge = (SETUP_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
3207 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_ACKNOWLEDGE_REQ, DIRECTION_OUT);
3208 /* channel information */
3209 if (p_state == PORT_STATE_IN_SETUP)
3211 enc_ie_channel_id(l3m, 1, p_m_b_channel);
3213 enc_ie_channel_id(&setup_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
3215 /* progress information */
3216 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
3217 || p_capainfo.bearer_capa==INFO_BC_AUDIO
3218 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
3219 if (p_m_mISDNport->tones)
3221 enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
3223 enc_ie_progress(&setup_acknowledge->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
3227 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SETUP_ACKNOWLEDGE, p_m_d_l3id, l3m);
3229 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3232 new_state(PORT_STATE_IN_OVERLAP);
3235 /* MESSAGE_PROCEEDING */
3236 void Pdss1::message_proceeding(unsigned long epoint_id, int message_id, union parameter *param)
3241 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
3243 CALL_PROCEEDING_t *proceeding;
3246 /* sending proceeding */
3248 l3m = create_l3msg();
3250 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
3251 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
3253 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
3254 /* channel information */
3255 if (p_state == PORT_STATE_IN_SETUP)
3257 enc_ie_channel_id(l3m, 1, p_m_b_channel);
3259 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
3261 /* progress information */
3262 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
3263 || p_capainfo.bearer_capa==INFO_BC_AUDIO
3264 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
3265 if (p_m_mISDNport->tones)
3267 enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
3269 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
3273 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
3275 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3278 new_state(PORT_STATE_IN_PROCEEDING);
3281 /* MESSAGE_ALERTING */
3282 void Pdss1::message_alerting(unsigned long epoint_id, int message_id, union parameter *param)
3287 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
3289 ALERTING_t *alerting;
3292 /* NT-MODE in setup state we must send PROCEEDING first */
3293 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
3295 /* sending proceeding */
3297 l3m = create_l3msg();
3299 CALL_PROCEEDING_t *proceeding;
3300 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
3301 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
3303 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
3304 /* channel information */
3306 enc_ie_channel_id(l3m, 1, p_m_b_channel);
3308 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
3310 /* progress information */
3311 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
3312 || p_capainfo.bearer_capa==INFO_BC_AUDIO
3313 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
3315 enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
3317 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
3321 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
3323 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3325 new_state(PORT_STATE_IN_PROCEEDING);
3328 /* sending alerting */
3330 l3m = create_l3msg();
3332 dmsg = create_l3msg(CC_ALERTING | REQUEST, MT_ALERTING, p_m_d_l3id, sizeof(ALERTING_t), p_m_d_ntmode);
3333 alerting = (ALERTING_t *)(dmsg->data + headerlen);
3335 l1l2l3_trace_header(p_m_mISDNport, this, L3_ALERTING_REQ, DIRECTION_OUT);
3336 /* channel information */
3337 if (p_state == PORT_STATE_IN_SETUP)
3339 enc_ie_channel_id(l3m, 1, p_m_b_channel);
3341 enc_ie_channel_id(&alerting->CHANNEL_ID, dmsg, 1, p_m_b_channel);
3343 /* progress information */
3344 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
3345 || p_capainfo.bearer_capa==INFO_BC_AUDIO
3346 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
3347 if (p_m_mISDNport->tones)
3349 enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
3351 enc_ie_progress(&alerting->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
3355 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_ALERTING, p_m_d_l3id, l3m);
3357 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3360 new_state(PORT_STATE_IN_ALERTING);
3363 /* MESSAGE_CONNECT */
3364 void Pdss1::message_connect(unsigned long epoint_id, int message_id, union parameter *param)
3369 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
3371 INFORMATION_t *information;
3374 int type, plan, present, screen;
3375 class Endpoint *epoint;
3377 /* NT-MODE in setup state we must send PROCEEDING first */
3378 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
3380 /* sending proceeding */
3382 l3m = create_l3msg();
3384 CALL_PROCEEDING_t *proceeding;
3385 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
3386 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
3388 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
3389 /* channel information */
3391 enc_ie_channel_id(l3m, 1, p_m_b_channel);
3393 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
3395 // /* progress information */
3396 // if (p_capainfo.bearer_capa==INFO_BC_SPEECH
3397 // || p_capainfo.bearer_capa==INFO_BC_AUDIO
3398 // || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
3400 // enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
3402 // enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
3406 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
3408 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3410 new_state(PORT_STATE_IN_PROCEEDING);
3413 /* copy connected information */
3414 memcpy(&p_connectinfo, ¶m->connectinfo, sizeof(p_connectinfo));
3415 /* screen outgoing caller id */
3416 do_screen(1, p_connectinfo.id, sizeof(p_connectinfo.id), &p_connectinfo.ntype, &p_connectinfo.present, p_m_mISDNport->ifport->interface);
3418 /* only display at connect state */
3419 if (p_state == PORT_STATE_CONNECT)
3420 if (p_connectinfo.display[0])
3422 /* sending information */
3424 l3m = create_l3msg();
3426 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
3427 information = (INFORMATION_t *)(dmsg->data + headerlen);
3429 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
3432 enc_ie_display(l3m, (unsigned char *)p_connectinfo.display);
3434 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_connectinfo.display);
3438 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
3440 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3445 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)
3447 /* connect command only possible in setup, proceeding or alerting state */
3451 /* preparing connect message */
3453 l3m = create_l3msg();
3455 dmsg = create_l3msg(CC_CONNECT | REQUEST, MT_CONNECT, p_m_d_l3id, sizeof(CONNECT_t), p_m_d_ntmode);
3456 connect = (CONNECT_t *)(dmsg->data + headerlen);
3458 l1l2l3_trace_header(p_m_mISDNport, this, L3_CONNECT_REQ, DIRECTION_OUT);
3459 /* connect information */
3461 switch (p_connectinfo.ntype)
3463 case INFO_NTYPE_INTERNATIONAL:
3466 case INFO_NTYPE_NATIONAL:
3469 case INFO_NTYPE_SUBSCRIBER:
3472 default: /* INFO_NTYPE_UNKNOWN */
3476 switch (param->connectinfo.screen)
3478 case INFO_SCREEN_USER:
3481 default: /* INFO_SCREE_NETWORK */
3485 switch (p_connectinfo.present)
3487 case INFO_PRESENT_NULL: /* no colp at all */
3493 case INFO_PRESENT_RESTRICTED:
3496 case INFO_PRESENT_NOTAVAIL:
3499 default: /* INFO_PRESENT_ALLOWED */
3505 enc_ie_connected_pn(l3m, type, plan, present, screen, (unsigned char *)p_connectinfo.id);
3507 enc_ie_connected_pn(&connect->CONNECT_PN, dmsg, type, plan, present, screen, (unsigned char *)p_connectinfo.id);
3510 if (p_connectinfo.display[0] && p_m_d_ntmode)
3512 enc_ie_display(l3m, (unsigned char *)p_connectinfo.display);
3514 enc_ie_display(&connect->DISPLAY, dmsg, (unsigned char *)p_connectinfo.display);
3516 /* nt-mode: CONP (connected name identification presentation) */
3517 // if (p_connectinfo.name[0] && p_m_d_ntmode)
3518 // enc_facility_centrex(&connect->FACILITY, dmsg, (unsigned char *)p_connectinfo.name, 0);
3522 epoint = find_epoint_id(epoint_id);
3524 enc_ie_date(l3m, now, p_settings.no_seconds);
3526 enc_ie_date(&connect->DATE, dmsg, now, p_settings.no_seconds);
3530 /* finally send message */
3532 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CONNECT, p_m_d_l3id, l3m);
3534 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3538 new_state(PORT_STATE_CONNECT);
3540 new_state(PORT_STATE_CONNECT_WAITING);
3544 /* MESSAGE_DISCONNECT */
3545 void Pdss1::message_disconnect(unsigned long epoint_id, int message_id, union parameter *param)
3550 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
3552 DISCONNECT_t *disconnect;
3553 RELEASE_COMPLETE_t *release_complete;
3555 struct message *message;
3558 /* we reject during incoming setup when we have no tones. also if we are in outgoing setup state */
3559 // if ((p_state==PORT_STATE_IN_SETUP && !p_m_mISDNport->tones)
3560 if (/* ||*/ p_state==PORT_STATE_OUT_SETUP)
3562 /* sending release to endpoint */
3565 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
3566 message->param.disconnectinfo.cause = 16;
3567 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
3568 message_put(message);
3570 free_epointlist(p_epointlist);
3572 /* sending release */
3574 l3m = create_l3msg();
3576 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
3577 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
3579 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
3582 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
3584 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);
3588 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
3590 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3592 new_state(PORT_STATE_RELEASE);
3597 /* workarround: NT-MODE in setup state we must send PROCEEDING first to make it work */
3598 if (p_state==PORT_STATE_IN_SETUP)
3600 /* sending proceeding */
3602 l3m = create_l3msg();
3604 CALL_PROCEEDING_t *proceeding;
3605 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
3606 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
3608 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
3609 /* channel information */
3611 enc_ie_channel_id(l3m, 1, p_m_b_channel);
3613 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
3615 /* progress information */
3616 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
3617 || p_capainfo.bearer_capa==INFO_BC_AUDIO
3618 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
3620 enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
3622 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
3626 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
3628 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3630 new_state(PORT_STATE_IN_PROCEEDING);
3633 /* sending disconnect */
3635 l3m = create_l3msg();
3637 dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode);
3638 disconnect = (DISCONNECT_t *)(dmsg->data + headerlen);
3640 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_REQ, DIRECTION_OUT);
3641 /* progress information */
3642 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
3643 || p_capainfo.bearer_capa==INFO_BC_AUDIO
3644 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
3645 if (p_m_mISDNport->tones)
3647 enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
3649 enc_ie_progress(&disconnect->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
3653 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
3655 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);
3658 if (param->disconnectinfo.display[0])
3659 p = param->disconnectinfo.display;
3660 if (p) if (*p && p_m_d_ntmode)
3662 enc_ie_display(l3m, (unsigned char *)p);
3664 enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p);
3668 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_DISCONNECT, p_m_d_l3id, l3m);
3670 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3672 new_state(PORT_STATE_OUT_DISCONNECT);
3675 /* MESSAGE_RELEASE */
3676 void Pdss1::message_release(unsigned long epoint_id, int message_id, union parameter *param)
3681 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
3684 RELEASE_COMPLETE_t *release_complete;
3685 DISCONNECT_t *disconnect;
3687 class Endpoint *epoint;
3691 * we may only release during incoming disconnect state.
3692 * this means that the endpoint doesnt require audio anymore
3694 if (p_state == PORT_STATE_IN_DISCONNECT
3695 || p_state == PORT_STATE_OUT_DISCONNECT)
3697 /* sending release */
3699 l3m = create_l3msg();
3701 dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, p_m_d_l3id, sizeof(RELEASE_t), p_m_d_ntmode);
3702 release = (RELEASE_t *)(dmsg->data + headerlen);
3704 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_REQ, DIRECTION_OUT);
3707 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
3709 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);
3713 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE, p_m_d_l3id, l3m);
3715 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3717 new_state(PORT_STATE_RELEASE);
3719 free_epointid(epoint_id);
3720 // wait for callref to be released
3725 * if we are on incoming call setup, we may reject by sending a release_complete
3726 * also on outgoing call setup, we send a release complete, BUT this is not conform. (i don't know any other way)
3728 if (p_state==PORT_STATE_IN_SETUP
3729 || p_state==PORT_STATE_OUT_SETUP)
3730 // // NOTE: a bug in mISDNuser (see disconnect_req_out !!!)
3731 // || p_state==PORT_STATE_OUT_DISCO)
3733 //#warning remove me
3734 //PDEBUG(DEBUG_LOG, "JOLLY sending release complete %d\n", p_serial);
3735 /* sending release complete */
3737 l3m = create_l3msg();
3739 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
3740 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
3742 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_REQ, DIRECTION_OUT);
3745 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
3747 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);
3751 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
3753 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3755 new_state(PORT_STATE_RELEASE);
3757 free_epointid(epoint_id);
3758 // wait for callref to be released
3763 wirklich erst proceeding?:
3764 /* NT-MODE in setup state we must send PROCEEDING first */
3765 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
3767 CALL_PROCEEDING_t *proceeding;
3769 /* sending proceeding */
3771 l3m = create_l3msg();
3773 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
3774 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
3776 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
3777 /* channel information */
3779 enc_ie_channel_id(l3m, 1, p_m_b_channel);
3781 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
3783 /* progress information */
3784 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
3785 || p_capainfo.bearer_capa==INFO_BC_AUDIO
3786 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
3788 enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
3790 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
3794 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
3796 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3801 /* sending disconnect */
3803 l3m = create_l3msg();
3805 dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode);
3806 disconnect = (DISCONNECT_t *)(dmsg->data + headerlen);
3808 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_REQ, DIRECTION_OUT);
3809 /* progress information */
3810 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
3811 || p_capainfo.bearer_capa==INFO_BC_AUDIO
3812 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
3813 if (p_m_mISDNport->tones)
3815 enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
3817 enc_ie_progress(&disconnect->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
3821 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
3823 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);
3826 epoint = find_epoint_id(epoint_id);
3827 if (param->disconnectinfo.display[0])
3828 p = param->disconnectinfo.display;
3829 if (p) if (*p && p_m_d_ntmode)
3831 enc_ie_display(l3m, (unsigned char *)p);
3833 enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p);
3837 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_DISCONNECT, p_m_d_l3id, l3m);
3839 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3841 new_state(PORT_STATE_OUT_DISCONNECT);
3843 free_epointid(epoint_id);
3844 // wait for release and callref to be released
3845 //#warning remove me
3846 //PDEBUG(DEBUG_LOG, "JOLLY sending disconnect %d\n", p_serial);
3851 * endpoint sends messages to the port
3853 int Pdss1::message_epoint(unsigned long epoint_id, int message_id, union parameter *param)
3855 struct message *message;
3857 if (PmISDN::message_epoint(epoint_id, message_id, param))
3862 case MESSAGE_INFORMATION: /* overlap dialing */
3863 if (p_type==PORT_TYPE_DSS1_NT_OUT
3864 && p_state!=PORT_STATE_OUT_OVERLAP
3865 && p_state!=PORT_STATE_CONNECT
3866 && p_state!=PORT_STATE_OUT_DISCONNECT
3867 && p_state!=PORT_STATE_IN_DISCONNECT)
3871 if (p_type==PORT_TYPE_DSS1_TE_OUT
3872 && p_state!=PORT_STATE_OUT_OVERLAP
3873 && p_state!=PORT_STATE_OUT_PROCEEDING
3874 && p_state!=PORT_STATE_OUT_ALERTING
3875 && p_state!=PORT_STATE_CONNECT
3876 && p_state!=PORT_STATE_OUT_DISCONNECT
3877 && p_state!=PORT_STATE_IN_DISCONNECT)
3881 if ((p_type==PORT_TYPE_DSS1_NT_IN || p_type==PORT_TYPE_DSS1_TE_IN)
3882 && p_state!=PORT_STATE_IN_OVERLAP
3883 && p_state!=PORT_STATE_IN_PROCEEDING
3884 && p_state!=PORT_STATE_IN_ALERTING
3885 && p_state!=PORT_STATE_CONNECT
3886 && p_state!=PORT_STATE_CONNECT_WAITING
3887 && p_state!=PORT_STATE_OUT_DISCONNECT
3888 && p_state!=PORT_STATE_IN_DISCONNECT)
3892 message_information(epoint_id, message_id, param);
3895 case MESSAGE_SETUP: /* dial-out command received from epoint */
3896 if (p_state!=PORT_STATE_IDLE
3897 && p_state!=PORT_STATE_CONNECT)
3899 PERROR("Pdss1(%s) ignoring setup because isdn port is not in idle state (or connected for sending display info).\n", p_name);
3902 if (p_epointlist && p_state==PORT_STATE_IDLE)
3903 FATAL("Pdss1(%s): epoint pointer is set in idle state, how bad!!\n", p_name);
3905 message_setup(epoint_id, message_id, param);
3907 /* note: pri is a special case, because links must be up for pri */
3908 if (p_m_mISDNport->l1link || p_m_mISDNport->pri || !p_m_mISDNport->ntmode || p_state!=PORT_STATE_IDLE)
3910 /* LAYER 1 is up, or we may send */
3911 message_setup(epoint_id, message_id, param);
3914 /* LAYER 1 id down, so we queue */
3915 p_m_d_queue = message_create(epoint_id, p_serial, EPOINT_TO_PORT, message_id);
3916 memcpy(&p_m_d_queue->param, param, sizeof(union parameter));
3918 if (!(epointlist_new(epoint_id)))
3919 FATAL("No memory for epointlist\n");
3921 PDEBUG(DEBUG_ISDN, "the L1 is down, we try to establish the link NT portnum=%d (%s).\n", p_m_mISDNport->portnum, p_name);
3922 act.prim = PH_ACTIVATE | REQUEST;
3923 act.addr = p_m_mISDNport->upper_id | FLG_MSG_DOWN;
3926 mISDN_write(mISDNdevice, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
3927 l1l2l3_trace_header(p_m_mISDNport, this, L1_ACTIVATE_REQ, DIRECTION_OUT);
3929 // /* set timeout */
3930 // p_m_mISDNport->l1timeout = now+3;
3935 case MESSAGE_NOTIFY: /* display and notifications */
3936 message_notify(epoint_id, message_id, param);
3939 case MESSAGE_FACILITY: /* facility message */
3940 message_facility(epoint_id, message_id, param);
3943 case MESSAGE_OVERLAP: /* more information is needed */
3944 if (p_state!=PORT_STATE_IN_SETUP)
3948 message_overlap(epoint_id, message_id, param);
3951 case MESSAGE_PROCEEDING: /* call of endpoint is proceeding */
3952 if (p_state!=PORT_STATE_IN_SETUP
3953 && p_state!=PORT_STATE_IN_OVERLAP)
3957 message_proceeding(epoint_id, message_id, param);
3960 case MESSAGE_ALERTING: /* call of endpoint is ringing */
3961 if (p_state!=PORT_STATE_IN_SETUP
3962 && p_state!=PORT_STATE_IN_OVERLAP
3963 && p_state!=PORT_STATE_IN_PROCEEDING)
3967 message_alerting(epoint_id, message_id, param);
3970 case MESSAGE_CONNECT: /* call of endpoint is connected */
3971 if (p_state!=PORT_STATE_IN_SETUP
3972 && p_state!=PORT_STATE_IN_OVERLAP
3973 && p_state!=PORT_STATE_IN_PROCEEDING
3974 && p_state!=PORT_STATE_IN_ALERTING
3975 && !(p_state==PORT_STATE_CONNECT && p_m_d_ntmode))
3979 message_connect(epoint_id, message_id, param);
3982 case MESSAGE_DISCONNECT: /* call has been disconnected */
3983 if (p_state!=PORT_STATE_IN_SETUP
3984 && p_state!=PORT_STATE_IN_OVERLAP
3985 && p_state!=PORT_STATE_IN_PROCEEDING
3986 && p_state!=PORT_STATE_IN_ALERTING
3987 && p_state!=PORT_STATE_OUT_SETUP
3988 && p_state!=PORT_STATE_OUT_OVERLAP
3989 && p_state!=PORT_STATE_OUT_PROCEEDING
3990 && p_state!=PORT_STATE_OUT_ALERTING
3991 && p_state!=PORT_STATE_CONNECT
3992 && p_state!=PORT_STATE_CONNECT_WAITING)
3996 message_disconnect(epoint_id, message_id, param);
3999 case MESSAGE_RELEASE: /* release isdn port */
4000 if (p_state==PORT_STATE_RELEASE)
4004 message_release(epoint_id, message_id, param);
4008 PERROR("Pdss1(%s) isdn port with (caller id %s) received a wrong message: %d\n", p_name, p_callerinfo.id, message);
4017 * data from isdn-stack (layer-3) to pbx (port class)
4020 int stack2manager(struct mISDNport *mISDNport, unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
4026 PDEBUG(DEBUG_ISDN, "cmd(0x%x) pid(0x%x)\n", cmd, pid);
4030 PERROR("PID is 0. change it.... quick...\n");
4034 /* find Port object of type ISDN */
4039 if (port->p_type == PORT_TYPE_DSS1_NT_IN || port->p_type == PORT_TYPE_DSS1_NT_OUT)
4041 pdss1 = (class Pdss1 *)port;
4042 /* check out correct stack and id */
4043 if (pdss1->p_m_mISDNport == mISDNport
4044 && pdss1->p_m_d_l3id == pid)
4046 /* found port, the message belongs to */
4053 /* aktueller prozess */
4056 /* if process id is master process, but a child disconnects */
4058 //hier das abfragen des child processes
4061 if (cmd == MT_DISCONNECT)
4063 /* send special indication for child disconnect */
4064 pdss1->disconnect_ind_i(cmd, pid, l3m);
4067 // ignoring other messages from child processes
4070 /* if process id and layer 3 id matches */
4071 pdss1->message_isdn(cmd, pid, l3m);
4079 /* creating port object */
4080 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
4081 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0)))
4083 FATAL("Cannot create Port instance.\n");
4084 pdss1->message_isdn(cmd, pid, l3m);
4088 /* creating port object */
4089 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
4090 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0)))
4091 FATAL("Cannot create Port instance.\n");
4092 pdss1->message_isdn(cmd, pid, l3m);
4096 PERROR("unhandled message from stack: call ref released (l3id=0x%x)\n", pid);
4099 case MT_RELEASE_COMPLETE:
4100 PERROR("must be ignored by stack, not sent to app\n");
4104 // facility als broadcast
4108 PERROR("unhandled message: cmd(0x%x) pid(0x%x)\n", cmd, pid);
4112 if (port->p_type == PORT_TYPE_DSS1_NT_IN || port->p_type == PORT_TYPE_DSS1_NT_OUT)
4114 pdss1 = (class Pdss1 *)port;
4115 /* check out correct stack */
4116 if (pdss1->p_m_mISDNport == mISDNport)
4117 /* check out correct id */
4118 PERROR("unhandled message: pid=%x is not associated with port-dinfo=%x\n", pid, pdss1->p_m_d_l3id);
4127 /* NOTE: nt mode use mISDNuser_head_t as header */
4128 int stack2manager_nt(void *dat, void *arg)
4132 manager_t *mgr = (manager_t *)dat;
4133 msg_t *msg = (msg_t *)arg;
4134 mISDNuser_head_t *hh;
4135 struct mISDNport *mISDNport;
4141 /* note: nst is the first data feld of mISDNport */
4142 mISDNport = (struct mISDNport *)mgr->nst;
4144 hh = (mISDNuser_head_t *)msg->data;
4145 PDEBUG(DEBUG_ISDN, "prim(0x%x) dinfo(0x%x) msg->len(%d)\n", hh->prim, hh->dinfo, msg->len);
4147 /* find Port object of type ISDN */
4151 if (port->p_type == PORT_TYPE_DSS1_NT_IN || port->p_type == PORT_TYPE_DSS1_NT_OUT)
4153 pdss1 = (class Pdss1 *)port;
4154 //PDEBUG(DEBUG_ISDN, "comparing dinfo = 0x%x with l3id 0x%x\n", hh->dinfo, pdss1->p_m_d_l3id);
4155 /* check out correct stack */
4156 if (pdss1->p_m_mISDNport == mISDNport)
4157 /* check out correct id */
4158 if ((pdss1->p_m_d_l3id&0x0000ff00) != 0x000ff00)
4160 /* a single process */
4161 if (hh->dinfo == pdss1->p_m_d_l3id)
4163 /* found port, the message belongs to */
4168 /* a broadcast process */
4169 if ((hh->dinfo&0xffff0000) == (pdss1->p_m_d_l3id&0xffff0000))
4171 /* found port, the message belongs to */
4180 //printf("%x %x\n", hh->dinfo, pdss1->p_m_d_l3id);
4181 /* if process id is master process, but a child disconnects */
4182 if ((hh->dinfo&0x0000ff00)!=0x0000ff00 && (pdss1->p_m_d_l3id&0x0000ff00)==0x0000ff00)
4184 if (hh->prim == (CC_DISCONNECT|INDICATION))
4186 /* send special indication for child disconnect */
4187 pdss1->disconnect_ind_i(hh->prim, hh->dinfo, msg->data);
4191 // ignoring other messages from child processes
4195 /* if process id and layer 3 id matches */
4196 if (hh->dinfo == pdss1->p_m_d_l3id)
4198 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
4207 case MGR_SHORTSTATUS | INDICATION:
4208 case MGR_SHORTSTATUS | CONFIRM:
4210 case SSTATUS_L2_ESTABLISHED:
4212 case SSTATUS_L2_RELEASED:
4217 case DL_ESTABLISH | INDICATION:
4218 l1l2l3_trace_header(mISDNport, NULL, L2_ESTABLISH_IND, DIRECTION_IN);
4220 case DL_ESTABLISH | CONFIRM:
4221 l1l2l3_trace_header(mISDNport, NULL, L2_ESTABLISH_CON, DIRECTION_IN);
4223 add_trace("tei", NULL, "%d", hh->dinfo);
4225 if (mISDNport->ptp && hh->dinfo == 0)
4227 if (mISDNport->l2establish)
4229 mISDNport->l2establish = 0;
4230 PDEBUG(DEBUG_ISDN, "the link became active before l2establish timer expiry.\n");
4232 mISDNport->l2link = 1;
4233 if (mISDNport->pri);
4234 mISDNport->l1link = 1; /* this is a hack, we also assume L1 to be active */
4238 case DL_RELEASE | INDICATION:
4239 l1l2l3_trace_header(mISDNport, NULL, L2_RELEASE_IND, DIRECTION_IN);
4241 case DL_RELEASE | CONFIRM:
4242 l1l2l3_trace_header(mISDNport, NULL, L2_RELEASE_CON, DIRECTION_IN);
4244 add_trace("tei", NULL, "%d", hh->dinfo);
4246 if (mISDNport->ptp && hh->dinfo == 0)
4248 mISDNport->l2link = 0;
4249 time(&mISDNport->l2establish);
4250 PDEBUG(DEBUG_ISDN, "because we are ptp, we set a l2establish timer.\n");
4254 case CC_SETUP | INDICATION:
4255 /* creating port object */
4256 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
4257 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0)))
4259 FATAL("Cannot create Port instance.\n");
4260 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
4263 case CC_RESUME | INDICATION:
4264 /* creating port object */
4265 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
4266 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0)))
4267 FATAL("Cannot create Port instance.\n");
4268 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
4271 case CC_RELEASE_CR | INDICATION:
4272 PERROR("unhandled message from stack: call ref released (l3id=0x%x)\n", hh->dinfo);
4275 case CC_RELEASE_COMPLETE | INDICATION:
4278 case CC_FACILITY | INDICATION:
4282 PERROR("unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", hh->prim, hh->dinfo, msg->len);
4286 if (port->p_type == PORT_TYPE_DSS1_NT_IN || port->p_type == PORT_TYPE_DSS1_NT_OUT)
4288 pdss1 = (class Pdss1 *)port;
4289 //PDEBUG(DEBUG_ISDN, "comparing dinfo = 0x%x with l3id 0x%x\n", hh->dinfo, pdss1->p_m_d_l3id);
4290 /* check out correct stack */
4291 if (pdss1->p_m_mISDNport == mISDNport)
4292 /* check out correct id */
4293 PERROR("unhandled message: dinfo=%x is not associated with port-dinfo=%x\n",hh->dinfo,pdss1->p_m_d_l3id);
4303 /* NOTE: te mode use iframe_t as header */
4304 int stack2manager_te(struct mISDNport *mISDNport, msg_t *msg)
4311 if (!msg || !mISDNport)
4313 frm = (iframe_t *)msg->data;
4314 PDEBUG(DEBUG_ISDN, "prim(0x%x) dinfo(0x%x) msg->len(%d)\n", frm->prim, frm->dinfo, msg->len);
4316 /* find Port object of type ISDN */
4320 if (port->p_type == PORT_TYPE_DSS1_TE_IN || port->p_type == PORT_TYPE_DSS1_TE_OUT)
4322 pdss1 = (class Pdss1 *)port;
4323 /* check out correct stack */
4324 if (pdss1->p_m_mISDNport == mISDNport)
4325 /* check out correct id */
4326 if (frm->dinfo == pdss1->p_m_d_l3id)
4328 /* found port, the message belongs to */
4336 pdss1->message_isdn(frm->prim, frm->dinfo, msg->data);
4341 /* process new cr (before setup indication) */
4342 //printf("prim = 0x%x, looking for 0x%x\n",frm->prim, (CC_NEW_CR | INDICATION));
4343 if (frm->prim == (CC_NEW_CR | INDICATION))
4346 /* creating port object */
4347 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
4348 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_TE_IN, mISDNport, name, NULL, 0, 0)))
4349 FATAL("Cannot create Port instance.\n");
4350 /* l3id will be set from dinfo at message_isdn */
4351 pdss1->message_isdn(frm->prim, frm->dinfo, msg->data);
4356 if (frm->prim == (CC_RELEASE_CR | INDICATION))
4358 PDEBUG(DEBUG_ISDN, "unhandled message from stack: call ref released (l3id=0x%x)\n", frm->dinfo);
4362 PERROR("unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", frm->prim, frm->dinfo, msg->len);
4366 #endif // stacktomanager
4369 #ifndef SOCKET_MISDN
4371 * sending message that were queued during L1 activation
4372 * or releasing port if link is down
4374 void setup_queue(struct mISDNport *mISDNport, int link)
4378 struct message *message;
4380 if (!mISDNport->ntmode)
4383 /* check all port objects for pending message */
4387 if ((port->p_type&PORT_CLASS_mISDN_MASK) == PORT_CLASS_mISDN_DSS1)
4389 pdss1 = (class Pdss1 *)port;
4390 if (pdss1->p_m_mISDNport == mISDNport)
4392 if (pdss1->p_m_d_queue)
4396 PDEBUG(DEBUG_ISDN, "the L1 became active, so we send queued message for portnum=%d (%s).\n", mISDNport->portnum, pdss1->p_name);
4397 /* LAYER 1 is up, so we send */
4398 pdss1->message_setup(pdss1->p_m_d_queue->id_from, pdss1->p_m_d_queue->type, &pdss1->p_m_d_queue->param);
4399 message_free(pdss1->p_m_d_queue);
4400 pdss1->p_m_d_queue = NULL;
4403 PDEBUG(DEBUG_ISDN, "the L1 became NOT active, so we release port for portnum=%d (%s).\n", mISDNport->portnum, pdss1->p_name);
4404 message = message_create(pdss1->p_serial, pdss1->p_m_d_queue->id_from, PORT_TO_EPOINT, MESSAGE_RELEASE);
4405 message->param.disconnectinfo.cause = 27;
4406 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
4407 message_put(message);
4408 pdss1->new_state(PORT_STATE_RELEASE);
4409 pdss1->p_m_delete = 1;