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