Skip to content

Commit 6039f6d

Browse files
Jouni Malinenlinvjw
authored andcommitted
nl80211: Event notifications for MLME events
Add new nl80211 event notifications (and a new multicast group, "mlme") for informing user space about received and processed Authentication, (Re)Association Response, Deauthentication, and Disassociation frames in station and IBSS modes (i.e., MLME SAP interface primitives MLME-AUTHENTICATE.confirm, MLME-ASSOCIATE.confirm, MLME-REASSOCIATE.confirm, MLME-DEAUTHENTICATE.indicate, and MLME-DISASSOCIATE.indication). The event data is encapsulated as the 802.11 management frame since we already have the frame in that format and it includes all the needed information. This is the initial step in providing MLME SAP interface for authentication and association with nl80211. In other words, kernel code will act as the MLME and a user space application can control it as the SME. Signed-off-by: Jouni Malinen <j@w1.fi> Signed-off-by: John W. Linville <linville@tuxdriver.com>
1 parent a299542 commit 6039f6d

7 files changed

Lines changed: 219 additions & 4 deletions

File tree

‎include/linux/nl80211.h‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,25 @@
161161
* %NL80211_REG_TYPE_COUNTRY the alpha2 to which we have moved on
162162
* to (%NL80211_ATTR_REG_ALPHA2).
163163
*
164+
* @NL80211_CMD_AUTHENTICATE: authentication notification (on the "mlme"
165+
* multicast group). This event reports reception of an Authentication
166+
* frame in station and IBSS modes when the local MLME processed the
167+
* frame, i.e., it was for the local STA and was received in correct
168+
* state. This is similar to MLME-AUTHENTICATE.confirm primitive in the
169+
* MLME SAP interface (kernel providing MLME, userspace SME). The
170+
* included NL80211_ATTR_FRAME attribute contains the management frame
171+
* (including both the header and frame body, but not FCS).
172+
* @NL80211_CMD_ASSOCIATE: association notification; like
173+
* NL80211_CMD_AUTHENTICATE but for Association Response and Reassociation
174+
* Response frames (similar to MLME-ASSOCIATE.confirm or
175+
* MLME-REASSOCIATE.confirm primitives).
176+
* @NL80211_CMD_DEAUTHENTICATE: deauthentication notification; like
177+
* NL80211_CMD_AUTHENTICATE but for Deauthentication frames (similar to
178+
* MLME-DEAUTHENTICATE.indication primitive).
179+
* @NL80211_CMD_DISASSOCIATE: disassociation notification; like
180+
* NL80211_CMD_AUTHENTICATE but for Disassociation frames (similar to
181+
* MLME-DISASSOCIATE.indication primitive).
182+
*
164183
* @NL80211_CMD_MAX: highest used command number
165184
* @__NL80211_CMD_AFTER_LAST: internal use
166185
*/
@@ -217,6 +236,11 @@ enum nl80211_commands {
217236

218237
NL80211_CMD_REG_CHANGE,
219238

239+
NL80211_CMD_AUTHENTICATE,
240+
NL80211_CMD_ASSOCIATE,
241+
NL80211_CMD_DEAUTHENTICATE,
242+
NL80211_CMD_DISASSOCIATE,
243+
220244
/* add new commands above here */
221245

222246
/* used to define NL80211_CMD_MAX below */
@@ -230,8 +254,11 @@ enum nl80211_commands {
230254
*/
231255
#define NL80211_CMD_SET_BSS NL80211_CMD_SET_BSS
232256
#define NL80211_CMD_SET_MGMT_EXTRA_IE NL80211_CMD_SET_MGMT_EXTRA_IE
233-
234257
#define NL80211_CMD_REG_CHANGE NL80211_CMD_REG_CHANGE
258+
#define NL80211_CMD_AUTHENTICATE NL80211_CMD_AUTHENTICATE
259+
#define NL80211_CMD_ASSOCIATE NL80211_CMD_ASSOCIATE
260+
#define NL80211_CMD_DEAUTHENTICATE NL80211_CMD_DEAUTHENTICATE
261+
#define NL80211_CMD_DISASSOCIATE NL80211_CMD_DISASSOCIATE
235262

236263
/**
237264
* enum nl80211_attrs - nl80211 netlink attributes
@@ -353,6 +380,10 @@ enum nl80211_commands {
353380
* an array of command numbers (i.e. a mapping index to command number)
354381
* that the driver for the given wiphy supports.
355382
*
383+
* @NL80211_ATTR_FRAME: frame data (binary attribute), including frame header
384+
* and body, but not FCS; used, e.g., with NL80211_CMD_AUTHENTICATE and
385+
* NL80211_CMD_ASSOCIATE events
386+
*
356387
* @NL80211_ATTR_MAX: highest attribute number currently defined
357388
* @__NL80211_ATTR_AFTER_LAST: internal use
358389
*/
@@ -432,6 +463,8 @@ enum nl80211_attrs {
432463

433464
NL80211_ATTR_SUPPORTED_COMMANDS,
434465

466+
NL80211_ATTR_FRAME,
467+
435468
/* add attributes here, update the policy in nl80211.c */
436469

437470
__NL80211_ATTR_AFTER_LAST,
@@ -451,6 +484,7 @@ enum nl80211_attrs {
451484
#define NL80211_ATTR_IE NL80211_ATTR_IE
452485
#define NL80211_ATTR_REG_INITIATOR NL80211_ATTR_REG_INITIATOR
453486
#define NL80211_ATTR_REG_TYPE NL80211_ATTR_REG_TYPE
487+
#define NL80211_ATTR_FRAME NL80211_ATTR_FRAME
454488

455489
#define NL80211_MAX_SUPP_RATES 32
456490
#define NL80211_MAX_SUPP_REG_RULES 32

‎include/net/cfg80211.h‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,4 +807,50 @@ void cfg80211_put_bss(struct cfg80211_bss *bss);
807807
*/
808808
void cfg80211_unlink_bss(struct wiphy *wiphy, struct cfg80211_bss *bss);
809809

810+
/**
811+
* cfg80211_send_rx_auth - notification of processed authentication
812+
* @dev: network device
813+
* @buf: authentication frame (header + body)
814+
* @len: length of the frame data
815+
*
816+
* This function is called whenever an authentication has been processed in
817+
* station mode.
818+
*/
819+
void cfg80211_send_rx_auth(struct net_device *dev, const u8 *buf, size_t len);
820+
821+
/**
822+
* cfg80211_send_rx_assoc - notification of processed association
823+
* @dev: network device
824+
* @buf: (re)association response frame (header + body)
825+
* @len: length of the frame data
826+
*
827+
* This function is called whenever a (re)association response has been
828+
* processed in station mode.
829+
*/
830+
void cfg80211_send_rx_assoc(struct net_device *dev, const u8 *buf, size_t len);
831+
832+
/**
833+
* cfg80211_send_rx_deauth - notification of processed deauthentication
834+
* @dev: network device
835+
* @buf: deauthentication frame (header + body)
836+
* @len: length of the frame data
837+
*
838+
* This function is called whenever deauthentication has been processed in
839+
* station mode.
840+
*/
841+
void cfg80211_send_rx_deauth(struct net_device *dev, const u8 *buf,
842+
size_t len);
843+
844+
/**
845+
* cfg80211_send_rx_disassoc - notification of processed disassociation
846+
* @dev: network device
847+
* @buf: disassociation response frame (header + body)
848+
* @len: length of the frame data
849+
*
850+
* This function is called whenever disassociation has been processed in
851+
* station mode.
852+
*/
853+
void cfg80211_send_rx_disassoc(struct net_device *dev, const u8 *buf,
854+
size_t len);
855+
810856
#endif /* __NET_CFG80211_H */

‎net/mac80211/mlme.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,11 +1085,13 @@ static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
10851085
case WLAN_AUTH_OPEN:
10861086
case WLAN_AUTH_LEAP:
10871087
ieee80211_auth_completed(sdata);
1088+
cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, len);
10881089
break;
10891090
case WLAN_AUTH_SHARED_KEY:
1090-
if (ifmgd->auth_transaction == 4)
1091+
if (ifmgd->auth_transaction == 4) {
10911092
ieee80211_auth_completed(sdata);
1092-
else
1093+
cfg80211_send_rx_auth(sdata->dev, (u8 *) mgmt, len);
1094+
} else
10931095
ieee80211_auth_challenge(sdata, mgmt, len);
10941096
break;
10951097
}
@@ -1125,6 +1127,7 @@ static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
11251127

11261128
ieee80211_set_disassoc(sdata, true, false, 0);
11271129
ifmgd->flags &= ~IEEE80211_STA_AUTHENTICATED;
1130+
cfg80211_send_rx_deauth(sdata->dev, (u8 *) mgmt, len);
11281131
}
11291132

11301133

@@ -1154,6 +1157,7 @@ static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
11541157
}
11551158

11561159
ieee80211_set_disassoc(sdata, false, false, reason_code);
1160+
cfg80211_send_rx_disassoc(sdata->dev, (u8 *) mgmt, len);
11571161
}
11581162

11591163

@@ -1370,6 +1374,7 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
13701374
ieee80211_set_associated(sdata, changed);
13711375

13721376
ieee80211_associated(sdata);
1377+
cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, len);
13731378
}
13741379

13751380

‎net/wireless/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ obj-$(CONFIG_LIB80211_CRYPT_WEP) += lib80211_crypt_wep.o
55
obj-$(CONFIG_LIB80211_CRYPT_CCMP) += lib80211_crypt_ccmp.o
66
obj-$(CONFIG_LIB80211_CRYPT_TKIP) += lib80211_crypt_tkip.o
77

8-
cfg80211-y += core.o sysfs.o radiotap.o util.o reg.o scan.o nl80211.o
8+
cfg80211-y += core.o sysfs.o radiotap.o util.o reg.o scan.o nl80211.o mlme.o
99
cfg80211-$(CONFIG_WIRELESS_EXT) += wext-compat.o
1010

1111
ccflags-y += -D__CHECK_ENDIAN__

‎net/wireless/mlme.c‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* cfg80211 MLME SAP interface
3+
*
4+
* Copyright (c) 2009, Jouni Malinen <j@w1.fi>
5+
*/
6+
7+
#include <linux/kernel.h>
8+
#include <linux/module.h>
9+
#include <linux/netdevice.h>
10+
#include <linux/nl80211.h>
11+
#include <net/cfg80211.h>
12+
#include "core.h"
13+
#include "nl80211.h"
14+
15+
void cfg80211_send_rx_auth(struct net_device *dev, const u8 *buf, size_t len)
16+
{
17+
struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
18+
struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
19+
nl80211_send_rx_auth(rdev, dev, buf, len);
20+
}
21+
EXPORT_SYMBOL(cfg80211_send_rx_auth);
22+
23+
void cfg80211_send_rx_assoc(struct net_device *dev, const u8 *buf, size_t len)
24+
{
25+
struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
26+
struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
27+
nl80211_send_rx_assoc(rdev, dev, buf, len);
28+
}
29+
EXPORT_SYMBOL(cfg80211_send_rx_assoc);
30+
31+
void cfg80211_send_rx_deauth(struct net_device *dev, const u8 *buf, size_t len)
32+
{
33+
struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
34+
struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
35+
nl80211_send_rx_deauth(rdev, dev, buf, len);
36+
}
37+
EXPORT_SYMBOL(cfg80211_send_rx_deauth);
38+
39+
void cfg80211_send_rx_disassoc(struct net_device *dev, const u8 *buf,
40+
size_t len)
41+
{
42+
struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
43+
struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
44+
nl80211_send_rx_disassoc(rdev, dev, buf, len);
45+
}
46+
EXPORT_SYMBOL(cfg80211_send_rx_disassoc);

‎net/wireless/nl80211.c‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2830,6 +2830,9 @@ static struct genl_ops nl80211_ops[] = {
28302830
.dumpit = nl80211_dump_scan,
28312831
},
28322832
};
2833+
static struct genl_multicast_group nl80211_mlme_mcgrp = {
2834+
.name = "mlme",
2835+
};
28332836

28342837
/* multicast groups */
28352838
static struct genl_multicast_group nl80211_config_mcgrp = {
@@ -2975,6 +2978,71 @@ void nl80211_send_reg_change_event(struct regulatory_request *request)
29752978
nlmsg_free(msg);
29762979
}
29772980

2981+
static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
2982+
struct net_device *netdev,
2983+
const u8 *buf, size_t len,
2984+
enum nl80211_commands cmd)
2985+
{
2986+
struct sk_buff *msg;
2987+
void *hdr;
2988+
2989+
msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
2990+
if (!msg)
2991+
return;
2992+
2993+
hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
2994+
if (!hdr) {
2995+
nlmsg_free(msg);
2996+
return;
2997+
}
2998+
2999+
NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
3000+
NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
3001+
NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
3002+
3003+
if (genlmsg_end(msg, hdr) < 0) {
3004+
nlmsg_free(msg);
3005+
return;
3006+
}
3007+
3008+
genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, GFP_KERNEL);
3009+
return;
3010+
3011+
nla_put_failure:
3012+
genlmsg_cancel(msg, hdr);
3013+
nlmsg_free(msg);
3014+
}
3015+
3016+
void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
3017+
struct net_device *netdev, const u8 *buf, size_t len)
3018+
{
3019+
nl80211_send_mlme_event(rdev, netdev, buf, len,
3020+
NL80211_CMD_AUTHENTICATE);
3021+
}
3022+
3023+
void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
3024+
struct net_device *netdev, const u8 *buf,
3025+
size_t len)
3026+
{
3027+
nl80211_send_mlme_event(rdev, netdev, buf, len, NL80211_CMD_ASSOCIATE);
3028+
}
3029+
3030+
void nl80211_send_rx_deauth(struct cfg80211_registered_device *rdev,
3031+
struct net_device *netdev, const u8 *buf,
3032+
size_t len)
3033+
{
3034+
nl80211_send_mlme_event(rdev, netdev, buf, len,
3035+
NL80211_CMD_DEAUTHENTICATE);
3036+
}
3037+
3038+
void nl80211_send_rx_disassoc(struct cfg80211_registered_device *rdev,
3039+
struct net_device *netdev, const u8 *buf,
3040+
size_t len)
3041+
{
3042+
nl80211_send_mlme_event(rdev, netdev, buf, len,
3043+
NL80211_CMD_DISASSOCIATE);
3044+
}
3045+
29783046
/* initialisation/exit functions */
29793047

29803048
int nl80211_init(void)
@@ -3003,6 +3071,10 @@ int nl80211_init(void)
30033071
if (err)
30043072
goto err_out;
30053073

3074+
err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
3075+
if (err)
3076+
goto err_out;
3077+
30063078
return 0;
30073079
err_out:
30083080
genl_unregister_family(&nl80211_fam);

‎net/wireless/nl80211.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,17 @@ extern void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
1111
extern void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
1212
struct net_device *netdev);
1313
extern void nl80211_send_reg_change_event(struct regulatory_request *request);
14+
extern void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
15+
struct net_device *netdev,
16+
const u8 *buf, size_t len);
17+
extern void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
18+
struct net_device *netdev,
19+
const u8 *buf, size_t len);
20+
extern void nl80211_send_rx_deauth(struct cfg80211_registered_device *rdev,
21+
struct net_device *netdev,
22+
const u8 *buf, size_t len);
23+
extern void nl80211_send_rx_disassoc(struct cfg80211_registered_device *rdev,
24+
struct net_device *netdev,
25+
const u8 *buf, size_t len);
1426

1527
#endif /* __NET_WIRELESS_NL80211_H */

0 commit comments

Comments
 (0)