Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * mac80211 configuration hooks for cfg80211 |
| 3 | * |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 4 | * Copyright 2006, 2007 Johannes Berg <johannes@sipsolutions.net> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 5 | * |
| 6 | * This file is GPLv2 as found in COPYING. |
| 7 | */ |
| 8 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 9 | #include <linux/ieee80211.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 10 | #include <linux/nl80211.h> |
| 11 | #include <linux/rtnetlink.h> |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 12 | #include <net/net_namespace.h> |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 13 | #include <linux/rcupdate.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 14 | #include <net/cfg80211.h> |
| 15 | #include "ieee80211_i.h" |
Michael Wu | e0eb685 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 16 | #include "cfg.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 17 | #include "rate.h" |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 18 | #include "mesh.h" |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 19 | |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 20 | static enum ieee80211_if_types |
| 21 | nl80211_type_to_mac80211_type(enum nl80211_iftype type) |
| 22 | { |
| 23 | switch (type) { |
| 24 | case NL80211_IFTYPE_UNSPECIFIED: |
| 25 | return IEEE80211_IF_TYPE_STA; |
| 26 | case NL80211_IFTYPE_ADHOC: |
| 27 | return IEEE80211_IF_TYPE_IBSS; |
| 28 | case NL80211_IFTYPE_STATION: |
| 29 | return IEEE80211_IF_TYPE_STA; |
| 30 | case NL80211_IFTYPE_MONITOR: |
| 31 | return IEEE80211_IF_TYPE_MNTR; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 32 | #ifdef CONFIG_MAC80211_MESH |
| 33 | case NL80211_IFTYPE_MESH_POINT: |
| 34 | return IEEE80211_IF_TYPE_MESH_POINT; |
| 35 | #endif |
Johannes Berg | b454048 | 2008-04-14 15:37:03 +0200 | [diff] [blame] | 36 | case NL80211_IFTYPE_WDS: |
| 37 | return IEEE80211_IF_TYPE_WDS; |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 38 | default: |
| 39 | return IEEE80211_IF_TYPE_INVALID; |
| 40 | } |
| 41 | } |
| 42 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 43 | static int ieee80211_add_iface(struct wiphy *wiphy, char *name, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 44 | enum nl80211_iftype type, u32 *flags, |
| 45 | struct vif_params *params) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 46 | { |
| 47 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 48 | enum ieee80211_if_types itype; |
Michael Wu | 8cc9a73 | 2008-01-31 19:48:23 +0100 | [diff] [blame] | 49 | struct net_device *dev; |
| 50 | struct ieee80211_sub_if_data *sdata; |
| 51 | int err; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 52 | |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 53 | itype = nl80211_type_to_mac80211_type(type); |
| 54 | if (itype == IEEE80211_IF_TYPE_INVALID) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 55 | return -EINVAL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 56 | |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 57 | err = ieee80211_if_add(local, name, &dev, itype, params); |
Michael Wu | 8cc9a73 | 2008-01-31 19:48:23 +0100 | [diff] [blame] | 58 | if (err || itype != IEEE80211_IF_TYPE_MNTR || !flags) |
| 59 | return err; |
| 60 | |
| 61 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 62 | sdata->u.mntr_flags = *flags; |
| 63 | return 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex) |
| 67 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 68 | struct net_device *dev; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 69 | |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 70 | /* we're under RTNL */ |
| 71 | dev = __dev_get_by_index(&init_net, ifindex); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 72 | if (!dev) |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 73 | return -ENODEV; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 74 | |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 75 | ieee80211_if_remove(dev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 76 | |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 77 | return 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 80 | static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 81 | enum nl80211_iftype type, u32 *flags, |
| 82 | struct vif_params *params) |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 83 | { |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 84 | struct net_device *dev; |
| 85 | enum ieee80211_if_types itype; |
| 86 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | f3947e2 | 2008-07-09 14:40:36 +0200 | [diff] [blame^] | 87 | int ret; |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 88 | |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 89 | /* we're under RTNL */ |
| 90 | dev = __dev_get_by_index(&init_net, ifindex); |
| 91 | if (!dev) |
| 92 | return -ENODEV; |
| 93 | |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 94 | itype = nl80211_type_to_mac80211_type(type); |
| 95 | if (itype == IEEE80211_IF_TYPE_INVALID) |
| 96 | return -EINVAL; |
| 97 | |
| 98 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 99 | |
Johannes Berg | f3947e2 | 2008-07-09 14:40:36 +0200 | [diff] [blame^] | 100 | ret = ieee80211_if_change_type(sdata, itype); |
| 101 | if (ret) |
| 102 | return ret; |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 103 | |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 104 | if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len) |
| 105 | ieee80211_if_sta_set_mesh_id(&sdata->u.sta, |
| 106 | params->mesh_id_len, |
| 107 | params->mesh_id); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 108 | |
Michael Wu | 8cc9a73 | 2008-01-31 19:48:23 +0100 | [diff] [blame] | 109 | if (sdata->vif.type != IEEE80211_IF_TYPE_MNTR || !flags) |
| 110 | return 0; |
| 111 | |
| 112 | sdata->u.mntr_flags = *flags; |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 113 | return 0; |
| 114 | } |
| 115 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 116 | static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev, |
| 117 | u8 key_idx, u8 *mac_addr, |
| 118 | struct key_params *params) |
| 119 | { |
| 120 | struct ieee80211_sub_if_data *sdata; |
| 121 | struct sta_info *sta = NULL; |
| 122 | enum ieee80211_key_alg alg; |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 123 | struct ieee80211_key *key; |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 124 | int err; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 125 | |
| 126 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 127 | |
| 128 | switch (params->cipher) { |
| 129 | case WLAN_CIPHER_SUITE_WEP40: |
| 130 | case WLAN_CIPHER_SUITE_WEP104: |
| 131 | alg = ALG_WEP; |
| 132 | break; |
| 133 | case WLAN_CIPHER_SUITE_TKIP: |
| 134 | alg = ALG_TKIP; |
| 135 | break; |
| 136 | case WLAN_CIPHER_SUITE_CCMP: |
| 137 | alg = ALG_CCMP; |
| 138 | break; |
| 139 | default: |
| 140 | return -EINVAL; |
| 141 | } |
| 142 | |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 143 | key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key); |
| 144 | if (!key) |
| 145 | return -ENOMEM; |
| 146 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 147 | rcu_read_lock(); |
| 148 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 149 | if (mac_addr) { |
| 150 | sta = sta_info_get(sdata->local, mac_addr); |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 151 | if (!sta) { |
| 152 | ieee80211_key_free(key); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 153 | err = -ENOENT; |
| 154 | goto out_unlock; |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 155 | } |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 156 | } |
| 157 | |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 158 | ieee80211_key_link(key, sdata, sta); |
| 159 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 160 | err = 0; |
| 161 | out_unlock: |
| 162 | rcu_read_unlock(); |
| 163 | |
| 164 | return err; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev, |
| 168 | u8 key_idx, u8 *mac_addr) |
| 169 | { |
| 170 | struct ieee80211_sub_if_data *sdata; |
| 171 | struct sta_info *sta; |
| 172 | int ret; |
| 173 | |
| 174 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 175 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 176 | rcu_read_lock(); |
| 177 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 178 | if (mac_addr) { |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 179 | ret = -ENOENT; |
| 180 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 181 | sta = sta_info_get(sdata->local, mac_addr); |
| 182 | if (!sta) |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 183 | goto out_unlock; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 184 | |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 185 | if (sta->key) { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 186 | ieee80211_key_free(sta->key); |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 187 | WARN_ON(sta->key); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 188 | ret = 0; |
| 189 | } |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 190 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 191 | goto out_unlock; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 192 | } |
| 193 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 194 | if (!sdata->keys[key_idx]) { |
| 195 | ret = -ENOENT; |
| 196 | goto out_unlock; |
| 197 | } |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 198 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 199 | ieee80211_key_free(sdata->keys[key_idx]); |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 200 | WARN_ON(sdata->keys[key_idx]); |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 201 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 202 | ret = 0; |
| 203 | out_unlock: |
| 204 | rcu_read_unlock(); |
| 205 | |
| 206 | return ret; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 207 | } |
| 208 | |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 209 | static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev, |
| 210 | u8 key_idx, u8 *mac_addr, void *cookie, |
| 211 | void (*callback)(void *cookie, |
| 212 | struct key_params *params)) |
| 213 | { |
| 214 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 215 | struct sta_info *sta = NULL; |
| 216 | u8 seq[6] = {0}; |
| 217 | struct key_params params; |
| 218 | struct ieee80211_key *key; |
| 219 | u32 iv32; |
| 220 | u16 iv16; |
| 221 | int err = -ENOENT; |
| 222 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 223 | rcu_read_lock(); |
| 224 | |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 225 | if (mac_addr) { |
| 226 | sta = sta_info_get(sdata->local, mac_addr); |
| 227 | if (!sta) |
| 228 | goto out; |
| 229 | |
| 230 | key = sta->key; |
| 231 | } else |
| 232 | key = sdata->keys[key_idx]; |
| 233 | |
| 234 | if (!key) |
| 235 | goto out; |
| 236 | |
| 237 | memset(¶ms, 0, sizeof(params)); |
| 238 | |
| 239 | switch (key->conf.alg) { |
| 240 | case ALG_TKIP: |
| 241 | params.cipher = WLAN_CIPHER_SUITE_TKIP; |
| 242 | |
Harvey Harrison | b0f76b3 | 2008-05-14 16:26:19 -0700 | [diff] [blame] | 243 | iv32 = key->u.tkip.tx.iv32; |
| 244 | iv16 = key->u.tkip.tx.iv16; |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 245 | |
| 246 | if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE && |
| 247 | sdata->local->ops->get_tkip_seq) |
| 248 | sdata->local->ops->get_tkip_seq( |
| 249 | local_to_hw(sdata->local), |
| 250 | key->conf.hw_key_idx, |
| 251 | &iv32, &iv16); |
| 252 | |
| 253 | seq[0] = iv16 & 0xff; |
| 254 | seq[1] = (iv16 >> 8) & 0xff; |
| 255 | seq[2] = iv32 & 0xff; |
| 256 | seq[3] = (iv32 >> 8) & 0xff; |
| 257 | seq[4] = (iv32 >> 16) & 0xff; |
| 258 | seq[5] = (iv32 >> 24) & 0xff; |
| 259 | params.seq = seq; |
| 260 | params.seq_len = 6; |
| 261 | break; |
| 262 | case ALG_CCMP: |
| 263 | params.cipher = WLAN_CIPHER_SUITE_CCMP; |
| 264 | seq[0] = key->u.ccmp.tx_pn[5]; |
| 265 | seq[1] = key->u.ccmp.tx_pn[4]; |
| 266 | seq[2] = key->u.ccmp.tx_pn[3]; |
| 267 | seq[3] = key->u.ccmp.tx_pn[2]; |
| 268 | seq[4] = key->u.ccmp.tx_pn[1]; |
| 269 | seq[5] = key->u.ccmp.tx_pn[0]; |
| 270 | params.seq = seq; |
| 271 | params.seq_len = 6; |
| 272 | break; |
| 273 | case ALG_WEP: |
| 274 | if (key->conf.keylen == 5) |
| 275 | params.cipher = WLAN_CIPHER_SUITE_WEP40; |
| 276 | else |
| 277 | params.cipher = WLAN_CIPHER_SUITE_WEP104; |
| 278 | break; |
| 279 | } |
| 280 | |
| 281 | params.key = key->conf.key; |
| 282 | params.key_len = key->conf.keylen; |
| 283 | |
| 284 | callback(cookie, ¶ms); |
| 285 | err = 0; |
| 286 | |
| 287 | out: |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 288 | rcu_read_unlock(); |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 289 | return err; |
| 290 | } |
| 291 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 292 | static int ieee80211_config_default_key(struct wiphy *wiphy, |
| 293 | struct net_device *dev, |
| 294 | u8 key_idx) |
| 295 | { |
| 296 | struct ieee80211_sub_if_data *sdata; |
| 297 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 298 | rcu_read_lock(); |
| 299 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 300 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 301 | ieee80211_set_default_key(sdata, key_idx); |
| 302 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 303 | rcu_read_unlock(); |
| 304 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 305 | return 0; |
| 306 | } |
| 307 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 308 | static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo) |
| 309 | { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 310 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 311 | |
| 312 | sinfo->filled = STATION_INFO_INACTIVE_TIME | |
| 313 | STATION_INFO_RX_BYTES | |
| 314 | STATION_INFO_TX_BYTES; |
| 315 | |
| 316 | sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx); |
| 317 | sinfo->rx_bytes = sta->rx_bytes; |
| 318 | sinfo->tx_bytes = sta->tx_bytes; |
| 319 | |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 320 | if (ieee80211_vif_is_mesh(&sdata->vif)) { |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 321 | #ifdef CONFIG_MAC80211_MESH |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 322 | sinfo->filled |= STATION_INFO_LLID | |
| 323 | STATION_INFO_PLID | |
| 324 | STATION_INFO_PLINK_STATE; |
| 325 | |
| 326 | sinfo->llid = le16_to_cpu(sta->llid); |
| 327 | sinfo->plid = le16_to_cpu(sta->plid); |
| 328 | sinfo->plink_state = sta->plink_state; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 329 | #endif |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 330 | } |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | |
| 334 | static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev, |
| 335 | int idx, u8 *mac, struct station_info *sinfo) |
| 336 | { |
| 337 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 338 | struct sta_info *sta; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 339 | int ret = -ENOENT; |
| 340 | |
| 341 | rcu_read_lock(); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 342 | |
| 343 | sta = sta_info_get_by_idx(local, idx, dev); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 344 | if (sta) { |
| 345 | ret = 0; |
| 346 | memcpy(mac, sta->addr, ETH_ALEN); |
| 347 | sta_set_sinfo(sta, sinfo); |
| 348 | } |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 349 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 350 | rcu_read_unlock(); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 351 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 352 | return ret; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 353 | } |
| 354 | |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 355 | static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 356 | u8 *mac, struct station_info *sinfo) |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 357 | { |
| 358 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 359 | struct sta_info *sta; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 360 | int ret = -ENOENT; |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 361 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 362 | rcu_read_lock(); |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 363 | |
| 364 | /* XXX: verify sta->dev == dev */ |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 365 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 366 | sta = sta_info_get(local, mac); |
| 367 | if (sta) { |
| 368 | ret = 0; |
| 369 | sta_set_sinfo(sta, sinfo); |
| 370 | } |
| 371 | |
| 372 | rcu_read_unlock(); |
| 373 | |
| 374 | return ret; |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 375 | } |
| 376 | |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 377 | /* |
| 378 | * This handles both adding a beacon and setting new beacon info |
| 379 | */ |
| 380 | static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata, |
| 381 | struct beacon_parameters *params) |
| 382 | { |
| 383 | struct beacon_data *new, *old; |
| 384 | int new_head_len, new_tail_len; |
| 385 | int size; |
| 386 | int err = -EINVAL; |
| 387 | |
| 388 | old = sdata->u.ap.beacon; |
| 389 | |
| 390 | /* head must not be zero-length */ |
| 391 | if (params->head && !params->head_len) |
| 392 | return -EINVAL; |
| 393 | |
| 394 | /* |
| 395 | * This is a kludge. beacon interval should really be part |
| 396 | * of the beacon information. |
| 397 | */ |
| 398 | if (params->interval) { |
| 399 | sdata->local->hw.conf.beacon_int = params->interval; |
| 400 | if (ieee80211_hw_config(sdata->local)) |
| 401 | return -EINVAL; |
| 402 | /* |
| 403 | * We updated some parameter so if below bails out |
| 404 | * it's not an error. |
| 405 | */ |
| 406 | err = 0; |
| 407 | } |
| 408 | |
| 409 | /* Need to have a beacon head if we don't have one yet */ |
| 410 | if (!params->head && !old) |
| 411 | return err; |
| 412 | |
| 413 | /* sorry, no way to start beaconing without dtim period */ |
| 414 | if (!params->dtim_period && !old) |
| 415 | return err; |
| 416 | |
| 417 | /* new or old head? */ |
| 418 | if (params->head) |
| 419 | new_head_len = params->head_len; |
| 420 | else |
| 421 | new_head_len = old->head_len; |
| 422 | |
| 423 | /* new or old tail? */ |
| 424 | if (params->tail || !old) |
| 425 | /* params->tail_len will be zero for !params->tail */ |
| 426 | new_tail_len = params->tail_len; |
| 427 | else |
| 428 | new_tail_len = old->tail_len; |
| 429 | |
| 430 | size = sizeof(*new) + new_head_len + new_tail_len; |
| 431 | |
| 432 | new = kzalloc(size, GFP_KERNEL); |
| 433 | if (!new) |
| 434 | return -ENOMEM; |
| 435 | |
| 436 | /* start filling the new info now */ |
| 437 | |
| 438 | /* new or old dtim period? */ |
| 439 | if (params->dtim_period) |
| 440 | new->dtim_period = params->dtim_period; |
| 441 | else |
| 442 | new->dtim_period = old->dtim_period; |
| 443 | |
| 444 | /* |
| 445 | * pointers go into the block we allocated, |
| 446 | * memory is | beacon_data | head | tail | |
| 447 | */ |
| 448 | new->head = ((u8 *) new) + sizeof(*new); |
| 449 | new->tail = new->head + new_head_len; |
| 450 | new->head_len = new_head_len; |
| 451 | new->tail_len = new_tail_len; |
| 452 | |
| 453 | /* copy in head */ |
| 454 | if (params->head) |
| 455 | memcpy(new->head, params->head, new_head_len); |
| 456 | else |
| 457 | memcpy(new->head, old->head, new_head_len); |
| 458 | |
| 459 | /* copy in optional tail */ |
| 460 | if (params->tail) |
| 461 | memcpy(new->tail, params->tail, new_tail_len); |
| 462 | else |
| 463 | if (old) |
| 464 | memcpy(new->tail, old->tail, new_tail_len); |
| 465 | |
| 466 | rcu_assign_pointer(sdata->u.ap.beacon, new); |
| 467 | |
| 468 | synchronize_rcu(); |
| 469 | |
| 470 | kfree(old); |
| 471 | |
| 472 | return ieee80211_if_config_beacon(sdata->dev); |
| 473 | } |
| 474 | |
| 475 | static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev, |
| 476 | struct beacon_parameters *params) |
| 477 | { |
| 478 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 479 | struct beacon_data *old; |
| 480 | |
| 481 | if (sdata->vif.type != IEEE80211_IF_TYPE_AP) |
| 482 | return -EINVAL; |
| 483 | |
| 484 | old = sdata->u.ap.beacon; |
| 485 | |
| 486 | if (old) |
| 487 | return -EALREADY; |
| 488 | |
| 489 | return ieee80211_config_beacon(sdata, params); |
| 490 | } |
| 491 | |
| 492 | static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev, |
| 493 | struct beacon_parameters *params) |
| 494 | { |
| 495 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 496 | struct beacon_data *old; |
| 497 | |
| 498 | if (sdata->vif.type != IEEE80211_IF_TYPE_AP) |
| 499 | return -EINVAL; |
| 500 | |
| 501 | old = sdata->u.ap.beacon; |
| 502 | |
| 503 | if (!old) |
| 504 | return -ENOENT; |
| 505 | |
| 506 | return ieee80211_config_beacon(sdata, params); |
| 507 | } |
| 508 | |
| 509 | static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev) |
| 510 | { |
| 511 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 512 | struct beacon_data *old; |
| 513 | |
| 514 | if (sdata->vif.type != IEEE80211_IF_TYPE_AP) |
| 515 | return -EINVAL; |
| 516 | |
| 517 | old = sdata->u.ap.beacon; |
| 518 | |
| 519 | if (!old) |
| 520 | return -ENOENT; |
| 521 | |
| 522 | rcu_assign_pointer(sdata->u.ap.beacon, NULL); |
| 523 | synchronize_rcu(); |
| 524 | kfree(old); |
| 525 | |
| 526 | return ieee80211_if_config_beacon(dev); |
| 527 | } |
| 528 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 529 | /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */ |
| 530 | struct iapp_layer2_update { |
| 531 | u8 da[ETH_ALEN]; /* broadcast */ |
| 532 | u8 sa[ETH_ALEN]; /* STA addr */ |
| 533 | __be16 len; /* 6 */ |
| 534 | u8 dsap; /* 0 */ |
| 535 | u8 ssap; /* 0 */ |
| 536 | u8 control; |
| 537 | u8 xid_info[3]; |
| 538 | } __attribute__ ((packed)); |
| 539 | |
| 540 | static void ieee80211_send_layer2_update(struct sta_info *sta) |
| 541 | { |
| 542 | struct iapp_layer2_update *msg; |
| 543 | struct sk_buff *skb; |
| 544 | |
| 545 | /* Send Level 2 Update Frame to update forwarding tables in layer 2 |
| 546 | * bridge devices */ |
| 547 | |
| 548 | skb = dev_alloc_skb(sizeof(*msg)); |
| 549 | if (!skb) |
| 550 | return; |
| 551 | msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg)); |
| 552 | |
| 553 | /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID) |
| 554 | * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */ |
| 555 | |
| 556 | memset(msg->da, 0xff, ETH_ALEN); |
| 557 | memcpy(msg->sa, sta->addr, ETH_ALEN); |
| 558 | msg->len = htons(6); |
| 559 | msg->dsap = 0; |
| 560 | msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */ |
| 561 | msg->control = 0xaf; /* XID response lsb.1111F101. |
| 562 | * F=0 (no poll command; unsolicited frame) */ |
| 563 | msg->xid_info[0] = 0x81; /* XID format identifier */ |
| 564 | msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */ |
| 565 | msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */ |
| 566 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 567 | skb->dev = sta->sdata->dev; |
| 568 | skb->protocol = eth_type_trans(skb, sta->sdata->dev); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 569 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 570 | netif_rx(skb); |
| 571 | } |
| 572 | |
| 573 | static void sta_apply_parameters(struct ieee80211_local *local, |
| 574 | struct sta_info *sta, |
| 575 | struct station_parameters *params) |
| 576 | { |
| 577 | u32 rates; |
| 578 | int i, j; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 579 | struct ieee80211_supported_band *sband; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 580 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 581 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 582 | /* |
| 583 | * FIXME: updating the flags is racy when this function is |
| 584 | * called from ieee80211_change_station(), this will |
| 585 | * be resolved in a future patch. |
| 586 | */ |
| 587 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 588 | if (params->station_flags & STATION_FLAG_CHANGED) { |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 589 | spin_lock_bh(&sta->lock); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 590 | sta->flags &= ~WLAN_STA_AUTHORIZED; |
| 591 | if (params->station_flags & STATION_FLAG_AUTHORIZED) |
| 592 | sta->flags |= WLAN_STA_AUTHORIZED; |
| 593 | |
| 594 | sta->flags &= ~WLAN_STA_SHORT_PREAMBLE; |
| 595 | if (params->station_flags & STATION_FLAG_SHORT_PREAMBLE) |
| 596 | sta->flags |= WLAN_STA_SHORT_PREAMBLE; |
| 597 | |
| 598 | sta->flags &= ~WLAN_STA_WME; |
| 599 | if (params->station_flags & STATION_FLAG_WME) |
| 600 | sta->flags |= WLAN_STA_WME; |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 601 | spin_unlock_bh(&sta->lock); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 602 | } |
| 603 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 604 | /* |
| 605 | * FIXME: updating the following information is racy when this |
| 606 | * function is called from ieee80211_change_station(). |
| 607 | * However, all this information should be static so |
| 608 | * maybe we should just reject attemps to change it. |
| 609 | */ |
| 610 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 611 | if (params->aid) { |
| 612 | sta->aid = params->aid; |
| 613 | if (sta->aid > IEEE80211_MAX_AID) |
| 614 | sta->aid = 0; /* XXX: should this be an error? */ |
| 615 | } |
| 616 | |
| 617 | if (params->listen_interval >= 0) |
| 618 | sta->listen_interval = params->listen_interval; |
| 619 | |
| 620 | if (params->supported_rates) { |
| 621 | rates = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 622 | sband = local->hw.wiphy->bands[local->oper_channel->band]; |
| 623 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 624 | for (i = 0; i < params->supported_rates_len; i++) { |
| 625 | int rate = (params->supported_rates[i] & 0x7f) * 5; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 626 | for (j = 0; j < sband->n_bitrates; j++) { |
| 627 | if (sband->bitrates[j].bitrate == rate) |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 628 | rates |= BIT(j); |
| 629 | } |
| 630 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 631 | sta->supp_rates[local->oper_channel->band] = rates; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 632 | } |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 633 | |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 634 | if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) { |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 635 | switch (params->plink_action) { |
| 636 | case PLINK_ACTION_OPEN: |
| 637 | mesh_plink_open(sta); |
| 638 | break; |
| 639 | case PLINK_ACTION_BLOCK: |
| 640 | mesh_plink_block(sta); |
| 641 | break; |
| 642 | } |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 643 | } |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev, |
| 647 | u8 *mac, struct station_parameters *params) |
| 648 | { |
| 649 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 650 | struct sta_info *sta; |
| 651 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 652 | int err; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 653 | |
| 654 | /* Prevent a race with changing the rate control algorithm */ |
| 655 | if (!netif_running(dev)) |
| 656 | return -ENETDOWN; |
| 657 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 658 | if (params->vlan) { |
| 659 | sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); |
| 660 | |
Nicolas Kaiser | 679fda1 | 2008-05-20 18:42:54 +0200 | [diff] [blame] | 661 | if (sdata->vif.type != IEEE80211_IF_TYPE_VLAN && |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 662 | sdata->vif.type != IEEE80211_IF_TYPE_AP) |
| 663 | return -EINVAL; |
| 664 | } else |
| 665 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 666 | |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 667 | if (compare_ether_addr(mac, dev->dev_addr) == 0) |
| 668 | return -EINVAL; |
| 669 | |
| 670 | if (is_multicast_ether_addr(mac)) |
| 671 | return -EINVAL; |
| 672 | |
| 673 | sta = sta_info_alloc(sdata, mac, GFP_KERNEL); |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 674 | if (!sta) |
| 675 | return -ENOMEM; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 676 | |
| 677 | sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC; |
| 678 | |
| 679 | sta_apply_parameters(local, sta, params); |
| 680 | |
| 681 | rate_control_rate_init(sta, local); |
| 682 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 683 | rcu_read_lock(); |
| 684 | |
| 685 | err = sta_info_insert(sta); |
| 686 | if (err) { |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 687 | /* STA has been freed */ |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 688 | rcu_read_unlock(); |
| 689 | return err; |
| 690 | } |
| 691 | |
| 692 | if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN || |
| 693 | sdata->vif.type == IEEE80211_IF_TYPE_AP) |
| 694 | ieee80211_send_layer2_update(sta); |
| 695 | |
| 696 | rcu_read_unlock(); |
| 697 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 698 | return 0; |
| 699 | } |
| 700 | |
| 701 | static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev, |
| 702 | u8 *mac) |
| 703 | { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 704 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 705 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 706 | struct sta_info *sta; |
| 707 | |
| 708 | if (mac) { |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 709 | rcu_read_lock(); |
| 710 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 711 | /* XXX: get sta belonging to dev */ |
| 712 | sta = sta_info_get(local, mac); |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 713 | if (!sta) { |
| 714 | rcu_read_unlock(); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 715 | return -ENOENT; |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 716 | } |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 717 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 718 | sta_info_unlink(&sta); |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 719 | rcu_read_unlock(); |
| 720 | |
Johannes Berg | 4f6fab4 | 2008-03-31 19:23:02 +0200 | [diff] [blame] | 721 | sta_info_destroy(sta); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 722 | } else |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 723 | sta_info_flush(local, sdata); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 724 | |
| 725 | return 0; |
| 726 | } |
| 727 | |
| 728 | static int ieee80211_change_station(struct wiphy *wiphy, |
| 729 | struct net_device *dev, |
| 730 | u8 *mac, |
| 731 | struct station_parameters *params) |
| 732 | { |
| 733 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 734 | struct sta_info *sta; |
| 735 | struct ieee80211_sub_if_data *vlansdata; |
| 736 | |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 737 | rcu_read_lock(); |
| 738 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 739 | /* XXX: get sta belonging to dev */ |
| 740 | sta = sta_info_get(local, mac); |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 741 | if (!sta) { |
| 742 | rcu_read_unlock(); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 743 | return -ENOENT; |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 744 | } |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 745 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 746 | if (params->vlan && params->vlan != sta->sdata->dev) { |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 747 | vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); |
| 748 | |
Nicolas Kaiser | 679fda1 | 2008-05-20 18:42:54 +0200 | [diff] [blame] | 749 | if (vlansdata->vif.type != IEEE80211_IF_TYPE_VLAN && |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 750 | vlansdata->vif.type != IEEE80211_IF_TYPE_AP) { |
| 751 | rcu_read_unlock(); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 752 | return -EINVAL; |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 753 | } |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 754 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 755 | sta->sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 756 | ieee80211_send_layer2_update(sta); |
| 757 | } |
| 758 | |
| 759 | sta_apply_parameters(local, sta, params); |
| 760 | |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 761 | rcu_read_unlock(); |
| 762 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 763 | return 0; |
| 764 | } |
| 765 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 766 | #ifdef CONFIG_MAC80211_MESH |
| 767 | static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev, |
| 768 | u8 *dst, u8 *next_hop) |
| 769 | { |
| 770 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 771 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 772 | struct mesh_path *mpath; |
| 773 | struct sta_info *sta; |
| 774 | int err; |
| 775 | |
| 776 | if (!netif_running(dev)) |
| 777 | return -ENETDOWN; |
| 778 | |
| 779 | if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT) |
| 780 | return -ENOTSUPP; |
| 781 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 782 | rcu_read_lock(); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 783 | sta = sta_info_get(local, next_hop); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 784 | if (!sta) { |
| 785 | rcu_read_unlock(); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 786 | return -ENOENT; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 787 | } |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 788 | |
| 789 | err = mesh_path_add(dst, dev); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 790 | if (err) { |
| 791 | rcu_read_unlock(); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 792 | return err; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 793 | } |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 794 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 795 | mpath = mesh_path_lookup(dst, dev); |
| 796 | if (!mpath) { |
| 797 | rcu_read_unlock(); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 798 | return -ENXIO; |
| 799 | } |
| 800 | mesh_path_fix_nexthop(mpath, sta); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 801 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 802 | rcu_read_unlock(); |
| 803 | return 0; |
| 804 | } |
| 805 | |
| 806 | static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev, |
| 807 | u8 *dst) |
| 808 | { |
| 809 | if (dst) |
Luis Carlos Cobo | cfa22c7 | 2008-02-29 15:04:13 -0800 | [diff] [blame] | 810 | return mesh_path_del(dst, dev); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 811 | |
| 812 | mesh_path_flush(dev); |
| 813 | return 0; |
| 814 | } |
| 815 | |
| 816 | static int ieee80211_change_mpath(struct wiphy *wiphy, |
| 817 | struct net_device *dev, |
| 818 | u8 *dst, u8 *next_hop) |
| 819 | { |
| 820 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 821 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 822 | struct mesh_path *mpath; |
| 823 | struct sta_info *sta; |
| 824 | |
| 825 | if (!netif_running(dev)) |
| 826 | return -ENETDOWN; |
| 827 | |
| 828 | if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT) |
| 829 | return -ENOTSUPP; |
| 830 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 831 | rcu_read_lock(); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 832 | |
| 833 | sta = sta_info_get(local, next_hop); |
| 834 | if (!sta) { |
| 835 | rcu_read_unlock(); |
| 836 | return -ENOENT; |
| 837 | } |
| 838 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 839 | mpath = mesh_path_lookup(dst, dev); |
| 840 | if (!mpath) { |
| 841 | rcu_read_unlock(); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 842 | return -ENOENT; |
| 843 | } |
| 844 | |
| 845 | mesh_path_fix_nexthop(mpath, sta); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 846 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 847 | rcu_read_unlock(); |
| 848 | return 0; |
| 849 | } |
| 850 | |
| 851 | static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop, |
| 852 | struct mpath_info *pinfo) |
| 853 | { |
| 854 | if (mpath->next_hop) |
| 855 | memcpy(next_hop, mpath->next_hop->addr, ETH_ALEN); |
| 856 | else |
| 857 | memset(next_hop, 0, ETH_ALEN); |
| 858 | |
| 859 | pinfo->filled = MPATH_INFO_FRAME_QLEN | |
| 860 | MPATH_INFO_DSN | |
| 861 | MPATH_INFO_METRIC | |
| 862 | MPATH_INFO_EXPTIME | |
| 863 | MPATH_INFO_DISCOVERY_TIMEOUT | |
| 864 | MPATH_INFO_DISCOVERY_RETRIES | |
| 865 | MPATH_INFO_FLAGS; |
| 866 | |
| 867 | pinfo->frame_qlen = mpath->frame_queue.qlen; |
| 868 | pinfo->dsn = mpath->dsn; |
| 869 | pinfo->metric = mpath->metric; |
| 870 | if (time_before(jiffies, mpath->exp_time)) |
| 871 | pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies); |
| 872 | pinfo->discovery_timeout = |
| 873 | jiffies_to_msecs(mpath->discovery_timeout); |
| 874 | pinfo->discovery_retries = mpath->discovery_retries; |
| 875 | pinfo->flags = 0; |
| 876 | if (mpath->flags & MESH_PATH_ACTIVE) |
| 877 | pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE; |
| 878 | if (mpath->flags & MESH_PATH_RESOLVING) |
| 879 | pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING; |
| 880 | if (mpath->flags & MESH_PATH_DSN_VALID) |
| 881 | pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID; |
| 882 | if (mpath->flags & MESH_PATH_FIXED) |
| 883 | pinfo->flags |= NL80211_MPATH_FLAG_FIXED; |
| 884 | if (mpath->flags & MESH_PATH_RESOLVING) |
| 885 | pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING; |
| 886 | |
| 887 | pinfo->flags = mpath->flags; |
| 888 | } |
| 889 | |
| 890 | static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev, |
| 891 | u8 *dst, u8 *next_hop, struct mpath_info *pinfo) |
| 892 | |
| 893 | { |
| 894 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 895 | struct mesh_path *mpath; |
| 896 | |
| 897 | if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT) |
| 898 | return -ENOTSUPP; |
| 899 | |
| 900 | rcu_read_lock(); |
| 901 | mpath = mesh_path_lookup(dst, dev); |
| 902 | if (!mpath) { |
| 903 | rcu_read_unlock(); |
| 904 | return -ENOENT; |
| 905 | } |
| 906 | memcpy(dst, mpath->dst, ETH_ALEN); |
| 907 | mpath_set_pinfo(mpath, next_hop, pinfo); |
| 908 | rcu_read_unlock(); |
| 909 | return 0; |
| 910 | } |
| 911 | |
| 912 | static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev, |
| 913 | int idx, u8 *dst, u8 *next_hop, |
| 914 | struct mpath_info *pinfo) |
| 915 | { |
| 916 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 917 | struct mesh_path *mpath; |
| 918 | |
| 919 | if (sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT) |
| 920 | return -ENOTSUPP; |
| 921 | |
| 922 | rcu_read_lock(); |
| 923 | mpath = mesh_path_lookup_by_idx(idx, dev); |
| 924 | if (!mpath) { |
| 925 | rcu_read_unlock(); |
| 926 | return -ENOENT; |
| 927 | } |
| 928 | memcpy(dst, mpath->dst, ETH_ALEN); |
| 929 | mpath_set_pinfo(mpath, next_hop, pinfo); |
| 930 | rcu_read_unlock(); |
| 931 | return 0; |
| 932 | } |
| 933 | #endif |
| 934 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 935 | struct cfg80211_ops mac80211_config_ops = { |
| 936 | .add_virtual_intf = ieee80211_add_iface, |
| 937 | .del_virtual_intf = ieee80211_del_iface, |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 938 | .change_virtual_intf = ieee80211_change_iface, |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 939 | .add_key = ieee80211_add_key, |
| 940 | .del_key = ieee80211_del_key, |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 941 | .get_key = ieee80211_get_key, |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 942 | .set_default_key = ieee80211_config_default_key, |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 943 | .add_beacon = ieee80211_add_beacon, |
| 944 | .set_beacon = ieee80211_set_beacon, |
| 945 | .del_beacon = ieee80211_del_beacon, |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 946 | .add_station = ieee80211_add_station, |
| 947 | .del_station = ieee80211_del_station, |
| 948 | .change_station = ieee80211_change_station, |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 949 | .get_station = ieee80211_get_station, |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 950 | .dump_station = ieee80211_dump_station, |
| 951 | #ifdef CONFIG_MAC80211_MESH |
| 952 | .add_mpath = ieee80211_add_mpath, |
| 953 | .del_mpath = ieee80211_del_mpath, |
| 954 | .change_mpath = ieee80211_change_mpath, |
| 955 | .get_mpath = ieee80211_get_mpath, |
| 956 | .dump_mpath = ieee80211_dump_mpath, |
| 957 | #endif |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 958 | }; |