1 Subject: mac80211: implement cfg80211's station handling
3 This implements station handling from userspace via cfg80211
6 Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
9 net/mac80211/cfg.c | 192 +++++++++++++++++++++++++++++++++++++++++++++++++++++
10 1 file changed, 192 insertions(+)
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
15 #include <net/cfg80211.h>
16 #include "ieee80211_i.h"
18 +#include "ieee80211_rate.h"
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);
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 */
35 +} __attribute__ ((packed));
37 +static void ieee80211_send_layer2_update(struct sta_info *sta)
39 + struct iapp_layer2_update *msg;
40 + struct sk_buff *skb;
42 + /* Send Level 2 Update Frame to update forwarding tables in layer 2
45 + skb = dev_alloc_skb(sizeof(*msg));
48 + msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
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 */
53 + memset(msg->da, 0xff, ETH_ALEN);
54 + memcpy(msg->sa, sta->addr, ETH_ALEN);
55 + msg->len = htons(6);
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) */
64 + skb->dev = sta->dev;
65 + skb->protocol = eth_type_trans(skb, sta->dev);
66 + memset(skb->cb, 0, sizeof(skb->cb));
70 +static void sta_apply_parameters(struct ieee80211_local *local,
71 + struct sta_info *sta,
72 + struct station_parameters *params)
76 + struct ieee80211_hw_mode *mode;
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;
83 + sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
84 + if (params->station_flags & STATION_FLAG_SHORT_PREAMBLE)
85 + sta->flags |= WLAN_STA_SHORT_PREAMBLE;
87 + sta->flags &= ~WLAN_STA_WME;
88 + if (params->station_flags & STATION_FLAG_WME)
89 + sta->flags |= WLAN_STA_WME;
93 + sta->aid = params->aid;
94 + if (sta->aid > IEEE80211_MAX_AID)
95 + sta->aid = 0; /* XXX: should this be an error? */
98 + if (params->listen_interval >= 0)
99 + sta->listen_interval = params->listen_interval;
101 + if (params->supported_rates) {
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)
111 + sta->supp_rates = rates;
115 +static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
116 + u8 *mac, struct station_parameters *params)
118 + struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
119 + struct sta_info *sta;
120 + struct ieee80211_sub_if_data *sdata;
122 + /* Prevent a race with changing the rate control algorithm */
123 + if (!netif_running(dev))
126 + /* XXX: get sta belonging to dev */
127 + sta = sta_info_get(local, mac);
133 + if (params->vlan) {
134 + sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
136 + if (sdata->type != IEEE80211_IF_TYPE_VLAN ||
137 + sdata->type != IEEE80211_IF_TYPE_AP)
140 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
142 + sta = sta_info_add(local, dev, mac, GFP_KERNEL);
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);
151 + sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
153 + sta_apply_parameters(local, sta, params);
155 + rate_control_rate_init(sta, local);
162 +static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
165 + struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
166 + struct sta_info *sta;
169 + /* XXX: get sta belonging to dev */
170 + sta = sta_info_get(local, mac);
174 + sta_info_free(sta);
177 + sta_info_flush(local, dev);
182 +static int ieee80211_change_station(struct wiphy *wiphy,
183 + struct net_device *dev,
185 + struct station_parameters *params)
187 + struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
188 + struct sta_info *sta;
189 + struct ieee80211_sub_if_data *vlansdata;
191 + /* XXX: get sta belonging to dev */
192 + sta = sta_info_get(local, mac);
196 + if (params->vlan && params->vlan != sta->dev) {
197 + vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
199 + if (vlansdata->type != IEEE80211_IF_TYPE_VLAN ||
200 + vlansdata->type != IEEE80211_IF_TYPE_AP)
203 + sta->dev = params->vlan;
204 + ieee80211_send_layer2_update(sta);
207 + sta_apply_parameters(local, sta, params);
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,