2 * WPA Supplicant / dbus-based control interface (WPS)
3 * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
16 #include <dbus/dbus.h>
19 #include "../config.h"
20 #include "../wpa_supplicant_i.h"
21 #include "../wps_supplicant.h"
23 #include "dbus_old_handlers.h"
26 * wpas_dbus_iface_wps_pbc - Request credentials using WPS PBC method
27 * @message: Pointer to incoming dbus message
28 * @wpa_s: %wpa_supplicant data structure
29 * Returns: A dbus message containing a UINT32 indicating success (1) or
32 * Handler function for "wpsPbc" method call
34 DBusMessage
* wpas_dbus_iface_wps_pbc(DBusMessage
*message
,
35 struct wpa_supplicant
*wpa_s
)
37 char *arg_bssid
= NULL
;
41 if (!dbus_message_get_args(message
, NULL
, DBUS_TYPE_STRING
, &arg_bssid
,
43 return wpas_dbus_new_invalid_opts_error(message
, NULL
);
45 if (!os_strcmp(arg_bssid
, "any"))
46 ret
= wpas_wps_start_pbc(wpa_s
, NULL
);
47 else if (!hwaddr_aton(arg_bssid
, bssid
))
48 ret
= wpas_wps_start_pbc(wpa_s
, bssid
);
50 return wpas_dbus_new_invalid_opts_error(message
,
55 return dbus_message_new_error(message
,
56 WPAS_ERROR_WPS_PBC_ERROR
,
57 "Could not start PBC "
61 return wpas_dbus_new_success_reply(message
);
66 * wpas_dbus_iface_wps_pin - Establish the PIN number of the enrollee
67 * @message: Pointer to incoming dbus message
68 * @wpa_s: %wpa_supplicant data structure
69 * Returns: A dbus message containing a UINT32 indicating success (1) or
72 * Handler function for "wpsPin" method call
74 DBusMessage
* wpas_dbus_iface_wps_pin(DBusMessage
*message
,
75 struct wpa_supplicant
*wpa_s
)
77 DBusMessage
*reply
= NULL
;
80 u8 bssid
[ETH_ALEN
], *_bssid
= NULL
;
83 if (!dbus_message_get_args(message
, NULL
, DBUS_TYPE_STRING
, &arg_bssid
,
84 DBUS_TYPE_STRING
, &pin
, DBUS_TYPE_INVALID
))
85 return wpas_dbus_new_invalid_opts_error(message
, NULL
);
87 if (!os_strcmp(arg_bssid
, "any"))
89 else if (!hwaddr_aton(arg_bssid
, bssid
))
92 return wpas_dbus_new_invalid_opts_error(message
,
96 if (os_strlen(pin
) > 0)
97 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, pin
);
99 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, NULL
);
102 return dbus_message_new_error(message
,
103 WPAS_ERROR_WPS_PIN_ERROR
,
104 "Could not init PIN");
107 reply
= dbus_message_new_method_return(message
);
112 dbus_message_append_args(reply
, DBUS_TYPE_STRING
, &pin
,
116 os_snprintf(npin
, sizeof(npin
), "%08d", ret
);
117 dbus_message_append_args(reply
, DBUS_TYPE_STRING
, &npin
,
125 * wpas_dbus_iface_wps_reg - Request credentials using the PIN of the AP
126 * @message: Pointer to incoming dbus message
127 * @wpa_s: %wpa_supplicant data structure
128 * Returns: A dbus message containing a UINT32 indicating success (1) or
131 * Handler function for "wpsReg" method call
133 DBusMessage
* wpas_dbus_iface_wps_reg(DBusMessage
*message
,
134 struct wpa_supplicant
*wpa_s
)
141 if (!dbus_message_get_args(message
, NULL
, DBUS_TYPE_STRING
, &arg_bssid
,
142 DBUS_TYPE_STRING
, &pin
, DBUS_TYPE_INVALID
))
143 return wpas_dbus_new_invalid_opts_error(message
, NULL
);
145 if (!os_strcmp(arg_bssid
, "any"))
146 ret
= wpas_wps_start_reg(wpa_s
, NULL
, pin
, NULL
);
147 else if (!hwaddr_aton(arg_bssid
, bssid
))
148 ret
= wpas_wps_start_reg(wpa_s
, bssid
, pin
, NULL
);
150 return wpas_dbus_new_invalid_opts_error(message
,
155 return dbus_message_new_error(message
,
156 WPAS_ERROR_WPS_PBC_ERROR
,
157 "Could not request credentials");
160 return wpas_dbus_new_success_reply(message
);