resolve merge conflicts
MFC after: 3 weeks
This commit is contained in:
parent
52cae81516
commit
7e30ef1bec
@ -266,12 +266,12 @@ enum { MSG_MSGDUMP, MSG_DEBUG, MSG_INFO, MSG_WARNING, MSG_ERROR };
|
||||
#define wpa_hexdump_key(l,t,b,le) do { } while (0)
|
||||
#define wpa_hexdump_ascii(l,t,b,le) do { } while (0)
|
||||
#define wpa_hexdump_ascii_key(l,t,b,le) do { } while (0)
|
||||
#define wpa_debug_open_file() do { } while (0)
|
||||
#define wpa_debug_open_file(p) do { } while (0)
|
||||
#define wpa_debug_close_file() do { } while (0)
|
||||
|
||||
#else /* CONFIG_NO_STDOUT_DEBUG */
|
||||
|
||||
int wpa_debug_open_file(void);
|
||||
int wpa_debug_open_file(const char *path);
|
||||
void wpa_debug_close_file(void);
|
||||
|
||||
/**
|
||||
|
@ -1,882 +0,0 @@
|
||||
/*
|
||||
* WPA Supplicant / Configuration backend: Windows registry
|
||||
* Copyright (c) 2003-2006, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*
|
||||
* This file implements a configuration backend for Windows registry.. All the
|
||||
* configuration information is stored in the registry and the format for
|
||||
* network configuration fields is same as described in the sample
|
||||
* configuration file, wpa_supplicant.conf.
|
||||
*
|
||||
* Configuration data is in HKEY_LOCAL_MACHINE\SOFTWARE\wpa_supplicant\configs
|
||||
* key. Each configuration profile has its own key under this. In terms of text
|
||||
* files, each profile would map to a separate text file with possibly multiple
|
||||
* networks. Under each profile, there is a networks key that lists all
|
||||
* networks as a subkey. Each network has set of values in the same way as
|
||||
* network block in the configuration file. In addition, blobs subkey has
|
||||
* possible blobs as values.
|
||||
*
|
||||
* HKEY_LOCAL_MACHINE\SOFTWARE\wpa_supplicant\configs\test\networks\0000
|
||||
* ssid="example"
|
||||
* key_mgmt=WPA-PSK
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
|
||||
#include "common.h"
|
||||
#include "config.h"
|
||||
|
||||
#ifndef WPA_KEY_ROOT
|
||||
#define WPA_KEY_ROOT HKEY_LOCAL_MACHINE
|
||||
#endif
|
||||
#ifndef WPA_KEY_PREFIX
|
||||
#define WPA_KEY_PREFIX TEXT("SOFTWARE\\wpa_supplicant")
|
||||
#endif
|
||||
|
||||
#ifdef UNICODE
|
||||
#define TSTR "%S"
|
||||
#else /* UNICODE */
|
||||
#define TSTR "%s"
|
||||
#endif /* UNICODE */
|
||||
|
||||
|
||||
static int wpa_config_read_blobs(struct wpa_config *config, HKEY hk)
|
||||
{
|
||||
struct wpa_config_blob *blob;
|
||||
int errors = 0;
|
||||
HKEY bhk;
|
||||
LONG ret;
|
||||
DWORD i;
|
||||
|
||||
ret = RegOpenKeyEx(hk, TEXT("blobs"), 0, KEY_QUERY_VALUE, &bhk);
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
wpa_printf(MSG_DEBUG, "Could not open wpa_supplicant config "
|
||||
"blobs key");
|
||||
return 0; /* assume no blobs */
|
||||
}
|
||||
|
||||
for (i = 0; ; i++) {
|
||||
#define TNAMELEN 255
|
||||
TCHAR name[TNAMELEN];
|
||||
char data[4096];
|
||||
DWORD namelen, datalen, type;
|
||||
|
||||
namelen = TNAMELEN;
|
||||
datalen = sizeof(data);
|
||||
ret = RegEnumValue(bhk, i, name, &namelen, NULL, &type,
|
||||
(LPBYTE) data, &datalen);
|
||||
|
||||
if (ret == ERROR_NO_MORE_ITEMS)
|
||||
break;
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
wpa_printf(MSG_DEBUG, "RegEnumValue failed: 0x%x",
|
||||
(unsigned int) ret);
|
||||
break;
|
||||
}
|
||||
|
||||
if (namelen >= TNAMELEN)
|
||||
namelen = TNAMELEN - 1;
|
||||
name[namelen] = TEXT('\0');
|
||||
wpa_unicode2ascii_inplace(name);
|
||||
|
||||
if (datalen >= sizeof(data))
|
||||
datalen = sizeof(data) - 1;
|
||||
|
||||
wpa_printf(MSG_MSGDUMP, "blob %d: field='%s' len %d",
|
||||
(int) i, name, (int) datalen);
|
||||
|
||||
blob = os_zalloc(sizeof(*blob));
|
||||
if (blob == NULL) {
|
||||
errors++;
|
||||
break;
|
||||
}
|
||||
blob->name = os_strdup((char *) name);
|
||||
blob->data = os_malloc(datalen);
|
||||
if (blob->name == NULL || blob->data == NULL) {
|
||||
wpa_config_free_blob(blob);
|
||||
errors++;
|
||||
break;
|
||||
}
|
||||
os_memcpy(blob->data, data, datalen);
|
||||
blob->len = datalen;
|
||||
|
||||
wpa_config_set_blob(config, blob);
|
||||
}
|
||||
|
||||
RegCloseKey(bhk);
|
||||
|
||||
return errors ? -1 : 0;
|
||||
}
|
||||
|
||||
|
||||
static int wpa_config_read_reg_dword(HKEY hk, const TCHAR *name, int *_val)
|
||||
{
|
||||
DWORD val, buflen;
|
||||
LONG ret;
|
||||
|
||||
buflen = sizeof(val);
|
||||
ret = RegQueryValueEx(hk, name, NULL, NULL, (LPBYTE) &val, &buflen);
|
||||
if (ret == ERROR_SUCCESS && buflen == sizeof(val)) {
|
||||
wpa_printf(MSG_DEBUG, TSTR "=%d", name, (int) val);
|
||||
*_val = val;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
static char * wpa_config_read_reg_string(HKEY hk, const TCHAR *name)
|
||||
{
|
||||
DWORD buflen;
|
||||
LONG ret;
|
||||
TCHAR *val;
|
||||
|
||||
buflen = 0;
|
||||
ret = RegQueryValueEx(hk, name, NULL, NULL, NULL, &buflen);
|
||||
if (ret != ERROR_SUCCESS)
|
||||
return NULL;
|
||||
val = os_malloc(buflen);
|
||||
if (val == NULL)
|
||||
return NULL;
|
||||
|
||||
ret = RegQueryValueEx(hk, name, NULL, NULL, (LPBYTE) val, &buflen);
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
os_free(val);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wpa_unicode2ascii_inplace(val);
|
||||
wpa_printf(MSG_DEBUG, TSTR "=%s", name, (char *) val);
|
||||
return (char *) val;
|
||||
}
|
||||
|
||||
|
||||
static int wpa_config_read_global(struct wpa_config *config, HKEY hk)
|
||||
{
|
||||
int errors = 0;
|
||||
|
||||
wpa_config_read_reg_dword(hk, TEXT("ap_scan"), &config->ap_scan);
|
||||
wpa_config_read_reg_dword(hk, TEXT("fast_reauth"),
|
||||
&config->fast_reauth);
|
||||
wpa_config_read_reg_dword(hk, TEXT("dot11RSNAConfigPMKLifetime"),
|
||||
&config->dot11RSNAConfigPMKLifetime);
|
||||
wpa_config_read_reg_dword(hk,
|
||||
TEXT("dot11RSNAConfigPMKReauthThreshold"),
|
||||
&config->dot11RSNAConfigPMKReauthThreshold);
|
||||
wpa_config_read_reg_dword(hk, TEXT("dot11RSNAConfigSATimeout"),
|
||||
&config->dot11RSNAConfigSATimeout);
|
||||
wpa_config_read_reg_dword(hk, TEXT("update_config"),
|
||||
&config->update_config);
|
||||
|
||||
if (wpa_config_read_reg_dword(hk, TEXT("eapol_version"),
|
||||
&config->eapol_version) == 0) {
|
||||
if (config->eapol_version < 1 ||
|
||||
config->eapol_version > 2) {
|
||||
wpa_printf(MSG_ERROR, "Invalid EAPOL version (%d)",
|
||||
config->eapol_version);
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
|
||||
config->ctrl_interface = wpa_config_read_reg_string(
|
||||
hk, TEXT("ctrl_interface"));
|
||||
|
||||
return errors ? -1 : 0;
|
||||
}
|
||||
|
||||
|
||||
static struct wpa_ssid * wpa_config_read_network(HKEY hk, const TCHAR *netw,
|
||||
int id)
|
||||
{
|
||||
HKEY nhk;
|
||||
LONG ret;
|
||||
DWORD i;
|
||||
struct wpa_ssid *ssid;
|
||||
int errors = 0;
|
||||
|
||||
ret = RegOpenKeyEx(hk, netw, 0, KEY_QUERY_VALUE, &nhk);
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
wpa_printf(MSG_DEBUG, "Could not open wpa_supplicant config "
|
||||
"network '" TSTR "'", netw);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wpa_printf(MSG_MSGDUMP, "Start of a new network '" TSTR "'", netw);
|
||||
ssid = os_zalloc(sizeof(*ssid));
|
||||
if (ssid == NULL) {
|
||||
RegCloseKey(nhk);
|
||||
return NULL;
|
||||
}
|
||||
ssid->id = id;
|
||||
|
||||
wpa_config_set_network_defaults(ssid);
|
||||
|
||||
for (i = 0; ; i++) {
|
||||
TCHAR name[255], data[1024];
|
||||
DWORD namelen, datalen, type;
|
||||
|
||||
namelen = 255;
|
||||
datalen = sizeof(data);
|
||||
ret = RegEnumValue(nhk, i, name, &namelen, NULL, &type,
|
||||
(LPBYTE) data, &datalen);
|
||||
|
||||
if (ret == ERROR_NO_MORE_ITEMS)
|
||||
break;
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
wpa_printf(MSG_ERROR, "RegEnumValue failed: 0x%x",
|
||||
(unsigned int) ret);
|
||||
break;
|
||||
}
|
||||
|
||||
if (namelen >= 255)
|
||||
namelen = 255 - 1;
|
||||
name[namelen] = TEXT('\0');
|
||||
|
||||
if (datalen >= 1024)
|
||||
datalen = 1024 - 1;
|
||||
data[datalen] = TEXT('\0');
|
||||
|
||||
wpa_unicode2ascii_inplace(name);
|
||||
wpa_unicode2ascii_inplace(data);
|
||||
if (wpa_config_set(ssid, (char *) name, (char *) data, 0) < 0)
|
||||
errors++;
|
||||
}
|
||||
|
||||
RegCloseKey(nhk);
|
||||
|
||||
if (ssid->passphrase) {
|
||||
if (ssid->psk_set) {
|
||||
wpa_printf(MSG_ERROR, "Both PSK and passphrase "
|
||||
"configured for network '" TSTR "'.", netw);
|
||||
errors++;
|
||||
}
|
||||
wpa_config_update_psk(ssid);
|
||||
}
|
||||
|
||||
if ((ssid->key_mgmt & WPA_KEY_MGMT_PSK) && !ssid->psk_set) {
|
||||
wpa_printf(MSG_ERROR, "WPA-PSK accepted for key management, "
|
||||
"but no PSK configured for network '" TSTR "'.",
|
||||
netw);
|
||||
errors++;
|
||||
}
|
||||
|
||||
if ((ssid->group_cipher & WPA_CIPHER_CCMP) &&
|
||||
!(ssid->pairwise_cipher & WPA_CIPHER_CCMP) &&
|
||||
!(ssid->pairwise_cipher & WPA_CIPHER_NONE)) {
|
||||
/* Group cipher cannot be stronger than the pairwise cipher. */
|
||||
wpa_printf(MSG_DEBUG, "Removed CCMP from group cipher "
|
||||
"list since it was not allowed for pairwise "
|
||||
"cipher for network '" TSTR "'.", netw);
|
||||
ssid->group_cipher &= ~WPA_CIPHER_CCMP;
|
||||
}
|
||||
|
||||
if (errors) {
|
||||
wpa_config_free_ssid(ssid);
|
||||
ssid = NULL;
|
||||
}
|
||||
|
||||
return ssid;
|
||||
}
|
||||
|
||||
|
||||
static int wpa_config_read_networks(struct wpa_config *config, HKEY hk)
|
||||
{
|
||||
HKEY nhk;
|
||||
struct wpa_ssid *ssid, *tail = NULL, *head = NULL;
|
||||
int errors = 0;
|
||||
LONG ret;
|
||||
DWORD i;
|
||||
|
||||
ret = RegOpenKeyEx(hk, TEXT("networks"), 0, KEY_ENUMERATE_SUB_KEYS,
|
||||
&nhk);
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
wpa_printf(MSG_ERROR, "Could not open wpa_supplicant networks "
|
||||
"registry key");
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0; ; i++) {
|
||||
TCHAR name[255];
|
||||
DWORD namelen;
|
||||
|
||||
namelen = 255;
|
||||
ret = RegEnumKeyEx(nhk, i, name, &namelen, NULL, NULL, NULL,
|
||||
NULL);
|
||||
|
||||
if (ret == ERROR_NO_MORE_ITEMS)
|
||||
break;
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
wpa_printf(MSG_DEBUG, "RegEnumKeyEx failed: 0x%x",
|
||||
(unsigned int) ret);
|
||||
break;
|
||||
}
|
||||
|
||||
if (namelen >= 255)
|
||||
namelen = 255 - 1;
|
||||
name[namelen] = '\0';
|
||||
|
||||
ssid = wpa_config_read_network(nhk, name, i);
|
||||
if (ssid == NULL) {
|
||||
wpa_printf(MSG_ERROR, "Failed to parse network "
|
||||
"profile '%s'.", name);
|
||||
errors++;
|
||||
continue;
|
||||
}
|
||||
if (head == NULL) {
|
||||
head = tail = ssid;
|
||||
} else {
|
||||
tail->next = ssid;
|
||||
tail = ssid;
|
||||
}
|
||||
if (wpa_config_add_prio_network(config, ssid)) {
|
||||
wpa_printf(MSG_ERROR, "Failed to add network profile "
|
||||
"'%s' to priority list.", name);
|
||||
errors++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
RegCloseKey(nhk);
|
||||
|
||||
config->ssid = head;
|
||||
|
||||
return errors ? -1 : 0;
|
||||
}
|
||||
|
||||
|
||||
struct wpa_config * wpa_config_read(const char *name)
|
||||
{
|
||||
TCHAR buf[256];
|
||||
int errors = 0;
|
||||
struct wpa_config *config;
|
||||
HKEY hk;
|
||||
LONG ret;
|
||||
|
||||
config = wpa_config_alloc_empty(NULL, NULL);
|
||||
if (config == NULL)
|
||||
return NULL;
|
||||
wpa_printf(MSG_DEBUG, "Reading configuration profile '%s'", name);
|
||||
|
||||
#ifdef UNICODE
|
||||
_snwprintf(buf, 256, WPA_KEY_PREFIX TEXT("\\configs\\%S"), name);
|
||||
#else /* UNICODE */
|
||||
os_snprintf(buf, 256, WPA_KEY_PREFIX TEXT("\\configs\\%s"), name);
|
||||
#endif /* UNICODE */
|
||||
|
||||
ret = RegOpenKeyEx(WPA_KEY_ROOT, buf, 0, KEY_QUERY_VALUE, &hk);
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
wpa_printf(MSG_ERROR, "Could not open wpa_supplicant "
|
||||
"configuration registry HKLM\\" TSTR, buf);
|
||||
os_free(config);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (wpa_config_read_global(config, hk))
|
||||
errors++;
|
||||
|
||||
if (wpa_config_read_networks(config, hk))
|
||||
errors++;
|
||||
|
||||
if (wpa_config_read_blobs(config, hk))
|
||||
errors++;
|
||||
|
||||
wpa_config_debug_dump_networks(config);
|
||||
|
||||
RegCloseKey(hk);
|
||||
|
||||
if (errors) {
|
||||
wpa_config_free(config);
|
||||
config = NULL;
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
static int wpa_config_write_reg_dword(HKEY hk, const TCHAR *name, int val,
|
||||
int def)
|
||||
{
|
||||
LONG ret;
|
||||
DWORD _val = val;
|
||||
|
||||
if (val == def) {
|
||||
RegDeleteValue(hk, name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = RegSetValueEx(hk, name, 0, REG_DWORD, (LPBYTE) &_val,
|
||||
sizeof(_val));
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
wpa_printf(MSG_ERROR, "WINREG: Failed to set %s=%d: error %d",
|
||||
name, val, (int) GetLastError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int wpa_config_write_reg_string(HKEY hk, const char *name,
|
||||
const char *val)
|
||||
{
|
||||
LONG ret;
|
||||
TCHAR *_name, *_val;
|
||||
|
||||
_name = wpa_strdup_tchar(name);
|
||||
if (_name == NULL)
|
||||
return -1;
|
||||
|
||||
if (val == NULL) {
|
||||
RegDeleteValue(hk, _name);
|
||||
os_free(_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
_val = wpa_strdup_tchar(val);
|
||||
if (_val == NULL) {
|
||||
os_free(_name);
|
||||
return -1;
|
||||
}
|
||||
ret = RegSetValueEx(hk, _name, 0, REG_SZ, (BYTE *) _val,
|
||||
(os_strlen(val) + 1) * sizeof(TCHAR));
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
wpa_printf(MSG_ERROR, "WINREG: Failed to set %s='%s': "
|
||||
"error %d", name, val, (int) GetLastError());
|
||||
os_free(_name);
|
||||
os_free(_val);
|
||||
return -1;
|
||||
}
|
||||
|
||||
os_free(_name);
|
||||
os_free(_val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int wpa_config_write_global(struct wpa_config *config, HKEY hk)
|
||||
{
|
||||
#ifdef CONFIG_CTRL_IFACE
|
||||
wpa_config_write_reg_string(hk, "ctrl_interface",
|
||||
config->ctrl_interface);
|
||||
#endif /* CONFIG_CTRL_IFACE */
|
||||
|
||||
wpa_config_write_reg_dword(hk, TEXT("eapol_version"),
|
||||
config->eapol_version,
|
||||
DEFAULT_EAPOL_VERSION);
|
||||
wpa_config_write_reg_dword(hk, TEXT("ap_scan"), config->ap_scan,
|
||||
DEFAULT_AP_SCAN);
|
||||
wpa_config_write_reg_dword(hk, TEXT("fast_reauth"),
|
||||
config->fast_reauth, DEFAULT_FAST_REAUTH);
|
||||
wpa_config_write_reg_dword(hk, TEXT("dot11RSNAConfigPMKLifetime"),
|
||||
config->dot11RSNAConfigPMKLifetime, 0);
|
||||
wpa_config_write_reg_dword(hk,
|
||||
TEXT("dot11RSNAConfigPMKReauthThreshold"),
|
||||
config->dot11RSNAConfigPMKReauthThreshold,
|
||||
0);
|
||||
wpa_config_write_reg_dword(hk, TEXT("dot11RSNAConfigSATimeout"),
|
||||
config->dot11RSNAConfigSATimeout, 0);
|
||||
wpa_config_write_reg_dword(hk, TEXT("update_config"),
|
||||
config->update_config,
|
||||
0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int wpa_config_delete_subkeys(HKEY hk, const TCHAR *key)
|
||||
{
|
||||
HKEY nhk;
|
||||
int i, errors = 0;
|
||||
LONG ret;
|
||||
|
||||
ret = RegOpenKeyEx(hk, key, 0, KEY_ENUMERATE_SUB_KEYS | DELETE, &nhk);
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
wpa_printf(MSG_DEBUG, "WINREG: Could not open key '" TSTR
|
||||
"' for subkey deletion: error 0x%x (%d)", key,
|
||||
(unsigned int) ret, (int) GetLastError());
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; ; i++) {
|
||||
TCHAR name[255];
|
||||
DWORD namelen;
|
||||
|
||||
namelen = 255;
|
||||
ret = RegEnumKeyEx(nhk, i, name, &namelen, NULL, NULL, NULL,
|
||||
NULL);
|
||||
|
||||
if (ret == ERROR_NO_MORE_ITEMS)
|
||||
break;
|
||||
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
wpa_printf(MSG_DEBUG, "RegEnumKeyEx failed: 0x%x (%d)",
|
||||
(unsigned int) ret, (int) GetLastError());
|
||||
break;
|
||||
}
|
||||
|
||||
if (namelen >= 255)
|
||||
namelen = 255 - 1;
|
||||
name[namelen] = TEXT('\0');
|
||||
|
||||
ret = RegDeleteKey(nhk, name);
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
wpa_printf(MSG_DEBUG, "RegDeleteKey failed: 0x%x (%d)",
|
||||
(unsigned int) ret, (int) GetLastError());
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
|
||||
RegCloseKey(nhk);
|
||||
|
||||
return errors ? -1 : 0;
|
||||
}
|
||||
|
||||
|
||||
static void write_str(HKEY hk, const char *field, struct wpa_ssid *ssid)
|
||||
{
|
||||
char *value = wpa_config_get(ssid, field);
|
||||
if (value == NULL)
|
||||
return;
|
||||
wpa_config_write_reg_string(hk, field, value);
|
||||
os_free(value);
|
||||
}
|
||||
|
||||
|
||||
static void write_int(HKEY hk, const char *field, int value, int def)
|
||||
{
|
||||
char val[20];
|
||||
if (value == def)
|
||||
return;
|
||||
os_snprintf(val, sizeof(val), "%d", value);
|
||||
wpa_config_write_reg_string(hk, field, val);
|
||||
}
|
||||
|
||||
|
||||
static void write_bssid(HKEY hk, struct wpa_ssid *ssid)
|
||||
{
|
||||
char *value = wpa_config_get(ssid, "bssid");
|
||||
if (value == NULL)
|
||||
return;
|
||||
wpa_config_write_reg_string(hk, "bssid", value);
|
||||
os_free(value);
|
||||
}
|
||||
|
||||
|
||||
static void write_psk(HKEY hk, struct wpa_ssid *ssid)
|
||||
{
|
||||
char *value = wpa_config_get(ssid, "psk");
|
||||
if (value == NULL)
|
||||
return;
|
||||
wpa_config_write_reg_string(hk, "psk", value);
|
||||
os_free(value);
|
||||
}
|
||||
|
||||
|
||||
static void write_proto(HKEY hk, struct wpa_ssid *ssid)
|
||||
{
|
||||
char *value;
|
||||
|
||||
if (ssid->proto == DEFAULT_PROTO)
|
||||
return;
|
||||
|
||||
value = wpa_config_get(ssid, "proto");
|
||||
if (value == NULL)
|
||||
return;
|
||||
if (value[0])
|
||||
wpa_config_write_reg_string(hk, "proto", value);
|
||||
os_free(value);
|
||||
}
|
||||
|
||||
|
||||
static void write_key_mgmt(HKEY hk, struct wpa_ssid *ssid)
|
||||
{
|
||||
char *value;
|
||||
|
||||
if (ssid->key_mgmt == DEFAULT_KEY_MGMT)
|
||||
return;
|
||||
|
||||
value = wpa_config_get(ssid, "key_mgmt");
|
||||
if (value == NULL)
|
||||
return;
|
||||
if (value[0])
|
||||
wpa_config_write_reg_string(hk, "key_mgmt", value);
|
||||
os_free(value);
|
||||
}
|
||||
|
||||
|
||||
static void write_pairwise(HKEY hk, struct wpa_ssid *ssid)
|
||||
{
|
||||
char *value;
|
||||
|
||||
if (ssid->pairwise_cipher == DEFAULT_PAIRWISE)
|
||||
return;
|
||||
|
||||
value = wpa_config_get(ssid, "pairwise");
|
||||
if (value == NULL)
|
||||
return;
|
||||
if (value[0])
|
||||
wpa_config_write_reg_string(hk, "pairwise", value);
|
||||
os_free(value);
|
||||
}
|
||||
|
||||
|
||||
static void write_group(HKEY hk, struct wpa_ssid *ssid)
|
||||
{
|
||||
char *value;
|
||||
|
||||
if (ssid->group_cipher == DEFAULT_GROUP)
|
||||
return;
|
||||
|
||||
value = wpa_config_get(ssid, "group");
|
||||
if (value == NULL)
|
||||
return;
|
||||
if (value[0])
|
||||
wpa_config_write_reg_string(hk, "group", value);
|
||||
os_free(value);
|
||||
}
|
||||
|
||||
|
||||
static void write_auth_alg(HKEY hk, struct wpa_ssid *ssid)
|
||||
{
|
||||
char *value;
|
||||
|
||||
if (ssid->auth_alg == 0)
|
||||
return;
|
||||
|
||||
value = wpa_config_get(ssid, "auth_alg");
|
||||
if (value == NULL)
|
||||
return;
|
||||
if (value[0])
|
||||
wpa_config_write_reg_string(hk, "auth_alg", value);
|
||||
os_free(value);
|
||||
}
|
||||
|
||||
|
||||
#ifdef IEEE8021X_EAPOL
|
||||
static void write_eap(HKEY hk, struct wpa_ssid *ssid)
|
||||
{
|
||||
char *value;
|
||||
|
||||
value = wpa_config_get(ssid, "eap");
|
||||
if (value == NULL)
|
||||
return;
|
||||
|
||||
if (value[0])
|
||||
wpa_config_write_reg_string(hk, "eap", value);
|
||||
os_free(value);
|
||||
}
|
||||
#endif /* IEEE8021X_EAPOL */
|
||||
|
||||
|
||||
static void write_wep_key(HKEY hk, int idx, struct wpa_ssid *ssid)
|
||||
{
|
||||
char field[20], *value;
|
||||
|
||||
os_snprintf(field, sizeof(field), "wep_key%d", idx);
|
||||
value = wpa_config_get(ssid, field);
|
||||
if (value) {
|
||||
wpa_config_write_reg_string(hk, field, value);
|
||||
os_free(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int wpa_config_write_network(HKEY hk, struct wpa_ssid *ssid, int id)
|
||||
{
|
||||
int i, errors = 0;
|
||||
HKEY nhk, netw;
|
||||
LONG ret;
|
||||
TCHAR name[5];
|
||||
|
||||
ret = RegOpenKeyEx(hk, TEXT("networks"), 0, KEY_CREATE_SUB_KEY, &nhk);
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
wpa_printf(MSG_DEBUG, "WINREG: Could not open networks key "
|
||||
"for subkey addition: error 0x%x (%d)",
|
||||
(unsigned int) ret, (int) GetLastError());
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef UNICODE
|
||||
wsprintf(name, L"%04d", id);
|
||||
#else /* UNICODE */
|
||||
os_snprintf(name, sizeof(name), "%04d", id);
|
||||
#endif /* UNICODE */
|
||||
ret = RegCreateKeyEx(nhk, name, 0, NULL, 0, KEY_WRITE, NULL, &netw,
|
||||
NULL);
|
||||
RegCloseKey(nhk);
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
wpa_printf(MSG_DEBUG, "WINREG: Could not add network key '%s':"
|
||||
" error 0x%x (%d)",
|
||||
name, (unsigned int) ret, (int) GetLastError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
#define STR(t) write_str(netw, #t, ssid)
|
||||
#define INT(t) write_int(netw, #t, ssid->t, 0)
|
||||
#define INT_DEF(t, def) write_int(netw, #t, ssid->t, def)
|
||||
|
||||
STR(ssid);
|
||||
INT(scan_ssid);
|
||||
write_bssid(netw, ssid);
|
||||
write_psk(netw, ssid);
|
||||
write_proto(netw, ssid);
|
||||
write_key_mgmt(netw, ssid);
|
||||
write_pairwise(netw, ssid);
|
||||
write_group(netw, ssid);
|
||||
write_auth_alg(netw, ssid);
|
||||
#ifdef IEEE8021X_EAPOL
|
||||
write_eap(netw, ssid);
|
||||
STR(identity);
|
||||
STR(anonymous_identity);
|
||||
STR(eappsk);
|
||||
STR(nai);
|
||||
STR(password);
|
||||
STR(ca_cert);
|
||||
STR(ca_path);
|
||||
STR(client_cert);
|
||||
STR(private_key);
|
||||
STR(private_key_passwd);
|
||||
STR(dh_file);
|
||||
STR(subject_match);
|
||||
STR(altsubject_match);
|
||||
STR(ca_cert2);
|
||||
STR(ca_path2);
|
||||
STR(client_cert2);
|
||||
STR(private_key2);
|
||||
STR(private_key2_passwd);
|
||||
STR(dh_file2);
|
||||
STR(subject_match2);
|
||||
STR(altsubject_match2);
|
||||
STR(phase1);
|
||||
STR(phase2);
|
||||
STR(pcsc);
|
||||
STR(pin);
|
||||
STR(engine_id);
|
||||
STR(key_id);
|
||||
INT(engine);
|
||||
INT_DEF(eapol_flags, DEFAULT_EAPOL_FLAGS);
|
||||
#endif /* IEEE8021X_EAPOL */
|
||||
for (i = 0; i < 4; i++)
|
||||
write_wep_key(netw, i, ssid);
|
||||
INT(wep_tx_keyidx);
|
||||
INT(priority);
|
||||
#ifdef IEEE8021X_EAPOL
|
||||
INT_DEF(eap_workaround, DEFAULT_EAP_WORKAROUND);
|
||||
STR(pac_file);
|
||||
INT_DEF(fragment_size, DEFAULT_FRAGMENT_SIZE);
|
||||
#endif /* IEEE8021X_EAPOL */
|
||||
INT(mode);
|
||||
INT(proactive_key_caching);
|
||||
INT(disabled);
|
||||
INT(peerkey);
|
||||
#ifdef CONFIG_IEEE80211W
|
||||
INT(ieee80211w);
|
||||
#endif /* CONFIG_IEEE80211W */
|
||||
STR(id_str);
|
||||
|
||||
#undef STR
|
||||
#undef INT
|
||||
#undef INT_DEF
|
||||
|
||||
RegCloseKey(netw);
|
||||
|
||||
return errors ? -1 : 0;
|
||||
}
|
||||
|
||||
|
||||
static int wpa_config_write_blob(HKEY hk, struct wpa_config_blob *blob)
|
||||
{
|
||||
HKEY bhk;
|
||||
LONG ret;
|
||||
TCHAR *name;
|
||||
|
||||
ret = RegCreateKeyEx(hk, TEXT("blobs"), 0, NULL, 0, KEY_WRITE, NULL,
|
||||
&bhk, NULL);
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
wpa_printf(MSG_DEBUG, "WINREG: Could not add blobs key: "
|
||||
"error 0x%x (%d)",
|
||||
(unsigned int) ret, (int) GetLastError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
name = wpa_strdup_tchar(blob->name);
|
||||
ret = RegSetValueEx(bhk, name, 0, REG_BINARY, blob->data,
|
||||
blob->len);
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
wpa_printf(MSG_ERROR, "WINREG: Failed to set blob %s': "
|
||||
"error 0x%x (%d)", blob->name, (unsigned int) ret,
|
||||
(int) GetLastError());
|
||||
RegCloseKey(bhk);
|
||||
os_free(name);
|
||||
return -1;
|
||||
}
|
||||
os_free(name);
|
||||
|
||||
RegCloseKey(bhk);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int wpa_config_write(const char *name, struct wpa_config *config)
|
||||
{
|
||||
TCHAR buf[256];
|
||||
HKEY hk;
|
||||
LONG ret;
|
||||
int errors = 0;
|
||||
struct wpa_ssid *ssid;
|
||||
struct wpa_config_blob *blob;
|
||||
int id;
|
||||
|
||||
wpa_printf(MSG_DEBUG, "Writing configuration file '%s'", name);
|
||||
|
||||
#ifdef UNICODE
|
||||
_snwprintf(buf, 256, WPA_KEY_PREFIX TEXT("\\configs\\%S"), name);
|
||||
#else /* UNICODE */
|
||||
os_snprintf(buf, 256, WPA_KEY_PREFIX TEXT("\\configs\\%s"), name);
|
||||
#endif /* UNICODE */
|
||||
|
||||
ret = RegOpenKeyEx(WPA_KEY_ROOT, buf, 0, KEY_SET_VALUE | DELETE, &hk);
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
wpa_printf(MSG_ERROR, "Could not open wpa_supplicant "
|
||||
"configuration registry %s: error %d", buf,
|
||||
(int) GetLastError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (wpa_config_write_global(config, hk)) {
|
||||
wpa_printf(MSG_ERROR, "Failed to write global configuration "
|
||||
"data");
|
||||
errors++;
|
||||
}
|
||||
|
||||
wpa_config_delete_subkeys(hk, TEXT("networks"));
|
||||
for (ssid = config->ssid, id = 0; ssid; ssid = ssid->next, id++) {
|
||||
if (wpa_config_write_network(hk, ssid, id))
|
||||
errors++;
|
||||
}
|
||||
|
||||
RegDeleteKey(hk, TEXT("blobs"));
|
||||
for (blob = config->blobs; blob; blob = blob->next) {
|
||||
if (wpa_config_write_blob(hk, blob))
|
||||
errors++;
|
||||
}
|
||||
|
||||
RegCloseKey(hk);
|
||||
|
||||
wpa_printf(MSG_DEBUG, "Configuration '%s' written %ssuccessfully",
|
||||
name, errors ? "un" : "");
|
||||
return errors ? -1 : 0;
|
||||
}
|
@ -1,834 +0,0 @@
|
||||
/*
|
||||
* WPA Supplicant / Windows Named Pipe -based control interface
|
||||
* Copyright (c) 2004-2006, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
|
||||
#include "common.h"
|
||||
#include "eloop.h"
|
||||
#include "config.h"
|
||||
#include "eapol_sm.h"
|
||||
#include "wpa_supplicant_i.h"
|
||||
#include "ctrl_iface.h"
|
||||
#include "wpa_ctrl.h"
|
||||
|
||||
#ifdef __MINGW32_VERSION
|
||||
/* mingw-w32api v3.1 does not yet include sddl.h, so define needed parts here
|
||||
*/
|
||||
#define SDDL_REVISION_1 1
|
||||
BOOL WINAPI ConvertStringSecurityDescriptorToSecurityDescriptorA(
|
||||
LPCSTR, DWORD, PSECURITY_DESCRIPTOR *, PULONG);
|
||||
BOOL WINAPI ConvertStringSecurityDescriptorToSecurityDescriptorW(
|
||||
LPCWSTR, DWORD, PSECURITY_DESCRIPTOR *, PULONG);
|
||||
#ifdef UNICODE
|
||||
#define ConvertStringSecurityDescriptorToSecurityDescriptor \
|
||||
ConvertStringSecurityDescriptorToSecurityDescriptorW
|
||||
#else
|
||||
#define ConvertStringSecurityDescriptorToSecurityDescriptor \
|
||||
ConvertStringSecurityDescriptorToSecurityDescriptorA
|
||||
#endif
|
||||
#else /* __MINGW32_VERSION */
|
||||
#ifndef _WIN32_WINNT
|
||||
#define _WIN32_WINNT 0x0500
|
||||
#endif
|
||||
#include <sddl.h>
|
||||
#endif /* __MINGW32_VERSION */
|
||||
|
||||
#ifndef WPA_SUPPLICANT_NAMED_PIPE
|
||||
#define WPA_SUPPLICANT_NAMED_PIPE "WpaSupplicant"
|
||||
#endif
|
||||
#define NAMED_PIPE_PREFIX TEXT("\\\\.\\pipe\\") TEXT(WPA_SUPPLICANT_NAMED_PIPE)
|
||||
|
||||
/* Per-interface ctrl_iface */
|
||||
|
||||
#define REQUEST_BUFSIZE 256
|
||||
#define REPLY_BUFSIZE 4096
|
||||
|
||||
struct ctrl_iface_priv;
|
||||
|
||||
/**
|
||||
* struct wpa_ctrl_dst - Internal data structure of control interface clients
|
||||
*
|
||||
* This structure is used to store information about registered control
|
||||
* interface monitors into struct wpa_supplicant. This data is private to
|
||||
* ctrl_iface_named_pipe.c and should not be touched directly from other files.
|
||||
*/
|
||||
struct wpa_ctrl_dst {
|
||||
/* Note: OVERLAPPED must be the first member of struct wpa_ctrl_dst */
|
||||
OVERLAPPED overlap;
|
||||
struct wpa_ctrl_dst *next, *prev;
|
||||
struct ctrl_iface_priv *priv;
|
||||
HANDLE pipe;
|
||||
int attached;
|
||||
int debug_level;
|
||||
int errors;
|
||||
char req_buf[REQUEST_BUFSIZE];
|
||||
char *rsp_buf;
|
||||
int used;
|
||||
};
|
||||
|
||||
|
||||
struct ctrl_iface_priv {
|
||||
struct wpa_supplicant *wpa_s;
|
||||
struct wpa_ctrl_dst *ctrl_dst;
|
||||
SECURITY_ATTRIBUTES attr;
|
||||
int sec_attr_set;
|
||||
};
|
||||
|
||||
|
||||
static void wpa_supplicant_ctrl_iface_send(struct ctrl_iface_priv *priv,
|
||||
int level, const char *buf,
|
||||
size_t len);
|
||||
|
||||
static void ctrl_close_pipe(struct wpa_ctrl_dst *dst);
|
||||
static void wpa_supplicant_ctrl_iface_receive(void *, void *);
|
||||
static VOID WINAPI ctrl_iface_read_completed(DWORD err, DWORD bytes,
|
||||
LPOVERLAPPED overlap);
|
||||
|
||||
struct wpa_global_dst;
|
||||
static void global_close_pipe(struct wpa_global_dst *dst);
|
||||
static void wpa_supplicant_global_iface_receive(void *eloop_data,
|
||||
void *user_ctx);
|
||||
static VOID WINAPI global_iface_read_completed(DWORD err, DWORD bytes,
|
||||
LPOVERLAPPED overlap);
|
||||
|
||||
|
||||
static int ctrl_broken_pipe(HANDLE pipe, int used)
|
||||
{
|
||||
DWORD err;
|
||||
|
||||
if (PeekNamedPipe(pipe, NULL, 0, NULL, NULL, NULL))
|
||||
return 0;
|
||||
|
||||
err = GetLastError();
|
||||
if (err == ERROR_BROKEN_PIPE || (err == ERROR_BAD_PIPE && used))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void ctrl_flush_broken_pipes(struct ctrl_iface_priv *priv)
|
||||
{
|
||||
struct wpa_ctrl_dst *dst, *next;
|
||||
|
||||
dst = priv->ctrl_dst;
|
||||
|
||||
while (dst) {
|
||||
next = dst->next;
|
||||
if (ctrl_broken_pipe(dst->pipe, dst->used)) {
|
||||
wpa_printf(MSG_DEBUG, "CTRL: closing broken pipe %p",
|
||||
dst);
|
||||
ctrl_close_pipe(dst);
|
||||
}
|
||||
dst = next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int ctrl_open_pipe(struct ctrl_iface_priv *priv)
|
||||
{
|
||||
struct wpa_ctrl_dst *dst;
|
||||
DWORD err;
|
||||
TCHAR name[256];
|
||||
|
||||
dst = os_zalloc(sizeof(*dst));
|
||||
if (dst == NULL)
|
||||
return -1;
|
||||
wpa_printf(MSG_DEBUG, "CTRL: Open pipe %p", dst);
|
||||
|
||||
dst->priv = priv;
|
||||
dst->debug_level = MSG_INFO;
|
||||
dst->pipe = INVALID_HANDLE_VALUE;
|
||||
|
||||
dst->overlap.hEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
|
||||
if (dst->overlap.hEvent == NULL) {
|
||||
wpa_printf(MSG_ERROR, "CTRL: CreateEvent failed: %d",
|
||||
(int) GetLastError());
|
||||
goto fail;
|
||||
}
|
||||
|
||||
eloop_register_event(dst->overlap.hEvent,
|
||||
sizeof(dst->overlap.hEvent),
|
||||
wpa_supplicant_ctrl_iface_receive, dst, NULL);
|
||||
|
||||
#ifdef UNICODE
|
||||
_snwprintf(name, 256, NAMED_PIPE_PREFIX TEXT("-%S"),
|
||||
priv->wpa_s->ifname);
|
||||
#else /* UNICODE */
|
||||
os_snprintf(name, 256, NAMED_PIPE_PREFIX "-%s",
|
||||
priv->wpa_s->ifname);
|
||||
#endif /* UNICODE */
|
||||
|
||||
/* TODO: add support for configuring access list for the pipe */
|
||||
dst->pipe = CreateNamedPipe(name,
|
||||
PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
|
||||
PIPE_TYPE_MESSAGE |
|
||||
PIPE_READMODE_MESSAGE |
|
||||
PIPE_WAIT,
|
||||
15, REPLY_BUFSIZE, REQUEST_BUFSIZE,
|
||||
1000,
|
||||
priv->sec_attr_set ? &priv->attr : NULL);
|
||||
if (dst->pipe == INVALID_HANDLE_VALUE) {
|
||||
wpa_printf(MSG_ERROR, "CTRL: CreateNamedPipe failed: %d",
|
||||
(int) GetLastError());
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (ConnectNamedPipe(dst->pipe, &dst->overlap)) {
|
||||
wpa_printf(MSG_ERROR, "CTRL: ConnectNamedPipe failed: %d",
|
||||
(int) GetLastError());
|
||||
CloseHandle(dst->pipe);
|
||||
os_free(dst);
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = GetLastError();
|
||||
switch (err) {
|
||||
case ERROR_IO_PENDING:
|
||||
wpa_printf(MSG_DEBUG, "CTRL: ConnectNamedPipe: connection in "
|
||||
"progress");
|
||||
break;
|
||||
case ERROR_PIPE_CONNECTED:
|
||||
wpa_printf(MSG_DEBUG, "CTRL: ConnectNamedPipe: already "
|
||||
"connected");
|
||||
if (SetEvent(dst->overlap.hEvent))
|
||||
break;
|
||||
/* fall through */
|
||||
default:
|
||||
wpa_printf(MSG_DEBUG, "CTRL: ConnectNamedPipe error: %d",
|
||||
(int) err);
|
||||
CloseHandle(dst->pipe);
|
||||
os_free(dst);
|
||||
return -1;
|
||||
}
|
||||
|
||||
dst->next = priv->ctrl_dst;
|
||||
if (dst->next)
|
||||
dst->next->prev = dst;
|
||||
priv->ctrl_dst = dst;
|
||||
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
ctrl_close_pipe(dst);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
static void ctrl_close_pipe(struct wpa_ctrl_dst *dst)
|
||||
{
|
||||
wpa_printf(MSG_DEBUG, "CTRL: close pipe %p", dst);
|
||||
|
||||
if (dst->overlap.hEvent) {
|
||||
eloop_unregister_event(dst->overlap.hEvent,
|
||||
sizeof(dst->overlap.hEvent));
|
||||
CloseHandle(dst->overlap.hEvent);
|
||||
}
|
||||
|
||||
if (dst->pipe != INVALID_HANDLE_VALUE) {
|
||||
/*
|
||||
* Could use FlushFileBuffers() here to guarantee that all data
|
||||
* gets delivered to the client, but that can block, so let's
|
||||
* not do this for now.
|
||||
* FlushFileBuffers(dst->pipe);
|
||||
*/
|
||||
CloseHandle(dst->pipe);
|
||||
}
|
||||
|
||||
if (dst->prev)
|
||||
dst->prev->next = dst->next;
|
||||
else
|
||||
dst->priv->ctrl_dst = dst->next;
|
||||
if (dst->next)
|
||||
dst->next->prev = dst->prev;
|
||||
|
||||
os_free(dst->rsp_buf);
|
||||
os_free(dst);
|
||||
}
|
||||
|
||||
|
||||
static VOID WINAPI ctrl_iface_write_completed(DWORD err, DWORD bytes,
|
||||
LPOVERLAPPED overlap)
|
||||
{
|
||||
struct wpa_ctrl_dst *dst = (struct wpa_ctrl_dst *) overlap;
|
||||
wpa_printf(MSG_DEBUG, "CTRL: Overlapped write completed: dst=%p "
|
||||
"err=%d bytes=%d", dst, (int) err, (int) bytes);
|
||||
if (err) {
|
||||
ctrl_close_pipe(dst);
|
||||
return;
|
||||
}
|
||||
|
||||
os_free(dst->rsp_buf);
|
||||
dst->rsp_buf = NULL;
|
||||
|
||||
if (!ReadFileEx(dst->pipe, dst->req_buf, sizeof(dst->req_buf),
|
||||
&dst->overlap, ctrl_iface_read_completed)) {
|
||||
wpa_printf(MSG_DEBUG, "CTRL: ReadFileEx failed: %d",
|
||||
(int) GetLastError());
|
||||
ctrl_close_pipe(dst);
|
||||
return;
|
||||
}
|
||||
wpa_printf(MSG_DEBUG, "CTRL: Overlapped read started for %p", dst);
|
||||
}
|
||||
|
||||
|
||||
static void wpa_supplicant_ctrl_iface_rx(struct wpa_ctrl_dst *dst, size_t len)
|
||||
{
|
||||
struct wpa_supplicant *wpa_s = dst->priv->wpa_s;
|
||||
char *reply = NULL, *send_buf;
|
||||
size_t reply_len = 0, send_len;
|
||||
int new_attached = 0;
|
||||
char *buf = dst->req_buf;
|
||||
|
||||
dst->used = 1;
|
||||
if (len >= REQUEST_BUFSIZE)
|
||||
len = REQUEST_BUFSIZE - 1;
|
||||
buf[len] = '\0';
|
||||
|
||||
if (os_strcmp(buf, "ATTACH") == 0) {
|
||||
dst->attached = 1;
|
||||
wpa_printf(MSG_DEBUG, "CTRL_IFACE monitor attached");
|
||||
new_attached = 1;
|
||||
reply_len = 2;
|
||||
} else if (os_strcmp(buf, "DETACH") == 0) {
|
||||
dst->attached = 0;
|
||||
wpa_printf(MSG_DEBUG, "CTRL_IFACE monitor detached");
|
||||
reply_len = 2;
|
||||
} else if (os_strncmp(buf, "LEVEL ", 6) == 0) {
|
||||
wpa_printf(MSG_DEBUG, "CTRL_IFACE LEVEL %s", buf + 6);
|
||||
dst->debug_level = atoi(buf + 6);
|
||||
reply_len = 2;
|
||||
} else {
|
||||
reply = wpa_supplicant_ctrl_iface_process(wpa_s, buf,
|
||||
&reply_len);
|
||||
}
|
||||
|
||||
if (reply) {
|
||||
send_buf = reply;
|
||||
send_len = reply_len;
|
||||
} else if (reply_len == 2) {
|
||||
send_buf = "OK\n";
|
||||
send_len = 3;
|
||||
} else {
|
||||
send_buf = "FAIL\n";
|
||||
send_len = 5;
|
||||
}
|
||||
|
||||
os_free(dst->rsp_buf);
|
||||
dst->rsp_buf = os_malloc(send_len);
|
||||
if (dst->rsp_buf == NULL) {
|
||||
ctrl_close_pipe(dst);
|
||||
os_free(reply);
|
||||
return;
|
||||
}
|
||||
os_memcpy(dst->rsp_buf, send_buf, send_len);
|
||||
os_free(reply);
|
||||
|
||||
if (!WriteFileEx(dst->pipe, dst->rsp_buf, send_len, &dst->overlap,
|
||||
ctrl_iface_write_completed)) {
|
||||
wpa_printf(MSG_DEBUG, "CTRL: WriteFileEx failed: %d",
|
||||
(int) GetLastError());
|
||||
ctrl_close_pipe(dst);
|
||||
} else {
|
||||
wpa_printf(MSG_DEBUG, "CTRL: Overlapped write started for %p",
|
||||
dst);
|
||||
}
|
||||
|
||||
if (new_attached)
|
||||
eapol_sm_notify_ctrl_attached(wpa_s->eapol);
|
||||
}
|
||||
|
||||
|
||||
static VOID WINAPI ctrl_iface_read_completed(DWORD err, DWORD bytes,
|
||||
LPOVERLAPPED overlap)
|
||||
{
|
||||
struct wpa_ctrl_dst *dst = (struct wpa_ctrl_dst *) overlap;
|
||||
wpa_printf(MSG_DEBUG, "CTRL: Overlapped read completed: dst=%p err=%d "
|
||||
"bytes=%d", dst, (int) err, (int) bytes);
|
||||
if (err == 0 && bytes > 0)
|
||||
wpa_supplicant_ctrl_iface_rx(dst, bytes);
|
||||
}
|
||||
|
||||
|
||||
static void wpa_supplicant_ctrl_iface_receive(void *eloop_data, void *user_ctx)
|
||||
{
|
||||
struct wpa_ctrl_dst *dst = eloop_data;
|
||||
struct ctrl_iface_priv *priv = dst->priv;
|
||||
DWORD bytes;
|
||||
|
||||
wpa_printf(MSG_DEBUG, "CTRL: wpa_supplicant_ctrl_iface_receive");
|
||||
ResetEvent(dst->overlap.hEvent);
|
||||
|
||||
if (!GetOverlappedResult(dst->pipe, &dst->overlap, &bytes, FALSE)) {
|
||||
wpa_printf(MSG_DEBUG, "CTRL: GetOverlappedResult failed: %d",
|
||||
(int) GetLastError());
|
||||
return;
|
||||
}
|
||||
wpa_printf(MSG_DEBUG, "CTRL: GetOverlappedResult: New client "
|
||||
"connected");
|
||||
|
||||
/* Open a new named pipe for the next client. */
|
||||
ctrl_open_pipe(priv);
|
||||
|
||||
/* Use write completion function to start reading a command */
|
||||
ctrl_iface_write_completed(0, 0, &dst->overlap);
|
||||
|
||||
ctrl_flush_broken_pipes(priv);
|
||||
}
|
||||
|
||||
|
||||
static int ctrl_iface_parse(struct ctrl_iface_priv *priv, const char *params)
|
||||
{
|
||||
const char *sddl = NULL;
|
||||
TCHAR *t_sddl;
|
||||
|
||||
if (os_strncmp(params, "SDDL=", 5) == 0)
|
||||
sddl = params + 5;
|
||||
if (!sddl) {
|
||||
sddl = os_strstr(params, " SDDL=");
|
||||
if (sddl)
|
||||
sddl += 6;
|
||||
}
|
||||
|
||||
if (!sddl)
|
||||
return 0;
|
||||
|
||||
wpa_printf(MSG_DEBUG, "CTRL: SDDL='%s'", sddl);
|
||||
os_memset(&priv->attr, 0, sizeof(priv->attr));
|
||||
priv->attr.nLength = sizeof(priv->attr);
|
||||
priv->attr.bInheritHandle = FALSE;
|
||||
t_sddl = wpa_strdup_tchar(sddl);
|
||||
if (t_sddl == NULL)
|
||||
return -1;
|
||||
if (!ConvertStringSecurityDescriptorToSecurityDescriptor(
|
||||
t_sddl, SDDL_REVISION_1,
|
||||
(PSECURITY_DESCRIPTOR *) &priv->attr.lpSecurityDescriptor,
|
||||
NULL)) {
|
||||
os_free(t_sddl);
|
||||
wpa_printf(MSG_ERROR, "CTRL: SDDL='%s' - could not convert to "
|
||||
"security descriptor: %d",
|
||||
sddl, (int) GetLastError());
|
||||
return -1;
|
||||
}
|
||||
os_free(t_sddl);
|
||||
|
||||
priv->sec_attr_set = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void wpa_supplicant_ctrl_iface_msg_cb(void *ctx, int level,
|
||||
const char *txt, size_t len)
|
||||
{
|
||||
struct wpa_supplicant *wpa_s = ctx;
|
||||
if (wpa_s == NULL || wpa_s->ctrl_iface == NULL)
|
||||
return;
|
||||
wpa_supplicant_ctrl_iface_send(wpa_s->ctrl_iface, level, txt, len);
|
||||
}
|
||||
|
||||
|
||||
struct ctrl_iface_priv *
|
||||
wpa_supplicant_ctrl_iface_init(struct wpa_supplicant *wpa_s)
|
||||
{
|
||||
struct ctrl_iface_priv *priv;
|
||||
|
||||
priv = os_zalloc(sizeof(*priv));
|
||||
if (priv == NULL)
|
||||
return NULL;
|
||||
priv->wpa_s = wpa_s;
|
||||
|
||||
if (wpa_s->conf->ctrl_interface == NULL)
|
||||
return priv;
|
||||
|
||||
if (ctrl_iface_parse(priv, wpa_s->conf->ctrl_interface) < 0) {
|
||||
os_free(priv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (ctrl_open_pipe(priv) < 0) {
|
||||
os_free(priv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wpa_msg_register_cb(wpa_supplicant_ctrl_iface_msg_cb);
|
||||
|
||||
return priv;
|
||||
}
|
||||
|
||||
|
||||
void wpa_supplicant_ctrl_iface_deinit(struct ctrl_iface_priv *priv)
|
||||
{
|
||||
while (priv->ctrl_dst)
|
||||
ctrl_close_pipe(priv->ctrl_dst);
|
||||
if (priv->sec_attr_set)
|
||||
LocalFree(priv->attr.lpSecurityDescriptor);
|
||||
os_free(priv);
|
||||
}
|
||||
|
||||
|
||||
static void wpa_supplicant_ctrl_iface_send(struct ctrl_iface_priv *priv,
|
||||
int level, const char *buf,
|
||||
size_t len)
|
||||
{
|
||||
struct wpa_ctrl_dst *dst, *next;
|
||||
char levelstr[10];
|
||||
int idx;
|
||||
char *sbuf;
|
||||
int llen;
|
||||
DWORD written;
|
||||
|
||||
dst = priv->ctrl_dst;
|
||||
if (dst == NULL)
|
||||
return;
|
||||
|
||||
os_snprintf(levelstr, sizeof(levelstr), "<%d>", level);
|
||||
|
||||
llen = os_strlen(levelstr);
|
||||
sbuf = os_malloc(llen + len);
|
||||
if (sbuf == NULL)
|
||||
return;
|
||||
|
||||
os_memcpy(sbuf, levelstr, llen);
|
||||
os_memcpy(sbuf + llen, buf, len);
|
||||
|
||||
idx = 0;
|
||||
while (dst) {
|
||||
next = dst->next;
|
||||
if (dst->attached && level >= dst->debug_level) {
|
||||
wpa_printf(MSG_DEBUG, "CTRL_IFACE monitor send %p",
|
||||
dst);
|
||||
if (!WriteFile(dst->pipe, sbuf, llen + len, &written,
|
||||
NULL)) {
|
||||
wpa_printf(MSG_DEBUG, "CTRL: WriteFile to dst "
|
||||
"%p failed: %d",
|
||||
dst, (int) GetLastError());
|
||||
dst->errors++;
|
||||
if (dst->errors > 10)
|
||||
ctrl_close_pipe(dst);
|
||||
} else
|
||||
dst->errors = 0;
|
||||
}
|
||||
idx++;
|
||||
dst = next;
|
||||
}
|
||||
os_free(sbuf);
|
||||
}
|
||||
|
||||
|
||||
void wpa_supplicant_ctrl_iface_wait(struct ctrl_iface_priv *priv)
|
||||
{
|
||||
wpa_printf(MSG_DEBUG, "CTRL_IFACE - %s - wait for monitor",
|
||||
priv->wpa_s->ifname);
|
||||
if (priv->ctrl_dst == NULL)
|
||||
return;
|
||||
WaitForSingleObject(priv->ctrl_dst->pipe, INFINITE);
|
||||
}
|
||||
|
||||
|
||||
/* Global ctrl_iface */
|
||||
|
||||
struct ctrl_iface_global_priv;
|
||||
|
||||
struct wpa_global_dst {
|
||||
/* Note: OVERLAPPED must be the first member of struct wpa_global_dst
|
||||
*/
|
||||
OVERLAPPED overlap;
|
||||
struct wpa_global_dst *next, *prev;
|
||||
struct ctrl_iface_global_priv *priv;
|
||||
HANDLE pipe;
|
||||
char req_buf[REQUEST_BUFSIZE];
|
||||
char *rsp_buf;
|
||||
int used;
|
||||
};
|
||||
|
||||
struct ctrl_iface_global_priv {
|
||||
struct wpa_global *global;
|
||||
struct wpa_global_dst *ctrl_dst;
|
||||
};
|
||||
|
||||
|
||||
static void global_flush_broken_pipes(struct ctrl_iface_global_priv *priv)
|
||||
{
|
||||
struct wpa_global_dst *dst, *next;
|
||||
|
||||
dst = priv->ctrl_dst;
|
||||
|
||||
while (dst) {
|
||||
next = dst->next;
|
||||
if (ctrl_broken_pipe(dst->pipe, dst->used)) {
|
||||
wpa_printf(MSG_DEBUG, "CTRL: closing broken pipe %p",
|
||||
dst);
|
||||
global_close_pipe(dst);
|
||||
}
|
||||
dst = next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int global_open_pipe(struct ctrl_iface_global_priv *priv)
|
||||
{
|
||||
struct wpa_global_dst *dst;
|
||||
DWORD err;
|
||||
|
||||
dst = os_zalloc(sizeof(*dst));
|
||||
if (dst == NULL)
|
||||
return -1;
|
||||
wpa_printf(MSG_DEBUG, "CTRL: Open pipe %p", dst);
|
||||
|
||||
dst->priv = priv;
|
||||
dst->pipe = INVALID_HANDLE_VALUE;
|
||||
|
||||
dst->overlap.hEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
|
||||
if (dst->overlap.hEvent == NULL) {
|
||||
wpa_printf(MSG_ERROR, "CTRL: CreateEvent failed: %d",
|
||||
(int) GetLastError());
|
||||
goto fail;
|
||||
}
|
||||
|
||||
eloop_register_event(dst->overlap.hEvent,
|
||||
sizeof(dst->overlap.hEvent),
|
||||
wpa_supplicant_global_iface_receive, dst, NULL);
|
||||
|
||||
/* TODO: add support for configuring access list for the pipe */
|
||||
dst->pipe = CreateNamedPipe(NAMED_PIPE_PREFIX,
|
||||
PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
|
||||
PIPE_TYPE_MESSAGE |
|
||||
PIPE_READMODE_MESSAGE |
|
||||
PIPE_WAIT,
|
||||
10, REPLY_BUFSIZE, REQUEST_BUFSIZE,
|
||||
1000, NULL);
|
||||
if (dst->pipe == INVALID_HANDLE_VALUE) {
|
||||
wpa_printf(MSG_ERROR, "CTRL: CreateNamedPipe failed: %d",
|
||||
(int) GetLastError());
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (ConnectNamedPipe(dst->pipe, &dst->overlap)) {
|
||||
wpa_printf(MSG_ERROR, "CTRL: ConnectNamedPipe failed: %d",
|
||||
(int) GetLastError());
|
||||
CloseHandle(dst->pipe);
|
||||
os_free(dst);
|
||||
return -1;
|
||||
}
|
||||
|
||||
err = GetLastError();
|
||||
switch (err) {
|
||||
case ERROR_IO_PENDING:
|
||||
wpa_printf(MSG_DEBUG, "CTRL: ConnectNamedPipe: connection in "
|
||||
"progress");
|
||||
break;
|
||||
case ERROR_PIPE_CONNECTED:
|
||||
wpa_printf(MSG_DEBUG, "CTRL: ConnectNamedPipe: already "
|
||||
"connected");
|
||||
if (SetEvent(dst->overlap.hEvent))
|
||||
break;
|
||||
/* fall through */
|
||||
default:
|
||||
wpa_printf(MSG_DEBUG, "CTRL: ConnectNamedPipe error: %d",
|
||||
(int) err);
|
||||
CloseHandle(dst->pipe);
|
||||
os_free(dst);
|
||||
return -1;
|
||||
}
|
||||
|
||||
dst->next = priv->ctrl_dst;
|
||||
if (dst->next)
|
||||
dst->next->prev = dst;
|
||||
priv->ctrl_dst = dst;
|
||||
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
global_close_pipe(dst);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
static void global_close_pipe(struct wpa_global_dst *dst)
|
||||
{
|
||||
wpa_printf(MSG_DEBUG, "CTRL: close pipe %p", dst);
|
||||
|
||||
if (dst->overlap.hEvent) {
|
||||
eloop_unregister_event(dst->overlap.hEvent,
|
||||
sizeof(dst->overlap.hEvent));
|
||||
CloseHandle(dst->overlap.hEvent);
|
||||
}
|
||||
|
||||
if (dst->pipe != INVALID_HANDLE_VALUE) {
|
||||
/*
|
||||
* Could use FlushFileBuffers() here to guarantee that all data
|
||||
* gets delivered to the client, but that can block, so let's
|
||||
* not do this for now.
|
||||
* FlushFileBuffers(dst->pipe);
|
||||
*/
|
||||
CloseHandle(dst->pipe);
|
||||
}
|
||||
|
||||
if (dst->prev)
|
||||
dst->prev->next = dst->next;
|
||||
else
|
||||
dst->priv->ctrl_dst = dst->next;
|
||||
if (dst->next)
|
||||
dst->next->prev = dst->prev;
|
||||
|
||||
os_free(dst->rsp_buf);
|
||||
os_free(dst);
|
||||
}
|
||||
|
||||
|
||||
static VOID WINAPI global_iface_write_completed(DWORD err, DWORD bytes,
|
||||
LPOVERLAPPED overlap)
|
||||
{
|
||||
struct wpa_global_dst *dst = (struct wpa_global_dst *) overlap;
|
||||
wpa_printf(MSG_DEBUG, "CTRL: Overlapped write completed: dst=%p "
|
||||
"err=%d bytes=%d", dst, (int) err, (int) bytes);
|
||||
if (err) {
|
||||
global_close_pipe(dst);
|
||||
return;
|
||||
}
|
||||
|
||||
os_free(dst->rsp_buf);
|
||||
dst->rsp_buf = NULL;
|
||||
|
||||
if (!ReadFileEx(dst->pipe, dst->req_buf, sizeof(dst->req_buf),
|
||||
&dst->overlap, global_iface_read_completed)) {
|
||||
wpa_printf(MSG_DEBUG, "CTRL: ReadFileEx failed: %d",
|
||||
(int) GetLastError());
|
||||
global_close_pipe(dst);
|
||||
/* FIX: if this was the pipe waiting for new global
|
||||
* connections, at this point there are no open global pipes..
|
||||
* Should try to open a new pipe.. */
|
||||
return;
|
||||
}
|
||||
wpa_printf(MSG_DEBUG, "CTRL: Overlapped read started for %p", dst);
|
||||
}
|
||||
|
||||
|
||||
static void wpa_supplicant_global_iface_rx(struct wpa_global_dst *dst,
|
||||
size_t len)
|
||||
{
|
||||
struct wpa_global *global = dst->priv->global;
|
||||
char *reply = NULL, *send_buf;
|
||||
size_t reply_len = 0, send_len;
|
||||
char *buf = dst->req_buf;
|
||||
|
||||
dst->used = 1;
|
||||
if (len >= REQUEST_BUFSIZE)
|
||||
len = REQUEST_BUFSIZE - 1;
|
||||
buf[len] = '\0';
|
||||
|
||||
reply = wpa_supplicant_global_ctrl_iface_process(global, buf,
|
||||
&reply_len);
|
||||
if (reply) {
|
||||
send_buf = reply;
|
||||
send_len = reply_len;
|
||||
} else if (reply_len) {
|
||||
send_buf = "FAIL\n";
|
||||
send_len = 5;
|
||||
} else {
|
||||
os_free(dst->rsp_buf);
|
||||
dst->rsp_buf = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
os_free(dst->rsp_buf);
|
||||
dst->rsp_buf = os_malloc(send_len);
|
||||
if (dst->rsp_buf == NULL) {
|
||||
global_close_pipe(dst);
|
||||
os_free(reply);
|
||||
return;
|
||||
}
|
||||
os_memcpy(dst->rsp_buf, send_buf, send_len);
|
||||
os_free(reply);
|
||||
|
||||
if (!WriteFileEx(dst->pipe, dst->rsp_buf, send_len, &dst->overlap,
|
||||
global_iface_write_completed)) {
|
||||
wpa_printf(MSG_DEBUG, "CTRL: WriteFileEx failed: %d",
|
||||
(int) GetLastError());
|
||||
global_close_pipe(dst);
|
||||
} else {
|
||||
wpa_printf(MSG_DEBUG, "CTRL: Overlapped write started for %p",
|
||||
dst);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static VOID WINAPI global_iface_read_completed(DWORD err, DWORD bytes,
|
||||
LPOVERLAPPED overlap)
|
||||
{
|
||||
struct wpa_global_dst *dst = (struct wpa_global_dst *) overlap;
|
||||
wpa_printf(MSG_DEBUG, "CTRL: Overlapped read completed: dst=%p err=%d "
|
||||
"bytes=%d", dst, (int) err, (int) bytes);
|
||||
if (err == 0 && bytes > 0)
|
||||
wpa_supplicant_global_iface_rx(dst, bytes);
|
||||
}
|
||||
|
||||
|
||||
static void wpa_supplicant_global_iface_receive(void *eloop_data,
|
||||
void *user_ctx)
|
||||
{
|
||||
struct wpa_global_dst *dst = eloop_data;
|
||||
struct ctrl_iface_global_priv *priv = dst->priv;
|
||||
DWORD bytes;
|
||||
|
||||
wpa_printf(MSG_DEBUG, "CTRL: wpa_supplicant_global_iface_receive");
|
||||
ResetEvent(dst->overlap.hEvent);
|
||||
|
||||
if (!GetOverlappedResult(dst->pipe, &dst->overlap, &bytes, FALSE)) {
|
||||
wpa_printf(MSG_DEBUG, "CTRL: GetOverlappedResult failed: %d",
|
||||
(int) GetLastError());
|
||||
return;
|
||||
}
|
||||
wpa_printf(MSG_DEBUG, "CTRL: GetOverlappedResult: New client "
|
||||
"connected");
|
||||
|
||||
/* Open a new named pipe for the next client. */
|
||||
if (global_open_pipe(priv) < 0) {
|
||||
wpa_printf(MSG_DEBUG, "CTRL: global_open_pipe failed");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Use write completion function to start reading a command */
|
||||
global_iface_write_completed(0, 0, &dst->overlap);
|
||||
|
||||
global_flush_broken_pipes(priv);
|
||||
}
|
||||
|
||||
|
||||
struct ctrl_iface_global_priv *
|
||||
wpa_supplicant_global_ctrl_iface_init(struct wpa_global *global)
|
||||
{
|
||||
struct ctrl_iface_global_priv *priv;
|
||||
|
||||
priv = os_zalloc(sizeof(*priv));
|
||||
if (priv == NULL)
|
||||
return NULL;
|
||||
priv->global = global;
|
||||
|
||||
if (global_open_pipe(priv) < 0) {
|
||||
os_free(priv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return priv;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
wpa_supplicant_global_ctrl_iface_deinit(struct ctrl_iface_global_priv *priv)
|
||||
{
|
||||
while (priv->ctrl_dst)
|
||||
global_close_pipe(priv->ctrl_dst);
|
||||
os_free(priv);
|
||||
}
|
@ -1,153 +0,0 @@
|
||||
/*
|
||||
* WPA Supplicant - driver interaction with Linux Host AP driver
|
||||
* Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#ifndef HOSTAP_DRIVER_H
|
||||
#define HOSTAP_DRIVER_H
|
||||
|
||||
#define PRISM2_IOCTL_PRISM2_PARAM (SIOCIWFIRSTPRIV + 0)
|
||||
#define PRISM2_IOCTL_RESET (SIOCIWFIRSTPRIV + 6)
|
||||
#define PRISM2_IOCTL_HOSTAPD (SIOCDEVPRIVATE + 14)
|
||||
|
||||
/* PRISM2_IOCTL_PRISM2_PARAM ioctl() subtypes: */
|
||||
enum {
|
||||
/* PRISM2_PARAM_PTYPE = 1, */ /* REMOVED 2003-10-22 */
|
||||
PRISM2_PARAM_TXRATECTRL = 2,
|
||||
PRISM2_PARAM_BEACON_INT = 3,
|
||||
PRISM2_PARAM_PSEUDO_IBSS = 4,
|
||||
PRISM2_PARAM_ALC = 5,
|
||||
/* PRISM2_PARAM_TXPOWER = 6, */ /* REMOVED 2003-10-22 */
|
||||
PRISM2_PARAM_DUMP = 7,
|
||||
PRISM2_PARAM_OTHER_AP_POLICY = 8,
|
||||
PRISM2_PARAM_AP_MAX_INACTIVITY = 9,
|
||||
PRISM2_PARAM_AP_BRIDGE_PACKETS = 10,
|
||||
PRISM2_PARAM_DTIM_PERIOD = 11,
|
||||
PRISM2_PARAM_AP_NULLFUNC_ACK = 12,
|
||||
PRISM2_PARAM_MAX_WDS = 13,
|
||||
PRISM2_PARAM_AP_AUTOM_AP_WDS = 14,
|
||||
PRISM2_PARAM_AP_AUTH_ALGS = 15,
|
||||
PRISM2_PARAM_MONITOR_ALLOW_FCSERR = 16,
|
||||
PRISM2_PARAM_HOST_ENCRYPT = 17,
|
||||
PRISM2_PARAM_HOST_DECRYPT = 18,
|
||||
PRISM2_PARAM_BUS_MASTER_THRESHOLD_RX = 19,
|
||||
PRISM2_PARAM_BUS_MASTER_THRESHOLD_TX = 20,
|
||||
PRISM2_PARAM_HOST_ROAMING = 21,
|
||||
PRISM2_PARAM_BCRX_STA_KEY = 22,
|
||||
PRISM2_PARAM_IEEE_802_1X = 23,
|
||||
PRISM2_PARAM_ANTSEL_TX = 24,
|
||||
PRISM2_PARAM_ANTSEL_RX = 25,
|
||||
PRISM2_PARAM_MONITOR_TYPE = 26,
|
||||
PRISM2_PARAM_WDS_TYPE = 27,
|
||||
PRISM2_PARAM_HOSTSCAN = 28,
|
||||
PRISM2_PARAM_AP_SCAN = 29,
|
||||
PRISM2_PARAM_ENH_SEC = 30,
|
||||
PRISM2_PARAM_IO_DEBUG = 31,
|
||||
PRISM2_PARAM_BASIC_RATES = 32,
|
||||
PRISM2_PARAM_OPER_RATES = 33,
|
||||
PRISM2_PARAM_HOSTAPD = 34,
|
||||
PRISM2_PARAM_HOSTAPD_STA = 35,
|
||||
PRISM2_PARAM_WPA = 36,
|
||||
PRISM2_PARAM_PRIVACY_INVOKED = 37,
|
||||
PRISM2_PARAM_TKIP_COUNTERMEASURES = 38,
|
||||
PRISM2_PARAM_DROP_UNENCRYPTED = 39,
|
||||
PRISM2_PARAM_SCAN_CHANNEL_MASK = 40,
|
||||
};
|
||||
|
||||
/* PRISM2_IOCTL_HOSTAPD ioctl() cmd: */
|
||||
enum {
|
||||
PRISM2_HOSTAPD_FLUSH = 1,
|
||||
PRISM2_HOSTAPD_ADD_STA = 2,
|
||||
PRISM2_HOSTAPD_REMOVE_STA = 3,
|
||||
PRISM2_HOSTAPD_GET_INFO_STA = 4,
|
||||
/* REMOVED: PRISM2_HOSTAPD_RESET_TXEXC_STA = 5, */
|
||||
PRISM2_SET_ENCRYPTION = 6,
|
||||
PRISM2_GET_ENCRYPTION = 7,
|
||||
PRISM2_HOSTAPD_SET_FLAGS_STA = 8,
|
||||
PRISM2_HOSTAPD_GET_RID = 9,
|
||||
PRISM2_HOSTAPD_SET_RID = 10,
|
||||
PRISM2_HOSTAPD_SET_ASSOC_AP_ADDR = 11,
|
||||
PRISM2_HOSTAPD_SET_GENERIC_ELEMENT = 12,
|
||||
PRISM2_HOSTAPD_MLME = 13,
|
||||
PRISM2_HOSTAPD_SCAN_REQ = 14,
|
||||
PRISM2_HOSTAPD_STA_CLEAR_STATS = 15,
|
||||
};
|
||||
|
||||
#define PRISM2_HOSTAPD_MAX_BUF_SIZE 1024
|
||||
#define PRISM2_HOSTAPD_RID_HDR_LEN \
|
||||
((int) (&((struct prism2_hostapd_param *) 0)->u.rid.data))
|
||||
#define PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN \
|
||||
((int) (&((struct prism2_hostapd_param *) 0)->u.generic_elem.data))
|
||||
|
||||
/* Maximum length for algorithm names (-1 for nul termination) used in ioctl()
|
||||
*/
|
||||
#define HOSTAP_CRYPT_ALG_NAME_LEN 16
|
||||
|
||||
|
||||
struct prism2_hostapd_param {
|
||||
u32 cmd;
|
||||
u8 sta_addr[ETH_ALEN];
|
||||
union {
|
||||
struct {
|
||||
u16 aid;
|
||||
u16 capability;
|
||||
u8 tx_supp_rates;
|
||||
} add_sta;
|
||||
struct {
|
||||
u32 inactive_sec;
|
||||
} get_info_sta;
|
||||
struct {
|
||||
u8 alg[HOSTAP_CRYPT_ALG_NAME_LEN];
|
||||
u32 flags;
|
||||
u32 err;
|
||||
u8 idx;
|
||||
u8 seq[8]; /* sequence counter (set: RX, get: TX) */
|
||||
u16 key_len;
|
||||
u8 key[0];
|
||||
} crypt;
|
||||
struct {
|
||||
u32 flags_and;
|
||||
u32 flags_or;
|
||||
} set_flags_sta;
|
||||
struct {
|
||||
u16 rid;
|
||||
u16 len;
|
||||
u8 data[0];
|
||||
} rid;
|
||||
struct {
|
||||
u8 len;
|
||||
u8 data[0];
|
||||
} generic_elem;
|
||||
struct {
|
||||
#define MLME_STA_DEAUTH 0
|
||||
#define MLME_STA_DISASSOC 1
|
||||
u16 cmd;
|
||||
u16 reason_code;
|
||||
} mlme;
|
||||
struct {
|
||||
u8 ssid_len;
|
||||
u8 ssid[32];
|
||||
} scan_req;
|
||||
} u;
|
||||
};
|
||||
|
||||
#define HOSTAP_CRYPT_FLAG_SET_TX_KEY 0x01
|
||||
#define HOSTAP_CRYPT_FLAG_PERMANENT 0x02
|
||||
|
||||
#define HOSTAP_CRYPT_ERR_UNKNOWN_ALG 2
|
||||
#define HOSTAP_CRYPT_ERR_UNKNOWN_ADDR 3
|
||||
#define HOSTAP_CRYPT_ERR_CRYPT_INIT_FAILED 4
|
||||
#define HOSTAP_CRYPT_ERR_KEY_SET_FAILED 5
|
||||
#define HOSTAP_CRYPT_ERR_TX_KEY_SET_FAILED 6
|
||||
#define HOSTAP_CRYPT_ERR_CARD_CONF_FAILED 7
|
||||
|
||||
#endif /* HOSTAP_DRIVER_H */
|
@ -1,604 +0,0 @@
|
||||
/*
|
||||
* Event loop based on Windows events and WaitForMultipleObjects
|
||||
* Copyright (c) 2002-2006, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
#include <winsock2.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "eloop.h"
|
||||
|
||||
|
||||
struct eloop_sock {
|
||||
int sock;
|
||||
void *eloop_data;
|
||||
void *user_data;
|
||||
eloop_sock_handler handler;
|
||||
WSAEVENT event;
|
||||
};
|
||||
|
||||
struct eloop_event {
|
||||
void *eloop_data;
|
||||
void *user_data;
|
||||
eloop_event_handler handler;
|
||||
HANDLE event;
|
||||
};
|
||||
|
||||
struct eloop_timeout {
|
||||
struct os_time time;
|
||||
void *eloop_data;
|
||||
void *user_data;
|
||||
eloop_timeout_handler handler;
|
||||
struct eloop_timeout *next;
|
||||
};
|
||||
|
||||
struct eloop_signal {
|
||||
int sig;
|
||||
void *user_data;
|
||||
eloop_signal_handler handler;
|
||||
int signaled;
|
||||
};
|
||||
|
||||
struct eloop_data {
|
||||
void *user_data;
|
||||
|
||||
int max_sock;
|
||||
size_t reader_count;
|
||||
struct eloop_sock *readers;
|
||||
|
||||
size_t event_count;
|
||||
struct eloop_event *events;
|
||||
|
||||
struct eloop_timeout *timeout;
|
||||
|
||||
int signal_count;
|
||||
struct eloop_signal *signals;
|
||||
int signaled;
|
||||
int pending_terminate;
|
||||
|
||||
int terminate;
|
||||
int reader_table_changed;
|
||||
|
||||
struct eloop_signal term_signal;
|
||||
HANDLE term_event;
|
||||
|
||||
HANDLE *handles;
|
||||
size_t num_handles;
|
||||
};
|
||||
|
||||
static struct eloop_data eloop;
|
||||
|
||||
|
||||
int eloop_init(void *user_data)
|
||||
{
|
||||
os_memset(&eloop, 0, sizeof(eloop));
|
||||
eloop.user_data = user_data;
|
||||
eloop.num_handles = 1;
|
||||
eloop.handles = os_malloc(eloop.num_handles *
|
||||
sizeof(eloop.handles[0]));
|
||||
if (eloop.handles == NULL)
|
||||
return -1;
|
||||
|
||||
eloop.term_event = CreateEvent(NULL, FALSE, FALSE, NULL);
|
||||
if (eloop.term_event == NULL) {
|
||||
printf("CreateEvent() failed: %d\n",
|
||||
(int) GetLastError());
|
||||
os_free(eloop.handles);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int eloop_prepare_handles(void)
|
||||
{
|
||||
HANDLE *n;
|
||||
|
||||
if (eloop.num_handles > eloop.reader_count + eloop.event_count + 8)
|
||||
return 0;
|
||||
n = os_realloc(eloop.handles,
|
||||
eloop.num_handles * 2 * sizeof(eloop.handles[0]));
|
||||
if (n == NULL)
|
||||
return -1;
|
||||
eloop.handles = n;
|
||||
eloop.num_handles *= 2;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int eloop_register_read_sock(int sock, eloop_sock_handler handler,
|
||||
void *eloop_data, void *user_data)
|
||||
{
|
||||
WSAEVENT event;
|
||||
struct eloop_sock *tmp;
|
||||
|
||||
if (eloop_prepare_handles())
|
||||
return -1;
|
||||
|
||||
event = WSACreateEvent();
|
||||
if (event == WSA_INVALID_EVENT) {
|
||||
printf("WSACreateEvent() failed: %d\n", WSAGetLastError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (WSAEventSelect(sock, event, FD_READ)) {
|
||||
printf("WSAEventSelect() failed: %d\n", WSAGetLastError());
|
||||
WSACloseEvent(event);
|
||||
return -1;
|
||||
}
|
||||
tmp = os_realloc(eloop.readers,
|
||||
(eloop.reader_count + 1) * sizeof(struct eloop_sock));
|
||||
if (tmp == NULL) {
|
||||
WSAEventSelect(sock, event, 0);
|
||||
WSACloseEvent(event);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tmp[eloop.reader_count].sock = sock;
|
||||
tmp[eloop.reader_count].eloop_data = eloop_data;
|
||||
tmp[eloop.reader_count].user_data = user_data;
|
||||
tmp[eloop.reader_count].handler = handler;
|
||||
tmp[eloop.reader_count].event = event;
|
||||
eloop.reader_count++;
|
||||
eloop.readers = tmp;
|
||||
if (sock > eloop.max_sock)
|
||||
eloop.max_sock = sock;
|
||||
eloop.reader_table_changed = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void eloop_unregister_read_sock(int sock)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (eloop.readers == NULL || eloop.reader_count == 0)
|
||||
return;
|
||||
|
||||
for (i = 0; i < eloop.reader_count; i++) {
|
||||
if (eloop.readers[i].sock == sock)
|
||||
break;
|
||||
}
|
||||
if (i == eloop.reader_count)
|
||||
return;
|
||||
|
||||
WSAEventSelect(eloop.readers[i].sock, eloop.readers[i].event, 0);
|
||||
WSACloseEvent(eloop.readers[i].event);
|
||||
|
||||
if (i != eloop.reader_count - 1) {
|
||||
os_memmove(&eloop.readers[i], &eloop.readers[i + 1],
|
||||
(eloop.reader_count - i - 1) *
|
||||
sizeof(struct eloop_sock));
|
||||
}
|
||||
eloop.reader_count--;
|
||||
eloop.reader_table_changed = 1;
|
||||
}
|
||||
|
||||
|
||||
int eloop_register_event(void *event, size_t event_size,
|
||||
eloop_event_handler handler,
|
||||
void *eloop_data, void *user_data)
|
||||
{
|
||||
struct eloop_event *tmp;
|
||||
HANDLE h = event;
|
||||
|
||||
if (event_size != sizeof(HANDLE) || h == INVALID_HANDLE_VALUE)
|
||||
return -1;
|
||||
|
||||
if (eloop_prepare_handles())
|
||||
return -1;
|
||||
|
||||
tmp = os_realloc(eloop.events,
|
||||
(eloop.event_count + 1) * sizeof(struct eloop_event));
|
||||
if (tmp == NULL)
|
||||
return -1;
|
||||
|
||||
tmp[eloop.event_count].eloop_data = eloop_data;
|
||||
tmp[eloop.event_count].user_data = user_data;
|
||||
tmp[eloop.event_count].handler = handler;
|
||||
tmp[eloop.event_count].event = h;
|
||||
eloop.event_count++;
|
||||
eloop.events = tmp;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void eloop_unregister_event(void *event, size_t event_size)
|
||||
{
|
||||
size_t i;
|
||||
HANDLE h = event;
|
||||
|
||||
if (eloop.events == NULL || eloop.event_count == 0 ||
|
||||
event_size != sizeof(HANDLE))
|
||||
return;
|
||||
|
||||
for (i = 0; i < eloop.event_count; i++) {
|
||||
if (eloop.events[i].event == h)
|
||||
break;
|
||||
}
|
||||
if (i == eloop.event_count)
|
||||
return;
|
||||
|
||||
if (i != eloop.event_count - 1) {
|
||||
os_memmove(&eloop.events[i], &eloop.events[i + 1],
|
||||
(eloop.event_count - i - 1) *
|
||||
sizeof(struct eloop_event));
|
||||
}
|
||||
eloop.event_count--;
|
||||
}
|
||||
|
||||
|
||||
int eloop_register_timeout(unsigned int secs, unsigned int usecs,
|
||||
eloop_timeout_handler handler,
|
||||
void *eloop_data, void *user_data)
|
||||
{
|
||||
struct eloop_timeout *timeout, *tmp, *prev;
|
||||
|
||||
timeout = os_malloc(sizeof(*timeout));
|
||||
if (timeout == NULL)
|
||||
return -1;
|
||||
os_get_time(&timeout->time);
|
||||
timeout->time.sec += secs;
|
||||
timeout->time.usec += usecs;
|
||||
while (timeout->time.usec >= 1000000) {
|
||||
timeout->time.sec++;
|
||||
timeout->time.usec -= 1000000;
|
||||
}
|
||||
timeout->eloop_data = eloop_data;
|
||||
timeout->user_data = user_data;
|
||||
timeout->handler = handler;
|
||||
timeout->next = NULL;
|
||||
|
||||
if (eloop.timeout == NULL) {
|
||||
eloop.timeout = timeout;
|
||||
return 0;
|
||||
}
|
||||
|
||||
prev = NULL;
|
||||
tmp = eloop.timeout;
|
||||
while (tmp != NULL) {
|
||||
if (os_time_before(&timeout->time, &tmp->time))
|
||||
break;
|
||||
prev = tmp;
|
||||
tmp = tmp->next;
|
||||
}
|
||||
|
||||
if (prev == NULL) {
|
||||
timeout->next = eloop.timeout;
|
||||
eloop.timeout = timeout;
|
||||
} else {
|
||||
timeout->next = prev->next;
|
||||
prev->next = timeout;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int eloop_cancel_timeout(eloop_timeout_handler handler,
|
||||
void *eloop_data, void *user_data)
|
||||
{
|
||||
struct eloop_timeout *timeout, *prev, *next;
|
||||
int removed = 0;
|
||||
|
||||
prev = NULL;
|
||||
timeout = eloop.timeout;
|
||||
while (timeout != NULL) {
|
||||
next = timeout->next;
|
||||
|
||||
if (timeout->handler == handler &&
|
||||
(timeout->eloop_data == eloop_data ||
|
||||
eloop_data == ELOOP_ALL_CTX) &&
|
||||
(timeout->user_data == user_data ||
|
||||
user_data == ELOOP_ALL_CTX)) {
|
||||
if (prev == NULL)
|
||||
eloop.timeout = next;
|
||||
else
|
||||
prev->next = next;
|
||||
os_free(timeout);
|
||||
removed++;
|
||||
} else
|
||||
prev = timeout;
|
||||
|
||||
timeout = next;
|
||||
}
|
||||
|
||||
return removed;
|
||||
}
|
||||
|
||||
|
||||
/* TODO: replace with suitable signal handler */
|
||||
#if 0
|
||||
static void eloop_handle_signal(int sig)
|
||||
{
|
||||
int i;
|
||||
|
||||
eloop.signaled++;
|
||||
for (i = 0; i < eloop.signal_count; i++) {
|
||||
if (eloop.signals[i].sig == sig) {
|
||||
eloop.signals[i].signaled++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static void eloop_process_pending_signals(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (eloop.signaled == 0)
|
||||
return;
|
||||
eloop.signaled = 0;
|
||||
|
||||
if (eloop.pending_terminate) {
|
||||
eloop.pending_terminate = 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < eloop.signal_count; i++) {
|
||||
if (eloop.signals[i].signaled) {
|
||||
eloop.signals[i].signaled = 0;
|
||||
eloop.signals[i].handler(eloop.signals[i].sig,
|
||||
eloop.user_data,
|
||||
eloop.signals[i].user_data);
|
||||
}
|
||||
}
|
||||
|
||||
if (eloop.term_signal.signaled) {
|
||||
eloop.term_signal.signaled = 0;
|
||||
eloop.term_signal.handler(eloop.term_signal.sig,
|
||||
eloop.user_data,
|
||||
eloop.term_signal.user_data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int eloop_register_signal(int sig, eloop_signal_handler handler,
|
||||
void *user_data)
|
||||
{
|
||||
struct eloop_signal *tmp;
|
||||
|
||||
tmp = os_realloc(eloop.signals,
|
||||
(eloop.signal_count + 1) *
|
||||
sizeof(struct eloop_signal));
|
||||
if (tmp == NULL)
|
||||
return -1;
|
||||
|
||||
tmp[eloop.signal_count].sig = sig;
|
||||
tmp[eloop.signal_count].user_data = user_data;
|
||||
tmp[eloop.signal_count].handler = handler;
|
||||
tmp[eloop.signal_count].signaled = 0;
|
||||
eloop.signal_count++;
|
||||
eloop.signals = tmp;
|
||||
|
||||
/* TODO: register signal handler */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#ifndef _WIN32_WCE
|
||||
static BOOL eloop_handle_console_ctrl(DWORD type)
|
||||
{
|
||||
switch (type) {
|
||||
case CTRL_C_EVENT:
|
||||
case CTRL_BREAK_EVENT:
|
||||
eloop.signaled++;
|
||||
eloop.term_signal.signaled++;
|
||||
SetEvent(eloop.term_event);
|
||||
return TRUE;
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
#endif /* _WIN32_WCE */
|
||||
|
||||
|
||||
int eloop_register_signal_terminate(eloop_signal_handler handler,
|
||||
void *user_data)
|
||||
{
|
||||
#ifndef _WIN32_WCE
|
||||
if (SetConsoleCtrlHandler((PHANDLER_ROUTINE) eloop_handle_console_ctrl,
|
||||
TRUE) == 0) {
|
||||
printf("SetConsoleCtrlHandler() failed: %d\n",
|
||||
(int) GetLastError());
|
||||
return -1;
|
||||
}
|
||||
#endif /* _WIN32_WCE */
|
||||
|
||||
eloop.term_signal.handler = handler;
|
||||
eloop.term_signal.user_data = user_data;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int eloop_register_signal_reconfig(eloop_signal_handler handler,
|
||||
void *user_data)
|
||||
{
|
||||
/* TODO */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void eloop_run(void)
|
||||
{
|
||||
struct os_time tv, now;
|
||||
DWORD count, ret, timeout, err;
|
||||
size_t i;
|
||||
|
||||
while (!eloop.terminate &&
|
||||
(eloop.timeout || eloop.reader_count > 0 ||
|
||||
eloop.event_count > 0)) {
|
||||
if (eloop.timeout) {
|
||||
os_get_time(&now);
|
||||
if (os_time_before(&now, &eloop.timeout->time))
|
||||
os_time_sub(&eloop.timeout->time, &now, &tv);
|
||||
else
|
||||
tv.sec = tv.usec = 0;
|
||||
}
|
||||
|
||||
count = 0;
|
||||
for (i = 0; i < eloop.event_count; i++)
|
||||
eloop.handles[count++] = eloop.events[i].event;
|
||||
|
||||
for (i = 0; i < eloop.reader_count; i++)
|
||||
eloop.handles[count++] = eloop.readers[i].event;
|
||||
|
||||
if (eloop.term_event)
|
||||
eloop.handles[count++] = eloop.term_event;
|
||||
|
||||
if (eloop.timeout)
|
||||
timeout = tv.sec * 1000 + tv.usec / 1000;
|
||||
else
|
||||
timeout = INFINITE;
|
||||
|
||||
if (count > MAXIMUM_WAIT_OBJECTS) {
|
||||
printf("WaitForMultipleObjects: Too many events: "
|
||||
"%d > %d (ignoring extra events)\n",
|
||||
(int) count, MAXIMUM_WAIT_OBJECTS);
|
||||
count = MAXIMUM_WAIT_OBJECTS;
|
||||
}
|
||||
#ifdef _WIN32_WCE
|
||||
ret = WaitForMultipleObjects(count, eloop.handles, FALSE,
|
||||
timeout);
|
||||
#else /* _WIN32_WCE */
|
||||
ret = WaitForMultipleObjectsEx(count, eloop.handles, FALSE,
|
||||
timeout, TRUE);
|
||||
#endif /* _WIN32_WCE */
|
||||
err = GetLastError();
|
||||
|
||||
eloop_process_pending_signals();
|
||||
|
||||
/* check if some registered timeouts have occurred */
|
||||
if (eloop.timeout) {
|
||||
struct eloop_timeout *tmp;
|
||||
|
||||
os_get_time(&now);
|
||||
if (!os_time_before(&now, &eloop.timeout->time)) {
|
||||
tmp = eloop.timeout;
|
||||
eloop.timeout = eloop.timeout->next;
|
||||
tmp->handler(tmp->eloop_data,
|
||||
tmp->user_data);
|
||||
os_free(tmp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (ret == WAIT_FAILED) {
|
||||
printf("WaitForMultipleObjects(count=%d) failed: %d\n",
|
||||
(int) count, (int) err);
|
||||
os_sleep(1, 0);
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifndef _WIN32_WCE
|
||||
if (ret == WAIT_IO_COMPLETION)
|
||||
continue;
|
||||
#endif /* _WIN32_WCE */
|
||||
|
||||
if (ret == WAIT_TIMEOUT)
|
||||
continue;
|
||||
|
||||
while (ret >= WAIT_OBJECT_0 &&
|
||||
ret < WAIT_OBJECT_0 + eloop.event_count) {
|
||||
eloop.events[ret].handler(
|
||||
eloop.events[ret].eloop_data,
|
||||
eloop.events[ret].user_data);
|
||||
ret = WaitForMultipleObjects(eloop.event_count,
|
||||
eloop.handles, FALSE, 0);
|
||||
}
|
||||
|
||||
eloop.reader_table_changed = 0;
|
||||
for (i = 0; i < eloop.reader_count; i++) {
|
||||
WSANETWORKEVENTS events;
|
||||
if (WSAEnumNetworkEvents(eloop.readers[i].sock,
|
||||
eloop.readers[i].event,
|
||||
&events) == 0 &&
|
||||
(events.lNetworkEvents & FD_READ)) {
|
||||
eloop.readers[i].handler(
|
||||
eloop.readers[i].sock,
|
||||
eloop.readers[i].eloop_data,
|
||||
eloop.readers[i].user_data);
|
||||
if (eloop.reader_table_changed)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void eloop_terminate(void)
|
||||
{
|
||||
eloop.terminate = 1;
|
||||
SetEvent(eloop.term_event);
|
||||
}
|
||||
|
||||
|
||||
void eloop_destroy(void)
|
||||
{
|
||||
struct eloop_timeout *timeout, *prev;
|
||||
|
||||
timeout = eloop.timeout;
|
||||
while (timeout != NULL) {
|
||||
prev = timeout;
|
||||
timeout = timeout->next;
|
||||
os_free(prev);
|
||||
}
|
||||
os_free(eloop.readers);
|
||||
os_free(eloop.signals);
|
||||
if (eloop.term_event)
|
||||
CloseHandle(eloop.term_event);
|
||||
os_free(eloop.handles);
|
||||
eloop.handles = NULL;
|
||||
os_free(eloop.events);
|
||||
eloop.events = NULL;
|
||||
}
|
||||
|
||||
|
||||
int eloop_terminated(void)
|
||||
{
|
||||
return eloop.terminate;
|
||||
}
|
||||
|
||||
|
||||
void eloop_wait_for_read_sock(int sock)
|
||||
{
|
||||
WSAEVENT event;
|
||||
|
||||
event = WSACreateEvent();
|
||||
if (event == WSA_INVALID_EVENT) {
|
||||
printf("WSACreateEvent() failed: %d\n", WSAGetLastError());
|
||||
return;
|
||||
}
|
||||
|
||||
if (WSAEventSelect(sock, event, FD_READ)) {
|
||||
printf("WSAEventSelect() failed: %d\n", WSAGetLastError());
|
||||
WSACloseEvent(event);
|
||||
return ;
|
||||
}
|
||||
|
||||
WaitForSingleObject(event, INFINITE);
|
||||
WSAEventSelect(sock, event, 0);
|
||||
WSACloseEvent(event);
|
||||
}
|
||||
|
||||
|
||||
void * eloop_get_user_data(void)
|
||||
{
|
||||
return eloop.user_data;
|
||||
}
|
@ -441,9 +441,10 @@ wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s, struct wpa_ssid *group,
|
||||
wpa_printf(MSG_DEBUG, " skip - disabled");
|
||||
continue;
|
||||
}
|
||||
if (bss->ssid_len != ssid->ssid_len ||
|
||||
os_memcmp(bss->ssid, ssid->ssid,
|
||||
bss->ssid_len) != 0) {
|
||||
if (ssid->ssid_len != 0 &&
|
||||
(bss->ssid_len != ssid->ssid_len ||
|
||||
os_memcmp(bss->ssid, ssid->ssid,
|
||||
bss->ssid_len) != 0)) {
|
||||
wpa_printf(MSG_DEBUG, " skip - "
|
||||
"SSID mismatch");
|
||||
continue;
|
||||
@ -466,8 +467,8 @@ wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s, struct wpa_ssid *group,
|
||||
}
|
||||
|
||||
if ((ssid->key_mgmt &
|
||||
(WPA_KEY_MGMT_IEEE8021X | WPA_KEY_MGMT_PSK)) ||
|
||||
bss->wpa_ie_len != 0 || bss->rsn_ie_len != 0) {
|
||||
(WPA_KEY_MGMT_IEEE8021X | WPA_KEY_MGMT_PSK)) &&
|
||||
(bss->wpa_ie_len != 0 || bss->rsn_ie_len != 0)) {
|
||||
wpa_printf(MSG_DEBUG, " skip - "
|
||||
"WPA network");
|
||||
continue;
|
||||
@ -517,7 +518,7 @@ static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s)
|
||||
|
||||
wpa_supplicant_dbus_notify_scan_results(wpa_s);
|
||||
|
||||
if (wpa_s->conf->ap_scan == 2)
|
||||
if (wpa_s->conf->ap_scan == 2 || wpa_s->disconnected)
|
||||
return;
|
||||
results = wpa_s->scan_results;
|
||||
num = wpa_s->num_scan_results;
|
||||
|
@ -10,6 +10,8 @@
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
@ -39,11 +41,12 @@ static void usage(void)
|
||||
int i;
|
||||
printf("%s\n\n%s\n"
|
||||
"usage:\n"
|
||||
" wpa_supplicant [-BddehLqquvwW] [-P<pid file>] "
|
||||
" wpa_supplicant [-BddhKLqqtuvwW] [-P<pid file>] "
|
||||
"[-g<global ctrl>] \\\n"
|
||||
" -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] "
|
||||
"[-p<driver_param>] \\\n"
|
||||
" [-b<br_ifname> [-N -i<ifname> -c<conf> [-C<ctrl>] "
|
||||
" [-b<br_ifname>] [-f<debug file>] \\\n"
|
||||
" [-N -i<ifname> -c<conf> [-C<ctrl>] "
|
||||
"[-D<driver>] \\\n"
|
||||
" [-p<driver_param>] [-b<br_ifname>] ...]\n"
|
||||
"\n"
|
||||
@ -65,6 +68,9 @@ static void usage(void)
|
||||
" -i = interface name\n"
|
||||
" -d = increase debugging verbosity (-dd even more)\n"
|
||||
" -D = driver name\n"
|
||||
#ifdef CONFIG_DEBUG_FILE
|
||||
" -f = log output to debug file instead of stdout\n"
|
||||
#endif /* CONFIG_DEBUG_FILE */
|
||||
" -g = global ctrl_interface\n"
|
||||
" -K = include keys (passwords, etc.) in debug output\n"
|
||||
" -t = include timestamp in debug messages\n"
|
||||
@ -143,7 +149,7 @@ int main(int argc, char *argv[])
|
||||
wpa_supplicant_fd_workaround();
|
||||
|
||||
for (;;) {
|
||||
c = getopt(argc, argv, "b:Bc:C:D:dg:hi:KLNp:P:qtuvwW");
|
||||
c = getopt(argc, argv, "b:Bc:C:D:df:g:hi:KLNp:P:qtuvwW");
|
||||
if (c < 0)
|
||||
break;
|
||||
switch (c) {
|
||||
@ -172,6 +178,11 @@ int main(int argc, char *argv[])
|
||||
params.wpa_debug_level--;
|
||||
break;
|
||||
#endif /* CONFIG_NO_STDOUT_DEBUG */
|
||||
#ifdef CONFIG_DEBUG_FILE
|
||||
case 'f':
|
||||
params.wpa_debug_file_path = optarg;
|
||||
break;
|
||||
#endif /* CONFIG_DEBUG_FILE */
|
||||
case 'g':
|
||||
params.ctrl_interface = optarg;
|
||||
break;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* WPA Supplicant
|
||||
* Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
|
||||
* Copyright (c) 2003-2008, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
@ -40,7 +40,7 @@
|
||||
|
||||
const char *wpa_supplicant_version =
|
||||
"wpa_supplicant v" VERSION_STR "\n"
|
||||
"Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi> and contributors";
|
||||
"Copyright (c) 2003-2008, Jouni Malinen <j@w1.fi> and contributors";
|
||||
|
||||
const char *wpa_supplicant_license =
|
||||
"This program is free software. You can distribute it and/or modify it\n"
|
||||
@ -108,7 +108,6 @@ const char *wpa_supplicant_full_license5 =
|
||||
|
||||
extern struct wpa_driver_ops *wpa_supplicant_drivers[];
|
||||
|
||||
extern int wpa_debug_use_file;
|
||||
extern int wpa_debug_level;
|
||||
extern int wpa_debug_show_keys;
|
||||
extern int wpa_debug_timestamp;
|
||||
@ -521,7 +520,7 @@ static void wpa_supplicant_timeout(void *eloop_ctx, void *timeout_ctx)
|
||||
if (os_memcmp(bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) == 0)
|
||||
bssid = wpa_s->pending_bssid;
|
||||
wpa_msg(wpa_s, MSG_INFO, "Authentication with " MACSTR " timed out.",
|
||||
MAC2STR(wpa_s->bssid));
|
||||
MAC2STR(bssid));
|
||||
wpa_blacklist_add(wpa_s, bssid);
|
||||
wpa_sm_notify_disassoc(wpa_s->wpa);
|
||||
wpa_supplicant_disassociate(wpa_s, REASON_DEAUTH_LEAVING);
|
||||
@ -902,6 +901,13 @@ int wpa_supplicant_reload_configuration(struct wpa_supplicant *wpa_s)
|
||||
* TODO: should notify EAPOL SM about changes in opensc_engine_path,
|
||||
* pkcs11_engine_path, pkcs11_module_path.
|
||||
*/
|
||||
if (wpa_s->key_mgmt == WPA_KEY_MGMT_PSK) {
|
||||
/*
|
||||
* Clear forced success to clear EAP state for next
|
||||
* authentication.
|
||||
*/
|
||||
eapol_sm_notify_eap_success(wpa_s->eapol, FALSE);
|
||||
}
|
||||
eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
|
||||
wpa_sm_set_config(wpa_s->wpa, NULL);
|
||||
wpa_sm_set_fast_reauth(wpa_s->wpa, wpa_s->conf->fast_reauth);
|
||||
@ -958,7 +964,7 @@ static void wpa_supplicant_scan(void *eloop_ctx, void *timeout_ctx)
|
||||
struct wpa_ssid *ssid;
|
||||
int enabled, scan_req = 0, ret;
|
||||
|
||||
if (wpa_s->disconnected)
|
||||
if (wpa_s->disconnected && !wpa_s->scan_req)
|
||||
return;
|
||||
|
||||
enabled = 0;
|
||||
@ -1463,6 +1469,8 @@ void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
|
||||
params.ssid = ssid->ssid;
|
||||
params.ssid_len = ssid->ssid_len;
|
||||
}
|
||||
if (ssid->mode == 1 && ssid->frequency > 0 && params.freq == 0)
|
||||
params.freq = ssid->frequency; /* Initial channel for IBSS */
|
||||
params.wpa_ie = wpa_ie;
|
||||
params.wpa_ie_len = wpa_ie_len;
|
||||
params.pairwise_suite = cipher_pairwise;
|
||||
@ -2416,7 +2424,7 @@ struct wpa_supplicant * wpa_supplicant_add_iface(struct wpa_global *global,
|
||||
*
|
||||
* This function can be used to dynamically remove network interfaces from
|
||||
* %wpa_supplicant, e.g., when a hotplug network adapter is ejected. In
|
||||
* addition, this function is used to remove all remaining interdaces when
|
||||
* addition, this function is used to remove all remaining interfaces when
|
||||
* %wpa_supplicant is terminated.
|
||||
*/
|
||||
int wpa_supplicant_remove_iface(struct wpa_global *global,
|
||||
@ -2481,8 +2489,7 @@ struct wpa_global * wpa_supplicant_init(struct wpa_params *params)
|
||||
if (params == NULL)
|
||||
return NULL;
|
||||
|
||||
wpa_debug_use_file = params->wpa_debug_use_file;
|
||||
wpa_debug_open_file();
|
||||
wpa_debug_open_file(params->wpa_debug_file_path);
|
||||
|
||||
ret = eap_peer_register_methods();
|
||||
if (ret) {
|
||||
@ -2511,8 +2518,6 @@ struct wpa_global * wpa_supplicant_init(struct wpa_params *params)
|
||||
params->wpa_debug_show_keys;
|
||||
wpa_debug_timestamp = global->params.wpa_debug_timestamp =
|
||||
params->wpa_debug_timestamp;
|
||||
wpa_debug_use_file = global->params.wpa_debug_use_file =
|
||||
params->wpa_debug_use_file;
|
||||
|
||||
if (eloop_init(global)) {
|
||||
wpa_printf(MSG_ERROR, "Failed to initialize event loop");
|
||||
|
Loading…
Reference in New Issue
Block a user