2 * wprobe.h: API for the wireless probe interface
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.
20 #include <linux/types.h>
21 #include <linux/if_ether.h>
22 #include <linux/spinlock.h>
23 #include <linux/module.h>
24 #include <linux/list.h>
25 #include <linux/timer.h>
26 #include <net/genetlink.h>
30 * enum wprobe_attr: netlink attribute list
32 * @WPROBE_ATTR_UNSPEC: unused
34 * @WPROBE_ATTR_INTERFACE: interface name to process query on (NLA_STRING)
35 * @WPROBE_ATTR_MAC: mac address (used for wireless links) (NLA_STRING)
36 * @WPROBE_ATTR_FLAGS: interface/link/attribute flags (see enum wprobe_flags) (NLA_U32)a
37 * @WPROBE_ATTR_DURATION: sampling duration (in milliseconds) (NLA_MSECS)
39 * @WPROBE_ATTR_ID: attribute id (NLA_U32)
40 * @WPROBE_ATTR_NAME: attribute name (NLA_STRING)
41 * @WPROBE_ATTR_TYPE: attribute type (NLA_U8)
45 * @WPROBE_VAL_STRING: string value (NLA_STRING)
46 * @WPROBE_VAL_S8: signed 8-bit integer (NLA_U8)
47 * @WPROBE_VAL_S16: signed 16-bit integer (NLA_U16)
48 * @WPROBE_VAL_S32: signed 32-bit integer (NLA_U32)
49 * @WPROBE_VAL_S64: signed 64-bit integer (NLA_U64)
50 * @WPROBE_VAL_U8: unsigned 8-bit integer (NLA_U8)
51 * @WPROBE_VAL_U16: unsigned 16-bit integer (NLA_U16)
52 * @WPROBE_VAL_U32: unsigned 32-bit integer (NLA_U32)
53 * @WPROBE_VAL_U64: unsigned 64-bit integer (NLA_U64)
56 * @WPROBE_VAL_SUM: sum of all samples
57 * @WPROBE_VAL_SUM_SQ: sum of all samples^2
58 * @WPROBE_VAL_SAMPLES: number of samples
59 * @WPROBE_VAL_SCALE_TIME: last time the samples were scaled down
62 * @WPROBE_ATTR_INTERVAL: (measurement interval in milliseconds) (NLA_MSECS)
63 * @WPROBE_ATTR_SAMPLES_MIN: minimum samples to keep during inactivity (NLA_U32)
64 * @WPROBE_ATTR_SAMPLES_MAX: maximum samples to keep before scaling down (NLA_U32)
65 * @WPROBE_ATTR_SAMPLES_SCALE_M: multiplier for scaling down samples (NLA_U32)
66 * @WPROBE_ATTR_SAMPLES_SCALE_D: divisor for scaling down samples (NLA_U32)
68 * @WPROBE_ATTR_LAST: unused
71 /* query attributes */
73 WPROBE_ATTR_INTERFACE
,
83 /* value type attributes */
94 /* aggregates for statistics */
98 WPROBE_VAL_SCALE_TIME
,
100 /* config attributes */
101 WPROBE_ATTR_INTERVAL
,
102 WPROBE_ATTR_SAMPLES_MIN
,
103 WPROBE_ATTR_SAMPLES_MAX
,
104 WPROBE_ATTR_SAMPLES_SCALE_M
,
105 WPROBE_ATTR_SAMPLES_SCALE_D
,
112 * enum wprobe_cmd: netlink commands for interacting with wprobe
114 * @WPROBE_CMD_UNSPEC: unused
116 * @WPROBE_CMD_GET_LIST: get global/link property list
117 * @WPROBE_CMD_GET_INFO: get global/link properties
118 * @WPROBE_CMD_SET_FLAGS: set global/link flags
119 * @WPROBE_CMD_MEASURE: take a snapshot of the current data
120 * @WPROBE_CMD_GET_LINKS: get a list of links
122 * @WPROBE_CMD_LAST: unused
124 * options for GET_INFO and SET_FLAGS:
125 * - mac address set: per-link
126 * - mac address unset: globalsa
132 WPROBE_CMD_SET_FLAGS
,
134 WPROBE_CMD_GET_LINKS
,
140 * enum wprobe_flags: flags for wprobe links and items
141 * @WPROBE_F_KEEPSTAT: keep statistics for this link/device
142 * @WPROBE_F_RESET: reset statistics now (used only in WPROBE_CMD_SET_LINK)
143 * @WPROBE_F_NEWDATA: used to indicate that a value has been updated
146 WPROBE_F_KEEPSTAT
= (1 << 0),
147 WPROBE_F_RESET
= (1 << 1),
148 WPROBE_F_NEWDATA
= (1 << 2),
155 struct wprobe_source
;
158 * struct wprobe_link - data structure describing a wireless link
159 * @iface: pointer to the wprobe_iface that this link belongs to
160 * @addr: BSSID of the remote link partner
161 * @flags: link flags (see wprobe_flags)
162 * @priv: user pointer
164 * @list: for internal use
165 * @val: for internal use
168 struct list_head list
;
169 struct wprobe_iface
*iface
;
177 * struct wprobe_item - data structure describing the format of wprobe_link::data or wprobe_iface::data
178 * @name: name of the field
179 * @type: data type of this field
180 * @flags: measurement item flags (see wprobe_flags)
184 enum wprobe_attr type
;
188 struct wprobe_value
{
192 * the following are kept uppercase to allow
193 * for automated checking against WPROBE_VAL_*
215 * struct wprobe_source - data structure describing a wireless interface
217 * @name: name of the interface
218 * @addr: local mac address of the interface
219 * @links: list of wireless links to poll
220 * @link_items: description of the per-link data structure
221 * @n_link_items: number of link description items
222 * @global_items: description of the per-interface data structure
223 * @n_global_items: number of per-interface description items
224 * @sync_data: callback allowing the driver to prepare data for the wprobe poll
226 * @list: head for the list of interfaces
227 * @priv: user pointer
228 * @lock: spinlock protecting value data access
230 * @query_val: internal use
232 * if sync_data is NULL, wprobe assumes that it can access the data structure
233 * at any time (in atomic context). if sync_data returns a negative error code,
234 * the poll request will not be handled for the given link
236 struct wprobe_iface
{
237 /* to be filled in by wprobe source drivers */
240 const struct wprobe_item
*link_items
;
242 const struct wprobe_item
*global_items
;
245 int (*sync_data
)(struct wprobe_iface
*dev
, struct wprobe_link
*l
,
246 struct wprobe_value
*val
, bool measure
);
249 /* handled by the wprobe core */
250 struct list_head list
;
251 struct list_head links
;
256 u32 measure_interval
;
257 struct timer_list measure_timer
;
265 #define WPROBE_FILL_BEGIN(_ptr, _list) do { \
266 struct wprobe_value *__val = (_ptr); \
267 const struct wprobe_item *__item = _list; \
268 u64 __msecs = jiffies_to_msecs(jiffies)
270 #define WPROBE_SET(_idx, _type, _value) \
271 if (__item[_idx].type != WPROBE_VAL_##_type) { \
272 printk("ERROR: invalid data type at %s:%d\n", __FILE__, __LINE__); \
275 __val[_idx].pending = true; \
276 __val[_idx]._type = _value; \
277 if (!__val[_idx].first) \
278 __val[_idx].first = __msecs; \
279 __val[_idx].first = __msecs
281 #define WPROBE_FILL_END() \
285 * wprobe_add_iface: register an interface with the wireless probe subsystem
286 * @dev: wprobe_iface structure describing the interface
288 extern int __weak
wprobe_add_iface(struct wprobe_iface
*dev
);
291 * wprobe_remove_iface: deregister an interface from the wireless probe subsystem
292 * @dev: wprobe_iface structure describing the interface
294 extern void __weak
wprobe_remove_iface(struct wprobe_iface
*dev
);
297 * wprobe_add_link: register a new wireless link
298 * @dev: wprobe_iface structure describing the interface
299 * @l: storage space for the wprobe_link structure
300 * @addr: mac address of the new link
302 * the entire wprobe_link structure is overwritten by this function call
304 extern int __weak
wprobe_add_link(struct wprobe_iface
*dev
, struct wprobe_link
*l
, const char *addr
);
307 * wprobe_remove_link: deregister a previously registered wireless link
308 * @dev: wprobe_iface structure describing the interface
309 * @l: wprobe_link data structure
311 extern void __weak
wprobe_remove_link(struct wprobe_iface
*dev
, struct wprobe_link
*l
);
314 * wprobe_update_stats: update statistics after sampling values
315 * @dev: wprobe_iface structure describing the interface
316 * @l: wprobe_link data structure
318 * if l == NULL, then the stats for globals are updated
320 extern void __weak
wprobe_update_stats(struct wprobe_iface
*dev
, struct wprobe_link
*l
);
322 #endif /* __KERNEL__ */