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
) {
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
);
2775 cfg80211_unlock_rdev(rdev
);
2783 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2785 if (table[attr_num]) {\
2786 cfg.param = nla_fn(table[attr_num]); \
2787 mask |= (1 << (attr_num - 1)); \
2791 static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
2792 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
2793 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
2794 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
2795 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
2796 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
2797 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
2798 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
2800 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
2801 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
2802 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
2803 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
2804 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
2805 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
2808 static int nl80211_set_mesh_params(struct sk_buff
*skb
, struct genl_info
*info
)
2812 struct cfg80211_registered_device
*rdev
;
2813 struct net_device
*dev
;
2814 struct mesh_config cfg
;
2815 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
2816 struct nlattr
*parent_attr
;
2818 parent_attr
= info
->attrs
[NL80211_ATTR_MESH_PARAMS
];
2821 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
2822 parent_attr
, nl80211_meshconf_params_policy
))
2827 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2831 if (!rdev
->ops
->set_mesh_params
) {
2836 /* This makes sure that there aren't more than 32 mesh config
2837 * parameters (otherwise our bitfield scheme would not work.) */
2838 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
2840 /* Fill in the params struct */
2842 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
2843 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
, nla_get_u16
);
2844 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
2845 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
, nla_get_u16
);
2846 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
2847 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
, nla_get_u16
);
2848 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
2849 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
, nla_get_u16
);
2850 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
2851 mask
, NL80211_MESHCONF_MAX_RETRIES
, nla_get_u8
);
2852 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
2853 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
2854 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
2855 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
, nla_get_u8
);
2856 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
2857 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2859 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
2860 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
, nla_get_u32
);
2861 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
2862 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2864 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
2865 mask
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2867 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
2868 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2870 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
2871 dot11MeshHWMPnetDiameterTraversalTime
,
2872 mask
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2874 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
2875 dot11MeshHWMPRootMode
, mask
,
2876 NL80211_MESHCONF_HWMP_ROOTMODE
,
2880 err
= rdev
->ops
->set_mesh_params(&rdev
->wiphy
, dev
, &cfg
, mask
);
2884 cfg80211_unlock_rdev(rdev
);
2892 #undef FILL_IN_MESH_PARAM_IF_SET
2894 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2896 struct sk_buff
*msg
;
2898 struct nlattr
*nl_reg_rules
;
2902 mutex_lock(&cfg80211_mutex
);
2904 if (!cfg80211_regdomain
)
2907 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2913 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2914 NL80211_CMD_GET_REG
);
2916 goto nla_put_failure
;
2918 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
,
2919 cfg80211_regdomain
->alpha2
);
2921 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
2923 goto nla_put_failure
;
2925 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
2926 struct nlattr
*nl_reg_rule
;
2927 const struct ieee80211_reg_rule
*reg_rule
;
2928 const struct ieee80211_freq_range
*freq_range
;
2929 const struct ieee80211_power_rule
*power_rule
;
2931 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
2932 freq_range
= ®_rule
->freq_range
;
2933 power_rule
= ®_rule
->power_rule
;
2935 nl_reg_rule
= nla_nest_start(msg
, i
);
2937 goto nla_put_failure
;
2939 NLA_PUT_U32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
2941 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
2942 freq_range
->start_freq_khz
);
2943 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
2944 freq_range
->end_freq_khz
);
2945 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
2946 freq_range
->max_bandwidth_khz
);
2947 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
2948 power_rule
->max_antenna_gain
);
2949 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
2950 power_rule
->max_eirp
);
2952 nla_nest_end(msg
, nl_reg_rule
);
2955 nla_nest_end(msg
, nl_reg_rules
);
2957 genlmsg_end(msg
, hdr
);
2958 err
= genlmsg_reply(msg
, info
);
2962 genlmsg_cancel(msg
, hdr
);
2965 mutex_unlock(&cfg80211_mutex
);
2969 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2971 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
2972 struct nlattr
*nl_reg_rule
;
2973 char *alpha2
= NULL
;
2974 int rem_reg_rules
= 0, r
= 0;
2975 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
2976 struct ieee80211_regdomain
*rd
= NULL
;
2978 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2981 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
2984 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2986 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
2989 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
2993 mutex_lock(&cfg80211_mutex
);
2995 if (!reg_is_valid_request(alpha2
)) {
3000 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
3001 (num_rules
* sizeof(struct ieee80211_reg_rule
));
3003 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
3009 rd
->n_reg_rules
= num_rules
;
3010 rd
->alpha2
[0] = alpha2
[0];
3011 rd
->alpha2
[1] = alpha2
[1];
3013 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
3015 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
3016 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
3018 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
3024 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
3030 BUG_ON(rule_idx
!= num_rules
);
3034 mutex_unlock(&cfg80211_mutex
);
3039 mutex_unlock(&cfg80211_mutex
);
3044 static int validate_scan_freqs(struct nlattr
*freqs
)
3046 struct nlattr
*attr1
, *attr2
;
3047 int n_channels
= 0, tmp1
, tmp2
;
3049 nla_for_each_nested(attr1
, freqs
, tmp1
) {
3052 * Some hardware has a limited channel list for
3053 * scanning, and it is pretty much nonsensical
3054 * to scan for a channel twice, so disallow that
3055 * and don't require drivers to check that the
3056 * channel list they get isn't longer than what
3057 * they can scan, as long as they can scan all
3058 * the channels they registered at once.
3060 nla_for_each_nested(attr2
, freqs
, tmp2
)
3061 if (attr1
!= attr2
&&
3062 nla_get_u32(attr1
) == nla_get_u32(attr2
))
3069 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
3071 struct cfg80211_registered_device
*rdev
;
3072 struct net_device
*dev
;
3073 struct cfg80211_scan_request
*request
;
3074 struct cfg80211_ssid
*ssid
;
3075 struct ieee80211_channel
*channel
;
3076 struct nlattr
*attr
;
3077 struct wiphy
*wiphy
;
3078 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
3079 enum ieee80211_band band
;
3082 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3087 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3091 wiphy
= &rdev
->wiphy
;
3093 if (!rdev
->ops
->scan
) {
3098 if (!netif_running(dev
)) {
3103 if (rdev
->scan_req
) {
3108 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3109 n_channels
= validate_scan_freqs(
3110 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
3118 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
3119 if (wiphy
->bands
[band
])
3120 n_channels
+= wiphy
->bands
[band
]->n_channels
;
3123 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
3124 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
3127 if (n_ssids
> wiphy
->max_scan_ssids
) {
3132 if (info
->attrs
[NL80211_ATTR_IE
])
3133 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3137 if (ie_len
> wiphy
->max_scan_ie_len
) {
3142 request
= kzalloc(sizeof(*request
)
3143 + sizeof(*ssid
) * n_ssids
3144 + sizeof(channel
) * n_channels
3145 + ie_len
, GFP_KERNEL
);
3152 request
->ssids
= (void *)&request
->channels
[n_channels
];
3153 request
->n_ssids
= n_ssids
;
3156 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
3158 request
->ie
= (void *)(request
->channels
+ n_channels
);
3162 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3163 /* user specified, bail out if channel not found */
3164 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
3165 struct ieee80211_channel
*chan
;
3167 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
3174 /* ignore disabled channels */
3175 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3178 request
->channels
[i
] = chan
;
3183 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
3185 if (!wiphy
->bands
[band
])
3187 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
3188 struct ieee80211_channel
*chan
;
3190 chan
= &wiphy
->bands
[band
]->channels
[j
];
3192 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3195 request
->channels
[i
] = chan
;
3206 request
->n_channels
= i
;
3209 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
3210 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
3211 if (request
->ssids
[i
].ssid_len
> IEEE80211_MAX_SSID_LEN
) {
3215 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
3216 request
->ssids
[i
].ssid_len
= nla_len(attr
);
3221 if (info
->attrs
[NL80211_ATTR_IE
]) {
3222 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3223 memcpy((void *)request
->ie
,
3224 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
3229 request
->wiphy
= &rdev
->wiphy
;
3231 rdev
->scan_req
= request
;
3232 err
= rdev
->ops
->scan(&rdev
->wiphy
, dev
, request
);
3235 nl80211_send_scan_start(rdev
, dev
);
3241 rdev
->scan_req
= NULL
;
3245 cfg80211_unlock_rdev(rdev
);
3253 static int nl80211_send_bss(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
3254 struct cfg80211_registered_device
*rdev
,
3255 struct wireless_dev
*wdev
,
3256 struct cfg80211_internal_bss
*intbss
)
3258 struct cfg80211_bss
*res
= &intbss
->pub
;
3263 ASSERT_WDEV_LOCK(wdev
);
3265 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3266 NL80211_CMD_NEW_SCAN_RESULTS
);
3270 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
);
3271 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
);
3273 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
3275 goto nla_put_failure
;
3276 if (!is_zero_ether_addr(res
->bssid
))
3277 NLA_PUT(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
);
3278 if (res
->information_elements
&& res
->len_information_elements
)
3279 NLA_PUT(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
3280 res
->len_information_elements
,
3281 res
->information_elements
);
3282 if (res
->beacon_ies
&& res
->len_beacon_ies
&&
3283 res
->beacon_ies
!= res
->information_elements
)
3284 NLA_PUT(msg
, NL80211_BSS_BEACON_IES
,
3285 res
->len_beacon_ies
, res
->beacon_ies
);
3287 NLA_PUT_U64(msg
, NL80211_BSS_TSF
, res
->tsf
);
3288 if (res
->beacon_interval
)
3289 NLA_PUT_U16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
);
3290 NLA_PUT_U16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
);
3291 NLA_PUT_U32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
);
3292 NLA_PUT_U32(msg
, NL80211_BSS_SEEN_MS_AGO
,
3293 jiffies_to_msecs(jiffies
- intbss
->ts
));
3295 switch (rdev
->wiphy
.signal_type
) {
3296 case CFG80211_SIGNAL_TYPE_MBM
:
3297 NLA_PUT_U32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
);
3299 case CFG80211_SIGNAL_TYPE_UNSPEC
:
3300 NLA_PUT_U8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
);
3306 switch (wdev
->iftype
) {
3307 case NL80211_IFTYPE_STATION
:
3308 if (intbss
== wdev
->current_bss
)
3309 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3310 NL80211_BSS_STATUS_ASSOCIATED
);
3311 else for (i
= 0; i
< MAX_AUTH_BSSES
; i
++) {
3312 if (intbss
!= wdev
->auth_bsses
[i
])
3314 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3315 NL80211_BSS_STATUS_AUTHENTICATED
);
3319 case NL80211_IFTYPE_ADHOC
:
3320 if (intbss
== wdev
->current_bss
)
3321 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3322 NL80211_BSS_STATUS_IBSS_JOINED
);
3328 nla_nest_end(msg
, bss
);
3330 return genlmsg_end(msg
, hdr
);
3333 genlmsg_cancel(msg
, hdr
);
3337 static int nl80211_dump_scan(struct sk_buff
*skb
,
3338 struct netlink_callback
*cb
)
3340 struct cfg80211_registered_device
*rdev
;
3341 struct net_device
*dev
;
3342 struct cfg80211_internal_bss
*scan
;
3343 struct wireless_dev
*wdev
;
3344 int ifidx
= cb
->args
[0];
3345 int start
= cb
->args
[1], idx
= 0;
3349 ifidx
= nl80211_get_ifidx(cb
);
3352 cb
->args
[0] = ifidx
;
3354 dev
= dev_get_by_index(sock_net(skb
->sk
), ifidx
);
3358 rdev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
3360 err
= PTR_ERR(rdev
);
3361 goto out_put_netdev
;
3364 wdev
= dev
->ieee80211_ptr
;
3367 spin_lock_bh(&rdev
->bss_lock
);
3368 cfg80211_bss_expire(rdev
);
3370 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
3373 if (nl80211_send_bss(skb
,
3374 NETLINK_CB(cb
->skb
).pid
,
3375 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3376 rdev
, wdev
, scan
) < 0) {
3383 spin_unlock_bh(&rdev
->bss_lock
);
3388 cfg80211_unlock_rdev(rdev
);
3395 static int nl80211_send_survey(struct sk_buff
*msg
, u32 pid
, u32 seq
,
3396 int flags
, struct net_device
*dev
,
3397 struct survey_info
*survey
)
3400 struct nlattr
*infoattr
;
3402 /* Survey without a channel doesn't make sense */
3403 if (!survey
->channel
)
3406 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3407 NL80211_CMD_NEW_SURVEY_RESULTS
);
3411 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
3413 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
3415 goto nla_put_failure
;
3417 NLA_PUT_U32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
3418 survey
->channel
->center_freq
);
3419 if (survey
->filled
& SURVEY_INFO_NOISE_DBM
)
3420 NLA_PUT_U8(msg
, NL80211_SURVEY_INFO_NOISE
,
3423 nla_nest_end(msg
, infoattr
);
3425 return genlmsg_end(msg
, hdr
);
3428 genlmsg_cancel(msg
, hdr
);
3432 static int nl80211_dump_survey(struct sk_buff
*skb
,
3433 struct netlink_callback
*cb
)
3435 struct survey_info survey
;
3436 struct cfg80211_registered_device
*dev
;
3437 struct net_device
*netdev
;
3438 int ifidx
= cb
->args
[0];
3439 int survey_idx
= cb
->args
[1];
3443 ifidx
= nl80211_get_ifidx(cb
);
3446 cb
->args
[0] = ifidx
;
3450 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
3456 dev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
3462 if (!dev
->ops
->dump_survey
) {
3468 res
= dev
->ops
->dump_survey(&dev
->wiphy
, netdev
, survey_idx
,
3475 if (nl80211_send_survey(skb
,
3476 NETLINK_CB(cb
->skb
).pid
,
3477 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3485 cb
->args
[1] = survey_idx
;
3488 cfg80211_unlock_rdev(dev
);
3495 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
)
3497 return auth_type
<= NL80211_AUTHTYPE_MAX
;
3500 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
3502 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
3503 NL80211_WPA_VERSION_2
));
3506 static bool nl80211_valid_akm_suite(u32 akm
)
3508 return akm
== WLAN_AKM_SUITE_8021X
||
3509 akm
== WLAN_AKM_SUITE_PSK
;
3512 static bool nl80211_valid_cipher_suite(u32 cipher
)
3514 return cipher
== WLAN_CIPHER_SUITE_WEP40
||
3515 cipher
== WLAN_CIPHER_SUITE_WEP104
||
3516 cipher
== WLAN_CIPHER_SUITE_TKIP
||
3517 cipher
== WLAN_CIPHER_SUITE_CCMP
||
3518 cipher
== WLAN_CIPHER_SUITE_AES_CMAC
;
3522 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3524 struct cfg80211_registered_device
*rdev
;
3525 struct net_device
*dev
;
3526 struct ieee80211_channel
*chan
;
3527 const u8
*bssid
, *ssid
, *ie
= NULL
;
3528 int err
, ssid_len
, ie_len
= 0;
3529 enum nl80211_auth_type auth_type
;
3530 struct key_parse key
;
3531 bool local_state_change
;
3533 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3536 if (!info
->attrs
[NL80211_ATTR_MAC
])
3539 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
3542 if (!info
->attrs
[NL80211_ATTR_SSID
])
3545 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
3548 err
= nl80211_parse_key(info
, &key
);
3553 if (!key
.p
.key
|| !key
.p
.key_len
)
3555 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
3556 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
3557 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
3558 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
3569 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3573 if (!rdev
->ops
->auth
) {
3578 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3583 if (!netif_running(dev
)) {
3588 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3589 chan
= ieee80211_get_channel(&rdev
->wiphy
,
3590 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3591 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
)) {
3596 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3597 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3599 if (info
->attrs
[NL80211_ATTR_IE
]) {
3600 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3601 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3604 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3605 if (!nl80211_valid_auth_type(auth_type
)) {
3610 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
3612 err
= cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
3613 ssid
, ssid_len
, ie
, ie_len
,
3614 key
.p
.key
, key
.p
.key_len
, key
.idx
,
3615 local_state_change
);
3618 cfg80211_unlock_rdev(rdev
);
3625 static int nl80211_crypto_settings(struct genl_info
*info
,
3626 struct cfg80211_crypto_settings
*settings
,
3629 memset(settings
, 0, sizeof(*settings
));
3631 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
3633 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
3637 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
3638 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
3639 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
3641 if (len
% sizeof(u32
))
3644 if (settings
->n_ciphers_pairwise
> cipher_limit
)
3647 memcpy(settings
->ciphers_pairwise
, data
, len
);
3649 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
3650 if (!nl80211_valid_cipher_suite(
3651 settings
->ciphers_pairwise
[i
]))
3655 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
3656 settings
->cipher_group
=
3657 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
3658 if (!nl80211_valid_cipher_suite(settings
->cipher_group
))
3662 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
3663 settings
->wpa_versions
=
3664 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
3665 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
3669 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
3673 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
3674 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
3675 settings
->n_akm_suites
= len
/ sizeof(u32
);
3677 if (len
% sizeof(u32
))
3680 memcpy(settings
->akm_suites
, data
, len
);
3682 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
3683 if (!nl80211_valid_akm_suite(settings
->akm_suites
[i
]))
3690 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
3692 struct cfg80211_registered_device
*rdev
;
3693 struct net_device
*dev
;
3694 struct cfg80211_crypto_settings crypto
;
3695 struct ieee80211_channel
*chan
;
3696 const u8
*bssid
, *ssid
, *ie
= NULL
, *prev_bssid
= NULL
;
3697 int err
, ssid_len
, ie_len
= 0;
3698 bool use_mfp
= false;
3700 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3703 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
3704 !info
->attrs
[NL80211_ATTR_SSID
] ||
3705 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
3710 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3714 if (!rdev
->ops
->assoc
) {
3719 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3724 if (!netif_running(dev
)) {
3729 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3731 chan
= ieee80211_get_channel(&rdev
->wiphy
,
3732 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3733 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
)) {
3738 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3739 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3741 if (info
->attrs
[NL80211_ATTR_IE
]) {
3742 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3743 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3746 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
3747 enum nl80211_mfp mfp
=
3748 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
3749 if (mfp
== NL80211_MFP_REQUIRED
)
3751 else if (mfp
!= NL80211_MFP_NO
) {
3757 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
3758 prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
3760 err
= nl80211_crypto_settings(info
, &crypto
, 1);
3762 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
, prev_bssid
,
3763 ssid
, ssid_len
, ie
, ie_len
, use_mfp
,
3767 cfg80211_unlock_rdev(rdev
);
3774 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3776 struct cfg80211_registered_device
*rdev
;
3777 struct net_device
*dev
;
3778 const u8
*ie
= NULL
, *bssid
;
3779 int err
, ie_len
= 0;
3781 bool local_state_change
;
3783 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3786 if (!info
->attrs
[NL80211_ATTR_MAC
])
3789 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3794 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3798 if (!rdev
->ops
->deauth
) {
3803 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3808 if (!netif_running(dev
)) {
3813 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3815 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3816 if (reason_code
== 0) {
3817 /* Reason Code 0 is reserved */
3822 if (info
->attrs
[NL80211_ATTR_IE
]) {
3823 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3824 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3827 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
3829 err
= cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
3830 local_state_change
);
3833 cfg80211_unlock_rdev(rdev
);
3840 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
3842 struct cfg80211_registered_device
*rdev
;
3843 struct net_device
*dev
;
3844 const u8
*ie
= NULL
, *bssid
;
3845 int err
, ie_len
= 0;
3847 bool local_state_change
;
3849 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3852 if (!info
->attrs
[NL80211_ATTR_MAC
])
3855 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3860 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3864 if (!rdev
->ops
->disassoc
) {
3869 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3874 if (!netif_running(dev
)) {
3879 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3881 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3882 if (reason_code
== 0) {
3883 /* Reason Code 0 is reserved */
3888 if (info
->attrs
[NL80211_ATTR_IE
]) {
3889 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3890 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3893 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
3895 err
= cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
3896 local_state_change
);
3899 cfg80211_unlock_rdev(rdev
);
3906 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
3908 struct cfg80211_registered_device
*rdev
;
3909 struct net_device
*dev
;
3910 struct cfg80211_ibss_params ibss
;
3911 struct wiphy
*wiphy
;
3912 struct cfg80211_cached_keys
*connkeys
= NULL
;
3915 memset(&ibss
, 0, sizeof(ibss
));
3917 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3920 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
3921 !info
->attrs
[NL80211_ATTR_SSID
] ||
3922 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
3925 ibss
.beacon_interval
= 100;
3927 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
3928 ibss
.beacon_interval
=
3929 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3930 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
3936 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3940 if (!rdev
->ops
->join_ibss
) {
3945 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
3950 if (!netif_running(dev
)) {
3955 wiphy
= &rdev
->wiphy
;
3957 if (info
->attrs
[NL80211_ATTR_MAC
])
3958 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3959 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3960 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3962 if (info
->attrs
[NL80211_ATTR_IE
]) {
3963 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3964 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3967 ibss
.channel
= ieee80211_get_channel(wiphy
,
3968 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3969 if (!ibss
.channel
||
3970 ibss
.channel
->flags
& IEEE80211_CHAN_NO_IBSS
||
3971 ibss
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
3976 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
3977 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3979 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
3980 connkeys
= nl80211_parse_connkeys(rdev
,
3981 info
->attrs
[NL80211_ATTR_KEYS
]);
3982 if (IS_ERR(connkeys
)) {
3983 err
= PTR_ERR(connkeys
);
3989 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
3991 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
3993 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
3994 struct ieee80211_supported_band
*sband
=
3995 wiphy
->bands
[ibss
.channel
->band
];
4003 for (i
= 0; i
< n_rates
; i
++) {
4004 int rate
= (rates
[i
] & 0x7f) * 5;
4007 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
4008 if (sband
->bitrates
[j
].bitrate
== rate
) {
4010 ibss
.basic_rates
|= BIT(j
);
4021 * If no rates were explicitly configured,
4022 * use the mandatory rate set for 11b or
4023 * 11a for maximum compatibility.
4025 struct ieee80211_supported_band
*sband
=
4026 wiphy
->bands
[ibss
.channel
->band
];
4028 u32 flag
= ibss
.channel
->band
== IEEE80211_BAND_5GHZ
?
4029 IEEE80211_RATE_MANDATORY_A
:
4030 IEEE80211_RATE_MANDATORY_B
;
4032 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
4033 if (sband
->bitrates
[j
].flags
& flag
)
4034 ibss
.basic_rates
|= BIT(j
);
4038 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
4041 cfg80211_unlock_rdev(rdev
);
4050 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
4052 struct cfg80211_registered_device
*rdev
;
4053 struct net_device
*dev
;
4058 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4062 if (!rdev
->ops
->leave_ibss
) {
4067 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
4072 if (!netif_running(dev
)) {
4077 err
= cfg80211_leave_ibss(rdev
, dev
, false);
4080 cfg80211_unlock_rdev(rdev
);
4087 #ifdef CONFIG_NL80211_TESTMODE
4088 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
4092 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
4094 struct cfg80211_registered_device
*rdev
;
4097 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
4102 rdev
= cfg80211_get_dev_from_info(info
);
4104 err
= PTR_ERR(rdev
);
4109 if (rdev
->ops
->testmode_cmd
) {
4110 rdev
->testmode_info
= info
;
4111 err
= rdev
->ops
->testmode_cmd(&rdev
->wiphy
,
4112 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
4113 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
4114 rdev
->testmode_info
= NULL
;
4117 cfg80211_unlock_rdev(rdev
);
4124 static struct sk_buff
*
4125 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
4126 int approxlen
, u32 pid
, u32 seq
, gfp_t gfp
)
4128 struct sk_buff
*skb
;
4130 struct nlattr
*data
;
4132 skb
= nlmsg_new(approxlen
+ 100, gfp
);
4136 hdr
= nl80211hdr_put(skb
, pid
, seq
, 0, NL80211_CMD_TESTMODE
);
4142 NLA_PUT_U32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4143 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
4145 ((void **)skb
->cb
)[0] = rdev
;
4146 ((void **)skb
->cb
)[1] = hdr
;
4147 ((void **)skb
->cb
)[2] = data
;
4156 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
4159 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4161 if (WARN_ON(!rdev
->testmode_info
))
4164 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
4165 rdev
->testmode_info
->snd_pid
,
4166 rdev
->testmode_info
->snd_seq
,
4169 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
4171 int cfg80211_testmode_reply(struct sk_buff
*skb
)
4173 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
4174 void *hdr
= ((void **)skb
->cb
)[1];
4175 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4177 if (WARN_ON(!rdev
->testmode_info
)) {
4182 nla_nest_end(skb
, data
);
4183 genlmsg_end(skb
, hdr
);
4184 return genlmsg_reply(skb
, rdev
->testmode_info
);
4186 EXPORT_SYMBOL(cfg80211_testmode_reply
);
4188 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
4189 int approxlen
, gfp_t gfp
)
4191 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4193 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
4195 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
4197 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
4199 void *hdr
= ((void **)skb
->cb
)[1];
4200 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4202 nla_nest_end(skb
, data
);
4203 genlmsg_end(skb
, hdr
);
4204 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
4206 EXPORT_SYMBOL(cfg80211_testmode_event
);
4209 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
4211 struct cfg80211_registered_device
*rdev
;
4212 struct net_device
*dev
;
4213 struct cfg80211_connect_params connect
;
4214 struct wiphy
*wiphy
;
4215 struct cfg80211_cached_keys
*connkeys
= NULL
;
4218 memset(&connect
, 0, sizeof(connect
));
4220 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4223 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
4224 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
4227 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
4229 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4230 if (!nl80211_valid_auth_type(connect
.auth_type
))
4233 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
4235 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
4237 err
= nl80211_crypto_settings(info
, &connect
.crypto
,
4238 NL80211_MAX_NR_CIPHER_SUITES
);
4243 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4247 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4252 if (!netif_running(dev
)) {
4257 wiphy
= &rdev
->wiphy
;
4259 if (info
->attrs
[NL80211_ATTR_MAC
])
4260 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4261 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4262 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4264 if (info
->attrs
[NL80211_ATTR_IE
]) {
4265 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4266 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4269 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
4271 ieee80211_get_channel(wiphy
,
4272 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4273 if (!connect
.channel
||
4274 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
4280 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
4281 connkeys
= nl80211_parse_connkeys(rdev
,
4282 info
->attrs
[NL80211_ATTR_KEYS
]);
4283 if (IS_ERR(connkeys
)) {
4284 err
= PTR_ERR(connkeys
);
4290 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
4293 cfg80211_unlock_rdev(rdev
);
4302 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
4304 struct cfg80211_registered_device
*rdev
;
4305 struct net_device
*dev
;
4309 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4310 reason
= WLAN_REASON_DEAUTH_LEAVING
;
4312 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4319 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4323 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4328 if (!netif_running(dev
)) {
4333 err
= cfg80211_disconnect(rdev
, dev
, reason
, true);
4336 cfg80211_unlock_rdev(rdev
);
4343 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
4345 struct cfg80211_registered_device
*rdev
;
4350 if (!info
->attrs
[NL80211_ATTR_PID
])
4353 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
4357 rdev
= cfg80211_get_dev_from_info(info
);
4359 err
= PTR_ERR(rdev
);
4363 net
= get_net_ns_by_pid(pid
);
4371 /* check if anything to do */
4372 if (net_eq(wiphy_net(&rdev
->wiphy
), net
))
4375 err
= cfg80211_switch_netns(rdev
, net
);
4379 cfg80211_unlock_rdev(rdev
);
4385 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4387 struct cfg80211_registered_device
*rdev
;
4388 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
4389 struct cfg80211_pmksa
*pmksa
) = NULL
;
4391 struct net_device
*dev
;
4392 struct cfg80211_pmksa pmksa
;
4394 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
4396 if (!info
->attrs
[NL80211_ATTR_MAC
])
4399 if (!info
->attrs
[NL80211_ATTR_PMKID
])
4404 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4408 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
4409 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4411 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4416 switch (info
->genlhdr
->cmd
) {
4417 case NL80211_CMD_SET_PMKSA
:
4418 rdev_ops
= rdev
->ops
->set_pmksa
;
4420 case NL80211_CMD_DEL_PMKSA
:
4421 rdev_ops
= rdev
->ops
->del_pmksa
;
4433 err
= rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
4436 cfg80211_unlock_rdev(rdev
);
4444 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4446 struct cfg80211_registered_device
*rdev
;
4448 struct net_device
*dev
;
4452 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4456 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4461 if (!rdev
->ops
->flush_pmksa
) {
4466 err
= rdev
->ops
->flush_pmksa(&rdev
->wiphy
, dev
);
4469 cfg80211_unlock_rdev(rdev
);
4478 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
4479 struct genl_info
*info
)
4481 struct cfg80211_registered_device
*rdev
;
4482 struct net_device
*dev
;
4483 struct ieee80211_channel
*chan
;
4484 struct sk_buff
*msg
;
4487 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
4491 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
4492 !info
->attrs
[NL80211_ATTR_DURATION
])
4495 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
4498 * We should be on that channel for at least one jiffie,
4499 * and more than 5 seconds seems excessive.
4501 if (!duration
|| !msecs_to_jiffies(duration
) || duration
> 5000)
4506 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4510 if (!rdev
->ops
->remain_on_channel
) {
4515 if (!netif_running(dev
)) {
4520 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
4521 channel_type
= nla_get_u32(
4522 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
4523 if (channel_type
!= NL80211_CHAN_NO_HT
&&
4524 channel_type
!= NL80211_CHAN_HT20
&&
4525 channel_type
!= NL80211_CHAN_HT40PLUS
&&
4526 channel_type
!= NL80211_CHAN_HT40MINUS
) {
4532 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
4533 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
4539 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4545 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4546 NL80211_CMD_REMAIN_ON_CHANNEL
);
4553 err
= rdev
->ops
->remain_on_channel(&rdev
->wiphy
, dev
, chan
,
4554 channel_type
, duration
, &cookie
);
4559 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
4561 genlmsg_end(msg
, hdr
);
4562 err
= genlmsg_reply(msg
, info
);
4570 cfg80211_unlock_rdev(rdev
);
4577 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
4578 struct genl_info
*info
)
4580 struct cfg80211_registered_device
*rdev
;
4581 struct net_device
*dev
;
4585 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
4590 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4594 if (!rdev
->ops
->cancel_remain_on_channel
) {
4599 if (!netif_running(dev
)) {
4604 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
4606 err
= rdev
->ops
->cancel_remain_on_channel(&rdev
->wiphy
, dev
, cookie
);
4609 cfg80211_unlock_rdev(rdev
);
4616 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
4617 u8
*rates
, u8 rates_len
)
4622 for (i
= 0; i
< rates_len
; i
++) {
4623 int rate
= (rates
[i
] & 0x7f) * 5;
4625 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
4626 struct ieee80211_rate
*srate
=
4627 &sband
->bitrates
[ridx
];
4628 if (rate
== srate
->bitrate
) {
4633 if (ridx
== sband
->n_bitrates
)
4634 return 0; /* rate not found */
4640 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
4641 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
4642 .len
= NL80211_MAX_SUPP_RATES
},
4645 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
4646 struct genl_info
*info
)
4648 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
4649 struct cfg80211_registered_device
*rdev
;
4650 struct cfg80211_bitrate_mask mask
;
4652 struct net_device
*dev
;
4653 struct nlattr
*tx_rates
;
4654 struct ieee80211_supported_band
*sband
;
4656 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
4661 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4665 if (!rdev
->ops
->set_bitrate_mask
) {
4670 memset(&mask
, 0, sizeof(mask
));
4671 /* Default to all rates enabled */
4672 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
4673 sband
= rdev
->wiphy
.bands
[i
];
4674 mask
.control
[i
].legacy
=
4675 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
4679 * The nested attribute uses enum nl80211_band as the index. This maps
4680 * directly to the enum ieee80211_band values used in cfg80211.
4682 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
4684 enum ieee80211_band band
= nla_type(tx_rates
);
4685 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
4689 sband
= rdev
->wiphy
.bands
[band
];
4690 if (sband
== NULL
) {
4694 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
4695 nla_len(tx_rates
), nl80211_txattr_policy
);
4696 if (tb
[NL80211_TXRATE_LEGACY
]) {
4697 mask
.control
[band
].legacy
= rateset_to_mask(
4699 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
4700 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
4701 if (mask
.control
[band
].legacy
== 0) {
4708 err
= rdev
->ops
->set_bitrate_mask(&rdev
->wiphy
, dev
, NULL
, &mask
);
4712 cfg80211_unlock_rdev(rdev
);
4718 static int nl80211_register_action(struct sk_buff
*skb
, struct genl_info
*info
)
4720 struct cfg80211_registered_device
*rdev
;
4721 struct net_device
*dev
;
4724 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
4727 if (nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]) < 1)
4732 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4736 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4737 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
4742 /* not much point in registering if we can't reply */
4743 if (!rdev
->ops
->action
) {
4748 err
= cfg80211_mlme_register_action(dev
->ieee80211_ptr
, info
->snd_pid
,
4749 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
4750 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
4752 cfg80211_unlock_rdev(rdev
);
4759 static int nl80211_action(struct sk_buff
*skb
, struct genl_info
*info
)
4761 struct cfg80211_registered_device
*rdev
;
4762 struct net_device
*dev
;
4763 struct ieee80211_channel
*chan
;
4764 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
4765 bool channel_type_valid
= false;
4770 struct sk_buff
*msg
;
4772 if (!info
->attrs
[NL80211_ATTR_FRAME
] ||
4773 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4778 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4782 if (!rdev
->ops
->action
) {
4787 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4788 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
4793 if (!netif_running(dev
)) {
4798 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
4799 channel_type
= nla_get_u32(
4800 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
4801 if (channel_type
!= NL80211_CHAN_NO_HT
&&
4802 channel_type
!= NL80211_CHAN_HT20
&&
4803 channel_type
!= NL80211_CHAN_HT40PLUS
&&
4804 channel_type
!= NL80211_CHAN_HT40MINUS
) {
4808 channel_type_valid
= true;
4811 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
4812 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
4818 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4824 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4825 NL80211_CMD_ACTION
);
4831 err
= cfg80211_mlme_action(rdev
, dev
, chan
, channel_type
,
4833 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
4834 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
4839 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
4841 genlmsg_end(msg
, hdr
);
4842 err
= genlmsg_reply(msg
, info
);
4850 cfg80211_unlock_rdev(rdev
);
4857 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
4859 struct cfg80211_registered_device
*rdev
;
4860 struct wireless_dev
*wdev
;
4861 struct net_device
*dev
;
4866 if (!info
->attrs
[NL80211_ATTR_PS_STATE
]) {
4871 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
4873 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
) {
4880 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4884 wdev
= dev
->ieee80211_ptr
;
4886 if (!rdev
->ops
->set_power_mgmt
) {
4891 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
4893 if (state
== wdev
->ps
)
4898 if (rdev
->ops
->set_power_mgmt(wdev
->wiphy
, dev
, wdev
->ps
,
4900 /* assume this means it's off */
4904 cfg80211_unlock_rdev(rdev
);
4912 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
4914 struct cfg80211_registered_device
*rdev
;
4915 enum nl80211_ps_state ps_state
;
4916 struct wireless_dev
*wdev
;
4917 struct net_device
*dev
;
4918 struct sk_buff
*msg
;
4924 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4928 wdev
= dev
->ieee80211_ptr
;
4930 if (!rdev
->ops
->set_power_mgmt
) {
4935 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4941 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4942 NL80211_CMD_GET_POWER_SAVE
);
4949 ps_state
= NL80211_PS_ENABLED
;
4951 ps_state
= NL80211_PS_DISABLED
;
4953 NLA_PUT_U32(msg
, NL80211_ATTR_PS_STATE
, ps_state
);
4955 genlmsg_end(msg
, hdr
);
4956 err
= genlmsg_reply(msg
, info
);
4966 cfg80211_unlock_rdev(rdev
);
4975 static struct nla_policy
4976 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
4977 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
4978 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
4979 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
4982 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
4983 s32 threshold
, u32 hysteresis
)
4985 struct cfg80211_registered_device
*rdev
;
4986 struct wireless_dev
*wdev
;
4987 struct net_device
*dev
;
4995 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4999 wdev
= dev
->ieee80211_ptr
;
5001 if (!rdev
->ops
->set_cqm_rssi_config
) {
5006 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
) {
5011 err
= rdev
->ops
->set_cqm_rssi_config(wdev
->wiphy
, dev
,
5012 threshold
, hysteresis
);
5015 cfg80211_unlock_rdev(rdev
);
5022 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
5024 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
5028 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
5034 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
5035 nl80211_attr_cqm_policy
);
5039 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
5040 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
5043 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
5044 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
5045 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
5053 static struct genl_ops nl80211_ops
[] = {
5055 .cmd
= NL80211_CMD_GET_WIPHY
,
5056 .doit
= nl80211_get_wiphy
,
5057 .dumpit
= nl80211_dump_wiphy
,
5058 .policy
= nl80211_policy
,
5059 /* can be retrieved by unprivileged users */
5062 .cmd
= NL80211_CMD_SET_WIPHY
,
5063 .doit
= nl80211_set_wiphy
,
5064 .policy
= nl80211_policy
,
5065 .flags
= GENL_ADMIN_PERM
,
5068 .cmd
= NL80211_CMD_GET_INTERFACE
,
5069 .doit
= nl80211_get_interface
,
5070 .dumpit
= nl80211_dump_interface
,
5071 .policy
= nl80211_policy
,
5072 /* can be retrieved by unprivileged users */
5075 .cmd
= NL80211_CMD_SET_INTERFACE
,
5076 .doit
= nl80211_set_interface
,
5077 .policy
= nl80211_policy
,
5078 .flags
= GENL_ADMIN_PERM
,
5081 .cmd
= NL80211_CMD_NEW_INTERFACE
,
5082 .doit
= nl80211_new_interface
,
5083 .policy
= nl80211_policy
,
5084 .flags
= GENL_ADMIN_PERM
,
5087 .cmd
= NL80211_CMD_DEL_INTERFACE
,
5088 .doit
= nl80211_del_interface
,
5089 .policy
= nl80211_policy
,
5090 .flags
= GENL_ADMIN_PERM
,
5093 .cmd
= NL80211_CMD_GET_KEY
,
5094 .doit
= nl80211_get_key
,
5095 .policy
= nl80211_policy
,
5096 .flags
= GENL_ADMIN_PERM
,
5099 .cmd
= NL80211_CMD_SET_KEY
,
5100 .doit
= nl80211_set_key
,
5101 .policy
= nl80211_policy
,
5102 .flags
= GENL_ADMIN_PERM
,
5105 .cmd
= NL80211_CMD_NEW_KEY
,
5106 .doit
= nl80211_new_key
,
5107 .policy
= nl80211_policy
,
5108 .flags
= GENL_ADMIN_PERM
,
5111 .cmd
= NL80211_CMD_DEL_KEY
,
5112 .doit
= nl80211_del_key
,
5113 .policy
= nl80211_policy
,
5114 .flags
= GENL_ADMIN_PERM
,
5117 .cmd
= NL80211_CMD_SET_BEACON
,
5118 .policy
= nl80211_policy
,
5119 .flags
= GENL_ADMIN_PERM
,
5120 .doit
= nl80211_addset_beacon
,
5123 .cmd
= NL80211_CMD_NEW_BEACON
,
5124 .policy
= nl80211_policy
,
5125 .flags
= GENL_ADMIN_PERM
,
5126 .doit
= nl80211_addset_beacon
,
5129 .cmd
= NL80211_CMD_DEL_BEACON
,
5130 .policy
= nl80211_policy
,
5131 .flags
= GENL_ADMIN_PERM
,
5132 .doit
= nl80211_del_beacon
,
5135 .cmd
= NL80211_CMD_GET_STATION
,
5136 .doit
= nl80211_get_station
,
5137 .dumpit
= nl80211_dump_station
,
5138 .policy
= nl80211_policy
,
5141 .cmd
= NL80211_CMD_SET_STATION
,
5142 .doit
= nl80211_set_station
,
5143 .policy
= nl80211_policy
,
5144 .flags
= GENL_ADMIN_PERM
,
5147 .cmd
= NL80211_CMD_NEW_STATION
,
5148 .doit
= nl80211_new_station
,
5149 .policy
= nl80211_policy
,
5150 .flags
= GENL_ADMIN_PERM
,
5153 .cmd
= NL80211_CMD_DEL_STATION
,
5154 .doit
= nl80211_del_station
,
5155 .policy
= nl80211_policy
,
5156 .flags
= GENL_ADMIN_PERM
,
5159 .cmd
= NL80211_CMD_GET_MPATH
,
5160 .doit
= nl80211_get_mpath
,
5161 .dumpit
= nl80211_dump_mpath
,
5162 .policy
= nl80211_policy
,
5163 .flags
= GENL_ADMIN_PERM
,
5166 .cmd
= NL80211_CMD_SET_MPATH
,
5167 .doit
= nl80211_set_mpath
,
5168 .policy
= nl80211_policy
,
5169 .flags
= GENL_ADMIN_PERM
,
5172 .cmd
= NL80211_CMD_NEW_MPATH
,
5173 .doit
= nl80211_new_mpath
,
5174 .policy
= nl80211_policy
,
5175 .flags
= GENL_ADMIN_PERM
,
5178 .cmd
= NL80211_CMD_DEL_MPATH
,
5179 .doit
= nl80211_del_mpath
,
5180 .policy
= nl80211_policy
,
5181 .flags
= GENL_ADMIN_PERM
,
5184 .cmd
= NL80211_CMD_SET_BSS
,
5185 .doit
= nl80211_set_bss
,
5186 .policy
= nl80211_policy
,
5187 .flags
= GENL_ADMIN_PERM
,
5190 .cmd
= NL80211_CMD_GET_REG
,
5191 .doit
= nl80211_get_reg
,
5192 .policy
= nl80211_policy
,
5193 /* can be retrieved by unprivileged users */
5196 .cmd
= NL80211_CMD_SET_REG
,
5197 .doit
= nl80211_set_reg
,
5198 .policy
= nl80211_policy
,
5199 .flags
= GENL_ADMIN_PERM
,
5202 .cmd
= NL80211_CMD_REQ_SET_REG
,
5203 .doit
= nl80211_req_set_reg
,
5204 .policy
= nl80211_policy
,
5205 .flags
= GENL_ADMIN_PERM
,
5208 .cmd
= NL80211_CMD_GET_MESH_PARAMS
,
5209 .doit
= nl80211_get_mesh_params
,
5210 .policy
= nl80211_policy
,
5211 /* can be retrieved by unprivileged users */
5214 .cmd
= NL80211_CMD_SET_MESH_PARAMS
,
5215 .doit
= nl80211_set_mesh_params
,
5216 .policy
= nl80211_policy
,
5217 .flags
= GENL_ADMIN_PERM
,
5220 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
5221 .doit
= nl80211_trigger_scan
,
5222 .policy
= nl80211_policy
,
5223 .flags
= GENL_ADMIN_PERM
,
5226 .cmd
= NL80211_CMD_GET_SCAN
,
5227 .policy
= nl80211_policy
,
5228 .dumpit
= nl80211_dump_scan
,
5231 .cmd
= NL80211_CMD_AUTHENTICATE
,
5232 .doit
= nl80211_authenticate
,
5233 .policy
= nl80211_policy
,
5234 .flags
= GENL_ADMIN_PERM
,
5237 .cmd
= NL80211_CMD_ASSOCIATE
,
5238 .doit
= nl80211_associate
,
5239 .policy
= nl80211_policy
,
5240 .flags
= GENL_ADMIN_PERM
,
5243 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
5244 .doit
= nl80211_deauthenticate
,
5245 .policy
= nl80211_policy
,
5246 .flags
= GENL_ADMIN_PERM
,
5249 .cmd
= NL80211_CMD_DISASSOCIATE
,
5250 .doit
= nl80211_disassociate
,
5251 .policy
= nl80211_policy
,
5252 .flags
= GENL_ADMIN_PERM
,
5255 .cmd
= NL80211_CMD_JOIN_IBSS
,
5256 .doit
= nl80211_join_ibss
,
5257 .policy
= nl80211_policy
,
5258 .flags
= GENL_ADMIN_PERM
,
5261 .cmd
= NL80211_CMD_LEAVE_IBSS
,
5262 .doit
= nl80211_leave_ibss
,
5263 .policy
= nl80211_policy
,
5264 .flags
= GENL_ADMIN_PERM
,
5266 #ifdef CONFIG_NL80211_TESTMODE
5268 .cmd
= NL80211_CMD_TESTMODE
,
5269 .doit
= nl80211_testmode_do
,
5270 .policy
= nl80211_policy
,
5271 .flags
= GENL_ADMIN_PERM
,
5275 .cmd
= NL80211_CMD_CONNECT
,
5276 .doit
= nl80211_connect
,
5277 .policy
= nl80211_policy
,
5278 .flags
= GENL_ADMIN_PERM
,
5281 .cmd
= NL80211_CMD_DISCONNECT
,
5282 .doit
= nl80211_disconnect
,
5283 .policy
= nl80211_policy
,
5284 .flags
= GENL_ADMIN_PERM
,
5287 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
5288 .doit
= nl80211_wiphy_netns
,
5289 .policy
= nl80211_policy
,
5290 .flags
= GENL_ADMIN_PERM
,
5293 .cmd
= NL80211_CMD_GET_SURVEY
,
5294 .policy
= nl80211_policy
,
5295 .dumpit
= nl80211_dump_survey
,
5298 .cmd
= NL80211_CMD_SET_PMKSA
,
5299 .doit
= nl80211_setdel_pmksa
,
5300 .policy
= nl80211_policy
,
5301 .flags
= GENL_ADMIN_PERM
,
5304 .cmd
= NL80211_CMD_DEL_PMKSA
,
5305 .doit
= nl80211_setdel_pmksa
,
5306 .policy
= nl80211_policy
,
5307 .flags
= GENL_ADMIN_PERM
,
5310 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
5311 .doit
= nl80211_flush_pmksa
,
5312 .policy
= nl80211_policy
,
5313 .flags
= GENL_ADMIN_PERM
,
5316 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
5317 .doit
= nl80211_remain_on_channel
,
5318 .policy
= nl80211_policy
,
5319 .flags
= GENL_ADMIN_PERM
,
5322 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
5323 .doit
= nl80211_cancel_remain_on_channel
,
5324 .policy
= nl80211_policy
,
5325 .flags
= GENL_ADMIN_PERM
,
5328 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
5329 .doit
= nl80211_set_tx_bitrate_mask
,
5330 .policy
= nl80211_policy
,
5331 .flags
= GENL_ADMIN_PERM
,
5334 .cmd
= NL80211_CMD_REGISTER_ACTION
,
5335 .doit
= nl80211_register_action
,
5336 .policy
= nl80211_policy
,
5337 .flags
= GENL_ADMIN_PERM
,
5340 .cmd
= NL80211_CMD_ACTION
,
5341 .doit
= nl80211_action
,
5342 .policy
= nl80211_policy
,
5343 .flags
= GENL_ADMIN_PERM
,
5346 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
5347 .doit
= nl80211_set_power_save
,
5348 .policy
= nl80211_policy
,
5349 .flags
= GENL_ADMIN_PERM
,
5352 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
5353 .doit
= nl80211_get_power_save
,
5354 .policy
= nl80211_policy
,
5355 /* can be retrieved by unprivileged users */
5358 .cmd
= NL80211_CMD_SET_CQM
,
5359 .doit
= nl80211_set_cqm
,
5360 .policy
= nl80211_policy
,
5361 .flags
= GENL_ADMIN_PERM
,
5364 .cmd
= NL80211_CMD_SET_CHANNEL
,
5365 .doit
= nl80211_set_channel
,
5366 .policy
= nl80211_policy
,
5367 .flags
= GENL_ADMIN_PERM
,
5371 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
5375 /* multicast groups */
5376 static struct genl_multicast_group nl80211_config_mcgrp
= {
5379 static struct genl_multicast_group nl80211_scan_mcgrp
= {
5382 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
5383 .name
= "regulatory",
5386 /* notification functions */
5388 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
5390 struct sk_buff
*msg
;
5392 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5396 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
5401 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5402 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
5405 static int nl80211_add_scan_req(struct sk_buff
*msg
,
5406 struct cfg80211_registered_device
*rdev
)
5408 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
5409 struct nlattr
*nest
;
5412 ASSERT_RDEV_LOCK(rdev
);
5417 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
5419 goto nla_put_failure
;
5420 for (i
= 0; i
< req
->n_ssids
; i
++)
5421 NLA_PUT(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
);
5422 nla_nest_end(msg
, nest
);
5424 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
5426 goto nla_put_failure
;
5427 for (i
= 0; i
< req
->n_channels
; i
++)
5428 NLA_PUT_U32(msg
, i
, req
->channels
[i
]->center_freq
);
5429 nla_nest_end(msg
, nest
);
5432 NLA_PUT(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
);
5439 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
5440 struct cfg80211_registered_device
*rdev
,
5441 struct net_device
*netdev
,
5442 u32 pid
, u32 seq
, int flags
,
5447 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
5451 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5452 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5454 /* ignore errors and send incomplete event anyway */
5455 nl80211_add_scan_req(msg
, rdev
);
5457 return genlmsg_end(msg
, hdr
);
5460 genlmsg_cancel(msg
, hdr
);
5464 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
5465 struct net_device
*netdev
)
5467 struct sk_buff
*msg
;
5469 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
5473 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5474 NL80211_CMD_TRIGGER_SCAN
) < 0) {
5479 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5480 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5483 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
5484 struct net_device
*netdev
)
5486 struct sk_buff
*msg
;
5488 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5492 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5493 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
5498 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5499 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5502 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
5503 struct net_device
*netdev
)
5505 struct sk_buff
*msg
;
5507 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5511 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5512 NL80211_CMD_SCAN_ABORTED
) < 0) {
5517 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5518 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5522 * This can happen on global regulatory changes or device specific settings
5523 * based on custom world regulatory domains.
5525 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
5527 struct sk_buff
*msg
;
5530 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5534 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
5540 /* Userspace can always count this one always being set */
5541 NLA_PUT_U8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
);
5543 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0')
5544 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5545 NL80211_REGDOM_TYPE_WORLD
);
5546 else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9')
5547 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5548 NL80211_REGDOM_TYPE_CUSTOM_WORLD
);
5549 else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
5551 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5552 NL80211_REGDOM_TYPE_INTERSECTION
);
5554 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5555 NL80211_REGDOM_TYPE_COUNTRY
);
5556 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, request
->alpha2
);
5559 if (wiphy_idx_valid(request
->wiphy_idx
))
5560 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
);
5562 if (genlmsg_end(msg
, hdr
) < 0) {
5568 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
5575 genlmsg_cancel(msg
, hdr
);
5579 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
5580 struct net_device
*netdev
,
5581 const u8
*buf
, size_t len
,
5582 enum nl80211_commands cmd
, gfp_t gfp
)
5584 struct sk_buff
*msg
;
5587 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5591 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
5597 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5598 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5599 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
5601 if (genlmsg_end(msg
, hdr
) < 0) {
5606 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5607 nl80211_mlme_mcgrp
.id
, gfp
);
5611 genlmsg_cancel(msg
, hdr
);
5615 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
5616 struct net_device
*netdev
, const u8
*buf
,
5617 size_t len
, gfp_t gfp
)
5619 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5620 NL80211_CMD_AUTHENTICATE
, gfp
);
5623 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
5624 struct net_device
*netdev
, const u8
*buf
,
5625 size_t len
, gfp_t gfp
)
5627 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5628 NL80211_CMD_ASSOCIATE
, gfp
);
5631 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
5632 struct net_device
*netdev
, const u8
*buf
,
5633 size_t len
, gfp_t gfp
)
5635 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5636 NL80211_CMD_DEAUTHENTICATE
, gfp
);
5639 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
5640 struct net_device
*netdev
, const u8
*buf
,
5641 size_t len
, gfp_t gfp
)
5643 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5644 NL80211_CMD_DISASSOCIATE
, gfp
);
5647 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
5648 struct net_device
*netdev
, int cmd
,
5649 const u8
*addr
, gfp_t gfp
)
5651 struct sk_buff
*msg
;
5654 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5658 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
5664 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5665 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5666 NLA_PUT_FLAG(msg
, NL80211_ATTR_TIMED_OUT
);
5667 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5669 if (genlmsg_end(msg
, hdr
) < 0) {
5674 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5675 nl80211_mlme_mcgrp
.id
, gfp
);
5679 genlmsg_cancel(msg
, hdr
);
5683 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
5684 struct net_device
*netdev
, const u8
*addr
,
5687 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
5691 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
5692 struct net_device
*netdev
, const u8
*addr
,
5695 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
5699 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
5700 struct net_device
*netdev
, const u8
*bssid
,
5701 const u8
*req_ie
, size_t req_ie_len
,
5702 const u8
*resp_ie
, size_t resp_ie_len
,
5703 u16 status
, gfp_t gfp
)
5705 struct sk_buff
*msg
;
5708 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
5712 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
5718 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5719 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5721 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
5722 NLA_PUT_U16(msg
, NL80211_ATTR_STATUS_CODE
, status
);
5724 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
5726 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
5728 if (genlmsg_end(msg
, hdr
) < 0) {
5733 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5734 nl80211_mlme_mcgrp
.id
, gfp
);
5738 genlmsg_cancel(msg
, hdr
);
5743 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
5744 struct net_device
*netdev
, const u8
*bssid
,
5745 const u8
*req_ie
, size_t req_ie_len
,
5746 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
5748 struct sk_buff
*msg
;
5751 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
5755 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
5761 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5762 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5763 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
5765 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
5767 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
5769 if (genlmsg_end(msg
, hdr
) < 0) {
5774 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5775 nl80211_mlme_mcgrp
.id
, gfp
);
5779 genlmsg_cancel(msg
, hdr
);
5784 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
5785 struct net_device
*netdev
, u16 reason
,
5786 const u8
*ie
, size_t ie_len
, bool from_ap
)
5788 struct sk_buff
*msg
;
5791 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
5795 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
5801 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5802 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5803 if (from_ap
&& reason
)
5804 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason
);
5806 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
);
5808 NLA_PUT(msg
, NL80211_ATTR_IE
, ie_len
, ie
);
5810 if (genlmsg_end(msg
, hdr
) < 0) {
5815 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5816 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
5820 genlmsg_cancel(msg
, hdr
);
5825 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
5826 struct net_device
*netdev
, const u8
*bssid
,
5829 struct sk_buff
*msg
;
5832 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5836 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
5842 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5843 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5844 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
5846 if (genlmsg_end(msg
, hdr
) < 0) {
5851 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5852 nl80211_mlme_mcgrp
.id
, gfp
);
5856 genlmsg_cancel(msg
, hdr
);
5860 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
5861 struct net_device
*netdev
, const u8
*addr
,
5862 enum nl80211_key_type key_type
, int key_id
,
5863 const u8
*tsc
, gfp_t gfp
)
5865 struct sk_buff
*msg
;
5868 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5872 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
5878 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5879 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5881 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5882 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
);
5883 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_id
);
5885 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
);
5887 if (genlmsg_end(msg
, hdr
) < 0) {
5892 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5893 nl80211_mlme_mcgrp
.id
, gfp
);
5897 genlmsg_cancel(msg
, hdr
);
5901 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
5902 struct ieee80211_channel
*channel_before
,
5903 struct ieee80211_channel
*channel_after
)
5905 struct sk_buff
*msg
;
5907 struct nlattr
*nl_freq
;
5909 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
5913 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
5920 * Since we are applying the beacon hint to a wiphy we know its
5921 * wiphy_idx is valid
5923 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
));
5926 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
5928 goto nla_put_failure
;
5929 if (nl80211_msg_put_channel(msg
, channel_before
))
5930 goto nla_put_failure
;
5931 nla_nest_end(msg
, nl_freq
);
5934 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
5936 goto nla_put_failure
;
5937 if (nl80211_msg_put_channel(msg
, channel_after
))
5938 goto nla_put_failure
;
5939 nla_nest_end(msg
, nl_freq
);
5941 if (genlmsg_end(msg
, hdr
) < 0) {
5947 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
5954 genlmsg_cancel(msg
, hdr
);
5958 static void nl80211_send_remain_on_chan_event(
5959 int cmd
, struct cfg80211_registered_device
*rdev
,
5960 struct net_device
*netdev
, u64 cookie
,
5961 struct ieee80211_channel
*chan
,
5962 enum nl80211_channel_type channel_type
,
5963 unsigned int duration
, gfp_t gfp
)
5965 struct sk_buff
*msg
;
5968 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5972 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
5978 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5979 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5980 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
);
5981 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, channel_type
);
5982 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
5984 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
)
5985 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, duration
);
5987 if (genlmsg_end(msg
, hdr
) < 0) {
5992 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5993 nl80211_mlme_mcgrp
.id
, gfp
);
5997 genlmsg_cancel(msg
, hdr
);
6001 void nl80211_send_remain_on_channel(struct cfg80211_registered_device
*rdev
,
6002 struct net_device
*netdev
, u64 cookie
,
6003 struct ieee80211_channel
*chan
,
6004 enum nl80211_channel_type channel_type
,
6005 unsigned int duration
, gfp_t gfp
)
6007 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
6008 rdev
, netdev
, cookie
, chan
,
6009 channel_type
, duration
, gfp
);
6012 void nl80211_send_remain_on_channel_cancel(
6013 struct cfg80211_registered_device
*rdev
, struct net_device
*netdev
,
6014 u64 cookie
, struct ieee80211_channel
*chan
,
6015 enum nl80211_channel_type channel_type
, gfp_t gfp
)
6017 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
6018 rdev
, netdev
, cookie
, chan
,
6019 channel_type
, 0, gfp
);
6022 void nl80211_send_sta_event(struct cfg80211_registered_device
*rdev
,
6023 struct net_device
*dev
, const u8
*mac_addr
,
6024 struct station_info
*sinfo
, gfp_t gfp
)
6026 struct sk_buff
*msg
;
6028 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6032 if (nl80211_send_station(msg
, 0, 0, 0, dev
, mac_addr
, sinfo
) < 0) {
6037 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6038 nl80211_mlme_mcgrp
.id
, gfp
);
6041 int nl80211_send_action(struct cfg80211_registered_device
*rdev
,
6042 struct net_device
*netdev
, u32 nlpid
,
6043 int freq
, const u8
*buf
, size_t len
, gfp_t gfp
)
6045 struct sk_buff
*msg
;
6049 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6053 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ACTION
);
6059 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6060 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6061 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
6062 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
6064 err
= genlmsg_end(msg
, hdr
);
6070 err
= genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
6076 genlmsg_cancel(msg
, hdr
);
6081 void nl80211_send_action_tx_status(struct cfg80211_registered_device
*rdev
,
6082 struct net_device
*netdev
, u64 cookie
,
6083 const u8
*buf
, size_t len
, bool ack
,
6086 struct sk_buff
*msg
;
6089 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6093 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ACTION_TX_STATUS
);
6099 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6100 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6101 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
6102 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
6104 NLA_PUT_FLAG(msg
, NL80211_ATTR_ACK
);
6106 if (genlmsg_end(msg
, hdr
) < 0) {
6111 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
6115 genlmsg_cancel(msg
, hdr
);
6120 nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device
*rdev
,
6121 struct net_device
*netdev
,
6122 enum nl80211_cqm_rssi_threshold_event rssi_event
,
6125 struct sk_buff
*msg
;
6126 struct nlattr
*pinfoattr
;
6129 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6133 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
6139 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6140 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6142 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
6144 goto nla_put_failure
;
6146 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
6149 nla_nest_end(msg
, pinfoattr
);
6151 if (genlmsg_end(msg
, hdr
) < 0) {
6156 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6157 nl80211_mlme_mcgrp
.id
, gfp
);
6161 genlmsg_cancel(msg
, hdr
);
6165 static int nl80211_netlink_notify(struct notifier_block
* nb
,
6166 unsigned long state
,
6169 struct netlink_notify
*notify
= _notify
;
6170 struct cfg80211_registered_device
*rdev
;
6171 struct wireless_dev
*wdev
;
6173 if (state
!= NETLINK_URELEASE
)
6178 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
)
6179 list_for_each_entry_rcu(wdev
, &rdev
->netdev_list
, list
)
6180 cfg80211_mlme_unregister_actions(wdev
, notify
->pid
);
6187 static struct notifier_block nl80211_netlink_notifier
= {
6188 .notifier_call
= nl80211_netlink_notify
,
6191 /* initialisation/exit functions */
6193 int nl80211_init(void)
6197 err
= genl_register_family_with_ops(&nl80211_fam
,
6198 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
6202 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
6206 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
6210 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
6214 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
6218 #ifdef CONFIG_NL80211_TESTMODE
6219 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
6224 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
6230 genl_unregister_family(&nl80211_fam
);
6234 void nl80211_exit(void)
6236 netlink_unregister_notifier(&nl80211_netlink_notifier
);
6237 genl_unregister_family(&nl80211_fam
);