summaryrefslogtreecommitdiff
path: root/hapc_test.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2015-11-09 20:01:37 +0100
committerHarald Welte <laforge@gnumonks.org>2015-11-09 20:01:37 +0100
commita915c1c944938f332e70aff8927f19b6e381eeea (patch)
treeeb9301d3b28df8b01d6f208780d9ef827dea688d /hapc_test.c
initial checkin of some c-language code to parse Sierra Wireless HAPC
Diffstat (limited to 'hapc_test.c')
-rw-r--r--hapc_test.c55
1 files changed, 55 insertions, 0 deletions
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 <stdio.h>
+
+#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);
+}
personal git repositories of Harald Welte. Your mileage may vary