remove @EAP_LDFLAGS@, no longer exists
[mech_eap.orig] / libeap / wpa_supplicant / dbus / dbus_old_handlers_wps.c
1 /*
2  * WPA Supplicant / dbus-based control interface (WPS)
3  * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
4  *
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.
8  *
9  * Alternatively, this software may be distributed under the terms of BSD
10  * license.
11  *
12  * See README and COPYING for more details.
13  */
14
15 #include "includes.h"
16 #include <dbus/dbus.h>
17
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"
24
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)
31  *
32  * Handler function for "wpsPbc" method call
33  */
34 DBusMessage * wpas_dbus_iface_wps_pbc(DBusMessage *message,
35                                       struct wpa_supplicant *wpa_s)
36 {
37         char *arg_bssid = NULL;
38         u8 bssid[ETH_ALEN];
39         int ret = 0;
40
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);
44
45         if (!os_strcmp(arg_bssid, "any"))
46                 ret = wpas_wps_start_pbc(wpa_s, NULL, 0);
47         else if (!hwaddr_aton(arg_bssid, bssid))
48                 ret = wpas_wps_start_pbc(wpa_s, bssid, 0);
49         else {
50                 return wpas_dbus_new_invalid_opts_error(message,
51                                                         "Invalid BSSID");
52         }
53
54         if (ret < 0) {
55                 return dbus_message_new_error(message,
56                                               WPAS_ERROR_WPS_PBC_ERROR,
57                                               "Could not start PBC "
58                                               "negotiation");
59         }
60
61         return wpas_dbus_new_success_reply(message);
62 }
63
64
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)
71  *
72  * Handler function for "wpsPin" method call
73  */
74 DBusMessage * wpas_dbus_iface_wps_pin(DBusMessage *message,
75                                       struct wpa_supplicant *wpa_s)
76 {
77         DBusMessage *reply = NULL;
78         char *arg_bssid;
79         char *pin = NULL;
80         u8 bssid[ETH_ALEN], *_bssid = NULL;
81         int ret = 0;
82
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);
86
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");
94         }
95
96         if (os_strlen(pin) > 0)
97                 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
98                                          DEV_PW_DEFAULT);
99         else
100                 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0,
101                                          DEV_PW_DEFAULT);
102
103         if (ret < 0) {
104                 return dbus_message_new_error(message,
105                                               WPAS_ERROR_WPS_PIN_ERROR,
106                                               "Could not init PIN");
107         }
108
109         reply = dbus_message_new_method_return(message);
110         if (reply == NULL)
111                 return NULL;
112
113         if (ret == 0) {
114                 dbus_message_append_args(reply, DBUS_TYPE_STRING, &pin,
115                                          DBUS_TYPE_INVALID);
116         } else {
117                 char npin[9];
118                 os_snprintf(npin, sizeof(npin), "%08d", ret);
119                 dbus_message_append_args(reply, DBUS_TYPE_STRING, &npin,
120                                          DBUS_TYPE_INVALID);
121         }
122         return reply;
123 }
124
125
126 /**
127  * wpas_dbus_iface_wps_reg - Request credentials using the PIN of the AP
128  * @message: Pointer to incoming dbus message
129  * @wpa_s: %wpa_supplicant data structure
130  * Returns: A dbus message containing a UINT32 indicating success (1) or
131  *          failure (0)
132  *
133  * Handler function for "wpsReg" method call
134  */
135 DBusMessage * wpas_dbus_iface_wps_reg(DBusMessage *message,
136                                       struct wpa_supplicant *wpa_s)
137 {
138         char *arg_bssid;
139         char *pin = NULL;
140         u8 bssid[ETH_ALEN];
141         int ret = 0;
142
143         if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg_bssid,
144                                    DBUS_TYPE_STRING, &pin, DBUS_TYPE_INVALID))
145                 return wpas_dbus_new_invalid_opts_error(message, NULL);
146
147         if (!os_strcmp(arg_bssid, "any"))
148                 ret = wpas_wps_start_reg(wpa_s, NULL, pin, NULL);
149         else if (!hwaddr_aton(arg_bssid, bssid))
150                 ret = wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
151         else {
152                 return wpas_dbus_new_invalid_opts_error(message,
153                                                         "Invalid BSSID");
154         }
155
156         if (ret < 0) {
157                 return dbus_message_new_error(message,
158                                               WPAS_ERROR_WPS_PBC_ERROR,
159                                               "Could not request credentials");
160         }
161
162         return wpas_dbus_new_success_reply(message);
163 }