From a915c1c944938f332e70aff8927f19b6e381eeea Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Mon, 9 Nov 2015 20:01:37 +0100 Subject: initial checkin of some c-language code to parse Sierra Wireless HAPC --- hapc_test.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 hapc_test.c (limited to 'hapc_test.c') diff --git a/hapc_test.c b/hapc_test.c new file mode 100644 index 0000000..a240c14 --- /dev/null +++ b/hapc_test.c @@ -0,0 +1,55 @@ +#include + +#include "hapc_frame.h" + +const uint8_t test_frame[] = { 0xAA, 0x10, 0x58, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x00, 0x00, 0x01, 0x00, 0x13 }; +const uint8_t resp_frame[] = { 0xAA, 0x20, 0x58, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0x00, 0x00, 0x82, + 0x18, 0x81, 0x00, 0x00, 0x20, 0x03, 0x00, 0x09, 0x08, 0x91, 0x94, 0x58, 0x16, 0x89, 0x63, 0x07, 0xf2, 0x0d }; + +static void dump_frame_object(const struct hapc_flash_obj_hdr *foh, unsigned int len) +{ + unsigned int payload_len = len - sizeof(*foh); + printf("obj_id=0x%08x, mask=0x%08x, total_size=%d, block_size=%d, offset_block=%d, status=%s, data=%s\n", + foh->obj_id, foh->mask, foh->total_size, foh->block_size, foh->offset_block, + get_value_string(hapc_obj_status_names, foh->obj_status & 0x7f), osmo_hexdump(foh->data, payload_len)); +} + +static uint8_t compute_checksum(const uint8_t *data, unsigned int len) +{ + unsigned int i; + uint8_t checksum = 0; + + for (i = 0; i < len; i++) + checksum += data[i]; + + return checksum; +} + +void dump_frame(const struct hapc_msg_hdr *hdr) +{ + unsigned int len = hapc_payload_len(hdr); + + printf("len=%4u, flow_id=%s: ", len, + get_value_string(hapc_flow_names, hdr->flow_id)); + + printf("checksum=0x%02x, computed=0x%02x\n", + hapc_frame_csum(hdr), compute_checksum((const uint8_t *) hdr, sizeof(*hdr)+len)); + + switch (hdr->flow_id) { + case HAPC_FLOW_OBJECT: + dump_frame_object((const struct hapc_flash_obj_hdr *) hdr->data, len - sizeof(*hdr)); + break; + default: + printf("\n"); + break; + } +} + +int main(int argc, char **argv) +{ + const struct hapc_msg_hdr *hdr = (const struct hapc_msg_hdr *) test_frame; + dump_frame(hdr); + + hdr = (const struct hapc_msg_hdr *) resp_frame; + dump_frame(hdr); +} -- cgit v1.2.3