Fix typos.
[linux-2.6/linux-mips.git] / drivers / isdn / hisax / l3dss1.c
bloba2cae62f6bcc7481e5a9f95756f495d2a1245daa
1 /* $Id: l3dss1.c,v 2.30.6.2 2001/09/23 22:24:49 kai Exp $
3 * EURO/DSS1 D-channel protocol
5 * German 1TR6 D-channel protocol
7 * Author Karsten Keil
8 * based on the teles driver from Jan den Ouden
9 * Copyright by Karsten Keil <keil@isdn4linux.de>
11 * This software may be used and distributed according to the terms
12 * of the GNU General Public License, incorporated herein by reference.
14 * For changes and modifications please read
15 * ../../../Documentation/isdn/HiSax.cert
17 * Thanks to Jan den Ouden
18 * Fritz Elfert
22 #include "hisax.h"
23 #include "isdnl3.h"
24 #include "l3dss1.h"
25 #include <linux/ctype.h>
26 #include <linux/config.h>
28 extern char *HiSax_getrev(const char *revision);
29 const char *dss1_revision = "$Revision: 2.30.6.2 $";
30 static spinlock_t l3dss1_lock = SPIN_LOCK_UNLOCKED;
32 #define EXT_BEARER_CAPS 1
34 #define MsgHead(ptr, cref, mty) \
35 *ptr++ = 0x8; \
36 if (cref == -1) { \
37 *ptr++ = 0x0; \
38 } else { \
39 *ptr++ = 0x1; \
40 *ptr++ = cref^0x80; \
41 } \
42 *ptr++ = mty
45 /**********************************************/
46 /* get a new invoke id for remote operations. */
47 /* Only a return value != 0 is valid */
48 /**********************************************/
49 static unsigned char new_invoke_id(struct PStack *p)
51 unsigned char retval;
52 unsigned long flags;
53 int i;
55 i = 32; /* maximum search depth */
57 spin_lock_irqsave(&l3dss1_lock, flags);
59 retval = p->prot.dss1.last_invoke_id + 1; /* try new id */
60 while ((i) && (p->prot.dss1.invoke_used[retval >> 3] == 0xFF)) {
61 p->prot.dss1.last_invoke_id = (retval & 0xF8) + 8;
62 i--;
64 if (i) {
65 while (p->prot.dss1.invoke_used[retval >> 3] & (1 << (retval & 7)))
66 retval++;
67 } else
68 retval = 0;
69 p->prot.dss1.last_invoke_id = retval;
70 p->prot.dss1.invoke_used[retval >> 3] |= (1 << (retval & 7));
71 spin_unlock_irqrestore(&l3dss1_lock, flags);
73 return(retval);
74 } /* new_invoke_id */
76 /*************************/
77 /* free a used invoke id */
78 /*************************/
79 static void free_invoke_id(struct PStack *p, unsigned char id)
80 { unsigned long flags;
82 if (!id) return; /* 0 = invalid value */
84 spin_lock_irqsave(&l3dss1_lock, flags);
85 p->prot.dss1.invoke_used[id >> 3] &= ~(1 << (id & 7));
86 spin_unlock_irqrestore(&l3dss1_lock, flags);
87 } /* free_invoke_id */
90 /**********************************************************/
91 /* create a new l3 process and fill in dss1 specific data */
92 /**********************************************************/
93 static struct l3_process
94 *dss1_new_l3_process(struct PStack *st, int cr)
95 { struct l3_process *proc;
97 if (!(proc = new_l3_process(st, cr)))
98 return(NULL);
100 proc->prot.dss1.invoke_id = 0;
101 proc->prot.dss1.remote_operation = 0;
102 proc->prot.dss1.uus1_data[0] = '\0';
104 return(proc);
105 } /* dss1_new_l3_process */
107 /************************************************/
108 /* free a l3 process and all dss1 specific data */
109 /************************************************/
110 static void
111 dss1_release_l3_process(struct l3_process *p)
113 free_invoke_id(p->st,p->prot.dss1.invoke_id);
114 release_l3_process(p);
115 } /* dss1_release_l3_process */
117 /********************************************************/
118 /* search a process with invoke id id and dummy callref */
119 /********************************************************/
120 static struct l3_process *
121 l3dss1_search_dummy_proc(struct PStack *st, int id)
122 { struct l3_process *pc = st->l3.proc; /* start of processes */
124 if (!id) return(NULL);
126 while (pc)
127 { if ((pc->callref == -1) && (pc->prot.dss1.invoke_id == id))
128 return(pc);
129 pc = pc->next;
131 return(NULL);
132 } /* l3dss1_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 /*******************************************************************/
138 static void
139 l3dss1_dummy_return_result(struct PStack *st, int id, u8 *p, u8 nlen)
140 { isdn_ctrl ic;
141 struct IsdnCardState *cs;
142 struct l3_process *pc = NULL;
144 if ((pc = l3dss1_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 = DSS1_STAT_INVOKE_RES;
151 ic.parm.dss1_io.hl_id = pc->prot.dss1.invoke_id;
152 ic.parm.dss1_io.ll_id = pc->prot.dss1.ll_id;
153 ic.parm.dss1_io.proc = pc->prot.dss1.proc;
154 ic.parm.dss1_io.timeout= 0;
155 ic.parm.dss1_io.datalen = nlen;
156 ic.parm.dss1_io.data = p;
157 free_invoke_id(pc->st, pc->prot.dss1.invoke_id);
158 pc->prot.dss1.invoke_id = 0; /* reset id */
160 cs->iif.statcallb(&ic);
161 dss1_release_l3_process(pc);
163 else
164 l3_debug(st, "dummy return result id=0x%x result len=%d",id,nlen);
165 } /* l3dss1_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 /*******************************************************************/
171 static void
172 l3dss1_dummy_error_return(struct PStack *st, int id, ulong error)
173 { isdn_ctrl ic;
174 struct IsdnCardState *cs;
175 struct l3_process *pc = NULL;
177 if ((pc = l3dss1_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 = DSS1_STAT_INVOKE_ERR;
184 ic.parm.dss1_io.hl_id = pc->prot.dss1.invoke_id;
185 ic.parm.dss1_io.ll_id = pc->prot.dss1.ll_id;
186 ic.parm.dss1_io.proc = pc->prot.dss1.proc;
187 ic.parm.dss1_io.timeout= error;
188 ic.parm.dss1_io.datalen = 0;
189 ic.parm.dss1_io.data = NULL;
190 free_invoke_id(pc->st, pc->prot.dss1.invoke_id);
191 pc->prot.dss1.invoke_id = 0; /* reset id */
193 cs->iif.statcallb(&ic);
194 dss1_release_l3_process(pc);
196 else
197 l3_debug(st, "dummy return error id=0x%x error=0x%lx",id,error);
198 } /* l3dss1_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 /*******************************************************************/
204 static void
205 l3dss1_dummy_invoke(struct PStack *st, int cr, int id,
206 int ident, u8 *p, u8 nlen)
207 { isdn_ctrl ic;
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 = DSS1_STAT_INVOKE_BRD;
218 ic.parm.dss1_io.hl_id = id;
219 ic.parm.dss1_io.ll_id = 0;
220 ic.parm.dss1_io.proc = ident;
221 ic.parm.dss1_io.timeout= 0;
222 ic.parm.dss1_io.datalen = nlen;
223 ic.parm.dss1_io.data = p;
225 cs->iif.statcallb(&ic);
226 } /* l3dss1_dummy_invoke */
228 static void
229 l3dss1_parse_facility(struct PStack *st, struct l3_process *pc,
230 int cr, u8 * p)
232 int qd_len = 0;
233 unsigned char nlen = 0, ilen, cp_tag;
234 int ident, id;
235 ulong err_ret;
237 if (pc)
238 st = pc->st; /* valid Stack */
239 else
240 if ((!st) || (cr >= 0)) return; /* neither pc nor st specified */
242 p++;
243 qd_len = *p++;
244 if (qd_len == 0) {
245 l3_debug(st, "qd_len == 0");
246 return;
248 if ((*p & 0x1F) != 0x11) { /* Service discriminator, supplementary service */
249 l3_debug(st, "supplementary service != 0x11");
250 return;
252 while (qd_len > 0 && !(*p & 0x80)) { /* extension ? */
253 p++;
254 qd_len--;
256 if (qd_len < 2) {
257 l3_debug(st, "qd_len < 2");
258 return;
260 p++;
261 qd_len--;
262 if ((*p & 0xE0) != 0xA0) { /* class and form */
263 l3_debug(st, "class and form != 0xA0");
264 return;
267 cp_tag = *p & 0x1F; /* remember tag value */
269 p++;
270 qd_len--;
271 if (qd_len < 1)
272 { l3_debug(st, "qd_len < 1");
273 return;
275 if (*p & 0x80)
276 { /* length format indefinite or limited */
277 nlen = *p++ & 0x7F; /* number of len bytes or indefinite */
278 if ((qd_len-- < ((!nlen) ? 3 : (1 + nlen))) ||
279 (nlen > 1))
280 { l3_debug(st, "length format error or not implemented");
281 return;
283 if (nlen == 1)
284 { nlen = *p++; /* complete length */
285 qd_len--;
287 else
288 { qd_len -= 2; /* trailing null bytes */
289 if ((*(p+qd_len)) || (*(p+qd_len+1)))
290 { l3_debug(st,"length format indefinite error");
291 return;
293 nlen = qd_len;
296 else
297 { nlen = *p++;
298 qd_len--;
300 if (qd_len < nlen)
301 { l3_debug(st, "qd_len < nlen");
302 return;
304 qd_len -= nlen;
306 if (nlen < 2)
307 { l3_debug(st, "nlen < 2");
308 return;
310 if (*p != 0x02)
311 { /* invoke identifier tag */
312 l3_debug(st, "invoke identifier tag !=0x02");
313 return;
315 p++;
316 nlen--;
317 if (*p & 0x80)
318 { /* length format */
319 l3_debug(st, "invoke id length format 2");
320 return;
322 ilen = *p++;
323 nlen--;
324 if (ilen > nlen || ilen == 0)
325 { l3_debug(st, "ilen > nlen || ilen == 0");
326 return;
328 nlen -= ilen;
329 id = 0;
330 while (ilen > 0)
331 { id = (id << 8) | (*p++ & 0xFF); /* invoke identifier */
332 ilen--;
335 switch (cp_tag) { /* component tag */
336 case 1: /* invoke */
337 if (nlen < 2) {
338 l3_debug(st, "nlen < 2 22");
339 return;
341 if (*p != 0x02) { /* operation value */
342 l3_debug(st, "operation value !=0x02");
343 return;
345 p++;
346 nlen--;
347 ilen = *p++;
348 nlen--;
349 if (ilen > nlen || ilen == 0) {
350 l3_debug(st, "ilen > nlen || ilen == 0 22");
351 return;
353 nlen -= ilen;
354 ident = 0;
355 while (ilen > 0) {
356 ident = (ident << 8) | (*p++ & 0xFF);
357 ilen--;
360 if (!pc)
361 { l3dss1_dummy_invoke(st, cr, id, ident, p, nlen);
362 return;
364 #if HISAX_DE_AOC
367 #define FOO1(s,a,b) \
368 while(nlen > 1) { \
369 int ilen = p[1]; \
370 if(nlen < ilen+2) { \
371 l3_debug(st, "FOO1 nlen < ilen+2"); \
372 return; \
374 nlen -= ilen+2; \
375 if((*p & 0xFF) == (a)) { \
376 int nlen = ilen; \
377 p += 2; \
378 b; \
379 } else { \
380 p += ilen+2; \
384 switch (ident) {
385 case 0x22: /* during */
386 FOO1("1A", 0x30, FOO1("1C", 0xA1, FOO1("1D", 0x30, FOO1("1E", 0x02, ( {
387 ident = 0;
388 nlen = (nlen)?nlen:0; /* Make gcc happy */
389 while (ilen > 0) {
390 ident = (ident << 8) | *p++;
391 ilen--;
393 if (ident > pc->para.chargeinfo) {
394 pc->para.chargeinfo = ident;
395 st->l3.l3l4(st, CC_CHARGE | INDICATION, pc);
397 if (st->l3.debug & L3_DEB_CHARGE) {
398 if (*(p + 2) == 0) {
399 l3_debug(st, "charging info during %d", pc->para.chargeinfo);
401 else {
402 l3_debug(st, "charging info final %d", pc->para.chargeinfo);
406 )))))
407 break;
408 case 0x24: /* final */
409 FOO1("2A", 0x30, FOO1("2B", 0x30, FOO1("2C", 0xA1, FOO1("2D", 0x30, FOO1("2E", 0x02, ( {
410 ident = 0;
411 nlen = (nlen)?nlen:0; /* Make gcc happy */
412 while (ilen > 0) {
413 ident = (ident << 8) | *p++;
414 ilen--;
416 if (ident > pc->para.chargeinfo) {
417 pc->para.chargeinfo = ident;
418 st->l3.l3l4(st, CC_CHARGE | INDICATION, pc);
420 if (st->l3.debug & L3_DEB_CHARGE) {
421 l3_debug(st, "charging info final %d", pc->para.chargeinfo);
424 ))))))
425 break;
426 default:
427 l3_debug(st, "invoke break invalid ident %02x",ident);
428 break;
430 #undef FOO1
433 #else /* not HISAX_DE_AOC */
434 l3_debug(st, "invoke break");
435 #endif /* not HISAX_DE_AOC */
436 break;
437 case 2: /* return result */
438 /* if no process available handle separately */
439 if (!pc)
440 { if (cr == -1)
441 l3dss1_dummy_return_result(st, id, p, nlen);
442 return;
444 if ((pc->prot.dss1.invoke_id) && (pc->prot.dss1.invoke_id == id))
445 { /* Diversion successful */
446 free_invoke_id(st,pc->prot.dss1.invoke_id);
447 pc->prot.dss1.remote_result = 0; /* success */
448 pc->prot.dss1.invoke_id = 0;
449 pc->redir_result = pc->prot.dss1.remote_result;
450 L3L4(st, CC_REDIR | INDICATION, pc); } /* Diversion successful */
451 else
452 l3_debug(st,"return error unknown identifier");
453 break;
454 case 3: /* return error */
455 err_ret = 0;
456 if (nlen < 2)
457 { l3_debug(st, "return error nlen < 2");
458 return;
460 if (*p != 0x02)
461 { /* result tag */
462 l3_debug(st, "invoke error tag !=0x02");
463 return;
465 p++;
466 nlen--;
467 if (*p > 4)
468 { /* length format */
469 l3_debug(st, "invoke return errlen > 4 ");
470 return;
472 ilen = *p++;
473 nlen--;
474 if (ilen > nlen || ilen == 0)
475 { l3_debug(st, "error return ilen > nlen || ilen == 0");
476 return;
478 nlen -= ilen;
479 while (ilen > 0)
480 { err_ret = (err_ret << 8) | (*p++ & 0xFF); /* error value */
481 ilen--;
483 /* if no process available handle separately */
484 if (!pc)
485 { if (cr == -1)
486 l3dss1_dummy_error_return(st, id, err_ret);
487 return;
489 if ((pc->prot.dss1.invoke_id) && (pc->prot.dss1.invoke_id == id))
490 { /* Deflection error */
491 free_invoke_id(st,pc->prot.dss1.invoke_id);
492 pc->prot.dss1.remote_result = err_ret; /* result */
493 pc->prot.dss1.invoke_id = 0;
494 pc->redir_result = pc->prot.dss1.remote_result;
495 L3L4(st, CC_REDIR | INDICATION, pc);
496 } /* Deflection error */
497 else
498 l3_debug(st,"return result unknown identifier");
499 break;
500 default:
501 l3_debug(st, "facility default break tag=0x%02x",cp_tag);
502 break;
506 static void
507 l3dss1_message(struct l3_process *pc, u8 mt)
509 struct sk_buff *skb;
510 u8 *p;
512 if (!(skb = l3_alloc_skb(4)))
513 return;
514 p = skb_put(skb, 4);
515 MsgHead(p, pc->callref, mt);
516 l3_msg(pc->st, DL_DATA | REQUEST, skb);
519 static void
520 l3dss1_message_cause(struct l3_process *pc, u8 mt, u8 cause)
522 struct sk_buff *skb;
523 u8 tmp[16];
524 u8 *p = tmp;
525 int l;
527 MsgHead(p, pc->callref, mt);
528 *p++ = IE_CAUSE;
529 *p++ = 0x2;
530 *p++ = 0x80;
531 *p++ = cause | 0x80;
533 l = p - tmp;
534 if (!(skb = l3_alloc_skb(l)))
535 return;
536 memcpy(skb_put(skb, l), tmp, l);
537 l3_msg(pc->st, DL_DATA | REQUEST, skb);
540 static void
541 l3dss1_status_send(struct l3_process *pc, u8 pr, void *arg)
543 u8 tmp[16];
544 u8 *p = tmp;
545 int l;
546 struct sk_buff *skb;
548 MsgHead(p, pc->callref, MT_STATUS);
550 *p++ = IE_CAUSE;
551 *p++ = 0x2;
552 *p++ = 0x80;
553 *p++ = pc->para.cause | 0x80;
555 *p++ = IE_CALL_STATE;
556 *p++ = 0x1;
557 *p++ = pc->state & 0x3f;
559 l = p - tmp;
560 if (!(skb = l3_alloc_skb(l)))
561 return;
562 memcpy(skb_put(skb, l), tmp, l);
563 l3_msg(pc->st, DL_DATA | REQUEST, skb);
566 static void
567 l3dss1_msg_without_setup(struct l3_process *pc, u8 pr, void *arg)
569 /* This routine is called if here was no SETUP made (checks in dss1up and in
570 * l3dss1_setup) and a RELEASE_COMPLETE have to be sent with an error code
571 * MT_STATUS_ENQUIRE in the NULL state is handled too
573 u8 tmp[16];
574 u8 *p = tmp;
575 int l;
576 struct sk_buff *skb;
578 switch (pc->para.cause) {
579 case 81: /* invalid callreference */
580 case 88: /* incomp destination */
581 case 96: /* mandory IE missing */
582 case 100: /* invalid IE contents */
583 case 101: /* incompatible Callstate */
584 MsgHead(p, pc->callref, MT_RELEASE_COMPLETE);
585 *p++ = IE_CAUSE;
586 *p++ = 0x2;
587 *p++ = 0x80;
588 *p++ = pc->para.cause | 0x80;
589 break;
590 default:
591 printk(KERN_ERR "HiSax l3dss1_msg_without_setup wrong cause %d\n",
592 pc->para.cause);
593 return;
595 l = p - tmp;
596 if (!(skb = l3_alloc_skb(l)))
597 return;
598 memcpy(skb_put(skb, l), tmp, l);
599 l3_msg(pc->st, DL_DATA | REQUEST, skb);
600 dss1_release_l3_process(pc);
603 static int ie_ALERTING[] = {IE_BEARER, IE_CHANNEL_ID | IE_MANDATORY_1,
604 IE_FACILITY, IE_PROGRESS, IE_DISPLAY, IE_SIGNAL, IE_HLC,
605 IE_USER_USER, -1};
606 static int ie_CALL_PROCEEDING[] = {IE_BEARER, IE_CHANNEL_ID | IE_MANDATORY_1,
607 IE_FACILITY, IE_PROGRESS, IE_DISPLAY, IE_HLC, -1};
608 static int ie_CONNECT[] = {IE_BEARER, IE_CHANNEL_ID | IE_MANDATORY_1,
609 IE_FACILITY, IE_PROGRESS, IE_DISPLAY, IE_DATE, IE_SIGNAL,
610 IE_CONNECT_PN, IE_CONNECT_SUB, IE_LLC, IE_HLC, IE_USER_USER, -1};
611 static int ie_CONNECT_ACKNOWLEDGE[] = {IE_CHANNEL_ID, IE_DISPLAY, IE_SIGNAL, -1};
612 static int ie_DISCONNECT[] = {IE_CAUSE | IE_MANDATORY, IE_FACILITY,
613 IE_PROGRESS, IE_DISPLAY, IE_SIGNAL, IE_USER_USER, -1};
614 static int ie_INFORMATION[] = {IE_COMPLETE, IE_DISPLAY, IE_KEYPAD, IE_SIGNAL,
615 IE_CALLED_PN, -1};
616 static int ie_NOTIFY[] = {IE_BEARER, IE_NOTIFY | IE_MANDATORY, IE_DISPLAY, -1};
617 static int ie_PROGRESS[] = {IE_BEARER, IE_CAUSE, IE_FACILITY, IE_PROGRESS |
618 IE_MANDATORY, IE_DISPLAY, IE_HLC, IE_USER_USER, -1};
619 static int ie_RELEASE[] = {IE_CAUSE | IE_MANDATORY_1, IE_FACILITY, IE_DISPLAY,
620 IE_SIGNAL, IE_USER_USER, -1};
621 /* a RELEASE_COMPLETE with errors don't require special actions
622 static int ie_RELEASE_COMPLETE[] = {IE_CAUSE | IE_MANDATORY_1, IE_DISPLAY, IE_SIGNAL, IE_USER_USER, -1};
624 static int ie_RESUME_ACKNOWLEDGE[] = {IE_CHANNEL_ID| IE_MANDATORY, IE_FACILITY,
625 IE_DISPLAY, -1};
626 static int ie_RESUME_REJECT[] = {IE_CAUSE | IE_MANDATORY, IE_DISPLAY, -1};
627 static int ie_SETUP[] = {IE_COMPLETE, IE_BEARER | IE_MANDATORY,
628 IE_CHANNEL_ID| IE_MANDATORY, IE_FACILITY, IE_PROGRESS,
629 IE_NET_FAC, IE_DISPLAY, IE_KEYPAD, IE_SIGNAL, IE_CALLING_PN,
630 IE_CALLING_SUB, IE_CALLED_PN, IE_CALLED_SUB, IE_REDIR_NR,
631 IE_LLC, IE_HLC, IE_USER_USER, -1};
632 static int ie_SETUP_ACKNOWLEDGE[] = {IE_CHANNEL_ID | IE_MANDATORY, IE_FACILITY,
633 IE_PROGRESS, IE_DISPLAY, IE_SIGNAL, -1};
634 static int ie_STATUS[] = {IE_CAUSE | IE_MANDATORY, IE_CALL_STATE |
635 IE_MANDATORY, IE_DISPLAY, -1};
636 static int ie_STATUS_ENQUIRY[] = {IE_DISPLAY, -1};
637 static int ie_SUSPEND_ACKNOWLEDGE[] = {IE_DISPLAY, IE_FACILITY, -1};
638 static int ie_SUSPEND_REJECT[] = {IE_CAUSE | IE_MANDATORY, IE_DISPLAY, -1};
639 /* not used
640 * static int ie_CONGESTION_CONTROL[] = {IE_CONGESTION | IE_MANDATORY,
641 * IE_CAUSE | IE_MANDATORY, IE_DISPLAY, -1};
642 * static int ie_USER_INFORMATION[] = {IE_MORE_DATA, IE_USER_USER | IE_MANDATORY, -1};
643 * static int ie_RESTART[] = {IE_CHANNEL_ID, IE_DISPLAY, IE_RESTART_IND |
644 * IE_MANDATORY, -1};
646 static int ie_FACILITY[] = {IE_FACILITY | IE_MANDATORY, IE_DISPLAY, -1};
647 static int comp_required[] = {1,2,3,5,6,7,9,10,11,14,15,-1};
648 static int l3_valid_states[] = {0,1,2,3,4,6,7,8,9,10,11,12,15,17,19,25,-1};
650 struct ie_len {
651 int ie;
652 int len;
655 static
656 struct ie_len max_ie_len[] = {
657 {IE_SEGMENT, 4},
658 {IE_BEARER, 12},
659 {IE_CAUSE, 32},
660 {IE_CALL_ID, 10},
661 {IE_CALL_STATE, 3},
662 {IE_CHANNEL_ID, 34},
663 {IE_FACILITY, 255},
664 {IE_PROGRESS, 4},
665 {IE_NET_FAC, 255},
666 {IE_NOTIFY, 3},
667 {IE_DISPLAY, 82},
668 {IE_DATE, 8},
669 {IE_KEYPAD, 34},
670 {IE_SIGNAL, 3},
671 {IE_INFORATE, 6},
672 {IE_E2E_TDELAY, 11},
673 {IE_TDELAY_SEL, 5},
674 {IE_PACK_BINPARA, 3},
675 {IE_PACK_WINSIZE, 4},
676 {IE_PACK_SIZE, 4},
677 {IE_CUG, 7},
678 {IE_REV_CHARGE, 3},
679 {IE_CALLING_PN, 24},
680 {IE_CALLING_SUB, 23},
681 {IE_CALLED_PN, 24},
682 {IE_CALLED_SUB, 23},
683 {IE_REDIR_NR, 255},
684 {IE_TRANS_SEL, 255},
685 {IE_RESTART_IND, 3},
686 {IE_LLC, 18},
687 {IE_HLC, 5},
688 {IE_USER_USER, 131},
689 {-1,0},
692 static int
693 getmax_ie_len(u8 ie) {
694 int i = 0;
695 while (max_ie_len[i].ie != -1) {
696 if (max_ie_len[i].ie == ie)
697 return(max_ie_len[i].len);
698 i++;
700 return(255);
703 static int
704 ie_in_set(struct l3_process *pc, u8 ie, int *checklist) {
705 int ret = 1;
707 while (*checklist != -1) {
708 if ((*checklist & 0xff) == ie) {
709 if (ie & 0x80)
710 return(-ret);
711 else
712 return(ret);
714 ret++;
715 checklist++;
717 return(0);
720 static int
721 check_infoelements(struct l3_process *pc, struct sk_buff *skb, int *checklist)
723 int *cl = checklist;
724 u8 mt;
725 u8 *p, ie;
726 int l, newpos, oldpos;
727 int err_seq = 0, err_len = 0, err_compr = 0, err_ureg = 0;
728 u8 codeset = 0;
729 u8 old_codeset = 0;
730 u8 codelock = 1;
732 p = skb->data;
733 /* skip cr */
734 p++;
735 l = (*p++) & 0xf;
736 p += l;
737 mt = *p++;
738 oldpos = 0;
739 while ((p - skb->data) < skb->len) {
740 if ((*p & 0xf0) == 0x90) { /* shift codeset */
741 old_codeset = codeset;
742 codeset = *p & 7;
743 if (*p & 0x08)
744 codelock = 0;
745 else
746 codelock = 1;
747 if (pc->debug & L3_DEB_CHECK)
748 l3_debug(pc->st, "check IE shift%scodeset %d->%d",
749 codelock ? " locking ": " ", old_codeset, codeset);
750 p++;
751 continue;
753 if (!codeset) { /* only codeset 0 */
754 if ((newpos = ie_in_set(pc, *p, cl))) {
755 if (newpos > 0) {
756 if (newpos < oldpos)
757 err_seq++;
758 else
759 oldpos = newpos;
761 } else {
762 if (ie_in_set(pc, *p, comp_required))
763 err_compr++;
764 else
765 err_ureg++;
768 ie = *p++;
769 if (ie & 0x80) {
770 l = 1;
771 } else {
772 l = *p++;
773 p += l;
774 l += 2;
776 if (!codeset && (l > getmax_ie_len(ie)))
777 err_len++;
778 if (!codelock) {
779 if (pc->debug & L3_DEB_CHECK)
780 l3_debug(pc->st, "check IE shift back codeset %d->%d",
781 codeset, old_codeset);
782 codeset = old_codeset;
783 codelock = 1;
786 if (err_compr | err_ureg | err_len | err_seq) {
787 if (pc->debug & L3_DEB_CHECK)
788 l3_debug(pc->st, "check IE MT(%x) %d/%d/%d/%d",
789 mt, err_compr, err_ureg, err_len, err_seq);
790 if (err_compr)
791 return(ERR_IE_COMPREHENSION);
792 if (err_ureg)
793 return(ERR_IE_UNRECOGNIZED);
794 if (err_len)
795 return(ERR_IE_LENGTH);
796 if (err_seq)
797 return(ERR_IE_SEQUENCE);
799 return(0);
802 /* verify if a message type exists and contain no IE error */
803 static int
804 l3dss1_check_messagetype_validity(struct l3_process *pc, int mt, void *arg)
806 switch (mt) {
807 case MT_ALERTING:
808 case MT_CALL_PROCEEDING:
809 case MT_CONNECT:
810 case MT_CONNECT_ACKNOWLEDGE:
811 case MT_DISCONNECT:
812 case MT_INFORMATION:
813 case MT_FACILITY:
814 case MT_NOTIFY:
815 case MT_PROGRESS:
816 case MT_RELEASE:
817 case MT_RELEASE_COMPLETE:
818 case MT_SETUP:
819 case MT_SETUP_ACKNOWLEDGE:
820 case MT_RESUME_ACKNOWLEDGE:
821 case MT_RESUME_REJECT:
822 case MT_SUSPEND_ACKNOWLEDGE:
823 case MT_SUSPEND_REJECT:
824 case MT_USER_INFORMATION:
825 case MT_RESTART:
826 case MT_RESTART_ACKNOWLEDGE:
827 case MT_CONGESTION_CONTROL:
828 case MT_STATUS:
829 case MT_STATUS_ENQUIRY:
830 if (pc->debug & L3_DEB_CHECK)
831 l3_debug(pc->st, "l3dss1_check_messagetype_validity mt(%x) OK", mt);
832 break;
833 case MT_RESUME: /* RESUME only in user->net */
834 case MT_SUSPEND: /* SUSPEND only in user->net */
835 default:
836 if (pc->debug & (L3_DEB_CHECK | L3_DEB_WARN))
837 l3_debug(pc->st, "l3dss1_check_messagetype_validity mt(%x) fail", mt);
838 pc->para.cause = 97;
839 l3dss1_status_send(pc, 0, NULL);
840 return(1);
842 return(0);
845 static void
846 l3dss1_std_ie_err(struct l3_process *pc, int ret) {
848 if (pc->debug & L3_DEB_CHECK)
849 l3_debug(pc->st, "check_infoelements ret %d", ret);
850 switch(ret) {
851 case 0:
852 break;
853 case ERR_IE_COMPREHENSION:
854 pc->para.cause = 96;
855 l3dss1_status_send(pc, 0, NULL);
856 break;
857 case ERR_IE_UNRECOGNIZED:
858 pc->para.cause = 99;
859 l3dss1_status_send(pc, 0, NULL);
860 break;
861 case ERR_IE_LENGTH:
862 pc->para.cause = 100;
863 l3dss1_status_send(pc, 0, NULL);
864 break;
865 case ERR_IE_SEQUENCE:
866 default:
867 break;
871 static int
872 l3dss1_get_channel_id(struct l3_process *pc, struct sk_buff *skb) {
873 u8 *p;
875 p = skb->data;
876 if ((p = findie(p, skb->len, IE_CHANNEL_ID, 0))) {
877 p++;
878 if (*p != 1) { /* len for BRI = 1 */
879 if (pc->debug & L3_DEB_WARN)
880 l3_debug(pc->st, "wrong chid len %d", *p);
881 return (-2);
883 p++;
884 if (*p & 0x60) { /* only base rate interface */
885 if (pc->debug & L3_DEB_WARN)
886 l3_debug(pc->st, "wrong chid %x", *p);
887 return (-3);
889 return(*p & 0x3);
890 } else
891 return(-1);
894 static int
895 l3dss1_get_cause(struct l3_process *pc, struct sk_buff *skb) {
896 u8 l, i=0;
897 u8 *p;
899 p = skb->data;
900 pc->para.cause = 31;
901 pc->para.loc = 0;
902 if ((p = findie(p, skb->len, IE_CAUSE, 0))) {
903 p++;
904 l = *p++;
905 if (l>30)
906 return(1);
907 if (l) {
908 pc->para.loc = *p++;
909 l--;
910 } else {
911 return(2);
913 if (l && !(pc->para.loc & 0x80)) {
914 l--;
915 p++; /* skip recommendation */
917 if (l) {
918 pc->para.cause = *p++;
919 l--;
920 if (!(pc->para.cause & 0x80))
921 return(3);
922 } else
923 return(4);
924 while (l && (i<6)) {
925 pc->para.diag[i++] = *p++;
926 l--;
928 } else
929 return(-1);
930 return(0);
933 static void
934 l3dss1_msg_with_uus(struct l3_process *pc, u8 cmd)
936 struct sk_buff *skb;
937 u8 tmp[16+40];
938 u8 *p = tmp;
939 int l;
941 MsgHead(p, pc->callref, cmd);
943 if (pc->prot.dss1.uus1_data[0])
944 { *p++ = IE_USER_USER; /* UUS info element */
945 *p++ = strlen(pc->prot.dss1.uus1_data) + 1;
946 *p++ = 0x04; /* IA5 chars */
947 strcpy(p,pc->prot.dss1.uus1_data);
948 p += strlen(pc->prot.dss1.uus1_data);
949 pc->prot.dss1.uus1_data[0] = '\0';
952 l = p - tmp;
953 if (!(skb = l3_alloc_skb(l)))
954 return;
955 memcpy(skb_put(skb, l), tmp, l);
956 l3_msg(pc->st, DL_DATA | REQUEST, skb);
957 } /* l3dss1_msg_with_uus */
959 static void
960 l3dss1_release_req(struct l3_process *pc, u8 pr, void *arg)
962 StopAllL3Timer(pc);
963 newl3state(pc, 19);
964 if (!pc->prot.dss1.uus1_data[0])
965 l3dss1_message(pc, MT_RELEASE);
966 else
967 l3dss1_msg_with_uus(pc, MT_RELEASE);
968 L3AddTimer(&pc->timer, T308, CC_T308_1);
971 static void
972 l3dss1_release_cmpl(struct l3_process *pc, u8 pr, void *arg)
974 struct sk_buff *skb = arg;
975 int ret;
977 if ((ret = l3dss1_get_cause(pc, skb))>0) {
978 if (pc->debug & L3_DEB_WARN)
979 l3_debug(pc->st, "RELCMPL get_cause ret(%d)",ret);
980 } else if (ret < 0)
981 pc->para.cause = NO_CAUSE;
982 StopAllL3Timer(pc);
983 newl3state(pc, 0);
984 L3L4(pc->st, CC_RELEASE | CONFIRM, pc);
985 dss1_release_l3_process(pc);
988 #if EXT_BEARER_CAPS
990 static u8 *
991 EncodeASyncParams(u8 * p, u8 si2)
992 { // 7c 06 88 90 21 42 00 bb
994 p[0] = 0;
995 p[1] = 0x40; // Intermediate rate: 16 kbit/s jj 2000.02.19
996 p[2] = 0x80;
997 if (si2 & 32) // 7 data bits
999 p[2] += 16;
1000 else // 8 data bits
1002 p[2] += 24;
1004 if (si2 & 16) // 2 stop bits
1006 p[2] += 96;
1007 else // 1 stop bit
1009 p[2] += 32;
1011 if (si2 & 8) // even parity
1013 p[2] += 2;
1014 else // no parity
1016 p[2] += 3;
1018 switch (si2 & 0x07) {
1019 case 0:
1020 p[0] = 66; // 1200 bit/s
1022 break;
1023 case 1:
1024 p[0] = 88; // 1200/75 bit/s
1026 break;
1027 case 2:
1028 p[0] = 87; // 75/1200 bit/s
1030 break;
1031 case 3:
1032 p[0] = 67; // 2400 bit/s
1034 break;
1035 case 4:
1036 p[0] = 69; // 4800 bit/s
1038 break;
1039 case 5:
1040 p[0] = 72; // 9600 bit/s
1042 break;
1043 case 6:
1044 p[0] = 73; // 14400 bit/s
1046 break;
1047 case 7:
1048 p[0] = 75; // 19200 bit/s
1050 break;
1052 return p + 3;
1055 static u8
1056 EncodeSyncParams(u8 si2, u8 ai)
1059 switch (si2) {
1060 case 0:
1061 return ai + 2; // 1200 bit/s
1063 case 1:
1064 return ai + 24; // 1200/75 bit/s
1066 case 2:
1067 return ai + 23; // 75/1200 bit/s
1069 case 3:
1070 return ai + 3; // 2400 bit/s
1072 case 4:
1073 return ai + 5; // 4800 bit/s
1075 case 5:
1076 return ai + 8; // 9600 bit/s
1078 case 6:
1079 return ai + 9; // 14400 bit/s
1081 case 7:
1082 return ai + 11; // 19200 bit/s
1084 case 8:
1085 return ai + 14; // 48000 bit/s
1087 case 9:
1088 return ai + 15; // 56000 bit/s
1090 case 15:
1091 return ai + 40; // negotiate bit/s
1093 default:
1094 break;
1096 return ai;
1100 static u8
1101 DecodeASyncParams(u8 si2, u8 * p)
1103 u8 info;
1105 switch (p[5]) {
1106 case 66: // 1200 bit/s
1108 break; // si2 don't change
1110 case 88: // 1200/75 bit/s
1112 si2 += 1;
1113 break;
1114 case 87: // 75/1200 bit/s
1116 si2 += 2;
1117 break;
1118 case 67: // 2400 bit/s
1120 si2 += 3;
1121 break;
1122 case 69: // 4800 bit/s
1124 si2 += 4;
1125 break;
1126 case 72: // 9600 bit/s
1128 si2 += 5;
1129 break;
1130 case 73: // 14400 bit/s
1132 si2 += 6;
1133 break;
1134 case 75: // 19200 bit/s
1136 si2 += 7;
1137 break;
1140 info = p[7] & 0x7f;
1141 if ((info & 16) && (!(info & 8))) // 7 data bits
1143 si2 += 32; // else 8 data bits
1145 if ((info & 96) == 96) // 2 stop bits
1147 si2 += 16; // else 1 stop bit
1149 if ((info & 2) && (!(info & 1))) // even parity
1151 si2 += 8; // else no parity
1153 return si2;
1157 static u8
1158 DecodeSyncParams(u8 si2, u8 info)
1160 info &= 0x7f;
1161 switch (info) {
1162 case 40: // bit/s negotiation failed ai := 165 not 175!
1164 return si2 + 15;
1165 case 15: // 56000 bit/s failed, ai := 0 not 169 !
1167 return si2 + 9;
1168 case 14: // 48000 bit/s
1170 return si2 + 8;
1171 case 11: // 19200 bit/s
1173 return si2 + 7;
1174 case 9: // 14400 bit/s
1176 return si2 + 6;
1177 case 8: // 9600 bit/s
1179 return si2 + 5;
1180 case 5: // 4800 bit/s
1182 return si2 + 4;
1183 case 3: // 2400 bit/s
1185 return si2 + 3;
1186 case 23: // 75/1200 bit/s
1188 return si2 + 2;
1189 case 24: // 1200/75 bit/s
1191 return si2 + 1;
1192 default: // 1200 bit/s
1194 return si2;
1198 static u8
1199 DecodeSI2(struct sk_buff *skb)
1201 u8 *p; //, *pend=skb->data + skb->len;
1203 if ((p = findie(skb->data, skb->len, 0x7c, 0))) {
1204 switch (p[4] & 0x0f) {
1205 case 0x01:
1206 if (p[1] == 0x04) // sync. Bitratenadaption
1208 return DecodeSyncParams(160, p[5]); // V.110/X.30
1210 else if (p[1] == 0x06) // async. Bitratenadaption
1212 return DecodeASyncParams(192, p); // V.110/X.30
1214 break;
1215 case 0x08: // if (p[5] == 0x02) // sync. Bitratenadaption
1216 if (p[1] > 3)
1217 return DecodeSyncParams(176, p[5]); // V.120
1218 break;
1221 return 0;
1224 #endif
1227 static void
1228 l3dss1_setup_req(struct l3_process *pc, u8 pr,
1229 void *arg)
1231 struct sk_buff *skb;
1232 u8 tmp[128];
1233 u8 *p = tmp;
1234 u8 channel = 0;
1236 u8 send_keypad;
1237 u8 screen = 0x80;
1238 u8 *teln;
1239 u8 *msn;
1240 u8 *sub;
1241 u8 *sp;
1242 int l;
1244 MsgHead(p, pc->callref, MT_SETUP);
1246 teln = pc->para.setup.phone;
1247 #ifndef CONFIG_HISAX_NO_KEYPAD
1248 send_keypad = (strchr(teln,'*') || strchr(teln,'#')) ? 1 : 0;
1249 #else
1250 send_keypad = 0;
1251 #endif
1252 #ifndef CONFIG_HISAX_NO_SENDCOMPLETE
1253 if (!send_keypad)
1254 *p++ = 0xa1; /* complete indicator */
1255 #endif
1257 * Set Bearer Capability, Map info from 1TR6-convention to EDSS1
1259 switch (pc->para.setup.si1) {
1260 case 1: /* Telephony */
1261 *p++ = IE_BEARER;
1262 *p++ = 0x3; /* Length */
1263 *p++ = 0x90; /* Coding Std. CCITT, 3.1 kHz audio */
1264 *p++ = 0x90; /* Circuit-Mode 64kbps */
1265 *p++ = 0xa3; /* A-Law Audio */
1266 break;
1267 case 5: /* Datatransmission 64k, BTX */
1268 case 7: /* Datatransmission 64k */
1269 default:
1270 *p++ = IE_BEARER;
1271 *p++ = 0x2; /* Length */
1272 *p++ = 0x88; /* Coding Std. CCITT, unrestr. dig. Inform. */
1273 *p++ = 0x90; /* Circuit-Mode 64kbps */
1274 break;
1277 if (send_keypad) {
1278 *p++ = IE_KEYPAD;
1279 *p++ = strlen(teln);
1280 while (*teln)
1281 *p++ = (*teln++) & 0x7F;
1285 * What about info2? Mapping to High-Layer-Compatibility?
1287 if ((*teln) && (!send_keypad)) {
1288 /* parse number for special things */
1289 if (!isdigit(*teln)) {
1290 switch (0x5f & *teln) {
1291 case 'C':
1292 channel = 0x08;
1293 case 'P':
1294 channel |= 0x80;
1295 teln++;
1296 if (*teln == '1')
1297 channel |= 0x01;
1298 else
1299 channel |= 0x02;
1300 break;
1301 case 'R':
1302 screen = 0xA0;
1303 break;
1304 case 'D':
1305 screen = 0x80;
1306 break;
1308 default:
1309 if (pc->debug & L3_DEB_WARN)
1310 l3_debug(pc->st, "Wrong MSN Code");
1311 break;
1313 teln++;
1316 if (channel) {
1317 *p++ = IE_CHANNEL_ID;
1318 *p++ = 1;
1319 *p++ = channel;
1321 msn = pc->para.setup.eazmsn;
1322 sub = NULL;
1323 sp = msn;
1324 while (*sp) {
1325 if ('.' == *sp) {
1326 sub = sp;
1327 *sp = 0;
1328 } else
1329 sp++;
1331 if (*msn) {
1332 *p++ = IE_CALLING_PN;
1333 *p++ = strlen(msn) + (screen ? 2 : 1);
1334 /* Classify as AnyPref. */
1335 if (screen) {
1336 *p++ = 0x01; /* Ext = '0'B, Type = '000'B, Plan = '0001'B. */
1337 *p++ = screen;
1338 } else
1339 *p++ = 0x81; /* Ext = '1'B, Type = '000'B, Plan = '0001'B. */
1340 while (*msn)
1341 *p++ = *msn++ & 0x7f;
1343 if (sub) {
1344 *sub++ = '.';
1345 *p++ = IE_CALLING_SUB;
1346 *p++ = strlen(sub) + 2;
1347 *p++ = 0x80; /* NSAP coded */
1348 *p++ = 0x50; /* local IDI format */
1349 while (*sub)
1350 *p++ = *sub++ & 0x7f;
1352 sub = NULL;
1353 sp = teln;
1354 while (*sp) {
1355 if ('.' == *sp) {
1356 sub = sp;
1357 *sp = 0;
1358 } else
1359 sp++;
1362 if (!send_keypad) {
1363 *p++ = IE_CALLED_PN;
1364 *p++ = strlen(teln) + 1;
1365 /* Classify as AnyPref. */
1366 *p++ = 0x81; /* Ext = '1'B, Type = '000'B, Plan = '0001'B. */
1367 while (*teln)
1368 *p++ = *teln++ & 0x7f;
1370 if (sub) {
1371 *sub++ = '.';
1372 *p++ = IE_CALLED_SUB;
1373 *p++ = strlen(sub) + 2;
1374 *p++ = 0x80; /* NSAP coded */
1375 *p++ = 0x50; /* local IDI format */
1376 while (*sub)
1377 *p++ = *sub++ & 0x7f;
1380 #if EXT_BEARER_CAPS
1381 if ((pc->para.setup.si2 >= 160) && (pc->para.setup.si2 <= 175)) { // sync. Bitratenadaption, V.110/X.30
1383 *p++ = IE_LLC;
1384 *p++ = 0x04;
1385 *p++ = 0x88;
1386 *p++ = 0x90;
1387 *p++ = 0x21;
1388 *p++ = EncodeSyncParams(pc->para.setup.si2 - 160, 0x80);
1389 } else if ((pc->para.setup.si2 >= 176) && (pc->para.setup.si2 <= 191)) { // sync. Bitratenadaption, V.120
1391 *p++ = IE_LLC;
1392 *p++ = 0x05;
1393 *p++ = 0x88;
1394 *p++ = 0x90;
1395 *p++ = 0x28;
1396 *p++ = EncodeSyncParams(pc->para.setup.si2 - 176, 0);
1397 *p++ = 0x82;
1398 } else if (pc->para.setup.si2 >= 192) { // async. Bitratenadaption, V.110/X.30
1400 *p++ = IE_LLC;
1401 *p++ = 0x06;
1402 *p++ = 0x88;
1403 *p++ = 0x90;
1404 *p++ = 0x21;
1405 p = EncodeASyncParams(p, pc->para.setup.si2 - 192);
1406 #ifndef CONFIG_HISAX_NO_LLC
1407 } else {
1408 switch (pc->para.setup.si1) {
1409 case 1: /* Telephony */
1410 *p++ = IE_LLC;
1411 *p++ = 0x3; /* Length */
1412 *p++ = 0x90; /* Coding Std. CCITT, 3.1 kHz audio */
1413 *p++ = 0x90; /* Circuit-Mode 64kbps */
1414 *p++ = 0xa3; /* A-Law Audio */
1415 break;
1416 case 5: /* Datatransmission 64k, BTX */
1417 case 7: /* Datatransmission 64k */
1418 default:
1419 *p++ = IE_LLC;
1420 *p++ = 0x2; /* Length */
1421 *p++ = 0x88; /* Coding Std. CCITT, unrestr. dig. Inform. */
1422 *p++ = 0x90; /* Circuit-Mode 64kbps */
1423 break;
1425 #endif
1427 #endif
1428 l = p - tmp;
1429 if (!(skb = l3_alloc_skb(l)))
1430 return;
1431 memcpy(skb_put(skb, l), tmp, l);
1432 L3DelTimer(&pc->timer);
1433 L3AddTimer(&pc->timer, T303, CC_T303);
1434 newl3state(pc, 1);
1435 l3_msg(pc->st, DL_DATA | REQUEST, skb);
1438 static void
1439 l3dss1_call_proc(struct l3_process *pc, u8 pr, void *arg)
1441 struct sk_buff *skb = arg;
1442 int id, ret;
1444 if ((id = l3dss1_get_channel_id(pc, skb)) >= 0) {
1445 if ((0 == id) || ((3 == id) && (0x10 == pc->para.moderate))) {
1446 if (pc->debug & L3_DEB_WARN)
1447 l3_debug(pc->st, "setup answer with wrong chid %x", id);
1448 pc->para.cause = 100;
1449 l3dss1_status_send(pc, pr, NULL);
1450 return;
1452 pc->para.bchannel = id;
1453 } else if (1 == pc->state) {
1454 if (pc->debug & L3_DEB_WARN)
1455 l3_debug(pc->st, "setup answer wrong chid (ret %d)", id);
1456 if (id == -1)
1457 pc->para.cause = 96;
1458 else
1459 pc->para.cause = 100;
1460 l3dss1_status_send(pc, pr, NULL);
1461 return;
1463 /* Now we are on none mandatory IEs */
1464 ret = check_infoelements(pc, skb, ie_CALL_PROCEEDING);
1465 if (ERR_IE_COMPREHENSION == ret) {
1466 l3dss1_std_ie_err(pc, ret);
1467 return;
1469 L3DelTimer(&pc->timer);
1470 newl3state(pc, 3);
1471 L3AddTimer(&pc->timer, T310, CC_T310);
1472 if (ret) /* STATUS for none mandatory IE errors after actions are taken */
1473 l3dss1_std_ie_err(pc, ret);
1474 L3L4(pc->st, CC_PROCEEDING | INDICATION, pc);
1477 static void
1478 l3dss1_setup_ack(struct l3_process *pc, u8 pr, void *arg)
1480 struct sk_buff *skb = arg;
1481 int id, ret;
1483 if ((id = l3dss1_get_channel_id(pc, skb)) >= 0) {
1484 if ((0 == id) || ((3 == id) && (0x10 == pc->para.moderate))) {
1485 if (pc->debug & L3_DEB_WARN)
1486 l3_debug(pc->st, "setup answer with wrong chid %x", id);
1487 pc->para.cause = 100;
1488 l3dss1_status_send(pc, pr, NULL);
1489 return;
1491 pc->para.bchannel = id;
1492 } else {
1493 if (pc->debug & L3_DEB_WARN)
1494 l3_debug(pc->st, "setup answer wrong chid (ret %d)", id);
1495 if (id == -1)
1496 pc->para.cause = 96;
1497 else
1498 pc->para.cause = 100;
1499 l3dss1_status_send(pc, pr, NULL);
1500 return;
1502 /* Now we are on none mandatory IEs */
1503 ret = check_infoelements(pc, skb, ie_SETUP_ACKNOWLEDGE);
1504 if (ERR_IE_COMPREHENSION == ret) {
1505 l3dss1_std_ie_err(pc, ret);
1506 return;
1508 L3DelTimer(&pc->timer);
1509 newl3state(pc, 2);
1510 L3AddTimer(&pc->timer, T304, CC_T304);
1511 if (ret) /* STATUS for none mandatory IE errors after actions are taken */
1512 l3dss1_std_ie_err(pc, ret);
1513 L3L4(pc->st, CC_MORE_INFO | INDICATION, pc);
1516 static void
1517 l3dss1_disconnect(struct l3_process *pc, u8 pr, void *arg)
1519 struct sk_buff *skb = arg;
1520 u8 *p;
1521 int ret;
1522 u8 cause = 0;
1524 StopAllL3Timer(pc);
1525 if ((ret = l3dss1_get_cause(pc, skb))) {
1526 if (pc->debug & L3_DEB_WARN)
1527 l3_debug(pc->st, "DISC get_cause ret(%d)", ret);
1528 if (ret < 0)
1529 cause = 96;
1530 else if (ret > 0)
1531 cause = 100;
1533 if ((p = findie(skb->data, skb->len, IE_FACILITY, 0)))
1534 l3dss1_parse_facility(pc->st, pc, pc->callref, p);
1535 ret = check_infoelements(pc, skb, ie_DISCONNECT);
1536 if (ERR_IE_COMPREHENSION == ret)
1537 cause = 96;
1538 else if ((!cause) && (ERR_IE_UNRECOGNIZED == ret))
1539 cause = 99;
1540 ret = pc->state;
1541 newl3state(pc, 12);
1542 if (cause)
1543 newl3state(pc, 19);
1544 if (11 != ret)
1545 L3L4(pc->st, CC_DISCONNECT | INDICATION, pc);
1546 else if (!cause)
1547 l3dss1_release_req(pc, pr, NULL);
1548 if (cause) {
1549 l3dss1_message_cause(pc, MT_RELEASE, cause);
1550 L3AddTimer(&pc->timer, T308, CC_T308_1);
1554 static void
1555 l3dss1_connect(struct l3_process *pc, u8 pr, void *arg)
1557 struct sk_buff *skb = arg;
1558 int ret;
1560 ret = check_infoelements(pc, skb, ie_CONNECT);
1561 if (ERR_IE_COMPREHENSION == ret) {
1562 l3dss1_std_ie_err(pc, ret);
1563 return;
1565 L3DelTimer(&pc->timer); /* T310 */
1566 newl3state(pc, 10);
1567 pc->para.chargeinfo = 0;
1568 /* here should inserted COLP handling KKe */
1569 if (ret)
1570 l3dss1_std_ie_err(pc, ret);
1571 L3L4(pc->st, CC_SETUP | CONFIRM, pc);
1574 static void
1575 l3dss1_alerting(struct l3_process *pc, u8 pr, void *arg)
1577 struct sk_buff *skb = arg;
1578 int ret;
1580 ret = check_infoelements(pc, skb, ie_ALERTING);
1581 if (ERR_IE_COMPREHENSION == ret) {
1582 l3dss1_std_ie_err(pc, ret);
1583 return;
1585 L3DelTimer(&pc->timer); /* T304 */
1586 newl3state(pc, 4);
1587 if (ret)
1588 l3dss1_std_ie_err(pc, ret);
1589 L3L4(pc->st, CC_ALERTING | INDICATION, pc);
1592 static void
1593 l3dss1_setup(struct l3_process *pc, u8 pr, void *arg)
1595 u8 *p;
1596 int bcfound = 0;
1597 char tmp[80];
1598 struct sk_buff *skb = arg;
1599 int id;
1600 int err = 0;
1603 * Bearer Capabilities
1605 p = skb->data;
1606 /* only the first occurrence 'll be detected ! */
1607 if ((p = findie(p, skb->len, 0x04, 0))) {
1608 if ((p[1] < 2) || (p[1] > 11))
1609 err = 1;
1610 else {
1611 pc->para.setup.si2 = 0;
1612 switch (p[2] & 0x7f) {
1613 case 0x00: /* Speech */
1614 case 0x10: /* 3.1 Khz audio */
1615 pc->para.setup.si1 = 1;
1616 break;
1617 case 0x08: /* Unrestricted digital information */
1618 pc->para.setup.si1 = 7;
1619 /* JIM, 05.11.97 I wanna set service indicator 2 */
1620 #if EXT_BEARER_CAPS
1621 pc->para.setup.si2 = DecodeSI2(skb);
1622 #endif
1623 break;
1624 case 0x09: /* Restricted digital information */
1625 pc->para.setup.si1 = 2;
1626 break;
1627 case 0x11:
1628 /* Unrestr. digital information with
1629 * tones/announcements ( or 7 kHz audio
1631 pc->para.setup.si1 = 3;
1632 break;
1633 case 0x18: /* Video */
1634 pc->para.setup.si1 = 4;
1635 break;
1636 default:
1637 err = 2;
1638 break;
1640 switch (p[3] & 0x7f) {
1641 case 0x40: /* packed mode */
1642 pc->para.setup.si1 = 8;
1643 break;
1644 case 0x10: /* 64 kbit */
1645 case 0x11: /* 2*64 kbit */
1646 case 0x13: /* 384 kbit */
1647 case 0x15: /* 1536 kbit */
1648 case 0x17: /* 1920 kbit */
1649 pc->para.moderate = p[3] & 0x7f;
1650 break;
1651 default:
1652 err = 3;
1653 break;
1656 if (pc->debug & L3_DEB_SI)
1657 l3_debug(pc->st, "SI=%d, AI=%d",
1658 pc->para.setup.si1, pc->para.setup.si2);
1659 if (err) {
1660 if (pc->debug & L3_DEB_WARN)
1661 l3_debug(pc->st, "setup with wrong bearer(l=%d:%x,%x)",
1662 p[1], p[2], p[3]);
1663 pc->para.cause = 100;
1664 l3dss1_msg_without_setup(pc, pr, NULL);
1665 return;
1667 } else {
1668 if (pc->debug & L3_DEB_WARN)
1669 l3_debug(pc->st, "setup without bearer capabilities");
1670 /* ETS 300-104 1.3.3 */
1671 pc->para.cause = 96;
1672 l3dss1_msg_without_setup(pc, pr, NULL);
1673 return;
1676 * Channel Identification
1678 if ((id = l3dss1_get_channel_id(pc, skb)) >= 0) {
1679 if ((pc->para.bchannel = id)) {
1680 if ((3 == id) && (0x10 == pc->para.moderate)) {
1681 if (pc->debug & L3_DEB_WARN)
1682 l3_debug(pc->st, "setup with wrong chid %x",
1683 id);
1684 pc->para.cause = 100;
1685 l3dss1_msg_without_setup(pc, pr, NULL);
1686 return;
1688 bcfound++;
1689 } else
1690 { if (pc->debug & L3_DEB_WARN)
1691 l3_debug(pc->st, "setup without bchannel, call waiting");
1692 bcfound++;
1694 } else {
1695 if (pc->debug & L3_DEB_WARN)
1696 l3_debug(pc->st, "setup with wrong chid ret %d", id);
1697 if (id == -1)
1698 pc->para.cause = 96;
1699 else
1700 pc->para.cause = 100;
1701 l3dss1_msg_without_setup(pc, pr, NULL);
1702 return;
1704 /* Now we are on none mandatory IEs */
1705 err = check_infoelements(pc, skb, ie_SETUP);
1706 if (ERR_IE_COMPREHENSION == err) {
1707 pc->para.cause = 96;
1708 l3dss1_msg_without_setup(pc, pr, NULL);
1709 return;
1711 p = skb->data;
1712 if ((p = findie(p, skb->len, 0x70, 0)))
1713 iecpy(pc->para.setup.eazmsn, p, 1);
1714 else
1715 pc->para.setup.eazmsn[0] = 0;
1717 p = skb->data;
1718 if ((p = findie(p, skb->len, 0x71, 0))) {
1719 /* Called party subaddress */
1720 if ((p[1] >= 2) && (p[2] == 0x80) && (p[3] == 0x50)) {
1721 tmp[0] = '.';
1722 iecpy(&tmp[1], p, 2);
1723 strcat(pc->para.setup.eazmsn, tmp);
1724 } else if (pc->debug & L3_DEB_WARN)
1725 l3_debug(pc->st, "wrong called subaddress");
1727 p = skb->data;
1728 if ((p = findie(p, skb->len, 0x6c, 0))) {
1729 pc->para.setup.plan = p[2];
1730 if (p[2] & 0x80) {
1731 iecpy(pc->para.setup.phone, p, 1);
1732 pc->para.setup.screen = 0;
1733 } else {
1734 iecpy(pc->para.setup.phone, p, 2);
1735 pc->para.setup.screen = p[3];
1737 } else {
1738 pc->para.setup.phone[0] = 0;
1739 pc->para.setup.plan = 0;
1740 pc->para.setup.screen = 0;
1742 p = skb->data;
1743 if ((p = findie(p, skb->len, 0x6d, 0))) {
1744 /* Calling party subaddress */
1745 if ((p[1] >= 2) && (p[2] == 0x80) && (p[3] == 0x50)) {
1746 tmp[0] = '.';
1747 iecpy(&tmp[1], p, 2);
1748 strcat(pc->para.setup.phone, tmp);
1749 } else if (pc->debug & L3_DEB_WARN)
1750 l3_debug(pc->st, "wrong calling subaddress");
1752 newl3state(pc, 6);
1753 if (err) /* STATUS for none mandatory IE errors after actions are taken */
1754 l3dss1_std_ie_err(pc, err);
1755 L3L4(pc->st, CC_SETUP | INDICATION, pc);
1758 static void
1759 l3dss1_reset(struct l3_process *pc, u8 pr, void *arg)
1761 dss1_release_l3_process(pc);
1764 static void
1765 l3dss1_disconnect_req(struct l3_process *pc, u8 pr, void *arg)
1767 struct sk_buff *skb;
1768 u8 tmp[16+40];
1769 u8 *p = tmp;
1770 int l;
1771 u8 cause = 16;
1773 if (pc->para.cause != NO_CAUSE)
1774 cause = pc->para.cause;
1776 StopAllL3Timer(pc);
1778 MsgHead(p, pc->callref, MT_DISCONNECT);
1780 *p++ = IE_CAUSE;
1781 *p++ = 0x2;
1782 *p++ = 0x80;
1783 *p++ = cause | 0x80;
1785 if (pc->prot.dss1.uus1_data[0])
1786 { *p++ = IE_USER_USER; /* UUS info element */
1787 *p++ = strlen(pc->prot.dss1.uus1_data) + 1;
1788 *p++ = 0x04; /* IA5 chars */
1789 strcpy(p,pc->prot.dss1.uus1_data);
1790 p += strlen(pc->prot.dss1.uus1_data);
1791 pc->prot.dss1.uus1_data[0] = '\0';
1794 l = p - tmp;
1795 if (!(skb = l3_alloc_skb(l)))
1796 return;
1797 memcpy(skb_put(skb, l), tmp, l);
1798 newl3state(pc, 11);
1799 l3_msg(pc->st, DL_DATA | REQUEST, skb);
1800 L3AddTimer(&pc->timer, T305, CC_T305);
1803 static void
1804 l3dss1_setup_rsp(struct l3_process *pc, u8 pr,
1805 void *arg)
1807 if (!pc->para.bchannel)
1808 { if (pc->debug & L3_DEB_WARN)
1809 l3_debug(pc->st, "D-chan connect for waiting call");
1810 l3dss1_disconnect_req(pc, pr, arg);
1811 return;
1813 newl3state(pc, 8);
1814 l3dss1_message(pc, MT_CONNECT);
1815 L3DelTimer(&pc->timer);
1816 L3AddTimer(&pc->timer, T313, CC_T313);
1819 static void
1820 l3dss1_connect_ack(struct l3_process *pc, u8 pr, void *arg)
1822 struct sk_buff *skb = arg;
1823 int ret;
1825 ret = check_infoelements(pc, skb, ie_CONNECT_ACKNOWLEDGE);
1826 if (ERR_IE_COMPREHENSION == ret) {
1827 l3dss1_std_ie_err(pc, ret);
1828 return;
1830 newl3state(pc, 10);
1831 L3DelTimer(&pc->timer);
1832 if (ret)
1833 l3dss1_std_ie_err(pc, ret);
1834 L3L4(pc->st, CC_SETUP_COMPL | INDICATION, pc);
1837 static void
1838 l3dss1_reject_req(struct l3_process *pc, u8 pr, void *arg)
1840 struct sk_buff *skb;
1841 u8 tmp[16];
1842 u8 *p = tmp;
1843 int l;
1844 u8 cause = 21;
1846 if (pc->para.cause != NO_CAUSE)
1847 cause = pc->para.cause;
1849 MsgHead(p, pc->callref, MT_RELEASE_COMPLETE);
1851 *p++ = IE_CAUSE;
1852 *p++ = 0x2;
1853 *p++ = 0x80;
1854 *p++ = cause | 0x80;
1856 l = p - tmp;
1857 if (!(skb = l3_alloc_skb(l)))
1858 return;
1859 memcpy(skb_put(skb, l), tmp, l);
1860 l3_msg(pc->st, DL_DATA | REQUEST, skb);
1861 L3L4(pc->st, CC_RELEASE | INDICATION, pc);
1862 newl3state(pc, 0);
1863 dss1_release_l3_process(pc);
1866 static void
1867 l3dss1_release(struct l3_process *pc, u8 pr, void *arg)
1869 struct sk_buff *skb = arg;
1870 u8 *p;
1871 int ret, cause=0;
1873 StopAllL3Timer(pc);
1874 if ((ret = l3dss1_get_cause(pc, skb))>0) {
1875 if (pc->debug & L3_DEB_WARN)
1876 l3_debug(pc->st, "REL get_cause ret(%d)", ret);
1877 } else if (ret<0)
1878 pc->para.cause = NO_CAUSE;
1879 if ((p = findie(skb->data, skb->len, IE_FACILITY, 0))) {
1880 l3dss1_parse_facility(pc->st, pc, pc->callref, p);
1882 if ((ret<0) && (pc->state != 11))
1883 cause = 96;
1884 else if (ret>0)
1885 cause = 100;
1886 ret = check_infoelements(pc, skb, ie_RELEASE);
1887 if (ERR_IE_COMPREHENSION == ret)
1888 cause = 96;
1889 else if ((ERR_IE_UNRECOGNIZED == ret) && (!cause))
1890 cause = 99;
1891 if (cause)
1892 l3dss1_message_cause(pc, MT_RELEASE_COMPLETE, cause);
1893 else
1894 l3dss1_message(pc, MT_RELEASE_COMPLETE);
1895 L3L4(pc->st, CC_RELEASE | INDICATION, pc);
1896 newl3state(pc, 0);
1897 dss1_release_l3_process(pc);
1900 static void
1901 l3dss1_alert_req(struct l3_process *pc, u8 pr,
1902 void *arg)
1904 newl3state(pc, 7);
1905 if (!pc->prot.dss1.uus1_data[0])
1906 l3dss1_message(pc, MT_ALERTING);
1907 else
1908 l3dss1_msg_with_uus(pc, MT_ALERTING);
1911 static void
1912 l3dss1_proceed_req(struct l3_process *pc, u8 pr,
1913 void *arg)
1915 newl3state(pc, 9);
1916 l3dss1_message(pc, MT_CALL_PROCEEDING);
1917 L3L4(pc->st, CC_PROCEED_SEND | INDICATION, pc);
1920 static void
1921 l3dss1_setup_ack_req(struct l3_process *pc, u8 pr,
1922 void *arg)
1924 newl3state(pc, 25);
1925 L3DelTimer(&pc->timer);
1926 L3AddTimer(&pc->timer, T302, CC_T302);
1927 l3dss1_message(pc, MT_SETUP_ACKNOWLEDGE);
1930 /********************************************/
1931 /* deliver a incoming display message to HL */
1932 /********************************************/
1933 static void
1934 l3dss1_deliver_display(struct l3_process *pc, int pr, u8 *infp)
1935 { u8 len;
1936 isdn_ctrl ic;
1937 struct IsdnCardState *cs;
1938 char *p;
1940 if (*infp++ != IE_DISPLAY) return;
1941 if ((len = *infp++) > 80) return; /* total length <= 82 */
1942 if (!pc->chan) return;
1944 p = ic.parm.display;
1945 while (len--)
1946 *p++ = *infp++;
1947 *p = '\0';
1948 ic.command = ISDN_STAT_DISPLAY;
1949 cs = pc->st->l1.hardware;
1950 ic.driver = cs->myid;
1951 ic.arg = pc->chan->chan;
1952 cs->iif.statcallb(&ic);
1953 } /* l3dss1_deliver_display */
1956 static void
1957 l3dss1_progress(struct l3_process *pc, u8 pr, void *arg)
1959 struct sk_buff *skb = arg;
1960 int err = 0;
1961 u8 *p;
1963 if ((p = findie(skb->data, skb->len, IE_PROGRESS, 0))) {
1964 if (p[1] != 2) {
1965 err = 1;
1966 pc->para.cause = 100;
1967 } else if (!(p[2] & 0x70)) {
1968 switch (p[2]) {
1969 case 0x80:
1970 case 0x81:
1971 case 0x82:
1972 case 0x84:
1973 case 0x85:
1974 case 0x87:
1975 case 0x8a:
1976 switch (p[3]) {
1977 case 0x81:
1978 case 0x82:
1979 case 0x83:
1980 case 0x84:
1981 case 0x88:
1982 break;
1983 default:
1984 err = 2;
1985 pc->para.cause = 100;
1986 break;
1988 break;
1989 default:
1990 err = 3;
1991 pc->para.cause = 100;
1992 break;
1995 } else {
1996 pc->para.cause = 96;
1997 err = 4;
1999 if (err) {
2000 if (pc->debug & L3_DEB_WARN)
2001 l3_debug(pc->st, "progress error %d", err);
2002 l3dss1_status_send(pc, pr, NULL);
2003 return;
2005 /* Now we are on none mandatory IEs */
2006 err = check_infoelements(pc, skb, ie_PROGRESS);
2007 if (err)
2008 l3dss1_std_ie_err(pc, err);
2009 if (ERR_IE_COMPREHENSION != err)
2010 L3L4(pc->st, CC_PROGRESS | INDICATION, pc);
2013 static void
2014 l3dss1_notify(struct l3_process *pc, u8 pr, void *arg)
2016 struct sk_buff *skb = arg;
2017 int err = 0;
2018 u8 *p;
2020 if ((p = findie(skb->data, skb->len, IE_NOTIFY, 0))) {
2021 if (p[1] != 1) {
2022 err = 1;
2023 pc->para.cause = 100;
2024 } else {
2025 switch (p[2]) {
2026 case 0x80:
2027 case 0x81:
2028 case 0x82:
2029 break;
2030 default:
2031 pc->para.cause = 100;
2032 err = 2;
2033 break;
2036 } else {
2037 pc->para.cause = 96;
2038 err = 3;
2040 if (err) {
2041 if (pc->debug & L3_DEB_WARN)
2042 l3_debug(pc->st, "notify error %d", err);
2043 l3dss1_status_send(pc, pr, NULL);
2044 return;
2046 /* Now we are on none mandatory IEs */
2047 err = check_infoelements(pc, skb, ie_NOTIFY);
2048 if (err)
2049 l3dss1_std_ie_err(pc, err);
2050 if (ERR_IE_COMPREHENSION != err)
2051 L3L4(pc->st, CC_NOTIFY | INDICATION, pc);
2054 static void
2055 l3dss1_status_enq(struct l3_process *pc, u8 pr, void *arg)
2057 int ret;
2058 struct sk_buff *skb = arg;
2060 ret = check_infoelements(pc, skb, ie_STATUS_ENQUIRY);
2061 l3dss1_std_ie_err(pc, ret);
2062 pc->para.cause = 30; /* response to STATUS_ENQUIRY */
2063 l3dss1_status_send(pc, pr, NULL);
2066 static void
2067 l3dss1_information(struct l3_process *pc, u8 pr, void *arg)
2069 int ret;
2070 struct sk_buff *skb = arg;
2071 u8 *p;
2072 char tmp[32];
2074 ret = check_infoelements(pc, skb, ie_INFORMATION);
2075 if (ret)
2076 l3dss1_std_ie_err(pc, ret);
2077 if (pc->state == 25) { /* overlap receiving */
2078 L3DelTimer(&pc->timer);
2079 p = skb->data;
2080 if ((p = findie(p, skb->len, 0x70, 0))) {
2081 iecpy(tmp, p, 1);
2082 strcat(pc->para.setup.eazmsn, tmp);
2083 L3L4(pc->st, CC_MORE_INFO | INDICATION, pc);
2085 L3AddTimer(&pc->timer, T302, CC_T302);
2089 /******************************/
2090 /* handle deflection requests */
2091 /******************************/
2092 static void l3dss1_redir_req(struct l3_process *pc, u8 pr, void *arg)
2094 struct sk_buff *skb;
2095 u8 tmp[128];
2096 u8 *p = tmp;
2097 u8 *subp;
2098 u8 len_phone = 0;
2099 u8 len_sub = 0;
2100 int l;
2103 strcpy(pc->prot.dss1.uus1_data,pc->chan->setup.eazmsn); /* copy uus element if available */
2104 if (!pc->chan->setup.phone[0])
2105 { pc->para.cause = -1;
2106 l3dss1_disconnect_req(pc,pr,arg); /* disconnect immediately */
2107 return;
2108 } /* only uus */
2110 if (pc->prot.dss1.invoke_id)
2111 free_invoke_id(pc->st,pc->prot.dss1.invoke_id);
2113 if (!(pc->prot.dss1.invoke_id = new_invoke_id(pc->st)))
2114 return;
2116 MsgHead(p, pc->callref, MT_FACILITY);
2118 for (subp = pc->chan->setup.phone; (*subp) && (*subp != '.'); subp++) len_phone++; /* len of phone number */
2119 if (*subp++ == '.') len_sub = strlen(subp) + 2; /* length including info subaddress element */
2121 *p++ = 0x1c; /* Facility info element */
2122 *p++ = len_phone + len_sub + 2 + 2 + 8 + 3 + 3; /* length of element */
2123 *p++ = 0x91; /* remote operations protocol */
2124 *p++ = 0xa1; /* invoke component */
2126 *p++ = len_phone + len_sub + 2 + 2 + 8 + 3; /* length of data */
2127 *p++ = 0x02; /* invoke id tag, integer */
2128 *p++ = 0x01; /* length */
2129 *p++ = pc->prot.dss1.invoke_id; /* invoke id */
2130 *p++ = 0x02; /* operation value tag, integer */
2131 *p++ = 0x01; /* length */
2132 *p++ = 0x0D; /* Call Deflect */
2134 *p++ = 0x30; /* sequence phone number */
2135 *p++ = len_phone + 2 + 2 + 3 + len_sub; /* length */
2137 *p++ = 0x30; /* Deflected to UserNumber */
2138 *p++ = len_phone+2+len_sub; /* length */
2139 *p++ = 0x80; /* NumberDigits */
2140 *p++ = len_phone; /* length */
2141 for (l = 0; l < len_phone; l++)
2142 *p++ = pc->chan->setup.phone[l];
2144 if (len_sub)
2145 { *p++ = 0x04; /* called party subaddress */
2146 *p++ = len_sub - 2;
2147 while (*subp) *p++ = *subp++;
2150 *p++ = 0x01; /* screening identifier */
2151 *p++ = 0x01;
2152 *p++ = pc->chan->setup.screen;
2154 l = p - tmp;
2155 if (!(skb = l3_alloc_skb(l))) return;
2156 memcpy(skb_put(skb, l), tmp, l);
2158 l3_msg(pc->st, DL_DATA | REQUEST, skb);
2159 } /* l3dss1_redir_req */
2161 /********************************************/
2162 /* handle deflection request in early state */
2163 /********************************************/
2164 static void l3dss1_redir_req_early(struct l3_process *pc, u8 pr, void *arg)
2166 l3dss1_proceed_req(pc,pr,arg);
2167 l3dss1_redir_req(pc,pr,arg);
2168 } /* l3dss1_redir_req_early */
2170 /***********************************************/
2171 /* handle special commands for this protocol. */
2172 /* Examples are call independent services like */
2173 /* remote operations with dummy callref. */
2174 /***********************************************/
2175 static int l3dss1_cmd_global(struct PStack *st, isdn_ctrl *ic)
2176 { u8 id;
2177 u8 temp[265];
2178 u8 *p = temp;
2179 int i, l, proc_len;
2180 struct sk_buff *skb;
2181 struct l3_process *pc = NULL;
2183 switch (ic->arg)
2184 { case DSS1_CMD_INVOKE:
2185 if (ic->parm.dss1_io.datalen < 0) return(-2); /* invalid parameter */
2187 for (proc_len = 1, i = ic->parm.dss1_io.proc >> 8; i; i++)
2188 i = i >> 8; /* add one byte */
2189 l = ic->parm.dss1_io.datalen + proc_len + 8; /* length excluding ie header */
2190 if (l > 255)
2191 return(-2); /* too long */
2193 if (!(id = new_invoke_id(st)))
2194 return(0); /* first get a invoke id -> return if no available */
2196 i = -1;
2197 MsgHead(p, i, MT_FACILITY); /* build message head */
2198 *p++ = 0x1C; /* Facility IE */
2199 *p++ = l; /* length of ie */
2200 *p++ = 0x91; /* remote operations */
2201 *p++ = 0xA1; /* invoke */
2202 *p++ = l - 3; /* length of invoke */
2203 *p++ = 0x02; /* invoke id tag */
2204 *p++ = 0x01; /* length is 1 */
2205 *p++ = id; /* invoke id */
2206 *p++ = 0x02; /* operation */
2207 *p++ = proc_len; /* length of operation */
2209 for (i = proc_len; i; i--)
2210 *p++ = (ic->parm.dss1_io.proc >> (i-1)) & 0xFF;
2211 memcpy(p, ic->parm.dss1_io.data, ic->parm.dss1_io.datalen); /* copy data */
2212 l = (p - temp) + ic->parm.dss1_io.datalen; /* total length */
2214 if (ic->parm.dss1_io.timeout > 0)
2215 if (!(pc = dss1_new_l3_process(st, -1)))
2216 { free_invoke_id(st, id);
2217 return(-2);
2219 pc->prot.dss1.ll_id = ic->parm.dss1_io.ll_id; /* remember id */
2220 pc->prot.dss1.proc = ic->parm.dss1_io.proc; /* and procedure */
2222 if (!(skb = l3_alloc_skb(l)))
2223 { free_invoke_id(st, id);
2224 if (pc) dss1_release_l3_process(pc);
2225 return(-2);
2227 memcpy(skb_put(skb, l), temp, l);
2229 if (pc)
2230 { pc->prot.dss1.invoke_id = id; /* remember id */
2231 L3AddTimer(&pc->timer, ic->parm.dss1_io.timeout, CC_TDSS1_IO | REQUEST);
2234 l3_msg(st, DL_DATA | REQUEST, skb);
2235 ic->parm.dss1_io.hl_id = id; /* return id */
2236 return(0);
2238 case DSS1_CMD_INVOKE_ABORT:
2239 if ((pc = l3dss1_search_dummy_proc(st, ic->parm.dss1_io.hl_id)))
2240 { L3DelTimer(&pc->timer); /* remove timer */
2241 dss1_release_l3_process(pc);
2242 return(0);
2244 else
2245 { l3_debug(st, "l3dss1_cmd_global abort unknown id");
2246 return(-2);
2248 break;
2250 default:
2251 l3_debug(st, "l3dss1_cmd_global unknown cmd 0x%lx", ic->arg);
2252 return(-1);
2253 } /* switch ic-> arg */
2254 return(-1);
2255 } /* l3dss1_cmd_global */
2257 static void
2258 l3dss1_io_timer(struct l3_process *pc)
2259 { isdn_ctrl ic;
2260 struct IsdnCardState *cs = pc->st->l1.hardware;
2262 L3DelTimer(&pc->timer); /* remove timer */
2264 ic.driver = cs->myid;
2265 ic.command = ISDN_STAT_PROT;
2266 ic.arg = DSS1_STAT_INVOKE_ERR;
2267 ic.parm.dss1_io.hl_id = pc->prot.dss1.invoke_id;
2268 ic.parm.dss1_io.ll_id = pc->prot.dss1.ll_id;
2269 ic.parm.dss1_io.proc = pc->prot.dss1.proc;
2270 ic.parm.dss1_io.timeout= -1;
2271 ic.parm.dss1_io.datalen = 0;
2272 ic.parm.dss1_io.data = NULL;
2273 free_invoke_id(pc->st, pc->prot.dss1.invoke_id);
2274 pc->prot.dss1.invoke_id = 0; /* reset id */
2276 cs->iif.statcallb(&ic);
2278 dss1_release_l3_process(pc);
2279 } /* l3dss1_io_timer */
2281 static void
2282 l3dss1_release_ind(struct l3_process *pc, u8 pr, void *arg)
2284 u8 *p;
2285 struct sk_buff *skb = arg;
2286 int callState = 0;
2287 p = skb->data;
2289 if ((p = findie(p, skb->len, IE_CALL_STATE, 0))) {
2290 p++;
2291 if (1 == *p++)
2292 callState = *p;
2294 if (callState == 0) {
2295 /* ETS 300-104 7.6.1, 8.6.1, 10.6.1... and 16.1
2296 * set down layer 3 without sending any message
2298 L3L4(pc->st, CC_RELEASE | INDICATION, pc);
2299 newl3state(pc, 0);
2300 dss1_release_l3_process(pc);
2301 } else {
2302 L3L4(pc->st, CC_IGNORE | INDICATION, pc);
2306 static void
2307 l3dss1_dummy(struct l3_process *pc, u8 pr, void *arg)
2311 static void
2312 l3dss1_t302(struct l3_process *pc, u8 pr, void *arg)
2314 L3DelTimer(&pc->timer);
2315 pc->para.loc = 0;
2316 pc->para.cause = 28; /* invalid number */
2317 l3dss1_disconnect_req(pc, pr, NULL);
2318 L3L4(pc->st, CC_SETUP_ERR, pc);
2321 static void
2322 l3dss1_t303(struct l3_process *pc, u8 pr, void *arg)
2324 if (pc->N303 > 0) {
2325 pc->N303--;
2326 L3DelTimer(&pc->timer);
2327 l3dss1_setup_req(pc, pr, arg);
2328 } else {
2329 L3DelTimer(&pc->timer);
2330 l3dss1_message_cause(pc, MT_RELEASE_COMPLETE, 102);
2331 L3L4(pc->st, CC_NOSETUP_RSP, pc);
2332 dss1_release_l3_process(pc);
2336 static void
2337 l3dss1_t304(struct l3_process *pc, u8 pr, void *arg)
2339 L3DelTimer(&pc->timer);
2340 pc->para.loc = 0;
2341 pc->para.cause = 102;
2342 l3dss1_disconnect_req(pc, pr, NULL);
2343 L3L4(pc->st, CC_SETUP_ERR, pc);
2347 static void
2348 l3dss1_t305(struct l3_process *pc, u8 pr, void *arg)
2350 u8 tmp[16];
2351 u8 *p = tmp;
2352 int l;
2353 struct sk_buff *skb;
2354 u8 cause = 16;
2356 L3DelTimer(&pc->timer);
2357 if (pc->para.cause != NO_CAUSE)
2358 cause = pc->para.cause;
2360 MsgHead(p, pc->callref, MT_RELEASE);
2362 *p++ = IE_CAUSE;
2363 *p++ = 0x2;
2364 *p++ = 0x80;
2365 *p++ = cause | 0x80;
2367 l = p - tmp;
2368 if (!(skb = l3_alloc_skb(l)))
2369 return;
2370 memcpy(skb_put(skb, l), tmp, l);
2371 newl3state(pc, 19);
2372 l3_msg(pc->st, DL_DATA | REQUEST, skb);
2373 L3AddTimer(&pc->timer, T308, CC_T308_1);
2376 static void
2377 l3dss1_t310(struct l3_process *pc, u8 pr, void *arg)
2379 L3DelTimer(&pc->timer);
2380 pc->para.loc = 0;
2381 pc->para.cause = 102;
2382 l3dss1_disconnect_req(pc, pr, NULL);
2383 L3L4(pc->st, CC_SETUP_ERR, pc);
2386 static void
2387 l3dss1_t313(struct l3_process *pc, u8 pr, void *arg)
2389 L3DelTimer(&pc->timer);
2390 pc->para.loc = 0;
2391 pc->para.cause = 102;
2392 l3dss1_disconnect_req(pc, pr, NULL);
2393 L3L4(pc->st, CC_CONNECT_ERR, pc);
2396 static void
2397 l3dss1_t308_1(struct l3_process *pc, u8 pr, void *arg)
2399 newl3state(pc, 19);
2400 L3DelTimer(&pc->timer);
2401 l3dss1_message(pc, MT_RELEASE);
2402 L3AddTimer(&pc->timer, T308, CC_T308_2);
2405 static void
2406 l3dss1_t308_2(struct l3_process *pc, u8 pr, void *arg)
2408 L3DelTimer(&pc->timer);
2409 L3L4(pc->st, CC_RELEASE_ERR, pc);
2410 dss1_release_l3_process(pc);
2413 static void
2414 l3dss1_t318(struct l3_process *pc, u8 pr, void *arg)
2416 L3DelTimer(&pc->timer);
2417 pc->para.cause = 102; /* Timer expiry */
2418 pc->para.loc = 0; /* local */
2419 L3L4(pc->st, CC_RESUME_ERR, pc);
2420 newl3state(pc, 19);
2421 l3dss1_message(pc, MT_RELEASE);
2422 L3AddTimer(&pc->timer, T308, CC_T308_1);
2425 static void
2426 l3dss1_t319(struct l3_process *pc, u8 pr, void *arg)
2428 L3DelTimer(&pc->timer);
2429 pc->para.cause = 102; /* Timer expiry */
2430 pc->para.loc = 0; /* local */
2431 L3L4(pc->st, CC_SUSPEND_ERR, pc);
2432 newl3state(pc, 10);
2435 static void
2436 l3dss1_restart(struct l3_process *pc, u8 pr, void *arg)
2438 L3DelTimer(&pc->timer);
2439 L3L4(pc->st, CC_RELEASE | INDICATION, pc);
2440 dss1_release_l3_process(pc);
2443 static void
2444 l3dss1_status(struct l3_process *pc, u8 pr, void *arg)
2446 u8 *p;
2447 struct sk_buff *skb = arg;
2448 int ret;
2449 u8 cause = 0, callState = 0;
2451 if ((ret = l3dss1_get_cause(pc, skb))) {
2452 if (pc->debug & L3_DEB_WARN)
2453 l3_debug(pc->st, "STATUS get_cause ret(%d)",ret);
2454 if (ret < 0)
2455 cause = 96;
2456 else if (ret > 0)
2457 cause = 100;
2459 if ((p = findie(skb->data, skb->len, IE_CALL_STATE, 0))) {
2460 p++;
2461 if (1 == *p++) {
2462 callState = *p;
2463 if (!ie_in_set(pc, *p, l3_valid_states))
2464 cause = 100;
2465 } else
2466 cause = 100;
2467 } else
2468 cause = 96;
2469 if (!cause) { /* no error before */
2470 ret = check_infoelements(pc, skb, ie_STATUS);
2471 if (ERR_IE_COMPREHENSION == ret)
2472 cause = 96;
2473 else if (ERR_IE_UNRECOGNIZED == ret)
2474 cause = 99;
2476 if (cause) {
2477 u8 tmp;
2479 if (pc->debug & L3_DEB_WARN)
2480 l3_debug(pc->st, "STATUS error(%d/%d)",ret,cause);
2481 tmp = pc->para.cause;
2482 pc->para.cause = cause;
2483 l3dss1_status_send(pc, 0, NULL);
2484 if (cause == 99)
2485 pc->para.cause = tmp;
2486 else
2487 return;
2489 cause = pc->para.cause;
2490 if (((cause & 0x7f) == 111) && (callState == 0)) {
2491 /* ETS 300-104 7.6.1, 8.6.1, 10.6.1...
2492 * if received MT_STATUS with cause == 111 and call
2493 * state == 0, then we must set down layer 3
2495 L3L4(pc->st, CC_RELEASE | INDICATION, pc);
2496 newl3state(pc, 0);
2497 dss1_release_l3_process(pc);
2501 static void
2502 l3dss1_facility(struct l3_process *pc, u8 pr, void *arg)
2504 struct sk_buff *skb = arg;
2505 int ret;
2507 ret = check_infoelements(pc, skb, ie_FACILITY);
2508 l3dss1_std_ie_err(pc, ret);
2510 u8 *p;
2511 if ((p = findie(skb->data, skb->len, IE_FACILITY, 0)))
2512 l3dss1_parse_facility(pc->st, pc, pc->callref, p);
2516 static void
2517 l3dss1_suspend_req(struct l3_process *pc, u8 pr, void *arg)
2519 struct sk_buff *skb;
2520 u8 tmp[32];
2521 u8 *p = tmp;
2522 u8 i, l;
2523 u8 *msg = pc->chan->setup.phone;
2525 MsgHead(p, pc->callref, MT_SUSPEND);
2526 l = *msg++;
2527 if (l && (l <= 10)) { /* Max length 10 octets */
2528 *p++ = IE_CALL_ID;
2529 *p++ = l;
2530 for (i = 0; i < l; i++)
2531 *p++ = *msg++;
2532 } else if (l) {
2533 l3_debug(pc->st, "SUS wrong CALL_ID len %d", l);
2534 return;
2536 l = p - tmp;
2537 if (!(skb = l3_alloc_skb(l)))
2538 return;
2539 memcpy(skb_put(skb, l), tmp, l);
2540 l3_msg(pc->st, DL_DATA | REQUEST, skb);
2541 newl3state(pc, 15);
2542 L3AddTimer(&pc->timer, T319, CC_T319);
2545 static void
2546 l3dss1_suspend_ack(struct l3_process *pc, u8 pr, void *arg)
2548 struct sk_buff *skb = arg;
2549 int ret;
2551 L3DelTimer(&pc->timer);
2552 newl3state(pc, 0);
2553 pc->para.cause = NO_CAUSE;
2554 L3L4(pc->st, CC_SUSPEND | CONFIRM, pc);
2555 /* We don't handle suspend_ack for IE errors now */
2556 if ((ret = check_infoelements(pc, skb, ie_SUSPEND_ACKNOWLEDGE)))
2557 if (pc->debug & L3_DEB_WARN)
2558 l3_debug(pc->st, "SUSPACK check ie(%d)",ret);
2559 dss1_release_l3_process(pc);
2562 static void
2563 l3dss1_suspend_rej(struct l3_process *pc, u8 pr, void *arg)
2565 struct sk_buff *skb = arg;
2566 int ret;
2568 if ((ret = l3dss1_get_cause(pc, skb))) {
2569 if (pc->debug & L3_DEB_WARN)
2570 l3_debug(pc->st, "SUSP_REJ get_cause ret(%d)",ret);
2571 if (ret < 0)
2572 pc->para.cause = 96;
2573 else
2574 pc->para.cause = 100;
2575 l3dss1_status_send(pc, pr, NULL);
2576 return;
2578 ret = check_infoelements(pc, skb, ie_SUSPEND_REJECT);
2579 if (ERR_IE_COMPREHENSION == ret) {
2580 l3dss1_std_ie_err(pc, ret);
2581 return;
2583 L3DelTimer(&pc->timer);
2584 L3L4(pc->st, CC_SUSPEND_ERR, pc);
2585 newl3state(pc, 10);
2586 if (ret) /* STATUS for none mandatory IE errors after actions are taken */
2587 l3dss1_std_ie_err(pc, ret);
2590 static void
2591 l3dss1_resume_req(struct l3_process *pc, u8 pr, void *arg)
2593 struct sk_buff *skb;
2594 u8 tmp[32];
2595 u8 *p = tmp;
2596 u8 i, l;
2597 u8 *msg = pc->para.setup.phone;
2599 MsgHead(p, pc->callref, MT_RESUME);
2601 l = *msg++;
2602 if (l && (l <= 10)) { /* Max length 10 octets */
2603 *p++ = IE_CALL_ID;
2604 *p++ = l;
2605 for (i = 0; i < l; i++)
2606 *p++ = *msg++;
2607 } else if (l) {
2608 l3_debug(pc->st, "RES wrong CALL_ID len %d", l);
2609 return;
2611 l = p - tmp;
2612 if (!(skb = l3_alloc_skb(l)))
2613 return;
2614 memcpy(skb_put(skb, l), tmp, l);
2615 l3_msg(pc->st, DL_DATA | REQUEST, skb);
2616 newl3state(pc, 17);
2617 L3AddTimer(&pc->timer, T318, CC_T318);
2620 static void
2621 l3dss1_resume_ack(struct l3_process *pc, u8 pr, void *arg)
2623 struct sk_buff *skb = arg;
2624 int id, ret;
2626 if ((id = l3dss1_get_channel_id(pc, skb)) > 0) {
2627 if ((0 == id) || ((3 == id) && (0x10 == pc->para.moderate))) {
2628 if (pc->debug & L3_DEB_WARN)
2629 l3_debug(pc->st, "resume ack with wrong chid %x", id);
2630 pc->para.cause = 100;
2631 l3dss1_status_send(pc, pr, NULL);
2632 return;
2634 pc->para.bchannel = id;
2635 } else if (1 == pc->state) {
2636 if (pc->debug & L3_DEB_WARN)
2637 l3_debug(pc->st, "resume ack without chid (ret %d)", id);
2638 pc->para.cause = 96;
2639 l3dss1_status_send(pc, pr, NULL);
2640 return;
2642 ret = check_infoelements(pc, skb, ie_RESUME_ACKNOWLEDGE);
2643 if (ERR_IE_COMPREHENSION == ret) {
2644 l3dss1_std_ie_err(pc, ret);
2645 return;
2647 L3DelTimer(&pc->timer);
2648 L3L4(pc->st, CC_RESUME | CONFIRM, pc);
2649 newl3state(pc, 10);
2650 if (ret) /* STATUS for none mandatory IE errors after actions are taken */
2651 l3dss1_std_ie_err(pc, ret);
2654 static void
2655 l3dss1_resume_rej(struct l3_process *pc, u8 pr, void *arg)
2657 struct sk_buff *skb = arg;
2658 int ret;
2660 if ((ret = l3dss1_get_cause(pc, skb))) {
2661 if (pc->debug & L3_DEB_WARN)
2662 l3_debug(pc->st, "RES_REJ get_cause ret(%d)",ret);
2663 if (ret < 0)
2664 pc->para.cause = 96;
2665 else
2666 pc->para.cause = 100;
2667 l3dss1_status_send(pc, pr, NULL);
2668 return;
2670 ret = check_infoelements(pc, skb, ie_RESUME_REJECT);
2671 if (ERR_IE_COMPREHENSION == ret) {
2672 l3dss1_std_ie_err(pc, ret);
2673 return;
2675 L3DelTimer(&pc->timer);
2676 L3L4(pc->st, CC_RESUME_ERR, pc);
2677 newl3state(pc, 0);
2678 if (ret) /* STATUS for none mandatory IE errors after actions are taken */
2679 l3dss1_std_ie_err(pc, ret);
2680 dss1_release_l3_process(pc);
2683 static void
2684 l3dss1_global_restart(struct l3_process *pc, u8 pr, void *arg)
2686 u8 tmp[32];
2687 u8 *p;
2688 u8 ri, ch = 0, chan = 0;
2689 int l;
2690 struct sk_buff *skb = arg;
2691 struct l3_process *up;
2693 newl3state(pc, 2);
2694 L3DelTimer(&pc->timer);
2695 p = skb->data;
2696 if ((p = findie(p, skb->len, IE_RESTART_IND, 0))) {
2697 ri = p[2];
2698 l3_debug(pc->st, "Restart %x", ri);
2699 } else {
2700 l3_debug(pc->st, "Restart without restart IE");
2701 ri = 0x86;
2703 p = skb->data;
2704 if ((p = findie(p, skb->len, IE_CHANNEL_ID, 0))) {
2705 chan = p[2] & 3;
2706 ch = p[2];
2707 if (pc->st->l3.debug)
2708 l3_debug(pc->st, "Restart for channel %d", chan);
2710 newl3state(pc, 2);
2711 up = pc->st->l3.proc;
2712 while (up) {
2713 if ((ri & 7) == 7)
2714 L4L3(up->st, CC_RESTART | REQUEST, up);
2715 else if (up->para.bchannel == chan)
2716 L4L3(up->st, CC_RESTART | REQUEST, up);
2717 up = up->next;
2719 p = tmp;
2720 MsgHead(p, pc->callref, MT_RESTART_ACKNOWLEDGE);
2721 if (chan) {
2722 *p++ = IE_CHANNEL_ID;
2723 *p++ = 1;
2724 *p++ = ch | 0x80;
2726 *p++ = 0x79; /* RESTART Ind */
2727 *p++ = 1;
2728 *p++ = ri;
2729 l = p - tmp;
2730 if (!(skb = l3_alloc_skb(l)))
2731 return;
2732 memcpy(skb_put(skb, l), tmp, l);
2733 newl3state(pc, 0);
2734 l3_msg(pc->st, DL_DATA | REQUEST, skb);
2737 static void
2738 l3dss1_dl_reset(struct l3_process *pc, u8 pr, void *arg)
2740 pc->para.cause = 0x29; /* Temporary failure */
2741 pc->para.loc = 0;
2742 l3dss1_disconnect_req(pc, pr, NULL);
2743 L3L4(pc->st, CC_SETUP_ERR, pc);
2746 static void
2747 l3dss1_dl_release(struct l3_process *pc, u8 pr, void *arg)
2749 newl3state(pc, 0);
2750 pc->para.cause = 0x1b; /* Destination out of order */
2751 pc->para.loc = 0;
2752 L3L4(pc->st, CC_RELEASE | INDICATION, pc);
2753 release_l3_process(pc);
2756 static void
2757 l3dss1_dl_reestablish(struct l3_process *pc, u8 pr, void *arg)
2759 L3DelTimer(&pc->timer);
2760 L3AddTimer(&pc->timer, T309, CC_T309);
2761 l3_msg(pc->st, DL_ESTABLISH | REQUEST, NULL);
2764 static void
2765 l3dss1_dl_reest_status(struct l3_process *pc, u8 pr, void *arg)
2767 L3DelTimer(&pc->timer);
2769 pc->para.cause = 0x1F; /* normal, unspecified */
2770 l3dss1_status_send(pc, 0, NULL);
2773 /* *INDENT-OFF* */
2774 static struct stateentry downstatelist[] =
2776 {SBIT(0),
2777 CC_SETUP | REQUEST, l3dss1_setup_req},
2778 {SBIT(0),
2779 CC_RESUME | REQUEST, l3dss1_resume_req},
2780 {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(6) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | SBIT(25),
2781 CC_DISCONNECT | REQUEST, l3dss1_disconnect_req},
2782 {SBIT(12),
2783 CC_RELEASE | REQUEST, l3dss1_release_req},
2784 {ALL_STATES,
2785 CC_RESTART | REQUEST, l3dss1_restart},
2786 {SBIT(6) | SBIT(25),
2787 CC_IGNORE | REQUEST, l3dss1_reset},
2788 {SBIT(6) | SBIT(25),
2789 CC_REJECT | REQUEST, l3dss1_reject_req},
2790 {SBIT(6) | SBIT(25),
2791 CC_PROCEED_SEND | REQUEST, l3dss1_proceed_req},
2792 {SBIT(6),
2793 CC_MORE_INFO | REQUEST, l3dss1_setup_ack_req},
2794 {SBIT(25),
2795 CC_MORE_INFO | REQUEST, l3dss1_dummy},
2796 {SBIT(6) | SBIT(9) | SBIT(25),
2797 CC_ALERTING | REQUEST, l3dss1_alert_req},
2798 {SBIT(6) | SBIT(7) | SBIT(9) | SBIT(25),
2799 CC_SETUP | RESPONSE, l3dss1_setup_rsp},
2800 {SBIT(10),
2801 CC_SUSPEND | REQUEST, l3dss1_suspend_req},
2802 {SBIT(7) | SBIT(9) | SBIT(25),
2803 CC_REDIR | REQUEST, l3dss1_redir_req},
2804 {SBIT(6),
2805 CC_REDIR | REQUEST, l3dss1_redir_req_early},
2806 {SBIT(9) | SBIT(25),
2807 CC_DISCONNECT | REQUEST, l3dss1_disconnect_req},
2808 {SBIT(25),
2809 CC_T302, l3dss1_t302},
2810 {SBIT(1),
2811 CC_T303, l3dss1_t303},
2812 {SBIT(2),
2813 CC_T304, l3dss1_t304},
2814 {SBIT(3),
2815 CC_T310, l3dss1_t310},
2816 {SBIT(8),
2817 CC_T313, l3dss1_t313},
2818 {SBIT(11),
2819 CC_T305, l3dss1_t305},
2820 {SBIT(15),
2821 CC_T319, l3dss1_t319},
2822 {SBIT(17),
2823 CC_T318, l3dss1_t318},
2824 {SBIT(19),
2825 CC_T308_1, l3dss1_t308_1},
2826 {SBIT(19),
2827 CC_T308_2, l3dss1_t308_2},
2828 {SBIT(10),
2829 CC_T309, l3dss1_dl_release},
2832 #define DOWNSLLEN \
2833 (sizeof(downstatelist) / sizeof(struct stateentry))
2835 static struct stateentry datastatelist[] =
2837 {ALL_STATES,
2838 MT_STATUS_ENQUIRY, l3dss1_status_enq},
2839 {ALL_STATES,
2840 MT_FACILITY, l3dss1_facility},
2841 {SBIT(19),
2842 MT_STATUS, l3dss1_release_ind},
2843 {ALL_STATES,
2844 MT_STATUS, l3dss1_status},
2845 {SBIT(0),
2846 MT_SETUP, l3dss1_setup},
2847 {SBIT(6) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | SBIT(11) | SBIT(12) |
2848 SBIT(15) | SBIT(17) | SBIT(19) | SBIT(25),
2849 MT_SETUP, l3dss1_dummy},
2850 {SBIT(1) | SBIT(2),
2851 MT_CALL_PROCEEDING, l3dss1_call_proc},
2852 {SBIT(1),
2853 MT_SETUP_ACKNOWLEDGE, l3dss1_setup_ack},
2854 {SBIT(2) | SBIT(3),
2855 MT_ALERTING, l3dss1_alerting},
2856 {SBIT(2) | SBIT(3),
2857 MT_PROGRESS, l3dss1_progress},
2858 {SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) |
2859 SBIT(11) | SBIT(12) | SBIT(15) | SBIT(17) | SBIT(19) | SBIT(25),
2860 MT_INFORMATION, l3dss1_information},
2861 {SBIT(10) | SBIT(11) | SBIT(15),
2862 MT_NOTIFY, l3dss1_notify},
2863 {SBIT(0) | SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(10) |
2864 SBIT(11) | SBIT(12) | SBIT(15) | SBIT(17) | SBIT(19) | SBIT(25),
2865 MT_RELEASE_COMPLETE, l3dss1_release_cmpl},
2866 {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),
2867 MT_RELEASE, l3dss1_release},
2868 {SBIT(19), MT_RELEASE, l3dss1_release_ind},
2869 {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | SBIT(11) | SBIT(15) | SBIT(17) | SBIT(25),
2870 MT_DISCONNECT, l3dss1_disconnect},
2871 {SBIT(19),
2872 MT_DISCONNECT, l3dss1_dummy},
2873 {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4),
2874 MT_CONNECT, l3dss1_connect},
2875 {SBIT(8),
2876 MT_CONNECT_ACKNOWLEDGE, l3dss1_connect_ack},
2877 {SBIT(15),
2878 MT_SUSPEND_ACKNOWLEDGE, l3dss1_suspend_ack},
2879 {SBIT(15),
2880 MT_SUSPEND_REJECT, l3dss1_suspend_rej},
2881 {SBIT(17),
2882 MT_RESUME_ACKNOWLEDGE, l3dss1_resume_ack},
2883 {SBIT(17),
2884 MT_RESUME_REJECT, l3dss1_resume_rej},
2887 #define DATASLLEN \
2888 (sizeof(datastatelist) / sizeof(struct stateentry))
2890 static struct stateentry globalmes_list[] =
2892 {ALL_STATES,
2893 MT_STATUS, l3dss1_status},
2894 {SBIT(0),
2895 MT_RESTART, l3dss1_global_restart},
2896 /* {SBIT(1),
2897 MT_RESTART_ACKNOWLEDGE, l3dss1_restart_ack},
2900 #define GLOBALM_LEN \
2901 (sizeof(globalmes_list) / sizeof(struct stateentry))
2903 static struct stateentry manstatelist[] =
2905 {SBIT(2),
2906 DL_ESTABLISH | INDICATION, l3dss1_dl_reset},
2907 {SBIT(10),
2908 DL_ESTABLISH | CONFIRM, l3dss1_dl_reest_status},
2909 {SBIT(10),
2910 DL_RELEASE | INDICATION, l3dss1_dl_reestablish},
2911 {ALL_STATES,
2912 DL_RELEASE | INDICATION, l3dss1_dl_release},
2915 #define MANSLLEN \
2916 (sizeof(manstatelist) / sizeof(struct stateentry))
2917 /* *INDENT-ON* */
2920 static void
2921 global_handler(struct PStack *st, int mt, struct sk_buff *skb)
2923 u8 tmp[16];
2924 u8 *p = tmp;
2925 int l;
2926 int i;
2927 struct l3_process *proc = st->l3.global;
2929 proc->callref = skb->data[2]; /* cr flag */
2930 for (i = 0; i < GLOBALM_LEN; i++)
2931 if ((mt == globalmes_list[i].primitive) &&
2932 ((1 << proc->state) & globalmes_list[i].state))
2933 break;
2934 if (i == GLOBALM_LEN) {
2935 if (st->l3.debug & L3_DEB_STATE) {
2936 l3_debug(st, "dss1 global state %d mt %x unhandled",
2937 proc->state, mt);
2939 MsgHead(p, proc->callref, MT_STATUS);
2940 *p++ = IE_CAUSE;
2941 *p++ = 0x2;
2942 *p++ = 0x80;
2943 *p++ = 81 |0x80; /* invalid cr */
2944 *p++ = 0x14; /* CallState */
2945 *p++ = 0x1;
2946 *p++ = proc->state & 0x3f;
2947 l = p - tmp;
2948 if (!(skb = l3_alloc_skb(l)))
2949 return;
2950 memcpy(skb_put(skb, l), tmp, l);
2951 l3_msg(proc->st, DL_DATA | REQUEST, skb);
2952 } else {
2953 if (st->l3.debug & L3_DEB_STATE) {
2954 l3_debug(st, "dss1 global %d mt %x",
2955 proc->state, mt);
2957 globalmes_list[i].rout(proc, mt, skb);
2961 static void
2962 dss1up(struct PStack *st, int pr, void *arg)
2964 int i, mt, cr, cause, callState;
2965 char *ptr;
2966 u8 *p;
2967 struct sk_buff *skb = arg;
2968 struct l3_process *proc;
2970 switch (pr) {
2971 case (DL_DATA | INDICATION):
2972 case (DL_UNIT_DATA | INDICATION):
2973 break;
2974 case (DL_ESTABLISH | CONFIRM):
2975 case (DL_ESTABLISH | INDICATION):
2976 case (DL_RELEASE | INDICATION):
2977 case (DL_RELEASE | CONFIRM):
2978 l3_msg(st, pr, arg);
2979 return;
2980 break;
2981 default:
2982 printk(KERN_ERR "HiSax dss1up unknown pr=%04x\n", pr);
2983 return;
2985 if (skb->len < 3) {
2986 l3_debug(st, "dss1up frame too short(%d)", skb->len);
2987 dev_kfree_skb(skb);
2988 return;
2991 if (skb->data[0] != PROTO_DIS_EURO) {
2992 if (st->l3.debug & L3_DEB_PROTERR) {
2993 l3_debug(st, "dss1up%sunexpected discriminator %x message len %d",
2994 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
2995 skb->data[0], skb->len);
2997 dev_kfree_skb(skb);
2998 return;
3000 cr = getcallref(skb->data);
3001 if (skb->len < ((skb->data[1] & 0x0f) + 3)) {
3002 l3_debug(st, "dss1up frame too short(%d)", skb->len);
3003 dev_kfree_skb(skb);
3004 return;
3006 mt = skb->data[skb->data[1] + 2];
3007 if (st->l3.debug & L3_DEB_STATE)
3008 l3_debug(st, "dss1up cr %d", cr);
3009 if (cr == -2) { /* wrong Callref */
3010 if (st->l3.debug & L3_DEB_WARN)
3011 l3_debug(st, "dss1up wrong Callref");
3012 dev_kfree_skb(skb);
3013 return;
3014 } else if (cr == -1) { /* Dummy Callref */
3015 if (mt == MT_FACILITY)
3016 if ((p = findie(skb->data, skb->len, IE_FACILITY, 0))) {
3017 l3dss1_parse_facility(st, NULL,
3018 (pr == (DL_DATA | INDICATION)) ? -1 : -2, p);
3019 dev_kfree_skb(skb);
3020 return;
3022 if (st->l3.debug & L3_DEB_WARN)
3023 l3_debug(st, "dss1up dummy Callref (no facility msg or ie)");
3024 dev_kfree_skb(skb);
3025 return;
3026 } else if ((((skb->data[1] & 0x0f) == 1) && (0==(cr & 0x7f))) ||
3027 (((skb->data[1] & 0x0f) == 2) && (0==(cr & 0x7fff)))) { /* Global CallRef */
3028 if (st->l3.debug & L3_DEB_STATE)
3029 l3_debug(st, "dss1up Global CallRef");
3030 global_handler(st, mt, skb);
3031 dev_kfree_skb(skb);
3032 return;
3033 } else if (!(proc = getl3proc(st, cr))) {
3034 /* No transaction process exist, that means no call with
3035 * this callreference is active
3037 if (mt == MT_SETUP) {
3038 /* Setup creates a new transaction process */
3039 if (skb->data[2] & 0x80) {
3040 /* Setup with wrong CREF flag */
3041 if (st->l3.debug & L3_DEB_STATE)
3042 l3_debug(st, "dss1up wrong CRef flag");
3043 dev_kfree_skb(skb);
3044 return;
3046 if (!(proc = dss1_new_l3_process(st, cr))) {
3047 /* May be to answer with RELEASE_COMPLETE and
3048 * CAUSE 0x2f "Resource unavailable", but this
3049 * need a new_l3_process too ... arghh
3051 dev_kfree_skb(skb);
3052 return;
3054 } else if (mt == MT_STATUS) {
3055 cause = 0;
3056 if ((ptr = findie(skb->data, skb->len, IE_CAUSE, 0)) != NULL) {
3057 ptr++;
3058 if (*ptr++ == 2)
3059 ptr++;
3060 cause = *ptr & 0x7f;
3062 callState = 0;
3063 if ((ptr = findie(skb->data, skb->len, IE_CALL_STATE, 0)) != NULL) {
3064 ptr++;
3065 if (*ptr++ == 2)
3066 ptr++;
3067 callState = *ptr;
3069 /* ETS 300-104 part 2.4.1
3070 * if setup has not been made and a message type
3071 * MT_STATUS is received with call state == 0,
3072 * we must send nothing
3074 if (callState != 0) {
3075 /* ETS 300-104 part 2.4.2
3076 * if setup has not been made and a message type
3077 * MT_STATUS is received with call state != 0,
3078 * we must send MT_RELEASE_COMPLETE cause 101
3080 if ((proc = dss1_new_l3_process(st, cr))) {
3081 proc->para.cause = 101;
3082 l3dss1_msg_without_setup(proc, 0, NULL);
3085 dev_kfree_skb(skb);
3086 return;
3087 } else if (mt == MT_RELEASE_COMPLETE) {
3088 dev_kfree_skb(skb);
3089 return;
3090 } else {
3091 /* ETS 300-104 part 2
3092 * if setup has not been made and a message type
3093 * (except MT_SETUP and RELEASE_COMPLETE) is received,
3094 * we must send MT_RELEASE_COMPLETE cause 81 */
3095 dev_kfree_skb(skb);
3096 if ((proc = dss1_new_l3_process(st, cr))) {
3097 proc->para.cause = 81;
3098 l3dss1_msg_without_setup(proc, 0, NULL);
3100 return;
3103 if (l3dss1_check_messagetype_validity(proc, mt, skb)) {
3104 dev_kfree_skb(skb);
3105 return;
3107 if ((p = findie(skb->data, skb->len, IE_DISPLAY, 0)) != NULL)
3108 l3dss1_deliver_display(proc, pr, p); /* Display IE included */
3109 for (i = 0; i < DATASLLEN; i++)
3110 if ((mt == datastatelist[i].primitive) &&
3111 ((1 << proc->state) & datastatelist[i].state))
3112 break;
3113 if (i == DATASLLEN) {
3114 if (st->l3.debug & L3_DEB_STATE) {
3115 l3_debug(st, "dss1up%sstate %d mt %#x unhandled",
3116 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
3117 proc->state, mt);
3119 if ((MT_RELEASE_COMPLETE != mt) && (MT_RELEASE != mt)) {
3120 proc->para.cause = 101;
3121 l3dss1_status_send(proc, pr, skb);
3123 } else {
3124 if (st->l3.debug & L3_DEB_STATE) {
3125 l3_debug(st, "dss1up%sstate %d mt %x",
3126 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
3127 proc->state, mt);
3129 datastatelist[i].rout(proc, pr, skb);
3131 dev_kfree_skb(skb);
3132 return;
3135 static void
3136 dss1down(struct PStack *st, int pr, void *arg)
3138 int i, cr;
3139 struct l3_process *proc;
3140 struct Channel *chan;
3142 if ((DL_ESTABLISH | REQUEST) == pr) {
3143 l3_msg(st, pr, NULL);
3144 return;
3145 } else if (((CC_SETUP | REQUEST) == pr) || ((CC_RESUME | REQUEST) == pr)) {
3146 chan = arg;
3147 cr = newcallref();
3148 cr |= 0x80;
3149 if ((proc = dss1_new_l3_process(st, cr))) {
3150 proc->chan = chan;
3151 chan->proc = proc;
3152 memcpy(&proc->para.setup, &chan->setup, sizeof(setup_parm));
3153 proc->callref = cr;
3155 } else {
3156 proc = arg;
3158 if (!proc) {
3159 printk(KERN_ERR "HiSax dss1down without proc pr=%04x\n", pr);
3160 return;
3163 if ( pr == (CC_TDSS1_IO | REQUEST)) {
3164 l3dss1_io_timer(proc); /* timer expires */
3165 return;
3168 for (i = 0; i < DOWNSLLEN; i++)
3169 if ((pr == downstatelist[i].primitive) &&
3170 ((1 << proc->state) & downstatelist[i].state))
3171 break;
3172 if (i == DOWNSLLEN) {
3173 if (st->l3.debug & L3_DEB_STATE) {
3174 l3_debug(st, "dss1down state %d prim %#x unhandled",
3175 proc->state, pr);
3177 } else {
3178 if (st->l3.debug & L3_DEB_STATE) {
3179 l3_debug(st, "dss1down state %d prim %#x",
3180 proc->state, pr);
3182 downstatelist[i].rout(proc, pr, arg);
3186 static void
3187 dss1man(struct PStack *st, int pr, void *arg)
3189 int i;
3190 struct l3_process *proc = arg;
3192 if (!proc) {
3193 printk(KERN_ERR "HiSax dss1man without proc pr=%04x\n", pr);
3194 return;
3196 for (i = 0; i < MANSLLEN; i++)
3197 if ((pr == manstatelist[i].primitive) &&
3198 ((1 << proc->state) & manstatelist[i].state))
3199 break;
3200 if (i == MANSLLEN) {
3201 if (st->l3.debug & L3_DEB_STATE) {
3202 l3_debug(st, "cr %d dss1man state %d prim %#x unhandled",
3203 proc->callref & 0x7f, proc->state, pr);
3205 } else {
3206 if (st->l3.debug & L3_DEB_STATE) {
3207 l3_debug(st, "cr %d dss1man state %d prim %#x",
3208 proc->callref & 0x7f, proc->state, pr);
3210 manstatelist[i].rout(proc, pr, arg);
3214 void
3215 setstack_dss1(struct PStack *st)
3217 char tmp[64];
3218 int i;
3220 st->l3.l4l3 = dss1down;
3221 st->l3.l4l3_proto = l3dss1_cmd_global;
3222 st->l3.l2l3 = dss1up;
3223 st->l3.l3ml3 = dss1man;
3224 st->l3.N303 = 1;
3225 st->prot.dss1.last_invoke_id = 0;
3226 st->prot.dss1.invoke_used[0] = 1; /* Bit 0 must always be set to 1 */
3227 i = 1;
3228 while (i < 32)
3229 st->prot.dss1.invoke_used[i++] = 0;
3231 if (!(st->l3.global = kmalloc(sizeof(struct l3_process), GFP_ATOMIC))) {
3232 printk(KERN_ERR "HiSax can't get memory for dss1 global CR\n");
3233 } else {
3234 st->l3.global->state = 0;
3235 st->l3.global->callref = 0;
3236 st->l3.global->next = NULL;
3237 st->l3.global->debug = L3_DEB_WARN;
3238 st->l3.global->st = st;
3239 st->l3.global->N303 = 1;
3240 st->l3.global->prot.dss1.invoke_id = 0;
3242 L3InitTimer(st->l3.global, &st->l3.global->timer);
3244 strcpy(tmp, dss1_revision);
3245 printk(KERN_INFO "HiSax: DSS1 Rev. %s\n", HiSax_getrev(tmp));