Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * mac80211 configuration hooks for cfg80211 |
| 3 | * |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 4 | * Copyright 2006, 2007 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> |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 12 | #include <net/net_namespace.h> |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 13 | #include <linux/rcupdate.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 14 | #include <net/cfg80211.h> |
| 15 | #include "ieee80211_i.h" |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 16 | #include "driver-ops.h" |
Michael Wu | e0eb685 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 17 | #include "cfg.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 18 | #include "rate.h" |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 19 | #include "mesh.h" |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 20 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 21 | static bool nl80211_type_check(enum nl80211_iftype type) |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 22 | { |
| 23 | switch (type) { |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 24 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 25 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 26 | case NL80211_IFTYPE_MONITOR: |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 27 | #ifdef CONFIG_MAC80211_MESH |
| 28 | case NL80211_IFTYPE_MESH_POINT: |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 29 | #endif |
Jouni Malinen | fbf1892 | 2008-10-30 19:50:30 +0200 | [diff] [blame] | 30 | case NL80211_IFTYPE_AP: |
| 31 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | b454048 | 2008-04-14 15:37:03 +0200 | [diff] [blame] | 32 | case NL80211_IFTYPE_WDS: |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 33 | return true; |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 34 | default: |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 35 | return false; |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 36 | } |
| 37 | } |
| 38 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 39 | static int ieee80211_add_iface(struct wiphy *wiphy, char *name, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 40 | enum nl80211_iftype type, u32 *flags, |
| 41 | struct vif_params *params) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 42 | { |
| 43 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Michael Wu | 8cc9a73 | 2008-01-31 19:48:23 +0100 | [diff] [blame] | 44 | struct net_device *dev; |
| 45 | struct ieee80211_sub_if_data *sdata; |
| 46 | int err; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 47 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 48 | if (!nl80211_type_check(type)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 49 | return -EINVAL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 50 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 51 | err = ieee80211_if_add(local, name, &dev, type, params); |
| 52 | if (err || type != NL80211_IFTYPE_MONITOR || !flags) |
Michael Wu | 8cc9a73 | 2008-01-31 19:48:23 +0100 | [diff] [blame] | 53 | return err; |
| 54 | |
| 55 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 56 | sdata->u.mntr_flags = *flags; |
| 57 | return 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex) |
| 61 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 62 | struct net_device *dev; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 63 | struct ieee80211_sub_if_data *sdata; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 64 | |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 65 | /* we're under RTNL */ |
| 66 | dev = __dev_get_by_index(&init_net, ifindex); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 67 | if (!dev) |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 68 | return -ENODEV; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 69 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 70 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 71 | |
| 72 | ieee80211_if_remove(sdata); |
Jiri Benc | f0706e8 | 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 | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 77 | static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 78 | enum nl80211_iftype type, u32 *flags, |
| 79 | struct vif_params *params) |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 80 | { |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 81 | struct net_device *dev; |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 82 | struct ieee80211_sub_if_data *sdata; |
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 | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 85 | /* we're under RTNL */ |
| 86 | dev = __dev_get_by_index(&init_net, ifindex); |
| 87 | if (!dev) |
| 88 | return -ENODEV; |
| 89 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 90 | if (!nl80211_type_check(type)) |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 91 | return -EINVAL; |
| 92 | |
| 93 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 94 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 95 | ret = ieee80211_if_change_type(sdata, type); |
Johannes Berg | f3947e2 | 2008-07-09 14:40:36 +0200 | [diff] [blame] | 96 | if (ret) |
| 97 | return ret; |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 98 | |
Johannes Berg | f8b25cd | 2008-09-16 20:22:21 +0200 | [diff] [blame] | 99 | if (netif_running(sdata->dev)) |
| 100 | return -EBUSY; |
| 101 | |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 102 | if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len) |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 103 | ieee80211_sdata_set_mesh_id(sdata, |
| 104 | params->mesh_id_len, |
| 105 | params->mesh_id); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 106 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 107 | if (sdata->vif.type != NL80211_IFTYPE_MONITOR || !flags) |
Michael Wu | 8cc9a73 | 2008-01-31 19:48:23 +0100 | [diff] [blame] | 108 | return 0; |
| 109 | |
| 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 | 3cfcf6ac | 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) { |
| 152 | sta = sta_info_get(sdata->local, 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 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 183 | sta = sta_info_get(sdata->local, mac_addr); |
| 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) { |
| 230 | sta = sta_info_get(sdata->local, mac_addr); |
| 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 | 3cfcf6ac | 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 | 3cfcf6ac | 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 | |
| 341 | sinfo->filled = STATION_INFO_INACTIVE_TIME | |
| 342 | STATION_INFO_RX_BYTES | |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 343 | STATION_INFO_TX_BYTES | |
Jouni Malinen | 98c8a60a | 2009-02-17 13:24:57 +0200 | [diff] [blame] | 344 | STATION_INFO_RX_PACKETS | |
| 345 | STATION_INFO_TX_PACKETS | |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 346 | STATION_INFO_TX_BITRATE; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 347 | |
| 348 | sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx); |
| 349 | sinfo->rx_bytes = sta->rx_bytes; |
| 350 | sinfo->tx_bytes = sta->tx_bytes; |
Jouni Malinen | 98c8a60a | 2009-02-17 13:24:57 +0200 | [diff] [blame] | 351 | sinfo->rx_packets = sta->rx_packets; |
| 352 | sinfo->tx_packets = sta->tx_packets; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 353 | |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 354 | if (sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) { |
| 355 | sinfo->filled |= STATION_INFO_SIGNAL; |
| 356 | sinfo->signal = (s8)sta->last_signal; |
| 357 | } |
| 358 | |
| 359 | sinfo->txrate.flags = 0; |
| 360 | if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS) |
| 361 | sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS; |
| 362 | if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH) |
| 363 | sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH; |
| 364 | if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI) |
| 365 | sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI; |
| 366 | |
| 367 | if (!(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) { |
| 368 | struct ieee80211_supported_band *sband; |
| 369 | sband = sta->local->hw.wiphy->bands[ |
| 370 | sta->local->hw.conf.channel->band]; |
| 371 | sinfo->txrate.legacy = |
| 372 | sband->bitrates[sta->last_tx_rate.idx].bitrate; |
| 373 | } else |
| 374 | sinfo->txrate.mcs = sta->last_tx_rate.idx; |
| 375 | |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 376 | if (ieee80211_vif_is_mesh(&sdata->vif)) { |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 377 | #ifdef CONFIG_MAC80211_MESH |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 378 | sinfo->filled |= STATION_INFO_LLID | |
| 379 | STATION_INFO_PLID | |
| 380 | STATION_INFO_PLINK_STATE; |
| 381 | |
| 382 | sinfo->llid = le16_to_cpu(sta->llid); |
| 383 | sinfo->plid = le16_to_cpu(sta->plid); |
| 384 | sinfo->plink_state = sta->plink_state; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 385 | #endif |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 386 | } |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | |
| 390 | static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev, |
| 391 | int idx, u8 *mac, struct station_info *sinfo) |
| 392 | { |
| 393 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 394 | struct sta_info *sta; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 395 | int ret = -ENOENT; |
| 396 | |
| 397 | rcu_read_lock(); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 398 | |
| 399 | sta = sta_info_get_by_idx(local, idx, dev); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 400 | if (sta) { |
| 401 | ret = 0; |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 402 | memcpy(mac, sta->sta.addr, ETH_ALEN); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 403 | sta_set_sinfo(sta, sinfo); |
| 404 | } |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 405 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 406 | rcu_read_unlock(); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 407 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 408 | return ret; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 409 | } |
| 410 | |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 411 | 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] | 412 | u8 *mac, struct station_info *sinfo) |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 413 | { |
| 414 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 415 | struct sta_info *sta; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 416 | int ret = -ENOENT; |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 417 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 418 | rcu_read_lock(); |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 419 | |
| 420 | /* XXX: verify sta->dev == dev */ |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 421 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 422 | sta = sta_info_get(local, mac); |
| 423 | if (sta) { |
| 424 | ret = 0; |
| 425 | sta_set_sinfo(sta, sinfo); |
| 426 | } |
| 427 | |
| 428 | rcu_read_unlock(); |
| 429 | |
| 430 | return ret; |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 431 | } |
| 432 | |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 433 | /* |
| 434 | * This handles both adding a beacon and setting new beacon info |
| 435 | */ |
| 436 | static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata, |
| 437 | struct beacon_parameters *params) |
| 438 | { |
| 439 | struct beacon_data *new, *old; |
| 440 | int new_head_len, new_tail_len; |
| 441 | int size; |
| 442 | int err = -EINVAL; |
| 443 | |
| 444 | old = sdata->u.ap.beacon; |
| 445 | |
| 446 | /* head must not be zero-length */ |
| 447 | if (params->head && !params->head_len) |
| 448 | return -EINVAL; |
| 449 | |
| 450 | /* |
| 451 | * This is a kludge. beacon interval should really be part |
| 452 | * of the beacon information. |
| 453 | */ |
Johannes Berg | 57c4d7b | 2009-04-23 16:10:04 +0200 | [diff] [blame] | 454 | if (params->interval && |
| 455 | (sdata->vif.bss_conf.beacon_int != params->interval)) { |
| 456 | sdata->vif.bss_conf.beacon_int = params->interval; |
| 457 | ieee80211_bss_info_change_notify(sdata, |
| 458 | BSS_CHANGED_BEACON_INT); |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | /* Need to have a beacon head if we don't have one yet */ |
| 462 | if (!params->head && !old) |
| 463 | return err; |
| 464 | |
| 465 | /* sorry, no way to start beaconing without dtim period */ |
| 466 | if (!params->dtim_period && !old) |
| 467 | return err; |
| 468 | |
| 469 | /* new or old head? */ |
| 470 | if (params->head) |
| 471 | new_head_len = params->head_len; |
| 472 | else |
| 473 | new_head_len = old->head_len; |
| 474 | |
| 475 | /* new or old tail? */ |
| 476 | if (params->tail || !old) |
| 477 | /* params->tail_len will be zero for !params->tail */ |
| 478 | new_tail_len = params->tail_len; |
| 479 | else |
| 480 | new_tail_len = old->tail_len; |
| 481 | |
| 482 | size = sizeof(*new) + new_head_len + new_tail_len; |
| 483 | |
| 484 | new = kzalloc(size, GFP_KERNEL); |
| 485 | if (!new) |
| 486 | return -ENOMEM; |
| 487 | |
| 488 | /* start filling the new info now */ |
| 489 | |
| 490 | /* new or old dtim period? */ |
| 491 | if (params->dtim_period) |
| 492 | new->dtim_period = params->dtim_period; |
| 493 | else |
| 494 | new->dtim_period = old->dtim_period; |
| 495 | |
| 496 | /* |
| 497 | * pointers go into the block we allocated, |
| 498 | * memory is | beacon_data | head | tail | |
| 499 | */ |
| 500 | new->head = ((u8 *) new) + sizeof(*new); |
| 501 | new->tail = new->head + new_head_len; |
| 502 | new->head_len = new_head_len; |
| 503 | new->tail_len = new_tail_len; |
| 504 | |
| 505 | /* copy in head */ |
| 506 | if (params->head) |
| 507 | memcpy(new->head, params->head, new_head_len); |
| 508 | else |
| 509 | memcpy(new->head, old->head, new_head_len); |
| 510 | |
| 511 | /* copy in optional tail */ |
| 512 | if (params->tail) |
| 513 | memcpy(new->tail, params->tail, new_tail_len); |
| 514 | else |
| 515 | if (old) |
| 516 | memcpy(new->tail, old->tail, new_tail_len); |
| 517 | |
| 518 | rcu_assign_pointer(sdata->u.ap.beacon, new); |
| 519 | |
| 520 | synchronize_rcu(); |
| 521 | |
| 522 | kfree(old); |
| 523 | |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 524 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED | |
| 525 | BSS_CHANGED_BEACON); |
| 526 | return 0; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev, |
| 530 | struct beacon_parameters *params) |
| 531 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 532 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 533 | struct beacon_data *old; |
| 534 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 535 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 536 | |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 537 | old = sdata->u.ap.beacon; |
| 538 | |
| 539 | if (old) |
| 540 | return -EALREADY; |
| 541 | |
| 542 | return ieee80211_config_beacon(sdata, params); |
| 543 | } |
| 544 | |
| 545 | static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev, |
| 546 | struct beacon_parameters *params) |
| 547 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 548 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 549 | struct beacon_data *old; |
| 550 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 551 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 552 | |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 553 | old = sdata->u.ap.beacon; |
| 554 | |
| 555 | if (!old) |
| 556 | return -ENOENT; |
| 557 | |
| 558 | return ieee80211_config_beacon(sdata, params); |
| 559 | } |
| 560 | |
| 561 | static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev) |
| 562 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 563 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 564 | struct beacon_data *old; |
| 565 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 566 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 567 | |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 568 | old = sdata->u.ap.beacon; |
| 569 | |
| 570 | if (!old) |
| 571 | return -ENOENT; |
| 572 | |
| 573 | rcu_assign_pointer(sdata->u.ap.beacon, NULL); |
| 574 | synchronize_rcu(); |
| 575 | kfree(old); |
| 576 | |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 577 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED); |
| 578 | return 0; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 579 | } |
| 580 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 581 | /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */ |
| 582 | struct iapp_layer2_update { |
| 583 | u8 da[ETH_ALEN]; /* broadcast */ |
| 584 | u8 sa[ETH_ALEN]; /* STA addr */ |
| 585 | __be16 len; /* 6 */ |
| 586 | u8 dsap; /* 0 */ |
| 587 | u8 ssap; /* 0 */ |
| 588 | u8 control; |
| 589 | u8 xid_info[3]; |
| 590 | } __attribute__ ((packed)); |
| 591 | |
| 592 | static void ieee80211_send_layer2_update(struct sta_info *sta) |
| 593 | { |
| 594 | struct iapp_layer2_update *msg; |
| 595 | struct sk_buff *skb; |
| 596 | |
| 597 | /* Send Level 2 Update Frame to update forwarding tables in layer 2 |
| 598 | * bridge devices */ |
| 599 | |
| 600 | skb = dev_alloc_skb(sizeof(*msg)); |
| 601 | if (!skb) |
| 602 | return; |
| 603 | msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg)); |
| 604 | |
| 605 | /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID) |
| 606 | * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */ |
| 607 | |
| 608 | memset(msg->da, 0xff, ETH_ALEN); |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 609 | memcpy(msg->sa, sta->sta.addr, ETH_ALEN); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 610 | msg->len = htons(6); |
| 611 | msg->dsap = 0; |
| 612 | msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */ |
| 613 | msg->control = 0xaf; /* XID response lsb.1111F101. |
| 614 | * F=0 (no poll command; unsolicited frame) */ |
| 615 | msg->xid_info[0] = 0x81; /* XID format identifier */ |
| 616 | msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */ |
| 617 | msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */ |
| 618 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 619 | skb->dev = sta->sdata->dev; |
| 620 | skb->protocol = eth_type_trans(skb, sta->sdata->dev); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 621 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 622 | netif_rx(skb); |
| 623 | } |
| 624 | |
| 625 | static void sta_apply_parameters(struct ieee80211_local *local, |
| 626 | struct sta_info *sta, |
| 627 | struct station_parameters *params) |
| 628 | { |
| 629 | u32 rates; |
| 630 | int i, j; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 631 | struct ieee80211_supported_band *sband; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 632 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 633 | u32 mask, set; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 634 | |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 635 | sband = local->hw.wiphy->bands[local->oper_channel->band]; |
| 636 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 637 | spin_lock_bh(&sta->lock); |
| 638 | mask = params->sta_flags_mask; |
| 639 | set = params->sta_flags_set; |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 640 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 641 | if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) { |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 642 | sta->flags &= ~WLAN_STA_AUTHORIZED; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 643 | if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 644 | sta->flags |= WLAN_STA_AUTHORIZED; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 645 | } |
| 646 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 647 | if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) { |
| 648 | sta->flags &= ~WLAN_STA_SHORT_PREAMBLE; |
| 649 | if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) |
| 650 | sta->flags |= WLAN_STA_SHORT_PREAMBLE; |
| 651 | } |
| 652 | |
| 653 | if (mask & BIT(NL80211_STA_FLAG_WME)) { |
| 654 | sta->flags &= ~WLAN_STA_WME; |
| 655 | if (set & BIT(NL80211_STA_FLAG_WME)) |
| 656 | sta->flags |= WLAN_STA_WME; |
| 657 | } |
| 658 | |
| 659 | if (mask & BIT(NL80211_STA_FLAG_MFP)) { |
| 660 | sta->flags &= ~WLAN_STA_MFP; |
| 661 | if (set & BIT(NL80211_STA_FLAG_MFP)) |
| 662 | sta->flags |= WLAN_STA_MFP; |
| 663 | } |
| 664 | spin_unlock_bh(&sta->lock); |
| 665 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 666 | /* |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 667 | * cfg80211 validates this (1-2007) and allows setting the AID |
| 668 | * only when creating a new station entry |
| 669 | */ |
| 670 | if (params->aid) |
| 671 | sta->sta.aid = params->aid; |
| 672 | |
| 673 | /* |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 674 | * FIXME: updating the following information is racy when this |
| 675 | * function is called from ieee80211_change_station(). |
| 676 | * However, all this information should be static so |
| 677 | * maybe we should just reject attemps to change it. |
| 678 | */ |
| 679 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 680 | if (params->listen_interval >= 0) |
| 681 | sta->listen_interval = params->listen_interval; |
| 682 | |
| 683 | if (params->supported_rates) { |
| 684 | rates = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 685 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 686 | for (i = 0; i < params->supported_rates_len; i++) { |
| 687 | int rate = (params->supported_rates[i] & 0x7f) * 5; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 688 | for (j = 0; j < sband->n_bitrates; j++) { |
| 689 | if (sband->bitrates[j].bitrate == rate) |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 690 | rates |= BIT(j); |
| 691 | } |
| 692 | } |
Johannes Berg | 323ce79 | 2008-09-11 02:45:11 +0200 | [diff] [blame] | 693 | sta->sta.supp_rates[local->oper_channel->band] = rates; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 694 | } |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 695 | |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 696 | if (params->ht_capa) |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 697 | ieee80211_ht_cap_ie_to_sta_ht_cap(sband, |
| 698 | params->ht_capa, |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 699 | &sta->sta.ht_cap); |
Jouni Malinen | 36aedc90 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 700 | |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 701 | if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) { |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 702 | switch (params->plink_action) { |
| 703 | case PLINK_ACTION_OPEN: |
| 704 | mesh_plink_open(sta); |
| 705 | break; |
| 706 | case PLINK_ACTION_BLOCK: |
| 707 | mesh_plink_block(sta); |
| 708 | break; |
| 709 | } |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 710 | } |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev, |
| 714 | u8 *mac, struct station_parameters *params) |
| 715 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 716 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 717 | struct sta_info *sta; |
| 718 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 719 | int err; |
Jouni Malinen | b8d476c | 2008-12-12 17:08:31 +0200 | [diff] [blame] | 720 | int layer2_update; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 721 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 722 | if (params->vlan) { |
| 723 | sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); |
| 724 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 725 | if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN && |
| 726 | sdata->vif.type != NL80211_IFTYPE_AP) |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 727 | return -EINVAL; |
| 728 | } else |
| 729 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 730 | |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 731 | if (compare_ether_addr(mac, dev->dev_addr) == 0) |
| 732 | return -EINVAL; |
| 733 | |
| 734 | if (is_multicast_ether_addr(mac)) |
| 735 | return -EINVAL; |
| 736 | |
| 737 | sta = sta_info_alloc(sdata, mac, GFP_KERNEL); |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 738 | if (!sta) |
| 739 | return -ENOMEM; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 740 | |
| 741 | sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC; |
| 742 | |
| 743 | sta_apply_parameters(local, sta, params); |
| 744 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 745 | rate_control_rate_init(sta); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 746 | |
Jouni Malinen | b8d476c | 2008-12-12 17:08:31 +0200 | [diff] [blame] | 747 | layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN || |
| 748 | sdata->vif.type == NL80211_IFTYPE_AP; |
| 749 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 750 | rcu_read_lock(); |
| 751 | |
| 752 | err = sta_info_insert(sta); |
| 753 | if (err) { |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 754 | /* STA has been freed */ |
Jouni Malinen | b8d476c | 2008-12-12 17:08:31 +0200 | [diff] [blame] | 755 | if (err == -EEXIST && layer2_update) { |
| 756 | /* Need to update layer 2 devices on reassociation */ |
| 757 | sta = sta_info_get(local, mac); |
| 758 | if (sta) |
| 759 | ieee80211_send_layer2_update(sta); |
| 760 | } |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 761 | rcu_read_unlock(); |
| 762 | return err; |
| 763 | } |
| 764 | |
Jouni Malinen | b8d476c | 2008-12-12 17:08:31 +0200 | [diff] [blame] | 765 | if (layer2_update) |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 766 | ieee80211_send_layer2_update(sta); |
| 767 | |
| 768 | rcu_read_unlock(); |
| 769 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 770 | return 0; |
| 771 | } |
| 772 | |
| 773 | static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev, |
| 774 | u8 *mac) |
| 775 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 776 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 777 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 778 | struct sta_info *sta; |
| 779 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 780 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 781 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 782 | if (mac) { |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 783 | rcu_read_lock(); |
| 784 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 785 | /* XXX: get sta belonging to dev */ |
| 786 | sta = sta_info_get(local, mac); |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 787 | if (!sta) { |
| 788 | rcu_read_unlock(); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 789 | return -ENOENT; |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 790 | } |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 791 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 792 | sta_info_unlink(&sta); |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 793 | rcu_read_unlock(); |
| 794 | |
Johannes Berg | 4f6fab4 | 2008-03-31 19:23:02 +0200 | [diff] [blame] | 795 | sta_info_destroy(sta); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 796 | } else |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 797 | sta_info_flush(local, sdata); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 798 | |
| 799 | return 0; |
| 800 | } |
| 801 | |
| 802 | static int ieee80211_change_station(struct wiphy *wiphy, |
| 803 | struct net_device *dev, |
| 804 | u8 *mac, |
| 805 | struct station_parameters *params) |
| 806 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 807 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 808 | struct sta_info *sta; |
| 809 | struct ieee80211_sub_if_data *vlansdata; |
| 810 | |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 811 | rcu_read_lock(); |
| 812 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 813 | /* XXX: get sta belonging to dev */ |
| 814 | sta = sta_info_get(local, mac); |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 815 | if (!sta) { |
| 816 | rcu_read_unlock(); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 817 | return -ENOENT; |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 818 | } |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 819 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 820 | if (params->vlan && params->vlan != sta->sdata->dev) { |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 821 | vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); |
| 822 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 823 | if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN && |
| 824 | vlansdata->vif.type != NL80211_IFTYPE_AP) { |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 825 | rcu_read_unlock(); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 826 | return -EINVAL; |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 827 | } |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 828 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 829 | sta->sdata = vlansdata; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 830 | ieee80211_send_layer2_update(sta); |
| 831 | } |
| 832 | |
| 833 | sta_apply_parameters(local, sta, params); |
| 834 | |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 835 | rcu_read_unlock(); |
| 836 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 837 | return 0; |
| 838 | } |
| 839 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 840 | #ifdef CONFIG_MAC80211_MESH |
| 841 | static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev, |
| 842 | u8 *dst, u8 *next_hop) |
| 843 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 844 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 845 | struct ieee80211_sub_if_data *sdata; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 846 | struct mesh_path *mpath; |
| 847 | struct sta_info *sta; |
| 848 | int err; |
| 849 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 850 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 851 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 852 | rcu_read_lock(); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 853 | sta = sta_info_get(local, next_hop); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 854 | if (!sta) { |
| 855 | rcu_read_unlock(); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 856 | return -ENOENT; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 857 | } |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 858 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 859 | err = mesh_path_add(dst, sdata); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 860 | if (err) { |
| 861 | rcu_read_unlock(); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 862 | return err; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 863 | } |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 864 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 865 | mpath = mesh_path_lookup(dst, sdata); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 866 | if (!mpath) { |
| 867 | rcu_read_unlock(); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 868 | return -ENXIO; |
| 869 | } |
| 870 | mesh_path_fix_nexthop(mpath, sta); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 871 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 872 | rcu_read_unlock(); |
| 873 | return 0; |
| 874 | } |
| 875 | |
| 876 | static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev, |
| 877 | u8 *dst) |
| 878 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 879 | 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] | 880 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 881 | if (dst) |
| 882 | return mesh_path_del(dst, sdata); |
| 883 | |
| 884 | mesh_path_flush(sdata); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 885 | return 0; |
| 886 | } |
| 887 | |
| 888 | static int ieee80211_change_mpath(struct wiphy *wiphy, |
| 889 | struct net_device *dev, |
| 890 | u8 *dst, u8 *next_hop) |
| 891 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 892 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 893 | struct ieee80211_sub_if_data *sdata; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 894 | struct mesh_path *mpath; |
| 895 | struct sta_info *sta; |
| 896 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 897 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 898 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 899 | rcu_read_lock(); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 900 | |
| 901 | sta = sta_info_get(local, next_hop); |
| 902 | if (!sta) { |
| 903 | rcu_read_unlock(); |
| 904 | return -ENOENT; |
| 905 | } |
| 906 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 907 | mpath = mesh_path_lookup(dst, sdata); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 908 | if (!mpath) { |
| 909 | rcu_read_unlock(); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 910 | return -ENOENT; |
| 911 | } |
| 912 | |
| 913 | mesh_path_fix_nexthop(mpath, sta); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 914 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 915 | rcu_read_unlock(); |
| 916 | return 0; |
| 917 | } |
| 918 | |
| 919 | static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop, |
| 920 | struct mpath_info *pinfo) |
| 921 | { |
| 922 | if (mpath->next_hop) |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 923 | memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 924 | else |
| 925 | memset(next_hop, 0, ETH_ALEN); |
| 926 | |
| 927 | pinfo->filled = MPATH_INFO_FRAME_QLEN | |
| 928 | MPATH_INFO_DSN | |
| 929 | MPATH_INFO_METRIC | |
| 930 | MPATH_INFO_EXPTIME | |
| 931 | MPATH_INFO_DISCOVERY_TIMEOUT | |
| 932 | MPATH_INFO_DISCOVERY_RETRIES | |
| 933 | MPATH_INFO_FLAGS; |
| 934 | |
| 935 | pinfo->frame_qlen = mpath->frame_queue.qlen; |
| 936 | pinfo->dsn = mpath->dsn; |
| 937 | pinfo->metric = mpath->metric; |
| 938 | if (time_before(jiffies, mpath->exp_time)) |
| 939 | pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies); |
| 940 | pinfo->discovery_timeout = |
| 941 | jiffies_to_msecs(mpath->discovery_timeout); |
| 942 | pinfo->discovery_retries = mpath->discovery_retries; |
| 943 | pinfo->flags = 0; |
| 944 | if (mpath->flags & MESH_PATH_ACTIVE) |
| 945 | pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE; |
| 946 | if (mpath->flags & MESH_PATH_RESOLVING) |
| 947 | pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING; |
| 948 | if (mpath->flags & MESH_PATH_DSN_VALID) |
| 949 | pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID; |
| 950 | if (mpath->flags & MESH_PATH_FIXED) |
| 951 | pinfo->flags |= NL80211_MPATH_FLAG_FIXED; |
| 952 | if (mpath->flags & MESH_PATH_RESOLVING) |
| 953 | pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING; |
| 954 | |
| 955 | pinfo->flags = mpath->flags; |
| 956 | } |
| 957 | |
| 958 | static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev, |
| 959 | u8 *dst, u8 *next_hop, struct mpath_info *pinfo) |
| 960 | |
| 961 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 962 | struct ieee80211_sub_if_data *sdata; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 963 | struct mesh_path *mpath; |
| 964 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 965 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 966 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 967 | rcu_read_lock(); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 968 | mpath = mesh_path_lookup(dst, sdata); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 969 | if (!mpath) { |
| 970 | rcu_read_unlock(); |
| 971 | return -ENOENT; |
| 972 | } |
| 973 | memcpy(dst, mpath->dst, ETH_ALEN); |
| 974 | mpath_set_pinfo(mpath, next_hop, pinfo); |
| 975 | rcu_read_unlock(); |
| 976 | return 0; |
| 977 | } |
| 978 | |
| 979 | static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev, |
| 980 | int idx, u8 *dst, u8 *next_hop, |
| 981 | struct mpath_info *pinfo) |
| 982 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 983 | struct ieee80211_sub_if_data *sdata; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 984 | struct mesh_path *mpath; |
| 985 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 986 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 987 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 988 | rcu_read_lock(); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 989 | mpath = mesh_path_lookup_by_idx(idx, sdata); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 990 | if (!mpath) { |
| 991 | rcu_read_unlock(); |
| 992 | return -ENOENT; |
| 993 | } |
| 994 | memcpy(dst, mpath->dst, ETH_ALEN); |
| 995 | mpath_set_pinfo(mpath, next_hop, pinfo); |
| 996 | rcu_read_unlock(); |
| 997 | return 0; |
| 998 | } |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 999 | |
| 1000 | static int ieee80211_get_mesh_params(struct wiphy *wiphy, |
| 1001 | struct net_device *dev, |
| 1002 | struct mesh_config *conf) |
| 1003 | { |
| 1004 | struct ieee80211_sub_if_data *sdata; |
| 1005 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1006 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 1007 | memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config)); |
| 1008 | return 0; |
| 1009 | } |
| 1010 | |
| 1011 | static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask) |
| 1012 | { |
| 1013 | return (mask >> (parm-1)) & 0x1; |
| 1014 | } |
| 1015 | |
| 1016 | static int ieee80211_set_mesh_params(struct wiphy *wiphy, |
| 1017 | struct net_device *dev, |
| 1018 | const struct mesh_config *nconf, u32 mask) |
| 1019 | { |
| 1020 | struct mesh_config *conf; |
| 1021 | struct ieee80211_sub_if_data *sdata; |
| 1022 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1023 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 1024 | /* Set the config options which we are interested in setting */ |
| 1025 | conf = &(sdata->u.mesh.mshcfg); |
| 1026 | if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask)) |
| 1027 | conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout; |
| 1028 | if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask)) |
| 1029 | conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout; |
| 1030 | if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask)) |
| 1031 | conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout; |
| 1032 | if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask)) |
| 1033 | conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks; |
| 1034 | if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask)) |
| 1035 | conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries; |
| 1036 | if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask)) |
| 1037 | conf->dot11MeshTTL = nconf->dot11MeshTTL; |
| 1038 | if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) |
| 1039 | conf->auto_open_plinks = nconf->auto_open_plinks; |
| 1040 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask)) |
| 1041 | conf->dot11MeshHWMPmaxPREQretries = |
| 1042 | nconf->dot11MeshHWMPmaxPREQretries; |
| 1043 | if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask)) |
| 1044 | conf->path_refresh_time = nconf->path_refresh_time; |
| 1045 | if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask)) |
| 1046 | conf->min_discovery_timeout = nconf->min_discovery_timeout; |
| 1047 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask)) |
| 1048 | conf->dot11MeshHWMPactivePathTimeout = |
| 1049 | nconf->dot11MeshHWMPactivePathTimeout; |
| 1050 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask)) |
| 1051 | conf->dot11MeshHWMPpreqMinInterval = |
| 1052 | nconf->dot11MeshHWMPpreqMinInterval; |
| 1053 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 1054 | mask)) |
| 1055 | conf->dot11MeshHWMPnetDiameterTraversalTime = |
| 1056 | nconf->dot11MeshHWMPnetDiameterTraversalTime; |
| 1057 | return 0; |
| 1058 | } |
| 1059 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1060 | #endif |
| 1061 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1062 | static int ieee80211_change_bss(struct wiphy *wiphy, |
| 1063 | struct net_device *dev, |
| 1064 | struct bss_parameters *params) |
| 1065 | { |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1066 | struct ieee80211_sub_if_data *sdata; |
| 1067 | u32 changed = 0; |
| 1068 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1069 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1070 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1071 | if (params->use_cts_prot >= 0) { |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 1072 | sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1073 | changed |= BSS_CHANGED_ERP_CTS_PROT; |
| 1074 | } |
| 1075 | if (params->use_short_preamble >= 0) { |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 1076 | sdata->vif.bss_conf.use_short_preamble = |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1077 | params->use_short_preamble; |
| 1078 | changed |= BSS_CHANGED_ERP_PREAMBLE; |
| 1079 | } |
| 1080 | if (params->use_short_slot_time >= 0) { |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 1081 | sdata->vif.bss_conf.use_short_slot = |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1082 | params->use_short_slot_time; |
| 1083 | changed |= BSS_CHANGED_ERP_SLOT; |
| 1084 | } |
| 1085 | |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 1086 | if (params->basic_rates) { |
| 1087 | int i, j; |
| 1088 | u32 rates = 0; |
| 1089 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 1090 | struct ieee80211_supported_band *sband = |
| 1091 | wiphy->bands[local->oper_channel->band]; |
| 1092 | |
| 1093 | for (i = 0; i < params->basic_rates_len; i++) { |
| 1094 | int rate = (params->basic_rates[i] & 0x7f) * 5; |
| 1095 | for (j = 0; j < sband->n_bitrates; j++) { |
| 1096 | if (sband->bitrates[j].bitrate == rate) |
| 1097 | rates |= BIT(j); |
| 1098 | } |
| 1099 | } |
| 1100 | sdata->vif.bss_conf.basic_rates = rates; |
| 1101 | changed |= BSS_CHANGED_BASIC_RATES; |
| 1102 | } |
| 1103 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1104 | ieee80211_bss_info_change_notify(sdata, changed); |
| 1105 | |
| 1106 | return 0; |
| 1107 | } |
| 1108 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1109 | static int ieee80211_set_txq_params(struct wiphy *wiphy, |
| 1110 | struct ieee80211_txq_params *params) |
| 1111 | { |
| 1112 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 1113 | struct ieee80211_tx_queue_params p; |
| 1114 | |
| 1115 | if (!local->ops->conf_tx) |
| 1116 | return -EOPNOTSUPP; |
| 1117 | |
| 1118 | memset(&p, 0, sizeof(p)); |
| 1119 | p.aifs = params->aifs; |
| 1120 | p.cw_max = params->cwmax; |
| 1121 | p.cw_min = params->cwmin; |
| 1122 | p.txop = params->txop; |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 1123 | if (drv_conf_tx(local, params->queue, &p)) { |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1124 | printk(KERN_DEBUG "%s: failed to set TX queue " |
Johannes Berg | 0bffe40 | 2009-06-09 16:18:32 +0200 | [diff] [blame] | 1125 | "parameters for queue %d\n", |
| 1126 | wiphy_name(local->hw.wiphy), params->queue); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1127 | return -EINVAL; |
| 1128 | } |
| 1129 | |
| 1130 | return 0; |
| 1131 | } |
| 1132 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1133 | static int ieee80211_set_channel(struct wiphy *wiphy, |
| 1134 | struct ieee80211_channel *chan, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 1135 | enum nl80211_channel_type channel_type) |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1136 | { |
| 1137 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 1138 | |
| 1139 | local->oper_channel = chan; |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 1140 | local->oper_channel_type = channel_type; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1141 | |
| 1142 | return ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL); |
| 1143 | } |
| 1144 | |
Bob Copeland | 665af4f | 2009-01-19 11:20:53 -0500 | [diff] [blame] | 1145 | #ifdef CONFIG_PM |
| 1146 | static int ieee80211_suspend(struct wiphy *wiphy) |
| 1147 | { |
| 1148 | return __ieee80211_suspend(wiphy_priv(wiphy)); |
| 1149 | } |
| 1150 | |
| 1151 | static int ieee80211_resume(struct wiphy *wiphy) |
| 1152 | { |
| 1153 | return __ieee80211_resume(wiphy_priv(wiphy)); |
| 1154 | } |
| 1155 | #else |
| 1156 | #define ieee80211_suspend NULL |
| 1157 | #define ieee80211_resume NULL |
| 1158 | #endif |
| 1159 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1160 | static int ieee80211_scan(struct wiphy *wiphy, |
| 1161 | struct net_device *dev, |
| 1162 | struct cfg80211_scan_request *req) |
| 1163 | { |
| 1164 | struct ieee80211_sub_if_data *sdata; |
| 1165 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1166 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1167 | |
| 1168 | if (sdata->vif.type != NL80211_IFTYPE_STATION && |
| 1169 | sdata->vif.type != NL80211_IFTYPE_ADHOC && |
Jouni Malinen | 357303e | 2009-04-16 18:44:53 +0300 | [diff] [blame] | 1170 | sdata->vif.type != NL80211_IFTYPE_MESH_POINT && |
| 1171 | (sdata->vif.type != NL80211_IFTYPE_AP || sdata->u.ap.beacon)) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1172 | return -EOPNOTSUPP; |
| 1173 | |
| 1174 | return ieee80211_request_scan(sdata, req); |
| 1175 | } |
| 1176 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1177 | static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev, |
| 1178 | struct cfg80211_auth_request *req) |
| 1179 | { |
| 1180 | struct ieee80211_sub_if_data *sdata; |
| 1181 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1182 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1183 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1184 | switch (req->auth_type) { |
| 1185 | case NL80211_AUTHTYPE_OPEN_SYSTEM: |
| 1186 | sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_OPEN; |
| 1187 | break; |
| 1188 | case NL80211_AUTHTYPE_SHARED_KEY: |
| 1189 | sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_SHARED_KEY; |
| 1190 | break; |
| 1191 | case NL80211_AUTHTYPE_FT: |
| 1192 | sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_FT; |
| 1193 | break; |
| 1194 | case NL80211_AUTHTYPE_NETWORK_EAP: |
| 1195 | sdata->u.mgd.auth_algs = IEEE80211_AUTH_ALG_LEAP; |
| 1196 | break; |
| 1197 | default: |
| 1198 | return -EOPNOTSUPP; |
| 1199 | } |
| 1200 | |
| 1201 | memcpy(sdata->u.mgd.bssid, req->peer_addr, ETH_ALEN); |
| 1202 | sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL; |
| 1203 | sdata->u.mgd.flags |= IEEE80211_STA_BSSID_SET; |
| 1204 | |
| 1205 | /* TODO: req->chan */ |
| 1206 | sdata->u.mgd.flags |= IEEE80211_STA_AUTO_CHANNEL_SEL; |
| 1207 | |
| 1208 | if (req->ssid) { |
| 1209 | sdata->u.mgd.flags |= IEEE80211_STA_SSID_SET; |
| 1210 | memcpy(sdata->u.mgd.ssid, req->ssid, req->ssid_len); |
| 1211 | sdata->u.mgd.ssid_len = req->ssid_len; |
| 1212 | sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL; |
| 1213 | } |
| 1214 | |
| 1215 | kfree(sdata->u.mgd.sme_auth_ie); |
| 1216 | sdata->u.mgd.sme_auth_ie = NULL; |
| 1217 | sdata->u.mgd.sme_auth_ie_len = 0; |
| 1218 | if (req->ie) { |
| 1219 | sdata->u.mgd.sme_auth_ie = kmalloc(req->ie_len, GFP_KERNEL); |
| 1220 | if (sdata->u.mgd.sme_auth_ie == NULL) |
| 1221 | return -ENOMEM; |
| 1222 | memcpy(sdata->u.mgd.sme_auth_ie, req->ie, req->ie_len); |
| 1223 | sdata->u.mgd.sme_auth_ie_len = req->ie_len; |
| 1224 | } |
| 1225 | |
| 1226 | sdata->u.mgd.flags |= IEEE80211_STA_EXT_SME; |
| 1227 | sdata->u.mgd.state = IEEE80211_STA_MLME_DIRECT_PROBE; |
| 1228 | ieee80211_sta_req_auth(sdata); |
| 1229 | return 0; |
| 1230 | } |
| 1231 | |
| 1232 | static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev, |
| 1233 | struct cfg80211_assoc_request *req) |
| 1234 | { |
| 1235 | struct ieee80211_sub_if_data *sdata; |
| 1236 | int ret; |
| 1237 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1238 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1239 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1240 | if (memcmp(sdata->u.mgd.bssid, req->peer_addr, ETH_ALEN) != 0 || |
| 1241 | !(sdata->u.mgd.flags & IEEE80211_STA_AUTHENTICATED)) |
| 1242 | return -ENOLINK; /* not authenticated */ |
| 1243 | |
| 1244 | sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL; |
| 1245 | sdata->u.mgd.flags |= IEEE80211_STA_BSSID_SET; |
| 1246 | |
| 1247 | /* TODO: req->chan */ |
| 1248 | sdata->u.mgd.flags |= IEEE80211_STA_AUTO_CHANNEL_SEL; |
| 1249 | |
| 1250 | if (req->ssid) { |
| 1251 | sdata->u.mgd.flags |= IEEE80211_STA_SSID_SET; |
| 1252 | memcpy(sdata->u.mgd.ssid, req->ssid, req->ssid_len); |
| 1253 | sdata->u.mgd.ssid_len = req->ssid_len; |
| 1254 | sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL; |
| 1255 | } else |
| 1256 | sdata->u.mgd.flags |= IEEE80211_STA_AUTO_SSID_SEL; |
| 1257 | |
| 1258 | ret = ieee80211_sta_set_extra_ie(sdata, req->ie, req->ie_len); |
Luis R. Rodriguez | 86ab04c | 2009-05-27 22:56:05 -0400 | [diff] [blame] | 1259 | if (ret && ret != -EALREADY) |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1260 | return ret; |
| 1261 | |
Jouni Malinen | dc6382c | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 1262 | if (req->use_mfp) { |
| 1263 | sdata->u.mgd.mfp = IEEE80211_MFP_REQUIRED; |
| 1264 | sdata->u.mgd.flags |= IEEE80211_STA_MFP_ENABLED; |
| 1265 | } else { |
| 1266 | sdata->u.mgd.mfp = IEEE80211_MFP_DISABLED; |
| 1267 | sdata->u.mgd.flags &= ~IEEE80211_STA_MFP_ENABLED; |
| 1268 | } |
| 1269 | |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 1270 | if (req->control_port) |
| 1271 | sdata->u.mgd.flags |= IEEE80211_STA_CONTROL_PORT; |
| 1272 | else |
| 1273 | sdata->u.mgd.flags &= ~IEEE80211_STA_CONTROL_PORT; |
| 1274 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1275 | sdata->u.mgd.flags |= IEEE80211_STA_EXT_SME; |
| 1276 | sdata->u.mgd.state = IEEE80211_STA_MLME_ASSOCIATE; |
| 1277 | ieee80211_sta_req_auth(sdata); |
| 1278 | return 0; |
| 1279 | } |
| 1280 | |
| 1281 | static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev, |
| 1282 | struct cfg80211_deauth_request *req) |
| 1283 | { |
Johannes Berg | 691597c | 2009-04-19 19:57:45 +0200 | [diff] [blame] | 1284 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1285 | |
Johannes Berg | 691597c | 2009-04-19 19:57:45 +0200 | [diff] [blame] | 1286 | /* TODO: req->ie, req->peer_addr */ |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1287 | return ieee80211_sta_deauthenticate(sdata, req->reason_code); |
| 1288 | } |
| 1289 | |
| 1290 | static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev, |
| 1291 | struct cfg80211_disassoc_request *req) |
| 1292 | { |
Johannes Berg | 691597c | 2009-04-19 19:57:45 +0200 | [diff] [blame] | 1293 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1294 | |
Johannes Berg | 691597c | 2009-04-19 19:57:45 +0200 | [diff] [blame] | 1295 | /* TODO: req->ie, req->peer_addr */ |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1296 | return ieee80211_sta_disassociate(sdata, req->reason_code); |
| 1297 | } |
| 1298 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1299 | static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev, |
| 1300 | struct cfg80211_ibss_params *params) |
| 1301 | { |
| 1302 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1303 | |
| 1304 | return ieee80211_ibss_join(sdata, params); |
| 1305 | } |
| 1306 | |
| 1307 | static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev) |
| 1308 | { |
| 1309 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1310 | |
| 1311 | return ieee80211_ibss_leave(sdata); |
| 1312 | } |
| 1313 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1314 | static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed) |
| 1315 | { |
| 1316 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 1317 | int err; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1318 | |
| 1319 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) { |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 1320 | err = drv_set_rts_threshold(local, wiphy->rts_threshold); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1321 | |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 1322 | if (err) |
| 1323 | return err; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1324 | } |
| 1325 | |
| 1326 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 1327 | local->hw.conf.short_frame_max_tx_count = wiphy->retry_short; |
| 1328 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 1329 | local->hw.conf.long_frame_max_tx_count = wiphy->retry_long; |
| 1330 | if (changed & |
| 1331 | (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG)) |
| 1332 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS); |
| 1333 | |
| 1334 | return 0; |
| 1335 | } |
| 1336 | |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 1337 | static int ieee80211_set_tx_power(struct wiphy *wiphy, |
| 1338 | enum tx_power_setting type, int dbm) |
| 1339 | { |
| 1340 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 1341 | struct ieee80211_channel *chan = local->hw.conf.channel; |
| 1342 | u32 changes = 0; |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 1343 | |
| 1344 | switch (type) { |
| 1345 | case TX_POWER_AUTOMATIC: |
| 1346 | local->user_power_level = -1; |
| 1347 | break; |
| 1348 | case TX_POWER_LIMITED: |
| 1349 | if (dbm < 0) |
| 1350 | return -EINVAL; |
| 1351 | local->user_power_level = dbm; |
| 1352 | break; |
| 1353 | case TX_POWER_FIXED: |
| 1354 | if (dbm < 0) |
| 1355 | return -EINVAL; |
| 1356 | /* TODO: move to cfg80211 when it knows the channel */ |
| 1357 | if (dbm > chan->max_power) |
| 1358 | return -EINVAL; |
| 1359 | local->user_power_level = dbm; |
| 1360 | break; |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | ieee80211_hw_config(local, changes); |
| 1364 | |
| 1365 | return 0; |
| 1366 | } |
| 1367 | |
| 1368 | static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm) |
| 1369 | { |
| 1370 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 1371 | |
| 1372 | *dbm = local->hw.conf.power_level; |
| 1373 | |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 1374 | return 0; |
| 1375 | } |
| 1376 | |
Johannes Berg | 1f87f7d | 2009-06-02 13:01:41 +0200 | [diff] [blame] | 1377 | static void ieee80211_rfkill_poll(struct wiphy *wiphy) |
| 1378 | { |
| 1379 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 1380 | |
| 1381 | drv_rfkill_poll(local); |
| 1382 | } |
| 1383 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1384 | struct cfg80211_ops mac80211_config_ops = { |
| 1385 | .add_virtual_intf = ieee80211_add_iface, |
| 1386 | .del_virtual_intf = ieee80211_del_iface, |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 1387 | .change_virtual_intf = ieee80211_change_iface, |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 1388 | .add_key = ieee80211_add_key, |
| 1389 | .del_key = ieee80211_del_key, |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 1390 | .get_key = ieee80211_get_key, |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 1391 | .set_default_key = ieee80211_config_default_key, |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1392 | .set_default_mgmt_key = ieee80211_config_default_mgmt_key, |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1393 | .add_beacon = ieee80211_add_beacon, |
| 1394 | .set_beacon = ieee80211_set_beacon, |
| 1395 | .del_beacon = ieee80211_del_beacon, |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1396 | .add_station = ieee80211_add_station, |
| 1397 | .del_station = ieee80211_del_station, |
| 1398 | .change_station = ieee80211_change_station, |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 1399 | .get_station = ieee80211_get_station, |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1400 | .dump_station = ieee80211_dump_station, |
| 1401 | #ifdef CONFIG_MAC80211_MESH |
| 1402 | .add_mpath = ieee80211_add_mpath, |
| 1403 | .del_mpath = ieee80211_del_mpath, |
| 1404 | .change_mpath = ieee80211_change_mpath, |
| 1405 | .get_mpath = ieee80211_get_mpath, |
| 1406 | .dump_mpath = ieee80211_dump_mpath, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 1407 | .set_mesh_params = ieee80211_set_mesh_params, |
| 1408 | .get_mesh_params = ieee80211_get_mesh_params, |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1409 | #endif |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1410 | .change_bss = ieee80211_change_bss, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1411 | .set_txq_params = ieee80211_set_txq_params, |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 1412 | .set_channel = ieee80211_set_channel, |
Bob Copeland | 665af4f | 2009-01-19 11:20:53 -0500 | [diff] [blame] | 1413 | .suspend = ieee80211_suspend, |
| 1414 | .resume = ieee80211_resume, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1415 | .scan = ieee80211_scan, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 1416 | .auth = ieee80211_auth, |
| 1417 | .assoc = ieee80211_assoc, |
| 1418 | .deauth = ieee80211_deauth, |
| 1419 | .disassoc = ieee80211_disassoc, |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 1420 | .join_ibss = ieee80211_join_ibss, |
| 1421 | .leave_ibss = ieee80211_leave_ibss, |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 1422 | .set_wiphy_params = ieee80211_set_wiphy_params, |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 1423 | .set_tx_power = ieee80211_set_tx_power, |
| 1424 | .get_tx_power = ieee80211_get_tx_power, |
Johannes Berg | 1f87f7d | 2009-06-02 13:01:41 +0200 | [diff] [blame] | 1425 | .rfkill_poll = ieee80211_rfkill_poll, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1426 | }; |