1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
10 \*****************************************************************************/
17 #include <mISDNuser/net_l2.h>
21 #include <sys/socket.h>
25 extern unsigned long mt_assign_pid;
33 Pdss1::Pdss1(int type, struct mISDNport *mISDNport, char *portname, struct port_settings *settings, int channel, int exclusive) : PmISDN(type, mISDNport, portname, settings, channel, exclusive)
35 p_callerinfo.itype = (mISDNport->ifport->interface->extension)?INFO_ITYPE_ISDN_EXTENSION:INFO_ITYPE_ISDN;
36 p_m_d_ntmode = mISDNport->ntmode;
40 p_m_d_notify_pending = NULL;
41 p_m_d_collect_cause = 0;
42 p_m_d_collect_location = 0;
44 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);
53 /* remove queued message */
55 message_free(p_m_d_queue);
57 if (p_m_d_notify_pending)
58 message_free(p_m_d_notify_pending);
61 /* check how many processes are left */
62 if (p_m_d_ntmode == 1)
64 if (p_m_mISDNport->nst.layer3->proc)
65 PDEBUG(DEBUG_ISDN, "destroyed mISDNPort(%s). WARNING: There is still a layer 3 process left. Ignore this, if currently are other calls. This message is not an error!\n", p_name);
72 * create layer 3 message
75 static struct l3_msg *create_l3msg(void)
77 static msg_t *create_l3msg(int prim, int mt, int dinfo, int size, int ntmode)
92 size = sizeof(Q931_info_t)+2;
96 dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL);
103 dmsg = alloc_msg(size+256+mISDN_HEADER_LEN+DEFAULT_HEADROOM);
106 memset(msg_put(dmsg,size+mISDN_HEADER_LEN), 0, size+mISDN_HEADER_LEN);
107 frm = (iframe_t *)dmsg->data;
110 qi = (Q931_info_t *)(dmsg->data + mISDN_HEADER_LEN);
117 FATAL("Cannot allocate memory, system overloaded.\n");
118 exit(0); // make gcc happy
122 msg_t *create_l2msg(int prim, int dinfo, int size) /* NT only */
126 dmsg = prep_l3data_msg(prim, dinfo, size, 256, NULL);
130 FATAL("Cannot allocate memory, system overloaded.\n");
131 exit(0); // make gcc happy
136 * if we received a first reply to the setup message,
137 * we will check if we have now channel information
138 * return: <0: error, call is released, -cause is given
139 * 0: ok, nothing to do
142 int Pdss1::received_first_reply_to_setup(unsigned long cmd, int channel, int exclusive)
144 int Pdss1::received_first_reply_to_setup(unsigned long prim, int channel, int exclusive)
151 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
152 RELEASE_COMPLETE_t *release_complete;
156 /* correct exclusive to 0, if no explicit channel was given */
157 if (exclusive<0 || channel<=0)
160 /* select scenario */
161 if (p_m_b_channel && p_m_b_exclusive)
163 /*** we gave an exclusive channel (or if we are done) ***/
165 /* if not first reply, we are done */
166 if (p_state != PORT_STATE_OUT_SETUP)
169 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
170 add_trace("channel", "request", "%d (forced)", p_m_b_channel);
171 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
173 /* if give channel not accepted or not equal */
174 if (channel!=-1 && p_m_b_channel!=channel)
176 add_trace("conclusion", NULL, "forced channel not accepted");
182 add_trace("conclusion", NULL, "channel was accepted");
183 add_trace("connect", "channel", "%d", p_m_b_channel);
186 /* activate our exclusive channel */
187 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
191 /*** we gave a non-exclusive channel ***/
193 /* if not first reply, we are done */
194 if (p_state != PORT_STATE_OUT_SETUP)
197 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
198 add_trace("channel", "request", "%d (suggest)", p_m_b_channel);
199 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
201 /* if channel was accepted as given */
202 if (channel==-1 || p_m_b_channel==channel)
204 add_trace("conclusion", NULL, "channel was accepted as given");
205 add_trace("connect", "channel", "%d", p_m_b_channel);
207 p_m_b_exclusive = 1; // we are done
208 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
212 /* if channel value is faulty */
215 add_trace("conclusion", NULL, "illegal reply");
217 ret = -111; // protocol error
221 /* if channel was not accepted, try to get it */
222 ret = seize_bchannel(channel, 1); // exclusively
223 add_trace("channel", "available", ret<0?"no":"yes");
226 add_trace("conclusion", NULL, "replied channel not available");
230 add_trace("conclusion", NULL, "replied channel accepted");
231 add_trace("connect", "channel", "%d", p_m_b_channel);
234 /* activate channel given by remote */
235 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
239 /*** we sent 'any channel acceptable' ***/
241 /* if not first reply, we are done */
242 if (p_state != PORT_STATE_OUT_SETUP)
245 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
246 add_trace("channel", "request", "any");
247 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
248 /* if no channel was replied */
251 add_trace("conclusion", NULL, "no channel, protocol error");
253 ret = -111; // protocol error
257 /* we will see, if our received channel is available */
258 ret = seize_bchannel(channel, 1); // exclusively
259 add_trace("channel", "available", ret<0?"no":"yes");
262 add_trace("conclusion", NULL, "replied channel not available");
266 add_trace("conclusion", NULL, "replied channel accepted");
267 add_trace("connect", "channel", "%d", p_m_b_channel);
270 /* activate channel given by remote */
271 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
274 /*** we sent 'no channel available' ***/
276 /* if not the first reply, but a connect, we are forced */
278 if (cmd==MT_CONNECT && p_state!=PORT_STATE_OUT_SETUP)
280 if (prim==(CC_CONNECT | INDICATION) && p_state!=PORT_STATE_OUT_SETUP)
283 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (connect)", DIRECTION_NONE);
284 add_trace("channel", "request", "no-channel");
285 add_trace("channel", "reply", (channel>=0)?"%d%s":"(none)", channel, exclusive?" (forced)":"");
288 goto use_from_connect;
290 ret = seize_bchannel(CHANNEL_ANY, 0); // any channel
291 add_trace("channel", "available", ret<0?"no":"yes");
294 add_trace("conclusion", NULL, "no channel available during call-waiting");
298 add_trace("conclusion", NULL, "using channel %d", p_m_b_channel);
299 add_trace("connect", "channel", "%d", p_m_b_channel);
301 p_m_b_exclusive = 1; // we are done
303 /* activate channel given by remote */
304 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
308 /* if not first reply, we are done */
309 if (p_state != PORT_STATE_OUT_SETUP)
312 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (first reply to setup)", DIRECTION_NONE);
313 add_trace("channel", "request", "no-channel");
314 add_trace("channel", "reply", (channel>=0)?"%d":"(none)", channel);
315 /* if first reply has no channel, we are done */
318 add_trace("conclusion", NULL, "no channel until connect");
323 /* we will see, if our received channel is available */
325 ret = seize_bchannel(channel, exclusive);
326 add_trace("channel", "available", ret<0?"no":"yes");
329 add_trace("conclusion", NULL, "replied channel not available");
333 add_trace("conclusion", NULL, "replied channel accepted");
334 add_trace("connect", "channel", "%d", p_m_b_channel);
336 p_m_b_exclusive = 1; // we are done
338 /* activate channel given by remote */
339 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
345 * NOTE: we send MT_RELEASE_COMPLETE to "REJECT" the channel
346 * in response to the setup reply
349 l3m = create_l3msg();
351 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
352 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
354 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
356 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
358 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
362 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
364 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
366 new_state(PORT_STATE_RELEASE);
368 return(-34); /* to epoint: no channel available */
373 * hunt bchannel for incoming setup or retrieve or resume
375 int Pdss1::hunt_bchannel(int channel, int exclusive)
377 struct select_channel *selchannel;
378 struct interface_port *ifport = p_m_mISDNport->ifport;
381 chan_trace_header(p_m_mISDNport, this, "CHANNEL SELECTION (setup)", DIRECTION_NONE);
384 if (channel == CHANNEL_NO)
385 add_trace("channel", "request", "no-channel");
387 add_trace("channel", "request", (channel>0)?"%d%s":"any", channel, exclusive?" (forced)":"");
388 if (channel==CHANNEL_NO && p_type==PORT_TYPE_DSS1_TE_IN)
390 add_trace("conclusion", NULL, "incoming call-waiting not supported for TE-mode");
392 return(-6); // channel unacceptable
394 if (channel <= 0) /* not given, no channel, whatever.. */
395 channel = CHANNEL_ANY; /* any channel */
396 add_trace("channel", "reserved", "%d", p_m_mISDNport->b_reserved);
397 if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num) // of out chan..
399 add_trace("conclusion", NULL, "all channels are reserved");
401 return(-34); // no channel
403 if (channel == CHANNEL_ANY)
407 /* check for given channel in selection list */
408 selchannel = ifport->in_channel;
411 if (selchannel->channel == channel || selchannel->channel == CHANNEL_FREE)
413 selchannel = selchannel->next;
418 /* exclusive channel requests must be in the list */
423 add_trace("conclusion", NULL, "exclusively requested channel not in list");
425 return(-6); // channel unacceptable
427 i = selchannel->channel-1-(selchannel->channel>=17);
428 if (p_m_mISDNport->b_port[i] == NULL)
430 add_trace("conclusion", NULL, "exclusively requested channel is busy");
432 return(-6); // channel unacceptable
435 /* requested channels in list will be used */
438 i = selchannel->channel-1-(selchannel->channel>=17);
439 if (p_m_mISDNport->b_port[i] == NULL)
443 /* if channel is not available or not in list, it must be searched */
445 /* check for first free channel in list */
447 selchannel = ifport->in_channel;
450 switch(selchannel->channel)
452 case CHANNEL_FREE: /* free channel */
453 add_trace("hunting", "channel", "free");
454 if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num)
455 break; /* all channel in use or reserverd */
458 while(i < p_m_mISDNport->b_num)
460 if (p_m_mISDNport->b_port[i] == NULL)
462 channel = i+1+(i>=15);
470 add_trace("hunting", "channel", "%d", selchannel->channel);
471 if (selchannel->channel<1 || selchannel->channel==16)
472 break; /* invalid channels */
473 i = selchannel->channel-1-(selchannel->channel>=17);
474 if (i >= p_m_mISDNport->b_num)
475 break; /* channel not in port */
476 if (p_m_mISDNport->b_port[i] == NULL)
478 channel = selchannel->channel;
484 break; /* found channel */
485 selchannel = selchannel->next;
489 add_trace("conclusion", NULL, "no channel available");
491 return(-6); // channel unacceptable
495 add_trace("conclusion", NULL, "channel available");
496 add_trace("connect", "channel", "%d", channel);
502 * handles all indications
504 /* CC_SETUP INDICATION */
506 void Pdss1::setup_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
509 void Pdss1::setup_ind(unsigned long prim, unsigned long dinfo, void *data)
511 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
513 SETUP_t *setup = (SETUP_t *)((unsigned long)data + headerlen);
515 int calling_type, calling_plan, calling_present, calling_screen;
516 int called_type, called_plan;
517 int redir_type, redir_plan, redir_present, redir_screen, redir_reason;
518 int hlc_coding, hlc_presentation, hlc_interpretation, hlc_hlc, hlc_exthlc;
519 int bearer_coding, bearer_capability, bearer_mode, bearer_rate, bearer_multi, bearer_user;
520 int exclusive, channel;
522 unsigned char keypad[32] = "";
523 unsigned char useruser[128];
524 int useruser_len = 0, useruser_protocol;
525 class Endpoint *epoint;
526 struct lcr_msg *message;
529 /* process given callref */
530 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_IND, DIRECTION_IN);
531 add_trace("callref", "new", "0x%x", pid);
534 /* release in case the ID is already in use */
535 add_trace("error", NULL, "callref already in use");
537 l3m = create_l3msg();
538 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
539 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47);
540 add_trace("reason", NULL, "callref already in use");
542 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, pid, l3m);
543 new_state(PORT_STATE_RELEASE);
548 p_m_d_ces = pid >> 16;
551 /* callref from nt-lib */
554 /* nt-library now gives us the id via CC_SETUP */
555 if (dinfo&(~0xff) == 0xff00)
556 FATAL("l3-stack gives us a process id 0xff00-0xffff\n");
557 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_CR_IND, DIRECTION_IN);
559 add_trace("callref", "old", "0x%x", p_m_d_l3id);
560 add_trace("callref", "new", "0x%x", dinfo);
562 if (p_m_d_l3id&(~0xff) == 0xff00)
563 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
565 p_m_d_ces = setup->ces;
569 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_IND, DIRECTION_IN);
571 dec_ie_calling_pn(l3m, &calling_type, &calling_plan, &calling_present, &calling_screen, (unsigned char *)p_callerinfo.id, sizeof(p_callerinfo.id));
572 dec_ie_called_pn(l3m, &called_type, &called_plan, (unsigned char *)p_dialinginfo.id, sizeof(p_dialinginfo.id));
573 dec_ie_keypad(l3m, (unsigned char *)keypad, sizeof(keypad));
574 /* te-mode: CNIP (calling name identification presentation) */
576 dec_facility_centrex(l3m, (unsigned char *)p_callerinfo.name, sizeof(p_callerinfo.name));
577 dec_ie_useruser(l3m, &useruser_protocol, useruser, &useruser_len);
578 dec_ie_complete(l3m, &p_dialinginfo.sending_complete);
579 dec_ie_redir_nr(l3m, &redir_type, &redir_plan, &redir_present, &redir_screen, &redir_reason, (unsigned char *)p_redirinfo.id, sizeof(p_redirinfo.id));
580 dec_ie_channel_id(l3m, &exclusive, &channel);
581 dec_ie_hlc(l3m, &hlc_coding, &hlc_interpretation, &hlc_presentation, &hlc_hlc, &hlc_exthlc);
582 dec_ie_bearer(l3m, &bearer_coding, &bearer_capability, &bearer_mode, &bearer_rate, &bearer_multi, &bearer_user);
584 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));
585 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));
586 dec_ie_keypad(setup->KEYPAD, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)keypad, sizeof(keypad));
587 /* te-mode: CNIP (calling name identification presentation) */
589 dec_facility_centrex(setup->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)p_callerinfo.name, sizeof(p_callerinfo.name));
590 dec_ie_useruser(setup->USER_USER, (Q931_info_t *)((unsigned long)data+headerlen), &useruser_protocol, useruser, &useruser_len);
591 dec_ie_complete(setup->COMPLETE, (Q931_info_t *)((unsigned long)data+headerlen), &p_dialinginfo.sending_complete);
592 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));
593 dec_ie_channel_id(setup->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
594 dec_ie_hlc(setup->HLC, (Q931_info_t *)((unsigned long)data+headerlen), &hlc_coding, &hlc_interpretation, &hlc_presentation, &hlc_hlc, &hlc_exthlc);
595 dec_ie_bearer(setup->BEARER, (Q931_info_t *)((unsigned long)data+headerlen), &bearer_coding, &bearer_capability, &bearer_mode, &bearer_rate, &bearer_multi, &bearer_user);
599 /* if blocked, release call with MT_RELEASE_COMPLETE */
600 if (p_m_mISDNport->ifport->block)
603 l3m = create_l3msg();
605 RELEASE_COMPLETE_t *release_complete;
606 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
607 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
609 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
611 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 27); /* temporary unavailable */
613 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 27); /* temporary unavailable */
615 add_trace("reason", NULL, "port blocked");
618 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
620 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
622 new_state(PORT_STATE_RELEASE);
628 switch (calling_present)
631 p_callerinfo.present = INFO_PRESENT_RESTRICTED;
634 p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
637 p_callerinfo.present = INFO_PRESENT_ALLOWED;
640 switch (calling_screen)
643 p_callerinfo.screen = INFO_SCREEN_USER;
646 p_callerinfo.screen = INFO_SCREEN_NETWORK;
649 switch (calling_type)
652 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
653 p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
654 p_callerinfo.screen = INFO_SCREEN_NETWORK;
657 p_callerinfo.ntype = INFO_NTYPE_INTERNATIONAL;
660 p_callerinfo.ntype = INFO_NTYPE_NATIONAL;
663 p_callerinfo.ntype = INFO_NTYPE_SUBSCRIBER;
666 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
669 p_callerinfo.isdn_port = p_m_portnum;
670 SCPY(p_callerinfo.interface, p_m_mISDNport->ifport->interface->name);
672 /* dialing information */
673 SCAT(p_dialinginfo.id, (char *)keypad);
677 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
680 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
683 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
686 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
691 switch (redir_present)
694 p_redirinfo.present = INFO_PRESENT_RESTRICTED;
697 p_redirinfo.present = INFO_PRESENT_NOTAVAIL;
700 p_redirinfo.present = INFO_PRESENT_ALLOWED;
703 switch (redir_screen)
706 p_redirinfo.screen = INFO_SCREEN_USER;
709 p_redirinfo.screen = INFO_SCREEN_NETWORK;
712 switch (redir_reason)
715 p_redirinfo.reason = INFO_REDIR_BUSY;
718 p_redirinfo.reason = INFO_REDIR_NORESPONSE;
721 p_redirinfo.reason = INFO_REDIR_UNCONDITIONAL;
724 p_redirinfo.reason = INFO_REDIR_CALLDEFLECT;
727 p_redirinfo.reason = INFO_REDIR_OUTOFORDER;
730 p_redirinfo.reason = INFO_REDIR_UNKNOWN;
736 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
737 p_redirinfo.present = INFO_PRESENT_NULL; /* not redirecting */
738 p_redirinfo.reason = INFO_REDIR_UNKNOWN;
741 p_redirinfo.ntype = INFO_NTYPE_INTERNATIONAL;
744 p_redirinfo.ntype = INFO_NTYPE_NATIONAL;
747 p_redirinfo.ntype = INFO_NTYPE_SUBSCRIBER;
750 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
753 p_redirinfo.isdn_port = p_m_portnum;
755 /* bearer capability */
756 switch (bearer_capability)
759 p_capainfo.bearer_capa = INFO_BC_AUDIO;
760 bearer_user = (options.law=='a')?3:2;
763 p_capainfo.bearer_capa = bearer_capability;
769 p_capainfo.bearer_mode = INFO_BMODE_PACKET;
772 p_capainfo.bearer_mode = INFO_BMODE_CIRCUIT;
778 p_capainfo.bearer_info1 = INFO_INFO1_NONE;
781 p_capainfo.bearer_info1 = bearer_user + 0x80;
789 p_capainfo.hlc = INFO_HLC_NONE;
792 p_capainfo.hlc = hlc_hlc + 0x80;
798 p_capainfo.exthlc = INFO_HLC_NONE;
801 p_capainfo.exthlc = hlc_exthlc + 0x80;
806 ret = channel = hunt_bchannel(channel, exclusive);
811 ret = seize_bchannel(channel, 1);
816 * NOTE: we send MT_RELEASE_COMPLETE to "REJECT" the channel
817 * in response to the setup
820 l3m = create_l3msg();
822 RELEASE_COMPLETE_t *release_complete;
823 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
824 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
826 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
828 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
830 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
834 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
836 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
838 new_state(PORT_STATE_RELEASE);
842 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
844 /* create endpoint */
846 FATAL("Incoming call but already got an endpoint.\n");
847 if (!(epoint = new Endpoint(p_serial, 0)))
848 FATAL("No memory for Endpoint instance\n");
849 if (!(epoint->ep_app = new DEFAULT_ENDPOINT_APP(epoint, 0))) //incoming
850 FATAL("No memory for Endpoint Application instance\n");
851 epointlist_new(epoint->ep_serial);
853 /* send setup message to endpoit */
854 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_SETUP);
855 message->param.setup.isdn_port = p_m_portnum;
856 message->param.setup.port_type = p_type;
857 message->param.setup.dtmf = !p_m_mISDNport->ifport->nodtmf;
858 memcpy(&message->param.setup.dialinginfo, &p_dialinginfo, sizeof(struct dialing_info));
859 memcpy(&message->param.setup.callerinfo, &p_callerinfo, sizeof(struct caller_info));
860 memcpy(&message->param.setup.redirinfo, &p_redirinfo, sizeof(struct redir_info));
861 memcpy(&message->param.setup.capainfo, &p_capainfo, sizeof(struct capa_info));
862 memcpy(message->param.setup.useruser.data, &useruser, useruser_len);
863 message->param.setup.useruser.len = useruser_len;
864 message->param.setup.useruser.protocol = useruser_protocol;
865 message_put(message);
867 new_state(PORT_STATE_IN_SETUP);
870 /* CC_INFORMATION INDICATION */
872 void Pdss1::information_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
875 void Pdss1::information_ind(unsigned long prim, unsigned long dinfo, void *data)
877 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
878 INFORMATION_t *information = (INFORMATION_t *)((unsigned long)data + headerlen);
881 unsigned char keypad[32] = "";
882 struct lcr_msg *message;
884 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_IND, DIRECTION_IN);
886 dec_ie_called_pn(l3m, &type, &plan, (unsigned char *)p_dialinginfo.id, sizeof(p_dialinginfo.id));
887 dec_ie_keypad(l3m, (unsigned char *)keypad, sizeof(keypad));
888 dec_ie_complete(l3m, &p_dialinginfo.sending_complete);
890 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));
891 dec_ie_keypad(information->KEYPAD, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)keypad, sizeof(keypad));
892 dec_ie_complete(information->COMPLETE, (Q931_info_t *)((unsigned long)data+headerlen), &p_dialinginfo.sending_complete);
896 SCAT(p_dialinginfo.id, (char *)keypad);
900 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
903 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
906 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
909 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
912 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_INFORMATION);
913 memcpy(&message->param.information, &p_dialinginfo, sizeof(struct dialing_info));
914 message_put(message);
915 /* reset overlap timeout */
919 /* CC_SETUP_ACCNOWLEDGE INDICATION */
921 void Pdss1::setup_acknowledge_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
924 void Pdss1::setup_acknowledge_ind(unsigned long prim, unsigned long dinfo, void *data)
926 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
927 SETUP_ACKNOWLEDGE_t *setup_acknowledge = (SETUP_ACKNOWLEDGE_t *)((unsigned long)data + headerlen);
929 int exclusive, channel;
930 int coding, location, progress;
932 struct lcr_msg *message;
934 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_ACKNOWLEDGE_IND, DIRECTION_IN);
936 dec_ie_channel_id(l3m, &exclusive, &channel);
937 dec_ie_progress(l3m, &coding, &location, &progress);
939 dec_ie_channel_id(setup_acknowledge->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
940 dec_ie_progress(setup_acknowledge->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
944 /* process channel */
946 ret = received_first_reply_to_setup(cmd, channel, exclusive);
948 ret = received_first_reply_to_setup(prim, channel, exclusive);
952 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
953 message->param.disconnectinfo.cause = -ret;
954 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
955 message_put(message);
956 new_state(PORT_STATE_RELEASE);
961 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_OVERLAP);
962 message_put(message);
964 new_state(PORT_STATE_OUT_OVERLAP);
967 /* CC_PROCEEDING INDICATION */
969 void Pdss1::proceeding_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
972 void Pdss1::proceeding_ind(unsigned long prim, unsigned long dinfo, void *data)
974 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
975 CALL_PROCEEDING_t *proceeding = (CALL_PROCEEDING_t *)((unsigned long)data + headerlen);
977 int exclusive, channel;
978 int coding, location, progress;
980 struct lcr_msg *message;
981 int notify = -1, type, plan, present;
984 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_IND, DIRECTION_IN);
986 dec_ie_channel_id(l3m, &exclusive, &channel);
987 dec_ie_progress(l3m, &coding, &location, &progress);
988 dec_ie_notify(l3m, ¬ify);
989 dec_ie_redir_dn(l3m, &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
991 dec_ie_channel_id(proceeding->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
992 dec_ie_progress(proceeding->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
993 dec_ie_notify(NULL/*proceeding->NOTIFY*/, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
994 dec_ie_redir_dn(proceeding->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
999 ret = received_first_reply_to_setup(cmd, channel, exclusive);
1001 ret = received_first_reply_to_setup(prim, channel, exclusive);
1005 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1006 message->param.disconnectinfo.cause = -ret;
1007 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1008 message_put(message);
1009 new_state(PORT_STATE_RELEASE);
1013 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROCEEDING);
1014 message_put(message);
1016 new_state(PORT_STATE_OUT_PROCEEDING);
1022 if (type >= 0 || notify)
1024 if (!notify && type >= 0)
1026 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1027 message->param.notifyinfo.notify = notify;
1028 SCPY(message->param.notifyinfo.id, redir);
1029 /* redirection number */
1033 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1036 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1039 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1045 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1046 message->param.notifyinfo.present = INFO_PRESENT_NULL;
1049 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1052 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1055 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1058 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1061 message->param.notifyinfo.isdn_port = p_m_portnum;
1062 message_put(message);
1066 /* CC_ALERTING INDICATION */
1068 void Pdss1::alerting_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1071 void Pdss1::alerting_ind(unsigned long prim, unsigned long dinfo, void *data)
1073 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1074 ALERTING_t *alerting = (ALERTING_t *)((unsigned long)data + headerlen);
1076 int exclusive, channel;
1077 int coding, location, progress;
1079 struct lcr_msg *message;
1080 int notify = -1, type, plan, present;
1083 l1l2l3_trace_header(p_m_mISDNport, this, L3_ALERTING_IND, DIRECTION_IN);
1085 dec_ie_channel_id(l3m, &exclusive, &channel);
1086 dec_ie_progress(l3m, &coding, &location, &progress);
1087 dec_ie_notify(l3m, ¬ify);
1088 dec_ie_redir_dn(l3m, &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
1090 dec_ie_channel_id(alerting->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
1091 dec_ie_progress(alerting->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &location, &progress);
1092 dec_ie_notify(NULL/*alerting->NOTIFY*/, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
1093 dec_ie_redir_dn(alerting->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, (unsigned char *)redir, sizeof(redir));
1097 /* process channel */
1099 ret = received_first_reply_to_setup(cmd, channel, exclusive);
1101 ret = received_first_reply_to_setup(prim, channel, exclusive);
1105 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1106 message->param.disconnectinfo.cause = -ret;
1107 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1108 message_put(message);
1109 new_state(PORT_STATE_RELEASE);
1113 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_ALERTING);
1114 message_put(message);
1116 new_state(PORT_STATE_OUT_ALERTING);
1122 if (type >= 0 || notify)
1124 if (!notify && type >= 0)
1126 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1127 message->param.notifyinfo.notify = notify;
1128 SCPY(message->param.notifyinfo.id, redir);
1132 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1135 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1138 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1144 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1145 message->param.notifyinfo.present = INFO_PRESENT_NULL;
1148 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1151 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1154 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1157 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1160 message->param.notifyinfo.isdn_port = p_m_portnum;
1161 message_put(message);
1165 /* CC_CONNECT INDICATION */
1167 void Pdss1::connect_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1170 void Pdss1::connect_ind(unsigned long prim, unsigned long dinfo, void *data)
1172 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1174 CONNECT_t *connect = (CONNECT_t *)((unsigned long)data + headerlen);
1175 CONNECT_ACKNOWLEDGE_t *connect_acknowledge;
1177 int exclusive, channel;
1178 int type, plan, present, screen;
1180 struct lcr_msg *message;
1181 int bchannel_before;
1183 #ifndef SOCKET_MISDN
1185 p_m_d_ces = connect->ces;
1188 l1l2l3_trace_header(p_m_mISDNport, this, L3_CONNECT_IND, DIRECTION_IN);
1190 dec_ie_channel_id(l3m, &exclusive, &channel);
1191 dec_ie_connected_pn(l3m, &type, &plan, &present, &screen, (unsigned char *)p_connectinfo.id, sizeof(p_connectinfo.id));
1192 /* te-mode: CONP (connected name identification presentation) */
1194 dec_facility_centrex(l3m, (unsigned char *)p_connectinfo.name, sizeof(p_connectinfo.name));
1196 dec_ie_channel_id(connect->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
1197 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));
1198 /* te-mode: CONP (connected name identification presentation) */
1200 dec_facility_centrex(connect->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), (unsigned char *)p_connectinfo.name, sizeof(p_connectinfo.name));
1204 /* select channel */
1205 bchannel_before = p_m_b_channel;
1207 ret = received_first_reply_to_setup(cmd, channel, exclusive);
1209 ret = received_first_reply_to_setup(prim, channel, exclusive);
1213 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1214 message->param.disconnectinfo.cause = -ret;
1215 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1216 message_put(message);
1217 new_state(PORT_STATE_RELEASE);
1222 /* connect information */
1226 p_connectinfo.present = INFO_PRESENT_RESTRICTED;
1229 p_connectinfo.present = INFO_PRESENT_NOTAVAIL;
1232 p_connectinfo.present = INFO_PRESENT_ALLOWED;
1238 p_connectinfo.screen = INFO_SCREEN_USER;
1241 p_connectinfo.screen = INFO_SCREEN_NETWORK;
1247 p_connectinfo.present = INFO_PRESENT_NULL; /* no COLP info */
1248 p_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1251 p_connectinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1254 p_connectinfo.ntype = INFO_NTYPE_NATIONAL;
1257 p_connectinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1260 p_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
1263 p_connectinfo.isdn_port = p_m_portnum;
1264 SCPY(p_connectinfo.interface, p_m_mISDNport->ifport->interface->name);
1266 /* only in nt-mode we send connect ack. in te-mode it is done by stack itself or optional */
1269 /* send connect acknowledge */
1271 l3m = create_l3msg();
1273 dmsg = create_l3msg(CC_CONNECT | RESPONSE, MT_CONNECT, dinfo, sizeof(CONNECT_ACKNOWLEDGE_t), p_m_d_ntmode);
1274 connect_acknowledge = (CONNECT_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1276 l1l2l3_trace_header(p_m_mISDNport, this, L3_CONNECT_RES, DIRECTION_OUT);
1277 /* if we had no bchannel before, we send it now */
1278 if (!bchannel_before && p_m_b_channel)
1280 enc_ie_channel_id(l3m, 1, p_m_b_channel);
1282 enc_ie_channel_id(&connect_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
1286 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CONNECT_ACKNOWLEDGE, p_m_d_l3id, l3m);
1288 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1292 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CONNECT);
1293 memcpy(&message->param.connectinfo, &p_connectinfo, sizeof(struct connect_info));
1294 message_put(message);
1296 new_state(PORT_STATE_CONNECT);
1299 /* CC_DISCONNECT INDICATION */
1301 void Pdss1::disconnect_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1304 void Pdss1::disconnect_ind(unsigned long prim, unsigned long dinfo, void *data)
1306 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1307 DISCONNECT_t *disconnect = (DISCONNECT_t *)((unsigned long)data + headerlen);
1309 int location, cause;
1310 int coding, proglocation, progress;
1311 struct lcr_msg *message;
1313 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_IND, DIRECTION_IN);
1315 dec_ie_progress(l3m, &coding, &proglocation, &progress);
1316 dec_ie_cause(l3m, &location, &cause);
1318 dec_ie_progress(disconnect->PROGRESS, (Q931_info_t *)((unsigned long)data+headerlen), &coding, &proglocation, &progress);
1319 dec_ie_cause(disconnect->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1322 if (location == LOCATION_PRIVATE_LOCAL)
1323 location = LOCATION_PRIVATE_REMOTE;
1328 /* release if remote sends us no tones */
1329 if (!p_m_mISDNport->earlyb)
1339 l3m = create_l3msg();
1341 dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, dinfo, sizeof(RELEASE_t), p_m_d_ntmode);
1342 release = (RELEASE_t *)(dmsg->data + headerlen);
1344 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_REQ, DIRECTION_OUT);
1346 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16); /* normal */
1348 enc_ie_cause(&release->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16); /* normal */
1350 add_trace("reason", NULL, "no remote patterns");
1353 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE, p_m_d_l3id, l3m);
1355 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1358 /* sending release to endpoint */
1361 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1362 message->param.disconnectinfo.cause = cause;
1363 message->param.disconnectinfo.location = location;
1364 message_put(message);
1366 free_epointlist(p_epointlist);
1368 new_state(PORT_STATE_RELEASE);
1373 /* sending disconnect to active endpoint and release to inactive endpoints */
1374 if (ACTIVE_EPOINT(p_epointlist))
1376 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DISCONNECT);
1377 message->param.disconnectinfo.location = location;
1378 message->param.disconnectinfo.cause = cause;
1379 message_put(message);
1381 while(INACTIVE_EPOINT(p_epointlist))
1383 message = message_create(p_serial, INACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1384 message->param.disconnectinfo.location = location;
1385 message->param.disconnectinfo.cause = cause;
1386 message_put(message);
1388 free_epointid(INACTIVE_EPOINT(p_epointlist));
1390 new_state(PORT_STATE_IN_DISCONNECT);
1393 /* CC_DISCONNECT INDICATION */
1395 void Pdss1::disconnect_ind_i(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1398 void Pdss1::disconnect_ind_i(unsigned long prim, unsigned long dinfo, void *data)
1400 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1401 DISCONNECT_t *disconnect = (DISCONNECT_t *)((unsigned long)data + headerlen);
1403 int location, cause;
1406 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_IND, DIRECTION_IN);
1407 if (p_m_d_collect_cause > 0)
1409 add_trace("old-cause", "location", "%d", p_m_d_collect_location);
1410 add_trace("old-cause", "value", "%d", p_m_d_collect_cause);
1413 dec_ie_cause(l3m, &location, &cause);
1415 dec_ie_cause(disconnect->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1417 if (location == LOCATION_PRIVATE_LOCAL)
1418 location = LOCATION_PRIVATE_REMOTE;
1421 collect_cause(&p_m_d_collect_cause, &p_m_d_collect_location, cause, location);
1422 add_trace("new-cause", "location", "%d", p_m_d_collect_location);
1423 add_trace("new-cause", "value", "%d", p_m_d_collect_cause);
1428 /* CC_RELEASE INDICATION */
1430 void Pdss1::release_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1433 void Pdss1::release_ind(unsigned long prim, unsigned long dinfo, void *data)
1435 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1437 RELEASE_t *release = (RELEASE_t *)((unsigned long)data + headerlen);
1439 int location, cause;
1440 struct lcr_msg *message;
1442 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_IND, DIRECTION_IN);
1444 dec_ie_cause(l3m, &location, &cause);
1446 dec_ie_cause(release->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1449 if (location == LOCATION_PRIVATE_LOCAL)
1450 location = LOCATION_PRIVATE_REMOTE;
1455 /* sending release to endpoint */
1458 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1459 message->param.disconnectinfo.cause = cause;
1460 message->param.disconnectinfo.location = location;
1461 message_put(message);
1463 free_epointlist(p_epointlist);
1466 /* only in NT mode we must send release_complete, if we got a release confirm */
1468 if (cmd == MT_RELEASE)
1470 if (prim == (CC_RELEASE | CONFIRM))
1473 /* sending release complete */
1475 l3m = create_l3msg();
1477 RELEASE_COMPLETE_t *release_complete;
1478 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, dinfo, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
1479 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
1481 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
1483 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16);
1485 enc_ie_cause(&release_complete->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 16);
1489 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
1491 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1495 new_state(PORT_STATE_RELEASE);
1499 /* CC_RELEASE_COMPLETE INDICATION (a reject) */
1501 void Pdss1::release_complete_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1504 void Pdss1::release_complete_ind(unsigned long prim, unsigned long dinfo, void *data)
1506 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1507 RELEASE_COMPLETE_t *release_complete = (RELEASE_COMPLETE_t *)((unsigned long)data + headerlen);
1509 int location, cause;
1510 struct lcr_msg *message;
1512 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_IND, DIRECTION_IN);
1513 /* in case layer 2 is down during setup, we send cause 27 loc 5 */
1514 if (p_state == PORT_STATE_OUT_SETUP && !p_m_mISDNport->l1link)
1521 dec_ie_cause(l3m, &location, &cause);
1523 dec_ie_cause(release_complete->CAUSE, (Q931_info_t *)((unsigned long)data+headerlen), &location, &cause);
1525 add_trace("layer 1", NULL, (p_m_mISDNport->l1link)?"up":"down");
1528 if (location == LOCATION_PRIVATE_LOCAL)
1529 location = LOCATION_PRIVATE_REMOTE;
1534 /* sending release to endpoint */
1537 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1538 message->param.disconnectinfo.cause = cause;
1539 message->param.disconnectinfo.location = location;
1540 message_put(message);
1542 free_epointlist(p_epointlist);
1545 new_state(PORT_STATE_RELEASE);
1551 void Pdss1::t312_timeout_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1553 // not required, release is performed with MT_FREE
1556 void Pdss1::t312_timeout_ind(unsigned long prim, unsigned long dinfo, void *data)
1558 struct lcr_msg *message;
1559 // trace is done at message_isdn()
1561 /* sending release to endpoint */
1564 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
1565 if (p_m_d_collect_cause)
1567 message->param.disconnectinfo.cause = p_m_d_collect_cause;
1568 message->param.disconnectinfo.location = p_m_d_collect_location;
1571 message->param.disconnectinfo.cause = CAUSE_NOUSER;
1572 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1574 message_put(message);
1576 free_epointlist(p_epointlist);
1579 new_state(PORT_STATE_RELEASE);
1584 /* CC_NOTIFY INDICATION */
1586 void Pdss1::notify_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1589 void Pdss1::notify_ind(unsigned long prim, unsigned long dinfo, void *data)
1591 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1592 NOTIFY_t *notifying = (NOTIFY_t *)((unsigned long)data + headerlen);
1594 struct lcr_msg *message;
1595 int notify, type, plan, present;
1596 unsigned char notifyid[sizeof(message->param.notifyinfo.id)];
1598 l1l2l3_trace_header(p_m_mISDNport, this, L3_NOTIFY_IND, DIRECTION_IN);
1600 dec_ie_notify(l3m, ¬ify);
1601 dec_ie_redir_dn(l3m, &type, &plan, &present, notifyid, sizeof(notifyid));
1603 dec_ie_notify(notifying->NOTIFY, (Q931_info_t *)((unsigned long)data+headerlen), ¬ify);
1604 dec_ie_redir_dn(notifying->REDIR_DN, (Q931_info_t *)((unsigned long)data+headerlen), &type, &plan, &present, notifyid, sizeof(notifyid));
1608 if (!ACTIVE_EPOINT(p_epointlist))
1610 /* notification indicator */
1614 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1615 message->param.notifyinfo.notify = notify;
1616 SCPY(message->param.notifyinfo.id, (char *)notifyid);
1617 /* redirection number */
1621 message->param.notifyinfo.present = INFO_PRESENT_RESTRICTED;
1624 message->param.notifyinfo.present = INFO_PRESENT_NOTAVAIL;
1627 message->param.notifyinfo.present = INFO_PRESENT_ALLOWED;
1633 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1634 message->param.notifyinfo.present = INFO_PRESENT_NULL;
1637 message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL;
1640 message->param.notifyinfo.ntype = INFO_NTYPE_NATIONAL;
1643 message->param.notifyinfo.ntype = INFO_NTYPE_SUBSCRIBER;
1646 message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN;
1649 message->param.notifyinfo.isdn_port = p_m_portnum;
1650 message_put(message);
1654 /* CC_HOLD INDICATION */
1655 struct lcr_msg *message;
1657 void Pdss1::hold_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1660 void Pdss1::hold_ind(unsigned long prim, unsigned long dinfo, void *data)
1662 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1664 // HOLD_t *hold = (HOLD_t *)((unsigned long)data + headerlen);
1665 HOLD_REJECT_t *hold_reject;
1666 HOLD_ACKNOWLEDGE_t *hold_acknowledge;
1668 // class Endpoint *epoint;
1670 l1l2l3_trace_header(p_m_mISDNport, this, L3_HOLD_IND, DIRECTION_IN);
1673 if (!ACTIVE_EPOINT(p_epointlist) || p_m_hold)
1676 l3m = create_l3msg();
1678 dmsg = create_l3msg(CC_HOLD_REJECT | REQUEST, MT_HOLD_REJECT, dinfo, sizeof(HOLD_REJECT_t), p_m_d_ntmode);
1679 hold_reject = (HOLD_REJECT_t *)(dmsg->data + headerlen);
1681 l1l2l3_trace_header(p_m_mISDNport, this, L3_HOLD_REJECT_REQ, DIRECTION_OUT);
1683 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, p_m_hold?101:31); /* normal unspecified / incompatible state */
1685 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 */
1687 add_trace("reason", NULL, "no endpoint");
1690 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_HOLD_REJECT, p_m_d_l3id, l3m);
1692 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1698 /* notify the hold of call */
1699 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1700 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_HOLD;
1701 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1702 message_put(message);
1704 /* deactivate bchannel */
1705 chan_trace_header(p_m_mISDNport, this, "CHANNEL RELEASE (hold)", DIRECTION_NONE);
1706 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1710 /* set hold state */
1713 epoint = find_epoint_id(ACTIVE_EPOINT(p_epointlist));
1714 if (epoint && p_m_d_ntmode)
1716 p_m_timeout = p_settings.tout_hold;
1721 /* acknowledge hold */
1723 l3m = create_l3msg();
1725 dmsg = create_l3msg(CC_HOLD_ACKNOWLEDGE | REQUEST, MT_HOLD_ACKNOWLEDGE, dinfo, sizeof(HOLD_ACKNOWLEDGE_t), p_m_d_ntmode);
1726 hold_acknowledge = (HOLD_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1728 l1l2l3_trace_header(p_m_mISDNport, this, L3_HOLD_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1731 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_HOLD_ACKNOWLEDGE, p_m_d_l3id, l3m);
1733 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1738 /* CC_RETRIEVE INDICATION */
1740 void Pdss1::retrieve_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1743 void Pdss1::retrieve_ind(unsigned long prim, unsigned long dinfo, void *data)
1745 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1747 RETRIEVE_t *retrieve = (RETRIEVE_t *)((unsigned long)data + headerlen);
1748 RETRIEVE_REJECT_t *retrieve_reject;
1749 RETRIEVE_ACKNOWLEDGE_t *retrieve_acknowledge;
1751 struct lcr_msg *message;
1752 int channel, exclusive, cause;
1755 l1l2l3_trace_header(p_m_mISDNport, this, L3_RETRIEVE_IND, DIRECTION_IN);
1757 dec_ie_channel_id(l3m, &exclusive, &channel);
1759 dec_ie_channel_id(retrieve->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
1765 cause = 101; /* incompatible state */
1769 l3m = create_l3msg();
1771 dmsg = create_l3msg(CC_RETRIEVE_REJECT | REQUEST, MT_RETRIEVE_REJECT, dinfo, sizeof(RETRIEVE_REJECT_t), p_m_d_ntmode);
1772 retrieve_reject = (RETRIEVE_REJECT_t *)(dmsg->data + headerlen);
1774 l1l2l3_trace_header(p_m_mISDNport, this, L3_RETRIEVE_REJECT_REQ, DIRECTION_OUT);
1776 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, cause);
1778 enc_ie_cause(&retrieve_reject->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, cause);
1782 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RETRIEVE_REJECT, p_m_d_l3id, l3m);
1784 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1790 /* notify the retrieve of call */
1791 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1792 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_RETRIEVAL;
1793 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
1794 message_put(message);
1797 ret = channel = hunt_bchannel(channel, exclusive);
1802 ret = seize_bchannel(channel, 1);
1809 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
1811 /* set hold state */
1815 /* acknowledge retrieve */
1817 l3m = create_l3msg();
1819 dmsg = create_l3msg(CC_RETRIEVE_ACKNOWLEDGE | REQUEST, MT_RETRIEVE_ACKNOWLEDGE, dinfo, sizeof(RETRIEVE_ACKNOWLEDGE_t), p_m_d_ntmode);
1820 retrieve_acknowledge = (RETRIEVE_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1822 l1l2l3_trace_header(p_m_mISDNport, this, L3_RETRIEVE_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1824 enc_ie_channel_id(l3m, 1, p_m_b_channel);
1826 enc_ie_channel_id(&retrieve_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
1830 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RETRIEVE_ACKNOWLEDGE, p_m_d_l3id, l3m);
1832 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1836 /* CC_SUSPEND INDICATION */
1838 void Pdss1::suspend_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1841 void Pdss1::suspend_ind(unsigned long prim, unsigned long dinfo, void *data)
1843 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1845 SUSPEND_t *suspend = (SUSPEND_t *)((unsigned long)data + headerlen);
1846 SUSPEND_ACKNOWLEDGE_t *suspend_acknowledge;
1847 SUSPEND_REJECT_t *suspend_reject;
1849 struct lcr_msg *message;
1850 class Endpoint *epoint;
1851 unsigned char callid[8];
1853 int ret = -31; /* normal, unspecified */
1855 l1l2l3_trace_header(p_m_mISDNport, this, L3_SUSPEND_IND, DIRECTION_IN);
1857 dec_ie_call_id(l3m, callid, &len);
1859 dec_ie_call_id(suspend->CALL_ID, (Q931_info_t *)((unsigned long)data+headerlen), callid, &len);
1863 if (!ACTIVE_EPOINT(p_epointlist))
1867 l3m = create_l3msg();
1869 dmsg = create_l3msg(CC_SUSPEND_REJECT | REQUEST, MT_SUSPEND_REJECT, dinfo, sizeof(SUSPEND_REJECT_t), p_m_d_ntmode);
1870 suspend_reject = (SUSPEND_REJECT_t *)(dmsg->data + headerlen);
1872 l1l2l3_trace_header(p_m_mISDNport, this, L3_SUSPEND_REJECT_REQ, DIRECTION_OUT);
1874 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1876 enc_ie_cause(&suspend_reject->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
1880 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SUSPEND_REJECT, p_m_d_l3id, l3m);
1882 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1891 /* check if call id is in use */
1892 epoint = epoint_first;
1895 if (epoint->ep_park)
1897 if (epoint->ep_park_len == len)
1898 if (!memcmp(epoint->ep_park_callid, callid, len))
1900 ret = -84; /* call id in use */
1904 epoint = epoint->next;
1907 /* notify the hold of call */
1908 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
1909 message->param.notifyinfo.notify = INFO_NOTIFY_USER_SUSPENDED;
1910 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
1911 message_put(message);
1913 /* deactivate bchannel */
1914 chan_trace_header(p_m_mISDNport, this, "CHANNEL RELEASE (suspend)", DIRECTION_NONE);
1915 add_trace("disconnect", "channel", "%d", p_m_b_channel);
1919 /* sending suspend to endpoint */
1920 while (p_epointlist)
1922 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_SUSPEND);
1923 memcpy(message->param.parkinfo.callid, callid, sizeof(message->param.parkinfo.callid));
1924 message->param.parkinfo.len = len;
1925 message_put(message);
1927 free_epointlist(p_epointlist);
1930 /* sending SUSPEND_ACKNOWLEDGE */
1932 l3m = create_l3msg();
1934 dmsg = create_l3msg(CC_SUSPEND_ACKNOWLEDGE | REQUEST, MT_SUSPEND_ACKNOWLEDGE, dinfo, sizeof(SUSPEND_ACKNOWLEDGE_t), p_m_d_ntmode);
1935 suspend_acknowledge = (SUSPEND_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
1937 l1l2l3_trace_header(p_m_mISDNport, this, L3_SUSPEND_ACKNOWLEDGE_REQ, DIRECTION_OUT);
1940 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SUSPEND_ACKNOWLEDGE, p_m_d_l3id, l3m);
1942 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
1945 new_state(PORT_STATE_RELEASE);
1949 /* CC_RESUME INDICATION */
1951 void Pdss1::resume_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
1954 void Pdss1::resume_ind(unsigned long prim, unsigned long dinfo, void *data)
1956 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
1958 RESUME_t *resume = (RESUME_t *)((unsigned long)data + headerlen);
1959 RESUME_REJECT_t *resume_reject;
1960 RESUME_ACKNOWLEDGE_t *resume_acknowledge;
1962 unsigned char callid[8];
1964 int channel, exclusive;
1965 class Endpoint *epoint;
1966 struct lcr_msg *message;
1970 /* process given callref */
1971 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_IND, DIRECTION_IN);
1972 add_trace("callref", "new", "0x%x", pid);
1975 /* release is case the ID is already in use */
1976 add_trace("error", NULL, "callref already in use");
1978 l3m = create_l3msg();
1979 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_REJECT_REQ, DIRECTION_OUT);
1980 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, 47);
1981 add_trace("reason", NULL, "callref already in use");
1983 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RESUME_REJECT, pid, l3m);
1984 new_state(PORT_STATE_RELEASE);
1989 p_m_d_ces = pid >> 16;
1992 /* callref from nt-lib */
1995 /* nt-library now gives us the id via CC_RESUME */
1996 if (dinfo&(~0xff) == 0xff00)
1997 FATAL("l3-stack gives us a process id 0xff00-0xffff\n");
1998 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_CR_IND, DIRECTION_IN);
2000 add_trace("callref", "old", "0x%x", p_m_d_l3id);
2001 add_trace("callref", "new", "0x%x", dinfo);
2003 if (p_m_d_l3id&(~0xff) == 0xff00)
2004 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
2006 p_m_d_ces = resume->ces;
2010 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_IND, DIRECTION_IN);
2012 dec_ie_call_id(l3m, callid, &len);
2014 dec_ie_call_id(resume->CALL_ID, (Q931_info_t *)((unsigned long)data+headerlen), callid, &len);
2018 /* if blocked, release call */
2019 if (p_m_mISDNport->ifport->block)
2028 /* channel_id (no channel is possible in message) */
2030 channel = -1; /* any channel */
2033 ret = channel = hunt_bchannel(channel, exclusive);
2038 ret = seize_bchannel(channel, 1);
2044 l3m = create_l3msg();
2046 dmsg = create_l3msg(CC_RESUME_REJECT | REQUEST, MT_RESUME_REJECT, dinfo, sizeof(RESUME_REJECT_t), p_m_d_ntmode);
2047 resume_reject = (RESUME_REJECT_t *)(dmsg->data + headerlen);
2049 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_REJECT_REQ, DIRECTION_OUT);
2051 enc_ie_cause(l3m, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
2053 enc_ie_cause(&resume_reject->CAUSE, dmsg, (p_m_mISDNport->locally)?LOCATION_PRIVATE_LOCAL:LOCATION_PRIVATE_REMOTE, -ret);
2056 add_trace("reason", NULL, "port blocked");
2059 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RESUME_REJECT, p_m_d_l3id, l3m);
2061 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2063 new_state(PORT_STATE_RELEASE);
2067 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
2069 /* create endpoint */
2071 FATAL("Incoming resume but already got an endpoint.\n");
2072 ret = -85; /* no call suspended */
2073 epoint = epoint_first;
2076 if (epoint->ep_park)
2078 ret = -83; /* suspended call exists, but this not */
2079 if (epoint->ep_park_len == len)
2080 if (!memcmp(epoint->ep_park_callid, callid, len))
2083 epoint = epoint->next;
2088 epointlist_new(epoint->ep_serial);
2089 if (!(epoint->portlist_new(p_serial, p_type, p_m_mISDNport->earlyb)))
2090 FATAL("No memory for portlist\n");
2091 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RESUME);
2092 message_put(message);
2094 /* notify the resume of call */
2095 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
2096 message->param.notifyinfo.notify = INFO_NOTIFY_USER_RESUMED;
2097 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
2098 message_put(message);
2100 /* sending RESUME_ACKNOWLEDGE */
2102 l3m = create_l3msg();
2104 dmsg = create_l3msg(CC_RESUME_ACKNOWLEDGE | REQUEST, MT_RESUME_ACKNOWLEDGE, dinfo, sizeof(RESUME_ACKNOWLEDGE_t), p_m_d_ntmode);
2105 resume_acknowledge = (RESUME_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
2107 l1l2l3_trace_header(p_m_mISDNport, this, L3_RESUME_ACKNOWLEDGE_REQ, DIRECTION_OUT);
2109 enc_ie_channel_id(l3m, 1, p_m_b_channel);
2111 enc_ie_channel_id(&resume_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
2115 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RESUME_ACKNOWLEDGE, p_m_d_l3id, l3m);
2117 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2120 new_state(PORT_STATE_CONNECT);
2124 /* CC_FACILITY INDICATION */
2126 void Pdss1::facility_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
2129 void Pdss1::facility_ind(unsigned long prim, unsigned long dinfo, void *data)
2131 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2132 FACILITY_t *facility = (FACILITY_t *)((unsigned long)data + headerlen);
2134 unsigned char facil[256];
2136 struct lcr_msg *message;
2138 l1l2l3_trace_header(p_m_mISDNport, this, L3_FACILITY_IND, DIRECTION_IN);
2140 dec_ie_facility(l3m, facil, &facil_len);
2142 dec_ie_facility(facility->FACILITY, (Q931_info_t *)((unsigned long)data+headerlen), facil, &facil_len);
2150 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_FACILITY);
2151 message->param.facilityinfo.len = facil_len;
2152 memcpy(message->param.facilityinfo.data, facil, facil_len);
2153 message_put(message);
2158 * handler for isdn connections
2159 * incoming information are parsed and sent via message to the endpoint
2162 void Pdss1::message_isdn(unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
2171 PERROR("Pdss1(%s) timeout without cause.\n", p_name);
2174 if (l3m->cause[0] != 5)
2176 PERROR("Pdss1(%s) expecting timeout with timer diagnostic. (got len=%d)\n", p_name, l3m->cause[0]);
2179 timer = (l3m->cause[3]-'0')*100;
2180 timer += (l3m->cause[4]-'0')*10;
2181 timer += (l3m->cause[5]-'0');
2182 l1l2l3_trace_header(p_m_mISDNport, this, L3_TIMEOUT_IND, DIRECTION_IN);
2183 add_trace("timer", NULL, "%d", timer);
2186 t312_timeout_ind(cmd, pid, l3m);
2190 if (p_state != PORT_STATE_IDLE)
2192 setup_ind(cmd, pid, l3m);
2195 case MT_INFORMATION:
2196 information_ind(cmd, pid, l3m);
2199 case MT_SETUP_ACKNOWLEDGE:
2200 if (p_state != PORT_STATE_OUT_SETUP)
2202 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received setup_acknowledge, but we are not in outgoing setup state, IGNORING.\n", p_name);
2205 setup_acknowledge_ind(cmd, pid, l3m);
2208 case MT_CALL_PROCEEDING:
2209 if (p_state != PORT_STATE_OUT_SETUP
2210 && p_state != PORT_STATE_OUT_OVERLAP)
2212 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received proceeding, but we are not in outgoing setup OR overlap state, IGNORING.\n", p_name);
2215 proceeding_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)
2223 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding state, IGNORING.\n", p_name);
2226 alerting_ind(cmd, pid, l3m);
2230 if (p_state != PORT_STATE_OUT_SETUP
2231 && p_state != PORT_STATE_OUT_OVERLAP
2232 && p_state != PORT_STATE_OUT_PROCEEDING
2233 && p_state != PORT_STATE_OUT_ALERTING)
2235 PDEBUG(DEBUG_ISDN, "Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding OR ALERTING state, IGNORING.\n", p_name);
2238 connect_ind(cmd, pid, l3m);
2239 if (p_m_d_notify_pending)
2241 /* send pending notify message during connect */
2242 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2243 message_free(p_m_d_notify_pending);
2244 p_m_d_notify_pending = NULL;
2248 case MT_CONNECT_ACKNOWLEDGE:
2249 if (p_state == PORT_STATE_CONNECT_WAITING)
2250 new_state(PORT_STATE_CONNECT);
2251 if (p_m_d_notify_pending)
2253 /* send pending notify message during connect-ack */
2254 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2255 message_free(p_m_d_notify_pending);
2256 p_m_d_notify_pending = NULL;
2261 disconnect_ind(cmd, pid, l3m);
2265 release_ind(cmd, pid, l3m);
2268 case MT_RELEASE_COMPLETE:
2269 release_complete_ind(cmd, pid, l3m);
2273 notify_ind(cmd, pid, l3m);
2277 hold_ind(cmd, pid, l3m);
2281 retrieve_ind(cmd, pid, l3m);
2285 suspend_ind(cmd, pid, l3m);
2289 resume_ind(cmd, pid, l3m);
2293 facility_ind(cmd, pid, l3m);
2297 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_L3ID_IND, DIRECTION_IN);
2298 add_trace("callref", NULL, "0x%x", p_m_d_l3id);
2303 /* sending release to endpoint in case we still have an endpoint
2304 * this is because we don't get any response if a release_complete is received (or a release in release state)
2306 while(p_epointlist) // only if not already released
2308 struct lcr_msg *message;
2309 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
2310 if (p_m_d_collect_cause)
2312 message->param.disconnectinfo.cause = p_m_d_collect_cause;
2313 message->param.disconnectinfo.location = p_m_d_collect_location;
2316 message->param.disconnectinfo.cause = CAUSE_NOUSER;
2317 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2319 message_put(message);
2321 free_epointlist(p_epointlist);
2323 new_state(PORT_STATE_RELEASE);
2328 l1l2l3_trace_header(p_m_mISDNport, this, L3_UNKNOWN, DIRECTION_IN);
2329 add_trace("unhandled", "cmd", "0x%x", cmd);
2334 void Pdss1::message_isdn(unsigned long prim, unsigned long dinfo, void *data)
2341 case CC_TIMEOUT | INDICATION:
2344 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2345 timer_hex = *((int *)(((char *)data)+headerlen));
2347 if (timer_hex==0x312 && p_m_d_ntmode)
2349 l1l2l3_trace_header(p_m_mISDNport, this, L3_TIMEOUT_IND, DIRECTION_IN);
2350 add_trace("timer", NULL, "%x", timer_hex);
2352 t312_timeout_ind(prim, dinfo, data);
2356 case CC_SETUP | INDICATION:
2357 if (p_state != PORT_STATE_IDLE)
2359 setup_ind(prim, dinfo, data);
2362 case CC_SETUP | CONFIRM:
2365 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_CR_IND, DIRECTION_IN);
2366 add_trace("callref", "old", "0x%x", p_m_d_l3id);
2367 /* nt-library now gives us a new id via CC_SETUP_CONFIRM */
2368 if ((p_m_d_l3id&0xff00) != 0xff00)
2369 PERROR(" strange setup-procid 0x%x\n", p_m_d_l3id);
2370 p_m_d_l3id = *((int *)(((u_char *)data)+ mISDNUSER_HEAD_SIZE));
2371 add_trace("callref", "new", "0x%x", p_m_d_l3id);
2376 case CC_INFORMATION | INDICATION:
2377 information_ind(prim, dinfo, data);
2380 case CC_SETUP_ACKNOWLEDGE | INDICATION:
2381 if (p_state != PORT_STATE_OUT_SETUP)
2383 PERROR("Pdss1(%s) received setup_acknowledge, but we are not in outgoing setup state, IGNORING.\n", p_name);
2386 setup_acknowledge_ind(prim, dinfo, data);
2389 case CC_PROCEEDING | INDICATION:
2390 if (p_state != PORT_STATE_OUT_SETUP
2391 && p_state != PORT_STATE_OUT_OVERLAP)
2393 PERROR("Pdss1(%s) received proceeding, but we are not in outgoing setup OR overlap state, IGNORING.\n", p_name);
2396 proceeding_ind(prim, dinfo, data);
2399 case CC_ALERTING | INDICATION:
2400 if (p_state != PORT_STATE_OUT_SETUP
2401 && p_state != PORT_STATE_OUT_OVERLAP
2402 && p_state != PORT_STATE_OUT_PROCEEDING)
2404 PERROR("Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding state, IGNORING.\n", p_name);
2407 alerting_ind(prim, dinfo, data);
2410 case CC_CONNECT | INDICATION:
2411 if (p_state != PORT_STATE_OUT_SETUP
2412 && p_state != PORT_STATE_OUT_OVERLAP
2413 && p_state != PORT_STATE_OUT_PROCEEDING
2414 && p_state != PORT_STATE_OUT_ALERTING)
2416 PERROR("Pdss1(%s) received alerting, but we are not in outgoing setup OR overlap OR proceeding OR ALERTING state, IGNORING.\n", p_name);
2419 connect_ind(prim, dinfo, data);
2420 if (p_m_d_notify_pending)
2422 /* send pending notify message during connect */
2423 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2424 message_free(p_m_d_notify_pending);
2425 p_m_d_notify_pending = NULL;
2429 case CC_CONNECT_ACKNOWLEDGE | INDICATION:
2430 case CC_CONNECT | CONFIRM:
2431 if (p_state == PORT_STATE_CONNECT_WAITING)
2432 new_state(PORT_STATE_CONNECT);
2433 if (p_m_d_notify_pending)
2435 /* send pending notify message during connect-ack */
2436 message_notify(ACTIVE_EPOINT(p_epointlist), p_m_d_notify_pending->type, &p_m_d_notify_pending->param);
2437 message_free(p_m_d_notify_pending);
2438 p_m_d_notify_pending = NULL;
2442 case CC_DISCONNECT | INDICATION:
2443 disconnect_ind(prim, dinfo, data);
2446 case CC_RELEASE | CONFIRM:
2447 case CC_RELEASE | INDICATION:
2448 release_ind(prim, dinfo, data);
2451 case CC_RELEASE_COMPLETE | INDICATION:
2452 release_complete_ind(prim, dinfo, data);
2455 case CC_RELEASE_COMPLETE | CONFIRM:
2458 case CC_NOTIFY | INDICATION:
2459 notify_ind(prim, dinfo, data);
2462 case CC_HOLD | INDICATION:
2463 hold_ind(prim, dinfo, data);
2466 case CC_RETRIEVE | INDICATION:
2467 retrieve_ind(prim, dinfo, data);
2470 case CC_SUSPEND | INDICATION:
2471 suspend_ind(prim, dinfo, data);
2474 case CC_RESUME | INDICATION:
2475 resume_ind(prim, dinfo, data);
2478 case CC_FACILITY | INDICATION:
2479 facility_ind(prim, dinfo, data);
2482 case CC_RELEASE_CR | INDICATION:
2483 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_CR_IND, DIRECTION_IN);
2484 add_trace("callref", NULL, "0x%x", p_m_d_l3id);
2488 if ((p_m_d_l3id&0xff00) == 0xff00)
2489 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
2494 //#warning remove me
2495 //PDEBUG(DEBUG_LOG, "JOLLY release cr %d\n", p_serial);
2496 /* sending release to endpoint in case we still have an endpoint
2497 * this is because we don't get any response if a release_complete is received (or a release in release state)
2501 struct lcr_msg *message;
2502 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
2503 message->param.disconnectinfo.cause = (p_m_d_collect_cause!=CAUSE_NOUSER)?p_m_d_collect_cause:CAUSE_UNSPECIFIED;
2504 message->param.disconnectinfo.location = (p_m_d_collect_cause!=CAUSE_NOUSER)?p_m_d_collect_location:LOCATION_PRIVATE_LOCAL;
2505 message_put(message);
2507 free_epointlist(p_epointlist);
2509 new_state(PORT_STATE_RELEASE);
2513 case CC_NEW_CR | INDICATION:
2514 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_CR_IND, DIRECTION_IN);
2516 add_trace("callref", "old", "0x%x", p_m_d_l3id);
2519 new_l3id = *((int *)(((u_char *)data+mISDNUSER_HEAD_SIZE)));
2520 if (((new_l3id&0xff00)!=0xff00) && ((p_m_d_l3id&0xff00)==0xff00))
2521 p_m_mISDNport->procids[p_m_d_l3id&0xff] = 0;
2526 p_m_d_l3id = new_l3id;
2527 add_trace("callref", "new", "0x%x", p_m_d_l3id);
2532 l1l2l3_trace_header(p_m_mISDNport, this, L3_UNKNOWN, DIRECTION_IN);
2533 add_trace("unhandled", "prim", "0x%x", prim);
2539 void Pdss1::new_state(int state)
2541 // class Endpoint *epoint;
2544 if (state == PORT_STATE_IN_OVERLAP)
2546 p_m_timeout = p_m_mISDNport->ifport->tout_dialing;
2549 if (state != p_state)
2551 if (state == PORT_STATE_IN_SETUP
2552 || state == PORT_STATE_OUT_SETUP
2553 || state == PORT_STATE_IN_OVERLAP
2554 || state == PORT_STATE_OUT_OVERLAP)
2556 p_m_timeout = p_m_mISDNport->ifport->tout_setup;
2559 if (state == PORT_STATE_IN_PROCEEDING
2560 || state == PORT_STATE_OUT_PROCEEDING)
2562 p_m_timeout = p_m_mISDNport->ifport->tout_proceeding;
2565 if (state == PORT_STATE_IN_ALERTING
2566 || state == PORT_STATE_OUT_ALERTING)
2568 p_m_timeout = p_m_mISDNport->ifport->tout_alerting;
2571 if (state == PORT_STATE_CONNECT
2572 || state == PORT_STATE_CONNECT_WAITING)
2576 if (state == PORT_STATE_IN_DISCONNECT
2577 || state == PORT_STATE_OUT_DISCONNECT)
2579 p_m_timeout = p_m_mISDNport->ifport->tout_disconnect;
2584 Port::new_state(state);
2591 int Pdss1::handler(void)
2595 if ((ret = PmISDN::handler()))
2598 /* handle destruction */
2599 if (p_m_delete && p_m_d_l3id==0)
2610 * handles all messages from endpoint
2612 /* MESSAGE_INFORMATION */
2613 void Pdss1::message_information(unsigned long epoint_id, int message_id, union parameter *param)
2618 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2620 INFORMATION_t *information;
2623 if (param->information.id[0]) /* only if we have something to dial */
2626 l3m = create_l3msg();
2628 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2629 information = (INFORMATION_t *)(dmsg->data + headerlen);
2631 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
2633 enc_ie_called_pn(l3m, 0, 1, (unsigned char *)param->information.id);
2635 enc_ie_called_pn(&information->CALLED_PN, dmsg, 0, 1, (unsigned char *)param->information.id);
2639 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
2641 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2651 void Pdss1::message_setup(unsigned long epoint_id, int message_id, union parameter *param)
2657 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
2659 INFORMATION_t *information;
2663 int plan, type, screen, present, reason;
2664 int capability, mode, rate, coding, user, presentation, interpretation, hlc, exthlc;
2665 int channel, exclusive;
2666 struct epoint_list *epointlist;
2668 /* release if port is blocked */
2669 if (p_m_mISDNport->ifport->block)
2671 struct lcr_msg *message;
2673 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2674 message->param.disconnectinfo.cause = 27; // temp. unavail.
2675 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2676 message_put(message);
2677 new_state(PORT_STATE_RELEASE);
2682 /* copy setup infos to port */
2683 memcpy(&p_callerinfo, ¶m->setup.callerinfo, sizeof(p_callerinfo));
2684 memcpy(&p_dialinginfo, ¶m->setup.dialinginfo, sizeof(p_dialinginfo));
2685 memcpy(&p_capainfo, ¶m->setup.capainfo, sizeof(p_capainfo));
2686 memcpy(&p_redirinfo, ¶m->setup.redirinfo, sizeof(p_redirinfo));
2687 // SCPY(&p_m_tones_dir, param->setup.ext.tones_dir);
2688 /* screen outgoing caller id */
2689 do_screen(1, p_callerinfo.id, sizeof(p_callerinfo.id), &p_callerinfo.ntype, &p_callerinfo.present, p_m_mISDNport->ifport->interface);
2691 /* only display at connect state: this case happens if endpoint is in connected mode */
2692 if (p_state==PORT_STATE_CONNECT)
2694 if (p_type!=PORT_TYPE_DSS1_NT_OUT
2695 && p_type!=PORT_TYPE_DSS1_NT_IN)
2697 if (p_callerinfo.display[0])
2699 /* sending information */
2701 l3m = create_l3msg();
2703 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
2704 information = (INFORMATION_t *)(dmsg->data + headerlen);
2706 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
2709 enc_ie_display(l3m, (unsigned char *)p_callerinfo.display);
2711 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_callerinfo.display);
2715 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
2717 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
2723 /* attach only if not already */
2724 epointlist = p_epointlist;
2727 if (epointlist->epoint_id == epoint_id)
2729 epointlist = epointlist->next;
2732 epointlist_new(epoint_id);
2738 channel = p_m_b_channel;
2739 exclusive = p_m_b_exclusive;
2741 channel = CHANNEL_ANY;
2742 /* nt-port with no channel, not reserverd */
2743 if (!p_m_b_channel && !p_m_b_reserve && p_type==PORT_TYPE_DSS1_NT_OUT)
2744 channel = CHANNEL_NO;
2748 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_REQ, DIRECTION_OUT);
2749 /* see MT_ASSIGN notes at do_layer3() */
2751 ret = p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_ASSIGN, 0, NULL);
2752 if (mt_assign_pid == 0 || ret < 0)
2754 struct lcr_msg *message;
2756 add_trace("callref", NULL, "no free id");
2758 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2759 message->param.disconnectinfo.cause = 47;
2760 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2761 message_put(message);
2762 new_state(PORT_STATE_RELEASE);
2766 p_m_d_l3id = mt_assign_pid;
2770 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_CR_REQ, DIRECTION_OUT);
2776 if (p_m_mISDNport->procids[i] == 0)
2782 struct lcr_msg *message;
2784 add_trace("callref", NULL, "no free id");
2786 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
2787 message->param.disconnectinfo.cause = 47;
2788 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
2789 message_put(message);
2790 new_state(PORT_STATE_RELEASE);
2794 p_m_mISDNport->procids[i] = 1;
2795 p_m_d_l3id = 0xff00 | i;
2799 /* if we are in te-mode, we need to create a process first */
2800 if (newteid++ > 0x7fff)
2802 p_m_d_l3id = (entity<<16) | newteid;
2803 /* preparing message */
2804 ncr.prim = CC_NEW_CR | REQUEST;
2805 ncr.addr = p_m_mISDNport->upper_id | FLG_MSG_DOWN;
2806 ncr.dinfo = p_m_d_l3id;
2809 mISDN_write(mISDNdevice, &ncr, mISDN_HEADER_LEN+ncr.len, TIMEOUT_1SEC);
2812 add_trace("callref", "new", "0x%x", p_m_d_l3id);
2815 /* preparing setup message */
2817 l3m = create_l3msg();
2819 dmsg = create_l3msg(CC_SETUP | REQUEST, MT_SETUP, p_m_d_l3id, sizeof(SETUP_t), p_m_d_ntmode);
2820 setup = (SETUP_t *)(dmsg->data + headerlen);
2822 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_REQ, DIRECTION_OUT);
2823 /* channel information */
2824 if (channel >= 0) /* it should */
2827 enc_ie_channel_id(l3m, exclusive, channel);
2829 enc_ie_channel_id(&setup->CHANNEL_ID, dmsg, exclusive, channel);
2832 /* caller information */
2834 switch (p_callerinfo.ntype)
2836 case INFO_NTYPE_INTERNATIONAL:
2839 case INFO_NTYPE_NATIONAL:
2842 case INFO_NTYPE_SUBSCRIBER:
2845 default: /* INFO_NTYPE_UNKNOWN */
2849 switch (p_callerinfo.screen)
2851 case INFO_SCREEN_USER:
2854 default: /* INFO_SCREEN_NETWORK */
2858 switch (p_callerinfo.present)
2860 case INFO_PRESENT_RESTRICTED:
2863 case INFO_PRESENT_NOTAVAIL:
2866 default: /* INFO_PRESENT_ALLOWED */
2872 enc_ie_calling_pn(l3m, type, plan, present, screen, (unsigned char *)p_callerinfo.id);
2874 enc_ie_calling_pn(&setup->CALLING_PN, dmsg, type, plan, present, screen, (unsigned char *)p_callerinfo.id);
2876 /* dialing information */
2877 if (p_dialinginfo.id[0]) /* only if we have something to dial */
2880 enc_ie_called_pn(l3m, 0, 1, (unsigned char *)p_dialinginfo.id);
2882 enc_ie_called_pn(&setup->CALLED_PN, dmsg, 0, 1, (unsigned char *)p_dialinginfo.id);
2885 /* sending complete */
2886 if (p_dialinginfo.sending_complete)
2888 enc_ie_complete(l3m, 1);
2890 enc_ie_complete(&setup->COMPLETE, dmsg, 1);
2892 /* sending user-user */
2893 if (param->setup.useruser.len)
2896 enc_ie_useruser(l3m, param->setup.useruser.protocol, param->setup.useruser.data, param->setup.useruser.len);
2898 enc_ie_useruser(&setup->USER_USER, dmsg, param->setup.useruser.protocol, param->setup.useruser.data, param->setup.useruser.len);
2901 /* redirecting number */
2903 switch (p_redirinfo.ntype)
2905 case INFO_NTYPE_INTERNATIONAL:
2908 case INFO_NTYPE_NATIONAL:
2911 case INFO_NTYPE_SUBSCRIBER:
2914 default: /* INFO_NTYPE_UNKNOWN */
2918 switch (p_redirinfo.screen)
2920 case INFO_SCREEN_USER:
2923 default: /* INFO_SCREE_NETWORK */
2927 switch (p_redirinfo.reason)
2929 case INFO_REDIR_BUSY:
2932 case INFO_REDIR_NORESPONSE:
2935 case INFO_REDIR_UNCONDITIONAL:
2938 case INFO_REDIR_CALLDEFLECT:
2941 case INFO_REDIR_OUTOFORDER:
2944 default: /* INFO_REDIR_UNKNOWN */
2948 switch (p_redirinfo.present)
2950 case INFO_PRESENT_NULL: /* no redir at all */
2957 case INFO_PRESENT_RESTRICTED:
2960 case INFO_PRESENT_NOTAVAIL:
2963 default: /* INFO_PRESENT_ALLOWED */
2967 /* sending redirecting number only in ntmode */
2968 if (type >= 0 && p_m_d_ntmode)
2970 enc_ie_redir_nr(l3m, type, plan, present, screen, reason, (unsigned char *)p_redirinfo.id);
2972 enc_ie_redir_nr(&setup->REDIR_NR, dmsg, type, plan, present, screen, reason, (unsigned char *)p_redirinfo.id);
2974 /* bearer capability */
2975 //printf("hlc=%d\n",p_capainfo.hlc);
2977 capability = p_capainfo.bearer_capa;
2978 mode = p_capainfo.bearer_mode;
2979 rate = (mode==INFO_BMODE_CIRCUIT)?0x10:0x00;
2980 switch (p_capainfo.bearer_info1)
2982 case INFO_INFO1_NONE:
2986 user = p_capainfo.bearer_info1 & 0x7f;
2990 enc_ie_bearer(l3m, coding, capability, mode, rate, -1, user);
2992 enc_ie_bearer(&setup->BEARER, dmsg, coding, capability, mode, rate, -1, user);
3000 hlc = p_capainfo.hlc & 0x7f;
3002 if (p_capainfo.exthlc)
3003 exthlc = p_capainfo.exthlc & 0x7f;
3005 enc_ie_hlc(l3m, coding, interpretation, presentation, hlc, exthlc);
3007 enc_ie_hlc(&setup->HLC, dmsg, coding, interpretation, presentation, hlc, exthlc);
3012 if (p_callerinfo.display[0] && p_m_d_ntmode)
3014 enc_ie_display(l3m, (unsigned char *)p_callerinfo.display);
3016 enc_ie_display(&setup->DISPLAY, dmsg, (unsigned char *)p_callerinfo.display);
3018 /* nt-mode: CNIP (calling name identification presentation) */
3019 // if (p_callerinfo.name[0] && p_m_d_ntmode)
3020 // enc_facility_centrex(&setup->FACILITY, dmsg, (unsigned char *)p_callerinfo.name, 1);
3023 /* send setup message now */
3025 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SETUP, p_m_d_l3id, l3m);
3027 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3030 new_state(PORT_STATE_OUT_SETUP);
3033 /* MESSAGE_FACILITY */
3034 void Pdss1::message_facility(unsigned long epoint_id, int message_id, union parameter *param)
3039 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
3041 FACILITY_t *facility;
3044 /* facility will not be sent to external lines */
3048 /* sending facility */
3050 l3m = create_l3msg();
3052 dmsg = create_l3msg(CC_FACILITY | REQUEST, MT_FACILITY, p_m_d_l3id, sizeof(FACILITY_t), p_m_d_ntmode);
3053 facility = (FACILITY_t *)(dmsg->data + headerlen);
3055 l1l2l3_trace_header(p_m_mISDNport, this, L3_FACILITY_REQ, DIRECTION_OUT);
3057 enc_ie_facility(l3m, (unsigned char *)param->facilityinfo.data, param->facilityinfo.len);
3059 enc_ie_facility(&facility->FACILITY, dmsg, (unsigned char *)param->facilityinfo.data, param->facilityinfo.len);
3063 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_FACILITY, p_m_d_l3id, l3m);
3065 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3069 /* MESSAGE_NOTIFY */
3070 void Pdss1::message_notify(unsigned long epoint_id, int message_id, union parameter *param)
3075 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
3077 INFORMATION_t *information;
3078 NOTIFY_t *notification;
3081 int plan, type = -1, present;
3083 if (param->notifyinfo.notify>INFO_NOTIFY_NONE)
3084 notify = param->notifyinfo.notify & 0x7f;
3087 if (p_state != PORT_STATE_CONNECT)
3089 /* notify only allowed in active state */
3095 switch (param->notifyinfo.ntype)
3097 case INFO_NTYPE_INTERNATIONAL:
3100 case INFO_NTYPE_NATIONAL:
3103 case INFO_NTYPE_SUBSCRIBER:
3106 default: /* INFO_NTYPE_UNKNOWN */
3110 switch (param->notifyinfo.present)
3112 case INFO_PRESENT_NULL: /* no redir at all */
3117 case INFO_PRESENT_RESTRICTED:
3120 case INFO_PRESENT_NOTAVAIL:
3123 default: /* INFO_PRESENT_ALLOWED */
3129 if (notify<0 && !param->notifyinfo.display[0])
3131 /* nothing to notify, nothing to display */
3137 if (p_state!=PORT_STATE_CONNECT)
3139 /* queue notification */
3140 if (p_m_d_notify_pending)
3141 message_free(p_m_d_notify_pending);
3142 p_m_d_notify_pending = message_create(ACTIVE_EPOINT(p_epointlist), p_serial, EPOINT_TO_PORT, message_id);
3143 memcpy(&p_m_d_notify_pending->param, param, sizeof(union parameter));
3146 /* sending notification */
3148 l3m = create_l3msg();
3150 dmsg = create_l3msg(CC_NOTIFY | REQUEST, MT_NOTIFY, p_m_d_l3id, sizeof(NOTIFY_t), p_m_d_ntmode);
3151 notification = (NOTIFY_t *)(dmsg->data + headerlen);
3153 l1l2l3_trace_header(p_m_mISDNport, this, L3_NOTIFY_REQ, DIRECTION_OUT);
3155 enc_ie_notify(l3m, notify);
3157 enc_ie_notify(¬ification->NOTIFY, dmsg, notify);
3159 /* sending redirection number only in ntmode */
3160 if (type >= 0 && p_m_d_ntmode)
3162 enc_ie_redir_dn(l3m, type, plan, present, (unsigned char *)param->notifyinfo.id);
3164 enc_ie_redir_dn(¬ification->REDIR_DN, dmsg, type, plan, present, (unsigned char *)param->notifyinfo.id);
3166 if (param->notifyinfo.display[0] && p_m_d_ntmode)
3168 enc_ie_display(l3m, (unsigned char *)param->notifyinfo.display);
3170 enc_ie_display(¬ification->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display);
3174 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_NOTIFY, p_m_d_l3id, l3m);
3176 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3179 } else if (p_m_d_ntmode)
3181 /* sending information */
3183 l3m = create_l3msg();
3185 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
3186 information = (INFORMATION_t *)(dmsg->data + headerlen);
3188 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
3190 enc_ie_display(l3m, (unsigned char *)param->notifyinfo.display);
3192 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)param->notifyinfo.display);
3196 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
3198 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3203 /* MESSAGE_OVERLAP */
3204 void Pdss1::message_overlap(unsigned long epoint_id, int message_id, union parameter *param)
3209 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
3211 SETUP_ACKNOWLEDGE_t *setup_acknowledge;
3214 /* sending setup_acknowledge */
3216 l3m = create_l3msg();
3218 dmsg = create_l3msg(CC_SETUP_ACKNOWLEDGE | REQUEST, MT_SETUP_ACKNOWLEDGE, p_m_d_l3id, sizeof(SETUP_ACKNOWLEDGE_t), p_m_d_ntmode);
3219 setup_acknowledge = (SETUP_ACKNOWLEDGE_t *)(dmsg->data + headerlen);
3221 l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_ACKNOWLEDGE_REQ, DIRECTION_OUT);
3222 /* channel information */
3223 if (p_state == PORT_STATE_IN_SETUP)
3225 enc_ie_channel_id(l3m, 1, p_m_b_channel);
3227 enc_ie_channel_id(&setup_acknowledge->CHANNEL_ID, dmsg, 1, p_m_b_channel);
3229 /* progress information */
3230 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
3231 || p_capainfo.bearer_capa==INFO_BC_AUDIO
3232 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
3233 if (p_m_mISDNport->tones)
3235 enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
3237 enc_ie_progress(&setup_acknowledge->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
3241 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_SETUP_ACKNOWLEDGE, p_m_d_l3id, l3m);
3243 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3246 new_state(PORT_STATE_IN_OVERLAP);
3249 /* MESSAGE_PROCEEDING */
3250 void Pdss1::message_proceeding(unsigned long epoint_id, int message_id, union parameter *param)
3255 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
3257 CALL_PROCEEDING_t *proceeding;
3260 /* sending proceeding */
3262 l3m = create_l3msg();
3264 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
3265 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
3267 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
3268 /* channel information */
3269 if (p_state == PORT_STATE_IN_SETUP)
3271 enc_ie_channel_id(l3m, 1, p_m_b_channel);
3273 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
3275 /* progress information */
3276 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
3277 || p_capainfo.bearer_capa==INFO_BC_AUDIO
3278 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
3279 if (p_m_mISDNport->tones)
3281 enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
3283 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
3287 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
3289 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3292 new_state(PORT_STATE_IN_PROCEEDING);
3295 /* MESSAGE_ALERTING */
3296 void Pdss1::message_alerting(unsigned long epoint_id, int message_id, union parameter *param)
3301 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
3303 ALERTING_t *alerting;
3306 /* NT-MODE in setup state we must send PROCEEDING first */
3307 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
3309 /* sending proceeding */
3311 l3m = create_l3msg();
3313 CALL_PROCEEDING_t *proceeding;
3314 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
3315 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
3317 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
3318 /* channel information */
3320 enc_ie_channel_id(l3m, 1, p_m_b_channel);
3322 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
3324 /* progress information */
3325 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
3326 || p_capainfo.bearer_capa==INFO_BC_AUDIO
3327 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
3329 enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
3331 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
3335 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
3337 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3339 new_state(PORT_STATE_IN_PROCEEDING);
3342 /* sending alerting */
3344 l3m = create_l3msg();
3346 dmsg = create_l3msg(CC_ALERTING | REQUEST, MT_ALERTING, p_m_d_l3id, sizeof(ALERTING_t), p_m_d_ntmode);
3347 alerting = (ALERTING_t *)(dmsg->data + headerlen);
3349 l1l2l3_trace_header(p_m_mISDNport, this, L3_ALERTING_REQ, DIRECTION_OUT);
3350 /* channel information */
3351 if (p_state == PORT_STATE_IN_SETUP)
3353 enc_ie_channel_id(l3m, 1, p_m_b_channel);
3355 enc_ie_channel_id(&alerting->CHANNEL_ID, dmsg, 1, p_m_b_channel);
3357 /* progress information */
3358 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
3359 || p_capainfo.bearer_capa==INFO_BC_AUDIO
3360 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
3361 if (p_m_mISDNport->tones)
3363 enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
3365 enc_ie_progress(&alerting->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
3369 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_ALERTING, p_m_d_l3id, l3m);
3371 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3374 new_state(PORT_STATE_IN_ALERTING);
3377 /* MESSAGE_CONNECT */
3378 void Pdss1::message_connect(unsigned long epoint_id, int message_id, union parameter *param)
3383 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
3385 INFORMATION_t *information;
3388 int type, plan, present, screen;
3389 class Endpoint *epoint;
3391 /* NT-MODE in setup state we must send PROCEEDING first */
3392 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
3394 /* sending proceeding */
3396 l3m = create_l3msg();
3398 CALL_PROCEEDING_t *proceeding;
3399 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
3400 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
3402 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
3403 /* channel information */
3405 enc_ie_channel_id(l3m, 1, p_m_b_channel);
3407 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
3409 // /* progress information */
3410 // if (p_capainfo.bearer_capa==INFO_BC_SPEECH
3411 // || p_capainfo.bearer_capa==INFO_BC_AUDIO
3412 // || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
3414 // enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
3416 // enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
3420 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
3422 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3424 new_state(PORT_STATE_IN_PROCEEDING);
3427 /* copy connected information */
3428 memcpy(&p_connectinfo, ¶m->connectinfo, sizeof(p_connectinfo));
3429 /* screen outgoing caller id */
3430 do_screen(1, p_connectinfo.id, sizeof(p_connectinfo.id), &p_connectinfo.ntype, &p_connectinfo.present, p_m_mISDNport->ifport->interface);
3432 /* only display at connect state */
3433 if (p_state == PORT_STATE_CONNECT)
3434 if (p_connectinfo.display[0])
3436 /* sending information */
3438 l3m = create_l3msg();
3440 dmsg = create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, p_m_d_l3id, sizeof(INFORMATION_t), p_m_d_ntmode);
3441 information = (INFORMATION_t *)(dmsg->data + headerlen);
3443 l1l2l3_trace_header(p_m_mISDNport, this, L3_INFORMATION_REQ, DIRECTION_OUT);
3446 enc_ie_display(l3m, (unsigned char *)p_connectinfo.display);
3448 enc_ie_display(&information->DISPLAY, dmsg, (unsigned char *)p_connectinfo.display);
3452 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_INFORMATION, p_m_d_l3id, l3m);
3454 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3459 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)
3461 /* connect command only possible in setup, proceeding or alerting state */
3465 /* preparing connect message */
3467 l3m = create_l3msg();
3469 dmsg = create_l3msg(CC_CONNECT | REQUEST, MT_CONNECT, p_m_d_l3id, sizeof(CONNECT_t), p_m_d_ntmode);
3470 connect = (CONNECT_t *)(dmsg->data + headerlen);
3472 l1l2l3_trace_header(p_m_mISDNport, this, L3_CONNECT_REQ, DIRECTION_OUT);
3473 /* connect information */
3475 switch (p_connectinfo.ntype)
3477 case INFO_NTYPE_INTERNATIONAL:
3480 case INFO_NTYPE_NATIONAL:
3483 case INFO_NTYPE_SUBSCRIBER:
3486 default: /* INFO_NTYPE_UNKNOWN */
3490 switch (param->connectinfo.screen)
3492 case INFO_SCREEN_USER:
3495 default: /* INFO_SCREE_NETWORK */
3499 switch (p_connectinfo.present)
3501 case INFO_PRESENT_NULL: /* no colp at all */
3507 case INFO_PRESENT_RESTRICTED:
3510 case INFO_PRESENT_NOTAVAIL:
3513 default: /* INFO_PRESENT_ALLOWED */
3519 enc_ie_connected_pn(l3m, type, plan, present, screen, (unsigned char *)p_connectinfo.id);
3521 enc_ie_connected_pn(&connect->CONNECT_PN, dmsg, type, plan, present, screen, (unsigned char *)p_connectinfo.id);
3524 if (p_connectinfo.display[0] && p_m_d_ntmode)
3526 enc_ie_display(l3m, (unsigned char *)p_connectinfo.display);
3528 enc_ie_display(&connect->DISPLAY, dmsg, (unsigned char *)p_connectinfo.display);
3530 /* nt-mode: CONP (connected name identification presentation) */
3531 // if (p_connectinfo.name[0] && p_m_d_ntmode)
3532 // enc_facility_centrex(&connect->FACILITY, dmsg, (unsigned char *)p_connectinfo.name, 0);
3536 epoint = find_epoint_id(epoint_id);
3538 enc_ie_date(l3m, now, p_settings.no_seconds);
3540 enc_ie_date(&connect->DATE, dmsg, now, p_settings.no_seconds);
3544 /* finally send message */
3546 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CONNECT, p_m_d_l3id, l3m);
3548 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3552 new_state(PORT_STATE_CONNECT);
3554 new_state(PORT_STATE_CONNECT_WAITING);
3558 /* MESSAGE_DISCONNECT */
3559 void Pdss1::message_disconnect(unsigned long epoint_id, int message_id, union parameter *param)
3564 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
3566 DISCONNECT_t *disconnect;
3567 RELEASE_COMPLETE_t *release_complete;
3569 struct lcr_msg *message;
3572 /* we reject during incoming setup when we have no tones. also if we are in outgoing setup state */
3573 // if ((p_state==PORT_STATE_IN_SETUP && !p_m_mISDNport->tones)
3574 if (/* ||*/ p_state==PORT_STATE_OUT_SETUP)
3576 /* sending release to endpoint */
3579 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
3580 message->param.disconnectinfo.cause = 16;
3581 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
3582 message_put(message);
3584 free_epointlist(p_epointlist);
3586 /* sending release */
3588 l3m = create_l3msg();
3590 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
3591 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
3593 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_COMPLETE_REQ, DIRECTION_OUT);
3596 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
3598 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);
3602 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
3604 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3606 new_state(PORT_STATE_RELEASE);
3611 /* workarround: NT-MODE in setup state we must send PROCEEDING first to make it work */
3612 if (p_state==PORT_STATE_IN_SETUP)
3614 /* sending proceeding */
3616 l3m = create_l3msg();
3618 CALL_PROCEEDING_t *proceeding;
3619 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
3620 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
3622 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
3623 /* channel information */
3625 enc_ie_channel_id(l3m, 1, p_m_b_channel);
3627 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
3629 /* progress information */
3630 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
3631 || p_capainfo.bearer_capa==INFO_BC_AUDIO
3632 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
3634 enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
3636 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
3640 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
3642 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3644 new_state(PORT_STATE_IN_PROCEEDING);
3647 /* sending disconnect */
3649 l3m = create_l3msg();
3651 dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode);
3652 disconnect = (DISCONNECT_t *)(dmsg->data + headerlen);
3654 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_REQ, DIRECTION_OUT);
3655 /* progress information */
3656 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
3657 || p_capainfo.bearer_capa==INFO_BC_AUDIO
3658 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
3659 if (p_m_mISDNport->tones)
3661 enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
3663 enc_ie_progress(&disconnect->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
3667 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
3669 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);
3672 if (param->disconnectinfo.display[0])
3673 p = param->disconnectinfo.display;
3674 if (p) if (*p && p_m_d_ntmode)
3676 enc_ie_display(l3m, (unsigned char *)p);
3678 enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p);
3682 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_DISCONNECT, p_m_d_l3id, l3m);
3684 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3686 new_state(PORT_STATE_OUT_DISCONNECT);
3689 /* MESSAGE_RELEASE */
3690 void Pdss1::message_release(unsigned long epoint_id, int message_id, union parameter *param)
3695 int headerlen = (p_m_d_ntmode)?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
3698 RELEASE_COMPLETE_t *release_complete;
3699 DISCONNECT_t *disconnect;
3701 class Endpoint *epoint;
3705 * we may only release during incoming disconnect state.
3706 * this means that the endpoint doesnt require audio anymore
3708 if (p_state == PORT_STATE_IN_DISCONNECT
3709 || p_state == PORT_STATE_OUT_DISCONNECT)
3711 /* sending release */
3713 l3m = create_l3msg();
3715 dmsg = create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, p_m_d_l3id, sizeof(RELEASE_t), p_m_d_ntmode);
3716 release = (RELEASE_t *)(dmsg->data + headerlen);
3718 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_REQ, DIRECTION_OUT);
3721 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
3723 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);
3727 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE, p_m_d_l3id, l3m);
3729 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3731 new_state(PORT_STATE_RELEASE);
3733 free_epointid(epoint_id);
3734 // wait for callref to be released
3739 * if we are on incoming call setup, we may reject by sending a release_complete
3740 * also on outgoing call setup, we send a release complete, BUT this is not conform. (i don't know any other way)
3742 if (p_state==PORT_STATE_IN_SETUP
3743 || p_state==PORT_STATE_OUT_SETUP)
3744 // // NOTE: a bug in mISDNuser (see disconnect_req_out !!!)
3745 // || p_state==PORT_STATE_OUT_DISCO)
3747 //#warning remove me
3748 //PDEBUG(DEBUG_LOG, "JOLLY sending release complete %d\n", p_serial);
3749 /* sending release complete */
3751 l3m = create_l3msg();
3753 dmsg = create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, p_m_d_l3id, sizeof(RELEASE_COMPLETE_t), p_m_d_ntmode);
3754 release_complete = (RELEASE_COMPLETE_t *)(dmsg->data + headerlen);
3756 l1l2l3_trace_header(p_m_mISDNport, this, L3_RELEASE_REQ, DIRECTION_OUT);
3759 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
3761 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);
3765 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_RELEASE_COMPLETE, p_m_d_l3id, l3m);
3767 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3769 new_state(PORT_STATE_RELEASE);
3771 free_epointid(epoint_id);
3772 // wait for callref to be released
3777 wirklich erst proceeding?:
3778 /* NT-MODE in setup state we must send PROCEEDING first */
3779 if (p_m_d_ntmode && p_state==PORT_STATE_IN_SETUP)
3781 CALL_PROCEEDING_t *proceeding;
3783 /* sending proceeding */
3785 l3m = create_l3msg();
3787 dmsg = create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, p_m_d_l3id, sizeof(CALL_PROCEEDING_t), p_m_d_ntmode);
3788 proceeding = (CALL_PROCEEDING_t *)(dmsg->data + headerlen);
3790 l1l2l3_trace_header(p_m_mISDNport, this, L3_PROCEEDING_REQ, DIRECTION_OUT);
3791 /* channel information */
3793 enc_ie_channel_id(l3m, 1, p_m_b_channel);
3795 enc_ie_channel_id(&proceeding->CHANNEL_ID, dmsg, 1, p_m_b_channel);
3797 /* progress information */
3798 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
3799 || p_capainfo.bearer_capa==INFO_BC_AUDIO
3800 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
3802 enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
3804 enc_ie_progress(&proceeding->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
3808 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_CALL_PROCEEDING, p_m_d_l3id, l3m);
3810 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3815 /* sending disconnect */
3817 l3m = create_l3msg();
3819 dmsg = create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, p_m_d_l3id, sizeof(DISCONNECT_t), p_m_d_ntmode);
3820 disconnect = (DISCONNECT_t *)(dmsg->data + headerlen);
3822 l1l2l3_trace_header(p_m_mISDNport, this, L3_DISCONNECT_REQ, DIRECTION_OUT);
3823 /* progress information */
3824 if (p_capainfo.bearer_capa==INFO_BC_SPEECH
3825 || p_capainfo.bearer_capa==INFO_BC_AUDIO
3826 || p_capainfo.bearer_capa==INFO_BC_DATAUNRESTRICTED_TONES)
3827 if (p_m_mISDNport->tones)
3829 enc_ie_progress(l3m, 0, p_m_d_ntmode?1:5, 8);
3831 enc_ie_progress(&disconnect->PROGRESS, dmsg, 0, p_m_d_ntmode?1:5, 8);
3835 enc_ie_cause(l3m, (p_m_mISDNport->locally && param->disconnectinfo.location==LOCATION_PRIVATE_LOCAL)?LOCATION_PRIVATE_LOCAL:param->disconnectinfo.location, param->disconnectinfo.cause);
3837 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);
3840 epoint = find_epoint_id(epoint_id);
3841 if (param->disconnectinfo.display[0])
3842 p = param->disconnectinfo.display;
3843 if (p) if (*p && p_m_d_ntmode)
3845 enc_ie_display(l3m, (unsigned char *)p);
3847 enc_ie_display(&disconnect->DISPLAY, dmsg, (unsigned char *)p);
3851 p_m_mISDNport->ml3->to_layer3(p_m_mISDNport->ml3, MT_DISCONNECT, p_m_d_l3id, l3m);
3853 msg_queue_tail(&p_m_mISDNport->downqueue, dmsg);
3855 new_state(PORT_STATE_OUT_DISCONNECT);
3857 free_epointid(epoint_id);
3858 // wait for release and callref to be released
3859 //#warning remove me
3860 //PDEBUG(DEBUG_LOG, "JOLLY sending disconnect %d\n", p_serial);
3865 * endpoint sends messages to the port
3867 int Pdss1::message_epoint(unsigned long epoint_id, int message_id, union parameter *param)
3869 struct lcr_msg *message;
3871 if (PmISDN::message_epoint(epoint_id, message_id, param))
3876 case MESSAGE_INFORMATION: /* overlap dialing */
3877 if (p_type==PORT_TYPE_DSS1_NT_OUT
3878 && p_state!=PORT_STATE_OUT_OVERLAP
3879 && p_state!=PORT_STATE_CONNECT
3880 && p_state!=PORT_STATE_OUT_DISCONNECT
3881 && p_state!=PORT_STATE_IN_DISCONNECT)
3885 if (p_type==PORT_TYPE_DSS1_TE_OUT
3886 && p_state!=PORT_STATE_OUT_OVERLAP
3887 && p_state!=PORT_STATE_OUT_PROCEEDING
3888 && p_state!=PORT_STATE_OUT_ALERTING
3889 && p_state!=PORT_STATE_CONNECT
3890 && p_state!=PORT_STATE_OUT_DISCONNECT
3891 && p_state!=PORT_STATE_IN_DISCONNECT)
3895 if ((p_type==PORT_TYPE_DSS1_NT_IN || p_type==PORT_TYPE_DSS1_TE_IN)
3896 && p_state!=PORT_STATE_IN_OVERLAP
3897 && p_state!=PORT_STATE_IN_PROCEEDING
3898 && p_state!=PORT_STATE_IN_ALERTING
3899 && p_state!=PORT_STATE_CONNECT
3900 && p_state!=PORT_STATE_CONNECT_WAITING
3901 && p_state!=PORT_STATE_OUT_DISCONNECT
3902 && p_state!=PORT_STATE_IN_DISCONNECT)
3906 message_information(epoint_id, message_id, param);
3909 case MESSAGE_SETUP: /* dial-out command received from epoint */
3910 if (p_state!=PORT_STATE_IDLE
3911 && p_state!=PORT_STATE_CONNECT)
3913 PERROR("Pdss1(%s) ignoring setup because isdn port is not in idle state (or connected for sending display info).\n", p_name);
3916 if (p_epointlist && p_state==PORT_STATE_IDLE)
3917 FATAL("Pdss1(%s): epoint pointer is set in idle state, how bad!!\n", p_name);
3919 message_setup(epoint_id, message_id, param);
3921 /* note: pri is a special case, because links must be up for pri */
3922 if (p_m_mISDNport->l1link || p_m_mISDNport->pri || !p_m_mISDNport->ntmode || p_state!=PORT_STATE_IDLE)
3924 /* LAYER 1 is up, or we may send */
3925 message_setup(epoint_id, message_id, param);
3928 /* LAYER 1 id down, so we queue */
3929 p_m_d_queue = message_create(epoint_id, p_serial, EPOINT_TO_PORT, message_id);
3930 memcpy(&p_m_d_queue->param, param, sizeof(union parameter));
3932 if (!(epointlist_new(epoint_id)))
3933 FATAL("No memory for epointlist\n");
3935 PDEBUG(DEBUG_ISDN, "the L1 is down, we try to establish the link NT portnum=%d (%s).\n", p_m_mISDNport->portnum, p_name);
3936 act.prim = PH_ACTIVATE | REQUEST;
3937 act.addr = p_m_mISDNport->upper_id | FLG_MSG_DOWN;
3940 mISDN_write(mISDNdevice, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
3941 l1l2l3_trace_header(p_m_mISDNport, this, L1_ACTIVATE_REQ, DIRECTION_OUT);
3943 // /* set timeout */
3944 // p_m_mISDNport->l1timeout = now+3;
3949 case MESSAGE_NOTIFY: /* display and notifications */
3950 message_notify(epoint_id, message_id, param);
3953 case MESSAGE_FACILITY: /* facility message */
3954 message_facility(epoint_id, message_id, param);
3957 case MESSAGE_OVERLAP: /* more information is needed */
3958 if (p_state!=PORT_STATE_IN_SETUP)
3962 message_overlap(epoint_id, message_id, param);
3965 case MESSAGE_PROCEEDING: /* call of endpoint is proceeding */
3966 if (p_state!=PORT_STATE_IN_SETUP
3967 && p_state!=PORT_STATE_IN_OVERLAP)
3971 message_proceeding(epoint_id, message_id, param);
3974 case MESSAGE_ALERTING: /* call of endpoint is ringing */
3975 if (p_state!=PORT_STATE_IN_SETUP
3976 && p_state!=PORT_STATE_IN_OVERLAP
3977 && p_state!=PORT_STATE_IN_PROCEEDING)
3981 message_alerting(epoint_id, message_id, param);
3984 case MESSAGE_CONNECT: /* call of endpoint is connected */
3985 if (p_state!=PORT_STATE_IN_SETUP
3986 && p_state!=PORT_STATE_IN_OVERLAP
3987 && p_state!=PORT_STATE_IN_PROCEEDING
3988 && p_state!=PORT_STATE_IN_ALERTING
3989 && !(p_state==PORT_STATE_CONNECT && p_m_d_ntmode))
3993 message_connect(epoint_id, message_id, param);
3996 case MESSAGE_DISCONNECT: /* call has been disconnected */
3997 if (p_state!=PORT_STATE_IN_SETUP
3998 && p_state!=PORT_STATE_IN_OVERLAP
3999 && p_state!=PORT_STATE_IN_PROCEEDING
4000 && p_state!=PORT_STATE_IN_ALERTING
4001 && p_state!=PORT_STATE_OUT_SETUP
4002 && p_state!=PORT_STATE_OUT_OVERLAP
4003 && p_state!=PORT_STATE_OUT_PROCEEDING
4004 && p_state!=PORT_STATE_OUT_ALERTING
4005 && p_state!=PORT_STATE_CONNECT
4006 && p_state!=PORT_STATE_CONNECT_WAITING)
4010 message_disconnect(epoint_id, message_id, param);
4013 case MESSAGE_RELEASE: /* release isdn port */
4014 if (p_state==PORT_STATE_RELEASE)
4018 message_release(epoint_id, message_id, param);
4022 PERROR("Pdss1(%s) isdn port with (caller id %s) received a wrong message: %d\n", p_name, p_callerinfo.id, message);
4031 * data from isdn-stack (layer-3) to pbx (port class)
4034 int stack2manager(struct mISDNport *mISDNport, unsigned int cmd, unsigned int pid, struct l3_msg *l3m)
4040 PDEBUG(DEBUG_ISDN, "cmd(0x%x) pid(0x%x)\n", cmd, pid);
4044 PDEBUG(DEBUG_ISDN, "ignoring dummy process from phone.\n");
4048 /* find Port object of type ISDN */
4053 if ((port->p_type & PORT_CLASS_mISDN_MASK) == PORT_CLASS_mISDN_DSS1)
4055 pdss1 = (class Pdss1 *)port;
4056 /* check out correct stack and id */
4057 if (pdss1->p_m_mISDNport == mISDNport)
4059 if (pdss1->p_m_d_l3id & MISDN_PID_CR_FLAG)
4061 /* local callref, so match value only */
4062 if ((pdss1->p_m_d_l3id & MISDN_PID_CRVAL_MASK) == (pid & MISDN_PID_CRVAL_MASK))
4066 /* remote callref, ref + channel id */
4067 if (pdss1->p_m_d_l3id == pid)
4075 /* aktueller prozess */
4078 if (cmd == MT_ASSIGN)
4080 /* stack gives us new layer 3 id (during connect) */
4081 l1l2l3_trace_header(mISDNport, pdss1, L3_NEW_L3ID_IND, DIRECTION_IN);
4082 add_trace("callref", "old", "0x%x", pdss1->p_m_d_l3id);
4083 /* nt-library now gives us a new id via CC_SETUP_CONFIRM */
4084 if ((pdss1->p_m_d_l3id&MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER)
4085 PERROR(" strange setup-procid 0x%x\n", pdss1->p_m_d_l3id);
4086 pdss1->p_m_d_l3id = pid;
4087 if (port->p_state == PORT_STATE_CONNECT)
4088 pdss1->p_m_d_ces = pid >> 16;
4089 add_trace("callref", "new", "0x%x", pdss1->p_m_d_l3id);
4093 /* if process id is master process, but a child disconnects */
4094 if (mISDNport->ntmode
4095 && (pid & MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER
4096 && (pdss1->p_m_d_l3id & MISDN_PID_CRTYPE_MASK) == MISDN_PID_MASTER)
4098 if (cmd == MT_DISCONNECT
4099 || cmd == MT_RELEASE)
4101 /* send special indication for child disconnect */
4102 pdss1->disconnect_ind_i(cmd, pid, l3m);
4105 if (cmd == MT_RELEASE_COMPLETE)
4108 /* if we have child pid and got different child pid message, ignore */
4109 if (mISDNport->ntmode
4110 && (pid & MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER
4111 && (pdss1->p_m_d_l3id & MISDN_PID_CRTYPE_MASK) != MISDN_PID_MASTER
4112 && pid != pdss1->p_m_d_l3id)
4115 /* process message */
4116 pdss1->message_isdn(cmd, pid, l3m);
4124 /* creating port object */
4125 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
4126 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0)))
4128 FATAL("Cannot create Port instance.\n");
4129 pdss1->message_isdn(cmd, pid, l3m);
4133 /* creating port object */
4134 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
4135 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0)))
4136 FATAL("Cannot create Port instance.\n");
4137 pdss1->message_isdn(cmd, pid, l3m);
4141 PDEBUG(DEBUG_ISDN, "unused call ref released (l3id=0x%x)\n", pid);
4144 case MT_RELEASE_COMPLETE:
4145 PERROR("must be ignored by stack, not sent to app\n");
4149 // facility als broadcast
4153 PERROR("unhandled message: cmd(0x%x) pid(0x%x)\n", cmd, pid);
4157 if (port->p_type == PORT_TYPE_DSS1_NT_IN || port->p_type == PORT_TYPE_DSS1_NT_OUT)
4159 pdss1 = (class Pdss1 *)port;
4160 /* check out correct stack */
4161 if (pdss1->p_m_mISDNport == mISDNport)
4162 /* check out correct id */
4163 PERROR("unhandled message: pid=%x is not associated with port-dinfo=%x\n", pid, pdss1->p_m_d_l3id);
4172 /* NOTE: nt mode use mISDNuser_head_t as header */
4173 int stack2manager_nt(void *dat, void *arg)
4177 manager_t *mgr = (manager_t *)dat;
4178 msg_t *msg = (msg_t *)arg;
4179 mISDNuser_head_t *hh;
4180 struct mISDNport *mISDNport;
4186 /* note: nst is the first data feld of mISDNport */
4187 mISDNport = (struct mISDNport *)mgr->nst;
4189 hh = (mISDNuser_head_t *)msg->data;
4190 PDEBUG(DEBUG_ISDN, "prim(0x%x) dinfo(0x%x) msg->len(%d)\n", hh->prim, hh->dinfo, msg->len);
4192 /* find Port object of type ISDN */
4196 if (port->p_type == PORT_TYPE_DSS1_NT_IN || port->p_type == PORT_TYPE_DSS1_NT_OUT)
4198 pdss1 = (class Pdss1 *)port;
4199 //PDEBUG(DEBUG_ISDN, "comparing dinfo = 0x%x with l3id 0x%x\n", hh->dinfo, pdss1->p_m_d_l3id);
4200 /* check out correct stack */
4201 if (pdss1->p_m_mISDNport == mISDNport)
4202 /* check out correct id */
4203 if ((pdss1->p_m_d_l3id&0x0000ff00) != 0x000ff00)
4205 /* a single process */
4206 if (hh->dinfo == pdss1->p_m_d_l3id)
4208 /* found port, the message belongs to */
4213 /* a broadcast process */
4214 if ((hh->dinfo&0xffff0000) == (pdss1->p_m_d_l3id&0xffff0000))
4216 /* found port, the message belongs to */
4225 //printf("%x %x\n", hh->dinfo, pdss1->p_m_d_l3id);
4226 /* if process id is master process, but a child disconnects */
4227 if ((hh->dinfo&0x0000ff00)!=0x0000ff00 && (pdss1->p_m_d_l3id&0x0000ff00)==0x0000ff00)
4229 if (hh->prim == (CC_DISCONNECT|INDICATION))
4231 /* send special indication for child disconnect */
4232 pdss1->disconnect_ind_i(hh->prim, hh->dinfo, msg->data);
4236 // ignoring other messages from child processes
4240 /* if process id and layer 3 id matches */
4241 if (hh->dinfo == pdss1->p_m_d_l3id)
4243 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
4252 case MGR_SHORTSTATUS | INDICATION:
4253 case MGR_SHORTSTATUS | CONFIRM:
4255 case SSTATUS_L2_ESTABLISHED:
4257 case SSTATUS_L2_RELEASED:
4262 case DL_ESTABLISH | INDICATION:
4263 l1l2l3_trace_header(mISDNport, NULL, L2_ESTABLISH_IND, DIRECTION_IN);
4265 case DL_ESTABLISH | CONFIRM:
4266 l1l2l3_trace_header(mISDNport, NULL, L2_ESTABLISH_CON, DIRECTION_IN);
4268 add_trace("tei", NULL, "%d", hh->dinfo);
4270 if (mISDNport->ptp && hh->dinfo == 0)
4272 if (mISDNport->l2establish)
4274 mISDNport->l2establish = 0;
4275 PDEBUG(DEBUG_ISDN, "the link became active before l2establish timer expiry.\n");
4277 mISDNport->l2link = 1;
4278 if (mISDNport->pri);
4279 mISDNport->l1link = 1; /* this is a hack, we also assume L1 to be active */
4283 case DL_RELEASE | INDICATION:
4284 l1l2l3_trace_header(mISDNport, NULL, L2_RELEASE_IND, DIRECTION_IN);
4286 case DL_RELEASE | CONFIRM:
4287 l1l2l3_trace_header(mISDNport, NULL, L2_RELEASE_CON, DIRECTION_IN);
4289 add_trace("tei", NULL, "%d", hh->dinfo);
4291 if (mISDNport->ptp && hh->dinfo == 0)
4293 mISDNport->l2link = 0;
4294 time(&mISDNport->l2establish);
4295 PDEBUG(DEBUG_ISDN, "because we are ptp, we set a l2establish timer.\n");
4299 case CC_SETUP | INDICATION:
4300 /* creating port object */
4301 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
4302 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0)))
4304 FATAL("Cannot create Port instance.\n");
4305 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
4308 case CC_RESUME | INDICATION:
4309 /* creating port object */
4310 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
4311 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_NT_IN, mISDNport, name, NULL, 0, 0)))
4312 FATAL("Cannot create Port instance.\n");
4313 pdss1->message_isdn(hh->prim, hh->dinfo, msg->data);
4316 case CC_RELEASE_CR | INDICATION:
4317 PERROR("unhandled message from stack: call ref released (l3id=0x%x)\n", hh->dinfo);
4320 case CC_RELEASE_COMPLETE | INDICATION:
4323 case CC_FACILITY | INDICATION:
4327 PERROR("unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", hh->prim, hh->dinfo, msg->len);
4331 if (port->p_type == PORT_TYPE_DSS1_NT_IN || port->p_type == PORT_TYPE_DSS1_NT_OUT)
4333 pdss1 = (class Pdss1 *)port;
4334 //PDEBUG(DEBUG_ISDN, "comparing dinfo = 0x%x with l3id 0x%x\n", hh->dinfo, pdss1->p_m_d_l3id);
4335 /* check out correct stack */
4336 if (pdss1->p_m_mISDNport == mISDNport)
4337 /* check out correct id */
4338 PERROR("unhandled message: dinfo=%x is not associated with port-dinfo=%x\n",hh->dinfo,pdss1->p_m_d_l3id);
4348 /* NOTE: te mode use iframe_t as header */
4349 int stack2manager_te(struct mISDNport *mISDNport, msg_t *msg)
4356 if (!msg || !mISDNport)
4358 frm = (iframe_t *)msg->data;
4359 PDEBUG(DEBUG_ISDN, "prim(0x%x) dinfo(0x%x) msg->len(%d)\n", frm->prim, frm->dinfo, msg->len);
4361 /* find Port object of type ISDN */
4365 if (port->p_type == PORT_TYPE_DSS1_TE_IN || port->p_type == PORT_TYPE_DSS1_TE_OUT)
4367 pdss1 = (class Pdss1 *)port;
4368 /* check out correct stack */
4369 if (pdss1->p_m_mISDNport == mISDNport)
4370 /* check out correct id */
4371 if (frm->dinfo == pdss1->p_m_d_l3id)
4373 /* found port, the message belongs to */
4381 pdss1->message_isdn(frm->prim, frm->dinfo, msg->data);
4386 /* process new cr (before setup indication) */
4387 //printf("prim = 0x%x, looking for 0x%x\n",frm->prim, (CC_NEW_CR | INDICATION));
4388 if (frm->prim == (CC_NEW_CR | INDICATION))
4391 /* creating port object */
4392 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
4393 if (!(pdss1 = new Pdss1(PORT_TYPE_DSS1_TE_IN, mISDNport, name, NULL, 0, 0)))
4394 FATAL("Cannot create Port instance.\n");
4395 /* l3id will be set from dinfo at message_isdn */
4396 pdss1->message_isdn(frm->prim, frm->dinfo, msg->data);
4401 if (frm->prim == (CC_RELEASE_CR | INDICATION))
4403 PDEBUG(DEBUG_ISDN, "unhandled message from stack: call ref released (l3id=0x%x)\n", frm->dinfo);
4407 PERROR("unhandled message: prim(0x%x) dinfo(0x%x) msg->len(%d)\n", frm->prim, frm->dinfo, msg->len);
4411 #endif // stacktomanager
4414 #ifndef SOCKET_MISDN
4416 * sending message that were queued during L1 activation
4417 * or releasing port if link is down
4419 void setup_queue(struct mISDNport *mISDNport, int link)
4423 struct lcr_msg *message;
4425 if (!mISDNport->ntmode)
4428 /* check all port objects for pending message */
4432 if ((port->p_type&PORT_CLASS_mISDN_MASK) == PORT_CLASS_mISDN_DSS1)
4434 pdss1 = (class Pdss1 *)port;
4435 if (pdss1->p_m_mISDNport == mISDNport)
4437 if (pdss1->p_m_d_queue)
4441 PDEBUG(DEBUG_ISDN, "the L1 became active, so we send queued message for portnum=%d (%s).\n", mISDNport->portnum, pdss1->p_name);
4442 /* LAYER 1 is up, so we send */
4443 pdss1->message_setup(pdss1->p_m_d_queue->id_from, pdss1->p_m_d_queue->type, &pdss1->p_m_d_queue->param);
4444 message_free(pdss1->p_m_d_queue);
4445 pdss1->p_m_d_queue = NULL;
4448 PDEBUG(DEBUG_ISDN, "the L1 became NOT active, so we release port for portnum=%d (%s).\n", mISDNport->portnum, pdss1->p_name);
4449 message = message_create(pdss1->p_serial, pdss1->p_m_d_queue->id_from, PORT_TO_EPOINT, MESSAGE_RELEASE);
4450 message->param.disconnectinfo.cause = 27;
4451 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
4452 message_put(message);
4453 pdss1->new_state(PORT_STATE_RELEASE);
4454 pdss1->p_m_delete = 1;