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 bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
);
27 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
28 struct genl_info
*info
,
29 struct cfg80211_crypto_settings
*settings
,
32 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
33 struct genl_info
*info
);
34 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
35 struct genl_info
*info
);
37 /* the netlink family */
38 static struct genl_family nl80211_fam
= {
39 .id
= GENL_ID_GENERATE
, /* don't bother with a hardcoded ID */
40 .name
= "nl80211", /* have users key off the name instead */
41 .hdrsize
= 0, /* no private header */
42 .version
= 1, /* no particular meaning now */
43 .maxattr
= NL80211_ATTR_MAX
,
45 .pre_doit
= nl80211_pre_doit
,
46 .post_doit
= nl80211_post_doit
,
49 /* internal helper: get rdev and dev */
50 static int get_rdev_dev_by_info_ifindex(struct genl_info
*info
,
51 struct cfg80211_registered_device
**rdev
,
52 struct net_device
**dev
)
54 struct nlattr
**attrs
= info
->attrs
;
57 if (!attrs
[NL80211_ATTR_IFINDEX
])
60 ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
61 *dev
= dev_get_by_index(genl_info_net(info
), ifindex
);
65 *rdev
= cfg80211_get_dev_from_ifindex(genl_info_net(info
), ifindex
);
68 return PTR_ERR(*rdev
);
74 /* policy for the attributes */
75 static const struct nla_policy nl80211_policy
[NL80211_ATTR_MAX
+1] = {
76 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
77 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
79 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
80 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
81 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
82 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
83 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
84 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
85 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
86 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
88 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
89 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
90 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
92 [NL80211_ATTR_MAC
] = { .type
= NLA_BINARY
, .len
= ETH_ALEN
},
93 [NL80211_ATTR_PREV_BSSID
] = { .type
= NLA_BINARY
, .len
= ETH_ALEN
},
95 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
96 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
97 .len
= WLAN_MAX_KEY_LEN
},
98 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
99 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
100 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
101 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 8 },
102 [NL80211_ATTR_KEY_TYPE
] = { .type
= NLA_U32
},
104 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
105 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
106 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
107 .len
= IEEE80211_MAX_DATA_LEN
},
108 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
109 .len
= IEEE80211_MAX_DATA_LEN
},
110 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
111 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
112 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
113 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
114 .len
= NL80211_MAX_SUPP_RATES
},
115 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
116 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
117 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
118 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
119 .len
= IEEE80211_MAX_MESH_ID_LEN
},
120 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
122 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
123 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
125 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
126 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
127 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
128 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
129 .len
= NL80211_MAX_SUPP_RATES
},
130 [NL80211_ATTR_BSS_HT_OPMODE
] = { .type
= NLA_U16
},
132 [NL80211_ATTR_MESH_CONFIG
] = { .type
= NLA_NESTED
},
133 [NL80211_ATTR_SUPPORT_MESH_AUTH
] = { .type
= NLA_FLAG
},
135 [NL80211_ATTR_HT_CAPABILITY
] = { .type
= NLA_BINARY
,
136 .len
= NL80211_HT_CAPABILITY_LEN
},
138 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
139 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
140 .len
= IEEE80211_MAX_DATA_LEN
},
141 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
142 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
144 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
145 .len
= IEEE80211_MAX_SSID_LEN
},
146 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
147 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
148 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
149 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
150 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
151 [NL80211_ATTR_STA_FLAGS2
] = {
152 .len
= sizeof(struct nl80211_sta_flag_update
),
154 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
155 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE
] = { .type
= NLA_U16
},
156 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
] = { .type
= NLA_FLAG
},
157 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
158 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
159 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
160 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
161 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
162 [NL80211_ATTR_PMKID
] = { .type
= NLA_BINARY
,
163 .len
= WLAN_PMKID_LEN
},
164 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
165 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
166 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
167 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
168 .len
= IEEE80211_MAX_DATA_LEN
},
169 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
170 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
171 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
172 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
173 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
174 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
175 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
176 [NL80211_ATTR_FRAME_TYPE
] = { .type
= NLA_U16
},
177 [NL80211_ATTR_WIPHY_ANTENNA_TX
] = { .type
= NLA_U32
},
178 [NL80211_ATTR_WIPHY_ANTENNA_RX
] = { .type
= NLA_U32
},
179 [NL80211_ATTR_MCAST_RATE
] = { .type
= NLA_U32
},
180 [NL80211_ATTR_OFFCHANNEL_TX_OK
] = { .type
= NLA_FLAG
},
181 [NL80211_ATTR_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
182 [NL80211_ATTR_WOWLAN_TRIGGERS
] = { .type
= NLA_NESTED
},
183 [NL80211_ATTR_STA_PLINK_STATE
] = { .type
= NLA_U8
},
184 [NL80211_ATTR_SCHED_SCAN_INTERVAL
] = { .type
= NLA_U32
},
185 [NL80211_ATTR_REKEY_DATA
] = { .type
= NLA_NESTED
},
186 [NL80211_ATTR_SCAN_SUPP_RATES
] = { .type
= NLA_NESTED
},
187 [NL80211_ATTR_HIDDEN_SSID
] = { .type
= NLA_U32
},
188 [NL80211_ATTR_IE_PROBE_RESP
] = { .type
= NLA_BINARY
,
189 .len
= IEEE80211_MAX_DATA_LEN
},
190 [NL80211_ATTR_IE_ASSOC_RESP
] = { .type
= NLA_BINARY
,
191 .len
= IEEE80211_MAX_DATA_LEN
},
194 /* policy for the key attributes */
195 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
196 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
197 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
198 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
199 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 8 },
200 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
201 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
202 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
203 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
206 /* policy for the key default flags */
207 static const struct nla_policy
208 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
209 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
210 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
213 /* policy for WoWLAN attributes */
214 static const struct nla_policy
215 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
216 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
217 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
218 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
219 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
220 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
221 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
222 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
223 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
226 /* policy for GTK rekey offload attributes */
227 static const struct nla_policy
228 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
229 [NL80211_REKEY_DATA_KEK
] = { .len
= NL80211_KEK_LEN
},
230 [NL80211_REKEY_DATA_KCK
] = { .len
= NL80211_KCK_LEN
},
231 [NL80211_REKEY_DATA_REPLAY_CTR
] = { .len
= NL80211_REPLAY_CTR_LEN
},
234 /* ifidx get helper */
235 static int nl80211_get_ifidx(struct netlink_callback
*cb
)
239 res
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
240 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
245 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
248 res
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
254 static int nl80211_prepare_netdev_dump(struct sk_buff
*skb
,
255 struct netlink_callback
*cb
,
256 struct cfg80211_registered_device
**rdev
,
257 struct net_device
**dev
)
259 int ifidx
= cb
->args
[0];
263 ifidx
= nl80211_get_ifidx(cb
);
271 *dev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
277 *rdev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
279 err
= PTR_ERR(*rdev
);
289 static void nl80211_finish_netdev_dump(struct cfg80211_registered_device
*rdev
)
291 cfg80211_unlock_rdev(rdev
);
296 static bool is_valid_ie_attr(const struct nlattr
*attr
)
304 pos
= nla_data(attr
);
325 /* message building helper */
326 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 pid
, u32 seq
,
329 /* since there is no private header just add the generic one */
330 return genlmsg_put(skb
, pid
, seq
, &nl80211_fam
, flags
, cmd
);
333 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
334 struct ieee80211_channel
*chan
)
336 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
339 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
340 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_DISABLED
);
341 if (chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
342 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
);
343 if (chan
->flags
& IEEE80211_CHAN_NO_IBSS
)
344 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
);
345 if (chan
->flags
& IEEE80211_CHAN_RADAR
)
346 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_RADAR
);
348 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
349 DBM_TO_MBM(chan
->max_power
));
357 /* netlink command implementations */
364 bool def_uni
, def_multi
;
367 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
369 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
370 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
375 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
376 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
385 if (tb
[NL80211_KEY_IDX
])
386 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
388 if (tb
[NL80211_KEY_DATA
]) {
389 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
390 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
393 if (tb
[NL80211_KEY_SEQ
]) {
394 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
395 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
398 if (tb
[NL80211_KEY_CIPHER
])
399 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
401 if (tb
[NL80211_KEY_TYPE
]) {
402 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
403 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
407 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
408 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
409 int err
= nla_parse_nested(kdt
,
410 NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
411 tb
[NL80211_KEY_DEFAULT_TYPES
],
412 nl80211_key_default_policy
);
416 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
417 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
423 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
425 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
426 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
427 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
430 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
431 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
432 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
435 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
436 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
438 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
439 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
441 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
442 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
451 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
452 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
453 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
457 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
458 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
459 int err
= nla_parse_nested(
460 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
461 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
462 nl80211_key_default_policy
);
466 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
467 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
473 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
477 memset(k
, 0, sizeof(*k
));
481 if (info
->attrs
[NL80211_ATTR_KEY
])
482 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
484 err
= nl80211_parse_key_old(info
, k
);
489 if (k
->def
&& k
->defmgmt
)
493 if (k
->def_uni
|| !k
->def_multi
)
499 if (k
->idx
< 4 || k
->idx
> 5)
502 if (k
->idx
< 0 || k
->idx
> 3)
505 if (k
->idx
< 0 || k
->idx
> 5)
513 static struct cfg80211_cached_keys
*
514 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
517 struct key_parse parse
;
519 struct cfg80211_cached_keys
*result
;
520 int rem
, err
, def
= 0;
522 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
524 return ERR_PTR(-ENOMEM
);
527 result
->defmgmt
= -1;
529 nla_for_each_nested(key
, keys
, rem
) {
530 memset(&parse
, 0, sizeof(parse
));
533 err
= nl80211_parse_key_new(key
, &parse
);
539 if (parse
.idx
< 0 || parse
.idx
> 4)
545 result
->def
= parse
.idx
;
546 if (!parse
.def_uni
|| !parse
.def_multi
)
548 } else if (parse
.defmgmt
)
550 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
551 parse
.idx
, false, NULL
);
554 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
555 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
556 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
557 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
566 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
568 ASSERT_WDEV_LOCK(wdev
);
570 switch (wdev
->iftype
) {
571 case NL80211_IFTYPE_AP
:
572 case NL80211_IFTYPE_AP_VLAN
:
573 case NL80211_IFTYPE_P2P_GO
:
574 case NL80211_IFTYPE_MESH_POINT
:
576 case NL80211_IFTYPE_ADHOC
:
577 if (!wdev
->current_bss
)
580 case NL80211_IFTYPE_STATION
:
581 case NL80211_IFTYPE_P2P_CLIENT
:
582 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
592 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
594 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
598 goto nla_put_failure
;
603 NLA_PUT_FLAG(msg
, i
);
608 nla_nest_end(msg
, nl_modes
);
615 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
618 struct nlattr
*nl_combis
;
621 nl_combis
= nla_nest_start(msg
,
622 NL80211_ATTR_INTERFACE_COMBINATIONS
);
624 goto nla_put_failure
;
626 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
627 const struct ieee80211_iface_combination
*c
;
628 struct nlattr
*nl_combi
, *nl_limits
;
630 c
= &wiphy
->iface_combinations
[i
];
632 nl_combi
= nla_nest_start(msg
, i
+ 1);
634 goto nla_put_failure
;
636 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
638 goto nla_put_failure
;
640 for (j
= 0; j
< c
->n_limits
; j
++) {
641 struct nlattr
*nl_limit
;
643 nl_limit
= nla_nest_start(msg
, j
+ 1);
645 goto nla_put_failure
;
646 NLA_PUT_U32(msg
, NL80211_IFACE_LIMIT_MAX
,
648 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
650 goto nla_put_failure
;
651 nla_nest_end(msg
, nl_limit
);
654 nla_nest_end(msg
, nl_limits
);
656 if (c
->beacon_int_infra_match
)
658 NL80211_IFACE_COMB_STA_AP_BI_MATCH
);
659 NLA_PUT_U32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
660 c
->num_different_channels
);
661 NLA_PUT_U32(msg
, NL80211_IFACE_COMB_MAXNUM
,
664 nla_nest_end(msg
, nl_combi
);
667 nla_nest_end(msg
, nl_combis
);
674 static int nl80211_send_wiphy(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
675 struct cfg80211_registered_device
*dev
)
678 struct nlattr
*nl_bands
, *nl_band
;
679 struct nlattr
*nl_freqs
, *nl_freq
;
680 struct nlattr
*nl_rates
, *nl_rate
;
681 struct nlattr
*nl_cmds
;
682 enum ieee80211_band band
;
683 struct ieee80211_channel
*chan
;
684 struct ieee80211_rate
*rate
;
686 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
687 dev
->wiphy
.mgmt_stypes
;
689 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
693 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
);
694 NLA_PUT_STRING(msg
, NL80211_ATTR_WIPHY_NAME
, wiphy_name(&dev
->wiphy
));
696 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
697 cfg80211_rdev_list_generation
);
699 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
700 dev
->wiphy
.retry_short
);
701 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
702 dev
->wiphy
.retry_long
);
703 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
704 dev
->wiphy
.frag_threshold
);
705 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
706 dev
->wiphy
.rts_threshold
);
707 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
708 dev
->wiphy
.coverage_class
);
709 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
710 dev
->wiphy
.max_scan_ssids
);
711 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
712 dev
->wiphy
.max_sched_scan_ssids
);
713 NLA_PUT_U16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
714 dev
->wiphy
.max_scan_ie_len
);
715 NLA_PUT_U16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
716 dev
->wiphy
.max_sched_scan_ie_len
);
718 if (dev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
)
719 NLA_PUT_FLAG(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
);
720 if (dev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
)
721 NLA_PUT_FLAG(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
);
723 NLA_PUT(msg
, NL80211_ATTR_CIPHER_SUITES
,
724 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
725 dev
->wiphy
.cipher_suites
);
727 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
728 dev
->wiphy
.max_num_pmkids
);
730 if (dev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
)
731 NLA_PUT_FLAG(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
);
733 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
734 dev
->wiphy
.available_antennas_tx
);
735 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
736 dev
->wiphy
.available_antennas_rx
);
738 if ((dev
->wiphy
.available_antennas_tx
||
739 dev
->wiphy
.available_antennas_rx
) && dev
->ops
->get_antenna
) {
740 u32 tx_ant
= 0, rx_ant
= 0;
742 res
= dev
->ops
->get_antenna(&dev
->wiphy
, &tx_ant
, &rx_ant
);
744 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_TX
, tx_ant
);
745 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_RX
, rx_ant
);
749 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
750 dev
->wiphy
.interface_modes
))
751 goto nla_put_failure
;
753 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
755 goto nla_put_failure
;
757 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
758 if (!dev
->wiphy
.bands
[band
])
761 nl_band
= nla_nest_start(msg
, band
);
763 goto nla_put_failure
;
766 if (dev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
) {
767 NLA_PUT(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
768 sizeof(dev
->wiphy
.bands
[band
]->ht_cap
.mcs
),
769 &dev
->wiphy
.bands
[band
]->ht_cap
.mcs
);
770 NLA_PUT_U16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
771 dev
->wiphy
.bands
[band
]->ht_cap
.cap
);
772 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
773 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_factor
);
774 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
775 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_density
);
778 /* add frequencies */
779 nl_freqs
= nla_nest_start(msg
, NL80211_BAND_ATTR_FREQS
);
781 goto nla_put_failure
;
783 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_channels
; i
++) {
784 nl_freq
= nla_nest_start(msg
, i
);
786 goto nla_put_failure
;
788 chan
= &dev
->wiphy
.bands
[band
]->channels
[i
];
790 if (nl80211_msg_put_channel(msg
, chan
))
791 goto nla_put_failure
;
793 nla_nest_end(msg
, nl_freq
);
796 nla_nest_end(msg
, nl_freqs
);
799 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
801 goto nla_put_failure
;
803 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_bitrates
; i
++) {
804 nl_rate
= nla_nest_start(msg
, i
);
806 goto nla_put_failure
;
808 rate
= &dev
->wiphy
.bands
[band
]->bitrates
[i
];
809 NLA_PUT_U32(msg
, NL80211_BITRATE_ATTR_RATE
,
811 if (rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
)
813 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
);
815 nla_nest_end(msg
, nl_rate
);
818 nla_nest_end(msg
, nl_rates
);
820 nla_nest_end(msg
, nl_band
);
822 nla_nest_end(msg
, nl_bands
);
824 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
826 goto nla_put_failure
;
831 if (dev->ops->op) { \
833 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
837 CMD(add_virtual_intf
, NEW_INTERFACE
);
838 CMD(change_virtual_intf
, SET_INTERFACE
);
839 CMD(add_key
, NEW_KEY
);
840 CMD(add_beacon
, NEW_BEACON
);
841 CMD(add_station
, NEW_STATION
);
842 CMD(add_mpath
, NEW_MPATH
);
843 CMD(update_mesh_config
, SET_MESH_CONFIG
);
844 CMD(change_bss
, SET_BSS
);
845 CMD(auth
, AUTHENTICATE
);
846 CMD(assoc
, ASSOCIATE
);
847 CMD(deauth
, DEAUTHENTICATE
);
848 CMD(disassoc
, DISASSOCIATE
);
849 CMD(join_ibss
, JOIN_IBSS
);
850 CMD(join_mesh
, JOIN_MESH
);
851 CMD(set_pmksa
, SET_PMKSA
);
852 CMD(del_pmksa
, DEL_PMKSA
);
853 CMD(flush_pmksa
, FLUSH_PMKSA
);
854 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
855 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
857 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
858 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
860 NLA_PUT_U32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
);
862 CMD(set_channel
, SET_CHANNEL
);
863 CMD(set_wds_peer
, SET_WDS_PEER
);
864 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
865 CMD(sched_scan_start
, START_SCHED_SCAN
);
869 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
871 NLA_PUT_U32(msg
, i
, NL80211_CMD_CONNECT
);
874 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
876 NLA_PUT_U32(msg
, i
, NL80211_CMD_DISCONNECT
);
879 nla_nest_end(msg
, nl_cmds
);
881 if (dev
->ops
->remain_on_channel
)
882 NLA_PUT_U32(msg
, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
883 dev
->wiphy
.max_remain_on_channel_duration
);
885 if (dev
->ops
->mgmt_tx_cancel_wait
)
886 NLA_PUT_FLAG(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
);
890 struct nlattr
*nl_ftypes
, *nl_ifs
;
891 enum nl80211_iftype ift
;
893 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
895 goto nla_put_failure
;
897 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
898 nl_ftypes
= nla_nest_start(msg
, ift
);
900 goto nla_put_failure
;
902 stypes
= mgmt_stypes
[ift
].tx
;
905 NLA_PUT_U16(msg
, NL80211_ATTR_FRAME_TYPE
,
906 (i
<< 4) | IEEE80211_FTYPE_MGMT
);
910 nla_nest_end(msg
, nl_ftypes
);
913 nla_nest_end(msg
, nl_ifs
);
915 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
917 goto nla_put_failure
;
919 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
920 nl_ftypes
= nla_nest_start(msg
, ift
);
922 goto nla_put_failure
;
924 stypes
= mgmt_stypes
[ift
].rx
;
927 NLA_PUT_U16(msg
, NL80211_ATTR_FRAME_TYPE
,
928 (i
<< 4) | IEEE80211_FTYPE_MGMT
);
932 nla_nest_end(msg
, nl_ftypes
);
934 nla_nest_end(msg
, nl_ifs
);
937 if (dev
->wiphy
.wowlan
.flags
|| dev
->wiphy
.wowlan
.n_patterns
) {
938 struct nlattr
*nl_wowlan
;
940 nl_wowlan
= nla_nest_start(msg
,
941 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
943 goto nla_put_failure
;
945 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_ANY
)
946 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_ANY
);
947 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_DISCONNECT
)
948 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
);
949 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_MAGIC_PKT
)
950 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
);
951 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
)
952 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
);
953 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
)
954 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
);
955 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
)
956 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
);
957 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
)
958 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
);
959 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_RFKILL_RELEASE
)
960 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
);
961 if (dev
->wiphy
.wowlan
.n_patterns
) {
962 struct nl80211_wowlan_pattern_support pat
= {
963 .max_patterns
= dev
->wiphy
.wowlan
.n_patterns
,
965 dev
->wiphy
.wowlan
.pattern_min_len
,
967 dev
->wiphy
.wowlan
.pattern_max_len
,
969 NLA_PUT(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
973 nla_nest_end(msg
, nl_wowlan
);
976 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
977 dev
->wiphy
.software_iftypes
))
978 goto nla_put_failure
;
980 if (nl80211_put_iface_combinations(&dev
->wiphy
, msg
))
981 goto nla_put_failure
;
983 return genlmsg_end(msg
, hdr
);
986 genlmsg_cancel(msg
, hdr
);
990 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
993 int start
= cb
->args
[0];
994 struct cfg80211_registered_device
*dev
;
996 mutex_lock(&cfg80211_mutex
);
997 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
998 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
1002 if (nl80211_send_wiphy(skb
, NETLINK_CB(cb
->skb
).pid
,
1003 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1009 mutex_unlock(&cfg80211_mutex
);
1016 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1018 struct sk_buff
*msg
;
1019 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1021 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1025 if (nl80211_send_wiphy(msg
, info
->snd_pid
, info
->snd_seq
, 0, dev
) < 0) {
1030 return genlmsg_reply(msg
, info
);
1033 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
1034 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
1035 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
1036 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
1037 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
1038 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1041 static int parse_txq_params(struct nlattr
*tb
[],
1042 struct ieee80211_txq_params
*txq_params
)
1044 if (!tb
[NL80211_TXQ_ATTR_QUEUE
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1045 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1046 !tb
[NL80211_TXQ_ATTR_AIFS
])
1049 txq_params
->queue
= nla_get_u8(tb
[NL80211_TXQ_ATTR_QUEUE
]);
1050 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1051 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1052 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1053 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1058 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1061 * You can only set the channel explicitly for AP, mesh
1062 * and WDS type interfaces; all others have their channel
1063 * managed via their respective "establish a connection"
1064 * command (connect, join, ...)
1066 * Monitors are special as they are normally slaved to
1067 * whatever else is going on, so they behave as though
1068 * you tried setting the wiphy channel itself.
1071 wdev
->iftype
== NL80211_IFTYPE_AP
||
1072 wdev
->iftype
== NL80211_IFTYPE_WDS
||
1073 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
1074 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
1075 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
1078 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
1079 struct wireless_dev
*wdev
,
1080 struct genl_info
*info
)
1082 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
1086 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
1089 if (!nl80211_can_set_dev_channel(wdev
))
1092 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
1093 channel_type
= nla_get_u32(info
->attrs
[
1094 NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1095 if (channel_type
!= NL80211_CHAN_NO_HT
&&
1096 channel_type
!= NL80211_CHAN_HT20
&&
1097 channel_type
!= NL80211_CHAN_HT40PLUS
&&
1098 channel_type
!= NL80211_CHAN_HT40MINUS
)
1102 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
1104 mutex_lock(&rdev
->devlist_mtx
);
1107 result
= cfg80211_set_freq(rdev
, wdev
, freq
, channel_type
);
1110 result
= cfg80211_set_freq(rdev
, NULL
, freq
, channel_type
);
1112 mutex_unlock(&rdev
->devlist_mtx
);
1117 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
1119 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1120 struct net_device
*netdev
= info
->user_ptr
[1];
1122 return __nl80211_set_channel(rdev
, netdev
->ieee80211_ptr
, info
);
1125 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
1127 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1128 struct net_device
*dev
= info
->user_ptr
[1];
1129 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1132 if (!info
->attrs
[NL80211_ATTR_MAC
])
1135 if (netif_running(dev
))
1138 if (!rdev
->ops
->set_wds_peer
)
1141 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
1144 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1145 return rdev
->ops
->set_wds_peer(wdev
->wiphy
, dev
, bssid
);
1149 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1151 struct cfg80211_registered_device
*rdev
;
1152 struct net_device
*netdev
= NULL
;
1153 struct wireless_dev
*wdev
;
1154 int result
= 0, rem_txq_params
= 0;
1155 struct nlattr
*nl_txq_params
;
1157 u8 retry_short
= 0, retry_long
= 0;
1158 u32 frag_threshold
= 0, rts_threshold
= 0;
1159 u8 coverage_class
= 0;
1162 * Try to find the wiphy and netdev. Normally this
1163 * function shouldn't need the netdev, but this is
1164 * done for backward compatibility -- previously
1165 * setting the channel was done per wiphy, but now
1166 * it is per netdev. Previous userland like hostapd
1167 * also passed a netdev to set_wiphy, so that it is
1168 * possible to let that go to the right netdev!
1170 mutex_lock(&cfg80211_mutex
);
1172 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
1173 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
1175 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
1176 if (netdev
&& netdev
->ieee80211_ptr
) {
1177 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
1178 mutex_lock(&rdev
->mtx
);
1184 rdev
= __cfg80211_rdev_from_info(info
);
1186 mutex_unlock(&cfg80211_mutex
);
1187 return PTR_ERR(rdev
);
1193 mutex_lock(&rdev
->mtx
);
1194 } else if (netif_running(netdev
) &&
1195 nl80211_can_set_dev_channel(netdev
->ieee80211_ptr
))
1196 wdev
= netdev
->ieee80211_ptr
;
1201 * end workaround code, by now the rdev is available
1202 * and locked, and wdev may or may not be NULL.
1205 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
1206 result
= cfg80211_dev_rename(
1207 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
1209 mutex_unlock(&cfg80211_mutex
);
1214 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
1215 struct ieee80211_txq_params txq_params
;
1216 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
1218 if (!rdev
->ops
->set_txq_params
) {
1219 result
= -EOPNOTSUPP
;
1223 nla_for_each_nested(nl_txq_params
,
1224 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
1226 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
1227 nla_data(nl_txq_params
),
1228 nla_len(nl_txq_params
),
1230 result
= parse_txq_params(tb
, &txq_params
);
1234 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
1241 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
1242 result
= __nl80211_set_channel(rdev
, wdev
, info
);
1247 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
1248 enum nl80211_tx_power_setting type
;
1251 if (!rdev
->ops
->set_tx_power
) {
1252 result
= -EOPNOTSUPP
;
1256 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
1257 type
= nla_get_u32(info
->attrs
[idx
]);
1259 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
1260 (type
!= NL80211_TX_POWER_AUTOMATIC
)) {
1265 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
1266 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
1267 mbm
= nla_get_u32(info
->attrs
[idx
]);
1270 result
= rdev
->ops
->set_tx_power(&rdev
->wiphy
, type
, mbm
);
1275 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
1276 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
1278 if ((!rdev
->wiphy
.available_antennas_tx
&&
1279 !rdev
->wiphy
.available_antennas_rx
) ||
1280 !rdev
->ops
->set_antenna
) {
1281 result
= -EOPNOTSUPP
;
1285 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
1286 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
1288 /* reject antenna configurations which don't match the
1289 * available antenna masks, except for the "all" mask */
1290 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
1291 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
))) {
1296 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
1297 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
1299 result
= rdev
->ops
->set_antenna(&rdev
->wiphy
, tx_ant
, rx_ant
);
1306 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
1307 retry_short
= nla_get_u8(
1308 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
1309 if (retry_short
== 0) {
1313 changed
|= WIPHY_PARAM_RETRY_SHORT
;
1316 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
1317 retry_long
= nla_get_u8(
1318 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
1319 if (retry_long
== 0) {
1323 changed
|= WIPHY_PARAM_RETRY_LONG
;
1326 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
1327 frag_threshold
= nla_get_u32(
1328 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
1329 if (frag_threshold
< 256) {
1333 if (frag_threshold
!= (u32
) -1) {
1335 * Fragments (apart from the last one) are required to
1336 * have even length. Make the fragmentation code
1337 * simpler by stripping LSB should someone try to use
1338 * odd threshold value.
1340 frag_threshold
&= ~0x1;
1342 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
1345 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
1346 rts_threshold
= nla_get_u32(
1347 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
1348 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
1351 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
1352 coverage_class
= nla_get_u8(
1353 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
1354 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
1358 u8 old_retry_short
, old_retry_long
;
1359 u32 old_frag_threshold
, old_rts_threshold
;
1360 u8 old_coverage_class
;
1362 if (!rdev
->ops
->set_wiphy_params
) {
1363 result
= -EOPNOTSUPP
;
1367 old_retry_short
= rdev
->wiphy
.retry_short
;
1368 old_retry_long
= rdev
->wiphy
.retry_long
;
1369 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
1370 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
1371 old_coverage_class
= rdev
->wiphy
.coverage_class
;
1373 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
1374 rdev
->wiphy
.retry_short
= retry_short
;
1375 if (changed
& WIPHY_PARAM_RETRY_LONG
)
1376 rdev
->wiphy
.retry_long
= retry_long
;
1377 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
1378 rdev
->wiphy
.frag_threshold
= frag_threshold
;
1379 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
1380 rdev
->wiphy
.rts_threshold
= rts_threshold
;
1381 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
1382 rdev
->wiphy
.coverage_class
= coverage_class
;
1384 result
= rdev
->ops
->set_wiphy_params(&rdev
->wiphy
, changed
);
1386 rdev
->wiphy
.retry_short
= old_retry_short
;
1387 rdev
->wiphy
.retry_long
= old_retry_long
;
1388 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
1389 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
1390 rdev
->wiphy
.coverage_class
= old_coverage_class
;
1395 mutex_unlock(&rdev
->mtx
);
1402 static int nl80211_send_iface(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
1403 struct cfg80211_registered_device
*rdev
,
1404 struct net_device
*dev
)
1408 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
1412 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1413 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
1414 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, dev
->name
);
1415 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, dev
->ieee80211_ptr
->iftype
);
1417 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
1418 rdev
->devlist_generation
^
1419 (cfg80211_rdev_list_generation
<< 2));
1421 return genlmsg_end(msg
, hdr
);
1424 genlmsg_cancel(msg
, hdr
);
1428 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1432 int wp_start
= cb
->args
[0];
1433 int if_start
= cb
->args
[1];
1434 struct cfg80211_registered_device
*rdev
;
1435 struct wireless_dev
*wdev
;
1437 mutex_lock(&cfg80211_mutex
);
1438 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
1439 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
1441 if (wp_idx
< wp_start
) {
1447 mutex_lock(&rdev
->devlist_mtx
);
1448 list_for_each_entry(wdev
, &rdev
->netdev_list
, list
) {
1449 if (if_idx
< if_start
) {
1453 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).pid
,
1454 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1455 rdev
, wdev
->netdev
) < 0) {
1456 mutex_unlock(&rdev
->devlist_mtx
);
1461 mutex_unlock(&rdev
->devlist_mtx
);
1466 mutex_unlock(&cfg80211_mutex
);
1468 cb
->args
[0] = wp_idx
;
1469 cb
->args
[1] = if_idx
;
1474 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1476 struct sk_buff
*msg
;
1477 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1478 struct net_device
*netdev
= info
->user_ptr
[1];
1480 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1484 if (nl80211_send_iface(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1490 return genlmsg_reply(msg
, info
);
1493 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
1494 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
1495 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
1496 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
1497 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
1498 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
1501 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
1503 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
1511 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
1512 nla
, mntr_flags_policy
))
1515 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
1517 *mntrflags
|= (1<<flag
);
1522 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
1523 struct net_device
*netdev
, u8 use_4addr
,
1524 enum nl80211_iftype iftype
)
1527 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
1533 case NL80211_IFTYPE_AP_VLAN
:
1534 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
1537 case NL80211_IFTYPE_STATION
:
1538 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
1548 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1550 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1551 struct vif_params params
;
1553 enum nl80211_iftype otype
, ntype
;
1554 struct net_device
*dev
= info
->user_ptr
[1];
1555 u32 _flags
, *flags
= NULL
;
1556 bool change
= false;
1558 memset(¶ms
, 0, sizeof(params
));
1560 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
1562 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1563 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1566 if (ntype
> NL80211_IFTYPE_MAX
)
1570 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1571 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1573 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
1575 if (netif_running(dev
))
1579 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
1580 IEEE80211_MAX_MESH_ID_LEN
);
1581 wdev
->mesh_id_up_len
=
1582 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1583 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
1584 wdev
->mesh_id_up_len
);
1588 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1589 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1591 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
1595 params
.use_4addr
= -1;
1598 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
1599 if (ntype
!= NL80211_IFTYPE_MONITOR
)
1601 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
1611 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
1615 if (!err
&& params
.use_4addr
!= -1)
1616 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
1621 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1623 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1624 struct vif_params params
;
1625 struct net_device
*dev
;
1627 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
1630 memset(¶ms
, 0, sizeof(params
));
1632 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
1635 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1636 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1637 if (type
> NL80211_IFTYPE_MAX
)
1641 if (!rdev
->ops
->add_virtual_intf
||
1642 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
1645 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1646 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1647 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
1652 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
1653 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
1655 dev
= rdev
->ops
->add_virtual_intf(&rdev
->wiphy
,
1656 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
1657 type
, err
? NULL
: &flags
, ¶ms
);
1659 return PTR_ERR(dev
);
1661 if (type
== NL80211_IFTYPE_MESH_POINT
&&
1662 info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1663 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1666 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
1667 IEEE80211_MAX_MESH_ID_LEN
);
1668 wdev
->mesh_id_up_len
=
1669 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1670 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
1671 wdev
->mesh_id_up_len
);
1678 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1680 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1681 struct net_device
*dev
= info
->user_ptr
[1];
1683 if (!rdev
->ops
->del_virtual_intf
)
1686 return rdev
->ops
->del_virtual_intf(&rdev
->wiphy
, dev
);
1689 struct get_key_cookie
{
1690 struct sk_buff
*msg
;
1695 static void get_key_callback(void *c
, struct key_params
*params
)
1698 struct get_key_cookie
*cookie
= c
;
1701 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
1702 params
->key_len
, params
->key
);
1705 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
1706 params
->seq_len
, params
->seq
);
1709 NLA_PUT_U32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
1712 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
1714 goto nla_put_failure
;
1717 NLA_PUT(cookie
->msg
, NL80211_KEY_DATA
,
1718 params
->key_len
, params
->key
);
1721 NLA_PUT(cookie
->msg
, NL80211_KEY_SEQ
,
1722 params
->seq_len
, params
->seq
);
1725 NLA_PUT_U32(cookie
->msg
, NL80211_KEY_CIPHER
,
1728 NLA_PUT_U8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
);
1730 nla_nest_end(cookie
->msg
, key
);
1737 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
1739 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1741 struct net_device
*dev
= info
->user_ptr
[1];
1743 const u8
*mac_addr
= NULL
;
1745 struct get_key_cookie cookie
= {
1749 struct sk_buff
*msg
;
1751 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
1752 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1757 if (info
->attrs
[NL80211_ATTR_MAC
])
1758 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1760 pairwise
= !!mac_addr
;
1761 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
1762 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
1763 if (kt
>= NUM_NL80211_KEYTYPES
)
1765 if (kt
!= NL80211_KEYTYPE_GROUP
&&
1766 kt
!= NL80211_KEYTYPE_PAIRWISE
)
1768 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
1771 if (!rdev
->ops
->get_key
)
1774 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1778 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1779 NL80211_CMD_NEW_KEY
);
1781 return PTR_ERR(hdr
);
1784 cookie
.idx
= key_idx
;
1786 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1787 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
1789 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1791 if (pairwise
&& mac_addr
&&
1792 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
1795 err
= rdev
->ops
->get_key(&rdev
->wiphy
, dev
, key_idx
, pairwise
,
1796 mac_addr
, &cookie
, get_key_callback
);
1802 goto nla_put_failure
;
1804 genlmsg_end(msg
, hdr
);
1805 return genlmsg_reply(msg
, info
);
1814 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
1816 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1817 struct key_parse key
;
1819 struct net_device
*dev
= info
->user_ptr
[1];
1821 err
= nl80211_parse_key(info
, &key
);
1828 /* only support setting default key */
1829 if (!key
.def
&& !key
.defmgmt
)
1832 wdev_lock(dev
->ieee80211_ptr
);
1835 if (!rdev
->ops
->set_default_key
) {
1840 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1844 err
= rdev
->ops
->set_default_key(&rdev
->wiphy
, dev
, key
.idx
,
1845 key
.def_uni
, key
.def_multi
);
1850 #ifdef CONFIG_CFG80211_WEXT
1851 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
1854 if (key
.def_uni
|| !key
.def_multi
) {
1859 if (!rdev
->ops
->set_default_mgmt_key
) {
1864 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1868 err
= rdev
->ops
->set_default_mgmt_key(&rdev
->wiphy
,
1873 #ifdef CONFIG_CFG80211_WEXT
1874 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
1879 wdev_unlock(dev
->ieee80211_ptr
);
1884 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
1886 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1888 struct net_device
*dev
= info
->user_ptr
[1];
1889 struct key_parse key
;
1890 const u8
*mac_addr
= NULL
;
1892 err
= nl80211_parse_key(info
, &key
);
1899 if (info
->attrs
[NL80211_ATTR_MAC
])
1900 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1902 if (key
.type
== -1) {
1904 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
1906 key
.type
= NL80211_KEYTYPE_GROUP
;
1910 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
1911 key
.type
!= NL80211_KEYTYPE_GROUP
)
1914 if (!rdev
->ops
->add_key
)
1917 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
1918 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
1922 wdev_lock(dev
->ieee80211_ptr
);
1923 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1925 err
= rdev
->ops
->add_key(&rdev
->wiphy
, dev
, key
.idx
,
1926 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
1928 wdev_unlock(dev
->ieee80211_ptr
);
1933 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
1935 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1937 struct net_device
*dev
= info
->user_ptr
[1];
1938 u8
*mac_addr
= NULL
;
1939 struct key_parse key
;
1941 err
= nl80211_parse_key(info
, &key
);
1945 if (info
->attrs
[NL80211_ATTR_MAC
])
1946 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1948 if (key
.type
== -1) {
1950 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
1952 key
.type
= NL80211_KEYTYPE_GROUP
;
1956 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
1957 key
.type
!= NL80211_KEYTYPE_GROUP
)
1960 if (!rdev
->ops
->del_key
)
1963 wdev_lock(dev
->ieee80211_ptr
);
1964 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1966 if (key
.type
== NL80211_KEYTYPE_PAIRWISE
&& mac_addr
&&
1967 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
1971 err
= rdev
->ops
->del_key(&rdev
->wiphy
, dev
, key
.idx
,
1972 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
1975 #ifdef CONFIG_CFG80211_WEXT
1977 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
1978 dev
->ieee80211_ptr
->wext
.default_key
= -1;
1979 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
1980 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
1983 wdev_unlock(dev
->ieee80211_ptr
);
1988 static int nl80211_addset_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1990 int (*call
)(struct wiphy
*wiphy
, struct net_device
*dev
,
1991 struct beacon_parameters
*info
);
1992 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1993 struct net_device
*dev
= info
->user_ptr
[1];
1994 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1995 struct beacon_parameters params
;
1996 int haveinfo
= 0, err
;
1998 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) ||
1999 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]) ||
2000 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) ||
2001 !is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]))
2004 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2005 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2008 memset(¶ms
, 0, sizeof(params
));
2010 switch (info
->genlhdr
->cmd
) {
2011 case NL80211_CMD_NEW_BEACON
:
2012 /* these are required for NEW_BEACON */
2013 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
2014 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
2015 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
2019 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
2020 params
.dtim_period
=
2021 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
2023 err
= cfg80211_validate_beacon_int(rdev
, params
.interval
);
2028 * In theory, some of these attributes could be required for
2029 * NEW_BEACON, but since they were not used when the command was
2030 * originally added, keep them optional for old user space
2031 * programs to work with drivers that do not need the additional
2034 if (info
->attrs
[NL80211_ATTR_SSID
]) {
2035 params
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
2037 nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
2038 if (params
.ssid_len
== 0 ||
2039 params
.ssid_len
> IEEE80211_MAX_SSID_LEN
)
2043 if (info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]) {
2044 params
.hidden_ssid
= nla_get_u32(
2045 info
->attrs
[NL80211_ATTR_HIDDEN_SSID
]);
2046 if (params
.hidden_ssid
!=
2047 NL80211_HIDDEN_SSID_NOT_IN_USE
&&
2048 params
.hidden_ssid
!=
2049 NL80211_HIDDEN_SSID_ZERO_LEN
&&
2050 params
.hidden_ssid
!=
2051 NL80211_HIDDEN_SSID_ZERO_CONTENTS
)
2055 params
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
2057 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
2058 params
.auth_type
= nla_get_u32(
2059 info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
2060 if (!nl80211_valid_auth_type(params
.auth_type
))
2063 params
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
2065 err
= nl80211_crypto_settings(rdev
, info
, ¶ms
.crypto
,
2066 NL80211_MAX_NR_CIPHER_SUITES
);
2070 call
= rdev
->ops
->add_beacon
;
2072 case NL80211_CMD_SET_BEACON
:
2073 call
= rdev
->ops
->set_beacon
;
2083 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
2084 params
.head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2086 nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2090 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
2091 params
.tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2093 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2100 if (info
->attrs
[NL80211_ATTR_IE
]) {
2101 params
.beacon_ies
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
2102 params
.beacon_ies_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
2105 if (info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]) {
2106 params
.proberesp_ies
=
2107 nla_data(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2108 params
.proberesp_ies_len
=
2109 nla_len(info
->attrs
[NL80211_ATTR_IE_PROBE_RESP
]);
2112 if (info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]) {
2113 params
.assocresp_ies
=
2114 nla_data(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2115 params
.assocresp_ies_len
=
2116 nla_len(info
->attrs
[NL80211_ATTR_IE_ASSOC_RESP
]);
2119 err
= call(&rdev
->wiphy
, dev
, ¶ms
);
2120 if (!err
&& params
.interval
)
2121 wdev
->beacon_interval
= params
.interval
;
2125 static int nl80211_del_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
2127 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2128 struct net_device
*dev
= info
->user_ptr
[1];
2129 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2132 if (!rdev
->ops
->del_beacon
)
2135 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2136 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2139 err
= rdev
->ops
->del_beacon(&rdev
->wiphy
, dev
);
2141 wdev
->beacon_interval
= 0;
2145 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
2146 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
2147 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
2148 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
2149 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
2150 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
2153 static int parse_station_flags(struct genl_info
*info
,
2154 struct station_parameters
*params
)
2156 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
2161 * Try parsing the new attribute first so userspace
2162 * can specify both for older kernels.
2164 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
2166 struct nl80211_sta_flag_update
*sta_flags
;
2168 sta_flags
= nla_data(nla
);
2169 params
->sta_flags_mask
= sta_flags
->mask
;
2170 params
->sta_flags_set
= sta_flags
->set
;
2171 if ((params
->sta_flags_mask
|
2172 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
2177 /* if present, parse the old attribute */
2179 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
2183 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
2184 nla
, sta_flags_policy
))
2187 params
->sta_flags_mask
= (1 << __NL80211_STA_FLAG_AFTER_LAST
) - 1;
2188 params
->sta_flags_mask
&= ~1;
2190 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++)
2192 params
->sta_flags_set
|= (1<<flag
);
2197 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
2200 struct nlattr
*rate
;
2203 rate
= nla_nest_start(msg
, attr
);
2205 goto nla_put_failure
;
2207 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2208 bitrate
= cfg80211_calculate_bitrate(info
);
2210 NLA_PUT_U16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate
);
2212 if (info
->flags
& RATE_INFO_FLAGS_MCS
)
2213 NLA_PUT_U8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
);
2214 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
)
2215 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
);
2216 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
)
2217 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_SHORT_GI
);
2219 nla_nest_end(msg
, rate
);
2226 static int nl80211_send_station(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2227 int flags
, struct net_device
*dev
,
2228 const u8
*mac_addr
, struct station_info
*sinfo
)
2231 struct nlattr
*sinfoattr
, *bss_param
;
2233 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2237 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2238 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
2240 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
);
2242 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
2244 goto nla_put_failure
;
2245 if (sinfo
->filled
& STATION_INFO_CONNECTED_TIME
)
2246 NLA_PUT_U32(msg
, NL80211_STA_INFO_CONNECTED_TIME
,
2247 sinfo
->connected_time
);
2248 if (sinfo
->filled
& STATION_INFO_INACTIVE_TIME
)
2249 NLA_PUT_U32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
2250 sinfo
->inactive_time
);
2251 if (sinfo
->filled
& STATION_INFO_RX_BYTES
)
2252 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_BYTES
,
2254 if (sinfo
->filled
& STATION_INFO_TX_BYTES
)
2255 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_BYTES
,
2257 if (sinfo
->filled
& STATION_INFO_LLID
)
2258 NLA_PUT_U16(msg
, NL80211_STA_INFO_LLID
,
2260 if (sinfo
->filled
& STATION_INFO_PLID
)
2261 NLA_PUT_U16(msg
, NL80211_STA_INFO_PLID
,
2263 if (sinfo
->filled
& STATION_INFO_PLINK_STATE
)
2264 NLA_PUT_U8(msg
, NL80211_STA_INFO_PLINK_STATE
,
2265 sinfo
->plink_state
);
2266 if (sinfo
->filled
& STATION_INFO_SIGNAL
)
2267 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL
,
2269 if (sinfo
->filled
& STATION_INFO_SIGNAL_AVG
)
2270 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
2272 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
2273 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
2274 NL80211_STA_INFO_TX_BITRATE
))
2275 goto nla_put_failure
;
2277 if (sinfo
->filled
& STATION_INFO_RX_BITRATE
) {
2278 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
2279 NL80211_STA_INFO_RX_BITRATE
))
2280 goto nla_put_failure
;
2282 if (sinfo
->filled
& STATION_INFO_RX_PACKETS
)
2283 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_PACKETS
,
2285 if (sinfo
->filled
& STATION_INFO_TX_PACKETS
)
2286 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_PACKETS
,
2288 if (sinfo
->filled
& STATION_INFO_TX_RETRIES
)
2289 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_RETRIES
,
2291 if (sinfo
->filled
& STATION_INFO_TX_FAILED
)
2292 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_FAILED
,
2294 if (sinfo
->filled
& STATION_INFO_BSS_PARAM
) {
2295 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
2297 goto nla_put_failure
;
2299 if (sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
)
2300 NLA_PUT_FLAG(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
);
2301 if (sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
)
2302 NLA_PUT_FLAG(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
);
2303 if (sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
)
2305 NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
);
2306 NLA_PUT_U8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
2307 sinfo
->bss_param
.dtim_period
);
2308 NLA_PUT_U16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
2309 sinfo
->bss_param
.beacon_interval
);
2311 nla_nest_end(msg
, bss_param
);
2313 nla_nest_end(msg
, sinfoattr
);
2315 if (sinfo
->filled
& STATION_INFO_ASSOC_REQ_IES
)
2316 NLA_PUT(msg
, NL80211_ATTR_IE
, sinfo
->assoc_req_ies_len
,
2317 sinfo
->assoc_req_ies
);
2319 return genlmsg_end(msg
, hdr
);
2322 genlmsg_cancel(msg
, hdr
);
2326 static int nl80211_dump_station(struct sk_buff
*skb
,
2327 struct netlink_callback
*cb
)
2329 struct station_info sinfo
;
2330 struct cfg80211_registered_device
*dev
;
2331 struct net_device
*netdev
;
2332 u8 mac_addr
[ETH_ALEN
];
2333 int sta_idx
= cb
->args
[1];
2336 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
2340 if (!dev
->ops
->dump_station
) {
2346 memset(&sinfo
, 0, sizeof(sinfo
));
2347 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
2354 if (nl80211_send_station(skb
,
2355 NETLINK_CB(cb
->skb
).pid
,
2356 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2366 cb
->args
[1] = sta_idx
;
2369 nl80211_finish_netdev_dump(dev
);
2374 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
2376 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2377 struct net_device
*dev
= info
->user_ptr
[1];
2378 struct station_info sinfo
;
2379 struct sk_buff
*msg
;
2380 u8
*mac_addr
= NULL
;
2383 memset(&sinfo
, 0, sizeof(sinfo
));
2385 if (!info
->attrs
[NL80211_ATTR_MAC
])
2388 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2390 if (!rdev
->ops
->get_station
)
2393 err
= rdev
->ops
->get_station(&rdev
->wiphy
, dev
, mac_addr
, &sinfo
);
2397 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2401 if (nl80211_send_station(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2402 dev
, mac_addr
, &sinfo
) < 0) {
2407 return genlmsg_reply(msg
, info
);
2411 * Get vlan interface making sure it is running and on the right wiphy.
2413 static int get_vlan(struct genl_info
*info
,
2414 struct cfg80211_registered_device
*rdev
,
2415 struct net_device
**vlan
)
2417 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
2421 *vlan
= dev_get_by_index(genl_info_net(info
),
2422 nla_get_u32(vlanattr
));
2425 if (!(*vlan
)->ieee80211_ptr
)
2427 if ((*vlan
)->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
)
2429 if (!netif_running(*vlan
))
2435 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
2437 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2439 struct net_device
*dev
= info
->user_ptr
[1];
2440 struct station_parameters params
;
2441 u8
*mac_addr
= NULL
;
2443 memset(¶ms
, 0, sizeof(params
));
2445 params
.listen_interval
= -1;
2446 params
.plink_state
= -1;
2448 if (info
->attrs
[NL80211_ATTR_STA_AID
])
2451 if (!info
->attrs
[NL80211_ATTR_MAC
])
2454 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2456 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
2457 params
.supported_rates
=
2458 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2459 params
.supported_rates_len
=
2460 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2463 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2464 params
.listen_interval
=
2465 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2467 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2469 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2471 if (parse_station_flags(info
, ¶ms
))
2474 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
2475 params
.plink_action
=
2476 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
2478 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
])
2479 params
.plink_state
=
2480 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
2482 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
2486 /* validate settings */
2489 switch (dev
->ieee80211_ptr
->iftype
) {
2490 case NL80211_IFTYPE_AP
:
2491 case NL80211_IFTYPE_AP_VLAN
:
2492 case NL80211_IFTYPE_P2P_GO
:
2493 /* disallow mesh-specific things */
2494 if (params
.plink_action
)
2497 case NL80211_IFTYPE_P2P_CLIENT
:
2498 case NL80211_IFTYPE_STATION
:
2499 /* disallow everything but AUTHORIZED flag */
2500 if (params
.plink_action
)
2504 if (params
.supported_rates
)
2508 if (params
.listen_interval
>= 0)
2510 if (params
.sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
2513 case NL80211_IFTYPE_MESH_POINT
:
2514 /* disallow things mesh doesn't support */
2519 if (params
.listen_interval
>= 0)
2521 if (params
.sta_flags_mask
&
2522 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
2523 BIT(NL80211_STA_FLAG_MFP
) |
2524 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
2534 if (!rdev
->ops
->change_station
) {
2539 err
= rdev
->ops
->change_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2543 dev_put(params
.vlan
);
2548 static struct nla_policy
2549 nl80211_sta_wme_policy
[NL80211_STA_WME_MAX
+ 1] __read_mostly
= {
2550 [NL80211_STA_WME_UAPSD_QUEUES
] = { .type
= NLA_U8
},
2551 [NL80211_STA_WME_MAX_SP
] = { .type
= NLA_U8
},
2554 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
2556 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2558 struct net_device
*dev
= info
->user_ptr
[1];
2559 struct station_parameters params
;
2560 u8
*mac_addr
= NULL
;
2562 memset(¶ms
, 0, sizeof(params
));
2564 if (!info
->attrs
[NL80211_ATTR_MAC
])
2567 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2570 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
2573 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
2576 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2577 params
.supported_rates
=
2578 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2579 params
.supported_rates_len
=
2580 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2581 params
.listen_interval
=
2582 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2584 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
2585 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
2588 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2590 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2592 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
2593 params
.plink_action
=
2594 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
2596 if (parse_station_flags(info
, ¶ms
))
2599 /* parse WME attributes if sta is WME capable */
2600 if ((params
.sta_flags_set
& NL80211_STA_FLAG_WME
) &&
2601 info
->attrs
[NL80211_ATTR_STA_WME
]) {
2602 struct nlattr
*tb
[NL80211_STA_WME_MAX
+ 1];
2605 nla
= info
->attrs
[NL80211_ATTR_STA_WME
];
2606 err
= nla_parse_nested(tb
, NL80211_STA_WME_MAX
, nla
,
2607 nl80211_sta_wme_policy
);
2611 if (tb
[NL80211_STA_WME_UAPSD_QUEUES
])
2612 params
.uapsd_queues
=
2613 nla_get_u8(tb
[NL80211_STA_WME_UAPSD_QUEUES
]);
2615 if (tb
[NL80211_STA_WME_MAX_SP
])
2617 nla_get_u8(tb
[NL80211_STA_WME_MAX_SP
]);
2620 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2621 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
2622 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
2623 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2626 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
2630 /* validate settings */
2633 if (!rdev
->ops
->add_station
) {
2638 err
= rdev
->ops
->add_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2642 dev_put(params
.vlan
);
2646 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
2648 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2649 struct net_device
*dev
= info
->user_ptr
[1];
2650 u8
*mac_addr
= NULL
;
2652 if (info
->attrs
[NL80211_ATTR_MAC
])
2653 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2655 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2656 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
2657 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
2658 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2661 if (!rdev
->ops
->del_station
)
2664 return rdev
->ops
->del_station(&rdev
->wiphy
, dev
, mac_addr
);
2667 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2668 int flags
, struct net_device
*dev
,
2669 u8
*dst
, u8
*next_hop
,
2670 struct mpath_info
*pinfo
)
2673 struct nlattr
*pinfoattr
;
2675 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2679 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2680 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
2681 NLA_PUT(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
);
2683 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
);
2685 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
2687 goto nla_put_failure
;
2688 if (pinfo
->filled
& MPATH_INFO_FRAME_QLEN
)
2689 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
2691 if (pinfo
->filled
& MPATH_INFO_SN
)
2692 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_SN
,
2694 if (pinfo
->filled
& MPATH_INFO_METRIC
)
2695 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_METRIC
,
2697 if (pinfo
->filled
& MPATH_INFO_EXPTIME
)
2698 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_EXPTIME
,
2700 if (pinfo
->filled
& MPATH_INFO_FLAGS
)
2701 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_FLAGS
,
2703 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
)
2704 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
2705 pinfo
->discovery_timeout
);
2706 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
)
2707 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
2708 pinfo
->discovery_retries
);
2710 nla_nest_end(msg
, pinfoattr
);
2712 return genlmsg_end(msg
, hdr
);
2715 genlmsg_cancel(msg
, hdr
);
2719 static int nl80211_dump_mpath(struct sk_buff
*skb
,
2720 struct netlink_callback
*cb
)
2722 struct mpath_info pinfo
;
2723 struct cfg80211_registered_device
*dev
;
2724 struct net_device
*netdev
;
2726 u8 next_hop
[ETH_ALEN
];
2727 int path_idx
= cb
->args
[1];
2730 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
2734 if (!dev
->ops
->dump_mpath
) {
2739 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2745 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
2746 dst
, next_hop
, &pinfo
);
2752 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).pid
,
2753 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2754 netdev
, dst
, next_hop
,
2763 cb
->args
[1] = path_idx
;
2766 nl80211_finish_netdev_dump(dev
);
2770 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2772 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2774 struct net_device
*dev
= info
->user_ptr
[1];
2775 struct mpath_info pinfo
;
2776 struct sk_buff
*msg
;
2778 u8 next_hop
[ETH_ALEN
];
2780 memset(&pinfo
, 0, sizeof(pinfo
));
2782 if (!info
->attrs
[NL80211_ATTR_MAC
])
2785 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2787 if (!rdev
->ops
->get_mpath
)
2790 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2793 err
= rdev
->ops
->get_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
2797 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2801 if (nl80211_send_mpath(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2802 dev
, dst
, next_hop
, &pinfo
) < 0) {
2807 return genlmsg_reply(msg
, info
);
2810 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2812 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2813 struct net_device
*dev
= info
->user_ptr
[1];
2815 u8
*next_hop
= NULL
;
2817 if (!info
->attrs
[NL80211_ATTR_MAC
])
2820 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2823 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2824 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2826 if (!rdev
->ops
->change_mpath
)
2829 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2832 return rdev
->ops
->change_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2835 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2837 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2838 struct net_device
*dev
= info
->user_ptr
[1];
2840 u8
*next_hop
= NULL
;
2842 if (!info
->attrs
[NL80211_ATTR_MAC
])
2845 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2848 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2849 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2851 if (!rdev
->ops
->add_mpath
)
2854 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2857 return rdev
->ops
->add_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2860 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2862 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2863 struct net_device
*dev
= info
->user_ptr
[1];
2866 if (info
->attrs
[NL80211_ATTR_MAC
])
2867 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2869 if (!rdev
->ops
->del_mpath
)
2872 return rdev
->ops
->del_mpath(&rdev
->wiphy
, dev
, dst
);
2875 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
2877 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2878 struct net_device
*dev
= info
->user_ptr
[1];
2879 struct bss_parameters params
;
2881 memset(¶ms
, 0, sizeof(params
));
2882 /* default to not changing parameters */
2883 params
.use_cts_prot
= -1;
2884 params
.use_short_preamble
= -1;
2885 params
.use_short_slot_time
= -1;
2886 params
.ap_isolate
= -1;
2887 params
.ht_opmode
= -1;
2889 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
2890 params
.use_cts_prot
=
2891 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
2892 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
2893 params
.use_short_preamble
=
2894 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
2895 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
2896 params
.use_short_slot_time
=
2897 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
2898 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
2899 params
.basic_rates
=
2900 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2901 params
.basic_rates_len
=
2902 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2904 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
2905 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
2906 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
2908 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
2910 if (!rdev
->ops
->change_bss
)
2913 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2914 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2917 return rdev
->ops
->change_bss(&rdev
->wiphy
, dev
, ¶ms
);
2920 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
2921 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
2922 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
2923 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
2924 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
2925 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
2926 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
2929 static int parse_reg_rule(struct nlattr
*tb
[],
2930 struct ieee80211_reg_rule
*reg_rule
)
2932 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
2933 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
2935 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
2937 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
2939 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
2941 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
2943 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
2946 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
2948 freq_range
->start_freq_khz
=
2949 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
2950 freq_range
->end_freq_khz
=
2951 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
2952 freq_range
->max_bandwidth_khz
=
2953 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
2955 power_rule
->max_eirp
=
2956 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
2958 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
2959 power_rule
->max_antenna_gain
=
2960 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
2965 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2971 * You should only get this when cfg80211 hasn't yet initialized
2972 * completely when built-in to the kernel right between the time
2973 * window between nl80211_init() and regulatory_init(), if that is
2976 mutex_lock(&cfg80211_mutex
);
2977 if (unlikely(!cfg80211_regdomain
)) {
2978 mutex_unlock(&cfg80211_mutex
);
2979 return -EINPROGRESS
;
2981 mutex_unlock(&cfg80211_mutex
);
2983 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2986 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2988 r
= regulatory_hint_user(data
);
2993 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
2994 struct genl_info
*info
)
2996 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2997 struct net_device
*dev
= info
->user_ptr
[1];
2998 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2999 struct mesh_config cur_params
;
3002 struct nlattr
*pinfoattr
;
3003 struct sk_buff
*msg
;
3005 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3008 if (!rdev
->ops
->get_mesh_config
)
3012 /* If not connected, get default parameters */
3013 if (!wdev
->mesh_id_len
)
3014 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
3016 err
= rdev
->ops
->get_mesh_config(&rdev
->wiphy
, dev
,
3023 /* Draw up a netlink message to send back */
3024 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3027 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
3028 NL80211_CMD_GET_MESH_CONFIG
);
3031 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
3033 goto nla_put_failure
;
3034 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
3035 NLA_PUT_U16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
3036 cur_params
.dot11MeshRetryTimeout
);
3037 NLA_PUT_U16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
3038 cur_params
.dot11MeshConfirmTimeout
);
3039 NLA_PUT_U16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
3040 cur_params
.dot11MeshHoldingTimeout
);
3041 NLA_PUT_U16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
3042 cur_params
.dot11MeshMaxPeerLinks
);
3043 NLA_PUT_U8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
3044 cur_params
.dot11MeshMaxRetries
);
3045 NLA_PUT_U8(msg
, NL80211_MESHCONF_TTL
,
3046 cur_params
.dot11MeshTTL
);
3047 NLA_PUT_U8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
3048 cur_params
.element_ttl
);
3049 NLA_PUT_U8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
3050 cur_params
.auto_open_plinks
);
3051 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
3052 cur_params
.dot11MeshHWMPmaxPREQretries
);
3053 NLA_PUT_U32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
3054 cur_params
.path_refresh_time
);
3055 NLA_PUT_U16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
3056 cur_params
.min_discovery_timeout
);
3057 NLA_PUT_U32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
3058 cur_params
.dot11MeshHWMPactivePathTimeout
);
3059 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
3060 cur_params
.dot11MeshHWMPpreqMinInterval
);
3061 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
3062 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
);
3063 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
3064 cur_params
.dot11MeshHWMPRootMode
);
3065 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
3066 cur_params
.dot11MeshHWMPRannInterval
);
3067 NLA_PUT_U8(msg
, NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
3068 cur_params
.dot11MeshGateAnnouncementProtocol
);
3069 nla_nest_end(msg
, pinfoattr
);
3070 genlmsg_end(msg
, hdr
);
3071 return genlmsg_reply(msg
, info
);
3074 genlmsg_cancel(msg
, hdr
);
3080 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
3081 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
3082 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
3083 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
3084 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
3085 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
3086 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
3087 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
3088 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
3090 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
3091 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
3092 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
3093 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
3094 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
3095 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
3096 [NL80211_MESHCONF_HWMP_ROOTMODE
] = { .type
= NLA_U8
},
3097 [NL80211_MESHCONF_HWMP_RANN_INTERVAL
] = { .type
= NLA_U16
},
3098 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS
] = { .type
= NLA_U8
},
3101 static const struct nla_policy
3102 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
3103 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
3104 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
3105 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
3106 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
3107 .len
= IEEE80211_MAX_DATA_LEN
},
3108 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
3111 static int nl80211_parse_mesh_config(struct genl_info
*info
,
3112 struct mesh_config
*cfg
,
3115 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
3118 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3120 if (table[attr_num]) {\
3121 cfg->param = nla_fn(table[attr_num]); \
3122 mask |= (1 << (attr_num - 1)); \
3127 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
3129 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
3130 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
3131 nl80211_meshconf_params_policy
))
3134 /* This makes sure that there aren't more than 32 mesh config
3135 * parameters (otherwise our bitfield scheme would not work.) */
3136 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
3138 /* Fill in the params struct */
3139 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
3140 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
, nla_get_u16
);
3141 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
3142 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
, nla_get_u16
);
3143 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
3144 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
, nla_get_u16
);
3145 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
3146 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
, nla_get_u16
);
3147 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
3148 mask
, NL80211_MESHCONF_MAX_RETRIES
, nla_get_u8
);
3149 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
3150 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
3151 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
,
3152 mask
, NL80211_MESHCONF_ELEMENT_TTL
, nla_get_u8
);
3153 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
3154 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
, nla_get_u8
);
3155 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
3156 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
3158 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
3159 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
, nla_get_u32
);
3160 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
3161 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
3163 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
3164 mask
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
3166 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
3167 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
3169 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3170 dot11MeshHWMPnetDiameterTraversalTime
,
3171 mask
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
3173 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3174 dot11MeshHWMPRootMode
, mask
,
3175 NL80211_MESHCONF_HWMP_ROOTMODE
,
3177 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3178 dot11MeshHWMPRannInterval
, mask
,
3179 NL80211_MESHCONF_HWMP_RANN_INTERVAL
,
3181 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3182 dot11MeshGateAnnouncementProtocol
, mask
,
3183 NL80211_MESHCONF_GATE_ANNOUNCEMENTS
,
3190 #undef FILL_IN_MESH_PARAM_IF_SET
3193 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
3194 struct mesh_setup
*setup
)
3196 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
3198 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
3200 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
3201 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
3202 nl80211_mesh_setup_params_policy
))
3205 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
3206 setup
->path_sel_proto
=
3207 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
3208 IEEE80211_PATH_PROTOCOL_VENDOR
:
3209 IEEE80211_PATH_PROTOCOL_HWMP
;
3211 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
3212 setup
->path_metric
=
3213 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
3214 IEEE80211_PATH_METRIC_VENDOR
:
3215 IEEE80211_PATH_METRIC_AIRTIME
;
3218 if (tb
[NL80211_MESH_SETUP_IE
]) {
3219 struct nlattr
*ieattr
=
3220 tb
[NL80211_MESH_SETUP_IE
];
3221 if (!is_valid_ie_attr(ieattr
))
3223 setup
->ie
= nla_data(ieattr
);
3224 setup
->ie_len
= nla_len(ieattr
);
3226 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
3227 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
3232 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
3233 struct genl_info
*info
)
3235 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3236 struct net_device
*dev
= info
->user_ptr
[1];
3237 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3238 struct mesh_config cfg
;
3242 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3245 if (!rdev
->ops
->update_mesh_config
)
3248 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
3253 if (!wdev
->mesh_id_len
)
3257 err
= rdev
->ops
->update_mesh_config(&rdev
->wiphy
, dev
,
3265 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3267 struct sk_buff
*msg
;
3269 struct nlattr
*nl_reg_rules
;
3273 mutex_lock(&cfg80211_mutex
);
3275 if (!cfg80211_regdomain
)
3278 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3284 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
3285 NL80211_CMD_GET_REG
);
3289 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
,
3290 cfg80211_regdomain
->alpha2
);
3292 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
3294 goto nla_put_failure
;
3296 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
3297 struct nlattr
*nl_reg_rule
;
3298 const struct ieee80211_reg_rule
*reg_rule
;
3299 const struct ieee80211_freq_range
*freq_range
;
3300 const struct ieee80211_power_rule
*power_rule
;
3302 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
3303 freq_range
= ®_rule
->freq_range
;
3304 power_rule
= ®_rule
->power_rule
;
3306 nl_reg_rule
= nla_nest_start(msg
, i
);
3308 goto nla_put_failure
;
3310 NLA_PUT_U32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
3312 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
3313 freq_range
->start_freq_khz
);
3314 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
3315 freq_range
->end_freq_khz
);
3316 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
3317 freq_range
->max_bandwidth_khz
);
3318 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
3319 power_rule
->max_antenna_gain
);
3320 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
3321 power_rule
->max_eirp
);
3323 nla_nest_end(msg
, nl_reg_rule
);
3326 nla_nest_end(msg
, nl_reg_rules
);
3328 genlmsg_end(msg
, hdr
);
3329 err
= genlmsg_reply(msg
, info
);
3333 genlmsg_cancel(msg
, hdr
);
3338 mutex_unlock(&cfg80211_mutex
);
3342 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3344 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
3345 struct nlattr
*nl_reg_rule
;
3346 char *alpha2
= NULL
;
3347 int rem_reg_rules
= 0, r
= 0;
3348 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
3349 struct ieee80211_regdomain
*rd
= NULL
;
3351 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
3354 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
3357 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
3359 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
3362 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
3366 mutex_lock(&cfg80211_mutex
);
3368 if (!reg_is_valid_request(alpha2
)) {
3373 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
3374 (num_rules
* sizeof(struct ieee80211_reg_rule
));
3376 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
3382 rd
->n_reg_rules
= num_rules
;
3383 rd
->alpha2
[0] = alpha2
[0];
3384 rd
->alpha2
[1] = alpha2
[1];
3386 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
3388 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
3389 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
3391 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
3397 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
3403 BUG_ON(rule_idx
!= num_rules
);
3407 mutex_unlock(&cfg80211_mutex
);
3412 mutex_unlock(&cfg80211_mutex
);
3417 static int validate_scan_freqs(struct nlattr
*freqs
)
3419 struct nlattr
*attr1
, *attr2
;
3420 int n_channels
= 0, tmp1
, tmp2
;
3422 nla_for_each_nested(attr1
, freqs
, tmp1
) {
3425 * Some hardware has a limited channel list for
3426 * scanning, and it is pretty much nonsensical
3427 * to scan for a channel twice, so disallow that
3428 * and don't require drivers to check that the
3429 * channel list they get isn't longer than what
3430 * they can scan, as long as they can scan all
3431 * the channels they registered at once.
3433 nla_for_each_nested(attr2
, freqs
, tmp2
)
3434 if (attr1
!= attr2
&&
3435 nla_get_u32(attr1
) == nla_get_u32(attr2
))
3442 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
3444 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3445 struct net_device
*dev
= info
->user_ptr
[1];
3446 struct cfg80211_scan_request
*request
;
3447 struct nlattr
*attr
;
3448 struct wiphy
*wiphy
;
3449 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
3452 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3455 wiphy
= &rdev
->wiphy
;
3457 if (!rdev
->ops
->scan
)
3463 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3464 n_channels
= validate_scan_freqs(
3465 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
3469 enum ieee80211_band band
;
3472 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
3473 if (wiphy
->bands
[band
])
3474 n_channels
+= wiphy
->bands
[band
]->n_channels
;
3477 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
3478 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
3481 if (n_ssids
> wiphy
->max_scan_ssids
)
3484 if (info
->attrs
[NL80211_ATTR_IE
])
3485 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3489 if (ie_len
> wiphy
->max_scan_ie_len
)
3492 request
= kzalloc(sizeof(*request
)
3493 + sizeof(*request
->ssids
) * n_ssids
3494 + sizeof(*request
->channels
) * n_channels
3495 + ie_len
, GFP_KERNEL
);
3500 request
->ssids
= (void *)&request
->channels
[n_channels
];
3501 request
->n_ssids
= n_ssids
;
3504 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
3506 request
->ie
= (void *)(request
->channels
+ n_channels
);
3510 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3511 /* user specified, bail out if channel not found */
3512 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
3513 struct ieee80211_channel
*chan
;
3515 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
3522 /* ignore disabled channels */
3523 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3526 request
->channels
[i
] = chan
;
3530 enum ieee80211_band band
;
3533 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
3535 if (!wiphy
->bands
[band
])
3537 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
3538 struct ieee80211_channel
*chan
;
3540 chan
= &wiphy
->bands
[band
]->channels
[j
];
3542 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3545 request
->channels
[i
] = chan
;
3556 request
->n_channels
= i
;
3559 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
3560 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
3561 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
3565 request
->ssids
[i
].ssid_len
= nla_len(attr
);
3566 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
3571 if (info
->attrs
[NL80211_ATTR_IE
]) {
3572 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3573 memcpy((void *)request
->ie
,
3574 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
3578 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
3579 if (wiphy
->bands
[i
])
3581 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
3583 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
3584 nla_for_each_nested(attr
,
3585 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
3587 enum ieee80211_band band
= nla_type(attr
);
3589 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
3593 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
3596 &request
->rates
[band
]);
3603 request
->wiphy
= &rdev
->wiphy
;
3605 rdev
->scan_req
= request
;
3606 err
= rdev
->ops
->scan(&rdev
->wiphy
, dev
, request
);
3609 nl80211_send_scan_start(rdev
, dev
);
3613 rdev
->scan_req
= NULL
;
3620 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
3621 struct genl_info
*info
)
3623 struct cfg80211_sched_scan_request
*request
;
3624 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3625 struct net_device
*dev
= info
->user_ptr
[1];
3626 struct nlattr
*attr
;
3627 struct wiphy
*wiphy
;
3628 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
3630 enum ieee80211_band band
;
3633 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
3634 !rdev
->ops
->sched_scan_start
)
3637 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3640 if (!info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
3643 interval
= nla_get_u32(info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
3647 wiphy
= &rdev
->wiphy
;
3649 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3650 n_channels
= validate_scan_freqs(
3651 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
3657 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
3658 if (wiphy
->bands
[band
])
3659 n_channels
+= wiphy
->bands
[band
]->n_channels
;
3662 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
3663 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
3667 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
3670 if (info
->attrs
[NL80211_ATTR_IE
])
3671 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3675 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
3678 mutex_lock(&rdev
->sched_scan_mtx
);
3680 if (rdev
->sched_scan_req
) {
3685 request
= kzalloc(sizeof(*request
)
3686 + sizeof(*request
->ssids
) * n_ssids
3687 + sizeof(*request
->channels
) * n_channels
3688 + ie_len
, GFP_KERNEL
);
3695 request
->ssids
= (void *)&request
->channels
[n_channels
];
3696 request
->n_ssids
= n_ssids
;
3699 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
3701 request
->ie
= (void *)(request
->channels
+ n_channels
);
3705 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3706 /* user specified, bail out if channel not found */
3707 nla_for_each_nested(attr
,
3708 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
3710 struct ieee80211_channel
*chan
;
3712 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
3719 /* ignore disabled channels */
3720 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3723 request
->channels
[i
] = chan
;
3728 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
3730 if (!wiphy
->bands
[band
])
3732 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
3733 struct ieee80211_channel
*chan
;
3735 chan
= &wiphy
->bands
[band
]->channels
[j
];
3737 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3740 request
->channels
[i
] = chan
;
3751 request
->n_channels
= i
;
3754 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
3755 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
3757 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
3761 request
->ssids
[i
].ssid_len
= nla_len(attr
);
3762 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
3768 if (info
->attrs
[NL80211_ATTR_IE
]) {
3769 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3770 memcpy((void *)request
->ie
,
3771 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
3776 request
->wiphy
= &rdev
->wiphy
;
3777 request
->interval
= interval
;
3779 err
= rdev
->ops
->sched_scan_start(&rdev
->wiphy
, dev
, request
);
3781 rdev
->sched_scan_req
= request
;
3782 nl80211_send_sched_scan(rdev
, dev
,
3783 NL80211_CMD_START_SCHED_SCAN
);
3790 mutex_unlock(&rdev
->sched_scan_mtx
);
3794 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
3795 struct genl_info
*info
)
3797 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3800 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
3801 !rdev
->ops
->sched_scan_stop
)
3804 mutex_lock(&rdev
->sched_scan_mtx
);
3805 err
= __cfg80211_stop_sched_scan(rdev
, false);
3806 mutex_unlock(&rdev
->sched_scan_mtx
);
3811 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
3813 struct cfg80211_registered_device
*rdev
,
3814 struct wireless_dev
*wdev
,
3815 struct cfg80211_internal_bss
*intbss
)
3817 struct cfg80211_bss
*res
= &intbss
->pub
;
3822 ASSERT_WDEV_LOCK(wdev
);
3824 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).pid
, seq
, flags
,
3825 NL80211_CMD_NEW_SCAN_RESULTS
);
3829 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
3831 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
);
3832 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
);
3834 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
3836 goto nla_put_failure
;
3837 if (!is_zero_ether_addr(res
->bssid
))
3838 NLA_PUT(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
);
3839 if (res
->information_elements
&& res
->len_information_elements
)
3840 NLA_PUT(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
3841 res
->len_information_elements
,
3842 res
->information_elements
);
3843 if (res
->beacon_ies
&& res
->len_beacon_ies
&&
3844 res
->beacon_ies
!= res
->information_elements
)
3845 NLA_PUT(msg
, NL80211_BSS_BEACON_IES
,
3846 res
->len_beacon_ies
, res
->beacon_ies
);
3848 NLA_PUT_U64(msg
, NL80211_BSS_TSF
, res
->tsf
);
3849 if (res
->beacon_interval
)
3850 NLA_PUT_U16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
);
3851 NLA_PUT_U16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
);
3852 NLA_PUT_U32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
);
3853 NLA_PUT_U32(msg
, NL80211_BSS_SEEN_MS_AGO
,
3854 jiffies_to_msecs(jiffies
- intbss
->ts
));
3856 switch (rdev
->wiphy
.signal_type
) {
3857 case CFG80211_SIGNAL_TYPE_MBM
:
3858 NLA_PUT_U32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
);
3860 case CFG80211_SIGNAL_TYPE_UNSPEC
:
3861 NLA_PUT_U8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
);
3867 switch (wdev
->iftype
) {
3868 case NL80211_IFTYPE_P2P_CLIENT
:
3869 case NL80211_IFTYPE_STATION
:
3870 if (intbss
== wdev
->current_bss
)
3871 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3872 NL80211_BSS_STATUS_ASSOCIATED
);
3873 else for (i
= 0; i
< MAX_AUTH_BSSES
; i
++) {
3874 if (intbss
!= wdev
->auth_bsses
[i
])
3876 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3877 NL80211_BSS_STATUS_AUTHENTICATED
);
3881 case NL80211_IFTYPE_ADHOC
:
3882 if (intbss
== wdev
->current_bss
)
3883 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3884 NL80211_BSS_STATUS_IBSS_JOINED
);
3890 nla_nest_end(msg
, bss
);
3892 return genlmsg_end(msg
, hdr
);
3895 genlmsg_cancel(msg
, hdr
);
3899 static int nl80211_dump_scan(struct sk_buff
*skb
,
3900 struct netlink_callback
*cb
)
3902 struct cfg80211_registered_device
*rdev
;
3903 struct net_device
*dev
;
3904 struct cfg80211_internal_bss
*scan
;
3905 struct wireless_dev
*wdev
;
3906 int start
= cb
->args
[1], idx
= 0;
3909 err
= nl80211_prepare_netdev_dump(skb
, cb
, &rdev
, &dev
);
3913 wdev
= dev
->ieee80211_ptr
;
3916 spin_lock_bh(&rdev
->bss_lock
);
3917 cfg80211_bss_expire(rdev
);
3919 cb
->seq
= rdev
->bss_generation
;
3921 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
3924 if (nl80211_send_bss(skb
, cb
,
3925 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3926 rdev
, wdev
, scan
) < 0) {
3932 spin_unlock_bh(&rdev
->bss_lock
);
3936 nl80211_finish_netdev_dump(rdev
);
3941 static int nl80211_send_survey(struct sk_buff
*msg
, u32 pid
, u32 seq
,
3942 int flags
, struct net_device
*dev
,
3943 struct survey_info
*survey
)
3946 struct nlattr
*infoattr
;
3948 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3949 NL80211_CMD_NEW_SURVEY_RESULTS
);
3953 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
3955 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
3957 goto nla_put_failure
;
3959 NLA_PUT_U32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
3960 survey
->channel
->center_freq
);
3961 if (survey
->filled
& SURVEY_INFO_NOISE_DBM
)
3962 NLA_PUT_U8(msg
, NL80211_SURVEY_INFO_NOISE
,
3964 if (survey
->filled
& SURVEY_INFO_IN_USE
)
3965 NLA_PUT_FLAG(msg
, NL80211_SURVEY_INFO_IN_USE
);
3966 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME
)
3967 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
3968 survey
->channel_time
);
3969 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
)
3970 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
3971 survey
->channel_time_busy
);
3972 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
)
3973 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
3974 survey
->channel_time_ext_busy
);
3975 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
)
3976 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
3977 survey
->channel_time_rx
);
3978 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
)
3979 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
3980 survey
->channel_time_tx
);
3982 nla_nest_end(msg
, infoattr
);
3984 return genlmsg_end(msg
, hdr
);
3987 genlmsg_cancel(msg
, hdr
);
3991 static int nl80211_dump_survey(struct sk_buff
*skb
,
3992 struct netlink_callback
*cb
)
3994 struct survey_info survey
;
3995 struct cfg80211_registered_device
*dev
;
3996 struct net_device
*netdev
;
3997 int survey_idx
= cb
->args
[1];
4000 res
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
4004 if (!dev
->ops
->dump_survey
) {
4010 struct ieee80211_channel
*chan
;
4012 res
= dev
->ops
->dump_survey(&dev
->wiphy
, netdev
, survey_idx
,
4019 /* Survey without a channel doesn't make sense */
4020 if (!survey
.channel
) {
4025 chan
= ieee80211_get_channel(&dev
->wiphy
,
4026 survey
.channel
->center_freq
);
4027 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
) {
4032 if (nl80211_send_survey(skb
,
4033 NETLINK_CB(cb
->skb
).pid
,
4034 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4042 cb
->args
[1] = survey_idx
;
4045 nl80211_finish_netdev_dump(dev
);
4049 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
)
4051 return auth_type
<= NL80211_AUTHTYPE_MAX
;
4054 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
4056 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
4057 NL80211_WPA_VERSION_2
));
4060 static bool nl80211_valid_akm_suite(u32 akm
)
4062 return akm
== WLAN_AKM_SUITE_8021X
||
4063 akm
== WLAN_AKM_SUITE_PSK
;
4066 static bool nl80211_valid_cipher_suite(u32 cipher
)
4068 return cipher
== WLAN_CIPHER_SUITE_WEP40
||
4069 cipher
== WLAN_CIPHER_SUITE_WEP104
||
4070 cipher
== WLAN_CIPHER_SUITE_TKIP
||
4071 cipher
== WLAN_CIPHER_SUITE_CCMP
||
4072 cipher
== WLAN_CIPHER_SUITE_AES_CMAC
;
4076 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
4078 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4079 struct net_device
*dev
= info
->user_ptr
[1];
4080 struct ieee80211_channel
*chan
;
4081 const u8
*bssid
, *ssid
, *ie
= NULL
;
4082 int err
, ssid_len
, ie_len
= 0;
4083 enum nl80211_auth_type auth_type
;
4084 struct key_parse key
;
4085 bool local_state_change
;
4087 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4090 if (!info
->attrs
[NL80211_ATTR_MAC
])
4093 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
4096 if (!info
->attrs
[NL80211_ATTR_SSID
])
4099 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4102 err
= nl80211_parse_key(info
, &key
);
4107 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
4109 if (!key
.p
.key
|| !key
.p
.key_len
)
4111 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
4112 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
4113 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
4114 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
4126 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
4127 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
4136 if (!rdev
->ops
->auth
)
4139 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4140 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4143 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4144 chan
= ieee80211_get_channel(&rdev
->wiphy
,
4145 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4146 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
4149 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4150 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4152 if (info
->attrs
[NL80211_ATTR_IE
]) {
4153 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4154 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4157 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4158 if (!nl80211_valid_auth_type(auth_type
))
4161 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
4163 return cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
4164 ssid
, ssid_len
, ie
, ie_len
,
4165 key
.p
.key
, key
.p
.key_len
, key
.idx
,
4166 local_state_change
);
4169 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
4170 struct genl_info
*info
,
4171 struct cfg80211_crypto_settings
*settings
,
4174 memset(settings
, 0, sizeof(*settings
));
4176 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
4178 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
4180 proto
= nla_get_u16(
4181 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
4182 settings
->control_port_ethertype
= cpu_to_be16(proto
);
4183 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
4186 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
4187 settings
->control_port_no_encrypt
= true;
4189 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
4191 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
4195 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
4196 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
4197 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
4199 if (len
% sizeof(u32
))
4202 if (settings
->n_ciphers_pairwise
> cipher_limit
)
4205 memcpy(settings
->ciphers_pairwise
, data
, len
);
4207 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
4208 if (!nl80211_valid_cipher_suite(
4209 settings
->ciphers_pairwise
[i
]))
4213 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
4214 settings
->cipher_group
=
4215 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
4216 if (!nl80211_valid_cipher_suite(settings
->cipher_group
))
4220 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
4221 settings
->wpa_versions
=
4222 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
4223 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
4227 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
4231 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
4232 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
4233 settings
->n_akm_suites
= len
/ sizeof(u32
);
4235 if (len
% sizeof(u32
))
4238 memcpy(settings
->akm_suites
, data
, len
);
4240 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
4241 if (!nl80211_valid_akm_suite(settings
->akm_suites
[i
]))
4248 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
4250 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4251 struct net_device
*dev
= info
->user_ptr
[1];
4252 struct cfg80211_crypto_settings crypto
;
4253 struct ieee80211_channel
*chan
;
4254 const u8
*bssid
, *ssid
, *ie
= NULL
, *prev_bssid
= NULL
;
4255 int err
, ssid_len
, ie_len
= 0;
4256 bool use_mfp
= false;
4258 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4261 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
4262 !info
->attrs
[NL80211_ATTR_SSID
] ||
4263 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4266 if (!rdev
->ops
->assoc
)
4269 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4270 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4273 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4275 chan
= ieee80211_get_channel(&rdev
->wiphy
,
4276 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4277 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
4280 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4281 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4283 if (info
->attrs
[NL80211_ATTR_IE
]) {
4284 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4285 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4288 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
4289 enum nl80211_mfp mfp
=
4290 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
4291 if (mfp
== NL80211_MFP_REQUIRED
)
4293 else if (mfp
!= NL80211_MFP_NO
)
4297 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
4298 prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
4300 err
= nl80211_crypto_settings(rdev
, info
, &crypto
, 1);
4302 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
, prev_bssid
,
4303 ssid
, ssid_len
, ie
, ie_len
, use_mfp
,
4309 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
4311 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4312 struct net_device
*dev
= info
->user_ptr
[1];
4313 const u8
*ie
= NULL
, *bssid
;
4316 bool local_state_change
;
4318 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4321 if (!info
->attrs
[NL80211_ATTR_MAC
])
4324 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4327 if (!rdev
->ops
->deauth
)
4330 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4331 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4334 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4336 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4337 if (reason_code
== 0) {
4338 /* Reason Code 0 is reserved */
4342 if (info
->attrs
[NL80211_ATTR_IE
]) {
4343 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4344 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4347 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
4349 return cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
4350 local_state_change
);
4353 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
4355 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4356 struct net_device
*dev
= info
->user_ptr
[1];
4357 const u8
*ie
= NULL
, *bssid
;
4360 bool local_state_change
;
4362 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4365 if (!info
->attrs
[NL80211_ATTR_MAC
])
4368 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4371 if (!rdev
->ops
->disassoc
)
4374 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4375 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4378 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4380 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4381 if (reason_code
== 0) {
4382 /* Reason Code 0 is reserved */
4386 if (info
->attrs
[NL80211_ATTR_IE
]) {
4387 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4388 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4391 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
4393 return cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
4394 local_state_change
);
4398 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
4399 int mcast_rate
[IEEE80211_NUM_BANDS
],
4402 struct wiphy
*wiphy
= &rdev
->wiphy
;
4406 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
4407 struct ieee80211_supported_band
*sband
;
4409 sband
= wiphy
->bands
[band
];
4413 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
4414 if (sband
->bitrates
[i
].bitrate
== rateval
) {
4415 mcast_rate
[band
] = i
+ 1;
4425 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
4427 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4428 struct net_device
*dev
= info
->user_ptr
[1];
4429 struct cfg80211_ibss_params ibss
;
4430 struct wiphy
*wiphy
;
4431 struct cfg80211_cached_keys
*connkeys
= NULL
;
4434 memset(&ibss
, 0, sizeof(ibss
));
4436 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4439 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
4440 !info
->attrs
[NL80211_ATTR_SSID
] ||
4441 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
4444 ibss
.beacon_interval
= 100;
4446 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
4447 ibss
.beacon_interval
=
4448 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
4449 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
4453 if (!rdev
->ops
->join_ibss
)
4456 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
4459 wiphy
= &rdev
->wiphy
;
4461 if (info
->attrs
[NL80211_ATTR_MAC
])
4462 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4463 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4464 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4466 if (info
->attrs
[NL80211_ATTR_IE
]) {
4467 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4468 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4471 ibss
.channel
= ieee80211_get_channel(wiphy
,
4472 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4473 if (!ibss
.channel
||
4474 ibss
.channel
->flags
& IEEE80211_CHAN_NO_IBSS
||
4475 ibss
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
4478 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
4479 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
4481 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
4483 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4485 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4486 struct ieee80211_supported_band
*sband
=
4487 wiphy
->bands
[ibss
.channel
->band
];
4490 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
4496 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
4497 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
4498 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
4501 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
4502 connkeys
= nl80211_parse_connkeys(rdev
,
4503 info
->attrs
[NL80211_ATTR_KEYS
]);
4504 if (IS_ERR(connkeys
))
4505 return PTR_ERR(connkeys
);
4508 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
4514 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
4516 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4517 struct net_device
*dev
= info
->user_ptr
[1];
4519 if (!rdev
->ops
->leave_ibss
)
4522 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
4525 return cfg80211_leave_ibss(rdev
, dev
, false);
4528 #ifdef CONFIG_NL80211_TESTMODE
4529 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
4533 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
4535 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4538 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
4542 if (rdev
->ops
->testmode_cmd
) {
4543 rdev
->testmode_info
= info
;
4544 err
= rdev
->ops
->testmode_cmd(&rdev
->wiphy
,
4545 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
4546 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
4547 rdev
->testmode_info
= NULL
;
4553 static int nl80211_testmode_dump(struct sk_buff
*skb
,
4554 struct netlink_callback
*cb
)
4556 struct cfg80211_registered_device
*dev
;
4564 * 0 is a valid index, but not valid for args[0],
4565 * so we need to offset by 1.
4567 phy_idx
= cb
->args
[0] - 1;
4569 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
4570 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
4574 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_WIPHY
])
4576 phy_idx
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_WIPHY
]);
4577 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
4579 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
4583 data
= nla_data((void *)cb
->args
[1]);
4584 data_len
= nla_len((void *)cb
->args
[1]);
4587 mutex_lock(&cfg80211_mutex
);
4588 dev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
4590 mutex_unlock(&cfg80211_mutex
);
4593 cfg80211_lock_rdev(dev
);
4594 mutex_unlock(&cfg80211_mutex
);
4596 if (!dev
->ops
->testmode_dump
) {
4602 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).pid
,
4603 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4604 NL80211_CMD_TESTMODE
);
4605 struct nlattr
*tmdata
;
4607 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
) < 0) {
4608 genlmsg_cancel(skb
, hdr
);
4612 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
4614 genlmsg_cancel(skb
, hdr
);
4617 err
= dev
->ops
->testmode_dump(&dev
->wiphy
, skb
, cb
,
4619 nla_nest_end(skb
, tmdata
);
4621 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
4622 genlmsg_cancel(skb
, hdr
);
4625 genlmsg_cancel(skb
, hdr
);
4629 genlmsg_end(skb
, hdr
);
4634 cb
->args
[0] = phy_idx
+ 1;
4636 cfg80211_unlock_rdev(dev
);
4640 static struct sk_buff
*
4641 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
4642 int approxlen
, u32 pid
, u32 seq
, gfp_t gfp
)
4644 struct sk_buff
*skb
;
4646 struct nlattr
*data
;
4648 skb
= nlmsg_new(approxlen
+ 100, gfp
);
4652 hdr
= nl80211hdr_put(skb
, pid
, seq
, 0, NL80211_CMD_TESTMODE
);
4658 NLA_PUT_U32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4659 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
4661 ((void **)skb
->cb
)[0] = rdev
;
4662 ((void **)skb
->cb
)[1] = hdr
;
4663 ((void **)skb
->cb
)[2] = data
;
4672 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
4675 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4677 if (WARN_ON(!rdev
->testmode_info
))
4680 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
4681 rdev
->testmode_info
->snd_pid
,
4682 rdev
->testmode_info
->snd_seq
,
4685 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
4687 int cfg80211_testmode_reply(struct sk_buff
*skb
)
4689 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
4690 void *hdr
= ((void **)skb
->cb
)[1];
4691 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4693 if (WARN_ON(!rdev
->testmode_info
)) {
4698 nla_nest_end(skb
, data
);
4699 genlmsg_end(skb
, hdr
);
4700 return genlmsg_reply(skb
, rdev
->testmode_info
);
4702 EXPORT_SYMBOL(cfg80211_testmode_reply
);
4704 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
4705 int approxlen
, gfp_t gfp
)
4707 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4709 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
4711 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
4713 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
4715 void *hdr
= ((void **)skb
->cb
)[1];
4716 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4718 nla_nest_end(skb
, data
);
4719 genlmsg_end(skb
, hdr
);
4720 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
4722 EXPORT_SYMBOL(cfg80211_testmode_event
);
4725 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
4727 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4728 struct net_device
*dev
= info
->user_ptr
[1];
4729 struct cfg80211_connect_params connect
;
4730 struct wiphy
*wiphy
;
4731 struct cfg80211_cached_keys
*connkeys
= NULL
;
4734 memset(&connect
, 0, sizeof(connect
));
4736 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4739 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
4740 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
4743 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
4745 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4746 if (!nl80211_valid_auth_type(connect
.auth_type
))
4749 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
4751 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
4753 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
4754 NL80211_MAX_NR_CIPHER_SUITES
);
4758 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4759 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4762 wiphy
= &rdev
->wiphy
;
4764 if (info
->attrs
[NL80211_ATTR_MAC
])
4765 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4766 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4767 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4769 if (info
->attrs
[NL80211_ATTR_IE
]) {
4770 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4771 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4774 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
4776 ieee80211_get_channel(wiphy
,
4777 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4778 if (!connect
.channel
||
4779 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
4783 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
4784 connkeys
= nl80211_parse_connkeys(rdev
,
4785 info
->attrs
[NL80211_ATTR_KEYS
]);
4786 if (IS_ERR(connkeys
))
4787 return PTR_ERR(connkeys
);
4790 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
4796 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
4798 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4799 struct net_device
*dev
= info
->user_ptr
[1];
4802 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4803 reason
= WLAN_REASON_DEAUTH_LEAVING
;
4805 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4810 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4811 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4814 return cfg80211_disconnect(rdev
, dev
, reason
, true);
4817 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
4819 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4824 if (!info
->attrs
[NL80211_ATTR_PID
])
4827 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
4829 net
= get_net_ns_by_pid(pid
);
4831 return PTR_ERR(net
);
4835 /* check if anything to do */
4836 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
4837 err
= cfg80211_switch_netns(rdev
, net
);
4843 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4845 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4846 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
4847 struct cfg80211_pmksa
*pmksa
) = NULL
;
4848 struct net_device
*dev
= info
->user_ptr
[1];
4849 struct cfg80211_pmksa pmksa
;
4851 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
4853 if (!info
->attrs
[NL80211_ATTR_MAC
])
4856 if (!info
->attrs
[NL80211_ATTR_PMKID
])
4859 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
4860 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4862 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4863 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4866 switch (info
->genlhdr
->cmd
) {
4867 case NL80211_CMD_SET_PMKSA
:
4868 rdev_ops
= rdev
->ops
->set_pmksa
;
4870 case NL80211_CMD_DEL_PMKSA
:
4871 rdev_ops
= rdev
->ops
->del_pmksa
;
4881 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
4884 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4886 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4887 struct net_device
*dev
= info
->user_ptr
[1];
4889 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4890 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4893 if (!rdev
->ops
->flush_pmksa
)
4896 return rdev
->ops
->flush_pmksa(&rdev
->wiphy
, dev
);
4899 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
4900 struct genl_info
*info
)
4902 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4903 struct net_device
*dev
= info
->user_ptr
[1];
4904 struct ieee80211_channel
*chan
;
4905 struct sk_buff
*msg
;
4908 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
4912 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
4913 !info
->attrs
[NL80211_ATTR_DURATION
])
4916 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
4919 * We should be on that channel for at least one jiffie,
4920 * and more than 5 seconds seems excessive.
4922 if (!duration
|| !msecs_to_jiffies(duration
) ||
4923 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
4926 if (!rdev
->ops
->remain_on_channel
)
4929 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
4930 channel_type
= nla_get_u32(
4931 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
4932 if (channel_type
!= NL80211_CHAN_NO_HT
&&
4933 channel_type
!= NL80211_CHAN_HT20
&&
4934 channel_type
!= NL80211_CHAN_HT40PLUS
&&
4935 channel_type
!= NL80211_CHAN_HT40MINUS
)
4939 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
4940 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
4944 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4948 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4949 NL80211_CMD_REMAIN_ON_CHANNEL
);
4956 err
= rdev
->ops
->remain_on_channel(&rdev
->wiphy
, dev
, chan
,
4957 channel_type
, duration
, &cookie
);
4962 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
4964 genlmsg_end(msg
, hdr
);
4966 return genlmsg_reply(msg
, info
);
4975 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
4976 struct genl_info
*info
)
4978 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4979 struct net_device
*dev
= info
->user_ptr
[1];
4982 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
4985 if (!rdev
->ops
->cancel_remain_on_channel
)
4988 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
4990 return rdev
->ops
->cancel_remain_on_channel(&rdev
->wiphy
, dev
, cookie
);
4993 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
4994 u8
*rates
, u8 rates_len
)
4999 for (i
= 0; i
< rates_len
; i
++) {
5000 int rate
= (rates
[i
] & 0x7f) * 5;
5002 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
5003 struct ieee80211_rate
*srate
=
5004 &sband
->bitrates
[ridx
];
5005 if (rate
== srate
->bitrate
) {
5010 if (ridx
== sband
->n_bitrates
)
5011 return 0; /* rate not found */
5017 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
5018 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
5019 .len
= NL80211_MAX_SUPP_RATES
},
5022 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
5023 struct genl_info
*info
)
5025 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
5026 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5027 struct cfg80211_bitrate_mask mask
;
5029 struct net_device
*dev
= info
->user_ptr
[1];
5030 struct nlattr
*tx_rates
;
5031 struct ieee80211_supported_band
*sband
;
5033 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
5036 if (!rdev
->ops
->set_bitrate_mask
)
5039 memset(&mask
, 0, sizeof(mask
));
5040 /* Default to all rates enabled */
5041 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
5042 sband
= rdev
->wiphy
.bands
[i
];
5043 mask
.control
[i
].legacy
=
5044 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
5048 * The nested attribute uses enum nl80211_band as the index. This maps
5049 * directly to the enum ieee80211_band values used in cfg80211.
5051 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
5053 enum ieee80211_band band
= nla_type(tx_rates
);
5054 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
5056 sband
= rdev
->wiphy
.bands
[band
];
5059 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
5060 nla_len(tx_rates
), nl80211_txattr_policy
);
5061 if (tb
[NL80211_TXRATE_LEGACY
]) {
5062 mask
.control
[band
].legacy
= rateset_to_mask(
5064 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
5065 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
5066 if (mask
.control
[band
].legacy
== 0)
5071 return rdev
->ops
->set_bitrate_mask(&rdev
->wiphy
, dev
, NULL
, &mask
);
5074 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
5076 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5077 struct net_device
*dev
= info
->user_ptr
[1];
5078 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
5080 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
5083 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
5084 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
5086 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5087 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
5088 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
5089 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5090 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
5091 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
5092 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5095 /* not much point in registering if we can't reply */
5096 if (!rdev
->ops
->mgmt_tx
)
5099 return cfg80211_mlme_register_mgmt(dev
->ieee80211_ptr
, info
->snd_pid
,
5101 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
5102 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
5105 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
5107 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5108 struct net_device
*dev
= info
->user_ptr
[1];
5109 struct ieee80211_channel
*chan
;
5110 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
5111 bool channel_type_valid
= false;
5116 struct sk_buff
*msg
;
5117 unsigned int wait
= 0;
5120 if (!info
->attrs
[NL80211_ATTR_FRAME
] ||
5121 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
5124 if (!rdev
->ops
->mgmt_tx
)
5127 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5128 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
5129 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
5130 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5131 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
5132 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
5133 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5136 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
5137 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
5139 wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
5142 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
5143 channel_type
= nla_get_u32(
5144 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
5145 if (channel_type
!= NL80211_CHAN_NO_HT
&&
5146 channel_type
!= NL80211_CHAN_HT20
&&
5147 channel_type
!= NL80211_CHAN_HT40PLUS
&&
5148 channel_type
!= NL80211_CHAN_HT40MINUS
)
5150 channel_type_valid
= true;
5153 offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
5155 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
5156 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
5160 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5164 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
5171 err
= cfg80211_mlme_mgmt_tx(rdev
, dev
, chan
, offchan
, channel_type
,
5172 channel_type_valid
, wait
,
5173 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
5174 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
5179 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
5181 genlmsg_end(msg
, hdr
);
5182 return genlmsg_reply(msg
, info
);
5191 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
5193 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5194 struct net_device
*dev
= info
->user_ptr
[1];
5197 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
5200 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
5203 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5204 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
5205 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
5206 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5207 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
5208 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5211 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
5213 return rdev
->ops
->mgmt_tx_cancel_wait(&rdev
->wiphy
, dev
, cookie
);
5216 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
5218 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5219 struct wireless_dev
*wdev
;
5220 struct net_device
*dev
= info
->user_ptr
[1];
5225 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
5228 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
5230 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
5233 wdev
= dev
->ieee80211_ptr
;
5235 if (!rdev
->ops
->set_power_mgmt
)
5238 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
5240 if (state
== wdev
->ps
)
5243 err
= rdev
->ops
->set_power_mgmt(wdev
->wiphy
, dev
, state
,
5250 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
5252 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5253 enum nl80211_ps_state ps_state
;
5254 struct wireless_dev
*wdev
;
5255 struct net_device
*dev
= info
->user_ptr
[1];
5256 struct sk_buff
*msg
;
5260 wdev
= dev
->ieee80211_ptr
;
5262 if (!rdev
->ops
->set_power_mgmt
)
5265 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5269 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
5270 NL80211_CMD_GET_POWER_SAVE
);
5277 ps_state
= NL80211_PS_ENABLED
;
5279 ps_state
= NL80211_PS_DISABLED
;
5281 NLA_PUT_U32(msg
, NL80211_ATTR_PS_STATE
, ps_state
);
5283 genlmsg_end(msg
, hdr
);
5284 return genlmsg_reply(msg
, info
);
5293 static struct nla_policy
5294 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
5295 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
5296 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
5297 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
5300 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
5301 s32 threshold
, u32 hysteresis
)
5303 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5304 struct wireless_dev
*wdev
;
5305 struct net_device
*dev
= info
->user_ptr
[1];
5310 wdev
= dev
->ieee80211_ptr
;
5312 if (!rdev
->ops
->set_cqm_rssi_config
)
5315 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
5316 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5319 return rdev
->ops
->set_cqm_rssi_config(wdev
->wiphy
, dev
,
5320 threshold
, hysteresis
);
5323 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
5325 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
5329 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
5335 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
5336 nl80211_attr_cqm_policy
);
5340 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
5341 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
5344 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
5345 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
5346 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
5354 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
5356 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5357 struct net_device
*dev
= info
->user_ptr
[1];
5358 struct mesh_config cfg
;
5359 struct mesh_setup setup
;
5362 /* start with default */
5363 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
5364 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
5366 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
5367 /* and parse parameters if given */
5368 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
5373 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
5374 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
5377 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
5378 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
5380 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
5381 /* parse additional setup parameters if given */
5382 err
= nl80211_parse_mesh_setup(info
, &setup
);
5387 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
5390 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
5392 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5393 struct net_device
*dev
= info
->user_ptr
[1];
5395 return cfg80211_leave_mesh(rdev
, dev
);
5398 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
5400 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5401 struct sk_buff
*msg
;
5404 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
5407 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5411 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
5412 NL80211_CMD_GET_WOWLAN
);
5414 goto nla_put_failure
;
5417 struct nlattr
*nl_wowlan
;
5419 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
5421 goto nla_put_failure
;
5423 if (rdev
->wowlan
->any
)
5424 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_ANY
);
5425 if (rdev
->wowlan
->disconnect
)
5426 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
);
5427 if (rdev
->wowlan
->magic_pkt
)
5428 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
);
5429 if (rdev
->wowlan
->gtk_rekey_failure
)
5430 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
);
5431 if (rdev
->wowlan
->eap_identity_req
)
5432 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
);
5433 if (rdev
->wowlan
->four_way_handshake
)
5434 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
);
5435 if (rdev
->wowlan
->rfkill_release
)
5436 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
);
5437 if (rdev
->wowlan
->n_patterns
) {
5438 struct nlattr
*nl_pats
, *nl_pat
;
5441 nl_pats
= nla_nest_start(msg
,
5442 NL80211_WOWLAN_TRIG_PKT_PATTERN
);
5444 goto nla_put_failure
;
5446 for (i
= 0; i
< rdev
->wowlan
->n_patterns
; i
++) {
5447 nl_pat
= nla_nest_start(msg
, i
+ 1);
5449 goto nla_put_failure
;
5450 pat_len
= rdev
->wowlan
->patterns
[i
].pattern_len
;
5451 NLA_PUT(msg
, NL80211_WOWLAN_PKTPAT_MASK
,
5452 DIV_ROUND_UP(pat_len
, 8),
5453 rdev
->wowlan
->patterns
[i
].mask
);
5454 NLA_PUT(msg
, NL80211_WOWLAN_PKTPAT_PATTERN
,
5456 rdev
->wowlan
->patterns
[i
].pattern
);
5457 nla_nest_end(msg
, nl_pat
);
5459 nla_nest_end(msg
, nl_pats
);
5462 nla_nest_end(msg
, nl_wowlan
);
5465 genlmsg_end(msg
, hdr
);
5466 return genlmsg_reply(msg
, info
);
5473 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
5475 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5476 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
5477 struct cfg80211_wowlan no_triggers
= {};
5478 struct cfg80211_wowlan new_triggers
= {};
5479 struct wiphy_wowlan_support
*wowlan
= &rdev
->wiphy
.wowlan
;
5482 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
5485 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
])
5488 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
5489 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
5490 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
5491 nl80211_wowlan_policy
);
5495 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
5496 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
5498 new_triggers
.any
= true;
5501 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
5502 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
5504 new_triggers
.disconnect
= true;
5507 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
5508 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
5510 new_triggers
.magic_pkt
= true;
5513 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
5516 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
5517 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
5519 new_triggers
.gtk_rekey_failure
= true;
5522 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
5523 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
5525 new_triggers
.eap_identity_req
= true;
5528 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
5529 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
5531 new_triggers
.four_way_handshake
= true;
5534 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
5535 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
5537 new_triggers
.rfkill_release
= true;
5540 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
5543 int rem
, pat_len
, mask_len
;
5544 struct nlattr
*pat_tb
[NUM_NL80211_WOWLAN_PKTPAT
];
5546 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
5549 if (n_patterns
> wowlan
->n_patterns
)
5552 new_triggers
.patterns
= kcalloc(n_patterns
,
5553 sizeof(new_triggers
.patterns
[0]),
5555 if (!new_triggers
.patterns
)
5558 new_triggers
.n_patterns
= n_patterns
;
5561 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
5563 nla_parse(pat_tb
, MAX_NL80211_WOWLAN_PKTPAT
,
5564 nla_data(pat
), nla_len(pat
), NULL
);
5566 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
] ||
5567 !pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
])
5569 pat_len
= nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]);
5570 mask_len
= DIV_ROUND_UP(pat_len
, 8);
5571 if (nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]) !=
5574 if (pat_len
> wowlan
->pattern_max_len
||
5575 pat_len
< wowlan
->pattern_min_len
)
5578 new_triggers
.patterns
[i
].mask
=
5579 kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
5580 if (!new_triggers
.patterns
[i
].mask
) {
5584 new_triggers
.patterns
[i
].pattern
=
5585 new_triggers
.patterns
[i
].mask
+ mask_len
;
5586 memcpy(new_triggers
.patterns
[i
].mask
,
5587 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]),
5589 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
5590 memcpy(new_triggers
.patterns
[i
].pattern
,
5591 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]),
5597 if (memcmp(&new_triggers
, &no_triggers
, sizeof(new_triggers
))) {
5598 struct cfg80211_wowlan
*ntrig
;
5599 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
),
5605 cfg80211_rdev_free_wowlan(rdev
);
5606 rdev
->wowlan
= ntrig
;
5609 cfg80211_rdev_free_wowlan(rdev
);
5610 rdev
->wowlan
= NULL
;
5615 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
5616 kfree(new_triggers
.patterns
[i
].mask
);
5617 kfree(new_triggers
.patterns
);
5621 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
5623 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5624 struct net_device
*dev
= info
->user_ptr
[1];
5625 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5626 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
5627 struct cfg80211_gtk_rekey_data rekey_data
;
5630 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
5633 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
5634 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
5635 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
5636 nl80211_rekey_policy
);
5640 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
5642 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
5644 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
5647 memcpy(rekey_data
.kek
, nla_data(tb
[NL80211_REKEY_DATA_KEK
]),
5649 memcpy(rekey_data
.kck
, nla_data(tb
[NL80211_REKEY_DATA_KCK
]),
5651 memcpy(rekey_data
.replay_ctr
,
5652 nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]),
5653 NL80211_REPLAY_CTR_LEN
);
5656 if (!wdev
->current_bss
) {
5661 if (!rdev
->ops
->set_rekey_data
) {
5666 err
= rdev
->ops
->set_rekey_data(&rdev
->wiphy
, dev
, &rekey_data
);
5672 #define NL80211_FLAG_NEED_WIPHY 0x01
5673 #define NL80211_FLAG_NEED_NETDEV 0x02
5674 #define NL80211_FLAG_NEED_RTNL 0x04
5675 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
5676 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
5677 NL80211_FLAG_CHECK_NETDEV_UP)
5679 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
5680 struct genl_info
*info
)
5682 struct cfg80211_registered_device
*rdev
;
5683 struct net_device
*dev
;
5685 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
5690 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
5691 rdev
= cfg80211_get_dev_from_info(info
);
5695 return PTR_ERR(rdev
);
5697 info
->user_ptr
[0] = rdev
;
5698 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
5699 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
5705 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
5706 !netif_running(dev
)) {
5707 cfg80211_unlock_rdev(rdev
);
5713 info
->user_ptr
[0] = rdev
;
5714 info
->user_ptr
[1] = dev
;
5720 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
5721 struct genl_info
*info
)
5723 if (info
->user_ptr
[0])
5724 cfg80211_unlock_rdev(info
->user_ptr
[0]);
5725 if (info
->user_ptr
[1])
5726 dev_put(info
->user_ptr
[1]);
5727 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
5731 static struct genl_ops nl80211_ops
[] = {
5733 .cmd
= NL80211_CMD_GET_WIPHY
,
5734 .doit
= nl80211_get_wiphy
,
5735 .dumpit
= nl80211_dump_wiphy
,
5736 .policy
= nl80211_policy
,
5737 /* can be retrieved by unprivileged users */
5738 .internal_flags
= NL80211_FLAG_NEED_WIPHY
,
5741 .cmd
= NL80211_CMD_SET_WIPHY
,
5742 .doit
= nl80211_set_wiphy
,
5743 .policy
= nl80211_policy
,
5744 .flags
= GENL_ADMIN_PERM
,
5745 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
5748 .cmd
= NL80211_CMD_GET_INTERFACE
,
5749 .doit
= nl80211_get_interface
,
5750 .dumpit
= nl80211_dump_interface
,
5751 .policy
= nl80211_policy
,
5752 /* can be retrieved by unprivileged users */
5753 .internal_flags
= NL80211_FLAG_NEED_NETDEV
,
5756 .cmd
= NL80211_CMD_SET_INTERFACE
,
5757 .doit
= nl80211_set_interface
,
5758 .policy
= nl80211_policy
,
5759 .flags
= GENL_ADMIN_PERM
,
5760 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5761 NL80211_FLAG_NEED_RTNL
,
5764 .cmd
= NL80211_CMD_NEW_INTERFACE
,
5765 .doit
= nl80211_new_interface
,
5766 .policy
= nl80211_policy
,
5767 .flags
= GENL_ADMIN_PERM
,
5768 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
5769 NL80211_FLAG_NEED_RTNL
,
5772 .cmd
= NL80211_CMD_DEL_INTERFACE
,
5773 .doit
= nl80211_del_interface
,
5774 .policy
= nl80211_policy
,
5775 .flags
= GENL_ADMIN_PERM
,
5776 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5777 NL80211_FLAG_NEED_RTNL
,
5780 .cmd
= NL80211_CMD_GET_KEY
,
5781 .doit
= nl80211_get_key
,
5782 .policy
= nl80211_policy
,
5783 .flags
= GENL_ADMIN_PERM
,
5784 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5785 NL80211_FLAG_NEED_RTNL
,
5788 .cmd
= NL80211_CMD_SET_KEY
,
5789 .doit
= nl80211_set_key
,
5790 .policy
= nl80211_policy
,
5791 .flags
= GENL_ADMIN_PERM
,
5792 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5793 NL80211_FLAG_NEED_RTNL
,
5796 .cmd
= NL80211_CMD_NEW_KEY
,
5797 .doit
= nl80211_new_key
,
5798 .policy
= nl80211_policy
,
5799 .flags
= GENL_ADMIN_PERM
,
5800 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5801 NL80211_FLAG_NEED_RTNL
,
5804 .cmd
= NL80211_CMD_DEL_KEY
,
5805 .doit
= nl80211_del_key
,
5806 .policy
= nl80211_policy
,
5807 .flags
= GENL_ADMIN_PERM
,
5808 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5809 NL80211_FLAG_NEED_RTNL
,
5812 .cmd
= NL80211_CMD_SET_BEACON
,
5813 .policy
= nl80211_policy
,
5814 .flags
= GENL_ADMIN_PERM
,
5815 .doit
= nl80211_addset_beacon
,
5816 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5817 NL80211_FLAG_NEED_RTNL
,
5820 .cmd
= NL80211_CMD_NEW_BEACON
,
5821 .policy
= nl80211_policy
,
5822 .flags
= GENL_ADMIN_PERM
,
5823 .doit
= nl80211_addset_beacon
,
5824 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5825 NL80211_FLAG_NEED_RTNL
,
5828 .cmd
= NL80211_CMD_DEL_BEACON
,
5829 .policy
= nl80211_policy
,
5830 .flags
= GENL_ADMIN_PERM
,
5831 .doit
= nl80211_del_beacon
,
5832 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5833 NL80211_FLAG_NEED_RTNL
,
5836 .cmd
= NL80211_CMD_GET_STATION
,
5837 .doit
= nl80211_get_station
,
5838 .dumpit
= nl80211_dump_station
,
5839 .policy
= nl80211_policy
,
5840 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5841 NL80211_FLAG_NEED_RTNL
,
5844 .cmd
= NL80211_CMD_SET_STATION
,
5845 .doit
= nl80211_set_station
,
5846 .policy
= nl80211_policy
,
5847 .flags
= GENL_ADMIN_PERM
,
5848 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5849 NL80211_FLAG_NEED_RTNL
,
5852 .cmd
= NL80211_CMD_NEW_STATION
,
5853 .doit
= nl80211_new_station
,
5854 .policy
= nl80211_policy
,
5855 .flags
= GENL_ADMIN_PERM
,
5856 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5857 NL80211_FLAG_NEED_RTNL
,
5860 .cmd
= NL80211_CMD_DEL_STATION
,
5861 .doit
= nl80211_del_station
,
5862 .policy
= nl80211_policy
,
5863 .flags
= GENL_ADMIN_PERM
,
5864 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5865 NL80211_FLAG_NEED_RTNL
,
5868 .cmd
= NL80211_CMD_GET_MPATH
,
5869 .doit
= nl80211_get_mpath
,
5870 .dumpit
= nl80211_dump_mpath
,
5871 .policy
= nl80211_policy
,
5872 .flags
= GENL_ADMIN_PERM
,
5873 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5874 NL80211_FLAG_NEED_RTNL
,
5877 .cmd
= NL80211_CMD_SET_MPATH
,
5878 .doit
= nl80211_set_mpath
,
5879 .policy
= nl80211_policy
,
5880 .flags
= GENL_ADMIN_PERM
,
5881 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5882 NL80211_FLAG_NEED_RTNL
,
5885 .cmd
= NL80211_CMD_NEW_MPATH
,
5886 .doit
= nl80211_new_mpath
,
5887 .policy
= nl80211_policy
,
5888 .flags
= GENL_ADMIN_PERM
,
5889 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5890 NL80211_FLAG_NEED_RTNL
,
5893 .cmd
= NL80211_CMD_DEL_MPATH
,
5894 .doit
= nl80211_del_mpath
,
5895 .policy
= nl80211_policy
,
5896 .flags
= GENL_ADMIN_PERM
,
5897 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5898 NL80211_FLAG_NEED_RTNL
,
5901 .cmd
= NL80211_CMD_SET_BSS
,
5902 .doit
= nl80211_set_bss
,
5903 .policy
= nl80211_policy
,
5904 .flags
= GENL_ADMIN_PERM
,
5905 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5906 NL80211_FLAG_NEED_RTNL
,
5909 .cmd
= NL80211_CMD_GET_REG
,
5910 .doit
= nl80211_get_reg
,
5911 .policy
= nl80211_policy
,
5912 /* can be retrieved by unprivileged users */
5915 .cmd
= NL80211_CMD_SET_REG
,
5916 .doit
= nl80211_set_reg
,
5917 .policy
= nl80211_policy
,
5918 .flags
= GENL_ADMIN_PERM
,
5921 .cmd
= NL80211_CMD_REQ_SET_REG
,
5922 .doit
= nl80211_req_set_reg
,
5923 .policy
= nl80211_policy
,
5924 .flags
= GENL_ADMIN_PERM
,
5927 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
5928 .doit
= nl80211_get_mesh_config
,
5929 .policy
= nl80211_policy
,
5930 /* can be retrieved by unprivileged users */
5931 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5932 NL80211_FLAG_NEED_RTNL
,
5935 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
5936 .doit
= nl80211_update_mesh_config
,
5937 .policy
= nl80211_policy
,
5938 .flags
= GENL_ADMIN_PERM
,
5939 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5940 NL80211_FLAG_NEED_RTNL
,
5943 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
5944 .doit
= nl80211_trigger_scan
,
5945 .policy
= nl80211_policy
,
5946 .flags
= GENL_ADMIN_PERM
,
5947 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5948 NL80211_FLAG_NEED_RTNL
,
5951 .cmd
= NL80211_CMD_GET_SCAN
,
5952 .policy
= nl80211_policy
,
5953 .dumpit
= nl80211_dump_scan
,
5956 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
5957 .doit
= nl80211_start_sched_scan
,
5958 .policy
= nl80211_policy
,
5959 .flags
= GENL_ADMIN_PERM
,
5960 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5961 NL80211_FLAG_NEED_RTNL
,
5964 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
5965 .doit
= nl80211_stop_sched_scan
,
5966 .policy
= nl80211_policy
,
5967 .flags
= GENL_ADMIN_PERM
,
5968 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5969 NL80211_FLAG_NEED_RTNL
,
5972 .cmd
= NL80211_CMD_AUTHENTICATE
,
5973 .doit
= nl80211_authenticate
,
5974 .policy
= nl80211_policy
,
5975 .flags
= GENL_ADMIN_PERM
,
5976 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5977 NL80211_FLAG_NEED_RTNL
,
5980 .cmd
= NL80211_CMD_ASSOCIATE
,
5981 .doit
= nl80211_associate
,
5982 .policy
= nl80211_policy
,
5983 .flags
= GENL_ADMIN_PERM
,
5984 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5985 NL80211_FLAG_NEED_RTNL
,
5988 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
5989 .doit
= nl80211_deauthenticate
,
5990 .policy
= nl80211_policy
,
5991 .flags
= GENL_ADMIN_PERM
,
5992 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5993 NL80211_FLAG_NEED_RTNL
,
5996 .cmd
= NL80211_CMD_DISASSOCIATE
,
5997 .doit
= nl80211_disassociate
,
5998 .policy
= nl80211_policy
,
5999 .flags
= GENL_ADMIN_PERM
,
6000 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6001 NL80211_FLAG_NEED_RTNL
,
6004 .cmd
= NL80211_CMD_JOIN_IBSS
,
6005 .doit
= nl80211_join_ibss
,
6006 .policy
= nl80211_policy
,
6007 .flags
= GENL_ADMIN_PERM
,
6008 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6009 NL80211_FLAG_NEED_RTNL
,
6012 .cmd
= NL80211_CMD_LEAVE_IBSS
,
6013 .doit
= nl80211_leave_ibss
,
6014 .policy
= nl80211_policy
,
6015 .flags
= GENL_ADMIN_PERM
,
6016 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6017 NL80211_FLAG_NEED_RTNL
,
6019 #ifdef CONFIG_NL80211_TESTMODE
6021 .cmd
= NL80211_CMD_TESTMODE
,
6022 .doit
= nl80211_testmode_do
,
6023 .dumpit
= nl80211_testmode_dump
,
6024 .policy
= nl80211_policy
,
6025 .flags
= GENL_ADMIN_PERM
,
6026 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
6027 NL80211_FLAG_NEED_RTNL
,
6031 .cmd
= NL80211_CMD_CONNECT
,
6032 .doit
= nl80211_connect
,
6033 .policy
= nl80211_policy
,
6034 .flags
= GENL_ADMIN_PERM
,
6035 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6036 NL80211_FLAG_NEED_RTNL
,
6039 .cmd
= NL80211_CMD_DISCONNECT
,
6040 .doit
= nl80211_disconnect
,
6041 .policy
= nl80211_policy
,
6042 .flags
= GENL_ADMIN_PERM
,
6043 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6044 NL80211_FLAG_NEED_RTNL
,
6047 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
6048 .doit
= nl80211_wiphy_netns
,
6049 .policy
= nl80211_policy
,
6050 .flags
= GENL_ADMIN_PERM
,
6051 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
6052 NL80211_FLAG_NEED_RTNL
,
6055 .cmd
= NL80211_CMD_GET_SURVEY
,
6056 .policy
= nl80211_policy
,
6057 .dumpit
= nl80211_dump_survey
,
6060 .cmd
= NL80211_CMD_SET_PMKSA
,
6061 .doit
= nl80211_setdel_pmksa
,
6062 .policy
= nl80211_policy
,
6063 .flags
= GENL_ADMIN_PERM
,
6064 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6065 NL80211_FLAG_NEED_RTNL
,
6068 .cmd
= NL80211_CMD_DEL_PMKSA
,
6069 .doit
= nl80211_setdel_pmksa
,
6070 .policy
= nl80211_policy
,
6071 .flags
= GENL_ADMIN_PERM
,
6072 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6073 NL80211_FLAG_NEED_RTNL
,
6076 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
6077 .doit
= nl80211_flush_pmksa
,
6078 .policy
= nl80211_policy
,
6079 .flags
= GENL_ADMIN_PERM
,
6080 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6081 NL80211_FLAG_NEED_RTNL
,
6084 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
6085 .doit
= nl80211_remain_on_channel
,
6086 .policy
= nl80211_policy
,
6087 .flags
= GENL_ADMIN_PERM
,
6088 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6089 NL80211_FLAG_NEED_RTNL
,
6092 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
6093 .doit
= nl80211_cancel_remain_on_channel
,
6094 .policy
= nl80211_policy
,
6095 .flags
= GENL_ADMIN_PERM
,
6096 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6097 NL80211_FLAG_NEED_RTNL
,
6100 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
6101 .doit
= nl80211_set_tx_bitrate_mask
,
6102 .policy
= nl80211_policy
,
6103 .flags
= GENL_ADMIN_PERM
,
6104 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6105 NL80211_FLAG_NEED_RTNL
,
6108 .cmd
= NL80211_CMD_REGISTER_FRAME
,
6109 .doit
= nl80211_register_mgmt
,
6110 .policy
= nl80211_policy
,
6111 .flags
= GENL_ADMIN_PERM
,
6112 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6113 NL80211_FLAG_NEED_RTNL
,
6116 .cmd
= NL80211_CMD_FRAME
,
6117 .doit
= nl80211_tx_mgmt
,
6118 .policy
= nl80211_policy
,
6119 .flags
= GENL_ADMIN_PERM
,
6120 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6121 NL80211_FLAG_NEED_RTNL
,
6124 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
6125 .doit
= nl80211_tx_mgmt_cancel_wait
,
6126 .policy
= nl80211_policy
,
6127 .flags
= GENL_ADMIN_PERM
,
6128 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6129 NL80211_FLAG_NEED_RTNL
,
6132 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
6133 .doit
= nl80211_set_power_save
,
6134 .policy
= nl80211_policy
,
6135 .flags
= GENL_ADMIN_PERM
,
6136 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6137 NL80211_FLAG_NEED_RTNL
,
6140 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
6141 .doit
= nl80211_get_power_save
,
6142 .policy
= nl80211_policy
,
6143 /* can be retrieved by unprivileged users */
6144 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6145 NL80211_FLAG_NEED_RTNL
,
6148 .cmd
= NL80211_CMD_SET_CQM
,
6149 .doit
= nl80211_set_cqm
,
6150 .policy
= nl80211_policy
,
6151 .flags
= GENL_ADMIN_PERM
,
6152 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6153 NL80211_FLAG_NEED_RTNL
,
6156 .cmd
= NL80211_CMD_SET_CHANNEL
,
6157 .doit
= nl80211_set_channel
,
6158 .policy
= nl80211_policy
,
6159 .flags
= GENL_ADMIN_PERM
,
6160 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6161 NL80211_FLAG_NEED_RTNL
,
6164 .cmd
= NL80211_CMD_SET_WDS_PEER
,
6165 .doit
= nl80211_set_wds_peer
,
6166 .policy
= nl80211_policy
,
6167 .flags
= GENL_ADMIN_PERM
,
6168 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6169 NL80211_FLAG_NEED_RTNL
,
6172 .cmd
= NL80211_CMD_JOIN_MESH
,
6173 .doit
= nl80211_join_mesh
,
6174 .policy
= nl80211_policy
,
6175 .flags
= GENL_ADMIN_PERM
,
6176 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6177 NL80211_FLAG_NEED_RTNL
,
6180 .cmd
= NL80211_CMD_LEAVE_MESH
,
6181 .doit
= nl80211_leave_mesh
,
6182 .policy
= nl80211_policy
,
6183 .flags
= GENL_ADMIN_PERM
,
6184 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6185 NL80211_FLAG_NEED_RTNL
,
6188 .cmd
= NL80211_CMD_GET_WOWLAN
,
6189 .doit
= nl80211_get_wowlan
,
6190 .policy
= nl80211_policy
,
6191 /* can be retrieved by unprivileged users */
6192 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
6193 NL80211_FLAG_NEED_RTNL
,
6196 .cmd
= NL80211_CMD_SET_WOWLAN
,
6197 .doit
= nl80211_set_wowlan
,
6198 .policy
= nl80211_policy
,
6199 .flags
= GENL_ADMIN_PERM
,
6200 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
6201 NL80211_FLAG_NEED_RTNL
,
6204 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
6205 .doit
= nl80211_set_rekey_data
,
6206 .policy
= nl80211_policy
,
6207 .flags
= GENL_ADMIN_PERM
,
6208 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6209 NL80211_FLAG_NEED_RTNL
,
6213 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
6217 /* multicast groups */
6218 static struct genl_multicast_group nl80211_config_mcgrp
= {
6221 static struct genl_multicast_group nl80211_scan_mcgrp
= {
6224 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
6225 .name
= "regulatory",
6228 /* notification functions */
6230 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
6232 struct sk_buff
*msg
;
6234 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6238 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
6243 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6244 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
6247 static int nl80211_add_scan_req(struct sk_buff
*msg
,
6248 struct cfg80211_registered_device
*rdev
)
6250 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
6251 struct nlattr
*nest
;
6254 ASSERT_RDEV_LOCK(rdev
);
6259 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
6261 goto nla_put_failure
;
6262 for (i
= 0; i
< req
->n_ssids
; i
++)
6263 NLA_PUT(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
);
6264 nla_nest_end(msg
, nest
);
6266 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
6268 goto nla_put_failure
;
6269 for (i
= 0; i
< req
->n_channels
; i
++)
6270 NLA_PUT_U32(msg
, i
, req
->channels
[i
]->center_freq
);
6271 nla_nest_end(msg
, nest
);
6274 NLA_PUT(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
);
6281 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
6282 struct cfg80211_registered_device
*rdev
,
6283 struct net_device
*netdev
,
6284 u32 pid
, u32 seq
, int flags
,
6289 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
6293 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6294 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6296 /* ignore errors and send incomplete event anyway */
6297 nl80211_add_scan_req(msg
, rdev
);
6299 return genlmsg_end(msg
, hdr
);
6302 genlmsg_cancel(msg
, hdr
);
6307 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
6308 struct cfg80211_registered_device
*rdev
,
6309 struct net_device
*netdev
,
6310 u32 pid
, u32 seq
, int flags
, u32 cmd
)
6314 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
6318 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6319 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6321 return genlmsg_end(msg
, hdr
);
6324 genlmsg_cancel(msg
, hdr
);
6328 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
6329 struct net_device
*netdev
)
6331 struct sk_buff
*msg
;
6333 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
6337 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
6338 NL80211_CMD_TRIGGER_SCAN
) < 0) {
6343 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6344 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6347 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
6348 struct net_device
*netdev
)
6350 struct sk_buff
*msg
;
6352 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6356 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
6357 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
6362 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6363 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6366 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
6367 struct net_device
*netdev
)
6369 struct sk_buff
*msg
;
6371 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6375 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
6376 NL80211_CMD_SCAN_ABORTED
) < 0) {
6381 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6382 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6385 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
6386 struct net_device
*netdev
)
6388 struct sk_buff
*msg
;
6390 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6394 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
6395 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
6400 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6401 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6404 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
6405 struct net_device
*netdev
, u32 cmd
)
6407 struct sk_buff
*msg
;
6409 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
6413 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
6418 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6419 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6423 * This can happen on global regulatory changes or device specific settings
6424 * based on custom world regulatory domains.
6426 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
6428 struct sk_buff
*msg
;
6431 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6435 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
6441 /* Userspace can always count this one always being set */
6442 NLA_PUT_U8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
);
6444 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0')
6445 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6446 NL80211_REGDOM_TYPE_WORLD
);
6447 else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9')
6448 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6449 NL80211_REGDOM_TYPE_CUSTOM_WORLD
);
6450 else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
6452 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6453 NL80211_REGDOM_TYPE_INTERSECTION
);
6455 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6456 NL80211_REGDOM_TYPE_COUNTRY
);
6457 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, request
->alpha2
);
6460 if (wiphy_idx_valid(request
->wiphy_idx
))
6461 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
);
6463 if (genlmsg_end(msg
, hdr
) < 0) {
6469 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
6476 genlmsg_cancel(msg
, hdr
);
6480 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
6481 struct net_device
*netdev
,
6482 const u8
*buf
, size_t len
,
6483 enum nl80211_commands cmd
, gfp_t gfp
)
6485 struct sk_buff
*msg
;
6488 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6492 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
6498 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6499 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6500 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
6502 if (genlmsg_end(msg
, hdr
) < 0) {
6507 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6508 nl80211_mlme_mcgrp
.id
, gfp
);
6512 genlmsg_cancel(msg
, hdr
);
6516 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
6517 struct net_device
*netdev
, const u8
*buf
,
6518 size_t len
, gfp_t gfp
)
6520 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6521 NL80211_CMD_AUTHENTICATE
, gfp
);
6524 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
6525 struct net_device
*netdev
, const u8
*buf
,
6526 size_t len
, gfp_t gfp
)
6528 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6529 NL80211_CMD_ASSOCIATE
, gfp
);
6532 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
6533 struct net_device
*netdev
, const u8
*buf
,
6534 size_t len
, gfp_t gfp
)
6536 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6537 NL80211_CMD_DEAUTHENTICATE
, gfp
);
6540 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
6541 struct net_device
*netdev
, const u8
*buf
,
6542 size_t len
, gfp_t gfp
)
6544 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6545 NL80211_CMD_DISASSOCIATE
, gfp
);
6548 void nl80211_send_unprot_deauth(struct cfg80211_registered_device
*rdev
,
6549 struct net_device
*netdev
, const u8
*buf
,
6550 size_t len
, gfp_t gfp
)
6552 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6553 NL80211_CMD_UNPROT_DEAUTHENTICATE
, gfp
);
6556 void nl80211_send_unprot_disassoc(struct cfg80211_registered_device
*rdev
,
6557 struct net_device
*netdev
, const u8
*buf
,
6558 size_t len
, gfp_t gfp
)
6560 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6561 NL80211_CMD_UNPROT_DISASSOCIATE
, gfp
);
6564 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
6565 struct net_device
*netdev
, int cmd
,
6566 const u8
*addr
, gfp_t gfp
)
6568 struct sk_buff
*msg
;
6571 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6575 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
6581 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6582 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6583 NLA_PUT_FLAG(msg
, NL80211_ATTR_TIMED_OUT
);
6584 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
6586 if (genlmsg_end(msg
, hdr
) < 0) {
6591 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6592 nl80211_mlme_mcgrp
.id
, gfp
);
6596 genlmsg_cancel(msg
, hdr
);
6600 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
6601 struct net_device
*netdev
, const u8
*addr
,
6604 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
6608 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
6609 struct net_device
*netdev
, const u8
*addr
,
6612 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
6616 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
6617 struct net_device
*netdev
, const u8
*bssid
,
6618 const u8
*req_ie
, size_t req_ie_len
,
6619 const u8
*resp_ie
, size_t resp_ie_len
,
6620 u16 status
, gfp_t gfp
)
6622 struct sk_buff
*msg
;
6625 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6629 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
6635 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6636 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6638 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
6639 NLA_PUT_U16(msg
, NL80211_ATTR_STATUS_CODE
, status
);
6641 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
6643 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
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
);
6660 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
6661 struct net_device
*netdev
, const u8
*bssid
,
6662 const u8
*req_ie
, size_t req_ie_len
,
6663 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
6665 struct sk_buff
*msg
;
6668 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6672 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
6678 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6679 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6680 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
6682 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
6684 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
6686 if (genlmsg_end(msg
, hdr
) < 0) {
6691 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6692 nl80211_mlme_mcgrp
.id
, gfp
);
6696 genlmsg_cancel(msg
, hdr
);
6701 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
6702 struct net_device
*netdev
, u16 reason
,
6703 const u8
*ie
, size_t ie_len
, bool from_ap
)
6705 struct sk_buff
*msg
;
6708 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
6712 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
6718 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6719 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6720 if (from_ap
&& reason
)
6721 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason
);
6723 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
);
6725 NLA_PUT(msg
, NL80211_ATTR_IE
, ie_len
, ie
);
6727 if (genlmsg_end(msg
, hdr
) < 0) {
6732 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6733 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
6737 genlmsg_cancel(msg
, hdr
);
6742 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
6743 struct net_device
*netdev
, const u8
*bssid
,
6746 struct sk_buff
*msg
;
6749 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6753 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
6759 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6760 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6761 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
6763 if (genlmsg_end(msg
, hdr
) < 0) {
6768 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6769 nl80211_mlme_mcgrp
.id
, gfp
);
6773 genlmsg_cancel(msg
, hdr
);
6777 void nl80211_send_new_peer_candidate(struct cfg80211_registered_device
*rdev
,
6778 struct net_device
*netdev
,
6779 const u8
*macaddr
, const u8
* ie
, u8 ie_len
,
6782 struct sk_buff
*msg
;
6785 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6789 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
6795 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6796 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6797 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, macaddr
);
6799 NLA_PUT(msg
, NL80211_ATTR_IE
, ie_len
, ie
);
6801 if (genlmsg_end(msg
, hdr
) < 0) {
6806 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6807 nl80211_mlme_mcgrp
.id
, gfp
);
6811 genlmsg_cancel(msg
, hdr
);
6815 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
6816 struct net_device
*netdev
, const u8
*addr
,
6817 enum nl80211_key_type key_type
, int key_id
,
6818 const u8
*tsc
, gfp_t gfp
)
6820 struct sk_buff
*msg
;
6823 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6827 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
6833 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6834 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6836 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
6837 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
);
6839 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_id
);
6841 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
);
6843 if (genlmsg_end(msg
, hdr
) < 0) {
6848 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6849 nl80211_mlme_mcgrp
.id
, gfp
);
6853 genlmsg_cancel(msg
, hdr
);
6857 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
6858 struct ieee80211_channel
*channel_before
,
6859 struct ieee80211_channel
*channel_after
)
6861 struct sk_buff
*msg
;
6863 struct nlattr
*nl_freq
;
6865 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
6869 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
6876 * Since we are applying the beacon hint to a wiphy we know its
6877 * wiphy_idx is valid
6879 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
));
6882 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
6884 goto nla_put_failure
;
6885 if (nl80211_msg_put_channel(msg
, channel_before
))
6886 goto nla_put_failure
;
6887 nla_nest_end(msg
, nl_freq
);
6890 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
6892 goto nla_put_failure
;
6893 if (nl80211_msg_put_channel(msg
, channel_after
))
6894 goto nla_put_failure
;
6895 nla_nest_end(msg
, nl_freq
);
6897 if (genlmsg_end(msg
, hdr
) < 0) {
6903 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
6910 genlmsg_cancel(msg
, hdr
);
6914 static void nl80211_send_remain_on_chan_event(
6915 int cmd
, struct cfg80211_registered_device
*rdev
,
6916 struct net_device
*netdev
, u64 cookie
,
6917 struct ieee80211_channel
*chan
,
6918 enum nl80211_channel_type channel_type
,
6919 unsigned int duration
, gfp_t gfp
)
6921 struct sk_buff
*msg
;
6924 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6928 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
6934 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6935 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6936 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
);
6937 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, channel_type
);
6938 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
6940 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
)
6941 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, duration
);
6943 if (genlmsg_end(msg
, hdr
) < 0) {
6948 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6949 nl80211_mlme_mcgrp
.id
, gfp
);
6953 genlmsg_cancel(msg
, hdr
);
6957 void nl80211_send_remain_on_channel(struct cfg80211_registered_device
*rdev
,
6958 struct net_device
*netdev
, u64 cookie
,
6959 struct ieee80211_channel
*chan
,
6960 enum nl80211_channel_type channel_type
,
6961 unsigned int duration
, gfp_t gfp
)
6963 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
6964 rdev
, netdev
, cookie
, chan
,
6965 channel_type
, duration
, gfp
);
6968 void nl80211_send_remain_on_channel_cancel(
6969 struct cfg80211_registered_device
*rdev
, struct net_device
*netdev
,
6970 u64 cookie
, struct ieee80211_channel
*chan
,
6971 enum nl80211_channel_type channel_type
, gfp_t gfp
)
6973 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
6974 rdev
, netdev
, cookie
, chan
,
6975 channel_type
, 0, gfp
);
6978 void nl80211_send_sta_event(struct cfg80211_registered_device
*rdev
,
6979 struct net_device
*dev
, const u8
*mac_addr
,
6980 struct station_info
*sinfo
, gfp_t gfp
)
6982 struct sk_buff
*msg
;
6984 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6988 if (nl80211_send_station(msg
, 0, 0, 0, dev
, mac_addr
, sinfo
) < 0) {
6993 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6994 nl80211_mlme_mcgrp
.id
, gfp
);
6997 void nl80211_send_sta_del_event(struct cfg80211_registered_device
*rdev
,
6998 struct net_device
*dev
, const u8
*mac_addr
,
7001 struct sk_buff
*msg
;
7004 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7008 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_STATION
);
7014 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
7015 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
7017 if (genlmsg_end(msg
, hdr
) < 0) {
7022 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7023 nl80211_mlme_mcgrp
.id
, gfp
);
7027 genlmsg_cancel(msg
, hdr
);
7031 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
7032 struct net_device
*netdev
, u32 nlpid
,
7033 int freq
, const u8
*buf
, size_t len
, gfp_t gfp
)
7035 struct sk_buff
*msg
;
7039 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7043 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
7049 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7050 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7051 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
7052 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
7054 err
= genlmsg_end(msg
, hdr
);
7060 err
= genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
7066 genlmsg_cancel(msg
, hdr
);
7071 void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device
*rdev
,
7072 struct net_device
*netdev
, u64 cookie
,
7073 const u8
*buf
, size_t len
, bool ack
,
7076 struct sk_buff
*msg
;
7079 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
7083 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
7089 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7090 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7091 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
7092 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
7094 NLA_PUT_FLAG(msg
, NL80211_ATTR_ACK
);
7096 if (genlmsg_end(msg
, hdr
) < 0) {
7101 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
7105 genlmsg_cancel(msg
, hdr
);
7110 nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device
*rdev
,
7111 struct net_device
*netdev
,
7112 enum nl80211_cqm_rssi_threshold_event rssi_event
,
7115 struct sk_buff
*msg
;
7116 struct nlattr
*pinfoattr
;
7119 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7123 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
7129 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7130 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7132 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
7134 goto nla_put_failure
;
7136 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
7139 nla_nest_end(msg
, pinfoattr
);
7141 if (genlmsg_end(msg
, hdr
) < 0) {
7146 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7147 nl80211_mlme_mcgrp
.id
, gfp
);
7151 genlmsg_cancel(msg
, hdr
);
7155 void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
7156 struct net_device
*netdev
, const u8
*bssid
,
7157 const u8
*replay_ctr
, gfp_t gfp
)
7159 struct sk_buff
*msg
;
7160 struct nlattr
*rekey_attr
;
7163 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7167 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
7173 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7174 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7175 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
7177 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
7179 goto nla_put_failure
;
7181 NLA_PUT(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
7182 NL80211_REPLAY_CTR_LEN
, replay_ctr
);
7184 nla_nest_end(msg
, rekey_attr
);
7186 if (genlmsg_end(msg
, hdr
) < 0) {
7191 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7192 nl80211_mlme_mcgrp
.id
, gfp
);
7196 genlmsg_cancel(msg
, hdr
);
7201 nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device
*rdev
,
7202 struct net_device
*netdev
, const u8
*peer
,
7203 u32 num_packets
, gfp_t gfp
)
7205 struct sk_buff
*msg
;
7206 struct nlattr
*pinfoattr
;
7209 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7213 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
7219 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7220 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7221 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
);
7223 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
7225 goto nla_put_failure
;
7227 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
);
7229 nla_nest_end(msg
, pinfoattr
);
7231 if (genlmsg_end(msg
, hdr
) < 0) {
7236 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7237 nl80211_mlme_mcgrp
.id
, gfp
);
7241 genlmsg_cancel(msg
, hdr
);
7245 static int nl80211_netlink_notify(struct notifier_block
* nb
,
7246 unsigned long state
,
7249 struct netlink_notify
*notify
= _notify
;
7250 struct cfg80211_registered_device
*rdev
;
7251 struct wireless_dev
*wdev
;
7253 if (state
!= NETLINK_URELEASE
)
7258 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
)
7259 list_for_each_entry_rcu(wdev
, &rdev
->netdev_list
, list
)
7260 cfg80211_mlme_unregister_socket(wdev
, notify
->pid
);
7267 static struct notifier_block nl80211_netlink_notifier
= {
7268 .notifier_call
= nl80211_netlink_notify
,
7271 /* initialisation/exit functions */
7273 int nl80211_init(void)
7277 err
= genl_register_family_with_ops(&nl80211_fam
,
7278 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
7282 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
7286 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
7290 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
7294 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
7298 #ifdef CONFIG_NL80211_TESTMODE
7299 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
7304 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
7310 genl_unregister_family(&nl80211_fam
);
7314 void nl80211_exit(void)
7316 netlink_unregister_notifier(&nl80211_netlink_notifier
);
7317 genl_unregister_family(&nl80211_fam
);