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
},
157 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
158 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
161 /* policy for the attributes */
162 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
163 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
164 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
165 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
166 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 8 },
167 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
168 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
171 /* ifidx get helper */
172 static int nl80211_get_ifidx(struct netlink_callback
*cb
)
176 res
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
177 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
182 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
185 res
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
192 static bool is_valid_ie_attr(const struct nlattr
*attr
)
200 pos
= nla_data(attr
);
221 /* message building helper */
222 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 pid
, u32 seq
,
225 /* since there is no private header just add the generic one */
226 return genlmsg_put(skb
, pid
, seq
, &nl80211_fam
, flags
, cmd
);
229 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
230 struct ieee80211_channel
*chan
)
232 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
235 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
236 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_DISABLED
);
237 if (chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
238 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
);
239 if (chan
->flags
& IEEE80211_CHAN_NO_IBSS
)
240 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
);
241 if (chan
->flags
& IEEE80211_CHAN_RADAR
)
242 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_RADAR
);
244 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
245 DBM_TO_MBM(chan
->max_power
));
253 /* netlink command implementations */
261 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
263 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
264 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
269 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
270 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
272 if (tb
[NL80211_KEY_IDX
])
273 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
275 if (tb
[NL80211_KEY_DATA
]) {
276 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
277 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
280 if (tb
[NL80211_KEY_SEQ
]) {
281 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
282 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
285 if (tb
[NL80211_KEY_CIPHER
])
286 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
291 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
293 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
294 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
295 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
298 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
299 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
300 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
303 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
304 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
306 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
307 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
309 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
310 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
315 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
319 memset(k
, 0, sizeof(*k
));
322 if (info
->attrs
[NL80211_ATTR_KEY
])
323 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
325 err
= nl80211_parse_key_old(info
, k
);
330 if (k
->def
&& k
->defmgmt
)
335 if (k
->idx
< 4 || k
->idx
> 5)
338 if (k
->idx
< 0 || k
->idx
> 3)
341 if (k
->idx
< 0 || k
->idx
> 5)
349 static struct cfg80211_cached_keys
*
350 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
353 struct key_parse parse
;
355 struct cfg80211_cached_keys
*result
;
356 int rem
, err
, def
= 0;
358 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
360 return ERR_PTR(-ENOMEM
);
363 result
->defmgmt
= -1;
365 nla_for_each_nested(key
, keys
, rem
) {
366 memset(&parse
, 0, sizeof(parse
));
369 err
= nl80211_parse_key_new(key
, &parse
);
375 if (parse
.idx
< 0 || parse
.idx
> 4)
381 result
->def
= parse
.idx
;
382 } else if (parse
.defmgmt
)
384 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
388 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
389 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
390 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
391 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
400 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
402 ASSERT_WDEV_LOCK(wdev
);
404 if (!netif_running(wdev
->netdev
))
407 switch (wdev
->iftype
) {
408 case NL80211_IFTYPE_AP
:
409 case NL80211_IFTYPE_AP_VLAN
:
411 case NL80211_IFTYPE_ADHOC
:
412 if (!wdev
->current_bss
)
415 case NL80211_IFTYPE_STATION
:
416 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
426 static int nl80211_send_wiphy(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
427 struct cfg80211_registered_device
*dev
)
430 struct nlattr
*nl_bands
, *nl_band
;
431 struct nlattr
*nl_freqs
, *nl_freq
;
432 struct nlattr
*nl_rates
, *nl_rate
;
433 struct nlattr
*nl_modes
;
434 struct nlattr
*nl_cmds
;
435 enum ieee80211_band band
;
436 struct ieee80211_channel
*chan
;
437 struct ieee80211_rate
*rate
;
439 u16 ifmodes
= dev
->wiphy
.interface_modes
;
441 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
445 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
);
446 NLA_PUT_STRING(msg
, NL80211_ATTR_WIPHY_NAME
, wiphy_name(&dev
->wiphy
));
448 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
449 cfg80211_rdev_list_generation
);
451 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
452 dev
->wiphy
.retry_short
);
453 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
454 dev
->wiphy
.retry_long
);
455 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
456 dev
->wiphy
.frag_threshold
);
457 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
458 dev
->wiphy
.rts_threshold
);
459 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
460 dev
->wiphy
.coverage_class
);
462 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
463 dev
->wiphy
.max_scan_ssids
);
464 NLA_PUT_U16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
465 dev
->wiphy
.max_scan_ie_len
);
467 NLA_PUT(msg
, NL80211_ATTR_CIPHER_SUITES
,
468 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
469 dev
->wiphy
.cipher_suites
);
471 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
472 dev
->wiphy
.max_num_pmkids
);
474 nl_modes
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
);
476 goto nla_put_failure
;
481 NLA_PUT_FLAG(msg
, i
);
486 nla_nest_end(msg
, nl_modes
);
488 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
490 goto nla_put_failure
;
492 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
493 if (!dev
->wiphy
.bands
[band
])
496 nl_band
= nla_nest_start(msg
, band
);
498 goto nla_put_failure
;
501 if (dev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
) {
502 NLA_PUT(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
503 sizeof(dev
->wiphy
.bands
[band
]->ht_cap
.mcs
),
504 &dev
->wiphy
.bands
[band
]->ht_cap
.mcs
);
505 NLA_PUT_U16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
506 dev
->wiphy
.bands
[band
]->ht_cap
.cap
);
507 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
508 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_factor
);
509 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
510 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_density
);
513 /* add frequencies */
514 nl_freqs
= nla_nest_start(msg
, NL80211_BAND_ATTR_FREQS
);
516 goto nla_put_failure
;
518 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_channels
; i
++) {
519 nl_freq
= nla_nest_start(msg
, i
);
521 goto nla_put_failure
;
523 chan
= &dev
->wiphy
.bands
[band
]->channels
[i
];
525 if (nl80211_msg_put_channel(msg
, chan
))
526 goto nla_put_failure
;
528 nla_nest_end(msg
, nl_freq
);
531 nla_nest_end(msg
, nl_freqs
);
534 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
536 goto nla_put_failure
;
538 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_bitrates
; i
++) {
539 nl_rate
= nla_nest_start(msg
, i
);
541 goto nla_put_failure
;
543 rate
= &dev
->wiphy
.bands
[band
]->bitrates
[i
];
544 NLA_PUT_U32(msg
, NL80211_BITRATE_ATTR_RATE
,
546 if (rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
)
548 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
);
550 nla_nest_end(msg
, nl_rate
);
553 nla_nest_end(msg
, nl_rates
);
555 nla_nest_end(msg
, nl_band
);
557 nla_nest_end(msg
, nl_bands
);
559 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
561 goto nla_put_failure
;
566 if (dev->ops->op) { \
568 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
572 CMD(add_virtual_intf
, NEW_INTERFACE
);
573 CMD(change_virtual_intf
, SET_INTERFACE
);
574 CMD(add_key
, NEW_KEY
);
575 CMD(add_beacon
, NEW_BEACON
);
576 CMD(add_station
, NEW_STATION
);
577 CMD(add_mpath
, NEW_MPATH
);
578 CMD(set_mesh_params
, SET_MESH_PARAMS
);
579 CMD(change_bss
, SET_BSS
);
580 CMD(auth
, AUTHENTICATE
);
581 CMD(assoc
, ASSOCIATE
);
582 CMD(deauth
, DEAUTHENTICATE
);
583 CMD(disassoc
, DISASSOCIATE
);
584 CMD(join_ibss
, JOIN_IBSS
);
585 CMD(set_pmksa
, SET_PMKSA
);
586 CMD(del_pmksa
, DEL_PMKSA
);
587 CMD(flush_pmksa
, FLUSH_PMKSA
);
588 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
589 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
591 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
593 NLA_PUT_U32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
);
595 CMD(set_channel
, SET_CHANNEL
);
599 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
601 NLA_PUT_U32(msg
, i
, NL80211_CMD_CONNECT
);
604 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
606 NLA_PUT_U32(msg
, i
, NL80211_CMD_DISCONNECT
);
609 nla_nest_end(msg
, nl_cmds
);
611 return genlmsg_end(msg
, hdr
);
614 genlmsg_cancel(msg
, hdr
);
618 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
621 int start
= cb
->args
[0];
622 struct cfg80211_registered_device
*dev
;
624 mutex_lock(&cfg80211_mutex
);
625 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
626 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
630 if (nl80211_send_wiphy(skb
, NETLINK_CB(cb
->skb
).pid
,
631 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
637 mutex_unlock(&cfg80211_mutex
);
644 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
647 struct cfg80211_registered_device
*dev
;
649 dev
= cfg80211_get_dev_from_info(info
);
653 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
657 if (nl80211_send_wiphy(msg
, info
->snd_pid
, info
->snd_seq
, 0, dev
) < 0)
660 cfg80211_unlock_rdev(dev
);
662 return genlmsg_reply(msg
, info
);
667 cfg80211_unlock_rdev(dev
);
671 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
672 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
673 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
674 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
675 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
676 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
679 static int parse_txq_params(struct nlattr
*tb
[],
680 struct ieee80211_txq_params
*txq_params
)
682 if (!tb
[NL80211_TXQ_ATTR_QUEUE
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
683 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
684 !tb
[NL80211_TXQ_ATTR_AIFS
])
687 txq_params
->queue
= nla_get_u8(tb
[NL80211_TXQ_ATTR_QUEUE
]);
688 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
689 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
690 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
691 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
696 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
699 * You can only set the channel explicitly for AP, mesh
700 * and WDS type interfaces; all others have their channel
701 * managed via their respective "establish a connection"
702 * command (connect, join, ...)
704 * Monitors are special as they are normally slaved to
705 * whatever else is going on, so they behave as though
706 * you tried setting the wiphy channel itself.
709 wdev
->iftype
== NL80211_IFTYPE_AP
||
710 wdev
->iftype
== NL80211_IFTYPE_WDS
||
711 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
712 wdev
->iftype
== NL80211_IFTYPE_MONITOR
;
715 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
716 struct wireless_dev
*wdev
,
717 struct genl_info
*info
)
719 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
723 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
726 if (!nl80211_can_set_dev_channel(wdev
))
729 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
730 channel_type
= nla_get_u32(info
->attrs
[
731 NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
732 if (channel_type
!= NL80211_CHAN_NO_HT
&&
733 channel_type
!= NL80211_CHAN_HT20
&&
734 channel_type
!= NL80211_CHAN_HT40PLUS
&&
735 channel_type
!= NL80211_CHAN_HT40MINUS
)
739 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
741 mutex_lock(&rdev
->devlist_mtx
);
744 result
= cfg80211_set_freq(rdev
, wdev
, freq
, channel_type
);
747 result
= cfg80211_set_freq(rdev
, NULL
, freq
, channel_type
);
749 mutex_unlock(&rdev
->devlist_mtx
);
754 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
756 struct cfg80211_registered_device
*rdev
;
757 struct net_device
*netdev
;
762 result
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &netdev
);
766 result
= __nl80211_set_channel(rdev
, netdev
->ieee80211_ptr
, info
);
774 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
776 struct cfg80211_registered_device
*rdev
;
777 struct net_device
*netdev
= NULL
;
778 struct wireless_dev
*wdev
;
779 int result
, rem_txq_params
= 0;
780 struct nlattr
*nl_txq_params
;
782 u8 retry_short
= 0, retry_long
= 0;
783 u32 frag_threshold
= 0, rts_threshold
= 0;
784 u8 coverage_class
= 0;
789 * Try to find the wiphy and netdev. Normally this
790 * function shouldn't need the netdev, but this is
791 * done for backward compatibility -- previously
792 * setting the channel was done per wiphy, but now
793 * it is per netdev. Previous userland like hostapd
794 * also passed a netdev to set_wiphy, so that it is
795 * possible to let that go to the right netdev!
797 mutex_lock(&cfg80211_mutex
);
799 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
800 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
802 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
803 if (netdev
&& netdev
->ieee80211_ptr
) {
804 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
805 mutex_lock(&rdev
->mtx
);
811 rdev
= __cfg80211_rdev_from_info(info
);
813 mutex_unlock(&cfg80211_mutex
);
814 result
= PTR_ERR(rdev
);
821 mutex_lock(&rdev
->mtx
);
822 } else if (netif_running(netdev
) &&
823 nl80211_can_set_dev_channel(netdev
->ieee80211_ptr
))
824 wdev
= netdev
->ieee80211_ptr
;
829 * end workaround code, by now the rdev is available
830 * and locked, and wdev may or may not be NULL.
833 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
834 result
= cfg80211_dev_rename(
835 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
837 mutex_unlock(&cfg80211_mutex
);
842 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
843 struct ieee80211_txq_params txq_params
;
844 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
846 if (!rdev
->ops
->set_txq_params
) {
847 result
= -EOPNOTSUPP
;
851 nla_for_each_nested(nl_txq_params
,
852 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
854 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
855 nla_data(nl_txq_params
),
856 nla_len(nl_txq_params
),
858 result
= parse_txq_params(tb
, &txq_params
);
862 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
869 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
870 result
= __nl80211_set_channel(rdev
, wdev
, info
);
875 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
876 enum nl80211_tx_power_setting type
;
879 if (!rdev
->ops
->set_tx_power
) {
880 result
= -EOPNOTSUPP
;
884 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
885 type
= nla_get_u32(info
->attrs
[idx
]);
887 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
888 (type
!= NL80211_TX_POWER_AUTOMATIC
)) {
893 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
894 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
895 mbm
= nla_get_u32(info
->attrs
[idx
]);
898 result
= rdev
->ops
->set_tx_power(&rdev
->wiphy
, type
, mbm
);
905 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
906 retry_short
= nla_get_u8(
907 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
908 if (retry_short
== 0) {
912 changed
|= WIPHY_PARAM_RETRY_SHORT
;
915 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
916 retry_long
= nla_get_u8(
917 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
918 if (retry_long
== 0) {
922 changed
|= WIPHY_PARAM_RETRY_LONG
;
925 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
926 frag_threshold
= nla_get_u32(
927 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
928 if (frag_threshold
< 256) {
932 if (frag_threshold
!= (u32
) -1) {
934 * Fragments (apart from the last one) are required to
935 * have even length. Make the fragmentation code
936 * simpler by stripping LSB should someone try to use
937 * odd threshold value.
939 frag_threshold
&= ~0x1;
941 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
944 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
945 rts_threshold
= nla_get_u32(
946 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
947 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
950 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
951 coverage_class
= nla_get_u8(
952 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
953 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
957 u8 old_retry_short
, old_retry_long
;
958 u32 old_frag_threshold
, old_rts_threshold
;
959 u8 old_coverage_class
;
961 if (!rdev
->ops
->set_wiphy_params
) {
962 result
= -EOPNOTSUPP
;
966 old_retry_short
= rdev
->wiphy
.retry_short
;
967 old_retry_long
= rdev
->wiphy
.retry_long
;
968 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
969 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
970 old_coverage_class
= rdev
->wiphy
.coverage_class
;
972 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
973 rdev
->wiphy
.retry_short
= retry_short
;
974 if (changed
& WIPHY_PARAM_RETRY_LONG
)
975 rdev
->wiphy
.retry_long
= retry_long
;
976 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
977 rdev
->wiphy
.frag_threshold
= frag_threshold
;
978 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
979 rdev
->wiphy
.rts_threshold
= rts_threshold
;
980 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
981 rdev
->wiphy
.coverage_class
= coverage_class
;
983 result
= rdev
->ops
->set_wiphy_params(&rdev
->wiphy
, changed
);
985 rdev
->wiphy
.retry_short
= old_retry_short
;
986 rdev
->wiphy
.retry_long
= old_retry_long
;
987 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
988 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
989 rdev
->wiphy
.coverage_class
= old_coverage_class
;
994 mutex_unlock(&rdev
->mtx
);
1003 static int nl80211_send_iface(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
1004 struct cfg80211_registered_device
*rdev
,
1005 struct net_device
*dev
)
1009 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
1013 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1014 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
1015 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, dev
->name
);
1016 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, dev
->ieee80211_ptr
->iftype
);
1018 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
1019 rdev
->devlist_generation
^
1020 (cfg80211_rdev_list_generation
<< 2));
1022 return genlmsg_end(msg
, hdr
);
1025 genlmsg_cancel(msg
, hdr
);
1029 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1033 int wp_start
= cb
->args
[0];
1034 int if_start
= cb
->args
[1];
1035 struct cfg80211_registered_device
*rdev
;
1036 struct wireless_dev
*wdev
;
1038 mutex_lock(&cfg80211_mutex
);
1039 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
1040 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
1042 if (wp_idx
< wp_start
) {
1048 mutex_lock(&rdev
->devlist_mtx
);
1049 list_for_each_entry(wdev
, &rdev
->netdev_list
, list
) {
1050 if (if_idx
< if_start
) {
1054 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).pid
,
1055 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1056 rdev
, wdev
->netdev
) < 0) {
1057 mutex_unlock(&rdev
->devlist_mtx
);
1062 mutex_unlock(&rdev
->devlist_mtx
);
1067 mutex_unlock(&cfg80211_mutex
);
1069 cb
->args
[0] = wp_idx
;
1070 cb
->args
[1] = if_idx
;
1075 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1077 struct sk_buff
*msg
;
1078 struct cfg80211_registered_device
*dev
;
1079 struct net_device
*netdev
;
1082 err
= get_rdev_dev_by_info_ifindex(info
, &dev
, &netdev
);
1086 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1090 if (nl80211_send_iface(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1095 cfg80211_unlock_rdev(dev
);
1097 return genlmsg_reply(msg
, info
);
1103 cfg80211_unlock_rdev(dev
);
1107 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
1108 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
1109 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
1110 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
1111 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
1112 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
1115 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
1117 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
1125 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
1126 nla
, mntr_flags_policy
))
1129 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
1131 *mntrflags
|= (1<<flag
);
1136 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
1137 struct net_device
*netdev
, u8 use_4addr
,
1138 enum nl80211_iftype iftype
)
1141 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
1147 case NL80211_IFTYPE_AP_VLAN
:
1148 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
1151 case NL80211_IFTYPE_STATION
:
1152 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
1162 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1164 struct cfg80211_registered_device
*rdev
;
1165 struct vif_params params
;
1167 enum nl80211_iftype otype
, ntype
;
1168 struct net_device
*dev
;
1169 u32 _flags
, *flags
= NULL
;
1170 bool change
= false;
1172 memset(¶ms
, 0, sizeof(params
));
1176 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1180 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
1182 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1183 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1186 if (ntype
> NL80211_IFTYPE_MAX
) {
1192 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1193 if (ntype
!= NL80211_IFTYPE_MESH_POINT
) {
1197 params
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1198 params
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1202 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1203 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1205 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
1209 params
.use_4addr
= -1;
1212 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
1213 if (ntype
!= NL80211_IFTYPE_MONITOR
) {
1217 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
1227 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
1231 if (!err
&& params
.use_4addr
!= -1)
1232 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
1236 cfg80211_unlock_rdev(rdev
);
1242 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1244 struct cfg80211_registered_device
*rdev
;
1245 struct vif_params params
;
1247 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
1250 memset(¶ms
, 0, sizeof(params
));
1252 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
1255 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1256 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1257 if (type
> NL80211_IFTYPE_MAX
)
1263 rdev
= cfg80211_get_dev_from_info(info
);
1265 err
= PTR_ERR(rdev
);
1269 if (!rdev
->ops
->add_virtual_intf
||
1270 !(rdev
->wiphy
.interface_modes
& (1 << type
))) {
1275 if (type
== NL80211_IFTYPE_MESH_POINT
&&
1276 info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1277 params
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1278 params
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1281 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1282 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1283 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
1288 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
1289 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
1291 err
= rdev
->ops
->add_virtual_intf(&rdev
->wiphy
,
1292 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
1293 type
, err
? NULL
: &flags
, ¶ms
);
1296 cfg80211_unlock_rdev(rdev
);
1302 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1304 struct cfg80211_registered_device
*rdev
;
1306 struct net_device
*dev
;
1310 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1314 if (!rdev
->ops
->del_virtual_intf
) {
1319 err
= rdev
->ops
->del_virtual_intf(&rdev
->wiphy
, dev
);
1322 cfg80211_unlock_rdev(rdev
);
1329 struct get_key_cookie
{
1330 struct sk_buff
*msg
;
1335 static void get_key_callback(void *c
, struct key_params
*params
)
1338 struct get_key_cookie
*cookie
= c
;
1341 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
1342 params
->key_len
, params
->key
);
1345 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
1346 params
->seq_len
, params
->seq
);
1349 NLA_PUT_U32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
1352 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
1354 goto nla_put_failure
;
1357 NLA_PUT(cookie
->msg
, NL80211_KEY_DATA
,
1358 params
->key_len
, params
->key
);
1361 NLA_PUT(cookie
->msg
, NL80211_KEY_SEQ
,
1362 params
->seq_len
, params
->seq
);
1365 NLA_PUT_U32(cookie
->msg
, NL80211_KEY_CIPHER
,
1368 NLA_PUT_U8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
);
1370 nla_nest_end(cookie
->msg
, key
);
1377 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
1379 struct cfg80211_registered_device
*rdev
;
1381 struct net_device
*dev
;
1383 u8
*mac_addr
= NULL
;
1384 struct get_key_cookie cookie
= {
1388 struct sk_buff
*msg
;
1390 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
1391 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1396 if (info
->attrs
[NL80211_ATTR_MAC
])
1397 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1401 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1405 if (!rdev
->ops
->get_key
) {
1410 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1416 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1417 NL80211_CMD_NEW_KEY
);
1425 cookie
.idx
= key_idx
;
1427 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1428 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
1430 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1432 err
= rdev
->ops
->get_key(&rdev
->wiphy
, dev
, key_idx
, mac_addr
,
1433 &cookie
, get_key_callback
);
1439 goto nla_put_failure
;
1441 genlmsg_end(msg
, hdr
);
1442 err
= genlmsg_reply(msg
, info
);
1450 cfg80211_unlock_rdev(rdev
);
1458 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
1460 struct cfg80211_registered_device
*rdev
;
1461 struct key_parse key
;
1463 struct net_device
*dev
;
1464 int (*func
)(struct wiphy
*wiphy
, struct net_device
*netdev
,
1467 err
= nl80211_parse_key(info
, &key
);
1474 /* only support setting default key */
1475 if (!key
.def
&& !key
.defmgmt
)
1480 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1485 func
= rdev
->ops
->set_default_key
;
1487 func
= rdev
->ops
->set_default_mgmt_key
;
1494 wdev_lock(dev
->ieee80211_ptr
);
1495 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1497 err
= func(&rdev
->wiphy
, dev
, key
.idx
);
1499 #ifdef CONFIG_CFG80211_WEXT
1501 if (func
== rdev
->ops
->set_default_key
)
1502 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
1504 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
1507 wdev_unlock(dev
->ieee80211_ptr
);
1510 cfg80211_unlock_rdev(rdev
);
1519 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
1521 struct cfg80211_registered_device
*rdev
;
1523 struct net_device
*dev
;
1524 struct key_parse key
;
1525 u8
*mac_addr
= NULL
;
1527 err
= nl80211_parse_key(info
, &key
);
1534 if (info
->attrs
[NL80211_ATTR_MAC
])
1535 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1539 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1543 if (!rdev
->ops
->add_key
) {
1548 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
, mac_addr
)) {
1553 wdev_lock(dev
->ieee80211_ptr
);
1554 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1556 err
= rdev
->ops
->add_key(&rdev
->wiphy
, dev
, key
.idx
,
1558 wdev_unlock(dev
->ieee80211_ptr
);
1561 cfg80211_unlock_rdev(rdev
);
1569 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
1571 struct cfg80211_registered_device
*rdev
;
1573 struct net_device
*dev
;
1574 u8
*mac_addr
= NULL
;
1575 struct key_parse key
;
1577 err
= nl80211_parse_key(info
, &key
);
1581 if (info
->attrs
[NL80211_ATTR_MAC
])
1582 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1586 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1590 if (!rdev
->ops
->del_key
) {
1595 wdev_lock(dev
->ieee80211_ptr
);
1596 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1598 err
= rdev
->ops
->del_key(&rdev
->wiphy
, dev
, key
.idx
, mac_addr
);
1600 #ifdef CONFIG_CFG80211_WEXT
1602 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
1603 dev
->ieee80211_ptr
->wext
.default_key
= -1;
1604 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
1605 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
1608 wdev_unlock(dev
->ieee80211_ptr
);
1611 cfg80211_unlock_rdev(rdev
);
1620 static int nl80211_addset_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1622 int (*call
)(struct wiphy
*wiphy
, struct net_device
*dev
,
1623 struct beacon_parameters
*info
);
1624 struct cfg80211_registered_device
*rdev
;
1626 struct net_device
*dev
;
1627 struct beacon_parameters params
;
1630 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]))
1635 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1639 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1644 switch (info
->genlhdr
->cmd
) {
1645 case NL80211_CMD_NEW_BEACON
:
1646 /* these are required for NEW_BEACON */
1647 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
1648 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
1649 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1654 call
= rdev
->ops
->add_beacon
;
1656 case NL80211_CMD_SET_BEACON
:
1657 call
= rdev
->ops
->set_beacon
;
1670 memset(¶ms
, 0, sizeof(params
));
1672 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
1674 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
1678 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
1679 params
.dtim_period
=
1680 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
1684 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1685 params
.head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1687 nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1691 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
1692 params
.tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1694 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1703 err
= call(&rdev
->wiphy
, dev
, ¶ms
);
1706 cfg80211_unlock_rdev(rdev
);
1714 static int nl80211_del_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1716 struct cfg80211_registered_device
*rdev
;
1718 struct net_device
*dev
;
1722 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1726 if (!rdev
->ops
->del_beacon
) {
1731 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1735 err
= rdev
->ops
->del_beacon(&rdev
->wiphy
, dev
);
1738 cfg80211_unlock_rdev(rdev
);
1746 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
1747 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
1748 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
1749 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
1750 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
1753 static int parse_station_flags(struct genl_info
*info
,
1754 struct station_parameters
*params
)
1756 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
1761 * Try parsing the new attribute first so userspace
1762 * can specify both for older kernels.
1764 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
1766 struct nl80211_sta_flag_update
*sta_flags
;
1768 sta_flags
= nla_data(nla
);
1769 params
->sta_flags_mask
= sta_flags
->mask
;
1770 params
->sta_flags_set
= sta_flags
->set
;
1771 if ((params
->sta_flags_mask
|
1772 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
1777 /* if present, parse the old attribute */
1779 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
1783 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
1784 nla
, sta_flags_policy
))
1787 params
->sta_flags_mask
= (1 << __NL80211_STA_FLAG_AFTER_LAST
) - 1;
1788 params
->sta_flags_mask
&= ~1;
1790 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++)
1792 params
->sta_flags_set
|= (1<<flag
);
1797 static int nl80211_send_station(struct sk_buff
*msg
, u32 pid
, u32 seq
,
1798 int flags
, struct net_device
*dev
,
1799 const u8
*mac_addr
, struct station_info
*sinfo
)
1802 struct nlattr
*sinfoattr
, *txrate
;
1805 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
1809 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1810 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1812 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
);
1814 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
1816 goto nla_put_failure
;
1817 if (sinfo
->filled
& STATION_INFO_INACTIVE_TIME
)
1818 NLA_PUT_U32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
1819 sinfo
->inactive_time
);
1820 if (sinfo
->filled
& STATION_INFO_RX_BYTES
)
1821 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_BYTES
,
1823 if (sinfo
->filled
& STATION_INFO_TX_BYTES
)
1824 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_BYTES
,
1826 if (sinfo
->filled
& STATION_INFO_LLID
)
1827 NLA_PUT_U16(msg
, NL80211_STA_INFO_LLID
,
1829 if (sinfo
->filled
& STATION_INFO_PLID
)
1830 NLA_PUT_U16(msg
, NL80211_STA_INFO_PLID
,
1832 if (sinfo
->filled
& STATION_INFO_PLINK_STATE
)
1833 NLA_PUT_U8(msg
, NL80211_STA_INFO_PLINK_STATE
,
1834 sinfo
->plink_state
);
1835 if (sinfo
->filled
& STATION_INFO_SIGNAL
)
1836 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL
,
1838 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
1839 txrate
= nla_nest_start(msg
, NL80211_STA_INFO_TX_BITRATE
);
1841 goto nla_put_failure
;
1843 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
1844 bitrate
= cfg80211_calculate_bitrate(&sinfo
->txrate
);
1846 NLA_PUT_U16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate
);
1848 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_MCS
)
1849 NLA_PUT_U8(msg
, NL80211_RATE_INFO_MCS
,
1851 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
)
1852 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
);
1853 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_SHORT_GI
)
1854 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_SHORT_GI
);
1856 nla_nest_end(msg
, txrate
);
1858 if (sinfo
->filled
& STATION_INFO_RX_PACKETS
)
1859 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_PACKETS
,
1861 if (sinfo
->filled
& STATION_INFO_TX_PACKETS
)
1862 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_PACKETS
,
1864 nla_nest_end(msg
, sinfoattr
);
1866 return genlmsg_end(msg
, hdr
);
1869 genlmsg_cancel(msg
, hdr
);
1873 static int nl80211_dump_station(struct sk_buff
*skb
,
1874 struct netlink_callback
*cb
)
1876 struct station_info sinfo
;
1877 struct cfg80211_registered_device
*dev
;
1878 struct net_device
*netdev
;
1879 u8 mac_addr
[ETH_ALEN
];
1880 int ifidx
= cb
->args
[0];
1881 int sta_idx
= cb
->args
[1];
1885 ifidx
= nl80211_get_ifidx(cb
);
1891 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
1897 dev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
1903 if (!dev
->ops
->dump_station
) {
1909 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
1916 if (nl80211_send_station(skb
,
1917 NETLINK_CB(cb
->skb
).pid
,
1918 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1928 cb
->args
[1] = sta_idx
;
1931 cfg80211_unlock_rdev(dev
);
1938 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
1940 struct cfg80211_registered_device
*rdev
;
1942 struct net_device
*dev
;
1943 struct station_info sinfo
;
1944 struct sk_buff
*msg
;
1945 u8
*mac_addr
= NULL
;
1947 memset(&sinfo
, 0, sizeof(sinfo
));
1949 if (!info
->attrs
[NL80211_ATTR_MAC
])
1952 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1956 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1960 if (!rdev
->ops
->get_station
) {
1965 err
= rdev
->ops
->get_station(&rdev
->wiphy
, dev
, mac_addr
, &sinfo
);
1969 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1973 if (nl80211_send_station(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1974 dev
, mac_addr
, &sinfo
) < 0)
1977 err
= genlmsg_reply(msg
, info
);
1983 cfg80211_unlock_rdev(rdev
);
1992 * Get vlan interface making sure it is running and on the right wiphy.
1994 static int get_vlan(struct genl_info
*info
,
1995 struct cfg80211_registered_device
*rdev
,
1996 struct net_device
**vlan
)
1998 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
2002 *vlan
= dev_get_by_index(genl_info_net(info
),
2003 nla_get_u32(vlanattr
));
2006 if (!(*vlan
)->ieee80211_ptr
)
2008 if ((*vlan
)->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
)
2010 if (!netif_running(*vlan
))
2016 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
2018 struct cfg80211_registered_device
*rdev
;
2020 struct net_device
*dev
;
2021 struct station_parameters params
;
2022 u8
*mac_addr
= NULL
;
2024 memset(¶ms
, 0, sizeof(params
));
2026 params
.listen_interval
= -1;
2028 if (info
->attrs
[NL80211_ATTR_STA_AID
])
2031 if (!info
->attrs
[NL80211_ATTR_MAC
])
2034 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2036 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
2037 params
.supported_rates
=
2038 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2039 params
.supported_rates_len
=
2040 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2043 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2044 params
.listen_interval
=
2045 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2047 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2049 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2051 if (parse_station_flags(info
, ¶ms
))
2054 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
2055 params
.plink_action
=
2056 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
2060 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2064 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
2068 /* validate settings */
2071 switch (dev
->ieee80211_ptr
->iftype
) {
2072 case NL80211_IFTYPE_AP
:
2073 case NL80211_IFTYPE_AP_VLAN
:
2074 /* disallow mesh-specific things */
2075 if (params
.plink_action
)
2078 case NL80211_IFTYPE_STATION
:
2079 /* disallow everything but AUTHORIZED flag */
2080 if (params
.plink_action
)
2084 if (params
.supported_rates
)
2088 if (params
.listen_interval
>= 0)
2090 if (params
.sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
2093 case NL80211_IFTYPE_MESH_POINT
:
2094 /* disallow things mesh doesn't support */
2099 if (params
.listen_interval
>= 0)
2101 if (params
.supported_rates
)
2103 if (params
.sta_flags_mask
)
2113 if (!rdev
->ops
->change_station
) {
2118 err
= rdev
->ops
->change_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2122 dev_put(params
.vlan
);
2123 cfg80211_unlock_rdev(rdev
);
2131 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
2133 struct cfg80211_registered_device
*rdev
;
2135 struct net_device
*dev
;
2136 struct station_parameters params
;
2137 u8
*mac_addr
= NULL
;
2139 memset(¶ms
, 0, sizeof(params
));
2141 if (!info
->attrs
[NL80211_ATTR_MAC
])
2144 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2147 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
2150 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
2153 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2154 params
.supported_rates
=
2155 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2156 params
.supported_rates_len
=
2157 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2158 params
.listen_interval
=
2159 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2161 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
2162 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
2165 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2167 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2169 if (parse_station_flags(info
, ¶ms
))
2174 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2178 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2179 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
) {
2184 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
2188 /* validate settings */
2191 if (!rdev
->ops
->add_station
) {
2196 if (!netif_running(dev
)) {
2201 err
= rdev
->ops
->add_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2205 dev_put(params
.vlan
);
2206 cfg80211_unlock_rdev(rdev
);
2214 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
2216 struct cfg80211_registered_device
*rdev
;
2218 struct net_device
*dev
;
2219 u8
*mac_addr
= NULL
;
2221 if (info
->attrs
[NL80211_ATTR_MAC
])
2222 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2226 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2230 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2231 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
2232 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2237 if (!rdev
->ops
->del_station
) {
2242 err
= rdev
->ops
->del_station(&rdev
->wiphy
, dev
, mac_addr
);
2245 cfg80211_unlock_rdev(rdev
);
2253 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2254 int flags
, struct net_device
*dev
,
2255 u8
*dst
, u8
*next_hop
,
2256 struct mpath_info
*pinfo
)
2259 struct nlattr
*pinfoattr
;
2261 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2265 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2266 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
2267 NLA_PUT(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
);
2269 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
);
2271 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
2273 goto nla_put_failure
;
2274 if (pinfo
->filled
& MPATH_INFO_FRAME_QLEN
)
2275 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
2277 if (pinfo
->filled
& MPATH_INFO_SN
)
2278 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_SN
,
2280 if (pinfo
->filled
& MPATH_INFO_METRIC
)
2281 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_METRIC
,
2283 if (pinfo
->filled
& MPATH_INFO_EXPTIME
)
2284 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_EXPTIME
,
2286 if (pinfo
->filled
& MPATH_INFO_FLAGS
)
2287 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_FLAGS
,
2289 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
)
2290 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
2291 pinfo
->discovery_timeout
);
2292 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
)
2293 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
2294 pinfo
->discovery_retries
);
2296 nla_nest_end(msg
, pinfoattr
);
2298 return genlmsg_end(msg
, hdr
);
2301 genlmsg_cancel(msg
, hdr
);
2305 static int nl80211_dump_mpath(struct sk_buff
*skb
,
2306 struct netlink_callback
*cb
)
2308 struct mpath_info pinfo
;
2309 struct cfg80211_registered_device
*dev
;
2310 struct net_device
*netdev
;
2312 u8 next_hop
[ETH_ALEN
];
2313 int ifidx
= cb
->args
[0];
2314 int path_idx
= cb
->args
[1];
2318 ifidx
= nl80211_get_ifidx(cb
);
2324 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
2330 dev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
2336 if (!dev
->ops
->dump_mpath
) {
2341 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2347 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
2348 dst
, next_hop
, &pinfo
);
2354 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).pid
,
2355 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2356 netdev
, dst
, next_hop
,
2365 cb
->args
[1] = path_idx
;
2368 cfg80211_unlock_rdev(dev
);
2375 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2377 struct cfg80211_registered_device
*rdev
;
2379 struct net_device
*dev
;
2380 struct mpath_info pinfo
;
2381 struct sk_buff
*msg
;
2383 u8 next_hop
[ETH_ALEN
];
2385 memset(&pinfo
, 0, sizeof(pinfo
));
2387 if (!info
->attrs
[NL80211_ATTR_MAC
])
2390 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2394 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2398 if (!rdev
->ops
->get_mpath
) {
2403 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2408 err
= rdev
->ops
->get_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
2412 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2416 if (nl80211_send_mpath(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2417 dev
, dst
, next_hop
, &pinfo
) < 0)
2420 err
= genlmsg_reply(msg
, info
);
2426 cfg80211_unlock_rdev(rdev
);
2434 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2436 struct cfg80211_registered_device
*rdev
;
2438 struct net_device
*dev
;
2440 u8
*next_hop
= NULL
;
2442 if (!info
->attrs
[NL80211_ATTR_MAC
])
2445 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2448 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2449 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2453 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2457 if (!rdev
->ops
->change_mpath
) {
2462 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2467 if (!netif_running(dev
)) {
2472 err
= rdev
->ops
->change_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2475 cfg80211_unlock_rdev(rdev
);
2482 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2484 struct cfg80211_registered_device
*rdev
;
2486 struct net_device
*dev
;
2488 u8
*next_hop
= NULL
;
2490 if (!info
->attrs
[NL80211_ATTR_MAC
])
2493 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2496 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2497 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2501 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2505 if (!rdev
->ops
->add_mpath
) {
2510 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2515 if (!netif_running(dev
)) {
2520 err
= rdev
->ops
->add_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2523 cfg80211_unlock_rdev(rdev
);
2531 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2533 struct cfg80211_registered_device
*rdev
;
2535 struct net_device
*dev
;
2538 if (info
->attrs
[NL80211_ATTR_MAC
])
2539 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2543 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2547 if (!rdev
->ops
->del_mpath
) {
2552 err
= rdev
->ops
->del_mpath(&rdev
->wiphy
, dev
, dst
);
2555 cfg80211_unlock_rdev(rdev
);
2563 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
2565 struct cfg80211_registered_device
*rdev
;
2567 struct net_device
*dev
;
2568 struct bss_parameters params
;
2570 memset(¶ms
, 0, sizeof(params
));
2571 /* default to not changing parameters */
2572 params
.use_cts_prot
= -1;
2573 params
.use_short_preamble
= -1;
2574 params
.use_short_slot_time
= -1;
2575 params
.ap_isolate
= -1;
2577 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
2578 params
.use_cts_prot
=
2579 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
2580 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
2581 params
.use_short_preamble
=
2582 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
2583 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
2584 params
.use_short_slot_time
=
2585 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
2586 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
2587 params
.basic_rates
=
2588 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2589 params
.basic_rates_len
=
2590 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2592 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
2593 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
2597 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2601 if (!rdev
->ops
->change_bss
) {
2606 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
2611 err
= rdev
->ops
->change_bss(&rdev
->wiphy
, dev
, ¶ms
);
2614 cfg80211_unlock_rdev(rdev
);
2622 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
2623 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
2624 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
2625 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
2626 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
2627 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
2628 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
2631 static int parse_reg_rule(struct nlattr
*tb
[],
2632 struct ieee80211_reg_rule
*reg_rule
)
2634 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
2635 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
2637 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
2639 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
2641 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
2643 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
2645 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
2648 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
2650 freq_range
->start_freq_khz
=
2651 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
2652 freq_range
->end_freq_khz
=
2653 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
2654 freq_range
->max_bandwidth_khz
=
2655 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
2657 power_rule
->max_eirp
=
2658 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
2660 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
2661 power_rule
->max_antenna_gain
=
2662 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
2667 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2673 * You should only get this when cfg80211 hasn't yet initialized
2674 * completely when built-in to the kernel right between the time
2675 * window between nl80211_init() and regulatory_init(), if that is
2678 mutex_lock(&cfg80211_mutex
);
2679 if (unlikely(!cfg80211_regdomain
)) {
2680 mutex_unlock(&cfg80211_mutex
);
2681 return -EINPROGRESS
;
2683 mutex_unlock(&cfg80211_mutex
);
2685 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2688 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2690 r
= regulatory_hint_user(data
);
2695 static int nl80211_get_mesh_params(struct sk_buff
*skb
,
2696 struct genl_info
*info
)
2698 struct cfg80211_registered_device
*rdev
;
2699 struct mesh_config cur_params
;
2701 struct net_device
*dev
;
2703 struct nlattr
*pinfoattr
;
2704 struct sk_buff
*msg
;
2708 /* Look up our device */
2709 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2713 if (!rdev
->ops
->get_mesh_params
) {
2718 /* Get the mesh params */
2719 err
= rdev
->ops
->get_mesh_params(&rdev
->wiphy
, dev
, &cur_params
);
2723 /* Draw up a netlink message to send back */
2724 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2729 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2730 NL80211_CMD_GET_MESH_PARAMS
);
2732 goto nla_put_failure
;
2733 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_PARAMS
);
2735 goto nla_put_failure
;
2736 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2737 NLA_PUT_U16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
2738 cur_params
.dot11MeshRetryTimeout
);
2739 NLA_PUT_U16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
2740 cur_params
.dot11MeshConfirmTimeout
);
2741 NLA_PUT_U16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
2742 cur_params
.dot11MeshHoldingTimeout
);
2743 NLA_PUT_U16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
2744 cur_params
.dot11MeshMaxPeerLinks
);
2745 NLA_PUT_U8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
2746 cur_params
.dot11MeshMaxRetries
);
2747 NLA_PUT_U8(msg
, NL80211_MESHCONF_TTL
,
2748 cur_params
.dot11MeshTTL
);
2749 NLA_PUT_U8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
2750 cur_params
.auto_open_plinks
);
2751 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2752 cur_params
.dot11MeshHWMPmaxPREQretries
);
2753 NLA_PUT_U32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
2754 cur_params
.path_refresh_time
);
2755 NLA_PUT_U16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2756 cur_params
.min_discovery_timeout
);
2757 NLA_PUT_U32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2758 cur_params
.dot11MeshHWMPactivePathTimeout
);
2759 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2760 cur_params
.dot11MeshHWMPpreqMinInterval
);
2761 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2762 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
);
2763 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
2764 cur_params
.dot11MeshHWMPRootMode
);
2765 nla_nest_end(msg
, pinfoattr
);
2766 genlmsg_end(msg
, hdr
);
2767 err
= genlmsg_reply(msg
, info
);
2771 genlmsg_cancel(msg
, hdr
);
2776 cfg80211_unlock_rdev(rdev
);
2784 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2786 if (table[attr_num]) {\
2787 cfg.param = nla_fn(table[attr_num]); \
2788 mask |= (1 << (attr_num - 1)); \
2792 static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
2793 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
2794 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
2795 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
2796 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
2797 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
2798 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
2799 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
2801 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
2802 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
2803 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
2804 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
2805 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
2806 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
2809 static int nl80211_set_mesh_params(struct sk_buff
*skb
, struct genl_info
*info
)
2813 struct cfg80211_registered_device
*rdev
;
2814 struct net_device
*dev
;
2815 struct mesh_config cfg
;
2816 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
2817 struct nlattr
*parent_attr
;
2819 parent_attr
= info
->attrs
[NL80211_ATTR_MESH_PARAMS
];
2822 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
2823 parent_attr
, nl80211_meshconf_params_policy
))
2828 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2832 if (!rdev
->ops
->set_mesh_params
) {
2837 /* This makes sure that there aren't more than 32 mesh config
2838 * parameters (otherwise our bitfield scheme would not work.) */
2839 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
2841 /* Fill in the params struct */
2843 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
2844 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
, nla_get_u16
);
2845 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
2846 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
, nla_get_u16
);
2847 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
2848 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
, nla_get_u16
);
2849 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
2850 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
, nla_get_u16
);
2851 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
2852 mask
, NL80211_MESHCONF_MAX_RETRIES
, nla_get_u8
);
2853 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
2854 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
2855 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
2856 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
, nla_get_u8
);
2857 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
2858 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2860 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
2861 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
, nla_get_u32
);
2862 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
2863 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2865 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
2866 mask
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2868 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
2869 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2871 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
2872 dot11MeshHWMPnetDiameterTraversalTime
,
2873 mask
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2875 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
2876 dot11MeshHWMPRootMode
, mask
,
2877 NL80211_MESHCONF_HWMP_ROOTMODE
,
2881 err
= rdev
->ops
->set_mesh_params(&rdev
->wiphy
, dev
, &cfg
, mask
);
2885 cfg80211_unlock_rdev(rdev
);
2893 #undef FILL_IN_MESH_PARAM_IF_SET
2895 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2897 struct sk_buff
*msg
;
2899 struct nlattr
*nl_reg_rules
;
2903 mutex_lock(&cfg80211_mutex
);
2905 if (!cfg80211_regdomain
)
2908 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2914 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2915 NL80211_CMD_GET_REG
);
2917 goto nla_put_failure
;
2919 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
,
2920 cfg80211_regdomain
->alpha2
);
2922 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
2924 goto nla_put_failure
;
2926 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
2927 struct nlattr
*nl_reg_rule
;
2928 const struct ieee80211_reg_rule
*reg_rule
;
2929 const struct ieee80211_freq_range
*freq_range
;
2930 const struct ieee80211_power_rule
*power_rule
;
2932 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
2933 freq_range
= ®_rule
->freq_range
;
2934 power_rule
= ®_rule
->power_rule
;
2936 nl_reg_rule
= nla_nest_start(msg
, i
);
2938 goto nla_put_failure
;
2940 NLA_PUT_U32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
2942 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
2943 freq_range
->start_freq_khz
);
2944 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
2945 freq_range
->end_freq_khz
);
2946 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
2947 freq_range
->max_bandwidth_khz
);
2948 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
2949 power_rule
->max_antenna_gain
);
2950 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
2951 power_rule
->max_eirp
);
2953 nla_nest_end(msg
, nl_reg_rule
);
2956 nla_nest_end(msg
, nl_reg_rules
);
2958 genlmsg_end(msg
, hdr
);
2959 err
= genlmsg_reply(msg
, info
);
2963 genlmsg_cancel(msg
, hdr
);
2967 mutex_unlock(&cfg80211_mutex
);
2971 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2973 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
2974 struct nlattr
*nl_reg_rule
;
2975 char *alpha2
= NULL
;
2976 int rem_reg_rules
= 0, r
= 0;
2977 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
2978 struct ieee80211_regdomain
*rd
= NULL
;
2980 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2983 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
2986 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2988 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
2991 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
2995 mutex_lock(&cfg80211_mutex
);
2997 if (!reg_is_valid_request(alpha2
)) {
3002 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
3003 (num_rules
* sizeof(struct ieee80211_reg_rule
));
3005 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
3011 rd
->n_reg_rules
= num_rules
;
3012 rd
->alpha2
[0] = alpha2
[0];
3013 rd
->alpha2
[1] = alpha2
[1];
3015 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
3017 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
3018 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
3020 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
3026 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
3032 BUG_ON(rule_idx
!= num_rules
);
3036 mutex_unlock(&cfg80211_mutex
);
3041 mutex_unlock(&cfg80211_mutex
);
3046 static int validate_scan_freqs(struct nlattr
*freqs
)
3048 struct nlattr
*attr1
, *attr2
;
3049 int n_channels
= 0, tmp1
, tmp2
;
3051 nla_for_each_nested(attr1
, freqs
, tmp1
) {
3054 * Some hardware has a limited channel list for
3055 * scanning, and it is pretty much nonsensical
3056 * to scan for a channel twice, so disallow that
3057 * and don't require drivers to check that the
3058 * channel list they get isn't longer than what
3059 * they can scan, as long as they can scan all
3060 * the channels they registered at once.
3062 nla_for_each_nested(attr2
, freqs
, tmp2
)
3063 if (attr1
!= attr2
&&
3064 nla_get_u32(attr1
) == nla_get_u32(attr2
))
3071 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
3073 struct cfg80211_registered_device
*rdev
;
3074 struct net_device
*dev
;
3075 struct cfg80211_scan_request
*request
;
3076 struct cfg80211_ssid
*ssid
;
3077 struct ieee80211_channel
*channel
;
3078 struct nlattr
*attr
;
3079 struct wiphy
*wiphy
;
3080 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
3081 enum ieee80211_band band
;
3084 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3089 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3093 wiphy
= &rdev
->wiphy
;
3095 if (!rdev
->ops
->scan
) {
3100 if (!netif_running(dev
)) {
3105 if (rdev
->scan_req
) {
3110 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3111 n_channels
= validate_scan_freqs(
3112 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
3120 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
3121 if (wiphy
->bands
[band
])
3122 n_channels
+= wiphy
->bands
[band
]->n_channels
;
3125 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
3126 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
3129 if (n_ssids
> wiphy
->max_scan_ssids
) {
3134 if (info
->attrs
[NL80211_ATTR_IE
])
3135 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3139 if (ie_len
> wiphy
->max_scan_ie_len
) {
3144 request
= kzalloc(sizeof(*request
)
3145 + sizeof(*ssid
) * n_ssids
3146 + sizeof(channel
) * n_channels
3147 + ie_len
, GFP_KERNEL
);
3154 request
->ssids
= (void *)&request
->channels
[n_channels
];
3155 request
->n_ssids
= n_ssids
;
3158 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
3160 request
->ie
= (void *)(request
->channels
+ n_channels
);
3164 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3165 /* user specified, bail out if channel not found */
3166 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
3167 struct ieee80211_channel
*chan
;
3169 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
3176 /* ignore disabled channels */
3177 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3180 request
->channels
[i
] = chan
;
3185 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
3187 if (!wiphy
->bands
[band
])
3189 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
3190 struct ieee80211_channel
*chan
;
3192 chan
= &wiphy
->bands
[band
]->channels
[j
];
3194 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3197 request
->channels
[i
] = chan
;
3208 request
->n_channels
= i
;
3211 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
3212 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
3213 if (request
->ssids
[i
].ssid_len
> IEEE80211_MAX_SSID_LEN
) {
3217 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
3218 request
->ssids
[i
].ssid_len
= nla_len(attr
);
3223 if (info
->attrs
[NL80211_ATTR_IE
]) {
3224 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3225 memcpy((void *)request
->ie
,
3226 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
3231 request
->wiphy
= &rdev
->wiphy
;
3233 rdev
->scan_req
= request
;
3234 err
= rdev
->ops
->scan(&rdev
->wiphy
, dev
, request
);
3237 nl80211_send_scan_start(rdev
, dev
);
3243 rdev
->scan_req
= NULL
;
3247 cfg80211_unlock_rdev(rdev
);
3255 static int nl80211_send_bss(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
3256 struct cfg80211_registered_device
*rdev
,
3257 struct wireless_dev
*wdev
,
3258 struct cfg80211_internal_bss
*intbss
)
3260 struct cfg80211_bss
*res
= &intbss
->pub
;
3265 ASSERT_WDEV_LOCK(wdev
);
3267 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3268 NL80211_CMD_NEW_SCAN_RESULTS
);
3272 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
);
3273 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
);
3275 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
3277 goto nla_put_failure
;
3278 if (!is_zero_ether_addr(res
->bssid
))
3279 NLA_PUT(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
);
3280 if (res
->information_elements
&& res
->len_information_elements
)
3281 NLA_PUT(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
3282 res
->len_information_elements
,
3283 res
->information_elements
);
3284 if (res
->beacon_ies
&& res
->len_beacon_ies
&&
3285 res
->beacon_ies
!= res
->information_elements
)
3286 NLA_PUT(msg
, NL80211_BSS_BEACON_IES
,
3287 res
->len_beacon_ies
, res
->beacon_ies
);
3289 NLA_PUT_U64(msg
, NL80211_BSS_TSF
, res
->tsf
);
3290 if (res
->beacon_interval
)
3291 NLA_PUT_U16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
);
3292 NLA_PUT_U16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
);
3293 NLA_PUT_U32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
);
3294 NLA_PUT_U32(msg
, NL80211_BSS_SEEN_MS_AGO
,
3295 jiffies_to_msecs(jiffies
- intbss
->ts
));
3297 switch (rdev
->wiphy
.signal_type
) {
3298 case CFG80211_SIGNAL_TYPE_MBM
:
3299 NLA_PUT_U32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
);
3301 case CFG80211_SIGNAL_TYPE_UNSPEC
:
3302 NLA_PUT_U8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
);
3308 switch (wdev
->iftype
) {
3309 case NL80211_IFTYPE_STATION
:
3310 if (intbss
== wdev
->current_bss
)
3311 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3312 NL80211_BSS_STATUS_ASSOCIATED
);
3313 else for (i
= 0; i
< MAX_AUTH_BSSES
; i
++) {
3314 if (intbss
!= wdev
->auth_bsses
[i
])
3316 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3317 NL80211_BSS_STATUS_AUTHENTICATED
);
3321 case NL80211_IFTYPE_ADHOC
:
3322 if (intbss
== wdev
->current_bss
)
3323 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3324 NL80211_BSS_STATUS_IBSS_JOINED
);
3330 nla_nest_end(msg
, bss
);
3332 return genlmsg_end(msg
, hdr
);
3335 genlmsg_cancel(msg
, hdr
);
3339 static int nl80211_dump_scan(struct sk_buff
*skb
,
3340 struct netlink_callback
*cb
)
3342 struct cfg80211_registered_device
*rdev
;
3343 struct net_device
*dev
;
3344 struct cfg80211_internal_bss
*scan
;
3345 struct wireless_dev
*wdev
;
3346 int ifidx
= cb
->args
[0];
3347 int start
= cb
->args
[1], idx
= 0;
3351 ifidx
= nl80211_get_ifidx(cb
);
3354 cb
->args
[0] = ifidx
;
3356 dev
= dev_get_by_index(sock_net(skb
->sk
), ifidx
);
3360 rdev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
3362 err
= PTR_ERR(rdev
);
3363 goto out_put_netdev
;
3366 wdev
= dev
->ieee80211_ptr
;
3369 spin_lock_bh(&rdev
->bss_lock
);
3370 cfg80211_bss_expire(rdev
);
3372 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
3375 if (nl80211_send_bss(skb
,
3376 NETLINK_CB(cb
->skb
).pid
,
3377 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3378 rdev
, wdev
, scan
) < 0) {
3385 spin_unlock_bh(&rdev
->bss_lock
);
3390 cfg80211_unlock_rdev(rdev
);
3397 static int nl80211_send_survey(struct sk_buff
*msg
, u32 pid
, u32 seq
,
3398 int flags
, struct net_device
*dev
,
3399 struct survey_info
*survey
)
3402 struct nlattr
*infoattr
;
3404 /* Survey without a channel doesn't make sense */
3405 if (!survey
->channel
)
3408 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3409 NL80211_CMD_NEW_SURVEY_RESULTS
);
3413 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
3415 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
3417 goto nla_put_failure
;
3419 NLA_PUT_U32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
3420 survey
->channel
->center_freq
);
3421 if (survey
->filled
& SURVEY_INFO_NOISE_DBM
)
3422 NLA_PUT_U8(msg
, NL80211_SURVEY_INFO_NOISE
,
3425 nla_nest_end(msg
, infoattr
);
3427 return genlmsg_end(msg
, hdr
);
3430 genlmsg_cancel(msg
, hdr
);
3434 static int nl80211_dump_survey(struct sk_buff
*skb
,
3435 struct netlink_callback
*cb
)
3437 struct survey_info survey
;
3438 struct cfg80211_registered_device
*dev
;
3439 struct net_device
*netdev
;
3440 int ifidx
= cb
->args
[0];
3441 int survey_idx
= cb
->args
[1];
3445 ifidx
= nl80211_get_ifidx(cb
);
3448 cb
->args
[0] = ifidx
;
3452 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
3458 dev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
3464 if (!dev
->ops
->dump_survey
) {
3470 res
= dev
->ops
->dump_survey(&dev
->wiphy
, netdev
, survey_idx
,
3477 if (nl80211_send_survey(skb
,
3478 NETLINK_CB(cb
->skb
).pid
,
3479 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3487 cb
->args
[1] = survey_idx
;
3490 cfg80211_unlock_rdev(dev
);
3497 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
)
3499 return auth_type
<= NL80211_AUTHTYPE_MAX
;
3502 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
3504 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
3505 NL80211_WPA_VERSION_2
));
3508 static bool nl80211_valid_akm_suite(u32 akm
)
3510 return akm
== WLAN_AKM_SUITE_8021X
||
3511 akm
== WLAN_AKM_SUITE_PSK
;
3514 static bool nl80211_valid_cipher_suite(u32 cipher
)
3516 return cipher
== WLAN_CIPHER_SUITE_WEP40
||
3517 cipher
== WLAN_CIPHER_SUITE_WEP104
||
3518 cipher
== WLAN_CIPHER_SUITE_TKIP
||
3519 cipher
== WLAN_CIPHER_SUITE_CCMP
||
3520 cipher
== WLAN_CIPHER_SUITE_AES_CMAC
;
3524 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3526 struct cfg80211_registered_device
*rdev
;
3527 struct net_device
*dev
;
3528 struct ieee80211_channel
*chan
;
3529 const u8
*bssid
, *ssid
, *ie
= NULL
;
3530 int err
, ssid_len
, ie_len
= 0;
3531 enum nl80211_auth_type auth_type
;
3532 struct key_parse key
;
3533 bool local_state_change
;
3535 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3538 if (!info
->attrs
[NL80211_ATTR_MAC
])
3541 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
3544 if (!info
->attrs
[NL80211_ATTR_SSID
])
3547 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
3550 err
= nl80211_parse_key(info
, &key
);
3555 if (!key
.p
.key
|| !key
.p
.key_len
)
3557 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
3558 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
3559 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
3560 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
3571 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3575 if (!rdev
->ops
->auth
) {
3580 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3585 if (!netif_running(dev
)) {
3590 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3591 chan
= ieee80211_get_channel(&rdev
->wiphy
,
3592 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3593 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
)) {
3598 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3599 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3601 if (info
->attrs
[NL80211_ATTR_IE
]) {
3602 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3603 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3606 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3607 if (!nl80211_valid_auth_type(auth_type
)) {
3612 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
3614 err
= cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
3615 ssid
, ssid_len
, ie
, ie_len
,
3616 key
.p
.key
, key
.p
.key_len
, key
.idx
,
3617 local_state_change
);
3620 cfg80211_unlock_rdev(rdev
);
3627 static int nl80211_crypto_settings(struct genl_info
*info
,
3628 struct cfg80211_crypto_settings
*settings
,
3631 memset(settings
, 0, sizeof(*settings
));
3633 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
3635 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
3639 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
3640 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
3641 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
3643 if (len
% sizeof(u32
))
3646 if (settings
->n_ciphers_pairwise
> cipher_limit
)
3649 memcpy(settings
->ciphers_pairwise
, data
, len
);
3651 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
3652 if (!nl80211_valid_cipher_suite(
3653 settings
->ciphers_pairwise
[i
]))
3657 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
3658 settings
->cipher_group
=
3659 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
3660 if (!nl80211_valid_cipher_suite(settings
->cipher_group
))
3664 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
3665 settings
->wpa_versions
=
3666 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
3667 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
3671 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
3675 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
3676 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
3677 settings
->n_akm_suites
= len
/ sizeof(u32
);
3679 if (len
% sizeof(u32
))
3682 memcpy(settings
->akm_suites
, data
, len
);
3684 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
3685 if (!nl80211_valid_akm_suite(settings
->akm_suites
[i
]))
3692 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
3694 struct cfg80211_registered_device
*rdev
;
3695 struct net_device
*dev
;
3696 struct cfg80211_crypto_settings crypto
;
3697 struct ieee80211_channel
*chan
;
3698 const u8
*bssid
, *ssid
, *ie
= NULL
, *prev_bssid
= NULL
;
3699 int err
, ssid_len
, ie_len
= 0;
3700 bool use_mfp
= false;
3702 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3705 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
3706 !info
->attrs
[NL80211_ATTR_SSID
] ||
3707 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
3712 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3716 if (!rdev
->ops
->assoc
) {
3721 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3726 if (!netif_running(dev
)) {
3731 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3733 chan
= ieee80211_get_channel(&rdev
->wiphy
,
3734 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3735 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
)) {
3740 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3741 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3743 if (info
->attrs
[NL80211_ATTR_IE
]) {
3744 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3745 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3748 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
3749 enum nl80211_mfp mfp
=
3750 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
3751 if (mfp
== NL80211_MFP_REQUIRED
)
3753 else if (mfp
!= NL80211_MFP_NO
) {
3759 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
3760 prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
3762 err
= nl80211_crypto_settings(info
, &crypto
, 1);
3764 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
, prev_bssid
,
3765 ssid
, ssid_len
, ie
, ie_len
, use_mfp
,
3769 cfg80211_unlock_rdev(rdev
);
3776 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3778 struct cfg80211_registered_device
*rdev
;
3779 struct net_device
*dev
;
3780 const u8
*ie
= NULL
, *bssid
;
3781 int err
, ie_len
= 0;
3783 bool local_state_change
;
3785 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3788 if (!info
->attrs
[NL80211_ATTR_MAC
])
3791 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3796 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3800 if (!rdev
->ops
->deauth
) {
3805 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3810 if (!netif_running(dev
)) {
3815 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3817 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3818 if (reason_code
== 0) {
3819 /* Reason Code 0 is reserved */
3824 if (info
->attrs
[NL80211_ATTR_IE
]) {
3825 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3826 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3829 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
3831 err
= cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
3832 local_state_change
);
3835 cfg80211_unlock_rdev(rdev
);
3842 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
3844 struct cfg80211_registered_device
*rdev
;
3845 struct net_device
*dev
;
3846 const u8
*ie
= NULL
, *bssid
;
3847 int err
, ie_len
= 0;
3849 bool local_state_change
;
3851 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3854 if (!info
->attrs
[NL80211_ATTR_MAC
])
3857 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3862 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3866 if (!rdev
->ops
->disassoc
) {
3871 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3876 if (!netif_running(dev
)) {
3881 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3883 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3884 if (reason_code
== 0) {
3885 /* Reason Code 0 is reserved */
3890 if (info
->attrs
[NL80211_ATTR_IE
]) {
3891 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3892 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3895 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
3897 err
= cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
3898 local_state_change
);
3901 cfg80211_unlock_rdev(rdev
);
3908 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
3910 struct cfg80211_registered_device
*rdev
;
3911 struct net_device
*dev
;
3912 struct cfg80211_ibss_params ibss
;
3913 struct wiphy
*wiphy
;
3914 struct cfg80211_cached_keys
*connkeys
= NULL
;
3917 memset(&ibss
, 0, sizeof(ibss
));
3919 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3922 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
3923 !info
->attrs
[NL80211_ATTR_SSID
] ||
3924 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
3927 ibss
.beacon_interval
= 100;
3929 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
3930 ibss
.beacon_interval
=
3931 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3932 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
3938 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3942 if (!rdev
->ops
->join_ibss
) {
3947 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
3952 if (!netif_running(dev
)) {
3957 wiphy
= &rdev
->wiphy
;
3959 if (info
->attrs
[NL80211_ATTR_MAC
])
3960 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3961 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3962 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3964 if (info
->attrs
[NL80211_ATTR_IE
]) {
3965 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3966 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3969 ibss
.channel
= ieee80211_get_channel(wiphy
,
3970 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3971 if (!ibss
.channel
||
3972 ibss
.channel
->flags
& IEEE80211_CHAN_NO_IBSS
||
3973 ibss
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
3978 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
3979 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3981 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
3982 connkeys
= nl80211_parse_connkeys(rdev
,
3983 info
->attrs
[NL80211_ATTR_KEYS
]);
3984 if (IS_ERR(connkeys
)) {
3985 err
= PTR_ERR(connkeys
);
3991 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
3993 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
3995 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
3996 struct ieee80211_supported_band
*sband
=
3997 wiphy
->bands
[ibss
.channel
->band
];
4005 for (i
= 0; i
< n_rates
; i
++) {
4006 int rate
= (rates
[i
] & 0x7f) * 5;
4009 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
4010 if (sband
->bitrates
[j
].bitrate
== rate
) {
4012 ibss
.basic_rates
|= BIT(j
);
4023 * If no rates were explicitly configured,
4024 * use the mandatory rate set for 11b or
4025 * 11a for maximum compatibility.
4027 struct ieee80211_supported_band
*sband
=
4028 wiphy
->bands
[ibss
.channel
->band
];
4030 u32 flag
= ibss
.channel
->band
== IEEE80211_BAND_5GHZ
?
4031 IEEE80211_RATE_MANDATORY_A
:
4032 IEEE80211_RATE_MANDATORY_B
;
4034 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
4035 if (sband
->bitrates
[j
].flags
& flag
)
4036 ibss
.basic_rates
|= BIT(j
);
4040 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
4043 cfg80211_unlock_rdev(rdev
);
4052 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
4054 struct cfg80211_registered_device
*rdev
;
4055 struct net_device
*dev
;
4060 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4064 if (!rdev
->ops
->leave_ibss
) {
4069 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
4074 if (!netif_running(dev
)) {
4079 err
= cfg80211_leave_ibss(rdev
, dev
, false);
4082 cfg80211_unlock_rdev(rdev
);
4089 #ifdef CONFIG_NL80211_TESTMODE
4090 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
4094 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
4096 struct cfg80211_registered_device
*rdev
;
4099 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
4104 rdev
= cfg80211_get_dev_from_info(info
);
4106 err
= PTR_ERR(rdev
);
4111 if (rdev
->ops
->testmode_cmd
) {
4112 rdev
->testmode_info
= info
;
4113 err
= rdev
->ops
->testmode_cmd(&rdev
->wiphy
,
4114 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
4115 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
4116 rdev
->testmode_info
= NULL
;
4119 cfg80211_unlock_rdev(rdev
);
4126 static struct sk_buff
*
4127 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
4128 int approxlen
, u32 pid
, u32 seq
, gfp_t gfp
)
4130 struct sk_buff
*skb
;
4132 struct nlattr
*data
;
4134 skb
= nlmsg_new(approxlen
+ 100, gfp
);
4138 hdr
= nl80211hdr_put(skb
, pid
, seq
, 0, NL80211_CMD_TESTMODE
);
4144 NLA_PUT_U32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4145 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
4147 ((void **)skb
->cb
)[0] = rdev
;
4148 ((void **)skb
->cb
)[1] = hdr
;
4149 ((void **)skb
->cb
)[2] = data
;
4158 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
4161 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4163 if (WARN_ON(!rdev
->testmode_info
))
4166 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
4167 rdev
->testmode_info
->snd_pid
,
4168 rdev
->testmode_info
->snd_seq
,
4171 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
4173 int cfg80211_testmode_reply(struct sk_buff
*skb
)
4175 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
4176 void *hdr
= ((void **)skb
->cb
)[1];
4177 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4179 if (WARN_ON(!rdev
->testmode_info
)) {
4184 nla_nest_end(skb
, data
);
4185 genlmsg_end(skb
, hdr
);
4186 return genlmsg_reply(skb
, rdev
->testmode_info
);
4188 EXPORT_SYMBOL(cfg80211_testmode_reply
);
4190 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
4191 int approxlen
, gfp_t gfp
)
4193 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4195 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
4197 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
4199 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
4201 void *hdr
= ((void **)skb
->cb
)[1];
4202 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4204 nla_nest_end(skb
, data
);
4205 genlmsg_end(skb
, hdr
);
4206 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
4208 EXPORT_SYMBOL(cfg80211_testmode_event
);
4211 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
4213 struct cfg80211_registered_device
*rdev
;
4214 struct net_device
*dev
;
4215 struct cfg80211_connect_params connect
;
4216 struct wiphy
*wiphy
;
4217 struct cfg80211_cached_keys
*connkeys
= NULL
;
4220 memset(&connect
, 0, sizeof(connect
));
4222 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4225 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
4226 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
4229 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
4231 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4232 if (!nl80211_valid_auth_type(connect
.auth_type
))
4235 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
4237 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
4239 err
= nl80211_crypto_settings(info
, &connect
.crypto
,
4240 NL80211_MAX_NR_CIPHER_SUITES
);
4245 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4249 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4254 if (!netif_running(dev
)) {
4259 wiphy
= &rdev
->wiphy
;
4261 if (info
->attrs
[NL80211_ATTR_MAC
])
4262 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4263 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4264 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4266 if (info
->attrs
[NL80211_ATTR_IE
]) {
4267 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4268 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4271 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
4273 ieee80211_get_channel(wiphy
,
4274 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4275 if (!connect
.channel
||
4276 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
4282 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
4283 connkeys
= nl80211_parse_connkeys(rdev
,
4284 info
->attrs
[NL80211_ATTR_KEYS
]);
4285 if (IS_ERR(connkeys
)) {
4286 err
= PTR_ERR(connkeys
);
4292 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
4295 cfg80211_unlock_rdev(rdev
);
4304 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
4306 struct cfg80211_registered_device
*rdev
;
4307 struct net_device
*dev
;
4311 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4312 reason
= WLAN_REASON_DEAUTH_LEAVING
;
4314 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4321 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4325 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4330 if (!netif_running(dev
)) {
4335 err
= cfg80211_disconnect(rdev
, dev
, reason
, true);
4338 cfg80211_unlock_rdev(rdev
);
4345 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
4347 struct cfg80211_registered_device
*rdev
;
4352 if (!info
->attrs
[NL80211_ATTR_PID
])
4355 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
4359 rdev
= cfg80211_get_dev_from_info(info
);
4361 err
= PTR_ERR(rdev
);
4365 net
= get_net_ns_by_pid(pid
);
4373 /* check if anything to do */
4374 if (net_eq(wiphy_net(&rdev
->wiphy
), net
))
4377 err
= cfg80211_switch_netns(rdev
, net
);
4381 cfg80211_unlock_rdev(rdev
);
4387 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4389 struct cfg80211_registered_device
*rdev
;
4390 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
4391 struct cfg80211_pmksa
*pmksa
) = NULL
;
4393 struct net_device
*dev
;
4394 struct cfg80211_pmksa pmksa
;
4396 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
4398 if (!info
->attrs
[NL80211_ATTR_MAC
])
4401 if (!info
->attrs
[NL80211_ATTR_PMKID
])
4406 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4410 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
4411 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4413 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4418 switch (info
->genlhdr
->cmd
) {
4419 case NL80211_CMD_SET_PMKSA
:
4420 rdev_ops
= rdev
->ops
->set_pmksa
;
4422 case NL80211_CMD_DEL_PMKSA
:
4423 rdev_ops
= rdev
->ops
->del_pmksa
;
4435 err
= rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
4438 cfg80211_unlock_rdev(rdev
);
4446 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4448 struct cfg80211_registered_device
*rdev
;
4450 struct net_device
*dev
;
4454 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4458 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4463 if (!rdev
->ops
->flush_pmksa
) {
4468 err
= rdev
->ops
->flush_pmksa(&rdev
->wiphy
, dev
);
4471 cfg80211_unlock_rdev(rdev
);
4480 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
4481 struct genl_info
*info
)
4483 struct cfg80211_registered_device
*rdev
;
4484 struct net_device
*dev
;
4485 struct ieee80211_channel
*chan
;
4486 struct sk_buff
*msg
;
4489 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
4493 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
4494 !info
->attrs
[NL80211_ATTR_DURATION
])
4497 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
4500 * We should be on that channel for at least one jiffie,
4501 * and more than 5 seconds seems excessive.
4503 if (!duration
|| !msecs_to_jiffies(duration
) || duration
> 5000)
4508 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4512 if (!rdev
->ops
->remain_on_channel
) {
4517 if (!netif_running(dev
)) {
4522 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
4523 channel_type
= nla_get_u32(
4524 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
4525 if (channel_type
!= NL80211_CHAN_NO_HT
&&
4526 channel_type
!= NL80211_CHAN_HT20
&&
4527 channel_type
!= NL80211_CHAN_HT40PLUS
&&
4528 channel_type
!= NL80211_CHAN_HT40MINUS
) {
4534 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
4535 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
4541 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4547 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4548 NL80211_CMD_REMAIN_ON_CHANNEL
);
4555 err
= rdev
->ops
->remain_on_channel(&rdev
->wiphy
, dev
, chan
,
4556 channel_type
, duration
, &cookie
);
4561 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
4563 genlmsg_end(msg
, hdr
);
4564 err
= genlmsg_reply(msg
, info
);
4572 cfg80211_unlock_rdev(rdev
);
4579 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
4580 struct genl_info
*info
)
4582 struct cfg80211_registered_device
*rdev
;
4583 struct net_device
*dev
;
4587 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
4592 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4596 if (!rdev
->ops
->cancel_remain_on_channel
) {
4601 if (!netif_running(dev
)) {
4606 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
4608 err
= rdev
->ops
->cancel_remain_on_channel(&rdev
->wiphy
, dev
, cookie
);
4611 cfg80211_unlock_rdev(rdev
);
4618 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
4619 u8
*rates
, u8 rates_len
)
4624 for (i
= 0; i
< rates_len
; i
++) {
4625 int rate
= (rates
[i
] & 0x7f) * 5;
4627 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
4628 struct ieee80211_rate
*srate
=
4629 &sband
->bitrates
[ridx
];
4630 if (rate
== srate
->bitrate
) {
4635 if (ridx
== sband
->n_bitrates
)
4636 return 0; /* rate not found */
4642 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
4643 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
4644 .len
= NL80211_MAX_SUPP_RATES
},
4647 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
4648 struct genl_info
*info
)
4650 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
4651 struct cfg80211_registered_device
*rdev
;
4652 struct cfg80211_bitrate_mask mask
;
4654 struct net_device
*dev
;
4655 struct nlattr
*tx_rates
;
4656 struct ieee80211_supported_band
*sband
;
4658 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
4663 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4667 if (!rdev
->ops
->set_bitrate_mask
) {
4672 memset(&mask
, 0, sizeof(mask
));
4673 /* Default to all rates enabled */
4674 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
4675 sband
= rdev
->wiphy
.bands
[i
];
4676 mask
.control
[i
].legacy
=
4677 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
4681 * The nested attribute uses enum nl80211_band as the index. This maps
4682 * directly to the enum ieee80211_band values used in cfg80211.
4684 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
4686 enum ieee80211_band band
= nla_type(tx_rates
);
4687 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
4691 sband
= rdev
->wiphy
.bands
[band
];
4692 if (sband
== NULL
) {
4696 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
4697 nla_len(tx_rates
), nl80211_txattr_policy
);
4698 if (tb
[NL80211_TXRATE_LEGACY
]) {
4699 mask
.control
[band
].legacy
= rateset_to_mask(
4701 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
4702 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
4703 if (mask
.control
[band
].legacy
== 0) {
4710 err
= rdev
->ops
->set_bitrate_mask(&rdev
->wiphy
, dev
, NULL
, &mask
);
4714 cfg80211_unlock_rdev(rdev
);
4720 static int nl80211_register_action(struct sk_buff
*skb
, struct genl_info
*info
)
4722 struct cfg80211_registered_device
*rdev
;
4723 struct net_device
*dev
;
4726 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
4729 if (nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]) < 1)
4734 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4738 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4739 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
4744 /* not much point in registering if we can't reply */
4745 if (!rdev
->ops
->action
) {
4750 err
= cfg80211_mlme_register_action(dev
->ieee80211_ptr
, info
->snd_pid
,
4751 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
4752 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
4754 cfg80211_unlock_rdev(rdev
);
4761 static int nl80211_action(struct sk_buff
*skb
, struct genl_info
*info
)
4763 struct cfg80211_registered_device
*rdev
;
4764 struct net_device
*dev
;
4765 struct ieee80211_channel
*chan
;
4766 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
4767 bool channel_type_valid
= false;
4772 struct sk_buff
*msg
;
4774 if (!info
->attrs
[NL80211_ATTR_FRAME
] ||
4775 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4780 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4784 if (!rdev
->ops
->action
) {
4789 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4790 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
4795 if (!netif_running(dev
)) {
4800 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
4801 channel_type
= nla_get_u32(
4802 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
4803 if (channel_type
!= NL80211_CHAN_NO_HT
&&
4804 channel_type
!= NL80211_CHAN_HT20
&&
4805 channel_type
!= NL80211_CHAN_HT40PLUS
&&
4806 channel_type
!= NL80211_CHAN_HT40MINUS
) {
4810 channel_type_valid
= true;
4813 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
4814 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
4820 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4826 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4827 NL80211_CMD_ACTION
);
4833 err
= cfg80211_mlme_action(rdev
, dev
, chan
, channel_type
,
4835 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
4836 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
4841 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
4843 genlmsg_end(msg
, hdr
);
4844 err
= genlmsg_reply(msg
, info
);
4852 cfg80211_unlock_rdev(rdev
);
4859 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
4861 struct cfg80211_registered_device
*rdev
;
4862 struct wireless_dev
*wdev
;
4863 struct net_device
*dev
;
4868 if (!info
->attrs
[NL80211_ATTR_PS_STATE
]) {
4873 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
4875 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
) {
4882 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4886 wdev
= dev
->ieee80211_ptr
;
4888 if (!rdev
->ops
->set_power_mgmt
) {
4893 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
4895 if (state
== wdev
->ps
)
4900 if (rdev
->ops
->set_power_mgmt(wdev
->wiphy
, dev
, wdev
->ps
,
4902 /* assume this means it's off */
4906 cfg80211_unlock_rdev(rdev
);
4914 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
4916 struct cfg80211_registered_device
*rdev
;
4917 enum nl80211_ps_state ps_state
;
4918 struct wireless_dev
*wdev
;
4919 struct net_device
*dev
;
4920 struct sk_buff
*msg
;
4926 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4930 wdev
= dev
->ieee80211_ptr
;
4932 if (!rdev
->ops
->set_power_mgmt
) {
4937 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4943 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4944 NL80211_CMD_GET_POWER_SAVE
);
4951 ps_state
= NL80211_PS_ENABLED
;
4953 ps_state
= NL80211_PS_DISABLED
;
4955 NLA_PUT_U32(msg
, NL80211_ATTR_PS_STATE
, ps_state
);
4957 genlmsg_end(msg
, hdr
);
4958 err
= genlmsg_reply(msg
, info
);
4968 cfg80211_unlock_rdev(rdev
);
4977 static struct nla_policy
4978 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
4979 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
4980 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
4981 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
4984 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
4985 s32 threshold
, u32 hysteresis
)
4987 struct cfg80211_registered_device
*rdev
;
4988 struct wireless_dev
*wdev
;
4989 struct net_device
*dev
;
4997 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
5001 wdev
= dev
->ieee80211_ptr
;
5003 if (!rdev
->ops
->set_cqm_rssi_config
) {
5008 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
) {
5013 err
= rdev
->ops
->set_cqm_rssi_config(wdev
->wiphy
, dev
,
5014 threshold
, hysteresis
);
5017 cfg80211_unlock_rdev(rdev
);
5024 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
5026 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
5030 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
5036 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
5037 nl80211_attr_cqm_policy
);
5041 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
5042 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
5045 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
5046 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
5047 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
5055 static struct genl_ops nl80211_ops
[] = {
5057 .cmd
= NL80211_CMD_GET_WIPHY
,
5058 .doit
= nl80211_get_wiphy
,
5059 .dumpit
= nl80211_dump_wiphy
,
5060 .policy
= nl80211_policy
,
5061 /* can be retrieved by unprivileged users */
5064 .cmd
= NL80211_CMD_SET_WIPHY
,
5065 .doit
= nl80211_set_wiphy
,
5066 .policy
= nl80211_policy
,
5067 .flags
= GENL_ADMIN_PERM
,
5070 .cmd
= NL80211_CMD_GET_INTERFACE
,
5071 .doit
= nl80211_get_interface
,
5072 .dumpit
= nl80211_dump_interface
,
5073 .policy
= nl80211_policy
,
5074 /* can be retrieved by unprivileged users */
5077 .cmd
= NL80211_CMD_SET_INTERFACE
,
5078 .doit
= nl80211_set_interface
,
5079 .policy
= nl80211_policy
,
5080 .flags
= GENL_ADMIN_PERM
,
5083 .cmd
= NL80211_CMD_NEW_INTERFACE
,
5084 .doit
= nl80211_new_interface
,
5085 .policy
= nl80211_policy
,
5086 .flags
= GENL_ADMIN_PERM
,
5089 .cmd
= NL80211_CMD_DEL_INTERFACE
,
5090 .doit
= nl80211_del_interface
,
5091 .policy
= nl80211_policy
,
5092 .flags
= GENL_ADMIN_PERM
,
5095 .cmd
= NL80211_CMD_GET_KEY
,
5096 .doit
= nl80211_get_key
,
5097 .policy
= nl80211_policy
,
5098 .flags
= GENL_ADMIN_PERM
,
5101 .cmd
= NL80211_CMD_SET_KEY
,
5102 .doit
= nl80211_set_key
,
5103 .policy
= nl80211_policy
,
5104 .flags
= GENL_ADMIN_PERM
,
5107 .cmd
= NL80211_CMD_NEW_KEY
,
5108 .doit
= nl80211_new_key
,
5109 .policy
= nl80211_policy
,
5110 .flags
= GENL_ADMIN_PERM
,
5113 .cmd
= NL80211_CMD_DEL_KEY
,
5114 .doit
= nl80211_del_key
,
5115 .policy
= nl80211_policy
,
5116 .flags
= GENL_ADMIN_PERM
,
5119 .cmd
= NL80211_CMD_SET_BEACON
,
5120 .policy
= nl80211_policy
,
5121 .flags
= GENL_ADMIN_PERM
,
5122 .doit
= nl80211_addset_beacon
,
5125 .cmd
= NL80211_CMD_NEW_BEACON
,
5126 .policy
= nl80211_policy
,
5127 .flags
= GENL_ADMIN_PERM
,
5128 .doit
= nl80211_addset_beacon
,
5131 .cmd
= NL80211_CMD_DEL_BEACON
,
5132 .policy
= nl80211_policy
,
5133 .flags
= GENL_ADMIN_PERM
,
5134 .doit
= nl80211_del_beacon
,
5137 .cmd
= NL80211_CMD_GET_STATION
,
5138 .doit
= nl80211_get_station
,
5139 .dumpit
= nl80211_dump_station
,
5140 .policy
= nl80211_policy
,
5143 .cmd
= NL80211_CMD_SET_STATION
,
5144 .doit
= nl80211_set_station
,
5145 .policy
= nl80211_policy
,
5146 .flags
= GENL_ADMIN_PERM
,
5149 .cmd
= NL80211_CMD_NEW_STATION
,
5150 .doit
= nl80211_new_station
,
5151 .policy
= nl80211_policy
,
5152 .flags
= GENL_ADMIN_PERM
,
5155 .cmd
= NL80211_CMD_DEL_STATION
,
5156 .doit
= nl80211_del_station
,
5157 .policy
= nl80211_policy
,
5158 .flags
= GENL_ADMIN_PERM
,
5161 .cmd
= NL80211_CMD_GET_MPATH
,
5162 .doit
= nl80211_get_mpath
,
5163 .dumpit
= nl80211_dump_mpath
,
5164 .policy
= nl80211_policy
,
5165 .flags
= GENL_ADMIN_PERM
,
5168 .cmd
= NL80211_CMD_SET_MPATH
,
5169 .doit
= nl80211_set_mpath
,
5170 .policy
= nl80211_policy
,
5171 .flags
= GENL_ADMIN_PERM
,
5174 .cmd
= NL80211_CMD_NEW_MPATH
,
5175 .doit
= nl80211_new_mpath
,
5176 .policy
= nl80211_policy
,
5177 .flags
= GENL_ADMIN_PERM
,
5180 .cmd
= NL80211_CMD_DEL_MPATH
,
5181 .doit
= nl80211_del_mpath
,
5182 .policy
= nl80211_policy
,
5183 .flags
= GENL_ADMIN_PERM
,
5186 .cmd
= NL80211_CMD_SET_BSS
,
5187 .doit
= nl80211_set_bss
,
5188 .policy
= nl80211_policy
,
5189 .flags
= GENL_ADMIN_PERM
,
5192 .cmd
= NL80211_CMD_GET_REG
,
5193 .doit
= nl80211_get_reg
,
5194 .policy
= nl80211_policy
,
5195 /* can be retrieved by unprivileged users */
5198 .cmd
= NL80211_CMD_SET_REG
,
5199 .doit
= nl80211_set_reg
,
5200 .policy
= nl80211_policy
,
5201 .flags
= GENL_ADMIN_PERM
,
5204 .cmd
= NL80211_CMD_REQ_SET_REG
,
5205 .doit
= nl80211_req_set_reg
,
5206 .policy
= nl80211_policy
,
5207 .flags
= GENL_ADMIN_PERM
,
5210 .cmd
= NL80211_CMD_GET_MESH_PARAMS
,
5211 .doit
= nl80211_get_mesh_params
,
5212 .policy
= nl80211_policy
,
5213 /* can be retrieved by unprivileged users */
5216 .cmd
= NL80211_CMD_SET_MESH_PARAMS
,
5217 .doit
= nl80211_set_mesh_params
,
5218 .policy
= nl80211_policy
,
5219 .flags
= GENL_ADMIN_PERM
,
5222 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
5223 .doit
= nl80211_trigger_scan
,
5224 .policy
= nl80211_policy
,
5225 .flags
= GENL_ADMIN_PERM
,
5228 .cmd
= NL80211_CMD_GET_SCAN
,
5229 .policy
= nl80211_policy
,
5230 .dumpit
= nl80211_dump_scan
,
5233 .cmd
= NL80211_CMD_AUTHENTICATE
,
5234 .doit
= nl80211_authenticate
,
5235 .policy
= nl80211_policy
,
5236 .flags
= GENL_ADMIN_PERM
,
5239 .cmd
= NL80211_CMD_ASSOCIATE
,
5240 .doit
= nl80211_associate
,
5241 .policy
= nl80211_policy
,
5242 .flags
= GENL_ADMIN_PERM
,
5245 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
5246 .doit
= nl80211_deauthenticate
,
5247 .policy
= nl80211_policy
,
5248 .flags
= GENL_ADMIN_PERM
,
5251 .cmd
= NL80211_CMD_DISASSOCIATE
,
5252 .doit
= nl80211_disassociate
,
5253 .policy
= nl80211_policy
,
5254 .flags
= GENL_ADMIN_PERM
,
5257 .cmd
= NL80211_CMD_JOIN_IBSS
,
5258 .doit
= nl80211_join_ibss
,
5259 .policy
= nl80211_policy
,
5260 .flags
= GENL_ADMIN_PERM
,
5263 .cmd
= NL80211_CMD_LEAVE_IBSS
,
5264 .doit
= nl80211_leave_ibss
,
5265 .policy
= nl80211_policy
,
5266 .flags
= GENL_ADMIN_PERM
,
5268 #ifdef CONFIG_NL80211_TESTMODE
5270 .cmd
= NL80211_CMD_TESTMODE
,
5271 .doit
= nl80211_testmode_do
,
5272 .policy
= nl80211_policy
,
5273 .flags
= GENL_ADMIN_PERM
,
5277 .cmd
= NL80211_CMD_CONNECT
,
5278 .doit
= nl80211_connect
,
5279 .policy
= nl80211_policy
,
5280 .flags
= GENL_ADMIN_PERM
,
5283 .cmd
= NL80211_CMD_DISCONNECT
,
5284 .doit
= nl80211_disconnect
,
5285 .policy
= nl80211_policy
,
5286 .flags
= GENL_ADMIN_PERM
,
5289 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
5290 .doit
= nl80211_wiphy_netns
,
5291 .policy
= nl80211_policy
,
5292 .flags
= GENL_ADMIN_PERM
,
5295 .cmd
= NL80211_CMD_GET_SURVEY
,
5296 .policy
= nl80211_policy
,
5297 .dumpit
= nl80211_dump_survey
,
5300 .cmd
= NL80211_CMD_SET_PMKSA
,
5301 .doit
= nl80211_setdel_pmksa
,
5302 .policy
= nl80211_policy
,
5303 .flags
= GENL_ADMIN_PERM
,
5306 .cmd
= NL80211_CMD_DEL_PMKSA
,
5307 .doit
= nl80211_setdel_pmksa
,
5308 .policy
= nl80211_policy
,
5309 .flags
= GENL_ADMIN_PERM
,
5312 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
5313 .doit
= nl80211_flush_pmksa
,
5314 .policy
= nl80211_policy
,
5315 .flags
= GENL_ADMIN_PERM
,
5318 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
5319 .doit
= nl80211_remain_on_channel
,
5320 .policy
= nl80211_policy
,
5321 .flags
= GENL_ADMIN_PERM
,
5324 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
5325 .doit
= nl80211_cancel_remain_on_channel
,
5326 .policy
= nl80211_policy
,
5327 .flags
= GENL_ADMIN_PERM
,
5330 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
5331 .doit
= nl80211_set_tx_bitrate_mask
,
5332 .policy
= nl80211_policy
,
5333 .flags
= GENL_ADMIN_PERM
,
5336 .cmd
= NL80211_CMD_REGISTER_ACTION
,
5337 .doit
= nl80211_register_action
,
5338 .policy
= nl80211_policy
,
5339 .flags
= GENL_ADMIN_PERM
,
5342 .cmd
= NL80211_CMD_ACTION
,
5343 .doit
= nl80211_action
,
5344 .policy
= nl80211_policy
,
5345 .flags
= GENL_ADMIN_PERM
,
5348 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
5349 .doit
= nl80211_set_power_save
,
5350 .policy
= nl80211_policy
,
5351 .flags
= GENL_ADMIN_PERM
,
5354 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
5355 .doit
= nl80211_get_power_save
,
5356 .policy
= nl80211_policy
,
5357 /* can be retrieved by unprivileged users */
5360 .cmd
= NL80211_CMD_SET_CQM
,
5361 .doit
= nl80211_set_cqm
,
5362 .policy
= nl80211_policy
,
5363 .flags
= GENL_ADMIN_PERM
,
5366 .cmd
= NL80211_CMD_SET_CHANNEL
,
5367 .doit
= nl80211_set_channel
,
5368 .policy
= nl80211_policy
,
5369 .flags
= GENL_ADMIN_PERM
,
5373 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
5377 /* multicast groups */
5378 static struct genl_multicast_group nl80211_config_mcgrp
= {
5381 static struct genl_multicast_group nl80211_scan_mcgrp
= {
5384 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
5385 .name
= "regulatory",
5388 /* notification functions */
5390 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
5392 struct sk_buff
*msg
;
5394 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5398 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
5403 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5404 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
5407 static int nl80211_add_scan_req(struct sk_buff
*msg
,
5408 struct cfg80211_registered_device
*rdev
)
5410 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
5411 struct nlattr
*nest
;
5414 ASSERT_RDEV_LOCK(rdev
);
5419 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
5421 goto nla_put_failure
;
5422 for (i
= 0; i
< req
->n_ssids
; i
++)
5423 NLA_PUT(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
);
5424 nla_nest_end(msg
, nest
);
5426 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
5428 goto nla_put_failure
;
5429 for (i
= 0; i
< req
->n_channels
; i
++)
5430 NLA_PUT_U32(msg
, i
, req
->channels
[i
]->center_freq
);
5431 nla_nest_end(msg
, nest
);
5434 NLA_PUT(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
);
5441 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
5442 struct cfg80211_registered_device
*rdev
,
5443 struct net_device
*netdev
,
5444 u32 pid
, u32 seq
, int flags
,
5449 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
5453 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5454 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5456 /* ignore errors and send incomplete event anyway */
5457 nl80211_add_scan_req(msg
, rdev
);
5459 return genlmsg_end(msg
, hdr
);
5462 genlmsg_cancel(msg
, hdr
);
5466 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
5467 struct net_device
*netdev
)
5469 struct sk_buff
*msg
;
5471 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
5475 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5476 NL80211_CMD_TRIGGER_SCAN
) < 0) {
5481 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5482 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5485 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
5486 struct net_device
*netdev
)
5488 struct sk_buff
*msg
;
5490 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5494 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5495 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
5500 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5501 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5504 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
5505 struct net_device
*netdev
)
5507 struct sk_buff
*msg
;
5509 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5513 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5514 NL80211_CMD_SCAN_ABORTED
) < 0) {
5519 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5520 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5524 * This can happen on global regulatory changes or device specific settings
5525 * based on custom world regulatory domains.
5527 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
5529 struct sk_buff
*msg
;
5532 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5536 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
5542 /* Userspace can always count this one always being set */
5543 NLA_PUT_U8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
);
5545 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0')
5546 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5547 NL80211_REGDOM_TYPE_WORLD
);
5548 else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9')
5549 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5550 NL80211_REGDOM_TYPE_CUSTOM_WORLD
);
5551 else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
5553 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5554 NL80211_REGDOM_TYPE_INTERSECTION
);
5556 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5557 NL80211_REGDOM_TYPE_COUNTRY
);
5558 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, request
->alpha2
);
5561 if (wiphy_idx_valid(request
->wiphy_idx
))
5562 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
);
5564 if (genlmsg_end(msg
, hdr
) < 0) {
5570 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
5577 genlmsg_cancel(msg
, hdr
);
5581 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
5582 struct net_device
*netdev
,
5583 const u8
*buf
, size_t len
,
5584 enum nl80211_commands cmd
, gfp_t gfp
)
5586 struct sk_buff
*msg
;
5589 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5593 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
5599 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5600 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5601 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
5603 if (genlmsg_end(msg
, hdr
) < 0) {
5608 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5609 nl80211_mlme_mcgrp
.id
, gfp
);
5613 genlmsg_cancel(msg
, hdr
);
5617 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
5618 struct net_device
*netdev
, const u8
*buf
,
5619 size_t len
, gfp_t gfp
)
5621 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5622 NL80211_CMD_AUTHENTICATE
, gfp
);
5625 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
5626 struct net_device
*netdev
, const u8
*buf
,
5627 size_t len
, gfp_t gfp
)
5629 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5630 NL80211_CMD_ASSOCIATE
, gfp
);
5633 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
5634 struct net_device
*netdev
, const u8
*buf
,
5635 size_t len
, gfp_t gfp
)
5637 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5638 NL80211_CMD_DEAUTHENTICATE
, gfp
);
5641 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
5642 struct net_device
*netdev
, const u8
*buf
,
5643 size_t len
, gfp_t gfp
)
5645 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5646 NL80211_CMD_DISASSOCIATE
, gfp
);
5649 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
5650 struct net_device
*netdev
, int cmd
,
5651 const u8
*addr
, gfp_t gfp
)
5653 struct sk_buff
*msg
;
5656 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5660 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
5666 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5667 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5668 NLA_PUT_FLAG(msg
, NL80211_ATTR_TIMED_OUT
);
5669 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5671 if (genlmsg_end(msg
, hdr
) < 0) {
5676 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5677 nl80211_mlme_mcgrp
.id
, gfp
);
5681 genlmsg_cancel(msg
, hdr
);
5685 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
5686 struct net_device
*netdev
, const u8
*addr
,
5689 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
5693 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
5694 struct net_device
*netdev
, const u8
*addr
,
5697 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
5701 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
5702 struct net_device
*netdev
, const u8
*bssid
,
5703 const u8
*req_ie
, size_t req_ie_len
,
5704 const u8
*resp_ie
, size_t resp_ie_len
,
5705 u16 status
, gfp_t gfp
)
5707 struct sk_buff
*msg
;
5710 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
5714 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
5720 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5721 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5723 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
5724 NLA_PUT_U16(msg
, NL80211_ATTR_STATUS_CODE
, status
);
5726 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
5728 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
5730 if (genlmsg_end(msg
, hdr
) < 0) {
5735 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5736 nl80211_mlme_mcgrp
.id
, gfp
);
5740 genlmsg_cancel(msg
, hdr
);
5745 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
5746 struct net_device
*netdev
, const u8
*bssid
,
5747 const u8
*req_ie
, size_t req_ie_len
,
5748 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
5750 struct sk_buff
*msg
;
5753 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
5757 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
5763 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5764 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5765 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
5767 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
5769 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
5771 if (genlmsg_end(msg
, hdr
) < 0) {
5776 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5777 nl80211_mlme_mcgrp
.id
, gfp
);
5781 genlmsg_cancel(msg
, hdr
);
5786 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
5787 struct net_device
*netdev
, u16 reason
,
5788 const u8
*ie
, size_t ie_len
, bool from_ap
)
5790 struct sk_buff
*msg
;
5793 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
5797 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
5803 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5804 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5805 if (from_ap
&& reason
)
5806 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason
);
5808 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
);
5810 NLA_PUT(msg
, NL80211_ATTR_IE
, ie_len
, ie
);
5812 if (genlmsg_end(msg
, hdr
) < 0) {
5817 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5818 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
5822 genlmsg_cancel(msg
, hdr
);
5827 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
5828 struct net_device
*netdev
, const u8
*bssid
,
5831 struct sk_buff
*msg
;
5834 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5838 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
5844 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5845 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5846 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
5848 if (genlmsg_end(msg
, hdr
) < 0) {
5853 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5854 nl80211_mlme_mcgrp
.id
, gfp
);
5858 genlmsg_cancel(msg
, hdr
);
5862 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
5863 struct net_device
*netdev
, const u8
*addr
,
5864 enum nl80211_key_type key_type
, int key_id
,
5865 const u8
*tsc
, gfp_t gfp
)
5867 struct sk_buff
*msg
;
5870 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5874 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
5880 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5881 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5883 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5884 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
);
5885 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_id
);
5887 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
);
5889 if (genlmsg_end(msg
, hdr
) < 0) {
5894 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5895 nl80211_mlme_mcgrp
.id
, gfp
);
5899 genlmsg_cancel(msg
, hdr
);
5903 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
5904 struct ieee80211_channel
*channel_before
,
5905 struct ieee80211_channel
*channel_after
)
5907 struct sk_buff
*msg
;
5909 struct nlattr
*nl_freq
;
5911 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
5915 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
5922 * Since we are applying the beacon hint to a wiphy we know its
5923 * wiphy_idx is valid
5925 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
));
5928 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
5930 goto nla_put_failure
;
5931 if (nl80211_msg_put_channel(msg
, channel_before
))
5932 goto nla_put_failure
;
5933 nla_nest_end(msg
, nl_freq
);
5936 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
5938 goto nla_put_failure
;
5939 if (nl80211_msg_put_channel(msg
, channel_after
))
5940 goto nla_put_failure
;
5941 nla_nest_end(msg
, nl_freq
);
5943 if (genlmsg_end(msg
, hdr
) < 0) {
5949 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
5956 genlmsg_cancel(msg
, hdr
);
5960 static void nl80211_send_remain_on_chan_event(
5961 int cmd
, struct cfg80211_registered_device
*rdev
,
5962 struct net_device
*netdev
, u64 cookie
,
5963 struct ieee80211_channel
*chan
,
5964 enum nl80211_channel_type channel_type
,
5965 unsigned int duration
, gfp_t gfp
)
5967 struct sk_buff
*msg
;
5970 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5974 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
5980 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5981 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5982 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
);
5983 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, channel_type
);
5984 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
5986 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
)
5987 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, duration
);
5989 if (genlmsg_end(msg
, hdr
) < 0) {
5994 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5995 nl80211_mlme_mcgrp
.id
, gfp
);
5999 genlmsg_cancel(msg
, hdr
);
6003 void nl80211_send_remain_on_channel(struct cfg80211_registered_device
*rdev
,
6004 struct net_device
*netdev
, u64 cookie
,
6005 struct ieee80211_channel
*chan
,
6006 enum nl80211_channel_type channel_type
,
6007 unsigned int duration
, gfp_t gfp
)
6009 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
6010 rdev
, netdev
, cookie
, chan
,
6011 channel_type
, duration
, gfp
);
6014 void nl80211_send_remain_on_channel_cancel(
6015 struct cfg80211_registered_device
*rdev
, struct net_device
*netdev
,
6016 u64 cookie
, struct ieee80211_channel
*chan
,
6017 enum nl80211_channel_type channel_type
, gfp_t gfp
)
6019 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
6020 rdev
, netdev
, cookie
, chan
,
6021 channel_type
, 0, gfp
);
6024 void nl80211_send_sta_event(struct cfg80211_registered_device
*rdev
,
6025 struct net_device
*dev
, const u8
*mac_addr
,
6026 struct station_info
*sinfo
, gfp_t gfp
)
6028 struct sk_buff
*msg
;
6030 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6034 if (nl80211_send_station(msg
, 0, 0, 0, dev
, mac_addr
, sinfo
) < 0) {
6039 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6040 nl80211_mlme_mcgrp
.id
, gfp
);
6043 int nl80211_send_action(struct cfg80211_registered_device
*rdev
,
6044 struct net_device
*netdev
, u32 nlpid
,
6045 int freq
, const u8
*buf
, size_t len
, gfp_t gfp
)
6047 struct sk_buff
*msg
;
6051 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6055 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ACTION
);
6061 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6062 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6063 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
6064 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
6066 err
= genlmsg_end(msg
, hdr
);
6072 err
= genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
6078 genlmsg_cancel(msg
, hdr
);
6083 void nl80211_send_action_tx_status(struct cfg80211_registered_device
*rdev
,
6084 struct net_device
*netdev
, u64 cookie
,
6085 const u8
*buf
, size_t len
, bool ack
,
6088 struct sk_buff
*msg
;
6091 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6095 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ACTION_TX_STATUS
);
6101 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6102 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6103 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
6104 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
6106 NLA_PUT_FLAG(msg
, NL80211_ATTR_ACK
);
6108 if (genlmsg_end(msg
, hdr
) < 0) {
6113 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
6117 genlmsg_cancel(msg
, hdr
);
6122 nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device
*rdev
,
6123 struct net_device
*netdev
,
6124 enum nl80211_cqm_rssi_threshold_event rssi_event
,
6127 struct sk_buff
*msg
;
6128 struct nlattr
*pinfoattr
;
6131 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6135 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
6141 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6142 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6144 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
6146 goto nla_put_failure
;
6148 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
6151 nla_nest_end(msg
, pinfoattr
);
6153 if (genlmsg_end(msg
, hdr
) < 0) {
6158 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6159 nl80211_mlme_mcgrp
.id
, gfp
);
6163 genlmsg_cancel(msg
, hdr
);
6167 static int nl80211_netlink_notify(struct notifier_block
* nb
,
6168 unsigned long state
,
6171 struct netlink_notify
*notify
= _notify
;
6172 struct cfg80211_registered_device
*rdev
;
6173 struct wireless_dev
*wdev
;
6175 if (state
!= NETLINK_URELEASE
)
6180 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
)
6181 list_for_each_entry_rcu(wdev
, &rdev
->netdev_list
, list
)
6182 cfg80211_mlme_unregister_actions(wdev
, notify
->pid
);
6189 static struct notifier_block nl80211_netlink_notifier
= {
6190 .notifier_call
= nl80211_netlink_notify
,
6193 /* initialisation/exit functions */
6195 int nl80211_init(void)
6199 err
= genl_register_family_with_ops(&nl80211_fam
,
6200 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
6204 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
6208 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
6212 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
6216 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
6220 #ifdef CONFIG_NL80211_TESTMODE
6221 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
6226 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
6232 genl_unregister_family(&nl80211_fam
);
6236 void nl80211_exit(void)
6238 netlink_unregister_notifier(&nl80211_netlink_notifier
);
6239 genl_unregister_family(&nl80211_fam
);