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
);
771 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
773 struct cfg80211_registered_device
*rdev
;
774 struct net_device
*netdev
= NULL
;
775 struct wireless_dev
*wdev
;
776 int result
, rem_txq_params
= 0;
777 struct nlattr
*nl_txq_params
;
779 u8 retry_short
= 0, retry_long
= 0;
780 u32 frag_threshold
= 0, rts_threshold
= 0;
781 u8 coverage_class
= 0;
786 * Try to find the wiphy and netdev. Normally this
787 * function shouldn't need the netdev, but this is
788 * done for backward compatibility -- previously
789 * setting the channel was done per wiphy, but now
790 * it is per netdev. Previous userland like hostapd
791 * also passed a netdev to set_wiphy, so that it is
792 * possible to let that go to the right netdev!
794 mutex_lock(&cfg80211_mutex
);
796 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
797 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
799 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
800 if (netdev
&& netdev
->ieee80211_ptr
) {
801 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
802 mutex_lock(&rdev
->mtx
);
808 rdev
= __cfg80211_rdev_from_info(info
);
810 mutex_unlock(&cfg80211_mutex
);
811 result
= PTR_ERR(rdev
);
818 mutex_lock(&rdev
->mtx
);
819 } else if (netif_running(netdev
) &&
820 nl80211_can_set_dev_channel(netdev
->ieee80211_ptr
))
821 wdev
= netdev
->ieee80211_ptr
;
826 * end workaround code, by now the rdev is available
827 * and locked, and wdev may or may not be NULL.
830 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
831 result
= cfg80211_dev_rename(
832 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
834 mutex_unlock(&cfg80211_mutex
);
839 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
840 struct ieee80211_txq_params txq_params
;
841 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
843 if (!rdev
->ops
->set_txq_params
) {
844 result
= -EOPNOTSUPP
;
848 nla_for_each_nested(nl_txq_params
,
849 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
851 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
852 nla_data(nl_txq_params
),
853 nla_len(nl_txq_params
),
855 result
= parse_txq_params(tb
, &txq_params
);
859 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
866 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
867 result
= __nl80211_set_channel(rdev
, wdev
, info
);
874 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
875 retry_short
= nla_get_u8(
876 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
877 if (retry_short
== 0) {
881 changed
|= WIPHY_PARAM_RETRY_SHORT
;
884 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
885 retry_long
= nla_get_u8(
886 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
887 if (retry_long
== 0) {
891 changed
|= WIPHY_PARAM_RETRY_LONG
;
894 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
895 frag_threshold
= nla_get_u32(
896 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
897 if (frag_threshold
< 256) {
901 if (frag_threshold
!= (u32
) -1) {
903 * Fragments (apart from the last one) are required to
904 * have even length. Make the fragmentation code
905 * simpler by stripping LSB should someone try to use
906 * odd threshold value.
908 frag_threshold
&= ~0x1;
910 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
913 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
914 rts_threshold
= nla_get_u32(
915 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
916 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
919 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
920 coverage_class
= nla_get_u8(
921 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
922 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
926 u8 old_retry_short
, old_retry_long
;
927 u32 old_frag_threshold
, old_rts_threshold
;
928 u8 old_coverage_class
;
930 if (!rdev
->ops
->set_wiphy_params
) {
931 result
= -EOPNOTSUPP
;
935 old_retry_short
= rdev
->wiphy
.retry_short
;
936 old_retry_long
= rdev
->wiphy
.retry_long
;
937 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
938 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
939 old_coverage_class
= rdev
->wiphy
.coverage_class
;
941 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
942 rdev
->wiphy
.retry_short
= retry_short
;
943 if (changed
& WIPHY_PARAM_RETRY_LONG
)
944 rdev
->wiphy
.retry_long
= retry_long
;
945 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
946 rdev
->wiphy
.frag_threshold
= frag_threshold
;
947 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
948 rdev
->wiphy
.rts_threshold
= rts_threshold
;
949 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
950 rdev
->wiphy
.coverage_class
= coverage_class
;
952 result
= rdev
->ops
->set_wiphy_params(&rdev
->wiphy
, changed
);
954 rdev
->wiphy
.retry_short
= old_retry_short
;
955 rdev
->wiphy
.retry_long
= old_retry_long
;
956 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
957 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
958 rdev
->wiphy
.coverage_class
= old_coverage_class
;
963 mutex_unlock(&rdev
->mtx
);
972 static int nl80211_send_iface(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
973 struct cfg80211_registered_device
*rdev
,
974 struct net_device
*dev
)
978 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
982 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
983 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
984 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, dev
->name
);
985 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, dev
->ieee80211_ptr
->iftype
);
987 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
988 rdev
->devlist_generation
^
989 (cfg80211_rdev_list_generation
<< 2));
991 return genlmsg_end(msg
, hdr
);
994 genlmsg_cancel(msg
, hdr
);
998 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1002 int wp_start
= cb
->args
[0];
1003 int if_start
= cb
->args
[1];
1004 struct cfg80211_registered_device
*rdev
;
1005 struct wireless_dev
*wdev
;
1007 mutex_lock(&cfg80211_mutex
);
1008 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
1009 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
1011 if (wp_idx
< wp_start
) {
1017 mutex_lock(&rdev
->devlist_mtx
);
1018 list_for_each_entry(wdev
, &rdev
->netdev_list
, list
) {
1019 if (if_idx
< if_start
) {
1023 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).pid
,
1024 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1025 rdev
, wdev
->netdev
) < 0) {
1026 mutex_unlock(&rdev
->devlist_mtx
);
1031 mutex_unlock(&rdev
->devlist_mtx
);
1036 mutex_unlock(&cfg80211_mutex
);
1038 cb
->args
[0] = wp_idx
;
1039 cb
->args
[1] = if_idx
;
1044 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1046 struct sk_buff
*msg
;
1047 struct cfg80211_registered_device
*dev
;
1048 struct net_device
*netdev
;
1051 err
= get_rdev_dev_by_info_ifindex(info
, &dev
, &netdev
);
1055 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1059 if (nl80211_send_iface(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1064 cfg80211_unlock_rdev(dev
);
1066 return genlmsg_reply(msg
, info
);
1072 cfg80211_unlock_rdev(dev
);
1076 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
1077 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
1078 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
1079 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
1080 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
1081 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
1084 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
1086 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
1094 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
1095 nla
, mntr_flags_policy
))
1098 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
1100 *mntrflags
|= (1<<flag
);
1105 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
1106 struct net_device
*netdev
, u8 use_4addr
,
1107 enum nl80211_iftype iftype
)
1110 if (netdev
&& netdev
->br_port
)
1116 case NL80211_IFTYPE_AP_VLAN
:
1117 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
1120 case NL80211_IFTYPE_STATION
:
1121 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
1131 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1133 struct cfg80211_registered_device
*rdev
;
1134 struct vif_params params
;
1136 enum nl80211_iftype otype
, ntype
;
1137 struct net_device
*dev
;
1138 u32 _flags
, *flags
= NULL
;
1139 bool change
= false;
1141 memset(¶ms
, 0, sizeof(params
));
1145 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1149 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
1151 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1152 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1155 if (ntype
> NL80211_IFTYPE_MAX
) {
1161 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1162 if (ntype
!= NL80211_IFTYPE_MESH_POINT
) {
1166 params
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1167 params
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1171 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1172 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1174 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
1178 params
.use_4addr
= -1;
1181 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
1182 if (ntype
!= NL80211_IFTYPE_MONITOR
) {
1186 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
1196 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
1200 if (!err
&& params
.use_4addr
!= -1)
1201 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
1205 cfg80211_unlock_rdev(rdev
);
1211 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1213 struct cfg80211_registered_device
*rdev
;
1214 struct vif_params params
;
1216 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
1219 memset(¶ms
, 0, sizeof(params
));
1221 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
1224 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1225 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1226 if (type
> NL80211_IFTYPE_MAX
)
1232 rdev
= cfg80211_get_dev_from_info(info
);
1234 err
= PTR_ERR(rdev
);
1238 if (!rdev
->ops
->add_virtual_intf
||
1239 !(rdev
->wiphy
.interface_modes
& (1 << type
))) {
1244 if (type
== NL80211_IFTYPE_MESH_POINT
&&
1245 info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1246 params
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1247 params
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1250 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1251 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1252 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
1257 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
1258 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
1260 err
= rdev
->ops
->add_virtual_intf(&rdev
->wiphy
,
1261 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
1262 type
, err
? NULL
: &flags
, ¶ms
);
1265 cfg80211_unlock_rdev(rdev
);
1271 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1273 struct cfg80211_registered_device
*rdev
;
1275 struct net_device
*dev
;
1279 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1283 if (!rdev
->ops
->del_virtual_intf
) {
1288 err
= rdev
->ops
->del_virtual_intf(&rdev
->wiphy
, dev
);
1291 cfg80211_unlock_rdev(rdev
);
1298 struct get_key_cookie
{
1299 struct sk_buff
*msg
;
1304 static void get_key_callback(void *c
, struct key_params
*params
)
1307 struct get_key_cookie
*cookie
= c
;
1310 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
1311 params
->key_len
, params
->key
);
1314 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
1315 params
->seq_len
, params
->seq
);
1318 NLA_PUT_U32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
1321 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
1323 goto nla_put_failure
;
1326 NLA_PUT(cookie
->msg
, NL80211_KEY_DATA
,
1327 params
->key_len
, params
->key
);
1330 NLA_PUT(cookie
->msg
, NL80211_KEY_SEQ
,
1331 params
->seq_len
, params
->seq
);
1334 NLA_PUT_U32(cookie
->msg
, NL80211_KEY_CIPHER
,
1337 NLA_PUT_U8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
);
1339 nla_nest_end(cookie
->msg
, key
);
1346 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
1348 struct cfg80211_registered_device
*rdev
;
1350 struct net_device
*dev
;
1352 u8
*mac_addr
= NULL
;
1353 struct get_key_cookie cookie
= {
1357 struct sk_buff
*msg
;
1359 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
1360 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1365 if (info
->attrs
[NL80211_ATTR_MAC
])
1366 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1370 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1374 if (!rdev
->ops
->get_key
) {
1379 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1385 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1386 NL80211_CMD_NEW_KEY
);
1394 cookie
.idx
= key_idx
;
1396 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1397 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
1399 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1401 err
= rdev
->ops
->get_key(&rdev
->wiphy
, dev
, key_idx
, mac_addr
,
1402 &cookie
, get_key_callback
);
1408 goto nla_put_failure
;
1410 genlmsg_end(msg
, hdr
);
1411 err
= genlmsg_reply(msg
, info
);
1419 cfg80211_unlock_rdev(rdev
);
1427 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
1429 struct cfg80211_registered_device
*rdev
;
1430 struct key_parse key
;
1432 struct net_device
*dev
;
1433 int (*func
)(struct wiphy
*wiphy
, struct net_device
*netdev
,
1436 err
= nl80211_parse_key(info
, &key
);
1443 /* only support setting default key */
1444 if (!key
.def
&& !key
.defmgmt
)
1449 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1454 func
= rdev
->ops
->set_default_key
;
1456 func
= rdev
->ops
->set_default_mgmt_key
;
1463 wdev_lock(dev
->ieee80211_ptr
);
1464 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1466 err
= func(&rdev
->wiphy
, dev
, key
.idx
);
1468 #ifdef CONFIG_CFG80211_WEXT
1470 if (func
== rdev
->ops
->set_default_key
)
1471 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
1473 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
1476 wdev_unlock(dev
->ieee80211_ptr
);
1479 cfg80211_unlock_rdev(rdev
);
1488 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
1490 struct cfg80211_registered_device
*rdev
;
1492 struct net_device
*dev
;
1493 struct key_parse key
;
1494 u8
*mac_addr
= NULL
;
1496 err
= nl80211_parse_key(info
, &key
);
1503 if (info
->attrs
[NL80211_ATTR_MAC
])
1504 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1508 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1512 if (!rdev
->ops
->add_key
) {
1517 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
, mac_addr
)) {
1522 wdev_lock(dev
->ieee80211_ptr
);
1523 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1525 err
= rdev
->ops
->add_key(&rdev
->wiphy
, dev
, key
.idx
,
1527 wdev_unlock(dev
->ieee80211_ptr
);
1530 cfg80211_unlock_rdev(rdev
);
1538 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
1540 struct cfg80211_registered_device
*rdev
;
1542 struct net_device
*dev
;
1543 u8
*mac_addr
= NULL
;
1544 struct key_parse key
;
1546 err
= nl80211_parse_key(info
, &key
);
1550 if (info
->attrs
[NL80211_ATTR_MAC
])
1551 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1555 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1559 if (!rdev
->ops
->del_key
) {
1564 wdev_lock(dev
->ieee80211_ptr
);
1565 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1567 err
= rdev
->ops
->del_key(&rdev
->wiphy
, dev
, key
.idx
, mac_addr
);
1569 #ifdef CONFIG_CFG80211_WEXT
1571 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
1572 dev
->ieee80211_ptr
->wext
.default_key
= -1;
1573 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
1574 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
1577 wdev_unlock(dev
->ieee80211_ptr
);
1580 cfg80211_unlock_rdev(rdev
);
1589 static int nl80211_addset_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1591 int (*call
)(struct wiphy
*wiphy
, struct net_device
*dev
,
1592 struct beacon_parameters
*info
);
1593 struct cfg80211_registered_device
*rdev
;
1595 struct net_device
*dev
;
1596 struct beacon_parameters params
;
1599 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]))
1604 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1608 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1613 switch (info
->genlhdr
->cmd
) {
1614 case NL80211_CMD_NEW_BEACON
:
1615 /* these are required for NEW_BEACON */
1616 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
1617 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
1618 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1623 call
= rdev
->ops
->add_beacon
;
1625 case NL80211_CMD_SET_BEACON
:
1626 call
= rdev
->ops
->set_beacon
;
1639 memset(¶ms
, 0, sizeof(params
));
1641 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
1643 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
1647 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
1648 params
.dtim_period
=
1649 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
1653 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1654 params
.head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1656 nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1660 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
1661 params
.tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1663 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1672 err
= call(&rdev
->wiphy
, dev
, ¶ms
);
1675 cfg80211_unlock_rdev(rdev
);
1683 static int nl80211_del_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1685 struct cfg80211_registered_device
*rdev
;
1687 struct net_device
*dev
;
1691 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1695 if (!rdev
->ops
->del_beacon
) {
1700 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1704 err
= rdev
->ops
->del_beacon(&rdev
->wiphy
, dev
);
1707 cfg80211_unlock_rdev(rdev
);
1715 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
1716 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
1717 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
1718 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
1719 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
1722 static int parse_station_flags(struct genl_info
*info
,
1723 struct station_parameters
*params
)
1725 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
1730 * Try parsing the new attribute first so userspace
1731 * can specify both for older kernels.
1733 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
1735 struct nl80211_sta_flag_update
*sta_flags
;
1737 sta_flags
= nla_data(nla
);
1738 params
->sta_flags_mask
= sta_flags
->mask
;
1739 params
->sta_flags_set
= sta_flags
->set
;
1740 if ((params
->sta_flags_mask
|
1741 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
1746 /* if present, parse the old attribute */
1748 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
1752 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
1753 nla
, sta_flags_policy
))
1756 params
->sta_flags_mask
= (1 << __NL80211_STA_FLAG_AFTER_LAST
) - 1;
1757 params
->sta_flags_mask
&= ~1;
1759 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++)
1761 params
->sta_flags_set
|= (1<<flag
);
1766 static int nl80211_send_station(struct sk_buff
*msg
, u32 pid
, u32 seq
,
1767 int flags
, struct net_device
*dev
,
1768 const u8
*mac_addr
, struct station_info
*sinfo
)
1771 struct nlattr
*sinfoattr
, *txrate
;
1774 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
1778 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1779 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1781 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
);
1783 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
1785 goto nla_put_failure
;
1786 if (sinfo
->filled
& STATION_INFO_INACTIVE_TIME
)
1787 NLA_PUT_U32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
1788 sinfo
->inactive_time
);
1789 if (sinfo
->filled
& STATION_INFO_RX_BYTES
)
1790 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_BYTES
,
1792 if (sinfo
->filled
& STATION_INFO_TX_BYTES
)
1793 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_BYTES
,
1795 if (sinfo
->filled
& STATION_INFO_LLID
)
1796 NLA_PUT_U16(msg
, NL80211_STA_INFO_LLID
,
1798 if (sinfo
->filled
& STATION_INFO_PLID
)
1799 NLA_PUT_U16(msg
, NL80211_STA_INFO_PLID
,
1801 if (sinfo
->filled
& STATION_INFO_PLINK_STATE
)
1802 NLA_PUT_U8(msg
, NL80211_STA_INFO_PLINK_STATE
,
1803 sinfo
->plink_state
);
1804 if (sinfo
->filled
& STATION_INFO_SIGNAL
)
1805 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL
,
1807 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
1808 txrate
= nla_nest_start(msg
, NL80211_STA_INFO_TX_BITRATE
);
1810 goto nla_put_failure
;
1812 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
1813 bitrate
= cfg80211_calculate_bitrate(&sinfo
->txrate
);
1815 NLA_PUT_U16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate
);
1817 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_MCS
)
1818 NLA_PUT_U8(msg
, NL80211_RATE_INFO_MCS
,
1820 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
)
1821 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
);
1822 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_SHORT_GI
)
1823 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_SHORT_GI
);
1825 nla_nest_end(msg
, txrate
);
1827 if (sinfo
->filled
& STATION_INFO_RX_PACKETS
)
1828 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_PACKETS
,
1830 if (sinfo
->filled
& STATION_INFO_TX_PACKETS
)
1831 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_PACKETS
,
1833 nla_nest_end(msg
, sinfoattr
);
1835 return genlmsg_end(msg
, hdr
);
1838 genlmsg_cancel(msg
, hdr
);
1842 static int nl80211_dump_station(struct sk_buff
*skb
,
1843 struct netlink_callback
*cb
)
1845 struct station_info sinfo
;
1846 struct cfg80211_registered_device
*dev
;
1847 struct net_device
*netdev
;
1848 u8 mac_addr
[ETH_ALEN
];
1849 int ifidx
= cb
->args
[0];
1850 int sta_idx
= cb
->args
[1];
1854 ifidx
= nl80211_get_ifidx(cb
);
1860 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
1866 dev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
1872 if (!dev
->ops
->dump_station
) {
1878 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
1885 if (nl80211_send_station(skb
,
1886 NETLINK_CB(cb
->skb
).pid
,
1887 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1897 cb
->args
[1] = sta_idx
;
1900 cfg80211_unlock_rdev(dev
);
1907 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
1909 struct cfg80211_registered_device
*rdev
;
1911 struct net_device
*dev
;
1912 struct station_info sinfo
;
1913 struct sk_buff
*msg
;
1914 u8
*mac_addr
= NULL
;
1916 memset(&sinfo
, 0, sizeof(sinfo
));
1918 if (!info
->attrs
[NL80211_ATTR_MAC
])
1921 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1925 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1929 if (!rdev
->ops
->get_station
) {
1934 err
= rdev
->ops
->get_station(&rdev
->wiphy
, dev
, mac_addr
, &sinfo
);
1938 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1942 if (nl80211_send_station(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1943 dev
, mac_addr
, &sinfo
) < 0)
1946 err
= genlmsg_reply(msg
, info
);
1952 cfg80211_unlock_rdev(rdev
);
1961 * Get vlan interface making sure it is running and on the right wiphy.
1963 static int get_vlan(struct genl_info
*info
,
1964 struct cfg80211_registered_device
*rdev
,
1965 struct net_device
**vlan
)
1967 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
1971 *vlan
= dev_get_by_index(genl_info_net(info
),
1972 nla_get_u32(vlanattr
));
1975 if (!(*vlan
)->ieee80211_ptr
)
1977 if ((*vlan
)->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
)
1979 if (!netif_running(*vlan
))
1985 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
1987 struct cfg80211_registered_device
*rdev
;
1989 struct net_device
*dev
;
1990 struct station_parameters params
;
1991 u8
*mac_addr
= NULL
;
1993 memset(¶ms
, 0, sizeof(params
));
1995 params
.listen_interval
= -1;
1997 if (info
->attrs
[NL80211_ATTR_STA_AID
])
2000 if (!info
->attrs
[NL80211_ATTR_MAC
])
2003 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2005 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
2006 params
.supported_rates
=
2007 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2008 params
.supported_rates_len
=
2009 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2012 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2013 params
.listen_interval
=
2014 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2016 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2018 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2020 if (parse_station_flags(info
, ¶ms
))
2023 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
2024 params
.plink_action
=
2025 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
2029 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2033 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
2037 /* validate settings */
2040 switch (dev
->ieee80211_ptr
->iftype
) {
2041 case NL80211_IFTYPE_AP
:
2042 case NL80211_IFTYPE_AP_VLAN
:
2043 /* disallow mesh-specific things */
2044 if (params
.plink_action
)
2047 case NL80211_IFTYPE_STATION
:
2048 /* disallow everything but AUTHORIZED flag */
2049 if (params
.plink_action
)
2053 if (params
.supported_rates
)
2057 if (params
.listen_interval
>= 0)
2059 if (params
.sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
2062 case NL80211_IFTYPE_MESH_POINT
:
2063 /* disallow things mesh doesn't support */
2068 if (params
.listen_interval
>= 0)
2070 if (params
.supported_rates
)
2072 if (params
.sta_flags_mask
)
2082 if (!rdev
->ops
->change_station
) {
2087 err
= rdev
->ops
->change_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2091 dev_put(params
.vlan
);
2092 cfg80211_unlock_rdev(rdev
);
2100 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
2102 struct cfg80211_registered_device
*rdev
;
2104 struct net_device
*dev
;
2105 struct station_parameters params
;
2106 u8
*mac_addr
= NULL
;
2108 memset(¶ms
, 0, sizeof(params
));
2110 if (!info
->attrs
[NL80211_ATTR_MAC
])
2113 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2116 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
2119 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
2122 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2123 params
.supported_rates
=
2124 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2125 params
.supported_rates_len
=
2126 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2127 params
.listen_interval
=
2128 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2130 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
2131 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
2134 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2136 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2138 if (parse_station_flags(info
, ¶ms
))
2143 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2147 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2148 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
) {
2153 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
2157 /* validate settings */
2160 if (!rdev
->ops
->add_station
) {
2165 if (!netif_running(dev
)) {
2170 err
= rdev
->ops
->add_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2174 dev_put(params
.vlan
);
2175 cfg80211_unlock_rdev(rdev
);
2183 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
2185 struct cfg80211_registered_device
*rdev
;
2187 struct net_device
*dev
;
2188 u8
*mac_addr
= NULL
;
2190 if (info
->attrs
[NL80211_ATTR_MAC
])
2191 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2195 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2199 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2200 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
2201 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2206 if (!rdev
->ops
->del_station
) {
2211 err
= rdev
->ops
->del_station(&rdev
->wiphy
, dev
, mac_addr
);
2214 cfg80211_unlock_rdev(rdev
);
2222 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2223 int flags
, struct net_device
*dev
,
2224 u8
*dst
, u8
*next_hop
,
2225 struct mpath_info
*pinfo
)
2228 struct nlattr
*pinfoattr
;
2230 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2234 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2235 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
2236 NLA_PUT(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
);
2238 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
);
2240 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
2242 goto nla_put_failure
;
2243 if (pinfo
->filled
& MPATH_INFO_FRAME_QLEN
)
2244 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
2246 if (pinfo
->filled
& MPATH_INFO_SN
)
2247 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_SN
,
2249 if (pinfo
->filled
& MPATH_INFO_METRIC
)
2250 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_METRIC
,
2252 if (pinfo
->filled
& MPATH_INFO_EXPTIME
)
2253 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_EXPTIME
,
2255 if (pinfo
->filled
& MPATH_INFO_FLAGS
)
2256 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_FLAGS
,
2258 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
)
2259 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
2260 pinfo
->discovery_timeout
);
2261 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
)
2262 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
2263 pinfo
->discovery_retries
);
2265 nla_nest_end(msg
, pinfoattr
);
2267 return genlmsg_end(msg
, hdr
);
2270 genlmsg_cancel(msg
, hdr
);
2274 static int nl80211_dump_mpath(struct sk_buff
*skb
,
2275 struct netlink_callback
*cb
)
2277 struct mpath_info pinfo
;
2278 struct cfg80211_registered_device
*dev
;
2279 struct net_device
*netdev
;
2281 u8 next_hop
[ETH_ALEN
];
2282 int ifidx
= cb
->args
[0];
2283 int path_idx
= cb
->args
[1];
2287 ifidx
= nl80211_get_ifidx(cb
);
2293 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
2299 dev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
2305 if (!dev
->ops
->dump_mpath
) {
2310 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2316 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
2317 dst
, next_hop
, &pinfo
);
2323 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).pid
,
2324 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2325 netdev
, dst
, next_hop
,
2334 cb
->args
[1] = path_idx
;
2337 cfg80211_unlock_rdev(dev
);
2344 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2346 struct cfg80211_registered_device
*rdev
;
2348 struct net_device
*dev
;
2349 struct mpath_info pinfo
;
2350 struct sk_buff
*msg
;
2352 u8 next_hop
[ETH_ALEN
];
2354 memset(&pinfo
, 0, sizeof(pinfo
));
2356 if (!info
->attrs
[NL80211_ATTR_MAC
])
2359 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2363 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2367 if (!rdev
->ops
->get_mpath
) {
2372 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2377 err
= rdev
->ops
->get_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
2381 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2385 if (nl80211_send_mpath(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2386 dev
, dst
, next_hop
, &pinfo
) < 0)
2389 err
= genlmsg_reply(msg
, info
);
2395 cfg80211_unlock_rdev(rdev
);
2403 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2405 struct cfg80211_registered_device
*rdev
;
2407 struct net_device
*dev
;
2409 u8
*next_hop
= NULL
;
2411 if (!info
->attrs
[NL80211_ATTR_MAC
])
2414 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2417 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2418 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2422 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2426 if (!rdev
->ops
->change_mpath
) {
2431 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2436 if (!netif_running(dev
)) {
2441 err
= rdev
->ops
->change_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2444 cfg80211_unlock_rdev(rdev
);
2451 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2453 struct cfg80211_registered_device
*rdev
;
2455 struct net_device
*dev
;
2457 u8
*next_hop
= NULL
;
2459 if (!info
->attrs
[NL80211_ATTR_MAC
])
2462 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2465 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2466 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2470 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2474 if (!rdev
->ops
->add_mpath
) {
2479 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2484 if (!netif_running(dev
)) {
2489 err
= rdev
->ops
->add_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2492 cfg80211_unlock_rdev(rdev
);
2500 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2502 struct cfg80211_registered_device
*rdev
;
2504 struct net_device
*dev
;
2507 if (info
->attrs
[NL80211_ATTR_MAC
])
2508 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2512 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2516 if (!rdev
->ops
->del_mpath
) {
2521 err
= rdev
->ops
->del_mpath(&rdev
->wiphy
, dev
, dst
);
2524 cfg80211_unlock_rdev(rdev
);
2532 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
2534 struct cfg80211_registered_device
*rdev
;
2536 struct net_device
*dev
;
2537 struct bss_parameters params
;
2539 memset(¶ms
, 0, sizeof(params
));
2540 /* default to not changing parameters */
2541 params
.use_cts_prot
= -1;
2542 params
.use_short_preamble
= -1;
2543 params
.use_short_slot_time
= -1;
2544 params
.ap_isolate
= -1;
2546 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
2547 params
.use_cts_prot
=
2548 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
2549 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
2550 params
.use_short_preamble
=
2551 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
2552 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
2553 params
.use_short_slot_time
=
2554 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
2555 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
2556 params
.basic_rates
=
2557 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2558 params
.basic_rates_len
=
2559 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2561 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
2562 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
2566 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2570 if (!rdev
->ops
->change_bss
) {
2575 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
2580 err
= rdev
->ops
->change_bss(&rdev
->wiphy
, dev
, ¶ms
);
2583 cfg80211_unlock_rdev(rdev
);
2591 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
2592 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
2593 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
2594 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
2595 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
2596 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
2597 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
2600 static int parse_reg_rule(struct nlattr
*tb
[],
2601 struct ieee80211_reg_rule
*reg_rule
)
2603 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
2604 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
2606 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
2608 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
2610 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
2612 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
2614 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
2617 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
2619 freq_range
->start_freq_khz
=
2620 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
2621 freq_range
->end_freq_khz
=
2622 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
2623 freq_range
->max_bandwidth_khz
=
2624 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
2626 power_rule
->max_eirp
=
2627 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
2629 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
2630 power_rule
->max_antenna_gain
=
2631 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
2636 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2642 * You should only get this when cfg80211 hasn't yet initialized
2643 * completely when built-in to the kernel right between the time
2644 * window between nl80211_init() and regulatory_init(), if that is
2647 mutex_lock(&cfg80211_mutex
);
2648 if (unlikely(!cfg80211_regdomain
)) {
2649 mutex_unlock(&cfg80211_mutex
);
2650 return -EINPROGRESS
;
2652 mutex_unlock(&cfg80211_mutex
);
2654 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2657 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2659 r
= regulatory_hint_user(data
);
2664 static int nl80211_get_mesh_params(struct sk_buff
*skb
,
2665 struct genl_info
*info
)
2667 struct cfg80211_registered_device
*rdev
;
2668 struct mesh_config cur_params
;
2670 struct net_device
*dev
;
2672 struct nlattr
*pinfoattr
;
2673 struct sk_buff
*msg
;
2677 /* Look up our device */
2678 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2682 if (!rdev
->ops
->get_mesh_params
) {
2687 /* Get the mesh params */
2688 err
= rdev
->ops
->get_mesh_params(&rdev
->wiphy
, dev
, &cur_params
);
2692 /* Draw up a netlink message to send back */
2693 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2698 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2699 NL80211_CMD_GET_MESH_PARAMS
);
2701 goto nla_put_failure
;
2702 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_PARAMS
);
2704 goto nla_put_failure
;
2705 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2706 NLA_PUT_U16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
2707 cur_params
.dot11MeshRetryTimeout
);
2708 NLA_PUT_U16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
2709 cur_params
.dot11MeshConfirmTimeout
);
2710 NLA_PUT_U16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
2711 cur_params
.dot11MeshHoldingTimeout
);
2712 NLA_PUT_U16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
2713 cur_params
.dot11MeshMaxPeerLinks
);
2714 NLA_PUT_U8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
2715 cur_params
.dot11MeshMaxRetries
);
2716 NLA_PUT_U8(msg
, NL80211_MESHCONF_TTL
,
2717 cur_params
.dot11MeshTTL
);
2718 NLA_PUT_U8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
2719 cur_params
.auto_open_plinks
);
2720 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2721 cur_params
.dot11MeshHWMPmaxPREQretries
);
2722 NLA_PUT_U32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
2723 cur_params
.path_refresh_time
);
2724 NLA_PUT_U16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2725 cur_params
.min_discovery_timeout
);
2726 NLA_PUT_U32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2727 cur_params
.dot11MeshHWMPactivePathTimeout
);
2728 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2729 cur_params
.dot11MeshHWMPpreqMinInterval
);
2730 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2731 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
);
2732 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
2733 cur_params
.dot11MeshHWMPRootMode
);
2734 nla_nest_end(msg
, pinfoattr
);
2735 genlmsg_end(msg
, hdr
);
2736 err
= genlmsg_reply(msg
, info
);
2740 genlmsg_cancel(msg
, hdr
);
2744 cfg80211_unlock_rdev(rdev
);
2752 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2754 if (table[attr_num]) {\
2755 cfg.param = nla_fn(table[attr_num]); \
2756 mask |= (1 << (attr_num - 1)); \
2760 static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
2761 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
2762 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
2763 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
2764 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
2765 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
2766 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
2767 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
2769 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
2770 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
2771 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
2772 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
2773 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
2774 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
2777 static int nl80211_set_mesh_params(struct sk_buff
*skb
, struct genl_info
*info
)
2781 struct cfg80211_registered_device
*rdev
;
2782 struct net_device
*dev
;
2783 struct mesh_config cfg
;
2784 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
2785 struct nlattr
*parent_attr
;
2787 parent_attr
= info
->attrs
[NL80211_ATTR_MESH_PARAMS
];
2790 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
2791 parent_attr
, nl80211_meshconf_params_policy
))
2796 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2800 if (!rdev
->ops
->set_mesh_params
) {
2805 /* This makes sure that there aren't more than 32 mesh config
2806 * parameters (otherwise our bitfield scheme would not work.) */
2807 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
2809 /* Fill in the params struct */
2811 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
2812 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
, nla_get_u16
);
2813 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
2814 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
, nla_get_u16
);
2815 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
2816 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
, nla_get_u16
);
2817 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
2818 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
, nla_get_u16
);
2819 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
2820 mask
, NL80211_MESHCONF_MAX_RETRIES
, nla_get_u8
);
2821 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
2822 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
2823 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
2824 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
, nla_get_u8
);
2825 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
2826 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2828 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
2829 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
, nla_get_u32
);
2830 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
2831 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2833 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
2834 mask
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2836 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
2837 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2839 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
2840 dot11MeshHWMPnetDiameterTraversalTime
,
2841 mask
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2843 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
2844 dot11MeshHWMPRootMode
, mask
,
2845 NL80211_MESHCONF_HWMP_ROOTMODE
,
2849 err
= rdev
->ops
->set_mesh_params(&rdev
->wiphy
, dev
, &cfg
, mask
);
2853 cfg80211_unlock_rdev(rdev
);
2861 #undef FILL_IN_MESH_PARAM_IF_SET
2863 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2865 struct sk_buff
*msg
;
2867 struct nlattr
*nl_reg_rules
;
2871 mutex_lock(&cfg80211_mutex
);
2873 if (!cfg80211_regdomain
)
2876 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2882 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2883 NL80211_CMD_GET_REG
);
2885 goto nla_put_failure
;
2887 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
,
2888 cfg80211_regdomain
->alpha2
);
2890 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
2892 goto nla_put_failure
;
2894 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
2895 struct nlattr
*nl_reg_rule
;
2896 const struct ieee80211_reg_rule
*reg_rule
;
2897 const struct ieee80211_freq_range
*freq_range
;
2898 const struct ieee80211_power_rule
*power_rule
;
2900 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
2901 freq_range
= ®_rule
->freq_range
;
2902 power_rule
= ®_rule
->power_rule
;
2904 nl_reg_rule
= nla_nest_start(msg
, i
);
2906 goto nla_put_failure
;
2908 NLA_PUT_U32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
2910 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
2911 freq_range
->start_freq_khz
);
2912 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
2913 freq_range
->end_freq_khz
);
2914 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
2915 freq_range
->max_bandwidth_khz
);
2916 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
2917 power_rule
->max_antenna_gain
);
2918 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
2919 power_rule
->max_eirp
);
2921 nla_nest_end(msg
, nl_reg_rule
);
2924 nla_nest_end(msg
, nl_reg_rules
);
2926 genlmsg_end(msg
, hdr
);
2927 err
= genlmsg_reply(msg
, info
);
2931 genlmsg_cancel(msg
, hdr
);
2934 mutex_unlock(&cfg80211_mutex
);
2938 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2940 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
2941 struct nlattr
*nl_reg_rule
;
2942 char *alpha2
= NULL
;
2943 int rem_reg_rules
= 0, r
= 0;
2944 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
2945 struct ieee80211_regdomain
*rd
= NULL
;
2947 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2950 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
2953 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2955 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
2958 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
2962 mutex_lock(&cfg80211_mutex
);
2964 if (!reg_is_valid_request(alpha2
)) {
2969 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
2970 (num_rules
* sizeof(struct ieee80211_reg_rule
));
2972 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
2978 rd
->n_reg_rules
= num_rules
;
2979 rd
->alpha2
[0] = alpha2
[0];
2980 rd
->alpha2
[1] = alpha2
[1];
2982 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
2984 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
2985 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
2987 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
2993 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
2999 BUG_ON(rule_idx
!= num_rules
);
3003 mutex_unlock(&cfg80211_mutex
);
3008 mutex_unlock(&cfg80211_mutex
);
3013 static int validate_scan_freqs(struct nlattr
*freqs
)
3015 struct nlattr
*attr1
, *attr2
;
3016 int n_channels
= 0, tmp1
, tmp2
;
3018 nla_for_each_nested(attr1
, freqs
, tmp1
) {
3021 * Some hardware has a limited channel list for
3022 * scanning, and it is pretty much nonsensical
3023 * to scan for a channel twice, so disallow that
3024 * and don't require drivers to check that the
3025 * channel list they get isn't longer than what
3026 * they can scan, as long as they can scan all
3027 * the channels they registered at once.
3029 nla_for_each_nested(attr2
, freqs
, tmp2
)
3030 if (attr1
!= attr2
&&
3031 nla_get_u32(attr1
) == nla_get_u32(attr2
))
3038 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
3040 struct cfg80211_registered_device
*rdev
;
3041 struct net_device
*dev
;
3042 struct cfg80211_scan_request
*request
;
3043 struct cfg80211_ssid
*ssid
;
3044 struct ieee80211_channel
*channel
;
3045 struct nlattr
*attr
;
3046 struct wiphy
*wiphy
;
3047 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
3048 enum ieee80211_band band
;
3051 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3056 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3060 wiphy
= &rdev
->wiphy
;
3062 if (!rdev
->ops
->scan
) {
3067 if (!netif_running(dev
)) {
3072 if (rdev
->scan_req
) {
3077 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3078 n_channels
= validate_scan_freqs(
3079 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
3087 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
3088 if (wiphy
->bands
[band
])
3089 n_channels
+= wiphy
->bands
[band
]->n_channels
;
3092 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
3093 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
3096 if (n_ssids
> wiphy
->max_scan_ssids
) {
3101 if (info
->attrs
[NL80211_ATTR_IE
])
3102 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3106 if (ie_len
> wiphy
->max_scan_ie_len
) {
3111 request
= kzalloc(sizeof(*request
)
3112 + sizeof(*ssid
) * n_ssids
3113 + sizeof(channel
) * n_channels
3114 + ie_len
, GFP_KERNEL
);
3121 request
->ssids
= (void *)&request
->channels
[n_channels
];
3122 request
->n_ssids
= n_ssids
;
3125 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
3127 request
->ie
= (void *)(request
->channels
+ n_channels
);
3131 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3132 /* user specified, bail out if channel not found */
3133 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
3134 struct ieee80211_channel
*chan
;
3136 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
3143 /* ignore disabled channels */
3144 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3147 request
->channels
[i
] = chan
;
3152 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
3154 if (!wiphy
->bands
[band
])
3156 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
3157 struct ieee80211_channel
*chan
;
3159 chan
= &wiphy
->bands
[band
]->channels
[j
];
3161 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3164 request
->channels
[i
] = chan
;
3175 request
->n_channels
= i
;
3178 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
3179 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
3180 if (request
->ssids
[i
].ssid_len
> IEEE80211_MAX_SSID_LEN
) {
3184 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
3185 request
->ssids
[i
].ssid_len
= nla_len(attr
);
3190 if (info
->attrs
[NL80211_ATTR_IE
]) {
3191 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3192 memcpy((void *)request
->ie
,
3193 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
3198 request
->wiphy
= &rdev
->wiphy
;
3200 rdev
->scan_req
= request
;
3201 err
= rdev
->ops
->scan(&rdev
->wiphy
, dev
, request
);
3204 nl80211_send_scan_start(rdev
, dev
);
3210 rdev
->scan_req
= NULL
;
3214 cfg80211_unlock_rdev(rdev
);
3222 static int nl80211_send_bss(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
3223 struct cfg80211_registered_device
*rdev
,
3224 struct wireless_dev
*wdev
,
3225 struct cfg80211_internal_bss
*intbss
)
3227 struct cfg80211_bss
*res
= &intbss
->pub
;
3232 ASSERT_WDEV_LOCK(wdev
);
3234 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3235 NL80211_CMD_NEW_SCAN_RESULTS
);
3239 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
);
3240 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
);
3242 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
3244 goto nla_put_failure
;
3245 if (!is_zero_ether_addr(res
->bssid
))
3246 NLA_PUT(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
);
3247 if (res
->information_elements
&& res
->len_information_elements
)
3248 NLA_PUT(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
3249 res
->len_information_elements
,
3250 res
->information_elements
);
3251 if (res
->beacon_ies
&& res
->len_beacon_ies
&&
3252 res
->beacon_ies
!= res
->information_elements
)
3253 NLA_PUT(msg
, NL80211_BSS_BEACON_IES
,
3254 res
->len_beacon_ies
, res
->beacon_ies
);
3256 NLA_PUT_U64(msg
, NL80211_BSS_TSF
, res
->tsf
);
3257 if (res
->beacon_interval
)
3258 NLA_PUT_U16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
);
3259 NLA_PUT_U16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
);
3260 NLA_PUT_U32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
);
3261 NLA_PUT_U32(msg
, NL80211_BSS_SEEN_MS_AGO
,
3262 jiffies_to_msecs(jiffies
- intbss
->ts
));
3264 switch (rdev
->wiphy
.signal_type
) {
3265 case CFG80211_SIGNAL_TYPE_MBM
:
3266 NLA_PUT_U32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
);
3268 case CFG80211_SIGNAL_TYPE_UNSPEC
:
3269 NLA_PUT_U8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
);
3275 switch (wdev
->iftype
) {
3276 case NL80211_IFTYPE_STATION
:
3277 if (intbss
== wdev
->current_bss
)
3278 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3279 NL80211_BSS_STATUS_ASSOCIATED
);
3280 else for (i
= 0; i
< MAX_AUTH_BSSES
; i
++) {
3281 if (intbss
!= wdev
->auth_bsses
[i
])
3283 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3284 NL80211_BSS_STATUS_AUTHENTICATED
);
3288 case NL80211_IFTYPE_ADHOC
:
3289 if (intbss
== wdev
->current_bss
)
3290 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3291 NL80211_BSS_STATUS_IBSS_JOINED
);
3297 nla_nest_end(msg
, bss
);
3299 return genlmsg_end(msg
, hdr
);
3302 genlmsg_cancel(msg
, hdr
);
3306 static int nl80211_dump_scan(struct sk_buff
*skb
,
3307 struct netlink_callback
*cb
)
3309 struct cfg80211_registered_device
*rdev
;
3310 struct net_device
*dev
;
3311 struct cfg80211_internal_bss
*scan
;
3312 struct wireless_dev
*wdev
;
3313 int ifidx
= cb
->args
[0];
3314 int start
= cb
->args
[1], idx
= 0;
3318 ifidx
= nl80211_get_ifidx(cb
);
3321 cb
->args
[0] = ifidx
;
3323 dev
= dev_get_by_index(sock_net(skb
->sk
), ifidx
);
3327 rdev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
3329 err
= PTR_ERR(rdev
);
3330 goto out_put_netdev
;
3333 wdev
= dev
->ieee80211_ptr
;
3336 spin_lock_bh(&rdev
->bss_lock
);
3337 cfg80211_bss_expire(rdev
);
3339 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
3342 if (nl80211_send_bss(skb
,
3343 NETLINK_CB(cb
->skb
).pid
,
3344 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3345 rdev
, wdev
, scan
) < 0) {
3352 spin_unlock_bh(&rdev
->bss_lock
);
3357 cfg80211_unlock_rdev(rdev
);
3364 static int nl80211_send_survey(struct sk_buff
*msg
, u32 pid
, u32 seq
,
3365 int flags
, struct net_device
*dev
,
3366 struct survey_info
*survey
)
3369 struct nlattr
*infoattr
;
3371 /* Survey without a channel doesn't make sense */
3372 if (!survey
->channel
)
3375 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3376 NL80211_CMD_NEW_SURVEY_RESULTS
);
3380 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
3382 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
3384 goto nla_put_failure
;
3386 NLA_PUT_U32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
3387 survey
->channel
->center_freq
);
3388 if (survey
->filled
& SURVEY_INFO_NOISE_DBM
)
3389 NLA_PUT_U8(msg
, NL80211_SURVEY_INFO_NOISE
,
3392 nla_nest_end(msg
, infoattr
);
3394 return genlmsg_end(msg
, hdr
);
3397 genlmsg_cancel(msg
, hdr
);
3401 static int nl80211_dump_survey(struct sk_buff
*skb
,
3402 struct netlink_callback
*cb
)
3404 struct survey_info survey
;
3405 struct cfg80211_registered_device
*dev
;
3406 struct net_device
*netdev
;
3407 int ifidx
= cb
->args
[0];
3408 int survey_idx
= cb
->args
[1];
3412 ifidx
= nl80211_get_ifidx(cb
);
3415 cb
->args
[0] = ifidx
;
3419 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
3425 dev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
3431 if (!dev
->ops
->dump_survey
) {
3437 res
= dev
->ops
->dump_survey(&dev
->wiphy
, netdev
, survey_idx
,
3444 if (nl80211_send_survey(skb
,
3445 NETLINK_CB(cb
->skb
).pid
,
3446 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3454 cb
->args
[1] = survey_idx
;
3457 cfg80211_unlock_rdev(dev
);
3464 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
)
3466 return auth_type
<= NL80211_AUTHTYPE_MAX
;
3469 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
3471 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
3472 NL80211_WPA_VERSION_2
));
3475 static bool nl80211_valid_akm_suite(u32 akm
)
3477 return akm
== WLAN_AKM_SUITE_8021X
||
3478 akm
== WLAN_AKM_SUITE_PSK
;
3481 static bool nl80211_valid_cipher_suite(u32 cipher
)
3483 return cipher
== WLAN_CIPHER_SUITE_WEP40
||
3484 cipher
== WLAN_CIPHER_SUITE_WEP104
||
3485 cipher
== WLAN_CIPHER_SUITE_TKIP
||
3486 cipher
== WLAN_CIPHER_SUITE_CCMP
||
3487 cipher
== WLAN_CIPHER_SUITE_AES_CMAC
;
3491 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3493 struct cfg80211_registered_device
*rdev
;
3494 struct net_device
*dev
;
3495 struct ieee80211_channel
*chan
;
3496 const u8
*bssid
, *ssid
, *ie
= NULL
;
3497 int err
, ssid_len
, ie_len
= 0;
3498 enum nl80211_auth_type auth_type
;
3499 struct key_parse key
;
3500 bool local_state_change
;
3502 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3505 if (!info
->attrs
[NL80211_ATTR_MAC
])
3508 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
3511 if (!info
->attrs
[NL80211_ATTR_SSID
])
3514 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
3517 err
= nl80211_parse_key(info
, &key
);
3522 if (!key
.p
.key
|| !key
.p
.key_len
)
3524 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
3525 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
3526 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
3527 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
3538 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3542 if (!rdev
->ops
->auth
) {
3547 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3552 if (!netif_running(dev
)) {
3557 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3558 chan
= ieee80211_get_channel(&rdev
->wiphy
,
3559 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3560 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
)) {
3565 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3566 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3568 if (info
->attrs
[NL80211_ATTR_IE
]) {
3569 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3570 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3573 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3574 if (!nl80211_valid_auth_type(auth_type
)) {
3579 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
3581 err
= cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
3582 ssid
, ssid_len
, ie
, ie_len
,
3583 key
.p
.key
, key
.p
.key_len
, key
.idx
,
3584 local_state_change
);
3587 cfg80211_unlock_rdev(rdev
);
3594 static int nl80211_crypto_settings(struct genl_info
*info
,
3595 struct cfg80211_crypto_settings
*settings
,
3598 memset(settings
, 0, sizeof(*settings
));
3600 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
3602 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
3606 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
3607 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
3608 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
3610 if (len
% sizeof(u32
))
3613 if (settings
->n_ciphers_pairwise
> cipher_limit
)
3616 memcpy(settings
->ciphers_pairwise
, data
, len
);
3618 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
3619 if (!nl80211_valid_cipher_suite(
3620 settings
->ciphers_pairwise
[i
]))
3624 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
3625 settings
->cipher_group
=
3626 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
3627 if (!nl80211_valid_cipher_suite(settings
->cipher_group
))
3631 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
3632 settings
->wpa_versions
=
3633 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
3634 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
3638 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
3642 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
3643 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
3644 settings
->n_akm_suites
= len
/ sizeof(u32
);
3646 if (len
% sizeof(u32
))
3649 memcpy(settings
->akm_suites
, data
, len
);
3651 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
3652 if (!nl80211_valid_akm_suite(settings
->akm_suites
[i
]))
3659 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
3661 struct cfg80211_registered_device
*rdev
;
3662 struct net_device
*dev
;
3663 struct cfg80211_crypto_settings crypto
;
3664 struct ieee80211_channel
*chan
;
3665 const u8
*bssid
, *ssid
, *ie
= NULL
, *prev_bssid
= NULL
;
3666 int err
, ssid_len
, ie_len
= 0;
3667 bool use_mfp
= false;
3669 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3672 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
3673 !info
->attrs
[NL80211_ATTR_SSID
] ||
3674 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
3679 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3683 if (!rdev
->ops
->assoc
) {
3688 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3693 if (!netif_running(dev
)) {
3698 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3700 chan
= ieee80211_get_channel(&rdev
->wiphy
,
3701 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3702 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
)) {
3707 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3708 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3710 if (info
->attrs
[NL80211_ATTR_IE
]) {
3711 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3712 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3715 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
3716 enum nl80211_mfp mfp
=
3717 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
3718 if (mfp
== NL80211_MFP_REQUIRED
)
3720 else if (mfp
!= NL80211_MFP_NO
) {
3726 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
3727 prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
3729 err
= nl80211_crypto_settings(info
, &crypto
, 1);
3731 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
, prev_bssid
,
3732 ssid
, ssid_len
, ie
, ie_len
, use_mfp
,
3736 cfg80211_unlock_rdev(rdev
);
3743 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3745 struct cfg80211_registered_device
*rdev
;
3746 struct net_device
*dev
;
3747 const u8
*ie
= NULL
, *bssid
;
3748 int err
, ie_len
= 0;
3750 bool local_state_change
;
3752 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3755 if (!info
->attrs
[NL80211_ATTR_MAC
])
3758 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3763 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3767 if (!rdev
->ops
->deauth
) {
3772 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3777 if (!netif_running(dev
)) {
3782 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3784 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3785 if (reason_code
== 0) {
3786 /* Reason Code 0 is reserved */
3791 if (info
->attrs
[NL80211_ATTR_IE
]) {
3792 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3793 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3796 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
3798 err
= cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
3799 local_state_change
);
3802 cfg80211_unlock_rdev(rdev
);
3809 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
3811 struct cfg80211_registered_device
*rdev
;
3812 struct net_device
*dev
;
3813 const u8
*ie
= NULL
, *bssid
;
3814 int err
, ie_len
= 0;
3816 bool local_state_change
;
3818 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3821 if (!info
->attrs
[NL80211_ATTR_MAC
])
3824 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3829 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3833 if (!rdev
->ops
->disassoc
) {
3838 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3843 if (!netif_running(dev
)) {
3848 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3850 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3851 if (reason_code
== 0) {
3852 /* Reason Code 0 is reserved */
3857 if (info
->attrs
[NL80211_ATTR_IE
]) {
3858 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3859 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3862 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
3864 err
= cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
3865 local_state_change
);
3868 cfg80211_unlock_rdev(rdev
);
3875 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
3877 struct cfg80211_registered_device
*rdev
;
3878 struct net_device
*dev
;
3879 struct cfg80211_ibss_params ibss
;
3880 struct wiphy
*wiphy
;
3881 struct cfg80211_cached_keys
*connkeys
= NULL
;
3884 memset(&ibss
, 0, sizeof(ibss
));
3886 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3889 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
3890 !info
->attrs
[NL80211_ATTR_SSID
] ||
3891 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
3894 ibss
.beacon_interval
= 100;
3896 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
3897 ibss
.beacon_interval
=
3898 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3899 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
3905 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3909 if (!rdev
->ops
->join_ibss
) {
3914 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
3919 if (!netif_running(dev
)) {
3924 wiphy
= &rdev
->wiphy
;
3926 if (info
->attrs
[NL80211_ATTR_MAC
])
3927 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3928 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3929 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3931 if (info
->attrs
[NL80211_ATTR_IE
]) {
3932 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3933 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3936 ibss
.channel
= ieee80211_get_channel(wiphy
,
3937 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3938 if (!ibss
.channel
||
3939 ibss
.channel
->flags
& IEEE80211_CHAN_NO_IBSS
||
3940 ibss
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
3945 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
3946 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3948 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
3949 connkeys
= nl80211_parse_connkeys(rdev
,
3950 info
->attrs
[NL80211_ATTR_KEYS
]);
3951 if (IS_ERR(connkeys
)) {
3952 err
= PTR_ERR(connkeys
);
3958 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
3961 cfg80211_unlock_rdev(rdev
);
3970 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
3972 struct cfg80211_registered_device
*rdev
;
3973 struct net_device
*dev
;
3978 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3982 if (!rdev
->ops
->leave_ibss
) {
3987 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
3992 if (!netif_running(dev
)) {
3997 err
= cfg80211_leave_ibss(rdev
, dev
, false);
4000 cfg80211_unlock_rdev(rdev
);
4007 #ifdef CONFIG_NL80211_TESTMODE
4008 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
4012 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
4014 struct cfg80211_registered_device
*rdev
;
4017 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
4022 rdev
= cfg80211_get_dev_from_info(info
);
4024 err
= PTR_ERR(rdev
);
4029 if (rdev
->ops
->testmode_cmd
) {
4030 rdev
->testmode_info
= info
;
4031 err
= rdev
->ops
->testmode_cmd(&rdev
->wiphy
,
4032 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
4033 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
4034 rdev
->testmode_info
= NULL
;
4037 cfg80211_unlock_rdev(rdev
);
4044 static struct sk_buff
*
4045 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
4046 int approxlen
, u32 pid
, u32 seq
, gfp_t gfp
)
4048 struct sk_buff
*skb
;
4050 struct nlattr
*data
;
4052 skb
= nlmsg_new(approxlen
+ 100, gfp
);
4056 hdr
= nl80211hdr_put(skb
, pid
, seq
, 0, NL80211_CMD_TESTMODE
);
4062 NLA_PUT_U32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4063 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
4065 ((void **)skb
->cb
)[0] = rdev
;
4066 ((void **)skb
->cb
)[1] = hdr
;
4067 ((void **)skb
->cb
)[2] = data
;
4076 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
4079 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4081 if (WARN_ON(!rdev
->testmode_info
))
4084 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
4085 rdev
->testmode_info
->snd_pid
,
4086 rdev
->testmode_info
->snd_seq
,
4089 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
4091 int cfg80211_testmode_reply(struct sk_buff
*skb
)
4093 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
4094 void *hdr
= ((void **)skb
->cb
)[1];
4095 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4097 if (WARN_ON(!rdev
->testmode_info
)) {
4102 nla_nest_end(skb
, data
);
4103 genlmsg_end(skb
, hdr
);
4104 return genlmsg_reply(skb
, rdev
->testmode_info
);
4106 EXPORT_SYMBOL(cfg80211_testmode_reply
);
4108 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
4109 int approxlen
, gfp_t gfp
)
4111 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4113 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
4115 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
4117 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
4119 void *hdr
= ((void **)skb
->cb
)[1];
4120 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4122 nla_nest_end(skb
, data
);
4123 genlmsg_end(skb
, hdr
);
4124 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
4126 EXPORT_SYMBOL(cfg80211_testmode_event
);
4129 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
4131 struct cfg80211_registered_device
*rdev
;
4132 struct net_device
*dev
;
4133 struct cfg80211_connect_params connect
;
4134 struct wiphy
*wiphy
;
4135 struct cfg80211_cached_keys
*connkeys
= NULL
;
4138 memset(&connect
, 0, sizeof(connect
));
4140 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4143 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
4144 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
4147 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
4149 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4150 if (!nl80211_valid_auth_type(connect
.auth_type
))
4153 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
4155 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
4157 err
= nl80211_crypto_settings(info
, &connect
.crypto
,
4158 NL80211_MAX_NR_CIPHER_SUITES
);
4163 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4167 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4172 if (!netif_running(dev
)) {
4177 wiphy
= &rdev
->wiphy
;
4179 if (info
->attrs
[NL80211_ATTR_MAC
])
4180 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4181 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4182 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4184 if (info
->attrs
[NL80211_ATTR_IE
]) {
4185 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4186 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4189 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
4191 ieee80211_get_channel(wiphy
,
4192 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4193 if (!connect
.channel
||
4194 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
4200 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
4201 connkeys
= nl80211_parse_connkeys(rdev
,
4202 info
->attrs
[NL80211_ATTR_KEYS
]);
4203 if (IS_ERR(connkeys
)) {
4204 err
= PTR_ERR(connkeys
);
4210 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
4213 cfg80211_unlock_rdev(rdev
);
4222 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
4224 struct cfg80211_registered_device
*rdev
;
4225 struct net_device
*dev
;
4229 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4230 reason
= WLAN_REASON_DEAUTH_LEAVING
;
4232 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4239 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4243 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4248 if (!netif_running(dev
)) {
4253 err
= cfg80211_disconnect(rdev
, dev
, reason
, true);
4256 cfg80211_unlock_rdev(rdev
);
4263 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
4265 struct cfg80211_registered_device
*rdev
;
4270 if (!info
->attrs
[NL80211_ATTR_PID
])
4273 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
4277 rdev
= cfg80211_get_dev_from_info(info
);
4279 err
= PTR_ERR(rdev
);
4283 net
= get_net_ns_by_pid(pid
);
4291 /* check if anything to do */
4292 if (net_eq(wiphy_net(&rdev
->wiphy
), net
))
4295 err
= cfg80211_switch_netns(rdev
, net
);
4299 cfg80211_unlock_rdev(rdev
);
4305 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4307 struct cfg80211_registered_device
*rdev
;
4308 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
4309 struct cfg80211_pmksa
*pmksa
) = NULL
;
4311 struct net_device
*dev
;
4312 struct cfg80211_pmksa pmksa
;
4314 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
4316 if (!info
->attrs
[NL80211_ATTR_MAC
])
4319 if (!info
->attrs
[NL80211_ATTR_PMKID
])
4324 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4328 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
4329 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4331 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4336 switch (info
->genlhdr
->cmd
) {
4337 case NL80211_CMD_SET_PMKSA
:
4338 rdev_ops
= rdev
->ops
->set_pmksa
;
4340 case NL80211_CMD_DEL_PMKSA
:
4341 rdev_ops
= rdev
->ops
->del_pmksa
;
4353 err
= rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
4356 cfg80211_unlock_rdev(rdev
);
4364 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4366 struct cfg80211_registered_device
*rdev
;
4368 struct net_device
*dev
;
4372 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4376 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4381 if (!rdev
->ops
->flush_pmksa
) {
4386 err
= rdev
->ops
->flush_pmksa(&rdev
->wiphy
, dev
);
4389 cfg80211_unlock_rdev(rdev
);
4398 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
4399 struct genl_info
*info
)
4401 struct cfg80211_registered_device
*rdev
;
4402 struct net_device
*dev
;
4403 struct ieee80211_channel
*chan
;
4404 struct sk_buff
*msg
;
4407 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
4411 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
4412 !info
->attrs
[NL80211_ATTR_DURATION
])
4415 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
4418 * We should be on that channel for at least one jiffie,
4419 * and more than 5 seconds seems excessive.
4421 if (!duration
|| !msecs_to_jiffies(duration
) || duration
> 5000)
4426 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4430 if (!rdev
->ops
->remain_on_channel
) {
4435 if (!netif_running(dev
)) {
4440 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
4441 channel_type
= nla_get_u32(
4442 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
4443 if (channel_type
!= NL80211_CHAN_NO_HT
&&
4444 channel_type
!= NL80211_CHAN_HT20
&&
4445 channel_type
!= NL80211_CHAN_HT40PLUS
&&
4446 channel_type
!= NL80211_CHAN_HT40MINUS
) {
4452 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
4453 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
4459 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4465 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4466 NL80211_CMD_REMAIN_ON_CHANNEL
);
4473 err
= rdev
->ops
->remain_on_channel(&rdev
->wiphy
, dev
, chan
,
4474 channel_type
, duration
, &cookie
);
4479 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
4481 genlmsg_end(msg
, hdr
);
4482 err
= genlmsg_reply(msg
, info
);
4490 cfg80211_unlock_rdev(rdev
);
4497 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
4498 struct genl_info
*info
)
4500 struct cfg80211_registered_device
*rdev
;
4501 struct net_device
*dev
;
4505 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
4510 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4514 if (!rdev
->ops
->cancel_remain_on_channel
) {
4519 if (!netif_running(dev
)) {
4524 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
4526 err
= rdev
->ops
->cancel_remain_on_channel(&rdev
->wiphy
, dev
, cookie
);
4529 cfg80211_unlock_rdev(rdev
);
4536 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
4537 u8
*rates
, u8 rates_len
)
4542 for (i
= 0; i
< rates_len
; i
++) {
4543 int rate
= (rates
[i
] & 0x7f) * 5;
4545 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
4546 struct ieee80211_rate
*srate
=
4547 &sband
->bitrates
[ridx
];
4548 if (rate
== srate
->bitrate
) {
4553 if (ridx
== sband
->n_bitrates
)
4554 return 0; /* rate not found */
4560 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
4561 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
4562 .len
= NL80211_MAX_SUPP_RATES
},
4565 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
4566 struct genl_info
*info
)
4568 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
4569 struct cfg80211_registered_device
*rdev
;
4570 struct cfg80211_bitrate_mask mask
;
4572 struct net_device
*dev
;
4573 struct nlattr
*tx_rates
;
4574 struct ieee80211_supported_band
*sband
;
4576 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
4581 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4585 if (!rdev
->ops
->set_bitrate_mask
) {
4590 memset(&mask
, 0, sizeof(mask
));
4591 /* Default to all rates enabled */
4592 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
4593 sband
= rdev
->wiphy
.bands
[i
];
4594 mask
.control
[i
].legacy
=
4595 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
4599 * The nested attribute uses enum nl80211_band as the index. This maps
4600 * directly to the enum ieee80211_band values used in cfg80211.
4602 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
4604 enum ieee80211_band band
= nla_type(tx_rates
);
4605 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
4609 sband
= rdev
->wiphy
.bands
[band
];
4610 if (sband
== NULL
) {
4614 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
4615 nla_len(tx_rates
), nl80211_txattr_policy
);
4616 if (tb
[NL80211_TXRATE_LEGACY
]) {
4617 mask
.control
[band
].legacy
= rateset_to_mask(
4619 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
4620 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
4621 if (mask
.control
[band
].legacy
== 0) {
4628 err
= rdev
->ops
->set_bitrate_mask(&rdev
->wiphy
, dev
, NULL
, &mask
);
4632 cfg80211_unlock_rdev(rdev
);
4638 static int nl80211_register_action(struct sk_buff
*skb
, struct genl_info
*info
)
4640 struct cfg80211_registered_device
*rdev
;
4641 struct net_device
*dev
;
4644 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
4647 if (nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]) < 1)
4652 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4656 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4661 /* not much point in registering if we can't reply */
4662 if (!rdev
->ops
->action
) {
4667 err
= cfg80211_mlme_register_action(dev
->ieee80211_ptr
, info
->snd_pid
,
4668 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
4669 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
4671 cfg80211_unlock_rdev(rdev
);
4678 static int nl80211_action(struct sk_buff
*skb
, struct genl_info
*info
)
4680 struct cfg80211_registered_device
*rdev
;
4681 struct net_device
*dev
;
4682 struct ieee80211_channel
*chan
;
4683 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
4688 struct sk_buff
*msg
;
4690 if (!info
->attrs
[NL80211_ATTR_FRAME
] ||
4691 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4696 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4700 if (!rdev
->ops
->action
) {
4705 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4710 if (!netif_running(dev
)) {
4715 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
4716 channel_type
= nla_get_u32(
4717 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
4718 if (channel_type
!= NL80211_CHAN_NO_HT
&&
4719 channel_type
!= NL80211_CHAN_HT20
&&
4720 channel_type
!= NL80211_CHAN_HT40PLUS
&&
4721 channel_type
!= NL80211_CHAN_HT40MINUS
) {
4727 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
4728 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
4734 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4740 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4741 NL80211_CMD_ACTION
);
4747 err
= cfg80211_mlme_action(rdev
, dev
, chan
, channel_type
,
4748 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
4749 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
4754 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
4756 genlmsg_end(msg
, hdr
);
4757 err
= genlmsg_reply(msg
, info
);
4765 cfg80211_unlock_rdev(rdev
);
4772 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
4774 struct cfg80211_registered_device
*rdev
;
4775 struct wireless_dev
*wdev
;
4776 struct net_device
*dev
;
4781 if (!info
->attrs
[NL80211_ATTR_PS_STATE
]) {
4786 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
4788 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
) {
4795 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4799 wdev
= dev
->ieee80211_ptr
;
4801 if (!rdev
->ops
->set_power_mgmt
) {
4806 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
4808 if (state
== wdev
->ps
)
4813 if (rdev
->ops
->set_power_mgmt(wdev
->wiphy
, dev
, wdev
->ps
,
4815 /* assume this means it's off */
4819 cfg80211_unlock_rdev(rdev
);
4827 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
4829 struct cfg80211_registered_device
*rdev
;
4830 enum nl80211_ps_state ps_state
;
4831 struct wireless_dev
*wdev
;
4832 struct net_device
*dev
;
4833 struct sk_buff
*msg
;
4839 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4843 wdev
= dev
->ieee80211_ptr
;
4845 if (!rdev
->ops
->set_power_mgmt
) {
4850 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4856 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4857 NL80211_CMD_GET_POWER_SAVE
);
4864 ps_state
= NL80211_PS_ENABLED
;
4866 ps_state
= NL80211_PS_DISABLED
;
4868 NLA_PUT_U32(msg
, NL80211_ATTR_PS_STATE
, ps_state
);
4870 genlmsg_end(msg
, hdr
);
4871 err
= genlmsg_reply(msg
, info
);
4881 cfg80211_unlock_rdev(rdev
);
4890 static struct nla_policy
4891 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
4892 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
4893 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
4894 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
4897 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
4898 s32 threshold
, u32 hysteresis
)
4900 struct cfg80211_registered_device
*rdev
;
4901 struct wireless_dev
*wdev
;
4902 struct net_device
*dev
;
4910 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4914 wdev
= dev
->ieee80211_ptr
;
4916 if (!rdev
->ops
->set_cqm_rssi_config
) {
4921 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
) {
4926 err
= rdev
->ops
->set_cqm_rssi_config(wdev
->wiphy
, dev
,
4927 threshold
, hysteresis
);
4930 cfg80211_unlock_rdev(rdev
);
4937 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
4939 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
4943 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
4949 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
4950 nl80211_attr_cqm_policy
);
4954 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
4955 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
4958 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
4959 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
4960 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
4968 static struct genl_ops nl80211_ops
[] = {
4970 .cmd
= NL80211_CMD_GET_WIPHY
,
4971 .doit
= nl80211_get_wiphy
,
4972 .dumpit
= nl80211_dump_wiphy
,
4973 .policy
= nl80211_policy
,
4974 /* can be retrieved by unprivileged users */
4977 .cmd
= NL80211_CMD_SET_WIPHY
,
4978 .doit
= nl80211_set_wiphy
,
4979 .policy
= nl80211_policy
,
4980 .flags
= GENL_ADMIN_PERM
,
4983 .cmd
= NL80211_CMD_GET_INTERFACE
,
4984 .doit
= nl80211_get_interface
,
4985 .dumpit
= nl80211_dump_interface
,
4986 .policy
= nl80211_policy
,
4987 /* can be retrieved by unprivileged users */
4990 .cmd
= NL80211_CMD_SET_INTERFACE
,
4991 .doit
= nl80211_set_interface
,
4992 .policy
= nl80211_policy
,
4993 .flags
= GENL_ADMIN_PERM
,
4996 .cmd
= NL80211_CMD_NEW_INTERFACE
,
4997 .doit
= nl80211_new_interface
,
4998 .policy
= nl80211_policy
,
4999 .flags
= GENL_ADMIN_PERM
,
5002 .cmd
= NL80211_CMD_DEL_INTERFACE
,
5003 .doit
= nl80211_del_interface
,
5004 .policy
= nl80211_policy
,
5005 .flags
= GENL_ADMIN_PERM
,
5008 .cmd
= NL80211_CMD_GET_KEY
,
5009 .doit
= nl80211_get_key
,
5010 .policy
= nl80211_policy
,
5011 .flags
= GENL_ADMIN_PERM
,
5014 .cmd
= NL80211_CMD_SET_KEY
,
5015 .doit
= nl80211_set_key
,
5016 .policy
= nl80211_policy
,
5017 .flags
= GENL_ADMIN_PERM
,
5020 .cmd
= NL80211_CMD_NEW_KEY
,
5021 .doit
= nl80211_new_key
,
5022 .policy
= nl80211_policy
,
5023 .flags
= GENL_ADMIN_PERM
,
5026 .cmd
= NL80211_CMD_DEL_KEY
,
5027 .doit
= nl80211_del_key
,
5028 .policy
= nl80211_policy
,
5029 .flags
= GENL_ADMIN_PERM
,
5032 .cmd
= NL80211_CMD_SET_BEACON
,
5033 .policy
= nl80211_policy
,
5034 .flags
= GENL_ADMIN_PERM
,
5035 .doit
= nl80211_addset_beacon
,
5038 .cmd
= NL80211_CMD_NEW_BEACON
,
5039 .policy
= nl80211_policy
,
5040 .flags
= GENL_ADMIN_PERM
,
5041 .doit
= nl80211_addset_beacon
,
5044 .cmd
= NL80211_CMD_DEL_BEACON
,
5045 .policy
= nl80211_policy
,
5046 .flags
= GENL_ADMIN_PERM
,
5047 .doit
= nl80211_del_beacon
,
5050 .cmd
= NL80211_CMD_GET_STATION
,
5051 .doit
= nl80211_get_station
,
5052 .dumpit
= nl80211_dump_station
,
5053 .policy
= nl80211_policy
,
5056 .cmd
= NL80211_CMD_SET_STATION
,
5057 .doit
= nl80211_set_station
,
5058 .policy
= nl80211_policy
,
5059 .flags
= GENL_ADMIN_PERM
,
5062 .cmd
= NL80211_CMD_NEW_STATION
,
5063 .doit
= nl80211_new_station
,
5064 .policy
= nl80211_policy
,
5065 .flags
= GENL_ADMIN_PERM
,
5068 .cmd
= NL80211_CMD_DEL_STATION
,
5069 .doit
= nl80211_del_station
,
5070 .policy
= nl80211_policy
,
5071 .flags
= GENL_ADMIN_PERM
,
5074 .cmd
= NL80211_CMD_GET_MPATH
,
5075 .doit
= nl80211_get_mpath
,
5076 .dumpit
= nl80211_dump_mpath
,
5077 .policy
= nl80211_policy
,
5078 .flags
= GENL_ADMIN_PERM
,
5081 .cmd
= NL80211_CMD_SET_MPATH
,
5082 .doit
= nl80211_set_mpath
,
5083 .policy
= nl80211_policy
,
5084 .flags
= GENL_ADMIN_PERM
,
5087 .cmd
= NL80211_CMD_NEW_MPATH
,
5088 .doit
= nl80211_new_mpath
,
5089 .policy
= nl80211_policy
,
5090 .flags
= GENL_ADMIN_PERM
,
5093 .cmd
= NL80211_CMD_DEL_MPATH
,
5094 .doit
= nl80211_del_mpath
,
5095 .policy
= nl80211_policy
,
5096 .flags
= GENL_ADMIN_PERM
,
5099 .cmd
= NL80211_CMD_SET_BSS
,
5100 .doit
= nl80211_set_bss
,
5101 .policy
= nl80211_policy
,
5102 .flags
= GENL_ADMIN_PERM
,
5105 .cmd
= NL80211_CMD_GET_REG
,
5106 .doit
= nl80211_get_reg
,
5107 .policy
= nl80211_policy
,
5108 /* can be retrieved by unprivileged users */
5111 .cmd
= NL80211_CMD_SET_REG
,
5112 .doit
= nl80211_set_reg
,
5113 .policy
= nl80211_policy
,
5114 .flags
= GENL_ADMIN_PERM
,
5117 .cmd
= NL80211_CMD_REQ_SET_REG
,
5118 .doit
= nl80211_req_set_reg
,
5119 .policy
= nl80211_policy
,
5120 .flags
= GENL_ADMIN_PERM
,
5123 .cmd
= NL80211_CMD_GET_MESH_PARAMS
,
5124 .doit
= nl80211_get_mesh_params
,
5125 .policy
= nl80211_policy
,
5126 /* can be retrieved by unprivileged users */
5129 .cmd
= NL80211_CMD_SET_MESH_PARAMS
,
5130 .doit
= nl80211_set_mesh_params
,
5131 .policy
= nl80211_policy
,
5132 .flags
= GENL_ADMIN_PERM
,
5135 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
5136 .doit
= nl80211_trigger_scan
,
5137 .policy
= nl80211_policy
,
5138 .flags
= GENL_ADMIN_PERM
,
5141 .cmd
= NL80211_CMD_GET_SCAN
,
5142 .policy
= nl80211_policy
,
5143 .dumpit
= nl80211_dump_scan
,
5146 .cmd
= NL80211_CMD_AUTHENTICATE
,
5147 .doit
= nl80211_authenticate
,
5148 .policy
= nl80211_policy
,
5149 .flags
= GENL_ADMIN_PERM
,
5152 .cmd
= NL80211_CMD_ASSOCIATE
,
5153 .doit
= nl80211_associate
,
5154 .policy
= nl80211_policy
,
5155 .flags
= GENL_ADMIN_PERM
,
5158 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
5159 .doit
= nl80211_deauthenticate
,
5160 .policy
= nl80211_policy
,
5161 .flags
= GENL_ADMIN_PERM
,
5164 .cmd
= NL80211_CMD_DISASSOCIATE
,
5165 .doit
= nl80211_disassociate
,
5166 .policy
= nl80211_policy
,
5167 .flags
= GENL_ADMIN_PERM
,
5170 .cmd
= NL80211_CMD_JOIN_IBSS
,
5171 .doit
= nl80211_join_ibss
,
5172 .policy
= nl80211_policy
,
5173 .flags
= GENL_ADMIN_PERM
,
5176 .cmd
= NL80211_CMD_LEAVE_IBSS
,
5177 .doit
= nl80211_leave_ibss
,
5178 .policy
= nl80211_policy
,
5179 .flags
= GENL_ADMIN_PERM
,
5181 #ifdef CONFIG_NL80211_TESTMODE
5183 .cmd
= NL80211_CMD_TESTMODE
,
5184 .doit
= nl80211_testmode_do
,
5185 .policy
= nl80211_policy
,
5186 .flags
= GENL_ADMIN_PERM
,
5190 .cmd
= NL80211_CMD_CONNECT
,
5191 .doit
= nl80211_connect
,
5192 .policy
= nl80211_policy
,
5193 .flags
= GENL_ADMIN_PERM
,
5196 .cmd
= NL80211_CMD_DISCONNECT
,
5197 .doit
= nl80211_disconnect
,
5198 .policy
= nl80211_policy
,
5199 .flags
= GENL_ADMIN_PERM
,
5202 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
5203 .doit
= nl80211_wiphy_netns
,
5204 .policy
= nl80211_policy
,
5205 .flags
= GENL_ADMIN_PERM
,
5208 .cmd
= NL80211_CMD_GET_SURVEY
,
5209 .policy
= nl80211_policy
,
5210 .dumpit
= nl80211_dump_survey
,
5213 .cmd
= NL80211_CMD_SET_PMKSA
,
5214 .doit
= nl80211_setdel_pmksa
,
5215 .policy
= nl80211_policy
,
5216 .flags
= GENL_ADMIN_PERM
,
5219 .cmd
= NL80211_CMD_DEL_PMKSA
,
5220 .doit
= nl80211_setdel_pmksa
,
5221 .policy
= nl80211_policy
,
5222 .flags
= GENL_ADMIN_PERM
,
5225 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
5226 .doit
= nl80211_flush_pmksa
,
5227 .policy
= nl80211_policy
,
5228 .flags
= GENL_ADMIN_PERM
,
5231 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
5232 .doit
= nl80211_remain_on_channel
,
5233 .policy
= nl80211_policy
,
5234 .flags
= GENL_ADMIN_PERM
,
5237 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
5238 .doit
= nl80211_cancel_remain_on_channel
,
5239 .policy
= nl80211_policy
,
5240 .flags
= GENL_ADMIN_PERM
,
5243 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
5244 .doit
= nl80211_set_tx_bitrate_mask
,
5245 .policy
= nl80211_policy
,
5246 .flags
= GENL_ADMIN_PERM
,
5249 .cmd
= NL80211_CMD_REGISTER_ACTION
,
5250 .doit
= nl80211_register_action
,
5251 .policy
= nl80211_policy
,
5252 .flags
= GENL_ADMIN_PERM
,
5255 .cmd
= NL80211_CMD_ACTION
,
5256 .doit
= nl80211_action
,
5257 .policy
= nl80211_policy
,
5258 .flags
= GENL_ADMIN_PERM
,
5261 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
5262 .doit
= nl80211_set_power_save
,
5263 .policy
= nl80211_policy
,
5264 .flags
= GENL_ADMIN_PERM
,
5267 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
5268 .doit
= nl80211_get_power_save
,
5269 .policy
= nl80211_policy
,
5270 /* can be retrieved by unprivileged users */
5273 .cmd
= NL80211_CMD_SET_CQM
,
5274 .doit
= nl80211_set_cqm
,
5275 .policy
= nl80211_policy
,
5276 .flags
= GENL_ADMIN_PERM
,
5279 .cmd
= NL80211_CMD_SET_CHANNEL
,
5280 .doit
= nl80211_set_channel
,
5281 .policy
= nl80211_policy
,
5282 .flags
= GENL_ADMIN_PERM
,
5286 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
5290 /* multicast groups */
5291 static struct genl_multicast_group nl80211_config_mcgrp
= {
5294 static struct genl_multicast_group nl80211_scan_mcgrp
= {
5297 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
5298 .name
= "regulatory",
5301 /* notification functions */
5303 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
5305 struct sk_buff
*msg
;
5307 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5311 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
5316 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5317 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
5320 static int nl80211_add_scan_req(struct sk_buff
*msg
,
5321 struct cfg80211_registered_device
*rdev
)
5323 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
5324 struct nlattr
*nest
;
5327 ASSERT_RDEV_LOCK(rdev
);
5332 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
5334 goto nla_put_failure
;
5335 for (i
= 0; i
< req
->n_ssids
; i
++)
5336 NLA_PUT(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
);
5337 nla_nest_end(msg
, nest
);
5339 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
5341 goto nla_put_failure
;
5342 for (i
= 0; i
< req
->n_channels
; i
++)
5343 NLA_PUT_U32(msg
, i
, req
->channels
[i
]->center_freq
);
5344 nla_nest_end(msg
, nest
);
5347 NLA_PUT(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
);
5354 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
5355 struct cfg80211_registered_device
*rdev
,
5356 struct net_device
*netdev
,
5357 u32 pid
, u32 seq
, int flags
,
5362 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
5366 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5367 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5369 /* ignore errors and send incomplete event anyway */
5370 nl80211_add_scan_req(msg
, rdev
);
5372 return genlmsg_end(msg
, hdr
);
5375 genlmsg_cancel(msg
, hdr
);
5379 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
5380 struct net_device
*netdev
)
5382 struct sk_buff
*msg
;
5384 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
5388 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5389 NL80211_CMD_TRIGGER_SCAN
) < 0) {
5394 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5395 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5398 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
5399 struct net_device
*netdev
)
5401 struct sk_buff
*msg
;
5403 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5407 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5408 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
5413 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5414 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5417 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
5418 struct net_device
*netdev
)
5420 struct sk_buff
*msg
;
5422 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5426 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5427 NL80211_CMD_SCAN_ABORTED
) < 0) {
5432 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5433 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5437 * This can happen on global regulatory changes or device specific settings
5438 * based on custom world regulatory domains.
5440 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
5442 struct sk_buff
*msg
;
5445 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5449 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
5455 /* Userspace can always count this one always being set */
5456 NLA_PUT_U8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
);
5458 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0')
5459 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5460 NL80211_REGDOM_TYPE_WORLD
);
5461 else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9')
5462 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5463 NL80211_REGDOM_TYPE_CUSTOM_WORLD
);
5464 else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
5466 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5467 NL80211_REGDOM_TYPE_INTERSECTION
);
5469 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5470 NL80211_REGDOM_TYPE_COUNTRY
);
5471 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, request
->alpha2
);
5474 if (wiphy_idx_valid(request
->wiphy_idx
))
5475 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
);
5477 if (genlmsg_end(msg
, hdr
) < 0) {
5483 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
5490 genlmsg_cancel(msg
, hdr
);
5494 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
5495 struct net_device
*netdev
,
5496 const u8
*buf
, size_t len
,
5497 enum nl80211_commands cmd
, gfp_t gfp
)
5499 struct sk_buff
*msg
;
5502 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5506 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
5512 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5513 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5514 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
5516 if (genlmsg_end(msg
, hdr
) < 0) {
5521 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5522 nl80211_mlme_mcgrp
.id
, gfp
);
5526 genlmsg_cancel(msg
, hdr
);
5530 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
5531 struct net_device
*netdev
, const u8
*buf
,
5532 size_t len
, gfp_t gfp
)
5534 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5535 NL80211_CMD_AUTHENTICATE
, gfp
);
5538 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
5539 struct net_device
*netdev
, const u8
*buf
,
5540 size_t len
, gfp_t gfp
)
5542 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5543 NL80211_CMD_ASSOCIATE
, gfp
);
5546 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
5547 struct net_device
*netdev
, const u8
*buf
,
5548 size_t len
, gfp_t gfp
)
5550 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5551 NL80211_CMD_DEAUTHENTICATE
, gfp
);
5554 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
5555 struct net_device
*netdev
, const u8
*buf
,
5556 size_t len
, gfp_t gfp
)
5558 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5559 NL80211_CMD_DISASSOCIATE
, gfp
);
5562 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
5563 struct net_device
*netdev
, int cmd
,
5564 const u8
*addr
, gfp_t gfp
)
5566 struct sk_buff
*msg
;
5569 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5573 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
5579 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5580 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5581 NLA_PUT_FLAG(msg
, NL80211_ATTR_TIMED_OUT
);
5582 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5584 if (genlmsg_end(msg
, hdr
) < 0) {
5589 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5590 nl80211_mlme_mcgrp
.id
, gfp
);
5594 genlmsg_cancel(msg
, hdr
);
5598 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
5599 struct net_device
*netdev
, const u8
*addr
,
5602 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
5606 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
5607 struct net_device
*netdev
, const u8
*addr
,
5610 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
5614 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
5615 struct net_device
*netdev
, const u8
*bssid
,
5616 const u8
*req_ie
, size_t req_ie_len
,
5617 const u8
*resp_ie
, size_t resp_ie_len
,
5618 u16 status
, gfp_t gfp
)
5620 struct sk_buff
*msg
;
5623 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
5627 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
5633 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5634 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5636 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
5637 NLA_PUT_U16(msg
, NL80211_ATTR_STATUS_CODE
, status
);
5639 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
5641 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
5643 if (genlmsg_end(msg
, hdr
) < 0) {
5648 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5649 nl80211_mlme_mcgrp
.id
, gfp
);
5653 genlmsg_cancel(msg
, hdr
);
5658 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
5659 struct net_device
*netdev
, const u8
*bssid
,
5660 const u8
*req_ie
, size_t req_ie_len
,
5661 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
5663 struct sk_buff
*msg
;
5666 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
5670 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
5676 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5677 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5678 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
5680 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
5682 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
5684 if (genlmsg_end(msg
, hdr
) < 0) {
5689 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5690 nl80211_mlme_mcgrp
.id
, gfp
);
5694 genlmsg_cancel(msg
, hdr
);
5699 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
5700 struct net_device
*netdev
, u16 reason
,
5701 const u8
*ie
, size_t ie_len
, bool from_ap
)
5703 struct sk_buff
*msg
;
5706 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
5710 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
5716 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5717 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5718 if (from_ap
&& reason
)
5719 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason
);
5721 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
);
5723 NLA_PUT(msg
, NL80211_ATTR_IE
, ie_len
, ie
);
5725 if (genlmsg_end(msg
, hdr
) < 0) {
5730 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5731 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
5735 genlmsg_cancel(msg
, hdr
);
5740 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
5741 struct net_device
*netdev
, const u8
*bssid
,
5744 struct sk_buff
*msg
;
5747 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5751 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
5757 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5758 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5759 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
5761 if (genlmsg_end(msg
, hdr
) < 0) {
5766 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5767 nl80211_mlme_mcgrp
.id
, gfp
);
5771 genlmsg_cancel(msg
, hdr
);
5775 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
5776 struct net_device
*netdev
, const u8
*addr
,
5777 enum nl80211_key_type key_type
, int key_id
,
5778 const u8
*tsc
, gfp_t gfp
)
5780 struct sk_buff
*msg
;
5783 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5787 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
5793 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5794 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5796 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5797 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
);
5798 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_id
);
5800 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
);
5802 if (genlmsg_end(msg
, hdr
) < 0) {
5807 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5808 nl80211_mlme_mcgrp
.id
, gfp
);
5812 genlmsg_cancel(msg
, hdr
);
5816 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
5817 struct ieee80211_channel
*channel_before
,
5818 struct ieee80211_channel
*channel_after
)
5820 struct sk_buff
*msg
;
5822 struct nlattr
*nl_freq
;
5824 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
5828 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
5835 * Since we are applying the beacon hint to a wiphy we know its
5836 * wiphy_idx is valid
5838 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
));
5841 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
5843 goto nla_put_failure
;
5844 if (nl80211_msg_put_channel(msg
, channel_before
))
5845 goto nla_put_failure
;
5846 nla_nest_end(msg
, nl_freq
);
5849 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
5851 goto nla_put_failure
;
5852 if (nl80211_msg_put_channel(msg
, channel_after
))
5853 goto nla_put_failure
;
5854 nla_nest_end(msg
, nl_freq
);
5856 if (genlmsg_end(msg
, hdr
) < 0) {
5862 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
5869 genlmsg_cancel(msg
, hdr
);
5873 static void nl80211_send_remain_on_chan_event(
5874 int cmd
, struct cfg80211_registered_device
*rdev
,
5875 struct net_device
*netdev
, u64 cookie
,
5876 struct ieee80211_channel
*chan
,
5877 enum nl80211_channel_type channel_type
,
5878 unsigned int duration
, gfp_t gfp
)
5880 struct sk_buff
*msg
;
5883 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5887 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
5893 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5894 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5895 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
);
5896 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, channel_type
);
5897 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
5899 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
)
5900 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, duration
);
5902 if (genlmsg_end(msg
, hdr
) < 0) {
5907 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5908 nl80211_mlme_mcgrp
.id
, gfp
);
5912 genlmsg_cancel(msg
, hdr
);
5916 void nl80211_send_remain_on_channel(struct cfg80211_registered_device
*rdev
,
5917 struct net_device
*netdev
, u64 cookie
,
5918 struct ieee80211_channel
*chan
,
5919 enum nl80211_channel_type channel_type
,
5920 unsigned int duration
, gfp_t gfp
)
5922 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
5923 rdev
, netdev
, cookie
, chan
,
5924 channel_type
, duration
, gfp
);
5927 void nl80211_send_remain_on_channel_cancel(
5928 struct cfg80211_registered_device
*rdev
, struct net_device
*netdev
,
5929 u64 cookie
, struct ieee80211_channel
*chan
,
5930 enum nl80211_channel_type channel_type
, gfp_t gfp
)
5932 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
5933 rdev
, netdev
, cookie
, chan
,
5934 channel_type
, 0, gfp
);
5937 void nl80211_send_sta_event(struct cfg80211_registered_device
*rdev
,
5938 struct net_device
*dev
, const u8
*mac_addr
,
5939 struct station_info
*sinfo
, gfp_t gfp
)
5941 struct sk_buff
*msg
;
5943 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
5947 if (nl80211_send_station(msg
, 0, 0, 0, dev
, mac_addr
, sinfo
) < 0) {
5952 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5953 nl80211_mlme_mcgrp
.id
, gfp
);
5956 int nl80211_send_action(struct cfg80211_registered_device
*rdev
,
5957 struct net_device
*netdev
, u32 nlpid
,
5958 int freq
, const u8
*buf
, size_t len
, gfp_t gfp
)
5960 struct sk_buff
*msg
;
5964 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5968 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ACTION
);
5974 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5975 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5976 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
5977 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
5979 err
= genlmsg_end(msg
, hdr
);
5985 err
= genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
5991 genlmsg_cancel(msg
, hdr
);
5996 void nl80211_send_action_tx_status(struct cfg80211_registered_device
*rdev
,
5997 struct net_device
*netdev
, u64 cookie
,
5998 const u8
*buf
, size_t len
, bool ack
,
6001 struct sk_buff
*msg
;
6004 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6008 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ACTION_TX_STATUS
);
6014 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6015 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6016 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
6017 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
6019 NLA_PUT_FLAG(msg
, NL80211_ATTR_ACK
);
6021 if (genlmsg_end(msg
, hdr
) < 0) {
6026 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
6030 genlmsg_cancel(msg
, hdr
);
6035 nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device
*rdev
,
6036 struct net_device
*netdev
,
6037 enum nl80211_cqm_rssi_threshold_event rssi_event
,
6040 struct sk_buff
*msg
;
6041 struct nlattr
*pinfoattr
;
6044 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6048 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
6054 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6055 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6057 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
6059 goto nla_put_failure
;
6061 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
6064 nla_nest_end(msg
, pinfoattr
);
6066 if (genlmsg_end(msg
, hdr
) < 0) {
6071 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6072 nl80211_mlme_mcgrp
.id
, gfp
);
6076 genlmsg_cancel(msg
, hdr
);
6080 static int nl80211_netlink_notify(struct notifier_block
* nb
,
6081 unsigned long state
,
6084 struct netlink_notify
*notify
= _notify
;
6085 struct cfg80211_registered_device
*rdev
;
6086 struct wireless_dev
*wdev
;
6088 if (state
!= NETLINK_URELEASE
)
6093 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
)
6094 list_for_each_entry_rcu(wdev
, &rdev
->netdev_list
, list
)
6095 cfg80211_mlme_unregister_actions(wdev
, notify
->pid
);
6102 static struct notifier_block nl80211_netlink_notifier
= {
6103 .notifier_call
= nl80211_netlink_notify
,
6106 /* initialisation/exit functions */
6108 int nl80211_init(void)
6112 err
= genl_register_family_with_ops(&nl80211_fam
,
6113 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
6117 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
6121 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
6125 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
6129 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
6133 #ifdef CONFIG_NL80211_TESTMODE
6134 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
6139 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
6145 genl_unregister_family(&nl80211_fam
);
6149 void nl80211_exit(void)
6151 netlink_unregister_notifier(&nl80211_netlink_notifier
);
6152 genl_unregister_family(&nl80211_fam
);