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
] = { .len
= ETH_ALEN
},
87 [NL80211_ATTR_PREV_BSSID
] = { .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
] = { .len
= NL80211_HT_CAPABILITY_LEN
},
131 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
132 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
133 .len
= IEEE80211_MAX_DATA_LEN
},
134 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
135 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
137 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
138 .len
= IEEE80211_MAX_SSID_LEN
},
139 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
140 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
141 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
142 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
143 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
144 [NL80211_ATTR_STA_FLAGS2
] = {
145 .len
= sizeof(struct nl80211_sta_flag_update
),
147 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
148 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE
] = { .type
= NLA_U16
},
149 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
] = { .type
= NLA_FLAG
},
150 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
151 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
152 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
153 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
154 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
155 [NL80211_ATTR_PMKID
] = { .type
= NLA_BINARY
,
156 .len
= WLAN_PMKID_LEN
},
157 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
158 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
159 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
160 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
161 .len
= IEEE80211_MAX_DATA_LEN
},
162 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
163 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
164 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
165 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
166 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
167 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
168 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
169 [NL80211_ATTR_FRAME_TYPE
] = { .type
= NLA_U16
},
170 [NL80211_ATTR_WIPHY_ANTENNA_TX
] = { .type
= NLA_U32
},
171 [NL80211_ATTR_WIPHY_ANTENNA_RX
] = { .type
= NLA_U32
},
172 [NL80211_ATTR_MCAST_RATE
] = { .type
= NLA_U32
},
173 [NL80211_ATTR_OFFCHANNEL_TX_OK
] = { .type
= NLA_FLAG
},
174 [NL80211_ATTR_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
175 [NL80211_ATTR_WOWLAN_TRIGGERS
] = { .type
= NLA_NESTED
},
176 [NL80211_ATTR_STA_PLINK_STATE
] = { .type
= NLA_U8
},
177 [NL80211_ATTR_SCHED_SCAN_INTERVAL
] = { .type
= NLA_U32
},
180 /* policy for the key attributes */
181 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
182 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
183 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
184 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
185 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 8 },
186 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
187 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
188 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
189 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
192 /* policy for the key default flags */
193 static const struct nla_policy
194 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
195 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
196 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
199 /* policy for WoWLAN attributes */
200 static const struct nla_policy
201 nl80211_wowlan_policy
[NUM_NL80211_WOWLAN_TRIG
] = {
202 [NL80211_WOWLAN_TRIG_ANY
] = { .type
= NLA_FLAG
},
203 [NL80211_WOWLAN_TRIG_DISCONNECT
] = { .type
= NLA_FLAG
},
204 [NL80211_WOWLAN_TRIG_MAGIC_PKT
] = { .type
= NLA_FLAG
},
205 [NL80211_WOWLAN_TRIG_PKT_PATTERN
] = { .type
= NLA_NESTED
},
208 /* ifidx get helper */
209 static int nl80211_get_ifidx(struct netlink_callback
*cb
)
213 res
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
214 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
219 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
222 res
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
228 static int nl80211_prepare_netdev_dump(struct sk_buff
*skb
,
229 struct netlink_callback
*cb
,
230 struct cfg80211_registered_device
**rdev
,
231 struct net_device
**dev
)
233 int ifidx
= cb
->args
[0];
237 ifidx
= nl80211_get_ifidx(cb
);
245 *dev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
251 *rdev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
253 err
= PTR_ERR(*rdev
);
263 static void nl80211_finish_netdev_dump(struct cfg80211_registered_device
*rdev
)
265 cfg80211_unlock_rdev(rdev
);
270 static bool is_valid_ie_attr(const struct nlattr
*attr
)
278 pos
= nla_data(attr
);
299 /* message building helper */
300 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 pid
, u32 seq
,
303 /* since there is no private header just add the generic one */
304 return genlmsg_put(skb
, pid
, seq
, &nl80211_fam
, flags
, cmd
);
307 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
308 struct ieee80211_channel
*chan
)
310 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
313 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
314 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_DISABLED
);
315 if (chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
316 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
);
317 if (chan
->flags
& IEEE80211_CHAN_NO_IBSS
)
318 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
);
319 if (chan
->flags
& IEEE80211_CHAN_RADAR
)
320 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_RADAR
);
322 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
323 DBM_TO_MBM(chan
->max_power
));
331 /* netlink command implementations */
338 bool def_uni
, def_multi
;
341 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
343 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
344 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
349 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
350 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
359 if (tb
[NL80211_KEY_IDX
])
360 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
362 if (tb
[NL80211_KEY_DATA
]) {
363 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
364 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
367 if (tb
[NL80211_KEY_SEQ
]) {
368 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
369 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
372 if (tb
[NL80211_KEY_CIPHER
])
373 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
375 if (tb
[NL80211_KEY_TYPE
]) {
376 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
377 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
381 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
382 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
383 int err
= nla_parse_nested(kdt
,
384 NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
385 tb
[NL80211_KEY_DEFAULT_TYPES
],
386 nl80211_key_default_policy
);
390 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
391 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
397 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
399 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
400 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
401 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
404 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
405 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
406 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
409 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
410 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
412 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
413 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
415 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
416 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
425 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
426 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
427 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
431 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
432 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
433 int err
= nla_parse_nested(
434 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
435 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
436 nl80211_key_default_policy
);
440 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
441 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
447 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
451 memset(k
, 0, sizeof(*k
));
455 if (info
->attrs
[NL80211_ATTR_KEY
])
456 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
458 err
= nl80211_parse_key_old(info
, k
);
463 if (k
->def
&& k
->defmgmt
)
467 if (k
->def_uni
|| !k
->def_multi
)
473 if (k
->idx
< 4 || k
->idx
> 5)
476 if (k
->idx
< 0 || k
->idx
> 3)
479 if (k
->idx
< 0 || k
->idx
> 5)
487 static struct cfg80211_cached_keys
*
488 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
491 struct key_parse parse
;
493 struct cfg80211_cached_keys
*result
;
494 int rem
, err
, def
= 0;
496 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
498 return ERR_PTR(-ENOMEM
);
501 result
->defmgmt
= -1;
503 nla_for_each_nested(key
, keys
, rem
) {
504 memset(&parse
, 0, sizeof(parse
));
507 err
= nl80211_parse_key_new(key
, &parse
);
513 if (parse
.idx
< 0 || parse
.idx
> 4)
519 result
->def
= parse
.idx
;
520 if (!parse
.def_uni
|| !parse
.def_multi
)
522 } else if (parse
.defmgmt
)
524 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
525 parse
.idx
, false, NULL
);
528 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
529 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
530 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
531 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
540 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
542 ASSERT_WDEV_LOCK(wdev
);
544 switch (wdev
->iftype
) {
545 case NL80211_IFTYPE_AP
:
546 case NL80211_IFTYPE_AP_VLAN
:
547 case NL80211_IFTYPE_P2P_GO
:
548 case NL80211_IFTYPE_MESH_POINT
:
550 case NL80211_IFTYPE_ADHOC
:
551 if (!wdev
->current_bss
)
554 case NL80211_IFTYPE_STATION
:
555 case NL80211_IFTYPE_P2P_CLIENT
:
556 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
566 static int nl80211_put_iftypes(struct sk_buff
*msg
, u32 attr
, u16 ifmodes
)
568 struct nlattr
*nl_modes
= nla_nest_start(msg
, attr
);
572 goto nla_put_failure
;
577 NLA_PUT_FLAG(msg
, i
);
582 nla_nest_end(msg
, nl_modes
);
589 static int nl80211_put_iface_combinations(struct wiphy
*wiphy
,
592 struct nlattr
*nl_combis
;
595 nl_combis
= nla_nest_start(msg
,
596 NL80211_ATTR_INTERFACE_COMBINATIONS
);
598 goto nla_put_failure
;
600 for (i
= 0; i
< wiphy
->n_iface_combinations
; i
++) {
601 const struct ieee80211_iface_combination
*c
;
602 struct nlattr
*nl_combi
, *nl_limits
;
604 c
= &wiphy
->iface_combinations
[i
];
606 nl_combi
= nla_nest_start(msg
, i
+ 1);
608 goto nla_put_failure
;
610 nl_limits
= nla_nest_start(msg
, NL80211_IFACE_COMB_LIMITS
);
612 goto nla_put_failure
;
614 for (j
= 0; j
< c
->n_limits
; j
++) {
615 struct nlattr
*nl_limit
;
617 nl_limit
= nla_nest_start(msg
, j
+ 1);
619 goto nla_put_failure
;
620 NLA_PUT_U32(msg
, NL80211_IFACE_LIMIT_MAX
,
622 if (nl80211_put_iftypes(msg
, NL80211_IFACE_LIMIT_TYPES
,
624 goto nla_put_failure
;
625 nla_nest_end(msg
, nl_limit
);
628 nla_nest_end(msg
, nl_limits
);
630 if (c
->beacon_int_infra_match
)
632 NL80211_IFACE_COMB_STA_AP_BI_MATCH
);
633 NLA_PUT_U32(msg
, NL80211_IFACE_COMB_NUM_CHANNELS
,
634 c
->num_different_channels
);
635 NLA_PUT_U32(msg
, NL80211_IFACE_COMB_MAXNUM
,
638 nla_nest_end(msg
, nl_combi
);
641 nla_nest_end(msg
, nl_combis
);
648 static int nl80211_send_wiphy(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
649 struct cfg80211_registered_device
*dev
)
652 struct nlattr
*nl_bands
, *nl_band
;
653 struct nlattr
*nl_freqs
, *nl_freq
;
654 struct nlattr
*nl_rates
, *nl_rate
;
655 struct nlattr
*nl_cmds
;
656 enum ieee80211_band band
;
657 struct ieee80211_channel
*chan
;
658 struct ieee80211_rate
*rate
;
660 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
661 dev
->wiphy
.mgmt_stypes
;
663 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
667 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
);
668 NLA_PUT_STRING(msg
, NL80211_ATTR_WIPHY_NAME
, wiphy_name(&dev
->wiphy
));
670 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
671 cfg80211_rdev_list_generation
);
673 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
674 dev
->wiphy
.retry_short
);
675 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
676 dev
->wiphy
.retry_long
);
677 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
678 dev
->wiphy
.frag_threshold
);
679 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
680 dev
->wiphy
.rts_threshold
);
681 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
682 dev
->wiphy
.coverage_class
);
683 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
684 dev
->wiphy
.max_scan_ssids
);
685 NLA_PUT_U16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
686 dev
->wiphy
.max_scan_ie_len
);
688 if (dev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
)
689 NLA_PUT_FLAG(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
);
690 if (dev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
)
691 NLA_PUT_FLAG(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
);
693 NLA_PUT(msg
, NL80211_ATTR_CIPHER_SUITES
,
694 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
695 dev
->wiphy
.cipher_suites
);
697 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
698 dev
->wiphy
.max_num_pmkids
);
700 if (dev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
)
701 NLA_PUT_FLAG(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
);
703 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
704 dev
->wiphy
.available_antennas_tx
);
705 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
706 dev
->wiphy
.available_antennas_rx
);
708 if ((dev
->wiphy
.available_antennas_tx
||
709 dev
->wiphy
.available_antennas_rx
) && dev
->ops
->get_antenna
) {
710 u32 tx_ant
= 0, rx_ant
= 0;
712 res
= dev
->ops
->get_antenna(&dev
->wiphy
, &tx_ant
, &rx_ant
);
714 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_TX
, tx_ant
);
715 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_RX
, rx_ant
);
719 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
,
720 dev
->wiphy
.interface_modes
))
721 goto nla_put_failure
;
723 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
725 goto nla_put_failure
;
727 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
728 if (!dev
->wiphy
.bands
[band
])
731 nl_band
= nla_nest_start(msg
, band
);
733 goto nla_put_failure
;
736 if (dev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
) {
737 NLA_PUT(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
738 sizeof(dev
->wiphy
.bands
[band
]->ht_cap
.mcs
),
739 &dev
->wiphy
.bands
[band
]->ht_cap
.mcs
);
740 NLA_PUT_U16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
741 dev
->wiphy
.bands
[band
]->ht_cap
.cap
);
742 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
743 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_factor
);
744 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
745 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_density
);
748 /* add frequencies */
749 nl_freqs
= nla_nest_start(msg
, NL80211_BAND_ATTR_FREQS
);
751 goto nla_put_failure
;
753 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_channels
; i
++) {
754 nl_freq
= nla_nest_start(msg
, i
);
756 goto nla_put_failure
;
758 chan
= &dev
->wiphy
.bands
[band
]->channels
[i
];
760 if (nl80211_msg_put_channel(msg
, chan
))
761 goto nla_put_failure
;
763 nla_nest_end(msg
, nl_freq
);
766 nla_nest_end(msg
, nl_freqs
);
769 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
771 goto nla_put_failure
;
773 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_bitrates
; i
++) {
774 nl_rate
= nla_nest_start(msg
, i
);
776 goto nla_put_failure
;
778 rate
= &dev
->wiphy
.bands
[band
]->bitrates
[i
];
779 NLA_PUT_U32(msg
, NL80211_BITRATE_ATTR_RATE
,
781 if (rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
)
783 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
);
785 nla_nest_end(msg
, nl_rate
);
788 nla_nest_end(msg
, nl_rates
);
790 nla_nest_end(msg
, nl_band
);
792 nla_nest_end(msg
, nl_bands
);
794 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
796 goto nla_put_failure
;
801 if (dev->ops->op) { \
803 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
807 CMD(add_virtual_intf
, NEW_INTERFACE
);
808 CMD(change_virtual_intf
, SET_INTERFACE
);
809 CMD(add_key
, NEW_KEY
);
810 CMD(add_beacon
, NEW_BEACON
);
811 CMD(add_station
, NEW_STATION
);
812 CMD(add_mpath
, NEW_MPATH
);
813 CMD(update_mesh_config
, SET_MESH_CONFIG
);
814 CMD(change_bss
, SET_BSS
);
815 CMD(auth
, AUTHENTICATE
);
816 CMD(assoc
, ASSOCIATE
);
817 CMD(deauth
, DEAUTHENTICATE
);
818 CMD(disassoc
, DISASSOCIATE
);
819 CMD(join_ibss
, JOIN_IBSS
);
820 CMD(join_mesh
, JOIN_MESH
);
821 CMD(set_pmksa
, SET_PMKSA
);
822 CMD(del_pmksa
, DEL_PMKSA
);
823 CMD(flush_pmksa
, FLUSH_PMKSA
);
824 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
825 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
827 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
828 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
830 NLA_PUT_U32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
);
832 CMD(set_channel
, SET_CHANNEL
);
833 CMD(set_wds_peer
, SET_WDS_PEER
);
834 if (dev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
)
835 CMD(sched_scan_start
, START_SCHED_SCAN
);
839 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
841 NLA_PUT_U32(msg
, i
, NL80211_CMD_CONNECT
);
844 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
846 NLA_PUT_U32(msg
, i
, NL80211_CMD_DISCONNECT
);
849 nla_nest_end(msg
, nl_cmds
);
851 if (dev
->ops
->remain_on_channel
)
852 NLA_PUT_U32(msg
, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
853 dev
->wiphy
.max_remain_on_channel_duration
);
855 /* for now at least assume all drivers have it */
856 if (dev
->ops
->mgmt_tx
)
857 NLA_PUT_FLAG(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
);
861 struct nlattr
*nl_ftypes
, *nl_ifs
;
862 enum nl80211_iftype ift
;
864 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
866 goto nla_put_failure
;
868 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
869 nl_ftypes
= nla_nest_start(msg
, ift
);
871 goto nla_put_failure
;
873 stypes
= mgmt_stypes
[ift
].tx
;
876 NLA_PUT_U16(msg
, NL80211_ATTR_FRAME_TYPE
,
877 (i
<< 4) | IEEE80211_FTYPE_MGMT
);
881 nla_nest_end(msg
, nl_ftypes
);
884 nla_nest_end(msg
, nl_ifs
);
886 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
888 goto nla_put_failure
;
890 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
891 nl_ftypes
= nla_nest_start(msg
, ift
);
893 goto nla_put_failure
;
895 stypes
= mgmt_stypes
[ift
].rx
;
898 NLA_PUT_U16(msg
, NL80211_ATTR_FRAME_TYPE
,
899 (i
<< 4) | IEEE80211_FTYPE_MGMT
);
903 nla_nest_end(msg
, nl_ftypes
);
905 nla_nest_end(msg
, nl_ifs
);
908 if (dev
->wiphy
.wowlan
.flags
|| dev
->wiphy
.wowlan
.n_patterns
) {
909 struct nlattr
*nl_wowlan
;
911 nl_wowlan
= nla_nest_start(msg
,
912 NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED
);
914 goto nla_put_failure
;
916 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_ANY
)
917 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_ANY
);
918 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_DISCONNECT
)
919 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
);
920 if (dev
->wiphy
.wowlan
.flags
& WIPHY_WOWLAN_MAGIC_PKT
)
921 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
);
922 if (dev
->wiphy
.wowlan
.n_patterns
) {
923 struct nl80211_wowlan_pattern_support pat
= {
924 .max_patterns
= dev
->wiphy
.wowlan
.n_patterns
,
926 dev
->wiphy
.wowlan
.pattern_min_len
,
928 dev
->wiphy
.wowlan
.pattern_max_len
,
930 NLA_PUT(msg
, NL80211_WOWLAN_TRIG_PKT_PATTERN
,
934 nla_nest_end(msg
, nl_wowlan
);
937 if (nl80211_put_iftypes(msg
, NL80211_ATTR_SOFTWARE_IFTYPES
,
938 dev
->wiphy
.software_iftypes
))
939 goto nla_put_failure
;
941 if (nl80211_put_iface_combinations(&dev
->wiphy
, msg
))
942 goto nla_put_failure
;
944 return genlmsg_end(msg
, hdr
);
947 genlmsg_cancel(msg
, hdr
);
951 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
954 int start
= cb
->args
[0];
955 struct cfg80211_registered_device
*dev
;
957 mutex_lock(&cfg80211_mutex
);
958 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
959 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
963 if (nl80211_send_wiphy(skb
, NETLINK_CB(cb
->skb
).pid
,
964 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
970 mutex_unlock(&cfg80211_mutex
);
977 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
980 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
982 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
986 if (nl80211_send_wiphy(msg
, info
->snd_pid
, info
->snd_seq
, 0, dev
) < 0) {
991 return genlmsg_reply(msg
, info
);
994 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
995 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
996 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
997 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
998 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
999 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
1002 static int parse_txq_params(struct nlattr
*tb
[],
1003 struct ieee80211_txq_params
*txq_params
)
1005 if (!tb
[NL80211_TXQ_ATTR_QUEUE
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
1006 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
1007 !tb
[NL80211_TXQ_ATTR_AIFS
])
1010 txq_params
->queue
= nla_get_u8(tb
[NL80211_TXQ_ATTR_QUEUE
]);
1011 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
1012 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
1013 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
1014 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
1019 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
1022 * You can only set the channel explicitly for AP, mesh
1023 * and WDS type interfaces; all others have their channel
1024 * managed via their respective "establish a connection"
1025 * command (connect, join, ...)
1027 * Monitors are special as they are normally slaved to
1028 * whatever else is going on, so they behave as though
1029 * you tried setting the wiphy channel itself.
1032 wdev
->iftype
== NL80211_IFTYPE_AP
||
1033 wdev
->iftype
== NL80211_IFTYPE_WDS
||
1034 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
1035 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
1036 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
1039 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
1040 struct wireless_dev
*wdev
,
1041 struct genl_info
*info
)
1043 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
1047 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
1050 if (!nl80211_can_set_dev_channel(wdev
))
1053 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
1054 channel_type
= nla_get_u32(info
->attrs
[
1055 NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
1056 if (channel_type
!= NL80211_CHAN_NO_HT
&&
1057 channel_type
!= NL80211_CHAN_HT20
&&
1058 channel_type
!= NL80211_CHAN_HT40PLUS
&&
1059 channel_type
!= NL80211_CHAN_HT40MINUS
)
1063 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
1065 mutex_lock(&rdev
->devlist_mtx
);
1068 result
= cfg80211_set_freq(rdev
, wdev
, freq
, channel_type
);
1071 result
= cfg80211_set_freq(rdev
, NULL
, freq
, channel_type
);
1073 mutex_unlock(&rdev
->devlist_mtx
);
1078 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
1080 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1081 struct net_device
*netdev
= info
->user_ptr
[1];
1083 return __nl80211_set_channel(rdev
, netdev
->ieee80211_ptr
, info
);
1086 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
1088 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1089 struct net_device
*dev
= info
->user_ptr
[1];
1090 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1093 if (!info
->attrs
[NL80211_ATTR_MAC
])
1096 if (netif_running(dev
))
1099 if (!rdev
->ops
->set_wds_peer
)
1102 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
1105 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1106 return rdev
->ops
->set_wds_peer(wdev
->wiphy
, dev
, bssid
);
1110 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
1112 struct cfg80211_registered_device
*rdev
;
1113 struct net_device
*netdev
= NULL
;
1114 struct wireless_dev
*wdev
;
1115 int result
= 0, rem_txq_params
= 0;
1116 struct nlattr
*nl_txq_params
;
1118 u8 retry_short
= 0, retry_long
= 0;
1119 u32 frag_threshold
= 0, rts_threshold
= 0;
1120 u8 coverage_class
= 0;
1123 * Try to find the wiphy and netdev. Normally this
1124 * function shouldn't need the netdev, but this is
1125 * done for backward compatibility -- previously
1126 * setting the channel was done per wiphy, but now
1127 * it is per netdev. Previous userland like hostapd
1128 * also passed a netdev to set_wiphy, so that it is
1129 * possible to let that go to the right netdev!
1131 mutex_lock(&cfg80211_mutex
);
1133 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
1134 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
1136 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
1137 if (netdev
&& netdev
->ieee80211_ptr
) {
1138 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
1139 mutex_lock(&rdev
->mtx
);
1145 rdev
= __cfg80211_rdev_from_info(info
);
1147 mutex_unlock(&cfg80211_mutex
);
1148 return PTR_ERR(rdev
);
1154 mutex_lock(&rdev
->mtx
);
1155 } else if (netif_running(netdev
) &&
1156 nl80211_can_set_dev_channel(netdev
->ieee80211_ptr
))
1157 wdev
= netdev
->ieee80211_ptr
;
1162 * end workaround code, by now the rdev is available
1163 * and locked, and wdev may or may not be NULL.
1166 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
1167 result
= cfg80211_dev_rename(
1168 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
1170 mutex_unlock(&cfg80211_mutex
);
1175 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
1176 struct ieee80211_txq_params txq_params
;
1177 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
1179 if (!rdev
->ops
->set_txq_params
) {
1180 result
= -EOPNOTSUPP
;
1184 if (!netif_running(netdev
)) {
1189 nla_for_each_nested(nl_txq_params
,
1190 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
1192 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
1193 nla_data(nl_txq_params
),
1194 nla_len(nl_txq_params
),
1196 result
= parse_txq_params(tb
, &txq_params
);
1200 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
1207 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
1208 result
= __nl80211_set_channel(rdev
, wdev
, info
);
1213 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
1214 enum nl80211_tx_power_setting type
;
1217 if (!rdev
->ops
->set_tx_power
) {
1218 result
= -EOPNOTSUPP
;
1222 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
1223 type
= nla_get_u32(info
->attrs
[idx
]);
1225 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
1226 (type
!= NL80211_TX_POWER_AUTOMATIC
)) {
1231 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
1232 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
1233 mbm
= nla_get_u32(info
->attrs
[idx
]);
1236 result
= rdev
->ops
->set_tx_power(&rdev
->wiphy
, type
, mbm
);
1241 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
1242 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
1244 if ((!rdev
->wiphy
.available_antennas_tx
&&
1245 !rdev
->wiphy
.available_antennas_rx
) ||
1246 !rdev
->ops
->set_antenna
) {
1247 result
= -EOPNOTSUPP
;
1251 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
1252 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
1254 /* reject antenna configurations which don't match the
1255 * available antenna masks, except for the "all" mask */
1256 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
1257 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
))) {
1262 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
1263 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
1265 result
= rdev
->ops
->set_antenna(&rdev
->wiphy
, tx_ant
, rx_ant
);
1272 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
1273 retry_short
= nla_get_u8(
1274 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
1275 if (retry_short
== 0) {
1279 changed
|= WIPHY_PARAM_RETRY_SHORT
;
1282 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
1283 retry_long
= nla_get_u8(
1284 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
1285 if (retry_long
== 0) {
1289 changed
|= WIPHY_PARAM_RETRY_LONG
;
1292 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
1293 frag_threshold
= nla_get_u32(
1294 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
1295 if (frag_threshold
< 256) {
1299 if (frag_threshold
!= (u32
) -1) {
1301 * Fragments (apart from the last one) are required to
1302 * have even length. Make the fragmentation code
1303 * simpler by stripping LSB should someone try to use
1304 * odd threshold value.
1306 frag_threshold
&= ~0x1;
1308 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
1311 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
1312 rts_threshold
= nla_get_u32(
1313 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
1314 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
1317 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
1318 coverage_class
= nla_get_u8(
1319 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
1320 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
1324 u8 old_retry_short
, old_retry_long
;
1325 u32 old_frag_threshold
, old_rts_threshold
;
1326 u8 old_coverage_class
;
1328 if (!rdev
->ops
->set_wiphy_params
) {
1329 result
= -EOPNOTSUPP
;
1333 old_retry_short
= rdev
->wiphy
.retry_short
;
1334 old_retry_long
= rdev
->wiphy
.retry_long
;
1335 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
1336 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
1337 old_coverage_class
= rdev
->wiphy
.coverage_class
;
1339 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
1340 rdev
->wiphy
.retry_short
= retry_short
;
1341 if (changed
& WIPHY_PARAM_RETRY_LONG
)
1342 rdev
->wiphy
.retry_long
= retry_long
;
1343 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
1344 rdev
->wiphy
.frag_threshold
= frag_threshold
;
1345 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
1346 rdev
->wiphy
.rts_threshold
= rts_threshold
;
1347 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
1348 rdev
->wiphy
.coverage_class
= coverage_class
;
1350 result
= rdev
->ops
->set_wiphy_params(&rdev
->wiphy
, changed
);
1352 rdev
->wiphy
.retry_short
= old_retry_short
;
1353 rdev
->wiphy
.retry_long
= old_retry_long
;
1354 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
1355 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
1356 rdev
->wiphy
.coverage_class
= old_coverage_class
;
1361 mutex_unlock(&rdev
->mtx
);
1368 static int nl80211_send_iface(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
1369 struct cfg80211_registered_device
*rdev
,
1370 struct net_device
*dev
)
1374 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
1378 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1379 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
1380 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, dev
->name
);
1381 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, dev
->ieee80211_ptr
->iftype
);
1383 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
1384 rdev
->devlist_generation
^
1385 (cfg80211_rdev_list_generation
<< 2));
1387 return genlmsg_end(msg
, hdr
);
1390 genlmsg_cancel(msg
, hdr
);
1394 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1398 int wp_start
= cb
->args
[0];
1399 int if_start
= cb
->args
[1];
1400 struct cfg80211_registered_device
*rdev
;
1401 struct wireless_dev
*wdev
;
1403 mutex_lock(&cfg80211_mutex
);
1404 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
1405 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
1407 if (wp_idx
< wp_start
) {
1413 mutex_lock(&rdev
->devlist_mtx
);
1414 list_for_each_entry(wdev
, &rdev
->netdev_list
, list
) {
1415 if (if_idx
< if_start
) {
1419 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).pid
,
1420 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1421 rdev
, wdev
->netdev
) < 0) {
1422 mutex_unlock(&rdev
->devlist_mtx
);
1427 mutex_unlock(&rdev
->devlist_mtx
);
1432 mutex_unlock(&cfg80211_mutex
);
1434 cb
->args
[0] = wp_idx
;
1435 cb
->args
[1] = if_idx
;
1440 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1442 struct sk_buff
*msg
;
1443 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1444 struct net_device
*netdev
= info
->user_ptr
[1];
1446 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1450 if (nl80211_send_iface(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1456 return genlmsg_reply(msg
, info
);
1459 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
1460 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
1461 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
1462 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
1463 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
1464 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
1467 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
1469 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
1477 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
1478 nla
, mntr_flags_policy
))
1481 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
1483 *mntrflags
|= (1<<flag
);
1488 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
1489 struct net_device
*netdev
, u8 use_4addr
,
1490 enum nl80211_iftype iftype
)
1493 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
1499 case NL80211_IFTYPE_AP_VLAN
:
1500 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
1503 case NL80211_IFTYPE_STATION
:
1504 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
1514 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1516 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1517 struct vif_params params
;
1519 enum nl80211_iftype otype
, ntype
;
1520 struct net_device
*dev
= info
->user_ptr
[1];
1521 u32 _flags
, *flags
= NULL
;
1522 bool change
= false;
1524 memset(¶ms
, 0, sizeof(params
));
1526 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
1528 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1529 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1532 if (ntype
> NL80211_IFTYPE_MAX
)
1536 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1537 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1539 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
1541 if (netif_running(dev
))
1545 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
1546 IEEE80211_MAX_MESH_ID_LEN
);
1547 wdev
->mesh_id_up_len
=
1548 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1549 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
1550 wdev
->mesh_id_up_len
);
1554 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1555 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1557 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
1561 params
.use_4addr
= -1;
1564 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
1565 if (ntype
!= NL80211_IFTYPE_MONITOR
)
1567 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
1577 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
1581 if (!err
&& params
.use_4addr
!= -1)
1582 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
1587 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1589 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1590 struct vif_params params
;
1591 struct net_device
*dev
;
1593 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
1596 memset(¶ms
, 0, sizeof(params
));
1598 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
1601 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1602 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1603 if (type
> NL80211_IFTYPE_MAX
)
1607 if (!rdev
->ops
->add_virtual_intf
||
1608 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
1611 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1612 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1613 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
1618 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
1619 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
1621 dev
= rdev
->ops
->add_virtual_intf(&rdev
->wiphy
,
1622 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
1623 type
, err
? NULL
: &flags
, ¶ms
);
1625 return PTR_ERR(dev
);
1627 if (type
== NL80211_IFTYPE_MESH_POINT
&&
1628 info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1629 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1632 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
1633 IEEE80211_MAX_MESH_ID_LEN
);
1634 wdev
->mesh_id_up_len
=
1635 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1636 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
1637 wdev
->mesh_id_up_len
);
1644 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1646 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1647 struct net_device
*dev
= info
->user_ptr
[1];
1649 if (!rdev
->ops
->del_virtual_intf
)
1652 return rdev
->ops
->del_virtual_intf(&rdev
->wiphy
, dev
);
1655 struct get_key_cookie
{
1656 struct sk_buff
*msg
;
1661 static void get_key_callback(void *c
, struct key_params
*params
)
1664 struct get_key_cookie
*cookie
= c
;
1667 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
1668 params
->key_len
, params
->key
);
1671 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
1672 params
->seq_len
, params
->seq
);
1675 NLA_PUT_U32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
1678 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
1680 goto nla_put_failure
;
1683 NLA_PUT(cookie
->msg
, NL80211_KEY_DATA
,
1684 params
->key_len
, params
->key
);
1687 NLA_PUT(cookie
->msg
, NL80211_KEY_SEQ
,
1688 params
->seq_len
, params
->seq
);
1691 NLA_PUT_U32(cookie
->msg
, NL80211_KEY_CIPHER
,
1694 NLA_PUT_U8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
);
1696 nla_nest_end(cookie
->msg
, key
);
1703 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
1705 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1707 struct net_device
*dev
= info
->user_ptr
[1];
1709 const u8
*mac_addr
= NULL
;
1711 struct get_key_cookie cookie
= {
1715 struct sk_buff
*msg
;
1717 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
1718 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1723 if (info
->attrs
[NL80211_ATTR_MAC
])
1724 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1726 pairwise
= !!mac_addr
;
1727 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
1728 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
1729 if (kt
>= NUM_NL80211_KEYTYPES
)
1731 if (kt
!= NL80211_KEYTYPE_GROUP
&&
1732 kt
!= NL80211_KEYTYPE_PAIRWISE
)
1734 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
1737 if (!rdev
->ops
->get_key
)
1740 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1744 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1745 NL80211_CMD_NEW_KEY
);
1747 return PTR_ERR(hdr
);
1750 cookie
.idx
= key_idx
;
1752 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1753 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
1755 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1757 if (pairwise
&& mac_addr
&&
1758 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
1761 err
= rdev
->ops
->get_key(&rdev
->wiphy
, dev
, key_idx
, pairwise
,
1762 mac_addr
, &cookie
, get_key_callback
);
1768 goto nla_put_failure
;
1770 genlmsg_end(msg
, hdr
);
1771 return genlmsg_reply(msg
, info
);
1780 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
1782 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1783 struct key_parse key
;
1785 struct net_device
*dev
= info
->user_ptr
[1];
1787 err
= nl80211_parse_key(info
, &key
);
1794 /* only support setting default key */
1795 if (!key
.def
&& !key
.defmgmt
)
1798 wdev_lock(dev
->ieee80211_ptr
);
1801 if (!rdev
->ops
->set_default_key
) {
1806 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1810 err
= rdev
->ops
->set_default_key(&rdev
->wiphy
, dev
, key
.idx
,
1811 key
.def_uni
, key
.def_multi
);
1816 #ifdef CONFIG_CFG80211_WEXT
1817 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
1820 if (key
.def_uni
|| !key
.def_multi
) {
1825 if (!rdev
->ops
->set_default_mgmt_key
) {
1830 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1834 err
= rdev
->ops
->set_default_mgmt_key(&rdev
->wiphy
,
1839 #ifdef CONFIG_CFG80211_WEXT
1840 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
1845 wdev_unlock(dev
->ieee80211_ptr
);
1850 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
1852 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1854 struct net_device
*dev
= info
->user_ptr
[1];
1855 struct key_parse key
;
1856 const u8
*mac_addr
= NULL
;
1858 err
= nl80211_parse_key(info
, &key
);
1865 if (info
->attrs
[NL80211_ATTR_MAC
])
1866 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1868 if (key
.type
== -1) {
1870 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
1872 key
.type
= NL80211_KEYTYPE_GROUP
;
1876 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
1877 key
.type
!= NL80211_KEYTYPE_GROUP
)
1880 if (!rdev
->ops
->add_key
)
1883 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
1884 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
1888 wdev_lock(dev
->ieee80211_ptr
);
1889 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1891 err
= rdev
->ops
->add_key(&rdev
->wiphy
, dev
, key
.idx
,
1892 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
1894 wdev_unlock(dev
->ieee80211_ptr
);
1899 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
1901 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1903 struct net_device
*dev
= info
->user_ptr
[1];
1904 u8
*mac_addr
= NULL
;
1905 struct key_parse key
;
1907 err
= nl80211_parse_key(info
, &key
);
1911 if (info
->attrs
[NL80211_ATTR_MAC
])
1912 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1914 if (key
.type
== -1) {
1916 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
1918 key
.type
= NL80211_KEYTYPE_GROUP
;
1922 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
1923 key
.type
!= NL80211_KEYTYPE_GROUP
)
1926 if (!rdev
->ops
->del_key
)
1929 wdev_lock(dev
->ieee80211_ptr
);
1930 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1932 if (key
.type
== NL80211_KEYTYPE_PAIRWISE
&& mac_addr
&&
1933 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
1937 err
= rdev
->ops
->del_key(&rdev
->wiphy
, dev
, key
.idx
,
1938 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
1941 #ifdef CONFIG_CFG80211_WEXT
1943 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
1944 dev
->ieee80211_ptr
->wext
.default_key
= -1;
1945 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
1946 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
1949 wdev_unlock(dev
->ieee80211_ptr
);
1954 static int nl80211_addset_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1956 int (*call
)(struct wiphy
*wiphy
, struct net_device
*dev
,
1957 struct beacon_parameters
*info
);
1958 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1959 struct net_device
*dev
= info
->user_ptr
[1];
1960 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1961 struct beacon_parameters params
;
1962 int haveinfo
= 0, err
;
1964 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]))
1967 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1968 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
1971 memset(¶ms
, 0, sizeof(params
));
1973 switch (info
->genlhdr
->cmd
) {
1974 case NL80211_CMD_NEW_BEACON
:
1975 /* these are required for NEW_BEACON */
1976 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
1977 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
1978 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
1982 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
1983 params
.dtim_period
=
1984 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
1986 err
= cfg80211_validate_beacon_int(rdev
, params
.interval
);
1990 call
= rdev
->ops
->add_beacon
;
1992 case NL80211_CMD_SET_BEACON
:
1993 call
= rdev
->ops
->set_beacon
;
2003 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
2004 params
.head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2006 nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2010 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
2011 params
.tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2013 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2020 err
= call(&rdev
->wiphy
, dev
, ¶ms
);
2021 if (!err
&& params
.interval
)
2022 wdev
->beacon_interval
= params
.interval
;
2026 static int nl80211_del_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
2028 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2029 struct net_device
*dev
= info
->user_ptr
[1];
2030 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2033 if (!rdev
->ops
->del_beacon
)
2036 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2037 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2040 err
= rdev
->ops
->del_beacon(&rdev
->wiphy
, dev
);
2042 wdev
->beacon_interval
= 0;
2046 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
2047 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
2048 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
2049 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
2050 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
2051 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
2054 static int parse_station_flags(struct genl_info
*info
,
2055 struct station_parameters
*params
)
2057 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
2062 * Try parsing the new attribute first so userspace
2063 * can specify both for older kernels.
2065 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
2067 struct nl80211_sta_flag_update
*sta_flags
;
2069 sta_flags
= nla_data(nla
);
2070 params
->sta_flags_mask
= sta_flags
->mask
;
2071 params
->sta_flags_set
= sta_flags
->set
;
2072 if ((params
->sta_flags_mask
|
2073 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
2078 /* if present, parse the old attribute */
2080 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
2084 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
2085 nla
, sta_flags_policy
))
2088 params
->sta_flags_mask
= (1 << __NL80211_STA_FLAG_AFTER_LAST
) - 1;
2089 params
->sta_flags_mask
&= ~1;
2091 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++)
2093 params
->sta_flags_set
|= (1<<flag
);
2098 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
2101 struct nlattr
*rate
;
2104 rate
= nla_nest_start(msg
, attr
);
2106 goto nla_put_failure
;
2108 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2109 bitrate
= cfg80211_calculate_bitrate(info
);
2111 NLA_PUT_U16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate
);
2113 if (info
->flags
& RATE_INFO_FLAGS_MCS
)
2114 NLA_PUT_U8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
);
2115 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
)
2116 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
);
2117 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
)
2118 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_SHORT_GI
);
2120 nla_nest_end(msg
, rate
);
2127 static int nl80211_send_station(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2128 int flags
, struct net_device
*dev
,
2129 const u8
*mac_addr
, struct station_info
*sinfo
)
2132 struct nlattr
*sinfoattr
, *bss_param
;
2134 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2138 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2139 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
2141 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
);
2143 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
2145 goto nla_put_failure
;
2146 if (sinfo
->filled
& STATION_INFO_CONNECTED_TIME
)
2147 NLA_PUT_U32(msg
, NL80211_STA_INFO_CONNECTED_TIME
,
2148 sinfo
->connected_time
);
2149 if (sinfo
->filled
& STATION_INFO_INACTIVE_TIME
)
2150 NLA_PUT_U32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
2151 sinfo
->inactive_time
);
2152 if (sinfo
->filled
& STATION_INFO_RX_BYTES
)
2153 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_BYTES
,
2155 if (sinfo
->filled
& STATION_INFO_TX_BYTES
)
2156 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_BYTES
,
2158 if (sinfo
->filled
& STATION_INFO_LLID
)
2159 NLA_PUT_U16(msg
, NL80211_STA_INFO_LLID
,
2161 if (sinfo
->filled
& STATION_INFO_PLID
)
2162 NLA_PUT_U16(msg
, NL80211_STA_INFO_PLID
,
2164 if (sinfo
->filled
& STATION_INFO_PLINK_STATE
)
2165 NLA_PUT_U8(msg
, NL80211_STA_INFO_PLINK_STATE
,
2166 sinfo
->plink_state
);
2167 if (sinfo
->filled
& STATION_INFO_SIGNAL
)
2168 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL
,
2170 if (sinfo
->filled
& STATION_INFO_SIGNAL_AVG
)
2171 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
2173 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
2174 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
2175 NL80211_STA_INFO_TX_BITRATE
))
2176 goto nla_put_failure
;
2178 if (sinfo
->filled
& STATION_INFO_RX_BITRATE
) {
2179 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
2180 NL80211_STA_INFO_RX_BITRATE
))
2181 goto nla_put_failure
;
2183 if (sinfo
->filled
& STATION_INFO_RX_PACKETS
)
2184 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_PACKETS
,
2186 if (sinfo
->filled
& STATION_INFO_TX_PACKETS
)
2187 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_PACKETS
,
2189 if (sinfo
->filled
& STATION_INFO_TX_RETRIES
)
2190 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_RETRIES
,
2192 if (sinfo
->filled
& STATION_INFO_TX_FAILED
)
2193 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_FAILED
,
2195 if (sinfo
->filled
& STATION_INFO_BSS_PARAM
) {
2196 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
2198 goto nla_put_failure
;
2200 if (sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
)
2201 NLA_PUT_FLAG(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
);
2202 if (sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
)
2203 NLA_PUT_FLAG(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
);
2204 if (sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
)
2206 NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
);
2207 NLA_PUT_U8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
2208 sinfo
->bss_param
.dtim_period
);
2209 NLA_PUT_U16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
2210 sinfo
->bss_param
.beacon_interval
);
2212 nla_nest_end(msg
, bss_param
);
2214 nla_nest_end(msg
, sinfoattr
);
2216 return genlmsg_end(msg
, hdr
);
2219 genlmsg_cancel(msg
, hdr
);
2223 static int nl80211_dump_station(struct sk_buff
*skb
,
2224 struct netlink_callback
*cb
)
2226 struct station_info sinfo
;
2227 struct cfg80211_registered_device
*dev
;
2228 struct net_device
*netdev
;
2229 u8 mac_addr
[ETH_ALEN
];
2230 int sta_idx
= cb
->args
[1];
2233 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
2237 if (!dev
->ops
->dump_station
) {
2243 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
2250 if (nl80211_send_station(skb
,
2251 NETLINK_CB(cb
->skb
).pid
,
2252 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2262 cb
->args
[1] = sta_idx
;
2265 nl80211_finish_netdev_dump(dev
);
2270 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
2272 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2273 struct net_device
*dev
= info
->user_ptr
[1];
2274 struct station_info sinfo
;
2275 struct sk_buff
*msg
;
2276 u8
*mac_addr
= NULL
;
2279 memset(&sinfo
, 0, sizeof(sinfo
));
2281 if (!info
->attrs
[NL80211_ATTR_MAC
])
2284 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2286 if (!rdev
->ops
->get_station
)
2289 err
= rdev
->ops
->get_station(&rdev
->wiphy
, dev
, mac_addr
, &sinfo
);
2293 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2297 if (nl80211_send_station(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2298 dev
, mac_addr
, &sinfo
) < 0) {
2303 return genlmsg_reply(msg
, info
);
2307 * Get vlan interface making sure it is running and on the right wiphy.
2309 static int get_vlan(struct genl_info
*info
,
2310 struct cfg80211_registered_device
*rdev
,
2311 struct net_device
**vlan
)
2313 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
2317 *vlan
= dev_get_by_index(genl_info_net(info
),
2318 nla_get_u32(vlanattr
));
2321 if (!(*vlan
)->ieee80211_ptr
)
2323 if ((*vlan
)->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
)
2325 if (!netif_running(*vlan
))
2331 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
2333 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2335 struct net_device
*dev
= info
->user_ptr
[1];
2336 struct station_parameters params
;
2337 u8
*mac_addr
= NULL
;
2339 memset(¶ms
, 0, sizeof(params
));
2341 params
.listen_interval
= -1;
2342 params
.plink_state
= -1;
2344 if (info
->attrs
[NL80211_ATTR_STA_AID
])
2347 if (!info
->attrs
[NL80211_ATTR_MAC
])
2350 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2352 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
2353 params
.supported_rates
=
2354 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2355 params
.supported_rates_len
=
2356 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2359 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2360 params
.listen_interval
=
2361 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2363 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2365 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2367 if (parse_station_flags(info
, ¶ms
))
2370 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
2371 params
.plink_action
=
2372 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
2374 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
])
2375 params
.plink_state
=
2376 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
2378 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
2382 /* validate settings */
2385 switch (dev
->ieee80211_ptr
->iftype
) {
2386 case NL80211_IFTYPE_AP
:
2387 case NL80211_IFTYPE_AP_VLAN
:
2388 case NL80211_IFTYPE_P2P_GO
:
2389 /* disallow mesh-specific things */
2390 if (params
.plink_action
)
2393 case NL80211_IFTYPE_P2P_CLIENT
:
2394 case NL80211_IFTYPE_STATION
:
2395 /* disallow everything but AUTHORIZED flag */
2396 if (params
.plink_action
)
2400 if (params
.supported_rates
)
2404 if (params
.listen_interval
>= 0)
2406 if (params
.sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
2409 case NL80211_IFTYPE_MESH_POINT
:
2410 /* disallow things mesh doesn't support */
2415 if (params
.listen_interval
>= 0)
2417 if (params
.sta_flags_mask
&
2418 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
2419 BIT(NL80211_STA_FLAG_MFP
) |
2420 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
2430 if (!rdev
->ops
->change_station
) {
2435 err
= rdev
->ops
->change_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2439 dev_put(params
.vlan
);
2444 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
2446 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2448 struct net_device
*dev
= info
->user_ptr
[1];
2449 struct station_parameters params
;
2450 u8
*mac_addr
= NULL
;
2452 memset(¶ms
, 0, sizeof(params
));
2454 if (!info
->attrs
[NL80211_ATTR_MAC
])
2457 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2460 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
2463 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
2466 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2467 params
.supported_rates
=
2468 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2469 params
.supported_rates_len
=
2470 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2471 params
.listen_interval
=
2472 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2474 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
2475 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
2478 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2480 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2482 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
2483 params
.plink_action
=
2484 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
2486 if (parse_station_flags(info
, ¶ms
))
2489 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2490 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
2491 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
2492 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2495 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
2499 /* validate settings */
2502 if (!rdev
->ops
->add_station
) {
2507 err
= rdev
->ops
->add_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2511 dev_put(params
.vlan
);
2515 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
2517 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2518 struct net_device
*dev
= info
->user_ptr
[1];
2519 u8
*mac_addr
= NULL
;
2521 if (info
->attrs
[NL80211_ATTR_MAC
])
2522 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2524 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2525 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
2526 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
2527 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2530 if (!rdev
->ops
->del_station
)
2533 return rdev
->ops
->del_station(&rdev
->wiphy
, dev
, mac_addr
);
2536 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2537 int flags
, struct net_device
*dev
,
2538 u8
*dst
, u8
*next_hop
,
2539 struct mpath_info
*pinfo
)
2542 struct nlattr
*pinfoattr
;
2544 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2548 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2549 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
2550 NLA_PUT(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
);
2552 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
);
2554 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
2556 goto nla_put_failure
;
2557 if (pinfo
->filled
& MPATH_INFO_FRAME_QLEN
)
2558 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
2560 if (pinfo
->filled
& MPATH_INFO_SN
)
2561 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_SN
,
2563 if (pinfo
->filled
& MPATH_INFO_METRIC
)
2564 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_METRIC
,
2566 if (pinfo
->filled
& MPATH_INFO_EXPTIME
)
2567 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_EXPTIME
,
2569 if (pinfo
->filled
& MPATH_INFO_FLAGS
)
2570 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_FLAGS
,
2572 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
)
2573 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
2574 pinfo
->discovery_timeout
);
2575 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
)
2576 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
2577 pinfo
->discovery_retries
);
2579 nla_nest_end(msg
, pinfoattr
);
2581 return genlmsg_end(msg
, hdr
);
2584 genlmsg_cancel(msg
, hdr
);
2588 static int nl80211_dump_mpath(struct sk_buff
*skb
,
2589 struct netlink_callback
*cb
)
2591 struct mpath_info pinfo
;
2592 struct cfg80211_registered_device
*dev
;
2593 struct net_device
*netdev
;
2595 u8 next_hop
[ETH_ALEN
];
2596 int path_idx
= cb
->args
[1];
2599 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
2603 if (!dev
->ops
->dump_mpath
) {
2608 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2614 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
2615 dst
, next_hop
, &pinfo
);
2621 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).pid
,
2622 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2623 netdev
, dst
, next_hop
,
2632 cb
->args
[1] = path_idx
;
2635 nl80211_finish_netdev_dump(dev
);
2639 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2641 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2643 struct net_device
*dev
= info
->user_ptr
[1];
2644 struct mpath_info pinfo
;
2645 struct sk_buff
*msg
;
2647 u8 next_hop
[ETH_ALEN
];
2649 memset(&pinfo
, 0, sizeof(pinfo
));
2651 if (!info
->attrs
[NL80211_ATTR_MAC
])
2654 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2656 if (!rdev
->ops
->get_mpath
)
2659 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2662 err
= rdev
->ops
->get_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
2666 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2670 if (nl80211_send_mpath(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2671 dev
, dst
, next_hop
, &pinfo
) < 0) {
2676 return genlmsg_reply(msg
, info
);
2679 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2681 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2682 struct net_device
*dev
= info
->user_ptr
[1];
2684 u8
*next_hop
= NULL
;
2686 if (!info
->attrs
[NL80211_ATTR_MAC
])
2689 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2692 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2693 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2695 if (!rdev
->ops
->change_mpath
)
2698 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2701 return rdev
->ops
->change_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2704 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2706 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2707 struct net_device
*dev
= info
->user_ptr
[1];
2709 u8
*next_hop
= NULL
;
2711 if (!info
->attrs
[NL80211_ATTR_MAC
])
2714 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2717 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2718 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2720 if (!rdev
->ops
->add_mpath
)
2723 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2726 return rdev
->ops
->add_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2729 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2731 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2732 struct net_device
*dev
= info
->user_ptr
[1];
2735 if (info
->attrs
[NL80211_ATTR_MAC
])
2736 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2738 if (!rdev
->ops
->del_mpath
)
2741 return rdev
->ops
->del_mpath(&rdev
->wiphy
, dev
, dst
);
2744 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
2746 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2747 struct net_device
*dev
= info
->user_ptr
[1];
2748 struct bss_parameters params
;
2750 memset(¶ms
, 0, sizeof(params
));
2751 /* default to not changing parameters */
2752 params
.use_cts_prot
= -1;
2753 params
.use_short_preamble
= -1;
2754 params
.use_short_slot_time
= -1;
2755 params
.ap_isolate
= -1;
2756 params
.ht_opmode
= -1;
2758 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
2759 params
.use_cts_prot
=
2760 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
2761 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
2762 params
.use_short_preamble
=
2763 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
2764 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
2765 params
.use_short_slot_time
=
2766 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
2767 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
2768 params
.basic_rates
=
2769 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2770 params
.basic_rates_len
=
2771 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2773 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
2774 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
2775 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
2777 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
2779 if (!rdev
->ops
->change_bss
)
2782 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2783 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2786 return rdev
->ops
->change_bss(&rdev
->wiphy
, dev
, ¶ms
);
2789 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
2790 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
2791 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
2792 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
2793 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
2794 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
2795 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
2798 static int parse_reg_rule(struct nlattr
*tb
[],
2799 struct ieee80211_reg_rule
*reg_rule
)
2801 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
2802 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
2804 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
2806 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
2808 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
2810 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
2812 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
2815 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
2817 freq_range
->start_freq_khz
=
2818 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
2819 freq_range
->end_freq_khz
=
2820 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
2821 freq_range
->max_bandwidth_khz
=
2822 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
2824 power_rule
->max_eirp
=
2825 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
2827 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
2828 power_rule
->max_antenna_gain
=
2829 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
2834 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2840 * You should only get this when cfg80211 hasn't yet initialized
2841 * completely when built-in to the kernel right between the time
2842 * window between nl80211_init() and regulatory_init(), if that is
2845 mutex_lock(&cfg80211_mutex
);
2846 if (unlikely(!cfg80211_regdomain
)) {
2847 mutex_unlock(&cfg80211_mutex
);
2848 return -EINPROGRESS
;
2850 mutex_unlock(&cfg80211_mutex
);
2852 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2855 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2857 r
= regulatory_hint_user(data
);
2862 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
2863 struct genl_info
*info
)
2865 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2866 struct net_device
*dev
= info
->user_ptr
[1];
2867 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2868 struct mesh_config cur_params
;
2871 struct nlattr
*pinfoattr
;
2872 struct sk_buff
*msg
;
2874 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2877 if (!rdev
->ops
->get_mesh_config
)
2881 /* If not connected, get default parameters */
2882 if (!wdev
->mesh_id_len
)
2883 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
2885 err
= rdev
->ops
->get_mesh_config(&rdev
->wiphy
, dev
,
2892 /* Draw up a netlink message to send back */
2893 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2896 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2897 NL80211_CMD_GET_MESH_CONFIG
);
2900 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
2902 goto nla_put_failure
;
2903 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2904 NLA_PUT_U16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
2905 cur_params
.dot11MeshRetryTimeout
);
2906 NLA_PUT_U16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
2907 cur_params
.dot11MeshConfirmTimeout
);
2908 NLA_PUT_U16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
2909 cur_params
.dot11MeshHoldingTimeout
);
2910 NLA_PUT_U16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
2911 cur_params
.dot11MeshMaxPeerLinks
);
2912 NLA_PUT_U8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
2913 cur_params
.dot11MeshMaxRetries
);
2914 NLA_PUT_U8(msg
, NL80211_MESHCONF_TTL
,
2915 cur_params
.dot11MeshTTL
);
2916 NLA_PUT_U8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
2917 cur_params
.element_ttl
);
2918 NLA_PUT_U8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
2919 cur_params
.auto_open_plinks
);
2920 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2921 cur_params
.dot11MeshHWMPmaxPREQretries
);
2922 NLA_PUT_U32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
2923 cur_params
.path_refresh_time
);
2924 NLA_PUT_U16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2925 cur_params
.min_discovery_timeout
);
2926 NLA_PUT_U32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2927 cur_params
.dot11MeshHWMPactivePathTimeout
);
2928 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2929 cur_params
.dot11MeshHWMPpreqMinInterval
);
2930 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2931 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
);
2932 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
2933 cur_params
.dot11MeshHWMPRootMode
);
2934 nla_nest_end(msg
, pinfoattr
);
2935 genlmsg_end(msg
, hdr
);
2936 return genlmsg_reply(msg
, info
);
2939 genlmsg_cancel(msg
, hdr
);
2945 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
2946 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
2947 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
2948 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
2949 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
2950 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
2951 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
2952 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
2953 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
2955 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
2956 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
2957 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
2958 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
2959 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
2960 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
2963 static const struct nla_policy
2964 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
2965 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
2966 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
2967 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
2968 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
2969 .len
= IEEE80211_MAX_DATA_LEN
},
2970 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
2973 static int nl80211_parse_mesh_config(struct genl_info
*info
,
2974 struct mesh_config
*cfg
,
2977 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
2980 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2982 if (table[attr_num]) {\
2983 cfg->param = nla_fn(table[attr_num]); \
2984 mask |= (1 << (attr_num - 1)); \
2989 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
2991 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
2992 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
2993 nl80211_meshconf_params_policy
))
2996 /* This makes sure that there aren't more than 32 mesh config
2997 * parameters (otherwise our bitfield scheme would not work.) */
2998 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
3000 /* Fill in the params struct */
3001 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
3002 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
, nla_get_u16
);
3003 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
3004 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
, nla_get_u16
);
3005 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
3006 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
, nla_get_u16
);
3007 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
3008 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
, nla_get_u16
);
3009 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
3010 mask
, NL80211_MESHCONF_MAX_RETRIES
, nla_get_u8
);
3011 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
3012 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
3013 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
,
3014 mask
, NL80211_MESHCONF_ELEMENT_TTL
, nla_get_u8
);
3015 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
3016 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
, nla_get_u8
);
3017 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
3018 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
3020 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
3021 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
, nla_get_u32
);
3022 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
3023 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
3025 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
3026 mask
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
3028 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
3029 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
3031 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3032 dot11MeshHWMPnetDiameterTraversalTime
,
3033 mask
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
3035 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3036 dot11MeshHWMPRootMode
, mask
,
3037 NL80211_MESHCONF_HWMP_ROOTMODE
,
3044 #undef FILL_IN_MESH_PARAM_IF_SET
3047 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
3048 struct mesh_setup
*setup
)
3050 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
3052 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
3054 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
3055 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
3056 nl80211_mesh_setup_params_policy
))
3059 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
3060 setup
->path_sel_proto
=
3061 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
3062 IEEE80211_PATH_PROTOCOL_VENDOR
:
3063 IEEE80211_PATH_PROTOCOL_HWMP
;
3065 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
3066 setup
->path_metric
=
3067 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
3068 IEEE80211_PATH_METRIC_VENDOR
:
3069 IEEE80211_PATH_METRIC_AIRTIME
;
3072 if (tb
[NL80211_MESH_SETUP_IE
]) {
3073 struct nlattr
*ieattr
=
3074 tb
[NL80211_MESH_SETUP_IE
];
3075 if (!is_valid_ie_attr(ieattr
))
3077 setup
->ie
= nla_data(ieattr
);
3078 setup
->ie_len
= nla_len(ieattr
);
3080 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
3081 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
3086 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
3087 struct genl_info
*info
)
3089 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3090 struct net_device
*dev
= info
->user_ptr
[1];
3091 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3092 struct mesh_config cfg
;
3096 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3099 if (!rdev
->ops
->update_mesh_config
)
3102 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
3107 if (!wdev
->mesh_id_len
)
3111 err
= rdev
->ops
->update_mesh_config(&rdev
->wiphy
, dev
,
3119 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3121 struct sk_buff
*msg
;
3123 struct nlattr
*nl_reg_rules
;
3127 mutex_lock(&cfg80211_mutex
);
3129 if (!cfg80211_regdomain
)
3132 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3138 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
3139 NL80211_CMD_GET_REG
);
3143 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
,
3144 cfg80211_regdomain
->alpha2
);
3146 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
3148 goto nla_put_failure
;
3150 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
3151 struct nlattr
*nl_reg_rule
;
3152 const struct ieee80211_reg_rule
*reg_rule
;
3153 const struct ieee80211_freq_range
*freq_range
;
3154 const struct ieee80211_power_rule
*power_rule
;
3156 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
3157 freq_range
= ®_rule
->freq_range
;
3158 power_rule
= ®_rule
->power_rule
;
3160 nl_reg_rule
= nla_nest_start(msg
, i
);
3162 goto nla_put_failure
;
3164 NLA_PUT_U32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
3166 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
3167 freq_range
->start_freq_khz
);
3168 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
3169 freq_range
->end_freq_khz
);
3170 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
3171 freq_range
->max_bandwidth_khz
);
3172 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
3173 power_rule
->max_antenna_gain
);
3174 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
3175 power_rule
->max_eirp
);
3177 nla_nest_end(msg
, nl_reg_rule
);
3180 nla_nest_end(msg
, nl_reg_rules
);
3182 genlmsg_end(msg
, hdr
);
3183 err
= genlmsg_reply(msg
, info
);
3187 genlmsg_cancel(msg
, hdr
);
3192 mutex_unlock(&cfg80211_mutex
);
3196 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3198 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
3199 struct nlattr
*nl_reg_rule
;
3200 char *alpha2
= NULL
;
3201 int rem_reg_rules
= 0, r
= 0;
3202 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
3203 struct ieee80211_regdomain
*rd
= NULL
;
3205 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
3208 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
3211 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
3213 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
3216 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
3220 mutex_lock(&cfg80211_mutex
);
3222 if (!reg_is_valid_request(alpha2
)) {
3227 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
3228 (num_rules
* sizeof(struct ieee80211_reg_rule
));
3230 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
3236 rd
->n_reg_rules
= num_rules
;
3237 rd
->alpha2
[0] = alpha2
[0];
3238 rd
->alpha2
[1] = alpha2
[1];
3240 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
3242 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
3243 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
3245 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
3251 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
3257 BUG_ON(rule_idx
!= num_rules
);
3261 mutex_unlock(&cfg80211_mutex
);
3266 mutex_unlock(&cfg80211_mutex
);
3271 static int validate_scan_freqs(struct nlattr
*freqs
)
3273 struct nlattr
*attr1
, *attr2
;
3274 int n_channels
= 0, tmp1
, tmp2
;
3276 nla_for_each_nested(attr1
, freqs
, tmp1
) {
3279 * Some hardware has a limited channel list for
3280 * scanning, and it is pretty much nonsensical
3281 * to scan for a channel twice, so disallow that
3282 * and don't require drivers to check that the
3283 * channel list they get isn't longer than what
3284 * they can scan, as long as they can scan all
3285 * the channels they registered at once.
3287 nla_for_each_nested(attr2
, freqs
, tmp2
)
3288 if (attr1
!= attr2
&&
3289 nla_get_u32(attr1
) == nla_get_u32(attr2
))
3296 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
3298 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3299 struct net_device
*dev
= info
->user_ptr
[1];
3300 struct cfg80211_scan_request
*request
;
3301 struct nlattr
*attr
;
3302 struct wiphy
*wiphy
;
3303 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
3304 enum ieee80211_band band
;
3307 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3310 wiphy
= &rdev
->wiphy
;
3312 if (!rdev
->ops
->scan
)
3318 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3319 n_channels
= validate_scan_freqs(
3320 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
3326 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
3327 if (wiphy
->bands
[band
])
3328 n_channels
+= wiphy
->bands
[band
]->n_channels
;
3331 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
3332 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
3335 if (n_ssids
> wiphy
->max_scan_ssids
)
3338 if (info
->attrs
[NL80211_ATTR_IE
])
3339 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3343 if (ie_len
> wiphy
->max_scan_ie_len
)
3346 request
= kzalloc(sizeof(*request
)
3347 + sizeof(*request
->ssids
) * n_ssids
3348 + sizeof(*request
->channels
) * n_channels
3349 + ie_len
, GFP_KERNEL
);
3354 request
->ssids
= (void *)&request
->channels
[n_channels
];
3355 request
->n_ssids
= n_ssids
;
3358 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
3360 request
->ie
= (void *)(request
->channels
+ n_channels
);
3364 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3365 /* user specified, bail out if channel not found */
3366 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
3367 struct ieee80211_channel
*chan
;
3369 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
3376 /* ignore disabled channels */
3377 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3380 request
->channels
[i
] = chan
;
3385 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
3387 if (!wiphy
->bands
[band
])
3389 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
3390 struct ieee80211_channel
*chan
;
3392 chan
= &wiphy
->bands
[band
]->channels
[j
];
3394 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3397 request
->channels
[i
] = chan
;
3408 request
->n_channels
= i
;
3411 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
3412 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
3413 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
3417 request
->ssids
[i
].ssid_len
= nla_len(attr
);
3418 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
3423 if (info
->attrs
[NL80211_ATTR_IE
]) {
3424 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3425 memcpy((void *)request
->ie
,
3426 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
3431 request
->wiphy
= &rdev
->wiphy
;
3433 rdev
->scan_req
= request
;
3434 err
= rdev
->ops
->scan(&rdev
->wiphy
, dev
, request
);
3437 nl80211_send_scan_start(rdev
, dev
);
3441 rdev
->scan_req
= NULL
;
3448 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
3449 struct genl_info
*info
)
3451 struct cfg80211_sched_scan_request
*request
;
3452 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3453 struct net_device
*dev
= info
->user_ptr
[1];
3454 struct nlattr
*attr
;
3455 struct wiphy
*wiphy
;
3456 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
3458 enum ieee80211_band band
;
3461 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
3462 !rdev
->ops
->sched_scan_start
)
3465 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3468 if (!info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
3471 interval
= nla_get_u32(info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
3475 wiphy
= &rdev
->wiphy
;
3477 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3478 n_channels
= validate_scan_freqs(
3479 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
3485 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
3486 if (wiphy
->bands
[band
])
3487 n_channels
+= wiphy
->bands
[band
]->n_channels
;
3490 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
3491 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
3495 if (n_ssids
> wiphy
->max_scan_ssids
)
3498 if (info
->attrs
[NL80211_ATTR_IE
])
3499 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3503 if (ie_len
> wiphy
->max_scan_ie_len
)
3506 mutex_lock(&rdev
->sched_scan_mtx
);
3508 if (rdev
->sched_scan_req
) {
3513 request
= kzalloc(sizeof(*request
)
3514 + sizeof(*request
->ssids
) * n_ssids
3515 + sizeof(*request
->channels
) * n_channels
3516 + ie_len
, GFP_KERNEL
);
3523 request
->ssids
= (void *)&request
->channels
[n_channels
];
3524 request
->n_ssids
= n_ssids
;
3527 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
3529 request
->ie
= (void *)(request
->channels
+ n_channels
);
3533 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3534 /* user specified, bail out if channel not found */
3535 nla_for_each_nested(attr
,
3536 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
3538 struct ieee80211_channel
*chan
;
3540 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
3547 /* ignore disabled channels */
3548 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3551 request
->channels
[i
] = chan
;
3556 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
3558 if (!wiphy
->bands
[band
])
3560 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
3561 struct ieee80211_channel
*chan
;
3563 chan
= &wiphy
->bands
[band
]->channels
[j
];
3565 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3568 request
->channels
[i
] = chan
;
3579 request
->n_channels
= i
;
3582 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
3583 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
3585 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
3589 request
->ssids
[i
].ssid_len
= nla_len(attr
);
3590 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
3596 if (info
->attrs
[NL80211_ATTR_IE
]) {
3597 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3598 memcpy((void *)request
->ie
,
3599 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
3604 request
->wiphy
= &rdev
->wiphy
;
3605 request
->interval
= interval
;
3607 err
= rdev
->ops
->sched_scan_start(&rdev
->wiphy
, dev
, request
);
3609 rdev
->sched_scan_req
= request
;
3610 nl80211_send_sched_scan(rdev
, dev
,
3611 NL80211_CMD_START_SCHED_SCAN
);
3618 mutex_unlock(&rdev
->sched_scan_mtx
);
3622 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
3623 struct genl_info
*info
)
3625 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3628 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
3629 !rdev
->ops
->sched_scan_stop
)
3632 mutex_lock(&rdev
->sched_scan_mtx
);
3633 err
= __cfg80211_stop_sched_scan(rdev
, false);
3634 mutex_unlock(&rdev
->sched_scan_mtx
);
3639 static int nl80211_send_bss(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
3640 struct cfg80211_registered_device
*rdev
,
3641 struct wireless_dev
*wdev
,
3642 struct cfg80211_internal_bss
*intbss
)
3644 struct cfg80211_bss
*res
= &intbss
->pub
;
3649 ASSERT_WDEV_LOCK(wdev
);
3651 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3652 NL80211_CMD_NEW_SCAN_RESULTS
);
3656 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
);
3657 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
);
3659 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
3661 goto nla_put_failure
;
3662 if (!is_zero_ether_addr(res
->bssid
))
3663 NLA_PUT(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
);
3664 if (res
->information_elements
&& res
->len_information_elements
)
3665 NLA_PUT(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
3666 res
->len_information_elements
,
3667 res
->information_elements
);
3668 if (res
->beacon_ies
&& res
->len_beacon_ies
&&
3669 res
->beacon_ies
!= res
->information_elements
)
3670 NLA_PUT(msg
, NL80211_BSS_BEACON_IES
,
3671 res
->len_beacon_ies
, res
->beacon_ies
);
3673 NLA_PUT_U64(msg
, NL80211_BSS_TSF
, res
->tsf
);
3674 if (res
->beacon_interval
)
3675 NLA_PUT_U16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
);
3676 NLA_PUT_U16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
);
3677 NLA_PUT_U32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
);
3678 NLA_PUT_U32(msg
, NL80211_BSS_SEEN_MS_AGO
,
3679 jiffies_to_msecs(jiffies
- intbss
->ts
));
3681 switch (rdev
->wiphy
.signal_type
) {
3682 case CFG80211_SIGNAL_TYPE_MBM
:
3683 NLA_PUT_U32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
);
3685 case CFG80211_SIGNAL_TYPE_UNSPEC
:
3686 NLA_PUT_U8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
);
3692 switch (wdev
->iftype
) {
3693 case NL80211_IFTYPE_P2P_CLIENT
:
3694 case NL80211_IFTYPE_STATION
:
3695 if (intbss
== wdev
->current_bss
)
3696 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3697 NL80211_BSS_STATUS_ASSOCIATED
);
3698 else for (i
= 0; i
< MAX_AUTH_BSSES
; i
++) {
3699 if (intbss
!= wdev
->auth_bsses
[i
])
3701 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3702 NL80211_BSS_STATUS_AUTHENTICATED
);
3706 case NL80211_IFTYPE_ADHOC
:
3707 if (intbss
== wdev
->current_bss
)
3708 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3709 NL80211_BSS_STATUS_IBSS_JOINED
);
3715 nla_nest_end(msg
, bss
);
3717 return genlmsg_end(msg
, hdr
);
3720 genlmsg_cancel(msg
, hdr
);
3724 static int nl80211_dump_scan(struct sk_buff
*skb
,
3725 struct netlink_callback
*cb
)
3727 struct cfg80211_registered_device
*rdev
;
3728 struct net_device
*dev
;
3729 struct cfg80211_internal_bss
*scan
;
3730 struct wireless_dev
*wdev
;
3731 int start
= cb
->args
[1], idx
= 0;
3734 err
= nl80211_prepare_netdev_dump(skb
, cb
, &rdev
, &dev
);
3738 wdev
= dev
->ieee80211_ptr
;
3741 spin_lock_bh(&rdev
->bss_lock
);
3742 cfg80211_bss_expire(rdev
);
3744 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
3747 if (nl80211_send_bss(skb
,
3748 NETLINK_CB(cb
->skb
).pid
,
3749 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3750 rdev
, wdev
, scan
) < 0) {
3756 spin_unlock_bh(&rdev
->bss_lock
);
3760 nl80211_finish_netdev_dump(rdev
);
3765 static int nl80211_send_survey(struct sk_buff
*msg
, u32 pid
, u32 seq
,
3766 int flags
, struct net_device
*dev
,
3767 struct survey_info
*survey
)
3770 struct nlattr
*infoattr
;
3772 /* Survey without a channel doesn't make sense */
3773 if (!survey
->channel
)
3776 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3777 NL80211_CMD_NEW_SURVEY_RESULTS
);
3781 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
3783 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
3785 goto nla_put_failure
;
3787 NLA_PUT_U32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
3788 survey
->channel
->center_freq
);
3789 if (survey
->filled
& SURVEY_INFO_NOISE_DBM
)
3790 NLA_PUT_U8(msg
, NL80211_SURVEY_INFO_NOISE
,
3792 if (survey
->filled
& SURVEY_INFO_IN_USE
)
3793 NLA_PUT_FLAG(msg
, NL80211_SURVEY_INFO_IN_USE
);
3794 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME
)
3795 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
3796 survey
->channel_time
);
3797 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
)
3798 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
3799 survey
->channel_time_busy
);
3800 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
)
3801 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
3802 survey
->channel_time_ext_busy
);
3803 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
)
3804 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
3805 survey
->channel_time_rx
);
3806 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
)
3807 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
3808 survey
->channel_time_tx
);
3810 nla_nest_end(msg
, infoattr
);
3812 return genlmsg_end(msg
, hdr
);
3815 genlmsg_cancel(msg
, hdr
);
3819 static int nl80211_dump_survey(struct sk_buff
*skb
,
3820 struct netlink_callback
*cb
)
3822 struct survey_info survey
;
3823 struct cfg80211_registered_device
*dev
;
3824 struct net_device
*netdev
;
3825 int survey_idx
= cb
->args
[1];
3828 res
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
3832 if (!dev
->ops
->dump_survey
) {
3838 res
= dev
->ops
->dump_survey(&dev
->wiphy
, netdev
, survey_idx
,
3845 if (nl80211_send_survey(skb
,
3846 NETLINK_CB(cb
->skb
).pid
,
3847 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3855 cb
->args
[1] = survey_idx
;
3858 nl80211_finish_netdev_dump(dev
);
3862 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
)
3864 return auth_type
<= NL80211_AUTHTYPE_MAX
;
3867 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
3869 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
3870 NL80211_WPA_VERSION_2
));
3873 static bool nl80211_valid_akm_suite(u32 akm
)
3875 return akm
== WLAN_AKM_SUITE_8021X
||
3876 akm
== WLAN_AKM_SUITE_PSK
;
3879 static bool nl80211_valid_cipher_suite(u32 cipher
)
3881 return cipher
== WLAN_CIPHER_SUITE_WEP40
||
3882 cipher
== WLAN_CIPHER_SUITE_WEP104
||
3883 cipher
== WLAN_CIPHER_SUITE_TKIP
||
3884 cipher
== WLAN_CIPHER_SUITE_CCMP
||
3885 cipher
== WLAN_CIPHER_SUITE_AES_CMAC
;
3889 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3891 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3892 struct net_device
*dev
= info
->user_ptr
[1];
3893 struct ieee80211_channel
*chan
;
3894 const u8
*bssid
, *ssid
, *ie
= NULL
;
3895 int err
, ssid_len
, ie_len
= 0;
3896 enum nl80211_auth_type auth_type
;
3897 struct key_parse key
;
3898 bool local_state_change
;
3900 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3903 if (!info
->attrs
[NL80211_ATTR_MAC
])
3906 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
3909 if (!info
->attrs
[NL80211_ATTR_SSID
])
3912 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
3915 err
= nl80211_parse_key(info
, &key
);
3920 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
3922 if (!key
.p
.key
|| !key
.p
.key_len
)
3924 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
3925 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
3926 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
3927 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
3939 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
3940 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
3949 if (!rdev
->ops
->auth
)
3952 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
3953 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
3956 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3957 chan
= ieee80211_get_channel(&rdev
->wiphy
,
3958 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3959 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
3962 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3963 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3965 if (info
->attrs
[NL80211_ATTR_IE
]) {
3966 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3967 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3970 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3971 if (!nl80211_valid_auth_type(auth_type
))
3974 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
3976 return cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
3977 ssid
, ssid_len
, ie
, ie_len
,
3978 key
.p
.key
, key
.p
.key_len
, key
.idx
,
3979 local_state_change
);
3982 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
3983 struct genl_info
*info
,
3984 struct cfg80211_crypto_settings
*settings
,
3987 memset(settings
, 0, sizeof(*settings
));
3989 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
3991 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
3993 proto
= nla_get_u16(
3994 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
3995 settings
->control_port_ethertype
= cpu_to_be16(proto
);
3996 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
3999 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
4000 settings
->control_port_no_encrypt
= true;
4002 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
4004 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
4008 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
4009 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
4010 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
4012 if (len
% sizeof(u32
))
4015 if (settings
->n_ciphers_pairwise
> cipher_limit
)
4018 memcpy(settings
->ciphers_pairwise
, data
, len
);
4020 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
4021 if (!nl80211_valid_cipher_suite(
4022 settings
->ciphers_pairwise
[i
]))
4026 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
4027 settings
->cipher_group
=
4028 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
4029 if (!nl80211_valid_cipher_suite(settings
->cipher_group
))
4033 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
4034 settings
->wpa_versions
=
4035 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
4036 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
4040 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
4044 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
4045 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
4046 settings
->n_akm_suites
= len
/ sizeof(u32
);
4048 if (len
% sizeof(u32
))
4051 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
4054 memcpy(settings
->akm_suites
, data
, len
);
4056 for (i
= 0; i
< settings
->n_akm_suites
; i
++)
4057 if (!nl80211_valid_akm_suite(settings
->akm_suites
[i
]))
4064 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
4066 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4067 struct net_device
*dev
= info
->user_ptr
[1];
4068 struct cfg80211_crypto_settings crypto
;
4069 struct ieee80211_channel
*chan
;
4070 const u8
*bssid
, *ssid
, *ie
= NULL
, *prev_bssid
= NULL
;
4071 int err
, ssid_len
, ie_len
= 0;
4072 bool use_mfp
= false;
4074 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4077 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
4078 !info
->attrs
[NL80211_ATTR_SSID
] ||
4079 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4082 if (!rdev
->ops
->assoc
)
4085 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4086 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4089 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4091 chan
= ieee80211_get_channel(&rdev
->wiphy
,
4092 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4093 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
4096 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4097 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4099 if (info
->attrs
[NL80211_ATTR_IE
]) {
4100 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4101 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4104 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
4105 enum nl80211_mfp mfp
=
4106 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
4107 if (mfp
== NL80211_MFP_REQUIRED
)
4109 else if (mfp
!= NL80211_MFP_NO
)
4113 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
4114 prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
4116 err
= nl80211_crypto_settings(rdev
, info
, &crypto
, 1);
4118 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
, prev_bssid
,
4119 ssid
, ssid_len
, ie
, ie_len
, use_mfp
,
4125 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
4127 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4128 struct net_device
*dev
= info
->user_ptr
[1];
4129 const u8
*ie
= NULL
, *bssid
;
4132 bool local_state_change
;
4134 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4137 if (!info
->attrs
[NL80211_ATTR_MAC
])
4140 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4143 if (!rdev
->ops
->deauth
)
4146 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4147 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4150 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4152 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4153 if (reason_code
== 0) {
4154 /* Reason Code 0 is reserved */
4158 if (info
->attrs
[NL80211_ATTR_IE
]) {
4159 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4160 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4163 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
4165 return cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
4166 local_state_change
);
4169 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
4171 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4172 struct net_device
*dev
= info
->user_ptr
[1];
4173 const u8
*ie
= NULL
, *bssid
;
4176 bool local_state_change
;
4178 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4181 if (!info
->attrs
[NL80211_ATTR_MAC
])
4184 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4187 if (!rdev
->ops
->disassoc
)
4190 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4191 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4194 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4196 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4197 if (reason_code
== 0) {
4198 /* Reason Code 0 is reserved */
4202 if (info
->attrs
[NL80211_ATTR_IE
]) {
4203 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4204 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4207 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
4209 return cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
4210 local_state_change
);
4214 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
4215 int mcast_rate
[IEEE80211_NUM_BANDS
],
4218 struct wiphy
*wiphy
= &rdev
->wiphy
;
4222 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
4223 struct ieee80211_supported_band
*sband
;
4225 sband
= wiphy
->bands
[band
];
4229 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
4230 if (sband
->bitrates
[i
].bitrate
== rateval
) {
4231 mcast_rate
[band
] = i
+ 1;
4241 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
4243 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4244 struct net_device
*dev
= info
->user_ptr
[1];
4245 struct cfg80211_ibss_params ibss
;
4246 struct wiphy
*wiphy
;
4247 struct cfg80211_cached_keys
*connkeys
= NULL
;
4250 memset(&ibss
, 0, sizeof(ibss
));
4252 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4255 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
4256 !info
->attrs
[NL80211_ATTR_SSID
] ||
4257 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
4260 ibss
.beacon_interval
= 100;
4262 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
4263 ibss
.beacon_interval
=
4264 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
4265 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
4269 if (!rdev
->ops
->join_ibss
)
4272 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
4275 wiphy
= &rdev
->wiphy
;
4277 if (info
->attrs
[NL80211_ATTR_MAC
])
4278 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4279 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4280 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4282 if (info
->attrs
[NL80211_ATTR_IE
]) {
4283 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4284 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4287 ibss
.channel
= ieee80211_get_channel(wiphy
,
4288 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4289 if (!ibss
.channel
||
4290 ibss
.channel
->flags
& IEEE80211_CHAN_NO_IBSS
||
4291 ibss
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
4294 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
4295 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
4297 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
4299 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4301 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4302 struct ieee80211_supported_band
*sband
=
4303 wiphy
->bands
[ibss
.channel
->band
];
4309 for (i
= 0; i
< n_rates
; i
++) {
4310 int rate
= (rates
[i
] & 0x7f) * 5;
4313 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
4314 if (sband
->bitrates
[j
].bitrate
== rate
) {
4316 ibss
.basic_rates
|= BIT(j
);
4325 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
4326 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
4327 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
4330 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
4331 connkeys
= nl80211_parse_connkeys(rdev
,
4332 info
->attrs
[NL80211_ATTR_KEYS
]);
4333 if (IS_ERR(connkeys
))
4334 return PTR_ERR(connkeys
);
4337 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
4343 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
4345 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4346 struct net_device
*dev
= info
->user_ptr
[1];
4348 if (!rdev
->ops
->leave_ibss
)
4351 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
4354 return cfg80211_leave_ibss(rdev
, dev
, false);
4357 #ifdef CONFIG_NL80211_TESTMODE
4358 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
4362 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
4364 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4367 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
4371 if (rdev
->ops
->testmode_cmd
) {
4372 rdev
->testmode_info
= info
;
4373 err
= rdev
->ops
->testmode_cmd(&rdev
->wiphy
,
4374 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
4375 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
4376 rdev
->testmode_info
= NULL
;
4382 static struct sk_buff
*
4383 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
4384 int approxlen
, u32 pid
, u32 seq
, gfp_t gfp
)
4386 struct sk_buff
*skb
;
4388 struct nlattr
*data
;
4390 skb
= nlmsg_new(approxlen
+ 100, gfp
);
4394 hdr
= nl80211hdr_put(skb
, pid
, seq
, 0, NL80211_CMD_TESTMODE
);
4400 NLA_PUT_U32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4401 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
4403 ((void **)skb
->cb
)[0] = rdev
;
4404 ((void **)skb
->cb
)[1] = hdr
;
4405 ((void **)skb
->cb
)[2] = data
;
4414 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
4417 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4419 if (WARN_ON(!rdev
->testmode_info
))
4422 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
4423 rdev
->testmode_info
->snd_pid
,
4424 rdev
->testmode_info
->snd_seq
,
4427 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
4429 int cfg80211_testmode_reply(struct sk_buff
*skb
)
4431 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
4432 void *hdr
= ((void **)skb
->cb
)[1];
4433 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4435 if (WARN_ON(!rdev
->testmode_info
)) {
4440 nla_nest_end(skb
, data
);
4441 genlmsg_end(skb
, hdr
);
4442 return genlmsg_reply(skb
, rdev
->testmode_info
);
4444 EXPORT_SYMBOL(cfg80211_testmode_reply
);
4446 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
4447 int approxlen
, gfp_t gfp
)
4449 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4451 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
4453 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
4455 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
4457 void *hdr
= ((void **)skb
->cb
)[1];
4458 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4460 nla_nest_end(skb
, data
);
4461 genlmsg_end(skb
, hdr
);
4462 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
4464 EXPORT_SYMBOL(cfg80211_testmode_event
);
4467 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
4469 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4470 struct net_device
*dev
= info
->user_ptr
[1];
4471 struct cfg80211_connect_params connect
;
4472 struct wiphy
*wiphy
;
4473 struct cfg80211_cached_keys
*connkeys
= NULL
;
4476 memset(&connect
, 0, sizeof(connect
));
4478 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4481 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
4482 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
4485 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
4487 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4488 if (!nl80211_valid_auth_type(connect
.auth_type
))
4491 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
4493 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
4495 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
4496 NL80211_MAX_NR_CIPHER_SUITES
);
4500 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4501 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4504 wiphy
= &rdev
->wiphy
;
4506 if (info
->attrs
[NL80211_ATTR_MAC
])
4507 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4508 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4509 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4511 if (info
->attrs
[NL80211_ATTR_IE
]) {
4512 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4513 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4516 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
4518 ieee80211_get_channel(wiphy
,
4519 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4520 if (!connect
.channel
||
4521 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
4525 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
4526 connkeys
= nl80211_parse_connkeys(rdev
,
4527 info
->attrs
[NL80211_ATTR_KEYS
]);
4528 if (IS_ERR(connkeys
))
4529 return PTR_ERR(connkeys
);
4532 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
4538 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
4540 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4541 struct net_device
*dev
= info
->user_ptr
[1];
4544 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4545 reason
= WLAN_REASON_DEAUTH_LEAVING
;
4547 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4552 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4553 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4556 return cfg80211_disconnect(rdev
, dev
, reason
, true);
4559 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
4561 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4566 if (!info
->attrs
[NL80211_ATTR_PID
])
4569 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
4571 net
= get_net_ns_by_pid(pid
);
4573 return PTR_ERR(net
);
4577 /* check if anything to do */
4578 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
4579 err
= cfg80211_switch_netns(rdev
, net
);
4585 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4587 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4588 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
4589 struct cfg80211_pmksa
*pmksa
) = NULL
;
4590 struct net_device
*dev
= info
->user_ptr
[1];
4591 struct cfg80211_pmksa pmksa
;
4593 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
4595 if (!info
->attrs
[NL80211_ATTR_MAC
])
4598 if (!info
->attrs
[NL80211_ATTR_PMKID
])
4601 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
4602 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4604 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4605 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4608 switch (info
->genlhdr
->cmd
) {
4609 case NL80211_CMD_SET_PMKSA
:
4610 rdev_ops
= rdev
->ops
->set_pmksa
;
4612 case NL80211_CMD_DEL_PMKSA
:
4613 rdev_ops
= rdev
->ops
->del_pmksa
;
4623 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
4626 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4628 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4629 struct net_device
*dev
= info
->user_ptr
[1];
4631 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4632 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4635 if (!rdev
->ops
->flush_pmksa
)
4638 return rdev
->ops
->flush_pmksa(&rdev
->wiphy
, dev
);
4641 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
4642 struct genl_info
*info
)
4644 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4645 struct net_device
*dev
= info
->user_ptr
[1];
4646 struct ieee80211_channel
*chan
;
4647 struct sk_buff
*msg
;
4650 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
4654 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
4655 !info
->attrs
[NL80211_ATTR_DURATION
])
4658 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
4661 * We should be on that channel for at least one jiffie,
4662 * and more than 5 seconds seems excessive.
4664 if (!duration
|| !msecs_to_jiffies(duration
) ||
4665 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
4668 if (!rdev
->ops
->remain_on_channel
)
4671 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
4672 channel_type
= nla_get_u32(
4673 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
4674 if (channel_type
!= NL80211_CHAN_NO_HT
&&
4675 channel_type
!= NL80211_CHAN_HT20
&&
4676 channel_type
!= NL80211_CHAN_HT40PLUS
&&
4677 channel_type
!= NL80211_CHAN_HT40MINUS
)
4681 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
4682 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
4686 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4690 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4691 NL80211_CMD_REMAIN_ON_CHANNEL
);
4698 err
= rdev
->ops
->remain_on_channel(&rdev
->wiphy
, dev
, chan
,
4699 channel_type
, duration
, &cookie
);
4704 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
4706 genlmsg_end(msg
, hdr
);
4708 return genlmsg_reply(msg
, info
);
4717 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
4718 struct genl_info
*info
)
4720 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4721 struct net_device
*dev
= info
->user_ptr
[1];
4724 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
4727 if (!rdev
->ops
->cancel_remain_on_channel
)
4730 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
4732 return rdev
->ops
->cancel_remain_on_channel(&rdev
->wiphy
, dev
, cookie
);
4735 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
4736 u8
*rates
, u8 rates_len
)
4741 for (i
= 0; i
< rates_len
; i
++) {
4742 int rate
= (rates
[i
] & 0x7f) * 5;
4744 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
4745 struct ieee80211_rate
*srate
=
4746 &sband
->bitrates
[ridx
];
4747 if (rate
== srate
->bitrate
) {
4752 if (ridx
== sband
->n_bitrates
)
4753 return 0; /* rate not found */
4759 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
4760 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
4761 .len
= NL80211_MAX_SUPP_RATES
},
4764 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
4765 struct genl_info
*info
)
4767 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
4768 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4769 struct cfg80211_bitrate_mask mask
;
4771 struct net_device
*dev
= info
->user_ptr
[1];
4772 struct nlattr
*tx_rates
;
4773 struct ieee80211_supported_band
*sband
;
4775 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
4778 if (!rdev
->ops
->set_bitrate_mask
)
4781 memset(&mask
, 0, sizeof(mask
));
4782 /* Default to all rates enabled */
4783 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
4784 sband
= rdev
->wiphy
.bands
[i
];
4785 mask
.control
[i
].legacy
=
4786 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
4790 * The nested attribute uses enum nl80211_band as the index. This maps
4791 * directly to the enum ieee80211_band values used in cfg80211.
4793 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
4795 enum ieee80211_band band
= nla_type(tx_rates
);
4796 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
4798 sband
= rdev
->wiphy
.bands
[band
];
4801 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
4802 nla_len(tx_rates
), nl80211_txattr_policy
);
4803 if (tb
[NL80211_TXRATE_LEGACY
]) {
4804 mask
.control
[band
].legacy
= rateset_to_mask(
4806 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
4807 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
4808 if (mask
.control
[band
].legacy
== 0)
4813 return rdev
->ops
->set_bitrate_mask(&rdev
->wiphy
, dev
, NULL
, &mask
);
4816 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
4818 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4819 struct net_device
*dev
= info
->user_ptr
[1];
4820 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
4822 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
4825 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
4826 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
4828 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4829 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
4830 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
4831 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4832 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4833 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
4834 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4837 /* not much point in registering if we can't reply */
4838 if (!rdev
->ops
->mgmt_tx
)
4841 return cfg80211_mlme_register_mgmt(dev
->ieee80211_ptr
, info
->snd_pid
,
4843 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
4844 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
4847 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
4849 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4850 struct net_device
*dev
= info
->user_ptr
[1];
4851 struct ieee80211_channel
*chan
;
4852 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
4853 bool channel_type_valid
= false;
4858 struct sk_buff
*msg
;
4859 unsigned int wait
= 0;
4862 if (!info
->attrs
[NL80211_ATTR_FRAME
] ||
4863 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4866 if (!rdev
->ops
->mgmt_tx
)
4869 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4870 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
4871 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
4872 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4873 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4874 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
4875 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4878 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
4879 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
4881 wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
4884 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
4885 channel_type
= nla_get_u32(
4886 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
4887 if (channel_type
!= NL80211_CHAN_NO_HT
&&
4888 channel_type
!= NL80211_CHAN_HT20
&&
4889 channel_type
!= NL80211_CHAN_HT40PLUS
&&
4890 channel_type
!= NL80211_CHAN_HT40MINUS
)
4892 channel_type_valid
= true;
4895 offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
4897 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
4898 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
4902 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4906 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4913 err
= cfg80211_mlme_mgmt_tx(rdev
, dev
, chan
, offchan
, channel_type
,
4914 channel_type_valid
, wait
,
4915 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
4916 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
4921 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
4923 genlmsg_end(msg
, hdr
);
4924 return genlmsg_reply(msg
, info
);
4933 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
4935 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4936 struct net_device
*dev
= info
->user_ptr
[1];
4939 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
4942 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
4945 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4946 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
4947 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
4948 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4949 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4950 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4953 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
4955 return rdev
->ops
->mgmt_tx_cancel_wait(&rdev
->wiphy
, dev
, cookie
);
4958 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
4960 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4961 struct wireless_dev
*wdev
;
4962 struct net_device
*dev
= info
->user_ptr
[1];
4967 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
4970 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
4972 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
4975 wdev
= dev
->ieee80211_ptr
;
4977 if (!rdev
->ops
->set_power_mgmt
)
4980 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
4982 if (state
== wdev
->ps
)
4985 err
= rdev
->ops
->set_power_mgmt(wdev
->wiphy
, dev
, state
,
4992 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
4994 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4995 enum nl80211_ps_state ps_state
;
4996 struct wireless_dev
*wdev
;
4997 struct net_device
*dev
= info
->user_ptr
[1];
4998 struct sk_buff
*msg
;
5002 wdev
= dev
->ieee80211_ptr
;
5004 if (!rdev
->ops
->set_power_mgmt
)
5007 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5011 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
5012 NL80211_CMD_GET_POWER_SAVE
);
5019 ps_state
= NL80211_PS_ENABLED
;
5021 ps_state
= NL80211_PS_DISABLED
;
5023 NLA_PUT_U32(msg
, NL80211_ATTR_PS_STATE
, ps_state
);
5025 genlmsg_end(msg
, hdr
);
5026 return genlmsg_reply(msg
, info
);
5035 static struct nla_policy
5036 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
5037 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
5038 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
5039 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
5042 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
5043 s32 threshold
, u32 hysteresis
)
5045 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5046 struct wireless_dev
*wdev
;
5047 struct net_device
*dev
= info
->user_ptr
[1];
5052 wdev
= dev
->ieee80211_ptr
;
5054 if (!rdev
->ops
->set_cqm_rssi_config
)
5057 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
5058 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5061 return rdev
->ops
->set_cqm_rssi_config(wdev
->wiphy
, dev
,
5062 threshold
, hysteresis
);
5065 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
5067 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
5071 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
5077 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
5078 nl80211_attr_cqm_policy
);
5082 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
5083 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
5086 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
5087 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
5088 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
5096 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
5098 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5099 struct net_device
*dev
= info
->user_ptr
[1];
5100 struct mesh_config cfg
;
5101 struct mesh_setup setup
;
5104 /* start with default */
5105 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
5106 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
5108 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
5109 /* and parse parameters if given */
5110 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
5115 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
5116 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
5119 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
5120 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
5122 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
5123 /* parse additional setup parameters if given */
5124 err
= nl80211_parse_mesh_setup(info
, &setup
);
5129 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
5132 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
5134 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5135 struct net_device
*dev
= info
->user_ptr
[1];
5137 return cfg80211_leave_mesh(rdev
, dev
);
5140 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
5142 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5143 struct sk_buff
*msg
;
5146 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
5149 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5153 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
5154 NL80211_CMD_GET_WOWLAN
);
5156 goto nla_put_failure
;
5159 struct nlattr
*nl_wowlan
;
5161 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
5163 goto nla_put_failure
;
5165 if (rdev
->wowlan
->any
)
5166 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_ANY
);
5167 if (rdev
->wowlan
->disconnect
)
5168 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
);
5169 if (rdev
->wowlan
->magic_pkt
)
5170 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
);
5171 if (rdev
->wowlan
->n_patterns
) {
5172 struct nlattr
*nl_pats
, *nl_pat
;
5175 nl_pats
= nla_nest_start(msg
,
5176 NL80211_WOWLAN_TRIG_PKT_PATTERN
);
5178 goto nla_put_failure
;
5180 for (i
= 0; i
< rdev
->wowlan
->n_patterns
; i
++) {
5181 nl_pat
= nla_nest_start(msg
, i
+ 1);
5183 goto nla_put_failure
;
5184 pat_len
= rdev
->wowlan
->patterns
[i
].pattern_len
;
5185 NLA_PUT(msg
, NL80211_WOWLAN_PKTPAT_MASK
,
5186 DIV_ROUND_UP(pat_len
, 8),
5187 rdev
->wowlan
->patterns
[i
].mask
);
5188 NLA_PUT(msg
, NL80211_WOWLAN_PKTPAT_PATTERN
,
5190 rdev
->wowlan
->patterns
[i
].pattern
);
5191 nla_nest_end(msg
, nl_pat
);
5193 nla_nest_end(msg
, nl_pats
);
5196 nla_nest_end(msg
, nl_wowlan
);
5199 genlmsg_end(msg
, hdr
);
5200 return genlmsg_reply(msg
, info
);
5207 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
5209 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5210 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
5211 struct cfg80211_wowlan no_triggers
= {};
5212 struct cfg80211_wowlan new_triggers
= {};
5213 struct wiphy_wowlan_support
*wowlan
= &rdev
->wiphy
.wowlan
;
5216 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
5219 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
])
5222 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
5223 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
5224 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
5225 nl80211_wowlan_policy
);
5229 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
5230 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
5232 new_triggers
.any
= true;
5235 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
5236 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
5238 new_triggers
.disconnect
= true;
5241 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
5242 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
5244 new_triggers
.magic_pkt
= true;
5247 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
5250 int rem
, pat_len
, mask_len
;
5251 struct nlattr
*pat_tb
[NUM_NL80211_WOWLAN_PKTPAT
];
5253 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
5256 if (n_patterns
> wowlan
->n_patterns
)
5259 new_triggers
.patterns
= kcalloc(n_patterns
,
5260 sizeof(new_triggers
.patterns
[0]),
5262 if (!new_triggers
.patterns
)
5265 new_triggers
.n_patterns
= n_patterns
;
5268 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
5270 nla_parse(pat_tb
, MAX_NL80211_WOWLAN_PKTPAT
,
5271 nla_data(pat
), nla_len(pat
), NULL
);
5273 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
] ||
5274 !pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
])
5276 pat_len
= nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]);
5277 mask_len
= DIV_ROUND_UP(pat_len
, 8);
5278 if (nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]) !=
5281 if (pat_len
> wowlan
->pattern_max_len
||
5282 pat_len
< wowlan
->pattern_min_len
)
5285 new_triggers
.patterns
[i
].mask
=
5286 kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
5287 if (!new_triggers
.patterns
[i
].mask
) {
5291 new_triggers
.patterns
[i
].pattern
=
5292 new_triggers
.patterns
[i
].mask
+ mask_len
;
5293 memcpy(new_triggers
.patterns
[i
].mask
,
5294 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]),
5296 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
5297 memcpy(new_triggers
.patterns
[i
].pattern
,
5298 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]),
5304 if (memcmp(&new_triggers
, &no_triggers
, sizeof(new_triggers
))) {
5305 struct cfg80211_wowlan
*ntrig
;
5306 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
),
5312 cfg80211_rdev_free_wowlan(rdev
);
5313 rdev
->wowlan
= ntrig
;
5316 cfg80211_rdev_free_wowlan(rdev
);
5317 rdev
->wowlan
= NULL
;
5322 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
5323 kfree(new_triggers
.patterns
[i
].mask
);
5324 kfree(new_triggers
.patterns
);
5328 #define NL80211_FLAG_NEED_WIPHY 0x01
5329 #define NL80211_FLAG_NEED_NETDEV 0x02
5330 #define NL80211_FLAG_NEED_RTNL 0x04
5331 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
5332 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
5333 NL80211_FLAG_CHECK_NETDEV_UP)
5335 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
5336 struct genl_info
*info
)
5338 struct cfg80211_registered_device
*rdev
;
5339 struct net_device
*dev
;
5341 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
5346 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
5347 rdev
= cfg80211_get_dev_from_info(info
);
5351 return PTR_ERR(rdev
);
5353 info
->user_ptr
[0] = rdev
;
5354 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
5355 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
5361 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
5362 !netif_running(dev
)) {
5363 cfg80211_unlock_rdev(rdev
);
5369 info
->user_ptr
[0] = rdev
;
5370 info
->user_ptr
[1] = dev
;
5376 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
5377 struct genl_info
*info
)
5379 if (info
->user_ptr
[0])
5380 cfg80211_unlock_rdev(info
->user_ptr
[0]);
5381 if (info
->user_ptr
[1])
5382 dev_put(info
->user_ptr
[1]);
5383 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
5387 static struct genl_ops nl80211_ops
[] = {
5389 .cmd
= NL80211_CMD_GET_WIPHY
,
5390 .doit
= nl80211_get_wiphy
,
5391 .dumpit
= nl80211_dump_wiphy
,
5392 .policy
= nl80211_policy
,
5393 /* can be retrieved by unprivileged users */
5394 .internal_flags
= NL80211_FLAG_NEED_WIPHY
,
5397 .cmd
= NL80211_CMD_SET_WIPHY
,
5398 .doit
= nl80211_set_wiphy
,
5399 .policy
= nl80211_policy
,
5400 .flags
= GENL_ADMIN_PERM
,
5401 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
5404 .cmd
= NL80211_CMD_GET_INTERFACE
,
5405 .doit
= nl80211_get_interface
,
5406 .dumpit
= nl80211_dump_interface
,
5407 .policy
= nl80211_policy
,
5408 /* can be retrieved by unprivileged users */
5409 .internal_flags
= NL80211_FLAG_NEED_NETDEV
,
5412 .cmd
= NL80211_CMD_SET_INTERFACE
,
5413 .doit
= nl80211_set_interface
,
5414 .policy
= nl80211_policy
,
5415 .flags
= GENL_ADMIN_PERM
,
5416 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5417 NL80211_FLAG_NEED_RTNL
,
5420 .cmd
= NL80211_CMD_NEW_INTERFACE
,
5421 .doit
= nl80211_new_interface
,
5422 .policy
= nl80211_policy
,
5423 .flags
= GENL_ADMIN_PERM
,
5424 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
5425 NL80211_FLAG_NEED_RTNL
,
5428 .cmd
= NL80211_CMD_DEL_INTERFACE
,
5429 .doit
= nl80211_del_interface
,
5430 .policy
= nl80211_policy
,
5431 .flags
= GENL_ADMIN_PERM
,
5432 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5433 NL80211_FLAG_NEED_RTNL
,
5436 .cmd
= NL80211_CMD_GET_KEY
,
5437 .doit
= nl80211_get_key
,
5438 .policy
= nl80211_policy
,
5439 .flags
= GENL_ADMIN_PERM
,
5440 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5441 NL80211_FLAG_NEED_RTNL
,
5444 .cmd
= NL80211_CMD_SET_KEY
,
5445 .doit
= nl80211_set_key
,
5446 .policy
= nl80211_policy
,
5447 .flags
= GENL_ADMIN_PERM
,
5448 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5449 NL80211_FLAG_NEED_RTNL
,
5452 .cmd
= NL80211_CMD_NEW_KEY
,
5453 .doit
= nl80211_new_key
,
5454 .policy
= nl80211_policy
,
5455 .flags
= GENL_ADMIN_PERM
,
5456 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5457 NL80211_FLAG_NEED_RTNL
,
5460 .cmd
= NL80211_CMD_DEL_KEY
,
5461 .doit
= nl80211_del_key
,
5462 .policy
= nl80211_policy
,
5463 .flags
= GENL_ADMIN_PERM
,
5464 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5465 NL80211_FLAG_NEED_RTNL
,
5468 .cmd
= NL80211_CMD_SET_BEACON
,
5469 .policy
= nl80211_policy
,
5470 .flags
= GENL_ADMIN_PERM
,
5471 .doit
= nl80211_addset_beacon
,
5472 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5473 NL80211_FLAG_NEED_RTNL
,
5476 .cmd
= NL80211_CMD_NEW_BEACON
,
5477 .policy
= nl80211_policy
,
5478 .flags
= GENL_ADMIN_PERM
,
5479 .doit
= nl80211_addset_beacon
,
5480 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5481 NL80211_FLAG_NEED_RTNL
,
5484 .cmd
= NL80211_CMD_DEL_BEACON
,
5485 .policy
= nl80211_policy
,
5486 .flags
= GENL_ADMIN_PERM
,
5487 .doit
= nl80211_del_beacon
,
5488 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5489 NL80211_FLAG_NEED_RTNL
,
5492 .cmd
= NL80211_CMD_GET_STATION
,
5493 .doit
= nl80211_get_station
,
5494 .dumpit
= nl80211_dump_station
,
5495 .policy
= nl80211_policy
,
5496 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5497 NL80211_FLAG_NEED_RTNL
,
5500 .cmd
= NL80211_CMD_SET_STATION
,
5501 .doit
= nl80211_set_station
,
5502 .policy
= nl80211_policy
,
5503 .flags
= GENL_ADMIN_PERM
,
5504 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5505 NL80211_FLAG_NEED_RTNL
,
5508 .cmd
= NL80211_CMD_NEW_STATION
,
5509 .doit
= nl80211_new_station
,
5510 .policy
= nl80211_policy
,
5511 .flags
= GENL_ADMIN_PERM
,
5512 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5513 NL80211_FLAG_NEED_RTNL
,
5516 .cmd
= NL80211_CMD_DEL_STATION
,
5517 .doit
= nl80211_del_station
,
5518 .policy
= nl80211_policy
,
5519 .flags
= GENL_ADMIN_PERM
,
5520 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5521 NL80211_FLAG_NEED_RTNL
,
5524 .cmd
= NL80211_CMD_GET_MPATH
,
5525 .doit
= nl80211_get_mpath
,
5526 .dumpit
= nl80211_dump_mpath
,
5527 .policy
= nl80211_policy
,
5528 .flags
= GENL_ADMIN_PERM
,
5529 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5530 NL80211_FLAG_NEED_RTNL
,
5533 .cmd
= NL80211_CMD_SET_MPATH
,
5534 .doit
= nl80211_set_mpath
,
5535 .policy
= nl80211_policy
,
5536 .flags
= GENL_ADMIN_PERM
,
5537 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5538 NL80211_FLAG_NEED_RTNL
,
5541 .cmd
= NL80211_CMD_NEW_MPATH
,
5542 .doit
= nl80211_new_mpath
,
5543 .policy
= nl80211_policy
,
5544 .flags
= GENL_ADMIN_PERM
,
5545 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5546 NL80211_FLAG_NEED_RTNL
,
5549 .cmd
= NL80211_CMD_DEL_MPATH
,
5550 .doit
= nl80211_del_mpath
,
5551 .policy
= nl80211_policy
,
5552 .flags
= GENL_ADMIN_PERM
,
5553 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5554 NL80211_FLAG_NEED_RTNL
,
5557 .cmd
= NL80211_CMD_SET_BSS
,
5558 .doit
= nl80211_set_bss
,
5559 .policy
= nl80211_policy
,
5560 .flags
= GENL_ADMIN_PERM
,
5561 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5562 NL80211_FLAG_NEED_RTNL
,
5565 .cmd
= NL80211_CMD_GET_REG
,
5566 .doit
= nl80211_get_reg
,
5567 .policy
= nl80211_policy
,
5568 /* can be retrieved by unprivileged users */
5571 .cmd
= NL80211_CMD_SET_REG
,
5572 .doit
= nl80211_set_reg
,
5573 .policy
= nl80211_policy
,
5574 .flags
= GENL_ADMIN_PERM
,
5577 .cmd
= NL80211_CMD_REQ_SET_REG
,
5578 .doit
= nl80211_req_set_reg
,
5579 .policy
= nl80211_policy
,
5580 .flags
= GENL_ADMIN_PERM
,
5583 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
5584 .doit
= nl80211_get_mesh_config
,
5585 .policy
= nl80211_policy
,
5586 /* can be retrieved by unprivileged users */
5587 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5588 NL80211_FLAG_NEED_RTNL
,
5591 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
5592 .doit
= nl80211_update_mesh_config
,
5593 .policy
= nl80211_policy
,
5594 .flags
= GENL_ADMIN_PERM
,
5595 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5596 NL80211_FLAG_NEED_RTNL
,
5599 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
5600 .doit
= nl80211_trigger_scan
,
5601 .policy
= nl80211_policy
,
5602 .flags
= GENL_ADMIN_PERM
,
5603 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5604 NL80211_FLAG_NEED_RTNL
,
5607 .cmd
= NL80211_CMD_GET_SCAN
,
5608 .policy
= nl80211_policy
,
5609 .dumpit
= nl80211_dump_scan
,
5612 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
5613 .doit
= nl80211_start_sched_scan
,
5614 .policy
= nl80211_policy
,
5615 .flags
= GENL_ADMIN_PERM
,
5616 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5617 NL80211_FLAG_NEED_RTNL
,
5620 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
5621 .doit
= nl80211_stop_sched_scan
,
5622 .policy
= nl80211_policy
,
5623 .flags
= GENL_ADMIN_PERM
,
5624 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5625 NL80211_FLAG_NEED_RTNL
,
5628 .cmd
= NL80211_CMD_AUTHENTICATE
,
5629 .doit
= nl80211_authenticate
,
5630 .policy
= nl80211_policy
,
5631 .flags
= GENL_ADMIN_PERM
,
5632 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5633 NL80211_FLAG_NEED_RTNL
,
5636 .cmd
= NL80211_CMD_ASSOCIATE
,
5637 .doit
= nl80211_associate
,
5638 .policy
= nl80211_policy
,
5639 .flags
= GENL_ADMIN_PERM
,
5640 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5641 NL80211_FLAG_NEED_RTNL
,
5644 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
5645 .doit
= nl80211_deauthenticate
,
5646 .policy
= nl80211_policy
,
5647 .flags
= GENL_ADMIN_PERM
,
5648 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5649 NL80211_FLAG_NEED_RTNL
,
5652 .cmd
= NL80211_CMD_DISASSOCIATE
,
5653 .doit
= nl80211_disassociate
,
5654 .policy
= nl80211_policy
,
5655 .flags
= GENL_ADMIN_PERM
,
5656 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5657 NL80211_FLAG_NEED_RTNL
,
5660 .cmd
= NL80211_CMD_JOIN_IBSS
,
5661 .doit
= nl80211_join_ibss
,
5662 .policy
= nl80211_policy
,
5663 .flags
= GENL_ADMIN_PERM
,
5664 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5665 NL80211_FLAG_NEED_RTNL
,
5668 .cmd
= NL80211_CMD_LEAVE_IBSS
,
5669 .doit
= nl80211_leave_ibss
,
5670 .policy
= nl80211_policy
,
5671 .flags
= GENL_ADMIN_PERM
,
5672 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5673 NL80211_FLAG_NEED_RTNL
,
5675 #ifdef CONFIG_NL80211_TESTMODE
5677 .cmd
= NL80211_CMD_TESTMODE
,
5678 .doit
= nl80211_testmode_do
,
5679 .policy
= nl80211_policy
,
5680 .flags
= GENL_ADMIN_PERM
,
5681 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
5682 NL80211_FLAG_NEED_RTNL
,
5686 .cmd
= NL80211_CMD_CONNECT
,
5687 .doit
= nl80211_connect
,
5688 .policy
= nl80211_policy
,
5689 .flags
= GENL_ADMIN_PERM
,
5690 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5691 NL80211_FLAG_NEED_RTNL
,
5694 .cmd
= NL80211_CMD_DISCONNECT
,
5695 .doit
= nl80211_disconnect
,
5696 .policy
= nl80211_policy
,
5697 .flags
= GENL_ADMIN_PERM
,
5698 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5699 NL80211_FLAG_NEED_RTNL
,
5702 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
5703 .doit
= nl80211_wiphy_netns
,
5704 .policy
= nl80211_policy
,
5705 .flags
= GENL_ADMIN_PERM
,
5706 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
5707 NL80211_FLAG_NEED_RTNL
,
5710 .cmd
= NL80211_CMD_GET_SURVEY
,
5711 .policy
= nl80211_policy
,
5712 .dumpit
= nl80211_dump_survey
,
5715 .cmd
= NL80211_CMD_SET_PMKSA
,
5716 .doit
= nl80211_setdel_pmksa
,
5717 .policy
= nl80211_policy
,
5718 .flags
= GENL_ADMIN_PERM
,
5719 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5720 NL80211_FLAG_NEED_RTNL
,
5723 .cmd
= NL80211_CMD_DEL_PMKSA
,
5724 .doit
= nl80211_setdel_pmksa
,
5725 .policy
= nl80211_policy
,
5726 .flags
= GENL_ADMIN_PERM
,
5727 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5728 NL80211_FLAG_NEED_RTNL
,
5731 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
5732 .doit
= nl80211_flush_pmksa
,
5733 .policy
= nl80211_policy
,
5734 .flags
= GENL_ADMIN_PERM
,
5735 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5736 NL80211_FLAG_NEED_RTNL
,
5739 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
5740 .doit
= nl80211_remain_on_channel
,
5741 .policy
= nl80211_policy
,
5742 .flags
= GENL_ADMIN_PERM
,
5743 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5744 NL80211_FLAG_NEED_RTNL
,
5747 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
5748 .doit
= nl80211_cancel_remain_on_channel
,
5749 .policy
= nl80211_policy
,
5750 .flags
= GENL_ADMIN_PERM
,
5751 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5752 NL80211_FLAG_NEED_RTNL
,
5755 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
5756 .doit
= nl80211_set_tx_bitrate_mask
,
5757 .policy
= nl80211_policy
,
5758 .flags
= GENL_ADMIN_PERM
,
5759 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5760 NL80211_FLAG_NEED_RTNL
,
5763 .cmd
= NL80211_CMD_REGISTER_FRAME
,
5764 .doit
= nl80211_register_mgmt
,
5765 .policy
= nl80211_policy
,
5766 .flags
= GENL_ADMIN_PERM
,
5767 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5768 NL80211_FLAG_NEED_RTNL
,
5771 .cmd
= NL80211_CMD_FRAME
,
5772 .doit
= nl80211_tx_mgmt
,
5773 .policy
= nl80211_policy
,
5774 .flags
= GENL_ADMIN_PERM
,
5775 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5776 NL80211_FLAG_NEED_RTNL
,
5779 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
5780 .doit
= nl80211_tx_mgmt_cancel_wait
,
5781 .policy
= nl80211_policy
,
5782 .flags
= GENL_ADMIN_PERM
,
5783 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5784 NL80211_FLAG_NEED_RTNL
,
5787 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
5788 .doit
= nl80211_set_power_save
,
5789 .policy
= nl80211_policy
,
5790 .flags
= GENL_ADMIN_PERM
,
5791 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5792 NL80211_FLAG_NEED_RTNL
,
5795 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
5796 .doit
= nl80211_get_power_save
,
5797 .policy
= nl80211_policy
,
5798 /* can be retrieved by unprivileged users */
5799 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5800 NL80211_FLAG_NEED_RTNL
,
5803 .cmd
= NL80211_CMD_SET_CQM
,
5804 .doit
= nl80211_set_cqm
,
5805 .policy
= nl80211_policy
,
5806 .flags
= GENL_ADMIN_PERM
,
5807 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5808 NL80211_FLAG_NEED_RTNL
,
5811 .cmd
= NL80211_CMD_SET_CHANNEL
,
5812 .doit
= nl80211_set_channel
,
5813 .policy
= nl80211_policy
,
5814 .flags
= GENL_ADMIN_PERM
,
5815 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5816 NL80211_FLAG_NEED_RTNL
,
5819 .cmd
= NL80211_CMD_SET_WDS_PEER
,
5820 .doit
= nl80211_set_wds_peer
,
5821 .policy
= nl80211_policy
,
5822 .flags
= GENL_ADMIN_PERM
,
5823 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5824 NL80211_FLAG_NEED_RTNL
,
5827 .cmd
= NL80211_CMD_JOIN_MESH
,
5828 .doit
= nl80211_join_mesh
,
5829 .policy
= nl80211_policy
,
5830 .flags
= GENL_ADMIN_PERM
,
5831 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5832 NL80211_FLAG_NEED_RTNL
,
5835 .cmd
= NL80211_CMD_LEAVE_MESH
,
5836 .doit
= nl80211_leave_mesh
,
5837 .policy
= nl80211_policy
,
5838 .flags
= GENL_ADMIN_PERM
,
5839 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5840 NL80211_FLAG_NEED_RTNL
,
5843 .cmd
= NL80211_CMD_GET_WOWLAN
,
5844 .doit
= nl80211_get_wowlan
,
5845 .policy
= nl80211_policy
,
5846 /* can be retrieved by unprivileged users */
5847 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
5848 NL80211_FLAG_NEED_RTNL
,
5851 .cmd
= NL80211_CMD_SET_WOWLAN
,
5852 .doit
= nl80211_set_wowlan
,
5853 .policy
= nl80211_policy
,
5854 .flags
= GENL_ADMIN_PERM
,
5855 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
5856 NL80211_FLAG_NEED_RTNL
,
5860 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
5864 /* multicast groups */
5865 static struct genl_multicast_group nl80211_config_mcgrp
= {
5868 static struct genl_multicast_group nl80211_scan_mcgrp
= {
5871 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
5872 .name
= "regulatory",
5875 /* notification functions */
5877 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
5879 struct sk_buff
*msg
;
5881 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5885 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
5890 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5891 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
5894 static int nl80211_add_scan_req(struct sk_buff
*msg
,
5895 struct cfg80211_registered_device
*rdev
)
5897 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
5898 struct nlattr
*nest
;
5901 ASSERT_RDEV_LOCK(rdev
);
5906 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
5908 goto nla_put_failure
;
5909 for (i
= 0; i
< req
->n_ssids
; i
++)
5910 NLA_PUT(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
);
5911 nla_nest_end(msg
, nest
);
5913 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
5915 goto nla_put_failure
;
5916 for (i
= 0; i
< req
->n_channels
; i
++)
5917 NLA_PUT_U32(msg
, i
, req
->channels
[i
]->center_freq
);
5918 nla_nest_end(msg
, nest
);
5921 NLA_PUT(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
);
5928 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
5929 struct cfg80211_registered_device
*rdev
,
5930 struct net_device
*netdev
,
5931 u32 pid
, u32 seq
, int flags
,
5936 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
5940 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5941 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5943 /* ignore errors and send incomplete event anyway */
5944 nl80211_add_scan_req(msg
, rdev
);
5946 return genlmsg_end(msg
, hdr
);
5949 genlmsg_cancel(msg
, hdr
);
5954 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
5955 struct cfg80211_registered_device
*rdev
,
5956 struct net_device
*netdev
,
5957 u32 pid
, u32 seq
, int flags
, u32 cmd
)
5961 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
5965 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5966 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5968 return genlmsg_end(msg
, hdr
);
5971 genlmsg_cancel(msg
, hdr
);
5975 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
5976 struct net_device
*netdev
)
5978 struct sk_buff
*msg
;
5980 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
5984 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5985 NL80211_CMD_TRIGGER_SCAN
) < 0) {
5990 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5991 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5994 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
5995 struct net_device
*netdev
)
5997 struct sk_buff
*msg
;
5999 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6003 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
6004 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
6009 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6010 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6013 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
6014 struct net_device
*netdev
)
6016 struct sk_buff
*msg
;
6018 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6022 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
6023 NL80211_CMD_SCAN_ABORTED
) < 0) {
6028 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6029 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6032 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
6033 struct net_device
*netdev
)
6035 struct sk_buff
*msg
;
6037 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6041 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
6042 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
6047 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6048 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6051 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
6052 struct net_device
*netdev
, u32 cmd
)
6054 struct sk_buff
*msg
;
6056 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
6060 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
6065 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6066 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6070 * This can happen on global regulatory changes or device specific settings
6071 * based on custom world regulatory domains.
6073 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
6075 struct sk_buff
*msg
;
6078 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6082 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
6088 /* Userspace can always count this one always being set */
6089 NLA_PUT_U8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
);
6091 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0')
6092 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6093 NL80211_REGDOM_TYPE_WORLD
);
6094 else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9')
6095 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6096 NL80211_REGDOM_TYPE_CUSTOM_WORLD
);
6097 else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
6099 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6100 NL80211_REGDOM_TYPE_INTERSECTION
);
6102 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6103 NL80211_REGDOM_TYPE_COUNTRY
);
6104 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, request
->alpha2
);
6107 if (wiphy_idx_valid(request
->wiphy_idx
))
6108 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
);
6110 if (genlmsg_end(msg
, hdr
) < 0) {
6116 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
6123 genlmsg_cancel(msg
, hdr
);
6127 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
6128 struct net_device
*netdev
,
6129 const u8
*buf
, size_t len
,
6130 enum nl80211_commands cmd
, gfp_t gfp
)
6132 struct sk_buff
*msg
;
6135 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6139 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
6145 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6146 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6147 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
6149 if (genlmsg_end(msg
, hdr
) < 0) {
6154 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6155 nl80211_mlme_mcgrp
.id
, gfp
);
6159 genlmsg_cancel(msg
, hdr
);
6163 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
6164 struct net_device
*netdev
, const u8
*buf
,
6165 size_t len
, gfp_t gfp
)
6167 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6168 NL80211_CMD_AUTHENTICATE
, gfp
);
6171 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
6172 struct net_device
*netdev
, const u8
*buf
,
6173 size_t len
, gfp_t gfp
)
6175 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6176 NL80211_CMD_ASSOCIATE
, gfp
);
6179 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
6180 struct net_device
*netdev
, const u8
*buf
,
6181 size_t len
, gfp_t gfp
)
6183 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6184 NL80211_CMD_DEAUTHENTICATE
, gfp
);
6187 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
6188 struct net_device
*netdev
, const u8
*buf
,
6189 size_t len
, gfp_t gfp
)
6191 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6192 NL80211_CMD_DISASSOCIATE
, gfp
);
6195 void nl80211_send_unprot_deauth(struct cfg80211_registered_device
*rdev
,
6196 struct net_device
*netdev
, const u8
*buf
,
6197 size_t len
, gfp_t gfp
)
6199 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6200 NL80211_CMD_UNPROT_DEAUTHENTICATE
, gfp
);
6203 void nl80211_send_unprot_disassoc(struct cfg80211_registered_device
*rdev
,
6204 struct net_device
*netdev
, const u8
*buf
,
6205 size_t len
, gfp_t gfp
)
6207 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6208 NL80211_CMD_UNPROT_DISASSOCIATE
, gfp
);
6211 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
6212 struct net_device
*netdev
, int cmd
,
6213 const u8
*addr
, gfp_t gfp
)
6215 struct sk_buff
*msg
;
6218 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6222 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
6228 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6229 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6230 NLA_PUT_FLAG(msg
, NL80211_ATTR_TIMED_OUT
);
6231 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
6233 if (genlmsg_end(msg
, hdr
) < 0) {
6238 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6239 nl80211_mlme_mcgrp
.id
, gfp
);
6243 genlmsg_cancel(msg
, hdr
);
6247 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
6248 struct net_device
*netdev
, const u8
*addr
,
6251 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
6255 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
6256 struct net_device
*netdev
, const u8
*addr
,
6259 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
6263 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
6264 struct net_device
*netdev
, const u8
*bssid
,
6265 const u8
*req_ie
, size_t req_ie_len
,
6266 const u8
*resp_ie
, size_t resp_ie_len
,
6267 u16 status
, gfp_t gfp
)
6269 struct sk_buff
*msg
;
6272 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6276 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
6282 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6283 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6285 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
6286 NLA_PUT_U16(msg
, NL80211_ATTR_STATUS_CODE
, status
);
6288 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
6290 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
6292 if (genlmsg_end(msg
, hdr
) < 0) {
6297 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6298 nl80211_mlme_mcgrp
.id
, gfp
);
6302 genlmsg_cancel(msg
, hdr
);
6307 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
6308 struct net_device
*netdev
, const u8
*bssid
,
6309 const u8
*req_ie
, size_t req_ie_len
,
6310 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
6312 struct sk_buff
*msg
;
6315 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6319 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
6325 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6326 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6327 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
6329 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
6331 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
6333 if (genlmsg_end(msg
, hdr
) < 0) {
6338 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6339 nl80211_mlme_mcgrp
.id
, gfp
);
6343 genlmsg_cancel(msg
, hdr
);
6348 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
6349 struct net_device
*netdev
, u16 reason
,
6350 const u8
*ie
, size_t ie_len
, bool from_ap
)
6352 struct sk_buff
*msg
;
6355 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
6359 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
6365 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6366 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6367 if (from_ap
&& reason
)
6368 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason
);
6370 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
);
6372 NLA_PUT(msg
, NL80211_ATTR_IE
, ie_len
, ie
);
6374 if (genlmsg_end(msg
, hdr
) < 0) {
6379 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6380 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
6384 genlmsg_cancel(msg
, hdr
);
6389 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
6390 struct net_device
*netdev
, const u8
*bssid
,
6393 struct sk_buff
*msg
;
6396 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6400 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
6406 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6407 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6408 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
6410 if (genlmsg_end(msg
, hdr
) < 0) {
6415 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6416 nl80211_mlme_mcgrp
.id
, gfp
);
6420 genlmsg_cancel(msg
, hdr
);
6424 void nl80211_send_new_peer_candidate(struct cfg80211_registered_device
*rdev
,
6425 struct net_device
*netdev
,
6426 const u8
*macaddr
, const u8
* ie
, u8 ie_len
,
6429 struct sk_buff
*msg
;
6432 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6436 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
6442 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6443 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6444 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, macaddr
);
6446 NLA_PUT(msg
, NL80211_ATTR_IE
, ie_len
, ie
);
6448 if (genlmsg_end(msg
, hdr
) < 0) {
6453 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6454 nl80211_mlme_mcgrp
.id
, gfp
);
6458 genlmsg_cancel(msg
, hdr
);
6462 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
6463 struct net_device
*netdev
, const u8
*addr
,
6464 enum nl80211_key_type key_type
, int key_id
,
6465 const u8
*tsc
, gfp_t gfp
)
6467 struct sk_buff
*msg
;
6470 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6474 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
6480 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6481 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6483 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
6484 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
);
6486 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_id
);
6488 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
);
6490 if (genlmsg_end(msg
, hdr
) < 0) {
6495 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6496 nl80211_mlme_mcgrp
.id
, gfp
);
6500 genlmsg_cancel(msg
, hdr
);
6504 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
6505 struct ieee80211_channel
*channel_before
,
6506 struct ieee80211_channel
*channel_after
)
6508 struct sk_buff
*msg
;
6510 struct nlattr
*nl_freq
;
6512 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
6516 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
6523 * Since we are applying the beacon hint to a wiphy we know its
6524 * wiphy_idx is valid
6526 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
));
6529 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
6531 goto nla_put_failure
;
6532 if (nl80211_msg_put_channel(msg
, channel_before
))
6533 goto nla_put_failure
;
6534 nla_nest_end(msg
, nl_freq
);
6537 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
6539 goto nla_put_failure
;
6540 if (nl80211_msg_put_channel(msg
, channel_after
))
6541 goto nla_put_failure
;
6542 nla_nest_end(msg
, nl_freq
);
6544 if (genlmsg_end(msg
, hdr
) < 0) {
6550 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
6557 genlmsg_cancel(msg
, hdr
);
6561 static void nl80211_send_remain_on_chan_event(
6562 int cmd
, struct cfg80211_registered_device
*rdev
,
6563 struct net_device
*netdev
, u64 cookie
,
6564 struct ieee80211_channel
*chan
,
6565 enum nl80211_channel_type channel_type
,
6566 unsigned int duration
, gfp_t gfp
)
6568 struct sk_buff
*msg
;
6571 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6575 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
6581 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6582 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6583 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
);
6584 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, channel_type
);
6585 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
6587 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
)
6588 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, duration
);
6590 if (genlmsg_end(msg
, hdr
) < 0) {
6595 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6596 nl80211_mlme_mcgrp
.id
, gfp
);
6600 genlmsg_cancel(msg
, hdr
);
6604 void nl80211_send_remain_on_channel(struct cfg80211_registered_device
*rdev
,
6605 struct net_device
*netdev
, u64 cookie
,
6606 struct ieee80211_channel
*chan
,
6607 enum nl80211_channel_type channel_type
,
6608 unsigned int duration
, gfp_t gfp
)
6610 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
6611 rdev
, netdev
, cookie
, chan
,
6612 channel_type
, duration
, gfp
);
6615 void nl80211_send_remain_on_channel_cancel(
6616 struct cfg80211_registered_device
*rdev
, struct net_device
*netdev
,
6617 u64 cookie
, struct ieee80211_channel
*chan
,
6618 enum nl80211_channel_type channel_type
, gfp_t gfp
)
6620 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
6621 rdev
, netdev
, cookie
, chan
,
6622 channel_type
, 0, gfp
);
6625 void nl80211_send_sta_event(struct cfg80211_registered_device
*rdev
,
6626 struct net_device
*dev
, const u8
*mac_addr
,
6627 struct station_info
*sinfo
, gfp_t gfp
)
6629 struct sk_buff
*msg
;
6631 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6635 if (nl80211_send_station(msg
, 0, 0, 0, dev
, mac_addr
, sinfo
) < 0) {
6640 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6641 nl80211_mlme_mcgrp
.id
, gfp
);
6644 void nl80211_send_sta_del_event(struct cfg80211_registered_device
*rdev
,
6645 struct net_device
*dev
, const u8
*mac_addr
,
6648 struct sk_buff
*msg
;
6651 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6655 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_STATION
);
6661 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
6662 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
6664 if (genlmsg_end(msg
, hdr
) < 0) {
6669 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6670 nl80211_mlme_mcgrp
.id
, gfp
);
6674 genlmsg_cancel(msg
, hdr
);
6678 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
6679 struct net_device
*netdev
, u32 nlpid
,
6680 int freq
, const u8
*buf
, size_t len
, gfp_t gfp
)
6682 struct sk_buff
*msg
;
6686 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6690 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
6696 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6697 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6698 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
6699 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
6701 err
= genlmsg_end(msg
, hdr
);
6707 err
= genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
6713 genlmsg_cancel(msg
, hdr
);
6718 void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device
*rdev
,
6719 struct net_device
*netdev
, u64 cookie
,
6720 const u8
*buf
, size_t len
, bool ack
,
6723 struct sk_buff
*msg
;
6726 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6730 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
6736 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6737 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6738 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
6739 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
6741 NLA_PUT_FLAG(msg
, NL80211_ATTR_ACK
);
6743 if (genlmsg_end(msg
, hdr
) < 0) {
6748 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
6752 genlmsg_cancel(msg
, hdr
);
6757 nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device
*rdev
,
6758 struct net_device
*netdev
,
6759 enum nl80211_cqm_rssi_threshold_event rssi_event
,
6762 struct sk_buff
*msg
;
6763 struct nlattr
*pinfoattr
;
6766 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6770 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
6776 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6777 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6779 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
6781 goto nla_put_failure
;
6783 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
6786 nla_nest_end(msg
, pinfoattr
);
6788 if (genlmsg_end(msg
, hdr
) < 0) {
6793 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6794 nl80211_mlme_mcgrp
.id
, gfp
);
6798 genlmsg_cancel(msg
, hdr
);
6803 nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device
*rdev
,
6804 struct net_device
*netdev
, const u8
*peer
,
6805 u32 num_packets
, gfp_t gfp
)
6807 struct sk_buff
*msg
;
6808 struct nlattr
*pinfoattr
;
6811 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6815 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
6821 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6822 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6823 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
);
6825 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
6827 goto nla_put_failure
;
6829 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
);
6831 nla_nest_end(msg
, pinfoattr
);
6833 if (genlmsg_end(msg
, hdr
) < 0) {
6838 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6839 nl80211_mlme_mcgrp
.id
, gfp
);
6843 genlmsg_cancel(msg
, hdr
);
6847 static int nl80211_netlink_notify(struct notifier_block
* nb
,
6848 unsigned long state
,
6851 struct netlink_notify
*notify
= _notify
;
6852 struct cfg80211_registered_device
*rdev
;
6853 struct wireless_dev
*wdev
;
6855 if (state
!= NETLINK_URELEASE
)
6860 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
)
6861 list_for_each_entry_rcu(wdev
, &rdev
->netdev_list
, list
)
6862 cfg80211_mlme_unregister_socket(wdev
, notify
->pid
);
6869 static struct notifier_block nl80211_netlink_notifier
= {
6870 .notifier_call
= nl80211_netlink_notify
,
6873 /* initialisation/exit functions */
6875 int nl80211_init(void)
6879 err
= genl_register_family_with_ops(&nl80211_fam
,
6880 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
6884 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
6888 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
6892 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
6896 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
6900 #ifdef CONFIG_NL80211_TESTMODE
6901 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
6906 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
6912 genl_unregister_family(&nl80211_fam
);
6916 void nl80211_exit(void)
6918 netlink_unregister_notifier(&nl80211_netlink_notifier
);
6919 genl_unregister_family(&nl80211_fam
);