2018-05-11 15:36:13 +00:00
|
|
|
/*
|
2018-05-11 15:39:21 +00:00
|
|
|
* isdnhdlc.h -- General purpose ISDN HDLC decoder.
|
2018-05-11 15:36:13 +00:00
|
|
|
*
|
|
|
|
* Implementation of a HDLC decoder/encoder in software.
|
|
|
|
* Necessary because some ISDN devices don't have HDLC
|
|
|
|
* controllers.
|
|
|
|
*
|
|
|
|
* Copyright (C)
|
|
|
|
* 2009 Karsten Keil <keil@b1-systems.de>
|
|
|
|
* 2002 Wolfgang Mües <wolfgang@iksw-muees.de>
|
|
|
|
* 2001 Frode Isaksen <fisaksen@bewan.com>
|
|
|
|
* 2001 Kai Germaschewski <kai.germaschewski@gmx.de>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
2022-09-28 16:51:42 +00:00
|
|
|
#pragma once
|
2018-05-11 15:36:13 +00:00
|
|
|
|
2018-05-11 15:39:21 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
struct osmo_isdnhdlc_vars {
|
2018-05-11 15:36:13 +00:00
|
|
|
int bit_shift;
|
|
|
|
int hdlc_bits1;
|
|
|
|
int data_bits;
|
|
|
|
int ffbit_shift; /* encoding only */
|
|
|
|
int state;
|
|
|
|
int dstpos;
|
|
|
|
|
2018-05-11 15:39:21 +00:00
|
|
|
uint16_t crc;
|
2018-05-11 15:36:13 +00:00
|
|
|
|
2018-05-11 15:39:21 +00:00
|
|
|
uint8_t cbin;
|
|
|
|
uint8_t shift_reg;
|
|
|
|
uint8_t ffvalue;
|
2018-05-11 15:36:13 +00:00
|
|
|
|
|
|
|
/* set if transferring data */
|
2018-05-11 15:39:21 +00:00
|
|
|
uint32_t data_received:1;
|
2018-05-11 15:36:13 +00:00
|
|
|
/* set if D channel (send idle instead of flags) */
|
2018-05-11 15:39:21 +00:00
|
|
|
uint32_t dchannel:1;
|
2018-05-11 15:36:13 +00:00
|
|
|
/* set if 56K adaptation */
|
2018-05-11 15:39:21 +00:00
|
|
|
uint32_t do_adapt56:1;
|
2018-05-11 15:36:13 +00:00
|
|
|
/* set if in closing phase (need to send CRC + flag) */
|
2018-05-11 15:39:21 +00:00
|
|
|
uint32_t do_closing:1;
|
2018-05-11 15:36:13 +00:00
|
|
|
/* set if data is bitreverse */
|
2018-05-11 15:39:21 +00:00
|
|
|
uint32_t do_bitreverse:1;
|
2018-05-11 15:36:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Feature Flags */
|
2018-05-11 15:39:21 +00:00
|
|
|
#define OSMO_HDLC_F_56KBIT 0x01
|
|
|
|
#define OSMO_HDLC_F_DCHANNEL 0x02
|
|
|
|
#define OSMO_HDLC_F_BITREVERSE 0x04
|
2018-05-11 15:36:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
The return value from isdnhdlc_decode is
|
|
|
|
the frame length, 0 if no complete frame was decoded,
|
|
|
|
or a negative error number
|
|
|
|
*/
|
2018-05-11 15:39:21 +00:00
|
|
|
#define OSMO_HDLC_FRAMING_ERROR 1
|
|
|
|
#define OSMO_HDLC_CRC_ERROR 2
|
|
|
|
#define OSMO_HDLC_LENGTH_ERROR 3
|
2018-05-11 15:36:13 +00:00
|
|
|
|
2018-05-11 15:39:21 +00:00
|
|
|
extern void osmo_isdnhdlc_rcv_init(struct osmo_isdnhdlc_vars *hdlc, uint32_t features);
|
2018-05-11 15:36:13 +00:00
|
|
|
|
2018-05-11 15:39:21 +00:00
|
|
|
extern int osmo_isdnhdlc_decode(struct osmo_isdnhdlc_vars *hdlc, const uint8_t *src,
|
|
|
|
int slen, int *count, uint8_t *dst, int dsize);
|
2018-05-11 15:36:13 +00:00
|
|
|
|
2018-05-11 15:39:21 +00:00
|
|
|
extern void osmo_isdnhdlc_out_init(struct osmo_isdnhdlc_vars *hdlc, uint32_t features);
|
2018-05-11 15:36:13 +00:00
|
|
|
|
2018-05-11 15:39:21 +00:00
|
|
|
extern int osmo_isdnhdlc_encode(struct osmo_isdnhdlc_vars *hdlc, const uint8_t *src,
|
|
|
|
uint16_t slen, int *count, uint8_t *dst, int dsize);
|