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
},
155 /* policy for the attributes */
156 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
157 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
158 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
159 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
160 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 8 },
161 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
162 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
165 /* ifidx get helper */
166 static int nl80211_get_ifidx(struct netlink_callback
*cb
)
170 res
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
171 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
176 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
179 res
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
186 static bool is_valid_ie_attr(const struct nlattr
*attr
)
194 pos
= nla_data(attr
);
215 /* message building helper */
216 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 pid
, u32 seq
,
219 /* since there is no private header just add the generic one */
220 return genlmsg_put(skb
, pid
, seq
, &nl80211_fam
, flags
, cmd
);
223 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
224 struct ieee80211_channel
*chan
)
226 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
229 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
230 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_DISABLED
);
231 if (chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
232 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
);
233 if (chan
->flags
& IEEE80211_CHAN_NO_IBSS
)
234 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
);
235 if (chan
->flags
& IEEE80211_CHAN_RADAR
)
236 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_RADAR
);
238 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
239 DBM_TO_MBM(chan
->max_power
));
247 /* netlink command implementations */
255 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
257 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
258 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
263 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
264 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
266 if (tb
[NL80211_KEY_IDX
])
267 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
269 if (tb
[NL80211_KEY_DATA
]) {
270 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
271 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
274 if (tb
[NL80211_KEY_SEQ
]) {
275 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
276 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
279 if (tb
[NL80211_KEY_CIPHER
])
280 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
285 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
287 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
288 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
289 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
292 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
293 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
294 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
297 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
298 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
300 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
301 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
303 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
304 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
309 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
313 memset(k
, 0, sizeof(*k
));
316 if (info
->attrs
[NL80211_ATTR_KEY
])
317 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
319 err
= nl80211_parse_key_old(info
, k
);
324 if (k
->def
&& k
->defmgmt
)
329 if (k
->idx
< 4 || k
->idx
> 5)
332 if (k
->idx
< 0 || k
->idx
> 3)
335 if (k
->idx
< 0 || k
->idx
> 5)
343 static struct cfg80211_cached_keys
*
344 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
347 struct key_parse parse
;
349 struct cfg80211_cached_keys
*result
;
350 int rem
, err
, def
= 0;
352 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
354 return ERR_PTR(-ENOMEM
);
357 result
->defmgmt
= -1;
359 nla_for_each_nested(key
, keys
, rem
) {
360 memset(&parse
, 0, sizeof(parse
));
363 err
= nl80211_parse_key_new(key
, &parse
);
369 if (parse
.idx
< 0 || parse
.idx
> 4)
375 result
->def
= parse
.idx
;
376 } else if (parse
.defmgmt
)
378 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
382 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
383 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
384 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
385 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
394 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
396 ASSERT_WDEV_LOCK(wdev
);
398 if (!netif_running(wdev
->netdev
))
401 switch (wdev
->iftype
) {
402 case NL80211_IFTYPE_AP
:
403 case NL80211_IFTYPE_AP_VLAN
:
405 case NL80211_IFTYPE_ADHOC
:
406 if (!wdev
->current_bss
)
409 case NL80211_IFTYPE_STATION
:
410 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
420 static int nl80211_send_wiphy(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
421 struct cfg80211_registered_device
*dev
)
424 struct nlattr
*nl_bands
, *nl_band
;
425 struct nlattr
*nl_freqs
, *nl_freq
;
426 struct nlattr
*nl_rates
, *nl_rate
;
427 struct nlattr
*nl_modes
;
428 struct nlattr
*nl_cmds
;
429 enum ieee80211_band band
;
430 struct ieee80211_channel
*chan
;
431 struct ieee80211_rate
*rate
;
433 u16 ifmodes
= dev
->wiphy
.interface_modes
;
435 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
439 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
);
440 NLA_PUT_STRING(msg
, NL80211_ATTR_WIPHY_NAME
, wiphy_name(&dev
->wiphy
));
442 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
443 cfg80211_rdev_list_generation
);
445 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
446 dev
->wiphy
.retry_short
);
447 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
448 dev
->wiphy
.retry_long
);
449 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
450 dev
->wiphy
.frag_threshold
);
451 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
452 dev
->wiphy
.rts_threshold
);
453 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
454 dev
->wiphy
.coverage_class
);
456 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
457 dev
->wiphy
.max_scan_ssids
);
458 NLA_PUT_U16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
459 dev
->wiphy
.max_scan_ie_len
);
461 NLA_PUT(msg
, NL80211_ATTR_CIPHER_SUITES
,
462 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
463 dev
->wiphy
.cipher_suites
);
465 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
466 dev
->wiphy
.max_num_pmkids
);
468 nl_modes
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
);
470 goto nla_put_failure
;
475 NLA_PUT_FLAG(msg
, i
);
480 nla_nest_end(msg
, nl_modes
);
482 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
484 goto nla_put_failure
;
486 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
487 if (!dev
->wiphy
.bands
[band
])
490 nl_band
= nla_nest_start(msg
, band
);
492 goto nla_put_failure
;
495 if (dev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
) {
496 NLA_PUT(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
497 sizeof(dev
->wiphy
.bands
[band
]->ht_cap
.mcs
),
498 &dev
->wiphy
.bands
[band
]->ht_cap
.mcs
);
499 NLA_PUT_U16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
500 dev
->wiphy
.bands
[band
]->ht_cap
.cap
);
501 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
502 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_factor
);
503 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
504 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_density
);
507 /* add frequencies */
508 nl_freqs
= nla_nest_start(msg
, NL80211_BAND_ATTR_FREQS
);
510 goto nla_put_failure
;
512 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_channels
; i
++) {
513 nl_freq
= nla_nest_start(msg
, i
);
515 goto nla_put_failure
;
517 chan
= &dev
->wiphy
.bands
[band
]->channels
[i
];
519 if (nl80211_msg_put_channel(msg
, chan
))
520 goto nla_put_failure
;
522 nla_nest_end(msg
, nl_freq
);
525 nla_nest_end(msg
, nl_freqs
);
528 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
530 goto nla_put_failure
;
532 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_bitrates
; i
++) {
533 nl_rate
= nla_nest_start(msg
, i
);
535 goto nla_put_failure
;
537 rate
= &dev
->wiphy
.bands
[band
]->bitrates
[i
];
538 NLA_PUT_U32(msg
, NL80211_BITRATE_ATTR_RATE
,
540 if (rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
)
542 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
);
544 nla_nest_end(msg
, nl_rate
);
547 nla_nest_end(msg
, nl_rates
);
549 nla_nest_end(msg
, nl_band
);
551 nla_nest_end(msg
, nl_bands
);
553 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
555 goto nla_put_failure
;
560 if (dev->ops->op) { \
562 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
566 CMD(add_virtual_intf
, NEW_INTERFACE
);
567 CMD(change_virtual_intf
, SET_INTERFACE
);
568 CMD(add_key
, NEW_KEY
);
569 CMD(add_beacon
, NEW_BEACON
);
570 CMD(add_station
, NEW_STATION
);
571 CMD(add_mpath
, NEW_MPATH
);
572 CMD(set_mesh_params
, SET_MESH_PARAMS
);
573 CMD(change_bss
, SET_BSS
);
574 CMD(auth
, AUTHENTICATE
);
575 CMD(assoc
, ASSOCIATE
);
576 CMD(deauth
, DEAUTHENTICATE
);
577 CMD(disassoc
, DISASSOCIATE
);
578 CMD(join_ibss
, JOIN_IBSS
);
579 CMD(set_pmksa
, SET_PMKSA
);
580 CMD(del_pmksa
, DEL_PMKSA
);
581 CMD(flush_pmksa
, FLUSH_PMKSA
);
582 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
583 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
585 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
587 NLA_PUT_U32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
);
592 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
594 NLA_PUT_U32(msg
, i
, NL80211_CMD_CONNECT
);
597 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
599 NLA_PUT_U32(msg
, i
, NL80211_CMD_DISCONNECT
);
602 nla_nest_end(msg
, nl_cmds
);
604 return genlmsg_end(msg
, hdr
);
607 genlmsg_cancel(msg
, hdr
);
611 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
614 int start
= cb
->args
[0];
615 struct cfg80211_registered_device
*dev
;
617 mutex_lock(&cfg80211_mutex
);
618 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
619 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
623 if (nl80211_send_wiphy(skb
, NETLINK_CB(cb
->skb
).pid
,
624 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
630 mutex_unlock(&cfg80211_mutex
);
637 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
640 struct cfg80211_registered_device
*dev
;
642 dev
= cfg80211_get_dev_from_info(info
);
646 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
650 if (nl80211_send_wiphy(msg
, info
->snd_pid
, info
->snd_seq
, 0, dev
) < 0)
653 cfg80211_unlock_rdev(dev
);
655 return genlmsg_reply(msg
, info
);
660 cfg80211_unlock_rdev(dev
);
664 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
665 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
666 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
667 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
668 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
669 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
672 static int parse_txq_params(struct nlattr
*tb
[],
673 struct ieee80211_txq_params
*txq_params
)
675 if (!tb
[NL80211_TXQ_ATTR_QUEUE
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
676 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
677 !tb
[NL80211_TXQ_ATTR_AIFS
])
680 txq_params
->queue
= nla_get_u8(tb
[NL80211_TXQ_ATTR_QUEUE
]);
681 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
682 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
683 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
684 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
689 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
691 struct cfg80211_registered_device
*rdev
;
692 int result
= 0, rem_txq_params
= 0;
693 struct nlattr
*nl_txq_params
;
695 u8 retry_short
= 0, retry_long
= 0;
696 u32 frag_threshold
= 0, rts_threshold
= 0;
697 u8 coverage_class
= 0;
701 mutex_lock(&cfg80211_mutex
);
703 rdev
= __cfg80211_rdev_from_info(info
);
705 mutex_unlock(&cfg80211_mutex
);
706 result
= PTR_ERR(rdev
);
710 mutex_lock(&rdev
->mtx
);
712 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
713 result
= cfg80211_dev_rename(
714 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
716 mutex_unlock(&cfg80211_mutex
);
721 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
722 struct ieee80211_txq_params txq_params
;
723 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
725 if (!rdev
->ops
->set_txq_params
) {
726 result
= -EOPNOTSUPP
;
730 nla_for_each_nested(nl_txq_params
,
731 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
733 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
734 nla_data(nl_txq_params
),
735 nla_len(nl_txq_params
),
737 result
= parse_txq_params(tb
, &txq_params
);
741 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
748 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
749 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
754 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
755 channel_type
= nla_get_u32(info
->attrs
[
756 NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
757 if (channel_type
!= NL80211_CHAN_NO_HT
&&
758 channel_type
!= NL80211_CHAN_HT20
&&
759 channel_type
!= NL80211_CHAN_HT40PLUS
&&
760 channel_type
!= NL80211_CHAN_HT40MINUS
)
764 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
766 mutex_lock(&rdev
->devlist_mtx
);
767 result
= rdev_set_freq(rdev
, NULL
, freq
, channel_type
);
768 mutex_unlock(&rdev
->devlist_mtx
);
775 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
776 retry_short
= nla_get_u8(
777 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
778 if (retry_short
== 0) {
782 changed
|= WIPHY_PARAM_RETRY_SHORT
;
785 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
786 retry_long
= nla_get_u8(
787 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
788 if (retry_long
== 0) {
792 changed
|= WIPHY_PARAM_RETRY_LONG
;
795 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
796 frag_threshold
= nla_get_u32(
797 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
798 if (frag_threshold
< 256) {
802 if (frag_threshold
!= (u32
) -1) {
804 * Fragments (apart from the last one) are required to
805 * have even length. Make the fragmentation code
806 * simpler by stripping LSB should someone try to use
807 * odd threshold value.
809 frag_threshold
&= ~0x1;
811 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
814 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
815 rts_threshold
= nla_get_u32(
816 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
817 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
820 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
821 coverage_class
= nla_get_u8(
822 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
823 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
827 u8 old_retry_short
, old_retry_long
;
828 u32 old_frag_threshold
, old_rts_threshold
;
829 u8 old_coverage_class
;
831 if (!rdev
->ops
->set_wiphy_params
) {
832 result
= -EOPNOTSUPP
;
836 old_retry_short
= rdev
->wiphy
.retry_short
;
837 old_retry_long
= rdev
->wiphy
.retry_long
;
838 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
839 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
840 old_coverage_class
= rdev
->wiphy
.coverage_class
;
842 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
843 rdev
->wiphy
.retry_short
= retry_short
;
844 if (changed
& WIPHY_PARAM_RETRY_LONG
)
845 rdev
->wiphy
.retry_long
= retry_long
;
846 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
847 rdev
->wiphy
.frag_threshold
= frag_threshold
;
848 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
849 rdev
->wiphy
.rts_threshold
= rts_threshold
;
850 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
851 rdev
->wiphy
.coverage_class
= coverage_class
;
853 result
= rdev
->ops
->set_wiphy_params(&rdev
->wiphy
, changed
);
855 rdev
->wiphy
.retry_short
= old_retry_short
;
856 rdev
->wiphy
.retry_long
= old_retry_long
;
857 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
858 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
859 rdev
->wiphy
.coverage_class
= old_coverage_class
;
864 mutex_unlock(&rdev
->mtx
);
871 static int nl80211_send_iface(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
872 struct cfg80211_registered_device
*rdev
,
873 struct net_device
*dev
)
877 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
881 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
882 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
883 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, dev
->name
);
884 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, dev
->ieee80211_ptr
->iftype
);
886 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
887 rdev
->devlist_generation
^
888 (cfg80211_rdev_list_generation
<< 2));
890 return genlmsg_end(msg
, hdr
);
893 genlmsg_cancel(msg
, hdr
);
897 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
901 int wp_start
= cb
->args
[0];
902 int if_start
= cb
->args
[1];
903 struct cfg80211_registered_device
*rdev
;
904 struct wireless_dev
*wdev
;
906 mutex_lock(&cfg80211_mutex
);
907 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
908 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
910 if (wp_idx
< wp_start
) {
916 mutex_lock(&rdev
->devlist_mtx
);
917 list_for_each_entry(wdev
, &rdev
->netdev_list
, list
) {
918 if (if_idx
< if_start
) {
922 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).pid
,
923 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
924 rdev
, wdev
->netdev
) < 0) {
925 mutex_unlock(&rdev
->devlist_mtx
);
930 mutex_unlock(&rdev
->devlist_mtx
);
935 mutex_unlock(&cfg80211_mutex
);
937 cb
->args
[0] = wp_idx
;
938 cb
->args
[1] = if_idx
;
943 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
946 struct cfg80211_registered_device
*dev
;
947 struct net_device
*netdev
;
950 err
= get_rdev_dev_by_info_ifindex(info
, &dev
, &netdev
);
954 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
958 if (nl80211_send_iface(msg
, info
->snd_pid
, info
->snd_seq
, 0,
963 cfg80211_unlock_rdev(dev
);
965 return genlmsg_reply(msg
, info
);
971 cfg80211_unlock_rdev(dev
);
975 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
976 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
977 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
978 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
979 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
980 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
983 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
985 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
993 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
994 nla
, mntr_flags_policy
))
997 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
999 *mntrflags
|= (1<<flag
);
1004 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
1005 struct net_device
*netdev
, u8 use_4addr
,
1006 enum nl80211_iftype iftype
)
1009 if (netdev
&& netdev
->br_port
)
1015 case NL80211_IFTYPE_AP_VLAN
:
1016 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
1019 case NL80211_IFTYPE_STATION
:
1020 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
1030 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1032 struct cfg80211_registered_device
*rdev
;
1033 struct vif_params params
;
1035 enum nl80211_iftype otype
, ntype
;
1036 struct net_device
*dev
;
1037 u32 _flags
, *flags
= NULL
;
1038 bool change
= false;
1040 memset(¶ms
, 0, sizeof(params
));
1044 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1048 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
1050 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1051 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1054 if (ntype
> NL80211_IFTYPE_MAX
) {
1060 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1061 if (ntype
!= NL80211_IFTYPE_MESH_POINT
) {
1065 params
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1066 params
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1070 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1071 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1073 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
1077 params
.use_4addr
= -1;
1080 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
1081 if (ntype
!= NL80211_IFTYPE_MONITOR
) {
1085 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
1095 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
1099 if (!err
&& params
.use_4addr
!= -1)
1100 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
1104 cfg80211_unlock_rdev(rdev
);
1110 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1112 struct cfg80211_registered_device
*rdev
;
1113 struct vif_params params
;
1115 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
1118 memset(¶ms
, 0, sizeof(params
));
1120 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
1123 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1124 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1125 if (type
> NL80211_IFTYPE_MAX
)
1131 rdev
= cfg80211_get_dev_from_info(info
);
1133 err
= PTR_ERR(rdev
);
1137 if (!rdev
->ops
->add_virtual_intf
||
1138 !(rdev
->wiphy
.interface_modes
& (1 << type
))) {
1143 if (type
== NL80211_IFTYPE_MESH_POINT
&&
1144 info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1145 params
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1146 params
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1149 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1150 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1151 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
1156 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
1157 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
1159 err
= rdev
->ops
->add_virtual_intf(&rdev
->wiphy
,
1160 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
1161 type
, err
? NULL
: &flags
, ¶ms
);
1164 cfg80211_unlock_rdev(rdev
);
1170 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1172 struct cfg80211_registered_device
*rdev
;
1174 struct net_device
*dev
;
1178 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1182 if (!rdev
->ops
->del_virtual_intf
) {
1187 err
= rdev
->ops
->del_virtual_intf(&rdev
->wiphy
, dev
);
1190 cfg80211_unlock_rdev(rdev
);
1197 struct get_key_cookie
{
1198 struct sk_buff
*msg
;
1203 static void get_key_callback(void *c
, struct key_params
*params
)
1206 struct get_key_cookie
*cookie
= c
;
1209 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
1210 params
->key_len
, params
->key
);
1213 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
1214 params
->seq_len
, params
->seq
);
1217 NLA_PUT_U32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
1220 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
1222 goto nla_put_failure
;
1225 NLA_PUT(cookie
->msg
, NL80211_KEY_DATA
,
1226 params
->key_len
, params
->key
);
1229 NLA_PUT(cookie
->msg
, NL80211_KEY_SEQ
,
1230 params
->seq_len
, params
->seq
);
1233 NLA_PUT_U32(cookie
->msg
, NL80211_KEY_CIPHER
,
1236 NLA_PUT_U8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
);
1238 nla_nest_end(cookie
->msg
, key
);
1245 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
1247 struct cfg80211_registered_device
*rdev
;
1249 struct net_device
*dev
;
1251 u8
*mac_addr
= NULL
;
1252 struct get_key_cookie cookie
= {
1256 struct sk_buff
*msg
;
1258 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
1259 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1264 if (info
->attrs
[NL80211_ATTR_MAC
])
1265 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1269 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1273 if (!rdev
->ops
->get_key
) {
1278 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1284 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1285 NL80211_CMD_NEW_KEY
);
1293 cookie
.idx
= key_idx
;
1295 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1296 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
1298 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1300 err
= rdev
->ops
->get_key(&rdev
->wiphy
, dev
, key_idx
, mac_addr
,
1301 &cookie
, get_key_callback
);
1307 goto nla_put_failure
;
1309 genlmsg_end(msg
, hdr
);
1310 err
= genlmsg_reply(msg
, info
);
1318 cfg80211_unlock_rdev(rdev
);
1326 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
1328 struct cfg80211_registered_device
*rdev
;
1329 struct key_parse key
;
1331 struct net_device
*dev
;
1332 int (*func
)(struct wiphy
*wiphy
, struct net_device
*netdev
,
1335 err
= nl80211_parse_key(info
, &key
);
1342 /* only support setting default key */
1343 if (!key
.def
&& !key
.defmgmt
)
1348 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1353 func
= rdev
->ops
->set_default_key
;
1355 func
= rdev
->ops
->set_default_mgmt_key
;
1362 wdev_lock(dev
->ieee80211_ptr
);
1363 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1365 err
= func(&rdev
->wiphy
, dev
, key
.idx
);
1367 #ifdef CONFIG_CFG80211_WEXT
1369 if (func
== rdev
->ops
->set_default_key
)
1370 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
1372 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
1375 wdev_unlock(dev
->ieee80211_ptr
);
1378 cfg80211_unlock_rdev(rdev
);
1387 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
1389 struct cfg80211_registered_device
*rdev
;
1391 struct net_device
*dev
;
1392 struct key_parse key
;
1393 u8
*mac_addr
= NULL
;
1395 err
= nl80211_parse_key(info
, &key
);
1402 if (info
->attrs
[NL80211_ATTR_MAC
])
1403 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1407 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1411 if (!rdev
->ops
->add_key
) {
1416 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
, mac_addr
)) {
1421 wdev_lock(dev
->ieee80211_ptr
);
1422 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1424 err
= rdev
->ops
->add_key(&rdev
->wiphy
, dev
, key
.idx
,
1426 wdev_unlock(dev
->ieee80211_ptr
);
1429 cfg80211_unlock_rdev(rdev
);
1437 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
1439 struct cfg80211_registered_device
*rdev
;
1441 struct net_device
*dev
;
1442 u8
*mac_addr
= NULL
;
1443 struct key_parse key
;
1445 err
= nl80211_parse_key(info
, &key
);
1449 if (info
->attrs
[NL80211_ATTR_MAC
])
1450 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1454 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1458 if (!rdev
->ops
->del_key
) {
1463 wdev_lock(dev
->ieee80211_ptr
);
1464 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1466 err
= rdev
->ops
->del_key(&rdev
->wiphy
, dev
, key
.idx
, mac_addr
);
1468 #ifdef CONFIG_CFG80211_WEXT
1470 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
1471 dev
->ieee80211_ptr
->wext
.default_key
= -1;
1472 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
1473 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
1476 wdev_unlock(dev
->ieee80211_ptr
);
1479 cfg80211_unlock_rdev(rdev
);
1488 static int nl80211_addset_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1490 int (*call
)(struct wiphy
*wiphy
, struct net_device
*dev
,
1491 struct beacon_parameters
*info
);
1492 struct cfg80211_registered_device
*rdev
;
1494 struct net_device
*dev
;
1495 struct beacon_parameters params
;
1498 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]))
1503 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1507 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1512 switch (info
->genlhdr
->cmd
) {
1513 case NL80211_CMD_NEW_BEACON
:
1514 /* these are required for NEW_BEACON */
1515 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
1516 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
1517 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1522 call
= rdev
->ops
->add_beacon
;
1524 case NL80211_CMD_SET_BEACON
:
1525 call
= rdev
->ops
->set_beacon
;
1538 memset(¶ms
, 0, sizeof(params
));
1540 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
1542 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
1546 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
1547 params
.dtim_period
=
1548 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
1552 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1553 params
.head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1555 nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1559 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
1560 params
.tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1562 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1571 err
= call(&rdev
->wiphy
, dev
, ¶ms
);
1574 cfg80211_unlock_rdev(rdev
);
1582 static int nl80211_del_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1584 struct cfg80211_registered_device
*rdev
;
1586 struct net_device
*dev
;
1590 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1594 if (!rdev
->ops
->del_beacon
) {
1599 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1603 err
= rdev
->ops
->del_beacon(&rdev
->wiphy
, dev
);
1606 cfg80211_unlock_rdev(rdev
);
1614 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
1615 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
1616 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
1617 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
1618 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
1621 static int parse_station_flags(struct genl_info
*info
,
1622 struct station_parameters
*params
)
1624 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
1629 * Try parsing the new attribute first so userspace
1630 * can specify both for older kernels.
1632 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
1634 struct nl80211_sta_flag_update
*sta_flags
;
1636 sta_flags
= nla_data(nla
);
1637 params
->sta_flags_mask
= sta_flags
->mask
;
1638 params
->sta_flags_set
= sta_flags
->set
;
1639 if ((params
->sta_flags_mask
|
1640 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
1645 /* if present, parse the old attribute */
1647 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
1651 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
1652 nla
, sta_flags_policy
))
1655 params
->sta_flags_mask
= (1 << __NL80211_STA_FLAG_AFTER_LAST
) - 1;
1656 params
->sta_flags_mask
&= ~1;
1658 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++)
1660 params
->sta_flags_set
|= (1<<flag
);
1665 static int nl80211_send_station(struct sk_buff
*msg
, u32 pid
, u32 seq
,
1666 int flags
, struct net_device
*dev
,
1667 const u8
*mac_addr
, struct station_info
*sinfo
)
1670 struct nlattr
*sinfoattr
, *txrate
;
1673 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
1677 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1678 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1680 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
);
1682 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
1684 goto nla_put_failure
;
1685 if (sinfo
->filled
& STATION_INFO_INACTIVE_TIME
)
1686 NLA_PUT_U32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
1687 sinfo
->inactive_time
);
1688 if (sinfo
->filled
& STATION_INFO_RX_BYTES
)
1689 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_BYTES
,
1691 if (sinfo
->filled
& STATION_INFO_TX_BYTES
)
1692 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_BYTES
,
1694 if (sinfo
->filled
& STATION_INFO_LLID
)
1695 NLA_PUT_U16(msg
, NL80211_STA_INFO_LLID
,
1697 if (sinfo
->filled
& STATION_INFO_PLID
)
1698 NLA_PUT_U16(msg
, NL80211_STA_INFO_PLID
,
1700 if (sinfo
->filled
& STATION_INFO_PLINK_STATE
)
1701 NLA_PUT_U8(msg
, NL80211_STA_INFO_PLINK_STATE
,
1702 sinfo
->plink_state
);
1703 if (sinfo
->filled
& STATION_INFO_SIGNAL
)
1704 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL
,
1706 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
1707 txrate
= nla_nest_start(msg
, NL80211_STA_INFO_TX_BITRATE
);
1709 goto nla_put_failure
;
1711 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
1712 bitrate
= cfg80211_calculate_bitrate(&sinfo
->txrate
);
1714 NLA_PUT_U16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate
);
1716 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_MCS
)
1717 NLA_PUT_U8(msg
, NL80211_RATE_INFO_MCS
,
1719 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
)
1720 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
);
1721 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_SHORT_GI
)
1722 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_SHORT_GI
);
1724 nla_nest_end(msg
, txrate
);
1726 if (sinfo
->filled
& STATION_INFO_RX_PACKETS
)
1727 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_PACKETS
,
1729 if (sinfo
->filled
& STATION_INFO_TX_PACKETS
)
1730 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_PACKETS
,
1732 nla_nest_end(msg
, sinfoattr
);
1734 return genlmsg_end(msg
, hdr
);
1737 genlmsg_cancel(msg
, hdr
);
1741 static int nl80211_dump_station(struct sk_buff
*skb
,
1742 struct netlink_callback
*cb
)
1744 struct station_info sinfo
;
1745 struct cfg80211_registered_device
*dev
;
1746 struct net_device
*netdev
;
1747 u8 mac_addr
[ETH_ALEN
];
1748 int ifidx
= cb
->args
[0];
1749 int sta_idx
= cb
->args
[1];
1753 ifidx
= nl80211_get_ifidx(cb
);
1759 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
1765 dev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
1771 if (!dev
->ops
->dump_station
) {
1777 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
1784 if (nl80211_send_station(skb
,
1785 NETLINK_CB(cb
->skb
).pid
,
1786 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1796 cb
->args
[1] = sta_idx
;
1799 cfg80211_unlock_rdev(dev
);
1806 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
1808 struct cfg80211_registered_device
*rdev
;
1810 struct net_device
*dev
;
1811 struct station_info sinfo
;
1812 struct sk_buff
*msg
;
1813 u8
*mac_addr
= NULL
;
1815 memset(&sinfo
, 0, sizeof(sinfo
));
1817 if (!info
->attrs
[NL80211_ATTR_MAC
])
1820 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1824 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1828 if (!rdev
->ops
->get_station
) {
1833 err
= rdev
->ops
->get_station(&rdev
->wiphy
, dev
, mac_addr
, &sinfo
);
1837 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1841 if (nl80211_send_station(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1842 dev
, mac_addr
, &sinfo
) < 0)
1845 err
= genlmsg_reply(msg
, info
);
1851 cfg80211_unlock_rdev(rdev
);
1860 * Get vlan interface making sure it is running and on the right wiphy.
1862 static int get_vlan(struct genl_info
*info
,
1863 struct cfg80211_registered_device
*rdev
,
1864 struct net_device
**vlan
)
1866 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
1870 *vlan
= dev_get_by_index(genl_info_net(info
),
1871 nla_get_u32(vlanattr
));
1874 if (!(*vlan
)->ieee80211_ptr
)
1876 if ((*vlan
)->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
)
1878 if (!netif_running(*vlan
))
1884 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
1886 struct cfg80211_registered_device
*rdev
;
1888 struct net_device
*dev
;
1889 struct station_parameters params
;
1890 u8
*mac_addr
= NULL
;
1892 memset(¶ms
, 0, sizeof(params
));
1894 params
.listen_interval
= -1;
1896 if (info
->attrs
[NL80211_ATTR_STA_AID
])
1899 if (!info
->attrs
[NL80211_ATTR_MAC
])
1902 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1904 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
1905 params
.supported_rates
=
1906 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1907 params
.supported_rates_len
=
1908 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1911 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
1912 params
.listen_interval
=
1913 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
1915 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
1917 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
1919 if (parse_station_flags(info
, ¶ms
))
1922 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
1923 params
.plink_action
=
1924 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
1928 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1932 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
1936 /* validate settings */
1939 switch (dev
->ieee80211_ptr
->iftype
) {
1940 case NL80211_IFTYPE_AP
:
1941 case NL80211_IFTYPE_AP_VLAN
:
1942 /* disallow mesh-specific things */
1943 if (params
.plink_action
)
1946 case NL80211_IFTYPE_STATION
:
1947 /* disallow everything but AUTHORIZED flag */
1948 if (params
.plink_action
)
1952 if (params
.supported_rates
)
1956 if (params
.listen_interval
>= 0)
1958 if (params
.sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
1961 case NL80211_IFTYPE_MESH_POINT
:
1962 /* disallow things mesh doesn't support */
1967 if (params
.listen_interval
>= 0)
1969 if (params
.supported_rates
)
1971 if (params
.sta_flags_mask
)
1981 if (!rdev
->ops
->change_station
) {
1986 err
= rdev
->ops
->change_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
1990 dev_put(params
.vlan
);
1991 cfg80211_unlock_rdev(rdev
);
1999 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
2001 struct cfg80211_registered_device
*rdev
;
2003 struct net_device
*dev
;
2004 struct station_parameters params
;
2005 u8
*mac_addr
= NULL
;
2007 memset(¶ms
, 0, sizeof(params
));
2009 if (!info
->attrs
[NL80211_ATTR_MAC
])
2012 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2015 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
2018 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
2021 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2022 params
.supported_rates
=
2023 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2024 params
.supported_rates_len
=
2025 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2026 params
.listen_interval
=
2027 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2029 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
2030 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
2033 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2035 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2037 if (parse_station_flags(info
, ¶ms
))
2042 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2046 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2047 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
) {
2052 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
2056 /* validate settings */
2059 if (!rdev
->ops
->add_station
) {
2064 if (!netif_running(dev
)) {
2069 err
= rdev
->ops
->add_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2073 dev_put(params
.vlan
);
2074 cfg80211_unlock_rdev(rdev
);
2082 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
2084 struct cfg80211_registered_device
*rdev
;
2086 struct net_device
*dev
;
2087 u8
*mac_addr
= NULL
;
2089 if (info
->attrs
[NL80211_ATTR_MAC
])
2090 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2094 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2098 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2099 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
) {
2104 if (!rdev
->ops
->del_station
) {
2109 err
= rdev
->ops
->del_station(&rdev
->wiphy
, dev
, mac_addr
);
2112 cfg80211_unlock_rdev(rdev
);
2120 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2121 int flags
, struct net_device
*dev
,
2122 u8
*dst
, u8
*next_hop
,
2123 struct mpath_info
*pinfo
)
2126 struct nlattr
*pinfoattr
;
2128 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2132 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2133 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
2134 NLA_PUT(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
);
2136 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
);
2138 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
2140 goto nla_put_failure
;
2141 if (pinfo
->filled
& MPATH_INFO_FRAME_QLEN
)
2142 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
2144 if (pinfo
->filled
& MPATH_INFO_SN
)
2145 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_SN
,
2147 if (pinfo
->filled
& MPATH_INFO_METRIC
)
2148 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_METRIC
,
2150 if (pinfo
->filled
& MPATH_INFO_EXPTIME
)
2151 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_EXPTIME
,
2153 if (pinfo
->filled
& MPATH_INFO_FLAGS
)
2154 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_FLAGS
,
2156 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
)
2157 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
2158 pinfo
->discovery_timeout
);
2159 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
)
2160 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
2161 pinfo
->discovery_retries
);
2163 nla_nest_end(msg
, pinfoattr
);
2165 return genlmsg_end(msg
, hdr
);
2168 genlmsg_cancel(msg
, hdr
);
2172 static int nl80211_dump_mpath(struct sk_buff
*skb
,
2173 struct netlink_callback
*cb
)
2175 struct mpath_info pinfo
;
2176 struct cfg80211_registered_device
*dev
;
2177 struct net_device
*netdev
;
2179 u8 next_hop
[ETH_ALEN
];
2180 int ifidx
= cb
->args
[0];
2181 int path_idx
= cb
->args
[1];
2185 ifidx
= nl80211_get_ifidx(cb
);
2191 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
2197 dev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
2203 if (!dev
->ops
->dump_mpath
) {
2208 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2214 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
2215 dst
, next_hop
, &pinfo
);
2221 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).pid
,
2222 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2223 netdev
, dst
, next_hop
,
2232 cb
->args
[1] = path_idx
;
2235 cfg80211_unlock_rdev(dev
);
2242 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2244 struct cfg80211_registered_device
*rdev
;
2246 struct net_device
*dev
;
2247 struct mpath_info pinfo
;
2248 struct sk_buff
*msg
;
2250 u8 next_hop
[ETH_ALEN
];
2252 memset(&pinfo
, 0, sizeof(pinfo
));
2254 if (!info
->attrs
[NL80211_ATTR_MAC
])
2257 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2261 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2265 if (!rdev
->ops
->get_mpath
) {
2270 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2275 err
= rdev
->ops
->get_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
2279 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2283 if (nl80211_send_mpath(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2284 dev
, dst
, next_hop
, &pinfo
) < 0)
2287 err
= genlmsg_reply(msg
, info
);
2293 cfg80211_unlock_rdev(rdev
);
2301 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2303 struct cfg80211_registered_device
*rdev
;
2305 struct net_device
*dev
;
2307 u8
*next_hop
= NULL
;
2309 if (!info
->attrs
[NL80211_ATTR_MAC
])
2312 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2315 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2316 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2320 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2324 if (!rdev
->ops
->change_mpath
) {
2329 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2334 if (!netif_running(dev
)) {
2339 err
= rdev
->ops
->change_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2342 cfg80211_unlock_rdev(rdev
);
2349 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2351 struct cfg80211_registered_device
*rdev
;
2353 struct net_device
*dev
;
2355 u8
*next_hop
= NULL
;
2357 if (!info
->attrs
[NL80211_ATTR_MAC
])
2360 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2363 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2364 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2368 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2372 if (!rdev
->ops
->add_mpath
) {
2377 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2382 if (!netif_running(dev
)) {
2387 err
= rdev
->ops
->add_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2390 cfg80211_unlock_rdev(rdev
);
2398 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2400 struct cfg80211_registered_device
*rdev
;
2402 struct net_device
*dev
;
2405 if (info
->attrs
[NL80211_ATTR_MAC
])
2406 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2410 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2414 if (!rdev
->ops
->del_mpath
) {
2419 err
= rdev
->ops
->del_mpath(&rdev
->wiphy
, dev
, dst
);
2422 cfg80211_unlock_rdev(rdev
);
2430 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
2432 struct cfg80211_registered_device
*rdev
;
2434 struct net_device
*dev
;
2435 struct bss_parameters params
;
2437 memset(¶ms
, 0, sizeof(params
));
2438 /* default to not changing parameters */
2439 params
.use_cts_prot
= -1;
2440 params
.use_short_preamble
= -1;
2441 params
.use_short_slot_time
= -1;
2443 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
2444 params
.use_cts_prot
=
2445 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
2446 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
2447 params
.use_short_preamble
=
2448 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
2449 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
2450 params
.use_short_slot_time
=
2451 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
2452 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
2453 params
.basic_rates
=
2454 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2455 params
.basic_rates_len
=
2456 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2461 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2465 if (!rdev
->ops
->change_bss
) {
2470 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
2475 err
= rdev
->ops
->change_bss(&rdev
->wiphy
, dev
, ¶ms
);
2478 cfg80211_unlock_rdev(rdev
);
2486 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
2487 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
2488 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
2489 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
2490 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
2491 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
2492 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
2495 static int parse_reg_rule(struct nlattr
*tb
[],
2496 struct ieee80211_reg_rule
*reg_rule
)
2498 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
2499 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
2501 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
2503 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
2505 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
2507 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
2509 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
2512 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
2514 freq_range
->start_freq_khz
=
2515 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
2516 freq_range
->end_freq_khz
=
2517 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
2518 freq_range
->max_bandwidth_khz
=
2519 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
2521 power_rule
->max_eirp
=
2522 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
2524 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
2525 power_rule
->max_antenna_gain
=
2526 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
2531 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2537 * You should only get this when cfg80211 hasn't yet initialized
2538 * completely when built-in to the kernel right between the time
2539 * window between nl80211_init() and regulatory_init(), if that is
2542 mutex_lock(&cfg80211_mutex
);
2543 if (unlikely(!cfg80211_regdomain
)) {
2544 mutex_unlock(&cfg80211_mutex
);
2545 return -EINPROGRESS
;
2547 mutex_unlock(&cfg80211_mutex
);
2549 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2552 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2554 r
= regulatory_hint_user(data
);
2559 static int nl80211_get_mesh_params(struct sk_buff
*skb
,
2560 struct genl_info
*info
)
2562 struct cfg80211_registered_device
*rdev
;
2563 struct mesh_config cur_params
;
2565 struct net_device
*dev
;
2567 struct nlattr
*pinfoattr
;
2568 struct sk_buff
*msg
;
2572 /* Look up our device */
2573 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2577 if (!rdev
->ops
->get_mesh_params
) {
2582 /* Get the mesh params */
2583 err
= rdev
->ops
->get_mesh_params(&rdev
->wiphy
, dev
, &cur_params
);
2587 /* Draw up a netlink message to send back */
2588 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2593 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2594 NL80211_CMD_GET_MESH_PARAMS
);
2596 goto nla_put_failure
;
2597 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_PARAMS
);
2599 goto nla_put_failure
;
2600 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2601 NLA_PUT_U16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
2602 cur_params
.dot11MeshRetryTimeout
);
2603 NLA_PUT_U16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
2604 cur_params
.dot11MeshConfirmTimeout
);
2605 NLA_PUT_U16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
2606 cur_params
.dot11MeshHoldingTimeout
);
2607 NLA_PUT_U16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
2608 cur_params
.dot11MeshMaxPeerLinks
);
2609 NLA_PUT_U8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
2610 cur_params
.dot11MeshMaxRetries
);
2611 NLA_PUT_U8(msg
, NL80211_MESHCONF_TTL
,
2612 cur_params
.dot11MeshTTL
);
2613 NLA_PUT_U8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
2614 cur_params
.auto_open_plinks
);
2615 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2616 cur_params
.dot11MeshHWMPmaxPREQretries
);
2617 NLA_PUT_U32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
2618 cur_params
.path_refresh_time
);
2619 NLA_PUT_U16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2620 cur_params
.min_discovery_timeout
);
2621 NLA_PUT_U32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2622 cur_params
.dot11MeshHWMPactivePathTimeout
);
2623 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2624 cur_params
.dot11MeshHWMPpreqMinInterval
);
2625 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2626 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
);
2627 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
2628 cur_params
.dot11MeshHWMPRootMode
);
2629 nla_nest_end(msg
, pinfoattr
);
2630 genlmsg_end(msg
, hdr
);
2631 err
= genlmsg_reply(msg
, info
);
2635 genlmsg_cancel(msg
, hdr
);
2639 cfg80211_unlock_rdev(rdev
);
2647 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2649 if (table[attr_num]) {\
2650 cfg.param = nla_fn(table[attr_num]); \
2651 mask |= (1 << (attr_num - 1)); \
2655 static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
2656 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
2657 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
2658 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
2659 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
2660 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
2661 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
2662 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
2664 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
2665 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
2666 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
2667 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
2668 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
2669 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
2672 static int nl80211_set_mesh_params(struct sk_buff
*skb
, struct genl_info
*info
)
2676 struct cfg80211_registered_device
*rdev
;
2677 struct net_device
*dev
;
2678 struct mesh_config cfg
;
2679 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
2680 struct nlattr
*parent_attr
;
2682 parent_attr
= info
->attrs
[NL80211_ATTR_MESH_PARAMS
];
2685 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
2686 parent_attr
, nl80211_meshconf_params_policy
))
2691 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2695 if (!rdev
->ops
->set_mesh_params
) {
2700 /* This makes sure that there aren't more than 32 mesh config
2701 * parameters (otherwise our bitfield scheme would not work.) */
2702 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
2704 /* Fill in the params struct */
2706 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
2707 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
, nla_get_u16
);
2708 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
2709 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
, nla_get_u16
);
2710 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
2711 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
, nla_get_u16
);
2712 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
2713 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
, nla_get_u16
);
2714 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
2715 mask
, NL80211_MESHCONF_MAX_RETRIES
, nla_get_u8
);
2716 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
2717 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
2718 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
2719 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
, nla_get_u8
);
2720 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
2721 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2723 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
2724 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
, nla_get_u32
);
2725 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
2726 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2728 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
2729 mask
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2731 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
2732 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2734 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
2735 dot11MeshHWMPnetDiameterTraversalTime
,
2736 mask
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2738 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
2739 dot11MeshHWMPRootMode
, mask
,
2740 NL80211_MESHCONF_HWMP_ROOTMODE
,
2744 err
= rdev
->ops
->set_mesh_params(&rdev
->wiphy
, dev
, &cfg
, mask
);
2748 cfg80211_unlock_rdev(rdev
);
2756 #undef FILL_IN_MESH_PARAM_IF_SET
2758 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2760 struct sk_buff
*msg
;
2762 struct nlattr
*nl_reg_rules
;
2766 mutex_lock(&cfg80211_mutex
);
2768 if (!cfg80211_regdomain
)
2771 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2777 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2778 NL80211_CMD_GET_REG
);
2780 goto nla_put_failure
;
2782 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
,
2783 cfg80211_regdomain
->alpha2
);
2785 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
2787 goto nla_put_failure
;
2789 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
2790 struct nlattr
*nl_reg_rule
;
2791 const struct ieee80211_reg_rule
*reg_rule
;
2792 const struct ieee80211_freq_range
*freq_range
;
2793 const struct ieee80211_power_rule
*power_rule
;
2795 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
2796 freq_range
= ®_rule
->freq_range
;
2797 power_rule
= ®_rule
->power_rule
;
2799 nl_reg_rule
= nla_nest_start(msg
, i
);
2801 goto nla_put_failure
;
2803 NLA_PUT_U32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
2805 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
2806 freq_range
->start_freq_khz
);
2807 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
2808 freq_range
->end_freq_khz
);
2809 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
2810 freq_range
->max_bandwidth_khz
);
2811 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
2812 power_rule
->max_antenna_gain
);
2813 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
2814 power_rule
->max_eirp
);
2816 nla_nest_end(msg
, nl_reg_rule
);
2819 nla_nest_end(msg
, nl_reg_rules
);
2821 genlmsg_end(msg
, hdr
);
2822 err
= genlmsg_reply(msg
, info
);
2826 genlmsg_cancel(msg
, hdr
);
2829 mutex_unlock(&cfg80211_mutex
);
2833 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2835 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
2836 struct nlattr
*nl_reg_rule
;
2837 char *alpha2
= NULL
;
2838 int rem_reg_rules
= 0, r
= 0;
2839 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
2840 struct ieee80211_regdomain
*rd
= NULL
;
2842 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2845 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
2848 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2850 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
2853 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
2857 mutex_lock(&cfg80211_mutex
);
2859 if (!reg_is_valid_request(alpha2
)) {
2864 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
2865 (num_rules
* sizeof(struct ieee80211_reg_rule
));
2867 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
2873 rd
->n_reg_rules
= num_rules
;
2874 rd
->alpha2
[0] = alpha2
[0];
2875 rd
->alpha2
[1] = alpha2
[1];
2877 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
2879 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
2880 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
2882 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
2888 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
2894 BUG_ON(rule_idx
!= num_rules
);
2898 mutex_unlock(&cfg80211_mutex
);
2903 mutex_unlock(&cfg80211_mutex
);
2908 static int validate_scan_freqs(struct nlattr
*freqs
)
2910 struct nlattr
*attr1
, *attr2
;
2911 int n_channels
= 0, tmp1
, tmp2
;
2913 nla_for_each_nested(attr1
, freqs
, tmp1
) {
2916 * Some hardware has a limited channel list for
2917 * scanning, and it is pretty much nonsensical
2918 * to scan for a channel twice, so disallow that
2919 * and don't require drivers to check that the
2920 * channel list they get isn't longer than what
2921 * they can scan, as long as they can scan all
2922 * the channels they registered at once.
2924 nla_for_each_nested(attr2
, freqs
, tmp2
)
2925 if (attr1
!= attr2
&&
2926 nla_get_u32(attr1
) == nla_get_u32(attr2
))
2933 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
2935 struct cfg80211_registered_device
*rdev
;
2936 struct net_device
*dev
;
2937 struct cfg80211_scan_request
*request
;
2938 struct cfg80211_ssid
*ssid
;
2939 struct ieee80211_channel
*channel
;
2940 struct nlattr
*attr
;
2941 struct wiphy
*wiphy
;
2942 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
2943 enum ieee80211_band band
;
2946 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
2951 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2955 wiphy
= &rdev
->wiphy
;
2957 if (!rdev
->ops
->scan
) {
2962 if (!netif_running(dev
)) {
2967 if (rdev
->scan_req
) {
2972 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
2973 n_channels
= validate_scan_freqs(
2974 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
2982 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
2983 if (wiphy
->bands
[band
])
2984 n_channels
+= wiphy
->bands
[band
]->n_channels
;
2987 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
2988 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
2991 if (n_ssids
> wiphy
->max_scan_ssids
) {
2996 if (info
->attrs
[NL80211_ATTR_IE
])
2997 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3001 if (ie_len
> wiphy
->max_scan_ie_len
) {
3006 request
= kzalloc(sizeof(*request
)
3007 + sizeof(*ssid
) * n_ssids
3008 + sizeof(channel
) * n_channels
3009 + ie_len
, GFP_KERNEL
);
3016 request
->ssids
= (void *)&request
->channels
[n_channels
];
3017 request
->n_ssids
= n_ssids
;
3020 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
3022 request
->ie
= (void *)(request
->channels
+ n_channels
);
3026 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3027 /* user specified, bail out if channel not found */
3028 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
3029 struct ieee80211_channel
*chan
;
3031 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
3038 /* ignore disabled channels */
3039 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3042 request
->channels
[i
] = chan
;
3047 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
3049 if (!wiphy
->bands
[band
])
3051 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
3052 struct ieee80211_channel
*chan
;
3054 chan
= &wiphy
->bands
[band
]->channels
[j
];
3056 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3059 request
->channels
[i
] = chan
;
3070 request
->n_channels
= i
;
3073 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
3074 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
3075 if (request
->ssids
[i
].ssid_len
> IEEE80211_MAX_SSID_LEN
) {
3079 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
3080 request
->ssids
[i
].ssid_len
= nla_len(attr
);
3085 if (info
->attrs
[NL80211_ATTR_IE
]) {
3086 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3087 memcpy((void *)request
->ie
,
3088 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
3093 request
->wiphy
= &rdev
->wiphy
;
3095 rdev
->scan_req
= request
;
3096 err
= rdev
->ops
->scan(&rdev
->wiphy
, dev
, request
);
3099 nl80211_send_scan_start(rdev
, dev
);
3105 rdev
->scan_req
= NULL
;
3109 cfg80211_unlock_rdev(rdev
);
3117 static int nl80211_send_bss(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
3118 struct cfg80211_registered_device
*rdev
,
3119 struct wireless_dev
*wdev
,
3120 struct cfg80211_internal_bss
*intbss
)
3122 struct cfg80211_bss
*res
= &intbss
->pub
;
3127 ASSERT_WDEV_LOCK(wdev
);
3129 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3130 NL80211_CMD_NEW_SCAN_RESULTS
);
3134 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
);
3135 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
);
3137 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
3139 goto nla_put_failure
;
3140 if (!is_zero_ether_addr(res
->bssid
))
3141 NLA_PUT(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
);
3142 if (res
->information_elements
&& res
->len_information_elements
)
3143 NLA_PUT(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
3144 res
->len_information_elements
,
3145 res
->information_elements
);
3146 if (res
->beacon_ies
&& res
->len_beacon_ies
&&
3147 res
->beacon_ies
!= res
->information_elements
)
3148 NLA_PUT(msg
, NL80211_BSS_BEACON_IES
,
3149 res
->len_beacon_ies
, res
->beacon_ies
);
3151 NLA_PUT_U64(msg
, NL80211_BSS_TSF
, res
->tsf
);
3152 if (res
->beacon_interval
)
3153 NLA_PUT_U16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
);
3154 NLA_PUT_U16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
);
3155 NLA_PUT_U32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
);
3156 NLA_PUT_U32(msg
, NL80211_BSS_SEEN_MS_AGO
,
3157 jiffies_to_msecs(jiffies
- intbss
->ts
));
3159 switch (rdev
->wiphy
.signal_type
) {
3160 case CFG80211_SIGNAL_TYPE_MBM
:
3161 NLA_PUT_U32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
);
3163 case CFG80211_SIGNAL_TYPE_UNSPEC
:
3164 NLA_PUT_U8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
);
3170 switch (wdev
->iftype
) {
3171 case NL80211_IFTYPE_STATION
:
3172 if (intbss
== wdev
->current_bss
)
3173 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3174 NL80211_BSS_STATUS_ASSOCIATED
);
3175 else for (i
= 0; i
< MAX_AUTH_BSSES
; i
++) {
3176 if (intbss
!= wdev
->auth_bsses
[i
])
3178 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3179 NL80211_BSS_STATUS_AUTHENTICATED
);
3183 case NL80211_IFTYPE_ADHOC
:
3184 if (intbss
== wdev
->current_bss
)
3185 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3186 NL80211_BSS_STATUS_IBSS_JOINED
);
3192 nla_nest_end(msg
, bss
);
3194 return genlmsg_end(msg
, hdr
);
3197 genlmsg_cancel(msg
, hdr
);
3201 static int nl80211_dump_scan(struct sk_buff
*skb
,
3202 struct netlink_callback
*cb
)
3204 struct cfg80211_registered_device
*rdev
;
3205 struct net_device
*dev
;
3206 struct cfg80211_internal_bss
*scan
;
3207 struct wireless_dev
*wdev
;
3208 int ifidx
= cb
->args
[0];
3209 int start
= cb
->args
[1], idx
= 0;
3213 ifidx
= nl80211_get_ifidx(cb
);
3216 cb
->args
[0] = ifidx
;
3218 dev
= dev_get_by_index(sock_net(skb
->sk
), ifidx
);
3222 rdev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
3224 err
= PTR_ERR(rdev
);
3225 goto out_put_netdev
;
3228 wdev
= dev
->ieee80211_ptr
;
3231 spin_lock_bh(&rdev
->bss_lock
);
3232 cfg80211_bss_expire(rdev
);
3234 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
3237 if (nl80211_send_bss(skb
,
3238 NETLINK_CB(cb
->skb
).pid
,
3239 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3240 rdev
, wdev
, scan
) < 0) {
3247 spin_unlock_bh(&rdev
->bss_lock
);
3252 cfg80211_unlock_rdev(rdev
);
3259 static int nl80211_send_survey(struct sk_buff
*msg
, u32 pid
, u32 seq
,
3260 int flags
, struct net_device
*dev
,
3261 struct survey_info
*survey
)
3264 struct nlattr
*infoattr
;
3266 /* Survey without a channel doesn't make sense */
3267 if (!survey
->channel
)
3270 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3271 NL80211_CMD_NEW_SURVEY_RESULTS
);
3275 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
3277 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
3279 goto nla_put_failure
;
3281 NLA_PUT_U32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
3282 survey
->channel
->center_freq
);
3283 if (survey
->filled
& SURVEY_INFO_NOISE_DBM
)
3284 NLA_PUT_U8(msg
, NL80211_SURVEY_INFO_NOISE
,
3287 nla_nest_end(msg
, infoattr
);
3289 return genlmsg_end(msg
, hdr
);
3292 genlmsg_cancel(msg
, hdr
);
3296 static int nl80211_dump_survey(struct sk_buff
*skb
,
3297 struct netlink_callback
*cb
)
3299 struct survey_info survey
;
3300 struct cfg80211_registered_device
*dev
;
3301 struct net_device
*netdev
;
3302 int ifidx
= cb
->args
[0];
3303 int survey_idx
= cb
->args
[1];
3307 ifidx
= nl80211_get_ifidx(cb
);
3310 cb
->args
[0] = ifidx
;
3314 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
3320 dev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
3326 if (!dev
->ops
->dump_survey
) {
3332 res
= dev
->ops
->dump_survey(&dev
->wiphy
, netdev
, survey_idx
,
3339 if (nl80211_send_survey(skb
,
3340 NETLINK_CB(cb
->skb
).pid
,
3341 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3349 cb
->args
[1] = survey_idx
;
3352 cfg80211_unlock_rdev(dev
);
3359 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
)
3361 return auth_type
<= NL80211_AUTHTYPE_MAX
;
3364 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
3366 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
3367 NL80211_WPA_VERSION_2
));
3370 static bool nl80211_valid_akm_suite(u32 akm
)
3372 return akm
== WLAN_AKM_SUITE_8021X
||
3373 akm
== WLAN_AKM_SUITE_PSK
;
3376 static bool nl80211_valid_cipher_suite(u32 cipher
)
3378 return cipher
== WLAN_CIPHER_SUITE_WEP40
||
3379 cipher
== WLAN_CIPHER_SUITE_WEP104
||
3380 cipher
== WLAN_CIPHER_SUITE_TKIP
||
3381 cipher
== WLAN_CIPHER_SUITE_CCMP
||
3382 cipher
== WLAN_CIPHER_SUITE_AES_CMAC
;
3386 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3388 struct cfg80211_registered_device
*rdev
;
3389 struct net_device
*dev
;
3390 struct ieee80211_channel
*chan
;
3391 const u8
*bssid
, *ssid
, *ie
= NULL
;
3392 int err
, ssid_len
, ie_len
= 0;
3393 enum nl80211_auth_type auth_type
;
3394 struct key_parse key
;
3396 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3399 if (!info
->attrs
[NL80211_ATTR_MAC
])
3402 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
3405 if (!info
->attrs
[NL80211_ATTR_SSID
])
3408 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
3411 err
= nl80211_parse_key(info
, &key
);
3416 if (!key
.p
.key
|| !key
.p
.key_len
)
3418 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
3419 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
3420 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
3421 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
3432 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3436 if (!rdev
->ops
->auth
) {
3441 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3446 if (!netif_running(dev
)) {
3451 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3452 chan
= ieee80211_get_channel(&rdev
->wiphy
,
3453 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3454 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
)) {
3459 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3460 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3462 if (info
->attrs
[NL80211_ATTR_IE
]) {
3463 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3464 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3467 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3468 if (!nl80211_valid_auth_type(auth_type
)) {
3473 err
= cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
3474 ssid
, ssid_len
, ie
, ie_len
,
3475 key
.p
.key
, key
.p
.key_len
, key
.idx
);
3478 cfg80211_unlock_rdev(rdev
);
3485 static int nl80211_crypto_settings(struct genl_info
*info
,
3486 struct cfg80211_crypto_settings
*settings
,
3489 memset(settings
, 0, sizeof(*settings
));
3491 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
3493 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
3497 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
3498 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
3499 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
3501 if (len
% sizeof(u32
))
3504 if (settings
->n_ciphers_pairwise
> cipher_limit
)
3507 memcpy(settings
->ciphers_pairwise
, data
, len
);
3509 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
3510 if (!nl80211_valid_cipher_suite(
3511 settings
->ciphers_pairwise
[i
]))
3515 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
3516 settings
->cipher_group
=
3517 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
3518 if (!nl80211_valid_cipher_suite(settings
->cipher_group
))
3522 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
3523 settings
->wpa_versions
=
3524 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
3525 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
3529 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
3533 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
3534 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
3535 settings
->n_akm_suites
= len
/ sizeof(u32
);
3537 if (len
% sizeof(u32
))
3540 memcpy(settings
->akm_suites
, data
, len
);
3542 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
3543 if (!nl80211_valid_akm_suite(settings
->akm_suites
[i
]))
3550 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
3552 struct cfg80211_registered_device
*rdev
;
3553 struct net_device
*dev
;
3554 struct wireless_dev
*wdev
;
3555 struct cfg80211_crypto_settings crypto
;
3556 struct ieee80211_channel
*chan
, *fixedchan
;
3557 const u8
*bssid
, *ssid
, *ie
= NULL
, *prev_bssid
= NULL
;
3558 int err
, ssid_len
, ie_len
= 0;
3559 bool use_mfp
= false;
3561 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3564 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
3565 !info
->attrs
[NL80211_ATTR_SSID
] ||
3566 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
3571 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3575 if (!rdev
->ops
->assoc
) {
3580 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3585 if (!netif_running(dev
)) {
3590 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3592 chan
= ieee80211_get_channel(&rdev
->wiphy
,
3593 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3594 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
)) {
3599 mutex_lock(&rdev
->devlist_mtx
);
3600 wdev
= dev
->ieee80211_ptr
;
3601 fixedchan
= rdev_fixed_channel(rdev
, wdev
);
3602 if (fixedchan
&& chan
!= fixedchan
) {
3604 mutex_unlock(&rdev
->devlist_mtx
);
3607 mutex_unlock(&rdev
->devlist_mtx
);
3609 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3610 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3612 if (info
->attrs
[NL80211_ATTR_IE
]) {
3613 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3614 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3617 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
3618 enum nl80211_mfp mfp
=
3619 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
3620 if (mfp
== NL80211_MFP_REQUIRED
)
3622 else if (mfp
!= NL80211_MFP_NO
) {
3628 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
3629 prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
3631 err
= nl80211_crypto_settings(info
, &crypto
, 1);
3633 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
, prev_bssid
,
3634 ssid
, ssid_len
, ie
, ie_len
, use_mfp
,
3638 cfg80211_unlock_rdev(rdev
);
3645 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3647 struct cfg80211_registered_device
*rdev
;
3648 struct net_device
*dev
;
3649 const u8
*ie
= NULL
, *bssid
;
3650 int err
, ie_len
= 0;
3653 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3656 if (!info
->attrs
[NL80211_ATTR_MAC
])
3659 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3664 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3668 if (!rdev
->ops
->deauth
) {
3673 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3678 if (!netif_running(dev
)) {
3683 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3685 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3686 if (reason_code
== 0) {
3687 /* Reason Code 0 is reserved */
3692 if (info
->attrs
[NL80211_ATTR_IE
]) {
3693 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3694 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3697 err
= cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
);
3700 cfg80211_unlock_rdev(rdev
);
3707 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
3709 struct cfg80211_registered_device
*rdev
;
3710 struct net_device
*dev
;
3711 const u8
*ie
= NULL
, *bssid
;
3712 int err
, ie_len
= 0;
3715 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3718 if (!info
->attrs
[NL80211_ATTR_MAC
])
3721 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3726 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3730 if (!rdev
->ops
->disassoc
) {
3735 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3740 if (!netif_running(dev
)) {
3745 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3747 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3748 if (reason_code
== 0) {
3749 /* Reason Code 0 is reserved */
3754 if (info
->attrs
[NL80211_ATTR_IE
]) {
3755 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3756 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3759 err
= cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
);
3762 cfg80211_unlock_rdev(rdev
);
3769 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
3771 struct cfg80211_registered_device
*rdev
;
3772 struct net_device
*dev
;
3773 struct cfg80211_ibss_params ibss
;
3774 struct wiphy
*wiphy
;
3775 struct cfg80211_cached_keys
*connkeys
= NULL
;
3778 memset(&ibss
, 0, sizeof(ibss
));
3780 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3783 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
3784 !info
->attrs
[NL80211_ATTR_SSID
] ||
3785 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
3788 ibss
.beacon_interval
= 100;
3790 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
3791 ibss
.beacon_interval
=
3792 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3793 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
3799 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3803 if (!rdev
->ops
->join_ibss
) {
3808 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
3813 if (!netif_running(dev
)) {
3818 wiphy
= &rdev
->wiphy
;
3820 if (info
->attrs
[NL80211_ATTR_MAC
])
3821 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3822 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3823 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3825 if (info
->attrs
[NL80211_ATTR_IE
]) {
3826 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3827 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3830 ibss
.channel
= ieee80211_get_channel(wiphy
,
3831 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3832 if (!ibss
.channel
||
3833 ibss
.channel
->flags
& IEEE80211_CHAN_NO_IBSS
||
3834 ibss
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
3839 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
3840 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3842 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
3843 connkeys
= nl80211_parse_connkeys(rdev
,
3844 info
->attrs
[NL80211_ATTR_KEYS
]);
3845 if (IS_ERR(connkeys
)) {
3846 err
= PTR_ERR(connkeys
);
3852 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
3855 cfg80211_unlock_rdev(rdev
);
3864 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
3866 struct cfg80211_registered_device
*rdev
;
3867 struct net_device
*dev
;
3872 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3876 if (!rdev
->ops
->leave_ibss
) {
3881 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
3886 if (!netif_running(dev
)) {
3891 err
= cfg80211_leave_ibss(rdev
, dev
, false);
3894 cfg80211_unlock_rdev(rdev
);
3901 #ifdef CONFIG_NL80211_TESTMODE
3902 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
3906 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
3908 struct cfg80211_registered_device
*rdev
;
3911 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
3916 rdev
= cfg80211_get_dev_from_info(info
);
3918 err
= PTR_ERR(rdev
);
3923 if (rdev
->ops
->testmode_cmd
) {
3924 rdev
->testmode_info
= info
;
3925 err
= rdev
->ops
->testmode_cmd(&rdev
->wiphy
,
3926 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
3927 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
3928 rdev
->testmode_info
= NULL
;
3931 cfg80211_unlock_rdev(rdev
);
3938 static struct sk_buff
*
3939 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
3940 int approxlen
, u32 pid
, u32 seq
, gfp_t gfp
)
3942 struct sk_buff
*skb
;
3944 struct nlattr
*data
;
3946 skb
= nlmsg_new(approxlen
+ 100, gfp
);
3950 hdr
= nl80211hdr_put(skb
, pid
, seq
, 0, NL80211_CMD_TESTMODE
);
3956 NLA_PUT_U32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
3957 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
3959 ((void **)skb
->cb
)[0] = rdev
;
3960 ((void **)skb
->cb
)[1] = hdr
;
3961 ((void **)skb
->cb
)[2] = data
;
3970 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
3973 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
3975 if (WARN_ON(!rdev
->testmode_info
))
3978 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
3979 rdev
->testmode_info
->snd_pid
,
3980 rdev
->testmode_info
->snd_seq
,
3983 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
3985 int cfg80211_testmode_reply(struct sk_buff
*skb
)
3987 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
3988 void *hdr
= ((void **)skb
->cb
)[1];
3989 struct nlattr
*data
= ((void **)skb
->cb
)[2];
3991 if (WARN_ON(!rdev
->testmode_info
)) {
3996 nla_nest_end(skb
, data
);
3997 genlmsg_end(skb
, hdr
);
3998 return genlmsg_reply(skb
, rdev
->testmode_info
);
4000 EXPORT_SYMBOL(cfg80211_testmode_reply
);
4002 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
4003 int approxlen
, gfp_t gfp
)
4005 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4007 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
4009 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
4011 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
4013 void *hdr
= ((void **)skb
->cb
)[1];
4014 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4016 nla_nest_end(skb
, data
);
4017 genlmsg_end(skb
, hdr
);
4018 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
4020 EXPORT_SYMBOL(cfg80211_testmode_event
);
4023 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
4025 struct cfg80211_registered_device
*rdev
;
4026 struct net_device
*dev
;
4027 struct cfg80211_connect_params connect
;
4028 struct wiphy
*wiphy
;
4029 struct cfg80211_cached_keys
*connkeys
= NULL
;
4032 memset(&connect
, 0, sizeof(connect
));
4034 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4037 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
4038 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
4041 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
4043 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4044 if (!nl80211_valid_auth_type(connect
.auth_type
))
4047 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
4049 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
4051 err
= nl80211_crypto_settings(info
, &connect
.crypto
,
4052 NL80211_MAX_NR_CIPHER_SUITES
);
4057 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4061 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4066 if (!netif_running(dev
)) {
4071 wiphy
= &rdev
->wiphy
;
4073 if (info
->attrs
[NL80211_ATTR_MAC
])
4074 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4075 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4076 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4078 if (info
->attrs
[NL80211_ATTR_IE
]) {
4079 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4080 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4083 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
4085 ieee80211_get_channel(wiphy
,
4086 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4087 if (!connect
.channel
||
4088 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
4094 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
4095 connkeys
= nl80211_parse_connkeys(rdev
,
4096 info
->attrs
[NL80211_ATTR_KEYS
]);
4097 if (IS_ERR(connkeys
)) {
4098 err
= PTR_ERR(connkeys
);
4104 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
4107 cfg80211_unlock_rdev(rdev
);
4116 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
4118 struct cfg80211_registered_device
*rdev
;
4119 struct net_device
*dev
;
4123 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4124 reason
= WLAN_REASON_DEAUTH_LEAVING
;
4126 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4133 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4137 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4142 if (!netif_running(dev
)) {
4147 err
= cfg80211_disconnect(rdev
, dev
, reason
, true);
4150 cfg80211_unlock_rdev(rdev
);
4157 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
4159 struct cfg80211_registered_device
*rdev
;
4164 if (!info
->attrs
[NL80211_ATTR_PID
])
4167 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
4171 rdev
= cfg80211_get_dev_from_info(info
);
4173 err
= PTR_ERR(rdev
);
4177 net
= get_net_ns_by_pid(pid
);
4185 /* check if anything to do */
4186 if (net_eq(wiphy_net(&rdev
->wiphy
), net
))
4189 err
= cfg80211_switch_netns(rdev
, net
);
4193 cfg80211_unlock_rdev(rdev
);
4199 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4201 struct cfg80211_registered_device
*rdev
;
4202 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
4203 struct cfg80211_pmksa
*pmksa
) = NULL
;
4205 struct net_device
*dev
;
4206 struct cfg80211_pmksa pmksa
;
4208 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
4210 if (!info
->attrs
[NL80211_ATTR_MAC
])
4213 if (!info
->attrs
[NL80211_ATTR_PMKID
])
4218 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4222 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
4223 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4225 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4230 switch (info
->genlhdr
->cmd
) {
4231 case NL80211_CMD_SET_PMKSA
:
4232 rdev_ops
= rdev
->ops
->set_pmksa
;
4234 case NL80211_CMD_DEL_PMKSA
:
4235 rdev_ops
= rdev
->ops
->del_pmksa
;
4247 err
= rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
4250 cfg80211_unlock_rdev(rdev
);
4258 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4260 struct cfg80211_registered_device
*rdev
;
4262 struct net_device
*dev
;
4266 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4270 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4275 if (!rdev
->ops
->flush_pmksa
) {
4280 err
= rdev
->ops
->flush_pmksa(&rdev
->wiphy
, dev
);
4283 cfg80211_unlock_rdev(rdev
);
4292 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
4293 struct genl_info
*info
)
4295 struct cfg80211_registered_device
*rdev
;
4296 struct net_device
*dev
;
4297 struct ieee80211_channel
*chan
;
4298 struct sk_buff
*msg
;
4301 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
4305 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
4306 !info
->attrs
[NL80211_ATTR_DURATION
])
4309 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
4312 * We should be on that channel for at least one jiffie,
4313 * and more than 5 seconds seems excessive.
4315 if (!duration
|| !msecs_to_jiffies(duration
) || duration
> 5000)
4320 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4324 if (!rdev
->ops
->remain_on_channel
) {
4329 if (!netif_running(dev
)) {
4334 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
4335 channel_type
= nla_get_u32(
4336 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
4337 if (channel_type
!= NL80211_CHAN_NO_HT
&&
4338 channel_type
!= NL80211_CHAN_HT20
&&
4339 channel_type
!= NL80211_CHAN_HT40PLUS
&&
4340 channel_type
!= NL80211_CHAN_HT40MINUS
)
4345 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
4346 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
4352 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4358 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4359 NL80211_CMD_REMAIN_ON_CHANNEL
);
4366 err
= rdev
->ops
->remain_on_channel(&rdev
->wiphy
, dev
, chan
,
4367 channel_type
, duration
, &cookie
);
4372 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
4374 genlmsg_end(msg
, hdr
);
4375 err
= genlmsg_reply(msg
, info
);
4383 cfg80211_unlock_rdev(rdev
);
4390 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
4391 struct genl_info
*info
)
4393 struct cfg80211_registered_device
*rdev
;
4394 struct net_device
*dev
;
4398 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
4403 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4407 if (!rdev
->ops
->cancel_remain_on_channel
) {
4412 if (!netif_running(dev
)) {
4417 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
4419 err
= rdev
->ops
->cancel_remain_on_channel(&rdev
->wiphy
, dev
, cookie
);
4422 cfg80211_unlock_rdev(rdev
);
4429 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
4430 u8
*rates
, u8 rates_len
)
4435 for (i
= 0; i
< rates_len
; i
++) {
4436 int rate
= (rates
[i
] & 0x7f) * 5;
4438 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
4439 struct ieee80211_rate
*srate
=
4440 &sband
->bitrates
[ridx
];
4441 if (rate
== srate
->bitrate
) {
4446 if (ridx
== sband
->n_bitrates
)
4447 return 0; /* rate not found */
4453 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
4454 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
4455 .len
= NL80211_MAX_SUPP_RATES
},
4458 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
4459 struct genl_info
*info
)
4461 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
4462 struct cfg80211_registered_device
*rdev
;
4463 struct cfg80211_bitrate_mask mask
;
4465 struct net_device
*dev
;
4466 struct nlattr
*tx_rates
;
4467 struct ieee80211_supported_band
*sband
;
4469 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
4474 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4478 if (!rdev
->ops
->set_bitrate_mask
) {
4483 memset(&mask
, 0, sizeof(mask
));
4484 /* Default to all rates enabled */
4485 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
4486 sband
= rdev
->wiphy
.bands
[i
];
4487 mask
.control
[i
].legacy
=
4488 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
4492 * The nested attribute uses enum nl80211_band as the index. This maps
4493 * directly to the enum ieee80211_band values used in cfg80211.
4495 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
4497 enum ieee80211_band band
= nla_type(tx_rates
);
4498 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
4502 sband
= rdev
->wiphy
.bands
[band
];
4503 if (sband
== NULL
) {
4507 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
4508 nla_len(tx_rates
), nl80211_txattr_policy
);
4509 if (tb
[NL80211_TXRATE_LEGACY
]) {
4510 mask
.control
[band
].legacy
= rateset_to_mask(
4512 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
4513 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
4514 if (mask
.control
[band
].legacy
== 0) {
4521 err
= rdev
->ops
->set_bitrate_mask(&rdev
->wiphy
, dev
, NULL
, &mask
);
4525 cfg80211_unlock_rdev(rdev
);
4531 static int nl80211_register_action(struct sk_buff
*skb
, struct genl_info
*info
)
4533 struct cfg80211_registered_device
*rdev
;
4534 struct net_device
*dev
;
4537 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
4540 if (nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]) < 1)
4545 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4549 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4554 /* not much point in registering if we can't reply */
4555 if (!rdev
->ops
->action
) {
4560 err
= cfg80211_mlme_register_action(dev
->ieee80211_ptr
, info
->snd_pid
,
4561 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
4562 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
4564 cfg80211_unlock_rdev(rdev
);
4571 static int nl80211_action(struct sk_buff
*skb
, struct genl_info
*info
)
4573 struct cfg80211_registered_device
*rdev
;
4574 struct net_device
*dev
;
4575 struct ieee80211_channel
*chan
;
4576 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
4581 struct sk_buff
*msg
;
4583 if (!info
->attrs
[NL80211_ATTR_FRAME
] ||
4584 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4589 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4593 if (!rdev
->ops
->action
) {
4598 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4603 if (!netif_running(dev
)) {
4608 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
4609 channel_type
= nla_get_u32(
4610 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
4611 if (channel_type
!= NL80211_CHAN_NO_HT
&&
4612 channel_type
!= NL80211_CHAN_HT20
&&
4613 channel_type
!= NL80211_CHAN_HT40PLUS
&&
4614 channel_type
!= NL80211_CHAN_HT40MINUS
)
4619 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
4620 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
4626 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4632 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4633 NL80211_CMD_ACTION
);
4639 err
= cfg80211_mlme_action(rdev
, dev
, chan
, channel_type
,
4640 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
4641 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
4646 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
4648 genlmsg_end(msg
, hdr
);
4649 err
= genlmsg_reply(msg
, info
);
4657 cfg80211_unlock_rdev(rdev
);
4664 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
4666 struct cfg80211_registered_device
*rdev
;
4667 struct wireless_dev
*wdev
;
4668 struct net_device
*dev
;
4673 if (!info
->attrs
[NL80211_ATTR_PS_STATE
]) {
4678 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
4680 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
) {
4687 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4691 wdev
= dev
->ieee80211_ptr
;
4693 if (!rdev
->ops
->set_power_mgmt
) {
4698 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
4700 if (state
== wdev
->ps
)
4705 if (rdev
->ops
->set_power_mgmt(wdev
->wiphy
, dev
, wdev
->ps
,
4707 /* assume this means it's off */
4711 cfg80211_unlock_rdev(rdev
);
4719 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
4721 struct cfg80211_registered_device
*rdev
;
4722 enum nl80211_ps_state ps_state
;
4723 struct wireless_dev
*wdev
;
4724 struct net_device
*dev
;
4725 struct sk_buff
*msg
;
4731 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4735 wdev
= dev
->ieee80211_ptr
;
4737 if (!rdev
->ops
->set_power_mgmt
) {
4742 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4748 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4749 NL80211_CMD_GET_POWER_SAVE
);
4756 ps_state
= NL80211_PS_ENABLED
;
4758 ps_state
= NL80211_PS_DISABLED
;
4760 NLA_PUT_U32(msg
, NL80211_ATTR_PS_STATE
, ps_state
);
4762 genlmsg_end(msg
, hdr
);
4763 err
= genlmsg_reply(msg
, info
);
4773 cfg80211_unlock_rdev(rdev
);
4782 static struct genl_ops nl80211_ops
[] = {
4784 .cmd
= NL80211_CMD_GET_WIPHY
,
4785 .doit
= nl80211_get_wiphy
,
4786 .dumpit
= nl80211_dump_wiphy
,
4787 .policy
= nl80211_policy
,
4788 /* can be retrieved by unprivileged users */
4791 .cmd
= NL80211_CMD_SET_WIPHY
,
4792 .doit
= nl80211_set_wiphy
,
4793 .policy
= nl80211_policy
,
4794 .flags
= GENL_ADMIN_PERM
,
4797 .cmd
= NL80211_CMD_GET_INTERFACE
,
4798 .doit
= nl80211_get_interface
,
4799 .dumpit
= nl80211_dump_interface
,
4800 .policy
= nl80211_policy
,
4801 /* can be retrieved by unprivileged users */
4804 .cmd
= NL80211_CMD_SET_INTERFACE
,
4805 .doit
= nl80211_set_interface
,
4806 .policy
= nl80211_policy
,
4807 .flags
= GENL_ADMIN_PERM
,
4810 .cmd
= NL80211_CMD_NEW_INTERFACE
,
4811 .doit
= nl80211_new_interface
,
4812 .policy
= nl80211_policy
,
4813 .flags
= GENL_ADMIN_PERM
,
4816 .cmd
= NL80211_CMD_DEL_INTERFACE
,
4817 .doit
= nl80211_del_interface
,
4818 .policy
= nl80211_policy
,
4819 .flags
= GENL_ADMIN_PERM
,
4822 .cmd
= NL80211_CMD_GET_KEY
,
4823 .doit
= nl80211_get_key
,
4824 .policy
= nl80211_policy
,
4825 .flags
= GENL_ADMIN_PERM
,
4828 .cmd
= NL80211_CMD_SET_KEY
,
4829 .doit
= nl80211_set_key
,
4830 .policy
= nl80211_policy
,
4831 .flags
= GENL_ADMIN_PERM
,
4834 .cmd
= NL80211_CMD_NEW_KEY
,
4835 .doit
= nl80211_new_key
,
4836 .policy
= nl80211_policy
,
4837 .flags
= GENL_ADMIN_PERM
,
4840 .cmd
= NL80211_CMD_DEL_KEY
,
4841 .doit
= nl80211_del_key
,
4842 .policy
= nl80211_policy
,
4843 .flags
= GENL_ADMIN_PERM
,
4846 .cmd
= NL80211_CMD_SET_BEACON
,
4847 .policy
= nl80211_policy
,
4848 .flags
= GENL_ADMIN_PERM
,
4849 .doit
= nl80211_addset_beacon
,
4852 .cmd
= NL80211_CMD_NEW_BEACON
,
4853 .policy
= nl80211_policy
,
4854 .flags
= GENL_ADMIN_PERM
,
4855 .doit
= nl80211_addset_beacon
,
4858 .cmd
= NL80211_CMD_DEL_BEACON
,
4859 .policy
= nl80211_policy
,
4860 .flags
= GENL_ADMIN_PERM
,
4861 .doit
= nl80211_del_beacon
,
4864 .cmd
= NL80211_CMD_GET_STATION
,
4865 .doit
= nl80211_get_station
,
4866 .dumpit
= nl80211_dump_station
,
4867 .policy
= nl80211_policy
,
4870 .cmd
= NL80211_CMD_SET_STATION
,
4871 .doit
= nl80211_set_station
,
4872 .policy
= nl80211_policy
,
4873 .flags
= GENL_ADMIN_PERM
,
4876 .cmd
= NL80211_CMD_NEW_STATION
,
4877 .doit
= nl80211_new_station
,
4878 .policy
= nl80211_policy
,
4879 .flags
= GENL_ADMIN_PERM
,
4882 .cmd
= NL80211_CMD_DEL_STATION
,
4883 .doit
= nl80211_del_station
,
4884 .policy
= nl80211_policy
,
4885 .flags
= GENL_ADMIN_PERM
,
4888 .cmd
= NL80211_CMD_GET_MPATH
,
4889 .doit
= nl80211_get_mpath
,
4890 .dumpit
= nl80211_dump_mpath
,
4891 .policy
= nl80211_policy
,
4892 .flags
= GENL_ADMIN_PERM
,
4895 .cmd
= NL80211_CMD_SET_MPATH
,
4896 .doit
= nl80211_set_mpath
,
4897 .policy
= nl80211_policy
,
4898 .flags
= GENL_ADMIN_PERM
,
4901 .cmd
= NL80211_CMD_NEW_MPATH
,
4902 .doit
= nl80211_new_mpath
,
4903 .policy
= nl80211_policy
,
4904 .flags
= GENL_ADMIN_PERM
,
4907 .cmd
= NL80211_CMD_DEL_MPATH
,
4908 .doit
= nl80211_del_mpath
,
4909 .policy
= nl80211_policy
,
4910 .flags
= GENL_ADMIN_PERM
,
4913 .cmd
= NL80211_CMD_SET_BSS
,
4914 .doit
= nl80211_set_bss
,
4915 .policy
= nl80211_policy
,
4916 .flags
= GENL_ADMIN_PERM
,
4919 .cmd
= NL80211_CMD_GET_REG
,
4920 .doit
= nl80211_get_reg
,
4921 .policy
= nl80211_policy
,
4922 /* can be retrieved by unprivileged users */
4925 .cmd
= NL80211_CMD_SET_REG
,
4926 .doit
= nl80211_set_reg
,
4927 .policy
= nl80211_policy
,
4928 .flags
= GENL_ADMIN_PERM
,
4931 .cmd
= NL80211_CMD_REQ_SET_REG
,
4932 .doit
= nl80211_req_set_reg
,
4933 .policy
= nl80211_policy
,
4934 .flags
= GENL_ADMIN_PERM
,
4937 .cmd
= NL80211_CMD_GET_MESH_PARAMS
,
4938 .doit
= nl80211_get_mesh_params
,
4939 .policy
= nl80211_policy
,
4940 /* can be retrieved by unprivileged users */
4943 .cmd
= NL80211_CMD_SET_MESH_PARAMS
,
4944 .doit
= nl80211_set_mesh_params
,
4945 .policy
= nl80211_policy
,
4946 .flags
= GENL_ADMIN_PERM
,
4949 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
4950 .doit
= nl80211_trigger_scan
,
4951 .policy
= nl80211_policy
,
4952 .flags
= GENL_ADMIN_PERM
,
4955 .cmd
= NL80211_CMD_GET_SCAN
,
4956 .policy
= nl80211_policy
,
4957 .dumpit
= nl80211_dump_scan
,
4960 .cmd
= NL80211_CMD_AUTHENTICATE
,
4961 .doit
= nl80211_authenticate
,
4962 .policy
= nl80211_policy
,
4963 .flags
= GENL_ADMIN_PERM
,
4966 .cmd
= NL80211_CMD_ASSOCIATE
,
4967 .doit
= nl80211_associate
,
4968 .policy
= nl80211_policy
,
4969 .flags
= GENL_ADMIN_PERM
,
4972 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
4973 .doit
= nl80211_deauthenticate
,
4974 .policy
= nl80211_policy
,
4975 .flags
= GENL_ADMIN_PERM
,
4978 .cmd
= NL80211_CMD_DISASSOCIATE
,
4979 .doit
= nl80211_disassociate
,
4980 .policy
= nl80211_policy
,
4981 .flags
= GENL_ADMIN_PERM
,
4984 .cmd
= NL80211_CMD_JOIN_IBSS
,
4985 .doit
= nl80211_join_ibss
,
4986 .policy
= nl80211_policy
,
4987 .flags
= GENL_ADMIN_PERM
,
4990 .cmd
= NL80211_CMD_LEAVE_IBSS
,
4991 .doit
= nl80211_leave_ibss
,
4992 .policy
= nl80211_policy
,
4993 .flags
= GENL_ADMIN_PERM
,
4995 #ifdef CONFIG_NL80211_TESTMODE
4997 .cmd
= NL80211_CMD_TESTMODE
,
4998 .doit
= nl80211_testmode_do
,
4999 .policy
= nl80211_policy
,
5000 .flags
= GENL_ADMIN_PERM
,
5004 .cmd
= NL80211_CMD_CONNECT
,
5005 .doit
= nl80211_connect
,
5006 .policy
= nl80211_policy
,
5007 .flags
= GENL_ADMIN_PERM
,
5010 .cmd
= NL80211_CMD_DISCONNECT
,
5011 .doit
= nl80211_disconnect
,
5012 .policy
= nl80211_policy
,
5013 .flags
= GENL_ADMIN_PERM
,
5016 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
5017 .doit
= nl80211_wiphy_netns
,
5018 .policy
= nl80211_policy
,
5019 .flags
= GENL_ADMIN_PERM
,
5022 .cmd
= NL80211_CMD_GET_SURVEY
,
5023 .policy
= nl80211_policy
,
5024 .dumpit
= nl80211_dump_survey
,
5027 .cmd
= NL80211_CMD_SET_PMKSA
,
5028 .doit
= nl80211_setdel_pmksa
,
5029 .policy
= nl80211_policy
,
5030 .flags
= GENL_ADMIN_PERM
,
5033 .cmd
= NL80211_CMD_DEL_PMKSA
,
5034 .doit
= nl80211_setdel_pmksa
,
5035 .policy
= nl80211_policy
,
5036 .flags
= GENL_ADMIN_PERM
,
5039 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
5040 .doit
= nl80211_flush_pmksa
,
5041 .policy
= nl80211_policy
,
5042 .flags
= GENL_ADMIN_PERM
,
5045 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
5046 .doit
= nl80211_remain_on_channel
,
5047 .policy
= nl80211_policy
,
5048 .flags
= GENL_ADMIN_PERM
,
5051 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
5052 .doit
= nl80211_cancel_remain_on_channel
,
5053 .policy
= nl80211_policy
,
5054 .flags
= GENL_ADMIN_PERM
,
5057 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
5058 .doit
= nl80211_set_tx_bitrate_mask
,
5059 .policy
= nl80211_policy
,
5060 .flags
= GENL_ADMIN_PERM
,
5063 .cmd
= NL80211_CMD_REGISTER_ACTION
,
5064 .doit
= nl80211_register_action
,
5065 .policy
= nl80211_policy
,
5066 .flags
= GENL_ADMIN_PERM
,
5069 .cmd
= NL80211_CMD_ACTION
,
5070 .doit
= nl80211_action
,
5071 .policy
= nl80211_policy
,
5072 .flags
= GENL_ADMIN_PERM
,
5075 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
5076 .doit
= nl80211_set_power_save
,
5077 .policy
= nl80211_policy
,
5078 .flags
= GENL_ADMIN_PERM
,
5081 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
5082 .doit
= nl80211_get_power_save
,
5083 .policy
= nl80211_policy
,
5084 /* can be retrieved by unprivileged users */
5088 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
5092 /* multicast groups */
5093 static struct genl_multicast_group nl80211_config_mcgrp
= {
5096 static struct genl_multicast_group nl80211_scan_mcgrp
= {
5099 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
5100 .name
= "regulatory",
5103 /* notification functions */
5105 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
5107 struct sk_buff
*msg
;
5109 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5113 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
5118 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5119 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
5122 static int nl80211_add_scan_req(struct sk_buff
*msg
,
5123 struct cfg80211_registered_device
*rdev
)
5125 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
5126 struct nlattr
*nest
;
5129 ASSERT_RDEV_LOCK(rdev
);
5134 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
5136 goto nla_put_failure
;
5137 for (i
= 0; i
< req
->n_ssids
; i
++)
5138 NLA_PUT(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
);
5139 nla_nest_end(msg
, nest
);
5141 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
5143 goto nla_put_failure
;
5144 for (i
= 0; i
< req
->n_channels
; i
++)
5145 NLA_PUT_U32(msg
, i
, req
->channels
[i
]->center_freq
);
5146 nla_nest_end(msg
, nest
);
5149 NLA_PUT(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
);
5156 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
5157 struct cfg80211_registered_device
*rdev
,
5158 struct net_device
*netdev
,
5159 u32 pid
, u32 seq
, int flags
,
5164 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
5168 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5169 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5171 /* ignore errors and send incomplete event anyway */
5172 nl80211_add_scan_req(msg
, rdev
);
5174 return genlmsg_end(msg
, hdr
);
5177 genlmsg_cancel(msg
, hdr
);
5181 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
5182 struct net_device
*netdev
)
5184 struct sk_buff
*msg
;
5186 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
5190 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5191 NL80211_CMD_TRIGGER_SCAN
) < 0) {
5196 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5197 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5200 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
5201 struct net_device
*netdev
)
5203 struct sk_buff
*msg
;
5205 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5209 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5210 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
5215 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5216 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5219 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
5220 struct net_device
*netdev
)
5222 struct sk_buff
*msg
;
5224 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5228 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5229 NL80211_CMD_SCAN_ABORTED
) < 0) {
5234 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5235 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5239 * This can happen on global regulatory changes or device specific settings
5240 * based on custom world regulatory domains.
5242 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
5244 struct sk_buff
*msg
;
5247 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5251 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
5257 /* Userspace can always count this one always being set */
5258 NLA_PUT_U8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
);
5260 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0')
5261 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5262 NL80211_REGDOM_TYPE_WORLD
);
5263 else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9')
5264 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5265 NL80211_REGDOM_TYPE_CUSTOM_WORLD
);
5266 else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
5268 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5269 NL80211_REGDOM_TYPE_INTERSECTION
);
5271 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5272 NL80211_REGDOM_TYPE_COUNTRY
);
5273 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, request
->alpha2
);
5276 if (wiphy_idx_valid(request
->wiphy_idx
))
5277 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
);
5279 if (genlmsg_end(msg
, hdr
) < 0) {
5285 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
5292 genlmsg_cancel(msg
, hdr
);
5296 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
5297 struct net_device
*netdev
,
5298 const u8
*buf
, size_t len
,
5299 enum nl80211_commands cmd
, gfp_t gfp
)
5301 struct sk_buff
*msg
;
5304 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5308 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
5314 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5315 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5316 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
5318 if (genlmsg_end(msg
, hdr
) < 0) {
5323 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5324 nl80211_mlme_mcgrp
.id
, gfp
);
5328 genlmsg_cancel(msg
, hdr
);
5332 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
5333 struct net_device
*netdev
, const u8
*buf
,
5334 size_t len
, gfp_t gfp
)
5336 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5337 NL80211_CMD_AUTHENTICATE
, gfp
);
5340 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
5341 struct net_device
*netdev
, const u8
*buf
,
5342 size_t len
, gfp_t gfp
)
5344 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5345 NL80211_CMD_ASSOCIATE
, gfp
);
5348 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
5349 struct net_device
*netdev
, const u8
*buf
,
5350 size_t len
, gfp_t gfp
)
5352 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5353 NL80211_CMD_DEAUTHENTICATE
, gfp
);
5356 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
5357 struct net_device
*netdev
, const u8
*buf
,
5358 size_t len
, gfp_t gfp
)
5360 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5361 NL80211_CMD_DISASSOCIATE
, gfp
);
5364 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
5365 struct net_device
*netdev
, int cmd
,
5366 const u8
*addr
, gfp_t gfp
)
5368 struct sk_buff
*msg
;
5371 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5375 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
5381 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5382 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5383 NLA_PUT_FLAG(msg
, NL80211_ATTR_TIMED_OUT
);
5384 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5386 if (genlmsg_end(msg
, hdr
) < 0) {
5391 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5392 nl80211_mlme_mcgrp
.id
, gfp
);
5396 genlmsg_cancel(msg
, hdr
);
5400 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
5401 struct net_device
*netdev
, const u8
*addr
,
5404 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
5408 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
5409 struct net_device
*netdev
, const u8
*addr
,
5412 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
5416 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
5417 struct net_device
*netdev
, const u8
*bssid
,
5418 const u8
*req_ie
, size_t req_ie_len
,
5419 const u8
*resp_ie
, size_t resp_ie_len
,
5420 u16 status
, gfp_t gfp
)
5422 struct sk_buff
*msg
;
5425 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
5429 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
5435 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5436 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5438 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
5439 NLA_PUT_U16(msg
, NL80211_ATTR_STATUS_CODE
, status
);
5441 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
5443 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
5445 if (genlmsg_end(msg
, hdr
) < 0) {
5450 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5451 nl80211_mlme_mcgrp
.id
, gfp
);
5455 genlmsg_cancel(msg
, hdr
);
5460 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
5461 struct net_device
*netdev
, const u8
*bssid
,
5462 const u8
*req_ie
, size_t req_ie_len
,
5463 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
5465 struct sk_buff
*msg
;
5468 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
5472 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
5478 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5479 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5480 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
5482 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
5484 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
5486 if (genlmsg_end(msg
, hdr
) < 0) {
5491 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5492 nl80211_mlme_mcgrp
.id
, gfp
);
5496 genlmsg_cancel(msg
, hdr
);
5501 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
5502 struct net_device
*netdev
, u16 reason
,
5503 const u8
*ie
, size_t ie_len
, bool from_ap
)
5505 struct sk_buff
*msg
;
5508 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
5512 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
5518 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5519 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5520 if (from_ap
&& reason
)
5521 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason
);
5523 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
);
5525 NLA_PUT(msg
, NL80211_ATTR_IE
, ie_len
, ie
);
5527 if (genlmsg_end(msg
, hdr
) < 0) {
5532 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5533 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
5537 genlmsg_cancel(msg
, hdr
);
5542 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
5543 struct net_device
*netdev
, const u8
*bssid
,
5546 struct sk_buff
*msg
;
5549 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5553 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
5559 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5560 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5561 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
5563 if (genlmsg_end(msg
, hdr
) < 0) {
5568 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5569 nl80211_mlme_mcgrp
.id
, gfp
);
5573 genlmsg_cancel(msg
, hdr
);
5577 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
5578 struct net_device
*netdev
, const u8
*addr
,
5579 enum nl80211_key_type key_type
, int key_id
,
5580 const u8
*tsc
, gfp_t gfp
)
5582 struct sk_buff
*msg
;
5585 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5589 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
5595 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5596 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5598 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5599 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
);
5600 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_id
);
5602 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
);
5604 if (genlmsg_end(msg
, hdr
) < 0) {
5609 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5610 nl80211_mlme_mcgrp
.id
, gfp
);
5614 genlmsg_cancel(msg
, hdr
);
5618 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
5619 struct ieee80211_channel
*channel_before
,
5620 struct ieee80211_channel
*channel_after
)
5622 struct sk_buff
*msg
;
5624 struct nlattr
*nl_freq
;
5626 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
5630 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
5637 * Since we are applying the beacon hint to a wiphy we know its
5638 * wiphy_idx is valid
5640 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
));
5643 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
5645 goto nla_put_failure
;
5646 if (nl80211_msg_put_channel(msg
, channel_before
))
5647 goto nla_put_failure
;
5648 nla_nest_end(msg
, nl_freq
);
5651 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
5653 goto nla_put_failure
;
5654 if (nl80211_msg_put_channel(msg
, channel_after
))
5655 goto nla_put_failure
;
5656 nla_nest_end(msg
, nl_freq
);
5658 if (genlmsg_end(msg
, hdr
) < 0) {
5664 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
5671 genlmsg_cancel(msg
, hdr
);
5675 static void nl80211_send_remain_on_chan_event(
5676 int cmd
, struct cfg80211_registered_device
*rdev
,
5677 struct net_device
*netdev
, u64 cookie
,
5678 struct ieee80211_channel
*chan
,
5679 enum nl80211_channel_type channel_type
,
5680 unsigned int duration
, gfp_t gfp
)
5682 struct sk_buff
*msg
;
5685 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5689 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
5695 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5696 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5697 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
);
5698 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, channel_type
);
5699 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
5701 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
)
5702 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, duration
);
5704 if (genlmsg_end(msg
, hdr
) < 0) {
5709 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5710 nl80211_mlme_mcgrp
.id
, gfp
);
5714 genlmsg_cancel(msg
, hdr
);
5718 void nl80211_send_remain_on_channel(struct cfg80211_registered_device
*rdev
,
5719 struct net_device
*netdev
, u64 cookie
,
5720 struct ieee80211_channel
*chan
,
5721 enum nl80211_channel_type channel_type
,
5722 unsigned int duration
, gfp_t gfp
)
5724 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
5725 rdev
, netdev
, cookie
, chan
,
5726 channel_type
, duration
, gfp
);
5729 void nl80211_send_remain_on_channel_cancel(
5730 struct cfg80211_registered_device
*rdev
, struct net_device
*netdev
,
5731 u64 cookie
, struct ieee80211_channel
*chan
,
5732 enum nl80211_channel_type channel_type
, gfp_t gfp
)
5734 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
5735 rdev
, netdev
, cookie
, chan
,
5736 channel_type
, 0, gfp
);
5739 void nl80211_send_sta_event(struct cfg80211_registered_device
*rdev
,
5740 struct net_device
*dev
, const u8
*mac_addr
,
5741 struct station_info
*sinfo
, gfp_t gfp
)
5743 struct sk_buff
*msg
;
5745 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
5749 if (nl80211_send_station(msg
, 0, 0, 0, dev
, mac_addr
, sinfo
) < 0) {
5754 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5755 nl80211_mlme_mcgrp
.id
, gfp
);
5758 int nl80211_send_action(struct cfg80211_registered_device
*rdev
,
5759 struct net_device
*netdev
, u32 nlpid
,
5760 int freq
, const u8
*buf
, size_t len
, gfp_t gfp
)
5762 struct sk_buff
*msg
;
5766 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5770 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ACTION
);
5776 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5777 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5778 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
5779 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
5781 err
= genlmsg_end(msg
, hdr
);
5787 err
= genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
5793 genlmsg_cancel(msg
, hdr
);
5798 void nl80211_send_action_tx_status(struct cfg80211_registered_device
*rdev
,
5799 struct net_device
*netdev
, u64 cookie
,
5800 const u8
*buf
, size_t len
, bool ack
,
5803 struct sk_buff
*msg
;
5806 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5810 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ACTION_TX_STATUS
);
5816 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5817 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5818 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
5819 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
5821 NLA_PUT_FLAG(msg
, NL80211_ATTR_ACK
);
5823 if (genlmsg_end(msg
, hdr
) < 0) {
5828 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
5832 genlmsg_cancel(msg
, hdr
);
5836 static int nl80211_netlink_notify(struct notifier_block
* nb
,
5837 unsigned long state
,
5840 struct netlink_notify
*notify
= _notify
;
5841 struct cfg80211_registered_device
*rdev
;
5842 struct wireless_dev
*wdev
;
5844 if (state
!= NETLINK_URELEASE
)
5849 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
)
5850 list_for_each_entry_rcu(wdev
, &rdev
->netdev_list
, list
)
5851 cfg80211_mlme_unregister_actions(wdev
, notify
->pid
);
5858 static struct notifier_block nl80211_netlink_notifier
= {
5859 .notifier_call
= nl80211_netlink_notify
,
5862 /* initialisation/exit functions */
5864 int nl80211_init(void)
5868 err
= genl_register_family_with_ops(&nl80211_fam
,
5869 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
5873 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
5877 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
5881 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
5885 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
5889 #ifdef CONFIG_NL80211_TESTMODE
5890 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
5895 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
5901 genl_unregister_family(&nl80211_fam
);
5905 void nl80211_exit(void)
5907 netlink_unregister_notifier(&nl80211_netlink_notifier
);
5908 genl_unregister_family(&nl80211_fam
);