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