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