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