OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [uclinux/] [uClinux-2.0.x/] [drivers/] [isdn/] [pcbit/] [capi.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/*
2
 * Copyright (C) 1996 Universidade de Lisboa
3
 *
4
 * Written by Pedro Roque Marques (roque@di.fc.ul.pt)
5
 *
6
 * This software may be used and distributed according to the terms of
7
 * the GNU Public License, incorporated herein by reference.
8
 */
9
 
10
/*
11
 *        CAPI encoder/decoder for
12
 *        Portugal Telecom CAPI 2.0
13
 *
14
 *        Not compatible with the AVM Gmbh. CAPI 2.0
15
 */
16
 
17
/*
18
 *        Documentation:
19
 *        - "Common ISDN API - Perfil Português - Versão 2.1",
20
 *           Telecom Portugal, Fev 1992.
21
 *        - "Common ISDN API - Especificação de protocolos para
22
 *           acesso aos canais B", Inesc, Jan 1994.
23
 */
24
 
25
/*
26
 *        TODO: better decoding of Information Elements
27
 *              for debug purposes mainly
28
 *              encode our number in CallerPN and ConnectedPN
29
 */
30
 
31
#define __NO_VERSION__
32
 
33
#include <linux/module.h>
34
 
35
#include <linux/sched.h>
36
#include <linux/string.h>
37
#include <linux/kernel.h>
38
 
39
#include <linux/types.h>
40
#include <linux/malloc.h>
41
#include <linux/mm.h>
42
 
43
#include <linux/tqueue.h>
44
#include <linux/skbuff.h>
45
 
46
#include <asm/io.h>
47
#include <asm/string.h>
48
 
49
#include <linux/isdnif.h>
50
 
51
#include "pcbit.h"
52
#include "edss1.h"
53
#include "capi.h"
54
 
55
 
56
/*
57
 *  Encoding of CAPI messages
58
 *
59
 */
60
 
61
int capi_conn_req(const char * calledPN, struct sk_buff **skb, int proto)
62
{
63
        ushort len;
64
 
65
        /*
66
         * length
67
         *   AppInfoMask - 2
68
         *   BC0         - 3
69
         *   BC1         - 1
70
         *   Chan        - 2
71
         *   Keypad      - 1
72
         *   CPN         - 1
73
         *   CPSA        - 1
74
         *   CalledPN    - 2 + strlen
75
         *   CalledPSA   - 1
76
         *   rest...     - 4
77
         *   ----------------
78
         *   Total        18 + strlen
79
         */
80
 
81
        len = 18 + strlen(calledPN);
82
 
83
        if (proto == ISDN_PROTO_L2_TRANS)
84
                len++;
85
 
86
        if ((*skb = dev_alloc_skb(len)) == NULL) {
87
 
88
                printk(KERN_WARNING "capi_conn_req: alloc_skb failed\n");
89
                return -1;
90
        }
91
 
92
        /* InfoElmMask */
93
        *((ushort*) skb_put(*skb, 2)) = AppInfoMask;
94
 
95
        if (proto == ISDN_PROTO_L2_TRANS)
96
        {
97
                /* Bearer Capability - Mandatory*/
98
                *(skb_put(*skb, 1)) = 3;        /* BC0.Length           */
99
                *(skb_put(*skb, 1)) = 0x80;     /* Speech               */
100
                *(skb_put(*skb, 1)) = 0x10;     /* Circuit Mode         */
101
                *(skb_put(*skb, 1)) = 0x23;     /* A-law                */
102
        }
103
        else
104
        {
105
                /* Bearer Capability - Mandatory*/
106
                *(skb_put(*skb, 1)) = 2;        /* BC0.Length           */
107
                *(skb_put(*skb, 1)) = 0x88;     /* Digital Information  */
108
                *(skb_put(*skb, 1)) = 0x90;     /* BC0.Octect4          */
109
        }
110
 
111
        /* Bearer Capability - Optional*/
112
        *(skb_put(*skb, 1)) = 0;        /* BC1.Length = 0                    */
113
 
114
        *(skb_put(*skb, 1)) = 1;        /* ChannelID.Length = 1              */
115
        *(skb_put(*skb, 1)) = 0x83;     /* Basic Interface - Any Channel     */
116
 
117
        *(skb_put(*skb, 1)) = 0;        /* Keypad.Length = 0                 */
118
 
119
 
120
        *(skb_put(*skb, 1)) = 0;        /* CallingPN.Length = 0              */
121
        *(skb_put(*skb, 1)) = 0;        /* CallingPSA.Length = 0             */
122
 
123
        /* Called Party Number */
124
        *(skb_put(*skb, 1)) = strlen(calledPN) + 1;
125
        *(skb_put(*skb, 1)) = 0x81;
126
        memcpy(skb_put(*skb, strlen(calledPN)), calledPN, strlen(calledPN));
127
 
128
        /* '#' */
129
 
130
        *(skb_put(*skb, 1)) = 0;       /* CalledPSA.Length = 0     */
131
 
132
        /* LLC.Length  = 0; */
133
        /* HLC0.Length = 0; */
134
        /* HLC1.Length = 0; */
135
        /* UTUS.Length = 0; */
136
        memset(skb_put(*skb, 4), 0, 4);
137
 
138
        return len;
139
}
140
 
141
int capi_conn_resp(struct pcbit_chan* chan, struct sk_buff **skb)
142
{
143
 
144
        if ((*skb = dev_alloc_skb(5)) == NULL) {
145
 
146
                printk(KERN_WARNING "capi_conn_resp: alloc_skb failed\n");
147
                return -1;
148
        }
149
 
150
        SET_SKB_FREE((*skb));
151
 
152
 
153
        *((ushort*) skb_put(*skb, 2) ) = chan->callref;
154
        *(skb_put(*skb, 1)) = 0x01;  /* ACCEPT_CALL */
155
        *(skb_put(*skb, 1)) = 0;
156
        *(skb_put(*skb, 1)) = 0;
157
 
158
        return 5;
159
}
160
 
161
int capi_conn_active_req(struct pcbit_chan* chan, struct sk_buff **skb)
162
{
163
        /*
164
         * 8 bytes
165
         */
166
 
167
        if ((*skb = dev_alloc_skb(8)) == NULL) {
168
 
169
                printk(KERN_WARNING "capi_conn_active_req: alloc_skb failed\n");
170
                return -1;
171
        }
172
 
173
        SET_SKB_FREE((*skb));
174
 
175
        *((ushort*) skb_put(*skb, 2) ) = chan->callref;
176
 
177
#ifdef DEBUG
178
        printk(KERN_DEBUG "Call Reference: %04x\n", chan->callref);
179
#endif
180
 
181
        *(skb_put(*skb, 1)) = 0;       /*  BC.Length = 0;          */
182
        *(skb_put(*skb, 1)) = 0;       /*  ConnectedPN.Length = 0  */
183
        *(skb_put(*skb, 1)) = 0;       /*  PSA.Length              */
184
        *(skb_put(*skb, 1)) = 0;       /*  LLC.Length = 0;         */
185
        *(skb_put(*skb, 1)) = 0;       /*  HLC.Length = 0;         */
186
        *(skb_put(*skb, 1)) = 0;       /*  UTUS.Length = 0;        */
187
 
188
        return 8;
189
}
190
 
191
int capi_conn_active_resp(struct pcbit_chan* chan, struct sk_buff **skb)
192
{
193
        /*
194
         * 2 bytes
195
         */
196
 
197
        if ((*skb = dev_alloc_skb(2)) == NULL) {
198
 
199
                printk(KERN_WARNING "capi_conn_active_resp: alloc_skb failed\n");
200
                return -1;
201
        }
202
 
203
        SET_SKB_FREE((*skb));
204
 
205
        *((ushort*) skb_put(*skb, 2) ) = chan->callref;
206
 
207
        return 2;
208
}
209
 
210
 
211
int capi_select_proto_req(struct pcbit_chan *chan, struct sk_buff **skb,
212
                          int outgoing)
213
{
214
 
215
        /*
216
         * 18 bytes
217
         */
218
 
219
        if ((*skb = dev_alloc_skb(18)) == NULL) {
220
 
221
                printk(KERN_WARNING "capi_select_proto_req: alloc_skb failed\n");
222
                return -1;
223
        }
224
 
225
        SET_SKB_FREE((*skb));
226
 
227
        *((ushort*) skb_put(*skb, 2) ) = chan->callref;
228
 
229
        /* Layer2 protocol */
230
 
231
        switch (chan->proto) {
232
        case ISDN_PROTO_L2_X75I:
233
                *(skb_put(*skb, 1)) = 0x05;            /* LAPB */
234
                break;
235
        case ISDN_PROTO_L2_HDLC:
236
                *(skb_put(*skb, 1)) = 0x02;
237
                break;
238
        case ISDN_PROTO_L2_TRANS:
239
                /*
240
                 *      Voice (a-law)
241
                 */
242
                *(skb_put(*skb, 1)) = 0x06;
243
                break;
244
        default:
245
#ifdef DEBUG 
246
                printk(KERN_DEBUG "Transparent\n");
247
#endif
248
                *(skb_put(*skb, 1)) = 0x03;
249
                break;
250
        }
251
 
252
        *(skb_put(*skb, 1)) = (outgoing ? 0x02 : 0x42);    /* Don't ask */
253
        *(skb_put(*skb, 1)) = 0x00;
254
 
255
        *((ushort *) skb_put(*skb, 2)) = MRU;
256
 
257
 
258
        *(skb_put(*skb, 1)) = 0x08;           /* Modulo */
259
        *(skb_put(*skb, 1)) = 0x07;           /* Max Window */
260
 
261
        *(skb_put(*skb, 1)) = 0x01;           /* No Layer3 Protocol */
262
 
263
        /*
264
         * 2 - layer3 MTU       [10]
265
         *   - Modulo           [12]
266
         *   - Window
267
         *   - layer1 proto     [14]
268
         *   - bitrate
269
         *   - sub-channel      [16]
270
         *   - layer1dataformat [17]
271
         */
272
 
273
        memset(skb_put(*skb, 8), 0, 8);
274
 
275
        return 18;
276
}
277
 
278
 
279
int capi_activate_transp_req(struct pcbit_chan *chan, struct sk_buff **skb)
280
{
281
 
282
        if ((*skb = dev_alloc_skb(7)) == NULL) {
283
 
284
                printk(KERN_WARNING "capi_activate_transp_req: alloc_skb failed\n");
285
                return -1;
286
        }
287
 
288
        SET_SKB_FREE((*skb));
289
 
290
        *((ushort*) skb_put(*skb, 2) ) = chan->callref;
291
 
292
 
293
        *(skb_put(*skb, 1)) = chan->layer2link; /* Layer2 id */
294
        *(skb_put(*skb, 1)) = 0x00;             /* Transmit by default */
295
 
296
        *((ushort *) skb_put(*skb, 2)) = MRU;
297
 
298
        *(skb_put(*skb, 1)) = 0x01;             /* Enables reception*/
299
 
300
        return 7;
301
}
302
 
303
int capi_tdata_req(struct pcbit_chan* chan, struct sk_buff *skb)
304
{
305
        ushort data_len;
306
 
307
 
308
        /*
309
         * callref      - 2
310
         * layer2link   - 1
311
         * wBlockLength - 2
312
         * data         - 4
313
         * sernum       - 1
314
         */
315
 
316
        data_len = skb->len;
317
 
318
        skb_push(skb, 10);
319
 
320
        *((u16 *) (skb->data)) = chan->callref;
321
        skb->data[2] = chan->layer2link;
322
        *((u16 *) (skb->data + 3)) = data_len;
323
 
324
        chan->s_refnum = (chan->s_refnum + 1) % 8;
325
        *((u32 *) (skb->data + 5)) = chan->s_refnum;
326
 
327
        skb->data[9] = 0;                           /* HDLC frame number */
328
 
329
        return 10;
330
}
331
 
332
int capi_tdata_resp(struct pcbit_chan *chan, struct sk_buff ** skb)
333
 
334
{
335
        if ((*skb = dev_alloc_skb(4)) == NULL) {
336
 
337
                printk(KERN_WARNING "capi_tdata_resp: alloc_skb failed\n");
338
                return -1;
339
        }
340
 
341
        SET_SKB_FREE((*skb));
342
 
343
        *((ushort*) skb_put(*skb, 2) ) = chan->callref;
344
 
345
        *(skb_put(*skb, 1)) = chan->layer2link;
346
        *(skb_put(*skb, 1)) = chan->r_refnum;
347
 
348
        return (*skb)->len;
349
}
350
 
351
int capi_disc_req(ushort callref, struct sk_buff **skb, u_char cause)
352
{
353
 
354
        if ((*skb = dev_alloc_skb(6)) == NULL) {
355
 
356
                printk(KERN_WARNING "capi_disc_req: alloc_skb failed\n");
357
                return -1;
358
        }
359
 
360
        SET_SKB_FREE((*skb));
361
 
362
        *((ushort*) skb_put(*skb, 2) ) = callref;
363
 
364
        *(skb_put(*skb, 1)) = 2;                  /* Cause.Length = 2; */
365
        *(skb_put(*skb, 1)) = 0x80;
366
        *(skb_put(*skb, 1)) = 0x80 | cause;
367
 
368
        /*
369
         * Change it: we should send 'Sic transit gloria Mundi' here ;-)
370
         */
371
 
372
        *(skb_put(*skb, 1)) = 0;                   /* UTUS.Length = 0;  */
373
 
374
        return 6;
375
}
376
 
377
int capi_disc_resp(struct pcbit_chan *chan, struct sk_buff **skb)
378
{
379
        if ((*skb = dev_alloc_skb(2)) == NULL) {
380
 
381
                printk(KERN_WARNING "capi_disc_resp: alloc_skb failed\n");
382
                return -1;
383
        }
384
 
385
        SET_SKB_FREE((*skb));
386
 
387
        *((ushort*) skb_put(*skb, 2)) = chan->callref;
388
 
389
        return 2;
390
}
391
 
392
 
393
/*
394
 *  Decoding of CAPI messages
395
 *
396
 */
397
 
398
int capi_decode_conn_ind(struct pcbit_chan * chan,
399
                         struct sk_buff *skb,
400
                         struct callb_data *info)
401
{
402
        int CIlen, len;
403
 
404
        /* Call Reference [CAPI] */
405
        chan->callref = *((ushort*) skb->data);
406
        skb_pull(skb, 2);
407
 
408
#ifdef DEBUG
409
        printk(KERN_DEBUG "Call Reference: %04x\n", chan->callref);
410
#endif
411
 
412
        /* Channel Identification */
413
 
414
        /* Expect
415
           Len = 1
416
           Octect 3 = 0100 10CC - [ 7 Basic, 4 , 2-1 chan ]
417
           */
418
 
419
        CIlen = skb->data[0];
420
#ifdef DEBUG
421
        if (CIlen == 1) {
422
 
423
                if ( ((skb->data[1]) & 0xFC) == 0x48 )
424
                        printk(KERN_DEBUG "decode_conn_ind: chan ok\n");
425
                printk(KERN_DEBUG "phyChan = %d\n", skb->data[1] & 0x03);
426
        }
427
        else
428
                printk(KERN_DEBUG "conn_ind: CIlen = %d\n", CIlen);
429
#endif
430
        skb_pull(skb, CIlen + 1);
431
 
432
        /* Calling Party Number */
433
        /* An "additional service" as far as Portugal Telecom is concerned */
434
 
435
        len = skb->data[0];
436
 
437
        if (len > 0) {
438
                int count = 1;
439
 
440
#ifdef DEBUG
441
                printk(KERN_DEBUG "CPN: Octect 3 %02x\n", skb->data[1]);
442
#endif
443
                if ((skb->data[1] & 0x80) == 0)
444
                        count = 2;
445
 
446
                if (!(info->data.setup.CallingPN = kmalloc(len - count + 1, GFP_ATOMIC)))
447
                        return -1;
448
 
449
                memcpy(info->data.setup.CallingPN, skb->data + count + 1,
450
                       len - count);
451
                info->data.setup.CallingPN[len - count] = 0;
452
 
453
        }
454
        else {
455
                info->data.setup.CallingPN = NULL;
456
                printk(KERN_DEBUG "NULL CallingPN\n");
457
        }
458
 
459
        skb_pull(skb, len + 1);
460
 
461
        /* Calling Party Subaddress */
462
        skb_pull(skb, skb->data[0] + 1);
463
 
464
        /* Called Party Number */
465
 
466
        len = skb->data[0];
467
 
468
        if (len > 0) {
469
                int count = 1;
470
 
471
                if ((skb->data[1] & 0x80) == 0)
472
                        count = 2;
473
 
474
                if (!(info->data.setup.CalledPN = kmalloc(len - count + 1, GFP_ATOMIC)))
475
                        return -1;
476
 
477
                memcpy(info->data.setup.CalledPN, skb->data + count + 1,
478
                       len - count);
479
                info->data.setup.CalledPN[len - count] = 0;
480
 
481
        }
482
        else {
483
                info->data.setup.CalledPN = NULL;
484
                printk(KERN_DEBUG "NULL CalledPN\n");
485
        }
486
 
487
        skb_pull(skb, len + 1);
488
 
489
        /* Called Party Subaddress */
490
        skb_pull(skb, skb->data[0] + 1);
491
 
492
        /* LLC */
493
        skb_pull(skb, skb->data[0] + 1);
494
 
495
        /* HLC */
496
        skb_pull(skb, skb->data[0] + 1);
497
 
498
        /* U2U */
499
        skb_pull(skb, skb->data[0] + 1);
500
 
501
        return 0;
502
}
503
 
504
/*
505
 *  returns errcode
506
 */
507
 
508
int capi_decode_conn_conf(struct pcbit_chan * chan, struct sk_buff *skb,
509
                          int *complete)
510
{
511
        int errcode;
512
 
513
        chan->callref = *((ushort *) skb->data);     /* Update CallReference */
514
        skb_pull(skb, 2);
515
 
516
        errcode = *((ushort *) skb->data);   /* read errcode */
517
        skb_pull(skb, 2);
518
 
519
        *complete = *(skb->data);
520
        skb_pull(skb, 1);
521
 
522
        /* FIX ME */
523
        /* This is actually a firmware bug */
524
        if (!*complete)
525
        {
526
                printk(KERN_DEBUG "complete=%02x\n", *complete);
527
                *complete = 1;
528
        }
529
 
530
 
531
        /* Optional Bearer Capability */
532
        skb_pull(skb, *(skb->data) + 1);
533
 
534
        /* Channel Identification */
535
        skb_pull(skb, *(skb->data) + 1);
536
 
537
        /* High Layer Compatibility follows */
538
        skb_pull(skb, *(skb->data) + 1);
539
 
540
        return errcode;
541
}
542
 
543
int capi_decode_conn_actv_ind(struct pcbit_chan * chan, struct sk_buff *skb)
544
{
545
        ushort len;
546
#ifdef DEBUG
547
        char str[32];
548
#endif
549
 
550
        /* Yet Another Bearer Capability */
551
        skb_pull(skb, *(skb->data) + 1);
552
 
553
 
554
        /* Connected Party Number */
555
        len=*(skb->data);
556
 
557
#ifdef DEBUG
558
        if (len > 1 && len < 31) {
559
                memcpy(str, skb->data + 2, len - 1);
560
                str[len] = 0;
561
                printk(KERN_DEBUG "Connected Party Number: %s\n", str);
562
        }
563
        else
564
                printk(KERN_DEBUG "actv_ind CPN len = %d\n", len);
565
#endif
566
 
567
        skb_pull(skb, len + 1);
568
 
569
        /* Connected Subaddress */
570
        skb_pull(skb, *(skb->data) + 1);
571
 
572
        /* Low Layer Capability */
573
        skb_pull(skb, *(skb->data) + 1);
574
 
575
        /* High Layer Capability */
576
        skb_pull(skb, *(skb->data) + 1);
577
 
578
        return 0;
579
}
580
 
581
int capi_decode_conn_actv_conf(struct pcbit_chan * chan, struct sk_buff *skb)
582
{
583
        ushort errcode;
584
 
585
        errcode = *((ushort*) skb->data);
586
        skb_pull(skb, 2);
587
 
588
        /* Channel Identification
589
        skb_pull(skb, skb->data[0] + 1);
590
        */
591
        return errcode;
592
}
593
 
594
 
595
int capi_decode_sel_proto_conf(struct pcbit_chan *chan, struct sk_buff *skb)
596
{
597
        ushort errcode;
598
 
599
        chan->layer2link = *(skb->data);
600
        skb_pull(skb, 1);
601
 
602
        errcode = *((ushort*) skb->data);
603
        skb_pull(skb, 2);
604
 
605
        return errcode;
606
}
607
 
608
int capi_decode_actv_trans_conf(struct pcbit_chan *chan, struct sk_buff *skb)
609
{
610
        ushort errcode;
611
 
612
        if (chan->layer2link != *(skb->data) )
613
                printk("capi_decode_actv_trans_conf: layer2link doesn't match\n");
614
 
615
        skb_pull(skb, 1);
616
 
617
        errcode = *((ushort*) skb->data);
618
        skb_pull(skb, 2);
619
 
620
        return errcode;
621
}
622
 
623
int capi_decode_disc_ind(struct pcbit_chan *chan, struct sk_buff *skb)
624
{
625
        ushort len;
626
#ifdef DEBUG
627
        int i;
628
#endif
629
        /* Cause */
630
 
631
        len = *(skb->data);
632
        skb_pull(skb, 1);
633
 
634
#ifdef DEBUG
635
 
636
        for (i=0; i<len; i++)
637
                printk(KERN_DEBUG "Cause Octect %d: %02x\n", i+3,
638
                       *(skb->data + i));
639
#endif
640
 
641
        skb_pull(skb, len);
642
 
643
        return 0;
644
}
645
 
646
int capi_decode_disc_conf(struct pcbit_chan *chan, struct sk_buff *skb)
647
{
648
        ushort errcode;
649
 
650
        errcode = *((ushort*) skb->data);
651
        skb_pull(skb, 2);
652
 
653
        return errcode;
654
}
655
 
656
#ifdef DEBUG
657
int capi_decode_debug_188(u_char *hdr, ushort hdrlen)
658
{
659
        char str[64];
660
        int len;
661
 
662
        len = hdr[0];
663
 
664
        if (len < 64 && len == hdrlen - 1) {
665
                memcpy(str, hdr + 1, hdrlen - 1);
666
                str[hdrlen - 1] = 0;
667
                printk("%s\n", str);
668
        }
669
        else
670
                printk("debug message incorrect\n");
671
 
672
        return 0;
673
}
674
#endif
675
 
676
 
677
 
678
 
679
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.