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