3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-12-22 04:32:37 +01:00

wsc: Make WSC netdev centric

This commit is contained in:
Denis Kenzior 2018-08-19 23:28:07 -05:00
parent 2e0638d51b
commit e068c97409

View File

@ -49,7 +49,8 @@
static uint32_t netdev_watch = 0; static uint32_t netdev_watch = 0;
struct wsc { struct wsc {
struct device *device; struct netdev *netdev;
struct device *device; /* TODO: Should be Station */
struct l_dbus_message *pending; struct l_dbus_message *pending;
struct l_dbus_message *pending_cancel; struct l_dbus_message *pending_cancel;
uint8_t *wsc_ies; uint8_t *wsc_ies;
@ -206,7 +207,7 @@ static void wsc_connect_cb(struct netdev *netdev, enum netdev_result result,
{ {
struct wsc *wsc = user_data; struct wsc *wsc = user_data;
l_debug("%d, result: %d", device_get_ifindex(wsc->device), result); l_debug("%d, result: %d", netdev_get_ifindex(wsc->netdev), result);
wsc->wsc_association = false; wsc->wsc_association = false;
@ -370,7 +371,7 @@ static void wsc_netdev_event(struct netdev *netdev, enum netdev_event event,
break; break;
case NETDEV_EVENT_DISCONNECT_BY_AP: case NETDEV_EVENT_DISCONNECT_BY_AP:
l_debug("Disconnect by AP"); l_debug("Disconnect by AP");
wsc_connect_cb(device_get_netdev(wsc->device), wsc_connect_cb(wsc->netdev,
NETDEV_RESULT_HANDSHAKE_FAILED, wsc); NETDEV_RESULT_HANDSHAKE_FAILED, wsc);
break; break;
case NETDEV_EVENT_RSSI_THRESHOLD_LOW: case NETDEV_EVENT_RSSI_THRESHOLD_LOW:
@ -418,7 +419,7 @@ static void wsc_connect(struct wsc *wsc)
wsc->target = NULL; wsc->target = NULL;
hs = netdev_handshake_state_new(device_get_netdev(wsc->device)); hs = netdev_handshake_state_new(wsc->netdev);
l_settings_set_string(settings, "Security", "EAP-Identity", l_settings_set_string(settings, "Security", "EAP-Identity",
"WFA-SimpleConfig-Enrollee-1-0"); "WFA-SimpleConfig-Enrollee-1-0");
@ -433,7 +434,7 @@ static void wsc_connect(struct wsc *wsc)
l_settings_set_string(settings, "WSC", "PrimaryDeviceType", l_settings_set_string(settings, "WSC", "PrimaryDeviceType",
"0-00000000-0"); "0-00000000-0");
l_settings_set_string(settings, "WSC", "EnrolleeMAC", l_settings_set_string(settings, "WSC", "EnrolleeMAC",
util_address_to_string(device_get_address(wsc->device))); util_address_to_string(netdev_get_address(wsc->netdev)));
if (!strcmp(l_dbus_message_get_member(wsc->pending), "StartPin")) { if (!strcmp(l_dbus_message_get_member(wsc->pending), "StartPin")) {
const char *pin; const char *pin;
@ -457,7 +458,7 @@ static void wsc_connect(struct wsc *wsc)
handshake_state_set_8021x_config(hs, settings); handshake_state_set_8021x_config(hs, settings);
wsc->eap_settings = settings; wsc->eap_settings = settings;
if (netdev_connect_wsc(device_get_netdev(wsc->device), bss, hs, if (netdev_connect_wsc(wsc->netdev, bss, hs,
wsc_netdev_event, wsc_connect_cb, wsc_netdev_event, wsc_connect_cb,
wsc_eapol_event, wsc) < 0) { wsc_eapol_event, wsc) < 0) {
dbus_pending_reply(&wsc->pending, dbus_pending_reply(&wsc->pending,
@ -526,7 +527,7 @@ static void wsc_cancel_scan(struct wsc *wsc)
wsc->wsc_ies = 0; wsc->wsc_ies = 0;
if (wsc->scan_id > 0) { if (wsc->scan_id > 0) {
scan_cancel(device_get_ifindex(wsc->device), wsc->scan_id); scan_cancel(netdev_get_ifindex(wsc->netdev), wsc->scan_id);
wsc->scan_id = 0; wsc->scan_id = 0;
} }
@ -657,7 +658,7 @@ static bool push_button_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");
wsc->scan_id = scan_active(device_get_ifindex(wsc->device), wsc->scan_id = scan_active(netdev_get_ifindex(wsc->netdev),
wsc->wsc_ies, wsc->wsc_ies_size, wsc->wsc_ies, wsc->wsc_ies_size,
NULL, push_button_scan_results, NULL, push_button_scan_results,
wsc, NULL); wsc, NULL);
@ -794,7 +795,7 @@ static bool pin_scan_results(uint32_t wiphy_id, uint32_t ifindex, int err,
l_debug("AuthorizedMacs: %s", authorized_macs_to_string(amacs)); l_debug("AuthorizedMacs: %s", authorized_macs_to_string(amacs));
if (authorized_macs_contains(amacs, if (authorized_macs_contains(amacs,
device_get_address(wsc->device))) { netdev_get_address(wsc->netdev))) {
target = bss; target = bss;
break; break;
} else if (!target && authorized_macs_contains(amacs, } else if (!target && authorized_macs_contains(amacs,
@ -804,7 +805,7 @@ static bool pin_scan_results(uint32_t wiphy_id, uint32_t ifindex, int err,
if (!target) { if (!target) {
l_debug("No PIN APs found, running the scan again"); l_debug("No PIN APs found, running the scan again");
wsc->scan_id = scan_active(device_get_ifindex(wsc->device), wsc->scan_id = scan_active(netdev_get_ifindex(wsc->netdev),
wsc->wsc_ies, wsc->wsc_ies_size, wsc->wsc_ies, wsc->wsc_ies_size,
NULL, pin_scan_results, NULL, pin_scan_results,
wsc, NULL); wsc, NULL);
@ -827,7 +828,7 @@ static bool wsc_initiate_scan(struct wsc *wsc,
{ {
static const uint8_t wfa_oui[] = { 0x00, 0x50, 0xF2 }; static const uint8_t wfa_oui[] = { 0x00, 0x50, 0xF2 };
struct wsc_probe_request req; struct wsc_probe_request req;
struct wiphy *wiphy = device_get_wiphy(wsc->device); struct wiphy *wiphy = netdev_get_wiphy(wsc->netdev);
uint32_t bands; uint32_t bands;
uint8_t *wsc_data; uint8_t *wsc_data;
size_t wsc_data_size; size_t wsc_data_size;
@ -841,7 +842,7 @@ static bool wsc_initiate_scan(struct wsc *wsc,
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(device_get_address(wsc->device), req.uuid_e)) if (!wsc_uuid_from_addr(netdev_get_address(wsc->netdev), req.uuid_e))
return false; return false;
/* TODO: Grab from configuration file ? */ /* TODO: Grab from configuration file ? */
@ -872,7 +873,7 @@ static bool wsc_initiate_scan(struct wsc *wsc,
if (!wsc->wsc_ies) if (!wsc->wsc_ies)
return false; return false;
wsc->scan_id = scan_active(device_get_ifindex(wsc->device), wsc->scan_id = scan_active(netdev_get_ifindex(wsc->netdev),
wsc->wsc_ies, wsc->wsc_ies_size, wsc->wsc_ies, wsc->wsc_ies_size,
NULL, callback, wsc, NULL); NULL, callback, wsc, NULL);
if (!wsc->scan_id) { if (!wsc->scan_id) {
@ -984,8 +985,7 @@ static struct l_dbus_message *wsc_cancel(struct l_dbus *dbus,
if (wsc->wsc_association) { if (wsc->wsc_association) {
int r; int r;
r = netdev_disconnect(device_get_netdev(wsc->device), r = netdev_disconnect(wsc->netdev, wsc_disconnect_cb, wsc);
wsc_disconnect_cb, wsc);
if (r == 0) { if (r == 0) {
wsc->pending_cancel = l_dbus_message_ref(message); wsc->pending_cancel = l_dbus_message_ref(message);
return NULL; return NULL;
@ -1041,15 +1041,16 @@ static void wsc_free(void *userdata)
l_free(wsc); l_free(wsc);
} }
static void wsc_add_interface(struct device *device) static void wsc_add_interface(struct netdev *netdev)
{ {
struct l_dbus *dbus = dbus_get_bus(); struct l_dbus *dbus = dbus_get_bus();
struct wsc *wsc; struct wsc *wsc;
wsc = l_new(struct wsc, 1); wsc = l_new(struct wsc, 1);
wsc->device = device; wsc->netdev = netdev;
wsc->device = netdev_get_device(netdev);
if (!l_dbus_object_add_interface(dbus, device_get_path(device), if (!l_dbus_object_add_interface(dbus, netdev_get_path(netdev),
IWD_WSC_INTERFACE, IWD_WSC_INTERFACE,
wsc)) { wsc)) {
wsc_free(wsc); wsc_free(wsc);
@ -1057,11 +1058,11 @@ static void wsc_add_interface(struct device *device)
} }
} }
static void wsc_remove_interface(struct device *device) static void wsc_remove_interface(struct netdev *netdev)
{ {
struct l_dbus *dbus = dbus_get_bus(); struct l_dbus *dbus = dbus_get_bus();
l_dbus_object_remove_interface(dbus, device_get_path(device), l_dbus_object_remove_interface(dbus, netdev_get_path(netdev),
IWD_WSC_INTERFACE); IWD_WSC_INTERFACE);
} }
@ -1077,11 +1078,11 @@ static void wsc_netdev_watch(struct netdev *netdev,
case NETDEV_WATCH_EVENT_UP: case NETDEV_WATCH_EVENT_UP:
case NETDEV_WATCH_EVENT_NEW: case NETDEV_WATCH_EVENT_NEW:
if (netdev_get_iftype(netdev) == NETDEV_IFTYPE_STATION) if (netdev_get_iftype(netdev) == NETDEV_IFTYPE_STATION)
wsc_add_interface(device); wsc_add_interface(netdev);
break; break;
case NETDEV_WATCH_EVENT_DOWN: case NETDEV_WATCH_EVENT_DOWN:
case NETDEV_WATCH_EVENT_DEL: case NETDEV_WATCH_EVENT_DEL:
wsc_remove_interface(device); wsc_remove_interface(netdev);
break; break;
default: default:
break; break;