blob: 1c7c6ef6346755fb0ff6f4d249199c26c38ec64c [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;
15 int rc;
16
17 printf("hex string = %s\n", hex);
18 bytes = alloca(byte_len);
19 bits = alloca(bit_len);
20 rc = osmo_hexparse(hex, bytes, byte_len);
21 printf("parsed bytes = %s\n", osmo_hexdump(bytes, byte_len));
22
23 printf("MSB mode\n");
24 osmo_pbit2ubit(bits, bytes, bit_len);
25 process_raw_hdlc(hdlc, bits, bit_len);
26
27 printf("LSB mode\n");
28 memset(hdlc, 0, sizeof(*hdlc));
29 osmo_pbit2ubit_ext(bits, 0, bytes, 0, bit_len, 1);
30 process_raw_hdlc(hdlc, bits, bit_len);
31}
32
33int main(int argc, char **argv)
34{
35 struct hdlc_proc hdlc;
36 memset(&hdlc, 0, sizeof(hdlc));
37
38 if (argc < 2)
39 exit(1);
40
41 hdlc_process_hex_str(&hdlc, argv[1]);
42}