Harald Welte | f5e7264 | 2022-10-30 22:20:55 +0100 | [diff] [blame^] | 1 | /* (C) 2020 by Harald Welte <laforge@gnumonks.org> |
| 2 | * All Rights Reserved |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published |
| 8 | * by the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | */ |
| 16 | |
| 17 | #include <string.h> |
| 18 | #include <sys/types.h> |
| 19 | #include <fcntl.h> |
| 20 | #include <stdint.h> |
| 21 | #include <stdlib.h> |
| 22 | #include <getopt.h> |
| 23 | #include <unistd.h> |
| 24 | #include <stdio.h> |
| 25 | #include <errno.h> |
| 26 | #include <inttypes.h> |
| 27 | |
| 28 | #include <osmocom/core/isdnhdlc.h> |
| 29 | |
| 30 | static struct osmo_isdnhdlc_vars g_hdlc; |
| 31 | |
| 32 | /* read bitstream from STDIN, pass through HDLC decoder, write decoded frames to stdout */ |
| 33 | |
| 34 | int main(int argc, char **argv) |
| 35 | { |
| 36 | osmo_isdnhdlc_rcv_init(&g_hdlc, OSMO_HDLC_F_BITREVERSE); |
| 37 | |
| 38 | while (1) { |
| 39 | uint8_t inbuf[320]; |
| 40 | uint8_t outbuf[2048]; |
| 41 | int rc, inlen, outlen; |
| 42 | |
| 43 | rc = read(0, inbuf, sizeof(inbuf)); |
| 44 | if (rc < 0) |
| 45 | exit(1); |
| 46 | else if (rc == 0) |
| 47 | exit(0); |
| 48 | |
| 49 | inlen = rc; |
| 50 | rc = osmo_isdnhdlc_decode(&g_hdlc, inbuf, inlen, &outlen, outbuf, sizeof(outbuf)); |
| 51 | |
| 52 | if (outlen > 0) |
| 53 | write(1, outbuf, outlen); |
| 54 | } |
| 55 | } |