2016-05-05 19:13:45 +02:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Wireless daemon for Linux
|
|
|
|
*
|
2018-01-18 22:36:38 +01:00
|
|
|
* Copyright (C) 2013-2018 Intel Corporation. All rights reserved.
|
2016-05-05 19:13:45 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2016-06-14 18:31:48 +02:00
|
|
|
#include <stdio.h>
|
2016-06-16 22:37:50 +02:00
|
|
|
#include <errno.h>
|
2017-01-18 12:36:32 +01:00
|
|
|
#include <linux/if_ether.h>
|
2016-06-14 18:31:48 +02:00
|
|
|
|
2016-05-05 19:13:45 +02:00
|
|
|
#include <ell/ell.h>
|
|
|
|
|
2016-06-15 17:54:13 +02:00
|
|
|
#include "src/iwd.h"
|
2016-06-16 22:37:50 +02:00
|
|
|
#include "src/util.h"
|
2016-06-15 17:54:13 +02:00
|
|
|
#include "src/wiphy.h"
|
|
|
|
#include "src/scan.h"
|
2016-06-14 18:19:05 +02:00
|
|
|
#include "src/netdev.h"
|
2016-06-14 18:14:45 +02:00
|
|
|
#include "src/dbus.h"
|
2018-09-01 00:44:10 +02:00
|
|
|
#include "src/station.h"
|
2018-09-25 02:29:40 +02:00
|
|
|
#include "src/device.h"
|
2016-05-05 19:13:45 +02:00
|
|
|
|
2016-06-16 23:23:00 +02:00
|
|
|
struct device {
|
|
|
|
uint32_t index;
|
|
|
|
|
|
|
|
struct wiphy *wiphy;
|
|
|
|
struct netdev *netdev;
|
2016-09-22 19:57:10 +02:00
|
|
|
|
2018-11-29 18:34:07 +01:00
|
|
|
bool powered : 1; /* Current IFUP state */
|
|
|
|
bool dbus_powered : 1; /* Last IFUP state wanted via D-Bus */
|
2018-01-18 22:36:38 +01:00
|
|
|
|
|
|
|
uint32_t ap_roam_watch;
|
2018-11-29 18:34:07 +01:00
|
|
|
uint32_t wiphy_rfkill_watch;
|
2016-06-16 23:23:00 +02:00
|
|
|
};
|
|
|
|
|
2018-08-18 06:40:49 +02:00
|
|
|
static uint32_t netdev_watch;
|
2016-06-16 22:37:50 +02:00
|
|
|
|
2018-01-18 22:36:38 +01:00
|
|
|
static void device_ap_roam_frame_event(struct netdev *netdev,
|
|
|
|
const struct mmpdu_header *hdr,
|
|
|
|
const void *body, size_t body_len,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct device *device = user_data;
|
2018-09-25 02:27:04 +02:00
|
|
|
struct station *station = station_find(device->index);
|
|
|
|
|
|
|
|
if (!station)
|
|
|
|
return;
|
2018-01-18 22:36:38 +01:00
|
|
|
|
2018-09-04 20:48:18 +02:00
|
|
|
station_ap_directed_roam(station, hdr, body, body_len);
|
2017-08-14 14:31:18 +02:00
|
|
|
}
|
|
|
|
|
2016-06-16 23:22:14 +02: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 device *device = user_data;
|
|
|
|
|
|
|
|
l_dbus_message_builder_append_basic(builder, 's',
|
|
|
|
netdev_get_name(device->netdev));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool device_property_get_address(struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
struct l_dbus_message_builder *builder,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct device *device = user_data;
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
str = util_address_to_string(netdev_get_address(device->netdev));
|
|
|
|
l_dbus_message_builder_append_basic(builder, 's', str);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-06-20 12:42:06 +02:00
|
|
|
static bool device_property_get_powered(struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
struct l_dbus_message_builder *builder,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct device *device = user_data;
|
2018-09-04 17:40:45 +02:00
|
|
|
bool powered = device->powered;
|
2016-06-20 12:42:06 +02:00
|
|
|
|
|
|
|
l_dbus_message_builder_append_basic(builder, 'b', &powered);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-06-13 17:57:37 +02:00
|
|
|
struct set_generic_cb_data {
|
2016-07-12 04:13:52 +02:00
|
|
|
struct device *device;
|
|
|
|
struct l_dbus *dbus;
|
|
|
|
struct l_dbus_message *message;
|
|
|
|
l_dbus_property_complete_cb_t complete;
|
|
|
|
};
|
|
|
|
|
2018-08-17 19:02:15 +02:00
|
|
|
static void set_generic_destroy(void *user_data)
|
|
|
|
{
|
|
|
|
struct set_generic_cb_data *cb_data = user_data;
|
|
|
|
|
|
|
|
/* Message hasn't been replied to, generate an Aborted error */
|
|
|
|
if (cb_data->message)
|
|
|
|
cb_data->complete(cb_data->dbus, cb_data->message,
|
|
|
|
dbus_error_aborted(cb_data->message));
|
|
|
|
|
|
|
|
l_free(cb_data);
|
|
|
|
}
|
|
|
|
|
2016-07-12 04:13:52 +02:00
|
|
|
static void set_powered_cb(struct netdev *netdev, int result, void *user_data)
|
|
|
|
{
|
2018-06-13 17:57:37 +02:00
|
|
|
struct set_generic_cb_data *cb_data = user_data;
|
2016-07-12 04:13:52 +02:00
|
|
|
struct l_dbus_message *reply = NULL;
|
|
|
|
|
|
|
|
if (result < 0)
|
|
|
|
reply = dbus_error_failed(cb_data->message);
|
|
|
|
|
|
|
|
cb_data->complete(cb_data->dbus, cb_data->message, reply);
|
2018-08-17 19:02:15 +02:00
|
|
|
cb_data->message = NULL;
|
2016-07-12 04:13:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct l_dbus_message *device_property_set_powered(struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
struct l_dbus_message_iter *new_value,
|
|
|
|
l_dbus_property_complete_cb_t complete,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct device *device = user_data;
|
|
|
|
bool powered;
|
2018-06-13 17:57:37 +02:00
|
|
|
struct set_generic_cb_data *cb_data;
|
2018-08-17 18:52:47 +02:00
|
|
|
int r;
|
2016-07-12 04:13:52 +02:00
|
|
|
|
|
|
|
if (!l_dbus_message_iter_get_variant(new_value, "b", &powered))
|
|
|
|
return dbus_error_invalid_args(message);
|
|
|
|
|
2018-11-29 18:34:07 +01:00
|
|
|
device->dbus_powered = powered;
|
|
|
|
|
2018-09-04 17:40:45 +02:00
|
|
|
if (powered == device->powered) {
|
2016-07-12 04:13:52 +02:00
|
|
|
complete(dbus, message, NULL);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-06-13 17:57:37 +02:00
|
|
|
cb_data = l_new(struct set_generic_cb_data, 1);
|
2016-07-12 04:13:52 +02:00
|
|
|
cb_data->device = device;
|
|
|
|
cb_data->dbus = dbus;
|
|
|
|
cb_data->message = message;
|
|
|
|
cb_data->complete = complete;
|
|
|
|
|
2018-08-17 18:52:47 +02:00
|
|
|
r = netdev_set_powered(device->netdev, powered, set_powered_cb,
|
2018-08-17 19:02:15 +02:00
|
|
|
cb_data, set_generic_destroy);
|
2018-08-17 18:52:47 +02:00
|
|
|
if (r < 0) {
|
|
|
|
l_free(cb_data);
|
|
|
|
return dbus_error_from_errno(r, message);
|
|
|
|
}
|
2016-07-12 04:13:52 +02:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-06-13 17:57:37 +02:00
|
|
|
static bool device_property_get_4addr(struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
struct l_dbus_message_builder *builder,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct device *device = user_data;
|
|
|
|
bool use_4addr = netdev_get_4addr(device->netdev);
|
|
|
|
|
|
|
|
l_dbus_message_builder_append_basic(builder, 'b', &use_4addr);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_4addr_cb(struct netdev *netdev, int result, void *user_data)
|
|
|
|
{
|
|
|
|
struct set_generic_cb_data *cb_data = user_data;
|
|
|
|
struct l_dbus_message *reply = NULL;
|
|
|
|
|
|
|
|
if (result < 0)
|
|
|
|
reply = dbus_error_failed(cb_data->message);
|
|
|
|
|
|
|
|
cb_data->complete(cb_data->dbus, cb_data->message, reply);
|
2018-08-17 19:02:15 +02:00
|
|
|
cb_data->message = NULL;
|
2018-06-13 17:57:37 +02:00
|
|
|
|
2018-09-04 22:51:44 +02:00
|
|
|
l_dbus_property_changed(cb_data->dbus,
|
|
|
|
netdev_get_path(cb_data->device->netdev),
|
2018-06-13 17:57:37 +02:00
|
|
|
IWD_DEVICE_INTERFACE, "WDS");
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct l_dbus_message *device_property_set_4addr(struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
struct l_dbus_message_iter *new_value,
|
|
|
|
l_dbus_property_complete_cb_t complete,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct set_generic_cb_data *cb_data;
|
|
|
|
struct device *device = user_data;
|
|
|
|
bool use_4addr;
|
|
|
|
|
|
|
|
if (!l_dbus_message_iter_get_variant(new_value, "b", &use_4addr))
|
|
|
|
return dbus_error_invalid_args(message);
|
|
|
|
|
|
|
|
if (use_4addr == netdev_get_4addr(device->netdev)) {
|
|
|
|
complete(dbus, message, NULL);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
cb_data = l_new(struct set_generic_cb_data, 1);
|
|
|
|
cb_data->device = device;
|
|
|
|
cb_data->dbus = dbus;
|
|
|
|
cb_data->message = message;
|
|
|
|
cb_data->complete = complete;
|
|
|
|
|
2018-08-17 19:02:15 +02:00
|
|
|
if (netdev_set_4addr(device->netdev, use_4addr, set_4addr_cb,
|
|
|
|
cb_data, set_generic_destroy) < 0)
|
2018-06-13 17:57:37 +02:00
|
|
|
return dbus_error_failed(message);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-11-02 15:24:31 +01:00
|
|
|
static bool device_property_get_adapter(struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
struct l_dbus_message_builder *builder,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct device *device = user_data;
|
|
|
|
|
|
|
|
l_dbus_message_builder_append_basic(builder, 'o',
|
|
|
|
wiphy_get_path(device->wiphy));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-06-30 01:29:17 +02:00
|
|
|
static bool device_property_get_mode(struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
struct l_dbus_message_builder *builder,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct device *device = user_data;
|
2018-08-20 03:39:37 +02:00
|
|
|
uint32_t iftype = netdev_get_iftype(device->netdev);
|
|
|
|
const char *modestr = dbus_iftype_to_string(iftype);
|
2018-06-30 01:29:17 +02:00
|
|
|
|
2018-08-20 03:39:37 +02:00
|
|
|
if (modestr == NULL)
|
|
|
|
modestr = "unknown";
|
2018-06-30 01:29:17 +02:00
|
|
|
|
|
|
|
l_dbus_message_builder_append_basic(builder, 's', modestr);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-08-20 05:07:15 +02:00
|
|
|
static void set_mode_cb(struct netdev *netdev, int result, void *user_data)
|
2018-07-18 01:39:54 +02:00
|
|
|
{
|
2018-08-20 05:07:15 +02:00
|
|
|
struct set_generic_cb_data *cb_data = user_data;
|
|
|
|
struct l_dbus_message *reply = NULL;
|
2018-07-18 01:39:54 +02:00
|
|
|
|
2018-08-20 05:07:15 +02:00
|
|
|
if (result < 0)
|
|
|
|
reply = dbus_error_from_errno(result, cb_data->message);
|
2018-07-18 01:39:54 +02:00
|
|
|
|
2018-08-20 05:07:15 +02:00
|
|
|
cb_data->complete(cb_data->dbus, cb_data->message, reply);
|
|
|
|
cb_data->message = NULL;
|
2018-07-18 01:39:54 +02:00
|
|
|
|
2018-09-04 22:51:44 +02:00
|
|
|
l_dbus_property_changed(cb_data->dbus,
|
|
|
|
netdev_get_path(cb_data->device->netdev),
|
2018-08-20 05:07:15 +02:00
|
|
|
IWD_DEVICE_INTERFACE, "Mode");
|
2018-07-18 01:39:54 +02:00
|
|
|
}
|
|
|
|
|
2018-06-30 01:29:17 +02:00
|
|
|
static struct l_dbus_message *device_property_set_mode(struct l_dbus *dbus,
|
|
|
|
struct l_dbus_message *message,
|
|
|
|
struct l_dbus_message_iter *new_value,
|
|
|
|
l_dbus_property_complete_cb_t complete,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct device *device = user_data;
|
2018-08-20 05:07:15 +02:00
|
|
|
struct netdev *netdev = device->netdev;
|
|
|
|
const char *mode;
|
|
|
|
enum netdev_iftype iftype;
|
|
|
|
int r;
|
|
|
|
struct set_generic_cb_data *cb_data;
|
2018-06-30 01:29:17 +02:00
|
|
|
|
|
|
|
if (!l_dbus_message_iter_get_variant(new_value, "s", &mode))
|
|
|
|
return dbus_error_invalid_args(message);
|
|
|
|
|
2018-07-18 01:39:54 +02:00
|
|
|
if (!strcmp(mode, "station"))
|
2018-08-20 05:07:15 +02:00
|
|
|
iftype = NETDEV_IFTYPE_STATION;
|
2018-07-18 01:39:54 +02:00
|
|
|
else if (!strcmp(mode, "ap"))
|
2018-08-20 05:07:15 +02:00
|
|
|
iftype = NETDEV_IFTYPE_AP;
|
2018-07-18 01:39:54 +02:00
|
|
|
else if (!strcmp(mode, "ad-hoc"))
|
2018-08-20 05:07:15 +02:00
|
|
|
iftype = NETDEV_IFTYPE_ADHOC;
|
2018-07-18 01:39:54 +02:00
|
|
|
else
|
2018-06-30 01:29:17 +02:00
|
|
|
return dbus_error_invalid_args(message);
|
2018-07-18 01:39:54 +02:00
|
|
|
|
2018-08-20 05:07:15 +02:00
|
|
|
if (iftype == netdev_get_iftype(netdev)) {
|
|
|
|
complete(dbus, message, NULL);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
cb_data = l_new(struct set_generic_cb_data, 1);
|
|
|
|
cb_data->device = device;
|
|
|
|
cb_data->dbus = dbus;
|
|
|
|
cb_data->message = message;
|
|
|
|
cb_data->complete = complete;
|
2018-06-30 01:29:17 +02:00
|
|
|
|
2018-08-20 05:07:15 +02:00
|
|
|
r = netdev_set_iftype(device->netdev, iftype, set_mode_cb,
|
|
|
|
cb_data, set_generic_destroy);
|
|
|
|
if (r < 0) {
|
|
|
|
l_free(cb_data);
|
|
|
|
return dbus_error_from_errno(r, message);
|
|
|
|
}
|
2018-06-30 01:29:17 +02:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-06-16 23:22:14 +02:00
|
|
|
static void setup_device_interface(struct l_dbus_interface *interface)
|
|
|
|
{
|
|
|
|
l_dbus_interface_property(interface, "Name", 0, "s",
|
|
|
|
device_property_get_name, NULL);
|
|
|
|
l_dbus_interface_property(interface, "Address", 0, "s",
|
|
|
|
device_property_get_address, NULL);
|
2018-06-13 17:57:37 +02:00
|
|
|
l_dbus_interface_property(interface, "WDS", 0, "b",
|
|
|
|
device_property_get_4addr,
|
|
|
|
device_property_set_4addr);
|
2016-06-20 12:42:06 +02:00
|
|
|
l_dbus_interface_property(interface, "Powered", 0, "b",
|
2016-07-12 04:13:52 +02:00
|
|
|
device_property_get_powered,
|
|
|
|
device_property_set_powered);
|
2016-11-02 15:24:31 +01:00
|
|
|
l_dbus_interface_property(interface, "Adapter", 0, "o",
|
|
|
|
device_property_get_adapter, NULL);
|
2018-06-30 01:29:17 +02:00
|
|
|
l_dbus_interface_property(interface, "Mode", 0, "s",
|
|
|
|
device_property_get_mode,
|
|
|
|
device_property_set_mode);
|
2016-06-16 23:22:14 +02:00
|
|
|
}
|
|
|
|
|
2016-07-14 02:38:05 +02:00
|
|
|
static void device_netdev_notify(struct netdev *netdev,
|
|
|
|
enum netdev_watch_event event,
|
2016-06-20 12:42:05 +02:00
|
|
|
void *user_data)
|
|
|
|
{
|
2018-08-18 06:40:49 +02:00
|
|
|
struct device *device = netdev_get_device(netdev);
|
2016-06-20 12:42:05 +02:00
|
|
|
struct l_dbus *dbus = dbus_get_bus();
|
|
|
|
|
2018-08-18 06:40:49 +02:00
|
|
|
if (!device)
|
|
|
|
return;
|
|
|
|
|
2016-07-20 01:03:21 +02:00
|
|
|
switch (event) {
|
|
|
|
case NETDEV_WATCH_EVENT_UP:
|
2018-09-04 17:40:45 +02:00
|
|
|
device->powered = true;
|
2018-09-22 18:48:25 +02:00
|
|
|
|
2018-09-04 22:51:44 +02:00
|
|
|
l_dbus_property_changed(dbus, netdev_get_path(device->netdev),
|
2016-07-14 02:38:05 +02:00
|
|
|
IWD_DEVICE_INTERFACE, "Powered");
|
2016-07-20 01:03:21 +02:00
|
|
|
break;
|
|
|
|
case NETDEV_WATCH_EVENT_DOWN:
|
2018-09-04 17:40:45 +02:00
|
|
|
device->powered = false;
|
2016-06-20 12:42:05 +02:00
|
|
|
|
2018-09-04 22:51:44 +02:00
|
|
|
l_dbus_property_changed(dbus, netdev_get_path(device->netdev),
|
2016-07-14 02:38:05 +02:00
|
|
|
IWD_DEVICE_INTERFACE, "Powered");
|
2016-07-20 01:03:21 +02:00
|
|
|
break;
|
|
|
|
case NETDEV_WATCH_EVENT_NAME_CHANGE:
|
2018-09-04 22:51:44 +02:00
|
|
|
l_dbus_property_changed(dbus, netdev_get_path(device->netdev),
|
2016-07-14 02:38:06 +02:00
|
|
|
IWD_DEVICE_INTERFACE, "Name");
|
2016-07-20 01:03:21 +02:00
|
|
|
break;
|
2017-03-08 15:07:14 +01:00
|
|
|
case NETDEV_WATCH_EVENT_ADDRESS_CHANGE:
|
2018-09-04 22:51:44 +02:00
|
|
|
l_dbus_property_changed(dbus, netdev_get_path(device->netdev),
|
2017-03-08 15:07:14 +01:00
|
|
|
IWD_DEVICE_INTERFACE, "Address");
|
|
|
|
break;
|
2018-08-18 06:40:49 +02:00
|
|
|
default:
|
|
|
|
break;
|
2016-07-20 01:03:21 +02:00
|
|
|
}
|
2016-06-20 12:42:05 +02:00
|
|
|
}
|
|
|
|
|
2018-11-29 18:34:07 +01:00
|
|
|
static void device_wiphy_state_changed_event(struct wiphy *wiphy,
|
|
|
|
enum wiphy_state_watch_event event,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct device *device = user_data;
|
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
case WIPHY_STATE_WATCH_EVENT_RFKILLED:
|
|
|
|
break;
|
|
|
|
case WIPHY_STATE_WATCH_EVENT_POWERED:
|
|
|
|
if (device->dbus_powered)
|
|
|
|
netdev_set_powered(device->netdev, true,
|
|
|
|
NULL, NULL, NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-16 22:37:50 +02:00
|
|
|
struct device *device_create(struct wiphy *wiphy, struct netdev *netdev)
|
|
|
|
{
|
|
|
|
struct device *device;
|
|
|
|
struct l_dbus *dbus = dbus_get_bus();
|
|
|
|
uint32_t ifindex = netdev_get_ifindex(netdev);
|
2018-01-18 22:36:38 +01:00
|
|
|
const uint8_t action_ap_roam_prefix[2] = { 0x0a, 0x07 };
|
2016-06-16 22:37:50 +02:00
|
|
|
|
|
|
|
device = l_new(struct device, 1);
|
|
|
|
device->index = ifindex;
|
|
|
|
device->wiphy = wiphy;
|
|
|
|
device->netdev = netdev;
|
|
|
|
|
2018-09-04 22:51:44 +02:00
|
|
|
if (!l_dbus_object_add_interface(dbus, netdev_get_path(device->netdev),
|
2016-06-16 22:37:50 +02:00
|
|
|
IWD_DEVICE_INTERFACE, device))
|
|
|
|
l_info("Unable to register %s interface", IWD_DEVICE_INTERFACE);
|
|
|
|
|
2018-09-04 22:51:44 +02:00
|
|
|
if (!l_dbus_object_add_interface(dbus, netdev_get_path(device->netdev),
|
2016-09-21 18:51:55 +02:00
|
|
|
L_DBUS_INTERFACE_PROPERTIES, device))
|
|
|
|
l_info("Unable to register %s interface",
|
|
|
|
L_DBUS_INTERFACE_PROPERTIES);
|
|
|
|
|
2016-06-16 22:37:50 +02:00
|
|
|
scan_ifindex_add(device->index);
|
2016-06-20 12:42:05 +02:00
|
|
|
|
2018-01-18 22:36:38 +01:00
|
|
|
/*
|
|
|
|
* register for AP roam transition watch
|
|
|
|
*/
|
|
|
|
device->ap_roam_watch = netdev_frame_watch_add(netdev, 0x00d0,
|
|
|
|
action_ap_roam_prefix, sizeof(action_ap_roam_prefix),
|
|
|
|
device_ap_roam_frame_event, device);
|
|
|
|
|
2018-09-04 17:40:45 +02:00
|
|
|
device->powered = netdev_get_is_up(netdev);
|
|
|
|
|
2018-11-29 18:34:07 +01:00
|
|
|
device->dbus_powered = true;
|
|
|
|
device->wiphy_rfkill_watch =
|
|
|
|
wiphy_state_watch_add(wiphy, device_wiphy_state_changed_event,
|
|
|
|
device, NULL);
|
|
|
|
|
2016-06-16 22:37:50 +02:00
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
2018-09-04 23:41:37 +02:00
|
|
|
void device_remove(struct device *device)
|
2016-06-16 22:37:50 +02:00
|
|
|
{
|
2018-09-05 05:46:12 +02:00
|
|
|
struct l_dbus *dbus = dbus_get_bus();
|
2016-06-16 22:37:50 +02:00
|
|
|
|
|
|
|
l_debug("");
|
|
|
|
|
2018-09-04 22:51:44 +02:00
|
|
|
l_dbus_unregister_object(dbus, netdev_get_path(device->netdev));
|
2016-06-16 22:37:50 +02:00
|
|
|
|
|
|
|
scan_ifindex_remove(device->index);
|
2018-01-18 22:36:38 +01:00
|
|
|
|
|
|
|
netdev_frame_watch_remove(device->netdev, device->ap_roam_watch);
|
2018-11-29 18:34:07 +01:00
|
|
|
wiphy_state_watch_remove(device->wiphy, device->wiphy_rfkill_watch);
|
2018-01-18 22:36:38 +01:00
|
|
|
|
2016-06-16 22:37:50 +02:00
|
|
|
l_free(device);
|
|
|
|
}
|
|
|
|
|
2016-05-05 19:13:45 +02:00
|
|
|
bool device_init(void)
|
|
|
|
{
|
2016-06-16 23:22:14 +02:00
|
|
|
if (!l_dbus_register_interface(dbus_get_bus(),
|
|
|
|
IWD_DEVICE_INTERFACE,
|
|
|
|
setup_device_interface,
|
2016-09-21 18:51:55 +02:00
|
|
|
NULL, false))
|
2016-06-16 23:22:14 +02:00
|
|
|
return false;
|
|
|
|
|
2018-08-18 06:40:49 +02:00
|
|
|
netdev_watch = netdev_watch_add(device_netdev_notify, NULL, NULL);
|
2016-05-05 19:13:45 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-08-14 21:11:52 +02:00
|
|
|
void device_exit(void)
|
2016-05-05 19:13:45 +02:00
|
|
|
{
|
2018-08-18 06:40:49 +02:00
|
|
|
netdev_watch_remove(netdev_watch);
|
2016-05-05 19:13:45 +02:00
|
|
|
|
2016-06-16 23:22:14 +02:00
|
|
|
l_dbus_unregister_interface(dbus_get_bus(), IWD_DEVICE_INTERFACE);
|
2016-05-05 19:13:45 +02:00
|
|
|
}
|