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/genetlink.h>
18 #include <net/cfg80211.h>
23 /* the netlink family */
24 static struct genl_family nl80211_fam
= {
25 .id
= GENL_ID_GENERATE
, /* don't bother with a hardcoded ID */
26 .name
= "nl80211", /* have users key off the name instead */
27 .hdrsize
= 0, /* no private header */
28 .version
= 1, /* no particular meaning now */
29 .maxattr
= NL80211_ATTR_MAX
,
32 /* internal helper: get rdev and dev */
33 static int get_rdev_dev_by_info_ifindex(struct nlattr
**attrs
,
34 struct cfg80211_registered_device
**rdev
,
35 struct net_device
**dev
)
39 if (!attrs
[NL80211_ATTR_IFINDEX
])
42 ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
43 *dev
= dev_get_by_index(&init_net
, ifindex
);
47 *rdev
= cfg80211_get_dev_from_ifindex(ifindex
);
50 return PTR_ERR(*rdev
);
56 /* policy for the attributes */
57 static struct nla_policy nl80211_policy
[NL80211_ATTR_MAX
+1] __read_mostly
= {
58 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
59 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
61 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
62 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
63 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
64 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
65 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
66 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
67 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
69 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
70 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
71 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
73 [NL80211_ATTR_MAC
] = { .type
= NLA_BINARY
, .len
= ETH_ALEN
},
74 [NL80211_ATTR_PREV_BSSID
] = { .type
= NLA_BINARY
, .len
= ETH_ALEN
},
76 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
77 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
78 .len
= WLAN_MAX_KEY_LEN
},
79 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
80 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
81 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
82 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 8 },
84 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
85 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
86 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
87 .len
= IEEE80211_MAX_DATA_LEN
},
88 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
89 .len
= IEEE80211_MAX_DATA_LEN
},
90 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
91 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
92 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
93 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
94 .len
= NL80211_MAX_SUPP_RATES
},
95 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
96 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
97 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
98 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
99 .len
= IEEE80211_MAX_MESH_ID_LEN
},
100 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
102 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
103 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
105 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
106 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
107 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
108 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
109 .len
= NL80211_MAX_SUPP_RATES
},
111 [NL80211_ATTR_MESH_PARAMS
] = { .type
= NLA_NESTED
},
113 [NL80211_ATTR_HT_CAPABILITY
] = { .type
= NLA_BINARY
,
114 .len
= NL80211_HT_CAPABILITY_LEN
},
116 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
117 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
118 .len
= IEEE80211_MAX_DATA_LEN
},
119 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
120 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
122 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
123 .len
= IEEE80211_MAX_SSID_LEN
},
124 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
125 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
126 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
127 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
128 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
129 [NL80211_ATTR_STA_FLAGS2
] = {
130 .len
= sizeof(struct nl80211_sta_flag_update
),
132 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
133 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
134 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
135 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
138 /* policy for the attributes */
139 static struct nla_policy
140 nl80211_key_policy
[NL80211_KEY_MAX
+ 1] __read_mostly
= {
141 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
142 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
143 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
144 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 8 },
145 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
146 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
150 static bool is_valid_ie_attr(const struct nlattr
*attr
)
158 pos
= nla_data(attr
);
179 /* message building helper */
180 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 pid
, u32 seq
,
183 /* since there is no private header just add the generic one */
184 return genlmsg_put(skb
, pid
, seq
, &nl80211_fam
, flags
, cmd
);
187 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
188 struct ieee80211_channel
*chan
)
190 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
193 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
194 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_DISABLED
);
195 if (chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
196 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
);
197 if (chan
->flags
& IEEE80211_CHAN_NO_IBSS
)
198 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
);
199 if (chan
->flags
& IEEE80211_CHAN_RADAR
)
200 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_RADAR
);
202 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
203 DBM_TO_MBM(chan
->max_power
));
211 /* netlink command implementations */
219 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
221 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
222 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
227 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
228 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
230 if (tb
[NL80211_KEY_IDX
])
231 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
233 if (tb
[NL80211_KEY_DATA
]) {
234 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
235 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
238 if (tb
[NL80211_KEY_SEQ
]) {
239 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
240 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
243 if (tb
[NL80211_KEY_CIPHER
])
244 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
249 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
251 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
252 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
253 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
256 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
257 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
258 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
261 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
262 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
264 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
265 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
267 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
268 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
273 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
277 memset(k
, 0, sizeof(*k
));
280 if (info
->attrs
[NL80211_ATTR_KEY
])
281 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
283 err
= nl80211_parse_key_old(info
, k
);
288 if (k
->def
&& k
->defmgmt
)
293 if (k
->idx
< 4 || k
->idx
> 5)
296 if (k
->idx
< 0 || k
->idx
> 3)
299 if (k
->idx
< 0 || k
->idx
> 5)
307 static struct cfg80211_cached_keys
*
308 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
311 struct key_parse parse
;
313 struct cfg80211_cached_keys
*result
;
314 int rem
, err
, def
= 0;
316 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
318 return ERR_PTR(-ENOMEM
);
321 result
->defmgmt
= -1;
323 nla_for_each_nested(key
, keys
, rem
) {
324 memset(&parse
, 0, sizeof(parse
));
327 err
= nl80211_parse_key_new(key
, &parse
);
333 if (parse
.idx
< 0 || parse
.idx
> 4)
339 result
->def
= parse
.idx
;
340 } else if (parse
.defmgmt
)
342 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
346 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
347 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
348 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
349 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
358 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
360 ASSERT_WDEV_LOCK(wdev
);
362 if (!netif_running(wdev
->netdev
))
365 switch (wdev
->iftype
) {
366 case NL80211_IFTYPE_AP
:
367 case NL80211_IFTYPE_AP_VLAN
:
369 case NL80211_IFTYPE_ADHOC
:
370 if (!wdev
->current_bss
)
373 case NL80211_IFTYPE_STATION
:
374 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
384 static int nl80211_send_wiphy(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
385 struct cfg80211_registered_device
*dev
)
388 struct nlattr
*nl_bands
, *nl_band
;
389 struct nlattr
*nl_freqs
, *nl_freq
;
390 struct nlattr
*nl_rates
, *nl_rate
;
391 struct nlattr
*nl_modes
;
392 struct nlattr
*nl_cmds
;
393 enum ieee80211_band band
;
394 struct ieee80211_channel
*chan
;
395 struct ieee80211_rate
*rate
;
397 u16 ifmodes
= dev
->wiphy
.interface_modes
;
399 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
403 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
);
404 NLA_PUT_STRING(msg
, NL80211_ATTR_WIPHY_NAME
, wiphy_name(&dev
->wiphy
));
406 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
407 dev
->wiphy
.retry_short
);
408 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
409 dev
->wiphy
.retry_long
);
410 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
411 dev
->wiphy
.frag_threshold
);
412 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
413 dev
->wiphy
.rts_threshold
);
415 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
416 dev
->wiphy
.max_scan_ssids
);
417 NLA_PUT_U16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
418 dev
->wiphy
.max_scan_ie_len
);
420 NLA_PUT(msg
, NL80211_ATTR_CIPHER_SUITES
,
421 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
422 dev
->wiphy
.cipher_suites
);
424 nl_modes
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
);
426 goto nla_put_failure
;
431 NLA_PUT_FLAG(msg
, i
);
436 nla_nest_end(msg
, nl_modes
);
438 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
440 goto nla_put_failure
;
442 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
443 if (!dev
->wiphy
.bands
[band
])
446 nl_band
= nla_nest_start(msg
, band
);
448 goto nla_put_failure
;
451 if (dev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
) {
452 NLA_PUT(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
453 sizeof(dev
->wiphy
.bands
[band
]->ht_cap
.mcs
),
454 &dev
->wiphy
.bands
[band
]->ht_cap
.mcs
);
455 NLA_PUT_U16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
456 dev
->wiphy
.bands
[band
]->ht_cap
.cap
);
457 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
458 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_factor
);
459 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
460 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_density
);
463 /* add frequencies */
464 nl_freqs
= nla_nest_start(msg
, NL80211_BAND_ATTR_FREQS
);
466 goto nla_put_failure
;
468 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_channels
; i
++) {
469 nl_freq
= nla_nest_start(msg
, i
);
471 goto nla_put_failure
;
473 chan
= &dev
->wiphy
.bands
[band
]->channels
[i
];
475 if (nl80211_msg_put_channel(msg
, chan
))
476 goto nla_put_failure
;
478 nla_nest_end(msg
, nl_freq
);
481 nla_nest_end(msg
, nl_freqs
);
484 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
486 goto nla_put_failure
;
488 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_bitrates
; i
++) {
489 nl_rate
= nla_nest_start(msg
, i
);
491 goto nla_put_failure
;
493 rate
= &dev
->wiphy
.bands
[band
]->bitrates
[i
];
494 NLA_PUT_U32(msg
, NL80211_BITRATE_ATTR_RATE
,
496 if (rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
)
498 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
);
500 nla_nest_end(msg
, nl_rate
);
503 nla_nest_end(msg
, nl_rates
);
505 nla_nest_end(msg
, nl_band
);
507 nla_nest_end(msg
, nl_bands
);
509 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
511 goto nla_put_failure
;
516 if (dev->ops->op) { \
518 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
522 CMD(add_virtual_intf
, NEW_INTERFACE
);
523 CMD(change_virtual_intf
, SET_INTERFACE
);
524 CMD(add_key
, NEW_KEY
);
525 CMD(add_beacon
, NEW_BEACON
);
526 CMD(add_station
, NEW_STATION
);
527 CMD(add_mpath
, NEW_MPATH
);
528 CMD(set_mesh_params
, SET_MESH_PARAMS
);
529 CMD(change_bss
, SET_BSS
);
530 CMD(auth
, AUTHENTICATE
);
531 CMD(assoc
, ASSOCIATE
);
532 CMD(deauth
, DEAUTHENTICATE
);
533 CMD(disassoc
, DISASSOCIATE
);
534 CMD(join_ibss
, JOIN_IBSS
);
538 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
540 NLA_PUT_U32(msg
, i
, NL80211_CMD_CONNECT
);
543 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
545 NLA_PUT_U32(msg
, i
, NL80211_CMD_DISCONNECT
);
548 nla_nest_end(msg
, nl_cmds
);
550 return genlmsg_end(msg
, hdr
);
553 genlmsg_cancel(msg
, hdr
);
557 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
560 int start
= cb
->args
[0];
561 struct cfg80211_registered_device
*dev
;
563 mutex_lock(&cfg80211_mutex
);
564 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
567 if (nl80211_send_wiphy(skb
, NETLINK_CB(cb
->skb
).pid
,
568 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
574 mutex_unlock(&cfg80211_mutex
);
581 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
584 struct cfg80211_registered_device
*dev
;
586 dev
= cfg80211_get_dev_from_info(info
);
590 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
594 if (nl80211_send_wiphy(msg
, info
->snd_pid
, info
->snd_seq
, 0, dev
) < 0)
597 cfg80211_unlock_rdev(dev
);
599 return genlmsg_reply(msg
, info
);
604 cfg80211_unlock_rdev(dev
);
608 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
609 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
610 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
611 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
612 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
613 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
616 static int parse_txq_params(struct nlattr
*tb
[],
617 struct ieee80211_txq_params
*txq_params
)
619 if (!tb
[NL80211_TXQ_ATTR_QUEUE
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
620 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
621 !tb
[NL80211_TXQ_ATTR_AIFS
])
624 txq_params
->queue
= nla_get_u8(tb
[NL80211_TXQ_ATTR_QUEUE
]);
625 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
626 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
627 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
628 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
633 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
635 struct cfg80211_registered_device
*rdev
;
636 int result
= 0, rem_txq_params
= 0;
637 struct nlattr
*nl_txq_params
;
639 u8 retry_short
= 0, retry_long
= 0;
640 u32 frag_threshold
= 0, rts_threshold
= 0;
644 mutex_lock(&cfg80211_mutex
);
646 rdev
= __cfg80211_rdev_from_info(info
);
648 mutex_unlock(&cfg80211_mutex
);
649 result
= PTR_ERR(rdev
);
653 mutex_lock(&rdev
->mtx
);
655 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
656 result
= cfg80211_dev_rename(
657 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
659 mutex_unlock(&cfg80211_mutex
);
664 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
665 struct ieee80211_txq_params txq_params
;
666 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
668 if (!rdev
->ops
->set_txq_params
) {
669 result
= -EOPNOTSUPP
;
673 nla_for_each_nested(nl_txq_params
,
674 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
676 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
677 nla_data(nl_txq_params
),
678 nla_len(nl_txq_params
),
680 result
= parse_txq_params(tb
, &txq_params
);
684 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
691 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
692 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
693 struct ieee80211_channel
*chan
;
694 struct ieee80211_sta_ht_cap
*ht_cap
;
697 if (!rdev
->ops
->set_channel
) {
698 result
= -EOPNOTSUPP
;
704 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
705 channel_type
= nla_get_u32(info
->attrs
[
706 NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
707 if (channel_type
!= NL80211_CHAN_NO_HT
&&
708 channel_type
!= NL80211_CHAN_HT20
&&
709 channel_type
!= NL80211_CHAN_HT40PLUS
&&
710 channel_type
!= NL80211_CHAN_HT40MINUS
)
714 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
715 chan
= ieee80211_get_channel(&rdev
->wiphy
, freq
);
717 /* Primary channel not allowed */
718 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
)
721 if (channel_type
== NL80211_CHAN_HT40MINUS
&&
722 (chan
->flags
& IEEE80211_CHAN_NO_HT40MINUS
))
724 else if (channel_type
== NL80211_CHAN_HT40PLUS
&&
725 (chan
->flags
& IEEE80211_CHAN_NO_HT40PLUS
))
729 * At this point we know if that if HT40 was requested
730 * we are allowed to use it and the extension channel
734 ht_cap
= &rdev
->wiphy
.bands
[chan
->band
]->ht_cap
;
736 /* no HT capabilities or intolerant */
737 if (channel_type
!= NL80211_CHAN_NO_HT
) {
738 if (!ht_cap
->ht_supported
)
740 if (!(ht_cap
->cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
) ||
741 (ht_cap
->cap
& IEEE80211_HT_CAP_40MHZ_INTOLERANT
))
745 result
= rdev
->ops
->set_channel(&rdev
->wiphy
, chan
,
753 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
754 retry_short
= nla_get_u8(
755 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
756 if (retry_short
== 0) {
760 changed
|= WIPHY_PARAM_RETRY_SHORT
;
763 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
764 retry_long
= nla_get_u8(
765 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
766 if (retry_long
== 0) {
770 changed
|= WIPHY_PARAM_RETRY_LONG
;
773 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
774 frag_threshold
= nla_get_u32(
775 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
776 if (frag_threshold
< 256) {
780 if (frag_threshold
!= (u32
) -1) {
782 * Fragments (apart from the last one) are required to
783 * have even length. Make the fragmentation code
784 * simpler by stripping LSB should someone try to use
785 * odd threshold value.
787 frag_threshold
&= ~0x1;
789 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
792 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
793 rts_threshold
= nla_get_u32(
794 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
795 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
799 u8 old_retry_short
, old_retry_long
;
800 u32 old_frag_threshold
, old_rts_threshold
;
802 if (!rdev
->ops
->set_wiphy_params
) {
803 result
= -EOPNOTSUPP
;
807 old_retry_short
= rdev
->wiphy
.retry_short
;
808 old_retry_long
= rdev
->wiphy
.retry_long
;
809 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
810 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
812 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
813 rdev
->wiphy
.retry_short
= retry_short
;
814 if (changed
& WIPHY_PARAM_RETRY_LONG
)
815 rdev
->wiphy
.retry_long
= retry_long
;
816 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
817 rdev
->wiphy
.frag_threshold
= frag_threshold
;
818 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
819 rdev
->wiphy
.rts_threshold
= rts_threshold
;
821 result
= rdev
->ops
->set_wiphy_params(&rdev
->wiphy
, changed
);
823 rdev
->wiphy
.retry_short
= old_retry_short
;
824 rdev
->wiphy
.retry_long
= old_retry_long
;
825 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
826 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
831 mutex_unlock(&rdev
->mtx
);
838 static int nl80211_send_iface(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
839 struct cfg80211_registered_device
*rdev
,
840 struct net_device
*dev
)
844 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
848 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
849 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
850 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, dev
->name
);
851 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, dev
->ieee80211_ptr
->iftype
);
852 return genlmsg_end(msg
, hdr
);
855 genlmsg_cancel(msg
, hdr
);
859 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
863 int wp_start
= cb
->args
[0];
864 int if_start
= cb
->args
[1];
865 struct cfg80211_registered_device
*dev
;
866 struct wireless_dev
*wdev
;
868 mutex_lock(&cfg80211_mutex
);
869 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
870 if (wp_idx
< wp_start
) {
876 mutex_lock(&dev
->devlist_mtx
);
877 list_for_each_entry(wdev
, &dev
->netdev_list
, list
) {
878 if (if_idx
< if_start
) {
882 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).pid
,
883 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
884 dev
, wdev
->netdev
) < 0) {
885 mutex_unlock(&dev
->devlist_mtx
);
890 mutex_unlock(&dev
->devlist_mtx
);
895 mutex_unlock(&cfg80211_mutex
);
897 cb
->args
[0] = wp_idx
;
898 cb
->args
[1] = if_idx
;
903 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
906 struct cfg80211_registered_device
*dev
;
907 struct net_device
*netdev
;
910 err
= get_rdev_dev_by_info_ifindex(info
->attrs
, &dev
, &netdev
);
914 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
918 if (nl80211_send_iface(msg
, info
->snd_pid
, info
->snd_seq
, 0,
923 cfg80211_unlock_rdev(dev
);
925 return genlmsg_reply(msg
, info
);
931 cfg80211_unlock_rdev(dev
);
935 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
936 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
937 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
938 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
939 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
940 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
943 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
945 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
953 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
954 nla
, mntr_flags_policy
))
957 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
959 *mntrflags
|= (1<<flag
);
964 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
966 struct cfg80211_registered_device
*rdev
;
967 struct vif_params params
;
969 enum nl80211_iftype otype
, ntype
;
970 struct net_device
*dev
;
971 u32 _flags
, *flags
= NULL
;
974 memset(¶ms
, 0, sizeof(params
));
978 err
= get_rdev_dev_by_info_ifindex(info
->attrs
, &rdev
, &dev
);
982 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
984 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
985 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
988 if (ntype
> NL80211_IFTYPE_MAX
) {
994 if (!rdev
->ops
->change_virtual_intf
||
995 !(rdev
->wiphy
.interface_modes
& (1 << ntype
))) {
1000 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1001 if (ntype
!= NL80211_IFTYPE_MESH_POINT
) {
1005 params
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1006 params
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1010 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
1011 if (ntype
!= NL80211_IFTYPE_MONITOR
) {
1015 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
1025 err
= rdev
->ops
->change_virtual_intf(&rdev
->wiphy
, dev
,
1026 ntype
, flags
, ¶ms
);
1030 WARN_ON(!err
&& dev
->ieee80211_ptr
->iftype
!= ntype
);
1032 if (!err
&& (ntype
!= otype
)) {
1033 if (otype
== NL80211_IFTYPE_ADHOC
)
1034 cfg80211_clear_ibss(dev
, false);
1039 cfg80211_unlock_rdev(rdev
);
1045 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1047 struct cfg80211_registered_device
*rdev
;
1048 struct vif_params params
;
1050 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
1053 memset(¶ms
, 0, sizeof(params
));
1055 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
1058 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1059 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1060 if (type
> NL80211_IFTYPE_MAX
)
1066 rdev
= cfg80211_get_dev_from_info(info
);
1068 err
= PTR_ERR(rdev
);
1072 if (!rdev
->ops
->add_virtual_intf
||
1073 !(rdev
->wiphy
.interface_modes
& (1 << type
))) {
1078 if (type
== NL80211_IFTYPE_MESH_POINT
&&
1079 info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1080 params
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1081 params
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1084 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
1085 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
1087 err
= rdev
->ops
->add_virtual_intf(&rdev
->wiphy
,
1088 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
1089 type
, err
? NULL
: &flags
, ¶ms
);
1092 cfg80211_unlock_rdev(rdev
);
1098 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1100 struct cfg80211_registered_device
*rdev
;
1102 struct net_device
*dev
;
1106 err
= get_rdev_dev_by_info_ifindex(info
->attrs
, &rdev
, &dev
);
1109 ifindex
= dev
->ifindex
;
1112 if (!rdev
->ops
->del_virtual_intf
) {
1117 err
= rdev
->ops
->del_virtual_intf(&rdev
->wiphy
, ifindex
);
1120 cfg80211_unlock_rdev(rdev
);
1126 struct get_key_cookie
{
1127 struct sk_buff
*msg
;
1132 static void get_key_callback(void *c
, struct key_params
*params
)
1135 struct get_key_cookie
*cookie
= c
;
1138 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
1139 params
->key_len
, params
->key
);
1142 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
1143 params
->seq_len
, params
->seq
);
1146 NLA_PUT_U32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
1149 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
1151 goto nla_put_failure
;
1154 NLA_PUT(cookie
->msg
, NL80211_KEY_DATA
,
1155 params
->key_len
, params
->key
);
1158 NLA_PUT(cookie
->msg
, NL80211_KEY_SEQ
,
1159 params
->seq_len
, params
->seq
);
1162 NLA_PUT_U32(cookie
->msg
, NL80211_KEY_CIPHER
,
1165 NLA_PUT_U8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
);
1167 nla_nest_end(cookie
->msg
, key
);
1174 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
1176 struct cfg80211_registered_device
*rdev
;
1178 struct net_device
*dev
;
1180 u8
*mac_addr
= NULL
;
1181 struct get_key_cookie cookie
= {
1185 struct sk_buff
*msg
;
1187 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
1188 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1193 if (info
->attrs
[NL80211_ATTR_MAC
])
1194 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1198 err
= get_rdev_dev_by_info_ifindex(info
->attrs
, &rdev
, &dev
);
1202 if (!rdev
->ops
->get_key
) {
1207 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1213 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1214 NL80211_CMD_NEW_KEY
);
1222 cookie
.idx
= key_idx
;
1224 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1225 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
1227 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1229 err
= rdev
->ops
->get_key(&rdev
->wiphy
, dev
, key_idx
, mac_addr
,
1230 &cookie
, get_key_callback
);
1236 goto nla_put_failure
;
1238 genlmsg_end(msg
, hdr
);
1239 err
= genlmsg_reply(msg
, info
);
1247 cfg80211_unlock_rdev(rdev
);
1255 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
1257 struct cfg80211_registered_device
*rdev
;
1258 struct key_parse key
;
1260 struct net_device
*dev
;
1261 int (*func
)(struct wiphy
*wiphy
, struct net_device
*netdev
,
1264 err
= nl80211_parse_key(info
, &key
);
1271 /* only support setting default key */
1272 if (!key
.def
&& !key
.defmgmt
)
1277 err
= get_rdev_dev_by_info_ifindex(info
->attrs
, &rdev
, &dev
);
1282 func
= rdev
->ops
->set_default_key
;
1284 func
= rdev
->ops
->set_default_mgmt_key
;
1291 wdev_lock(dev
->ieee80211_ptr
);
1292 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1294 err
= func(&rdev
->wiphy
, dev
, key
.idx
);
1296 #ifdef CONFIG_WIRELESS_EXT
1298 if (func
== rdev
->ops
->set_default_key
)
1299 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
1301 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
1304 wdev_unlock(dev
->ieee80211_ptr
);
1307 cfg80211_unlock_rdev(rdev
);
1316 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
1318 struct cfg80211_registered_device
*rdev
;
1320 struct net_device
*dev
;
1321 struct key_parse key
;
1322 u8
*mac_addr
= NULL
;
1324 err
= nl80211_parse_key(info
, &key
);
1331 if (info
->attrs
[NL80211_ATTR_MAC
])
1332 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1336 err
= get_rdev_dev_by_info_ifindex(info
->attrs
, &rdev
, &dev
);
1340 if (!rdev
->ops
->add_key
) {
1345 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
, mac_addr
)) {
1350 wdev_lock(dev
->ieee80211_ptr
);
1351 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1353 err
= rdev
->ops
->add_key(&rdev
->wiphy
, dev
, key
.idx
,
1355 wdev_unlock(dev
->ieee80211_ptr
);
1358 cfg80211_unlock_rdev(rdev
);
1366 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
1368 struct cfg80211_registered_device
*rdev
;
1370 struct net_device
*dev
;
1371 u8
*mac_addr
= NULL
;
1372 struct key_parse key
;
1374 err
= nl80211_parse_key(info
, &key
);
1378 if (info
->attrs
[NL80211_ATTR_MAC
])
1379 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1383 err
= get_rdev_dev_by_info_ifindex(info
->attrs
, &rdev
, &dev
);
1387 if (!rdev
->ops
->del_key
) {
1392 wdev_lock(dev
->ieee80211_ptr
);
1393 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1395 err
= rdev
->ops
->del_key(&rdev
->wiphy
, dev
, key
.idx
, mac_addr
);
1397 #ifdef CONFIG_WIRELESS_EXT
1399 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
1400 dev
->ieee80211_ptr
->wext
.default_key
= -1;
1401 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
1402 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
1405 wdev_unlock(dev
->ieee80211_ptr
);
1408 cfg80211_unlock_rdev(rdev
);
1417 static int nl80211_addset_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1419 int (*call
)(struct wiphy
*wiphy
, struct net_device
*dev
,
1420 struct beacon_parameters
*info
);
1421 struct cfg80211_registered_device
*rdev
;
1423 struct net_device
*dev
;
1424 struct beacon_parameters params
;
1427 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]))
1432 err
= get_rdev_dev_by_info_ifindex(info
->attrs
, &rdev
, &dev
);
1436 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1441 switch (info
->genlhdr
->cmd
) {
1442 case NL80211_CMD_NEW_BEACON
:
1443 /* these are required for NEW_BEACON */
1444 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
1445 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
1446 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1451 call
= rdev
->ops
->add_beacon
;
1453 case NL80211_CMD_SET_BEACON
:
1454 call
= rdev
->ops
->set_beacon
;
1467 memset(¶ms
, 0, sizeof(params
));
1469 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
1471 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
1475 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
1476 params
.dtim_period
=
1477 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
1481 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1482 params
.head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1484 nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1488 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
1489 params
.tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1491 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1500 err
= call(&rdev
->wiphy
, dev
, ¶ms
);
1503 cfg80211_unlock_rdev(rdev
);
1511 static int nl80211_del_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1513 struct cfg80211_registered_device
*rdev
;
1515 struct net_device
*dev
;
1519 err
= get_rdev_dev_by_info_ifindex(info
->attrs
, &rdev
, &dev
);
1523 if (!rdev
->ops
->del_beacon
) {
1528 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1532 err
= rdev
->ops
->del_beacon(&rdev
->wiphy
, dev
);
1535 cfg80211_unlock_rdev(rdev
);
1543 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
1544 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
1545 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
1546 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
1547 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
1550 static int parse_station_flags(struct genl_info
*info
,
1551 struct station_parameters
*params
)
1553 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
1558 * Try parsing the new attribute first so userspace
1559 * can specify both for older kernels.
1561 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
1563 struct nl80211_sta_flag_update
*sta_flags
;
1565 sta_flags
= nla_data(nla
);
1566 params
->sta_flags_mask
= sta_flags
->mask
;
1567 params
->sta_flags_set
= sta_flags
->set
;
1568 if ((params
->sta_flags_mask
|
1569 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
1574 /* if present, parse the old attribute */
1576 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
1580 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
1581 nla
, sta_flags_policy
))
1584 params
->sta_flags_mask
= (1 << __NL80211_STA_FLAG_AFTER_LAST
) - 1;
1585 params
->sta_flags_mask
&= ~1;
1587 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++)
1589 params
->sta_flags_set
|= (1<<flag
);
1594 static u16
nl80211_calculate_bitrate(struct rate_info
*rate
)
1596 int modulation
, streams
, bitrate
;
1598 if (!(rate
->flags
& RATE_INFO_FLAGS_MCS
))
1599 return rate
->legacy
;
1601 /* the formula below does only work for MCS values smaller than 32 */
1602 if (rate
->mcs
>= 32)
1605 modulation
= rate
->mcs
& 7;
1606 streams
= (rate
->mcs
>> 3) + 1;
1608 bitrate
= (rate
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
) ?
1612 bitrate
*= (modulation
+ 1);
1613 else if (modulation
== 4)
1614 bitrate
*= (modulation
+ 2);
1616 bitrate
*= (modulation
+ 3);
1620 if (rate
->flags
& RATE_INFO_FLAGS_SHORT_GI
)
1621 bitrate
= (bitrate
/ 9) * 10;
1623 /* do NOT round down here */
1624 return (bitrate
+ 50000) / 100000;
1627 static int nl80211_send_station(struct sk_buff
*msg
, u32 pid
, u32 seq
,
1628 int flags
, struct net_device
*dev
,
1629 u8
*mac_addr
, struct station_info
*sinfo
)
1632 struct nlattr
*sinfoattr
, *txrate
;
1635 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
1639 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1640 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1642 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
1644 goto nla_put_failure
;
1645 if (sinfo
->filled
& STATION_INFO_INACTIVE_TIME
)
1646 NLA_PUT_U32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
1647 sinfo
->inactive_time
);
1648 if (sinfo
->filled
& STATION_INFO_RX_BYTES
)
1649 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_BYTES
,
1651 if (sinfo
->filled
& STATION_INFO_TX_BYTES
)
1652 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_BYTES
,
1654 if (sinfo
->filled
& STATION_INFO_LLID
)
1655 NLA_PUT_U16(msg
, NL80211_STA_INFO_LLID
,
1657 if (sinfo
->filled
& STATION_INFO_PLID
)
1658 NLA_PUT_U16(msg
, NL80211_STA_INFO_PLID
,
1660 if (sinfo
->filled
& STATION_INFO_PLINK_STATE
)
1661 NLA_PUT_U8(msg
, NL80211_STA_INFO_PLINK_STATE
,
1662 sinfo
->plink_state
);
1663 if (sinfo
->filled
& STATION_INFO_SIGNAL
)
1664 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL
,
1666 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
1667 txrate
= nla_nest_start(msg
, NL80211_STA_INFO_TX_BITRATE
);
1669 goto nla_put_failure
;
1671 /* nl80211_calculate_bitrate will return 0 for mcs >= 32 */
1672 bitrate
= nl80211_calculate_bitrate(&sinfo
->txrate
);
1674 NLA_PUT_U16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate
);
1676 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_MCS
)
1677 NLA_PUT_U8(msg
, NL80211_RATE_INFO_MCS
,
1679 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
)
1680 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
);
1681 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_SHORT_GI
)
1682 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_SHORT_GI
);
1684 nla_nest_end(msg
, txrate
);
1686 if (sinfo
->filled
& STATION_INFO_RX_PACKETS
)
1687 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_PACKETS
,
1689 if (sinfo
->filled
& STATION_INFO_TX_PACKETS
)
1690 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_PACKETS
,
1692 nla_nest_end(msg
, sinfoattr
);
1694 return genlmsg_end(msg
, hdr
);
1697 genlmsg_cancel(msg
, hdr
);
1701 static int nl80211_dump_station(struct sk_buff
*skb
,
1702 struct netlink_callback
*cb
)
1704 struct station_info sinfo
;
1705 struct cfg80211_registered_device
*dev
;
1706 struct net_device
*netdev
;
1707 u8 mac_addr
[ETH_ALEN
];
1708 int ifidx
= cb
->args
[0];
1709 int sta_idx
= cb
->args
[1];
1713 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
1714 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
1719 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
1722 ifidx
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
1729 netdev
= __dev_get_by_index(&init_net
, ifidx
);
1735 dev
= cfg80211_get_dev_from_ifindex(ifidx
);
1741 if (!dev
->ops
->dump_station
) {
1747 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
1754 if (nl80211_send_station(skb
,
1755 NETLINK_CB(cb
->skb
).pid
,
1756 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1766 cb
->args
[1] = sta_idx
;
1769 cfg80211_unlock_rdev(dev
);
1776 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
1778 struct cfg80211_registered_device
*rdev
;
1780 struct net_device
*dev
;
1781 struct station_info sinfo
;
1782 struct sk_buff
*msg
;
1783 u8
*mac_addr
= NULL
;
1785 memset(&sinfo
, 0, sizeof(sinfo
));
1787 if (!info
->attrs
[NL80211_ATTR_MAC
])
1790 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1794 err
= get_rdev_dev_by_info_ifindex(info
->attrs
, &rdev
, &dev
);
1798 if (!rdev
->ops
->get_station
) {
1803 err
= rdev
->ops
->get_station(&rdev
->wiphy
, dev
, mac_addr
, &sinfo
);
1807 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1811 if (nl80211_send_station(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1812 dev
, mac_addr
, &sinfo
) < 0)
1815 err
= genlmsg_reply(msg
, info
);
1821 cfg80211_unlock_rdev(rdev
);
1830 * Get vlan interface making sure it is on the right wiphy.
1832 static int get_vlan(struct nlattr
*vlanattr
,
1833 struct cfg80211_registered_device
*rdev
,
1834 struct net_device
**vlan
)
1839 *vlan
= dev_get_by_index(&init_net
, nla_get_u32(vlanattr
));
1842 if (!(*vlan
)->ieee80211_ptr
)
1844 if ((*vlan
)->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
)
1850 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
1852 struct cfg80211_registered_device
*rdev
;
1854 struct net_device
*dev
;
1855 struct station_parameters params
;
1856 u8
*mac_addr
= NULL
;
1858 memset(¶ms
, 0, sizeof(params
));
1860 params
.listen_interval
= -1;
1862 if (info
->attrs
[NL80211_ATTR_STA_AID
])
1865 if (!info
->attrs
[NL80211_ATTR_MAC
])
1868 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1870 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
1871 params
.supported_rates
=
1872 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1873 params
.supported_rates_len
=
1874 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1877 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
1878 params
.listen_interval
=
1879 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
1881 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
1883 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
1885 if (parse_station_flags(info
, ¶ms
))
1888 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
1889 params
.plink_action
=
1890 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
1894 err
= get_rdev_dev_by_info_ifindex(info
->attrs
, &rdev
, &dev
);
1898 err
= get_vlan(info
->attrs
[NL80211_ATTR_STA_VLAN
], rdev
, ¶ms
.vlan
);
1902 /* validate settings */
1905 switch (dev
->ieee80211_ptr
->iftype
) {
1906 case NL80211_IFTYPE_AP
:
1907 case NL80211_IFTYPE_AP_VLAN
:
1908 /* disallow mesh-specific things */
1909 if (params
.plink_action
)
1912 case NL80211_IFTYPE_STATION
:
1913 /* disallow everything but AUTHORIZED flag */
1914 if (params
.plink_action
)
1918 if (params
.supported_rates
)
1922 if (params
.listen_interval
>= 0)
1924 if (params
.sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
1927 case NL80211_IFTYPE_MESH_POINT
:
1928 /* disallow things mesh doesn't support */
1933 if (params
.listen_interval
>= 0)
1935 if (params
.supported_rates
)
1937 if (params
.sta_flags_mask
)
1947 if (!rdev
->ops
->change_station
) {
1952 err
= rdev
->ops
->change_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
1956 dev_put(params
.vlan
);
1957 cfg80211_unlock_rdev(rdev
);
1965 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
1967 struct cfg80211_registered_device
*rdev
;
1969 struct net_device
*dev
;
1970 struct station_parameters params
;
1971 u8
*mac_addr
= NULL
;
1973 memset(¶ms
, 0, sizeof(params
));
1975 if (!info
->attrs
[NL80211_ATTR_MAC
])
1978 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
1981 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
1984 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1985 params
.supported_rates
=
1986 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1987 params
.supported_rates_len
=
1988 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1989 params
.listen_interval
=
1990 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
1992 if (info
->attrs
[NL80211_ATTR_STA_AID
]) {
1993 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
1994 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
1998 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2000 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2002 if (parse_station_flags(info
, ¶ms
))
2007 err
= get_rdev_dev_by_info_ifindex(info
->attrs
, &rdev
, &dev
);
2011 err
= get_vlan(info
->attrs
[NL80211_ATTR_STA_VLAN
], rdev
, ¶ms
.vlan
);
2015 /* validate settings */
2018 switch (dev
->ieee80211_ptr
->iftype
) {
2019 case NL80211_IFTYPE_AP
:
2020 case NL80211_IFTYPE_AP_VLAN
:
2021 /* all ok but must have AID */
2025 case NL80211_IFTYPE_MESH_POINT
:
2026 /* disallow things mesh doesn't support */
2033 if (params
.listen_interval
>= 0)
2035 if (params
.supported_rates
)
2037 if (params
.sta_flags_mask
)
2047 if (!rdev
->ops
->add_station
) {
2052 if (!netif_running(dev
)) {
2057 err
= rdev
->ops
->add_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2061 dev_put(params
.vlan
);
2062 cfg80211_unlock_rdev(rdev
);
2070 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
2072 struct cfg80211_registered_device
*rdev
;
2074 struct net_device
*dev
;
2075 u8
*mac_addr
= NULL
;
2077 if (info
->attrs
[NL80211_ATTR_MAC
])
2078 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2082 err
= get_rdev_dev_by_info_ifindex(info
->attrs
, &rdev
, &dev
);
2086 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2087 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
2088 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2093 if (!rdev
->ops
->del_station
) {
2098 err
= rdev
->ops
->del_station(&rdev
->wiphy
, dev
, mac_addr
);
2101 cfg80211_unlock_rdev(rdev
);
2109 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2110 int flags
, struct net_device
*dev
,
2111 u8
*dst
, u8
*next_hop
,
2112 struct mpath_info
*pinfo
)
2115 struct nlattr
*pinfoattr
;
2117 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2121 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2122 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
2123 NLA_PUT(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
);
2125 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
2127 goto nla_put_failure
;
2128 if (pinfo
->filled
& MPATH_INFO_FRAME_QLEN
)
2129 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
2131 if (pinfo
->filled
& MPATH_INFO_DSN
)
2132 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DSN
,
2134 if (pinfo
->filled
& MPATH_INFO_METRIC
)
2135 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_METRIC
,
2137 if (pinfo
->filled
& MPATH_INFO_EXPTIME
)
2138 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_EXPTIME
,
2140 if (pinfo
->filled
& MPATH_INFO_FLAGS
)
2141 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_FLAGS
,
2143 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
)
2144 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
2145 pinfo
->discovery_timeout
);
2146 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
)
2147 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
2148 pinfo
->discovery_retries
);
2150 nla_nest_end(msg
, pinfoattr
);
2152 return genlmsg_end(msg
, hdr
);
2155 genlmsg_cancel(msg
, hdr
);
2159 static int nl80211_dump_mpath(struct sk_buff
*skb
,
2160 struct netlink_callback
*cb
)
2162 struct mpath_info pinfo
;
2163 struct cfg80211_registered_device
*dev
;
2164 struct net_device
*netdev
;
2166 u8 next_hop
[ETH_ALEN
];
2167 int ifidx
= cb
->args
[0];
2168 int path_idx
= cb
->args
[1];
2172 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
2173 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
2178 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
2181 ifidx
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
2188 netdev
= __dev_get_by_index(&init_net
, ifidx
);
2194 dev
= cfg80211_get_dev_from_ifindex(ifidx
);
2200 if (!dev
->ops
->dump_mpath
) {
2205 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2211 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
2212 dst
, next_hop
, &pinfo
);
2218 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).pid
,
2219 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2220 netdev
, dst
, next_hop
,
2229 cb
->args
[1] = path_idx
;
2232 cfg80211_unlock_rdev(dev
);
2239 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2241 struct cfg80211_registered_device
*rdev
;
2243 struct net_device
*dev
;
2244 struct mpath_info pinfo
;
2245 struct sk_buff
*msg
;
2247 u8 next_hop
[ETH_ALEN
];
2249 memset(&pinfo
, 0, sizeof(pinfo
));
2251 if (!info
->attrs
[NL80211_ATTR_MAC
])
2254 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2258 err
= get_rdev_dev_by_info_ifindex(info
->attrs
, &rdev
, &dev
);
2262 if (!rdev
->ops
->get_mpath
) {
2267 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2272 err
= rdev
->ops
->get_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
2276 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2280 if (nl80211_send_mpath(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2281 dev
, dst
, next_hop
, &pinfo
) < 0)
2284 err
= genlmsg_reply(msg
, info
);
2290 cfg80211_unlock_rdev(rdev
);
2298 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2300 struct cfg80211_registered_device
*rdev
;
2302 struct net_device
*dev
;
2304 u8
*next_hop
= NULL
;
2306 if (!info
->attrs
[NL80211_ATTR_MAC
])
2309 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2312 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2313 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2317 err
= get_rdev_dev_by_info_ifindex(info
->attrs
, &rdev
, &dev
);
2321 if (!rdev
->ops
->change_mpath
) {
2326 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2331 if (!netif_running(dev
)) {
2336 err
= rdev
->ops
->change_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2339 cfg80211_unlock_rdev(rdev
);
2346 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2348 struct cfg80211_registered_device
*rdev
;
2350 struct net_device
*dev
;
2352 u8
*next_hop
= NULL
;
2354 if (!info
->attrs
[NL80211_ATTR_MAC
])
2357 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2360 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2361 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2365 err
= get_rdev_dev_by_info_ifindex(info
->attrs
, &rdev
, &dev
);
2369 if (!rdev
->ops
->add_mpath
) {
2374 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2379 if (!netif_running(dev
)) {
2384 err
= rdev
->ops
->add_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2387 cfg80211_unlock_rdev(rdev
);
2395 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2397 struct cfg80211_registered_device
*rdev
;
2399 struct net_device
*dev
;
2402 if (info
->attrs
[NL80211_ATTR_MAC
])
2403 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2407 err
= get_rdev_dev_by_info_ifindex(info
->attrs
, &rdev
, &dev
);
2411 if (!rdev
->ops
->del_mpath
) {
2416 err
= rdev
->ops
->del_mpath(&rdev
->wiphy
, dev
, dst
);
2419 cfg80211_unlock_rdev(rdev
);
2427 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
2429 struct cfg80211_registered_device
*rdev
;
2431 struct net_device
*dev
;
2432 struct bss_parameters params
;
2434 memset(¶ms
, 0, sizeof(params
));
2435 /* default to not changing parameters */
2436 params
.use_cts_prot
= -1;
2437 params
.use_short_preamble
= -1;
2438 params
.use_short_slot_time
= -1;
2440 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
2441 params
.use_cts_prot
=
2442 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
2443 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
2444 params
.use_short_preamble
=
2445 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
2446 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
2447 params
.use_short_slot_time
=
2448 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
2449 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
2450 params
.basic_rates
=
2451 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2452 params
.basic_rates_len
=
2453 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2458 err
= get_rdev_dev_by_info_ifindex(info
->attrs
, &rdev
, &dev
);
2462 if (!rdev
->ops
->change_bss
) {
2467 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
2472 err
= rdev
->ops
->change_bss(&rdev
->wiphy
, dev
, ¶ms
);
2475 cfg80211_unlock_rdev(rdev
);
2483 static const struct nla_policy
2484 reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
2485 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
2486 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
2487 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
2488 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
2489 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
2490 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
2493 static int parse_reg_rule(struct nlattr
*tb
[],
2494 struct ieee80211_reg_rule
*reg_rule
)
2496 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
2497 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
2499 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
2501 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
2503 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
2505 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
2507 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
2510 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
2512 freq_range
->start_freq_khz
=
2513 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
2514 freq_range
->end_freq_khz
=
2515 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
2516 freq_range
->max_bandwidth_khz
=
2517 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
2519 power_rule
->max_eirp
=
2520 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
2522 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
2523 power_rule
->max_antenna_gain
=
2524 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
2529 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2535 * You should only get this when cfg80211 hasn't yet initialized
2536 * completely when built-in to the kernel right between the time
2537 * window between nl80211_init() and regulatory_init(), if that is
2540 mutex_lock(&cfg80211_mutex
);
2541 if (unlikely(!cfg80211_regdomain
)) {
2542 mutex_unlock(&cfg80211_mutex
);
2543 return -EINPROGRESS
;
2545 mutex_unlock(&cfg80211_mutex
);
2547 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2550 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2552 #ifdef CONFIG_WIRELESS_OLD_REGULATORY
2553 /* We ignore world regdom requests with the old regdom setup */
2554 if (is_world_regdom(data
))
2558 r
= regulatory_hint_user(data
);
2563 static int nl80211_get_mesh_params(struct sk_buff
*skb
,
2564 struct genl_info
*info
)
2566 struct cfg80211_registered_device
*rdev
;
2567 struct mesh_config cur_params
;
2569 struct net_device
*dev
;
2571 struct nlattr
*pinfoattr
;
2572 struct sk_buff
*msg
;
2576 /* Look up our device */
2577 err
= get_rdev_dev_by_info_ifindex(info
->attrs
, &rdev
, &dev
);
2581 if (!rdev
->ops
->get_mesh_params
) {
2586 /* Get the mesh params */
2587 err
= rdev
->ops
->get_mesh_params(&rdev
->wiphy
, dev
, &cur_params
);
2591 /* Draw up a netlink message to send back */
2592 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2597 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2598 NL80211_CMD_GET_MESH_PARAMS
);
2600 goto nla_put_failure
;
2601 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_PARAMS
);
2603 goto nla_put_failure
;
2604 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2605 NLA_PUT_U16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
2606 cur_params
.dot11MeshRetryTimeout
);
2607 NLA_PUT_U16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
2608 cur_params
.dot11MeshConfirmTimeout
);
2609 NLA_PUT_U16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
2610 cur_params
.dot11MeshHoldingTimeout
);
2611 NLA_PUT_U16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
2612 cur_params
.dot11MeshMaxPeerLinks
);
2613 NLA_PUT_U8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
2614 cur_params
.dot11MeshMaxRetries
);
2615 NLA_PUT_U8(msg
, NL80211_MESHCONF_TTL
,
2616 cur_params
.dot11MeshTTL
);
2617 NLA_PUT_U8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
2618 cur_params
.auto_open_plinks
);
2619 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2620 cur_params
.dot11MeshHWMPmaxPREQretries
);
2621 NLA_PUT_U32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
2622 cur_params
.path_refresh_time
);
2623 NLA_PUT_U16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2624 cur_params
.min_discovery_timeout
);
2625 NLA_PUT_U32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2626 cur_params
.dot11MeshHWMPactivePathTimeout
);
2627 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2628 cur_params
.dot11MeshHWMPpreqMinInterval
);
2629 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2630 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
);
2631 nla_nest_end(msg
, pinfoattr
);
2632 genlmsg_end(msg
, hdr
);
2633 err
= genlmsg_reply(msg
, info
);
2637 genlmsg_cancel(msg
, hdr
);
2641 cfg80211_unlock_rdev(rdev
);
2649 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2651 if (table[attr_num]) {\
2652 cfg.param = nla_fn(table[attr_num]); \
2653 mask |= (1 << (attr_num - 1)); \
2657 static struct nla_policy
2658 nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] __read_mostly
= {
2659 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
2660 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
2661 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
2662 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
2663 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
2664 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
2665 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
2667 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
2668 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
2669 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
2670 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
2671 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
2672 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
2675 static int nl80211_set_mesh_params(struct sk_buff
*skb
, struct genl_info
*info
)
2679 struct cfg80211_registered_device
*rdev
;
2680 struct net_device
*dev
;
2681 struct mesh_config cfg
;
2682 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
2683 struct nlattr
*parent_attr
;
2685 parent_attr
= info
->attrs
[NL80211_ATTR_MESH_PARAMS
];
2688 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
2689 parent_attr
, nl80211_meshconf_params_policy
))
2694 err
= get_rdev_dev_by_info_ifindex(info
->attrs
, &rdev
, &dev
);
2698 if (!rdev
->ops
->set_mesh_params
) {
2703 /* This makes sure that there aren't more than 32 mesh config
2704 * parameters (otherwise our bitfield scheme would not work.) */
2705 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
2707 /* Fill in the params struct */
2709 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
2710 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
, nla_get_u16
);
2711 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
2712 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
, nla_get_u16
);
2713 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
2714 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
, nla_get_u16
);
2715 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
2716 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
, nla_get_u16
);
2717 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
2718 mask
, NL80211_MESHCONF_MAX_RETRIES
, nla_get_u8
);
2719 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
2720 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
2721 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
2722 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
, nla_get_u8
);
2723 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
2724 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2726 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
2727 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
, nla_get_u32
);
2728 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
2729 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2731 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
2732 mask
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2734 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
2735 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2737 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
2738 dot11MeshHWMPnetDiameterTraversalTime
,
2739 mask
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2743 err
= rdev
->ops
->set_mesh_params(&rdev
->wiphy
, dev
, &cfg
, mask
);
2747 cfg80211_unlock_rdev(rdev
);
2755 #undef FILL_IN_MESH_PARAM_IF_SET
2757 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2759 struct sk_buff
*msg
;
2761 struct nlattr
*nl_reg_rules
;
2765 mutex_lock(&cfg80211_mutex
);
2767 if (!cfg80211_regdomain
)
2770 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2776 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2777 NL80211_CMD_GET_REG
);
2779 goto nla_put_failure
;
2781 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
,
2782 cfg80211_regdomain
->alpha2
);
2784 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
2786 goto nla_put_failure
;
2788 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
2789 struct nlattr
*nl_reg_rule
;
2790 const struct ieee80211_reg_rule
*reg_rule
;
2791 const struct ieee80211_freq_range
*freq_range
;
2792 const struct ieee80211_power_rule
*power_rule
;
2794 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
2795 freq_range
= ®_rule
->freq_range
;
2796 power_rule
= ®_rule
->power_rule
;
2798 nl_reg_rule
= nla_nest_start(msg
, i
);
2800 goto nla_put_failure
;
2802 NLA_PUT_U32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
2804 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
2805 freq_range
->start_freq_khz
);
2806 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
2807 freq_range
->end_freq_khz
);
2808 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
2809 freq_range
->max_bandwidth_khz
);
2810 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
2811 power_rule
->max_antenna_gain
);
2812 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
2813 power_rule
->max_eirp
);
2815 nla_nest_end(msg
, nl_reg_rule
);
2818 nla_nest_end(msg
, nl_reg_rules
);
2820 genlmsg_end(msg
, hdr
);
2821 err
= genlmsg_reply(msg
, info
);
2825 genlmsg_cancel(msg
, hdr
);
2828 mutex_unlock(&cfg80211_mutex
);
2832 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2834 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
2835 struct nlattr
*nl_reg_rule
;
2836 char *alpha2
= NULL
;
2837 int rem_reg_rules
= 0, r
= 0;
2838 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
2839 struct ieee80211_regdomain
*rd
= NULL
;
2841 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2844 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
2847 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2849 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
2852 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
2856 mutex_lock(&cfg80211_mutex
);
2858 if (!reg_is_valid_request(alpha2
)) {
2863 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
2864 (num_rules
* sizeof(struct ieee80211_reg_rule
));
2866 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
2872 rd
->n_reg_rules
= num_rules
;
2873 rd
->alpha2
[0] = alpha2
[0];
2874 rd
->alpha2
[1] = alpha2
[1];
2876 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
2878 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
2879 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
2881 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
2887 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
2893 BUG_ON(rule_idx
!= num_rules
);
2897 mutex_unlock(&cfg80211_mutex
);
2902 mutex_unlock(&cfg80211_mutex
);
2907 static int validate_scan_freqs(struct nlattr
*freqs
)
2909 struct nlattr
*attr1
, *attr2
;
2910 int n_channels
= 0, tmp1
, tmp2
;
2912 nla_for_each_nested(attr1
, freqs
, tmp1
) {
2915 * Some hardware has a limited channel list for
2916 * scanning, and it is pretty much nonsensical
2917 * to scan for a channel twice, so disallow that
2918 * and don't require drivers to check that the
2919 * channel list they get isn't longer than what
2920 * they can scan, as long as they can scan all
2921 * the channels they registered at once.
2923 nla_for_each_nested(attr2
, freqs
, tmp2
)
2924 if (attr1
!= attr2
&&
2925 nla_get_u32(attr1
) == nla_get_u32(attr2
))
2932 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
2934 struct cfg80211_registered_device
*rdev
;
2935 struct net_device
*dev
;
2936 struct cfg80211_scan_request
*request
;
2937 struct cfg80211_ssid
*ssid
;
2938 struct ieee80211_channel
*channel
;
2939 struct nlattr
*attr
;
2940 struct wiphy
*wiphy
;
2941 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
2942 enum ieee80211_band band
;
2945 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
2950 err
= get_rdev_dev_by_info_ifindex(info
->attrs
, &rdev
, &dev
);
2954 wiphy
= &rdev
->wiphy
;
2956 if (!rdev
->ops
->scan
) {
2961 if (!netif_running(dev
)) {
2966 if (rdev
->scan_req
) {
2971 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
2972 n_channels
= validate_scan_freqs(
2973 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
2981 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
2982 if (wiphy
->bands
[band
])
2983 n_channels
+= wiphy
->bands
[band
]->n_channels
;
2986 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
2987 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
2990 if (n_ssids
> wiphy
->max_scan_ssids
) {
2995 if (info
->attrs
[NL80211_ATTR_IE
])
2996 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3000 if (ie_len
> wiphy
->max_scan_ie_len
) {
3005 request
= kzalloc(sizeof(*request
)
3006 + sizeof(*ssid
) * n_ssids
3007 + sizeof(channel
) * n_channels
3008 + ie_len
, GFP_KERNEL
);
3014 request
->channels
= (void *)((char *)request
+ sizeof(*request
));
3015 request
->n_channels
= n_channels
;
3017 request
->ssids
= (void *)(request
->channels
+ n_channels
);
3018 request
->n_ssids
= n_ssids
;
3021 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
3023 request
->ie
= (void *)(request
->channels
+ n_channels
);
3026 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3027 /* user specified, bail out if channel not found */
3028 request
->n_channels
= n_channels
;
3030 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
3031 request
->channels
[i
] = ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
3032 if (!request
->channels
[i
]) {
3041 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
3043 if (!wiphy
->bands
[band
])
3045 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
3046 request
->channels
[i
] = &wiphy
->bands
[band
]->channels
[j
];
3053 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
3054 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
3055 if (request
->ssids
[i
].ssid_len
> IEEE80211_MAX_SSID_LEN
) {
3059 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
3060 request
->ssids
[i
].ssid_len
= nla_len(attr
);
3065 if (info
->attrs
[NL80211_ATTR_IE
]) {
3066 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3067 memcpy((void *)request
->ie
,
3068 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
3072 request
->ifidx
= dev
->ifindex
;
3073 request
->wiphy
= &rdev
->wiphy
;
3075 rdev
->scan_req
= request
;
3076 err
= rdev
->ops
->scan(&rdev
->wiphy
, dev
, request
);
3079 nl80211_send_scan_start(rdev
, dev
);
3083 rdev
->scan_req
= NULL
;
3087 cfg80211_unlock_rdev(rdev
);
3095 static int nl80211_send_bss(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
3096 struct cfg80211_registered_device
*rdev
,
3097 struct net_device
*dev
,
3098 struct cfg80211_bss
*res
)
3103 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3104 NL80211_CMD_NEW_SCAN_RESULTS
);
3108 NLA_PUT_U32(msg
, NL80211_ATTR_SCAN_GENERATION
,
3109 rdev
->bss_generation
);
3110 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
3112 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
3114 goto nla_put_failure
;
3115 if (!is_zero_ether_addr(res
->bssid
))
3116 NLA_PUT(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
);
3117 if (res
->information_elements
&& res
->len_information_elements
)
3118 NLA_PUT(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
3119 res
->len_information_elements
,
3120 res
->information_elements
);
3122 NLA_PUT_U64(msg
, NL80211_BSS_TSF
, res
->tsf
);
3123 if (res
->beacon_interval
)
3124 NLA_PUT_U16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
);
3125 NLA_PUT_U16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
);
3126 NLA_PUT_U32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
);
3128 switch (rdev
->wiphy
.signal_type
) {
3129 case CFG80211_SIGNAL_TYPE_MBM
:
3130 NLA_PUT_U32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
);
3132 case CFG80211_SIGNAL_TYPE_UNSPEC
:
3133 NLA_PUT_U8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
);
3139 nla_nest_end(msg
, bss
);
3141 return genlmsg_end(msg
, hdr
);
3144 genlmsg_cancel(msg
, hdr
);
3148 static int nl80211_dump_scan(struct sk_buff
*skb
,
3149 struct netlink_callback
*cb
)
3151 struct cfg80211_registered_device
*dev
;
3152 struct net_device
*netdev
;
3153 struct cfg80211_internal_bss
*scan
;
3154 int ifidx
= cb
->args
[0];
3155 int start
= cb
->args
[1], idx
= 0;
3159 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
3160 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
3165 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
3168 ifidx
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
3171 cb
->args
[0] = ifidx
;
3174 netdev
= dev_get_by_index(&init_net
, ifidx
);
3178 dev
= cfg80211_get_dev_from_ifindex(ifidx
);
3181 goto out_put_netdev
;
3184 spin_lock_bh(&dev
->bss_lock
);
3185 cfg80211_bss_expire(dev
);
3187 list_for_each_entry(scan
, &dev
->bss_list
, list
) {
3190 if (nl80211_send_bss(skb
,
3191 NETLINK_CB(cb
->skb
).pid
,
3192 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3193 dev
, netdev
, &scan
->pub
) < 0) {
3200 spin_unlock_bh(&dev
->bss_lock
);
3204 cfg80211_unlock_rdev(dev
);
3211 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
)
3213 return auth_type
<= NL80211_AUTHTYPE_MAX
;
3216 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
3218 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
3219 NL80211_WPA_VERSION_2
));
3222 static bool nl80211_valid_akm_suite(u32 akm
)
3224 return akm
== WLAN_AKM_SUITE_8021X
||
3225 akm
== WLAN_AKM_SUITE_PSK
;
3228 static bool nl80211_valid_cipher_suite(u32 cipher
)
3230 return cipher
== WLAN_CIPHER_SUITE_WEP40
||
3231 cipher
== WLAN_CIPHER_SUITE_WEP104
||
3232 cipher
== WLAN_CIPHER_SUITE_TKIP
||
3233 cipher
== WLAN_CIPHER_SUITE_CCMP
||
3234 cipher
== WLAN_CIPHER_SUITE_AES_CMAC
;
3238 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3240 struct cfg80211_registered_device
*rdev
;
3241 struct net_device
*dev
;
3242 struct ieee80211_channel
*chan
;
3243 const u8
*bssid
, *ssid
, *ie
= NULL
;
3244 int err
, ssid_len
, ie_len
= 0;
3245 enum nl80211_auth_type auth_type
;
3246 struct key_parse key
;
3248 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3251 if (!info
->attrs
[NL80211_ATTR_MAC
])
3254 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
3257 if (!info
->attrs
[NL80211_ATTR_SSID
])
3260 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
3263 err
= nl80211_parse_key(info
, &key
);
3268 if (!key
.p
.key
|| !key
.p
.key_len
)
3270 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
3271 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
3272 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
3273 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
3284 err
= get_rdev_dev_by_info_ifindex(info
->attrs
, &rdev
, &dev
);
3288 if (!rdev
->ops
->auth
) {
3293 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3298 if (!netif_running(dev
)) {
3303 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3304 chan
= ieee80211_get_channel(&rdev
->wiphy
,
3305 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3306 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
)) {
3311 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3312 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3314 if (info
->attrs
[NL80211_ATTR_IE
]) {
3315 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3316 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3319 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3320 if (!nl80211_valid_auth_type(auth_type
)) {
3325 err
= cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
3326 ssid
, ssid_len
, ie
, ie_len
,
3327 key
.p
.key
, key
.p
.key_len
, key
.idx
);
3330 cfg80211_unlock_rdev(rdev
);
3337 static int nl80211_crypto_settings(struct genl_info
*info
,
3338 struct cfg80211_crypto_settings
*settings
,
3341 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
3343 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
3347 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
3348 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
3349 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
3351 if (len
% sizeof(u32
))
3354 if (settings
->n_ciphers_pairwise
> cipher_limit
)
3357 memcpy(settings
->ciphers_pairwise
, data
, len
);
3359 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
3360 if (!nl80211_valid_cipher_suite(
3361 settings
->ciphers_pairwise
[i
]))
3365 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
3366 settings
->cipher_group
=
3367 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
3368 if (!nl80211_valid_cipher_suite(settings
->cipher_group
))
3372 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
3373 settings
->wpa_versions
=
3374 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
3375 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
3379 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
3383 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
3384 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
3385 settings
->n_akm_suites
= len
/ sizeof(u32
);
3387 if (len
% sizeof(u32
))
3390 memcpy(settings
->akm_suites
, data
, len
);
3392 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
3393 if (!nl80211_valid_akm_suite(settings
->akm_suites
[i
]))
3400 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
3402 struct cfg80211_registered_device
*rdev
;
3403 struct net_device
*dev
;
3404 struct cfg80211_crypto_settings crypto
;
3405 struct ieee80211_channel
*chan
;
3406 const u8
*bssid
, *ssid
, *ie
= NULL
, *prev_bssid
= NULL
;
3407 int err
, ssid_len
, ie_len
= 0;
3408 bool use_mfp
= false;
3410 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3413 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
3414 !info
->attrs
[NL80211_ATTR_SSID
] ||
3415 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
3420 err
= get_rdev_dev_by_info_ifindex(info
->attrs
, &rdev
, &dev
);
3424 if (!rdev
->ops
->assoc
) {
3429 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3434 if (!netif_running(dev
)) {
3439 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3441 chan
= ieee80211_get_channel(&rdev
->wiphy
,
3442 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3443 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
)) {
3448 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3449 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3451 if (info
->attrs
[NL80211_ATTR_IE
]) {
3452 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3453 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3456 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
3457 enum nl80211_mfp mfp
=
3458 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
3459 if (mfp
== NL80211_MFP_REQUIRED
)
3461 else if (mfp
!= NL80211_MFP_NO
) {
3467 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
3468 prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
3470 err
= nl80211_crypto_settings(info
, &crypto
, 1);
3472 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
, prev_bssid
,
3473 ssid
, ssid_len
, ie
, ie_len
, use_mfp
,
3477 cfg80211_unlock_rdev(rdev
);
3484 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3486 struct cfg80211_registered_device
*rdev
;
3487 struct net_device
*dev
;
3488 const u8
*ie
= NULL
, *bssid
;
3489 int err
, ie_len
= 0;
3492 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3495 if (!info
->attrs
[NL80211_ATTR_MAC
])
3498 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3503 err
= get_rdev_dev_by_info_ifindex(info
->attrs
, &rdev
, &dev
);
3507 if (!rdev
->ops
->deauth
) {
3512 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3517 if (!netif_running(dev
)) {
3522 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3524 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3525 if (reason_code
== 0) {
3526 /* Reason Code 0 is reserved */
3531 if (info
->attrs
[NL80211_ATTR_IE
]) {
3532 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3533 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3536 err
= cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
);
3539 cfg80211_unlock_rdev(rdev
);
3546 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
3548 struct cfg80211_registered_device
*rdev
;
3549 struct net_device
*dev
;
3550 const u8
*ie
= NULL
, *bssid
;
3551 int err
, ie_len
= 0;
3554 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3557 if (!info
->attrs
[NL80211_ATTR_MAC
])
3560 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3565 err
= get_rdev_dev_by_info_ifindex(info
->attrs
, &rdev
, &dev
);
3569 if (!rdev
->ops
->disassoc
) {
3574 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3579 if (!netif_running(dev
)) {
3584 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3586 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3587 if (reason_code
== 0) {
3588 /* Reason Code 0 is reserved */
3593 if (info
->attrs
[NL80211_ATTR_IE
]) {
3594 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3595 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3598 err
= cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
);
3601 cfg80211_unlock_rdev(rdev
);
3608 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
3610 struct cfg80211_registered_device
*rdev
;
3611 struct net_device
*dev
;
3612 struct cfg80211_ibss_params ibss
;
3613 struct wiphy
*wiphy
;
3614 struct cfg80211_cached_keys
*connkeys
= NULL
;
3617 memset(&ibss
, 0, sizeof(ibss
));
3619 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3622 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
3623 !info
->attrs
[NL80211_ATTR_SSID
] ||
3624 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
3627 ibss
.beacon_interval
= 100;
3629 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
3630 ibss
.beacon_interval
=
3631 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3632 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
3638 err
= get_rdev_dev_by_info_ifindex(info
->attrs
, &rdev
, &dev
);
3642 if (!rdev
->ops
->join_ibss
) {
3647 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
3652 if (!netif_running(dev
)) {
3657 wiphy
= &rdev
->wiphy
;
3659 if (info
->attrs
[NL80211_ATTR_MAC
])
3660 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3661 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3662 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3664 if (info
->attrs
[NL80211_ATTR_IE
]) {
3665 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3666 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3669 ibss
.channel
= ieee80211_get_channel(wiphy
,
3670 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3671 if (!ibss
.channel
||
3672 ibss
.channel
->flags
& IEEE80211_CHAN_NO_IBSS
||
3673 ibss
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
3678 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
3679 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3681 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
3682 connkeys
= nl80211_parse_connkeys(rdev
,
3683 info
->attrs
[NL80211_ATTR_KEYS
]);
3684 if (IS_ERR(connkeys
)) {
3685 err
= PTR_ERR(connkeys
);
3691 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
3694 cfg80211_unlock_rdev(rdev
);
3703 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
3705 struct cfg80211_registered_device
*rdev
;
3706 struct net_device
*dev
;
3711 err
= get_rdev_dev_by_info_ifindex(info
->attrs
, &rdev
, &dev
);
3715 if (!rdev
->ops
->leave_ibss
) {
3720 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
3725 if (!netif_running(dev
)) {
3730 err
= cfg80211_leave_ibss(rdev
, dev
, false);
3733 cfg80211_unlock_rdev(rdev
);
3740 #ifdef CONFIG_NL80211_TESTMODE
3741 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
3745 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
3747 struct cfg80211_registered_device
*rdev
;
3750 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
3755 rdev
= cfg80211_get_dev_from_info(info
);
3757 err
= PTR_ERR(rdev
);
3762 if (rdev
->ops
->testmode_cmd
) {
3763 rdev
->testmode_info
= info
;
3764 err
= rdev
->ops
->testmode_cmd(&rdev
->wiphy
,
3765 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
3766 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
3767 rdev
->testmode_info
= NULL
;
3770 cfg80211_unlock_rdev(rdev
);
3777 static struct sk_buff
*
3778 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
3779 int approxlen
, u32 pid
, u32 seq
, gfp_t gfp
)
3781 struct sk_buff
*skb
;
3783 struct nlattr
*data
;
3785 skb
= nlmsg_new(approxlen
+ 100, gfp
);
3789 hdr
= nl80211hdr_put(skb
, pid
, seq
, 0, NL80211_CMD_TESTMODE
);
3795 NLA_PUT_U32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
3796 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
3798 ((void **)skb
->cb
)[0] = rdev
;
3799 ((void **)skb
->cb
)[1] = hdr
;
3800 ((void **)skb
->cb
)[2] = data
;
3809 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
3812 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
3814 if (WARN_ON(!rdev
->testmode_info
))
3817 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
3818 rdev
->testmode_info
->snd_pid
,
3819 rdev
->testmode_info
->snd_seq
,
3822 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
3824 int cfg80211_testmode_reply(struct sk_buff
*skb
)
3826 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
3827 void *hdr
= ((void **)skb
->cb
)[1];
3828 struct nlattr
*data
= ((void **)skb
->cb
)[2];
3830 if (WARN_ON(!rdev
->testmode_info
)) {
3835 nla_nest_end(skb
, data
);
3836 genlmsg_end(skb
, hdr
);
3837 return genlmsg_reply(skb
, rdev
->testmode_info
);
3839 EXPORT_SYMBOL(cfg80211_testmode_reply
);
3841 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
3842 int approxlen
, gfp_t gfp
)
3844 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
3846 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
3848 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
3850 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
3852 void *hdr
= ((void **)skb
->cb
)[1];
3853 struct nlattr
*data
= ((void **)skb
->cb
)[2];
3855 nla_nest_end(skb
, data
);
3856 genlmsg_end(skb
, hdr
);
3857 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
3859 EXPORT_SYMBOL(cfg80211_testmode_event
);
3862 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
3864 struct cfg80211_registered_device
*rdev
;
3865 struct net_device
*dev
;
3866 struct cfg80211_connect_params connect
;
3867 struct wiphy
*wiphy
;
3868 struct cfg80211_cached_keys
*connkeys
= NULL
;
3871 memset(&connect
, 0, sizeof(connect
));
3873 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3876 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
3877 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
3880 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
3882 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3883 if (!nl80211_valid_auth_type(connect
.auth_type
))
3886 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
3888 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
3890 err
= nl80211_crypto_settings(info
, &connect
.crypto
,
3891 NL80211_MAX_NR_CIPHER_SUITES
);
3896 err
= get_rdev_dev_by_info_ifindex(info
->attrs
, &rdev
, &dev
);
3900 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3905 if (!netif_running(dev
)) {
3910 wiphy
= &rdev
->wiphy
;
3912 if (info
->attrs
[NL80211_ATTR_MAC
])
3913 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3914 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3915 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3917 if (info
->attrs
[NL80211_ATTR_IE
]) {
3918 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3919 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3922 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
3924 ieee80211_get_channel(wiphy
,
3925 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3926 if (!connect
.channel
||
3927 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
3933 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
3934 connkeys
= nl80211_parse_connkeys(rdev
,
3935 info
->attrs
[NL80211_ATTR_KEYS
]);
3936 if (IS_ERR(connkeys
)) {
3937 err
= PTR_ERR(connkeys
);
3943 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
3946 cfg80211_unlock_rdev(rdev
);
3955 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
3957 struct cfg80211_registered_device
*rdev
;
3958 struct net_device
*dev
;
3962 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3963 reason
= WLAN_REASON_DEAUTH_LEAVING
;
3965 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3972 err
= get_rdev_dev_by_info_ifindex(info
->attrs
, &rdev
, &dev
);
3976 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3981 if (!netif_running(dev
)) {
3986 err
= cfg80211_disconnect(rdev
, dev
, reason
, true);
3989 cfg80211_unlock_rdev(rdev
);
3996 static struct genl_ops nl80211_ops
[] = {
3998 .cmd
= NL80211_CMD_GET_WIPHY
,
3999 .doit
= nl80211_get_wiphy
,
4000 .dumpit
= nl80211_dump_wiphy
,
4001 .policy
= nl80211_policy
,
4002 /* can be retrieved by unprivileged users */
4005 .cmd
= NL80211_CMD_SET_WIPHY
,
4006 .doit
= nl80211_set_wiphy
,
4007 .policy
= nl80211_policy
,
4008 .flags
= GENL_ADMIN_PERM
,
4011 .cmd
= NL80211_CMD_GET_INTERFACE
,
4012 .doit
= nl80211_get_interface
,
4013 .dumpit
= nl80211_dump_interface
,
4014 .policy
= nl80211_policy
,
4015 /* can be retrieved by unprivileged users */
4018 .cmd
= NL80211_CMD_SET_INTERFACE
,
4019 .doit
= nl80211_set_interface
,
4020 .policy
= nl80211_policy
,
4021 .flags
= GENL_ADMIN_PERM
,
4024 .cmd
= NL80211_CMD_NEW_INTERFACE
,
4025 .doit
= nl80211_new_interface
,
4026 .policy
= nl80211_policy
,
4027 .flags
= GENL_ADMIN_PERM
,
4030 .cmd
= NL80211_CMD_DEL_INTERFACE
,
4031 .doit
= nl80211_del_interface
,
4032 .policy
= nl80211_policy
,
4033 .flags
= GENL_ADMIN_PERM
,
4036 .cmd
= NL80211_CMD_GET_KEY
,
4037 .doit
= nl80211_get_key
,
4038 .policy
= nl80211_policy
,
4039 .flags
= GENL_ADMIN_PERM
,
4042 .cmd
= NL80211_CMD_SET_KEY
,
4043 .doit
= nl80211_set_key
,
4044 .policy
= nl80211_policy
,
4045 .flags
= GENL_ADMIN_PERM
,
4048 .cmd
= NL80211_CMD_NEW_KEY
,
4049 .doit
= nl80211_new_key
,
4050 .policy
= nl80211_policy
,
4051 .flags
= GENL_ADMIN_PERM
,
4054 .cmd
= NL80211_CMD_DEL_KEY
,
4055 .doit
= nl80211_del_key
,
4056 .policy
= nl80211_policy
,
4057 .flags
= GENL_ADMIN_PERM
,
4060 .cmd
= NL80211_CMD_SET_BEACON
,
4061 .policy
= nl80211_policy
,
4062 .flags
= GENL_ADMIN_PERM
,
4063 .doit
= nl80211_addset_beacon
,
4066 .cmd
= NL80211_CMD_NEW_BEACON
,
4067 .policy
= nl80211_policy
,
4068 .flags
= GENL_ADMIN_PERM
,
4069 .doit
= nl80211_addset_beacon
,
4072 .cmd
= NL80211_CMD_DEL_BEACON
,
4073 .policy
= nl80211_policy
,
4074 .flags
= GENL_ADMIN_PERM
,
4075 .doit
= nl80211_del_beacon
,
4078 .cmd
= NL80211_CMD_GET_STATION
,
4079 .doit
= nl80211_get_station
,
4080 .dumpit
= nl80211_dump_station
,
4081 .policy
= nl80211_policy
,
4084 .cmd
= NL80211_CMD_SET_STATION
,
4085 .doit
= nl80211_set_station
,
4086 .policy
= nl80211_policy
,
4087 .flags
= GENL_ADMIN_PERM
,
4090 .cmd
= NL80211_CMD_NEW_STATION
,
4091 .doit
= nl80211_new_station
,
4092 .policy
= nl80211_policy
,
4093 .flags
= GENL_ADMIN_PERM
,
4096 .cmd
= NL80211_CMD_DEL_STATION
,
4097 .doit
= nl80211_del_station
,
4098 .policy
= nl80211_policy
,
4099 .flags
= GENL_ADMIN_PERM
,
4102 .cmd
= NL80211_CMD_GET_MPATH
,
4103 .doit
= nl80211_get_mpath
,
4104 .dumpit
= nl80211_dump_mpath
,
4105 .policy
= nl80211_policy
,
4106 .flags
= GENL_ADMIN_PERM
,
4109 .cmd
= NL80211_CMD_SET_MPATH
,
4110 .doit
= nl80211_set_mpath
,
4111 .policy
= nl80211_policy
,
4112 .flags
= GENL_ADMIN_PERM
,
4115 .cmd
= NL80211_CMD_NEW_MPATH
,
4116 .doit
= nl80211_new_mpath
,
4117 .policy
= nl80211_policy
,
4118 .flags
= GENL_ADMIN_PERM
,
4121 .cmd
= NL80211_CMD_DEL_MPATH
,
4122 .doit
= nl80211_del_mpath
,
4123 .policy
= nl80211_policy
,
4124 .flags
= GENL_ADMIN_PERM
,
4127 .cmd
= NL80211_CMD_SET_BSS
,
4128 .doit
= nl80211_set_bss
,
4129 .policy
= nl80211_policy
,
4130 .flags
= GENL_ADMIN_PERM
,
4133 .cmd
= NL80211_CMD_GET_REG
,
4134 .doit
= nl80211_get_reg
,
4135 .policy
= nl80211_policy
,
4136 /* can be retrieved by unprivileged users */
4139 .cmd
= NL80211_CMD_SET_REG
,
4140 .doit
= nl80211_set_reg
,
4141 .policy
= nl80211_policy
,
4142 .flags
= GENL_ADMIN_PERM
,
4145 .cmd
= NL80211_CMD_REQ_SET_REG
,
4146 .doit
= nl80211_req_set_reg
,
4147 .policy
= nl80211_policy
,
4148 .flags
= GENL_ADMIN_PERM
,
4151 .cmd
= NL80211_CMD_GET_MESH_PARAMS
,
4152 .doit
= nl80211_get_mesh_params
,
4153 .policy
= nl80211_policy
,
4154 /* can be retrieved by unprivileged users */
4157 .cmd
= NL80211_CMD_SET_MESH_PARAMS
,
4158 .doit
= nl80211_set_mesh_params
,
4159 .policy
= nl80211_policy
,
4160 .flags
= GENL_ADMIN_PERM
,
4163 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
4164 .doit
= nl80211_trigger_scan
,
4165 .policy
= nl80211_policy
,
4166 .flags
= GENL_ADMIN_PERM
,
4169 .cmd
= NL80211_CMD_GET_SCAN
,
4170 .policy
= nl80211_policy
,
4171 .dumpit
= nl80211_dump_scan
,
4174 .cmd
= NL80211_CMD_AUTHENTICATE
,
4175 .doit
= nl80211_authenticate
,
4176 .policy
= nl80211_policy
,
4177 .flags
= GENL_ADMIN_PERM
,
4180 .cmd
= NL80211_CMD_ASSOCIATE
,
4181 .doit
= nl80211_associate
,
4182 .policy
= nl80211_policy
,
4183 .flags
= GENL_ADMIN_PERM
,
4186 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
4187 .doit
= nl80211_deauthenticate
,
4188 .policy
= nl80211_policy
,
4189 .flags
= GENL_ADMIN_PERM
,
4192 .cmd
= NL80211_CMD_DISASSOCIATE
,
4193 .doit
= nl80211_disassociate
,
4194 .policy
= nl80211_policy
,
4195 .flags
= GENL_ADMIN_PERM
,
4198 .cmd
= NL80211_CMD_JOIN_IBSS
,
4199 .doit
= nl80211_join_ibss
,
4200 .policy
= nl80211_policy
,
4201 .flags
= GENL_ADMIN_PERM
,
4204 .cmd
= NL80211_CMD_LEAVE_IBSS
,
4205 .doit
= nl80211_leave_ibss
,
4206 .policy
= nl80211_policy
,
4207 .flags
= GENL_ADMIN_PERM
,
4209 #ifdef CONFIG_NL80211_TESTMODE
4211 .cmd
= NL80211_CMD_TESTMODE
,
4212 .doit
= nl80211_testmode_do
,
4213 .policy
= nl80211_policy
,
4214 .flags
= GENL_ADMIN_PERM
,
4218 .cmd
= NL80211_CMD_CONNECT
,
4219 .doit
= nl80211_connect
,
4220 .policy
= nl80211_policy
,
4221 .flags
= GENL_ADMIN_PERM
,
4224 .cmd
= NL80211_CMD_DISCONNECT
,
4225 .doit
= nl80211_disconnect
,
4226 .policy
= nl80211_policy
,
4227 .flags
= GENL_ADMIN_PERM
,
4230 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
4234 /* multicast groups */
4235 static struct genl_multicast_group nl80211_config_mcgrp
= {
4238 static struct genl_multicast_group nl80211_scan_mcgrp
= {
4241 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
4242 .name
= "regulatory",
4245 /* notification functions */
4247 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
4249 struct sk_buff
*msg
;
4251 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4255 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
4260 genlmsg_multicast(msg
, 0, nl80211_config_mcgrp
.id
, GFP_KERNEL
);
4263 static int nl80211_add_scan_req(struct sk_buff
*msg
,
4264 struct cfg80211_registered_device
*rdev
)
4266 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
4267 struct nlattr
*nest
;
4270 ASSERT_RDEV_LOCK(rdev
);
4275 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
4277 goto nla_put_failure
;
4278 for (i
= 0; i
< req
->n_ssids
; i
++)
4279 NLA_PUT(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
);
4280 nla_nest_end(msg
, nest
);
4282 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
4284 goto nla_put_failure
;
4285 for (i
= 0; i
< req
->n_channels
; i
++)
4286 NLA_PUT_U32(msg
, i
, req
->channels
[i
]->center_freq
);
4287 nla_nest_end(msg
, nest
);
4290 NLA_PUT(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
);
4297 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
4298 struct cfg80211_registered_device
*rdev
,
4299 struct net_device
*netdev
,
4300 u32 pid
, u32 seq
, int flags
,
4305 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
4309 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4310 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
4312 /* ignore errors and send incomplete event anyway */
4313 nl80211_add_scan_req(msg
, rdev
);
4315 return genlmsg_end(msg
, hdr
);
4318 genlmsg_cancel(msg
, hdr
);
4322 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
4323 struct net_device
*netdev
)
4325 struct sk_buff
*msg
;
4327 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
4331 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
4332 NL80211_CMD_TRIGGER_SCAN
) < 0) {
4337 genlmsg_multicast(msg
, 0, nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
4340 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
4341 struct net_device
*netdev
)
4343 struct sk_buff
*msg
;
4345 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4349 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
4350 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
4355 genlmsg_multicast(msg
, 0, nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
4358 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
4359 struct net_device
*netdev
)
4361 struct sk_buff
*msg
;
4363 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4367 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
4368 NL80211_CMD_SCAN_ABORTED
) < 0) {
4373 genlmsg_multicast(msg
, 0, nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
4377 * This can happen on global regulatory changes or device specific settings
4378 * based on custom world regulatory domains.
4380 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
4382 struct sk_buff
*msg
;
4385 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4389 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
4395 /* Userspace can always count this one always being set */
4396 NLA_PUT_U8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
);
4398 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0')
4399 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
4400 NL80211_REGDOM_TYPE_WORLD
);
4401 else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9')
4402 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
4403 NL80211_REGDOM_TYPE_CUSTOM_WORLD
);
4404 else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
4406 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
4407 NL80211_REGDOM_TYPE_INTERSECTION
);
4409 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
4410 NL80211_REGDOM_TYPE_COUNTRY
);
4411 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, request
->alpha2
);
4414 if (wiphy_idx_valid(request
->wiphy_idx
))
4415 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
);
4417 if (genlmsg_end(msg
, hdr
) < 0) {
4422 genlmsg_multicast(msg
, 0, nl80211_regulatory_mcgrp
.id
, GFP_KERNEL
);
4427 genlmsg_cancel(msg
, hdr
);
4431 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
4432 struct net_device
*netdev
,
4433 const u8
*buf
, size_t len
,
4434 enum nl80211_commands cmd
, gfp_t gfp
)
4436 struct sk_buff
*msg
;
4439 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
4443 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
4449 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4450 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
4451 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
4453 if (genlmsg_end(msg
, hdr
) < 0) {
4458 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
4462 genlmsg_cancel(msg
, hdr
);
4466 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
4467 struct net_device
*netdev
, const u8
*buf
,
4468 size_t len
, gfp_t gfp
)
4470 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
4471 NL80211_CMD_AUTHENTICATE
, gfp
);
4474 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
4475 struct net_device
*netdev
, const u8
*buf
,
4476 size_t len
, gfp_t gfp
)
4478 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
4479 NL80211_CMD_ASSOCIATE
, gfp
);
4482 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
4483 struct net_device
*netdev
, const u8
*buf
,
4484 size_t len
, gfp_t gfp
)
4486 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
4487 NL80211_CMD_DEAUTHENTICATE
, gfp
);
4490 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
4491 struct net_device
*netdev
, const u8
*buf
,
4492 size_t len
, gfp_t gfp
)
4494 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
4495 NL80211_CMD_DISASSOCIATE
, gfp
);
4498 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
4499 struct net_device
*netdev
, int cmd
,
4500 const u8
*addr
, gfp_t gfp
)
4502 struct sk_buff
*msg
;
4505 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
4509 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
4515 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4516 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
4517 NLA_PUT_FLAG(msg
, NL80211_ATTR_TIMED_OUT
);
4518 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
4520 if (genlmsg_end(msg
, hdr
) < 0) {
4525 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
4529 genlmsg_cancel(msg
, hdr
);
4533 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
4534 struct net_device
*netdev
, const u8
*addr
,
4537 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
4541 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
4542 struct net_device
*netdev
, const u8
*addr
,
4545 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
4549 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
4550 struct net_device
*netdev
, const u8
*bssid
,
4551 const u8
*req_ie
, size_t req_ie_len
,
4552 const u8
*resp_ie
, size_t resp_ie_len
,
4553 u16 status
, gfp_t gfp
)
4555 struct sk_buff
*msg
;
4558 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
4562 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
4568 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4569 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
4571 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
4572 NLA_PUT_U16(msg
, NL80211_ATTR_STATUS_CODE
, status
);
4574 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
4576 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
4578 if (genlmsg_end(msg
, hdr
) < 0) {
4583 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
4587 genlmsg_cancel(msg
, hdr
);
4592 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
4593 struct net_device
*netdev
, const u8
*bssid
,
4594 const u8
*req_ie
, size_t req_ie_len
,
4595 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
4597 struct sk_buff
*msg
;
4600 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
4604 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
4610 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4611 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
4612 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
4614 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
4616 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
4618 if (genlmsg_end(msg
, hdr
) < 0) {
4623 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
4627 genlmsg_cancel(msg
, hdr
);
4632 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
4633 struct net_device
*netdev
, u16 reason
,
4634 const u8
*ie
, size_t ie_len
, bool from_ap
)
4636 struct sk_buff
*msg
;
4639 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
4643 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
4649 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4650 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
4651 if (from_ap
&& reason
)
4652 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason
);
4654 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
);
4656 NLA_PUT(msg
, NL80211_ATTR_IE
, ie_len
, ie
);
4658 if (genlmsg_end(msg
, hdr
) < 0) {
4663 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
4667 genlmsg_cancel(msg
, hdr
);
4672 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
4673 struct net_device
*netdev
, const u8
*bssid
,
4676 struct sk_buff
*msg
;
4679 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
4683 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
4689 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4690 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
4691 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
4693 if (genlmsg_end(msg
, hdr
) < 0) {
4698 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
4702 genlmsg_cancel(msg
, hdr
);
4706 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
4707 struct net_device
*netdev
, const u8
*addr
,
4708 enum nl80211_key_type key_type
, int key_id
,
4709 const u8
*tsc
, gfp_t gfp
)
4711 struct sk_buff
*msg
;
4714 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
4718 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
4724 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4725 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
4727 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
4728 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
);
4729 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_id
);
4731 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
);
4733 if (genlmsg_end(msg
, hdr
) < 0) {
4738 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
4742 genlmsg_cancel(msg
, hdr
);
4746 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
4747 struct ieee80211_channel
*channel_before
,
4748 struct ieee80211_channel
*channel_after
)
4750 struct sk_buff
*msg
;
4752 struct nlattr
*nl_freq
;
4754 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
4758 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
4765 * Since we are applying the beacon hint to a wiphy we know its
4766 * wiphy_idx is valid
4768 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
));
4771 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
4773 goto nla_put_failure
;
4774 if (nl80211_msg_put_channel(msg
, channel_before
))
4775 goto nla_put_failure
;
4776 nla_nest_end(msg
, nl_freq
);
4779 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
4781 goto nla_put_failure
;
4782 if (nl80211_msg_put_channel(msg
, channel_after
))
4783 goto nla_put_failure
;
4784 nla_nest_end(msg
, nl_freq
);
4786 if (genlmsg_end(msg
, hdr
) < 0) {
4791 genlmsg_multicast(msg
, 0, nl80211_regulatory_mcgrp
.id
, GFP_ATOMIC
);
4796 genlmsg_cancel(msg
, hdr
);
4800 /* initialisation/exit functions */
4802 int nl80211_init(void)
4806 err
= genl_register_family_with_ops(&nl80211_fam
,
4807 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
4811 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
4815 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
4819 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
4823 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
4827 #ifdef CONFIG_NL80211_TESTMODE
4828 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
4835 genl_unregister_family(&nl80211_fam
);
4839 void nl80211_exit(void)
4841 genl_unregister_family(&nl80211_fam
);