Introduced new helper function is_zero_ether_addr()
authorJouni Malinen <j@w1.fi>
Tue, 3 Jun 2008 15:08:48 +0000 (18:08 +0300)
committerJouni Malinen <j@w1.fi>
Tue, 3 Jun 2008 15:08:48 +0000 (18:08 +0300)
Use this inline function to replace os_memcmp(addr,
"\x00\x00\x00\x00\x00\x00", ETH_ALEN) == 0.

12 files changed:
hostapd/config.c
src/drivers/driver_ndis.c
src/drivers/driver_wext.c
src/rsn_supp/preauth.c
src/rsn_supp/wpa.c
src/utils/common.h
wpa_supplicant/ctrl_iface.c
wpa_supplicant/events.c
wpa_supplicant/mlme.c
wpa_supplicant/todo.txt
wpa_supplicant/wpa_supplicant.c
wpa_supplicant/wpas_glue.c

index 725e7ed..dd805c1 100644 (file)
@@ -369,7 +369,7 @@ static int hostapd_config_read_wpa_psk(const char *fname,
                        ret = -1;
                        break;
                }
-               if (os_memcmp(addr, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) == 0)
+               if (is_zero_ether_addr(addr))
                        psk->group = 1;
                else
                        os_memcpy(psk->addr, addr, ETH_ALEN);
index f306a52..baa95e6 100644 (file)
@@ -1317,8 +1317,7 @@ static void wpa_driver_ndis_poll_timeout(void *eloop_ctx, void *timeout_ctx)
 
        if (wpa_driver_ndis_get_bssid(drv, bssid)) {
                /* Disconnected */
-               if (os_memcmp(drv->bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN)
-                   != 0) {
+               if (!is_zero_ether_addr(drv->bssid)) {
                        os_memset(drv->bssid, 0, ETH_ALEN);
                        wpa_supplicant_event(drv->ctx, EVENT_DISASSOC, NULL);
                }
index efa88a8..1226b94 100644 (file)
@@ -631,9 +631,8 @@ static void wpa_driver_wext_event_wireless(struct wpa_driver_wext_data *drv,
                        wpa_printf(MSG_DEBUG, "Wireless event: new AP: "
                                   MACSTR,
                                   MAC2STR((u8 *) iwe->u.ap_addr.sa_data));
-                       if (os_memcmp(iwe->u.ap_addr.sa_data,
-                                     "\x00\x00\x00\x00\x00\x00", ETH_ALEN) ==
-                           0 ||
+                       if (is_zero_ether_addr(
+                                   (const u8 *) iwe->u.ap_addr.sa_data) ||
                            os_memcmp(iwe->u.ap_addr.sa_data,
                                      "\x44\x44\x44\x44\x44\x44", ETH_ALEN) ==
                            0) {
index e9bf7c6..7bc3c04 100644 (file)
@@ -68,8 +68,7 @@ static void rsn_preauth_receive(void *ctx, const u8 *src_addr,
        wpa_hexdump(MSG_MSGDUMP, "RX pre-auth", buf, len);
 
        if (sm->preauth_eapol == NULL ||
-           os_memcmp(sm->preauth_bssid, "\x00\x00\x00\x00\x00\x00",
-                     ETH_ALEN) == 0 ||
+           is_zero_ether_addr(sm->preauth_bssid) ||
            os_memcmp(sm->preauth_bssid, src_addr, ETH_ALEN) != 0) {
                wpa_printf(MSG_WARNING, "RSN pre-auth frame received from "
                           "unexpected source " MACSTR " - dropped",
index 1dada92..cb511e0 100644 (file)
@@ -98,8 +98,7 @@ void wpa_eapol_key_send(struct wpa_sm *sm, const u8 *kck,
                        int ver, const u8 *dest, u16 proto,
                        u8 *msg, size_t msg_len, u8 *key_mic)
 {
-       if (os_memcmp(dest, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) == 0 &&
-           os_memcmp(sm->bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) == 0) {
+       if (is_zero_ether_addr(dest) && is_zero_ether_addr(sm->bssid)) {
                /*
                 * Association event was not yet received; try to fetch
                 * BSSID from the driver.
index d495a2e..d0a2eb3 100644 (file)
@@ -428,6 +428,10 @@ TCHAR * wpa_strdup_tchar(const char *str);
 
 const char * wpa_ssid_txt(const u8 *ssid, size_t ssid_len);
 
+static inline int is_zero_ether_addr(const u8 *a)
+{
+       return !(a[0] | a[1] | a[2] | a[3] | a[4] | a[5]);
+}
 
 #include "wpa_debug.h"
 
index 2e10f80..98ac08f 100644 (file)
@@ -330,9 +330,7 @@ static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
        }
 
        os_memcpy(ssid->bssid, bssid, ETH_ALEN);
-       ssid->bssid_set =
-               os_memcmp(bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) != 0;
-               
+       ssid->bssid_set = !is_zero_ether_addr(bssid);
 
        return 0;
 }
index ca559c8..66a98c2 100644 (file)
@@ -805,7 +805,7 @@ static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s)
        if (wpa_s->wpa_state >= WPA_ASSOCIATED)
                wpa_supplicant_req_scan(wpa_s, 0, 100000);
        bssid = wpa_s->bssid;
-       if (os_memcmp(bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) == 0)
+       if (is_zero_ether_addr(bssid))
                bssid = wpa_s->pending_bssid;
        wpa_blacklist_add(wpa_s, bssid);
        wpa_sm_notify_disassoc(wpa_s->wpa);
index 4d169e4..20f2701 100644 (file)
@@ -2455,8 +2455,7 @@ int ieee80211_sta_associate(struct wpa_supplicant *wpa_s,
        wpa_s->mlme.freq = params->freq;
        if (params->bssid) {
                os_memcpy(wpa_s->bssid, params->bssid, ETH_ALEN);
-               if (os_memcmp(params->bssid, "\x00\x00\x00\x00\x00\x00",
-                             ETH_ALEN))
+               if (!is_zero_ether_addr(params->bssid))
                        wpa_s->mlme.bssid_set = 1;
                bss = ieee80211_bss_get(wpa_s, wpa_s->bssid);
                if (bss) {
index e6487b0..a02a937 100644 (file)
@@ -59,7 +59,6 @@ To do:
   could very well be done before EAP has been started
 - try to work around race in receiving association event and first EAPOL
   message
-- helper function to do memcmp(addr, "\x00\x00\x00\x00\x00\x00", ETH_ALEN)
 - add wpa_secure_memzero() macro and secure implementation (volatile u8*) to
   clear memory; this would be used to clear temporary buffers containing
   private data (e.g., keys); the macro can be defined to NOP in order to save
index 9bd5435..5487212 100644 (file)
@@ -187,7 +187,7 @@ static void wpa_supplicant_timeout(void *eloop_ctx, void *timeout_ctx)
 {
        struct wpa_supplicant *wpa_s = eloop_ctx;
        const u8 *bssid = wpa_s->bssid;
-       if (os_memcmp(bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) == 0)
+       if (is_zero_ether_addr(bssid))
                bssid = wpa_s->pending_bssid;
        wpa_msg(wpa_s, MSG_INFO, "Authentication with " MACSTR " timed out.",
                MAC2STR(bssid));
@@ -1131,8 +1131,7 @@ void wpa_supplicant_disassociate(struct wpa_supplicant *wpa_s,
                                 int reason_code)
 {
        u8 *addr = NULL;
-       if (os_memcmp(wpa_s->bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) != 0)
-       {
+       if (!is_zero_ether_addr(wpa_s->bssid)) {
                if (wpa_s->use_client_mlme)
                        ieee80211_sta_disassociate(wpa_s, reason_code);
                else
@@ -1160,8 +1159,7 @@ void wpa_supplicant_deauthenticate(struct wpa_supplicant *wpa_s,
 {
        u8 *addr = NULL;
        wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
-       if (os_memcmp(wpa_s->bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) != 0)
-       {
+       if (!is_zero_ether_addr(wpa_s->bssid)) {
                if (wpa_s->use_client_mlme)
                        ieee80211_sta_deauthenticate(wpa_s, reason_code);
                else
index 3a87d06..eb422cb 100644 (file)
@@ -143,13 +143,11 @@ static int wpa_supplicant_eapol_send(void *ctx, int type, const u8 *buf,
                return -1;
        }
 
-       if (os_memcmp(wpa_s->bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) == 0)
-       {
+       if (is_zero_ether_addr(wpa_s->bssid)) {
                wpa_printf(MSG_DEBUG, "BSSID not set when trying to send an "
                           "EAPOL frame");
                if (wpa_drv_get_bssid(wpa_s, bssid) == 0 &&
-                   os_memcmp(bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) !=
-                   0) {
+                   !is_zero_ether_addr(bssid)) {
                        dst = bssid;
                        wpa_printf(MSG_DEBUG, "Using current BSSID " MACSTR
                                   " from the driver as the EAPOL destination",