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
);
769 cfg80211_unlock_rdev(rdev
);
776 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
778 struct cfg80211_registered_device
*rdev
;
779 struct net_device
*netdev
= NULL
;
780 struct wireless_dev
*wdev
;
781 int result
, rem_txq_params
= 0;
782 struct nlattr
*nl_txq_params
;
784 u8 retry_short
= 0, retry_long
= 0;
785 u32 frag_threshold
= 0, rts_threshold
= 0;
786 u8 coverage_class
= 0;
791 * Try to find the wiphy and netdev. Normally this
792 * function shouldn't need the netdev, but this is
793 * done for backward compatibility -- previously
794 * setting the channel was done per wiphy, but now
795 * it is per netdev. Previous userland like hostapd
796 * also passed a netdev to set_wiphy, so that it is
797 * possible to let that go to the right netdev!
799 mutex_lock(&cfg80211_mutex
);
801 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
802 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
804 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
805 if (netdev
&& netdev
->ieee80211_ptr
) {
806 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
807 mutex_lock(&rdev
->mtx
);
813 rdev
= __cfg80211_rdev_from_info(info
);
815 mutex_unlock(&cfg80211_mutex
);
816 result
= PTR_ERR(rdev
);
823 mutex_lock(&rdev
->mtx
);
824 } else if (netif_running(netdev
) &&
825 nl80211_can_set_dev_channel(netdev
->ieee80211_ptr
))
826 wdev
= netdev
->ieee80211_ptr
;
831 * end workaround code, by now the rdev is available
832 * and locked, and wdev may or may not be NULL.
835 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
836 result
= cfg80211_dev_rename(
837 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
839 mutex_unlock(&cfg80211_mutex
);
844 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
845 struct ieee80211_txq_params txq_params
;
846 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
848 if (!rdev
->ops
->set_txq_params
) {
849 result
= -EOPNOTSUPP
;
853 nla_for_each_nested(nl_txq_params
,
854 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
856 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
857 nla_data(nl_txq_params
),
858 nla_len(nl_txq_params
),
860 result
= parse_txq_params(tb
, &txq_params
);
864 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
871 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
872 result
= __nl80211_set_channel(rdev
, wdev
, info
);
877 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
878 enum nl80211_tx_power_setting type
;
881 if (!rdev
->ops
->set_tx_power
) {
882 result
= -EOPNOTSUPP
;
886 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
887 type
= nla_get_u32(info
->attrs
[idx
]);
889 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
890 (type
!= NL80211_TX_POWER_AUTOMATIC
)) {
895 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
896 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
897 mbm
= nla_get_u32(info
->attrs
[idx
]);
900 result
= rdev
->ops
->set_tx_power(&rdev
->wiphy
, type
, mbm
);
907 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
908 retry_short
= nla_get_u8(
909 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
910 if (retry_short
== 0) {
914 changed
|= WIPHY_PARAM_RETRY_SHORT
;
917 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
918 retry_long
= nla_get_u8(
919 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
920 if (retry_long
== 0) {
924 changed
|= WIPHY_PARAM_RETRY_LONG
;
927 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
928 frag_threshold
= nla_get_u32(
929 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
930 if (frag_threshold
< 256) {
934 if (frag_threshold
!= (u32
) -1) {
936 * Fragments (apart from the last one) are required to
937 * have even length. Make the fragmentation code
938 * simpler by stripping LSB should someone try to use
939 * odd threshold value.
941 frag_threshold
&= ~0x1;
943 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
946 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
947 rts_threshold
= nla_get_u32(
948 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
949 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
952 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
953 coverage_class
= nla_get_u8(
954 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
955 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
959 u8 old_retry_short
, old_retry_long
;
960 u32 old_frag_threshold
, old_rts_threshold
;
961 u8 old_coverage_class
;
963 if (!rdev
->ops
->set_wiphy_params
) {
964 result
= -EOPNOTSUPP
;
968 old_retry_short
= rdev
->wiphy
.retry_short
;
969 old_retry_long
= rdev
->wiphy
.retry_long
;
970 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
971 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
972 old_coverage_class
= rdev
->wiphy
.coverage_class
;
974 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
975 rdev
->wiphy
.retry_short
= retry_short
;
976 if (changed
& WIPHY_PARAM_RETRY_LONG
)
977 rdev
->wiphy
.retry_long
= retry_long
;
978 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
979 rdev
->wiphy
.frag_threshold
= frag_threshold
;
980 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
981 rdev
->wiphy
.rts_threshold
= rts_threshold
;
982 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
983 rdev
->wiphy
.coverage_class
= coverage_class
;
985 result
= rdev
->ops
->set_wiphy_params(&rdev
->wiphy
, changed
);
987 rdev
->wiphy
.retry_short
= old_retry_short
;
988 rdev
->wiphy
.retry_long
= old_retry_long
;
989 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
990 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
991 rdev
->wiphy
.coverage_class
= old_coverage_class
;
996 mutex_unlock(&rdev
->mtx
);
1005 static int nl80211_send_iface(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
1006 struct cfg80211_registered_device
*rdev
,
1007 struct net_device
*dev
)
1011 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
1015 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1016 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
1017 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, dev
->name
);
1018 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, dev
->ieee80211_ptr
->iftype
);
1020 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
1021 rdev
->devlist_generation
^
1022 (cfg80211_rdev_list_generation
<< 2));
1024 return genlmsg_end(msg
, hdr
);
1027 genlmsg_cancel(msg
, hdr
);
1031 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1035 int wp_start
= cb
->args
[0];
1036 int if_start
= cb
->args
[1];
1037 struct cfg80211_registered_device
*rdev
;
1038 struct wireless_dev
*wdev
;
1040 mutex_lock(&cfg80211_mutex
);
1041 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
1042 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
1044 if (wp_idx
< wp_start
) {
1050 mutex_lock(&rdev
->devlist_mtx
);
1051 list_for_each_entry(wdev
, &rdev
->netdev_list
, list
) {
1052 if (if_idx
< if_start
) {
1056 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).pid
,
1057 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1058 rdev
, wdev
->netdev
) < 0) {
1059 mutex_unlock(&rdev
->devlist_mtx
);
1064 mutex_unlock(&rdev
->devlist_mtx
);
1069 mutex_unlock(&cfg80211_mutex
);
1071 cb
->args
[0] = wp_idx
;
1072 cb
->args
[1] = if_idx
;
1077 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1079 struct sk_buff
*msg
;
1080 struct cfg80211_registered_device
*dev
;
1081 struct net_device
*netdev
;
1084 err
= get_rdev_dev_by_info_ifindex(info
, &dev
, &netdev
);
1088 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1092 if (nl80211_send_iface(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1097 cfg80211_unlock_rdev(dev
);
1099 return genlmsg_reply(msg
, info
);
1105 cfg80211_unlock_rdev(dev
);
1109 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
1110 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
1111 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
1112 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
1113 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
1114 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
1117 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
1119 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
1127 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
1128 nla
, mntr_flags_policy
))
1131 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
1133 *mntrflags
|= (1<<flag
);
1138 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
1139 struct net_device
*netdev
, u8 use_4addr
,
1140 enum nl80211_iftype iftype
)
1143 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
1149 case NL80211_IFTYPE_AP_VLAN
:
1150 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
1153 case NL80211_IFTYPE_STATION
:
1154 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
1164 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1166 struct cfg80211_registered_device
*rdev
;
1167 struct vif_params params
;
1169 enum nl80211_iftype otype
, ntype
;
1170 struct net_device
*dev
;
1171 u32 _flags
, *flags
= NULL
;
1172 bool change
= false;
1174 memset(¶ms
, 0, sizeof(params
));
1178 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1182 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
1184 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1185 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1188 if (ntype
> NL80211_IFTYPE_MAX
) {
1194 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1195 if (ntype
!= NL80211_IFTYPE_MESH_POINT
) {
1199 params
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1200 params
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1204 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1205 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1207 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
1211 params
.use_4addr
= -1;
1214 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
1215 if (ntype
!= NL80211_IFTYPE_MONITOR
) {
1219 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
1229 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
1233 if (!err
&& params
.use_4addr
!= -1)
1234 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
1238 cfg80211_unlock_rdev(rdev
);
1244 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1246 struct cfg80211_registered_device
*rdev
;
1247 struct vif_params params
;
1249 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
1252 memset(¶ms
, 0, sizeof(params
));
1254 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
1257 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1258 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1259 if (type
> NL80211_IFTYPE_MAX
)
1265 rdev
= cfg80211_get_dev_from_info(info
);
1267 err
= PTR_ERR(rdev
);
1271 if (!rdev
->ops
->add_virtual_intf
||
1272 !(rdev
->wiphy
.interface_modes
& (1 << type
))) {
1277 if (type
== NL80211_IFTYPE_MESH_POINT
&&
1278 info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1279 params
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1280 params
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1283 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1284 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1285 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
1290 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
1291 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
1293 err
= rdev
->ops
->add_virtual_intf(&rdev
->wiphy
,
1294 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
1295 type
, err
? NULL
: &flags
, ¶ms
);
1298 cfg80211_unlock_rdev(rdev
);
1304 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1306 struct cfg80211_registered_device
*rdev
;
1308 struct net_device
*dev
;
1312 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1316 if (!rdev
->ops
->del_virtual_intf
) {
1321 err
= rdev
->ops
->del_virtual_intf(&rdev
->wiphy
, dev
);
1324 cfg80211_unlock_rdev(rdev
);
1331 struct get_key_cookie
{
1332 struct sk_buff
*msg
;
1337 static void get_key_callback(void *c
, struct key_params
*params
)
1340 struct get_key_cookie
*cookie
= c
;
1343 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
1344 params
->key_len
, params
->key
);
1347 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
1348 params
->seq_len
, params
->seq
);
1351 NLA_PUT_U32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
1354 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
1356 goto nla_put_failure
;
1359 NLA_PUT(cookie
->msg
, NL80211_KEY_DATA
,
1360 params
->key_len
, params
->key
);
1363 NLA_PUT(cookie
->msg
, NL80211_KEY_SEQ
,
1364 params
->seq_len
, params
->seq
);
1367 NLA_PUT_U32(cookie
->msg
, NL80211_KEY_CIPHER
,
1370 NLA_PUT_U8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
);
1372 nla_nest_end(cookie
->msg
, key
);
1379 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
1381 struct cfg80211_registered_device
*rdev
;
1383 struct net_device
*dev
;
1385 u8
*mac_addr
= NULL
;
1386 struct get_key_cookie cookie
= {
1390 struct sk_buff
*msg
;
1392 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
1393 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1398 if (info
->attrs
[NL80211_ATTR_MAC
])
1399 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1403 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1407 if (!rdev
->ops
->get_key
) {
1412 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1418 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1419 NL80211_CMD_NEW_KEY
);
1427 cookie
.idx
= key_idx
;
1429 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1430 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
1432 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1434 err
= rdev
->ops
->get_key(&rdev
->wiphy
, dev
, key_idx
, mac_addr
,
1435 &cookie
, get_key_callback
);
1441 goto nla_put_failure
;
1443 genlmsg_end(msg
, hdr
);
1444 err
= genlmsg_reply(msg
, info
);
1452 cfg80211_unlock_rdev(rdev
);
1460 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
1462 struct cfg80211_registered_device
*rdev
;
1463 struct key_parse key
;
1465 struct net_device
*dev
;
1466 int (*func
)(struct wiphy
*wiphy
, struct net_device
*netdev
,
1469 err
= nl80211_parse_key(info
, &key
);
1476 /* only support setting default key */
1477 if (!key
.def
&& !key
.defmgmt
)
1482 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1487 func
= rdev
->ops
->set_default_key
;
1489 func
= rdev
->ops
->set_default_mgmt_key
;
1496 wdev_lock(dev
->ieee80211_ptr
);
1497 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1499 err
= func(&rdev
->wiphy
, dev
, key
.idx
);
1501 #ifdef CONFIG_CFG80211_WEXT
1503 if (func
== rdev
->ops
->set_default_key
)
1504 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
1506 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
1509 wdev_unlock(dev
->ieee80211_ptr
);
1512 cfg80211_unlock_rdev(rdev
);
1521 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
1523 struct cfg80211_registered_device
*rdev
;
1525 struct net_device
*dev
;
1526 struct key_parse key
;
1527 u8
*mac_addr
= NULL
;
1529 err
= nl80211_parse_key(info
, &key
);
1536 if (info
->attrs
[NL80211_ATTR_MAC
])
1537 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1541 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1545 if (!rdev
->ops
->add_key
) {
1550 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
, mac_addr
)) {
1555 wdev_lock(dev
->ieee80211_ptr
);
1556 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1558 err
= rdev
->ops
->add_key(&rdev
->wiphy
, dev
, key
.idx
,
1560 wdev_unlock(dev
->ieee80211_ptr
);
1563 cfg80211_unlock_rdev(rdev
);
1571 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
1573 struct cfg80211_registered_device
*rdev
;
1575 struct net_device
*dev
;
1576 u8
*mac_addr
= NULL
;
1577 struct key_parse key
;
1579 err
= nl80211_parse_key(info
, &key
);
1583 if (info
->attrs
[NL80211_ATTR_MAC
])
1584 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1588 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1592 if (!rdev
->ops
->del_key
) {
1597 wdev_lock(dev
->ieee80211_ptr
);
1598 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1600 err
= rdev
->ops
->del_key(&rdev
->wiphy
, dev
, key
.idx
, mac_addr
);
1602 #ifdef CONFIG_CFG80211_WEXT
1604 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
1605 dev
->ieee80211_ptr
->wext
.default_key
= -1;
1606 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
1607 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
1610 wdev_unlock(dev
->ieee80211_ptr
);
1613 cfg80211_unlock_rdev(rdev
);
1622 static int nl80211_addset_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1624 int (*call
)(struct wiphy
*wiphy
, struct net_device
*dev
,
1625 struct beacon_parameters
*info
);
1626 struct cfg80211_registered_device
*rdev
;
1628 struct net_device
*dev
;
1629 struct beacon_parameters params
;
1632 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]))
1637 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1641 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1646 switch (info
->genlhdr
->cmd
) {
1647 case NL80211_CMD_NEW_BEACON
:
1648 /* these are required for NEW_BEACON */
1649 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
1650 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
1651 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1656 call
= rdev
->ops
->add_beacon
;
1658 case NL80211_CMD_SET_BEACON
:
1659 call
= rdev
->ops
->set_beacon
;
1672 memset(¶ms
, 0, sizeof(params
));
1674 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
1676 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
1680 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
1681 params
.dtim_period
=
1682 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
1686 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1687 params
.head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1689 nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1693 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
1694 params
.tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1696 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1705 err
= call(&rdev
->wiphy
, dev
, ¶ms
);
1708 cfg80211_unlock_rdev(rdev
);
1716 static int nl80211_del_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1718 struct cfg80211_registered_device
*rdev
;
1720 struct net_device
*dev
;
1724 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1728 if (!rdev
->ops
->del_beacon
) {
1733 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1737 err
= rdev
->ops
->del_beacon(&rdev
->wiphy
, dev
);
1740 cfg80211_unlock_rdev(rdev
);
1748 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
1749 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
1750 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
1751 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
1752 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
1755 static int parse_station_flags(struct genl_info
*info
,
1756 struct station_parameters
*params
)
1758 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
1763 * Try parsing the new attribute first so userspace
1764 * can specify both for older kernels.
1766 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
1768 struct nl80211_sta_flag_update
*sta_flags
;
1770 sta_flags
= nla_data(nla
);
1771 params
->sta_flags_mask
= sta_flags
->mask
;
1772 params
->sta_flags_set
= sta_flags
->set
;
1773 if ((params
->sta_flags_mask
|
1774 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
1779 /* if present, parse the old attribute */
1781 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
1785 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
1786 nla
, sta_flags_policy
))
1789 params
->sta_flags_mask
= (1 << __NL80211_STA_FLAG_AFTER_LAST
) - 1;
1790 params
->sta_flags_mask
&= ~1;
1792 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++)
1794 params
->sta_flags_set
|= (1<<flag
);
1799 static int nl80211_send_station(struct sk_buff
*msg
, u32 pid
, u32 seq
,
1800 int flags
, struct net_device
*dev
,
1801 const u8
*mac_addr
, struct station_info
*sinfo
)
1804 struct nlattr
*sinfoattr
, *txrate
;
1807 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
1811 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1812 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1814 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
);
1816 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
1818 goto nla_put_failure
;
1819 if (sinfo
->filled
& STATION_INFO_INACTIVE_TIME
)
1820 NLA_PUT_U32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
1821 sinfo
->inactive_time
);
1822 if (sinfo
->filled
& STATION_INFO_RX_BYTES
)
1823 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_BYTES
,
1825 if (sinfo
->filled
& STATION_INFO_TX_BYTES
)
1826 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_BYTES
,
1828 if (sinfo
->filled
& STATION_INFO_LLID
)
1829 NLA_PUT_U16(msg
, NL80211_STA_INFO_LLID
,
1831 if (sinfo
->filled
& STATION_INFO_PLID
)
1832 NLA_PUT_U16(msg
, NL80211_STA_INFO_PLID
,
1834 if (sinfo
->filled
& STATION_INFO_PLINK_STATE
)
1835 NLA_PUT_U8(msg
, NL80211_STA_INFO_PLINK_STATE
,
1836 sinfo
->plink_state
);
1837 if (sinfo
->filled
& STATION_INFO_SIGNAL
)
1838 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL
,
1840 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
1841 txrate
= nla_nest_start(msg
, NL80211_STA_INFO_TX_BITRATE
);
1843 goto nla_put_failure
;
1845 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
1846 bitrate
= cfg80211_calculate_bitrate(&sinfo
->txrate
);
1848 NLA_PUT_U16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate
);
1850 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_MCS
)
1851 NLA_PUT_U8(msg
, NL80211_RATE_INFO_MCS
,
1853 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
)
1854 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
);
1855 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_SHORT_GI
)
1856 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_SHORT_GI
);
1858 nla_nest_end(msg
, txrate
);
1860 if (sinfo
->filled
& STATION_INFO_RX_PACKETS
)
1861 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_PACKETS
,
1863 if (sinfo
->filled
& STATION_INFO_TX_PACKETS
)
1864 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_PACKETS
,
1866 nla_nest_end(msg
, sinfoattr
);
1868 return genlmsg_end(msg
, hdr
);
1871 genlmsg_cancel(msg
, hdr
);
1875 static int nl80211_dump_station(struct sk_buff
*skb
,
1876 struct netlink_callback
*cb
)
1878 struct station_info sinfo
;
1879 struct cfg80211_registered_device
*dev
;
1880 struct net_device
*netdev
;
1881 u8 mac_addr
[ETH_ALEN
];
1882 int ifidx
= cb
->args
[0];
1883 int sta_idx
= cb
->args
[1];
1887 ifidx
= nl80211_get_ifidx(cb
);
1893 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
1899 dev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
1905 if (!dev
->ops
->dump_station
) {
1911 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
1918 if (nl80211_send_station(skb
,
1919 NETLINK_CB(cb
->skb
).pid
,
1920 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1930 cb
->args
[1] = sta_idx
;
1933 cfg80211_unlock_rdev(dev
);
1940 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
1942 struct cfg80211_registered_device
*rdev
;
1944 struct net_device
*dev
;
1945 struct station_info sinfo
;
1946 struct sk_buff
*msg
;
1947 u8
*mac_addr
= NULL
;
1949 memset(&sinfo
, 0, sizeof(sinfo
));
1951 if (!info
->attrs
[NL80211_ATTR_MAC
])
1954 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1958 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1962 if (!rdev
->ops
->get_station
) {
1967 err
= rdev
->ops
->get_station(&rdev
->wiphy
, dev
, mac_addr
, &sinfo
);
1971 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1975 if (nl80211_send_station(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1976 dev
, mac_addr
, &sinfo
) < 0)
1979 err
= genlmsg_reply(msg
, info
);
1985 cfg80211_unlock_rdev(rdev
);
1994 * Get vlan interface making sure it is running and on the right wiphy.
1996 static int get_vlan(struct genl_info
*info
,
1997 struct cfg80211_registered_device
*rdev
,
1998 struct net_device
**vlan
)
2000 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
2004 *vlan
= dev_get_by_index(genl_info_net(info
),
2005 nla_get_u32(vlanattr
));
2008 if (!(*vlan
)->ieee80211_ptr
)
2010 if ((*vlan
)->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
)
2012 if (!netif_running(*vlan
))
2018 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
2020 struct cfg80211_registered_device
*rdev
;
2022 struct net_device
*dev
;
2023 struct station_parameters params
;
2024 u8
*mac_addr
= NULL
;
2026 memset(¶ms
, 0, sizeof(params
));
2028 params
.listen_interval
= -1;
2030 if (info
->attrs
[NL80211_ATTR_STA_AID
])
2033 if (!info
->attrs
[NL80211_ATTR_MAC
])
2036 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2038 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
2039 params
.supported_rates
=
2040 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2041 params
.supported_rates_len
=
2042 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2045 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2046 params
.listen_interval
=
2047 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2049 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2051 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2053 if (parse_station_flags(info
, ¶ms
))
2056 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
2057 params
.plink_action
=
2058 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
2062 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2066 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
2070 /* validate settings */
2073 switch (dev
->ieee80211_ptr
->iftype
) {
2074 case NL80211_IFTYPE_AP
:
2075 case NL80211_IFTYPE_AP_VLAN
:
2076 /* disallow mesh-specific things */
2077 if (params
.plink_action
)
2080 case NL80211_IFTYPE_STATION
:
2081 /* disallow everything but AUTHORIZED flag */
2082 if (params
.plink_action
)
2086 if (params
.supported_rates
)
2090 if (params
.listen_interval
>= 0)
2092 if (params
.sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
2095 case NL80211_IFTYPE_MESH_POINT
:
2096 /* disallow things mesh doesn't support */
2101 if (params
.listen_interval
>= 0)
2103 if (params
.supported_rates
)
2105 if (params
.sta_flags_mask
)
2115 if (!rdev
->ops
->change_station
) {
2120 err
= rdev
->ops
->change_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2124 dev_put(params
.vlan
);
2125 cfg80211_unlock_rdev(rdev
);
2133 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
2135 struct cfg80211_registered_device
*rdev
;
2137 struct net_device
*dev
;
2138 struct station_parameters params
;
2139 u8
*mac_addr
= NULL
;
2141 memset(¶ms
, 0, sizeof(params
));
2143 if (!info
->attrs
[NL80211_ATTR_MAC
])
2146 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2149 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
2152 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
2155 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2156 params
.supported_rates
=
2157 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2158 params
.supported_rates_len
=
2159 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2160 params
.listen_interval
=
2161 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2163 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
2164 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
2167 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2169 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2171 if (parse_station_flags(info
, ¶ms
))
2176 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2180 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2181 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
) {
2186 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
2190 /* validate settings */
2193 if (!rdev
->ops
->add_station
) {
2198 if (!netif_running(dev
)) {
2203 err
= rdev
->ops
->add_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2207 dev_put(params
.vlan
);
2208 cfg80211_unlock_rdev(rdev
);
2216 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
2218 struct cfg80211_registered_device
*rdev
;
2220 struct net_device
*dev
;
2221 u8
*mac_addr
= NULL
;
2223 if (info
->attrs
[NL80211_ATTR_MAC
])
2224 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2228 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2232 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2233 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
2234 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2239 if (!rdev
->ops
->del_station
) {
2244 err
= rdev
->ops
->del_station(&rdev
->wiphy
, dev
, mac_addr
);
2247 cfg80211_unlock_rdev(rdev
);
2255 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2256 int flags
, struct net_device
*dev
,
2257 u8
*dst
, u8
*next_hop
,
2258 struct mpath_info
*pinfo
)
2261 struct nlattr
*pinfoattr
;
2263 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2267 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2268 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
2269 NLA_PUT(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
);
2271 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
);
2273 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
2275 goto nla_put_failure
;
2276 if (pinfo
->filled
& MPATH_INFO_FRAME_QLEN
)
2277 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
2279 if (pinfo
->filled
& MPATH_INFO_SN
)
2280 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_SN
,
2282 if (pinfo
->filled
& MPATH_INFO_METRIC
)
2283 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_METRIC
,
2285 if (pinfo
->filled
& MPATH_INFO_EXPTIME
)
2286 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_EXPTIME
,
2288 if (pinfo
->filled
& MPATH_INFO_FLAGS
)
2289 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_FLAGS
,
2291 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
)
2292 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
2293 pinfo
->discovery_timeout
);
2294 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
)
2295 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
2296 pinfo
->discovery_retries
);
2298 nla_nest_end(msg
, pinfoattr
);
2300 return genlmsg_end(msg
, hdr
);
2303 genlmsg_cancel(msg
, hdr
);
2307 static int nl80211_dump_mpath(struct sk_buff
*skb
,
2308 struct netlink_callback
*cb
)
2310 struct mpath_info pinfo
;
2311 struct cfg80211_registered_device
*dev
;
2312 struct net_device
*netdev
;
2314 u8 next_hop
[ETH_ALEN
];
2315 int ifidx
= cb
->args
[0];
2316 int path_idx
= cb
->args
[1];
2320 ifidx
= nl80211_get_ifidx(cb
);
2326 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
2332 dev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
2338 if (!dev
->ops
->dump_mpath
) {
2343 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2349 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
2350 dst
, next_hop
, &pinfo
);
2356 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).pid
,
2357 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2358 netdev
, dst
, next_hop
,
2367 cb
->args
[1] = path_idx
;
2370 cfg80211_unlock_rdev(dev
);
2377 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2379 struct cfg80211_registered_device
*rdev
;
2381 struct net_device
*dev
;
2382 struct mpath_info pinfo
;
2383 struct sk_buff
*msg
;
2385 u8 next_hop
[ETH_ALEN
];
2387 memset(&pinfo
, 0, sizeof(pinfo
));
2389 if (!info
->attrs
[NL80211_ATTR_MAC
])
2392 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2396 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2400 if (!rdev
->ops
->get_mpath
) {
2405 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2410 err
= rdev
->ops
->get_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
2414 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2418 if (nl80211_send_mpath(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2419 dev
, dst
, next_hop
, &pinfo
) < 0)
2422 err
= genlmsg_reply(msg
, info
);
2428 cfg80211_unlock_rdev(rdev
);
2436 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2438 struct cfg80211_registered_device
*rdev
;
2440 struct net_device
*dev
;
2442 u8
*next_hop
= NULL
;
2444 if (!info
->attrs
[NL80211_ATTR_MAC
])
2447 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2450 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2451 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2455 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2459 if (!rdev
->ops
->change_mpath
) {
2464 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2469 if (!netif_running(dev
)) {
2474 err
= rdev
->ops
->change_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2477 cfg80211_unlock_rdev(rdev
);
2484 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2486 struct cfg80211_registered_device
*rdev
;
2488 struct net_device
*dev
;
2490 u8
*next_hop
= NULL
;
2492 if (!info
->attrs
[NL80211_ATTR_MAC
])
2495 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2498 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2499 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2503 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2507 if (!rdev
->ops
->add_mpath
) {
2512 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2517 if (!netif_running(dev
)) {
2522 err
= rdev
->ops
->add_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2525 cfg80211_unlock_rdev(rdev
);
2533 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2535 struct cfg80211_registered_device
*rdev
;
2537 struct net_device
*dev
;
2540 if (info
->attrs
[NL80211_ATTR_MAC
])
2541 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2545 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2549 if (!rdev
->ops
->del_mpath
) {
2554 err
= rdev
->ops
->del_mpath(&rdev
->wiphy
, dev
, dst
);
2557 cfg80211_unlock_rdev(rdev
);
2565 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
2567 struct cfg80211_registered_device
*rdev
;
2569 struct net_device
*dev
;
2570 struct bss_parameters params
;
2572 memset(¶ms
, 0, sizeof(params
));
2573 /* default to not changing parameters */
2574 params
.use_cts_prot
= -1;
2575 params
.use_short_preamble
= -1;
2576 params
.use_short_slot_time
= -1;
2577 params
.ap_isolate
= -1;
2579 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
2580 params
.use_cts_prot
=
2581 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
2582 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
2583 params
.use_short_preamble
=
2584 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
2585 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
2586 params
.use_short_slot_time
=
2587 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
2588 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
2589 params
.basic_rates
=
2590 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2591 params
.basic_rates_len
=
2592 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2594 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
2595 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
2599 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2603 if (!rdev
->ops
->change_bss
) {
2608 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
2613 err
= rdev
->ops
->change_bss(&rdev
->wiphy
, dev
, ¶ms
);
2616 cfg80211_unlock_rdev(rdev
);
2624 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
2625 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
2626 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
2627 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
2628 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
2629 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
2630 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
2633 static int parse_reg_rule(struct nlattr
*tb
[],
2634 struct ieee80211_reg_rule
*reg_rule
)
2636 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
2637 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
2639 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
2641 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
2643 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
2645 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
2647 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
2650 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
2652 freq_range
->start_freq_khz
=
2653 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
2654 freq_range
->end_freq_khz
=
2655 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
2656 freq_range
->max_bandwidth_khz
=
2657 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
2659 power_rule
->max_eirp
=
2660 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
2662 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
2663 power_rule
->max_antenna_gain
=
2664 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
2669 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2675 * You should only get this when cfg80211 hasn't yet initialized
2676 * completely when built-in to the kernel right between the time
2677 * window between nl80211_init() and regulatory_init(), if that is
2680 mutex_lock(&cfg80211_mutex
);
2681 if (unlikely(!cfg80211_regdomain
)) {
2682 mutex_unlock(&cfg80211_mutex
);
2683 return -EINPROGRESS
;
2685 mutex_unlock(&cfg80211_mutex
);
2687 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2690 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2692 r
= regulatory_hint_user(data
);
2697 static int nl80211_get_mesh_params(struct sk_buff
*skb
,
2698 struct genl_info
*info
)
2700 struct cfg80211_registered_device
*rdev
;
2701 struct mesh_config cur_params
;
2703 struct net_device
*dev
;
2705 struct nlattr
*pinfoattr
;
2706 struct sk_buff
*msg
;
2710 /* Look up our device */
2711 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2715 if (!rdev
->ops
->get_mesh_params
) {
2720 /* Get the mesh params */
2721 err
= rdev
->ops
->get_mesh_params(&rdev
->wiphy
, dev
, &cur_params
);
2725 /* Draw up a netlink message to send back */
2726 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2731 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2732 NL80211_CMD_GET_MESH_PARAMS
);
2734 goto nla_put_failure
;
2735 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_PARAMS
);
2737 goto nla_put_failure
;
2738 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2739 NLA_PUT_U16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
2740 cur_params
.dot11MeshRetryTimeout
);
2741 NLA_PUT_U16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
2742 cur_params
.dot11MeshConfirmTimeout
);
2743 NLA_PUT_U16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
2744 cur_params
.dot11MeshHoldingTimeout
);
2745 NLA_PUT_U16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
2746 cur_params
.dot11MeshMaxPeerLinks
);
2747 NLA_PUT_U8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
2748 cur_params
.dot11MeshMaxRetries
);
2749 NLA_PUT_U8(msg
, NL80211_MESHCONF_TTL
,
2750 cur_params
.dot11MeshTTL
);
2751 NLA_PUT_U8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
2752 cur_params
.auto_open_plinks
);
2753 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2754 cur_params
.dot11MeshHWMPmaxPREQretries
);
2755 NLA_PUT_U32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
2756 cur_params
.path_refresh_time
);
2757 NLA_PUT_U16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2758 cur_params
.min_discovery_timeout
);
2759 NLA_PUT_U32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2760 cur_params
.dot11MeshHWMPactivePathTimeout
);
2761 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2762 cur_params
.dot11MeshHWMPpreqMinInterval
);
2763 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2764 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
);
2765 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
2766 cur_params
.dot11MeshHWMPRootMode
);
2767 nla_nest_end(msg
, pinfoattr
);
2768 genlmsg_end(msg
, hdr
);
2769 err
= genlmsg_reply(msg
, info
);
2773 genlmsg_cancel(msg
, hdr
);
2778 cfg80211_unlock_rdev(rdev
);
2786 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2788 if (table[attr_num]) {\
2789 cfg.param = nla_fn(table[attr_num]); \
2790 mask |= (1 << (attr_num - 1)); \
2794 static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
2795 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
2796 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
2797 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
2798 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
2799 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
2800 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
2801 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
2803 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
2804 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
2805 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
2806 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
2807 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
2808 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
2811 static int nl80211_set_mesh_params(struct sk_buff
*skb
, struct genl_info
*info
)
2815 struct cfg80211_registered_device
*rdev
;
2816 struct net_device
*dev
;
2817 struct mesh_config cfg
;
2818 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
2819 struct nlattr
*parent_attr
;
2821 parent_attr
= info
->attrs
[NL80211_ATTR_MESH_PARAMS
];
2824 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
2825 parent_attr
, nl80211_meshconf_params_policy
))
2830 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2834 if (!rdev
->ops
->set_mesh_params
) {
2839 /* This makes sure that there aren't more than 32 mesh config
2840 * parameters (otherwise our bitfield scheme would not work.) */
2841 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
2843 /* Fill in the params struct */
2845 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
2846 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
, nla_get_u16
);
2847 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
2848 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
, nla_get_u16
);
2849 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
2850 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
, nla_get_u16
);
2851 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
2852 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
, nla_get_u16
);
2853 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
2854 mask
, NL80211_MESHCONF_MAX_RETRIES
, nla_get_u8
);
2855 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
2856 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
2857 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
2858 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
, nla_get_u8
);
2859 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
2860 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2862 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
2863 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
, nla_get_u32
);
2864 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
2865 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2867 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
2868 mask
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2870 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
2871 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2873 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
2874 dot11MeshHWMPnetDiameterTraversalTime
,
2875 mask
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2877 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
2878 dot11MeshHWMPRootMode
, mask
,
2879 NL80211_MESHCONF_HWMP_ROOTMODE
,
2883 err
= rdev
->ops
->set_mesh_params(&rdev
->wiphy
, dev
, &cfg
, mask
);
2887 cfg80211_unlock_rdev(rdev
);
2895 #undef FILL_IN_MESH_PARAM_IF_SET
2897 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2899 struct sk_buff
*msg
;
2901 struct nlattr
*nl_reg_rules
;
2905 mutex_lock(&cfg80211_mutex
);
2907 if (!cfg80211_regdomain
)
2910 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2916 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2917 NL80211_CMD_GET_REG
);
2919 goto nla_put_failure
;
2921 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
,
2922 cfg80211_regdomain
->alpha2
);
2924 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
2926 goto nla_put_failure
;
2928 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
2929 struct nlattr
*nl_reg_rule
;
2930 const struct ieee80211_reg_rule
*reg_rule
;
2931 const struct ieee80211_freq_range
*freq_range
;
2932 const struct ieee80211_power_rule
*power_rule
;
2934 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
2935 freq_range
= ®_rule
->freq_range
;
2936 power_rule
= ®_rule
->power_rule
;
2938 nl_reg_rule
= nla_nest_start(msg
, i
);
2940 goto nla_put_failure
;
2942 NLA_PUT_U32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
2944 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
2945 freq_range
->start_freq_khz
);
2946 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
2947 freq_range
->end_freq_khz
);
2948 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
2949 freq_range
->max_bandwidth_khz
);
2950 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
2951 power_rule
->max_antenna_gain
);
2952 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
2953 power_rule
->max_eirp
);
2955 nla_nest_end(msg
, nl_reg_rule
);
2958 nla_nest_end(msg
, nl_reg_rules
);
2960 genlmsg_end(msg
, hdr
);
2961 err
= genlmsg_reply(msg
, info
);
2965 genlmsg_cancel(msg
, hdr
);
2969 mutex_unlock(&cfg80211_mutex
);
2973 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2975 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
2976 struct nlattr
*nl_reg_rule
;
2977 char *alpha2
= NULL
;
2978 int rem_reg_rules
= 0, r
= 0;
2979 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
2980 struct ieee80211_regdomain
*rd
= NULL
;
2982 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2985 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
2988 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2990 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
2993 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
2997 mutex_lock(&cfg80211_mutex
);
2999 if (!reg_is_valid_request(alpha2
)) {
3004 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
3005 (num_rules
* sizeof(struct ieee80211_reg_rule
));
3007 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
3013 rd
->n_reg_rules
= num_rules
;
3014 rd
->alpha2
[0] = alpha2
[0];
3015 rd
->alpha2
[1] = alpha2
[1];
3017 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
3019 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
3020 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
3022 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
3028 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
3034 BUG_ON(rule_idx
!= num_rules
);
3038 mutex_unlock(&cfg80211_mutex
);
3043 mutex_unlock(&cfg80211_mutex
);
3048 static int validate_scan_freqs(struct nlattr
*freqs
)
3050 struct nlattr
*attr1
, *attr2
;
3051 int n_channels
= 0, tmp1
, tmp2
;
3053 nla_for_each_nested(attr1
, freqs
, tmp1
) {
3056 * Some hardware has a limited channel list for
3057 * scanning, and it is pretty much nonsensical
3058 * to scan for a channel twice, so disallow that
3059 * and don't require drivers to check that the
3060 * channel list they get isn't longer than what
3061 * they can scan, as long as they can scan all
3062 * the channels they registered at once.
3064 nla_for_each_nested(attr2
, freqs
, tmp2
)
3065 if (attr1
!= attr2
&&
3066 nla_get_u32(attr1
) == nla_get_u32(attr2
))
3073 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
3075 struct cfg80211_registered_device
*rdev
;
3076 struct net_device
*dev
;
3077 struct cfg80211_scan_request
*request
;
3078 struct cfg80211_ssid
*ssid
;
3079 struct ieee80211_channel
*channel
;
3080 struct nlattr
*attr
;
3081 struct wiphy
*wiphy
;
3082 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
3083 enum ieee80211_band band
;
3086 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3091 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3095 wiphy
= &rdev
->wiphy
;
3097 if (!rdev
->ops
->scan
) {
3102 if (!netif_running(dev
)) {
3107 if (rdev
->scan_req
) {
3112 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3113 n_channels
= validate_scan_freqs(
3114 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
3122 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
3123 if (wiphy
->bands
[band
])
3124 n_channels
+= wiphy
->bands
[band
]->n_channels
;
3127 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
3128 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
3131 if (n_ssids
> wiphy
->max_scan_ssids
) {
3136 if (info
->attrs
[NL80211_ATTR_IE
])
3137 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3141 if (ie_len
> wiphy
->max_scan_ie_len
) {
3146 request
= kzalloc(sizeof(*request
)
3147 + sizeof(*ssid
) * n_ssids
3148 + sizeof(channel
) * n_channels
3149 + ie_len
, GFP_KERNEL
);
3156 request
->ssids
= (void *)&request
->channels
[n_channels
];
3157 request
->n_ssids
= n_ssids
;
3160 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
3162 request
->ie
= (void *)(request
->channels
+ n_channels
);
3166 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3167 /* user specified, bail out if channel not found */
3168 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
3169 struct ieee80211_channel
*chan
;
3171 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
3178 /* ignore disabled channels */
3179 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3182 request
->channels
[i
] = chan
;
3187 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
3189 if (!wiphy
->bands
[band
])
3191 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
3192 struct ieee80211_channel
*chan
;
3194 chan
= &wiphy
->bands
[band
]->channels
[j
];
3196 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3199 request
->channels
[i
] = chan
;
3210 request
->n_channels
= i
;
3213 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
3214 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
3215 if (request
->ssids
[i
].ssid_len
> IEEE80211_MAX_SSID_LEN
) {
3219 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
3220 request
->ssids
[i
].ssid_len
= nla_len(attr
);
3225 if (info
->attrs
[NL80211_ATTR_IE
]) {
3226 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3227 memcpy((void *)request
->ie
,
3228 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
3233 request
->wiphy
= &rdev
->wiphy
;
3235 rdev
->scan_req
= request
;
3236 err
= rdev
->ops
->scan(&rdev
->wiphy
, dev
, request
);
3239 nl80211_send_scan_start(rdev
, dev
);
3245 rdev
->scan_req
= NULL
;
3249 cfg80211_unlock_rdev(rdev
);
3257 static int nl80211_send_bss(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
3258 struct cfg80211_registered_device
*rdev
,
3259 struct wireless_dev
*wdev
,
3260 struct cfg80211_internal_bss
*intbss
)
3262 struct cfg80211_bss
*res
= &intbss
->pub
;
3267 ASSERT_WDEV_LOCK(wdev
);
3269 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3270 NL80211_CMD_NEW_SCAN_RESULTS
);
3274 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
);
3275 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
);
3277 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
3279 goto nla_put_failure
;
3280 if (!is_zero_ether_addr(res
->bssid
))
3281 NLA_PUT(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
);
3282 if (res
->information_elements
&& res
->len_information_elements
)
3283 NLA_PUT(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
3284 res
->len_information_elements
,
3285 res
->information_elements
);
3286 if (res
->beacon_ies
&& res
->len_beacon_ies
&&
3287 res
->beacon_ies
!= res
->information_elements
)
3288 NLA_PUT(msg
, NL80211_BSS_BEACON_IES
,
3289 res
->len_beacon_ies
, res
->beacon_ies
);
3291 NLA_PUT_U64(msg
, NL80211_BSS_TSF
, res
->tsf
);
3292 if (res
->beacon_interval
)
3293 NLA_PUT_U16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
);
3294 NLA_PUT_U16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
);
3295 NLA_PUT_U32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
);
3296 NLA_PUT_U32(msg
, NL80211_BSS_SEEN_MS_AGO
,
3297 jiffies_to_msecs(jiffies
- intbss
->ts
));
3299 switch (rdev
->wiphy
.signal_type
) {
3300 case CFG80211_SIGNAL_TYPE_MBM
:
3301 NLA_PUT_U32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
);
3303 case CFG80211_SIGNAL_TYPE_UNSPEC
:
3304 NLA_PUT_U8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
);
3310 switch (wdev
->iftype
) {
3311 case NL80211_IFTYPE_STATION
:
3312 if (intbss
== wdev
->current_bss
)
3313 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3314 NL80211_BSS_STATUS_ASSOCIATED
);
3315 else for (i
= 0; i
< MAX_AUTH_BSSES
; i
++) {
3316 if (intbss
!= wdev
->auth_bsses
[i
])
3318 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3319 NL80211_BSS_STATUS_AUTHENTICATED
);
3323 case NL80211_IFTYPE_ADHOC
:
3324 if (intbss
== wdev
->current_bss
)
3325 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3326 NL80211_BSS_STATUS_IBSS_JOINED
);
3332 nla_nest_end(msg
, bss
);
3334 return genlmsg_end(msg
, hdr
);
3337 genlmsg_cancel(msg
, hdr
);
3341 static int nl80211_dump_scan(struct sk_buff
*skb
,
3342 struct netlink_callback
*cb
)
3344 struct cfg80211_registered_device
*rdev
;
3345 struct net_device
*dev
;
3346 struct cfg80211_internal_bss
*scan
;
3347 struct wireless_dev
*wdev
;
3348 int ifidx
= cb
->args
[0];
3349 int start
= cb
->args
[1], idx
= 0;
3353 ifidx
= nl80211_get_ifidx(cb
);
3356 cb
->args
[0] = ifidx
;
3358 dev
= dev_get_by_index(sock_net(skb
->sk
), ifidx
);
3362 rdev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
3364 err
= PTR_ERR(rdev
);
3365 goto out_put_netdev
;
3368 wdev
= dev
->ieee80211_ptr
;
3371 spin_lock_bh(&rdev
->bss_lock
);
3372 cfg80211_bss_expire(rdev
);
3374 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
3377 if (nl80211_send_bss(skb
,
3378 NETLINK_CB(cb
->skb
).pid
,
3379 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3380 rdev
, wdev
, scan
) < 0) {
3387 spin_unlock_bh(&rdev
->bss_lock
);
3392 cfg80211_unlock_rdev(rdev
);
3399 static int nl80211_send_survey(struct sk_buff
*msg
, u32 pid
, u32 seq
,
3400 int flags
, struct net_device
*dev
,
3401 struct survey_info
*survey
)
3404 struct nlattr
*infoattr
;
3406 /* Survey without a channel doesn't make sense */
3407 if (!survey
->channel
)
3410 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3411 NL80211_CMD_NEW_SURVEY_RESULTS
);
3415 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
3417 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
3419 goto nla_put_failure
;
3421 NLA_PUT_U32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
3422 survey
->channel
->center_freq
);
3423 if (survey
->filled
& SURVEY_INFO_NOISE_DBM
)
3424 NLA_PUT_U8(msg
, NL80211_SURVEY_INFO_NOISE
,
3427 nla_nest_end(msg
, infoattr
);
3429 return genlmsg_end(msg
, hdr
);
3432 genlmsg_cancel(msg
, hdr
);
3436 static int nl80211_dump_survey(struct sk_buff
*skb
,
3437 struct netlink_callback
*cb
)
3439 struct survey_info survey
;
3440 struct cfg80211_registered_device
*dev
;
3441 struct net_device
*netdev
;
3442 int ifidx
= cb
->args
[0];
3443 int survey_idx
= cb
->args
[1];
3447 ifidx
= nl80211_get_ifidx(cb
);
3450 cb
->args
[0] = ifidx
;
3454 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
3460 dev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
3466 if (!dev
->ops
->dump_survey
) {
3472 res
= dev
->ops
->dump_survey(&dev
->wiphy
, netdev
, survey_idx
,
3479 if (nl80211_send_survey(skb
,
3480 NETLINK_CB(cb
->skb
).pid
,
3481 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3489 cb
->args
[1] = survey_idx
;
3492 cfg80211_unlock_rdev(dev
);
3499 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
)
3501 return auth_type
<= NL80211_AUTHTYPE_MAX
;
3504 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
3506 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
3507 NL80211_WPA_VERSION_2
));
3510 static bool nl80211_valid_akm_suite(u32 akm
)
3512 return akm
== WLAN_AKM_SUITE_8021X
||
3513 akm
== WLAN_AKM_SUITE_PSK
;
3516 static bool nl80211_valid_cipher_suite(u32 cipher
)
3518 return cipher
== WLAN_CIPHER_SUITE_WEP40
||
3519 cipher
== WLAN_CIPHER_SUITE_WEP104
||
3520 cipher
== WLAN_CIPHER_SUITE_TKIP
||
3521 cipher
== WLAN_CIPHER_SUITE_CCMP
||
3522 cipher
== WLAN_CIPHER_SUITE_AES_CMAC
;
3526 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3528 struct cfg80211_registered_device
*rdev
;
3529 struct net_device
*dev
;
3530 struct ieee80211_channel
*chan
;
3531 const u8
*bssid
, *ssid
, *ie
= NULL
;
3532 int err
, ssid_len
, ie_len
= 0;
3533 enum nl80211_auth_type auth_type
;
3534 struct key_parse key
;
3535 bool local_state_change
;
3537 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3540 if (!info
->attrs
[NL80211_ATTR_MAC
])
3543 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
3546 if (!info
->attrs
[NL80211_ATTR_SSID
])
3549 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
3552 err
= nl80211_parse_key(info
, &key
);
3557 if (!key
.p
.key
|| !key
.p
.key_len
)
3559 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
3560 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
3561 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
3562 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
3573 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3577 if (!rdev
->ops
->auth
) {
3582 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3587 if (!netif_running(dev
)) {
3592 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3593 chan
= ieee80211_get_channel(&rdev
->wiphy
,
3594 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3595 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
)) {
3600 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3601 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3603 if (info
->attrs
[NL80211_ATTR_IE
]) {
3604 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3605 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3608 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3609 if (!nl80211_valid_auth_type(auth_type
)) {
3614 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
3616 err
= cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
3617 ssid
, ssid_len
, ie
, ie_len
,
3618 key
.p
.key
, key
.p
.key_len
, key
.idx
,
3619 local_state_change
);
3622 cfg80211_unlock_rdev(rdev
);
3629 static int nl80211_crypto_settings(struct genl_info
*info
,
3630 struct cfg80211_crypto_settings
*settings
,
3633 memset(settings
, 0, sizeof(*settings
));
3635 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
3637 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
3641 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
3642 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
3643 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
3645 if (len
% sizeof(u32
))
3648 if (settings
->n_ciphers_pairwise
> cipher_limit
)
3651 memcpy(settings
->ciphers_pairwise
, data
, len
);
3653 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
3654 if (!nl80211_valid_cipher_suite(
3655 settings
->ciphers_pairwise
[i
]))
3659 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
3660 settings
->cipher_group
=
3661 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
3662 if (!nl80211_valid_cipher_suite(settings
->cipher_group
))
3666 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
3667 settings
->wpa_versions
=
3668 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
3669 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
3673 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
3677 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
3678 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
3679 settings
->n_akm_suites
= len
/ sizeof(u32
);
3681 if (len
% sizeof(u32
))
3684 memcpy(settings
->akm_suites
, data
, len
);
3686 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
3687 if (!nl80211_valid_akm_suite(settings
->akm_suites
[i
]))
3694 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
3696 struct cfg80211_registered_device
*rdev
;
3697 struct net_device
*dev
;
3698 struct cfg80211_crypto_settings crypto
;
3699 struct ieee80211_channel
*chan
;
3700 const u8
*bssid
, *ssid
, *ie
= NULL
, *prev_bssid
= NULL
;
3701 int err
, ssid_len
, ie_len
= 0;
3702 bool use_mfp
= false;
3704 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3707 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
3708 !info
->attrs
[NL80211_ATTR_SSID
] ||
3709 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
3714 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3718 if (!rdev
->ops
->assoc
) {
3723 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3728 if (!netif_running(dev
)) {
3733 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3735 chan
= ieee80211_get_channel(&rdev
->wiphy
,
3736 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3737 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
)) {
3742 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3743 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3745 if (info
->attrs
[NL80211_ATTR_IE
]) {
3746 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3747 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3750 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
3751 enum nl80211_mfp mfp
=
3752 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
3753 if (mfp
== NL80211_MFP_REQUIRED
)
3755 else if (mfp
!= NL80211_MFP_NO
) {
3761 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
3762 prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
3764 err
= nl80211_crypto_settings(info
, &crypto
, 1);
3766 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
, prev_bssid
,
3767 ssid
, ssid_len
, ie
, ie_len
, use_mfp
,
3771 cfg80211_unlock_rdev(rdev
);
3778 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3780 struct cfg80211_registered_device
*rdev
;
3781 struct net_device
*dev
;
3782 const u8
*ie
= NULL
, *bssid
;
3783 int err
, ie_len
= 0;
3785 bool local_state_change
;
3787 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3790 if (!info
->attrs
[NL80211_ATTR_MAC
])
3793 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3798 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3802 if (!rdev
->ops
->deauth
) {
3807 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3812 if (!netif_running(dev
)) {
3817 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3819 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3820 if (reason_code
== 0) {
3821 /* Reason Code 0 is reserved */
3826 if (info
->attrs
[NL80211_ATTR_IE
]) {
3827 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3828 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3831 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
3833 err
= cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
3834 local_state_change
);
3837 cfg80211_unlock_rdev(rdev
);
3844 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
3846 struct cfg80211_registered_device
*rdev
;
3847 struct net_device
*dev
;
3848 const u8
*ie
= NULL
, *bssid
;
3849 int err
, ie_len
= 0;
3851 bool local_state_change
;
3853 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3856 if (!info
->attrs
[NL80211_ATTR_MAC
])
3859 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3864 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3868 if (!rdev
->ops
->disassoc
) {
3873 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3878 if (!netif_running(dev
)) {
3883 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3885 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3886 if (reason_code
== 0) {
3887 /* Reason Code 0 is reserved */
3892 if (info
->attrs
[NL80211_ATTR_IE
]) {
3893 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3894 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3897 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
3899 err
= cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
3900 local_state_change
);
3903 cfg80211_unlock_rdev(rdev
);
3910 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
3912 struct cfg80211_registered_device
*rdev
;
3913 struct net_device
*dev
;
3914 struct cfg80211_ibss_params ibss
;
3915 struct wiphy
*wiphy
;
3916 struct cfg80211_cached_keys
*connkeys
= NULL
;
3919 memset(&ibss
, 0, sizeof(ibss
));
3921 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3924 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
3925 !info
->attrs
[NL80211_ATTR_SSID
] ||
3926 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
3929 ibss
.beacon_interval
= 100;
3931 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
3932 ibss
.beacon_interval
=
3933 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3934 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
3940 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3944 if (!rdev
->ops
->join_ibss
) {
3949 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
3954 if (!netif_running(dev
)) {
3959 wiphy
= &rdev
->wiphy
;
3961 if (info
->attrs
[NL80211_ATTR_MAC
])
3962 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3963 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3964 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3966 if (info
->attrs
[NL80211_ATTR_IE
]) {
3967 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3968 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3971 ibss
.channel
= ieee80211_get_channel(wiphy
,
3972 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3973 if (!ibss
.channel
||
3974 ibss
.channel
->flags
& IEEE80211_CHAN_NO_IBSS
||
3975 ibss
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
3980 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
3981 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3983 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
3984 connkeys
= nl80211_parse_connkeys(rdev
,
3985 info
->attrs
[NL80211_ATTR_KEYS
]);
3986 if (IS_ERR(connkeys
)) {
3987 err
= PTR_ERR(connkeys
);
3993 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
3995 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
3997 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
3998 struct ieee80211_supported_band
*sband
=
3999 wiphy
->bands
[ibss
.channel
->band
];
4007 for (i
= 0; i
< n_rates
; i
++) {
4008 int rate
= (rates
[i
] & 0x7f) * 5;
4011 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
4012 if (sband
->bitrates
[j
].bitrate
== rate
) {
4014 ibss
.basic_rates
|= BIT(j
);
4025 * If no rates were explicitly configured,
4026 * use the mandatory rate set for 11b or
4027 * 11a for maximum compatibility.
4029 struct ieee80211_supported_band
*sband
=
4030 wiphy
->bands
[ibss
.channel
->band
];
4032 u32 flag
= ibss
.channel
->band
== IEEE80211_BAND_5GHZ
?
4033 IEEE80211_RATE_MANDATORY_A
:
4034 IEEE80211_RATE_MANDATORY_B
;
4036 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
4037 if (sband
->bitrates
[j
].flags
& flag
)
4038 ibss
.basic_rates
|= BIT(j
);
4042 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
4045 cfg80211_unlock_rdev(rdev
);
4054 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
4056 struct cfg80211_registered_device
*rdev
;
4057 struct net_device
*dev
;
4062 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4066 if (!rdev
->ops
->leave_ibss
) {
4071 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
4076 if (!netif_running(dev
)) {
4081 err
= cfg80211_leave_ibss(rdev
, dev
, false);
4084 cfg80211_unlock_rdev(rdev
);
4091 #ifdef CONFIG_NL80211_TESTMODE
4092 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
4096 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
4098 struct cfg80211_registered_device
*rdev
;
4101 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
4106 rdev
= cfg80211_get_dev_from_info(info
);
4108 err
= PTR_ERR(rdev
);
4113 if (rdev
->ops
->testmode_cmd
) {
4114 rdev
->testmode_info
= info
;
4115 err
= rdev
->ops
->testmode_cmd(&rdev
->wiphy
,
4116 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
4117 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
4118 rdev
->testmode_info
= NULL
;
4121 cfg80211_unlock_rdev(rdev
);
4128 static struct sk_buff
*
4129 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
4130 int approxlen
, u32 pid
, u32 seq
, gfp_t gfp
)
4132 struct sk_buff
*skb
;
4134 struct nlattr
*data
;
4136 skb
= nlmsg_new(approxlen
+ 100, gfp
);
4140 hdr
= nl80211hdr_put(skb
, pid
, seq
, 0, NL80211_CMD_TESTMODE
);
4146 NLA_PUT_U32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4147 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
4149 ((void **)skb
->cb
)[0] = rdev
;
4150 ((void **)skb
->cb
)[1] = hdr
;
4151 ((void **)skb
->cb
)[2] = data
;
4160 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
4163 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4165 if (WARN_ON(!rdev
->testmode_info
))
4168 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
4169 rdev
->testmode_info
->snd_pid
,
4170 rdev
->testmode_info
->snd_seq
,
4173 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
4175 int cfg80211_testmode_reply(struct sk_buff
*skb
)
4177 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
4178 void *hdr
= ((void **)skb
->cb
)[1];
4179 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4181 if (WARN_ON(!rdev
->testmode_info
)) {
4186 nla_nest_end(skb
, data
);
4187 genlmsg_end(skb
, hdr
);
4188 return genlmsg_reply(skb
, rdev
->testmode_info
);
4190 EXPORT_SYMBOL(cfg80211_testmode_reply
);
4192 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
4193 int approxlen
, gfp_t gfp
)
4195 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4197 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
4199 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
4201 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
4203 void *hdr
= ((void **)skb
->cb
)[1];
4204 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4206 nla_nest_end(skb
, data
);
4207 genlmsg_end(skb
, hdr
);
4208 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
4210 EXPORT_SYMBOL(cfg80211_testmode_event
);
4213 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
4215 struct cfg80211_registered_device
*rdev
;
4216 struct net_device
*dev
;
4217 struct cfg80211_connect_params connect
;
4218 struct wiphy
*wiphy
;
4219 struct cfg80211_cached_keys
*connkeys
= NULL
;
4222 memset(&connect
, 0, sizeof(connect
));
4224 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4227 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
4228 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
4231 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
4233 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4234 if (!nl80211_valid_auth_type(connect
.auth_type
))
4237 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
4239 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
4241 err
= nl80211_crypto_settings(info
, &connect
.crypto
,
4242 NL80211_MAX_NR_CIPHER_SUITES
);
4247 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4251 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4256 if (!netif_running(dev
)) {
4261 wiphy
= &rdev
->wiphy
;
4263 if (info
->attrs
[NL80211_ATTR_MAC
])
4264 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4265 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4266 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4268 if (info
->attrs
[NL80211_ATTR_IE
]) {
4269 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4270 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4273 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
4275 ieee80211_get_channel(wiphy
,
4276 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4277 if (!connect
.channel
||
4278 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
4284 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
4285 connkeys
= nl80211_parse_connkeys(rdev
,
4286 info
->attrs
[NL80211_ATTR_KEYS
]);
4287 if (IS_ERR(connkeys
)) {
4288 err
= PTR_ERR(connkeys
);
4294 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
4297 cfg80211_unlock_rdev(rdev
);
4306 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
4308 struct cfg80211_registered_device
*rdev
;
4309 struct net_device
*dev
;
4313 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4314 reason
= WLAN_REASON_DEAUTH_LEAVING
;
4316 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4323 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4327 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4332 if (!netif_running(dev
)) {
4337 err
= cfg80211_disconnect(rdev
, dev
, reason
, true);
4340 cfg80211_unlock_rdev(rdev
);
4347 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
4349 struct cfg80211_registered_device
*rdev
;
4354 if (!info
->attrs
[NL80211_ATTR_PID
])
4357 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
4361 rdev
= cfg80211_get_dev_from_info(info
);
4363 err
= PTR_ERR(rdev
);
4367 net
= get_net_ns_by_pid(pid
);
4375 /* check if anything to do */
4376 if (net_eq(wiphy_net(&rdev
->wiphy
), net
))
4379 err
= cfg80211_switch_netns(rdev
, net
);
4383 cfg80211_unlock_rdev(rdev
);
4389 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4391 struct cfg80211_registered_device
*rdev
;
4392 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
4393 struct cfg80211_pmksa
*pmksa
) = NULL
;
4395 struct net_device
*dev
;
4396 struct cfg80211_pmksa pmksa
;
4398 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
4400 if (!info
->attrs
[NL80211_ATTR_MAC
])
4403 if (!info
->attrs
[NL80211_ATTR_PMKID
])
4408 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4412 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
4413 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4415 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4420 switch (info
->genlhdr
->cmd
) {
4421 case NL80211_CMD_SET_PMKSA
:
4422 rdev_ops
= rdev
->ops
->set_pmksa
;
4424 case NL80211_CMD_DEL_PMKSA
:
4425 rdev_ops
= rdev
->ops
->del_pmksa
;
4437 err
= rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
4440 cfg80211_unlock_rdev(rdev
);
4448 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4450 struct cfg80211_registered_device
*rdev
;
4452 struct net_device
*dev
;
4456 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4460 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4465 if (!rdev
->ops
->flush_pmksa
) {
4470 err
= rdev
->ops
->flush_pmksa(&rdev
->wiphy
, dev
);
4473 cfg80211_unlock_rdev(rdev
);
4482 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
4483 struct genl_info
*info
)
4485 struct cfg80211_registered_device
*rdev
;
4486 struct net_device
*dev
;
4487 struct ieee80211_channel
*chan
;
4488 struct sk_buff
*msg
;
4491 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
4495 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
4496 !info
->attrs
[NL80211_ATTR_DURATION
])
4499 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
4502 * We should be on that channel for at least one jiffie,
4503 * and more than 5 seconds seems excessive.
4505 if (!duration
|| !msecs_to_jiffies(duration
) || duration
> 5000)
4510 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4514 if (!rdev
->ops
->remain_on_channel
) {
4519 if (!netif_running(dev
)) {
4524 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
4525 channel_type
= nla_get_u32(
4526 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
4527 if (channel_type
!= NL80211_CHAN_NO_HT
&&
4528 channel_type
!= NL80211_CHAN_HT20
&&
4529 channel_type
!= NL80211_CHAN_HT40PLUS
&&
4530 channel_type
!= NL80211_CHAN_HT40MINUS
) {
4536 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
4537 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
4543 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4549 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4550 NL80211_CMD_REMAIN_ON_CHANNEL
);
4557 err
= rdev
->ops
->remain_on_channel(&rdev
->wiphy
, dev
, chan
,
4558 channel_type
, duration
, &cookie
);
4563 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
4565 genlmsg_end(msg
, hdr
);
4566 err
= genlmsg_reply(msg
, info
);
4574 cfg80211_unlock_rdev(rdev
);
4581 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
4582 struct genl_info
*info
)
4584 struct cfg80211_registered_device
*rdev
;
4585 struct net_device
*dev
;
4589 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
4594 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4598 if (!rdev
->ops
->cancel_remain_on_channel
) {
4603 if (!netif_running(dev
)) {
4608 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
4610 err
= rdev
->ops
->cancel_remain_on_channel(&rdev
->wiphy
, dev
, cookie
);
4613 cfg80211_unlock_rdev(rdev
);
4620 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
4621 u8
*rates
, u8 rates_len
)
4626 for (i
= 0; i
< rates_len
; i
++) {
4627 int rate
= (rates
[i
] & 0x7f) * 5;
4629 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
4630 struct ieee80211_rate
*srate
=
4631 &sband
->bitrates
[ridx
];
4632 if (rate
== srate
->bitrate
) {
4637 if (ridx
== sband
->n_bitrates
)
4638 return 0; /* rate not found */
4644 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
4645 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
4646 .len
= NL80211_MAX_SUPP_RATES
},
4649 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
4650 struct genl_info
*info
)
4652 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
4653 struct cfg80211_registered_device
*rdev
;
4654 struct cfg80211_bitrate_mask mask
;
4656 struct net_device
*dev
;
4657 struct nlattr
*tx_rates
;
4658 struct ieee80211_supported_band
*sband
;
4660 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
4665 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4669 if (!rdev
->ops
->set_bitrate_mask
) {
4674 memset(&mask
, 0, sizeof(mask
));
4675 /* Default to all rates enabled */
4676 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
4677 sband
= rdev
->wiphy
.bands
[i
];
4678 mask
.control
[i
].legacy
=
4679 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
4683 * The nested attribute uses enum nl80211_band as the index. This maps
4684 * directly to the enum ieee80211_band values used in cfg80211.
4686 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
4688 enum ieee80211_band band
= nla_type(tx_rates
);
4689 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
4693 sband
= rdev
->wiphy
.bands
[band
];
4694 if (sband
== NULL
) {
4698 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
4699 nla_len(tx_rates
), nl80211_txattr_policy
);
4700 if (tb
[NL80211_TXRATE_LEGACY
]) {
4701 mask
.control
[band
].legacy
= rateset_to_mask(
4703 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
4704 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
4705 if (mask
.control
[band
].legacy
== 0) {
4712 err
= rdev
->ops
->set_bitrate_mask(&rdev
->wiphy
, dev
, NULL
, &mask
);
4716 cfg80211_unlock_rdev(rdev
);
4722 static int nl80211_register_action(struct sk_buff
*skb
, struct genl_info
*info
)
4724 struct cfg80211_registered_device
*rdev
;
4725 struct net_device
*dev
;
4728 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
4731 if (nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]) < 1)
4736 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4740 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4741 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
4746 /* not much point in registering if we can't reply */
4747 if (!rdev
->ops
->action
) {
4752 err
= cfg80211_mlme_register_action(dev
->ieee80211_ptr
, info
->snd_pid
,
4753 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
4754 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
4756 cfg80211_unlock_rdev(rdev
);
4763 static int nl80211_action(struct sk_buff
*skb
, struct genl_info
*info
)
4765 struct cfg80211_registered_device
*rdev
;
4766 struct net_device
*dev
;
4767 struct ieee80211_channel
*chan
;
4768 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
4769 bool channel_type_valid
= false;
4774 struct sk_buff
*msg
;
4776 if (!info
->attrs
[NL80211_ATTR_FRAME
] ||
4777 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4782 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4786 if (!rdev
->ops
->action
) {
4791 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4792 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
4797 if (!netif_running(dev
)) {
4802 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
4803 channel_type
= nla_get_u32(
4804 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
4805 if (channel_type
!= NL80211_CHAN_NO_HT
&&
4806 channel_type
!= NL80211_CHAN_HT20
&&
4807 channel_type
!= NL80211_CHAN_HT40PLUS
&&
4808 channel_type
!= NL80211_CHAN_HT40MINUS
) {
4812 channel_type_valid
= true;
4815 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
4816 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
4822 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4828 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4829 NL80211_CMD_ACTION
);
4835 err
= cfg80211_mlme_action(rdev
, dev
, chan
, channel_type
,
4837 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
4838 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
4843 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
4845 genlmsg_end(msg
, hdr
);
4846 err
= genlmsg_reply(msg
, info
);
4854 cfg80211_unlock_rdev(rdev
);
4861 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
4863 struct cfg80211_registered_device
*rdev
;
4864 struct wireless_dev
*wdev
;
4865 struct net_device
*dev
;
4870 if (!info
->attrs
[NL80211_ATTR_PS_STATE
]) {
4875 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
4877 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
) {
4884 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4888 wdev
= dev
->ieee80211_ptr
;
4890 if (!rdev
->ops
->set_power_mgmt
) {
4895 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
4897 if (state
== wdev
->ps
)
4902 if (rdev
->ops
->set_power_mgmt(wdev
->wiphy
, dev
, wdev
->ps
,
4904 /* assume this means it's off */
4908 cfg80211_unlock_rdev(rdev
);
4916 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
4918 struct cfg80211_registered_device
*rdev
;
4919 enum nl80211_ps_state ps_state
;
4920 struct wireless_dev
*wdev
;
4921 struct net_device
*dev
;
4922 struct sk_buff
*msg
;
4928 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4932 wdev
= dev
->ieee80211_ptr
;
4934 if (!rdev
->ops
->set_power_mgmt
) {
4939 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4945 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4946 NL80211_CMD_GET_POWER_SAVE
);
4953 ps_state
= NL80211_PS_ENABLED
;
4955 ps_state
= NL80211_PS_DISABLED
;
4957 NLA_PUT_U32(msg
, NL80211_ATTR_PS_STATE
, ps_state
);
4959 genlmsg_end(msg
, hdr
);
4960 err
= genlmsg_reply(msg
, info
);
4970 cfg80211_unlock_rdev(rdev
);
4979 static struct nla_policy
4980 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
4981 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
4982 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
4983 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
4986 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
4987 s32 threshold
, u32 hysteresis
)
4989 struct cfg80211_registered_device
*rdev
;
4990 struct wireless_dev
*wdev
;
4991 struct net_device
*dev
;
4999 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
5003 wdev
= dev
->ieee80211_ptr
;
5005 if (!rdev
->ops
->set_cqm_rssi_config
) {
5010 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
) {
5015 err
= rdev
->ops
->set_cqm_rssi_config(wdev
->wiphy
, dev
,
5016 threshold
, hysteresis
);
5019 cfg80211_unlock_rdev(rdev
);
5027 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
5029 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
5033 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
5039 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
5040 nl80211_attr_cqm_policy
);
5044 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
5045 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
5048 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
5049 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
5050 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
5058 static struct genl_ops nl80211_ops
[] = {
5060 .cmd
= NL80211_CMD_GET_WIPHY
,
5061 .doit
= nl80211_get_wiphy
,
5062 .dumpit
= nl80211_dump_wiphy
,
5063 .policy
= nl80211_policy
,
5064 /* can be retrieved by unprivileged users */
5067 .cmd
= NL80211_CMD_SET_WIPHY
,
5068 .doit
= nl80211_set_wiphy
,
5069 .policy
= nl80211_policy
,
5070 .flags
= GENL_ADMIN_PERM
,
5073 .cmd
= NL80211_CMD_GET_INTERFACE
,
5074 .doit
= nl80211_get_interface
,
5075 .dumpit
= nl80211_dump_interface
,
5076 .policy
= nl80211_policy
,
5077 /* can be retrieved by unprivileged users */
5080 .cmd
= NL80211_CMD_SET_INTERFACE
,
5081 .doit
= nl80211_set_interface
,
5082 .policy
= nl80211_policy
,
5083 .flags
= GENL_ADMIN_PERM
,
5086 .cmd
= NL80211_CMD_NEW_INTERFACE
,
5087 .doit
= nl80211_new_interface
,
5088 .policy
= nl80211_policy
,
5089 .flags
= GENL_ADMIN_PERM
,
5092 .cmd
= NL80211_CMD_DEL_INTERFACE
,
5093 .doit
= nl80211_del_interface
,
5094 .policy
= nl80211_policy
,
5095 .flags
= GENL_ADMIN_PERM
,
5098 .cmd
= NL80211_CMD_GET_KEY
,
5099 .doit
= nl80211_get_key
,
5100 .policy
= nl80211_policy
,
5101 .flags
= GENL_ADMIN_PERM
,
5104 .cmd
= NL80211_CMD_SET_KEY
,
5105 .doit
= nl80211_set_key
,
5106 .policy
= nl80211_policy
,
5107 .flags
= GENL_ADMIN_PERM
,
5110 .cmd
= NL80211_CMD_NEW_KEY
,
5111 .doit
= nl80211_new_key
,
5112 .policy
= nl80211_policy
,
5113 .flags
= GENL_ADMIN_PERM
,
5116 .cmd
= NL80211_CMD_DEL_KEY
,
5117 .doit
= nl80211_del_key
,
5118 .policy
= nl80211_policy
,
5119 .flags
= GENL_ADMIN_PERM
,
5122 .cmd
= NL80211_CMD_SET_BEACON
,
5123 .policy
= nl80211_policy
,
5124 .flags
= GENL_ADMIN_PERM
,
5125 .doit
= nl80211_addset_beacon
,
5128 .cmd
= NL80211_CMD_NEW_BEACON
,
5129 .policy
= nl80211_policy
,
5130 .flags
= GENL_ADMIN_PERM
,
5131 .doit
= nl80211_addset_beacon
,
5134 .cmd
= NL80211_CMD_DEL_BEACON
,
5135 .policy
= nl80211_policy
,
5136 .flags
= GENL_ADMIN_PERM
,
5137 .doit
= nl80211_del_beacon
,
5140 .cmd
= NL80211_CMD_GET_STATION
,
5141 .doit
= nl80211_get_station
,
5142 .dumpit
= nl80211_dump_station
,
5143 .policy
= nl80211_policy
,
5146 .cmd
= NL80211_CMD_SET_STATION
,
5147 .doit
= nl80211_set_station
,
5148 .policy
= nl80211_policy
,
5149 .flags
= GENL_ADMIN_PERM
,
5152 .cmd
= NL80211_CMD_NEW_STATION
,
5153 .doit
= nl80211_new_station
,
5154 .policy
= nl80211_policy
,
5155 .flags
= GENL_ADMIN_PERM
,
5158 .cmd
= NL80211_CMD_DEL_STATION
,
5159 .doit
= nl80211_del_station
,
5160 .policy
= nl80211_policy
,
5161 .flags
= GENL_ADMIN_PERM
,
5164 .cmd
= NL80211_CMD_GET_MPATH
,
5165 .doit
= nl80211_get_mpath
,
5166 .dumpit
= nl80211_dump_mpath
,
5167 .policy
= nl80211_policy
,
5168 .flags
= GENL_ADMIN_PERM
,
5171 .cmd
= NL80211_CMD_SET_MPATH
,
5172 .doit
= nl80211_set_mpath
,
5173 .policy
= nl80211_policy
,
5174 .flags
= GENL_ADMIN_PERM
,
5177 .cmd
= NL80211_CMD_NEW_MPATH
,
5178 .doit
= nl80211_new_mpath
,
5179 .policy
= nl80211_policy
,
5180 .flags
= GENL_ADMIN_PERM
,
5183 .cmd
= NL80211_CMD_DEL_MPATH
,
5184 .doit
= nl80211_del_mpath
,
5185 .policy
= nl80211_policy
,
5186 .flags
= GENL_ADMIN_PERM
,
5189 .cmd
= NL80211_CMD_SET_BSS
,
5190 .doit
= nl80211_set_bss
,
5191 .policy
= nl80211_policy
,
5192 .flags
= GENL_ADMIN_PERM
,
5195 .cmd
= NL80211_CMD_GET_REG
,
5196 .doit
= nl80211_get_reg
,
5197 .policy
= nl80211_policy
,
5198 /* can be retrieved by unprivileged users */
5201 .cmd
= NL80211_CMD_SET_REG
,
5202 .doit
= nl80211_set_reg
,
5203 .policy
= nl80211_policy
,
5204 .flags
= GENL_ADMIN_PERM
,
5207 .cmd
= NL80211_CMD_REQ_SET_REG
,
5208 .doit
= nl80211_req_set_reg
,
5209 .policy
= nl80211_policy
,
5210 .flags
= GENL_ADMIN_PERM
,
5213 .cmd
= NL80211_CMD_GET_MESH_PARAMS
,
5214 .doit
= nl80211_get_mesh_params
,
5215 .policy
= nl80211_policy
,
5216 /* can be retrieved by unprivileged users */
5219 .cmd
= NL80211_CMD_SET_MESH_PARAMS
,
5220 .doit
= nl80211_set_mesh_params
,
5221 .policy
= nl80211_policy
,
5222 .flags
= GENL_ADMIN_PERM
,
5225 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
5226 .doit
= nl80211_trigger_scan
,
5227 .policy
= nl80211_policy
,
5228 .flags
= GENL_ADMIN_PERM
,
5231 .cmd
= NL80211_CMD_GET_SCAN
,
5232 .policy
= nl80211_policy
,
5233 .dumpit
= nl80211_dump_scan
,
5236 .cmd
= NL80211_CMD_AUTHENTICATE
,
5237 .doit
= nl80211_authenticate
,
5238 .policy
= nl80211_policy
,
5239 .flags
= GENL_ADMIN_PERM
,
5242 .cmd
= NL80211_CMD_ASSOCIATE
,
5243 .doit
= nl80211_associate
,
5244 .policy
= nl80211_policy
,
5245 .flags
= GENL_ADMIN_PERM
,
5248 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
5249 .doit
= nl80211_deauthenticate
,
5250 .policy
= nl80211_policy
,
5251 .flags
= GENL_ADMIN_PERM
,
5254 .cmd
= NL80211_CMD_DISASSOCIATE
,
5255 .doit
= nl80211_disassociate
,
5256 .policy
= nl80211_policy
,
5257 .flags
= GENL_ADMIN_PERM
,
5260 .cmd
= NL80211_CMD_JOIN_IBSS
,
5261 .doit
= nl80211_join_ibss
,
5262 .policy
= nl80211_policy
,
5263 .flags
= GENL_ADMIN_PERM
,
5266 .cmd
= NL80211_CMD_LEAVE_IBSS
,
5267 .doit
= nl80211_leave_ibss
,
5268 .policy
= nl80211_policy
,
5269 .flags
= GENL_ADMIN_PERM
,
5271 #ifdef CONFIG_NL80211_TESTMODE
5273 .cmd
= NL80211_CMD_TESTMODE
,
5274 .doit
= nl80211_testmode_do
,
5275 .policy
= nl80211_policy
,
5276 .flags
= GENL_ADMIN_PERM
,
5280 .cmd
= NL80211_CMD_CONNECT
,
5281 .doit
= nl80211_connect
,
5282 .policy
= nl80211_policy
,
5283 .flags
= GENL_ADMIN_PERM
,
5286 .cmd
= NL80211_CMD_DISCONNECT
,
5287 .doit
= nl80211_disconnect
,
5288 .policy
= nl80211_policy
,
5289 .flags
= GENL_ADMIN_PERM
,
5292 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
5293 .doit
= nl80211_wiphy_netns
,
5294 .policy
= nl80211_policy
,
5295 .flags
= GENL_ADMIN_PERM
,
5298 .cmd
= NL80211_CMD_GET_SURVEY
,
5299 .policy
= nl80211_policy
,
5300 .dumpit
= nl80211_dump_survey
,
5303 .cmd
= NL80211_CMD_SET_PMKSA
,
5304 .doit
= nl80211_setdel_pmksa
,
5305 .policy
= nl80211_policy
,
5306 .flags
= GENL_ADMIN_PERM
,
5309 .cmd
= NL80211_CMD_DEL_PMKSA
,
5310 .doit
= nl80211_setdel_pmksa
,
5311 .policy
= nl80211_policy
,
5312 .flags
= GENL_ADMIN_PERM
,
5315 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
5316 .doit
= nl80211_flush_pmksa
,
5317 .policy
= nl80211_policy
,
5318 .flags
= GENL_ADMIN_PERM
,
5321 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
5322 .doit
= nl80211_remain_on_channel
,
5323 .policy
= nl80211_policy
,
5324 .flags
= GENL_ADMIN_PERM
,
5327 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
5328 .doit
= nl80211_cancel_remain_on_channel
,
5329 .policy
= nl80211_policy
,
5330 .flags
= GENL_ADMIN_PERM
,
5333 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
5334 .doit
= nl80211_set_tx_bitrate_mask
,
5335 .policy
= nl80211_policy
,
5336 .flags
= GENL_ADMIN_PERM
,
5339 .cmd
= NL80211_CMD_REGISTER_ACTION
,
5340 .doit
= nl80211_register_action
,
5341 .policy
= nl80211_policy
,
5342 .flags
= GENL_ADMIN_PERM
,
5345 .cmd
= NL80211_CMD_ACTION
,
5346 .doit
= nl80211_action
,
5347 .policy
= nl80211_policy
,
5348 .flags
= GENL_ADMIN_PERM
,
5351 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
5352 .doit
= nl80211_set_power_save
,
5353 .policy
= nl80211_policy
,
5354 .flags
= GENL_ADMIN_PERM
,
5357 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
5358 .doit
= nl80211_get_power_save
,
5359 .policy
= nl80211_policy
,
5360 /* can be retrieved by unprivileged users */
5363 .cmd
= NL80211_CMD_SET_CQM
,
5364 .doit
= nl80211_set_cqm
,
5365 .policy
= nl80211_policy
,
5366 .flags
= GENL_ADMIN_PERM
,
5369 .cmd
= NL80211_CMD_SET_CHANNEL
,
5370 .doit
= nl80211_set_channel
,
5371 .policy
= nl80211_policy
,
5372 .flags
= GENL_ADMIN_PERM
,
5376 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
5380 /* multicast groups */
5381 static struct genl_multicast_group nl80211_config_mcgrp
= {
5384 static struct genl_multicast_group nl80211_scan_mcgrp
= {
5387 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
5388 .name
= "regulatory",
5391 /* notification functions */
5393 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
5395 struct sk_buff
*msg
;
5397 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5401 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
5406 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5407 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
5410 static int nl80211_add_scan_req(struct sk_buff
*msg
,
5411 struct cfg80211_registered_device
*rdev
)
5413 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
5414 struct nlattr
*nest
;
5417 ASSERT_RDEV_LOCK(rdev
);
5422 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
5424 goto nla_put_failure
;
5425 for (i
= 0; i
< req
->n_ssids
; i
++)
5426 NLA_PUT(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
);
5427 nla_nest_end(msg
, nest
);
5429 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
5431 goto nla_put_failure
;
5432 for (i
= 0; i
< req
->n_channels
; i
++)
5433 NLA_PUT_U32(msg
, i
, req
->channels
[i
]->center_freq
);
5434 nla_nest_end(msg
, nest
);
5437 NLA_PUT(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
);
5444 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
5445 struct cfg80211_registered_device
*rdev
,
5446 struct net_device
*netdev
,
5447 u32 pid
, u32 seq
, int flags
,
5452 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
5456 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5457 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5459 /* ignore errors and send incomplete event anyway */
5460 nl80211_add_scan_req(msg
, rdev
);
5462 return genlmsg_end(msg
, hdr
);
5465 genlmsg_cancel(msg
, hdr
);
5469 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
5470 struct net_device
*netdev
)
5472 struct sk_buff
*msg
;
5474 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
5478 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5479 NL80211_CMD_TRIGGER_SCAN
) < 0) {
5484 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5485 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5488 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
5489 struct net_device
*netdev
)
5491 struct sk_buff
*msg
;
5493 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5497 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5498 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
5503 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5504 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5507 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
5508 struct net_device
*netdev
)
5510 struct sk_buff
*msg
;
5512 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5516 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5517 NL80211_CMD_SCAN_ABORTED
) < 0) {
5522 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5523 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5527 * This can happen on global regulatory changes or device specific settings
5528 * based on custom world regulatory domains.
5530 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
5532 struct sk_buff
*msg
;
5535 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5539 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
5545 /* Userspace can always count this one always being set */
5546 NLA_PUT_U8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
);
5548 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0')
5549 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5550 NL80211_REGDOM_TYPE_WORLD
);
5551 else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9')
5552 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5553 NL80211_REGDOM_TYPE_CUSTOM_WORLD
);
5554 else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
5556 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5557 NL80211_REGDOM_TYPE_INTERSECTION
);
5559 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5560 NL80211_REGDOM_TYPE_COUNTRY
);
5561 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, request
->alpha2
);
5564 if (wiphy_idx_valid(request
->wiphy_idx
))
5565 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
);
5567 if (genlmsg_end(msg
, hdr
) < 0) {
5573 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
5580 genlmsg_cancel(msg
, hdr
);
5584 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
5585 struct net_device
*netdev
,
5586 const u8
*buf
, size_t len
,
5587 enum nl80211_commands cmd
, gfp_t gfp
)
5589 struct sk_buff
*msg
;
5592 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5596 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
5602 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5603 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5604 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
5606 if (genlmsg_end(msg
, hdr
) < 0) {
5611 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5612 nl80211_mlme_mcgrp
.id
, gfp
);
5616 genlmsg_cancel(msg
, hdr
);
5620 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
5621 struct net_device
*netdev
, const u8
*buf
,
5622 size_t len
, gfp_t gfp
)
5624 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5625 NL80211_CMD_AUTHENTICATE
, gfp
);
5628 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
5629 struct net_device
*netdev
, const u8
*buf
,
5630 size_t len
, gfp_t gfp
)
5632 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5633 NL80211_CMD_ASSOCIATE
, gfp
);
5636 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
5637 struct net_device
*netdev
, const u8
*buf
,
5638 size_t len
, gfp_t gfp
)
5640 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5641 NL80211_CMD_DEAUTHENTICATE
, gfp
);
5644 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
5645 struct net_device
*netdev
, const u8
*buf
,
5646 size_t len
, gfp_t gfp
)
5648 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5649 NL80211_CMD_DISASSOCIATE
, gfp
);
5652 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
5653 struct net_device
*netdev
, int cmd
,
5654 const u8
*addr
, gfp_t gfp
)
5656 struct sk_buff
*msg
;
5659 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5663 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
5669 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5670 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5671 NLA_PUT_FLAG(msg
, NL80211_ATTR_TIMED_OUT
);
5672 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5674 if (genlmsg_end(msg
, hdr
) < 0) {
5679 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5680 nl80211_mlme_mcgrp
.id
, gfp
);
5684 genlmsg_cancel(msg
, hdr
);
5688 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
5689 struct net_device
*netdev
, const u8
*addr
,
5692 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
5696 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
5697 struct net_device
*netdev
, const u8
*addr
,
5700 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
5704 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
5705 struct net_device
*netdev
, const u8
*bssid
,
5706 const u8
*req_ie
, size_t req_ie_len
,
5707 const u8
*resp_ie
, size_t resp_ie_len
,
5708 u16 status
, gfp_t gfp
)
5710 struct sk_buff
*msg
;
5713 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
5717 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
5723 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5724 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5726 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
5727 NLA_PUT_U16(msg
, NL80211_ATTR_STATUS_CODE
, status
);
5729 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
5731 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
5733 if (genlmsg_end(msg
, hdr
) < 0) {
5738 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5739 nl80211_mlme_mcgrp
.id
, gfp
);
5743 genlmsg_cancel(msg
, hdr
);
5748 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
5749 struct net_device
*netdev
, const u8
*bssid
,
5750 const u8
*req_ie
, size_t req_ie_len
,
5751 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
5753 struct sk_buff
*msg
;
5756 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
5760 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
5766 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5767 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5768 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
5770 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
5772 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
5774 if (genlmsg_end(msg
, hdr
) < 0) {
5779 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5780 nl80211_mlme_mcgrp
.id
, gfp
);
5784 genlmsg_cancel(msg
, hdr
);
5789 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
5790 struct net_device
*netdev
, u16 reason
,
5791 const u8
*ie
, size_t ie_len
, bool from_ap
)
5793 struct sk_buff
*msg
;
5796 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
5800 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
5806 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5807 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5808 if (from_ap
&& reason
)
5809 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason
);
5811 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
);
5813 NLA_PUT(msg
, NL80211_ATTR_IE
, ie_len
, ie
);
5815 if (genlmsg_end(msg
, hdr
) < 0) {
5820 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5821 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
5825 genlmsg_cancel(msg
, hdr
);
5830 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
5831 struct net_device
*netdev
, const u8
*bssid
,
5834 struct sk_buff
*msg
;
5837 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5841 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
5847 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5848 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5849 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
5851 if (genlmsg_end(msg
, hdr
) < 0) {
5856 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5857 nl80211_mlme_mcgrp
.id
, gfp
);
5861 genlmsg_cancel(msg
, hdr
);
5865 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
5866 struct net_device
*netdev
, const u8
*addr
,
5867 enum nl80211_key_type key_type
, int key_id
,
5868 const u8
*tsc
, gfp_t gfp
)
5870 struct sk_buff
*msg
;
5873 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5877 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
5883 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5884 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5886 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5887 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
);
5888 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_id
);
5890 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
);
5892 if (genlmsg_end(msg
, hdr
) < 0) {
5897 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5898 nl80211_mlme_mcgrp
.id
, gfp
);
5902 genlmsg_cancel(msg
, hdr
);
5906 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
5907 struct ieee80211_channel
*channel_before
,
5908 struct ieee80211_channel
*channel_after
)
5910 struct sk_buff
*msg
;
5912 struct nlattr
*nl_freq
;
5914 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
5918 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
5925 * Since we are applying the beacon hint to a wiphy we know its
5926 * wiphy_idx is valid
5928 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
));
5931 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
5933 goto nla_put_failure
;
5934 if (nl80211_msg_put_channel(msg
, channel_before
))
5935 goto nla_put_failure
;
5936 nla_nest_end(msg
, nl_freq
);
5939 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
5941 goto nla_put_failure
;
5942 if (nl80211_msg_put_channel(msg
, channel_after
))
5943 goto nla_put_failure
;
5944 nla_nest_end(msg
, nl_freq
);
5946 if (genlmsg_end(msg
, hdr
) < 0) {
5952 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
5959 genlmsg_cancel(msg
, hdr
);
5963 static void nl80211_send_remain_on_chan_event(
5964 int cmd
, struct cfg80211_registered_device
*rdev
,
5965 struct net_device
*netdev
, u64 cookie
,
5966 struct ieee80211_channel
*chan
,
5967 enum nl80211_channel_type channel_type
,
5968 unsigned int duration
, gfp_t gfp
)
5970 struct sk_buff
*msg
;
5973 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5977 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
5983 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5984 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5985 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
);
5986 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, channel_type
);
5987 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
5989 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
)
5990 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, duration
);
5992 if (genlmsg_end(msg
, hdr
) < 0) {
5997 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5998 nl80211_mlme_mcgrp
.id
, gfp
);
6002 genlmsg_cancel(msg
, hdr
);
6006 void nl80211_send_remain_on_channel(struct cfg80211_registered_device
*rdev
,
6007 struct net_device
*netdev
, u64 cookie
,
6008 struct ieee80211_channel
*chan
,
6009 enum nl80211_channel_type channel_type
,
6010 unsigned int duration
, gfp_t gfp
)
6012 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
6013 rdev
, netdev
, cookie
, chan
,
6014 channel_type
, duration
, gfp
);
6017 void nl80211_send_remain_on_channel_cancel(
6018 struct cfg80211_registered_device
*rdev
, struct net_device
*netdev
,
6019 u64 cookie
, struct ieee80211_channel
*chan
,
6020 enum nl80211_channel_type channel_type
, gfp_t gfp
)
6022 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
6023 rdev
, netdev
, cookie
, chan
,
6024 channel_type
, 0, gfp
);
6027 void nl80211_send_sta_event(struct cfg80211_registered_device
*rdev
,
6028 struct net_device
*dev
, const u8
*mac_addr
,
6029 struct station_info
*sinfo
, gfp_t gfp
)
6031 struct sk_buff
*msg
;
6033 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6037 if (nl80211_send_station(msg
, 0, 0, 0, dev
, mac_addr
, sinfo
) < 0) {
6042 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6043 nl80211_mlme_mcgrp
.id
, gfp
);
6046 int nl80211_send_action(struct cfg80211_registered_device
*rdev
,
6047 struct net_device
*netdev
, u32 nlpid
,
6048 int freq
, const u8
*buf
, size_t len
, gfp_t gfp
)
6050 struct sk_buff
*msg
;
6054 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6058 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ACTION
);
6064 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6065 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6066 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
6067 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
6069 err
= genlmsg_end(msg
, hdr
);
6075 err
= genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
6081 genlmsg_cancel(msg
, hdr
);
6086 void nl80211_send_action_tx_status(struct cfg80211_registered_device
*rdev
,
6087 struct net_device
*netdev
, u64 cookie
,
6088 const u8
*buf
, size_t len
, bool ack
,
6091 struct sk_buff
*msg
;
6094 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6098 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ACTION_TX_STATUS
);
6104 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6105 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6106 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
6107 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
6109 NLA_PUT_FLAG(msg
, NL80211_ATTR_ACK
);
6111 if (genlmsg_end(msg
, hdr
) < 0) {
6116 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
6120 genlmsg_cancel(msg
, hdr
);
6125 nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device
*rdev
,
6126 struct net_device
*netdev
,
6127 enum nl80211_cqm_rssi_threshold_event rssi_event
,
6130 struct sk_buff
*msg
;
6131 struct nlattr
*pinfoattr
;
6134 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6138 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
6144 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6145 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6147 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
6149 goto nla_put_failure
;
6151 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
6154 nla_nest_end(msg
, pinfoattr
);
6156 if (genlmsg_end(msg
, hdr
) < 0) {
6161 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6162 nl80211_mlme_mcgrp
.id
, gfp
);
6166 genlmsg_cancel(msg
, hdr
);
6170 static int nl80211_netlink_notify(struct notifier_block
* nb
,
6171 unsigned long state
,
6174 struct netlink_notify
*notify
= _notify
;
6175 struct cfg80211_registered_device
*rdev
;
6176 struct wireless_dev
*wdev
;
6178 if (state
!= NETLINK_URELEASE
)
6183 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
)
6184 list_for_each_entry_rcu(wdev
, &rdev
->netdev_list
, list
)
6185 cfg80211_mlme_unregister_actions(wdev
, notify
->pid
);
6192 static struct notifier_block nl80211_netlink_notifier
= {
6193 .notifier_call
= nl80211_netlink_notify
,
6196 /* initialisation/exit functions */
6198 int nl80211_init(void)
6202 err
= genl_register_family_with_ops(&nl80211_fam
,
6203 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
6207 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
6211 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
6215 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
6219 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
6223 #ifdef CONFIG_NL80211_TESTMODE
6224 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
6229 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
6235 genl_unregister_family(&nl80211_fam
);
6239 void nl80211_exit(void)
6241 netlink_unregister_notifier(&nl80211_netlink_notifier
);
6242 genl_unregister_family(&nl80211_fam
);