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