1 /* $Id: l3ni1.c,v 2.8.2.3 2004/01/13 14:31:25 keil 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
24 #include <linux/ctype.h>
26 extern char *HiSax_getrev(const char *revision);
27 static const char *ni1_revision = "$Revision: 2.8.2.3 $";
29 #define EXT_BEARER_CAPS 1
31 #define MsgHead(ptr, cref, mty) \
42 /**********************************************/
43 /* get a new invoke id for remote operations. */
44 /* Only a return value != 0 is valid */
45 /**********************************************/
46 static unsigned char new_invoke_id(struct PStack *p)
51 i = 32; /* maximum search depth */
53 retval = p->prot.ni1.last_invoke_id + 1; /* try new id */
54 while ((i) && (p->prot.ni1.invoke_used[retval >> 3] == 0xFF)) {
55 p->prot.ni1.last_invoke_id = (retval & 0xF8) + 8;
59 while (p->prot.ni1.invoke_used[retval >> 3] & (1 << (retval & 7)))
63 p->prot.ni1.last_invoke_id = retval;
64 p->prot.ni1.invoke_used[retval >> 3] |= (1 << (retval & 7));
68 /*************************/
69 /* free a used invoke id */
70 /*************************/
71 static void free_invoke_id(struct PStack *p, unsigned char id)
74 if (!id) return; /* 0 = invalid value */
76 p->prot.ni1.invoke_used[id >> 3] &= ~(1 << (id & 7));
77 } /* free_invoke_id */
80 /**********************************************************/
81 /* create a new l3 process and fill in ni1 specific data */
82 /**********************************************************/
83 static struct l3_process
84 *ni1_new_l3_process(struct PStack *st, int cr)
85 { struct l3_process *proc;
87 if (!(proc = new_l3_process(st, cr)))
90 proc->prot.ni1.invoke_id = 0;
91 proc->prot.ni1.remote_operation = 0;
92 proc->prot.ni1.uus1_data[0] = '\0';
95 } /* ni1_new_l3_process */
97 /************************************************/
98 /* free a l3 process and all ni1 specific data */
99 /************************************************/
101 ni1_release_l3_process(struct l3_process *p)
103 free_invoke_id(p->st,p->prot.ni1.invoke_id);
104 release_l3_process(p);
105 } /* ni1_release_l3_process */
107 /********************************************************/
108 /* search a process with invoke id id and dummy callref */
109 /********************************************************/
110 static struct l3_process *
111 l3ni1_search_dummy_proc(struct PStack *st, int id)
112 { struct l3_process *pc = st->l3.proc; /* start of processes */
114 if (!id) return(NULL);
117 { if ((pc->callref == -1) && (pc->prot.ni1.invoke_id == id))
122 } /* l3ni1_search_dummy_proc */
124 /*******************************************************************/
125 /* called when a facility message with a dummy callref is received */
126 /* and a return result is delivered. id specifies the invoke id. */
127 /*******************************************************************/
129 l3ni1_dummy_return_result(struct PStack *st, int id, u_char *p, u_char nlen)
131 struct IsdnCardState *cs;
132 struct l3_process *pc = NULL;
134 if ((pc = l3ni1_search_dummy_proc(st, id)))
135 { L3DelTimer(&pc->timer); /* remove timer */
137 cs = pc->st->l1.hardware;
138 ic.driver = cs->myid;
139 ic.command = ISDN_STAT_PROT;
140 ic.arg = NI1_STAT_INVOKE_RES;
141 ic.parm.ni1_io.hl_id = pc->prot.ni1.invoke_id;
142 ic.parm.ni1_io.ll_id = pc->prot.ni1.ll_id;
143 ic.parm.ni1_io.proc = pc->prot.ni1.proc;
144 ic.parm.ni1_io.timeout= 0;
145 ic.parm.ni1_io.datalen = nlen;
146 ic.parm.ni1_io.data = p;
147 free_invoke_id(pc->st, pc->prot.ni1.invoke_id);
148 pc->prot.ni1.invoke_id = 0; /* reset id */
150 cs->iif.statcallb(&ic);
151 ni1_release_l3_process(pc);
154 l3_debug(st, "dummy return result id=0x%x result len=%d",id,nlen);
155 } /* l3ni1_dummy_return_result */
157 /*******************************************************************/
158 /* called when a facility message with a dummy callref is received */
159 /* and a return error is delivered. id specifies the invoke id. */
160 /*******************************************************************/
162 l3ni1_dummy_error_return(struct PStack *st, int id, ulong error)
164 struct IsdnCardState *cs;
165 struct l3_process *pc = NULL;
167 if ((pc = l3ni1_search_dummy_proc(st, id)))
168 { L3DelTimer(&pc->timer); /* remove timer */
170 cs = pc->st->l1.hardware;
171 ic.driver = cs->myid;
172 ic.command = ISDN_STAT_PROT;
173 ic.arg = NI1_STAT_INVOKE_ERR;
174 ic.parm.ni1_io.hl_id = pc->prot.ni1.invoke_id;
175 ic.parm.ni1_io.ll_id = pc->prot.ni1.ll_id;
176 ic.parm.ni1_io.proc = pc->prot.ni1.proc;
177 ic.parm.ni1_io.timeout= error;
178 ic.parm.ni1_io.datalen = 0;
179 ic.parm.ni1_io.data = NULL;
180 free_invoke_id(pc->st, pc->prot.ni1.invoke_id);
181 pc->prot.ni1.invoke_id = 0; /* reset id */
183 cs->iif.statcallb(&ic);
184 ni1_release_l3_process(pc);
187 l3_debug(st, "dummy return error id=0x%x error=0x%lx",id,error);
188 } /* l3ni1_error_return */
190 /*******************************************************************/
191 /* called when a facility message with a dummy callref is received */
192 /* and a invoke is delivered. id specifies the invoke id. */
193 /*******************************************************************/
195 l3ni1_dummy_invoke(struct PStack *st, int cr, int id,
196 int ident, u_char *p, u_char nlen)
198 struct IsdnCardState *cs;
200 l3_debug(st, "dummy invoke %s id=0x%x ident=0x%x datalen=%d",
201 (cr == -1) ? "local" : "broadcast",id,ident,nlen);
202 if (cr >= -1) return; /* ignore local data */
204 cs = st->l1.hardware;
205 ic.driver = cs->myid;
206 ic.command = ISDN_STAT_PROT;
207 ic.arg = NI1_STAT_INVOKE_BRD;
208 ic.parm.ni1_io.hl_id = id;
209 ic.parm.ni1_io.ll_id = 0;
210 ic.parm.ni1_io.proc = ident;
211 ic.parm.ni1_io.timeout= 0;
212 ic.parm.ni1_io.datalen = nlen;
213 ic.parm.ni1_io.data = p;
215 cs->iif.statcallb(&ic);
216 } /* l3ni1_dummy_invoke */
219 l3ni1_parse_facility(struct PStack *st, struct l3_process *pc,
223 unsigned char nlen = 0, ilen, cp_tag;
228 st = pc->st; /* valid Stack */
230 if ((!st) || (cr >= 0)) return; /* neither pc nor st specified */
235 l3_debug(st, "qd_len == 0");
238 if ((*p & 0x1F) != 0x11) { /* Service discriminator, supplementary service */
239 l3_debug(st, "supplementary service != 0x11");
242 while (qd_len > 0 && !(*p & 0x80)) { /* extension ? */
247 l3_debug(st, "qd_len < 2");
252 if ((*p & 0xE0) != 0xA0) { /* class and form */
253 l3_debug(st, "class and form != 0xA0");
257 cp_tag = *p & 0x1F; /* remember tag value */
262 { l3_debug(st, "qd_len < 1");
266 { /* length format indefinite or limited */
267 nlen = *p++ & 0x7F; /* number of len bytes or indefinite */
268 if ((qd_len-- < ((!nlen) ? 3 : (1 + nlen))) ||
270 { l3_debug(st, "length format error or not implemented");
274 { nlen = *p++; /* complete length */
278 { qd_len -= 2; /* trailing null bytes */
279 if ((*(p+qd_len)) || (*(p+qd_len+1)))
280 { l3_debug(st,"length format indefinite error");
291 { l3_debug(st, "qd_len < nlen");
297 { l3_debug(st, "nlen < 2");
301 { /* invoke identifier tag */
302 l3_debug(st, "invoke identifier tag !=0x02");
308 { /* length format */
309 l3_debug(st, "invoke id length format 2");
314 if (ilen > nlen || ilen == 0)
315 { l3_debug(st, "ilen > nlen || ilen == 0");
321 { id = (id << 8) | (*p++ & 0xFF); /* invoke identifier */
325 switch (cp_tag) { /* component tag */
328 l3_debug(st, "nlen < 2 22");
331 if (*p != 0x02) { /* operation value */
332 l3_debug(st, "operation value !=0x02");
339 if (ilen > nlen || ilen == 0) {
340 l3_debug(st, "ilen > nlen || ilen == 0 22");
346 ident = (ident << 8) | (*p++ & 0xFF);
352 l3ni1_dummy_invoke(st, cr, id, ident, p, nlen);
355 l3_debug(st, "invoke break");
357 case 2: /* return result */
358 /* if no process available handle separately */
361 l3ni1_dummy_return_result(st, id, p, nlen);
364 if ((pc->prot.ni1.invoke_id) && (pc->prot.ni1.invoke_id == id))
365 { /* Diversion successful */
366 free_invoke_id(st,pc->prot.ni1.invoke_id);
367 pc->prot.ni1.remote_result = 0; /* success */
368 pc->prot.ni1.invoke_id = 0;
369 pc->redir_result = pc->prot.ni1.remote_result;
370 st->l3.l3l4(st, CC_REDIR | INDICATION, pc); } /* Diversion successful */
372 l3_debug(st,"return error unknown identifier");
374 case 3: /* return error */
377 { l3_debug(st, "return error nlen < 2");
382 l3_debug(st, "invoke error tag !=0x02");
388 { /* length format */
389 l3_debug(st, "invoke return errlen > 4 ");
394 if (ilen > nlen || ilen == 0)
395 { l3_debug(st, "error return ilen > nlen || ilen == 0");
400 { err_ret = (err_ret << 8) | (*p++ & 0xFF); /* error value */
403 /* if no process available handle separately */
406 l3ni1_dummy_error_return(st, id, err_ret);
409 if ((pc->prot.ni1.invoke_id) && (pc->prot.ni1.invoke_id == id))
410 { /* Deflection error */
411 free_invoke_id(st,pc->prot.ni1.invoke_id);
412 pc->prot.ni1.remote_result = err_ret; /* result */
413 pc->prot.ni1.invoke_id = 0;
414 pc->redir_result = pc->prot.ni1.remote_result;
415 st->l3.l3l4(st, CC_REDIR | INDICATION, pc);
416 } /* Deflection error */
418 l3_debug(st,"return result unknown identifier");
421 l3_debug(st, "facility default break tag=0x%02x",cp_tag);
427 l3ni1_message(struct l3_process *pc, u_char mt)
432 if (!(skb = l3_alloc_skb(4)))
435 MsgHead(p, pc->callref, mt);
436 l3_msg(pc->st, DL_DATA | REQUEST, skb);
440 l3ni1_message_plus_chid(struct l3_process *pc, u_char mt)
441 /* sends an l3 messages plus channel id - added GE 05/09/00 */
448 chid = (u_char)(pc->para.bchannel & 0x03) | 0x88;
449 MsgHead(p, pc->callref, mt);
450 *p++ = IE_CHANNEL_ID;
454 if (!(skb = l3_alloc_skb(7)))
456 memcpy(skb_put(skb, 7), tmp, 7);
457 l3_msg(pc->st, DL_DATA | REQUEST, skb);
461 l3ni1_message_cause(struct l3_process *pc, u_char mt, u_char cause)
468 MsgHead(p, pc->callref, mt);
475 if (!(skb = l3_alloc_skb(l)))
477 memcpy(skb_put(skb, l), tmp, l);
478 l3_msg(pc->st, DL_DATA | REQUEST, skb);
482 l3ni1_status_send(struct l3_process *pc, u_char pr, void *arg)
489 MsgHead(p, pc->callref, MT_STATUS);
494 *p++ = pc->para.cause | 0x80;
496 *p++ = IE_CALL_STATE;
498 *p++ = pc->state & 0x3f;
501 if (!(skb = l3_alloc_skb(l)))
503 memcpy(skb_put(skb, l), tmp, l);
504 l3_msg(pc->st, DL_DATA | REQUEST, skb);
508 l3ni1_msg_without_setup(struct l3_process *pc, u_char pr, void *arg)
510 /* This routine is called if here was no SETUP made (checks in ni1up and in
511 * l3ni1_setup) and a RELEASE_COMPLETE have to be sent with an error code
512 * MT_STATUS_ENQUIRE in the NULL state is handled too
519 switch (pc->para.cause) {
520 case 81: /* invalid callreference */
521 case 88: /* incomp destination */
522 case 96: /* mandory IE missing */
523 case 100: /* invalid IE contents */
524 case 101: /* incompatible Callstate */
525 MsgHead(p, pc->callref, MT_RELEASE_COMPLETE);
529 *p++ = pc->para.cause | 0x80;
532 printk(KERN_ERR "HiSax l3ni1_msg_without_setup wrong cause %d\n",
537 if (!(skb = l3_alloc_skb(l)))
539 memcpy(skb_put(skb, l), tmp, l);
540 l3_msg(pc->st, DL_DATA | REQUEST, skb);
541 ni1_release_l3_process(pc);
544 static int ie_ALERTING[] = {IE_BEARER, IE_CHANNEL_ID | IE_MANDATORY_1,
545 IE_FACILITY, IE_PROGRESS, IE_DISPLAY, IE_SIGNAL, IE_HLC,
547 static int ie_CALL_PROCEEDING[] = {IE_BEARER, IE_CHANNEL_ID | IE_MANDATORY_1,
548 IE_FACILITY, IE_PROGRESS, IE_DISPLAY, IE_HLC, -1};
549 static int ie_CONNECT[] = {IE_BEARER, IE_CHANNEL_ID | IE_MANDATORY_1,
550 IE_FACILITY, IE_PROGRESS, IE_DISPLAY, IE_DATE, IE_SIGNAL,
551 IE_CONNECT_PN, IE_CONNECT_SUB, IE_LLC, IE_HLC, IE_USER_USER, -1};
552 static int ie_CONNECT_ACKNOWLEDGE[] = {IE_CHANNEL_ID, IE_DISPLAY, IE_SIGNAL, -1};
553 static int ie_DISCONNECT[] = {IE_CAUSE | IE_MANDATORY, IE_FACILITY,
554 IE_PROGRESS, IE_DISPLAY, IE_SIGNAL, IE_USER_USER, -1};
555 static int ie_INFORMATION[] = {IE_COMPLETE, IE_DISPLAY, IE_KEYPAD, IE_SIGNAL,
557 static int ie_NOTIFY[] = {IE_BEARER, IE_NOTIFY | IE_MANDATORY, IE_DISPLAY, -1};
558 static int ie_PROGRESS[] = {IE_BEARER, IE_CAUSE, IE_FACILITY, IE_PROGRESS |
559 IE_MANDATORY, IE_DISPLAY, IE_HLC, IE_USER_USER, -1};
560 static int ie_RELEASE[] = {IE_CAUSE | IE_MANDATORY_1, IE_FACILITY, IE_DISPLAY,
561 IE_SIGNAL, IE_USER_USER, -1};
562 /* a RELEASE_COMPLETE with errors don't require special actions
563 static int ie_RELEASE_COMPLETE[] = {IE_CAUSE | IE_MANDATORY_1, IE_DISPLAY, IE_SIGNAL, IE_USER_USER, -1};
565 static int ie_RESUME_ACKNOWLEDGE[] = {IE_CHANNEL_ID| IE_MANDATORY, IE_FACILITY,
567 static int ie_RESUME_REJECT[] = {IE_CAUSE | IE_MANDATORY, IE_DISPLAY, -1};
568 static int ie_SETUP[] = {IE_COMPLETE, IE_BEARER | IE_MANDATORY,
569 IE_CHANNEL_ID| IE_MANDATORY, IE_FACILITY, IE_PROGRESS,
570 IE_NET_FAC, IE_DISPLAY, IE_KEYPAD, IE_SIGNAL, IE_CALLING_PN,
571 IE_CALLING_SUB, IE_CALLED_PN, IE_CALLED_SUB, IE_REDIR_NR,
572 IE_LLC, IE_HLC, IE_USER_USER, -1};
573 static int ie_SETUP_ACKNOWLEDGE[] = {IE_CHANNEL_ID | IE_MANDATORY, IE_FACILITY,
574 IE_PROGRESS, IE_DISPLAY, IE_SIGNAL, -1};
575 static int ie_STATUS[] = {IE_CAUSE | IE_MANDATORY, IE_CALL_STATE |
576 IE_MANDATORY, IE_DISPLAY, -1};
577 static int ie_STATUS_ENQUIRY[] = {IE_DISPLAY, -1};
578 static int ie_SUSPEND_ACKNOWLEDGE[] = {IE_DISPLAY, IE_FACILITY, -1};
579 static int ie_SUSPEND_REJECT[] = {IE_CAUSE | IE_MANDATORY, IE_DISPLAY, -1};
581 * static int ie_CONGESTION_CONTROL[] = {IE_CONGESTION | IE_MANDATORY,
582 * IE_CAUSE | IE_MANDATORY, IE_DISPLAY, -1};
583 * static int ie_USER_INFORMATION[] = {IE_MORE_DATA, IE_USER_USER | IE_MANDATORY, -1};
584 * static int ie_RESTART[] = {IE_CHANNEL_ID, IE_DISPLAY, IE_RESTART_IND |
587 static int ie_FACILITY[] = {IE_FACILITY | IE_MANDATORY, IE_DISPLAY, -1};
588 static int comp_required[] = {1,2,3,5,6,7,9,10,11,14,15,-1};
589 static int l3_valid_states[] = {0,1,2,3,4,6,7,8,9,10,11,12,15,17,19,25,-1};
597 struct ie_len max_ie_len[] = {
615 {IE_PACK_BINPARA, 3},
616 {IE_PACK_WINSIZE, 4},
621 {IE_CALLING_SUB, 23},
634 getmax_ie_len(u_char ie) {
636 while (max_ie_len[i].ie != -1) {
637 if (max_ie_len[i].ie == ie)
638 return(max_ie_len[i].len);
645 ie_in_set(struct l3_process *pc, u_char ie, int *checklist) {
648 while (*checklist != -1) {
649 if ((*checklist & 0xff) == ie) {
662 check_infoelements(struct l3_process *pc, struct sk_buff *skb, int *checklist)
667 int l, newpos, oldpos;
668 int err_seq = 0, err_len = 0, err_compr = 0, err_ureg = 0;
670 u_char old_codeset = 0;
680 while ((p - skb->data) < skb->len) {
681 if ((*p & 0xf0) == 0x90) { /* shift codeset */
682 old_codeset = codeset;
688 if (pc->debug & L3_DEB_CHECK)
689 l3_debug(pc->st, "check IE shift%scodeset %d->%d",
690 codelock ? " locking ": " ", old_codeset, codeset);
694 if (!codeset) { /* only codeset 0 */
695 if ((newpos = ie_in_set(pc, *p, cl))) {
703 if (ie_in_set(pc, *p, comp_required))
717 if (!codeset && (l > getmax_ie_len(ie)))
720 if (pc->debug & L3_DEB_CHECK)
721 l3_debug(pc->st, "check IE shift back codeset %d->%d",
722 codeset, old_codeset);
723 codeset = old_codeset;
727 if (err_compr | err_ureg | err_len | err_seq) {
728 if (pc->debug & L3_DEB_CHECK)
729 l3_debug(pc->st, "check IE MT(%x) %d/%d/%d/%d",
730 mt, err_compr, err_ureg, err_len, err_seq);
732 return(ERR_IE_COMPREHENSION);
734 return(ERR_IE_UNRECOGNIZED);
736 return(ERR_IE_LENGTH);
738 return(ERR_IE_SEQUENCE);
743 /* verify if a message type exists and contain no IE error */
745 l3ni1_check_messagetype_validity(struct l3_process *pc, int mt, void *arg)
749 case MT_CALL_PROCEEDING:
751 case MT_CONNECT_ACKNOWLEDGE:
758 case MT_RELEASE_COMPLETE:
760 case MT_SETUP_ACKNOWLEDGE:
761 case MT_RESUME_ACKNOWLEDGE:
762 case MT_RESUME_REJECT:
763 case MT_SUSPEND_ACKNOWLEDGE:
764 case MT_SUSPEND_REJECT:
765 case MT_USER_INFORMATION:
767 case MT_RESTART_ACKNOWLEDGE:
768 case MT_CONGESTION_CONTROL:
770 case MT_STATUS_ENQUIRY:
771 if (pc->debug & L3_DEB_CHECK)
772 l3_debug(pc->st, "l3ni1_check_messagetype_validity mt(%x) OK", mt);
774 case MT_RESUME: /* RESUME only in user->net */
775 case MT_SUSPEND: /* SUSPEND only in user->net */
777 if (pc->debug & (L3_DEB_CHECK | L3_DEB_WARN))
778 l3_debug(pc->st, "l3ni1_check_messagetype_validity mt(%x) fail", mt);
780 l3ni1_status_send(pc, 0, NULL);
787 l3ni1_std_ie_err(struct l3_process *pc, int ret) {
789 if (pc->debug & L3_DEB_CHECK)
790 l3_debug(pc->st, "check_infoelements ret %d", ret);
794 case ERR_IE_COMPREHENSION:
796 l3ni1_status_send(pc, 0, NULL);
798 case ERR_IE_UNRECOGNIZED:
800 l3ni1_status_send(pc, 0, NULL);
803 pc->para.cause = 100;
804 l3ni1_status_send(pc, 0, NULL);
806 case ERR_IE_SEQUENCE:
813 l3ni1_get_channel_id(struct l3_process *pc, struct sk_buff *skb) {
817 if ((p = findie(p, skb->len, IE_CHANNEL_ID, 0))) {
819 if (*p != 1) { /* len for BRI = 1 */
820 if (pc->debug & L3_DEB_WARN)
821 l3_debug(pc->st, "wrong chid len %d", *p);
825 if (*p & 0x60) { /* only base rate interface */
826 if (pc->debug & L3_DEB_WARN)
827 l3_debug(pc->st, "wrong chid %x", *p);
836 l3ni1_get_cause(struct l3_process *pc, struct sk_buff *skb) {
843 if ((p = findie(p, skb->len, IE_CAUSE, 0))) {
854 if (l && !(pc->para.loc & 0x80)) {
856 p++; /* skip recommendation */
859 pc->para.cause = *p++;
861 if (!(pc->para.cause & 0x80))
866 pc->para.diag[i++] = *p++;
875 l3ni1_msg_with_uus(struct l3_process *pc, u_char cmd)
882 MsgHead(p, pc->callref, cmd);
884 if (pc->prot.ni1.uus1_data[0])
885 { *p++ = IE_USER_USER; /* UUS info element */
886 *p++ = strlen(pc->prot.ni1.uus1_data) + 1;
887 *p++ = 0x04; /* IA5 chars */
888 strcpy(p,pc->prot.ni1.uus1_data);
889 p += strlen(pc->prot.ni1.uus1_data);
890 pc->prot.ni1.uus1_data[0] = '\0';
894 if (!(skb = l3_alloc_skb(l)))
896 memcpy(skb_put(skb, l), tmp, l);
897 l3_msg(pc->st, DL_DATA | REQUEST, skb);
898 } /* l3ni1_msg_with_uus */
901 l3ni1_release_req(struct l3_process *pc, u_char pr, void *arg)
905 if (!pc->prot.ni1.uus1_data[0])
906 l3ni1_message(pc, MT_RELEASE);
908 l3ni1_msg_with_uus(pc, MT_RELEASE);
909 L3AddTimer(&pc->timer, T308, CC_T308_1);
913 l3ni1_release_cmpl(struct l3_process *pc, u_char pr, void *arg)
915 struct sk_buff *skb = arg;
918 if ((ret = l3ni1_get_cause(pc, skb))>0) {
919 if (pc->debug & L3_DEB_WARN)
920 l3_debug(pc->st, "RELCMPL get_cause ret(%d)",ret);
922 pc->para.cause = NO_CAUSE;
925 pc->st->l3.l3l4(pc->st, CC_RELEASE | CONFIRM, pc);
926 ni1_release_l3_process(pc);
932 EncodeASyncParams(u_char * p, u_char si2)
933 { // 7c 06 88 90 21 42 00 bb
936 p[1] = 0x40; // Intermediate rate: 16 kbit/s jj 2000.02.19
938 if (si2 & 32) // 7 data bits
945 if (si2 & 16) // 2 stop bits
952 if (si2 & 8) // even parity
959 switch (si2 & 0x07) {
961 p[0] = 66; // 1200 bit/s
965 p[0] = 88; // 1200/75 bit/s
969 p[0] = 87; // 75/1200 bit/s
973 p[0] = 67; // 2400 bit/s
977 p[0] = 69; // 4800 bit/s
981 p[0] = 72; // 9600 bit/s
985 p[0] = 73; // 14400 bit/s
989 p[0] = 75; // 19200 bit/s
997 EncodeSyncParams(u_char si2, u_char ai)
1002 return ai + 2; // 1200 bit/s
1005 return ai + 24; // 1200/75 bit/s
1008 return ai + 23; // 75/1200 bit/s
1011 return ai + 3; // 2400 bit/s
1014 return ai + 5; // 4800 bit/s
1017 return ai + 8; // 9600 bit/s
1020 return ai + 9; // 14400 bit/s
1023 return ai + 11; // 19200 bit/s
1026 return ai + 14; // 48000 bit/s
1029 return ai + 15; // 56000 bit/s
1032 return ai + 40; // negotiate bit/s
1042 DecodeASyncParams(u_char si2, u_char * p)
1047 case 66: // 1200 bit/s
1049 break; // si2 don't change
1051 case 88: // 1200/75 bit/s
1055 case 87: // 75/1200 bit/s
1059 case 67: // 2400 bit/s
1063 case 69: // 4800 bit/s
1067 case 72: // 9600 bit/s
1071 case 73: // 14400 bit/s
1075 case 75: // 19200 bit/s
1082 if ((info & 16) && (!(info & 8))) // 7 data bits
1084 si2 += 32; // else 8 data bits
1086 if ((info & 96) == 96) // 2 stop bits
1088 si2 += 16; // else 1 stop bit
1090 if ((info & 2) && (!(info & 1))) // even parity
1092 si2 += 8; // else no parity
1099 DecodeSyncParams(u_char si2, u_char info)
1103 case 40: // bit/s negotiation failed ai := 165 not 175!
1106 case 15: // 56000 bit/s failed, ai := 0 not 169 !
1109 case 14: // 48000 bit/s
1112 case 11: // 19200 bit/s
1115 case 9: // 14400 bit/s
1118 case 8: // 9600 bit/s
1121 case 5: // 4800 bit/s
1124 case 3: // 2400 bit/s
1127 case 23: // 75/1200 bit/s
1130 case 24: // 1200/75 bit/s
1133 default: // 1200 bit/s
1140 DecodeSI2(struct sk_buff *skb)
1142 u_char *p; //, *pend=skb->data + skb->len;
1144 if ((p = findie(skb->data, skb->len, 0x7c, 0))) {
1145 switch (p[4] & 0x0f) {
1147 if (p[1] == 0x04) // sync. Bitratenadaption
1149 return DecodeSyncParams(160, p[5]); // V.110/X.30
1151 else if (p[1] == 0x06) // async. Bitratenadaption
1153 return DecodeASyncParams(192, p); // V.110/X.30
1156 case 0x08: // if (p[5] == 0x02) // sync. Bitratenadaption
1158 return DecodeSyncParams(176, p[5]); // V.120
1169 l3ni1_setup_req(struct l3_process *pc, u_char pr,
1172 struct sk_buff *skb;
1181 MsgHead(p, pc->callref, MT_SETUP);
1183 teln = pc->para.setup.phone;
1185 *p++ = 0xa1; /* complete indicator */
1187 * Set Bearer Capability, Map info from 1TR6-convention to NI1
1189 switch (pc->para.setup.si1) {
1190 case 1: /* Telephony */
1192 *p++ = 0x3; /* Length */
1193 *p++ = 0x90; /* 3.1khz Audio */
1194 *p++ = 0x90; /* Circuit-Mode 64kbps */
1195 *p++ = 0xa2; /* u-Law Audio */
1197 case 5: /* Datatransmission 64k, BTX */
1198 case 7: /* Datatransmission 64k */
1201 *p++ = 0x2; /* Length */
1202 *p++ = 0x88; /* Coding Std. CCITT, unrestr. dig. Inform. */
1203 *p++ = 0x90; /* Circuit-Mode 64kbps */
1218 *p++ = strlen(teln);
1220 *p++ = (*teln++) & 0x7F;
1226 if ((pc->para.setup.si2 >= 160) && (pc->para.setup.si2 <= 175)) { // sync. Bitratenadaption, V.110/X.30
1233 *p++ = EncodeSyncParams(pc->para.setup.si2 - 160, 0x80);
1234 } else if ((pc->para.setup.si2 >= 176) && (pc->para.setup.si2 <= 191)) { // sync. Bitratenadaption, V.120
1241 *p++ = EncodeSyncParams(pc->para.setup.si2 - 176, 0);
1243 } else if (pc->para.setup.si2 >= 192) { // async. Bitratenadaption, V.110/X.30
1250 p = EncodeASyncParams(p, pc->para.setup.si2 - 192);
1252 switch (pc->para.setup.si1) {
1253 case 1: /* Telephony */
1255 *p++ = 0x3; /* Length */
1256 *p++ = 0x90; /* Coding Std. CCITT, 3.1 kHz audio */
1257 *p++ = 0x90; /* Circuit-Mode 64kbps */
1258 *p++ = 0xa2; /* u-Law Audio */
1260 case 5: /* Datatransmission 64k, BTX */
1261 case 7: /* Datatransmission 64k */
1264 *p++ = 0x2; /* Length */
1265 *p++ = 0x88; /* Coding Std. CCITT, unrestr. dig. Inform. */
1266 *p++ = 0x90; /* Circuit-Mode 64kbps */
1272 if (!(skb = l3_alloc_skb(l)))
1276 memcpy(skb_put(skb, l), tmp, l);
1277 L3DelTimer(&pc->timer);
1278 L3AddTimer(&pc->timer, T303, CC_T303);
1280 l3_msg(pc->st, DL_DATA | REQUEST, skb);
1284 l3ni1_call_proc(struct l3_process *pc, u_char pr, void *arg)
1286 struct sk_buff *skb = arg;
1289 if ((id = l3ni1_get_channel_id(pc, skb)) >= 0) {
1290 if ((0 == id) || ((3 == id) && (0x10 == pc->para.moderate))) {
1291 if (pc->debug & L3_DEB_WARN)
1292 l3_debug(pc->st, "setup answer with wrong chid %x", id);
1293 pc->para.cause = 100;
1294 l3ni1_status_send(pc, pr, NULL);
1297 pc->para.bchannel = id;
1298 } else if (1 == pc->state) {
1299 if (pc->debug & L3_DEB_WARN)
1300 l3_debug(pc->st, "setup answer wrong chid (ret %d)", id);
1302 pc->para.cause = 96;
1304 pc->para.cause = 100;
1305 l3ni1_status_send(pc, pr, NULL);
1308 /* Now we are on none mandatory IEs */
1309 ret = check_infoelements(pc, skb, ie_CALL_PROCEEDING);
1310 if (ERR_IE_COMPREHENSION == ret) {
1311 l3ni1_std_ie_err(pc, ret);
1314 L3DelTimer(&pc->timer);
1316 L3AddTimer(&pc->timer, T310, CC_T310);
1317 if (ret) /* STATUS for none mandatory IE errors after actions are taken */
1318 l3ni1_std_ie_err(pc, ret);
1319 pc->st->l3.l3l4(pc->st, CC_PROCEEDING | INDICATION, pc);
1323 l3ni1_setup_ack(struct l3_process *pc, u_char pr, void *arg)
1325 struct sk_buff *skb = arg;
1328 if ((id = l3ni1_get_channel_id(pc, skb)) >= 0) {
1329 if ((0 == id) || ((3 == id) && (0x10 == pc->para.moderate))) {
1330 if (pc->debug & L3_DEB_WARN)
1331 l3_debug(pc->st, "setup answer with wrong chid %x", id);
1332 pc->para.cause = 100;
1333 l3ni1_status_send(pc, pr, NULL);
1336 pc->para.bchannel = id;
1338 if (pc->debug & L3_DEB_WARN)
1339 l3_debug(pc->st, "setup answer wrong chid (ret %d)", id);
1341 pc->para.cause = 96;
1343 pc->para.cause = 100;
1344 l3ni1_status_send(pc, pr, NULL);
1347 /* Now we are on none mandatory IEs */
1348 ret = check_infoelements(pc, skb, ie_SETUP_ACKNOWLEDGE);
1349 if (ERR_IE_COMPREHENSION == ret) {
1350 l3ni1_std_ie_err(pc, ret);
1353 L3DelTimer(&pc->timer);
1355 L3AddTimer(&pc->timer, T304, CC_T304);
1356 if (ret) /* STATUS for none mandatory IE errors after actions are taken */
1357 l3ni1_std_ie_err(pc, ret);
1358 pc->st->l3.l3l4(pc->st, CC_MORE_INFO | INDICATION, pc);
1362 l3ni1_disconnect(struct l3_process *pc, u_char pr, void *arg)
1364 struct sk_buff *skb = arg;
1370 if ((ret = l3ni1_get_cause(pc, skb))) {
1371 if (pc->debug & L3_DEB_WARN)
1372 l3_debug(pc->st, "DISC get_cause ret(%d)", ret);
1378 if ((p = findie(skb->data, skb->len, IE_FACILITY, 0)))
1379 l3ni1_parse_facility(pc->st, pc, pc->callref, p);
1380 ret = check_infoelements(pc, skb, ie_DISCONNECT);
1381 if (ERR_IE_COMPREHENSION == ret)
1383 else if ((!cause) && (ERR_IE_UNRECOGNIZED == ret))
1390 pc->st->l3.l3l4(pc->st, CC_DISCONNECT | INDICATION, pc);
1392 l3ni1_release_req(pc, pr, NULL);
1394 l3ni1_message_cause(pc, MT_RELEASE, cause);
1395 L3AddTimer(&pc->timer, T308, CC_T308_1);
1400 l3ni1_connect(struct l3_process *pc, u_char pr, void *arg)
1402 struct sk_buff *skb = arg;
1405 ret = check_infoelements(pc, skb, ie_CONNECT);
1406 if (ERR_IE_COMPREHENSION == ret) {
1407 l3ni1_std_ie_err(pc, ret);
1410 L3DelTimer(&pc->timer); /* T310 */
1412 pc->para.chargeinfo = 0;
1413 /* here should inserted COLP handling KKe */
1415 l3ni1_std_ie_err(pc, ret);
1416 pc->st->l3.l3l4(pc->st, CC_SETUP | CONFIRM, pc);
1420 l3ni1_alerting(struct l3_process *pc, u_char pr, void *arg)
1422 struct sk_buff *skb = arg;
1425 ret = check_infoelements(pc, skb, ie_ALERTING);
1426 if (ERR_IE_COMPREHENSION == ret) {
1427 l3ni1_std_ie_err(pc, ret);
1430 L3DelTimer(&pc->timer); /* T304 */
1433 l3ni1_std_ie_err(pc, ret);
1434 pc->st->l3.l3l4(pc->st, CC_ALERTING | INDICATION, pc);
1438 l3ni1_setup(struct l3_process *pc, u_char pr, void *arg)
1443 struct sk_buff *skb = arg;
1448 * Bearer Capabilities
1451 /* only the first occurence 'll be detected ! */
1452 if ((p = findie(p, skb->len, 0x04, 0))) {
1453 if ((p[1] < 2) || (p[1] > 11))
1456 pc->para.setup.si2 = 0;
1457 switch (p[2] & 0x7f) {
1458 case 0x00: /* Speech */
1459 case 0x10: /* 3.1 Khz audio */
1460 pc->para.setup.si1 = 1;
1462 case 0x08: /* Unrestricted digital information */
1463 pc->para.setup.si1 = 7;
1464 /* JIM, 05.11.97 I wanna set service indicator 2 */
1466 pc->para.setup.si2 = DecodeSI2(skb);
1469 case 0x09: /* Restricted digital information */
1470 pc->para.setup.si1 = 2;
1473 /* Unrestr. digital information with
1474 * tones/announcements ( or 7 kHz audio
1476 pc->para.setup.si1 = 3;
1478 case 0x18: /* Video */
1479 pc->para.setup.si1 = 4;
1485 switch (p[3] & 0x7f) {
1486 case 0x40: /* packed mode */
1487 pc->para.setup.si1 = 8;
1489 case 0x10: /* 64 kbit */
1490 case 0x11: /* 2*64 kbit */
1491 case 0x13: /* 384 kbit */
1492 case 0x15: /* 1536 kbit */
1493 case 0x17: /* 1920 kbit */
1494 pc->para.moderate = p[3] & 0x7f;
1501 if (pc->debug & L3_DEB_SI)
1502 l3_debug(pc->st, "SI=%d, AI=%d",
1503 pc->para.setup.si1, pc->para.setup.si2);
1505 if (pc->debug & L3_DEB_WARN)
1506 l3_debug(pc->st, "setup with wrong bearer(l=%d:%x,%x)",
1508 pc->para.cause = 100;
1509 l3ni1_msg_without_setup(pc, pr, NULL);
1513 if (pc->debug & L3_DEB_WARN)
1514 l3_debug(pc->st, "setup without bearer capabilities");
1515 /* ETS 300-104 1.3.3 */
1516 pc->para.cause = 96;
1517 l3ni1_msg_without_setup(pc, pr, NULL);
1521 * Channel Identification
1523 if ((id = l3ni1_get_channel_id(pc, skb)) >= 0) {
1524 if ((pc->para.bchannel = id)) {
1525 if ((3 == id) && (0x10 == pc->para.moderate)) {
1526 if (pc->debug & L3_DEB_WARN)
1527 l3_debug(pc->st, "setup with wrong chid %x",
1529 pc->para.cause = 100;
1530 l3ni1_msg_without_setup(pc, pr, NULL);
1535 { if (pc->debug & L3_DEB_WARN)
1536 l3_debug(pc->st, "setup without bchannel, call waiting");
1540 if (pc->debug & L3_DEB_WARN)
1541 l3_debug(pc->st, "setup with wrong chid ret %d", id);
1543 pc->para.cause = 96;
1545 pc->para.cause = 100;
1546 l3ni1_msg_without_setup(pc, pr, NULL);
1549 /* Now we are on none mandatory IEs */
1550 err = check_infoelements(pc, skb, ie_SETUP);
1551 if (ERR_IE_COMPREHENSION == err) {
1552 pc->para.cause = 96;
1553 l3ni1_msg_without_setup(pc, pr, NULL);
1557 if ((p = findie(p, skb->len, 0x70, 0)))
1558 iecpy(pc->para.setup.eazmsn, p, 1);
1560 pc->para.setup.eazmsn[0] = 0;
1563 if ((p = findie(p, skb->len, 0x71, 0))) {
1564 /* Called party subaddress */
1565 if ((p[1] >= 2) && (p[2] == 0x80) && (p[3] == 0x50)) {
1567 iecpy(&tmp[1], p, 2);
1568 strcat(pc->para.setup.eazmsn, tmp);
1569 } else if (pc->debug & L3_DEB_WARN)
1570 l3_debug(pc->st, "wrong called subaddress");
1573 if ((p = findie(p, skb->len, 0x6c, 0))) {
1574 pc->para.setup.plan = p[2];
1576 iecpy(pc->para.setup.phone, p, 1);
1577 pc->para.setup.screen = 0;
1579 iecpy(pc->para.setup.phone, p, 2);
1580 pc->para.setup.screen = p[3];
1583 pc->para.setup.phone[0] = 0;
1584 pc->para.setup.plan = 0;
1585 pc->para.setup.screen = 0;
1588 if ((p = findie(p, skb->len, 0x6d, 0))) {
1589 /* Calling party subaddress */
1590 if ((p[1] >= 2) && (p[2] == 0x80) && (p[3] == 0x50)) {
1592 iecpy(&tmp[1], p, 2);
1593 strcat(pc->para.setup.phone, tmp);
1594 } else if (pc->debug & L3_DEB_WARN)
1595 l3_debug(pc->st, "wrong calling subaddress");
1598 if (err) /* STATUS for none mandatory IE errors after actions are taken */
1599 l3ni1_std_ie_err(pc, err);
1600 pc->st->l3.l3l4(pc->st, CC_SETUP | INDICATION, pc);
1604 l3ni1_reset(struct l3_process *pc, u_char pr, void *arg)
1606 ni1_release_l3_process(pc);
1610 l3ni1_disconnect_req(struct l3_process *pc, u_char pr, void *arg)
1612 struct sk_buff *skb;
1618 if (pc->para.cause != NO_CAUSE)
1619 cause = pc->para.cause;
1623 MsgHead(p, pc->callref, MT_DISCONNECT);
1628 *p++ = cause | 0x80;
1630 if (pc->prot.ni1.uus1_data[0])
1631 { *p++ = IE_USER_USER; /* UUS info element */
1632 *p++ = strlen(pc->prot.ni1.uus1_data) + 1;
1633 *p++ = 0x04; /* IA5 chars */
1634 strcpy(p,pc->prot.ni1.uus1_data);
1635 p += strlen(pc->prot.ni1.uus1_data);
1636 pc->prot.ni1.uus1_data[0] = '\0';
1640 if (!(skb = l3_alloc_skb(l)))
1642 memcpy(skb_put(skb, l), tmp, l);
1644 l3_msg(pc->st, DL_DATA | REQUEST, skb);
1645 L3AddTimer(&pc->timer, T305, CC_T305);
1649 l3ni1_setup_rsp(struct l3_process *pc, u_char pr,
1652 if (!pc->para.bchannel)
1653 { if (pc->debug & L3_DEB_WARN)
1654 l3_debug(pc->st, "D-chan connect for waiting call");
1655 l3ni1_disconnect_req(pc, pr, arg);
1659 if (pc->debug & L3_DEB_WARN)
1660 l3_debug(pc->st, "D-chan connect for waiting call");
1661 l3ni1_message_plus_chid(pc, MT_CONNECT); /* GE 05/09/00 */
1662 L3DelTimer(&pc->timer);
1663 L3AddTimer(&pc->timer, T313, CC_T313);
1667 l3ni1_connect_ack(struct l3_process *pc, u_char pr, void *arg)
1669 struct sk_buff *skb = arg;
1672 ret = check_infoelements(pc, skb, ie_CONNECT_ACKNOWLEDGE);
1673 if (ERR_IE_COMPREHENSION == ret) {
1674 l3ni1_std_ie_err(pc, ret);
1678 L3DelTimer(&pc->timer);
1680 l3ni1_std_ie_err(pc, ret);
1681 pc->st->l3.l3l4(pc->st, CC_SETUP_COMPL | INDICATION, pc);
1685 l3ni1_reject_req(struct l3_process *pc, u_char pr, void *arg)
1687 struct sk_buff *skb;
1693 if (pc->para.cause != NO_CAUSE)
1694 cause = pc->para.cause;
1696 MsgHead(p, pc->callref, MT_RELEASE_COMPLETE);
1701 *p++ = cause | 0x80;
1704 if (!(skb = l3_alloc_skb(l)))
1706 memcpy(skb_put(skb, l), tmp, l);
1707 l3_msg(pc->st, DL_DATA | REQUEST, skb);
1708 pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
1710 ni1_release_l3_process(pc);
1714 l3ni1_release(struct l3_process *pc, u_char pr, void *arg)
1716 struct sk_buff *skb = arg;
1721 if ((ret = l3ni1_get_cause(pc, skb))>0) {
1722 if (pc->debug & L3_DEB_WARN)
1723 l3_debug(pc->st, "REL get_cause ret(%d)", ret);
1725 pc->para.cause = NO_CAUSE;
1726 if ((p = findie(skb->data, skb->len, IE_FACILITY, 0))) {
1727 l3ni1_parse_facility(pc->st, pc, pc->callref, p);
1729 if ((ret<0) && (pc->state != 11))
1733 ret = check_infoelements(pc, skb, ie_RELEASE);
1734 if (ERR_IE_COMPREHENSION == ret)
1736 else if ((ERR_IE_UNRECOGNIZED == ret) && (!cause))
1739 l3ni1_message_cause(pc, MT_RELEASE_COMPLETE, cause);
1741 l3ni1_message(pc, MT_RELEASE_COMPLETE);
1742 pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
1744 ni1_release_l3_process(pc);
1748 l3ni1_alert_req(struct l3_process *pc, u_char pr,
1752 if (!pc->prot.ni1.uus1_data[0])
1753 l3ni1_message(pc, MT_ALERTING);
1755 l3ni1_msg_with_uus(pc, MT_ALERTING);
1759 l3ni1_proceed_req(struct l3_process *pc, u_char pr,
1763 l3ni1_message(pc, MT_CALL_PROCEEDING);
1764 pc->st->l3.l3l4(pc->st, CC_PROCEED_SEND | INDICATION, pc);
1768 l3ni1_setup_ack_req(struct l3_process *pc, u_char pr,
1772 L3DelTimer(&pc->timer);
1773 L3AddTimer(&pc->timer, T302, CC_T302);
1774 l3ni1_message(pc, MT_SETUP_ACKNOWLEDGE);
1777 /********************************************/
1778 /* deliver a incoming display message to HL */
1779 /********************************************/
1781 l3ni1_deliver_display(struct l3_process *pc, int pr, u_char *infp)
1784 struct IsdnCardState *cs;
1787 if (*infp++ != IE_DISPLAY) return;
1788 if ((len = *infp++) > 80) return; /* total length <= 82 */
1789 if (!pc->chan) return;
1791 p = ic.parm.display;
1795 ic.command = ISDN_STAT_DISPLAY;
1796 cs = pc->st->l1.hardware;
1797 ic.driver = cs->myid;
1798 ic.arg = pc->chan->chan;
1799 cs->iif.statcallb(&ic);
1800 } /* l3ni1_deliver_display */
1804 l3ni1_progress(struct l3_process *pc, u_char pr, void *arg)
1806 struct sk_buff *skb = arg;
1810 if ((p = findie(skb->data, skb->len, IE_PROGRESS, 0))) {
1813 pc->para.cause = 100;
1814 } else if (!(p[2] & 0x70)) {
1832 pc->para.cause = 100;
1838 pc->para.cause = 100;
1843 pc->para.cause = 96;
1847 if (pc->debug & L3_DEB_WARN)
1848 l3_debug(pc->st, "progress error %d", err);
1849 l3ni1_status_send(pc, pr, NULL);
1852 /* Now we are on none mandatory IEs */
1853 err = check_infoelements(pc, skb, ie_PROGRESS);
1855 l3ni1_std_ie_err(pc, err);
1856 if (ERR_IE_COMPREHENSION != err)
1857 pc->st->l3.l3l4(pc->st, CC_PROGRESS | INDICATION, pc);
1861 l3ni1_notify(struct l3_process *pc, u_char pr, void *arg)
1863 struct sk_buff *skb = arg;
1867 if ((p = findie(skb->data, skb->len, IE_NOTIFY, 0))) {
1870 pc->para.cause = 100;
1878 pc->para.cause = 100;
1884 pc->para.cause = 96;
1888 if (pc->debug & L3_DEB_WARN)
1889 l3_debug(pc->st, "notify error %d", err);
1890 l3ni1_status_send(pc, pr, NULL);
1893 /* Now we are on none mandatory IEs */
1894 err = check_infoelements(pc, skb, ie_NOTIFY);
1896 l3ni1_std_ie_err(pc, err);
1897 if (ERR_IE_COMPREHENSION != err)
1898 pc->st->l3.l3l4(pc->st, CC_NOTIFY | INDICATION, pc);
1902 l3ni1_status_enq(struct l3_process *pc, u_char pr, void *arg)
1905 struct sk_buff *skb = arg;
1907 ret = check_infoelements(pc, skb, ie_STATUS_ENQUIRY);
1908 l3ni1_std_ie_err(pc, ret);
1909 pc->para.cause = 30; /* response to STATUS_ENQUIRY */
1910 l3ni1_status_send(pc, pr, NULL);
1914 l3ni1_information(struct l3_process *pc, u_char pr, void *arg)
1917 struct sk_buff *skb = arg;
1921 ret = check_infoelements(pc, skb, ie_INFORMATION);
1923 l3ni1_std_ie_err(pc, ret);
1924 if (pc->state == 25) { /* overlap receiving */
1925 L3DelTimer(&pc->timer);
1927 if ((p = findie(p, skb->len, 0x70, 0))) {
1929 strcat(pc->para.setup.eazmsn, tmp);
1930 pc->st->l3.l3l4(pc->st, CC_MORE_INFO | INDICATION, pc);
1932 L3AddTimer(&pc->timer, T302, CC_T302);
1936 /******************************/
1937 /* handle deflection requests */
1938 /******************************/
1939 static void l3ni1_redir_req(struct l3_process *pc, u_char pr, void *arg)
1941 struct sk_buff *skb;
1945 u_char len_phone = 0;
1950 strcpy(pc->prot.ni1.uus1_data,pc->chan->setup.eazmsn); /* copy uus element if available */
1951 if (!pc->chan->setup.phone[0])
1952 { pc->para.cause = -1;
1953 l3ni1_disconnect_req(pc,pr,arg); /* disconnect immediately */
1957 if (pc->prot.ni1.invoke_id)
1958 free_invoke_id(pc->st,pc->prot.ni1.invoke_id);
1960 if (!(pc->prot.ni1.invoke_id = new_invoke_id(pc->st)))
1963 MsgHead(p, pc->callref, MT_FACILITY);
1965 for (subp = pc->chan->setup.phone; (*subp) && (*subp != '.'); subp++) len_phone++; /* len of phone number */
1966 if (*subp++ == '.') len_sub = strlen(subp) + 2; /* length including info subaddress element */
1968 *p++ = 0x1c; /* Facility info element */
1969 *p++ = len_phone + len_sub + 2 + 2 + 8 + 3 + 3; /* length of element */
1970 *p++ = 0x91; /* remote operations protocol */
1971 *p++ = 0xa1; /* invoke component */
1973 *p++ = len_phone + len_sub + 2 + 2 + 8 + 3; /* length of data */
1974 *p++ = 0x02; /* invoke id tag, integer */
1975 *p++ = 0x01; /* length */
1976 *p++ = pc->prot.ni1.invoke_id; /* invoke id */
1977 *p++ = 0x02; /* operation value tag, integer */
1978 *p++ = 0x01; /* length */
1979 *p++ = 0x0D; /* Call Deflect */
1981 *p++ = 0x30; /* sequence phone number */
1982 *p++ = len_phone + 2 + 2 + 3 + len_sub; /* length */
1984 *p++ = 0x30; /* Deflected to UserNumber */
1985 *p++ = len_phone+2+len_sub; /* length */
1986 *p++ = 0x80; /* NumberDigits */
1987 *p++ = len_phone; /* length */
1988 for (l = 0; l < len_phone; l++)
1989 *p++ = pc->chan->setup.phone[l];
1992 { *p++ = 0x04; /* called party subaddress */
1994 while (*subp) *p++ = *subp++;
1997 *p++ = 0x01; /* screening identifier */
1999 *p++ = pc->chan->setup.screen;
2002 if (!(skb = l3_alloc_skb(l))) return;
2003 memcpy(skb_put(skb, l), tmp, l);
2005 l3_msg(pc->st, DL_DATA | REQUEST, skb);
2006 } /* l3ni1_redir_req */
2008 /********************************************/
2009 /* handle deflection request in early state */
2010 /********************************************/
2011 static void l3ni1_redir_req_early(struct l3_process *pc, u_char pr, void *arg)
2013 l3ni1_proceed_req(pc,pr,arg);
2014 l3ni1_redir_req(pc,pr,arg);
2015 } /* l3ni1_redir_req_early */
2017 /***********************************************/
2018 /* handle special commands for this protocol. */
2019 /* Examples are call independant services like */
2020 /* remote operations with dummy callref. */
2021 /***********************************************/
2022 static int l3ni1_cmd_global(struct PStack *st, isdn_ctrl *ic)
2027 struct sk_buff *skb;
2028 struct l3_process *pc = NULL;
2031 { case NI1_CMD_INVOKE:
2032 if (ic->parm.ni1_io.datalen < 0) return(-2); /* invalid parameter */
2034 for (proc_len = 1, i = ic->parm.ni1_io.proc >> 8; i; i++)
2035 i = i >> 8; /* add one byte */
2036 l = ic->parm.ni1_io.datalen + proc_len + 8; /* length excluding ie header */
2038 return(-2); /* too long */
2040 if (!(id = new_invoke_id(st)))
2041 return(0); /* first get a invoke id -> return if no available */
2044 MsgHead(p, i, MT_FACILITY); /* build message head */
2045 *p++ = 0x1C; /* Facility IE */
2046 *p++ = l; /* length of ie */
2047 *p++ = 0x91; /* remote operations */
2048 *p++ = 0xA1; /* invoke */
2049 *p++ = l - 3; /* length of invoke */
2050 *p++ = 0x02; /* invoke id tag */
2051 *p++ = 0x01; /* length is 1 */
2052 *p++ = id; /* invoke id */
2053 *p++ = 0x02; /* operation */
2054 *p++ = proc_len; /* length of operation */
2056 for (i = proc_len; i; i--)
2057 *p++ = (ic->parm.ni1_io.proc >> (i-1)) & 0xFF;
2058 memcpy(p, ic->parm.ni1_io.data, ic->parm.ni1_io.datalen); /* copy data */
2059 l = (p - temp) + ic->parm.ni1_io.datalen; /* total length */
2061 if (ic->parm.ni1_io.timeout > 0)
2062 if (!(pc = ni1_new_l3_process(st, -1)))
2063 { free_invoke_id(st, id);
2066 pc->prot.ni1.ll_id = ic->parm.ni1_io.ll_id; /* remember id */
2067 pc->prot.ni1.proc = ic->parm.ni1_io.proc; /* and procedure */
2069 if (!(skb = l3_alloc_skb(l)))
2070 { free_invoke_id(st, id);
2071 if (pc) ni1_release_l3_process(pc);
2074 memcpy(skb_put(skb, l), temp, l);
2077 { pc->prot.ni1.invoke_id = id; /* remember id */
2078 L3AddTimer(&pc->timer, ic->parm.ni1_io.timeout, CC_TNI1_IO | REQUEST);
2081 l3_msg(st, DL_DATA | REQUEST, skb);
2082 ic->parm.ni1_io.hl_id = id; /* return id */
2085 case NI1_CMD_INVOKE_ABORT:
2086 if ((pc = l3ni1_search_dummy_proc(st, ic->parm.ni1_io.hl_id)))
2087 { L3DelTimer(&pc->timer); /* remove timer */
2088 ni1_release_l3_process(pc);
2092 { l3_debug(st, "l3ni1_cmd_global abort unknown id");
2098 l3_debug(st, "l3ni1_cmd_global unknown cmd 0x%lx", ic->arg);
2100 } /* switch ic-> arg */
2102 } /* l3ni1_cmd_global */
2105 l3ni1_io_timer(struct l3_process *pc)
2107 struct IsdnCardState *cs = pc->st->l1.hardware;
2109 L3DelTimer(&pc->timer); /* remove timer */
2111 ic.driver = cs->myid;
2112 ic.command = ISDN_STAT_PROT;
2113 ic.arg = NI1_STAT_INVOKE_ERR;
2114 ic.parm.ni1_io.hl_id = pc->prot.ni1.invoke_id;
2115 ic.parm.ni1_io.ll_id = pc->prot.ni1.ll_id;
2116 ic.parm.ni1_io.proc = pc->prot.ni1.proc;
2117 ic.parm.ni1_io.timeout= -1;
2118 ic.parm.ni1_io.datalen = 0;
2119 ic.parm.ni1_io.data = NULL;
2120 free_invoke_id(pc->st, pc->prot.ni1.invoke_id);
2121 pc->prot.ni1.invoke_id = 0; /* reset id */
2123 cs->iif.statcallb(&ic);
2125 ni1_release_l3_process(pc);
2126 } /* l3ni1_io_timer */
2129 l3ni1_release_ind(struct l3_process *pc, u_char pr, void *arg)
2132 struct sk_buff *skb = arg;
2136 if ((p = findie(p, skb->len, IE_CALL_STATE, 0))) {
2141 if (callState == 0) {
2142 /* ETS 300-104 7.6.1, 8.6.1, 10.6.1... and 16.1
2143 * set down layer 3 without sending any message
2145 pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
2147 ni1_release_l3_process(pc);
2149 pc->st->l3.l3l4(pc->st, CC_IGNORE | INDICATION, pc);
2154 l3ni1_dummy(struct l3_process *pc, u_char pr, void *arg)
2159 l3ni1_t302(struct l3_process *pc, u_char pr, void *arg)
2161 L3DelTimer(&pc->timer);
2163 pc->para.cause = 28; /* invalid number */
2164 l3ni1_disconnect_req(pc, pr, NULL);
2165 pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc);
2169 l3ni1_t303(struct l3_process *pc, u_char pr, void *arg)
2173 L3DelTimer(&pc->timer);
2174 l3ni1_setup_req(pc, pr, arg);
2176 L3DelTimer(&pc->timer);
2177 l3ni1_message_cause(pc, MT_RELEASE_COMPLETE, 102);
2178 pc->st->l3.l3l4(pc->st, CC_NOSETUP_RSP, pc);
2179 ni1_release_l3_process(pc);
2184 l3ni1_t304(struct l3_process *pc, u_char pr, void *arg)
2186 L3DelTimer(&pc->timer);
2188 pc->para.cause = 102;
2189 l3ni1_disconnect_req(pc, pr, NULL);
2190 pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc);
2195 l3ni1_t305(struct l3_process *pc, u_char pr, void *arg)
2200 struct sk_buff *skb;
2203 L3DelTimer(&pc->timer);
2204 if (pc->para.cause != NO_CAUSE)
2205 cause = pc->para.cause;
2207 MsgHead(p, pc->callref, MT_RELEASE);
2212 *p++ = cause | 0x80;
2215 if (!(skb = l3_alloc_skb(l)))
2217 memcpy(skb_put(skb, l), tmp, l);
2219 l3_msg(pc->st, DL_DATA | REQUEST, skb);
2220 L3AddTimer(&pc->timer, T308, CC_T308_1);
2224 l3ni1_t310(struct l3_process *pc, u_char pr, void *arg)
2226 L3DelTimer(&pc->timer);
2228 pc->para.cause = 102;
2229 l3ni1_disconnect_req(pc, pr, NULL);
2230 pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc);
2234 l3ni1_t313(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_CONNECT_ERR, pc);
2244 l3ni1_t308_1(struct l3_process *pc, u_char pr, void *arg)
2247 L3DelTimer(&pc->timer);
2248 l3ni1_message(pc, MT_RELEASE);
2249 L3AddTimer(&pc->timer, T308, CC_T308_2);
2253 l3ni1_t308_2(struct l3_process *pc, u_char pr, void *arg)
2255 L3DelTimer(&pc->timer);
2256 pc->st->l3.l3l4(pc->st, CC_RELEASE_ERR, pc);
2257 ni1_release_l3_process(pc);
2261 l3ni1_t318(struct l3_process *pc, u_char pr, void *arg)
2263 L3DelTimer(&pc->timer);
2264 pc->para.cause = 102; /* Timer expiry */
2265 pc->para.loc = 0; /* local */
2266 pc->st->l3.l3l4(pc->st, CC_RESUME_ERR, pc);
2268 l3ni1_message(pc, MT_RELEASE);
2269 L3AddTimer(&pc->timer, T308, CC_T308_1);
2273 l3ni1_t319(struct l3_process *pc, u_char pr, void *arg)
2275 L3DelTimer(&pc->timer);
2276 pc->para.cause = 102; /* Timer expiry */
2277 pc->para.loc = 0; /* local */
2278 pc->st->l3.l3l4(pc->st, CC_SUSPEND_ERR, pc);
2283 l3ni1_restart(struct l3_process *pc, u_char pr, void *arg)
2285 L3DelTimer(&pc->timer);
2286 pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
2287 ni1_release_l3_process(pc);
2291 l3ni1_status(struct l3_process *pc, u_char pr, void *arg)
2294 struct sk_buff *skb = arg;
2296 u_char cause = 0, callState = 0;
2298 if ((ret = l3ni1_get_cause(pc, skb))) {
2299 if (pc->debug & L3_DEB_WARN)
2300 l3_debug(pc->st, "STATUS get_cause ret(%d)",ret);
2306 if ((p = findie(skb->data, skb->len, IE_CALL_STATE, 0))) {
2310 if (!ie_in_set(pc, *p, l3_valid_states))
2316 if (!cause) { /* no error before */
2317 ret = check_infoelements(pc, skb, ie_STATUS);
2318 if (ERR_IE_COMPREHENSION == ret)
2320 else if (ERR_IE_UNRECOGNIZED == ret)
2326 if (pc->debug & L3_DEB_WARN)
2327 l3_debug(pc->st, "STATUS error(%d/%d)",ret,cause);
2328 tmp = pc->para.cause;
2329 pc->para.cause = cause;
2330 l3ni1_status_send(pc, 0, NULL);
2332 pc->para.cause = tmp;
2336 cause = pc->para.cause;
2337 if (((cause & 0x7f) == 111) && (callState == 0)) {
2338 /* ETS 300-104 7.6.1, 8.6.1, 10.6.1...
2339 * if received MT_STATUS with cause == 111 and call
2340 * state == 0, then we must set down layer 3
2342 pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
2344 ni1_release_l3_process(pc);
2349 l3ni1_facility(struct l3_process *pc, u_char pr, void *arg)
2351 struct sk_buff *skb = arg;
2354 ret = check_infoelements(pc, skb, ie_FACILITY);
2355 l3ni1_std_ie_err(pc, ret);
2358 if ((p = findie(skb->data, skb->len, IE_FACILITY, 0)))
2359 l3ni1_parse_facility(pc->st, pc, pc->callref, p);
2364 l3ni1_suspend_req(struct l3_process *pc, u_char pr, void *arg)
2366 struct sk_buff *skb;
2370 u_char *msg = pc->chan->setup.phone;
2372 MsgHead(p, pc->callref, MT_SUSPEND);
2374 if (l && (l <= 10)) { /* Max length 10 octets */
2377 for (i = 0; i < l; i++)
2380 l3_debug(pc->st, "SUS wrong CALL_ID len %d", l);
2384 if (!(skb = l3_alloc_skb(l)))
2386 memcpy(skb_put(skb, l), tmp, l);
2387 l3_msg(pc->st, DL_DATA | REQUEST, skb);
2389 L3AddTimer(&pc->timer, T319, CC_T319);
2393 l3ni1_suspend_ack(struct l3_process *pc, u_char pr, void *arg)
2395 struct sk_buff *skb = arg;
2398 L3DelTimer(&pc->timer);
2400 pc->para.cause = NO_CAUSE;
2401 pc->st->l3.l3l4(pc->st, CC_SUSPEND | CONFIRM, pc);
2402 /* We don't handle suspend_ack for IE errors now */
2403 if ((ret = check_infoelements(pc, skb, ie_SUSPEND_ACKNOWLEDGE)))
2404 if (pc->debug & L3_DEB_WARN)
2405 l3_debug(pc->st, "SUSPACK check ie(%d)",ret);
2406 ni1_release_l3_process(pc);
2410 l3ni1_suspend_rej(struct l3_process *pc, u_char pr, void *arg)
2412 struct sk_buff *skb = arg;
2415 if ((ret = l3ni1_get_cause(pc, skb))) {
2416 if (pc->debug & L3_DEB_WARN)
2417 l3_debug(pc->st, "SUSP_REJ get_cause ret(%d)",ret);
2419 pc->para.cause = 96;
2421 pc->para.cause = 100;
2422 l3ni1_status_send(pc, pr, NULL);
2425 ret = check_infoelements(pc, skb, ie_SUSPEND_REJECT);
2426 if (ERR_IE_COMPREHENSION == ret) {
2427 l3ni1_std_ie_err(pc, ret);
2430 L3DelTimer(&pc->timer);
2431 pc->st->l3.l3l4(pc->st, CC_SUSPEND_ERR, pc);
2433 if (ret) /* STATUS for none mandatory IE errors after actions are taken */
2434 l3ni1_std_ie_err(pc, ret);
2438 l3ni1_resume_req(struct l3_process *pc, u_char pr, void *arg)
2440 struct sk_buff *skb;
2444 u_char *msg = pc->para.setup.phone;
2446 MsgHead(p, pc->callref, MT_RESUME);
2449 if (l && (l <= 10)) { /* Max length 10 octets */
2452 for (i = 0; i < l; i++)
2455 l3_debug(pc->st, "RES wrong CALL_ID len %d", l);
2459 if (!(skb = l3_alloc_skb(l)))
2461 memcpy(skb_put(skb, l), tmp, l);
2462 l3_msg(pc->st, DL_DATA | REQUEST, skb);
2464 L3AddTimer(&pc->timer, T318, CC_T318);
2468 l3ni1_resume_ack(struct l3_process *pc, u_char pr, void *arg)
2470 struct sk_buff *skb = arg;
2473 if ((id = l3ni1_get_channel_id(pc, skb)) > 0) {
2474 if ((0 == id) || ((3 == id) && (0x10 == pc->para.moderate))) {
2475 if (pc->debug & L3_DEB_WARN)
2476 l3_debug(pc->st, "resume ack with wrong chid %x", id);
2477 pc->para.cause = 100;
2478 l3ni1_status_send(pc, pr, NULL);
2481 pc->para.bchannel = id;
2482 } else if (1 == pc->state) {
2483 if (pc->debug & L3_DEB_WARN)
2484 l3_debug(pc->st, "resume ack without chid (ret %d)", id);
2485 pc->para.cause = 96;
2486 l3ni1_status_send(pc, pr, NULL);
2489 ret = check_infoelements(pc, skb, ie_RESUME_ACKNOWLEDGE);
2490 if (ERR_IE_COMPREHENSION == ret) {
2491 l3ni1_std_ie_err(pc, ret);
2494 L3DelTimer(&pc->timer);
2495 pc->st->l3.l3l4(pc->st, CC_RESUME | CONFIRM, pc);
2497 if (ret) /* STATUS for none mandatory IE errors after actions are taken */
2498 l3ni1_std_ie_err(pc, ret);
2502 l3ni1_resume_rej(struct l3_process *pc, u_char pr, void *arg)
2504 struct sk_buff *skb = arg;
2507 if ((ret = l3ni1_get_cause(pc, skb))) {
2508 if (pc->debug & L3_DEB_WARN)
2509 l3_debug(pc->st, "RES_REJ get_cause ret(%d)",ret);
2511 pc->para.cause = 96;
2513 pc->para.cause = 100;
2514 l3ni1_status_send(pc, pr, NULL);
2517 ret = check_infoelements(pc, skb, ie_RESUME_REJECT);
2518 if (ERR_IE_COMPREHENSION == ret) {
2519 l3ni1_std_ie_err(pc, ret);
2522 L3DelTimer(&pc->timer);
2523 pc->st->l3.l3l4(pc->st, CC_RESUME_ERR, pc);
2525 if (ret) /* STATUS for none mandatory IE errors after actions are taken */
2526 l3ni1_std_ie_err(pc, ret);
2527 ni1_release_l3_process(pc);
2531 l3ni1_global_restart(struct l3_process *pc, u_char pr, void *arg)
2535 u_char ri, ch = 0, chan = 0;
2537 struct sk_buff *skb = arg;
2538 struct l3_process *up;
2541 L3DelTimer(&pc->timer);
2543 if ((p = findie(p, skb->len, IE_RESTART_IND, 0))) {
2545 l3_debug(pc->st, "Restart %x", ri);
2547 l3_debug(pc->st, "Restart without restart IE");
2551 if ((p = findie(p, skb->len, IE_CHANNEL_ID, 0))) {
2554 if (pc->st->l3.debug)
2555 l3_debug(pc->st, "Restart for channel %d", chan);
2558 up = pc->st->l3.proc;
2561 up->st->lli.l4l3(up->st, CC_RESTART | REQUEST, up);
2562 else if (up->para.bchannel == chan)
2563 up->st->lli.l4l3(up->st, CC_RESTART | REQUEST, up);
2568 MsgHead(p, pc->callref, MT_RESTART_ACKNOWLEDGE);
2570 *p++ = IE_CHANNEL_ID;
2574 *p++ = 0x79; /* RESTART Ind */
2578 if (!(skb = l3_alloc_skb(l)))
2580 memcpy(skb_put(skb, l), tmp, l);
2582 l3_msg(pc->st, DL_DATA | REQUEST, skb);
2586 l3ni1_dl_reset(struct l3_process *pc, u_char pr, void *arg)
2588 pc->para.cause = 0x29; /* Temporary failure */
2590 l3ni1_disconnect_req(pc, pr, NULL);
2591 pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc);
2595 l3ni1_dl_release(struct l3_process *pc, u_char pr, void *arg)
2598 pc->para.cause = 0x1b; /* Destination out of order */
2600 pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
2601 release_l3_process(pc);
2605 l3ni1_dl_reestablish(struct l3_process *pc, u_char pr, void *arg)
2607 L3DelTimer(&pc->timer);
2608 L3AddTimer(&pc->timer, T309, CC_T309);
2609 l3_msg(pc->st, DL_ESTABLISH | REQUEST, NULL);
2613 l3ni1_dl_reest_status(struct l3_process *pc, u_char pr, void *arg)
2615 L3DelTimer(&pc->timer);
2617 pc->para.cause = 0x1F; /* normal, unspecified */
2618 l3ni1_status_send(pc, 0, NULL);
2621 static void l3ni1_SendSpid( struct l3_process *pc, u_char pr, struct sk_buff *skb, int iNewState )
2625 struct Channel * pChan = pc->st->lli.userdata;
2629 dev_kfree_skb( skb);
2631 if ( !( pSPID = strchr( pChan->setup.eazmsn, ':' ) ) )
2633 printk( KERN_ERR "SPID not supplied in EAZMSN %s\n", pChan->setup.eazmsn );
2634 newl3state( pc, 0 );
2635 pc->st->l3.l3l2( pc->st, DL_RELEASE | REQUEST, NULL );
2639 l = strlen( ++pSPID );
2640 if ( !( skb = l3_alloc_skb( 5+l ) ) )
2642 printk( KERN_ERR "HiSax can't get memory to send SPID\n" );
2646 p = skb_put( skb, 5 );
2647 *p++ = PROTO_DIS_EURO;
2649 *p++ = MT_INFORMATION;
2653 memcpy( skb_put( skb, l ), pSPID, l );
2655 newl3state( pc, iNewState );
2657 L3DelTimer( &pc->timer );
2658 L3AddTimer( &pc->timer, TSPID, CC_TSPID );
2660 pc->st->l3.l3l2( pc->st, DL_DATA | REQUEST, skb );
2663 static void l3ni1_spid_send( struct l3_process *pc, u_char pr, void *arg )
2665 l3ni1_SendSpid( pc, pr, arg, 20 );
2668 static void l3ni1_spid_epid( struct l3_process *pc, u_char pr, void *arg )
2670 struct sk_buff *skb = arg;
2672 if ( skb->data[ 1 ] == 0 )
2673 if ( skb->data[ 3 ] == IE_ENDPOINT_ID )
2675 L3DelTimer( &pc->timer );
2676 newl3state( pc, 0 );
2677 l3_msg( pc->st, DL_ESTABLISH | CONFIRM, NULL );
2679 dev_kfree_skb( skb);
2682 static void l3ni1_spid_tout( struct l3_process *pc, u_char pr, void *arg )
2684 if ( pc->state < 22 )
2685 l3ni1_SendSpid( pc, pr, arg, pc->state+1 );
2688 L3DelTimer( &pc->timer );
2689 dev_kfree_skb( arg);
2691 printk( KERN_ERR "SPID not accepted\n" );
2692 newl3state( pc, 0 );
2693 pc->st->l3.l3l2( pc->st, DL_RELEASE | REQUEST, NULL );
2698 static struct stateentry downstatelist[] =
2701 CC_SETUP | REQUEST, l3ni1_setup_req},
2703 CC_RESUME | REQUEST, l3ni1_resume_req},
2704 {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(6) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | SBIT(25),
2705 CC_DISCONNECT | REQUEST, l3ni1_disconnect_req},
2707 CC_RELEASE | REQUEST, l3ni1_release_req},
2709 CC_RESTART | REQUEST, l3ni1_restart},
2710 {SBIT(6) | SBIT(25),
2711 CC_IGNORE | REQUEST, l3ni1_reset},
2712 {SBIT(6) | SBIT(25),
2713 CC_REJECT | REQUEST, l3ni1_reject_req},
2714 {SBIT(6) | SBIT(25),
2715 CC_PROCEED_SEND | REQUEST, l3ni1_proceed_req},
2717 CC_MORE_INFO | REQUEST, l3ni1_setup_ack_req},
2719 CC_MORE_INFO | REQUEST, l3ni1_dummy},
2720 {SBIT(6) | SBIT(9) | SBIT(25),
2721 CC_ALERTING | REQUEST, l3ni1_alert_req},
2722 {SBIT(6) | SBIT(7) | SBIT(9) | SBIT(25),
2723 CC_SETUP | RESPONSE, l3ni1_setup_rsp},
2725 CC_SUSPEND | REQUEST, l3ni1_suspend_req},
2726 {SBIT(7) | SBIT(9) | SBIT(25),
2727 CC_REDIR | REQUEST, l3ni1_redir_req},
2729 CC_REDIR | REQUEST, l3ni1_redir_req_early},
2730 {SBIT(9) | SBIT(25),
2731 CC_DISCONNECT | REQUEST, l3ni1_disconnect_req},
2733 CC_T302, l3ni1_t302},
2735 CC_T303, l3ni1_t303},
2737 CC_T304, l3ni1_t304},
2739 CC_T310, l3ni1_t310},
2741 CC_T313, l3ni1_t313},
2743 CC_T305, l3ni1_t305},
2745 CC_T319, l3ni1_t319},
2747 CC_T318, l3ni1_t318},
2749 CC_T308_1, l3ni1_t308_1},
2751 CC_T308_2, l3ni1_t308_2},
2753 CC_T309, l3ni1_dl_release},
2754 { SBIT( 20 ) | SBIT( 21 ) | SBIT( 22 ),
2755 CC_TSPID, l3ni1_spid_tout },
2759 (sizeof(downstatelist) / sizeof(struct stateentry))
2761 static struct stateentry datastatelist[] =
2764 MT_STATUS_ENQUIRY, l3ni1_status_enq},
2766 MT_FACILITY, l3ni1_facility},
2768 MT_STATUS, l3ni1_release_ind},
2770 MT_STATUS, l3ni1_status},
2772 MT_SETUP, l3ni1_setup},
2773 {SBIT(6) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | SBIT(11) | SBIT(12) |
2774 SBIT(15) | SBIT(17) | SBIT(19) | SBIT(25),
2775 MT_SETUP, l3ni1_dummy},
2777 MT_CALL_PROCEEDING, l3ni1_call_proc},
2779 MT_SETUP_ACKNOWLEDGE, l3ni1_setup_ack},
2781 MT_ALERTING, l3ni1_alerting},
2783 MT_PROGRESS, l3ni1_progress},
2784 {SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) |
2785 SBIT(11) | SBIT(12) | SBIT(15) | SBIT(17) | SBIT(19) | SBIT(25),
2786 MT_INFORMATION, l3ni1_information},
2787 {SBIT(10) | SBIT(11) | SBIT(15),
2788 MT_NOTIFY, l3ni1_notify},
2789 {SBIT(0) | SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(10) |
2790 SBIT(11) | SBIT(12) | SBIT(15) | SBIT(17) | SBIT(19) | SBIT(25),
2791 MT_RELEASE_COMPLETE, l3ni1_release_cmpl},
2792 {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),
2793 MT_RELEASE, l3ni1_release},
2794 {SBIT(19), MT_RELEASE, l3ni1_release_ind},
2795 {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | SBIT(11) | SBIT(15) | SBIT(17) | SBIT(25),
2796 MT_DISCONNECT, l3ni1_disconnect},
2798 MT_DISCONNECT, l3ni1_dummy},
2799 {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4),
2800 MT_CONNECT, l3ni1_connect},
2802 MT_CONNECT_ACKNOWLEDGE, l3ni1_connect_ack},
2804 MT_SUSPEND_ACKNOWLEDGE, l3ni1_suspend_ack},
2806 MT_SUSPEND_REJECT, l3ni1_suspend_rej},
2808 MT_RESUME_ACKNOWLEDGE, l3ni1_resume_ack},
2810 MT_RESUME_REJECT, l3ni1_resume_rej},
2814 (sizeof(datastatelist) / sizeof(struct stateentry))
2816 static struct stateentry globalmes_list[] =
2819 MT_STATUS, l3ni1_status},
2821 MT_RESTART, l3ni1_global_restart},
2823 MT_RESTART_ACKNOWLEDGE, l3ni1_restart_ack},
2825 { SBIT( 0 ), MT_DL_ESTABLISHED, l3ni1_spid_send },
2826 { SBIT( 20 ) | SBIT( 21 ) | SBIT( 22 ), MT_INFORMATION, l3ni1_spid_epid },
2828 #define GLOBALM_LEN \
2829 (sizeof(globalmes_list) / sizeof(struct stateentry))
2831 static struct stateentry manstatelist[] =
2834 DL_ESTABLISH | INDICATION, l3ni1_dl_reset},
2836 DL_ESTABLISH | CONFIRM, l3ni1_dl_reest_status},
2838 DL_RELEASE | INDICATION, l3ni1_dl_reestablish},
2840 DL_RELEASE | INDICATION, l3ni1_dl_release},
2844 (sizeof(manstatelist) / sizeof(struct stateentry))
2849 global_handler(struct PStack *st, int mt, struct sk_buff *skb)
2855 struct l3_process *proc = st->l3.global;
2858 proc->callref = skb->data[2]; /* cr flag */
2861 for (i = 0; i < GLOBALM_LEN; i++)
2862 if ((mt == globalmes_list[i].primitive) &&
2863 ((1 << proc->state) & globalmes_list[i].state))
2865 if (i == GLOBALM_LEN) {
2866 if (st->l3.debug & L3_DEB_STATE) {
2867 l3_debug(st, "ni1 global state %d mt %x unhandled",
2870 MsgHead(p, proc->callref, MT_STATUS);
2874 *p++ = 81 |0x80; /* invalid cr */
2875 *p++ = 0x14; /* CallState */
2877 *p++ = proc->state & 0x3f;
2879 if (!(skb = l3_alloc_skb(l)))
2881 memcpy(skb_put(skb, l), tmp, l);
2882 l3_msg(proc->st, DL_DATA | REQUEST, skb);
2884 if (st->l3.debug & L3_DEB_STATE) {
2885 l3_debug(st, "ni1 global %d mt %x",
2888 globalmes_list[i].rout(proc, mt, skb);
2893 ni1up(struct PStack *st, int pr, void *arg)
2895 int i, mt, cr, cause, callState;
2898 struct sk_buff *skb = arg;
2899 struct l3_process *proc;
2902 case (DL_DATA | INDICATION):
2903 case (DL_UNIT_DATA | INDICATION):
2905 case (DL_ESTABLISH | INDICATION):
2906 case (DL_RELEASE | INDICATION):
2907 case (DL_RELEASE | CONFIRM):
2908 l3_msg(st, pr, arg);
2912 case (DL_ESTABLISH | CONFIRM):
2913 global_handler( st, MT_DL_ESTABLISHED, NULL );
2917 printk(KERN_ERR "HiSax ni1up unknown pr=%04x\n", pr);
2921 l3_debug(st, "ni1up frame too short(%d)", skb->len);
2926 if (skb->data[0] != PROTO_DIS_EURO) {
2927 if (st->l3.debug & L3_DEB_PROTERR) {
2928 l3_debug(st, "ni1up%sunexpected discriminator %x message len %d",
2929 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
2930 skb->data[0], skb->len);
2935 cr = getcallref(skb->data);
2936 if (skb->len < ((skb->data[1] & 0x0f) + 3)) {
2937 l3_debug(st, "ni1up frame too short(%d)", skb->len);
2941 mt = skb->data[skb->data[1] + 2];
2942 if (st->l3.debug & L3_DEB_STATE)
2943 l3_debug(st, "ni1up cr %d", cr);
2944 if (cr == -2) { /* wrong Callref */
2945 if (st->l3.debug & L3_DEB_WARN)
2946 l3_debug(st, "ni1up wrong Callref");
2949 } else if (cr == -1) { /* Dummy Callref */
2950 if (mt == MT_FACILITY)
2952 if ((p = findie(skb->data, skb->len, IE_FACILITY, 0))) {
2953 l3ni1_parse_facility(st, NULL,
2954 (pr == (DL_DATA | INDICATION)) ? -1 : -2, p);
2961 global_handler(st, mt, skb);
2965 if (st->l3.debug & L3_DEB_WARN)
2966 l3_debug(st, "ni1up dummy Callref (no facility msg or ie)");
2969 } else if ((((skb->data[1] & 0x0f) == 1) && (0==(cr & 0x7f))) ||
2970 (((skb->data[1] & 0x0f) == 2) && (0==(cr & 0x7fff)))) { /* Global CallRef */
2971 if (st->l3.debug & L3_DEB_STATE)
2972 l3_debug(st, "ni1up Global CallRef");
2973 global_handler(st, mt, skb);
2976 } else if (!(proc = getl3proc(st, cr))) {
2977 /* No transaction process exist, that means no call with
2978 * this callreference is active
2980 if (mt == MT_SETUP) {
2981 /* Setup creates a new transaction process */
2982 if (skb->data[2] & 0x80) {
2983 /* Setup with wrong CREF flag */
2984 if (st->l3.debug & L3_DEB_STATE)
2985 l3_debug(st, "ni1up wrong CRef flag");
2989 if (!(proc = ni1_new_l3_process(st, cr))) {
2990 /* May be to answer with RELEASE_COMPLETE and
2991 * CAUSE 0x2f "Resource unavailable", but this
2992 * need a new_l3_process too ... arghh
2997 } else if (mt == MT_STATUS) {
2999 if ((ptr = findie(skb->data, skb->len, IE_CAUSE, 0)) != NULL) {
3003 cause = *ptr & 0x7f;
3006 if ((ptr = findie(skb->data, skb->len, IE_CALL_STATE, 0)) != NULL) {
3012 /* ETS 300-104 part 2.4.1
3013 * if setup has not been made and a message type
3014 * MT_STATUS is received with call state == 0,
3015 * we must send nothing
3017 if (callState != 0) {
3018 /* ETS 300-104 part 2.4.2
3019 * if setup has not been made and a message type
3020 * MT_STATUS is received with call state != 0,
3021 * we must send MT_RELEASE_COMPLETE cause 101
3023 if ((proc = ni1_new_l3_process(st, cr))) {
3024 proc->para.cause = 101;
3025 l3ni1_msg_without_setup(proc, 0, NULL);
3030 } else if (mt == MT_RELEASE_COMPLETE) {
3034 /* ETS 300-104 part 2
3035 * if setup has not been made and a message type
3036 * (except MT_SETUP and RELEASE_COMPLETE) is received,
3037 * we must send MT_RELEASE_COMPLETE cause 81 */
3039 if ((proc = ni1_new_l3_process(st, cr))) {
3040 proc->para.cause = 81;
3041 l3ni1_msg_without_setup(proc, 0, NULL);
3046 if (l3ni1_check_messagetype_validity(proc, mt, skb)) {
3050 if ((p = findie(skb->data, skb->len, IE_DISPLAY, 0)) != NULL)
3051 l3ni1_deliver_display(proc, pr, p); /* Display IE included */
3052 for (i = 0; i < DATASLLEN; i++)
3053 if ((mt == datastatelist[i].primitive) &&
3054 ((1 << proc->state) & datastatelist[i].state))
3056 if (i == DATASLLEN) {
3057 if (st->l3.debug & L3_DEB_STATE) {
3058 l3_debug(st, "ni1up%sstate %d mt %#x unhandled",
3059 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
3062 if ((MT_RELEASE_COMPLETE != mt) && (MT_RELEASE != mt)) {
3063 proc->para.cause = 101;
3064 l3ni1_status_send(proc, pr, skb);
3067 if (st->l3.debug & L3_DEB_STATE) {
3068 l3_debug(st, "ni1up%sstate %d mt %x",
3069 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
3072 datastatelist[i].rout(proc, pr, skb);
3079 ni1down(struct PStack *st, int pr, void *arg)
3082 struct l3_process *proc;
3083 struct Channel *chan;
3085 if ((DL_ESTABLISH | REQUEST) == pr) {
3086 l3_msg(st, pr, NULL);
3088 } else if (((CC_SETUP | REQUEST) == pr) || ((CC_RESUME | REQUEST) == pr)) {
3092 if ((proc = ni1_new_l3_process(st, cr))) {
3095 memcpy(&proc->para.setup, &chan->setup, sizeof(setup_parm));
3102 printk(KERN_ERR "HiSax ni1down without proc pr=%04x\n", pr);
3106 if ( pr == (CC_TNI1_IO | REQUEST)) {
3107 l3ni1_io_timer(proc); /* timer expires */
3111 for (i = 0; i < DOWNSLLEN; i++)
3112 if ((pr == downstatelist[i].primitive) &&
3113 ((1 << proc->state) & downstatelist[i].state))
3115 if (i == DOWNSLLEN) {
3116 if (st->l3.debug & L3_DEB_STATE) {
3117 l3_debug(st, "ni1down state %d prim %#x unhandled",
3121 if (st->l3.debug & L3_DEB_STATE) {
3122 l3_debug(st, "ni1down state %d prim %#x",
3125 downstatelist[i].rout(proc, pr, arg);
3130 ni1man(struct PStack *st, int pr, void *arg)
3133 struct l3_process *proc = arg;
3136 printk(KERN_ERR "HiSax ni1man without proc pr=%04x\n", pr);
3139 for (i = 0; i < MANSLLEN; i++)
3140 if ((pr == manstatelist[i].primitive) &&
3141 ((1 << proc->state) & manstatelist[i].state))
3143 if (i == MANSLLEN) {
3144 if (st->l3.debug & L3_DEB_STATE) {
3145 l3_debug(st, "cr %d ni1man state %d prim %#x unhandled",
3146 proc->callref & 0x7f, proc->state, pr);
3149 if (st->l3.debug & L3_DEB_STATE) {
3150 l3_debug(st, "cr %d ni1man state %d prim %#x",
3151 proc->callref & 0x7f, proc->state, pr);
3153 manstatelist[i].rout(proc, pr, arg);
3158 setstack_ni1(struct PStack *st)
3163 st->lli.l4l3 = ni1down;
3164 st->lli.l4l3_proto = l3ni1_cmd_global;
3165 st->l2.l2l3 = ni1up;
3166 st->l3.l3ml3 = ni1man;
3168 st->prot.ni1.last_invoke_id = 0;
3169 st->prot.ni1.invoke_used[0] = 1; /* Bit 0 must always be set to 1 */
3172 st->prot.ni1.invoke_used[i++] = 0;
3174 if (!(st->l3.global = kmalloc(sizeof(struct l3_process), GFP_ATOMIC))) {
3175 printk(KERN_ERR "HiSax can't get memory for ni1 global CR\n");
3177 st->l3.global->state = 0;
3178 st->l3.global->callref = 0;
3179 st->l3.global->next = NULL;
3180 st->l3.global->debug = L3_DEB_WARN;
3181 st->l3.global->st = st;
3182 st->l3.global->N303 = 1;
3183 st->l3.global->prot.ni1.invoke_id = 0;
3185 L3InitTimer(st->l3.global, &st->l3.global->timer);
3187 strcpy(tmp, ni1_revision);
3188 printk(KERN_INFO "HiSax: National ISDN-1 Rev. %s\n", HiSax_getrev(tmp));