Remove src/crypto from default include path
[libeap.git] / src / wps / wps.c
index dde16d1..5be2b9a 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Wi-Fi Protected Setup
- * Copyright (c) 2007-2008, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2007-2009, 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
 #include "includes.h"
 
 #include "common.h"
+#include "crypto/dh_group5.h"
+#include "common/ieee802_11_defs.h"
 #include "wps_i.h"
 #include "wps_dev_attr.h"
-#include "ieee802_11_defs.h"
 
 
 /**
@@ -89,6 +90,20 @@ struct wps_data * wps_init(const struct wps_config *cfg)
                }
        }
 
+       if (cfg->new_ap_settings) {
+               data->new_ap_settings =
+                       os_malloc(sizeof(*data->new_ap_settings));
+               if (data->new_ap_settings == NULL) {
+                       os_free(data);
+                       return NULL;
+               }
+               os_memcpy(data->new_ap_settings, cfg->new_ap_settings,
+                         sizeof(*data->new_ap_settings));
+       }
+
+       if (cfg->peer_addr)
+               os_memcpy(data->peer_dev.mac_addr, cfg->peer_addr, ETH_ALEN);
+
        return data;
 }
 
@@ -115,6 +130,8 @@ void wps_deinit(struct wps_data *data)
        os_free(data->dev_password);
        os_free(data->new_psk);
        wps_device_data_free(&data->peer_dev);
+       os_free(data->new_ap_settings);
+       dh5_free(data->dh_ctx);
        os_free(data);
 }
 
@@ -341,3 +358,105 @@ void wps_free_pending_msgs(struct upnp_pending_message *msgs)
                os_free(prev);
        }
 }
+
+
+int wps_attr_text(struct wpabuf *data, char *buf, char *end)
+{
+       struct wps_parse_attr attr;
+       char *pos = buf;
+       int ret;
+
+       if (wps_parse_msg(data, &attr) < 0)
+               return -1;
+
+       if (attr.wps_state) {
+               if (*attr.wps_state == WPS_STATE_NOT_CONFIGURED)
+                       ret = os_snprintf(pos, end - pos,
+                                         "wps_state=unconfigured\n");
+               else if (*attr.wps_state == WPS_STATE_CONFIGURED)
+                       ret = os_snprintf(pos, end - pos,
+                                         "wps_state=configured\n");
+               else
+                       ret = 0;
+               if (ret < 0 || ret >= end - pos)
+                       return pos - buf;
+               pos += ret;
+       }
+
+       if (attr.ap_setup_locked && *attr.ap_setup_locked) {
+               ret = os_snprintf(pos, end - pos,
+                                 "wps_ap_setup_locked=1\n");
+               if (ret < 0 || ret >= end - pos)
+                       return pos - buf;
+               pos += ret;
+       }
+
+       if (attr.selected_registrar && *attr.selected_registrar) {
+               ret = os_snprintf(pos, end - pos,
+                                 "wps_selected_registrar=1\n");
+               if (ret < 0 || ret >= end - pos)
+                       return pos - buf;
+               pos += ret;
+       }
+
+       if (attr.dev_password_id) {
+               ret = os_snprintf(pos, end - pos,
+                                 "wps_device_password_id=%u\n",
+                                 WPA_GET_BE16(attr.dev_password_id));
+               if (ret < 0 || ret >= end - pos)
+                       return pos - buf;
+               pos += ret;
+       }
+
+       if (attr.sel_reg_config_methods) {
+               ret = os_snprintf(pos, end - pos,
+                                 "wps_selected_registrar_config_methods="
+                                 "0x%04x\n",
+                                 WPA_GET_BE16(attr.sel_reg_config_methods));
+               if (ret < 0 || ret >= end - pos)
+                       return pos - buf;
+               pos += ret;
+       }
+
+       if (attr.primary_dev_type) {
+               char devtype[WPS_DEV_TYPE_BUFSIZE];
+               ret = os_snprintf(pos, end - pos,
+                                 "wps_primary_device_type=%s\n",
+                                 wps_dev_type_bin2str(attr.primary_dev_type,
+                                                      devtype,
+                                                      sizeof(devtype)));
+               if (ret < 0 || ret >= end - pos)
+                       return pos - buf;
+               pos += ret;
+       }
+
+       if (attr.dev_name) {
+               char *str = os_malloc(attr.dev_name_len + 1);
+               size_t i;
+               if (str == NULL)
+                       return pos - buf;
+               for (i = 0; i < attr.dev_name_len; i++) {
+                       if (attr.dev_name[i] < 32)
+                               str[i] = '_';
+                       else
+                               str[i] = attr.dev_name[i];
+               }
+               str[i] = '\0';
+               ret = os_snprintf(pos, end - pos, "wps_device_name=%s\n", str);
+               os_free(str);
+               if (ret < 0 || ret >= end - pos)
+                       return pos - buf;
+               pos += ret;
+       }
+
+       if (attr.config_methods) {
+               ret = os_snprintf(pos, end - pos,
+                                 "wps_config_methods=0x%04x\n",
+                                 WPA_GET_BE16(attr.config_methods));
+               if (ret < 0 || ret >= end - pos)
+                       return pos - buf;
+               pos += ret;
+       }
+
+       return pos - buf;
+}