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