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();