package uuidgen
[openwrt.git] / package / mac80211 / patches / 023-mac80211-implement-sta.patch
1 Subject: mac80211: implement cfg80211's station handling
2
3 This implements station handling from userspace via cfg80211
4 in mac80211.
5
6 Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
7
8 ---
9 net/mac80211/cfg.c | 192 +++++++++++++++++++++++++++++++++++++++++++++++++++++
10 1 file changed, 192 insertions(+)
11
12 --- everything.orig/net/mac80211/cfg.c 2007-11-08 17:11:52.351521702 +0100
13 +++ everything/net/mac80211/cfg.c 2007-11-08 17:15:51.801523493 +0100
14 @@ -14,6 +14,7 @@
15 #include <net/cfg80211.h>
16 #include "ieee80211_i.h"
17 #include "cfg.h"
18 +#include "ieee80211_rate.h"
19
20 static enum ieee80211_if_types
21 nl80211_type_to_mac80211_type(enum nl80211_iftype type)
22 @@ -428,6 +429,194 @@ static int ieee80211_del_beacon(struct w
23 return ieee80211_if_config_beacon(dev);
24 }
25
26 +/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
27 +struct iapp_layer2_update {
28 + u8 da[ETH_ALEN]; /* broadcast */
29 + u8 sa[ETH_ALEN]; /* STA addr */
30 + __be16 len; /* 6 */
31 + u8 dsap; /* 0 */
32 + u8 ssap; /* 0 */
33 + u8 control;
34 + u8 xid_info[3];
35 +} __attribute__ ((packed));
36 +
37 +static void ieee80211_send_layer2_update(struct sta_info *sta)
38 +{
39 + struct iapp_layer2_update *msg;
40 + struct sk_buff *skb;
41 +
42 + /* Send Level 2 Update Frame to update forwarding tables in layer 2
43 + * bridge devices */
44 +
45 + skb = dev_alloc_skb(sizeof(*msg));
46 + if (!skb)
47 + return;
48 + msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
49 +
50 + /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
51 + * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
52 +
53 + memset(msg->da, 0xff, ETH_ALEN);
54 + memcpy(msg->sa, sta->addr, ETH_ALEN);
55 + msg->len = htons(6);
56 + msg->dsap = 0;
57 + msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
58 + msg->control = 0xaf; /* XID response lsb.1111F101.
59 + * F=0 (no poll command; unsolicited frame) */
60 + msg->xid_info[0] = 0x81; /* XID format identifier */
61 + msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
62 + msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
63 +
64 + skb->dev = sta->dev;
65 + skb->protocol = eth_type_trans(skb, sta->dev);
66 + memset(skb->cb, 0, sizeof(skb->cb));
67 + netif_rx(skb);
68 +}
69 +
70 +static void sta_apply_parameters(struct ieee80211_local *local,
71 + struct sta_info *sta,
72 + struct station_parameters *params)
73 +{
74 + u32 rates;
75 + int i, j;
76 + struct ieee80211_hw_mode *mode;
77 +
78 + if (params->station_flags & STATION_FLAG_CHANGED) {
79 + sta->flags &= ~WLAN_STA_AUTHORIZED;
80 + if (params->station_flags & STATION_FLAG_AUTHORIZED)
81 + sta->flags |= WLAN_STA_AUTHORIZED;
82 +
83 + sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
84 + if (params->station_flags & STATION_FLAG_SHORT_PREAMBLE)
85 + sta->flags |= WLAN_STA_SHORT_PREAMBLE;
86 +
87 + sta->flags &= ~WLAN_STA_WME;
88 + if (params->station_flags & STATION_FLAG_WME)
89 + sta->flags |= WLAN_STA_WME;
90 + }
91 +
92 + if (params->aid) {
93 + sta->aid = params->aid;
94 + if (sta->aid > IEEE80211_MAX_AID)
95 + sta->aid = 0; /* XXX: should this be an error? */
96 + }
97 +
98 + if (params->listen_interval >= 0)
99 + sta->listen_interval = params->listen_interval;
100 +
101 + if (params->supported_rates) {
102 + rates = 0;
103 + mode = local->oper_hw_mode;
104 + for (i = 0; i < params->supported_rates_len; i++) {
105 + int rate = (params->supported_rates[i] & 0x7f) * 5;
106 + for (j = 0; j < mode->num_rates; j++) {
107 + if (mode->rates[j].rate == rate)
108 + rates |= BIT(j);
109 + }
110 + }
111 + sta->supp_rates = rates;
112 + }
113 +}
114 +
115 +static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
116 + u8 *mac, struct station_parameters *params)
117 +{
118 + struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
119 + struct sta_info *sta;
120 + struct ieee80211_sub_if_data *sdata;
121 +
122 + /* Prevent a race with changing the rate control algorithm */
123 + if (!netif_running(dev))
124 + return -ENETDOWN;
125 +
126 + /* XXX: get sta belonging to dev */
127 + sta = sta_info_get(local, mac);
128 + if (sta) {
129 + sta_info_put(sta);
130 + return -EEXIST;
131 + }
132 +
133 + if (params->vlan) {
134 + sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
135 +
136 + if (sdata->type != IEEE80211_IF_TYPE_VLAN ||
137 + sdata->type != IEEE80211_IF_TYPE_AP)
138 + return -EINVAL;
139 + } else
140 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
141 +
142 + sta = sta_info_add(local, dev, mac, GFP_KERNEL);
143 + if (!sta)
144 + return -ENOMEM;
145 +
146 + sta->dev = sdata->dev;
147 + if (sdata->type == IEEE80211_IF_TYPE_VLAN ||
148 + sdata->type == IEEE80211_IF_TYPE_AP)
149 + ieee80211_send_layer2_update(sta);
150 +
151 + sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
152 +
153 + sta_apply_parameters(local, sta, params);
154 +
155 + rate_control_rate_init(sta, local);
156 +
157 + sta_info_put(sta);
158 +
159 + return 0;
160 +}
161 +
162 +static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
163 + u8 *mac)
164 +{
165 + struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
166 + struct sta_info *sta;
167 +
168 + if (mac) {
169 + /* XXX: get sta belonging to dev */
170 + sta = sta_info_get(local, mac);
171 + if (!sta)
172 + return -ENOENT;
173 +
174 + sta_info_free(sta);
175 + sta_info_put(sta);
176 + } else
177 + sta_info_flush(local, dev);
178 +
179 + return 0;
180 +}
181 +
182 +static int ieee80211_change_station(struct wiphy *wiphy,
183 + struct net_device *dev,
184 + u8 *mac,
185 + struct station_parameters *params)
186 +{
187 + struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
188 + struct sta_info *sta;
189 + struct ieee80211_sub_if_data *vlansdata;
190 +
191 + /* XXX: get sta belonging to dev */
192 + sta = sta_info_get(local, mac);
193 + if (!sta)
194 + return -ENOENT;
195 +
196 + if (params->vlan && params->vlan != sta->dev) {
197 + vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
198 +
199 + if (vlansdata->type != IEEE80211_IF_TYPE_VLAN ||
200 + vlansdata->type != IEEE80211_IF_TYPE_AP)
201 + return -EINVAL;
202 +
203 + sta->dev = params->vlan;
204 + ieee80211_send_layer2_update(sta);
205 + }
206 +
207 + sta_apply_parameters(local, sta, params);
208 +
209 + sta_info_put(sta);
210 +
211 + return 0;
212 +}
213 +
214 struct cfg80211_ops mac80211_config_ops = {
215 .add_virtual_intf = ieee80211_add_iface,
216 .del_virtual_intf = ieee80211_del_iface,
217 @@ -439,4 +628,7 @@ struct cfg80211_ops mac80211_config_ops
218 .add_beacon = ieee80211_add_beacon,
219 .set_beacon = ieee80211_set_beacon,
220 .del_beacon = ieee80211_del_beacon,
221 + .add_station = ieee80211_add_station,
222 + .del_station = ieee80211_del_station,
223 + .change_station = ieee80211_change_station,
224 };
This page took 0.067707 seconds and 5 git commands to generate.