aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/isdn/i4l
diff options
context:
space:
mode:
authorKarsten Keil <keil@b1-systems.de>2009-07-08 14:31:42 -0400
committerKarsten Keil <keil@b1-systems.de>2009-07-25 14:16:01 -0400
commitc38fc3bc2ecddd4f5278131603e6964cbed071b2 (patch)
tree3821cf2fc6226375bbbf8c338316eef33f5b899d /drivers/isdn/i4l
parent6bd4bcd3cd8affc09eaee7efbc037f65f4a71501 (diff)
ISDN: Add support for none reverse bitstreams to isdnhdc
The original isdnhdlc code was developed for devices which had reversed bitorder in the byte stream. Adding code to handle normal bitstreams as well. Signed-off-by: Karsten Keil <keil@b1-systems.de>
Diffstat (limited to 'drivers/isdn/i4l')
-rw-r--r--drivers/isdn/i4l/isdnhdlc.c70
1 files changed, 35 insertions, 35 deletions
diff --git a/drivers/isdn/i4l/isdnhdlc.c b/drivers/isdn/i4l/isdnhdlc.c
index b80e55ab8914..df345ce73f48 100644
--- a/drivers/isdn/i4l/isdnhdlc.c
+++ b/drivers/isdn/i4l/isdnhdlc.c
@@ -2,6 +2,7 @@
2 * isdnhdlc.c -- General purpose ISDN HDLC decoder. 2 * isdnhdlc.c -- General purpose ISDN HDLC decoder.
3 * 3 *
4 * Copyright (C) 4 * Copyright (C)
5 * 2009 Karsten Keil <keil@b1-systems.de>
5 * 2002 Wolfgang Mües <wolfgang@iksw-muees.de> 6 * 2002 Wolfgang Mües <wolfgang@iksw-muees.de>
6 * 2001 Frode Isaksen <fisaksen@bewan.com> 7 * 2001 Frode Isaksen <fisaksen@bewan.com>
7 * 2001 Kai Germaschewski <kai.germaschewski@gmx.de> 8 * 2001 Kai Germaschewski <kai.germaschewski@gmx.de>
@@ -25,6 +26,7 @@
25#include <linux/init.h> 26#include <linux/init.h>
26#include <linux/crc-ccitt.h> 27#include <linux/crc-ccitt.h>
27#include <linux/isdn/hdlc.h> 28#include <linux/isdn/hdlc.h>
29#include <linux/bitrev.h>
28 30
29/*-------------------------------------------------------------------*/ 31/*-------------------------------------------------------------------*/
30 32
@@ -48,35 +50,21 @@ enum {
48 HDLC_SENDFLAG_B1A6, HDLC_SENDFLAG_B7, STOPPED 50 HDLC_SENDFLAG_B1A6, HDLC_SENDFLAG_B7, STOPPED
49}; 51};
50 52
51void isdnhdlc_rcv_init(struct isdnhdlc_vars *hdlc, int do_adapt56) 53void isdnhdlc_rcv_init(struct isdnhdlc_vars *hdlc, u32 features)
52{ 54{
53 hdlc->bit_shift = 0; 55 memset(hdlc, 0, sizeof(struct isdnhdlc_vars));
54 hdlc->hdlc_bits1 = 0;
55 hdlc->data_bits = 0;
56 hdlc->ffbit_shift = 0;
57 hdlc->data_received = 0;
58 hdlc->state = HDLC_GET_DATA; 56 hdlc->state = HDLC_GET_DATA;
59 hdlc->do_adapt56 = do_adapt56; 57 if (features & HDLC_56KBIT)
60 hdlc->dchannel = 0; 58 hdlc->do_adapt56 = 1;
61 hdlc->crc = 0; 59 if (features & HDLC_BITREVERSE)
62 hdlc->cbin = 0; 60 hdlc->do_bitreverse = 1;
63 hdlc->shift_reg = 0;
64 hdlc->ffvalue = 0;
65 hdlc->dstpos = 0;
66} 61}
67EXPORT_SYMBOL(isdnhdlc_out_init); 62EXPORT_SYMBOL(isdnhdlc_out_init);
68 63
69void isdnhdlc_out_init(struct isdnhdlc_vars *hdlc, int is_d_channel, 64void isdnhdlc_out_init(struct isdnhdlc_vars *hdlc, u32 features)
70 int do_adapt56)
71{ 65{
72 hdlc->bit_shift = 0; 66 memset(hdlc, 0, sizeof(struct isdnhdlc_vars));
73 hdlc->hdlc_bits1 = 0; 67 if (features & HDLC_DCHANNEL) {
74 hdlc->data_bits = 0;
75 hdlc->ffbit_shift = 0;
76 hdlc->data_received = 0;
77 hdlc->do_closing = 0;
78 hdlc->ffvalue = 0;
79 if (is_d_channel) {
80 hdlc->dchannel = 1; 68 hdlc->dchannel = 1;
81 hdlc->state = HDLC_SEND_FIRST_FLAG; 69 hdlc->state = HDLC_SEND_FIRST_FLAG;
82 } else { 70 } else {
@@ -85,16 +73,13 @@ void isdnhdlc_out_init(struct isdnhdlc_vars *hdlc, int is_d_channel,
85 hdlc->ffvalue = 0x7e; 73 hdlc->ffvalue = 0x7e;
86 } 74 }
87 hdlc->cbin = 0x7e; 75 hdlc->cbin = 0x7e;
88 hdlc->bit_shift = 0; 76 if (features & HDLC_56KBIT) {
89 if (do_adapt56) {
90 hdlc->do_adapt56 = 1; 77 hdlc->do_adapt56 = 1;
91 hdlc->data_bits = 0;
92 hdlc->state = HDLC_SENDFLAG_B0; 78 hdlc->state = HDLC_SENDFLAG_B0;
93 } else { 79 } else
94 hdlc->do_adapt56 = 0;
95 hdlc->data_bits = 8; 80 hdlc->data_bits = 8;
96 } 81 if (features & HDLC_BITREVERSE)
97 hdlc->shift_reg = 0; 82 hdlc->do_bitreverse = 1;
98} 83}
99EXPORT_SYMBOL(isdnhdlc_rcv_init); 84EXPORT_SYMBOL(isdnhdlc_rcv_init);
100 85
@@ -188,7 +173,11 @@ int isdnhdlc_decode(struct isdnhdlc_vars *hdlc, const u8 *src, int slen,
188 173
189 while (slen > 0) { 174 while (slen > 0) {
190 if (hdlc->bit_shift == 0) { 175 if (hdlc->bit_shift == 0) {
191 hdlc->cbin = *src++; 176 /* the code is for bitreverse streams */
177 if (hdlc->do_bitreverse == 0)
178 hdlc->cbin = bitrev8(*src++);
179 else
180 hdlc->cbin = *src++;
192 slen--; 181 slen--;
193 hdlc->bit_shift = 8; 182 hdlc->bit_shift = 8;
194 if (hdlc->do_adapt56) 183 if (hdlc->do_adapt56)
@@ -405,12 +394,15 @@ int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const u8 *src, u16 slen,
405 case STOPPED: 394 case STOPPED:
406 while (dsize--) 395 while (dsize--)
407 *dst++ = 0xff; 396 *dst++ = 0xff;
408
409 return dsize; 397 return dsize;
410 case HDLC_SEND_FAST_FLAG: 398 case HDLC_SEND_FAST_FLAG:
411 hdlc->do_closing = 0; 399 hdlc->do_closing = 0;
412 if (slen == 0) { 400 if (slen == 0) {
413 *dst++ = hdlc->ffvalue; 401 /* the code is for bitreverse streams */
402 if (hdlc->do_bitreverse == 0)
403 *dst++ = bitrev8(hdlc->ffvalue);
404 else
405 *dst++ = hdlc->ffvalue;
414 len++; 406 len++;
415 dsize--; 407 dsize--;
416 break; 408 break;
@@ -594,7 +586,11 @@ int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const u8 *src, u16 slen,
594 hdlc->cbin = 0x7e; 586 hdlc->cbin = 0x7e;
595 hdlc->state = HDLC_SEND_FIRST_FLAG; 587 hdlc->state = HDLC_SEND_FIRST_FLAG;
596 } else { 588 } else {
597 *dst++ = hdlc->cbin; 589 /* the code is for bitreverse streams */
590 if (hdlc->do_bitreverse == 0)
591 *dst++ = bitrev8(hdlc->cbin);
592 else
593 *dst++ = hdlc->cbin;
598 hdlc->bit_shift = 0; 594 hdlc->bit_shift = 0;
599 hdlc->data_bits = 0; 595 hdlc->data_bits = 0;
600 len++; 596 len++;
@@ -612,7 +608,11 @@ int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const u8 *src, u16 slen,
612 } 608 }
613 } 609 }
614 if (hdlc->data_bits == 8) { 610 if (hdlc->data_bits == 8) {
615 *dst++ = hdlc->cbin; 611 /* the code is for bitreverse streams */
612 if (hdlc->do_bitreverse == 0)
613 *dst++ = bitrev8(hdlc->cbin);
614 else
615 *dst++ = hdlc->cbin;
616 hdlc->data_bits = 0; 616 hdlc->data_bits = 0;
617 len++; 617 len++;
618 dsize--; 618 dsize--;