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