12 #include <linux/string.h>
13 #include <linux/kernel.h>
14 #include <linux/slab.h>
18 #include <linux/isdn.h>
21 #undef ISDN_V110_DEBUG
25 #define V110_38400 255
33 static unsigned char V110_OnMatrix_9600[] =
34 {0xfc, 0xfc, 0xfc, 0xfc, 0xff, 0xff, 0xff, 0xfd, 0xff, 0xff,
35 0xff, 0xfd, 0xff, 0xff, 0xff, 0xfd, 0xff, 0xff, 0xff, 0xfd,
36 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfd, 0xff, 0xff,
37 0xff, 0xfd, 0xff, 0xff, 0xff, 0xfd, 0xff, 0xff, 0xff, 0xfd};
39 static unsigned char V110_OffMatrix_9600[] =
40 {0xfc, 0xfc, 0xfc, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
41 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
42 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
43 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
45 static unsigned char V110_OnMatrix_19200[] =
46 {0xf0, 0xf0, 0xff, 0xf7, 0xff, 0xf7, 0xff, 0xf7, 0xff, 0xf7,
47 0xfd, 0xff, 0xff, 0xf7, 0xff, 0xf7, 0xff, 0xf7, 0xff, 0xf7};
49 static unsigned char V110_OffMatrix_19200[] =
50 {0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
51 0xfd, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
53 static unsigned char V110_OnMatrix_38400[] =
54 {0x00, 0x7f, 0x7f, 0x7f, 0x7f, 0xfd, 0x7f, 0x7f, 0x7f, 0x7f};
56 static unsigned char V110_OffMatrix_38400[] =
57 {0x00, 0xff, 0xff, 0xff, 0xff, 0xfd, 0xff, 0xff, 0xff, 0xff};
65 static inline unsigned char
66 FlipBits(
unsigned char c,
int keylen)
69 unsigned char bit = 128;
72 int hunks = (8 / keylen);
75 for (i = 0; i < hunks; i++) {
76 for (j = 0; j < keylen; j++) {
78 c |= bit >> (keylen - j - 1);
90 isdn_v110_open(
unsigned char key,
int hdrlen,
int maxsize)
99 for (i = 0; key & (1 <<
i); i++)
139 #ifdef ISDN_V110_DEBUG
171 for (rbuf++, len--; len > 0; len--, rbuf++)
172 if ((*rbuf & v->
key) == 0)
178 #ifdef ISDN_V110_DEBUG
197 unsigned char b = v->
b;
200 if ((line % 10) == 0) {
201 if (m[line] != 0x00) {
202 #ifdef ISDN_V110_DEBUG
209 }
else if ((line % 10) == 5) {
210 if ((m[line] & 0x70) != 0x30) {
211 #ifdef ISDN_V110_DEBUG
218 }
else if (!introducer) {
219 introducer = (m[line] & mbit) ? 0 : 1;
260 unsigned char *v110_buf;
276 for (; len > 0; len--, rbuf++)
277 if ((*rbuf & v->
key) == 0)
291 if (ValidHeaderBytes(v) != v->
nbytes) {
301 for (i = 0; i <
len; i++) {
303 for (j = 0; j < v->
nbytes; j++)
305 v110_buf[
i] = FlipBits(v110_buf[i], v->
nbits);
310 skb_trim(skb, DecodeMatrix(v, v110_buf, len, skb->
data));
325 EncodeMatrix(
unsigned char *buf,
int len,
unsigned char *m,
int mlen)
332 int ibit[] = {0, 1, 1};
334 while ((i < len) && (line < mlen)) {
364 m[line] |= ibit[introducer] ? mbit : 0;
368 m[line] |= (buf[
i] & dbit) ? mbit : 0;
375 m[line] |= (mbit - 1) & 0xfe;
385 if ((line) && ((line + 10) < mlen))
386 switch (++line % 10) {
423 skb_reserve(skb, v->
skbres);
443 skb_reserve(skb, v->
skbres);
461 unsigned char *v110buf;
476 nframes = (rlen + 3) / 4;
478 if ((nframes * 40) > v->
maxsize) {
483 if (!(nskb = dev_alloc_skb(size + v->
skbres +
sizeof(
int)))) {
487 skb_reserve(nskb, v->
skbres +
sizeof(
int));
490 *((
int *)
skb_push(nskb,
sizeof(
int))) = 0;
493 mlen = EncodeMatrix(skb->
data, rlen, v110buf, size);
497 sval1 = 8 - v->
nbits;
498 sval2 = v->
key << sval1;
499 for (i = 0; i < mlen; i++) {
500 v110buf[
i] = FlipBits(v110buf[i], v->
nbits);
501 for (j = 0; j < v->
nbytes; j++) {
503 *rbuf++ = ~v->
key | (((v110buf[
i] << (j * v->
nbits)) & sval2) >> sval1);
513 *((
int *)
skb_push(nskb,
sizeof(
int))) = rlen;
534 if (!(v =
dev->v110[idx]))
550 skb = isdn_v110_sync(v);
552 skb = isdn_v110_idle(v);
580 if (
dev->v110emu[idx] && (
dev->v110[idx] ==
NULL)) {
581 int hdrlen =
dev->drv[c->
driver]->interface->hl_hdrlen;
582 int maxsize =
dev->drv[c->
driver]->interface->maxbufsize;
584 switch (
dev->v110emu[idx]) {
596 if ((v =
dev->v110[idx])) {
598 struct sk_buff *skb = isdn_v110_sync(v);