2 * This is the new netlink-based wireless configuration interface.
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
8 #include <linux/module.h>
10 #include <linux/list.h>
11 #include <linux/if_ether.h>
12 #include <linux/ieee80211.h>
13 #include <linux/nl80211.h>
14 #include <linux/rtnetlink.h>
15 #include <linux/netlink.h>
16 #include <linux/etherdevice.h>
17 #include <net/net_namespace.h>
18 #include <net/genetlink.h>
19 #include <net/cfg80211.h>
25 /* the netlink family */
26 static struct genl_family nl80211_fam
= {
27 .id
= GENL_ID_GENERATE
, /* don't bother with a hardcoded ID */
28 .name
= "nl80211", /* have users key off the name instead */
29 .hdrsize
= 0, /* no private header */
30 .version
= 1, /* no particular meaning now */
31 .maxattr
= NL80211_ATTR_MAX
,
35 /* internal helper: get rdev and dev */
36 static int get_rdev_dev_by_info_ifindex(struct genl_info
*info
,
37 struct cfg80211_registered_device
**rdev
,
38 struct net_device
**dev
)
40 struct nlattr
**attrs
= info
->attrs
;
43 if (!attrs
[NL80211_ATTR_IFINDEX
])
46 ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
47 *dev
= dev_get_by_index(genl_info_net(info
), ifindex
);
51 *rdev
= cfg80211_get_dev_from_ifindex(genl_info_net(info
), ifindex
);
54 return PTR_ERR(*rdev
);
60 /* policy for the attributes */
61 static const struct nla_policy nl80211_policy
[NL80211_ATTR_MAX
+1] = {
62 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
63 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
65 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
66 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
67 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
68 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
69 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
70 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
71 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
72 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
74 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
75 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
76 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
78 [NL80211_ATTR_MAC
] = { .type
= NLA_BINARY
, .len
= ETH_ALEN
},
79 [NL80211_ATTR_PREV_BSSID
] = { .type
= NLA_BINARY
, .len
= ETH_ALEN
},
81 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
82 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
83 .len
= WLAN_MAX_KEY_LEN
},
84 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
85 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
86 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
87 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 8 },
89 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
90 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
91 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
92 .len
= IEEE80211_MAX_DATA_LEN
},
93 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
94 .len
= IEEE80211_MAX_DATA_LEN
},
95 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
96 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
97 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
98 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
99 .len
= NL80211_MAX_SUPP_RATES
},
100 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
101 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
102 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
103 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
104 .len
= IEEE80211_MAX_MESH_ID_LEN
},
105 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
107 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
108 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
110 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
111 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
112 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
113 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
114 .len
= NL80211_MAX_SUPP_RATES
},
116 [NL80211_ATTR_MESH_PARAMS
] = { .type
= NLA_NESTED
},
118 [NL80211_ATTR_HT_CAPABILITY
] = { .type
= NLA_BINARY
,
119 .len
= NL80211_HT_CAPABILITY_LEN
},
121 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
122 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
123 .len
= IEEE80211_MAX_DATA_LEN
},
124 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
125 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
127 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
128 .len
= IEEE80211_MAX_SSID_LEN
},
129 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
130 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
131 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
132 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
133 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
134 [NL80211_ATTR_STA_FLAGS2
] = {
135 .len
= sizeof(struct nl80211_sta_flag_update
),
137 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
138 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
139 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
140 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
141 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
142 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
143 [NL80211_ATTR_PMKID
] = { .type
= NLA_BINARY
,
144 .len
= WLAN_PMKID_LEN
},
145 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
146 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
147 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
148 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
149 .len
= IEEE80211_MAX_DATA_LEN
},
150 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
151 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
152 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
155 /* policy for the attributes */
156 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
157 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
158 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
159 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
160 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 8 },
161 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
162 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
165 /* ifidx get helper */
166 static int nl80211_get_ifidx(struct netlink_callback
*cb
)
170 res
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
171 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
176 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
179 res
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
186 static bool is_valid_ie_attr(const struct nlattr
*attr
)
194 pos
= nla_data(attr
);
215 /* message building helper */
216 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 pid
, u32 seq
,
219 /* since there is no private header just add the generic one */
220 return genlmsg_put(skb
, pid
, seq
, &nl80211_fam
, flags
, cmd
);
223 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
224 struct ieee80211_channel
*chan
)
226 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
229 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
230 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_DISABLED
);
231 if (chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
232 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
);
233 if (chan
->flags
& IEEE80211_CHAN_NO_IBSS
)
234 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
);
235 if (chan
->flags
& IEEE80211_CHAN_RADAR
)
236 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_RADAR
);
238 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
239 DBM_TO_MBM(chan
->max_power
));
247 /* netlink command implementations */
255 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
257 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
258 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
263 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
264 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
266 if (tb
[NL80211_KEY_IDX
])
267 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
269 if (tb
[NL80211_KEY_DATA
]) {
270 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
271 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
274 if (tb
[NL80211_KEY_SEQ
]) {
275 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
276 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
279 if (tb
[NL80211_KEY_CIPHER
])
280 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
285 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
287 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
288 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
289 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
292 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
293 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
294 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
297 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
298 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
300 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
301 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
303 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
304 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
309 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
313 memset(k
, 0, sizeof(*k
));
316 if (info
->attrs
[NL80211_ATTR_KEY
])
317 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
319 err
= nl80211_parse_key_old(info
, k
);
324 if (k
->def
&& k
->defmgmt
)
329 if (k
->idx
< 4 || k
->idx
> 5)
332 if (k
->idx
< 0 || k
->idx
> 3)
335 if (k
->idx
< 0 || k
->idx
> 5)
343 static struct cfg80211_cached_keys
*
344 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
347 struct key_parse parse
;
349 struct cfg80211_cached_keys
*result
;
350 int rem
, err
, def
= 0;
352 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
354 return ERR_PTR(-ENOMEM
);
357 result
->defmgmt
= -1;
359 nla_for_each_nested(key
, keys
, rem
) {
360 memset(&parse
, 0, sizeof(parse
));
363 err
= nl80211_parse_key_new(key
, &parse
);
369 if (parse
.idx
< 0 || parse
.idx
> 4)
375 result
->def
= parse
.idx
;
376 } else if (parse
.defmgmt
)
378 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
382 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
383 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
384 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
385 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
394 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
396 ASSERT_WDEV_LOCK(wdev
);
398 if (!netif_running(wdev
->netdev
))
401 switch (wdev
->iftype
) {
402 case NL80211_IFTYPE_AP
:
403 case NL80211_IFTYPE_AP_VLAN
:
405 case NL80211_IFTYPE_ADHOC
:
406 if (!wdev
->current_bss
)
409 case NL80211_IFTYPE_STATION
:
410 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
420 static int nl80211_send_wiphy(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
421 struct cfg80211_registered_device
*dev
)
424 struct nlattr
*nl_bands
, *nl_band
;
425 struct nlattr
*nl_freqs
, *nl_freq
;
426 struct nlattr
*nl_rates
, *nl_rate
;
427 struct nlattr
*nl_modes
;
428 struct nlattr
*nl_cmds
;
429 enum ieee80211_band band
;
430 struct ieee80211_channel
*chan
;
431 struct ieee80211_rate
*rate
;
433 u16 ifmodes
= dev
->wiphy
.interface_modes
;
435 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
439 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
);
440 NLA_PUT_STRING(msg
, NL80211_ATTR_WIPHY_NAME
, wiphy_name(&dev
->wiphy
));
442 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
443 cfg80211_rdev_list_generation
);
445 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
446 dev
->wiphy
.retry_short
);
447 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
448 dev
->wiphy
.retry_long
);
449 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
450 dev
->wiphy
.frag_threshold
);
451 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
452 dev
->wiphy
.rts_threshold
);
453 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
454 dev
->wiphy
.coverage_class
);
456 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
457 dev
->wiphy
.max_scan_ssids
);
458 NLA_PUT_U16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
459 dev
->wiphy
.max_scan_ie_len
);
461 NLA_PUT(msg
, NL80211_ATTR_CIPHER_SUITES
,
462 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
463 dev
->wiphy
.cipher_suites
);
465 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
466 dev
->wiphy
.max_num_pmkids
);
468 nl_modes
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
);
470 goto nla_put_failure
;
475 NLA_PUT_FLAG(msg
, i
);
480 nla_nest_end(msg
, nl_modes
);
482 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
484 goto nla_put_failure
;
486 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
487 if (!dev
->wiphy
.bands
[band
])
490 nl_band
= nla_nest_start(msg
, band
);
492 goto nla_put_failure
;
495 if (dev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
) {
496 NLA_PUT(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
497 sizeof(dev
->wiphy
.bands
[band
]->ht_cap
.mcs
),
498 &dev
->wiphy
.bands
[band
]->ht_cap
.mcs
);
499 NLA_PUT_U16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
500 dev
->wiphy
.bands
[band
]->ht_cap
.cap
);
501 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
502 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_factor
);
503 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
504 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_density
);
507 /* add frequencies */
508 nl_freqs
= nla_nest_start(msg
, NL80211_BAND_ATTR_FREQS
);
510 goto nla_put_failure
;
512 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_channels
; i
++) {
513 nl_freq
= nla_nest_start(msg
, i
);
515 goto nla_put_failure
;
517 chan
= &dev
->wiphy
.bands
[band
]->channels
[i
];
519 if (nl80211_msg_put_channel(msg
, chan
))
520 goto nla_put_failure
;
522 nla_nest_end(msg
, nl_freq
);
525 nla_nest_end(msg
, nl_freqs
);
528 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
530 goto nla_put_failure
;
532 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_bitrates
; i
++) {
533 nl_rate
= nla_nest_start(msg
, i
);
535 goto nla_put_failure
;
537 rate
= &dev
->wiphy
.bands
[band
]->bitrates
[i
];
538 NLA_PUT_U32(msg
, NL80211_BITRATE_ATTR_RATE
,
540 if (rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
)
542 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
);
544 nla_nest_end(msg
, nl_rate
);
547 nla_nest_end(msg
, nl_rates
);
549 nla_nest_end(msg
, nl_band
);
551 nla_nest_end(msg
, nl_bands
);
553 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
555 goto nla_put_failure
;
560 if (dev->ops->op) { \
562 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
566 CMD(add_virtual_intf
, NEW_INTERFACE
);
567 CMD(change_virtual_intf
, SET_INTERFACE
);
568 CMD(add_key
, NEW_KEY
);
569 CMD(add_beacon
, NEW_BEACON
);
570 CMD(add_station
, NEW_STATION
);
571 CMD(add_mpath
, NEW_MPATH
);
572 CMD(set_mesh_params
, SET_MESH_PARAMS
);
573 CMD(change_bss
, SET_BSS
);
574 CMD(auth
, AUTHENTICATE
);
575 CMD(assoc
, ASSOCIATE
);
576 CMD(deauth
, DEAUTHENTICATE
);
577 CMD(disassoc
, DISASSOCIATE
);
578 CMD(join_ibss
, JOIN_IBSS
);
579 CMD(set_pmksa
, SET_PMKSA
);
580 CMD(del_pmksa
, DEL_PMKSA
);
581 CMD(flush_pmksa
, FLUSH_PMKSA
);
582 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
583 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
585 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
587 NLA_PUT_U32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
);
592 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
594 NLA_PUT_U32(msg
, i
, NL80211_CMD_CONNECT
);
597 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
599 NLA_PUT_U32(msg
, i
, NL80211_CMD_DISCONNECT
);
602 nla_nest_end(msg
, nl_cmds
);
604 return genlmsg_end(msg
, hdr
);
607 genlmsg_cancel(msg
, hdr
);
611 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
614 int start
= cb
->args
[0];
615 struct cfg80211_registered_device
*dev
;
617 mutex_lock(&cfg80211_mutex
);
618 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
619 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
623 if (nl80211_send_wiphy(skb
, NETLINK_CB(cb
->skb
).pid
,
624 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
630 mutex_unlock(&cfg80211_mutex
);
637 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
640 struct cfg80211_registered_device
*dev
;
642 dev
= cfg80211_get_dev_from_info(info
);
646 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
650 if (nl80211_send_wiphy(msg
, info
->snd_pid
, info
->snd_seq
, 0, dev
) < 0)
653 cfg80211_unlock_rdev(dev
);
655 return genlmsg_reply(msg
, info
);
660 cfg80211_unlock_rdev(dev
);
664 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
665 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
666 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
667 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
668 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
669 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
672 static int parse_txq_params(struct nlattr
*tb
[],
673 struct ieee80211_txq_params
*txq_params
)
675 if (!tb
[NL80211_TXQ_ATTR_QUEUE
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
676 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
677 !tb
[NL80211_TXQ_ATTR_AIFS
])
680 txq_params
->queue
= nla_get_u8(tb
[NL80211_TXQ_ATTR_QUEUE
]);
681 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
682 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
683 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
684 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
689 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
691 struct cfg80211_registered_device
*rdev
;
692 int result
= 0, rem_txq_params
= 0;
693 struct nlattr
*nl_txq_params
;
695 u8 retry_short
= 0, retry_long
= 0;
696 u32 frag_threshold
= 0, rts_threshold
= 0;
697 u8 coverage_class
= 0;
701 mutex_lock(&cfg80211_mutex
);
703 rdev
= __cfg80211_rdev_from_info(info
);
705 mutex_unlock(&cfg80211_mutex
);
706 result
= PTR_ERR(rdev
);
710 mutex_lock(&rdev
->mtx
);
712 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
713 result
= cfg80211_dev_rename(
714 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
716 mutex_unlock(&cfg80211_mutex
);
721 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
722 struct ieee80211_txq_params txq_params
;
723 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
725 if (!rdev
->ops
->set_txq_params
) {
726 result
= -EOPNOTSUPP
;
730 nla_for_each_nested(nl_txq_params
,
731 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
733 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
734 nla_data(nl_txq_params
),
735 nla_len(nl_txq_params
),
737 result
= parse_txq_params(tb
, &txq_params
);
741 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
748 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
749 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
754 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
755 channel_type
= nla_get_u32(info
->attrs
[
756 NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
757 if (channel_type
!= NL80211_CHAN_NO_HT
&&
758 channel_type
!= NL80211_CHAN_HT20
&&
759 channel_type
!= NL80211_CHAN_HT40PLUS
&&
760 channel_type
!= NL80211_CHAN_HT40MINUS
)
764 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
766 mutex_lock(&rdev
->devlist_mtx
);
767 result
= rdev_set_freq(rdev
, NULL
, freq
, channel_type
);
768 mutex_unlock(&rdev
->devlist_mtx
);
775 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
776 retry_short
= nla_get_u8(
777 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
778 if (retry_short
== 0) {
782 changed
|= WIPHY_PARAM_RETRY_SHORT
;
785 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
786 retry_long
= nla_get_u8(
787 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
788 if (retry_long
== 0) {
792 changed
|= WIPHY_PARAM_RETRY_LONG
;
795 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
796 frag_threshold
= nla_get_u32(
797 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
798 if (frag_threshold
< 256) {
802 if (frag_threshold
!= (u32
) -1) {
804 * Fragments (apart from the last one) are required to
805 * have even length. Make the fragmentation code
806 * simpler by stripping LSB should someone try to use
807 * odd threshold value.
809 frag_threshold
&= ~0x1;
811 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
814 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
815 rts_threshold
= nla_get_u32(
816 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
817 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
820 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
821 coverage_class
= nla_get_u8(
822 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
823 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
827 u8 old_retry_short
, old_retry_long
;
828 u32 old_frag_threshold
, old_rts_threshold
;
829 u8 old_coverage_class
;
831 if (!rdev
->ops
->set_wiphy_params
) {
832 result
= -EOPNOTSUPP
;
836 old_retry_short
= rdev
->wiphy
.retry_short
;
837 old_retry_long
= rdev
->wiphy
.retry_long
;
838 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
839 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
840 old_coverage_class
= rdev
->wiphy
.coverage_class
;
842 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
843 rdev
->wiphy
.retry_short
= retry_short
;
844 if (changed
& WIPHY_PARAM_RETRY_LONG
)
845 rdev
->wiphy
.retry_long
= retry_long
;
846 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
847 rdev
->wiphy
.frag_threshold
= frag_threshold
;
848 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
849 rdev
->wiphy
.rts_threshold
= rts_threshold
;
850 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
851 rdev
->wiphy
.coverage_class
= coverage_class
;
853 result
= rdev
->ops
->set_wiphy_params(&rdev
->wiphy
, changed
);
855 rdev
->wiphy
.retry_short
= old_retry_short
;
856 rdev
->wiphy
.retry_long
= old_retry_long
;
857 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
858 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
859 rdev
->wiphy
.coverage_class
= old_coverage_class
;
864 mutex_unlock(&rdev
->mtx
);
871 static int nl80211_send_iface(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
872 struct cfg80211_registered_device
*rdev
,
873 struct net_device
*dev
)
877 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
881 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
882 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
883 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, dev
->name
);
884 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, dev
->ieee80211_ptr
->iftype
);
886 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
887 rdev
->devlist_generation
^
888 (cfg80211_rdev_list_generation
<< 2));
890 return genlmsg_end(msg
, hdr
);
893 genlmsg_cancel(msg
, hdr
);
897 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
901 int wp_start
= cb
->args
[0];
902 int if_start
= cb
->args
[1];
903 struct cfg80211_registered_device
*rdev
;
904 struct wireless_dev
*wdev
;
906 mutex_lock(&cfg80211_mutex
);
907 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
908 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
910 if (wp_idx
< wp_start
) {
916 mutex_lock(&rdev
->devlist_mtx
);
917 list_for_each_entry(wdev
, &rdev
->netdev_list
, list
) {
918 if (if_idx
< if_start
) {
922 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).pid
,
923 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
924 rdev
, wdev
->netdev
) < 0) {
925 mutex_unlock(&rdev
->devlist_mtx
);
930 mutex_unlock(&rdev
->devlist_mtx
);
935 mutex_unlock(&cfg80211_mutex
);
937 cb
->args
[0] = wp_idx
;
938 cb
->args
[1] = if_idx
;
943 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
946 struct cfg80211_registered_device
*dev
;
947 struct net_device
*netdev
;
950 err
= get_rdev_dev_by_info_ifindex(info
, &dev
, &netdev
);
954 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
958 if (nl80211_send_iface(msg
, info
->snd_pid
, info
->snd_seq
, 0,
963 cfg80211_unlock_rdev(dev
);
965 return genlmsg_reply(msg
, info
);
971 cfg80211_unlock_rdev(dev
);
975 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
976 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
977 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
978 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
979 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
980 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
983 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
985 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
993 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
994 nla
, mntr_flags_policy
))
997 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
999 *mntrflags
|= (1<<flag
);
1004 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
1005 struct net_device
*netdev
, u8 use_4addr
,
1006 enum nl80211_iftype iftype
)
1009 if (netdev
&& netdev
->br_port
)
1015 case NL80211_IFTYPE_AP_VLAN
:
1016 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
1019 case NL80211_IFTYPE_STATION
:
1020 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
1030 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1032 struct cfg80211_registered_device
*rdev
;
1033 struct vif_params params
;
1035 enum nl80211_iftype otype
, ntype
;
1036 struct net_device
*dev
;
1037 u32 _flags
, *flags
= NULL
;
1038 bool change
= false;
1040 memset(¶ms
, 0, sizeof(params
));
1044 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1048 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
1050 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1051 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1054 if (ntype
> NL80211_IFTYPE_MAX
) {
1060 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1061 if (ntype
!= NL80211_IFTYPE_MESH_POINT
) {
1065 params
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1066 params
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1070 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1071 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1073 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
1077 params
.use_4addr
= -1;
1080 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
1081 if (ntype
!= NL80211_IFTYPE_MONITOR
) {
1085 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
1095 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
1099 if (!err
&& params
.use_4addr
!= -1)
1100 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
1104 cfg80211_unlock_rdev(rdev
);
1110 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1112 struct cfg80211_registered_device
*rdev
;
1113 struct vif_params params
;
1115 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
1118 memset(¶ms
, 0, sizeof(params
));
1120 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
1123 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1124 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1125 if (type
> NL80211_IFTYPE_MAX
)
1131 rdev
= cfg80211_get_dev_from_info(info
);
1133 err
= PTR_ERR(rdev
);
1137 if (!rdev
->ops
->add_virtual_intf
||
1138 !(rdev
->wiphy
.interface_modes
& (1 << type
))) {
1143 if (type
== NL80211_IFTYPE_MESH_POINT
&&
1144 info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1145 params
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1146 params
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1149 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1150 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1151 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
1156 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
1157 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
1159 err
= rdev
->ops
->add_virtual_intf(&rdev
->wiphy
,
1160 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
1161 type
, err
? NULL
: &flags
, ¶ms
);
1164 cfg80211_unlock_rdev(rdev
);
1170 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1172 struct cfg80211_registered_device
*rdev
;
1174 struct net_device
*dev
;
1178 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1182 if (!rdev
->ops
->del_virtual_intf
) {
1187 err
= rdev
->ops
->del_virtual_intf(&rdev
->wiphy
, dev
);
1190 cfg80211_unlock_rdev(rdev
);
1197 struct get_key_cookie
{
1198 struct sk_buff
*msg
;
1203 static void get_key_callback(void *c
, struct key_params
*params
)
1206 struct get_key_cookie
*cookie
= c
;
1209 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
1210 params
->key_len
, params
->key
);
1213 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
1214 params
->seq_len
, params
->seq
);
1217 NLA_PUT_U32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
1220 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
1222 goto nla_put_failure
;
1225 NLA_PUT(cookie
->msg
, NL80211_KEY_DATA
,
1226 params
->key_len
, params
->key
);
1229 NLA_PUT(cookie
->msg
, NL80211_KEY_SEQ
,
1230 params
->seq_len
, params
->seq
);
1233 NLA_PUT_U32(cookie
->msg
, NL80211_KEY_CIPHER
,
1236 NLA_PUT_U8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
);
1238 nla_nest_end(cookie
->msg
, key
);
1245 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
1247 struct cfg80211_registered_device
*rdev
;
1249 struct net_device
*dev
;
1251 u8
*mac_addr
= NULL
;
1252 struct get_key_cookie cookie
= {
1256 struct sk_buff
*msg
;
1258 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
1259 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1264 if (info
->attrs
[NL80211_ATTR_MAC
])
1265 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1269 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1273 if (!rdev
->ops
->get_key
) {
1278 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1284 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1285 NL80211_CMD_NEW_KEY
);
1293 cookie
.idx
= key_idx
;
1295 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1296 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
1298 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1300 err
= rdev
->ops
->get_key(&rdev
->wiphy
, dev
, key_idx
, mac_addr
,
1301 &cookie
, get_key_callback
);
1307 goto nla_put_failure
;
1309 genlmsg_end(msg
, hdr
);
1310 err
= genlmsg_reply(msg
, info
);
1318 cfg80211_unlock_rdev(rdev
);
1326 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
1328 struct cfg80211_registered_device
*rdev
;
1329 struct key_parse key
;
1331 struct net_device
*dev
;
1332 int (*func
)(struct wiphy
*wiphy
, struct net_device
*netdev
,
1335 err
= nl80211_parse_key(info
, &key
);
1342 /* only support setting default key */
1343 if (!key
.def
&& !key
.defmgmt
)
1348 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1353 func
= rdev
->ops
->set_default_key
;
1355 func
= rdev
->ops
->set_default_mgmt_key
;
1362 wdev_lock(dev
->ieee80211_ptr
);
1363 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1365 err
= func(&rdev
->wiphy
, dev
, key
.idx
);
1367 #ifdef CONFIG_CFG80211_WEXT
1369 if (func
== rdev
->ops
->set_default_key
)
1370 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
1372 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
1375 wdev_unlock(dev
->ieee80211_ptr
);
1378 cfg80211_unlock_rdev(rdev
);
1387 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
1389 struct cfg80211_registered_device
*rdev
;
1391 struct net_device
*dev
;
1392 struct key_parse key
;
1393 u8
*mac_addr
= NULL
;
1395 err
= nl80211_parse_key(info
, &key
);
1402 if (info
->attrs
[NL80211_ATTR_MAC
])
1403 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1407 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1411 if (!rdev
->ops
->add_key
) {
1416 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
, mac_addr
)) {
1421 wdev_lock(dev
->ieee80211_ptr
);
1422 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1424 err
= rdev
->ops
->add_key(&rdev
->wiphy
, dev
, key
.idx
,
1426 wdev_unlock(dev
->ieee80211_ptr
);
1429 cfg80211_unlock_rdev(rdev
);
1437 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
1439 struct cfg80211_registered_device
*rdev
;
1441 struct net_device
*dev
;
1442 u8
*mac_addr
= NULL
;
1443 struct key_parse key
;
1445 err
= nl80211_parse_key(info
, &key
);
1449 if (info
->attrs
[NL80211_ATTR_MAC
])
1450 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1454 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1458 if (!rdev
->ops
->del_key
) {
1463 wdev_lock(dev
->ieee80211_ptr
);
1464 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1466 err
= rdev
->ops
->del_key(&rdev
->wiphy
, dev
, key
.idx
, mac_addr
);
1468 #ifdef CONFIG_CFG80211_WEXT
1470 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
1471 dev
->ieee80211_ptr
->wext
.default_key
= -1;
1472 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
1473 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
1476 wdev_unlock(dev
->ieee80211_ptr
);
1479 cfg80211_unlock_rdev(rdev
);
1488 static int nl80211_addset_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1490 int (*call
)(struct wiphy
*wiphy
, struct net_device
*dev
,
1491 struct beacon_parameters
*info
);
1492 struct cfg80211_registered_device
*rdev
;
1494 struct net_device
*dev
;
1495 struct beacon_parameters params
;
1498 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]))
1503 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1507 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1512 switch (info
->genlhdr
->cmd
) {
1513 case NL80211_CMD_NEW_BEACON
:
1514 /* these are required for NEW_BEACON */
1515 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
1516 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
1517 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1522 call
= rdev
->ops
->add_beacon
;
1524 case NL80211_CMD_SET_BEACON
:
1525 call
= rdev
->ops
->set_beacon
;
1538 memset(¶ms
, 0, sizeof(params
));
1540 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
1542 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
1546 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
1547 params
.dtim_period
=
1548 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
1552 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1553 params
.head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1555 nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1559 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
1560 params
.tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1562 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1571 err
= call(&rdev
->wiphy
, dev
, ¶ms
);
1574 cfg80211_unlock_rdev(rdev
);
1582 static int nl80211_del_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1584 struct cfg80211_registered_device
*rdev
;
1586 struct net_device
*dev
;
1590 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1594 if (!rdev
->ops
->del_beacon
) {
1599 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
1603 err
= rdev
->ops
->del_beacon(&rdev
->wiphy
, dev
);
1606 cfg80211_unlock_rdev(rdev
);
1614 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
1615 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
1616 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
1617 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
1618 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
1621 static int parse_station_flags(struct genl_info
*info
,
1622 struct station_parameters
*params
)
1624 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
1629 * Try parsing the new attribute first so userspace
1630 * can specify both for older kernels.
1632 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
1634 struct nl80211_sta_flag_update
*sta_flags
;
1636 sta_flags
= nla_data(nla
);
1637 params
->sta_flags_mask
= sta_flags
->mask
;
1638 params
->sta_flags_set
= sta_flags
->set
;
1639 if ((params
->sta_flags_mask
|
1640 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
1645 /* if present, parse the old attribute */
1647 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
1651 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
1652 nla
, sta_flags_policy
))
1655 params
->sta_flags_mask
= (1 << __NL80211_STA_FLAG_AFTER_LAST
) - 1;
1656 params
->sta_flags_mask
&= ~1;
1658 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++)
1660 params
->sta_flags_set
|= (1<<flag
);
1665 static int nl80211_send_station(struct sk_buff
*msg
, u32 pid
, u32 seq
,
1666 int flags
, struct net_device
*dev
,
1667 const u8
*mac_addr
, struct station_info
*sinfo
)
1670 struct nlattr
*sinfoattr
, *txrate
;
1673 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
1677 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1678 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1680 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
);
1682 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
1684 goto nla_put_failure
;
1685 if (sinfo
->filled
& STATION_INFO_INACTIVE_TIME
)
1686 NLA_PUT_U32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
1687 sinfo
->inactive_time
);
1688 if (sinfo
->filled
& STATION_INFO_RX_BYTES
)
1689 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_BYTES
,
1691 if (sinfo
->filled
& STATION_INFO_TX_BYTES
)
1692 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_BYTES
,
1694 if (sinfo
->filled
& STATION_INFO_LLID
)
1695 NLA_PUT_U16(msg
, NL80211_STA_INFO_LLID
,
1697 if (sinfo
->filled
& STATION_INFO_PLID
)
1698 NLA_PUT_U16(msg
, NL80211_STA_INFO_PLID
,
1700 if (sinfo
->filled
& STATION_INFO_PLINK_STATE
)
1701 NLA_PUT_U8(msg
, NL80211_STA_INFO_PLINK_STATE
,
1702 sinfo
->plink_state
);
1703 if (sinfo
->filled
& STATION_INFO_SIGNAL
)
1704 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL
,
1706 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
1707 txrate
= nla_nest_start(msg
, NL80211_STA_INFO_TX_BITRATE
);
1709 goto nla_put_failure
;
1711 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
1712 bitrate
= cfg80211_calculate_bitrate(&sinfo
->txrate
);
1714 NLA_PUT_U16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate
);
1716 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_MCS
)
1717 NLA_PUT_U8(msg
, NL80211_RATE_INFO_MCS
,
1719 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
)
1720 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
);
1721 if (sinfo
->txrate
.flags
& RATE_INFO_FLAGS_SHORT_GI
)
1722 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_SHORT_GI
);
1724 nla_nest_end(msg
, txrate
);
1726 if (sinfo
->filled
& STATION_INFO_RX_PACKETS
)
1727 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_PACKETS
,
1729 if (sinfo
->filled
& STATION_INFO_TX_PACKETS
)
1730 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_PACKETS
,
1732 nla_nest_end(msg
, sinfoattr
);
1734 return genlmsg_end(msg
, hdr
);
1737 genlmsg_cancel(msg
, hdr
);
1741 static int nl80211_dump_station(struct sk_buff
*skb
,
1742 struct netlink_callback
*cb
)
1744 struct station_info sinfo
;
1745 struct cfg80211_registered_device
*dev
;
1746 struct net_device
*netdev
;
1747 u8 mac_addr
[ETH_ALEN
];
1748 int ifidx
= cb
->args
[0];
1749 int sta_idx
= cb
->args
[1];
1753 ifidx
= nl80211_get_ifidx(cb
);
1759 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
1765 dev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
1771 if (!dev
->ops
->dump_station
) {
1777 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
1784 if (nl80211_send_station(skb
,
1785 NETLINK_CB(cb
->skb
).pid
,
1786 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1796 cb
->args
[1] = sta_idx
;
1799 cfg80211_unlock_rdev(dev
);
1806 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
1808 struct cfg80211_registered_device
*rdev
;
1810 struct net_device
*dev
;
1811 struct station_info sinfo
;
1812 struct sk_buff
*msg
;
1813 u8
*mac_addr
= NULL
;
1815 memset(&sinfo
, 0, sizeof(sinfo
));
1817 if (!info
->attrs
[NL80211_ATTR_MAC
])
1820 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1824 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1828 if (!rdev
->ops
->get_station
) {
1833 err
= rdev
->ops
->get_station(&rdev
->wiphy
, dev
, mac_addr
, &sinfo
);
1837 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1841 if (nl80211_send_station(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1842 dev
, mac_addr
, &sinfo
) < 0)
1845 err
= genlmsg_reply(msg
, info
);
1851 cfg80211_unlock_rdev(rdev
);
1860 * Get vlan interface making sure it is running and on the right wiphy.
1862 static int get_vlan(struct genl_info
*info
,
1863 struct cfg80211_registered_device
*rdev
,
1864 struct net_device
**vlan
)
1866 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
1870 *vlan
= dev_get_by_index(genl_info_net(info
),
1871 nla_get_u32(vlanattr
));
1874 if (!(*vlan
)->ieee80211_ptr
)
1876 if ((*vlan
)->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
)
1878 if (!netif_running(*vlan
))
1884 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
1886 struct cfg80211_registered_device
*rdev
;
1888 struct net_device
*dev
;
1889 struct station_parameters params
;
1890 u8
*mac_addr
= NULL
;
1892 memset(¶ms
, 0, sizeof(params
));
1894 params
.listen_interval
= -1;
1896 if (info
->attrs
[NL80211_ATTR_STA_AID
])
1899 if (!info
->attrs
[NL80211_ATTR_MAC
])
1902 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1904 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
1905 params
.supported_rates
=
1906 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1907 params
.supported_rates_len
=
1908 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
1911 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
1912 params
.listen_interval
=
1913 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
1915 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
1917 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
1919 if (parse_station_flags(info
, ¶ms
))
1922 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
1923 params
.plink_action
=
1924 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
1928 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
1932 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
1936 /* validate settings */
1939 switch (dev
->ieee80211_ptr
->iftype
) {
1940 case NL80211_IFTYPE_AP
:
1941 case NL80211_IFTYPE_AP_VLAN
:
1942 /* disallow mesh-specific things */
1943 if (params
.plink_action
)
1946 case NL80211_IFTYPE_STATION
:
1947 /* disallow everything but AUTHORIZED flag */
1948 if (params
.plink_action
)
1952 if (params
.supported_rates
)
1956 if (params
.listen_interval
>= 0)
1958 if (params
.sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
1961 case NL80211_IFTYPE_MESH_POINT
:
1962 /* disallow things mesh doesn't support */
1967 if (params
.listen_interval
>= 0)
1969 if (params
.supported_rates
)
1971 if (params
.sta_flags_mask
)
1981 if (!rdev
->ops
->change_station
) {
1986 err
= rdev
->ops
->change_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
1990 dev_put(params
.vlan
);
1991 cfg80211_unlock_rdev(rdev
);
1999 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
2001 struct cfg80211_registered_device
*rdev
;
2003 struct net_device
*dev
;
2004 struct station_parameters params
;
2005 u8
*mac_addr
= NULL
;
2007 memset(¶ms
, 0, sizeof(params
));
2009 if (!info
->attrs
[NL80211_ATTR_MAC
])
2012 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2015 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
2018 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
2021 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2022 params
.supported_rates
=
2023 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2024 params
.supported_rates_len
=
2025 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2026 params
.listen_interval
=
2027 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2029 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
2030 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
2033 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2035 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2037 if (parse_station_flags(info
, ¶ms
))
2042 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2046 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2047 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
) {
2052 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
2056 /* validate settings */
2059 if (!rdev
->ops
->add_station
) {
2064 if (!netif_running(dev
)) {
2069 err
= rdev
->ops
->add_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2073 dev_put(params
.vlan
);
2074 cfg80211_unlock_rdev(rdev
);
2082 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
2084 struct cfg80211_registered_device
*rdev
;
2086 struct net_device
*dev
;
2087 u8
*mac_addr
= NULL
;
2089 if (info
->attrs
[NL80211_ATTR_MAC
])
2090 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2094 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2098 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2099 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
2100 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2105 if (!rdev
->ops
->del_station
) {
2110 err
= rdev
->ops
->del_station(&rdev
->wiphy
, dev
, mac_addr
);
2113 cfg80211_unlock_rdev(rdev
);
2121 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2122 int flags
, struct net_device
*dev
,
2123 u8
*dst
, u8
*next_hop
,
2124 struct mpath_info
*pinfo
)
2127 struct nlattr
*pinfoattr
;
2129 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2133 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2134 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
2135 NLA_PUT(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
);
2137 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
);
2139 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
2141 goto nla_put_failure
;
2142 if (pinfo
->filled
& MPATH_INFO_FRAME_QLEN
)
2143 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
2145 if (pinfo
->filled
& MPATH_INFO_SN
)
2146 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_SN
,
2148 if (pinfo
->filled
& MPATH_INFO_METRIC
)
2149 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_METRIC
,
2151 if (pinfo
->filled
& MPATH_INFO_EXPTIME
)
2152 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_EXPTIME
,
2154 if (pinfo
->filled
& MPATH_INFO_FLAGS
)
2155 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_FLAGS
,
2157 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
)
2158 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
2159 pinfo
->discovery_timeout
);
2160 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
)
2161 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
2162 pinfo
->discovery_retries
);
2164 nla_nest_end(msg
, pinfoattr
);
2166 return genlmsg_end(msg
, hdr
);
2169 genlmsg_cancel(msg
, hdr
);
2173 static int nl80211_dump_mpath(struct sk_buff
*skb
,
2174 struct netlink_callback
*cb
)
2176 struct mpath_info pinfo
;
2177 struct cfg80211_registered_device
*dev
;
2178 struct net_device
*netdev
;
2180 u8 next_hop
[ETH_ALEN
];
2181 int ifidx
= cb
->args
[0];
2182 int path_idx
= cb
->args
[1];
2186 ifidx
= nl80211_get_ifidx(cb
);
2192 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
2198 dev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
2204 if (!dev
->ops
->dump_mpath
) {
2209 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2215 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
2216 dst
, next_hop
, &pinfo
);
2222 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).pid
,
2223 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2224 netdev
, dst
, next_hop
,
2233 cb
->args
[1] = path_idx
;
2236 cfg80211_unlock_rdev(dev
);
2243 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2245 struct cfg80211_registered_device
*rdev
;
2247 struct net_device
*dev
;
2248 struct mpath_info pinfo
;
2249 struct sk_buff
*msg
;
2251 u8 next_hop
[ETH_ALEN
];
2253 memset(&pinfo
, 0, sizeof(pinfo
));
2255 if (!info
->attrs
[NL80211_ATTR_MAC
])
2258 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2262 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2266 if (!rdev
->ops
->get_mpath
) {
2271 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2276 err
= rdev
->ops
->get_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
2280 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2284 if (nl80211_send_mpath(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2285 dev
, dst
, next_hop
, &pinfo
) < 0)
2288 err
= genlmsg_reply(msg
, info
);
2294 cfg80211_unlock_rdev(rdev
);
2302 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2304 struct cfg80211_registered_device
*rdev
;
2306 struct net_device
*dev
;
2308 u8
*next_hop
= NULL
;
2310 if (!info
->attrs
[NL80211_ATTR_MAC
])
2313 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2316 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2317 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2321 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2325 if (!rdev
->ops
->change_mpath
) {
2330 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2335 if (!netif_running(dev
)) {
2340 err
= rdev
->ops
->change_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2343 cfg80211_unlock_rdev(rdev
);
2350 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2352 struct cfg80211_registered_device
*rdev
;
2354 struct net_device
*dev
;
2356 u8
*next_hop
= NULL
;
2358 if (!info
->attrs
[NL80211_ATTR_MAC
])
2361 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2364 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2365 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2369 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2373 if (!rdev
->ops
->add_mpath
) {
2378 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2383 if (!netif_running(dev
)) {
2388 err
= rdev
->ops
->add_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2391 cfg80211_unlock_rdev(rdev
);
2399 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2401 struct cfg80211_registered_device
*rdev
;
2403 struct net_device
*dev
;
2406 if (info
->attrs
[NL80211_ATTR_MAC
])
2407 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2411 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2415 if (!rdev
->ops
->del_mpath
) {
2420 err
= rdev
->ops
->del_mpath(&rdev
->wiphy
, dev
, dst
);
2423 cfg80211_unlock_rdev(rdev
);
2431 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
2433 struct cfg80211_registered_device
*rdev
;
2435 struct net_device
*dev
;
2436 struct bss_parameters params
;
2438 memset(¶ms
, 0, sizeof(params
));
2439 /* default to not changing parameters */
2440 params
.use_cts_prot
= -1;
2441 params
.use_short_preamble
= -1;
2442 params
.use_short_slot_time
= -1;
2444 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
2445 params
.use_cts_prot
=
2446 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
2447 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
2448 params
.use_short_preamble
=
2449 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
2450 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
2451 params
.use_short_slot_time
=
2452 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
2453 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
2454 params
.basic_rates
=
2455 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2456 params
.basic_rates_len
=
2457 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2462 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2466 if (!rdev
->ops
->change_bss
) {
2471 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
) {
2476 err
= rdev
->ops
->change_bss(&rdev
->wiphy
, dev
, ¶ms
);
2479 cfg80211_unlock_rdev(rdev
);
2487 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
2488 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
2489 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
2490 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
2491 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
2492 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
2493 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
2496 static int parse_reg_rule(struct nlattr
*tb
[],
2497 struct ieee80211_reg_rule
*reg_rule
)
2499 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
2500 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
2502 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
2504 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
2506 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
2508 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
2510 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
2513 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
2515 freq_range
->start_freq_khz
=
2516 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
2517 freq_range
->end_freq_khz
=
2518 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
2519 freq_range
->max_bandwidth_khz
=
2520 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
2522 power_rule
->max_eirp
=
2523 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
2525 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
2526 power_rule
->max_antenna_gain
=
2527 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
2532 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2538 * You should only get this when cfg80211 hasn't yet initialized
2539 * completely when built-in to the kernel right between the time
2540 * window between nl80211_init() and regulatory_init(), if that is
2543 mutex_lock(&cfg80211_mutex
);
2544 if (unlikely(!cfg80211_regdomain
)) {
2545 mutex_unlock(&cfg80211_mutex
);
2546 return -EINPROGRESS
;
2548 mutex_unlock(&cfg80211_mutex
);
2550 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2553 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2555 r
= regulatory_hint_user(data
);
2560 static int nl80211_get_mesh_params(struct sk_buff
*skb
,
2561 struct genl_info
*info
)
2563 struct cfg80211_registered_device
*rdev
;
2564 struct mesh_config cur_params
;
2566 struct net_device
*dev
;
2568 struct nlattr
*pinfoattr
;
2569 struct sk_buff
*msg
;
2573 /* Look up our device */
2574 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2578 if (!rdev
->ops
->get_mesh_params
) {
2583 /* Get the mesh params */
2584 err
= rdev
->ops
->get_mesh_params(&rdev
->wiphy
, dev
, &cur_params
);
2588 /* Draw up a netlink message to send back */
2589 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2594 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2595 NL80211_CMD_GET_MESH_PARAMS
);
2597 goto nla_put_failure
;
2598 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_PARAMS
);
2600 goto nla_put_failure
;
2601 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2602 NLA_PUT_U16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
2603 cur_params
.dot11MeshRetryTimeout
);
2604 NLA_PUT_U16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
2605 cur_params
.dot11MeshConfirmTimeout
);
2606 NLA_PUT_U16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
2607 cur_params
.dot11MeshHoldingTimeout
);
2608 NLA_PUT_U16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
2609 cur_params
.dot11MeshMaxPeerLinks
);
2610 NLA_PUT_U8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
2611 cur_params
.dot11MeshMaxRetries
);
2612 NLA_PUT_U8(msg
, NL80211_MESHCONF_TTL
,
2613 cur_params
.dot11MeshTTL
);
2614 NLA_PUT_U8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
2615 cur_params
.auto_open_plinks
);
2616 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2617 cur_params
.dot11MeshHWMPmaxPREQretries
);
2618 NLA_PUT_U32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
2619 cur_params
.path_refresh_time
);
2620 NLA_PUT_U16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2621 cur_params
.min_discovery_timeout
);
2622 NLA_PUT_U32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2623 cur_params
.dot11MeshHWMPactivePathTimeout
);
2624 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2625 cur_params
.dot11MeshHWMPpreqMinInterval
);
2626 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2627 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
);
2628 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
2629 cur_params
.dot11MeshHWMPRootMode
);
2630 nla_nest_end(msg
, pinfoattr
);
2631 genlmsg_end(msg
, hdr
);
2632 err
= genlmsg_reply(msg
, info
);
2636 genlmsg_cancel(msg
, hdr
);
2640 cfg80211_unlock_rdev(rdev
);
2648 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2650 if (table[attr_num]) {\
2651 cfg.param = nla_fn(table[attr_num]); \
2652 mask |= (1 << (attr_num - 1)); \
2656 static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
2657 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
2658 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
2659 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
2660 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
2661 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
2662 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
2663 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
2665 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
2666 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
2667 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
2668 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
2669 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
2670 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
2673 static int nl80211_set_mesh_params(struct sk_buff
*skb
, struct genl_info
*info
)
2677 struct cfg80211_registered_device
*rdev
;
2678 struct net_device
*dev
;
2679 struct mesh_config cfg
;
2680 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
2681 struct nlattr
*parent_attr
;
2683 parent_attr
= info
->attrs
[NL80211_ATTR_MESH_PARAMS
];
2686 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
2687 parent_attr
, nl80211_meshconf_params_policy
))
2692 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2696 if (!rdev
->ops
->set_mesh_params
) {
2701 /* This makes sure that there aren't more than 32 mesh config
2702 * parameters (otherwise our bitfield scheme would not work.) */
2703 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
2705 /* Fill in the params struct */
2707 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
2708 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
, nla_get_u16
);
2709 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
2710 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
, nla_get_u16
);
2711 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
2712 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
, nla_get_u16
);
2713 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
2714 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
, nla_get_u16
);
2715 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
2716 mask
, NL80211_MESHCONF_MAX_RETRIES
, nla_get_u8
);
2717 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
2718 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
2719 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
2720 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
, nla_get_u8
);
2721 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
2722 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2724 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
2725 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
, nla_get_u32
);
2726 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
2727 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2729 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
2730 mask
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2732 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
2733 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2735 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
2736 dot11MeshHWMPnetDiameterTraversalTime
,
2737 mask
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2739 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
2740 dot11MeshHWMPRootMode
, mask
,
2741 NL80211_MESHCONF_HWMP_ROOTMODE
,
2745 err
= rdev
->ops
->set_mesh_params(&rdev
->wiphy
, dev
, &cfg
, mask
);
2749 cfg80211_unlock_rdev(rdev
);
2757 #undef FILL_IN_MESH_PARAM_IF_SET
2759 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2761 struct sk_buff
*msg
;
2763 struct nlattr
*nl_reg_rules
;
2767 mutex_lock(&cfg80211_mutex
);
2769 if (!cfg80211_regdomain
)
2772 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2778 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2779 NL80211_CMD_GET_REG
);
2781 goto nla_put_failure
;
2783 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
,
2784 cfg80211_regdomain
->alpha2
);
2786 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
2788 goto nla_put_failure
;
2790 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
2791 struct nlattr
*nl_reg_rule
;
2792 const struct ieee80211_reg_rule
*reg_rule
;
2793 const struct ieee80211_freq_range
*freq_range
;
2794 const struct ieee80211_power_rule
*power_rule
;
2796 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
2797 freq_range
= ®_rule
->freq_range
;
2798 power_rule
= ®_rule
->power_rule
;
2800 nl_reg_rule
= nla_nest_start(msg
, i
);
2802 goto nla_put_failure
;
2804 NLA_PUT_U32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
2806 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
2807 freq_range
->start_freq_khz
);
2808 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
2809 freq_range
->end_freq_khz
);
2810 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
2811 freq_range
->max_bandwidth_khz
);
2812 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
2813 power_rule
->max_antenna_gain
);
2814 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
2815 power_rule
->max_eirp
);
2817 nla_nest_end(msg
, nl_reg_rule
);
2820 nla_nest_end(msg
, nl_reg_rules
);
2822 genlmsg_end(msg
, hdr
);
2823 err
= genlmsg_reply(msg
, info
);
2827 genlmsg_cancel(msg
, hdr
);
2830 mutex_unlock(&cfg80211_mutex
);
2834 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2836 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
2837 struct nlattr
*nl_reg_rule
;
2838 char *alpha2
= NULL
;
2839 int rem_reg_rules
= 0, r
= 0;
2840 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
2841 struct ieee80211_regdomain
*rd
= NULL
;
2843 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2846 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
2849 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2851 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
2854 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
2858 mutex_lock(&cfg80211_mutex
);
2860 if (!reg_is_valid_request(alpha2
)) {
2865 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
2866 (num_rules
* sizeof(struct ieee80211_reg_rule
));
2868 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
2874 rd
->n_reg_rules
= num_rules
;
2875 rd
->alpha2
[0] = alpha2
[0];
2876 rd
->alpha2
[1] = alpha2
[1];
2878 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
2880 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
2881 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
2883 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
2889 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
2895 BUG_ON(rule_idx
!= num_rules
);
2899 mutex_unlock(&cfg80211_mutex
);
2904 mutex_unlock(&cfg80211_mutex
);
2909 static int validate_scan_freqs(struct nlattr
*freqs
)
2911 struct nlattr
*attr1
, *attr2
;
2912 int n_channels
= 0, tmp1
, tmp2
;
2914 nla_for_each_nested(attr1
, freqs
, tmp1
) {
2917 * Some hardware has a limited channel list for
2918 * scanning, and it is pretty much nonsensical
2919 * to scan for a channel twice, so disallow that
2920 * and don't require drivers to check that the
2921 * channel list they get isn't longer than what
2922 * they can scan, as long as they can scan all
2923 * the channels they registered at once.
2925 nla_for_each_nested(attr2
, freqs
, tmp2
)
2926 if (attr1
!= attr2
&&
2927 nla_get_u32(attr1
) == nla_get_u32(attr2
))
2934 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
2936 struct cfg80211_registered_device
*rdev
;
2937 struct net_device
*dev
;
2938 struct cfg80211_scan_request
*request
;
2939 struct cfg80211_ssid
*ssid
;
2940 struct ieee80211_channel
*channel
;
2941 struct nlattr
*attr
;
2942 struct wiphy
*wiphy
;
2943 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
2944 enum ieee80211_band band
;
2947 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
2952 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
2956 wiphy
= &rdev
->wiphy
;
2958 if (!rdev
->ops
->scan
) {
2963 if (!netif_running(dev
)) {
2968 if (rdev
->scan_req
) {
2973 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
2974 n_channels
= validate_scan_freqs(
2975 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
2983 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
2984 if (wiphy
->bands
[band
])
2985 n_channels
+= wiphy
->bands
[band
]->n_channels
;
2988 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
2989 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
2992 if (n_ssids
> wiphy
->max_scan_ssids
) {
2997 if (info
->attrs
[NL80211_ATTR_IE
])
2998 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3002 if (ie_len
> wiphy
->max_scan_ie_len
) {
3007 request
= kzalloc(sizeof(*request
)
3008 + sizeof(*ssid
) * n_ssids
3009 + sizeof(channel
) * n_channels
3010 + ie_len
, GFP_KERNEL
);
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
);
3027 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3028 /* user specified, bail out if channel not found */
3029 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
3030 struct ieee80211_channel
*chan
;
3032 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
3039 /* ignore disabled channels */
3040 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3043 request
->channels
[i
] = chan
;
3048 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
3050 if (!wiphy
->bands
[band
])
3052 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
3053 struct ieee80211_channel
*chan
;
3055 chan
= &wiphy
->bands
[band
]->channels
[j
];
3057 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3060 request
->channels
[i
] = chan
;
3071 request
->n_channels
= i
;
3074 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
3075 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
3076 if (request
->ssids
[i
].ssid_len
> IEEE80211_MAX_SSID_LEN
) {
3080 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
3081 request
->ssids
[i
].ssid_len
= nla_len(attr
);
3086 if (info
->attrs
[NL80211_ATTR_IE
]) {
3087 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3088 memcpy((void *)request
->ie
,
3089 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
3094 request
->wiphy
= &rdev
->wiphy
;
3096 rdev
->scan_req
= request
;
3097 err
= rdev
->ops
->scan(&rdev
->wiphy
, dev
, request
);
3100 nl80211_send_scan_start(rdev
, dev
);
3106 rdev
->scan_req
= NULL
;
3110 cfg80211_unlock_rdev(rdev
);
3118 static int nl80211_send_bss(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
3119 struct cfg80211_registered_device
*rdev
,
3120 struct wireless_dev
*wdev
,
3121 struct cfg80211_internal_bss
*intbss
)
3123 struct cfg80211_bss
*res
= &intbss
->pub
;
3128 ASSERT_WDEV_LOCK(wdev
);
3130 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3131 NL80211_CMD_NEW_SCAN_RESULTS
);
3135 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
);
3136 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
);
3138 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
3140 goto nla_put_failure
;
3141 if (!is_zero_ether_addr(res
->bssid
))
3142 NLA_PUT(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
);
3143 if (res
->information_elements
&& res
->len_information_elements
)
3144 NLA_PUT(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
3145 res
->len_information_elements
,
3146 res
->information_elements
);
3147 if (res
->beacon_ies
&& res
->len_beacon_ies
&&
3148 res
->beacon_ies
!= res
->information_elements
)
3149 NLA_PUT(msg
, NL80211_BSS_BEACON_IES
,
3150 res
->len_beacon_ies
, res
->beacon_ies
);
3152 NLA_PUT_U64(msg
, NL80211_BSS_TSF
, res
->tsf
);
3153 if (res
->beacon_interval
)
3154 NLA_PUT_U16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
);
3155 NLA_PUT_U16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
);
3156 NLA_PUT_U32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
);
3157 NLA_PUT_U32(msg
, NL80211_BSS_SEEN_MS_AGO
,
3158 jiffies_to_msecs(jiffies
- intbss
->ts
));
3160 switch (rdev
->wiphy
.signal_type
) {
3161 case CFG80211_SIGNAL_TYPE_MBM
:
3162 NLA_PUT_U32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
);
3164 case CFG80211_SIGNAL_TYPE_UNSPEC
:
3165 NLA_PUT_U8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
);
3171 switch (wdev
->iftype
) {
3172 case NL80211_IFTYPE_STATION
:
3173 if (intbss
== wdev
->current_bss
)
3174 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3175 NL80211_BSS_STATUS_ASSOCIATED
);
3176 else for (i
= 0; i
< MAX_AUTH_BSSES
; i
++) {
3177 if (intbss
!= wdev
->auth_bsses
[i
])
3179 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3180 NL80211_BSS_STATUS_AUTHENTICATED
);
3184 case NL80211_IFTYPE_ADHOC
:
3185 if (intbss
== wdev
->current_bss
)
3186 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3187 NL80211_BSS_STATUS_IBSS_JOINED
);
3193 nla_nest_end(msg
, bss
);
3195 return genlmsg_end(msg
, hdr
);
3198 genlmsg_cancel(msg
, hdr
);
3202 static int nl80211_dump_scan(struct sk_buff
*skb
,
3203 struct netlink_callback
*cb
)
3205 struct cfg80211_registered_device
*rdev
;
3206 struct net_device
*dev
;
3207 struct cfg80211_internal_bss
*scan
;
3208 struct wireless_dev
*wdev
;
3209 int ifidx
= cb
->args
[0];
3210 int start
= cb
->args
[1], idx
= 0;
3214 ifidx
= nl80211_get_ifidx(cb
);
3217 cb
->args
[0] = ifidx
;
3219 dev
= dev_get_by_index(sock_net(skb
->sk
), ifidx
);
3223 rdev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
3225 err
= PTR_ERR(rdev
);
3226 goto out_put_netdev
;
3229 wdev
= dev
->ieee80211_ptr
;
3232 spin_lock_bh(&rdev
->bss_lock
);
3233 cfg80211_bss_expire(rdev
);
3235 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
3238 if (nl80211_send_bss(skb
,
3239 NETLINK_CB(cb
->skb
).pid
,
3240 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3241 rdev
, wdev
, scan
) < 0) {
3248 spin_unlock_bh(&rdev
->bss_lock
);
3253 cfg80211_unlock_rdev(rdev
);
3260 static int nl80211_send_survey(struct sk_buff
*msg
, u32 pid
, u32 seq
,
3261 int flags
, struct net_device
*dev
,
3262 struct survey_info
*survey
)
3265 struct nlattr
*infoattr
;
3267 /* Survey without a channel doesn't make sense */
3268 if (!survey
->channel
)
3271 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3272 NL80211_CMD_NEW_SURVEY_RESULTS
);
3276 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
3278 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
3280 goto nla_put_failure
;
3282 NLA_PUT_U32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
3283 survey
->channel
->center_freq
);
3284 if (survey
->filled
& SURVEY_INFO_NOISE_DBM
)
3285 NLA_PUT_U8(msg
, NL80211_SURVEY_INFO_NOISE
,
3288 nla_nest_end(msg
, infoattr
);
3290 return genlmsg_end(msg
, hdr
);
3293 genlmsg_cancel(msg
, hdr
);
3297 static int nl80211_dump_survey(struct sk_buff
*skb
,
3298 struct netlink_callback
*cb
)
3300 struct survey_info survey
;
3301 struct cfg80211_registered_device
*dev
;
3302 struct net_device
*netdev
;
3303 int ifidx
= cb
->args
[0];
3304 int survey_idx
= cb
->args
[1];
3308 ifidx
= nl80211_get_ifidx(cb
);
3311 cb
->args
[0] = ifidx
;
3315 netdev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
3321 dev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
3327 if (!dev
->ops
->dump_survey
) {
3333 res
= dev
->ops
->dump_survey(&dev
->wiphy
, netdev
, survey_idx
,
3340 if (nl80211_send_survey(skb
,
3341 NETLINK_CB(cb
->skb
).pid
,
3342 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3350 cb
->args
[1] = survey_idx
;
3353 cfg80211_unlock_rdev(dev
);
3360 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
)
3362 return auth_type
<= NL80211_AUTHTYPE_MAX
;
3365 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
3367 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
3368 NL80211_WPA_VERSION_2
));
3371 static bool nl80211_valid_akm_suite(u32 akm
)
3373 return akm
== WLAN_AKM_SUITE_8021X
||
3374 akm
== WLAN_AKM_SUITE_PSK
;
3377 static bool nl80211_valid_cipher_suite(u32 cipher
)
3379 return cipher
== WLAN_CIPHER_SUITE_WEP40
||
3380 cipher
== WLAN_CIPHER_SUITE_WEP104
||
3381 cipher
== WLAN_CIPHER_SUITE_TKIP
||
3382 cipher
== WLAN_CIPHER_SUITE_CCMP
||
3383 cipher
== WLAN_CIPHER_SUITE_AES_CMAC
;
3387 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3389 struct cfg80211_registered_device
*rdev
;
3390 struct net_device
*dev
;
3391 struct ieee80211_channel
*chan
;
3392 const u8
*bssid
, *ssid
, *ie
= NULL
;
3393 int err
, ssid_len
, ie_len
= 0;
3394 enum nl80211_auth_type auth_type
;
3395 struct key_parse key
;
3397 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3400 if (!info
->attrs
[NL80211_ATTR_MAC
])
3403 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
3406 if (!info
->attrs
[NL80211_ATTR_SSID
])
3409 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
3412 err
= nl80211_parse_key(info
, &key
);
3417 if (!key
.p
.key
|| !key
.p
.key_len
)
3419 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
3420 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
3421 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
3422 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
3433 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3437 if (!rdev
->ops
->auth
) {
3442 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3447 if (!netif_running(dev
)) {
3452 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3453 chan
= ieee80211_get_channel(&rdev
->wiphy
,
3454 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3455 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
)) {
3460 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3461 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3463 if (info
->attrs
[NL80211_ATTR_IE
]) {
3464 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3465 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3468 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3469 if (!nl80211_valid_auth_type(auth_type
)) {
3474 err
= cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
3475 ssid
, ssid_len
, ie
, ie_len
,
3476 key
.p
.key
, key
.p
.key_len
, key
.idx
);
3479 cfg80211_unlock_rdev(rdev
);
3486 static int nl80211_crypto_settings(struct genl_info
*info
,
3487 struct cfg80211_crypto_settings
*settings
,
3490 memset(settings
, 0, sizeof(*settings
));
3492 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
3494 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
3498 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
3499 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
3500 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
3502 if (len
% sizeof(u32
))
3505 if (settings
->n_ciphers_pairwise
> cipher_limit
)
3508 memcpy(settings
->ciphers_pairwise
, data
, len
);
3510 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
3511 if (!nl80211_valid_cipher_suite(
3512 settings
->ciphers_pairwise
[i
]))
3516 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
3517 settings
->cipher_group
=
3518 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
3519 if (!nl80211_valid_cipher_suite(settings
->cipher_group
))
3523 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
3524 settings
->wpa_versions
=
3525 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
3526 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
3530 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
3534 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
3535 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
3536 settings
->n_akm_suites
= len
/ sizeof(u32
);
3538 if (len
% sizeof(u32
))
3541 memcpy(settings
->akm_suites
, data
, len
);
3543 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
3544 if (!nl80211_valid_akm_suite(settings
->akm_suites
[i
]))
3551 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
3553 struct cfg80211_registered_device
*rdev
;
3554 struct net_device
*dev
;
3555 struct wireless_dev
*wdev
;
3556 struct cfg80211_crypto_settings crypto
;
3557 struct ieee80211_channel
*chan
, *fixedchan
;
3558 const u8
*bssid
, *ssid
, *ie
= NULL
, *prev_bssid
= NULL
;
3559 int err
, ssid_len
, ie_len
= 0;
3560 bool use_mfp
= false;
3562 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3565 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
3566 !info
->attrs
[NL80211_ATTR_SSID
] ||
3567 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
3572 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3576 if (!rdev
->ops
->assoc
) {
3581 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3586 if (!netif_running(dev
)) {
3591 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3593 chan
= ieee80211_get_channel(&rdev
->wiphy
,
3594 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3595 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
)) {
3600 mutex_lock(&rdev
->devlist_mtx
);
3601 wdev
= dev
->ieee80211_ptr
;
3602 fixedchan
= rdev_fixed_channel(rdev
, wdev
);
3603 if (fixedchan
&& chan
!= fixedchan
) {
3605 mutex_unlock(&rdev
->devlist_mtx
);
3608 mutex_unlock(&rdev
->devlist_mtx
);
3610 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3611 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3613 if (info
->attrs
[NL80211_ATTR_IE
]) {
3614 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3615 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3618 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
3619 enum nl80211_mfp mfp
=
3620 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
3621 if (mfp
== NL80211_MFP_REQUIRED
)
3623 else if (mfp
!= NL80211_MFP_NO
) {
3629 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
3630 prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
3632 err
= nl80211_crypto_settings(info
, &crypto
, 1);
3634 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
, prev_bssid
,
3635 ssid
, ssid_len
, ie
, ie_len
, use_mfp
,
3639 cfg80211_unlock_rdev(rdev
);
3646 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3648 struct cfg80211_registered_device
*rdev
;
3649 struct net_device
*dev
;
3650 const u8
*ie
= NULL
, *bssid
;
3651 int err
, ie_len
= 0;
3654 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3657 if (!info
->attrs
[NL80211_ATTR_MAC
])
3660 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3665 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3669 if (!rdev
->ops
->deauth
) {
3674 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3679 if (!netif_running(dev
)) {
3684 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3686 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3687 if (reason_code
== 0) {
3688 /* Reason Code 0 is reserved */
3693 if (info
->attrs
[NL80211_ATTR_IE
]) {
3694 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3695 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3698 err
= cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
);
3701 cfg80211_unlock_rdev(rdev
);
3708 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
3710 struct cfg80211_registered_device
*rdev
;
3711 struct net_device
*dev
;
3712 const u8
*ie
= NULL
, *bssid
;
3713 int err
, ie_len
= 0;
3716 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3719 if (!info
->attrs
[NL80211_ATTR_MAC
])
3722 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3727 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3731 if (!rdev
->ops
->disassoc
) {
3736 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
3741 if (!netif_running(dev
)) {
3746 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3748 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3749 if (reason_code
== 0) {
3750 /* Reason Code 0 is reserved */
3755 if (info
->attrs
[NL80211_ATTR_IE
]) {
3756 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3757 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3760 err
= cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
);
3763 cfg80211_unlock_rdev(rdev
);
3770 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
3772 struct cfg80211_registered_device
*rdev
;
3773 struct net_device
*dev
;
3774 struct cfg80211_ibss_params ibss
;
3775 struct wiphy
*wiphy
;
3776 struct cfg80211_cached_keys
*connkeys
= NULL
;
3779 memset(&ibss
, 0, sizeof(ibss
));
3781 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3784 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
3785 !info
->attrs
[NL80211_ATTR_SSID
] ||
3786 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
3789 ibss
.beacon_interval
= 100;
3791 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
3792 ibss
.beacon_interval
=
3793 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3794 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
3800 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3804 if (!rdev
->ops
->join_ibss
) {
3809 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
3814 if (!netif_running(dev
)) {
3819 wiphy
= &rdev
->wiphy
;
3821 if (info
->attrs
[NL80211_ATTR_MAC
])
3822 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3823 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3824 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3826 if (info
->attrs
[NL80211_ATTR_IE
]) {
3827 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3828 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3831 ibss
.channel
= ieee80211_get_channel(wiphy
,
3832 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3833 if (!ibss
.channel
||
3834 ibss
.channel
->flags
& IEEE80211_CHAN_NO_IBSS
||
3835 ibss
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
3840 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
3841 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3843 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
3844 connkeys
= nl80211_parse_connkeys(rdev
,
3845 info
->attrs
[NL80211_ATTR_KEYS
]);
3846 if (IS_ERR(connkeys
)) {
3847 err
= PTR_ERR(connkeys
);
3853 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
3856 cfg80211_unlock_rdev(rdev
);
3865 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
3867 struct cfg80211_registered_device
*rdev
;
3868 struct net_device
*dev
;
3873 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
3877 if (!rdev
->ops
->leave_ibss
) {
3882 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
) {
3887 if (!netif_running(dev
)) {
3892 err
= cfg80211_leave_ibss(rdev
, dev
, false);
3895 cfg80211_unlock_rdev(rdev
);
3902 #ifdef CONFIG_NL80211_TESTMODE
3903 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
3907 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
3909 struct cfg80211_registered_device
*rdev
;
3912 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
3917 rdev
= cfg80211_get_dev_from_info(info
);
3919 err
= PTR_ERR(rdev
);
3924 if (rdev
->ops
->testmode_cmd
) {
3925 rdev
->testmode_info
= info
;
3926 err
= rdev
->ops
->testmode_cmd(&rdev
->wiphy
,
3927 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
3928 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
3929 rdev
->testmode_info
= NULL
;
3932 cfg80211_unlock_rdev(rdev
);
3939 static struct sk_buff
*
3940 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
3941 int approxlen
, u32 pid
, u32 seq
, gfp_t gfp
)
3943 struct sk_buff
*skb
;
3945 struct nlattr
*data
;
3947 skb
= nlmsg_new(approxlen
+ 100, gfp
);
3951 hdr
= nl80211hdr_put(skb
, pid
, seq
, 0, NL80211_CMD_TESTMODE
);
3957 NLA_PUT_U32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
3958 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
3960 ((void **)skb
->cb
)[0] = rdev
;
3961 ((void **)skb
->cb
)[1] = hdr
;
3962 ((void **)skb
->cb
)[2] = data
;
3971 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
3974 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
3976 if (WARN_ON(!rdev
->testmode_info
))
3979 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
3980 rdev
->testmode_info
->snd_pid
,
3981 rdev
->testmode_info
->snd_seq
,
3984 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
3986 int cfg80211_testmode_reply(struct sk_buff
*skb
)
3988 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
3989 void *hdr
= ((void **)skb
->cb
)[1];
3990 struct nlattr
*data
= ((void **)skb
->cb
)[2];
3992 if (WARN_ON(!rdev
->testmode_info
)) {
3997 nla_nest_end(skb
, data
);
3998 genlmsg_end(skb
, hdr
);
3999 return genlmsg_reply(skb
, rdev
->testmode_info
);
4001 EXPORT_SYMBOL(cfg80211_testmode_reply
);
4003 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
4004 int approxlen
, gfp_t gfp
)
4006 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4008 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
4010 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
4012 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
4014 void *hdr
= ((void **)skb
->cb
)[1];
4015 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4017 nla_nest_end(skb
, data
);
4018 genlmsg_end(skb
, hdr
);
4019 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
4021 EXPORT_SYMBOL(cfg80211_testmode_event
);
4024 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
4026 struct cfg80211_registered_device
*rdev
;
4027 struct net_device
*dev
;
4028 struct cfg80211_connect_params connect
;
4029 struct wiphy
*wiphy
;
4030 struct cfg80211_cached_keys
*connkeys
= NULL
;
4033 memset(&connect
, 0, sizeof(connect
));
4035 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4038 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
4039 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
4042 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
4044 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4045 if (!nl80211_valid_auth_type(connect
.auth_type
))
4048 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
4050 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
4052 err
= nl80211_crypto_settings(info
, &connect
.crypto
,
4053 NL80211_MAX_NR_CIPHER_SUITES
);
4058 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4062 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4067 if (!netif_running(dev
)) {
4072 wiphy
= &rdev
->wiphy
;
4074 if (info
->attrs
[NL80211_ATTR_MAC
])
4075 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4076 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4077 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4079 if (info
->attrs
[NL80211_ATTR_IE
]) {
4080 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4081 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4084 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
4086 ieee80211_get_channel(wiphy
,
4087 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4088 if (!connect
.channel
||
4089 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
) {
4095 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
4096 connkeys
= nl80211_parse_connkeys(rdev
,
4097 info
->attrs
[NL80211_ATTR_KEYS
]);
4098 if (IS_ERR(connkeys
)) {
4099 err
= PTR_ERR(connkeys
);
4105 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
4108 cfg80211_unlock_rdev(rdev
);
4117 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
4119 struct cfg80211_registered_device
*rdev
;
4120 struct net_device
*dev
;
4124 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4125 reason
= WLAN_REASON_DEAUTH_LEAVING
;
4127 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4134 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4138 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4143 if (!netif_running(dev
)) {
4148 err
= cfg80211_disconnect(rdev
, dev
, reason
, true);
4151 cfg80211_unlock_rdev(rdev
);
4158 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
4160 struct cfg80211_registered_device
*rdev
;
4165 if (!info
->attrs
[NL80211_ATTR_PID
])
4168 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
4172 rdev
= cfg80211_get_dev_from_info(info
);
4174 err
= PTR_ERR(rdev
);
4178 net
= get_net_ns_by_pid(pid
);
4186 /* check if anything to do */
4187 if (net_eq(wiphy_net(&rdev
->wiphy
), net
))
4190 err
= cfg80211_switch_netns(rdev
, net
);
4194 cfg80211_unlock_rdev(rdev
);
4200 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4202 struct cfg80211_registered_device
*rdev
;
4203 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
4204 struct cfg80211_pmksa
*pmksa
) = NULL
;
4206 struct net_device
*dev
;
4207 struct cfg80211_pmksa pmksa
;
4209 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
4211 if (!info
->attrs
[NL80211_ATTR_MAC
])
4214 if (!info
->attrs
[NL80211_ATTR_PMKID
])
4219 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4223 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
4224 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4226 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4231 switch (info
->genlhdr
->cmd
) {
4232 case NL80211_CMD_SET_PMKSA
:
4233 rdev_ops
= rdev
->ops
->set_pmksa
;
4235 case NL80211_CMD_DEL_PMKSA
:
4236 rdev_ops
= rdev
->ops
->del_pmksa
;
4248 err
= rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
4251 cfg80211_unlock_rdev(rdev
);
4259 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4261 struct cfg80211_registered_device
*rdev
;
4263 struct net_device
*dev
;
4267 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4271 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4276 if (!rdev
->ops
->flush_pmksa
) {
4281 err
= rdev
->ops
->flush_pmksa(&rdev
->wiphy
, dev
);
4284 cfg80211_unlock_rdev(rdev
);
4293 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
4294 struct genl_info
*info
)
4296 struct cfg80211_registered_device
*rdev
;
4297 struct net_device
*dev
;
4298 struct ieee80211_channel
*chan
;
4299 struct sk_buff
*msg
;
4302 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
4306 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
4307 !info
->attrs
[NL80211_ATTR_DURATION
])
4310 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
4313 * We should be on that channel for at least one jiffie,
4314 * and more than 5 seconds seems excessive.
4316 if (!duration
|| !msecs_to_jiffies(duration
) || duration
> 5000)
4321 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4325 if (!rdev
->ops
->remain_on_channel
) {
4330 if (!netif_running(dev
)) {
4335 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
4336 channel_type
= nla_get_u32(
4337 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
4338 if (channel_type
!= NL80211_CHAN_NO_HT
&&
4339 channel_type
!= NL80211_CHAN_HT20
&&
4340 channel_type
!= NL80211_CHAN_HT40PLUS
&&
4341 channel_type
!= NL80211_CHAN_HT40MINUS
)
4346 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
4347 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
4353 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4359 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4360 NL80211_CMD_REMAIN_ON_CHANNEL
);
4367 err
= rdev
->ops
->remain_on_channel(&rdev
->wiphy
, dev
, chan
,
4368 channel_type
, duration
, &cookie
);
4373 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
4375 genlmsg_end(msg
, hdr
);
4376 err
= genlmsg_reply(msg
, info
);
4384 cfg80211_unlock_rdev(rdev
);
4391 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
4392 struct genl_info
*info
)
4394 struct cfg80211_registered_device
*rdev
;
4395 struct net_device
*dev
;
4399 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
4404 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4408 if (!rdev
->ops
->cancel_remain_on_channel
) {
4413 if (!netif_running(dev
)) {
4418 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
4420 err
= rdev
->ops
->cancel_remain_on_channel(&rdev
->wiphy
, dev
, cookie
);
4423 cfg80211_unlock_rdev(rdev
);
4430 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
4431 u8
*rates
, u8 rates_len
)
4436 for (i
= 0; i
< rates_len
; i
++) {
4437 int rate
= (rates
[i
] & 0x7f) * 5;
4439 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
4440 struct ieee80211_rate
*srate
=
4441 &sband
->bitrates
[ridx
];
4442 if (rate
== srate
->bitrate
) {
4447 if (ridx
== sband
->n_bitrates
)
4448 return 0; /* rate not found */
4454 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
4455 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
4456 .len
= NL80211_MAX_SUPP_RATES
},
4459 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
4460 struct genl_info
*info
)
4462 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
4463 struct cfg80211_registered_device
*rdev
;
4464 struct cfg80211_bitrate_mask mask
;
4466 struct net_device
*dev
;
4467 struct nlattr
*tx_rates
;
4468 struct ieee80211_supported_band
*sband
;
4470 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
4475 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4479 if (!rdev
->ops
->set_bitrate_mask
) {
4484 memset(&mask
, 0, sizeof(mask
));
4485 /* Default to all rates enabled */
4486 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
4487 sband
= rdev
->wiphy
.bands
[i
];
4488 mask
.control
[i
].legacy
=
4489 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
4493 * The nested attribute uses enum nl80211_band as the index. This maps
4494 * directly to the enum ieee80211_band values used in cfg80211.
4496 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
4498 enum ieee80211_band band
= nla_type(tx_rates
);
4499 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
4503 sband
= rdev
->wiphy
.bands
[band
];
4504 if (sband
== NULL
) {
4508 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
4509 nla_len(tx_rates
), nl80211_txattr_policy
);
4510 if (tb
[NL80211_TXRATE_LEGACY
]) {
4511 mask
.control
[band
].legacy
= rateset_to_mask(
4513 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
4514 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
4515 if (mask
.control
[band
].legacy
== 0) {
4522 err
= rdev
->ops
->set_bitrate_mask(&rdev
->wiphy
, dev
, NULL
, &mask
);
4526 cfg80211_unlock_rdev(rdev
);
4532 static int nl80211_register_action(struct sk_buff
*skb
, struct genl_info
*info
)
4534 struct cfg80211_registered_device
*rdev
;
4535 struct net_device
*dev
;
4538 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
4541 if (nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]) < 1)
4546 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4550 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4555 /* not much point in registering if we can't reply */
4556 if (!rdev
->ops
->action
) {
4561 err
= cfg80211_mlme_register_action(dev
->ieee80211_ptr
, info
->snd_pid
,
4562 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
4563 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
4565 cfg80211_unlock_rdev(rdev
);
4572 static int nl80211_action(struct sk_buff
*skb
, struct genl_info
*info
)
4574 struct cfg80211_registered_device
*rdev
;
4575 struct net_device
*dev
;
4576 struct ieee80211_channel
*chan
;
4577 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
4582 struct sk_buff
*msg
;
4584 if (!info
->attrs
[NL80211_ATTR_FRAME
] ||
4585 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4590 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4594 if (!rdev
->ops
->action
) {
4599 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
) {
4604 if (!netif_running(dev
)) {
4609 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
4610 channel_type
= nla_get_u32(
4611 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
4612 if (channel_type
!= NL80211_CHAN_NO_HT
&&
4613 channel_type
!= NL80211_CHAN_HT20
&&
4614 channel_type
!= NL80211_CHAN_HT40PLUS
&&
4615 channel_type
!= NL80211_CHAN_HT40MINUS
)
4620 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
4621 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
4627 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4633 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4634 NL80211_CMD_ACTION
);
4640 err
= cfg80211_mlme_action(rdev
, dev
, chan
, channel_type
,
4641 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
4642 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
4647 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
4649 genlmsg_end(msg
, hdr
);
4650 err
= genlmsg_reply(msg
, info
);
4658 cfg80211_unlock_rdev(rdev
);
4665 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
4667 struct cfg80211_registered_device
*rdev
;
4668 struct wireless_dev
*wdev
;
4669 struct net_device
*dev
;
4674 if (!info
->attrs
[NL80211_ATTR_PS_STATE
]) {
4679 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
4681 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
) {
4688 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4692 wdev
= dev
->ieee80211_ptr
;
4694 if (!rdev
->ops
->set_power_mgmt
) {
4699 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
4701 if (state
== wdev
->ps
)
4706 if (rdev
->ops
->set_power_mgmt(wdev
->wiphy
, dev
, wdev
->ps
,
4708 /* assume this means it's off */
4712 cfg80211_unlock_rdev(rdev
);
4720 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
4722 struct cfg80211_registered_device
*rdev
;
4723 enum nl80211_ps_state ps_state
;
4724 struct wireless_dev
*wdev
;
4725 struct net_device
*dev
;
4726 struct sk_buff
*msg
;
4732 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4736 wdev
= dev
->ieee80211_ptr
;
4738 if (!rdev
->ops
->set_power_mgmt
) {
4743 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4749 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4750 NL80211_CMD_GET_POWER_SAVE
);
4757 ps_state
= NL80211_PS_ENABLED
;
4759 ps_state
= NL80211_PS_DISABLED
;
4761 NLA_PUT_U32(msg
, NL80211_ATTR_PS_STATE
, ps_state
);
4763 genlmsg_end(msg
, hdr
);
4764 err
= genlmsg_reply(msg
, info
);
4774 cfg80211_unlock_rdev(rdev
);
4783 static struct nla_policy
4784 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
4785 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
4786 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
4787 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
4790 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
4791 s32 threshold
, u32 hysteresis
)
4793 struct cfg80211_registered_device
*rdev
;
4794 struct wireless_dev
*wdev
;
4795 struct net_device
*dev
;
4803 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4807 wdev
= dev
->ieee80211_ptr
;
4809 if (!rdev
->ops
->set_cqm_rssi_config
) {
4814 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
) {
4819 err
= rdev
->ops
->set_cqm_rssi_config(wdev
->wiphy
, dev
,
4820 threshold
, hysteresis
);
4823 cfg80211_unlock_rdev(rdev
);
4830 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
4832 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
4836 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
4842 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
4843 nl80211_attr_cqm_policy
);
4847 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
4848 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
4851 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
4852 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
4853 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
4861 static struct genl_ops nl80211_ops
[] = {
4863 .cmd
= NL80211_CMD_GET_WIPHY
,
4864 .doit
= nl80211_get_wiphy
,
4865 .dumpit
= nl80211_dump_wiphy
,
4866 .policy
= nl80211_policy
,
4867 /* can be retrieved by unprivileged users */
4870 .cmd
= NL80211_CMD_SET_WIPHY
,
4871 .doit
= nl80211_set_wiphy
,
4872 .policy
= nl80211_policy
,
4873 .flags
= GENL_ADMIN_PERM
,
4876 .cmd
= NL80211_CMD_GET_INTERFACE
,
4877 .doit
= nl80211_get_interface
,
4878 .dumpit
= nl80211_dump_interface
,
4879 .policy
= nl80211_policy
,
4880 /* can be retrieved by unprivileged users */
4883 .cmd
= NL80211_CMD_SET_INTERFACE
,
4884 .doit
= nl80211_set_interface
,
4885 .policy
= nl80211_policy
,
4886 .flags
= GENL_ADMIN_PERM
,
4889 .cmd
= NL80211_CMD_NEW_INTERFACE
,
4890 .doit
= nl80211_new_interface
,
4891 .policy
= nl80211_policy
,
4892 .flags
= GENL_ADMIN_PERM
,
4895 .cmd
= NL80211_CMD_DEL_INTERFACE
,
4896 .doit
= nl80211_del_interface
,
4897 .policy
= nl80211_policy
,
4898 .flags
= GENL_ADMIN_PERM
,
4901 .cmd
= NL80211_CMD_GET_KEY
,
4902 .doit
= nl80211_get_key
,
4903 .policy
= nl80211_policy
,
4904 .flags
= GENL_ADMIN_PERM
,
4907 .cmd
= NL80211_CMD_SET_KEY
,
4908 .doit
= nl80211_set_key
,
4909 .policy
= nl80211_policy
,
4910 .flags
= GENL_ADMIN_PERM
,
4913 .cmd
= NL80211_CMD_NEW_KEY
,
4914 .doit
= nl80211_new_key
,
4915 .policy
= nl80211_policy
,
4916 .flags
= GENL_ADMIN_PERM
,
4919 .cmd
= NL80211_CMD_DEL_KEY
,
4920 .doit
= nl80211_del_key
,
4921 .policy
= nl80211_policy
,
4922 .flags
= GENL_ADMIN_PERM
,
4925 .cmd
= NL80211_CMD_SET_BEACON
,
4926 .policy
= nl80211_policy
,
4927 .flags
= GENL_ADMIN_PERM
,
4928 .doit
= nl80211_addset_beacon
,
4931 .cmd
= NL80211_CMD_NEW_BEACON
,
4932 .policy
= nl80211_policy
,
4933 .flags
= GENL_ADMIN_PERM
,
4934 .doit
= nl80211_addset_beacon
,
4937 .cmd
= NL80211_CMD_DEL_BEACON
,
4938 .policy
= nl80211_policy
,
4939 .flags
= GENL_ADMIN_PERM
,
4940 .doit
= nl80211_del_beacon
,
4943 .cmd
= NL80211_CMD_GET_STATION
,
4944 .doit
= nl80211_get_station
,
4945 .dumpit
= nl80211_dump_station
,
4946 .policy
= nl80211_policy
,
4949 .cmd
= NL80211_CMD_SET_STATION
,
4950 .doit
= nl80211_set_station
,
4951 .policy
= nl80211_policy
,
4952 .flags
= GENL_ADMIN_PERM
,
4955 .cmd
= NL80211_CMD_NEW_STATION
,
4956 .doit
= nl80211_new_station
,
4957 .policy
= nl80211_policy
,
4958 .flags
= GENL_ADMIN_PERM
,
4961 .cmd
= NL80211_CMD_DEL_STATION
,
4962 .doit
= nl80211_del_station
,
4963 .policy
= nl80211_policy
,
4964 .flags
= GENL_ADMIN_PERM
,
4967 .cmd
= NL80211_CMD_GET_MPATH
,
4968 .doit
= nl80211_get_mpath
,
4969 .dumpit
= nl80211_dump_mpath
,
4970 .policy
= nl80211_policy
,
4971 .flags
= GENL_ADMIN_PERM
,
4974 .cmd
= NL80211_CMD_SET_MPATH
,
4975 .doit
= nl80211_set_mpath
,
4976 .policy
= nl80211_policy
,
4977 .flags
= GENL_ADMIN_PERM
,
4980 .cmd
= NL80211_CMD_NEW_MPATH
,
4981 .doit
= nl80211_new_mpath
,
4982 .policy
= nl80211_policy
,
4983 .flags
= GENL_ADMIN_PERM
,
4986 .cmd
= NL80211_CMD_DEL_MPATH
,
4987 .doit
= nl80211_del_mpath
,
4988 .policy
= nl80211_policy
,
4989 .flags
= GENL_ADMIN_PERM
,
4992 .cmd
= NL80211_CMD_SET_BSS
,
4993 .doit
= nl80211_set_bss
,
4994 .policy
= nl80211_policy
,
4995 .flags
= GENL_ADMIN_PERM
,
4998 .cmd
= NL80211_CMD_GET_REG
,
4999 .doit
= nl80211_get_reg
,
5000 .policy
= nl80211_policy
,
5001 /* can be retrieved by unprivileged users */
5004 .cmd
= NL80211_CMD_SET_REG
,
5005 .doit
= nl80211_set_reg
,
5006 .policy
= nl80211_policy
,
5007 .flags
= GENL_ADMIN_PERM
,
5010 .cmd
= NL80211_CMD_REQ_SET_REG
,
5011 .doit
= nl80211_req_set_reg
,
5012 .policy
= nl80211_policy
,
5013 .flags
= GENL_ADMIN_PERM
,
5016 .cmd
= NL80211_CMD_GET_MESH_PARAMS
,
5017 .doit
= nl80211_get_mesh_params
,
5018 .policy
= nl80211_policy
,
5019 /* can be retrieved by unprivileged users */
5022 .cmd
= NL80211_CMD_SET_MESH_PARAMS
,
5023 .doit
= nl80211_set_mesh_params
,
5024 .policy
= nl80211_policy
,
5025 .flags
= GENL_ADMIN_PERM
,
5028 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
5029 .doit
= nl80211_trigger_scan
,
5030 .policy
= nl80211_policy
,
5031 .flags
= GENL_ADMIN_PERM
,
5034 .cmd
= NL80211_CMD_GET_SCAN
,
5035 .policy
= nl80211_policy
,
5036 .dumpit
= nl80211_dump_scan
,
5039 .cmd
= NL80211_CMD_AUTHENTICATE
,
5040 .doit
= nl80211_authenticate
,
5041 .policy
= nl80211_policy
,
5042 .flags
= GENL_ADMIN_PERM
,
5045 .cmd
= NL80211_CMD_ASSOCIATE
,
5046 .doit
= nl80211_associate
,
5047 .policy
= nl80211_policy
,
5048 .flags
= GENL_ADMIN_PERM
,
5051 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
5052 .doit
= nl80211_deauthenticate
,
5053 .policy
= nl80211_policy
,
5054 .flags
= GENL_ADMIN_PERM
,
5057 .cmd
= NL80211_CMD_DISASSOCIATE
,
5058 .doit
= nl80211_disassociate
,
5059 .policy
= nl80211_policy
,
5060 .flags
= GENL_ADMIN_PERM
,
5063 .cmd
= NL80211_CMD_JOIN_IBSS
,
5064 .doit
= nl80211_join_ibss
,
5065 .policy
= nl80211_policy
,
5066 .flags
= GENL_ADMIN_PERM
,
5069 .cmd
= NL80211_CMD_LEAVE_IBSS
,
5070 .doit
= nl80211_leave_ibss
,
5071 .policy
= nl80211_policy
,
5072 .flags
= GENL_ADMIN_PERM
,
5074 #ifdef CONFIG_NL80211_TESTMODE
5076 .cmd
= NL80211_CMD_TESTMODE
,
5077 .doit
= nl80211_testmode_do
,
5078 .policy
= nl80211_policy
,
5079 .flags
= GENL_ADMIN_PERM
,
5083 .cmd
= NL80211_CMD_CONNECT
,
5084 .doit
= nl80211_connect
,
5085 .policy
= nl80211_policy
,
5086 .flags
= GENL_ADMIN_PERM
,
5089 .cmd
= NL80211_CMD_DISCONNECT
,
5090 .doit
= nl80211_disconnect
,
5091 .policy
= nl80211_policy
,
5092 .flags
= GENL_ADMIN_PERM
,
5095 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
5096 .doit
= nl80211_wiphy_netns
,
5097 .policy
= nl80211_policy
,
5098 .flags
= GENL_ADMIN_PERM
,
5101 .cmd
= NL80211_CMD_GET_SURVEY
,
5102 .policy
= nl80211_policy
,
5103 .dumpit
= nl80211_dump_survey
,
5106 .cmd
= NL80211_CMD_SET_PMKSA
,
5107 .doit
= nl80211_setdel_pmksa
,
5108 .policy
= nl80211_policy
,
5109 .flags
= GENL_ADMIN_PERM
,
5112 .cmd
= NL80211_CMD_DEL_PMKSA
,
5113 .doit
= nl80211_setdel_pmksa
,
5114 .policy
= nl80211_policy
,
5115 .flags
= GENL_ADMIN_PERM
,
5118 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
5119 .doit
= nl80211_flush_pmksa
,
5120 .policy
= nl80211_policy
,
5121 .flags
= GENL_ADMIN_PERM
,
5124 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
5125 .doit
= nl80211_remain_on_channel
,
5126 .policy
= nl80211_policy
,
5127 .flags
= GENL_ADMIN_PERM
,
5130 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
5131 .doit
= nl80211_cancel_remain_on_channel
,
5132 .policy
= nl80211_policy
,
5133 .flags
= GENL_ADMIN_PERM
,
5136 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
5137 .doit
= nl80211_set_tx_bitrate_mask
,
5138 .policy
= nl80211_policy
,
5139 .flags
= GENL_ADMIN_PERM
,
5142 .cmd
= NL80211_CMD_REGISTER_ACTION
,
5143 .doit
= nl80211_register_action
,
5144 .policy
= nl80211_policy
,
5145 .flags
= GENL_ADMIN_PERM
,
5148 .cmd
= NL80211_CMD_ACTION
,
5149 .doit
= nl80211_action
,
5150 .policy
= nl80211_policy
,
5151 .flags
= GENL_ADMIN_PERM
,
5154 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
5155 .doit
= nl80211_set_power_save
,
5156 .policy
= nl80211_policy
,
5157 .flags
= GENL_ADMIN_PERM
,
5160 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
5161 .doit
= nl80211_get_power_save
,
5162 .policy
= nl80211_policy
,
5163 /* can be retrieved by unprivileged users */
5166 .cmd
= NL80211_CMD_SET_CQM
,
5167 .doit
= nl80211_set_cqm
,
5168 .policy
= nl80211_policy
,
5169 .flags
= GENL_ADMIN_PERM
,
5173 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
5177 /* multicast groups */
5178 static struct genl_multicast_group nl80211_config_mcgrp
= {
5181 static struct genl_multicast_group nl80211_scan_mcgrp
= {
5184 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
5185 .name
= "regulatory",
5188 /* notification functions */
5190 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
5192 struct sk_buff
*msg
;
5194 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5198 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
5203 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5204 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
5207 static int nl80211_add_scan_req(struct sk_buff
*msg
,
5208 struct cfg80211_registered_device
*rdev
)
5210 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
5211 struct nlattr
*nest
;
5214 ASSERT_RDEV_LOCK(rdev
);
5219 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
5221 goto nla_put_failure
;
5222 for (i
= 0; i
< req
->n_ssids
; i
++)
5223 NLA_PUT(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
);
5224 nla_nest_end(msg
, nest
);
5226 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
5228 goto nla_put_failure
;
5229 for (i
= 0; i
< req
->n_channels
; i
++)
5230 NLA_PUT_U32(msg
, i
, req
->channels
[i
]->center_freq
);
5231 nla_nest_end(msg
, nest
);
5234 NLA_PUT(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
);
5241 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
5242 struct cfg80211_registered_device
*rdev
,
5243 struct net_device
*netdev
,
5244 u32 pid
, u32 seq
, int flags
,
5249 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
5253 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5254 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5256 /* ignore errors and send incomplete event anyway */
5257 nl80211_add_scan_req(msg
, rdev
);
5259 return genlmsg_end(msg
, hdr
);
5262 genlmsg_cancel(msg
, hdr
);
5266 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
5267 struct net_device
*netdev
)
5269 struct sk_buff
*msg
;
5271 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
5275 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5276 NL80211_CMD_TRIGGER_SCAN
) < 0) {
5281 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5282 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5285 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
5286 struct net_device
*netdev
)
5288 struct sk_buff
*msg
;
5290 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5294 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5295 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
5300 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5301 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5304 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
5305 struct net_device
*netdev
)
5307 struct sk_buff
*msg
;
5309 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5313 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5314 NL80211_CMD_SCAN_ABORTED
) < 0) {
5319 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5320 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5324 * This can happen on global regulatory changes or device specific settings
5325 * based on custom world regulatory domains.
5327 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
5329 struct sk_buff
*msg
;
5332 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5336 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
5342 /* Userspace can always count this one always being set */
5343 NLA_PUT_U8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
);
5345 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0')
5346 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5347 NL80211_REGDOM_TYPE_WORLD
);
5348 else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9')
5349 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5350 NL80211_REGDOM_TYPE_CUSTOM_WORLD
);
5351 else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
5353 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5354 NL80211_REGDOM_TYPE_INTERSECTION
);
5356 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5357 NL80211_REGDOM_TYPE_COUNTRY
);
5358 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, request
->alpha2
);
5361 if (wiphy_idx_valid(request
->wiphy_idx
))
5362 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
);
5364 if (genlmsg_end(msg
, hdr
) < 0) {
5370 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
5377 genlmsg_cancel(msg
, hdr
);
5381 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
5382 struct net_device
*netdev
,
5383 const u8
*buf
, size_t len
,
5384 enum nl80211_commands cmd
, gfp_t gfp
)
5386 struct sk_buff
*msg
;
5389 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5393 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
5399 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5400 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5401 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
5403 if (genlmsg_end(msg
, hdr
) < 0) {
5408 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5409 nl80211_mlme_mcgrp
.id
, gfp
);
5413 genlmsg_cancel(msg
, hdr
);
5417 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
5418 struct net_device
*netdev
, const u8
*buf
,
5419 size_t len
, gfp_t gfp
)
5421 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5422 NL80211_CMD_AUTHENTICATE
, gfp
);
5425 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
5426 struct net_device
*netdev
, const u8
*buf
,
5427 size_t len
, gfp_t gfp
)
5429 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5430 NL80211_CMD_ASSOCIATE
, gfp
);
5433 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
5434 struct net_device
*netdev
, const u8
*buf
,
5435 size_t len
, gfp_t gfp
)
5437 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5438 NL80211_CMD_DEAUTHENTICATE
, gfp
);
5441 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
5442 struct net_device
*netdev
, const u8
*buf
,
5443 size_t len
, gfp_t gfp
)
5445 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5446 NL80211_CMD_DISASSOCIATE
, gfp
);
5449 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
5450 struct net_device
*netdev
, int cmd
,
5451 const u8
*addr
, gfp_t gfp
)
5453 struct sk_buff
*msg
;
5456 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5460 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
5466 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5467 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5468 NLA_PUT_FLAG(msg
, NL80211_ATTR_TIMED_OUT
);
5469 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5471 if (genlmsg_end(msg
, hdr
) < 0) {
5476 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5477 nl80211_mlme_mcgrp
.id
, gfp
);
5481 genlmsg_cancel(msg
, hdr
);
5485 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
5486 struct net_device
*netdev
, const u8
*addr
,
5489 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
5493 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
5494 struct net_device
*netdev
, const u8
*addr
,
5497 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
5501 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
5502 struct net_device
*netdev
, const u8
*bssid
,
5503 const u8
*req_ie
, size_t req_ie_len
,
5504 const u8
*resp_ie
, size_t resp_ie_len
,
5505 u16 status
, gfp_t gfp
)
5507 struct sk_buff
*msg
;
5510 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
5514 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
5520 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5521 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5523 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
5524 NLA_PUT_U16(msg
, NL80211_ATTR_STATUS_CODE
, status
);
5526 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
5528 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
5530 if (genlmsg_end(msg
, hdr
) < 0) {
5535 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5536 nl80211_mlme_mcgrp
.id
, gfp
);
5540 genlmsg_cancel(msg
, hdr
);
5545 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
5546 struct net_device
*netdev
, const u8
*bssid
,
5547 const u8
*req_ie
, size_t req_ie_len
,
5548 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
5550 struct sk_buff
*msg
;
5553 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
5557 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
5563 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5564 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5565 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
5567 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
5569 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
5571 if (genlmsg_end(msg
, hdr
) < 0) {
5576 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5577 nl80211_mlme_mcgrp
.id
, gfp
);
5581 genlmsg_cancel(msg
, hdr
);
5586 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
5587 struct net_device
*netdev
, u16 reason
,
5588 const u8
*ie
, size_t ie_len
, bool from_ap
)
5590 struct sk_buff
*msg
;
5593 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
5597 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
5603 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5604 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5605 if (from_ap
&& reason
)
5606 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason
);
5608 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
);
5610 NLA_PUT(msg
, NL80211_ATTR_IE
, ie_len
, ie
);
5612 if (genlmsg_end(msg
, hdr
) < 0) {
5617 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5618 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
5622 genlmsg_cancel(msg
, hdr
);
5627 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
5628 struct net_device
*netdev
, const u8
*bssid
,
5631 struct sk_buff
*msg
;
5634 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5638 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
5644 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5645 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5646 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
5648 if (genlmsg_end(msg
, hdr
) < 0) {
5653 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5654 nl80211_mlme_mcgrp
.id
, gfp
);
5658 genlmsg_cancel(msg
, hdr
);
5662 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
5663 struct net_device
*netdev
, const u8
*addr
,
5664 enum nl80211_key_type key_type
, int key_id
,
5665 const u8
*tsc
, gfp_t gfp
)
5667 struct sk_buff
*msg
;
5670 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5674 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
5680 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5681 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5683 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5684 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
);
5685 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_id
);
5687 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
);
5689 if (genlmsg_end(msg
, hdr
) < 0) {
5694 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5695 nl80211_mlme_mcgrp
.id
, gfp
);
5699 genlmsg_cancel(msg
, hdr
);
5703 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
5704 struct ieee80211_channel
*channel_before
,
5705 struct ieee80211_channel
*channel_after
)
5707 struct sk_buff
*msg
;
5709 struct nlattr
*nl_freq
;
5711 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
5715 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
5722 * Since we are applying the beacon hint to a wiphy we know its
5723 * wiphy_idx is valid
5725 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
));
5728 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
5730 goto nla_put_failure
;
5731 if (nl80211_msg_put_channel(msg
, channel_before
))
5732 goto nla_put_failure
;
5733 nla_nest_end(msg
, nl_freq
);
5736 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
5738 goto nla_put_failure
;
5739 if (nl80211_msg_put_channel(msg
, channel_after
))
5740 goto nla_put_failure
;
5741 nla_nest_end(msg
, nl_freq
);
5743 if (genlmsg_end(msg
, hdr
) < 0) {
5749 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
5756 genlmsg_cancel(msg
, hdr
);
5760 static void nl80211_send_remain_on_chan_event(
5761 int cmd
, struct cfg80211_registered_device
*rdev
,
5762 struct net_device
*netdev
, u64 cookie
,
5763 struct ieee80211_channel
*chan
,
5764 enum nl80211_channel_type channel_type
,
5765 unsigned int duration
, gfp_t gfp
)
5767 struct sk_buff
*msg
;
5770 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5774 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
5780 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5781 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5782 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
);
5783 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, channel_type
);
5784 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
5786 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
)
5787 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, duration
);
5789 if (genlmsg_end(msg
, hdr
) < 0) {
5794 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5795 nl80211_mlme_mcgrp
.id
, gfp
);
5799 genlmsg_cancel(msg
, hdr
);
5803 void nl80211_send_remain_on_channel(struct cfg80211_registered_device
*rdev
,
5804 struct net_device
*netdev
, u64 cookie
,
5805 struct ieee80211_channel
*chan
,
5806 enum nl80211_channel_type channel_type
,
5807 unsigned int duration
, gfp_t gfp
)
5809 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
5810 rdev
, netdev
, cookie
, chan
,
5811 channel_type
, duration
, gfp
);
5814 void nl80211_send_remain_on_channel_cancel(
5815 struct cfg80211_registered_device
*rdev
, struct net_device
*netdev
,
5816 u64 cookie
, struct ieee80211_channel
*chan
,
5817 enum nl80211_channel_type channel_type
, gfp_t gfp
)
5819 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
5820 rdev
, netdev
, cookie
, chan
,
5821 channel_type
, 0, gfp
);
5824 void nl80211_send_sta_event(struct cfg80211_registered_device
*rdev
,
5825 struct net_device
*dev
, const u8
*mac_addr
,
5826 struct station_info
*sinfo
, gfp_t gfp
)
5828 struct sk_buff
*msg
;
5830 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
5834 if (nl80211_send_station(msg
, 0, 0, 0, dev
, mac_addr
, sinfo
) < 0) {
5839 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5840 nl80211_mlme_mcgrp
.id
, gfp
);
5843 int nl80211_send_action(struct cfg80211_registered_device
*rdev
,
5844 struct net_device
*netdev
, u32 nlpid
,
5845 int freq
, const u8
*buf
, size_t len
, gfp_t gfp
)
5847 struct sk_buff
*msg
;
5851 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5855 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ACTION
);
5861 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5862 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5863 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
5864 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
5866 err
= genlmsg_end(msg
, hdr
);
5872 err
= genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
5878 genlmsg_cancel(msg
, hdr
);
5883 void nl80211_send_action_tx_status(struct cfg80211_registered_device
*rdev
,
5884 struct net_device
*netdev
, u64 cookie
,
5885 const u8
*buf
, size_t len
, bool ack
,
5888 struct sk_buff
*msg
;
5891 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5895 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ACTION_TX_STATUS
);
5901 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5902 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5903 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
5904 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
5906 NLA_PUT_FLAG(msg
, NL80211_ATTR_ACK
);
5908 if (genlmsg_end(msg
, hdr
) < 0) {
5913 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
5917 genlmsg_cancel(msg
, hdr
);
5922 nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device
*rdev
,
5923 struct net_device
*netdev
,
5924 enum nl80211_cqm_rssi_threshold_event rssi_event
,
5927 struct sk_buff
*msg
;
5928 struct nlattr
*pinfoattr
;
5931 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
5935 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
5941 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5942 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5944 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
5946 goto nla_put_failure
;
5948 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
5951 nla_nest_end(msg
, pinfoattr
);
5953 if (genlmsg_end(msg
, hdr
) < 0) {
5958 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5959 nl80211_mlme_mcgrp
.id
, gfp
);
5963 genlmsg_cancel(msg
, hdr
);
5967 static int nl80211_netlink_notify(struct notifier_block
* nb
,
5968 unsigned long state
,
5971 struct netlink_notify
*notify
= _notify
;
5972 struct cfg80211_registered_device
*rdev
;
5973 struct wireless_dev
*wdev
;
5975 if (state
!= NETLINK_URELEASE
)
5980 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
)
5981 list_for_each_entry_rcu(wdev
, &rdev
->netdev_list
, list
)
5982 cfg80211_mlme_unregister_actions(wdev
, notify
->pid
);
5989 static struct notifier_block nl80211_netlink_notifier
= {
5990 .notifier_call
= nl80211_netlink_notify
,
5993 /* initialisation/exit functions */
5995 int nl80211_init(void)
5999 err
= genl_register_family_with_ops(&nl80211_fam
,
6000 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
6004 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
6008 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
6012 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
6016 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
6020 #ifdef CONFIG_NL80211_TESTMODE
6021 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
6026 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
6032 genl_unregister_family(&nl80211_fam
);
6036 void nl80211_exit(void)
6038 netlink_unregister_notifier(&nl80211_netlink_notifier
);
6039 genl_unregister_family(&nl80211_fam
);