blob: d30c4ba8fd999557610bd40d9822f28ac9731dec [file] [log] [blame]
Johannes Berg704232c2007-04-23 12:20:05 -07001#ifndef __NET_WIRELESS_H
2#define __NET_WIRELESS_H
3
4/*
5 * 802.11 device management
6 *
7 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
8 */
9
10#include <linux/netdevice.h>
11#include <linux/debugfs.h>
12#include <linux/list.h>
13#include <net/cfg80211.h>
14
15/**
16 * struct wiphy - wireless hardware description
17 * @idx: the wiphy index assigned to this item
18 * @class_dev: the class device representing /sys/class/ieee80211/<wiphy-name>
19 */
20struct wiphy {
21 /* assign these fields before you register the wiphy */
22
23 /* permanent MAC address */
24 u8 perm_addr[ETH_ALEN];
25
26 /* If multiple wiphys are registered and you're handed e.g.
27 * a regular netdev with assigned ieee80211_ptr, you won't
28 * know whether it points to a wiphy your driver has registered
29 * or not. Assign this to something global to your driver to
30 * help determine whether you own this wiphy or not. */
31 void *privid;
32
33 /* fields below are read-only, assigned by cfg80211 */
34
35 /* the item in /sys/class/ieee80211/ points to this,
36 * you need use set_wiphy_dev() (see below) */
37 struct device dev;
38
39 /* dir in debugfs: ieee80211/<wiphyname> */
40 struct dentry *debugfsdir;
41
42 char priv[0] __attribute__((__aligned__(NETDEV_ALIGN)));
43};
44
45/** struct wireless_dev - wireless per-netdev state
46 *
47 * This structure must be allocated by the driver/stack
48 * that uses the ieee80211_ptr field in struct net_device
49 * (this is intentional so it can be allocated along with
50 * the netdev.)
51 *
52 * @wiphy: pointer to hardware description
53 */
54struct wireless_dev {
55 struct wiphy *wiphy;
56
57 /* private to the generic wireless code */
58 struct list_head list;
59 struct net_device *netdev;
60};
61
62/**
63 * wiphy_priv - return priv from wiphy
64 */
65static inline void *wiphy_priv(struct wiphy *wiphy)
66{
67 BUG_ON(!wiphy);
68 return &wiphy->priv;
69}
70
71/**
72 * set_wiphy_dev - set device pointer for wiphy
73 */
74static inline void set_wiphy_dev(struct wiphy *wiphy, struct device *dev)
75{
76 wiphy->dev.parent = dev;
77}
78
79/**
80 * wiphy_dev - get wiphy dev pointer
81 */
82static inline struct device *wiphy_dev(struct wiphy *wiphy)
83{
84 return wiphy->dev.parent;
85}
86
87/**
88 * wiphy_name - get wiphy name
89 */
90static inline char *wiphy_name(struct wiphy *wiphy)
91{
92 return wiphy->dev.bus_id;
93}
94
95/**
96 * wdev_priv - return wiphy priv from wireless_dev
97 */
98static inline void *wdev_priv(struct wireless_dev *wdev)
99{
100 BUG_ON(!wdev);
101 return wiphy_priv(wdev->wiphy);
102}
103
104/**
105 * wiphy_new - create a new wiphy for use with cfg80211
106 *
107 * create a new wiphy and associate the given operations with it.
108 * @sizeof_priv bytes are allocated for private use.
109 *
110 * the returned pointer must be assigned to each netdev's
111 * ieee80211_ptr for proper operation.
112 */
113struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv);
114
115/**
116 * wiphy_register - register a wiphy with cfg80211
117 *
118 * register the given wiphy
119 *
120 * Returns a non-negative wiphy index or a negative error code.
121 */
122extern int wiphy_register(struct wiphy *wiphy);
123
124/**
125 * wiphy_unregister - deregister a wiphy from cfg80211
126 *
127 * unregister a device with the given priv pointer.
128 * After this call, no more requests can be made with this priv
129 * pointer, but the call may sleep to wait for an outstanding
130 * request that is being handled.
131 */
132extern void wiphy_unregister(struct wiphy *wiphy);
133
134/**
135 * wiphy_free - free wiphy
136 */
137extern void wiphy_free(struct wiphy *wiphy);
138
139#endif /* __NET_WIRELESS_H */