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