1 #include <linux/module.h>
2 #include <linux/version.h>
3 #include <linux/errno.h>
4 #include <linux/fs.h>
5 #include <linux/major.h>
6 #include <asm/segment.h>
7 #include <asm/io.h>
8 #include <linux/delay.h>
9 #include <linux/kernel.h>
10 #include <linux/signal.h>
11 #include <linux/malloc.h>
12 #include <linux/mm.h>
13 #include <linux/mman.h>
14 #include <linux/ioport.h>
15 #include <linux/timer.h>
16 #include <linux/wait.h>
17 #include <linux/isdnif.h>
18 #include <linux/tty.h>
19
20 #define PH_ACTIVATE 1
21 #define PH_DATA 2
22 #define PH_DEACTIVATE 3
23
24 #define MDL_ASSIGN 4
25 #define DL_UNIT_DATA 5
26 #define SC_STARTUP 6
27 #define CC_ESTABLISH 7
28 #define DL_ESTABLISH 8
29 #define DL_DATA 9
30 #define CC_S_STATUS_ENQ 10
31
32 #define CC_CONNECT 15
33 #define CC_CONNECT_ACKNOWLEDGE 16
34 #define CO_EOF 17
35 #define SC_DISCONNECT 18
36 #define CO_DTMF 19
37 #define DL_RELEASE 20
38
39 #define CO_ALARM 22
40 #define CC_REJECT 23
41
42 #define CC_SETUP_REQ 24
43 #define CC_SETUP_CNF 25
44 #define CC_SETUP_IND 26
45 #define CC_SETUP_RSP 27
46 #define CC_SETUP_COMPLETE_IND 28
47
48 #define CC_DISCONNECT_REQ 29
49 #define CC_DISCONNECT_IND 30
50
51 #define CC_RELEASE_CNF 31
52 #define CC_RELEASE_IND 32
53 #define CC_RELEASE_REQ 33
54
55 #define CC_REJECT_REQ 34
56
57 #define CC_PROCEEDING_IND 35
58
59 #define CC_DLRL 36
60 #define CC_DLEST 37
61
62 #define CC_ALERTING_REQ 38
63 #define CC_ALERTING_IND 39
64
65 #define DL_STOP 40
66 #define DL_START 41
67
68 #define MDL_NOTEIPROC 46
69
70 #define LC_ESTABLISH 47
71 #define LC_RELEASE 48
72
73 #define PH_REQUEST_PULL 49
74 #define PH_PULL_ACK 50
75 #define PH_DATA_PULLED 51
76 #define CC_INFO_CHARGE 52
77
78
79
80
81
82 #define MT_ALERTING 0x01
83 #define MT_CALL_PROCEEDING 0x02
84 #define MT_CONNECT 0x07
85 #define MT_CONNECT_ACKNOWLEDGE 0x0f
86 #define MT_PROGRESS 0x03
87 #define MT_SETUP 0x05
88 #define MT_SETUP_ACKNOWLEDGE 0x0d
89 #define MT_RESUME 0x26
90 #define MT_RESUME_ACKNOWLEDGE 0x2e
91 #define MT_RESUME_REJECT 0x22
92 #define MT_SUSPEND 0x25
93 #define MT_SUSPEND_ACKNOWLEDGE 0x2d
94 #define MT_SUSPEND_REJECT 0x21
95 #define MT_USER_INFORMATION 0x20
96 #define MT_DISCONNECT 0x45
97 #define MT_RELEASE 0x4d
98 #define MT_RELEASE_COMPLETE 0x5a
99 #define MT_RESTART 0x46
100 #define MT_RESTART_ACKNOWLEDGE 0x4e
101 #define MT_SEGMENT 0x60
102 #define MT_CONGESTION_CONTROL 0x79
103 #define MT_INFORMATION 0x7b
104 #define MT_FACILITY 0x62
105 #define MT_NOTIFY 0x6e
106 #define MT_STATUS 0x7d
107 #define MT_STATUS_ENQUIRY 0x75
108
109 #define IE_CAUSE 0x08
110
111 struct HscxIoctlArg {
112 int channel;
113 int mode;
114 int transbufsize;
115 };
116
117 #ifdef __KERNEL__
118
119 #undef DEBUG_MAGIC
120
121 #define HSCX_SBUF_ORDER 1
122 #define HSCX_SBUF_BPPS 2
123 #define HSCX_SBUF_MAXPAGES 3
124
125 #define HSCX_RBUF_ORDER 1
126 #define HSCX_RBUF_BPPS 2
127 #define HSCX_RBUF_MAXPAGES 3
128
129 #define HSCX_SMALLBUF_ORDER 0
130 #define HSCX_SMALLBUF_BPPS 40
131 #define HSCX_SMALLBUF_MAXPAGES 1
132
133 #define ISAC_SBUF_ORDER 0
134 #define ISAC_SBUF_BPPS 16
135 #define ISAC_SBUF_MAXPAGES 1
136
137 #define ISAC_RBUF_ORDER 0
138 #define ISAC_RBUF_BPPS 16
139 #define ISAC_RBUF_MAXPAGES 1
140
141 #define ISAC_SMALLBUF_ORDER 0
142 #define ISAC_SMALLBUF_BPPS 40
143 #define ISAC_SMALLBUF_MAXPAGES 1
144
145 #define byte unsigned char
146
147 #define MAX_WINDOW 8
148
149 byte *Smalloc(int size, int pr, char *why);
150 void Sfree(byte * ptr);
151
152
153
154
155 struct Fsm {
156 int *jumpmatrix;
157 int state_count, event_count;
158 char **strEvent, **strState;
159 };
160
161 struct FsmInst {
162 struct Fsm *fsm;
163 int state;
164 int debug;
165 void *userdata;
166 int userint;
167 void (*printdebug) (struct FsmInst *, char *);
168 };
169
170 struct FsmNode {
171 int state, event;
172 void (*routine) (struct FsmInst *, int, void *);
173 };
174
175 struct FsmTimer {
176 struct FsmInst *fi;
177 struct timer_list tl;
178 int event;
179 void *arg;
180 };
181
182 struct BufHeader {
183 #ifdef DEBUG_MAGIC
184 int magic;
185 #endif
186 struct BufHeader *next;
187 struct BufPool *bp;
188 int datasize;
189 byte primitive, where;
190 void *heldby;
191 };
192
193 struct Pages {
194 struct Pages *next;
195 };
196
197 struct BufPool {
198 #ifdef DEBUG_MAGIC
199 int magic;
200 #endif
201 struct BufHeader *freelist;
202 struct Pages *pageslist;
203 int pageorder;
204 int pagescount;
205 int bpps;
206 int bufsize;
207 int maxpages;
208 };
209
210 struct BufQueue {
211 #ifdef DEBUG_MAGIC
212 int magic;
213 #endif
214 struct BufHeader *head, *tail;
215 };
216
217 struct Layer1 {
218 void *hardware;
219 int hscx;
220 struct BufPool *sbufpool, *rbufpool, *smallpool;
221 struct PStack **stlistp;
222 int act_state;
223 void (*l1l2) (struct PStack *, int, struct BufHeader *);
224 void (*l1man) (struct PStack *, int, void *);
225 int hscxmode, hscxchannel, requestpull;
226 };
227
228 struct Layer2 {
229 int sap, tei, ces;
230 int extended, laptype;
231 int uihsize, ihsize;
232 int vs, va, vr;
233 struct BufQueue i_queue;
234 int window, orig;
235 int rejexp;
236 int debug;
237 struct BufHeader *windowar[MAX_WINDOW];
238 int sow;
239 struct FsmInst l2m;
240 void (*l2l1) (struct PStack *, int, struct BufHeader *);
241 void (*l2l1discardq) (struct PStack *, int, void *, int);
242 void (*l2man) (struct PStack *, int, void *);
243 void (*l2l3) (struct PStack *, int, void *);
244 void (*l2tei) (struct PStack *, int, void *);
245 struct FsmTimer t200_timer, t203_timer;
246 int t200, n200, t203;
247 int rc, t200_running;
248 char debug_id[32];
249 };
250
251 struct Layer3 {
252 void (*l3l4) (struct PStack *, int, struct BufHeader *);
253 void (*l3l2) (struct PStack *, int, void *);
254 int state, callref;
255 int debug;
256 };
257
258 struct Layer4 {
259 void (*l4l3) (struct PStack *, int, void *);
260 void *userdata;
261 void (*l1writewakeup) (struct PStack *);
262 void (*l2writewakeup) (struct PStack *);
263 };
264
265 struct Management {
266 void (*manl1) (struct PStack *, int, void *);
267 void (*manl2) (struct PStack *, int, void *);
268 void (*teil2) (struct PStack *, int, void *);
269 };
270
271 struct Param {
272 int cause;
273 int bchannel;
274 int callref;
275 int itc;
276 int info;
277 int info2;
278 char calling[40];
279 char called[40];
280 int chargeinfo;
281
282
283 };
284
285 struct PStack {
286 struct PStack *next;
287 struct Layer1 l1;
288 struct Layer2 l2;
289 struct Layer3 l3;
290 struct Layer4 l4;
291 struct Management ma;
292 struct Param *pa;
293 int protocol;
294 };
295
296 struct HscxState {
297 byte *membase;
298 int iobase;
299 int inuse, init, active;
300 struct BufPool sbufpool, rbufpool, smallpool;
301 struct IsdnCardState *sp;
302 int hscx, mode;
303 int transbufsize, receive;
304 struct BufHeader *rcvibh, *xmtibh;
305 int rcvptr, sendptr;
306 struct PStack *st;
307 struct tq_struct tqueue;
308 int event;
309 struct BufQueue rq, sq;
310 int releasebuf;
311 #ifdef DEBUG_MAGIC
312 int magic;
313 #endif
314 };
315
316 struct IsdnCardState {
317 #ifdef DEBUG_MAGIC
318 int magic;
319 #endif
320 byte *membase;
321 int iobase;
322 struct BufPool sbufpool, rbufpool, smallpool;
323 struct PStack *stlist;
324 struct BufHeader *xmtibh, *rcvibh;
325 int rcvptr, sendptr;
326 int event;
327 struct tq_struct tqueue;
328 int ph_active;
329 struct BufQueue rq, sq;
330
331 int cardnr, ph_state;
332 struct PStack *teistack;
333 struct HscxState hs[2];
334
335 int dlogflag;
336 char *dlogspace;
337 int debug;
338 int releasebuf;
339 };
340
341 struct IsdnCard {
342 byte *membase;
343 int interrupt;
344 unsigned int iobase;
345 int protocol;
346 struct IsdnCardState *sp;
347 };
348
349 #define DATAPTR(x) ((byte *)x+sizeof(struct BufHeader))
350
351 #define LAPD 0
352 #define LAPB 1
353
354 void BufPoolInit(struct BufPool *bp, int order, int bpps,
355 int maxpages);
356 int BufPoolAdd(struct BufPool *bp, int priority);
357 void BufPoolFree(struct BufPool *bp);
358 int BufPoolGet(struct BufHeader **bh,
359 struct BufPool *bp, int priority, void *heldby, int where);
360 void BufPoolRelease(struct BufHeader *bh);
361 void BufQueueLink(struct BufQueue *bq,
362 struct BufHeader *bh);
363 int BufQueueUnlink(struct BufHeader **bh, struct BufQueue *bq);
364 void BufQueueInit(struct BufQueue *bq);
365 void BufQueueRelease(struct BufQueue *bq);
366 void BufQueueDiscard(struct BufQueue *q, int pr, void *heldby,
367 int releasetoo);
368 int BufQueueLength(struct BufQueue *bq);
369 void BufQueueLinkFront(struct BufQueue *bq,
370 struct BufHeader *bh);
371
372 void l2down(struct PStack *st,
373 byte pr, struct BufHeader *ibh);
374 void l2up(struct PStack *st,
375 byte pr, struct BufHeader *ibh);
376 void acceptph(struct PStack *st,
377 struct BufHeader *ibh);
378 void setstack_isdnl2(struct PStack *st, char *debug_id);
379 int teles_inithardware(void);
380 void teles_closehardware(void);
381
382 void setstack_teles(struct PStack *st, struct IsdnCardState *sp);
383 unsigned int randomces(void);
384 void setstack_isdnl3(struct PStack *st);
385 void teles_addlist(struct IsdnCardState *sp,
386 struct PStack *st);
387 void releasestack_isdnl2(struct PStack *st);
388 void teles_rmlist(struct IsdnCardState *sp,
389 struct PStack *st);
390 void newcallref(struct PStack *st);
391
392 int ll_init(void);
393 void ll_stop(void), ll_unload(void);
394 int setstack_hscx(struct PStack *st, struct HscxState *hs);
395 void modehscx(struct HscxState *hs, int mode, int ichan);
396 byte *findie(byte * p, int size, byte ie, int wanted_set);
397 int getcallref(byte * p);
398
399 void FsmNew(struct Fsm *fsm,
400 struct FsmNode *fnlist, int fncount);
401 void FsmFree(struct Fsm *fsm);
402 int FsmEvent(struct FsmInst *fi,
403 int event, void *arg);
404 void FsmChangeState(struct FsmInst *fi,
405 int newstate);
406 void FsmInitTimer(struct FsmInst *fi, struct FsmTimer *ft);
407 int FsmAddTimer(struct FsmTimer *ft,
408 int millisec, int event, void *arg, int where);
409 void FsmDelTimer(struct FsmTimer *ft, int where);
410 int FsmTimerRunning(struct FsmTimer *ft);
411 void jiftime(char *s, long mark);
412
413 void CallcNew(void);
414 void CallcFree(void);
415 int CallcNewChan(void);
416 void CallcFreeChan(void);
417 int teles_command(isdn_ctrl * ic);
418 int teles_writebuf(int id, int chan, const u_char * buf, int count, int user);
419 void teles_putstatus(char *buf);
420 void teles_reportcard(int cardnr);
421 int ListLength(struct BufHeader *ibh);
422 void dlogframe(struct IsdnCardState *sp, byte * p, int size, char *comment);
423 void iecpy(byte * dest, byte * iestart, int ieoffset);
424 void setstack_transl2(struct PStack *st);
425 void releasestack_transl2(struct PStack *st);
426 void close_hscxstate(struct HscxState *);
427 void setstack_tei(struct PStack *st);
428
429 struct LcFsm {
430 struct FsmInst lcfi;
431 int type;
432 struct Channel *ch;
433 void (*lccall) (struct LcFsm *, int, void *);
434 struct PStack *st;
435 int l2_establish;
436 int l2_start;
437 struct FsmTimer act_timer;
438 char debug_id[32];
439 };
440
441 struct Channel {
442 struct PStack ds, is;
443 struct IsdnCardState *sp;
444 int hscx;
445 int chan;
446 int incoming;
447 struct FsmInst fi;
448 struct LcFsm lc_d, lc_b;
449 struct Param para;
450 int debug;
451 #ifdef DEBUG_MAGIC
452 int magic;
453 #endif
454 int l2_protocol, l2_active_protocol;
455 int l2_primitive, l2_headersize;
456 int data_open;
457 int outcallref;
458 int impair;
459 };
460
461 #define PART_SIZE(order,bpps) (( (PAGE_SIZE<<order) -\
462 sizeof(void *))/bpps)
463 #define BUFFER_SIZE(order,bpps) (PART_SIZE(order,bpps)-\
464 sizeof(struct BufHeader))
465
466 #endif
467
468 void Isdnl2New(void);
469 void Isdnl2Free(void);
470 void TeiNew(void);
471 void TeiFree(void);
472
473
474
475