2 * This is the new netlink-based wireless configuration interface.
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
8 #include <linux/module.h>
10 #include <linux/slab.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 <linux/etherdevice.h>
18 #include <net/net_namespace.h>
19 #include <net/genetlink.h>
20 #include <net/cfg80211.h>
26 /* the netlink family */
27 static struct genl_family nl80211_fam
= {
28 .id
= GENL_ID_GENERATE
, /* don't bother with a hardcoded ID */
29 .name
= "nl80211", /* have users key off the name instead */
30 .hdrsize
= 0, /* no private header */
31 .version
= 1, /* no particular meaning now */
32 .maxattr
= NL80211_ATTR_MAX
,
36 /* internal helper: get rdev and dev */
37 static int get_rdev_dev_by_info_ifindex(struct genl_info
*info
,
38 struct cfg80211_registered_device
**rdev
,
39 struct net_device
**dev
)
41 struct nlattr
**attrs
= info
->attrs
;
44 if (!attrs
[NL80211_ATTR_IFINDEX
])
47 ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
48 *dev
= dev_get_by_index(genl_info_net(info
), ifindex
);
52 *rdev
= cfg80211_get_dev_from_ifindex(genl_info_net(info
), ifindex
);
55 return PTR_ERR(*rdev
);
61 /* policy for the attributes */
62 static const struct nla_policy nl80211_policy
[NL80211_ATTR_MAX
+1] = {
63 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
64 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
66 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
67 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
68 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
69 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
70 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
71 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
72 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
73 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
75 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
76 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
77 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
79 [NL80211_ATTR_MAC
] = { .type
= NLA_BINARY
, .len
= ETH_ALEN
},
80 [NL80211_ATTR_PREV_BSSID
] = { .type
= NLA_BINARY
, .len
= ETH_ALEN
},
82 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
83 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
84 .len
= WLAN_MAX_KEY_LEN
},
85 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
86 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
87 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
88 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 8 },
90 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
91 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
92 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
93 .len
= IEEE80211_MAX_DATA_LEN
},
94 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
95 .len
= IEEE80211_MAX_DATA_LEN
},
96 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
97 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
98 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
99 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
100 .len
= NL80211_MAX_SUPP_RATES
},
101 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
102 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
103 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
104 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
105 .len
= IEEE80211_MAX_MESH_ID_LEN
},
106 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
108 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
109 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
111 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
112 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
113 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
114 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
115 .len
= NL80211_MAX_SUPP_RATES
},
117 [NL80211_ATTR_MESH_PARAMS
] = { .type
= NLA_NESTED
},
119 [NL80211_ATTR_HT_CAPABILITY
] = { .type
= NLA_BINARY
,
120 .len
= NL80211_HT_CAPABILITY_LEN
},
122 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
123 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
124 .len
= IEEE80211_MAX_DATA_LEN
},
125 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
126 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
128 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
129 .len
= IEEE80211_MAX_SSID_LEN
},
130 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
131 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
132 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
133 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
134 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
135 [NL80211_ATTR_STA_FLAGS2
] = {
136 .len
= sizeof(struct nl80211_sta_flag_update
),
138 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
139 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
140 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
141 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
142 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
143 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
144 [NL80211_ATTR_PMKID
] = { .type
= NLA_BINARY
,
145 .len
= WLAN_PMKID_LEN
},
146 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
147 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
148 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
149 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
150 .len
= IEEE80211_MAX_DATA_LEN
},
151 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
152 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
153 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
154 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
155 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
158 /* policy for the attributes */
159 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
160 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
161 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
162 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
163 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 8 },
164 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
165 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
168 /* ifidx get helper */
169 static int nl80211_get_ifidx(struct netlink_callback
*cb
)
173 res
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
174 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
179 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
182 res
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
189 static bool is_valid_ie_attr(const struct nlattr
*attr
)
197 pos
= nla_data(attr
);
218 /* message building helper */
219 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 pid
, u32 seq
,
222 /* since there is no private header just add the generic one */
223 return genlmsg_put(skb
, pid
, seq
, &nl80211_fam
, flags
, cmd
);
226 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
227 struct ieee80211_channel
*chan
)
229 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
232 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
233 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_DISABLED
);
234 if (chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
235 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
);
236 if (chan
->flags
& IEEE80211_CHAN_NO_IBSS
)
237 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
);
238 if (chan
->flags
& IEEE80211_CHAN_RADAR
)
239 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_RADAR
);
241 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
242 DBM_TO_MBM(chan
->max_power
));
250 /* netlink command implementations */
258 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
260 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
261 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
266 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
267 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
269 if (tb
[NL80211_KEY_IDX
])
270 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
272 if (tb
[NL80211_KEY_DATA
]) {
273 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
274 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
277 if (tb
[NL80211_KEY_SEQ
]) {
278 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
279 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
282 if (tb
[NL80211_KEY_CIPHER
])
283 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
288 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
290 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
291 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
292 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
295 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
296 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
297 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
300 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
301 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
303 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
304 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
306 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
307 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
312 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
316 memset(k
, 0, sizeof(*k
));
319 if (info
->attrs
[NL80211_ATTR_KEY
])
320 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
322 err
= nl80211_parse_key_old(info
, k
);
327 if (k
->def
&& k
->defmgmt
)
332 if (k
->idx
< 4 || k
->idx
> 5)
335 if (k
->idx
< 0 || k
->idx
> 3)
338 if (k
->idx
< 0 || k
->idx
> 5)
346 static struct cfg80211_cached_keys
*
347 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
350 struct key_parse parse
;
352 struct cfg80211_cached_keys
*result
;
353 int rem
, err
, def
= 0;
355 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
357 return ERR_PTR(-ENOMEM
);
360 result
->defmgmt
= -1;
362 nla_for_each_nested(key
, keys
, rem
) {
363 memset(&parse
, 0, sizeof(parse
));
366 err
= nl80211_parse_key_new(key
, &parse
);
372 if (parse
.idx
< 0 || parse
.idx
> 4)
378 result
->def
= parse
.idx
;
379 } else if (parse
.defmgmt
)
381 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
385 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
386 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
387 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
388 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
397 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
399 ASSERT_WDEV_LOCK(wdev
);
401 if (!netif_running(wdev
->netdev
))
404 switch (wdev
->iftype
) {
405 case NL80211_IFTYPE_AP
:
406 case NL80211_IFTYPE_AP_VLAN
:
408 case NL80211_IFTYPE_ADHOC
:
409 if (!wdev
->current_bss
)
412 case NL80211_IFTYPE_STATION
:
413 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
423 static int nl80211_send_wiphy(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
424 struct cfg80211_registered_device
*dev
)
427 struct nlattr
*nl_bands
, *nl_band
;
428 struct nlattr
*nl_freqs
, *nl_freq
;
429 struct nlattr
*nl_rates
, *nl_rate
;
430 struct nlattr
*nl_modes
;
431 struct nlattr
*nl_cmds
;
432 enum ieee80211_band band
;
433 struct ieee80211_channel
*chan
;
434 struct ieee80211_rate
*rate
;
436 u16 ifmodes
= dev
->wiphy
.interface_modes
;
438 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
442 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
);
443 NLA_PUT_STRING(msg
, NL80211_ATTR_WIPHY_NAME
, wiphy_name(&dev
->wiphy
));
445 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
446 cfg80211_rdev_list_generation
);
448 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
449 dev
->wiphy
.retry_short
);
450 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
451 dev
->wiphy
.retry_long
);
452 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
453 dev
->wiphy
.frag_threshold
);
454 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
455 dev
->wiphy
.rts_threshold
);
456 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
457 dev
->wiphy
.coverage_class
);
459 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
460 dev
->wiphy
.max_scan_ssids
);
461 NLA_PUT_U16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
462 dev
->wiphy
.max_scan_ie_len
);
464 NLA_PUT(msg
, NL80211_ATTR_CIPHER_SUITES
,
465 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
466 dev
->wiphy
.cipher_suites
);
468 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
469 dev
->wiphy
.max_num_pmkids
);
471 nl_modes
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
);
473 goto nla_put_failure
;
478 NLA_PUT_FLAG(msg
, i
);
483 nla_nest_end(msg
, nl_modes
);
485 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
487 goto nla_put_failure
;
489 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
490 if (!dev
->wiphy
.bands
[band
])
493 nl_band
= nla_nest_start(msg
, band
);
495 goto nla_put_failure
;
498 if (dev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
) {
499 NLA_PUT(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
500 sizeof(dev
->wiphy
.bands
[band
]->ht_cap
.mcs
),
501 &dev
->wiphy
.bands
[band
]->ht_cap
.mcs
);
502 NLA_PUT_U16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
503 dev
->wiphy
.bands
[band
]->ht_cap
.cap
);
504 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
505 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_factor
);
506 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
507 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_density
);
510 /* add frequencies */
511 nl_freqs
= nla_nest_start(msg
, NL80211_BAND_ATTR_FREQS
);
513 goto nla_put_failure
;
515 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_channels
; i
++) {
516 nl_freq
= nla_nest_start(msg
, i
);
518 goto nla_put_failure
;
520 chan
= &dev
->wiphy
.bands
[band
]->channels
[i
];
522 if (nl80211_msg_put_channel(msg
, chan
))
523 goto nla_put_failure
;
525 nla_nest_end(msg
, nl_freq
);
528 nla_nest_end(msg
, nl_freqs
);
531 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
533 goto nla_put_failure
;
535 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_bitrates
; i
++) {
536 nl_rate
= nla_nest_start(msg
, i
);
538 goto nla_put_failure
;
540 rate
= &dev
->wiphy
.bands
[band
]->bitrates
[i
];
541 NLA_PUT_U32(msg
, NL80211_BITRATE_ATTR_RATE
,
543 if (rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
)
545 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
);
547 nla_nest_end(msg
, nl_rate
);
550 nla_nest_end(msg
, nl_rates
);
552 nla_nest_end(msg
, nl_band
);
554 nla_nest_end(msg
, nl_bands
);
556 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
558 goto nla_put_failure
;
563 if (dev->ops->op) { \
565 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
569 CMD(add_virtual_intf
, NEW_INTERFACE
);
570 CMD(change_virtual_intf
, SET_INTERFACE
);
571 CMD(add_key
, NEW_KEY
);
572 CMD(add_beacon
, NEW_BEACON
);
573 CMD(add_station
, NEW_STATION
);
574 CMD(add_mpath
, NEW_MPATH
);
575 CMD(set_mesh_params
, SET_MESH_PARAMS
);
576 CMD(change_bss
, SET_BSS
);
577 CMD(auth
, AUTHENTICATE
);
578 CMD(assoc
, ASSOCIATE
);
579 CMD(deauth
, DEAUTHENTICATE
);
580 CMD(disassoc
, DISASSOCIATE
);
581 CMD(join_ibss
, JOIN_IBSS
);
582 CMD(set_pmksa
, SET_PMKSA
);
583 CMD(del_pmksa
, DEL_PMKSA
);
584 CMD(flush_pmksa
, FLUSH_PMKSA
);
585 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
586 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
588 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
590 NLA_PUT_U32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
);
592 CMD(set_channel
, SET_CHANNEL
);
596 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
598 NLA_PUT_U32(msg
, i
, NL80211_CMD_CONNECT
);
601 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
603 NLA_PUT_U32(msg
, i
, NL80211_CMD_DISCONNECT
);
606 nla_nest_end(msg
, nl_cmds
);
608 return genlmsg_end(msg
, hdr
);
611 genlmsg_cancel(msg
, hdr
);
615 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
618 int start
= cb
->args
[0];
619 struct cfg80211_registered_device
*dev
;
621 mutex_lock(&cfg80211_mutex
);
622 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
623 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
627 if (nl80211_send_wiphy(skb
, NETLINK_CB(cb
->skb
).pid
,
628 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
634 mutex_unlock(&cfg80211_mutex
);
641 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
644 struct cfg80211_registered_device
*dev
;
646 dev
= cfg80211_get_dev_from_info(info
);
650 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
654 if (nl80211_send_wiphy(msg
, info
->snd_pid
, info
->snd_seq
, 0, dev
) < 0)
657 cfg80211_unlock_rdev(dev
);
659 return genlmsg_reply(msg
, info
);
664 cfg80211_unlock_rdev(dev
);
668 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
669 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
670 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
671 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
672 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
673 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
676 static int parse_txq_params(struct nlattr
*tb
[],
677 struct ieee80211_txq_params
*txq_params
)
679 if (!tb
[NL80211_TXQ_ATTR_QUEUE
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
680 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
681 !tb
[NL80211_TXQ_ATTR_AIFS
])
684 txq_params
->queue
= nla_get_u8(tb
[NL80211_TXQ_ATTR_QUEUE
]);
685 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
686 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
687 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
688 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
693 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
696 * You can only set the channel explicitly for AP, mesh
697 * and WDS type interfaces; all others have their channel
698 * managed via their respective "establish a connection"
699 * command (connect, join, ...)
701 * Monitors are special as they are normally slaved to
702 * whatever else is going on, so they behave as though
703 * you tried setting the wiphy channel itself.
706 wdev
->iftype
== NL80211_IFTYPE_AP
||
707 wdev
->iftype
== NL80211_IFTYPE_WDS
||
708 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
709 wdev
->iftype
== NL80211_IFTYPE_MONITOR
;
712 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
713 struct wireless_dev
*wdev
,
714 struct genl_info
*info
)
716 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
720 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
723 if (!nl80211_can_set_dev_channel(wdev
))
726 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
727 channel_type
= nla_get_u32(info
->attrs
[
728 NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
729 if (channel_type
!= NL80211_CHAN_NO_HT
&&
730 channel_type
!= NL80211_CHAN_HT20
&&
731 channel_type
!= NL80211_CHAN_HT40PLUS
&&
732 channel_type
!= NL80211_CHAN_HT40MINUS
)
736 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
738 mutex_lock(&rdev
->devlist_mtx
);
741 result
= cfg80211_set_freq(rdev
, wdev
, freq
, channel_type
);
744 result
= cfg80211_set_freq(rdev
, NULL
, freq
, channel_type
);
746 mutex_unlock(&rdev
->devlist_mtx
);
751 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
753 struct cfg80211_registered_device
*rdev
;
754 struct net_device
*netdev
;
759 result
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &netdev
);
763 result
= __nl80211_set_channel(rdev
, netdev
->ieee80211_ptr
, info
);
766 cfg80211_unlock_rdev(rdev
);
773 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
775 struct cfg80211_registered_device
*rdev
;
776 struct net_device
*netdev
= NULL
;
777 struct wireless_dev
*wdev
;
778 int result
, rem_txq_params
= 0;
779 struct nlattr
*nl_txq_params
;
781 u8 retry_short
= 0, retry_long
= 0;
782 u32 frag_threshold
= 0, rts_threshold
= 0;
783 u8 coverage_class
= 0;
788 * Try to find the wiphy and netdev. Normally this
789 * function shouldn't need the netdev, but this is
790 * done for backward compatibility -- previously
791 * setting the channel was done per wiphy, but now
792 * it is per netdev. Previous userland like hostapd
793 * also passed a netdev to set_wiphy, so that it is
794 * possible to let that go to the right netdev!
796 mutex_lock(&cfg80211_mutex
);
798 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
799 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
801 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
802 if (netdev
&& netdev
->ieee80211_ptr
) {
803 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
804 mutex_lock(&rdev
->mtx
);
810 rdev
= __cfg80211_rdev_from_info(info
);
812 mutex_unlock(&cfg80211_mutex
);
813 result
= PTR_ERR(rdev
);
820 mutex_lock(&rdev
->mtx
);
821 } else if (netif_running(netdev
) &&
822 nl80211_can_set_dev_channel(netdev
->ieee80211_ptr
))
823 wdev
= netdev
->ieee80211_ptr
;
828 * end workaround code, by now the rdev is available
829 * and locked, and wdev may or may not be NULL.
832 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
833 result
= cfg80211_dev_rename(
834 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
836 mutex_unlock(&cfg80211_mutex
);
841 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
842 struct ieee80211_txq_params txq_params
;
843 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
845 if (!rdev
->ops
->set_txq_params
) {
846 result
= -EOPNOTSUPP
;
850 nla_for_each_nested(nl_txq_params
,
851 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
853 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
854 nla_data(nl_txq_params
),
855 nla_len(nl_txq_params
),
857 result
= parse_txq_params(tb
, &txq_params
);
861 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
868 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
869 result
= __nl80211_set_channel(rdev
, wdev
, info
);
876 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
877 retry_short
= nla_get_u8(
878 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
879 if (retry_short
== 0) {
883 changed
|= WIPHY_PARAM_RETRY_SHORT
;
886 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
887 retry_long
= nla_get_u8(
888 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
889 if (retry_long
== 0) {
893 changed
|= WIPHY_PARAM_RETRY_LONG
;
896 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
897 frag_threshold
= nla_get_u32(
898 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
899 if (frag_threshold
< 256) {
903 if (frag_threshold
!= (u32
) -1) {
905 * Fragments (apart from the last one) are required to
906 * have even length. Make the fragmentation code
907 * simpler by stripping LSB should someone try to use
908 * odd threshold value.
910 frag_threshold
&= ~0x1;
912 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
915 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
916 rts_threshold
= nla_get_u32(
917 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
918 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
921 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
922 coverage_class
= nla_get_u8(
923 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
924 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
928 u8 old_retry_short
, old_retry_long
;
929 u32 old_frag_threshold
, old_rts_threshold
;
930 u8 old_coverage_class
;
932 if (!rdev
->ops
->set_wiphy_params
) {
933 result
= -EOPNOTSUPP
;
937 old_retry_short
= rdev
->wiphy
.retry_short
;
938 old_retry_long
= rdev
->wiphy
.retry_long
;
939 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
940 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
941 old_coverage_class
= rdev
->wiphy
.coverage_class
;
943 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
944 rdev
->wiphy
.retry_short
= retry_short
;
945 if (changed
& WIPHY_PARAM_RETRY_LONG
)
946 rdev
->wiphy
.retry_long
= retry_long
;
947 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
948 rdev
->wiphy
.frag_threshold
= frag_threshold
;
949 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
950 rdev
->wiphy
.rts_threshold
= rts_threshold
;
951 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
952 rdev
->wiphy
.coverage_class
= coverage_class
;
954 result
= rdev
->ops
->set_wiphy_params(&rdev
->wiphy
, changed
);
956 rdev
->wiphy
.retry_short
= old_retry_short
;
957 rdev
->wiphy
.retry_long
= old_retry_long
;
958 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
959 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
960 rdev
->wiphy
.coverage_class
= old_coverage_class
;
965 mutex_unlock(&rdev
->mtx
);
974 static int nl80211_send_iface(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
975 struct cfg80211_registered_device
*rdev
,
976 struct net_device
*dev
)
980 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
984 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
985 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
986 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, dev
->name
);
987 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, dev
->ieee80211_ptr
->iftype
);
989 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
990 rdev
->devlist_generation
^
991 (cfg80211_rdev_list_generation
<< 2));
993 return genlmsg_end(msg
, hdr
);
996 genlmsg_cancel(msg
, hdr
);
1000 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1004 int wp_start
= cb
->args
[0];
1005 int if_start
= cb
->args
[1];
1006 struct cfg80211_registered_device
*rdev
;
1007 struct wireless_dev
*wdev
;
1009 mutex_lock(&cfg80211_mutex
);
1010 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
1011 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
1013 if (wp_idx
< wp_start
) {
1019 mutex_lock(&rdev
->devlist_mtx
);
1020 list_for_each_entry(wdev
, &rdev
->netdev_list
, list
) {
1021 if (if_idx
< if_start
) {
1025 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).pid
,
1026 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1027 rdev
, wdev
->netdev
) < 0) {
1028 mutex_unlock(&rdev
->devlist_mtx
);
1033 mutex_unlock(&rdev
->devlist_mtx
);
1038 mutex_unlock(&cfg80211_mutex
);
1040 cb
->args
[0] = wp_idx
;
1041 cb
->args
[1] = if_idx
;
1046 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1048 struct sk_buff
*msg
;
1049 struct cfg80211_registered_device
*dev
;
1050 struct net_device
*netdev
;
1053 err
= get_rdev_dev_by_info_ifindex(info
, &dev
, &netdev
);
1057 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1061 if (nl80211_send_iface(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1066 cfg80211_unlock_rdev(dev
);
1068 return genlmsg_reply(msg
, info
);
1074 cfg80211_unlock_rdev(dev
);
1078 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
1079 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
1080 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
1081 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
1082 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
1083 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
1086 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
1088 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
1096 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
1097 nla
, mntr_flags_policy
))
1100 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
1102 *mntrflags
|= (1<<flag
);
1107 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
1108 struct net_device
*netdev
, u8 use_4addr
,
1109 enum nl80211_iftype iftype
)
1112 if (netdev
&& netdev
->br_port
)
1118 case NL80211_IFTYPE_AP_VLAN
:
1119 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
1122 case NL80211_IFTYPE_STATION
:
1123 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
1133 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1135 struct cfg80211_registered_device
*rdev
;
1136 struct vif_params params
;
1138 enum nl80211_iftype otype
, ntype
;
1139 struct net_device
*dev
;
1140 u32 _flags
, *flags
= NULL
;
1141 bool change
= false;
1143 memset(¶ms
, 0, sizeof(params
));
1147 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1151 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
1153 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1154 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1157 if (ntype
> NL80211_IFTYPE_MAX
) {
1163 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1164 if (ntype
!= NL80211_IFTYPE_MESH_POINT
) {
1168 params
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1169 params
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1173 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1174 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1176 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
1180 params
.use_4addr
= -1;
1183 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
1184 if (ntype
!= NL80211_IFTYPE_MONITOR
) {
1188 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
1198 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
1202 if (!err
&& params
.use_4addr
!= -1)
1203 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
1207 cfg80211_unlock_rdev(rdev
);
1213 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1215 struct cfg80211_registered_device
*rdev
;
1216 struct vif_params params
;
1218 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
1221 memset(¶ms
, 0, sizeof(params
));
1223 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
1226 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1227 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1228 if (type
> NL80211_IFTYPE_MAX
)
1234 rdev
= cfg80211_get_dev_from_info(info
);
1236 err
= PTR_ERR(rdev
);
1240 if (!rdev
->ops
->add_virtual_intf
||
1241 !(rdev
->wiphy
.interface_modes
& (1 << type
))) {
1246 if (type
== NL80211_IFTYPE_MESH_POINT
&&
1247 info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1248 params
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1249 params
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1252 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1253 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1254 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
1259 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
1260 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
1262 err
= rdev
->ops
->add_virtual_intf(&rdev
->wiphy
,
1263 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
1264 type
, err
? NULL
: &flags
, ¶ms
);
1267 cfg80211_unlock_rdev(rdev
);
1273 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1275 struct cfg80211_registered_device
*rdev
;
1277 struct net_device
*dev
;
1281 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1285 if (!rdev
->ops
->del_virtual_intf
) {
1290 err
= rdev
->ops
->del_virtual_intf(&rdev
->wiphy
, dev
);
1293 cfg80211_unlock_rdev(rdev
);
1300 struct get_key_cookie
{
1301 struct sk_buff
*msg
;
1306 static void get_key_callback(void *c
, struct key_params
*params
)
1309 struct get_key_cookie
*cookie
= c
;
1312 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
1313 params
->key_len
, params
->key
);
1316 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
1317 params
->seq_len
, params
->seq
);
1320 NLA_PUT_U32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
1323 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
1325 goto nla_put_failure
;
1328 NLA_PUT(cookie
->msg
, NL80211_KEY_DATA
,
1329 params
->key_len
, params
->key
);
1332 NLA_PUT(cookie
->msg
, NL80211_KEY_SEQ
,
1333 params
->seq_len
, params
->seq
);
1336 NLA_PUT_U32(cookie
->msg
, NL80211_KEY_CIPHER
,
1339 NLA_PUT_U8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
);
1341 nla_nest_end(cookie
->msg
, key
);
1348 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
1350 struct cfg80211_registered_device
*rdev
;
1352 struct net_device
*dev
;
1354 u8
*mac_addr
= NULL
;
1355 struct get_key_cookie cookie
= {
1359 struct sk_buff
*msg
;
1361 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
1362 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1367 if (info
->attrs
[NL80211_ATTR_MAC
])
1368 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1372 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1376 if (!rdev
->ops
->get_key
) {
1381 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1387 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1388 NL80211_CMD_NEW_KEY
);
1396 cookie
.idx
= key_idx
;
1398 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1399 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
1401 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1403 err
= rdev
->ops
->get_key(&rdev
->wiphy
, dev
, key_idx
, mac_addr
,
1404 &cookie
, get_key_callback
);
1410 goto nla_put_failure
;
1412 genlmsg_end(msg
, hdr
);
1413 err
= genlmsg_reply(msg
, info
);
1421 cfg80211_unlock_rdev(rdev
);
1429 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
1431 struct cfg80211_registered_device
*rdev
;
1432 struct key_parse key
;
1434 struct net_device
*dev
;
1435 int (*func
)(struct wiphy
*wiphy
, struct net_device
*netdev
,
1438 err
= nl80211_parse_key(info
, &key
);
1445 /* only support setting default key */
1446 if (!key
.def
&& !key
.defmgmt
)
1451 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1456 func
= rdev
->ops
->set_default_key
;
1458 func
= rdev
->ops
->set_default_mgmt_key
;
1465 wdev_lock(dev
->ieee80211_ptr
);
1466 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1468 err
= func(&rdev
->wiphy
, dev
, key
.idx
);
1470 #ifdef CONFIG_CFG80211_WEXT
1472 if (func
== rdev
->ops
->set_default_key
)
1473 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
1475 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
1478 wdev_unlock(dev
->ieee80211_ptr
);
1481 cfg80211_unlock_rdev(rdev
);
1490 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
1492 struct cfg80211_registered_device
*rdev
;
1494 struct net_device
*dev
;
1495 struct key_parse key
;
1496 u8
*mac_addr
= NULL
;
1498 err
= nl80211_parse_key(info
, &key
);
1505 if (info
->attrs
[NL80211_ATTR_MAC
])
1506 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1510 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1514 if (!rdev
->ops
->add_key
) {
1519 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
, mac_addr
)) {
1524 wdev_lock(dev
->ieee80211_ptr
);
1525 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1527 err
= rdev
->ops
->add_key(&rdev
->wiphy
, dev
, key
.idx
,
1529 wdev_unlock(dev
->ieee80211_ptr
);
1532 cfg80211_unlock_rdev(rdev
);
1540 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
1542 struct cfg80211_registered_device
*rdev
;
1544 struct net_device
*dev
;
1545 u8
*mac_addr
= NULL
;
1546 struct key_parse key
;
1548 err
= nl80211_parse_key(info
, &key
);
1552 if (info
->attrs
[NL80211_ATTR_MAC
])
1553 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1557 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1561 if (!rdev
->ops
->del_key
) {
1566 wdev_lock(dev
->ieee80211_ptr
);
1567 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1569 err
= rdev
->ops
->del_key(&rdev
->wiphy
, dev
, key
.idx
, mac_addr
);
1571 #ifdef CONFIG_CFG80211_WEXT
1573 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
1574 dev
->ieee80211_ptr
->wext
.default_key
= -1;
1575 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
1576 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
1579 wdev_unlock(dev
->ieee80211_ptr
);
1582 cfg80211_unlock_rdev(rdev
);
1591 static int nl80211_addset_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1593 int (*call
)(struct wiphy
*wiphy
, struct net_device
*dev
,
1594 struct beacon_parameters
*info
);
1595 struct cfg80211_registered_device
*rdev
;
1597 struct net_device
*dev
;
1598 struct beacon_parameters params
;
1601 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]))
1606 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1610 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1615 switch (info
->genlhdr
->cmd
) {
1616 case NL80211_CMD_NEW_BEACON
:
1617 /* these are required for NEW_BEACON */
1618 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
1619 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
1620 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1625 call
= rdev
->ops
->add_beacon
;
1627 case NL80211_CMD_SET_BEACON
:
1628 call
= rdev
->ops
->set_beacon
;
1641 memset(¶ms
, 0, sizeof(params
));
1643 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
1645 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
1649 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
1650 params
.dtim_period
=
1651 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
1655 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1656 params
.head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1658 nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1662 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
1663 params
.tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1665 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1674 err
= call(&rdev
->wiphy
, dev
, ¶ms
);
1677 cfg80211_unlock_rdev(rdev
);
1685 static int nl80211_del_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1687 struct cfg80211_registered_device
*rdev
;
1689 struct net_device
*dev
;
1693 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1697 if (!rdev
->ops
->del_beacon
) {
1702 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1706 err
= rdev
->ops
->del_beacon(&rdev
->wiphy
, dev
);
1709 cfg80211_unlock_rdev(rdev
);
1717 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
1718 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
1719 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
1720 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
1721 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
1724 static int parse_station_flags(struct genl_info
*info
,
1725 struct station_parameters
*params
)
1727 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
1732 * Try parsing the new attribute first so userspace
1733 * can specify both for older kernels.
1735 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
1737 struct nl80211_sta_flag_update
*sta_flags
;
1739 sta_flags
= nla_data(nla
);
1740 params
->sta_flags_mask
= sta_flags
->mask
;
1741 params
->sta_flags_set
= sta_flags
->set
;
1742 if ((params
->sta_flags_mask
|
1743 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
1748 /* if present, parse the old attribute */
1750 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
1754 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
1755 nla
, sta_flags_policy
))
1758 params
->sta_flags_mask
= (1 << __NL80211_STA_FLAG_AFTER_LAST
) - 1;
1759 params
->sta_flags_mask
&= ~1;
1761 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++)
1763 params
->sta_flags_set
|= (1<<flag
);
1768 static int nl80211_send_station(struct sk_buff
*msg
, u32 pid
, u32 seq
,
1769 int flags
, struct net_device
*dev
,
1770 const u8
*mac_addr
, struct station_info
*sinfo
)
1773 struct nlattr
*sinfoattr
, *txrate
;
1776 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
1780 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1781 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1783 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
);
1785 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
1787 goto nla_put_failure
;
1788 if (sinfo
->filled
& STATION_INFO_INACTIVE_TIME
)
1789 NLA_PUT_U32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
1790 sinfo
->inactive_time
);
1791 if (sinfo
->filled
& STATION_INFO_RX_BYTES
)
1792 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_BYTES
,
1794 if (sinfo
->filled
& STATION_INFO_TX_BYTES
)
1795 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_BYTES
,
1797 if (sinfo
->filled
& STATION_INFO_LLID
)
1798 NLA_PUT_U16(msg
, NL80211_STA_INFO_LLID
,
1800 if (sinfo
->filled
& STATION_INFO_PLID
)
1801 NLA_PUT_U16(msg
, NL80211_STA_INFO_PLID
,
1803 if (sinfo
->filled
& STATION_INFO_PLINK_STATE
)
1804 NLA_PUT_U8(msg
, NL80211_STA_INFO_PLINK_STATE
,
1805 sinfo
->plink_state
);
1806 if (sinfo
->filled
& STATION_INFO_SIGNAL
)
1807 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL
,
1809 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
1810 txrate
= nla_nest_start(msg
, NL80211_STA_INFO_TX_BITRATE
);
1812 goto nla_put_failure
;
1814 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
1815 bitrate
= cfg80211_calculate_bitrate(&sinfo
->txrate
);
1817 NLA_PUT_U16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate
);
1819 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_MCS
)
1820 NLA_PUT_U8(msg
, NL80211_RATE_INFO_MCS
,
1822 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
)
1823 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
);
1824 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_SHORT_GI
)
1825 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_SHORT_GI
);
1827 nla_nest_end(msg
, txrate
);
1829 if (sinfo
->filled
& STATION_INFO_RX_PACKETS
)
1830 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_PACKETS
,
1832 if (sinfo
->filled
& STATION_INFO_TX_PACKETS
)
1833 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_PACKETS
,
1835 nla_nest_end(msg
, sinfoattr
);
1837 return genlmsg_end(msg
, hdr
);
1840 genlmsg_cancel(msg
, hdr
);
1844 static int nl80211_dump_station(struct sk_buff
*skb
,
1845 struct netlink_callback
*cb
)
1847 struct station_info sinfo
;
1848 struct cfg80211_registered_device
*dev
;
1849 struct net_device
*netdev
;
1850 u8 mac_addr
[ETH_ALEN
];
1851 int ifidx
= cb
->args
[0];
1852 int sta_idx
= cb
->args
[1];
1856 ifidx
= nl80211_get_ifidx(cb
);
1862 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
1868 dev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
1874 if (!dev
->ops
->dump_station
) {
1880 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
1887 if (nl80211_send_station(skb
,
1888 NETLINK_CB(cb
->skb
).pid
,
1889 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1899 cb
->args
[1] = sta_idx
;
1902 cfg80211_unlock_rdev(dev
);
1909 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
1911 struct cfg80211_registered_device
*rdev
;
1913 struct net_device
*dev
;
1914 struct station_info sinfo
;
1915 struct sk_buff
*msg
;
1916 u8
*mac_addr
= NULL
;
1918 memset(&sinfo
, 0, sizeof(sinfo
));
1920 if (!info
->attrs
[NL80211_ATTR_MAC
])
1923 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1927 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1931 if (!rdev
->ops
->get_station
) {
1936 err
= rdev
->ops
->get_station(&rdev
->wiphy
, dev
, mac_addr
, &sinfo
);
1940 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1944 if (nl80211_send_station(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1945 dev
, mac_addr
, &sinfo
) < 0)
1948 err
= genlmsg_reply(msg
, info
);
1954 cfg80211_unlock_rdev(rdev
);
1963 * Get vlan interface making sure it is running and on the right wiphy.
1965 static int get_vlan(struct genl_info
*info
,
1966 struct cfg80211_registered_device
*rdev
,
1967 struct net_device
**vlan
)
1969 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
1973 *vlan
= dev_get_by_index(genl_info_net(info
),
1974 nla_get_u32(vlanattr
));
1977 if (!(*vlan
)->ieee80211_ptr
)
1979 if ((*vlan
)->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
)
1981 if (!netif_running(*vlan
))
1987 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
1989 struct cfg80211_registered_device
*rdev
;
1991 struct net_device
*dev
;
1992 struct station_parameters params
;
1993 u8
*mac_addr
= NULL
;
1995 memset(¶ms
, 0, sizeof(params
));
1997 params
.listen_interval
= -1;
1999 if (info
->attrs
[NL80211_ATTR_STA_AID
])
2002 if (!info
->attrs
[NL80211_ATTR_MAC
])
2005 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2007 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
2008 params
.supported_rates
=
2009 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2010 params
.supported_rates_len
=
2011 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2014 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2015 params
.listen_interval
=
2016 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2018 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2020 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2022 if (parse_station_flags(info
, ¶ms
))
2025 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
2026 params
.plink_action
=
2027 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
2031 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2035 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
2039 /* validate settings */
2042 switch (dev
->ieee80211_ptr
->iftype
) {
2043 case NL80211_IFTYPE_AP
:
2044 case NL80211_IFTYPE_AP_VLAN
:
2045 /* disallow mesh-specific things */
2046 if (params
.plink_action
)
2049 case NL80211_IFTYPE_STATION
:
2050 /* disallow everything but AUTHORIZED flag */
2051 if (params
.plink_action
)
2055 if (params
.supported_rates
)
2059 if (params
.listen_interval
>= 0)
2061 if (params
.sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
2064 case NL80211_IFTYPE_MESH_POINT
:
2065 /* disallow things mesh doesn't support */
2070 if (params
.listen_interval
>= 0)
2072 if (params
.supported_rates
)
2074 if (params
.sta_flags_mask
)
2084 if (!rdev
->ops
->change_station
) {
2089 err
= rdev
->ops
->change_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2093 dev_put(params
.vlan
);
2094 cfg80211_unlock_rdev(rdev
);
2102 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
2104 struct cfg80211_registered_device
*rdev
;
2106 struct net_device
*dev
;
2107 struct station_parameters params
;
2108 u8
*mac_addr
= NULL
;
2110 memset(¶ms
, 0, sizeof(params
));
2112 if (!info
->attrs
[NL80211_ATTR_MAC
])
2115 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2118 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
2121 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
2124 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2125 params
.supported_rates
=
2126 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2127 params
.supported_rates_len
=
2128 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2129 params
.listen_interval
=
2130 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2132 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
2133 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
2136 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2138 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2140 if (parse_station_flags(info
, ¶ms
))
2145 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2149 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2150 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
) {
2155 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
2159 /* validate settings */
2162 if (!rdev
->ops
->add_station
) {
2167 if (!netif_running(dev
)) {
2172 err
= rdev
->ops
->add_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2176 dev_put(params
.vlan
);
2177 cfg80211_unlock_rdev(rdev
);
2185 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
2187 struct cfg80211_registered_device
*rdev
;
2189 struct net_device
*dev
;
2190 u8
*mac_addr
= NULL
;
2192 if (info
->attrs
[NL80211_ATTR_MAC
])
2193 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2197 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2201 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2202 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
2203 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2208 if (!rdev
->ops
->del_station
) {
2213 err
= rdev
->ops
->del_station(&rdev
->wiphy
, dev
, mac_addr
);
2216 cfg80211_unlock_rdev(rdev
);
2224 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2225 int flags
, struct net_device
*dev
,
2226 u8
*dst
, u8
*next_hop
,
2227 struct mpath_info
*pinfo
)
2230 struct nlattr
*pinfoattr
;
2232 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2236 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2237 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
2238 NLA_PUT(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
);
2240 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
);
2242 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
2244 goto nla_put_failure
;
2245 if (pinfo
->filled
& MPATH_INFO_FRAME_QLEN
)
2246 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
2248 if (pinfo
->filled
& MPATH_INFO_SN
)
2249 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_SN
,
2251 if (pinfo
->filled
& MPATH_INFO_METRIC
)
2252 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_METRIC
,
2254 if (pinfo
->filled
& MPATH_INFO_EXPTIME
)
2255 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_EXPTIME
,
2257 if (pinfo
->filled
& MPATH_INFO_FLAGS
)
2258 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_FLAGS
,
2260 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
)
2261 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
2262 pinfo
->discovery_timeout
);
2263 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
)
2264 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
2265 pinfo
->discovery_retries
);
2267 nla_nest_end(msg
, pinfoattr
);
2269 return genlmsg_end(msg
, hdr
);
2272 genlmsg_cancel(msg
, hdr
);
2276 static int nl80211_dump_mpath(struct sk_buff
*skb
,
2277 struct netlink_callback
*cb
)
2279 struct mpath_info pinfo
;
2280 struct cfg80211_registered_device
*dev
;
2281 struct net_device
*netdev
;
2283 u8 next_hop
[ETH_ALEN
];
2284 int ifidx
= cb
->args
[0];
2285 int path_idx
= cb
->args
[1];
2289 ifidx
= nl80211_get_ifidx(cb
);
2295 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
2301 dev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
2307 if (!dev
->ops
->dump_mpath
) {
2312 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2318 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
2319 dst
, next_hop
, &pinfo
);
2325 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).pid
,
2326 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2327 netdev
, dst
, next_hop
,
2336 cb
->args
[1] = path_idx
;
2339 cfg80211_unlock_rdev(dev
);
2346 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2348 struct cfg80211_registered_device
*rdev
;
2350 struct net_device
*dev
;
2351 struct mpath_info pinfo
;
2352 struct sk_buff
*msg
;
2354 u8 next_hop
[ETH_ALEN
];
2356 memset(&pinfo
, 0, sizeof(pinfo
));
2358 if (!info
->attrs
[NL80211_ATTR_MAC
])
2361 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2365 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2369 if (!rdev
->ops
->get_mpath
) {
2374 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2379 err
= rdev
->ops
->get_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
2383 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2387 if (nl80211_send_mpath(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2388 dev
, dst
, next_hop
, &pinfo
) < 0)
2391 err
= genlmsg_reply(msg
, info
);
2397 cfg80211_unlock_rdev(rdev
);
2405 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2407 struct cfg80211_registered_device
*rdev
;
2409 struct net_device
*dev
;
2411 u8
*next_hop
= NULL
;
2413 if (!info
->attrs
[NL80211_ATTR_MAC
])
2416 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2419 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2420 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2424 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2428 if (!rdev
->ops
->change_mpath
) {
2433 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2438 if (!netif_running(dev
)) {
2443 err
= rdev
->ops
->change_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2446 cfg80211_unlock_rdev(rdev
);
2453 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2455 struct cfg80211_registered_device
*rdev
;
2457 struct net_device
*dev
;
2459 u8
*next_hop
= NULL
;
2461 if (!info
->attrs
[NL80211_ATTR_MAC
])
2464 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2467 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2468 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2472 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2476 if (!rdev
->ops
->add_mpath
) {
2481 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2486 if (!netif_running(dev
)) {
2491 err
= rdev
->ops
->add_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2494 cfg80211_unlock_rdev(rdev
);
2502 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2504 struct cfg80211_registered_device
*rdev
;
2506 struct net_device
*dev
;
2509 if (info
->attrs
[NL80211_ATTR_MAC
])
2510 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2514 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2518 if (!rdev
->ops
->del_mpath
) {
2523 err
= rdev
->ops
->del_mpath(&rdev
->wiphy
, dev
, dst
);
2526 cfg80211_unlock_rdev(rdev
);
2534 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
2536 struct cfg80211_registered_device
*rdev
;
2538 struct net_device
*dev
;
2539 struct bss_parameters params
;
2541 memset(¶ms
, 0, sizeof(params
));
2542 /* default to not changing parameters */
2543 params
.use_cts_prot
= -1;
2544 params
.use_short_preamble
= -1;
2545 params
.use_short_slot_time
= -1;
2546 params
.ap_isolate
= -1;
2548 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
2549 params
.use_cts_prot
=
2550 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
2551 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
2552 params
.use_short_preamble
=
2553 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
2554 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
2555 params
.use_short_slot_time
=
2556 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
2557 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
2558 params
.basic_rates
=
2559 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2560 params
.basic_rates_len
=
2561 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2563 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
2564 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
2568 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2572 if (!rdev
->ops
->change_bss
) {
2577 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
2582 err
= rdev
->ops
->change_bss(&rdev
->wiphy
, dev
, ¶ms
);
2585 cfg80211_unlock_rdev(rdev
);
2593 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
2594 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
2595 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
2596 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
2597 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
2598 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
2599 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
2602 static int parse_reg_rule(struct nlattr
*tb
[],
2603 struct ieee80211_reg_rule
*reg_rule
)
2605 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
2606 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
2608 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
2610 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
2612 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
2614 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
2616 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
2619 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
2621 freq_range
->start_freq_khz
=
2622 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
2623 freq_range
->end_freq_khz
=
2624 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
2625 freq_range
->max_bandwidth_khz
=
2626 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
2628 power_rule
->max_eirp
=
2629 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
2631 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
2632 power_rule
->max_antenna_gain
=
2633 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
2638 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2644 * You should only get this when cfg80211 hasn't yet initialized
2645 * completely when built-in to the kernel right between the time
2646 * window between nl80211_init() and regulatory_init(), if that is
2649 mutex_lock(&cfg80211_mutex
);
2650 if (unlikely(!cfg80211_regdomain
)) {
2651 mutex_unlock(&cfg80211_mutex
);
2652 return -EINPROGRESS
;
2654 mutex_unlock(&cfg80211_mutex
);
2656 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2659 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2661 r
= regulatory_hint_user(data
);
2666 static int nl80211_get_mesh_params(struct sk_buff
*skb
,
2667 struct genl_info
*info
)
2669 struct cfg80211_registered_device
*rdev
;
2670 struct mesh_config cur_params
;
2672 struct net_device
*dev
;
2674 struct nlattr
*pinfoattr
;
2675 struct sk_buff
*msg
;
2679 /* Look up our device */
2680 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2684 if (!rdev
->ops
->get_mesh_params
) {
2689 /* Get the mesh params */
2690 err
= rdev
->ops
->get_mesh_params(&rdev
->wiphy
, dev
, &cur_params
);
2694 /* Draw up a netlink message to send back */
2695 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2700 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2701 NL80211_CMD_GET_MESH_PARAMS
);
2703 goto nla_put_failure
;
2704 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_PARAMS
);
2706 goto nla_put_failure
;
2707 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2708 NLA_PUT_U16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
2709 cur_params
.dot11MeshRetryTimeout
);
2710 NLA_PUT_U16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
2711 cur_params
.dot11MeshConfirmTimeout
);
2712 NLA_PUT_U16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
2713 cur_params
.dot11MeshHoldingTimeout
);
2714 NLA_PUT_U16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
2715 cur_params
.dot11MeshMaxPeerLinks
);
2716 NLA_PUT_U8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
2717 cur_params
.dot11MeshMaxRetries
);
2718 NLA_PUT_U8(msg
, NL80211_MESHCONF_TTL
,
2719 cur_params
.dot11MeshTTL
);
2720 NLA_PUT_U8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
2721 cur_params
.auto_open_plinks
);
2722 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2723 cur_params
.dot11MeshHWMPmaxPREQretries
);
2724 NLA_PUT_U32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
2725 cur_params
.path_refresh_time
);
2726 NLA_PUT_U16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2727 cur_params
.min_discovery_timeout
);
2728 NLA_PUT_U32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2729 cur_params
.dot11MeshHWMPactivePathTimeout
);
2730 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2731 cur_params
.dot11MeshHWMPpreqMinInterval
);
2732 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2733 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
);
2734 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
2735 cur_params
.dot11MeshHWMPRootMode
);
2736 nla_nest_end(msg
, pinfoattr
);
2737 genlmsg_end(msg
, hdr
);
2738 err
= genlmsg_reply(msg
, info
);
2742 genlmsg_cancel(msg
, hdr
);
2746 cfg80211_unlock_rdev(rdev
);
2754 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2756 if (table[attr_num]) {\
2757 cfg.param = nla_fn(table[attr_num]); \
2758 mask |= (1 << (attr_num - 1)); \
2762 static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
2763 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
2764 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
2765 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
2766 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
2767 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
2768 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
2769 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
2771 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
2772 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
2773 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
2774 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
2775 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
2776 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
2779 static int nl80211_set_mesh_params(struct sk_buff
*skb
, struct genl_info
*info
)
2783 struct cfg80211_registered_device
*rdev
;
2784 struct net_device
*dev
;
2785 struct mesh_config cfg
;
2786 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
2787 struct nlattr
*parent_attr
;
2789 parent_attr
= info
->attrs
[NL80211_ATTR_MESH_PARAMS
];
2792 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
2793 parent_attr
, nl80211_meshconf_params_policy
))
2798 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2802 if (!rdev
->ops
->set_mesh_params
) {
2807 /* This makes sure that there aren't more than 32 mesh config
2808 * parameters (otherwise our bitfield scheme would not work.) */
2809 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
2811 /* Fill in the params struct */
2813 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
2814 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
, nla_get_u16
);
2815 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
2816 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
, nla_get_u16
);
2817 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
2818 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
, nla_get_u16
);
2819 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
2820 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
, nla_get_u16
);
2821 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
2822 mask
, NL80211_MESHCONF_MAX_RETRIES
, nla_get_u8
);
2823 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
2824 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
2825 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
2826 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
, nla_get_u8
);
2827 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
2828 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2830 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
2831 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
, nla_get_u32
);
2832 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
2833 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2835 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
2836 mask
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2838 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
2839 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2841 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
2842 dot11MeshHWMPnetDiameterTraversalTime
,
2843 mask
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2845 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
2846 dot11MeshHWMPRootMode
, mask
,
2847 NL80211_MESHCONF_HWMP_ROOTMODE
,
2851 err
= rdev
->ops
->set_mesh_params(&rdev
->wiphy
, dev
, &cfg
, mask
);
2855 cfg80211_unlock_rdev(rdev
);
2863 #undef FILL_IN_MESH_PARAM_IF_SET
2865 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2867 struct sk_buff
*msg
;
2869 struct nlattr
*nl_reg_rules
;
2873 mutex_lock(&cfg80211_mutex
);
2875 if (!cfg80211_regdomain
)
2878 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2884 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2885 NL80211_CMD_GET_REG
);
2887 goto nla_put_failure
;
2889 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
,
2890 cfg80211_regdomain
->alpha2
);
2892 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
2894 goto nla_put_failure
;
2896 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
2897 struct nlattr
*nl_reg_rule
;
2898 const struct ieee80211_reg_rule
*reg_rule
;
2899 const struct ieee80211_freq_range
*freq_range
;
2900 const struct ieee80211_power_rule
*power_rule
;
2902 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
2903 freq_range
= ®_rule
->freq_range
;
2904 power_rule
= ®_rule
->power_rule
;
2906 nl_reg_rule
= nla_nest_start(msg
, i
);
2908 goto nla_put_failure
;
2910 NLA_PUT_U32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
2912 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
2913 freq_range
->start_freq_khz
);
2914 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
2915 freq_range
->end_freq_khz
);
2916 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
2917 freq_range
->max_bandwidth_khz
);
2918 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
2919 power_rule
->max_antenna_gain
);
2920 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
2921 power_rule
->max_eirp
);
2923 nla_nest_end(msg
, nl_reg_rule
);
2926 nla_nest_end(msg
, nl_reg_rules
);
2928 genlmsg_end(msg
, hdr
);
2929 err
= genlmsg_reply(msg
, info
);
2933 genlmsg_cancel(msg
, hdr
);
2936 mutex_unlock(&cfg80211_mutex
);
2940 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2942 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
2943 struct nlattr
*nl_reg_rule
;
2944 char *alpha2
= NULL
;
2945 int rem_reg_rules
= 0, r
= 0;
2946 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
2947 struct ieee80211_regdomain
*rd
= NULL
;
2949 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2952 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
2955 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2957 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
2960 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
2964 mutex_lock(&cfg80211_mutex
);
2966 if (!reg_is_valid_request(alpha2
)) {
2971 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
2972 (num_rules
* sizeof(struct ieee80211_reg_rule
));
2974 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
2980 rd
->n_reg_rules
= num_rules
;
2981 rd
->alpha2
[0] = alpha2
[0];
2982 rd
->alpha2
[1] = alpha2
[1];
2984 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
2986 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
2987 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
2989 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
2995 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
3001 BUG_ON(rule_idx
!= num_rules
);
3005 mutex_unlock(&cfg80211_mutex
);
3010 mutex_unlock(&cfg80211_mutex
);
3015 static int validate_scan_freqs(struct nlattr
*freqs
)
3017 struct nlattr
*attr1
, *attr2
;
3018 int n_channels
= 0, tmp1
, tmp2
;
3020 nla_for_each_nested(attr1
, freqs
, tmp1
) {
3023 * Some hardware has a limited channel list for
3024 * scanning, and it is pretty much nonsensical
3025 * to scan for a channel twice, so disallow that
3026 * and don't require drivers to check that the
3027 * channel list they get isn't longer than what
3028 * they can scan, as long as they can scan all
3029 * the channels they registered at once.
3031 nla_for_each_nested(attr2
, freqs
, tmp2
)
3032 if (attr1
!= attr2
&&
3033 nla_get_u32(attr1
) == nla_get_u32(attr2
))
3040 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
3042 struct cfg80211_registered_device
*rdev
;
3043 struct net_device
*dev
;
3044 struct cfg80211_scan_request
*request
;
3045 struct cfg80211_ssid
*ssid
;
3046 struct ieee80211_channel
*channel
;
3047 struct nlattr
*attr
;
3048 struct wiphy
*wiphy
;
3049 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
3050 enum ieee80211_band band
;
3053 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3058 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3062 wiphy
= &rdev
->wiphy
;
3064 if (!rdev
->ops
->scan
) {
3069 if (!netif_running(dev
)) {
3074 if (rdev
->scan_req
) {
3079 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3080 n_channels
= validate_scan_freqs(
3081 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
3089 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
3090 if (wiphy
->bands
[band
])
3091 n_channels
+= wiphy
->bands
[band
]->n_channels
;
3094 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
3095 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
3098 if (n_ssids
> wiphy
->max_scan_ssids
) {
3103 if (info
->attrs
[NL80211_ATTR_IE
])
3104 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3108 if (ie_len
> wiphy
->max_scan_ie_len
) {
3113 request
= kzalloc(sizeof(*request
)
3114 + sizeof(*ssid
) * n_ssids
3115 + sizeof(channel
) * n_channels
3116 + ie_len
, GFP_KERNEL
);
3123 request
->ssids
= (void *)&request
->channels
[n_channels
];
3124 request
->n_ssids
= n_ssids
;
3127 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
3129 request
->ie
= (void *)(request
->channels
+ n_channels
);
3133 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3134 /* user specified, bail out if channel not found */
3135 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
3136 struct ieee80211_channel
*chan
;
3138 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
3145 /* ignore disabled channels */
3146 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3149 request
->channels
[i
] = chan
;
3154 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
3156 if (!wiphy
->bands
[band
])
3158 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
3159 struct ieee80211_channel
*chan
;
3161 chan
= &wiphy
->bands
[band
]->channels
[j
];
3163 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3166 request
->channels
[i
] = chan
;
3177 request
->n_channels
= i
;
3180 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
3181 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
3182 request
->ssids
[i
].ssid_len
= nla_len(attr
);
3183 if (request
->ssids
[i
].ssid_len
> IEEE80211_MAX_SSID_LEN
) {
3187 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
3192 if (info
->attrs
[NL80211_ATTR_IE
]) {
3193 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3194 memcpy((void *)request
->ie
,
3195 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
3200 request
->wiphy
= &rdev
->wiphy
;
3202 rdev
->scan_req
= request
;
3203 err
= rdev
->ops
->scan(&rdev
->wiphy
, dev
, request
);
3206 nl80211_send_scan_start(rdev
, dev
);
3212 rdev
->scan_req
= NULL
;
3216 cfg80211_unlock_rdev(rdev
);
3224 static int nl80211_send_bss(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
3225 struct cfg80211_registered_device
*rdev
,
3226 struct wireless_dev
*wdev
,
3227 struct cfg80211_internal_bss
*intbss
)
3229 struct cfg80211_bss
*res
= &intbss
->pub
;
3234 ASSERT_WDEV_LOCK(wdev
);
3236 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3237 NL80211_CMD_NEW_SCAN_RESULTS
);
3241 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
);
3242 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
);
3244 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
3246 goto nla_put_failure
;
3247 if (!is_zero_ether_addr(res
->bssid
))
3248 NLA_PUT(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
);
3249 if (res
->information_elements
&& res
->len_information_elements
)
3250 NLA_PUT(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
3251 res
->len_information_elements
,
3252 res
->information_elements
);
3253 if (res
->beacon_ies
&& res
->len_beacon_ies
&&
3254 res
->beacon_ies
!= res
->information_elements
)
3255 NLA_PUT(msg
, NL80211_BSS_BEACON_IES
,
3256 res
->len_beacon_ies
, res
->beacon_ies
);
3258 NLA_PUT_U64(msg
, NL80211_BSS_TSF
, res
->tsf
);
3259 if (res
->beacon_interval
)
3260 NLA_PUT_U16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
);
3261 NLA_PUT_U16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
);
3262 NLA_PUT_U32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
);
3263 NLA_PUT_U32(msg
, NL80211_BSS_SEEN_MS_AGO
,
3264 jiffies_to_msecs(jiffies
- intbss
->ts
));
3266 switch (rdev
->wiphy
.signal_type
) {
3267 case CFG80211_SIGNAL_TYPE_MBM
:
3268 NLA_PUT_U32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
);
3270 case CFG80211_SIGNAL_TYPE_UNSPEC
:
3271 NLA_PUT_U8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
);
3277 switch (wdev
->iftype
) {
3278 case NL80211_IFTYPE_STATION
:
3279 if (intbss
== wdev
->current_bss
)
3280 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3281 NL80211_BSS_STATUS_ASSOCIATED
);
3282 else for (i
= 0; i
< MAX_AUTH_BSSES
; i
++) {
3283 if (intbss
!= wdev
->auth_bsses
[i
])
3285 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3286 NL80211_BSS_STATUS_AUTHENTICATED
);
3290 case NL80211_IFTYPE_ADHOC
:
3291 if (intbss
== wdev
->current_bss
)
3292 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3293 NL80211_BSS_STATUS_IBSS_JOINED
);
3299 nla_nest_end(msg
, bss
);
3301 return genlmsg_end(msg
, hdr
);
3304 genlmsg_cancel(msg
, hdr
);
3308 static int nl80211_dump_scan(struct sk_buff
*skb
,
3309 struct netlink_callback
*cb
)
3311 struct cfg80211_registered_device
*rdev
;
3312 struct net_device
*dev
;
3313 struct cfg80211_internal_bss
*scan
;
3314 struct wireless_dev
*wdev
;
3315 int ifidx
= cb
->args
[0];
3316 int start
= cb
->args
[1], idx
= 0;
3320 ifidx
= nl80211_get_ifidx(cb
);
3323 cb
->args
[0] = ifidx
;
3325 dev
= dev_get_by_index(sock_net(skb
->sk
), ifidx
);
3329 rdev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
3331 err
= PTR_ERR(rdev
);
3332 goto out_put_netdev
;
3335 wdev
= dev
->ieee80211_ptr
;
3338 spin_lock_bh(&rdev
->bss_lock
);
3339 cfg80211_bss_expire(rdev
);
3341 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
3344 if (nl80211_send_bss(skb
,
3345 NETLINK_CB(cb
->skb
).pid
,
3346 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3347 rdev
, wdev
, scan
) < 0) {
3354 spin_unlock_bh(&rdev
->bss_lock
);
3359 cfg80211_unlock_rdev(rdev
);
3366 static int nl80211_send_survey(struct sk_buff
*msg
, u32 pid
, u32 seq
,
3367 int flags
, struct net_device
*dev
,
3368 struct survey_info
*survey
)
3371 struct nlattr
*infoattr
;
3373 /* Survey without a channel doesn't make sense */
3374 if (!survey
->channel
)
3377 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3378 NL80211_CMD_NEW_SURVEY_RESULTS
);
3382 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
3384 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
3386 goto nla_put_failure
;
3388 NLA_PUT_U32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
3389 survey
->channel
->center_freq
);
3390 if (survey
->filled
& SURVEY_INFO_NOISE_DBM
)
3391 NLA_PUT_U8(msg
, NL80211_SURVEY_INFO_NOISE
,
3394 nla_nest_end(msg
, infoattr
);
3396 return genlmsg_end(msg
, hdr
);
3399 genlmsg_cancel(msg
, hdr
);
3403 static int nl80211_dump_survey(struct sk_buff
*skb
,
3404 struct netlink_callback
*cb
)
3406 struct survey_info survey
;
3407 struct cfg80211_registered_device
*dev
;
3408 struct net_device
*netdev
;
3409 int ifidx
= cb
->args
[0];
3410 int survey_idx
= cb
->args
[1];
3414 ifidx
= nl80211_get_ifidx(cb
);
3417 cb
->args
[0] = ifidx
;
3421 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
3427 dev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
3433 if (!dev
->ops
->dump_survey
) {
3439 res
= dev
->ops
->dump_survey(&dev
->wiphy
, netdev
, survey_idx
,
3446 if (nl80211_send_survey(skb
,
3447 NETLINK_CB(cb
->skb
).pid
,
3448 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3456 cb
->args
[1] = survey_idx
;
3459 cfg80211_unlock_rdev(dev
);
3466 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
)
3468 return auth_type
<= NL80211_AUTHTYPE_MAX
;
3471 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
3473 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
3474 NL80211_WPA_VERSION_2
));
3477 static bool nl80211_valid_akm_suite(u32 akm
)
3479 return akm
== WLAN_AKM_SUITE_8021X
||
3480 akm
== WLAN_AKM_SUITE_PSK
;
3483 static bool nl80211_valid_cipher_suite(u32 cipher
)
3485 return cipher
== WLAN_CIPHER_SUITE_WEP40
||
3486 cipher
== WLAN_CIPHER_SUITE_WEP104
||
3487 cipher
== WLAN_CIPHER_SUITE_TKIP
||
3488 cipher
== WLAN_CIPHER_SUITE_CCMP
||
3489 cipher
== WLAN_CIPHER_SUITE_AES_CMAC
;
3493 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3495 struct cfg80211_registered_device
*rdev
;
3496 struct net_device
*dev
;
3497 struct ieee80211_channel
*chan
;
3498 const u8
*bssid
, *ssid
, *ie
= NULL
;
3499 int err
, ssid_len
, ie_len
= 0;
3500 enum nl80211_auth_type auth_type
;
3501 struct key_parse key
;
3502 bool local_state_change
;
3504 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3507 if (!info
->attrs
[NL80211_ATTR_MAC
])
3510 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
3513 if (!info
->attrs
[NL80211_ATTR_SSID
])
3516 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
3519 err
= nl80211_parse_key(info
, &key
);
3524 if (!key
.p
.key
|| !key
.p
.key_len
)
3526 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
3527 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
3528 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
3529 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
3540 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3544 if (!rdev
->ops
->auth
) {
3549 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3554 if (!netif_running(dev
)) {
3559 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3560 chan
= ieee80211_get_channel(&rdev
->wiphy
,
3561 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3562 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
)) {
3567 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3568 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3570 if (info
->attrs
[NL80211_ATTR_IE
]) {
3571 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3572 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3575 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3576 if (!nl80211_valid_auth_type(auth_type
)) {
3581 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
3583 err
= cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
3584 ssid
, ssid_len
, ie
, ie_len
,
3585 key
.p
.key
, key
.p
.key_len
, key
.idx
,
3586 local_state_change
);
3589 cfg80211_unlock_rdev(rdev
);
3596 static int nl80211_crypto_settings(struct genl_info
*info
,
3597 struct cfg80211_crypto_settings
*settings
,
3600 memset(settings
, 0, sizeof(*settings
));
3602 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
3604 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
3608 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
3609 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
3610 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
3612 if (len
% sizeof(u32
))
3615 if (settings
->n_ciphers_pairwise
> cipher_limit
)
3618 memcpy(settings
->ciphers_pairwise
, data
, len
);
3620 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
3621 if (!nl80211_valid_cipher_suite(
3622 settings
->ciphers_pairwise
[i
]))
3626 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
3627 settings
->cipher_group
=
3628 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
3629 if (!nl80211_valid_cipher_suite(settings
->cipher_group
))
3633 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
3634 settings
->wpa_versions
=
3635 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
3636 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
3640 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
3644 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
3645 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
3646 settings
->n_akm_suites
= len
/ sizeof(u32
);
3648 if (len
% sizeof(u32
))
3651 memcpy(settings
->akm_suites
, data
, len
);
3653 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
3654 if (!nl80211_valid_akm_suite(settings
->akm_suites
[i
]))
3661 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
3663 struct cfg80211_registered_device
*rdev
;
3664 struct net_device
*dev
;
3665 struct cfg80211_crypto_settings crypto
;
3666 struct ieee80211_channel
*chan
;
3667 const u8
*bssid
, *ssid
, *ie
= NULL
, *prev_bssid
= NULL
;
3668 int err
, ssid_len
, ie_len
= 0;
3669 bool use_mfp
= false;
3671 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3674 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
3675 !info
->attrs
[NL80211_ATTR_SSID
] ||
3676 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
3681 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3685 if (!rdev
->ops
->assoc
) {
3690 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3695 if (!netif_running(dev
)) {
3700 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3702 chan
= ieee80211_get_channel(&rdev
->wiphy
,
3703 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3704 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
)) {
3709 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3710 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3712 if (info
->attrs
[NL80211_ATTR_IE
]) {
3713 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3714 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3717 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
3718 enum nl80211_mfp mfp
=
3719 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
3720 if (mfp
== NL80211_MFP_REQUIRED
)
3722 else if (mfp
!= NL80211_MFP_NO
) {
3728 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
3729 prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
3731 err
= nl80211_crypto_settings(info
, &crypto
, 1);
3733 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
, prev_bssid
,
3734 ssid
, ssid_len
, ie
, ie_len
, use_mfp
,
3738 cfg80211_unlock_rdev(rdev
);
3745 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3747 struct cfg80211_registered_device
*rdev
;
3748 struct net_device
*dev
;
3749 const u8
*ie
= NULL
, *bssid
;
3750 int err
, ie_len
= 0;
3752 bool local_state_change
;
3754 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3757 if (!info
->attrs
[NL80211_ATTR_MAC
])
3760 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3765 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3769 if (!rdev
->ops
->deauth
) {
3774 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3779 if (!netif_running(dev
)) {
3784 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3786 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3787 if (reason_code
== 0) {
3788 /* Reason Code 0 is reserved */
3793 if (info
->attrs
[NL80211_ATTR_IE
]) {
3794 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3795 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3798 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
3800 err
= cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
3801 local_state_change
);
3804 cfg80211_unlock_rdev(rdev
);
3811 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
3813 struct cfg80211_registered_device
*rdev
;
3814 struct net_device
*dev
;
3815 const u8
*ie
= NULL
, *bssid
;
3816 int err
, ie_len
= 0;
3818 bool local_state_change
;
3820 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3823 if (!info
->attrs
[NL80211_ATTR_MAC
])
3826 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3831 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3835 if (!rdev
->ops
->disassoc
) {
3840 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3845 if (!netif_running(dev
)) {
3850 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3852 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3853 if (reason_code
== 0) {
3854 /* Reason Code 0 is reserved */
3859 if (info
->attrs
[NL80211_ATTR_IE
]) {
3860 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3861 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3864 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
3866 err
= cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
3867 local_state_change
);
3870 cfg80211_unlock_rdev(rdev
);
3877 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
3879 struct cfg80211_registered_device
*rdev
;
3880 struct net_device
*dev
;
3881 struct cfg80211_ibss_params ibss
;
3882 struct wiphy
*wiphy
;
3883 struct cfg80211_cached_keys
*connkeys
= NULL
;
3886 memset(&ibss
, 0, sizeof(ibss
));
3888 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3891 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
3892 !info
->attrs
[NL80211_ATTR_SSID
] ||
3893 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
3896 ibss
.beacon_interval
= 100;
3898 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
3899 ibss
.beacon_interval
=
3900 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3901 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
3907 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3911 if (!rdev
->ops
->join_ibss
) {
3916 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
3921 if (!netif_running(dev
)) {
3926 wiphy
= &rdev
->wiphy
;
3928 if (info
->attrs
[NL80211_ATTR_MAC
])
3929 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3930 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3931 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3933 if (info
->attrs
[NL80211_ATTR_IE
]) {
3934 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3935 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3938 ibss
.channel
= ieee80211_get_channel(wiphy
,
3939 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3940 if (!ibss
.channel
||
3941 ibss
.channel
->flags
& IEEE80211_CHAN_NO_IBSS
||
3942 ibss
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
3947 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
3948 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3950 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
3951 connkeys
= nl80211_parse_connkeys(rdev
,
3952 info
->attrs
[NL80211_ATTR_KEYS
]);
3953 if (IS_ERR(connkeys
)) {
3954 err
= PTR_ERR(connkeys
);
3960 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
3963 cfg80211_unlock_rdev(rdev
);
3972 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
3974 struct cfg80211_registered_device
*rdev
;
3975 struct net_device
*dev
;
3980 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3984 if (!rdev
->ops
->leave_ibss
) {
3989 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
3994 if (!netif_running(dev
)) {
3999 err
= cfg80211_leave_ibss(rdev
, dev
, false);
4002 cfg80211_unlock_rdev(rdev
);
4009 #ifdef CONFIG_NL80211_TESTMODE
4010 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
4014 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
4016 struct cfg80211_registered_device
*rdev
;
4019 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
4024 rdev
= cfg80211_get_dev_from_info(info
);
4026 err
= PTR_ERR(rdev
);
4031 if (rdev
->ops
->testmode_cmd
) {
4032 rdev
->testmode_info
= info
;
4033 err
= rdev
->ops
->testmode_cmd(&rdev
->wiphy
,
4034 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
4035 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
4036 rdev
->testmode_info
= NULL
;
4039 cfg80211_unlock_rdev(rdev
);
4046 static struct sk_buff
*
4047 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
4048 int approxlen
, u32 pid
, u32 seq
, gfp_t gfp
)
4050 struct sk_buff
*skb
;
4052 struct nlattr
*data
;
4054 skb
= nlmsg_new(approxlen
+ 100, gfp
);
4058 hdr
= nl80211hdr_put(skb
, pid
, seq
, 0, NL80211_CMD_TESTMODE
);
4064 NLA_PUT_U32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4065 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
4067 ((void **)skb
->cb
)[0] = rdev
;
4068 ((void **)skb
->cb
)[1] = hdr
;
4069 ((void **)skb
->cb
)[2] = data
;
4078 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
4081 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4083 if (WARN_ON(!rdev
->testmode_info
))
4086 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
4087 rdev
->testmode_info
->snd_pid
,
4088 rdev
->testmode_info
->snd_seq
,
4091 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
4093 int cfg80211_testmode_reply(struct sk_buff
*skb
)
4095 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
4096 void *hdr
= ((void **)skb
->cb
)[1];
4097 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4099 if (WARN_ON(!rdev
->testmode_info
)) {
4104 nla_nest_end(skb
, data
);
4105 genlmsg_end(skb
, hdr
);
4106 return genlmsg_reply(skb
, rdev
->testmode_info
);
4108 EXPORT_SYMBOL(cfg80211_testmode_reply
);
4110 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
4111 int approxlen
, gfp_t gfp
)
4113 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4115 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
4117 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
4119 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
4121 void *hdr
= ((void **)skb
->cb
)[1];
4122 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4124 nla_nest_end(skb
, data
);
4125 genlmsg_end(skb
, hdr
);
4126 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
4128 EXPORT_SYMBOL(cfg80211_testmode_event
);
4131 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
4133 struct cfg80211_registered_device
*rdev
;
4134 struct net_device
*dev
;
4135 struct cfg80211_connect_params connect
;
4136 struct wiphy
*wiphy
;
4137 struct cfg80211_cached_keys
*connkeys
= NULL
;
4140 memset(&connect
, 0, sizeof(connect
));
4142 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4145 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
4146 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
4149 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
4151 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4152 if (!nl80211_valid_auth_type(connect
.auth_type
))
4155 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
4157 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
4159 err
= nl80211_crypto_settings(info
, &connect
.crypto
,
4160 NL80211_MAX_NR_CIPHER_SUITES
);
4165 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4169 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4174 if (!netif_running(dev
)) {
4179 wiphy
= &rdev
->wiphy
;
4181 if (info
->attrs
[NL80211_ATTR_MAC
])
4182 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4183 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4184 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4186 if (info
->attrs
[NL80211_ATTR_IE
]) {
4187 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4188 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4191 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
4193 ieee80211_get_channel(wiphy
,
4194 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4195 if (!connect
.channel
||
4196 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
4202 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
4203 connkeys
= nl80211_parse_connkeys(rdev
,
4204 info
->attrs
[NL80211_ATTR_KEYS
]);
4205 if (IS_ERR(connkeys
)) {
4206 err
= PTR_ERR(connkeys
);
4212 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
4215 cfg80211_unlock_rdev(rdev
);
4224 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
4226 struct cfg80211_registered_device
*rdev
;
4227 struct net_device
*dev
;
4231 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4232 reason
= WLAN_REASON_DEAUTH_LEAVING
;
4234 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4241 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4245 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4250 if (!netif_running(dev
)) {
4255 err
= cfg80211_disconnect(rdev
, dev
, reason
, true);
4258 cfg80211_unlock_rdev(rdev
);
4265 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
4267 struct cfg80211_registered_device
*rdev
;
4272 if (!info
->attrs
[NL80211_ATTR_PID
])
4275 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
4279 rdev
= cfg80211_get_dev_from_info(info
);
4281 err
= PTR_ERR(rdev
);
4285 net
= get_net_ns_by_pid(pid
);
4293 /* check if anything to do */
4294 if (net_eq(wiphy_net(&rdev
->wiphy
), net
))
4297 err
= cfg80211_switch_netns(rdev
, net
);
4301 cfg80211_unlock_rdev(rdev
);
4307 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4309 struct cfg80211_registered_device
*rdev
;
4310 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
4311 struct cfg80211_pmksa
*pmksa
) = NULL
;
4313 struct net_device
*dev
;
4314 struct cfg80211_pmksa pmksa
;
4316 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
4318 if (!info
->attrs
[NL80211_ATTR_MAC
])
4321 if (!info
->attrs
[NL80211_ATTR_PMKID
])
4326 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4330 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
4331 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4333 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4338 switch (info
->genlhdr
->cmd
) {
4339 case NL80211_CMD_SET_PMKSA
:
4340 rdev_ops
= rdev
->ops
->set_pmksa
;
4342 case NL80211_CMD_DEL_PMKSA
:
4343 rdev_ops
= rdev
->ops
->del_pmksa
;
4355 err
= rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
4358 cfg80211_unlock_rdev(rdev
);
4366 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4368 struct cfg80211_registered_device
*rdev
;
4370 struct net_device
*dev
;
4374 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4378 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4383 if (!rdev
->ops
->flush_pmksa
) {
4388 err
= rdev
->ops
->flush_pmksa(&rdev
->wiphy
, dev
);
4391 cfg80211_unlock_rdev(rdev
);
4400 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
4401 struct genl_info
*info
)
4403 struct cfg80211_registered_device
*rdev
;
4404 struct net_device
*dev
;
4405 struct ieee80211_channel
*chan
;
4406 struct sk_buff
*msg
;
4409 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
4413 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
4414 !info
->attrs
[NL80211_ATTR_DURATION
])
4417 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
4420 * We should be on that channel for at least one jiffie,
4421 * and more than 5 seconds seems excessive.
4423 if (!duration
|| !msecs_to_jiffies(duration
) || duration
> 5000)
4428 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4432 if (!rdev
->ops
->remain_on_channel
) {
4437 if (!netif_running(dev
)) {
4442 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
4443 channel_type
= nla_get_u32(
4444 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
4445 if (channel_type
!= NL80211_CHAN_NO_HT
&&
4446 channel_type
!= NL80211_CHAN_HT20
&&
4447 channel_type
!= NL80211_CHAN_HT40PLUS
&&
4448 channel_type
!= NL80211_CHAN_HT40MINUS
) {
4454 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
4455 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
4461 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4467 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4468 NL80211_CMD_REMAIN_ON_CHANNEL
);
4475 err
= rdev
->ops
->remain_on_channel(&rdev
->wiphy
, dev
, chan
,
4476 channel_type
, duration
, &cookie
);
4481 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
4483 genlmsg_end(msg
, hdr
);
4484 err
= genlmsg_reply(msg
, info
);
4492 cfg80211_unlock_rdev(rdev
);
4499 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
4500 struct genl_info
*info
)
4502 struct cfg80211_registered_device
*rdev
;
4503 struct net_device
*dev
;
4507 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
4512 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4516 if (!rdev
->ops
->cancel_remain_on_channel
) {
4521 if (!netif_running(dev
)) {
4526 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
4528 err
= rdev
->ops
->cancel_remain_on_channel(&rdev
->wiphy
, dev
, cookie
);
4531 cfg80211_unlock_rdev(rdev
);
4538 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
4539 u8
*rates
, u8 rates_len
)
4544 for (i
= 0; i
< rates_len
; i
++) {
4545 int rate
= (rates
[i
] & 0x7f) * 5;
4547 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
4548 struct ieee80211_rate
*srate
=
4549 &sband
->bitrates
[ridx
];
4550 if (rate
== srate
->bitrate
) {
4555 if (ridx
== sband
->n_bitrates
)
4556 return 0; /* rate not found */
4562 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
4563 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
4564 .len
= NL80211_MAX_SUPP_RATES
},
4567 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
4568 struct genl_info
*info
)
4570 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
4571 struct cfg80211_registered_device
*rdev
;
4572 struct cfg80211_bitrate_mask mask
;
4574 struct net_device
*dev
;
4575 struct nlattr
*tx_rates
;
4576 struct ieee80211_supported_band
*sband
;
4578 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
4583 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4587 if (!rdev
->ops
->set_bitrate_mask
) {
4592 memset(&mask
, 0, sizeof(mask
));
4593 /* Default to all rates enabled */
4594 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
4595 sband
= rdev
->wiphy
.bands
[i
];
4596 mask
.control
[i
].legacy
=
4597 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
4601 * The nested attribute uses enum nl80211_band as the index. This maps
4602 * directly to the enum ieee80211_band values used in cfg80211.
4604 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
4606 enum ieee80211_band band
= nla_type(tx_rates
);
4607 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
4611 sband
= rdev
->wiphy
.bands
[band
];
4612 if (sband
== NULL
) {
4616 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
4617 nla_len(tx_rates
), nl80211_txattr_policy
);
4618 if (tb
[NL80211_TXRATE_LEGACY
]) {
4619 mask
.control
[band
].legacy
= rateset_to_mask(
4621 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
4622 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
4623 if (mask
.control
[band
].legacy
== 0) {
4630 err
= rdev
->ops
->set_bitrate_mask(&rdev
->wiphy
, dev
, NULL
, &mask
);
4634 cfg80211_unlock_rdev(rdev
);
4640 static int nl80211_register_action(struct sk_buff
*skb
, struct genl_info
*info
)
4642 struct cfg80211_registered_device
*rdev
;
4643 struct net_device
*dev
;
4646 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
4649 if (nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]) < 1)
4654 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4658 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4663 /* not much point in registering if we can't reply */
4664 if (!rdev
->ops
->action
) {
4669 err
= cfg80211_mlme_register_action(dev
->ieee80211_ptr
, info
->snd_pid
,
4670 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
4671 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
4673 cfg80211_unlock_rdev(rdev
);
4680 static int nl80211_action(struct sk_buff
*skb
, struct genl_info
*info
)
4682 struct cfg80211_registered_device
*rdev
;
4683 struct net_device
*dev
;
4684 struct ieee80211_channel
*chan
;
4685 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
4690 struct sk_buff
*msg
;
4692 if (!info
->attrs
[NL80211_ATTR_FRAME
] ||
4693 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4698 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4702 if (!rdev
->ops
->action
) {
4707 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4712 if (!netif_running(dev
)) {
4717 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
4718 channel_type
= nla_get_u32(
4719 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
4720 if (channel_type
!= NL80211_CHAN_NO_HT
&&
4721 channel_type
!= NL80211_CHAN_HT20
&&
4722 channel_type
!= NL80211_CHAN_HT40PLUS
&&
4723 channel_type
!= NL80211_CHAN_HT40MINUS
) {
4729 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
4730 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
4736 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4742 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4743 NL80211_CMD_ACTION
);
4749 err
= cfg80211_mlme_action(rdev
, dev
, chan
, channel_type
,
4750 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
4751 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
4756 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
4758 genlmsg_end(msg
, hdr
);
4759 err
= genlmsg_reply(msg
, info
);
4767 cfg80211_unlock_rdev(rdev
);
4774 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
4776 struct cfg80211_registered_device
*rdev
;
4777 struct wireless_dev
*wdev
;
4778 struct net_device
*dev
;
4783 if (!info
->attrs
[NL80211_ATTR_PS_STATE
]) {
4788 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
4790 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
) {
4797 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4801 wdev
= dev
->ieee80211_ptr
;
4803 if (!rdev
->ops
->set_power_mgmt
) {
4808 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
4810 if (state
== wdev
->ps
)
4815 if (rdev
->ops
->set_power_mgmt(wdev
->wiphy
, dev
, wdev
->ps
,
4817 /* assume this means it's off */
4821 cfg80211_unlock_rdev(rdev
);
4829 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
4831 struct cfg80211_registered_device
*rdev
;
4832 enum nl80211_ps_state ps_state
;
4833 struct wireless_dev
*wdev
;
4834 struct net_device
*dev
;
4835 struct sk_buff
*msg
;
4841 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4845 wdev
= dev
->ieee80211_ptr
;
4847 if (!rdev
->ops
->set_power_mgmt
) {
4852 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4858 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4859 NL80211_CMD_GET_POWER_SAVE
);
4866 ps_state
= NL80211_PS_ENABLED
;
4868 ps_state
= NL80211_PS_DISABLED
;
4870 NLA_PUT_U32(msg
, NL80211_ATTR_PS_STATE
, ps_state
);
4872 genlmsg_end(msg
, hdr
);
4873 err
= genlmsg_reply(msg
, info
);
4883 cfg80211_unlock_rdev(rdev
);
4892 static struct nla_policy
4893 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
4894 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
4895 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
4896 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
4899 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
4900 s32 threshold
, u32 hysteresis
)
4902 struct cfg80211_registered_device
*rdev
;
4903 struct wireless_dev
*wdev
;
4904 struct net_device
*dev
;
4912 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4916 wdev
= dev
->ieee80211_ptr
;
4918 if (!rdev
->ops
->set_cqm_rssi_config
) {
4923 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
) {
4928 err
= rdev
->ops
->set_cqm_rssi_config(wdev
->wiphy
, dev
,
4929 threshold
, hysteresis
);
4932 cfg80211_unlock_rdev(rdev
);
4940 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
4942 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
4946 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
4952 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
4953 nl80211_attr_cqm_policy
);
4957 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
4958 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
4961 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
4962 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
4963 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
4971 static struct genl_ops nl80211_ops
[] = {
4973 .cmd
= NL80211_CMD_GET_WIPHY
,
4974 .doit
= nl80211_get_wiphy
,
4975 .dumpit
= nl80211_dump_wiphy
,
4976 .policy
= nl80211_policy
,
4977 /* can be retrieved by unprivileged users */
4980 .cmd
= NL80211_CMD_SET_WIPHY
,
4981 .doit
= nl80211_set_wiphy
,
4982 .policy
= nl80211_policy
,
4983 .flags
= GENL_ADMIN_PERM
,
4986 .cmd
= NL80211_CMD_GET_INTERFACE
,
4987 .doit
= nl80211_get_interface
,
4988 .dumpit
= nl80211_dump_interface
,
4989 .policy
= nl80211_policy
,
4990 /* can be retrieved by unprivileged users */
4993 .cmd
= NL80211_CMD_SET_INTERFACE
,
4994 .doit
= nl80211_set_interface
,
4995 .policy
= nl80211_policy
,
4996 .flags
= GENL_ADMIN_PERM
,
4999 .cmd
= NL80211_CMD_NEW_INTERFACE
,
5000 .doit
= nl80211_new_interface
,
5001 .policy
= nl80211_policy
,
5002 .flags
= GENL_ADMIN_PERM
,
5005 .cmd
= NL80211_CMD_DEL_INTERFACE
,
5006 .doit
= nl80211_del_interface
,
5007 .policy
= nl80211_policy
,
5008 .flags
= GENL_ADMIN_PERM
,
5011 .cmd
= NL80211_CMD_GET_KEY
,
5012 .doit
= nl80211_get_key
,
5013 .policy
= nl80211_policy
,
5014 .flags
= GENL_ADMIN_PERM
,
5017 .cmd
= NL80211_CMD_SET_KEY
,
5018 .doit
= nl80211_set_key
,
5019 .policy
= nl80211_policy
,
5020 .flags
= GENL_ADMIN_PERM
,
5023 .cmd
= NL80211_CMD_NEW_KEY
,
5024 .doit
= nl80211_new_key
,
5025 .policy
= nl80211_policy
,
5026 .flags
= GENL_ADMIN_PERM
,
5029 .cmd
= NL80211_CMD_DEL_KEY
,
5030 .doit
= nl80211_del_key
,
5031 .policy
= nl80211_policy
,
5032 .flags
= GENL_ADMIN_PERM
,
5035 .cmd
= NL80211_CMD_SET_BEACON
,
5036 .policy
= nl80211_policy
,
5037 .flags
= GENL_ADMIN_PERM
,
5038 .doit
= nl80211_addset_beacon
,
5041 .cmd
= NL80211_CMD_NEW_BEACON
,
5042 .policy
= nl80211_policy
,
5043 .flags
= GENL_ADMIN_PERM
,
5044 .doit
= nl80211_addset_beacon
,
5047 .cmd
= NL80211_CMD_DEL_BEACON
,
5048 .policy
= nl80211_policy
,
5049 .flags
= GENL_ADMIN_PERM
,
5050 .doit
= nl80211_del_beacon
,
5053 .cmd
= NL80211_CMD_GET_STATION
,
5054 .doit
= nl80211_get_station
,
5055 .dumpit
= nl80211_dump_station
,
5056 .policy
= nl80211_policy
,
5059 .cmd
= NL80211_CMD_SET_STATION
,
5060 .doit
= nl80211_set_station
,
5061 .policy
= nl80211_policy
,
5062 .flags
= GENL_ADMIN_PERM
,
5065 .cmd
= NL80211_CMD_NEW_STATION
,
5066 .doit
= nl80211_new_station
,
5067 .policy
= nl80211_policy
,
5068 .flags
= GENL_ADMIN_PERM
,
5071 .cmd
= NL80211_CMD_DEL_STATION
,
5072 .doit
= nl80211_del_station
,
5073 .policy
= nl80211_policy
,
5074 .flags
= GENL_ADMIN_PERM
,
5077 .cmd
= NL80211_CMD_GET_MPATH
,
5078 .doit
= nl80211_get_mpath
,
5079 .dumpit
= nl80211_dump_mpath
,
5080 .policy
= nl80211_policy
,
5081 .flags
= GENL_ADMIN_PERM
,
5084 .cmd
= NL80211_CMD_SET_MPATH
,
5085 .doit
= nl80211_set_mpath
,
5086 .policy
= nl80211_policy
,
5087 .flags
= GENL_ADMIN_PERM
,
5090 .cmd
= NL80211_CMD_NEW_MPATH
,
5091 .doit
= nl80211_new_mpath
,
5092 .policy
= nl80211_policy
,
5093 .flags
= GENL_ADMIN_PERM
,
5096 .cmd
= NL80211_CMD_DEL_MPATH
,
5097 .doit
= nl80211_del_mpath
,
5098 .policy
= nl80211_policy
,
5099 .flags
= GENL_ADMIN_PERM
,
5102 .cmd
= NL80211_CMD_SET_BSS
,
5103 .doit
= nl80211_set_bss
,
5104 .policy
= nl80211_policy
,
5105 .flags
= GENL_ADMIN_PERM
,
5108 .cmd
= NL80211_CMD_GET_REG
,
5109 .doit
= nl80211_get_reg
,
5110 .policy
= nl80211_policy
,
5111 /* can be retrieved by unprivileged users */
5114 .cmd
= NL80211_CMD_SET_REG
,
5115 .doit
= nl80211_set_reg
,
5116 .policy
= nl80211_policy
,
5117 .flags
= GENL_ADMIN_PERM
,
5120 .cmd
= NL80211_CMD_REQ_SET_REG
,
5121 .doit
= nl80211_req_set_reg
,
5122 .policy
= nl80211_policy
,
5123 .flags
= GENL_ADMIN_PERM
,
5126 .cmd
= NL80211_CMD_GET_MESH_PARAMS
,
5127 .doit
= nl80211_get_mesh_params
,
5128 .policy
= nl80211_policy
,
5129 /* can be retrieved by unprivileged users */
5132 .cmd
= NL80211_CMD_SET_MESH_PARAMS
,
5133 .doit
= nl80211_set_mesh_params
,
5134 .policy
= nl80211_policy
,
5135 .flags
= GENL_ADMIN_PERM
,
5138 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
5139 .doit
= nl80211_trigger_scan
,
5140 .policy
= nl80211_policy
,
5141 .flags
= GENL_ADMIN_PERM
,
5144 .cmd
= NL80211_CMD_GET_SCAN
,
5145 .policy
= nl80211_policy
,
5146 .dumpit
= nl80211_dump_scan
,
5149 .cmd
= NL80211_CMD_AUTHENTICATE
,
5150 .doit
= nl80211_authenticate
,
5151 .policy
= nl80211_policy
,
5152 .flags
= GENL_ADMIN_PERM
,
5155 .cmd
= NL80211_CMD_ASSOCIATE
,
5156 .doit
= nl80211_associate
,
5157 .policy
= nl80211_policy
,
5158 .flags
= GENL_ADMIN_PERM
,
5161 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
5162 .doit
= nl80211_deauthenticate
,
5163 .policy
= nl80211_policy
,
5164 .flags
= GENL_ADMIN_PERM
,
5167 .cmd
= NL80211_CMD_DISASSOCIATE
,
5168 .doit
= nl80211_disassociate
,
5169 .policy
= nl80211_policy
,
5170 .flags
= GENL_ADMIN_PERM
,
5173 .cmd
= NL80211_CMD_JOIN_IBSS
,
5174 .doit
= nl80211_join_ibss
,
5175 .policy
= nl80211_policy
,
5176 .flags
= GENL_ADMIN_PERM
,
5179 .cmd
= NL80211_CMD_LEAVE_IBSS
,
5180 .doit
= nl80211_leave_ibss
,
5181 .policy
= nl80211_policy
,
5182 .flags
= GENL_ADMIN_PERM
,
5184 #ifdef CONFIG_NL80211_TESTMODE
5186 .cmd
= NL80211_CMD_TESTMODE
,
5187 .doit
= nl80211_testmode_do
,
5188 .policy
= nl80211_policy
,
5189 .flags
= GENL_ADMIN_PERM
,
5193 .cmd
= NL80211_CMD_CONNECT
,
5194 .doit
= nl80211_connect
,
5195 .policy
= nl80211_policy
,
5196 .flags
= GENL_ADMIN_PERM
,
5199 .cmd
= NL80211_CMD_DISCONNECT
,
5200 .doit
= nl80211_disconnect
,
5201 .policy
= nl80211_policy
,
5202 .flags
= GENL_ADMIN_PERM
,
5205 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
5206 .doit
= nl80211_wiphy_netns
,
5207 .policy
= nl80211_policy
,
5208 .flags
= GENL_ADMIN_PERM
,
5211 .cmd
= NL80211_CMD_GET_SURVEY
,
5212 .policy
= nl80211_policy
,
5213 .dumpit
= nl80211_dump_survey
,
5216 .cmd
= NL80211_CMD_SET_PMKSA
,
5217 .doit
= nl80211_setdel_pmksa
,
5218 .policy
= nl80211_policy
,
5219 .flags
= GENL_ADMIN_PERM
,
5222 .cmd
= NL80211_CMD_DEL_PMKSA
,
5223 .doit
= nl80211_setdel_pmksa
,
5224 .policy
= nl80211_policy
,
5225 .flags
= GENL_ADMIN_PERM
,
5228 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
5229 .doit
= nl80211_flush_pmksa
,
5230 .policy
= nl80211_policy
,
5231 .flags
= GENL_ADMIN_PERM
,
5234 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
5235 .doit
= nl80211_remain_on_channel
,
5236 .policy
= nl80211_policy
,
5237 .flags
= GENL_ADMIN_PERM
,
5240 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
5241 .doit
= nl80211_cancel_remain_on_channel
,
5242 .policy
= nl80211_policy
,
5243 .flags
= GENL_ADMIN_PERM
,
5246 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
5247 .doit
= nl80211_set_tx_bitrate_mask
,
5248 .policy
= nl80211_policy
,
5249 .flags
= GENL_ADMIN_PERM
,
5252 .cmd
= NL80211_CMD_REGISTER_ACTION
,
5253 .doit
= nl80211_register_action
,
5254 .policy
= nl80211_policy
,
5255 .flags
= GENL_ADMIN_PERM
,
5258 .cmd
= NL80211_CMD_ACTION
,
5259 .doit
= nl80211_action
,
5260 .policy
= nl80211_policy
,
5261 .flags
= GENL_ADMIN_PERM
,
5264 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
5265 .doit
= nl80211_set_power_save
,
5266 .policy
= nl80211_policy
,
5267 .flags
= GENL_ADMIN_PERM
,
5270 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
5271 .doit
= nl80211_get_power_save
,
5272 .policy
= nl80211_policy
,
5273 /* can be retrieved by unprivileged users */
5276 .cmd
= NL80211_CMD_SET_CQM
,
5277 .doit
= nl80211_set_cqm
,
5278 .policy
= nl80211_policy
,
5279 .flags
= GENL_ADMIN_PERM
,
5282 .cmd
= NL80211_CMD_SET_CHANNEL
,
5283 .doit
= nl80211_set_channel
,
5284 .policy
= nl80211_policy
,
5285 .flags
= GENL_ADMIN_PERM
,
5289 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
5293 /* multicast groups */
5294 static struct genl_multicast_group nl80211_config_mcgrp
= {
5297 static struct genl_multicast_group nl80211_scan_mcgrp
= {
5300 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
5301 .name
= "regulatory",
5304 /* notification functions */
5306 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
5308 struct sk_buff
*msg
;
5310 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5314 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
5319 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5320 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
5323 static int nl80211_add_scan_req(struct sk_buff
*msg
,
5324 struct cfg80211_registered_device
*rdev
)
5326 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
5327 struct nlattr
*nest
;
5330 ASSERT_RDEV_LOCK(rdev
);
5335 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
5337 goto nla_put_failure
;
5338 for (i
= 0; i
< req
->n_ssids
; i
++)
5339 NLA_PUT(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
);
5340 nla_nest_end(msg
, nest
);
5342 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
5344 goto nla_put_failure
;
5345 for (i
= 0; i
< req
->n_channels
; i
++)
5346 NLA_PUT_U32(msg
, i
, req
->channels
[i
]->center_freq
);
5347 nla_nest_end(msg
, nest
);
5350 NLA_PUT(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
);
5357 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
5358 struct cfg80211_registered_device
*rdev
,
5359 struct net_device
*netdev
,
5360 u32 pid
, u32 seq
, int flags
,
5365 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
5369 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5370 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5372 /* ignore errors and send incomplete event anyway */
5373 nl80211_add_scan_req(msg
, rdev
);
5375 return genlmsg_end(msg
, hdr
);
5378 genlmsg_cancel(msg
, hdr
);
5382 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
5383 struct net_device
*netdev
)
5385 struct sk_buff
*msg
;
5387 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
5391 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5392 NL80211_CMD_TRIGGER_SCAN
) < 0) {
5397 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5398 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5401 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
5402 struct net_device
*netdev
)
5404 struct sk_buff
*msg
;
5406 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5410 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5411 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
5416 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5417 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5420 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
5421 struct net_device
*netdev
)
5423 struct sk_buff
*msg
;
5425 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5429 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5430 NL80211_CMD_SCAN_ABORTED
) < 0) {
5435 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5436 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5440 * This can happen on global regulatory changes or device specific settings
5441 * based on custom world regulatory domains.
5443 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
5445 struct sk_buff
*msg
;
5448 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5452 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
5458 /* Userspace can always count this one always being set */
5459 NLA_PUT_U8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
);
5461 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0')
5462 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5463 NL80211_REGDOM_TYPE_WORLD
);
5464 else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9')
5465 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5466 NL80211_REGDOM_TYPE_CUSTOM_WORLD
);
5467 else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
5469 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5470 NL80211_REGDOM_TYPE_INTERSECTION
);
5472 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5473 NL80211_REGDOM_TYPE_COUNTRY
);
5474 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, request
->alpha2
);
5477 if (wiphy_idx_valid(request
->wiphy_idx
))
5478 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
);
5480 if (genlmsg_end(msg
, hdr
) < 0) {
5486 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
5493 genlmsg_cancel(msg
, hdr
);
5497 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
5498 struct net_device
*netdev
,
5499 const u8
*buf
, size_t len
,
5500 enum nl80211_commands cmd
, gfp_t gfp
)
5502 struct sk_buff
*msg
;
5505 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5509 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
5515 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5516 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5517 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
5519 if (genlmsg_end(msg
, hdr
) < 0) {
5524 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5525 nl80211_mlme_mcgrp
.id
, gfp
);
5529 genlmsg_cancel(msg
, hdr
);
5533 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
5534 struct net_device
*netdev
, const u8
*buf
,
5535 size_t len
, gfp_t gfp
)
5537 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5538 NL80211_CMD_AUTHENTICATE
, gfp
);
5541 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
5542 struct net_device
*netdev
, const u8
*buf
,
5543 size_t len
, gfp_t gfp
)
5545 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5546 NL80211_CMD_ASSOCIATE
, gfp
);
5549 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
5550 struct net_device
*netdev
, const u8
*buf
,
5551 size_t len
, gfp_t gfp
)
5553 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5554 NL80211_CMD_DEAUTHENTICATE
, gfp
);
5557 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
5558 struct net_device
*netdev
, const u8
*buf
,
5559 size_t len
, gfp_t gfp
)
5561 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5562 NL80211_CMD_DISASSOCIATE
, gfp
);
5565 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
5566 struct net_device
*netdev
, int cmd
,
5567 const u8
*addr
, gfp_t gfp
)
5569 struct sk_buff
*msg
;
5572 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5576 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
5582 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5583 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5584 NLA_PUT_FLAG(msg
, NL80211_ATTR_TIMED_OUT
);
5585 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5587 if (genlmsg_end(msg
, hdr
) < 0) {
5592 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5593 nl80211_mlme_mcgrp
.id
, gfp
);
5597 genlmsg_cancel(msg
, hdr
);
5601 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
5602 struct net_device
*netdev
, const u8
*addr
,
5605 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
5609 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
5610 struct net_device
*netdev
, const u8
*addr
,
5613 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
5617 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
5618 struct net_device
*netdev
, const u8
*bssid
,
5619 const u8
*req_ie
, size_t req_ie_len
,
5620 const u8
*resp_ie
, size_t resp_ie_len
,
5621 u16 status
, gfp_t gfp
)
5623 struct sk_buff
*msg
;
5626 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
5630 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
5636 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5637 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5639 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
5640 NLA_PUT_U16(msg
, NL80211_ATTR_STATUS_CODE
, status
);
5642 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
5644 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
5646 if (genlmsg_end(msg
, hdr
) < 0) {
5651 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5652 nl80211_mlme_mcgrp
.id
, gfp
);
5656 genlmsg_cancel(msg
, hdr
);
5661 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
5662 struct net_device
*netdev
, const u8
*bssid
,
5663 const u8
*req_ie
, size_t req_ie_len
,
5664 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
5666 struct sk_buff
*msg
;
5669 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
5673 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
5679 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5680 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5681 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
5683 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
5685 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
5687 if (genlmsg_end(msg
, hdr
) < 0) {
5692 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5693 nl80211_mlme_mcgrp
.id
, gfp
);
5697 genlmsg_cancel(msg
, hdr
);
5702 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
5703 struct net_device
*netdev
, u16 reason
,
5704 const u8
*ie
, size_t ie_len
, bool from_ap
)
5706 struct sk_buff
*msg
;
5709 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
5713 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
5719 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5720 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5721 if (from_ap
&& reason
)
5722 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason
);
5724 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
);
5726 NLA_PUT(msg
, NL80211_ATTR_IE
, ie_len
, ie
);
5728 if (genlmsg_end(msg
, hdr
) < 0) {
5733 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5734 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
5738 genlmsg_cancel(msg
, hdr
);
5743 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
5744 struct net_device
*netdev
, const u8
*bssid
,
5747 struct sk_buff
*msg
;
5750 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5754 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
5760 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5761 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5762 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
5764 if (genlmsg_end(msg
, hdr
) < 0) {
5769 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5770 nl80211_mlme_mcgrp
.id
, gfp
);
5774 genlmsg_cancel(msg
, hdr
);
5778 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
5779 struct net_device
*netdev
, const u8
*addr
,
5780 enum nl80211_key_type key_type
, int key_id
,
5781 const u8
*tsc
, gfp_t gfp
)
5783 struct sk_buff
*msg
;
5786 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5790 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
5796 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5797 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5799 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5800 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
);
5801 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_id
);
5803 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
);
5805 if (genlmsg_end(msg
, hdr
) < 0) {
5810 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5811 nl80211_mlme_mcgrp
.id
, gfp
);
5815 genlmsg_cancel(msg
, hdr
);
5819 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
5820 struct ieee80211_channel
*channel_before
,
5821 struct ieee80211_channel
*channel_after
)
5823 struct sk_buff
*msg
;
5825 struct nlattr
*nl_freq
;
5827 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
5831 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
5838 * Since we are applying the beacon hint to a wiphy we know its
5839 * wiphy_idx is valid
5841 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
));
5844 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
5846 goto nla_put_failure
;
5847 if (nl80211_msg_put_channel(msg
, channel_before
))
5848 goto nla_put_failure
;
5849 nla_nest_end(msg
, nl_freq
);
5852 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
5854 goto nla_put_failure
;
5855 if (nl80211_msg_put_channel(msg
, channel_after
))
5856 goto nla_put_failure
;
5857 nla_nest_end(msg
, nl_freq
);
5859 if (genlmsg_end(msg
, hdr
) < 0) {
5865 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
5872 genlmsg_cancel(msg
, hdr
);
5876 static void nl80211_send_remain_on_chan_event(
5877 int cmd
, struct cfg80211_registered_device
*rdev
,
5878 struct net_device
*netdev
, u64 cookie
,
5879 struct ieee80211_channel
*chan
,
5880 enum nl80211_channel_type channel_type
,
5881 unsigned int duration
, gfp_t gfp
)
5883 struct sk_buff
*msg
;
5886 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5890 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
5896 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5897 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5898 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
);
5899 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, channel_type
);
5900 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
5902 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
)
5903 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, duration
);
5905 if (genlmsg_end(msg
, hdr
) < 0) {
5910 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5911 nl80211_mlme_mcgrp
.id
, gfp
);
5915 genlmsg_cancel(msg
, hdr
);
5919 void nl80211_send_remain_on_channel(struct cfg80211_registered_device
*rdev
,
5920 struct net_device
*netdev
, u64 cookie
,
5921 struct ieee80211_channel
*chan
,
5922 enum nl80211_channel_type channel_type
,
5923 unsigned int duration
, gfp_t gfp
)
5925 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
5926 rdev
, netdev
, cookie
, chan
,
5927 channel_type
, duration
, gfp
);
5930 void nl80211_send_remain_on_channel_cancel(
5931 struct cfg80211_registered_device
*rdev
, struct net_device
*netdev
,
5932 u64 cookie
, struct ieee80211_channel
*chan
,
5933 enum nl80211_channel_type channel_type
, gfp_t gfp
)
5935 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
5936 rdev
, netdev
, cookie
, chan
,
5937 channel_type
, 0, gfp
);
5940 void nl80211_send_sta_event(struct cfg80211_registered_device
*rdev
,
5941 struct net_device
*dev
, const u8
*mac_addr
,
5942 struct station_info
*sinfo
, gfp_t gfp
)
5944 struct sk_buff
*msg
;
5946 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
5950 if (nl80211_send_station(msg
, 0, 0, 0, dev
, mac_addr
, sinfo
) < 0) {
5955 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5956 nl80211_mlme_mcgrp
.id
, gfp
);
5959 int nl80211_send_action(struct cfg80211_registered_device
*rdev
,
5960 struct net_device
*netdev
, u32 nlpid
,
5961 int freq
, const u8
*buf
, size_t len
, gfp_t gfp
)
5963 struct sk_buff
*msg
;
5967 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5971 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ACTION
);
5977 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5978 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5979 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
5980 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
5982 err
= genlmsg_end(msg
, hdr
);
5988 err
= genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
5994 genlmsg_cancel(msg
, hdr
);
5999 void nl80211_send_action_tx_status(struct cfg80211_registered_device
*rdev
,
6000 struct net_device
*netdev
, u64 cookie
,
6001 const u8
*buf
, size_t len
, bool ack
,
6004 struct sk_buff
*msg
;
6007 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6011 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ACTION_TX_STATUS
);
6017 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6018 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6019 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
6020 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
6022 NLA_PUT_FLAG(msg
, NL80211_ATTR_ACK
);
6024 if (genlmsg_end(msg
, hdr
) < 0) {
6029 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
6033 genlmsg_cancel(msg
, hdr
);
6038 nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device
*rdev
,
6039 struct net_device
*netdev
,
6040 enum nl80211_cqm_rssi_threshold_event rssi_event
,
6043 struct sk_buff
*msg
;
6044 struct nlattr
*pinfoattr
;
6047 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6051 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
6057 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6058 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6060 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
6062 goto nla_put_failure
;
6064 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
6067 nla_nest_end(msg
, pinfoattr
);
6069 if (genlmsg_end(msg
, hdr
) < 0) {
6074 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6075 nl80211_mlme_mcgrp
.id
, gfp
);
6079 genlmsg_cancel(msg
, hdr
);
6083 static int nl80211_netlink_notify(struct notifier_block
* nb
,
6084 unsigned long state
,
6087 struct netlink_notify
*notify
= _notify
;
6088 struct cfg80211_registered_device
*rdev
;
6089 struct wireless_dev
*wdev
;
6091 if (state
!= NETLINK_URELEASE
)
6096 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
)
6097 list_for_each_entry_rcu(wdev
, &rdev
->netdev_list
, list
)
6098 cfg80211_mlme_unregister_actions(wdev
, notify
->pid
);
6105 static struct notifier_block nl80211_netlink_notifier
= {
6106 .notifier_call
= nl80211_netlink_notify
,
6109 /* initialisation/exit functions */
6111 int nl80211_init(void)
6115 err
= genl_register_family_with_ops(&nl80211_fam
,
6116 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
6120 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
6124 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
6128 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
6132 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
6136 #ifdef CONFIG_NL80211_TESTMODE
6137 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
6142 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
6148 genl_unregister_family(&nl80211_fam
);
6152 void nl80211_exit(void)
6154 netlink_unregister_notifier(&nl80211_netlink_notifier
);
6155 genl_unregister_family(&nl80211_fam
);