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