add support for if{down,up} -a and implement proper start/stop/restart for /etc/init...
[openwrt/staging/florian.git] / package / d80211 / src / ieee80211_rate.h
1 /*
2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005, Devicescape Software, Inc.
4 * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11 #ifndef IEEE80211_RATE_H
12 #define IEEE80211_RATE_H
13
14 #include <linux/netdevice.h>
15 #include <linux/skbuff.h>
16 #include <linux/types.h>
17 #include <net/d80211.h>
18 #include "ieee80211_i.h"
19 #include "sta_info.h"
20
21 #define RATE_CONTROL_NUM_DOWN 20
22 #define RATE_CONTROL_NUM_UP 15
23
24
25 struct rate_control_extra {
26 /* values from rate_control_get_rate() to the caller: */
27 struct ieee80211_rate *probe; /* probe with this rate, or NULL for no
28 * probing */
29 int startidx, endidx, rateidx;
30 struct ieee80211_rate *nonerp;
31 int nonerp_idx;
32
33 /* parameters from the caller to rate_control_get_rate(): */
34 int mgmt_data; /* this is data frame that is used for management
35 * (e.g., IEEE 802.1X EAPOL) */
36 u16 ethertype;
37 };
38
39
40 struct rate_control_ops {
41 struct module *module;
42 const char *name;
43 void (*tx_status)(void *priv, struct net_device *dev,
44 struct sk_buff *skb,
45 struct ieee80211_tx_status *status);
46 struct ieee80211_rate *(*get_rate)(void *priv, struct net_device *dev,
47 struct sk_buff *skb,
48 struct rate_control_extra *extra);
49 void (*rate_init)(void *priv, void *priv_sta,
50 struct ieee80211_local *local, struct sta_info *sta);
51 void (*clear)(void *priv);
52
53 void *(*alloc)(struct ieee80211_local *local);
54 void (*free)(void *priv);
55 void *(*alloc_sta)(void *priv, gfp_t gfp);
56 void (*free_sta)(void *priv, void *priv_sta);
57
58 int (*add_attrs)(void *priv, struct kobject *kobj);
59 void (*remove_attrs)(void *priv, struct kobject *kobj);
60 int (*add_sta_attrs)(void *priv, void *priv_sta,
61 struct kobject *kobj);
62 void (*remove_sta_attrs)(void *priv, void *priv_sta,
63 struct kobject *kobj);
64 };
65
66 struct rate_control_ref {
67 struct rate_control_ops *ops;
68 void *priv;
69 struct kref kref;
70 };
71
72 int ieee80211_rate_control_register(struct rate_control_ops *ops);
73 void ieee80211_rate_control_unregister(struct rate_control_ops *ops);
74
75 /* Get a reference to the rate control algorithm. If `name' is NULL, get the
76 * first available algorithm. */
77 struct rate_control_ref *rate_control_alloc(const char *name,
78 struct ieee80211_local *local);
79 struct rate_control_ref *rate_control_get(struct rate_control_ref *ref);
80 void rate_control_put(struct rate_control_ref *ref);
81
82 static inline void rate_control_tx_status(struct ieee80211_local *local,
83 struct net_device *dev,
84 struct sk_buff *skb,
85 struct ieee80211_tx_status *status)
86 {
87 struct rate_control_ref *ref = local->rate_ctrl;
88 ref->ops->tx_status(ref->priv, dev, skb, status);
89 }
90
91
92 static inline struct ieee80211_rate *
93 rate_control_get_rate(struct ieee80211_local *local, struct net_device *dev,
94 struct sk_buff *skb, struct rate_control_extra *extra)
95 {
96 struct rate_control_ref *ref = local->rate_ctrl;
97 return ref->ops->get_rate(ref->priv, dev, skb, extra);
98 }
99
100
101 static inline void rate_control_rate_init(struct sta_info *sta,
102 struct ieee80211_local *local)
103 {
104 struct rate_control_ref *ref = sta->rate_ctrl;
105 ref->ops->rate_init(ref->priv, sta->rate_ctrl_priv, local, sta);
106 }
107
108
109 static inline void rate_control_clear(struct ieee80211_local *local)
110 {
111 struct rate_control_ref *ref = local->rate_ctrl;
112 ref->ops->clear(ref->priv);
113 }
114
115 static inline void *rate_control_alloc_sta(struct rate_control_ref *ref,
116 gfp_t gfp)
117 {
118 return ref->ops->alloc_sta(ref->priv, gfp);
119 }
120
121 static inline void rate_control_free_sta(struct rate_control_ref *ref,
122 void *priv)
123 {
124 ref->ops->free_sta(ref->priv, priv);
125 }
126
127 static inline int rate_control_add_attrs(struct rate_control_ref *ref,
128 struct kobject *kobj)
129 {
130 if (ref->ops->add_attrs)
131 return ref->ops->add_attrs(ref->priv, kobj);
132 return 0;
133 }
134
135 static inline void rate_control_remove_attrs(struct rate_control_ref *ref,
136 struct kobject *kobj)
137 {
138 if (ref->ops->remove_attrs)
139 ref->ops->remove_attrs(ref->priv, kobj);
140 }
141
142 static inline int rate_control_add_sta_attrs(struct sta_info *sta,
143 struct kobject *kobj)
144 {
145 struct rate_control_ref *ref = sta->rate_ctrl;
146 if (ref->ops->add_sta_attrs)
147 return ref->ops->add_sta_attrs(ref->priv, sta->rate_ctrl_priv,
148 kobj);
149 return 0;
150 }
151
152 static inline void rate_control_remove_sta_attrs(struct sta_info *sta,
153 struct kobject *kobj)
154 {
155 struct rate_control_ref *ref = sta->rate_ctrl;
156 if (ref->ops->remove_sta_attrs)
157 ref->ops->remove_sta_attrs(ref->priv, sta->rate_ctrl_priv,
158 kobj);
159 }
160
161 #endif /* IEEE80211_RATE_H */