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/list.h>
11 #include <linux/if_ether.h>
12 #include <linux/ieee80211.h>
13 #include <linux/nl80211.h>
14 #include <linux/rtnetlink.h>
15 #include <linux/netlink.h>
16 #include <linux/etherdevice.h>
17 #include <net/net_namespace.h>
18 #include <net/genetlink.h>
19 #include <net/cfg80211.h>
25 /* the netlink family */
26 static struct genl_family nl80211_fam
= {
27 .id
= GENL_ID_GENERATE
, /* don't bother with a hardcoded ID */
28 .name
= "nl80211", /* have users key off the name instead */
29 .hdrsize
= 0, /* no private header */
30 .version
= 1, /* no particular meaning now */
31 .maxattr
= NL80211_ATTR_MAX
,
35 /* internal helper: get rdev and dev */
36 static int get_rdev_dev_by_info_ifindex(struct genl_info
*info
,
37 struct cfg80211_registered_device
**rdev
,
38 struct net_device
**dev
)
40 struct nlattr
**attrs
= info
->attrs
;
43 if (!attrs
[NL80211_ATTR_IFINDEX
])
46 ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
47 *dev
= dev_get_by_index(genl_info_net(info
), ifindex
);
51 *rdev
= cfg80211_get_dev_from_ifindex(genl_info_net(info
), ifindex
);
54 return PTR_ERR(*rdev
);
60 /* policy for the attributes */
61 static const struct nla_policy nl80211_policy
[NL80211_ATTR_MAX
+1] = {
62 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
63 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
65 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
66 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
67 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
68 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
69 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
70 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
71 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
72 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
74 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
75 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
76 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
78 [NL80211_ATTR_MAC
] = { .type
= NLA_BINARY
, .len
= ETH_ALEN
},
79 [NL80211_ATTR_PREV_BSSID
] = { .type
= NLA_BINARY
, .len
= ETH_ALEN
},
81 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
82 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
83 .len
= WLAN_MAX_KEY_LEN
},
84 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
85 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
86 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
87 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 8 },
89 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
90 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
91 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
92 .len
= IEEE80211_MAX_DATA_LEN
},
93 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
94 .len
= IEEE80211_MAX_DATA_LEN
},
95 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
96 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
97 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
98 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
99 .len
= NL80211_MAX_SUPP_RATES
},
100 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
101 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
102 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
103 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
104 .len
= IEEE80211_MAX_MESH_ID_LEN
},
105 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
107 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
108 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
110 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
111 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
112 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
113 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
114 .len
= NL80211_MAX_SUPP_RATES
},
116 [NL80211_ATTR_MESH_PARAMS
] = { .type
= NLA_NESTED
},
118 [NL80211_ATTR_HT_CAPABILITY
] = { .type
= NLA_BINARY
,
119 .len
= NL80211_HT_CAPABILITY_LEN
},
121 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
122 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
123 .len
= IEEE80211_MAX_DATA_LEN
},
124 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
125 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
127 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
128 .len
= IEEE80211_MAX_SSID_LEN
},
129 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
130 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
131 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
132 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
133 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
134 [NL80211_ATTR_STA_FLAGS2
] = {
135 .len
= sizeof(struct nl80211_sta_flag_update
),
137 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
138 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
139 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
140 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
141 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
142 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
143 [NL80211_ATTR_PMKID
] = { .type
= NLA_BINARY
,
144 .len
= WLAN_PMKID_LEN
},
145 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
146 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
147 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
148 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
149 .len
= IEEE80211_MAX_DATA_LEN
},
150 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
151 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
154 /* policy for the attributes */
155 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
156 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
157 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
158 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
159 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 8 },
160 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
161 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
164 /* ifidx get helper */
165 static int nl80211_get_ifidx(struct netlink_callback
*cb
)
169 res
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
170 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
175 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
178 res
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
185 static bool is_valid_ie_attr(const struct nlattr
*attr
)
193 pos
= nla_data(attr
);
214 /* message building helper */
215 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 pid
, u32 seq
,
218 /* since there is no private header just add the generic one */
219 return genlmsg_put(skb
, pid
, seq
, &nl80211_fam
, flags
, cmd
);
222 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
223 struct ieee80211_channel
*chan
)
225 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
228 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
229 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_DISABLED
);
230 if (chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
231 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
);
232 if (chan
->flags
& IEEE80211_CHAN_NO_IBSS
)
233 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
);
234 if (chan
->flags
& IEEE80211_CHAN_RADAR
)
235 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_RADAR
);
237 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
238 DBM_TO_MBM(chan
->max_power
));
246 /* netlink command implementations */
254 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
256 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
257 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
262 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
263 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
265 if (tb
[NL80211_KEY_IDX
])
266 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
268 if (tb
[NL80211_KEY_DATA
]) {
269 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
270 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
273 if (tb
[NL80211_KEY_SEQ
]) {
274 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
275 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
278 if (tb
[NL80211_KEY_CIPHER
])
279 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
284 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
286 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
287 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
288 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
291 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
292 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
293 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
296 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
297 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
299 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
300 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
302 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
303 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
308 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
312 memset(k
, 0, sizeof(*k
));
315 if (info
->attrs
[NL80211_ATTR_KEY
])
316 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
318 err
= nl80211_parse_key_old(info
, k
);
323 if (k
->def
&& k
->defmgmt
)
328 if (k
->idx
< 4 || k
->idx
> 5)
331 if (k
->idx
< 0 || k
->idx
> 3)
334 if (k
->idx
< 0 || k
->idx
> 5)
342 static struct cfg80211_cached_keys
*
343 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
346 struct key_parse parse
;
348 struct cfg80211_cached_keys
*result
;
349 int rem
, err
, def
= 0;
351 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
353 return ERR_PTR(-ENOMEM
);
356 result
->defmgmt
= -1;
358 nla_for_each_nested(key
, keys
, rem
) {
359 memset(&parse
, 0, sizeof(parse
));
362 err
= nl80211_parse_key_new(key
, &parse
);
368 if (parse
.idx
< 0 || parse
.idx
> 4)
374 result
->def
= parse
.idx
;
375 } else if (parse
.defmgmt
)
377 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
381 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
382 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
383 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
384 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
393 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
395 ASSERT_WDEV_LOCK(wdev
);
397 if (!netif_running(wdev
->netdev
))
400 switch (wdev
->iftype
) {
401 case NL80211_IFTYPE_AP
:
402 case NL80211_IFTYPE_AP_VLAN
:
404 case NL80211_IFTYPE_ADHOC
:
405 if (!wdev
->current_bss
)
408 case NL80211_IFTYPE_STATION
:
409 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
419 static int nl80211_send_wiphy(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
420 struct cfg80211_registered_device
*dev
)
423 struct nlattr
*nl_bands
, *nl_band
;
424 struct nlattr
*nl_freqs
, *nl_freq
;
425 struct nlattr
*nl_rates
, *nl_rate
;
426 struct nlattr
*nl_modes
;
427 struct nlattr
*nl_cmds
;
428 enum ieee80211_band band
;
429 struct ieee80211_channel
*chan
;
430 struct ieee80211_rate
*rate
;
432 u16 ifmodes
= dev
->wiphy
.interface_modes
;
434 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
438 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
);
439 NLA_PUT_STRING(msg
, NL80211_ATTR_WIPHY_NAME
, wiphy_name(&dev
->wiphy
));
441 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
442 cfg80211_rdev_list_generation
);
444 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
445 dev
->wiphy
.retry_short
);
446 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
447 dev
->wiphy
.retry_long
);
448 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
449 dev
->wiphy
.frag_threshold
);
450 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
451 dev
->wiphy
.rts_threshold
);
452 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
453 dev
->wiphy
.coverage_class
);
455 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
456 dev
->wiphy
.max_scan_ssids
);
457 NLA_PUT_U16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
458 dev
->wiphy
.max_scan_ie_len
);
460 NLA_PUT(msg
, NL80211_ATTR_CIPHER_SUITES
,
461 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
462 dev
->wiphy
.cipher_suites
);
464 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
465 dev
->wiphy
.max_num_pmkids
);
467 nl_modes
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
);
469 goto nla_put_failure
;
474 NLA_PUT_FLAG(msg
, i
);
479 nla_nest_end(msg
, nl_modes
);
481 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
483 goto nla_put_failure
;
485 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
486 if (!dev
->wiphy
.bands
[band
])
489 nl_band
= nla_nest_start(msg
, band
);
491 goto nla_put_failure
;
494 if (dev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
) {
495 NLA_PUT(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
496 sizeof(dev
->wiphy
.bands
[band
]->ht_cap
.mcs
),
497 &dev
->wiphy
.bands
[band
]->ht_cap
.mcs
);
498 NLA_PUT_U16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
499 dev
->wiphy
.bands
[band
]->ht_cap
.cap
);
500 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
501 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_factor
);
502 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
503 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_density
);
506 /* add frequencies */
507 nl_freqs
= nla_nest_start(msg
, NL80211_BAND_ATTR_FREQS
);
509 goto nla_put_failure
;
511 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_channels
; i
++) {
512 nl_freq
= nla_nest_start(msg
, i
);
514 goto nla_put_failure
;
516 chan
= &dev
->wiphy
.bands
[band
]->channels
[i
];
518 if (nl80211_msg_put_channel(msg
, chan
))
519 goto nla_put_failure
;
521 nla_nest_end(msg
, nl_freq
);
524 nla_nest_end(msg
, nl_freqs
);
527 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
529 goto nla_put_failure
;
531 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_bitrates
; i
++) {
532 nl_rate
= nla_nest_start(msg
, i
);
534 goto nla_put_failure
;
536 rate
= &dev
->wiphy
.bands
[band
]->bitrates
[i
];
537 NLA_PUT_U32(msg
, NL80211_BITRATE_ATTR_RATE
,
539 if (rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
)
541 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
);
543 nla_nest_end(msg
, nl_rate
);
546 nla_nest_end(msg
, nl_rates
);
548 nla_nest_end(msg
, nl_band
);
550 nla_nest_end(msg
, nl_bands
);
552 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
554 goto nla_put_failure
;
559 if (dev->ops->op) { \
561 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
565 CMD(add_virtual_intf
, NEW_INTERFACE
);
566 CMD(change_virtual_intf
, SET_INTERFACE
);
567 CMD(add_key
, NEW_KEY
);
568 CMD(add_beacon
, NEW_BEACON
);
569 CMD(add_station
, NEW_STATION
);
570 CMD(add_mpath
, NEW_MPATH
);
571 CMD(set_mesh_params
, SET_MESH_PARAMS
);
572 CMD(change_bss
, SET_BSS
);
573 CMD(auth
, AUTHENTICATE
);
574 CMD(assoc
, ASSOCIATE
);
575 CMD(deauth
, DEAUTHENTICATE
);
576 CMD(disassoc
, DISASSOCIATE
);
577 CMD(join_ibss
, JOIN_IBSS
);
578 CMD(set_pmksa
, SET_PMKSA
);
579 CMD(del_pmksa
, DEL_PMKSA
);
580 CMD(flush_pmksa
, FLUSH_PMKSA
);
581 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
582 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
584 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
586 NLA_PUT_U32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
);
591 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
593 NLA_PUT_U32(msg
, i
, NL80211_CMD_CONNECT
);
596 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
598 NLA_PUT_U32(msg
, i
, NL80211_CMD_DISCONNECT
);
601 nla_nest_end(msg
, nl_cmds
);
603 return genlmsg_end(msg
, hdr
);
606 genlmsg_cancel(msg
, hdr
);
610 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
613 int start
= cb
->args
[0];
614 struct cfg80211_registered_device
*dev
;
616 mutex_lock(&cfg80211_mutex
);
617 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
618 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
622 if (nl80211_send_wiphy(skb
, NETLINK_CB(cb
->skb
).pid
,
623 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
629 mutex_unlock(&cfg80211_mutex
);
636 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
639 struct cfg80211_registered_device
*dev
;
641 dev
= cfg80211_get_dev_from_info(info
);
645 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
649 if (nl80211_send_wiphy(msg
, info
->snd_pid
, info
->snd_seq
, 0, dev
) < 0)
652 cfg80211_unlock_rdev(dev
);
654 return genlmsg_reply(msg
, info
);
659 cfg80211_unlock_rdev(dev
);
663 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
664 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
665 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
666 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
667 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
668 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
671 static int parse_txq_params(struct nlattr
*tb
[],
672 struct ieee80211_txq_params
*txq_params
)
674 if (!tb
[NL80211_TXQ_ATTR_QUEUE
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
675 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
676 !tb
[NL80211_TXQ_ATTR_AIFS
])
679 txq_params
->queue
= nla_get_u8(tb
[NL80211_TXQ_ATTR_QUEUE
]);
680 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
681 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
682 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
683 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
688 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
690 struct cfg80211_registered_device
*rdev
;
691 int result
= 0, rem_txq_params
= 0;
692 struct nlattr
*nl_txq_params
;
694 u8 retry_short
= 0, retry_long
= 0;
695 u32 frag_threshold
= 0, rts_threshold
= 0;
696 u8 coverage_class
= 0;
700 mutex_lock(&cfg80211_mutex
);
702 rdev
= __cfg80211_rdev_from_info(info
);
704 mutex_unlock(&cfg80211_mutex
);
705 result
= PTR_ERR(rdev
);
709 mutex_lock(&rdev
->mtx
);
711 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
712 result
= cfg80211_dev_rename(
713 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
715 mutex_unlock(&cfg80211_mutex
);
720 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
721 struct ieee80211_txq_params txq_params
;
722 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
724 if (!rdev
->ops
->set_txq_params
) {
725 result
= -EOPNOTSUPP
;
729 nla_for_each_nested(nl_txq_params
,
730 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
732 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
733 nla_data(nl_txq_params
),
734 nla_len(nl_txq_params
),
736 result
= parse_txq_params(tb
, &txq_params
);
740 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
747 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
748 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
753 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
754 channel_type
= nla_get_u32(info
->attrs
[
755 NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
756 if (channel_type
!= NL80211_CHAN_NO_HT
&&
757 channel_type
!= NL80211_CHAN_HT20
&&
758 channel_type
!= NL80211_CHAN_HT40PLUS
&&
759 channel_type
!= NL80211_CHAN_HT40MINUS
)
763 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
765 mutex_lock(&rdev
->devlist_mtx
);
766 result
= rdev_set_freq(rdev
, NULL
, freq
, channel_type
);
767 mutex_unlock(&rdev
->devlist_mtx
);
774 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
775 retry_short
= nla_get_u8(
776 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
777 if (retry_short
== 0) {
781 changed
|= WIPHY_PARAM_RETRY_SHORT
;
784 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
785 retry_long
= nla_get_u8(
786 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
787 if (retry_long
== 0) {
791 changed
|= WIPHY_PARAM_RETRY_LONG
;
794 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
795 frag_threshold
= nla_get_u32(
796 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
797 if (frag_threshold
< 256) {
801 if (frag_threshold
!= (u32
) -1) {
803 * Fragments (apart from the last one) are required to
804 * have even length. Make the fragmentation code
805 * simpler by stripping LSB should someone try to use
806 * odd threshold value.
808 frag_threshold
&= ~0x1;
810 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
813 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
814 rts_threshold
= nla_get_u32(
815 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
816 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
819 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
820 coverage_class
= nla_get_u8(
821 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
822 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
826 u8 old_retry_short
, old_retry_long
;
827 u32 old_frag_threshold
, old_rts_threshold
;
828 u8 old_coverage_class
;
830 if (!rdev
->ops
->set_wiphy_params
) {
831 result
= -EOPNOTSUPP
;
835 old_retry_short
= rdev
->wiphy
.retry_short
;
836 old_retry_long
= rdev
->wiphy
.retry_long
;
837 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
838 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
839 old_coverage_class
= rdev
->wiphy
.coverage_class
;
841 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
842 rdev
->wiphy
.retry_short
= retry_short
;
843 if (changed
& WIPHY_PARAM_RETRY_LONG
)
844 rdev
->wiphy
.retry_long
= retry_long
;
845 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
846 rdev
->wiphy
.frag_threshold
= frag_threshold
;
847 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
848 rdev
->wiphy
.rts_threshold
= rts_threshold
;
849 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
850 rdev
->wiphy
.coverage_class
= coverage_class
;
852 result
= rdev
->ops
->set_wiphy_params(&rdev
->wiphy
, changed
);
854 rdev
->wiphy
.retry_short
= old_retry_short
;
855 rdev
->wiphy
.retry_long
= old_retry_long
;
856 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
857 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
858 rdev
->wiphy
.coverage_class
= old_coverage_class
;
863 mutex_unlock(&rdev
->mtx
);
870 static int nl80211_send_iface(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
871 struct cfg80211_registered_device
*rdev
,
872 struct net_device
*dev
)
876 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
880 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
881 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
882 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, dev
->name
);
883 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, dev
->ieee80211_ptr
->iftype
);
885 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
886 rdev
->devlist_generation
^
887 (cfg80211_rdev_list_generation
<< 2));
889 return genlmsg_end(msg
, hdr
);
892 genlmsg_cancel(msg
, hdr
);
896 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
900 int wp_start
= cb
->args
[0];
901 int if_start
= cb
->args
[1];
902 struct cfg80211_registered_device
*rdev
;
903 struct wireless_dev
*wdev
;
905 mutex_lock(&cfg80211_mutex
);
906 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
907 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
909 if (wp_idx
< wp_start
) {
915 mutex_lock(&rdev
->devlist_mtx
);
916 list_for_each_entry(wdev
, &rdev
->netdev_list
, list
) {
917 if (if_idx
< if_start
) {
921 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).pid
,
922 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
923 rdev
, wdev
->netdev
) < 0) {
924 mutex_unlock(&rdev
->devlist_mtx
);
929 mutex_unlock(&rdev
->devlist_mtx
);
934 mutex_unlock(&cfg80211_mutex
);
936 cb
->args
[0] = wp_idx
;
937 cb
->args
[1] = if_idx
;
942 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
945 struct cfg80211_registered_device
*dev
;
946 struct net_device
*netdev
;
949 err
= get_rdev_dev_by_info_ifindex(info
, &dev
, &netdev
);
953 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
957 if (nl80211_send_iface(msg
, info
->snd_pid
, info
->snd_seq
, 0,
962 cfg80211_unlock_rdev(dev
);
964 return genlmsg_reply(msg
, info
);
970 cfg80211_unlock_rdev(dev
);
974 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
975 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
976 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
977 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
978 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
979 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
982 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
984 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
992 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
993 nla
, mntr_flags_policy
))
996 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
998 *mntrflags
|= (1<<flag
);
1003 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
1004 struct net_device
*netdev
, u8 use_4addr
,
1005 enum nl80211_iftype iftype
)
1008 if (netdev
&& netdev
->br_port
)
1014 case NL80211_IFTYPE_AP_VLAN
:
1015 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
1018 case NL80211_IFTYPE_STATION
:
1019 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
1029 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1031 struct cfg80211_registered_device
*rdev
;
1032 struct vif_params params
;
1034 enum nl80211_iftype otype
, ntype
;
1035 struct net_device
*dev
;
1036 u32 _flags
, *flags
= NULL
;
1037 bool change
= false;
1039 memset(¶ms
, 0, sizeof(params
));
1043 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1047 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
1049 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1050 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1053 if (ntype
> NL80211_IFTYPE_MAX
) {
1059 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1060 if (ntype
!= NL80211_IFTYPE_MESH_POINT
) {
1064 params
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1065 params
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1069 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1070 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1072 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
1076 params
.use_4addr
= -1;
1079 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
1080 if (ntype
!= NL80211_IFTYPE_MONITOR
) {
1084 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
1094 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
1098 if (!err
&& params
.use_4addr
!= -1)
1099 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
1103 cfg80211_unlock_rdev(rdev
);
1109 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1111 struct cfg80211_registered_device
*rdev
;
1112 struct vif_params params
;
1114 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
1117 memset(¶ms
, 0, sizeof(params
));
1119 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
1122 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1123 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1124 if (type
> NL80211_IFTYPE_MAX
)
1130 rdev
= cfg80211_get_dev_from_info(info
);
1132 err
= PTR_ERR(rdev
);
1136 if (!rdev
->ops
->add_virtual_intf
||
1137 !(rdev
->wiphy
.interface_modes
& (1 << type
))) {
1142 if (type
== NL80211_IFTYPE_MESH_POINT
&&
1143 info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1144 params
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1145 params
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1148 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1149 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1150 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
1155 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
1156 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
1158 err
= rdev
->ops
->add_virtual_intf(&rdev
->wiphy
,
1159 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
1160 type
, err
? NULL
: &flags
, ¶ms
);
1163 cfg80211_unlock_rdev(rdev
);
1169 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1171 struct cfg80211_registered_device
*rdev
;
1173 struct net_device
*dev
;
1177 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1181 if (!rdev
->ops
->del_virtual_intf
) {
1186 err
= rdev
->ops
->del_virtual_intf(&rdev
->wiphy
, dev
);
1189 cfg80211_unlock_rdev(rdev
);
1196 struct get_key_cookie
{
1197 struct sk_buff
*msg
;
1202 static void get_key_callback(void *c
, struct key_params
*params
)
1205 struct get_key_cookie
*cookie
= c
;
1208 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
1209 params
->key_len
, params
->key
);
1212 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
1213 params
->seq_len
, params
->seq
);
1216 NLA_PUT_U32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
1219 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
1221 goto nla_put_failure
;
1224 NLA_PUT(cookie
->msg
, NL80211_KEY_DATA
,
1225 params
->key_len
, params
->key
);
1228 NLA_PUT(cookie
->msg
, NL80211_KEY_SEQ
,
1229 params
->seq_len
, params
->seq
);
1232 NLA_PUT_U32(cookie
->msg
, NL80211_KEY_CIPHER
,
1235 NLA_PUT_U8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
);
1237 nla_nest_end(cookie
->msg
, key
);
1244 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
1246 struct cfg80211_registered_device
*rdev
;
1248 struct net_device
*dev
;
1250 u8
*mac_addr
= NULL
;
1251 struct get_key_cookie cookie
= {
1255 struct sk_buff
*msg
;
1257 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
1258 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1263 if (info
->attrs
[NL80211_ATTR_MAC
])
1264 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1268 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1272 if (!rdev
->ops
->get_key
) {
1277 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1283 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1284 NL80211_CMD_NEW_KEY
);
1292 cookie
.idx
= key_idx
;
1294 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1295 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
1297 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1299 err
= rdev
->ops
->get_key(&rdev
->wiphy
, dev
, key_idx
, mac_addr
,
1300 &cookie
, get_key_callback
);
1306 goto nla_put_failure
;
1308 genlmsg_end(msg
, hdr
);
1309 err
= genlmsg_reply(msg
, info
);
1317 cfg80211_unlock_rdev(rdev
);
1325 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
1327 struct cfg80211_registered_device
*rdev
;
1328 struct key_parse key
;
1330 struct net_device
*dev
;
1331 int (*func
)(struct wiphy
*wiphy
, struct net_device
*netdev
,
1334 err
= nl80211_parse_key(info
, &key
);
1341 /* only support setting default key */
1342 if (!key
.def
&& !key
.defmgmt
)
1347 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1352 func
= rdev
->ops
->set_default_key
;
1354 func
= rdev
->ops
->set_default_mgmt_key
;
1361 wdev_lock(dev
->ieee80211_ptr
);
1362 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1364 err
= func(&rdev
->wiphy
, dev
, key
.idx
);
1366 #ifdef CONFIG_CFG80211_WEXT
1368 if (func
== rdev
->ops
->set_default_key
)
1369 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
1371 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
1374 wdev_unlock(dev
->ieee80211_ptr
);
1377 cfg80211_unlock_rdev(rdev
);
1386 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
1388 struct cfg80211_registered_device
*rdev
;
1390 struct net_device
*dev
;
1391 struct key_parse key
;
1392 u8
*mac_addr
= NULL
;
1394 err
= nl80211_parse_key(info
, &key
);
1401 if (info
->attrs
[NL80211_ATTR_MAC
])
1402 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1406 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1410 if (!rdev
->ops
->add_key
) {
1415 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
, mac_addr
)) {
1420 wdev_lock(dev
->ieee80211_ptr
);
1421 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1423 err
= rdev
->ops
->add_key(&rdev
->wiphy
, dev
, key
.idx
,
1425 wdev_unlock(dev
->ieee80211_ptr
);
1428 cfg80211_unlock_rdev(rdev
);
1436 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
1438 struct cfg80211_registered_device
*rdev
;
1440 struct net_device
*dev
;
1441 u8
*mac_addr
= NULL
;
1442 struct key_parse key
;
1444 err
= nl80211_parse_key(info
, &key
);
1448 if (info
->attrs
[NL80211_ATTR_MAC
])
1449 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1453 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1457 if (!rdev
->ops
->del_key
) {
1462 wdev_lock(dev
->ieee80211_ptr
);
1463 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1465 err
= rdev
->ops
->del_key(&rdev
->wiphy
, dev
, key
.idx
, mac_addr
);
1467 #ifdef CONFIG_CFG80211_WEXT
1469 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
1470 dev
->ieee80211_ptr
->wext
.default_key
= -1;
1471 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
1472 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
1475 wdev_unlock(dev
->ieee80211_ptr
);
1478 cfg80211_unlock_rdev(rdev
);
1487 static int nl80211_addset_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1489 int (*call
)(struct wiphy
*wiphy
, struct net_device
*dev
,
1490 struct beacon_parameters
*info
);
1491 struct cfg80211_registered_device
*rdev
;
1493 struct net_device
*dev
;
1494 struct beacon_parameters params
;
1497 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]))
1502 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1506 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1511 switch (info
->genlhdr
->cmd
) {
1512 case NL80211_CMD_NEW_BEACON
:
1513 /* these are required for NEW_BEACON */
1514 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
1515 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
1516 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1521 call
= rdev
->ops
->add_beacon
;
1523 case NL80211_CMD_SET_BEACON
:
1524 call
= rdev
->ops
->set_beacon
;
1537 memset(¶ms
, 0, sizeof(params
));
1539 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
1541 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
1545 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
1546 params
.dtim_period
=
1547 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
1551 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1552 params
.head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1554 nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1558 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
1559 params
.tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1561 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1570 err
= call(&rdev
->wiphy
, dev
, ¶ms
);
1573 cfg80211_unlock_rdev(rdev
);
1581 static int nl80211_del_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1583 struct cfg80211_registered_device
*rdev
;
1585 struct net_device
*dev
;
1589 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1593 if (!rdev
->ops
->del_beacon
) {
1598 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1602 err
= rdev
->ops
->del_beacon(&rdev
->wiphy
, dev
);
1605 cfg80211_unlock_rdev(rdev
);
1613 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
1614 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
1615 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
1616 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
1617 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
1620 static int parse_station_flags(struct genl_info
*info
,
1621 struct station_parameters
*params
)
1623 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
1628 * Try parsing the new attribute first so userspace
1629 * can specify both for older kernels.
1631 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
1633 struct nl80211_sta_flag_update
*sta_flags
;
1635 sta_flags
= nla_data(nla
);
1636 params
->sta_flags_mask
= sta_flags
->mask
;
1637 params
->sta_flags_set
= sta_flags
->set
;
1638 if ((params
->sta_flags_mask
|
1639 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
1644 /* if present, parse the old attribute */
1646 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
1650 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
1651 nla
, sta_flags_policy
))
1654 params
->sta_flags_mask
= (1 << __NL80211_STA_FLAG_AFTER_LAST
) - 1;
1655 params
->sta_flags_mask
&= ~1;
1657 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++)
1659 params
->sta_flags_set
|= (1<<flag
);
1664 static int nl80211_send_station(struct sk_buff
*msg
, u32 pid
, u32 seq
,
1665 int flags
, struct net_device
*dev
,
1666 const u8
*mac_addr
, struct station_info
*sinfo
)
1669 struct nlattr
*sinfoattr
, *txrate
;
1672 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
1676 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1677 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1679 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
);
1681 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
1683 goto nla_put_failure
;
1684 if (sinfo
->filled
& STATION_INFO_INACTIVE_TIME
)
1685 NLA_PUT_U32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
1686 sinfo
->inactive_time
);
1687 if (sinfo
->filled
& STATION_INFO_RX_BYTES
)
1688 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_BYTES
,
1690 if (sinfo
->filled
& STATION_INFO_TX_BYTES
)
1691 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_BYTES
,
1693 if (sinfo
->filled
& STATION_INFO_LLID
)
1694 NLA_PUT_U16(msg
, NL80211_STA_INFO_LLID
,
1696 if (sinfo
->filled
& STATION_INFO_PLID
)
1697 NLA_PUT_U16(msg
, NL80211_STA_INFO_PLID
,
1699 if (sinfo
->filled
& STATION_INFO_PLINK_STATE
)
1700 NLA_PUT_U8(msg
, NL80211_STA_INFO_PLINK_STATE
,
1701 sinfo
->plink_state
);
1702 if (sinfo
->filled
& STATION_INFO_SIGNAL
)
1703 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL
,
1705 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
1706 txrate
= nla_nest_start(msg
, NL80211_STA_INFO_TX_BITRATE
);
1708 goto nla_put_failure
;
1710 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
1711 bitrate
= cfg80211_calculate_bitrate(&sinfo
->txrate
);
1713 NLA_PUT_U16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate
);
1715 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_MCS
)
1716 NLA_PUT_U8(msg
, NL80211_RATE_INFO_MCS
,
1718 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
)
1719 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
);
1720 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_SHORT_GI
)
1721 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_SHORT_GI
);
1723 nla_nest_end(msg
, txrate
);
1725 if (sinfo
->filled
& STATION_INFO_RX_PACKETS
)
1726 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_PACKETS
,
1728 if (sinfo
->filled
& STATION_INFO_TX_PACKETS
)
1729 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_PACKETS
,
1731 nla_nest_end(msg
, sinfoattr
);
1733 return genlmsg_end(msg
, hdr
);
1736 genlmsg_cancel(msg
, hdr
);
1740 static int nl80211_dump_station(struct sk_buff
*skb
,
1741 struct netlink_callback
*cb
)
1743 struct station_info sinfo
;
1744 struct cfg80211_registered_device
*dev
;
1745 struct net_device
*netdev
;
1746 u8 mac_addr
[ETH_ALEN
];
1747 int ifidx
= cb
->args
[0];
1748 int sta_idx
= cb
->args
[1];
1752 ifidx
= nl80211_get_ifidx(cb
);
1758 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
1764 dev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
1770 if (!dev
->ops
->dump_station
) {
1776 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
1783 if (nl80211_send_station(skb
,
1784 NETLINK_CB(cb
->skb
).pid
,
1785 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1795 cb
->args
[1] = sta_idx
;
1798 cfg80211_unlock_rdev(dev
);
1805 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
1807 struct cfg80211_registered_device
*rdev
;
1809 struct net_device
*dev
;
1810 struct station_info sinfo
;
1811 struct sk_buff
*msg
;
1812 u8
*mac_addr
= NULL
;
1814 memset(&sinfo
, 0, sizeof(sinfo
));
1816 if (!info
->attrs
[NL80211_ATTR_MAC
])
1819 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1823 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1827 if (!rdev
->ops
->get_station
) {
1832 err
= rdev
->ops
->get_station(&rdev
->wiphy
, dev
, mac_addr
, &sinfo
);
1836 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1840 if (nl80211_send_station(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1841 dev
, mac_addr
, &sinfo
) < 0)
1844 err
= genlmsg_reply(msg
, info
);
1850 cfg80211_unlock_rdev(rdev
);
1859 * Get vlan interface making sure it is running and on the right wiphy.
1861 static int get_vlan(struct genl_info
*info
,
1862 struct cfg80211_registered_device
*rdev
,
1863 struct net_device
**vlan
)
1865 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
1869 *vlan
= dev_get_by_index(genl_info_net(info
),
1870 nla_get_u32(vlanattr
));
1873 if (!(*vlan
)->ieee80211_ptr
)
1875 if ((*vlan
)->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
)
1877 if (!netif_running(*vlan
))
1883 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
1885 struct cfg80211_registered_device
*rdev
;
1887 struct net_device
*dev
;
1888 struct station_parameters params
;
1889 u8
*mac_addr
= NULL
;
1891 memset(¶ms
, 0, sizeof(params
));
1893 params
.listen_interval
= -1;
1895 if (info
->attrs
[NL80211_ATTR_STA_AID
])
1898 if (!info
->attrs
[NL80211_ATTR_MAC
])
1901 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1903 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
1904 params
.supported_rates
=
1905 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1906 params
.supported_rates_len
=
1907 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1910 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
1911 params
.listen_interval
=
1912 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
1914 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
1916 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
1918 if (parse_station_flags(info
, ¶ms
))
1921 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
1922 params
.plink_action
=
1923 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
1927 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1931 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
1935 /* validate settings */
1938 switch (dev
->ieee80211_ptr
->iftype
) {
1939 case NL80211_IFTYPE_AP
:
1940 case NL80211_IFTYPE_AP_VLAN
:
1941 /* disallow mesh-specific things */
1942 if (params
.plink_action
)
1945 case NL80211_IFTYPE_STATION
:
1946 /* disallow everything but AUTHORIZED flag */
1947 if (params
.plink_action
)
1951 if (params
.supported_rates
)
1955 if (params
.listen_interval
>= 0)
1957 if (params
.sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
1960 case NL80211_IFTYPE_MESH_POINT
:
1961 /* disallow things mesh doesn't support */
1966 if (params
.listen_interval
>= 0)
1968 if (params
.supported_rates
)
1970 if (params
.sta_flags_mask
)
1980 if (!rdev
->ops
->change_station
) {
1985 err
= rdev
->ops
->change_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
1989 dev_put(params
.vlan
);
1990 cfg80211_unlock_rdev(rdev
);
1998 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
2000 struct cfg80211_registered_device
*rdev
;
2002 struct net_device
*dev
;
2003 struct station_parameters params
;
2004 u8
*mac_addr
= NULL
;
2006 memset(¶ms
, 0, sizeof(params
));
2008 if (!info
->attrs
[NL80211_ATTR_MAC
])
2011 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2014 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
2017 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
2020 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2021 params
.supported_rates
=
2022 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2023 params
.supported_rates_len
=
2024 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2025 params
.listen_interval
=
2026 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2028 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
2029 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
2032 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2034 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2036 if (parse_station_flags(info
, ¶ms
))
2041 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2045 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2046 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
) {
2051 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
2055 /* validate settings */
2058 if (!rdev
->ops
->add_station
) {
2063 if (!netif_running(dev
)) {
2068 err
= rdev
->ops
->add_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2072 dev_put(params
.vlan
);
2073 cfg80211_unlock_rdev(rdev
);
2081 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
2083 struct cfg80211_registered_device
*rdev
;
2085 struct net_device
*dev
;
2086 u8
*mac_addr
= NULL
;
2088 if (info
->attrs
[NL80211_ATTR_MAC
])
2089 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2093 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2097 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2098 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
) {
2103 if (!rdev
->ops
->del_station
) {
2108 err
= rdev
->ops
->del_station(&rdev
->wiphy
, dev
, mac_addr
);
2111 cfg80211_unlock_rdev(rdev
);
2119 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2120 int flags
, struct net_device
*dev
,
2121 u8
*dst
, u8
*next_hop
,
2122 struct mpath_info
*pinfo
)
2125 struct nlattr
*pinfoattr
;
2127 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2131 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2132 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
2133 NLA_PUT(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
);
2135 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
);
2137 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
2139 goto nla_put_failure
;
2140 if (pinfo
->filled
& MPATH_INFO_FRAME_QLEN
)
2141 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
2143 if (pinfo
->filled
& MPATH_INFO_SN
)
2144 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_SN
,
2146 if (pinfo
->filled
& MPATH_INFO_METRIC
)
2147 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_METRIC
,
2149 if (pinfo
->filled
& MPATH_INFO_EXPTIME
)
2150 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_EXPTIME
,
2152 if (pinfo
->filled
& MPATH_INFO_FLAGS
)
2153 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_FLAGS
,
2155 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
)
2156 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
2157 pinfo
->discovery_timeout
);
2158 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
)
2159 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
2160 pinfo
->discovery_retries
);
2162 nla_nest_end(msg
, pinfoattr
);
2164 return genlmsg_end(msg
, hdr
);
2167 genlmsg_cancel(msg
, hdr
);
2171 static int nl80211_dump_mpath(struct sk_buff
*skb
,
2172 struct netlink_callback
*cb
)
2174 struct mpath_info pinfo
;
2175 struct cfg80211_registered_device
*dev
;
2176 struct net_device
*netdev
;
2178 u8 next_hop
[ETH_ALEN
];
2179 int ifidx
= cb
->args
[0];
2180 int path_idx
= cb
->args
[1];
2184 ifidx
= nl80211_get_ifidx(cb
);
2190 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
2196 dev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
2202 if (!dev
->ops
->dump_mpath
) {
2207 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2213 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
2214 dst
, next_hop
, &pinfo
);
2220 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).pid
,
2221 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2222 netdev
, dst
, next_hop
,
2231 cb
->args
[1] = path_idx
;
2234 cfg80211_unlock_rdev(dev
);
2241 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2243 struct cfg80211_registered_device
*rdev
;
2245 struct net_device
*dev
;
2246 struct mpath_info pinfo
;
2247 struct sk_buff
*msg
;
2249 u8 next_hop
[ETH_ALEN
];
2251 memset(&pinfo
, 0, sizeof(pinfo
));
2253 if (!info
->attrs
[NL80211_ATTR_MAC
])
2256 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2260 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2264 if (!rdev
->ops
->get_mpath
) {
2269 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2274 err
= rdev
->ops
->get_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
2278 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2282 if (nl80211_send_mpath(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2283 dev
, dst
, next_hop
, &pinfo
) < 0)
2286 err
= genlmsg_reply(msg
, info
);
2292 cfg80211_unlock_rdev(rdev
);
2300 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2302 struct cfg80211_registered_device
*rdev
;
2304 struct net_device
*dev
;
2306 u8
*next_hop
= NULL
;
2308 if (!info
->attrs
[NL80211_ATTR_MAC
])
2311 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2314 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2315 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2319 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2323 if (!rdev
->ops
->change_mpath
) {
2328 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2333 if (!netif_running(dev
)) {
2338 err
= rdev
->ops
->change_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2341 cfg80211_unlock_rdev(rdev
);
2348 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2350 struct cfg80211_registered_device
*rdev
;
2352 struct net_device
*dev
;
2354 u8
*next_hop
= NULL
;
2356 if (!info
->attrs
[NL80211_ATTR_MAC
])
2359 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2362 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2363 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2367 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2371 if (!rdev
->ops
->add_mpath
) {
2376 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2381 if (!netif_running(dev
)) {
2386 err
= rdev
->ops
->add_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2389 cfg80211_unlock_rdev(rdev
);
2397 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2399 struct cfg80211_registered_device
*rdev
;
2401 struct net_device
*dev
;
2404 if (info
->attrs
[NL80211_ATTR_MAC
])
2405 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2409 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2413 if (!rdev
->ops
->del_mpath
) {
2418 err
= rdev
->ops
->del_mpath(&rdev
->wiphy
, dev
, dst
);
2421 cfg80211_unlock_rdev(rdev
);
2429 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
2431 struct cfg80211_registered_device
*rdev
;
2433 struct net_device
*dev
;
2434 struct bss_parameters params
;
2436 memset(¶ms
, 0, sizeof(params
));
2437 /* default to not changing parameters */
2438 params
.use_cts_prot
= -1;
2439 params
.use_short_preamble
= -1;
2440 params
.use_short_slot_time
= -1;
2442 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
2443 params
.use_cts_prot
=
2444 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
2445 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
2446 params
.use_short_preamble
=
2447 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
2448 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
2449 params
.use_short_slot_time
=
2450 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
2451 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
2452 params
.basic_rates
=
2453 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2454 params
.basic_rates_len
=
2455 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2460 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2464 if (!rdev
->ops
->change_bss
) {
2469 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
2474 err
= rdev
->ops
->change_bss(&rdev
->wiphy
, dev
, ¶ms
);
2477 cfg80211_unlock_rdev(rdev
);
2485 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
2486 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
2487 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
2488 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
2489 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
2490 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
2491 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
2494 static int parse_reg_rule(struct nlattr
*tb
[],
2495 struct ieee80211_reg_rule
*reg_rule
)
2497 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
2498 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
2500 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
2502 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
2504 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
2506 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
2508 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
2511 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
2513 freq_range
->start_freq_khz
=
2514 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
2515 freq_range
->end_freq_khz
=
2516 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
2517 freq_range
->max_bandwidth_khz
=
2518 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
2520 power_rule
->max_eirp
=
2521 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
2523 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
2524 power_rule
->max_antenna_gain
=
2525 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
2530 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2536 * You should only get this when cfg80211 hasn't yet initialized
2537 * completely when built-in to the kernel right between the time
2538 * window between nl80211_init() and regulatory_init(), if that is
2541 mutex_lock(&cfg80211_mutex
);
2542 if (unlikely(!cfg80211_regdomain
)) {
2543 mutex_unlock(&cfg80211_mutex
);
2544 return -EINPROGRESS
;
2546 mutex_unlock(&cfg80211_mutex
);
2548 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2551 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2553 r
= regulatory_hint_user(data
);
2558 static int nl80211_get_mesh_params(struct sk_buff
*skb
,
2559 struct genl_info
*info
)
2561 struct cfg80211_registered_device
*rdev
;
2562 struct mesh_config cur_params
;
2564 struct net_device
*dev
;
2566 struct nlattr
*pinfoattr
;
2567 struct sk_buff
*msg
;
2571 /* Look up our device */
2572 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2576 if (!rdev
->ops
->get_mesh_params
) {
2581 /* Get the mesh params */
2582 err
= rdev
->ops
->get_mesh_params(&rdev
->wiphy
, dev
, &cur_params
);
2586 /* Draw up a netlink message to send back */
2587 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2592 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2593 NL80211_CMD_GET_MESH_PARAMS
);
2595 goto nla_put_failure
;
2596 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_PARAMS
);
2598 goto nla_put_failure
;
2599 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2600 NLA_PUT_U16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
2601 cur_params
.dot11MeshRetryTimeout
);
2602 NLA_PUT_U16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
2603 cur_params
.dot11MeshConfirmTimeout
);
2604 NLA_PUT_U16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
2605 cur_params
.dot11MeshHoldingTimeout
);
2606 NLA_PUT_U16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
2607 cur_params
.dot11MeshMaxPeerLinks
);
2608 NLA_PUT_U8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
2609 cur_params
.dot11MeshMaxRetries
);
2610 NLA_PUT_U8(msg
, NL80211_MESHCONF_TTL
,
2611 cur_params
.dot11MeshTTL
);
2612 NLA_PUT_U8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
2613 cur_params
.auto_open_plinks
);
2614 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2615 cur_params
.dot11MeshHWMPmaxPREQretries
);
2616 NLA_PUT_U32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
2617 cur_params
.path_refresh_time
);
2618 NLA_PUT_U16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2619 cur_params
.min_discovery_timeout
);
2620 NLA_PUT_U32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2621 cur_params
.dot11MeshHWMPactivePathTimeout
);
2622 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2623 cur_params
.dot11MeshHWMPpreqMinInterval
);
2624 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2625 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
);
2626 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
2627 cur_params
.dot11MeshHWMPRootMode
);
2628 nla_nest_end(msg
, pinfoattr
);
2629 genlmsg_end(msg
, hdr
);
2630 err
= genlmsg_reply(msg
, info
);
2634 genlmsg_cancel(msg
, hdr
);
2638 cfg80211_unlock_rdev(rdev
);
2646 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2648 if (table[attr_num]) {\
2649 cfg.param = nla_fn(table[attr_num]); \
2650 mask |= (1 << (attr_num - 1)); \
2654 static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
2655 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
2656 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
2657 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
2658 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
2659 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
2660 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
2661 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
2663 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
2664 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
2665 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
2666 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
2667 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
2668 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
2671 static int nl80211_set_mesh_params(struct sk_buff
*skb
, struct genl_info
*info
)
2675 struct cfg80211_registered_device
*rdev
;
2676 struct net_device
*dev
;
2677 struct mesh_config cfg
;
2678 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
2679 struct nlattr
*parent_attr
;
2681 parent_attr
= info
->attrs
[NL80211_ATTR_MESH_PARAMS
];
2684 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
2685 parent_attr
, nl80211_meshconf_params_policy
))
2690 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2694 if (!rdev
->ops
->set_mesh_params
) {
2699 /* This makes sure that there aren't more than 32 mesh config
2700 * parameters (otherwise our bitfield scheme would not work.) */
2701 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
2703 /* Fill in the params struct */
2705 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
2706 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
, nla_get_u16
);
2707 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
2708 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
, nla_get_u16
);
2709 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
2710 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
, nla_get_u16
);
2711 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
2712 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
, nla_get_u16
);
2713 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
2714 mask
, NL80211_MESHCONF_MAX_RETRIES
, nla_get_u8
);
2715 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
2716 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
2717 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
2718 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
, nla_get_u8
);
2719 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
2720 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2722 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
2723 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
, nla_get_u32
);
2724 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
2725 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2727 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
2728 mask
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2730 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
2731 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2733 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
2734 dot11MeshHWMPnetDiameterTraversalTime
,
2735 mask
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2737 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
2738 dot11MeshHWMPRootMode
, mask
,
2739 NL80211_MESHCONF_HWMP_ROOTMODE
,
2743 err
= rdev
->ops
->set_mesh_params(&rdev
->wiphy
, dev
, &cfg
, mask
);
2747 cfg80211_unlock_rdev(rdev
);
2755 #undef FILL_IN_MESH_PARAM_IF_SET
2757 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2759 struct sk_buff
*msg
;
2761 struct nlattr
*nl_reg_rules
;
2765 mutex_lock(&cfg80211_mutex
);
2767 if (!cfg80211_regdomain
)
2770 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2776 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2777 NL80211_CMD_GET_REG
);
2779 goto nla_put_failure
;
2781 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
,
2782 cfg80211_regdomain
->alpha2
);
2784 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
2786 goto nla_put_failure
;
2788 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
2789 struct nlattr
*nl_reg_rule
;
2790 const struct ieee80211_reg_rule
*reg_rule
;
2791 const struct ieee80211_freq_range
*freq_range
;
2792 const struct ieee80211_power_rule
*power_rule
;
2794 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
2795 freq_range
= ®_rule
->freq_range
;
2796 power_rule
= ®_rule
->power_rule
;
2798 nl_reg_rule
= nla_nest_start(msg
, i
);
2800 goto nla_put_failure
;
2802 NLA_PUT_U32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
2804 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
2805 freq_range
->start_freq_khz
);
2806 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
2807 freq_range
->end_freq_khz
);
2808 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
2809 freq_range
->max_bandwidth_khz
);
2810 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
2811 power_rule
->max_antenna_gain
);
2812 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
2813 power_rule
->max_eirp
);
2815 nla_nest_end(msg
, nl_reg_rule
);
2818 nla_nest_end(msg
, nl_reg_rules
);
2820 genlmsg_end(msg
, hdr
);
2821 err
= genlmsg_reply(msg
, info
);
2825 genlmsg_cancel(msg
, hdr
);
2828 mutex_unlock(&cfg80211_mutex
);
2832 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2834 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
2835 struct nlattr
*nl_reg_rule
;
2836 char *alpha2
= NULL
;
2837 int rem_reg_rules
= 0, r
= 0;
2838 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
2839 struct ieee80211_regdomain
*rd
= NULL
;
2841 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2844 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
2847 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2849 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
2852 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
2856 mutex_lock(&cfg80211_mutex
);
2858 if (!reg_is_valid_request(alpha2
)) {
2863 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
2864 (num_rules
* sizeof(struct ieee80211_reg_rule
));
2866 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
2872 rd
->n_reg_rules
= num_rules
;
2873 rd
->alpha2
[0] = alpha2
[0];
2874 rd
->alpha2
[1] = alpha2
[1];
2876 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
2878 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
2879 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
2881 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
2887 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
2893 BUG_ON(rule_idx
!= num_rules
);
2897 mutex_unlock(&cfg80211_mutex
);
2902 mutex_unlock(&cfg80211_mutex
);
2907 static int validate_scan_freqs(struct nlattr
*freqs
)
2909 struct nlattr
*attr1
, *attr2
;
2910 int n_channels
= 0, tmp1
, tmp2
;
2912 nla_for_each_nested(attr1
, freqs
, tmp1
) {
2915 * Some hardware has a limited channel list for
2916 * scanning, and it is pretty much nonsensical
2917 * to scan for a channel twice, so disallow that
2918 * and don't require drivers to check that the
2919 * channel list they get isn't longer than what
2920 * they can scan, as long as they can scan all
2921 * the channels they registered at once.
2923 nla_for_each_nested(attr2
, freqs
, tmp2
)
2924 if (attr1
!= attr2
&&
2925 nla_get_u32(attr1
) == nla_get_u32(attr2
))
2932 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
2934 struct cfg80211_registered_device
*rdev
;
2935 struct net_device
*dev
;
2936 struct cfg80211_scan_request
*request
;
2937 struct cfg80211_ssid
*ssid
;
2938 struct ieee80211_channel
*channel
;
2939 struct nlattr
*attr
;
2940 struct wiphy
*wiphy
;
2941 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
2942 enum ieee80211_band band
;
2945 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
2950 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2954 wiphy
= &rdev
->wiphy
;
2956 if (!rdev
->ops
->scan
) {
2961 if (!netif_running(dev
)) {
2966 if (rdev
->scan_req
) {
2971 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
2972 n_channels
= validate_scan_freqs(
2973 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
2981 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
2982 if (wiphy
->bands
[band
])
2983 n_channels
+= wiphy
->bands
[band
]->n_channels
;
2986 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
2987 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
2990 if (n_ssids
> wiphy
->max_scan_ssids
) {
2995 if (info
->attrs
[NL80211_ATTR_IE
])
2996 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3000 if (ie_len
> wiphy
->max_scan_ie_len
) {
3005 request
= kzalloc(sizeof(*request
)
3006 + sizeof(*ssid
) * n_ssids
3007 + sizeof(channel
) * n_channels
3008 + ie_len
, GFP_KERNEL
);
3015 request
->ssids
= (void *)&request
->channels
[n_channels
];
3016 request
->n_ssids
= n_ssids
;
3019 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
3021 request
->ie
= (void *)(request
->channels
+ n_channels
);
3025 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3026 /* user specified, bail out if channel not found */
3027 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
3028 struct ieee80211_channel
*chan
;
3030 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
3037 /* ignore disabled channels */
3038 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3041 request
->channels
[i
] = chan
;
3046 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
3048 if (!wiphy
->bands
[band
])
3050 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
3051 struct ieee80211_channel
*chan
;
3053 chan
= &wiphy
->bands
[band
]->channels
[j
];
3055 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3058 request
->channels
[i
] = chan
;
3069 request
->n_channels
= i
;
3072 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
3073 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
3074 if (request
->ssids
[i
].ssid_len
> IEEE80211_MAX_SSID_LEN
) {
3078 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
3079 request
->ssids
[i
].ssid_len
= nla_len(attr
);
3084 if (info
->attrs
[NL80211_ATTR_IE
]) {
3085 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3086 memcpy((void *)request
->ie
,
3087 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
3092 request
->wiphy
= &rdev
->wiphy
;
3094 rdev
->scan_req
= request
;
3095 err
= rdev
->ops
->scan(&rdev
->wiphy
, dev
, request
);
3098 nl80211_send_scan_start(rdev
, dev
);
3104 rdev
->scan_req
= NULL
;
3108 cfg80211_unlock_rdev(rdev
);
3116 static int nl80211_send_bss(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
3117 struct cfg80211_registered_device
*rdev
,
3118 struct wireless_dev
*wdev
,
3119 struct cfg80211_internal_bss
*intbss
)
3121 struct cfg80211_bss
*res
= &intbss
->pub
;
3126 ASSERT_WDEV_LOCK(wdev
);
3128 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3129 NL80211_CMD_NEW_SCAN_RESULTS
);
3133 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
);
3134 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
);
3136 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
3138 goto nla_put_failure
;
3139 if (!is_zero_ether_addr(res
->bssid
))
3140 NLA_PUT(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
);
3141 if (res
->information_elements
&& res
->len_information_elements
)
3142 NLA_PUT(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
3143 res
->len_information_elements
,
3144 res
->information_elements
);
3145 if (res
->beacon_ies
&& res
->len_beacon_ies
&&
3146 res
->beacon_ies
!= res
->information_elements
)
3147 NLA_PUT(msg
, NL80211_BSS_BEACON_IES
,
3148 res
->len_beacon_ies
, res
->beacon_ies
);
3150 NLA_PUT_U64(msg
, NL80211_BSS_TSF
, res
->tsf
);
3151 if (res
->beacon_interval
)
3152 NLA_PUT_U16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
);
3153 NLA_PUT_U16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
);
3154 NLA_PUT_U32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
);
3155 NLA_PUT_U32(msg
, NL80211_BSS_SEEN_MS_AGO
,
3156 jiffies_to_msecs(jiffies
- intbss
->ts
));
3158 switch (rdev
->wiphy
.signal_type
) {
3159 case CFG80211_SIGNAL_TYPE_MBM
:
3160 NLA_PUT_U32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
);
3162 case CFG80211_SIGNAL_TYPE_UNSPEC
:
3163 NLA_PUT_U8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
);
3169 switch (wdev
->iftype
) {
3170 case NL80211_IFTYPE_STATION
:
3171 if (intbss
== wdev
->current_bss
)
3172 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3173 NL80211_BSS_STATUS_ASSOCIATED
);
3174 else for (i
= 0; i
< MAX_AUTH_BSSES
; i
++) {
3175 if (intbss
!= wdev
->auth_bsses
[i
])
3177 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3178 NL80211_BSS_STATUS_AUTHENTICATED
);
3182 case NL80211_IFTYPE_ADHOC
:
3183 if (intbss
== wdev
->current_bss
)
3184 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3185 NL80211_BSS_STATUS_IBSS_JOINED
);
3191 nla_nest_end(msg
, bss
);
3193 return genlmsg_end(msg
, hdr
);
3196 genlmsg_cancel(msg
, hdr
);
3200 static int nl80211_dump_scan(struct sk_buff
*skb
,
3201 struct netlink_callback
*cb
)
3203 struct cfg80211_registered_device
*rdev
;
3204 struct net_device
*dev
;
3205 struct cfg80211_internal_bss
*scan
;
3206 struct wireless_dev
*wdev
;
3207 int ifidx
= cb
->args
[0];
3208 int start
= cb
->args
[1], idx
= 0;
3212 ifidx
= nl80211_get_ifidx(cb
);
3215 cb
->args
[0] = ifidx
;
3217 dev
= dev_get_by_index(sock_net(skb
->sk
), ifidx
);
3221 rdev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
3223 err
= PTR_ERR(rdev
);
3224 goto out_put_netdev
;
3227 wdev
= dev
->ieee80211_ptr
;
3230 spin_lock_bh(&rdev
->bss_lock
);
3231 cfg80211_bss_expire(rdev
);
3233 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
3236 if (nl80211_send_bss(skb
,
3237 NETLINK_CB(cb
->skb
).pid
,
3238 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3239 rdev
, wdev
, scan
) < 0) {
3246 spin_unlock_bh(&rdev
->bss_lock
);
3251 cfg80211_unlock_rdev(rdev
);
3258 static int nl80211_send_survey(struct sk_buff
*msg
, u32 pid
, u32 seq
,
3259 int flags
, struct net_device
*dev
,
3260 struct survey_info
*survey
)
3263 struct nlattr
*infoattr
;
3265 /* Survey without a channel doesn't make sense */
3266 if (!survey
->channel
)
3269 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3270 NL80211_CMD_NEW_SURVEY_RESULTS
);
3274 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
3276 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
3278 goto nla_put_failure
;
3280 NLA_PUT_U32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
3281 survey
->channel
->center_freq
);
3282 if (survey
->filled
& SURVEY_INFO_NOISE_DBM
)
3283 NLA_PUT_U8(msg
, NL80211_SURVEY_INFO_NOISE
,
3286 nla_nest_end(msg
, infoattr
);
3288 return genlmsg_end(msg
, hdr
);
3291 genlmsg_cancel(msg
, hdr
);
3295 static int nl80211_dump_survey(struct sk_buff
*skb
,
3296 struct netlink_callback
*cb
)
3298 struct survey_info survey
;
3299 struct cfg80211_registered_device
*dev
;
3300 struct net_device
*netdev
;
3301 int ifidx
= cb
->args
[0];
3302 int survey_idx
= cb
->args
[1];
3306 ifidx
= nl80211_get_ifidx(cb
);
3309 cb
->args
[0] = ifidx
;
3313 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
3319 dev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
3325 if (!dev
->ops
->dump_survey
) {
3331 res
= dev
->ops
->dump_survey(&dev
->wiphy
, netdev
, survey_idx
,
3338 if (nl80211_send_survey(skb
,
3339 NETLINK_CB(cb
->skb
).pid
,
3340 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3348 cb
->args
[1] = survey_idx
;
3351 cfg80211_unlock_rdev(dev
);
3358 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
)
3360 return auth_type
<= NL80211_AUTHTYPE_MAX
;
3363 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
3365 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
3366 NL80211_WPA_VERSION_2
));
3369 static bool nl80211_valid_akm_suite(u32 akm
)
3371 return akm
== WLAN_AKM_SUITE_8021X
||
3372 akm
== WLAN_AKM_SUITE_PSK
;
3375 static bool nl80211_valid_cipher_suite(u32 cipher
)
3377 return cipher
== WLAN_CIPHER_SUITE_WEP40
||
3378 cipher
== WLAN_CIPHER_SUITE_WEP104
||
3379 cipher
== WLAN_CIPHER_SUITE_TKIP
||
3380 cipher
== WLAN_CIPHER_SUITE_CCMP
||
3381 cipher
== WLAN_CIPHER_SUITE_AES_CMAC
;
3385 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3387 struct cfg80211_registered_device
*rdev
;
3388 struct net_device
*dev
;
3389 struct ieee80211_channel
*chan
;
3390 const u8
*bssid
, *ssid
, *ie
= NULL
;
3391 int err
, ssid_len
, ie_len
= 0;
3392 enum nl80211_auth_type auth_type
;
3393 struct key_parse key
;
3395 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3398 if (!info
->attrs
[NL80211_ATTR_MAC
])
3401 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
3404 if (!info
->attrs
[NL80211_ATTR_SSID
])
3407 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
3410 err
= nl80211_parse_key(info
, &key
);
3415 if (!key
.p
.key
|| !key
.p
.key_len
)
3417 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
3418 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
3419 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
3420 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
3431 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3435 if (!rdev
->ops
->auth
) {
3440 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3445 if (!netif_running(dev
)) {
3450 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3451 chan
= ieee80211_get_channel(&rdev
->wiphy
,
3452 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3453 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
)) {
3458 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3459 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3461 if (info
->attrs
[NL80211_ATTR_IE
]) {
3462 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3463 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3466 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3467 if (!nl80211_valid_auth_type(auth_type
)) {
3472 err
= cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
3473 ssid
, ssid_len
, ie
, ie_len
,
3474 key
.p
.key
, key
.p
.key_len
, key
.idx
);
3477 cfg80211_unlock_rdev(rdev
);
3484 static int nl80211_crypto_settings(struct genl_info
*info
,
3485 struct cfg80211_crypto_settings
*settings
,
3488 memset(settings
, 0, sizeof(*settings
));
3490 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
3492 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
3496 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
3497 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
3498 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
3500 if (len
% sizeof(u32
))
3503 if (settings
->n_ciphers_pairwise
> cipher_limit
)
3506 memcpy(settings
->ciphers_pairwise
, data
, len
);
3508 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
3509 if (!nl80211_valid_cipher_suite(
3510 settings
->ciphers_pairwise
[i
]))
3514 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
3515 settings
->cipher_group
=
3516 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
3517 if (!nl80211_valid_cipher_suite(settings
->cipher_group
))
3521 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
3522 settings
->wpa_versions
=
3523 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
3524 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
3528 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
3532 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
3533 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
3534 settings
->n_akm_suites
= len
/ sizeof(u32
);
3536 if (len
% sizeof(u32
))
3539 memcpy(settings
->akm_suites
, data
, len
);
3541 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
3542 if (!nl80211_valid_akm_suite(settings
->akm_suites
[i
]))
3549 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
3551 struct cfg80211_registered_device
*rdev
;
3552 struct net_device
*dev
;
3553 struct wireless_dev
*wdev
;
3554 struct cfg80211_crypto_settings crypto
;
3555 struct ieee80211_channel
*chan
, *fixedchan
;
3556 const u8
*bssid
, *ssid
, *ie
= NULL
, *prev_bssid
= NULL
;
3557 int err
, ssid_len
, ie_len
= 0;
3558 bool use_mfp
= false;
3560 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3563 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
3564 !info
->attrs
[NL80211_ATTR_SSID
] ||
3565 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
3570 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3574 if (!rdev
->ops
->assoc
) {
3579 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3584 if (!netif_running(dev
)) {
3589 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3591 chan
= ieee80211_get_channel(&rdev
->wiphy
,
3592 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3593 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
)) {
3598 mutex_lock(&rdev
->devlist_mtx
);
3599 wdev
= dev
->ieee80211_ptr
;
3600 fixedchan
= rdev_fixed_channel(rdev
, wdev
);
3601 if (fixedchan
&& chan
!= fixedchan
) {
3603 mutex_unlock(&rdev
->devlist_mtx
);
3606 mutex_unlock(&rdev
->devlist_mtx
);
3608 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3609 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3611 if (info
->attrs
[NL80211_ATTR_IE
]) {
3612 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3613 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3616 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
3617 enum nl80211_mfp mfp
=
3618 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
3619 if (mfp
== NL80211_MFP_REQUIRED
)
3621 else if (mfp
!= NL80211_MFP_NO
) {
3627 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
3628 prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
3630 err
= nl80211_crypto_settings(info
, &crypto
, 1);
3632 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
, prev_bssid
,
3633 ssid
, ssid_len
, ie
, ie_len
, use_mfp
,
3637 cfg80211_unlock_rdev(rdev
);
3644 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3646 struct cfg80211_registered_device
*rdev
;
3647 struct net_device
*dev
;
3648 const u8
*ie
= NULL
, *bssid
;
3649 int err
, ie_len
= 0;
3652 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3655 if (!info
->attrs
[NL80211_ATTR_MAC
])
3658 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3663 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3667 if (!rdev
->ops
->deauth
) {
3672 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3677 if (!netif_running(dev
)) {
3682 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3684 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3685 if (reason_code
== 0) {
3686 /* Reason Code 0 is reserved */
3691 if (info
->attrs
[NL80211_ATTR_IE
]) {
3692 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3693 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3696 err
= cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
);
3699 cfg80211_unlock_rdev(rdev
);
3706 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
3708 struct cfg80211_registered_device
*rdev
;
3709 struct net_device
*dev
;
3710 const u8
*ie
= NULL
, *bssid
;
3711 int err
, ie_len
= 0;
3714 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3717 if (!info
->attrs
[NL80211_ATTR_MAC
])
3720 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3725 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3729 if (!rdev
->ops
->disassoc
) {
3734 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3739 if (!netif_running(dev
)) {
3744 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3746 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3747 if (reason_code
== 0) {
3748 /* Reason Code 0 is reserved */
3753 if (info
->attrs
[NL80211_ATTR_IE
]) {
3754 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3755 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3758 err
= cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
);
3761 cfg80211_unlock_rdev(rdev
);
3768 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
3770 struct cfg80211_registered_device
*rdev
;
3771 struct net_device
*dev
;
3772 struct cfg80211_ibss_params ibss
;
3773 struct wiphy
*wiphy
;
3774 struct cfg80211_cached_keys
*connkeys
= NULL
;
3777 memset(&ibss
, 0, sizeof(ibss
));
3779 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3782 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
3783 !info
->attrs
[NL80211_ATTR_SSID
] ||
3784 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
3787 ibss
.beacon_interval
= 100;
3789 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
3790 ibss
.beacon_interval
=
3791 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3792 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
3798 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3802 if (!rdev
->ops
->join_ibss
) {
3807 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
3812 if (!netif_running(dev
)) {
3817 wiphy
= &rdev
->wiphy
;
3819 if (info
->attrs
[NL80211_ATTR_MAC
])
3820 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3821 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3822 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3824 if (info
->attrs
[NL80211_ATTR_IE
]) {
3825 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3826 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3829 ibss
.channel
= ieee80211_get_channel(wiphy
,
3830 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3831 if (!ibss
.channel
||
3832 ibss
.channel
->flags
& IEEE80211_CHAN_NO_IBSS
||
3833 ibss
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
3838 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
3839 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3841 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
3842 connkeys
= nl80211_parse_connkeys(rdev
,
3843 info
->attrs
[NL80211_ATTR_KEYS
]);
3844 if (IS_ERR(connkeys
)) {
3845 err
= PTR_ERR(connkeys
);
3851 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
3854 cfg80211_unlock_rdev(rdev
);
3863 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
3865 struct cfg80211_registered_device
*rdev
;
3866 struct net_device
*dev
;
3871 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3875 if (!rdev
->ops
->leave_ibss
) {
3880 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
3885 if (!netif_running(dev
)) {
3890 err
= cfg80211_leave_ibss(rdev
, dev
, false);
3893 cfg80211_unlock_rdev(rdev
);
3900 #ifdef CONFIG_NL80211_TESTMODE
3901 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
3905 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
3907 struct cfg80211_registered_device
*rdev
;
3910 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
3915 rdev
= cfg80211_get_dev_from_info(info
);
3917 err
= PTR_ERR(rdev
);
3922 if (rdev
->ops
->testmode_cmd
) {
3923 rdev
->testmode_info
= info
;
3924 err
= rdev
->ops
->testmode_cmd(&rdev
->wiphy
,
3925 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
3926 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
3927 rdev
->testmode_info
= NULL
;
3930 cfg80211_unlock_rdev(rdev
);
3937 static struct sk_buff
*
3938 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
3939 int approxlen
, u32 pid
, u32 seq
, gfp_t gfp
)
3941 struct sk_buff
*skb
;
3943 struct nlattr
*data
;
3945 skb
= nlmsg_new(approxlen
+ 100, gfp
);
3949 hdr
= nl80211hdr_put(skb
, pid
, seq
, 0, NL80211_CMD_TESTMODE
);
3955 NLA_PUT_U32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
3956 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
3958 ((void **)skb
->cb
)[0] = rdev
;
3959 ((void **)skb
->cb
)[1] = hdr
;
3960 ((void **)skb
->cb
)[2] = data
;
3969 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
3972 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
3974 if (WARN_ON(!rdev
->testmode_info
))
3977 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
3978 rdev
->testmode_info
->snd_pid
,
3979 rdev
->testmode_info
->snd_seq
,
3982 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
3984 int cfg80211_testmode_reply(struct sk_buff
*skb
)
3986 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
3987 void *hdr
= ((void **)skb
->cb
)[1];
3988 struct nlattr
*data
= ((void **)skb
->cb
)[2];
3990 if (WARN_ON(!rdev
->testmode_info
)) {
3995 nla_nest_end(skb
, data
);
3996 genlmsg_end(skb
, hdr
);
3997 return genlmsg_reply(skb
, rdev
->testmode_info
);
3999 EXPORT_SYMBOL(cfg80211_testmode_reply
);
4001 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
4002 int approxlen
, gfp_t gfp
)
4004 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4006 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
4008 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
4010 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
4012 void *hdr
= ((void **)skb
->cb
)[1];
4013 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4015 nla_nest_end(skb
, data
);
4016 genlmsg_end(skb
, hdr
);
4017 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
4019 EXPORT_SYMBOL(cfg80211_testmode_event
);
4022 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
4024 struct cfg80211_registered_device
*rdev
;
4025 struct net_device
*dev
;
4026 struct cfg80211_connect_params connect
;
4027 struct wiphy
*wiphy
;
4028 struct cfg80211_cached_keys
*connkeys
= NULL
;
4031 memset(&connect
, 0, sizeof(connect
));
4033 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4036 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
4037 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
4040 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
4042 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4043 if (!nl80211_valid_auth_type(connect
.auth_type
))
4046 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
4048 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
4050 err
= nl80211_crypto_settings(info
, &connect
.crypto
,
4051 NL80211_MAX_NR_CIPHER_SUITES
);
4056 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4060 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4065 if (!netif_running(dev
)) {
4070 wiphy
= &rdev
->wiphy
;
4072 if (info
->attrs
[NL80211_ATTR_MAC
])
4073 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4074 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4075 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4077 if (info
->attrs
[NL80211_ATTR_IE
]) {
4078 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4079 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4082 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
4084 ieee80211_get_channel(wiphy
,
4085 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4086 if (!connect
.channel
||
4087 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
4093 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
4094 connkeys
= nl80211_parse_connkeys(rdev
,
4095 info
->attrs
[NL80211_ATTR_KEYS
]);
4096 if (IS_ERR(connkeys
)) {
4097 err
= PTR_ERR(connkeys
);
4103 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
4106 cfg80211_unlock_rdev(rdev
);
4115 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
4117 struct cfg80211_registered_device
*rdev
;
4118 struct net_device
*dev
;
4122 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4123 reason
= WLAN_REASON_DEAUTH_LEAVING
;
4125 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4132 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4136 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4141 if (!netif_running(dev
)) {
4146 err
= cfg80211_disconnect(rdev
, dev
, reason
, true);
4149 cfg80211_unlock_rdev(rdev
);
4156 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
4158 struct cfg80211_registered_device
*rdev
;
4163 if (!info
->attrs
[NL80211_ATTR_PID
])
4166 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
4170 rdev
= cfg80211_get_dev_from_info(info
);
4172 err
= PTR_ERR(rdev
);
4176 net
= get_net_ns_by_pid(pid
);
4184 /* check if anything to do */
4185 if (net_eq(wiphy_net(&rdev
->wiphy
), net
))
4188 err
= cfg80211_switch_netns(rdev
, net
);
4192 cfg80211_unlock_rdev(rdev
);
4198 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4200 struct cfg80211_registered_device
*rdev
;
4201 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
4202 struct cfg80211_pmksa
*pmksa
) = NULL
;
4204 struct net_device
*dev
;
4205 struct cfg80211_pmksa pmksa
;
4207 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
4209 if (!info
->attrs
[NL80211_ATTR_MAC
])
4212 if (!info
->attrs
[NL80211_ATTR_PMKID
])
4217 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4221 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
4222 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4224 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4229 switch (info
->genlhdr
->cmd
) {
4230 case NL80211_CMD_SET_PMKSA
:
4231 rdev_ops
= rdev
->ops
->set_pmksa
;
4233 case NL80211_CMD_DEL_PMKSA
:
4234 rdev_ops
= rdev
->ops
->del_pmksa
;
4246 err
= rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
4249 cfg80211_unlock_rdev(rdev
);
4257 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4259 struct cfg80211_registered_device
*rdev
;
4261 struct net_device
*dev
;
4265 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4269 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4274 if (!rdev
->ops
->flush_pmksa
) {
4279 err
= rdev
->ops
->flush_pmksa(&rdev
->wiphy
, dev
);
4282 cfg80211_unlock_rdev(rdev
);
4291 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
4292 struct genl_info
*info
)
4294 struct cfg80211_registered_device
*rdev
;
4295 struct net_device
*dev
;
4296 struct ieee80211_channel
*chan
;
4297 struct sk_buff
*msg
;
4300 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
4304 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
4305 !info
->attrs
[NL80211_ATTR_DURATION
])
4308 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
4311 * We should be on that channel for at least one jiffie,
4312 * and more than 5 seconds seems excessive.
4314 if (!duration
|| !msecs_to_jiffies(duration
) || duration
> 5000)
4319 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4323 if (!rdev
->ops
->remain_on_channel
) {
4328 if (!netif_running(dev
)) {
4333 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
4334 channel_type
= nla_get_u32(
4335 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
4336 if (channel_type
!= NL80211_CHAN_NO_HT
&&
4337 channel_type
!= NL80211_CHAN_HT20
&&
4338 channel_type
!= NL80211_CHAN_HT40PLUS
&&
4339 channel_type
!= NL80211_CHAN_HT40MINUS
)
4344 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
4345 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
4351 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4357 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4358 NL80211_CMD_REMAIN_ON_CHANNEL
);
4365 err
= rdev
->ops
->remain_on_channel(&rdev
->wiphy
, dev
, chan
,
4366 channel_type
, duration
, &cookie
);
4371 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
4373 genlmsg_end(msg
, hdr
);
4374 err
= genlmsg_reply(msg
, info
);
4382 cfg80211_unlock_rdev(rdev
);
4389 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
4390 struct genl_info
*info
)
4392 struct cfg80211_registered_device
*rdev
;
4393 struct net_device
*dev
;
4397 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
4402 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4406 if (!rdev
->ops
->cancel_remain_on_channel
) {
4411 if (!netif_running(dev
)) {
4416 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
4418 err
= rdev
->ops
->cancel_remain_on_channel(&rdev
->wiphy
, dev
, cookie
);
4421 cfg80211_unlock_rdev(rdev
);
4428 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
4429 u8
*rates
, u8 rates_len
)
4434 for (i
= 0; i
< rates_len
; i
++) {
4435 int rate
= (rates
[i
] & 0x7f) * 5;
4437 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
4438 struct ieee80211_rate
*srate
=
4439 &sband
->bitrates
[ridx
];
4440 if (rate
== srate
->bitrate
) {
4445 if (ridx
== sband
->n_bitrates
)
4446 return 0; /* rate not found */
4452 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
4453 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
4454 .len
= NL80211_MAX_SUPP_RATES
},
4457 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
4458 struct genl_info
*info
)
4460 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
4461 struct cfg80211_registered_device
*rdev
;
4462 struct cfg80211_bitrate_mask mask
;
4464 struct net_device
*dev
;
4465 struct nlattr
*tx_rates
;
4466 struct ieee80211_supported_band
*sband
;
4468 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
4473 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4477 if (!rdev
->ops
->set_bitrate_mask
) {
4482 memset(&mask
, 0, sizeof(mask
));
4483 /* Default to all rates enabled */
4484 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
4485 sband
= rdev
->wiphy
.bands
[i
];
4486 mask
.control
[i
].legacy
=
4487 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
4491 * The nested attribute uses enum nl80211_band as the index. This maps
4492 * directly to the enum ieee80211_band values used in cfg80211.
4494 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
4496 enum ieee80211_band band
= nla_type(tx_rates
);
4497 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
4501 sband
= rdev
->wiphy
.bands
[band
];
4502 if (sband
== NULL
) {
4506 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
4507 nla_len(tx_rates
), nl80211_txattr_policy
);
4508 if (tb
[NL80211_TXRATE_LEGACY
]) {
4509 mask
.control
[band
].legacy
= rateset_to_mask(
4511 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
4512 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
4513 if (mask
.control
[band
].legacy
== 0) {
4520 err
= rdev
->ops
->set_bitrate_mask(&rdev
->wiphy
, dev
, NULL
, &mask
);
4524 cfg80211_unlock_rdev(rdev
);
4530 static int nl80211_register_action(struct sk_buff
*skb
, struct genl_info
*info
)
4532 struct cfg80211_registered_device
*rdev
;
4533 struct net_device
*dev
;
4536 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
4539 if (nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]) < 1)
4544 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4548 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4553 /* not much point in registering if we can't reply */
4554 if (!rdev
->ops
->action
) {
4559 err
= cfg80211_mlme_register_action(dev
->ieee80211_ptr
, info
->snd_pid
,
4560 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
4561 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
4563 cfg80211_unlock_rdev(rdev
);
4570 static int nl80211_action(struct sk_buff
*skb
, struct genl_info
*info
)
4572 struct cfg80211_registered_device
*rdev
;
4573 struct net_device
*dev
;
4574 struct ieee80211_channel
*chan
;
4575 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
4580 struct sk_buff
*msg
;
4582 if (!info
->attrs
[NL80211_ATTR_FRAME
] ||
4583 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4588 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4592 if (!rdev
->ops
->action
) {
4597 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4602 if (!netif_running(dev
)) {
4607 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
4608 channel_type
= nla_get_u32(
4609 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
4610 if (channel_type
!= NL80211_CHAN_NO_HT
&&
4611 channel_type
!= NL80211_CHAN_HT20
&&
4612 channel_type
!= NL80211_CHAN_HT40PLUS
&&
4613 channel_type
!= NL80211_CHAN_HT40MINUS
)
4618 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
4619 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
4625 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4631 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4632 NL80211_CMD_ACTION
);
4638 err
= cfg80211_mlme_action(rdev
, dev
, chan
, channel_type
,
4639 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
4640 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
4645 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
4647 genlmsg_end(msg
, hdr
);
4648 err
= genlmsg_reply(msg
, info
);
4656 cfg80211_unlock_rdev(rdev
);
4663 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
4665 struct cfg80211_registered_device
*rdev
;
4666 struct wireless_dev
*wdev
;
4667 struct net_device
*dev
;
4672 if (!info
->attrs
[NL80211_ATTR_PS_STATE
]) {
4677 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
4679 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
) {
4686 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4690 wdev
= dev
->ieee80211_ptr
;
4692 if (!rdev
->ops
->set_power_mgmt
) {
4697 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
4699 if (state
== wdev
->ps
)
4704 if (rdev
->ops
->set_power_mgmt(wdev
->wiphy
, dev
, wdev
->ps
,
4706 /* assume this means it's off */
4710 cfg80211_unlock_rdev(rdev
);
4718 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
4720 struct cfg80211_registered_device
*rdev
;
4721 enum nl80211_ps_state ps_state
;
4722 struct wireless_dev
*wdev
;
4723 struct net_device
*dev
;
4724 struct sk_buff
*msg
;
4730 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4734 wdev
= dev
->ieee80211_ptr
;
4736 if (!rdev
->ops
->set_power_mgmt
) {
4741 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4747 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4748 NL80211_CMD_GET_POWER_SAVE
);
4755 ps_state
= NL80211_PS_ENABLED
;
4757 ps_state
= NL80211_PS_DISABLED
;
4759 NLA_PUT_U32(msg
, NL80211_ATTR_PS_STATE
, ps_state
);
4761 genlmsg_end(msg
, hdr
);
4762 err
= genlmsg_reply(msg
, info
);
4772 cfg80211_unlock_rdev(rdev
);
4781 static struct genl_ops nl80211_ops
[] = {
4783 .cmd
= NL80211_CMD_GET_WIPHY
,
4784 .doit
= nl80211_get_wiphy
,
4785 .dumpit
= nl80211_dump_wiphy
,
4786 .policy
= nl80211_policy
,
4787 /* can be retrieved by unprivileged users */
4790 .cmd
= NL80211_CMD_SET_WIPHY
,
4791 .doit
= nl80211_set_wiphy
,
4792 .policy
= nl80211_policy
,
4793 .flags
= GENL_ADMIN_PERM
,
4796 .cmd
= NL80211_CMD_GET_INTERFACE
,
4797 .doit
= nl80211_get_interface
,
4798 .dumpit
= nl80211_dump_interface
,
4799 .policy
= nl80211_policy
,
4800 /* can be retrieved by unprivileged users */
4803 .cmd
= NL80211_CMD_SET_INTERFACE
,
4804 .doit
= nl80211_set_interface
,
4805 .policy
= nl80211_policy
,
4806 .flags
= GENL_ADMIN_PERM
,
4809 .cmd
= NL80211_CMD_NEW_INTERFACE
,
4810 .doit
= nl80211_new_interface
,
4811 .policy
= nl80211_policy
,
4812 .flags
= GENL_ADMIN_PERM
,
4815 .cmd
= NL80211_CMD_DEL_INTERFACE
,
4816 .doit
= nl80211_del_interface
,
4817 .policy
= nl80211_policy
,
4818 .flags
= GENL_ADMIN_PERM
,
4821 .cmd
= NL80211_CMD_GET_KEY
,
4822 .doit
= nl80211_get_key
,
4823 .policy
= nl80211_policy
,
4824 .flags
= GENL_ADMIN_PERM
,
4827 .cmd
= NL80211_CMD_SET_KEY
,
4828 .doit
= nl80211_set_key
,
4829 .policy
= nl80211_policy
,
4830 .flags
= GENL_ADMIN_PERM
,
4833 .cmd
= NL80211_CMD_NEW_KEY
,
4834 .doit
= nl80211_new_key
,
4835 .policy
= nl80211_policy
,
4836 .flags
= GENL_ADMIN_PERM
,
4839 .cmd
= NL80211_CMD_DEL_KEY
,
4840 .doit
= nl80211_del_key
,
4841 .policy
= nl80211_policy
,
4842 .flags
= GENL_ADMIN_PERM
,
4845 .cmd
= NL80211_CMD_SET_BEACON
,
4846 .policy
= nl80211_policy
,
4847 .flags
= GENL_ADMIN_PERM
,
4848 .doit
= nl80211_addset_beacon
,
4851 .cmd
= NL80211_CMD_NEW_BEACON
,
4852 .policy
= nl80211_policy
,
4853 .flags
= GENL_ADMIN_PERM
,
4854 .doit
= nl80211_addset_beacon
,
4857 .cmd
= NL80211_CMD_DEL_BEACON
,
4858 .policy
= nl80211_policy
,
4859 .flags
= GENL_ADMIN_PERM
,
4860 .doit
= nl80211_del_beacon
,
4863 .cmd
= NL80211_CMD_GET_STATION
,
4864 .doit
= nl80211_get_station
,
4865 .dumpit
= nl80211_dump_station
,
4866 .policy
= nl80211_policy
,
4869 .cmd
= NL80211_CMD_SET_STATION
,
4870 .doit
= nl80211_set_station
,
4871 .policy
= nl80211_policy
,
4872 .flags
= GENL_ADMIN_PERM
,
4875 .cmd
= NL80211_CMD_NEW_STATION
,
4876 .doit
= nl80211_new_station
,
4877 .policy
= nl80211_policy
,
4878 .flags
= GENL_ADMIN_PERM
,
4881 .cmd
= NL80211_CMD_DEL_STATION
,
4882 .doit
= nl80211_del_station
,
4883 .policy
= nl80211_policy
,
4884 .flags
= GENL_ADMIN_PERM
,
4887 .cmd
= NL80211_CMD_GET_MPATH
,
4888 .doit
= nl80211_get_mpath
,
4889 .dumpit
= nl80211_dump_mpath
,
4890 .policy
= nl80211_policy
,
4891 .flags
= GENL_ADMIN_PERM
,
4894 .cmd
= NL80211_CMD_SET_MPATH
,
4895 .doit
= nl80211_set_mpath
,
4896 .policy
= nl80211_policy
,
4897 .flags
= GENL_ADMIN_PERM
,
4900 .cmd
= NL80211_CMD_NEW_MPATH
,
4901 .doit
= nl80211_new_mpath
,
4902 .policy
= nl80211_policy
,
4903 .flags
= GENL_ADMIN_PERM
,
4906 .cmd
= NL80211_CMD_DEL_MPATH
,
4907 .doit
= nl80211_del_mpath
,
4908 .policy
= nl80211_policy
,
4909 .flags
= GENL_ADMIN_PERM
,
4912 .cmd
= NL80211_CMD_SET_BSS
,
4913 .doit
= nl80211_set_bss
,
4914 .policy
= nl80211_policy
,
4915 .flags
= GENL_ADMIN_PERM
,
4918 .cmd
= NL80211_CMD_GET_REG
,
4919 .doit
= nl80211_get_reg
,
4920 .policy
= nl80211_policy
,
4921 /* can be retrieved by unprivileged users */
4924 .cmd
= NL80211_CMD_SET_REG
,
4925 .doit
= nl80211_set_reg
,
4926 .policy
= nl80211_policy
,
4927 .flags
= GENL_ADMIN_PERM
,
4930 .cmd
= NL80211_CMD_REQ_SET_REG
,
4931 .doit
= nl80211_req_set_reg
,
4932 .policy
= nl80211_policy
,
4933 .flags
= GENL_ADMIN_PERM
,
4936 .cmd
= NL80211_CMD_GET_MESH_PARAMS
,
4937 .doit
= nl80211_get_mesh_params
,
4938 .policy
= nl80211_policy
,
4939 /* can be retrieved by unprivileged users */
4942 .cmd
= NL80211_CMD_SET_MESH_PARAMS
,
4943 .doit
= nl80211_set_mesh_params
,
4944 .policy
= nl80211_policy
,
4945 .flags
= GENL_ADMIN_PERM
,
4948 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
4949 .doit
= nl80211_trigger_scan
,
4950 .policy
= nl80211_policy
,
4951 .flags
= GENL_ADMIN_PERM
,
4954 .cmd
= NL80211_CMD_GET_SCAN
,
4955 .policy
= nl80211_policy
,
4956 .dumpit
= nl80211_dump_scan
,
4959 .cmd
= NL80211_CMD_AUTHENTICATE
,
4960 .doit
= nl80211_authenticate
,
4961 .policy
= nl80211_policy
,
4962 .flags
= GENL_ADMIN_PERM
,
4965 .cmd
= NL80211_CMD_ASSOCIATE
,
4966 .doit
= nl80211_associate
,
4967 .policy
= nl80211_policy
,
4968 .flags
= GENL_ADMIN_PERM
,
4971 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
4972 .doit
= nl80211_deauthenticate
,
4973 .policy
= nl80211_policy
,
4974 .flags
= GENL_ADMIN_PERM
,
4977 .cmd
= NL80211_CMD_DISASSOCIATE
,
4978 .doit
= nl80211_disassociate
,
4979 .policy
= nl80211_policy
,
4980 .flags
= GENL_ADMIN_PERM
,
4983 .cmd
= NL80211_CMD_JOIN_IBSS
,
4984 .doit
= nl80211_join_ibss
,
4985 .policy
= nl80211_policy
,
4986 .flags
= GENL_ADMIN_PERM
,
4989 .cmd
= NL80211_CMD_LEAVE_IBSS
,
4990 .doit
= nl80211_leave_ibss
,
4991 .policy
= nl80211_policy
,
4992 .flags
= GENL_ADMIN_PERM
,
4994 #ifdef CONFIG_NL80211_TESTMODE
4996 .cmd
= NL80211_CMD_TESTMODE
,
4997 .doit
= nl80211_testmode_do
,
4998 .policy
= nl80211_policy
,
4999 .flags
= GENL_ADMIN_PERM
,
5003 .cmd
= NL80211_CMD_CONNECT
,
5004 .doit
= nl80211_connect
,
5005 .policy
= nl80211_policy
,
5006 .flags
= GENL_ADMIN_PERM
,
5009 .cmd
= NL80211_CMD_DISCONNECT
,
5010 .doit
= nl80211_disconnect
,
5011 .policy
= nl80211_policy
,
5012 .flags
= GENL_ADMIN_PERM
,
5015 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
5016 .doit
= nl80211_wiphy_netns
,
5017 .policy
= nl80211_policy
,
5018 .flags
= GENL_ADMIN_PERM
,
5021 .cmd
= NL80211_CMD_GET_SURVEY
,
5022 .policy
= nl80211_policy
,
5023 .dumpit
= nl80211_dump_survey
,
5026 .cmd
= NL80211_CMD_SET_PMKSA
,
5027 .doit
= nl80211_setdel_pmksa
,
5028 .policy
= nl80211_policy
,
5029 .flags
= GENL_ADMIN_PERM
,
5032 .cmd
= NL80211_CMD_DEL_PMKSA
,
5033 .doit
= nl80211_setdel_pmksa
,
5034 .policy
= nl80211_policy
,
5035 .flags
= GENL_ADMIN_PERM
,
5038 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
5039 .doit
= nl80211_flush_pmksa
,
5040 .policy
= nl80211_policy
,
5041 .flags
= GENL_ADMIN_PERM
,
5044 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
5045 .doit
= nl80211_remain_on_channel
,
5046 .policy
= nl80211_policy
,
5047 .flags
= GENL_ADMIN_PERM
,
5050 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
5051 .doit
= nl80211_cancel_remain_on_channel
,
5052 .policy
= nl80211_policy
,
5053 .flags
= GENL_ADMIN_PERM
,
5056 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
5057 .doit
= nl80211_set_tx_bitrate_mask
,
5058 .policy
= nl80211_policy
,
5059 .flags
= GENL_ADMIN_PERM
,
5062 .cmd
= NL80211_CMD_REGISTER_ACTION
,
5063 .doit
= nl80211_register_action
,
5064 .policy
= nl80211_policy
,
5065 .flags
= GENL_ADMIN_PERM
,
5068 .cmd
= NL80211_CMD_ACTION
,
5069 .doit
= nl80211_action
,
5070 .policy
= nl80211_policy
,
5071 .flags
= GENL_ADMIN_PERM
,
5074 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
5075 .doit
= nl80211_set_power_save
,
5076 .policy
= nl80211_policy
,
5077 .flags
= GENL_ADMIN_PERM
,
5080 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
5081 .doit
= nl80211_get_power_save
,
5082 .policy
= nl80211_policy
,
5083 /* can be retrieved by unprivileged users */
5087 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
5091 /* multicast groups */
5092 static struct genl_multicast_group nl80211_config_mcgrp
= {
5095 static struct genl_multicast_group nl80211_scan_mcgrp
= {
5098 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
5099 .name
= "regulatory",
5102 /* notification functions */
5104 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
5106 struct sk_buff
*msg
;
5108 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5112 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
5117 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5118 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
5121 static int nl80211_add_scan_req(struct sk_buff
*msg
,
5122 struct cfg80211_registered_device
*rdev
)
5124 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
5125 struct nlattr
*nest
;
5128 ASSERT_RDEV_LOCK(rdev
);
5133 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
5135 goto nla_put_failure
;
5136 for (i
= 0; i
< req
->n_ssids
; i
++)
5137 NLA_PUT(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
);
5138 nla_nest_end(msg
, nest
);
5140 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
5142 goto nla_put_failure
;
5143 for (i
= 0; i
< req
->n_channels
; i
++)
5144 NLA_PUT_U32(msg
, i
, req
->channels
[i
]->center_freq
);
5145 nla_nest_end(msg
, nest
);
5148 NLA_PUT(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
);
5155 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
5156 struct cfg80211_registered_device
*rdev
,
5157 struct net_device
*netdev
,
5158 u32 pid
, u32 seq
, int flags
,
5163 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
5167 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5168 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5170 /* ignore errors and send incomplete event anyway */
5171 nl80211_add_scan_req(msg
, rdev
);
5173 return genlmsg_end(msg
, hdr
);
5176 genlmsg_cancel(msg
, hdr
);
5180 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
5181 struct net_device
*netdev
)
5183 struct sk_buff
*msg
;
5185 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
5189 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5190 NL80211_CMD_TRIGGER_SCAN
) < 0) {
5195 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5196 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5199 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
5200 struct net_device
*netdev
)
5202 struct sk_buff
*msg
;
5204 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5208 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5209 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
5214 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5215 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5218 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
5219 struct net_device
*netdev
)
5221 struct sk_buff
*msg
;
5223 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5227 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5228 NL80211_CMD_SCAN_ABORTED
) < 0) {
5233 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5234 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5238 * This can happen on global regulatory changes or device specific settings
5239 * based on custom world regulatory domains.
5241 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
5243 struct sk_buff
*msg
;
5246 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5250 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
5256 /* Userspace can always count this one always being set */
5257 NLA_PUT_U8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
);
5259 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0')
5260 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5261 NL80211_REGDOM_TYPE_WORLD
);
5262 else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9')
5263 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5264 NL80211_REGDOM_TYPE_CUSTOM_WORLD
);
5265 else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
5267 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5268 NL80211_REGDOM_TYPE_INTERSECTION
);
5270 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5271 NL80211_REGDOM_TYPE_COUNTRY
);
5272 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, request
->alpha2
);
5275 if (wiphy_idx_valid(request
->wiphy_idx
))
5276 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
);
5278 if (genlmsg_end(msg
, hdr
) < 0) {
5284 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
5291 genlmsg_cancel(msg
, hdr
);
5295 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
5296 struct net_device
*netdev
,
5297 const u8
*buf
, size_t len
,
5298 enum nl80211_commands cmd
, gfp_t gfp
)
5300 struct sk_buff
*msg
;
5303 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5307 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
5313 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5314 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5315 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
5317 if (genlmsg_end(msg
, hdr
) < 0) {
5322 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5323 nl80211_mlme_mcgrp
.id
, gfp
);
5327 genlmsg_cancel(msg
, hdr
);
5331 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
5332 struct net_device
*netdev
, const u8
*buf
,
5333 size_t len
, gfp_t gfp
)
5335 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5336 NL80211_CMD_AUTHENTICATE
, gfp
);
5339 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
5340 struct net_device
*netdev
, const u8
*buf
,
5341 size_t len
, gfp_t gfp
)
5343 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5344 NL80211_CMD_ASSOCIATE
, gfp
);
5347 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
5348 struct net_device
*netdev
, const u8
*buf
,
5349 size_t len
, gfp_t gfp
)
5351 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5352 NL80211_CMD_DEAUTHENTICATE
, gfp
);
5355 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
5356 struct net_device
*netdev
, const u8
*buf
,
5357 size_t len
, gfp_t gfp
)
5359 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5360 NL80211_CMD_DISASSOCIATE
, gfp
);
5363 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
5364 struct net_device
*netdev
, int cmd
,
5365 const u8
*addr
, gfp_t gfp
)
5367 struct sk_buff
*msg
;
5370 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5374 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
5380 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5381 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5382 NLA_PUT_FLAG(msg
, NL80211_ATTR_TIMED_OUT
);
5383 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5385 if (genlmsg_end(msg
, hdr
) < 0) {
5390 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5391 nl80211_mlme_mcgrp
.id
, gfp
);
5395 genlmsg_cancel(msg
, hdr
);
5399 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
5400 struct net_device
*netdev
, const u8
*addr
,
5403 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
5407 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
5408 struct net_device
*netdev
, const u8
*addr
,
5411 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
5415 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
5416 struct net_device
*netdev
, const u8
*bssid
,
5417 const u8
*req_ie
, size_t req_ie_len
,
5418 const u8
*resp_ie
, size_t resp_ie_len
,
5419 u16 status
, gfp_t gfp
)
5421 struct sk_buff
*msg
;
5424 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
5428 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
5434 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5435 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5437 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
5438 NLA_PUT_U16(msg
, NL80211_ATTR_STATUS_CODE
, status
);
5440 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
5442 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
5444 if (genlmsg_end(msg
, hdr
) < 0) {
5449 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5450 nl80211_mlme_mcgrp
.id
, gfp
);
5454 genlmsg_cancel(msg
, hdr
);
5459 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
5460 struct net_device
*netdev
, const u8
*bssid
,
5461 const u8
*req_ie
, size_t req_ie_len
,
5462 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
5464 struct sk_buff
*msg
;
5467 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
5471 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
5477 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5478 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5479 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
5481 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
5483 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
5485 if (genlmsg_end(msg
, hdr
) < 0) {
5490 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5491 nl80211_mlme_mcgrp
.id
, gfp
);
5495 genlmsg_cancel(msg
, hdr
);
5500 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
5501 struct net_device
*netdev
, u16 reason
,
5502 const u8
*ie
, size_t ie_len
, bool from_ap
)
5504 struct sk_buff
*msg
;
5507 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
5511 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
5517 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5518 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5519 if (from_ap
&& reason
)
5520 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason
);
5522 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
);
5524 NLA_PUT(msg
, NL80211_ATTR_IE
, ie_len
, ie
);
5526 if (genlmsg_end(msg
, hdr
) < 0) {
5531 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5532 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
5536 genlmsg_cancel(msg
, hdr
);
5541 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
5542 struct net_device
*netdev
, const u8
*bssid
,
5545 struct sk_buff
*msg
;
5548 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5552 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
5558 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5559 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5560 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
5562 if (genlmsg_end(msg
, hdr
) < 0) {
5567 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5568 nl80211_mlme_mcgrp
.id
, gfp
);
5572 genlmsg_cancel(msg
, hdr
);
5576 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
5577 struct net_device
*netdev
, const u8
*addr
,
5578 enum nl80211_key_type key_type
, int key_id
,
5579 const u8
*tsc
, gfp_t gfp
)
5581 struct sk_buff
*msg
;
5584 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5588 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
5594 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5595 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5597 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5598 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
);
5599 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_id
);
5601 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
);
5603 if (genlmsg_end(msg
, hdr
) < 0) {
5608 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5609 nl80211_mlme_mcgrp
.id
, gfp
);
5613 genlmsg_cancel(msg
, hdr
);
5617 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
5618 struct ieee80211_channel
*channel_before
,
5619 struct ieee80211_channel
*channel_after
)
5621 struct sk_buff
*msg
;
5623 struct nlattr
*nl_freq
;
5625 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
5629 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
5636 * Since we are applying the beacon hint to a wiphy we know its
5637 * wiphy_idx is valid
5639 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
));
5642 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
5644 goto nla_put_failure
;
5645 if (nl80211_msg_put_channel(msg
, channel_before
))
5646 goto nla_put_failure
;
5647 nla_nest_end(msg
, nl_freq
);
5650 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
5652 goto nla_put_failure
;
5653 if (nl80211_msg_put_channel(msg
, channel_after
))
5654 goto nla_put_failure
;
5655 nla_nest_end(msg
, nl_freq
);
5657 if (genlmsg_end(msg
, hdr
) < 0) {
5663 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
5670 genlmsg_cancel(msg
, hdr
);
5674 static void nl80211_send_remain_on_chan_event(
5675 int cmd
, struct cfg80211_registered_device
*rdev
,
5676 struct net_device
*netdev
, u64 cookie
,
5677 struct ieee80211_channel
*chan
,
5678 enum nl80211_channel_type channel_type
,
5679 unsigned int duration
, gfp_t gfp
)
5681 struct sk_buff
*msg
;
5684 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5688 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
5694 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5695 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5696 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
);
5697 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, channel_type
);
5698 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
5700 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
)
5701 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, duration
);
5703 if (genlmsg_end(msg
, hdr
) < 0) {
5708 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5709 nl80211_mlme_mcgrp
.id
, gfp
);
5713 genlmsg_cancel(msg
, hdr
);
5717 void nl80211_send_remain_on_channel(struct cfg80211_registered_device
*rdev
,
5718 struct net_device
*netdev
, u64 cookie
,
5719 struct ieee80211_channel
*chan
,
5720 enum nl80211_channel_type channel_type
,
5721 unsigned int duration
, gfp_t gfp
)
5723 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
5724 rdev
, netdev
, cookie
, chan
,
5725 channel_type
, duration
, gfp
);
5728 void nl80211_send_remain_on_channel_cancel(
5729 struct cfg80211_registered_device
*rdev
, struct net_device
*netdev
,
5730 u64 cookie
, struct ieee80211_channel
*chan
,
5731 enum nl80211_channel_type channel_type
, gfp_t gfp
)
5733 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
5734 rdev
, netdev
, cookie
, chan
,
5735 channel_type
, 0, gfp
);
5738 void nl80211_send_sta_event(struct cfg80211_registered_device
*rdev
,
5739 struct net_device
*dev
, const u8
*mac_addr
,
5740 struct station_info
*sinfo
, gfp_t gfp
)
5742 struct sk_buff
*msg
;
5744 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
5748 if (nl80211_send_station(msg
, 0, 0, 0, dev
, mac_addr
, sinfo
) < 0) {
5753 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5754 nl80211_mlme_mcgrp
.id
, gfp
);
5757 int nl80211_send_action(struct cfg80211_registered_device
*rdev
,
5758 struct net_device
*netdev
, u32 nlpid
,
5759 int freq
, const u8
*buf
, size_t len
, gfp_t gfp
)
5761 struct sk_buff
*msg
;
5765 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5769 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ACTION
);
5775 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5776 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5777 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
5778 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
5780 err
= genlmsg_end(msg
, hdr
);
5786 err
= genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
5792 genlmsg_cancel(msg
, hdr
);
5797 void nl80211_send_action_tx_status(struct cfg80211_registered_device
*rdev
,
5798 struct net_device
*netdev
, u64 cookie
,
5799 const u8
*buf
, size_t len
, bool ack
,
5802 struct sk_buff
*msg
;
5805 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5809 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ACTION_TX_STATUS
);
5815 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5816 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5817 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
5818 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
5820 NLA_PUT_FLAG(msg
, NL80211_ATTR_ACK
);
5822 if (genlmsg_end(msg
, hdr
) < 0) {
5827 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
5831 genlmsg_cancel(msg
, hdr
);
5835 static int nl80211_netlink_notify(struct notifier_block
* nb
,
5836 unsigned long state
,
5839 struct netlink_notify
*notify
= _notify
;
5840 struct cfg80211_registered_device
*rdev
;
5841 struct wireless_dev
*wdev
;
5843 if (state
!= NETLINK_URELEASE
)
5848 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
)
5849 list_for_each_entry_rcu(wdev
, &rdev
->netdev_list
, list
)
5850 cfg80211_mlme_unregister_actions(wdev
, notify
->pid
);
5857 static struct notifier_block nl80211_netlink_notifier
= {
5858 .notifier_call
= nl80211_netlink_notify
,
5861 /* initialisation/exit functions */
5863 int nl80211_init(void)
5867 err
= genl_register_family_with_ops(&nl80211_fam
,
5868 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
5872 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
5876 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
5880 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
5884 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
5888 #ifdef CONFIG_NL80211_TESTMODE
5889 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
5894 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
5900 genl_unregister_family(&nl80211_fam
);
5904 void nl80211_exit(void)
5906 netlink_unregister_notifier(&nl80211_netlink_notifier
);
5907 genl_unregister_family(&nl80211_fam
);