dbus: Verify dbus_message_new_method_return() return value before use
[hostap-gosc2009.git] / wpa_supplicant / dbus / dbus_handlers_wps.c
blob42bed1cc7f27df10cb4b58e83081e516bf5ce1ab
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"
17 #include "common.h"
18 #include "../config.h"
19 #include "../wpa_supplicant_i.h"
20 #include "../wps_supplicant.h"
21 #include "dbus.h"
22 #include "dbus_handlers.h"
24 /**
25 * wpas_dbus_iface_wps_pbc - Request credentials using WPS PBC method
26 * @message: Pointer to incoming dbus message
27 * @wpa_s: %wpa_supplicant data structure
28 * Returns: A dbus message containing a UINT32 indicating success (1) or
29 * failure (0)
31 * Handler function for "wpsPbc" method call
33 DBusMessage * wpas_dbus_iface_wps_pbc(DBusMessage *message,
34 struct wpa_supplicant *wpa_s)
36 char *arg_bssid = NULL;
37 u8 bssid[ETH_ALEN];
38 int ret = 0;
40 if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg_bssid,
41 DBUS_TYPE_INVALID))
42 return wpas_dbus_new_invalid_opts_error(message, NULL);
44 if (!os_strcmp(arg_bssid, "any"))
45 ret = wpas_wps_start_pbc(wpa_s, NULL);
46 else if (!hwaddr_aton(arg_bssid, bssid))
47 ret = wpas_wps_start_pbc(wpa_s, bssid);
48 else {
49 return wpas_dbus_new_invalid_opts_error(message,
50 "Invalid BSSID");
53 if (ret < 0) {
54 return dbus_message_new_error(message,
55 WPAS_ERROR_WPS_PBC_ERROR,
56 "Could not start PBC "
57 "negotiation");
60 return wpas_dbus_new_success_reply(message);
64 /**
65 * wpas_dbus_iface_wps_pin - Establish the PIN number of the enrollee
66 * @message: Pointer to incoming dbus message
67 * @wpa_s: %wpa_supplicant data structure
68 * Returns: A dbus message containing a UINT32 indicating success (1) or
69 * failure (0)
71 * Handler function for "wpsPin" method call
73 DBusMessage * wpas_dbus_iface_wps_pin(DBusMessage *message,
74 struct wpa_supplicant *wpa_s)
76 DBusMessage *reply = NULL;
77 char *arg_bssid;
78 char *pin = NULL;
79 u8 bssid[ETH_ALEN], *_bssid = NULL;
80 int ret = 0;
82 if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg_bssid,
83 DBUS_TYPE_STRING, &pin, DBUS_TYPE_INVALID))
84 return wpas_dbus_new_invalid_opts_error(message, NULL);
86 if (!os_strcmp(arg_bssid, "any"))
87 _bssid = NULL;
88 else if (!hwaddr_aton(arg_bssid, bssid))
89 _bssid = bssid;
90 else {
91 return wpas_dbus_new_invalid_opts_error(message,
92 "Invalid BSSID");
95 if (os_strlen(pin) > 0)
96 ret = wpas_wps_start_pin(wpa_s, _bssid, pin);
97 else
98 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL);
100 if (ret < 0) {
101 return dbus_message_new_error(message,
102 WPAS_ERROR_WPS_PIN_ERROR,
103 "Could not init PIN");
106 reply = dbus_message_new_method_return(message);
107 if (reply == NULL)
108 return NULL;
110 if (ret == 0) {
111 dbus_message_append_args(reply, DBUS_TYPE_STRING, &pin,
112 DBUS_TYPE_INVALID);
113 } else {
114 char npin[9];
115 os_snprintf(npin, sizeof(npin), "%08d", ret);
116 dbus_message_append_args(reply, DBUS_TYPE_STRING, &npin,
117 DBUS_TYPE_INVALID);
119 return reply;
124 * wpas_dbus_iface_wps_reg - Request credentials using the PIN of the AP
125 * @message: Pointer to incoming dbus message
126 * @wpa_s: %wpa_supplicant data structure
127 * Returns: A dbus message containing a UINT32 indicating success (1) or
128 * failure (0)
130 * Handler function for "wpsReg" method call
132 DBusMessage * wpas_dbus_iface_wps_reg(DBusMessage *message,
133 struct wpa_supplicant *wpa_s)
135 char *arg_bssid;
136 char *pin = NULL;
137 u8 bssid[ETH_ALEN];
138 int ret = 0;
140 if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg_bssid,
141 DBUS_TYPE_STRING, &pin, DBUS_TYPE_INVALID))
142 return wpas_dbus_new_invalid_opts_error(message, NULL);
144 if (!os_strcmp(arg_bssid, "any"))
145 ret = wpas_wps_start_reg(wpa_s, NULL, pin, NULL);
146 else if (!hwaddr_aton(arg_bssid, bssid))
147 ret = wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
148 else {
149 return wpas_dbus_new_invalid_opts_error(message,
150 "Invalid BSSID");
153 if (ret < 0) {
154 return dbus_message_new_error(message,
155 WPAS_ERROR_WPS_PBC_ERROR,
156 "Could not request credentials");
159 return wpas_dbus_new_success_reply(message);