Updated through tag hostap_2_5 from git://w1.fi/hostap.git
[mech_eap.git] / libeap / src / eap_peer / eap_vendor_test.c
index 3e114c1..b61057e 100644 (file)
@@ -1,15 +1,9 @@
 /*
  * EAP peer method: Test method for vendor specific (expanded) EAP type
- * Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2005-2015, Jouni Malinen <j@w1.fi>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
  *
  * This file implements a vendor specific test method using EAP expanded types.
  * This is only for test use and must not be used for authentication since no
 
 #include "common.h"
 #include "eap_i.h"
-#ifdef TEST_PENDING_REQUEST
 #include "eloop.h"
-#endif /* TEST_PENDING_REQUEST */
 
 
-#define EAP_VENDOR_ID 0xfffefd
+#define EAP_VENDOR_ID EAP_VENDOR_HOSTAP
 #define EAP_VENDOR_TYPE 0xfcfbfaf9
 
 
-/* #define TEST_PENDING_REQUEST */
-
 struct eap_vendor_test_data {
        enum { INIT, CONFIRM, SUCCESS } state;
        int first_try;
+       int test_pending_req;
 };
 
 
 static void * eap_vendor_test_init(struct eap_sm *sm)
 {
        struct eap_vendor_test_data *data;
+       const u8 *password;
+       size_t password_len;
+
        data = os_zalloc(sizeof(*data));
        if (data == NULL)
                return NULL;
        data->state = INIT;
        data->first_try = 1;
+
+       password = eap_get_config_password(sm, &password_len);
+       data->test_pending_req = password && password_len == 7 &&
+               os_memcmp(password, "pending", 7) == 0;
+
        return data;
 }
 
@@ -56,7 +55,6 @@ static void eap_vendor_test_deinit(struct eap_sm *sm, void *priv)
 }
 
 
-#ifdef TEST_PENDING_REQUEST
 static void eap_vendor_ready(void *eloop_ctx, void *timeout_ctx)
 {
        struct eap_sm *sm = eloop_ctx;
@@ -64,7 +62,6 @@ static void eap_vendor_ready(void *eloop_ctx, void *timeout_ctx)
                   "request");
        eap_notify_pending(sm);
 }
-#endif /* TEST_PENDING_REQUEST */
 
 
 static struct wpabuf * eap_vendor_test_process(struct eap_sm *sm, void *priv,
@@ -104,8 +101,7 @@ static struct wpabuf * eap_vendor_test_process(struct eap_sm *sm, void *priv,
        }
 
        if (data->state == CONFIRM) {
-#ifdef TEST_PENDING_REQUEST
-               if (data->first_try) {
+               if (data->test_pending_req && data->first_try) {
                        data->first_try = 0;
                        wpa_printf(MSG_DEBUG, "EAP-VENDOR-TEST: Testing "
                                   "pending request");
@@ -114,7 +110,6 @@ static struct wpabuf * eap_vendor_test_process(struct eap_sm *sm, void *priv,
                                               NULL);
                        return NULL;
                }
-#endif /* TEST_PENDING_REQUEST */
        }
 
        ret->ignore = FALSE;