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