9ceea7da57d83774fb14e389ca5cd04b6061ec41
[openwrt.git] / target / linux / package / ieee80211-dscape / src / rate_control.h
1 /*
2  * Copyright 2002-2005, Instant802 Networks, Inc.
3  * Copyright 2005, Devicescape Software, Inc.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  */
9
10 #ifndef RATE_CONTROL
11 #define RATE_CONTROL
12
13 #define RATE_CONTROL_NUM_DOWN 20
14 #define RATE_CONTROL_NUM_UP   15
15
16
17 struct rate_control_extra {
18         /* values from rate_control_get_rate() to the caller: */
19         struct ieee80211_rate *probe; /* probe with this rate, or NULL for no
20                                        * probing */
21         int startidx, endidx, rateidx;
22         struct ieee80211_rate *nonerp;
23         int nonerp_idx;
24
25         /* parameters from the caller to rate_control_get_rate(): */
26         int mgmt_data; /* this is data frame that is used for management
27                         * (e.g., IEEE 802.1X EAPOL) */
28         u16 ethertype;
29 };
30
31
32 struct rate_control_ops {
33         const char *name;
34         void (*tx_status)(struct net_device *dev, struct sk_buff *skb,
35                           struct ieee80211_tx_status *status);
36         struct ieee80211_rate *
37         (*get_rate)(struct net_device *dev, struct sk_buff *skb,
38                     struct rate_control_extra *extra);
39         void (*rate_init)(struct ieee80211_local *local, struct sta_info *sta);
40         void (*clear)(void *priv);
41         int (*status_sta)(struct ieee80211_local *local,
42                           struct sta_info *sta, char *buf);
43         int (*status_global)(struct ieee80211_local *local, char *buf);
44
45         void * (*alloc)(struct ieee80211_local *local);
46         void (*free)(void *priv);
47         void * (*alloc_sta)(void);
48         void (*free_sta)(void *priv);
49 };
50
51
52 int ieee80211_rate_control_register(struct rate_control_ops *ops);
53 void ieee80211_rate_control_unregister(struct rate_control_ops *ops);
54
55
56 static inline void rate_control_tx_status(struct net_device *dev,
57                                           struct sk_buff *skb,
58                                           struct ieee80211_tx_status *status)
59 {
60         struct ieee80211_local *local = dev->priv;
61         local->rate_ctrl->tx_status(dev, skb, status);
62 }
63
64
65 static inline struct ieee80211_rate *
66 rate_control_get_rate(struct net_device *dev, struct sk_buff *skb,
67                       struct rate_control_extra *extra)
68 {
69         struct ieee80211_local *local = dev->priv;
70         return local->rate_ctrl->get_rate(dev, skb, extra);
71 }
72
73
74 static inline void rate_control_rate_init(struct ieee80211_local *local,
75                                           struct sta_info *sta)
76 {
77         local->rate_ctrl->rate_init(local, sta);
78 }
79
80
81 static inline void rate_control_clear(struct ieee80211_local *local)
82 {
83         local->rate_ctrl->clear(local->rate_ctrl_priv);
84 }
85
86
87 static inline int rate_control_status_sta(struct ieee80211_local *local,
88                                           struct sta_info *sta, char *buf)
89 {
90         return local->rate_ctrl->status_sta(local, sta, buf);
91 }
92
93
94 static inline int rate_control_status_global(struct ieee80211_local *local,
95                                              char *buf)
96 {
97         return local->rate_ctrl->status_global(local, buf);
98 }
99
100
101 static inline void * rate_control_alloc(struct ieee80211_local *local)
102 {
103         return local->rate_ctrl->alloc(local);
104 }
105
106
107 static inline void rate_control_free(struct ieee80211_local *local)
108 {
109         if (local->rate_ctrl == NULL || local->rate_ctrl_priv == NULL)
110                 return;
111         local->rate_ctrl->free(local->rate_ctrl_priv);
112         local->rate_ctrl_priv = NULL;
113 }
114
115
116 static inline void * rate_control_alloc_sta(struct ieee80211_local *local)
117 {
118         return local->rate_ctrl->alloc_sta();
119 }
120
121
122 static inline void rate_control_free_sta(struct ieee80211_local *local,
123                                          void *priv)
124 {
125         local->rate_ctrl->free_sta(priv);
126 }
127
128 #endif /* RATE_CONTROL */