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