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 nla_for_each_nested(nl_txq_params
,
1185 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
1187 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
1188 nla_data(nl_txq_params
),
1189 nla_len(nl_txq_params
),
1191 result
= parse_txq_params(tb
, &txq_params
);
1195 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
1202 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
1203 result
= __nl80211_set_channel(rdev
, wdev
, info
);
1208 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
1209 enum nl80211_tx_power_setting type
;
1212 if (!rdev
->ops
->set_tx_power
) {
1213 result
= -EOPNOTSUPP
;
1217 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
1218 type
= nla_get_u32(info
->attrs
[idx
]);
1220 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
1221 (type
!= NL80211_TX_POWER_AUTOMATIC
)) {
1226 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
1227 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
1228 mbm
= nla_get_u32(info
->attrs
[idx
]);
1231 result
= rdev
->ops
->set_tx_power(&rdev
->wiphy
, type
, mbm
);
1236 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
1237 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
1239 if ((!rdev
->wiphy
.available_antennas_tx
&&
1240 !rdev
->wiphy
.available_antennas_rx
) ||
1241 !rdev
->ops
->set_antenna
) {
1242 result
= -EOPNOTSUPP
;
1246 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
1247 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
1249 /* reject antenna configurations which don't match the
1250 * available antenna masks, except for the "all" mask */
1251 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
1252 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
))) {
1257 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
1258 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
1260 result
= rdev
->ops
->set_antenna(&rdev
->wiphy
, tx_ant
, rx_ant
);
1267 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
1268 retry_short
= nla_get_u8(
1269 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
1270 if (retry_short
== 0) {
1274 changed
|= WIPHY_PARAM_RETRY_SHORT
;
1277 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
1278 retry_long
= nla_get_u8(
1279 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
1280 if (retry_long
== 0) {
1284 changed
|= WIPHY_PARAM_RETRY_LONG
;
1287 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
1288 frag_threshold
= nla_get_u32(
1289 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
1290 if (frag_threshold
< 256) {
1294 if (frag_threshold
!= (u32
) -1) {
1296 * Fragments (apart from the last one) are required to
1297 * have even length. Make the fragmentation code
1298 * simpler by stripping LSB should someone try to use
1299 * odd threshold value.
1301 frag_threshold
&= ~0x1;
1303 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
1306 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
1307 rts_threshold
= nla_get_u32(
1308 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
1309 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
1312 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
1313 coverage_class
= nla_get_u8(
1314 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
1315 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
1319 u8 old_retry_short
, old_retry_long
;
1320 u32 old_frag_threshold
, old_rts_threshold
;
1321 u8 old_coverage_class
;
1323 if (!rdev
->ops
->set_wiphy_params
) {
1324 result
= -EOPNOTSUPP
;
1328 old_retry_short
= rdev
->wiphy
.retry_short
;
1329 old_retry_long
= rdev
->wiphy
.retry_long
;
1330 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
1331 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
1332 old_coverage_class
= rdev
->wiphy
.coverage_class
;
1334 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
1335 rdev
->wiphy
.retry_short
= retry_short
;
1336 if (changed
& WIPHY_PARAM_RETRY_LONG
)
1337 rdev
->wiphy
.retry_long
= retry_long
;
1338 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
1339 rdev
->wiphy
.frag_threshold
= frag_threshold
;
1340 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
1341 rdev
->wiphy
.rts_threshold
= rts_threshold
;
1342 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
1343 rdev
->wiphy
.coverage_class
= coverage_class
;
1345 result
= rdev
->ops
->set_wiphy_params(&rdev
->wiphy
, changed
);
1347 rdev
->wiphy
.retry_short
= old_retry_short
;
1348 rdev
->wiphy
.retry_long
= old_retry_long
;
1349 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
1350 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
1351 rdev
->wiphy
.coverage_class
= old_coverage_class
;
1356 mutex_unlock(&rdev
->mtx
);
1363 static int nl80211_send_iface(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
1364 struct cfg80211_registered_device
*rdev
,
1365 struct net_device
*dev
)
1369 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
1373 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1374 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
1375 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, dev
->name
);
1376 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, dev
->ieee80211_ptr
->iftype
);
1378 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
1379 rdev
->devlist_generation
^
1380 (cfg80211_rdev_list_generation
<< 2));
1382 return genlmsg_end(msg
, hdr
);
1385 genlmsg_cancel(msg
, hdr
);
1389 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1393 int wp_start
= cb
->args
[0];
1394 int if_start
= cb
->args
[1];
1395 struct cfg80211_registered_device
*rdev
;
1396 struct wireless_dev
*wdev
;
1398 mutex_lock(&cfg80211_mutex
);
1399 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
1400 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
1402 if (wp_idx
< wp_start
) {
1408 mutex_lock(&rdev
->devlist_mtx
);
1409 list_for_each_entry(wdev
, &rdev
->netdev_list
, list
) {
1410 if (if_idx
< if_start
) {
1414 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).pid
,
1415 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1416 rdev
, wdev
->netdev
) < 0) {
1417 mutex_unlock(&rdev
->devlist_mtx
);
1422 mutex_unlock(&rdev
->devlist_mtx
);
1427 mutex_unlock(&cfg80211_mutex
);
1429 cb
->args
[0] = wp_idx
;
1430 cb
->args
[1] = if_idx
;
1435 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1437 struct sk_buff
*msg
;
1438 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1439 struct net_device
*netdev
= info
->user_ptr
[1];
1441 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1445 if (nl80211_send_iface(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1451 return genlmsg_reply(msg
, info
);
1454 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
1455 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
1456 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
1457 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
1458 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
1459 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
1462 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
1464 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
1472 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
1473 nla
, mntr_flags_policy
))
1476 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
1478 *mntrflags
|= (1<<flag
);
1483 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
1484 struct net_device
*netdev
, u8 use_4addr
,
1485 enum nl80211_iftype iftype
)
1488 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
1494 case NL80211_IFTYPE_AP_VLAN
:
1495 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
1498 case NL80211_IFTYPE_STATION
:
1499 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
1509 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1511 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1512 struct vif_params params
;
1514 enum nl80211_iftype otype
, ntype
;
1515 struct net_device
*dev
= info
->user_ptr
[1];
1516 u32 _flags
, *flags
= NULL
;
1517 bool change
= false;
1519 memset(¶ms
, 0, sizeof(params
));
1521 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
1523 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1524 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1527 if (ntype
> NL80211_IFTYPE_MAX
)
1531 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1532 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1534 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
1536 if (netif_running(dev
))
1540 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
1541 IEEE80211_MAX_MESH_ID_LEN
);
1542 wdev
->mesh_id_up_len
=
1543 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1544 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
1545 wdev
->mesh_id_up_len
);
1549 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1550 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1552 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
1556 params
.use_4addr
= -1;
1559 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
1560 if (ntype
!= NL80211_IFTYPE_MONITOR
)
1562 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
1572 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
1576 if (!err
&& params
.use_4addr
!= -1)
1577 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
1582 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1584 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1585 struct vif_params params
;
1586 struct net_device
*dev
;
1588 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
1591 memset(¶ms
, 0, sizeof(params
));
1593 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
1596 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1597 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1598 if (type
> NL80211_IFTYPE_MAX
)
1602 if (!rdev
->ops
->add_virtual_intf
||
1603 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
1606 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1607 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1608 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
1613 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
1614 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
1616 dev
= rdev
->ops
->add_virtual_intf(&rdev
->wiphy
,
1617 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
1618 type
, err
? NULL
: &flags
, ¶ms
);
1620 return PTR_ERR(dev
);
1622 if (type
== NL80211_IFTYPE_MESH_POINT
&&
1623 info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1624 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1627 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
1628 IEEE80211_MAX_MESH_ID_LEN
);
1629 wdev
->mesh_id_up_len
=
1630 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1631 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
1632 wdev
->mesh_id_up_len
);
1639 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1641 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1642 struct net_device
*dev
= info
->user_ptr
[1];
1644 if (!rdev
->ops
->del_virtual_intf
)
1647 return rdev
->ops
->del_virtual_intf(&rdev
->wiphy
, dev
);
1650 struct get_key_cookie
{
1651 struct sk_buff
*msg
;
1656 static void get_key_callback(void *c
, struct key_params
*params
)
1659 struct get_key_cookie
*cookie
= c
;
1662 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
1663 params
->key_len
, params
->key
);
1666 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
1667 params
->seq_len
, params
->seq
);
1670 NLA_PUT_U32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
1673 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
1675 goto nla_put_failure
;
1678 NLA_PUT(cookie
->msg
, NL80211_KEY_DATA
,
1679 params
->key_len
, params
->key
);
1682 NLA_PUT(cookie
->msg
, NL80211_KEY_SEQ
,
1683 params
->seq_len
, params
->seq
);
1686 NLA_PUT_U32(cookie
->msg
, NL80211_KEY_CIPHER
,
1689 NLA_PUT_U8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
);
1691 nla_nest_end(cookie
->msg
, key
);
1698 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
1700 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1702 struct net_device
*dev
= info
->user_ptr
[1];
1704 const u8
*mac_addr
= NULL
;
1706 struct get_key_cookie cookie
= {
1710 struct sk_buff
*msg
;
1712 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
1713 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1718 if (info
->attrs
[NL80211_ATTR_MAC
])
1719 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1721 pairwise
= !!mac_addr
;
1722 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
1723 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
1724 if (kt
>= NUM_NL80211_KEYTYPES
)
1726 if (kt
!= NL80211_KEYTYPE_GROUP
&&
1727 kt
!= NL80211_KEYTYPE_PAIRWISE
)
1729 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
1732 if (!rdev
->ops
->get_key
)
1735 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1739 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1740 NL80211_CMD_NEW_KEY
);
1742 return PTR_ERR(hdr
);
1745 cookie
.idx
= key_idx
;
1747 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1748 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
1750 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1752 if (pairwise
&& mac_addr
&&
1753 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
1756 err
= rdev
->ops
->get_key(&rdev
->wiphy
, dev
, key_idx
, pairwise
,
1757 mac_addr
, &cookie
, get_key_callback
);
1763 goto nla_put_failure
;
1765 genlmsg_end(msg
, hdr
);
1766 return genlmsg_reply(msg
, info
);
1775 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
1777 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1778 struct key_parse key
;
1780 struct net_device
*dev
= info
->user_ptr
[1];
1782 err
= nl80211_parse_key(info
, &key
);
1789 /* only support setting default key */
1790 if (!key
.def
&& !key
.defmgmt
)
1793 wdev_lock(dev
->ieee80211_ptr
);
1796 if (!rdev
->ops
->set_default_key
) {
1801 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1805 err
= rdev
->ops
->set_default_key(&rdev
->wiphy
, dev
, key
.idx
,
1806 key
.def_uni
, key
.def_multi
);
1811 #ifdef CONFIG_CFG80211_WEXT
1812 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
1815 if (key
.def_uni
|| !key
.def_multi
) {
1820 if (!rdev
->ops
->set_default_mgmt_key
) {
1825 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1829 err
= rdev
->ops
->set_default_mgmt_key(&rdev
->wiphy
,
1834 #ifdef CONFIG_CFG80211_WEXT
1835 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
1840 wdev_unlock(dev
->ieee80211_ptr
);
1845 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
1847 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1849 struct net_device
*dev
= info
->user_ptr
[1];
1850 struct key_parse key
;
1851 const u8
*mac_addr
= NULL
;
1853 err
= nl80211_parse_key(info
, &key
);
1860 if (info
->attrs
[NL80211_ATTR_MAC
])
1861 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1863 if (key
.type
== -1) {
1865 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
1867 key
.type
= NL80211_KEYTYPE_GROUP
;
1871 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
1872 key
.type
!= NL80211_KEYTYPE_GROUP
)
1875 if (!rdev
->ops
->add_key
)
1878 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
1879 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
1883 wdev_lock(dev
->ieee80211_ptr
);
1884 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1886 err
= rdev
->ops
->add_key(&rdev
->wiphy
, dev
, key
.idx
,
1887 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
1889 wdev_unlock(dev
->ieee80211_ptr
);
1894 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
1896 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1898 struct net_device
*dev
= info
->user_ptr
[1];
1899 u8
*mac_addr
= NULL
;
1900 struct key_parse key
;
1902 err
= nl80211_parse_key(info
, &key
);
1906 if (info
->attrs
[NL80211_ATTR_MAC
])
1907 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1909 if (key
.type
== -1) {
1911 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
1913 key
.type
= NL80211_KEYTYPE_GROUP
;
1917 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
1918 key
.type
!= NL80211_KEYTYPE_GROUP
)
1921 if (!rdev
->ops
->del_key
)
1924 wdev_lock(dev
->ieee80211_ptr
);
1925 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1927 if (key
.type
== NL80211_KEYTYPE_PAIRWISE
&& mac_addr
&&
1928 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
1932 err
= rdev
->ops
->del_key(&rdev
->wiphy
, dev
, key
.idx
,
1933 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
1936 #ifdef CONFIG_CFG80211_WEXT
1938 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
1939 dev
->ieee80211_ptr
->wext
.default_key
= -1;
1940 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
1941 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
1944 wdev_unlock(dev
->ieee80211_ptr
);
1949 static int nl80211_addset_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1951 int (*call
)(struct wiphy
*wiphy
, struct net_device
*dev
,
1952 struct beacon_parameters
*info
);
1953 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1954 struct net_device
*dev
= info
->user_ptr
[1];
1955 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1956 struct beacon_parameters params
;
1957 int haveinfo
= 0, err
;
1959 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]))
1962 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1963 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
1966 memset(¶ms
, 0, sizeof(params
));
1968 switch (info
->genlhdr
->cmd
) {
1969 case NL80211_CMD_NEW_BEACON
:
1970 /* these are required for NEW_BEACON */
1971 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
1972 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
1973 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
1977 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
1978 params
.dtim_period
=
1979 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
1981 err
= cfg80211_validate_beacon_int(rdev
, params
.interval
);
1985 call
= rdev
->ops
->add_beacon
;
1987 case NL80211_CMD_SET_BEACON
:
1988 call
= rdev
->ops
->set_beacon
;
1998 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1999 params
.head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2001 nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
2005 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
2006 params
.tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2008 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
2015 err
= call(&rdev
->wiphy
, dev
, ¶ms
);
2016 if (!err
&& params
.interval
)
2017 wdev
->beacon_interval
= params
.interval
;
2021 static int nl80211_del_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
2023 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2024 struct net_device
*dev
= info
->user_ptr
[1];
2025 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2028 if (!rdev
->ops
->del_beacon
)
2031 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2032 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2035 err
= rdev
->ops
->del_beacon(&rdev
->wiphy
, dev
);
2037 wdev
->beacon_interval
= 0;
2041 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
2042 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
2043 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
2044 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
2045 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
2046 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
2049 static int parse_station_flags(struct genl_info
*info
,
2050 struct station_parameters
*params
)
2052 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
2057 * Try parsing the new attribute first so userspace
2058 * can specify both for older kernels.
2060 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
2062 struct nl80211_sta_flag_update
*sta_flags
;
2064 sta_flags
= nla_data(nla
);
2065 params
->sta_flags_mask
= sta_flags
->mask
;
2066 params
->sta_flags_set
= sta_flags
->set
;
2067 if ((params
->sta_flags_mask
|
2068 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
2073 /* if present, parse the old attribute */
2075 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
2079 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
2080 nla
, sta_flags_policy
))
2083 params
->sta_flags_mask
= (1 << __NL80211_STA_FLAG_AFTER_LAST
) - 1;
2084 params
->sta_flags_mask
&= ~1;
2086 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++)
2088 params
->sta_flags_set
|= (1<<flag
);
2093 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
2096 struct nlattr
*rate
;
2099 rate
= nla_nest_start(msg
, attr
);
2101 goto nla_put_failure
;
2103 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
2104 bitrate
= cfg80211_calculate_bitrate(info
);
2106 NLA_PUT_U16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate
);
2108 if (info
->flags
& RATE_INFO_FLAGS_MCS
)
2109 NLA_PUT_U8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
);
2110 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
)
2111 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
);
2112 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
)
2113 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_SHORT_GI
);
2115 nla_nest_end(msg
, rate
);
2122 static int nl80211_send_station(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2123 int flags
, struct net_device
*dev
,
2124 const u8
*mac_addr
, struct station_info
*sinfo
)
2127 struct nlattr
*sinfoattr
, *bss_param
;
2129 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2133 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2134 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
2136 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
);
2138 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
2140 goto nla_put_failure
;
2141 if (sinfo
->filled
& STATION_INFO_CONNECTED_TIME
)
2142 NLA_PUT_U32(msg
, NL80211_STA_INFO_CONNECTED_TIME
,
2143 sinfo
->connected_time
);
2144 if (sinfo
->filled
& STATION_INFO_INACTIVE_TIME
)
2145 NLA_PUT_U32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
2146 sinfo
->inactive_time
);
2147 if (sinfo
->filled
& STATION_INFO_RX_BYTES
)
2148 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_BYTES
,
2150 if (sinfo
->filled
& STATION_INFO_TX_BYTES
)
2151 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_BYTES
,
2153 if (sinfo
->filled
& STATION_INFO_LLID
)
2154 NLA_PUT_U16(msg
, NL80211_STA_INFO_LLID
,
2156 if (sinfo
->filled
& STATION_INFO_PLID
)
2157 NLA_PUT_U16(msg
, NL80211_STA_INFO_PLID
,
2159 if (sinfo
->filled
& STATION_INFO_PLINK_STATE
)
2160 NLA_PUT_U8(msg
, NL80211_STA_INFO_PLINK_STATE
,
2161 sinfo
->plink_state
);
2162 if (sinfo
->filled
& STATION_INFO_SIGNAL
)
2163 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL
,
2165 if (sinfo
->filled
& STATION_INFO_SIGNAL_AVG
)
2166 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
2168 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
2169 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
2170 NL80211_STA_INFO_TX_BITRATE
))
2171 goto nla_put_failure
;
2173 if (sinfo
->filled
& STATION_INFO_RX_BITRATE
) {
2174 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
2175 NL80211_STA_INFO_RX_BITRATE
))
2176 goto nla_put_failure
;
2178 if (sinfo
->filled
& STATION_INFO_RX_PACKETS
)
2179 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_PACKETS
,
2181 if (sinfo
->filled
& STATION_INFO_TX_PACKETS
)
2182 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_PACKETS
,
2184 if (sinfo
->filled
& STATION_INFO_TX_RETRIES
)
2185 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_RETRIES
,
2187 if (sinfo
->filled
& STATION_INFO_TX_FAILED
)
2188 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_FAILED
,
2190 if (sinfo
->filled
& STATION_INFO_BSS_PARAM
) {
2191 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
2193 goto nla_put_failure
;
2195 if (sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
)
2196 NLA_PUT_FLAG(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
);
2197 if (sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
)
2198 NLA_PUT_FLAG(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
);
2199 if (sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
)
2201 NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
);
2202 NLA_PUT_U8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
2203 sinfo
->bss_param
.dtim_period
);
2204 NLA_PUT_U16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
2205 sinfo
->bss_param
.beacon_interval
);
2207 nla_nest_end(msg
, bss_param
);
2209 nla_nest_end(msg
, sinfoattr
);
2211 return genlmsg_end(msg
, hdr
);
2214 genlmsg_cancel(msg
, hdr
);
2218 static int nl80211_dump_station(struct sk_buff
*skb
,
2219 struct netlink_callback
*cb
)
2221 struct station_info sinfo
;
2222 struct cfg80211_registered_device
*dev
;
2223 struct net_device
*netdev
;
2224 u8 mac_addr
[ETH_ALEN
];
2225 int sta_idx
= cb
->args
[1];
2228 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
2232 if (!dev
->ops
->dump_station
) {
2238 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
2245 if (nl80211_send_station(skb
,
2246 NETLINK_CB(cb
->skb
).pid
,
2247 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2257 cb
->args
[1] = sta_idx
;
2260 nl80211_finish_netdev_dump(dev
);
2265 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
2267 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2268 struct net_device
*dev
= info
->user_ptr
[1];
2269 struct station_info sinfo
;
2270 struct sk_buff
*msg
;
2271 u8
*mac_addr
= NULL
;
2274 memset(&sinfo
, 0, sizeof(sinfo
));
2276 if (!info
->attrs
[NL80211_ATTR_MAC
])
2279 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2281 if (!rdev
->ops
->get_station
)
2284 err
= rdev
->ops
->get_station(&rdev
->wiphy
, dev
, mac_addr
, &sinfo
);
2288 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2292 if (nl80211_send_station(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2293 dev
, mac_addr
, &sinfo
) < 0) {
2298 return genlmsg_reply(msg
, info
);
2302 * Get vlan interface making sure it is running and on the right wiphy.
2304 static int get_vlan(struct genl_info
*info
,
2305 struct cfg80211_registered_device
*rdev
,
2306 struct net_device
**vlan
)
2308 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
2312 *vlan
= dev_get_by_index(genl_info_net(info
),
2313 nla_get_u32(vlanattr
));
2316 if (!(*vlan
)->ieee80211_ptr
)
2318 if ((*vlan
)->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
)
2320 if (!netif_running(*vlan
))
2326 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
2328 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2330 struct net_device
*dev
= info
->user_ptr
[1];
2331 struct station_parameters params
;
2332 u8
*mac_addr
= NULL
;
2334 memset(¶ms
, 0, sizeof(params
));
2336 params
.listen_interval
= -1;
2337 params
.plink_state
= -1;
2339 if (info
->attrs
[NL80211_ATTR_STA_AID
])
2342 if (!info
->attrs
[NL80211_ATTR_MAC
])
2345 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2347 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
2348 params
.supported_rates
=
2349 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2350 params
.supported_rates_len
=
2351 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2354 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2355 params
.listen_interval
=
2356 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2358 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2360 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2362 if (parse_station_flags(info
, ¶ms
))
2365 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
2366 params
.plink_action
=
2367 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
2369 if (info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
])
2370 params
.plink_state
=
2371 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_STATE
]);
2373 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
2377 /* validate settings */
2380 switch (dev
->ieee80211_ptr
->iftype
) {
2381 case NL80211_IFTYPE_AP
:
2382 case NL80211_IFTYPE_AP_VLAN
:
2383 case NL80211_IFTYPE_P2P_GO
:
2384 /* disallow mesh-specific things */
2385 if (params
.plink_action
)
2388 case NL80211_IFTYPE_P2P_CLIENT
:
2389 case NL80211_IFTYPE_STATION
:
2390 /* disallow everything but AUTHORIZED flag */
2391 if (params
.plink_action
)
2395 if (params
.supported_rates
)
2399 if (params
.listen_interval
>= 0)
2401 if (params
.sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
2404 case NL80211_IFTYPE_MESH_POINT
:
2405 /* disallow things mesh doesn't support */
2410 if (params
.listen_interval
>= 0)
2412 if (params
.sta_flags_mask
&
2413 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
2414 BIT(NL80211_STA_FLAG_MFP
) |
2415 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
2425 if (!rdev
->ops
->change_station
) {
2430 err
= rdev
->ops
->change_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2434 dev_put(params
.vlan
);
2439 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
2441 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2443 struct net_device
*dev
= info
->user_ptr
[1];
2444 struct station_parameters params
;
2445 u8
*mac_addr
= NULL
;
2447 memset(¶ms
, 0, sizeof(params
));
2449 if (!info
->attrs
[NL80211_ATTR_MAC
])
2452 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2455 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
2458 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
2461 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2462 params
.supported_rates
=
2463 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2464 params
.supported_rates_len
=
2465 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2466 params
.listen_interval
=
2467 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2469 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
2470 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
2473 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2475 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2477 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
2478 params
.plink_action
=
2479 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
2481 if (parse_station_flags(info
, ¶ms
))
2484 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2485 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
2486 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
2487 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2490 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
2494 /* validate settings */
2497 if (!rdev
->ops
->add_station
) {
2502 err
= rdev
->ops
->add_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2506 dev_put(params
.vlan
);
2510 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
2512 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2513 struct net_device
*dev
= info
->user_ptr
[1];
2514 u8
*mac_addr
= NULL
;
2516 if (info
->attrs
[NL80211_ATTR_MAC
])
2517 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2519 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2520 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
2521 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
2522 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2525 if (!rdev
->ops
->del_station
)
2528 return rdev
->ops
->del_station(&rdev
->wiphy
, dev
, mac_addr
);
2531 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2532 int flags
, struct net_device
*dev
,
2533 u8
*dst
, u8
*next_hop
,
2534 struct mpath_info
*pinfo
)
2537 struct nlattr
*pinfoattr
;
2539 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2543 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2544 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
2545 NLA_PUT(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
);
2547 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
);
2549 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
2551 goto nla_put_failure
;
2552 if (pinfo
->filled
& MPATH_INFO_FRAME_QLEN
)
2553 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
2555 if (pinfo
->filled
& MPATH_INFO_SN
)
2556 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_SN
,
2558 if (pinfo
->filled
& MPATH_INFO_METRIC
)
2559 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_METRIC
,
2561 if (pinfo
->filled
& MPATH_INFO_EXPTIME
)
2562 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_EXPTIME
,
2564 if (pinfo
->filled
& MPATH_INFO_FLAGS
)
2565 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_FLAGS
,
2567 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
)
2568 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
2569 pinfo
->discovery_timeout
);
2570 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
)
2571 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
2572 pinfo
->discovery_retries
);
2574 nla_nest_end(msg
, pinfoattr
);
2576 return genlmsg_end(msg
, hdr
);
2579 genlmsg_cancel(msg
, hdr
);
2583 static int nl80211_dump_mpath(struct sk_buff
*skb
,
2584 struct netlink_callback
*cb
)
2586 struct mpath_info pinfo
;
2587 struct cfg80211_registered_device
*dev
;
2588 struct net_device
*netdev
;
2590 u8 next_hop
[ETH_ALEN
];
2591 int path_idx
= cb
->args
[1];
2594 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
2598 if (!dev
->ops
->dump_mpath
) {
2603 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2609 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
2610 dst
, next_hop
, &pinfo
);
2616 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).pid
,
2617 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2618 netdev
, dst
, next_hop
,
2627 cb
->args
[1] = path_idx
;
2630 nl80211_finish_netdev_dump(dev
);
2634 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2636 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2638 struct net_device
*dev
= info
->user_ptr
[1];
2639 struct mpath_info pinfo
;
2640 struct sk_buff
*msg
;
2642 u8 next_hop
[ETH_ALEN
];
2644 memset(&pinfo
, 0, sizeof(pinfo
));
2646 if (!info
->attrs
[NL80211_ATTR_MAC
])
2649 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2651 if (!rdev
->ops
->get_mpath
)
2654 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2657 err
= rdev
->ops
->get_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
2661 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2665 if (nl80211_send_mpath(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2666 dev
, dst
, next_hop
, &pinfo
) < 0) {
2671 return genlmsg_reply(msg
, info
);
2674 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2676 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2677 struct net_device
*dev
= info
->user_ptr
[1];
2679 u8
*next_hop
= NULL
;
2681 if (!info
->attrs
[NL80211_ATTR_MAC
])
2684 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2687 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2688 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2690 if (!rdev
->ops
->change_mpath
)
2693 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2696 return rdev
->ops
->change_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2699 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2701 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2702 struct net_device
*dev
= info
->user_ptr
[1];
2704 u8
*next_hop
= NULL
;
2706 if (!info
->attrs
[NL80211_ATTR_MAC
])
2709 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2712 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2713 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2715 if (!rdev
->ops
->add_mpath
)
2718 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2721 return rdev
->ops
->add_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2724 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2726 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2727 struct net_device
*dev
= info
->user_ptr
[1];
2730 if (info
->attrs
[NL80211_ATTR_MAC
])
2731 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2733 if (!rdev
->ops
->del_mpath
)
2736 return rdev
->ops
->del_mpath(&rdev
->wiphy
, dev
, dst
);
2739 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
2741 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2742 struct net_device
*dev
= info
->user_ptr
[1];
2743 struct bss_parameters params
;
2745 memset(¶ms
, 0, sizeof(params
));
2746 /* default to not changing parameters */
2747 params
.use_cts_prot
= -1;
2748 params
.use_short_preamble
= -1;
2749 params
.use_short_slot_time
= -1;
2750 params
.ap_isolate
= -1;
2751 params
.ht_opmode
= -1;
2753 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
2754 params
.use_cts_prot
=
2755 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
2756 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
2757 params
.use_short_preamble
=
2758 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
2759 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
2760 params
.use_short_slot_time
=
2761 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
2762 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
2763 params
.basic_rates
=
2764 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2765 params
.basic_rates_len
=
2766 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2768 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
2769 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
2770 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
2772 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
2774 if (!rdev
->ops
->change_bss
)
2777 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2778 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2781 return rdev
->ops
->change_bss(&rdev
->wiphy
, dev
, ¶ms
);
2784 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
2785 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
2786 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
2787 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
2788 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
2789 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
2790 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
2793 static int parse_reg_rule(struct nlattr
*tb
[],
2794 struct ieee80211_reg_rule
*reg_rule
)
2796 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
2797 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
2799 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
2801 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
2803 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
2805 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
2807 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
2810 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
2812 freq_range
->start_freq_khz
=
2813 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
2814 freq_range
->end_freq_khz
=
2815 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
2816 freq_range
->max_bandwidth_khz
=
2817 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
2819 power_rule
->max_eirp
=
2820 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
2822 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
2823 power_rule
->max_antenna_gain
=
2824 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
2829 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2835 * You should only get this when cfg80211 hasn't yet initialized
2836 * completely when built-in to the kernel right between the time
2837 * window between nl80211_init() and regulatory_init(), if that is
2840 mutex_lock(&cfg80211_mutex
);
2841 if (unlikely(!cfg80211_regdomain
)) {
2842 mutex_unlock(&cfg80211_mutex
);
2843 return -EINPROGRESS
;
2845 mutex_unlock(&cfg80211_mutex
);
2847 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2850 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2852 r
= regulatory_hint_user(data
);
2857 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
2858 struct genl_info
*info
)
2860 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2861 struct net_device
*dev
= info
->user_ptr
[1];
2862 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2863 struct mesh_config cur_params
;
2866 struct nlattr
*pinfoattr
;
2867 struct sk_buff
*msg
;
2869 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2872 if (!rdev
->ops
->get_mesh_config
)
2876 /* If not connected, get default parameters */
2877 if (!wdev
->mesh_id_len
)
2878 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
2880 err
= rdev
->ops
->get_mesh_config(&rdev
->wiphy
, dev
,
2887 /* Draw up a netlink message to send back */
2888 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2891 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2892 NL80211_CMD_GET_MESH_CONFIG
);
2895 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
2897 goto nla_put_failure
;
2898 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2899 NLA_PUT_U16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
2900 cur_params
.dot11MeshRetryTimeout
);
2901 NLA_PUT_U16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
2902 cur_params
.dot11MeshConfirmTimeout
);
2903 NLA_PUT_U16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
2904 cur_params
.dot11MeshHoldingTimeout
);
2905 NLA_PUT_U16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
2906 cur_params
.dot11MeshMaxPeerLinks
);
2907 NLA_PUT_U8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
2908 cur_params
.dot11MeshMaxRetries
);
2909 NLA_PUT_U8(msg
, NL80211_MESHCONF_TTL
,
2910 cur_params
.dot11MeshTTL
);
2911 NLA_PUT_U8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
2912 cur_params
.element_ttl
);
2913 NLA_PUT_U8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
2914 cur_params
.auto_open_plinks
);
2915 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2916 cur_params
.dot11MeshHWMPmaxPREQretries
);
2917 NLA_PUT_U32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
2918 cur_params
.path_refresh_time
);
2919 NLA_PUT_U16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2920 cur_params
.min_discovery_timeout
);
2921 NLA_PUT_U32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2922 cur_params
.dot11MeshHWMPactivePathTimeout
);
2923 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2924 cur_params
.dot11MeshHWMPpreqMinInterval
);
2925 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2926 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
);
2927 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
2928 cur_params
.dot11MeshHWMPRootMode
);
2929 nla_nest_end(msg
, pinfoattr
);
2930 genlmsg_end(msg
, hdr
);
2931 return genlmsg_reply(msg
, info
);
2934 genlmsg_cancel(msg
, hdr
);
2940 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
2941 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
2942 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
2943 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
2944 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
2945 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
2946 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
2947 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
2948 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
2950 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
2951 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
2952 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
2953 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
2954 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
2955 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
2958 static const struct nla_policy
2959 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
2960 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
2961 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
2962 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
2963 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
2964 .len
= IEEE80211_MAX_DATA_LEN
},
2965 [NL80211_MESH_SETUP_USERSPACE_AMPE
] = { .type
= NLA_FLAG
},
2968 static int nl80211_parse_mesh_config(struct genl_info
*info
,
2969 struct mesh_config
*cfg
,
2972 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
2975 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2977 if (table[attr_num]) {\
2978 cfg->param = nla_fn(table[attr_num]); \
2979 mask |= (1 << (attr_num - 1)); \
2984 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
2986 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
2987 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
2988 nl80211_meshconf_params_policy
))
2991 /* This makes sure that there aren't more than 32 mesh config
2992 * parameters (otherwise our bitfield scheme would not work.) */
2993 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
2995 /* Fill in the params struct */
2996 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
2997 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
, nla_get_u16
);
2998 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
2999 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
, nla_get_u16
);
3000 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
3001 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
, nla_get_u16
);
3002 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
3003 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
, nla_get_u16
);
3004 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
3005 mask
, NL80211_MESHCONF_MAX_RETRIES
, nla_get_u8
);
3006 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
3007 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
3008 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
,
3009 mask
, NL80211_MESHCONF_ELEMENT_TTL
, nla_get_u8
);
3010 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
3011 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
, nla_get_u8
);
3012 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
3013 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
3015 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
3016 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
, nla_get_u32
);
3017 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
3018 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
3020 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
3021 mask
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
3023 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
3024 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
3026 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3027 dot11MeshHWMPnetDiameterTraversalTime
,
3028 mask
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
3030 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
3031 dot11MeshHWMPRootMode
, mask
,
3032 NL80211_MESHCONF_HWMP_ROOTMODE
,
3039 #undef FILL_IN_MESH_PARAM_IF_SET
3042 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
3043 struct mesh_setup
*setup
)
3045 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
3047 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
3049 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
3050 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
3051 nl80211_mesh_setup_params_policy
))
3054 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
3055 setup
->path_sel_proto
=
3056 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
3057 IEEE80211_PATH_PROTOCOL_VENDOR
:
3058 IEEE80211_PATH_PROTOCOL_HWMP
;
3060 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
3061 setup
->path_metric
=
3062 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
3063 IEEE80211_PATH_METRIC_VENDOR
:
3064 IEEE80211_PATH_METRIC_AIRTIME
;
3067 if (tb
[NL80211_MESH_SETUP_IE
]) {
3068 struct nlattr
*ieattr
=
3069 tb
[NL80211_MESH_SETUP_IE
];
3070 if (!is_valid_ie_attr(ieattr
))
3072 setup
->ie
= nla_data(ieattr
);
3073 setup
->ie_len
= nla_len(ieattr
);
3075 setup
->is_authenticated
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
3076 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AMPE
]);
3081 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
3082 struct genl_info
*info
)
3084 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3085 struct net_device
*dev
= info
->user_ptr
[1];
3086 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
3087 struct mesh_config cfg
;
3091 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
3094 if (!rdev
->ops
->update_mesh_config
)
3097 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
3102 if (!wdev
->mesh_id_len
)
3106 err
= rdev
->ops
->update_mesh_config(&rdev
->wiphy
, dev
,
3114 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3116 struct sk_buff
*msg
;
3118 struct nlattr
*nl_reg_rules
;
3122 mutex_lock(&cfg80211_mutex
);
3124 if (!cfg80211_regdomain
)
3127 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3133 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
3134 NL80211_CMD_GET_REG
);
3138 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
,
3139 cfg80211_regdomain
->alpha2
);
3141 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
3143 goto nla_put_failure
;
3145 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
3146 struct nlattr
*nl_reg_rule
;
3147 const struct ieee80211_reg_rule
*reg_rule
;
3148 const struct ieee80211_freq_range
*freq_range
;
3149 const struct ieee80211_power_rule
*power_rule
;
3151 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
3152 freq_range
= ®_rule
->freq_range
;
3153 power_rule
= ®_rule
->power_rule
;
3155 nl_reg_rule
= nla_nest_start(msg
, i
);
3157 goto nla_put_failure
;
3159 NLA_PUT_U32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
3161 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
3162 freq_range
->start_freq_khz
);
3163 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
3164 freq_range
->end_freq_khz
);
3165 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
3166 freq_range
->max_bandwidth_khz
);
3167 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
3168 power_rule
->max_antenna_gain
);
3169 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
3170 power_rule
->max_eirp
);
3172 nla_nest_end(msg
, nl_reg_rule
);
3175 nla_nest_end(msg
, nl_reg_rules
);
3177 genlmsg_end(msg
, hdr
);
3178 err
= genlmsg_reply(msg
, info
);
3182 genlmsg_cancel(msg
, hdr
);
3187 mutex_unlock(&cfg80211_mutex
);
3191 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3193 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
3194 struct nlattr
*nl_reg_rule
;
3195 char *alpha2
= NULL
;
3196 int rem_reg_rules
= 0, r
= 0;
3197 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
3198 struct ieee80211_regdomain
*rd
= NULL
;
3200 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
3203 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
3206 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
3208 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
3211 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
3215 mutex_lock(&cfg80211_mutex
);
3217 if (!reg_is_valid_request(alpha2
)) {
3222 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
3223 (num_rules
* sizeof(struct ieee80211_reg_rule
));
3225 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
3231 rd
->n_reg_rules
= num_rules
;
3232 rd
->alpha2
[0] = alpha2
[0];
3233 rd
->alpha2
[1] = alpha2
[1];
3235 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
3237 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
3238 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
3240 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
3246 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
3252 BUG_ON(rule_idx
!= num_rules
);
3256 mutex_unlock(&cfg80211_mutex
);
3261 mutex_unlock(&cfg80211_mutex
);
3266 static int validate_scan_freqs(struct nlattr
*freqs
)
3268 struct nlattr
*attr1
, *attr2
;
3269 int n_channels
= 0, tmp1
, tmp2
;
3271 nla_for_each_nested(attr1
, freqs
, tmp1
) {
3274 * Some hardware has a limited channel list for
3275 * scanning, and it is pretty much nonsensical
3276 * to scan for a channel twice, so disallow that
3277 * and don't require drivers to check that the
3278 * channel list they get isn't longer than what
3279 * they can scan, as long as they can scan all
3280 * the channels they registered at once.
3282 nla_for_each_nested(attr2
, freqs
, tmp2
)
3283 if (attr1
!= attr2
&&
3284 nla_get_u32(attr1
) == nla_get_u32(attr2
))
3291 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
3293 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3294 struct net_device
*dev
= info
->user_ptr
[1];
3295 struct cfg80211_scan_request
*request
;
3296 struct nlattr
*attr
;
3297 struct wiphy
*wiphy
;
3298 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
3299 enum ieee80211_band band
;
3302 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3305 wiphy
= &rdev
->wiphy
;
3307 if (!rdev
->ops
->scan
)
3313 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3314 n_channels
= validate_scan_freqs(
3315 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
3321 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
3322 if (wiphy
->bands
[band
])
3323 n_channels
+= wiphy
->bands
[band
]->n_channels
;
3326 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
3327 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
3330 if (n_ssids
> wiphy
->max_scan_ssids
)
3333 if (info
->attrs
[NL80211_ATTR_IE
])
3334 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3338 if (ie_len
> wiphy
->max_scan_ie_len
)
3341 request
= kzalloc(sizeof(*request
)
3342 + sizeof(*request
->ssids
) * n_ssids
3343 + sizeof(*request
->channels
) * n_channels
3344 + ie_len
, GFP_KERNEL
);
3349 request
->ssids
= (void *)&request
->channels
[n_channels
];
3350 request
->n_ssids
= n_ssids
;
3353 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
3355 request
->ie
= (void *)(request
->channels
+ n_channels
);
3359 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3360 /* user specified, bail out if channel not found */
3361 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
3362 struct ieee80211_channel
*chan
;
3364 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
3371 /* ignore disabled channels */
3372 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3375 request
->channels
[i
] = chan
;
3380 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
3382 if (!wiphy
->bands
[band
])
3384 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
3385 struct ieee80211_channel
*chan
;
3387 chan
= &wiphy
->bands
[band
]->channels
[j
];
3389 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3392 request
->channels
[i
] = chan
;
3403 request
->n_channels
= i
;
3406 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
3407 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
3408 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
3412 request
->ssids
[i
].ssid_len
= nla_len(attr
);
3413 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
3418 if (info
->attrs
[NL80211_ATTR_IE
]) {
3419 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3420 memcpy((void *)request
->ie
,
3421 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
3426 request
->wiphy
= &rdev
->wiphy
;
3428 rdev
->scan_req
= request
;
3429 err
= rdev
->ops
->scan(&rdev
->wiphy
, dev
, request
);
3432 nl80211_send_scan_start(rdev
, dev
);
3436 rdev
->scan_req
= NULL
;
3443 static int nl80211_start_sched_scan(struct sk_buff
*skb
,
3444 struct genl_info
*info
)
3446 struct cfg80211_sched_scan_request
*request
;
3447 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3448 struct net_device
*dev
= info
->user_ptr
[1];
3449 struct nlattr
*attr
;
3450 struct wiphy
*wiphy
;
3451 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
3453 enum ieee80211_band band
;
3456 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
3457 !rdev
->ops
->sched_scan_start
)
3460 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3463 if (!info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
])
3466 interval
= nla_get_u32(info
->attrs
[NL80211_ATTR_SCHED_SCAN_INTERVAL
]);
3470 wiphy
= &rdev
->wiphy
;
3472 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3473 n_channels
= validate_scan_freqs(
3474 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
3480 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
3481 if (wiphy
->bands
[band
])
3482 n_channels
+= wiphy
->bands
[band
]->n_channels
;
3485 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
3486 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
3490 if (n_ssids
> wiphy
->max_scan_ssids
)
3493 if (info
->attrs
[NL80211_ATTR_IE
])
3494 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3498 if (ie_len
> wiphy
->max_scan_ie_len
)
3501 mutex_lock(&rdev
->sched_scan_mtx
);
3503 if (rdev
->sched_scan_req
) {
3508 request
= kzalloc(sizeof(*request
)
3509 + sizeof(*request
->ssids
) * n_ssids
3510 + sizeof(*request
->channels
) * n_channels
3511 + ie_len
, GFP_KERNEL
);
3518 request
->ssids
= (void *)&request
->channels
[n_channels
];
3519 request
->n_ssids
= n_ssids
;
3522 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
3524 request
->ie
= (void *)(request
->channels
+ n_channels
);
3528 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3529 /* user specified, bail out if channel not found */
3530 nla_for_each_nested(attr
,
3531 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
],
3533 struct ieee80211_channel
*chan
;
3535 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
3542 /* ignore disabled channels */
3543 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3546 request
->channels
[i
] = chan
;
3551 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
3553 if (!wiphy
->bands
[band
])
3555 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
3556 struct ieee80211_channel
*chan
;
3558 chan
= &wiphy
->bands
[band
]->channels
[j
];
3560 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3563 request
->channels
[i
] = chan
;
3574 request
->n_channels
= i
;
3577 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
3578 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
],
3580 if (nla_len(attr
) > IEEE80211_MAX_SSID_LEN
) {
3584 request
->ssids
[i
].ssid_len
= nla_len(attr
);
3585 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
),
3591 if (info
->attrs
[NL80211_ATTR_IE
]) {
3592 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3593 memcpy((void *)request
->ie
,
3594 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
3599 request
->wiphy
= &rdev
->wiphy
;
3600 request
->interval
= interval
;
3602 err
= rdev
->ops
->sched_scan_start(&rdev
->wiphy
, dev
, request
);
3604 rdev
->sched_scan_req
= request
;
3605 nl80211_send_sched_scan(rdev
, dev
,
3606 NL80211_CMD_START_SCHED_SCAN
);
3613 mutex_unlock(&rdev
->sched_scan_mtx
);
3617 static int nl80211_stop_sched_scan(struct sk_buff
*skb
,
3618 struct genl_info
*info
)
3620 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3623 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_SUPPORTS_SCHED_SCAN
) ||
3624 !rdev
->ops
->sched_scan_stop
)
3627 mutex_lock(&rdev
->sched_scan_mtx
);
3628 err
= __cfg80211_stop_sched_scan(rdev
, false);
3629 mutex_unlock(&rdev
->sched_scan_mtx
);
3634 static int nl80211_send_bss(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
3635 struct cfg80211_registered_device
*rdev
,
3636 struct wireless_dev
*wdev
,
3637 struct cfg80211_internal_bss
*intbss
)
3639 struct cfg80211_bss
*res
= &intbss
->pub
;
3644 ASSERT_WDEV_LOCK(wdev
);
3646 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3647 NL80211_CMD_NEW_SCAN_RESULTS
);
3651 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
);
3652 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
);
3654 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
3656 goto nla_put_failure
;
3657 if (!is_zero_ether_addr(res
->bssid
))
3658 NLA_PUT(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
);
3659 if (res
->information_elements
&& res
->len_information_elements
)
3660 NLA_PUT(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
3661 res
->len_information_elements
,
3662 res
->information_elements
);
3663 if (res
->beacon_ies
&& res
->len_beacon_ies
&&
3664 res
->beacon_ies
!= res
->information_elements
)
3665 NLA_PUT(msg
, NL80211_BSS_BEACON_IES
,
3666 res
->len_beacon_ies
, res
->beacon_ies
);
3668 NLA_PUT_U64(msg
, NL80211_BSS_TSF
, res
->tsf
);
3669 if (res
->beacon_interval
)
3670 NLA_PUT_U16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
);
3671 NLA_PUT_U16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
);
3672 NLA_PUT_U32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
);
3673 NLA_PUT_U32(msg
, NL80211_BSS_SEEN_MS_AGO
,
3674 jiffies_to_msecs(jiffies
- intbss
->ts
));
3676 switch (rdev
->wiphy
.signal_type
) {
3677 case CFG80211_SIGNAL_TYPE_MBM
:
3678 NLA_PUT_U32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
);
3680 case CFG80211_SIGNAL_TYPE_UNSPEC
:
3681 NLA_PUT_U8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
);
3687 switch (wdev
->iftype
) {
3688 case NL80211_IFTYPE_P2P_CLIENT
:
3689 case NL80211_IFTYPE_STATION
:
3690 if (intbss
== wdev
->current_bss
)
3691 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3692 NL80211_BSS_STATUS_ASSOCIATED
);
3693 else for (i
= 0; i
< MAX_AUTH_BSSES
; i
++) {
3694 if (intbss
!= wdev
->auth_bsses
[i
])
3696 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3697 NL80211_BSS_STATUS_AUTHENTICATED
);
3701 case NL80211_IFTYPE_ADHOC
:
3702 if (intbss
== wdev
->current_bss
)
3703 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3704 NL80211_BSS_STATUS_IBSS_JOINED
);
3710 nla_nest_end(msg
, bss
);
3712 return genlmsg_end(msg
, hdr
);
3715 genlmsg_cancel(msg
, hdr
);
3719 static int nl80211_dump_scan(struct sk_buff
*skb
,
3720 struct netlink_callback
*cb
)
3722 struct cfg80211_registered_device
*rdev
;
3723 struct net_device
*dev
;
3724 struct cfg80211_internal_bss
*scan
;
3725 struct wireless_dev
*wdev
;
3726 int start
= cb
->args
[1], idx
= 0;
3729 err
= nl80211_prepare_netdev_dump(skb
, cb
, &rdev
, &dev
);
3733 wdev
= dev
->ieee80211_ptr
;
3736 spin_lock_bh(&rdev
->bss_lock
);
3737 cfg80211_bss_expire(rdev
);
3739 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
3742 if (nl80211_send_bss(skb
,
3743 NETLINK_CB(cb
->skb
).pid
,
3744 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3745 rdev
, wdev
, scan
) < 0) {
3751 spin_unlock_bh(&rdev
->bss_lock
);
3755 nl80211_finish_netdev_dump(rdev
);
3760 static int nl80211_send_survey(struct sk_buff
*msg
, u32 pid
, u32 seq
,
3761 int flags
, struct net_device
*dev
,
3762 struct survey_info
*survey
)
3765 struct nlattr
*infoattr
;
3767 /* Survey without a channel doesn't make sense */
3768 if (!survey
->channel
)
3771 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3772 NL80211_CMD_NEW_SURVEY_RESULTS
);
3776 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
3778 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
3780 goto nla_put_failure
;
3782 NLA_PUT_U32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
3783 survey
->channel
->center_freq
);
3784 if (survey
->filled
& SURVEY_INFO_NOISE_DBM
)
3785 NLA_PUT_U8(msg
, NL80211_SURVEY_INFO_NOISE
,
3787 if (survey
->filled
& SURVEY_INFO_IN_USE
)
3788 NLA_PUT_FLAG(msg
, NL80211_SURVEY_INFO_IN_USE
);
3789 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME
)
3790 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
3791 survey
->channel_time
);
3792 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
)
3793 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
3794 survey
->channel_time_busy
);
3795 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
)
3796 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
3797 survey
->channel_time_ext_busy
);
3798 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
)
3799 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
3800 survey
->channel_time_rx
);
3801 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
)
3802 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
3803 survey
->channel_time_tx
);
3805 nla_nest_end(msg
, infoattr
);
3807 return genlmsg_end(msg
, hdr
);
3810 genlmsg_cancel(msg
, hdr
);
3814 static int nl80211_dump_survey(struct sk_buff
*skb
,
3815 struct netlink_callback
*cb
)
3817 struct survey_info survey
;
3818 struct cfg80211_registered_device
*dev
;
3819 struct net_device
*netdev
;
3820 int survey_idx
= cb
->args
[1];
3823 res
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
3827 if (!dev
->ops
->dump_survey
) {
3833 res
= dev
->ops
->dump_survey(&dev
->wiphy
, netdev
, survey_idx
,
3840 if (nl80211_send_survey(skb
,
3841 NETLINK_CB(cb
->skb
).pid
,
3842 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3850 cb
->args
[1] = survey_idx
;
3853 nl80211_finish_netdev_dump(dev
);
3857 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
)
3859 return auth_type
<= NL80211_AUTHTYPE_MAX
;
3862 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
3864 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
3865 NL80211_WPA_VERSION_2
));
3868 static bool nl80211_valid_akm_suite(u32 akm
)
3870 return akm
== WLAN_AKM_SUITE_8021X
||
3871 akm
== WLAN_AKM_SUITE_PSK
;
3874 static bool nl80211_valid_cipher_suite(u32 cipher
)
3876 return cipher
== WLAN_CIPHER_SUITE_WEP40
||
3877 cipher
== WLAN_CIPHER_SUITE_WEP104
||
3878 cipher
== WLAN_CIPHER_SUITE_TKIP
||
3879 cipher
== WLAN_CIPHER_SUITE_CCMP
||
3880 cipher
== WLAN_CIPHER_SUITE_AES_CMAC
;
3884 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3886 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3887 struct net_device
*dev
= info
->user_ptr
[1];
3888 struct ieee80211_channel
*chan
;
3889 const u8
*bssid
, *ssid
, *ie
= NULL
;
3890 int err
, ssid_len
, ie_len
= 0;
3891 enum nl80211_auth_type auth_type
;
3892 struct key_parse key
;
3893 bool local_state_change
;
3895 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3898 if (!info
->attrs
[NL80211_ATTR_MAC
])
3901 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
3904 if (!info
->attrs
[NL80211_ATTR_SSID
])
3907 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
3910 err
= nl80211_parse_key(info
, &key
);
3915 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
3917 if (!key
.p
.key
|| !key
.p
.key_len
)
3919 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
3920 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
3921 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
3922 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
3934 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
3935 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
3944 if (!rdev
->ops
->auth
)
3947 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
3948 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
3951 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3952 chan
= ieee80211_get_channel(&rdev
->wiphy
,
3953 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3954 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
3957 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3958 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3960 if (info
->attrs
[NL80211_ATTR_IE
]) {
3961 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3962 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3965 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3966 if (!nl80211_valid_auth_type(auth_type
))
3969 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
3971 return cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
3972 ssid
, ssid_len
, ie
, ie_len
,
3973 key
.p
.key
, key
.p
.key_len
, key
.idx
,
3974 local_state_change
);
3977 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
3978 struct genl_info
*info
,
3979 struct cfg80211_crypto_settings
*settings
,
3982 memset(settings
, 0, sizeof(*settings
));
3984 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
3986 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
3988 proto
= nla_get_u16(
3989 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
3990 settings
->control_port_ethertype
= cpu_to_be16(proto
);
3991 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
3994 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
3995 settings
->control_port_no_encrypt
= true;
3997 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
3999 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
4003 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
4004 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
4005 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
4007 if (len
% sizeof(u32
))
4010 if (settings
->n_ciphers_pairwise
> cipher_limit
)
4013 memcpy(settings
->ciphers_pairwise
, data
, len
);
4015 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
4016 if (!nl80211_valid_cipher_suite(
4017 settings
->ciphers_pairwise
[i
]))
4021 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
4022 settings
->cipher_group
=
4023 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
4024 if (!nl80211_valid_cipher_suite(settings
->cipher_group
))
4028 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
4029 settings
->wpa_versions
=
4030 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
4031 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
4035 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
4039 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
4040 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
4041 settings
->n_akm_suites
= len
/ sizeof(u32
);
4043 if (len
% sizeof(u32
))
4046 if (settings
->n_akm_suites
> NL80211_MAX_NR_AKM_SUITES
)
4049 memcpy(settings
->akm_suites
, data
, len
);
4051 for (i
= 0; i
< settings
->n_akm_suites
; i
++)
4052 if (!nl80211_valid_akm_suite(settings
->akm_suites
[i
]))
4059 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
4061 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4062 struct net_device
*dev
= info
->user_ptr
[1];
4063 struct cfg80211_crypto_settings crypto
;
4064 struct ieee80211_channel
*chan
;
4065 const u8
*bssid
, *ssid
, *ie
= NULL
, *prev_bssid
= NULL
;
4066 int err
, ssid_len
, ie_len
= 0;
4067 bool use_mfp
= false;
4069 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4072 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
4073 !info
->attrs
[NL80211_ATTR_SSID
] ||
4074 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4077 if (!rdev
->ops
->assoc
)
4080 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4081 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4084 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4086 chan
= ieee80211_get_channel(&rdev
->wiphy
,
4087 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4088 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
4091 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4092 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4094 if (info
->attrs
[NL80211_ATTR_IE
]) {
4095 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4096 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4099 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
4100 enum nl80211_mfp mfp
=
4101 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
4102 if (mfp
== NL80211_MFP_REQUIRED
)
4104 else if (mfp
!= NL80211_MFP_NO
)
4108 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
4109 prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
4111 err
= nl80211_crypto_settings(rdev
, info
, &crypto
, 1);
4113 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
, prev_bssid
,
4114 ssid
, ssid_len
, ie
, ie_len
, use_mfp
,
4120 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
4122 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4123 struct net_device
*dev
= info
->user_ptr
[1];
4124 const u8
*ie
= NULL
, *bssid
;
4127 bool local_state_change
;
4129 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4132 if (!info
->attrs
[NL80211_ATTR_MAC
])
4135 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4138 if (!rdev
->ops
->deauth
)
4141 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4142 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4145 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4147 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4148 if (reason_code
== 0) {
4149 /* Reason Code 0 is reserved */
4153 if (info
->attrs
[NL80211_ATTR_IE
]) {
4154 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4155 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4158 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
4160 return cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
4161 local_state_change
);
4164 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
4166 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4167 struct net_device
*dev
= info
->user_ptr
[1];
4168 const u8
*ie
= NULL
, *bssid
;
4171 bool local_state_change
;
4173 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4176 if (!info
->attrs
[NL80211_ATTR_MAC
])
4179 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4182 if (!rdev
->ops
->disassoc
)
4185 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4186 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4189 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4191 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4192 if (reason_code
== 0) {
4193 /* Reason Code 0 is reserved */
4197 if (info
->attrs
[NL80211_ATTR_IE
]) {
4198 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4199 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4202 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
4204 return cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
4205 local_state_change
);
4209 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
4210 int mcast_rate
[IEEE80211_NUM_BANDS
],
4213 struct wiphy
*wiphy
= &rdev
->wiphy
;
4217 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
4218 struct ieee80211_supported_band
*sband
;
4220 sband
= wiphy
->bands
[band
];
4224 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
4225 if (sband
->bitrates
[i
].bitrate
== rateval
) {
4226 mcast_rate
[band
] = i
+ 1;
4236 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
4238 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4239 struct net_device
*dev
= info
->user_ptr
[1];
4240 struct cfg80211_ibss_params ibss
;
4241 struct wiphy
*wiphy
;
4242 struct cfg80211_cached_keys
*connkeys
= NULL
;
4245 memset(&ibss
, 0, sizeof(ibss
));
4247 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4250 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
4251 !info
->attrs
[NL80211_ATTR_SSID
] ||
4252 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
4255 ibss
.beacon_interval
= 100;
4257 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
4258 ibss
.beacon_interval
=
4259 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
4260 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
4264 if (!rdev
->ops
->join_ibss
)
4267 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
4270 wiphy
= &rdev
->wiphy
;
4272 if (info
->attrs
[NL80211_ATTR_MAC
])
4273 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4274 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4275 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4277 if (info
->attrs
[NL80211_ATTR_IE
]) {
4278 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4279 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4282 ibss
.channel
= ieee80211_get_channel(wiphy
,
4283 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4284 if (!ibss
.channel
||
4285 ibss
.channel
->flags
& IEEE80211_CHAN_NO_IBSS
||
4286 ibss
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
4289 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
4290 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
4292 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
4294 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4296 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
4297 struct ieee80211_supported_band
*sband
=
4298 wiphy
->bands
[ibss
.channel
->band
];
4304 for (i
= 0; i
< n_rates
; i
++) {
4305 int rate
= (rates
[i
] & 0x7f) * 5;
4308 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
4309 if (sband
->bitrates
[j
].bitrate
== rate
) {
4311 ibss
.basic_rates
|= BIT(j
);
4320 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
4321 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
4322 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
4325 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
4326 connkeys
= nl80211_parse_connkeys(rdev
,
4327 info
->attrs
[NL80211_ATTR_KEYS
]);
4328 if (IS_ERR(connkeys
))
4329 return PTR_ERR(connkeys
);
4332 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
4338 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
4340 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4341 struct net_device
*dev
= info
->user_ptr
[1];
4343 if (!rdev
->ops
->leave_ibss
)
4346 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
4349 return cfg80211_leave_ibss(rdev
, dev
, false);
4352 #ifdef CONFIG_NL80211_TESTMODE
4353 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
4357 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
4359 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4362 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
4366 if (rdev
->ops
->testmode_cmd
) {
4367 rdev
->testmode_info
= info
;
4368 err
= rdev
->ops
->testmode_cmd(&rdev
->wiphy
,
4369 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
4370 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
4371 rdev
->testmode_info
= NULL
;
4377 static struct sk_buff
*
4378 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
4379 int approxlen
, u32 pid
, u32 seq
, gfp_t gfp
)
4381 struct sk_buff
*skb
;
4383 struct nlattr
*data
;
4385 skb
= nlmsg_new(approxlen
+ 100, gfp
);
4389 hdr
= nl80211hdr_put(skb
, pid
, seq
, 0, NL80211_CMD_TESTMODE
);
4395 NLA_PUT_U32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4396 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
4398 ((void **)skb
->cb
)[0] = rdev
;
4399 ((void **)skb
->cb
)[1] = hdr
;
4400 ((void **)skb
->cb
)[2] = data
;
4409 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
4412 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4414 if (WARN_ON(!rdev
->testmode_info
))
4417 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
4418 rdev
->testmode_info
->snd_pid
,
4419 rdev
->testmode_info
->snd_seq
,
4422 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
4424 int cfg80211_testmode_reply(struct sk_buff
*skb
)
4426 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
4427 void *hdr
= ((void **)skb
->cb
)[1];
4428 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4430 if (WARN_ON(!rdev
->testmode_info
)) {
4435 nla_nest_end(skb
, data
);
4436 genlmsg_end(skb
, hdr
);
4437 return genlmsg_reply(skb
, rdev
->testmode_info
);
4439 EXPORT_SYMBOL(cfg80211_testmode_reply
);
4441 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
4442 int approxlen
, gfp_t gfp
)
4444 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4446 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
4448 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
4450 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
4452 void *hdr
= ((void **)skb
->cb
)[1];
4453 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4455 nla_nest_end(skb
, data
);
4456 genlmsg_end(skb
, hdr
);
4457 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
4459 EXPORT_SYMBOL(cfg80211_testmode_event
);
4462 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
4464 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4465 struct net_device
*dev
= info
->user_ptr
[1];
4466 struct cfg80211_connect_params connect
;
4467 struct wiphy
*wiphy
;
4468 struct cfg80211_cached_keys
*connkeys
= NULL
;
4471 memset(&connect
, 0, sizeof(connect
));
4473 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4476 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
4477 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
4480 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
4482 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4483 if (!nl80211_valid_auth_type(connect
.auth_type
))
4486 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
4488 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
4490 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
4491 NL80211_MAX_NR_CIPHER_SUITES
);
4495 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4496 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4499 wiphy
= &rdev
->wiphy
;
4501 if (info
->attrs
[NL80211_ATTR_MAC
])
4502 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4503 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4504 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4506 if (info
->attrs
[NL80211_ATTR_IE
]) {
4507 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4508 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4511 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
4513 ieee80211_get_channel(wiphy
,
4514 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4515 if (!connect
.channel
||
4516 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
4520 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
4521 connkeys
= nl80211_parse_connkeys(rdev
,
4522 info
->attrs
[NL80211_ATTR_KEYS
]);
4523 if (IS_ERR(connkeys
))
4524 return PTR_ERR(connkeys
);
4527 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
4533 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
4535 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4536 struct net_device
*dev
= info
->user_ptr
[1];
4539 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4540 reason
= WLAN_REASON_DEAUTH_LEAVING
;
4542 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4547 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4548 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4551 return cfg80211_disconnect(rdev
, dev
, reason
, true);
4554 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
4556 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4561 if (!info
->attrs
[NL80211_ATTR_PID
])
4564 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
4566 net
= get_net_ns_by_pid(pid
);
4568 return PTR_ERR(net
);
4572 /* check if anything to do */
4573 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
4574 err
= cfg80211_switch_netns(rdev
, net
);
4580 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4582 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4583 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
4584 struct cfg80211_pmksa
*pmksa
) = NULL
;
4585 struct net_device
*dev
= info
->user_ptr
[1];
4586 struct cfg80211_pmksa pmksa
;
4588 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
4590 if (!info
->attrs
[NL80211_ATTR_MAC
])
4593 if (!info
->attrs
[NL80211_ATTR_PMKID
])
4596 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
4597 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4599 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4600 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4603 switch (info
->genlhdr
->cmd
) {
4604 case NL80211_CMD_SET_PMKSA
:
4605 rdev_ops
= rdev
->ops
->set_pmksa
;
4607 case NL80211_CMD_DEL_PMKSA
:
4608 rdev_ops
= rdev
->ops
->del_pmksa
;
4618 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
4621 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4623 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4624 struct net_device
*dev
= info
->user_ptr
[1];
4626 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4627 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4630 if (!rdev
->ops
->flush_pmksa
)
4633 return rdev
->ops
->flush_pmksa(&rdev
->wiphy
, dev
);
4636 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
4637 struct genl_info
*info
)
4639 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4640 struct net_device
*dev
= info
->user_ptr
[1];
4641 struct ieee80211_channel
*chan
;
4642 struct sk_buff
*msg
;
4645 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
4649 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
4650 !info
->attrs
[NL80211_ATTR_DURATION
])
4653 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
4656 * We should be on that channel for at least one jiffie,
4657 * and more than 5 seconds seems excessive.
4659 if (!duration
|| !msecs_to_jiffies(duration
) ||
4660 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
4663 if (!rdev
->ops
->remain_on_channel
)
4666 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
4667 channel_type
= nla_get_u32(
4668 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
4669 if (channel_type
!= NL80211_CHAN_NO_HT
&&
4670 channel_type
!= NL80211_CHAN_HT20
&&
4671 channel_type
!= NL80211_CHAN_HT40PLUS
&&
4672 channel_type
!= NL80211_CHAN_HT40MINUS
)
4676 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
4677 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
4681 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4685 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4686 NL80211_CMD_REMAIN_ON_CHANNEL
);
4693 err
= rdev
->ops
->remain_on_channel(&rdev
->wiphy
, dev
, chan
,
4694 channel_type
, duration
, &cookie
);
4699 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
4701 genlmsg_end(msg
, hdr
);
4703 return genlmsg_reply(msg
, info
);
4712 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
4713 struct genl_info
*info
)
4715 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4716 struct net_device
*dev
= info
->user_ptr
[1];
4719 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
4722 if (!rdev
->ops
->cancel_remain_on_channel
)
4725 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
4727 return rdev
->ops
->cancel_remain_on_channel(&rdev
->wiphy
, dev
, cookie
);
4730 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
4731 u8
*rates
, u8 rates_len
)
4736 for (i
= 0; i
< rates_len
; i
++) {
4737 int rate
= (rates
[i
] & 0x7f) * 5;
4739 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
4740 struct ieee80211_rate
*srate
=
4741 &sband
->bitrates
[ridx
];
4742 if (rate
== srate
->bitrate
) {
4747 if (ridx
== sband
->n_bitrates
)
4748 return 0; /* rate not found */
4754 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
4755 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
4756 .len
= NL80211_MAX_SUPP_RATES
},
4759 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
4760 struct genl_info
*info
)
4762 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
4763 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4764 struct cfg80211_bitrate_mask mask
;
4766 struct net_device
*dev
= info
->user_ptr
[1];
4767 struct nlattr
*tx_rates
;
4768 struct ieee80211_supported_band
*sband
;
4770 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
4773 if (!rdev
->ops
->set_bitrate_mask
)
4776 memset(&mask
, 0, sizeof(mask
));
4777 /* Default to all rates enabled */
4778 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
4779 sband
= rdev
->wiphy
.bands
[i
];
4780 mask
.control
[i
].legacy
=
4781 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
4785 * The nested attribute uses enum nl80211_band as the index. This maps
4786 * directly to the enum ieee80211_band values used in cfg80211.
4788 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
4790 enum ieee80211_band band
= nla_type(tx_rates
);
4791 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
4793 sband
= rdev
->wiphy
.bands
[band
];
4796 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
4797 nla_len(tx_rates
), nl80211_txattr_policy
);
4798 if (tb
[NL80211_TXRATE_LEGACY
]) {
4799 mask
.control
[band
].legacy
= rateset_to_mask(
4801 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
4802 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
4803 if (mask
.control
[band
].legacy
== 0)
4808 return rdev
->ops
->set_bitrate_mask(&rdev
->wiphy
, dev
, NULL
, &mask
);
4811 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
4813 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4814 struct net_device
*dev
= info
->user_ptr
[1];
4815 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
4817 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
4820 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
4821 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
4823 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4824 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
4825 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
4826 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4827 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4828 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
4829 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4832 /* not much point in registering if we can't reply */
4833 if (!rdev
->ops
->mgmt_tx
)
4836 return cfg80211_mlme_register_mgmt(dev
->ieee80211_ptr
, info
->snd_pid
,
4838 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
4839 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
4842 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
4844 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4845 struct net_device
*dev
= info
->user_ptr
[1];
4846 struct ieee80211_channel
*chan
;
4847 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
4848 bool channel_type_valid
= false;
4853 struct sk_buff
*msg
;
4854 unsigned int wait
= 0;
4857 if (!info
->attrs
[NL80211_ATTR_FRAME
] ||
4858 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4861 if (!rdev
->ops
->mgmt_tx
)
4864 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4865 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
4866 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
4867 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4868 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4869 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
4870 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4873 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
4874 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
4876 wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
4879 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
4880 channel_type
= nla_get_u32(
4881 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
4882 if (channel_type
!= NL80211_CHAN_NO_HT
&&
4883 channel_type
!= NL80211_CHAN_HT20
&&
4884 channel_type
!= NL80211_CHAN_HT40PLUS
&&
4885 channel_type
!= NL80211_CHAN_HT40MINUS
)
4887 channel_type_valid
= true;
4890 offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
4892 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
4893 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
4897 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4901 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4908 err
= cfg80211_mlme_mgmt_tx(rdev
, dev
, chan
, offchan
, channel_type
,
4909 channel_type_valid
, wait
,
4910 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
4911 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
4916 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
4918 genlmsg_end(msg
, hdr
);
4919 return genlmsg_reply(msg
, info
);
4928 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
4930 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4931 struct net_device
*dev
= info
->user_ptr
[1];
4934 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
4937 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
4940 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4941 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
4942 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
4943 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4944 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4945 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4948 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
4950 return rdev
->ops
->mgmt_tx_cancel_wait(&rdev
->wiphy
, dev
, cookie
);
4953 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
4955 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4956 struct wireless_dev
*wdev
;
4957 struct net_device
*dev
= info
->user_ptr
[1];
4962 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
4965 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
4967 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
4970 wdev
= dev
->ieee80211_ptr
;
4972 if (!rdev
->ops
->set_power_mgmt
)
4975 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
4977 if (state
== wdev
->ps
)
4980 err
= rdev
->ops
->set_power_mgmt(wdev
->wiphy
, dev
, state
,
4987 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
4989 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4990 enum nl80211_ps_state ps_state
;
4991 struct wireless_dev
*wdev
;
4992 struct net_device
*dev
= info
->user_ptr
[1];
4993 struct sk_buff
*msg
;
4997 wdev
= dev
->ieee80211_ptr
;
4999 if (!rdev
->ops
->set_power_mgmt
)
5002 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5006 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
5007 NL80211_CMD_GET_POWER_SAVE
);
5014 ps_state
= NL80211_PS_ENABLED
;
5016 ps_state
= NL80211_PS_DISABLED
;
5018 NLA_PUT_U32(msg
, NL80211_ATTR_PS_STATE
, ps_state
);
5020 genlmsg_end(msg
, hdr
);
5021 return genlmsg_reply(msg
, info
);
5030 static struct nla_policy
5031 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
5032 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
5033 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
5034 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
5037 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
5038 s32 threshold
, u32 hysteresis
)
5040 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5041 struct wireless_dev
*wdev
;
5042 struct net_device
*dev
= info
->user_ptr
[1];
5047 wdev
= dev
->ieee80211_ptr
;
5049 if (!rdev
->ops
->set_cqm_rssi_config
)
5052 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
5053 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
5056 return rdev
->ops
->set_cqm_rssi_config(wdev
->wiphy
, dev
,
5057 threshold
, hysteresis
);
5060 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
5062 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
5066 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
5072 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
5073 nl80211_attr_cqm_policy
);
5077 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
5078 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
5081 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
5082 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
5083 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
5091 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
5093 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5094 struct net_device
*dev
= info
->user_ptr
[1];
5095 struct mesh_config cfg
;
5096 struct mesh_setup setup
;
5099 /* start with default */
5100 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
5101 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
5103 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
5104 /* and parse parameters if given */
5105 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
5110 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
5111 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
5114 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
5115 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
5117 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
5118 /* parse additional setup parameters if given */
5119 err
= nl80211_parse_mesh_setup(info
, &setup
);
5124 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
5127 static int nl80211_leave_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
5129 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5130 struct net_device
*dev
= info
->user_ptr
[1];
5132 return cfg80211_leave_mesh(rdev
, dev
);
5135 static int nl80211_get_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
5137 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5138 struct sk_buff
*msg
;
5141 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
5144 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5148 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
5149 NL80211_CMD_GET_WOWLAN
);
5151 goto nla_put_failure
;
5154 struct nlattr
*nl_wowlan
;
5156 nl_wowlan
= nla_nest_start(msg
, NL80211_ATTR_WOWLAN_TRIGGERS
);
5158 goto nla_put_failure
;
5160 if (rdev
->wowlan
->any
)
5161 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_ANY
);
5162 if (rdev
->wowlan
->disconnect
)
5163 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_DISCONNECT
);
5164 if (rdev
->wowlan
->magic_pkt
)
5165 NLA_PUT_FLAG(msg
, NL80211_WOWLAN_TRIG_MAGIC_PKT
);
5166 if (rdev
->wowlan
->n_patterns
) {
5167 struct nlattr
*nl_pats
, *nl_pat
;
5170 nl_pats
= nla_nest_start(msg
,
5171 NL80211_WOWLAN_TRIG_PKT_PATTERN
);
5173 goto nla_put_failure
;
5175 for (i
= 0; i
< rdev
->wowlan
->n_patterns
; i
++) {
5176 nl_pat
= nla_nest_start(msg
, i
+ 1);
5178 goto nla_put_failure
;
5179 pat_len
= rdev
->wowlan
->patterns
[i
].pattern_len
;
5180 NLA_PUT(msg
, NL80211_WOWLAN_PKTPAT_MASK
,
5181 DIV_ROUND_UP(pat_len
, 8),
5182 rdev
->wowlan
->patterns
[i
].mask
);
5183 NLA_PUT(msg
, NL80211_WOWLAN_PKTPAT_PATTERN
,
5185 rdev
->wowlan
->patterns
[i
].pattern
);
5186 nla_nest_end(msg
, nl_pat
);
5188 nla_nest_end(msg
, nl_pats
);
5191 nla_nest_end(msg
, nl_wowlan
);
5194 genlmsg_end(msg
, hdr
);
5195 return genlmsg_reply(msg
, info
);
5202 static int nl80211_set_wowlan(struct sk_buff
*skb
, struct genl_info
*info
)
5204 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
5205 struct nlattr
*tb
[NUM_NL80211_WOWLAN_TRIG
];
5206 struct cfg80211_wowlan no_triggers
= {};
5207 struct cfg80211_wowlan new_triggers
= {};
5208 struct wiphy_wowlan_support
*wowlan
= &rdev
->wiphy
.wowlan
;
5211 if (!rdev
->wiphy
.wowlan
.flags
&& !rdev
->wiphy
.wowlan
.n_patterns
)
5214 if (!info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
])
5217 err
= nla_parse(tb
, MAX_NL80211_WOWLAN_TRIG
,
5218 nla_data(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
5219 nla_len(info
->attrs
[NL80211_ATTR_WOWLAN_TRIGGERS
]),
5220 nl80211_wowlan_policy
);
5224 if (tb
[NL80211_WOWLAN_TRIG_ANY
]) {
5225 if (!(wowlan
->flags
& WIPHY_WOWLAN_ANY
))
5227 new_triggers
.any
= true;
5230 if (tb
[NL80211_WOWLAN_TRIG_DISCONNECT
]) {
5231 if (!(wowlan
->flags
& WIPHY_WOWLAN_DISCONNECT
))
5233 new_triggers
.disconnect
= true;
5236 if (tb
[NL80211_WOWLAN_TRIG_MAGIC_PKT
]) {
5237 if (!(wowlan
->flags
& WIPHY_WOWLAN_MAGIC_PKT
))
5239 new_triggers
.magic_pkt
= true;
5242 if (tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
]) {
5245 int rem
, pat_len
, mask_len
;
5246 struct nlattr
*pat_tb
[NUM_NL80211_WOWLAN_PKTPAT
];
5248 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
5251 if (n_patterns
> wowlan
->n_patterns
)
5254 new_triggers
.patterns
= kcalloc(n_patterns
,
5255 sizeof(new_triggers
.patterns
[0]),
5257 if (!new_triggers
.patterns
)
5260 new_triggers
.n_patterns
= n_patterns
;
5263 nla_for_each_nested(pat
, tb
[NL80211_WOWLAN_TRIG_PKT_PATTERN
],
5265 nla_parse(pat_tb
, MAX_NL80211_WOWLAN_PKTPAT
,
5266 nla_data(pat
), nla_len(pat
), NULL
);
5268 if (!pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
] ||
5269 !pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
])
5271 pat_len
= nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]);
5272 mask_len
= DIV_ROUND_UP(pat_len
, 8);
5273 if (nla_len(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]) !=
5276 if (pat_len
> wowlan
->pattern_max_len
||
5277 pat_len
< wowlan
->pattern_min_len
)
5280 new_triggers
.patterns
[i
].mask
=
5281 kmalloc(mask_len
+ pat_len
, GFP_KERNEL
);
5282 if (!new_triggers
.patterns
[i
].mask
) {
5286 new_triggers
.patterns
[i
].pattern
=
5287 new_triggers
.patterns
[i
].mask
+ mask_len
;
5288 memcpy(new_triggers
.patterns
[i
].mask
,
5289 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_MASK
]),
5291 new_triggers
.patterns
[i
].pattern_len
= pat_len
;
5292 memcpy(new_triggers
.patterns
[i
].pattern
,
5293 nla_data(pat_tb
[NL80211_WOWLAN_PKTPAT_PATTERN
]),
5299 if (memcmp(&new_triggers
, &no_triggers
, sizeof(new_triggers
))) {
5300 struct cfg80211_wowlan
*ntrig
;
5301 ntrig
= kmemdup(&new_triggers
, sizeof(new_triggers
),
5307 cfg80211_rdev_free_wowlan(rdev
);
5308 rdev
->wowlan
= ntrig
;
5311 cfg80211_rdev_free_wowlan(rdev
);
5312 rdev
->wowlan
= NULL
;
5317 for (i
= 0; i
< new_triggers
.n_patterns
; i
++)
5318 kfree(new_triggers
.patterns
[i
].mask
);
5319 kfree(new_triggers
.patterns
);
5323 #define NL80211_FLAG_NEED_WIPHY 0x01
5324 #define NL80211_FLAG_NEED_NETDEV 0x02
5325 #define NL80211_FLAG_NEED_RTNL 0x04
5326 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
5327 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
5328 NL80211_FLAG_CHECK_NETDEV_UP)
5330 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
5331 struct genl_info
*info
)
5333 struct cfg80211_registered_device
*rdev
;
5334 struct net_device
*dev
;
5336 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
5341 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
5342 rdev
= cfg80211_get_dev_from_info(info
);
5346 return PTR_ERR(rdev
);
5348 info
->user_ptr
[0] = rdev
;
5349 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
5350 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
5356 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
5357 !netif_running(dev
)) {
5358 cfg80211_unlock_rdev(rdev
);
5364 info
->user_ptr
[0] = rdev
;
5365 info
->user_ptr
[1] = dev
;
5371 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
5372 struct genl_info
*info
)
5374 if (info
->user_ptr
[0])
5375 cfg80211_unlock_rdev(info
->user_ptr
[0]);
5376 if (info
->user_ptr
[1])
5377 dev_put(info
->user_ptr
[1]);
5378 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
5382 static struct genl_ops nl80211_ops
[] = {
5384 .cmd
= NL80211_CMD_GET_WIPHY
,
5385 .doit
= nl80211_get_wiphy
,
5386 .dumpit
= nl80211_dump_wiphy
,
5387 .policy
= nl80211_policy
,
5388 /* can be retrieved by unprivileged users */
5389 .internal_flags
= NL80211_FLAG_NEED_WIPHY
,
5392 .cmd
= NL80211_CMD_SET_WIPHY
,
5393 .doit
= nl80211_set_wiphy
,
5394 .policy
= nl80211_policy
,
5395 .flags
= GENL_ADMIN_PERM
,
5396 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
5399 .cmd
= NL80211_CMD_GET_INTERFACE
,
5400 .doit
= nl80211_get_interface
,
5401 .dumpit
= nl80211_dump_interface
,
5402 .policy
= nl80211_policy
,
5403 /* can be retrieved by unprivileged users */
5404 .internal_flags
= NL80211_FLAG_NEED_NETDEV
,
5407 .cmd
= NL80211_CMD_SET_INTERFACE
,
5408 .doit
= nl80211_set_interface
,
5409 .policy
= nl80211_policy
,
5410 .flags
= GENL_ADMIN_PERM
,
5411 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5412 NL80211_FLAG_NEED_RTNL
,
5415 .cmd
= NL80211_CMD_NEW_INTERFACE
,
5416 .doit
= nl80211_new_interface
,
5417 .policy
= nl80211_policy
,
5418 .flags
= GENL_ADMIN_PERM
,
5419 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
5420 NL80211_FLAG_NEED_RTNL
,
5423 .cmd
= NL80211_CMD_DEL_INTERFACE
,
5424 .doit
= nl80211_del_interface
,
5425 .policy
= nl80211_policy
,
5426 .flags
= GENL_ADMIN_PERM
,
5427 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5428 NL80211_FLAG_NEED_RTNL
,
5431 .cmd
= NL80211_CMD_GET_KEY
,
5432 .doit
= nl80211_get_key
,
5433 .policy
= nl80211_policy
,
5434 .flags
= GENL_ADMIN_PERM
,
5435 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5436 NL80211_FLAG_NEED_RTNL
,
5439 .cmd
= NL80211_CMD_SET_KEY
,
5440 .doit
= nl80211_set_key
,
5441 .policy
= nl80211_policy
,
5442 .flags
= GENL_ADMIN_PERM
,
5443 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5444 NL80211_FLAG_NEED_RTNL
,
5447 .cmd
= NL80211_CMD_NEW_KEY
,
5448 .doit
= nl80211_new_key
,
5449 .policy
= nl80211_policy
,
5450 .flags
= GENL_ADMIN_PERM
,
5451 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5452 NL80211_FLAG_NEED_RTNL
,
5455 .cmd
= NL80211_CMD_DEL_KEY
,
5456 .doit
= nl80211_del_key
,
5457 .policy
= nl80211_policy
,
5458 .flags
= GENL_ADMIN_PERM
,
5459 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5460 NL80211_FLAG_NEED_RTNL
,
5463 .cmd
= NL80211_CMD_SET_BEACON
,
5464 .policy
= nl80211_policy
,
5465 .flags
= GENL_ADMIN_PERM
,
5466 .doit
= nl80211_addset_beacon
,
5467 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5468 NL80211_FLAG_NEED_RTNL
,
5471 .cmd
= NL80211_CMD_NEW_BEACON
,
5472 .policy
= nl80211_policy
,
5473 .flags
= GENL_ADMIN_PERM
,
5474 .doit
= nl80211_addset_beacon
,
5475 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5476 NL80211_FLAG_NEED_RTNL
,
5479 .cmd
= NL80211_CMD_DEL_BEACON
,
5480 .policy
= nl80211_policy
,
5481 .flags
= GENL_ADMIN_PERM
,
5482 .doit
= nl80211_del_beacon
,
5483 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5484 NL80211_FLAG_NEED_RTNL
,
5487 .cmd
= NL80211_CMD_GET_STATION
,
5488 .doit
= nl80211_get_station
,
5489 .dumpit
= nl80211_dump_station
,
5490 .policy
= nl80211_policy
,
5491 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5492 NL80211_FLAG_NEED_RTNL
,
5495 .cmd
= NL80211_CMD_SET_STATION
,
5496 .doit
= nl80211_set_station
,
5497 .policy
= nl80211_policy
,
5498 .flags
= GENL_ADMIN_PERM
,
5499 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5500 NL80211_FLAG_NEED_RTNL
,
5503 .cmd
= NL80211_CMD_NEW_STATION
,
5504 .doit
= nl80211_new_station
,
5505 .policy
= nl80211_policy
,
5506 .flags
= GENL_ADMIN_PERM
,
5507 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5508 NL80211_FLAG_NEED_RTNL
,
5511 .cmd
= NL80211_CMD_DEL_STATION
,
5512 .doit
= nl80211_del_station
,
5513 .policy
= nl80211_policy
,
5514 .flags
= GENL_ADMIN_PERM
,
5515 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5516 NL80211_FLAG_NEED_RTNL
,
5519 .cmd
= NL80211_CMD_GET_MPATH
,
5520 .doit
= nl80211_get_mpath
,
5521 .dumpit
= nl80211_dump_mpath
,
5522 .policy
= nl80211_policy
,
5523 .flags
= GENL_ADMIN_PERM
,
5524 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5525 NL80211_FLAG_NEED_RTNL
,
5528 .cmd
= NL80211_CMD_SET_MPATH
,
5529 .doit
= nl80211_set_mpath
,
5530 .policy
= nl80211_policy
,
5531 .flags
= GENL_ADMIN_PERM
,
5532 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5533 NL80211_FLAG_NEED_RTNL
,
5536 .cmd
= NL80211_CMD_NEW_MPATH
,
5537 .doit
= nl80211_new_mpath
,
5538 .policy
= nl80211_policy
,
5539 .flags
= GENL_ADMIN_PERM
,
5540 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5541 NL80211_FLAG_NEED_RTNL
,
5544 .cmd
= NL80211_CMD_DEL_MPATH
,
5545 .doit
= nl80211_del_mpath
,
5546 .policy
= nl80211_policy
,
5547 .flags
= GENL_ADMIN_PERM
,
5548 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5549 NL80211_FLAG_NEED_RTNL
,
5552 .cmd
= NL80211_CMD_SET_BSS
,
5553 .doit
= nl80211_set_bss
,
5554 .policy
= nl80211_policy
,
5555 .flags
= GENL_ADMIN_PERM
,
5556 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5557 NL80211_FLAG_NEED_RTNL
,
5560 .cmd
= NL80211_CMD_GET_REG
,
5561 .doit
= nl80211_get_reg
,
5562 .policy
= nl80211_policy
,
5563 /* can be retrieved by unprivileged users */
5566 .cmd
= NL80211_CMD_SET_REG
,
5567 .doit
= nl80211_set_reg
,
5568 .policy
= nl80211_policy
,
5569 .flags
= GENL_ADMIN_PERM
,
5572 .cmd
= NL80211_CMD_REQ_SET_REG
,
5573 .doit
= nl80211_req_set_reg
,
5574 .policy
= nl80211_policy
,
5575 .flags
= GENL_ADMIN_PERM
,
5578 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
5579 .doit
= nl80211_get_mesh_config
,
5580 .policy
= nl80211_policy
,
5581 /* can be retrieved by unprivileged users */
5582 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5583 NL80211_FLAG_NEED_RTNL
,
5586 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
5587 .doit
= nl80211_update_mesh_config
,
5588 .policy
= nl80211_policy
,
5589 .flags
= GENL_ADMIN_PERM
,
5590 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5591 NL80211_FLAG_NEED_RTNL
,
5594 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
5595 .doit
= nl80211_trigger_scan
,
5596 .policy
= nl80211_policy
,
5597 .flags
= GENL_ADMIN_PERM
,
5598 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5599 NL80211_FLAG_NEED_RTNL
,
5602 .cmd
= NL80211_CMD_GET_SCAN
,
5603 .policy
= nl80211_policy
,
5604 .dumpit
= nl80211_dump_scan
,
5607 .cmd
= NL80211_CMD_START_SCHED_SCAN
,
5608 .doit
= nl80211_start_sched_scan
,
5609 .policy
= nl80211_policy
,
5610 .flags
= GENL_ADMIN_PERM
,
5611 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5612 NL80211_FLAG_NEED_RTNL
,
5615 .cmd
= NL80211_CMD_STOP_SCHED_SCAN
,
5616 .doit
= nl80211_stop_sched_scan
,
5617 .policy
= nl80211_policy
,
5618 .flags
= GENL_ADMIN_PERM
,
5619 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5620 NL80211_FLAG_NEED_RTNL
,
5623 .cmd
= NL80211_CMD_AUTHENTICATE
,
5624 .doit
= nl80211_authenticate
,
5625 .policy
= nl80211_policy
,
5626 .flags
= GENL_ADMIN_PERM
,
5627 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5628 NL80211_FLAG_NEED_RTNL
,
5631 .cmd
= NL80211_CMD_ASSOCIATE
,
5632 .doit
= nl80211_associate
,
5633 .policy
= nl80211_policy
,
5634 .flags
= GENL_ADMIN_PERM
,
5635 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5636 NL80211_FLAG_NEED_RTNL
,
5639 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
5640 .doit
= nl80211_deauthenticate
,
5641 .policy
= nl80211_policy
,
5642 .flags
= GENL_ADMIN_PERM
,
5643 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5644 NL80211_FLAG_NEED_RTNL
,
5647 .cmd
= NL80211_CMD_DISASSOCIATE
,
5648 .doit
= nl80211_disassociate
,
5649 .policy
= nl80211_policy
,
5650 .flags
= GENL_ADMIN_PERM
,
5651 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5652 NL80211_FLAG_NEED_RTNL
,
5655 .cmd
= NL80211_CMD_JOIN_IBSS
,
5656 .doit
= nl80211_join_ibss
,
5657 .policy
= nl80211_policy
,
5658 .flags
= GENL_ADMIN_PERM
,
5659 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5660 NL80211_FLAG_NEED_RTNL
,
5663 .cmd
= NL80211_CMD_LEAVE_IBSS
,
5664 .doit
= nl80211_leave_ibss
,
5665 .policy
= nl80211_policy
,
5666 .flags
= GENL_ADMIN_PERM
,
5667 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5668 NL80211_FLAG_NEED_RTNL
,
5670 #ifdef CONFIG_NL80211_TESTMODE
5672 .cmd
= NL80211_CMD_TESTMODE
,
5673 .doit
= nl80211_testmode_do
,
5674 .policy
= nl80211_policy
,
5675 .flags
= GENL_ADMIN_PERM
,
5676 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
5677 NL80211_FLAG_NEED_RTNL
,
5681 .cmd
= NL80211_CMD_CONNECT
,
5682 .doit
= nl80211_connect
,
5683 .policy
= nl80211_policy
,
5684 .flags
= GENL_ADMIN_PERM
,
5685 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5686 NL80211_FLAG_NEED_RTNL
,
5689 .cmd
= NL80211_CMD_DISCONNECT
,
5690 .doit
= nl80211_disconnect
,
5691 .policy
= nl80211_policy
,
5692 .flags
= GENL_ADMIN_PERM
,
5693 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5694 NL80211_FLAG_NEED_RTNL
,
5697 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
5698 .doit
= nl80211_wiphy_netns
,
5699 .policy
= nl80211_policy
,
5700 .flags
= GENL_ADMIN_PERM
,
5701 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
5702 NL80211_FLAG_NEED_RTNL
,
5705 .cmd
= NL80211_CMD_GET_SURVEY
,
5706 .policy
= nl80211_policy
,
5707 .dumpit
= nl80211_dump_survey
,
5710 .cmd
= NL80211_CMD_SET_PMKSA
,
5711 .doit
= nl80211_setdel_pmksa
,
5712 .policy
= nl80211_policy
,
5713 .flags
= GENL_ADMIN_PERM
,
5714 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5715 NL80211_FLAG_NEED_RTNL
,
5718 .cmd
= NL80211_CMD_DEL_PMKSA
,
5719 .doit
= nl80211_setdel_pmksa
,
5720 .policy
= nl80211_policy
,
5721 .flags
= GENL_ADMIN_PERM
,
5722 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5723 NL80211_FLAG_NEED_RTNL
,
5726 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
5727 .doit
= nl80211_flush_pmksa
,
5728 .policy
= nl80211_policy
,
5729 .flags
= GENL_ADMIN_PERM
,
5730 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5731 NL80211_FLAG_NEED_RTNL
,
5734 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
5735 .doit
= nl80211_remain_on_channel
,
5736 .policy
= nl80211_policy
,
5737 .flags
= GENL_ADMIN_PERM
,
5738 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5739 NL80211_FLAG_NEED_RTNL
,
5742 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
5743 .doit
= nl80211_cancel_remain_on_channel
,
5744 .policy
= nl80211_policy
,
5745 .flags
= GENL_ADMIN_PERM
,
5746 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5747 NL80211_FLAG_NEED_RTNL
,
5750 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
5751 .doit
= nl80211_set_tx_bitrate_mask
,
5752 .policy
= nl80211_policy
,
5753 .flags
= GENL_ADMIN_PERM
,
5754 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5755 NL80211_FLAG_NEED_RTNL
,
5758 .cmd
= NL80211_CMD_REGISTER_FRAME
,
5759 .doit
= nl80211_register_mgmt
,
5760 .policy
= nl80211_policy
,
5761 .flags
= GENL_ADMIN_PERM
,
5762 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5763 NL80211_FLAG_NEED_RTNL
,
5766 .cmd
= NL80211_CMD_FRAME
,
5767 .doit
= nl80211_tx_mgmt
,
5768 .policy
= nl80211_policy
,
5769 .flags
= GENL_ADMIN_PERM
,
5770 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5771 NL80211_FLAG_NEED_RTNL
,
5774 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
5775 .doit
= nl80211_tx_mgmt_cancel_wait
,
5776 .policy
= nl80211_policy
,
5777 .flags
= GENL_ADMIN_PERM
,
5778 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5779 NL80211_FLAG_NEED_RTNL
,
5782 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
5783 .doit
= nl80211_set_power_save
,
5784 .policy
= nl80211_policy
,
5785 .flags
= GENL_ADMIN_PERM
,
5786 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5787 NL80211_FLAG_NEED_RTNL
,
5790 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
5791 .doit
= nl80211_get_power_save
,
5792 .policy
= nl80211_policy
,
5793 /* can be retrieved by unprivileged users */
5794 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5795 NL80211_FLAG_NEED_RTNL
,
5798 .cmd
= NL80211_CMD_SET_CQM
,
5799 .doit
= nl80211_set_cqm
,
5800 .policy
= nl80211_policy
,
5801 .flags
= GENL_ADMIN_PERM
,
5802 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5803 NL80211_FLAG_NEED_RTNL
,
5806 .cmd
= NL80211_CMD_SET_CHANNEL
,
5807 .doit
= nl80211_set_channel
,
5808 .policy
= nl80211_policy
,
5809 .flags
= GENL_ADMIN_PERM
,
5810 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5811 NL80211_FLAG_NEED_RTNL
,
5814 .cmd
= NL80211_CMD_SET_WDS_PEER
,
5815 .doit
= nl80211_set_wds_peer
,
5816 .policy
= nl80211_policy
,
5817 .flags
= GENL_ADMIN_PERM
,
5818 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5819 NL80211_FLAG_NEED_RTNL
,
5822 .cmd
= NL80211_CMD_JOIN_MESH
,
5823 .doit
= nl80211_join_mesh
,
5824 .policy
= nl80211_policy
,
5825 .flags
= GENL_ADMIN_PERM
,
5826 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5827 NL80211_FLAG_NEED_RTNL
,
5830 .cmd
= NL80211_CMD_LEAVE_MESH
,
5831 .doit
= nl80211_leave_mesh
,
5832 .policy
= nl80211_policy
,
5833 .flags
= GENL_ADMIN_PERM
,
5834 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5835 NL80211_FLAG_NEED_RTNL
,
5838 .cmd
= NL80211_CMD_GET_WOWLAN
,
5839 .doit
= nl80211_get_wowlan
,
5840 .policy
= nl80211_policy
,
5841 /* can be retrieved by unprivileged users */
5842 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
5843 NL80211_FLAG_NEED_RTNL
,
5846 .cmd
= NL80211_CMD_SET_WOWLAN
,
5847 .doit
= nl80211_set_wowlan
,
5848 .policy
= nl80211_policy
,
5849 .flags
= GENL_ADMIN_PERM
,
5850 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
5851 NL80211_FLAG_NEED_RTNL
,
5855 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
5859 /* multicast groups */
5860 static struct genl_multicast_group nl80211_config_mcgrp
= {
5863 static struct genl_multicast_group nl80211_scan_mcgrp
= {
5866 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
5867 .name
= "regulatory",
5870 /* notification functions */
5872 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
5874 struct sk_buff
*msg
;
5876 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5880 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
5885 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5886 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
5889 static int nl80211_add_scan_req(struct sk_buff
*msg
,
5890 struct cfg80211_registered_device
*rdev
)
5892 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
5893 struct nlattr
*nest
;
5896 ASSERT_RDEV_LOCK(rdev
);
5901 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
5903 goto nla_put_failure
;
5904 for (i
= 0; i
< req
->n_ssids
; i
++)
5905 NLA_PUT(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
);
5906 nla_nest_end(msg
, nest
);
5908 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
5910 goto nla_put_failure
;
5911 for (i
= 0; i
< req
->n_channels
; i
++)
5912 NLA_PUT_U32(msg
, i
, req
->channels
[i
]->center_freq
);
5913 nla_nest_end(msg
, nest
);
5916 NLA_PUT(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
);
5923 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
5924 struct cfg80211_registered_device
*rdev
,
5925 struct net_device
*netdev
,
5926 u32 pid
, u32 seq
, int flags
,
5931 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
5935 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5936 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5938 /* ignore errors and send incomplete event anyway */
5939 nl80211_add_scan_req(msg
, rdev
);
5941 return genlmsg_end(msg
, hdr
);
5944 genlmsg_cancel(msg
, hdr
);
5949 nl80211_send_sched_scan_msg(struct sk_buff
*msg
,
5950 struct cfg80211_registered_device
*rdev
,
5951 struct net_device
*netdev
,
5952 u32 pid
, u32 seq
, int flags
, u32 cmd
)
5956 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
5960 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5961 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5963 return genlmsg_end(msg
, hdr
);
5966 genlmsg_cancel(msg
, hdr
);
5970 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
5971 struct net_device
*netdev
)
5973 struct sk_buff
*msg
;
5975 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
5979 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5980 NL80211_CMD_TRIGGER_SCAN
) < 0) {
5985 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5986 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5989 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
5990 struct net_device
*netdev
)
5992 struct sk_buff
*msg
;
5994 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5998 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5999 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
6004 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6005 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6008 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
6009 struct net_device
*netdev
)
6011 struct sk_buff
*msg
;
6013 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6017 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
6018 NL80211_CMD_SCAN_ABORTED
) < 0) {
6023 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6024 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6027 void nl80211_send_sched_scan_results(struct cfg80211_registered_device
*rdev
,
6028 struct net_device
*netdev
)
6030 struct sk_buff
*msg
;
6032 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6036 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
6037 NL80211_CMD_SCHED_SCAN_RESULTS
) < 0) {
6042 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6043 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6046 void nl80211_send_sched_scan(struct cfg80211_registered_device
*rdev
,
6047 struct net_device
*netdev
, u32 cmd
)
6049 struct sk_buff
*msg
;
6051 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
6055 if (nl80211_send_sched_scan_msg(msg
, rdev
, netdev
, 0, 0, 0, cmd
) < 0) {
6060 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6061 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
6065 * This can happen on global regulatory changes or device specific settings
6066 * based on custom world regulatory domains.
6068 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
6070 struct sk_buff
*msg
;
6073 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
6077 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
6083 /* Userspace can always count this one always being set */
6084 NLA_PUT_U8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
);
6086 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0')
6087 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6088 NL80211_REGDOM_TYPE_WORLD
);
6089 else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9')
6090 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6091 NL80211_REGDOM_TYPE_CUSTOM_WORLD
);
6092 else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
6094 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6095 NL80211_REGDOM_TYPE_INTERSECTION
);
6097 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
6098 NL80211_REGDOM_TYPE_COUNTRY
);
6099 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, request
->alpha2
);
6102 if (wiphy_idx_valid(request
->wiphy_idx
))
6103 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
);
6105 if (genlmsg_end(msg
, hdr
) < 0) {
6111 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
6118 genlmsg_cancel(msg
, hdr
);
6122 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
6123 struct net_device
*netdev
,
6124 const u8
*buf
, size_t len
,
6125 enum nl80211_commands cmd
, gfp_t gfp
)
6127 struct sk_buff
*msg
;
6130 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6134 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
6140 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6141 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6142 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
6144 if (genlmsg_end(msg
, hdr
) < 0) {
6149 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6150 nl80211_mlme_mcgrp
.id
, gfp
);
6154 genlmsg_cancel(msg
, hdr
);
6158 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
6159 struct net_device
*netdev
, const u8
*buf
,
6160 size_t len
, gfp_t gfp
)
6162 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6163 NL80211_CMD_AUTHENTICATE
, gfp
);
6166 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
6167 struct net_device
*netdev
, const u8
*buf
,
6168 size_t len
, gfp_t gfp
)
6170 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6171 NL80211_CMD_ASSOCIATE
, gfp
);
6174 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
6175 struct net_device
*netdev
, const u8
*buf
,
6176 size_t len
, gfp_t gfp
)
6178 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6179 NL80211_CMD_DEAUTHENTICATE
, gfp
);
6182 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
6183 struct net_device
*netdev
, const u8
*buf
,
6184 size_t len
, gfp_t gfp
)
6186 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6187 NL80211_CMD_DISASSOCIATE
, gfp
);
6190 void nl80211_send_unprot_deauth(struct cfg80211_registered_device
*rdev
,
6191 struct net_device
*netdev
, const u8
*buf
,
6192 size_t len
, gfp_t gfp
)
6194 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6195 NL80211_CMD_UNPROT_DEAUTHENTICATE
, gfp
);
6198 void nl80211_send_unprot_disassoc(struct cfg80211_registered_device
*rdev
,
6199 struct net_device
*netdev
, const u8
*buf
,
6200 size_t len
, gfp_t gfp
)
6202 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
6203 NL80211_CMD_UNPROT_DISASSOCIATE
, gfp
);
6206 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
6207 struct net_device
*netdev
, int cmd
,
6208 const u8
*addr
, gfp_t gfp
)
6210 struct sk_buff
*msg
;
6213 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6217 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
6223 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6224 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6225 NLA_PUT_FLAG(msg
, NL80211_ATTR_TIMED_OUT
);
6226 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
6228 if (genlmsg_end(msg
, hdr
) < 0) {
6233 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6234 nl80211_mlme_mcgrp
.id
, gfp
);
6238 genlmsg_cancel(msg
, hdr
);
6242 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
6243 struct net_device
*netdev
, const u8
*addr
,
6246 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
6250 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
6251 struct net_device
*netdev
, const u8
*addr
,
6254 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
6258 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
6259 struct net_device
*netdev
, const u8
*bssid
,
6260 const u8
*req_ie
, size_t req_ie_len
,
6261 const u8
*resp_ie
, size_t resp_ie_len
,
6262 u16 status
, gfp_t gfp
)
6264 struct sk_buff
*msg
;
6267 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6271 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
6277 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6278 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6280 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
6281 NLA_PUT_U16(msg
, NL80211_ATTR_STATUS_CODE
, status
);
6283 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
6285 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
6287 if (genlmsg_end(msg
, hdr
) < 0) {
6292 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6293 nl80211_mlme_mcgrp
.id
, gfp
);
6297 genlmsg_cancel(msg
, hdr
);
6302 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
6303 struct net_device
*netdev
, const u8
*bssid
,
6304 const u8
*req_ie
, size_t req_ie_len
,
6305 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
6307 struct sk_buff
*msg
;
6310 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6314 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
6320 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6321 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6322 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
6324 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
6326 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
6328 if (genlmsg_end(msg
, hdr
) < 0) {
6333 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6334 nl80211_mlme_mcgrp
.id
, gfp
);
6338 genlmsg_cancel(msg
, hdr
);
6343 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
6344 struct net_device
*netdev
, u16 reason
,
6345 const u8
*ie
, size_t ie_len
, bool from_ap
)
6347 struct sk_buff
*msg
;
6350 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
6354 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
6360 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6361 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6362 if (from_ap
&& reason
)
6363 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason
);
6365 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
);
6367 NLA_PUT(msg
, NL80211_ATTR_IE
, ie_len
, ie
);
6369 if (genlmsg_end(msg
, hdr
) < 0) {
6374 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6375 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
6379 genlmsg_cancel(msg
, hdr
);
6384 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
6385 struct net_device
*netdev
, const u8
*bssid
,
6388 struct sk_buff
*msg
;
6391 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6395 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
6401 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6402 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6403 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
6405 if (genlmsg_end(msg
, hdr
) < 0) {
6410 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6411 nl80211_mlme_mcgrp
.id
, gfp
);
6415 genlmsg_cancel(msg
, hdr
);
6419 void nl80211_send_new_peer_candidate(struct cfg80211_registered_device
*rdev
,
6420 struct net_device
*netdev
,
6421 const u8
*macaddr
, const u8
* ie
, u8 ie_len
,
6424 struct sk_buff
*msg
;
6427 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6431 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
6437 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6438 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6439 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, macaddr
);
6441 NLA_PUT(msg
, NL80211_ATTR_IE
, ie_len
, ie
);
6443 if (genlmsg_end(msg
, hdr
) < 0) {
6448 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6449 nl80211_mlme_mcgrp
.id
, gfp
);
6453 genlmsg_cancel(msg
, hdr
);
6457 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
6458 struct net_device
*netdev
, const u8
*addr
,
6459 enum nl80211_key_type key_type
, int key_id
,
6460 const u8
*tsc
, gfp_t gfp
)
6462 struct sk_buff
*msg
;
6465 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6469 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
6475 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6476 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6478 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
6479 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
);
6481 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_id
);
6483 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
);
6485 if (genlmsg_end(msg
, hdr
) < 0) {
6490 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6491 nl80211_mlme_mcgrp
.id
, gfp
);
6495 genlmsg_cancel(msg
, hdr
);
6499 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
6500 struct ieee80211_channel
*channel_before
,
6501 struct ieee80211_channel
*channel_after
)
6503 struct sk_buff
*msg
;
6505 struct nlattr
*nl_freq
;
6507 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
6511 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
6518 * Since we are applying the beacon hint to a wiphy we know its
6519 * wiphy_idx is valid
6521 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
));
6524 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
6526 goto nla_put_failure
;
6527 if (nl80211_msg_put_channel(msg
, channel_before
))
6528 goto nla_put_failure
;
6529 nla_nest_end(msg
, nl_freq
);
6532 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
6534 goto nla_put_failure
;
6535 if (nl80211_msg_put_channel(msg
, channel_after
))
6536 goto nla_put_failure
;
6537 nla_nest_end(msg
, nl_freq
);
6539 if (genlmsg_end(msg
, hdr
) < 0) {
6545 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
6552 genlmsg_cancel(msg
, hdr
);
6556 static void nl80211_send_remain_on_chan_event(
6557 int cmd
, struct cfg80211_registered_device
*rdev
,
6558 struct net_device
*netdev
, u64 cookie
,
6559 struct ieee80211_channel
*chan
,
6560 enum nl80211_channel_type channel_type
,
6561 unsigned int duration
, gfp_t gfp
)
6563 struct sk_buff
*msg
;
6566 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6570 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
6576 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6577 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6578 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
);
6579 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, channel_type
);
6580 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
6582 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
)
6583 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, duration
);
6585 if (genlmsg_end(msg
, hdr
) < 0) {
6590 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6591 nl80211_mlme_mcgrp
.id
, gfp
);
6595 genlmsg_cancel(msg
, hdr
);
6599 void nl80211_send_remain_on_channel(struct cfg80211_registered_device
*rdev
,
6600 struct net_device
*netdev
, u64 cookie
,
6601 struct ieee80211_channel
*chan
,
6602 enum nl80211_channel_type channel_type
,
6603 unsigned int duration
, gfp_t gfp
)
6605 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
6606 rdev
, netdev
, cookie
, chan
,
6607 channel_type
, duration
, gfp
);
6610 void nl80211_send_remain_on_channel_cancel(
6611 struct cfg80211_registered_device
*rdev
, struct net_device
*netdev
,
6612 u64 cookie
, struct ieee80211_channel
*chan
,
6613 enum nl80211_channel_type channel_type
, gfp_t gfp
)
6615 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
6616 rdev
, netdev
, cookie
, chan
,
6617 channel_type
, 0, gfp
);
6620 void nl80211_send_sta_event(struct cfg80211_registered_device
*rdev
,
6621 struct net_device
*dev
, const u8
*mac_addr
,
6622 struct station_info
*sinfo
, gfp_t gfp
)
6624 struct sk_buff
*msg
;
6626 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6630 if (nl80211_send_station(msg
, 0, 0, 0, dev
, mac_addr
, sinfo
) < 0) {
6635 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6636 nl80211_mlme_mcgrp
.id
, gfp
);
6639 void nl80211_send_sta_del_event(struct cfg80211_registered_device
*rdev
,
6640 struct net_device
*dev
, const u8
*mac_addr
,
6643 struct sk_buff
*msg
;
6646 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6650 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_STATION
);
6656 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
6657 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
6659 if (genlmsg_end(msg
, hdr
) < 0) {
6664 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6665 nl80211_mlme_mcgrp
.id
, gfp
);
6669 genlmsg_cancel(msg
, hdr
);
6673 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
6674 struct net_device
*netdev
, u32 nlpid
,
6675 int freq
, const u8
*buf
, size_t len
, gfp_t gfp
)
6677 struct sk_buff
*msg
;
6681 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6685 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
6691 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6692 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6693 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
6694 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
6696 err
= genlmsg_end(msg
, hdr
);
6702 err
= genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
6708 genlmsg_cancel(msg
, hdr
);
6713 void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device
*rdev
,
6714 struct net_device
*netdev
, u64 cookie
,
6715 const u8
*buf
, size_t len
, bool ack
,
6718 struct sk_buff
*msg
;
6721 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6725 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
6731 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6732 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6733 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
6734 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
6736 NLA_PUT_FLAG(msg
, NL80211_ATTR_ACK
);
6738 if (genlmsg_end(msg
, hdr
) < 0) {
6743 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
6747 genlmsg_cancel(msg
, hdr
);
6752 nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device
*rdev
,
6753 struct net_device
*netdev
,
6754 enum nl80211_cqm_rssi_threshold_event rssi_event
,
6757 struct sk_buff
*msg
;
6758 struct nlattr
*pinfoattr
;
6761 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6765 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
6771 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6772 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6774 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
6776 goto nla_put_failure
;
6778 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
6781 nla_nest_end(msg
, pinfoattr
);
6783 if (genlmsg_end(msg
, hdr
) < 0) {
6788 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6789 nl80211_mlme_mcgrp
.id
, gfp
);
6793 genlmsg_cancel(msg
, hdr
);
6798 nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device
*rdev
,
6799 struct net_device
*netdev
, const u8
*peer
,
6800 u32 num_packets
, gfp_t gfp
)
6802 struct sk_buff
*msg
;
6803 struct nlattr
*pinfoattr
;
6806 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6810 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
6816 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6817 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6818 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
);
6820 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
6822 goto nla_put_failure
;
6824 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
);
6826 nla_nest_end(msg
, pinfoattr
);
6828 if (genlmsg_end(msg
, hdr
) < 0) {
6833 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6834 nl80211_mlme_mcgrp
.id
, gfp
);
6838 genlmsg_cancel(msg
, hdr
);
6842 static int nl80211_netlink_notify(struct notifier_block
* nb
,
6843 unsigned long state
,
6846 struct netlink_notify
*notify
= _notify
;
6847 struct cfg80211_registered_device
*rdev
;
6848 struct wireless_dev
*wdev
;
6850 if (state
!= NETLINK_URELEASE
)
6855 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
)
6856 list_for_each_entry_rcu(wdev
, &rdev
->netdev_list
, list
)
6857 cfg80211_mlme_unregister_socket(wdev
, notify
->pid
);
6864 static struct notifier_block nl80211_netlink_notifier
= {
6865 .notifier_call
= nl80211_netlink_notify
,
6868 /* initialisation/exit functions */
6870 int nl80211_init(void)
6874 err
= genl_register_family_with_ops(&nl80211_fam
,
6875 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
6879 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
6883 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
6887 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
6891 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
6895 #ifdef CONFIG_NL80211_TESTMODE
6896 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
6901 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
6907 genl_unregister_family(&nl80211_fam
);
6911 void nl80211_exit(void)
6913 netlink_unregister_notifier(&nl80211_netlink_notifier
);
6914 genl_unregister_family(&nl80211_fam
);