Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This is the new netlink-based wireless configuration interface. |
| 3 | * |
| 4 | * Copyright 2006, 2007 Johannes Berg <johannes@sipsolutions.net> |
| 5 | */ |
| 6 | |
| 7 | #include <linux/if.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/err.h> |
| 10 | #include <linux/mutex.h> |
| 11 | #include <linux/list.h> |
| 12 | #include <linux/if_ether.h> |
| 13 | #include <linux/ieee80211.h> |
| 14 | #include <linux/nl80211.h> |
| 15 | #include <linux/rtnetlink.h> |
| 16 | #include <linux/netlink.h> |
| 17 | #include <net/genetlink.h> |
| 18 | #include <net/cfg80211.h> |
| 19 | #include "core.h" |
| 20 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 21 | #include "reg.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 22 | |
| 23 | /* the netlink family */ |
| 24 | static struct genl_family nl80211_fam = { |
| 25 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 26 | .name = "nl80211", /* have users key off the name instead */ |
| 27 | .hdrsize = 0, /* no private header */ |
| 28 | .version = 1, /* no particular meaning now */ |
| 29 | .maxattr = NL80211_ATTR_MAX, |
| 30 | }; |
| 31 | |
| 32 | /* internal helper: get drv and dev */ |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 33 | static int get_drv_dev_by_info_ifindex(struct nlattr **attrs, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 34 | struct cfg80211_registered_device **drv, |
| 35 | struct net_device **dev) |
| 36 | { |
| 37 | int ifindex; |
| 38 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 39 | if (!attrs[NL80211_ATTR_IFINDEX]) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 40 | return -EINVAL; |
| 41 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 42 | ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 43 | *dev = dev_get_by_index(&init_net, ifindex); |
| 44 | if (!*dev) |
| 45 | return -ENODEV; |
| 46 | |
| 47 | *drv = cfg80211_get_dev_from_ifindex(ifindex); |
| 48 | if (IS_ERR(*drv)) { |
| 49 | dev_put(*dev); |
| 50 | return PTR_ERR(*drv); |
| 51 | } |
| 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | /* policy for the attributes */ |
| 57 | static struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] __read_mostly = { |
| 58 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 59 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
| 60 | .len = BUS_ID_SIZE-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 61 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 62 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
| 63 | [NL80211_ATTR_WIPHY_SEC_CHAN_OFFSET] = { .type = NLA_U32 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 64 | |
| 65 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 66 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 67 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 68 | |
| 69 | [NL80211_ATTR_MAC] = { .type = NLA_BINARY, .len = ETH_ALEN }, |
| 70 | |
| 71 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 72 | .len = WLAN_MAX_KEY_LEN }, |
| 73 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 74 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 75 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 76 | |
| 77 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 78 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 79 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 80 | .len = IEEE80211_MAX_DATA_LEN }, |
| 81 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 82 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 83 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 84 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 85 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 86 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 87 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 88 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 89 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 90 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 91 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
| 92 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
| 93 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 94 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 95 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 96 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 97 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 98 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 99 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 100 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 101 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 102 | .len = NL80211_MAX_SUPP_RATES }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 103 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 104 | [NL80211_ATTR_MESH_PARAMS] = { .type = NLA_NESTED }, |
| 105 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 106 | [NL80211_ATTR_HT_CAPABILITY] = { .type = NLA_BINARY, |
| 107 | .len = NL80211_HT_CAPABILITY_LEN }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | /* message building helper */ |
| 111 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, |
| 112 | int flags, u8 cmd) |
| 113 | { |
| 114 | /* since there is no private header just add the generic one */ |
| 115 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); |
| 116 | } |
| 117 | |
| 118 | /* netlink command implementations */ |
| 119 | |
| 120 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 121 | struct cfg80211_registered_device *dev) |
| 122 | { |
| 123 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 124 | struct nlattr *nl_bands, *nl_band; |
| 125 | struct nlattr *nl_freqs, *nl_freq; |
| 126 | struct nlattr *nl_rates, *nl_rate; |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 127 | struct nlattr *nl_modes; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 128 | enum ieee80211_band band; |
| 129 | struct ieee80211_channel *chan; |
| 130 | struct ieee80211_rate *rate; |
| 131 | int i; |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 132 | u16 ifmodes = dev->wiphy.interface_modes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 133 | |
| 134 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); |
| 135 | if (!hdr) |
| 136 | return -1; |
| 137 | |
| 138 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->idx); |
| 139 | NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 140 | |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 141 | nl_modes = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_IFTYPES); |
| 142 | if (!nl_modes) |
| 143 | goto nla_put_failure; |
| 144 | |
| 145 | i = 0; |
| 146 | while (ifmodes) { |
| 147 | if (ifmodes & 1) |
| 148 | NLA_PUT_FLAG(msg, i); |
| 149 | ifmodes >>= 1; |
| 150 | i++; |
| 151 | } |
| 152 | |
| 153 | nla_nest_end(msg, nl_modes); |
| 154 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 155 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 156 | if (!nl_bands) |
| 157 | goto nla_put_failure; |
| 158 | |
| 159 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 160 | if (!dev->wiphy.bands[band]) |
| 161 | continue; |
| 162 | |
| 163 | nl_band = nla_nest_start(msg, band); |
| 164 | if (!nl_band) |
| 165 | goto nla_put_failure; |
| 166 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 167 | /* add HT info */ |
| 168 | if (dev->wiphy.bands[band]->ht_cap.ht_supported) { |
| 169 | NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 170 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 171 | &dev->wiphy.bands[band]->ht_cap.mcs); |
| 172 | NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 173 | dev->wiphy.bands[band]->ht_cap.cap); |
| 174 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 175 | dev->wiphy.bands[band]->ht_cap.ampdu_factor); |
| 176 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 177 | dev->wiphy.bands[band]->ht_cap.ampdu_density); |
| 178 | } |
| 179 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 180 | /* add frequencies */ |
| 181 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 182 | if (!nl_freqs) |
| 183 | goto nla_put_failure; |
| 184 | |
| 185 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 186 | nl_freq = nla_nest_start(msg, i); |
| 187 | if (!nl_freq) |
| 188 | goto nla_put_failure; |
| 189 | |
| 190 | chan = &dev->wiphy.bands[band]->channels[i]; |
| 191 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 192 | chan->center_freq); |
| 193 | |
| 194 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 195 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED); |
| 196 | if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 197 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN); |
| 198 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) |
| 199 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS); |
| 200 | if (chan->flags & IEEE80211_CHAN_RADAR) |
| 201 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR); |
| 202 | |
Jouni Malinen | bf8c1ac | 2008-11-22 22:00:31 +0200 | [diff] [blame] | 203 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 204 | DBM_TO_MBM(chan->max_power)); |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 205 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 206 | nla_nest_end(msg, nl_freq); |
| 207 | } |
| 208 | |
| 209 | nla_nest_end(msg, nl_freqs); |
| 210 | |
| 211 | /* add bitrates */ |
| 212 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 213 | if (!nl_rates) |
| 214 | goto nla_put_failure; |
| 215 | |
| 216 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 217 | nl_rate = nla_nest_start(msg, i); |
| 218 | if (!nl_rate) |
| 219 | goto nla_put_failure; |
| 220 | |
| 221 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
| 222 | NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE, |
| 223 | rate->bitrate); |
| 224 | if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) |
| 225 | NLA_PUT_FLAG(msg, |
| 226 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE); |
| 227 | |
| 228 | nla_nest_end(msg, nl_rate); |
| 229 | } |
| 230 | |
| 231 | nla_nest_end(msg, nl_rates); |
| 232 | |
| 233 | nla_nest_end(msg, nl_band); |
| 234 | } |
| 235 | nla_nest_end(msg, nl_bands); |
| 236 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 237 | return genlmsg_end(msg, hdr); |
| 238 | |
| 239 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 240 | genlmsg_cancel(msg, hdr); |
| 241 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 245 | { |
| 246 | int idx = 0; |
| 247 | int start = cb->args[0]; |
| 248 | struct cfg80211_registered_device *dev; |
| 249 | |
| 250 | mutex_lock(&cfg80211_drv_mutex); |
| 251 | list_for_each_entry(dev, &cfg80211_drv_list, list) { |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 252 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 253 | continue; |
| 254 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, |
| 255 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 256 | dev) < 0) { |
| 257 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 258 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 259 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 260 | } |
| 261 | mutex_unlock(&cfg80211_drv_mutex); |
| 262 | |
| 263 | cb->args[0] = idx; |
| 264 | |
| 265 | return skb->len; |
| 266 | } |
| 267 | |
| 268 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 269 | { |
| 270 | struct sk_buff *msg; |
| 271 | struct cfg80211_registered_device *dev; |
| 272 | |
| 273 | dev = cfg80211_get_dev_from_info(info); |
| 274 | if (IS_ERR(dev)) |
| 275 | return PTR_ERR(dev); |
| 276 | |
| 277 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 278 | if (!msg) |
| 279 | goto out_err; |
| 280 | |
| 281 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) |
| 282 | goto out_free; |
| 283 | |
| 284 | cfg80211_put_dev(dev); |
| 285 | |
| 286 | return genlmsg_unicast(msg, info->snd_pid); |
| 287 | |
| 288 | out_free: |
| 289 | nlmsg_free(msg); |
| 290 | out_err: |
| 291 | cfg80211_put_dev(dev); |
| 292 | return -ENOBUFS; |
| 293 | } |
| 294 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 295 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 296 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 297 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 298 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 299 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 300 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 301 | }; |
| 302 | |
| 303 | static int parse_txq_params(struct nlattr *tb[], |
| 304 | struct ieee80211_txq_params *txq_params) |
| 305 | { |
| 306 | if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] || |
| 307 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 308 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 309 | return -EINVAL; |
| 310 | |
| 311 | txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]); |
| 312 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 313 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 314 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 315 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 316 | |
| 317 | return 0; |
| 318 | } |
| 319 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 320 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 321 | { |
| 322 | struct cfg80211_registered_device *rdev; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 323 | int result = 0, rem_txq_params = 0; |
| 324 | struct nlattr *nl_txq_params; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 325 | |
| 326 | rdev = cfg80211_get_dev_from_info(info); |
| 327 | if (IS_ERR(rdev)) |
| 328 | return PTR_ERR(rdev); |
| 329 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 330 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) { |
| 331 | result = cfg80211_dev_rename( |
| 332 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
| 333 | if (result) |
| 334 | goto bad_res; |
| 335 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 336 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 337 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 338 | struct ieee80211_txq_params txq_params; |
| 339 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 340 | |
| 341 | if (!rdev->ops->set_txq_params) { |
| 342 | result = -EOPNOTSUPP; |
| 343 | goto bad_res; |
| 344 | } |
| 345 | |
| 346 | nla_for_each_nested(nl_txq_params, |
| 347 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 348 | rem_txq_params) { |
| 349 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 350 | nla_data(nl_txq_params), |
| 351 | nla_len(nl_txq_params), |
| 352 | txq_params_policy); |
| 353 | result = parse_txq_params(tb, &txq_params); |
| 354 | if (result) |
| 355 | goto bad_res; |
| 356 | |
| 357 | result = rdev->ops->set_txq_params(&rdev->wiphy, |
| 358 | &txq_params); |
| 359 | if (result) |
| 360 | goto bad_res; |
| 361 | } |
| 362 | } |
| 363 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 364 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 365 | enum nl80211_sec_chan_offset sec_chan_offset = |
| 366 | NL80211_SEC_CHAN_NO_HT; |
| 367 | struct ieee80211_channel *chan; |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 368 | struct ieee80211_sta_ht_cap *ht_cap; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 369 | u32 freq, sec_freq; |
| 370 | |
| 371 | if (!rdev->ops->set_channel) { |
| 372 | result = -EOPNOTSUPP; |
| 373 | goto bad_res; |
| 374 | } |
| 375 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 376 | result = -EINVAL; |
| 377 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 378 | if (info->attrs[NL80211_ATTR_WIPHY_SEC_CHAN_OFFSET]) { |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 379 | sec_chan_offset = nla_get_u32(info->attrs[ |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 380 | NL80211_ATTR_WIPHY_SEC_CHAN_OFFSET]); |
| 381 | if (sec_chan_offset != NL80211_SEC_CHAN_NO_HT && |
| 382 | sec_chan_offset != NL80211_SEC_CHAN_DISABLED && |
| 383 | sec_chan_offset != NL80211_SEC_CHAN_BELOW && |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 384 | sec_chan_offset != NL80211_SEC_CHAN_ABOVE) |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 385 | goto bad_res; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 389 | chan = ieee80211_get_channel(&rdev->wiphy, freq); |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 390 | |
| 391 | /* Primary channel not allowed */ |
| 392 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 393 | goto bad_res; |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 394 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 395 | if (sec_chan_offset == NL80211_SEC_CHAN_BELOW) |
| 396 | sec_freq = freq - 20; |
| 397 | else if (sec_chan_offset == NL80211_SEC_CHAN_ABOVE) |
| 398 | sec_freq = freq + 20; |
| 399 | else |
| 400 | sec_freq = 0; |
| 401 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 402 | ht_cap = &rdev->wiphy.bands[chan->band]->ht_cap; |
| 403 | |
| 404 | /* no HT capabilities */ |
| 405 | if (sec_chan_offset != NL80211_SEC_CHAN_NO_HT && |
| 406 | !ht_cap->ht_supported) |
| 407 | goto bad_res; |
| 408 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 409 | if (sec_freq) { |
| 410 | struct ieee80211_channel *schan; |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 411 | |
| 412 | /* no 40 MHz capabilities */ |
| 413 | if (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) || |
| 414 | (ht_cap->cap & IEEE80211_HT_CAP_40MHZ_INTOLERANT)) |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 415 | goto bad_res; |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 416 | |
| 417 | schan = ieee80211_get_channel(&rdev->wiphy, sec_freq); |
| 418 | |
| 419 | /* Secondary channel not allowed */ |
| 420 | if (!schan || schan->flags & IEEE80211_CHAN_DISABLED) |
| 421 | goto bad_res; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | result = rdev->ops->set_channel(&rdev->wiphy, chan, |
| 425 | sec_chan_offset); |
| 426 | if (result) |
| 427 | goto bad_res; |
| 428 | } |
| 429 | |
| 430 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 431 | bad_res: |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 432 | cfg80211_put_dev(rdev); |
| 433 | return result; |
| 434 | } |
| 435 | |
| 436 | |
| 437 | static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 438 | struct net_device *dev) |
| 439 | { |
| 440 | void *hdr; |
| 441 | |
| 442 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
| 443 | if (!hdr) |
| 444 | return -1; |
| 445 | |
| 446 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 447 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name); |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 448 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 449 | return genlmsg_end(msg, hdr); |
| 450 | |
| 451 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 452 | genlmsg_cancel(msg, hdr); |
| 453 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 457 | { |
| 458 | int wp_idx = 0; |
| 459 | int if_idx = 0; |
| 460 | int wp_start = cb->args[0]; |
| 461 | int if_start = cb->args[1]; |
| 462 | struct cfg80211_registered_device *dev; |
| 463 | struct wireless_dev *wdev; |
| 464 | |
| 465 | mutex_lock(&cfg80211_drv_mutex); |
| 466 | list_for_each_entry(dev, &cfg80211_drv_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 467 | if (wp_idx < wp_start) { |
| 468 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 469 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 470 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 471 | if_idx = 0; |
| 472 | |
| 473 | mutex_lock(&dev->devlist_mtx); |
| 474 | list_for_each_entry(wdev, &dev->netdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 475 | if (if_idx < if_start) { |
| 476 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 477 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 478 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 479 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
| 480 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 481 | wdev->netdev) < 0) { |
| 482 | mutex_unlock(&dev->devlist_mtx); |
| 483 | goto out; |
| 484 | } |
| 485 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 486 | } |
| 487 | mutex_unlock(&dev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 488 | |
| 489 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 490 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 491 | out: |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 492 | mutex_unlock(&cfg80211_drv_mutex); |
| 493 | |
| 494 | cb->args[0] = wp_idx; |
| 495 | cb->args[1] = if_idx; |
| 496 | |
| 497 | return skb->len; |
| 498 | } |
| 499 | |
| 500 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 501 | { |
| 502 | struct sk_buff *msg; |
| 503 | struct cfg80211_registered_device *dev; |
| 504 | struct net_device *netdev; |
| 505 | int err; |
| 506 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 507 | err = get_drv_dev_by_info_ifindex(info->attrs, &dev, &netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 508 | if (err) |
| 509 | return err; |
| 510 | |
| 511 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 512 | if (!msg) |
| 513 | goto out_err; |
| 514 | |
| 515 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, netdev) < 0) |
| 516 | goto out_free; |
| 517 | |
| 518 | dev_put(netdev); |
| 519 | cfg80211_put_dev(dev); |
| 520 | |
| 521 | return genlmsg_unicast(msg, info->snd_pid); |
| 522 | |
| 523 | out_free: |
| 524 | nlmsg_free(msg); |
| 525 | out_err: |
| 526 | dev_put(netdev); |
| 527 | cfg80211_put_dev(dev); |
| 528 | return -ENOBUFS; |
| 529 | } |
| 530 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 531 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 532 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 533 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 534 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 535 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 536 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 537 | }; |
| 538 | |
| 539 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 540 | { |
| 541 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 542 | int flag; |
| 543 | |
| 544 | *mntrflags = 0; |
| 545 | |
| 546 | if (!nla) |
| 547 | return -EINVAL; |
| 548 | |
| 549 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 550 | nla, mntr_flags_policy)) |
| 551 | return -EINVAL; |
| 552 | |
| 553 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 554 | if (flags[flag]) |
| 555 | *mntrflags |= (1<<flag); |
| 556 | |
| 557 | return 0; |
| 558 | } |
| 559 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 560 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 561 | { |
| 562 | struct cfg80211_registered_device *drv; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 563 | struct vif_params params; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 564 | int err, ifindex; |
| 565 | enum nl80211_iftype type; |
| 566 | struct net_device *dev; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 567 | u32 _flags, *flags = NULL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 568 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 569 | memset(¶ms, 0, sizeof(params)); |
| 570 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 571 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 572 | if (err) |
| 573 | return err; |
| 574 | ifindex = dev->ifindex; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 575 | type = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 576 | dev_put(dev); |
| 577 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 578 | err = -EINVAL; |
| 579 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 580 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 581 | if (type > NL80211_IFTYPE_MAX) |
| 582 | goto unlock; |
| 583 | } |
| 584 | |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 585 | if (!drv->ops->change_virtual_intf || |
| 586 | !(drv->wiphy.interface_modes & (1 << type))) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 587 | err = -EOPNOTSUPP; |
| 588 | goto unlock; |
| 589 | } |
| 590 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 591 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
| 592 | if (type != NL80211_IFTYPE_MESH_POINT) { |
| 593 | err = -EINVAL; |
| 594 | goto unlock; |
| 595 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 596 | params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 597 | params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 598 | } |
| 599 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 600 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
| 601 | if (type != NL80211_IFTYPE_MONITOR) { |
| 602 | err = -EINVAL; |
| 603 | goto unlock; |
| 604 | } |
| 605 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 606 | &_flags); |
| 607 | if (!err) |
| 608 | flags = &_flags; |
| 609 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 610 | rtnl_lock(); |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 611 | err = drv->ops->change_virtual_intf(&drv->wiphy, ifindex, |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 612 | type, flags, ¶ms); |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 613 | |
| 614 | dev = __dev_get_by_index(&init_net, ifindex); |
| 615 | WARN_ON(!dev || (!err && dev->ieee80211_ptr->iftype != type)); |
| 616 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 617 | rtnl_unlock(); |
| 618 | |
| 619 | unlock: |
| 620 | cfg80211_put_dev(drv); |
| 621 | return err; |
| 622 | } |
| 623 | |
| 624 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 625 | { |
| 626 | struct cfg80211_registered_device *drv; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 627 | struct vif_params params; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 628 | int err; |
| 629 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 630 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 631 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 632 | memset(¶ms, 0, sizeof(params)); |
| 633 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 634 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 635 | return -EINVAL; |
| 636 | |
| 637 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 638 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 639 | if (type > NL80211_IFTYPE_MAX) |
| 640 | return -EINVAL; |
| 641 | } |
| 642 | |
| 643 | drv = cfg80211_get_dev_from_info(info); |
| 644 | if (IS_ERR(drv)) |
| 645 | return PTR_ERR(drv); |
| 646 | |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 647 | if (!drv->ops->add_virtual_intf || |
| 648 | !(drv->wiphy.interface_modes & (1 << type))) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 649 | err = -EOPNOTSUPP; |
| 650 | goto unlock; |
| 651 | } |
| 652 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 653 | if (type == NL80211_IFTYPE_MESH_POINT && |
| 654 | info->attrs[NL80211_ATTR_MESH_ID]) { |
| 655 | params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 656 | params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 657 | } |
| 658 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 659 | rtnl_lock(); |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 660 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 661 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 662 | &flags); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 663 | err = drv->ops->add_virtual_intf(&drv->wiphy, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 664 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 665 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 666 | rtnl_unlock(); |
| 667 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 668 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 669 | unlock: |
| 670 | cfg80211_put_dev(drv); |
| 671 | return err; |
| 672 | } |
| 673 | |
| 674 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 675 | { |
| 676 | struct cfg80211_registered_device *drv; |
| 677 | int ifindex, err; |
| 678 | struct net_device *dev; |
| 679 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 680 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 681 | if (err) |
| 682 | return err; |
| 683 | ifindex = dev->ifindex; |
| 684 | dev_put(dev); |
| 685 | |
| 686 | if (!drv->ops->del_virtual_intf) { |
| 687 | err = -EOPNOTSUPP; |
| 688 | goto out; |
| 689 | } |
| 690 | |
| 691 | rtnl_lock(); |
| 692 | err = drv->ops->del_virtual_intf(&drv->wiphy, ifindex); |
| 693 | rtnl_unlock(); |
| 694 | |
| 695 | out: |
| 696 | cfg80211_put_dev(drv); |
| 697 | return err; |
| 698 | } |
| 699 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 700 | struct get_key_cookie { |
| 701 | struct sk_buff *msg; |
| 702 | int error; |
| 703 | }; |
| 704 | |
| 705 | static void get_key_callback(void *c, struct key_params *params) |
| 706 | { |
| 707 | struct get_key_cookie *cookie = c; |
| 708 | |
| 709 | if (params->key) |
| 710 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 711 | params->key_len, params->key); |
| 712 | |
| 713 | if (params->seq) |
| 714 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 715 | params->seq_len, params->seq); |
| 716 | |
| 717 | if (params->cipher) |
| 718 | NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 719 | params->cipher); |
| 720 | |
| 721 | return; |
| 722 | nla_put_failure: |
| 723 | cookie->error = 1; |
| 724 | } |
| 725 | |
| 726 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 727 | { |
| 728 | struct cfg80211_registered_device *drv; |
| 729 | int err; |
| 730 | struct net_device *dev; |
| 731 | u8 key_idx = 0; |
| 732 | u8 *mac_addr = NULL; |
| 733 | struct get_key_cookie cookie = { |
| 734 | .error = 0, |
| 735 | }; |
| 736 | void *hdr; |
| 737 | struct sk_buff *msg; |
| 738 | |
| 739 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 740 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 741 | |
| 742 | if (key_idx > 3) |
| 743 | return -EINVAL; |
| 744 | |
| 745 | if (info->attrs[NL80211_ATTR_MAC]) |
| 746 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 747 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 748 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 749 | if (err) |
| 750 | return err; |
| 751 | |
| 752 | if (!drv->ops->get_key) { |
| 753 | err = -EOPNOTSUPP; |
| 754 | goto out; |
| 755 | } |
| 756 | |
| 757 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 758 | if (!msg) { |
| 759 | err = -ENOMEM; |
| 760 | goto out; |
| 761 | } |
| 762 | |
| 763 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 764 | NL80211_CMD_NEW_KEY); |
| 765 | |
| 766 | if (IS_ERR(hdr)) { |
| 767 | err = PTR_ERR(hdr); |
| 768 | goto out; |
| 769 | } |
| 770 | |
| 771 | cookie.msg = msg; |
| 772 | |
| 773 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 774 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
| 775 | if (mac_addr) |
| 776 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 777 | |
| 778 | rtnl_lock(); |
| 779 | err = drv->ops->get_key(&drv->wiphy, dev, key_idx, mac_addr, |
| 780 | &cookie, get_key_callback); |
| 781 | rtnl_unlock(); |
| 782 | |
| 783 | if (err) |
| 784 | goto out; |
| 785 | |
| 786 | if (cookie.error) |
| 787 | goto nla_put_failure; |
| 788 | |
| 789 | genlmsg_end(msg, hdr); |
| 790 | err = genlmsg_unicast(msg, info->snd_pid); |
| 791 | goto out; |
| 792 | |
| 793 | nla_put_failure: |
| 794 | err = -ENOBUFS; |
| 795 | nlmsg_free(msg); |
| 796 | out: |
| 797 | cfg80211_put_dev(drv); |
| 798 | dev_put(dev); |
| 799 | return err; |
| 800 | } |
| 801 | |
| 802 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 803 | { |
| 804 | struct cfg80211_registered_device *drv; |
| 805 | int err; |
| 806 | struct net_device *dev; |
| 807 | u8 key_idx; |
| 808 | |
| 809 | if (!info->attrs[NL80211_ATTR_KEY_IDX]) |
| 810 | return -EINVAL; |
| 811 | |
| 812 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 813 | |
| 814 | if (key_idx > 3) |
| 815 | return -EINVAL; |
| 816 | |
| 817 | /* currently only support setting default key */ |
| 818 | if (!info->attrs[NL80211_ATTR_KEY_DEFAULT]) |
| 819 | return -EINVAL; |
| 820 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 821 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 822 | if (err) |
| 823 | return err; |
| 824 | |
| 825 | if (!drv->ops->set_default_key) { |
| 826 | err = -EOPNOTSUPP; |
| 827 | goto out; |
| 828 | } |
| 829 | |
| 830 | rtnl_lock(); |
| 831 | err = drv->ops->set_default_key(&drv->wiphy, dev, key_idx); |
| 832 | rtnl_unlock(); |
| 833 | |
| 834 | out: |
| 835 | cfg80211_put_dev(drv); |
| 836 | dev_put(dev); |
| 837 | return err; |
| 838 | } |
| 839 | |
| 840 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 841 | { |
| 842 | struct cfg80211_registered_device *drv; |
| 843 | int err; |
| 844 | struct net_device *dev; |
| 845 | struct key_params params; |
| 846 | u8 key_idx = 0; |
| 847 | u8 *mac_addr = NULL; |
| 848 | |
| 849 | memset(¶ms, 0, sizeof(params)); |
| 850 | |
| 851 | if (!info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 852 | return -EINVAL; |
| 853 | |
| 854 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 855 | params.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 856 | params.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 857 | } |
| 858 | |
| 859 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 860 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 861 | |
| 862 | params.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 863 | |
| 864 | if (info->attrs[NL80211_ATTR_MAC]) |
| 865 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 866 | |
| 867 | if (key_idx > 3) |
| 868 | return -EINVAL; |
| 869 | |
| 870 | /* |
| 871 | * Disallow pairwise keys with non-zero index unless it's WEP |
| 872 | * (because current deployments use pairwise WEP keys with |
| 873 | * non-zero indizes but 802.11i clearly specifies to use zero) |
| 874 | */ |
| 875 | if (mac_addr && key_idx && |
| 876 | params.cipher != WLAN_CIPHER_SUITE_WEP40 && |
| 877 | params.cipher != WLAN_CIPHER_SUITE_WEP104) |
| 878 | return -EINVAL; |
| 879 | |
| 880 | /* TODO: add definitions for the lengths to linux/ieee80211.h */ |
| 881 | switch (params.cipher) { |
| 882 | case WLAN_CIPHER_SUITE_WEP40: |
| 883 | if (params.key_len != 5) |
| 884 | return -EINVAL; |
| 885 | break; |
| 886 | case WLAN_CIPHER_SUITE_TKIP: |
| 887 | if (params.key_len != 32) |
| 888 | return -EINVAL; |
| 889 | break; |
| 890 | case WLAN_CIPHER_SUITE_CCMP: |
| 891 | if (params.key_len != 16) |
| 892 | return -EINVAL; |
| 893 | break; |
| 894 | case WLAN_CIPHER_SUITE_WEP104: |
| 895 | if (params.key_len != 13) |
| 896 | return -EINVAL; |
| 897 | break; |
| 898 | default: |
| 899 | return -EINVAL; |
| 900 | } |
| 901 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 902 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 903 | if (err) |
| 904 | return err; |
| 905 | |
| 906 | if (!drv->ops->add_key) { |
| 907 | err = -EOPNOTSUPP; |
| 908 | goto out; |
| 909 | } |
| 910 | |
| 911 | rtnl_lock(); |
| 912 | err = drv->ops->add_key(&drv->wiphy, dev, key_idx, mac_addr, ¶ms); |
| 913 | rtnl_unlock(); |
| 914 | |
| 915 | out: |
| 916 | cfg80211_put_dev(drv); |
| 917 | dev_put(dev); |
| 918 | return err; |
| 919 | } |
| 920 | |
| 921 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 922 | { |
| 923 | struct cfg80211_registered_device *drv; |
| 924 | int err; |
| 925 | struct net_device *dev; |
| 926 | u8 key_idx = 0; |
| 927 | u8 *mac_addr = NULL; |
| 928 | |
| 929 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 930 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 931 | |
| 932 | if (key_idx > 3) |
| 933 | return -EINVAL; |
| 934 | |
| 935 | if (info->attrs[NL80211_ATTR_MAC]) |
| 936 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 937 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 938 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 939 | if (err) |
| 940 | return err; |
| 941 | |
| 942 | if (!drv->ops->del_key) { |
| 943 | err = -EOPNOTSUPP; |
| 944 | goto out; |
| 945 | } |
| 946 | |
| 947 | rtnl_lock(); |
| 948 | err = drv->ops->del_key(&drv->wiphy, dev, key_idx, mac_addr); |
| 949 | rtnl_unlock(); |
| 950 | |
| 951 | out: |
| 952 | cfg80211_put_dev(drv); |
| 953 | dev_put(dev); |
| 954 | return err; |
| 955 | } |
| 956 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 957 | static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info) |
| 958 | { |
| 959 | int (*call)(struct wiphy *wiphy, struct net_device *dev, |
| 960 | struct beacon_parameters *info); |
| 961 | struct cfg80211_registered_device *drv; |
| 962 | int err; |
| 963 | struct net_device *dev; |
| 964 | struct beacon_parameters params; |
| 965 | int haveinfo = 0; |
| 966 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 967 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 968 | if (err) |
| 969 | return err; |
| 970 | |
| 971 | switch (info->genlhdr->cmd) { |
| 972 | case NL80211_CMD_NEW_BEACON: |
| 973 | /* these are required for NEW_BEACON */ |
| 974 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 975 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 976 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 977 | err = -EINVAL; |
| 978 | goto out; |
| 979 | } |
| 980 | |
| 981 | call = drv->ops->add_beacon; |
| 982 | break; |
| 983 | case NL80211_CMD_SET_BEACON: |
| 984 | call = drv->ops->set_beacon; |
| 985 | break; |
| 986 | default: |
| 987 | WARN_ON(1); |
| 988 | err = -EOPNOTSUPP; |
| 989 | goto out; |
| 990 | } |
| 991 | |
| 992 | if (!call) { |
| 993 | err = -EOPNOTSUPP; |
| 994 | goto out; |
| 995 | } |
| 996 | |
| 997 | memset(¶ms, 0, sizeof(params)); |
| 998 | |
| 999 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 1000 | params.interval = |
| 1001 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 1002 | haveinfo = 1; |
| 1003 | } |
| 1004 | |
| 1005 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 1006 | params.dtim_period = |
| 1007 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 1008 | haveinfo = 1; |
| 1009 | } |
| 1010 | |
| 1011 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 1012 | params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 1013 | params.head_len = |
| 1014 | nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 1015 | haveinfo = 1; |
| 1016 | } |
| 1017 | |
| 1018 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 1019 | params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 1020 | params.tail_len = |
| 1021 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 1022 | haveinfo = 1; |
| 1023 | } |
| 1024 | |
| 1025 | if (!haveinfo) { |
| 1026 | err = -EINVAL; |
| 1027 | goto out; |
| 1028 | } |
| 1029 | |
| 1030 | rtnl_lock(); |
| 1031 | err = call(&drv->wiphy, dev, ¶ms); |
| 1032 | rtnl_unlock(); |
| 1033 | |
| 1034 | out: |
| 1035 | cfg80211_put_dev(drv); |
| 1036 | dev_put(dev); |
| 1037 | return err; |
| 1038 | } |
| 1039 | |
| 1040 | static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info) |
| 1041 | { |
| 1042 | struct cfg80211_registered_device *drv; |
| 1043 | int err; |
| 1044 | struct net_device *dev; |
| 1045 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1046 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1047 | if (err) |
| 1048 | return err; |
| 1049 | |
| 1050 | if (!drv->ops->del_beacon) { |
| 1051 | err = -EOPNOTSUPP; |
| 1052 | goto out; |
| 1053 | } |
| 1054 | |
| 1055 | rtnl_lock(); |
| 1056 | err = drv->ops->del_beacon(&drv->wiphy, dev); |
| 1057 | rtnl_unlock(); |
| 1058 | |
| 1059 | out: |
| 1060 | cfg80211_put_dev(drv); |
| 1061 | dev_put(dev); |
| 1062 | return err; |
| 1063 | } |
| 1064 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1065 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 1066 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 1067 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 1068 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
| 1069 | }; |
| 1070 | |
| 1071 | static int parse_station_flags(struct nlattr *nla, u32 *staflags) |
| 1072 | { |
| 1073 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
| 1074 | int flag; |
| 1075 | |
| 1076 | *staflags = 0; |
| 1077 | |
| 1078 | if (!nla) |
| 1079 | return 0; |
| 1080 | |
| 1081 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 1082 | nla, sta_flags_policy)) |
| 1083 | return -EINVAL; |
| 1084 | |
| 1085 | *staflags = STATION_FLAG_CHANGED; |
| 1086 | |
| 1087 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) |
| 1088 | if (flags[flag]) |
| 1089 | *staflags |= (1<<flag); |
| 1090 | |
| 1091 | return 0; |
| 1092 | } |
| 1093 | |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame^] | 1094 | static u16 nl80211_calculate_bitrate(struct rate_info *rate) |
| 1095 | { |
| 1096 | int modulation, streams, bitrate; |
| 1097 | |
| 1098 | if (!(rate->flags & RATE_INFO_FLAGS_MCS)) |
| 1099 | return rate->legacy; |
| 1100 | |
| 1101 | /* the formula below does only work for MCS values smaller than 32 */ |
| 1102 | if (rate->mcs >= 32) |
| 1103 | return 0; |
| 1104 | |
| 1105 | modulation = rate->mcs & 7; |
| 1106 | streams = (rate->mcs >> 3) + 1; |
| 1107 | |
| 1108 | bitrate = (rate->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) ? |
| 1109 | 13500000 : 6500000; |
| 1110 | |
| 1111 | if (modulation < 4) |
| 1112 | bitrate *= (modulation + 1); |
| 1113 | else if (modulation == 4) |
| 1114 | bitrate *= (modulation + 2); |
| 1115 | else |
| 1116 | bitrate *= (modulation + 3); |
| 1117 | |
| 1118 | bitrate *= streams; |
| 1119 | |
| 1120 | if (rate->flags & RATE_INFO_FLAGS_SHORT_GI) |
| 1121 | bitrate = (bitrate / 9) * 10; |
| 1122 | |
| 1123 | /* do NOT round down here */ |
| 1124 | return (bitrate + 50000) / 100000; |
| 1125 | } |
| 1126 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1127 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
| 1128 | int flags, struct net_device *dev, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1129 | u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1130 | { |
| 1131 | void *hdr; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame^] | 1132 | struct nlattr *sinfoattr, *txrate; |
| 1133 | u16 bitrate; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1134 | |
| 1135 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 1136 | if (!hdr) |
| 1137 | return -1; |
| 1138 | |
| 1139 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1140 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 1141 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1142 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 1143 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1144 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1145 | if (sinfo->filled & STATION_INFO_INACTIVE_TIME) |
| 1146 | NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 1147 | sinfo->inactive_time); |
| 1148 | if (sinfo->filled & STATION_INFO_RX_BYTES) |
| 1149 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES, |
| 1150 | sinfo->rx_bytes); |
| 1151 | if (sinfo->filled & STATION_INFO_TX_BYTES) |
| 1152 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES, |
| 1153 | sinfo->tx_bytes); |
| 1154 | if (sinfo->filled & STATION_INFO_LLID) |
| 1155 | NLA_PUT_U16(msg, NL80211_STA_INFO_LLID, |
| 1156 | sinfo->llid); |
| 1157 | if (sinfo->filled & STATION_INFO_PLID) |
| 1158 | NLA_PUT_U16(msg, NL80211_STA_INFO_PLID, |
| 1159 | sinfo->plid); |
| 1160 | if (sinfo->filled & STATION_INFO_PLINK_STATE) |
| 1161 | NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 1162 | sinfo->plink_state); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame^] | 1163 | if (sinfo->filled & STATION_INFO_SIGNAL) |
| 1164 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, |
| 1165 | sinfo->signal); |
| 1166 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
| 1167 | txrate = nla_nest_start(msg, NL80211_STA_INFO_TX_BITRATE); |
| 1168 | if (!txrate) |
| 1169 | goto nla_put_failure; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1170 | |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame^] | 1171 | /* nl80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 1172 | bitrate = nl80211_calculate_bitrate(&sinfo->txrate); |
| 1173 | if (bitrate > 0) |
| 1174 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); |
| 1175 | |
| 1176 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_MCS) |
| 1177 | NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, |
| 1178 | sinfo->txrate.mcs); |
| 1179 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) |
| 1180 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH); |
| 1181 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_SHORT_GI) |
| 1182 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI); |
| 1183 | |
| 1184 | nla_nest_end(msg, txrate); |
| 1185 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1186 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1187 | |
| 1188 | return genlmsg_end(msg, hdr); |
| 1189 | |
| 1190 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1191 | genlmsg_cancel(msg, hdr); |
| 1192 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1193 | } |
| 1194 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1195 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1196 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1197 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1198 | struct station_info sinfo; |
| 1199 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1200 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1201 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1202 | int ifidx = cb->args[0]; |
| 1203 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1204 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1205 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1206 | if (!ifidx) { |
| 1207 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1208 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 1209 | nl80211_policy); |
| 1210 | if (err) |
| 1211 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1212 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1213 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 1214 | return -EINVAL; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1215 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1216 | ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 1217 | if (!ifidx) |
| 1218 | return -EINVAL; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1219 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1220 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1221 | netdev = dev_get_by_index(&init_net, ifidx); |
| 1222 | if (!netdev) |
| 1223 | return -ENODEV; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1224 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1225 | dev = cfg80211_get_dev_from_ifindex(ifidx); |
| 1226 | if (IS_ERR(dev)) { |
| 1227 | err = PTR_ERR(dev); |
| 1228 | goto out_put_netdev; |
| 1229 | } |
| 1230 | |
| 1231 | if (!dev->ops->dump_station) { |
| 1232 | err = -ENOSYS; |
| 1233 | goto out_err; |
| 1234 | } |
| 1235 | |
| 1236 | rtnl_lock(); |
| 1237 | |
| 1238 | while (1) { |
| 1239 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
| 1240 | mac_addr, &sinfo); |
| 1241 | if (err == -ENOENT) |
| 1242 | break; |
| 1243 | if (err) |
| 1244 | goto out_err_rtnl; |
| 1245 | |
| 1246 | if (nl80211_send_station(skb, |
| 1247 | NETLINK_CB(cb->skb).pid, |
| 1248 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 1249 | netdev, mac_addr, |
| 1250 | &sinfo) < 0) |
| 1251 | goto out; |
| 1252 | |
| 1253 | sta_idx++; |
| 1254 | } |
| 1255 | |
| 1256 | |
| 1257 | out: |
| 1258 | cb->args[1] = sta_idx; |
| 1259 | err = skb->len; |
| 1260 | out_err_rtnl: |
| 1261 | rtnl_unlock(); |
| 1262 | out_err: |
| 1263 | cfg80211_put_dev(dev); |
| 1264 | out_put_netdev: |
| 1265 | dev_put(netdev); |
| 1266 | |
| 1267 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1268 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1269 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1270 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 1271 | { |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1272 | struct cfg80211_registered_device *drv; |
| 1273 | int err; |
| 1274 | struct net_device *dev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1275 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1276 | struct sk_buff *msg; |
| 1277 | u8 *mac_addr = NULL; |
| 1278 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1279 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1280 | |
| 1281 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1282 | return -EINVAL; |
| 1283 | |
| 1284 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1285 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1286 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1287 | if (err) |
| 1288 | return err; |
| 1289 | |
| 1290 | if (!drv->ops->get_station) { |
| 1291 | err = -EOPNOTSUPP; |
| 1292 | goto out; |
| 1293 | } |
| 1294 | |
| 1295 | rtnl_lock(); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1296 | err = drv->ops->get_station(&drv->wiphy, dev, mac_addr, &sinfo); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1297 | rtnl_unlock(); |
| 1298 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1299 | if (err) |
| 1300 | goto out; |
| 1301 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1302 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 1303 | if (!msg) |
| 1304 | goto out; |
| 1305 | |
| 1306 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1307 | dev, mac_addr, &sinfo) < 0) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1308 | goto out_free; |
| 1309 | |
| 1310 | err = genlmsg_unicast(msg, info->snd_pid); |
| 1311 | goto out; |
| 1312 | |
| 1313 | out_free: |
| 1314 | nlmsg_free(msg); |
| 1315 | |
| 1316 | out: |
| 1317 | cfg80211_put_dev(drv); |
| 1318 | dev_put(dev); |
| 1319 | return err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1320 | } |
| 1321 | |
| 1322 | /* |
| 1323 | * Get vlan interface making sure it is on the right wiphy. |
| 1324 | */ |
| 1325 | static int get_vlan(struct nlattr *vlanattr, |
| 1326 | struct cfg80211_registered_device *rdev, |
| 1327 | struct net_device **vlan) |
| 1328 | { |
| 1329 | *vlan = NULL; |
| 1330 | |
| 1331 | if (vlanattr) { |
| 1332 | *vlan = dev_get_by_index(&init_net, nla_get_u32(vlanattr)); |
| 1333 | if (!*vlan) |
| 1334 | return -ENODEV; |
| 1335 | if (!(*vlan)->ieee80211_ptr) |
| 1336 | return -EINVAL; |
| 1337 | if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy) |
| 1338 | return -EINVAL; |
| 1339 | } |
| 1340 | return 0; |
| 1341 | } |
| 1342 | |
| 1343 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 1344 | { |
| 1345 | struct cfg80211_registered_device *drv; |
| 1346 | int err; |
| 1347 | struct net_device *dev; |
| 1348 | struct station_parameters params; |
| 1349 | u8 *mac_addr = NULL; |
| 1350 | |
| 1351 | memset(¶ms, 0, sizeof(params)); |
| 1352 | |
| 1353 | params.listen_interval = -1; |
| 1354 | |
| 1355 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 1356 | return -EINVAL; |
| 1357 | |
| 1358 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1359 | return -EINVAL; |
| 1360 | |
| 1361 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1362 | |
| 1363 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 1364 | params.supported_rates = |
| 1365 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 1366 | params.supported_rates_len = |
| 1367 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 1368 | } |
| 1369 | |
| 1370 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 1371 | params.listen_interval = |
| 1372 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 1373 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 1374 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 1375 | params.ht_capa = |
| 1376 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 1377 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1378 | if (parse_station_flags(info->attrs[NL80211_ATTR_STA_FLAGS], |
| 1379 | ¶ms.station_flags)) |
| 1380 | return -EINVAL; |
| 1381 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1382 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 1383 | params.plink_action = |
| 1384 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 1385 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1386 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1387 | if (err) |
| 1388 | return err; |
| 1389 | |
| 1390 | err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, ¶ms.vlan); |
| 1391 | if (err) |
| 1392 | goto out; |
| 1393 | |
| 1394 | if (!drv->ops->change_station) { |
| 1395 | err = -EOPNOTSUPP; |
| 1396 | goto out; |
| 1397 | } |
| 1398 | |
| 1399 | rtnl_lock(); |
| 1400 | err = drv->ops->change_station(&drv->wiphy, dev, mac_addr, ¶ms); |
| 1401 | rtnl_unlock(); |
| 1402 | |
| 1403 | out: |
| 1404 | if (params.vlan) |
| 1405 | dev_put(params.vlan); |
| 1406 | cfg80211_put_dev(drv); |
| 1407 | dev_put(dev); |
| 1408 | return err; |
| 1409 | } |
| 1410 | |
| 1411 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 1412 | { |
| 1413 | struct cfg80211_registered_device *drv; |
| 1414 | int err; |
| 1415 | struct net_device *dev; |
| 1416 | struct station_parameters params; |
| 1417 | u8 *mac_addr = NULL; |
| 1418 | |
| 1419 | memset(¶ms, 0, sizeof(params)); |
| 1420 | |
| 1421 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1422 | return -EINVAL; |
| 1423 | |
| 1424 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 1425 | return -EINVAL; |
| 1426 | |
| 1427 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 1428 | return -EINVAL; |
| 1429 | |
| 1430 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 1431 | return -EINVAL; |
| 1432 | |
| 1433 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1434 | params.supported_rates = |
| 1435 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 1436 | params.supported_rates_len = |
| 1437 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 1438 | params.listen_interval = |
| 1439 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 16f2e85 | 2008-04-07 14:35:46 +0200 | [diff] [blame] | 1440 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 1441 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 1442 | params.ht_capa = |
| 1443 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1444 | |
| 1445 | if (parse_station_flags(info->attrs[NL80211_ATTR_STA_FLAGS], |
| 1446 | ¶ms.station_flags)) |
| 1447 | return -EINVAL; |
| 1448 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1449 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1450 | if (err) |
| 1451 | return err; |
| 1452 | |
| 1453 | err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, ¶ms.vlan); |
| 1454 | if (err) |
| 1455 | goto out; |
| 1456 | |
| 1457 | if (!drv->ops->add_station) { |
| 1458 | err = -EOPNOTSUPP; |
| 1459 | goto out; |
| 1460 | } |
| 1461 | |
| 1462 | rtnl_lock(); |
| 1463 | err = drv->ops->add_station(&drv->wiphy, dev, mac_addr, ¶ms); |
| 1464 | rtnl_unlock(); |
| 1465 | |
| 1466 | out: |
| 1467 | if (params.vlan) |
| 1468 | dev_put(params.vlan); |
| 1469 | cfg80211_put_dev(drv); |
| 1470 | dev_put(dev); |
| 1471 | return err; |
| 1472 | } |
| 1473 | |
| 1474 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 1475 | { |
| 1476 | struct cfg80211_registered_device *drv; |
| 1477 | int err; |
| 1478 | struct net_device *dev; |
| 1479 | u8 *mac_addr = NULL; |
| 1480 | |
| 1481 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1482 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1483 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1484 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1485 | if (err) |
| 1486 | return err; |
| 1487 | |
| 1488 | if (!drv->ops->del_station) { |
| 1489 | err = -EOPNOTSUPP; |
| 1490 | goto out; |
| 1491 | } |
| 1492 | |
| 1493 | rtnl_lock(); |
| 1494 | err = drv->ops->del_station(&drv->wiphy, dev, mac_addr); |
| 1495 | rtnl_unlock(); |
| 1496 | |
| 1497 | out: |
| 1498 | cfg80211_put_dev(drv); |
| 1499 | dev_put(dev); |
| 1500 | return err; |
| 1501 | } |
| 1502 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1503 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
| 1504 | int flags, struct net_device *dev, |
| 1505 | u8 *dst, u8 *next_hop, |
| 1506 | struct mpath_info *pinfo) |
| 1507 | { |
| 1508 | void *hdr; |
| 1509 | struct nlattr *pinfoattr; |
| 1510 | |
| 1511 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 1512 | if (!hdr) |
| 1513 | return -1; |
| 1514 | |
| 1515 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1516 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); |
| 1517 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); |
| 1518 | |
| 1519 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 1520 | if (!pinfoattr) |
| 1521 | goto nla_put_failure; |
| 1522 | if (pinfo->filled & MPATH_INFO_FRAME_QLEN) |
| 1523 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 1524 | pinfo->frame_qlen); |
| 1525 | if (pinfo->filled & MPATH_INFO_DSN) |
| 1526 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DSN, |
| 1527 | pinfo->dsn); |
| 1528 | if (pinfo->filled & MPATH_INFO_METRIC) |
| 1529 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, |
| 1530 | pinfo->metric); |
| 1531 | if (pinfo->filled & MPATH_INFO_EXPTIME) |
| 1532 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 1533 | pinfo->exptime); |
| 1534 | if (pinfo->filled & MPATH_INFO_FLAGS) |
| 1535 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS, |
| 1536 | pinfo->flags); |
| 1537 | if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) |
| 1538 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 1539 | pinfo->discovery_timeout); |
| 1540 | if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) |
| 1541 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 1542 | pinfo->discovery_retries); |
| 1543 | |
| 1544 | nla_nest_end(msg, pinfoattr); |
| 1545 | |
| 1546 | return genlmsg_end(msg, hdr); |
| 1547 | |
| 1548 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1549 | genlmsg_cancel(msg, hdr); |
| 1550 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1551 | } |
| 1552 | |
| 1553 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1554 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1555 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1556 | struct mpath_info pinfo; |
| 1557 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1558 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1559 | u8 dst[ETH_ALEN]; |
| 1560 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1561 | int ifidx = cb->args[0]; |
| 1562 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1563 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1564 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1565 | if (!ifidx) { |
| 1566 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1567 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 1568 | nl80211_policy); |
| 1569 | if (err) |
| 1570 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1571 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1572 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 1573 | return -EINVAL; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1574 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1575 | ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 1576 | if (!ifidx) |
| 1577 | return -EINVAL; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1578 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1579 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1580 | netdev = dev_get_by_index(&init_net, ifidx); |
| 1581 | if (!netdev) |
| 1582 | return -ENODEV; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1583 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1584 | dev = cfg80211_get_dev_from_ifindex(ifidx); |
| 1585 | if (IS_ERR(dev)) { |
| 1586 | err = PTR_ERR(dev); |
| 1587 | goto out_put_netdev; |
| 1588 | } |
| 1589 | |
| 1590 | if (!dev->ops->dump_mpath) { |
| 1591 | err = -ENOSYS; |
| 1592 | goto out_err; |
| 1593 | } |
| 1594 | |
| 1595 | rtnl_lock(); |
| 1596 | |
| 1597 | while (1) { |
| 1598 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, |
| 1599 | dst, next_hop, &pinfo); |
| 1600 | if (err == -ENOENT) |
| 1601 | break; |
| 1602 | if (err) |
| 1603 | goto out_err_rtnl; |
| 1604 | |
| 1605 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
| 1606 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 1607 | netdev, dst, next_hop, |
| 1608 | &pinfo) < 0) |
| 1609 | goto out; |
| 1610 | |
| 1611 | path_idx++; |
| 1612 | } |
| 1613 | |
| 1614 | |
| 1615 | out: |
| 1616 | cb->args[1] = path_idx; |
| 1617 | err = skb->len; |
| 1618 | out_err_rtnl: |
| 1619 | rtnl_unlock(); |
| 1620 | out_err: |
| 1621 | cfg80211_put_dev(dev); |
| 1622 | out_put_netdev: |
| 1623 | dev_put(netdev); |
| 1624 | |
| 1625 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1626 | } |
| 1627 | |
| 1628 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 1629 | { |
| 1630 | struct cfg80211_registered_device *drv; |
| 1631 | int err; |
| 1632 | struct net_device *dev; |
| 1633 | struct mpath_info pinfo; |
| 1634 | struct sk_buff *msg; |
| 1635 | u8 *dst = NULL; |
| 1636 | u8 next_hop[ETH_ALEN]; |
| 1637 | |
| 1638 | memset(&pinfo, 0, sizeof(pinfo)); |
| 1639 | |
| 1640 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1641 | return -EINVAL; |
| 1642 | |
| 1643 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1644 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1645 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1646 | if (err) |
| 1647 | return err; |
| 1648 | |
| 1649 | if (!drv->ops->get_mpath) { |
| 1650 | err = -EOPNOTSUPP; |
| 1651 | goto out; |
| 1652 | } |
| 1653 | |
| 1654 | rtnl_lock(); |
| 1655 | err = drv->ops->get_mpath(&drv->wiphy, dev, dst, next_hop, &pinfo); |
| 1656 | rtnl_unlock(); |
| 1657 | |
| 1658 | if (err) |
| 1659 | goto out; |
| 1660 | |
| 1661 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 1662 | if (!msg) |
| 1663 | goto out; |
| 1664 | |
| 1665 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, |
| 1666 | dev, dst, next_hop, &pinfo) < 0) |
| 1667 | goto out_free; |
| 1668 | |
| 1669 | err = genlmsg_unicast(msg, info->snd_pid); |
| 1670 | goto out; |
| 1671 | |
| 1672 | out_free: |
| 1673 | nlmsg_free(msg); |
| 1674 | |
| 1675 | out: |
| 1676 | cfg80211_put_dev(drv); |
| 1677 | dev_put(dev); |
| 1678 | return err; |
| 1679 | } |
| 1680 | |
| 1681 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 1682 | { |
| 1683 | struct cfg80211_registered_device *drv; |
| 1684 | int err; |
| 1685 | struct net_device *dev; |
| 1686 | u8 *dst = NULL; |
| 1687 | u8 *next_hop = NULL; |
| 1688 | |
| 1689 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1690 | return -EINVAL; |
| 1691 | |
| 1692 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 1693 | return -EINVAL; |
| 1694 | |
| 1695 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1696 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 1697 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1698 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1699 | if (err) |
| 1700 | return err; |
| 1701 | |
| 1702 | if (!drv->ops->change_mpath) { |
| 1703 | err = -EOPNOTSUPP; |
| 1704 | goto out; |
| 1705 | } |
| 1706 | |
| 1707 | rtnl_lock(); |
| 1708 | err = drv->ops->change_mpath(&drv->wiphy, dev, dst, next_hop); |
| 1709 | rtnl_unlock(); |
| 1710 | |
| 1711 | out: |
| 1712 | cfg80211_put_dev(drv); |
| 1713 | dev_put(dev); |
| 1714 | return err; |
| 1715 | } |
| 1716 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 1717 | { |
| 1718 | struct cfg80211_registered_device *drv; |
| 1719 | int err; |
| 1720 | struct net_device *dev; |
| 1721 | u8 *dst = NULL; |
| 1722 | u8 *next_hop = NULL; |
| 1723 | |
| 1724 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1725 | return -EINVAL; |
| 1726 | |
| 1727 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 1728 | return -EINVAL; |
| 1729 | |
| 1730 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1731 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 1732 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1733 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1734 | if (err) |
| 1735 | return err; |
| 1736 | |
| 1737 | if (!drv->ops->add_mpath) { |
| 1738 | err = -EOPNOTSUPP; |
| 1739 | goto out; |
| 1740 | } |
| 1741 | |
| 1742 | rtnl_lock(); |
| 1743 | err = drv->ops->add_mpath(&drv->wiphy, dev, dst, next_hop); |
| 1744 | rtnl_unlock(); |
| 1745 | |
| 1746 | out: |
| 1747 | cfg80211_put_dev(drv); |
| 1748 | dev_put(dev); |
| 1749 | return err; |
| 1750 | } |
| 1751 | |
| 1752 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 1753 | { |
| 1754 | struct cfg80211_registered_device *drv; |
| 1755 | int err; |
| 1756 | struct net_device *dev; |
| 1757 | u8 *dst = NULL; |
| 1758 | |
| 1759 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1760 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1761 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1762 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1763 | if (err) |
| 1764 | return err; |
| 1765 | |
| 1766 | if (!drv->ops->del_mpath) { |
| 1767 | err = -EOPNOTSUPP; |
| 1768 | goto out; |
| 1769 | } |
| 1770 | |
| 1771 | rtnl_lock(); |
| 1772 | err = drv->ops->del_mpath(&drv->wiphy, dev, dst); |
| 1773 | rtnl_unlock(); |
| 1774 | |
| 1775 | out: |
| 1776 | cfg80211_put_dev(drv); |
| 1777 | dev_put(dev); |
| 1778 | return err; |
| 1779 | } |
| 1780 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1781 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 1782 | { |
| 1783 | struct cfg80211_registered_device *drv; |
| 1784 | int err; |
| 1785 | struct net_device *dev; |
| 1786 | struct bss_parameters params; |
| 1787 | |
| 1788 | memset(¶ms, 0, sizeof(params)); |
| 1789 | /* default to not changing parameters */ |
| 1790 | params.use_cts_prot = -1; |
| 1791 | params.use_short_preamble = -1; |
| 1792 | params.use_short_slot_time = -1; |
| 1793 | |
| 1794 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 1795 | params.use_cts_prot = |
| 1796 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 1797 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 1798 | params.use_short_preamble = |
| 1799 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 1800 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 1801 | params.use_short_slot_time = |
| 1802 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 1803 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 1804 | params.basic_rates = |
| 1805 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 1806 | params.basic_rates_len = |
| 1807 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 1808 | } |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1809 | |
| 1810 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 1811 | if (err) |
| 1812 | return err; |
| 1813 | |
| 1814 | if (!drv->ops->change_bss) { |
| 1815 | err = -EOPNOTSUPP; |
| 1816 | goto out; |
| 1817 | } |
| 1818 | |
| 1819 | rtnl_lock(); |
| 1820 | err = drv->ops->change_bss(&drv->wiphy, dev, ¶ms); |
| 1821 | rtnl_unlock(); |
| 1822 | |
| 1823 | out: |
| 1824 | cfg80211_put_dev(drv); |
| 1825 | dev_put(dev); |
| 1826 | return err; |
| 1827 | } |
| 1828 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1829 | static const struct nla_policy |
| 1830 | reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
| 1831 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 1832 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 1833 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 1834 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 1835 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 1836 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 1837 | }; |
| 1838 | |
| 1839 | static int parse_reg_rule(struct nlattr *tb[], |
| 1840 | struct ieee80211_reg_rule *reg_rule) |
| 1841 | { |
| 1842 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 1843 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 1844 | |
| 1845 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 1846 | return -EINVAL; |
| 1847 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 1848 | return -EINVAL; |
| 1849 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 1850 | return -EINVAL; |
| 1851 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 1852 | return -EINVAL; |
| 1853 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 1854 | return -EINVAL; |
| 1855 | |
| 1856 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 1857 | |
| 1858 | freq_range->start_freq_khz = |
| 1859 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 1860 | freq_range->end_freq_khz = |
| 1861 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 1862 | freq_range->max_bandwidth_khz = |
| 1863 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 1864 | |
| 1865 | power_rule->max_eirp = |
| 1866 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 1867 | |
| 1868 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 1869 | power_rule->max_antenna_gain = |
| 1870 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 1871 | |
| 1872 | return 0; |
| 1873 | } |
| 1874 | |
| 1875 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 1876 | { |
| 1877 | int r; |
| 1878 | char *data = NULL; |
| 1879 | |
| 1880 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 1881 | return -EINVAL; |
| 1882 | |
| 1883 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 1884 | |
| 1885 | #ifdef CONFIG_WIRELESS_OLD_REGULATORY |
| 1886 | /* We ignore world regdom requests with the old regdom setup */ |
| 1887 | if (is_world_regdom(data)) |
| 1888 | return -EINVAL; |
| 1889 | #endif |
| 1890 | mutex_lock(&cfg80211_drv_mutex); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1891 | r = __regulatory_hint(NULL, REGDOM_SET_BY_USER, data, 0, ENVIRON_ANY); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1892 | mutex_unlock(&cfg80211_drv_mutex); |
| 1893 | return r; |
| 1894 | } |
| 1895 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 1896 | static int nl80211_get_mesh_params(struct sk_buff *skb, |
| 1897 | struct genl_info *info) |
| 1898 | { |
| 1899 | struct cfg80211_registered_device *drv; |
| 1900 | struct mesh_config cur_params; |
| 1901 | int err; |
| 1902 | struct net_device *dev; |
| 1903 | void *hdr; |
| 1904 | struct nlattr *pinfoattr; |
| 1905 | struct sk_buff *msg; |
| 1906 | |
| 1907 | /* Look up our device */ |
| 1908 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 1909 | if (err) |
| 1910 | return err; |
| 1911 | |
| 1912 | /* Get the mesh params */ |
| 1913 | rtnl_lock(); |
| 1914 | err = drv->ops->get_mesh_params(&drv->wiphy, dev, &cur_params); |
| 1915 | rtnl_unlock(); |
| 1916 | if (err) |
| 1917 | goto out; |
| 1918 | |
| 1919 | /* Draw up a netlink message to send back */ |
| 1920 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 1921 | if (!msg) { |
| 1922 | err = -ENOBUFS; |
| 1923 | goto out; |
| 1924 | } |
| 1925 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 1926 | NL80211_CMD_GET_MESH_PARAMS); |
| 1927 | if (!hdr) |
| 1928 | goto nla_put_failure; |
| 1929 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_PARAMS); |
| 1930 | if (!pinfoattr) |
| 1931 | goto nla_put_failure; |
| 1932 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1933 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 1934 | cur_params.dot11MeshRetryTimeout); |
| 1935 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 1936 | cur_params.dot11MeshConfirmTimeout); |
| 1937 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 1938 | cur_params.dot11MeshHoldingTimeout); |
| 1939 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 1940 | cur_params.dot11MeshMaxPeerLinks); |
| 1941 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 1942 | cur_params.dot11MeshMaxRetries); |
| 1943 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, |
| 1944 | cur_params.dot11MeshTTL); |
| 1945 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 1946 | cur_params.auto_open_plinks); |
| 1947 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 1948 | cur_params.dot11MeshHWMPmaxPREQretries); |
| 1949 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 1950 | cur_params.path_refresh_time); |
| 1951 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 1952 | cur_params.min_discovery_timeout); |
| 1953 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 1954 | cur_params.dot11MeshHWMPactivePathTimeout); |
| 1955 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 1956 | cur_params.dot11MeshHWMPpreqMinInterval); |
| 1957 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 1958 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); |
| 1959 | nla_nest_end(msg, pinfoattr); |
| 1960 | genlmsg_end(msg, hdr); |
| 1961 | err = genlmsg_unicast(msg, info->snd_pid); |
| 1962 | goto out; |
| 1963 | |
| 1964 | nla_put_failure: |
| 1965 | genlmsg_cancel(msg, hdr); |
| 1966 | err = -EMSGSIZE; |
| 1967 | out: |
| 1968 | /* Cleanup */ |
| 1969 | cfg80211_put_dev(drv); |
| 1970 | dev_put(dev); |
| 1971 | return err; |
| 1972 | } |
| 1973 | |
| 1974 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 1975 | do {\ |
| 1976 | if (table[attr_num]) {\ |
| 1977 | cfg.param = nla_fn(table[attr_num]); \ |
| 1978 | mask |= (1 << (attr_num - 1)); \ |
| 1979 | } \ |
| 1980 | } while (0);\ |
| 1981 | |
| 1982 | static struct nla_policy |
| 1983 | nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] __read_mostly = { |
| 1984 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 1985 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 1986 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 1987 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 1988 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 1989 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
| 1990 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
| 1991 | |
| 1992 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 1993 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 1994 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 1995 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 1996 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
| 1997 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
| 1998 | }; |
| 1999 | |
| 2000 | static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info) |
| 2001 | { |
| 2002 | int err; |
| 2003 | u32 mask; |
| 2004 | struct cfg80211_registered_device *drv; |
| 2005 | struct net_device *dev; |
| 2006 | struct mesh_config cfg; |
| 2007 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
| 2008 | struct nlattr *parent_attr; |
| 2009 | |
| 2010 | parent_attr = info->attrs[NL80211_ATTR_MESH_PARAMS]; |
| 2011 | if (!parent_attr) |
| 2012 | return -EINVAL; |
| 2013 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
| 2014 | parent_attr, nl80211_meshconf_params_policy)) |
| 2015 | return -EINVAL; |
| 2016 | |
| 2017 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 2018 | if (err) |
| 2019 | return err; |
| 2020 | |
| 2021 | /* This makes sure that there aren't more than 32 mesh config |
| 2022 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 2023 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 2024 | |
| 2025 | /* Fill in the params struct */ |
| 2026 | mask = 0; |
| 2027 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
| 2028 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 2029 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
| 2030 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); |
| 2031 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
| 2032 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); |
| 2033 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
| 2034 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); |
| 2035 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
| 2036 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 2037 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
| 2038 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
| 2039 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
| 2040 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); |
| 2041 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
| 2042 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 2043 | nla_get_u8); |
| 2044 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
| 2045 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); |
| 2046 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
| 2047 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 2048 | nla_get_u16); |
| 2049 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 2050 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 2051 | nla_get_u32); |
| 2052 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
| 2053 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 2054 | nla_get_u16); |
| 2055 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 2056 | dot11MeshHWMPnetDiameterTraversalTime, |
| 2057 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 2058 | nla_get_u16); |
| 2059 | |
| 2060 | /* Apply changes */ |
| 2061 | rtnl_lock(); |
| 2062 | err = drv->ops->set_mesh_params(&drv->wiphy, dev, &cfg, mask); |
| 2063 | rtnl_unlock(); |
| 2064 | |
| 2065 | /* cleanup */ |
| 2066 | cfg80211_put_dev(drv); |
| 2067 | dev_put(dev); |
| 2068 | return err; |
| 2069 | } |
| 2070 | |
| 2071 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 2072 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2073 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 2074 | { |
| 2075 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 2076 | struct nlattr *nl_reg_rule; |
| 2077 | char *alpha2 = NULL; |
| 2078 | int rem_reg_rules = 0, r = 0; |
| 2079 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
| 2080 | struct ieee80211_regdomain *rd = NULL; |
| 2081 | |
| 2082 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 2083 | return -EINVAL; |
| 2084 | |
| 2085 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 2086 | return -EINVAL; |
| 2087 | |
| 2088 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 2089 | |
| 2090 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 2091 | rem_reg_rules) { |
| 2092 | num_rules++; |
| 2093 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
| 2094 | goto bad_reg; |
| 2095 | } |
| 2096 | |
| 2097 | if (!reg_is_valid_request(alpha2)) |
| 2098 | return -EINVAL; |
| 2099 | |
| 2100 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 2101 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 2102 | |
| 2103 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
| 2104 | if (!rd) |
| 2105 | return -ENOMEM; |
| 2106 | |
| 2107 | rd->n_reg_rules = num_rules; |
| 2108 | rd->alpha2[0] = alpha2[0]; |
| 2109 | rd->alpha2[1] = alpha2[1]; |
| 2110 | |
| 2111 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 2112 | rem_reg_rules) { |
| 2113 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 2114 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 2115 | reg_rule_policy); |
| 2116 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 2117 | if (r) |
| 2118 | goto bad_reg; |
| 2119 | |
| 2120 | rule_idx++; |
| 2121 | |
| 2122 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) |
| 2123 | goto bad_reg; |
| 2124 | } |
| 2125 | |
| 2126 | BUG_ON(rule_idx != num_rules); |
| 2127 | |
| 2128 | mutex_lock(&cfg80211_drv_mutex); |
| 2129 | r = set_regdom(rd); |
| 2130 | mutex_unlock(&cfg80211_drv_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2131 | return r; |
| 2132 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 2133 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2134 | kfree(rd); |
| 2135 | return -EINVAL; |
| 2136 | } |
| 2137 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2138 | static struct genl_ops nl80211_ops[] = { |
| 2139 | { |
| 2140 | .cmd = NL80211_CMD_GET_WIPHY, |
| 2141 | .doit = nl80211_get_wiphy, |
| 2142 | .dumpit = nl80211_dump_wiphy, |
| 2143 | .policy = nl80211_policy, |
| 2144 | /* can be retrieved by unprivileged users */ |
| 2145 | }, |
| 2146 | { |
| 2147 | .cmd = NL80211_CMD_SET_WIPHY, |
| 2148 | .doit = nl80211_set_wiphy, |
| 2149 | .policy = nl80211_policy, |
| 2150 | .flags = GENL_ADMIN_PERM, |
| 2151 | }, |
| 2152 | { |
| 2153 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 2154 | .doit = nl80211_get_interface, |
| 2155 | .dumpit = nl80211_dump_interface, |
| 2156 | .policy = nl80211_policy, |
| 2157 | /* can be retrieved by unprivileged users */ |
| 2158 | }, |
| 2159 | { |
| 2160 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 2161 | .doit = nl80211_set_interface, |
| 2162 | .policy = nl80211_policy, |
| 2163 | .flags = GENL_ADMIN_PERM, |
| 2164 | }, |
| 2165 | { |
| 2166 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 2167 | .doit = nl80211_new_interface, |
| 2168 | .policy = nl80211_policy, |
| 2169 | .flags = GENL_ADMIN_PERM, |
| 2170 | }, |
| 2171 | { |
| 2172 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 2173 | .doit = nl80211_del_interface, |
| 2174 | .policy = nl80211_policy, |
| 2175 | .flags = GENL_ADMIN_PERM, |
| 2176 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 2177 | { |
| 2178 | .cmd = NL80211_CMD_GET_KEY, |
| 2179 | .doit = nl80211_get_key, |
| 2180 | .policy = nl80211_policy, |
| 2181 | .flags = GENL_ADMIN_PERM, |
| 2182 | }, |
| 2183 | { |
| 2184 | .cmd = NL80211_CMD_SET_KEY, |
| 2185 | .doit = nl80211_set_key, |
| 2186 | .policy = nl80211_policy, |
| 2187 | .flags = GENL_ADMIN_PERM, |
| 2188 | }, |
| 2189 | { |
| 2190 | .cmd = NL80211_CMD_NEW_KEY, |
| 2191 | .doit = nl80211_new_key, |
| 2192 | .policy = nl80211_policy, |
| 2193 | .flags = GENL_ADMIN_PERM, |
| 2194 | }, |
| 2195 | { |
| 2196 | .cmd = NL80211_CMD_DEL_KEY, |
| 2197 | .doit = nl80211_del_key, |
| 2198 | .policy = nl80211_policy, |
| 2199 | .flags = GENL_ADMIN_PERM, |
| 2200 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2201 | { |
| 2202 | .cmd = NL80211_CMD_SET_BEACON, |
| 2203 | .policy = nl80211_policy, |
| 2204 | .flags = GENL_ADMIN_PERM, |
| 2205 | .doit = nl80211_addset_beacon, |
| 2206 | }, |
| 2207 | { |
| 2208 | .cmd = NL80211_CMD_NEW_BEACON, |
| 2209 | .policy = nl80211_policy, |
| 2210 | .flags = GENL_ADMIN_PERM, |
| 2211 | .doit = nl80211_addset_beacon, |
| 2212 | }, |
| 2213 | { |
| 2214 | .cmd = NL80211_CMD_DEL_BEACON, |
| 2215 | .policy = nl80211_policy, |
| 2216 | .flags = GENL_ADMIN_PERM, |
| 2217 | .doit = nl80211_del_beacon, |
| 2218 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2219 | { |
| 2220 | .cmd = NL80211_CMD_GET_STATION, |
| 2221 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2222 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2223 | .policy = nl80211_policy, |
| 2224 | .flags = GENL_ADMIN_PERM, |
| 2225 | }, |
| 2226 | { |
| 2227 | .cmd = NL80211_CMD_SET_STATION, |
| 2228 | .doit = nl80211_set_station, |
| 2229 | .policy = nl80211_policy, |
| 2230 | .flags = GENL_ADMIN_PERM, |
| 2231 | }, |
| 2232 | { |
| 2233 | .cmd = NL80211_CMD_NEW_STATION, |
| 2234 | .doit = nl80211_new_station, |
| 2235 | .policy = nl80211_policy, |
| 2236 | .flags = GENL_ADMIN_PERM, |
| 2237 | }, |
| 2238 | { |
| 2239 | .cmd = NL80211_CMD_DEL_STATION, |
| 2240 | .doit = nl80211_del_station, |
| 2241 | .policy = nl80211_policy, |
| 2242 | .flags = GENL_ADMIN_PERM, |
| 2243 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2244 | { |
| 2245 | .cmd = NL80211_CMD_GET_MPATH, |
| 2246 | .doit = nl80211_get_mpath, |
| 2247 | .dumpit = nl80211_dump_mpath, |
| 2248 | .policy = nl80211_policy, |
| 2249 | .flags = GENL_ADMIN_PERM, |
| 2250 | }, |
| 2251 | { |
| 2252 | .cmd = NL80211_CMD_SET_MPATH, |
| 2253 | .doit = nl80211_set_mpath, |
| 2254 | .policy = nl80211_policy, |
| 2255 | .flags = GENL_ADMIN_PERM, |
| 2256 | }, |
| 2257 | { |
| 2258 | .cmd = NL80211_CMD_NEW_MPATH, |
| 2259 | .doit = nl80211_new_mpath, |
| 2260 | .policy = nl80211_policy, |
| 2261 | .flags = GENL_ADMIN_PERM, |
| 2262 | }, |
| 2263 | { |
| 2264 | .cmd = NL80211_CMD_DEL_MPATH, |
| 2265 | .doit = nl80211_del_mpath, |
| 2266 | .policy = nl80211_policy, |
| 2267 | .flags = GENL_ADMIN_PERM, |
| 2268 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2269 | { |
| 2270 | .cmd = NL80211_CMD_SET_BSS, |
| 2271 | .doit = nl80211_set_bss, |
| 2272 | .policy = nl80211_policy, |
| 2273 | .flags = GENL_ADMIN_PERM, |
| 2274 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2275 | { |
| 2276 | .cmd = NL80211_CMD_SET_REG, |
| 2277 | .doit = nl80211_set_reg, |
| 2278 | .policy = nl80211_policy, |
| 2279 | .flags = GENL_ADMIN_PERM, |
| 2280 | }, |
| 2281 | { |
| 2282 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 2283 | .doit = nl80211_req_set_reg, |
| 2284 | .policy = nl80211_policy, |
| 2285 | .flags = GENL_ADMIN_PERM, |
| 2286 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2287 | { |
| 2288 | .cmd = NL80211_CMD_GET_MESH_PARAMS, |
| 2289 | .doit = nl80211_get_mesh_params, |
| 2290 | .policy = nl80211_policy, |
| 2291 | /* can be retrieved by unprivileged users */ |
| 2292 | }, |
| 2293 | { |
| 2294 | .cmd = NL80211_CMD_SET_MESH_PARAMS, |
| 2295 | .doit = nl80211_set_mesh_params, |
| 2296 | .policy = nl80211_policy, |
| 2297 | .flags = GENL_ADMIN_PERM, |
| 2298 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2299 | }; |
| 2300 | |
| 2301 | /* multicast groups */ |
| 2302 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 2303 | .name = "config", |
| 2304 | }; |
| 2305 | |
| 2306 | /* notification functions */ |
| 2307 | |
| 2308 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 2309 | { |
| 2310 | struct sk_buff *msg; |
| 2311 | |
| 2312 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 2313 | if (!msg) |
| 2314 | return; |
| 2315 | |
| 2316 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 2317 | nlmsg_free(msg); |
| 2318 | return; |
| 2319 | } |
| 2320 | |
| 2321 | genlmsg_multicast(msg, 0, nl80211_config_mcgrp.id, GFP_KERNEL); |
| 2322 | } |
| 2323 | |
| 2324 | /* initialisation/exit functions */ |
| 2325 | |
| 2326 | int nl80211_init(void) |
| 2327 | { |
| 2328 | int err, i; |
| 2329 | |
| 2330 | err = genl_register_family(&nl80211_fam); |
| 2331 | if (err) |
| 2332 | return err; |
| 2333 | |
| 2334 | for (i = 0; i < ARRAY_SIZE(nl80211_ops); i++) { |
| 2335 | err = genl_register_ops(&nl80211_fam, &nl80211_ops[i]); |
| 2336 | if (err) |
| 2337 | goto err_out; |
| 2338 | } |
| 2339 | |
| 2340 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 2341 | if (err) |
| 2342 | goto err_out; |
| 2343 | |
| 2344 | return 0; |
| 2345 | err_out: |
| 2346 | genl_unregister_family(&nl80211_fam); |
| 2347 | return err; |
| 2348 | } |
| 2349 | |
| 2350 | void nl80211_exit(void) |
| 2351 | { |
| 2352 | genl_unregister_family(&nl80211_fam); |
| 2353 | } |