Skip to content

Commit c38fc3b

Browse files
author
Karsten Keil
committed
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>
1 parent 6bd4bcd commit c38fc3b

5 files changed

Lines changed: 56 additions & 44 deletions

File tree

‎drivers/isdn/hisax/st5481_b.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,10 @@ static void st5481B_mode(struct st5481_bcs *bcs, int mode)
218218
if (bcs->mode != L1_MODE_NULL) {
219219
// Open the B channel
220220
if (bcs->mode != L1_MODE_TRANS) {
221-
isdnhdlc_out_init(&b_out->hdlc_state, 0, bcs->mode == L1_MODE_HDLC_56K);
221+
u32 features = HDLC_BITREVERSE;
222+
if (bcs->mode == L1_MODE_HDLC_56K)
223+
features |= HDLC_56KBIT;
224+
isdnhdlc_out_init(&b_out->hdlc_state, features);
222225
}
223226
st5481_usb_pipe_reset(adapter, (bcs->channel+1)*2, NULL, NULL);
224227

‎drivers/isdn/hisax/st5481_d.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ static void dout_start_xmit(struct FsmInst *fsm, int event, void *arg)
417417

418418
DBG(2,"len=%d",skb->len);
419419

420-
isdnhdlc_out_init(&d_out->hdlc_state, 1, 0);
420+
isdnhdlc_out_init(&d_out->hdlc_state, HDLC_DCHANNEL | HDLC_BITREVERSE);
421421

422422
if (test_and_set_bit(buf_nr, &d_out->busy)) {
423423
WARNING("ep %d urb %d busy %#lx", EP_D_OUT, buf_nr, d_out->busy);

‎drivers/isdn/hisax/st5481_usb.c‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -637,10 +637,13 @@ void st5481_in_mode(struct st5481_in *in, int mode)
637637
usb_unlink_urb(in->urb[1]);
638638

639639
if (in->mode != L1_MODE_NULL) {
640-
if (in->mode != L1_MODE_TRANS)
641-
isdnhdlc_rcv_init(&in->hdlc_state,
642-
in->mode == L1_MODE_HDLC_56K);
643-
640+
if (in->mode != L1_MODE_TRANS) {
641+
u32 features = HDLC_BITREVERSE;
642+
643+
if (in->mode == L1_MODE_HDLC_56K)
644+
features |= HDLC_56KBIT;
645+
isdnhdlc_rcv_init(&in->hdlc_state, features);
646+
}
644647
st5481_usb_pipe_reset(in->adapter, in->ep, NULL, NULL);
645648
st5481_usb_device_ctrl_msg(in->adapter, in->counter,
646649
in->packet_size,

‎drivers/isdn/i4l/isdnhdlc.c‎

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* isdnhdlc.c -- General purpose ISDN HDLC decoder.
33
*
44
* Copyright (C)
5+
* 2009 Karsten Keil <keil@b1-systems.de>
56
* 2002 Wolfgang Mües <wolfgang@iksw-muees.de>
67
* 2001 Frode Isaksen <fisaksen@bewan.com>
78
* 2001 Kai Germaschewski <kai.germaschewski@gmx.de>
@@ -25,6 +26,7 @@
2526
#include <linux/init.h>
2627
#include <linux/crc-ccitt.h>
2728
#include <linux/isdn/hdlc.h>
29+
#include <linux/bitrev.h>
2830

2931
/*-------------------------------------------------------------------*/
3032

@@ -48,35 +50,21 @@ enum {
4850
HDLC_SENDFLAG_B1A6, HDLC_SENDFLAG_B7, STOPPED
4951
};
5052

51-
void isdnhdlc_rcv_init(struct isdnhdlc_vars *hdlc, int do_adapt56)
53+
void isdnhdlc_rcv_init(struct isdnhdlc_vars *hdlc, u32 features)
5254
{
53-
hdlc->bit_shift = 0;
54-
hdlc->hdlc_bits1 = 0;
55-
hdlc->data_bits = 0;
56-
hdlc->ffbit_shift = 0;
57-
hdlc->data_received = 0;
55+
memset(hdlc, 0, sizeof(struct isdnhdlc_vars));
5856
hdlc->state = HDLC_GET_DATA;
59-
hdlc->do_adapt56 = do_adapt56;
60-
hdlc->dchannel = 0;
61-
hdlc->crc = 0;
62-
hdlc->cbin = 0;
63-
hdlc->shift_reg = 0;
64-
hdlc->ffvalue = 0;
65-
hdlc->dstpos = 0;
57+
if (features & HDLC_56KBIT)
58+
hdlc->do_adapt56 = 1;
59+
if (features & HDLC_BITREVERSE)
60+
hdlc->do_bitreverse = 1;
6661
}
6762
EXPORT_SYMBOL(isdnhdlc_out_init);
6863

69-
void isdnhdlc_out_init(struct isdnhdlc_vars *hdlc, int is_d_channel,
70-
int do_adapt56)
64+
void isdnhdlc_out_init(struct isdnhdlc_vars *hdlc, u32 features)
7165
{
72-
hdlc->bit_shift = 0;
73-
hdlc->hdlc_bits1 = 0;
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) {
66+
memset(hdlc, 0, sizeof(struct isdnhdlc_vars));
67+
if (features & HDLC_DCHANNEL) {
8068
hdlc->dchannel = 1;
8169
hdlc->state = HDLC_SEND_FIRST_FLAG;
8270
} else {
@@ -85,16 +73,13 @@ void isdnhdlc_out_init(struct isdnhdlc_vars *hdlc, int is_d_channel,
8573
hdlc->ffvalue = 0x7e;
8674
}
8775
hdlc->cbin = 0x7e;
88-
hdlc->bit_shift = 0;
89-
if (do_adapt56) {
76+
if (features & HDLC_56KBIT) {
9077
hdlc->do_adapt56 = 1;
91-
hdlc->data_bits = 0;
9278
hdlc->state = HDLC_SENDFLAG_B0;
93-
} else {
94-
hdlc->do_adapt56 = 0;
79+
} else
9580
hdlc->data_bits = 8;
96-
}
97-
hdlc->shift_reg = 0;
81+
if (features & HDLC_BITREVERSE)
82+
hdlc->do_bitreverse = 1;
9883
}
9984
EXPORT_SYMBOL(isdnhdlc_rcv_init);
10085

@@ -188,7 +173,11 @@ int isdnhdlc_decode(struct isdnhdlc_vars *hdlc, const u8 *src, int slen,
188173

189174
while (slen > 0) {
190175
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++;
192181
slen--;
193182
hdlc->bit_shift = 8;
194183
if (hdlc->do_adapt56)
@@ -405,12 +394,15 @@ int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const u8 *src, u16 slen,
405394
case STOPPED:
406395
while (dsize--)
407396
*dst++ = 0xff;
408-
409397
return dsize;
410398
case HDLC_SEND_FAST_FLAG:
411399
hdlc->do_closing = 0;
412400
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;
414406
len++;
415407
dsize--;
416408
break;
@@ -594,7 +586,11 @@ int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const u8 *src, u16 slen,
594586
hdlc->cbin = 0x7e;
595587
hdlc->state = HDLC_SEND_FIRST_FLAG;
596588
} 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;
598594
hdlc->bit_shift = 0;
599595
hdlc->data_bits = 0;
600596
len++;
@@ -612,7 +608,11 @@ int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const u8 *src, u16 slen,
612608
}
613609
}
614610
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;
616616
hdlc->data_bits = 0;
617617
len++;
618618
dsize--;

‎include/linux/isdn/hdlc.h‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* controllers.
77
*
88
* Copyright (C)
9+
* 2009 Karsten Keil <keil@b1-systems.de>
910
* 2002 Wolfgang Mües <wolfgang@iksw-muees.de>
1011
* 2001 Frode Isaksen <fisaksen@bewan.com>
1112
* 2001 Kai Germaschewski <kai.germaschewski@gmx.de>
@@ -50,8 +51,14 @@ struct isdnhdlc_vars {
5051
u32 do_adapt56:1;
5152
/* set if in closing phase (need to send CRC + flag) */
5253
u32 do_closing:1;
54+
/* set if data is bitreverse */
55+
u32 do_bitreverse:1;
5356
};
5457

58+
/* Feature Flags */
59+
#define HDLC_56KBIT 0x01
60+
#define HDLC_DCHANNEL 0x02
61+
#define HDLC_BITREVERSE 0x04
5562

5663
/*
5764
The return value from isdnhdlc_decode is
@@ -62,13 +69,12 @@ struct isdnhdlc_vars {
6269
#define HDLC_CRC_ERROR 2
6370
#define HDLC_LENGTH_ERROR 3
6471

65-
extern void isdnhdlc_rcv_init(struct isdnhdlc_vars *hdlc, int do_adapt56);
72+
extern void isdnhdlc_rcv_init(struct isdnhdlc_vars *hdlc, u32 features);
6673

6774
extern int isdnhdlc_decode(struct isdnhdlc_vars *hdlc, const u8 *src,
6875
int slen, int *count, u8 *dst, int dsize);
6976

70-
extern void isdnhdlc_out_init(struct isdnhdlc_vars *hdlc, int is_d_channel,
71-
int do_adapt56);
77+
extern void isdnhdlc_out_init(struct isdnhdlc_vars *hdlc, u32 features);
7278

7379
extern int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const u8 *src,
7480
u16 slen, int *count, u8 *dst, int dsize);

0 commit comments

Comments
 (0)