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