Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * mac80211 configuration hooks for cfg80211 |
| 3 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 5 | * |
| 6 | * This file is GPLv2 as found in COPYING. |
| 7 | */ |
| 8 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 9 | #include <linux/ieee80211.h> |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 10 | #include <linux/nl80211.h> |
| 11 | #include <linux/rtnetlink.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 12 | #include <linux/slab.h> |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 13 | #include <net/net_namespace.h> |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 14 | #include <linux/rcupdate.h> |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 15 | #include <net/cfg80211.h> |
| 16 | #include "ieee80211_i.h" |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 17 | #include "driver-ops.h" |
Michael Wu | e0eb685 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 18 | #include "cfg.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 19 | #include "rate.h" |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 20 | #include "mesh.h" |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 21 | |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 22 | static int ieee80211_add_iface(struct wiphy *wiphy, char *name, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 23 | enum nl80211_iftype type, u32 *flags, |
| 24 | struct vif_params *params) |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 25 | { |
| 26 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Michael Wu | 8cc9a73 | 2008-01-31 19:48:23 +0100 | [diff] [blame] | 27 | struct net_device *dev; |
| 28 | struct ieee80211_sub_if_data *sdata; |
| 29 | int err; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 30 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 31 | err = ieee80211_if_add(local, name, &dev, type, params); |
| 32 | if (err || type != NL80211_IFTYPE_MONITOR || !flags) |
Michael Wu | 8cc9a73 | 2008-01-31 19:48:23 +0100 | [diff] [blame] | 33 | return err; |
| 34 | |
| 35 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 36 | sdata->u.mntr_flags = *flags; |
| 37 | return 0; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 40 | static int ieee80211_del_iface(struct wiphy *wiphy, struct net_device *dev) |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 41 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 42 | ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev)); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 43 | |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 44 | return 0; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 47 | static int ieee80211_change_iface(struct wiphy *wiphy, |
| 48 | struct net_device *dev, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 49 | enum nl80211_iftype type, u32 *flags, |
| 50 | struct vif_params *params) |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 51 | { |
Johannes Berg | 9607e6b | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 52 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | f3947e2 | 2008-07-09 14:40:36 +0200 | [diff] [blame] | 53 | int ret; |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 54 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 55 | ret = ieee80211_if_change_type(sdata, type); |
Johannes Berg | f3947e2 | 2008-07-09 14:40:36 +0200 | [diff] [blame] | 56 | if (ret) |
| 57 | return ret; |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 58 | |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 59 | if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len) |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 60 | ieee80211_sdata_set_mesh_id(sdata, |
| 61 | params->mesh_id_len, |
| 62 | params->mesh_id); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 63 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 64 | if (type == NL80211_IFTYPE_AP_VLAN && |
| 65 | params && params->use_4addr == 0) |
| 66 | rcu_assign_pointer(sdata->u.vlan.sta, NULL); |
| 67 | else if (type == NL80211_IFTYPE_STATION && |
| 68 | params && params->use_4addr >= 0) |
| 69 | sdata->u.mgd.use_4addr = params->use_4addr; |
| 70 | |
Christian Lamparter | 85416a4 | 2010-10-02 13:17:07 +0200 | [diff] [blame] | 71 | if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags) { |
| 72 | struct ieee80211_local *local = sdata->local; |
| 73 | |
| 74 | if (ieee80211_sdata_running(sdata)) { |
| 75 | /* |
| 76 | * Prohibit MONITOR_FLAG_COOK_FRAMES to be |
| 77 | * changed while the interface is up. |
| 78 | * Else we would need to add a lot of cruft |
| 79 | * to update everything: |
| 80 | * cooked_mntrs, monitor and all fif_* counters |
| 81 | * reconfigure hardware |
| 82 | */ |
| 83 | if ((*flags & MONITOR_FLAG_COOK_FRAMES) != |
| 84 | (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES)) |
| 85 | return -EBUSY; |
| 86 | |
| 87 | ieee80211_adjust_monitor_flags(sdata, -1); |
| 88 | sdata->u.mntr_flags = *flags; |
| 89 | ieee80211_adjust_monitor_flags(sdata, 1); |
| 90 | |
| 91 | ieee80211_configure_filter(local); |
| 92 | } else { |
| 93 | /* |
| 94 | * Because the interface is down, ieee80211_do_stop |
| 95 | * and ieee80211_do_open take care of "everything" |
| 96 | * mentioned in the comment above. |
| 97 | */ |
| 98 | sdata->u.mntr_flags = *flags; |
| 99 | } |
| 100 | } |
Felix Fietkau | f7917af | 2010-04-27 00:26:34 +0200 | [diff] [blame] | 101 | |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 102 | return 0; |
| 103 | } |
| 104 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 105 | static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | 4e94390 | 2009-05-09 20:06:47 +0200 | [diff] [blame] | 106 | u8 key_idx, const u8 *mac_addr, |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 107 | struct key_params *params) |
| 108 | { |
Johannes Berg | 26a5845 | 2010-08-27 12:35:55 +0200 | [diff] [blame] | 109 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 110 | struct sta_info *sta = NULL; |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 111 | struct ieee80211_key *key; |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 112 | int err; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 113 | |
Johannes Berg | 26a5845 | 2010-08-27 12:35:55 +0200 | [diff] [blame] | 114 | if (!ieee80211_sdata_running(sdata)) |
Johannes Berg | ad0e2b5 | 2010-06-01 10:19:19 +0200 | [diff] [blame] | 115 | return -ENETDOWN; |
| 116 | |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 117 | /* reject WEP and TKIP keys if WEP failed to initialize */ |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 118 | switch (params->cipher) { |
| 119 | case WLAN_CIPHER_SUITE_WEP40: |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 120 | case WLAN_CIPHER_SUITE_TKIP: |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 121 | case WLAN_CIPHER_SUITE_WEP104: |
| 122 | if (IS_ERR(sdata->local->wep_tx_tfm)) |
| 123 | return -EINVAL; |
Jouni Malinen | 3cfcf6a | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 124 | break; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 125 | default: |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 126 | break; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 127 | } |
| 128 | |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 129 | key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len, |
| 130 | params->key, params->seq_len, params->seq); |
Ben Hutchings | 1ac62ba | 2010-08-01 17:37:03 +0100 | [diff] [blame] | 131 | if (IS_ERR(key)) |
| 132 | return PTR_ERR(key); |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 133 | |
Johannes Berg | ad0e2b5 | 2010-06-01 10:19:19 +0200 | [diff] [blame] | 134 | mutex_lock(&sdata->local->sta_mtx); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 135 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 136 | if (mac_addr) { |
Felix Fietkau | 0e5ded5 | 2010-01-08 18:10:58 +0100 | [diff] [blame] | 137 | sta = sta_info_get_bss(sdata, mac_addr); |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 138 | if (!sta) { |
Jouni Malinen | 32162a4 | 2010-07-26 15:52:03 -0700 | [diff] [blame] | 139 | ieee80211_key_free(sdata->local, 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 | 3ffc2a9 | 2010-08-27 14:26:52 +0300 | [diff] [blame] | 145 | err = ieee80211_key_link(key, sdata, sta); |
| 146 | if (err) |
| 147 | ieee80211_key_free(sdata->local, key); |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 148 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 149 | out_unlock: |
Johannes Berg | ad0e2b5 | 2010-06-01 10:19:19 +0200 | [diff] [blame] | 150 | mutex_unlock(&sdata->local->sta_mtx); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 151 | |
| 152 | return err; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | 4e94390 | 2009-05-09 20:06:47 +0200 | [diff] [blame] | 156 | u8 key_idx, const u8 *mac_addr) |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 157 | { |
| 158 | struct ieee80211_sub_if_data *sdata; |
| 159 | struct sta_info *sta; |
| 160 | int ret; |
| 161 | |
| 162 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 163 | |
Johannes Berg | ad0e2b5 | 2010-06-01 10:19:19 +0200 | [diff] [blame] | 164 | mutex_lock(&sdata->local->sta_mtx); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 165 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 166 | if (mac_addr) { |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 167 | ret = -ENOENT; |
| 168 | |
Felix Fietkau | 0e5ded5 | 2010-01-08 18:10:58 +0100 | [diff] [blame] | 169 | sta = sta_info_get_bss(sdata, mac_addr); |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 170 | if (!sta) |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 171 | goto out_unlock; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 172 | |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 173 | if (sta->key) { |
Jouni Malinen | 32162a4 | 2010-07-26 15:52:03 -0700 | [diff] [blame] | 174 | ieee80211_key_free(sdata->local, sta->key); |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 175 | WARN_ON(sta->key); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 176 | ret = 0; |
| 177 | } |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 178 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 179 | goto out_unlock; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 180 | } |
| 181 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 182 | if (!sdata->keys[key_idx]) { |
| 183 | ret = -ENOENT; |
| 184 | goto out_unlock; |
| 185 | } |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 186 | |
Jouni Malinen | 32162a4 | 2010-07-26 15:52:03 -0700 | [diff] [blame] | 187 | ieee80211_key_free(sdata->local, sdata->keys[key_idx]); |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 188 | WARN_ON(sdata->keys[key_idx]); |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 189 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 190 | ret = 0; |
| 191 | out_unlock: |
Johannes Berg | ad0e2b5 | 2010-06-01 10:19:19 +0200 | [diff] [blame] | 192 | mutex_unlock(&sdata->local->sta_mtx); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 193 | |
| 194 | return ret; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 195 | } |
| 196 | |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 197 | static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | 4e94390 | 2009-05-09 20:06:47 +0200 | [diff] [blame] | 198 | u8 key_idx, const u8 *mac_addr, void *cookie, |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 199 | void (*callback)(void *cookie, |
| 200 | struct key_params *params)) |
| 201 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 202 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 203 | struct sta_info *sta = NULL; |
| 204 | u8 seq[6] = {0}; |
| 205 | struct key_params params; |
| 206 | struct ieee80211_key *key; |
| 207 | u32 iv32; |
| 208 | u16 iv16; |
| 209 | int err = -ENOENT; |
| 210 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 211 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 212 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 213 | rcu_read_lock(); |
| 214 | |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 215 | if (mac_addr) { |
Felix Fietkau | 0e5ded5 | 2010-01-08 18:10:58 +0100 | [diff] [blame] | 216 | sta = sta_info_get_bss(sdata, mac_addr); |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 217 | if (!sta) |
| 218 | goto out; |
| 219 | |
| 220 | key = sta->key; |
| 221 | } else |
| 222 | key = sdata->keys[key_idx]; |
| 223 | |
| 224 | if (!key) |
| 225 | goto out; |
| 226 | |
| 227 | memset(¶ms, 0, sizeof(params)); |
| 228 | |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 229 | params.cipher = key->conf.cipher; |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 230 | |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 231 | switch (key->conf.cipher) { |
| 232 | case WLAN_CIPHER_SUITE_TKIP: |
Harvey Harrison | b0f76b3 | 2008-05-14 16:26:19 -0700 | [diff] [blame] | 233 | iv32 = key->u.tkip.tx.iv32; |
| 234 | iv16 = key->u.tkip.tx.iv16; |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 235 | |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 236 | if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) |
| 237 | drv_get_tkip_seq(sdata->local, |
| 238 | key->conf.hw_key_idx, |
| 239 | &iv32, &iv16); |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 240 | |
| 241 | seq[0] = iv16 & 0xff; |
| 242 | seq[1] = (iv16 >> 8) & 0xff; |
| 243 | seq[2] = iv32 & 0xff; |
| 244 | seq[3] = (iv32 >> 8) & 0xff; |
| 245 | seq[4] = (iv32 >> 16) & 0xff; |
| 246 | seq[5] = (iv32 >> 24) & 0xff; |
| 247 | params.seq = seq; |
| 248 | params.seq_len = 6; |
| 249 | break; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 250 | case WLAN_CIPHER_SUITE_CCMP: |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 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; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 260 | case WLAN_CIPHER_SUITE_AES_CMAC: |
Jouni Malinen | 3cfcf6a | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 261 | seq[0] = key->u.aes_cmac.tx_pn[5]; |
| 262 | seq[1] = key->u.aes_cmac.tx_pn[4]; |
| 263 | seq[2] = key->u.aes_cmac.tx_pn[3]; |
| 264 | seq[3] = key->u.aes_cmac.tx_pn[2]; |
| 265 | seq[4] = key->u.aes_cmac.tx_pn[1]; |
| 266 | seq[5] = key->u.aes_cmac.tx_pn[0]; |
| 267 | params.seq = seq; |
| 268 | params.seq_len = 6; |
| 269 | break; |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | params.key = key->conf.key; |
| 273 | params.key_len = key->conf.keylen; |
| 274 | |
| 275 | callback(cookie, ¶ms); |
| 276 | err = 0; |
| 277 | |
| 278 | out: |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 279 | rcu_read_unlock(); |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 280 | return err; |
| 281 | } |
| 282 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 283 | static int ieee80211_config_default_key(struct wiphy *wiphy, |
| 284 | struct net_device *dev, |
| 285 | u8 key_idx) |
| 286 | { |
Johannes Berg | ad0e2b5 | 2010-06-01 10:19:19 +0200 | [diff] [blame] | 287 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 288 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 289 | ieee80211_set_default_key(sdata, key_idx); |
| 290 | |
| 291 | return 0; |
| 292 | } |
| 293 | |
Jouni Malinen | 3cfcf6a | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 294 | static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy, |
| 295 | struct net_device *dev, |
| 296 | u8 key_idx) |
| 297 | { |
Johannes Berg | 66c5242 | 2010-07-22 13:58:51 +0200 | [diff] [blame] | 298 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Jouni Malinen | 3cfcf6a | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 299 | |
Jouni Malinen | 3cfcf6a | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 300 | ieee80211_set_default_mgmt_key(sdata, key_idx); |
| 301 | |
Jouni Malinen | 3cfcf6a | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 302 | return 0; |
| 303 | } |
| 304 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 305 | static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo) |
| 306 | { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 307 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 308 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 309 | sinfo->generation = sdata->local->sta_generation; |
| 310 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 311 | sinfo->filled = STATION_INFO_INACTIVE_TIME | |
| 312 | STATION_INFO_RX_BYTES | |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 313 | STATION_INFO_TX_BYTES | |
Jouni Malinen | 98c8a60a | 2009-02-17 13:24:57 +0200 | [diff] [blame] | 314 | STATION_INFO_RX_PACKETS | |
| 315 | STATION_INFO_TX_PACKETS | |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 316 | STATION_INFO_TX_BITRATE; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 317 | |
| 318 | sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx); |
| 319 | sinfo->rx_bytes = sta->rx_bytes; |
| 320 | sinfo->tx_bytes = sta->tx_bytes; |
Jouni Malinen | 98c8a60a | 2009-02-17 13:24:57 +0200 | [diff] [blame] | 321 | sinfo->rx_packets = sta->rx_packets; |
| 322 | sinfo->tx_packets = sta->tx_packets; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 323 | |
John W. Linville | 19deffb | 2009-12-08 17:10:13 -0500 | [diff] [blame] | 324 | if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) || |
| 325 | (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) { |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 326 | sinfo->filled |= STATION_INFO_SIGNAL; |
| 327 | sinfo->signal = (s8)sta->last_signal; |
| 328 | } |
| 329 | |
| 330 | sinfo->txrate.flags = 0; |
| 331 | if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS) |
| 332 | sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS; |
| 333 | if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH) |
| 334 | sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH; |
| 335 | if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI) |
| 336 | sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI; |
| 337 | |
| 338 | if (!(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) { |
| 339 | struct ieee80211_supported_band *sband; |
| 340 | sband = sta->local->hw.wiphy->bands[ |
| 341 | sta->local->hw.conf.channel->band]; |
| 342 | sinfo->txrate.legacy = |
| 343 | sband->bitrates[sta->last_tx_rate.idx].bitrate; |
| 344 | } else |
| 345 | sinfo->txrate.mcs = sta->last_tx_rate.idx; |
| 346 | |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 347 | if (ieee80211_vif_is_mesh(&sdata->vif)) { |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 348 | #ifdef CONFIG_MAC80211_MESH |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 349 | sinfo->filled |= STATION_INFO_LLID | |
| 350 | STATION_INFO_PLID | |
| 351 | STATION_INFO_PLINK_STATE; |
| 352 | |
| 353 | sinfo->llid = le16_to_cpu(sta->llid); |
| 354 | sinfo->plid = le16_to_cpu(sta->plid); |
| 355 | sinfo->plink_state = sta->plink_state; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 356 | #endif |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 357 | } |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | |
| 361 | static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev, |
| 362 | int idx, u8 *mac, struct station_info *sinfo) |
| 363 | { |
Johannes Berg | 3b53fde8 | 2009-11-16 12:00:37 +0100 | [diff] [blame] | 364 | 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] | 365 | struct sta_info *sta; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 366 | int ret = -ENOENT; |
| 367 | |
| 368 | rcu_read_lock(); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 369 | |
Johannes Berg | 3b53fde8 | 2009-11-16 12:00:37 +0100 | [diff] [blame] | 370 | sta = sta_info_get_by_idx(sdata, idx); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 371 | if (sta) { |
| 372 | ret = 0; |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 373 | memcpy(mac, sta->sta.addr, ETH_ALEN); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 374 | sta_set_sinfo(sta, sinfo); |
| 375 | } |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 376 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 377 | rcu_read_unlock(); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 378 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 379 | return ret; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 380 | } |
| 381 | |
Holger Schurig | 1289723 | 2010-04-19 10:23:57 +0200 | [diff] [blame] | 382 | static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev, |
| 383 | int idx, struct survey_info *survey) |
| 384 | { |
| 385 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 386 | |
Holger Schurig | 1289723 | 2010-04-19 10:23:57 +0200 | [diff] [blame] | 387 | return drv_get_survey(local, idx, survey); |
| 388 | } |
| 389 | |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 390 | 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] | 391 | u8 *mac, struct station_info *sinfo) |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 392 | { |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 393 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 394 | struct sta_info *sta; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 395 | int ret = -ENOENT; |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 396 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 397 | rcu_read_lock(); |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 398 | |
Felix Fietkau | 0e5ded5 | 2010-01-08 18:10:58 +0100 | [diff] [blame] | 399 | sta = sta_info_get_bss(sdata, mac); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 400 | if (sta) { |
| 401 | ret = 0; |
| 402 | sta_set_sinfo(sta, sinfo); |
| 403 | } |
| 404 | |
| 405 | rcu_read_unlock(); |
| 406 | |
| 407 | return ret; |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 408 | } |
| 409 | |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 410 | /* |
| 411 | * This handles both adding a beacon and setting new beacon info |
| 412 | */ |
| 413 | static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata, |
| 414 | struct beacon_parameters *params) |
| 415 | { |
| 416 | struct beacon_data *new, *old; |
| 417 | int new_head_len, new_tail_len; |
| 418 | int size; |
| 419 | int err = -EINVAL; |
| 420 | |
| 421 | old = sdata->u.ap.beacon; |
| 422 | |
| 423 | /* head must not be zero-length */ |
| 424 | if (params->head && !params->head_len) |
| 425 | return -EINVAL; |
| 426 | |
| 427 | /* |
| 428 | * This is a kludge. beacon interval should really be part |
| 429 | * of the beacon information. |
| 430 | */ |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 431 | if (params->interval && |
| 432 | (sdata->vif.bss_conf.beacon_int != params->interval)) { |
| 433 | sdata->vif.bss_conf.beacon_int = params->interval; |
| 434 | ieee80211_bss_info_change_notify(sdata, |
| 435 | BSS_CHANGED_BEACON_INT); |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | /* Need to have a beacon head if we don't have one yet */ |
| 439 | if (!params->head && !old) |
| 440 | return err; |
| 441 | |
| 442 | /* sorry, no way to start beaconing without dtim period */ |
| 443 | if (!params->dtim_period && !old) |
| 444 | return err; |
| 445 | |
| 446 | /* new or old head? */ |
| 447 | if (params->head) |
| 448 | new_head_len = params->head_len; |
| 449 | else |
| 450 | new_head_len = old->head_len; |
| 451 | |
| 452 | /* new or old tail? */ |
| 453 | if (params->tail || !old) |
| 454 | /* params->tail_len will be zero for !params->tail */ |
| 455 | new_tail_len = params->tail_len; |
| 456 | else |
| 457 | new_tail_len = old->tail_len; |
| 458 | |
| 459 | size = sizeof(*new) + new_head_len + new_tail_len; |
| 460 | |
| 461 | new = kzalloc(size, GFP_KERNEL); |
| 462 | if (!new) |
| 463 | return -ENOMEM; |
| 464 | |
| 465 | /* start filling the new info now */ |
| 466 | |
| 467 | /* new or old dtim period? */ |
| 468 | if (params->dtim_period) |
| 469 | new->dtim_period = params->dtim_period; |
| 470 | else |
| 471 | new->dtim_period = old->dtim_period; |
| 472 | |
| 473 | /* |
| 474 | * pointers go into the block we allocated, |
| 475 | * memory is | beacon_data | head | tail | |
| 476 | */ |
| 477 | new->head = ((u8 *) new) + sizeof(*new); |
| 478 | new->tail = new->head + new_head_len; |
| 479 | new->head_len = new_head_len; |
| 480 | new->tail_len = new_tail_len; |
| 481 | |
| 482 | /* copy in head */ |
| 483 | if (params->head) |
| 484 | memcpy(new->head, params->head, new_head_len); |
| 485 | else |
| 486 | memcpy(new->head, old->head, new_head_len); |
| 487 | |
| 488 | /* copy in optional tail */ |
| 489 | if (params->tail) |
| 490 | memcpy(new->tail, params->tail, new_tail_len); |
| 491 | else |
| 492 | if (old) |
| 493 | memcpy(new->tail, old->tail, new_tail_len); |
| 494 | |
Johannes Berg | 19885c4 | 2010-02-05 11:45:06 +0100 | [diff] [blame] | 495 | sdata->vif.bss_conf.dtim_period = new->dtim_period; |
| 496 | |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 497 | rcu_assign_pointer(sdata->u.ap.beacon, new); |
| 498 | |
| 499 | synchronize_rcu(); |
| 500 | |
| 501 | kfree(old); |
| 502 | |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 503 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED | |
| 504 | BSS_CHANGED_BEACON); |
| 505 | return 0; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev, |
| 509 | struct beacon_parameters *params) |
| 510 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 511 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 512 | struct beacon_data *old; |
| 513 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 514 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 515 | |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 516 | old = sdata->u.ap.beacon; |
| 517 | |
| 518 | if (old) |
| 519 | return -EALREADY; |
| 520 | |
| 521 | return ieee80211_config_beacon(sdata, params); |
| 522 | } |
| 523 | |
| 524 | static int ieee80211_set_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 -ENOENT; |
| 536 | |
| 537 | return ieee80211_config_beacon(sdata, params); |
| 538 | } |
| 539 | |
| 540 | static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev) |
| 541 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 542 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 543 | struct beacon_data *old; |
| 544 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 545 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 546 | |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 547 | old = sdata->u.ap.beacon; |
| 548 | |
| 549 | if (!old) |
| 550 | return -ENOENT; |
| 551 | |
| 552 | rcu_assign_pointer(sdata->u.ap.beacon, NULL); |
| 553 | synchronize_rcu(); |
| 554 | kfree(old); |
| 555 | |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 556 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED); |
| 557 | return 0; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 558 | } |
| 559 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 560 | /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */ |
| 561 | struct iapp_layer2_update { |
| 562 | u8 da[ETH_ALEN]; /* broadcast */ |
| 563 | u8 sa[ETH_ALEN]; /* STA addr */ |
| 564 | __be16 len; /* 6 */ |
| 565 | u8 dsap; /* 0 */ |
| 566 | u8 ssap; /* 0 */ |
| 567 | u8 control; |
| 568 | u8 xid_info[3]; |
Eric Dumazet | bc10502 | 2010-06-03 03:21:52 -0700 | [diff] [blame] | 569 | } __packed; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 570 | |
| 571 | static void ieee80211_send_layer2_update(struct sta_info *sta) |
| 572 | { |
| 573 | struct iapp_layer2_update *msg; |
| 574 | struct sk_buff *skb; |
| 575 | |
| 576 | /* Send Level 2 Update Frame to update forwarding tables in layer 2 |
| 577 | * bridge devices */ |
| 578 | |
| 579 | skb = dev_alloc_skb(sizeof(*msg)); |
| 580 | if (!skb) |
| 581 | return; |
| 582 | msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg)); |
| 583 | |
| 584 | /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID) |
| 585 | * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */ |
| 586 | |
| 587 | memset(msg->da, 0xff, ETH_ALEN); |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 588 | memcpy(msg->sa, sta->sta.addr, ETH_ALEN); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 589 | msg->len = htons(6); |
| 590 | msg->dsap = 0; |
| 591 | msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */ |
| 592 | msg->control = 0xaf; /* XID response lsb.1111F101. |
| 593 | * F=0 (no poll command; unsolicited frame) */ |
| 594 | msg->xid_info[0] = 0x81; /* XID format identifier */ |
| 595 | msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */ |
| 596 | msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */ |
| 597 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 598 | skb->dev = sta->sdata->dev; |
| 599 | skb->protocol = eth_type_trans(skb, sta->sdata->dev); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 600 | memset(skb->cb, 0, sizeof(skb->cb)); |
John W. Linville | 06ee1c2 | 2010-07-19 11:52:59 -0400 | [diff] [blame] | 601 | netif_rx_ni(skb); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | static void sta_apply_parameters(struct ieee80211_local *local, |
| 605 | struct sta_info *sta, |
| 606 | struct station_parameters *params) |
| 607 | { |
Johannes Berg | f5521b1 | 2010-09-14 22:06:53 +0200 | [diff] [blame] | 608 | unsigned long flags; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 609 | u32 rates; |
| 610 | int i, j; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 611 | struct ieee80211_supported_band *sband; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 612 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 613 | u32 mask, set; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 614 | |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 615 | sband = local->hw.wiphy->bands[local->oper_channel->band]; |
| 616 | |
Johannes Berg | f5521b1 | 2010-09-14 22:06:53 +0200 | [diff] [blame] | 617 | spin_lock_irqsave(&sta->flaglock, flags); |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 618 | mask = params->sta_flags_mask; |
| 619 | set = params->sta_flags_set; |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 620 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 621 | if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) { |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 622 | sta->flags &= ~WLAN_STA_AUTHORIZED; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 623 | if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 624 | sta->flags |= WLAN_STA_AUTHORIZED; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 625 | } |
| 626 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 627 | if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) { |
| 628 | sta->flags &= ~WLAN_STA_SHORT_PREAMBLE; |
| 629 | if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) |
| 630 | sta->flags |= WLAN_STA_SHORT_PREAMBLE; |
| 631 | } |
| 632 | |
| 633 | if (mask & BIT(NL80211_STA_FLAG_WME)) { |
| 634 | sta->flags &= ~WLAN_STA_WME; |
| 635 | if (set & BIT(NL80211_STA_FLAG_WME)) |
| 636 | sta->flags |= WLAN_STA_WME; |
| 637 | } |
| 638 | |
| 639 | if (mask & BIT(NL80211_STA_FLAG_MFP)) { |
| 640 | sta->flags &= ~WLAN_STA_MFP; |
| 641 | if (set & BIT(NL80211_STA_FLAG_MFP)) |
| 642 | sta->flags |= WLAN_STA_MFP; |
| 643 | } |
Johannes Berg | f5521b1 | 2010-09-14 22:06:53 +0200 | [diff] [blame] | 644 | spin_unlock_irqrestore(&sta->flaglock, flags); |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 645 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 646 | /* |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 647 | * cfg80211 validates this (1-2007) and allows setting the AID |
| 648 | * only when creating a new station entry |
| 649 | */ |
| 650 | if (params->aid) |
| 651 | sta->sta.aid = params->aid; |
| 652 | |
| 653 | /* |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 654 | * FIXME: updating the following information is racy when this |
| 655 | * function is called from ieee80211_change_station(). |
| 656 | * However, all this information should be static so |
| 657 | * maybe we should just reject attemps to change it. |
| 658 | */ |
| 659 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 660 | if (params->listen_interval >= 0) |
| 661 | sta->listen_interval = params->listen_interval; |
| 662 | |
| 663 | if (params->supported_rates) { |
| 664 | rates = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 665 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 666 | for (i = 0; i < params->supported_rates_len; i++) { |
| 667 | int rate = (params->supported_rates[i] & 0x7f) * 5; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 668 | for (j = 0; j < sband->n_bitrates; j++) { |
| 669 | if (sband->bitrates[j].bitrate == rate) |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 670 | rates |= BIT(j); |
| 671 | } |
| 672 | } |
Johannes Berg | 323ce79 | 2008-09-11 02:45:11 +0200 | [diff] [blame] | 673 | sta->sta.supp_rates[local->oper_channel->band] = rates; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 674 | } |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 675 | |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 676 | if (params->ht_capa) |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 677 | ieee80211_ht_cap_ie_to_sta_ht_cap(sband, |
| 678 | params->ht_capa, |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 679 | &sta->sta.ht_cap); |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 680 | |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 681 | if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) { |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 682 | switch (params->plink_action) { |
| 683 | case PLINK_ACTION_OPEN: |
| 684 | mesh_plink_open(sta); |
| 685 | break; |
| 686 | case PLINK_ACTION_BLOCK: |
| 687 | mesh_plink_block(sta); |
| 688 | break; |
| 689 | } |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 690 | } |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev, |
| 694 | u8 *mac, struct station_parameters *params) |
| 695 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 696 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 697 | struct sta_info *sta; |
| 698 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 699 | int err; |
Jouni Malinen | b8d476c | 2008-12-12 17:08:31 +0200 | [diff] [blame] | 700 | int layer2_update; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 701 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 702 | if (params->vlan) { |
| 703 | sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); |
| 704 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 705 | if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN && |
| 706 | sdata->vif.type != NL80211_IFTYPE_AP) |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 707 | return -EINVAL; |
| 708 | } else |
| 709 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 710 | |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 711 | if (compare_ether_addr(mac, sdata->vif.addr) == 0) |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 712 | return -EINVAL; |
| 713 | |
| 714 | if (is_multicast_ether_addr(mac)) |
| 715 | return -EINVAL; |
| 716 | |
| 717 | sta = sta_info_alloc(sdata, mac, GFP_KERNEL); |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 718 | if (!sta) |
| 719 | return -ENOMEM; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 720 | |
| 721 | sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC; |
| 722 | |
| 723 | sta_apply_parameters(local, sta, params); |
| 724 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 725 | rate_control_rate_init(sta); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 726 | |
Jouni Malinen | b8d476c | 2008-12-12 17:08:31 +0200 | [diff] [blame] | 727 | layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN || |
| 728 | sdata->vif.type == NL80211_IFTYPE_AP; |
| 729 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 730 | err = sta_info_insert_rcu(sta); |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 731 | if (err) { |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 732 | rcu_read_unlock(); |
| 733 | return err; |
| 734 | } |
| 735 | |
Jouni Malinen | b8d476c | 2008-12-12 17:08:31 +0200 | [diff] [blame] | 736 | if (layer2_update) |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 737 | ieee80211_send_layer2_update(sta); |
| 738 | |
| 739 | rcu_read_unlock(); |
| 740 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 741 | return 0; |
| 742 | } |
| 743 | |
| 744 | static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev, |
| 745 | u8 *mac) |
| 746 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 747 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 748 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 749 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 750 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 751 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 752 | if (mac) |
| 753 | return sta_info_destroy_addr_bss(sdata, mac); |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 754 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 755 | sta_info_flush(local, sdata); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 756 | return 0; |
| 757 | } |
| 758 | |
| 759 | static int ieee80211_change_station(struct wiphy *wiphy, |
| 760 | struct net_device *dev, |
| 761 | u8 *mac, |
| 762 | struct station_parameters *params) |
| 763 | { |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 764 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 765 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 766 | struct sta_info *sta; |
| 767 | struct ieee80211_sub_if_data *vlansdata; |
| 768 | |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 769 | rcu_read_lock(); |
| 770 | |
Felix Fietkau | 0e5ded5 | 2010-01-08 18:10:58 +0100 | [diff] [blame] | 771 | sta = sta_info_get_bss(sdata, 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 | if (params->vlan && params->vlan != sta->sdata->dev) { |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 778 | vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); |
| 779 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 780 | if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN && |
| 781 | vlansdata->vif.type != NL80211_IFTYPE_AP) { |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 782 | rcu_read_unlock(); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 783 | return -EINVAL; |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 784 | } |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 785 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 786 | if (params->vlan->ieee80211_ptr->use_4addr) { |
Johannes Berg | 3305443 | 2009-11-20 10:09:14 +0100 | [diff] [blame] | 787 | if (vlansdata->u.vlan.sta) { |
| 788 | rcu_read_unlock(); |
Felix Fietkau | f14543e | 2009-11-10 20:10:05 +0100 | [diff] [blame] | 789 | return -EBUSY; |
Johannes Berg | 3305443 | 2009-11-20 10:09:14 +0100 | [diff] [blame] | 790 | } |
Felix Fietkau | f14543e | 2009-11-10 20:10:05 +0100 | [diff] [blame] | 791 | |
| 792 | rcu_assign_pointer(vlansdata->u.vlan.sta, sta); |
| 793 | } |
| 794 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 795 | sta->sdata = vlansdata; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 796 | ieee80211_send_layer2_update(sta); |
| 797 | } |
| 798 | |
| 799 | sta_apply_parameters(local, sta, params); |
| 800 | |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 801 | rcu_read_unlock(); |
| 802 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 803 | return 0; |
| 804 | } |
| 805 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 806 | #ifdef CONFIG_MAC80211_MESH |
| 807 | static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev, |
| 808 | u8 *dst, u8 *next_hop) |
| 809 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 810 | struct ieee80211_sub_if_data *sdata; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 811 | struct mesh_path *mpath; |
| 812 | struct sta_info *sta; |
| 813 | int err; |
| 814 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 815 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 816 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 817 | rcu_read_lock(); |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 818 | sta = sta_info_get(sdata, next_hop); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 819 | if (!sta) { |
| 820 | rcu_read_unlock(); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 821 | return -ENOENT; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 822 | } |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 823 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 824 | err = mesh_path_add(dst, sdata); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 825 | if (err) { |
| 826 | rcu_read_unlock(); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 827 | return err; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 828 | } |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 829 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 830 | mpath = mesh_path_lookup(dst, sdata); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 831 | if (!mpath) { |
| 832 | rcu_read_unlock(); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 833 | return -ENXIO; |
| 834 | } |
| 835 | mesh_path_fix_nexthop(mpath, sta); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 836 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 837 | rcu_read_unlock(); |
| 838 | return 0; |
| 839 | } |
| 840 | |
| 841 | static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev, |
| 842 | u8 *dst) |
| 843 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 844 | 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] | 845 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 846 | if (dst) |
| 847 | return mesh_path_del(dst, sdata); |
| 848 | |
| 849 | mesh_path_flush(sdata); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 850 | return 0; |
| 851 | } |
| 852 | |
| 853 | static int ieee80211_change_mpath(struct wiphy *wiphy, |
| 854 | struct net_device *dev, |
| 855 | u8 *dst, u8 *next_hop) |
| 856 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 857 | struct ieee80211_sub_if_data *sdata; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 858 | struct mesh_path *mpath; |
| 859 | struct sta_info *sta; |
| 860 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 861 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 862 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 863 | rcu_read_lock(); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 864 | |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 865 | sta = sta_info_get(sdata, next_hop); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 866 | if (!sta) { |
| 867 | rcu_read_unlock(); |
| 868 | return -ENOENT; |
| 869 | } |
| 870 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 871 | mpath = mesh_path_lookup(dst, sdata); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 872 | if (!mpath) { |
| 873 | rcu_read_unlock(); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 874 | return -ENOENT; |
| 875 | } |
| 876 | |
| 877 | mesh_path_fix_nexthop(mpath, sta); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 878 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 879 | rcu_read_unlock(); |
| 880 | return 0; |
| 881 | } |
| 882 | |
| 883 | static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop, |
| 884 | struct mpath_info *pinfo) |
| 885 | { |
| 886 | if (mpath->next_hop) |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 887 | memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 888 | else |
| 889 | memset(next_hop, 0, ETH_ALEN); |
| 890 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 891 | pinfo->generation = mesh_paths_generation; |
| 892 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 893 | pinfo->filled = MPATH_INFO_FRAME_QLEN | |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 894 | MPATH_INFO_SN | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 895 | MPATH_INFO_METRIC | |
| 896 | MPATH_INFO_EXPTIME | |
| 897 | MPATH_INFO_DISCOVERY_TIMEOUT | |
| 898 | MPATH_INFO_DISCOVERY_RETRIES | |
| 899 | MPATH_INFO_FLAGS; |
| 900 | |
| 901 | pinfo->frame_qlen = mpath->frame_queue.qlen; |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 902 | pinfo->sn = mpath->sn; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 903 | pinfo->metric = mpath->metric; |
| 904 | if (time_before(jiffies, mpath->exp_time)) |
| 905 | pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies); |
| 906 | pinfo->discovery_timeout = |
| 907 | jiffies_to_msecs(mpath->discovery_timeout); |
| 908 | pinfo->discovery_retries = mpath->discovery_retries; |
| 909 | pinfo->flags = 0; |
| 910 | if (mpath->flags & MESH_PATH_ACTIVE) |
| 911 | pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE; |
| 912 | if (mpath->flags & MESH_PATH_RESOLVING) |
| 913 | pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING; |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 914 | if (mpath->flags & MESH_PATH_SN_VALID) |
| 915 | pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 916 | if (mpath->flags & MESH_PATH_FIXED) |
| 917 | pinfo->flags |= NL80211_MPATH_FLAG_FIXED; |
| 918 | if (mpath->flags & MESH_PATH_RESOLVING) |
| 919 | pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING; |
| 920 | |
| 921 | pinfo->flags = mpath->flags; |
| 922 | } |
| 923 | |
| 924 | static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev, |
| 925 | u8 *dst, u8 *next_hop, struct mpath_info *pinfo) |
| 926 | |
| 927 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 928 | struct ieee80211_sub_if_data *sdata; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 929 | struct mesh_path *mpath; |
| 930 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 931 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 932 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 933 | rcu_read_lock(); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 934 | mpath = mesh_path_lookup(dst, sdata); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 935 | if (!mpath) { |
| 936 | rcu_read_unlock(); |
| 937 | return -ENOENT; |
| 938 | } |
| 939 | memcpy(dst, mpath->dst, ETH_ALEN); |
| 940 | mpath_set_pinfo(mpath, next_hop, pinfo); |
| 941 | rcu_read_unlock(); |
| 942 | return 0; |
| 943 | } |
| 944 | |
| 945 | static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev, |
| 946 | int idx, u8 *dst, u8 *next_hop, |
| 947 | struct mpath_info *pinfo) |
| 948 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 949 | struct ieee80211_sub_if_data *sdata; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 950 | struct mesh_path *mpath; |
| 951 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 952 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 953 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 954 | rcu_read_lock(); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 955 | mpath = mesh_path_lookup_by_idx(idx, sdata); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 956 | if (!mpath) { |
| 957 | rcu_read_unlock(); |
| 958 | return -ENOENT; |
| 959 | } |
| 960 | memcpy(dst, mpath->dst, ETH_ALEN); |
| 961 | mpath_set_pinfo(mpath, next_hop, pinfo); |
| 962 | rcu_read_unlock(); |
| 963 | return 0; |
| 964 | } |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 965 | |
| 966 | static int ieee80211_get_mesh_params(struct wiphy *wiphy, |
| 967 | struct net_device *dev, |
| 968 | struct mesh_config *conf) |
| 969 | { |
| 970 | struct ieee80211_sub_if_data *sdata; |
| 971 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 972 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 973 | memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config)); |
| 974 | return 0; |
| 975 | } |
| 976 | |
| 977 | static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask) |
| 978 | { |
| 979 | return (mask >> (parm-1)) & 0x1; |
| 980 | } |
| 981 | |
| 982 | static int ieee80211_set_mesh_params(struct wiphy *wiphy, |
| 983 | struct net_device *dev, |
| 984 | const struct mesh_config *nconf, u32 mask) |
| 985 | { |
| 986 | struct mesh_config *conf; |
| 987 | struct ieee80211_sub_if_data *sdata; |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 988 | struct ieee80211_if_mesh *ifmsh; |
| 989 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 990 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 991 | ifmsh = &sdata->u.mesh; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 992 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 993 | /* Set the config options which we are interested in setting */ |
| 994 | conf = &(sdata->u.mesh.mshcfg); |
| 995 | if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask)) |
| 996 | conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout; |
| 997 | if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask)) |
| 998 | conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout; |
| 999 | if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask)) |
| 1000 | conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout; |
| 1001 | if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask)) |
| 1002 | conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks; |
| 1003 | if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask)) |
| 1004 | conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries; |
| 1005 | if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask)) |
| 1006 | conf->dot11MeshTTL = nconf->dot11MeshTTL; |
| 1007 | if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) |
| 1008 | conf->auto_open_plinks = nconf->auto_open_plinks; |
| 1009 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask)) |
| 1010 | conf->dot11MeshHWMPmaxPREQretries = |
| 1011 | nconf->dot11MeshHWMPmaxPREQretries; |
| 1012 | if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask)) |
| 1013 | conf->path_refresh_time = nconf->path_refresh_time; |
| 1014 | if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask)) |
| 1015 | conf->min_discovery_timeout = nconf->min_discovery_timeout; |
| 1016 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask)) |
| 1017 | conf->dot11MeshHWMPactivePathTimeout = |
| 1018 | nconf->dot11MeshHWMPactivePathTimeout; |
| 1019 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask)) |
| 1020 | conf->dot11MeshHWMPpreqMinInterval = |
| 1021 | nconf->dot11MeshHWMPpreqMinInterval; |
| 1022 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 1023 | mask)) |
| 1024 | conf->dot11MeshHWMPnetDiameterTraversalTime = |
| 1025 | nconf->dot11MeshHWMPnetDiameterTraversalTime; |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 1026 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) { |
| 1027 | conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode; |
| 1028 | ieee80211_mesh_root_setup(ifmsh); |
| 1029 | } |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 1030 | return 0; |
| 1031 | } |
| 1032 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1033 | #endif |
| 1034 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1035 | static int ieee80211_change_bss(struct wiphy *wiphy, |
| 1036 | struct net_device *dev, |
| 1037 | struct bss_parameters *params) |
| 1038 | { |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1039 | struct ieee80211_sub_if_data *sdata; |
| 1040 | u32 changed = 0; |
| 1041 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1042 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1043 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1044 | if (params->use_cts_prot >= 0) { |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 1045 | sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1046 | changed |= BSS_CHANGED_ERP_CTS_PROT; |
| 1047 | } |
| 1048 | if (params->use_short_preamble >= 0) { |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 1049 | sdata->vif.bss_conf.use_short_preamble = |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1050 | params->use_short_preamble; |
| 1051 | changed |= BSS_CHANGED_ERP_PREAMBLE; |
| 1052 | } |
Felix Fietkau | 43d3534 | 2010-01-15 03:00:48 +0100 | [diff] [blame] | 1053 | |
| 1054 | if (!sdata->vif.bss_conf.use_short_slot && |
| 1055 | sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) { |
| 1056 | sdata->vif.bss_conf.use_short_slot = true; |
| 1057 | changed |= BSS_CHANGED_ERP_SLOT; |
| 1058 | } |
| 1059 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1060 | if (params->use_short_slot_time >= 0) { |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 1061 | sdata->vif.bss_conf.use_short_slot = |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1062 | params->use_short_slot_time; |
| 1063 | changed |= BSS_CHANGED_ERP_SLOT; |
| 1064 | } |
| 1065 | |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 1066 | if (params->basic_rates) { |
| 1067 | int i, j; |
| 1068 | u32 rates = 0; |
| 1069 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 1070 | struct ieee80211_supported_band *sband = |
| 1071 | wiphy->bands[local->oper_channel->band]; |
| 1072 | |
| 1073 | for (i = 0; i < params->basic_rates_len; i++) { |
| 1074 | int rate = (params->basic_rates[i] & 0x7f) * 5; |
| 1075 | for (j = 0; j < sband->n_bitrates; j++) { |
| 1076 | if (sband->bitrates[j].bitrate == rate) |
| 1077 | rates |= BIT(j); |
| 1078 | } |
| 1079 | } |
| 1080 | sdata->vif.bss_conf.basic_rates = rates; |
| 1081 | changed |= BSS_CHANGED_BASIC_RATES; |
| 1082 | } |
| 1083 | |
Felix Fietkau | 7b7b5e5 | 2010-04-27 01:23:36 +0200 | [diff] [blame] | 1084 | if (params->ap_isolate >= 0) { |
| 1085 | if (params->ap_isolate) |
| 1086 | sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS; |
| 1087 | else |
| 1088 | sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS; |
| 1089 | } |
| 1090 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1091 | ieee80211_bss_info_change_notify(sdata, changed); |
| 1092 | |
| 1093 | return 0; |
| 1094 | } |
| 1095 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1096 | static int ieee80211_set_txq_params(struct wiphy *wiphy, |
| 1097 | struct ieee80211_txq_params *params) |
| 1098 | { |
| 1099 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 1100 | struct ieee80211_tx_queue_params p; |
| 1101 | |
| 1102 | if (!local->ops->conf_tx) |
| 1103 | return -EOPNOTSUPP; |
| 1104 | |
| 1105 | memset(&p, 0, sizeof(p)); |
| 1106 | p.aifs = params->aifs; |
| 1107 | p.cw_max = params->cwmax; |
| 1108 | p.cw_min = params->cwmin; |
| 1109 | p.txop = params->txop; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 1110 | |
| 1111 | /* |
| 1112 | * Setting tx queue params disables u-apsd because it's only |
| 1113 | * called in master mode. |
| 1114 | */ |
| 1115 | p.uapsd = false; |
| 1116 | |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 1117 | if (drv_conf_tx(local, params->queue, &p)) { |
Joe Perches | 0fb9a9e | 2010-08-20 16:25:38 -0700 | [diff] [blame] | 1118 | wiphy_debug(local->hw.wiphy, |
| 1119 | "failed to set TX queue parameters for queue %d\n", |
| 1120 | params->queue); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1121 | return -EINVAL; |
| 1122 | } |
| 1123 | |
| 1124 | return 0; |
| 1125 | } |
| 1126 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1127 | static int ieee80211_set_channel(struct wiphy *wiphy, |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1128 | struct net_device *netdev, |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 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); |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 1133 | struct ieee80211_sub_if_data *sdata = NULL; |
| 1134 | |
| 1135 | if (netdev) |
| 1136 | sdata = IEEE80211_DEV_TO_SUB_IF(netdev); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1137 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1138 | switch (ieee80211_get_channel_mode(local, NULL)) { |
| 1139 | case CHAN_MODE_HOPPING: |
| 1140 | return -EBUSY; |
| 1141 | case CHAN_MODE_FIXED: |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 1142 | if (local->oper_channel != chan) |
| 1143 | return -EBUSY; |
| 1144 | if (!sdata && local->_oper_channel_type == channel_type) |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1145 | return 0; |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 1146 | break; |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1147 | case CHAN_MODE_UNDEFINED: |
| 1148 | break; |
| 1149 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1150 | |
| 1151 | local->oper_channel = chan; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1152 | |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 1153 | if (!ieee80211_set_channel_type(local, sdata, channel_type)) |
| 1154 | return -EBUSY; |
| 1155 | |
| 1156 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL); |
| 1157 | if (sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR) |
| 1158 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT); |
| 1159 | |
| 1160 | return 0; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1161 | } |
| 1162 | |
Bob Copeland | 665af4f | 2009-01-19 11:20:53 -0500 | [diff] [blame] | 1163 | #ifdef CONFIG_PM |
| 1164 | static int ieee80211_suspend(struct wiphy *wiphy) |
| 1165 | { |
| 1166 | return __ieee80211_suspend(wiphy_priv(wiphy)); |
| 1167 | } |
| 1168 | |
| 1169 | static int ieee80211_resume(struct wiphy *wiphy) |
| 1170 | { |
| 1171 | return __ieee80211_resume(wiphy_priv(wiphy)); |
| 1172 | } |
| 1173 | #else |
| 1174 | #define ieee80211_suspend NULL |
| 1175 | #define ieee80211_resume NULL |
| 1176 | #endif |
| 1177 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1178 | static int ieee80211_scan(struct wiphy *wiphy, |
| 1179 | struct net_device *dev, |
| 1180 | struct cfg80211_scan_request *req) |
| 1181 | { |
Johannes Berg | 2ca27bc | 2010-09-16 14:58:23 +0200 | [diff] [blame] | 1182 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1183 | |
Johannes Berg | 2ca27bc | 2010-09-16 14:58:23 +0200 | [diff] [blame] | 1184 | switch (ieee80211_vif_type_p2p(&sdata->vif)) { |
| 1185 | case NL80211_IFTYPE_STATION: |
| 1186 | case NL80211_IFTYPE_ADHOC: |
| 1187 | case NL80211_IFTYPE_MESH_POINT: |
| 1188 | case NL80211_IFTYPE_P2P_CLIENT: |
| 1189 | break; |
| 1190 | case NL80211_IFTYPE_P2P_GO: |
| 1191 | if (sdata->local->ops->hw_scan) |
| 1192 | break; |
| 1193 | /* FIXME: implement NoA while scanning in software */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1194 | return -EOPNOTSUPP; |
Johannes Berg | 2ca27bc | 2010-09-16 14:58:23 +0200 | [diff] [blame] | 1195 | case NL80211_IFTYPE_AP: |
| 1196 | if (sdata->u.ap.beacon) |
| 1197 | return -EOPNOTSUPP; |
| 1198 | break; |
| 1199 | default: |
| 1200 | return -EOPNOTSUPP; |
| 1201 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1202 | |
| 1203 | return ieee80211_request_scan(sdata, req); |
| 1204 | } |
| 1205 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1206 | static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev, |
| 1207 | struct cfg80211_auth_request *req) |
| 1208 | { |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1209 | return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev, |
| 1213 | struct cfg80211_assoc_request *req) |
| 1214 | { |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1215 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 1216 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1217 | |
| 1218 | switch (ieee80211_get_channel_mode(local, sdata)) { |
| 1219 | case CHAN_MODE_HOPPING: |
| 1220 | return -EBUSY; |
| 1221 | case CHAN_MODE_FIXED: |
| 1222 | if (local->oper_channel == req->bss->channel) |
| 1223 | break; |
| 1224 | return -EBUSY; |
| 1225 | case CHAN_MODE_UNDEFINED: |
| 1226 | break; |
| 1227 | } |
| 1228 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1229 | return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 1233 | struct cfg80211_deauth_request *req, |
| 1234 | void *cookie) |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1235 | { |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 1236 | return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), |
| 1237 | req, cookie); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 1241 | struct cfg80211_disassoc_request *req, |
| 1242 | void *cookie) |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1243 | { |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 1244 | return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), |
| 1245 | req, cookie); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1246 | } |
| 1247 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1248 | static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev, |
| 1249 | struct cfg80211_ibss_params *params) |
| 1250 | { |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1251 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1252 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1253 | |
Johannes Berg | f444de0 | 2010-05-05 15:25:02 +0200 | [diff] [blame] | 1254 | switch (ieee80211_get_channel_mode(local, sdata)) { |
| 1255 | case CHAN_MODE_HOPPING: |
| 1256 | return -EBUSY; |
| 1257 | case CHAN_MODE_FIXED: |
| 1258 | if (!params->channel_fixed) |
| 1259 | return -EBUSY; |
| 1260 | if (local->oper_channel == params->channel) |
| 1261 | break; |
| 1262 | return -EBUSY; |
| 1263 | case CHAN_MODE_UNDEFINED: |
| 1264 | break; |
| 1265 | } |
| 1266 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1267 | return ieee80211_ibss_join(sdata, params); |
| 1268 | } |
| 1269 | |
| 1270 | static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev) |
| 1271 | { |
| 1272 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1273 | |
| 1274 | return ieee80211_ibss_leave(sdata); |
| 1275 | } |
| 1276 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1277 | static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed) |
| 1278 | { |
| 1279 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 1280 | int err; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1281 | |
Lukáš Turek | 310bc67 | 2009-12-21 22:50:48 +0100 | [diff] [blame] | 1282 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) { |
| 1283 | err = drv_set_coverage_class(local, wiphy->coverage_class); |
| 1284 | |
| 1285 | if (err) |
| 1286 | return err; |
| 1287 | } |
| 1288 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1289 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) { |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 1290 | err = drv_set_rts_threshold(local, wiphy->rts_threshold); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1291 | |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 1292 | if (err) |
| 1293 | return err; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1294 | } |
| 1295 | |
| 1296 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1297 | local->hw.conf.short_frame_max_tx_count = wiphy->retry_short; |
| 1298 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1299 | local->hw.conf.long_frame_max_tx_count = wiphy->retry_long; |
| 1300 | if (changed & |
| 1301 | (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG)) |
| 1302 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS); |
| 1303 | |
| 1304 | return 0; |
| 1305 | } |
| 1306 | |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 1307 | static int ieee80211_set_tx_power(struct wiphy *wiphy, |
Juuso Oikarinen | fa61cf7 | 2010-06-23 12:12:37 +0300 | [diff] [blame] | 1308 | enum nl80211_tx_power_setting type, int mbm) |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 1309 | { |
| 1310 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 1311 | struct ieee80211_channel *chan = local->hw.conf.channel; |
| 1312 | u32 changes = 0; |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 1313 | |
| 1314 | switch (type) { |
Juuso Oikarinen | fa61cf7 | 2010-06-23 12:12:37 +0300 | [diff] [blame] | 1315 | case NL80211_TX_POWER_AUTOMATIC: |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 1316 | local->user_power_level = -1; |
| 1317 | break; |
Juuso Oikarinen | fa61cf7 | 2010-06-23 12:12:37 +0300 | [diff] [blame] | 1318 | case NL80211_TX_POWER_LIMITED: |
| 1319 | if (mbm < 0 || (mbm % 100)) |
| 1320 | return -EOPNOTSUPP; |
| 1321 | local->user_power_level = MBM_TO_DBM(mbm); |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 1322 | break; |
Juuso Oikarinen | fa61cf7 | 2010-06-23 12:12:37 +0300 | [diff] [blame] | 1323 | case NL80211_TX_POWER_FIXED: |
| 1324 | if (mbm < 0 || (mbm % 100)) |
| 1325 | return -EOPNOTSUPP; |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 1326 | /* TODO: move to cfg80211 when it knows the channel */ |
Juuso Oikarinen | fa61cf7 | 2010-06-23 12:12:37 +0300 | [diff] [blame] | 1327 | if (MBM_TO_DBM(mbm) > chan->max_power) |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 1328 | return -EINVAL; |
Juuso Oikarinen | fa61cf7 | 2010-06-23 12:12:37 +0300 | [diff] [blame] | 1329 | local->user_power_level = MBM_TO_DBM(mbm); |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 1330 | break; |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 1331 | } |
| 1332 | |
| 1333 | ieee80211_hw_config(local, changes); |
| 1334 | |
| 1335 | return 0; |
| 1336 | } |
| 1337 | |
| 1338 | static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm) |
| 1339 | { |
| 1340 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 1341 | |
| 1342 | *dbm = local->hw.conf.power_level; |
| 1343 | |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 1344 | return 0; |
| 1345 | } |
| 1346 | |
Johannes Berg | ab737a4 | 2009-07-01 21:26:58 +0200 | [diff] [blame] | 1347 | static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev, |
| 1348 | u8 *addr) |
| 1349 | { |
| 1350 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1351 | |
| 1352 | memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN); |
| 1353 | |
| 1354 | return 0; |
| 1355 | } |
| 1356 | |
Johannes Berg | 1f87f7d | 2009-06-02 13:01:41 +0200 | [diff] [blame] | 1357 | static void ieee80211_rfkill_poll(struct wiphy *wiphy) |
| 1358 | { |
| 1359 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 1360 | |
| 1361 | drv_rfkill_poll(local); |
| 1362 | } |
| 1363 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 1364 | #ifdef CONFIG_NL80211_TESTMODE |
Johannes Berg | 99783e2 | 2009-07-07 03:54:43 +0200 | [diff] [blame] | 1365 | static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 1366 | { |
| 1367 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 1368 | |
| 1369 | if (!local->ops->testmode_cmd) |
| 1370 | return -EOPNOTSUPP; |
| 1371 | |
| 1372 | return local->ops->testmode_cmd(&local->hw, data, len); |
| 1373 | } |
| 1374 | #endif |
| 1375 | |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 1376 | int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata, |
| 1377 | enum ieee80211_smps_mode smps_mode) |
| 1378 | { |
| 1379 | const u8 *ap; |
| 1380 | enum ieee80211_smps_mode old_req; |
| 1381 | int err; |
| 1382 | |
| 1383 | old_req = sdata->u.mgd.req_smps; |
| 1384 | sdata->u.mgd.req_smps = smps_mode; |
| 1385 | |
| 1386 | if (old_req == smps_mode && |
| 1387 | smps_mode != IEEE80211_SMPS_AUTOMATIC) |
| 1388 | return 0; |
| 1389 | |
| 1390 | /* |
| 1391 | * If not associated, or current association is not an HT |
| 1392 | * association, there's no need to send an action frame. |
| 1393 | */ |
| 1394 | if (!sdata->u.mgd.associated || |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 1395 | sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) { |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 1396 | mutex_lock(&sdata->local->iflist_mtx); |
Johannes Berg | 025e6be | 2010-10-05 10:41:47 +0200 | [diff] [blame^] | 1397 | ieee80211_recalc_smps(sdata->local); |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 1398 | mutex_unlock(&sdata->local->iflist_mtx); |
| 1399 | return 0; |
| 1400 | } |
| 1401 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 1402 | ap = sdata->u.mgd.associated->bssid; |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 1403 | |
| 1404 | if (smps_mode == IEEE80211_SMPS_AUTOMATIC) { |
| 1405 | if (sdata->u.mgd.powersave) |
| 1406 | smps_mode = IEEE80211_SMPS_DYNAMIC; |
| 1407 | else |
| 1408 | smps_mode = IEEE80211_SMPS_OFF; |
| 1409 | } |
| 1410 | |
| 1411 | /* send SM PS frame to AP */ |
| 1412 | err = ieee80211_send_smps_action(sdata, smps_mode, |
| 1413 | ap, ap); |
| 1414 | if (err) |
| 1415 | sdata->u.mgd.req_smps = old_req; |
| 1416 | |
| 1417 | return err; |
| 1418 | } |
| 1419 | |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 1420 | static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev, |
| 1421 | bool enabled, int timeout) |
| 1422 | { |
| 1423 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1424 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 1425 | |
Benoit Papillault | e5de30c | 2010-01-15 12:21:37 +0100 | [diff] [blame] | 1426 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
| 1427 | return -EOPNOTSUPP; |
| 1428 | |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 1429 | if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) |
| 1430 | return -EOPNOTSUPP; |
| 1431 | |
| 1432 | if (enabled == sdata->u.mgd.powersave && |
Juuso Oikarinen | ff61638 | 2010-06-09 09:51:52 +0300 | [diff] [blame] | 1433 | timeout == local->dynamic_ps_forced_timeout) |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 1434 | return 0; |
| 1435 | |
| 1436 | sdata->u.mgd.powersave = enabled; |
Juuso Oikarinen | ff61638 | 2010-06-09 09:51:52 +0300 | [diff] [blame] | 1437 | local->dynamic_ps_forced_timeout = timeout; |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 1438 | |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 1439 | /* no change, but if automatic follow powersave */ |
| 1440 | mutex_lock(&sdata->u.mgd.mtx); |
| 1441 | __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps); |
| 1442 | mutex_unlock(&sdata->u.mgd.mtx); |
| 1443 | |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 1444 | if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS) |
| 1445 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 1446 | |
| 1447 | ieee80211_recalc_ps(local, -1); |
| 1448 | |
| 1449 | return 0; |
| 1450 | } |
| 1451 | |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 1452 | static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy, |
| 1453 | struct net_device *dev, |
| 1454 | s32 rssi_thold, u32 rssi_hyst) |
| 1455 | { |
| 1456 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1457 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 1458 | struct ieee80211_vif *vif = &sdata->vif; |
| 1459 | struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; |
| 1460 | |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 1461 | if (rssi_thold == bss_conf->cqm_rssi_thold && |
| 1462 | rssi_hyst == bss_conf->cqm_rssi_hyst) |
| 1463 | return 0; |
| 1464 | |
| 1465 | bss_conf->cqm_rssi_thold = rssi_thold; |
| 1466 | bss_conf->cqm_rssi_hyst = rssi_hyst; |
| 1467 | |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 1468 | if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) { |
| 1469 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
| 1470 | return -EOPNOTSUPP; |
| 1471 | return 0; |
| 1472 | } |
| 1473 | |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 1474 | /* tell the driver upon association, unless already associated */ |
| 1475 | if (sdata->u.mgd.associated) |
| 1476 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM); |
| 1477 | |
| 1478 | return 0; |
| 1479 | } |
| 1480 | |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 1481 | static int ieee80211_set_bitrate_mask(struct wiphy *wiphy, |
| 1482 | struct net_device *dev, |
| 1483 | const u8 *addr, |
| 1484 | const struct cfg80211_bitrate_mask *mask) |
| 1485 | { |
| 1486 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1487 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
Johannes Berg | 2c7e6bc | 2009-12-04 09:26:38 +0100 | [diff] [blame] | 1488 | int i; |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 1489 | |
Johannes Berg | 2c7e6bc | 2009-12-04 09:26:38 +0100 | [diff] [blame] | 1490 | /* |
| 1491 | * This _could_ be supported by providing a hook for |
| 1492 | * drivers for this function, but at this point it |
| 1493 | * doesn't seem worth bothering. |
| 1494 | */ |
| 1495 | if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) |
| 1496 | return -EOPNOTSUPP; |
| 1497 | |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 1498 | |
Jouni Malinen | 37eb0b1 | 2010-01-06 13:09:08 +0200 | [diff] [blame] | 1499 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
| 1500 | sdata->rc_rateidx_mask[i] = mask->control[i].legacy; |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 1501 | |
Jouni Malinen | 37eb0b1 | 2010-01-06 13:09:08 +0200 | [diff] [blame] | 1502 | return 0; |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 1503 | } |
| 1504 | |
Johannes Berg | b8bc4b0 | 2009-12-23 13:15:42 +0100 | [diff] [blame] | 1505 | static int ieee80211_remain_on_channel(struct wiphy *wiphy, |
| 1506 | struct net_device *dev, |
| 1507 | struct ieee80211_channel *chan, |
| 1508 | enum nl80211_channel_type channel_type, |
| 1509 | unsigned int duration, |
| 1510 | u64 *cookie) |
| 1511 | { |
| 1512 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1513 | |
| 1514 | return ieee80211_wk_remain_on_channel(sdata, chan, channel_type, |
| 1515 | duration, cookie); |
| 1516 | } |
| 1517 | |
| 1518 | static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy, |
| 1519 | struct net_device *dev, |
| 1520 | u64 cookie) |
| 1521 | { |
| 1522 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1523 | |
| 1524 | return ieee80211_wk_cancel_remain_on_channel(sdata, cookie); |
| 1525 | } |
| 1526 | |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1527 | static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev, |
| 1528 | struct ieee80211_channel *chan, |
| 1529 | enum nl80211_channel_type channel_type, |
| 1530 | bool channel_type_valid, |
| 1531 | const u8 *buf, size_t len, u64 *cookie) |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 1532 | { |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 1533 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1534 | struct ieee80211_local *local = sdata->local; |
| 1535 | struct sk_buff *skb; |
| 1536 | struct sta_info *sta; |
| 1537 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
| 1538 | u32 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX | |
| 1539 | IEEE80211_TX_CTL_REQ_TX_STATUS; |
| 1540 | |
| 1541 | /* Check that we are on the requested channel for transmission */ |
| 1542 | if (chan != local->tmp_channel && |
| 1543 | chan != local->oper_channel) |
| 1544 | return -EBUSY; |
| 1545 | if (channel_type_valid && |
| 1546 | (channel_type != local->tmp_channel_type && |
| 1547 | channel_type != local->_oper_channel_type)) |
| 1548 | return -EBUSY; |
| 1549 | |
| 1550 | switch (sdata->vif.type) { |
| 1551 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 1552 | case NL80211_IFTYPE_AP: |
| 1553 | case NL80211_IFTYPE_AP_VLAN: |
| 1554 | case NL80211_IFTYPE_P2P_GO: |
| 1555 | if (!ieee80211_is_action(mgmt->frame_control) || |
| 1556 | mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 1557 | break; |
| 1558 | rcu_read_lock(); |
| 1559 | sta = sta_info_get(sdata, mgmt->da); |
| 1560 | rcu_read_unlock(); |
| 1561 | if (!sta) |
| 1562 | return -ENOLINK; |
| 1563 | break; |
| 1564 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 663fcaf | 2010-09-30 21:06:09 +0200 | [diff] [blame] | 1565 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | 9d38d85 | 2010-06-09 17:20:33 +0200 | [diff] [blame] | 1566 | break; |
| 1567 | default: |
| 1568 | return -EOPNOTSUPP; |
| 1569 | } |
| 1570 | |
| 1571 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + len); |
| 1572 | if (!skb) |
| 1573 | return -ENOMEM; |
| 1574 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 1575 | |
| 1576 | memcpy(skb_put(skb, len), buf, len); |
| 1577 | |
| 1578 | IEEE80211_SKB_CB(skb)->flags = flags; |
| 1579 | |
| 1580 | skb->dev = sdata->dev; |
| 1581 | ieee80211_tx_skb(sdata, skb); |
| 1582 | |
| 1583 | *cookie = (unsigned long) skb; |
| 1584 | return 0; |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 1585 | } |
| 1586 | |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1587 | struct cfg80211_ops mac80211_config_ops = { |
| 1588 | .add_virtual_intf = ieee80211_add_iface, |
| 1589 | .del_virtual_intf = ieee80211_del_iface, |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 1590 | .change_virtual_intf = ieee80211_change_iface, |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 1591 | .add_key = ieee80211_add_key, |
| 1592 | .del_key = ieee80211_del_key, |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 1593 | .get_key = ieee80211_get_key, |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 1594 | .set_default_key = ieee80211_config_default_key, |
Jouni Malinen | 3cfcf6a | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1595 | .set_default_mgmt_key = ieee80211_config_default_mgmt_key, |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1596 | .add_beacon = ieee80211_add_beacon, |
| 1597 | .set_beacon = ieee80211_set_beacon, |
| 1598 | .del_beacon = ieee80211_del_beacon, |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1599 | .add_station = ieee80211_add_station, |
| 1600 | .del_station = ieee80211_del_station, |
| 1601 | .change_station = ieee80211_change_station, |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 1602 | .get_station = ieee80211_get_station, |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1603 | .dump_station = ieee80211_dump_station, |
Holger Schurig | 1289723 | 2010-04-19 10:23:57 +0200 | [diff] [blame] | 1604 | .dump_survey = ieee80211_dump_survey, |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1605 | #ifdef CONFIG_MAC80211_MESH |
| 1606 | .add_mpath = ieee80211_add_mpath, |
| 1607 | .del_mpath = ieee80211_del_mpath, |
| 1608 | .change_mpath = ieee80211_change_mpath, |
| 1609 | .get_mpath = ieee80211_get_mpath, |
| 1610 | .dump_mpath = ieee80211_dump_mpath, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 1611 | .set_mesh_params = ieee80211_set_mesh_params, |
| 1612 | .get_mesh_params = ieee80211_get_mesh_params, |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1613 | #endif |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1614 | .change_bss = ieee80211_change_bss, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1615 | .set_txq_params = ieee80211_set_txq_params, |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1616 | .set_channel = ieee80211_set_channel, |
Bob Copeland | 665af4f | 2009-01-19 11:20:53 -0500 | [diff] [blame] | 1617 | .suspend = ieee80211_suspend, |
| 1618 | .resume = ieee80211_resume, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1619 | .scan = ieee80211_scan, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1620 | .auth = ieee80211_auth, |
| 1621 | .assoc = ieee80211_assoc, |
| 1622 | .deauth = ieee80211_deauth, |
| 1623 | .disassoc = ieee80211_disassoc, |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1624 | .join_ibss = ieee80211_join_ibss, |
| 1625 | .leave_ibss = ieee80211_leave_ibss, |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1626 | .set_wiphy_params = ieee80211_set_wiphy_params, |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 1627 | .set_tx_power = ieee80211_set_tx_power, |
| 1628 | .get_tx_power = ieee80211_get_tx_power, |
Johannes Berg | ab737a4 | 2009-07-01 21:26:58 +0200 | [diff] [blame] | 1629 | .set_wds_peer = ieee80211_set_wds_peer, |
Johannes Berg | 1f87f7d | 2009-06-02 13:01:41 +0200 | [diff] [blame] | 1630 | .rfkill_poll = ieee80211_rfkill_poll, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 1631 | CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd) |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 1632 | .set_power_mgmt = ieee80211_set_power_mgmt, |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 1633 | .set_bitrate_mask = ieee80211_set_bitrate_mask, |
Johannes Berg | b8bc4b0 | 2009-12-23 13:15:42 +0100 | [diff] [blame] | 1634 | .remain_on_channel = ieee80211_remain_on_channel, |
| 1635 | .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1636 | .mgmt_tx = ieee80211_mgmt_tx, |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 1637 | .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config, |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1638 | }; |