summaryrefslogtreecommitdiff
path: root/tools/parser/amp.c
blob: 79753147079bcad6f5663f793db816e4209e6254 (plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 *
 *  BlueZ - Bluetooth protocol stack for Linux
 *
 *  Copyright (C) 2012  Intel Corporation.
 *
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#define _GNU_SOURCE
#include "parser.h"
#include "lib/amp.h"

static void amp_dump_chanlist(int level, struct amp_tlv *tlv, char *prefix)
{
	struct amp_chan_list *chan_list = (void *) tlv->val;
	struct amp_country_triplet *triplet;
	int i, num;

	num = (tlv->len - sizeof(*chan_list)) / sizeof(*triplet);

	printf("%s (number of triplets %d)\n", prefix, num);

	p_indent(level+2, 0);

	printf("Country code: %c%c%c\n", chan_list->country_code[0],
		chan_list->country_code[1], chan_list->country_code[2]);

	for (i = 0; i < num; i++) {
		triplet = &chan_list->triplets[i];

		p_indent(level+2, 0);

		if (triplet->chans.first_channel >= 201) {
			printf("Reg ext id %d reg class %d coverage class %d\n",
						triplet->ext.reg_extension_id,
						triplet->ext.reg_class,
						triplet->ext.coverage_class);
		} else {
			if (triplet->chans.num_channels == 1)
				printf("Channel %d max power %d\n",
						triplet->chans.first_channel,
						triplet->chans.max_power);
			else
				printf("Channels %d - %d max power %d\n",
						triplet->chans.first_channel,
						triplet->chans.first_channel +
						triplet->chans.num_channels,
						triplet->chans.max_power);
		}
	}
}

void amp_assoc_dump(int level, uint8_t *assoc, uint16_t len)
{
	struct amp_tlv *tlv = (void *) assoc;

	p_indent(level, 0);
	printf("Assoc data [len %d]:\n", len);

	while (len > sizeof(*tlv)) {
		uint16_t tlvlen = btohs(tlv->len);
		struct amp_pal_ver *ver;

		p_indent(level+1, 0);

		switch (tlv->type) {
		case A2MP_MAC_ADDR_TYPE:
			if (tlvlen != 6)
				break;
			printf("MAC: %2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n",
					tlv->val[0], tlv->val[1], tlv->val[2],
					tlv->val[3], tlv->val[4], tlv->val[5]);
			break;

		case A2MP_PREF_CHANLIST_TYPE:
			amp_dump_chanlist(level, tlv, "Preferred Chan List");
			break;

		case A2MP_CONNECTED_CHAN:
			amp_dump_chanlist(level, tlv, "Connected Chan List");
			break;

		case A2MP_PAL_CAP_TYPE:
			if (tlvlen != 4)
				break;
			printf("PAL CAP: %2.2x %2.2x %2.2x %2.2x\n",
					tlv->val[0], tlv->val[1], tlv->val[2],
					tlv->val[3]);
			break;

		case A2MP_PAL_VER_INFO:
			if (tlvlen != 5)
				break;
			ver = (struct amp_pal_ver *) tlv->val;
			printf("PAL VER: %2.2x Comp ID: %4.4x SubVer: %4.4x\n",
					ver->ver, btohs(ver->company_id),
					btohs(ver->sub_ver));
			break;

		default:
			printf("Unrecognized type %d\n", tlv->type);
			break;
		}

		len -= tlvlen + sizeof(*tlv);
		assoc += tlvlen + sizeof(*tlv);
		tlv = (struct amp_tlv *) assoc;
	}
}