2 * This is the new netlink-based wireless configuration interface.
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
8 #include <linux/module.h>
10 #include <linux/slab.h>
11 #include <linux/list.h>
12 #include <linux/if_ether.h>
13 #include <linux/ieee80211.h>
14 #include <linux/nl80211.h>
15 #include <linux/rtnetlink.h>
16 #include <linux/netlink.h>
17 #include <linux/etherdevice.h>
18 #include <net/net_namespace.h>
19 #include <net/genetlink.h>
20 #include <net/cfg80211.h>
26 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
27 struct genl_info
*info
);
28 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
29 struct genl_info
*info
);
31 /* the netlink family */
32 static struct genl_family nl80211_fam
= {
33 .id
= GENL_ID_GENERATE
, /* don't bother with a hardcoded ID */
34 .name
= "nl80211", /* have users key off the name instead */
35 .hdrsize
= 0, /* no private header */
36 .version
= 1, /* no particular meaning now */
37 .maxattr
= NL80211_ATTR_MAX
,
39 .pre_doit
= nl80211_pre_doit
,
40 .post_doit
= nl80211_post_doit
,
43 /* internal helper: get rdev and dev */
44 static int get_rdev_dev_by_info_ifindex(struct genl_info
*info
,
45 struct cfg80211_registered_device
**rdev
,
46 struct net_device
**dev
)
48 struct nlattr
**attrs
= info
->attrs
;
51 if (!attrs
[NL80211_ATTR_IFINDEX
])
54 ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
55 *dev
= dev_get_by_index(genl_info_net(info
), ifindex
);
59 *rdev
= cfg80211_get_dev_from_ifindex(genl_info_net(info
), ifindex
);
62 return PTR_ERR(*rdev
);
68 /* policy for the attributes */
69 static const struct nla_policy nl80211_policy
[NL80211_ATTR_MAX
+1] = {
70 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
71 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
73 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
74 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
75 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
76 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
77 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
78 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
79 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
80 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
82 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
83 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
84 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
86 [NL80211_ATTR_MAC
] = { .type
= NLA_BINARY
, .len
= ETH_ALEN
},
87 [NL80211_ATTR_PREV_BSSID
] = { .type
= NLA_BINARY
, .len
= ETH_ALEN
},
89 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
90 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
91 .len
= WLAN_MAX_KEY_LEN
},
92 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
93 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
94 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
95 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 8 },
96 [NL80211_ATTR_KEY_TYPE
] = { .type
= NLA_U32
},
98 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
99 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
100 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
101 .len
= IEEE80211_MAX_DATA_LEN
},
102 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
103 .len
= IEEE80211_MAX_DATA_LEN
},
104 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
105 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
106 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
107 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
108 .len
= NL80211_MAX_SUPP_RATES
},
109 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
110 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
111 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
112 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
113 .len
= IEEE80211_MAX_MESH_ID_LEN
},
114 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
116 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
117 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
119 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
120 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
121 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
122 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
123 .len
= NL80211_MAX_SUPP_RATES
},
124 [NL80211_ATTR_BSS_HT_OPMODE
] = { .type
= NLA_U16
},
126 [NL80211_ATTR_MESH_CONFIG
] = { .type
= NLA_NESTED
},
127 [NL80211_ATTR_SUPPORT_MESH_AUTH
] = { .type
= NLA_FLAG
},
129 [NL80211_ATTR_HT_CAPABILITY
] = { .type
= NLA_BINARY
,
130 .len
= NL80211_HT_CAPABILITY_LEN
},
132 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
133 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
134 .len
= IEEE80211_MAX_DATA_LEN
},
135 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
136 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
138 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
139 .len
= IEEE80211_MAX_SSID_LEN
},
140 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
141 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
142 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
143 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
144 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
145 [NL80211_ATTR_STA_FLAGS2
] = {
146 .len
= sizeof(struct nl80211_sta_flag_update
),
148 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
149 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE
] = { .type
= NLA_U16
},
150 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
] = { .type
= NLA_FLAG
},
151 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
152 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
153 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
154 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
155 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
156 [NL80211_ATTR_PMKID
] = { .type
= NLA_BINARY
,
157 .len
= WLAN_PMKID_LEN
},
158 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
159 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
160 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
161 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
162 .len
= IEEE80211_MAX_DATA_LEN
},
163 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
164 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
165 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
166 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
167 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
168 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
169 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
170 [NL80211_ATTR_FRAME_TYPE
] = { .type
= NLA_U16
},
171 [NL80211_ATTR_WIPHY_ANTENNA_TX
] = { .type
= NLA_U32
},
172 [NL80211_ATTR_WIPHY_ANTENNA_RX
] = { .type
= NLA_U32
},
173 [NL80211_ATTR_MCAST_RATE
] = { .type
= NLA_U32
},
174 [NL80211_ATTR_OFFCHANNEL_TX_OK
] = { .type
= NLA_FLAG
},
175 [NL80211_ATTR_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
176 [NL80211_ATTR_WOWLAN_TRIGGERS
] = { .type
= NLA_NESTED
},
177 [NL80211_ATTR_STA_PLINK_STATE
] = { .type
= NLA_U8
},
178 [NL80211_ATTR_SCHED_SCAN_INTERVAL
] = { .type
= NLA_U32
},
179 [NL80211_ATTR_REKEY_DATA
] = { .type
= NLA_NESTED
},
180 [NL80211_ATTR_SCAN_SUPP_RATES
] = { .type
= NLA_NESTED
},
183 /* policy for the key attributes */
184 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
185 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
186 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
187 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
188 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 8 },
189 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
190 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
191 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
192 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
195 /* policy for the key default flags */
196 static const struct nla_policy
197 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
198 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
199 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
202 /* policy for WoWLAN attributes */
203 static const struct nla_policy
204 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
205 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
206 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
207 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
208 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
209 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
] = { .type
= NLA_FLAG
},
210 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
] = { .type
= NLA_FLAG
},
211 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
] = { .type
= NLA_FLAG
},
212 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE
] = { .type
= NLA_FLAG
},
215 /* policy for GTK rekey offload attributes */
216 static const struct nla_policy
217 nl80211_rekey_policy
[NUM_NL80211_REKEY_DATA
] = {
218 [NL80211_REKEY_DATA_KEK
] = { .len
= NL80211_KEK_LEN
},
219 [NL80211_REKEY_DATA_KCK
] = { .len
= NL80211_KCK_LEN
},
220 [NL80211_REKEY_DATA_REPLAY_CTR
] = { .len
= NL80211_REPLAY_CTR_LEN
},
223 /* ifidx get helper */
224 static int nl80211_get_ifidx(struct netlink_callback
*cb
)
228 res
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
229 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
234 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
237 res
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
243 static int nl80211_prepare_netdev_dump(struct sk_buff
*skb
,
244 struct netlink_callback
*cb
,
245 struct cfg80211_registered_device
**rdev
,
246 struct net_device
**dev
)
248 int ifidx
= cb
->args
[0];
252 ifidx
= nl80211_get_ifidx(cb
);
260 *dev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
266 *rdev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
268 err
= PTR_ERR(*rdev
);
278 static void nl80211_finish_netdev_dump(struct cfg80211_registered_device
*rdev
)
280 cfg80211_unlock_rdev(rdev
);
285 static bool is_valid_ie_attr(const struct nlattr
*attr
)
293 pos
= nla_data(attr
);
314 /* message building helper */
315 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 pid
, u32 seq
,
318 /* since there is no private header just add the generic one */
319 return genlmsg_put(skb
, pid
, seq
, &nl80211_fam
, flags
, cmd
);
322 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
323 struct ieee80211_channel
*chan
)
325 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
328 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
329 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_DISABLED
);
330 if (chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
331 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
);
332 if (chan
->flags
& IEEE80211_CHAN_NO_IBSS
)
333 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
);
334 if (chan
->flags
& IEEE80211_CHAN_RADAR
)
335 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_RADAR
);
337 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
338 DBM_TO_MBM(chan
->max_power
));
346 /* netlink command implementations */
353 bool def_uni
, def_multi
;
356 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
358 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
359 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
364 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
365 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
374 if (tb
[NL80211_KEY_IDX
])
375 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
377 if (tb
[NL80211_KEY_DATA
]) {
378 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
379 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
382 if (tb
[NL80211_KEY_SEQ
]) {
383 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
384 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
387 if (tb
[NL80211_KEY_CIPHER
])
388 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
390 if (tb
[NL80211_KEY_TYPE
]) {
391 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
392 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
396 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
397 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
398 int err
= nla_parse_nested(kdt
,
399 NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
400 tb
[NL80211_KEY_DEFAULT_TYPES
],
401 nl80211_key_default_policy
);
405 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
406 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
412 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
414 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
415 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
416 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
419 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
420 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
421 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
424 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
425 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
427 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
428 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
430 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
431 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
440 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
441 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
442 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
446 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
447 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
448 int err
= nla_parse_nested(
449 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
450 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
451 nl80211_key_default_policy
);
455 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
456 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
462 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
466 memset(k
, 0, sizeof(*k
));
470 if (info
->attrs
[NL80211_ATTR_KEY
])
471 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
473 err
= nl80211_parse_key_old(info
, k
);
478 if (k
->def
&& k
->defmgmt
)
482 if (k
->def_uni
|| !k
->def_multi
)
488 if (k
->idx
< 4 || k
->idx
> 5)
491 if (k
->idx
< 0 || k
->idx
> 3)
494 if (k
->idx
< 0 || k
->idx
> 5)
502 static struct cfg80211_cached_keys
*
503 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
506 struct key_parse parse
;
508 struct cfg80211_cached_keys
*result
;
509 int rem
, err
, def
= 0;
511 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
513 return ERR_PTR(-ENOMEM
);
516 result
->defmgmt
= -1;
518 nla_for_each_nested(key
, keys
, rem
) {
519 memset(&parse
, 0, sizeof(parse
));
522 err
= nl80211_parse_key_new(key
, &parse
);
528 if (parse
.idx
< 0 || parse
.idx
> 4)
534 result
->def
= parse
.idx
;
535 if (!parse
.def_uni
|| !parse
.def_multi
)
537 } else if (parse
.defmgmt
)
539 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
540 parse
.idx
, false, NULL
);
543 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
544 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
545 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
546 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
555 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
557 ASSERT_WDEV_LOCK(wdev
);
559 switch (wdev
->iftype
) {
560 case NL80211_IFTYPE_AP
:
561 case NL80211_IFTYPE_AP_VLAN
:
562 case NL80211_IFTYPE_P2P_GO
:
563 case NL80211_IFTYPE_MESH_POINT
:
565 case NL80211_IFTYPE_ADHOC
:
566 if (!wdev
->current_bss
)
569 case NL80211_IFTYPE_STATION
:
570 case NL80211_IFTYPE_P2P_CLIENT
:
571 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
581 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
583 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
587 goto nla_put_failure
;
592 NLA_PUT_FLAG(msg
, i
);
597 nla_nest_end(msg
, nl_modes
);
604 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
607 struct nlattr
*nl_combis
;
610 nl_combis
= nla_nest_start(msg
,
611 NL80211_ATTR_INTERFACE_COMBINATIONS
);
613 goto nla_put_failure
;
615 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
616 const struct ieee80211_iface_combination
*c
;
617 struct nlattr
*nl_combi
, *nl_limits
;
619 c
= &wiphy
->iface_combinations
[i
];
621 nl_combi
= nla_nest_start(msg
, i
+ 1);
623 goto nla_put_failure
;
625 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
627 goto nla_put_failure
;
629 for (j
= 0; j
< c
->n_limits
; j
++) {
630 struct nlattr
*nl_limit
;
632 nl_limit
= nla_nest_start(msg
, j
+ 1);
634 goto nla_put_failure
;
635 NLA_PUT_U32(msg
, NL80211_IFACE_LIMIT_MAX
,
637 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
639 goto nla_put_failure
;
640 nla_nest_end(msg
, nl_limit
);
643 nla_nest_end(msg
, nl_limits
);
645 if (c
->beacon_int_infra_match
)
647 NL80211_IFACE_COMB_STA_AP_BI_MATCH
);
648 NLA_PUT_U32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
649 c
->num_different_channels
);
650 NLA_PUT_U32(msg
, NL80211_IFACE_COMB_MAXNUM
,
653 nla_nest_end(msg
, nl_combi
);
656 nla_nest_end(msg
, nl_combis
);
663 static int nl80211_send_wiphy(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
664 struct cfg80211_registered_device
*dev
)
667 struct nlattr
*nl_bands
, *nl_band
;
668 struct nlattr
*nl_freqs
, *nl_freq
;
669 struct nlattr
*nl_rates
, *nl_rate
;
670 struct nlattr
*nl_cmds
;
671 enum ieee80211_band band
;
672 struct ieee80211_channel
*chan
;
673 struct ieee80211_rate
*rate
;
675 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
676 dev
->wiphy
.mgmt_stypes
;
678 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
682 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
);
683 NLA_PUT_STRING(msg
, NL80211_ATTR_WIPHY_NAME
, wiphy_name(&dev
->wiphy
));
685 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
686 cfg80211_rdev_list_generation
);
688 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
689 dev
->wiphy
.retry_short
);
690 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
691 dev
->wiphy
.retry_long
);
692 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
693 dev
->wiphy
.frag_threshold
);
694 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
695 dev
->wiphy
.rts_threshold
);
696 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
697 dev
->wiphy
.coverage_class
);
698 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
699 dev
->wiphy
.max_scan_ssids
);
700 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS
,
701 dev
->wiphy
.max_sched_scan_ssids
);
702 NLA_PUT_U16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
703 dev
->wiphy
.max_scan_ie_len
);
704 NLA_PUT_U16(msg
, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN
,
705 dev
->wiphy
.max_sched_scan_ie_len
);
707 if (dev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
)
708 NLA_PUT_FLAG(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
);
709 if (dev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
)
710 NLA_PUT_FLAG(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
);
712 NLA_PUT(msg
, NL80211_ATTR_CIPHER_SUITES
,
713 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
714 dev
->wiphy
.cipher_suites
);
716 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
717 dev
->wiphy
.max_num_pmkids
);
719 if (dev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
)
720 NLA_PUT_FLAG(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
);
722 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
723 dev
->wiphy
.available_antennas_tx
);
724 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
725 dev
->wiphy
.available_antennas_rx
);
727 if ((dev
->wiphy
.available_antennas_tx
||
728 dev
->wiphy
.available_antennas_rx
) && dev
->ops
->get_antenna
) {
729 u32 tx_ant
= 0, rx_ant
= 0;
731 res
= dev
->ops
->get_antenna(&dev
->wiphy
, &tx_ant
, &rx_ant
);
733 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_TX
, tx_ant
);
734 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_RX
, rx_ant
);
738 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
739 dev
->wiphy
.interface_modes
))
740 goto nla_put_failure
;
742 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
744 goto nla_put_failure
;
746 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
747 if (!dev
->wiphy
.bands
[band
])
750 nl_band
= nla_nest_start(msg
, band
);
752 goto nla_put_failure
;
755 if (dev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
) {
756 NLA_PUT(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
757 sizeof(dev
->wiphy
.bands
[band
]->ht_cap
.mcs
),
758 &dev
->wiphy
.bands
[band
]->ht_cap
.mcs
);
759 NLA_PUT_U16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
760 dev
->wiphy
.bands
[band
]->ht_cap
.cap
);
761 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
762 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_factor
);
763 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
764 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_density
);
767 /* add frequencies */
768 nl_freqs
= nla_nest_start(msg
, NL80211_BAND_ATTR_FREQS
);
770 goto nla_put_failure
;
772 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_channels
; i
++) {
773 nl_freq
= nla_nest_start(msg
, i
);
775 goto nla_put_failure
;
777 chan
= &dev
->wiphy
.bands
[band
]->channels
[i
];
779 if (nl80211_msg_put_channel(msg
, chan
))
780 goto nla_put_failure
;
782 nla_nest_end(msg
, nl_freq
);
785 nla_nest_end(msg
, nl_freqs
);
788 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
790 goto nla_put_failure
;
792 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_bitrates
; i
++) {
793 nl_rate
= nla_nest_start(msg
, i
);
795 goto nla_put_failure
;
797 rate
= &dev
->wiphy
.bands
[band
]->bitrates
[i
];
798 NLA_PUT_U32(msg
, NL80211_BITRATE_ATTR_RATE
,
800 if (rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
)
802 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
);
804 nla_nest_end(msg
, nl_rate
);
807 nla_nest_end(msg
, nl_rates
);
809 nla_nest_end(msg
, nl_band
);
811 nla_nest_end(msg
, nl_bands
);
813 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
815 goto nla_put_failure
;
820 if (dev->ops->op) { \
822 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
826 CMD(add_virtual_intf
, NEW_INTERFACE
);
827 CMD(change_virtual_intf
, SET_INTERFACE
);
828 CMD(add_key
, NEW_KEY
);
829 CMD(add_beacon
, NEW_BEACON
);
830 CMD(add_station
, NEW_STATION
);
831 CMD(add_mpath
, NEW_MPATH
);
832 CMD(update_mesh_config
, SET_MESH_CONFIG
);
833 CMD(change_bss
, SET_BSS
);
834 CMD(auth
, AUTHENTICATE
);
835 CMD(assoc
, ASSOCIATE
);
836 CMD(deauth
, DEAUTHENTICATE
);
837 CMD(disassoc
, DISASSOCIATE
);
838 CMD(join_ibss
, JOIN_IBSS
);
839 CMD(join_mesh
, JOIN_MESH
);
840 CMD(set_pmksa
, SET_PMKSA
);
841 CMD(del_pmksa
, DEL_PMKSA
);
842 CMD(flush_pmksa
, FLUSH_PMKSA
);
843 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
844 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
846 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
847 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
849 NLA_PUT_U32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
);
851 CMD(set_channel
, SET_CHANNEL
);
852 CMD(set_wds_peer
, SET_WDS_PEER
);
853 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
854 CMD(sched_scan_start
, START_SCHED_SCAN
);
858 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
860 NLA_PUT_U32(msg
, i
, NL80211_CMD_CONNECT
);
863 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
865 NLA_PUT_U32(msg
, i
, NL80211_CMD_DISCONNECT
);
868 nla_nest_end(msg
, nl_cmds
);
870 if (dev
->ops
->remain_on_channel
)
871 NLA_PUT_U32(msg
, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
872 dev
->wiphy
.max_remain_on_channel_duration
);
874 /* for now at least assume all drivers have it */
875 if (dev
->ops
->mgmt_tx
)
876 NLA_PUT_FLAG(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
);
880 struct nlattr
*nl_ftypes
, *nl_ifs
;
881 enum nl80211_iftype ift
;
883 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
885 goto nla_put_failure
;
887 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
888 nl_ftypes
= nla_nest_start(msg
, ift
);
890 goto nla_put_failure
;
892 stypes
= mgmt_stypes
[ift
].tx
;
895 NLA_PUT_U16(msg
, NL80211_ATTR_FRAME_TYPE
,
896 (i
<< 4) | IEEE80211_FTYPE_MGMT
);
900 nla_nest_end(msg
, nl_ftypes
);
903 nla_nest_end(msg
, nl_ifs
);
905 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
907 goto nla_put_failure
;
909 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
910 nl_ftypes
= nla_nest_start(msg
, ift
);
912 goto nla_put_failure
;
914 stypes
= mgmt_stypes
[ift
].rx
;
917 NLA_PUT_U16(msg
, NL80211_ATTR_FRAME_TYPE
,
918 (i
<< 4) | IEEE80211_FTYPE_MGMT
);
922 nla_nest_end(msg
, nl_ftypes
);
924 nla_nest_end(msg
, nl_ifs
);
927 if (dev
->wiphy
.wowlan
.flags
|| dev
->wiphy
.wowlan
.n_patterns
) {
928 struct nlattr
*nl_wowlan
;
930 nl_wowlan
= nla_nest_start(msg
,
931 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
933 goto nla_put_failure
;
935 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_ANY
)
936 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_ANY
);
937 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_DISCONNECT
)
938 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
);
939 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_MAGIC_PKT
)
940 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
);
941 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
)
942 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
);
943 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
)
944 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
);
945 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
)
946 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
);
947 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
)
948 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
);
949 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_RFKILL_RELEASE
)
950 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
);
951 if (dev
->wiphy
.wowlan
.n_patterns
) {
952 struct nl80211_wowlan_pattern_support pat
= {
953 .max_patterns
= dev
->wiphy
.wowlan
.n_patterns
,
955 dev
->wiphy
.wowlan
.pattern_min_len
,
957 dev
->wiphy
.wowlan
.pattern_max_len
,
959 NLA_PUT(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
963 nla_nest_end(msg
, nl_wowlan
);
966 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
967 dev
->wiphy
.software_iftypes
))
968 goto nla_put_failure
;
970 if (nl80211_put_iface_combinations(&dev
->wiphy
, msg
))
971 goto nla_put_failure
;
973 return genlmsg_end(msg
, hdr
);
976 genlmsg_cancel(msg
, hdr
);
980 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
983 int start
= cb
->args
[0];
984 struct cfg80211_registered_device
*dev
;
986 mutex_lock(&cfg80211_mutex
);
987 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
988 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
992 if (nl80211_send_wiphy(skb
, NETLINK_CB(cb
->skb
).pid
,
993 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
999 mutex_unlock(&cfg80211_mutex
);
1006 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1008 struct sk_buff
*msg
;
1009 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1011 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1015 if (nl80211_send_wiphy(msg
, info
->snd_pid
, info
->snd_seq
, 0, dev
) < 0) {
1020 return genlmsg_reply(msg
, info
);
1023 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
1024 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
1025 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
1026 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
1027 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
1028 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1031 static int parse_txq_params(struct nlattr
*tb
[],
1032 struct ieee80211_txq_params
*txq_params
)
1034 if (!tb
[NL80211_TXQ_ATTR_QUEUE
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1035 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1036 !tb
[NL80211_TXQ_ATTR_AIFS
])
1039 txq_params
->queue
= nla_get_u8(tb
[NL80211_TXQ_ATTR_QUEUE
]);
1040 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1041 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1042 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1043 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1048 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1051 * You can only set the channel explicitly for AP, mesh
1052 * and WDS type interfaces; all others have their channel
1053 * managed via their respective "establish a connection"
1054 * command (connect, join, ...)
1056 * Monitors are special as they are normally slaved to
1057 * whatever else is going on, so they behave as though
1058 * you tried setting the wiphy channel itself.
1061 wdev
->iftype
== NL80211_IFTYPE_AP
||
1062 wdev
->iftype
== NL80211_IFTYPE_WDS
||
1063 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
1064 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
1065 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
1068 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
1069 struct wireless_dev
*wdev
,
1070 struct genl_info
*info
)
1072 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
1076 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
1079 if (!nl80211_can_set_dev_channel(wdev
))
1082 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
1083 channel_type
= nla_get_u32(info
->attrs
[
1084 NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1085 if (channel_type
!= NL80211_CHAN_NO_HT
&&
1086 channel_type
!= NL80211_CHAN_HT20
&&
1087 channel_type
!= NL80211_CHAN_HT40PLUS
&&
1088 channel_type
!= NL80211_CHAN_HT40MINUS
)
1092 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
1094 mutex_lock(&rdev
->devlist_mtx
);
1097 result
= cfg80211_set_freq(rdev
, wdev
, freq
, channel_type
);
1100 result
= cfg80211_set_freq(rdev
, NULL
, freq
, channel_type
);
1102 mutex_unlock(&rdev
->devlist_mtx
);
1107 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
1109 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1110 struct net_device
*netdev
= info
->user_ptr
[1];
1112 return __nl80211_set_channel(rdev
, netdev
->ieee80211_ptr
, info
);
1115 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
1117 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1118 struct net_device
*dev
= info
->user_ptr
[1];
1119 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1122 if (!info
->attrs
[NL80211_ATTR_MAC
])
1125 if (netif_running(dev
))
1128 if (!rdev
->ops
->set_wds_peer
)
1131 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
1134 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1135 return rdev
->ops
->set_wds_peer(wdev
->wiphy
, dev
, bssid
);
1139 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1141 struct cfg80211_registered_device
*rdev
;
1142 struct net_device
*netdev
= NULL
;
1143 struct wireless_dev
*wdev
;
1144 int result
= 0, rem_txq_params
= 0;
1145 struct nlattr
*nl_txq_params
;
1147 u8 retry_short
= 0, retry_long
= 0;
1148 u32 frag_threshold
= 0, rts_threshold
= 0;
1149 u8 coverage_class
= 0;
1152 * Try to find the wiphy and netdev. Normally this
1153 * function shouldn't need the netdev, but this is
1154 * done for backward compatibility -- previously
1155 * setting the channel was done per wiphy, but now
1156 * it is per netdev. Previous userland like hostapd
1157 * also passed a netdev to set_wiphy, so that it is
1158 * possible to let that go to the right netdev!
1160 mutex_lock(&cfg80211_mutex
);
1162 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
1163 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
1165 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
1166 if (netdev
&& netdev
->ieee80211_ptr
) {
1167 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
1168 mutex_lock(&rdev
->mtx
);
1174 rdev
= __cfg80211_rdev_from_info(info
);
1176 mutex_unlock(&cfg80211_mutex
);
1177 return PTR_ERR(rdev
);
1183 mutex_lock(&rdev
->mtx
);
1184 } else if (netif_running(netdev
) &&
1185 nl80211_can_set_dev_channel(netdev
->ieee80211_ptr
))
1186 wdev
= netdev
->ieee80211_ptr
;
1191 * end workaround code, by now the rdev is available
1192 * and locked, and wdev may or may not be NULL.
1195 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
1196 result
= cfg80211_dev_rename(
1197 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
1199 mutex_unlock(&cfg80211_mutex
);
1204 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
1205 struct ieee80211_txq_params txq_params
;
1206 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
1208 if (!rdev
->ops
->set_txq_params
) {
1209 result
= -EOPNOTSUPP
;
1213 nla_for_each_nested(nl_txq_params
,
1214 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
1216 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
1217 nla_data(nl_txq_params
),
1218 nla_len(nl_txq_params
),
1220 result
= parse_txq_params(tb
, &txq_params
);
1224 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
1231 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
1232 result
= __nl80211_set_channel(rdev
, wdev
, info
);
1237 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
1238 enum nl80211_tx_power_setting type
;
1241 if (!rdev
->ops
->set_tx_power
) {
1242 result
= -EOPNOTSUPP
;
1246 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
1247 type
= nla_get_u32(info
->attrs
[idx
]);
1249 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
1250 (type
!= NL80211_TX_POWER_AUTOMATIC
)) {
1255 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
1256 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
1257 mbm
= nla_get_u32(info
->attrs
[idx
]);
1260 result
= rdev
->ops
->set_tx_power(&rdev
->wiphy
, type
, mbm
);
1265 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
1266 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
1268 if ((!rdev
->wiphy
.available_antennas_tx
&&
1269 !rdev
->wiphy
.available_antennas_rx
) ||
1270 !rdev
->ops
->set_antenna
) {
1271 result
= -EOPNOTSUPP
;
1275 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
1276 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
1278 /* reject antenna configurations which don't match the
1279 * available antenna masks, except for the "all" mask */
1280 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
1281 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
))) {
1286 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
1287 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
1289 result
= rdev
->ops
->set_antenna(&rdev
->wiphy
, tx_ant
, rx_ant
);
1296 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
1297 retry_short
= nla_get_u8(
1298 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
1299 if (retry_short
== 0) {
1303 changed
|= WIPHY_PARAM_RETRY_SHORT
;
1306 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
1307 retry_long
= nla_get_u8(
1308 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
1309 if (retry_long
== 0) {
1313 changed
|= WIPHY_PARAM_RETRY_LONG
;
1316 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
1317 frag_threshold
= nla_get_u32(
1318 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
1319 if (frag_threshold
< 256) {
1323 if (frag_threshold
!= (u32
) -1) {
1325 * Fragments (apart from the last one) are required to
1326 * have even length. Make the fragmentation code
1327 * simpler by stripping LSB should someone try to use
1328 * odd threshold value.
1330 frag_threshold
&= ~0x1;
1332 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
1335 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
1336 rts_threshold
= nla_get_u32(
1337 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
1338 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
1341 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
1342 coverage_class
= nla_get_u8(
1343 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
1344 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
1348 u8 old_retry_short
, old_retry_long
;
1349 u32 old_frag_threshold
, old_rts_threshold
;
1350 u8 old_coverage_class
;
1352 if (!rdev
->ops
->set_wiphy_params
) {
1353 result
= -EOPNOTSUPP
;
1357 old_retry_short
= rdev
->wiphy
.retry_short
;
1358 old_retry_long
= rdev
->wiphy
.retry_long
;
1359 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
1360 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
1361 old_coverage_class
= rdev
->wiphy
.coverage_class
;
1363 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
1364 rdev
->wiphy
.retry_short
= retry_short
;
1365 if (changed
& WIPHY_PARAM_RETRY_LONG
)
1366 rdev
->wiphy
.retry_long
= retry_long
;
1367 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
1368 rdev
->wiphy
.frag_threshold
= frag_threshold
;
1369 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
1370 rdev
->wiphy
.rts_threshold
= rts_threshold
;
1371 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
1372 rdev
->wiphy
.coverage_class
= coverage_class
;
1374 result
= rdev
->ops
->set_wiphy_params(&rdev
->wiphy
, changed
);
1376 rdev
->wiphy
.retry_short
= old_retry_short
;
1377 rdev
->wiphy
.retry_long
= old_retry_long
;
1378 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
1379 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
1380 rdev
->wiphy
.coverage_class
= old_coverage_class
;
1385 mutex_unlock(&rdev
->mtx
);
1392 static int nl80211_send_iface(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
1393 struct cfg80211_registered_device
*rdev
,
1394 struct net_device
*dev
)
1398 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
1402 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1403 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
1404 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, dev
->name
);
1405 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, dev
->ieee80211_ptr
->iftype
);
1407 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
1408 rdev
->devlist_generation
^
1409 (cfg80211_rdev_list_generation
<< 2));
1411 return genlmsg_end(msg
, hdr
);
1414 genlmsg_cancel(msg
, hdr
);
1418 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1422 int wp_start
= cb
->args
[0];
1423 int if_start
= cb
->args
[1];
1424 struct cfg80211_registered_device
*rdev
;
1425 struct wireless_dev
*wdev
;
1427 mutex_lock(&cfg80211_mutex
);
1428 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
1429 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
1431 if (wp_idx
< wp_start
) {
1437 mutex_lock(&rdev
->devlist_mtx
);
1438 list_for_each_entry(wdev
, &rdev
->netdev_list
, list
) {
1439 if (if_idx
< if_start
) {
1443 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).pid
,
1444 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1445 rdev
, wdev
->netdev
) < 0) {
1446 mutex_unlock(&rdev
->devlist_mtx
);
1451 mutex_unlock(&rdev
->devlist_mtx
);
1456 mutex_unlock(&cfg80211_mutex
);
1458 cb
->args
[0] = wp_idx
;
1459 cb
->args
[1] = if_idx
;
1464 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1466 struct sk_buff
*msg
;
1467 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1468 struct net_device
*netdev
= info
->user_ptr
[1];
1470 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1474 if (nl80211_send_iface(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1480 return genlmsg_reply(msg
, info
);
1483 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
1484 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
1485 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
1486 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
1487 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
1488 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
1491 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
1493 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
1501 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
1502 nla
, mntr_flags_policy
))
1505 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
1507 *mntrflags
|= (1<<flag
);
1512 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
1513 struct net_device
*netdev
, u8 use_4addr
,
1514 enum nl80211_iftype iftype
)
1517 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
1523 case NL80211_IFTYPE_AP_VLAN
:
1524 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
1527 case NL80211_IFTYPE_STATION
:
1528 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
1538 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1540 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1541 struct vif_params params
;
1543 enum nl80211_iftype otype
, ntype
;
1544 struct net_device
*dev
= info
->user_ptr
[1];
1545 u32 _flags
, *flags
= NULL
;
1546 bool change
= false;
1548 memset(¶ms
, 0, sizeof(params
));
1550 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
1552 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1553 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1556 if (ntype
> NL80211_IFTYPE_MAX
)
1560 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1561 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1563 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
1565 if (netif_running(dev
))
1569 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
1570 IEEE80211_MAX_MESH_ID_LEN
);
1571 wdev
->mesh_id_up_len
=
1572 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1573 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
1574 wdev
->mesh_id_up_len
);
1578 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1579 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1581 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
1585 params
.use_4addr
= -1;
1588 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
1589 if (ntype
!= NL80211_IFTYPE_MONITOR
)
1591 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
1601 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
1605 if (!err
&& params
.use_4addr
!= -1)
1606 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
1611 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1613 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1614 struct vif_params params
;
1615 struct net_device
*dev
;
1617 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
1620 memset(¶ms
, 0, sizeof(params
));
1622 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
1625 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1626 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1627 if (type
> NL80211_IFTYPE_MAX
)
1631 if (!rdev
->ops
->add_virtual_intf
||
1632 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
1635 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1636 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1637 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
1642 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
1643 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
1645 dev
= rdev
->ops
->add_virtual_intf(&rdev
->wiphy
,
1646 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
1647 type
, err
? NULL
: &flags
, ¶ms
);
1649 return PTR_ERR(dev
);
1651 if (type
== NL80211_IFTYPE_MESH_POINT
&&
1652 info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1653 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1656 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
1657 IEEE80211_MAX_MESH_ID_LEN
);
1658 wdev
->mesh_id_up_len
=
1659 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1660 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
1661 wdev
->mesh_id_up_len
);
1668 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1670 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1671 struct net_device
*dev
= info
->user_ptr
[1];
1673 if (!rdev
->ops
->del_virtual_intf
)
1676 return rdev
->ops
->del_virtual_intf(&rdev
->wiphy
, dev
);
1679 struct get_key_cookie
{
1680 struct sk_buff
*msg
;
1685 static void get_key_callback(void *c
, struct key_params
*params
)
1688 struct get_key_cookie
*cookie
= c
;
1691 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
1692 params
->key_len
, params
->key
);
1695 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
1696 params
->seq_len
, params
->seq
);
1699 NLA_PUT_U32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
1702 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
1704 goto nla_put_failure
;
1707 NLA_PUT(cookie
->msg
, NL80211_KEY_DATA
,
1708 params
->key_len
, params
->key
);
1711 NLA_PUT(cookie
->msg
, NL80211_KEY_SEQ
,
1712 params
->seq_len
, params
->seq
);
1715 NLA_PUT_U32(cookie
->msg
, NL80211_KEY_CIPHER
,
1718 NLA_PUT_U8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
);
1720 nla_nest_end(cookie
->msg
, key
);
1727 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
1729 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1731 struct net_device
*dev
= info
->user_ptr
[1];
1733 const u8
*mac_addr
= NULL
;
1735 struct get_key_cookie cookie
= {
1739 struct sk_buff
*msg
;
1741 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
1742 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1747 if (info
->attrs
[NL80211_ATTR_MAC
])
1748 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1750 pairwise
= !!mac_addr
;
1751 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
1752 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
1753 if (kt
>= NUM_NL80211_KEYTYPES
)
1755 if (kt
!= NL80211_KEYTYPE_GROUP
&&
1756 kt
!= NL80211_KEYTYPE_PAIRWISE
)
1758 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
1761 if (!rdev
->ops
->get_key
)
1764 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1768 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1769 NL80211_CMD_NEW_KEY
);
1771 return PTR_ERR(hdr
);
1774 cookie
.idx
= key_idx
;
1776 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1777 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
1779 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1781 if (pairwise
&& mac_addr
&&
1782 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
1785 err
= rdev
->ops
->get_key(&rdev
->wiphy
, dev
, key_idx
, pairwise
,
1786 mac_addr
, &cookie
, get_key_callback
);
1792 goto nla_put_failure
;
1794 genlmsg_end(msg
, hdr
);
1795 return genlmsg_reply(msg
, info
);
1804 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
1806 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1807 struct key_parse key
;
1809 struct net_device
*dev
= info
->user_ptr
[1];
1811 err
= nl80211_parse_key(info
, &key
);
1818 /* only support setting default key */
1819 if (!key
.def
&& !key
.defmgmt
)
1822 wdev_lock(dev
->ieee80211_ptr
);
1825 if (!rdev
->ops
->set_default_key
) {
1830 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1834 err
= rdev
->ops
->set_default_key(&rdev
->wiphy
, dev
, key
.idx
,
1835 key
.def_uni
, key
.def_multi
);
1840 #ifdef CONFIG_CFG80211_WEXT
1841 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
1844 if (key
.def_uni
|| !key
.def_multi
) {
1849 if (!rdev
->ops
->set_default_mgmt_key
) {
1854 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1858 err
= rdev
->ops
->set_default_mgmt_key(&rdev
->wiphy
,
1863 #ifdef CONFIG_CFG80211_WEXT
1864 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
1869 wdev_unlock(dev
->ieee80211_ptr
);
1874 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
1876 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1878 struct net_device
*dev
= info
->user_ptr
[1];
1879 struct key_parse key
;
1880 const u8
*mac_addr
= NULL
;
1882 err
= nl80211_parse_key(info
, &key
);
1889 if (info
->attrs
[NL80211_ATTR_MAC
])
1890 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1892 if (key
.type
== -1) {
1894 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
1896 key
.type
= NL80211_KEYTYPE_GROUP
;
1900 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
1901 key
.type
!= NL80211_KEYTYPE_GROUP
)
1904 if (!rdev
->ops
->add_key
)
1907 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
1908 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
1912 wdev_lock(dev
->ieee80211_ptr
);
1913 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1915 err
= rdev
->ops
->add_key(&rdev
->wiphy
, dev
, key
.idx
,
1916 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
1918 wdev_unlock(dev
->ieee80211_ptr
);
1923 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
1925 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1927 struct net_device
*dev
= info
->user_ptr
[1];
1928 u8
*mac_addr
= NULL
;
1929 struct key_parse key
;
1931 err
= nl80211_parse_key(info
, &key
);
1935 if (info
->attrs
[NL80211_ATTR_MAC
])
1936 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1938 if (key
.type
== -1) {
1940 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
1942 key
.type
= NL80211_KEYTYPE_GROUP
;
1946 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
1947 key
.type
!= NL80211_KEYTYPE_GROUP
)
1950 if (!rdev
->ops
->del_key
)
1953 wdev_lock(dev
->ieee80211_ptr
);
1954 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1956 if (key
.type
== NL80211_KEYTYPE_PAIRWISE
&& mac_addr
&&
1957 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
1961 err
= rdev
->ops
->del_key(&rdev
->wiphy
, dev
, key
.idx
,
1962 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
1965 #ifdef CONFIG_CFG80211_WEXT
1967 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
1968 dev
->ieee80211_ptr
->wext
.default_key
= -1;
1969 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
1970 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
1973 wdev_unlock(dev
->ieee80211_ptr
);
1978 static int nl80211_addset_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1980 int (*call
)(struct wiphy
*wiphy
, struct net_device
*dev
,
1981 struct beacon_parameters
*info
);
1982 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1983 struct net_device
*dev
= info
->user_ptr
[1];
1984 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1985 struct beacon_parameters params
;
1986 int haveinfo
= 0, err
;
1988 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]))
1991 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1992 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
1995 memset(¶ms
, 0, sizeof(params
));
1997 switch (info
->genlhdr
->cmd
) {
1998 case NL80211_CMD_NEW_BEACON
:
1999 /* these are required for NEW_BEACON */
2000 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
2001 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
2002 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
2006 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
2007 params
.dtim_period
=
2008 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
2010 err
= cfg80211_validate_beacon_int(rdev
, params
.interval
);
2014 call
= rdev
->ops
->add_beacon
;
2016 case NL80211_CMD_SET_BEACON
:
2017 call
= rdev
->ops
->set_beacon
;
2027 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
2028 params
.head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2030 nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2034 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
2035 params
.tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2037 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2044 err
= call(&rdev
->wiphy
, dev
, ¶ms
);
2045 if (!err
&& params
.interval
)
2046 wdev
->beacon_interval
= params
.interval
;
2050 static int nl80211_del_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
2052 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2053 struct net_device
*dev
= info
->user_ptr
[1];
2054 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2057 if (!rdev
->ops
->del_beacon
)
2060 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2061 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2064 err
= rdev
->ops
->del_beacon(&rdev
->wiphy
, dev
);
2066 wdev
->beacon_interval
= 0;
2070 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
2071 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
2072 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
2073 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
2074 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
2075 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
2078 static int parse_station_flags(struct genl_info
*info
,
2079 struct station_parameters
*params
)
2081 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
2086 * Try parsing the new attribute first so userspace
2087 * can specify both for older kernels.
2089 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
2091 struct nl80211_sta_flag_update
*sta_flags
;
2093 sta_flags
= nla_data(nla
);
2094 params
->sta_flags_mask
= sta_flags
->mask
;
2095 params
->sta_flags_set
= sta_flags
->set
;
2096 if ((params
->sta_flags_mask
|
2097 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
2102 /* if present, parse the old attribute */
2104 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
2108 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
2109 nla
, sta_flags_policy
))
2112 params
->sta_flags_mask
= (1 << __NL80211_STA_FLAG_AFTER_LAST
) - 1;
2113 params
->sta_flags_mask
&= ~1;
2115 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++)
2117 params
->sta_flags_set
|= (1<<flag
);
2122 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
2125 struct nlattr
*rate
;
2128 rate
= nla_nest_start(msg
, attr
);
2130 goto nla_put_failure
;
2132 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2133 bitrate
= cfg80211_calculate_bitrate(info
);
2135 NLA_PUT_U16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate
);
2137 if (info
->flags
& RATE_INFO_FLAGS_MCS
)
2138 NLA_PUT_U8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
);
2139 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
)
2140 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
);
2141 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
)
2142 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_SHORT_GI
);
2144 nla_nest_end(msg
, rate
);
2151 static int nl80211_send_station(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2152 int flags
, struct net_device
*dev
,
2153 const u8
*mac_addr
, struct station_info
*sinfo
)
2156 struct nlattr
*sinfoattr
, *bss_param
;
2158 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2162 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2163 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
2165 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
);
2167 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
2169 goto nla_put_failure
;
2170 if (sinfo
->filled
& STATION_INFO_CONNECTED_TIME
)
2171 NLA_PUT_U32(msg
, NL80211_STA_INFO_CONNECTED_TIME
,
2172 sinfo
->connected_time
);
2173 if (sinfo
->filled
& STATION_INFO_INACTIVE_TIME
)
2174 NLA_PUT_U32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
2175 sinfo
->inactive_time
);
2176 if (sinfo
->filled
& STATION_INFO_RX_BYTES
)
2177 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_BYTES
,
2179 if (sinfo
->filled
& STATION_INFO_TX_BYTES
)
2180 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_BYTES
,
2182 if (sinfo
->filled
& STATION_INFO_LLID
)
2183 NLA_PUT_U16(msg
, NL80211_STA_INFO_LLID
,
2185 if (sinfo
->filled
& STATION_INFO_PLID
)
2186 NLA_PUT_U16(msg
, NL80211_STA_INFO_PLID
,
2188 if (sinfo
->filled
& STATION_INFO_PLINK_STATE
)
2189 NLA_PUT_U8(msg
, NL80211_STA_INFO_PLINK_STATE
,
2190 sinfo
->plink_state
);
2191 if (sinfo
->filled
& STATION_INFO_SIGNAL
)
2192 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL
,
2194 if (sinfo
->filled
& STATION_INFO_SIGNAL_AVG
)
2195 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
2197 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
2198 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
2199 NL80211_STA_INFO_TX_BITRATE
))
2200 goto nla_put_failure
;
2202 if (sinfo
->filled
& STATION_INFO_RX_BITRATE
) {
2203 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
2204 NL80211_STA_INFO_RX_BITRATE
))
2205 goto nla_put_failure
;
2207 if (sinfo
->filled
& STATION_INFO_RX_PACKETS
)
2208 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_PACKETS
,
2210 if (sinfo
->filled
& STATION_INFO_TX_PACKETS
)
2211 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_PACKETS
,
2213 if (sinfo
->filled
& STATION_INFO_TX_RETRIES
)
2214 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_RETRIES
,
2216 if (sinfo
->filled
& STATION_INFO_TX_FAILED
)
2217 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_FAILED
,
2219 if (sinfo
->filled
& STATION_INFO_BSS_PARAM
) {
2220 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
2222 goto nla_put_failure
;
2224 if (sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
)
2225 NLA_PUT_FLAG(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
);
2226 if (sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
)
2227 NLA_PUT_FLAG(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
);
2228 if (sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
)
2230 NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
);
2231 NLA_PUT_U8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
2232 sinfo
->bss_param
.dtim_period
);
2233 NLA_PUT_U16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
2234 sinfo
->bss_param
.beacon_interval
);
2236 nla_nest_end(msg
, bss_param
);
2238 nla_nest_end(msg
, sinfoattr
);
2240 return genlmsg_end(msg
, hdr
);
2243 genlmsg_cancel(msg
, hdr
);
2247 static int nl80211_dump_station(struct sk_buff
*skb
,
2248 struct netlink_callback
*cb
)
2250 struct station_info sinfo
;
2251 struct cfg80211_registered_device
*dev
;
2252 struct net_device
*netdev
;
2253 u8 mac_addr
[ETH_ALEN
];
2254 int sta_idx
= cb
->args
[1];
2257 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
2261 if (!dev
->ops
->dump_station
) {
2267 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
2274 if (nl80211_send_station(skb
,
2275 NETLINK_CB(cb
->skb
).pid
,
2276 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2286 cb
->args
[1] = sta_idx
;
2289 nl80211_finish_netdev_dump(dev
);
2294 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
2296 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2297 struct net_device
*dev
= info
->user_ptr
[1];
2298 struct station_info sinfo
;
2299 struct sk_buff
*msg
;
2300 u8
*mac_addr
= NULL
;
2303 memset(&sinfo
, 0, sizeof(sinfo
));
2305 if (!info
->attrs
[NL80211_ATTR_MAC
])
2308 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2310 if (!rdev
->ops
->get_station
)
2313 err
= rdev
->ops
->get_station(&rdev
->wiphy
, dev
, mac_addr
, &sinfo
);
2317 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2321 if (nl80211_send_station(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2322 dev
, mac_addr
, &sinfo
) < 0) {
2327 return genlmsg_reply(msg
, info
);
2331 * Get vlan interface making sure it is running and on the right wiphy.
2333 static int get_vlan(struct genl_info
*info
,
2334 struct cfg80211_registered_device
*rdev
,
2335 struct net_device
**vlan
)
2337 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
2341 *vlan
= dev_get_by_index(genl_info_net(info
),
2342 nla_get_u32(vlanattr
));
2345 if (!(*vlan
)->ieee80211_ptr
)
2347 if ((*vlan
)->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
)
2349 if (!netif_running(*vlan
))
2355 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
2357 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2359 struct net_device
*dev
= info
->user_ptr
[1];
2360 struct station_parameters params
;
2361 u8
*mac_addr
= NULL
;
2363 memset(¶ms
, 0, sizeof(params
));
2365 params
.listen_interval
= -1;
2366 params
.plink_state
= -1;
2368 if (info
->attrs
[NL80211_ATTR_STA_AID
])
2371 if (!info
->attrs
[NL80211_ATTR_MAC
])
2374 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2376 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
2377 params
.supported_rates
=
2378 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2379 params
.supported_rates_len
=
2380 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2383 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2384 params
.listen_interval
=
2385 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2387 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2389 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2391 if (parse_station_flags(info
, ¶ms
))
2394 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
2395 params
.plink_action
=
2396 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
2398 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
])
2399 params
.plink_state
=
2400 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
2402 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
2406 /* validate settings */
2409 switch (dev
->ieee80211_ptr
->iftype
) {
2410 case NL80211_IFTYPE_AP
:
2411 case NL80211_IFTYPE_AP_VLAN
:
2412 case NL80211_IFTYPE_P2P_GO
:
2413 /* disallow mesh-specific things */
2414 if (params
.plink_action
)
2417 case NL80211_IFTYPE_P2P_CLIENT
:
2418 case NL80211_IFTYPE_STATION
:
2419 /* disallow everything but AUTHORIZED flag */
2420 if (params
.plink_action
)
2424 if (params
.supported_rates
)
2428 if (params
.listen_interval
>= 0)
2430 if (params
.sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
2433 case NL80211_IFTYPE_MESH_POINT
:
2434 /* disallow things mesh doesn't support */
2439 if (params
.listen_interval
>= 0)
2441 if (params
.sta_flags_mask
&
2442 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
2443 BIT(NL80211_STA_FLAG_MFP
) |
2444 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
2454 if (!rdev
->ops
->change_station
) {
2459 err
= rdev
->ops
->change_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2463 dev_put(params
.vlan
);
2468 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
2470 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2472 struct net_device
*dev
= info
->user_ptr
[1];
2473 struct station_parameters params
;
2474 u8
*mac_addr
= NULL
;
2476 memset(¶ms
, 0, sizeof(params
));
2478 if (!info
->attrs
[NL80211_ATTR_MAC
])
2481 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2484 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
2487 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
2490 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2491 params
.supported_rates
=
2492 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2493 params
.supported_rates_len
=
2494 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2495 params
.listen_interval
=
2496 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2498 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
2499 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
2502 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2504 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2506 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
2507 params
.plink_action
=
2508 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
2510 if (parse_station_flags(info
, ¶ms
))
2513 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2514 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
2515 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
2516 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2519 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
2523 /* validate settings */
2526 if (!rdev
->ops
->add_station
) {
2531 err
= rdev
->ops
->add_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2535 dev_put(params
.vlan
);
2539 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
2541 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2542 struct net_device
*dev
= info
->user_ptr
[1];
2543 u8
*mac_addr
= NULL
;
2545 if (info
->attrs
[NL80211_ATTR_MAC
])
2546 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2548 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2549 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
2550 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
2551 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2554 if (!rdev
->ops
->del_station
)
2557 return rdev
->ops
->del_station(&rdev
->wiphy
, dev
, mac_addr
);
2560 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2561 int flags
, struct net_device
*dev
,
2562 u8
*dst
, u8
*next_hop
,
2563 struct mpath_info
*pinfo
)
2566 struct nlattr
*pinfoattr
;
2568 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2572 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2573 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
2574 NLA_PUT(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
);
2576 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
);
2578 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
2580 goto nla_put_failure
;
2581 if (pinfo
->filled
& MPATH_INFO_FRAME_QLEN
)
2582 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
2584 if (pinfo
->filled
& MPATH_INFO_SN
)
2585 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_SN
,
2587 if (pinfo
->filled
& MPATH_INFO_METRIC
)
2588 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_METRIC
,
2590 if (pinfo
->filled
& MPATH_INFO_EXPTIME
)
2591 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_EXPTIME
,
2593 if (pinfo
->filled
& MPATH_INFO_FLAGS
)
2594 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_FLAGS
,
2596 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
)
2597 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
2598 pinfo
->discovery_timeout
);
2599 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
)
2600 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
2601 pinfo
->discovery_retries
);
2603 nla_nest_end(msg
, pinfoattr
);
2605 return genlmsg_end(msg
, hdr
);
2608 genlmsg_cancel(msg
, hdr
);
2612 static int nl80211_dump_mpath(struct sk_buff
*skb
,
2613 struct netlink_callback
*cb
)
2615 struct mpath_info pinfo
;
2616 struct cfg80211_registered_device
*dev
;
2617 struct net_device
*netdev
;
2619 u8 next_hop
[ETH_ALEN
];
2620 int path_idx
= cb
->args
[1];
2623 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
2627 if (!dev
->ops
->dump_mpath
) {
2632 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2638 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
2639 dst
, next_hop
, &pinfo
);
2645 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).pid
,
2646 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2647 netdev
, dst
, next_hop
,
2656 cb
->args
[1] = path_idx
;
2659 nl80211_finish_netdev_dump(dev
);
2663 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2665 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2667 struct net_device
*dev
= info
->user_ptr
[1];
2668 struct mpath_info pinfo
;
2669 struct sk_buff
*msg
;
2671 u8 next_hop
[ETH_ALEN
];
2673 memset(&pinfo
, 0, sizeof(pinfo
));
2675 if (!info
->attrs
[NL80211_ATTR_MAC
])
2678 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2680 if (!rdev
->ops
->get_mpath
)
2683 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2686 err
= rdev
->ops
->get_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
2690 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2694 if (nl80211_send_mpath(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2695 dev
, dst
, next_hop
, &pinfo
) < 0) {
2700 return genlmsg_reply(msg
, info
);
2703 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2705 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2706 struct net_device
*dev
= info
->user_ptr
[1];
2708 u8
*next_hop
= NULL
;
2710 if (!info
->attrs
[NL80211_ATTR_MAC
])
2713 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2716 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2717 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2719 if (!rdev
->ops
->change_mpath
)
2722 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2725 return rdev
->ops
->change_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2728 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2730 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2731 struct net_device
*dev
= info
->user_ptr
[1];
2733 u8
*next_hop
= NULL
;
2735 if (!info
->attrs
[NL80211_ATTR_MAC
])
2738 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2741 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2742 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2744 if (!rdev
->ops
->add_mpath
)
2747 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2750 return rdev
->ops
->add_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2753 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2755 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2756 struct net_device
*dev
= info
->user_ptr
[1];
2759 if (info
->attrs
[NL80211_ATTR_MAC
])
2760 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2762 if (!rdev
->ops
->del_mpath
)
2765 return rdev
->ops
->del_mpath(&rdev
->wiphy
, dev
, dst
);
2768 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
2770 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2771 struct net_device
*dev
= info
->user_ptr
[1];
2772 struct bss_parameters params
;
2774 memset(¶ms
, 0, sizeof(params
));
2775 /* default to not changing parameters */
2776 params
.use_cts_prot
= -1;
2777 params
.use_short_preamble
= -1;
2778 params
.use_short_slot_time
= -1;
2779 params
.ap_isolate
= -1;
2780 params
.ht_opmode
= -1;
2782 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
2783 params
.use_cts_prot
=
2784 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
2785 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
2786 params
.use_short_preamble
=
2787 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
2788 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
2789 params
.use_short_slot_time
=
2790 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
2791 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
2792 params
.basic_rates
=
2793 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2794 params
.basic_rates_len
=
2795 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2797 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
2798 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
2799 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
2801 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
2803 if (!rdev
->ops
->change_bss
)
2806 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2807 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2810 return rdev
->ops
->change_bss(&rdev
->wiphy
, dev
, ¶ms
);
2813 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
2814 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
2815 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
2816 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
2817 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
2818 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
2819 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
2822 static int parse_reg_rule(struct nlattr
*tb
[],
2823 struct ieee80211_reg_rule
*reg_rule
)
2825 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
2826 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
2828 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
2830 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
2832 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
2834 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
2836 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
2839 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
2841 freq_range
->start_freq_khz
=
2842 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
2843 freq_range
->end_freq_khz
=
2844 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
2845 freq_range
->max_bandwidth_khz
=
2846 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
2848 power_rule
->max_eirp
=
2849 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
2851 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
2852 power_rule
->max_antenna_gain
=
2853 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
2858 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2864 * You should only get this when cfg80211 hasn't yet initialized
2865 * completely when built-in to the kernel right between the time
2866 * window between nl80211_init() and regulatory_init(), if that is
2869 mutex_lock(&cfg80211_mutex
);
2870 if (unlikely(!cfg80211_regdomain
)) {
2871 mutex_unlock(&cfg80211_mutex
);
2872 return -EINPROGRESS
;
2874 mutex_unlock(&cfg80211_mutex
);
2876 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2879 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2881 r
= regulatory_hint_user(data
);
2886 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
2887 struct genl_info
*info
)
2889 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2890 struct net_device
*dev
= info
->user_ptr
[1];
2891 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2892 struct mesh_config cur_params
;
2895 struct nlattr
*pinfoattr
;
2896 struct sk_buff
*msg
;
2898 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2901 if (!rdev
->ops
->get_mesh_config
)
2905 /* If not connected, get default parameters */
2906 if (!wdev
->mesh_id_len
)
2907 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
2909 err
= rdev
->ops
->get_mesh_config(&rdev
->wiphy
, dev
,
2916 /* Draw up a netlink message to send back */
2917 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2920 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2921 NL80211_CMD_GET_MESH_CONFIG
);
2924 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
2926 goto nla_put_failure
;
2927 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2928 NLA_PUT_U16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
2929 cur_params
.dot11MeshRetryTimeout
);
2930 NLA_PUT_U16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
2931 cur_params
.dot11MeshConfirmTimeout
);
2932 NLA_PUT_U16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
2933 cur_params
.dot11MeshHoldingTimeout
);
2934 NLA_PUT_U16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
2935 cur_params
.dot11MeshMaxPeerLinks
);
2936 NLA_PUT_U8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
2937 cur_params
.dot11MeshMaxRetries
);
2938 NLA_PUT_U8(msg
, NL80211_MESHCONF_TTL
,
2939 cur_params
.dot11MeshTTL
);
2940 NLA_PUT_U8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
2941 cur_params
.element_ttl
);
2942 NLA_PUT_U8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
2943 cur_params
.auto_open_plinks
);
2944 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2945 cur_params
.dot11MeshHWMPmaxPREQretries
);
2946 NLA_PUT_U32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
2947 cur_params
.path_refresh_time
);
2948 NLA_PUT_U16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2949 cur_params
.min_discovery_timeout
);
2950 NLA_PUT_U32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2951 cur_params
.dot11MeshHWMPactivePathTimeout
);
2952 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2953 cur_params
.dot11MeshHWMPpreqMinInterval
);
2954 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2955 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
);
2956 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
2957 cur_params
.dot11MeshHWMPRootMode
);
2958 nla_nest_end(msg
, pinfoattr
);
2959 genlmsg_end(msg
, hdr
);
2960 return genlmsg_reply(msg
, info
);
2963 genlmsg_cancel(msg
, hdr
);
2969 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
2970 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
2971 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
2972 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
2973 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
2974 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
2975 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
2976 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
2977 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
2979 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
2980 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
2981 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
2982 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
2983 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
2984 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
2987 static const struct nla_policy
2988 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
2989 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
2990 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
2991 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
2992 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
2993 .len
= IEEE80211_MAX_DATA_LEN
},
2994 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
2997 static int nl80211_parse_mesh_config(struct genl_info
*info
,
2998 struct mesh_config
*cfg
,
3001 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
3004 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
3006 if (table[attr_num]) {\
3007 cfg->param = nla_fn(table[attr_num]); \
3008 mask |= (1 << (attr_num - 1)); \
3013 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
3015 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
3016 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
3017 nl80211_meshconf_params_policy
))
3020 /* This makes sure that there aren't more than 32 mesh config
3021 * parameters (otherwise our bitfield scheme would not work.) */
3022 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
3024 /* Fill in the params struct */
3025 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
3026 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
, nla_get_u16
);
3027 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
3028 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
, nla_get_u16
);
3029 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
3030 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
, nla_get_u16
);
3031 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
3032 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
, nla_get_u16
);
3033 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
3034 mask
, NL80211_MESHCONF_MAX_RETRIES
, nla_get_u8
);
3035 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
3036 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
3037 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
,
3038 mask
, NL80211_MESHCONF_ELEMENT_TTL
, nla_get_u8
);
3039 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
3040 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
, nla_get_u8
);
3041 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
3042 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
3044 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
3045 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
, nla_get_u32
);
3046 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
3047 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
3049 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
3050 mask
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
3052 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
3053 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
3055 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3056 dot11MeshHWMPnetDiameterTraversalTime
,
3057 mask
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
3059 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3060 dot11MeshHWMPRootMode
, mask
,
3061 NL80211_MESHCONF_HWMP_ROOTMODE
,
3068 #undef FILL_IN_MESH_PARAM_IF_SET
3071 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
3072 struct mesh_setup
*setup
)
3074 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
3076 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
3078 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
3079 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
3080 nl80211_mesh_setup_params_policy
))
3083 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
3084 setup
->path_sel_proto
=
3085 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
3086 IEEE80211_PATH_PROTOCOL_VENDOR
:
3087 IEEE80211_PATH_PROTOCOL_HWMP
;
3089 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
3090 setup
->path_metric
=
3091 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
3092 IEEE80211_PATH_METRIC_VENDOR
:
3093 IEEE80211_PATH_METRIC_AIRTIME
;
3096 if (tb
[NL80211_MESH_SETUP_IE
]) {
3097 struct nlattr
*ieattr
=
3098 tb
[NL80211_MESH_SETUP_IE
];
3099 if (!is_valid_ie_attr(ieattr
))
3101 setup
->ie
= nla_data(ieattr
);
3102 setup
->ie_len
= nla_len(ieattr
);
3104 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
3105 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
3110 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
3111 struct genl_info
*info
)
3113 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3114 struct net_device
*dev
= info
->user_ptr
[1];
3115 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3116 struct mesh_config cfg
;
3120 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3123 if (!rdev
->ops
->update_mesh_config
)
3126 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
3131 if (!wdev
->mesh_id_len
)
3135 err
= rdev
->ops
->update_mesh_config(&rdev
->wiphy
, dev
,
3143 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3145 struct sk_buff
*msg
;
3147 struct nlattr
*nl_reg_rules
;
3151 mutex_lock(&cfg80211_mutex
);
3153 if (!cfg80211_regdomain
)
3156 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3162 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
3163 NL80211_CMD_GET_REG
);
3167 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
,
3168 cfg80211_regdomain
->alpha2
);
3170 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
3172 goto nla_put_failure
;
3174 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
3175 struct nlattr
*nl_reg_rule
;
3176 const struct ieee80211_reg_rule
*reg_rule
;
3177 const struct ieee80211_freq_range
*freq_range
;
3178 const struct ieee80211_power_rule
*power_rule
;
3180 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
3181 freq_range
= ®_rule
->freq_range
;
3182 power_rule
= ®_rule
->power_rule
;
3184 nl_reg_rule
= nla_nest_start(msg
, i
);
3186 goto nla_put_failure
;
3188 NLA_PUT_U32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
3190 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
3191 freq_range
->start_freq_khz
);
3192 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
3193 freq_range
->end_freq_khz
);
3194 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
3195 freq_range
->max_bandwidth_khz
);
3196 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
3197 power_rule
->max_antenna_gain
);
3198 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
3199 power_rule
->max_eirp
);
3201 nla_nest_end(msg
, nl_reg_rule
);
3204 nla_nest_end(msg
, nl_reg_rules
);
3206 genlmsg_end(msg
, hdr
);
3207 err
= genlmsg_reply(msg
, info
);
3211 genlmsg_cancel(msg
, hdr
);
3216 mutex_unlock(&cfg80211_mutex
);
3220 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3222 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
3223 struct nlattr
*nl_reg_rule
;
3224 char *alpha2
= NULL
;
3225 int rem_reg_rules
= 0, r
= 0;
3226 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
3227 struct ieee80211_regdomain
*rd
= NULL
;
3229 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
3232 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
3235 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
3237 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
3240 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
3244 mutex_lock(&cfg80211_mutex
);
3246 if (!reg_is_valid_request(alpha2
)) {
3251 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
3252 (num_rules
* sizeof(struct ieee80211_reg_rule
));
3254 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
3260 rd
->n_reg_rules
= num_rules
;
3261 rd
->alpha2
[0] = alpha2
[0];
3262 rd
->alpha2
[1] = alpha2
[1];
3264 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
3266 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
3267 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
3269 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
3275 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
3281 BUG_ON(rule_idx
!= num_rules
);
3285 mutex_unlock(&cfg80211_mutex
);
3290 mutex_unlock(&cfg80211_mutex
);
3295 static int validate_scan_freqs(struct nlattr
*freqs
)
3297 struct nlattr
*attr1
, *attr2
;
3298 int n_channels
= 0, tmp1
, tmp2
;
3300 nla_for_each_nested(attr1
, freqs
, tmp1
) {
3303 * Some hardware has a limited channel list for
3304 * scanning, and it is pretty much nonsensical
3305 * to scan for a channel twice, so disallow that
3306 * and don't require drivers to check that the
3307 * channel list they get isn't longer than what
3308 * they can scan, as long as they can scan all
3309 * the channels they registered at once.
3311 nla_for_each_nested(attr2
, freqs
, tmp2
)
3312 if (attr1
!= attr2
&&
3313 nla_get_u32(attr1
) == nla_get_u32(attr2
))
3320 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
3322 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3323 struct net_device
*dev
= info
->user_ptr
[1];
3324 struct cfg80211_scan_request
*request
;
3325 struct nlattr
*attr
;
3326 struct wiphy
*wiphy
;
3327 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
3330 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3333 wiphy
= &rdev
->wiphy
;
3335 if (!rdev
->ops
->scan
)
3341 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3342 n_channels
= validate_scan_freqs(
3343 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
3347 enum ieee80211_band band
;
3350 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
3351 if (wiphy
->bands
[band
])
3352 n_channels
+= wiphy
->bands
[band
]->n_channels
;
3355 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
3356 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
3359 if (n_ssids
> wiphy
->max_scan_ssids
)
3362 if (info
->attrs
[NL80211_ATTR_IE
])
3363 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3367 if (ie_len
> wiphy
->max_scan_ie_len
)
3370 request
= kzalloc(sizeof(*request
)
3371 + sizeof(*request
->ssids
) * n_ssids
3372 + sizeof(*request
->channels
) * n_channels
3373 + ie_len
, GFP_KERNEL
);
3378 request
->ssids
= (void *)&request
->channels
[n_channels
];
3379 request
->n_ssids
= n_ssids
;
3382 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
3384 request
->ie
= (void *)(request
->channels
+ n_channels
);
3388 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3389 /* user specified, bail out if channel not found */
3390 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
3391 struct ieee80211_channel
*chan
;
3393 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
3400 /* ignore disabled channels */
3401 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3404 request
->channels
[i
] = chan
;
3408 enum ieee80211_band band
;
3411 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
3413 if (!wiphy
->bands
[band
])
3415 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
3416 struct ieee80211_channel
*chan
;
3418 chan
= &wiphy
->bands
[band
]->channels
[j
];
3420 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3423 request
->channels
[i
] = chan
;
3434 request
->n_channels
= i
;
3437 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
3438 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
3439 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
3443 request
->ssids
[i
].ssid_len
= nla_len(attr
);
3444 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
3449 if (info
->attrs
[NL80211_ATTR_IE
]) {
3450 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3451 memcpy((void *)request
->ie
,
3452 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
3456 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
3457 if (wiphy
->bands
[i
])
3459 (1 << wiphy
->bands
[i
]->n_bitrates
) - 1;
3461 if (info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
]) {
3462 nla_for_each_nested(attr
,
3463 info
->attrs
[NL80211_ATTR_SCAN_SUPP_RATES
],
3465 enum ieee80211_band band
= nla_type(attr
);
3467 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
) {
3471 err
= ieee80211_get_ratemask(wiphy
->bands
[band
],
3474 &request
->rates
[band
]);
3481 request
->wiphy
= &rdev
->wiphy
;
3483 rdev
->scan_req
= request
;
3484 err
= rdev
->ops
->scan(&rdev
->wiphy
, dev
, request
);
3487 nl80211_send_scan_start(rdev
, dev
);
3491 rdev
->scan_req
= NULL
;
3498 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
3499 struct genl_info
*info
)
3501 struct cfg80211_sched_scan_request
*request
;
3502 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3503 struct net_device
*dev
= info
->user_ptr
[1];
3504 struct nlattr
*attr
;
3505 struct wiphy
*wiphy
;
3506 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
3508 enum ieee80211_band band
;
3511 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
3512 !rdev
->ops
->sched_scan_start
)
3515 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3518 if (!info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
3521 interval
= nla_get_u32(info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
3525 wiphy
= &rdev
->wiphy
;
3527 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3528 n_channels
= validate_scan_freqs(
3529 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
3535 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
3536 if (wiphy
->bands
[band
])
3537 n_channels
+= wiphy
->bands
[band
]->n_channels
;
3540 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
3541 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
3545 if (n_ssids
> wiphy
->max_sched_scan_ssids
)
3548 if (info
->attrs
[NL80211_ATTR_IE
])
3549 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3553 if (ie_len
> wiphy
->max_sched_scan_ie_len
)
3556 mutex_lock(&rdev
->sched_scan_mtx
);
3558 if (rdev
->sched_scan_req
) {
3563 request
= kzalloc(sizeof(*request
)
3564 + sizeof(*request
->ssids
) * n_ssids
3565 + sizeof(*request
->channels
) * n_channels
3566 + ie_len
, GFP_KERNEL
);
3573 request
->ssids
= (void *)&request
->channels
[n_channels
];
3574 request
->n_ssids
= n_ssids
;
3577 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
3579 request
->ie
= (void *)(request
->channels
+ n_channels
);
3583 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3584 /* user specified, bail out if channel not found */
3585 nla_for_each_nested(attr
,
3586 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
3588 struct ieee80211_channel
*chan
;
3590 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
3597 /* ignore disabled channels */
3598 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3601 request
->channels
[i
] = chan
;
3606 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
3608 if (!wiphy
->bands
[band
])
3610 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
3611 struct ieee80211_channel
*chan
;
3613 chan
= &wiphy
->bands
[band
]->channels
[j
];
3615 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3618 request
->channels
[i
] = chan
;
3629 request
->n_channels
= i
;
3632 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
3633 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
3635 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
3639 request
->ssids
[i
].ssid_len
= nla_len(attr
);
3640 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
3646 if (info
->attrs
[NL80211_ATTR_IE
]) {
3647 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3648 memcpy((void *)request
->ie
,
3649 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
3654 request
->wiphy
= &rdev
->wiphy
;
3655 request
->interval
= interval
;
3657 err
= rdev
->ops
->sched_scan_start(&rdev
->wiphy
, dev
, request
);
3659 rdev
->sched_scan_req
= request
;
3660 nl80211_send_sched_scan(rdev
, dev
,
3661 NL80211_CMD_START_SCHED_SCAN
);
3668 mutex_unlock(&rdev
->sched_scan_mtx
);
3672 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
3673 struct genl_info
*info
)
3675 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3678 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
3679 !rdev
->ops
->sched_scan_stop
)
3682 mutex_lock(&rdev
->sched_scan_mtx
);
3683 err
= __cfg80211_stop_sched_scan(rdev
, false);
3684 mutex_unlock(&rdev
->sched_scan_mtx
);
3689 static int nl80211_send_bss(struct sk_buff
*msg
, struct netlink_callback
*cb
,
3691 struct cfg80211_registered_device
*rdev
,
3692 struct wireless_dev
*wdev
,
3693 struct cfg80211_internal_bss
*intbss
)
3695 struct cfg80211_bss
*res
= &intbss
->pub
;
3700 ASSERT_WDEV_LOCK(wdev
);
3702 hdr
= nl80211hdr_put(msg
, NETLINK_CB(cb
->skb
).pid
, seq
, flags
,
3703 NL80211_CMD_NEW_SCAN_RESULTS
);
3707 genl_dump_check_consistent(cb
, hdr
, &nl80211_fam
);
3709 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
);
3710 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
);
3712 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
3714 goto nla_put_failure
;
3715 if (!is_zero_ether_addr(res
->bssid
))
3716 NLA_PUT(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
);
3717 if (res
->information_elements
&& res
->len_information_elements
)
3718 NLA_PUT(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
3719 res
->len_information_elements
,
3720 res
->information_elements
);
3721 if (res
->beacon_ies
&& res
->len_beacon_ies
&&
3722 res
->beacon_ies
!= res
->information_elements
)
3723 NLA_PUT(msg
, NL80211_BSS_BEACON_IES
,
3724 res
->len_beacon_ies
, res
->beacon_ies
);
3726 NLA_PUT_U64(msg
, NL80211_BSS_TSF
, res
->tsf
);
3727 if (res
->beacon_interval
)
3728 NLA_PUT_U16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
);
3729 NLA_PUT_U16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
);
3730 NLA_PUT_U32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
);
3731 NLA_PUT_U32(msg
, NL80211_BSS_SEEN_MS_AGO
,
3732 jiffies_to_msecs(jiffies
- intbss
->ts
));
3734 switch (rdev
->wiphy
.signal_type
) {
3735 case CFG80211_SIGNAL_TYPE_MBM
:
3736 NLA_PUT_U32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
);
3738 case CFG80211_SIGNAL_TYPE_UNSPEC
:
3739 NLA_PUT_U8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
);
3745 switch (wdev
->iftype
) {
3746 case NL80211_IFTYPE_P2P_CLIENT
:
3747 case NL80211_IFTYPE_STATION
:
3748 if (intbss
== wdev
->current_bss
)
3749 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3750 NL80211_BSS_STATUS_ASSOCIATED
);
3751 else for (i
= 0; i
< MAX_AUTH_BSSES
; i
++) {
3752 if (intbss
!= wdev
->auth_bsses
[i
])
3754 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3755 NL80211_BSS_STATUS_AUTHENTICATED
);
3759 case NL80211_IFTYPE_ADHOC
:
3760 if (intbss
== wdev
->current_bss
)
3761 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3762 NL80211_BSS_STATUS_IBSS_JOINED
);
3768 nla_nest_end(msg
, bss
);
3770 return genlmsg_end(msg
, hdr
);
3773 genlmsg_cancel(msg
, hdr
);
3777 static int nl80211_dump_scan(struct sk_buff
*skb
,
3778 struct netlink_callback
*cb
)
3780 struct cfg80211_registered_device
*rdev
;
3781 struct net_device
*dev
;
3782 struct cfg80211_internal_bss
*scan
;
3783 struct wireless_dev
*wdev
;
3784 int start
= cb
->args
[1], idx
= 0;
3787 err
= nl80211_prepare_netdev_dump(skb
, cb
, &rdev
, &dev
);
3791 wdev
= dev
->ieee80211_ptr
;
3794 spin_lock_bh(&rdev
->bss_lock
);
3795 cfg80211_bss_expire(rdev
);
3797 cb
->seq
= rdev
->bss_generation
;
3799 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
3802 if (nl80211_send_bss(skb
, cb
,
3803 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3804 rdev
, wdev
, scan
) < 0) {
3810 spin_unlock_bh(&rdev
->bss_lock
);
3814 nl80211_finish_netdev_dump(rdev
);
3819 static int nl80211_send_survey(struct sk_buff
*msg
, u32 pid
, u32 seq
,
3820 int flags
, struct net_device
*dev
,
3821 struct survey_info
*survey
)
3824 struct nlattr
*infoattr
;
3826 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3827 NL80211_CMD_NEW_SURVEY_RESULTS
);
3831 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
3833 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
3835 goto nla_put_failure
;
3837 NLA_PUT_U32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
3838 survey
->channel
->center_freq
);
3839 if (survey
->filled
& SURVEY_INFO_NOISE_DBM
)
3840 NLA_PUT_U8(msg
, NL80211_SURVEY_INFO_NOISE
,
3842 if (survey
->filled
& SURVEY_INFO_IN_USE
)
3843 NLA_PUT_FLAG(msg
, NL80211_SURVEY_INFO_IN_USE
);
3844 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME
)
3845 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
3846 survey
->channel_time
);
3847 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
)
3848 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
3849 survey
->channel_time_busy
);
3850 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
)
3851 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
3852 survey
->channel_time_ext_busy
);
3853 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
)
3854 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
3855 survey
->channel_time_rx
);
3856 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
)
3857 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
3858 survey
->channel_time_tx
);
3860 nla_nest_end(msg
, infoattr
);
3862 return genlmsg_end(msg
, hdr
);
3865 genlmsg_cancel(msg
, hdr
);
3869 static int nl80211_dump_survey(struct sk_buff
*skb
,
3870 struct netlink_callback
*cb
)
3872 struct survey_info survey
;
3873 struct cfg80211_registered_device
*dev
;
3874 struct net_device
*netdev
;
3875 int survey_idx
= cb
->args
[1];
3878 res
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
3882 if (!dev
->ops
->dump_survey
) {
3888 struct ieee80211_channel
*chan
;
3890 res
= dev
->ops
->dump_survey(&dev
->wiphy
, netdev
, survey_idx
,
3897 /* Survey without a channel doesn't make sense */
3898 if (!survey
.channel
) {
3903 chan
= ieee80211_get_channel(&dev
->wiphy
,
3904 survey
.channel
->center_freq
);
3905 if (!chan
|| chan
->flags
& IEEE80211_CHAN_DISABLED
) {
3910 if (nl80211_send_survey(skb
,
3911 NETLINK_CB(cb
->skb
).pid
,
3912 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3920 cb
->args
[1] = survey_idx
;
3923 nl80211_finish_netdev_dump(dev
);
3927 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
)
3929 return auth_type
<= NL80211_AUTHTYPE_MAX
;
3932 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
3934 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
3935 NL80211_WPA_VERSION_2
));
3938 static bool nl80211_valid_akm_suite(u32 akm
)
3940 return akm
== WLAN_AKM_SUITE_8021X
||
3941 akm
== WLAN_AKM_SUITE_PSK
;
3944 static bool nl80211_valid_cipher_suite(u32 cipher
)
3946 return cipher
== WLAN_CIPHER_SUITE_WEP40
||
3947 cipher
== WLAN_CIPHER_SUITE_WEP104
||
3948 cipher
== WLAN_CIPHER_SUITE_TKIP
||
3949 cipher
== WLAN_CIPHER_SUITE_CCMP
||
3950 cipher
== WLAN_CIPHER_SUITE_AES_CMAC
;
3954 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3956 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3957 struct net_device
*dev
= info
->user_ptr
[1];
3958 struct ieee80211_channel
*chan
;
3959 const u8
*bssid
, *ssid
, *ie
= NULL
;
3960 int err
, ssid_len
, ie_len
= 0;
3961 enum nl80211_auth_type auth_type
;
3962 struct key_parse key
;
3963 bool local_state_change
;
3965 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3968 if (!info
->attrs
[NL80211_ATTR_MAC
])
3971 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
3974 if (!info
->attrs
[NL80211_ATTR_SSID
])
3977 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
3980 err
= nl80211_parse_key(info
, &key
);
3985 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
3987 if (!key
.p
.key
|| !key
.p
.key_len
)
3989 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
3990 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
3991 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
3992 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
4004 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
4005 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
4014 if (!rdev
->ops
->auth
)
4017 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4018 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4021 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4022 chan
= ieee80211_get_channel(&rdev
->wiphy
,
4023 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4024 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
4027 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4028 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4030 if (info
->attrs
[NL80211_ATTR_IE
]) {
4031 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4032 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4035 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4036 if (!nl80211_valid_auth_type(auth_type
))
4039 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
4041 return cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
4042 ssid
, ssid_len
, ie
, ie_len
,
4043 key
.p
.key
, key
.p
.key_len
, key
.idx
,
4044 local_state_change
);
4047 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
4048 struct genl_info
*info
,
4049 struct cfg80211_crypto_settings
*settings
,
4052 memset(settings
, 0, sizeof(*settings
));
4054 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
4056 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
4058 proto
= nla_get_u16(
4059 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
4060 settings
->control_port_ethertype
= cpu_to_be16(proto
);
4061 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
4064 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
4065 settings
->control_port_no_encrypt
= true;
4067 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
4069 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
4073 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
4074 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
4075 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
4077 if (len
% sizeof(u32
))
4080 if (settings
->n_ciphers_pairwise
> cipher_limit
)
4083 memcpy(settings
->ciphers_pairwise
, data
, len
);
4085 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
4086 if (!nl80211_valid_cipher_suite(
4087 settings
->ciphers_pairwise
[i
]))
4091 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
4092 settings
->cipher_group
=
4093 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
4094 if (!nl80211_valid_cipher_suite(settings
->cipher_group
))
4098 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
4099 settings
->wpa_versions
=
4100 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
4101 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
4105 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
4109 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
4110 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
4111 settings
->n_akm_suites
= len
/ sizeof(u32
);
4113 if (len
% sizeof(u32
))
4116 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
4119 memcpy(settings
->akm_suites
, data
, len
);
4121 for (i
= 0; i
< settings
->n_akm_suites
; i
++)
4122 if (!nl80211_valid_akm_suite(settings
->akm_suites
[i
]))
4129 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
4131 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4132 struct net_device
*dev
= info
->user_ptr
[1];
4133 struct cfg80211_crypto_settings crypto
;
4134 struct ieee80211_channel
*chan
;
4135 const u8
*bssid
, *ssid
, *ie
= NULL
, *prev_bssid
= NULL
;
4136 int err
, ssid_len
, ie_len
= 0;
4137 bool use_mfp
= false;
4139 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4142 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
4143 !info
->attrs
[NL80211_ATTR_SSID
] ||
4144 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4147 if (!rdev
->ops
->assoc
)
4150 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4151 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4154 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4156 chan
= ieee80211_get_channel(&rdev
->wiphy
,
4157 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4158 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
4161 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4162 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4164 if (info
->attrs
[NL80211_ATTR_IE
]) {
4165 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4166 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4169 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
4170 enum nl80211_mfp mfp
=
4171 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
4172 if (mfp
== NL80211_MFP_REQUIRED
)
4174 else if (mfp
!= NL80211_MFP_NO
)
4178 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
4179 prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
4181 err
= nl80211_crypto_settings(rdev
, info
, &crypto
, 1);
4183 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
, prev_bssid
,
4184 ssid
, ssid_len
, ie
, ie_len
, use_mfp
,
4190 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
4192 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4193 struct net_device
*dev
= info
->user_ptr
[1];
4194 const u8
*ie
= NULL
, *bssid
;
4197 bool local_state_change
;
4199 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4202 if (!info
->attrs
[NL80211_ATTR_MAC
])
4205 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4208 if (!rdev
->ops
->deauth
)
4211 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4212 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4215 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4217 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4218 if (reason_code
== 0) {
4219 /* Reason Code 0 is reserved */
4223 if (info
->attrs
[NL80211_ATTR_IE
]) {
4224 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4225 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4228 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
4230 return cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
4231 local_state_change
);
4234 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
4236 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4237 struct net_device
*dev
= info
->user_ptr
[1];
4238 const u8
*ie
= NULL
, *bssid
;
4241 bool local_state_change
;
4243 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4246 if (!info
->attrs
[NL80211_ATTR_MAC
])
4249 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4252 if (!rdev
->ops
->disassoc
)
4255 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4256 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4259 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4261 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4262 if (reason_code
== 0) {
4263 /* Reason Code 0 is reserved */
4267 if (info
->attrs
[NL80211_ATTR_IE
]) {
4268 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4269 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4272 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
4274 return cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
4275 local_state_change
);
4279 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
4280 int mcast_rate
[IEEE80211_NUM_BANDS
],
4283 struct wiphy
*wiphy
= &rdev
->wiphy
;
4287 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
4288 struct ieee80211_supported_band
*sband
;
4290 sband
= wiphy
->bands
[band
];
4294 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
4295 if (sband
->bitrates
[i
].bitrate
== rateval
) {
4296 mcast_rate
[band
] = i
+ 1;
4306 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
4308 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4309 struct net_device
*dev
= info
->user_ptr
[1];
4310 struct cfg80211_ibss_params ibss
;
4311 struct wiphy
*wiphy
;
4312 struct cfg80211_cached_keys
*connkeys
= NULL
;
4315 memset(&ibss
, 0, sizeof(ibss
));
4317 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4320 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
4321 !info
->attrs
[NL80211_ATTR_SSID
] ||
4322 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
4325 ibss
.beacon_interval
= 100;
4327 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
4328 ibss
.beacon_interval
=
4329 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
4330 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
4334 if (!rdev
->ops
->join_ibss
)
4337 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
4340 wiphy
= &rdev
->wiphy
;
4342 if (info
->attrs
[NL80211_ATTR_MAC
])
4343 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4344 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4345 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4347 if (info
->attrs
[NL80211_ATTR_IE
]) {
4348 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4349 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4352 ibss
.channel
= ieee80211_get_channel(wiphy
,
4353 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4354 if (!ibss
.channel
||
4355 ibss
.channel
->flags
& IEEE80211_CHAN_NO_IBSS
||
4356 ibss
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
4359 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
4360 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
4362 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
4364 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4366 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4367 struct ieee80211_supported_band
*sband
=
4368 wiphy
->bands
[ibss
.channel
->band
];
4371 err
= ieee80211_get_ratemask(sband
, rates
, n_rates
,
4377 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
4378 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
4379 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
4382 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
4383 connkeys
= nl80211_parse_connkeys(rdev
,
4384 info
->attrs
[NL80211_ATTR_KEYS
]);
4385 if (IS_ERR(connkeys
))
4386 return PTR_ERR(connkeys
);
4389 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
4395 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
4397 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4398 struct net_device
*dev
= info
->user_ptr
[1];
4400 if (!rdev
->ops
->leave_ibss
)
4403 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
4406 return cfg80211_leave_ibss(rdev
, dev
, false);
4409 #ifdef CONFIG_NL80211_TESTMODE
4410 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
4414 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
4416 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4419 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
4423 if (rdev
->ops
->testmode_cmd
) {
4424 rdev
->testmode_info
= info
;
4425 err
= rdev
->ops
->testmode_cmd(&rdev
->wiphy
,
4426 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
4427 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
4428 rdev
->testmode_info
= NULL
;
4434 static int nl80211_testmode_dump(struct sk_buff
*skb
,
4435 struct netlink_callback
*cb
)
4437 struct cfg80211_registered_device
*dev
;
4445 * 0 is a valid index, but not valid for args[0],
4446 * so we need to offset by 1.
4448 phy_idx
= cb
->args
[0] - 1;
4450 err
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
4451 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
4455 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_WIPHY
])
4457 phy_idx
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_WIPHY
]);
4458 if (nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
])
4460 (long)nl80211_fam
.attrbuf
[NL80211_ATTR_TESTDATA
];
4464 data
= nla_data((void *)cb
->args
[1]);
4465 data_len
= nla_len((void *)cb
->args
[1]);
4468 mutex_lock(&cfg80211_mutex
);
4469 dev
= cfg80211_rdev_by_wiphy_idx(phy_idx
);
4471 mutex_unlock(&cfg80211_mutex
);
4474 cfg80211_lock_rdev(dev
);
4475 mutex_unlock(&cfg80211_mutex
);
4477 if (!dev
->ops
->testmode_dump
) {
4483 void *hdr
= nl80211hdr_put(skb
, NETLINK_CB(cb
->skb
).pid
,
4484 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
4485 NL80211_CMD_TESTMODE
);
4486 struct nlattr
*tmdata
;
4488 if (nla_put_u32(skb
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
) < 0) {
4489 genlmsg_cancel(skb
, hdr
);
4493 tmdata
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
4495 genlmsg_cancel(skb
, hdr
);
4498 err
= dev
->ops
->testmode_dump(&dev
->wiphy
, skb
, cb
,
4500 nla_nest_end(skb
, tmdata
);
4502 if (err
== -ENOBUFS
|| err
== -ENOENT
) {
4503 genlmsg_cancel(skb
, hdr
);
4506 genlmsg_cancel(skb
, hdr
);
4510 genlmsg_end(skb
, hdr
);
4515 cb
->args
[0] = phy_idx
+ 1;
4517 cfg80211_unlock_rdev(dev
);
4521 static struct sk_buff
*
4522 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
4523 int approxlen
, u32 pid
, u32 seq
, gfp_t gfp
)
4525 struct sk_buff
*skb
;
4527 struct nlattr
*data
;
4529 skb
= nlmsg_new(approxlen
+ 100, gfp
);
4533 hdr
= nl80211hdr_put(skb
, pid
, seq
, 0, NL80211_CMD_TESTMODE
);
4539 NLA_PUT_U32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4540 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
4542 ((void **)skb
->cb
)[0] = rdev
;
4543 ((void **)skb
->cb
)[1] = hdr
;
4544 ((void **)skb
->cb
)[2] = data
;
4553 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
4556 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4558 if (WARN_ON(!rdev
->testmode_info
))
4561 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
4562 rdev
->testmode_info
->snd_pid
,
4563 rdev
->testmode_info
->snd_seq
,
4566 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
4568 int cfg80211_testmode_reply(struct sk_buff
*skb
)
4570 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
4571 void *hdr
= ((void **)skb
->cb
)[1];
4572 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4574 if (WARN_ON(!rdev
->testmode_info
)) {
4579 nla_nest_end(skb
, data
);
4580 genlmsg_end(skb
, hdr
);
4581 return genlmsg_reply(skb
, rdev
->testmode_info
);
4583 EXPORT_SYMBOL(cfg80211_testmode_reply
);
4585 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
4586 int approxlen
, gfp_t gfp
)
4588 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4590 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
4592 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
4594 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
4596 void *hdr
= ((void **)skb
->cb
)[1];
4597 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4599 nla_nest_end(skb
, data
);
4600 genlmsg_end(skb
, hdr
);
4601 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
4603 EXPORT_SYMBOL(cfg80211_testmode_event
);
4606 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
4608 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4609 struct net_device
*dev
= info
->user_ptr
[1];
4610 struct cfg80211_connect_params connect
;
4611 struct wiphy
*wiphy
;
4612 struct cfg80211_cached_keys
*connkeys
= NULL
;
4615 memset(&connect
, 0, sizeof(connect
));
4617 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4620 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
4621 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
4624 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
4626 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4627 if (!nl80211_valid_auth_type(connect
.auth_type
))
4630 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
4632 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
4634 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
4635 NL80211_MAX_NR_CIPHER_SUITES
);
4639 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4640 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4643 wiphy
= &rdev
->wiphy
;
4645 if (info
->attrs
[NL80211_ATTR_MAC
])
4646 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4647 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4648 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4650 if (info
->attrs
[NL80211_ATTR_IE
]) {
4651 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4652 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4655 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
4657 ieee80211_get_channel(wiphy
,
4658 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4659 if (!connect
.channel
||
4660 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
4664 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
4665 connkeys
= nl80211_parse_connkeys(rdev
,
4666 info
->attrs
[NL80211_ATTR_KEYS
]);
4667 if (IS_ERR(connkeys
))
4668 return PTR_ERR(connkeys
);
4671 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
4677 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
4679 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4680 struct net_device
*dev
= info
->user_ptr
[1];
4683 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4684 reason
= WLAN_REASON_DEAUTH_LEAVING
;
4686 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4691 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4692 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4695 return cfg80211_disconnect(rdev
, dev
, reason
, true);
4698 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
4700 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4705 if (!info
->attrs
[NL80211_ATTR_PID
])
4708 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
4710 net
= get_net_ns_by_pid(pid
);
4712 return PTR_ERR(net
);
4716 /* check if anything to do */
4717 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
4718 err
= cfg80211_switch_netns(rdev
, net
);
4724 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4726 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4727 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
4728 struct cfg80211_pmksa
*pmksa
) = NULL
;
4729 struct net_device
*dev
= info
->user_ptr
[1];
4730 struct cfg80211_pmksa pmksa
;
4732 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
4734 if (!info
->attrs
[NL80211_ATTR_MAC
])
4737 if (!info
->attrs
[NL80211_ATTR_PMKID
])
4740 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
4741 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4743 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4744 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4747 switch (info
->genlhdr
->cmd
) {
4748 case NL80211_CMD_SET_PMKSA
:
4749 rdev_ops
= rdev
->ops
->set_pmksa
;
4751 case NL80211_CMD_DEL_PMKSA
:
4752 rdev_ops
= rdev
->ops
->del_pmksa
;
4762 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
4765 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4767 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4768 struct net_device
*dev
= info
->user_ptr
[1];
4770 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4771 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4774 if (!rdev
->ops
->flush_pmksa
)
4777 return rdev
->ops
->flush_pmksa(&rdev
->wiphy
, dev
);
4780 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
4781 struct genl_info
*info
)
4783 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4784 struct net_device
*dev
= info
->user_ptr
[1];
4785 struct ieee80211_channel
*chan
;
4786 struct sk_buff
*msg
;
4789 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
4793 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
4794 !info
->attrs
[NL80211_ATTR_DURATION
])
4797 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
4800 * We should be on that channel for at least one jiffie,
4801 * and more than 5 seconds seems excessive.
4803 if (!duration
|| !msecs_to_jiffies(duration
) ||
4804 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
4807 if (!rdev
->ops
->remain_on_channel
)
4810 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
4811 channel_type
= nla_get_u32(
4812 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
4813 if (channel_type
!= NL80211_CHAN_NO_HT
&&
4814 channel_type
!= NL80211_CHAN_HT20
&&
4815 channel_type
!= NL80211_CHAN_HT40PLUS
&&
4816 channel_type
!= NL80211_CHAN_HT40MINUS
)
4820 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
4821 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
4825 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4829 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4830 NL80211_CMD_REMAIN_ON_CHANNEL
);
4837 err
= rdev
->ops
->remain_on_channel(&rdev
->wiphy
, dev
, chan
,
4838 channel_type
, duration
, &cookie
);
4843 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
4845 genlmsg_end(msg
, hdr
);
4847 return genlmsg_reply(msg
, info
);
4856 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
4857 struct genl_info
*info
)
4859 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4860 struct net_device
*dev
= info
->user_ptr
[1];
4863 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
4866 if (!rdev
->ops
->cancel_remain_on_channel
)
4869 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
4871 return rdev
->ops
->cancel_remain_on_channel(&rdev
->wiphy
, dev
, cookie
);
4874 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
4875 u8
*rates
, u8 rates_len
)
4880 for (i
= 0; i
< rates_len
; i
++) {
4881 int rate
= (rates
[i
] & 0x7f) * 5;
4883 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
4884 struct ieee80211_rate
*srate
=
4885 &sband
->bitrates
[ridx
];
4886 if (rate
== srate
->bitrate
) {
4891 if (ridx
== sband
->n_bitrates
)
4892 return 0; /* rate not found */
4898 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
4899 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
4900 .len
= NL80211_MAX_SUPP_RATES
},
4903 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
4904 struct genl_info
*info
)
4906 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
4907 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4908 struct cfg80211_bitrate_mask mask
;
4910 struct net_device
*dev
= info
->user_ptr
[1];
4911 struct nlattr
*tx_rates
;
4912 struct ieee80211_supported_band
*sband
;
4914 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
4917 if (!rdev
->ops
->set_bitrate_mask
)
4920 memset(&mask
, 0, sizeof(mask
));
4921 /* Default to all rates enabled */
4922 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
4923 sband
= rdev
->wiphy
.bands
[i
];
4924 mask
.control
[i
].legacy
=
4925 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
4929 * The nested attribute uses enum nl80211_band as the index. This maps
4930 * directly to the enum ieee80211_band values used in cfg80211.
4932 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
4934 enum ieee80211_band band
= nla_type(tx_rates
);
4935 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
4937 sband
= rdev
->wiphy
.bands
[band
];
4940 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
4941 nla_len(tx_rates
), nl80211_txattr_policy
);
4942 if (tb
[NL80211_TXRATE_LEGACY
]) {
4943 mask
.control
[band
].legacy
= rateset_to_mask(
4945 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
4946 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
4947 if (mask
.control
[band
].legacy
== 0)
4952 return rdev
->ops
->set_bitrate_mask(&rdev
->wiphy
, dev
, NULL
, &mask
);
4955 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
4957 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4958 struct net_device
*dev
= info
->user_ptr
[1];
4959 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
4961 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
4964 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
4965 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
4967 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4968 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
4969 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
4970 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4971 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4972 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
4973 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4976 /* not much point in registering if we can't reply */
4977 if (!rdev
->ops
->mgmt_tx
)
4980 return cfg80211_mlme_register_mgmt(dev
->ieee80211_ptr
, info
->snd_pid
,
4982 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
4983 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
4986 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
4988 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4989 struct net_device
*dev
= info
->user_ptr
[1];
4990 struct ieee80211_channel
*chan
;
4991 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
4992 bool channel_type_valid
= false;
4997 struct sk_buff
*msg
;
4998 unsigned int wait
= 0;
5001 if (!info
->attrs
[NL80211_ATTR_FRAME
] ||
5002 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
5005 if (!rdev
->ops
->mgmt_tx
)
5008 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5009 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
5010 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
5011 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5012 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
5013 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
5014 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5017 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
5018 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
5020 wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
5023 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
5024 channel_type
= nla_get_u32(
5025 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
5026 if (channel_type
!= NL80211_CHAN_NO_HT
&&
5027 channel_type
!= NL80211_CHAN_HT20
&&
5028 channel_type
!= NL80211_CHAN_HT40PLUS
&&
5029 channel_type
!= NL80211_CHAN_HT40MINUS
)
5031 channel_type_valid
= true;
5034 offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
5036 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
5037 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
5041 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5045 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
5052 err
= cfg80211_mlme_mgmt_tx(rdev
, dev
, chan
, offchan
, channel_type
,
5053 channel_type_valid
, wait
,
5054 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
5055 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
5060 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
5062 genlmsg_end(msg
, hdr
);
5063 return genlmsg_reply(msg
, info
);
5072 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
5074 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5075 struct net_device
*dev
= info
->user_ptr
[1];
5078 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
5081 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
5084 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
5085 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
5086 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
5087 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
5088 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
5089 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
5092 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
5094 return rdev
->ops
->mgmt_tx_cancel_wait(&rdev
->wiphy
, dev
, cookie
);
5097 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
5099 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5100 struct wireless_dev
*wdev
;
5101 struct net_device
*dev
= info
->user_ptr
[1];
5106 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
5109 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
5111 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
5114 wdev
= dev
->ieee80211_ptr
;
5116 if (!rdev
->ops
->set_power_mgmt
)
5119 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
5121 if (state
== wdev
->ps
)
5124 err
= rdev
->ops
->set_power_mgmt(wdev
->wiphy
, dev
, state
,
5131 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
5133 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5134 enum nl80211_ps_state ps_state
;
5135 struct wireless_dev
*wdev
;
5136 struct net_device
*dev
= info
->user_ptr
[1];
5137 struct sk_buff
*msg
;
5141 wdev
= dev
->ieee80211_ptr
;
5143 if (!rdev
->ops
->set_power_mgmt
)
5146 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5150 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
5151 NL80211_CMD_GET_POWER_SAVE
);
5158 ps_state
= NL80211_PS_ENABLED
;
5160 ps_state
= NL80211_PS_DISABLED
;
5162 NLA_PUT_U32(msg
, NL80211_ATTR_PS_STATE
, ps_state
);
5164 genlmsg_end(msg
, hdr
);
5165 return genlmsg_reply(msg
, info
);
5174 static struct nla_policy
5175 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
5176 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
5177 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
5178 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
5181 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
5182 s32 threshold
, u32 hysteresis
)
5184 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5185 struct wireless_dev
*wdev
;
5186 struct net_device
*dev
= info
->user_ptr
[1];
5191 wdev
= dev
->ieee80211_ptr
;
5193 if (!rdev
->ops
->set_cqm_rssi_config
)
5196 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
5197 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5200 return rdev
->ops
->set_cqm_rssi_config(wdev
->wiphy
, dev
,
5201 threshold
, hysteresis
);
5204 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
5206 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
5210 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
5216 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
5217 nl80211_attr_cqm_policy
);
5221 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
5222 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
5225 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
5226 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
5227 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
5235 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
5237 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5238 struct net_device
*dev
= info
->user_ptr
[1];
5239 struct mesh_config cfg
;
5240 struct mesh_setup setup
;
5243 /* start with default */
5244 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
5245 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
5247 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
5248 /* and parse parameters if given */
5249 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
5254 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
5255 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
5258 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
5259 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
5261 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
5262 /* parse additional setup parameters if given */
5263 err
= nl80211_parse_mesh_setup(info
, &setup
);
5268 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
5271 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
5273 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5274 struct net_device
*dev
= info
->user_ptr
[1];
5276 return cfg80211_leave_mesh(rdev
, dev
);
5279 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
5281 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5282 struct sk_buff
*msg
;
5285 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
5288 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5292 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
5293 NL80211_CMD_GET_WOWLAN
);
5295 goto nla_put_failure
;
5298 struct nlattr
*nl_wowlan
;
5300 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
5302 goto nla_put_failure
;
5304 if (rdev
->wowlan
->any
)
5305 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_ANY
);
5306 if (rdev
->wowlan
->disconnect
)
5307 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
);
5308 if (rdev
->wowlan
->magic_pkt
)
5309 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
);
5310 if (rdev
->wowlan
->gtk_rekey_failure
)
5311 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
);
5312 if (rdev
->wowlan
->eap_identity_req
)
5313 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
);
5314 if (rdev
->wowlan
->four_way_handshake
)
5315 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
);
5316 if (rdev
->wowlan
->rfkill_release
)
5317 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_RFKILL_RELEASE
);
5318 if (rdev
->wowlan
->n_patterns
) {
5319 struct nlattr
*nl_pats
, *nl_pat
;
5322 nl_pats
= nla_nest_start(msg
,
5323 NL80211_WOWLAN_TRIG_PKT_PATTERN
);
5325 goto nla_put_failure
;
5327 for (i
= 0; i
< rdev
->wowlan
->n_patterns
; i
++) {
5328 nl_pat
= nla_nest_start(msg
, i
+ 1);
5330 goto nla_put_failure
;
5331 pat_len
= rdev
->wowlan
->patterns
[i
].pattern_len
;
5332 NLA_PUT(msg
, NL80211_WOWLAN_PKTPAT_MASK
,
5333 DIV_ROUND_UP(pat_len
, 8),
5334 rdev
->wowlan
->patterns
[i
].mask
);
5335 NLA_PUT(msg
, NL80211_WOWLAN_PKTPAT_PATTERN
,
5337 rdev
->wowlan
->patterns
[i
].pattern
);
5338 nla_nest_end(msg
, nl_pat
);
5340 nla_nest_end(msg
, nl_pats
);
5343 nla_nest_end(msg
, nl_wowlan
);
5346 genlmsg_end(msg
, hdr
);
5347 return genlmsg_reply(msg
, info
);
5354 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
5356 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5357 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
5358 struct cfg80211_wowlan no_triggers
= {};
5359 struct cfg80211_wowlan new_triggers
= {};
5360 struct wiphy_wowlan_support
*wowlan
= &rdev
->wiphy
.wowlan
;
5363 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
5366 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
])
5369 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
5370 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
5371 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
5372 nl80211_wowlan_policy
);
5376 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
5377 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
5379 new_triggers
.any
= true;
5382 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
5383 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
5385 new_triggers
.disconnect
= true;
5388 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
5389 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
5391 new_triggers
.magic_pkt
= true;
5394 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED
])
5397 if (tb
[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE
]) {
5398 if (!(wowlan
->flags
& WIPHY_WOWLAN_GTK_REKEY_FAILURE
))
5400 new_triggers
.gtk_rekey_failure
= true;
5403 if (tb
[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST
]) {
5404 if (!(wowlan
->flags
& WIPHY_WOWLAN_EAP_IDENTITY_REQ
))
5406 new_triggers
.eap_identity_req
= true;
5409 if (tb
[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE
]) {
5410 if (!(wowlan
->flags
& WIPHY_WOWLAN_4WAY_HANDSHAKE
))
5412 new_triggers
.four_way_handshake
= true;
5415 if (tb
[NL80211_WOWLAN_TRIG_RFKILL_RELEASE
]) {
5416 if (!(wowlan
->flags
& WIPHY_WOWLAN_RFKILL_RELEASE
))
5418 new_triggers
.rfkill_release
= true;
5421 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
5424 int rem
, pat_len
, mask_len
;
5425 struct nlattr
*pat_tb
[NUM_NL80211_WOWLAN_PKTPAT
];
5427 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
5430 if (n_patterns
> wowlan
->n_patterns
)
5433 new_triggers
.patterns
= kcalloc(n_patterns
,
5434 sizeof(new_triggers
.patterns
[0]),
5436 if (!new_triggers
.patterns
)
5439 new_triggers
.n_patterns
= n_patterns
;
5442 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
5444 nla_parse(pat_tb
, MAX_NL80211_WOWLAN_PKTPAT
,
5445 nla_data(pat
), nla_len(pat
), NULL
);
5447 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
] ||
5448 !pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
])
5450 pat_len
= nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]);
5451 mask_len
= DIV_ROUND_UP(pat_len
, 8);
5452 if (nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]) !=
5455 if (pat_len
> wowlan
->pattern_max_len
||
5456 pat_len
< wowlan
->pattern_min_len
)
5459 new_triggers
.patterns
[i
].mask
=
5460 kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
5461 if (!new_triggers
.patterns
[i
].mask
) {
5465 new_triggers
.patterns
[i
].pattern
=
5466 new_triggers
.patterns
[i
].mask
+ mask_len
;
5467 memcpy(new_triggers
.patterns
[i
].mask
,
5468 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]),
5470 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
5471 memcpy(new_triggers
.patterns
[i
].pattern
,
5472 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]),
5478 if (memcmp(&new_triggers
, &no_triggers
, sizeof(new_triggers
))) {
5479 struct cfg80211_wowlan
*ntrig
;
5480 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
),
5486 cfg80211_rdev_free_wowlan(rdev
);
5487 rdev
->wowlan
= ntrig
;
5490 cfg80211_rdev_free_wowlan(rdev
);
5491 rdev
->wowlan
= NULL
;
5496 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
5497 kfree(new_triggers
.patterns
[i
].mask
);
5498 kfree(new_triggers
.patterns
);
5502 static int nl80211_set_rekey_data(struct sk_buff
*skb
, struct genl_info
*info
)
5504 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5505 struct net_device
*dev
= info
->user_ptr
[1];
5506 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
5507 struct nlattr
*tb
[NUM_NL80211_REKEY_DATA
];
5508 struct cfg80211_gtk_rekey_data rekey_data
;
5511 if (!info
->attrs
[NL80211_ATTR_REKEY_DATA
])
5514 err
= nla_parse(tb
, MAX_NL80211_REKEY_DATA
,
5515 nla_data(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
5516 nla_len(info
->attrs
[NL80211_ATTR_REKEY_DATA
]),
5517 nl80211_rekey_policy
);
5521 if (nla_len(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]) != NL80211_REPLAY_CTR_LEN
)
5523 if (nla_len(tb
[NL80211_REKEY_DATA_KEK
]) != NL80211_KEK_LEN
)
5525 if (nla_len(tb
[NL80211_REKEY_DATA_KCK
]) != NL80211_KCK_LEN
)
5528 memcpy(rekey_data
.kek
, nla_data(tb
[NL80211_REKEY_DATA_KEK
]),
5530 memcpy(rekey_data
.kck
, nla_data(tb
[NL80211_REKEY_DATA_KCK
]),
5532 memcpy(rekey_data
.replay_ctr
,
5533 nla_data(tb
[NL80211_REKEY_DATA_REPLAY_CTR
]),
5534 NL80211_REPLAY_CTR_LEN
);
5537 if (!wdev
->current_bss
) {
5542 if (!rdev
->ops
->set_rekey_data
) {
5547 err
= rdev
->ops
->set_rekey_data(&rdev
->wiphy
, dev
, &rekey_data
);
5553 #define NL80211_FLAG_NEED_WIPHY 0x01
5554 #define NL80211_FLAG_NEED_NETDEV 0x02
5555 #define NL80211_FLAG_NEED_RTNL 0x04
5556 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
5557 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
5558 NL80211_FLAG_CHECK_NETDEV_UP)
5560 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
5561 struct genl_info
*info
)
5563 struct cfg80211_registered_device
*rdev
;
5564 struct net_device
*dev
;
5566 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
5571 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
5572 rdev
= cfg80211_get_dev_from_info(info
);
5576 return PTR_ERR(rdev
);
5578 info
->user_ptr
[0] = rdev
;
5579 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
5580 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
5586 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
5587 !netif_running(dev
)) {
5588 cfg80211_unlock_rdev(rdev
);
5594 info
->user_ptr
[0] = rdev
;
5595 info
->user_ptr
[1] = dev
;
5601 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
5602 struct genl_info
*info
)
5604 if (info
->user_ptr
[0])
5605 cfg80211_unlock_rdev(info
->user_ptr
[0]);
5606 if (info
->user_ptr
[1])
5607 dev_put(info
->user_ptr
[1]);
5608 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
5612 static struct genl_ops nl80211_ops
[] = {
5614 .cmd
= NL80211_CMD_GET_WIPHY
,
5615 .doit
= nl80211_get_wiphy
,
5616 .dumpit
= nl80211_dump_wiphy
,
5617 .policy
= nl80211_policy
,
5618 /* can be retrieved by unprivileged users */
5619 .internal_flags
= NL80211_FLAG_NEED_WIPHY
,
5622 .cmd
= NL80211_CMD_SET_WIPHY
,
5623 .doit
= nl80211_set_wiphy
,
5624 .policy
= nl80211_policy
,
5625 .flags
= GENL_ADMIN_PERM
,
5626 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
5629 .cmd
= NL80211_CMD_GET_INTERFACE
,
5630 .doit
= nl80211_get_interface
,
5631 .dumpit
= nl80211_dump_interface
,
5632 .policy
= nl80211_policy
,
5633 /* can be retrieved by unprivileged users */
5634 .internal_flags
= NL80211_FLAG_NEED_NETDEV
,
5637 .cmd
= NL80211_CMD_SET_INTERFACE
,
5638 .doit
= nl80211_set_interface
,
5639 .policy
= nl80211_policy
,
5640 .flags
= GENL_ADMIN_PERM
,
5641 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5642 NL80211_FLAG_NEED_RTNL
,
5645 .cmd
= NL80211_CMD_NEW_INTERFACE
,
5646 .doit
= nl80211_new_interface
,
5647 .policy
= nl80211_policy
,
5648 .flags
= GENL_ADMIN_PERM
,
5649 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
5650 NL80211_FLAG_NEED_RTNL
,
5653 .cmd
= NL80211_CMD_DEL_INTERFACE
,
5654 .doit
= nl80211_del_interface
,
5655 .policy
= nl80211_policy
,
5656 .flags
= GENL_ADMIN_PERM
,
5657 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5658 NL80211_FLAG_NEED_RTNL
,
5661 .cmd
= NL80211_CMD_GET_KEY
,
5662 .doit
= nl80211_get_key
,
5663 .policy
= nl80211_policy
,
5664 .flags
= GENL_ADMIN_PERM
,
5665 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5666 NL80211_FLAG_NEED_RTNL
,
5669 .cmd
= NL80211_CMD_SET_KEY
,
5670 .doit
= nl80211_set_key
,
5671 .policy
= nl80211_policy
,
5672 .flags
= GENL_ADMIN_PERM
,
5673 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5674 NL80211_FLAG_NEED_RTNL
,
5677 .cmd
= NL80211_CMD_NEW_KEY
,
5678 .doit
= nl80211_new_key
,
5679 .policy
= nl80211_policy
,
5680 .flags
= GENL_ADMIN_PERM
,
5681 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5682 NL80211_FLAG_NEED_RTNL
,
5685 .cmd
= NL80211_CMD_DEL_KEY
,
5686 .doit
= nl80211_del_key
,
5687 .policy
= nl80211_policy
,
5688 .flags
= GENL_ADMIN_PERM
,
5689 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5690 NL80211_FLAG_NEED_RTNL
,
5693 .cmd
= NL80211_CMD_SET_BEACON
,
5694 .policy
= nl80211_policy
,
5695 .flags
= GENL_ADMIN_PERM
,
5696 .doit
= nl80211_addset_beacon
,
5697 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5698 NL80211_FLAG_NEED_RTNL
,
5701 .cmd
= NL80211_CMD_NEW_BEACON
,
5702 .policy
= nl80211_policy
,
5703 .flags
= GENL_ADMIN_PERM
,
5704 .doit
= nl80211_addset_beacon
,
5705 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5706 NL80211_FLAG_NEED_RTNL
,
5709 .cmd
= NL80211_CMD_DEL_BEACON
,
5710 .policy
= nl80211_policy
,
5711 .flags
= GENL_ADMIN_PERM
,
5712 .doit
= nl80211_del_beacon
,
5713 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5714 NL80211_FLAG_NEED_RTNL
,
5717 .cmd
= NL80211_CMD_GET_STATION
,
5718 .doit
= nl80211_get_station
,
5719 .dumpit
= nl80211_dump_station
,
5720 .policy
= nl80211_policy
,
5721 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5722 NL80211_FLAG_NEED_RTNL
,
5725 .cmd
= NL80211_CMD_SET_STATION
,
5726 .doit
= nl80211_set_station
,
5727 .policy
= nl80211_policy
,
5728 .flags
= GENL_ADMIN_PERM
,
5729 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5730 NL80211_FLAG_NEED_RTNL
,
5733 .cmd
= NL80211_CMD_NEW_STATION
,
5734 .doit
= nl80211_new_station
,
5735 .policy
= nl80211_policy
,
5736 .flags
= GENL_ADMIN_PERM
,
5737 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5738 NL80211_FLAG_NEED_RTNL
,
5741 .cmd
= NL80211_CMD_DEL_STATION
,
5742 .doit
= nl80211_del_station
,
5743 .policy
= nl80211_policy
,
5744 .flags
= GENL_ADMIN_PERM
,
5745 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5746 NL80211_FLAG_NEED_RTNL
,
5749 .cmd
= NL80211_CMD_GET_MPATH
,
5750 .doit
= nl80211_get_mpath
,
5751 .dumpit
= nl80211_dump_mpath
,
5752 .policy
= nl80211_policy
,
5753 .flags
= GENL_ADMIN_PERM
,
5754 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5755 NL80211_FLAG_NEED_RTNL
,
5758 .cmd
= NL80211_CMD_SET_MPATH
,
5759 .doit
= nl80211_set_mpath
,
5760 .policy
= nl80211_policy
,
5761 .flags
= GENL_ADMIN_PERM
,
5762 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5763 NL80211_FLAG_NEED_RTNL
,
5766 .cmd
= NL80211_CMD_NEW_MPATH
,
5767 .doit
= nl80211_new_mpath
,
5768 .policy
= nl80211_policy
,
5769 .flags
= GENL_ADMIN_PERM
,
5770 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5771 NL80211_FLAG_NEED_RTNL
,
5774 .cmd
= NL80211_CMD_DEL_MPATH
,
5775 .doit
= nl80211_del_mpath
,
5776 .policy
= nl80211_policy
,
5777 .flags
= GENL_ADMIN_PERM
,
5778 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5779 NL80211_FLAG_NEED_RTNL
,
5782 .cmd
= NL80211_CMD_SET_BSS
,
5783 .doit
= nl80211_set_bss
,
5784 .policy
= nl80211_policy
,
5785 .flags
= GENL_ADMIN_PERM
,
5786 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5787 NL80211_FLAG_NEED_RTNL
,
5790 .cmd
= NL80211_CMD_GET_REG
,
5791 .doit
= nl80211_get_reg
,
5792 .policy
= nl80211_policy
,
5793 /* can be retrieved by unprivileged users */
5796 .cmd
= NL80211_CMD_SET_REG
,
5797 .doit
= nl80211_set_reg
,
5798 .policy
= nl80211_policy
,
5799 .flags
= GENL_ADMIN_PERM
,
5802 .cmd
= NL80211_CMD_REQ_SET_REG
,
5803 .doit
= nl80211_req_set_reg
,
5804 .policy
= nl80211_policy
,
5805 .flags
= GENL_ADMIN_PERM
,
5808 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
5809 .doit
= nl80211_get_mesh_config
,
5810 .policy
= nl80211_policy
,
5811 /* can be retrieved by unprivileged users */
5812 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5813 NL80211_FLAG_NEED_RTNL
,
5816 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
5817 .doit
= nl80211_update_mesh_config
,
5818 .policy
= nl80211_policy
,
5819 .flags
= GENL_ADMIN_PERM
,
5820 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5821 NL80211_FLAG_NEED_RTNL
,
5824 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
5825 .doit
= nl80211_trigger_scan
,
5826 .policy
= nl80211_policy
,
5827 .flags
= GENL_ADMIN_PERM
,
5828 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5829 NL80211_FLAG_NEED_RTNL
,
5832 .cmd
= NL80211_CMD_GET_SCAN
,
5833 .policy
= nl80211_policy
,
5834 .dumpit
= nl80211_dump_scan
,
5837 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
5838 .doit
= nl80211_start_sched_scan
,
5839 .policy
= nl80211_policy
,
5840 .flags
= GENL_ADMIN_PERM
,
5841 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5842 NL80211_FLAG_NEED_RTNL
,
5845 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
5846 .doit
= nl80211_stop_sched_scan
,
5847 .policy
= nl80211_policy
,
5848 .flags
= GENL_ADMIN_PERM
,
5849 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5850 NL80211_FLAG_NEED_RTNL
,
5853 .cmd
= NL80211_CMD_AUTHENTICATE
,
5854 .doit
= nl80211_authenticate
,
5855 .policy
= nl80211_policy
,
5856 .flags
= GENL_ADMIN_PERM
,
5857 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5858 NL80211_FLAG_NEED_RTNL
,
5861 .cmd
= NL80211_CMD_ASSOCIATE
,
5862 .doit
= nl80211_associate
,
5863 .policy
= nl80211_policy
,
5864 .flags
= GENL_ADMIN_PERM
,
5865 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5866 NL80211_FLAG_NEED_RTNL
,
5869 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
5870 .doit
= nl80211_deauthenticate
,
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_DISASSOCIATE
,
5878 .doit
= nl80211_disassociate
,
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_JOIN_IBSS
,
5886 .doit
= nl80211_join_ibss
,
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_LEAVE_IBSS
,
5894 .doit
= nl80211_leave_ibss
,
5895 .policy
= nl80211_policy
,
5896 .flags
= GENL_ADMIN_PERM
,
5897 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5898 NL80211_FLAG_NEED_RTNL
,
5900 #ifdef CONFIG_NL80211_TESTMODE
5902 .cmd
= NL80211_CMD_TESTMODE
,
5903 .doit
= nl80211_testmode_do
,
5904 .dumpit
= nl80211_testmode_dump
,
5905 .policy
= nl80211_policy
,
5906 .flags
= GENL_ADMIN_PERM
,
5907 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
5908 NL80211_FLAG_NEED_RTNL
,
5912 .cmd
= NL80211_CMD_CONNECT
,
5913 .doit
= nl80211_connect
,
5914 .policy
= nl80211_policy
,
5915 .flags
= GENL_ADMIN_PERM
,
5916 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5917 NL80211_FLAG_NEED_RTNL
,
5920 .cmd
= NL80211_CMD_DISCONNECT
,
5921 .doit
= nl80211_disconnect
,
5922 .policy
= nl80211_policy
,
5923 .flags
= GENL_ADMIN_PERM
,
5924 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5925 NL80211_FLAG_NEED_RTNL
,
5928 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
5929 .doit
= nl80211_wiphy_netns
,
5930 .policy
= nl80211_policy
,
5931 .flags
= GENL_ADMIN_PERM
,
5932 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
5933 NL80211_FLAG_NEED_RTNL
,
5936 .cmd
= NL80211_CMD_GET_SURVEY
,
5937 .policy
= nl80211_policy
,
5938 .dumpit
= nl80211_dump_survey
,
5941 .cmd
= NL80211_CMD_SET_PMKSA
,
5942 .doit
= nl80211_setdel_pmksa
,
5943 .policy
= nl80211_policy
,
5944 .flags
= GENL_ADMIN_PERM
,
5945 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5946 NL80211_FLAG_NEED_RTNL
,
5949 .cmd
= NL80211_CMD_DEL_PMKSA
,
5950 .doit
= nl80211_setdel_pmksa
,
5951 .policy
= nl80211_policy
,
5952 .flags
= GENL_ADMIN_PERM
,
5953 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5954 NL80211_FLAG_NEED_RTNL
,
5957 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
5958 .doit
= nl80211_flush_pmksa
,
5959 .policy
= nl80211_policy
,
5960 .flags
= GENL_ADMIN_PERM
,
5961 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5962 NL80211_FLAG_NEED_RTNL
,
5965 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
5966 .doit
= nl80211_remain_on_channel
,
5967 .policy
= nl80211_policy
,
5968 .flags
= GENL_ADMIN_PERM
,
5969 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5970 NL80211_FLAG_NEED_RTNL
,
5973 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
5974 .doit
= nl80211_cancel_remain_on_channel
,
5975 .policy
= nl80211_policy
,
5976 .flags
= GENL_ADMIN_PERM
,
5977 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5978 NL80211_FLAG_NEED_RTNL
,
5981 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
5982 .doit
= nl80211_set_tx_bitrate_mask
,
5983 .policy
= nl80211_policy
,
5984 .flags
= GENL_ADMIN_PERM
,
5985 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5986 NL80211_FLAG_NEED_RTNL
,
5989 .cmd
= NL80211_CMD_REGISTER_FRAME
,
5990 .doit
= nl80211_register_mgmt
,
5991 .policy
= nl80211_policy
,
5992 .flags
= GENL_ADMIN_PERM
,
5993 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5994 NL80211_FLAG_NEED_RTNL
,
5997 .cmd
= NL80211_CMD_FRAME
,
5998 .doit
= nl80211_tx_mgmt
,
5999 .policy
= nl80211_policy
,
6000 .flags
= GENL_ADMIN_PERM
,
6001 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6002 NL80211_FLAG_NEED_RTNL
,
6005 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
6006 .doit
= nl80211_tx_mgmt_cancel_wait
,
6007 .policy
= nl80211_policy
,
6008 .flags
= GENL_ADMIN_PERM
,
6009 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6010 NL80211_FLAG_NEED_RTNL
,
6013 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
6014 .doit
= nl80211_set_power_save
,
6015 .policy
= nl80211_policy
,
6016 .flags
= GENL_ADMIN_PERM
,
6017 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6018 NL80211_FLAG_NEED_RTNL
,
6021 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
6022 .doit
= nl80211_get_power_save
,
6023 .policy
= nl80211_policy
,
6024 /* can be retrieved by unprivileged users */
6025 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6026 NL80211_FLAG_NEED_RTNL
,
6029 .cmd
= NL80211_CMD_SET_CQM
,
6030 .doit
= nl80211_set_cqm
,
6031 .policy
= nl80211_policy
,
6032 .flags
= GENL_ADMIN_PERM
,
6033 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6034 NL80211_FLAG_NEED_RTNL
,
6037 .cmd
= NL80211_CMD_SET_CHANNEL
,
6038 .doit
= nl80211_set_channel
,
6039 .policy
= nl80211_policy
,
6040 .flags
= GENL_ADMIN_PERM
,
6041 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6042 NL80211_FLAG_NEED_RTNL
,
6045 .cmd
= NL80211_CMD_SET_WDS_PEER
,
6046 .doit
= nl80211_set_wds_peer
,
6047 .policy
= nl80211_policy
,
6048 .flags
= GENL_ADMIN_PERM
,
6049 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
6050 NL80211_FLAG_NEED_RTNL
,
6053 .cmd
= NL80211_CMD_JOIN_MESH
,
6054 .doit
= nl80211_join_mesh
,
6055 .policy
= nl80211_policy
,
6056 .flags
= GENL_ADMIN_PERM
,
6057 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6058 NL80211_FLAG_NEED_RTNL
,
6061 .cmd
= NL80211_CMD_LEAVE_MESH
,
6062 .doit
= nl80211_leave_mesh
,
6063 .policy
= nl80211_policy
,
6064 .flags
= GENL_ADMIN_PERM
,
6065 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6066 NL80211_FLAG_NEED_RTNL
,
6069 .cmd
= NL80211_CMD_GET_WOWLAN
,
6070 .doit
= nl80211_get_wowlan
,
6071 .policy
= nl80211_policy
,
6072 /* can be retrieved by unprivileged users */
6073 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
6074 NL80211_FLAG_NEED_RTNL
,
6077 .cmd
= NL80211_CMD_SET_WOWLAN
,
6078 .doit
= nl80211_set_wowlan
,
6079 .policy
= nl80211_policy
,
6080 .flags
= GENL_ADMIN_PERM
,
6081 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
6082 NL80211_FLAG_NEED_RTNL
,
6085 .cmd
= NL80211_CMD_SET_REKEY_OFFLOAD
,
6086 .doit
= nl80211_set_rekey_data
,
6087 .policy
= nl80211_policy
,
6088 .flags
= GENL_ADMIN_PERM
,
6089 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
6090 NL80211_FLAG_NEED_RTNL
,
6094 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
6098 /* multicast groups */
6099 static struct genl_multicast_group nl80211_config_mcgrp
= {
6102 static struct genl_multicast_group nl80211_scan_mcgrp
= {
6105 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
6106 .name
= "regulatory",
6109 /* notification functions */
6111 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
6113 struct sk_buff
*msg
;
6115 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6119 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
6124 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6125 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
6128 static int nl80211_add_scan_req(struct sk_buff
*msg
,
6129 struct cfg80211_registered_device
*rdev
)
6131 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
6132 struct nlattr
*nest
;
6135 ASSERT_RDEV_LOCK(rdev
);
6140 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
6142 goto nla_put_failure
;
6143 for (i
= 0; i
< req
->n_ssids
; i
++)
6144 NLA_PUT(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
);
6145 nla_nest_end(msg
, nest
);
6147 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
6149 goto nla_put_failure
;
6150 for (i
= 0; i
< req
->n_channels
; i
++)
6151 NLA_PUT_U32(msg
, i
, req
->channels
[i
]->center_freq
);
6152 nla_nest_end(msg
, nest
);
6155 NLA_PUT(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
);
6162 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
6163 struct cfg80211_registered_device
*rdev
,
6164 struct net_device
*netdev
,
6165 u32 pid
, u32 seq
, int flags
,
6170 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
6174 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6175 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6177 /* ignore errors and send incomplete event anyway */
6178 nl80211_add_scan_req(msg
, rdev
);
6180 return genlmsg_end(msg
, hdr
);
6183 genlmsg_cancel(msg
, hdr
);
6188 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
6189 struct cfg80211_registered_device
*rdev
,
6190 struct net_device
*netdev
,
6191 u32 pid
, u32 seq
, int flags
, u32 cmd
)
6195 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
6199 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6200 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6202 return genlmsg_end(msg
, hdr
);
6205 genlmsg_cancel(msg
, hdr
);
6209 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
6210 struct net_device
*netdev
)
6212 struct sk_buff
*msg
;
6214 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
6218 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
6219 NL80211_CMD_TRIGGER_SCAN
) < 0) {
6224 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6225 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6228 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
6229 struct net_device
*netdev
)
6231 struct sk_buff
*msg
;
6233 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6237 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
6238 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
6243 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6244 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6247 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
6248 struct net_device
*netdev
)
6250 struct sk_buff
*msg
;
6252 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6256 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
6257 NL80211_CMD_SCAN_ABORTED
) < 0) {
6262 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6263 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6266 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
6267 struct net_device
*netdev
)
6269 struct sk_buff
*msg
;
6271 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6275 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
6276 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
6281 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6282 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6285 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
6286 struct net_device
*netdev
, u32 cmd
)
6288 struct sk_buff
*msg
;
6290 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
6294 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
6299 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6300 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6304 * This can happen on global regulatory changes or device specific settings
6305 * based on custom world regulatory domains.
6307 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
6309 struct sk_buff
*msg
;
6312 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6316 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
6322 /* Userspace can always count this one always being set */
6323 NLA_PUT_U8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
);
6325 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0')
6326 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6327 NL80211_REGDOM_TYPE_WORLD
);
6328 else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9')
6329 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6330 NL80211_REGDOM_TYPE_CUSTOM_WORLD
);
6331 else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
6333 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6334 NL80211_REGDOM_TYPE_INTERSECTION
);
6336 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6337 NL80211_REGDOM_TYPE_COUNTRY
);
6338 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, request
->alpha2
);
6341 if (wiphy_idx_valid(request
->wiphy_idx
))
6342 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
);
6344 if (genlmsg_end(msg
, hdr
) < 0) {
6350 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
6357 genlmsg_cancel(msg
, hdr
);
6361 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
6362 struct net_device
*netdev
,
6363 const u8
*buf
, size_t len
,
6364 enum nl80211_commands cmd
, gfp_t gfp
)
6366 struct sk_buff
*msg
;
6369 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6373 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
6379 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6380 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6381 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
6383 if (genlmsg_end(msg
, hdr
) < 0) {
6388 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6389 nl80211_mlme_mcgrp
.id
, gfp
);
6393 genlmsg_cancel(msg
, hdr
);
6397 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
6398 struct net_device
*netdev
, const u8
*buf
,
6399 size_t len
, gfp_t gfp
)
6401 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6402 NL80211_CMD_AUTHENTICATE
, gfp
);
6405 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
6406 struct net_device
*netdev
, const u8
*buf
,
6407 size_t len
, gfp_t gfp
)
6409 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6410 NL80211_CMD_ASSOCIATE
, gfp
);
6413 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
6414 struct net_device
*netdev
, const u8
*buf
,
6415 size_t len
, gfp_t gfp
)
6417 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6418 NL80211_CMD_DEAUTHENTICATE
, gfp
);
6421 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
6422 struct net_device
*netdev
, const u8
*buf
,
6423 size_t len
, gfp_t gfp
)
6425 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6426 NL80211_CMD_DISASSOCIATE
, gfp
);
6429 void nl80211_send_unprot_deauth(struct cfg80211_registered_device
*rdev
,
6430 struct net_device
*netdev
, const u8
*buf
,
6431 size_t len
, gfp_t gfp
)
6433 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6434 NL80211_CMD_UNPROT_DEAUTHENTICATE
, gfp
);
6437 void nl80211_send_unprot_disassoc(struct cfg80211_registered_device
*rdev
,
6438 struct net_device
*netdev
, const u8
*buf
,
6439 size_t len
, gfp_t gfp
)
6441 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6442 NL80211_CMD_UNPROT_DISASSOCIATE
, gfp
);
6445 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
6446 struct net_device
*netdev
, int cmd
,
6447 const u8
*addr
, gfp_t gfp
)
6449 struct sk_buff
*msg
;
6452 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6456 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
6462 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6463 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6464 NLA_PUT_FLAG(msg
, NL80211_ATTR_TIMED_OUT
);
6465 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
6467 if (genlmsg_end(msg
, hdr
) < 0) {
6472 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6473 nl80211_mlme_mcgrp
.id
, gfp
);
6477 genlmsg_cancel(msg
, hdr
);
6481 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
6482 struct net_device
*netdev
, const u8
*addr
,
6485 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
6489 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
6490 struct net_device
*netdev
, const u8
*addr
,
6493 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
6497 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
6498 struct net_device
*netdev
, const u8
*bssid
,
6499 const u8
*req_ie
, size_t req_ie_len
,
6500 const u8
*resp_ie
, size_t resp_ie_len
,
6501 u16 status
, gfp_t gfp
)
6503 struct sk_buff
*msg
;
6506 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6510 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
6516 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6517 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6519 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
6520 NLA_PUT_U16(msg
, NL80211_ATTR_STATUS_CODE
, status
);
6522 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
6524 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
6526 if (genlmsg_end(msg
, hdr
) < 0) {
6531 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6532 nl80211_mlme_mcgrp
.id
, gfp
);
6536 genlmsg_cancel(msg
, hdr
);
6541 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
6542 struct net_device
*netdev
, const u8
*bssid
,
6543 const u8
*req_ie
, size_t req_ie_len
,
6544 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
6546 struct sk_buff
*msg
;
6549 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6553 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
6559 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6560 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6561 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
6563 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
6565 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
6567 if (genlmsg_end(msg
, hdr
) < 0) {
6572 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6573 nl80211_mlme_mcgrp
.id
, gfp
);
6577 genlmsg_cancel(msg
, hdr
);
6582 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
6583 struct net_device
*netdev
, u16 reason
,
6584 const u8
*ie
, size_t ie_len
, bool from_ap
)
6586 struct sk_buff
*msg
;
6589 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
6593 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
6599 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6600 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6601 if (from_ap
&& reason
)
6602 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason
);
6604 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
);
6606 NLA_PUT(msg
, NL80211_ATTR_IE
, ie_len
, ie
);
6608 if (genlmsg_end(msg
, hdr
) < 0) {
6613 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6614 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
6618 genlmsg_cancel(msg
, hdr
);
6623 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
6624 struct net_device
*netdev
, const u8
*bssid
,
6627 struct sk_buff
*msg
;
6630 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6634 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
6640 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6641 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6642 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
6644 if (genlmsg_end(msg
, hdr
) < 0) {
6649 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6650 nl80211_mlme_mcgrp
.id
, gfp
);
6654 genlmsg_cancel(msg
, hdr
);
6658 void nl80211_send_new_peer_candidate(struct cfg80211_registered_device
*rdev
,
6659 struct net_device
*netdev
,
6660 const u8
*macaddr
, const u8
* ie
, u8 ie_len
,
6663 struct sk_buff
*msg
;
6666 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6670 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
6676 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6677 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6678 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, macaddr
);
6680 NLA_PUT(msg
, NL80211_ATTR_IE
, ie_len
, ie
);
6682 if (genlmsg_end(msg
, hdr
) < 0) {
6687 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6688 nl80211_mlme_mcgrp
.id
, gfp
);
6692 genlmsg_cancel(msg
, hdr
);
6696 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
6697 struct net_device
*netdev
, const u8
*addr
,
6698 enum nl80211_key_type key_type
, int key_id
,
6699 const u8
*tsc
, gfp_t gfp
)
6701 struct sk_buff
*msg
;
6704 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6708 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
6714 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6715 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6717 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
6718 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
);
6720 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_id
);
6722 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
);
6724 if (genlmsg_end(msg
, hdr
) < 0) {
6729 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6730 nl80211_mlme_mcgrp
.id
, gfp
);
6734 genlmsg_cancel(msg
, hdr
);
6738 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
6739 struct ieee80211_channel
*channel_before
,
6740 struct ieee80211_channel
*channel_after
)
6742 struct sk_buff
*msg
;
6744 struct nlattr
*nl_freq
;
6746 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
6750 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
6757 * Since we are applying the beacon hint to a wiphy we know its
6758 * wiphy_idx is valid
6760 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
));
6763 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
6765 goto nla_put_failure
;
6766 if (nl80211_msg_put_channel(msg
, channel_before
))
6767 goto nla_put_failure
;
6768 nla_nest_end(msg
, nl_freq
);
6771 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
6773 goto nla_put_failure
;
6774 if (nl80211_msg_put_channel(msg
, channel_after
))
6775 goto nla_put_failure
;
6776 nla_nest_end(msg
, nl_freq
);
6778 if (genlmsg_end(msg
, hdr
) < 0) {
6784 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
6791 genlmsg_cancel(msg
, hdr
);
6795 static void nl80211_send_remain_on_chan_event(
6796 int cmd
, struct cfg80211_registered_device
*rdev
,
6797 struct net_device
*netdev
, u64 cookie
,
6798 struct ieee80211_channel
*chan
,
6799 enum nl80211_channel_type channel_type
,
6800 unsigned int duration
, gfp_t gfp
)
6802 struct sk_buff
*msg
;
6805 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6809 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
6815 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6816 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6817 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
);
6818 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, channel_type
);
6819 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
6821 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
)
6822 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, duration
);
6824 if (genlmsg_end(msg
, hdr
) < 0) {
6829 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6830 nl80211_mlme_mcgrp
.id
, gfp
);
6834 genlmsg_cancel(msg
, hdr
);
6838 void nl80211_send_remain_on_channel(struct cfg80211_registered_device
*rdev
,
6839 struct net_device
*netdev
, u64 cookie
,
6840 struct ieee80211_channel
*chan
,
6841 enum nl80211_channel_type channel_type
,
6842 unsigned int duration
, gfp_t gfp
)
6844 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
6845 rdev
, netdev
, cookie
, chan
,
6846 channel_type
, duration
, gfp
);
6849 void nl80211_send_remain_on_channel_cancel(
6850 struct cfg80211_registered_device
*rdev
, struct net_device
*netdev
,
6851 u64 cookie
, struct ieee80211_channel
*chan
,
6852 enum nl80211_channel_type channel_type
, gfp_t gfp
)
6854 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
6855 rdev
, netdev
, cookie
, chan
,
6856 channel_type
, 0, gfp
);
6859 void nl80211_send_sta_event(struct cfg80211_registered_device
*rdev
,
6860 struct net_device
*dev
, const u8
*mac_addr
,
6861 struct station_info
*sinfo
, gfp_t gfp
)
6863 struct sk_buff
*msg
;
6865 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6869 if (nl80211_send_station(msg
, 0, 0, 0, dev
, mac_addr
, sinfo
) < 0) {
6874 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6875 nl80211_mlme_mcgrp
.id
, gfp
);
6878 void nl80211_send_sta_del_event(struct cfg80211_registered_device
*rdev
,
6879 struct net_device
*dev
, const u8
*mac_addr
,
6882 struct sk_buff
*msg
;
6885 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6889 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_STATION
);
6895 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
6896 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
6898 if (genlmsg_end(msg
, hdr
) < 0) {
6903 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6904 nl80211_mlme_mcgrp
.id
, gfp
);
6908 genlmsg_cancel(msg
, hdr
);
6912 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
6913 struct net_device
*netdev
, u32 nlpid
,
6914 int freq
, const u8
*buf
, size_t len
, gfp_t gfp
)
6916 struct sk_buff
*msg
;
6920 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6924 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
6930 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6931 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6932 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
6933 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
6935 err
= genlmsg_end(msg
, hdr
);
6941 err
= genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
6947 genlmsg_cancel(msg
, hdr
);
6952 void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device
*rdev
,
6953 struct net_device
*netdev
, u64 cookie
,
6954 const u8
*buf
, size_t len
, bool ack
,
6957 struct sk_buff
*msg
;
6960 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6964 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
6970 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6971 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6972 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
6973 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
6975 NLA_PUT_FLAG(msg
, NL80211_ATTR_ACK
);
6977 if (genlmsg_end(msg
, hdr
) < 0) {
6982 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
6986 genlmsg_cancel(msg
, hdr
);
6991 nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device
*rdev
,
6992 struct net_device
*netdev
,
6993 enum nl80211_cqm_rssi_threshold_event rssi_event
,
6996 struct sk_buff
*msg
;
6997 struct nlattr
*pinfoattr
;
7000 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7004 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
7010 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7011 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7013 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
7015 goto nla_put_failure
;
7017 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
7020 nla_nest_end(msg
, pinfoattr
);
7022 if (genlmsg_end(msg
, hdr
) < 0) {
7027 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7028 nl80211_mlme_mcgrp
.id
, gfp
);
7032 genlmsg_cancel(msg
, hdr
);
7036 void nl80211_gtk_rekey_notify(struct cfg80211_registered_device
*rdev
,
7037 struct net_device
*netdev
, const u8
*bssid
,
7038 const u8
*replay_ctr
, gfp_t gfp
)
7040 struct sk_buff
*msg
;
7041 struct nlattr
*rekey_attr
;
7044 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7048 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD
);
7054 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7055 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7056 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
7058 rekey_attr
= nla_nest_start(msg
, NL80211_ATTR_REKEY_DATA
);
7060 goto nla_put_failure
;
7062 NLA_PUT(msg
, NL80211_REKEY_DATA_REPLAY_CTR
,
7063 NL80211_REPLAY_CTR_LEN
, replay_ctr
);
7065 nla_nest_end(msg
, rekey_attr
);
7067 if (genlmsg_end(msg
, hdr
) < 0) {
7072 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7073 nl80211_mlme_mcgrp
.id
, gfp
);
7077 genlmsg_cancel(msg
, hdr
);
7082 nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device
*rdev
,
7083 struct net_device
*netdev
, const u8
*peer
,
7084 u32 num_packets
, gfp_t gfp
)
7086 struct sk_buff
*msg
;
7087 struct nlattr
*pinfoattr
;
7090 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
7094 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
7100 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
7101 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
7102 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
);
7104 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
7106 goto nla_put_failure
;
7108 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
);
7110 nla_nest_end(msg
, pinfoattr
);
7112 if (genlmsg_end(msg
, hdr
) < 0) {
7117 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
7118 nl80211_mlme_mcgrp
.id
, gfp
);
7122 genlmsg_cancel(msg
, hdr
);
7126 static int nl80211_netlink_notify(struct notifier_block
* nb
,
7127 unsigned long state
,
7130 struct netlink_notify
*notify
= _notify
;
7131 struct cfg80211_registered_device
*rdev
;
7132 struct wireless_dev
*wdev
;
7134 if (state
!= NETLINK_URELEASE
)
7139 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
)
7140 list_for_each_entry_rcu(wdev
, &rdev
->netdev_list
, list
)
7141 cfg80211_mlme_unregister_socket(wdev
, notify
->pid
);
7148 static struct notifier_block nl80211_netlink_notifier
= {
7149 .notifier_call
= nl80211_netlink_notify
,
7152 /* initialisation/exit functions */
7154 int nl80211_init(void)
7158 err
= genl_register_family_with_ops(&nl80211_fam
,
7159 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
7163 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
7167 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
7171 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
7175 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
7179 #ifdef CONFIG_NL80211_TESTMODE
7180 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
7185 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
7191 genl_unregister_family(&nl80211_fam
);
7195 void nl80211_exit(void)
7197 netlink_unregister_notifier(&nl80211_netlink_notifier
);
7198 genl_unregister_family(&nl80211_fam
);