2 * cfg80211 MLME SAP interface
4 * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
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>
15 void cfg80211_send_rx_auth(struct net_device *dev, const u8 *buf, size_t len, gfp_t gfp)
17 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
18 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
20 nl80211_send_rx_auth(rdev, dev, buf, len, gfp);
21 cfg80211_sme_rx_auth(dev, buf, len);
23 EXPORT_SYMBOL(cfg80211_send_rx_auth);
25 void cfg80211_send_rx_assoc(struct net_device *dev, const u8 *buf, size_t len, gfp_t gfp)
28 struct wireless_dev *wdev = dev->ieee80211_ptr;
29 struct wiphy *wiphy = wdev->wiphy;
30 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
31 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
32 u8 *ie = mgmt->u.assoc_resp.variable;
33 int ieoffs = offsetof(struct ieee80211_mgmt, u.assoc_resp.variable);
35 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
37 nl80211_send_rx_assoc(rdev, dev, buf, len, gfp);
39 cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, ie, len - ieoffs,
42 EXPORT_SYMBOL(cfg80211_send_rx_assoc);
44 void cfg80211_send_deauth(struct net_device *dev, const u8 *buf, size_t len, gfp_t gfp)
46 struct wireless_dev *wdev = dev->ieee80211_ptr;
47 struct wiphy *wiphy = wdev->wiphy;
48 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
49 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
51 nl80211_send_deauth(rdev, dev, buf, len, gfp);
53 if (wdev->sme_state == CFG80211_SME_CONNECTED) {
57 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
59 from_ap = memcmp(mgmt->da, dev->dev_addr, ETH_ALEN) == 0;
60 __cfg80211_disconnected(dev, gfp, NULL, 0,
61 reason_code, from_ap);
63 wdev->sme_state = CFG80211_SME_IDLE;
64 } else if (wdev->sme_state == CFG80211_SME_CONNECTING) {
65 cfg80211_connect_result(dev, mgmt->bssid, NULL, 0, NULL, 0,
66 WLAN_STATUS_UNSPECIFIED_FAILURE, gfp);
69 EXPORT_SYMBOL(cfg80211_send_deauth);
71 void cfg80211_send_disassoc(struct net_device *dev, const u8 *buf, size_t len, gfp_t gfp)
73 struct wireless_dev *wdev = dev->ieee80211_ptr;
74 struct wiphy *wiphy = wdev->wiphy;
75 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
76 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)buf;
78 nl80211_send_disassoc(rdev, dev, buf, len, gfp);
80 if (wdev->sme_state == CFG80211_SME_CONNECTED) {
84 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
86 from_ap = memcmp(mgmt->da, dev->dev_addr, ETH_ALEN) == 0;
87 __cfg80211_disconnected(dev, gfp, NULL, 0,
88 reason_code, from_ap);
90 wdev->sme_state = CFG80211_SME_IDLE;
93 EXPORT_SYMBOL(cfg80211_send_disassoc);
95 void cfg80211_send_auth_timeout(struct net_device *dev, const u8 *addr, gfp_t gfp)
97 struct wireless_dev *wdev = dev->ieee80211_ptr;
98 struct wiphy *wiphy = wdev->wiphy;
99 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
100 nl80211_send_auth_timeout(rdev, dev, addr, gfp);
101 if (wdev->sme_state == CFG80211_SME_CONNECTING)
102 cfg80211_connect_result(dev, addr, NULL, 0, NULL, 0,
103 WLAN_STATUS_UNSPECIFIED_FAILURE, gfp);
104 wdev->sme_state = CFG80211_SME_IDLE;
106 EXPORT_SYMBOL(cfg80211_send_auth_timeout);
108 void cfg80211_send_assoc_timeout(struct net_device *dev, const u8 *addr, gfp_t gfp)
110 struct wireless_dev *wdev = dev->ieee80211_ptr;
111 struct wiphy *wiphy = wdev->wiphy;
112 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
113 nl80211_send_assoc_timeout(rdev, dev, addr, gfp);
114 if (wdev->sme_state == CFG80211_SME_CONNECTING)
115 cfg80211_connect_result(dev, addr, NULL, 0, NULL, 0,
116 WLAN_STATUS_UNSPECIFIED_FAILURE, gfp);
117 wdev->sme_state = CFG80211_SME_IDLE;
119 EXPORT_SYMBOL(cfg80211_send_assoc_timeout);
121 void cfg80211_michael_mic_failure(struct net_device *dev, const u8 *addr,
122 enum nl80211_key_type key_type, int key_id,
123 const u8 *tsc, gfp_t gfp)
125 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
126 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
127 #ifdef CONFIG_WIRELESS_EXT
128 union iwreq_data wrqu;
129 char *buf = kmalloc(128, gfp);
132 sprintf(buf, "MLME-MICHAELMICFAILURE.indication("
133 "keyid=%d %scast addr=%pM)", key_id,
134 key_type == NL80211_KEYTYPE_GROUP ? "broad" : "uni",
136 memset(&wrqu, 0, sizeof(wrqu));
137 wrqu.data.length = strlen(buf);
138 wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf);
143 nl80211_michael_mic_failure(rdev, dev, addr, key_type, key_id, tsc, gfp);
145 EXPORT_SYMBOL(cfg80211_michael_mic_failure);