1 /* $Id: l3ni1.c,v 1.1.4.1 2001/11/20 14:19:36 kai Exp $
3 * NI1 D-channel protocol
5 * Author Matt Henderson & Guy Ellis
6 * Copyright by Traverse Technologies Pty Ltd, www.travers.com.au
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
11 * 2000.6.6 Initial implementation of routines for US NI1
12 * Layer 3 protocol based on the EURO/DSS1 D-channel protocol
13 * driver written by Karsten Keil et al.
14 * NI-1 Hall of Fame - Thanks to....
15 * Ragnar Paulson - for some handy code fragments
16 * Will Scales - beta tester extraordinaire
17 * Brett Whittacre - beta tester and remote devel system in Vegas
21 #define __NO_VERSION__
25 #include <linux/ctype.h>
27 extern char *HiSax_getrev(const char *revision);
28 const char *ni1_revision = "$Revision: 1.1.4.1 $";
30 #define EXT_BEARER_CAPS 1
32 #define MsgHead(ptr, cref, mty) \
43 /**********************************************/
44 /* get a new invoke id for remote operations. */
45 /* Only a return value != 0 is valid */
46 /**********************************************/
47 static unsigned char new_invoke_id(struct PStack *p)
53 i = 32; /* maximum search depth */
58 retval = p->prot.ni1.last_invoke_id + 1; /* try new id */
59 while ((i) && (p->prot.ni1.invoke_used[retval >> 3] == 0xFF)) {
60 p->prot.ni1.last_invoke_id = (retval & 0xF8) + 8;
64 while (p->prot.ni1.invoke_used[retval >> 3] & (1 << (retval & 7)))
68 p->prot.ni1.last_invoke_id = retval;
69 p->prot.ni1.invoke_used[retval >> 3] |= (1 << (retval & 7));
75 /*************************/
76 /* free a used invoke id */
77 /*************************/
78 static void free_invoke_id(struct PStack *p, unsigned char id)
79 { unsigned long flags;
81 if (!id) return; /* 0 = invalid value */
85 p->prot.ni1.invoke_used[id >> 3] &= ~(1 << (id & 7));
87 } /* free_invoke_id */
90 /**********************************************************/
91 /* create a new l3 process and fill in ni1 specific data */
92 /**********************************************************/
93 static struct l3_process
94 *ni1_new_l3_process(struct PStack *st, int cr)
95 { struct l3_process *proc;
97 if (!(proc = new_l3_process(st, cr)))
100 proc->prot.ni1.invoke_id = 0;
101 proc->prot.ni1.remote_operation = 0;
102 proc->prot.ni1.uus1_data[0] = '\0';
105 } /* ni1_new_l3_process */
107 /************************************************/
108 /* free a l3 process and all ni1 specific data */
109 /************************************************/
111 ni1_release_l3_process(struct l3_process *p)
113 free_invoke_id(p->st,p->prot.ni1.invoke_id);
114 release_l3_process(p);
115 } /* ni1_release_l3_process */
117 /********************************************************/
118 /* search a process with invoke id id and dummy callref */
119 /********************************************************/
120 static struct l3_process *
121 l3ni1_search_dummy_proc(struct PStack *st, int id)
122 { struct l3_process *pc = st->l3.proc; /* start of processes */
124 if (!id) return(NULL);
127 { if ((pc->callref == -1) && (pc->prot.ni1.invoke_id == id))
132 } /* l3ni1_search_dummy_proc */
134 /*******************************************************************/
135 /* called when a facility message with a dummy callref is received */
136 /* and a return result is delivered. id specifies the invoke id. */
137 /*******************************************************************/
139 l3ni1_dummy_return_result(struct PStack *st, int id, u_char *p, u_char nlen)
141 struct IsdnCardState *cs;
142 struct l3_process *pc = NULL;
144 if ((pc = l3ni1_search_dummy_proc(st, id)))
145 { L3DelTimer(&pc->timer); /* remove timer */
147 cs = pc->st->l1.hardware;
148 ic.driver = cs->myid;
149 ic.command = ISDN_STAT_PROT;
150 ic.arg = NI1_STAT_INVOKE_RES;
151 ic.parm.ni1_io.hl_id = pc->prot.ni1.invoke_id;
152 ic.parm.ni1_io.ll_id = pc->prot.ni1.ll_id;
153 ic.parm.ni1_io.proc = pc->prot.ni1.proc;
154 ic.parm.ni1_io.timeout= 0;
155 ic.parm.ni1_io.datalen = nlen;
156 ic.parm.ni1_io.data = p;
157 free_invoke_id(pc->st, pc->prot.ni1.invoke_id);
158 pc->prot.ni1.invoke_id = 0; /* reset id */
160 cs->iif.statcallb(&ic);
161 ni1_release_l3_process(pc);
164 l3_debug(st, "dummy return result id=0x%x result len=%d",id,nlen);
165 } /* l3ni1_dummy_return_result */
167 /*******************************************************************/
168 /* called when a facility message with a dummy callref is received */
169 /* and a return error is delivered. id specifies the invoke id. */
170 /*******************************************************************/
172 l3ni1_dummy_error_return(struct PStack *st, int id, ulong error)
174 struct IsdnCardState *cs;
175 struct l3_process *pc = NULL;
177 if ((pc = l3ni1_search_dummy_proc(st, id)))
178 { L3DelTimer(&pc->timer); /* remove timer */
180 cs = pc->st->l1.hardware;
181 ic.driver = cs->myid;
182 ic.command = ISDN_STAT_PROT;
183 ic.arg = NI1_STAT_INVOKE_ERR;
184 ic.parm.ni1_io.hl_id = pc->prot.ni1.invoke_id;
185 ic.parm.ni1_io.ll_id = pc->prot.ni1.ll_id;
186 ic.parm.ni1_io.proc = pc->prot.ni1.proc;
187 ic.parm.ni1_io.timeout= error;
188 ic.parm.ni1_io.datalen = 0;
189 ic.parm.ni1_io.data = NULL;
190 free_invoke_id(pc->st, pc->prot.ni1.invoke_id);
191 pc->prot.ni1.invoke_id = 0; /* reset id */
193 cs->iif.statcallb(&ic);
194 ni1_release_l3_process(pc);
197 l3_debug(st, "dummy return error id=0x%x error=0x%lx",id,error);
198 } /* l3ni1_error_return */
200 /*******************************************************************/
201 /* called when a facility message with a dummy callref is received */
202 /* and a invoke is delivered. id specifies the invoke id. */
203 /*******************************************************************/
205 l3ni1_dummy_invoke(struct PStack *st, int cr, int id,
206 int ident, u_char *p, u_char nlen)
208 struct IsdnCardState *cs;
210 l3_debug(st, "dummy invoke %s id=0x%x ident=0x%x datalen=%d",
211 (cr == -1) ? "local" : "broadcast",id,ident,nlen);
212 if (cr >= -1) return; /* ignore local data */
214 cs = st->l1.hardware;
215 ic.driver = cs->myid;
216 ic.command = ISDN_STAT_PROT;
217 ic.arg = NI1_STAT_INVOKE_BRD;
218 ic.parm.ni1_io.hl_id = id;
219 ic.parm.ni1_io.ll_id = 0;
220 ic.parm.ni1_io.proc = ident;
221 ic.parm.ni1_io.timeout= 0;
222 ic.parm.ni1_io.datalen = nlen;
223 ic.parm.ni1_io.data = p;
225 cs->iif.statcallb(&ic);
226 } /* l3ni1_dummy_invoke */
229 l3ni1_parse_facility(struct PStack *st, struct l3_process *pc,
233 unsigned char nlen = 0, ilen, cp_tag;
238 st = pc->st; /* valid Stack */
240 if ((!st) || (cr >= 0)) return; /* neither pc nor st specified */
245 l3_debug(st, "qd_len == 0");
248 if ((*p & 0x1F) != 0x11) { /* Service discriminator, supplementary service */
249 l3_debug(st, "supplementary service != 0x11");
252 while (qd_len > 0 && !(*p & 0x80)) { /* extension ? */
257 l3_debug(st, "qd_len < 2");
262 if ((*p & 0xE0) != 0xA0) { /* class and form */
263 l3_debug(st, "class and form != 0xA0");
267 cp_tag = *p & 0x1F; /* remember tag value */
272 { l3_debug(st, "qd_len < 1");
276 { /* length format indefinite or limited */
277 nlen = *p++ & 0x7F; /* number of len bytes or indefinite */
278 if ((qd_len-- < ((!nlen) ? 3 : (1 + nlen))) ||
280 { l3_debug(st, "length format error or not implemented");
284 { nlen = *p++; /* complete length */
288 { qd_len -= 2; /* trailing null bytes */
289 if ((*(p+qd_len)) || (*(p+qd_len+1)))
290 { l3_debug(st,"length format indefinite error");
301 { l3_debug(st, "qd_len < nlen");
307 { l3_debug(st, "nlen < 2");
311 { /* invoke identifier tag */
312 l3_debug(st, "invoke identifier tag !=0x02");
318 { /* length format */
319 l3_debug(st, "invoke id length format 2");
324 if (ilen > nlen || ilen == 0)
325 { l3_debug(st, "ilen > nlen || ilen == 0");
331 { id = (id << 8) | (*p++ & 0xFF); /* invoke identifier */
335 switch (cp_tag) { /* component tag */
338 l3_debug(st, "nlen < 2 22");
341 if (*p != 0x02) { /* operation value */
342 l3_debug(st, "operation value !=0x02");
349 if (ilen > nlen || ilen == 0) {
350 l3_debug(st, "ilen > nlen || ilen == 0 22");
356 ident = (ident << 8) | (*p++ & 0xFF);
362 l3ni1_dummy_invoke(st, cr, id, ident, p, nlen);
365 l3_debug(st, "invoke break");
367 case 2: /* return result */
368 /* if no process available handle separately */
371 l3ni1_dummy_return_result(st, id, p, nlen);
374 if ((pc->prot.ni1.invoke_id) && (pc->prot.ni1.invoke_id == id))
375 { /* Diversion successful */
376 free_invoke_id(st,pc->prot.ni1.invoke_id);
377 pc->prot.ni1.remote_result = 0; /* success */
378 pc->prot.ni1.invoke_id = 0;
379 pc->redir_result = pc->prot.ni1.remote_result;
380 st->l3.l3l4(st, CC_REDIR | INDICATION, pc); } /* Diversion successful */
382 l3_debug(st,"return error unknown identifier");
384 case 3: /* return error */
387 { l3_debug(st, "return error nlen < 2");
392 l3_debug(st, "invoke error tag !=0x02");
398 { /* length format */
399 l3_debug(st, "invoke return errlen > 4 ");
404 if (ilen > nlen || ilen == 0)
405 { l3_debug(st, "error return ilen > nlen || ilen == 0");
410 { err_ret = (err_ret << 8) | (*p++ & 0xFF); /* error value */
413 /* if no process available handle separately */
416 l3ni1_dummy_error_return(st, id, err_ret);
419 if ((pc->prot.ni1.invoke_id) && (pc->prot.ni1.invoke_id == id))
420 { /* Deflection error */
421 free_invoke_id(st,pc->prot.ni1.invoke_id);
422 pc->prot.ni1.remote_result = err_ret; /* result */
423 pc->prot.ni1.invoke_id = 0;
424 pc->redir_result = pc->prot.ni1.remote_result;
425 st->l3.l3l4(st, CC_REDIR | INDICATION, pc);
426 } /* Deflection error */
428 l3_debug(st,"return result unknown identifier");
431 l3_debug(st, "facility default break tag=0x%02x",cp_tag);
437 l3ni1_message(struct l3_process *pc, u_char mt)
442 if (!(skb = l3_alloc_skb(4)))
445 MsgHead(p, pc->callref, mt);
446 l3_msg(pc->st, DL_DATA | REQUEST, skb);
450 l3ni1_message_plus_chid(struct l3_process *pc, u_char mt)
451 /* sends an l3 messages plus channel id - added GE 05/09/00 */
458 chid = (u_char)(pc->para.bchannel & 0x03) | 0x88;
459 MsgHead(p, pc->callref, mt);
460 *p++ = IE_CHANNEL_ID;
464 if (!(skb = l3_alloc_skb(7)))
466 memcpy(skb_put(skb, 7), tmp, 7);
467 l3_msg(pc->st, DL_DATA | REQUEST, skb);
471 l3ni1_message_cause(struct l3_process *pc, u_char mt, u_char cause)
478 MsgHead(p, pc->callref, mt);
485 if (!(skb = l3_alloc_skb(l)))
487 memcpy(skb_put(skb, l), tmp, l);
488 l3_msg(pc->st, DL_DATA | REQUEST, skb);
492 l3ni1_status_send(struct l3_process *pc, u_char pr, void *arg)
499 MsgHead(p, pc->callref, MT_STATUS);
504 *p++ = pc->para.cause | 0x80;
506 *p++ = IE_CALL_STATE;
508 *p++ = pc->state & 0x3f;
511 if (!(skb = l3_alloc_skb(l)))
513 memcpy(skb_put(skb, l), tmp, l);
514 l3_msg(pc->st, DL_DATA | REQUEST, skb);
518 l3ni1_msg_without_setup(struct l3_process *pc, u_char pr, void *arg)
520 /* This routine is called if here was no SETUP made (checks in ni1up and in
521 * l3ni1_setup) and a RELEASE_COMPLETE have to be sent with an error code
522 * MT_STATUS_ENQUIRE in the NULL state is handled too
529 switch (pc->para.cause) {
530 case 81: /* invalid callreference */
531 case 88: /* incomp destination */
532 case 96: /* mandory IE missing */
533 case 100: /* invalid IE contents */
534 case 101: /* incompatible Callstate */
535 MsgHead(p, pc->callref, MT_RELEASE_COMPLETE);
539 *p++ = pc->para.cause | 0x80;
542 printk(KERN_ERR "HiSax l3ni1_msg_without_setup wrong cause %d\n",
547 if (!(skb = l3_alloc_skb(l)))
549 memcpy(skb_put(skb, l), tmp, l);
550 l3_msg(pc->st, DL_DATA | REQUEST, skb);
551 ni1_release_l3_process(pc);
554 static int ie_ALERTING[] = {IE_BEARER, IE_CHANNEL_ID | IE_MANDATORY_1,
555 IE_FACILITY, IE_PROGRESS, IE_DISPLAY, IE_SIGNAL, IE_HLC,
557 static int ie_CALL_PROCEEDING[] = {IE_BEARER, IE_CHANNEL_ID | IE_MANDATORY_1,
558 IE_FACILITY, IE_PROGRESS, IE_DISPLAY, IE_HLC, -1};
559 static int ie_CONNECT[] = {IE_BEARER, IE_CHANNEL_ID | IE_MANDATORY_1,
560 IE_FACILITY, IE_PROGRESS, IE_DISPLAY, IE_DATE, IE_SIGNAL,
561 IE_CONNECT_PN, IE_CONNECT_SUB, IE_LLC, IE_HLC, IE_USER_USER, -1};
562 static int ie_CONNECT_ACKNOWLEDGE[] = {IE_CHANNEL_ID, IE_DISPLAY, IE_SIGNAL, -1};
563 static int ie_DISCONNECT[] = {IE_CAUSE | IE_MANDATORY, IE_FACILITY,
564 IE_PROGRESS, IE_DISPLAY, IE_SIGNAL, IE_USER_USER, -1};
565 static int ie_INFORMATION[] = {IE_COMPLETE, IE_DISPLAY, IE_KEYPAD, IE_SIGNAL,
567 static int ie_NOTIFY[] = {IE_BEARER, IE_NOTIFY | IE_MANDATORY, IE_DISPLAY, -1};
568 static int ie_PROGRESS[] = {IE_BEARER, IE_CAUSE, IE_FACILITY, IE_PROGRESS |
569 IE_MANDATORY, IE_DISPLAY, IE_HLC, IE_USER_USER, -1};
570 static int ie_RELEASE[] = {IE_CAUSE | IE_MANDATORY_1, IE_FACILITY, IE_DISPLAY,
571 IE_SIGNAL, IE_USER_USER, -1};
572 /* a RELEASE_COMPLETE with errors don't require special actions
573 static int ie_RELEASE_COMPLETE[] = {IE_CAUSE | IE_MANDATORY_1, IE_DISPLAY, IE_SIGNAL, IE_USER_USER, -1};
575 static int ie_RESUME_ACKNOWLEDGE[] = {IE_CHANNEL_ID| IE_MANDATORY, IE_FACILITY,
577 static int ie_RESUME_REJECT[] = {IE_CAUSE | IE_MANDATORY, IE_DISPLAY, -1};
578 static int ie_SETUP[] = {IE_COMPLETE, IE_BEARER | IE_MANDATORY,
579 IE_CHANNEL_ID| IE_MANDATORY, IE_FACILITY, IE_PROGRESS,
580 IE_NET_FAC, IE_DISPLAY, IE_KEYPAD, IE_SIGNAL, IE_CALLING_PN,
581 IE_CALLING_SUB, IE_CALLED_PN, IE_CALLED_SUB, IE_REDIR_NR,
582 IE_LLC, IE_HLC, IE_USER_USER, -1};
583 static int ie_SETUP_ACKNOWLEDGE[] = {IE_CHANNEL_ID | IE_MANDATORY, IE_FACILITY,
584 IE_PROGRESS, IE_DISPLAY, IE_SIGNAL, -1};
585 static int ie_STATUS[] = {IE_CAUSE | IE_MANDATORY, IE_CALL_STATE |
586 IE_MANDATORY, IE_DISPLAY, -1};
587 static int ie_STATUS_ENQUIRY[] = {IE_DISPLAY, -1};
588 static int ie_SUSPEND_ACKNOWLEDGE[] = {IE_DISPLAY, IE_FACILITY, -1};
589 static int ie_SUSPEND_REJECT[] = {IE_CAUSE | IE_MANDATORY, IE_DISPLAY, -1};
591 * static int ie_CONGESTION_CONTROL[] = {IE_CONGESTION | IE_MANDATORY,
592 * IE_CAUSE | IE_MANDATORY, IE_DISPLAY, -1};
593 * static int ie_USER_INFORMATION[] = {IE_MORE_DATA, IE_USER_USER | IE_MANDATORY, -1};
594 * static int ie_RESTART[] = {IE_CHANNEL_ID, IE_DISPLAY, IE_RESTART_IND |
597 static int ie_FACILITY[] = {IE_FACILITY | IE_MANDATORY, IE_DISPLAY, -1};
598 static int comp_required[] = {1,2,3,5,6,7,9,10,11,14,15,-1};
599 static int l3_valid_states[] = {0,1,2,3,4,6,7,8,9,10,11,12,15,17,19,25,-1};
607 struct ie_len max_ie_len[] = {
625 {IE_PACK_BINPARA, 3},
626 {IE_PACK_WINSIZE, 4},
631 {IE_CALLING_SUB, 23},
644 getmax_ie_len(u_char ie) {
646 while (max_ie_len[i].ie != -1) {
647 if (max_ie_len[i].ie == ie)
648 return(max_ie_len[i].len);
655 ie_in_set(struct l3_process *pc, u_char ie, int *checklist) {
658 while (*checklist != -1) {
659 if ((*checklist & 0xff) == ie) {
672 check_infoelements(struct l3_process *pc, struct sk_buff *skb, int *checklist)
677 int l, newpos, oldpos;
678 int err_seq = 0, err_len = 0, err_compr = 0, err_ureg = 0;
680 u_char old_codeset = 0;
690 while ((p - skb->data) < skb->len) {
691 if ((*p & 0xf0) == 0x90) { /* shift codeset */
692 old_codeset = codeset;
698 if (pc->debug & L3_DEB_CHECK)
699 l3_debug(pc->st, "check IE shift%scodeset %d->%d",
700 codelock ? " locking ": " ", old_codeset, codeset);
704 if (!codeset) { /* only codeset 0 */
705 if ((newpos = ie_in_set(pc, *p, cl))) {
713 if (ie_in_set(pc, *p, comp_required))
727 if (!codeset && (l > getmax_ie_len(ie)))
730 if (pc->debug & L3_DEB_CHECK)
731 l3_debug(pc->st, "check IE shift back codeset %d->%d",
732 codeset, old_codeset);
733 codeset = old_codeset;
737 if (err_compr | err_ureg | err_len | err_seq) {
738 if (pc->debug & L3_DEB_CHECK)
739 l3_debug(pc->st, "check IE MT(%x) %d/%d/%d/%d",
740 mt, err_compr, err_ureg, err_len, err_seq);
742 return(ERR_IE_COMPREHENSION);
744 return(ERR_IE_UNRECOGNIZED);
746 return(ERR_IE_LENGTH);
748 return(ERR_IE_SEQUENCE);
753 /* verify if a message type exists and contain no IE error */
755 l3ni1_check_messagetype_validity(struct l3_process *pc, int mt, void *arg)
759 case MT_CALL_PROCEEDING:
761 case MT_CONNECT_ACKNOWLEDGE:
768 case MT_RELEASE_COMPLETE:
770 case MT_SETUP_ACKNOWLEDGE:
771 case MT_RESUME_ACKNOWLEDGE:
772 case MT_RESUME_REJECT:
773 case MT_SUSPEND_ACKNOWLEDGE:
774 case MT_SUSPEND_REJECT:
775 case MT_USER_INFORMATION:
777 case MT_RESTART_ACKNOWLEDGE:
778 case MT_CONGESTION_CONTROL:
780 case MT_STATUS_ENQUIRY:
781 if (pc->debug & L3_DEB_CHECK)
782 l3_debug(pc->st, "l3ni1_check_messagetype_validity mt(%x) OK", mt);
784 case MT_RESUME: /* RESUME only in user->net */
785 case MT_SUSPEND: /* SUSPEND only in user->net */
787 if (pc->debug & (L3_DEB_CHECK | L3_DEB_WARN))
788 l3_debug(pc->st, "l3ni1_check_messagetype_validity mt(%x) fail", mt);
790 l3ni1_status_send(pc, 0, NULL);
797 l3ni1_std_ie_err(struct l3_process *pc, int ret) {
799 if (pc->debug & L3_DEB_CHECK)
800 l3_debug(pc->st, "check_infoelements ret %d", ret);
804 case ERR_IE_COMPREHENSION:
806 l3ni1_status_send(pc, 0, NULL);
808 case ERR_IE_UNRECOGNIZED:
810 l3ni1_status_send(pc, 0, NULL);
813 pc->para.cause = 100;
814 l3ni1_status_send(pc, 0, NULL);
816 case ERR_IE_SEQUENCE:
823 l3ni1_get_channel_id(struct l3_process *pc, struct sk_buff *skb) {
827 if ((p = findie(p, skb->len, IE_CHANNEL_ID, 0))) {
829 if (*p != 1) { /* len for BRI = 1 */
830 if (pc->debug & L3_DEB_WARN)
831 l3_debug(pc->st, "wrong chid len %d", *p);
835 if (*p & 0x60) { /* only base rate interface */
836 if (pc->debug & L3_DEB_WARN)
837 l3_debug(pc->st, "wrong chid %x", *p);
846 l3ni1_get_cause(struct l3_process *pc, struct sk_buff *skb) {
853 if ((p = findie(p, skb->len, IE_CAUSE, 0))) {
864 if (l && !(pc->para.loc & 0x80)) {
866 p++; /* skip recommendation */
869 pc->para.cause = *p++;
871 if (!(pc->para.cause & 0x80))
876 pc->para.diag[i++] = *p++;
885 l3ni1_msg_with_uus(struct l3_process *pc, u_char cmd)
892 MsgHead(p, pc->callref, cmd);
894 if (pc->prot.ni1.uus1_data[0])
895 { *p++ = IE_USER_USER; /* UUS info element */
896 *p++ = strlen(pc->prot.ni1.uus1_data) + 1;
897 *p++ = 0x04; /* IA5 chars */
898 strcpy(p,pc->prot.ni1.uus1_data);
899 p += strlen(pc->prot.ni1.uus1_data);
900 pc->prot.ni1.uus1_data[0] = '\0';
904 if (!(skb = l3_alloc_skb(l)))
906 memcpy(skb_put(skb, l), tmp, l);
907 l3_msg(pc->st, DL_DATA | REQUEST, skb);
908 } /* l3ni1_msg_with_uus */
911 l3ni1_release_req(struct l3_process *pc, u_char pr, void *arg)
915 if (!pc->prot.ni1.uus1_data[0])
916 l3ni1_message(pc, MT_RELEASE);
918 l3ni1_msg_with_uus(pc, MT_RELEASE);
919 L3AddTimer(&pc->timer, T308, CC_T308_1);
923 l3ni1_release_cmpl(struct l3_process *pc, u_char pr, void *arg)
925 struct sk_buff *skb = arg;
928 if ((ret = l3ni1_get_cause(pc, skb))>0) {
929 if (pc->debug & L3_DEB_WARN)
930 l3_debug(pc->st, "RELCMPL get_cause ret(%d)",ret);
932 pc->para.cause = NO_CAUSE;
935 pc->st->l3.l3l4(pc->st, CC_RELEASE | CONFIRM, pc);
936 ni1_release_l3_process(pc);
942 EncodeASyncParams(u_char * p, u_char si2)
943 { // 7c 06 88 90 21 42 00 bb
946 p[1] = 0x40; // Intermediate rate: 16 kbit/s jj 2000.02.19
948 if (si2 & 32) // 7 data bits
955 if (si2 & 16) // 2 stop bits
962 if (si2 & 8) // even parity
969 switch (si2 & 0x07) {
971 p[0] = 66; // 1200 bit/s
975 p[0] = 88; // 1200/75 bit/s
979 p[0] = 87; // 75/1200 bit/s
983 p[0] = 67; // 2400 bit/s
987 p[0] = 69; // 4800 bit/s
991 p[0] = 72; // 9600 bit/s
995 p[0] = 73; // 14400 bit/s
999 p[0] = 75; // 19200 bit/s
1007 EncodeSyncParams(u_char si2, u_char ai)
1012 return ai + 2; // 1200 bit/s
1015 return ai + 24; // 1200/75 bit/s
1018 return ai + 23; // 75/1200 bit/s
1021 return ai + 3; // 2400 bit/s
1024 return ai + 5; // 4800 bit/s
1027 return ai + 8; // 9600 bit/s
1030 return ai + 9; // 14400 bit/s
1033 return ai + 11; // 19200 bit/s
1036 return ai + 14; // 48000 bit/s
1039 return ai + 15; // 56000 bit/s
1042 return ai + 40; // negotiate bit/s
1052 DecodeASyncParams(u_char si2, u_char * p)
1057 case 66: // 1200 bit/s
1059 break; // si2 don't change
1061 case 88: // 1200/75 bit/s
1065 case 87: // 75/1200 bit/s
1069 case 67: // 2400 bit/s
1073 case 69: // 4800 bit/s
1077 case 72: // 9600 bit/s
1081 case 73: // 14400 bit/s
1085 case 75: // 19200 bit/s
1092 if ((info & 16) && (!(info & 8))) // 7 data bits
1094 si2 += 32; // else 8 data bits
1096 if ((info & 96) == 96) // 2 stop bits
1098 si2 += 16; // else 1 stop bit
1100 if ((info & 2) && (!(info & 1))) // even parity
1102 si2 += 8; // else no parity
1109 DecodeSyncParams(u_char si2, u_char info)
1113 case 40: // bit/s negotiation failed ai := 165 not 175!
1116 case 15: // 56000 bit/s failed, ai := 0 not 169 !
1119 case 14: // 48000 bit/s
1122 case 11: // 19200 bit/s
1125 case 9: // 14400 bit/s
1128 case 8: // 9600 bit/s
1131 case 5: // 4800 bit/s
1134 case 3: // 2400 bit/s
1137 case 23: // 75/1200 bit/s
1140 case 24: // 1200/75 bit/s
1143 default: // 1200 bit/s
1150 DecodeSI2(struct sk_buff *skb)
1152 u_char *p; //, *pend=skb->data + skb->len;
1154 if ((p = findie(skb->data, skb->len, 0x7c, 0))) {
1155 switch (p[4] & 0x0f) {
1157 if (p[1] == 0x04) // sync. Bitratenadaption
1159 return DecodeSyncParams(160, p[5]); // V.110/X.30
1161 else if (p[1] == 0x06) // async. Bitratenadaption
1163 return DecodeASyncParams(192, p); // V.110/X.30
1166 case 0x08: // if (p[5] == 0x02) // sync. Bitratenadaption
1168 return DecodeSyncParams(176, p[5]); // V.120
1179 l3ni1_setup_req(struct l3_process *pc, u_char pr,
1182 struct sk_buff *skb;
1191 MsgHead(p, pc->callref, MT_SETUP);
1193 teln = pc->para.setup.phone;
1195 *p++ = 0xa1; /* complete indicator */
1197 * Set Bearer Capability, Map info from 1TR6-convention to NI1
1199 switch (pc->para.setup.si1) {
1200 case 1: /* Telephony */
1202 *p++ = 0x3; /* Length */
1203 *p++ = 0x90; /* 3.1khz Audio */
1204 *p++ = 0x90; /* Circuit-Mode 64kbps */
1205 *p++ = 0xa2; /* u-Law Audio */
1207 case 5: /* Datatransmission 64k, BTX */
1208 case 7: /* Datatransmission 64k */
1211 *p++ = 0x2; /* Length */
1212 *p++ = 0x88; /* Coding Std. CCITT, unrestr. dig. Inform. */
1213 *p++ = 0x90; /* Circuit-Mode 64kbps */
1228 *p++ = strlen(teln);
1230 *p++ = (*teln++) & 0x7F;
1236 if ((pc->para.setup.si2 >= 160) && (pc->para.setup.si2 <= 175)) { // sync. Bitratenadaption, V.110/X.30
1243 *p++ = EncodeSyncParams(pc->para.setup.si2 - 160, 0x80);
1244 } else if ((pc->para.setup.si2 >= 176) && (pc->para.setup.si2 <= 191)) { // sync. Bitratenadaption, V.120
1251 *p++ = EncodeSyncParams(pc->para.setup.si2 - 176, 0);
1253 } else if (pc->para.setup.si2 >= 192) { // async. Bitratenadaption, V.110/X.30
1260 p = EncodeASyncParams(p, pc->para.setup.si2 - 192);
1262 switch (pc->para.setup.si1) {
1263 case 1: /* Telephony */
1265 *p++ = 0x3; /* Length */
1266 *p++ = 0x90; /* Coding Std. CCITT, 3.1 kHz audio */
1267 *p++ = 0x90; /* Circuit-Mode 64kbps */
1268 *p++ = 0xa2; /* u-Law Audio */
1270 case 5: /* Datatransmission 64k, BTX */
1271 case 7: /* Datatransmission 64k */
1274 *p++ = 0x2; /* Length */
1275 *p++ = 0x88; /* Coding Std. CCITT, unrestr. dig. Inform. */
1276 *p++ = 0x90; /* Circuit-Mode 64kbps */
1282 if (!(skb = l3_alloc_skb(l)))
1286 memcpy(skb_put(skb, l), tmp, l);
1287 L3DelTimer(&pc->timer);
1288 L3AddTimer(&pc->timer, T303, CC_T303);
1290 l3_msg(pc->st, DL_DATA | REQUEST, skb);
1294 l3ni1_call_proc(struct l3_process *pc, u_char pr, void *arg)
1296 struct sk_buff *skb = arg;
1299 if ((id = l3ni1_get_channel_id(pc, skb)) >= 0) {
1300 if ((0 == id) || ((3 == id) && (0x10 == pc->para.moderate))) {
1301 if (pc->debug & L3_DEB_WARN)
1302 l3_debug(pc->st, "setup answer with wrong chid %x", id);
1303 pc->para.cause = 100;
1304 l3ni1_status_send(pc, pr, NULL);
1307 pc->para.bchannel = id;
1308 } else if (1 == pc->state) {
1309 if (pc->debug & L3_DEB_WARN)
1310 l3_debug(pc->st, "setup answer wrong chid (ret %d)", id);
1312 pc->para.cause = 96;
1314 pc->para.cause = 100;
1315 l3ni1_status_send(pc, pr, NULL);
1318 /* Now we are on none mandatory IEs */
1319 ret = check_infoelements(pc, skb, ie_CALL_PROCEEDING);
1320 if (ERR_IE_COMPREHENSION == ret) {
1321 l3ni1_std_ie_err(pc, ret);
1324 L3DelTimer(&pc->timer);
1326 L3AddTimer(&pc->timer, T310, CC_T310);
1327 if (ret) /* STATUS for none mandatory IE errors after actions are taken */
1328 l3ni1_std_ie_err(pc, ret);
1329 pc->st->l3.l3l4(pc->st, CC_PROCEEDING | INDICATION, pc);
1333 l3ni1_setup_ack(struct l3_process *pc, u_char pr, void *arg)
1335 struct sk_buff *skb = arg;
1338 if ((id = l3ni1_get_channel_id(pc, skb)) >= 0) {
1339 if ((0 == id) || ((3 == id) && (0x10 == pc->para.moderate))) {
1340 if (pc->debug & L3_DEB_WARN)
1341 l3_debug(pc->st, "setup answer with wrong chid %x", id);
1342 pc->para.cause = 100;
1343 l3ni1_status_send(pc, pr, NULL);
1346 pc->para.bchannel = id;
1348 if (pc->debug & L3_DEB_WARN)
1349 l3_debug(pc->st, "setup answer wrong chid (ret %d)", id);
1351 pc->para.cause = 96;
1353 pc->para.cause = 100;
1354 l3ni1_status_send(pc, pr, NULL);
1357 /* Now we are on none mandatory IEs */
1358 ret = check_infoelements(pc, skb, ie_SETUP_ACKNOWLEDGE);
1359 if (ERR_IE_COMPREHENSION == ret) {
1360 l3ni1_std_ie_err(pc, ret);
1363 L3DelTimer(&pc->timer);
1365 L3AddTimer(&pc->timer, T304, CC_T304);
1366 if (ret) /* STATUS for none mandatory IE errors after actions are taken */
1367 l3ni1_std_ie_err(pc, ret);
1368 pc->st->l3.l3l4(pc->st, CC_MORE_INFO | INDICATION, pc);
1372 l3ni1_disconnect(struct l3_process *pc, u_char pr, void *arg)
1374 struct sk_buff *skb = arg;
1380 if ((ret = l3ni1_get_cause(pc, skb))) {
1381 if (pc->debug & L3_DEB_WARN)
1382 l3_debug(pc->st, "DISC get_cause ret(%d)", ret);
1388 if ((p = findie(skb->data, skb->len, IE_FACILITY, 0)))
1389 l3ni1_parse_facility(pc->st, pc, pc->callref, p);
1390 ret = check_infoelements(pc, skb, ie_DISCONNECT);
1391 if (ERR_IE_COMPREHENSION == ret)
1393 else if ((!cause) && (ERR_IE_UNRECOGNIZED == ret))
1400 pc->st->l3.l3l4(pc->st, CC_DISCONNECT | INDICATION, pc);
1402 l3ni1_release_req(pc, pr, NULL);
1404 l3ni1_message_cause(pc, MT_RELEASE, cause);
1405 L3AddTimer(&pc->timer, T308, CC_T308_1);
1410 l3ni1_connect(struct l3_process *pc, u_char pr, void *arg)
1412 struct sk_buff *skb = arg;
1415 ret = check_infoelements(pc, skb, ie_CONNECT);
1416 if (ERR_IE_COMPREHENSION == ret) {
1417 l3ni1_std_ie_err(pc, ret);
1420 L3DelTimer(&pc->timer); /* T310 */
1422 pc->para.chargeinfo = 0;
1423 /* here should inserted COLP handling KKe */
1425 l3ni1_std_ie_err(pc, ret);
1426 pc->st->l3.l3l4(pc->st, CC_SETUP | CONFIRM, pc);
1430 l3ni1_alerting(struct l3_process *pc, u_char pr, void *arg)
1432 struct sk_buff *skb = arg;
1435 ret = check_infoelements(pc, skb, ie_ALERTING);
1436 if (ERR_IE_COMPREHENSION == ret) {
1437 l3ni1_std_ie_err(pc, ret);
1440 L3DelTimer(&pc->timer); /* T304 */
1443 l3ni1_std_ie_err(pc, ret);
1444 pc->st->l3.l3l4(pc->st, CC_ALERTING | INDICATION, pc);
1448 l3ni1_setup(struct l3_process *pc, u_char pr, void *arg)
1453 struct sk_buff *skb = arg;
1458 * Bearer Capabilities
1461 /* only the first occurence 'll be detected ! */
1462 if ((p = findie(p, skb->len, 0x04, 0))) {
1463 if ((p[1] < 2) || (p[1] > 11))
1466 pc->para.setup.si2 = 0;
1467 switch (p[2] & 0x7f) {
1468 case 0x00: /* Speech */
1469 case 0x10: /* 3.1 Khz audio */
1470 pc->para.setup.si1 = 1;
1472 case 0x08: /* Unrestricted digital information */
1473 pc->para.setup.si1 = 7;
1474 /* JIM, 05.11.97 I wanna set service indicator 2 */
1476 pc->para.setup.si2 = DecodeSI2(skb);
1479 case 0x09: /* Restricted digital information */
1480 pc->para.setup.si1 = 2;
1483 /* Unrestr. digital information with
1484 * tones/announcements ( or 7 kHz audio
1486 pc->para.setup.si1 = 3;
1488 case 0x18: /* Video */
1489 pc->para.setup.si1 = 4;
1495 switch (p[3] & 0x7f) {
1496 case 0x40: /* packed mode */
1497 pc->para.setup.si1 = 8;
1499 case 0x10: /* 64 kbit */
1500 case 0x11: /* 2*64 kbit */
1501 case 0x13: /* 384 kbit */
1502 case 0x15: /* 1536 kbit */
1503 case 0x17: /* 1920 kbit */
1504 pc->para.moderate = p[3] & 0x7f;
1511 if (pc->debug & L3_DEB_SI)
1512 l3_debug(pc->st, "SI=%d, AI=%d",
1513 pc->para.setup.si1, pc->para.setup.si2);
1515 if (pc->debug & L3_DEB_WARN)
1516 l3_debug(pc->st, "setup with wrong bearer(l=%d:%x,%x)",
1518 pc->para.cause = 100;
1519 l3ni1_msg_without_setup(pc, pr, NULL);
1523 if (pc->debug & L3_DEB_WARN)
1524 l3_debug(pc->st, "setup without bearer capabilities");
1525 /* ETS 300-104 1.3.3 */
1526 pc->para.cause = 96;
1527 l3ni1_msg_without_setup(pc, pr, NULL);
1531 * Channel Identification
1533 if ((id = l3ni1_get_channel_id(pc, skb)) >= 0) {
1534 if ((pc->para.bchannel = id)) {
1535 if ((3 == id) && (0x10 == pc->para.moderate)) {
1536 if (pc->debug & L3_DEB_WARN)
1537 l3_debug(pc->st, "setup with wrong chid %x",
1539 pc->para.cause = 100;
1540 l3ni1_msg_without_setup(pc, pr, NULL);
1545 { if (pc->debug & L3_DEB_WARN)
1546 l3_debug(pc->st, "setup without bchannel, call waiting");
1550 if (pc->debug & L3_DEB_WARN)
1551 l3_debug(pc->st, "setup with wrong chid ret %d", id);
1553 pc->para.cause = 96;
1555 pc->para.cause = 100;
1556 l3ni1_msg_without_setup(pc, pr, NULL);
1559 /* Now we are on none mandatory IEs */
1560 err = check_infoelements(pc, skb, ie_SETUP);
1561 if (ERR_IE_COMPREHENSION == err) {
1562 pc->para.cause = 96;
1563 l3ni1_msg_without_setup(pc, pr, NULL);
1567 if ((p = findie(p, skb->len, 0x70, 0)))
1568 iecpy(pc->para.setup.eazmsn, p, 1);
1570 pc->para.setup.eazmsn[0] = 0;
1573 if ((p = findie(p, skb->len, 0x71, 0))) {
1574 /* Called party subaddress */
1575 if ((p[1] >= 2) && (p[2] == 0x80) && (p[3] == 0x50)) {
1577 iecpy(&tmp[1], p, 2);
1578 strcat(pc->para.setup.eazmsn, tmp);
1579 } else if (pc->debug & L3_DEB_WARN)
1580 l3_debug(pc->st, "wrong called subaddress");
1583 if ((p = findie(p, skb->len, 0x6c, 0))) {
1584 pc->para.setup.plan = p[2];
1586 iecpy(pc->para.setup.phone, p, 1);
1587 pc->para.setup.screen = 0;
1589 iecpy(pc->para.setup.phone, p, 2);
1590 pc->para.setup.screen = p[3];
1593 pc->para.setup.phone[0] = 0;
1594 pc->para.setup.plan = 0;
1595 pc->para.setup.screen = 0;
1598 if ((p = findie(p, skb->len, 0x6d, 0))) {
1599 /* Calling party subaddress */
1600 if ((p[1] >= 2) && (p[2] == 0x80) && (p[3] == 0x50)) {
1602 iecpy(&tmp[1], p, 2);
1603 strcat(pc->para.setup.phone, tmp);
1604 } else if (pc->debug & L3_DEB_WARN)
1605 l3_debug(pc->st, "wrong calling subaddress");
1608 if (err) /* STATUS for none mandatory IE errors after actions are taken */
1609 l3ni1_std_ie_err(pc, err);
1610 pc->st->l3.l3l4(pc->st, CC_SETUP | INDICATION, pc);
1614 l3ni1_reset(struct l3_process *pc, u_char pr, void *arg)
1616 ni1_release_l3_process(pc);
1620 l3ni1_disconnect_req(struct l3_process *pc, u_char pr, void *arg)
1622 struct sk_buff *skb;
1628 if (pc->para.cause != NO_CAUSE)
1629 cause = pc->para.cause;
1633 MsgHead(p, pc->callref, MT_DISCONNECT);
1638 *p++ = cause | 0x80;
1640 if (pc->prot.ni1.uus1_data[0])
1641 { *p++ = IE_USER_USER; /* UUS info element */
1642 *p++ = strlen(pc->prot.ni1.uus1_data) + 1;
1643 *p++ = 0x04; /* IA5 chars */
1644 strcpy(p,pc->prot.ni1.uus1_data);
1645 p += strlen(pc->prot.ni1.uus1_data);
1646 pc->prot.ni1.uus1_data[0] = '\0';
1650 if (!(skb = l3_alloc_skb(l)))
1652 memcpy(skb_put(skb, l), tmp, l);
1654 l3_msg(pc->st, DL_DATA | REQUEST, skb);
1655 L3AddTimer(&pc->timer, T305, CC_T305);
1659 l3ni1_setup_rsp(struct l3_process *pc, u_char pr,
1662 if (!pc->para.bchannel)
1663 { if (pc->debug & L3_DEB_WARN)
1664 l3_debug(pc->st, "D-chan connect for waiting call");
1665 l3ni1_disconnect_req(pc, pr, arg);
1669 if (pc->debug & L3_DEB_WARN)
1670 l3_debug(pc->st, "D-chan connect for waiting call");
1671 l3ni1_message_plus_chid(pc, MT_CONNECT); /* GE 05/09/00 */
1672 L3DelTimer(&pc->timer);
1673 L3AddTimer(&pc->timer, T313, CC_T313);
1677 l3ni1_connect_ack(struct l3_process *pc, u_char pr, void *arg)
1679 struct sk_buff *skb = arg;
1682 ret = check_infoelements(pc, skb, ie_CONNECT_ACKNOWLEDGE);
1683 if (ERR_IE_COMPREHENSION == ret) {
1684 l3ni1_std_ie_err(pc, ret);
1688 L3DelTimer(&pc->timer);
1690 l3ni1_std_ie_err(pc, ret);
1691 pc->st->l3.l3l4(pc->st, CC_SETUP_COMPL | INDICATION, pc);
1695 l3ni1_reject_req(struct l3_process *pc, u_char pr, void *arg)
1697 struct sk_buff *skb;
1703 if (pc->para.cause != NO_CAUSE)
1704 cause = pc->para.cause;
1706 MsgHead(p, pc->callref, MT_RELEASE_COMPLETE);
1711 *p++ = cause | 0x80;
1714 if (!(skb = l3_alloc_skb(l)))
1716 memcpy(skb_put(skb, l), tmp, l);
1717 l3_msg(pc->st, DL_DATA | REQUEST, skb);
1718 pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
1720 ni1_release_l3_process(pc);
1724 l3ni1_release(struct l3_process *pc, u_char pr, void *arg)
1726 struct sk_buff *skb = arg;
1731 if ((ret = l3ni1_get_cause(pc, skb))>0) {
1732 if (pc->debug & L3_DEB_WARN)
1733 l3_debug(pc->st, "REL get_cause ret(%d)", ret);
1735 pc->para.cause = NO_CAUSE;
1736 if ((p = findie(skb->data, skb->len, IE_FACILITY, 0))) {
1737 l3ni1_parse_facility(pc->st, pc, pc->callref, p);
1739 if ((ret<0) && (pc->state != 11))
1743 ret = check_infoelements(pc, skb, ie_RELEASE);
1744 if (ERR_IE_COMPREHENSION == ret)
1746 else if ((ERR_IE_UNRECOGNIZED == ret) && (!cause))
1749 l3ni1_message_cause(pc, MT_RELEASE_COMPLETE, cause);
1751 l3ni1_message(pc, MT_RELEASE_COMPLETE);
1752 pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
1754 ni1_release_l3_process(pc);
1758 l3ni1_alert_req(struct l3_process *pc, u_char pr,
1762 if (!pc->prot.ni1.uus1_data[0])
1763 l3ni1_message(pc, MT_ALERTING);
1765 l3ni1_msg_with_uus(pc, MT_ALERTING);
1769 l3ni1_proceed_req(struct l3_process *pc, u_char pr,
1773 l3ni1_message(pc, MT_CALL_PROCEEDING);
1774 pc->st->l3.l3l4(pc->st, CC_PROCEED_SEND | INDICATION, pc);
1778 l3ni1_setup_ack_req(struct l3_process *pc, u_char pr,
1782 L3DelTimer(&pc->timer);
1783 L3AddTimer(&pc->timer, T302, CC_T302);
1784 l3ni1_message(pc, MT_SETUP_ACKNOWLEDGE);
1787 /********************************************/
1788 /* deliver a incoming display message to HL */
1789 /********************************************/
1791 l3ni1_deliver_display(struct l3_process *pc, int pr, u_char *infp)
1794 struct IsdnCardState *cs;
1797 if (*infp++ != IE_DISPLAY) return;
1798 if ((len = *infp++) > 80) return; /* total length <= 82 */
1799 if (!pc->chan) return;
1801 p = ic.parm.display;
1805 ic.command = ISDN_STAT_DISPLAY;
1806 cs = pc->st->l1.hardware;
1807 ic.driver = cs->myid;
1808 ic.arg = pc->chan->chan;
1809 cs->iif.statcallb(&ic);
1810 } /* l3ni1_deliver_display */
1814 l3ni1_progress(struct l3_process *pc, u_char pr, void *arg)
1816 struct sk_buff *skb = arg;
1820 if ((p = findie(skb->data, skb->len, IE_PROGRESS, 0))) {
1823 pc->para.cause = 100;
1824 } else if (!(p[2] & 0x70)) {
1842 pc->para.cause = 100;
1848 pc->para.cause = 100;
1853 pc->para.cause = 96;
1857 if (pc->debug & L3_DEB_WARN)
1858 l3_debug(pc->st, "progress error %d", err);
1859 l3ni1_status_send(pc, pr, NULL);
1862 /* Now we are on none mandatory IEs */
1863 err = check_infoelements(pc, skb, ie_PROGRESS);
1865 l3ni1_std_ie_err(pc, err);
1866 if (ERR_IE_COMPREHENSION != err)
1867 pc->st->l3.l3l4(pc->st, CC_PROGRESS | INDICATION, pc);
1871 l3ni1_notify(struct l3_process *pc, u_char pr, void *arg)
1873 struct sk_buff *skb = arg;
1877 if ((p = findie(skb->data, skb->len, IE_NOTIFY, 0))) {
1880 pc->para.cause = 100;
1888 pc->para.cause = 100;
1894 pc->para.cause = 96;
1898 if (pc->debug & L3_DEB_WARN)
1899 l3_debug(pc->st, "notify error %d", err);
1900 l3ni1_status_send(pc, pr, NULL);
1903 /* Now we are on none mandatory IEs */
1904 err = check_infoelements(pc, skb, ie_NOTIFY);
1906 l3ni1_std_ie_err(pc, err);
1907 if (ERR_IE_COMPREHENSION != err)
1908 pc->st->l3.l3l4(pc->st, CC_NOTIFY | INDICATION, pc);
1912 l3ni1_status_enq(struct l3_process *pc, u_char pr, void *arg)
1915 struct sk_buff *skb = arg;
1917 ret = check_infoelements(pc, skb, ie_STATUS_ENQUIRY);
1918 l3ni1_std_ie_err(pc, ret);
1919 pc->para.cause = 30; /* response to STATUS_ENQUIRY */
1920 l3ni1_status_send(pc, pr, NULL);
1924 l3ni1_information(struct l3_process *pc, u_char pr, void *arg)
1927 struct sk_buff *skb = arg;
1931 ret = check_infoelements(pc, skb, ie_INFORMATION);
1933 l3ni1_std_ie_err(pc, ret);
1934 if (pc->state == 25) { /* overlap receiving */
1935 L3DelTimer(&pc->timer);
1937 if ((p = findie(p, skb->len, 0x70, 0))) {
1939 strcat(pc->para.setup.eazmsn, tmp);
1940 pc->st->l3.l3l4(pc->st, CC_MORE_INFO | INDICATION, pc);
1942 L3AddTimer(&pc->timer, T302, CC_T302);
1946 /******************************/
1947 /* handle deflection requests */
1948 /******************************/
1949 static void l3ni1_redir_req(struct l3_process *pc, u_char pr, void *arg)
1951 struct sk_buff *skb;
1955 u_char len_phone = 0;
1960 strcpy(pc->prot.ni1.uus1_data,pc->chan->setup.eazmsn); /* copy uus element if available */
1961 if (!pc->chan->setup.phone[0])
1962 { pc->para.cause = -1;
1963 l3ni1_disconnect_req(pc,pr,arg); /* disconnect immediately */
1967 if (pc->prot.ni1.invoke_id)
1968 free_invoke_id(pc->st,pc->prot.ni1.invoke_id);
1970 if (!(pc->prot.ni1.invoke_id = new_invoke_id(pc->st)))
1973 MsgHead(p, pc->callref, MT_FACILITY);
1975 for (subp = pc->chan->setup.phone; (*subp) && (*subp != '.'); subp++) len_phone++; /* len of phone number */
1976 if (*subp++ == '.') len_sub = strlen(subp) + 2; /* length including info subaddress element */
1978 *p++ = 0x1c; /* Facility info element */
1979 *p++ = len_phone + len_sub + 2 + 2 + 8 + 3 + 3; /* length of element */
1980 *p++ = 0x91; /* remote operations protocol */
1981 *p++ = 0xa1; /* invoke component */
1983 *p++ = len_phone + len_sub + 2 + 2 + 8 + 3; /* length of data */
1984 *p++ = 0x02; /* invoke id tag, integer */
1985 *p++ = 0x01; /* length */
1986 *p++ = pc->prot.ni1.invoke_id; /* invoke id */
1987 *p++ = 0x02; /* operation value tag, integer */
1988 *p++ = 0x01; /* length */
1989 *p++ = 0x0D; /* Call Deflect */
1991 *p++ = 0x30; /* sequence phone number */
1992 *p++ = len_phone + 2 + 2 + 3 + len_sub; /* length */
1994 *p++ = 0x30; /* Deflected to UserNumber */
1995 *p++ = len_phone+2+len_sub; /* length */
1996 *p++ = 0x80; /* NumberDigits */
1997 *p++ = len_phone; /* length */
1998 for (l = 0; l < len_phone; l++)
1999 *p++ = pc->chan->setup.phone[l];
2002 { *p++ = 0x04; /* called party subaddress */
2004 while (*subp) *p++ = *subp++;
2007 *p++ = 0x01; /* screening identifier */
2009 *p++ = pc->chan->setup.screen;
2012 if (!(skb = l3_alloc_skb(l))) return;
2013 memcpy(skb_put(skb, l), tmp, l);
2015 l3_msg(pc->st, DL_DATA | REQUEST, skb);
2016 } /* l3ni1_redir_req */
2018 /********************************************/
2019 /* handle deflection request in early state */
2020 /********************************************/
2021 static void l3ni1_redir_req_early(struct l3_process *pc, u_char pr, void *arg)
2023 l3ni1_proceed_req(pc,pr,arg);
2024 l3ni1_redir_req(pc,pr,arg);
2025 } /* l3ni1_redir_req_early */
2027 /***********************************************/
2028 /* handle special commands for this protocol. */
2029 /* Examples are call independant services like */
2030 /* remote operations with dummy callref. */
2031 /***********************************************/
2032 static int l3ni1_cmd_global(struct PStack *st, isdn_ctrl *ic)
2037 struct sk_buff *skb;
2038 struct l3_process *pc = NULL;
2041 { case NI1_CMD_INVOKE:
2042 if (ic->parm.ni1_io.datalen < 0) return(-2); /* invalid parameter */
2044 for (proc_len = 1, i = ic->parm.ni1_io.proc >> 8; i; i++)
2045 i = i >> 8; /* add one byte */
2046 l = ic->parm.ni1_io.datalen + proc_len + 8; /* length excluding ie header */
2048 return(-2); /* too long */
2050 if (!(id = new_invoke_id(st)))
2051 return(0); /* first get a invoke id -> return if no available */
2054 MsgHead(p, i, MT_FACILITY); /* build message head */
2055 *p++ = 0x1C; /* Facility IE */
2056 *p++ = l; /* length of ie */
2057 *p++ = 0x91; /* remote operations */
2058 *p++ = 0xA1; /* invoke */
2059 *p++ = l - 3; /* length of invoke */
2060 *p++ = 0x02; /* invoke id tag */
2061 *p++ = 0x01; /* length is 1 */
2062 *p++ = id; /* invoke id */
2063 *p++ = 0x02; /* operation */
2064 *p++ = proc_len; /* length of operation */
2066 for (i = proc_len; i; i--)
2067 *p++ = (ic->parm.ni1_io.proc >> (i-1)) & 0xFF;
2068 memcpy(p, ic->parm.ni1_io.data, ic->parm.ni1_io.datalen); /* copy data */
2069 l = (p - temp) + ic->parm.ni1_io.datalen; /* total length */
2071 if (ic->parm.ni1_io.timeout > 0)
2072 if (!(pc = ni1_new_l3_process(st, -1)))
2073 { free_invoke_id(st, id);
2076 pc->prot.ni1.ll_id = ic->parm.ni1_io.ll_id; /* remember id */
2077 pc->prot.ni1.proc = ic->parm.ni1_io.proc; /* and procedure */
2079 if (!(skb = l3_alloc_skb(l)))
2080 { free_invoke_id(st, id);
2081 if (pc) ni1_release_l3_process(pc);
2084 memcpy(skb_put(skb, l), temp, l);
2087 { pc->prot.ni1.invoke_id = id; /* remember id */
2088 L3AddTimer(&pc->timer, ic->parm.ni1_io.timeout, CC_TNI1_IO | REQUEST);
2091 l3_msg(st, DL_DATA | REQUEST, skb);
2092 ic->parm.ni1_io.hl_id = id; /* return id */
2095 case NI1_CMD_INVOKE_ABORT:
2096 if ((pc = l3ni1_search_dummy_proc(st, ic->parm.ni1_io.hl_id)))
2097 { L3DelTimer(&pc->timer); /* remove timer */
2098 ni1_release_l3_process(pc);
2102 { l3_debug(st, "l3ni1_cmd_global abort unknown id");
2108 l3_debug(st, "l3ni1_cmd_global unknown cmd 0x%lx", ic->arg);
2110 } /* switch ic-> arg */
2112 } /* l3ni1_cmd_global */
2115 l3ni1_io_timer(struct l3_process *pc)
2117 struct IsdnCardState *cs = pc->st->l1.hardware;
2119 L3DelTimer(&pc->timer); /* remove timer */
2121 ic.driver = cs->myid;
2122 ic.command = ISDN_STAT_PROT;
2123 ic.arg = NI1_STAT_INVOKE_ERR;
2124 ic.parm.ni1_io.hl_id = pc->prot.ni1.invoke_id;
2125 ic.parm.ni1_io.ll_id = pc->prot.ni1.ll_id;
2126 ic.parm.ni1_io.proc = pc->prot.ni1.proc;
2127 ic.parm.ni1_io.timeout= -1;
2128 ic.parm.ni1_io.datalen = 0;
2129 ic.parm.ni1_io.data = NULL;
2130 free_invoke_id(pc->st, pc->prot.ni1.invoke_id);
2131 pc->prot.ni1.invoke_id = 0; /* reset id */
2133 cs->iif.statcallb(&ic);
2135 ni1_release_l3_process(pc);
2136 } /* l3ni1_io_timer */
2139 l3ni1_release_ind(struct l3_process *pc, u_char pr, void *arg)
2142 struct sk_buff *skb = arg;
2146 if ((p = findie(p, skb->len, IE_CALL_STATE, 0))) {
2151 if (callState == 0) {
2152 /* ETS 300-104 7.6.1, 8.6.1, 10.6.1... and 16.1
2153 * set down layer 3 without sending any message
2155 pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
2157 ni1_release_l3_process(pc);
2159 pc->st->l3.l3l4(pc->st, CC_IGNORE | INDICATION, pc);
2164 l3ni1_dummy(struct l3_process *pc, u_char pr, void *arg)
2169 l3ni1_t302(struct l3_process *pc, u_char pr, void *arg)
2171 L3DelTimer(&pc->timer);
2173 pc->para.cause = 28; /* invalid number */
2174 l3ni1_disconnect_req(pc, pr, NULL);
2175 pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc);
2179 l3ni1_t303(struct l3_process *pc, u_char pr, void *arg)
2183 L3DelTimer(&pc->timer);
2184 l3ni1_setup_req(pc, pr, arg);
2186 L3DelTimer(&pc->timer);
2187 l3ni1_message_cause(pc, MT_RELEASE_COMPLETE, 102);
2188 pc->st->l3.l3l4(pc->st, CC_NOSETUP_RSP, pc);
2189 ni1_release_l3_process(pc);
2194 l3ni1_t304(struct l3_process *pc, u_char pr, void *arg)
2196 L3DelTimer(&pc->timer);
2198 pc->para.cause = 102;
2199 l3ni1_disconnect_req(pc, pr, NULL);
2200 pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc);
2205 l3ni1_t305(struct l3_process *pc, u_char pr, void *arg)
2210 struct sk_buff *skb;
2213 L3DelTimer(&pc->timer);
2214 if (pc->para.cause != NO_CAUSE)
2215 cause = pc->para.cause;
2217 MsgHead(p, pc->callref, MT_RELEASE);
2222 *p++ = cause | 0x80;
2225 if (!(skb = l3_alloc_skb(l)))
2227 memcpy(skb_put(skb, l), tmp, l);
2229 l3_msg(pc->st, DL_DATA | REQUEST, skb);
2230 L3AddTimer(&pc->timer, T308, CC_T308_1);
2234 l3ni1_t310(struct l3_process *pc, u_char pr, void *arg)
2236 L3DelTimer(&pc->timer);
2238 pc->para.cause = 102;
2239 l3ni1_disconnect_req(pc, pr, NULL);
2240 pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc);
2244 l3ni1_t313(struct l3_process *pc, u_char pr, void *arg)
2246 L3DelTimer(&pc->timer);
2248 pc->para.cause = 102;
2249 l3ni1_disconnect_req(pc, pr, NULL);
2250 pc->st->l3.l3l4(pc->st, CC_CONNECT_ERR, pc);
2254 l3ni1_t308_1(struct l3_process *pc, u_char pr, void *arg)
2257 L3DelTimer(&pc->timer);
2258 l3ni1_message(pc, MT_RELEASE);
2259 L3AddTimer(&pc->timer, T308, CC_T308_2);
2263 l3ni1_t308_2(struct l3_process *pc, u_char pr, void *arg)
2265 L3DelTimer(&pc->timer);
2266 pc->st->l3.l3l4(pc->st, CC_RELEASE_ERR, pc);
2267 ni1_release_l3_process(pc);
2271 l3ni1_t318(struct l3_process *pc, u_char pr, void *arg)
2273 L3DelTimer(&pc->timer);
2274 pc->para.cause = 102; /* Timer expiry */
2275 pc->para.loc = 0; /* local */
2276 pc->st->l3.l3l4(pc->st, CC_RESUME_ERR, pc);
2278 l3ni1_message(pc, MT_RELEASE);
2279 L3AddTimer(&pc->timer, T308, CC_T308_1);
2283 l3ni1_t319(struct l3_process *pc, u_char pr, void *arg)
2285 L3DelTimer(&pc->timer);
2286 pc->para.cause = 102; /* Timer expiry */
2287 pc->para.loc = 0; /* local */
2288 pc->st->l3.l3l4(pc->st, CC_SUSPEND_ERR, pc);
2293 l3ni1_restart(struct l3_process *pc, u_char pr, void *arg)
2295 L3DelTimer(&pc->timer);
2296 pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
2297 ni1_release_l3_process(pc);
2301 l3ni1_status(struct l3_process *pc, u_char pr, void *arg)
2304 struct sk_buff *skb = arg;
2306 u_char cause = 0, callState = 0;
2308 if ((ret = l3ni1_get_cause(pc, skb))) {
2309 if (pc->debug & L3_DEB_WARN)
2310 l3_debug(pc->st, "STATUS get_cause ret(%d)",ret);
2316 if ((p = findie(skb->data, skb->len, IE_CALL_STATE, 0))) {
2320 if (!ie_in_set(pc, *p, l3_valid_states))
2326 if (!cause) { /* no error before */
2327 ret = check_infoelements(pc, skb, ie_STATUS);
2328 if (ERR_IE_COMPREHENSION == ret)
2330 else if (ERR_IE_UNRECOGNIZED == ret)
2336 if (pc->debug & L3_DEB_WARN)
2337 l3_debug(pc->st, "STATUS error(%d/%d)",ret,cause);
2338 tmp = pc->para.cause;
2339 pc->para.cause = cause;
2340 l3ni1_status_send(pc, 0, NULL);
2342 pc->para.cause = tmp;
2346 cause = pc->para.cause;
2347 if (((cause & 0x7f) == 111) && (callState == 0)) {
2348 /* ETS 300-104 7.6.1, 8.6.1, 10.6.1...
2349 * if received MT_STATUS with cause == 111 and call
2350 * state == 0, then we must set down layer 3
2352 pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
2354 ni1_release_l3_process(pc);
2359 l3ni1_facility(struct l3_process *pc, u_char pr, void *arg)
2361 struct sk_buff *skb = arg;
2364 ret = check_infoelements(pc, skb, ie_FACILITY);
2365 l3ni1_std_ie_err(pc, ret);
2368 if ((p = findie(skb->data, skb->len, IE_FACILITY, 0)))
2369 l3ni1_parse_facility(pc->st, pc, pc->callref, p);
2374 l3ni1_suspend_req(struct l3_process *pc, u_char pr, void *arg)
2376 struct sk_buff *skb;
2380 u_char *msg = pc->chan->setup.phone;
2382 MsgHead(p, pc->callref, MT_SUSPEND);
2384 if (l && (l <= 10)) { /* Max length 10 octets */
2387 for (i = 0; i < l; i++)
2390 l3_debug(pc->st, "SUS wrong CALL_ID len %d", l);
2394 if (!(skb = l3_alloc_skb(l)))
2396 memcpy(skb_put(skb, l), tmp, l);
2397 l3_msg(pc->st, DL_DATA | REQUEST, skb);
2399 L3AddTimer(&pc->timer, T319, CC_T319);
2403 l3ni1_suspend_ack(struct l3_process *pc, u_char pr, void *arg)
2405 struct sk_buff *skb = arg;
2408 L3DelTimer(&pc->timer);
2410 pc->para.cause = NO_CAUSE;
2411 pc->st->l3.l3l4(pc->st, CC_SUSPEND | CONFIRM, pc);
2412 /* We don't handle suspend_ack for IE errors now */
2413 if ((ret = check_infoelements(pc, skb, ie_SUSPEND_ACKNOWLEDGE)))
2414 if (pc->debug & L3_DEB_WARN)
2415 l3_debug(pc->st, "SUSPACK check ie(%d)",ret);
2416 ni1_release_l3_process(pc);
2420 l3ni1_suspend_rej(struct l3_process *pc, u_char pr, void *arg)
2422 struct sk_buff *skb = arg;
2425 if ((ret = l3ni1_get_cause(pc, skb))) {
2426 if (pc->debug & L3_DEB_WARN)
2427 l3_debug(pc->st, "SUSP_REJ get_cause ret(%d)",ret);
2429 pc->para.cause = 96;
2431 pc->para.cause = 100;
2432 l3ni1_status_send(pc, pr, NULL);
2435 ret = check_infoelements(pc, skb, ie_SUSPEND_REJECT);
2436 if (ERR_IE_COMPREHENSION == ret) {
2437 l3ni1_std_ie_err(pc, ret);
2440 L3DelTimer(&pc->timer);
2441 pc->st->l3.l3l4(pc->st, CC_SUSPEND_ERR, pc);
2443 if (ret) /* STATUS for none mandatory IE errors after actions are taken */
2444 l3ni1_std_ie_err(pc, ret);
2448 l3ni1_resume_req(struct l3_process *pc, u_char pr, void *arg)
2450 struct sk_buff *skb;
2454 u_char *msg = pc->para.setup.phone;
2456 MsgHead(p, pc->callref, MT_RESUME);
2459 if (l && (l <= 10)) { /* Max length 10 octets */
2462 for (i = 0; i < l; i++)
2465 l3_debug(pc->st, "RES wrong CALL_ID len %d", l);
2469 if (!(skb = l3_alloc_skb(l)))
2471 memcpy(skb_put(skb, l), tmp, l);
2472 l3_msg(pc->st, DL_DATA | REQUEST, skb);
2474 L3AddTimer(&pc->timer, T318, CC_T318);
2478 l3ni1_resume_ack(struct l3_process *pc, u_char pr, void *arg)
2480 struct sk_buff *skb = arg;
2483 if ((id = l3ni1_get_channel_id(pc, skb)) > 0) {
2484 if ((0 == id) || ((3 == id) && (0x10 == pc->para.moderate))) {
2485 if (pc->debug & L3_DEB_WARN)
2486 l3_debug(pc->st, "resume ack with wrong chid %x", id);
2487 pc->para.cause = 100;
2488 l3ni1_status_send(pc, pr, NULL);
2491 pc->para.bchannel = id;
2492 } else if (1 == pc->state) {
2493 if (pc->debug & L3_DEB_WARN)
2494 l3_debug(pc->st, "resume ack without chid (ret %d)", id);
2495 pc->para.cause = 96;
2496 l3ni1_status_send(pc, pr, NULL);
2499 ret = check_infoelements(pc, skb, ie_RESUME_ACKNOWLEDGE);
2500 if (ERR_IE_COMPREHENSION == ret) {
2501 l3ni1_std_ie_err(pc, ret);
2504 L3DelTimer(&pc->timer);
2505 pc->st->l3.l3l4(pc->st, CC_RESUME | CONFIRM, pc);
2507 if (ret) /* STATUS for none mandatory IE errors after actions are taken */
2508 l3ni1_std_ie_err(pc, ret);
2512 l3ni1_resume_rej(struct l3_process *pc, u_char pr, void *arg)
2514 struct sk_buff *skb = arg;
2517 if ((ret = l3ni1_get_cause(pc, skb))) {
2518 if (pc->debug & L3_DEB_WARN)
2519 l3_debug(pc->st, "RES_REJ get_cause ret(%d)",ret);
2521 pc->para.cause = 96;
2523 pc->para.cause = 100;
2524 l3ni1_status_send(pc, pr, NULL);
2527 ret = check_infoelements(pc, skb, ie_RESUME_REJECT);
2528 if (ERR_IE_COMPREHENSION == ret) {
2529 l3ni1_std_ie_err(pc, ret);
2532 L3DelTimer(&pc->timer);
2533 pc->st->l3.l3l4(pc->st, CC_RESUME_ERR, pc);
2535 if (ret) /* STATUS for none mandatory IE errors after actions are taken */
2536 l3ni1_std_ie_err(pc, ret);
2537 ni1_release_l3_process(pc);
2541 l3ni1_global_restart(struct l3_process *pc, u_char pr, void *arg)
2545 u_char ri, ch = 0, chan = 0;
2547 struct sk_buff *skb = arg;
2548 struct l3_process *up;
2551 L3DelTimer(&pc->timer);
2553 if ((p = findie(p, skb->len, IE_RESTART_IND, 0))) {
2555 l3_debug(pc->st, "Restart %x", ri);
2557 l3_debug(pc->st, "Restart without restart IE");
2561 if ((p = findie(p, skb->len, IE_CHANNEL_ID, 0))) {
2564 if (pc->st->l3.debug)
2565 l3_debug(pc->st, "Restart for channel %d", chan);
2568 up = pc->st->l3.proc;
2571 up->st->lli.l4l3(up->st, CC_RESTART | REQUEST, up);
2572 else if (up->para.bchannel == chan)
2573 up->st->lli.l4l3(up->st, CC_RESTART | REQUEST, up);
2578 MsgHead(p, pc->callref, MT_RESTART_ACKNOWLEDGE);
2580 *p++ = IE_CHANNEL_ID;
2584 *p++ = 0x79; /* RESTART Ind */
2588 if (!(skb = l3_alloc_skb(l)))
2590 memcpy(skb_put(skb, l), tmp, l);
2592 l3_msg(pc->st, DL_DATA | REQUEST, skb);
2596 l3ni1_dl_reset(struct l3_process *pc, u_char pr, void *arg)
2598 pc->para.cause = 0x29; /* Temporary failure */
2600 l3ni1_disconnect_req(pc, pr, NULL);
2601 pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc);
2605 l3ni1_dl_release(struct l3_process *pc, u_char pr, void *arg)
2608 pc->para.cause = 0x1b; /* Destination out of order */
2610 pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
2611 release_l3_process(pc);
2615 l3ni1_dl_reestablish(struct l3_process *pc, u_char pr, void *arg)
2617 L3DelTimer(&pc->timer);
2618 L3AddTimer(&pc->timer, T309, CC_T309);
2619 l3_msg(pc->st, DL_ESTABLISH | REQUEST, NULL);
2623 l3ni1_dl_reest_status(struct l3_process *pc, u_char pr, void *arg)
2625 L3DelTimer(&pc->timer);
2627 pc->para.cause = 0x1F; /* normal, unspecified */
2628 l3ni1_status_send(pc, 0, NULL);
2631 static void l3ni1_SendSpid( struct l3_process *pc, u_char pr, struct sk_buff *skb, int iNewState )
2635 struct Channel * pChan = pc->st->lli.userdata;
2639 dev_kfree_skb( skb);
2641 if ( !( pSPID = strchr( pChan->setup.eazmsn, ':' ) ) )
2643 printk( KERN_ERR "SPID not supplied in EAZMSN %s\n", pChan->setup.eazmsn );
2644 newl3state( pc, 0 );
2645 pc->st->l3.l3l2( pc->st, DL_RELEASE | REQUEST, NULL );
2649 l = strlen( ++pSPID );
2650 if ( !( skb = l3_alloc_skb( 5+l ) ) )
2652 printk( KERN_ERR "HiSax can't get memory to send SPID\n" );
2656 p = skb_put( skb, 5 );
2657 *p++ = PROTO_DIS_EURO;
2659 *p++ = MT_INFORMATION;
2663 memcpy( skb_put( skb, l ), pSPID, l );
2665 newl3state( pc, iNewState );
2667 L3DelTimer( &pc->timer );
2668 L3AddTimer( &pc->timer, TSPID, CC_TSPID );
2670 pc->st->l3.l3l2( pc->st, DL_DATA | REQUEST, skb );
2673 static void l3ni1_spid_send( struct l3_process *pc, u_char pr, void *arg )
2675 l3ni1_SendSpid( pc, pr, arg, 20 );
2678 void l3ni1_spid_epid( struct l3_process *pc, u_char pr, void *arg )
2680 struct sk_buff *skb = arg;
2682 if ( skb->data[ 1 ] == 0 )
2683 if ( skb->data[ 3 ] == IE_ENDPOINT_ID )
2685 L3DelTimer( &pc->timer );
2686 newl3state( pc, 0 );
2687 l3_msg( pc->st, DL_ESTABLISH | CONFIRM, NULL );
2689 dev_kfree_skb( skb);
2692 static void l3ni1_spid_tout( struct l3_process *pc, u_char pr, void *arg )
2694 if ( pc->state < 22 )
2695 l3ni1_SendSpid( pc, pr, arg, pc->state+1 );
2698 L3DelTimer( &pc->timer );
2699 dev_kfree_skb( arg);
2701 printk( KERN_ERR "SPID not accepted\n" );
2702 newl3state( pc, 0 );
2703 pc->st->l3.l3l2( pc->st, DL_RELEASE | REQUEST, NULL );
2708 static struct stateentry downstatelist[] =
2711 CC_SETUP | REQUEST, l3ni1_setup_req},
2713 CC_RESUME | REQUEST, l3ni1_resume_req},
2714 {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(6) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | SBIT(25),
2715 CC_DISCONNECT | REQUEST, l3ni1_disconnect_req},
2717 CC_RELEASE | REQUEST, l3ni1_release_req},
2719 CC_RESTART | REQUEST, l3ni1_restart},
2720 {SBIT(6) | SBIT(25),
2721 CC_IGNORE | REQUEST, l3ni1_reset},
2722 {SBIT(6) | SBIT(25),
2723 CC_REJECT | REQUEST, l3ni1_reject_req},
2724 {SBIT(6) | SBIT(25),
2725 CC_PROCEED_SEND | REQUEST, l3ni1_proceed_req},
2727 CC_MORE_INFO | REQUEST, l3ni1_setup_ack_req},
2729 CC_MORE_INFO | REQUEST, l3ni1_dummy},
2730 {SBIT(6) | SBIT(9) | SBIT(25),
2731 CC_ALERTING | REQUEST, l3ni1_alert_req},
2732 {SBIT(6) | SBIT(7) | SBIT(9) | SBIT(25),
2733 CC_SETUP | RESPONSE, l3ni1_setup_rsp},
2735 CC_SUSPEND | REQUEST, l3ni1_suspend_req},
2736 {SBIT(7) | SBIT(9) | SBIT(25),
2737 CC_REDIR | REQUEST, l3ni1_redir_req},
2739 CC_REDIR | REQUEST, l3ni1_redir_req_early},
2740 {SBIT(9) | SBIT(25),
2741 CC_DISCONNECT | REQUEST, l3ni1_disconnect_req},
2743 CC_T302, l3ni1_t302},
2745 CC_T303, l3ni1_t303},
2747 CC_T304, l3ni1_t304},
2749 CC_T310, l3ni1_t310},
2751 CC_T313, l3ni1_t313},
2753 CC_T305, l3ni1_t305},
2755 CC_T319, l3ni1_t319},
2757 CC_T318, l3ni1_t318},
2759 CC_T308_1, l3ni1_t308_1},
2761 CC_T308_2, l3ni1_t308_2},
2763 CC_T309, l3ni1_dl_release},
2764 { SBIT( 20 ) | SBIT( 21 ) | SBIT( 22 ),
2765 CC_TSPID, l3ni1_spid_tout },
2769 (sizeof(downstatelist) / sizeof(struct stateentry))
2771 static struct stateentry datastatelist[] =
2774 MT_STATUS_ENQUIRY, l3ni1_status_enq},
2776 MT_FACILITY, l3ni1_facility},
2778 MT_STATUS, l3ni1_release_ind},
2780 MT_STATUS, l3ni1_status},
2782 MT_SETUP, l3ni1_setup},
2783 {SBIT(6) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | SBIT(11) | SBIT(12) |
2784 SBIT(15) | SBIT(17) | SBIT(19) | SBIT(25),
2785 MT_SETUP, l3ni1_dummy},
2787 MT_CALL_PROCEEDING, l3ni1_call_proc},
2789 MT_SETUP_ACKNOWLEDGE, l3ni1_setup_ack},
2791 MT_ALERTING, l3ni1_alerting},
2793 MT_PROGRESS, l3ni1_progress},
2794 {SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) |
2795 SBIT(11) | SBIT(12) | SBIT(15) | SBIT(17) | SBIT(19) | SBIT(25),
2796 MT_INFORMATION, l3ni1_information},
2797 {SBIT(10) | SBIT(11) | SBIT(15),
2798 MT_NOTIFY, l3ni1_notify},
2799 {SBIT(0) | SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(10) |
2800 SBIT(11) | SBIT(12) | SBIT(15) | SBIT(17) | SBIT(19) | SBIT(25),
2801 MT_RELEASE_COMPLETE, l3ni1_release_cmpl},
2802 {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | SBIT(11) | SBIT(12) | SBIT(15) | SBIT(17) | SBIT(25),
2803 MT_RELEASE, l3ni1_release},
2804 {SBIT(19), MT_RELEASE, l3ni1_release_ind},
2805 {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | SBIT(11) | SBIT(15) | SBIT(17) | SBIT(25),
2806 MT_DISCONNECT, l3ni1_disconnect},
2808 MT_DISCONNECT, l3ni1_dummy},
2809 {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4),
2810 MT_CONNECT, l3ni1_connect},
2812 MT_CONNECT_ACKNOWLEDGE, l3ni1_connect_ack},
2814 MT_SUSPEND_ACKNOWLEDGE, l3ni1_suspend_ack},
2816 MT_SUSPEND_REJECT, l3ni1_suspend_rej},
2818 MT_RESUME_ACKNOWLEDGE, l3ni1_resume_ack},
2820 MT_RESUME_REJECT, l3ni1_resume_rej},
2824 (sizeof(datastatelist) / sizeof(struct stateentry))
2826 static struct stateentry globalmes_list[] =
2829 MT_STATUS, l3ni1_status},
2831 MT_RESTART, l3ni1_global_restart},
2833 MT_RESTART_ACKNOWLEDGE, l3ni1_restart_ack},
2835 { SBIT( 0 ), MT_DL_ESTABLISHED, l3ni1_spid_send },
2836 { SBIT( 20 ) | SBIT( 21 ) | SBIT( 22 ), MT_INFORMATION, l3ni1_spid_epid },
2838 #define GLOBALM_LEN \
2839 (sizeof(globalmes_list) / sizeof(struct stateentry))
2841 static struct stateentry manstatelist[] =
2844 DL_ESTABLISH | INDICATION, l3ni1_dl_reset},
2846 DL_ESTABLISH | CONFIRM, l3ni1_dl_reest_status},
2848 DL_RELEASE | INDICATION, l3ni1_dl_reestablish},
2850 DL_RELEASE | INDICATION, l3ni1_dl_release},
2854 (sizeof(manstatelist) / sizeof(struct stateentry))
2859 global_handler(struct PStack *st, int mt, struct sk_buff *skb)
2865 struct l3_process *proc = st->l3.global;
2868 proc->callref = skb->data[2]; /* cr flag */
2871 for (i = 0; i < GLOBALM_LEN; i++)
2872 if ((mt == globalmes_list[i].primitive) &&
2873 ((1 << proc->state) & globalmes_list[i].state))
2875 if (i == GLOBALM_LEN) {
2876 if (st->l3.debug & L3_DEB_STATE) {
2877 l3_debug(st, "ni1 global state %d mt %x unhandled",
2880 MsgHead(p, proc->callref, MT_STATUS);
2884 *p++ = 81 |0x80; /* invalid cr */
2885 *p++ = 0x14; /* CallState */
2887 *p++ = proc->state & 0x3f;
2889 if (!(skb = l3_alloc_skb(l)))
2891 memcpy(skb_put(skb, l), tmp, l);
2892 l3_msg(proc->st, DL_DATA | REQUEST, skb);
2894 if (st->l3.debug & L3_DEB_STATE) {
2895 l3_debug(st, "ni1 global %d mt %x",
2898 globalmes_list[i].rout(proc, mt, skb);
2903 ni1up(struct PStack *st, int pr, void *arg)
2905 int i, mt, cr, cause, callState;
2908 struct sk_buff *skb = arg;
2909 struct l3_process *proc;
2912 case (DL_DATA | INDICATION):
2913 case (DL_UNIT_DATA | INDICATION):
2915 case (DL_ESTABLISH | INDICATION):
2916 case (DL_RELEASE | INDICATION):
2917 case (DL_RELEASE | CONFIRM):
2918 l3_msg(st, pr, arg);
2922 case (DL_ESTABLISH | CONFIRM):
2923 global_handler( st, MT_DL_ESTABLISHED, NULL );
2927 printk(KERN_ERR "HiSax ni1up unknown pr=%04x\n", pr);
2931 l3_debug(st, "ni1up frame too short(%d)", skb->len);
2936 if (skb->data[0] != PROTO_DIS_EURO) {
2937 if (st->l3.debug & L3_DEB_PROTERR) {
2938 l3_debug(st, "ni1up%sunexpected discriminator %x message len %d",
2939 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
2940 skb->data[0], skb->len);
2945 cr = getcallref(skb->data);
2946 if (skb->len < ((skb->data[1] & 0x0f) + 3)) {
2947 l3_debug(st, "ni1up frame too short(%d)", skb->len);
2951 mt = skb->data[skb->data[1] + 2];
2952 if (st->l3.debug & L3_DEB_STATE)
2953 l3_debug(st, "ni1up cr %d", cr);
2954 if (cr == -2) { /* wrong Callref */
2955 if (st->l3.debug & L3_DEB_WARN)
2956 l3_debug(st, "ni1up wrong Callref");
2959 } else if (cr == -1) { /* Dummy Callref */
2960 if (mt == MT_FACILITY)
2962 if ((p = findie(skb->data, skb->len, IE_FACILITY, 0))) {
2963 l3ni1_parse_facility(st, NULL,
2964 (pr == (DL_DATA | INDICATION)) ? -1 : -2, p);
2971 global_handler(st, mt, skb);
2975 if (st->l3.debug & L3_DEB_WARN)
2976 l3_debug(st, "ni1up dummy Callref (no facility msg or ie)");
2979 } else if ((((skb->data[1] & 0x0f) == 1) && (0==(cr & 0x7f))) ||
2980 (((skb->data[1] & 0x0f) == 2) && (0==(cr & 0x7fff)))) { /* Global CallRef */
2981 if (st->l3.debug & L3_DEB_STATE)
2982 l3_debug(st, "ni1up Global CallRef");
2983 global_handler(st, mt, skb);
2986 } else if (!(proc = getl3proc(st, cr))) {
2987 /* No transaction process exist, that means no call with
2988 * this callreference is active
2990 if (mt == MT_SETUP) {
2991 /* Setup creates a new transaction process */
2992 if (skb->data[2] & 0x80) {
2993 /* Setup with wrong CREF flag */
2994 if (st->l3.debug & L3_DEB_STATE)
2995 l3_debug(st, "ni1up wrong CRef flag");
2999 if (!(proc = ni1_new_l3_process(st, cr))) {
3000 /* May be to answer with RELEASE_COMPLETE and
3001 * CAUSE 0x2f "Resource unavailable", but this
3002 * need a new_l3_process too ... arghh
3007 } else if (mt == MT_STATUS) {
3009 if ((ptr = findie(skb->data, skb->len, IE_CAUSE, 0)) != NULL) {
3013 cause = *ptr & 0x7f;
3016 if ((ptr = findie(skb->data, skb->len, IE_CALL_STATE, 0)) != NULL) {
3022 /* ETS 300-104 part 2.4.1
3023 * if setup has not been made and a message type
3024 * MT_STATUS is received with call state == 0,
3025 * we must send nothing
3027 if (callState != 0) {
3028 /* ETS 300-104 part 2.4.2
3029 * if setup has not been made and a message type
3030 * MT_STATUS is received with call state != 0,
3031 * we must send MT_RELEASE_COMPLETE cause 101
3033 if ((proc = ni1_new_l3_process(st, cr))) {
3034 proc->para.cause = 101;
3035 l3ni1_msg_without_setup(proc, 0, NULL);
3040 } else if (mt == MT_RELEASE_COMPLETE) {
3044 /* ETS 300-104 part 2
3045 * if setup has not been made and a message type
3046 * (except MT_SETUP and RELEASE_COMPLETE) is received,
3047 * we must send MT_RELEASE_COMPLETE cause 81 */
3049 if ((proc = ni1_new_l3_process(st, cr))) {
3050 proc->para.cause = 81;
3051 l3ni1_msg_without_setup(proc, 0, NULL);
3056 if (l3ni1_check_messagetype_validity(proc, mt, skb)) {
3060 if ((p = findie(skb->data, skb->len, IE_DISPLAY, 0)) != NULL)
3061 l3ni1_deliver_display(proc, pr, p); /* Display IE included */
3062 for (i = 0; i < DATASLLEN; i++)
3063 if ((mt == datastatelist[i].primitive) &&
3064 ((1 << proc->state) & datastatelist[i].state))
3066 if (i == DATASLLEN) {
3067 if (st->l3.debug & L3_DEB_STATE) {
3068 l3_debug(st, "ni1up%sstate %d mt %#x unhandled",
3069 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
3072 if ((MT_RELEASE_COMPLETE != mt) && (MT_RELEASE != mt)) {
3073 proc->para.cause = 101;
3074 l3ni1_status_send(proc, pr, skb);
3077 if (st->l3.debug & L3_DEB_STATE) {
3078 l3_debug(st, "ni1up%sstate %d mt %x",
3079 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
3082 datastatelist[i].rout(proc, pr, skb);
3089 ni1down(struct PStack *st, int pr, void *arg)
3092 struct l3_process *proc;
3093 struct Channel *chan;
3095 if ((DL_ESTABLISH | REQUEST) == pr) {
3096 l3_msg(st, pr, NULL);
3098 } else if (((CC_SETUP | REQUEST) == pr) || ((CC_RESUME | REQUEST) == pr)) {
3102 if ((proc = ni1_new_l3_process(st, cr))) {
3105 memcpy(&proc->para.setup, &chan->setup, sizeof(setup_parm));
3112 printk(KERN_ERR "HiSax ni1down without proc pr=%04x\n", pr);
3116 if ( pr == (CC_TNI1_IO | REQUEST)) {
3117 l3ni1_io_timer(proc); /* timer expires */
3121 for (i = 0; i < DOWNSLLEN; i++)
3122 if ((pr == downstatelist[i].primitive) &&
3123 ((1 << proc->state) & downstatelist[i].state))
3125 if (i == DOWNSLLEN) {
3126 if (st->l3.debug & L3_DEB_STATE) {
3127 l3_debug(st, "ni1down state %d prim %#x unhandled",
3131 if (st->l3.debug & L3_DEB_STATE) {
3132 l3_debug(st, "ni1down state %d prim %#x",
3135 downstatelist[i].rout(proc, pr, arg);
3140 ni1man(struct PStack *st, int pr, void *arg)
3143 struct l3_process *proc = arg;
3146 printk(KERN_ERR "HiSax ni1man without proc pr=%04x\n", pr);
3149 for (i = 0; i < MANSLLEN; i++)
3150 if ((pr == manstatelist[i].primitive) &&
3151 ((1 << proc->state) & manstatelist[i].state))
3153 if (i == MANSLLEN) {
3154 if (st->l3.debug & L3_DEB_STATE) {
3155 l3_debug(st, "cr %d ni1man state %d prim %#x unhandled",
3156 proc->callref & 0x7f, proc->state, pr);
3159 if (st->l3.debug & L3_DEB_STATE) {
3160 l3_debug(st, "cr %d ni1man state %d prim %#x",
3161 proc->callref & 0x7f, proc->state, pr);
3163 manstatelist[i].rout(proc, pr, arg);
3168 setstack_ni1(struct PStack *st)
3173 st->lli.l4l3 = ni1down;
3174 st->lli.l4l3_proto = l3ni1_cmd_global;
3175 st->l2.l2l3 = ni1up;
3176 st->l3.l3ml3 = ni1man;
3178 st->prot.ni1.last_invoke_id = 0;
3179 st->prot.ni1.invoke_used[0] = 1; /* Bit 0 must always be set to 1 */
3182 st->prot.ni1.invoke_used[i++] = 0;
3184 if (!(st->l3.global = kmalloc(sizeof(struct l3_process), GFP_ATOMIC))) {
3185 printk(KERN_ERR "HiSax can't get memory for ni1 global CR\n");
3187 st->l3.global->state = 0;
3188 st->l3.global->callref = 0;
3189 st->l3.global->next = NULL;
3190 st->l3.global->debug = L3_DEB_WARN;
3191 st->l3.global->st = st;
3192 st->l3.global->N303 = 1;
3193 st->l3.global->prot.ni1.invoke_id = 0;
3195 L3InitTimer(st->l3.global, &st->l3.global->timer);
3197 strcpy(tmp, ni1_revision);
3198 printk(KERN_INFO "HiSax: National ISDN-1 Rev. %s\n", HiSax_getrev(tmp));