dbus_new_handlers_wps.c (214501) | dbus_new_handlers_wps.c (252190) |
---|---|
1/* 2 * WPA Supplicant / dbus-based control interface (WPS) 3 * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc. 4 * Copyright (c) 2009, Witold Sowa <witold.sowa@gmail.com> 5 * | 1/* 2 * WPA Supplicant / dbus-based control interface (WPS) 3 * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc. 4 * Copyright (c) 2009, Witold Sowa <witold.sowa@gmail.com> 5 * |
6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 2 as 8 * published by the Free Software Foundation. 9 * 10 * Alternatively, this software may be distributed under the terms of BSD 11 * license. 12 * 13 * See README and COPYING for more details. | 6 * This software may be distributed under the terms of the BSD license. 7 * See README for more details. |
14 */ 15 16#include "includes.h" 17 18#include "common.h" 19#include "../config.h" 20#include "../wpa_supplicant_i.h" 21#include "../wps_supplicant.h" | 8 */ 9 10#include "includes.h" 11 12#include "common.h" 13#include "../config.h" 14#include "../wpa_supplicant_i.h" 15#include "../wps_supplicant.h" |
16#include "../driver_i.h" 17#include "../ap.h" |
|
22#include "dbus_new_helpers.h" 23#include "dbus_new.h" 24#include "dbus_new_handlers.h" 25#include "dbus_dict_helpers.h" 26 27 28struct wps_start_params { 29 int role; /* 0 - not set, 1 - enrollee, 2 - registrar */ 30 int type; /* 0 - not set, 1 - pin, 2 - pbc */ 31 u8 *bssid; 32 char *pin; | 18#include "dbus_new_helpers.h" 19#include "dbus_new.h" 20#include "dbus_new_handlers.h" 21#include "dbus_dict_helpers.h" 22 23 24struct wps_start_params { 25 int role; /* 0 - not set, 1 - enrollee, 2 - registrar */ 26 int type; /* 0 - not set, 1 - pin, 2 - pbc */ 27 u8 *bssid; 28 char *pin; |
29 u8 *p2p_dev_addr; |
|
33}; 34 35 36static int wpas_dbus_handler_wps_role(DBusMessage *message, 37 DBusMessageIter *entry_iter, 38 struct wps_start_params *params, 39 DBusMessage **reply) 40{ --- 61 unchanged lines hidden (view full) --- 102 DBusMessage **reply) 103{ 104 DBusMessageIter variant_iter, array_iter; 105 int len; 106 107 dbus_message_iter_recurse(entry_iter, &variant_iter); 108 if (dbus_message_iter_get_arg_type(&variant_iter) != DBUS_TYPE_ARRAY || 109 dbus_message_iter_get_element_type(&variant_iter) != | 30}; 31 32 33static int wpas_dbus_handler_wps_role(DBusMessage *message, 34 DBusMessageIter *entry_iter, 35 struct wps_start_params *params, 36 DBusMessage **reply) 37{ --- 61 unchanged lines hidden (view full) --- 99 DBusMessage **reply) 100{ 101 DBusMessageIter variant_iter, array_iter; 102 int len; 103 104 dbus_message_iter_recurse(entry_iter, &variant_iter); 105 if (dbus_message_iter_get_arg_type(&variant_iter) != DBUS_TYPE_ARRAY || 106 dbus_message_iter_get_element_type(&variant_iter) != |
110 DBUS_TYPE_ARRAY) { | 107 DBUS_TYPE_BYTE) { |
111 wpa_printf(MSG_DEBUG, "dbus: WPS.Start - Wrong Bssid type, " 112 "byte array required"); 113 *reply = wpas_dbus_error_invalid_args( 114 message, "Bssid must be a byte array"); 115 return -1; 116 } 117 dbus_message_iter_recurse(&variant_iter, &array_iter); 118 dbus_message_iter_get_fixed_array(&array_iter, ¶ms->bssid, &len); --- 24 unchanged lines hidden (view full) --- 143 "Pin must be a string"); 144 return -1; 145 } 146 dbus_message_iter_get_basic(&variant_iter, ¶ms->pin); 147 return 0; 148} 149 150 | 108 wpa_printf(MSG_DEBUG, "dbus: WPS.Start - Wrong Bssid type, " 109 "byte array required"); 110 *reply = wpas_dbus_error_invalid_args( 111 message, "Bssid must be a byte array"); 112 return -1; 113 } 114 dbus_message_iter_recurse(&variant_iter, &array_iter); 115 dbus_message_iter_get_fixed_array(&array_iter, ¶ms->bssid, &len); --- 24 unchanged lines hidden (view full) --- 140 "Pin must be a string"); 141 return -1; 142 } 143 dbus_message_iter_get_basic(&variant_iter, ¶ms->pin); 144 return 0; 145} 146 147 |
148#ifdef CONFIG_P2P 149static int wpas_dbus_handler_wps_p2p_dev_addr(DBusMessage *message, 150 DBusMessageIter *entry_iter, 151 struct wps_start_params *params, 152 DBusMessage **reply) 153{ 154 DBusMessageIter variant_iter, array_iter; 155 int len; 156 157 dbus_message_iter_recurse(entry_iter, &variant_iter); 158 if (dbus_message_iter_get_arg_type(&variant_iter) != DBUS_TYPE_ARRAY || 159 dbus_message_iter_get_element_type(&variant_iter) != 160 DBUS_TYPE_BYTE) { 161 wpa_printf(MSG_DEBUG, "dbus: WPS.Start - Wrong " 162 "P2PDeviceAddress type, byte array required"); 163 *reply = wpas_dbus_error_invalid_args( 164 message, "P2PDeviceAddress must be a byte array"); 165 return -1; 166 } 167 dbus_message_iter_recurse(&variant_iter, &array_iter); 168 dbus_message_iter_get_fixed_array(&array_iter, ¶ms->p2p_dev_addr, 169 &len); 170 if (len != ETH_ALEN) { 171 wpa_printf(MSG_DEBUG, "dbus: WPS.Start - Wrong " 172 "P2PDeviceAddress length %d", len); 173 *reply = wpas_dbus_error_invalid_args(message, 174 "P2PDeviceAddress " 175 "has wrong length"); 176 return -1; 177 } 178 return 0; 179} 180#endif /* CONFIG_P2P */ 181 182 |
|
151static int wpas_dbus_handler_wps_start_entry(DBusMessage *message, char *key, 152 DBusMessageIter *entry_iter, 153 struct wps_start_params *params, 154 DBusMessage **reply) 155{ 156 if (os_strcmp(key, "Role") == 0) 157 return wpas_dbus_handler_wps_role(message, entry_iter, 158 params, reply); 159 else if (os_strcmp(key, "Type") == 0) 160 return wpas_dbus_handler_wps_type(message, entry_iter, 161 params, reply); 162 else if (os_strcmp(key, "Bssid") == 0) 163 return wpas_dbus_handler_wps_bssid(message, entry_iter, 164 params, reply); 165 else if (os_strcmp(key, "Pin") == 0) 166 return wpas_dbus_handler_wps_pin(message, entry_iter, 167 params, reply); | 183static int wpas_dbus_handler_wps_start_entry(DBusMessage *message, char *key, 184 DBusMessageIter *entry_iter, 185 struct wps_start_params *params, 186 DBusMessage **reply) 187{ 188 if (os_strcmp(key, "Role") == 0) 189 return wpas_dbus_handler_wps_role(message, entry_iter, 190 params, reply); 191 else if (os_strcmp(key, "Type") == 0) 192 return wpas_dbus_handler_wps_type(message, entry_iter, 193 params, reply); 194 else if (os_strcmp(key, "Bssid") == 0) 195 return wpas_dbus_handler_wps_bssid(message, entry_iter, 196 params, reply); 197 else if (os_strcmp(key, "Pin") == 0) 198 return wpas_dbus_handler_wps_pin(message, entry_iter, 199 params, reply); |
200#ifdef CONFIG_P2P 201 else if (os_strcmp(key, "P2PDeviceAddress") == 0) 202 return wpas_dbus_handler_wps_p2p_dev_addr(message, entry_iter, 203 params, reply); 204#endif /* CONFIG_P2P */ |
|
168 169 wpa_printf(MSG_DEBUG, "dbus: WPS.Start - unknown key %s", key); 170 *reply = wpas_dbus_error_invalid_args(message, key); 171 return -1; 172} 173 174 175/** --- 50 unchanged lines hidden (view full) --- 226 return wpas_dbus_error_invalid_args( 227 message, "Pin required for registrar role."); 228 } 229 230 if (params.role == 2) 231 ret = wpas_wps_start_reg(wpa_s, params.bssid, params.pin, 232 NULL); 233 else if (params.type == 1) { | 205 206 wpa_printf(MSG_DEBUG, "dbus: WPS.Start - unknown key %s", key); 207 *reply = wpas_dbus_error_invalid_args(message, key); 208 return -1; 209} 210 211 212/** --- 50 unchanged lines hidden (view full) --- 263 return wpas_dbus_error_invalid_args( 264 message, "Pin required for registrar role."); 265 } 266 267 if (params.role == 2) 268 ret = wpas_wps_start_reg(wpa_s, params.bssid, params.pin, 269 NULL); 270 else if (params.type == 1) { |
234 ret = wpas_wps_start_pin(wpa_s, params.bssid, params.pin); 235 if (ret > 0) 236 os_snprintf(npin, sizeof(npin), "%08d", ret); 237 } else 238 ret = wpas_wps_start_pbc(wpa_s, params.bssid); | 271#ifdef CONFIG_AP 272 if (wpa_s->ap_iface) 273 ret = wpa_supplicant_ap_wps_pin(wpa_s, 274 params.bssid, 275 params.pin, 276 npin, sizeof(npin), 0); 277 else 278#endif /* CONFIG_AP */ 279 { 280 ret = wpas_wps_start_pin(wpa_s, params.bssid, 281 params.pin, 0, 282 DEV_PW_DEFAULT); 283 if (ret > 0) 284 os_snprintf(npin, sizeof(npin), "%08d", ret); 285 } 286 } else { 287#ifdef CONFIG_AP 288 if (wpa_s->ap_iface) 289 ret = wpa_supplicant_ap_wps_pbc(wpa_s, 290 params.bssid, 291 params.p2p_dev_addr); 292 else 293#endif /* CONFIG_AP */ 294 ret = wpas_wps_start_pbc(wpa_s, params.bssid, 0); 295 } |
239 240 if (ret < 0) { 241 wpa_printf(MSG_DEBUG, "dbus: WPS.Start wpas_wps_failed in " 242 "role %s and key %s", 243 (params.role == 1 ? "enrollee" : "registrar"), 244 (params.type == 0 ? "" : 245 (params.type == 1 ? "pin" : "pbc"))); 246 return wpas_dbus_error_unknown_error(message, --- 31 unchanged lines hidden (view full) --- 278 return reply; 279} 280 281 282/** 283 * wpas_dbus_getter_process_credentials - Check if credentials are processed 284 * @message: Pointer to incoming dbus message 285 * @wpa_s: %wpa_supplicant data structure | 296 297 if (ret < 0) { 298 wpa_printf(MSG_DEBUG, "dbus: WPS.Start wpas_wps_failed in " 299 "role %s and key %s", 300 (params.role == 1 ? "enrollee" : "registrar"), 301 (params.type == 0 ? "" : 302 (params.type == 1 ? "pin" : "pbc"))); 303 return wpas_dbus_error_unknown_error(message, --- 31 unchanged lines hidden (view full) --- 335 return reply; 336} 337 338 339/** 340 * wpas_dbus_getter_process_credentials - Check if credentials are processed 341 * @message: Pointer to incoming dbus message 342 * @wpa_s: %wpa_supplicant data structure |
286 * Returns: DBus message with a boolean on success or DBus error on failure | 343 * Returns: TRUE on success, FALSE on failure |
287 * 288 * Getter for "ProcessCredentials" property. Returns returned boolean will be 289 * true if wps_cred_processing configuration field is not equal to 1 or false 290 * if otherwise. 291 */ | 344 * 345 * Getter for "ProcessCredentials" property. Returns returned boolean will be 346 * true if wps_cred_processing configuration field is not equal to 1 or false 347 * if otherwise. 348 */ |
292DBusMessage * wpas_dbus_getter_process_credentials( 293 DBusMessage *message, struct wpa_supplicant *wpa_s) | 349dbus_bool_t wpas_dbus_getter_process_credentials(DBusMessageIter *iter, 350 DBusError *error, 351 void *user_data) |
294{ | 352{ |
353 struct wpa_supplicant *wpa_s = user_data; |
|
295 dbus_bool_t process = (wpa_s->conf->wps_cred_processing != 1); | 354 dbus_bool_t process = (wpa_s->conf->wps_cred_processing != 1); |
296 return wpas_dbus_simple_property_getter(message, DBUS_TYPE_BOOLEAN, 297 &process); | 355 return wpas_dbus_simple_property_getter(iter, DBUS_TYPE_BOOLEAN, 356 &process, error); |
298} 299 300 301/** 302 * wpas_dbus_setter_process_credentials - Set credentials_processed conf param | 357} 358 359 360/** 361 * wpas_dbus_setter_process_credentials - Set credentials_processed conf param |
303 * @message: Pointer to incoming dbus message 304 * @wpa_s: %wpa_supplicant data structure 305 * Returns: NULL on success or DBus error on failure | 362 * @iter: Pointer to incoming dbus message iter 363 * @error: Location to store error on failure 364 * @user_data: Function specific data 365 * Returns: TRUE on success, FALSE on failure |
306 * 307 * Setter for "ProcessCredentials" property. Sets credentials_processed on 2 308 * if boolean argument is true or on 1 if otherwise. 309 */ | 366 * 367 * Setter for "ProcessCredentials" property. Sets credentials_processed on 2 368 * if boolean argument is true or on 1 if otherwise. 369 */ |
310DBusMessage * wpas_dbus_setter_process_credentials( 311 DBusMessage *message, struct wpa_supplicant *wpa_s) | 370dbus_bool_t wpas_dbus_setter_process_credentials(DBusMessageIter *iter, 371 DBusError *error, 372 void *user_data) |
312{ | 373{ |
313 DBusMessage *reply = NULL; | 374 struct wpa_supplicant *wpa_s = user_data; |
314 dbus_bool_t process_credentials, old_pc; 315 | 375 dbus_bool_t process_credentials, old_pc; 376 |
316 reply = wpas_dbus_simple_property_setter(message, DBUS_TYPE_BOOLEAN, 317 &process_credentials); 318 if (reply) 319 return reply; | 377 if (!wpas_dbus_simple_property_setter(iter, error, DBUS_TYPE_BOOLEAN, 378 &process_credentials)) 379 return FALSE; |
320 321 old_pc = (wpa_s->conf->wps_cred_processing != 1); 322 wpa_s->conf->wps_cred_processing = (process_credentials ? 2 : 1); 323 324 if ((wpa_s->conf->wps_cred_processing != 1) != old_pc) 325 wpa_dbus_mark_property_changed(wpa_s->global->dbus, 326 wpa_s->dbus_new_path, 327 WPAS_DBUS_NEW_IFACE_WPS, 328 "ProcessCredentials"); 329 | 380 381 old_pc = (wpa_s->conf->wps_cred_processing != 1); 382 wpa_s->conf->wps_cred_processing = (process_credentials ? 2 : 1); 383 384 if ((wpa_s->conf->wps_cred_processing != 1) != old_pc) 385 wpa_dbus_mark_property_changed(wpa_s->global->dbus, 386 wpa_s->dbus_new_path, 387 WPAS_DBUS_NEW_IFACE_WPS, 388 "ProcessCredentials"); 389 |
330 return NULL; | 390 return TRUE; |
331} | 391} |