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