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(struct wprobe_iface
*dev
)
69 struct wprobe_attribute
*attr
;
70 struct wprobe_link
*link
;
73 fprintf(stderr
, "\n");
74 wprobe_request_data(dev
, NULL
);
75 list_for_each_entry(attr
, &dev
->global_attr
, list
) {
76 fprintf(stderr
, (first
?
80 wprobe_dump_value(attr
)
85 list_for_each_entry(link
, &dev
->links
, list
) {
87 wprobe_request_data(dev
, link
->addr
);
88 list_for_each_entry(attr
, &dev
->link_attr
, 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
)
123 "Usage: %s <interface> [options]\n"
126 " -c: Only apply configuration\n"
127 " -h: This help text\n"
128 " -i <interval>: Set measurement interval\n"
129 " -m: Run measurement loop\n"
135 static void show_attributes(struct wprobe_iface
*dev
)
137 struct wprobe_attribute
*attr
;
138 list_for_each_entry(attr
, &dev
->global_attr
, list
) {
139 fprintf(stderr
, "Global attribute: '%s' (%s)\n",
140 attr
->name
, attr_typestr
[attr
->type
]);
142 list_for_each_entry(attr
, &dev
->link_attr
, list
) {
143 fprintf(stderr
, "Link attribute: '%s' (%s)\n",
144 attr
->name
, attr_typestr
[attr
->type
]);
148 static void loop_measurement(struct wprobe_iface
*dev
)
152 wprobe_update_links(dev
);
153 wprobe_dump_data(dev
);
157 int main(int argc
, char **argv
)
159 struct wprobe_iface
*dev
;
161 const char *prog
= argv
[0];
169 if ((argc
< 2) || (argv
[1][0] == '-'))
173 dev
= wprobe_get_dev(ifname
);
177 if (!dev
|| (list_empty(&dev
->global_attr
) &&
178 list_empty(&dev
->link_attr
))) {
179 fprintf(stderr
, "Interface '%s' not found\n", ifname
);
183 while ((ch
= getopt(argc
, argv
, "chi:m")) != -1) {
192 dev
->interval
= strtoul(optarg
, NULL
, 10);
201 wprobe_apply_config(dev
);
202 if (cmd
!= CMD_CONFIG
)
203 show_attributes(dev
);
204 if (cmd
== CMD_MEASURE
)
205 loop_measurement(dev
);
207 wprobe_free_dev(dev
);
This page took 0.063779 seconds and 5 git commands to generate.