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