mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-20 04:19:25 +01:00
netdev: Move disconnect event handling
.. out of wiphy.c
This commit is contained in:
parent
0eeb71e4eb
commit
64d382cc89
18
src/device.c
18
src/device.c
@ -192,6 +192,22 @@ static void device_lost_beacon(struct device *device)
|
||||
device_disassociated(device);
|
||||
}
|
||||
|
||||
static void device_disconnect_by_ap(struct device *device)
|
||||
{
|
||||
l_debug("%d", device->index);
|
||||
|
||||
if (device->connect_pending) {
|
||||
struct network *network = device->connected_network;
|
||||
|
||||
dbus_pending_reply(&device->connect_pending,
|
||||
dbus_error_failed(device->connect_pending));
|
||||
|
||||
network_connect_failed(network);
|
||||
}
|
||||
|
||||
device_disassociated(device);
|
||||
}
|
||||
|
||||
static void device_connect_cb(struct netdev *netdev, enum netdev_result result,
|
||||
void *user_data)
|
||||
{
|
||||
@ -240,6 +256,8 @@ static void device_netdev_event(struct netdev *netdev, enum netdev_event event,
|
||||
case NETDEV_EVENT_LOST_BEACON:
|
||||
device_lost_beacon(device);
|
||||
break;
|
||||
case NETDEV_EVENT_DISCONNECT_BY_AP:
|
||||
device_disconnect_by_ap(device);
|
||||
};
|
||||
}
|
||||
|
||||
|
46
src/netdev.c
46
src/netdev.c
@ -225,6 +225,49 @@ static void netdev_cqm_event(struct l_genl_msg *msg, struct netdev *netdev)
|
||||
}
|
||||
}
|
||||
|
||||
static void netdev_disconnect_event(struct l_genl_msg *msg,
|
||||
struct netdev *netdev)
|
||||
{
|
||||
struct l_genl_attr attr;
|
||||
uint16_t type, len;
|
||||
const void *data;
|
||||
uint16_t reason_code = 0;
|
||||
bool disconnect_by_ap = false;
|
||||
|
||||
l_debug("");
|
||||
|
||||
if (!l_genl_attr_init(&attr, msg)) {
|
||||
l_error("attr init failed");
|
||||
return;
|
||||
}
|
||||
|
||||
while (l_genl_attr_next(&attr, &type, &len, &data)) {
|
||||
switch (type) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
l_info("Received Deauthentication event, reason: %hu, from_ap: %s",
|
||||
reason_code, disconnect_by_ap ? "true" : "false");
|
||||
|
||||
if (!disconnect_by_ap)
|
||||
return;
|
||||
|
||||
if (netdev->event_filter)
|
||||
netdev->event_filter(netdev, NETDEV_EVENT_DISCONNECT_BY_AP,
|
||||
netdev->user_data);
|
||||
}
|
||||
|
||||
static void netdev_deauthenticate_event(struct l_genl_msg *msg,
|
||||
struct netdev *netdev)
|
||||
{
|
||||
@ -536,6 +579,9 @@ static void netdev_mlme_notify(struct l_genl_msg *msg, void *user_data)
|
||||
case NL80211_CMD_ASSOCIATE:
|
||||
netdev_associate_event(msg, netdev);
|
||||
break;
|
||||
case NL80211_CMD_DISCONNECT:
|
||||
netdev_disconnect_event(msg, netdev);
|
||||
break;
|
||||
case NL80211_CMD_NOTIFY_CQM:
|
||||
netdev_cqm_event(msg, netdev);
|
||||
break;
|
||||
|
@ -40,6 +40,7 @@ enum netdev_event {
|
||||
NETDEV_EVENT_4WAY_HANDSHAKE,
|
||||
NETDEV_EVENT_SETTING_KEYS,
|
||||
NETDEV_EVENT_LOST_BEACON,
|
||||
NETDEV_EVENT_DISCONNECT_BY_AP,
|
||||
};
|
||||
|
||||
typedef void (*netdev_command_func_t) (bool result, void *user_data);
|
||||
|
133
src/wiphy.c
133
src/wiphy.c
@ -412,14 +412,6 @@ static bool bss_match(const void *a, const void *b)
|
||||
return !memcmp(bss_a->addr, bss_b->addr, sizeof(bss_a->addr));
|
||||
}
|
||||
|
||||
static bool device_match(const void *a, const void *b)
|
||||
{
|
||||
const struct device *device = a;
|
||||
uint32_t index = L_PTR_TO_UINT(b);
|
||||
|
||||
return (device->index == index);
|
||||
}
|
||||
|
||||
static void device_autoconnect_next(struct device *device)
|
||||
{
|
||||
struct autoconnect_entry *entry;
|
||||
@ -805,56 +797,6 @@ static void wiphy_set_gtk(uint32_t ifindex, uint8_t key_index,
|
||||
gtk_buf, gtk_len, rsc, rsc_len);
|
||||
}
|
||||
|
||||
static void mlme_disconnect_event(struct l_genl_msg *msg,
|
||||
struct device *device)
|
||||
{
|
||||
struct l_genl_attr attr;
|
||||
uint16_t type, len;
|
||||
const void *data;
|
||||
uint16_t reason_code = 0;
|
||||
bool disconnect_by_ap = false;
|
||||
|
||||
l_debug("");
|
||||
|
||||
if (!l_genl_attr_init(&attr, msg)) {
|
||||
l_error("attr init failed");
|
||||
return;
|
||||
}
|
||||
|
||||
while (l_genl_attr_next(&attr, &type, &len, &data)) {
|
||||
switch (type) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
l_info("Received Deauthentication event, reason: %hu, from_ap: %s",
|
||||
reason_code, disconnect_by_ap ? "true" : "false");
|
||||
|
||||
if (!disconnect_by_ap)
|
||||
return;
|
||||
|
||||
if (device->connect_pending) {
|
||||
struct network *network = device->connected_network;
|
||||
|
||||
dbus_pending_reply(&device->connect_pending,
|
||||
dbus_error_failed(device->connect_pending));
|
||||
|
||||
network_connect_failed(network);
|
||||
}
|
||||
|
||||
device_disassociated(device);
|
||||
}
|
||||
|
||||
static bool process_network(const void *key, void *data, void *user_data)
|
||||
{
|
||||
struct network *network = data;
|
||||
@ -1404,77 +1346,6 @@ static void wiphy_config_notify(struct l_genl_msg *msg, void *user_data)
|
||||
}
|
||||
}
|
||||
|
||||
static void wiphy_mlme_notify(struct l_genl_msg *msg, void *user_data)
|
||||
{
|
||||
struct wiphy *wiphy = NULL;
|
||||
struct device *device = NULL;
|
||||
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)) {
|
||||
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;
|
||||
}
|
||||
|
||||
device = l_queue_find(device_list, device_match,
|
||||
L_UINT_TO_PTR(*((uint32_t *) data)));
|
||||
if (!device) {
|
||||
l_warn("No interface structure found");
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!wiphy) {
|
||||
l_warn("MLME notification is missing wiphy attribute");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!device) {
|
||||
l_warn("MLME notification is missing interface attribute");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
switch (cmd) {
|
||||
case NL80211_CMD_DISCONNECT:
|
||||
mlme_disconnect_event(msg, device);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void wiphy_regulatory_notify(struct l_genl_msg *msg, void *user_data)
|
||||
{
|
||||
struct l_genl_attr attr;
|
||||
@ -1568,10 +1439,6 @@ bool wiphy_init(struct l_genl_family *in)
|
||||
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");
|
||||
|
Loading…
Reference in New Issue
Block a user