2 * wprobe-test.c: Wireless probe user space test code
3 * Copyright (C) 2008-2009 Felix Fietkau <nbd@openwrt.org>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
25 #include <sys/types.h>
26 #include <sys/socket.h>
27 #include <linux/wprobe.h>
31 wprobe_dump_value(struct wprobe_attribute
*attr
)
35 #define HANDLE_TYPE(_type, _format) \
36 case WPROBE_VAL_##_type: \
37 snprintf(buf, sizeof(buf), _format, attr->val._type); \
41 HANDLE_TYPE(S8
, "%d");
42 HANDLE_TYPE(S16
, "%d");
43 HANDLE_TYPE(S32
, "%d");
44 HANDLE_TYPE(S64
, "%lld");
45 HANDLE_TYPE(U8
, "%d");
46 HANDLE_TYPE(U16
, "%d");
47 HANDLE_TYPE(U32
, "%d");
48 HANDLE_TYPE(U64
, "%lld");
49 case WPROBE_VAL_STRING
:
50 /* FIXME: implement this */
52 strncpy(buf
, "<unknown>", sizeof(buf
));
55 if ((attr
->flags
& WPROBE_F_KEEPSTAT
) &&
57 int len
= strlen(buf
);
58 snprintf(buf
+ len
, sizeof(buf
) - len
, " (avg: %.02f; stdev: %.02f, n=%d)", attr
->val
.avg
, attr
->val
.stdev
, attr
->val
.n
);
67 wprobe_dump_data(const char *ifname
, struct list_head
*gl
, struct list_head
*ll
, struct list_head
*ls
)
69 struct wprobe_attribute
*attr
;
70 struct wprobe_link
*link
;
73 fprintf(stderr
, "\n");
74 wprobe_request_data(ifname
, gl
, NULL
, 2);
75 list_for_each_entry(attr
, gl
, list
) {
76 fprintf(stderr
, (first
?
80 wprobe_dump_value(attr
)
85 list_for_each_entry(link
, ls
, list
) {
87 wprobe_request_data(ifname
, ll
, link
->addr
, 2);
88 list_for_each_entry(attr
, ll
, list
) {
91 "%02x:%02x:%02x:%02x:%02x:%02x: %s=%s\n",
92 link
->addr
[0], link
->addr
[1], link
->addr
[2],
93 link
->addr
[3], link
->addr
[4], link
->addr
[5],
95 wprobe_dump_value(attr
));
101 wprobe_dump_value(attr
));
107 static const char *attr_typestr
[] = {
109 [WPROBE_VAL_STRING
] = "String",
110 [WPROBE_VAL_U8
] = "Unsigned 8 bit",
111 [WPROBE_VAL_U16
] = "Unsigned 16 bit",
112 [WPROBE_VAL_U32
] = "Unsigned 32 bit",
113 [WPROBE_VAL_U64
] = "Unsigned 64 bit",
114 [WPROBE_VAL_S8
] = "Signed 8 bit",
115 [WPROBE_VAL_S16
] = "Signed 16 bit",
116 [WPROBE_VAL_S32
] = "Signed 32 bit",
117 [WPROBE_VAL_S64
] = "Signed 64 bit",
120 static int usage(const char *prog
)
122 fprintf(stderr
, "Usage: %s <interface>\n", prog
);
126 int main(int argc
, char **argv
)
128 struct wprobe_attribute
*attr
;
130 LIST_HEAD(global_attr
);
131 LIST_HEAD(link_attr
);
136 return usage(argv
[0]);
140 if (wprobe_init() != 0)
143 wprobe_dump_attributes(ifname
, false, &global_attr
, NULL
);
144 wprobe_dump_attributes(ifname
, true, &link_attr
, NULL
);
146 if (list_empty(&global_attr
) &&
147 list_empty(&link_attr
)) {
148 fprintf(stderr
, "Interface '%s' not found\n", ifname
);
152 list_for_each_entry(attr
, &global_attr
, list
) {
153 fprintf(stderr
, "Global attribute: '%s' (%s)\n",
154 attr
->name
, attr_typestr
[attr
->type
]);
156 list_for_each_entry(attr
, &link_attr
, list
) {
157 fprintf(stderr
, "Link attribute: '%s' (%s)\n",
158 attr
->name
, attr_typestr
[attr
->type
]);
163 wprobe_measure(ifname
);
169 wprobe_update_links(ifname
, &links
);
170 wprobe_dump_data(ifname
, &global_attr
, &link_attr
, &links
);
This page took 0.054059 seconds and 5 git commands to generate.