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

wsc: Add initial PushButton SM

This commit is contained in:
Denis Kenzior 2015-09-28 10:54:45 -05:00
parent 46a0c1db00
commit d0d509d864
3 changed files with 131 additions and 0 deletions

View File

@ -68,6 +68,7 @@ src_iwd_SOURCES = src/main.c linux/nl80211.h linux/kdbus.h \
src/storage.h src/storage.c \
src/network.h src/network.c \
src/wscutil.h src/wscutil.c \
src/wsc.h src/wsc.c \
iwd.h
src_iwd_LDADD = ell/libell-internal.la

100
src/wsc.c Normal file
View File

@ -0,0 +1,100 @@
/*
*
* Wireless daemon for Linux
*
* Copyright (C) 2015 Intel Corporation. All rights reserved.
*
* 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
#include <errno.h>
#include <ell/ell.h>
#include "scan.h"
#include "ie.h"
#include "wscutil.h"
#include "wsc.h"
#define WALK_TIME 120
struct wsc_sm {
uint8_t *wsc_ies;
size_t wsc_ies_size;
struct l_timeout *walk_timer;
};
struct wsc_sm *wsc_sm_new_pushbutton(uint32_t ifindex, const uint8_t *addr,
uint32_t bands)
{
static const uint8_t wfa_oui[] = { 0x00, 0x50, 0xF2 };
struct wsc_sm *sm;
struct wsc_probe_request req;
uint8_t *wsc_data;
size_t wsc_data_size;
memset(&req, 0, sizeof(req));
req.version2 = true;
req.request_type = WSC_REQUEST_TYPE_ENROLLEE_INFO;
/* TODO: Grab from configuration file ? */
req.config_methods = WSC_CONFIGURATION_METHOD_VIRTUAL_PUSH_BUTTON |
WSC_CONFIGURATION_METHOD_KEYPAD;
if (!wsc_uuid_from_addr(addr, req.uuid_e))
return NULL;
/* TODO: Grab from configuration file ? */
req.primary_device_type.category = 255;
memcpy(req.primary_device_type.oui, wfa_oui, 3);
req.primary_device_type.oui_type = 0x04;
req.primary_device_type.subcategory = 0;
if (bands & SCAN_BAND_2_4_GHZ)
req.rf_bands |= WSC_RF_BAND_2_4_GHZ;
if (bands & SCAN_BAND_5_GHZ)
req.rf_bands |= WSC_RF_BAND_5_0_GHZ;
req.association_state = WSC_ASSOCIATION_STATE_NOT_ASSOCIATED,
req.configuration_error = WSC_CONFIGURATION_ERROR_NO_ERROR,
req.device_password_id = WSC_DEVICE_PASSWORD_ID_PUSH_BUTTON,
req.request_to_enroll = true,
wsc_data = wsc_build_probe_request(&req, &wsc_data_size);
if (!wsc_data)
return NULL;
sm = l_new(struct wsc_sm, 1);
sm->wsc_ies = ie_tlv_encapsulate_wsc_payload(wsc_data, wsc_data_size,
&sm->wsc_ies_size);
l_free(wsc_data);
if (sm->wsc_ies) {
l_free(sm);
return NULL;
}
return sm;
}
void wsc_sm_free(struct wsc_sm *sm)
{
l_free(sm);
}

30
src/wsc.h Normal file
View File

@ -0,0 +1,30 @@
/*
*
* Wireless daemon for Linux
*
* Copyright (C) 2013-2015 Intel Corporation. All rights reserved.
*
* 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
*
*/
#include <stdbool.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);