xref: /freebsd/contrib/wpa/src/ap/ap_mlme.c (revision 5b9c547c072b84410b50897cc53710c75b2f6b74)
1e28a4053SRui Paulo /*
2e28a4053SRui Paulo  * hostapd / IEEE 802.11 MLME
3e28a4053SRui Paulo  * Copyright 2003-2006, Jouni Malinen <j@w1.fi>
4e28a4053SRui Paulo  * Copyright 2003-2004, Instant802 Networks, Inc.
5e28a4053SRui Paulo  * Copyright 2005-2006, Devicescape Software, Inc.
6e28a4053SRui Paulo  *
7f05cddf9SRui Paulo  * This software may be distributed under the terms of the BSD license.
8f05cddf9SRui Paulo  * See README for more details.
9e28a4053SRui Paulo  */
10e28a4053SRui Paulo 
11e28a4053SRui Paulo #include "utils/includes.h"
12e28a4053SRui Paulo 
13e28a4053SRui Paulo #include "utils/common.h"
14e28a4053SRui Paulo #include "common/ieee802_11_defs.h"
15e28a4053SRui Paulo #include "ieee802_11.h"
16e28a4053SRui Paulo #include "wpa_auth.h"
17e28a4053SRui Paulo #include "sta_info.h"
18e28a4053SRui Paulo #include "ap_mlme.h"
19*5b9c547cSRui Paulo #include "hostapd.h"
20e28a4053SRui Paulo 
21e28a4053SRui Paulo 
22e28a4053SRui Paulo #ifndef CONFIG_NO_HOSTAPD_LOGGER
23e28a4053SRui Paulo static const char * mlme_auth_alg_str(int alg)
24e28a4053SRui Paulo {
25e28a4053SRui Paulo 	switch (alg) {
26e28a4053SRui Paulo 	case WLAN_AUTH_OPEN:
27e28a4053SRui Paulo 		return "OPEN_SYSTEM";
28e28a4053SRui Paulo 	case WLAN_AUTH_SHARED_KEY:
29e28a4053SRui Paulo 		return "SHARED_KEY";
30e28a4053SRui Paulo 	case WLAN_AUTH_FT:
31e28a4053SRui Paulo 		return "FT";
32e28a4053SRui Paulo 	}
33e28a4053SRui Paulo 
34e28a4053SRui Paulo 	return "unknown";
35e28a4053SRui Paulo }
36e28a4053SRui Paulo #endif /* CONFIG_NO_HOSTAPD_LOGGER */
37e28a4053SRui Paulo 
38e28a4053SRui Paulo 
39e28a4053SRui Paulo /**
40e28a4053SRui Paulo  * mlme_authenticate_indication - Report the establishment of an authentication
41e28a4053SRui Paulo  * relationship with a specific peer MAC entity
42e28a4053SRui Paulo  * @hapd: BSS data
43e28a4053SRui Paulo  * @sta: peer STA data
44e28a4053SRui Paulo  *
45e28a4053SRui Paulo  * MLME calls this function as a result of the establishment of an
46e28a4053SRui Paulo  * authentication relationship with a specific peer MAC entity that
47e28a4053SRui Paulo  * resulted from an authentication procedure that was initiated by
48e28a4053SRui Paulo  * that specific peer MAC entity.
49e28a4053SRui Paulo  *
50e28a4053SRui Paulo  * PeerSTAAddress = sta->addr
51e28a4053SRui Paulo  * AuthenticationType = sta->auth_alg (WLAN_AUTH_OPEN / WLAN_AUTH_SHARED_KEY)
52e28a4053SRui Paulo  */
53e28a4053SRui Paulo void mlme_authenticate_indication(struct hostapd_data *hapd,
54e28a4053SRui Paulo 				  struct sta_info *sta)
55e28a4053SRui Paulo {
56e28a4053SRui Paulo 	hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_MLME,
57e28a4053SRui Paulo 		       HOSTAPD_LEVEL_DEBUG,
58e28a4053SRui Paulo 		       "MLME-AUTHENTICATE.indication(" MACSTR ", %s)",
59e28a4053SRui Paulo 		       MAC2STR(sta->addr), mlme_auth_alg_str(sta->auth_alg));
60e28a4053SRui Paulo 	if (sta->auth_alg != WLAN_AUTH_FT && !(sta->flags & WLAN_STA_MFP))
61e28a4053SRui Paulo 		mlme_deletekeys_request(hapd, sta);
62e28a4053SRui Paulo }
63e28a4053SRui Paulo 
64e28a4053SRui Paulo 
65e28a4053SRui Paulo /**
66e28a4053SRui Paulo  * mlme_deauthenticate_indication - Report the invalidation of an
67e28a4053SRui Paulo  * authentication relationship with a specific peer MAC entity
68e28a4053SRui Paulo  * @hapd: BSS data
69e28a4053SRui Paulo  * @sta: Peer STA data
70e28a4053SRui Paulo  * @reason_code: ReasonCode from Deauthentication frame
71e28a4053SRui Paulo  *
72e28a4053SRui Paulo  * MLME calls this function as a result of the invalidation of an
73e28a4053SRui Paulo  * authentication relationship with a specific peer MAC entity.
74e28a4053SRui Paulo  *
75e28a4053SRui Paulo  * PeerSTAAddress = sta->addr
76e28a4053SRui Paulo  */
77e28a4053SRui Paulo void mlme_deauthenticate_indication(struct hostapd_data *hapd,
78e28a4053SRui Paulo 				    struct sta_info *sta, u16 reason_code)
79e28a4053SRui Paulo {
80e28a4053SRui Paulo 	hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_MLME,
81e28a4053SRui Paulo 		       HOSTAPD_LEVEL_DEBUG,
82e28a4053SRui Paulo 		       "MLME-DEAUTHENTICATE.indication(" MACSTR ", %d)",
83e28a4053SRui Paulo 		       MAC2STR(sta->addr), reason_code);
84*5b9c547cSRui Paulo 	if (!hapd->iface->driver_ap_teardown)
85e28a4053SRui Paulo 		mlme_deletekeys_request(hapd, sta);
86e28a4053SRui Paulo }
87e28a4053SRui Paulo 
88e28a4053SRui Paulo 
89e28a4053SRui Paulo /**
90e28a4053SRui Paulo  * mlme_associate_indication - Report the establishment of an association with
91e28a4053SRui Paulo  * a specific peer MAC entity
92e28a4053SRui Paulo  * @hapd: BSS data
93e28a4053SRui Paulo  * @sta: peer STA data
94e28a4053SRui Paulo  *
95e28a4053SRui Paulo  * MLME calls this function as a result of the establishment of an
96e28a4053SRui Paulo  * association with a specific peer MAC entity that resulted from an
97e28a4053SRui Paulo  * association procedure that was initiated by that specific peer MAC entity.
98e28a4053SRui Paulo  *
99e28a4053SRui Paulo  * PeerSTAAddress = sta->addr
100e28a4053SRui Paulo  */
101e28a4053SRui Paulo void mlme_associate_indication(struct hostapd_data *hapd, struct sta_info *sta)
102e28a4053SRui Paulo {
103e28a4053SRui Paulo 	hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_MLME,
104e28a4053SRui Paulo 		       HOSTAPD_LEVEL_DEBUG,
105e28a4053SRui Paulo 		       "MLME-ASSOCIATE.indication(" MACSTR ")",
106e28a4053SRui Paulo 		       MAC2STR(sta->addr));
107e28a4053SRui Paulo 	if (sta->auth_alg != WLAN_AUTH_FT)
108e28a4053SRui Paulo 		mlme_deletekeys_request(hapd, sta);
109e28a4053SRui Paulo }
110e28a4053SRui Paulo 
111e28a4053SRui Paulo 
112e28a4053SRui Paulo /**
113e28a4053SRui Paulo  * mlme_reassociate_indication - Report the establishment of an reassociation
114e28a4053SRui Paulo  * with a specific peer MAC entity
115e28a4053SRui Paulo  * @hapd: BSS data
116e28a4053SRui Paulo  * @sta: peer STA data
117e28a4053SRui Paulo  *
118e28a4053SRui Paulo  * MLME calls this function as a result of the establishment of an
119e28a4053SRui Paulo  * reassociation with a specific peer MAC entity that resulted from a
120e28a4053SRui Paulo  * reassociation procedure that was initiated by that specific peer MAC entity.
121e28a4053SRui Paulo  *
122e28a4053SRui Paulo  * PeerSTAAddress = sta->addr
123e28a4053SRui Paulo  */
124e28a4053SRui Paulo void mlme_reassociate_indication(struct hostapd_data *hapd,
125e28a4053SRui Paulo 				 struct sta_info *sta)
126e28a4053SRui Paulo {
127e28a4053SRui Paulo 	hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_MLME,
128e28a4053SRui Paulo 		       HOSTAPD_LEVEL_DEBUG,
129e28a4053SRui Paulo 		       "MLME-REASSOCIATE.indication(" MACSTR ")",
130e28a4053SRui Paulo 		       MAC2STR(sta->addr));
131e28a4053SRui Paulo 	if (sta->auth_alg != WLAN_AUTH_FT)
132e28a4053SRui Paulo 		mlme_deletekeys_request(hapd, sta);
133e28a4053SRui Paulo }
134e28a4053SRui Paulo 
135e28a4053SRui Paulo 
136e28a4053SRui Paulo /**
137e28a4053SRui Paulo  * mlme_disassociate_indication - Report disassociation with a specific peer
138e28a4053SRui Paulo  * MAC entity
139e28a4053SRui Paulo  * @hapd: BSS data
140e28a4053SRui Paulo  * @sta: Peer STA data
141e28a4053SRui Paulo  * @reason_code: ReasonCode from Disassociation frame
142e28a4053SRui Paulo  *
143e28a4053SRui Paulo  * MLME calls this function as a result of the invalidation of an association
144e28a4053SRui Paulo  * relationship with a specific peer MAC entity.
145e28a4053SRui Paulo  *
146e28a4053SRui Paulo  * PeerSTAAddress = sta->addr
147e28a4053SRui Paulo  */
148e28a4053SRui Paulo void mlme_disassociate_indication(struct hostapd_data *hapd,
149e28a4053SRui Paulo 				  struct sta_info *sta, u16 reason_code)
150e28a4053SRui Paulo {
151e28a4053SRui Paulo 	hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_MLME,
152e28a4053SRui Paulo 		       HOSTAPD_LEVEL_DEBUG,
153e28a4053SRui Paulo 		       "MLME-DISASSOCIATE.indication(" MACSTR ", %d)",
154e28a4053SRui Paulo 		       MAC2STR(sta->addr), reason_code);
155e28a4053SRui Paulo 	mlme_deletekeys_request(hapd, sta);
156e28a4053SRui Paulo }
157e28a4053SRui Paulo 
158e28a4053SRui Paulo 
159e28a4053SRui Paulo void mlme_michaelmicfailure_indication(struct hostapd_data *hapd,
160e28a4053SRui Paulo 				       const u8 *addr)
161e28a4053SRui Paulo {
162e28a4053SRui Paulo 	hostapd_logger(hapd, addr, HOSTAPD_MODULE_MLME,
163e28a4053SRui Paulo 		       HOSTAPD_LEVEL_DEBUG,
164e28a4053SRui Paulo 		       "MLME-MichaelMICFailure.indication(" MACSTR ")",
165e28a4053SRui Paulo 		       MAC2STR(addr));
166e28a4053SRui Paulo }
167e28a4053SRui Paulo 
168e28a4053SRui Paulo 
169e28a4053SRui Paulo void mlme_deletekeys_request(struct hostapd_data *hapd, struct sta_info *sta)
170e28a4053SRui Paulo {
171e28a4053SRui Paulo 	hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_MLME,
172e28a4053SRui Paulo 		       HOSTAPD_LEVEL_DEBUG,
173e28a4053SRui Paulo 		       "MLME-DELETEKEYS.request(" MACSTR ")",
174e28a4053SRui Paulo 		       MAC2STR(sta->addr));
175e28a4053SRui Paulo 
176e28a4053SRui Paulo 	if (sta->wpa_sm)
177e28a4053SRui Paulo 		wpa_remove_ptk(sta->wpa_sm);
178e28a4053SRui Paulo }
179