blob: 0814ca0fbe95d658bd2ad3141dfb52dd6a676ba4 [file] [log] [blame]
Harald Welte1df5cf42016-11-14 21:29:01 +01001#include <string.h>
2#include "hdlc.h"
3
4#include <osmocom/core/utils.h>
5#include <osmocom/core/bits.h>
6
7const char *tdata = "7e7e7e7e7a76f20609167d3cfcfcfc";
8
9static 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 Welte1df5cf42016-11-14 21:29:01 +010015
16 printf("hex string = %s\n", hex);
17 bytes = alloca(byte_len);
18 bits = alloca(bit_len);
Harald Welte6df07292019-11-06 16:21:55 +010019 osmo_hexparse(hex, bytes, byte_len);
Harald Welte1df5cf42016-11-14 21:29:01 +010020 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
32int 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}