2014-07-29 21:25:01 +02:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Wireless daemon for Linux
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013-2014 Intel Corporation. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
2014-08-07 01:06:51 +02:00
|
|
|
#include <stdlib.h>
|
2014-10-23 21:32:12 +02:00
|
|
|
#include <stdio.h>
|
2014-11-05 16:18:28 +01:00
|
|
|
#include <errno.h>
|
2014-08-07 05:15:20 +02:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <linux/if.h>
|
2015-03-20 03:54:28 +01:00
|
|
|
#include <linux/if_packet.h>
|
2014-08-07 05:15:20 +02:00
|
|
|
#include <linux/if_ether.h>
|
2015-03-20 18:29:50 +01:00
|
|
|
|
2014-07-29 21:25:01 +02:00
|
|
|
#include <ell/ell.h>
|
|
|
|
|
|
|
|
#include "linux/nl80211.h"
|
2014-10-30 06:26:49 +01:00
|
|
|
#include "src/iwd.h"
|
2014-08-09 08:23:56 +02:00
|
|
|
#include "src/ie.h"
|
2014-07-29 21:25:01 +02:00
|
|
|
#include "src/wiphy.h"
|
2014-10-23 21:32:12 +02:00
|
|
|
#include "src/dbus.h"
|
2015-01-12 16:52:37 +01:00
|
|
|
#include "src/scan.h"
|
2015-01-15 12:32:28 +01:00
|
|
|
#include "src/util.h"
|
2015-02-26 14:31:27 +01:00
|
|
|
#include "src/eapol.h"
|
2015-03-06 12:17:18 +01:00
|
|
|
#include "src/agent.h"
|
|
|
|
#include "src/crypto.h"
|
2015-03-27 08:54:25 +01:00
|
|
|
#include "src/netdev.h"
|
2015-03-30 03:27:57 +02:00
|
|
|
#include "src/mpdu.h"
|
2015-04-27 14:51:28 +02:00
|
|
|
#include "src/storage.h"
|
2015-06-23 00:42:30 +02:00
|
|
|
#include "src/network.h"
|
2014-10-23 21:32:12 +02:00
|
|
|
|
2014-07-29 21:25:01 +02:00
|
|
|
static struct l_genl_family *nl80211 = NULL;
|
|
|
|
|
2015-01-28 13:14:54 +01:00
|
|
|
struct network {
|
2015-03-10 12:20:43 +01:00
|
|
|
char *object_path;
|
2015-01-28 13:14:54 +01:00
|
|
|
struct netdev *netdev;
|
2015-04-08 20:29:03 +02:00
|
|
|
char ssid[33];
|
2015-03-06 12:17:18 +01:00
|
|
|
unsigned char *psk;
|
|
|
|
unsigned int agent_request;
|
2015-01-28 13:14:54 +01:00
|
|
|
enum scan_ssid_security ssid_security;
|
|
|
|
struct l_queue *bss_list;
|
2015-04-27 14:51:28 +02:00
|
|
|
struct l_settings *settings;
|
|
|
|
bool update_psk:1; /* Whether PSK should be written to storage */
|
|
|
|
bool ask_psk:1; /* Whether we should force-ask agent for PSK */
|
2014-08-09 08:23:56 +02:00
|
|
|
};
|
|
|
|
|
2016-05-05 18:40:54 +02:00
|
|
|
enum netdev_state {
|
|
|
|
NETDEV_STATE_DISCONNECTED = 0, /* Disconnected, no auto-connect */
|
|
|
|
NETDEV_STATE_AUTOCONNECT, /* Disconnected, try auto-connect */
|
|
|
|
NETDEV_STATE_CONNECTING, /* Connecting */
|
|
|
|
NETDEV_STATE_CONNECTED,
|
|
|
|
NETDEV_STATE_DISCONNECTING,
|
|
|
|
};
|
|
|
|
|
2014-08-07 05:15:20 +02:00
|
|
|
struct netdev {
|
|
|
|
uint32_t index;
|
|
|
|
char name[IFNAMSIZ];
|
|
|
|
uint32_t type;
|
|
|
|
uint8_t addr[ETH_ALEN];
|
2015-06-23 00:02:52 +02:00
|
|
|
enum netdev_state state;
|
2014-08-09 08:23:56 +02:00
|
|
|
struct l_queue *bss_list;
|
2014-10-30 04:50:27 +01:00
|
|
|
struct l_queue *old_bss_list;
|
2015-02-13 23:12:07 +01:00
|
|
|
struct l_dbus_message *scan_pending;
|
2014-10-30 05:20:43 +01:00
|
|
|
struct l_hashmap *networks;
|
2015-05-01 04:38:27 +02:00
|
|
|
struct scan_bss *connected_bss;
|
2015-04-30 22:00:02 +02:00
|
|
|
struct network *connected_network;
|
2015-06-23 00:42:30 +02:00
|
|
|
struct l_queue *autoconnect_list;
|
2015-02-13 23:12:08 +01:00
|
|
|
struct l_dbus_message *connect_pending;
|
2015-04-08 22:03:28 +02:00
|
|
|
struct l_dbus_message *disconnect_pending;
|
2015-02-26 14:31:27 +01:00
|
|
|
struct l_io *eapol_io;
|
2015-03-30 04:11:19 +02:00
|
|
|
|
|
|
|
uint32_t pairwise_new_key_cmd_id;
|
|
|
|
uint32_t pairwise_set_key_cmd_id;
|
|
|
|
uint32_t group_new_key_cmd_id;
|
2015-05-18 13:31:40 +02:00
|
|
|
|
|
|
|
struct wiphy *wiphy;
|
2014-08-07 05:15:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct wiphy {
|
|
|
|
uint32_t id;
|
|
|
|
char name[20];
|
2014-08-08 00:41:30 +02:00
|
|
|
uint32_t feature_flags;
|
2014-08-07 05:15:20 +02:00
|
|
|
struct l_queue *netdev_list;
|
2015-04-17 19:27:02 +02:00
|
|
|
bool support_scheduled_scan:1;
|
2015-05-06 22:24:14 +02:00
|
|
|
bool support_rekey_offload:1;
|
2015-04-17 20:02:32 +02:00
|
|
|
uint16_t pairwise_ciphers;
|
2015-10-06 22:23:32 +02:00
|
|
|
struct scan_freq_set *supported_freqs;
|
2014-08-07 05:15:20 +02:00
|
|
|
};
|
|
|
|
|
2015-06-23 00:42:30 +02:00
|
|
|
struct autoconnect_entry {
|
|
|
|
uint16_t rank;
|
|
|
|
struct network *network;
|
|
|
|
struct scan_bss *bss;
|
|
|
|
};
|
|
|
|
|
2014-08-07 05:15:20 +02:00
|
|
|
static struct l_queue *wiphy_list = NULL;
|
|
|
|
|
2015-09-20 21:58:23 +02:00
|
|
|
static bool new_scan_results(uint32_t wiphy_id, uint32_t ifindex,
|
|
|
|
struct l_queue *bss_list, void *userdata);
|
|
|
|
|
2015-03-20 03:54:28 +01:00
|
|
|
static bool eapol_read(struct l_io *io, void *user_data)
|
|
|
|
{
|
|
|
|
struct netdev *netdev = user_data;
|
|
|
|
int fd = l_io_get_fd(io);
|
|
|
|
struct sockaddr_ll sll;
|
|
|
|
socklen_t sll_len;
|
|
|
|
ssize_t bytes;
|
|
|
|
uint8_t frame[2304]; /* IEEE Std 802.11 ch. 8.2.3 */
|
|
|
|
|
2015-03-20 06:43:54 +01:00
|
|
|
memset(&sll, 0, sizeof(sll));
|
2015-03-20 03:54:28 +01:00
|
|
|
sll_len = sizeof(sll);
|
|
|
|
|
|
|
|
bytes = recvfrom(fd, frame, sizeof(frame), 0,
|
|
|
|
(struct sockaddr *) &sll, &sll_len);
|
|
|
|
if (bytes <= 0) {
|
2015-03-20 18:30:11 +01:00
|
|
|
l_error("EAPoL read socket: %s", strerror(errno));
|
2015-03-20 03:54:28 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
__eapol_rx_packet(netdev->index, netdev->addr, sll.sll_addr,
|
2015-10-30 11:12:19 +01:00
|
|
|
frame, bytes);
|
2015-03-20 03:54:28 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-03-10 12:20:43 +01:00
|
|
|
static const char *iwd_network_get_path(struct netdev *netdev,
|
|
|
|
const uint8_t *ssid, size_t ssid_len,
|
2015-01-28 13:14:54 +01:00
|
|
|
enum scan_ssid_security ssid_security)
|
|
|
|
{
|
|
|
|
static char path[256];
|
2015-03-10 12:20:43 +01:00
|
|
|
unsigned int pos, i;
|
|
|
|
|
|
|
|
pos = snprintf(path, sizeof(path), "%s/", iwd_device_get_path(netdev));
|
2015-01-28 13:14:54 +01:00
|
|
|
|
|
|
|
for (i = 0; i < ssid_len && pos < sizeof(path); i++)
|
|
|
|
pos += snprintf(path + pos, sizeof(path) - pos, "%02x",
|
2015-03-10 12:20:43 +01:00
|
|
|
ssid[i]);
|
2015-01-28 13:14:54 +01:00
|
|
|
|
2015-03-10 12:20:43 +01:00
|
|
|
snprintf(path + pos, sizeof(path) - pos, "_%s",
|
2016-02-10 00:08:03 +01:00
|
|
|
scan_ssid_security_to_str(ssid_security));
|
2015-01-28 13:14:54 +01:00
|
|
|
|
2014-10-23 22:09:52 +02:00
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2014-11-03 22:36:52 +01:00
|
|
|
static bool __iwd_network_append_properties(const struct network *network,
|
2014-10-30 06:01:52 +01:00
|
|
|
struct l_dbus_message_builder *builder)
|
|
|
|
{
|
2016-03-04 00:53:34 +01:00
|
|
|
bool connected;
|
2014-10-30 06:01:52 +01:00
|
|
|
|
2016-03-04 00:53:34 +01:00
|
|
|
l_dbus_message_builder_enter_array(builder, "{sv}");
|
2015-04-08 20:29:03 +02:00
|
|
|
dbus_dict_append_string(builder, "Name", network->ssid);
|
2014-10-30 06:01:52 +01:00
|
|
|
|
2016-03-04 00:53:34 +01:00
|
|
|
connected = network->netdev->connected_network == network;
|
|
|
|
dbus_dict_append_bool(builder, "Connected", connected);
|
2014-10-30 06:01:52 +01:00
|
|
|
l_dbus_message_builder_leave_array(builder);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-23 00:02:52 +02:00
|
|
|
static const char *netdev_state_to_string(enum netdev_state state)
|
|
|
|
{
|
|
|
|
switch (state) {
|
|
|
|
case NETDEV_STATE_DISCONNECTED:
|
|
|
|
return "disconnected";
|
|
|
|
case NETDEV_STATE_AUTOCONNECT:
|
|
|
|
return "autoconnect";
|
|
|
|
case NETDEV_STATE_CONNECTING:
|
|
|
|
return "connecting";
|
|
|
|
case NETDEV_STATE_CONNECTED:
|
|
|
|
return "connected";
|
|
|
|
case NETDEV_STATE_DISCONNECTING:
|
|
|
|
return "disconnecting";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "invalid";
|
|
|
|
}
|
|
|
|
|
2015-10-02 19:58:26 +02:00
|
|
|
uint32_t netdev_get_ifindex(struct netdev *netdev)
|
|
|
|
{
|
|
|
|
return netdev->index;
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint8_t *netdev_get_address(struct netdev *netdev)
|
|
|
|
{
|
|
|
|
return netdev->addr;
|
|
|
|
}
|
|
|
|
|
2015-06-23 00:02:52 +02:00
|
|
|
static void netdev_enter_state(struct netdev *netdev, enum netdev_state state)
|
|
|
|
{
|
|
|
|
l_debug("Old State: %s, new state: %s",
|
|
|
|
netdev_state_to_string(netdev->state),
|
|
|
|
netdev_state_to_string(state));
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case NETDEV_STATE_AUTOCONNECT:
|
2015-09-20 21:58:23 +02:00
|
|
|
scan_periodic_start(netdev->index, new_scan_results, netdev);
|
2015-06-23 00:02:52 +02:00
|
|
|
break;
|
|
|
|
case NETDEV_STATE_DISCONNECTED:
|
|
|
|
scan_periodic_stop(netdev->index);
|
|
|
|
break;
|
|
|
|
case NETDEV_STATE_CONNECTED:
|
|
|
|
scan_periodic_stop(netdev->index);
|
|
|
|
break;
|
|
|
|
case NETDEV_STATE_CONNECTING:
|
|
|
|
break;
|
|
|
|
case NETDEV_STATE_DISCONNECTING:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
netdev->state = state;
|
|
|
|
}
|
|
|
|
|
2015-04-27 14:51:28 +02:00
|
|
|
static void netdev_disassociated(struct netdev *netdev)
|
|
|
|
{
|
2015-04-30 22:00:02 +02:00
|
|
|
struct network *network = netdev->connected_network;
|
2015-04-27 14:51:28 +02:00
|
|
|
|
|
|
|
l_settings_free(network->settings);
|
|
|
|
network->settings = NULL;
|
|
|
|
|
|
|
|
netdev->connected_bss = NULL;
|
2015-04-30 22:00:02 +02:00
|
|
|
netdev->connected_network = NULL;
|
2015-06-23 00:02:52 +02:00
|
|
|
|
|
|
|
netdev_enter_state(netdev, NETDEV_STATE_AUTOCONNECT);
|
2015-04-27 14:51:28 +02:00
|
|
|
}
|
|
|
|
|
2015-05-01 01:42:44 +02:00
|
|
|
static void netdev_lost_beacon(struct netdev *netdev)
|
|
|
|
{
|
|
|
|
if (netdev->connect_pending)
|
|
|
|
dbus_pending_reply(&netdev->connect_pending,
|
|
|
|
dbus_error_failed(netdev->connect_pending));
|
|
|
|
|
2016-04-11 17:03:48 +02:00
|
|
|
if (netdev->connected_network)
|
|
|
|
netdev_disassociated(netdev);
|
2015-05-01 01:42:44 +02:00
|
|
|
}
|
|
|
|
|
2015-03-03 10:27:39 +01:00
|
|
|
static void genl_connect_cb(struct l_genl_msg *msg, void *user_data)
|
|
|
|
{
|
|
|
|
struct netdev *netdev = user_data;
|
|
|
|
|
2015-04-27 14:51:28 +02:00
|
|
|
if (l_genl_msg_get_error(msg) < 0) {
|
|
|
|
if (netdev->connect_pending)
|
|
|
|
dbus_pending_reply(&netdev->connect_pending,
|
2015-03-03 10:27:39 +01:00
|
|
|
dbus_error_failed(netdev->connect_pending));
|
2015-04-27 14:51:28 +02:00
|
|
|
|
|
|
|
netdev_disassociated(netdev);
|
|
|
|
}
|
2015-03-03 10:27:39 +01:00
|
|
|
}
|
|
|
|
|
2015-05-26 19:51:23 +02:00
|
|
|
static enum ie_rsn_cipher_suite wiphy_select_cipher(struct wiphy *wiphy,
|
|
|
|
uint16_t mask)
|
|
|
|
{
|
|
|
|
mask &= wiphy->pairwise_ciphers;
|
|
|
|
|
|
|
|
/* CCMP is our first choice, TKIP second */
|
|
|
|
if (mask & IE_RSN_CIPHER_SUITE_CCMP)
|
|
|
|
return IE_RSN_CIPHER_SUITE_CCMP;
|
|
|
|
|
|
|
|
if (mask & IE_RSN_CIPHER_SUITE_TKIP)
|
|
|
|
return IE_RSN_CIPHER_SUITE_TKIP;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct scan_bss *network_select_bss(struct wiphy *wiphy,
|
|
|
|
struct network *network)
|
|
|
|
{
|
|
|
|
struct l_queue *bss_list = network->bss_list;
|
|
|
|
const struct l_queue_entry *bss_entry;
|
|
|
|
|
|
|
|
/* TODO: sort the list by RSSI, potentially other criteria. */
|
|
|
|
|
|
|
|
switch (network->ssid_security) {
|
|
|
|
case SCAN_SSID_SECURITY_NONE:
|
|
|
|
/* Pick the first bss (strongest signal) */
|
|
|
|
return l_queue_peek_head(bss_list);
|
|
|
|
|
|
|
|
case SCAN_SSID_SECURITY_PSK:
|
2015-10-30 11:12:21 +01:00
|
|
|
case SCAN_SSID_SECURITY_8021X:
|
2015-05-26 19:51:23 +02:00
|
|
|
/* Pick the first bss that advertises any cipher we support. */
|
|
|
|
for (bss_entry = l_queue_get_entries(bss_list); bss_entry;
|
|
|
|
bss_entry = bss_entry->next) {
|
|
|
|
struct scan_bss *bss = bss_entry->data;
|
|
|
|
uint16_t pairwise_ciphers, group_ciphers;
|
|
|
|
|
|
|
|
bss_get_supported_ciphers(bss, &pairwise_ciphers,
|
|
|
|
&group_ciphers);
|
|
|
|
|
|
|
|
if (wiphy_select_cipher(wiphy, pairwise_ciphers) &&
|
|
|
|
wiphy_select_cipher(wiphy,
|
|
|
|
group_ciphers))
|
|
|
|
return bss;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mlme_authenticate_cmd(struct network *network, struct scan_bss *bss)
|
2015-03-06 12:17:18 +01:00
|
|
|
{
|
|
|
|
struct netdev *netdev = network->netdev;
|
|
|
|
uint32_t auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
|
|
|
|
struct l_genl_msg *msg;
|
|
|
|
|
|
|
|
msg = l_genl_msg_new_sized(NL80211_CMD_AUTHENTICATE, 512);
|
|
|
|
msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &netdev->index);
|
|
|
|
msg_append_attr(msg, NL80211_ATTR_WIPHY_FREQ, 4, &bss->frequency);
|
|
|
|
msg_append_attr(msg, NL80211_ATTR_MAC, ETH_ALEN, bss->addr);
|
2015-04-08 20:29:03 +02:00
|
|
|
msg_append_attr(msg, NL80211_ATTR_SSID, strlen(network->ssid),
|
2015-03-06 12:17:18 +01:00
|
|
|
network->ssid);
|
|
|
|
msg_append_attr(msg, NL80211_ATTR_AUTH_TYPE, 4, &auth_type);
|
|
|
|
l_genl_family_send(nl80211, msg, genl_connect_cb, netdev, NULL);
|
|
|
|
|
|
|
|
netdev->connected_bss = bss;
|
2015-04-30 22:00:02 +02:00
|
|
|
netdev->connected_network = network;
|
2015-06-23 00:02:52 +02:00
|
|
|
netdev_enter_state(netdev, NETDEV_STATE_CONNECTING);
|
2015-03-06 12:17:18 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void passphrase_callback(enum agent_result result,
|
|
|
|
const char *passphrase, void *user_data)
|
|
|
|
{
|
|
|
|
struct network *network = user_data;
|
|
|
|
struct netdev *netdev = network->netdev;
|
2015-05-26 19:51:23 +02:00
|
|
|
struct wiphy *wiphy = netdev->wiphy;
|
|
|
|
struct scan_bss *bss;
|
2015-03-06 12:17:18 +01:00
|
|
|
|
|
|
|
l_debug("result %d", result);
|
|
|
|
|
|
|
|
network->agent_request = 0;
|
|
|
|
|
|
|
|
if (result != AGENT_RESULT_OK) {
|
|
|
|
dbus_pending_reply(&netdev->connect_pending,
|
|
|
|
dbus_error_aborted(netdev->connect_pending));
|
2015-05-26 19:51:23 +02:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
bss = network_select_bss(wiphy, network);
|
|
|
|
|
|
|
|
/* Did all good BSSes go away while we waited */
|
|
|
|
if (!bss) {
|
|
|
|
dbus_pending_reply(&netdev->connect_pending,
|
|
|
|
dbus_error_failed(netdev->connect_pending));
|
|
|
|
goto err;
|
2015-03-06 12:17:18 +01:00
|
|
|
}
|
|
|
|
|
2015-04-27 14:51:28 +02:00
|
|
|
l_free(network->psk);
|
2015-03-06 12:17:18 +01:00
|
|
|
network->psk = l_malloc(32);
|
|
|
|
|
2015-04-08 20:29:03 +02:00
|
|
|
if (crypto_psk_from_passphrase(passphrase, (uint8_t *) network->ssid,
|
|
|
|
strlen(network->ssid),
|
|
|
|
network->psk) < 0) {
|
2015-03-20 21:22:44 +01:00
|
|
|
l_error("PMK generation failed. "
|
|
|
|
"Ensure Crypto Engine is properly configured");
|
2015-03-06 12:17:18 +01:00
|
|
|
dbus_pending_reply(&netdev->connect_pending,
|
|
|
|
dbus_error_failed(netdev->connect_pending));
|
|
|
|
|
2015-05-26 19:51:23 +02:00
|
|
|
goto err;
|
2015-03-06 12:17:18 +01:00
|
|
|
}
|
|
|
|
|
2015-04-27 14:51:28 +02:00
|
|
|
/*
|
|
|
|
* We need to store the PSK in our permanent store. However, before
|
|
|
|
* we do that, make sure the PSK works. We write to the store only
|
|
|
|
* when we are connected
|
|
|
|
*/
|
|
|
|
network->update_psk = true;
|
|
|
|
|
2015-05-26 19:51:23 +02:00
|
|
|
mlme_authenticate_cmd(network, bss);
|
|
|
|
return;
|
2015-03-06 12:17:18 +01:00
|
|
|
|
2015-05-26 19:51:23 +02:00
|
|
|
err:
|
|
|
|
l_settings_free(network->settings);
|
|
|
|
network->settings = NULL;
|
2015-05-18 13:31:40 +02:00
|
|
|
|
2015-05-26 19:51:23 +02:00
|
|
|
l_free(network->psk);
|
|
|
|
network->psk = NULL;
|
2015-05-18 13:31:40 +02:00
|
|
|
}
|
|
|
|
|
2015-04-27 14:51:28 +02:00
|
|
|
static struct l_dbus_message *network_connect_psk(struct network *network,
|
2015-05-26 19:51:23 +02:00
|
|
|
struct scan_bss *bss,
|
2015-04-27 14:51:28 +02:00
|
|
|
struct l_dbus_message *message)
|
|
|
|
{
|
|
|
|
struct netdev *netdev = network->netdev;
|
|
|
|
const char *psk;
|
|
|
|
|
|
|
|
l_debug("");
|
|
|
|
|
|
|
|
network->settings = storage_network_open("psk", network->ssid);
|
|
|
|
psk = l_settings_get_value(network->settings, "Security",
|
|
|
|
"PreSharedKey");
|
|
|
|
|
|
|
|
if (psk) {
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
l_debug("psk: %s", psk);
|
2015-05-01 00:00:38 +02:00
|
|
|
|
|
|
|
l_free(network->psk);
|
2015-04-27 14:51:28 +02:00
|
|
|
network->psk = l_util_from_hexstring(psk, &len);
|
|
|
|
|
|
|
|
l_debug("len: %zd", len);
|
|
|
|
|
|
|
|
if (network->psk && len != 32) {
|
|
|
|
l_debug("Can't parse PSK");
|
|
|
|
l_free(network->psk);
|
|
|
|
network->psk = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
l_debug("ask_psk: %s", network->ask_psk ? "true" : "false");
|
|
|
|
|
|
|
|
if (network->ask_psk || !network->psk) {
|
|
|
|
network->ask_psk = false;
|
|
|
|
|
|
|
|
network->agent_request =
|
|
|
|
agent_request_passphrase(network->object_path,
|
|
|
|
passphrase_callback,
|
|
|
|
network);
|
|
|
|
|
|
|
|
if (!network->agent_request)
|
|
|
|
return dbus_error_no_agent(message);
|
|
|
|
} else
|
2015-05-26 19:51:23 +02:00
|
|
|
mlme_authenticate_cmd(network, bss);
|
2015-04-27 14:51:28 +02:00
|
|
|
|
|
|
|
netdev->connect_pending = l_dbus_message_ref(message);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-10-30 06:27:06 +01:00
|
|
|
static struct l_dbus_message *network_connect(struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct network *network = user_data;
|
|
|
|
struct netdev *netdev = network->netdev;
|
2015-05-26 19:51:23 +02:00
|
|
|
struct scan_bss *bss;
|
2015-02-13 23:12:08 +01:00
|
|
|
|
|
|
|
l_debug("");
|
|
|
|
|
2015-06-23 00:02:52 +02:00
|
|
|
if (netdev->state != NETDEV_STATE_DISCONNECTED &&
|
|
|
|
netdev->state != NETDEV_STATE_AUTOCONNECT)
|
2015-02-13 23:12:08 +01:00
|
|
|
return dbus_error_busy(message);
|
2014-10-30 06:27:06 +01:00
|
|
|
|
2015-05-26 19:51:23 +02:00
|
|
|
/*
|
|
|
|
* Select the best BSS to use at this time. If we have to query the
|
|
|
|
* agent this may not be the final choice because BSS visibility can
|
|
|
|
* change while we wait for the agent.
|
|
|
|
*/
|
|
|
|
bss = network_select_bss(netdev->wiphy, network);
|
|
|
|
|
|
|
|
/* None of the BSSes is compatible with our stack */
|
|
|
|
if (!bss)
|
|
|
|
return dbus_error_not_supported(message);
|
|
|
|
|
2015-02-25 06:19:27 +01:00
|
|
|
switch (network->ssid_security) {
|
|
|
|
case SCAN_SSID_SECURITY_PSK:
|
2015-05-26 19:51:23 +02:00
|
|
|
return network_connect_psk(network, bss, message);
|
2015-03-06 12:17:18 +01:00
|
|
|
case SCAN_SSID_SECURITY_NONE:
|
2015-10-30 11:12:21 +01:00
|
|
|
mlme_authenticate_cmd(network, bss);
|
|
|
|
netdev->connect_pending = l_dbus_message_ref(message);
|
|
|
|
return NULL;
|
|
|
|
case SCAN_SSID_SECURITY_8021X:
|
|
|
|
network->settings = storage_network_open("8021x",
|
|
|
|
network->ssid);
|
|
|
|
|
2015-05-26 19:51:23 +02:00
|
|
|
mlme_authenticate_cmd(network, bss);
|
2015-04-27 14:51:28 +02:00
|
|
|
netdev->connect_pending = l_dbus_message_ref(message);
|
|
|
|
return NULL;
|
2015-02-25 06:19:27 +01:00
|
|
|
default:
|
|
|
|
return dbus_error_not_supported(message);
|
|
|
|
}
|
2014-10-30 06:27:06 +01:00
|
|
|
}
|
|
|
|
|
2016-02-11 23:19:55 +01:00
|
|
|
static bool network_property_get_name(struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
struct l_dbus_message_builder *builder,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct network *network = user_data;
|
|
|
|
|
|
|
|
l_dbus_message_builder_append_basic(builder, 's', network->ssid);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-04 00:53:34 +01:00
|
|
|
static bool network_property_is_connected(struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
struct l_dbus_message_builder *builder,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct network *network = user_data;
|
|
|
|
bool connected;
|
|
|
|
|
|
|
|
connected = network->netdev->connected_network == network;
|
|
|
|
l_dbus_message_builder_append_basic(builder, 'b', &connected);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-30 06:01:52 +01:00
|
|
|
static void setup_network_interface(struct l_dbus_interface *interface)
|
|
|
|
{
|
2014-10-30 06:27:06 +01:00
|
|
|
l_dbus_interface_method(interface, "Connect", 0,
|
|
|
|
network_connect,
|
|
|
|
"", "");
|
2014-10-30 06:01:52 +01:00
|
|
|
|
2016-02-11 23:19:55 +01:00
|
|
|
l_dbus_interface_property(interface, "Name", 0, "s",
|
|
|
|
network_property_get_name, NULL);
|
2016-03-04 00:53:34 +01:00
|
|
|
|
|
|
|
l_dbus_interface_property(interface, "Connected", 0, "b",
|
|
|
|
network_property_is_connected,
|
|
|
|
NULL);
|
2014-10-30 06:01:52 +01:00
|
|
|
}
|
|
|
|
|
2014-10-30 06:09:16 +01:00
|
|
|
static void network_emit_added(struct network *network)
|
|
|
|
{
|
|
|
|
struct l_dbus *dbus = dbus_get_bus();
|
|
|
|
struct l_dbus_message *signal;
|
|
|
|
struct l_dbus_message_builder *builder;
|
|
|
|
|
|
|
|
signal = l_dbus_message_new_signal(dbus,
|
|
|
|
iwd_device_get_path(network->netdev),
|
|
|
|
IWD_DEVICE_INTERFACE,
|
|
|
|
"NetworkAdded");
|
|
|
|
|
|
|
|
if (!signal)
|
|
|
|
return;
|
|
|
|
|
|
|
|
builder = l_dbus_message_builder_new(signal);
|
|
|
|
if (!builder) {
|
|
|
|
l_dbus_message_unref(signal);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
l_dbus_message_builder_append_basic(builder, 'o',
|
2015-03-10 12:20:43 +01:00
|
|
|
network->object_path);
|
2014-10-30 06:09:16 +01:00
|
|
|
__iwd_network_append_properties(network, builder);
|
|
|
|
|
|
|
|
l_dbus_message_builder_finalize(builder);
|
|
|
|
l_dbus_message_builder_destroy(builder);
|
|
|
|
l_dbus_send(dbus, signal);
|
|
|
|
}
|
|
|
|
|
2014-10-30 06:09:29 +01:00
|
|
|
static void network_emit_removed(struct network *network)
|
|
|
|
{
|
|
|
|
struct l_dbus *dbus = dbus_get_bus();
|
|
|
|
struct l_dbus_message *signal;
|
|
|
|
|
|
|
|
signal = l_dbus_message_new_signal(dbus,
|
|
|
|
iwd_device_get_path(network->netdev),
|
|
|
|
IWD_DEVICE_INTERFACE,
|
|
|
|
"NetworkRemoved");
|
|
|
|
|
|
|
|
if (!signal)
|
|
|
|
return;
|
|
|
|
|
2015-03-10 12:20:43 +01:00
|
|
|
l_dbus_message_set_arguments(signal, "o", network->object_path);
|
2014-10-30 06:09:29 +01:00
|
|
|
l_dbus_send(dbus, signal);
|
|
|
|
}
|
|
|
|
|
2015-01-28 13:14:54 +01:00
|
|
|
static void bss_free(void *data)
|
|
|
|
{
|
2015-05-01 04:38:27 +02:00
|
|
|
struct scan_bss *bss = data;
|
2015-01-28 13:14:54 +01:00
|
|
|
|
|
|
|
l_debug("Freeing BSS %02X:%02X:%02X:%02X:%02X:%02X",
|
|
|
|
bss->addr[0], bss->addr[1], bss->addr[2],
|
|
|
|
bss->addr[3], bss->addr[4], bss->addr[5]);
|
2015-05-01 05:21:31 +02:00
|
|
|
|
|
|
|
scan_bss_free(bss);
|
2015-01-28 13:14:54 +01:00
|
|
|
}
|
|
|
|
|
2014-10-30 05:20:43 +01:00
|
|
|
static void network_free(void *data)
|
|
|
|
{
|
|
|
|
struct network *network = data;
|
2014-10-30 06:01:52 +01:00
|
|
|
struct l_dbus *dbus;
|
|
|
|
|
2015-03-06 12:17:18 +01:00
|
|
|
agent_request_cancel(network->agent_request);
|
2015-04-30 23:21:21 +02:00
|
|
|
l_settings_free(network->settings);
|
2015-03-06 12:17:18 +01:00
|
|
|
|
2014-10-30 06:01:52 +01:00
|
|
|
dbus = dbus_get_bus();
|
2016-02-11 23:19:55 +01:00
|
|
|
l_dbus_unregister_object(dbus, network->object_path);
|
2014-10-30 06:09:29 +01:00
|
|
|
network_emit_removed(network);
|
2014-10-30 05:20:43 +01:00
|
|
|
|
2015-03-10 12:20:43 +01:00
|
|
|
l_free(network->object_path);
|
|
|
|
|
2015-01-29 04:10:35 +01:00
|
|
|
l_queue_destroy(network->bss_list, NULL);
|
2015-03-06 12:17:18 +01:00
|
|
|
l_free(network->psk);
|
2014-10-30 05:20:43 +01:00
|
|
|
l_free(network);
|
|
|
|
}
|
|
|
|
|
2014-10-30 06:01:52 +01:00
|
|
|
const char *iwd_device_get_path(struct netdev *netdev)
|
|
|
|
{
|
2015-02-26 12:03:05 +01:00
|
|
|
static char path[12];
|
2014-10-30 06:01:52 +01:00
|
|
|
|
|
|
|
snprintf(path, sizeof(path), "/%u", netdev->index);
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2014-10-23 23:52:57 +02:00
|
|
|
bool __iwd_device_append_properties(struct netdev *netdev,
|
|
|
|
struct l_dbus_message_builder *builder)
|
|
|
|
{
|
|
|
|
l_dbus_message_builder_enter_array(builder, "{sv}");
|
|
|
|
|
|
|
|
dbus_dict_append_string(builder, "Name", netdev->name);
|
|
|
|
|
2016-03-09 21:44:52 +01:00
|
|
|
if (netdev->connected_network)
|
|
|
|
dbus_dict_append_object(builder, "ConnectedNetwork",
|
|
|
|
netdev->connected_network->object_path);
|
|
|
|
|
2014-10-23 23:52:57 +02:00
|
|
|
l_dbus_message_builder_leave_array(builder);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-24 04:47:38 +02:00
|
|
|
void __iwd_device_foreach(iwd_device_foreach_func func, void *user_data)
|
|
|
|
{
|
|
|
|
const struct l_queue_entry *wiphy_entry;
|
|
|
|
|
|
|
|
for (wiphy_entry = l_queue_get_entries(wiphy_list); wiphy_entry;
|
|
|
|
wiphy_entry = wiphy_entry->next) {
|
|
|
|
struct wiphy *wiphy = wiphy_entry->data;
|
|
|
|
const struct l_queue_entry *netdev_entry;
|
|
|
|
|
|
|
|
netdev_entry = l_queue_get_entries(wiphy->netdev_list);
|
|
|
|
|
|
|
|
while (netdev_entry) {
|
|
|
|
struct netdev *netdev = netdev_entry->data;
|
|
|
|
|
|
|
|
func(netdev, user_data);
|
|
|
|
netdev_entry = netdev_entry->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-23 21:32:12 +02:00
|
|
|
static void device_emit_added(struct netdev *netdev)
|
|
|
|
{
|
2014-10-23 22:11:17 +02:00
|
|
|
struct l_dbus *dbus = dbus_get_bus();
|
|
|
|
struct l_dbus_message *signal;
|
|
|
|
struct l_dbus_message_builder *builder;
|
|
|
|
|
|
|
|
signal = l_dbus_message_new_signal(dbus, IWD_MANAGER_PATH,
|
|
|
|
IWD_MANAGER_INTERFACE,
|
|
|
|
"DeviceAdded");
|
|
|
|
|
|
|
|
if (!signal)
|
|
|
|
return;
|
|
|
|
|
|
|
|
builder = l_dbus_message_builder_new(signal);
|
|
|
|
if (!builder) {
|
|
|
|
l_dbus_message_unref(signal);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
l_dbus_message_builder_append_basic(builder, 'o',
|
2014-10-24 05:40:32 +02:00
|
|
|
iwd_device_get_path(netdev));
|
2014-10-24 03:25:23 +02:00
|
|
|
__iwd_device_append_properties(netdev, builder);
|
2014-10-23 21:32:12 +02:00
|
|
|
|
2014-10-23 22:11:17 +02:00
|
|
|
l_dbus_message_builder_finalize(builder);
|
|
|
|
l_dbus_message_builder_destroy(builder);
|
|
|
|
l_dbus_send(dbus, signal);
|
2014-10-23 21:32:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void device_emit_removed(struct netdev *netdev)
|
|
|
|
{
|
2014-10-23 22:11:01 +02:00
|
|
|
struct l_dbus *dbus = dbus_get_bus();
|
|
|
|
struct l_dbus_message *signal;
|
2014-10-23 21:32:12 +02:00
|
|
|
|
2014-10-23 22:11:01 +02:00
|
|
|
signal = l_dbus_message_new_signal(dbus, IWD_MANAGER_PATH,
|
|
|
|
IWD_MANAGER_INTERFACE,
|
|
|
|
"DeviceRemoved");
|
|
|
|
|
|
|
|
if (!signal)
|
|
|
|
return;
|
|
|
|
|
2014-10-24 05:40:32 +02:00
|
|
|
l_dbus_message_set_arguments(signal, "o", iwd_device_get_path(netdev));
|
2014-10-23 22:11:01 +02:00
|
|
|
l_dbus_send(dbus, signal);
|
2014-10-23 21:32:12 +02:00
|
|
|
}
|
|
|
|
|
2015-09-22 21:05:50 +02:00
|
|
|
static void device_scan_triggered(int err, void *user_data)
|
2014-10-28 05:43:21 +01:00
|
|
|
{
|
|
|
|
struct netdev *netdev = user_data;
|
|
|
|
struct l_dbus_message *reply;
|
|
|
|
|
2015-09-22 21:05:50 +02:00
|
|
|
l_debug("device_scan_triggered: %i", err);
|
2015-03-11 14:31:51 +01:00
|
|
|
|
2015-09-22 21:05:50 +02:00
|
|
|
if (err < 0) {
|
2015-02-13 23:12:07 +01:00
|
|
|
dbus_pending_reply(&netdev->scan_pending,
|
|
|
|
dbus_error_failed(netdev->scan_pending));
|
2014-10-28 05:43:21 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
l_debug("Scan triggered for netdev %s", netdev->name);
|
|
|
|
|
2015-02-13 23:12:07 +01:00
|
|
|
reply = l_dbus_message_new_method_return(netdev->scan_pending);
|
2014-10-28 05:43:21 +01:00
|
|
|
l_dbus_message_set_arguments(reply, "");
|
2015-02-13 23:12:07 +01:00
|
|
|
dbus_pending_reply(&netdev->scan_pending, reply);
|
2014-10-28 05:43:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct l_dbus_message *device_scan(struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct netdev *netdev = user_data;
|
|
|
|
|
2015-03-11 14:31:51 +01:00
|
|
|
l_debug("Scan called from DBus");
|
|
|
|
|
2015-02-13 23:12:07 +01:00
|
|
|
if (netdev->scan_pending)
|
2014-10-28 05:43:21 +01:00
|
|
|
return dbus_error_busy(message);
|
|
|
|
|
2015-02-13 23:12:07 +01:00
|
|
|
netdev->scan_pending = l_dbus_message_ref(message);
|
2014-10-28 05:43:21 +01:00
|
|
|
|
2015-09-22 21:05:50 +02:00
|
|
|
if (!scan_passive(netdev->index, device_scan_triggered,
|
|
|
|
new_scan_results, netdev, NULL))
|
|
|
|
return dbus_error_failed(message);
|
2014-10-28 05:43:21 +01:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-11-03 22:37:08 +01:00
|
|
|
static void append_network_properties(const void *key, void *value,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct network *network = value;
|
|
|
|
struct l_dbus_message_builder *builder = user_data;
|
|
|
|
|
|
|
|
l_dbus_message_builder_enter_dict(builder, "oa{sv}");
|
|
|
|
l_dbus_message_builder_append_basic(builder, 'o',
|
2015-03-10 12:20:43 +01:00
|
|
|
network->object_path);
|
2014-11-03 22:37:08 +01:00
|
|
|
__iwd_network_append_properties(network, builder);
|
|
|
|
l_dbus_message_builder_leave_dict(builder);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct l_dbus_message *device_get_networks(struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct netdev *netdev = user_data;
|
|
|
|
struct l_dbus_message *reply;
|
|
|
|
struct l_dbus_message_builder *builder;
|
|
|
|
|
|
|
|
reply = l_dbus_message_new_method_return(message);
|
|
|
|
builder = l_dbus_message_builder_new(reply);
|
|
|
|
|
|
|
|
l_dbus_message_builder_enter_array(builder, "{oa{sv}}");
|
|
|
|
l_hashmap_foreach(netdev->networks, append_network_properties, builder);
|
|
|
|
l_dbus_message_builder_leave_array(builder);
|
|
|
|
|
|
|
|
l_dbus_message_builder_finalize(builder);
|
|
|
|
l_dbus_message_builder_destroy(builder);
|
|
|
|
|
|
|
|
return reply;
|
|
|
|
}
|
|
|
|
|
2015-09-28 18:32:26 +02:00
|
|
|
static void device_disconnect_cb(struct l_genl_msg *msg, void *user_data)
|
2015-03-03 10:27:39 +01:00
|
|
|
{
|
|
|
|
struct netdev *netdev = user_data;
|
2015-04-08 22:03:28 +02:00
|
|
|
struct l_dbus_message *reply;
|
2015-03-03 10:27:39 +01:00
|
|
|
|
2015-04-08 22:03:28 +02:00
|
|
|
if (l_genl_msg_get_error(msg) < 0) {
|
|
|
|
dbus_pending_reply(&netdev->disconnect_pending,
|
|
|
|
dbus_error_failed(netdev->disconnect_pending));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-01 00:01:20 +02:00
|
|
|
netdev_disassociated(netdev);
|
|
|
|
|
2015-04-08 22:03:28 +02:00
|
|
|
reply = l_dbus_message_new_method_return(netdev->disconnect_pending);
|
|
|
|
l_dbus_message_set_arguments(reply, "");
|
|
|
|
dbus_pending_reply(&netdev->disconnect_pending, reply);
|
2015-03-03 10:27:39 +01:00
|
|
|
}
|
|
|
|
|
2015-02-20 12:27:58 +01:00
|
|
|
static struct l_dbus_message *device_disconnect(struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct netdev *netdev = user_data;
|
|
|
|
struct l_genl_msg *msg;
|
2015-03-30 03:27:57 +02:00
|
|
|
uint16_t reason_code = MPDU_REASON_CODE_DEAUTH_LEAVING;
|
2015-02-20 12:27:58 +01:00
|
|
|
|
|
|
|
l_debug("");
|
|
|
|
|
2015-06-23 00:02:52 +02:00
|
|
|
if (netdev->state == NETDEV_STATE_CONNECTING ||
|
|
|
|
netdev->state == NETDEV_STATE_DISCONNECTING)
|
2015-05-01 01:42:55 +02:00
|
|
|
return dbus_error_busy(message);
|
2015-02-20 12:27:58 +01:00
|
|
|
|
|
|
|
if (!netdev->connected_bss)
|
2015-05-01 01:42:55 +02:00
|
|
|
return dbus_error_not_connected(message);
|
2015-02-20 12:27:58 +01:00
|
|
|
|
2015-04-30 22:00:02 +02:00
|
|
|
if (netdev->connected_network->ssid_security ==
|
2015-10-30 11:12:21 +01:00
|
|
|
SCAN_SSID_SECURITY_PSK ||
|
|
|
|
netdev->connected_network->ssid_security ==
|
|
|
|
SCAN_SSID_SECURITY_8021X)
|
2015-03-30 05:50:34 +02:00
|
|
|
eapol_cancel(netdev->index);
|
|
|
|
|
2015-02-20 12:27:58 +01:00
|
|
|
msg = l_genl_msg_new_sized(NL80211_CMD_DEAUTHENTICATE, 512);
|
|
|
|
msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &netdev->index);
|
|
|
|
msg_append_attr(msg, NL80211_ATTR_REASON_CODE, 2, &reason_code);
|
|
|
|
msg_append_attr(msg, NL80211_ATTR_MAC, ETH_ALEN,
|
|
|
|
netdev->connected_bss->addr);
|
2015-09-28 18:32:26 +02:00
|
|
|
l_genl_family_send(nl80211, msg, device_disconnect_cb, netdev, NULL);
|
2015-02-20 12:27:58 +01:00
|
|
|
|
2015-06-23 00:02:52 +02:00
|
|
|
netdev_enter_state(netdev, NETDEV_STATE_DISCONNECTING);
|
|
|
|
|
2015-04-08 22:03:28 +02:00
|
|
|
netdev->disconnect_pending = l_dbus_message_ref(message);
|
2015-02-20 12:27:58 +01:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-02-11 23:19:55 +01:00
|
|
|
static bool device_property_get_name(struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
struct l_dbus_message_builder *builder,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct netdev *netdev = user_data;
|
|
|
|
|
|
|
|
l_dbus_message_builder_append_basic(builder, 's', netdev->name);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-09 21:44:52 +01:00
|
|
|
static bool device_property_get_connected_network(struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
struct l_dbus_message_builder *builder,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct netdev *netdev = user_data;
|
|
|
|
|
|
|
|
if (!netdev->connected_network)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
l_dbus_message_builder_append_basic(builder, 'o',
|
|
|
|
netdev->connected_network->object_path);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-23 21:32:12 +02:00
|
|
|
static void setup_device_interface(struct l_dbus_interface *interface)
|
|
|
|
{
|
2014-10-28 05:43:21 +01:00
|
|
|
l_dbus_interface_method(interface, "Scan", 0,
|
|
|
|
device_scan, "", "");
|
2014-11-03 22:37:08 +01:00
|
|
|
l_dbus_interface_method(interface, "GetNetworks", 0,
|
|
|
|
device_get_networks,
|
|
|
|
"a{oa{sv}}", "", "networks");
|
2015-02-20 12:27:58 +01:00
|
|
|
l_dbus_interface_method(interface, "Disconnect", 0,
|
|
|
|
device_disconnect, "", "");
|
2014-10-23 21:32:12 +02:00
|
|
|
|
2014-11-03 22:24:34 +01:00
|
|
|
l_dbus_interface_signal(interface, "NetworkAdded", 0,
|
|
|
|
"oa{sv}", "path", "properties");
|
|
|
|
l_dbus_interface_signal(interface, "NetworkRemoved", 0,
|
|
|
|
"o", "path");
|
2014-10-24 03:25:23 +02:00
|
|
|
|
2016-02-11 23:19:55 +01:00
|
|
|
l_dbus_interface_property(interface, "Name", 0, "s",
|
|
|
|
device_property_get_name, NULL);
|
2016-03-09 21:44:52 +01:00
|
|
|
l_dbus_interface_property(interface, "ConnectedNetwork", 0, "o",
|
|
|
|
device_property_get_connected_network,
|
|
|
|
NULL);
|
2014-10-23 21:32:12 +02:00
|
|
|
}
|
|
|
|
|
2014-10-30 04:50:27 +01:00
|
|
|
static bool bss_match(const void *a, const void *b)
|
|
|
|
{
|
2015-05-01 04:38:27 +02:00
|
|
|
const struct scan_bss *bss_a = a;
|
|
|
|
const struct scan_bss *bss_b = b;
|
2014-10-30 04:50:27 +01:00
|
|
|
|
|
|
|
return !memcmp(bss_a->addr, bss_b->addr, sizeof(bss_a->addr));
|
|
|
|
}
|
|
|
|
|
2014-08-07 05:15:20 +02:00
|
|
|
static void netdev_free(void *data)
|
|
|
|
{
|
|
|
|
struct netdev *netdev = data;
|
2014-10-23 21:32:12 +02:00
|
|
|
struct l_dbus *dbus;
|
|
|
|
|
2015-02-13 23:12:07 +01:00
|
|
|
if (netdev->scan_pending)
|
|
|
|
dbus_pending_reply(&netdev->scan_pending,
|
|
|
|
dbus_error_aborted(netdev->scan_pending));
|
|
|
|
|
2015-02-13 23:12:08 +01:00
|
|
|
if (netdev->connect_pending)
|
|
|
|
dbus_pending_reply(&netdev->connect_pending,
|
|
|
|
dbus_error_aborted(netdev->connect_pending));
|
|
|
|
|
2015-09-29 19:14:48 +02:00
|
|
|
__netdev_watch_call_removed(netdev);
|
|
|
|
|
2014-10-23 21:32:12 +02:00
|
|
|
dbus = dbus_get_bus();
|
2016-02-11 23:19:55 +01:00
|
|
|
l_dbus_unregister_object(dbus, iwd_device_get_path(netdev));
|
2014-10-23 21:32:12 +02:00
|
|
|
|
|
|
|
device_emit_removed(netdev);
|
2014-08-07 05:15:20 +02:00
|
|
|
|
|
|
|
l_debug("Freeing interface %s", netdev->name);
|
|
|
|
|
2014-11-05 15:29:33 +01:00
|
|
|
l_hashmap_destroy(netdev->networks, network_free);
|
|
|
|
|
2014-08-09 08:23:56 +02:00
|
|
|
l_queue_destroy(netdev->bss_list, bss_free);
|
2014-10-30 04:50:27 +01:00
|
|
|
l_queue_destroy(netdev->old_bss_list, bss_free);
|
2015-06-23 00:42:30 +02:00
|
|
|
l_queue_destroy(netdev->autoconnect_list, l_free);
|
2015-02-26 14:31:27 +01:00
|
|
|
l_io_destroy(netdev->eapol_io);
|
2014-10-30 05:20:43 +01:00
|
|
|
|
2015-09-20 21:58:23 +02:00
|
|
|
scan_ifindex_remove(netdev->index);
|
2015-03-27 08:54:25 +01:00
|
|
|
netdev_set_linkmode_and_operstate(netdev->index, 0, IF_OPER_DOWN,
|
|
|
|
NULL, NULL);
|
|
|
|
|
2014-08-07 05:15:20 +02:00
|
|
|
l_free(netdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool netdev_match(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const struct netdev *netdev = a;
|
|
|
|
uint32_t index = L_PTR_TO_UINT(b);
|
|
|
|
|
|
|
|
return (netdev->index == index);
|
|
|
|
}
|
|
|
|
|
2015-06-23 01:33:55 +02:00
|
|
|
static bool netdev_try_autoconnect(struct netdev *netdev,
|
|
|
|
struct network *network,
|
|
|
|
struct scan_bss *bss)
|
|
|
|
{
|
|
|
|
struct wiphy *wiphy = netdev->wiphy;
|
|
|
|
|
|
|
|
switch (network->ssid_security) {
|
|
|
|
case SCAN_SSID_SECURITY_NONE:
|
|
|
|
break;
|
|
|
|
case SCAN_SSID_SECURITY_PSK:
|
|
|
|
{
|
|
|
|
uint16_t pairwise_ciphers, group_ciphers;
|
|
|
|
const char *psk;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
bss_get_supported_ciphers(bss,
|
|
|
|
&pairwise_ciphers, &group_ciphers);
|
|
|
|
|
|
|
|
if (!wiphy_select_cipher(wiphy, pairwise_ciphers) ||
|
|
|
|
!wiphy_select_cipher(wiphy, group_ciphers)) {
|
|
|
|
l_debug("Cipher mis-match");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (network->ask_psk)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
network->settings = storage_network_open("psk", network->ssid);
|
|
|
|
psk = l_settings_get_value(network->settings, "Security",
|
|
|
|
"PreSharedKey");
|
|
|
|
|
|
|
|
/* TODO: Blacklist the network from auto-connect */
|
|
|
|
if (!psk)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
l_free(network->psk);
|
|
|
|
network->psk = l_util_from_hexstring(psk, &len);
|
|
|
|
|
|
|
|
if (network->psk && len != 32) {
|
|
|
|
l_free(network->psk);
|
|
|
|
network->psk = NULL;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2015-10-30 11:12:21 +01:00
|
|
|
case SCAN_SSID_SECURITY_8021X:
|
|
|
|
network->settings = storage_network_open("8021x",
|
|
|
|
network->ssid);
|
|
|
|
|
|
|
|
break;
|
2015-06-23 01:33:55 +02:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mlme_authenticate_cmd(network, bss);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void netdev_autoconnect_next(struct netdev *netdev)
|
|
|
|
{
|
|
|
|
struct autoconnect_entry *entry;
|
|
|
|
bool r;
|
|
|
|
|
|
|
|
while ((entry = l_queue_pop_head(netdev->autoconnect_list))) {
|
|
|
|
l_debug("Considering autoconnecting to BSS '%s' with SSID: %s,"
|
|
|
|
" freq: %u, rank: %u, strength: %i",
|
2015-10-02 19:06:20 +02:00
|
|
|
scan_bss_address_to_string(entry->bss),
|
2015-06-23 01:33:55 +02:00
|
|
|
entry->network->ssid,
|
|
|
|
entry->bss->frequency, entry->rank,
|
|
|
|
entry->bss->signal_strength);
|
|
|
|
|
|
|
|
r = netdev_try_autoconnect(netdev, entry->network, entry->bss);
|
|
|
|
l_free(entry);
|
|
|
|
|
|
|
|
if (r)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-07 05:15:20 +02:00
|
|
|
static void wiphy_free(void *data)
|
|
|
|
{
|
|
|
|
struct wiphy *wiphy = data;
|
|
|
|
|
|
|
|
l_debug("Freeing wiphy %s", wiphy->name);
|
|
|
|
|
2015-10-06 22:23:32 +02:00
|
|
|
scan_freq_set_free(wiphy->supported_freqs);
|
2014-08-07 05:15:20 +02:00
|
|
|
l_queue_destroy(wiphy->netdev_list, netdev_free);
|
|
|
|
l_free(wiphy);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool wiphy_match(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const struct wiphy *wiphy = a;
|
|
|
|
uint32_t id = L_PTR_TO_UINT(b);
|
|
|
|
|
|
|
|
return (wiphy->id == id);
|
|
|
|
}
|
|
|
|
|
2015-05-06 01:48:38 +02:00
|
|
|
static void deauthenticate_cb(struct l_genl_msg *msg,
|
2015-03-30 05:01:20 +02:00
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct netdev *netdev = user_data;
|
|
|
|
|
2015-05-06 01:48:38 +02:00
|
|
|
/* If we were inside a .Connect(), it has failed */
|
|
|
|
if (netdev->connect_pending)
|
|
|
|
dbus_pending_reply(&netdev->connect_pending,
|
2015-03-30 05:01:20 +02:00
|
|
|
dbus_error_failed(netdev->connect_pending));
|
2015-04-27 14:51:28 +02:00
|
|
|
|
|
|
|
netdev_disassociated(netdev);
|
2015-03-30 05:01:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void setting_keys_failed(struct netdev *netdev, uint16_t reason_code)
|
|
|
|
{
|
|
|
|
struct l_genl_msg *msg;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Something went wrong with our new_key, set_key, new_key,
|
|
|
|
* set_station, set_oper_state transaction
|
|
|
|
*
|
|
|
|
* Cancel all pending commands, then de-authenticate
|
|
|
|
*/
|
|
|
|
l_genl_family_cancel(nl80211, netdev->pairwise_new_key_cmd_id);
|
|
|
|
netdev->pairwise_new_key_cmd_id = 0;
|
|
|
|
|
|
|
|
l_genl_family_cancel(nl80211, netdev->pairwise_set_key_cmd_id);
|
|
|
|
netdev->pairwise_set_key_cmd_id = 0;
|
|
|
|
|
|
|
|
l_genl_family_cancel(nl80211, netdev->group_new_key_cmd_id);
|
|
|
|
netdev->group_new_key_cmd_id = 0;
|
|
|
|
|
|
|
|
eapol_cancel(netdev->index);
|
|
|
|
|
|
|
|
msg = l_genl_msg_new_sized(NL80211_CMD_DEAUTHENTICATE, 512);
|
|
|
|
msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &netdev->index);
|
|
|
|
msg_append_attr(msg, NL80211_ATTR_REASON_CODE, 2, &reason_code);
|
|
|
|
msg_append_attr(msg, NL80211_ATTR_MAC, ETH_ALEN,
|
|
|
|
netdev->connected_bss->addr);
|
2015-05-06 01:48:38 +02:00
|
|
|
l_genl_family_send(nl80211, msg, deauthenticate_cb, netdev, NULL);
|
2015-06-23 00:02:52 +02:00
|
|
|
netdev_enter_state(netdev, NETDEV_STATE_DISCONNECTING);
|
2015-03-30 05:01:20 +02:00
|
|
|
}
|
|
|
|
|
2015-03-30 05:13:49 +02:00
|
|
|
static void handshake_failed(uint32_t ifindex,
|
|
|
|
const uint8_t *aa, const uint8_t *spa,
|
|
|
|
uint16_t reason_code, void *user_data)
|
|
|
|
{
|
|
|
|
struct netdev *netdev = user_data;
|
|
|
|
struct l_genl_msg *msg;
|
|
|
|
|
|
|
|
l_error("4-Way Handshake failed for ifindex: %d", ifindex);
|
|
|
|
|
|
|
|
msg = l_genl_msg_new_sized(NL80211_CMD_DEAUTHENTICATE, 512);
|
|
|
|
msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &ifindex);
|
|
|
|
msg_append_attr(msg, NL80211_ATTR_REASON_CODE, 2, &reason_code);
|
|
|
|
msg_append_attr(msg, NL80211_ATTR_MAC, ETH_ALEN, aa);
|
2015-05-06 01:48:38 +02:00
|
|
|
l_genl_family_send(nl80211, msg, deauthenticate_cb, netdev, NULL);
|
2015-06-23 00:02:52 +02:00
|
|
|
netdev_enter_state(netdev, NETDEV_STATE_DISCONNECTING);
|
2015-03-30 05:13:49 +02:00
|
|
|
}
|
|
|
|
|
2015-03-26 04:36:06 +01:00
|
|
|
static void mlme_set_pairwise_key_cb(struct l_genl_msg *msg, void *data)
|
|
|
|
{
|
2015-03-30 04:11:19 +02:00
|
|
|
struct netdev *netdev = data;
|
|
|
|
|
|
|
|
netdev->pairwise_set_key_cmd_id = 0;
|
|
|
|
|
2015-03-30 05:01:20 +02:00
|
|
|
if (l_genl_msg_get_error(msg) < 0) {
|
|
|
|
l_error("Set Key for Pairwise Key failed for ifindex: %d",
|
|
|
|
netdev->index);
|
|
|
|
setting_keys_failed(netdev, MPDU_REASON_CODE_UNSPECIFIED);
|
2015-03-26 04:36:06 +01:00
|
|
|
return;
|
2015-03-30 05:01:20 +02:00
|
|
|
}
|
2015-03-26 04:36:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int mlme_set_pairwise_key(struct netdev *netdev)
|
|
|
|
{
|
|
|
|
uint8_t key_id = 0;
|
|
|
|
struct l_genl_msg *msg;
|
|
|
|
unsigned int id;
|
|
|
|
|
|
|
|
msg = l_genl_msg_new_sized(NL80211_CMD_SET_KEY, 512);
|
|
|
|
if (!msg)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
l_genl_msg_append_attr(msg, NL80211_ATTR_KEY_IDX, 1, &key_id);
|
|
|
|
l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &netdev->index);
|
|
|
|
|
|
|
|
l_genl_msg_append_attr(msg, NL80211_ATTR_KEY_DEFAULT, 0, NULL);
|
|
|
|
|
|
|
|
l_genl_msg_enter_nested(msg, NL80211_ATTR_KEY_DEFAULT_TYPES);
|
|
|
|
l_genl_msg_append_attr(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST, 0, NULL);
|
|
|
|
l_genl_msg_leave_nested(msg);
|
|
|
|
|
|
|
|
id = l_genl_family_send(nl80211, msg, mlme_set_pairwise_key_cb,
|
|
|
|
netdev, NULL);
|
|
|
|
if (!id)
|
|
|
|
l_genl_msg_unref(msg);
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mlme_new_pairwise_key_cb(struct l_genl_msg *msg, void *data)
|
|
|
|
{
|
2015-03-30 04:11:19 +02:00
|
|
|
struct netdev *netdev = data;
|
|
|
|
|
|
|
|
netdev->pairwise_new_key_cmd_id = 0;
|
|
|
|
|
2015-03-30 05:01:20 +02:00
|
|
|
if (l_genl_msg_get_error(msg) < 0) {
|
|
|
|
l_error("New Key for Pairwise Key failed for ifindex: %d",
|
|
|
|
netdev->index);
|
|
|
|
setting_keys_failed(netdev, MPDU_REASON_CODE_UNSPECIFIED);
|
2015-03-26 04:36:06 +01:00
|
|
|
return;
|
2015-03-30 05:01:20 +02:00
|
|
|
}
|
2015-03-26 04:36:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int mlme_new_pairwise_key(struct netdev *netdev,
|
|
|
|
uint32_t cipher,
|
|
|
|
const uint8_t *aa,
|
|
|
|
const uint8_t *tk,
|
|
|
|
size_t tk_len)
|
|
|
|
{
|
|
|
|
uint8_t key_id = 0;
|
|
|
|
struct l_genl_msg *msg;
|
|
|
|
unsigned int id;
|
|
|
|
|
|
|
|
msg = l_genl_msg_new_sized(NL80211_CMD_NEW_KEY, 512);
|
|
|
|
if (!msg)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
l_genl_msg_append_attr(msg, NL80211_ATTR_KEY_DATA, tk_len, tk);
|
|
|
|
l_genl_msg_append_attr(msg, NL80211_ATTR_KEY_CIPHER, 4, &cipher);
|
|
|
|
l_genl_msg_append_attr(msg, NL80211_ATTR_MAC, ETH_ALEN, aa);
|
|
|
|
l_genl_msg_append_attr(msg, NL80211_ATTR_KEY_IDX, 1, &key_id);
|
|
|
|
l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &netdev->index);
|
|
|
|
|
|
|
|
id = l_genl_family_send(nl80211, msg, mlme_new_pairwise_key_cb,
|
|
|
|
netdev, NULL);
|
|
|
|
if (!id)
|
|
|
|
l_genl_msg_unref(msg);
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wiphy_set_tk(uint32_t ifindex, const uint8_t *aa,
|
2015-05-22 04:10:21 +02:00
|
|
|
const uint8_t *tk, uint32_t cipher,
|
2015-03-26 04:36:06 +01:00
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct netdev *netdev = user_data;
|
2015-04-30 22:00:02 +02:00
|
|
|
struct network *network = netdev->connected_network;
|
2015-05-18 13:31:40 +02:00
|
|
|
uint8_t tk_buf[32];
|
2015-03-26 04:36:06 +01:00
|
|
|
|
|
|
|
l_debug("");
|
|
|
|
|
2015-05-22 04:10:21 +02:00
|
|
|
switch (cipher) {
|
|
|
|
case CRYPTO_CIPHER_CCMP:
|
2015-05-18 13:31:40 +02:00
|
|
|
memcpy(tk_buf, tk, 16);
|
|
|
|
break;
|
2015-05-22 04:10:21 +02:00
|
|
|
case CRYPTO_CIPHER_TKIP:
|
2015-05-18 13:31:40 +02:00
|
|
|
/*
|
|
|
|
* Swap the TX and RX MIC key portions for supplicant.
|
|
|
|
* WPA_80211_v3_1_090922 doc's 3.3.4:
|
|
|
|
* The MIC key used on the Client for transmit (TX) is in
|
|
|
|
* bytes 24-31, and the MIC key used on the Client for
|
|
|
|
* receive (RX) is in bytes 16-23 of the PTK. That is,
|
|
|
|
* assume that TX MIC and RX MIC referred to in Clause 8.7
|
|
|
|
* are referenced to the Authenticator. Similarly, on the AP,
|
|
|
|
* the MIC used for TX is in bytes 16-23, and the MIC key
|
|
|
|
* used for RX is in bytes 24-31 of the PTK.
|
|
|
|
*/
|
|
|
|
memcpy(tk_buf, tk, 16);
|
|
|
|
memcpy(tk_buf + 16, tk + 24, 8);
|
|
|
|
memcpy(tk_buf + 24, tk + 16, 8);
|
2015-03-26 04:36:06 +01:00
|
|
|
break;
|
|
|
|
default:
|
2015-05-22 04:10:21 +02:00
|
|
|
l_error("Unexpected cipher: %x", cipher);
|
2015-03-30 05:01:20 +02:00
|
|
|
setting_keys_failed(netdev,
|
|
|
|
MPDU_REASON_CODE_INVALID_PAIRWISE_CIPHER);
|
2015-03-26 04:36:06 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-27 14:51:28 +02:00
|
|
|
/* If we got here, then our PSK works. Save if required */
|
|
|
|
if (network->update_psk) {
|
|
|
|
char *hex;
|
|
|
|
|
|
|
|
network->update_psk = false;
|
|
|
|
hex = l_util_hexstring(network->psk, 32);
|
|
|
|
l_settings_set_value(network->settings, "Security",
|
|
|
|
"PreSharedKey", hex);
|
|
|
|
l_free(hex);
|
|
|
|
storage_network_sync("psk", network->ssid, network->settings);
|
|
|
|
}
|
|
|
|
|
2015-03-30 04:11:19 +02:00
|
|
|
netdev->pairwise_new_key_cmd_id =
|
|
|
|
mlme_new_pairwise_key(netdev, cipher, aa,
|
2015-05-18 13:31:40 +02:00
|
|
|
tk_buf, crypto_cipher_key_len(cipher));
|
2015-03-30 04:11:19 +02:00
|
|
|
netdev->pairwise_set_key_cmd_id = mlme_set_pairwise_key(netdev);
|
2015-03-26 04:36:06 +01:00
|
|
|
}
|
|
|
|
|
2015-03-27 08:54:25 +01:00
|
|
|
static void operstate_cb(bool result, void *user_data)
|
|
|
|
{
|
|
|
|
struct netdev *netdev = user_data;
|
|
|
|
|
|
|
|
if (!result) {
|
|
|
|
l_error("Setting LinkMode and OperState failed for ifindex %d",
|
|
|
|
netdev->index);
|
2015-03-30 05:01:20 +02:00
|
|
|
setting_keys_failed(netdev, MPDU_REASON_CODE_UNSPECIFIED);
|
2015-03-27 08:54:25 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (netdev->connect_pending) {
|
|
|
|
struct l_dbus_message *reply;
|
|
|
|
|
|
|
|
reply = l_dbus_message_new_method_return(
|
|
|
|
netdev->connect_pending);
|
|
|
|
l_dbus_message_set_arguments(reply, "");
|
|
|
|
dbus_pending_reply(&netdev->connect_pending, reply);
|
|
|
|
}
|
2015-06-23 00:02:52 +02:00
|
|
|
|
2016-02-11 23:19:44 +01:00
|
|
|
network_connected(netdev->connected_network->ssid_security,
|
|
|
|
netdev->connected_network->ssid);
|
2015-06-23 00:02:52 +02:00
|
|
|
netdev_enter_state(netdev, NETDEV_STATE_CONNECTED);
|
2015-03-27 08:54:25 +01:00
|
|
|
}
|
|
|
|
|
2015-03-27 08:54:23 +01:00
|
|
|
static void set_station_cb(struct l_genl_msg *msg, void *user_data)
|
|
|
|
{
|
|
|
|
struct netdev *netdev = user_data;
|
|
|
|
|
|
|
|
if (l_genl_msg_get_error(msg) < 0) {
|
2015-03-30 05:01:20 +02:00
|
|
|
l_error("Set Station failed for ifindex %d", netdev->index);
|
|
|
|
setting_keys_failed(netdev, MPDU_REASON_CODE_UNSPECIFIED);
|
2015-03-27 08:54:23 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-27 08:54:25 +01:00
|
|
|
netdev_set_linkmode_and_operstate(netdev->index, 1, IF_OPER_UP,
|
|
|
|
operstate_cb, netdev);
|
2015-03-27 08:54:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int set_station_cmd(struct netdev *netdev)
|
|
|
|
{
|
2015-05-01 04:38:27 +02:00
|
|
|
struct scan_bss *bss = netdev->connected_bss;
|
2015-03-27 08:54:23 +01:00
|
|
|
struct l_genl_msg *msg;
|
|
|
|
struct nl80211_sta_flag_update flags;
|
|
|
|
|
|
|
|
flags.mask = 1 << NL80211_STA_FLAG_AUTHORIZED;
|
|
|
|
flags.set = flags.mask;
|
|
|
|
|
|
|
|
msg = l_genl_msg_new_sized(NL80211_CMD_SET_STATION, 512);
|
|
|
|
msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &netdev->index);
|
|
|
|
msg_append_attr(msg, NL80211_ATTR_MAC, ETH_ALEN, bss->addr);
|
|
|
|
msg_append_attr(msg, NL80211_ATTR_STA_FLAGS2,
|
|
|
|
sizeof(struct nl80211_sta_flag_update), &flags);
|
|
|
|
l_genl_family_send(nl80211, msg, set_station_cb, netdev, NULL);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-26 05:27:37 +01:00
|
|
|
static void mlme_new_group_key_cb(struct l_genl_msg *msg, void *data)
|
|
|
|
{
|
2015-03-27 08:54:23 +01:00
|
|
|
struct netdev *netdev = data;
|
|
|
|
|
2015-03-30 04:11:19 +02:00
|
|
|
netdev->group_new_key_cmd_id = 0;
|
|
|
|
|
2015-03-27 08:54:23 +01:00
|
|
|
if (l_genl_msg_get_error(msg) < 0) {
|
2015-03-30 05:01:20 +02:00
|
|
|
l_error("New Key for Group Key failed for ifindex: %d",
|
|
|
|
netdev->index);
|
|
|
|
setting_keys_failed(netdev, MPDU_REASON_CODE_UNSPECIFIED);
|
2015-03-26 05:27:37 +01:00
|
|
|
return;
|
2015-03-27 08:54:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
set_station_cmd(netdev);
|
2015-03-26 05:27:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int mlme_new_group_key(struct netdev *netdev,
|
|
|
|
uint32_t cipher, uint8_t key_id,
|
|
|
|
const uint8_t *gtk, size_t gtk_len,
|
|
|
|
const uint8_t *rsc, size_t rsc_len)
|
|
|
|
{
|
|
|
|
struct l_genl_msg *msg;
|
|
|
|
unsigned int id;
|
|
|
|
|
|
|
|
msg = l_genl_msg_new_sized(NL80211_CMD_NEW_KEY, 512);
|
|
|
|
if (!msg)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
l_genl_msg_append_attr(msg, NL80211_ATTR_KEY_DATA, gtk_len, gtk);
|
|
|
|
l_genl_msg_append_attr(msg, NL80211_ATTR_KEY_CIPHER, 4, &cipher);
|
|
|
|
l_genl_msg_append_attr(msg, NL80211_ATTR_KEY_SEQ, rsc_len, rsc);
|
|
|
|
|
|
|
|
l_genl_msg_enter_nested(msg, NL80211_ATTR_KEY_DEFAULT_TYPES);
|
|
|
|
l_genl_msg_append_attr(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST,
|
|
|
|
0, NULL);
|
|
|
|
l_genl_msg_leave_nested(msg);
|
|
|
|
|
|
|
|
l_genl_msg_append_attr(msg, NL80211_ATTR_KEY_IDX, 1, &key_id);
|
|
|
|
l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &netdev->index);
|
|
|
|
|
|
|
|
id = l_genl_family_send(nl80211, msg, mlme_new_group_key_cb,
|
|
|
|
netdev, NULL);
|
|
|
|
if (!id)
|
|
|
|
l_genl_msg_unref(msg);
|
|
|
|
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wiphy_set_gtk(uint32_t ifindex, uint8_t key_index,
|
|
|
|
const uint8_t *gtk, uint8_t gtk_len,
|
|
|
|
const uint8_t *rsc, uint8_t rsc_len,
|
2015-05-22 04:08:47 +02:00
|
|
|
uint32_t cipher, void *user_data)
|
2015-03-26 05:27:37 +01:00
|
|
|
{
|
|
|
|
struct netdev *netdev = user_data;
|
2015-05-18 13:31:40 +02:00
|
|
|
uint8_t gtk_buf[32];
|
2015-03-26 05:27:37 +01:00
|
|
|
|
|
|
|
l_debug("");
|
|
|
|
|
2015-05-22 04:08:47 +02:00
|
|
|
switch (cipher) {
|
|
|
|
case CRYPTO_CIPHER_CCMP:
|
2015-05-18 13:31:40 +02:00
|
|
|
memcpy(gtk_buf, gtk, 16);
|
|
|
|
break;
|
2015-05-22 04:08:47 +02:00
|
|
|
case CRYPTO_CIPHER_TKIP:
|
2015-05-18 13:31:40 +02:00
|
|
|
/*
|
|
|
|
* Swap the TX and RX MIC key portions for supplicant.
|
|
|
|
* WPA_80211_v3_1_090922 doc's 3.3.4:
|
|
|
|
* The MIC key used on the Client for transmit (TX) is in
|
|
|
|
* bytes 24-31, and the MIC key used on the Client for
|
|
|
|
* receive (RX) is in bytes 16-23 of the PTK. That is,
|
|
|
|
* assume that TX MIC and RX MIC referred to in Clause 8.7
|
|
|
|
* are referenced to the Authenticator. Similarly, on the AP,
|
|
|
|
* the MIC used for TX is in bytes 16-23, and the MIC key
|
|
|
|
* used for RX is in bytes 24-31 of the PTK.
|
|
|
|
*
|
|
|
|
* Here apply this to the GTK instead of the PTK.
|
|
|
|
*/
|
|
|
|
memcpy(gtk_buf, gtk, 16);
|
|
|
|
memcpy(gtk_buf + 16, gtk + 24, 8);
|
|
|
|
memcpy(gtk_buf + 24, gtk + 16, 8);
|
2015-03-26 05:27:37 +01:00
|
|
|
break;
|
|
|
|
default:
|
2015-05-22 04:08:47 +02:00
|
|
|
l_error("Unexpected cipher: %x", cipher);
|
2015-03-30 05:01:20 +02:00
|
|
|
setting_keys_failed(netdev,
|
|
|
|
MPDU_REASON_CODE_INVALID_GROUP_CIPHER);
|
2015-03-26 05:27:37 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (crypto_cipher_key_len(cipher) != gtk_len) {
|
|
|
|
l_error("Unexpected key length: %d", gtk_len);
|
2015-03-30 05:01:20 +02:00
|
|
|
setting_keys_failed(netdev,
|
|
|
|
MPDU_REASON_CODE_INVALID_GROUP_CIPHER);
|
2015-03-26 05:27:37 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-30 04:11:19 +02:00
|
|
|
netdev->group_new_key_cmd_id =
|
|
|
|
mlme_new_group_key(netdev, cipher, key_index,
|
2015-05-18 13:31:40 +02:00
|
|
|
gtk_buf, gtk_len, rsc, rsc_len);
|
2015-03-26 05:27:37 +01:00
|
|
|
}
|
|
|
|
|
2015-02-13 23:12:08 +01:00
|
|
|
static void mlme_associate_event(struct l_genl_msg *msg, struct netdev *netdev)
|
2014-08-09 09:01:22 +02:00
|
|
|
{
|
2015-02-13 23:12:08 +01:00
|
|
|
int err;
|
2014-08-09 09:01:22 +02:00
|
|
|
|
2015-02-13 23:12:08 +01:00
|
|
|
l_debug("");
|
|
|
|
|
|
|
|
err = l_genl_msg_get_error(msg);
|
|
|
|
if (err < 0) {
|
|
|
|
l_error("association failed %s (%d)", strerror(-err), err);
|
|
|
|
dbus_pending_reply(&netdev->connect_pending,
|
|
|
|
dbus_error_failed(netdev->connect_pending));
|
2015-04-27 14:51:28 +02:00
|
|
|
netdev_disassociated(netdev);
|
2015-01-28 13:14:54 +01:00
|
|
|
return;
|
2014-08-09 09:01:22 +02:00
|
|
|
}
|
|
|
|
|
2015-02-13 23:12:08 +01:00
|
|
|
l_info("Association completed");
|
2015-03-19 14:21:44 +01:00
|
|
|
|
2015-04-30 23:03:17 +02:00
|
|
|
if (netdev->connected_network->ssid_security ==
|
|
|
|
SCAN_SSID_SECURITY_NONE)
|
2015-03-27 08:54:25 +01:00
|
|
|
netdev_set_linkmode_and_operstate(netdev->index, 1, IF_OPER_UP,
|
|
|
|
operstate_cb, netdev);
|
2015-02-13 23:12:08 +01:00
|
|
|
}
|
|
|
|
|
2015-03-03 10:27:39 +01:00
|
|
|
static void genl_associate_cb(struct l_genl_msg *msg, void *user_data)
|
|
|
|
{
|
|
|
|
struct netdev *netdev = user_data;
|
|
|
|
|
|
|
|
if (l_genl_msg_get_error(msg) < 0 && netdev->connect_pending)
|
|
|
|
dbus_pending_reply(&netdev->connect_pending,
|
|
|
|
dbus_error_failed(netdev->connect_pending));
|
|
|
|
}
|
|
|
|
|
2015-02-13 23:12:08 +01:00
|
|
|
static void mlme_associate_cmd(struct netdev *netdev)
|
|
|
|
{
|
|
|
|
struct l_genl_msg *msg;
|
2015-05-01 04:38:27 +02:00
|
|
|
struct scan_bss *bss = netdev->connected_bss;
|
2015-04-30 22:00:02 +02:00
|
|
|
struct network *network = netdev->connected_network;
|
2015-05-18 13:31:40 +02:00
|
|
|
struct wiphy *wiphy = netdev->wiphy;
|
2015-02-13 23:12:08 +01:00
|
|
|
|
|
|
|
l_debug("");
|
|
|
|
|
2014-08-09 09:01:22 +02:00
|
|
|
msg = l_genl_msg_new_sized(NL80211_CMD_ASSOCIATE, 512);
|
2014-11-11 16:03:07 +01:00
|
|
|
msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &netdev->index);
|
|
|
|
msg_append_attr(msg, NL80211_ATTR_WIPHY_FREQ, 4, &bss->frequency);
|
|
|
|
msg_append_attr(msg, NL80211_ATTR_MAC, ETH_ALEN, bss->addr);
|
2015-04-08 20:29:03 +02:00
|
|
|
msg_append_attr(msg, NL80211_ATTR_SSID, strlen(network->ssid),
|
2015-01-28 13:14:54 +01:00
|
|
|
network->ssid);
|
2015-02-26 03:56:46 +01:00
|
|
|
|
2015-10-30 11:12:21 +01:00
|
|
|
if (network->ssid_security == SCAN_SSID_SECURITY_PSK ||
|
|
|
|
network->ssid_security == SCAN_SSID_SECURITY_8021X) {
|
2015-05-18 13:31:40 +02:00
|
|
|
uint16_t pairwise_ciphers, group_ciphers;
|
|
|
|
uint32_t pairwise_cipher_attr;
|
|
|
|
uint32_t group_cipher_attr;
|
2015-02-26 03:56:46 +01:00
|
|
|
uint8_t rsne_buf[256];
|
|
|
|
struct ie_rsn_info info;
|
2015-03-20 05:53:55 +01:00
|
|
|
struct eapol_sm *sm = eapol_sm_new();
|
2015-02-26 03:56:46 +01:00
|
|
|
|
|
|
|
memset(&info, 0, sizeof(info));
|
2016-02-10 20:20:46 +01:00
|
|
|
|
|
|
|
if (network->ssid_security == SCAN_SSID_SECURITY_PSK)
|
|
|
|
info.akm_suites =
|
|
|
|
bss->sha256 ? IE_RSN_AKM_SUITE_PSK_SHA256 :
|
|
|
|
IE_RSN_AKM_SUITE_PSK;
|
|
|
|
else
|
|
|
|
info.akm_suites =
|
|
|
|
bss->sha256 ? IE_RSN_AKM_SUITE_8021X_SHA256 :
|
|
|
|
IE_RSN_AKM_SUITE_8021X;
|
2015-02-26 03:56:46 +01:00
|
|
|
|
2015-05-18 13:31:40 +02:00
|
|
|
bss_get_supported_ciphers(bss, &pairwise_ciphers,
|
|
|
|
&group_ciphers);
|
|
|
|
|
|
|
|
info.pairwise_ciphers = wiphy_select_cipher(wiphy,
|
|
|
|
pairwise_ciphers);
|
|
|
|
if (info.pairwise_ciphers == IE_RSN_CIPHER_SUITE_CCMP)
|
|
|
|
pairwise_cipher_attr = CRYPTO_CIPHER_CCMP;
|
|
|
|
else
|
|
|
|
pairwise_cipher_attr = CRYPTO_CIPHER_TKIP;
|
|
|
|
|
|
|
|
info.group_cipher = wiphy_select_cipher(wiphy, group_ciphers);
|
|
|
|
if (info.group_cipher == IE_RSN_CIPHER_SUITE_CCMP)
|
|
|
|
group_cipher_attr = CRYPTO_CIPHER_CCMP;
|
|
|
|
else
|
|
|
|
group_cipher_attr = CRYPTO_CIPHER_TKIP;
|
|
|
|
|
2015-05-06 01:48:36 +02:00
|
|
|
/* RSN takes priority */
|
|
|
|
if (bss->rsne) {
|
|
|
|
ie_build_rsne(&info, rsne_buf);
|
2015-05-22 03:43:54 +02:00
|
|
|
eapol_sm_set_ap_rsn(sm, bss->rsne, bss->rsne[1] + 2);
|
|
|
|
eapol_sm_set_own_rsn(sm, rsne_buf, rsne_buf[1] + 2);
|
2015-05-06 01:48:36 +02:00
|
|
|
} else {
|
|
|
|
ie_build_wpa(&info, rsne_buf);
|
2015-05-22 03:43:54 +02:00
|
|
|
eapol_sm_set_ap_wpa(sm, bss->wpa, bss->wpa[1] + 2);
|
|
|
|
eapol_sm_set_own_wpa(sm, rsne_buf, rsne_buf[1] + 2);
|
2015-05-06 01:48:36 +02:00
|
|
|
}
|
2015-02-26 03:56:46 +01:00
|
|
|
|
2015-10-30 11:12:21 +01:00
|
|
|
if (network->ssid_security == SCAN_SSID_SECURITY_PSK)
|
|
|
|
eapol_sm_set_pmk(sm, network->psk);
|
|
|
|
else
|
|
|
|
eapol_sm_set_8021x_config(sm, network->settings);
|
|
|
|
|
2015-03-20 05:53:55 +01:00
|
|
|
eapol_sm_set_authenticator_address(sm, bss->addr);
|
|
|
|
eapol_sm_set_supplicant_address(sm, netdev->addr);
|
2015-03-26 05:27:45 +01:00
|
|
|
eapol_sm_set_user_data(sm, netdev);
|
2015-10-30 11:12:19 +01:00
|
|
|
eapol_sm_set_tx_user_data(sm,
|
|
|
|
L_INT_TO_PTR(l_io_get_fd(netdev->eapol_io)));
|
2015-03-20 05:53:55 +01:00
|
|
|
eapol_start(netdev->index, sm);
|
|
|
|
|
2015-02-26 03:56:46 +01:00
|
|
|
msg_append_attr(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE,
|
2015-05-18 13:31:40 +02:00
|
|
|
4, &pairwise_cipher_attr);
|
2015-02-26 03:56:46 +01:00
|
|
|
msg_append_attr(msg, NL80211_ATTR_CIPHER_SUITE_GROUP,
|
2015-05-18 13:31:40 +02:00
|
|
|
4, &group_cipher_attr);
|
|
|
|
|
2015-02-26 03:56:46 +01:00
|
|
|
msg_append_attr(msg, NL80211_ATTR_CONTROL_PORT, 0, NULL);
|
|
|
|
msg_append_attr(msg, NL80211_ATTR_IE,
|
|
|
|
rsne_buf[1] + 2, rsne_buf);
|
|
|
|
}
|
|
|
|
|
2015-03-03 10:27:39 +01:00
|
|
|
l_genl_family_send(nl80211, msg, genl_associate_cb, netdev, NULL);
|
2014-08-09 09:01:22 +02:00
|
|
|
}
|
|
|
|
|
2015-02-13 23:12:08 +01:00
|
|
|
static void mlme_authenticate_event(struct l_genl_msg *msg,
|
|
|
|
struct netdev *netdev)
|
|
|
|
{
|
|
|
|
struct l_genl_attr attr;
|
|
|
|
uint16_t type, len;
|
|
|
|
const void *data;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
l_debug("");
|
|
|
|
|
|
|
|
err = l_genl_msg_get_error(msg);
|
|
|
|
if (err < 0) {
|
|
|
|
l_error("authentication failed %s (%d)", strerror(-err), err);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!l_genl_attr_init(&attr, msg)) {
|
|
|
|
l_debug("attr init failed");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (l_genl_attr_next(&attr, &type, &len, &data)) {
|
|
|
|
switch (type) {
|
|
|
|
case NL80211_ATTR_TIMED_OUT:
|
|
|
|
l_warn("authentication timed out");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
l_info("Authentication completed");
|
|
|
|
mlme_associate_cmd(netdev);
|
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
2015-06-23 01:33:38 +02:00
|
|
|
if (netdev->connect_pending)
|
|
|
|
dbus_pending_reply(&netdev->connect_pending,
|
2015-02-13 23:12:08 +01:00
|
|
|
dbus_error_failed(netdev->connect_pending));
|
2015-06-23 01:33:38 +02:00
|
|
|
|
2015-04-27 14:51:28 +02:00
|
|
|
netdev_disassociated(netdev);
|
2015-02-13 23:12:08 +01:00
|
|
|
}
|
|
|
|
|
2015-02-20 12:27:58 +01:00
|
|
|
static void mlme_deauthenticate_event(struct l_genl_msg *msg,
|
|
|
|
struct netdev *netdev)
|
2015-04-08 22:04:22 +02:00
|
|
|
{
|
|
|
|
l_debug("");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mlme_disconnect_event(struct l_genl_msg *msg,
|
|
|
|
struct netdev *netdev)
|
2015-02-20 12:27:58 +01:00
|
|
|
{
|
|
|
|
struct l_genl_attr attr;
|
|
|
|
uint16_t type, len;
|
|
|
|
const void *data;
|
2015-04-08 22:04:22 +02:00
|
|
|
uint16_t reason_code = 0;
|
|
|
|
bool disconnect_by_ap = false;
|
2015-02-20 12:27:58 +01:00
|
|
|
|
|
|
|
l_debug("");
|
|
|
|
|
|
|
|
if (!l_genl_attr_init(&attr, msg)) {
|
2015-04-08 22:04:22 +02:00
|
|
|
l_error("attr init failed");
|
|
|
|
return;
|
2015-02-20 12:27:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
while (l_genl_attr_next(&attr, &type, &len, &data)) {
|
|
|
|
switch (type) {
|
2015-04-08 22:04:22 +02:00
|
|
|
case NL80211_ATTR_REASON_CODE:
|
|
|
|
if (len != sizeof(uint16_t))
|
|
|
|
l_warn("Invalid reason code attribute");
|
|
|
|
else
|
|
|
|
reason_code = *((uint16_t *) data);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NL80211_ATTR_DISCONNECTED_BY_AP:
|
|
|
|
disconnect_by_ap = true;
|
|
|
|
break;
|
2015-02-20 12:27:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-08 22:04:22 +02:00
|
|
|
l_info("Received Deauthentication event, reason: %hu, from_ap: %s",
|
|
|
|
reason_code, disconnect_by_ap ? "true" : "false");
|
2015-02-25 15:11:33 +01:00
|
|
|
|
2015-04-08 22:04:22 +02:00
|
|
|
if (!disconnect_by_ap)
|
2015-02-25 15:11:33 +01:00
|
|
|
return;
|
|
|
|
|
2015-04-08 22:04:22 +02:00
|
|
|
if (netdev->connect_pending) {
|
2015-04-30 22:00:02 +02:00
|
|
|
struct network *network = netdev->connected_network;
|
2015-02-20 12:27:58 +01:00
|
|
|
|
2015-04-08 22:04:22 +02:00
|
|
|
dbus_pending_reply(&netdev->connect_pending,
|
2015-02-20 12:27:58 +01:00
|
|
|
dbus_error_failed(netdev->connect_pending));
|
2015-04-08 22:07:02 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Connection failed, if PSK try asking for the passphrase
|
|
|
|
* once more
|
|
|
|
*/
|
|
|
|
if (network->ssid_security == SCAN_SSID_SECURITY_PSK) {
|
2015-04-27 14:51:28 +02:00
|
|
|
network->update_psk = false;
|
|
|
|
network->ask_psk = true;
|
2015-04-08 22:07:02 +02:00
|
|
|
}
|
2015-04-08 22:04:22 +02:00
|
|
|
}
|
|
|
|
|
2015-04-27 14:51:28 +02:00
|
|
|
netdev_disassociated(netdev);
|
2015-02-20 12:27:58 +01:00
|
|
|
}
|
|
|
|
|
2015-05-01 01:42:44 +02:00
|
|
|
static void mlme_cqm_event(struct l_genl_msg *msg, struct netdev *netdev)
|
|
|
|
{
|
|
|
|
struct l_genl_attr attr;
|
|
|
|
struct l_genl_attr nested;
|
|
|
|
uint16_t type, len;
|
|
|
|
const void *data;
|
|
|
|
|
|
|
|
l_debug("");
|
|
|
|
|
|
|
|
if (!l_genl_attr_init(&attr, msg))
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (l_genl_attr_next(&attr, &type, &len, &data)) {
|
|
|
|
switch (type) {
|
|
|
|
case NL80211_ATTR_CQM:
|
|
|
|
if (!l_genl_attr_recurse(&attr, &nested))
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (l_genl_attr_next(&nested, &type, &len, &data)) {
|
|
|
|
switch (type) {
|
|
|
|
case NL80211_ATTR_CQM_BEACON_LOSS_EVENT:
|
|
|
|
netdev_lost_beacon(netdev);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-01 16:17:54 +02:00
|
|
|
static void network_reset_bss_list(const void *key, void *value,
|
|
|
|
void *user_data)
|
2014-08-09 08:23:56 +02:00
|
|
|
{
|
2015-05-01 16:17:54 +02:00
|
|
|
struct network *network = value;
|
|
|
|
|
|
|
|
l_queue_destroy(network->bss_list, NULL);
|
|
|
|
network->bss_list = l_queue_new();
|
|
|
|
}
|
|
|
|
|
2015-06-01 16:28:05 +02:00
|
|
|
static bool network_remove_if_lost(const void *key, void *data, void *user_data)
|
|
|
|
{
|
|
|
|
struct network *network = data;
|
|
|
|
|
|
|
|
if (!l_queue_isempty(network->bss_list))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
l_debug("No remaining BSSs for SSID: %s -- Removing network",
|
|
|
|
network->ssid);
|
|
|
|
network_free(network);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-23 00:42:30 +02:00
|
|
|
static int autoconnect_rank_compare(const void *a, const void *b, void *user)
|
|
|
|
{
|
|
|
|
const struct autoconnect_entry *new_ae = a;
|
|
|
|
const struct autoconnect_entry *ae = b;
|
|
|
|
|
|
|
|
return ae->rank - new_ae->rank;
|
|
|
|
}
|
|
|
|
|
2015-06-01 16:28:05 +02:00
|
|
|
static void process_bss(struct netdev *netdev, struct scan_bss *bss)
|
2015-05-01 16:17:54 +02:00
|
|
|
{
|
2015-02-26 17:03:51 +01:00
|
|
|
struct network *network;
|
2015-01-28 13:14:54 +01:00
|
|
|
enum scan_ssid_security ssid_security;
|
2015-03-10 12:20:43 +01:00
|
|
|
const char *path;
|
2015-06-23 00:42:30 +02:00
|
|
|
double rankmod;
|
|
|
|
struct autoconnect_entry *entry;
|
2014-10-28 17:04:31 +01:00
|
|
|
|
2015-06-16 21:03:25 +02:00
|
|
|
l_debug("Found BSS '%s' with SSID: %s, freq: %u, rank: %u, "
|
2015-06-01 16:28:05 +02:00
|
|
|
"strength: %i",
|
2015-10-02 19:06:20 +02:00
|
|
|
scan_bss_address_to_string(bss),
|
2015-06-01 16:28:05 +02:00
|
|
|
util_ssid_to_utf8(bss->ssid_len, bss->ssid),
|
2015-06-16 21:03:25 +02:00
|
|
|
bss->frequency, bss->rank, bss->signal_strength);
|
2014-08-09 08:23:56 +02:00
|
|
|
|
2015-06-01 16:28:05 +02:00
|
|
|
if (!util_ssid_is_utf8(bss->ssid_len, bss->ssid)) {
|
|
|
|
l_warn("Ignoring BSS with non-UTF8 SSID");
|
2015-05-01 16:17:54 +02:00
|
|
|
return;
|
2015-04-08 20:29:03 +02:00
|
|
|
}
|
|
|
|
|
2015-05-06 01:48:36 +02:00
|
|
|
/*
|
|
|
|
* If both an RSN and a WPA elements are present currently
|
|
|
|
* RSN takes priority and the WPA IE is ignored.
|
|
|
|
*/
|
2015-02-26 04:13:24 +01:00
|
|
|
if (bss->rsne) {
|
|
|
|
struct ie_rsn_info rsne;
|
|
|
|
int res = ie_parse_rsne_from_data(bss->rsne, bss->rsne[1] + 2,
|
|
|
|
&rsne);
|
|
|
|
if (res < 0) {
|
|
|
|
l_debug("Cannot parse RSN field (%d, %s)",
|
|
|
|
res, strerror(-res));
|
2015-06-01 16:28:05 +02:00
|
|
|
return;
|
2015-02-26 04:13:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ssid_security = scan_get_ssid_security(bss->capability, &rsne);
|
2016-02-10 19:56:11 +01:00
|
|
|
|
|
|
|
if (ssid_security == SCAN_SSID_SECURITY_PSK)
|
|
|
|
bss->sha256 =
|
|
|
|
rsne.akm_suites & IE_RSN_AKM_SUITE_PSK_SHA256;
|
|
|
|
else if (ssid_security == SCAN_SSID_SECURITY_8021X)
|
|
|
|
bss->sha256 =
|
|
|
|
rsne.akm_suites & IE_RSN_AKM_SUITE_8021X_SHA256;
|
2015-03-16 12:03:03 +01:00
|
|
|
} else if (bss->wpa) {
|
|
|
|
struct ie_rsn_info wpa;
|
|
|
|
int res = ie_parse_wpa_from_data(bss->wpa, bss->wpa[1] + 2,
|
|
|
|
&wpa);
|
|
|
|
if (res < 0) {
|
2015-06-01 16:28:05 +02:00
|
|
|
l_debug("Cannot parse WPA IE (%d, %s)",
|
2015-03-16 12:03:03 +01:00
|
|
|
res, strerror(-res));
|
2015-06-01 16:28:05 +02:00
|
|
|
return;
|
2015-03-16 12:03:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ssid_security = scan_get_ssid_security(bss->capability, &wpa);
|
2015-02-26 04:13:24 +01:00
|
|
|
} else
|
|
|
|
ssid_security = scan_get_ssid_security(bss->capability, NULL);
|
2015-02-25 06:11:48 +01:00
|
|
|
|
2015-06-01 16:28:05 +02:00
|
|
|
path = iwd_network_get_path(netdev, bss->ssid, bss->ssid_len,
|
|
|
|
ssid_security);
|
2014-10-30 06:01:52 +01:00
|
|
|
|
2015-03-10 12:20:43 +01:00
|
|
|
network = l_hashmap_lookup(netdev->networks, path);
|
2015-01-28 22:37:25 +01:00
|
|
|
if (!network) {
|
|
|
|
network = l_new(struct network, 1);
|
|
|
|
network->netdev = netdev;
|
2015-06-01 16:28:05 +02:00
|
|
|
memcpy(network->ssid, bss->ssid, bss->ssid_len);
|
2015-01-28 22:37:25 +01:00
|
|
|
network->ssid_security = ssid_security;
|
|
|
|
network->bss_list = l_queue_new();
|
2015-03-10 12:20:43 +01:00
|
|
|
network->object_path = strdup(path);
|
|
|
|
l_hashmap_insert(netdev->networks,
|
|
|
|
network->object_path, network);
|
2015-01-28 22:37:25 +01:00
|
|
|
|
2015-06-01 16:28:05 +02:00
|
|
|
l_debug("Added new Network \"%s\" security %s", network->ssid,
|
2016-02-10 00:08:03 +01:00
|
|
|
scan_ssid_security_to_str(ssid_security));
|
2015-04-08 20:29:03 +02:00
|
|
|
|
2016-02-11 23:19:55 +01:00
|
|
|
if (!l_dbus_object_add_interface(dbus_get_bus(),
|
2015-03-10 12:20:43 +01:00
|
|
|
network->object_path,
|
2016-02-11 23:19:55 +01:00
|
|
|
IWD_NETWORK_INTERFACE, network))
|
2015-01-28 22:37:25 +01:00
|
|
|
l_info("Unable to register %s interface",
|
|
|
|
IWD_NETWORK_INTERFACE);
|
|
|
|
else
|
|
|
|
network_emit_added(network);
|
2015-06-23 00:42:30 +02:00
|
|
|
|
|
|
|
network_seen(network->ssid_security, network->ssid);
|
2015-01-28 22:37:25 +01:00
|
|
|
}
|
2014-10-30 05:20:43 +01:00
|
|
|
|
2015-06-16 21:03:09 +02:00
|
|
|
l_queue_insert(network->bss_list, bss, scan_bss_rank_compare, NULL);
|
2015-06-23 00:42:30 +02:00
|
|
|
|
|
|
|
rankmod = network_rankmod(network->ssid_security, network->ssid);
|
|
|
|
if (rankmod == 0.0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
entry = l_new(struct autoconnect_entry, 1);
|
|
|
|
entry->network = network;
|
|
|
|
entry->bss = bss;
|
|
|
|
entry->rank = bss->rank * rankmod;
|
|
|
|
l_queue_insert(netdev->autoconnect_list, entry,
|
|
|
|
autoconnect_rank_compare, NULL);
|
2014-08-09 07:21:30 +02:00
|
|
|
}
|
|
|
|
|
2015-06-01 16:28:05 +02:00
|
|
|
static bool new_scan_results(uint32_t wiphy_id, uint32_t ifindex,
|
2015-09-20 21:58:23 +02:00
|
|
|
struct l_queue *bss_list, void *userdata)
|
2015-01-28 13:14:55 +01:00
|
|
|
{
|
2015-09-20 21:58:23 +02:00
|
|
|
struct netdev *netdev = userdata;
|
2015-06-01 16:28:05 +02:00
|
|
|
const struct l_queue_entry *bss_entry;
|
2015-01-28 13:14:55 +01:00
|
|
|
|
2015-06-01 16:28:05 +02:00
|
|
|
netdev->old_bss_list = netdev->bss_list;
|
|
|
|
netdev->bss_list = bss_list;
|
|
|
|
l_hashmap_foreach(netdev->networks, network_reset_bss_list, NULL);
|
2015-01-28 13:14:55 +01:00
|
|
|
|
2015-06-23 00:42:30 +02:00
|
|
|
l_queue_destroy(netdev->autoconnect_list, l_free);
|
|
|
|
netdev->autoconnect_list = l_queue_new();
|
|
|
|
|
2015-06-01 16:28:05 +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;
|
2014-08-09 07:21:30 +02:00
|
|
|
|
2015-06-01 16:28:05 +02:00
|
|
|
process_bss(netdev, bss);
|
|
|
|
}
|
2014-10-30 04:50:27 +01:00
|
|
|
|
2015-04-30 23:03:17 +02:00
|
|
|
if (netdev->connected_bss) {
|
2015-05-01 04:38:27 +02:00
|
|
|
struct scan_bss *bss;
|
2015-04-30 23:03:17 +02:00
|
|
|
|
|
|
|
bss = l_queue_find(netdev->bss_list, bss_match,
|
|
|
|
netdev->connected_bss);
|
|
|
|
|
|
|
|
if (!bss) {
|
|
|
|
l_warn("Connected BSS not in scan results!");
|
|
|
|
l_queue_push_tail(netdev->bss_list,
|
|
|
|
netdev->connected_bss);
|
|
|
|
l_queue_push_tail(netdev->connected_network->bss_list,
|
|
|
|
netdev->connected_bss);
|
|
|
|
l_queue_remove(netdev->old_bss_list,
|
|
|
|
netdev->connected_bss);
|
|
|
|
} else
|
|
|
|
netdev->connected_bss = bss;
|
|
|
|
}
|
2015-01-29 04:10:35 +01:00
|
|
|
|
2015-04-30 21:41:22 +02:00
|
|
|
l_hashmap_foreach_remove(netdev->networks,
|
|
|
|
network_remove_if_lost, NULL);
|
2015-04-30 23:03:17 +02:00
|
|
|
|
2014-10-30 04:50:27 +01:00
|
|
|
l_queue_destroy(netdev->old_bss_list, bss_free);
|
|
|
|
netdev->old_bss_list = NULL;
|
2015-06-01 16:28:05 +02:00
|
|
|
|
2015-06-23 01:33:55 +02:00
|
|
|
if (netdev->state == NETDEV_STATE_AUTOCONNECT)
|
|
|
|
netdev_autoconnect_next(netdev);
|
|
|
|
|
2015-06-01 16:28:05 +02:00
|
|
|
return true;
|
2014-10-28 17:14:40 +01:00
|
|
|
}
|
2014-08-09 07:21:30 +02:00
|
|
|
|
2014-08-07 06:27:32 +02:00
|
|
|
static void interface_dump_callback(struct l_genl_msg *msg, void *user_data)
|
2014-08-07 05:15:20 +02:00
|
|
|
{
|
2014-08-07 06:27:32 +02:00
|
|
|
struct wiphy *wiphy = NULL;
|
2014-08-07 05:15:20 +02:00
|
|
|
struct netdev *netdev;
|
|
|
|
struct l_genl_attr attr;
|
|
|
|
uint16_t type, len;
|
|
|
|
const void *data;
|
|
|
|
char ifname[IFNAMSIZ];
|
|
|
|
uint8_t ifaddr[ETH_ALEN];
|
|
|
|
uint32_t ifindex, iftype;
|
|
|
|
|
|
|
|
if (!l_genl_attr_init(&attr, msg))
|
|
|
|
return;
|
|
|
|
|
|
|
|
memset(ifname, 0, sizeof(ifname));
|
|
|
|
memset(ifaddr, 0, sizeof(ifaddr));
|
|
|
|
iftype = NL80211_IFTYPE_UNSPECIFIED;
|
|
|
|
ifindex = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The interface index and interface name attributes are normally
|
|
|
|
* listed before the wiphy attribute. This handling assumes that
|
|
|
|
* all attributes are included in the same message.
|
|
|
|
*
|
|
|
|
* If any required attribute is missing, the whole message will
|
|
|
|
* be ignored.
|
|
|
|
*/
|
|
|
|
while (l_genl_attr_next(&attr, &type, &len, &data)) {
|
|
|
|
switch (type) {
|
|
|
|
case NL80211_ATTR_IFINDEX:
|
|
|
|
if (len != sizeof(uint32_t)) {
|
|
|
|
l_warn("Invalid interface index attribute");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ifindex = *((uint32_t *) data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NL80211_ATTR_IFNAME:
|
|
|
|
if (len > sizeof(ifname)) {
|
|
|
|
l_warn("Invalid interface name attribute");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(ifname, data, len);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NL80211_ATTR_WIPHY:
|
|
|
|
if (len != sizeof(uint32_t)) {
|
|
|
|
l_warn("Invalid wiphy attribute");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-07 06:27:32 +02:00
|
|
|
wiphy = l_queue_find(wiphy_list, wiphy_match,
|
|
|
|
L_UINT_TO_PTR(*((uint32_t *) data)));
|
2014-08-07 05:15:20 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NL80211_ATTR_IFTYPE:
|
|
|
|
if (len != sizeof(uint32_t)) {
|
|
|
|
l_warn("Invalid interface type attribute");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
iftype = *((uint32_t *) data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NL80211_ATTR_MAC:
|
|
|
|
if (len != sizeof(ifaddr)) {
|
|
|
|
l_warn("Invalid interface address attribute");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(ifaddr, data, len);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-18 13:31:40 +02:00
|
|
|
if (!wiphy) {
|
|
|
|
l_warn("Missing wiphy attribute or wiphy not found");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-07 05:15:20 +02:00
|
|
|
if (!ifindex) {
|
|
|
|
l_warn("Missing interface index attribute");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
netdev = l_queue_find(wiphy->netdev_list, netdev_match,
|
|
|
|
L_UINT_TO_PTR(ifindex));
|
|
|
|
if (!netdev) {
|
2014-10-23 21:32:12 +02:00
|
|
|
struct l_dbus *dbus = dbus_get_bus();
|
|
|
|
|
2014-08-07 05:15:20 +02:00
|
|
|
netdev = l_new(struct netdev, 1);
|
2014-08-09 08:23:56 +02:00
|
|
|
netdev->bss_list = l_queue_new();
|
2015-03-10 12:20:43 +01:00
|
|
|
netdev->networks = l_hashmap_new();
|
|
|
|
l_hashmap_set_hash_function(netdev->networks, l_str_hash);
|
|
|
|
l_hashmap_set_compare_function(netdev->networks,
|
|
|
|
(l_hashmap_compare_func_t) strcmp);
|
2014-10-24 05:44:59 +02:00
|
|
|
memcpy(netdev->name, ifname, sizeof(netdev->name));
|
|
|
|
memcpy(netdev->addr, ifaddr, sizeof(netdev->addr));
|
|
|
|
netdev->index = ifindex;
|
|
|
|
netdev->type = iftype;
|
2015-05-18 13:31:40 +02:00
|
|
|
netdev->wiphy = wiphy;
|
2014-10-24 05:44:59 +02:00
|
|
|
|
2014-08-07 08:51:25 +02:00
|
|
|
l_queue_push_head(wiphy->netdev_list, netdev);
|
2014-10-23 21:32:12 +02:00
|
|
|
|
2016-02-11 23:19:55 +01:00
|
|
|
if (!l_dbus_object_add_interface(dbus,
|
2014-10-24 05:44:59 +02:00
|
|
|
iwd_device_get_path(netdev),
|
2016-02-11 23:19:55 +01:00
|
|
|
IWD_DEVICE_INTERFACE, netdev))
|
2014-10-23 21:32:12 +02:00
|
|
|
l_info("Unable to register %s interface",
|
|
|
|
IWD_DEVICE_INTERFACE);
|
2015-09-29 19:14:48 +02:00
|
|
|
else {
|
|
|
|
__netdev_watch_call_added(netdev);
|
2014-10-23 21:32:12 +02:00
|
|
|
device_emit_added(netdev);
|
2015-09-29 19:14:48 +02:00
|
|
|
}
|
2015-03-27 08:54:25 +01:00
|
|
|
|
|
|
|
netdev_set_linkmode_and_operstate(netdev->index, 1,
|
|
|
|
IF_OPER_DORMANT, NULL, NULL);
|
2015-06-23 00:02:52 +02:00
|
|
|
|
2015-09-20 21:58:23 +02:00
|
|
|
scan_ifindex_add(netdev->index);
|
2015-06-23 00:02:52 +02:00
|
|
|
netdev_enter_state(netdev, NETDEV_STATE_AUTOCONNECT);
|
2014-08-07 05:15:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
l_debug("Found interface %s", netdev->name);
|
2015-02-26 14:31:27 +01:00
|
|
|
|
|
|
|
netdev->eapol_io = eapol_open_pae(netdev->index);
|
2015-03-20 03:54:28 +01:00
|
|
|
if (!netdev->eapol_io) {
|
2015-02-26 14:31:27 +01:00
|
|
|
l_error("Failed to open PAE socket");
|
2015-03-20 03:54:28 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-02-26 14:31:27 +01:00
|
|
|
|
2015-03-20 03:54:28 +01:00
|
|
|
l_io_set_read_handler(netdev->eapol_io, eapol_read, netdev, NULL);
|
2014-08-07 05:15:20 +02:00
|
|
|
}
|
|
|
|
|
2014-11-05 16:18:28 +01:00
|
|
|
static void parse_supported_commands(struct wiphy *wiphy,
|
|
|
|
struct l_genl_attr *attr)
|
|
|
|
{
|
|
|
|
uint16_t type, len;
|
|
|
|
const void *data;
|
|
|
|
|
|
|
|
while (l_genl_attr_next(attr, &type, &len, &data)) {
|
|
|
|
uint32_t cmd = *(uint32_t *)data;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case NL80211_CMD_START_SCHED_SCAN:
|
|
|
|
wiphy->support_scheduled_scan = true;
|
|
|
|
break;
|
2015-05-06 22:24:14 +02:00
|
|
|
case NL80211_CMD_SET_REKEY_OFFLOAD:
|
|
|
|
wiphy->support_rekey_offload = true;
|
2014-11-05 16:18:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-17 20:02:32 +02:00
|
|
|
static void parse_supported_ciphers(struct wiphy *wiphy, const void *data,
|
|
|
|
uint16_t len)
|
|
|
|
{
|
|
|
|
bool s;
|
|
|
|
|
|
|
|
while (len >= 4) {
|
|
|
|
uint32_t cipher = *(uint32_t *)data;
|
|
|
|
|
|
|
|
switch (cipher) {
|
|
|
|
case CRYPTO_CIPHER_CCMP:
|
|
|
|
wiphy->pairwise_ciphers |= IE_RSN_CIPHER_SUITE_CCMP;
|
|
|
|
break;
|
|
|
|
case CRYPTO_CIPHER_TKIP:
|
|
|
|
wiphy->pairwise_ciphers |= IE_RSN_CIPHER_SUITE_TKIP;
|
|
|
|
break;
|
|
|
|
case CRYPTO_CIPHER_WEP40:
|
|
|
|
wiphy->pairwise_ciphers |= IE_RSN_CIPHER_SUITE_WEP40;
|
|
|
|
break;
|
|
|
|
case CRYPTO_CIPHER_WEP104:
|
|
|
|
wiphy->pairwise_ciphers |= IE_RSN_CIPHER_SUITE_WEP104;
|
|
|
|
break;
|
|
|
|
case CRYPTO_CIPHER_BIP:
|
|
|
|
wiphy->pairwise_ciphers |= IE_RSN_CIPHER_SUITE_BIP;
|
|
|
|
break;
|
|
|
|
default: /* TODO: Support other ciphers */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
len -= 4;
|
|
|
|
data += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
s = wiphy->pairwise_ciphers & IE_RSN_CIPHER_SUITE_CCMP;
|
|
|
|
l_info("Wiphy supports CCMP: %s", s ? "true" : "false");
|
|
|
|
|
|
|
|
s = wiphy->pairwise_ciphers & IE_RSN_CIPHER_SUITE_TKIP;
|
|
|
|
l_info("Wiphy supports TKIP: %s", s ? "true" : "false");
|
|
|
|
}
|
|
|
|
|
2015-10-06 22:23:32 +02:00
|
|
|
static void parse_supported_frequencies(struct wiphy *wiphy,
|
|
|
|
struct l_genl_attr *freqs)
|
|
|
|
{
|
|
|
|
uint16_t type, len;
|
|
|
|
const void *data;
|
|
|
|
struct l_genl_attr attr;
|
|
|
|
|
|
|
|
l_debug("");
|
|
|
|
|
|
|
|
while (l_genl_attr_next(freqs, NULL, NULL, NULL)) {
|
|
|
|
if (!l_genl_attr_recurse(freqs, &attr))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
while (l_genl_attr_next(&attr, &type, &len, &data)) {
|
|
|
|
uint32_t u32;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case NL80211_FREQUENCY_ATTR_FREQ:
|
|
|
|
u32 = *((uint32_t *) data);
|
|
|
|
scan_freq_set_add(wiphy->supported_freqs, u32);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void parse_supported_bands(struct wiphy *wiphy,
|
|
|
|
struct l_genl_attr *bands)
|
|
|
|
{
|
|
|
|
uint16_t type, len;
|
|
|
|
const void *data;
|
|
|
|
struct l_genl_attr attr;
|
|
|
|
|
|
|
|
l_debug("");
|
|
|
|
|
|
|
|
while (l_genl_attr_next(bands, NULL, NULL, NULL)) {
|
|
|
|
if (!l_genl_attr_recurse(bands, &attr))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
while (l_genl_attr_next(&attr, &type, &len, &data)) {
|
|
|
|
struct l_genl_attr freqs;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case NL80211_BAND_ATTR_FREQS:
|
|
|
|
if (!l_genl_attr_recurse(&attr, &freqs))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
parse_supported_frequencies(wiphy, &freqs);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define FAIL_NO_WIPHY() \
|
|
|
|
if (!wiphy) { \
|
|
|
|
l_warn("No wiphy structure found"); \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
|
2014-08-07 05:15:20 +02:00
|
|
|
static void wiphy_dump_callback(struct l_genl_msg *msg, void *user_data)
|
|
|
|
{
|
|
|
|
struct wiphy *wiphy = NULL;
|
2014-11-05 16:18:28 +01:00
|
|
|
struct l_genl_attr attr, nested;
|
2014-08-07 05:15:20 +02:00
|
|
|
uint16_t type, len;
|
|
|
|
const void *data;
|
|
|
|
uint32_t id;
|
|
|
|
|
|
|
|
if (!l_genl_attr_init(&attr, msg))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The wiphy attribute is always the first attribute in the
|
|
|
|
* list. If not then error out with a warning and ignore the
|
|
|
|
* whole message.
|
|
|
|
*
|
|
|
|
* In most cases multiple of these message will be send
|
|
|
|
* since the information included can not fit into a single
|
|
|
|
* message.
|
|
|
|
*/
|
|
|
|
while (l_genl_attr_next(&attr, &type, &len, &data)) {
|
|
|
|
switch (type) {
|
|
|
|
case NL80211_ATTR_WIPHY:
|
|
|
|
if (wiphy) {
|
|
|
|
l_warn("Duplicate wiphy attribute");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len != sizeof(uint32_t)) {
|
|
|
|
l_warn("Invalid wiphy attribute");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
id = *((uint32_t *) data);
|
|
|
|
|
|
|
|
wiphy = l_queue_find(wiphy_list, wiphy_match,
|
|
|
|
L_UINT_TO_PTR(id));
|
|
|
|
if (!wiphy) {
|
|
|
|
wiphy = l_new(struct wiphy, 1);
|
|
|
|
wiphy->id = id;
|
|
|
|
wiphy->netdev_list = l_queue_new();
|
2015-10-06 22:23:32 +02:00
|
|
|
wiphy->supported_freqs = scan_freq_set_new();
|
2014-08-07 06:27:32 +02:00
|
|
|
l_queue_push_head(wiphy_list, wiphy);
|
2014-08-07 05:15:20 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NL80211_ATTR_WIPHY_NAME:
|
2015-10-06 22:23:32 +02:00
|
|
|
FAIL_NO_WIPHY();
|
2014-08-07 05:15:20 +02:00
|
|
|
|
|
|
|
if (len > sizeof(wiphy->name)) {
|
|
|
|
l_warn("Invalid wiphy name attribute");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(wiphy->name, data, len);
|
|
|
|
break;
|
2014-08-08 00:41:30 +02:00
|
|
|
|
|
|
|
case NL80211_ATTR_FEATURE_FLAGS:
|
2015-10-06 22:23:32 +02:00
|
|
|
FAIL_NO_WIPHY();
|
2014-08-08 00:41:30 +02:00
|
|
|
|
|
|
|
if (len != sizeof(uint32_t)) {
|
|
|
|
l_warn("Invalid feature flags attribute");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wiphy->feature_flags = *((uint32_t *) data);
|
|
|
|
break;
|
2014-11-05 16:18:28 +01:00
|
|
|
case NL80211_ATTR_SUPPORTED_COMMANDS:
|
2015-10-06 22:23:32 +02:00
|
|
|
FAIL_NO_WIPHY();
|
2014-11-05 16:18:28 +01:00
|
|
|
|
|
|
|
if (!l_genl_attr_recurse(&attr, &nested))
|
|
|
|
return;
|
|
|
|
|
|
|
|
parse_supported_commands(wiphy, &nested);
|
|
|
|
break;
|
2015-04-17 20:02:32 +02:00
|
|
|
case NL80211_ATTR_CIPHER_SUITES:
|
2015-10-06 22:23:32 +02:00
|
|
|
FAIL_NO_WIPHY();
|
2015-04-17 20:02:32 +02:00
|
|
|
|
|
|
|
parse_supported_ciphers(wiphy, data, len);
|
|
|
|
break;
|
2015-10-06 22:23:32 +02:00
|
|
|
case NL80211_ATTR_WIPHY_BANDS:
|
|
|
|
FAIL_NO_WIPHY();
|
|
|
|
|
|
|
|
if (!l_genl_attr_recurse(&attr, &nested))
|
|
|
|
return;
|
|
|
|
|
|
|
|
parse_supported_bands(wiphy, &nested);
|
|
|
|
break;
|
2014-08-07 05:15:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-06 22:23:32 +02:00
|
|
|
static void wiphy_dump_done(void *user)
|
|
|
|
{
|
|
|
|
const struct l_queue_entry *wiphy_entry;
|
|
|
|
|
|
|
|
for (wiphy_entry = l_queue_get_entries(wiphy_list); wiphy_entry;
|
|
|
|
wiphy_entry = wiphy_entry->next) {
|
|
|
|
struct wiphy *wiphy = wiphy_entry->data;
|
|
|
|
uint32_t bands;
|
|
|
|
|
|
|
|
l_info("Wiphy: %d, Name: %s", wiphy->id, wiphy->name);
|
|
|
|
l_info("Bands:");
|
|
|
|
|
|
|
|
bands = scan_freq_set_get_bands(wiphy->supported_freqs);
|
|
|
|
|
|
|
|
if (bands & SCAN_BAND_2_4_GHZ)
|
|
|
|
l_info("\t2.4 Ghz");
|
|
|
|
|
|
|
|
if (bands & SCAN_BAND_5_GHZ)
|
|
|
|
l_info("\t5.0 Ghz");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-07 08:52:08 +02:00
|
|
|
static void wiphy_config_notify(struct l_genl_msg *msg, void *user_data)
|
|
|
|
{
|
|
|
|
struct l_genl_attr attr;
|
|
|
|
uint16_t type, len;
|
|
|
|
const void *data;
|
|
|
|
uint8_t cmd;
|
|
|
|
|
|
|
|
cmd = l_genl_msg_get_command(msg);
|
|
|
|
|
|
|
|
l_debug("Notification of command %u", cmd);
|
|
|
|
|
|
|
|
if (!l_genl_attr_init(&attr, msg))
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (l_genl_attr_next(&attr, &type, &len, &data)) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wiphy_mlme_notify(struct l_genl_msg *msg, void *user_data)
|
|
|
|
{
|
2014-08-09 09:01:22 +02:00
|
|
|
struct wiphy *wiphy = NULL;
|
|
|
|
struct netdev *netdev = NULL;
|
2014-08-07 08:52:08 +02:00
|
|
|
struct l_genl_attr attr;
|
|
|
|
uint16_t type, len;
|
|
|
|
const void *data;
|
|
|
|
uint8_t cmd;
|
|
|
|
|
|
|
|
cmd = l_genl_msg_get_command(msg);
|
|
|
|
|
|
|
|
l_debug("MLME notification %u", cmd);
|
|
|
|
|
|
|
|
if (!l_genl_attr_init(&attr, msg))
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (l_genl_attr_next(&attr, &type, &len, &data)) {
|
2014-08-09 09:01:22 +02:00
|
|
|
switch (type) {
|
|
|
|
case NL80211_ATTR_WIPHY:
|
|
|
|
if (len != sizeof(uint32_t)) {
|
|
|
|
l_warn("Invalid wiphy attribute");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wiphy = l_queue_find(wiphy_list, wiphy_match,
|
|
|
|
L_UINT_TO_PTR(*((uint32_t *) data)));
|
|
|
|
if (!wiphy) {
|
|
|
|
l_warn("No wiphy structure found");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NL80211_ATTR_IFINDEX:
|
|
|
|
if (!wiphy) {
|
|
|
|
l_warn("No wiphy structure found");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len != sizeof(uint32_t)) {
|
|
|
|
l_warn("Invalid interface index attribute");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
netdev = l_queue_find(wiphy->netdev_list, netdev_match,
|
|
|
|
L_UINT_TO_PTR(*((uint32_t *) data)));
|
|
|
|
if (!netdev) {
|
|
|
|
l_warn("No interface structure found");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!wiphy) {
|
2015-01-28 15:17:12 +01:00
|
|
|
l_warn("MLME notification is missing wiphy attribute");
|
2014-08-09 09:01:22 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!netdev) {
|
2015-01-28 15:17:12 +01:00
|
|
|
l_warn("MLME notification is missing interface attribute");
|
2014-08-09 09:01:22 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-13 23:12:08 +01:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case NL80211_CMD_AUTHENTICATE:
|
|
|
|
mlme_authenticate_event(msg, netdev);
|
|
|
|
break;
|
|
|
|
case NL80211_CMD_ASSOCIATE:
|
|
|
|
mlme_associate_event(msg, netdev);
|
|
|
|
break;
|
2015-02-20 12:27:58 +01:00
|
|
|
case NL80211_CMD_DEAUTHENTICATE:
|
|
|
|
mlme_deauthenticate_event(msg, netdev);
|
|
|
|
break;
|
2015-04-08 22:04:22 +02:00
|
|
|
case NL80211_CMD_DISCONNECT:
|
|
|
|
mlme_disconnect_event(msg, netdev);
|
|
|
|
break;
|
2015-05-01 01:42:44 +02:00
|
|
|
case NL80211_CMD_NOTIFY_CQM:
|
|
|
|
mlme_cqm_event(msg, netdev);
|
|
|
|
break;
|
2014-08-07 08:52:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wiphy_regulatory_notify(struct l_genl_msg *msg, void *user_data)
|
|
|
|
{
|
|
|
|
struct l_genl_attr attr;
|
|
|
|
uint16_t type, len;
|
|
|
|
const void *data;
|
|
|
|
uint8_t cmd;
|
|
|
|
|
|
|
|
cmd = l_genl_msg_get_command(msg);
|
|
|
|
|
|
|
|
l_debug("Regulatory notification %u", cmd);
|
|
|
|
|
|
|
|
if (!l_genl_attr_init(&attr, msg))
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (l_genl_attr_next(&attr, &type, &len, &data)) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-07 22:23:02 +02:00
|
|
|
static void regulatory_info_callback(struct l_genl_msg *msg, void *user_data)
|
|
|
|
{
|
|
|
|
struct l_genl_attr attr;
|
|
|
|
uint16_t type, len;
|
|
|
|
const void *data;
|
|
|
|
|
|
|
|
if (!l_genl_attr_init(&attr, msg))
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (l_genl_attr_next(&attr, &type, &len, &data)) {
|
|
|
|
switch (type) {
|
|
|
|
case NL80211_ATTR_REG_ALPHA2:
|
|
|
|
if (len != 3) {
|
|
|
|
l_warn("Invalid regulatory alpha2 attribute");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
l_debug("Regulatory alpha2 is %s", (char *) data);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-07 22:13:31 +02:00
|
|
|
static void protocol_features_callback(struct l_genl_msg *msg, void *user_data)
|
|
|
|
{
|
|
|
|
struct l_genl_attr attr;
|
|
|
|
uint16_t type, len;
|
|
|
|
const void *data;
|
|
|
|
uint32_t features = 0;
|
|
|
|
|
|
|
|
if (!l_genl_attr_init(&attr, msg))
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (l_genl_attr_next(&attr, &type, &len, &data)) {
|
|
|
|
switch (type) {
|
|
|
|
case NL80211_ATTR_PROTOCOL_FEATURES:
|
|
|
|
if (len != sizeof(uint32_t)) {
|
|
|
|
l_warn("Invalid protocol features attribute");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
features = *((uint32_t *) data);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (features & NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)
|
|
|
|
l_debug("Found split wiphy dump support");
|
|
|
|
}
|
|
|
|
|
2015-09-29 02:51:40 +02:00
|
|
|
bool wiphy_init(struct l_genl_family *in)
|
2014-07-29 21:25:01 +02:00
|
|
|
{
|
|
|
|
struct l_genl_msg *msg;
|
|
|
|
|
2014-08-07 05:15:20 +02:00
|
|
|
/*
|
|
|
|
* This is an extra sanity check so that no memory is leaked
|
|
|
|
* in case the generic netlink handling gets confused.
|
|
|
|
*/
|
|
|
|
if (wiphy_list) {
|
|
|
|
l_warn("Destroying existing list of wiphy devices");
|
|
|
|
l_queue_destroy(wiphy_list, NULL);
|
|
|
|
}
|
|
|
|
|
2016-02-11 23:19:55 +01:00
|
|
|
if (!l_dbus_register_interface(dbus_get_bus(),
|
|
|
|
IWD_NETWORK_INTERFACE,
|
|
|
|
setup_network_interface,
|
|
|
|
NULL, true))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!l_dbus_register_interface(dbus_get_bus(),
|
|
|
|
IWD_DEVICE_INTERFACE,
|
|
|
|
setup_device_interface,
|
|
|
|
NULL, true)) {
|
|
|
|
l_dbus_unregister_interface(dbus_get_bus(),
|
|
|
|
IWD_NETWORK_INTERFACE);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-09-29 02:51:40 +02:00
|
|
|
nl80211 = in;
|
|
|
|
|
2014-08-07 08:52:08 +02:00
|
|
|
if (!l_genl_family_register(nl80211, "config", wiphy_config_notify,
|
|
|
|
NULL, NULL))
|
|
|
|
l_error("Registering for config notification failed");
|
|
|
|
|
|
|
|
if (!l_genl_family_register(nl80211, "mlme", wiphy_mlme_notify,
|
|
|
|
NULL, NULL))
|
|
|
|
l_error("Registering for MLME notification failed");
|
|
|
|
|
|
|
|
if (!l_genl_family_register(nl80211, "regulatory",
|
|
|
|
wiphy_regulatory_notify, NULL, NULL))
|
|
|
|
l_error("Registering for regulatory notification failed");
|
|
|
|
|
2015-09-29 02:51:40 +02:00
|
|
|
__eapol_set_install_tk_func(wiphy_set_tk);
|
|
|
|
__eapol_set_install_gtk_func(wiphy_set_gtk);
|
|
|
|
__eapol_set_deauthenticate_func(handshake_failed);
|
2015-06-01 16:28:05 +02:00
|
|
|
|
2014-08-07 05:15:20 +02:00
|
|
|
wiphy_list = l_queue_new();
|
|
|
|
|
2014-08-07 22:13:31 +02:00
|
|
|
msg = l_genl_msg_new(NL80211_CMD_GET_PROTOCOL_FEATURES);
|
|
|
|
if (!l_genl_family_send(nl80211, msg, protocol_features_callback,
|
|
|
|
NULL, NULL))
|
|
|
|
l_error("Getting protocol features failed");
|
|
|
|
|
2014-08-07 22:23:02 +02:00
|
|
|
msg = l_genl_msg_new(NL80211_CMD_GET_REG);
|
|
|
|
if (!l_genl_family_send(nl80211, msg, regulatory_info_callback,
|
|
|
|
NULL, NULL))
|
|
|
|
l_error("Getting regulatory info failed");
|
|
|
|
|
2014-07-29 21:25:01 +02:00
|
|
|
msg = l_genl_msg_new(NL80211_CMD_GET_WIPHY);
|
2015-10-06 22:23:32 +02:00
|
|
|
if (!l_genl_family_dump(nl80211, msg, wiphy_dump_callback,
|
|
|
|
NULL, wiphy_dump_done))
|
2014-08-07 06:27:32 +02:00
|
|
|
l_error("Getting all wiphy devices failed");
|
|
|
|
|
|
|
|
msg = l_genl_msg_new(NL80211_CMD_GET_INTERFACE);
|
|
|
|
if (!l_genl_family_dump(nl80211, msg, interface_dump_callback,
|
|
|
|
NULL, NULL))
|
|
|
|
l_error("Getting all interface information failed");
|
2015-03-20 18:30:24 +01:00
|
|
|
|
2014-07-29 21:25:01 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool wiphy_exit(void)
|
|
|
|
{
|
2015-09-29 02:51:40 +02:00
|
|
|
l_queue_destroy(wiphy_list, wiphy_free);
|
|
|
|
wiphy_list = NULL;
|
2014-07-29 21:25:01 +02:00
|
|
|
|
2015-09-29 02:51:40 +02:00
|
|
|
nl80211 = NULL;
|
2014-08-07 05:15:20 +02:00
|
|
|
|
2016-02-11 23:19:55 +01:00
|
|
|
l_dbus_unregister_interface(dbus_get_bus(), IWD_DEVICE_INTERFACE);
|
|
|
|
l_dbus_unregister_interface(dbus_get_bus(), IWD_NETWORK_INTERFACE);
|
|
|
|
|
2014-07-29 21:25:01 +02:00
|
|
|
return true;
|
|
|
|
}
|
2014-08-07 08:52:42 +02:00
|
|
|
|
|
|
|
static void wiphy_check_dellink(void *data, void *user_data)
|
|
|
|
{
|
|
|
|
uint32_t index = L_PTR_TO_UINT(user_data);
|
|
|
|
struct wiphy *wiphy = data;
|
|
|
|
struct netdev *netdev;
|
|
|
|
|
|
|
|
netdev = l_queue_remove_if(wiphy->netdev_list, netdev_match,
|
|
|
|
L_UINT_TO_PTR(index));
|
|
|
|
if (netdev) {
|
|
|
|
l_warn("Removing leftover interface %s", netdev->name);
|
|
|
|
netdev_free(netdev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void wiphy_notify_dellink(uint32_t index)
|
|
|
|
{
|
|
|
|
if (!wiphy_list)
|
|
|
|
return;
|
|
|
|
|
|
|
|
l_queue_foreach(wiphy_list, wiphy_check_dellink, L_UINT_TO_PTR(index));
|
|
|
|
}
|