2 * This is the new netlink-based wireless configuration interface.
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
8 #include <linux/module.h>
10 #include <linux/slab.h>
11 #include <linux/list.h>
12 #include <linux/if_ether.h>
13 #include <linux/ieee80211.h>
14 #include <linux/nl80211.h>
15 #include <linux/rtnetlink.h>
16 #include <linux/netlink.h>
17 #include <linux/etherdevice.h>
18 #include <net/net_namespace.h>
19 #include <net/genetlink.h>
20 #include <net/cfg80211.h>
26 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
27 struct genl_info
*info
);
28 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
29 struct genl_info
*info
);
31 /* the netlink family */
32 static struct genl_family nl80211_fam
= {
33 .id
= GENL_ID_GENERATE
, /* don't bother with a hardcoded ID */
34 .name
= "nl80211", /* have users key off the name instead */
35 .hdrsize
= 0, /* no private header */
36 .version
= 1, /* no particular meaning now */
37 .maxattr
= NL80211_ATTR_MAX
,
39 .pre_doit
= nl80211_pre_doit
,
40 .post_doit
= nl80211_post_doit
,
43 /* internal helper: get rdev and dev */
44 static int get_rdev_dev_by_info_ifindex(struct genl_info
*info
,
45 struct cfg80211_registered_device
**rdev
,
46 struct net_device
**dev
)
48 struct nlattr
**attrs
= info
->attrs
;
51 if (!attrs
[NL80211_ATTR_IFINDEX
])
54 ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
55 *dev
= dev_get_by_index(genl_info_net(info
), ifindex
);
59 *rdev
= cfg80211_get_dev_from_ifindex(genl_info_net(info
), ifindex
);
62 return PTR_ERR(*rdev
);
68 /* policy for the attributes */
69 static const struct nla_policy nl80211_policy
[NL80211_ATTR_MAX
+1] = {
70 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
71 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
73 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
74 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
75 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
76 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
77 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
78 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
79 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
80 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
82 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
83 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
84 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
86 [NL80211_ATTR_MAC
] = { .type
= NLA_BINARY
, .len
= ETH_ALEN
},
87 [NL80211_ATTR_PREV_BSSID
] = { .type
= NLA_BINARY
, .len
= ETH_ALEN
},
89 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
90 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
91 .len
= WLAN_MAX_KEY_LEN
},
92 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
93 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
94 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
95 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 8 },
96 [NL80211_ATTR_KEY_TYPE
] = { .type
= NLA_U32
},
98 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
99 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
100 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
101 .len
= IEEE80211_MAX_DATA_LEN
},
102 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
103 .len
= IEEE80211_MAX_DATA_LEN
},
104 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
105 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
106 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
107 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
108 .len
= NL80211_MAX_SUPP_RATES
},
109 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
110 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
111 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
112 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
113 .len
= IEEE80211_MAX_MESH_ID_LEN
},
114 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
116 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
117 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
119 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
120 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
121 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
122 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
123 .len
= NL80211_MAX_SUPP_RATES
},
124 [NL80211_ATTR_BSS_HT_OPMODE
] = { .type
= NLA_U16
},
126 [NL80211_ATTR_MESH_CONFIG
] = { .type
= NLA_NESTED
},
127 [NL80211_ATTR_SUPPORT_MESH_AUTH
] = { .type
= NLA_FLAG
},
129 [NL80211_ATTR_HT_CAPABILITY
] = { .type
= NLA_BINARY
,
130 .len
= NL80211_HT_CAPABILITY_LEN
},
132 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
133 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
134 .len
= IEEE80211_MAX_DATA_LEN
},
135 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
136 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
138 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
139 .len
= IEEE80211_MAX_SSID_LEN
},
140 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
141 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
142 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
143 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
144 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
145 [NL80211_ATTR_STA_FLAGS2
] = {
146 .len
= sizeof(struct nl80211_sta_flag_update
),
148 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
149 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE
] = { .type
= NLA_U16
},
150 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
] = { .type
= NLA_FLAG
},
151 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
152 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
153 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
154 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
155 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
156 [NL80211_ATTR_PMKID
] = { .type
= NLA_BINARY
,
157 .len
= WLAN_PMKID_LEN
},
158 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
159 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
160 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
161 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
162 .len
= IEEE80211_MAX_DATA_LEN
},
163 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
164 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
165 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
166 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
167 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
168 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
169 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
170 [NL80211_ATTR_FRAME_TYPE
] = { .type
= NLA_U16
},
171 [NL80211_ATTR_WIPHY_ANTENNA_TX
] = { .type
= NLA_U32
},
172 [NL80211_ATTR_WIPHY_ANTENNA_RX
] = { .type
= NLA_U32
},
173 [NL80211_ATTR_MCAST_RATE
] = { .type
= NLA_U32
},
174 [NL80211_ATTR_OFFCHANNEL_TX_OK
] = { .type
= NLA_FLAG
},
175 [NL80211_ATTR_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
176 [NL80211_ATTR_WOWLAN_TRIGGERS
] = { .type
= NLA_NESTED
},
177 [NL80211_ATTR_STA_PLINK_STATE
] = { .type
= NLA_U8
},
178 [NL80211_ATTR_SCHED_SCAN_INTERVAL
] = { .type
= NLA_U32
},
181 /* policy for the key attributes */
182 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
183 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
184 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
185 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
186 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 8 },
187 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
188 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
189 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
190 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
193 /* policy for the key default flags */
194 static const struct nla_policy
195 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
196 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
197 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
200 /* policy for WoWLAN attributes */
201 static const struct nla_policy
202 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
203 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
204 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
205 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
206 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
209 /* ifidx get helper */
210 static int nl80211_get_ifidx(struct netlink_callback
*cb
)
214 res
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
215 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
220 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
223 res
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
229 static int nl80211_prepare_netdev_dump(struct sk_buff
*skb
,
230 struct netlink_callback
*cb
,
231 struct cfg80211_registered_device
**rdev
,
232 struct net_device
**dev
)
234 int ifidx
= cb
->args
[0];
238 ifidx
= nl80211_get_ifidx(cb
);
246 *dev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
252 *rdev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
254 err
= PTR_ERR(*rdev
);
264 static void nl80211_finish_netdev_dump(struct cfg80211_registered_device
*rdev
)
266 cfg80211_unlock_rdev(rdev
);
271 static bool is_valid_ie_attr(const struct nlattr
*attr
)
279 pos
= nla_data(attr
);
300 /* message building helper */
301 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 pid
, u32 seq
,
304 /* since there is no private header just add the generic one */
305 return genlmsg_put(skb
, pid
, seq
, &nl80211_fam
, flags
, cmd
);
308 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
309 struct ieee80211_channel
*chan
)
311 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
314 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
315 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_DISABLED
);
316 if (chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
317 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
);
318 if (chan
->flags
& IEEE80211_CHAN_NO_IBSS
)
319 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
);
320 if (chan
->flags
& IEEE80211_CHAN_RADAR
)
321 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_RADAR
);
323 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
324 DBM_TO_MBM(chan
->max_power
));
332 /* netlink command implementations */
339 bool def_uni
, def_multi
;
342 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
344 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
345 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
350 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
351 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
360 if (tb
[NL80211_KEY_IDX
])
361 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
363 if (tb
[NL80211_KEY_DATA
]) {
364 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
365 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
368 if (tb
[NL80211_KEY_SEQ
]) {
369 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
370 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
373 if (tb
[NL80211_KEY_CIPHER
])
374 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
376 if (tb
[NL80211_KEY_TYPE
]) {
377 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
378 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
382 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
383 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
384 int err
= nla_parse_nested(kdt
,
385 NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
386 tb
[NL80211_KEY_DEFAULT_TYPES
],
387 nl80211_key_default_policy
);
391 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
392 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
398 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
400 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
401 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
402 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
405 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
406 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
407 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
410 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
411 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
413 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
414 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
416 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
417 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
426 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
427 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
428 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
432 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
433 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
434 int err
= nla_parse_nested(
435 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
436 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
437 nl80211_key_default_policy
);
441 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
442 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
448 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
452 memset(k
, 0, sizeof(*k
));
456 if (info
->attrs
[NL80211_ATTR_KEY
])
457 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
459 err
= nl80211_parse_key_old(info
, k
);
464 if (k
->def
&& k
->defmgmt
)
468 if (k
->def_uni
|| !k
->def_multi
)
474 if (k
->idx
< 4 || k
->idx
> 5)
477 if (k
->idx
< 0 || k
->idx
> 3)
480 if (k
->idx
< 0 || k
->idx
> 5)
488 static struct cfg80211_cached_keys
*
489 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
492 struct key_parse parse
;
494 struct cfg80211_cached_keys
*result
;
495 int rem
, err
, def
= 0;
497 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
499 return ERR_PTR(-ENOMEM
);
502 result
->defmgmt
= -1;
504 nla_for_each_nested(key
, keys
, rem
) {
505 memset(&parse
, 0, sizeof(parse
));
508 err
= nl80211_parse_key_new(key
, &parse
);
514 if (parse
.idx
< 0 || parse
.idx
> 4)
520 result
->def
= parse
.idx
;
521 if (!parse
.def_uni
|| !parse
.def_multi
)
523 } else if (parse
.defmgmt
)
525 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
526 parse
.idx
, false, NULL
);
529 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
530 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
531 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
532 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
541 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
543 ASSERT_WDEV_LOCK(wdev
);
545 switch (wdev
->iftype
) {
546 case NL80211_IFTYPE_AP
:
547 case NL80211_IFTYPE_AP_VLAN
:
548 case NL80211_IFTYPE_P2P_GO
:
549 case NL80211_IFTYPE_MESH_POINT
:
551 case NL80211_IFTYPE_ADHOC
:
552 if (!wdev
->current_bss
)
555 case NL80211_IFTYPE_STATION
:
556 case NL80211_IFTYPE_P2P_CLIENT
:
557 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
567 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
569 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
573 goto nla_put_failure
;
578 NLA_PUT_FLAG(msg
, i
);
583 nla_nest_end(msg
, nl_modes
);
590 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
593 struct nlattr
*nl_combis
;
596 nl_combis
= nla_nest_start(msg
,
597 NL80211_ATTR_INTERFACE_COMBINATIONS
);
599 goto nla_put_failure
;
601 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
602 const struct ieee80211_iface_combination
*c
;
603 struct nlattr
*nl_combi
, *nl_limits
;
605 c
= &wiphy
->iface_combinations
[i
];
607 nl_combi
= nla_nest_start(msg
, i
+ 1);
609 goto nla_put_failure
;
611 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
613 goto nla_put_failure
;
615 for (j
= 0; j
< c
->n_limits
; j
++) {
616 struct nlattr
*nl_limit
;
618 nl_limit
= nla_nest_start(msg
, j
+ 1);
620 goto nla_put_failure
;
621 NLA_PUT_U32(msg
, NL80211_IFACE_LIMIT_MAX
,
623 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
625 goto nla_put_failure
;
626 nla_nest_end(msg
, nl_limit
);
629 nla_nest_end(msg
, nl_limits
);
631 if (c
->beacon_int_infra_match
)
633 NL80211_IFACE_COMB_STA_AP_BI_MATCH
);
634 NLA_PUT_U32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
635 c
->num_different_channels
);
636 NLA_PUT_U32(msg
, NL80211_IFACE_COMB_MAXNUM
,
639 nla_nest_end(msg
, nl_combi
);
642 nla_nest_end(msg
, nl_combis
);
649 static int nl80211_send_wiphy(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
650 struct cfg80211_registered_device
*dev
)
653 struct nlattr
*nl_bands
, *nl_band
;
654 struct nlattr
*nl_freqs
, *nl_freq
;
655 struct nlattr
*nl_rates
, *nl_rate
;
656 struct nlattr
*nl_cmds
;
657 enum ieee80211_band band
;
658 struct ieee80211_channel
*chan
;
659 struct ieee80211_rate
*rate
;
661 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
662 dev
->wiphy
.mgmt_stypes
;
664 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
668 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
);
669 NLA_PUT_STRING(msg
, NL80211_ATTR_WIPHY_NAME
, wiphy_name(&dev
->wiphy
));
671 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
672 cfg80211_rdev_list_generation
);
674 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
675 dev
->wiphy
.retry_short
);
676 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
677 dev
->wiphy
.retry_long
);
678 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
679 dev
->wiphy
.frag_threshold
);
680 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
681 dev
->wiphy
.rts_threshold
);
682 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
683 dev
->wiphy
.coverage_class
);
684 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
685 dev
->wiphy
.max_scan_ssids
);
686 NLA_PUT_U16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
687 dev
->wiphy
.max_scan_ie_len
);
689 if (dev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
)
690 NLA_PUT_FLAG(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
);
691 if (dev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
)
692 NLA_PUT_FLAG(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
);
694 NLA_PUT(msg
, NL80211_ATTR_CIPHER_SUITES
,
695 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
696 dev
->wiphy
.cipher_suites
);
698 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
699 dev
->wiphy
.max_num_pmkids
);
701 if (dev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
)
702 NLA_PUT_FLAG(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
);
704 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
705 dev
->wiphy
.available_antennas_tx
);
706 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
707 dev
->wiphy
.available_antennas_rx
);
709 if ((dev
->wiphy
.available_antennas_tx
||
710 dev
->wiphy
.available_antennas_rx
) && dev
->ops
->get_antenna
) {
711 u32 tx_ant
= 0, rx_ant
= 0;
713 res
= dev
->ops
->get_antenna(&dev
->wiphy
, &tx_ant
, &rx_ant
);
715 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_TX
, tx_ant
);
716 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_RX
, rx_ant
);
720 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
721 dev
->wiphy
.interface_modes
))
722 goto nla_put_failure
;
724 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
726 goto nla_put_failure
;
728 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
729 if (!dev
->wiphy
.bands
[band
])
732 nl_band
= nla_nest_start(msg
, band
);
734 goto nla_put_failure
;
737 if (dev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
) {
738 NLA_PUT(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
739 sizeof(dev
->wiphy
.bands
[band
]->ht_cap
.mcs
),
740 &dev
->wiphy
.bands
[band
]->ht_cap
.mcs
);
741 NLA_PUT_U16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
742 dev
->wiphy
.bands
[band
]->ht_cap
.cap
);
743 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
744 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_factor
);
745 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
746 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_density
);
749 /* add frequencies */
750 nl_freqs
= nla_nest_start(msg
, NL80211_BAND_ATTR_FREQS
);
752 goto nla_put_failure
;
754 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_channels
; i
++) {
755 nl_freq
= nla_nest_start(msg
, i
);
757 goto nla_put_failure
;
759 chan
= &dev
->wiphy
.bands
[band
]->channels
[i
];
761 if (nl80211_msg_put_channel(msg
, chan
))
762 goto nla_put_failure
;
764 nla_nest_end(msg
, nl_freq
);
767 nla_nest_end(msg
, nl_freqs
);
770 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
772 goto nla_put_failure
;
774 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_bitrates
; i
++) {
775 nl_rate
= nla_nest_start(msg
, i
);
777 goto nla_put_failure
;
779 rate
= &dev
->wiphy
.bands
[band
]->bitrates
[i
];
780 NLA_PUT_U32(msg
, NL80211_BITRATE_ATTR_RATE
,
782 if (rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
)
784 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
);
786 nla_nest_end(msg
, nl_rate
);
789 nla_nest_end(msg
, nl_rates
);
791 nla_nest_end(msg
, nl_band
);
793 nla_nest_end(msg
, nl_bands
);
795 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
797 goto nla_put_failure
;
802 if (dev->ops->op) { \
804 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
808 CMD(add_virtual_intf
, NEW_INTERFACE
);
809 CMD(change_virtual_intf
, SET_INTERFACE
);
810 CMD(add_key
, NEW_KEY
);
811 CMD(add_beacon
, NEW_BEACON
);
812 CMD(add_station
, NEW_STATION
);
813 CMD(add_mpath
, NEW_MPATH
);
814 CMD(update_mesh_config
, SET_MESH_CONFIG
);
815 CMD(change_bss
, SET_BSS
);
816 CMD(auth
, AUTHENTICATE
);
817 CMD(assoc
, ASSOCIATE
);
818 CMD(deauth
, DEAUTHENTICATE
);
819 CMD(disassoc
, DISASSOCIATE
);
820 CMD(join_ibss
, JOIN_IBSS
);
821 CMD(join_mesh
, JOIN_MESH
);
822 CMD(set_pmksa
, SET_PMKSA
);
823 CMD(del_pmksa
, DEL_PMKSA
);
824 CMD(flush_pmksa
, FLUSH_PMKSA
);
825 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
826 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
828 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
829 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
831 NLA_PUT_U32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
);
833 CMD(set_channel
, SET_CHANNEL
);
834 CMD(set_wds_peer
, SET_WDS_PEER
);
835 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
836 CMD(sched_scan_start
, START_SCHED_SCAN
);
840 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
842 NLA_PUT_U32(msg
, i
, NL80211_CMD_CONNECT
);
845 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
847 NLA_PUT_U32(msg
, i
, NL80211_CMD_DISCONNECT
);
850 nla_nest_end(msg
, nl_cmds
);
852 if (dev
->ops
->remain_on_channel
)
853 NLA_PUT_U32(msg
, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
854 dev
->wiphy
.max_remain_on_channel_duration
);
856 /* for now at least assume all drivers have it */
857 if (dev
->ops
->mgmt_tx
)
858 NLA_PUT_FLAG(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
);
862 struct nlattr
*nl_ftypes
, *nl_ifs
;
863 enum nl80211_iftype ift
;
865 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
867 goto nla_put_failure
;
869 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
870 nl_ftypes
= nla_nest_start(msg
, ift
);
872 goto nla_put_failure
;
874 stypes
= mgmt_stypes
[ift
].tx
;
877 NLA_PUT_U16(msg
, NL80211_ATTR_FRAME_TYPE
,
878 (i
<< 4) | IEEE80211_FTYPE_MGMT
);
882 nla_nest_end(msg
, nl_ftypes
);
885 nla_nest_end(msg
, nl_ifs
);
887 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
889 goto nla_put_failure
;
891 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
892 nl_ftypes
= nla_nest_start(msg
, ift
);
894 goto nla_put_failure
;
896 stypes
= mgmt_stypes
[ift
].rx
;
899 NLA_PUT_U16(msg
, NL80211_ATTR_FRAME_TYPE
,
900 (i
<< 4) | IEEE80211_FTYPE_MGMT
);
904 nla_nest_end(msg
, nl_ftypes
);
906 nla_nest_end(msg
, nl_ifs
);
909 if (dev
->wiphy
.wowlan
.flags
|| dev
->wiphy
.wowlan
.n_patterns
) {
910 struct nlattr
*nl_wowlan
;
912 nl_wowlan
= nla_nest_start(msg
,
913 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
915 goto nla_put_failure
;
917 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_ANY
)
918 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_ANY
);
919 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_DISCONNECT
)
920 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
);
921 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_MAGIC_PKT
)
922 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
);
923 if (dev
->wiphy
.wowlan
.n_patterns
) {
924 struct nl80211_wowlan_pattern_support pat
= {
925 .max_patterns
= dev
->wiphy
.wowlan
.n_patterns
,
927 dev
->wiphy
.wowlan
.pattern_min_len
,
929 dev
->wiphy
.wowlan
.pattern_max_len
,
931 NLA_PUT(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
935 nla_nest_end(msg
, nl_wowlan
);
938 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
939 dev
->wiphy
.software_iftypes
))
940 goto nla_put_failure
;
942 if (nl80211_put_iface_combinations(&dev
->wiphy
, msg
))
943 goto nla_put_failure
;
945 return genlmsg_end(msg
, hdr
);
948 genlmsg_cancel(msg
, hdr
);
952 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
955 int start
= cb
->args
[0];
956 struct cfg80211_registered_device
*dev
;
958 mutex_lock(&cfg80211_mutex
);
959 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
960 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
964 if (nl80211_send_wiphy(skb
, NETLINK_CB(cb
->skb
).pid
,
965 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
971 mutex_unlock(&cfg80211_mutex
);
978 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
981 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
983 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
987 if (nl80211_send_wiphy(msg
, info
->snd_pid
, info
->snd_seq
, 0, dev
) < 0) {
992 return genlmsg_reply(msg
, info
);
995 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
996 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
997 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
998 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
999 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
1000 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1003 static int parse_txq_params(struct nlattr
*tb
[],
1004 struct ieee80211_txq_params
*txq_params
)
1006 if (!tb
[NL80211_TXQ_ATTR_QUEUE
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1007 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1008 !tb
[NL80211_TXQ_ATTR_AIFS
])
1011 txq_params
->queue
= nla_get_u8(tb
[NL80211_TXQ_ATTR_QUEUE
]);
1012 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1013 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1014 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1015 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1020 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1023 * You can only set the channel explicitly for AP, mesh
1024 * and WDS type interfaces; all others have their channel
1025 * managed via their respective "establish a connection"
1026 * command (connect, join, ...)
1028 * Monitors are special as they are normally slaved to
1029 * whatever else is going on, so they behave as though
1030 * you tried setting the wiphy channel itself.
1033 wdev
->iftype
== NL80211_IFTYPE_AP
||
1034 wdev
->iftype
== NL80211_IFTYPE_WDS
||
1035 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
1036 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
1037 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
1040 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
1041 struct wireless_dev
*wdev
,
1042 struct genl_info
*info
)
1044 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
1048 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
1051 if (!nl80211_can_set_dev_channel(wdev
))
1054 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
1055 channel_type
= nla_get_u32(info
->attrs
[
1056 NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1057 if (channel_type
!= NL80211_CHAN_NO_HT
&&
1058 channel_type
!= NL80211_CHAN_HT20
&&
1059 channel_type
!= NL80211_CHAN_HT40PLUS
&&
1060 channel_type
!= NL80211_CHAN_HT40MINUS
)
1064 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
1066 mutex_lock(&rdev
->devlist_mtx
);
1069 result
= cfg80211_set_freq(rdev
, wdev
, freq
, channel_type
);
1072 result
= cfg80211_set_freq(rdev
, NULL
, freq
, channel_type
);
1074 mutex_unlock(&rdev
->devlist_mtx
);
1079 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
1081 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1082 struct net_device
*netdev
= info
->user_ptr
[1];
1084 return __nl80211_set_channel(rdev
, netdev
->ieee80211_ptr
, info
);
1087 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
1089 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1090 struct net_device
*dev
= info
->user_ptr
[1];
1091 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1094 if (!info
->attrs
[NL80211_ATTR_MAC
])
1097 if (netif_running(dev
))
1100 if (!rdev
->ops
->set_wds_peer
)
1103 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
1106 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1107 return rdev
->ops
->set_wds_peer(wdev
->wiphy
, dev
, bssid
);
1111 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1113 struct cfg80211_registered_device
*rdev
;
1114 struct net_device
*netdev
= NULL
;
1115 struct wireless_dev
*wdev
;
1116 int result
= 0, rem_txq_params
= 0;
1117 struct nlattr
*nl_txq_params
;
1119 u8 retry_short
= 0, retry_long
= 0;
1120 u32 frag_threshold
= 0, rts_threshold
= 0;
1121 u8 coverage_class
= 0;
1124 * Try to find the wiphy and netdev. Normally this
1125 * function shouldn't need the netdev, but this is
1126 * done for backward compatibility -- previously
1127 * setting the channel was done per wiphy, but now
1128 * it is per netdev. Previous userland like hostapd
1129 * also passed a netdev to set_wiphy, so that it is
1130 * possible to let that go to the right netdev!
1132 mutex_lock(&cfg80211_mutex
);
1134 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
1135 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
1137 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
1138 if (netdev
&& netdev
->ieee80211_ptr
) {
1139 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
1140 mutex_lock(&rdev
->mtx
);
1146 rdev
= __cfg80211_rdev_from_info(info
);
1148 mutex_unlock(&cfg80211_mutex
);
1149 return PTR_ERR(rdev
);
1155 mutex_lock(&rdev
->mtx
);
1156 } else if (netif_running(netdev
) &&
1157 nl80211_can_set_dev_channel(netdev
->ieee80211_ptr
))
1158 wdev
= netdev
->ieee80211_ptr
;
1163 * end workaround code, by now the rdev is available
1164 * and locked, and wdev may or may not be NULL.
1167 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
1168 result
= cfg80211_dev_rename(
1169 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
1171 mutex_unlock(&cfg80211_mutex
);
1176 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
1177 struct ieee80211_txq_params txq_params
;
1178 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
1180 if (!rdev
->ops
->set_txq_params
) {
1181 result
= -EOPNOTSUPP
;
1185 nla_for_each_nested(nl_txq_params
,
1186 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
1188 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
1189 nla_data(nl_txq_params
),
1190 nla_len(nl_txq_params
),
1192 result
= parse_txq_params(tb
, &txq_params
);
1196 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
1203 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
1204 result
= __nl80211_set_channel(rdev
, wdev
, info
);
1209 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
1210 enum nl80211_tx_power_setting type
;
1213 if (!rdev
->ops
->set_tx_power
) {
1214 result
= -EOPNOTSUPP
;
1218 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
1219 type
= nla_get_u32(info
->attrs
[idx
]);
1221 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
1222 (type
!= NL80211_TX_POWER_AUTOMATIC
)) {
1227 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
1228 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
1229 mbm
= nla_get_u32(info
->attrs
[idx
]);
1232 result
= rdev
->ops
->set_tx_power(&rdev
->wiphy
, type
, mbm
);
1237 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
1238 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
1240 if ((!rdev
->wiphy
.available_antennas_tx
&&
1241 !rdev
->wiphy
.available_antennas_rx
) ||
1242 !rdev
->ops
->set_antenna
) {
1243 result
= -EOPNOTSUPP
;
1247 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
1248 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
1250 /* reject antenna configurations which don't match the
1251 * available antenna masks, except for the "all" mask */
1252 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
1253 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
))) {
1258 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
1259 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
1261 result
= rdev
->ops
->set_antenna(&rdev
->wiphy
, tx_ant
, rx_ant
);
1268 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
1269 retry_short
= nla_get_u8(
1270 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
1271 if (retry_short
== 0) {
1275 changed
|= WIPHY_PARAM_RETRY_SHORT
;
1278 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
1279 retry_long
= nla_get_u8(
1280 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
1281 if (retry_long
== 0) {
1285 changed
|= WIPHY_PARAM_RETRY_LONG
;
1288 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
1289 frag_threshold
= nla_get_u32(
1290 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
1291 if (frag_threshold
< 256) {
1295 if (frag_threshold
!= (u32
) -1) {
1297 * Fragments (apart from the last one) are required to
1298 * have even length. Make the fragmentation code
1299 * simpler by stripping LSB should someone try to use
1300 * odd threshold value.
1302 frag_threshold
&= ~0x1;
1304 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
1307 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
1308 rts_threshold
= nla_get_u32(
1309 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
1310 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
1313 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
1314 coverage_class
= nla_get_u8(
1315 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
1316 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
1320 u8 old_retry_short
, old_retry_long
;
1321 u32 old_frag_threshold
, old_rts_threshold
;
1322 u8 old_coverage_class
;
1324 if (!rdev
->ops
->set_wiphy_params
) {
1325 result
= -EOPNOTSUPP
;
1329 old_retry_short
= rdev
->wiphy
.retry_short
;
1330 old_retry_long
= rdev
->wiphy
.retry_long
;
1331 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
1332 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
1333 old_coverage_class
= rdev
->wiphy
.coverage_class
;
1335 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
1336 rdev
->wiphy
.retry_short
= retry_short
;
1337 if (changed
& WIPHY_PARAM_RETRY_LONG
)
1338 rdev
->wiphy
.retry_long
= retry_long
;
1339 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
1340 rdev
->wiphy
.frag_threshold
= frag_threshold
;
1341 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
1342 rdev
->wiphy
.rts_threshold
= rts_threshold
;
1343 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
1344 rdev
->wiphy
.coverage_class
= coverage_class
;
1346 result
= rdev
->ops
->set_wiphy_params(&rdev
->wiphy
, changed
);
1348 rdev
->wiphy
.retry_short
= old_retry_short
;
1349 rdev
->wiphy
.retry_long
= old_retry_long
;
1350 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
1351 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
1352 rdev
->wiphy
.coverage_class
= old_coverage_class
;
1357 mutex_unlock(&rdev
->mtx
);
1364 static int nl80211_send_iface(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
1365 struct cfg80211_registered_device
*rdev
,
1366 struct net_device
*dev
)
1370 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
1374 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1375 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
1376 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, dev
->name
);
1377 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, dev
->ieee80211_ptr
->iftype
);
1379 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
1380 rdev
->devlist_generation
^
1381 (cfg80211_rdev_list_generation
<< 2));
1383 return genlmsg_end(msg
, hdr
);
1386 genlmsg_cancel(msg
, hdr
);
1390 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1394 int wp_start
= cb
->args
[0];
1395 int if_start
= cb
->args
[1];
1396 struct cfg80211_registered_device
*rdev
;
1397 struct wireless_dev
*wdev
;
1399 mutex_lock(&cfg80211_mutex
);
1400 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
1401 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
1403 if (wp_idx
< wp_start
) {
1409 mutex_lock(&rdev
->devlist_mtx
);
1410 list_for_each_entry(wdev
, &rdev
->netdev_list
, list
) {
1411 if (if_idx
< if_start
) {
1415 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).pid
,
1416 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1417 rdev
, wdev
->netdev
) < 0) {
1418 mutex_unlock(&rdev
->devlist_mtx
);
1423 mutex_unlock(&rdev
->devlist_mtx
);
1428 mutex_unlock(&cfg80211_mutex
);
1430 cb
->args
[0] = wp_idx
;
1431 cb
->args
[1] = if_idx
;
1436 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1438 struct sk_buff
*msg
;
1439 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1440 struct net_device
*netdev
= info
->user_ptr
[1];
1442 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1446 if (nl80211_send_iface(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1452 return genlmsg_reply(msg
, info
);
1455 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
1456 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
1457 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
1458 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
1459 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
1460 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
1463 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
1465 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
1473 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
1474 nla
, mntr_flags_policy
))
1477 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
1479 *mntrflags
|= (1<<flag
);
1484 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
1485 struct net_device
*netdev
, u8 use_4addr
,
1486 enum nl80211_iftype iftype
)
1489 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
1495 case NL80211_IFTYPE_AP_VLAN
:
1496 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
1499 case NL80211_IFTYPE_STATION
:
1500 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
1510 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1512 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1513 struct vif_params params
;
1515 enum nl80211_iftype otype
, ntype
;
1516 struct net_device
*dev
= info
->user_ptr
[1];
1517 u32 _flags
, *flags
= NULL
;
1518 bool change
= false;
1520 memset(¶ms
, 0, sizeof(params
));
1522 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
1524 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1525 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1528 if (ntype
> NL80211_IFTYPE_MAX
)
1532 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1533 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1535 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
1537 if (netif_running(dev
))
1541 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
1542 IEEE80211_MAX_MESH_ID_LEN
);
1543 wdev
->mesh_id_up_len
=
1544 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1545 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
1546 wdev
->mesh_id_up_len
);
1550 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1551 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1553 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
1557 params
.use_4addr
= -1;
1560 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
1561 if (ntype
!= NL80211_IFTYPE_MONITOR
)
1563 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
1573 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
1577 if (!err
&& params
.use_4addr
!= -1)
1578 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
1583 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1585 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1586 struct vif_params params
;
1587 struct net_device
*dev
;
1589 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
1592 memset(¶ms
, 0, sizeof(params
));
1594 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
1597 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1598 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1599 if (type
> NL80211_IFTYPE_MAX
)
1603 if (!rdev
->ops
->add_virtual_intf
||
1604 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
1607 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1608 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1609 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
1614 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
1615 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
1617 dev
= rdev
->ops
->add_virtual_intf(&rdev
->wiphy
,
1618 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
1619 type
, err
? NULL
: &flags
, ¶ms
);
1621 return PTR_ERR(dev
);
1623 if (type
== NL80211_IFTYPE_MESH_POINT
&&
1624 info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1625 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1628 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
1629 IEEE80211_MAX_MESH_ID_LEN
);
1630 wdev
->mesh_id_up_len
=
1631 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1632 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
1633 wdev
->mesh_id_up_len
);
1640 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1642 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1643 struct net_device
*dev
= info
->user_ptr
[1];
1645 if (!rdev
->ops
->del_virtual_intf
)
1648 return rdev
->ops
->del_virtual_intf(&rdev
->wiphy
, dev
);
1651 struct get_key_cookie
{
1652 struct sk_buff
*msg
;
1657 static void get_key_callback(void *c
, struct key_params
*params
)
1660 struct get_key_cookie
*cookie
= c
;
1663 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
1664 params
->key_len
, params
->key
);
1667 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
1668 params
->seq_len
, params
->seq
);
1671 NLA_PUT_U32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
1674 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
1676 goto nla_put_failure
;
1679 NLA_PUT(cookie
->msg
, NL80211_KEY_DATA
,
1680 params
->key_len
, params
->key
);
1683 NLA_PUT(cookie
->msg
, NL80211_KEY_SEQ
,
1684 params
->seq_len
, params
->seq
);
1687 NLA_PUT_U32(cookie
->msg
, NL80211_KEY_CIPHER
,
1690 NLA_PUT_U8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
);
1692 nla_nest_end(cookie
->msg
, key
);
1699 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
1701 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1703 struct net_device
*dev
= info
->user_ptr
[1];
1705 const u8
*mac_addr
= NULL
;
1707 struct get_key_cookie cookie
= {
1711 struct sk_buff
*msg
;
1713 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
1714 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1719 if (info
->attrs
[NL80211_ATTR_MAC
])
1720 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1722 pairwise
= !!mac_addr
;
1723 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
1724 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
1725 if (kt
>= NUM_NL80211_KEYTYPES
)
1727 if (kt
!= NL80211_KEYTYPE_GROUP
&&
1728 kt
!= NL80211_KEYTYPE_PAIRWISE
)
1730 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
1733 if (!rdev
->ops
->get_key
)
1736 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1740 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1741 NL80211_CMD_NEW_KEY
);
1743 return PTR_ERR(hdr
);
1746 cookie
.idx
= key_idx
;
1748 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1749 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
1751 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1753 if (pairwise
&& mac_addr
&&
1754 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
1757 err
= rdev
->ops
->get_key(&rdev
->wiphy
, dev
, key_idx
, pairwise
,
1758 mac_addr
, &cookie
, get_key_callback
);
1764 goto nla_put_failure
;
1766 genlmsg_end(msg
, hdr
);
1767 return genlmsg_reply(msg
, info
);
1776 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
1778 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1779 struct key_parse key
;
1781 struct net_device
*dev
= info
->user_ptr
[1];
1783 err
= nl80211_parse_key(info
, &key
);
1790 /* only support setting default key */
1791 if (!key
.def
&& !key
.defmgmt
)
1794 wdev_lock(dev
->ieee80211_ptr
);
1797 if (!rdev
->ops
->set_default_key
) {
1802 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1806 err
= rdev
->ops
->set_default_key(&rdev
->wiphy
, dev
, key
.idx
,
1807 key
.def_uni
, key
.def_multi
);
1812 #ifdef CONFIG_CFG80211_WEXT
1813 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
1816 if (key
.def_uni
|| !key
.def_multi
) {
1821 if (!rdev
->ops
->set_default_mgmt_key
) {
1826 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1830 err
= rdev
->ops
->set_default_mgmt_key(&rdev
->wiphy
,
1835 #ifdef CONFIG_CFG80211_WEXT
1836 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
1841 wdev_unlock(dev
->ieee80211_ptr
);
1846 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
1848 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1850 struct net_device
*dev
= info
->user_ptr
[1];
1851 struct key_parse key
;
1852 const u8
*mac_addr
= NULL
;
1854 err
= nl80211_parse_key(info
, &key
);
1861 if (info
->attrs
[NL80211_ATTR_MAC
])
1862 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1864 if (key
.type
== -1) {
1866 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
1868 key
.type
= NL80211_KEYTYPE_GROUP
;
1872 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
1873 key
.type
!= NL80211_KEYTYPE_GROUP
)
1876 if (!rdev
->ops
->add_key
)
1879 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
1880 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
1884 wdev_lock(dev
->ieee80211_ptr
);
1885 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1887 err
= rdev
->ops
->add_key(&rdev
->wiphy
, dev
, key
.idx
,
1888 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
1890 wdev_unlock(dev
->ieee80211_ptr
);
1895 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
1897 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1899 struct net_device
*dev
= info
->user_ptr
[1];
1900 u8
*mac_addr
= NULL
;
1901 struct key_parse key
;
1903 err
= nl80211_parse_key(info
, &key
);
1907 if (info
->attrs
[NL80211_ATTR_MAC
])
1908 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1910 if (key
.type
== -1) {
1912 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
1914 key
.type
= NL80211_KEYTYPE_GROUP
;
1918 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
1919 key
.type
!= NL80211_KEYTYPE_GROUP
)
1922 if (!rdev
->ops
->del_key
)
1925 wdev_lock(dev
->ieee80211_ptr
);
1926 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1928 if (key
.type
== NL80211_KEYTYPE_PAIRWISE
&& mac_addr
&&
1929 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
1933 err
= rdev
->ops
->del_key(&rdev
->wiphy
, dev
, key
.idx
,
1934 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
1937 #ifdef CONFIG_CFG80211_WEXT
1939 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
1940 dev
->ieee80211_ptr
->wext
.default_key
= -1;
1941 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
1942 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
1945 wdev_unlock(dev
->ieee80211_ptr
);
1950 static int nl80211_addset_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1952 int (*call
)(struct wiphy
*wiphy
, struct net_device
*dev
,
1953 struct beacon_parameters
*info
);
1954 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1955 struct net_device
*dev
= info
->user_ptr
[1];
1956 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1957 struct beacon_parameters params
;
1958 int haveinfo
= 0, err
;
1960 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]))
1963 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1964 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
1967 memset(¶ms
, 0, sizeof(params
));
1969 switch (info
->genlhdr
->cmd
) {
1970 case NL80211_CMD_NEW_BEACON
:
1971 /* these are required for NEW_BEACON */
1972 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
1973 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
1974 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
1978 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
1979 params
.dtim_period
=
1980 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
1982 err
= cfg80211_validate_beacon_int(rdev
, params
.interval
);
1986 call
= rdev
->ops
->add_beacon
;
1988 case NL80211_CMD_SET_BEACON
:
1989 call
= rdev
->ops
->set_beacon
;
1999 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
2000 params
.head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2002 nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2006 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
2007 params
.tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2009 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2016 err
= call(&rdev
->wiphy
, dev
, ¶ms
);
2017 if (!err
&& params
.interval
)
2018 wdev
->beacon_interval
= params
.interval
;
2022 static int nl80211_del_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
2024 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2025 struct net_device
*dev
= info
->user_ptr
[1];
2026 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2029 if (!rdev
->ops
->del_beacon
)
2032 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2033 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2036 err
= rdev
->ops
->del_beacon(&rdev
->wiphy
, dev
);
2038 wdev
->beacon_interval
= 0;
2042 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
2043 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
2044 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
2045 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
2046 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
2047 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
2050 static int parse_station_flags(struct genl_info
*info
,
2051 struct station_parameters
*params
)
2053 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
2058 * Try parsing the new attribute first so userspace
2059 * can specify both for older kernels.
2061 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
2063 struct nl80211_sta_flag_update
*sta_flags
;
2065 sta_flags
= nla_data(nla
);
2066 params
->sta_flags_mask
= sta_flags
->mask
;
2067 params
->sta_flags_set
= sta_flags
->set
;
2068 if ((params
->sta_flags_mask
|
2069 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
2074 /* if present, parse the old attribute */
2076 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
2080 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
2081 nla
, sta_flags_policy
))
2084 params
->sta_flags_mask
= (1 << __NL80211_STA_FLAG_AFTER_LAST
) - 1;
2085 params
->sta_flags_mask
&= ~1;
2087 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++)
2089 params
->sta_flags_set
|= (1<<flag
);
2094 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
2097 struct nlattr
*rate
;
2100 rate
= nla_nest_start(msg
, attr
);
2102 goto nla_put_failure
;
2104 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2105 bitrate
= cfg80211_calculate_bitrate(info
);
2107 NLA_PUT_U16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate
);
2109 if (info
->flags
& RATE_INFO_FLAGS_MCS
)
2110 NLA_PUT_U8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
);
2111 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
)
2112 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
);
2113 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
)
2114 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_SHORT_GI
);
2116 nla_nest_end(msg
, rate
);
2123 static int nl80211_send_station(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2124 int flags
, struct net_device
*dev
,
2125 const u8
*mac_addr
, struct station_info
*sinfo
)
2128 struct nlattr
*sinfoattr
, *bss_param
;
2130 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2134 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2135 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
2137 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
);
2139 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
2141 goto nla_put_failure
;
2142 if (sinfo
->filled
& STATION_INFO_CONNECTED_TIME
)
2143 NLA_PUT_U32(msg
, NL80211_STA_INFO_CONNECTED_TIME
,
2144 sinfo
->connected_time
);
2145 if (sinfo
->filled
& STATION_INFO_INACTIVE_TIME
)
2146 NLA_PUT_U32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
2147 sinfo
->inactive_time
);
2148 if (sinfo
->filled
& STATION_INFO_RX_BYTES
)
2149 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_BYTES
,
2151 if (sinfo
->filled
& STATION_INFO_TX_BYTES
)
2152 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_BYTES
,
2154 if (sinfo
->filled
& STATION_INFO_LLID
)
2155 NLA_PUT_U16(msg
, NL80211_STA_INFO_LLID
,
2157 if (sinfo
->filled
& STATION_INFO_PLID
)
2158 NLA_PUT_U16(msg
, NL80211_STA_INFO_PLID
,
2160 if (sinfo
->filled
& STATION_INFO_PLINK_STATE
)
2161 NLA_PUT_U8(msg
, NL80211_STA_INFO_PLINK_STATE
,
2162 sinfo
->plink_state
);
2163 if (sinfo
->filled
& STATION_INFO_SIGNAL
)
2164 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL
,
2166 if (sinfo
->filled
& STATION_INFO_SIGNAL_AVG
)
2167 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
2169 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
2170 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
2171 NL80211_STA_INFO_TX_BITRATE
))
2172 goto nla_put_failure
;
2174 if (sinfo
->filled
& STATION_INFO_RX_BITRATE
) {
2175 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
2176 NL80211_STA_INFO_RX_BITRATE
))
2177 goto nla_put_failure
;
2179 if (sinfo
->filled
& STATION_INFO_RX_PACKETS
)
2180 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_PACKETS
,
2182 if (sinfo
->filled
& STATION_INFO_TX_PACKETS
)
2183 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_PACKETS
,
2185 if (sinfo
->filled
& STATION_INFO_TX_RETRIES
)
2186 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_RETRIES
,
2188 if (sinfo
->filled
& STATION_INFO_TX_FAILED
)
2189 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_FAILED
,
2191 if (sinfo
->filled
& STATION_INFO_BSS_PARAM
) {
2192 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
2194 goto nla_put_failure
;
2196 if (sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
)
2197 NLA_PUT_FLAG(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
);
2198 if (sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
)
2199 NLA_PUT_FLAG(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
);
2200 if (sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
)
2202 NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
);
2203 NLA_PUT_U8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
2204 sinfo
->bss_param
.dtim_period
);
2205 NLA_PUT_U16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
2206 sinfo
->bss_param
.beacon_interval
);
2208 nla_nest_end(msg
, bss_param
);
2210 nla_nest_end(msg
, sinfoattr
);
2212 return genlmsg_end(msg
, hdr
);
2215 genlmsg_cancel(msg
, hdr
);
2219 static int nl80211_dump_station(struct sk_buff
*skb
,
2220 struct netlink_callback
*cb
)
2222 struct station_info sinfo
;
2223 struct cfg80211_registered_device
*dev
;
2224 struct net_device
*netdev
;
2225 u8 mac_addr
[ETH_ALEN
];
2226 int sta_idx
= cb
->args
[1];
2229 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
2233 if (!dev
->ops
->dump_station
) {
2239 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
2246 if (nl80211_send_station(skb
,
2247 NETLINK_CB(cb
->skb
).pid
,
2248 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2258 cb
->args
[1] = sta_idx
;
2261 nl80211_finish_netdev_dump(dev
);
2266 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
2268 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2269 struct net_device
*dev
= info
->user_ptr
[1];
2270 struct station_info sinfo
;
2271 struct sk_buff
*msg
;
2272 u8
*mac_addr
= NULL
;
2275 memset(&sinfo
, 0, sizeof(sinfo
));
2277 if (!info
->attrs
[NL80211_ATTR_MAC
])
2280 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2282 if (!rdev
->ops
->get_station
)
2285 err
= rdev
->ops
->get_station(&rdev
->wiphy
, dev
, mac_addr
, &sinfo
);
2289 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2293 if (nl80211_send_station(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2294 dev
, mac_addr
, &sinfo
) < 0) {
2299 return genlmsg_reply(msg
, info
);
2303 * Get vlan interface making sure it is running and on the right wiphy.
2305 static int get_vlan(struct genl_info
*info
,
2306 struct cfg80211_registered_device
*rdev
,
2307 struct net_device
**vlan
)
2309 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
2313 *vlan
= dev_get_by_index(genl_info_net(info
),
2314 nla_get_u32(vlanattr
));
2317 if (!(*vlan
)->ieee80211_ptr
)
2319 if ((*vlan
)->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
)
2321 if (!netif_running(*vlan
))
2327 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
2329 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2331 struct net_device
*dev
= info
->user_ptr
[1];
2332 struct station_parameters params
;
2333 u8
*mac_addr
= NULL
;
2335 memset(¶ms
, 0, sizeof(params
));
2337 params
.listen_interval
= -1;
2338 params
.plink_state
= -1;
2340 if (info
->attrs
[NL80211_ATTR_STA_AID
])
2343 if (!info
->attrs
[NL80211_ATTR_MAC
])
2346 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2348 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
2349 params
.supported_rates
=
2350 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2351 params
.supported_rates_len
=
2352 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2355 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2356 params
.listen_interval
=
2357 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2359 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2361 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2363 if (parse_station_flags(info
, ¶ms
))
2366 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
2367 params
.plink_action
=
2368 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
2370 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
])
2371 params
.plink_state
=
2372 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
2374 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
2378 /* validate settings */
2381 switch (dev
->ieee80211_ptr
->iftype
) {
2382 case NL80211_IFTYPE_AP
:
2383 case NL80211_IFTYPE_AP_VLAN
:
2384 case NL80211_IFTYPE_P2P_GO
:
2385 /* disallow mesh-specific things */
2386 if (params
.plink_action
)
2389 case NL80211_IFTYPE_P2P_CLIENT
:
2390 case NL80211_IFTYPE_STATION
:
2391 /* disallow everything but AUTHORIZED flag */
2392 if (params
.plink_action
)
2396 if (params
.supported_rates
)
2400 if (params
.listen_interval
>= 0)
2402 if (params
.sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
2405 case NL80211_IFTYPE_MESH_POINT
:
2406 /* disallow things mesh doesn't support */
2411 if (params
.listen_interval
>= 0)
2413 if (params
.sta_flags_mask
&
2414 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
2415 BIT(NL80211_STA_FLAG_MFP
) |
2416 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
2426 if (!rdev
->ops
->change_station
) {
2431 err
= rdev
->ops
->change_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2435 dev_put(params
.vlan
);
2440 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
2442 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2444 struct net_device
*dev
= info
->user_ptr
[1];
2445 struct station_parameters params
;
2446 u8
*mac_addr
= NULL
;
2448 memset(¶ms
, 0, sizeof(params
));
2450 if (!info
->attrs
[NL80211_ATTR_MAC
])
2453 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2456 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
2459 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
2462 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2463 params
.supported_rates
=
2464 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2465 params
.supported_rates_len
=
2466 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2467 params
.listen_interval
=
2468 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2470 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
2471 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
2474 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2476 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2478 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
2479 params
.plink_action
=
2480 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
2482 if (parse_station_flags(info
, ¶ms
))
2485 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2486 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
2487 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
2488 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2491 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
2495 /* validate settings */
2498 if (!rdev
->ops
->add_station
) {
2503 err
= rdev
->ops
->add_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2507 dev_put(params
.vlan
);
2511 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
2513 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2514 struct net_device
*dev
= info
->user_ptr
[1];
2515 u8
*mac_addr
= NULL
;
2517 if (info
->attrs
[NL80211_ATTR_MAC
])
2518 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2520 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2521 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
2522 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
2523 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2526 if (!rdev
->ops
->del_station
)
2529 return rdev
->ops
->del_station(&rdev
->wiphy
, dev
, mac_addr
);
2532 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2533 int flags
, struct net_device
*dev
,
2534 u8
*dst
, u8
*next_hop
,
2535 struct mpath_info
*pinfo
)
2538 struct nlattr
*pinfoattr
;
2540 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2544 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2545 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
2546 NLA_PUT(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
);
2548 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
);
2550 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
2552 goto nla_put_failure
;
2553 if (pinfo
->filled
& MPATH_INFO_FRAME_QLEN
)
2554 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
2556 if (pinfo
->filled
& MPATH_INFO_SN
)
2557 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_SN
,
2559 if (pinfo
->filled
& MPATH_INFO_METRIC
)
2560 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_METRIC
,
2562 if (pinfo
->filled
& MPATH_INFO_EXPTIME
)
2563 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_EXPTIME
,
2565 if (pinfo
->filled
& MPATH_INFO_FLAGS
)
2566 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_FLAGS
,
2568 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
)
2569 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
2570 pinfo
->discovery_timeout
);
2571 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
)
2572 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
2573 pinfo
->discovery_retries
);
2575 nla_nest_end(msg
, pinfoattr
);
2577 return genlmsg_end(msg
, hdr
);
2580 genlmsg_cancel(msg
, hdr
);
2584 static int nl80211_dump_mpath(struct sk_buff
*skb
,
2585 struct netlink_callback
*cb
)
2587 struct mpath_info pinfo
;
2588 struct cfg80211_registered_device
*dev
;
2589 struct net_device
*netdev
;
2591 u8 next_hop
[ETH_ALEN
];
2592 int path_idx
= cb
->args
[1];
2595 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
2599 if (!dev
->ops
->dump_mpath
) {
2604 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2610 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
2611 dst
, next_hop
, &pinfo
);
2617 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).pid
,
2618 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2619 netdev
, dst
, next_hop
,
2628 cb
->args
[1] = path_idx
;
2631 nl80211_finish_netdev_dump(dev
);
2635 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2637 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2639 struct net_device
*dev
= info
->user_ptr
[1];
2640 struct mpath_info pinfo
;
2641 struct sk_buff
*msg
;
2643 u8 next_hop
[ETH_ALEN
];
2645 memset(&pinfo
, 0, sizeof(pinfo
));
2647 if (!info
->attrs
[NL80211_ATTR_MAC
])
2650 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2652 if (!rdev
->ops
->get_mpath
)
2655 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2658 err
= rdev
->ops
->get_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
2662 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2666 if (nl80211_send_mpath(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2667 dev
, dst
, next_hop
, &pinfo
) < 0) {
2672 return genlmsg_reply(msg
, info
);
2675 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2677 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2678 struct net_device
*dev
= info
->user_ptr
[1];
2680 u8
*next_hop
= NULL
;
2682 if (!info
->attrs
[NL80211_ATTR_MAC
])
2685 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2688 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2689 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2691 if (!rdev
->ops
->change_mpath
)
2694 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2697 return rdev
->ops
->change_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2700 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2702 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2703 struct net_device
*dev
= info
->user_ptr
[1];
2705 u8
*next_hop
= NULL
;
2707 if (!info
->attrs
[NL80211_ATTR_MAC
])
2710 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2713 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2714 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2716 if (!rdev
->ops
->add_mpath
)
2719 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2722 return rdev
->ops
->add_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2725 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2727 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2728 struct net_device
*dev
= info
->user_ptr
[1];
2731 if (info
->attrs
[NL80211_ATTR_MAC
])
2732 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2734 if (!rdev
->ops
->del_mpath
)
2737 return rdev
->ops
->del_mpath(&rdev
->wiphy
, dev
, dst
);
2740 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
2742 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2743 struct net_device
*dev
= info
->user_ptr
[1];
2744 struct bss_parameters params
;
2746 memset(¶ms
, 0, sizeof(params
));
2747 /* default to not changing parameters */
2748 params
.use_cts_prot
= -1;
2749 params
.use_short_preamble
= -1;
2750 params
.use_short_slot_time
= -1;
2751 params
.ap_isolate
= -1;
2752 params
.ht_opmode
= -1;
2754 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
2755 params
.use_cts_prot
=
2756 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
2757 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
2758 params
.use_short_preamble
=
2759 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
2760 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
2761 params
.use_short_slot_time
=
2762 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
2763 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
2764 params
.basic_rates
=
2765 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2766 params
.basic_rates_len
=
2767 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2769 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
2770 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
2771 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
2773 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
2775 if (!rdev
->ops
->change_bss
)
2778 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2779 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2782 return rdev
->ops
->change_bss(&rdev
->wiphy
, dev
, ¶ms
);
2785 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
2786 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
2787 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
2788 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
2789 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
2790 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
2791 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
2794 static int parse_reg_rule(struct nlattr
*tb
[],
2795 struct ieee80211_reg_rule
*reg_rule
)
2797 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
2798 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
2800 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
2802 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
2804 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
2806 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
2808 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
2811 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
2813 freq_range
->start_freq_khz
=
2814 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
2815 freq_range
->end_freq_khz
=
2816 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
2817 freq_range
->max_bandwidth_khz
=
2818 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
2820 power_rule
->max_eirp
=
2821 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
2823 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
2824 power_rule
->max_antenna_gain
=
2825 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
2830 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2836 * You should only get this when cfg80211 hasn't yet initialized
2837 * completely when built-in to the kernel right between the time
2838 * window between nl80211_init() and regulatory_init(), if that is
2841 mutex_lock(&cfg80211_mutex
);
2842 if (unlikely(!cfg80211_regdomain
)) {
2843 mutex_unlock(&cfg80211_mutex
);
2844 return -EINPROGRESS
;
2846 mutex_unlock(&cfg80211_mutex
);
2848 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2851 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2853 r
= regulatory_hint_user(data
);
2858 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
2859 struct genl_info
*info
)
2861 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2862 struct net_device
*dev
= info
->user_ptr
[1];
2863 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2864 struct mesh_config cur_params
;
2867 struct nlattr
*pinfoattr
;
2868 struct sk_buff
*msg
;
2870 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2873 if (!rdev
->ops
->get_mesh_config
)
2877 /* If not connected, get default parameters */
2878 if (!wdev
->mesh_id_len
)
2879 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
2881 err
= rdev
->ops
->get_mesh_config(&rdev
->wiphy
, dev
,
2888 /* Draw up a netlink message to send back */
2889 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2892 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2893 NL80211_CMD_GET_MESH_CONFIG
);
2896 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
2898 goto nla_put_failure
;
2899 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2900 NLA_PUT_U16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
2901 cur_params
.dot11MeshRetryTimeout
);
2902 NLA_PUT_U16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
2903 cur_params
.dot11MeshConfirmTimeout
);
2904 NLA_PUT_U16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
2905 cur_params
.dot11MeshHoldingTimeout
);
2906 NLA_PUT_U16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
2907 cur_params
.dot11MeshMaxPeerLinks
);
2908 NLA_PUT_U8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
2909 cur_params
.dot11MeshMaxRetries
);
2910 NLA_PUT_U8(msg
, NL80211_MESHCONF_TTL
,
2911 cur_params
.dot11MeshTTL
);
2912 NLA_PUT_U8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
2913 cur_params
.element_ttl
);
2914 NLA_PUT_U8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
2915 cur_params
.auto_open_plinks
);
2916 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2917 cur_params
.dot11MeshHWMPmaxPREQretries
);
2918 NLA_PUT_U32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
2919 cur_params
.path_refresh_time
);
2920 NLA_PUT_U16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2921 cur_params
.min_discovery_timeout
);
2922 NLA_PUT_U32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2923 cur_params
.dot11MeshHWMPactivePathTimeout
);
2924 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2925 cur_params
.dot11MeshHWMPpreqMinInterval
);
2926 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2927 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
);
2928 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
2929 cur_params
.dot11MeshHWMPRootMode
);
2930 nla_nest_end(msg
, pinfoattr
);
2931 genlmsg_end(msg
, hdr
);
2932 return genlmsg_reply(msg
, info
);
2935 genlmsg_cancel(msg
, hdr
);
2941 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
2942 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
2943 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
2944 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
2945 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
2946 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
2947 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
2948 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
2949 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
2951 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
2952 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
2953 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
2954 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
2955 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
2956 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
2959 static const struct nla_policy
2960 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
2961 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
2962 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
2963 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
2964 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
2965 .len
= IEEE80211_MAX_DATA_LEN
},
2966 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
2969 static int nl80211_parse_mesh_config(struct genl_info
*info
,
2970 struct mesh_config
*cfg
,
2973 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
2976 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2978 if (table[attr_num]) {\
2979 cfg->param = nla_fn(table[attr_num]); \
2980 mask |= (1 << (attr_num - 1)); \
2985 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
2987 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
2988 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
2989 nl80211_meshconf_params_policy
))
2992 /* This makes sure that there aren't more than 32 mesh config
2993 * parameters (otherwise our bitfield scheme would not work.) */
2994 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
2996 /* Fill in the params struct */
2997 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
2998 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
, nla_get_u16
);
2999 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
3000 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
, nla_get_u16
);
3001 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
3002 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
, nla_get_u16
);
3003 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
3004 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
, nla_get_u16
);
3005 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
3006 mask
, NL80211_MESHCONF_MAX_RETRIES
, nla_get_u8
);
3007 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
3008 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
3009 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
,
3010 mask
, NL80211_MESHCONF_ELEMENT_TTL
, nla_get_u8
);
3011 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
3012 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
, nla_get_u8
);
3013 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
3014 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
3016 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
3017 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
, nla_get_u32
);
3018 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
3019 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
3021 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
3022 mask
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
3024 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
3025 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
3027 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3028 dot11MeshHWMPnetDiameterTraversalTime
,
3029 mask
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
3031 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3032 dot11MeshHWMPRootMode
, mask
,
3033 NL80211_MESHCONF_HWMP_ROOTMODE
,
3040 #undef FILL_IN_MESH_PARAM_IF_SET
3043 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
3044 struct mesh_setup
*setup
)
3046 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
3048 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
3050 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
3051 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
3052 nl80211_mesh_setup_params_policy
))
3055 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
3056 setup
->path_sel_proto
=
3057 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
3058 IEEE80211_PATH_PROTOCOL_VENDOR
:
3059 IEEE80211_PATH_PROTOCOL_HWMP
;
3061 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
3062 setup
->path_metric
=
3063 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
3064 IEEE80211_PATH_METRIC_VENDOR
:
3065 IEEE80211_PATH_METRIC_AIRTIME
;
3068 if (tb
[NL80211_MESH_SETUP_IE
]) {
3069 struct nlattr
*ieattr
=
3070 tb
[NL80211_MESH_SETUP_IE
];
3071 if (!is_valid_ie_attr(ieattr
))
3073 setup
->ie
= nla_data(ieattr
);
3074 setup
->ie_len
= nla_len(ieattr
);
3076 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
3077 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
3082 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
3083 struct genl_info
*info
)
3085 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3086 struct net_device
*dev
= info
->user_ptr
[1];
3087 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3088 struct mesh_config cfg
;
3092 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3095 if (!rdev
->ops
->update_mesh_config
)
3098 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
3103 if (!wdev
->mesh_id_len
)
3107 err
= rdev
->ops
->update_mesh_config(&rdev
->wiphy
, dev
,
3115 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3117 struct sk_buff
*msg
;
3119 struct nlattr
*nl_reg_rules
;
3123 mutex_lock(&cfg80211_mutex
);
3125 if (!cfg80211_regdomain
)
3128 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3134 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
3135 NL80211_CMD_GET_REG
);
3139 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
,
3140 cfg80211_regdomain
->alpha2
);
3142 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
3144 goto nla_put_failure
;
3146 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
3147 struct nlattr
*nl_reg_rule
;
3148 const struct ieee80211_reg_rule
*reg_rule
;
3149 const struct ieee80211_freq_range
*freq_range
;
3150 const struct ieee80211_power_rule
*power_rule
;
3152 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
3153 freq_range
= ®_rule
->freq_range
;
3154 power_rule
= ®_rule
->power_rule
;
3156 nl_reg_rule
= nla_nest_start(msg
, i
);
3158 goto nla_put_failure
;
3160 NLA_PUT_U32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
3162 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
3163 freq_range
->start_freq_khz
);
3164 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
3165 freq_range
->end_freq_khz
);
3166 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
3167 freq_range
->max_bandwidth_khz
);
3168 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
3169 power_rule
->max_antenna_gain
);
3170 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
3171 power_rule
->max_eirp
);
3173 nla_nest_end(msg
, nl_reg_rule
);
3176 nla_nest_end(msg
, nl_reg_rules
);
3178 genlmsg_end(msg
, hdr
);
3179 err
= genlmsg_reply(msg
, info
);
3183 genlmsg_cancel(msg
, hdr
);
3188 mutex_unlock(&cfg80211_mutex
);
3192 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3194 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
3195 struct nlattr
*nl_reg_rule
;
3196 char *alpha2
= NULL
;
3197 int rem_reg_rules
= 0, r
= 0;
3198 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
3199 struct ieee80211_regdomain
*rd
= NULL
;
3201 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
3204 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
3207 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
3209 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
3212 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
3216 mutex_lock(&cfg80211_mutex
);
3218 if (!reg_is_valid_request(alpha2
)) {
3223 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
3224 (num_rules
* sizeof(struct ieee80211_reg_rule
));
3226 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
3232 rd
->n_reg_rules
= num_rules
;
3233 rd
->alpha2
[0] = alpha2
[0];
3234 rd
->alpha2
[1] = alpha2
[1];
3236 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
3238 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
3239 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
3241 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
3247 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
3253 BUG_ON(rule_idx
!= num_rules
);
3257 mutex_unlock(&cfg80211_mutex
);
3262 mutex_unlock(&cfg80211_mutex
);
3267 static int validate_scan_freqs(struct nlattr
*freqs
)
3269 struct nlattr
*attr1
, *attr2
;
3270 int n_channels
= 0, tmp1
, tmp2
;
3272 nla_for_each_nested(attr1
, freqs
, tmp1
) {
3275 * Some hardware has a limited channel list for
3276 * scanning, and it is pretty much nonsensical
3277 * to scan for a channel twice, so disallow that
3278 * and don't require drivers to check that the
3279 * channel list they get isn't longer than what
3280 * they can scan, as long as they can scan all
3281 * the channels they registered at once.
3283 nla_for_each_nested(attr2
, freqs
, tmp2
)
3284 if (attr1
!= attr2
&&
3285 nla_get_u32(attr1
) == nla_get_u32(attr2
))
3292 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
3294 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3295 struct net_device
*dev
= info
->user_ptr
[1];
3296 struct cfg80211_scan_request
*request
;
3297 struct nlattr
*attr
;
3298 struct wiphy
*wiphy
;
3299 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
3300 enum ieee80211_band band
;
3303 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3306 wiphy
= &rdev
->wiphy
;
3308 if (!rdev
->ops
->scan
)
3314 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3315 n_channels
= validate_scan_freqs(
3316 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
3322 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
3323 if (wiphy
->bands
[band
])
3324 n_channels
+= wiphy
->bands
[band
]->n_channels
;
3327 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
3328 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
3331 if (n_ssids
> wiphy
->max_scan_ssids
)
3334 if (info
->attrs
[NL80211_ATTR_IE
])
3335 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3339 if (ie_len
> wiphy
->max_scan_ie_len
)
3342 request
= kzalloc(sizeof(*request
)
3343 + sizeof(*request
->ssids
) * n_ssids
3344 + sizeof(*request
->channels
) * n_channels
3345 + ie_len
, GFP_KERNEL
);
3350 request
->ssids
= (void *)&request
->channels
[n_channels
];
3351 request
->n_ssids
= n_ssids
;
3354 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
3356 request
->ie
= (void *)(request
->channels
+ n_channels
);
3360 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3361 /* user specified, bail out if channel not found */
3362 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
3363 struct ieee80211_channel
*chan
;
3365 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
3372 /* ignore disabled channels */
3373 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3376 request
->channels
[i
] = chan
;
3381 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
3383 if (!wiphy
->bands
[band
])
3385 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
3386 struct ieee80211_channel
*chan
;
3388 chan
= &wiphy
->bands
[band
]->channels
[j
];
3390 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3393 request
->channels
[i
] = chan
;
3404 request
->n_channels
= i
;
3407 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
3408 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
3409 request
->ssids
[i
].ssid_len
= nla_len(attr
);
3410 if (request
->ssids
[i
].ssid_len
> IEEE80211_MAX_SSID_LEN
) {
3414 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
3419 if (info
->attrs
[NL80211_ATTR_IE
]) {
3420 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3421 memcpy((void *)request
->ie
,
3422 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
3427 request
->wiphy
= &rdev
->wiphy
;
3429 rdev
->scan_req
= request
;
3430 err
= rdev
->ops
->scan(&rdev
->wiphy
, dev
, request
);
3433 nl80211_send_scan_start(rdev
, dev
);
3437 rdev
->scan_req
= NULL
;
3444 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
3445 struct genl_info
*info
)
3447 struct cfg80211_sched_scan_request
*request
;
3448 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3449 struct net_device
*dev
= info
->user_ptr
[1];
3450 struct nlattr
*attr
;
3451 struct wiphy
*wiphy
;
3452 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
3454 enum ieee80211_band band
;
3457 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
3458 !rdev
->ops
->sched_scan_start
)
3461 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3464 if (rdev
->sched_scan_req
)
3465 return -EINPROGRESS
;
3467 if (!info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
3470 interval
= nla_get_u32(info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
3474 wiphy
= &rdev
->wiphy
;
3476 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3477 n_channels
= validate_scan_freqs(
3478 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
3484 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
3485 if (wiphy
->bands
[band
])
3486 n_channels
+= wiphy
->bands
[band
]->n_channels
;
3489 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
3490 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
3494 if (n_ssids
> wiphy
->max_scan_ssids
)
3497 if (info
->attrs
[NL80211_ATTR_IE
])
3498 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3502 if (ie_len
> wiphy
->max_scan_ie_len
)
3505 request
= kzalloc(sizeof(*request
)
3506 + sizeof(*request
->ssids
) * n_ssids
3507 + sizeof(*request
->channels
) * n_channels
3508 + ie_len
, GFP_KERNEL
);
3513 request
->ssids
= (void *)&request
->channels
[n_channels
];
3514 request
->n_ssids
= n_ssids
;
3517 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
3519 request
->ie
= (void *)(request
->channels
+ n_channels
);
3523 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3524 /* user specified, bail out if channel not found */
3525 nla_for_each_nested(attr
,
3526 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
3528 struct ieee80211_channel
*chan
;
3530 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
3537 /* ignore disabled channels */
3538 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3541 request
->channels
[i
] = chan
;
3546 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
3548 if (!wiphy
->bands
[band
])
3550 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
3551 struct ieee80211_channel
*chan
;
3553 chan
= &wiphy
->bands
[band
]->channels
[j
];
3555 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3558 request
->channels
[i
] = chan
;
3569 request
->n_channels
= i
;
3572 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
3573 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
3575 request
->ssids
[i
].ssid_len
= nla_len(attr
);
3576 if (request
->ssids
[i
].ssid_len
>
3577 IEEE80211_MAX_SSID_LEN
) {
3581 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
3587 if (info
->attrs
[NL80211_ATTR_IE
]) {
3588 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3589 memcpy((void *)request
->ie
,
3590 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
3595 request
->wiphy
= &rdev
->wiphy
;
3596 request
->interval
= interval
;
3598 err
= rdev
->ops
->sched_scan_start(&rdev
->wiphy
, dev
, request
);
3600 rdev
->sched_scan_req
= request
;
3601 nl80211_send_sched_scan(rdev
, dev
,
3602 NL80211_CMD_START_SCHED_SCAN
);
3612 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
3613 struct genl_info
*info
)
3615 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3617 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
3618 !rdev
->ops
->sched_scan_stop
)
3621 return __cfg80211_stop_sched_scan(rdev
, false);
3624 static int nl80211_send_bss(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
3625 struct cfg80211_registered_device
*rdev
,
3626 struct wireless_dev
*wdev
,
3627 struct cfg80211_internal_bss
*intbss
)
3629 struct cfg80211_bss
*res
= &intbss
->pub
;
3634 ASSERT_WDEV_LOCK(wdev
);
3636 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3637 NL80211_CMD_NEW_SCAN_RESULTS
);
3641 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
);
3642 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
);
3644 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
3646 goto nla_put_failure
;
3647 if (!is_zero_ether_addr(res
->bssid
))
3648 NLA_PUT(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
);
3649 if (res
->information_elements
&& res
->len_information_elements
)
3650 NLA_PUT(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
3651 res
->len_information_elements
,
3652 res
->information_elements
);
3653 if (res
->beacon_ies
&& res
->len_beacon_ies
&&
3654 res
->beacon_ies
!= res
->information_elements
)
3655 NLA_PUT(msg
, NL80211_BSS_BEACON_IES
,
3656 res
->len_beacon_ies
, res
->beacon_ies
);
3658 NLA_PUT_U64(msg
, NL80211_BSS_TSF
, res
->tsf
);
3659 if (res
->beacon_interval
)
3660 NLA_PUT_U16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
);
3661 NLA_PUT_U16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
);
3662 NLA_PUT_U32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
);
3663 NLA_PUT_U32(msg
, NL80211_BSS_SEEN_MS_AGO
,
3664 jiffies_to_msecs(jiffies
- intbss
->ts
));
3666 switch (rdev
->wiphy
.signal_type
) {
3667 case CFG80211_SIGNAL_TYPE_MBM
:
3668 NLA_PUT_U32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
);
3670 case CFG80211_SIGNAL_TYPE_UNSPEC
:
3671 NLA_PUT_U8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
);
3677 switch (wdev
->iftype
) {
3678 case NL80211_IFTYPE_P2P_CLIENT
:
3679 case NL80211_IFTYPE_STATION
:
3680 if (intbss
== wdev
->current_bss
)
3681 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3682 NL80211_BSS_STATUS_ASSOCIATED
);
3683 else for (i
= 0; i
< MAX_AUTH_BSSES
; i
++) {
3684 if (intbss
!= wdev
->auth_bsses
[i
])
3686 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3687 NL80211_BSS_STATUS_AUTHENTICATED
);
3691 case NL80211_IFTYPE_ADHOC
:
3692 if (intbss
== wdev
->current_bss
)
3693 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3694 NL80211_BSS_STATUS_IBSS_JOINED
);
3700 nla_nest_end(msg
, bss
);
3702 return genlmsg_end(msg
, hdr
);
3705 genlmsg_cancel(msg
, hdr
);
3709 static int nl80211_dump_scan(struct sk_buff
*skb
,
3710 struct netlink_callback
*cb
)
3712 struct cfg80211_registered_device
*rdev
;
3713 struct net_device
*dev
;
3714 struct cfg80211_internal_bss
*scan
;
3715 struct wireless_dev
*wdev
;
3716 int start
= cb
->args
[1], idx
= 0;
3719 err
= nl80211_prepare_netdev_dump(skb
, cb
, &rdev
, &dev
);
3723 wdev
= dev
->ieee80211_ptr
;
3726 spin_lock_bh(&rdev
->bss_lock
);
3727 cfg80211_bss_expire(rdev
);
3729 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
3732 if (nl80211_send_bss(skb
,
3733 NETLINK_CB(cb
->skb
).pid
,
3734 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3735 rdev
, wdev
, scan
) < 0) {
3741 spin_unlock_bh(&rdev
->bss_lock
);
3745 nl80211_finish_netdev_dump(rdev
);
3750 static int nl80211_send_survey(struct sk_buff
*msg
, u32 pid
, u32 seq
,
3751 int flags
, struct net_device
*dev
,
3752 struct survey_info
*survey
)
3755 struct nlattr
*infoattr
;
3757 /* Survey without a channel doesn't make sense */
3758 if (!survey
->channel
)
3761 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3762 NL80211_CMD_NEW_SURVEY_RESULTS
);
3766 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
3768 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
3770 goto nla_put_failure
;
3772 NLA_PUT_U32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
3773 survey
->channel
->center_freq
);
3774 if (survey
->filled
& SURVEY_INFO_NOISE_DBM
)
3775 NLA_PUT_U8(msg
, NL80211_SURVEY_INFO_NOISE
,
3777 if (survey
->filled
& SURVEY_INFO_IN_USE
)
3778 NLA_PUT_FLAG(msg
, NL80211_SURVEY_INFO_IN_USE
);
3779 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME
)
3780 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
3781 survey
->channel_time
);
3782 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
)
3783 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
3784 survey
->channel_time_busy
);
3785 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
)
3786 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
3787 survey
->channel_time_ext_busy
);
3788 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
)
3789 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
3790 survey
->channel_time_rx
);
3791 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
)
3792 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
3793 survey
->channel_time_tx
);
3795 nla_nest_end(msg
, infoattr
);
3797 return genlmsg_end(msg
, hdr
);
3800 genlmsg_cancel(msg
, hdr
);
3804 static int nl80211_dump_survey(struct sk_buff
*skb
,
3805 struct netlink_callback
*cb
)
3807 struct survey_info survey
;
3808 struct cfg80211_registered_device
*dev
;
3809 struct net_device
*netdev
;
3810 int survey_idx
= cb
->args
[1];
3813 res
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
3817 if (!dev
->ops
->dump_survey
) {
3823 res
= dev
->ops
->dump_survey(&dev
->wiphy
, netdev
, survey_idx
,
3830 if (nl80211_send_survey(skb
,
3831 NETLINK_CB(cb
->skb
).pid
,
3832 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3840 cb
->args
[1] = survey_idx
;
3843 nl80211_finish_netdev_dump(dev
);
3847 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
)
3849 return auth_type
<= NL80211_AUTHTYPE_MAX
;
3852 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
3854 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
3855 NL80211_WPA_VERSION_2
));
3858 static bool nl80211_valid_akm_suite(u32 akm
)
3860 return akm
== WLAN_AKM_SUITE_8021X
||
3861 akm
== WLAN_AKM_SUITE_PSK
;
3864 static bool nl80211_valid_cipher_suite(u32 cipher
)
3866 return cipher
== WLAN_CIPHER_SUITE_WEP40
||
3867 cipher
== WLAN_CIPHER_SUITE_WEP104
||
3868 cipher
== WLAN_CIPHER_SUITE_TKIP
||
3869 cipher
== WLAN_CIPHER_SUITE_CCMP
||
3870 cipher
== WLAN_CIPHER_SUITE_AES_CMAC
;
3874 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3876 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3877 struct net_device
*dev
= info
->user_ptr
[1];
3878 struct ieee80211_channel
*chan
;
3879 const u8
*bssid
, *ssid
, *ie
= NULL
;
3880 int err
, ssid_len
, ie_len
= 0;
3881 enum nl80211_auth_type auth_type
;
3882 struct key_parse key
;
3883 bool local_state_change
;
3885 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3888 if (!info
->attrs
[NL80211_ATTR_MAC
])
3891 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
3894 if (!info
->attrs
[NL80211_ATTR_SSID
])
3897 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
3900 err
= nl80211_parse_key(info
, &key
);
3905 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
3907 if (!key
.p
.key
|| !key
.p
.key_len
)
3909 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
3910 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
3911 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
3912 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
3924 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
3925 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
3934 if (!rdev
->ops
->auth
)
3937 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
3938 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
3941 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3942 chan
= ieee80211_get_channel(&rdev
->wiphy
,
3943 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3944 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
3947 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3948 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3950 if (info
->attrs
[NL80211_ATTR_IE
]) {
3951 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3952 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3955 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3956 if (!nl80211_valid_auth_type(auth_type
))
3959 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
3961 return cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
3962 ssid
, ssid_len
, ie
, ie_len
,
3963 key
.p
.key
, key
.p
.key_len
, key
.idx
,
3964 local_state_change
);
3967 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
3968 struct genl_info
*info
,
3969 struct cfg80211_crypto_settings
*settings
,
3972 memset(settings
, 0, sizeof(*settings
));
3974 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
3976 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
3978 proto
= nla_get_u16(
3979 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
3980 settings
->control_port_ethertype
= cpu_to_be16(proto
);
3981 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
3984 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
3985 settings
->control_port_no_encrypt
= true;
3987 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
3989 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
3993 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
3994 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
3995 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
3997 if (len
% sizeof(u32
))
4000 if (settings
->n_ciphers_pairwise
> cipher_limit
)
4003 memcpy(settings
->ciphers_pairwise
, data
, len
);
4005 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
4006 if (!nl80211_valid_cipher_suite(
4007 settings
->ciphers_pairwise
[i
]))
4011 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
4012 settings
->cipher_group
=
4013 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
4014 if (!nl80211_valid_cipher_suite(settings
->cipher_group
))
4018 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
4019 settings
->wpa_versions
=
4020 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
4021 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
4025 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
4029 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
4030 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
4031 settings
->n_akm_suites
= len
/ sizeof(u32
);
4033 if (len
% sizeof(u32
))
4036 memcpy(settings
->akm_suites
, data
, len
);
4038 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
4039 if (!nl80211_valid_akm_suite(settings
->akm_suites
[i
]))
4046 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
4048 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4049 struct net_device
*dev
= info
->user_ptr
[1];
4050 struct cfg80211_crypto_settings crypto
;
4051 struct ieee80211_channel
*chan
;
4052 const u8
*bssid
, *ssid
, *ie
= NULL
, *prev_bssid
= NULL
;
4053 int err
, ssid_len
, ie_len
= 0;
4054 bool use_mfp
= false;
4056 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4059 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
4060 !info
->attrs
[NL80211_ATTR_SSID
] ||
4061 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4064 if (!rdev
->ops
->assoc
)
4067 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4068 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4071 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4073 chan
= ieee80211_get_channel(&rdev
->wiphy
,
4074 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4075 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
4078 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4079 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4081 if (info
->attrs
[NL80211_ATTR_IE
]) {
4082 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4083 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4086 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
4087 enum nl80211_mfp mfp
=
4088 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
4089 if (mfp
== NL80211_MFP_REQUIRED
)
4091 else if (mfp
!= NL80211_MFP_NO
)
4095 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
4096 prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
4098 err
= nl80211_crypto_settings(rdev
, info
, &crypto
, 1);
4100 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
, prev_bssid
,
4101 ssid
, ssid_len
, ie
, ie_len
, use_mfp
,
4107 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
4109 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4110 struct net_device
*dev
= info
->user_ptr
[1];
4111 const u8
*ie
= NULL
, *bssid
;
4114 bool local_state_change
;
4116 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4119 if (!info
->attrs
[NL80211_ATTR_MAC
])
4122 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4125 if (!rdev
->ops
->deauth
)
4128 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4129 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4132 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4134 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4135 if (reason_code
== 0) {
4136 /* Reason Code 0 is reserved */
4140 if (info
->attrs
[NL80211_ATTR_IE
]) {
4141 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4142 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4145 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
4147 return cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
4148 local_state_change
);
4151 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
4153 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4154 struct net_device
*dev
= info
->user_ptr
[1];
4155 const u8
*ie
= NULL
, *bssid
;
4158 bool local_state_change
;
4160 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4163 if (!info
->attrs
[NL80211_ATTR_MAC
])
4166 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4169 if (!rdev
->ops
->disassoc
)
4172 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4173 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4176 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4178 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4179 if (reason_code
== 0) {
4180 /* Reason Code 0 is reserved */
4184 if (info
->attrs
[NL80211_ATTR_IE
]) {
4185 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4186 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4189 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
4191 return cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
4192 local_state_change
);
4196 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
4197 int mcast_rate
[IEEE80211_NUM_BANDS
],
4200 struct wiphy
*wiphy
= &rdev
->wiphy
;
4204 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
4205 struct ieee80211_supported_band
*sband
;
4207 sband
= wiphy
->bands
[band
];
4211 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
4212 if (sband
->bitrates
[i
].bitrate
== rateval
) {
4213 mcast_rate
[band
] = i
+ 1;
4223 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
4225 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4226 struct net_device
*dev
= info
->user_ptr
[1];
4227 struct cfg80211_ibss_params ibss
;
4228 struct wiphy
*wiphy
;
4229 struct cfg80211_cached_keys
*connkeys
= NULL
;
4232 memset(&ibss
, 0, sizeof(ibss
));
4234 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4237 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
4238 !info
->attrs
[NL80211_ATTR_SSID
] ||
4239 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
4242 ibss
.beacon_interval
= 100;
4244 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
4245 ibss
.beacon_interval
=
4246 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
4247 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
4251 if (!rdev
->ops
->join_ibss
)
4254 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
4257 wiphy
= &rdev
->wiphy
;
4259 if (info
->attrs
[NL80211_ATTR_MAC
])
4260 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4261 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4262 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4264 if (info
->attrs
[NL80211_ATTR_IE
]) {
4265 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4266 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4269 ibss
.channel
= ieee80211_get_channel(wiphy
,
4270 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4271 if (!ibss
.channel
||
4272 ibss
.channel
->flags
& IEEE80211_CHAN_NO_IBSS
||
4273 ibss
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
4276 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
4277 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
4279 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
4281 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4283 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4284 struct ieee80211_supported_band
*sband
=
4285 wiphy
->bands
[ibss
.channel
->band
];
4291 for (i
= 0; i
< n_rates
; i
++) {
4292 int rate
= (rates
[i
] & 0x7f) * 5;
4295 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
4296 if (sband
->bitrates
[j
].bitrate
== rate
) {
4298 ibss
.basic_rates
|= BIT(j
);
4307 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
4308 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
4309 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
4312 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
4313 connkeys
= nl80211_parse_connkeys(rdev
,
4314 info
->attrs
[NL80211_ATTR_KEYS
]);
4315 if (IS_ERR(connkeys
))
4316 return PTR_ERR(connkeys
);
4319 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
4325 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
4327 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4328 struct net_device
*dev
= info
->user_ptr
[1];
4330 if (!rdev
->ops
->leave_ibss
)
4333 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
4336 return cfg80211_leave_ibss(rdev
, dev
, false);
4339 #ifdef CONFIG_NL80211_TESTMODE
4340 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
4344 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
4346 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4349 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
4353 if (rdev
->ops
->testmode_cmd
) {
4354 rdev
->testmode_info
= info
;
4355 err
= rdev
->ops
->testmode_cmd(&rdev
->wiphy
,
4356 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
4357 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
4358 rdev
->testmode_info
= NULL
;
4364 static struct sk_buff
*
4365 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
4366 int approxlen
, u32 pid
, u32 seq
, gfp_t gfp
)
4368 struct sk_buff
*skb
;
4370 struct nlattr
*data
;
4372 skb
= nlmsg_new(approxlen
+ 100, gfp
);
4376 hdr
= nl80211hdr_put(skb
, pid
, seq
, 0, NL80211_CMD_TESTMODE
);
4382 NLA_PUT_U32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4383 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
4385 ((void **)skb
->cb
)[0] = rdev
;
4386 ((void **)skb
->cb
)[1] = hdr
;
4387 ((void **)skb
->cb
)[2] = data
;
4396 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
4399 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4401 if (WARN_ON(!rdev
->testmode_info
))
4404 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
4405 rdev
->testmode_info
->snd_pid
,
4406 rdev
->testmode_info
->snd_seq
,
4409 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
4411 int cfg80211_testmode_reply(struct sk_buff
*skb
)
4413 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
4414 void *hdr
= ((void **)skb
->cb
)[1];
4415 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4417 if (WARN_ON(!rdev
->testmode_info
)) {
4422 nla_nest_end(skb
, data
);
4423 genlmsg_end(skb
, hdr
);
4424 return genlmsg_reply(skb
, rdev
->testmode_info
);
4426 EXPORT_SYMBOL(cfg80211_testmode_reply
);
4428 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
4429 int approxlen
, gfp_t gfp
)
4431 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4433 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
4435 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
4437 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
4439 void *hdr
= ((void **)skb
->cb
)[1];
4440 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4442 nla_nest_end(skb
, data
);
4443 genlmsg_end(skb
, hdr
);
4444 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
4446 EXPORT_SYMBOL(cfg80211_testmode_event
);
4449 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
4451 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4452 struct net_device
*dev
= info
->user_ptr
[1];
4453 struct cfg80211_connect_params connect
;
4454 struct wiphy
*wiphy
;
4455 struct cfg80211_cached_keys
*connkeys
= NULL
;
4458 memset(&connect
, 0, sizeof(connect
));
4460 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4463 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
4464 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
4467 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
4469 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4470 if (!nl80211_valid_auth_type(connect
.auth_type
))
4473 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
4475 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
4477 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
4478 NL80211_MAX_NR_CIPHER_SUITES
);
4482 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4483 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4486 wiphy
= &rdev
->wiphy
;
4488 if (info
->attrs
[NL80211_ATTR_MAC
])
4489 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4490 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4491 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4493 if (info
->attrs
[NL80211_ATTR_IE
]) {
4494 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4495 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4498 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
4500 ieee80211_get_channel(wiphy
,
4501 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4502 if (!connect
.channel
||
4503 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
4507 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
4508 connkeys
= nl80211_parse_connkeys(rdev
,
4509 info
->attrs
[NL80211_ATTR_KEYS
]);
4510 if (IS_ERR(connkeys
))
4511 return PTR_ERR(connkeys
);
4514 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
4520 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
4522 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4523 struct net_device
*dev
= info
->user_ptr
[1];
4526 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4527 reason
= WLAN_REASON_DEAUTH_LEAVING
;
4529 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4534 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4535 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4538 return cfg80211_disconnect(rdev
, dev
, reason
, true);
4541 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
4543 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4548 if (!info
->attrs
[NL80211_ATTR_PID
])
4551 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
4553 net
= get_net_ns_by_pid(pid
);
4555 return PTR_ERR(net
);
4559 /* check if anything to do */
4560 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
4561 err
= cfg80211_switch_netns(rdev
, net
);
4567 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4569 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4570 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
4571 struct cfg80211_pmksa
*pmksa
) = NULL
;
4572 struct net_device
*dev
= info
->user_ptr
[1];
4573 struct cfg80211_pmksa pmksa
;
4575 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
4577 if (!info
->attrs
[NL80211_ATTR_MAC
])
4580 if (!info
->attrs
[NL80211_ATTR_PMKID
])
4583 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
4584 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4586 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4587 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4590 switch (info
->genlhdr
->cmd
) {
4591 case NL80211_CMD_SET_PMKSA
:
4592 rdev_ops
= rdev
->ops
->set_pmksa
;
4594 case NL80211_CMD_DEL_PMKSA
:
4595 rdev_ops
= rdev
->ops
->del_pmksa
;
4605 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
4608 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4610 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4611 struct net_device
*dev
= info
->user_ptr
[1];
4613 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4614 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4617 if (!rdev
->ops
->flush_pmksa
)
4620 return rdev
->ops
->flush_pmksa(&rdev
->wiphy
, dev
);
4623 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
4624 struct genl_info
*info
)
4626 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4627 struct net_device
*dev
= info
->user_ptr
[1];
4628 struct ieee80211_channel
*chan
;
4629 struct sk_buff
*msg
;
4632 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
4636 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
4637 !info
->attrs
[NL80211_ATTR_DURATION
])
4640 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
4643 * We should be on that channel for at least one jiffie,
4644 * and more than 5 seconds seems excessive.
4646 if (!duration
|| !msecs_to_jiffies(duration
) ||
4647 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
4650 if (!rdev
->ops
->remain_on_channel
)
4653 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
4654 channel_type
= nla_get_u32(
4655 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
4656 if (channel_type
!= NL80211_CHAN_NO_HT
&&
4657 channel_type
!= NL80211_CHAN_HT20
&&
4658 channel_type
!= NL80211_CHAN_HT40PLUS
&&
4659 channel_type
!= NL80211_CHAN_HT40MINUS
)
4663 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
4664 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
4668 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4672 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4673 NL80211_CMD_REMAIN_ON_CHANNEL
);
4680 err
= rdev
->ops
->remain_on_channel(&rdev
->wiphy
, dev
, chan
,
4681 channel_type
, duration
, &cookie
);
4686 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
4688 genlmsg_end(msg
, hdr
);
4690 return genlmsg_reply(msg
, info
);
4699 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
4700 struct genl_info
*info
)
4702 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4703 struct net_device
*dev
= info
->user_ptr
[1];
4706 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
4709 if (!rdev
->ops
->cancel_remain_on_channel
)
4712 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
4714 return rdev
->ops
->cancel_remain_on_channel(&rdev
->wiphy
, dev
, cookie
);
4717 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
4718 u8
*rates
, u8 rates_len
)
4723 for (i
= 0; i
< rates_len
; i
++) {
4724 int rate
= (rates
[i
] & 0x7f) * 5;
4726 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
4727 struct ieee80211_rate
*srate
=
4728 &sband
->bitrates
[ridx
];
4729 if (rate
== srate
->bitrate
) {
4734 if (ridx
== sband
->n_bitrates
)
4735 return 0; /* rate not found */
4741 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
4742 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
4743 .len
= NL80211_MAX_SUPP_RATES
},
4746 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
4747 struct genl_info
*info
)
4749 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
4750 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4751 struct cfg80211_bitrate_mask mask
;
4753 struct net_device
*dev
= info
->user_ptr
[1];
4754 struct nlattr
*tx_rates
;
4755 struct ieee80211_supported_band
*sband
;
4757 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
4760 if (!rdev
->ops
->set_bitrate_mask
)
4763 memset(&mask
, 0, sizeof(mask
));
4764 /* Default to all rates enabled */
4765 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
4766 sband
= rdev
->wiphy
.bands
[i
];
4767 mask
.control
[i
].legacy
=
4768 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
4772 * The nested attribute uses enum nl80211_band as the index. This maps
4773 * directly to the enum ieee80211_band values used in cfg80211.
4775 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
4777 enum ieee80211_band band
= nla_type(tx_rates
);
4778 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
4780 sband
= rdev
->wiphy
.bands
[band
];
4783 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
4784 nla_len(tx_rates
), nl80211_txattr_policy
);
4785 if (tb
[NL80211_TXRATE_LEGACY
]) {
4786 mask
.control
[band
].legacy
= rateset_to_mask(
4788 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
4789 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
4790 if (mask
.control
[band
].legacy
== 0)
4795 return rdev
->ops
->set_bitrate_mask(&rdev
->wiphy
, dev
, NULL
, &mask
);
4798 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
4800 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4801 struct net_device
*dev
= info
->user_ptr
[1];
4802 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
4804 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
4807 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
4808 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
4810 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4811 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
4812 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
4813 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4814 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4815 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
4816 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4819 /* not much point in registering if we can't reply */
4820 if (!rdev
->ops
->mgmt_tx
)
4823 return cfg80211_mlme_register_mgmt(dev
->ieee80211_ptr
, info
->snd_pid
,
4825 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
4826 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
4829 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
4831 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4832 struct net_device
*dev
= info
->user_ptr
[1];
4833 struct ieee80211_channel
*chan
;
4834 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
4835 bool channel_type_valid
= false;
4840 struct sk_buff
*msg
;
4841 unsigned int wait
= 0;
4844 if (!info
->attrs
[NL80211_ATTR_FRAME
] ||
4845 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4848 if (!rdev
->ops
->mgmt_tx
)
4851 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4852 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
4853 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
4854 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4855 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4856 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
4857 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4860 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
4861 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
4863 wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
4866 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
4867 channel_type
= nla_get_u32(
4868 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
4869 if (channel_type
!= NL80211_CHAN_NO_HT
&&
4870 channel_type
!= NL80211_CHAN_HT20
&&
4871 channel_type
!= NL80211_CHAN_HT40PLUS
&&
4872 channel_type
!= NL80211_CHAN_HT40MINUS
)
4874 channel_type_valid
= true;
4877 offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
4879 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
4880 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
4884 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4888 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4895 err
= cfg80211_mlme_mgmt_tx(rdev
, dev
, chan
, offchan
, channel_type
,
4896 channel_type_valid
, wait
,
4897 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
4898 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
4903 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
4905 genlmsg_end(msg
, hdr
);
4906 return genlmsg_reply(msg
, info
);
4915 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
4917 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4918 struct net_device
*dev
= info
->user_ptr
[1];
4921 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
4924 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
4927 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4928 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
4929 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
4930 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4931 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4932 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4935 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
4937 return rdev
->ops
->mgmt_tx_cancel_wait(&rdev
->wiphy
, dev
, cookie
);
4940 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
4942 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4943 struct wireless_dev
*wdev
;
4944 struct net_device
*dev
= info
->user_ptr
[1];
4949 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
4952 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
4954 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
4957 wdev
= dev
->ieee80211_ptr
;
4959 if (!rdev
->ops
->set_power_mgmt
)
4962 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
4964 if (state
== wdev
->ps
)
4967 err
= rdev
->ops
->set_power_mgmt(wdev
->wiphy
, dev
, state
,
4974 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
4976 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4977 enum nl80211_ps_state ps_state
;
4978 struct wireless_dev
*wdev
;
4979 struct net_device
*dev
= info
->user_ptr
[1];
4980 struct sk_buff
*msg
;
4984 wdev
= dev
->ieee80211_ptr
;
4986 if (!rdev
->ops
->set_power_mgmt
)
4989 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4993 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4994 NL80211_CMD_GET_POWER_SAVE
);
5001 ps_state
= NL80211_PS_ENABLED
;
5003 ps_state
= NL80211_PS_DISABLED
;
5005 NLA_PUT_U32(msg
, NL80211_ATTR_PS_STATE
, ps_state
);
5007 genlmsg_end(msg
, hdr
);
5008 return genlmsg_reply(msg
, info
);
5017 static struct nla_policy
5018 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
5019 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
5020 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
5021 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
5024 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
5025 s32 threshold
, u32 hysteresis
)
5027 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5028 struct wireless_dev
*wdev
;
5029 struct net_device
*dev
= info
->user_ptr
[1];
5034 wdev
= dev
->ieee80211_ptr
;
5036 if (!rdev
->ops
->set_cqm_rssi_config
)
5039 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
5040 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5043 return rdev
->ops
->set_cqm_rssi_config(wdev
->wiphy
, dev
,
5044 threshold
, hysteresis
);
5047 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
5049 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
5053 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
5059 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
5060 nl80211_attr_cqm_policy
);
5064 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
5065 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
5068 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
5069 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
5070 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
5078 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
5080 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5081 struct net_device
*dev
= info
->user_ptr
[1];
5082 struct mesh_config cfg
;
5083 struct mesh_setup setup
;
5086 /* start with default */
5087 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
5088 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
5090 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
5091 /* and parse parameters if given */
5092 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
5097 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
5098 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
5101 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
5102 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
5104 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
5105 /* parse additional setup parameters if given */
5106 err
= nl80211_parse_mesh_setup(info
, &setup
);
5111 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
5114 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
5116 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5117 struct net_device
*dev
= info
->user_ptr
[1];
5119 return cfg80211_leave_mesh(rdev
, dev
);
5122 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
5124 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5125 struct sk_buff
*msg
;
5128 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
5131 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5135 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
5136 NL80211_CMD_GET_WOWLAN
);
5138 goto nla_put_failure
;
5141 struct nlattr
*nl_wowlan
;
5143 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
5145 goto nla_put_failure
;
5147 if (rdev
->wowlan
->any
)
5148 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_ANY
);
5149 if (rdev
->wowlan
->disconnect
)
5150 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
);
5151 if (rdev
->wowlan
->magic_pkt
)
5152 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
);
5153 if (rdev
->wowlan
->n_patterns
) {
5154 struct nlattr
*nl_pats
, *nl_pat
;
5157 nl_pats
= nla_nest_start(msg
,
5158 NL80211_WOWLAN_TRIG_PKT_PATTERN
);
5160 goto nla_put_failure
;
5162 for (i
= 0; i
< rdev
->wowlan
->n_patterns
; i
++) {
5163 nl_pat
= nla_nest_start(msg
, i
+ 1);
5165 goto nla_put_failure
;
5166 pat_len
= rdev
->wowlan
->patterns
[i
].pattern_len
;
5167 NLA_PUT(msg
, NL80211_WOWLAN_PKTPAT_MASK
,
5168 DIV_ROUND_UP(pat_len
, 8),
5169 rdev
->wowlan
->patterns
[i
].mask
);
5170 NLA_PUT(msg
, NL80211_WOWLAN_PKTPAT_PATTERN
,
5172 rdev
->wowlan
->patterns
[i
].pattern
);
5173 nla_nest_end(msg
, nl_pat
);
5175 nla_nest_end(msg
, nl_pats
);
5178 nla_nest_end(msg
, nl_wowlan
);
5181 genlmsg_end(msg
, hdr
);
5182 return genlmsg_reply(msg
, info
);
5189 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
5191 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5192 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
5193 struct cfg80211_wowlan no_triggers
= {};
5194 struct cfg80211_wowlan new_triggers
= {};
5195 struct wiphy_wowlan_support
*wowlan
= &rdev
->wiphy
.wowlan
;
5198 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
5201 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
])
5204 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
5205 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
5206 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
5207 nl80211_wowlan_policy
);
5211 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
5212 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
5214 new_triggers
.any
= true;
5217 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
5218 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
5220 new_triggers
.disconnect
= true;
5223 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
5224 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
5226 new_triggers
.magic_pkt
= true;
5229 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
5232 int rem
, pat_len
, mask_len
;
5233 struct nlattr
*pat_tb
[NUM_NL80211_WOWLAN_PKTPAT
];
5235 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
5238 if (n_patterns
> wowlan
->n_patterns
)
5241 new_triggers
.patterns
= kcalloc(n_patterns
,
5242 sizeof(new_triggers
.patterns
[0]),
5244 if (!new_triggers
.patterns
)
5247 new_triggers
.n_patterns
= n_patterns
;
5250 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
5252 nla_parse(pat_tb
, MAX_NL80211_WOWLAN_PKTPAT
,
5253 nla_data(pat
), nla_len(pat
), NULL
);
5255 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
] ||
5256 !pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
])
5258 pat_len
= nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]);
5259 mask_len
= DIV_ROUND_UP(pat_len
, 8);
5260 if (nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]) !=
5263 if (pat_len
> wowlan
->pattern_max_len
||
5264 pat_len
< wowlan
->pattern_min_len
)
5267 new_triggers
.patterns
[i
].mask
=
5268 kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
5269 if (!new_triggers
.patterns
[i
].mask
) {
5273 new_triggers
.patterns
[i
].pattern
=
5274 new_triggers
.patterns
[i
].mask
+ mask_len
;
5275 memcpy(new_triggers
.patterns
[i
].mask
,
5276 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]),
5278 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
5279 memcpy(new_triggers
.patterns
[i
].pattern
,
5280 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]),
5286 if (memcmp(&new_triggers
, &no_triggers
, sizeof(new_triggers
))) {
5287 struct cfg80211_wowlan
*ntrig
;
5288 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
),
5294 cfg80211_rdev_free_wowlan(rdev
);
5295 rdev
->wowlan
= ntrig
;
5298 cfg80211_rdev_free_wowlan(rdev
);
5299 rdev
->wowlan
= NULL
;
5304 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
5305 kfree(new_triggers
.patterns
[i
].mask
);
5306 kfree(new_triggers
.patterns
);
5310 #define NL80211_FLAG_NEED_WIPHY 0x01
5311 #define NL80211_FLAG_NEED_NETDEV 0x02
5312 #define NL80211_FLAG_NEED_RTNL 0x04
5313 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
5314 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
5315 NL80211_FLAG_CHECK_NETDEV_UP)
5317 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
5318 struct genl_info
*info
)
5320 struct cfg80211_registered_device
*rdev
;
5321 struct net_device
*dev
;
5323 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
5328 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
5329 rdev
= cfg80211_get_dev_from_info(info
);
5333 return PTR_ERR(rdev
);
5335 info
->user_ptr
[0] = rdev
;
5336 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
5337 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
5343 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
5344 !netif_running(dev
)) {
5345 cfg80211_unlock_rdev(rdev
);
5351 info
->user_ptr
[0] = rdev
;
5352 info
->user_ptr
[1] = dev
;
5358 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
5359 struct genl_info
*info
)
5361 if (info
->user_ptr
[0])
5362 cfg80211_unlock_rdev(info
->user_ptr
[0]);
5363 if (info
->user_ptr
[1])
5364 dev_put(info
->user_ptr
[1]);
5365 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
5369 static struct genl_ops nl80211_ops
[] = {
5371 .cmd
= NL80211_CMD_GET_WIPHY
,
5372 .doit
= nl80211_get_wiphy
,
5373 .dumpit
= nl80211_dump_wiphy
,
5374 .policy
= nl80211_policy
,
5375 /* can be retrieved by unprivileged users */
5376 .internal_flags
= NL80211_FLAG_NEED_WIPHY
,
5379 .cmd
= NL80211_CMD_SET_WIPHY
,
5380 .doit
= nl80211_set_wiphy
,
5381 .policy
= nl80211_policy
,
5382 .flags
= GENL_ADMIN_PERM
,
5383 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
5386 .cmd
= NL80211_CMD_GET_INTERFACE
,
5387 .doit
= nl80211_get_interface
,
5388 .dumpit
= nl80211_dump_interface
,
5389 .policy
= nl80211_policy
,
5390 /* can be retrieved by unprivileged users */
5391 .internal_flags
= NL80211_FLAG_NEED_NETDEV
,
5394 .cmd
= NL80211_CMD_SET_INTERFACE
,
5395 .doit
= nl80211_set_interface
,
5396 .policy
= nl80211_policy
,
5397 .flags
= GENL_ADMIN_PERM
,
5398 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5399 NL80211_FLAG_NEED_RTNL
,
5402 .cmd
= NL80211_CMD_NEW_INTERFACE
,
5403 .doit
= nl80211_new_interface
,
5404 .policy
= nl80211_policy
,
5405 .flags
= GENL_ADMIN_PERM
,
5406 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
5407 NL80211_FLAG_NEED_RTNL
,
5410 .cmd
= NL80211_CMD_DEL_INTERFACE
,
5411 .doit
= nl80211_del_interface
,
5412 .policy
= nl80211_policy
,
5413 .flags
= GENL_ADMIN_PERM
,
5414 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5415 NL80211_FLAG_NEED_RTNL
,
5418 .cmd
= NL80211_CMD_GET_KEY
,
5419 .doit
= nl80211_get_key
,
5420 .policy
= nl80211_policy
,
5421 .flags
= GENL_ADMIN_PERM
,
5422 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5423 NL80211_FLAG_NEED_RTNL
,
5426 .cmd
= NL80211_CMD_SET_KEY
,
5427 .doit
= nl80211_set_key
,
5428 .policy
= nl80211_policy
,
5429 .flags
= GENL_ADMIN_PERM
,
5430 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5431 NL80211_FLAG_NEED_RTNL
,
5434 .cmd
= NL80211_CMD_NEW_KEY
,
5435 .doit
= nl80211_new_key
,
5436 .policy
= nl80211_policy
,
5437 .flags
= GENL_ADMIN_PERM
,
5438 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5439 NL80211_FLAG_NEED_RTNL
,
5442 .cmd
= NL80211_CMD_DEL_KEY
,
5443 .doit
= nl80211_del_key
,
5444 .policy
= nl80211_policy
,
5445 .flags
= GENL_ADMIN_PERM
,
5446 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5447 NL80211_FLAG_NEED_RTNL
,
5450 .cmd
= NL80211_CMD_SET_BEACON
,
5451 .policy
= nl80211_policy
,
5452 .flags
= GENL_ADMIN_PERM
,
5453 .doit
= nl80211_addset_beacon
,
5454 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5455 NL80211_FLAG_NEED_RTNL
,
5458 .cmd
= NL80211_CMD_NEW_BEACON
,
5459 .policy
= nl80211_policy
,
5460 .flags
= GENL_ADMIN_PERM
,
5461 .doit
= nl80211_addset_beacon
,
5462 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5463 NL80211_FLAG_NEED_RTNL
,
5466 .cmd
= NL80211_CMD_DEL_BEACON
,
5467 .policy
= nl80211_policy
,
5468 .flags
= GENL_ADMIN_PERM
,
5469 .doit
= nl80211_del_beacon
,
5470 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5471 NL80211_FLAG_NEED_RTNL
,
5474 .cmd
= NL80211_CMD_GET_STATION
,
5475 .doit
= nl80211_get_station
,
5476 .dumpit
= nl80211_dump_station
,
5477 .policy
= nl80211_policy
,
5478 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5479 NL80211_FLAG_NEED_RTNL
,
5482 .cmd
= NL80211_CMD_SET_STATION
,
5483 .doit
= nl80211_set_station
,
5484 .policy
= nl80211_policy
,
5485 .flags
= GENL_ADMIN_PERM
,
5486 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5487 NL80211_FLAG_NEED_RTNL
,
5490 .cmd
= NL80211_CMD_NEW_STATION
,
5491 .doit
= nl80211_new_station
,
5492 .policy
= nl80211_policy
,
5493 .flags
= GENL_ADMIN_PERM
,
5494 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5495 NL80211_FLAG_NEED_RTNL
,
5498 .cmd
= NL80211_CMD_DEL_STATION
,
5499 .doit
= nl80211_del_station
,
5500 .policy
= nl80211_policy
,
5501 .flags
= GENL_ADMIN_PERM
,
5502 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5503 NL80211_FLAG_NEED_RTNL
,
5506 .cmd
= NL80211_CMD_GET_MPATH
,
5507 .doit
= nl80211_get_mpath
,
5508 .dumpit
= nl80211_dump_mpath
,
5509 .policy
= nl80211_policy
,
5510 .flags
= GENL_ADMIN_PERM
,
5511 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5512 NL80211_FLAG_NEED_RTNL
,
5515 .cmd
= NL80211_CMD_SET_MPATH
,
5516 .doit
= nl80211_set_mpath
,
5517 .policy
= nl80211_policy
,
5518 .flags
= GENL_ADMIN_PERM
,
5519 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5520 NL80211_FLAG_NEED_RTNL
,
5523 .cmd
= NL80211_CMD_NEW_MPATH
,
5524 .doit
= nl80211_new_mpath
,
5525 .policy
= nl80211_policy
,
5526 .flags
= GENL_ADMIN_PERM
,
5527 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5528 NL80211_FLAG_NEED_RTNL
,
5531 .cmd
= NL80211_CMD_DEL_MPATH
,
5532 .doit
= nl80211_del_mpath
,
5533 .policy
= nl80211_policy
,
5534 .flags
= GENL_ADMIN_PERM
,
5535 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5536 NL80211_FLAG_NEED_RTNL
,
5539 .cmd
= NL80211_CMD_SET_BSS
,
5540 .doit
= nl80211_set_bss
,
5541 .policy
= nl80211_policy
,
5542 .flags
= GENL_ADMIN_PERM
,
5543 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5544 NL80211_FLAG_NEED_RTNL
,
5547 .cmd
= NL80211_CMD_GET_REG
,
5548 .doit
= nl80211_get_reg
,
5549 .policy
= nl80211_policy
,
5550 /* can be retrieved by unprivileged users */
5553 .cmd
= NL80211_CMD_SET_REG
,
5554 .doit
= nl80211_set_reg
,
5555 .policy
= nl80211_policy
,
5556 .flags
= GENL_ADMIN_PERM
,
5559 .cmd
= NL80211_CMD_REQ_SET_REG
,
5560 .doit
= nl80211_req_set_reg
,
5561 .policy
= nl80211_policy
,
5562 .flags
= GENL_ADMIN_PERM
,
5565 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
5566 .doit
= nl80211_get_mesh_config
,
5567 .policy
= nl80211_policy
,
5568 /* can be retrieved by unprivileged users */
5569 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5570 NL80211_FLAG_NEED_RTNL
,
5573 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
5574 .doit
= nl80211_update_mesh_config
,
5575 .policy
= nl80211_policy
,
5576 .flags
= GENL_ADMIN_PERM
,
5577 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5578 NL80211_FLAG_NEED_RTNL
,
5581 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
5582 .doit
= nl80211_trigger_scan
,
5583 .policy
= nl80211_policy
,
5584 .flags
= GENL_ADMIN_PERM
,
5585 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5586 NL80211_FLAG_NEED_RTNL
,
5589 .cmd
= NL80211_CMD_GET_SCAN
,
5590 .policy
= nl80211_policy
,
5591 .dumpit
= nl80211_dump_scan
,
5594 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
5595 .doit
= nl80211_start_sched_scan
,
5596 .policy
= nl80211_policy
,
5597 .flags
= GENL_ADMIN_PERM
,
5598 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5599 NL80211_FLAG_NEED_RTNL
,
5602 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
5603 .doit
= nl80211_stop_sched_scan
,
5604 .policy
= nl80211_policy
,
5605 .flags
= GENL_ADMIN_PERM
,
5606 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5607 NL80211_FLAG_NEED_RTNL
,
5610 .cmd
= NL80211_CMD_AUTHENTICATE
,
5611 .doit
= nl80211_authenticate
,
5612 .policy
= nl80211_policy
,
5613 .flags
= GENL_ADMIN_PERM
,
5614 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5615 NL80211_FLAG_NEED_RTNL
,
5618 .cmd
= NL80211_CMD_ASSOCIATE
,
5619 .doit
= nl80211_associate
,
5620 .policy
= nl80211_policy
,
5621 .flags
= GENL_ADMIN_PERM
,
5622 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5623 NL80211_FLAG_NEED_RTNL
,
5626 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
5627 .doit
= nl80211_deauthenticate
,
5628 .policy
= nl80211_policy
,
5629 .flags
= GENL_ADMIN_PERM
,
5630 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5631 NL80211_FLAG_NEED_RTNL
,
5634 .cmd
= NL80211_CMD_DISASSOCIATE
,
5635 .doit
= nl80211_disassociate
,
5636 .policy
= nl80211_policy
,
5637 .flags
= GENL_ADMIN_PERM
,
5638 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5639 NL80211_FLAG_NEED_RTNL
,
5642 .cmd
= NL80211_CMD_JOIN_IBSS
,
5643 .doit
= nl80211_join_ibss
,
5644 .policy
= nl80211_policy
,
5645 .flags
= GENL_ADMIN_PERM
,
5646 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5647 NL80211_FLAG_NEED_RTNL
,
5650 .cmd
= NL80211_CMD_LEAVE_IBSS
,
5651 .doit
= nl80211_leave_ibss
,
5652 .policy
= nl80211_policy
,
5653 .flags
= GENL_ADMIN_PERM
,
5654 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5655 NL80211_FLAG_NEED_RTNL
,
5657 #ifdef CONFIG_NL80211_TESTMODE
5659 .cmd
= NL80211_CMD_TESTMODE
,
5660 .doit
= nl80211_testmode_do
,
5661 .policy
= nl80211_policy
,
5662 .flags
= GENL_ADMIN_PERM
,
5663 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
5664 NL80211_FLAG_NEED_RTNL
,
5668 .cmd
= NL80211_CMD_CONNECT
,
5669 .doit
= nl80211_connect
,
5670 .policy
= nl80211_policy
,
5671 .flags
= GENL_ADMIN_PERM
,
5672 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5673 NL80211_FLAG_NEED_RTNL
,
5676 .cmd
= NL80211_CMD_DISCONNECT
,
5677 .doit
= nl80211_disconnect
,
5678 .policy
= nl80211_policy
,
5679 .flags
= GENL_ADMIN_PERM
,
5680 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5681 NL80211_FLAG_NEED_RTNL
,
5684 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
5685 .doit
= nl80211_wiphy_netns
,
5686 .policy
= nl80211_policy
,
5687 .flags
= GENL_ADMIN_PERM
,
5688 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
5689 NL80211_FLAG_NEED_RTNL
,
5692 .cmd
= NL80211_CMD_GET_SURVEY
,
5693 .policy
= nl80211_policy
,
5694 .dumpit
= nl80211_dump_survey
,
5697 .cmd
= NL80211_CMD_SET_PMKSA
,
5698 .doit
= nl80211_setdel_pmksa
,
5699 .policy
= nl80211_policy
,
5700 .flags
= GENL_ADMIN_PERM
,
5701 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5702 NL80211_FLAG_NEED_RTNL
,
5705 .cmd
= NL80211_CMD_DEL_PMKSA
,
5706 .doit
= nl80211_setdel_pmksa
,
5707 .policy
= nl80211_policy
,
5708 .flags
= GENL_ADMIN_PERM
,
5709 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5710 NL80211_FLAG_NEED_RTNL
,
5713 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
5714 .doit
= nl80211_flush_pmksa
,
5715 .policy
= nl80211_policy
,
5716 .flags
= GENL_ADMIN_PERM
,
5717 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5718 NL80211_FLAG_NEED_RTNL
,
5721 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
5722 .doit
= nl80211_remain_on_channel
,
5723 .policy
= nl80211_policy
,
5724 .flags
= GENL_ADMIN_PERM
,
5725 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5726 NL80211_FLAG_NEED_RTNL
,
5729 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
5730 .doit
= nl80211_cancel_remain_on_channel
,
5731 .policy
= nl80211_policy
,
5732 .flags
= GENL_ADMIN_PERM
,
5733 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5734 NL80211_FLAG_NEED_RTNL
,
5737 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
5738 .doit
= nl80211_set_tx_bitrate_mask
,
5739 .policy
= nl80211_policy
,
5740 .flags
= GENL_ADMIN_PERM
,
5741 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5742 NL80211_FLAG_NEED_RTNL
,
5745 .cmd
= NL80211_CMD_REGISTER_FRAME
,
5746 .doit
= nl80211_register_mgmt
,
5747 .policy
= nl80211_policy
,
5748 .flags
= GENL_ADMIN_PERM
,
5749 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5750 NL80211_FLAG_NEED_RTNL
,
5753 .cmd
= NL80211_CMD_FRAME
,
5754 .doit
= nl80211_tx_mgmt
,
5755 .policy
= nl80211_policy
,
5756 .flags
= GENL_ADMIN_PERM
,
5757 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5758 NL80211_FLAG_NEED_RTNL
,
5761 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
5762 .doit
= nl80211_tx_mgmt_cancel_wait
,
5763 .policy
= nl80211_policy
,
5764 .flags
= GENL_ADMIN_PERM
,
5765 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5766 NL80211_FLAG_NEED_RTNL
,
5769 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
5770 .doit
= nl80211_set_power_save
,
5771 .policy
= nl80211_policy
,
5772 .flags
= GENL_ADMIN_PERM
,
5773 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5774 NL80211_FLAG_NEED_RTNL
,
5777 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
5778 .doit
= nl80211_get_power_save
,
5779 .policy
= nl80211_policy
,
5780 /* can be retrieved by unprivileged users */
5781 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5782 NL80211_FLAG_NEED_RTNL
,
5785 .cmd
= NL80211_CMD_SET_CQM
,
5786 .doit
= nl80211_set_cqm
,
5787 .policy
= nl80211_policy
,
5788 .flags
= GENL_ADMIN_PERM
,
5789 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5790 NL80211_FLAG_NEED_RTNL
,
5793 .cmd
= NL80211_CMD_SET_CHANNEL
,
5794 .doit
= nl80211_set_channel
,
5795 .policy
= nl80211_policy
,
5796 .flags
= GENL_ADMIN_PERM
,
5797 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5798 NL80211_FLAG_NEED_RTNL
,
5801 .cmd
= NL80211_CMD_SET_WDS_PEER
,
5802 .doit
= nl80211_set_wds_peer
,
5803 .policy
= nl80211_policy
,
5804 .flags
= GENL_ADMIN_PERM
,
5805 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5806 NL80211_FLAG_NEED_RTNL
,
5809 .cmd
= NL80211_CMD_JOIN_MESH
,
5810 .doit
= nl80211_join_mesh
,
5811 .policy
= nl80211_policy
,
5812 .flags
= GENL_ADMIN_PERM
,
5813 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5814 NL80211_FLAG_NEED_RTNL
,
5817 .cmd
= NL80211_CMD_LEAVE_MESH
,
5818 .doit
= nl80211_leave_mesh
,
5819 .policy
= nl80211_policy
,
5820 .flags
= GENL_ADMIN_PERM
,
5821 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5822 NL80211_FLAG_NEED_RTNL
,
5825 .cmd
= NL80211_CMD_GET_WOWLAN
,
5826 .doit
= nl80211_get_wowlan
,
5827 .policy
= nl80211_policy
,
5828 /* can be retrieved by unprivileged users */
5829 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
5830 NL80211_FLAG_NEED_RTNL
,
5833 .cmd
= NL80211_CMD_SET_WOWLAN
,
5834 .doit
= nl80211_set_wowlan
,
5835 .policy
= nl80211_policy
,
5836 .flags
= GENL_ADMIN_PERM
,
5837 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
5838 NL80211_FLAG_NEED_RTNL
,
5842 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
5846 /* multicast groups */
5847 static struct genl_multicast_group nl80211_config_mcgrp
= {
5850 static struct genl_multicast_group nl80211_scan_mcgrp
= {
5853 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
5854 .name
= "regulatory",
5857 /* notification functions */
5859 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
5861 struct sk_buff
*msg
;
5863 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5867 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
5872 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5873 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
5876 static int nl80211_add_scan_req(struct sk_buff
*msg
,
5877 struct cfg80211_registered_device
*rdev
)
5879 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
5880 struct nlattr
*nest
;
5883 ASSERT_RDEV_LOCK(rdev
);
5888 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
5890 goto nla_put_failure
;
5891 for (i
= 0; i
< req
->n_ssids
; i
++)
5892 NLA_PUT(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
);
5893 nla_nest_end(msg
, nest
);
5895 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
5897 goto nla_put_failure
;
5898 for (i
= 0; i
< req
->n_channels
; i
++)
5899 NLA_PUT_U32(msg
, i
, req
->channels
[i
]->center_freq
);
5900 nla_nest_end(msg
, nest
);
5903 NLA_PUT(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
);
5910 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
5911 struct cfg80211_registered_device
*rdev
,
5912 struct net_device
*netdev
,
5913 u32 pid
, u32 seq
, int flags
,
5918 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
5922 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5923 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5925 /* ignore errors and send incomplete event anyway */
5926 nl80211_add_scan_req(msg
, rdev
);
5928 return genlmsg_end(msg
, hdr
);
5931 genlmsg_cancel(msg
, hdr
);
5936 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
5937 struct cfg80211_registered_device
*rdev
,
5938 struct net_device
*netdev
,
5939 u32 pid
, u32 seq
, int flags
, u32 cmd
)
5943 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
5947 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5948 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5950 return genlmsg_end(msg
, hdr
);
5953 genlmsg_cancel(msg
, hdr
);
5957 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
5958 struct net_device
*netdev
)
5960 struct sk_buff
*msg
;
5962 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
5966 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5967 NL80211_CMD_TRIGGER_SCAN
) < 0) {
5972 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5973 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5976 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
5977 struct net_device
*netdev
)
5979 struct sk_buff
*msg
;
5981 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5985 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5986 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
5991 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5992 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5995 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
5996 struct net_device
*netdev
)
5998 struct sk_buff
*msg
;
6000 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6004 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
6005 NL80211_CMD_SCAN_ABORTED
) < 0) {
6010 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6011 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6014 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
6015 struct net_device
*netdev
)
6017 struct sk_buff
*msg
;
6019 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6023 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
6024 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
6029 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6030 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6033 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
6034 struct net_device
*netdev
, u32 cmd
)
6036 struct sk_buff
*msg
;
6038 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
6042 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
6047 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6048 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6052 * This can happen on global regulatory changes or device specific settings
6053 * based on custom world regulatory domains.
6055 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
6057 struct sk_buff
*msg
;
6060 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6064 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
6070 /* Userspace can always count this one always being set */
6071 NLA_PUT_U8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
);
6073 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0')
6074 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6075 NL80211_REGDOM_TYPE_WORLD
);
6076 else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9')
6077 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6078 NL80211_REGDOM_TYPE_CUSTOM_WORLD
);
6079 else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
6081 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6082 NL80211_REGDOM_TYPE_INTERSECTION
);
6084 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6085 NL80211_REGDOM_TYPE_COUNTRY
);
6086 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, request
->alpha2
);
6089 if (wiphy_idx_valid(request
->wiphy_idx
))
6090 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
);
6092 if (genlmsg_end(msg
, hdr
) < 0) {
6098 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
6105 genlmsg_cancel(msg
, hdr
);
6109 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
6110 struct net_device
*netdev
,
6111 const u8
*buf
, size_t len
,
6112 enum nl80211_commands cmd
, gfp_t gfp
)
6114 struct sk_buff
*msg
;
6117 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6121 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
6127 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6128 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6129 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
6131 if (genlmsg_end(msg
, hdr
) < 0) {
6136 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6137 nl80211_mlme_mcgrp
.id
, gfp
);
6141 genlmsg_cancel(msg
, hdr
);
6145 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
6146 struct net_device
*netdev
, const u8
*buf
,
6147 size_t len
, gfp_t gfp
)
6149 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6150 NL80211_CMD_AUTHENTICATE
, gfp
);
6153 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
6154 struct net_device
*netdev
, const u8
*buf
,
6155 size_t len
, gfp_t gfp
)
6157 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6158 NL80211_CMD_ASSOCIATE
, gfp
);
6161 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
6162 struct net_device
*netdev
, const u8
*buf
,
6163 size_t len
, gfp_t gfp
)
6165 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6166 NL80211_CMD_DEAUTHENTICATE
, gfp
);
6169 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
6170 struct net_device
*netdev
, const u8
*buf
,
6171 size_t len
, gfp_t gfp
)
6173 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6174 NL80211_CMD_DISASSOCIATE
, gfp
);
6177 void nl80211_send_unprot_deauth(struct cfg80211_registered_device
*rdev
,
6178 struct net_device
*netdev
, const u8
*buf
,
6179 size_t len
, gfp_t gfp
)
6181 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6182 NL80211_CMD_UNPROT_DEAUTHENTICATE
, gfp
);
6185 void nl80211_send_unprot_disassoc(struct cfg80211_registered_device
*rdev
,
6186 struct net_device
*netdev
, const u8
*buf
,
6187 size_t len
, gfp_t gfp
)
6189 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6190 NL80211_CMD_UNPROT_DISASSOCIATE
, gfp
);
6193 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
6194 struct net_device
*netdev
, int cmd
,
6195 const u8
*addr
, gfp_t gfp
)
6197 struct sk_buff
*msg
;
6200 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6204 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
6210 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6211 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6212 NLA_PUT_FLAG(msg
, NL80211_ATTR_TIMED_OUT
);
6213 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
6215 if (genlmsg_end(msg
, hdr
) < 0) {
6220 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6221 nl80211_mlme_mcgrp
.id
, gfp
);
6225 genlmsg_cancel(msg
, hdr
);
6229 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
6230 struct net_device
*netdev
, const u8
*addr
,
6233 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
6237 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
6238 struct net_device
*netdev
, const u8
*addr
,
6241 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
6245 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
6246 struct net_device
*netdev
, const u8
*bssid
,
6247 const u8
*req_ie
, size_t req_ie_len
,
6248 const u8
*resp_ie
, size_t resp_ie_len
,
6249 u16 status
, gfp_t gfp
)
6251 struct sk_buff
*msg
;
6254 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6258 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
6264 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6265 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6267 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
6268 NLA_PUT_U16(msg
, NL80211_ATTR_STATUS_CODE
, status
);
6270 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
6272 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
6274 if (genlmsg_end(msg
, hdr
) < 0) {
6279 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6280 nl80211_mlme_mcgrp
.id
, gfp
);
6284 genlmsg_cancel(msg
, hdr
);
6289 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
6290 struct net_device
*netdev
, const u8
*bssid
,
6291 const u8
*req_ie
, size_t req_ie_len
,
6292 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
6294 struct sk_buff
*msg
;
6297 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6301 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
6307 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6308 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6309 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
6311 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
6313 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
6315 if (genlmsg_end(msg
, hdr
) < 0) {
6320 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6321 nl80211_mlme_mcgrp
.id
, gfp
);
6325 genlmsg_cancel(msg
, hdr
);
6330 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
6331 struct net_device
*netdev
, u16 reason
,
6332 const u8
*ie
, size_t ie_len
, bool from_ap
)
6334 struct sk_buff
*msg
;
6337 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
6341 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
6347 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6348 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6349 if (from_ap
&& reason
)
6350 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason
);
6352 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
);
6354 NLA_PUT(msg
, NL80211_ATTR_IE
, ie_len
, ie
);
6356 if (genlmsg_end(msg
, hdr
) < 0) {
6361 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6362 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
6366 genlmsg_cancel(msg
, hdr
);
6371 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
6372 struct net_device
*netdev
, const u8
*bssid
,
6375 struct sk_buff
*msg
;
6378 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6382 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
6388 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6389 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6390 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
6392 if (genlmsg_end(msg
, hdr
) < 0) {
6397 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6398 nl80211_mlme_mcgrp
.id
, gfp
);
6402 genlmsg_cancel(msg
, hdr
);
6406 void nl80211_send_new_peer_candidate(struct cfg80211_registered_device
*rdev
,
6407 struct net_device
*netdev
,
6408 const u8
*macaddr
, const u8
* ie
, u8 ie_len
,
6411 struct sk_buff
*msg
;
6414 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6418 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
6424 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6425 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6426 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, macaddr
);
6428 NLA_PUT(msg
, NL80211_ATTR_IE
, ie_len
, ie
);
6430 if (genlmsg_end(msg
, hdr
) < 0) {
6435 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6436 nl80211_mlme_mcgrp
.id
, gfp
);
6440 genlmsg_cancel(msg
, hdr
);
6444 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
6445 struct net_device
*netdev
, const u8
*addr
,
6446 enum nl80211_key_type key_type
, int key_id
,
6447 const u8
*tsc
, gfp_t gfp
)
6449 struct sk_buff
*msg
;
6452 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6456 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
6462 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6463 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6465 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
6466 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
);
6467 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_id
);
6469 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
);
6471 if (genlmsg_end(msg
, hdr
) < 0) {
6476 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6477 nl80211_mlme_mcgrp
.id
, gfp
);
6481 genlmsg_cancel(msg
, hdr
);
6485 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
6486 struct ieee80211_channel
*channel_before
,
6487 struct ieee80211_channel
*channel_after
)
6489 struct sk_buff
*msg
;
6491 struct nlattr
*nl_freq
;
6493 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
6497 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
6504 * Since we are applying the beacon hint to a wiphy we know its
6505 * wiphy_idx is valid
6507 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
));
6510 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
6512 goto nla_put_failure
;
6513 if (nl80211_msg_put_channel(msg
, channel_before
))
6514 goto nla_put_failure
;
6515 nla_nest_end(msg
, nl_freq
);
6518 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
6520 goto nla_put_failure
;
6521 if (nl80211_msg_put_channel(msg
, channel_after
))
6522 goto nla_put_failure
;
6523 nla_nest_end(msg
, nl_freq
);
6525 if (genlmsg_end(msg
, hdr
) < 0) {
6531 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
6538 genlmsg_cancel(msg
, hdr
);
6542 static void nl80211_send_remain_on_chan_event(
6543 int cmd
, struct cfg80211_registered_device
*rdev
,
6544 struct net_device
*netdev
, u64 cookie
,
6545 struct ieee80211_channel
*chan
,
6546 enum nl80211_channel_type channel_type
,
6547 unsigned int duration
, gfp_t gfp
)
6549 struct sk_buff
*msg
;
6552 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6556 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
6562 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6563 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6564 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
);
6565 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, channel_type
);
6566 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
6568 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
)
6569 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, duration
);
6571 if (genlmsg_end(msg
, hdr
) < 0) {
6576 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6577 nl80211_mlme_mcgrp
.id
, gfp
);
6581 genlmsg_cancel(msg
, hdr
);
6585 void nl80211_send_remain_on_channel(struct cfg80211_registered_device
*rdev
,
6586 struct net_device
*netdev
, u64 cookie
,
6587 struct ieee80211_channel
*chan
,
6588 enum nl80211_channel_type channel_type
,
6589 unsigned int duration
, gfp_t gfp
)
6591 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
6592 rdev
, netdev
, cookie
, chan
,
6593 channel_type
, duration
, gfp
);
6596 void nl80211_send_remain_on_channel_cancel(
6597 struct cfg80211_registered_device
*rdev
, struct net_device
*netdev
,
6598 u64 cookie
, struct ieee80211_channel
*chan
,
6599 enum nl80211_channel_type channel_type
, gfp_t gfp
)
6601 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
6602 rdev
, netdev
, cookie
, chan
,
6603 channel_type
, 0, gfp
);
6606 void nl80211_send_sta_event(struct cfg80211_registered_device
*rdev
,
6607 struct net_device
*dev
, const u8
*mac_addr
,
6608 struct station_info
*sinfo
, gfp_t gfp
)
6610 struct sk_buff
*msg
;
6612 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6616 if (nl80211_send_station(msg
, 0, 0, 0, dev
, mac_addr
, sinfo
) < 0) {
6621 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6622 nl80211_mlme_mcgrp
.id
, gfp
);
6625 void nl80211_send_sta_del_event(struct cfg80211_registered_device
*rdev
,
6626 struct net_device
*dev
, const u8
*mac_addr
,
6629 struct sk_buff
*msg
;
6632 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6636 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_STATION
);
6642 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
6643 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
6645 if (genlmsg_end(msg
, hdr
) < 0) {
6650 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6651 nl80211_mlme_mcgrp
.id
, gfp
);
6655 genlmsg_cancel(msg
, hdr
);
6659 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
6660 struct net_device
*netdev
, u32 nlpid
,
6661 int freq
, const u8
*buf
, size_t len
, gfp_t gfp
)
6663 struct sk_buff
*msg
;
6667 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6671 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
6677 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6678 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6679 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
6680 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
6682 err
= genlmsg_end(msg
, hdr
);
6688 err
= genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
6694 genlmsg_cancel(msg
, hdr
);
6699 void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device
*rdev
,
6700 struct net_device
*netdev
, u64 cookie
,
6701 const u8
*buf
, size_t len
, bool ack
,
6704 struct sk_buff
*msg
;
6707 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6711 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
6717 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6718 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6719 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
6720 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
6722 NLA_PUT_FLAG(msg
, NL80211_ATTR_ACK
);
6724 if (genlmsg_end(msg
, hdr
) < 0) {
6729 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
6733 genlmsg_cancel(msg
, hdr
);
6738 nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device
*rdev
,
6739 struct net_device
*netdev
,
6740 enum nl80211_cqm_rssi_threshold_event rssi_event
,
6743 struct sk_buff
*msg
;
6744 struct nlattr
*pinfoattr
;
6747 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6751 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
6757 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6758 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6760 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
6762 goto nla_put_failure
;
6764 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
6767 nla_nest_end(msg
, pinfoattr
);
6769 if (genlmsg_end(msg
, hdr
) < 0) {
6774 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6775 nl80211_mlme_mcgrp
.id
, gfp
);
6779 genlmsg_cancel(msg
, hdr
);
6784 nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device
*rdev
,
6785 struct net_device
*netdev
, const u8
*peer
,
6786 u32 num_packets
, gfp_t gfp
)
6788 struct sk_buff
*msg
;
6789 struct nlattr
*pinfoattr
;
6792 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6796 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
6802 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6803 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6804 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
);
6806 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
6808 goto nla_put_failure
;
6810 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
);
6812 nla_nest_end(msg
, pinfoattr
);
6814 if (genlmsg_end(msg
, hdr
) < 0) {
6819 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6820 nl80211_mlme_mcgrp
.id
, gfp
);
6824 genlmsg_cancel(msg
, hdr
);
6828 static int nl80211_netlink_notify(struct notifier_block
* nb
,
6829 unsigned long state
,
6832 struct netlink_notify
*notify
= _notify
;
6833 struct cfg80211_registered_device
*rdev
;
6834 struct wireless_dev
*wdev
;
6836 if (state
!= NETLINK_URELEASE
)
6841 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
)
6842 list_for_each_entry_rcu(wdev
, &rdev
->netdev_list
, list
)
6843 cfg80211_mlme_unregister_socket(wdev
, notify
->pid
);
6850 static struct notifier_block nl80211_netlink_notifier
= {
6851 .notifier_call
= nl80211_netlink_notify
,
6854 /* initialisation/exit functions */
6856 int nl80211_init(void)
6860 err
= genl_register_family_with_ops(&nl80211_fam
,
6861 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
6865 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
6869 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
6873 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
6877 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
6881 #ifdef CONFIG_NL80211_TESTMODE
6882 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
6887 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
6893 genl_unregister_family(&nl80211_fam
);
6897 void nl80211_exit(void)
6899 netlink_unregister_notifier(&nl80211_netlink_notifier
);
6900 genl_unregister_family(&nl80211_fam
);