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