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" |
Michael Wu | e0eb685 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 16 | #include "cfg.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 17 | #include "rate.h" |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 18 | #include "mesh.h" |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 19 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 20 | static bool nl80211_type_check(enum nl80211_iftype type) |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 21 | { |
| 22 | switch (type) { |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 23 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 24 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 25 | case NL80211_IFTYPE_MONITOR: |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 26 | #ifdef CONFIG_MAC80211_MESH |
| 27 | case NL80211_IFTYPE_MESH_POINT: |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 28 | #endif |
Jouni Malinen | fbf1892 | 2008-10-30 19:50:30 +0200 | [diff] [blame^] | 29 | case NL80211_IFTYPE_AP: |
| 30 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | b454048 | 2008-04-14 15:37:03 +0200 | [diff] [blame] | 31 | case NL80211_IFTYPE_WDS: |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 32 | return true; |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 33 | default: |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 34 | return false; |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 35 | } |
| 36 | } |
| 37 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 38 | static int ieee80211_add_iface(struct wiphy *wiphy, char *name, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 39 | enum nl80211_iftype type, u32 *flags, |
| 40 | struct vif_params *params) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 41 | { |
| 42 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Michael Wu | 8cc9a73 | 2008-01-31 19:48:23 +0100 | [diff] [blame] | 43 | struct net_device *dev; |
| 44 | struct ieee80211_sub_if_data *sdata; |
| 45 | int err; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 46 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 47 | if (!nl80211_type_check(type)) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 48 | return -EINVAL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 49 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 50 | err = ieee80211_if_add(local, name, &dev, type, params); |
| 51 | if (err || type != NL80211_IFTYPE_MONITOR || !flags) |
Michael Wu | 8cc9a73 | 2008-01-31 19:48:23 +0100 | [diff] [blame] | 52 | return err; |
| 53 | |
| 54 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 55 | sdata->u.mntr_flags = *flags; |
| 56 | return 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex) |
| 60 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 61 | struct net_device *dev; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 62 | struct ieee80211_sub_if_data *sdata; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 63 | |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 64 | /* we're under RTNL */ |
| 65 | dev = __dev_get_by_index(&init_net, ifindex); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 66 | if (!dev) |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 67 | return -ENODEV; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 68 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 69 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 70 | |
| 71 | ieee80211_if_remove(sdata); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 72 | |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 73 | return 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 76 | static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 77 | enum nl80211_iftype type, u32 *flags, |
| 78 | struct vif_params *params) |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 79 | { |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 80 | struct net_device *dev; |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 81 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | f3947e2 | 2008-07-09 14:40:36 +0200 | [diff] [blame] | 82 | int ret; |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 83 | |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 84 | /* we're under RTNL */ |
| 85 | dev = __dev_get_by_index(&init_net, ifindex); |
| 86 | if (!dev) |
| 87 | return -ENODEV; |
| 88 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 89 | if (!nl80211_type_check(type)) |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 90 | return -EINVAL; |
| 91 | |
| 92 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 93 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 94 | ret = ieee80211_if_change_type(sdata, type); |
Johannes Berg | f3947e2 | 2008-07-09 14:40:36 +0200 | [diff] [blame] | 95 | if (ret) |
| 96 | return ret; |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 97 | |
Johannes Berg | f8b25cd | 2008-09-16 20:22:21 +0200 | [diff] [blame] | 98 | if (netif_running(sdata->dev)) |
| 99 | return -EBUSY; |
| 100 | |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 101 | if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len) |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 102 | ieee80211_sdata_set_mesh_id(sdata, |
| 103 | params->mesh_id_len, |
| 104 | params->mesh_id); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 105 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 106 | if (sdata->vif.type != NL80211_IFTYPE_MONITOR || !flags) |
Michael Wu | 8cc9a73 | 2008-01-31 19:48:23 +0100 | [diff] [blame] | 107 | return 0; |
| 108 | |
| 109 | sdata->u.mntr_flags = *flags; |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 110 | return 0; |
| 111 | } |
| 112 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 113 | static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev, |
| 114 | u8 key_idx, u8 *mac_addr, |
| 115 | struct key_params *params) |
| 116 | { |
| 117 | struct ieee80211_sub_if_data *sdata; |
| 118 | struct sta_info *sta = NULL; |
| 119 | enum ieee80211_key_alg alg; |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 120 | struct ieee80211_key *key; |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 121 | int err; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 122 | |
| 123 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 124 | |
| 125 | switch (params->cipher) { |
| 126 | case WLAN_CIPHER_SUITE_WEP40: |
| 127 | case WLAN_CIPHER_SUITE_WEP104: |
| 128 | alg = ALG_WEP; |
| 129 | break; |
| 130 | case WLAN_CIPHER_SUITE_TKIP: |
| 131 | alg = ALG_TKIP; |
| 132 | break; |
| 133 | case WLAN_CIPHER_SUITE_CCMP: |
| 134 | alg = ALG_CCMP; |
| 135 | break; |
| 136 | default: |
| 137 | return -EINVAL; |
| 138 | } |
| 139 | |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 140 | key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key); |
| 141 | if (!key) |
| 142 | return -ENOMEM; |
| 143 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 144 | rcu_read_lock(); |
| 145 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 146 | if (mac_addr) { |
| 147 | sta = sta_info_get(sdata->local, mac_addr); |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 148 | if (!sta) { |
| 149 | ieee80211_key_free(key); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 150 | err = -ENOENT; |
| 151 | goto out_unlock; |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 152 | } |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 153 | } |
| 154 | |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 155 | ieee80211_key_link(key, sdata, sta); |
| 156 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 157 | err = 0; |
| 158 | out_unlock: |
| 159 | rcu_read_unlock(); |
| 160 | |
| 161 | return err; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev, |
| 165 | u8 key_idx, u8 *mac_addr) |
| 166 | { |
| 167 | struct ieee80211_sub_if_data *sdata; |
| 168 | struct sta_info *sta; |
| 169 | int ret; |
| 170 | |
| 171 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 172 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 173 | rcu_read_lock(); |
| 174 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 175 | if (mac_addr) { |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 176 | ret = -ENOENT; |
| 177 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 178 | sta = sta_info_get(sdata->local, mac_addr); |
| 179 | if (!sta) |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 180 | goto out_unlock; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 181 | |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 182 | if (sta->key) { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 183 | ieee80211_key_free(sta->key); |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 184 | WARN_ON(sta->key); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 185 | ret = 0; |
| 186 | } |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 187 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 188 | goto out_unlock; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 189 | } |
| 190 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 191 | if (!sdata->keys[key_idx]) { |
| 192 | ret = -ENOENT; |
| 193 | goto out_unlock; |
| 194 | } |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 195 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 196 | ieee80211_key_free(sdata->keys[key_idx]); |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 197 | WARN_ON(sdata->keys[key_idx]); |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 198 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 199 | ret = 0; |
| 200 | out_unlock: |
| 201 | rcu_read_unlock(); |
| 202 | |
| 203 | return ret; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 204 | } |
| 205 | |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 206 | static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev, |
| 207 | u8 key_idx, u8 *mac_addr, void *cookie, |
| 208 | void (*callback)(void *cookie, |
| 209 | struct key_params *params)) |
| 210 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 211 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 212 | struct sta_info *sta = NULL; |
| 213 | u8 seq[6] = {0}; |
| 214 | struct key_params params; |
| 215 | struct ieee80211_key *key; |
| 216 | u32 iv32; |
| 217 | u16 iv16; |
| 218 | int err = -ENOENT; |
| 219 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 220 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 221 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 222 | rcu_read_lock(); |
| 223 | |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 224 | if (mac_addr) { |
| 225 | sta = sta_info_get(sdata->local, mac_addr); |
| 226 | if (!sta) |
| 227 | goto out; |
| 228 | |
| 229 | key = sta->key; |
| 230 | } else |
| 231 | key = sdata->keys[key_idx]; |
| 232 | |
| 233 | if (!key) |
| 234 | goto out; |
| 235 | |
| 236 | memset(¶ms, 0, sizeof(params)); |
| 237 | |
| 238 | switch (key->conf.alg) { |
| 239 | case ALG_TKIP: |
| 240 | params.cipher = WLAN_CIPHER_SUITE_TKIP; |
| 241 | |
Harvey Harrison | b0f76b3 | 2008-05-14 16:26:19 -0700 | [diff] [blame] | 242 | iv32 = key->u.tkip.tx.iv32; |
| 243 | iv16 = key->u.tkip.tx.iv16; |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 244 | |
| 245 | if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE && |
| 246 | sdata->local->ops->get_tkip_seq) |
| 247 | sdata->local->ops->get_tkip_seq( |
| 248 | local_to_hw(sdata->local), |
| 249 | key->conf.hw_key_idx, |
| 250 | &iv32, &iv16); |
| 251 | |
| 252 | seq[0] = iv16 & 0xff; |
| 253 | seq[1] = (iv16 >> 8) & 0xff; |
| 254 | seq[2] = iv32 & 0xff; |
| 255 | seq[3] = (iv32 >> 8) & 0xff; |
| 256 | seq[4] = (iv32 >> 16) & 0xff; |
| 257 | seq[5] = (iv32 >> 24) & 0xff; |
| 258 | params.seq = seq; |
| 259 | params.seq_len = 6; |
| 260 | break; |
| 261 | case ALG_CCMP: |
| 262 | params.cipher = WLAN_CIPHER_SUITE_CCMP; |
| 263 | seq[0] = key->u.ccmp.tx_pn[5]; |
| 264 | seq[1] = key->u.ccmp.tx_pn[4]; |
| 265 | seq[2] = key->u.ccmp.tx_pn[3]; |
| 266 | seq[3] = key->u.ccmp.tx_pn[2]; |
| 267 | seq[4] = key->u.ccmp.tx_pn[1]; |
| 268 | seq[5] = key->u.ccmp.tx_pn[0]; |
| 269 | params.seq = seq; |
| 270 | params.seq_len = 6; |
| 271 | break; |
| 272 | case ALG_WEP: |
| 273 | if (key->conf.keylen == 5) |
| 274 | params.cipher = WLAN_CIPHER_SUITE_WEP40; |
| 275 | else |
| 276 | params.cipher = WLAN_CIPHER_SUITE_WEP104; |
| 277 | break; |
| 278 | } |
| 279 | |
| 280 | params.key = key->conf.key; |
| 281 | params.key_len = key->conf.keylen; |
| 282 | |
| 283 | callback(cookie, ¶ms); |
| 284 | err = 0; |
| 285 | |
| 286 | out: |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 287 | rcu_read_unlock(); |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 288 | return err; |
| 289 | } |
| 290 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 291 | static int ieee80211_config_default_key(struct wiphy *wiphy, |
| 292 | struct net_device *dev, |
| 293 | u8 key_idx) |
| 294 | { |
| 295 | struct ieee80211_sub_if_data *sdata; |
| 296 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 297 | rcu_read_lock(); |
| 298 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 299 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 300 | ieee80211_set_default_key(sdata, key_idx); |
| 301 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 302 | rcu_read_unlock(); |
| 303 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 304 | return 0; |
| 305 | } |
| 306 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 307 | static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo) |
| 308 | { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 309 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 310 | |
| 311 | sinfo->filled = STATION_INFO_INACTIVE_TIME | |
| 312 | STATION_INFO_RX_BYTES | |
| 313 | STATION_INFO_TX_BYTES; |
| 314 | |
| 315 | sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx); |
| 316 | sinfo->rx_bytes = sta->rx_bytes; |
| 317 | sinfo->tx_bytes = sta->tx_bytes; |
| 318 | |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 319 | if (ieee80211_vif_is_mesh(&sdata->vif)) { |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 320 | #ifdef CONFIG_MAC80211_MESH |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 321 | sinfo->filled |= STATION_INFO_LLID | |
| 322 | STATION_INFO_PLID | |
| 323 | STATION_INFO_PLINK_STATE; |
| 324 | |
| 325 | sinfo->llid = le16_to_cpu(sta->llid); |
| 326 | sinfo->plid = le16_to_cpu(sta->plid); |
| 327 | sinfo->plink_state = sta->plink_state; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 328 | #endif |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 329 | } |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | |
| 333 | static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev, |
| 334 | int idx, u8 *mac, struct station_info *sinfo) |
| 335 | { |
| 336 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 337 | struct sta_info *sta; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 338 | int ret = -ENOENT; |
| 339 | |
| 340 | rcu_read_lock(); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 341 | |
| 342 | sta = sta_info_get_by_idx(local, idx, dev); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 343 | if (sta) { |
| 344 | ret = 0; |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 345 | memcpy(mac, sta->sta.addr, ETH_ALEN); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 346 | sta_set_sinfo(sta, sinfo); |
| 347 | } |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 348 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 349 | rcu_read_unlock(); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 350 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 351 | return ret; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 352 | } |
| 353 | |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 354 | 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] | 355 | u8 *mac, struct station_info *sinfo) |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 356 | { |
| 357 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 358 | struct sta_info *sta; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 359 | int ret = -ENOENT; |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 360 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 361 | rcu_read_lock(); |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 362 | |
| 363 | /* XXX: verify sta->dev == dev */ |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 364 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 365 | sta = sta_info_get(local, mac); |
| 366 | if (sta) { |
| 367 | ret = 0; |
| 368 | sta_set_sinfo(sta, sinfo); |
| 369 | } |
| 370 | |
| 371 | rcu_read_unlock(); |
| 372 | |
| 373 | return ret; |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 374 | } |
| 375 | |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 376 | /* |
| 377 | * This handles both adding a beacon and setting new beacon info |
| 378 | */ |
| 379 | static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata, |
| 380 | struct beacon_parameters *params) |
| 381 | { |
| 382 | struct beacon_data *new, *old; |
| 383 | int new_head_len, new_tail_len; |
| 384 | int size; |
| 385 | int err = -EINVAL; |
| 386 | |
| 387 | old = sdata->u.ap.beacon; |
| 388 | |
| 389 | /* head must not be zero-length */ |
| 390 | if (params->head && !params->head_len) |
| 391 | return -EINVAL; |
| 392 | |
| 393 | /* |
| 394 | * This is a kludge. beacon interval should really be part |
| 395 | * of the beacon information. |
| 396 | */ |
| 397 | if (params->interval) { |
| 398 | sdata->local->hw.conf.beacon_int = params->interval; |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 399 | ieee80211_hw_config(sdata->local, |
| 400 | IEEE80211_CONF_CHANGE_BEACON_INTERVAL); |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 401 | /* |
| 402 | * We updated some parameter so if below bails out |
| 403 | * it's not an error. |
| 404 | */ |
| 405 | err = 0; |
| 406 | } |
| 407 | |
| 408 | /* Need to have a beacon head if we don't have one yet */ |
| 409 | if (!params->head && !old) |
| 410 | return err; |
| 411 | |
| 412 | /* sorry, no way to start beaconing without dtim period */ |
| 413 | if (!params->dtim_period && !old) |
| 414 | return err; |
| 415 | |
| 416 | /* new or old head? */ |
| 417 | if (params->head) |
| 418 | new_head_len = params->head_len; |
| 419 | else |
| 420 | new_head_len = old->head_len; |
| 421 | |
| 422 | /* new or old tail? */ |
| 423 | if (params->tail || !old) |
| 424 | /* params->tail_len will be zero for !params->tail */ |
| 425 | new_tail_len = params->tail_len; |
| 426 | else |
| 427 | new_tail_len = old->tail_len; |
| 428 | |
| 429 | size = sizeof(*new) + new_head_len + new_tail_len; |
| 430 | |
| 431 | new = kzalloc(size, GFP_KERNEL); |
| 432 | if (!new) |
| 433 | return -ENOMEM; |
| 434 | |
| 435 | /* start filling the new info now */ |
| 436 | |
| 437 | /* new or old dtim period? */ |
| 438 | if (params->dtim_period) |
| 439 | new->dtim_period = params->dtim_period; |
| 440 | else |
| 441 | new->dtim_period = old->dtim_period; |
| 442 | |
| 443 | /* |
| 444 | * pointers go into the block we allocated, |
| 445 | * memory is | beacon_data | head | tail | |
| 446 | */ |
| 447 | new->head = ((u8 *) new) + sizeof(*new); |
| 448 | new->tail = new->head + new_head_len; |
| 449 | new->head_len = new_head_len; |
| 450 | new->tail_len = new_tail_len; |
| 451 | |
| 452 | /* copy in head */ |
| 453 | if (params->head) |
| 454 | memcpy(new->head, params->head, new_head_len); |
| 455 | else |
| 456 | memcpy(new->head, old->head, new_head_len); |
| 457 | |
| 458 | /* copy in optional tail */ |
| 459 | if (params->tail) |
| 460 | memcpy(new->tail, params->tail, new_tail_len); |
| 461 | else |
| 462 | if (old) |
| 463 | memcpy(new->tail, old->tail, new_tail_len); |
| 464 | |
| 465 | rcu_assign_pointer(sdata->u.ap.beacon, new); |
| 466 | |
| 467 | synchronize_rcu(); |
| 468 | |
| 469 | kfree(old); |
| 470 | |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 471 | return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON); |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev, |
| 475 | struct beacon_parameters *params) |
| 476 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 477 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 478 | struct beacon_data *old; |
| 479 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 480 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 481 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 482 | if (sdata->vif.type != NL80211_IFTYPE_AP) |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 483 | return -EINVAL; |
| 484 | |
| 485 | old = sdata->u.ap.beacon; |
| 486 | |
| 487 | if (old) |
| 488 | return -EALREADY; |
| 489 | |
| 490 | return ieee80211_config_beacon(sdata, params); |
| 491 | } |
| 492 | |
| 493 | static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev, |
| 494 | struct beacon_parameters *params) |
| 495 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 496 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 497 | struct beacon_data *old; |
| 498 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 499 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 500 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 501 | if (sdata->vif.type != NL80211_IFTYPE_AP) |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 502 | return -EINVAL; |
| 503 | |
| 504 | old = sdata->u.ap.beacon; |
| 505 | |
| 506 | if (!old) |
| 507 | return -ENOENT; |
| 508 | |
| 509 | return ieee80211_config_beacon(sdata, params); |
| 510 | } |
| 511 | |
| 512 | static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev) |
| 513 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 514 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 515 | struct beacon_data *old; |
| 516 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 517 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 518 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 519 | if (sdata->vif.type != NL80211_IFTYPE_AP) |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 520 | return -EINVAL; |
| 521 | |
| 522 | old = sdata->u.ap.beacon; |
| 523 | |
| 524 | if (!old) |
| 525 | return -ENOENT; |
| 526 | |
| 527 | rcu_assign_pointer(sdata->u.ap.beacon, NULL); |
| 528 | synchronize_rcu(); |
| 529 | kfree(old); |
| 530 | |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 531 | return ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON); |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 532 | } |
| 533 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 534 | /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */ |
| 535 | struct iapp_layer2_update { |
| 536 | u8 da[ETH_ALEN]; /* broadcast */ |
| 537 | u8 sa[ETH_ALEN]; /* STA addr */ |
| 538 | __be16 len; /* 6 */ |
| 539 | u8 dsap; /* 0 */ |
| 540 | u8 ssap; /* 0 */ |
| 541 | u8 control; |
| 542 | u8 xid_info[3]; |
| 543 | } __attribute__ ((packed)); |
| 544 | |
| 545 | static void ieee80211_send_layer2_update(struct sta_info *sta) |
| 546 | { |
| 547 | struct iapp_layer2_update *msg; |
| 548 | struct sk_buff *skb; |
| 549 | |
| 550 | /* Send Level 2 Update Frame to update forwarding tables in layer 2 |
| 551 | * bridge devices */ |
| 552 | |
| 553 | skb = dev_alloc_skb(sizeof(*msg)); |
| 554 | if (!skb) |
| 555 | return; |
| 556 | msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg)); |
| 557 | |
| 558 | /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID) |
| 559 | * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */ |
| 560 | |
| 561 | memset(msg->da, 0xff, ETH_ALEN); |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 562 | memcpy(msg->sa, sta->sta.addr, ETH_ALEN); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 563 | msg->len = htons(6); |
| 564 | msg->dsap = 0; |
| 565 | msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */ |
| 566 | msg->control = 0xaf; /* XID response lsb.1111F101. |
| 567 | * F=0 (no poll command; unsolicited frame) */ |
| 568 | msg->xid_info[0] = 0x81; /* XID format identifier */ |
| 569 | msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */ |
| 570 | msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */ |
| 571 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 572 | skb->dev = sta->sdata->dev; |
| 573 | skb->protocol = eth_type_trans(skb, sta->sdata->dev); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 574 | memset(skb->cb, 0, sizeof(skb->cb)); |
| 575 | netif_rx(skb); |
| 576 | } |
| 577 | |
| 578 | static void sta_apply_parameters(struct ieee80211_local *local, |
| 579 | struct sta_info *sta, |
| 580 | struct station_parameters *params) |
| 581 | { |
| 582 | u32 rates; |
| 583 | int i, j; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 584 | struct ieee80211_supported_band *sband; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 585 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 586 | |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 587 | sband = local->hw.wiphy->bands[local->oper_channel->band]; |
| 588 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 589 | /* |
| 590 | * FIXME: updating the flags is racy when this function is |
| 591 | * called from ieee80211_change_station(), this will |
| 592 | * be resolved in a future patch. |
| 593 | */ |
| 594 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 595 | if (params->station_flags & STATION_FLAG_CHANGED) { |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 596 | spin_lock_bh(&sta->lock); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 597 | sta->flags &= ~WLAN_STA_AUTHORIZED; |
| 598 | if (params->station_flags & STATION_FLAG_AUTHORIZED) |
| 599 | sta->flags |= WLAN_STA_AUTHORIZED; |
| 600 | |
| 601 | sta->flags &= ~WLAN_STA_SHORT_PREAMBLE; |
| 602 | if (params->station_flags & STATION_FLAG_SHORT_PREAMBLE) |
| 603 | sta->flags |= WLAN_STA_SHORT_PREAMBLE; |
| 604 | |
| 605 | sta->flags &= ~WLAN_STA_WME; |
| 606 | if (params->station_flags & STATION_FLAG_WME) |
| 607 | sta->flags |= WLAN_STA_WME; |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 608 | spin_unlock_bh(&sta->lock); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 609 | } |
| 610 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 611 | /* |
| 612 | * FIXME: updating the following information is racy when this |
| 613 | * function is called from ieee80211_change_station(). |
| 614 | * However, all this information should be static so |
| 615 | * maybe we should just reject attemps to change it. |
| 616 | */ |
| 617 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 618 | if (params->aid) { |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 619 | sta->sta.aid = params->aid; |
| 620 | if (sta->sta.aid > IEEE80211_MAX_AID) |
| 621 | sta->sta.aid = 0; /* XXX: should this be an error? */ |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | if (params->listen_interval >= 0) |
| 625 | sta->listen_interval = params->listen_interval; |
| 626 | |
| 627 | if (params->supported_rates) { |
| 628 | rates = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 629 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 630 | for (i = 0; i < params->supported_rates_len; i++) { |
| 631 | int rate = (params->supported_rates[i] & 0x7f) * 5; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 632 | for (j = 0; j < sband->n_bitrates; j++) { |
| 633 | if (sband->bitrates[j].bitrate == rate) |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 634 | rates |= BIT(j); |
| 635 | } |
| 636 | } |
Johannes Berg | 323ce79 | 2008-09-11 02:45:11 +0200 | [diff] [blame] | 637 | sta->sta.supp_rates[local->oper_channel->band] = rates; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 638 | } |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 639 | |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 640 | if (params->ht_capa) |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 641 | ieee80211_ht_cap_ie_to_sta_ht_cap(sband, |
| 642 | params->ht_capa, |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 643 | &sta->sta.ht_cap); |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 644 | |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 645 | if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) { |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 646 | switch (params->plink_action) { |
| 647 | case PLINK_ACTION_OPEN: |
| 648 | mesh_plink_open(sta); |
| 649 | break; |
| 650 | case PLINK_ACTION_BLOCK: |
| 651 | mesh_plink_block(sta); |
| 652 | break; |
| 653 | } |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 654 | } |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev, |
| 658 | u8 *mac, struct station_parameters *params) |
| 659 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 660 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 661 | struct sta_info *sta; |
| 662 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 663 | int err; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 664 | |
| 665 | /* Prevent a race with changing the rate control algorithm */ |
| 666 | if (!netif_running(dev)) |
| 667 | return -ENETDOWN; |
| 668 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 669 | if (params->vlan) { |
| 670 | sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); |
| 671 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 672 | if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN && |
| 673 | sdata->vif.type != NL80211_IFTYPE_AP) |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 674 | return -EINVAL; |
| 675 | } else |
| 676 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 677 | |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 678 | if (compare_ether_addr(mac, dev->dev_addr) == 0) |
| 679 | return -EINVAL; |
| 680 | |
| 681 | if (is_multicast_ether_addr(mac)) |
| 682 | return -EINVAL; |
| 683 | |
| 684 | sta = sta_info_alloc(sdata, mac, GFP_KERNEL); |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 685 | if (!sta) |
| 686 | return -ENOMEM; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 687 | |
| 688 | sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC; |
| 689 | |
| 690 | sta_apply_parameters(local, sta, params); |
| 691 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 692 | rate_control_rate_init(sta); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 693 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 694 | rcu_read_lock(); |
| 695 | |
| 696 | err = sta_info_insert(sta); |
| 697 | if (err) { |
Johannes Berg | 93e5deb | 2008-04-01 15:21:00 +0200 | [diff] [blame] | 698 | /* STA has been freed */ |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 699 | rcu_read_unlock(); |
| 700 | return err; |
| 701 | } |
| 702 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 703 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN || |
| 704 | sdata->vif.type == NL80211_IFTYPE_AP) |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 705 | ieee80211_send_layer2_update(sta); |
| 706 | |
| 707 | rcu_read_unlock(); |
| 708 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 709 | return 0; |
| 710 | } |
| 711 | |
| 712 | static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev, |
| 713 | u8 *mac) |
| 714 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 715 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 716 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 717 | struct sta_info *sta; |
| 718 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 719 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 720 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 721 | if (mac) { |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 722 | rcu_read_lock(); |
| 723 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 724 | /* XXX: get sta belonging to dev */ |
| 725 | sta = sta_info_get(local, mac); |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 726 | if (!sta) { |
| 727 | rcu_read_unlock(); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 728 | return -ENOENT; |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 729 | } |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 730 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 731 | sta_info_unlink(&sta); |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 732 | rcu_read_unlock(); |
| 733 | |
Johannes Berg | 4f6fab4 | 2008-03-31 19:23:02 +0200 | [diff] [blame] | 734 | sta_info_destroy(sta); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 735 | } else |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 736 | sta_info_flush(local, sdata); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 737 | |
| 738 | return 0; |
| 739 | } |
| 740 | |
| 741 | static int ieee80211_change_station(struct wiphy *wiphy, |
| 742 | struct net_device *dev, |
| 743 | u8 *mac, |
| 744 | struct station_parameters *params) |
| 745 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 746 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 747 | struct sta_info *sta; |
| 748 | struct ieee80211_sub_if_data *vlansdata; |
| 749 | |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 750 | rcu_read_lock(); |
| 751 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 752 | /* XXX: get sta belonging to dev */ |
| 753 | sta = sta_info_get(local, mac); |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 754 | if (!sta) { |
| 755 | rcu_read_unlock(); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 756 | return -ENOENT; |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 757 | } |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 758 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 759 | if (params->vlan && params->vlan != sta->sdata->dev) { |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 760 | vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); |
| 761 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 762 | if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN && |
| 763 | vlansdata->vif.type != NL80211_IFTYPE_AP) { |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 764 | rcu_read_unlock(); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 765 | return -EINVAL; |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 766 | } |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 767 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 768 | sta->sdata = vlansdata; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 769 | ieee80211_send_layer2_update(sta); |
| 770 | } |
| 771 | |
| 772 | sta_apply_parameters(local, sta, params); |
| 773 | |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 774 | rcu_read_unlock(); |
| 775 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 776 | return 0; |
| 777 | } |
| 778 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 779 | #ifdef CONFIG_MAC80211_MESH |
| 780 | static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev, |
| 781 | u8 *dst, u8 *next_hop) |
| 782 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 783 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 784 | struct ieee80211_sub_if_data *sdata; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 785 | struct mesh_path *mpath; |
| 786 | struct sta_info *sta; |
| 787 | int err; |
| 788 | |
| 789 | if (!netif_running(dev)) |
| 790 | return -ENETDOWN; |
| 791 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 792 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 793 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 794 | if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT) |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 795 | return -ENOTSUPP; |
| 796 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 797 | rcu_read_lock(); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 798 | sta = sta_info_get(local, next_hop); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 799 | if (!sta) { |
| 800 | rcu_read_unlock(); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 801 | return -ENOENT; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 802 | } |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 803 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 804 | err = mesh_path_add(dst, sdata); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 805 | if (err) { |
| 806 | rcu_read_unlock(); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 807 | return err; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 808 | } |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 809 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 810 | mpath = mesh_path_lookup(dst, sdata); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 811 | if (!mpath) { |
| 812 | rcu_read_unlock(); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 813 | return -ENXIO; |
| 814 | } |
| 815 | mesh_path_fix_nexthop(mpath, sta); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 816 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 817 | rcu_read_unlock(); |
| 818 | return 0; |
| 819 | } |
| 820 | |
| 821 | static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev, |
| 822 | u8 *dst) |
| 823 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 824 | 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] | 825 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 826 | if (dst) |
| 827 | return mesh_path_del(dst, sdata); |
| 828 | |
| 829 | mesh_path_flush(sdata); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 830 | return 0; |
| 831 | } |
| 832 | |
| 833 | static int ieee80211_change_mpath(struct wiphy *wiphy, |
| 834 | struct net_device *dev, |
| 835 | u8 *dst, u8 *next_hop) |
| 836 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 837 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 838 | struct ieee80211_sub_if_data *sdata; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 839 | struct mesh_path *mpath; |
| 840 | struct sta_info *sta; |
| 841 | |
| 842 | if (!netif_running(dev)) |
| 843 | return -ENETDOWN; |
| 844 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 845 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 846 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 847 | if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT) |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 848 | return -ENOTSUPP; |
| 849 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 850 | rcu_read_lock(); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 851 | |
| 852 | sta = sta_info_get(local, next_hop); |
| 853 | if (!sta) { |
| 854 | rcu_read_unlock(); |
| 855 | return -ENOENT; |
| 856 | } |
| 857 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 858 | mpath = mesh_path_lookup(dst, sdata); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 859 | if (!mpath) { |
| 860 | rcu_read_unlock(); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 861 | return -ENOENT; |
| 862 | } |
| 863 | |
| 864 | mesh_path_fix_nexthop(mpath, sta); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 865 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 866 | rcu_read_unlock(); |
| 867 | return 0; |
| 868 | } |
| 869 | |
| 870 | static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop, |
| 871 | struct mpath_info *pinfo) |
| 872 | { |
| 873 | if (mpath->next_hop) |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 874 | memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 875 | else |
| 876 | memset(next_hop, 0, ETH_ALEN); |
| 877 | |
| 878 | pinfo->filled = MPATH_INFO_FRAME_QLEN | |
| 879 | MPATH_INFO_DSN | |
| 880 | MPATH_INFO_METRIC | |
| 881 | MPATH_INFO_EXPTIME | |
| 882 | MPATH_INFO_DISCOVERY_TIMEOUT | |
| 883 | MPATH_INFO_DISCOVERY_RETRIES | |
| 884 | MPATH_INFO_FLAGS; |
| 885 | |
| 886 | pinfo->frame_qlen = mpath->frame_queue.qlen; |
| 887 | pinfo->dsn = mpath->dsn; |
| 888 | pinfo->metric = mpath->metric; |
| 889 | if (time_before(jiffies, mpath->exp_time)) |
| 890 | pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies); |
| 891 | pinfo->discovery_timeout = |
| 892 | jiffies_to_msecs(mpath->discovery_timeout); |
| 893 | pinfo->discovery_retries = mpath->discovery_retries; |
| 894 | pinfo->flags = 0; |
| 895 | if (mpath->flags & MESH_PATH_ACTIVE) |
| 896 | pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE; |
| 897 | if (mpath->flags & MESH_PATH_RESOLVING) |
| 898 | pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING; |
| 899 | if (mpath->flags & MESH_PATH_DSN_VALID) |
| 900 | pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID; |
| 901 | if (mpath->flags & MESH_PATH_FIXED) |
| 902 | pinfo->flags |= NL80211_MPATH_FLAG_FIXED; |
| 903 | if (mpath->flags & MESH_PATH_RESOLVING) |
| 904 | pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING; |
| 905 | |
| 906 | pinfo->flags = mpath->flags; |
| 907 | } |
| 908 | |
| 909 | static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev, |
| 910 | u8 *dst, u8 *next_hop, struct mpath_info *pinfo) |
| 911 | |
| 912 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 913 | struct ieee80211_sub_if_data *sdata; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 914 | struct mesh_path *mpath; |
| 915 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 916 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 917 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 918 | if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT) |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 919 | return -ENOTSUPP; |
| 920 | |
| 921 | rcu_read_lock(); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 922 | mpath = mesh_path_lookup(dst, sdata); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 923 | if (!mpath) { |
| 924 | rcu_read_unlock(); |
| 925 | return -ENOENT; |
| 926 | } |
| 927 | memcpy(dst, mpath->dst, ETH_ALEN); |
| 928 | mpath_set_pinfo(mpath, next_hop, pinfo); |
| 929 | rcu_read_unlock(); |
| 930 | return 0; |
| 931 | } |
| 932 | |
| 933 | static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev, |
| 934 | int idx, u8 *dst, u8 *next_hop, |
| 935 | struct mpath_info *pinfo) |
| 936 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 937 | struct ieee80211_sub_if_data *sdata; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 938 | struct mesh_path *mpath; |
| 939 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 940 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 941 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 942 | if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT) |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 943 | return -ENOTSUPP; |
| 944 | |
| 945 | rcu_read_lock(); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 946 | mpath = mesh_path_lookup_by_idx(idx, sdata); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 947 | if (!mpath) { |
| 948 | rcu_read_unlock(); |
| 949 | return -ENOENT; |
| 950 | } |
| 951 | memcpy(dst, mpath->dst, ETH_ALEN); |
| 952 | mpath_set_pinfo(mpath, next_hop, pinfo); |
| 953 | rcu_read_unlock(); |
| 954 | return 0; |
| 955 | } |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 956 | |
| 957 | static int ieee80211_get_mesh_params(struct wiphy *wiphy, |
| 958 | struct net_device *dev, |
| 959 | struct mesh_config *conf) |
| 960 | { |
| 961 | struct ieee80211_sub_if_data *sdata; |
| 962 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 963 | |
| 964 | if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT) |
| 965 | return -ENOTSUPP; |
| 966 | memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config)); |
| 967 | return 0; |
| 968 | } |
| 969 | |
| 970 | static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask) |
| 971 | { |
| 972 | return (mask >> (parm-1)) & 0x1; |
| 973 | } |
| 974 | |
| 975 | static int ieee80211_set_mesh_params(struct wiphy *wiphy, |
| 976 | struct net_device *dev, |
| 977 | const struct mesh_config *nconf, u32 mask) |
| 978 | { |
| 979 | struct mesh_config *conf; |
| 980 | struct ieee80211_sub_if_data *sdata; |
| 981 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 982 | |
| 983 | if (sdata->vif.type != NL80211_IFTYPE_MESH_POINT) |
| 984 | return -ENOTSUPP; |
| 985 | |
| 986 | /* Set the config options which we are interested in setting */ |
| 987 | conf = &(sdata->u.mesh.mshcfg); |
| 988 | if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask)) |
| 989 | conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout; |
| 990 | if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask)) |
| 991 | conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout; |
| 992 | if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask)) |
| 993 | conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout; |
| 994 | if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask)) |
| 995 | conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks; |
| 996 | if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask)) |
| 997 | conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries; |
| 998 | if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask)) |
| 999 | conf->dot11MeshTTL = nconf->dot11MeshTTL; |
| 1000 | if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) |
| 1001 | conf->auto_open_plinks = nconf->auto_open_plinks; |
| 1002 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask)) |
| 1003 | conf->dot11MeshHWMPmaxPREQretries = |
| 1004 | nconf->dot11MeshHWMPmaxPREQretries; |
| 1005 | if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask)) |
| 1006 | conf->path_refresh_time = nconf->path_refresh_time; |
| 1007 | if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask)) |
| 1008 | conf->min_discovery_timeout = nconf->min_discovery_timeout; |
| 1009 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask)) |
| 1010 | conf->dot11MeshHWMPactivePathTimeout = |
| 1011 | nconf->dot11MeshHWMPactivePathTimeout; |
| 1012 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask)) |
| 1013 | conf->dot11MeshHWMPpreqMinInterval = |
| 1014 | nconf->dot11MeshHWMPpreqMinInterval; |
| 1015 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 1016 | mask)) |
| 1017 | conf->dot11MeshHWMPnetDiameterTraversalTime = |
| 1018 | nconf->dot11MeshHWMPnetDiameterTraversalTime; |
| 1019 | return 0; |
| 1020 | } |
| 1021 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1022 | #endif |
| 1023 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1024 | static int ieee80211_change_bss(struct wiphy *wiphy, |
| 1025 | struct net_device *dev, |
| 1026 | struct bss_parameters *params) |
| 1027 | { |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1028 | struct ieee80211_sub_if_data *sdata; |
| 1029 | u32 changed = 0; |
| 1030 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1031 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1032 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1033 | if (sdata->vif.type != NL80211_IFTYPE_AP) |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1034 | return -EINVAL; |
| 1035 | |
| 1036 | if (params->use_cts_prot >= 0) { |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 1037 | sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1038 | changed |= BSS_CHANGED_ERP_CTS_PROT; |
| 1039 | } |
| 1040 | if (params->use_short_preamble >= 0) { |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 1041 | sdata->vif.bss_conf.use_short_preamble = |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1042 | params->use_short_preamble; |
| 1043 | changed |= BSS_CHANGED_ERP_PREAMBLE; |
| 1044 | } |
| 1045 | if (params->use_short_slot_time >= 0) { |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 1046 | sdata->vif.bss_conf.use_short_slot = |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1047 | params->use_short_slot_time; |
| 1048 | changed |= BSS_CHANGED_ERP_SLOT; |
| 1049 | } |
| 1050 | |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 1051 | if (params->basic_rates) { |
| 1052 | int i, j; |
| 1053 | u32 rates = 0; |
| 1054 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 1055 | struct ieee80211_supported_band *sband = |
| 1056 | wiphy->bands[local->oper_channel->band]; |
| 1057 | |
| 1058 | for (i = 0; i < params->basic_rates_len; i++) { |
| 1059 | int rate = (params->basic_rates[i] & 0x7f) * 5; |
| 1060 | for (j = 0; j < sband->n_bitrates; j++) { |
| 1061 | if (sband->bitrates[j].bitrate == rate) |
| 1062 | rates |= BIT(j); |
| 1063 | } |
| 1064 | } |
| 1065 | sdata->vif.bss_conf.basic_rates = rates; |
| 1066 | changed |= BSS_CHANGED_BASIC_RATES; |
| 1067 | } |
| 1068 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1069 | ieee80211_bss_info_change_notify(sdata, changed); |
| 1070 | |
| 1071 | return 0; |
| 1072 | } |
| 1073 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1074 | static int ieee80211_set_txq_params(struct wiphy *wiphy, |
| 1075 | struct ieee80211_txq_params *params) |
| 1076 | { |
| 1077 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 1078 | struct ieee80211_tx_queue_params p; |
| 1079 | |
| 1080 | if (!local->ops->conf_tx) |
| 1081 | return -EOPNOTSUPP; |
| 1082 | |
| 1083 | memset(&p, 0, sizeof(p)); |
| 1084 | p.aifs = params->aifs; |
| 1085 | p.cw_max = params->cwmax; |
| 1086 | p.cw_min = params->cwmin; |
| 1087 | p.txop = params->txop; |
| 1088 | if (local->ops->conf_tx(local_to_hw(local), params->queue, &p)) { |
| 1089 | printk(KERN_DEBUG "%s: failed to set TX queue " |
| 1090 | "parameters for queue %d\n", local->mdev->name, |
| 1091 | params->queue); |
| 1092 | return -EINVAL; |
| 1093 | } |
| 1094 | |
| 1095 | return 0; |
| 1096 | } |
| 1097 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1098 | struct cfg80211_ops mac80211_config_ops = { |
| 1099 | .add_virtual_intf = ieee80211_add_iface, |
| 1100 | .del_virtual_intf = ieee80211_del_iface, |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 1101 | .change_virtual_intf = ieee80211_change_iface, |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 1102 | .add_key = ieee80211_add_key, |
| 1103 | .del_key = ieee80211_del_key, |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 1104 | .get_key = ieee80211_get_key, |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 1105 | .set_default_key = ieee80211_config_default_key, |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1106 | .add_beacon = ieee80211_add_beacon, |
| 1107 | .set_beacon = ieee80211_set_beacon, |
| 1108 | .del_beacon = ieee80211_del_beacon, |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1109 | .add_station = ieee80211_add_station, |
| 1110 | .del_station = ieee80211_del_station, |
| 1111 | .change_station = ieee80211_change_station, |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 1112 | .get_station = ieee80211_get_station, |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1113 | .dump_station = ieee80211_dump_station, |
| 1114 | #ifdef CONFIG_MAC80211_MESH |
| 1115 | .add_mpath = ieee80211_add_mpath, |
| 1116 | .del_mpath = ieee80211_del_mpath, |
| 1117 | .change_mpath = ieee80211_change_mpath, |
| 1118 | .get_mpath = ieee80211_get_mpath, |
| 1119 | .dump_mpath = ieee80211_dump_mpath, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 1120 | .set_mesh_params = ieee80211_set_mesh_params, |
| 1121 | .get_mesh_params = ieee80211_get_mesh_params, |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1122 | #endif |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1123 | .change_bss = ieee80211_change_bss, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 1124 | .set_txq_params = ieee80211_set_txq_params, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1125 | }; |