1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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);
}
|