Import hostapd 0.5.8
[dragonfly.git] / contrib / hostapd-0.5.8 / 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 "sta_info.h"
22 #include "wpa.h"
23 #include "mlme.h"
24
25
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         }
34
35         return "unknown";
36 }
37
38
39 /**
40  * mlme_authenticate_indication - Report the establishment of an authentication
41  * relationship with a specific peer MAC entity
42  * @hapd: BSS data
43  * @sta: peer STA data
44  *
45  * MLME calls this function as a result of the establishment of an
46  * authentication relationship with a specific peer MAC entity that
47  * resulted from an authentication procedure that was initiated by
48  * that specific peer MAC entity.
49  *
50  * PeerSTAAddress = sta->addr
51  * AuthenticationType = sta->auth_alg (WLAN_AUTH_OPEN / WLAN_AUTH_SHARED_KEY)
52  */
53 void mlme_authenticate_indication(struct hostapd_data *hapd,
54                                   struct sta_info *sta)
55 {
56         hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_MLME,
57                        HOSTAPD_LEVEL_DEBUG,
58                        "MLME-AUTHENTICATE.indication(" MACSTR ", %s)",
59                        MAC2STR(sta->addr), mlme_auth_alg_str(sta->auth_alg));
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         mlme_deletekeys_request(hapd, sta);
106 }
107
108
109 /**
110  * mlme_reassociate_indication - Report the establishment of an reassociation
111  * with a specific peer MAC entity
112  * @hapd: BSS data
113  * @sta: peer STA data
114  *
115  * MLME calls this function as a result of the establishment of an
116  * reassociation with a specific peer MAC entity that resulted from a
117  * reassociation procedure that was initiated by that specific peer MAC entity.
118  *
119  * PeerSTAAddress = sta->addr
120  *
121  * sta->previous_ap contains the "Current AP" information from ReassocReq.
122  */
123 void mlme_reassociate_indication(struct hostapd_data *hapd,
124                                  struct sta_info *sta)
125 {
126         hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_MLME,
127                        HOSTAPD_LEVEL_DEBUG,
128                        "MLME-REASSOCIATE.indication(" MACSTR ")",
129                        MAC2STR(sta->addr));
130         mlme_deletekeys_request(hapd, sta);
131 }
132
133
134 /**
135  * mlme_disassociate_indication - Report disassociation with a specific peer
136  * MAC entity
137  * @hapd: BSS data
138  * @sta: Peer STA data
139  * @reason_code: ReasonCode from Disassociation frame
140  *
141  * MLME calls this function as a result of the invalidation of an association
142  * relationship with a specific peer MAC entity.
143  *
144  * PeerSTAAddress = sta->addr
145  */
146 void mlme_disassociate_indication(struct hostapd_data *hapd,
147                                   struct sta_info *sta, u16 reason_code)
148 {
149         hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_MLME,
150                        HOSTAPD_LEVEL_DEBUG,
151                        "MLME-DISASSOCIATE.indication(" MACSTR ", %d)",
152                        MAC2STR(sta->addr), reason_code);
153         mlme_deletekeys_request(hapd, sta);
154 }
155
156
157 void mlme_michaelmicfailure_indication(struct hostapd_data *hapd,
158                                        const u8 *addr)
159 {
160         hostapd_logger(hapd, addr, HOSTAPD_MODULE_MLME,
161                        HOSTAPD_LEVEL_DEBUG,
162                        "MLME-MichaelMICFailure.indication(" MACSTR ")",
163                        MAC2STR(addr));
164 }
165
166
167 void mlme_deletekeys_request(struct hostapd_data *hapd, struct sta_info *sta)
168 {
169         hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_MLME,
170                        HOSTAPD_LEVEL_DEBUG,
171                        "MLME-DELETEKEYS.request(" MACSTR ")",
172                        MAC2STR(sta->addr));
173
174         if (sta->wpa_sm)
175                 wpa_remove_ptk(sta->wpa_sm);
176 }