P2P: Fix D-Bus persistent parameter in group started event on GO
[mech_eap.git] / wlantest / wired.c
index fe64d45..77a395f 100644 (file)
@@ -2,14 +2,8 @@
  * Received frame processing for wired interface
  * Copyright (c) 2010, 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.
  */
 
 #include "utils/includes.h"
 #include "wlantest.h"
 
 
+static struct wlantest_radius * radius_get(struct wlantest *wt, u32 srv,
+                                          u32 cli)
+{
+       struct wlantest_radius *r;
+
+       dl_list_for_each(r, &wt->radius, struct wlantest_radius, list) {
+               if (r->srv == srv && r->cli == cli)
+                       return r;
+       }
+
+       r = os_zalloc(sizeof(*r));
+       if (r == NULL)
+               return NULL;
+
+       r->srv = srv;
+       r->cli = cli;
+       dl_list_add(&wt->radius, &r->list);
+
+       return r;
+}
+
+
 static const char * radius_code_string(u8 code)
 {
        switch (code) {
@@ -53,6 +69,7 @@ static void process_radius_access_request(struct wlantest *wt, u32 dst,
                                          u32 src, const u8 *data, size_t len)
 {
        struct radius_msg *msg;
+       struct wlantest_radius *r;
 
        msg = radius_msg_parse(data, len);
        if (msg == NULL) {
@@ -60,14 +77,43 @@ static void process_radius_access_request(struct wlantest *wt, u32 dst,
                return;
        }
 
+       r = radius_get(wt, dst, src);
+       if (r) {
+               radius_msg_free(r->last_req);
+               r->last_req = msg;
+               return;
+       }
        radius_msg_free(msg);
 }
 
 
+static void wlantest_add_pmk(struct wlantest *wt, const u8 *pmk)
+{
+       struct wlantest_pmk *p;
+
+       p = os_zalloc(sizeof(*p));
+       if (p == NULL)
+               return;
+       os_memcpy(p->pmk, pmk, 32);
+       dl_list_add(&wt->pmk, &p->list);
+       wpa_hexdump(MSG_INFO, "Add PMK", pmk, 32);
+}
+
+
 static void process_radius_access_accept(struct wlantest *wt, u32 dst, u32 src,
                                         const u8 *data, size_t len)
 {
        struct radius_msg *msg;
+       struct wlantest_radius *r;
+       struct radius_ms_mppe_keys *keys;
+       struct wlantest_radius_secret *s;
+
+       r = radius_get(wt, src, dst);
+       if (r == NULL || r->last_req == NULL) {
+               wpa_printf(MSG_DEBUG, "No RADIUS Access-Challenge found for "
+                          "decrypting Access-Accept keys");
+               return;
+       }
 
        msg = radius_msg_parse(data, len);
        if (msg == NULL) {
@@ -75,6 +121,39 @@ static void process_radius_access_accept(struct wlantest *wt, u32 dst, u32 src,
                return;
        }
 
+       dl_list_for_each(s, &wt->secret, struct wlantest_radius_secret, list) {
+               int found = 0;
+               keys = radius_msg_get_ms_keys(msg, r->last_req,
+                                             (u8 *) s->secret,
+                                             os_strlen(s->secret));
+               if (keys && keys->send && keys->recv) {
+                       u8 pmk[32];
+                       wpa_hexdump_key(MSG_DEBUG, "MS-MPPE-Send-Key",
+                                       keys->send, keys->send_len);
+                       wpa_hexdump_key(MSG_DEBUG, "MS-MPPE-Recv-Key",
+                                       keys->recv, keys->recv_len);
+                       os_memcpy(pmk, keys->recv,
+                                 keys->recv_len > 32 ? 32 : keys->recv_len);
+                       if (keys->recv_len < 32) {
+                               os_memcpy(pmk + keys->recv_len,
+                                         keys->send,
+                                         keys->recv_len + keys->send_len > 32
+                                         ? 32 : 32 - keys->recv_len);
+                       }
+                       wlantest_add_pmk(wt, pmk);
+                       found = 1;
+               }
+
+               if (keys) {
+                       os_free(keys->send);
+                       os_free(keys->recv);
+                       os_free(keys);
+               }
+
+               if (found)
+                       break;
+       }
+
        radius_msg_free(msg);
 }