2015-09-28 17:54:45 +02:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Wireless daemon for Linux
|
|
|
|
*
|
2019-10-25 00:43:08 +02:00
|
|
|
* Copyright (C) 2015-2019 Intel Corporation. All rights reserved.
|
2015-09-28 17:54:45 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <errno.h>
|
2017-02-23 00:03:44 +01:00
|
|
|
#include <stdio.h>
|
2015-09-28 17:54:45 +02:00
|
|
|
#include <ell/ell.h>
|
|
|
|
|
2021-07-06 20:38:56 +02:00
|
|
|
#include "ell/useful.h"
|
2019-04-03 18:34:22 +02:00
|
|
|
#include "src/missing.h"
|
2019-11-07 23:33:51 +01:00
|
|
|
#include "src/module.h"
|
2016-05-05 19:07:46 +02:00
|
|
|
#include "src/dbus.h"
|
|
|
|
#include "src/netdev.h"
|
|
|
|
#include "src/wiphy.h"
|
2018-09-04 17:40:45 +02:00
|
|
|
#include "src/station.h"
|
2016-05-05 19:07:46 +02:00
|
|
|
#include "src/scan.h"
|
|
|
|
#include "src/ie.h"
|
|
|
|
#include "src/wscutil.h"
|
|
|
|
#include "src/util.h"
|
2016-11-02 23:46:19 +01:00
|
|
|
#include "src/handshake.h"
|
2016-09-15 04:17:41 +02:00
|
|
|
#include "src/eap-wsc.h"
|
2016-09-21 20:50:51 +02:00
|
|
|
#include "src/common.h"
|
2016-09-21 23:21:28 +02:00
|
|
|
#include "src/storage.h"
|
2016-09-21 20:50:51 +02:00
|
|
|
#include "src/iwd.h"
|
2016-09-21 23:21:53 +02:00
|
|
|
#include "src/network.h"
|
2019-12-05 04:22:40 +01:00
|
|
|
#include "src/wsc.h"
|
2021-11-30 00:12:59 +01:00
|
|
|
#include "src/band.h"
|
2015-09-28 17:54:45 +02:00
|
|
|
|
|
|
|
#define WALK_TIME 120
|
|
|
|
|
2018-08-18 06:40:49 +02:00
|
|
|
static uint32_t netdev_watch = 0;
|
2015-09-29 03:38:17 +02:00
|
|
|
|
2020-01-16 05:29:29 +01:00
|
|
|
struct wsc_enrollee {
|
|
|
|
struct netdev *netdev;
|
|
|
|
struct wsc_credentials_info creds[3];
|
|
|
|
uint32_t n_creds;
|
|
|
|
struct l_settings *eap_settings;
|
|
|
|
wsc_done_cb_t done_cb;
|
|
|
|
void *done_data;
|
|
|
|
bool disconnecting : 1;
|
|
|
|
};
|
|
|
|
|
2016-09-13 21:55:13 +02:00
|
|
|
static struct l_dbus_message *wsc_error_session_overlap(
|
|
|
|
struct l_dbus_message *msg)
|
|
|
|
{
|
|
|
|
return l_dbus_message_new_error(msg,
|
|
|
|
IWD_WSC_INTERFACE ".SessionOverlap",
|
|
|
|
"Multiple sessions detected");
|
|
|
|
}
|
|
|
|
|
2016-09-21 23:21:28 +02:00
|
|
|
static struct l_dbus_message *wsc_error_no_credentials(
|
|
|
|
struct l_dbus_message *msg)
|
|
|
|
{
|
|
|
|
return l_dbus_message_new_error(msg, IWD_WSC_INTERFACE ".NoCredentials",
|
|
|
|
"No usable credentials obtained");
|
|
|
|
}
|
|
|
|
|
2016-09-21 23:21:53 +02:00
|
|
|
static struct l_dbus_message *wsc_error_not_reachable(
|
|
|
|
struct l_dbus_message *msg)
|
|
|
|
{
|
|
|
|
return l_dbus_message_new_error(msg, IWD_WSC_INTERFACE ".NotReachable",
|
|
|
|
"Credentials obtained, but network is "
|
|
|
|
"unreachable");
|
|
|
|
}
|
|
|
|
|
2016-09-22 18:32:18 +02:00
|
|
|
static struct l_dbus_message *wsc_error_walk_time_expired(
|
|
|
|
struct l_dbus_message *msg)
|
|
|
|
{
|
|
|
|
return l_dbus_message_new_error(msg,
|
|
|
|
IWD_WSC_INTERFACE ".WalkTimeExpired",
|
|
|
|
"No APs in PushButton mode found in "
|
2020-01-21 07:21:38 +01:00
|
|
|
"the allotted time");
|
2016-09-22 18:32:18 +02:00
|
|
|
}
|
|
|
|
|
2017-02-23 00:03:44 +01:00
|
|
|
static struct l_dbus_message *wsc_error_time_expired(struct l_dbus_message *msg)
|
|
|
|
{
|
|
|
|
return l_dbus_message_new_error(msg,
|
|
|
|
IWD_WSC_INTERFACE ".TimeExpired",
|
|
|
|
"No APs in PIN mode found in "
|
2020-01-21 07:21:38 +01:00
|
|
|
"the allotted time");
|
2017-02-23 00:03:44 +01:00
|
|
|
}
|
2016-09-21 23:21:53 +02:00
|
|
|
|
2020-01-16 05:29:29 +01:00
|
|
|
static void wsc_enrollee_connect_cb(struct netdev *netdev,
|
|
|
|
enum netdev_result result,
|
2019-02-28 18:32:40 +01:00
|
|
|
void *event_data, void *user_data)
|
2016-09-15 04:17:41 +02:00
|
|
|
{
|
2020-01-16 05:29:29 +01:00
|
|
|
struct wsc_enrollee *wsce = user_data;
|
2016-09-15 04:17:41 +02:00
|
|
|
|
2020-01-16 05:29:29 +01:00
|
|
|
l_debug("%d, result: %d", netdev_get_ifindex(wsce->netdev), result);
|
2016-09-15 04:17:41 +02:00
|
|
|
|
2020-01-16 05:29:29 +01:00
|
|
|
if (wsce->disconnecting)
|
|
|
|
return; /* Free the state in the disconnect callback */
|
2016-11-02 23:46:19 +01:00
|
|
|
|
2020-01-16 05:29:29 +01:00
|
|
|
if (!wsce->done_cb)
|
|
|
|
goto done;
|
2019-12-19 04:50:57 +01:00
|
|
|
|
2020-01-16 05:29:29 +01:00
|
|
|
if (result == NETDEV_RESULT_HANDSHAKE_FAILED && wsce->n_creds > 0) {
|
|
|
|
wsce->done_cb(0, wsce->creds, wsce->n_creds, wsce->done_data);
|
|
|
|
goto done;
|
2016-09-21 23:21:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (result) {
|
|
|
|
case NETDEV_RESULT_ABORTED:
|
2020-01-16 05:29:29 +01:00
|
|
|
wsce->done_cb(-ECANCELED, NULL, 0, wsce->done_data);
|
|
|
|
break;
|
2016-09-23 00:40:59 +02:00
|
|
|
case NETDEV_RESULT_HANDSHAKE_FAILED:
|
2020-01-16 05:29:29 +01:00
|
|
|
wsce->done_cb(-ENOKEY, NULL, 0, wsce->done_data);
|
2016-09-21 23:21:28 +02:00
|
|
|
break;
|
|
|
|
default:
|
2020-01-16 05:29:29 +01:00
|
|
|
wsce->done_cb(-EIO, NULL, 0, wsce->done_data);
|
2016-09-21 23:21:28 +02:00
|
|
|
break;
|
2016-09-15 04:17:41 +02:00
|
|
|
}
|
2016-09-21 23:21:28 +02:00
|
|
|
|
2020-01-16 05:29:29 +01:00
|
|
|
done:
|
|
|
|
wsc_enrollee_free(wsce);
|
2016-09-15 04:17:41 +02:00
|
|
|
}
|
|
|
|
|
2020-01-16 05:29:29 +01:00
|
|
|
static void wsc_enrollee_credential_obtained(struct wsc_enrollee *wsce,
|
2016-09-15 04:17:41 +02:00
|
|
|
const struct wsc_credential *cred)
|
|
|
|
{
|
2016-09-21 20:50:51 +02:00
|
|
|
uint16_t auth_mask;
|
|
|
|
unsigned int i;
|
2016-09-15 04:17:41 +02:00
|
|
|
|
|
|
|
l_debug("Obtained credenials for SSID: %s, address: %s",
|
|
|
|
util_ssid_to_utf8(cred->ssid_len, cred->ssid),
|
|
|
|
util_address_to_string(cred->addr));
|
|
|
|
|
|
|
|
l_debug("auth_type: %02x, encryption_type: %02x",
|
|
|
|
cred->auth_type, cred->encryption_type);
|
|
|
|
|
2019-03-19 01:25:17 +01:00
|
|
|
if (getenv("IWD_WSC_DEBUG_KEYS"))
|
|
|
|
l_debug("Key (%u): %.*s", cred->network_key_len,
|
2016-09-21 20:50:51 +02:00
|
|
|
cred->network_key_len, cred->network_key);
|
|
|
|
|
2020-01-16 05:29:29 +01:00
|
|
|
if (wsce->n_creds == L_ARRAY_SIZE(wsce->creds)) {
|
2016-09-21 20:50:51 +02:00
|
|
|
l_warn("Maximum number of credentials obtained, ignoring...");
|
|
|
|
return;
|
|
|
|
}
|
2016-09-15 04:17:41 +02:00
|
|
|
|
|
|
|
if (!util_ssid_is_utf8(cred->ssid_len, cred->ssid)) {
|
|
|
|
l_warn("Ignoring Credentials with non-UTF8 SSID");
|
|
|
|
return;
|
|
|
|
}
|
2016-09-21 20:50:51 +02:00
|
|
|
|
2020-01-16 05:29:29 +01:00
|
|
|
memcpy(wsce->creds[wsce->n_creds].ssid, cred->ssid, cred->ssid_len);
|
|
|
|
wsce->creds[wsce->n_creds].ssid[cred->ssid_len] = '\0';
|
2016-09-21 20:50:51 +02:00
|
|
|
|
|
|
|
/* We only support open/personal wpa/personal wpa2 */
|
|
|
|
auth_mask = WSC_AUTHENTICATION_TYPE_OPEN |
|
|
|
|
WSC_AUTHENTICATION_TYPE_WPA_PERSONAL |
|
|
|
|
WSC_AUTHENTICATION_TYPE_WPA2_PERSONAL;
|
|
|
|
if ((cred->auth_type & auth_mask) == 0) {
|
|
|
|
l_warn("Ignoring Credentials with unsupported auth_type");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cred->auth_type & WSC_AUTHENTICATION_TYPE_OPEN) {
|
|
|
|
auth_mask &= ~WSC_AUTHENTICATION_TYPE_OPEN;
|
|
|
|
|
|
|
|
if (cred->auth_type & auth_mask) {
|
|
|
|
l_warn("Ignoring mixed open/wpa credentials");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-16 05:29:29 +01:00
|
|
|
wsce->creds[wsce->n_creds].security = SECURITY_NONE;
|
2016-09-21 20:50:51 +02:00
|
|
|
} else
|
2020-01-16 05:29:29 +01:00
|
|
|
wsce->creds[wsce->n_creds].security = SECURITY_PSK;
|
2016-09-21 20:50:51 +02:00
|
|
|
|
2020-01-16 05:29:29 +01:00
|
|
|
switch (wsce->creds[wsce->n_creds].security) {
|
2016-09-21 20:50:51 +02:00
|
|
|
case SECURITY_NONE:
|
|
|
|
if (cred->network_key_len != 0) {
|
|
|
|
l_warn("ignoring invalid open key length");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case SECURITY_PSK:
|
|
|
|
if (cred->network_key_len == 64) {
|
|
|
|
unsigned char *decoded;
|
|
|
|
const char *hex = (const char *) cred->network_key;
|
|
|
|
|
|
|
|
decoded = l_util_from_hexstring(hex, NULL);
|
|
|
|
if (!decoded) {
|
|
|
|
l_warn("Ignoring non-hex network_key");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-16 05:29:29 +01:00
|
|
|
memcpy(wsce->creds[wsce->n_creds].psk, decoded, 32);
|
2019-03-19 01:25:17 +01:00
|
|
|
explicit_bzero(decoded, 32);
|
2016-09-21 20:50:51 +02:00
|
|
|
l_free(decoded);
|
|
|
|
} else {
|
2020-01-16 05:29:29 +01:00
|
|
|
strncpy(wsce->creds[wsce->n_creds].passphrase,
|
2019-09-18 18:02:56 +02:00
|
|
|
(const char *) cred->network_key,
|
|
|
|
cred->network_key_len);
|
2020-01-16 05:29:29 +01:00
|
|
|
wsce->creds[wsce->n_creds].has_passphrase = true;
|
2016-09-21 20:50:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-16 05:29:29 +01:00
|
|
|
for (i = 0; i < wsce->n_creds; i++) {
|
|
|
|
if (strcmp(wsce->creds[i].ssid,
|
|
|
|
wsce->creds[wsce->n_creds].ssid))
|
2016-09-21 20:50:51 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
l_warn("Found duplicate credentials for SSID: %s",
|
2020-01-16 05:29:29 +01:00
|
|
|
wsce->creds[i].ssid);
|
|
|
|
explicit_bzero(&wsce->creds[wsce->n_creds],
|
|
|
|
sizeof(wsce->creds[wsce->n_creds]));
|
2016-09-21 20:50:51 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-16 05:29:29 +01:00
|
|
|
memcpy(wsce->creds[wsce->n_creds].addr, cred->addr, 6);
|
|
|
|
wsce->n_creds += 1;
|
2016-09-15 04:17:41 +02:00
|
|
|
}
|
|
|
|
|
2020-01-16 05:29:29 +01:00
|
|
|
static void wsc_enrollee_netdev_event(struct netdev *netdev,
|
|
|
|
enum netdev_event event,
|
2019-03-01 00:41:51 +01:00
|
|
|
void *event_data, void *user_data)
|
2016-09-15 04:17:41 +02:00
|
|
|
{
|
2020-01-16 05:29:29 +01:00
|
|
|
struct wsc_enrollee *wsce = user_data;
|
2016-10-11 08:54:32 +02:00
|
|
|
|
2016-09-15 04:17:41 +02:00
|
|
|
switch (event) {
|
|
|
|
case NETDEV_EVENT_AUTHENTICATING:
|
|
|
|
case NETDEV_EVENT_ASSOCIATING:
|
|
|
|
break;
|
|
|
|
case NETDEV_EVENT_DISCONNECT_BY_AP:
|
|
|
|
l_debug("Disconnect by AP");
|
2020-01-16 05:29:29 +01:00
|
|
|
wsc_enrollee_connect_cb(wsce->netdev,
|
|
|
|
NETDEV_RESULT_HANDSHAKE_FAILED,
|
|
|
|
event_data, wsce);
|
2016-09-15 04:17:41 +02:00
|
|
|
break;
|
2017-02-23 00:06:17 +01:00
|
|
|
case NETDEV_EVENT_RSSI_THRESHOLD_LOW:
|
|
|
|
case NETDEV_EVENT_RSSI_THRESHOLD_HIGH:
|
|
|
|
break;
|
2016-09-15 04:17:41 +02:00
|
|
|
default:
|
2017-02-23 00:06:17 +01:00
|
|
|
l_debug("Unexpected event: %d", event);
|
2016-09-15 04:17:41 +02:00
|
|
|
break;
|
2020-04-10 02:38:29 +02:00
|
|
|
}
|
2016-09-15 04:17:41 +02:00
|
|
|
}
|
|
|
|
|
2020-01-16 05:29:29 +01:00
|
|
|
static void wsc_enrollee_handshake_event(struct handshake_state *hs,
|
|
|
|
enum handshake_event event,
|
|
|
|
void *user_data, ...)
|
2018-07-02 19:26:48 +02:00
|
|
|
{
|
2020-01-16 05:29:29 +01:00
|
|
|
struct wsc_enrollee *wsce = user_data;
|
2019-10-28 15:04:57 +01:00
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_start(args, user_data);
|
|
|
|
|
2018-07-02 19:26:48 +02:00
|
|
|
switch (event) {
|
|
|
|
case HANDSHAKE_EVENT_FAILED:
|
2019-10-28 15:04:57 +01:00
|
|
|
netdev_handshake_failed(hs, va_arg(args, int));
|
2018-07-02 19:26:48 +02:00
|
|
|
break;
|
2019-10-28 15:05:00 +01:00
|
|
|
case HANDSHAKE_EVENT_EAP_NOTIFY:
|
|
|
|
{
|
|
|
|
unsigned int eap_event = va_arg(args, unsigned int);
|
|
|
|
|
|
|
|
switch (eap_event) {
|
|
|
|
case EAP_WSC_EVENT_CREDENTIAL_OBTAINED:
|
2020-01-16 05:29:29 +01:00
|
|
|
wsc_enrollee_credential_obtained(wsce,
|
2019-10-28 15:05:00 +01:00
|
|
|
va_arg(args, const struct wsc_credential *));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
l_debug("Got event: %d", eap_event);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2018-07-02 19:26:48 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2019-10-28 15:04:57 +01:00
|
|
|
|
|
|
|
va_end(args);
|
2018-07-02 19:26:48 +02:00
|
|
|
}
|
|
|
|
|
2016-09-16 19:42:58 +02:00
|
|
|
static inline enum wsc_rf_band freq_to_rf_band(uint32_t freq)
|
|
|
|
{
|
2021-11-30 00:12:59 +01:00
|
|
|
enum band_freq band;
|
2016-09-16 19:42:58 +02:00
|
|
|
|
2021-11-30 00:12:59 +01:00
|
|
|
band_freq_to_channel(freq, &band);
|
2016-09-16 19:42:58 +02:00
|
|
|
|
|
|
|
switch (band) {
|
2021-11-30 00:12:59 +01:00
|
|
|
case BAND_FREQ_2_4_GHZ:
|
2016-09-16 19:42:58 +02:00
|
|
|
return WSC_RF_BAND_2_4_GHZ;
|
2021-11-30 00:12:59 +01:00
|
|
|
case BAND_FREQ_5_GHZ:
|
2022-02-25 18:58:02 +01:00
|
|
|
case BAND_FREQ_6_GHZ:
|
2016-09-16 19:42:58 +02:00
|
|
|
return WSC_RF_BAND_5_0_GHZ;
|
|
|
|
}
|
|
|
|
|
|
|
|
return WSC_RF_BAND_2_4_GHZ;
|
|
|
|
}
|
|
|
|
|
2020-01-16 05:29:29 +01:00
|
|
|
static int wsc_enrollee_connect(struct wsc_enrollee *wsce, struct scan_bss *bss,
|
2020-01-16 05:29:31 +01:00
|
|
|
const char *pin, struct iovec *ies,
|
|
|
|
unsigned int ies_num)
|
2016-09-15 04:17:41 +02:00
|
|
|
{
|
2016-11-02 23:46:19 +01:00
|
|
|
struct handshake_state *hs;
|
2016-09-15 04:17:41 +02:00
|
|
|
struct l_settings *settings = l_settings_new();
|
2019-10-28 15:05:02 +01:00
|
|
|
int r;
|
|
|
|
struct wsc_association_request request;
|
|
|
|
uint8_t *pdu;
|
|
|
|
size_t pdu_len;
|
2020-01-16 05:29:31 +01:00
|
|
|
struct iovec ie_iov[1 + ies_num];
|
2016-09-22 23:29:19 +02:00
|
|
|
|
2020-01-16 05:29:29 +01:00
|
|
|
hs = netdev_handshake_state_new(wsce->netdev);
|
2016-11-02 23:46:19 +01:00
|
|
|
|
2016-09-15 04:17:41 +02:00
|
|
|
l_settings_set_string(settings, "Security", "EAP-Identity",
|
|
|
|
"WFA-SimpleConfig-Enrollee-1-0");
|
|
|
|
l_settings_set_string(settings, "Security", "EAP-Method", "WSC");
|
|
|
|
|
2016-09-16 19:42:58 +02:00
|
|
|
l_settings_set_uint(settings, "WSC", "RFBand",
|
|
|
|
freq_to_rf_band(bss->frequency));
|
2016-09-15 04:17:41 +02:00
|
|
|
l_settings_set_uint(settings, "WSC", "ConfigurationMethods",
|
|
|
|
WSC_CONFIGURATION_METHOD_VIRTUAL_DISPLAY_PIN |
|
|
|
|
WSC_CONFIGURATION_METHOD_VIRTUAL_PUSH_BUTTON |
|
|
|
|
WSC_CONFIGURATION_METHOD_KEYPAD);
|
|
|
|
l_settings_set_string(settings, "WSC", "PrimaryDeviceType",
|
|
|
|
"0-00000000-0");
|
|
|
|
l_settings_set_string(settings, "WSC", "EnrolleeMAC",
|
2020-01-16 05:29:29 +01:00
|
|
|
util_address_to_string(netdev_get_address(wsce->netdev)));
|
2016-09-15 04:17:41 +02:00
|
|
|
|
2020-01-16 05:29:29 +01:00
|
|
|
if (pin) {
|
2019-12-19 04:50:57 +01:00
|
|
|
enum wsc_device_password_id dpid;
|
2017-02-23 00:03:44 +01:00
|
|
|
|
2020-01-16 05:29:29 +01:00
|
|
|
if (strlen(pin) == 4 || wsc_pin_is_checksum_valid(pin))
|
2019-12-19 04:50:57 +01:00
|
|
|
dpid = WSC_DEVICE_PASSWORD_ID_DEFAULT;
|
|
|
|
else
|
|
|
|
dpid = WSC_DEVICE_PASSWORD_ID_USER_SPECIFIED;
|
2017-02-23 00:03:44 +01:00
|
|
|
|
2019-12-19 04:50:57 +01:00
|
|
|
l_settings_set_uint(settings, "WSC", "DevicePasswordId", dpid);
|
2020-01-16 05:29:29 +01:00
|
|
|
l_settings_set_string(settings, "WSC", "DevicePassword", pin);
|
2017-02-23 00:03:44 +01:00
|
|
|
}
|
|
|
|
|
2020-01-16 05:29:29 +01:00
|
|
|
handshake_state_set_event_func(hs, wsc_enrollee_handshake_event, wsce);
|
2016-11-02 23:46:19 +01:00
|
|
|
handshake_state_set_8021x_config(hs, settings);
|
2021-09-03 21:35:43 +02:00
|
|
|
handshake_state_set_ssid(hs, bss->ssid, bss->ssid_len);
|
2020-01-16 05:29:29 +01:00
|
|
|
wsce->eap_settings = settings;
|
2016-11-02 23:46:19 +01:00
|
|
|
|
2019-10-28 15:05:02 +01:00
|
|
|
request.version2 = true;
|
|
|
|
request.request_type = WSC_REQUEST_TYPE_ENROLLEE_OPEN_8021X;
|
|
|
|
|
|
|
|
pdu = wsc_build_association_request(&request, &pdu_len);
|
|
|
|
if (!pdu) {
|
|
|
|
r = -ENOMEM;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2020-01-16 05:29:31 +01:00
|
|
|
ie_iov[0].iov_base = ie_tlv_encapsulate_wsc_payload(pdu, pdu_len,
|
|
|
|
&ie_iov[0].iov_len);
|
2019-10-28 15:05:02 +01:00
|
|
|
l_free(pdu);
|
|
|
|
|
2020-01-16 05:29:31 +01:00
|
|
|
if (!ie_iov[0].iov_base) {
|
2019-10-28 15:05:02 +01:00
|
|
|
r = -ENOMEM;
|
|
|
|
goto error;
|
2016-09-23 03:49:38 +02:00
|
|
|
}
|
2016-09-15 04:17:41 +02:00
|
|
|
|
2020-01-16 05:29:31 +01:00
|
|
|
if (ies_num)
|
|
|
|
memcpy(ie_iov + 1, ies, sizeof(struct iovec) * ies_num);
|
|
|
|
|
2023-11-30 23:28:11 +01:00
|
|
|
handshake_state_set_vendor_ies(hs, ie_iov, 1 + ies_num);
|
|
|
|
|
2023-11-30 23:32:00 +01:00
|
|
|
r = netdev_connect(wsce->netdev, bss, hs,
|
2020-01-16 05:29:29 +01:00
|
|
|
wsc_enrollee_netdev_event,
|
|
|
|
wsc_enrollee_connect_cb, wsce);
|
2020-01-16 05:29:31 +01:00
|
|
|
l_free(ie_iov[0].iov_base);
|
2019-10-28 15:05:02 +01:00
|
|
|
|
2020-01-16 05:29:29 +01:00
|
|
|
if (r == 0)
|
|
|
|
return 0;
|
2019-10-28 15:05:02 +01:00
|
|
|
|
|
|
|
error:
|
|
|
|
handshake_state_free(hs);
|
2020-01-16 05:29:29 +01:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wsc_enrollee *wsc_enrollee_new(struct netdev *netdev,
|
|
|
|
struct scan_bss *target,
|
|
|
|
const char *pin,
|
2020-01-16 05:29:31 +01:00
|
|
|
struct iovec *ies, unsigned int ies_num,
|
2020-01-16 05:29:29 +01:00
|
|
|
wsc_done_cb_t done_cb, void *user_data)
|
|
|
|
{
|
|
|
|
struct wsc_enrollee *wsce;
|
|
|
|
|
|
|
|
wsce = l_new(struct wsc_enrollee, 1);
|
|
|
|
wsce->netdev = netdev;
|
|
|
|
wsce->done_cb = done_cb;
|
|
|
|
wsce->done_data = user_data;
|
|
|
|
|
2020-01-16 05:29:31 +01:00
|
|
|
if (wsc_enrollee_connect(wsce, target, pin, ies, ies_num) == 0)
|
2020-01-16 05:29:29 +01:00
|
|
|
return wsce;
|
|
|
|
|
|
|
|
wsc_enrollee_free(wsce);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wsc_enrollee_disconnect_cb(struct netdev *netdev, bool result,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct wsc_enrollee *wsce = user_data;
|
|
|
|
|
|
|
|
wsce->done_cb(-ECANCELED, NULL, 0, wsce->done_data);
|
|
|
|
wsc_enrollee_free(wsce);
|
|
|
|
}
|
|
|
|
|
|
|
|
void wsc_enrollee_cancel(struct wsc_enrollee *wsce, bool defer_cb)
|
|
|
|
{
|
|
|
|
if (defer_cb) {
|
|
|
|
wsce->disconnecting = true;
|
|
|
|
netdev_disconnect(wsce->netdev, wsc_enrollee_disconnect_cb,
|
|
|
|
wsce);
|
|
|
|
} else {
|
|
|
|
wsce->done_cb(-ECANCELED, NULL, 0, wsce->done_data);
|
|
|
|
wsce->done_cb = NULL;
|
|
|
|
/*
|
|
|
|
* Results in a call to
|
|
|
|
* wsc_enrollee_connect_cb -> wsc_enrollee_free
|
|
|
|
*/
|
|
|
|
netdev_disconnect(wsce->netdev, NULL, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-17 18:18:23 +01:00
|
|
|
void wsc_enrollee_free(struct wsc_enrollee *wsce)
|
2020-01-16 05:29:29 +01:00
|
|
|
{
|
2020-01-17 18:18:23 +01:00
|
|
|
l_settings_free(wsce->eap_settings);
|
|
|
|
explicit_bzero(wsce->creds, sizeof(wsce->creds));
|
|
|
|
l_free(wsce);
|
2020-01-16 05:29:29 +01:00
|
|
|
}
|
|
|
|
|
2020-01-16 05:29:30 +01:00
|
|
|
struct wsc_station_dbus {
|
|
|
|
struct wsc_dbus super;
|
|
|
|
struct wsc_enrollee *enrollee;
|
|
|
|
struct scan_bss *target;
|
|
|
|
struct netdev *netdev;
|
|
|
|
struct station *station;
|
|
|
|
uint8_t *wsc_ies;
|
|
|
|
size_t wsc_ies_size;
|
|
|
|
struct l_timeout *walk_timer;
|
|
|
|
uint32_t scan_id;
|
|
|
|
uint32_t station_state_watch;
|
|
|
|
};
|
|
|
|
|
2020-01-17 19:05:47 +01:00
|
|
|
#define CONNECT_REPLY(wsc, message) \
|
|
|
|
if ((wsc)->super.pending_connect) \
|
|
|
|
dbus_pending_reply(&(wsc)->super.pending_connect, \
|
|
|
|
message((wsc)->super.pending_connect)) \
|
|
|
|
|
|
|
|
#define CANCEL_REPLY(wsc, message) \
|
|
|
|
if ((wsc)->super.pending_cancel) \
|
|
|
|
dbus_pending_reply(&(wsc)->super.pending_cancel, \
|
|
|
|
message((wsc)->super.pending_cancel)) \
|
|
|
|
|
2020-01-16 05:29:30 +01:00
|
|
|
static void wsc_try_credentials(struct wsc_station_dbus *wsc,
|
2020-01-16 05:29:29 +01:00
|
|
|
struct wsc_credentials_info *creds,
|
|
|
|
unsigned int n_creds)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
struct network *network;
|
|
|
|
struct scan_bss *bss;
|
|
|
|
|
|
|
|
for (i = 0; i < n_creds; i++) {
|
|
|
|
network = station_network_find(wsc->station, creds[i].ssid,
|
|
|
|
creds[i].security);
|
|
|
|
if (!network)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
bss = network_bss_find_by_addr(network, creds[i].addr);
|
|
|
|
|
|
|
|
if (!bss)
|
|
|
|
bss = network_bss_select(network, true);
|
|
|
|
|
|
|
|
if (!bss)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (creds[i].security == SECURITY_PSK) {
|
|
|
|
bool ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prefer setting passphrase, this will work for both
|
|
|
|
* WPA2 and WPA3 since the PSK can always be generated
|
|
|
|
* if needed
|
|
|
|
*/
|
|
|
|
if (creds[i].has_passphrase)
|
|
|
|
ret = network_set_passphrase(network,
|
|
|
|
creds[i].passphrase);
|
|
|
|
else
|
|
|
|
ret = network_set_psk(network, creds[i].psk);
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
station_connect_network(wsc->station, network, bss,
|
2020-01-16 05:29:30 +01:00
|
|
|
wsc->super.pending_connect);
|
|
|
|
l_dbus_message_unref(wsc->super.pending_connect);
|
|
|
|
wsc->super.pending_connect = NULL;
|
2020-01-16 05:29:29 +01:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-17 19:05:47 +01:00
|
|
|
CONNECT_REPLY(wsc, wsc_error_not_reachable);
|
2020-01-16 05:29:29 +01:00
|
|
|
station_set_autoconnect(wsc->station, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wsc_store_credentials(struct wsc_credentials_info *creds,
|
|
|
|
unsigned int n_creds)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
2021-07-06 20:38:56 +02:00
|
|
|
/* We don't store any non-open/psk credentials */
|
2020-01-16 05:29:29 +01:00
|
|
|
for (i = 0; i < n_creds; i++) {
|
|
|
|
enum security security = creds[i].security;
|
|
|
|
const char *ssid = creds[i].ssid;
|
2021-07-06 20:38:56 +02:00
|
|
|
_auto_(l_settings_free) struct l_settings *settings =
|
|
|
|
l_settings_new();
|
|
|
|
_auto_(l_free) char *path =
|
|
|
|
storage_get_network_file_path(security, ssid);
|
2020-01-16 05:29:29 +01:00
|
|
|
|
2021-07-06 20:38:56 +02:00
|
|
|
if (l_settings_load_from_file(settings, path)) {
|
|
|
|
/*
|
|
|
|
* Nothing to do,
|
|
|
|
* so don't overwrite any existing settings
|
|
|
|
*/
|
|
|
|
if (security == SECURITY_NONE)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Remove any existing Security keys */
|
|
|
|
l_settings_remove_group(settings, "Security");
|
|
|
|
}
|
2020-01-16 05:29:29 +01:00
|
|
|
|
2021-07-06 20:38:56 +02:00
|
|
|
if (security == SECURITY_PSK) {
|
|
|
|
if (creds[i].has_passphrase)
|
|
|
|
l_settings_set_string(settings, "Security",
|
|
|
|
"Passphrase", creds[i].passphrase);
|
|
|
|
else
|
|
|
|
l_settings_set_bytes(settings, "Security",
|
2020-09-16 11:17:54 +02:00
|
|
|
"PreSharedKey", creds[i].psk,
|
2022-01-11 17:51:11 +01:00
|
|
|
sizeof(creds[i].psk));
|
2021-07-06 20:38:56 +02:00
|
|
|
}
|
2020-01-16 05:29:29 +01:00
|
|
|
|
2021-07-06 20:38:56 +02:00
|
|
|
l_debug("Storing credential for '%s(%s)'", ssid,
|
|
|
|
security_to_str(security));
|
2020-01-16 05:29:29 +01:00
|
|
|
storage_network_sync(security, ssid, settings);
|
|
|
|
}
|
2019-12-19 04:50:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void wsc_dbus_done_cb(int err, struct wsc_credentials_info *creds,
|
|
|
|
unsigned int n_creds, void *user_data)
|
|
|
|
{
|
2020-01-16 05:29:30 +01:00
|
|
|
struct wsc_station_dbus *wsc = user_data;
|
2019-12-19 04:50:57 +01:00
|
|
|
|
2020-01-16 05:29:29 +01:00
|
|
|
wsc->enrollee = NULL;
|
|
|
|
wsc->target = NULL;
|
|
|
|
|
2019-12-19 04:50:57 +01:00
|
|
|
l_debug("err=%i", err);
|
|
|
|
|
2020-01-16 05:29:29 +01:00
|
|
|
if (err && wsc->station)
|
|
|
|
station_set_autoconnect(wsc->station, true);
|
|
|
|
|
2019-12-19 04:50:57 +01:00
|
|
|
switch (err) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case -ECANCELED:
|
2020-01-16 05:29:29 +01:00
|
|
|
/* Send reply if we haven't already sent one e.g. in Cancel() */
|
2020-01-17 19:05:47 +01:00
|
|
|
CONNECT_REPLY(wsc, dbus_error_aborted);
|
|
|
|
CANCEL_REPLY(wsc, l_dbus_message_new_method_return);
|
2019-12-19 04:50:57 +01:00
|
|
|
return;
|
|
|
|
case -ENOKEY:
|
2020-01-17 19:05:47 +01:00
|
|
|
CONNECT_REPLY(wsc, wsc_error_no_credentials);
|
2019-12-19 04:50:57 +01:00
|
|
|
return;
|
|
|
|
case -EBUSY:
|
2020-01-17 19:05:47 +01:00
|
|
|
CONNECT_REPLY(wsc, dbus_error_busy);
|
2019-12-19 04:50:57 +01:00
|
|
|
return;
|
|
|
|
default:
|
2020-01-17 19:05:47 +01:00
|
|
|
CONNECT_REPLY(wsc, dbus_error_failed);
|
2019-12-19 04:50:57 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-19 04:50:58 +01:00
|
|
|
wsc_store_credentials(creds, n_creds);
|
|
|
|
wsc_try_credentials(wsc, creds, n_creds);
|
2016-09-15 04:17:41 +02:00
|
|
|
}
|
|
|
|
|
2020-01-16 05:29:30 +01:00
|
|
|
static void wsc_connect(struct wsc_station_dbus *wsc)
|
2020-01-16 05:29:29 +01:00
|
|
|
{
|
|
|
|
const char *pin = NULL;
|
|
|
|
|
2020-01-16 05:29:30 +01:00
|
|
|
if (!strcmp(l_dbus_message_get_member(wsc->super.pending_connect),
|
|
|
|
"StartPin"))
|
|
|
|
l_dbus_message_get_arguments(wsc->super.pending_connect, "s",
|
|
|
|
&pin);
|
2020-01-16 05:29:29 +01:00
|
|
|
|
2020-01-16 05:29:31 +01:00
|
|
|
wsc->enrollee = wsc_enrollee_new(wsc->netdev, wsc->target, pin, NULL, 0,
|
2020-01-16 05:29:29 +01:00
|
|
|
wsc_dbus_done_cb, wsc);
|
|
|
|
if (wsc->enrollee)
|
|
|
|
return;
|
|
|
|
|
|
|
|
wsc_dbus_done_cb(-EIO, NULL, 0, wsc);
|
|
|
|
}
|
|
|
|
|
2018-09-04 17:40:45 +02:00
|
|
|
static void station_state_watch(enum station_state state, void *userdata)
|
2016-09-22 23:29:19 +02:00
|
|
|
{
|
2020-01-16 05:29:30 +01:00
|
|
|
struct wsc_station_dbus *wsc = userdata;
|
2016-09-22 23:29:19 +02:00
|
|
|
|
2018-09-04 17:40:45 +02:00
|
|
|
if (state != STATION_STATE_DISCONNECTED)
|
2016-09-22 23:29:19 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
l_debug("%p", wsc);
|
|
|
|
|
2018-09-04 17:40:45 +02:00
|
|
|
station_remove_state_watch(wsc->station, wsc->station_state_watch);
|
|
|
|
wsc->station_state_watch = 0;
|
2016-09-22 23:29:19 +02:00
|
|
|
|
|
|
|
wsc_connect(wsc);
|
|
|
|
}
|
|
|
|
|
2020-01-16 05:29:30 +01:00
|
|
|
static void wsc_check_can_connect(struct wsc_station_dbus *wsc,
|
|
|
|
struct scan_bss *target)
|
2016-09-22 23:29:19 +02:00
|
|
|
{
|
|
|
|
l_debug("%p", wsc);
|
|
|
|
|
|
|
|
/*
|
2018-06-29 23:40:55 +02:00
|
|
|
* For now we assign the target pointer directly, since we should not
|
2016-09-22 23:29:19 +02:00
|
|
|
* be triggering any more scans while disconnecting / connecting
|
|
|
|
*/
|
|
|
|
wsc->target = target;
|
2018-09-05 01:00:48 +02:00
|
|
|
station_set_autoconnect(wsc->station, false);
|
2016-09-22 23:29:19 +02:00
|
|
|
|
2018-09-04 17:40:45 +02:00
|
|
|
switch (station_get_state(wsc->station)) {
|
|
|
|
case STATION_STATE_DISCONNECTED:
|
2016-09-22 23:29:19 +02:00
|
|
|
wsc_connect(wsc);
|
|
|
|
return;
|
2018-09-04 17:40:45 +02:00
|
|
|
case STATION_STATE_CONNECTING:
|
2021-05-24 23:09:28 +02:00
|
|
|
case STATION_STATE_CONNECTING_AUTO:
|
2018-09-04 17:40:45 +02:00
|
|
|
case STATION_STATE_CONNECTED:
|
2018-09-05 02:54:48 +02:00
|
|
|
if (station_disconnect(wsc->station) < 0)
|
2016-09-22 23:29:19 +02:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* fall through */
|
2018-09-04 17:40:45 +02:00
|
|
|
case STATION_STATE_DISCONNECTING:
|
|
|
|
wsc->station_state_watch =
|
|
|
|
station_add_state_watch(wsc->station,
|
|
|
|
station_state_watch,
|
|
|
|
wsc, NULL);
|
2016-09-22 23:29:19 +02:00
|
|
|
return;
|
2019-03-22 22:17:45 +01:00
|
|
|
case STATION_STATE_AUTOCONNECT_QUICK:
|
|
|
|
case STATION_STATE_AUTOCONNECT_FULL:
|
2018-09-04 17:40:45 +02:00
|
|
|
case STATION_STATE_ROAMING:
|
2022-09-28 20:33:50 +02:00
|
|
|
case STATION_STATE_FT_ROAMING:
|
|
|
|
case STATION_STATE_FW_ROAMING:
|
2022-01-11 18:05:09 +01:00
|
|
|
l_warn("%s: invalid station state", __func__);
|
2016-09-22 23:29:19 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
error:
|
2020-01-16 05:29:29 +01:00
|
|
|
wsc->target = NULL;
|
2020-01-17 19:05:47 +01:00
|
|
|
CONNECT_REPLY(wsc, dbus_error_failed);
|
2016-09-22 23:29:19 +02:00
|
|
|
}
|
|
|
|
|
2020-01-16 05:29:30 +01:00
|
|
|
static void wsc_cancel_scan(struct wsc_station_dbus *wsc)
|
2016-09-22 18:32:18 +02:00
|
|
|
{
|
|
|
|
l_free(wsc->wsc_ies);
|
|
|
|
wsc->wsc_ies = 0;
|
|
|
|
|
|
|
|
if (wsc->scan_id > 0) {
|
2019-07-08 16:02:59 +02:00
|
|
|
scan_cancel(netdev_get_wdev_id(wsc->netdev), wsc->scan_id);
|
2016-09-22 18:32:18 +02:00
|
|
|
wsc->scan_id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wsc->walk_timer) {
|
|
|
|
l_timeout_remove(wsc->walk_timer);
|
|
|
|
wsc->walk_timer = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void walk_timeout(struct l_timeout *timeout, void *user_data)
|
|
|
|
{
|
2020-01-16 05:29:30 +01:00
|
|
|
struct wsc_station_dbus *wsc = user_data;
|
2016-09-22 18:32:18 +02:00
|
|
|
|
|
|
|
wsc_cancel_scan(wsc);
|
2020-01-17 19:05:47 +01:00
|
|
|
CONNECT_REPLY(wsc, wsc_error_walk_time_expired);
|
2016-09-22 18:32:18 +02:00
|
|
|
}
|
|
|
|
|
2017-02-23 00:03:44 +01:00
|
|
|
static void pin_timeout(struct l_timeout *timeout, void *user_data)
|
|
|
|
{
|
2020-01-16 05:29:30 +01:00
|
|
|
struct wsc_station_dbus *wsc = user_data;
|
2017-02-23 00:03:44 +01:00
|
|
|
|
|
|
|
wsc_cancel_scan(wsc);
|
2020-01-17 19:05:47 +01:00
|
|
|
CONNECT_REPLY(wsc, wsc_error_time_expired);
|
2017-02-23 00:03:44 +01:00
|
|
|
}
|
|
|
|
|
2019-03-14 21:42:11 +01:00
|
|
|
static bool push_button_scan_results(int err, struct l_queue *bss_list,
|
2021-02-03 17:02:40 +01:00
|
|
|
const struct scan_freq_set *freqs,
|
2017-03-27 13:04:11 +02:00
|
|
|
void *userdata)
|
2015-10-06 05:37:46 +02:00
|
|
|
{
|
2020-01-16 05:29:30 +01:00
|
|
|
struct wsc_station_dbus *wsc = userdata;
|
2015-10-06 05:37:46 +02:00
|
|
|
struct scan_bss *bss_2g;
|
|
|
|
struct scan_bss *bss_5g;
|
|
|
|
struct scan_bss *target;
|
|
|
|
uint8_t uuid_2g[16];
|
|
|
|
uint8_t uuid_5g[16];
|
|
|
|
const struct l_queue_entry *bss_entry;
|
|
|
|
struct wsc_probe_response probe_response;
|
|
|
|
|
2017-03-27 13:04:11 +02:00
|
|
|
if (err) {
|
|
|
|
wsc_cancel_scan(wsc);
|
2020-01-17 19:05:47 +01:00
|
|
|
CONNECT_REPLY(wsc, dbus_error_failed);
|
2017-03-27 13:04:11 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-06 05:37:46 +02:00
|
|
|
bss_2g = NULL;
|
|
|
|
bss_5g = NULL;
|
|
|
|
|
2016-09-13 21:45:05 +02:00
|
|
|
wsc->scan_id = 0;
|
2015-10-06 05:37:46 +02:00
|
|
|
|
|
|
|
for (bss_entry = l_queue_get_entries(bss_list); bss_entry;
|
|
|
|
bss_entry = bss_entry->next) {
|
|
|
|
struct scan_bss *bss = bss_entry->data;
|
2021-11-30 00:12:59 +01:00
|
|
|
enum band_freq band;
|
2015-10-06 05:37:46 +02:00
|
|
|
int err;
|
|
|
|
|
|
|
|
l_debug("bss '%s' with SSID: %s, freq: %u",
|
2016-06-07 01:24:49 +02:00
|
|
|
util_address_to_string(bss->addr),
|
2015-10-06 05:37:46 +02:00
|
|
|
util_ssid_to_utf8(bss->ssid_len, bss->ssid),
|
|
|
|
bss->frequency);
|
|
|
|
|
|
|
|
l_debug("bss->wsc: %p, %zu", bss->wsc, bss->wsc_size);
|
|
|
|
|
|
|
|
if (!bss->wsc)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
err = wsc_parse_probe_response(bss->wsc, bss->wsc_size,
|
|
|
|
&probe_response);
|
|
|
|
if (err < 0) {
|
|
|
|
l_debug("ProbeResponse parse failed: %s",
|
|
|
|
strerror(-err));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
l_debug("SelectedRegistar: %s",
|
|
|
|
probe_response.selected_registrar ? "true" : "false");
|
|
|
|
|
|
|
|
if (!probe_response.selected_registrar)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (probe_response.device_password_id !=
|
|
|
|
WSC_DEVICE_PASSWORD_ID_PUSH_BUTTON)
|
|
|
|
continue;
|
|
|
|
|
2021-11-30 00:12:59 +01:00
|
|
|
band_freq_to_channel(bss->frequency, &band);
|
2015-10-06 05:37:46 +02:00
|
|
|
|
|
|
|
switch (band) {
|
2021-11-30 00:12:59 +01:00
|
|
|
case BAND_FREQ_2_4_GHZ:
|
2015-10-06 05:37:46 +02:00
|
|
|
if (bss_2g) {
|
|
|
|
l_debug("2G Session overlap error");
|
2016-09-13 21:55:13 +02:00
|
|
|
goto session_overlap;
|
2015-10-06 05:37:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bss_2g = bss;
|
|
|
|
memcpy(uuid_2g, probe_response.uuid_e, 16);
|
|
|
|
break;
|
|
|
|
|
2021-11-30 00:12:59 +01:00
|
|
|
case BAND_FREQ_5_GHZ:
|
2015-10-06 05:37:46 +02:00
|
|
|
if (bss_5g) {
|
|
|
|
l_debug("5G Session overlap error");
|
2016-09-13 21:55:13 +02:00
|
|
|
goto session_overlap;
|
2015-10-06 05:37:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bss_5g = bss;
|
|
|
|
memcpy(uuid_5g, probe_response.uuid_e, 16);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bss_2g && bss_5g && memcmp(uuid_2g, uuid_5g, 16)) {
|
|
|
|
l_debug("Found two PBC APs on different bands");
|
2016-09-13 21:55:13 +02:00
|
|
|
goto session_overlap;
|
2015-10-06 05:37:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bss_5g)
|
|
|
|
target = bss_5g;
|
|
|
|
else if (bss_2g)
|
|
|
|
target = bss_2g;
|
|
|
|
else {
|
|
|
|
l_debug("No PBC APs found, running the scan again");
|
2019-07-08 16:02:59 +02:00
|
|
|
wsc->scan_id = scan_active(netdev_get_wdev_id(wsc->netdev),
|
2016-09-13 21:45:05 +02:00
|
|
|
wsc->wsc_ies, wsc->wsc_ies_size,
|
2017-02-21 23:20:16 +01:00
|
|
|
NULL, push_button_scan_results,
|
|
|
|
wsc, NULL);
|
2015-10-06 05:37:46 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-22 18:32:18 +02:00
|
|
|
wsc_cancel_scan(wsc);
|
2021-02-03 17:31:24 +01:00
|
|
|
station_set_scan_results(wsc->station, bss_list, freqs, false);
|
2016-09-21 23:21:53 +02:00
|
|
|
|
2015-10-06 05:37:46 +02:00
|
|
|
l_debug("Found AP to connect to: %s",
|
2016-06-07 01:24:49 +02:00
|
|
|
util_address_to_string(target->addr));
|
2016-09-22 23:29:19 +02:00
|
|
|
wsc_check_can_connect(wsc, target);
|
2015-10-06 05:37:46 +02:00
|
|
|
|
2016-09-21 23:21:53 +02:00
|
|
|
return true;
|
2016-09-13 21:55:13 +02:00
|
|
|
|
|
|
|
session_overlap:
|
2016-09-22 18:32:18 +02:00
|
|
|
wsc_cancel_scan(wsc);
|
2020-01-17 19:05:47 +01:00
|
|
|
CONNECT_REPLY(wsc, wsc_error_session_overlap);
|
2016-09-13 21:55:13 +02:00
|
|
|
|
|
|
|
return false;
|
2015-10-06 05:37:46 +02:00
|
|
|
}
|
|
|
|
|
2017-02-23 00:03:44 +01:00
|
|
|
static const char *authorized_macs_to_string(const uint8_t *authorized_macs)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
unsigned int offset = 0;
|
|
|
|
/* Max of 5 addresses in AuthorizedMacs, 17 bytes / address */
|
|
|
|
static char buf[128];
|
|
|
|
|
|
|
|
for (i = 0; i < 5; i++) {
|
|
|
|
const uint8_t *addr = authorized_macs + i * 6;
|
|
|
|
|
2021-03-09 22:40:35 +01:00
|
|
|
if (l_memeqzero(addr, 6))
|
2017-02-23 00:03:44 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
offset += sprintf(buf + offset, "%s",
|
|
|
|
util_address_to_string(addr));
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool authorized_macs_contains(const uint8_t *authorized_macs,
|
|
|
|
const uint8_t *target)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 5; i++) {
|
|
|
|
const uint8_t *addr = authorized_macs + i * 6;
|
|
|
|
|
|
|
|
if (!memcmp(addr, target, 6))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-02-03 17:02:40 +01:00
|
|
|
static bool pin_scan_results(int err, struct l_queue *bss_list,
|
|
|
|
const struct scan_freq_set *freqs,
|
|
|
|
void *userdata)
|
2017-02-23 00:03:44 +01:00
|
|
|
{
|
|
|
|
static const uint8_t wildcard_address[] =
|
|
|
|
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
2020-01-16 05:29:30 +01:00
|
|
|
struct wsc_station_dbus *wsc = userdata;
|
2017-02-23 00:03:44 +01:00
|
|
|
struct scan_bss *target = NULL;
|
|
|
|
const struct l_queue_entry *bss_entry;
|
|
|
|
struct wsc_probe_response probe_response;
|
|
|
|
|
2017-03-27 13:04:11 +02:00
|
|
|
if (err) {
|
|
|
|
wsc_cancel_scan(wsc);
|
2020-01-17 19:05:47 +01:00
|
|
|
CONNECT_REPLY(wsc, dbus_error_failed);
|
2017-03-27 13:04:11 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-02-23 00:03:44 +01:00
|
|
|
wsc->scan_id = 0;
|
|
|
|
|
|
|
|
for (bss_entry = l_queue_get_entries(bss_list); bss_entry;
|
|
|
|
bss_entry = bss_entry->next) {
|
|
|
|
struct scan_bss *bss = bss_entry->data;
|
|
|
|
const uint8_t *amacs;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
l_debug("bss '%s' with SSID: %s, freq: %u",
|
|
|
|
util_address_to_string(bss->addr),
|
|
|
|
util_ssid_to_utf8(bss->ssid_len, bss->ssid),
|
|
|
|
bss->frequency);
|
|
|
|
|
|
|
|
l_debug("bss->wsc: %p, %zu", bss->wsc, bss->wsc_size);
|
|
|
|
|
|
|
|
if (!bss->wsc)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
err = wsc_parse_probe_response(bss->wsc, bss->wsc_size,
|
|
|
|
&probe_response);
|
|
|
|
if (err < 0) {
|
|
|
|
l_debug("ProbeResponse parse failed: %s",
|
|
|
|
strerror(-err));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (probe_response.device_password_id !=
|
|
|
|
WSC_DEVICE_PASSWORD_ID_DEFAULT &&
|
|
|
|
probe_response.device_password_id !=
|
|
|
|
WSC_DEVICE_PASSWORD_ID_USER_SPECIFIED)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
l_debug("SelectedRegistar: %s",
|
|
|
|
probe_response.selected_registrar ? "true" : "false");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* WSC Best Practices v2.0.1, Section 3.4:
|
|
|
|
* In a mixed environment with both WSC 1.0 and WSC 2.0 APs, an
|
|
|
|
* Enrollee should be prepared to run both the WSC 1.0 and
|
|
|
|
* WSC 2.0 forms of discovery. An Enrollee may scan available
|
|
|
|
* channels and then order PIN attempts with prospective APs
|
|
|
|
* as follows:
|
|
|
|
* 1. WSC 2.0 AP with the Selected Registrar attribute TRUE
|
2019-11-21 21:19:15 +01:00
|
|
|
* and the Enrollee's MAC address in the AuthorizedMACs
|
2017-02-23 00:03:44 +01:00
|
|
|
* sub-element in Beacons and Probe Responses.
|
|
|
|
* 2. WSC 2.0 APs with the Selected Registrar attribute TRUE
|
|
|
|
* and the wildcard MAC address in the AuthorizedMACs
|
|
|
|
* sub-element in Beacons and Probe Responses, ordered by
|
|
|
|
* decreasing RSSI.
|
|
|
|
* 3. WSC 1.0 APs, ordered by decreasing RSSI.
|
|
|
|
* If option 1 is available, options 2 and 3 should be
|
|
|
|
* unnecessary.
|
|
|
|
*/
|
|
|
|
if (!probe_response.selected_registrar)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
amacs = probe_response.authorized_macs;
|
|
|
|
l_debug("AuthorizedMacs: %s", authorized_macs_to_string(amacs));
|
|
|
|
|
|
|
|
if (authorized_macs_contains(amacs,
|
2018-08-20 06:28:07 +02:00
|
|
|
netdev_get_address(wsc->netdev))) {
|
2017-02-23 00:03:44 +01:00
|
|
|
target = bss;
|
|
|
|
break;
|
|
|
|
} else if (!target && authorized_macs_contains(amacs,
|
|
|
|
wildcard_address))
|
|
|
|
target = bss;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!target) {
|
|
|
|
l_debug("No PIN APs found, running the scan again");
|
2019-07-08 16:02:59 +02:00
|
|
|
wsc->scan_id = scan_active(netdev_get_wdev_id(wsc->netdev),
|
2017-02-23 00:03:44 +01:00
|
|
|
wsc->wsc_ies, wsc->wsc_ies_size,
|
|
|
|
NULL, pin_scan_results,
|
|
|
|
wsc, NULL);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
wsc_cancel_scan(wsc);
|
2021-02-03 17:31:24 +01:00
|
|
|
station_set_scan_results(wsc->station, bss_list, freqs, false);
|
2017-02-23 00:03:44 +01:00
|
|
|
|
|
|
|
l_debug("Found AP to connect to: %s",
|
|
|
|
util_address_to_string(target->addr));
|
|
|
|
wsc_check_can_connect(wsc, target);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-16 05:29:30 +01:00
|
|
|
static bool wsc_initiate_scan(struct wsc_station_dbus *wsc,
|
2017-02-21 23:20:16 +01:00
|
|
|
enum wsc_device_password_id dpid,
|
|
|
|
scan_notify_func_t callback)
|
2015-09-28 17:54:45 +02:00
|
|
|
{
|
|
|
|
static const uint8_t wfa_oui[] = { 0x00, 0x50, 0xF2 };
|
|
|
|
struct wsc_probe_request req;
|
2018-08-20 06:28:07 +02:00
|
|
|
struct wiphy *wiphy = netdev_get_wiphy(wsc->netdev);
|
2016-09-13 21:45:05 +02:00
|
|
|
uint32_t bands;
|
2015-09-28 17:54:45 +02:00
|
|
|
uint8_t *wsc_data;
|
|
|
|
size_t wsc_data_size;
|
|
|
|
|
|
|
|
memset(&req, 0, sizeof(req));
|
|
|
|
|
|
|
|
req.version2 = true;
|
|
|
|
req.request_type = WSC_REQUEST_TYPE_ENROLLEE_INFO;
|
|
|
|
|
|
|
|
/* TODO: Grab from configuration file ? */
|
|
|
|
req.config_methods = WSC_CONFIGURATION_METHOD_VIRTUAL_PUSH_BUTTON |
|
|
|
|
WSC_CONFIGURATION_METHOD_KEYPAD;
|
|
|
|
|
2018-08-20 06:28:07 +02:00
|
|
|
if (!wsc_uuid_from_addr(netdev_get_address(wsc->netdev), req.uuid_e))
|
2016-09-13 21:45:05 +02:00
|
|
|
return false;
|
2015-09-28 17:54:45 +02:00
|
|
|
|
|
|
|
/* TODO: Grab from configuration file ? */
|
|
|
|
req.primary_device_type.category = 255;
|
|
|
|
memcpy(req.primary_device_type.oui, wfa_oui, 3);
|
|
|
|
req.primary_device_type.oui_type = 0x04;
|
|
|
|
req.primary_device_type.subcategory = 0;
|
|
|
|
|
2016-09-13 21:45:05 +02:00
|
|
|
bands = wiphy_get_supported_bands(wiphy);
|
2021-11-30 00:12:59 +01:00
|
|
|
if (bands & BAND_FREQ_2_4_GHZ)
|
2015-09-28 17:54:45 +02:00
|
|
|
req.rf_bands |= WSC_RF_BAND_2_4_GHZ;
|
2021-11-30 00:12:59 +01:00
|
|
|
if (bands & BAND_FREQ_5_GHZ)
|
2015-09-28 17:54:45 +02:00
|
|
|
req.rf_bands |= WSC_RF_BAND_5_0_GHZ;
|
|
|
|
|
2017-02-21 23:20:16 +01:00
|
|
|
req.association_state = WSC_ASSOCIATION_STATE_NOT_ASSOCIATED;
|
|
|
|
req.configuration_error = WSC_CONFIGURATION_ERROR_NO_ERROR;
|
|
|
|
req.device_password_id = dpid;
|
|
|
|
req.request_to_enroll = true;
|
2015-09-28 17:54:45 +02:00
|
|
|
|
|
|
|
wsc_data = wsc_build_probe_request(&req, &wsc_data_size);
|
|
|
|
if (!wsc_data)
|
2016-09-13 21:45:05 +02:00
|
|
|
return false;
|
2015-09-28 17:54:45 +02:00
|
|
|
|
2016-09-13 21:45:05 +02:00
|
|
|
wsc->wsc_ies = ie_tlv_encapsulate_wsc_payload(wsc_data, wsc_data_size,
|
|
|
|
&wsc->wsc_ies_size);
|
2015-09-28 17:54:45 +02:00
|
|
|
l_free(wsc_data);
|
|
|
|
|
2016-09-13 21:45:05 +02:00
|
|
|
if (!wsc->wsc_ies)
|
|
|
|
return false;
|
2015-10-06 05:37:46 +02:00
|
|
|
|
2019-07-08 16:02:59 +02:00
|
|
|
wsc->scan_id = scan_active(netdev_get_wdev_id(wsc->netdev),
|
2016-09-13 21:45:05 +02:00
|
|
|
wsc->wsc_ies, wsc->wsc_ies_size,
|
2017-02-21 23:20:16 +01:00
|
|
|
NULL, callback, wsc, NULL);
|
2017-02-04 00:58:31 +01:00
|
|
|
if (!wsc->scan_id) {
|
|
|
|
l_free(wsc->wsc_ies);
|
|
|
|
wsc->wsc_ies = NULL;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-22 18:32:18 +02:00
|
|
|
return true;
|
2015-09-28 17:54:45 +02:00
|
|
|
}
|
2015-09-29 03:38:17 +02:00
|
|
|
|
2020-01-16 05:29:30 +01:00
|
|
|
static const char *wsc_station_dbus_get_path(struct wsc_dbus *super)
|
|
|
|
{
|
|
|
|
struct wsc_station_dbus *wsc =
|
|
|
|
l_container_of(super, struct wsc_station_dbus, super);
|
|
|
|
|
|
|
|
return netdev_get_path(wsc->netdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wsc_station_dbus_connect(struct wsc_dbus *super,
|
|
|
|
const char *pin)
|
|
|
|
{
|
|
|
|
struct wsc_station_dbus *wsc =
|
|
|
|
l_container_of(super, struct wsc_station_dbus, super);
|
|
|
|
scan_notify_func_t scan_callback;
|
|
|
|
enum wsc_device_password_id dpid;
|
|
|
|
|
|
|
|
wsc->station = station_find(netdev_get_ifindex(wsc->netdev));
|
|
|
|
if (!wsc->station) {
|
2020-01-17 19:05:47 +01:00
|
|
|
CONNECT_REPLY(wsc, dbus_error_not_available);
|
2020-01-16 05:29:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pin) {
|
|
|
|
if (strlen(pin) == 4 || wsc_pin_is_checksum_valid(pin))
|
|
|
|
dpid = WSC_DEVICE_PASSWORD_ID_DEFAULT;
|
|
|
|
else
|
|
|
|
dpid = WSC_DEVICE_PASSWORD_ID_USER_SPECIFIED;
|
|
|
|
|
|
|
|
scan_callback = pin_scan_results;
|
|
|
|
} else {
|
|
|
|
dpid = WSC_DEVICE_PASSWORD_ID_PUSH_BUTTON;
|
|
|
|
scan_callback = push_button_scan_results;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!wsc_initiate_scan(wsc, dpid, scan_callback)) {
|
2020-01-17 19:05:47 +01:00
|
|
|
CONNECT_REPLY(wsc, dbus_error_failed);
|
2020-01-16 05:29:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pin) {
|
|
|
|
wsc->walk_timer = l_timeout_create(60, pin_timeout, wsc, NULL);
|
|
|
|
} else {
|
|
|
|
wsc->walk_timer = l_timeout_create(WALK_TIME, walk_timeout, wsc,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wsc_station_dbus_cancel(struct wsc_dbus *super)
|
|
|
|
{
|
|
|
|
struct wsc_station_dbus *wsc =
|
|
|
|
l_container_of(super, struct wsc_station_dbus, super);
|
|
|
|
|
|
|
|
wsc_cancel_scan(wsc);
|
|
|
|
|
|
|
|
if (wsc->station_state_watch) {
|
|
|
|
station_remove_state_watch(wsc->station,
|
|
|
|
wsc->station_state_watch);
|
|
|
|
wsc->station_state_watch = 0;
|
|
|
|
wsc->target = NULL;
|
|
|
|
}
|
|
|
|
|
2020-01-17 19:05:47 +01:00
|
|
|
CONNECT_REPLY(wsc, dbus_error_aborted);
|
2020-01-16 05:29:30 +01:00
|
|
|
|
|
|
|
if (wsc->enrollee)
|
|
|
|
wsc_enrollee_cancel(wsc->enrollee, true);
|
|
|
|
else
|
2020-01-17 19:05:47 +01:00
|
|
|
CANCEL_REPLY(wsc, l_dbus_message_new_method_return);
|
2020-01-16 05:29:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void wsc_station_dbus_remove(struct wsc_dbus *super)
|
|
|
|
{
|
|
|
|
struct wsc_station_dbus *wsc =
|
|
|
|
l_container_of(super, struct wsc_station_dbus, super);
|
|
|
|
|
|
|
|
wsc_cancel_scan(wsc);
|
|
|
|
|
|
|
|
if (wsc->station_state_watch) {
|
|
|
|
station_remove_state_watch(wsc->station,
|
|
|
|
wsc->station_state_watch);
|
|
|
|
wsc->station_state_watch = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wsc->enrollee)
|
2020-01-17 18:18:23 +01:00
|
|
|
wsc_enrollee_free(wsc->enrollee);
|
2020-01-16 05:29:30 +01:00
|
|
|
|
|
|
|
l_free(wsc);
|
|
|
|
}
|
|
|
|
|
2015-09-29 19:15:37 +02:00
|
|
|
static struct l_dbus_message *wsc_push_button(struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
void *user_data)
|
|
|
|
{
|
2020-01-16 05:29:30 +01:00
|
|
|
struct wsc_dbus *wsc = user_data;
|
2015-10-06 05:37:46 +02:00
|
|
|
|
2015-09-29 19:15:37 +02:00
|
|
|
l_debug("");
|
|
|
|
|
2020-01-16 05:29:30 +01:00
|
|
|
if (!l_dbus_message_get_arguments(message, ""))
|
|
|
|
return dbus_error_invalid_args(message);
|
2015-10-06 05:37:46 +02:00
|
|
|
|
2020-03-19 22:12:13 +01:00
|
|
|
if (wsc->pending_connect || wsc->pending_cancel)
|
2020-01-16 05:29:30 +01:00
|
|
|
return dbus_error_busy(message);
|
2017-02-21 23:20:16 +01:00
|
|
|
|
2020-01-16 05:29:30 +01:00
|
|
|
wsc->pending_connect = l_dbus_message_ref(message);
|
|
|
|
wsc->connect(wsc, NULL);
|
2015-10-06 05:37:46 +02:00
|
|
|
return NULL;
|
2015-09-29 19:15:37 +02:00
|
|
|
}
|
|
|
|
|
2017-02-17 20:43:58 +01:00
|
|
|
static struct l_dbus_message *wsc_generate_pin(struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
void *user_data)
|
|
|
|
{
|
2020-01-16 05:29:30 +01:00
|
|
|
struct wsc_dbus *wsc = user_data;
|
2017-02-17 20:43:58 +01:00
|
|
|
struct l_dbus_message *reply;
|
|
|
|
char pin[9];
|
|
|
|
|
|
|
|
l_debug("");
|
|
|
|
|
2020-01-16 05:29:30 +01:00
|
|
|
if (wsc->pending_connect)
|
2017-02-17 20:43:58 +01:00
|
|
|
return dbus_error_busy(message);
|
|
|
|
|
|
|
|
if (!wsc_pin_generate(pin))
|
|
|
|
return dbus_error_failed(message);
|
|
|
|
|
|
|
|
reply = l_dbus_message_new_method_return(message);
|
|
|
|
l_dbus_message_set_arguments(reply, "s", pin);
|
2020-04-03 18:45:11 +02:00
|
|
|
explicit_bzero(pin, 9);
|
2017-02-17 20:43:58 +01:00
|
|
|
|
|
|
|
return reply;
|
|
|
|
}
|
|
|
|
|
2017-02-23 00:03:44 +01:00
|
|
|
static struct l_dbus_message *wsc_start_pin(struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
void *user_data)
|
|
|
|
{
|
2020-01-16 05:29:30 +01:00
|
|
|
struct wsc_dbus *wsc = user_data;
|
2017-02-23 00:03:44 +01:00
|
|
|
const char *pin;
|
|
|
|
|
|
|
|
l_debug("");
|
|
|
|
|
2020-03-19 22:12:13 +01:00
|
|
|
if (wsc->pending_connect || wsc->pending_cancel)
|
2017-02-23 00:03:44 +01:00
|
|
|
return dbus_error_busy(message);
|
|
|
|
|
|
|
|
if (!l_dbus_message_get_arguments(message, "s", &pin))
|
|
|
|
return dbus_error_invalid_args(message);
|
|
|
|
|
|
|
|
if (!wsc_pin_is_valid(pin))
|
|
|
|
return dbus_error_invalid_format(message);
|
|
|
|
|
2020-01-16 05:29:30 +01:00
|
|
|
wsc->pending_connect = l_dbus_message_ref(message);
|
|
|
|
wsc->connect(wsc, pin);
|
2017-02-23 00:03:44 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-29 19:15:37 +02:00
|
|
|
static struct l_dbus_message *wsc_cancel(struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
void *user_data)
|
|
|
|
{
|
2020-01-16 05:29:30 +01:00
|
|
|
struct wsc_dbus *wsc = user_data;
|
2015-10-06 05:37:46 +02:00
|
|
|
|
2015-09-29 19:15:37 +02:00
|
|
|
l_debug("");
|
|
|
|
|
2020-01-16 05:29:30 +01:00
|
|
|
if (!l_dbus_message_get_arguments(message, ""))
|
|
|
|
return dbus_error_invalid_args(message);
|
|
|
|
|
|
|
|
if (!wsc->pending_connect)
|
2015-10-06 05:37:46 +02:00
|
|
|
return dbus_error_not_available(message);
|
|
|
|
|
2020-01-16 05:29:29 +01:00
|
|
|
if (wsc->pending_cancel)
|
|
|
|
return dbus_error_busy(message);
|
|
|
|
|
2020-01-16 05:29:30 +01:00
|
|
|
wsc->pending_cancel = l_dbus_message_ref(message);
|
|
|
|
wsc->cancel(wsc);
|
|
|
|
return NULL;
|
2015-09-29 19:15:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void setup_wsc_interface(struct l_dbus_interface *interface)
|
|
|
|
{
|
|
|
|
l_dbus_interface_method(interface, "PushButton", 0,
|
|
|
|
wsc_push_button, "", "");
|
2017-02-17 20:43:58 +01:00
|
|
|
l_dbus_interface_method(interface, "GeneratePin", 0,
|
|
|
|
wsc_generate_pin, "s", "", "pin");
|
2017-02-23 00:03:44 +01:00
|
|
|
l_dbus_interface_method(interface, "StartPin", 0,
|
|
|
|
wsc_start_pin, "", "s", "pin");
|
2015-09-29 19:15:37 +02:00
|
|
|
l_dbus_interface_method(interface, "Cancel", 0,
|
|
|
|
wsc_cancel, "", "");
|
|
|
|
}
|
|
|
|
|
2020-01-16 05:29:30 +01:00
|
|
|
bool wsc_dbus_add_interface(struct wsc_dbus *wsc)
|
2015-09-29 19:15:37 +02:00
|
|
|
{
|
2020-01-16 05:29:30 +01:00
|
|
|
struct l_dbus *dbus = dbus_get_bus();
|
2016-09-22 18:32:18 +02:00
|
|
|
|
2020-01-16 05:29:30 +01:00
|
|
|
if (!l_dbus_object_add_interface(dbus, wsc->get_path(wsc),
|
|
|
|
IWD_WSC_INTERFACE, wsc)) {
|
|
|
|
l_info("Unable to register %s interface", IWD_WSC_INTERFACE);
|
|
|
|
return false;
|
2016-09-22 23:29:19 +02:00
|
|
|
}
|
|
|
|
|
2020-01-16 05:29:30 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wsc_dbus_remove_interface(struct wsc_dbus *wsc)
|
|
|
|
{
|
|
|
|
struct l_dbus *dbus = dbus_get_bus();
|
|
|
|
|
|
|
|
l_dbus_object_remove_interface(dbus, wsc->get_path(wsc),
|
|
|
|
IWD_WSC_INTERFACE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wsc_dbus_free(void *user_data)
|
|
|
|
{
|
|
|
|
struct wsc_dbus *wsc = user_data;
|
|
|
|
|
|
|
|
if (wsc->pending_connect)
|
|
|
|
dbus_pending_reply(&wsc->pending_connect,
|
2020-01-17 18:40:57 +01:00
|
|
|
dbus_error_not_available(wsc->pending_connect));
|
2015-10-06 18:39:01 +02:00
|
|
|
|
2016-09-23 03:49:38 +02:00
|
|
|
if (wsc->pending_cancel)
|
|
|
|
dbus_pending_reply(&wsc->pending_cancel,
|
|
|
|
dbus_error_aborted(wsc->pending_cancel));
|
|
|
|
|
2020-01-16 05:29:30 +01:00
|
|
|
wsc->remove(wsc);
|
2015-09-29 19:15:37 +02:00
|
|
|
}
|
|
|
|
|
2020-01-16 05:29:30 +01:00
|
|
|
static void wsc_add_station(struct netdev *netdev)
|
2015-09-29 19:15:37 +02:00
|
|
|
{
|
2020-01-16 05:29:30 +01:00
|
|
|
struct wsc_station_dbus *wsc;
|
2015-09-29 19:15:37 +02:00
|
|
|
|
2019-11-07 00:50:59 +01:00
|
|
|
if (!wiphy_get_max_scan_ie_len(netdev_get_wiphy(netdev))) {
|
|
|
|
l_debug("Simple Configuration isn't supported by ifindex %u",
|
|
|
|
netdev_get_ifindex(netdev));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-01-16 05:29:30 +01:00
|
|
|
wsc = l_new(struct wsc_station_dbus, 1);
|
2018-08-20 06:28:07 +02:00
|
|
|
wsc->netdev = netdev;
|
2020-01-16 05:29:30 +01:00
|
|
|
wsc->super.get_path = wsc_station_dbus_get_path;
|
|
|
|
wsc->super.connect = wsc_station_dbus_connect;
|
|
|
|
wsc->super.cancel = wsc_station_dbus_cancel;
|
|
|
|
wsc->super.remove = wsc_station_dbus_remove;
|
2015-09-29 19:15:37 +02:00
|
|
|
|
2020-01-16 05:29:30 +01:00
|
|
|
if (!wsc_dbus_add_interface(&wsc->super))
|
|
|
|
wsc_station_dbus_remove(&wsc->super);
|
2015-09-29 19:15:37 +02:00
|
|
|
}
|
|
|
|
|
2020-01-16 05:29:30 +01:00
|
|
|
static void wsc_remove_station(struct netdev *netdev)
|
2015-09-29 19:15:37 +02:00
|
|
|
{
|
2016-07-14 02:38:04 +02:00
|
|
|
struct l_dbus *dbus = dbus_get_bus();
|
|
|
|
|
2018-08-20 06:28:07 +02:00
|
|
|
l_dbus_object_remove_interface(dbus, netdev_get_path(netdev),
|
2016-07-14 02:38:04 +02:00
|
|
|
IWD_WSC_INTERFACE);
|
2015-09-29 19:15:37 +02:00
|
|
|
}
|
|
|
|
|
2018-08-18 06:40:49 +02:00
|
|
|
static void wsc_netdev_watch(struct netdev *netdev,
|
|
|
|
enum netdev_watch_event event, void *userdata)
|
2018-07-18 01:39:54 +02:00
|
|
|
{
|
2018-08-18 06:40:49 +02:00
|
|
|
switch (event) {
|
|
|
|
case NETDEV_WATCH_EVENT_UP:
|
|
|
|
case NETDEV_WATCH_EVENT_NEW:
|
2018-11-29 18:45:20 +01:00
|
|
|
if (netdev_get_iftype(netdev) == NETDEV_IFTYPE_STATION &&
|
|
|
|
netdev_get_is_up(netdev))
|
2020-01-16 05:29:30 +01:00
|
|
|
wsc_add_station(netdev);
|
2018-08-18 06:40:49 +02:00
|
|
|
break;
|
|
|
|
case NETDEV_WATCH_EVENT_DOWN:
|
|
|
|
case NETDEV_WATCH_EVENT_DEL:
|
2020-01-16 05:29:30 +01:00
|
|
|
wsc_remove_station(netdev);
|
2018-07-18 01:39:54 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-22 17:01:53 +02:00
|
|
|
static int wsc_init(void)
|
2015-09-29 03:38:17 +02:00
|
|
|
{
|
2018-08-18 06:40:49 +02:00
|
|
|
l_debug("");
|
|
|
|
netdev_watch = netdev_watch_add(wsc_netdev_watch, NULL, NULL);
|
|
|
|
l_dbus_register_interface(dbus_get_bus(), IWD_WSC_INTERFACE,
|
2016-02-11 23:19:55 +01:00
|
|
|
setup_wsc_interface,
|
2020-01-16 05:29:30 +01:00
|
|
|
wsc_dbus_free, false);
|
2019-05-22 17:01:53 +02:00
|
|
|
return 0;
|
2015-09-29 03:38:17 +02:00
|
|
|
}
|
|
|
|
|
2019-05-22 17:01:53 +02:00
|
|
|
static void wsc_exit(void)
|
2015-09-29 03:38:17 +02:00
|
|
|
{
|
|
|
|
l_debug("");
|
2016-02-11 23:19:55 +01:00
|
|
|
l_dbus_unregister_interface(dbus_get_bus(), IWD_WSC_INTERFACE);
|
2018-08-18 06:40:49 +02:00
|
|
|
netdev_watch_remove(netdev_watch);
|
2015-09-29 03:38:17 +02:00
|
|
|
}
|
2019-05-22 17:01:53 +02:00
|
|
|
|
|
|
|
IWD_MODULE(wsc, wsc_init, wsc_exit)
|
2020-08-20 18:07:51 +02:00
|
|
|
IWD_MODULE_DEPENDS(wsc, netdev);
|