mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-12-30 06:02:39 +01:00
wsc: Squash wsc_sm structure
eap-wsc now handles most of the details
This commit is contained in:
parent
c60d34cd8d
commit
1627b3a2bd
79
src/wsc.c
79
src/wsc.c
@ -43,24 +43,19 @@
|
|||||||
static struct l_genl_family *nl80211 = NULL;
|
static struct l_genl_family *nl80211 = NULL;
|
||||||
static uint32_t device_watch = 0;
|
static uint32_t device_watch = 0;
|
||||||
|
|
||||||
struct wsc_sm {
|
struct wsc {
|
||||||
uint32_t ifindex;
|
struct device *device;
|
||||||
|
struct l_dbus_message *pending;
|
||||||
uint8_t *wsc_ies;
|
uint8_t *wsc_ies;
|
||||||
size_t wsc_ies_size;
|
size_t wsc_ies_size;
|
||||||
struct l_timeout *walk_timer;
|
struct l_timeout *walk_timer;
|
||||||
uint32_t scan_id;
|
uint32_t scan_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wsc {
|
|
||||||
struct device *device;
|
|
||||||
struct l_dbus_message *pending;
|
|
||||||
struct wsc_sm *sm;
|
|
||||||
};
|
|
||||||
|
|
||||||
static bool scan_results(uint32_t wiphy_id, uint32_t ifindex,
|
static bool scan_results(uint32_t wiphy_id, uint32_t ifindex,
|
||||||
struct l_queue *bss_list, void *userdata)
|
struct l_queue *bss_list, void *userdata)
|
||||||
{
|
{
|
||||||
struct wsc_sm *sm = userdata;
|
struct wsc *wsc = userdata;
|
||||||
struct scan_bss *bss_2g;
|
struct scan_bss *bss_2g;
|
||||||
struct scan_bss *bss_5g;
|
struct scan_bss *bss_5g;
|
||||||
struct scan_bss *target;
|
struct scan_bss *target;
|
||||||
@ -72,7 +67,7 @@ static bool scan_results(uint32_t wiphy_id, uint32_t ifindex,
|
|||||||
bss_2g = NULL;
|
bss_2g = NULL;
|
||||||
bss_5g = NULL;
|
bss_5g = NULL;
|
||||||
|
|
||||||
sm->scan_id = 0;
|
wsc->scan_id = 0;
|
||||||
|
|
||||||
for (bss_entry = l_queue_get_entries(bss_list); bss_entry;
|
for (bss_entry = l_queue_get_entries(bss_list); bss_entry;
|
||||||
bss_entry = bss_entry->next) {
|
bss_entry = bss_entry->next) {
|
||||||
@ -147,9 +142,9 @@ static bool scan_results(uint32_t wiphy_id, uint32_t ifindex,
|
|||||||
target = bss_2g;
|
target = bss_2g;
|
||||||
else {
|
else {
|
||||||
l_debug("No PBC APs found, running the scan again");
|
l_debug("No PBC APs found, running the scan again");
|
||||||
sm->scan_id = scan_active(sm->ifindex,
|
wsc->scan_id = scan_active(device_get_ifindex(wsc->device),
|
||||||
sm->wsc_ies, sm->wsc_ies_size,
|
wsc->wsc_ies, wsc->wsc_ies_size,
|
||||||
NULL, scan_results, sm, NULL);
|
NULL, scan_results, wsc, NULL);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,12 +154,12 @@ static bool scan_results(uint32_t wiphy_id, uint32_t ifindex,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct wsc_sm *wsc_sm_new_pushbutton(uint32_t ifindex, const uint8_t *addr,
|
static bool wsc_start_pushbutton(struct wsc *wsc)
|
||||||
uint32_t bands)
|
|
||||||
{
|
{
|
||||||
static const uint8_t wfa_oui[] = { 0x00, 0x50, 0xF2 };
|
static const uint8_t wfa_oui[] = { 0x00, 0x50, 0xF2 };
|
||||||
struct wsc_sm *sm;
|
|
||||||
struct wsc_probe_request req;
|
struct wsc_probe_request req;
|
||||||
|
struct wiphy *wiphy = device_get_wiphy(wsc->device);
|
||||||
|
uint32_t bands;
|
||||||
uint8_t *wsc_data;
|
uint8_t *wsc_data;
|
||||||
size_t wsc_data_size;
|
size_t wsc_data_size;
|
||||||
|
|
||||||
@ -177,8 +172,8 @@ struct wsc_sm *wsc_sm_new_pushbutton(uint32_t ifindex, const uint8_t *addr,
|
|||||||
req.config_methods = WSC_CONFIGURATION_METHOD_VIRTUAL_PUSH_BUTTON |
|
req.config_methods = WSC_CONFIGURATION_METHOD_VIRTUAL_PUSH_BUTTON |
|
||||||
WSC_CONFIGURATION_METHOD_KEYPAD;
|
WSC_CONFIGURATION_METHOD_KEYPAD;
|
||||||
|
|
||||||
if (!wsc_uuid_from_addr(addr, req.uuid_e))
|
if (!wsc_uuid_from_addr(device_get_address(wsc->device), req.uuid_e))
|
||||||
return NULL;
|
return false;
|
||||||
|
|
||||||
/* TODO: Grab from configuration file ? */
|
/* TODO: Grab from configuration file ? */
|
||||||
req.primary_device_type.category = 255;
|
req.primary_device_type.category = 255;
|
||||||
@ -186,6 +181,7 @@ struct wsc_sm *wsc_sm_new_pushbutton(uint32_t ifindex, const uint8_t *addr,
|
|||||||
req.primary_device_type.oui_type = 0x04;
|
req.primary_device_type.oui_type = 0x04;
|
||||||
req.primary_device_type.subcategory = 0;
|
req.primary_device_type.subcategory = 0;
|
||||||
|
|
||||||
|
bands = wiphy_get_supported_bands(wiphy);
|
||||||
if (bands & SCAN_BAND_2_4_GHZ)
|
if (bands & SCAN_BAND_2_4_GHZ)
|
||||||
req.rf_bands |= WSC_RF_BAND_2_4_GHZ;
|
req.rf_bands |= WSC_RF_BAND_2_4_GHZ;
|
||||||
if (bands & SCAN_BAND_5_GHZ)
|
if (bands & SCAN_BAND_5_GHZ)
|
||||||
@ -198,35 +194,30 @@ struct wsc_sm *wsc_sm_new_pushbutton(uint32_t ifindex, const uint8_t *addr,
|
|||||||
|
|
||||||
wsc_data = wsc_build_probe_request(&req, &wsc_data_size);
|
wsc_data = wsc_build_probe_request(&req, &wsc_data_size);
|
||||||
if (!wsc_data)
|
if (!wsc_data)
|
||||||
return NULL;
|
return false;
|
||||||
|
|
||||||
sm = l_new(struct wsc_sm, 1);
|
wsc->wsc_ies = ie_tlv_encapsulate_wsc_payload(wsc_data, wsc_data_size,
|
||||||
sm->wsc_ies = ie_tlv_encapsulate_wsc_payload(wsc_data, wsc_data_size,
|
&wsc->wsc_ies_size);
|
||||||
&sm->wsc_ies_size);
|
|
||||||
l_free(wsc_data);
|
l_free(wsc_data);
|
||||||
|
|
||||||
if (!sm->wsc_ies) {
|
if (!wsc->wsc_ies)
|
||||||
l_free(sm);
|
return false;
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
sm->ifindex = ifindex;
|
wsc->scan_id = scan_active(device_get_ifindex(wsc->device),
|
||||||
sm->scan_id = scan_active(ifindex, sm->wsc_ies, sm->wsc_ies_size,
|
wsc->wsc_ies, wsc->wsc_ies_size,
|
||||||
NULL, scan_results, sm, NULL);
|
NULL, scan_results, wsc, NULL);
|
||||||
|
return true;
|
||||||
return sm;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wsc_sm_free(struct wsc_sm *sm)
|
static void wsc_abort(struct wsc *wsc)
|
||||||
{
|
{
|
||||||
l_free(sm->wsc_ies);
|
l_free(wsc->wsc_ies);
|
||||||
|
wsc->wsc_ies = 0;
|
||||||
|
|
||||||
if (sm->scan_id > 0) {
|
if (wsc->scan_id > 0) {
|
||||||
scan_cancel(sm->ifindex, sm->scan_id);
|
scan_cancel(device_get_ifindex(wsc->device), wsc->scan_id);
|
||||||
sm->scan_id = 0;
|
wsc->scan_id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
l_free(sm);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct l_dbus_message *wsc_push_button(struct l_dbus *dbus,
|
static struct l_dbus_message *wsc_push_button(struct l_dbus *dbus,
|
||||||
@ -240,10 +231,8 @@ static struct l_dbus_message *wsc_push_button(struct l_dbus *dbus,
|
|||||||
if (wsc->pending)
|
if (wsc->pending)
|
||||||
return dbus_error_busy(message);
|
return dbus_error_busy(message);
|
||||||
|
|
||||||
/* TODO: Parse wiphy bands to set the RF Bands properly below */
|
if (!wsc_start_pushbutton(wsc))
|
||||||
wsc->sm = wsc_sm_new_pushbutton(device_get_ifindex(wsc->device),
|
return dbus_error_failed(message);
|
||||||
device_get_address(wsc->device),
|
|
||||||
SCAN_BAND_2_4_GHZ | SCAN_BAND_5_GHZ);
|
|
||||||
|
|
||||||
wsc->pending = l_dbus_message_ref(message);
|
wsc->pending = l_dbus_message_ref(message);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -266,8 +255,7 @@ static struct l_dbus_message *wsc_cancel(struct l_dbus *dbus,
|
|||||||
|
|
||||||
dbus_pending_reply(&wsc->pending, dbus_error_aborted(wsc->pending));
|
dbus_pending_reply(&wsc->pending, dbus_error_aborted(wsc->pending));
|
||||||
|
|
||||||
wsc_sm_free(wsc->sm);
|
wsc_abort(wsc);
|
||||||
wsc->sm = NULL;
|
|
||||||
|
|
||||||
return reply;
|
return reply;
|
||||||
}
|
}
|
||||||
@ -288,8 +276,7 @@ static void wsc_free(void *userdata)
|
|||||||
dbus_pending_reply(&wsc->pending,
|
dbus_pending_reply(&wsc->pending,
|
||||||
dbus_error_not_available(wsc->pending));
|
dbus_error_not_available(wsc->pending));
|
||||||
|
|
||||||
wsc_sm_free(wsc->sm);
|
wsc_abort(wsc);
|
||||||
wsc->sm = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
l_free(wsc);
|
l_free(wsc);
|
||||||
|
@ -23,11 +23,5 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
struct wsc_sm;
|
|
||||||
|
|
||||||
struct wsc_sm *wsc_sm_new_pushbutton(uint32_t ifindex, const uint8_t *addr,
|
|
||||||
uint32_t bands);
|
|
||||||
void wsc_sm_free(struct wsc_sm *wsc_sm);
|
|
||||||
|
|
||||||
bool wsc_init(struct l_genl_family *in);
|
bool wsc_init(struct l_genl_family *in);
|
||||||
bool wsc_exit();
|
bool wsc_exit();
|
||||||
|
Loading…
Reference in New Issue
Block a user