root/drivers/isdn/teles/tei.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. findces
  2. findtei
  3. tei_handler
  4. randomces
  5. tei_man
  6. tei_l2tei
  7. setstack_tei
  8. init_tei
  9. release_tei
  10. TeiNew
  11. TeiFree

   1 /* $Id: tei.c,v 1.1 1996/04/13 10:28:25 fritz Exp $
   2  *
   3  * $Log: tei.c,v $
   4  * Revision 1.1  1996/04/13 10:28:25  fritz
   5  * Initial revision
   6  *
   7  *
   8  */
   9 #define __NO_VERSION__
  10 #include "teles.h"
  11 
  12 extern struct IsdnCard cards[];
  13 extern int      nrcards;
  14 
  15 static struct PStack *
  16 findces(struct PStack *st, int ces)
     /* [previous][next][first][last][top][bottom][index][help] */
  17 {
  18         struct PStack  *ptr = *(st->l1.stlistp);
  19 
  20         while (ptr)
  21                 if (ptr->l2.ces == ces)
  22                         return (ptr);
  23                 else
  24                         ptr = ptr->next;
  25         return (NULL);
  26 }
  27 
  28 static struct PStack *
  29 findtei(struct PStack *st, int tei)
     /* [previous][next][first][last][top][bottom][index][help] */
  30 {
  31         struct PStack  *ptr = *(st->l1.stlistp);
  32 
  33         if (tei == 127)
  34                 return (NULL);
  35 
  36         while (ptr)
  37                 if (ptr->l2.tei == tei)
  38                         return (ptr);
  39                 else
  40                         ptr = ptr->next;
  41         return (NULL);
  42 }
  43 
  44 void 
  45 tei_handler(struct PStack *st,
     /* [previous][next][first][last][top][bottom][index][help] */
  46             byte pr, struct BufHeader *ibh)
  47 {
  48         byte           *bp;
  49         unsigned int    tces;
  50         struct PStack  *otsp, *ptr;
  51         unsigned int    data;
  52 
  53         if (st->l2.debug)
  54                 printk(KERN_DEBUG "teihandler %d\n", pr);
  55 
  56         switch (pr) {
  57           case (MDL_ASSIGN):
  58                   data = (unsigned int) ibh;
  59                   BufPoolGet(&ibh, st->l1.smallpool, GFP_ATOMIC, (void *) st, 6);
  60                   if (!ibh)
  61                           return;
  62                   bp = DATAPTR(ibh);
  63                   bp += st->l2.uihsize;
  64                   bp[0] = 0xf;
  65                   bp[1] = data >> 8;
  66                   bp[2] = data & 0xff;
  67                   bp[3] = 0x1;
  68                   bp[4] = 0xff;
  69                   ibh->datasize = 8;
  70                   st->l3.l3l2(st, DL_UNIT_DATA, ibh);
  71                   break;
  72           case (DL_UNIT_DATA):
  73                   bp = DATAPTR(ibh);
  74                   bp += 3;
  75                   if (bp[0] != 0xf)
  76                           break;
  77                   switch (bp[3]) {
  78                     case (2):
  79                             tces = (bp[1] << 8) | bp[2];
  80                             BufPoolRelease(ibh);
  81                             if (st->l3.debug)
  82                                     printk(KERN_DEBUG "tei identity assigned for %d=%d\n", tces,
  83                                            bp[4] >> 1);
  84                             if ((otsp = findces(st, tces)))
  85                                     otsp->ma.teil2(otsp, MDL_ASSIGN,
  86                                                    (void *)(bp[4] >> 1));
  87                             break;
  88                     case (4):
  89                             if (st->l3.debug)
  90                                     printk(KERN_DEBUG "checking identity for %d\n", bp[4] >> 1);
  91                             if (bp[4] >> 1 == 0x7f) {
  92                                     BufPoolRelease(ibh);
  93                                     ptr = *(st->l1.stlistp);
  94                                     while (ptr) {
  95                                             if ((ptr->l2.tei & 0x7f) != 0x7f) {
  96                                                     if (BufPoolGet(&ibh, st->l1.smallpool, GFP_ATOMIC, (void *) st, 7))
  97                                                             break;
  98                                                     bp = DATAPTR(ibh);
  99                                                     bp += 3;
 100                                                     bp[0] = 0xf;
 101                                                     bp[1] = ptr->l2.ces >> 8;
 102                                                     bp[2] = ptr->l2.ces & 0xff;
 103                                                     bp[3] = 0x5;
 104                                                     bp[4] = (ptr->l2.tei << 1) | 1;
 105                                                     ibh->datasize = 8;
 106                                                     st->l3.l3l2(st, DL_UNIT_DATA, ibh);
 107                                             }
 108                                             ptr = ptr->next;
 109                                     }
 110                             } else {
 111                                     otsp = findtei(st, bp[4] >> 1);
 112                                     BufPoolRelease(ibh);
 113                                     if (!otsp)
 114                                             break;
 115                                     if (st->l3.debug)
 116                                             printk(KERN_DEBUG "ces is %d\n", otsp->l2.ces);
 117                                     if (BufPoolGet(&ibh, st->l1.smallpool, GFP_ATOMIC, (void *) st, 7))
 118                                             break;
 119                                     bp = DATAPTR(ibh);
 120                                     bp += 3;
 121                                     bp[0] = 0xf;
 122                                     bp[1] = otsp->l2.ces >> 8;
 123                                     bp[2] = otsp->l2.ces & 0xff;
 124                                     bp[3] = 0x5;
 125                                     bp[4] = (otsp->l2.tei << 1) | 1;
 126                                     ibh->datasize = 8;
 127                                     st->l3.l3l2(st, DL_UNIT_DATA, ibh);
 128                             }
 129                             break;
 130                     default:
 131                             BufPoolRelease(ibh);
 132                             if (st->l3.debug)
 133                                     printk(KERN_DEBUG "tei message unknown %d ai %d\n", bp[3], bp[4] >> 1);
 134                   }
 135                   break;
 136           default:
 137                   printk(KERN_WARNING "tei handler unknown primitive %d\n", pr);
 138                   break;
 139         }
 140 }
 141 
 142 unsigned int 
 143 randomces(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 144 {
 145         int             x = jiffies & 0xffff;
 146 
 147         return (x);
 148 }
 149 
 150 static void 
 151 tei_man(struct PStack *sp, int i, void *v)
     /* [previous][next][first][last][top][bottom][index][help] */
 152 {
 153         printk(KERN_DEBUG "tei_man\n");
 154 }
 155 
 156 static void 
 157 tei_l2tei(struct PStack *st, int pr, void *arg)
     /* [previous][next][first][last][top][bottom][index][help] */
 158 {
 159         struct IsdnCardState *sp = st->l1.hardware;
 160 
 161         tei_handler(sp->teistack, pr, arg);
 162 }
 163 
 164 void 
 165 setstack_tei(struct PStack *st)
     /* [previous][next][first][last][top][bottom][index][help] */
 166 {
 167         st->l2.l2tei = tei_l2tei;
 168 }
 169 
 170 static void 
 171 init_tei(struct IsdnCardState *sp, int protocol)
     /* [previous][next][first][last][top][bottom][index][help] */
 172 {
 173         struct PStack  *st;
 174         char            tmp[128];
 175 
 176 #define DIRTY_HACK_AGAINST_SIGSEGV
 177 
 178         st = (struct PStack *) Smalloc(sizeof(struct PStack), GFP_KERNEL,
 179                                        "struct PStack");
 180 
 181 #ifdef DIRTY_HACK_AGAINST_SIGSEGV
 182         sp->teistack = st;                      /* struct is not initialized yet */
 183         sp->teistack->protocol = protocol;      /* struct is not initialized yet */
 184 #endif                                          /* DIRTY_HACK_AGAINST_SIGSEGV    */
 185 
 186 
 187         setstack_teles(st, sp);
 188 
 189         st->l2.extended = !0;
 190         st->l2.laptype = LAPD;
 191         st->l2.window = 1;
 192         st->l2.orig = !0;
 193         st->protocol = protocol;
 194 
 195 /*
 196  * the following is not necessary for tei mng. (broadcast only)
 197  */
 198 
 199         st->l2.t200 = 500;      /* 500 milliseconds */
 200         st->l2.n200 = 4;        /* try 4 times */
 201 
 202         st->l2.sap = 63;
 203         st->l2.tei = 127;
 204 
 205         sprintf(tmp, "Card %d tei ", sp->cardnr);
 206         setstack_isdnl2(st, tmp);
 207         st->l2.debug = 0;
 208         st->l3.debug = 0;
 209 
 210         st->ma.manl2(st, MDL_NOTEIPROC, NULL);
 211 
 212         st->l2.l2l3 = (void *) tei_handler;
 213         st->l1.l1man = tei_man;
 214         st->l2.l2man = tei_man;
 215         st->l4.l2writewakeup = NULL;
 216         
 217         teles_addlist(sp, st);
 218         sp->teistack = st;
 219 }
 220 
 221 static void 
 222 release_tei(struct IsdnCardState *sp)
     /* [previous][next][first][last][top][bottom][index][help] */
 223 {
 224         struct PStack  *st = sp->teistack;
 225 
 226         teles_rmlist(sp, st);
 227         Sfree((void *) st);
 228 }
 229 
 230 void 
 231 TeiNew(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 232 {
 233         int             i;
 234 
 235         for (i = 0; i < nrcards; i++)
 236                 if (cards[i].sp)
 237                         init_tei(cards[i].sp, cards[i].protocol);
 238 }
 239 
 240 void 
 241 TeiFree(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 242 {
 243         int             i;
 244 
 245         for (i = 0; i < nrcards; i++)
 246                 if (cards[i].sp)
 247                         release_tei(cards[i].sp);
 248 }

/* [previous][next][first][last][top][bottom][index][help] */