Home | History | Annotate | Download | only in ap
      1 /*
      2  * hostapd / IEEE 802.11 MLME
      3  * Copyright 2003-2006, Jouni Malinen <j (at) 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 #include "hostapd.h"
     20 
     21 
     22 #ifndef CONFIG_NO_HOSTAPD_LOGGER
     23 static const char * mlme_auth_alg_str(int alg)
     24 {
     25 	switch (alg) {
     26 	case WLAN_AUTH_OPEN:
     27 		return "OPEN_SYSTEM";
     28 	case WLAN_AUTH_SHARED_KEY:
     29 		return "SHARED_KEY";
     30 	case WLAN_AUTH_FT:
     31 		return "FT";
     32 	}
     33 
     34 	return "unknown";
     35 }
     36 #endif /* CONFIG_NO_HOSTAPD_LOGGER */
     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 	if (sta->auth_alg != WLAN_AUTH_FT && !(sta->flags & WLAN_STA_MFP))
     61 		mlme_deletekeys_request(hapd, sta);
     62 	ap_sta_clear_disconnect_timeouts(hapd, sta);
     63 }
     64 
     65 
     66 /**
     67  * mlme_deauthenticate_indication - Report the invalidation of an
     68  * authentication relationship with a specific peer MAC entity
     69  * @hapd: BSS data
     70  * @sta: Peer STA data
     71  * @reason_code: ReasonCode from Deauthentication frame
     72  *
     73  * MLME calls this function as a result of the invalidation of an
     74  * authentication relationship with a specific peer MAC entity.
     75  *
     76  * PeerSTAAddress = sta->addr
     77  */
     78 void mlme_deauthenticate_indication(struct hostapd_data *hapd,
     79 				    struct sta_info *sta, u16 reason_code)
     80 {
     81 	hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_MLME,
     82 		       HOSTAPD_LEVEL_DEBUG,
     83 		       "MLME-DEAUTHENTICATE.indication(" MACSTR ", %d)",
     84 		       MAC2STR(sta->addr), reason_code);
     85 	if (!hapd->iface->driver_ap_teardown)
     86 		mlme_deletekeys_request(hapd, sta);
     87 }
     88 
     89 
     90 /**
     91  * mlme_associate_indication - Report the establishment of an association with
     92  * a specific peer MAC entity
     93  * @hapd: BSS data
     94  * @sta: peer STA data
     95  *
     96  * MLME calls this function as a result of the establishment of an
     97  * association with a specific peer MAC entity that resulted from an
     98  * association procedure that was initiated by that specific peer MAC entity.
     99  *
    100  * PeerSTAAddress = sta->addr
    101  */
    102 void mlme_associate_indication(struct hostapd_data *hapd, struct sta_info *sta)
    103 {
    104 	hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_MLME,
    105 		       HOSTAPD_LEVEL_DEBUG,
    106 		       "MLME-ASSOCIATE.indication(" MACSTR ")",
    107 		       MAC2STR(sta->addr));
    108 	if (sta->auth_alg != WLAN_AUTH_FT)
    109 		mlme_deletekeys_request(hapd, sta);
    110 	ap_sta_clear_disconnect_timeouts(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 void mlme_reassociate_indication(struct hostapd_data *hapd,
    127 				 struct sta_info *sta)
    128 {
    129 	hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_MLME,
    130 		       HOSTAPD_LEVEL_DEBUG,
    131 		       "MLME-REASSOCIATE.indication(" MACSTR ")",
    132 		       MAC2STR(sta->addr));
    133 	if (sta->auth_alg != WLAN_AUTH_FT)
    134 		mlme_deletekeys_request(hapd, sta);
    135 	ap_sta_clear_disconnect_timeouts(hapd, sta);
    136 }
    137 
    138 
    139 /**
    140  * mlme_disassociate_indication - Report disassociation with a specific peer
    141  * MAC entity
    142  * @hapd: BSS data
    143  * @sta: Peer STA data
    144  * @reason_code: ReasonCode from Disassociation frame
    145  *
    146  * MLME calls this function as a result of the invalidation of an association
    147  * relationship with a specific peer MAC entity.
    148  *
    149  * PeerSTAAddress = sta->addr
    150  */
    151 void mlme_disassociate_indication(struct hostapd_data *hapd,
    152 				  struct sta_info *sta, u16 reason_code)
    153 {
    154 	hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_MLME,
    155 		       HOSTAPD_LEVEL_DEBUG,
    156 		       "MLME-DISASSOCIATE.indication(" MACSTR ", %d)",
    157 		       MAC2STR(sta->addr), reason_code);
    158 	mlme_deletekeys_request(hapd, sta);
    159 }
    160 
    161 
    162 void mlme_michaelmicfailure_indication(struct hostapd_data *hapd,
    163 				       const u8 *addr)
    164 {
    165 	hostapd_logger(hapd, addr, HOSTAPD_MODULE_MLME,
    166 		       HOSTAPD_LEVEL_DEBUG,
    167 		       "MLME-MichaelMICFailure.indication(" MACSTR ")",
    168 		       MAC2STR(addr));
    169 }
    170 
    171 
    172 void mlme_deletekeys_request(struct hostapd_data *hapd, struct sta_info *sta)
    173 {
    174 	hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_MLME,
    175 		       HOSTAPD_LEVEL_DEBUG,
    176 		       "MLME-DELETEKEYS.request(" MACSTR ")",
    177 		       MAC2STR(sta->addr));
    178 
    179 	if (sta->wpa_sm)
    180 		wpa_remove_ptk(sta->wpa_sm);
    181 }
    182