$search
00001 /* 00002 * WPA Supplicant / dbus-based control interface (WPS) 00003 * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc. 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation. 00008 * 00009 * Alternatively, this software may be distributed under the terms of BSD 00010 * license. 00011 * 00012 * See README and COPYING for more details. 00013 */ 00014 00015 #include "includes.h" 00016 #include <dbus/dbus.h> 00017 00018 #include "common.h" 00019 #include "../config.h" 00020 #include "../wpa_supplicant_i.h" 00021 #include "../wps_supplicant.h" 00022 #include "dbus_old.h" 00023 #include "dbus_old_handlers.h" 00024 00034 DBusMessage * wpas_dbus_iface_wps_pbc(DBusMessage *message, 00035 struct wpa_supplicant *wpa_s) 00036 { 00037 char *arg_bssid = NULL; 00038 u8 bssid[ETH_ALEN]; 00039 int ret = 0; 00040 00041 if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg_bssid, 00042 DBUS_TYPE_INVALID)) 00043 return wpas_dbus_new_invalid_opts_error(message, NULL); 00044 00045 if (!os_strcmp(arg_bssid, "any")) 00046 ret = wpas_wps_start_pbc(wpa_s, NULL); 00047 else if (!hwaddr_aton(arg_bssid, bssid)) 00048 ret = wpas_wps_start_pbc(wpa_s, bssid); 00049 else { 00050 return wpas_dbus_new_invalid_opts_error(message, 00051 "Invalid BSSID"); 00052 } 00053 00054 if (ret < 0) { 00055 return dbus_message_new_error(message, 00056 WPAS_ERROR_WPS_PBC_ERROR, 00057 "Could not start PBC " 00058 "negotiation"); 00059 } 00060 00061 return wpas_dbus_new_success_reply(message); 00062 } 00063 00064 00074 DBusMessage * wpas_dbus_iface_wps_pin(DBusMessage *message, 00075 struct wpa_supplicant *wpa_s) 00076 { 00077 DBusMessage *reply = NULL; 00078 char *arg_bssid; 00079 char *pin = NULL; 00080 u8 bssid[ETH_ALEN], *_bssid = NULL; 00081 int ret = 0; 00082 00083 if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg_bssid, 00084 DBUS_TYPE_STRING, &pin, DBUS_TYPE_INVALID)) 00085 return wpas_dbus_new_invalid_opts_error(message, NULL); 00086 00087 if (!os_strcmp(arg_bssid, "any")) 00088 _bssid = NULL; 00089 else if (!hwaddr_aton(arg_bssid, bssid)) 00090 _bssid = bssid; 00091 else { 00092 return wpas_dbus_new_invalid_opts_error(message, 00093 "Invalid BSSID"); 00094 } 00095 00096 if (os_strlen(pin) > 0) 00097 ret = wpas_wps_start_pin(wpa_s, _bssid, pin); 00098 else 00099 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL); 00100 00101 if (ret < 0) { 00102 return dbus_message_new_error(message, 00103 WPAS_ERROR_WPS_PIN_ERROR, 00104 "Could not init PIN"); 00105 } 00106 00107 reply = dbus_message_new_method_return(message); 00108 if (reply == NULL) 00109 return NULL; 00110 00111 if (ret == 0) { 00112 dbus_message_append_args(reply, DBUS_TYPE_STRING, &pin, 00113 DBUS_TYPE_INVALID); 00114 } else { 00115 char npin[9]; 00116 os_snprintf(npin, sizeof(npin), "%08d", ret); 00117 dbus_message_append_args(reply, DBUS_TYPE_STRING, &npin, 00118 DBUS_TYPE_INVALID); 00119 } 00120 return reply; 00121 } 00122 00123 00133 DBusMessage * wpas_dbus_iface_wps_reg(DBusMessage *message, 00134 struct wpa_supplicant *wpa_s) 00135 { 00136 char *arg_bssid; 00137 char *pin = NULL; 00138 u8 bssid[ETH_ALEN]; 00139 int ret = 0; 00140 00141 if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg_bssid, 00142 DBUS_TYPE_STRING, &pin, DBUS_TYPE_INVALID)) 00143 return wpas_dbus_new_invalid_opts_error(message, NULL); 00144 00145 if (!os_strcmp(arg_bssid, "any")) 00146 ret = wpas_wps_start_reg(wpa_s, NULL, pin, NULL); 00147 else if (!hwaddr_aton(arg_bssid, bssid)) 00148 ret = wpas_wps_start_reg(wpa_s, bssid, pin, NULL); 00149 else { 00150 return wpas_dbus_new_invalid_opts_error(message, 00151 "Invalid BSSID"); 00152 } 00153 00154 if (ret < 0) { 00155 return dbus_message_new_error(message, 00156 WPAS_ERROR_WPS_PBC_ERROR, 00157 "Could not request credentials"); 00158 } 00159 00160 return wpas_dbus_new_success_reply(message); 00161 }