2 * This is the new netlink-based wireless configuration interface.
4 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
8 #include <linux/module.h>
10 #include <linux/slab.h>
11 #include <linux/list.h>
12 #include <linux/if_ether.h>
13 #include <linux/ieee80211.h>
14 #include <linux/nl80211.h>
15 #include <linux/rtnetlink.h>
16 #include <linux/netlink.h>
17 #include <linux/etherdevice.h>
18 #include <net/net_namespace.h>
19 #include <net/genetlink.h>
20 #include <net/cfg80211.h>
26 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
27 struct genl_info
*info
);
28 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
29 struct genl_info
*info
);
31 /* the netlink family */
32 static struct genl_family nl80211_fam
= {
33 .id
= GENL_ID_GENERATE
, /* don't bother with a hardcoded ID */
34 .name
= "nl80211", /* have users key off the name instead */
35 .hdrsize
= 0, /* no private header */
36 .version
= 1, /* no particular meaning now */
37 .maxattr
= NL80211_ATTR_MAX
,
39 .pre_doit
= nl80211_pre_doit
,
40 .post_doit
= nl80211_post_doit
,
43 /* internal helper: get rdev and dev */
44 static int get_rdev_dev_by_info_ifindex(struct genl_info
*info
,
45 struct cfg80211_registered_device
**rdev
,
46 struct net_device
**dev
)
48 struct nlattr
**attrs
= info
->attrs
;
51 if (!attrs
[NL80211_ATTR_IFINDEX
])
54 ifindex
= nla_get_u32(attrs
[NL80211_ATTR_IFINDEX
]);
55 *dev
= dev_get_by_index(genl_info_net(info
), ifindex
);
59 *rdev
= cfg80211_get_dev_from_ifindex(genl_info_net(info
), ifindex
);
62 return PTR_ERR(*rdev
);
68 /* policy for the attributes */
69 static const struct nla_policy nl80211_policy
[NL80211_ATTR_MAX
+1] = {
70 [NL80211_ATTR_WIPHY
] = { .type
= NLA_U32
},
71 [NL80211_ATTR_WIPHY_NAME
] = { .type
= NLA_NUL_STRING
,
73 [NL80211_ATTR_WIPHY_TXQ_PARAMS
] = { .type
= NLA_NESTED
},
74 [NL80211_ATTR_WIPHY_FREQ
] = { .type
= NLA_U32
},
75 [NL80211_ATTR_WIPHY_CHANNEL_TYPE
] = { .type
= NLA_U32
},
76 [NL80211_ATTR_WIPHY_RETRY_SHORT
] = { .type
= NLA_U8
},
77 [NL80211_ATTR_WIPHY_RETRY_LONG
] = { .type
= NLA_U8
},
78 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD
] = { .type
= NLA_U32
},
79 [NL80211_ATTR_WIPHY_RTS_THRESHOLD
] = { .type
= NLA_U32
},
80 [NL80211_ATTR_WIPHY_COVERAGE_CLASS
] = { .type
= NLA_U8
},
82 [NL80211_ATTR_IFTYPE
] = { .type
= NLA_U32
},
83 [NL80211_ATTR_IFINDEX
] = { .type
= NLA_U32
},
84 [NL80211_ATTR_IFNAME
] = { .type
= NLA_NUL_STRING
, .len
= IFNAMSIZ
-1 },
86 [NL80211_ATTR_MAC
] = { .type
= NLA_BINARY
, .len
= ETH_ALEN
},
87 [NL80211_ATTR_PREV_BSSID
] = { .type
= NLA_BINARY
, .len
= ETH_ALEN
},
89 [NL80211_ATTR_KEY
] = { .type
= NLA_NESTED
, },
90 [NL80211_ATTR_KEY_DATA
] = { .type
= NLA_BINARY
,
91 .len
= WLAN_MAX_KEY_LEN
},
92 [NL80211_ATTR_KEY_IDX
] = { .type
= NLA_U8
},
93 [NL80211_ATTR_KEY_CIPHER
] = { .type
= NLA_U32
},
94 [NL80211_ATTR_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
95 [NL80211_ATTR_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 8 },
96 [NL80211_ATTR_KEY_TYPE
] = { .type
= NLA_U32
},
98 [NL80211_ATTR_BEACON_INTERVAL
] = { .type
= NLA_U32
},
99 [NL80211_ATTR_DTIM_PERIOD
] = { .type
= NLA_U32
},
100 [NL80211_ATTR_BEACON_HEAD
] = { .type
= NLA_BINARY
,
101 .len
= IEEE80211_MAX_DATA_LEN
},
102 [NL80211_ATTR_BEACON_TAIL
] = { .type
= NLA_BINARY
,
103 .len
= IEEE80211_MAX_DATA_LEN
},
104 [NL80211_ATTR_STA_AID
] = { .type
= NLA_U16
},
105 [NL80211_ATTR_STA_FLAGS
] = { .type
= NLA_NESTED
},
106 [NL80211_ATTR_STA_LISTEN_INTERVAL
] = { .type
= NLA_U16
},
107 [NL80211_ATTR_STA_SUPPORTED_RATES
] = { .type
= NLA_BINARY
,
108 .len
= NL80211_MAX_SUPP_RATES
},
109 [NL80211_ATTR_STA_PLINK_ACTION
] = { .type
= NLA_U8
},
110 [NL80211_ATTR_STA_VLAN
] = { .type
= NLA_U32
},
111 [NL80211_ATTR_MNTR_FLAGS
] = { /* NLA_NESTED can't be empty */ },
112 [NL80211_ATTR_MESH_ID
] = { .type
= NLA_BINARY
,
113 .len
= IEEE80211_MAX_MESH_ID_LEN
},
114 [NL80211_ATTR_MPATH_NEXT_HOP
] = { .type
= NLA_U32
},
116 [NL80211_ATTR_REG_ALPHA2
] = { .type
= NLA_STRING
, .len
= 2 },
117 [NL80211_ATTR_REG_RULES
] = { .type
= NLA_NESTED
},
119 [NL80211_ATTR_BSS_CTS_PROT
] = { .type
= NLA_U8
},
120 [NL80211_ATTR_BSS_SHORT_PREAMBLE
] = { .type
= NLA_U8
},
121 [NL80211_ATTR_BSS_SHORT_SLOT_TIME
] = { .type
= NLA_U8
},
122 [NL80211_ATTR_BSS_BASIC_RATES
] = { .type
= NLA_BINARY
,
123 .len
= NL80211_MAX_SUPP_RATES
},
124 [NL80211_ATTR_BSS_HT_OPMODE
] = { .type
= NLA_U16
},
126 [NL80211_ATTR_MESH_CONFIG
] = { .type
= NLA_NESTED
},
127 [NL80211_ATTR_SUPPORT_MESH_AUTH
] = { .type
= NLA_FLAG
},
129 [NL80211_ATTR_HT_CAPABILITY
] = { .type
= NLA_BINARY
,
130 .len
= NL80211_HT_CAPABILITY_LEN
},
132 [NL80211_ATTR_MGMT_SUBTYPE
] = { .type
= NLA_U8
},
133 [NL80211_ATTR_IE
] = { .type
= NLA_BINARY
,
134 .len
= IEEE80211_MAX_DATA_LEN
},
135 [NL80211_ATTR_SCAN_FREQUENCIES
] = { .type
= NLA_NESTED
},
136 [NL80211_ATTR_SCAN_SSIDS
] = { .type
= NLA_NESTED
},
138 [NL80211_ATTR_SSID
] = { .type
= NLA_BINARY
,
139 .len
= IEEE80211_MAX_SSID_LEN
},
140 [NL80211_ATTR_AUTH_TYPE
] = { .type
= NLA_U32
},
141 [NL80211_ATTR_REASON_CODE
] = { .type
= NLA_U16
},
142 [NL80211_ATTR_FREQ_FIXED
] = { .type
= NLA_FLAG
},
143 [NL80211_ATTR_TIMED_OUT
] = { .type
= NLA_FLAG
},
144 [NL80211_ATTR_USE_MFP
] = { .type
= NLA_U32
},
145 [NL80211_ATTR_STA_FLAGS2
] = {
146 .len
= sizeof(struct nl80211_sta_flag_update
),
148 [NL80211_ATTR_CONTROL_PORT
] = { .type
= NLA_FLAG
},
149 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE
] = { .type
= NLA_U16
},
150 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
] = { .type
= NLA_FLAG
},
151 [NL80211_ATTR_PRIVACY
] = { .type
= NLA_FLAG
},
152 [NL80211_ATTR_CIPHER_SUITE_GROUP
] = { .type
= NLA_U32
},
153 [NL80211_ATTR_WPA_VERSIONS
] = { .type
= NLA_U32
},
154 [NL80211_ATTR_PID
] = { .type
= NLA_U32
},
155 [NL80211_ATTR_4ADDR
] = { .type
= NLA_U8
},
156 [NL80211_ATTR_PMKID
] = { .type
= NLA_BINARY
,
157 .len
= WLAN_PMKID_LEN
},
158 [NL80211_ATTR_DURATION
] = { .type
= NLA_U32
},
159 [NL80211_ATTR_COOKIE
] = { .type
= NLA_U64
},
160 [NL80211_ATTR_TX_RATES
] = { .type
= NLA_NESTED
},
161 [NL80211_ATTR_FRAME
] = { .type
= NLA_BINARY
,
162 .len
= IEEE80211_MAX_DATA_LEN
},
163 [NL80211_ATTR_FRAME_MATCH
] = { .type
= NLA_BINARY
, },
164 [NL80211_ATTR_PS_STATE
] = { .type
= NLA_U32
},
165 [NL80211_ATTR_CQM
] = { .type
= NLA_NESTED
, },
166 [NL80211_ATTR_LOCAL_STATE_CHANGE
] = { .type
= NLA_FLAG
},
167 [NL80211_ATTR_AP_ISOLATE
] = { .type
= NLA_U8
},
168 [NL80211_ATTR_WIPHY_TX_POWER_SETTING
] = { .type
= NLA_U32
},
169 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] = { .type
= NLA_U32
},
170 [NL80211_ATTR_FRAME_TYPE
] = { .type
= NLA_U16
},
171 [NL80211_ATTR_WIPHY_ANTENNA_TX
] = { .type
= NLA_U32
},
172 [NL80211_ATTR_WIPHY_ANTENNA_RX
] = { .type
= NLA_U32
},
173 [NL80211_ATTR_MCAST_RATE
] = { .type
= NLA_U32
},
174 [NL80211_ATTR_OFFCHANNEL_TX_OK
] = { .type
= NLA_FLAG
},
175 [NL80211_ATTR_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
178 /* policy for the key attributes */
179 static const struct nla_policy nl80211_key_policy
[NL80211_KEY_MAX
+ 1] = {
180 [NL80211_KEY_DATA
] = { .type
= NLA_BINARY
, .len
= WLAN_MAX_KEY_LEN
},
181 [NL80211_KEY_IDX
] = { .type
= NLA_U8
},
182 [NL80211_KEY_CIPHER
] = { .type
= NLA_U32
},
183 [NL80211_KEY_SEQ
] = { .type
= NLA_BINARY
, .len
= 8 },
184 [NL80211_KEY_DEFAULT
] = { .type
= NLA_FLAG
},
185 [NL80211_KEY_DEFAULT_MGMT
] = { .type
= NLA_FLAG
},
186 [NL80211_KEY_TYPE
] = { .type
= NLA_U32
},
187 [NL80211_KEY_DEFAULT_TYPES
] = { .type
= NLA_NESTED
},
190 /* policy for the key default flags */
191 static const struct nla_policy
192 nl80211_key_default_policy
[NUM_NL80211_KEY_DEFAULT_TYPES
] = {
193 [NL80211_KEY_DEFAULT_TYPE_UNICAST
] = { .type
= NLA_FLAG
},
194 [NL80211_KEY_DEFAULT_TYPE_MULTICAST
] = { .type
= NLA_FLAG
},
197 /* ifidx get helper */
198 static int nl80211_get_ifidx(struct netlink_callback
*cb
)
202 res
= nlmsg_parse(cb
->nlh
, GENL_HDRLEN
+ nl80211_fam
.hdrsize
,
203 nl80211_fam
.attrbuf
, nl80211_fam
.maxattr
,
208 if (!nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
])
211 res
= nla_get_u32(nl80211_fam
.attrbuf
[NL80211_ATTR_IFINDEX
]);
217 static int nl80211_prepare_netdev_dump(struct sk_buff
*skb
,
218 struct netlink_callback
*cb
,
219 struct cfg80211_registered_device
**rdev
,
220 struct net_device
**dev
)
222 int ifidx
= cb
->args
[0];
226 ifidx
= nl80211_get_ifidx(cb
);
234 *dev
= __dev_get_by_index(sock_net(skb
->sk
), ifidx
);
240 *rdev
= cfg80211_get_dev_from_ifindex(sock_net(skb
->sk
), ifidx
);
242 err
= PTR_ERR(*rdev
);
252 static void nl80211_finish_netdev_dump(struct cfg80211_registered_device
*rdev
)
254 cfg80211_unlock_rdev(rdev
);
259 static bool is_valid_ie_attr(const struct nlattr
*attr
)
267 pos
= nla_data(attr
);
288 /* message building helper */
289 static inline void *nl80211hdr_put(struct sk_buff
*skb
, u32 pid
, u32 seq
,
292 /* since there is no private header just add the generic one */
293 return genlmsg_put(skb
, pid
, seq
, &nl80211_fam
, flags
, cmd
);
296 static int nl80211_msg_put_channel(struct sk_buff
*msg
,
297 struct ieee80211_channel
*chan
)
299 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_FREQ
,
302 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
303 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_DISABLED
);
304 if (chan
->flags
& IEEE80211_CHAN_PASSIVE_SCAN
)
305 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN
);
306 if (chan
->flags
& IEEE80211_CHAN_NO_IBSS
)
307 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_NO_IBSS
);
308 if (chan
->flags
& IEEE80211_CHAN_RADAR
)
309 NLA_PUT_FLAG(msg
, NL80211_FREQUENCY_ATTR_RADAR
);
311 NLA_PUT_U32(msg
, NL80211_FREQUENCY_ATTR_MAX_TX_POWER
,
312 DBM_TO_MBM(chan
->max_power
));
320 /* netlink command implementations */
327 bool def_uni
, def_multi
;
330 static int nl80211_parse_key_new(struct nlattr
*key
, struct key_parse
*k
)
332 struct nlattr
*tb
[NL80211_KEY_MAX
+ 1];
333 int err
= nla_parse_nested(tb
, NL80211_KEY_MAX
, key
,
338 k
->def
= !!tb
[NL80211_KEY_DEFAULT
];
339 k
->defmgmt
= !!tb
[NL80211_KEY_DEFAULT_MGMT
];
348 if (tb
[NL80211_KEY_IDX
])
349 k
->idx
= nla_get_u8(tb
[NL80211_KEY_IDX
]);
351 if (tb
[NL80211_KEY_DATA
]) {
352 k
->p
.key
= nla_data(tb
[NL80211_KEY_DATA
]);
353 k
->p
.key_len
= nla_len(tb
[NL80211_KEY_DATA
]);
356 if (tb
[NL80211_KEY_SEQ
]) {
357 k
->p
.seq
= nla_data(tb
[NL80211_KEY_SEQ
]);
358 k
->p
.seq_len
= nla_len(tb
[NL80211_KEY_SEQ
]);
361 if (tb
[NL80211_KEY_CIPHER
])
362 k
->p
.cipher
= nla_get_u32(tb
[NL80211_KEY_CIPHER
]);
364 if (tb
[NL80211_KEY_TYPE
]) {
365 k
->type
= nla_get_u32(tb
[NL80211_KEY_TYPE
]);
366 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
370 if (tb
[NL80211_KEY_DEFAULT_TYPES
]) {
371 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
372 int err
= nla_parse_nested(kdt
,
373 NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
374 tb
[NL80211_KEY_DEFAULT_TYPES
],
375 nl80211_key_default_policy
);
379 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
380 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
386 static int nl80211_parse_key_old(struct genl_info
*info
, struct key_parse
*k
)
388 if (info
->attrs
[NL80211_ATTR_KEY_DATA
]) {
389 k
->p
.key
= nla_data(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
390 k
->p
.key_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_DATA
]);
393 if (info
->attrs
[NL80211_ATTR_KEY_SEQ
]) {
394 k
->p
.seq
= nla_data(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
395 k
->p
.seq_len
= nla_len(info
->attrs
[NL80211_ATTR_KEY_SEQ
]);
398 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
399 k
->idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
401 if (info
->attrs
[NL80211_ATTR_KEY_CIPHER
])
402 k
->p
.cipher
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_CIPHER
]);
404 k
->def
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT
];
405 k
->defmgmt
= !!info
->attrs
[NL80211_ATTR_KEY_DEFAULT_MGMT
];
414 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
415 k
->type
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
416 if (k
->type
< 0 || k
->type
>= NUM_NL80211_KEYTYPES
)
420 if (info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
]) {
421 struct nlattr
*kdt
[NUM_NL80211_KEY_DEFAULT_TYPES
];
422 int err
= nla_parse_nested(
423 kdt
, NUM_NL80211_KEY_DEFAULT_TYPES
- 1,
424 info
->attrs
[NL80211_ATTR_KEY_DEFAULT_TYPES
],
425 nl80211_key_default_policy
);
429 k
->def_uni
= kdt
[NL80211_KEY_DEFAULT_TYPE_UNICAST
];
430 k
->def_multi
= kdt
[NL80211_KEY_DEFAULT_TYPE_MULTICAST
];
436 static int nl80211_parse_key(struct genl_info
*info
, struct key_parse
*k
)
440 memset(k
, 0, sizeof(*k
));
444 if (info
->attrs
[NL80211_ATTR_KEY
])
445 err
= nl80211_parse_key_new(info
->attrs
[NL80211_ATTR_KEY
], k
);
447 err
= nl80211_parse_key_old(info
, k
);
452 if (k
->def
&& k
->defmgmt
)
456 if (k
->def_uni
|| !k
->def_multi
)
462 if (k
->idx
< 4 || k
->idx
> 5)
465 if (k
->idx
< 0 || k
->idx
> 3)
468 if (k
->idx
< 0 || k
->idx
> 5)
476 static struct cfg80211_cached_keys
*
477 nl80211_parse_connkeys(struct cfg80211_registered_device
*rdev
,
480 struct key_parse parse
;
482 struct cfg80211_cached_keys
*result
;
483 int rem
, err
, def
= 0;
485 result
= kzalloc(sizeof(*result
), GFP_KERNEL
);
487 return ERR_PTR(-ENOMEM
);
490 result
->defmgmt
= -1;
492 nla_for_each_nested(key
, keys
, rem
) {
493 memset(&parse
, 0, sizeof(parse
));
496 err
= nl80211_parse_key_new(key
, &parse
);
502 if (parse
.idx
< 0 || parse
.idx
> 4)
508 result
->def
= parse
.idx
;
509 if (!parse
.def_uni
|| !parse
.def_multi
)
511 } else if (parse
.defmgmt
)
513 err
= cfg80211_validate_key_settings(rdev
, &parse
.p
,
514 parse
.idx
, false, NULL
);
517 result
->params
[parse
.idx
].cipher
= parse
.p
.cipher
;
518 result
->params
[parse
.idx
].key_len
= parse
.p
.key_len
;
519 result
->params
[parse
.idx
].key
= result
->data
[parse
.idx
];
520 memcpy(result
->data
[parse
.idx
], parse
.p
.key
, parse
.p
.key_len
);
529 static int nl80211_key_allowed(struct wireless_dev
*wdev
)
531 ASSERT_WDEV_LOCK(wdev
);
533 switch (wdev
->iftype
) {
534 case NL80211_IFTYPE_AP
:
535 case NL80211_IFTYPE_AP_VLAN
:
536 case NL80211_IFTYPE_P2P_GO
:
538 case NL80211_IFTYPE_ADHOC
:
539 if (!wdev
->current_bss
)
542 case NL80211_IFTYPE_STATION
:
543 case NL80211_IFTYPE_P2P_CLIENT
:
544 if (wdev
->sme_state
!= CFG80211_SME_CONNECTED
)
554 static int nl80211_send_wiphy(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
555 struct cfg80211_registered_device
*dev
)
558 struct nlattr
*nl_bands
, *nl_band
;
559 struct nlattr
*nl_freqs
, *nl_freq
;
560 struct nlattr
*nl_rates
, *nl_rate
;
561 struct nlattr
*nl_modes
;
562 struct nlattr
*nl_cmds
;
563 enum ieee80211_band band
;
564 struct ieee80211_channel
*chan
;
565 struct ieee80211_rate
*rate
;
567 u16 ifmodes
= dev
->wiphy
.interface_modes
;
568 const struct ieee80211_txrx_stypes
*mgmt_stypes
=
569 dev
->wiphy
.mgmt_stypes
;
571 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_WIPHY
);
575 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, dev
->wiphy_idx
);
576 NLA_PUT_STRING(msg
, NL80211_ATTR_WIPHY_NAME
, wiphy_name(&dev
->wiphy
));
578 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
579 cfg80211_rdev_list_generation
);
581 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_SHORT
,
582 dev
->wiphy
.retry_short
);
583 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_RETRY_LONG
,
584 dev
->wiphy
.retry_long
);
585 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FRAG_THRESHOLD
,
586 dev
->wiphy
.frag_threshold
);
587 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_RTS_THRESHOLD
,
588 dev
->wiphy
.rts_threshold
);
589 NLA_PUT_U8(msg
, NL80211_ATTR_WIPHY_COVERAGE_CLASS
,
590 dev
->wiphy
.coverage_class
);
591 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_SCAN_SSIDS
,
592 dev
->wiphy
.max_scan_ssids
);
593 NLA_PUT_U16(msg
, NL80211_ATTR_MAX_SCAN_IE_LEN
,
594 dev
->wiphy
.max_scan_ie_len
);
596 if (dev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
)
597 NLA_PUT_FLAG(msg
, NL80211_ATTR_SUPPORT_IBSS_RSN
);
598 if (dev
->wiphy
.flags
& WIPHY_FLAG_MESH_AUTH
)
599 NLA_PUT_FLAG(msg
, NL80211_ATTR_SUPPORT_MESH_AUTH
);
601 NLA_PUT(msg
, NL80211_ATTR_CIPHER_SUITES
,
602 sizeof(u32
) * dev
->wiphy
.n_cipher_suites
,
603 dev
->wiphy
.cipher_suites
);
605 NLA_PUT_U8(msg
, NL80211_ATTR_MAX_NUM_PMKIDS
,
606 dev
->wiphy
.max_num_pmkids
);
608 if (dev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
)
609 NLA_PUT_FLAG(msg
, NL80211_ATTR_CONTROL_PORT_ETHERTYPE
);
611 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX
,
612 dev
->wiphy
.available_antennas_tx
);
613 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX
,
614 dev
->wiphy
.available_antennas_rx
);
616 if ((dev
->wiphy
.available_antennas_tx
||
617 dev
->wiphy
.available_antennas_rx
) && dev
->ops
->get_antenna
) {
618 u32 tx_ant
= 0, rx_ant
= 0;
620 res
= dev
->ops
->get_antenna(&dev
->wiphy
, &tx_ant
, &rx_ant
);
622 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_TX
, tx_ant
);
623 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_ANTENNA_RX
, rx_ant
);
627 nl_modes
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_IFTYPES
);
629 goto nla_put_failure
;
634 NLA_PUT_FLAG(msg
, i
);
639 nla_nest_end(msg
, nl_modes
);
641 nl_bands
= nla_nest_start(msg
, NL80211_ATTR_WIPHY_BANDS
);
643 goto nla_put_failure
;
645 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
646 if (!dev
->wiphy
.bands
[band
])
649 nl_band
= nla_nest_start(msg
, band
);
651 goto nla_put_failure
;
654 if (dev
->wiphy
.bands
[band
]->ht_cap
.ht_supported
) {
655 NLA_PUT(msg
, NL80211_BAND_ATTR_HT_MCS_SET
,
656 sizeof(dev
->wiphy
.bands
[band
]->ht_cap
.mcs
),
657 &dev
->wiphy
.bands
[band
]->ht_cap
.mcs
);
658 NLA_PUT_U16(msg
, NL80211_BAND_ATTR_HT_CAPA
,
659 dev
->wiphy
.bands
[band
]->ht_cap
.cap
);
660 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_FACTOR
,
661 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_factor
);
662 NLA_PUT_U8(msg
, NL80211_BAND_ATTR_HT_AMPDU_DENSITY
,
663 dev
->wiphy
.bands
[band
]->ht_cap
.ampdu_density
);
666 /* add frequencies */
667 nl_freqs
= nla_nest_start(msg
, NL80211_BAND_ATTR_FREQS
);
669 goto nla_put_failure
;
671 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_channels
; i
++) {
672 nl_freq
= nla_nest_start(msg
, i
);
674 goto nla_put_failure
;
676 chan
= &dev
->wiphy
.bands
[band
]->channels
[i
];
678 if (nl80211_msg_put_channel(msg
, chan
))
679 goto nla_put_failure
;
681 nla_nest_end(msg
, nl_freq
);
684 nla_nest_end(msg
, nl_freqs
);
687 nl_rates
= nla_nest_start(msg
, NL80211_BAND_ATTR_RATES
);
689 goto nla_put_failure
;
691 for (i
= 0; i
< dev
->wiphy
.bands
[band
]->n_bitrates
; i
++) {
692 nl_rate
= nla_nest_start(msg
, i
);
694 goto nla_put_failure
;
696 rate
= &dev
->wiphy
.bands
[band
]->bitrates
[i
];
697 NLA_PUT_U32(msg
, NL80211_BITRATE_ATTR_RATE
,
699 if (rate
->flags
& IEEE80211_RATE_SHORT_PREAMBLE
)
701 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE
);
703 nla_nest_end(msg
, nl_rate
);
706 nla_nest_end(msg
, nl_rates
);
708 nla_nest_end(msg
, nl_band
);
710 nla_nest_end(msg
, nl_bands
);
712 nl_cmds
= nla_nest_start(msg
, NL80211_ATTR_SUPPORTED_COMMANDS
);
714 goto nla_put_failure
;
719 if (dev->ops->op) { \
721 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
725 CMD(add_virtual_intf
, NEW_INTERFACE
);
726 CMD(change_virtual_intf
, SET_INTERFACE
);
727 CMD(add_key
, NEW_KEY
);
728 CMD(add_beacon
, NEW_BEACON
);
729 CMD(add_station
, NEW_STATION
);
730 CMD(add_mpath
, NEW_MPATH
);
731 CMD(update_mesh_config
, SET_MESH_CONFIG
);
732 CMD(change_bss
, SET_BSS
);
733 CMD(auth
, AUTHENTICATE
);
734 CMD(assoc
, ASSOCIATE
);
735 CMD(deauth
, DEAUTHENTICATE
);
736 CMD(disassoc
, DISASSOCIATE
);
737 CMD(join_ibss
, JOIN_IBSS
);
738 CMD(join_mesh
, JOIN_MESH
);
739 CMD(set_pmksa
, SET_PMKSA
);
740 CMD(del_pmksa
, DEL_PMKSA
);
741 CMD(flush_pmksa
, FLUSH_PMKSA
);
742 CMD(remain_on_channel
, REMAIN_ON_CHANNEL
);
743 CMD(set_bitrate_mask
, SET_TX_BITRATE_MASK
);
745 CMD(mgmt_tx_cancel_wait
, FRAME_WAIT_CANCEL
);
746 if (dev
->wiphy
.flags
& WIPHY_FLAG_NETNS_OK
) {
748 NLA_PUT_U32(msg
, i
, NL80211_CMD_SET_WIPHY_NETNS
);
750 CMD(set_channel
, SET_CHANNEL
);
751 CMD(set_wds_peer
, SET_WDS_PEER
);
755 if (dev
->ops
->connect
|| dev
->ops
->auth
) {
757 NLA_PUT_U32(msg
, i
, NL80211_CMD_CONNECT
);
760 if (dev
->ops
->disconnect
|| dev
->ops
->deauth
) {
762 NLA_PUT_U32(msg
, i
, NL80211_CMD_DISCONNECT
);
765 nla_nest_end(msg
, nl_cmds
);
767 if (dev
->ops
->remain_on_channel
)
768 NLA_PUT_U32(msg
, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION
,
769 dev
->wiphy
.max_remain_on_channel_duration
);
771 /* for now at least assume all drivers have it */
772 if (dev
->ops
->mgmt_tx
)
773 NLA_PUT_FLAG(msg
, NL80211_ATTR_OFFCHANNEL_TX_OK
);
777 struct nlattr
*nl_ftypes
, *nl_ifs
;
778 enum nl80211_iftype ift
;
780 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_TX_FRAME_TYPES
);
782 goto nla_put_failure
;
784 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
785 nl_ftypes
= nla_nest_start(msg
, ift
);
787 goto nla_put_failure
;
789 stypes
= mgmt_stypes
[ift
].tx
;
792 NLA_PUT_U16(msg
, NL80211_ATTR_FRAME_TYPE
,
793 (i
<< 4) | IEEE80211_FTYPE_MGMT
);
797 nla_nest_end(msg
, nl_ftypes
);
800 nla_nest_end(msg
, nl_ifs
);
802 nl_ifs
= nla_nest_start(msg
, NL80211_ATTR_RX_FRAME_TYPES
);
804 goto nla_put_failure
;
806 for (ift
= 0; ift
< NUM_NL80211_IFTYPES
; ift
++) {
807 nl_ftypes
= nla_nest_start(msg
, ift
);
809 goto nla_put_failure
;
811 stypes
= mgmt_stypes
[ift
].rx
;
814 NLA_PUT_U16(msg
, NL80211_ATTR_FRAME_TYPE
,
815 (i
<< 4) | IEEE80211_FTYPE_MGMT
);
819 nla_nest_end(msg
, nl_ftypes
);
821 nla_nest_end(msg
, nl_ifs
);
824 return genlmsg_end(msg
, hdr
);
827 genlmsg_cancel(msg
, hdr
);
831 static int nl80211_dump_wiphy(struct sk_buff
*skb
, struct netlink_callback
*cb
)
834 int start
= cb
->args
[0];
835 struct cfg80211_registered_device
*dev
;
837 mutex_lock(&cfg80211_mutex
);
838 list_for_each_entry(dev
, &cfg80211_rdev_list
, list
) {
839 if (!net_eq(wiphy_net(&dev
->wiphy
), sock_net(skb
->sk
)))
843 if (nl80211_send_wiphy(skb
, NETLINK_CB(cb
->skb
).pid
,
844 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
850 mutex_unlock(&cfg80211_mutex
);
857 static int nl80211_get_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
860 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
862 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
866 if (nl80211_send_wiphy(msg
, info
->snd_pid
, info
->snd_seq
, 0, dev
) < 0) {
871 return genlmsg_reply(msg
, info
);
874 static const struct nla_policy txq_params_policy
[NL80211_TXQ_ATTR_MAX
+ 1] = {
875 [NL80211_TXQ_ATTR_QUEUE
] = { .type
= NLA_U8
},
876 [NL80211_TXQ_ATTR_TXOP
] = { .type
= NLA_U16
},
877 [NL80211_TXQ_ATTR_CWMIN
] = { .type
= NLA_U16
},
878 [NL80211_TXQ_ATTR_CWMAX
] = { .type
= NLA_U16
},
879 [NL80211_TXQ_ATTR_AIFS
] = { .type
= NLA_U8
},
882 static int parse_txq_params(struct nlattr
*tb
[],
883 struct ieee80211_txq_params
*txq_params
)
885 if (!tb
[NL80211_TXQ_ATTR_QUEUE
] || !tb
[NL80211_TXQ_ATTR_TXOP
] ||
886 !tb
[NL80211_TXQ_ATTR_CWMIN
] || !tb
[NL80211_TXQ_ATTR_CWMAX
] ||
887 !tb
[NL80211_TXQ_ATTR_AIFS
])
890 txq_params
->queue
= nla_get_u8(tb
[NL80211_TXQ_ATTR_QUEUE
]);
891 txq_params
->txop
= nla_get_u16(tb
[NL80211_TXQ_ATTR_TXOP
]);
892 txq_params
->cwmin
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMIN
]);
893 txq_params
->cwmax
= nla_get_u16(tb
[NL80211_TXQ_ATTR_CWMAX
]);
894 txq_params
->aifs
= nla_get_u8(tb
[NL80211_TXQ_ATTR_AIFS
]);
899 static bool nl80211_can_set_dev_channel(struct wireless_dev
*wdev
)
902 * You can only set the channel explicitly for AP, mesh
903 * and WDS type interfaces; all others have their channel
904 * managed via their respective "establish a connection"
905 * command (connect, join, ...)
907 * Monitors are special as they are normally slaved to
908 * whatever else is going on, so they behave as though
909 * you tried setting the wiphy channel itself.
912 wdev
->iftype
== NL80211_IFTYPE_AP
||
913 wdev
->iftype
== NL80211_IFTYPE_WDS
||
914 wdev
->iftype
== NL80211_IFTYPE_MESH_POINT
||
915 wdev
->iftype
== NL80211_IFTYPE_MONITOR
||
916 wdev
->iftype
== NL80211_IFTYPE_P2P_GO
;
919 static int __nl80211_set_channel(struct cfg80211_registered_device
*rdev
,
920 struct wireless_dev
*wdev
,
921 struct genl_info
*info
)
923 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
927 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
930 if (!nl80211_can_set_dev_channel(wdev
))
933 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
934 channel_type
= nla_get_u32(info
->attrs
[
935 NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
936 if (channel_type
!= NL80211_CHAN_NO_HT
&&
937 channel_type
!= NL80211_CHAN_HT20
&&
938 channel_type
!= NL80211_CHAN_HT40PLUS
&&
939 channel_type
!= NL80211_CHAN_HT40MINUS
)
943 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
945 mutex_lock(&rdev
->devlist_mtx
);
948 result
= cfg80211_set_freq(rdev
, wdev
, freq
, channel_type
);
951 result
= cfg80211_set_freq(rdev
, NULL
, freq
, channel_type
);
953 mutex_unlock(&rdev
->devlist_mtx
);
958 static int nl80211_set_channel(struct sk_buff
*skb
, struct genl_info
*info
)
960 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
961 struct net_device
*netdev
= info
->user_ptr
[1];
963 return __nl80211_set_channel(rdev
, netdev
->ieee80211_ptr
, info
);
966 static int nl80211_set_wds_peer(struct sk_buff
*skb
, struct genl_info
*info
)
968 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
969 struct net_device
*dev
= info
->user_ptr
[1];
970 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
973 if (!info
->attrs
[NL80211_ATTR_MAC
])
976 if (netif_running(dev
))
979 if (!rdev
->ops
->set_wds_peer
)
982 if (wdev
->iftype
!= NL80211_IFTYPE_WDS
)
985 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
986 return rdev
->ops
->set_wds_peer(wdev
->wiphy
, dev
, bssid
);
990 static int nl80211_set_wiphy(struct sk_buff
*skb
, struct genl_info
*info
)
992 struct cfg80211_registered_device
*rdev
;
993 struct net_device
*netdev
= NULL
;
994 struct wireless_dev
*wdev
;
995 int result
= 0, rem_txq_params
= 0;
996 struct nlattr
*nl_txq_params
;
998 u8 retry_short
= 0, retry_long
= 0;
999 u32 frag_threshold
= 0, rts_threshold
= 0;
1000 u8 coverage_class
= 0;
1003 * Try to find the wiphy and netdev. Normally this
1004 * function shouldn't need the netdev, but this is
1005 * done for backward compatibility -- previously
1006 * setting the channel was done per wiphy, but now
1007 * it is per netdev. Previous userland like hostapd
1008 * also passed a netdev to set_wiphy, so that it is
1009 * possible to let that go to the right netdev!
1011 mutex_lock(&cfg80211_mutex
);
1013 if (info
->attrs
[NL80211_ATTR_IFINDEX
]) {
1014 int ifindex
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFINDEX
]);
1016 netdev
= dev_get_by_index(genl_info_net(info
), ifindex
);
1017 if (netdev
&& netdev
->ieee80211_ptr
) {
1018 rdev
= wiphy_to_dev(netdev
->ieee80211_ptr
->wiphy
);
1019 mutex_lock(&rdev
->mtx
);
1025 rdev
= __cfg80211_rdev_from_info(info
);
1027 mutex_unlock(&cfg80211_mutex
);
1028 return PTR_ERR(rdev
);
1034 mutex_lock(&rdev
->mtx
);
1035 } else if (netif_running(netdev
) &&
1036 nl80211_can_set_dev_channel(netdev
->ieee80211_ptr
))
1037 wdev
= netdev
->ieee80211_ptr
;
1042 * end workaround code, by now the rdev is available
1043 * and locked, and wdev may or may not be NULL.
1046 if (info
->attrs
[NL80211_ATTR_WIPHY_NAME
])
1047 result
= cfg80211_dev_rename(
1048 rdev
, nla_data(info
->attrs
[NL80211_ATTR_WIPHY_NAME
]));
1050 mutex_unlock(&cfg80211_mutex
);
1055 if (info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
]) {
1056 struct ieee80211_txq_params txq_params
;
1057 struct nlattr
*tb
[NL80211_TXQ_ATTR_MAX
+ 1];
1059 if (!rdev
->ops
->set_txq_params
) {
1060 result
= -EOPNOTSUPP
;
1064 nla_for_each_nested(nl_txq_params
,
1065 info
->attrs
[NL80211_ATTR_WIPHY_TXQ_PARAMS
],
1067 nla_parse(tb
, NL80211_TXQ_ATTR_MAX
,
1068 nla_data(nl_txq_params
),
1069 nla_len(nl_txq_params
),
1071 result
= parse_txq_params(tb
, &txq_params
);
1075 result
= rdev
->ops
->set_txq_params(&rdev
->wiphy
,
1082 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
1083 result
= __nl80211_set_channel(rdev
, wdev
, info
);
1088 if (info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_SETTING
]) {
1089 enum nl80211_tx_power_setting type
;
1092 if (!rdev
->ops
->set_tx_power
) {
1093 result
= -EOPNOTSUPP
;
1097 idx
= NL80211_ATTR_WIPHY_TX_POWER_SETTING
;
1098 type
= nla_get_u32(info
->attrs
[idx
]);
1100 if (!info
->attrs
[NL80211_ATTR_WIPHY_TX_POWER_LEVEL
] &&
1101 (type
!= NL80211_TX_POWER_AUTOMATIC
)) {
1106 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
1107 idx
= NL80211_ATTR_WIPHY_TX_POWER_LEVEL
;
1108 mbm
= nla_get_u32(info
->attrs
[idx
]);
1111 result
= rdev
->ops
->set_tx_power(&rdev
->wiphy
, type
, mbm
);
1116 if (info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
] &&
1117 info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]) {
1119 if ((!rdev
->wiphy
.available_antennas_tx
&&
1120 !rdev
->wiphy
.available_antennas_rx
) ||
1121 !rdev
->ops
->set_antenna
) {
1122 result
= -EOPNOTSUPP
;
1126 tx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_TX
]);
1127 rx_ant
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_ANTENNA_RX
]);
1129 /* reject antenna configurations which don't match the
1130 * available antenna masks, except for the "all" mask */
1131 if ((~tx_ant
&& (tx_ant
& ~rdev
->wiphy
.available_antennas_tx
)) ||
1132 (~rx_ant
&& (rx_ant
& ~rdev
->wiphy
.available_antennas_rx
))) {
1137 tx_ant
= tx_ant
& rdev
->wiphy
.available_antennas_tx
;
1138 rx_ant
= rx_ant
& rdev
->wiphy
.available_antennas_rx
;
1140 result
= rdev
->ops
->set_antenna(&rdev
->wiphy
, tx_ant
, rx_ant
);
1147 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]) {
1148 retry_short
= nla_get_u8(
1149 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_SHORT
]);
1150 if (retry_short
== 0) {
1154 changed
|= WIPHY_PARAM_RETRY_SHORT
;
1157 if (info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]) {
1158 retry_long
= nla_get_u8(
1159 info
->attrs
[NL80211_ATTR_WIPHY_RETRY_LONG
]);
1160 if (retry_long
== 0) {
1164 changed
|= WIPHY_PARAM_RETRY_LONG
;
1167 if (info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]) {
1168 frag_threshold
= nla_get_u32(
1169 info
->attrs
[NL80211_ATTR_WIPHY_FRAG_THRESHOLD
]);
1170 if (frag_threshold
< 256) {
1174 if (frag_threshold
!= (u32
) -1) {
1176 * Fragments (apart from the last one) are required to
1177 * have even length. Make the fragmentation code
1178 * simpler by stripping LSB should someone try to use
1179 * odd threshold value.
1181 frag_threshold
&= ~0x1;
1183 changed
|= WIPHY_PARAM_FRAG_THRESHOLD
;
1186 if (info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]) {
1187 rts_threshold
= nla_get_u32(
1188 info
->attrs
[NL80211_ATTR_WIPHY_RTS_THRESHOLD
]);
1189 changed
|= WIPHY_PARAM_RTS_THRESHOLD
;
1192 if (info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]) {
1193 coverage_class
= nla_get_u8(
1194 info
->attrs
[NL80211_ATTR_WIPHY_COVERAGE_CLASS
]);
1195 changed
|= WIPHY_PARAM_COVERAGE_CLASS
;
1199 u8 old_retry_short
, old_retry_long
;
1200 u32 old_frag_threshold
, old_rts_threshold
;
1201 u8 old_coverage_class
;
1203 if (!rdev
->ops
->set_wiphy_params
) {
1204 result
= -EOPNOTSUPP
;
1208 old_retry_short
= rdev
->wiphy
.retry_short
;
1209 old_retry_long
= rdev
->wiphy
.retry_long
;
1210 old_frag_threshold
= rdev
->wiphy
.frag_threshold
;
1211 old_rts_threshold
= rdev
->wiphy
.rts_threshold
;
1212 old_coverage_class
= rdev
->wiphy
.coverage_class
;
1214 if (changed
& WIPHY_PARAM_RETRY_SHORT
)
1215 rdev
->wiphy
.retry_short
= retry_short
;
1216 if (changed
& WIPHY_PARAM_RETRY_LONG
)
1217 rdev
->wiphy
.retry_long
= retry_long
;
1218 if (changed
& WIPHY_PARAM_FRAG_THRESHOLD
)
1219 rdev
->wiphy
.frag_threshold
= frag_threshold
;
1220 if (changed
& WIPHY_PARAM_RTS_THRESHOLD
)
1221 rdev
->wiphy
.rts_threshold
= rts_threshold
;
1222 if (changed
& WIPHY_PARAM_COVERAGE_CLASS
)
1223 rdev
->wiphy
.coverage_class
= coverage_class
;
1225 result
= rdev
->ops
->set_wiphy_params(&rdev
->wiphy
, changed
);
1227 rdev
->wiphy
.retry_short
= old_retry_short
;
1228 rdev
->wiphy
.retry_long
= old_retry_long
;
1229 rdev
->wiphy
.frag_threshold
= old_frag_threshold
;
1230 rdev
->wiphy
.rts_threshold
= old_rts_threshold
;
1231 rdev
->wiphy
.coverage_class
= old_coverage_class
;
1236 mutex_unlock(&rdev
->mtx
);
1243 static int nl80211_send_iface(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
1244 struct cfg80211_registered_device
*rdev
,
1245 struct net_device
*dev
)
1249 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_INTERFACE
);
1253 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1254 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
1255 NLA_PUT_STRING(msg
, NL80211_ATTR_IFNAME
, dev
->name
);
1256 NLA_PUT_U32(msg
, NL80211_ATTR_IFTYPE
, dev
->ieee80211_ptr
->iftype
);
1258 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
,
1259 rdev
->devlist_generation
^
1260 (cfg80211_rdev_list_generation
<< 2));
1262 return genlmsg_end(msg
, hdr
);
1265 genlmsg_cancel(msg
, hdr
);
1269 static int nl80211_dump_interface(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1273 int wp_start
= cb
->args
[0];
1274 int if_start
= cb
->args
[1];
1275 struct cfg80211_registered_device
*rdev
;
1276 struct wireless_dev
*wdev
;
1278 mutex_lock(&cfg80211_mutex
);
1279 list_for_each_entry(rdev
, &cfg80211_rdev_list
, list
) {
1280 if (!net_eq(wiphy_net(&rdev
->wiphy
), sock_net(skb
->sk
)))
1282 if (wp_idx
< wp_start
) {
1288 mutex_lock(&rdev
->devlist_mtx
);
1289 list_for_each_entry(wdev
, &rdev
->netdev_list
, list
) {
1290 if (if_idx
< if_start
) {
1294 if (nl80211_send_iface(skb
, NETLINK_CB(cb
->skb
).pid
,
1295 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
1296 rdev
, wdev
->netdev
) < 0) {
1297 mutex_unlock(&rdev
->devlist_mtx
);
1302 mutex_unlock(&rdev
->devlist_mtx
);
1307 mutex_unlock(&cfg80211_mutex
);
1309 cb
->args
[0] = wp_idx
;
1310 cb
->args
[1] = if_idx
;
1315 static int nl80211_get_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1317 struct sk_buff
*msg
;
1318 struct cfg80211_registered_device
*dev
= info
->user_ptr
[0];
1319 struct net_device
*netdev
= info
->user_ptr
[1];
1321 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1325 if (nl80211_send_iface(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1331 return genlmsg_reply(msg
, info
);
1334 static const struct nla_policy mntr_flags_policy
[NL80211_MNTR_FLAG_MAX
+ 1] = {
1335 [NL80211_MNTR_FLAG_FCSFAIL
] = { .type
= NLA_FLAG
},
1336 [NL80211_MNTR_FLAG_PLCPFAIL
] = { .type
= NLA_FLAG
},
1337 [NL80211_MNTR_FLAG_CONTROL
] = { .type
= NLA_FLAG
},
1338 [NL80211_MNTR_FLAG_OTHER_BSS
] = { .type
= NLA_FLAG
},
1339 [NL80211_MNTR_FLAG_COOK_FRAMES
] = { .type
= NLA_FLAG
},
1342 static int parse_monitor_flags(struct nlattr
*nla
, u32
*mntrflags
)
1344 struct nlattr
*flags
[NL80211_MNTR_FLAG_MAX
+ 1];
1352 if (nla_parse_nested(flags
, NL80211_MNTR_FLAG_MAX
,
1353 nla
, mntr_flags_policy
))
1356 for (flag
= 1; flag
<= NL80211_MNTR_FLAG_MAX
; flag
++)
1358 *mntrflags
|= (1<<flag
);
1363 static int nl80211_valid_4addr(struct cfg80211_registered_device
*rdev
,
1364 struct net_device
*netdev
, u8 use_4addr
,
1365 enum nl80211_iftype iftype
)
1368 if (netdev
&& (netdev
->priv_flags
& IFF_BRIDGE_PORT
))
1374 case NL80211_IFTYPE_AP_VLAN
:
1375 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_AP
)
1378 case NL80211_IFTYPE_STATION
:
1379 if (rdev
->wiphy
.flags
& WIPHY_FLAG_4ADDR_STATION
)
1389 static int nl80211_set_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1391 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1392 struct vif_params params
;
1394 enum nl80211_iftype otype
, ntype
;
1395 struct net_device
*dev
= info
->user_ptr
[1];
1396 u32 _flags
, *flags
= NULL
;
1397 bool change
= false;
1399 memset(¶ms
, 0, sizeof(params
));
1401 otype
= ntype
= dev
->ieee80211_ptr
->iftype
;
1403 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1404 ntype
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1407 if (ntype
> NL80211_IFTYPE_MAX
)
1411 if (info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1412 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1414 if (ntype
!= NL80211_IFTYPE_MESH_POINT
)
1416 if (netif_running(dev
))
1420 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
1421 IEEE80211_MAX_MESH_ID_LEN
);
1422 wdev
->mesh_id_up_len
=
1423 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1424 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
1425 wdev
->mesh_id_up_len
);
1429 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1430 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1432 err
= nl80211_valid_4addr(rdev
, dev
, params
.use_4addr
, ntype
);
1436 params
.use_4addr
= -1;
1439 if (info
->attrs
[NL80211_ATTR_MNTR_FLAGS
]) {
1440 if (ntype
!= NL80211_IFTYPE_MONITOR
)
1442 err
= parse_monitor_flags(info
->attrs
[NL80211_ATTR_MNTR_FLAGS
],
1452 err
= cfg80211_change_iface(rdev
, dev
, ntype
, flags
, ¶ms
);
1456 if (!err
&& params
.use_4addr
!= -1)
1457 dev
->ieee80211_ptr
->use_4addr
= params
.use_4addr
;
1462 static int nl80211_new_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1464 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1465 struct vif_params params
;
1466 struct net_device
*dev
;
1468 enum nl80211_iftype type
= NL80211_IFTYPE_UNSPECIFIED
;
1471 memset(¶ms
, 0, sizeof(params
));
1473 if (!info
->attrs
[NL80211_ATTR_IFNAME
])
1476 if (info
->attrs
[NL80211_ATTR_IFTYPE
]) {
1477 type
= nla_get_u32(info
->attrs
[NL80211_ATTR_IFTYPE
]);
1478 if (type
> NL80211_IFTYPE_MAX
)
1482 if (!rdev
->ops
->add_virtual_intf
||
1483 !(rdev
->wiphy
.interface_modes
& (1 << type
)))
1486 if (info
->attrs
[NL80211_ATTR_4ADDR
]) {
1487 params
.use_4addr
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_4ADDR
]);
1488 err
= nl80211_valid_4addr(rdev
, NULL
, params
.use_4addr
, type
);
1493 err
= parse_monitor_flags(type
== NL80211_IFTYPE_MONITOR
?
1494 info
->attrs
[NL80211_ATTR_MNTR_FLAGS
] : NULL
,
1496 dev
= rdev
->ops
->add_virtual_intf(&rdev
->wiphy
,
1497 nla_data(info
->attrs
[NL80211_ATTR_IFNAME
]),
1498 type
, err
? NULL
: &flags
, ¶ms
);
1500 return PTR_ERR(dev
);
1502 if (type
== NL80211_IFTYPE_MESH_POINT
&&
1503 info
->attrs
[NL80211_ATTR_MESH_ID
]) {
1504 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
1507 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN
!=
1508 IEEE80211_MAX_MESH_ID_LEN
);
1509 wdev
->mesh_id_up_len
=
1510 nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
1511 memcpy(wdev
->ssid
, nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]),
1512 wdev
->mesh_id_up_len
);
1519 static int nl80211_del_interface(struct sk_buff
*skb
, struct genl_info
*info
)
1521 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1522 struct net_device
*dev
= info
->user_ptr
[1];
1524 if (!rdev
->ops
->del_virtual_intf
)
1527 return rdev
->ops
->del_virtual_intf(&rdev
->wiphy
, dev
);
1530 struct get_key_cookie
{
1531 struct sk_buff
*msg
;
1536 static void get_key_callback(void *c
, struct key_params
*params
)
1539 struct get_key_cookie
*cookie
= c
;
1542 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_DATA
,
1543 params
->key_len
, params
->key
);
1546 NLA_PUT(cookie
->msg
, NL80211_ATTR_KEY_SEQ
,
1547 params
->seq_len
, params
->seq
);
1550 NLA_PUT_U32(cookie
->msg
, NL80211_ATTR_KEY_CIPHER
,
1553 key
= nla_nest_start(cookie
->msg
, NL80211_ATTR_KEY
);
1555 goto nla_put_failure
;
1558 NLA_PUT(cookie
->msg
, NL80211_KEY_DATA
,
1559 params
->key_len
, params
->key
);
1562 NLA_PUT(cookie
->msg
, NL80211_KEY_SEQ
,
1563 params
->seq_len
, params
->seq
);
1566 NLA_PUT_U32(cookie
->msg
, NL80211_KEY_CIPHER
,
1569 NLA_PUT_U8(cookie
->msg
, NL80211_ATTR_KEY_IDX
, cookie
->idx
);
1571 nla_nest_end(cookie
->msg
, key
);
1578 static int nl80211_get_key(struct sk_buff
*skb
, struct genl_info
*info
)
1580 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1582 struct net_device
*dev
= info
->user_ptr
[1];
1584 const u8
*mac_addr
= NULL
;
1586 struct get_key_cookie cookie
= {
1590 struct sk_buff
*msg
;
1592 if (info
->attrs
[NL80211_ATTR_KEY_IDX
])
1593 key_idx
= nla_get_u8(info
->attrs
[NL80211_ATTR_KEY_IDX
]);
1598 if (info
->attrs
[NL80211_ATTR_MAC
])
1599 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1601 pairwise
= !!mac_addr
;
1602 if (info
->attrs
[NL80211_ATTR_KEY_TYPE
]) {
1603 u32 kt
= nla_get_u32(info
->attrs
[NL80211_ATTR_KEY_TYPE
]);
1604 if (kt
>= NUM_NL80211_KEYTYPES
)
1606 if (kt
!= NL80211_KEYTYPE_GROUP
&&
1607 kt
!= NL80211_KEYTYPE_PAIRWISE
)
1609 pairwise
= kt
== NL80211_KEYTYPE_PAIRWISE
;
1612 if (!rdev
->ops
->get_key
)
1615 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
1619 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
1620 NL80211_CMD_NEW_KEY
);
1622 return PTR_ERR(hdr
);
1625 cookie
.idx
= key_idx
;
1627 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
1628 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_idx
);
1630 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
1632 if (pairwise
&& mac_addr
&&
1633 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
1636 err
= rdev
->ops
->get_key(&rdev
->wiphy
, dev
, key_idx
, pairwise
,
1637 mac_addr
, &cookie
, get_key_callback
);
1643 goto nla_put_failure
;
1645 genlmsg_end(msg
, hdr
);
1646 return genlmsg_reply(msg
, info
);
1655 static int nl80211_set_key(struct sk_buff
*skb
, struct genl_info
*info
)
1657 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1658 struct key_parse key
;
1660 struct net_device
*dev
= info
->user_ptr
[1];
1662 err
= nl80211_parse_key(info
, &key
);
1669 /* only support setting default key */
1670 if (!key
.def
&& !key
.defmgmt
)
1673 wdev_lock(dev
->ieee80211_ptr
);
1676 if (!rdev
->ops
->set_default_key
) {
1681 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1685 if (!(rdev
->wiphy
.flags
&
1686 WIPHY_FLAG_SUPPORTS_SEPARATE_DEFAULT_KEYS
)) {
1687 if (!key
.def_uni
|| !key
.def_multi
) {
1693 err
= rdev
->ops
->set_default_key(&rdev
->wiphy
, dev
, key
.idx
,
1694 key
.def_uni
, key
.def_multi
);
1699 #ifdef CONFIG_CFG80211_WEXT
1700 dev
->ieee80211_ptr
->wext
.default_key
= key
.idx
;
1703 if (key
.def_uni
|| !key
.def_multi
) {
1708 if (!rdev
->ops
->set_default_mgmt_key
) {
1713 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1717 err
= rdev
->ops
->set_default_mgmt_key(&rdev
->wiphy
,
1722 #ifdef CONFIG_CFG80211_WEXT
1723 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= key
.idx
;
1728 wdev_unlock(dev
->ieee80211_ptr
);
1733 static int nl80211_new_key(struct sk_buff
*skb
, struct genl_info
*info
)
1735 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1737 struct net_device
*dev
= info
->user_ptr
[1];
1738 struct key_parse key
;
1739 const u8
*mac_addr
= NULL
;
1741 err
= nl80211_parse_key(info
, &key
);
1748 if (info
->attrs
[NL80211_ATTR_MAC
])
1749 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1751 if (key
.type
== -1) {
1753 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
1755 key
.type
= NL80211_KEYTYPE_GROUP
;
1759 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
1760 key
.type
!= NL80211_KEYTYPE_GROUP
)
1763 if (!rdev
->ops
->add_key
)
1766 if (cfg80211_validate_key_settings(rdev
, &key
.p
, key
.idx
,
1767 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
1771 wdev_lock(dev
->ieee80211_ptr
);
1772 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1774 err
= rdev
->ops
->add_key(&rdev
->wiphy
, dev
, key
.idx
,
1775 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
1777 wdev_unlock(dev
->ieee80211_ptr
);
1782 static int nl80211_del_key(struct sk_buff
*skb
, struct genl_info
*info
)
1784 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1786 struct net_device
*dev
= info
->user_ptr
[1];
1787 u8
*mac_addr
= NULL
;
1788 struct key_parse key
;
1790 err
= nl80211_parse_key(info
, &key
);
1794 if (info
->attrs
[NL80211_ATTR_MAC
])
1795 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
1797 if (key
.type
== -1) {
1799 key
.type
= NL80211_KEYTYPE_PAIRWISE
;
1801 key
.type
= NL80211_KEYTYPE_GROUP
;
1805 if (key
.type
!= NL80211_KEYTYPE_PAIRWISE
&&
1806 key
.type
!= NL80211_KEYTYPE_GROUP
)
1809 if (!rdev
->ops
->del_key
)
1812 wdev_lock(dev
->ieee80211_ptr
);
1813 err
= nl80211_key_allowed(dev
->ieee80211_ptr
);
1815 if (key
.type
== NL80211_KEYTYPE_PAIRWISE
&& mac_addr
&&
1816 !(rdev
->wiphy
.flags
& WIPHY_FLAG_IBSS_RSN
))
1820 err
= rdev
->ops
->del_key(&rdev
->wiphy
, dev
, key
.idx
,
1821 key
.type
== NL80211_KEYTYPE_PAIRWISE
,
1824 #ifdef CONFIG_CFG80211_WEXT
1826 if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_key
)
1827 dev
->ieee80211_ptr
->wext
.default_key
= -1;
1828 else if (key
.idx
== dev
->ieee80211_ptr
->wext
.default_mgmt_key
)
1829 dev
->ieee80211_ptr
->wext
.default_mgmt_key
= -1;
1832 wdev_unlock(dev
->ieee80211_ptr
);
1837 static int nl80211_addset_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1839 int (*call
)(struct wiphy
*wiphy
, struct net_device
*dev
,
1840 struct beacon_parameters
*info
);
1841 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1842 struct net_device
*dev
= info
->user_ptr
[1];
1843 struct beacon_parameters params
;
1846 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]))
1849 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1850 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
1853 switch (info
->genlhdr
->cmd
) {
1854 case NL80211_CMD_NEW_BEACON
:
1855 /* these are required for NEW_BEACON */
1856 if (!info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
] ||
1857 !info
->attrs
[NL80211_ATTR_DTIM_PERIOD
] ||
1858 !info
->attrs
[NL80211_ATTR_BEACON_HEAD
])
1861 call
= rdev
->ops
->add_beacon
;
1863 case NL80211_CMD_SET_BEACON
:
1864 call
= rdev
->ops
->set_beacon
;
1874 memset(¶ms
, 0, sizeof(params
));
1876 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
1878 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
1882 if (info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]) {
1883 params
.dtim_period
=
1884 nla_get_u32(info
->attrs
[NL80211_ATTR_DTIM_PERIOD
]);
1888 if (info
->attrs
[NL80211_ATTR_BEACON_HEAD
]) {
1889 params
.head
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1891 nla_len(info
->attrs
[NL80211_ATTR_BEACON_HEAD
]);
1895 if (info
->attrs
[NL80211_ATTR_BEACON_TAIL
]) {
1896 params
.tail
= nla_data(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1898 nla_len(info
->attrs
[NL80211_ATTR_BEACON_TAIL
]);
1905 return call(&rdev
->wiphy
, dev
, ¶ms
);
1908 static int nl80211_del_beacon(struct sk_buff
*skb
, struct genl_info
*info
)
1910 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
1911 struct net_device
*dev
= info
->user_ptr
[1];
1913 if (!rdev
->ops
->del_beacon
)
1916 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
1917 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
1920 return rdev
->ops
->del_beacon(&rdev
->wiphy
, dev
);
1923 static const struct nla_policy sta_flags_policy
[NL80211_STA_FLAG_MAX
+ 1] = {
1924 [NL80211_STA_FLAG_AUTHORIZED
] = { .type
= NLA_FLAG
},
1925 [NL80211_STA_FLAG_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
1926 [NL80211_STA_FLAG_WME
] = { .type
= NLA_FLAG
},
1927 [NL80211_STA_FLAG_MFP
] = { .type
= NLA_FLAG
},
1928 [NL80211_STA_FLAG_AUTHENTICATED
] = { .type
= NLA_FLAG
},
1931 static int parse_station_flags(struct genl_info
*info
,
1932 struct station_parameters
*params
)
1934 struct nlattr
*flags
[NL80211_STA_FLAG_MAX
+ 1];
1939 * Try parsing the new attribute first so userspace
1940 * can specify both for older kernels.
1942 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS2
];
1944 struct nl80211_sta_flag_update
*sta_flags
;
1946 sta_flags
= nla_data(nla
);
1947 params
->sta_flags_mask
= sta_flags
->mask
;
1948 params
->sta_flags_set
= sta_flags
->set
;
1949 if ((params
->sta_flags_mask
|
1950 params
->sta_flags_set
) & BIT(__NL80211_STA_FLAG_INVALID
))
1955 /* if present, parse the old attribute */
1957 nla
= info
->attrs
[NL80211_ATTR_STA_FLAGS
];
1961 if (nla_parse_nested(flags
, NL80211_STA_FLAG_MAX
,
1962 nla
, sta_flags_policy
))
1965 params
->sta_flags_mask
= (1 << __NL80211_STA_FLAG_AFTER_LAST
) - 1;
1966 params
->sta_flags_mask
&= ~1;
1968 for (flag
= 1; flag
<= NL80211_STA_FLAG_MAX
; flag
++)
1970 params
->sta_flags_set
|= (1<<flag
);
1975 static bool nl80211_put_sta_rate(struct sk_buff
*msg
, struct rate_info
*info
,
1978 struct nlattr
*rate
;
1981 rate
= nla_nest_start(msg
, attr
);
1983 goto nla_put_failure
;
1985 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
1986 bitrate
= cfg80211_calculate_bitrate(info
);
1988 NLA_PUT_U16(msg
, NL80211_RATE_INFO_BITRATE
, bitrate
);
1990 if (info
->flags
& RATE_INFO_FLAGS_MCS
)
1991 NLA_PUT_U8(msg
, NL80211_RATE_INFO_MCS
, info
->mcs
);
1992 if (info
->flags
& RATE_INFO_FLAGS_40_MHZ_WIDTH
)
1993 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_40_MHZ_WIDTH
);
1994 if (info
->flags
& RATE_INFO_FLAGS_SHORT_GI
)
1995 NLA_PUT_FLAG(msg
, NL80211_RATE_INFO_SHORT_GI
);
1997 nla_nest_end(msg
, rate
);
2004 static int nl80211_send_station(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2005 int flags
, struct net_device
*dev
,
2006 const u8
*mac_addr
, struct station_info
*sinfo
)
2009 struct nlattr
*sinfoattr
, *bss_param
;
2011 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2015 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2016 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
2018 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, sinfo
->generation
);
2020 sinfoattr
= nla_nest_start(msg
, NL80211_ATTR_STA_INFO
);
2022 goto nla_put_failure
;
2023 if (sinfo
->filled
& STATION_INFO_CONNECTED_TIME
)
2024 NLA_PUT_U32(msg
, NL80211_STA_INFO_CONNECTED_TIME
,
2025 sinfo
->connected_time
);
2026 if (sinfo
->filled
& STATION_INFO_INACTIVE_TIME
)
2027 NLA_PUT_U32(msg
, NL80211_STA_INFO_INACTIVE_TIME
,
2028 sinfo
->inactive_time
);
2029 if (sinfo
->filled
& STATION_INFO_RX_BYTES
)
2030 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_BYTES
,
2032 if (sinfo
->filled
& STATION_INFO_TX_BYTES
)
2033 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_BYTES
,
2035 if (sinfo
->filled
& STATION_INFO_LLID
)
2036 NLA_PUT_U16(msg
, NL80211_STA_INFO_LLID
,
2038 if (sinfo
->filled
& STATION_INFO_PLID
)
2039 NLA_PUT_U16(msg
, NL80211_STA_INFO_PLID
,
2041 if (sinfo
->filled
& STATION_INFO_PLINK_STATE
)
2042 NLA_PUT_U8(msg
, NL80211_STA_INFO_PLINK_STATE
,
2043 sinfo
->plink_state
);
2044 if (sinfo
->filled
& STATION_INFO_SIGNAL
)
2045 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL
,
2047 if (sinfo
->filled
& STATION_INFO_SIGNAL_AVG
)
2048 NLA_PUT_U8(msg
, NL80211_STA_INFO_SIGNAL_AVG
,
2050 if (sinfo
->filled
& STATION_INFO_TX_BITRATE
) {
2051 if (!nl80211_put_sta_rate(msg
, &sinfo
->txrate
,
2052 NL80211_STA_INFO_TX_BITRATE
))
2053 goto nla_put_failure
;
2055 if (sinfo
->filled
& STATION_INFO_RX_BITRATE
) {
2056 if (!nl80211_put_sta_rate(msg
, &sinfo
->rxrate
,
2057 NL80211_STA_INFO_RX_BITRATE
))
2058 goto nla_put_failure
;
2060 if (sinfo
->filled
& STATION_INFO_RX_PACKETS
)
2061 NLA_PUT_U32(msg
, NL80211_STA_INFO_RX_PACKETS
,
2063 if (sinfo
->filled
& STATION_INFO_TX_PACKETS
)
2064 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_PACKETS
,
2066 if (sinfo
->filled
& STATION_INFO_TX_RETRIES
)
2067 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_RETRIES
,
2069 if (sinfo
->filled
& STATION_INFO_TX_FAILED
)
2070 NLA_PUT_U32(msg
, NL80211_STA_INFO_TX_FAILED
,
2072 if (sinfo
->filled
& STATION_INFO_BSS_PARAM
) {
2073 bss_param
= nla_nest_start(msg
, NL80211_STA_INFO_BSS_PARAM
);
2075 goto nla_put_failure
;
2077 if (sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_CTS_PROT
)
2078 NLA_PUT_FLAG(msg
, NL80211_STA_BSS_PARAM_CTS_PROT
);
2079 if (sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_PREAMBLE
)
2080 NLA_PUT_FLAG(msg
, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
);
2081 if (sinfo
->bss_param
.flags
& BSS_PARAM_FLAGS_SHORT_SLOT_TIME
)
2083 NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
);
2084 NLA_PUT_U8(msg
, NL80211_STA_BSS_PARAM_DTIM_PERIOD
,
2085 sinfo
->bss_param
.dtim_period
);
2086 NLA_PUT_U16(msg
, NL80211_STA_BSS_PARAM_BEACON_INTERVAL
,
2087 sinfo
->bss_param
.beacon_interval
);
2089 nla_nest_end(msg
, bss_param
);
2091 nla_nest_end(msg
, sinfoattr
);
2093 return genlmsg_end(msg
, hdr
);
2096 genlmsg_cancel(msg
, hdr
);
2100 static int nl80211_dump_station(struct sk_buff
*skb
,
2101 struct netlink_callback
*cb
)
2103 struct station_info sinfo
;
2104 struct cfg80211_registered_device
*dev
;
2105 struct net_device
*netdev
;
2106 u8 mac_addr
[ETH_ALEN
];
2107 int sta_idx
= cb
->args
[1];
2110 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
2114 if (!dev
->ops
->dump_station
) {
2120 err
= dev
->ops
->dump_station(&dev
->wiphy
, netdev
, sta_idx
,
2127 if (nl80211_send_station(skb
,
2128 NETLINK_CB(cb
->skb
).pid
,
2129 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2139 cb
->args
[1] = sta_idx
;
2142 nl80211_finish_netdev_dump(dev
);
2147 static int nl80211_get_station(struct sk_buff
*skb
, struct genl_info
*info
)
2149 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2150 struct net_device
*dev
= info
->user_ptr
[1];
2151 struct station_info sinfo
;
2152 struct sk_buff
*msg
;
2153 u8
*mac_addr
= NULL
;
2156 memset(&sinfo
, 0, sizeof(sinfo
));
2158 if (!info
->attrs
[NL80211_ATTR_MAC
])
2161 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2163 if (!rdev
->ops
->get_station
)
2166 err
= rdev
->ops
->get_station(&rdev
->wiphy
, dev
, mac_addr
, &sinfo
);
2170 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2174 if (nl80211_send_station(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2175 dev
, mac_addr
, &sinfo
) < 0) {
2180 return genlmsg_reply(msg
, info
);
2184 * Get vlan interface making sure it is running and on the right wiphy.
2186 static int get_vlan(struct genl_info
*info
,
2187 struct cfg80211_registered_device
*rdev
,
2188 struct net_device
**vlan
)
2190 struct nlattr
*vlanattr
= info
->attrs
[NL80211_ATTR_STA_VLAN
];
2194 *vlan
= dev_get_by_index(genl_info_net(info
),
2195 nla_get_u32(vlanattr
));
2198 if (!(*vlan
)->ieee80211_ptr
)
2200 if ((*vlan
)->ieee80211_ptr
->wiphy
!= &rdev
->wiphy
)
2202 if (!netif_running(*vlan
))
2208 static int nl80211_set_station(struct sk_buff
*skb
, struct genl_info
*info
)
2210 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2212 struct net_device
*dev
= info
->user_ptr
[1];
2213 struct station_parameters params
;
2214 u8
*mac_addr
= NULL
;
2216 memset(¶ms
, 0, sizeof(params
));
2218 params
.listen_interval
= -1;
2220 if (info
->attrs
[NL80211_ATTR_STA_AID
])
2223 if (!info
->attrs
[NL80211_ATTR_MAC
])
2226 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2228 if (info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]) {
2229 params
.supported_rates
=
2230 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2231 params
.supported_rates_len
=
2232 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2235 if (info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2236 params
.listen_interval
=
2237 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2239 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2241 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2243 if (parse_station_flags(info
, ¶ms
))
2246 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
2247 params
.plink_action
=
2248 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
2250 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
2254 /* validate settings */
2257 switch (dev
->ieee80211_ptr
->iftype
) {
2258 case NL80211_IFTYPE_AP
:
2259 case NL80211_IFTYPE_AP_VLAN
:
2260 case NL80211_IFTYPE_P2P_GO
:
2261 /* disallow mesh-specific things */
2262 if (params
.plink_action
)
2265 case NL80211_IFTYPE_P2P_CLIENT
:
2266 case NL80211_IFTYPE_STATION
:
2267 /* disallow everything but AUTHORIZED flag */
2268 if (params
.plink_action
)
2272 if (params
.supported_rates
)
2276 if (params
.listen_interval
>= 0)
2278 if (params
.sta_flags_mask
& ~BIT(NL80211_STA_FLAG_AUTHORIZED
))
2281 case NL80211_IFTYPE_MESH_POINT
:
2282 /* disallow things mesh doesn't support */
2287 if (params
.listen_interval
>= 0)
2289 if (params
.supported_rates
)
2291 if (params
.sta_flags_mask
&
2292 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED
) |
2293 BIT(NL80211_STA_FLAG_AUTHORIZED
)))
2303 if (!rdev
->ops
->change_station
) {
2308 err
= rdev
->ops
->change_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2312 dev_put(params
.vlan
);
2317 static int nl80211_new_station(struct sk_buff
*skb
, struct genl_info
*info
)
2319 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2321 struct net_device
*dev
= info
->user_ptr
[1];
2322 struct station_parameters params
;
2323 u8
*mac_addr
= NULL
;
2325 memset(¶ms
, 0, sizeof(params
));
2327 if (!info
->attrs
[NL80211_ATTR_MAC
])
2330 if (!info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
])
2333 if (!info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
])
2336 if (!info
->attrs
[NL80211_ATTR_STA_AID
])
2339 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2340 params
.supported_rates
=
2341 nla_data(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2342 params
.supported_rates_len
=
2343 nla_len(info
->attrs
[NL80211_ATTR_STA_SUPPORTED_RATES
]);
2344 params
.listen_interval
=
2345 nla_get_u16(info
->attrs
[NL80211_ATTR_STA_LISTEN_INTERVAL
]);
2347 params
.aid
= nla_get_u16(info
->attrs
[NL80211_ATTR_STA_AID
]);
2348 if (!params
.aid
|| params
.aid
> IEEE80211_MAX_AID
)
2351 if (info
->attrs
[NL80211_ATTR_HT_CAPABILITY
])
2353 nla_data(info
->attrs
[NL80211_ATTR_HT_CAPABILITY
]);
2355 if (info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
])
2356 params
.plink_action
=
2357 nla_get_u8(info
->attrs
[NL80211_ATTR_STA_PLINK_ACTION
]);
2359 if (parse_station_flags(info
, ¶ms
))
2362 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2363 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
2364 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
2365 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2368 err
= get_vlan(info
, rdev
, ¶ms
.vlan
);
2372 /* validate settings */
2375 if (!rdev
->ops
->add_station
) {
2380 err
= rdev
->ops
->add_station(&rdev
->wiphy
, dev
, mac_addr
, ¶ms
);
2384 dev_put(params
.vlan
);
2388 static int nl80211_del_station(struct sk_buff
*skb
, struct genl_info
*info
)
2390 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2391 struct net_device
*dev
= info
->user_ptr
[1];
2392 u8
*mac_addr
= NULL
;
2394 if (info
->attrs
[NL80211_ATTR_MAC
])
2395 mac_addr
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2397 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2398 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
2399 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
2400 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2403 if (!rdev
->ops
->del_station
)
2406 return rdev
->ops
->del_station(&rdev
->wiphy
, dev
, mac_addr
);
2409 static int nl80211_send_mpath(struct sk_buff
*msg
, u32 pid
, u32 seq
,
2410 int flags
, struct net_device
*dev
,
2411 u8
*dst
, u8
*next_hop
,
2412 struct mpath_info
*pinfo
)
2415 struct nlattr
*pinfoattr
;
2417 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, NL80211_CMD_NEW_STATION
);
2421 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2422 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, dst
);
2423 NLA_PUT(msg
, NL80211_ATTR_MPATH_NEXT_HOP
, ETH_ALEN
, next_hop
);
2425 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, pinfo
->generation
);
2427 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MPATH_INFO
);
2429 goto nla_put_failure
;
2430 if (pinfo
->filled
& MPATH_INFO_FRAME_QLEN
)
2431 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_FRAME_QLEN
,
2433 if (pinfo
->filled
& MPATH_INFO_SN
)
2434 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_SN
,
2436 if (pinfo
->filled
& MPATH_INFO_METRIC
)
2437 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_METRIC
,
2439 if (pinfo
->filled
& MPATH_INFO_EXPTIME
)
2440 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_EXPTIME
,
2442 if (pinfo
->filled
& MPATH_INFO_FLAGS
)
2443 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_FLAGS
,
2445 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_TIMEOUT
)
2446 NLA_PUT_U32(msg
, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT
,
2447 pinfo
->discovery_timeout
);
2448 if (pinfo
->filled
& MPATH_INFO_DISCOVERY_RETRIES
)
2449 NLA_PUT_U8(msg
, NL80211_MPATH_INFO_DISCOVERY_RETRIES
,
2450 pinfo
->discovery_retries
);
2452 nla_nest_end(msg
, pinfoattr
);
2454 return genlmsg_end(msg
, hdr
);
2457 genlmsg_cancel(msg
, hdr
);
2461 static int nl80211_dump_mpath(struct sk_buff
*skb
,
2462 struct netlink_callback
*cb
)
2464 struct mpath_info pinfo
;
2465 struct cfg80211_registered_device
*dev
;
2466 struct net_device
*netdev
;
2468 u8 next_hop
[ETH_ALEN
];
2469 int path_idx
= cb
->args
[1];
2472 err
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
2476 if (!dev
->ops
->dump_mpath
) {
2481 if (netdev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
) {
2487 err
= dev
->ops
->dump_mpath(&dev
->wiphy
, netdev
, path_idx
,
2488 dst
, next_hop
, &pinfo
);
2494 if (nl80211_send_mpath(skb
, NETLINK_CB(cb
->skb
).pid
,
2495 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
2496 netdev
, dst
, next_hop
,
2505 cb
->args
[1] = path_idx
;
2508 nl80211_finish_netdev_dump(dev
);
2512 static int nl80211_get_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2514 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2516 struct net_device
*dev
= info
->user_ptr
[1];
2517 struct mpath_info pinfo
;
2518 struct sk_buff
*msg
;
2520 u8 next_hop
[ETH_ALEN
];
2522 memset(&pinfo
, 0, sizeof(pinfo
));
2524 if (!info
->attrs
[NL80211_ATTR_MAC
])
2527 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2529 if (!rdev
->ops
->get_mpath
)
2532 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2535 err
= rdev
->ops
->get_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
, &pinfo
);
2539 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2543 if (nl80211_send_mpath(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2544 dev
, dst
, next_hop
, &pinfo
) < 0) {
2549 return genlmsg_reply(msg
, info
);
2552 static int nl80211_set_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2554 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2555 struct net_device
*dev
= info
->user_ptr
[1];
2557 u8
*next_hop
= NULL
;
2559 if (!info
->attrs
[NL80211_ATTR_MAC
])
2562 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2565 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2566 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2568 if (!rdev
->ops
->change_mpath
)
2571 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2574 return rdev
->ops
->change_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2577 static int nl80211_new_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2579 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2580 struct net_device
*dev
= info
->user_ptr
[1];
2582 u8
*next_hop
= NULL
;
2584 if (!info
->attrs
[NL80211_ATTR_MAC
])
2587 if (!info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
])
2590 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2591 next_hop
= nla_data(info
->attrs
[NL80211_ATTR_MPATH_NEXT_HOP
]);
2593 if (!rdev
->ops
->add_mpath
)
2596 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2599 return rdev
->ops
->add_mpath(&rdev
->wiphy
, dev
, dst
, next_hop
);
2602 static int nl80211_del_mpath(struct sk_buff
*skb
, struct genl_info
*info
)
2604 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2605 struct net_device
*dev
= info
->user_ptr
[1];
2608 if (info
->attrs
[NL80211_ATTR_MAC
])
2609 dst
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
2611 if (!rdev
->ops
->del_mpath
)
2614 return rdev
->ops
->del_mpath(&rdev
->wiphy
, dev
, dst
);
2617 static int nl80211_set_bss(struct sk_buff
*skb
, struct genl_info
*info
)
2619 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2620 struct net_device
*dev
= info
->user_ptr
[1];
2621 struct bss_parameters params
;
2623 memset(¶ms
, 0, sizeof(params
));
2624 /* default to not changing parameters */
2625 params
.use_cts_prot
= -1;
2626 params
.use_short_preamble
= -1;
2627 params
.use_short_slot_time
= -1;
2628 params
.ap_isolate
= -1;
2629 params
.ht_opmode
= -1;
2631 if (info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
])
2632 params
.use_cts_prot
=
2633 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_CTS_PROT
]);
2634 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
])
2635 params
.use_short_preamble
=
2636 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_PREAMBLE
]);
2637 if (info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
])
2638 params
.use_short_slot_time
=
2639 nla_get_u8(info
->attrs
[NL80211_ATTR_BSS_SHORT_SLOT_TIME
]);
2640 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
2641 params
.basic_rates
=
2642 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2643 params
.basic_rates_len
=
2644 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
2646 if (info
->attrs
[NL80211_ATTR_AP_ISOLATE
])
2647 params
.ap_isolate
= !!nla_get_u8(info
->attrs
[NL80211_ATTR_AP_ISOLATE
]);
2648 if (info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
])
2650 nla_get_u16(info
->attrs
[NL80211_ATTR_BSS_HT_OPMODE
]);
2652 if (!rdev
->ops
->change_bss
)
2655 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
2656 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
2659 return rdev
->ops
->change_bss(&rdev
->wiphy
, dev
, ¶ms
);
2662 static const struct nla_policy reg_rule_policy
[NL80211_REG_RULE_ATTR_MAX
+ 1] = {
2663 [NL80211_ATTR_REG_RULE_FLAGS
] = { .type
= NLA_U32
},
2664 [NL80211_ATTR_FREQ_RANGE_START
] = { .type
= NLA_U32
},
2665 [NL80211_ATTR_FREQ_RANGE_END
] = { .type
= NLA_U32
},
2666 [NL80211_ATTR_FREQ_RANGE_MAX_BW
] = { .type
= NLA_U32
},
2667 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
] = { .type
= NLA_U32
},
2668 [NL80211_ATTR_POWER_RULE_MAX_EIRP
] = { .type
= NLA_U32
},
2671 static int parse_reg_rule(struct nlattr
*tb
[],
2672 struct ieee80211_reg_rule
*reg_rule
)
2674 struct ieee80211_freq_range
*freq_range
= ®_rule
->freq_range
;
2675 struct ieee80211_power_rule
*power_rule
= ®_rule
->power_rule
;
2677 if (!tb
[NL80211_ATTR_REG_RULE_FLAGS
])
2679 if (!tb
[NL80211_ATTR_FREQ_RANGE_START
])
2681 if (!tb
[NL80211_ATTR_FREQ_RANGE_END
])
2683 if (!tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
])
2685 if (!tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
])
2688 reg_rule
->flags
= nla_get_u32(tb
[NL80211_ATTR_REG_RULE_FLAGS
]);
2690 freq_range
->start_freq_khz
=
2691 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_START
]);
2692 freq_range
->end_freq_khz
=
2693 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_END
]);
2694 freq_range
->max_bandwidth_khz
=
2695 nla_get_u32(tb
[NL80211_ATTR_FREQ_RANGE_MAX_BW
]);
2697 power_rule
->max_eirp
=
2698 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_EIRP
]);
2700 if (tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
])
2701 power_rule
->max_antenna_gain
=
2702 nla_get_u32(tb
[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
]);
2707 static int nl80211_req_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2713 * You should only get this when cfg80211 hasn't yet initialized
2714 * completely when built-in to the kernel right between the time
2715 * window between nl80211_init() and regulatory_init(), if that is
2718 mutex_lock(&cfg80211_mutex
);
2719 if (unlikely(!cfg80211_regdomain
)) {
2720 mutex_unlock(&cfg80211_mutex
);
2721 return -EINPROGRESS
;
2723 mutex_unlock(&cfg80211_mutex
);
2725 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
2728 data
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
2730 r
= regulatory_hint_user(data
);
2735 static int nl80211_get_mesh_config(struct sk_buff
*skb
,
2736 struct genl_info
*info
)
2738 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2739 struct net_device
*dev
= info
->user_ptr
[1];
2740 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2741 struct mesh_config cur_params
;
2744 struct nlattr
*pinfoattr
;
2745 struct sk_buff
*msg
;
2747 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2750 if (!rdev
->ops
->get_mesh_config
)
2754 /* If not connected, get default parameters */
2755 if (!wdev
->mesh_id_len
)
2756 memcpy(&cur_params
, &default_mesh_config
, sizeof(cur_params
));
2758 err
= rdev
->ops
->get_mesh_config(&rdev
->wiphy
, dev
,
2765 /* Draw up a netlink message to send back */
2766 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
2769 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
2770 NL80211_CMD_GET_MESH_CONFIG
);
2773 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_MESH_CONFIG
);
2775 goto nla_put_failure
;
2776 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
2777 NLA_PUT_U16(msg
, NL80211_MESHCONF_RETRY_TIMEOUT
,
2778 cur_params
.dot11MeshRetryTimeout
);
2779 NLA_PUT_U16(msg
, NL80211_MESHCONF_CONFIRM_TIMEOUT
,
2780 cur_params
.dot11MeshConfirmTimeout
);
2781 NLA_PUT_U16(msg
, NL80211_MESHCONF_HOLDING_TIMEOUT
,
2782 cur_params
.dot11MeshHoldingTimeout
);
2783 NLA_PUT_U16(msg
, NL80211_MESHCONF_MAX_PEER_LINKS
,
2784 cur_params
.dot11MeshMaxPeerLinks
);
2785 NLA_PUT_U8(msg
, NL80211_MESHCONF_MAX_RETRIES
,
2786 cur_params
.dot11MeshMaxRetries
);
2787 NLA_PUT_U8(msg
, NL80211_MESHCONF_TTL
,
2788 cur_params
.dot11MeshTTL
);
2789 NLA_PUT_U8(msg
, NL80211_MESHCONF_ELEMENT_TTL
,
2790 cur_params
.element_ttl
);
2791 NLA_PUT_U8(msg
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
,
2792 cur_params
.auto_open_plinks
);
2793 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2794 cur_params
.dot11MeshHWMPmaxPREQretries
);
2795 NLA_PUT_U32(msg
, NL80211_MESHCONF_PATH_REFRESH_TIME
,
2796 cur_params
.path_refresh_time
);
2797 NLA_PUT_U16(msg
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2798 cur_params
.min_discovery_timeout
);
2799 NLA_PUT_U32(msg
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2800 cur_params
.dot11MeshHWMPactivePathTimeout
);
2801 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2802 cur_params
.dot11MeshHWMPpreqMinInterval
);
2803 NLA_PUT_U16(msg
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2804 cur_params
.dot11MeshHWMPnetDiameterTraversalTime
);
2805 NLA_PUT_U8(msg
, NL80211_MESHCONF_HWMP_ROOTMODE
,
2806 cur_params
.dot11MeshHWMPRootMode
);
2807 nla_nest_end(msg
, pinfoattr
);
2808 genlmsg_end(msg
, hdr
);
2809 return genlmsg_reply(msg
, info
);
2812 genlmsg_cancel(msg
, hdr
);
2818 static const struct nla_policy nl80211_meshconf_params_policy
[NL80211_MESHCONF_ATTR_MAX
+1] = {
2819 [NL80211_MESHCONF_RETRY_TIMEOUT
] = { .type
= NLA_U16
},
2820 [NL80211_MESHCONF_CONFIRM_TIMEOUT
] = { .type
= NLA_U16
},
2821 [NL80211_MESHCONF_HOLDING_TIMEOUT
] = { .type
= NLA_U16
},
2822 [NL80211_MESHCONF_MAX_PEER_LINKS
] = { .type
= NLA_U16
},
2823 [NL80211_MESHCONF_MAX_RETRIES
] = { .type
= NLA_U8
},
2824 [NL80211_MESHCONF_TTL
] = { .type
= NLA_U8
},
2825 [NL80211_MESHCONF_ELEMENT_TTL
] = { .type
= NLA_U8
},
2826 [NL80211_MESHCONF_AUTO_OPEN_PLINKS
] = { .type
= NLA_U8
},
2828 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
] = { .type
= NLA_U8
},
2829 [NL80211_MESHCONF_PATH_REFRESH_TIME
] = { .type
= NLA_U32
},
2830 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
] = { .type
= NLA_U16
},
2831 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
] = { .type
= NLA_U32
},
2832 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
] = { .type
= NLA_U16
},
2833 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
] = { .type
= NLA_U16
},
2836 static const struct nla_policy
2837 nl80211_mesh_setup_params_policy
[NL80211_MESH_SETUP_ATTR_MAX
+1] = {
2838 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
] = { .type
= NLA_U8
},
2839 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
] = { .type
= NLA_U8
},
2840 [NL80211_MESH_SETUP_USERSPACE_AUTH
] = { .type
= NLA_FLAG
},
2841 [NL80211_MESH_SETUP_IE
] = { .type
= NLA_BINARY
,
2842 .len
= IEEE80211_MAX_DATA_LEN
},
2845 static int nl80211_parse_mesh_config(struct genl_info
*info
,
2846 struct mesh_config
*cfg
,
2849 struct nlattr
*tb
[NL80211_MESHCONF_ATTR_MAX
+ 1];
2852 #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2854 if (table[attr_num]) {\
2855 cfg->param = nla_fn(table[attr_num]); \
2856 mask |= (1 << (attr_num - 1)); \
2861 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
2863 if (nla_parse_nested(tb
, NL80211_MESHCONF_ATTR_MAX
,
2864 info
->attrs
[NL80211_ATTR_MESH_CONFIG
],
2865 nl80211_meshconf_params_policy
))
2868 /* This makes sure that there aren't more than 32 mesh config
2869 * parameters (otherwise our bitfield scheme would not work.) */
2870 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX
> 32);
2872 /* Fill in the params struct */
2873 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshRetryTimeout
,
2874 mask
, NL80211_MESHCONF_RETRY_TIMEOUT
, nla_get_u16
);
2875 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshConfirmTimeout
,
2876 mask
, NL80211_MESHCONF_CONFIRM_TIMEOUT
, nla_get_u16
);
2877 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHoldingTimeout
,
2878 mask
, NL80211_MESHCONF_HOLDING_TIMEOUT
, nla_get_u16
);
2879 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxPeerLinks
,
2880 mask
, NL80211_MESHCONF_MAX_PEER_LINKS
, nla_get_u16
);
2881 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshMaxRetries
,
2882 mask
, NL80211_MESHCONF_MAX_RETRIES
, nla_get_u8
);
2883 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshTTL
,
2884 mask
, NL80211_MESHCONF_TTL
, nla_get_u8
);
2885 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, element_ttl
,
2886 mask
, NL80211_MESHCONF_ELEMENT_TTL
, nla_get_u8
);
2887 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, auto_open_plinks
,
2888 mask
, NL80211_MESHCONF_AUTO_OPEN_PLINKS
, nla_get_u8
);
2889 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPmaxPREQretries
,
2890 mask
, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES
,
2892 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, path_refresh_time
,
2893 mask
, NL80211_MESHCONF_PATH_REFRESH_TIME
, nla_get_u32
);
2894 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, min_discovery_timeout
,
2895 mask
, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT
,
2897 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPactivePathTimeout
,
2898 mask
, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT
,
2900 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
, dot11MeshHWMPpreqMinInterval
,
2901 mask
, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL
,
2903 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
2904 dot11MeshHWMPnetDiameterTraversalTime
,
2905 mask
, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME
,
2907 FILL_IN_MESH_PARAM_IF_SET(tb
, cfg
,
2908 dot11MeshHWMPRootMode
, mask
,
2909 NL80211_MESHCONF_HWMP_ROOTMODE
,
2916 #undef FILL_IN_MESH_PARAM_IF_SET
2919 static int nl80211_parse_mesh_setup(struct genl_info
*info
,
2920 struct mesh_setup
*setup
)
2922 struct nlattr
*tb
[NL80211_MESH_SETUP_ATTR_MAX
+ 1];
2924 if (!info
->attrs
[NL80211_ATTR_MESH_SETUP
])
2926 if (nla_parse_nested(tb
, NL80211_MESH_SETUP_ATTR_MAX
,
2927 info
->attrs
[NL80211_ATTR_MESH_SETUP
],
2928 nl80211_mesh_setup_params_policy
))
2931 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])
2932 setup
->path_sel_proto
=
2933 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL
])) ?
2934 IEEE80211_PATH_PROTOCOL_VENDOR
:
2935 IEEE80211_PATH_PROTOCOL_HWMP
;
2937 if (tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])
2938 setup
->path_metric
=
2939 (nla_get_u8(tb
[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC
])) ?
2940 IEEE80211_PATH_METRIC_VENDOR
:
2941 IEEE80211_PATH_METRIC_AIRTIME
;
2944 if (tb
[NL80211_MESH_SETUP_IE
]) {
2945 struct nlattr
*ieattr
=
2946 tb
[NL80211_MESH_SETUP_IE
];
2947 if (!is_valid_ie_attr(ieattr
))
2949 setup
->ie
= nla_data(ieattr
);
2950 setup
->ie_len
= nla_len(ieattr
);
2952 setup
->is_secure
= nla_get_flag(tb
[NL80211_MESH_SETUP_USERSPACE_AUTH
]);
2957 static int nl80211_update_mesh_config(struct sk_buff
*skb
,
2958 struct genl_info
*info
)
2960 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
2961 struct net_device
*dev
= info
->user_ptr
[1];
2962 struct wireless_dev
*wdev
= dev
->ieee80211_ptr
;
2963 struct mesh_config cfg
;
2967 if (wdev
->iftype
!= NL80211_IFTYPE_MESH_POINT
)
2970 if (!rdev
->ops
->update_mesh_config
)
2973 err
= nl80211_parse_mesh_config(info
, &cfg
, &mask
);
2978 if (!wdev
->mesh_id_len
)
2982 err
= rdev
->ops
->update_mesh_config(&rdev
->wiphy
, dev
,
2990 static int nl80211_get_reg(struct sk_buff
*skb
, struct genl_info
*info
)
2992 struct sk_buff
*msg
;
2994 struct nlattr
*nl_reg_rules
;
2998 mutex_lock(&cfg80211_mutex
);
3000 if (!cfg80211_regdomain
)
3003 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
3009 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
3010 NL80211_CMD_GET_REG
);
3014 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
,
3015 cfg80211_regdomain
->alpha2
);
3017 nl_reg_rules
= nla_nest_start(msg
, NL80211_ATTR_REG_RULES
);
3019 goto nla_put_failure
;
3021 for (i
= 0; i
< cfg80211_regdomain
->n_reg_rules
; i
++) {
3022 struct nlattr
*nl_reg_rule
;
3023 const struct ieee80211_reg_rule
*reg_rule
;
3024 const struct ieee80211_freq_range
*freq_range
;
3025 const struct ieee80211_power_rule
*power_rule
;
3027 reg_rule
= &cfg80211_regdomain
->reg_rules
[i
];
3028 freq_range
= ®_rule
->freq_range
;
3029 power_rule
= ®_rule
->power_rule
;
3031 nl_reg_rule
= nla_nest_start(msg
, i
);
3033 goto nla_put_failure
;
3035 NLA_PUT_U32(msg
, NL80211_ATTR_REG_RULE_FLAGS
,
3037 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_START
,
3038 freq_range
->start_freq_khz
);
3039 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_END
,
3040 freq_range
->end_freq_khz
);
3041 NLA_PUT_U32(msg
, NL80211_ATTR_FREQ_RANGE_MAX_BW
,
3042 freq_range
->max_bandwidth_khz
);
3043 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN
,
3044 power_rule
->max_antenna_gain
);
3045 NLA_PUT_U32(msg
, NL80211_ATTR_POWER_RULE_MAX_EIRP
,
3046 power_rule
->max_eirp
);
3048 nla_nest_end(msg
, nl_reg_rule
);
3051 nla_nest_end(msg
, nl_reg_rules
);
3053 genlmsg_end(msg
, hdr
);
3054 err
= genlmsg_reply(msg
, info
);
3058 genlmsg_cancel(msg
, hdr
);
3063 mutex_unlock(&cfg80211_mutex
);
3067 static int nl80211_set_reg(struct sk_buff
*skb
, struct genl_info
*info
)
3069 struct nlattr
*tb
[NL80211_REG_RULE_ATTR_MAX
+ 1];
3070 struct nlattr
*nl_reg_rule
;
3071 char *alpha2
= NULL
;
3072 int rem_reg_rules
= 0, r
= 0;
3073 u32 num_rules
= 0, rule_idx
= 0, size_of_regd
;
3074 struct ieee80211_regdomain
*rd
= NULL
;
3076 if (!info
->attrs
[NL80211_ATTR_REG_ALPHA2
])
3079 if (!info
->attrs
[NL80211_ATTR_REG_RULES
])
3082 alpha2
= nla_data(info
->attrs
[NL80211_ATTR_REG_ALPHA2
]);
3084 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
3087 if (num_rules
> NL80211_MAX_SUPP_REG_RULES
)
3091 mutex_lock(&cfg80211_mutex
);
3093 if (!reg_is_valid_request(alpha2
)) {
3098 size_of_regd
= sizeof(struct ieee80211_regdomain
) +
3099 (num_rules
* sizeof(struct ieee80211_reg_rule
));
3101 rd
= kzalloc(size_of_regd
, GFP_KERNEL
);
3107 rd
->n_reg_rules
= num_rules
;
3108 rd
->alpha2
[0] = alpha2
[0];
3109 rd
->alpha2
[1] = alpha2
[1];
3111 nla_for_each_nested(nl_reg_rule
, info
->attrs
[NL80211_ATTR_REG_RULES
],
3113 nla_parse(tb
, NL80211_REG_RULE_ATTR_MAX
,
3114 nla_data(nl_reg_rule
), nla_len(nl_reg_rule
),
3116 r
= parse_reg_rule(tb
, &rd
->reg_rules
[rule_idx
]);
3122 if (rule_idx
> NL80211_MAX_SUPP_REG_RULES
) {
3128 BUG_ON(rule_idx
!= num_rules
);
3132 mutex_unlock(&cfg80211_mutex
);
3137 mutex_unlock(&cfg80211_mutex
);
3142 static int validate_scan_freqs(struct nlattr
*freqs
)
3144 struct nlattr
*attr1
, *attr2
;
3145 int n_channels
= 0, tmp1
, tmp2
;
3147 nla_for_each_nested(attr1
, freqs
, tmp1
) {
3150 * Some hardware has a limited channel list for
3151 * scanning, and it is pretty much nonsensical
3152 * to scan for a channel twice, so disallow that
3153 * and don't require drivers to check that the
3154 * channel list they get isn't longer than what
3155 * they can scan, as long as they can scan all
3156 * the channels they registered at once.
3158 nla_for_each_nested(attr2
, freqs
, tmp2
)
3159 if (attr1
!= attr2
&&
3160 nla_get_u32(attr1
) == nla_get_u32(attr2
))
3167 static int nl80211_trigger_scan(struct sk_buff
*skb
, struct genl_info
*info
)
3169 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3170 struct net_device
*dev
= info
->user_ptr
[1];
3171 struct cfg80211_scan_request
*request
;
3172 struct cfg80211_ssid
*ssid
;
3173 struct ieee80211_channel
*channel
;
3174 struct nlattr
*attr
;
3175 struct wiphy
*wiphy
;
3176 int err
, tmp
, n_ssids
= 0, n_channels
, i
;
3177 enum ieee80211_band band
;
3180 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3183 wiphy
= &rdev
->wiphy
;
3185 if (!rdev
->ops
->scan
)
3191 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3192 n_channels
= validate_scan_freqs(
3193 info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]);
3199 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++)
3200 if (wiphy
->bands
[band
])
3201 n_channels
+= wiphy
->bands
[band
]->n_channels
;
3204 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
])
3205 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
)
3208 if (n_ssids
> wiphy
->max_scan_ssids
)
3211 if (info
->attrs
[NL80211_ATTR_IE
])
3212 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3216 if (ie_len
> wiphy
->max_scan_ie_len
)
3219 request
= kzalloc(sizeof(*request
)
3220 + sizeof(*ssid
) * n_ssids
3221 + sizeof(channel
) * n_channels
3222 + ie_len
, GFP_KERNEL
);
3227 request
->ssids
= (void *)&request
->channels
[n_channels
];
3228 request
->n_ssids
= n_ssids
;
3231 request
->ie
= (void *)(request
->ssids
+ n_ssids
);
3233 request
->ie
= (void *)(request
->channels
+ n_channels
);
3237 if (info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
]) {
3238 /* user specified, bail out if channel not found */
3239 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_FREQUENCIES
], tmp
) {
3240 struct ieee80211_channel
*chan
;
3242 chan
= ieee80211_get_channel(wiphy
, nla_get_u32(attr
));
3249 /* ignore disabled channels */
3250 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3253 request
->channels
[i
] = chan
;
3258 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
3260 if (!wiphy
->bands
[band
])
3262 for (j
= 0; j
< wiphy
->bands
[band
]->n_channels
; j
++) {
3263 struct ieee80211_channel
*chan
;
3265 chan
= &wiphy
->bands
[band
]->channels
[j
];
3267 if (chan
->flags
& IEEE80211_CHAN_DISABLED
)
3270 request
->channels
[i
] = chan
;
3281 request
->n_channels
= i
;
3284 if (info
->attrs
[NL80211_ATTR_SCAN_SSIDS
]) {
3285 nla_for_each_nested(attr
, info
->attrs
[NL80211_ATTR_SCAN_SSIDS
], tmp
) {
3286 if (request
->ssids
[i
].ssid_len
> IEEE80211_MAX_SSID_LEN
) {
3290 memcpy(request
->ssids
[i
].ssid
, nla_data(attr
), nla_len(attr
));
3291 request
->ssids
[i
].ssid_len
= nla_len(attr
);
3296 if (info
->attrs
[NL80211_ATTR_IE
]) {
3297 request
->ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3298 memcpy((void *)request
->ie
,
3299 nla_data(info
->attrs
[NL80211_ATTR_IE
]),
3304 request
->wiphy
= &rdev
->wiphy
;
3306 rdev
->scan_req
= request
;
3307 err
= rdev
->ops
->scan(&rdev
->wiphy
, dev
, request
);
3310 nl80211_send_scan_start(rdev
, dev
);
3314 rdev
->scan_req
= NULL
;
3321 static int nl80211_send_bss(struct sk_buff
*msg
, u32 pid
, u32 seq
, int flags
,
3322 struct cfg80211_registered_device
*rdev
,
3323 struct wireless_dev
*wdev
,
3324 struct cfg80211_internal_bss
*intbss
)
3326 struct cfg80211_bss
*res
= &intbss
->pub
;
3331 ASSERT_WDEV_LOCK(wdev
);
3333 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3334 NL80211_CMD_NEW_SCAN_RESULTS
);
3338 NLA_PUT_U32(msg
, NL80211_ATTR_GENERATION
, rdev
->bss_generation
);
3339 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, wdev
->netdev
->ifindex
);
3341 bss
= nla_nest_start(msg
, NL80211_ATTR_BSS
);
3343 goto nla_put_failure
;
3344 if (!is_zero_ether_addr(res
->bssid
))
3345 NLA_PUT(msg
, NL80211_BSS_BSSID
, ETH_ALEN
, res
->bssid
);
3346 if (res
->information_elements
&& res
->len_information_elements
)
3347 NLA_PUT(msg
, NL80211_BSS_INFORMATION_ELEMENTS
,
3348 res
->len_information_elements
,
3349 res
->information_elements
);
3350 if (res
->beacon_ies
&& res
->len_beacon_ies
&&
3351 res
->beacon_ies
!= res
->information_elements
)
3352 NLA_PUT(msg
, NL80211_BSS_BEACON_IES
,
3353 res
->len_beacon_ies
, res
->beacon_ies
);
3355 NLA_PUT_U64(msg
, NL80211_BSS_TSF
, res
->tsf
);
3356 if (res
->beacon_interval
)
3357 NLA_PUT_U16(msg
, NL80211_BSS_BEACON_INTERVAL
, res
->beacon_interval
);
3358 NLA_PUT_U16(msg
, NL80211_BSS_CAPABILITY
, res
->capability
);
3359 NLA_PUT_U32(msg
, NL80211_BSS_FREQUENCY
, res
->channel
->center_freq
);
3360 NLA_PUT_U32(msg
, NL80211_BSS_SEEN_MS_AGO
,
3361 jiffies_to_msecs(jiffies
- intbss
->ts
));
3363 switch (rdev
->wiphy
.signal_type
) {
3364 case CFG80211_SIGNAL_TYPE_MBM
:
3365 NLA_PUT_U32(msg
, NL80211_BSS_SIGNAL_MBM
, res
->signal
);
3367 case CFG80211_SIGNAL_TYPE_UNSPEC
:
3368 NLA_PUT_U8(msg
, NL80211_BSS_SIGNAL_UNSPEC
, res
->signal
);
3374 switch (wdev
->iftype
) {
3375 case NL80211_IFTYPE_P2P_CLIENT
:
3376 case NL80211_IFTYPE_STATION
:
3377 if (intbss
== wdev
->current_bss
)
3378 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3379 NL80211_BSS_STATUS_ASSOCIATED
);
3380 else for (i
= 0; i
< MAX_AUTH_BSSES
; i
++) {
3381 if (intbss
!= wdev
->auth_bsses
[i
])
3383 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3384 NL80211_BSS_STATUS_AUTHENTICATED
);
3388 case NL80211_IFTYPE_ADHOC
:
3389 if (intbss
== wdev
->current_bss
)
3390 NLA_PUT_U32(msg
, NL80211_BSS_STATUS
,
3391 NL80211_BSS_STATUS_IBSS_JOINED
);
3397 nla_nest_end(msg
, bss
);
3399 return genlmsg_end(msg
, hdr
);
3402 genlmsg_cancel(msg
, hdr
);
3406 static int nl80211_dump_scan(struct sk_buff
*skb
,
3407 struct netlink_callback
*cb
)
3409 struct cfg80211_registered_device
*rdev
;
3410 struct net_device
*dev
;
3411 struct cfg80211_internal_bss
*scan
;
3412 struct wireless_dev
*wdev
;
3413 int start
= cb
->args
[1], idx
= 0;
3416 err
= nl80211_prepare_netdev_dump(skb
, cb
, &rdev
, &dev
);
3420 wdev
= dev
->ieee80211_ptr
;
3423 spin_lock_bh(&rdev
->bss_lock
);
3424 cfg80211_bss_expire(rdev
);
3426 list_for_each_entry(scan
, &rdev
->bss_list
, list
) {
3429 if (nl80211_send_bss(skb
,
3430 NETLINK_CB(cb
->skb
).pid
,
3431 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3432 rdev
, wdev
, scan
) < 0) {
3438 spin_unlock_bh(&rdev
->bss_lock
);
3442 nl80211_finish_netdev_dump(rdev
);
3447 static int nl80211_send_survey(struct sk_buff
*msg
, u32 pid
, u32 seq
,
3448 int flags
, struct net_device
*dev
,
3449 struct survey_info
*survey
)
3452 struct nlattr
*infoattr
;
3454 /* Survey without a channel doesn't make sense */
3455 if (!survey
->channel
)
3458 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
,
3459 NL80211_CMD_NEW_SURVEY_RESULTS
);
3463 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
3465 infoattr
= nla_nest_start(msg
, NL80211_ATTR_SURVEY_INFO
);
3467 goto nla_put_failure
;
3469 NLA_PUT_U32(msg
, NL80211_SURVEY_INFO_FREQUENCY
,
3470 survey
->channel
->center_freq
);
3471 if (survey
->filled
& SURVEY_INFO_NOISE_DBM
)
3472 NLA_PUT_U8(msg
, NL80211_SURVEY_INFO_NOISE
,
3474 if (survey
->filled
& SURVEY_INFO_IN_USE
)
3475 NLA_PUT_FLAG(msg
, NL80211_SURVEY_INFO_IN_USE
);
3476 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME
)
3477 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME
,
3478 survey
->channel_time
);
3479 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_BUSY
)
3480 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY
,
3481 survey
->channel_time_busy
);
3482 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
)
3483 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY
,
3484 survey
->channel_time_ext_busy
);
3485 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_RX
)
3486 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_RX
,
3487 survey
->channel_time_rx
);
3488 if (survey
->filled
& SURVEY_INFO_CHANNEL_TIME_TX
)
3489 NLA_PUT_U64(msg
, NL80211_SURVEY_INFO_CHANNEL_TIME_TX
,
3490 survey
->channel_time_tx
);
3492 nla_nest_end(msg
, infoattr
);
3494 return genlmsg_end(msg
, hdr
);
3497 genlmsg_cancel(msg
, hdr
);
3501 static int nl80211_dump_survey(struct sk_buff
*skb
,
3502 struct netlink_callback
*cb
)
3504 struct survey_info survey
;
3505 struct cfg80211_registered_device
*dev
;
3506 struct net_device
*netdev
;
3507 int survey_idx
= cb
->args
[1];
3510 res
= nl80211_prepare_netdev_dump(skb
, cb
, &dev
, &netdev
);
3514 if (!dev
->ops
->dump_survey
) {
3520 res
= dev
->ops
->dump_survey(&dev
->wiphy
, netdev
, survey_idx
,
3527 if (nl80211_send_survey(skb
,
3528 NETLINK_CB(cb
->skb
).pid
,
3529 cb
->nlh
->nlmsg_seq
, NLM_F_MULTI
,
3537 cb
->args
[1] = survey_idx
;
3540 nl80211_finish_netdev_dump(dev
);
3544 static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type
)
3546 return auth_type
<= NL80211_AUTHTYPE_MAX
;
3549 static bool nl80211_valid_wpa_versions(u32 wpa_versions
)
3551 return !(wpa_versions
& ~(NL80211_WPA_VERSION_1
|
3552 NL80211_WPA_VERSION_2
));
3555 static bool nl80211_valid_akm_suite(u32 akm
)
3557 return akm
== WLAN_AKM_SUITE_8021X
||
3558 akm
== WLAN_AKM_SUITE_PSK
;
3561 static bool nl80211_valid_cipher_suite(u32 cipher
)
3563 return cipher
== WLAN_CIPHER_SUITE_WEP40
||
3564 cipher
== WLAN_CIPHER_SUITE_WEP104
||
3565 cipher
== WLAN_CIPHER_SUITE_TKIP
||
3566 cipher
== WLAN_CIPHER_SUITE_CCMP
||
3567 cipher
== WLAN_CIPHER_SUITE_AES_CMAC
;
3571 static int nl80211_authenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3573 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3574 struct net_device
*dev
= info
->user_ptr
[1];
3575 struct ieee80211_channel
*chan
;
3576 const u8
*bssid
, *ssid
, *ie
= NULL
;
3577 int err
, ssid_len
, ie_len
= 0;
3578 enum nl80211_auth_type auth_type
;
3579 struct key_parse key
;
3580 bool local_state_change
;
3582 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3585 if (!info
->attrs
[NL80211_ATTR_MAC
])
3588 if (!info
->attrs
[NL80211_ATTR_AUTH_TYPE
])
3591 if (!info
->attrs
[NL80211_ATTR_SSID
])
3594 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
3597 err
= nl80211_parse_key(info
, &key
);
3602 if (key
.type
!= -1 && key
.type
!= NL80211_KEYTYPE_GROUP
)
3604 if (!key
.p
.key
|| !key
.p
.key_len
)
3606 if ((key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP40
||
3607 key
.p
.key_len
!= WLAN_KEY_LEN_WEP40
) &&
3608 (key
.p
.cipher
!= WLAN_CIPHER_SUITE_WEP104
||
3609 key
.p
.key_len
!= WLAN_KEY_LEN_WEP104
))
3621 for (i
= 0; i
< rdev
->wiphy
.n_cipher_suites
; i
++) {
3622 if (key
.p
.cipher
== rdev
->wiphy
.cipher_suites
[i
]) {
3631 if (!rdev
->ops
->auth
)
3634 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
3635 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
3638 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3639 chan
= ieee80211_get_channel(&rdev
->wiphy
,
3640 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3641 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
3644 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3645 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3647 if (info
->attrs
[NL80211_ATTR_IE
]) {
3648 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3649 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3652 auth_type
= nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
3653 if (!nl80211_valid_auth_type(auth_type
))
3656 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
3658 return cfg80211_mlme_auth(rdev
, dev
, chan
, auth_type
, bssid
,
3659 ssid
, ssid_len
, ie
, ie_len
,
3660 key
.p
.key
, key
.p
.key_len
, key
.idx
,
3661 local_state_change
);
3664 static int nl80211_crypto_settings(struct cfg80211_registered_device
*rdev
,
3665 struct genl_info
*info
,
3666 struct cfg80211_crypto_settings
*settings
,
3669 memset(settings
, 0, sizeof(*settings
));
3671 settings
->control_port
= info
->attrs
[NL80211_ATTR_CONTROL_PORT
];
3673 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]) {
3675 proto
= nla_get_u16(
3676 info
->attrs
[NL80211_ATTR_CONTROL_PORT_ETHERTYPE
]);
3677 settings
->control_port_ethertype
= cpu_to_be16(proto
);
3678 if (!(rdev
->wiphy
.flags
& WIPHY_FLAG_CONTROL_PORT_PROTOCOL
) &&
3681 if (info
->attrs
[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT
])
3682 settings
->control_port_no_encrypt
= true;
3684 settings
->control_port_ethertype
= cpu_to_be16(ETH_P_PAE
);
3686 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]) {
3690 data
= nla_data(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
3691 len
= nla_len(info
->attrs
[NL80211_ATTR_CIPHER_SUITES_PAIRWISE
]);
3692 settings
->n_ciphers_pairwise
= len
/ sizeof(u32
);
3694 if (len
% sizeof(u32
))
3697 if (settings
->n_ciphers_pairwise
> cipher_limit
)
3700 memcpy(settings
->ciphers_pairwise
, data
, len
);
3702 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
3703 if (!nl80211_valid_cipher_suite(
3704 settings
->ciphers_pairwise
[i
]))
3708 if (info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]) {
3709 settings
->cipher_group
=
3710 nla_get_u32(info
->attrs
[NL80211_ATTR_CIPHER_SUITE_GROUP
]);
3711 if (!nl80211_valid_cipher_suite(settings
->cipher_group
))
3715 if (info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]) {
3716 settings
->wpa_versions
=
3717 nla_get_u32(info
->attrs
[NL80211_ATTR_WPA_VERSIONS
]);
3718 if (!nl80211_valid_wpa_versions(settings
->wpa_versions
))
3722 if (info
->attrs
[NL80211_ATTR_AKM_SUITES
]) {
3726 data
= nla_data(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
3727 len
= nla_len(info
->attrs
[NL80211_ATTR_AKM_SUITES
]);
3728 settings
->n_akm_suites
= len
/ sizeof(u32
);
3730 if (len
% sizeof(u32
))
3733 memcpy(settings
->akm_suites
, data
, len
);
3735 for (i
= 0; i
< settings
->n_ciphers_pairwise
; i
++)
3736 if (!nl80211_valid_akm_suite(settings
->akm_suites
[i
]))
3743 static int nl80211_associate(struct sk_buff
*skb
, struct genl_info
*info
)
3745 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3746 struct net_device
*dev
= info
->user_ptr
[1];
3747 struct cfg80211_crypto_settings crypto
;
3748 struct ieee80211_channel
*chan
;
3749 const u8
*bssid
, *ssid
, *ie
= NULL
, *prev_bssid
= NULL
;
3750 int err
, ssid_len
, ie_len
= 0;
3751 bool use_mfp
= false;
3753 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3756 if (!info
->attrs
[NL80211_ATTR_MAC
] ||
3757 !info
->attrs
[NL80211_ATTR_SSID
] ||
3758 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
3761 if (!rdev
->ops
->assoc
)
3764 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
3765 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
3768 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3770 chan
= ieee80211_get_channel(&rdev
->wiphy
,
3771 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3772 if (!chan
|| (chan
->flags
& IEEE80211_CHAN_DISABLED
))
3775 ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3776 ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3778 if (info
->attrs
[NL80211_ATTR_IE
]) {
3779 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3780 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3783 if (info
->attrs
[NL80211_ATTR_USE_MFP
]) {
3784 enum nl80211_mfp mfp
=
3785 nla_get_u32(info
->attrs
[NL80211_ATTR_USE_MFP
]);
3786 if (mfp
== NL80211_MFP_REQUIRED
)
3788 else if (mfp
!= NL80211_MFP_NO
)
3792 if (info
->attrs
[NL80211_ATTR_PREV_BSSID
])
3793 prev_bssid
= nla_data(info
->attrs
[NL80211_ATTR_PREV_BSSID
]);
3795 err
= nl80211_crypto_settings(rdev
, info
, &crypto
, 1);
3797 err
= cfg80211_mlme_assoc(rdev
, dev
, chan
, bssid
, prev_bssid
,
3798 ssid
, ssid_len
, ie
, ie_len
, use_mfp
,
3804 static int nl80211_deauthenticate(struct sk_buff
*skb
, struct genl_info
*info
)
3806 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3807 struct net_device
*dev
= info
->user_ptr
[1];
3808 const u8
*ie
= NULL
, *bssid
;
3811 bool local_state_change
;
3813 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3816 if (!info
->attrs
[NL80211_ATTR_MAC
])
3819 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3822 if (!rdev
->ops
->deauth
)
3825 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
3826 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
3829 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3831 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3832 if (reason_code
== 0) {
3833 /* Reason Code 0 is reserved */
3837 if (info
->attrs
[NL80211_ATTR_IE
]) {
3838 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3839 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3842 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
3844 return cfg80211_mlme_deauth(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
3845 local_state_change
);
3848 static int nl80211_disassociate(struct sk_buff
*skb
, struct genl_info
*info
)
3850 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3851 struct net_device
*dev
= info
->user_ptr
[1];
3852 const u8
*ie
= NULL
, *bssid
;
3855 bool local_state_change
;
3857 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3860 if (!info
->attrs
[NL80211_ATTR_MAC
])
3863 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
3866 if (!rdev
->ops
->disassoc
)
3869 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
3870 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
3873 bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3875 reason_code
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
3876 if (reason_code
== 0) {
3877 /* Reason Code 0 is reserved */
3881 if (info
->attrs
[NL80211_ATTR_IE
]) {
3882 ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3883 ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3886 local_state_change
= !!info
->attrs
[NL80211_ATTR_LOCAL_STATE_CHANGE
];
3888 return cfg80211_mlme_disassoc(rdev
, dev
, bssid
, ie
, ie_len
, reason_code
,
3889 local_state_change
);
3893 nl80211_parse_mcast_rate(struct cfg80211_registered_device
*rdev
,
3894 int mcast_rate
[IEEE80211_NUM_BANDS
],
3897 struct wiphy
*wiphy
= &rdev
->wiphy
;
3901 for (band
= 0; band
< IEEE80211_NUM_BANDS
; band
++) {
3902 struct ieee80211_supported_band
*sband
;
3904 sband
= wiphy
->bands
[band
];
3908 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
3909 if (sband
->bitrates
[i
].bitrate
== rateval
) {
3910 mcast_rate
[band
] = i
+ 1;
3920 static int nl80211_join_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
3922 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
3923 struct net_device
*dev
= info
->user_ptr
[1];
3924 struct cfg80211_ibss_params ibss
;
3925 struct wiphy
*wiphy
;
3926 struct cfg80211_cached_keys
*connkeys
= NULL
;
3929 memset(&ibss
, 0, sizeof(ibss
));
3931 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
3934 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
3935 !info
->attrs
[NL80211_ATTR_SSID
] ||
3936 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
3939 ibss
.beacon_interval
= 100;
3941 if (info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]) {
3942 ibss
.beacon_interval
=
3943 nla_get_u32(info
->attrs
[NL80211_ATTR_BEACON_INTERVAL
]);
3944 if (ibss
.beacon_interval
< 1 || ibss
.beacon_interval
> 10000)
3948 if (!rdev
->ops
->join_ibss
)
3951 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
3954 wiphy
= &rdev
->wiphy
;
3956 if (info
->attrs
[NL80211_ATTR_MAC
])
3957 ibss
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
3958 ibss
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
3959 ibss
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
3961 if (info
->attrs
[NL80211_ATTR_IE
]) {
3962 ibss
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
3963 ibss
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
3966 ibss
.channel
= ieee80211_get_channel(wiphy
,
3967 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
3968 if (!ibss
.channel
||
3969 ibss
.channel
->flags
& IEEE80211_CHAN_NO_IBSS
||
3970 ibss
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
3973 ibss
.channel_fixed
= !!info
->attrs
[NL80211_ATTR_FREQ_FIXED
];
3974 ibss
.privacy
= !!info
->attrs
[NL80211_ATTR_PRIVACY
];
3976 if (info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]) {
3978 nla_data(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
3980 nla_len(info
->attrs
[NL80211_ATTR_BSS_BASIC_RATES
]);
3981 struct ieee80211_supported_band
*sband
=
3982 wiphy
->bands
[ibss
.channel
->band
];
3988 for (i
= 0; i
< n_rates
; i
++) {
3989 int rate
= (rates
[i
] & 0x7f) * 5;
3992 for (j
= 0; j
< sband
->n_bitrates
; j
++) {
3993 if (sband
->bitrates
[j
].bitrate
== rate
) {
3995 ibss
.basic_rates
|= BIT(j
);
4004 if (info
->attrs
[NL80211_ATTR_MCAST_RATE
] &&
4005 !nl80211_parse_mcast_rate(rdev
, ibss
.mcast_rate
,
4006 nla_get_u32(info
->attrs
[NL80211_ATTR_MCAST_RATE
])))
4009 if (ibss
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
4010 connkeys
= nl80211_parse_connkeys(rdev
,
4011 info
->attrs
[NL80211_ATTR_KEYS
]);
4012 if (IS_ERR(connkeys
))
4013 return PTR_ERR(connkeys
);
4016 err
= cfg80211_join_ibss(rdev
, dev
, &ibss
, connkeys
);
4022 static int nl80211_leave_ibss(struct sk_buff
*skb
, struct genl_info
*info
)
4024 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4025 struct net_device
*dev
= info
->user_ptr
[1];
4027 if (!rdev
->ops
->leave_ibss
)
4030 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
)
4033 return cfg80211_leave_ibss(rdev
, dev
, false);
4036 #ifdef CONFIG_NL80211_TESTMODE
4037 static struct genl_multicast_group nl80211_testmode_mcgrp
= {
4041 static int nl80211_testmode_do(struct sk_buff
*skb
, struct genl_info
*info
)
4043 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4046 if (!info
->attrs
[NL80211_ATTR_TESTDATA
])
4050 if (rdev
->ops
->testmode_cmd
) {
4051 rdev
->testmode_info
= info
;
4052 err
= rdev
->ops
->testmode_cmd(&rdev
->wiphy
,
4053 nla_data(info
->attrs
[NL80211_ATTR_TESTDATA
]),
4054 nla_len(info
->attrs
[NL80211_ATTR_TESTDATA
]));
4055 rdev
->testmode_info
= NULL
;
4061 static struct sk_buff
*
4062 __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device
*rdev
,
4063 int approxlen
, u32 pid
, u32 seq
, gfp_t gfp
)
4065 struct sk_buff
*skb
;
4067 struct nlattr
*data
;
4069 skb
= nlmsg_new(approxlen
+ 100, gfp
);
4073 hdr
= nl80211hdr_put(skb
, pid
, seq
, 0, NL80211_CMD_TESTMODE
);
4079 NLA_PUT_U32(skb
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
4080 data
= nla_nest_start(skb
, NL80211_ATTR_TESTDATA
);
4082 ((void **)skb
->cb
)[0] = rdev
;
4083 ((void **)skb
->cb
)[1] = hdr
;
4084 ((void **)skb
->cb
)[2] = data
;
4093 struct sk_buff
*cfg80211_testmode_alloc_reply_skb(struct wiphy
*wiphy
,
4096 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4098 if (WARN_ON(!rdev
->testmode_info
))
4101 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
,
4102 rdev
->testmode_info
->snd_pid
,
4103 rdev
->testmode_info
->snd_seq
,
4106 EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb
);
4108 int cfg80211_testmode_reply(struct sk_buff
*skb
)
4110 struct cfg80211_registered_device
*rdev
= ((void **)skb
->cb
)[0];
4111 void *hdr
= ((void **)skb
->cb
)[1];
4112 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4114 if (WARN_ON(!rdev
->testmode_info
)) {
4119 nla_nest_end(skb
, data
);
4120 genlmsg_end(skb
, hdr
);
4121 return genlmsg_reply(skb
, rdev
->testmode_info
);
4123 EXPORT_SYMBOL(cfg80211_testmode_reply
);
4125 struct sk_buff
*cfg80211_testmode_alloc_event_skb(struct wiphy
*wiphy
,
4126 int approxlen
, gfp_t gfp
)
4128 struct cfg80211_registered_device
*rdev
= wiphy_to_dev(wiphy
);
4130 return __cfg80211_testmode_alloc_skb(rdev
, approxlen
, 0, 0, gfp
);
4132 EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb
);
4134 void cfg80211_testmode_event(struct sk_buff
*skb
, gfp_t gfp
)
4136 void *hdr
= ((void **)skb
->cb
)[1];
4137 struct nlattr
*data
= ((void **)skb
->cb
)[2];
4139 nla_nest_end(skb
, data
);
4140 genlmsg_end(skb
, hdr
);
4141 genlmsg_multicast(skb
, 0, nl80211_testmode_mcgrp
.id
, gfp
);
4143 EXPORT_SYMBOL(cfg80211_testmode_event
);
4146 static int nl80211_connect(struct sk_buff
*skb
, struct genl_info
*info
)
4148 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4149 struct net_device
*dev
= info
->user_ptr
[1];
4150 struct cfg80211_connect_params connect
;
4151 struct wiphy
*wiphy
;
4152 struct cfg80211_cached_keys
*connkeys
= NULL
;
4155 memset(&connect
, 0, sizeof(connect
));
4157 if (!is_valid_ie_attr(info
->attrs
[NL80211_ATTR_IE
]))
4160 if (!info
->attrs
[NL80211_ATTR_SSID
] ||
4161 !nla_len(info
->attrs
[NL80211_ATTR_SSID
]))
4164 if (info
->attrs
[NL80211_ATTR_AUTH_TYPE
]) {
4166 nla_get_u32(info
->attrs
[NL80211_ATTR_AUTH_TYPE
]);
4167 if (!nl80211_valid_auth_type(connect
.auth_type
))
4170 connect
.auth_type
= NL80211_AUTHTYPE_AUTOMATIC
;
4172 connect
.privacy
= info
->attrs
[NL80211_ATTR_PRIVACY
];
4174 err
= nl80211_crypto_settings(rdev
, info
, &connect
.crypto
,
4175 NL80211_MAX_NR_CIPHER_SUITES
);
4179 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4180 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4183 wiphy
= &rdev
->wiphy
;
4185 if (info
->attrs
[NL80211_ATTR_MAC
])
4186 connect
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4187 connect
.ssid
= nla_data(info
->attrs
[NL80211_ATTR_SSID
]);
4188 connect
.ssid_len
= nla_len(info
->attrs
[NL80211_ATTR_SSID
]);
4190 if (info
->attrs
[NL80211_ATTR_IE
]) {
4191 connect
.ie
= nla_data(info
->attrs
[NL80211_ATTR_IE
]);
4192 connect
.ie_len
= nla_len(info
->attrs
[NL80211_ATTR_IE
]);
4195 if (info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]) {
4197 ieee80211_get_channel(wiphy
,
4198 nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]));
4199 if (!connect
.channel
||
4200 connect
.channel
->flags
& IEEE80211_CHAN_DISABLED
)
4204 if (connect
.privacy
&& info
->attrs
[NL80211_ATTR_KEYS
]) {
4205 connkeys
= nl80211_parse_connkeys(rdev
,
4206 info
->attrs
[NL80211_ATTR_KEYS
]);
4207 if (IS_ERR(connkeys
))
4208 return PTR_ERR(connkeys
);
4211 err
= cfg80211_connect(rdev
, dev
, &connect
, connkeys
);
4217 static int nl80211_disconnect(struct sk_buff
*skb
, struct genl_info
*info
)
4219 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4220 struct net_device
*dev
= info
->user_ptr
[1];
4223 if (!info
->attrs
[NL80211_ATTR_REASON_CODE
])
4224 reason
= WLAN_REASON_DEAUTH_LEAVING
;
4226 reason
= nla_get_u16(info
->attrs
[NL80211_ATTR_REASON_CODE
]);
4231 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4232 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4235 return cfg80211_disconnect(rdev
, dev
, reason
, true);
4238 static int nl80211_wiphy_netns(struct sk_buff
*skb
, struct genl_info
*info
)
4240 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4245 if (!info
->attrs
[NL80211_ATTR_PID
])
4248 pid
= nla_get_u32(info
->attrs
[NL80211_ATTR_PID
]);
4250 net
= get_net_ns_by_pid(pid
);
4252 return PTR_ERR(net
);
4256 /* check if anything to do */
4257 if (!net_eq(wiphy_net(&rdev
->wiphy
), net
))
4258 err
= cfg80211_switch_netns(rdev
, net
);
4264 static int nl80211_setdel_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4266 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4267 int (*rdev_ops
)(struct wiphy
*wiphy
, struct net_device
*dev
,
4268 struct cfg80211_pmksa
*pmksa
) = NULL
;
4269 struct net_device
*dev
= info
->user_ptr
[1];
4270 struct cfg80211_pmksa pmksa
;
4272 memset(&pmksa
, 0, sizeof(struct cfg80211_pmksa
));
4274 if (!info
->attrs
[NL80211_ATTR_MAC
])
4277 if (!info
->attrs
[NL80211_ATTR_PMKID
])
4280 pmksa
.pmkid
= nla_data(info
->attrs
[NL80211_ATTR_PMKID
]);
4281 pmksa
.bssid
= nla_data(info
->attrs
[NL80211_ATTR_MAC
]);
4283 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4284 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4287 switch (info
->genlhdr
->cmd
) {
4288 case NL80211_CMD_SET_PMKSA
:
4289 rdev_ops
= rdev
->ops
->set_pmksa
;
4291 case NL80211_CMD_DEL_PMKSA
:
4292 rdev_ops
= rdev
->ops
->del_pmksa
;
4302 return rdev_ops(&rdev
->wiphy
, dev
, &pmksa
);
4305 static int nl80211_flush_pmksa(struct sk_buff
*skb
, struct genl_info
*info
)
4307 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4308 struct net_device
*dev
= info
->user_ptr
[1];
4310 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4311 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4314 if (!rdev
->ops
->flush_pmksa
)
4317 return rdev
->ops
->flush_pmksa(&rdev
->wiphy
, dev
);
4320 static int nl80211_remain_on_channel(struct sk_buff
*skb
,
4321 struct genl_info
*info
)
4323 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4324 struct net_device
*dev
= info
->user_ptr
[1];
4325 struct ieee80211_channel
*chan
;
4326 struct sk_buff
*msg
;
4329 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
4333 if (!info
->attrs
[NL80211_ATTR_WIPHY_FREQ
] ||
4334 !info
->attrs
[NL80211_ATTR_DURATION
])
4337 duration
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
4340 * We should be on that channel for at least one jiffie,
4341 * and more than 5 seconds seems excessive.
4343 if (!duration
|| !msecs_to_jiffies(duration
) ||
4344 duration
> rdev
->wiphy
.max_remain_on_channel_duration
)
4347 if (!rdev
->ops
->remain_on_channel
)
4350 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
4351 channel_type
= nla_get_u32(
4352 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
4353 if (channel_type
!= NL80211_CHAN_NO_HT
&&
4354 channel_type
!= NL80211_CHAN_HT20
&&
4355 channel_type
!= NL80211_CHAN_HT40PLUS
&&
4356 channel_type
!= NL80211_CHAN_HT40MINUS
)
4360 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
4361 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
4365 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4369 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4370 NL80211_CMD_REMAIN_ON_CHANNEL
);
4377 err
= rdev
->ops
->remain_on_channel(&rdev
->wiphy
, dev
, chan
,
4378 channel_type
, duration
, &cookie
);
4383 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
4385 genlmsg_end(msg
, hdr
);
4387 return genlmsg_reply(msg
, info
);
4396 static int nl80211_cancel_remain_on_channel(struct sk_buff
*skb
,
4397 struct genl_info
*info
)
4399 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4400 struct net_device
*dev
= info
->user_ptr
[1];
4403 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
4406 if (!rdev
->ops
->cancel_remain_on_channel
)
4409 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
4411 return rdev
->ops
->cancel_remain_on_channel(&rdev
->wiphy
, dev
, cookie
);
4414 static u32
rateset_to_mask(struct ieee80211_supported_band
*sband
,
4415 u8
*rates
, u8 rates_len
)
4420 for (i
= 0; i
< rates_len
; i
++) {
4421 int rate
= (rates
[i
] & 0x7f) * 5;
4423 for (ridx
= 0; ridx
< sband
->n_bitrates
; ridx
++) {
4424 struct ieee80211_rate
*srate
=
4425 &sband
->bitrates
[ridx
];
4426 if (rate
== srate
->bitrate
) {
4431 if (ridx
== sband
->n_bitrates
)
4432 return 0; /* rate not found */
4438 static const struct nla_policy nl80211_txattr_policy
[NL80211_TXRATE_MAX
+ 1] = {
4439 [NL80211_TXRATE_LEGACY
] = { .type
= NLA_BINARY
,
4440 .len
= NL80211_MAX_SUPP_RATES
},
4443 static int nl80211_set_tx_bitrate_mask(struct sk_buff
*skb
,
4444 struct genl_info
*info
)
4446 struct nlattr
*tb
[NL80211_TXRATE_MAX
+ 1];
4447 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4448 struct cfg80211_bitrate_mask mask
;
4450 struct net_device
*dev
= info
->user_ptr
[1];
4451 struct nlattr
*tx_rates
;
4452 struct ieee80211_supported_band
*sband
;
4454 if (info
->attrs
[NL80211_ATTR_TX_RATES
] == NULL
)
4457 if (!rdev
->ops
->set_bitrate_mask
)
4460 memset(&mask
, 0, sizeof(mask
));
4461 /* Default to all rates enabled */
4462 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++) {
4463 sband
= rdev
->wiphy
.bands
[i
];
4464 mask
.control
[i
].legacy
=
4465 sband
? (1 << sband
->n_bitrates
) - 1 : 0;
4469 * The nested attribute uses enum nl80211_band as the index. This maps
4470 * directly to the enum ieee80211_band values used in cfg80211.
4472 nla_for_each_nested(tx_rates
, info
->attrs
[NL80211_ATTR_TX_RATES
], rem
)
4474 enum ieee80211_band band
= nla_type(tx_rates
);
4475 if (band
< 0 || band
>= IEEE80211_NUM_BANDS
)
4477 sband
= rdev
->wiphy
.bands
[band
];
4480 nla_parse(tb
, NL80211_TXRATE_MAX
, nla_data(tx_rates
),
4481 nla_len(tx_rates
), nl80211_txattr_policy
);
4482 if (tb
[NL80211_TXRATE_LEGACY
]) {
4483 mask
.control
[band
].legacy
= rateset_to_mask(
4485 nla_data(tb
[NL80211_TXRATE_LEGACY
]),
4486 nla_len(tb
[NL80211_TXRATE_LEGACY
]));
4487 if (mask
.control
[band
].legacy
== 0)
4492 return rdev
->ops
->set_bitrate_mask(&rdev
->wiphy
, dev
, NULL
, &mask
);
4495 static int nl80211_register_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
4497 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4498 struct net_device
*dev
= info
->user_ptr
[1];
4499 u16 frame_type
= IEEE80211_FTYPE_MGMT
| IEEE80211_STYPE_ACTION
;
4501 if (!info
->attrs
[NL80211_ATTR_FRAME_MATCH
])
4504 if (info
->attrs
[NL80211_ATTR_FRAME_TYPE
])
4505 frame_type
= nla_get_u16(info
->attrs
[NL80211_ATTR_FRAME_TYPE
]);
4507 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4508 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
4509 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
4510 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4511 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4512 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
4513 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4516 /* not much point in registering if we can't reply */
4517 if (!rdev
->ops
->mgmt_tx
)
4520 return cfg80211_mlme_register_mgmt(dev
->ieee80211_ptr
, info
->snd_pid
,
4522 nla_data(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]),
4523 nla_len(info
->attrs
[NL80211_ATTR_FRAME_MATCH
]));
4526 static int nl80211_tx_mgmt(struct sk_buff
*skb
, struct genl_info
*info
)
4528 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4529 struct net_device
*dev
= info
->user_ptr
[1];
4530 struct ieee80211_channel
*chan
;
4531 enum nl80211_channel_type channel_type
= NL80211_CHAN_NO_HT
;
4532 bool channel_type_valid
= false;
4537 struct sk_buff
*msg
;
4538 unsigned int wait
= 0;
4541 if (!info
->attrs
[NL80211_ATTR_FRAME
] ||
4542 !info
->attrs
[NL80211_ATTR_WIPHY_FREQ
])
4545 if (!rdev
->ops
->mgmt_tx
)
4548 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4549 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
4550 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
4551 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4552 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4553 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_MESH_POINT
&&
4554 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4557 if (info
->attrs
[NL80211_ATTR_DURATION
]) {
4558 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
4560 wait
= nla_get_u32(info
->attrs
[NL80211_ATTR_DURATION
]);
4563 if (info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]) {
4564 channel_type
= nla_get_u32(
4565 info
->attrs
[NL80211_ATTR_WIPHY_CHANNEL_TYPE
]);
4566 if (channel_type
!= NL80211_CHAN_NO_HT
&&
4567 channel_type
!= NL80211_CHAN_HT20
&&
4568 channel_type
!= NL80211_CHAN_HT40PLUS
&&
4569 channel_type
!= NL80211_CHAN_HT40MINUS
)
4571 channel_type_valid
= true;
4574 offchan
= info
->attrs
[NL80211_ATTR_OFFCHANNEL_TX_OK
];
4576 freq
= nla_get_u32(info
->attrs
[NL80211_ATTR_WIPHY_FREQ
]);
4577 chan
= rdev_freq_to_chan(rdev
, freq
, channel_type
);
4581 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4585 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4592 err
= cfg80211_mlme_mgmt_tx(rdev
, dev
, chan
, offchan
, channel_type
,
4593 channel_type_valid
, wait
,
4594 nla_data(info
->attrs
[NL80211_ATTR_FRAME
]),
4595 nla_len(info
->attrs
[NL80211_ATTR_FRAME
]),
4600 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
4602 genlmsg_end(msg
, hdr
);
4603 return genlmsg_reply(msg
, info
);
4612 static int nl80211_tx_mgmt_cancel_wait(struct sk_buff
*skb
, struct genl_info
*info
)
4614 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4615 struct net_device
*dev
= info
->user_ptr
[1];
4618 if (!info
->attrs
[NL80211_ATTR_COOKIE
])
4621 if (!rdev
->ops
->mgmt_tx_cancel_wait
)
4624 if (dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_STATION
&&
4625 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_ADHOC
&&
4626 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
&&
4627 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP
&&
4628 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_AP_VLAN
&&
4629 dev
->ieee80211_ptr
->iftype
!= NL80211_IFTYPE_P2P_GO
)
4632 cookie
= nla_get_u64(info
->attrs
[NL80211_ATTR_COOKIE
]);
4634 return rdev
->ops
->mgmt_tx_cancel_wait(&rdev
->wiphy
, dev
, cookie
);
4637 static int nl80211_set_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
4639 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4640 struct wireless_dev
*wdev
;
4641 struct net_device
*dev
= info
->user_ptr
[1];
4646 if (!info
->attrs
[NL80211_ATTR_PS_STATE
])
4649 ps_state
= nla_get_u32(info
->attrs
[NL80211_ATTR_PS_STATE
]);
4651 if (ps_state
!= NL80211_PS_DISABLED
&& ps_state
!= NL80211_PS_ENABLED
)
4654 wdev
= dev
->ieee80211_ptr
;
4656 if (!rdev
->ops
->set_power_mgmt
)
4659 state
= (ps_state
== NL80211_PS_ENABLED
) ? true : false;
4661 if (state
== wdev
->ps
)
4664 err
= rdev
->ops
->set_power_mgmt(wdev
->wiphy
, dev
, state
,
4671 static int nl80211_get_power_save(struct sk_buff
*skb
, struct genl_info
*info
)
4673 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4674 enum nl80211_ps_state ps_state
;
4675 struct wireless_dev
*wdev
;
4676 struct net_device
*dev
= info
->user_ptr
[1];
4677 struct sk_buff
*msg
;
4681 wdev
= dev
->ieee80211_ptr
;
4683 if (!rdev
->ops
->set_power_mgmt
)
4686 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
4690 hdr
= nl80211hdr_put(msg
, info
->snd_pid
, info
->snd_seq
, 0,
4691 NL80211_CMD_GET_POWER_SAVE
);
4698 ps_state
= NL80211_PS_ENABLED
;
4700 ps_state
= NL80211_PS_DISABLED
;
4702 NLA_PUT_U32(msg
, NL80211_ATTR_PS_STATE
, ps_state
);
4704 genlmsg_end(msg
, hdr
);
4705 return genlmsg_reply(msg
, info
);
4714 static struct nla_policy
4715 nl80211_attr_cqm_policy
[NL80211_ATTR_CQM_MAX
+ 1] __read_mostly
= {
4716 [NL80211_ATTR_CQM_RSSI_THOLD
] = { .type
= NLA_U32
},
4717 [NL80211_ATTR_CQM_RSSI_HYST
] = { .type
= NLA_U32
},
4718 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
] = { .type
= NLA_U32
},
4721 static int nl80211_set_cqm_rssi(struct genl_info
*info
,
4722 s32 threshold
, u32 hysteresis
)
4724 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4725 struct wireless_dev
*wdev
;
4726 struct net_device
*dev
= info
->user_ptr
[1];
4731 wdev
= dev
->ieee80211_ptr
;
4733 if (!rdev
->ops
->set_cqm_rssi_config
)
4736 if (wdev
->iftype
!= NL80211_IFTYPE_STATION
&&
4737 wdev
->iftype
!= NL80211_IFTYPE_P2P_CLIENT
)
4740 return rdev
->ops
->set_cqm_rssi_config(wdev
->wiphy
, dev
,
4741 threshold
, hysteresis
);
4744 static int nl80211_set_cqm(struct sk_buff
*skb
, struct genl_info
*info
)
4746 struct nlattr
*attrs
[NL80211_ATTR_CQM_MAX
+ 1];
4750 cqm
= info
->attrs
[NL80211_ATTR_CQM
];
4756 err
= nla_parse_nested(attrs
, NL80211_ATTR_CQM_MAX
, cqm
,
4757 nl80211_attr_cqm_policy
);
4761 if (attrs
[NL80211_ATTR_CQM_RSSI_THOLD
] &&
4762 attrs
[NL80211_ATTR_CQM_RSSI_HYST
]) {
4765 threshold
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_THOLD
]);
4766 hysteresis
= nla_get_u32(attrs
[NL80211_ATTR_CQM_RSSI_HYST
]);
4767 err
= nl80211_set_cqm_rssi(info
, threshold
, hysteresis
);
4775 static int nl80211_join_mesh(struct sk_buff
*skb
, struct genl_info
*info
)
4777 struct cfg80211_registered_device
*rdev
= info
->user_ptr
[0];
4778 struct net_device
*dev
= info
->user_ptr
[1];
4779 struct mesh_config cfg
;
4780 struct mesh_setup setup
;
4783 /* start with default */
4784 memcpy(&cfg
, &default_mesh_config
, sizeof(cfg
));
4785 memcpy(&setup
, &default_mesh_setup
, sizeof(setup
));
4787 if (info
->attrs
[NL80211_ATTR_MESH_CONFIG
]) {
4788 /* and parse parameters if given */
4789 err
= nl80211_parse_mesh_config(info
, &cfg
, NULL
);
4794 if (!info
->attrs
[NL80211_ATTR_MESH_ID
] ||
4795 !nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]))
4798 setup
.mesh_id
= nla_data(info
->attrs
[NL80211_ATTR_MESH_ID
]);
4799 setup
.mesh_id_len
= nla_len(info
->attrs
[NL80211_ATTR_MESH_ID
]);
4801 if (info
->attrs
[NL80211_ATTR_MESH_SETUP
]) {
4802 /* parse additional setup parameters if given */
4803 err
= nl80211_parse_mesh_setup(info
, &setup
);
4808 return cfg80211_join_mesh(rdev
, dev
, &setup
, &cfg
);
4811 static int nl80211_leave_mesh(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];
4816 return cfg80211_leave_mesh(rdev
, dev
);
4819 #define NL80211_FLAG_NEED_WIPHY 0x01
4820 #define NL80211_FLAG_NEED_NETDEV 0x02
4821 #define NL80211_FLAG_NEED_RTNL 0x04
4822 #define NL80211_FLAG_CHECK_NETDEV_UP 0x08
4823 #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
4824 NL80211_FLAG_CHECK_NETDEV_UP)
4826 static int nl80211_pre_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
4827 struct genl_info
*info
)
4829 struct cfg80211_registered_device
*rdev
;
4830 struct net_device
*dev
;
4832 bool rtnl
= ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
;
4837 if (ops
->internal_flags
& NL80211_FLAG_NEED_WIPHY
) {
4838 rdev
= cfg80211_get_dev_from_info(info
);
4842 return PTR_ERR(rdev
);
4844 info
->user_ptr
[0] = rdev
;
4845 } else if (ops
->internal_flags
& NL80211_FLAG_NEED_NETDEV
) {
4846 err
= get_rdev_dev_by_info_ifindex(info
, &rdev
, &dev
);
4852 if (ops
->internal_flags
& NL80211_FLAG_CHECK_NETDEV_UP
&&
4853 !netif_running(dev
)) {
4854 cfg80211_unlock_rdev(rdev
);
4860 info
->user_ptr
[0] = rdev
;
4861 info
->user_ptr
[1] = dev
;
4867 static void nl80211_post_doit(struct genl_ops
*ops
, struct sk_buff
*skb
,
4868 struct genl_info
*info
)
4870 if (info
->user_ptr
[0])
4871 cfg80211_unlock_rdev(info
->user_ptr
[0]);
4872 if (info
->user_ptr
[1])
4873 dev_put(info
->user_ptr
[1]);
4874 if (ops
->internal_flags
& NL80211_FLAG_NEED_RTNL
)
4878 static struct genl_ops nl80211_ops
[] = {
4880 .cmd
= NL80211_CMD_GET_WIPHY
,
4881 .doit
= nl80211_get_wiphy
,
4882 .dumpit
= nl80211_dump_wiphy
,
4883 .policy
= nl80211_policy
,
4884 /* can be retrieved by unprivileged users */
4885 .internal_flags
= NL80211_FLAG_NEED_WIPHY
,
4888 .cmd
= NL80211_CMD_SET_WIPHY
,
4889 .doit
= nl80211_set_wiphy
,
4890 .policy
= nl80211_policy
,
4891 .flags
= GENL_ADMIN_PERM
,
4892 .internal_flags
= NL80211_FLAG_NEED_RTNL
,
4895 .cmd
= NL80211_CMD_GET_INTERFACE
,
4896 .doit
= nl80211_get_interface
,
4897 .dumpit
= nl80211_dump_interface
,
4898 .policy
= nl80211_policy
,
4899 /* can be retrieved by unprivileged users */
4900 .internal_flags
= NL80211_FLAG_NEED_NETDEV
,
4903 .cmd
= NL80211_CMD_SET_INTERFACE
,
4904 .doit
= nl80211_set_interface
,
4905 .policy
= nl80211_policy
,
4906 .flags
= GENL_ADMIN_PERM
,
4907 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
4908 NL80211_FLAG_NEED_RTNL
,
4911 .cmd
= NL80211_CMD_NEW_INTERFACE
,
4912 .doit
= nl80211_new_interface
,
4913 .policy
= nl80211_policy
,
4914 .flags
= GENL_ADMIN_PERM
,
4915 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
4916 NL80211_FLAG_NEED_RTNL
,
4919 .cmd
= NL80211_CMD_DEL_INTERFACE
,
4920 .doit
= nl80211_del_interface
,
4921 .policy
= nl80211_policy
,
4922 .flags
= GENL_ADMIN_PERM
,
4923 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
4924 NL80211_FLAG_NEED_RTNL
,
4927 .cmd
= NL80211_CMD_GET_KEY
,
4928 .doit
= nl80211_get_key
,
4929 .policy
= nl80211_policy
,
4930 .flags
= GENL_ADMIN_PERM
,
4931 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
4932 NL80211_FLAG_NEED_RTNL
,
4935 .cmd
= NL80211_CMD_SET_KEY
,
4936 .doit
= nl80211_set_key
,
4937 .policy
= nl80211_policy
,
4938 .flags
= GENL_ADMIN_PERM
,
4939 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
4940 NL80211_FLAG_NEED_RTNL
,
4943 .cmd
= NL80211_CMD_NEW_KEY
,
4944 .doit
= nl80211_new_key
,
4945 .policy
= nl80211_policy
,
4946 .flags
= GENL_ADMIN_PERM
,
4947 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
4948 NL80211_FLAG_NEED_RTNL
,
4951 .cmd
= NL80211_CMD_DEL_KEY
,
4952 .doit
= nl80211_del_key
,
4953 .policy
= nl80211_policy
,
4954 .flags
= GENL_ADMIN_PERM
,
4955 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
4956 NL80211_FLAG_NEED_RTNL
,
4959 .cmd
= NL80211_CMD_SET_BEACON
,
4960 .policy
= nl80211_policy
,
4961 .flags
= GENL_ADMIN_PERM
,
4962 .doit
= nl80211_addset_beacon
,
4963 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
4964 NL80211_FLAG_NEED_RTNL
,
4967 .cmd
= NL80211_CMD_NEW_BEACON
,
4968 .policy
= nl80211_policy
,
4969 .flags
= GENL_ADMIN_PERM
,
4970 .doit
= nl80211_addset_beacon
,
4971 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
4972 NL80211_FLAG_NEED_RTNL
,
4975 .cmd
= NL80211_CMD_DEL_BEACON
,
4976 .policy
= nl80211_policy
,
4977 .flags
= GENL_ADMIN_PERM
,
4978 .doit
= nl80211_del_beacon
,
4979 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
4980 NL80211_FLAG_NEED_RTNL
,
4983 .cmd
= NL80211_CMD_GET_STATION
,
4984 .doit
= nl80211_get_station
,
4985 .dumpit
= nl80211_dump_station
,
4986 .policy
= nl80211_policy
,
4987 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
4988 NL80211_FLAG_NEED_RTNL
,
4991 .cmd
= NL80211_CMD_SET_STATION
,
4992 .doit
= nl80211_set_station
,
4993 .policy
= nl80211_policy
,
4994 .flags
= GENL_ADMIN_PERM
,
4995 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
4996 NL80211_FLAG_NEED_RTNL
,
4999 .cmd
= NL80211_CMD_NEW_STATION
,
5000 .doit
= nl80211_new_station
,
5001 .policy
= nl80211_policy
,
5002 .flags
= GENL_ADMIN_PERM
,
5003 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5004 NL80211_FLAG_NEED_RTNL
,
5007 .cmd
= NL80211_CMD_DEL_STATION
,
5008 .doit
= nl80211_del_station
,
5009 .policy
= nl80211_policy
,
5010 .flags
= GENL_ADMIN_PERM
,
5011 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5012 NL80211_FLAG_NEED_RTNL
,
5015 .cmd
= NL80211_CMD_GET_MPATH
,
5016 .doit
= nl80211_get_mpath
,
5017 .dumpit
= nl80211_dump_mpath
,
5018 .policy
= nl80211_policy
,
5019 .flags
= GENL_ADMIN_PERM
,
5020 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5021 NL80211_FLAG_NEED_RTNL
,
5024 .cmd
= NL80211_CMD_SET_MPATH
,
5025 .doit
= nl80211_set_mpath
,
5026 .policy
= nl80211_policy
,
5027 .flags
= GENL_ADMIN_PERM
,
5028 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5029 NL80211_FLAG_NEED_RTNL
,
5032 .cmd
= NL80211_CMD_NEW_MPATH
,
5033 .doit
= nl80211_new_mpath
,
5034 .policy
= nl80211_policy
,
5035 .flags
= GENL_ADMIN_PERM
,
5036 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5037 NL80211_FLAG_NEED_RTNL
,
5040 .cmd
= NL80211_CMD_DEL_MPATH
,
5041 .doit
= nl80211_del_mpath
,
5042 .policy
= nl80211_policy
,
5043 .flags
= GENL_ADMIN_PERM
,
5044 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5045 NL80211_FLAG_NEED_RTNL
,
5048 .cmd
= NL80211_CMD_SET_BSS
,
5049 .doit
= nl80211_set_bss
,
5050 .policy
= nl80211_policy
,
5051 .flags
= GENL_ADMIN_PERM
,
5052 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5053 NL80211_FLAG_NEED_RTNL
,
5056 .cmd
= NL80211_CMD_GET_REG
,
5057 .doit
= nl80211_get_reg
,
5058 .policy
= nl80211_policy
,
5059 /* can be retrieved by unprivileged users */
5062 .cmd
= NL80211_CMD_SET_REG
,
5063 .doit
= nl80211_set_reg
,
5064 .policy
= nl80211_policy
,
5065 .flags
= GENL_ADMIN_PERM
,
5068 .cmd
= NL80211_CMD_REQ_SET_REG
,
5069 .doit
= nl80211_req_set_reg
,
5070 .policy
= nl80211_policy
,
5071 .flags
= GENL_ADMIN_PERM
,
5074 .cmd
= NL80211_CMD_GET_MESH_CONFIG
,
5075 .doit
= nl80211_get_mesh_config
,
5076 .policy
= nl80211_policy
,
5077 /* can be retrieved by unprivileged users */
5078 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5079 NL80211_FLAG_NEED_RTNL
,
5082 .cmd
= NL80211_CMD_SET_MESH_CONFIG
,
5083 .doit
= nl80211_update_mesh_config
,
5084 .policy
= nl80211_policy
,
5085 .flags
= GENL_ADMIN_PERM
,
5086 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5087 NL80211_FLAG_NEED_RTNL
,
5090 .cmd
= NL80211_CMD_TRIGGER_SCAN
,
5091 .doit
= nl80211_trigger_scan
,
5092 .policy
= nl80211_policy
,
5093 .flags
= GENL_ADMIN_PERM
,
5094 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5095 NL80211_FLAG_NEED_RTNL
,
5098 .cmd
= NL80211_CMD_GET_SCAN
,
5099 .policy
= nl80211_policy
,
5100 .dumpit
= nl80211_dump_scan
,
5103 .cmd
= NL80211_CMD_AUTHENTICATE
,
5104 .doit
= nl80211_authenticate
,
5105 .policy
= nl80211_policy
,
5106 .flags
= GENL_ADMIN_PERM
,
5107 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5108 NL80211_FLAG_NEED_RTNL
,
5111 .cmd
= NL80211_CMD_ASSOCIATE
,
5112 .doit
= nl80211_associate
,
5113 .policy
= nl80211_policy
,
5114 .flags
= GENL_ADMIN_PERM
,
5115 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5116 NL80211_FLAG_NEED_RTNL
,
5119 .cmd
= NL80211_CMD_DEAUTHENTICATE
,
5120 .doit
= nl80211_deauthenticate
,
5121 .policy
= nl80211_policy
,
5122 .flags
= GENL_ADMIN_PERM
,
5123 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5124 NL80211_FLAG_NEED_RTNL
,
5127 .cmd
= NL80211_CMD_DISASSOCIATE
,
5128 .doit
= nl80211_disassociate
,
5129 .policy
= nl80211_policy
,
5130 .flags
= GENL_ADMIN_PERM
,
5131 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5132 NL80211_FLAG_NEED_RTNL
,
5135 .cmd
= NL80211_CMD_JOIN_IBSS
,
5136 .doit
= nl80211_join_ibss
,
5137 .policy
= nl80211_policy
,
5138 .flags
= GENL_ADMIN_PERM
,
5139 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5140 NL80211_FLAG_NEED_RTNL
,
5143 .cmd
= NL80211_CMD_LEAVE_IBSS
,
5144 .doit
= nl80211_leave_ibss
,
5145 .policy
= nl80211_policy
,
5146 .flags
= GENL_ADMIN_PERM
,
5147 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5148 NL80211_FLAG_NEED_RTNL
,
5150 #ifdef CONFIG_NL80211_TESTMODE
5152 .cmd
= NL80211_CMD_TESTMODE
,
5153 .doit
= nl80211_testmode_do
,
5154 .policy
= nl80211_policy
,
5155 .flags
= GENL_ADMIN_PERM
,
5156 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
5157 NL80211_FLAG_NEED_RTNL
,
5161 .cmd
= NL80211_CMD_CONNECT
,
5162 .doit
= nl80211_connect
,
5163 .policy
= nl80211_policy
,
5164 .flags
= GENL_ADMIN_PERM
,
5165 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5166 NL80211_FLAG_NEED_RTNL
,
5169 .cmd
= NL80211_CMD_DISCONNECT
,
5170 .doit
= nl80211_disconnect
,
5171 .policy
= nl80211_policy
,
5172 .flags
= GENL_ADMIN_PERM
,
5173 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5174 NL80211_FLAG_NEED_RTNL
,
5177 .cmd
= NL80211_CMD_SET_WIPHY_NETNS
,
5178 .doit
= nl80211_wiphy_netns
,
5179 .policy
= nl80211_policy
,
5180 .flags
= GENL_ADMIN_PERM
,
5181 .internal_flags
= NL80211_FLAG_NEED_WIPHY
|
5182 NL80211_FLAG_NEED_RTNL
,
5185 .cmd
= NL80211_CMD_GET_SURVEY
,
5186 .policy
= nl80211_policy
,
5187 .dumpit
= nl80211_dump_survey
,
5190 .cmd
= NL80211_CMD_SET_PMKSA
,
5191 .doit
= nl80211_setdel_pmksa
,
5192 .policy
= nl80211_policy
,
5193 .flags
= GENL_ADMIN_PERM
,
5194 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5195 NL80211_FLAG_NEED_RTNL
,
5198 .cmd
= NL80211_CMD_DEL_PMKSA
,
5199 .doit
= nl80211_setdel_pmksa
,
5200 .policy
= nl80211_policy
,
5201 .flags
= GENL_ADMIN_PERM
,
5202 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5203 NL80211_FLAG_NEED_RTNL
,
5206 .cmd
= NL80211_CMD_FLUSH_PMKSA
,
5207 .doit
= nl80211_flush_pmksa
,
5208 .policy
= nl80211_policy
,
5209 .flags
= GENL_ADMIN_PERM
,
5210 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5211 NL80211_FLAG_NEED_RTNL
,
5214 .cmd
= NL80211_CMD_REMAIN_ON_CHANNEL
,
5215 .doit
= nl80211_remain_on_channel
,
5216 .policy
= nl80211_policy
,
5217 .flags
= GENL_ADMIN_PERM
,
5218 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5219 NL80211_FLAG_NEED_RTNL
,
5222 .cmd
= NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
5223 .doit
= nl80211_cancel_remain_on_channel
,
5224 .policy
= nl80211_policy
,
5225 .flags
= GENL_ADMIN_PERM
,
5226 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5227 NL80211_FLAG_NEED_RTNL
,
5230 .cmd
= NL80211_CMD_SET_TX_BITRATE_MASK
,
5231 .doit
= nl80211_set_tx_bitrate_mask
,
5232 .policy
= nl80211_policy
,
5233 .flags
= GENL_ADMIN_PERM
,
5234 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5235 NL80211_FLAG_NEED_RTNL
,
5238 .cmd
= NL80211_CMD_REGISTER_FRAME
,
5239 .doit
= nl80211_register_mgmt
,
5240 .policy
= nl80211_policy
,
5241 .flags
= GENL_ADMIN_PERM
,
5242 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5243 NL80211_FLAG_NEED_RTNL
,
5246 .cmd
= NL80211_CMD_FRAME
,
5247 .doit
= nl80211_tx_mgmt
,
5248 .policy
= nl80211_policy
,
5249 .flags
= GENL_ADMIN_PERM
,
5250 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5251 NL80211_FLAG_NEED_RTNL
,
5254 .cmd
= NL80211_CMD_FRAME_WAIT_CANCEL
,
5255 .doit
= nl80211_tx_mgmt_cancel_wait
,
5256 .policy
= nl80211_policy
,
5257 .flags
= GENL_ADMIN_PERM
,
5258 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5259 NL80211_FLAG_NEED_RTNL
,
5262 .cmd
= NL80211_CMD_SET_POWER_SAVE
,
5263 .doit
= nl80211_set_power_save
,
5264 .policy
= nl80211_policy
,
5265 .flags
= GENL_ADMIN_PERM
,
5266 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5267 NL80211_FLAG_NEED_RTNL
,
5270 .cmd
= NL80211_CMD_GET_POWER_SAVE
,
5271 .doit
= nl80211_get_power_save
,
5272 .policy
= nl80211_policy
,
5273 /* can be retrieved by unprivileged users */
5274 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5275 NL80211_FLAG_NEED_RTNL
,
5278 .cmd
= NL80211_CMD_SET_CQM
,
5279 .doit
= nl80211_set_cqm
,
5280 .policy
= nl80211_policy
,
5281 .flags
= GENL_ADMIN_PERM
,
5282 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5283 NL80211_FLAG_NEED_RTNL
,
5286 .cmd
= NL80211_CMD_SET_CHANNEL
,
5287 .doit
= nl80211_set_channel
,
5288 .policy
= nl80211_policy
,
5289 .flags
= GENL_ADMIN_PERM
,
5290 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5291 NL80211_FLAG_NEED_RTNL
,
5294 .cmd
= NL80211_CMD_SET_WDS_PEER
,
5295 .doit
= nl80211_set_wds_peer
,
5296 .policy
= nl80211_policy
,
5297 .flags
= GENL_ADMIN_PERM
,
5298 .internal_flags
= NL80211_FLAG_NEED_NETDEV
|
5299 NL80211_FLAG_NEED_RTNL
,
5302 .cmd
= NL80211_CMD_JOIN_MESH
,
5303 .doit
= nl80211_join_mesh
,
5304 .policy
= nl80211_policy
,
5305 .flags
= GENL_ADMIN_PERM
,
5306 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5307 NL80211_FLAG_NEED_RTNL
,
5310 .cmd
= NL80211_CMD_LEAVE_MESH
,
5311 .doit
= nl80211_leave_mesh
,
5312 .policy
= nl80211_policy
,
5313 .flags
= GENL_ADMIN_PERM
,
5314 .internal_flags
= NL80211_FLAG_NEED_NETDEV_UP
|
5315 NL80211_FLAG_NEED_RTNL
,
5319 static struct genl_multicast_group nl80211_mlme_mcgrp
= {
5323 /* multicast groups */
5324 static struct genl_multicast_group nl80211_config_mcgrp
= {
5327 static struct genl_multicast_group nl80211_scan_mcgrp
= {
5330 static struct genl_multicast_group nl80211_regulatory_mcgrp
= {
5331 .name
= "regulatory",
5334 /* notification functions */
5336 void nl80211_notify_dev_rename(struct cfg80211_registered_device
*rdev
)
5338 struct sk_buff
*msg
;
5340 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5344 if (nl80211_send_wiphy(msg
, 0, 0, 0, rdev
) < 0) {
5349 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5350 nl80211_config_mcgrp
.id
, GFP_KERNEL
);
5353 static int nl80211_add_scan_req(struct sk_buff
*msg
,
5354 struct cfg80211_registered_device
*rdev
)
5356 struct cfg80211_scan_request
*req
= rdev
->scan_req
;
5357 struct nlattr
*nest
;
5360 ASSERT_RDEV_LOCK(rdev
);
5365 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_SSIDS
);
5367 goto nla_put_failure
;
5368 for (i
= 0; i
< req
->n_ssids
; i
++)
5369 NLA_PUT(msg
, i
, req
->ssids
[i
].ssid_len
, req
->ssids
[i
].ssid
);
5370 nla_nest_end(msg
, nest
);
5372 nest
= nla_nest_start(msg
, NL80211_ATTR_SCAN_FREQUENCIES
);
5374 goto nla_put_failure
;
5375 for (i
= 0; i
< req
->n_channels
; i
++)
5376 NLA_PUT_U32(msg
, i
, req
->channels
[i
]->center_freq
);
5377 nla_nest_end(msg
, nest
);
5380 NLA_PUT(msg
, NL80211_ATTR_IE
, req
->ie_len
, req
->ie
);
5387 static int nl80211_send_scan_msg(struct sk_buff
*msg
,
5388 struct cfg80211_registered_device
*rdev
,
5389 struct net_device
*netdev
,
5390 u32 pid
, u32 seq
, int flags
,
5395 hdr
= nl80211hdr_put(msg
, pid
, seq
, flags
, cmd
);
5399 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5400 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5402 /* ignore errors and send incomplete event anyway */
5403 nl80211_add_scan_req(msg
, rdev
);
5405 return genlmsg_end(msg
, hdr
);
5408 genlmsg_cancel(msg
, hdr
);
5412 void nl80211_send_scan_start(struct cfg80211_registered_device
*rdev
,
5413 struct net_device
*netdev
)
5415 struct sk_buff
*msg
;
5417 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
5421 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5422 NL80211_CMD_TRIGGER_SCAN
) < 0) {
5427 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5428 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5431 void nl80211_send_scan_done(struct cfg80211_registered_device
*rdev
,
5432 struct net_device
*netdev
)
5434 struct sk_buff
*msg
;
5436 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5440 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5441 NL80211_CMD_NEW_SCAN_RESULTS
) < 0) {
5446 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5447 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5450 void nl80211_send_scan_aborted(struct cfg80211_registered_device
*rdev
,
5451 struct net_device
*netdev
)
5453 struct sk_buff
*msg
;
5455 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5459 if (nl80211_send_scan_msg(msg
, rdev
, netdev
, 0, 0, 0,
5460 NL80211_CMD_SCAN_ABORTED
) < 0) {
5465 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5466 nl80211_scan_mcgrp
.id
, GFP_KERNEL
);
5470 * This can happen on global regulatory changes or device specific settings
5471 * based on custom world regulatory domains.
5473 void nl80211_send_reg_change_event(struct regulatory_request
*request
)
5475 struct sk_buff
*msg
;
5478 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
5482 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_CHANGE
);
5488 /* Userspace can always count this one always being set */
5489 NLA_PUT_U8(msg
, NL80211_ATTR_REG_INITIATOR
, request
->initiator
);
5491 if (request
->alpha2
[0] == '0' && request
->alpha2
[1] == '0')
5492 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5493 NL80211_REGDOM_TYPE_WORLD
);
5494 else if (request
->alpha2
[0] == '9' && request
->alpha2
[1] == '9')
5495 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5496 NL80211_REGDOM_TYPE_CUSTOM_WORLD
);
5497 else if ((request
->alpha2
[0] == '9' && request
->alpha2
[1] == '8') ||
5499 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5500 NL80211_REGDOM_TYPE_INTERSECTION
);
5502 NLA_PUT_U8(msg
, NL80211_ATTR_REG_TYPE
,
5503 NL80211_REGDOM_TYPE_COUNTRY
);
5504 NLA_PUT_STRING(msg
, NL80211_ATTR_REG_ALPHA2
, request
->alpha2
);
5507 if (wiphy_idx_valid(request
->wiphy_idx
))
5508 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, request
->wiphy_idx
);
5510 if (genlmsg_end(msg
, hdr
) < 0) {
5516 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
5523 genlmsg_cancel(msg
, hdr
);
5527 static void nl80211_send_mlme_event(struct cfg80211_registered_device
*rdev
,
5528 struct net_device
*netdev
,
5529 const u8
*buf
, size_t len
,
5530 enum nl80211_commands cmd
, gfp_t gfp
)
5532 struct sk_buff
*msg
;
5535 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5539 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
5545 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5546 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5547 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
5549 if (genlmsg_end(msg
, hdr
) < 0) {
5554 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5555 nl80211_mlme_mcgrp
.id
, gfp
);
5559 genlmsg_cancel(msg
, hdr
);
5563 void nl80211_send_rx_auth(struct cfg80211_registered_device
*rdev
,
5564 struct net_device
*netdev
, const u8
*buf
,
5565 size_t len
, gfp_t gfp
)
5567 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5568 NL80211_CMD_AUTHENTICATE
, gfp
);
5571 void nl80211_send_rx_assoc(struct cfg80211_registered_device
*rdev
,
5572 struct net_device
*netdev
, const u8
*buf
,
5573 size_t len
, gfp_t gfp
)
5575 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5576 NL80211_CMD_ASSOCIATE
, gfp
);
5579 void nl80211_send_deauth(struct cfg80211_registered_device
*rdev
,
5580 struct net_device
*netdev
, const u8
*buf
,
5581 size_t len
, gfp_t gfp
)
5583 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5584 NL80211_CMD_DEAUTHENTICATE
, gfp
);
5587 void nl80211_send_disassoc(struct cfg80211_registered_device
*rdev
,
5588 struct net_device
*netdev
, const u8
*buf
,
5589 size_t len
, gfp_t gfp
)
5591 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5592 NL80211_CMD_DISASSOCIATE
, gfp
);
5595 void nl80211_send_unprot_deauth(struct cfg80211_registered_device
*rdev
,
5596 struct net_device
*netdev
, const u8
*buf
,
5597 size_t len
, gfp_t gfp
)
5599 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5600 NL80211_CMD_UNPROT_DEAUTHENTICATE
, gfp
);
5603 void nl80211_send_unprot_disassoc(struct cfg80211_registered_device
*rdev
,
5604 struct net_device
*netdev
, const u8
*buf
,
5605 size_t len
, gfp_t gfp
)
5607 nl80211_send_mlme_event(rdev
, netdev
, buf
, len
,
5608 NL80211_CMD_UNPROT_DISASSOCIATE
, gfp
);
5611 static void nl80211_send_mlme_timeout(struct cfg80211_registered_device
*rdev
,
5612 struct net_device
*netdev
, int cmd
,
5613 const u8
*addr
, gfp_t gfp
)
5615 struct sk_buff
*msg
;
5618 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5622 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
5628 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5629 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5630 NLA_PUT_FLAG(msg
, NL80211_ATTR_TIMED_OUT
);
5631 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5633 if (genlmsg_end(msg
, hdr
) < 0) {
5638 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5639 nl80211_mlme_mcgrp
.id
, gfp
);
5643 genlmsg_cancel(msg
, hdr
);
5647 void nl80211_send_auth_timeout(struct cfg80211_registered_device
*rdev
,
5648 struct net_device
*netdev
, const u8
*addr
,
5651 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_AUTHENTICATE
,
5655 void nl80211_send_assoc_timeout(struct cfg80211_registered_device
*rdev
,
5656 struct net_device
*netdev
, const u8
*addr
,
5659 nl80211_send_mlme_timeout(rdev
, netdev
, NL80211_CMD_ASSOCIATE
,
5663 void nl80211_send_connect_result(struct cfg80211_registered_device
*rdev
,
5664 struct net_device
*netdev
, const u8
*bssid
,
5665 const u8
*req_ie
, size_t req_ie_len
,
5666 const u8
*resp_ie
, size_t resp_ie_len
,
5667 u16 status
, gfp_t gfp
)
5669 struct sk_buff
*msg
;
5672 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
5676 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_CONNECT
);
5682 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5683 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5685 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
5686 NLA_PUT_U16(msg
, NL80211_ATTR_STATUS_CODE
, status
);
5688 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
5690 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
5692 if (genlmsg_end(msg
, hdr
) < 0) {
5697 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5698 nl80211_mlme_mcgrp
.id
, gfp
);
5702 genlmsg_cancel(msg
, hdr
);
5707 void nl80211_send_roamed(struct cfg80211_registered_device
*rdev
,
5708 struct net_device
*netdev
, const u8
*bssid
,
5709 const u8
*req_ie
, size_t req_ie_len
,
5710 const u8
*resp_ie
, size_t resp_ie_len
, gfp_t gfp
)
5712 struct sk_buff
*msg
;
5715 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
5719 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_ROAM
);
5725 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5726 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5727 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
5729 NLA_PUT(msg
, NL80211_ATTR_REQ_IE
, req_ie_len
, req_ie
);
5731 NLA_PUT(msg
, NL80211_ATTR_RESP_IE
, resp_ie_len
, resp_ie
);
5733 if (genlmsg_end(msg
, hdr
) < 0) {
5738 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5739 nl80211_mlme_mcgrp
.id
, gfp
);
5743 genlmsg_cancel(msg
, hdr
);
5748 void nl80211_send_disconnected(struct cfg80211_registered_device
*rdev
,
5749 struct net_device
*netdev
, u16 reason
,
5750 const u8
*ie
, size_t ie_len
, bool from_ap
)
5752 struct sk_buff
*msg
;
5755 msg
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
5759 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DISCONNECT
);
5765 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5766 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5767 if (from_ap
&& reason
)
5768 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason
);
5770 NLA_PUT_FLAG(msg
, NL80211_ATTR_DISCONNECTED_BY_AP
);
5772 NLA_PUT(msg
, NL80211_ATTR_IE
, ie_len
, ie
);
5774 if (genlmsg_end(msg
, hdr
) < 0) {
5779 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5780 nl80211_mlme_mcgrp
.id
, GFP_KERNEL
);
5784 genlmsg_cancel(msg
, hdr
);
5789 void nl80211_send_ibss_bssid(struct cfg80211_registered_device
*rdev
,
5790 struct net_device
*netdev
, const u8
*bssid
,
5793 struct sk_buff
*msg
;
5796 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5800 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_JOIN_IBSS
);
5806 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5807 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5808 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, bssid
);
5810 if (genlmsg_end(msg
, hdr
) < 0) {
5815 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5816 nl80211_mlme_mcgrp
.id
, gfp
);
5820 genlmsg_cancel(msg
, hdr
);
5824 void nl80211_send_new_peer_candidate(struct cfg80211_registered_device
*rdev
,
5825 struct net_device
*netdev
,
5826 const u8
*macaddr
, const u8
* ie
, u8 ie_len
,
5829 struct sk_buff
*msg
;
5832 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5836 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE
);
5842 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5843 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5844 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, macaddr
);
5846 NLA_PUT(msg
, NL80211_ATTR_IE
, ie_len
, ie
);
5848 if (genlmsg_end(msg
, hdr
) < 0) {
5853 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5854 nl80211_mlme_mcgrp
.id
, gfp
);
5858 genlmsg_cancel(msg
, hdr
);
5862 void nl80211_michael_mic_failure(struct cfg80211_registered_device
*rdev
,
5863 struct net_device
*netdev
, const u8
*addr
,
5864 enum nl80211_key_type key_type
, int key_id
,
5865 const u8
*tsc
, gfp_t gfp
)
5867 struct sk_buff
*msg
;
5870 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5874 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE
);
5880 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5881 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5883 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
5884 NLA_PUT_U32(msg
, NL80211_ATTR_KEY_TYPE
, key_type
);
5885 NLA_PUT_U8(msg
, NL80211_ATTR_KEY_IDX
, key_id
);
5887 NLA_PUT(msg
, NL80211_ATTR_KEY_SEQ
, 6, tsc
);
5889 if (genlmsg_end(msg
, hdr
) < 0) {
5894 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5895 nl80211_mlme_mcgrp
.id
, gfp
);
5899 genlmsg_cancel(msg
, hdr
);
5903 void nl80211_send_beacon_hint_event(struct wiphy
*wiphy
,
5904 struct ieee80211_channel
*channel_before
,
5905 struct ieee80211_channel
*channel_after
)
5907 struct sk_buff
*msg
;
5909 struct nlattr
*nl_freq
;
5911 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_ATOMIC
);
5915 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT
);
5922 * Since we are applying the beacon hint to a wiphy we know its
5923 * wiphy_idx is valid
5925 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, get_wiphy_idx(wiphy
));
5928 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_BEFORE
);
5930 goto nla_put_failure
;
5931 if (nl80211_msg_put_channel(msg
, channel_before
))
5932 goto nla_put_failure
;
5933 nla_nest_end(msg
, nl_freq
);
5936 nl_freq
= nla_nest_start(msg
, NL80211_ATTR_FREQ_AFTER
);
5938 goto nla_put_failure
;
5939 if (nl80211_msg_put_channel(msg
, channel_after
))
5940 goto nla_put_failure
;
5941 nla_nest_end(msg
, nl_freq
);
5943 if (genlmsg_end(msg
, hdr
) < 0) {
5949 genlmsg_multicast_allns(msg
, 0, nl80211_regulatory_mcgrp
.id
,
5956 genlmsg_cancel(msg
, hdr
);
5960 static void nl80211_send_remain_on_chan_event(
5961 int cmd
, struct cfg80211_registered_device
*rdev
,
5962 struct net_device
*netdev
, u64 cookie
,
5963 struct ieee80211_channel
*chan
,
5964 enum nl80211_channel_type channel_type
,
5965 unsigned int duration
, gfp_t gfp
)
5967 struct sk_buff
*msg
;
5970 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
5974 hdr
= nl80211hdr_put(msg
, 0, 0, 0, cmd
);
5980 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
5981 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
5982 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, chan
->center_freq
);
5983 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_CHANNEL_TYPE
, channel_type
);
5984 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
5986 if (cmd
== NL80211_CMD_REMAIN_ON_CHANNEL
)
5987 NLA_PUT_U32(msg
, NL80211_ATTR_DURATION
, duration
);
5989 if (genlmsg_end(msg
, hdr
) < 0) {
5994 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
5995 nl80211_mlme_mcgrp
.id
, gfp
);
5999 genlmsg_cancel(msg
, hdr
);
6003 void nl80211_send_remain_on_channel(struct cfg80211_registered_device
*rdev
,
6004 struct net_device
*netdev
, u64 cookie
,
6005 struct ieee80211_channel
*chan
,
6006 enum nl80211_channel_type channel_type
,
6007 unsigned int duration
, gfp_t gfp
)
6009 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL
,
6010 rdev
, netdev
, cookie
, chan
,
6011 channel_type
, duration
, gfp
);
6014 void nl80211_send_remain_on_channel_cancel(
6015 struct cfg80211_registered_device
*rdev
, struct net_device
*netdev
,
6016 u64 cookie
, struct ieee80211_channel
*chan
,
6017 enum nl80211_channel_type channel_type
, gfp_t gfp
)
6019 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
,
6020 rdev
, netdev
, cookie
, chan
,
6021 channel_type
, 0, gfp
);
6024 void nl80211_send_sta_event(struct cfg80211_registered_device
*rdev
,
6025 struct net_device
*dev
, const u8
*mac_addr
,
6026 struct station_info
*sinfo
, gfp_t gfp
)
6028 struct sk_buff
*msg
;
6030 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6034 if (nl80211_send_station(msg
, 0, 0, 0, dev
, mac_addr
, sinfo
) < 0) {
6039 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6040 nl80211_mlme_mcgrp
.id
, gfp
);
6043 void nl80211_send_sta_del_event(struct cfg80211_registered_device
*rdev
,
6044 struct net_device
*dev
, const u8
*mac_addr
,
6047 struct sk_buff
*msg
;
6050 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6054 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_DEL_STATION
);
6060 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, dev
->ifindex
);
6061 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
6063 if (genlmsg_end(msg
, hdr
) < 0) {
6068 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6069 nl80211_mlme_mcgrp
.id
, gfp
);
6073 genlmsg_cancel(msg
, hdr
);
6077 int nl80211_send_mgmt(struct cfg80211_registered_device
*rdev
,
6078 struct net_device
*netdev
, u32 nlpid
,
6079 int freq
, const u8
*buf
, size_t len
, gfp_t gfp
)
6081 struct sk_buff
*msg
;
6085 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6089 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME
);
6095 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6096 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6097 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, freq
);
6098 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
6100 err
= genlmsg_end(msg
, hdr
);
6106 err
= genlmsg_unicast(wiphy_net(&rdev
->wiphy
), msg
, nlpid
);
6112 genlmsg_cancel(msg
, hdr
);
6117 void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device
*rdev
,
6118 struct net_device
*netdev
, u64 cookie
,
6119 const u8
*buf
, size_t len
, bool ack
,
6122 struct sk_buff
*msg
;
6125 msg
= nlmsg_new(NLMSG_DEFAULT_SIZE
, gfp
);
6129 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS
);
6135 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6136 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6137 NLA_PUT(msg
, NL80211_ATTR_FRAME
, len
, buf
);
6138 NLA_PUT_U64(msg
, NL80211_ATTR_COOKIE
, cookie
);
6140 NLA_PUT_FLAG(msg
, NL80211_ATTR_ACK
);
6142 if (genlmsg_end(msg
, hdr
) < 0) {
6147 genlmsg_multicast(msg
, 0, nl80211_mlme_mcgrp
.id
, gfp
);
6151 genlmsg_cancel(msg
, hdr
);
6156 nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device
*rdev
,
6157 struct net_device
*netdev
,
6158 enum nl80211_cqm_rssi_threshold_event rssi_event
,
6161 struct sk_buff
*msg
;
6162 struct nlattr
*pinfoattr
;
6165 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6169 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
6175 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6176 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6178 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
6180 goto nla_put_failure
;
6182 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT
,
6185 nla_nest_end(msg
, pinfoattr
);
6187 if (genlmsg_end(msg
, hdr
) < 0) {
6192 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6193 nl80211_mlme_mcgrp
.id
, gfp
);
6197 genlmsg_cancel(msg
, hdr
);
6202 nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device
*rdev
,
6203 struct net_device
*netdev
, const u8
*peer
,
6204 u32 num_packets
, gfp_t gfp
)
6206 struct sk_buff
*msg
;
6207 struct nlattr
*pinfoattr
;
6210 msg
= nlmsg_new(NLMSG_GOODSIZE
, gfp
);
6214 hdr
= nl80211hdr_put(msg
, 0, 0, 0, NL80211_CMD_NOTIFY_CQM
);
6220 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY
, rdev
->wiphy_idx
);
6221 NLA_PUT_U32(msg
, NL80211_ATTR_IFINDEX
, netdev
->ifindex
);
6222 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, peer
);
6224 pinfoattr
= nla_nest_start(msg
, NL80211_ATTR_CQM
);
6226 goto nla_put_failure
;
6228 NLA_PUT_U32(msg
, NL80211_ATTR_CQM_PKT_LOSS_EVENT
, num_packets
);
6230 nla_nest_end(msg
, pinfoattr
);
6232 if (genlmsg_end(msg
, hdr
) < 0) {
6237 genlmsg_multicast_netns(wiphy_net(&rdev
->wiphy
), msg
, 0,
6238 nl80211_mlme_mcgrp
.id
, gfp
);
6242 genlmsg_cancel(msg
, hdr
);
6246 static int nl80211_netlink_notify(struct notifier_block
* nb
,
6247 unsigned long state
,
6250 struct netlink_notify
*notify
= _notify
;
6251 struct cfg80211_registered_device
*rdev
;
6252 struct wireless_dev
*wdev
;
6254 if (state
!= NETLINK_URELEASE
)
6259 list_for_each_entry_rcu(rdev
, &cfg80211_rdev_list
, list
)
6260 list_for_each_entry_rcu(wdev
, &rdev
->netdev_list
, list
)
6261 cfg80211_mlme_unregister_socket(wdev
, notify
->pid
);
6268 static struct notifier_block nl80211_netlink_notifier
= {
6269 .notifier_call
= nl80211_netlink_notify
,
6272 /* initialisation/exit functions */
6274 int nl80211_init(void)
6278 err
= genl_register_family_with_ops(&nl80211_fam
,
6279 nl80211_ops
, ARRAY_SIZE(nl80211_ops
));
6283 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_config_mcgrp
);
6287 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_scan_mcgrp
);
6291 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_regulatory_mcgrp
);
6295 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_mlme_mcgrp
);
6299 #ifdef CONFIG_NL80211_TESTMODE
6300 err
= genl_register_mc_group(&nl80211_fam
, &nl80211_testmode_mcgrp
);
6305 err
= netlink_register_notifier(&nl80211_netlink_notifier
);
6311 genl_unregister_family(&nl80211_fam
);
6315 void nl80211_exit(void)
6317 netlink_unregister_notifier(&nl80211_netlink_notifier
);
6318 genl_unregister_family(&nl80211_fam
);