mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2025-02-16 23:40:43 +01:00
station: Move hidden network code from device
This commit is contained in:
parent
e65c3e63be
commit
ee91cfcb7e
153
src/device.c
153
src/device.c
@ -49,7 +49,6 @@
|
|||||||
|
|
||||||
struct device {
|
struct device {
|
||||||
uint32_t index;
|
uint32_t index;
|
||||||
struct l_dbus_message *connect_pending;
|
|
||||||
struct l_dbus_message *disconnect_pending;
|
struct l_dbus_message *disconnect_pending;
|
||||||
uint8_t preauth_bssid[ETH_ALEN];
|
uint8_t preauth_bssid[ETH_ALEN];
|
||||||
struct signal_agent *signal_agent;
|
struct signal_agent *signal_agent;
|
||||||
@ -103,11 +102,11 @@ static void device_disconnect_event(struct device *device)
|
|||||||
|
|
||||||
l_debug("%d", device->index);
|
l_debug("%d", device->index);
|
||||||
|
|
||||||
if (device->connect_pending) {
|
if (station->connect_pending) {
|
||||||
struct network *network = station->connected_network;
|
struct network *network = station->connected_network;
|
||||||
|
|
||||||
dbus_pending_reply(&device->connect_pending,
|
dbus_pending_reply(&station->connect_pending,
|
||||||
dbus_error_failed(device->connect_pending));
|
dbus_error_failed(station->connect_pending));
|
||||||
|
|
||||||
network_connect_failed(network);
|
network_connect_failed(network);
|
||||||
}
|
}
|
||||||
@ -351,24 +350,24 @@ static void device_connect_cb(struct netdev *netdev, enum netdev_result result,
|
|||||||
|
|
||||||
l_debug("%d, result: %d", device->index, result);
|
l_debug("%d, result: %d", device->index, result);
|
||||||
|
|
||||||
if (device->connect_pending) {
|
if (station->connect_pending) {
|
||||||
struct l_dbus_message *reply;
|
struct l_dbus_message *reply;
|
||||||
|
|
||||||
switch (result) {
|
switch (result) {
|
||||||
case NETDEV_RESULT_ABORTED:
|
case NETDEV_RESULT_ABORTED:
|
||||||
reply = dbus_error_aborted(device->connect_pending);
|
reply = dbus_error_aborted(station->connect_pending);
|
||||||
break;
|
break;
|
||||||
case NETDEV_RESULT_OK:
|
case NETDEV_RESULT_OK:
|
||||||
reply = l_dbus_message_new_method_return(
|
reply = l_dbus_message_new_method_return(
|
||||||
device->connect_pending);
|
station->connect_pending);
|
||||||
l_dbus_message_set_arguments(reply, "");
|
l_dbus_message_set_arguments(reply, "");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
reply = dbus_error_failed(device->connect_pending);
|
reply = dbus_error_failed(station->connect_pending);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
dbus_pending_reply(&device->connect_pending, reply);
|
dbus_pending_reply(&station->connect_pending, reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result != NETDEV_RESULT_OK) {
|
if (result != NETDEV_RESULT_OK) {
|
||||||
@ -491,6 +490,7 @@ void device_connect_network(struct device *device, struct network *network,
|
|||||||
struct scan_bss *bss,
|
struct scan_bss *bss,
|
||||||
struct l_dbus_message *message)
|
struct l_dbus_message *message)
|
||||||
{
|
{
|
||||||
|
struct station *station = device->station;
|
||||||
int err = __device_connect_network(device, network, bss);
|
int err = __device_connect_network(device, network, bss);
|
||||||
|
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
@ -500,8 +500,8 @@ void device_connect_network(struct device *device, struct network *network,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
device->connect_pending = l_dbus_message_ref(message);
|
station->connect_pending = l_dbus_message_ref(message);
|
||||||
device->station->autoconnect = true;
|
station->autoconnect = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct l_dbus_message *device_scan(struct l_dbus *dbus,
|
static struct l_dbus_message *device_scan(struct l_dbus *dbus,
|
||||||
@ -754,134 +754,17 @@ static struct l_dbus_message *device_signal_agent_unregister(
|
|||||||
return l_dbus_message_new_method_return(message);
|
return l_dbus_message_new_method_return(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void device_hidden_network_scan_triggered(int err, void *user_data)
|
|
||||||
{
|
|
||||||
struct device *device = user_data;
|
|
||||||
|
|
||||||
l_debug("");
|
|
||||||
|
|
||||||
if (!err)
|
|
||||||
return;
|
|
||||||
|
|
||||||
dbus_pending_reply(&device->connect_pending,
|
|
||||||
dbus_error_failed(device->connect_pending));
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool device_hidden_network_scan_results(uint32_t wiphy_id,
|
|
||||||
uint32_t ifindex, int err,
|
|
||||||
struct l_queue *bss_list,
|
|
||||||
void *userdata)
|
|
||||||
{
|
|
||||||
struct device *device = userdata;
|
|
||||||
struct station *station = device->station;
|
|
||||||
struct network *network_psk;
|
|
||||||
struct network *network_open;
|
|
||||||
struct network *network;
|
|
||||||
const char *ssid;
|
|
||||||
uint8_t ssid_len;
|
|
||||||
struct l_dbus_message *msg;
|
|
||||||
struct scan_bss *bss;
|
|
||||||
|
|
||||||
l_debug("");
|
|
||||||
|
|
||||||
msg = device->connect_pending;
|
|
||||||
device->connect_pending = NULL;
|
|
||||||
|
|
||||||
if (err) {
|
|
||||||
dbus_pending_reply(&msg, dbus_error_failed(msg));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!l_dbus_message_get_arguments(msg, "s", &ssid)) {
|
|
||||||
dbus_pending_reply(&msg, dbus_error_invalid_args(msg));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ssid_len = strlen(ssid);
|
|
||||||
|
|
||||||
while ((bss = l_queue_pop_head(bss_list))) {
|
|
||||||
if (bss->ssid_len != ssid_len ||
|
|
||||||
memcmp(bss->ssid, ssid, ssid_len))
|
|
||||||
goto next;
|
|
||||||
|
|
||||||
if (station_add_seen_bss(device->station, bss)) {
|
|
||||||
l_queue_push_tail(device->station->bss_list, bss);
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
next:
|
|
||||||
scan_bss_free(bss);
|
|
||||||
}
|
|
||||||
|
|
||||||
l_queue_destroy(bss_list, NULL);
|
|
||||||
|
|
||||||
network_psk = station_network_find(station, ssid, SECURITY_PSK);
|
|
||||||
network_open = station_network_find(station, ssid, SECURITY_NONE);
|
|
||||||
|
|
||||||
if (!network_psk && !network_open) {
|
|
||||||
dbus_pending_reply(&msg, dbus_error_not_found(msg));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (network_psk && network_open) {
|
|
||||||
dbus_pending_reply(&msg, dbus_error_service_set_overlap(msg));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
network = network_psk ? : network_open;
|
|
||||||
|
|
||||||
network_connect_new_hidden_network(network, msg);
|
|
||||||
l_dbus_message_unref(msg);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct l_dbus_message *device_connect_hidden_network(struct l_dbus *dbus,
|
static struct l_dbus_message *device_connect_hidden_network(struct l_dbus *dbus,
|
||||||
struct l_dbus_message *message,
|
struct l_dbus_message *message,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
struct device *device = user_data;
|
struct device *device = user_data;
|
||||||
struct station *station = device->station;
|
struct station *station = device->station;
|
||||||
const char *ssid;
|
|
||||||
struct scan_parameters params = {
|
|
||||||
.flush = true,
|
|
||||||
.randomize_mac_addr_hint = true,
|
|
||||||
};
|
|
||||||
|
|
||||||
l_debug("");
|
if (!device->powered || !device->station)
|
||||||
|
return dbus_error_not_available(message);
|
||||||
|
|
||||||
if (!device->powered)
|
return station_dbus_connect_hidden_network(dbus, message, station);
|
||||||
return dbus_error_failed(message);
|
|
||||||
|
|
||||||
if (device->connect_pending || device_is_busy(device))
|
|
||||||
return dbus_error_busy(message);
|
|
||||||
|
|
||||||
if (!l_dbus_message_get_arguments(message, "s", &ssid))
|
|
||||||
return dbus_error_invalid_args(message);
|
|
||||||
|
|
||||||
if (strlen(ssid) > 32)
|
|
||||||
return dbus_error_invalid_args(message);
|
|
||||||
|
|
||||||
if (known_networks_find(ssid, SECURITY_PSK) ||
|
|
||||||
known_networks_find(ssid, SECURITY_NONE))
|
|
||||||
return dbus_error_already_provisioned(message);
|
|
||||||
|
|
||||||
if (station_network_find(station, ssid, SECURITY_PSK) ||
|
|
||||||
station_network_find(station, ssid, SECURITY_NONE))
|
|
||||||
return dbus_error_not_hidden(message);
|
|
||||||
|
|
||||||
params.ssid = ssid;
|
|
||||||
|
|
||||||
if (!scan_active_full(device->index, ¶ms,
|
|
||||||
device_hidden_network_scan_triggered,
|
|
||||||
device_hidden_network_scan_results,
|
|
||||||
device, NULL))
|
|
||||||
return dbus_error_failed(message);
|
|
||||||
|
|
||||||
device->connect_pending = l_dbus_message_ref(message);
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool device_property_get_name(struct l_dbus *dbus,
|
static bool device_property_get_name(struct l_dbus *dbus,
|
||||||
@ -1286,10 +1169,6 @@ static void device_netdev_notify(struct netdev *netdev,
|
|||||||
|
|
||||||
device->powered = false;
|
device->powered = false;
|
||||||
|
|
||||||
if (device->connect_pending)
|
|
||||||
dbus_pending_reply(&device->connect_pending,
|
|
||||||
dbus_error_aborted(device->connect_pending));
|
|
||||||
|
|
||||||
l_dbus_property_changed(dbus, netdev_get_path(device->netdev),
|
l_dbus_property_changed(dbus, netdev_get_path(device->netdev),
|
||||||
IWD_DEVICE_INTERFACE, "Powered");
|
IWD_DEVICE_INTERFACE, "Powered");
|
||||||
break;
|
break;
|
||||||
@ -1351,10 +1230,6 @@ void device_remove(struct device *device)
|
|||||||
|
|
||||||
l_debug("");
|
l_debug("");
|
||||||
|
|
||||||
if (device->connect_pending)
|
|
||||||
dbus_pending_reply(&device->connect_pending,
|
|
||||||
dbus_error_aborted(device->connect_pending));
|
|
||||||
|
|
||||||
if (device->signal_agent) {
|
if (device->signal_agent) {
|
||||||
device_signal_agent_release(device->signal_agent,
|
device_signal_agent_release(device->signal_agent,
|
||||||
netdev_get_path(device->netdev));
|
netdev_get_path(device->netdev));
|
||||||
|
133
src/station.c
133
src/station.c
@ -201,7 +201,7 @@ struct network *station_network_find(struct station *station, const char *ssid,
|
|||||||
/*
|
/*
|
||||||
* Returns the network object the BSS was added to or NULL if ignored.
|
* Returns the network object the BSS was added to or NULL if ignored.
|
||||||
*/
|
*/
|
||||||
struct network *station_add_seen_bss(struct station *station,
|
static struct network *station_add_seen_bss(struct station *station,
|
||||||
struct scan_bss *bss)
|
struct scan_bss *bss)
|
||||||
{
|
{
|
||||||
struct network *network;
|
struct network *network;
|
||||||
@ -1256,6 +1256,133 @@ void station_reset_connection_state(struct station *station)
|
|||||||
IWD_NETWORK_INTERFACE, "Connected");
|
IWD_NETWORK_INTERFACE, "Connected");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void station_hidden_network_scan_triggered(int err, void *user_data)
|
||||||
|
{
|
||||||
|
struct station *station = user_data;
|
||||||
|
|
||||||
|
l_debug("");
|
||||||
|
|
||||||
|
if (!err)
|
||||||
|
return;
|
||||||
|
|
||||||
|
dbus_pending_reply(&station->connect_pending,
|
||||||
|
dbus_error_failed(station->connect_pending));
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool station_hidden_network_scan_results(uint32_t wiphy_id,
|
||||||
|
uint32_t ifindex, int err,
|
||||||
|
struct l_queue *bss_list,
|
||||||
|
void *userdata)
|
||||||
|
{
|
||||||
|
struct station *station = userdata;
|
||||||
|
struct network *network_psk;
|
||||||
|
struct network *network_open;
|
||||||
|
struct network *network;
|
||||||
|
const char *ssid;
|
||||||
|
uint8_t ssid_len;
|
||||||
|
struct l_dbus_message *msg;
|
||||||
|
struct scan_bss *bss;
|
||||||
|
|
||||||
|
l_debug("");
|
||||||
|
|
||||||
|
msg = station->connect_pending;
|
||||||
|
station->connect_pending = NULL;
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
dbus_pending_reply(&msg, dbus_error_failed(msg));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!l_dbus_message_get_arguments(msg, "s", &ssid)) {
|
||||||
|
dbus_pending_reply(&msg, dbus_error_invalid_args(msg));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssid_len = strlen(ssid);
|
||||||
|
|
||||||
|
while ((bss = l_queue_pop_head(bss_list))) {
|
||||||
|
if (bss->ssid_len != ssid_len ||
|
||||||
|
memcmp(bss->ssid, ssid, ssid_len))
|
||||||
|
goto next;
|
||||||
|
|
||||||
|
if (station_add_seen_bss(station, bss)) {
|
||||||
|
l_queue_push_tail(station->bss_list, bss);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
next:
|
||||||
|
scan_bss_free(bss);
|
||||||
|
}
|
||||||
|
|
||||||
|
l_queue_destroy(bss_list, NULL);
|
||||||
|
|
||||||
|
network_psk = station_network_find(station, ssid, SECURITY_PSK);
|
||||||
|
network_open = station_network_find(station, ssid, SECURITY_NONE);
|
||||||
|
|
||||||
|
if (!network_psk && !network_open) {
|
||||||
|
dbus_pending_reply(&msg, dbus_error_not_found(msg));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (network_psk && network_open) {
|
||||||
|
dbus_pending_reply(&msg, dbus_error_service_set_overlap(msg));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
network = network_psk ? : network_open;
|
||||||
|
|
||||||
|
network_connect_new_hidden_network(network, msg);
|
||||||
|
l_dbus_message_unref(msg);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct l_dbus_message *station_dbus_connect_hidden_network(
|
||||||
|
struct l_dbus *dbus,
|
||||||
|
struct l_dbus_message *message,
|
||||||
|
void *user_data)
|
||||||
|
{
|
||||||
|
struct station *station = user_data;
|
||||||
|
uint32_t index = netdev_get_ifindex(station->netdev);
|
||||||
|
struct scan_parameters params = {
|
||||||
|
.flush = true,
|
||||||
|
.randomize_mac_addr_hint = true,
|
||||||
|
};
|
||||||
|
const char *ssid;
|
||||||
|
|
||||||
|
l_debug("");
|
||||||
|
|
||||||
|
if (station->connect_pending || station_is_busy(station))
|
||||||
|
return dbus_error_busy(message);
|
||||||
|
|
||||||
|
if (!l_dbus_message_get_arguments(message, "s", &ssid))
|
||||||
|
return dbus_error_invalid_args(message);
|
||||||
|
|
||||||
|
if (strlen(ssid) > 32)
|
||||||
|
return dbus_error_invalid_args(message);
|
||||||
|
|
||||||
|
if (known_networks_find(ssid, SECURITY_PSK) ||
|
||||||
|
known_networks_find(ssid, SECURITY_NONE))
|
||||||
|
return dbus_error_already_provisioned(message);
|
||||||
|
|
||||||
|
if (station_network_find(station, ssid, SECURITY_PSK) ||
|
||||||
|
station_network_find(station, ssid, SECURITY_NONE))
|
||||||
|
return dbus_error_not_hidden(message);
|
||||||
|
|
||||||
|
params.ssid = ssid;
|
||||||
|
|
||||||
|
if (!scan_active_full(index, ¶ms,
|
||||||
|
station_hidden_network_scan_triggered,
|
||||||
|
station_hidden_network_scan_results,
|
||||||
|
station, NULL))
|
||||||
|
return dbus_error_failed(message);
|
||||||
|
|
||||||
|
station->connect_pending = l_dbus_message_ref(message);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static void station_dbus_scan_triggered(int err, void *user_data)
|
static void station_dbus_scan_triggered(int err, void *user_data)
|
||||||
{
|
{
|
||||||
struct station *station = user_data;
|
struct station *station = user_data;
|
||||||
@ -1383,6 +1510,10 @@ void station_free(struct station *station)
|
|||||||
|
|
||||||
periodic_scan_stop(station);
|
periodic_scan_stop(station);
|
||||||
|
|
||||||
|
if (station->connect_pending)
|
||||||
|
dbus_pending_reply(&station->connect_pending,
|
||||||
|
dbus_error_aborted(station->connect_pending));
|
||||||
|
|
||||||
if (station->scan_pending)
|
if (station->scan_pending)
|
||||||
dbus_pending_reply(&station->scan_pending,
|
dbus_pending_reply(&station->scan_pending,
|
||||||
dbus_error_aborted(station->scan_pending));
|
dbus_error_aborted(station->scan_pending));
|
||||||
|
@ -51,6 +51,7 @@ struct station {
|
|||||||
struct l_queue *bss_list;
|
struct l_queue *bss_list;
|
||||||
struct l_hashmap *networks;
|
struct l_hashmap *networks;
|
||||||
struct l_queue *networks_sorted;
|
struct l_queue *networks_sorted;
|
||||||
|
struct l_dbus_message *connect_pending;
|
||||||
struct l_dbus_message *scan_pending;
|
struct l_dbus_message *scan_pending;
|
||||||
|
|
||||||
/* Roaming related members */
|
/* Roaming related members */
|
||||||
@ -78,9 +79,6 @@ bool station_is_busy(struct station *station);
|
|||||||
struct network *station_network_find(struct station *station, const char *ssid,
|
struct network *station_network_find(struct station *station, const char *ssid,
|
||||||
enum security security);
|
enum security security);
|
||||||
|
|
||||||
struct network *station_add_seen_bss(struct station *station,
|
|
||||||
struct scan_bss *bss);
|
|
||||||
|
|
||||||
void station_set_scan_results(struct station *station, struct l_queue *bss_list,
|
void station_set_scan_results(struct station *station, struct l_queue *bss_list,
|
||||||
bool add_to_autoconnect);
|
bool add_to_autoconnect);
|
||||||
|
|
||||||
@ -111,6 +109,10 @@ void station_ok_rssi(struct station *station);
|
|||||||
|
|
||||||
void station_reset_connection_state(struct station *station);
|
void station_reset_connection_state(struct station *station);
|
||||||
|
|
||||||
|
struct l_dbus_message *station_dbus_connect_hidden_network(
|
||||||
|
struct l_dbus *dbus,
|
||||||
|
struct l_dbus_message *message,
|
||||||
|
void *user_data);
|
||||||
struct l_dbus_message *station_dbus_scan(struct l_dbus *dbus,
|
struct l_dbus_message *station_dbus_scan(struct l_dbus *dbus,
|
||||||
struct l_dbus_message *message,
|
struct l_dbus_message *message,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user