This source file includes following definitions.
- findces
- findtei
- tei_handler
- randomces
- tei_man
- tei_l2tei
- setstack_tei
- init_tei
- release_tei
- TeiNew
- TeiFree
1
2
3
4
5
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)
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)
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,
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)
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)
152 {
153 printk(KERN_DEBUG "tei_man\n");
154 }
155
156 static void
157 tei_l2tei(struct PStack *st, int pr, void *arg)
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)
166 {
167 st->l2.l2tei = tei_l2tei;
168 }
169
170 static void
171 init_tei(struct IsdnCardState *sp, int protocol)
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;
183 sp->teistack->protocol = protocol;
184 #endif
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
197
198
199 st->l2.t200 = 500;
200 st->l2.n200 = 4;
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)
223 {
224 struct PStack *st = sp->teistack;
225
226 teles_rmlist(sp, st);
227 Sfree((void *) st);
228 }
229
230 void
231 TeiNew(void)
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)
242 {
243 int i;
244
245 for (i = 0; i < nrcards; i++)
246 if (cards[i].sp)
247 release_tei(cards[i].sp);
248 }