iwd/src/wsc.c

121 lines
2.8 KiB
C
Raw Normal View History

2015-09-28 17:54:45 +02:00
/*
*
* 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
2015-09-29 03:38:17 +02:00
static struct l_genl_family *nl80211 = NULL;
2015-09-28 17:54:45 +02:00
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);
}
2015-09-29 03:38:17 +02:00
bool wsc_init(struct l_genl_family *in)
{
nl80211 = in;
return true;
}
bool wsc_exit()
{
l_debug("");
if (!nl80211)
return false;
nl80211 = 0;
return true;
}