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>
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}
6762EXPORT_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}
9984EXPORT_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 -- ;
0 commit comments