/* $Id: isdnl3.c,v 2.22.2.3 2004/01/13 14:31:25 keil Exp $ * * Author Karsten Keil * based on the teles driver from Jan den Ouden * Copyright by Karsten Keil * * This software may be used and distributed according to the terms * of the GNU General Public License, incorporated herein by reference. * * For changes and modifications please read * Documentation/isdn/HiSax.cert * * Thanks to Jan den Ouden * Fritz Elfert * */ #include #include #include "hisax.h" #include "isdnl3.h" const char *l3_revision = "$Revision: 2.22.2.3 $"; static struct Fsm l3fsm; enum { ST_L3_LC_REL, ST_L3_LC_ESTAB_WAIT, ST_L3_LC_REL_DELAY, ST_L3_LC_REL_WAIT, ST_L3_LC_ESTAB, }; #define L3_STATE_COUNT (ST_L3_LC_ESTAB + 1) static char *strL3State[] = { "ST_L3_LC_REL", "ST_L3_LC_ESTAB_WAIT", "ST_L3_LC_REL_DELAY", "ST_L3_LC_REL_WAIT", "ST_L3_LC_ESTAB", }; enum { EV_ESTABLISH_REQ, EV_ESTABLISH_IND, EV_ESTABLISH_CNF, EV_RELEASE_REQ, EV_RELEASE_CNF, EV_RELEASE_IND, EV_TIMEOUT, }; #define L3_EVENT_COUNT (EV_TIMEOUT + 1) static char *strL3Event[] = { "EV_ESTABLISH_REQ", "EV_ESTABLISH_IND", "EV_ESTABLISH_CNF", "EV_RELEASE_REQ", "EV_RELEASE_CNF", "EV_RELEASE_IND", "EV_TIMEOUT", }; static __printf(2, 3) void l3m_debug(struct FsmInst *fi, char *fmt, ...) { va_list args; struct PStack *st = fi->userdata; va_start(args, fmt); VHiSax_putstatus(st->l1.hardware, st->l3.debug_id, fmt, args); va_end(args); } u_char * findie(u_char *p, int size, u_char ie, int wanted_set) { int l, codeset, maincodeset; u_char *pend = p + size; /* skip protocol discriminator, callref and message type */ p++; l = (*p++) & 0xf; p += l; p++; codeset = 0; maincodeset = 0; /* while there are bytes left... */ while (p < pend) { if ((*p & 0xf0) == 0x90) { codeset = *p & 0x07; if (!(*p & 0x08)) maincodeset = codeset; } if (*p & 0x80) p++; else { if (codeset == wanted_set) { if (*p == ie) { /* improved length check (Werner Cornelius) */ if ((pend - p) < 2) return (NULL); if (*(p + 1) > (pend - (p + 2))) return (NULL); return (p); } if (*p > ie) return (NULL); } p++; l = *p++; p += l; codeset = maincodeset; } } return (NULL); } int getcallref(u_char *p) { int l, cr = 0; p++; /* prot discr */ if (*p & 0xfe) /* wrong callref BRI only 1 octet*/ return (-2); l = 0xf & *p++; /* callref length */ if (!l) /* dummy CallRef */ return (-1); cr = *p++; return (cr); } static int OrigCallRef = 0; int newcallref(void) { if (OrigCallRef == 127) OrigCallRef = 1; else OrigCallRef++; return (OrigCallRef); } void newl3state(struct l3_process *pc, int state) { if (pc->debug & L3_DEB_STATE) l3_debug(pc->st, "%s cr %d %d --> %d", __func__, pc->callref & 0x7F, pc->state, state); pc->state = state; } static void L3ExpireTimer(struct L3Timer *t) { t->pc->st->lli.l4l3(t->pc->st, t->event, t->pc); } void L3InitTimer(struct l3_process *pc, struct L3Timer *t) { t->pc = pc; t->tl.function = (void *) L3ExpireTimer; t->tl.data = (long) t; init_timer(&t->tl); } void L3DelTimer(struct L3Timer *t) { del_timer(&t->tl); } int L3AddTimer(struct L3Timer *t, int millisec, int event) { if (timer_pending(&t->tl)) { printk(KERN_WARNING "L3AddTimer: timer already active!\n"); return -1; } init_timer(&t->tl); t->event = event; t->tl.expires = jiffies + (millisec * HZ) / 1000; add_timer(&t->tl); return 0; } void StopAllL3Timer(struct l3_process *pc) { L3DelTimer(&pc->timer); } struct sk_buff * l3_alloc_skb(int len) { struct sk_buff *skb; if (!(skb = alloc_skb(len + MAX_HEADER_LEN, GFP_ATOMIC))) { printk(KERN_WARNING "HiSax: No skb for D-channel\n"); return (NULL); } skb_reserve(skb, MAX_HEADER_LEN); return (skb); } static void no_l3_proto(struct PStack *st, int pr, void *arg) { struct sk_buff *skb = arg; HiSax_putstatus(st->l1.hardware, "L3", "no D protocol"); if (skb) { dev_kfree_skb(skb); } } static int no_l3_proto_spec(struct PStack *st, isdn_ctrl *ic) { printk(KERN_WARNING "HiSax: no specific protocol handler for proto %lu\n", ic->arg & 0xFF); return (-1); } struct l3_process *getl3proc(struct PStack *st, int cr) { struct l3_process *p = st->l3.proc; while (p) if (p->callref == cr) return (p); else p = p->next; return (NULL); } struct l3_process *new_l3_process(struct PStack *st, int cr) { struct l3_process *p, *np; if (!(p = kmalloc(sizeof(struct l3_process), GFP_ATOMIC))) { printk(KERN_ERR "HiSax can't get memory for cr %d\n", cr); return (NULL); } if (!st->l3.proc) st->l3.proc = p; else { np = st->l3.proc; while (np->next) np = np->next; np->next = p; } p->next = NULL; p->debug = st->l3.debug; p->callref = cr; p->state = 0; p->chan = NULL; p->st = st; p->N303 = st->l3.N303; L3InitTimer(p, &p->timer); return (p); }; void release_l3_process(struct l3_p