ISDN: Clean up isdnhdlc code
Clean up isdnhdlc to meet current code standard. Remove hint to already removed bit reversal table. Signed-off-by: Karsten Keil <keil@b1-systems.de>
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* isdnhdlc.c -- General purpose ISDN HDLC decoder.
|
* isdnhdlc.c -- General purpose ISDN HDLC decoder.
|
||||||
*
|
*
|
||||||
*Copyright (C) 2002 Wolfgang Mües <wolfgang@iksw-muees.de>
|
* Copyright (C)
|
||||||
|
* 2002 Wolfgang Mües <wolfgang@iksw-muees.de>
|
||||||
* 2001 Frode Isaksen <fisaksen@bewan.com>
|
* 2001 Frode Isaksen <fisaksen@bewan.com>
|
||||||
* 2001 Kai Germaschewski <kai.germaschewski@gmx.de>
|
* 2001 Kai Germaschewski <kai.germaschewski@gmx.de>
|
||||||
*
|
*
|
||||||
@@ -63,8 +64,10 @@ void isdnhdlc_rcv_init (struct isdnhdlc_vars *hdlc, int do_adapt56)
|
|||||||
hdlc->ffvalue = 0;
|
hdlc->ffvalue = 0;
|
||||||
hdlc->dstpos = 0;
|
hdlc->dstpos = 0;
|
||||||
}
|
}
|
||||||
|
EXPORT_SYMBOL(isdnhdlc_out_init);
|
||||||
|
|
||||||
void isdnhdlc_out_init (struct isdnhdlc_vars *hdlc, int is_d_channel, int do_adapt56)
|
void isdnhdlc_out_init(struct isdnhdlc_vars *hdlc, int is_d_channel,
|
||||||
|
int do_adapt56)
|
||||||
{
|
{
|
||||||
hdlc->bit_shift = 0;
|
hdlc->bit_shift = 0;
|
||||||
hdlc->hdlc_bits1 = 0;
|
hdlc->hdlc_bits1 = 0;
|
||||||
@@ -93,6 +96,25 @@ void isdnhdlc_out_init (struct isdnhdlc_vars *hdlc, int is_d_channel, int do_ada
|
|||||||
}
|
}
|
||||||
hdlc->shift_reg = 0;
|
hdlc->shift_reg = 0;
|
||||||
}
|
}
|
||||||
|
EXPORT_SYMBOL(isdnhdlc_rcv_init);
|
||||||
|
|
||||||
|
static int
|
||||||
|
check_frame(struct isdnhdlc_vars *hdlc)
|
||||||
|
{
|
||||||
|
int status;
|
||||||
|
|
||||||
|
if (hdlc->dstpos < 2) /* too small - framing error */
|
||||||
|
status = -HDLC_FRAMING_ERROR;
|
||||||
|
else if (hdlc->crc != 0xf0b8) /* crc error */
|
||||||
|
status = -HDLC_CRC_ERROR;
|
||||||
|
else {
|
||||||
|
/* remove CRC */
|
||||||
|
hdlc->dstpos -= 2;
|
||||||
|
/* good frame */
|
||||||
|
status = hdlc->dstpos;
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
isdnhdlc_decode - decodes HDLC frames from a transparent bit stream.
|
isdnhdlc_decode - decodes HDLC frames from a transparent bit stream.
|
||||||
@@ -121,8 +143,8 @@ void isdnhdlc_out_init (struct isdnhdlc_vars *hdlc, int is_d_channel, int do_ada
|
|||||||
returns - number of decoded bytes in the destination buffer and status
|
returns - number of decoded bytes in the destination buffer and status
|
||||||
flag.
|
flag.
|
||||||
*/
|
*/
|
||||||
int isdnhdlc_decode (struct isdnhdlc_vars *hdlc, const unsigned char *src,
|
int isdnhdlc_decode(struct isdnhdlc_vars *hdlc, const u8 *src, int slen,
|
||||||
int slen, int *count, unsigned char *dst, int dsize)
|
int *count, u8 *dst, int dsize)
|
||||||
{
|
{
|
||||||
int status = 0;
|
int status = 0;
|
||||||
|
|
||||||
@@ -138,6 +160,30 @@ int isdnhdlc_decode (struct isdnhdlc_vars *hdlc, const unsigned char *src,
|
|||||||
0x00, 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff
|
0x00, 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define handle_fast_flag(h) \
|
||||||
|
do {\
|
||||||
|
if (h->cbin == fast_flag[h->bit_shift]) {\
|
||||||
|
h->ffvalue = fast_flag_value[h->bit_shift];\
|
||||||
|
h->state = HDLC_FAST_FLAG;\
|
||||||
|
h->ffbit_shift = h->bit_shift;\
|
||||||
|
h->bit_shift = 1;\
|
||||||
|
} else {\
|
||||||
|
h->state = HDLC_GET_DATA;\
|
||||||
|
h->data_received = 0;\
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define handle_abort(h) \
|
||||||
|
do {\
|
||||||
|
h->shift_reg = fast_abort[h->ffbit_shift - 1];\
|
||||||
|
h->hdlc_bits1 = h->ffbit_shift - 2;\
|
||||||
|
if (h->hdlc_bits1 < 0)\
|
||||||
|
h->hdlc_bits1 = 0;\
|
||||||
|
h->data_bits = h->ffbit_shift - 1;\
|
||||||
|
h->state = HDLC_GET_DATA;\
|
||||||
|
h->data_received = 0;\
|
||||||
|
} while (0)
|
||||||
|
|
||||||
*count = slen;
|
*count = slen;
|
||||||
|
|
||||||
while (slen > 0) {
|
while (slen > 0) {
|
||||||
@@ -145,10 +191,9 @@ int isdnhdlc_decode (struct isdnhdlc_vars *hdlc, const unsigned char *src,
|
|||||||
hdlc->cbin = *src++;
|
hdlc->cbin = *src++;
|
||||||
slen--;
|
slen--;
|
||||||
hdlc->bit_shift = 8;
|
hdlc->bit_shift = 8;
|
||||||
if(hdlc->do_adapt56){
|
if (hdlc->do_adapt56)
|
||||||
hdlc->bit_shift--;
|
hdlc->bit_shift--;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
switch (hdlc->state) {
|
switch (hdlc->state) {
|
||||||
case STOPPED:
|
case STOPPED:
|
||||||
@@ -167,23 +212,21 @@ int isdnhdlc_decode (struct isdnhdlc_vars *hdlc, const unsigned char *src,
|
|||||||
hdlc->state = HDLC_GETFLAG_B1A6;
|
hdlc->state = HDLC_GETFLAG_B1A6;
|
||||||
hdlc->hdlc_bits1 = 0;
|
hdlc->hdlc_bits1 = 0;
|
||||||
} else {
|
} else {
|
||||||
if(!hdlc->do_adapt56){
|
if ((!hdlc->do_adapt56) &&
|
||||||
if(++hdlc->hdlc_bits1 >=8 ) if(hdlc->bit_shift==1)
|
(++hdlc->hdlc_bits1 >= 8) &&
|
||||||
|
(hdlc->bit_shift == 1))
|
||||||
hdlc->state = HDLC_FAST_IDLE;
|
hdlc->state = HDLC_FAST_IDLE;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
hdlc->cbin <<= 1;
|
hdlc->cbin <<= 1;
|
||||||
hdlc->bit_shift--;
|
hdlc->bit_shift--;
|
||||||
break;
|
break;
|
||||||
case HDLC_GETFLAG_B1A6:
|
case HDLC_GETFLAG_B1A6:
|
||||||
if (hdlc->cbin & 0x80) {
|
if (hdlc->cbin & 0x80) {
|
||||||
hdlc->hdlc_bits1++;
|
hdlc->hdlc_bits1++;
|
||||||
if(hdlc->hdlc_bits1==6){
|
if (hdlc->hdlc_bits1 == 6)
|
||||||
hdlc->state = HDLC_GETFLAG_B7;
|
hdlc->state = HDLC_GETFLAG_B7;
|
||||||
}
|
} else
|
||||||
} else {
|
|
||||||
hdlc->hdlc_bits1 = 0;
|
hdlc->hdlc_bits1 = 0;
|
||||||
}
|
|
||||||
hdlc->cbin <<= 1;
|
hdlc->cbin <<= 1;
|
||||||
hdlc->bit_shift--;
|
hdlc->bit_shift--;
|
||||||
break;
|
break;
|
||||||
@@ -208,19 +251,19 @@ int isdnhdlc_decode (struct isdnhdlc_vars *hdlc, const unsigned char *src,
|
|||||||
case 6:
|
case 6:
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
if(hdlc->data_received) {
|
if (hdlc->data_received)
|
||||||
// bad frame
|
/* bad frame */
|
||||||
status = -HDLC_FRAMING_ERROR;
|
status = -HDLC_FRAMING_ERROR;
|
||||||
}
|
|
||||||
if (!hdlc->do_adapt56) {
|
if (!hdlc->do_adapt56) {
|
||||||
if(hdlc->cbin==fast_abort[hdlc->bit_shift+1]){
|
if (hdlc->cbin == fast_abort
|
||||||
hdlc->state = HDLC_FAST_IDLE;
|
[hdlc->bit_shift + 1]) {
|
||||||
|
hdlc->state =
|
||||||
|
HDLC_FAST_IDLE;
|
||||||
hdlc->bit_shift = 1;
|
hdlc->bit_shift = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else
|
||||||
hdlc->state = HDLC_GET_FLAG_B0;
|
hdlc->state = HDLC_GET_FLAG_B0;
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
hdlc->shift_reg >>= 1;
|
hdlc->shift_reg >>= 1;
|
||||||
@@ -233,33 +276,14 @@ int isdnhdlc_decode (struct isdnhdlc_vars *hdlc, const unsigned char *src,
|
|||||||
case 5:
|
case 5:
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
if(hdlc->data_received){
|
if (hdlc->data_received)
|
||||||
if (hdlc->dstpos < 2) {
|
status = check_frame(hdlc);
|
||||||
status = -HDLC_FRAMING_ERROR;
|
|
||||||
} else if (hdlc->crc != 0xf0b8){
|
|
||||||
// crc error
|
|
||||||
status = -HDLC_CRC_ERROR;
|
|
||||||
} else {
|
|
||||||
// remove CRC
|
|
||||||
hdlc->dstpos -= 2;
|
|
||||||
// good frame
|
|
||||||
status = hdlc->dstpos;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
hdlc->crc = 0xffff;
|
hdlc->crc = 0xffff;
|
||||||
hdlc->shift_reg = 0;
|
hdlc->shift_reg = 0;
|
||||||
hdlc->data_bits = 0;
|
hdlc->data_bits = 0;
|
||||||
if(!hdlc->do_adapt56){
|
if (!hdlc->do_adapt56)
|
||||||
if(hdlc->cbin==fast_flag[hdlc->bit_shift]){
|
handle_fast_flag(hdlc);
|
||||||
hdlc->ffvalue = fast_flag_value[hdlc->bit_shift];
|
else {
|
||||||
hdlc->state = HDLC_FAST_FLAG;
|
|
||||||
hdlc->ffbit_shift = hdlc->bit_shift;
|
|
||||||
hdlc->bit_shift = 1;
|
|
||||||
} else {
|
|
||||||
hdlc->state = HDLC_GET_DATA;
|
|
||||||
hdlc->data_received = 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
hdlc->state = HDLC_GET_DATA;
|
hdlc->state = HDLC_GET_DATA;
|
||||||
hdlc->data_received = 0;
|
hdlc->data_received = 0;
|
||||||
}
|
}
|
||||||
@@ -281,13 +305,14 @@ int isdnhdlc_decode (struct isdnhdlc_vars *hdlc, const unsigned char *src,
|
|||||||
if (hdlc->data_bits == 8) {
|
if (hdlc->data_bits == 8) {
|
||||||
hdlc->data_bits = 0;
|
hdlc->data_bits = 0;
|
||||||
hdlc->data_received = 1;
|
hdlc->data_received = 1;
|
||||||
hdlc->crc = crc_ccitt_byte(hdlc->crc, hdlc->shift_reg);
|
hdlc->crc = crc_ccitt_byte(hdlc->crc,
|
||||||
|
hdlc->shift_reg);
|
||||||
|
|
||||||
// good byte received
|
/* good byte received */
|
||||||
if (hdlc->dstpos < dsize) {
|
if (hdlc->dstpos < dsize)
|
||||||
dst[hdlc->dstpos++] = hdlc->shift_reg;
|
dst[hdlc->dstpos++] = hdlc->shift_reg;
|
||||||
} else {
|
else {
|
||||||
// frame too long
|
/* frame too long */
|
||||||
status = -HDLC_LENGTH_ERROR;
|
status = -HDLC_LENGTH_ERROR;
|
||||||
hdlc->dstpos = 0;
|
hdlc->dstpos = 0;
|
||||||
}
|
}
|
||||||
@@ -306,14 +331,8 @@ int isdnhdlc_decode (struct isdnhdlc_vars *hdlc, const unsigned char *src,
|
|||||||
} else if (hdlc->ffbit_shift == 8) {
|
} else if (hdlc->ffbit_shift == 8) {
|
||||||
hdlc->state = HDLC_GETFLAG_B7;
|
hdlc->state = HDLC_GETFLAG_B7;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else
|
||||||
hdlc->shift_reg = fast_abort[hdlc->ffbit_shift-1];
|
handle_abort(hdlc);
|
||||||
hdlc->hdlc_bits1 = hdlc->ffbit_shift-2;
|
|
||||||
if(hdlc->hdlc_bits1<0)hdlc->hdlc_bits1 = 0;
|
|
||||||
hdlc->data_bits = hdlc->ffbit_shift-1;
|
|
||||||
hdlc->state = HDLC_GET_DATA;
|
|
||||||
hdlc->data_received = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -323,7 +342,7 @@ int isdnhdlc_decode (struct isdnhdlc_vars *hdlc, const unsigned char *src,
|
|||||||
*count -= slen;
|
*count -= slen;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
EXPORT_SYMBOL(isdnhdlc_decode);
|
||||||
/*
|
/*
|
||||||
isdnhdlc_encode - encodes HDLC frames to a transparent bit stream.
|
isdnhdlc_encode - encodes HDLC frames to a transparent bit stream.
|
||||||
|
|
||||||
@@ -343,9 +362,8 @@ int isdnhdlc_decode (struct isdnhdlc_vars *hdlc, const unsigned char *src,
|
|||||||
dsize - destination buffer size
|
dsize - destination buffer size
|
||||||
returns - number of encoded bytes in the destination buffer
|
returns - number of encoded bytes in the destination buffer
|
||||||
*/
|
*/
|
||||||
int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const unsigned char *src,
|
int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const u8 *src, u16 slen,
|
||||||
unsigned short slen, int *count,
|
int *count, u8 *dst, int dsize)
|
||||||
unsigned char *dst, int dsize)
|
|
||||||
{
|
{
|
||||||
static const unsigned char xfast_flag_value[] = {
|
static const unsigned char xfast_flag_value[] = {
|
||||||
0x7e, 0x3f, 0x9f, 0xcf, 0xe7, 0xf3, 0xf9, 0xfc, 0x7e
|
0x7e, 0x3f, 0x9f, 0xcf, 0xe7, 0xf3, 0xf9, 0xfc, 0x7e
|
||||||
@@ -361,7 +379,8 @@ int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const unsigned char *src,
|
|||||||
hdlc->shift_reg = *src++;
|
hdlc->shift_reg = *src++;
|
||||||
slen--;
|
slen--;
|
||||||
if (slen == 0)
|
if (slen == 0)
|
||||||
hdlc->do_closing = 1; /* closing sequence, CRC + flag(s) */
|
/* closing sequence, CRC + flag(s) */
|
||||||
|
hdlc->do_closing = 1;
|
||||||
hdlc->bit_shift = 8;
|
hdlc->bit_shift = 8;
|
||||||
} else {
|
} else {
|
||||||
if (hdlc->state == HDLC_SEND_DATA) {
|
if (hdlc->state == HDLC_SEND_DATA) {
|
||||||
@@ -369,12 +388,14 @@ int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const unsigned char *src,
|
|||||||
hdlc->state = HDLC_SEND_CRC1;
|
hdlc->state = HDLC_SEND_CRC1;
|
||||||
hdlc->crc ^= 0xffff;
|
hdlc->crc ^= 0xffff;
|
||||||
hdlc->bit_shift = 8;
|
hdlc->bit_shift = 8;
|
||||||
hdlc->shift_reg = hdlc->crc & 0xff;
|
hdlc->shift_reg =
|
||||||
} else if(!hdlc->do_adapt56){
|
hdlc->crc & 0xff;
|
||||||
hdlc->state = HDLC_SEND_FAST_FLAG;
|
} else if (!hdlc->do_adapt56)
|
||||||
} else {
|
hdlc->state =
|
||||||
hdlc->state = HDLC_SENDFLAG_B0;
|
HDLC_SEND_FAST_FLAG;
|
||||||
}
|
else
|
||||||
|
hdlc->state =
|
||||||
|
HDLC_SENDFLAG_B0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -395,7 +416,8 @@ int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const unsigned char *src,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (hdlc->bit_shift == 8) {
|
if (hdlc->bit_shift == 8) {
|
||||||
hdlc->cbin = hdlc->ffvalue>>(8-hdlc->data_bits);
|
hdlc->cbin = hdlc->ffvalue >>
|
||||||
|
(8 - hdlc->data_bits);
|
||||||
hdlc->state = HDLC_SEND_DATA;
|
hdlc->state = HDLC_SEND_DATA;
|
||||||
hdlc->crc = 0xffff;
|
hdlc->crc = 0xffff;
|
||||||
hdlc->hdlc_bits1 = 0;
|
hdlc->hdlc_bits1 = 0;
|
||||||
@@ -457,9 +479,9 @@ int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const unsigned char *src,
|
|||||||
hdlc->hdlc_bits1 = 0;
|
hdlc->hdlc_bits1 = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(hdlc->bit_shift==8){
|
if (hdlc->bit_shift == 8)
|
||||||
hdlc->crc = crc_ccitt_byte(hdlc->crc, hdlc->shift_reg);
|
hdlc->crc = crc_ccitt_byte(hdlc->crc,
|
||||||
}
|
hdlc->shift_reg);
|
||||||
if (hdlc->shift_reg & 0x01) {
|
if (hdlc->shift_reg & 0x01) {
|
||||||
hdlc->hdlc_bits1++;
|
hdlc->hdlc_bits1++;
|
||||||
hdlc->cbin++;
|
hdlc->cbin++;
|
||||||
@@ -524,29 +546,32 @@ int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const unsigned char *src,
|
|||||||
hdlc->hdlc_bits1 = 0;
|
hdlc->hdlc_bits1 = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(hdlc->shift_reg & 0x01){
|
if (hdlc->shift_reg & 0x01)
|
||||||
hdlc->cbin++;
|
hdlc->cbin++;
|
||||||
}
|
|
||||||
hdlc->shift_reg >>= 1;
|
hdlc->shift_reg >>= 1;
|
||||||
hdlc->bit_shift--;
|
hdlc->bit_shift--;
|
||||||
if (hdlc->bit_shift == 0) {
|
if (hdlc->bit_shift == 0) {
|
||||||
hdlc->ffvalue = xfast_flag_value[hdlc->data_bits];
|
hdlc->ffvalue =
|
||||||
|
xfast_flag_value[hdlc->data_bits];
|
||||||
if (hdlc->dchannel) {
|
if (hdlc->dchannel) {
|
||||||
hdlc->ffvalue = 0x7e;
|
hdlc->ffvalue = 0x7e;
|
||||||
hdlc->state = HDLC_SEND_IDLE1;
|
hdlc->state = HDLC_SEND_IDLE1;
|
||||||
hdlc->bit_shift = 8-hdlc->data_bits;
|
hdlc->bit_shift = 8-hdlc->data_bits;
|
||||||
if (hdlc->bit_shift == 0)
|
if (hdlc->bit_shift == 0)
|
||||||
hdlc->state = HDLC_SEND_FAST_IDLE;
|
hdlc->state =
|
||||||
|
HDLC_SEND_FAST_IDLE;
|
||||||
} else {
|
} else {
|
||||||
if (!hdlc->do_adapt56) {
|
if (!hdlc->do_adapt56) {
|
||||||
hdlc->state = HDLC_SEND_FAST_FLAG;
|
hdlc->state =
|
||||||
|
HDLC_SEND_FAST_FLAG;
|
||||||
hdlc->data_received = 0;
|
hdlc->data_received = 0;
|
||||||
} else {
|
} else {
|
||||||
hdlc->state = HDLC_SENDFLAG_B0;
|
hdlc->state = HDLC_SENDFLAG_B0;
|
||||||
hdlc->data_received = 0;
|
hdlc->data_received = 0;
|
||||||
}
|
}
|
||||||
// Finished with this frame, send flags
|
/* Finished this frame, send flags */
|
||||||
if (dsize > 1) dsize = 1;
|
if (dsize > 1)
|
||||||
|
dsize = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -570,7 +595,8 @@ int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const unsigned char *src,
|
|||||||
hdlc->state = HDLC_SEND_FIRST_FLAG;
|
hdlc->state = HDLC_SEND_FIRST_FLAG;
|
||||||
} else {
|
} else {
|
||||||
*dst++ = hdlc->cbin;
|
*dst++ = hdlc->cbin;
|
||||||
hdlc->bit_shift = hdlc->data_bits = 0;
|
hdlc->bit_shift = 0;
|
||||||
|
hdlc->data_bits = 0;
|
||||||
len++;
|
len++;
|
||||||
dsize = 0;
|
dsize = 0;
|
||||||
}
|
}
|
||||||
@@ -596,8 +622,4 @@ int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const unsigned char *src,
|
|||||||
|
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT_SYMBOL(isdnhdlc_rcv_init);
|
|
||||||
EXPORT_SYMBOL(isdnhdlc_decode);
|
|
||||||
EXPORT_SYMBOL(isdnhdlc_out_init);
|
|
||||||
EXPORT_SYMBOL(isdnhdlc_encode);
|
EXPORT_SYMBOL(isdnhdlc_encode);
|
||||||
|
@@ -1,11 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* isdnhdlc.h -- General purpose ISDN HDLC decoder.
|
* hdlc.h -- General purpose ISDN HDLC decoder.
|
||||||
*
|
*
|
||||||
* Implementation of a HDLC decoder/encoder in software.
|
* Implementation of a HDLC decoder/encoder in software.
|
||||||
* Neccessary because some ISDN devices don't have HDLC
|
* Neccessary because some ISDN devices don't have HDLC
|
||||||
* controllers. Also included: a bit reversal table.
|
* controllers.
|
||||||
*
|
*
|
||||||
*Copyright (C) 2002 Wolfgang Mües <wolfgang@iksw-muees.de>
|
* Copyright (C)
|
||||||
|
* 2002 Wolfgang Mües <wolfgang@iksw-muees.de>
|
||||||
* 2001 Frode Isaksen <fisaksen@bewan.com>
|
* 2001 Frode Isaksen <fisaksen@bewan.com>
|
||||||
* 2001 Kai Germaschewski <kai.germaschewski@gmx.de>
|
* 2001 Kai Germaschewski <kai.germaschewski@gmx.de>
|
||||||
*
|
*
|
||||||
@@ -31,20 +32,24 @@ struct isdnhdlc_vars {
|
|||||||
int bit_shift;
|
int bit_shift;
|
||||||
int hdlc_bits1;
|
int hdlc_bits1;
|
||||||
int data_bits;
|
int data_bits;
|
||||||
int ffbit_shift; // encoding only
|
int ffbit_shift; /* encoding only */
|
||||||
int state;
|
int state;
|
||||||
int dstpos;
|
int dstpos;
|
||||||
|
|
||||||
unsigned short crc;
|
u16 crc;
|
||||||
|
|
||||||
unsigned char cbin;
|
u8 cbin;
|
||||||
unsigned char shift_reg;
|
u8 shift_reg;
|
||||||
unsigned char ffvalue;
|
u8 ffvalue;
|
||||||
|
|
||||||
unsigned int data_received:1; // set if transferring data
|
/* set if transferring data */
|
||||||
unsigned int dchannel:1; // set if D channel (send idle instead of flags)
|
u32 data_received:1;
|
||||||
unsigned int do_adapt56:1; // set if 56K adaptation
|
/* set if D channel (send idle instead of flags) */
|
||||||
unsigned int do_closing:1; // set if in closing phase (need to send CRC + flag
|
u32 dchannel:1;
|
||||||
|
/* set if 56K adaptation */
|
||||||
|
u32 do_adapt56:1;
|
||||||
|
/* set if in closing phase (need to send CRC + flag) */
|
||||||
|
u32 do_closing:1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -59,12 +64,13 @@ struct isdnhdlc_vars {
|
|||||||
|
|
||||||
extern void isdnhdlc_rcv_init(struct isdnhdlc_vars *hdlc, int do_adapt56);
|
extern void isdnhdlc_rcv_init(struct isdnhdlc_vars *hdlc, int do_adapt56);
|
||||||
|
|
||||||
extern int isdnhdlc_decode (struct isdnhdlc_vars *hdlc, const unsigned char *src, int slen,int *count,
|
extern int isdnhdlc_decode(struct isdnhdlc_vars *hdlc, const u8 *src,
|
||||||
unsigned char *dst, int dsize);
|
int slen, int *count, u8 *dst, int dsize);
|
||||||
|
|
||||||
extern void isdnhdlc_out_init (struct isdnhdlc_vars *hdlc,int is_d_channel,int do_adapt56);
|
extern void isdnhdlc_out_init(struct isdnhdlc_vars *hdlc, int is_d_channel,
|
||||||
|
int do_adapt56);
|
||||||
|
|
||||||
extern int isdnhdlc_encode (struct isdnhdlc_vars *hdlc,const unsigned char *src,unsigned short slen,int *count,
|
extern int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const u8 *src,
|
||||||
unsigned char *dst,int dsize);
|
u16 slen, int *count, u8 *dst, int dsize);
|
||||||
|
|
||||||
#endif /* __ISDNHDLC_H__ */
|
#endif /* __ISDNHDLC_H__ */
|
||||||
|
Reference in New Issue
Block a user