Harald Welte | 1df5cf4 | 2016-11-14 21:29:01 +0100 | [diff] [blame] | 1 | #include <string.h> |
| 2 | #include "hdlc.h" |
| 3 | |
| 4 | #include <osmocom/core/utils.h> |
| 5 | #include <osmocom/core/bits.h> |
| 6 | |
| 7 | const char *tdata = "7e7e7e7e7a76f20609167d3cfcfcfc"; |
| 8 | |
| 9 | static void hdlc_process_hex_str(struct hdlc_proc *hdlc, const char *hex) |
| 10 | { |
| 11 | uint8_t *bytes, *bits; |
| 12 | int string_len = strlen(hex); |
| 13 | int byte_len = string_len/2; |
| 14 | int bit_len = byte_len*8; |
Harald Welte | 1df5cf4 | 2016-11-14 21:29:01 +0100 | [diff] [blame] | 15 | |
| 16 | printf("hex string = %s\n", hex); |
| 17 | bytes = alloca(byte_len); |
| 18 | bits = alloca(bit_len); |
Harald Welte | 6df0729 | 2019-11-06 16:21:55 +0100 | [diff] [blame] | 19 | osmo_hexparse(hex, bytes, byte_len); |
Harald Welte | 1df5cf4 | 2016-11-14 21:29:01 +0100 | [diff] [blame] | 20 | printf("parsed bytes = %s\n", osmo_hexdump(bytes, byte_len)); |
| 21 | |
| 22 | printf("MSB mode\n"); |
| 23 | osmo_pbit2ubit(bits, bytes, bit_len); |
| 24 | process_raw_hdlc(hdlc, bits, bit_len); |
| 25 | |
| 26 | printf("LSB mode\n"); |
| 27 | memset(hdlc, 0, sizeof(*hdlc)); |
| 28 | osmo_pbit2ubit_ext(bits, 0, bytes, 0, bit_len, 1); |
| 29 | process_raw_hdlc(hdlc, bits, bit_len); |
| 30 | } |
| 31 | |
| 32 | int main(int argc, char **argv) |
| 33 | { |
| 34 | struct hdlc_proc hdlc; |
| 35 | memset(&hdlc, 0, sizeof(hdlc)); |
| 36 | |
| 37 | if (argc < 2) |
| 38 | exit(1); |
| 39 | |
| 40 | hdlc_process_hex_str(&hdlc, argv[1]); |
| 41 | } |