Added WirelessManager, a port of wpa_supplicant.
[AROS.git] / workbench / network / WirelessManager / wpa_supplicant / dbus / dbus_old_handlers_wps.c
blobb5879f3ae8fba0602f3c7446172790d8fc2c30c4
1 /*
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
10 * license.
12 * See README and COPYING for more details.
15 #include "includes.h"
16 #include <dbus/dbus.h>
18 #include "common.h"
19 #include "../config.h"
20 #include "../wpa_supplicant_i.h"
21 #include "../wps_supplicant.h"
22 #include "dbus_old.h"
23 #include "dbus_old_handlers.h"
25 /**
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
30 * failure (0)
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;
38 u8 bssid[ETH_ALEN];
39 int ret = 0;
41 if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg_bssid,
42 DBUS_TYPE_INVALID))
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);
49 else {
50 return wpas_dbus_new_invalid_opts_error(message,
51 "Invalid BSSID");
54 if (ret < 0) {
55 return dbus_message_new_error(message,
56 WPAS_ERROR_WPS_PBC_ERROR,
57 "Could not start PBC "
58 "negotiation");
61 return wpas_dbus_new_success_reply(message);
65 /**
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
70 * failure (0)
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;
78 char *arg_bssid;
79 char *pin = NULL;
80 u8 bssid[ETH_ALEN], *_bssid = NULL;
81 int ret = 0;
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"))
88 _bssid = NULL;
89 else if (!hwaddr_aton(arg_bssid, bssid))
90 _bssid = bssid;
91 else {
92 return wpas_dbus_new_invalid_opts_error(message,
93 "Invalid BSSID");
96 if (os_strlen(pin) > 0)
97 ret = wpas_wps_start_pin(wpa_s, _bssid, pin);
98 else
99 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL);
101 if (ret < 0) {
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);
108 if (reply == NULL)
109 return NULL;
111 if (ret == 0) {
112 dbus_message_append_args(reply, DBUS_TYPE_STRING, &pin,
113 DBUS_TYPE_INVALID);
114 } else {
115 char npin[9];
116 os_snprintf(npin, sizeof(npin), "%08d", ret);
117 dbus_message_append_args(reply, DBUS_TYPE_STRING, &npin,
118 DBUS_TYPE_INVALID);
120 return reply;
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
129 * failure (0)
131 * Handler function for "wpsReg" method call
133 DBusMessage * wpas_dbus_iface_wps_reg(DBusMessage *message,
134 struct wpa_supplicant *wpa_s)
136 char *arg_bssid;
137 char *pin = NULL;
138 u8 bssid[ETH_ALEN];
139 int ret = 0;
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);
149 else {
150 return wpas_dbus_new_invalid_opts_error(message,
151 "Invalid BSSID");
154 if (ret < 0) {
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);