2 * This is the new netlink-based wireless configuration interface.
4 * Copyright 2006-2009 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 struct nla_policy nl80211_policy
[NL80211_ATTR_MAX
+1] __read_mostly
= {
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
},
73 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
74 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
75 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
77 [NL80211_ATTR_MAC
] = { .type
= NLA_BINARY
, .len
= ETH_ALEN
},
78 [NL80211_ATTR_PREV_BSSID
] = { .type
= NLA_BINARY
, .len
= ETH_ALEN
},
80 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
81 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
82 .len
= WLAN_MAX_KEY_LEN
},
83 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
84 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
85 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
86 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 8 },
88 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
89 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
90 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
91 .len
= IEEE80211_MAX_DATA_LEN
},
92 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
93 .len
= IEEE80211_MAX_DATA_LEN
},
94 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
95 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
96 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
97 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
98 .len
= NL80211_MAX_SUPP_RATES
},
99 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
100 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
101 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
102 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
103 .len
= IEEE80211_MAX_MESH_ID_LEN
},
104 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
106 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
107 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
109 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
110 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
111 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
112 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
113 .len
= NL80211_MAX_SUPP_RATES
},
115 [NL80211_ATTR_MESH_PARAMS
] = { .type
= NLA_NESTED
},
117 [NL80211_ATTR_HT_CAPABILITY
] = { .type
= NLA_BINARY
,
118 .len
= NL80211_HT_CAPABILITY_LEN
},
120 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
121 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
122 .len
= IEEE80211_MAX_DATA_LEN
},
123 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
124 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
126 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
127 .len
= IEEE80211_MAX_SSID_LEN
},
128 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
129 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
130 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
131 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
132 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
133 [NL80211_ATTR_STA_FLAGS2
] = {
134 .len
= sizeof(struct nl80211_sta_flag_update
),
136 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
137 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
138 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
139 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
140 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
141 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
142 [NL80211_ATTR_PMKID
] = { .type
= NLA_BINARY
,
143 .len
= WLAN_PMKID_LEN
},
146 /* policy for the attributes */
147 static struct nla_policy
148 nl80211_key_policy
[NL80211_KEY_MAX
+ 1] __read_mostly
= {
149 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
150 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
151 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
152 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 8 },
153 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
154 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
157 /* ifidx get helper */
158 static int nl80211_get_ifidx(struct netlink_callback
*cb
)
162 res
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
163 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
168 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
171 res
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
178 static bool is_valid_ie_attr(const struct nlattr
*attr
)
186 pos
= nla_data(attr
);
207 /* message building helper */
208 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 pid
, u32 seq
,
211 /* since there is no private header just add the generic one */
212 return genlmsg_put(skb
, pid
, seq
, &nl80211_fam
, flags
, cmd
);
215 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
216 struct ieee80211_channel
*chan
)
218 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
221 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
222 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_DISABLED
);
223 if (chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
224 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
);
225 if (chan
->flags
& IEEE80211_CHAN_NO_IBSS
)
226 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
);
227 if (chan
->flags
& IEEE80211_CHAN_RADAR
)
228 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_RADAR
);
230 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
231 DBM_TO_MBM(chan
->max_power
));
239 /* netlink command implementations */
247 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
249 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
250 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
255 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
256 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
258 if (tb
[NL80211_KEY_IDX
])
259 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
261 if (tb
[NL80211_KEY_DATA
]) {
262 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
263 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
266 if (tb
[NL80211_KEY_SEQ
]) {
267 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
268 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
271 if (tb
[NL80211_KEY_CIPHER
])
272 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
277 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
279 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
280 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
281 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
284 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
285 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
286 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
289 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
290 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
292 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
293 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
295 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
296 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
301 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
305 memset(k
, 0, sizeof(*k
));
308 if (info
->attrs
[NL80211_ATTR_KEY
])
309 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
311 err
= nl80211_parse_key_old(info
, k
);
316 if (k
->def
&& k
->defmgmt
)
321 if (k
->idx
< 4 || k
->idx
> 5)
324 if (k
->idx
< 0 || k
->idx
> 3)
327 if (k
->idx
< 0 || k
->idx
> 5)
335 static struct cfg80211_cached_keys
*
336 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
339 struct key_parse parse
;
341 struct cfg80211_cached_keys
*result
;
342 int rem
, err
, def
= 0;
344 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
346 return ERR_PTR(-ENOMEM
);
349 result
->defmgmt
= -1;
351 nla_for_each_nested(key
, keys
, rem
) {
352 memset(&parse
, 0, sizeof(parse
));
355 err
= nl80211_parse_key_new(key
, &parse
);
361 if (parse
.idx
< 0 || parse
.idx
> 4)
367 result
->def
= parse
.idx
;
368 } else if (parse
.defmgmt
)
370 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
374 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
375 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
376 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
377 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
386 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
388 ASSERT_WDEV_LOCK(wdev
);
390 if (!netif_running(wdev
->netdev
))
393 switch (wdev
->iftype
) {
394 case NL80211_IFTYPE_AP
:
395 case NL80211_IFTYPE_AP_VLAN
:
397 case NL80211_IFTYPE_ADHOC
:
398 if (!wdev
->current_bss
)
401 case NL80211_IFTYPE_STATION
:
402 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
412 static int nl80211_send_wiphy(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
413 struct cfg80211_registered_device
*dev
)
416 struct nlattr
*nl_bands
, *nl_band
;
417 struct nlattr
*nl_freqs
, *nl_freq
;
418 struct nlattr
*nl_rates
, *nl_rate
;
419 struct nlattr
*nl_modes
;
420 struct nlattr
*nl_cmds
;
421 enum ieee80211_band band
;
422 struct ieee80211_channel
*chan
;
423 struct ieee80211_rate
*rate
;
425 u16 ifmodes
= dev
->wiphy
.interface_modes
;
427 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
431 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
);
432 NLA_PUT_STRING(msg
, NL80211_ATTR_WIPHY_NAME
, wiphy_name(&dev
->wiphy
));
434 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
435 cfg80211_rdev_list_generation
);
437 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
438 dev
->wiphy
.retry_short
);
439 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
440 dev
->wiphy
.retry_long
);
441 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
442 dev
->wiphy
.frag_threshold
);
443 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
444 dev
->wiphy
.rts_threshold
);
446 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
447 dev
->wiphy
.max_scan_ssids
);
448 NLA_PUT_U16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
449 dev
->wiphy
.max_scan_ie_len
);
451 NLA_PUT(msg
, NL80211_ATTR_CIPHER_SUITES
,
452 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
453 dev
->wiphy
.cipher_suites
);
455 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
456 dev
->wiphy
.max_num_pmkids
);
458 nl_modes
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
);
460 goto nla_put_failure
;
465 NLA_PUT_FLAG(msg
, i
);
470 nla_nest_end(msg
, nl_modes
);
472 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
474 goto nla_put_failure
;
476 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
477 if (!dev
->wiphy
.bands
[band
])
480 nl_band
= nla_nest_start(msg
, band
);
482 goto nla_put_failure
;
485 if (dev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
) {
486 NLA_PUT(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
487 sizeof(dev
->wiphy
.bands
[band
]->ht_cap
.mcs
),
488 &dev
->wiphy
.bands
[band
]->ht_cap
.mcs
);
489 NLA_PUT_U16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
490 dev
->wiphy
.bands
[band
]->ht_cap
.cap
);
491 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
492 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_factor
);
493 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
494 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_density
);
497 /* add frequencies */
498 nl_freqs
= nla_nest_start(msg
, NL80211_BAND_ATTR_FREQS
);
500 goto nla_put_failure
;
502 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_channels
; i
++) {
503 nl_freq
= nla_nest_start(msg
, i
);
505 goto nla_put_failure
;
507 chan
= &dev
->wiphy
.bands
[band
]->channels
[i
];
509 if (nl80211_msg_put_channel(msg
, chan
))
510 goto nla_put_failure
;
512 nla_nest_end(msg
, nl_freq
);
515 nla_nest_end(msg
, nl_freqs
);
518 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
520 goto nla_put_failure
;
522 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_bitrates
; i
++) {
523 nl_rate
= nla_nest_start(msg
, i
);
525 goto nla_put_failure
;
527 rate
= &dev
->wiphy
.bands
[band
]->bitrates
[i
];
528 NLA_PUT_U32(msg
, NL80211_BITRATE_ATTR_RATE
,
530 if (rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
)
532 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
);
534 nla_nest_end(msg
, nl_rate
);
537 nla_nest_end(msg
, nl_rates
);
539 nla_nest_end(msg
, nl_band
);
541 nla_nest_end(msg
, nl_bands
);
543 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
545 goto nla_put_failure
;
550 if (dev->ops->op) { \
552 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
556 CMD(add_virtual_intf
, NEW_INTERFACE
);
557 CMD(change_virtual_intf
, SET_INTERFACE
);
558 CMD(add_key
, NEW_KEY
);
559 CMD(add_beacon
, NEW_BEACON
);
560 CMD(add_station
, NEW_STATION
);
561 CMD(add_mpath
, NEW_MPATH
);
562 CMD(set_mesh_params
, SET_MESH_PARAMS
);
563 CMD(change_bss
, SET_BSS
);
564 CMD(auth
, AUTHENTICATE
);
565 CMD(assoc
, ASSOCIATE
);
566 CMD(deauth
, DEAUTHENTICATE
);
567 CMD(disassoc
, DISASSOCIATE
);
568 CMD(join_ibss
, JOIN_IBSS
);
569 CMD(set_pmksa
, SET_PMKSA
);
570 CMD(del_pmksa
, DEL_PMKSA
);
571 CMD(flush_pmksa
, FLUSH_PMKSA
);
572 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
574 NLA_PUT_U32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
);
579 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
581 NLA_PUT_U32(msg
, i
, NL80211_CMD_CONNECT
);
584 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
586 NLA_PUT_U32(msg
, i
, NL80211_CMD_DISCONNECT
);
589 nla_nest_end(msg
, nl_cmds
);
591 return genlmsg_end(msg
, hdr
);
594 genlmsg_cancel(msg
, hdr
);
598 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
601 int start
= cb
->args
[0];
602 struct cfg80211_registered_device
*dev
;
604 mutex_lock(&cfg80211_mutex
);
605 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
606 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
610 if (nl80211_send_wiphy(skb
, NETLINK_CB(cb
->skb
).pid
,
611 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
617 mutex_unlock(&cfg80211_mutex
);
624 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
627 struct cfg80211_registered_device
*dev
;
629 dev
= cfg80211_get_dev_from_info(info
);
633 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
637 if (nl80211_send_wiphy(msg
, info
->snd_pid
, info
->snd_seq
, 0, dev
) < 0)
640 cfg80211_unlock_rdev(dev
);
642 return genlmsg_reply(msg
, info
);
647 cfg80211_unlock_rdev(dev
);
651 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
652 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
653 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
654 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
655 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
656 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
659 static int parse_txq_params(struct nlattr
*tb
[],
660 struct ieee80211_txq_params
*txq_params
)
662 if (!tb
[NL80211_TXQ_ATTR_QUEUE
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
663 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
664 !tb
[NL80211_TXQ_ATTR_AIFS
])
667 txq_params
->queue
= nla_get_u8(tb
[NL80211_TXQ_ATTR_QUEUE
]);
668 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
669 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
670 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
671 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
676 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
678 struct cfg80211_registered_device
*rdev
;
679 int result
= 0, rem_txq_params
= 0;
680 struct nlattr
*nl_txq_params
;
682 u8 retry_short
= 0, retry_long
= 0;
683 u32 frag_threshold
= 0, rts_threshold
= 0;
687 mutex_lock(&cfg80211_mutex
);
689 rdev
= __cfg80211_rdev_from_info(info
);
691 mutex_unlock(&cfg80211_mutex
);
692 result
= PTR_ERR(rdev
);
696 mutex_lock(&rdev
->mtx
);
698 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
699 result
= cfg80211_dev_rename(
700 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
702 mutex_unlock(&cfg80211_mutex
);
707 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
708 struct ieee80211_txq_params txq_params
;
709 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
711 if (!rdev
->ops
->set_txq_params
) {
712 result
= -EOPNOTSUPP
;
716 nla_for_each_nested(nl_txq_params
,
717 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
719 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
720 nla_data(nl_txq_params
),
721 nla_len(nl_txq_params
),
723 result
= parse_txq_params(tb
, &txq_params
);
727 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
734 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
735 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
740 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
741 channel_type
= nla_get_u32(info
->attrs
[
742 NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
743 if (channel_type
!= NL80211_CHAN_NO_HT
&&
744 channel_type
!= NL80211_CHAN_HT20
&&
745 channel_type
!= NL80211_CHAN_HT40PLUS
&&
746 channel_type
!= NL80211_CHAN_HT40MINUS
)
750 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
752 mutex_lock(&rdev
->devlist_mtx
);
753 result
= rdev_set_freq(rdev
, NULL
, freq
, channel_type
);
754 mutex_unlock(&rdev
->devlist_mtx
);
761 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
762 retry_short
= nla_get_u8(
763 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
764 if (retry_short
== 0) {
768 changed
|= WIPHY_PARAM_RETRY_SHORT
;
771 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
772 retry_long
= nla_get_u8(
773 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
774 if (retry_long
== 0) {
778 changed
|= WIPHY_PARAM_RETRY_LONG
;
781 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
782 frag_threshold
= nla_get_u32(
783 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
784 if (frag_threshold
< 256) {
788 if (frag_threshold
!= (u32
) -1) {
790 * Fragments (apart from the last one) are required to
791 * have even length. Make the fragmentation code
792 * simpler by stripping LSB should someone try to use
793 * odd threshold value.
795 frag_threshold
&= ~0x1;
797 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
800 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
801 rts_threshold
= nla_get_u32(
802 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
803 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
807 u8 old_retry_short
, old_retry_long
;
808 u32 old_frag_threshold
, old_rts_threshold
;
810 if (!rdev
->ops
->set_wiphy_params
) {
811 result
= -EOPNOTSUPP
;
815 old_retry_short
= rdev
->wiphy
.retry_short
;
816 old_retry_long
= rdev
->wiphy
.retry_long
;
817 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
818 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
820 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
821 rdev
->wiphy
.retry_short
= retry_short
;
822 if (changed
& WIPHY_PARAM_RETRY_LONG
)
823 rdev
->wiphy
.retry_long
= retry_long
;
824 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
825 rdev
->wiphy
.frag_threshold
= frag_threshold
;
826 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
827 rdev
->wiphy
.rts_threshold
= rts_threshold
;
829 result
= rdev
->ops
->set_wiphy_params(&rdev
->wiphy
, changed
);
831 rdev
->wiphy
.retry_short
= old_retry_short
;
832 rdev
->wiphy
.retry_long
= old_retry_long
;
833 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
834 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
839 mutex_unlock(&rdev
->mtx
);
846 static int nl80211_send_iface(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
847 struct cfg80211_registered_device
*rdev
,
848 struct net_device
*dev
)
852 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
856 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
857 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
858 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, dev
->name
);
859 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, dev
->ieee80211_ptr
->iftype
);
861 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
862 rdev
->devlist_generation
^
863 (cfg80211_rdev_list_generation
<< 2));
865 return genlmsg_end(msg
, hdr
);
868 genlmsg_cancel(msg
, hdr
);
872 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
876 int wp_start
= cb
->args
[0];
877 int if_start
= cb
->args
[1];
878 struct cfg80211_registered_device
*rdev
;
879 struct wireless_dev
*wdev
;
881 mutex_lock(&cfg80211_mutex
);
882 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
883 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
885 if (wp_idx
< wp_start
) {
891 mutex_lock(&rdev
->devlist_mtx
);
892 list_for_each_entry(wdev
, &rdev
->netdev_list
, list
) {
893 if (if_idx
< if_start
) {
897 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).pid
,
898 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
899 rdev
, wdev
->netdev
) < 0) {
900 mutex_unlock(&rdev
->devlist_mtx
);
905 mutex_unlock(&rdev
->devlist_mtx
);
910 mutex_unlock(&cfg80211_mutex
);
912 cb
->args
[0] = wp_idx
;
913 cb
->args
[1] = if_idx
;
918 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
921 struct cfg80211_registered_device
*dev
;
922 struct net_device
*netdev
;
925 err
= get_rdev_dev_by_info_ifindex(info
, &dev
, &netdev
);
929 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
933 if (nl80211_send_iface(msg
, info
->snd_pid
, info
->snd_seq
, 0,
938 cfg80211_unlock_rdev(dev
);
940 return genlmsg_reply(msg
, info
);
946 cfg80211_unlock_rdev(dev
);
950 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
951 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
952 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
953 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
954 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
955 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
958 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
960 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
968 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
969 nla
, mntr_flags_policy
))
972 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
974 *mntrflags
|= (1<<flag
);
979 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
980 struct net_device
*netdev
, u8 use_4addr
,
981 enum nl80211_iftype iftype
)
984 if (netdev
&& netdev
->br_port
)
990 case NL80211_IFTYPE_AP_VLAN
:
991 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
994 case NL80211_IFTYPE_STATION
:
995 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
1005 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1007 struct cfg80211_registered_device
*rdev
;
1008 struct vif_params params
;
1010 enum nl80211_iftype otype
, ntype
;
1011 struct net_device
*dev
;
1012 u32 _flags
, *flags
= NULL
;
1013 bool change
= false;
1015 memset(¶ms
, 0, sizeof(params
));
1019 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1023 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
1025 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1026 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1029 if (ntype
> NL80211_IFTYPE_MAX
) {
1035 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1036 if (ntype
!= NL80211_IFTYPE_MESH_POINT
) {
1040 params
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1041 params
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1045 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1046 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1048 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
1052 params
.use_4addr
= -1;
1055 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
1056 if (ntype
!= NL80211_IFTYPE_MONITOR
) {
1060 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
1070 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
1074 if (!err
&& params
.use_4addr
!= -1)
1075 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
1079 cfg80211_unlock_rdev(rdev
);
1085 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1087 struct cfg80211_registered_device
*rdev
;
1088 struct vif_params params
;
1090 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
1093 memset(¶ms
, 0, sizeof(params
));
1095 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
1098 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1099 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1100 if (type
> NL80211_IFTYPE_MAX
)
1106 rdev
= cfg80211_get_dev_from_info(info
);
1108 err
= PTR_ERR(rdev
);
1112 if (!rdev
->ops
->add_virtual_intf
||
1113 !(rdev
->wiphy
.interface_modes
& (1 << type
))) {
1118 if (type
== NL80211_IFTYPE_MESH_POINT
&&
1119 info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1120 params
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1121 params
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1124 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1125 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1126 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
1131 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
1132 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
1134 err
= rdev
->ops
->add_virtual_intf(&rdev
->wiphy
,
1135 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
1136 type
, err
? NULL
: &flags
, ¶ms
);
1139 cfg80211_unlock_rdev(rdev
);
1145 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1147 struct cfg80211_registered_device
*rdev
;
1149 struct net_device
*dev
;
1153 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1157 if (!rdev
->ops
->del_virtual_intf
) {
1162 err
= rdev
->ops
->del_virtual_intf(&rdev
->wiphy
, dev
);
1165 cfg80211_unlock_rdev(rdev
);
1172 struct get_key_cookie
{
1173 struct sk_buff
*msg
;
1178 static void get_key_callback(void *c
, struct key_params
*params
)
1181 struct get_key_cookie
*cookie
= c
;
1184 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
1185 params
->key_len
, params
->key
);
1188 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
1189 params
->seq_len
, params
->seq
);
1192 NLA_PUT_U32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
1195 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
1197 goto nla_put_failure
;
1200 NLA_PUT(cookie
->msg
, NL80211_KEY_DATA
,
1201 params
->key_len
, params
->key
);
1204 NLA_PUT(cookie
->msg
, NL80211_KEY_SEQ
,
1205 params
->seq_len
, params
->seq
);
1208 NLA_PUT_U32(cookie
->msg
, NL80211_KEY_CIPHER
,
1211 NLA_PUT_U8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
);
1213 nla_nest_end(cookie
->msg
, key
);
1220 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
1222 struct cfg80211_registered_device
*rdev
;
1224 struct net_device
*dev
;
1226 u8
*mac_addr
= NULL
;
1227 struct get_key_cookie cookie
= {
1231 struct sk_buff
*msg
;
1233 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
1234 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1239 if (info
->attrs
[NL80211_ATTR_MAC
])
1240 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1244 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1248 if (!rdev
->ops
->get_key
) {
1253 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1259 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1260 NL80211_CMD_NEW_KEY
);
1268 cookie
.idx
= key_idx
;
1270 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1271 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
1273 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1275 err
= rdev
->ops
->get_key(&rdev
->wiphy
, dev
, key_idx
, mac_addr
,
1276 &cookie
, get_key_callback
);
1282 goto nla_put_failure
;
1284 genlmsg_end(msg
, hdr
);
1285 err
= genlmsg_reply(msg
, info
);
1293 cfg80211_unlock_rdev(rdev
);
1301 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
1303 struct cfg80211_registered_device
*rdev
;
1304 struct key_parse key
;
1306 struct net_device
*dev
;
1307 int (*func
)(struct wiphy
*wiphy
, struct net_device
*netdev
,
1310 err
= nl80211_parse_key(info
, &key
);
1317 /* only support setting default key */
1318 if (!key
.def
&& !key
.defmgmt
)
1323 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1328 func
= rdev
->ops
->set_default_key
;
1330 func
= rdev
->ops
->set_default_mgmt_key
;
1337 wdev_lock(dev
->ieee80211_ptr
);
1338 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1340 err
= func(&rdev
->wiphy
, dev
, key
.idx
);
1342 #ifdef CONFIG_CFG80211_WEXT
1344 if (func
== rdev
->ops
->set_default_key
)
1345 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
1347 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
1350 wdev_unlock(dev
->ieee80211_ptr
);
1353 cfg80211_unlock_rdev(rdev
);
1362 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
1364 struct cfg80211_registered_device
*rdev
;
1366 struct net_device
*dev
;
1367 struct key_parse key
;
1368 u8
*mac_addr
= NULL
;
1370 err
= nl80211_parse_key(info
, &key
);
1377 if (info
->attrs
[NL80211_ATTR_MAC
])
1378 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1382 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1386 if (!rdev
->ops
->add_key
) {
1391 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
, mac_addr
)) {
1396 wdev_lock(dev
->ieee80211_ptr
);
1397 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1399 err
= rdev
->ops
->add_key(&rdev
->wiphy
, dev
, key
.idx
,
1401 wdev_unlock(dev
->ieee80211_ptr
);
1404 cfg80211_unlock_rdev(rdev
);
1412 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
1414 struct cfg80211_registered_device
*rdev
;
1416 struct net_device
*dev
;
1417 u8
*mac_addr
= NULL
;
1418 struct key_parse key
;
1420 err
= nl80211_parse_key(info
, &key
);
1424 if (info
->attrs
[NL80211_ATTR_MAC
])
1425 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1429 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1433 if (!rdev
->ops
->del_key
) {
1438 wdev_lock(dev
->ieee80211_ptr
);
1439 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1441 err
= rdev
->ops
->del_key(&rdev
->wiphy
, dev
, key
.idx
, mac_addr
);
1443 #ifdef CONFIG_CFG80211_WEXT
1445 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
1446 dev
->ieee80211_ptr
->wext
.default_key
= -1;
1447 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
1448 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
1451 wdev_unlock(dev
->ieee80211_ptr
);
1454 cfg80211_unlock_rdev(rdev
);
1463 static int nl80211_addset_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1465 int (*call
)(struct wiphy
*wiphy
, struct net_device
*dev
,
1466 struct beacon_parameters
*info
);
1467 struct cfg80211_registered_device
*rdev
;
1469 struct net_device
*dev
;
1470 struct beacon_parameters params
;
1473 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]))
1478 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1482 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1487 switch (info
->genlhdr
->cmd
) {
1488 case NL80211_CMD_NEW_BEACON
:
1489 /* these are required for NEW_BEACON */
1490 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
1491 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
1492 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1497 call
= rdev
->ops
->add_beacon
;
1499 case NL80211_CMD_SET_BEACON
:
1500 call
= rdev
->ops
->set_beacon
;
1513 memset(¶ms
, 0, sizeof(params
));
1515 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
1517 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
1521 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
1522 params
.dtim_period
=
1523 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
1527 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1528 params
.head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1530 nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1534 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
1535 params
.tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1537 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1546 err
= call(&rdev
->wiphy
, dev
, ¶ms
);
1549 cfg80211_unlock_rdev(rdev
);
1557 static int nl80211_del_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1559 struct cfg80211_registered_device
*rdev
;
1561 struct net_device
*dev
;
1565 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1569 if (!rdev
->ops
->del_beacon
) {
1574 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1578 err
= rdev
->ops
->del_beacon(&rdev
->wiphy
, dev
);
1581 cfg80211_unlock_rdev(rdev
);
1589 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
1590 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
1591 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
1592 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
1593 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
1596 static int parse_station_flags(struct genl_info
*info
,
1597 struct station_parameters
*params
)
1599 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
1604 * Try parsing the new attribute first so userspace
1605 * can specify both for older kernels.
1607 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
1609 struct nl80211_sta_flag_update
*sta_flags
;
1611 sta_flags
= nla_data(nla
);
1612 params
->sta_flags_mask
= sta_flags
->mask
;
1613 params
->sta_flags_set
= sta_flags
->set
;
1614 if ((params
->sta_flags_mask
|
1615 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
1620 /* if present, parse the old attribute */
1622 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
1626 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
1627 nla
, sta_flags_policy
))
1630 params
->sta_flags_mask
= (1 << __NL80211_STA_FLAG_AFTER_LAST
) - 1;
1631 params
->sta_flags_mask
&= ~1;
1633 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++)
1635 params
->sta_flags_set
|= (1<<flag
);
1640 static u16
nl80211_calculate_bitrate(struct rate_info
*rate
)
1642 int modulation
, streams
, bitrate
;
1644 if (!(rate
->flags
& RATE_INFO_FLAGS_MCS
))
1645 return rate
->legacy
;
1647 /* the formula below does only work for MCS values smaller than 32 */
1648 if (rate
->mcs
>= 32)
1651 modulation
= rate
->mcs
& 7;
1652 streams
= (rate
->mcs
>> 3) + 1;
1654 bitrate
= (rate
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
) ?
1658 bitrate
*= (modulation
+ 1);
1659 else if (modulation
== 4)
1660 bitrate
*= (modulation
+ 2);
1662 bitrate
*= (modulation
+ 3);
1666 if (rate
->flags
& RATE_INFO_FLAGS_SHORT_GI
)
1667 bitrate
= (bitrate
/ 9) * 10;
1669 /* do NOT round down here */
1670 return (bitrate
+ 50000) / 100000;
1673 static int nl80211_send_station(struct sk_buff
*msg
, u32 pid
, u32 seq
,
1674 int flags
, struct net_device
*dev
,
1675 u8
*mac_addr
, struct station_info
*sinfo
)
1678 struct nlattr
*sinfoattr
, *txrate
;
1681 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
1685 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1686 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1688 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
);
1690 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
1692 goto nla_put_failure
;
1693 if (sinfo
->filled
& STATION_INFO_INACTIVE_TIME
)
1694 NLA_PUT_U32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
1695 sinfo
->inactive_time
);
1696 if (sinfo
->filled
& STATION_INFO_RX_BYTES
)
1697 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_BYTES
,
1699 if (sinfo
->filled
& STATION_INFO_TX_BYTES
)
1700 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_BYTES
,
1702 if (sinfo
->filled
& STATION_INFO_LLID
)
1703 NLA_PUT_U16(msg
, NL80211_STA_INFO_LLID
,
1705 if (sinfo
->filled
& STATION_INFO_PLID
)
1706 NLA_PUT_U16(msg
, NL80211_STA_INFO_PLID
,
1708 if (sinfo
->filled
& STATION_INFO_PLINK_STATE
)
1709 NLA_PUT_U8(msg
, NL80211_STA_INFO_PLINK_STATE
,
1710 sinfo
->plink_state
);
1711 if (sinfo
->filled
& STATION_INFO_SIGNAL
)
1712 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL
,
1714 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
1715 txrate
= nla_nest_start(msg
, NL80211_STA_INFO_TX_BITRATE
);
1717 goto nla_put_failure
;
1719 /* nl80211_calculate_bitrate will return 0 for mcs >= 32 */
1720 bitrate
= nl80211_calculate_bitrate(&sinfo
->txrate
);
1722 NLA_PUT_U16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate
);
1724 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_MCS
)
1725 NLA_PUT_U8(msg
, NL80211_RATE_INFO_MCS
,
1727 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
)
1728 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
);
1729 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_SHORT_GI
)
1730 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_SHORT_GI
);
1732 nla_nest_end(msg
, txrate
);
1734 if (sinfo
->filled
& STATION_INFO_RX_PACKETS
)
1735 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_PACKETS
,
1737 if (sinfo
->filled
& STATION_INFO_TX_PACKETS
)
1738 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_PACKETS
,
1740 nla_nest_end(msg
, sinfoattr
);
1742 return genlmsg_end(msg
, hdr
);
1745 genlmsg_cancel(msg
, hdr
);
1749 static int nl80211_dump_station(struct sk_buff
*skb
,
1750 struct netlink_callback
*cb
)
1752 struct station_info sinfo
;
1753 struct cfg80211_registered_device
*dev
;
1754 struct net_device
*netdev
;
1755 u8 mac_addr
[ETH_ALEN
];
1756 int ifidx
= cb
->args
[0];
1757 int sta_idx
= cb
->args
[1];
1761 ifidx
= nl80211_get_ifidx(cb
);
1767 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
1773 dev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
1779 if (!dev
->ops
->dump_station
) {
1785 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
1792 if (nl80211_send_station(skb
,
1793 NETLINK_CB(cb
->skb
).pid
,
1794 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1804 cb
->args
[1] = sta_idx
;
1807 cfg80211_unlock_rdev(dev
);
1814 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
1816 struct cfg80211_registered_device
*rdev
;
1818 struct net_device
*dev
;
1819 struct station_info sinfo
;
1820 struct sk_buff
*msg
;
1821 u8
*mac_addr
= NULL
;
1823 memset(&sinfo
, 0, sizeof(sinfo
));
1825 if (!info
->attrs
[NL80211_ATTR_MAC
])
1828 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1832 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1836 if (!rdev
->ops
->get_station
) {
1841 err
= rdev
->ops
->get_station(&rdev
->wiphy
, dev
, mac_addr
, &sinfo
);
1845 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1849 if (nl80211_send_station(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1850 dev
, mac_addr
, &sinfo
) < 0)
1853 err
= genlmsg_reply(msg
, info
);
1859 cfg80211_unlock_rdev(rdev
);
1868 * Get vlan interface making sure it is running and on the right wiphy.
1870 static int get_vlan(struct genl_info
*info
,
1871 struct cfg80211_registered_device
*rdev
,
1872 struct net_device
**vlan
)
1874 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
1878 *vlan
= dev_get_by_index(genl_info_net(info
),
1879 nla_get_u32(vlanattr
));
1882 if (!(*vlan
)->ieee80211_ptr
)
1884 if ((*vlan
)->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
)
1886 if (!netif_running(*vlan
))
1892 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
1894 struct cfg80211_registered_device
*rdev
;
1896 struct net_device
*dev
;
1897 struct station_parameters params
;
1898 u8
*mac_addr
= NULL
;
1900 memset(¶ms
, 0, sizeof(params
));
1902 params
.listen_interval
= -1;
1904 if (info
->attrs
[NL80211_ATTR_STA_AID
])
1907 if (!info
->attrs
[NL80211_ATTR_MAC
])
1910 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1912 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
1913 params
.supported_rates
=
1914 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1915 params
.supported_rates_len
=
1916 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1919 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
1920 params
.listen_interval
=
1921 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
1923 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
1925 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
1927 if (parse_station_flags(info
, ¶ms
))
1930 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
1931 params
.plink_action
=
1932 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
1936 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1940 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
1944 /* validate settings */
1947 switch (dev
->ieee80211_ptr
->iftype
) {
1948 case NL80211_IFTYPE_AP
:
1949 case NL80211_IFTYPE_AP_VLAN
:
1950 /* disallow mesh-specific things */
1951 if (params
.plink_action
)
1954 case NL80211_IFTYPE_STATION
:
1955 /* disallow everything but AUTHORIZED flag */
1956 if (params
.plink_action
)
1960 if (params
.supported_rates
)
1964 if (params
.listen_interval
>= 0)
1966 if (params
.sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
1969 case NL80211_IFTYPE_MESH_POINT
:
1970 /* disallow things mesh doesn't support */
1975 if (params
.listen_interval
>= 0)
1977 if (params
.supported_rates
)
1979 if (params
.sta_flags_mask
)
1989 if (!rdev
->ops
->change_station
) {
1994 err
= rdev
->ops
->change_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
1998 dev_put(params
.vlan
);
1999 cfg80211_unlock_rdev(rdev
);
2007 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
2009 struct cfg80211_registered_device
*rdev
;
2011 struct net_device
*dev
;
2012 struct station_parameters params
;
2013 u8
*mac_addr
= NULL
;
2015 memset(¶ms
, 0, sizeof(params
));
2017 if (!info
->attrs
[NL80211_ATTR_MAC
])
2020 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2023 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
2026 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2027 params
.supported_rates
=
2028 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2029 params
.supported_rates_len
=
2030 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2031 params
.listen_interval
=
2032 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2034 if (info
->attrs
[NL80211_ATTR_STA_AID
]) {
2035 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
2036 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
2040 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2042 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2044 if (parse_station_flags(info
, ¶ms
))
2049 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2053 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
2057 /* validate settings */
2060 switch (dev
->ieee80211_ptr
->iftype
) {
2061 case NL80211_IFTYPE_AP
:
2062 case NL80211_IFTYPE_AP_VLAN
:
2063 /* all ok but must have AID */
2067 case NL80211_IFTYPE_MESH_POINT
:
2068 /* disallow things mesh doesn't support */
2075 if (params
.listen_interval
>= 0)
2077 if (params
.supported_rates
)
2079 if (params
.sta_flags_mask
)
2089 if (!rdev
->ops
->add_station
) {
2094 if (!netif_running(dev
)) {
2099 err
= rdev
->ops
->add_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2103 dev_put(params
.vlan
);
2104 cfg80211_unlock_rdev(rdev
);
2112 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
2114 struct cfg80211_registered_device
*rdev
;
2116 struct net_device
*dev
;
2117 u8
*mac_addr
= NULL
;
2119 if (info
->attrs
[NL80211_ATTR_MAC
])
2120 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2124 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2128 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2129 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
2130 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2135 if (!rdev
->ops
->del_station
) {
2140 err
= rdev
->ops
->del_station(&rdev
->wiphy
, dev
, mac_addr
);
2143 cfg80211_unlock_rdev(rdev
);
2151 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2152 int flags
, struct net_device
*dev
,
2153 u8
*dst
, u8
*next_hop
,
2154 struct mpath_info
*pinfo
)
2157 struct nlattr
*pinfoattr
;
2159 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2163 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2164 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
2165 NLA_PUT(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
);
2167 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
);
2169 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
2171 goto nla_put_failure
;
2172 if (pinfo
->filled
& MPATH_INFO_FRAME_QLEN
)
2173 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
2175 if (pinfo
->filled
& MPATH_INFO_SN
)
2176 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_SN
,
2178 if (pinfo
->filled
& MPATH_INFO_METRIC
)
2179 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_METRIC
,
2181 if (pinfo
->filled
& MPATH_INFO_EXPTIME
)
2182 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_EXPTIME
,
2184 if (pinfo
->filled
& MPATH_INFO_FLAGS
)
2185 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_FLAGS
,
2187 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
)
2188 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
2189 pinfo
->discovery_timeout
);
2190 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
)
2191 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
2192 pinfo
->discovery_retries
);
2194 nla_nest_end(msg
, pinfoattr
);
2196 return genlmsg_end(msg
, hdr
);
2199 genlmsg_cancel(msg
, hdr
);
2203 static int nl80211_dump_mpath(struct sk_buff
*skb
,
2204 struct netlink_callback
*cb
)
2206 struct mpath_info pinfo
;
2207 struct cfg80211_registered_device
*dev
;
2208 struct net_device
*netdev
;
2210 u8 next_hop
[ETH_ALEN
];
2211 int ifidx
= cb
->args
[0];
2212 int path_idx
= cb
->args
[1];
2216 ifidx
= nl80211_get_ifidx(cb
);
2222 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
2228 dev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
2234 if (!dev
->ops
->dump_mpath
) {
2239 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2245 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
2246 dst
, next_hop
, &pinfo
);
2252 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).pid
,
2253 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2254 netdev
, dst
, next_hop
,
2263 cb
->args
[1] = path_idx
;
2266 cfg80211_unlock_rdev(dev
);
2273 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2275 struct cfg80211_registered_device
*rdev
;
2277 struct net_device
*dev
;
2278 struct mpath_info pinfo
;
2279 struct sk_buff
*msg
;
2281 u8 next_hop
[ETH_ALEN
];
2283 memset(&pinfo
, 0, sizeof(pinfo
));
2285 if (!info
->attrs
[NL80211_ATTR_MAC
])
2288 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2292 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2296 if (!rdev
->ops
->get_mpath
) {
2301 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2306 err
= rdev
->ops
->get_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
2310 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2314 if (nl80211_send_mpath(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2315 dev
, dst
, next_hop
, &pinfo
) < 0)
2318 err
= genlmsg_reply(msg
, info
);
2324 cfg80211_unlock_rdev(rdev
);
2332 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2334 struct cfg80211_registered_device
*rdev
;
2336 struct net_device
*dev
;
2338 u8
*next_hop
= NULL
;
2340 if (!info
->attrs
[NL80211_ATTR_MAC
])
2343 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2346 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2347 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2351 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2355 if (!rdev
->ops
->change_mpath
) {
2360 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2365 if (!netif_running(dev
)) {
2370 err
= rdev
->ops
->change_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2373 cfg80211_unlock_rdev(rdev
);
2380 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2382 struct cfg80211_registered_device
*rdev
;
2384 struct net_device
*dev
;
2386 u8
*next_hop
= NULL
;
2388 if (!info
->attrs
[NL80211_ATTR_MAC
])
2391 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2394 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2395 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2399 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2403 if (!rdev
->ops
->add_mpath
) {
2408 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2413 if (!netif_running(dev
)) {
2418 err
= rdev
->ops
->add_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2421 cfg80211_unlock_rdev(rdev
);
2429 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2431 struct cfg80211_registered_device
*rdev
;
2433 struct net_device
*dev
;
2436 if (info
->attrs
[NL80211_ATTR_MAC
])
2437 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2441 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2445 if (!rdev
->ops
->del_mpath
) {
2450 err
= rdev
->ops
->del_mpath(&rdev
->wiphy
, dev
, dst
);
2453 cfg80211_unlock_rdev(rdev
);
2461 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
2463 struct cfg80211_registered_device
*rdev
;
2465 struct net_device
*dev
;
2466 struct bss_parameters params
;
2468 memset(¶ms
, 0, sizeof(params
));
2469 /* default to not changing parameters */
2470 params
.use_cts_prot
= -1;
2471 params
.use_short_preamble
= -1;
2472 params
.use_short_slot_time
= -1;
2474 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
2475 params
.use_cts_prot
=
2476 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
2477 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
2478 params
.use_short_preamble
=
2479 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
2480 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
2481 params
.use_short_slot_time
=
2482 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
2483 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
2484 params
.basic_rates
=
2485 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2486 params
.basic_rates_len
=
2487 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2492 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2496 if (!rdev
->ops
->change_bss
) {
2501 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
2506 err
= rdev
->ops
->change_bss(&rdev
->wiphy
, dev
, ¶ms
);
2509 cfg80211_unlock_rdev(rdev
);
2517 static const struct nla_policy
2518 reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
2519 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
2520 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
2521 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
2522 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
2523 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
2524 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
2527 static int parse_reg_rule(struct nlattr
*tb
[],
2528 struct ieee80211_reg_rule
*reg_rule
)
2530 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
2531 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
2533 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
2535 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
2537 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
2539 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
2541 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
2544 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
2546 freq_range
->start_freq_khz
=
2547 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
2548 freq_range
->end_freq_khz
=
2549 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
2550 freq_range
->max_bandwidth_khz
=
2551 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
2553 power_rule
->max_eirp
=
2554 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
2556 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
2557 power_rule
->max_antenna_gain
=
2558 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
2563 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2569 * You should only get this when cfg80211 hasn't yet initialized
2570 * completely when built-in to the kernel right between the time
2571 * window between nl80211_init() and regulatory_init(), if that is
2574 mutex_lock(&cfg80211_mutex
);
2575 if (unlikely(!cfg80211_regdomain
)) {
2576 mutex_unlock(&cfg80211_mutex
);
2577 return -EINPROGRESS
;
2579 mutex_unlock(&cfg80211_mutex
);
2581 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2584 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2586 #ifdef CONFIG_WIRELESS_OLD_REGULATORY
2587 /* We ignore world regdom requests with the old regdom setup */
2588 if (is_world_regdom(data
))
2592 r
= regulatory_hint_user(data
);
2597 static int nl80211_get_mesh_params(struct sk_buff
*skb
,
2598 struct genl_info
*info
)
2600 struct cfg80211_registered_device
*rdev
;
2601 struct mesh_config cur_params
;
2603 struct net_device
*dev
;
2605 struct nlattr
*pinfoattr
;
2606 struct sk_buff
*msg
;
2610 /* Look up our device */
2611 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2615 if (!rdev
->ops
->get_mesh_params
) {
2620 /* Get the mesh params */
2621 err
= rdev
->ops
->get_mesh_params(&rdev
->wiphy
, dev
, &cur_params
);
2625 /* Draw up a netlink message to send back */
2626 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2631 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2632 NL80211_CMD_GET_MESH_PARAMS
);
2634 goto nla_put_failure
;
2635 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_PARAMS
);
2637 goto nla_put_failure
;
2638 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2639 NLA_PUT_U16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
2640 cur_params
.dot11MeshRetryTimeout
);
2641 NLA_PUT_U16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
2642 cur_params
.dot11MeshConfirmTimeout
);
2643 NLA_PUT_U16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
2644 cur_params
.dot11MeshHoldingTimeout
);
2645 NLA_PUT_U16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
2646 cur_params
.dot11MeshMaxPeerLinks
);
2647 NLA_PUT_U8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
2648 cur_params
.dot11MeshMaxRetries
);
2649 NLA_PUT_U8(msg
, NL80211_MESHCONF_TTL
,
2650 cur_params
.dot11MeshTTL
);
2651 NLA_PUT_U8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
2652 cur_params
.auto_open_plinks
);
2653 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2654 cur_params
.dot11MeshHWMPmaxPREQretries
);
2655 NLA_PUT_U32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
2656 cur_params
.path_refresh_time
);
2657 NLA_PUT_U16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2658 cur_params
.min_discovery_timeout
);
2659 NLA_PUT_U32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2660 cur_params
.dot11MeshHWMPactivePathTimeout
);
2661 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2662 cur_params
.dot11MeshHWMPpreqMinInterval
);
2663 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2664 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
);
2665 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
2666 cur_params
.dot11MeshHWMPRootMode
);
2667 nla_nest_end(msg
, pinfoattr
);
2668 genlmsg_end(msg
, hdr
);
2669 err
= genlmsg_reply(msg
, info
);
2673 genlmsg_cancel(msg
, hdr
);
2677 cfg80211_unlock_rdev(rdev
);
2685 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2687 if (table[attr_num]) {\
2688 cfg.param = nla_fn(table[attr_num]); \
2689 mask |= (1 << (attr_num - 1)); \
2693 static struct nla_policy
2694 nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] __read_mostly
= {
2695 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
2696 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
2697 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
2698 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
2699 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
2700 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
2701 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
2703 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
2704 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
2705 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
2706 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
2707 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
2708 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
2711 static int nl80211_set_mesh_params(struct sk_buff
*skb
, struct genl_info
*info
)
2715 struct cfg80211_registered_device
*rdev
;
2716 struct net_device
*dev
;
2717 struct mesh_config cfg
;
2718 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
2719 struct nlattr
*parent_attr
;
2721 parent_attr
= info
->attrs
[NL80211_ATTR_MESH_PARAMS
];
2724 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
2725 parent_attr
, nl80211_meshconf_params_policy
))
2730 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2734 if (!rdev
->ops
->set_mesh_params
) {
2739 /* This makes sure that there aren't more than 32 mesh config
2740 * parameters (otherwise our bitfield scheme would not work.) */
2741 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
2743 /* Fill in the params struct */
2745 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
2746 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
, nla_get_u16
);
2747 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
2748 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
, nla_get_u16
);
2749 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
2750 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
, nla_get_u16
);
2751 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
2752 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
, nla_get_u16
);
2753 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
2754 mask
, NL80211_MESHCONF_MAX_RETRIES
, nla_get_u8
);
2755 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
2756 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
2757 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
2758 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
, nla_get_u8
);
2759 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
2760 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2762 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
2763 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
, nla_get_u32
);
2764 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
2765 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2767 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
2768 mask
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2770 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
2771 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2773 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
2774 dot11MeshHWMPnetDiameterTraversalTime
,
2775 mask
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2777 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
2778 dot11MeshHWMPRootMode
, mask
,
2779 NL80211_MESHCONF_HWMP_ROOTMODE
,
2783 err
= rdev
->ops
->set_mesh_params(&rdev
->wiphy
, dev
, &cfg
, mask
);
2787 cfg80211_unlock_rdev(rdev
);
2795 #undef FILL_IN_MESH_PARAM_IF_SET
2797 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2799 struct sk_buff
*msg
;
2801 struct nlattr
*nl_reg_rules
;
2805 mutex_lock(&cfg80211_mutex
);
2807 if (!cfg80211_regdomain
)
2810 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2816 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2817 NL80211_CMD_GET_REG
);
2819 goto nla_put_failure
;
2821 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
,
2822 cfg80211_regdomain
->alpha2
);
2824 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
2826 goto nla_put_failure
;
2828 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
2829 struct nlattr
*nl_reg_rule
;
2830 const struct ieee80211_reg_rule
*reg_rule
;
2831 const struct ieee80211_freq_range
*freq_range
;
2832 const struct ieee80211_power_rule
*power_rule
;
2834 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
2835 freq_range
= ®_rule
->freq_range
;
2836 power_rule
= ®_rule
->power_rule
;
2838 nl_reg_rule
= nla_nest_start(msg
, i
);
2840 goto nla_put_failure
;
2842 NLA_PUT_U32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
2844 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
2845 freq_range
->start_freq_khz
);
2846 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
2847 freq_range
->end_freq_khz
);
2848 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
2849 freq_range
->max_bandwidth_khz
);
2850 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
2851 power_rule
->max_antenna_gain
);
2852 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
2853 power_rule
->max_eirp
);
2855 nla_nest_end(msg
, nl_reg_rule
);
2858 nla_nest_end(msg
, nl_reg_rules
);
2860 genlmsg_end(msg
, hdr
);
2861 err
= genlmsg_reply(msg
, info
);
2865 genlmsg_cancel(msg
, hdr
);
2868 mutex_unlock(&cfg80211_mutex
);
2872 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2874 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
2875 struct nlattr
*nl_reg_rule
;
2876 char *alpha2
= NULL
;
2877 int rem_reg_rules
= 0, r
= 0;
2878 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
2879 struct ieee80211_regdomain
*rd
= NULL
;
2881 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2884 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
2887 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2889 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
2892 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
2896 mutex_lock(&cfg80211_mutex
);
2898 if (!reg_is_valid_request(alpha2
)) {
2903 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
2904 (num_rules
* sizeof(struct ieee80211_reg_rule
));
2906 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
2912 rd
->n_reg_rules
= num_rules
;
2913 rd
->alpha2
[0] = alpha2
[0];
2914 rd
->alpha2
[1] = alpha2
[1];
2916 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
2918 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
2919 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
2921 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
2927 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
2933 BUG_ON(rule_idx
!= num_rules
);
2937 mutex_unlock(&cfg80211_mutex
);
2942 mutex_unlock(&cfg80211_mutex
);
2947 static int validate_scan_freqs(struct nlattr
*freqs
)
2949 struct nlattr
*attr1
, *attr2
;
2950 int n_channels
= 0, tmp1
, tmp2
;
2952 nla_for_each_nested(attr1
, freqs
, tmp1
) {
2955 * Some hardware has a limited channel list for
2956 * scanning, and it is pretty much nonsensical
2957 * to scan for a channel twice, so disallow that
2958 * and don't require drivers to check that the
2959 * channel list they get isn't longer than what
2960 * they can scan, as long as they can scan all
2961 * the channels they registered at once.
2963 nla_for_each_nested(attr2
, freqs
, tmp2
)
2964 if (attr1
!= attr2
&&
2965 nla_get_u32(attr1
) == nla_get_u32(attr2
))
2972 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
2974 struct cfg80211_registered_device
*rdev
;
2975 struct net_device
*dev
;
2976 struct cfg80211_scan_request
*request
;
2977 struct cfg80211_ssid
*ssid
;
2978 struct ieee80211_channel
*channel
;
2979 struct nlattr
*attr
;
2980 struct wiphy
*wiphy
;
2981 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
2982 enum ieee80211_band band
;
2985 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
2990 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2994 wiphy
= &rdev
->wiphy
;
2996 if (!rdev
->ops
->scan
) {
3001 if (!netif_running(dev
)) {
3006 if (rdev
->scan_req
) {
3011 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3012 n_channels
= validate_scan_freqs(
3013 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
3021 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
3022 if (wiphy
->bands
[band
])
3023 n_channels
+= wiphy
->bands
[band
]->n_channels
;
3026 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
3027 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
3030 if (n_ssids
> wiphy
->max_scan_ssids
) {
3035 if (info
->attrs
[NL80211_ATTR_IE
])
3036 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3040 if (ie_len
> wiphy
->max_scan_ie_len
) {
3045 request
= kzalloc(sizeof(*request
)
3046 + sizeof(*ssid
) * n_ssids
3047 + sizeof(channel
) * n_channels
3048 + ie_len
, GFP_KERNEL
);
3055 request
->ssids
= (void *)&request
->channels
[n_channels
];
3056 request
->n_ssids
= n_ssids
;
3059 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
3061 request
->ie
= (void *)(request
->channels
+ n_channels
);
3065 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3066 /* user specified, bail out if channel not found */
3067 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
3068 struct ieee80211_channel
*chan
;
3070 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
3077 /* ignore disabled channels */
3078 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3081 request
->channels
[i
] = chan
;
3086 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
3088 if (!wiphy
->bands
[band
])
3090 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
3091 struct ieee80211_channel
*chan
;
3093 chan
= &wiphy
->bands
[band
]->channels
[j
];
3095 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3098 request
->channels
[i
] = chan
;
3109 request
->n_channels
= i
;
3112 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
3113 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
3114 if (request
->ssids
[i
].ssid_len
> IEEE80211_MAX_SSID_LEN
) {
3118 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
3119 request
->ssids
[i
].ssid_len
= nla_len(attr
);
3124 if (info
->attrs
[NL80211_ATTR_IE
]) {
3125 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3126 memcpy((void *)request
->ie
,
3127 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
3132 request
->wiphy
= &rdev
->wiphy
;
3134 rdev
->scan_req
= request
;
3135 err
= rdev
->ops
->scan(&rdev
->wiphy
, dev
, request
);
3138 nl80211_send_scan_start(rdev
, dev
);
3144 rdev
->scan_req
= NULL
;
3148 cfg80211_unlock_rdev(rdev
);
3156 static int nl80211_send_bss(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
3157 struct cfg80211_registered_device
*rdev
,
3158 struct wireless_dev
*wdev
,
3159 struct cfg80211_internal_bss
*intbss
)
3161 struct cfg80211_bss
*res
= &intbss
->pub
;
3166 ASSERT_WDEV_LOCK(wdev
);
3168 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3169 NL80211_CMD_NEW_SCAN_RESULTS
);
3173 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
);
3174 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
);
3176 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
3178 goto nla_put_failure
;
3179 if (!is_zero_ether_addr(res
->bssid
))
3180 NLA_PUT(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
);
3181 if (res
->information_elements
&& res
->len_information_elements
)
3182 NLA_PUT(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
3183 res
->len_information_elements
,
3184 res
->information_elements
);
3186 NLA_PUT_U64(msg
, NL80211_BSS_TSF
, res
->tsf
);
3187 if (res
->beacon_interval
)
3188 NLA_PUT_U16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
);
3189 NLA_PUT_U16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
);
3190 NLA_PUT_U32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
);
3191 NLA_PUT_U32(msg
, NL80211_BSS_SEEN_MS_AGO
,
3192 jiffies_to_msecs(jiffies
- intbss
->ts
));
3194 switch (rdev
->wiphy
.signal_type
) {
3195 case CFG80211_SIGNAL_TYPE_MBM
:
3196 NLA_PUT_U32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
);
3198 case CFG80211_SIGNAL_TYPE_UNSPEC
:
3199 NLA_PUT_U8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
);
3205 switch (wdev
->iftype
) {
3206 case NL80211_IFTYPE_STATION
:
3207 if (intbss
== wdev
->current_bss
)
3208 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3209 NL80211_BSS_STATUS_ASSOCIATED
);
3210 else for (i
= 0; i
< MAX_AUTH_BSSES
; i
++) {
3211 if (intbss
!= wdev
->auth_bsses
[i
])
3213 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3214 NL80211_BSS_STATUS_AUTHENTICATED
);
3218 case NL80211_IFTYPE_ADHOC
:
3219 if (intbss
== wdev
->current_bss
)
3220 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3221 NL80211_BSS_STATUS_IBSS_JOINED
);
3227 nla_nest_end(msg
, bss
);
3229 return genlmsg_end(msg
, hdr
);
3232 genlmsg_cancel(msg
, hdr
);
3236 static int nl80211_dump_scan(struct sk_buff
*skb
,
3237 struct netlink_callback
*cb
)
3239 struct cfg80211_registered_device
*rdev
;
3240 struct net_device
*dev
;
3241 struct cfg80211_internal_bss
*scan
;
3242 struct wireless_dev
*wdev
;
3243 int ifidx
= cb
->args
[0];
3244 int start
= cb
->args
[1], idx
= 0;
3248 ifidx
= nl80211_get_ifidx(cb
);
3251 cb
->args
[0] = ifidx
;
3253 dev
= dev_get_by_index(sock_net(skb
->sk
), ifidx
);
3257 rdev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
3259 err
= PTR_ERR(rdev
);
3260 goto out_put_netdev
;
3263 wdev
= dev
->ieee80211_ptr
;
3266 spin_lock_bh(&rdev
->bss_lock
);
3267 cfg80211_bss_expire(rdev
);
3269 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
3272 if (nl80211_send_bss(skb
,
3273 NETLINK_CB(cb
->skb
).pid
,
3274 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3275 rdev
, wdev
, scan
) < 0) {
3282 spin_unlock_bh(&rdev
->bss_lock
);
3287 cfg80211_unlock_rdev(rdev
);
3294 static int nl80211_send_survey(struct sk_buff
*msg
, u32 pid
, u32 seq
,
3295 int flags
, struct net_device
*dev
,
3296 struct survey_info
*survey
)
3299 struct nlattr
*infoattr
;
3301 /* Survey without a channel doesn't make sense */
3302 if (!survey
->channel
)
3305 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3306 NL80211_CMD_NEW_SURVEY_RESULTS
);
3310 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
3312 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
3314 goto nla_put_failure
;
3316 NLA_PUT_U32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
3317 survey
->channel
->center_freq
);
3318 if (survey
->filled
& SURVEY_INFO_NOISE_DBM
)
3319 NLA_PUT_U8(msg
, NL80211_SURVEY_INFO_NOISE
,
3322 nla_nest_end(msg
, infoattr
);
3324 return genlmsg_end(msg
, hdr
);
3327 genlmsg_cancel(msg
, hdr
);
3331 static int nl80211_dump_survey(struct sk_buff
*skb
,
3332 struct netlink_callback
*cb
)
3334 struct survey_info survey
;
3335 struct cfg80211_registered_device
*dev
;
3336 struct net_device
*netdev
;
3337 int ifidx
= cb
->args
[0];
3338 int survey_idx
= cb
->args
[1];
3342 ifidx
= nl80211_get_ifidx(cb
);
3345 cb
->args
[0] = ifidx
;
3349 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
3355 dev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
3361 if (!dev
->ops
->dump_survey
) {
3367 res
= dev
->ops
->dump_survey(&dev
->wiphy
, netdev
, survey_idx
,
3374 if (nl80211_send_survey(skb
,
3375 NETLINK_CB(cb
->skb
).pid
,
3376 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3384 cb
->args
[1] = survey_idx
;
3387 cfg80211_unlock_rdev(dev
);
3394 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
)
3396 return auth_type
<= NL80211_AUTHTYPE_MAX
;
3399 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
3401 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
3402 NL80211_WPA_VERSION_2
));
3405 static bool nl80211_valid_akm_suite(u32 akm
)
3407 return akm
== WLAN_AKM_SUITE_8021X
||
3408 akm
== WLAN_AKM_SUITE_PSK
;
3411 static bool nl80211_valid_cipher_suite(u32 cipher
)
3413 return cipher
== WLAN_CIPHER_SUITE_WEP40
||
3414 cipher
== WLAN_CIPHER_SUITE_WEP104
||
3415 cipher
== WLAN_CIPHER_SUITE_TKIP
||
3416 cipher
== WLAN_CIPHER_SUITE_CCMP
||
3417 cipher
== WLAN_CIPHER_SUITE_AES_CMAC
;
3421 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3423 struct cfg80211_registered_device
*rdev
;
3424 struct net_device
*dev
;
3425 struct ieee80211_channel
*chan
;
3426 const u8
*bssid
, *ssid
, *ie
= NULL
;
3427 int err
, ssid_len
, ie_len
= 0;
3428 enum nl80211_auth_type auth_type
;
3429 struct key_parse key
;
3431 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3434 if (!info
->attrs
[NL80211_ATTR_MAC
])
3437 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
3440 if (!info
->attrs
[NL80211_ATTR_SSID
])
3443 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
3446 err
= nl80211_parse_key(info
, &key
);
3451 if (!key
.p
.key
|| !key
.p
.key_len
)
3453 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
3454 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
3455 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
3456 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
3467 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3471 if (!rdev
->ops
->auth
) {
3476 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3481 if (!netif_running(dev
)) {
3486 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3487 chan
= ieee80211_get_channel(&rdev
->wiphy
,
3488 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3489 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
)) {
3494 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3495 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3497 if (info
->attrs
[NL80211_ATTR_IE
]) {
3498 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3499 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3502 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3503 if (!nl80211_valid_auth_type(auth_type
)) {
3508 err
= cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
3509 ssid
, ssid_len
, ie
, ie_len
,
3510 key
.p
.key
, key
.p
.key_len
, key
.idx
);
3513 cfg80211_unlock_rdev(rdev
);
3520 static int nl80211_crypto_settings(struct genl_info
*info
,
3521 struct cfg80211_crypto_settings
*settings
,
3524 memset(settings
, 0, sizeof(*settings
));
3526 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
3528 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
3532 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
3533 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
3534 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
3536 if (len
% sizeof(u32
))
3539 if (settings
->n_ciphers_pairwise
> cipher_limit
)
3542 memcpy(settings
->ciphers_pairwise
, data
, len
);
3544 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
3545 if (!nl80211_valid_cipher_suite(
3546 settings
->ciphers_pairwise
[i
]))
3550 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
3551 settings
->cipher_group
=
3552 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
3553 if (!nl80211_valid_cipher_suite(settings
->cipher_group
))
3557 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
3558 settings
->wpa_versions
=
3559 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
3560 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
3564 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
3568 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
3569 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
3570 settings
->n_akm_suites
= len
/ sizeof(u32
);
3572 if (len
% sizeof(u32
))
3575 memcpy(settings
->akm_suites
, data
, len
);
3577 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
3578 if (!nl80211_valid_akm_suite(settings
->akm_suites
[i
]))
3585 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
3587 struct cfg80211_registered_device
*rdev
;
3588 struct net_device
*dev
;
3589 struct cfg80211_crypto_settings crypto
;
3590 struct ieee80211_channel
*chan
, *fixedchan
;
3591 const u8
*bssid
, *ssid
, *ie
= NULL
, *prev_bssid
= NULL
;
3592 int err
, ssid_len
, ie_len
= 0;
3593 bool use_mfp
= false;
3595 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3598 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
3599 !info
->attrs
[NL80211_ATTR_SSID
] ||
3600 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
3605 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3609 if (!rdev
->ops
->assoc
) {
3614 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3619 if (!netif_running(dev
)) {
3624 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3626 chan
= ieee80211_get_channel(&rdev
->wiphy
,
3627 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3628 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
)) {
3633 mutex_lock(&rdev
->devlist_mtx
);
3634 fixedchan
= rdev_fixed_channel(rdev
, NULL
);
3635 if (fixedchan
&& chan
!= fixedchan
) {
3637 mutex_unlock(&rdev
->devlist_mtx
);
3640 mutex_unlock(&rdev
->devlist_mtx
);
3642 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3643 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3645 if (info
->attrs
[NL80211_ATTR_IE
]) {
3646 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3647 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3650 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
3651 enum nl80211_mfp mfp
=
3652 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
3653 if (mfp
== NL80211_MFP_REQUIRED
)
3655 else if (mfp
!= NL80211_MFP_NO
) {
3661 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
3662 prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
3664 err
= nl80211_crypto_settings(info
, &crypto
, 1);
3666 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
, prev_bssid
,
3667 ssid
, ssid_len
, ie
, ie_len
, use_mfp
,
3671 cfg80211_unlock_rdev(rdev
);
3678 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3680 struct cfg80211_registered_device
*rdev
;
3681 struct net_device
*dev
;
3682 const u8
*ie
= NULL
, *bssid
;
3683 int err
, ie_len
= 0;
3686 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3689 if (!info
->attrs
[NL80211_ATTR_MAC
])
3692 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3697 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3701 if (!rdev
->ops
->deauth
) {
3706 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3711 if (!netif_running(dev
)) {
3716 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3718 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3719 if (reason_code
== 0) {
3720 /* Reason Code 0 is reserved */
3725 if (info
->attrs
[NL80211_ATTR_IE
]) {
3726 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3727 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3730 err
= cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
);
3733 cfg80211_unlock_rdev(rdev
);
3740 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
3742 struct cfg80211_registered_device
*rdev
;
3743 struct net_device
*dev
;
3744 const u8
*ie
= NULL
, *bssid
;
3745 int err
, ie_len
= 0;
3748 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3751 if (!info
->attrs
[NL80211_ATTR_MAC
])
3754 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3759 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3763 if (!rdev
->ops
->disassoc
) {
3768 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3773 if (!netif_running(dev
)) {
3778 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3780 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3781 if (reason_code
== 0) {
3782 /* Reason Code 0 is reserved */
3787 if (info
->attrs
[NL80211_ATTR_IE
]) {
3788 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3789 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3792 err
= cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
);
3795 cfg80211_unlock_rdev(rdev
);
3802 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
3804 struct cfg80211_registered_device
*rdev
;
3805 struct net_device
*dev
;
3806 struct cfg80211_ibss_params ibss
;
3807 struct wiphy
*wiphy
;
3808 struct cfg80211_cached_keys
*connkeys
= NULL
;
3811 memset(&ibss
, 0, sizeof(ibss
));
3813 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3816 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
3817 !info
->attrs
[NL80211_ATTR_SSID
] ||
3818 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
3821 ibss
.beacon_interval
= 100;
3823 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
3824 ibss
.beacon_interval
=
3825 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3826 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
3832 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3836 if (!rdev
->ops
->join_ibss
) {
3841 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
3846 if (!netif_running(dev
)) {
3851 wiphy
= &rdev
->wiphy
;
3853 if (info
->attrs
[NL80211_ATTR_MAC
])
3854 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3855 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3856 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3858 if (info
->attrs
[NL80211_ATTR_IE
]) {
3859 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3860 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3863 ibss
.channel
= ieee80211_get_channel(wiphy
,
3864 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3865 if (!ibss
.channel
||
3866 ibss
.channel
->flags
& IEEE80211_CHAN_NO_IBSS
||
3867 ibss
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
3872 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
3873 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3875 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
3876 connkeys
= nl80211_parse_connkeys(rdev
,
3877 info
->attrs
[NL80211_ATTR_KEYS
]);
3878 if (IS_ERR(connkeys
)) {
3879 err
= PTR_ERR(connkeys
);
3885 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
3888 cfg80211_unlock_rdev(rdev
);
3897 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
3899 struct cfg80211_registered_device
*rdev
;
3900 struct net_device
*dev
;
3905 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3909 if (!rdev
->ops
->leave_ibss
) {
3914 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
3919 if (!netif_running(dev
)) {
3924 err
= cfg80211_leave_ibss(rdev
, dev
, false);
3927 cfg80211_unlock_rdev(rdev
);
3934 #ifdef CONFIG_NL80211_TESTMODE
3935 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
3939 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
3941 struct cfg80211_registered_device
*rdev
;
3944 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
3949 rdev
= cfg80211_get_dev_from_info(info
);
3951 err
= PTR_ERR(rdev
);
3956 if (rdev
->ops
->testmode_cmd
) {
3957 rdev
->testmode_info
= info
;
3958 err
= rdev
->ops
->testmode_cmd(&rdev
->wiphy
,
3959 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
3960 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
3961 rdev
->testmode_info
= NULL
;
3964 cfg80211_unlock_rdev(rdev
);
3971 static struct sk_buff
*
3972 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
3973 int approxlen
, u32 pid
, u32 seq
, gfp_t gfp
)
3975 struct sk_buff
*skb
;
3977 struct nlattr
*data
;
3979 skb
= nlmsg_new(approxlen
+ 100, gfp
);
3983 hdr
= nl80211hdr_put(skb
, pid
, seq
, 0, NL80211_CMD_TESTMODE
);
3989 NLA_PUT_U32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
3990 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
3992 ((void **)skb
->cb
)[0] = rdev
;
3993 ((void **)skb
->cb
)[1] = hdr
;
3994 ((void **)skb
->cb
)[2] = data
;
4003 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
4006 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4008 if (WARN_ON(!rdev
->testmode_info
))
4011 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
4012 rdev
->testmode_info
->snd_pid
,
4013 rdev
->testmode_info
->snd_seq
,
4016 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
4018 int cfg80211_testmode_reply(struct sk_buff
*skb
)
4020 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
4021 void *hdr
= ((void **)skb
->cb
)[1];
4022 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4024 if (WARN_ON(!rdev
->testmode_info
)) {
4029 nla_nest_end(skb
, data
);
4030 genlmsg_end(skb
, hdr
);
4031 return genlmsg_reply(skb
, rdev
->testmode_info
);
4033 EXPORT_SYMBOL(cfg80211_testmode_reply
);
4035 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
4036 int approxlen
, gfp_t gfp
)
4038 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4040 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
4042 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
4044 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
4046 void *hdr
= ((void **)skb
->cb
)[1];
4047 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4049 nla_nest_end(skb
, data
);
4050 genlmsg_end(skb
, hdr
);
4051 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
4053 EXPORT_SYMBOL(cfg80211_testmode_event
);
4056 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
4058 struct cfg80211_registered_device
*rdev
;
4059 struct net_device
*dev
;
4060 struct cfg80211_connect_params connect
;
4061 struct wiphy
*wiphy
;
4062 struct cfg80211_cached_keys
*connkeys
= NULL
;
4065 memset(&connect
, 0, sizeof(connect
));
4067 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4070 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
4071 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
4074 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
4076 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4077 if (!nl80211_valid_auth_type(connect
.auth_type
))
4080 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
4082 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
4084 err
= nl80211_crypto_settings(info
, &connect
.crypto
,
4085 NL80211_MAX_NR_CIPHER_SUITES
);
4090 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4094 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4099 if (!netif_running(dev
)) {
4104 wiphy
= &rdev
->wiphy
;
4106 if (info
->attrs
[NL80211_ATTR_MAC
])
4107 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4108 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4109 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4111 if (info
->attrs
[NL80211_ATTR_IE
]) {
4112 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4113 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4116 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
4118 ieee80211_get_channel(wiphy
,
4119 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4120 if (!connect
.channel
||
4121 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
4127 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
4128 connkeys
= nl80211_parse_connkeys(rdev
,
4129 info
->attrs
[NL80211_ATTR_KEYS
]);
4130 if (IS_ERR(connkeys
)) {
4131 err
= PTR_ERR(connkeys
);
4137 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
4140 cfg80211_unlock_rdev(rdev
);
4149 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
4151 struct cfg80211_registered_device
*rdev
;
4152 struct net_device
*dev
;
4156 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4157 reason
= WLAN_REASON_DEAUTH_LEAVING
;
4159 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4166 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4170 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4175 if (!netif_running(dev
)) {
4180 err
= cfg80211_disconnect(rdev
, dev
, reason
, true);
4183 cfg80211_unlock_rdev(rdev
);
4190 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
4192 struct cfg80211_registered_device
*rdev
;
4197 if (!info
->attrs
[NL80211_ATTR_PID
])
4200 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
4204 rdev
= cfg80211_get_dev_from_info(info
);
4206 err
= PTR_ERR(rdev
);
4210 net
= get_net_ns_by_pid(pid
);
4218 /* check if anything to do */
4219 if (net_eq(wiphy_net(&rdev
->wiphy
), net
))
4222 err
= cfg80211_switch_netns(rdev
, net
);
4226 cfg80211_unlock_rdev(rdev
);
4232 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4234 struct cfg80211_registered_device
*rdev
;
4235 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
4236 struct cfg80211_pmksa
*pmksa
) = NULL
;
4238 struct net_device
*dev
;
4239 struct cfg80211_pmksa pmksa
;
4241 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
4243 if (!info
->attrs
[NL80211_ATTR_MAC
])
4246 if (!info
->attrs
[NL80211_ATTR_PMKID
])
4251 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4255 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
4256 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4258 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4263 switch (info
->genlhdr
->cmd
) {
4264 case NL80211_CMD_SET_PMKSA
:
4265 rdev_ops
= rdev
->ops
->set_pmksa
;
4267 case NL80211_CMD_DEL_PMKSA
:
4268 rdev_ops
= rdev
->ops
->del_pmksa
;
4280 err
= rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
4283 cfg80211_unlock_rdev(rdev
);
4291 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4293 struct cfg80211_registered_device
*rdev
;
4295 struct net_device
*dev
;
4299 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4303 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4308 if (!rdev
->ops
->flush_pmksa
) {
4313 err
= rdev
->ops
->flush_pmksa(&rdev
->wiphy
, dev
);
4316 cfg80211_unlock_rdev(rdev
);
4325 static struct genl_ops nl80211_ops
[] = {
4327 .cmd
= NL80211_CMD_GET_WIPHY
,
4328 .doit
= nl80211_get_wiphy
,
4329 .dumpit
= nl80211_dump_wiphy
,
4330 .policy
= nl80211_policy
,
4331 /* can be retrieved by unprivileged users */
4334 .cmd
= NL80211_CMD_SET_WIPHY
,
4335 .doit
= nl80211_set_wiphy
,
4336 .policy
= nl80211_policy
,
4337 .flags
= GENL_ADMIN_PERM
,
4340 .cmd
= NL80211_CMD_GET_INTERFACE
,
4341 .doit
= nl80211_get_interface
,
4342 .dumpit
= nl80211_dump_interface
,
4343 .policy
= nl80211_policy
,
4344 /* can be retrieved by unprivileged users */
4347 .cmd
= NL80211_CMD_SET_INTERFACE
,
4348 .doit
= nl80211_set_interface
,
4349 .policy
= nl80211_policy
,
4350 .flags
= GENL_ADMIN_PERM
,
4353 .cmd
= NL80211_CMD_NEW_INTERFACE
,
4354 .doit
= nl80211_new_interface
,
4355 .policy
= nl80211_policy
,
4356 .flags
= GENL_ADMIN_PERM
,
4359 .cmd
= NL80211_CMD_DEL_INTERFACE
,
4360 .doit
= nl80211_del_interface
,
4361 .policy
= nl80211_policy
,
4362 .flags
= GENL_ADMIN_PERM
,
4365 .cmd
= NL80211_CMD_GET_KEY
,
4366 .doit
= nl80211_get_key
,
4367 .policy
= nl80211_policy
,
4368 .flags
= GENL_ADMIN_PERM
,
4371 .cmd
= NL80211_CMD_SET_KEY
,
4372 .doit
= nl80211_set_key
,
4373 .policy
= nl80211_policy
,
4374 .flags
= GENL_ADMIN_PERM
,
4377 .cmd
= NL80211_CMD_NEW_KEY
,
4378 .doit
= nl80211_new_key
,
4379 .policy
= nl80211_policy
,
4380 .flags
= GENL_ADMIN_PERM
,
4383 .cmd
= NL80211_CMD_DEL_KEY
,
4384 .doit
= nl80211_del_key
,
4385 .policy
= nl80211_policy
,
4386 .flags
= GENL_ADMIN_PERM
,
4389 .cmd
= NL80211_CMD_SET_BEACON
,
4390 .policy
= nl80211_policy
,
4391 .flags
= GENL_ADMIN_PERM
,
4392 .doit
= nl80211_addset_beacon
,
4395 .cmd
= NL80211_CMD_NEW_BEACON
,
4396 .policy
= nl80211_policy
,
4397 .flags
= GENL_ADMIN_PERM
,
4398 .doit
= nl80211_addset_beacon
,
4401 .cmd
= NL80211_CMD_DEL_BEACON
,
4402 .policy
= nl80211_policy
,
4403 .flags
= GENL_ADMIN_PERM
,
4404 .doit
= nl80211_del_beacon
,
4407 .cmd
= NL80211_CMD_GET_STATION
,
4408 .doit
= nl80211_get_station
,
4409 .dumpit
= nl80211_dump_station
,
4410 .policy
= nl80211_policy
,
4413 .cmd
= NL80211_CMD_SET_STATION
,
4414 .doit
= nl80211_set_station
,
4415 .policy
= nl80211_policy
,
4416 .flags
= GENL_ADMIN_PERM
,
4419 .cmd
= NL80211_CMD_NEW_STATION
,
4420 .doit
= nl80211_new_station
,
4421 .policy
= nl80211_policy
,
4422 .flags
= GENL_ADMIN_PERM
,
4425 .cmd
= NL80211_CMD_DEL_STATION
,
4426 .doit
= nl80211_del_station
,
4427 .policy
= nl80211_policy
,
4428 .flags
= GENL_ADMIN_PERM
,
4431 .cmd
= NL80211_CMD_GET_MPATH
,
4432 .doit
= nl80211_get_mpath
,
4433 .dumpit
= nl80211_dump_mpath
,
4434 .policy
= nl80211_policy
,
4435 .flags
= GENL_ADMIN_PERM
,
4438 .cmd
= NL80211_CMD_SET_MPATH
,
4439 .doit
= nl80211_set_mpath
,
4440 .policy
= nl80211_policy
,
4441 .flags
= GENL_ADMIN_PERM
,
4444 .cmd
= NL80211_CMD_NEW_MPATH
,
4445 .doit
= nl80211_new_mpath
,
4446 .policy
= nl80211_policy
,
4447 .flags
= GENL_ADMIN_PERM
,
4450 .cmd
= NL80211_CMD_DEL_MPATH
,
4451 .doit
= nl80211_del_mpath
,
4452 .policy
= nl80211_policy
,
4453 .flags
= GENL_ADMIN_PERM
,
4456 .cmd
= NL80211_CMD_SET_BSS
,
4457 .doit
= nl80211_set_bss
,
4458 .policy
= nl80211_policy
,
4459 .flags
= GENL_ADMIN_PERM
,
4462 .cmd
= NL80211_CMD_GET_REG
,
4463 .doit
= nl80211_get_reg
,
4464 .policy
= nl80211_policy
,
4465 /* can be retrieved by unprivileged users */
4468 .cmd
= NL80211_CMD_SET_REG
,
4469 .doit
= nl80211_set_reg
,
4470 .policy
= nl80211_policy
,
4471 .flags
= GENL_ADMIN_PERM
,
4474 .cmd
= NL80211_CMD_REQ_SET_REG
,
4475 .doit
= nl80211_req_set_reg
,
4476 .policy
= nl80211_policy
,
4477 .flags
= GENL_ADMIN_PERM
,
4480 .cmd
= NL80211_CMD_GET_MESH_PARAMS
,
4481 .doit
= nl80211_get_mesh_params
,
4482 .policy
= nl80211_policy
,
4483 /* can be retrieved by unprivileged users */
4486 .cmd
= NL80211_CMD_SET_MESH_PARAMS
,
4487 .doit
= nl80211_set_mesh_params
,
4488 .policy
= nl80211_policy
,
4489 .flags
= GENL_ADMIN_PERM
,
4492 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
4493 .doit
= nl80211_trigger_scan
,
4494 .policy
= nl80211_policy
,
4495 .flags
= GENL_ADMIN_PERM
,
4498 .cmd
= NL80211_CMD_GET_SCAN
,
4499 .policy
= nl80211_policy
,
4500 .dumpit
= nl80211_dump_scan
,
4503 .cmd
= NL80211_CMD_AUTHENTICATE
,
4504 .doit
= nl80211_authenticate
,
4505 .policy
= nl80211_policy
,
4506 .flags
= GENL_ADMIN_PERM
,
4509 .cmd
= NL80211_CMD_ASSOCIATE
,
4510 .doit
= nl80211_associate
,
4511 .policy
= nl80211_policy
,
4512 .flags
= GENL_ADMIN_PERM
,
4515 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
4516 .doit
= nl80211_deauthenticate
,
4517 .policy
= nl80211_policy
,
4518 .flags
= GENL_ADMIN_PERM
,
4521 .cmd
= NL80211_CMD_DISASSOCIATE
,
4522 .doit
= nl80211_disassociate
,
4523 .policy
= nl80211_policy
,
4524 .flags
= GENL_ADMIN_PERM
,
4527 .cmd
= NL80211_CMD_JOIN_IBSS
,
4528 .doit
= nl80211_join_ibss
,
4529 .policy
= nl80211_policy
,
4530 .flags
= GENL_ADMIN_PERM
,
4533 .cmd
= NL80211_CMD_LEAVE_IBSS
,
4534 .doit
= nl80211_leave_ibss
,
4535 .policy
= nl80211_policy
,
4536 .flags
= GENL_ADMIN_PERM
,
4538 #ifdef CONFIG_NL80211_TESTMODE
4540 .cmd
= NL80211_CMD_TESTMODE
,
4541 .doit
= nl80211_testmode_do
,
4542 .policy
= nl80211_policy
,
4543 .flags
= GENL_ADMIN_PERM
,
4547 .cmd
= NL80211_CMD_CONNECT
,
4548 .doit
= nl80211_connect
,
4549 .policy
= nl80211_policy
,
4550 .flags
= GENL_ADMIN_PERM
,
4553 .cmd
= NL80211_CMD_DISCONNECT
,
4554 .doit
= nl80211_disconnect
,
4555 .policy
= nl80211_policy
,
4556 .flags
= GENL_ADMIN_PERM
,
4559 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
4560 .doit
= nl80211_wiphy_netns
,
4561 .policy
= nl80211_policy
,
4562 .flags
= GENL_ADMIN_PERM
,
4565 .cmd
= NL80211_CMD_GET_SURVEY
,
4566 .policy
= nl80211_policy
,
4567 .dumpit
= nl80211_dump_survey
,
4570 .cmd
= NL80211_CMD_SET_PMKSA
,
4571 .doit
= nl80211_setdel_pmksa
,
4572 .policy
= nl80211_policy
,
4573 .flags
= GENL_ADMIN_PERM
,
4576 .cmd
= NL80211_CMD_DEL_PMKSA
,
4577 .doit
= nl80211_setdel_pmksa
,
4578 .policy
= nl80211_policy
,
4579 .flags
= GENL_ADMIN_PERM
,
4582 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
4583 .doit
= nl80211_flush_pmksa
,
4584 .policy
= nl80211_policy
,
4585 .flags
= GENL_ADMIN_PERM
,
4589 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
4593 /* multicast groups */
4594 static struct genl_multicast_group nl80211_config_mcgrp
= {
4597 static struct genl_multicast_group nl80211_scan_mcgrp
= {
4600 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
4601 .name
= "regulatory",
4604 /* notification functions */
4606 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
4608 struct sk_buff
*msg
;
4610 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4614 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
4619 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
4620 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
4623 static int nl80211_add_scan_req(struct sk_buff
*msg
,
4624 struct cfg80211_registered_device
*rdev
)
4626 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
4627 struct nlattr
*nest
;
4630 ASSERT_RDEV_LOCK(rdev
);
4635 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
4637 goto nla_put_failure
;
4638 for (i
= 0; i
< req
->n_ssids
; i
++)
4639 NLA_PUT(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
);
4640 nla_nest_end(msg
, nest
);
4642 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
4644 goto nla_put_failure
;
4645 for (i
= 0; i
< req
->n_channels
; i
++)
4646 NLA_PUT_U32(msg
, i
, req
->channels
[i
]->center_freq
);
4647 nla_nest_end(msg
, nest
);
4650 NLA_PUT(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
);
4657 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
4658 struct cfg80211_registered_device
*rdev
,
4659 struct net_device
*netdev
,
4660 u32 pid
, u32 seq
, int flags
,
4665 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
4669 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4670 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
4672 /* ignore errors and send incomplete event anyway */
4673 nl80211_add_scan_req(msg
, rdev
);
4675 return genlmsg_end(msg
, hdr
);
4678 genlmsg_cancel(msg
, hdr
);
4682 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
4683 struct net_device
*netdev
)
4685 struct sk_buff
*msg
;
4687 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
4691 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
4692 NL80211_CMD_TRIGGER_SCAN
) < 0) {
4697 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
4698 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
4701 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
4702 struct net_device
*netdev
)
4704 struct sk_buff
*msg
;
4706 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4710 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
4711 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
4716 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
4717 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
4720 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
4721 struct net_device
*netdev
)
4723 struct sk_buff
*msg
;
4725 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4729 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
4730 NL80211_CMD_SCAN_ABORTED
) < 0) {
4735 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
4736 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
4740 * This can happen on global regulatory changes or device specific settings
4741 * based on custom world regulatory domains.
4743 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
4745 struct sk_buff
*msg
;
4748 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4752 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
4758 /* Userspace can always count this one always being set */
4759 NLA_PUT_U8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
);
4761 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0')
4762 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
4763 NL80211_REGDOM_TYPE_WORLD
);
4764 else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9')
4765 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
4766 NL80211_REGDOM_TYPE_CUSTOM_WORLD
);
4767 else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
4769 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
4770 NL80211_REGDOM_TYPE_INTERSECTION
);
4772 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
4773 NL80211_REGDOM_TYPE_COUNTRY
);
4774 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, request
->alpha2
);
4777 if (wiphy_idx_valid(request
->wiphy_idx
))
4778 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
);
4780 if (genlmsg_end(msg
, hdr
) < 0) {
4786 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
4793 genlmsg_cancel(msg
, hdr
);
4797 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
4798 struct net_device
*netdev
,
4799 const u8
*buf
, size_t len
,
4800 enum nl80211_commands cmd
, gfp_t gfp
)
4802 struct sk_buff
*msg
;
4805 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
4809 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
4815 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4816 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
4817 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
4819 if (genlmsg_end(msg
, hdr
) < 0) {
4824 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
4825 nl80211_mlme_mcgrp
.id
, gfp
);
4829 genlmsg_cancel(msg
, hdr
);
4833 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
4834 struct net_device
*netdev
, const u8
*buf
,
4835 size_t len
, gfp_t gfp
)
4837 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
4838 NL80211_CMD_AUTHENTICATE
, gfp
);
4841 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
4842 struct net_device
*netdev
, const u8
*buf
,
4843 size_t len
, gfp_t gfp
)
4845 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
4846 NL80211_CMD_ASSOCIATE
, gfp
);
4849 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
4850 struct net_device
*netdev
, const u8
*buf
,
4851 size_t len
, gfp_t gfp
)
4853 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
4854 NL80211_CMD_DEAUTHENTICATE
, gfp
);
4857 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
4858 struct net_device
*netdev
, const u8
*buf
,
4859 size_t len
, gfp_t gfp
)
4861 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
4862 NL80211_CMD_DISASSOCIATE
, gfp
);
4865 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
4866 struct net_device
*netdev
, int cmd
,
4867 const u8
*addr
, gfp_t gfp
)
4869 struct sk_buff
*msg
;
4872 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
4876 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
4882 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4883 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
4884 NLA_PUT_FLAG(msg
, NL80211_ATTR_TIMED_OUT
);
4885 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
4887 if (genlmsg_end(msg
, hdr
) < 0) {
4892 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
4893 nl80211_mlme_mcgrp
.id
, gfp
);
4897 genlmsg_cancel(msg
, hdr
);
4901 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
4902 struct net_device
*netdev
, const u8
*addr
,
4905 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
4909 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
4910 struct net_device
*netdev
, const u8
*addr
,
4913 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
4917 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
4918 struct net_device
*netdev
, const u8
*bssid
,
4919 const u8
*req_ie
, size_t req_ie_len
,
4920 const u8
*resp_ie
, size_t resp_ie_len
,
4921 u16 status
, gfp_t gfp
)
4923 struct sk_buff
*msg
;
4926 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
4930 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
4936 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4937 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
4939 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
4940 NLA_PUT_U16(msg
, NL80211_ATTR_STATUS_CODE
, status
);
4942 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
4944 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
4946 if (genlmsg_end(msg
, hdr
) < 0) {
4951 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
4952 nl80211_mlme_mcgrp
.id
, gfp
);
4956 genlmsg_cancel(msg
, hdr
);
4961 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
4962 struct net_device
*netdev
, const u8
*bssid
,
4963 const u8
*req_ie
, size_t req_ie_len
,
4964 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
4966 struct sk_buff
*msg
;
4969 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
4973 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
4979 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4980 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
4981 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
4983 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
4985 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
4987 if (genlmsg_end(msg
, hdr
) < 0) {
4992 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
4993 nl80211_mlme_mcgrp
.id
, gfp
);
4997 genlmsg_cancel(msg
, hdr
);
5002 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
5003 struct net_device
*netdev
, u16 reason
,
5004 const u8
*ie
, size_t ie_len
, bool from_ap
)
5006 struct sk_buff
*msg
;
5009 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
5013 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
5019 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5020 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5021 if (from_ap
&& reason
)
5022 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason
);
5024 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
);
5026 NLA_PUT(msg
, NL80211_ATTR_IE
, ie_len
, ie
);
5028 if (genlmsg_end(msg
, hdr
) < 0) {
5033 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5034 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
5038 genlmsg_cancel(msg
, hdr
);
5043 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
5044 struct net_device
*netdev
, const u8
*bssid
,
5047 struct sk_buff
*msg
;
5050 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5054 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
5060 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5061 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5062 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
5064 if (genlmsg_end(msg
, hdr
) < 0) {
5069 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5070 nl80211_mlme_mcgrp
.id
, gfp
);
5074 genlmsg_cancel(msg
, hdr
);
5078 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
5079 struct net_device
*netdev
, const u8
*addr
,
5080 enum nl80211_key_type key_type
, int key_id
,
5081 const u8
*tsc
, gfp_t gfp
)
5083 struct sk_buff
*msg
;
5086 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5090 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
5096 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5097 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5099 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5100 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
);
5101 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_id
);
5103 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
);
5105 if (genlmsg_end(msg
, hdr
) < 0) {
5110 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5111 nl80211_mlme_mcgrp
.id
, gfp
);
5115 genlmsg_cancel(msg
, hdr
);
5119 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
5120 struct ieee80211_channel
*channel_before
,
5121 struct ieee80211_channel
*channel_after
)
5123 struct sk_buff
*msg
;
5125 struct nlattr
*nl_freq
;
5127 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
5131 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
5138 * Since we are applying the beacon hint to a wiphy we know its
5139 * wiphy_idx is valid
5141 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
));
5144 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
5146 goto nla_put_failure
;
5147 if (nl80211_msg_put_channel(msg
, channel_before
))
5148 goto nla_put_failure
;
5149 nla_nest_end(msg
, nl_freq
);
5152 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
5154 goto nla_put_failure
;
5155 if (nl80211_msg_put_channel(msg
, channel_after
))
5156 goto nla_put_failure
;
5157 nla_nest_end(msg
, nl_freq
);
5159 if (genlmsg_end(msg
, hdr
) < 0) {
5165 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
5172 genlmsg_cancel(msg
, hdr
);
5176 /* initialisation/exit functions */
5178 int nl80211_init(void)
5182 err
= genl_register_family_with_ops(&nl80211_fam
,
5183 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
5187 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
5191 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
5195 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
5199 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
5203 #ifdef CONFIG_NL80211_TESTMODE
5204 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
5211 genl_unregister_family(&nl80211_fam
);
5215 void nl80211_exit(void)
5217 genl_unregister_family(&nl80211_fam
);