1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
/*
* wpa_supplicant/hostapd / OS specific functions for Win32 systems
* Copyright (c) 2005-2006, Jouni Malinen <jkmaline@cc.hut.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 <wincrypt.h>
#include "os.h"
void os_sleep(os_time_t sec, os_time_t usec)
{
if (sec)
Sleep(sec * 1000);
if (usec)
Sleep(usec / 1000);
}
int os_get_time(struct os_time *t)
{
#ifdef _WIN32_WCE
/* TODO */
return 0;
#else /* _WIN32_WCE */
#define EPOCHFILETIME (116444736000000000ULL)
FILETIME ft;
LARGE_INTEGER li;
ULONGLONG tt;
GetSystemTimeAsFileTime(&ft);
li.LowPart = ft.dwLowDateTime;
li.HighPart = ft.dwHighDateTime;
tt = (li.QuadPart - EPOCHFILETIME) / 10;
t->sec = (os_time_t) (tt / 1000000);
t->usec = (os_time_t) (tt % 1000000);
return 0;
#endif /* _WIN32_WCE */
}
int os_daemonize(const char *pid_file)
{
/* TODO */
return -1;
}
void os_daemonize_terminate(const char *pid_file)
{
}
int os_get_random(unsigned char *buf, size_t len)
{
HCRYPTPROV prov;
BOOL ret;
if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL,
CRYPT_VERIFYCONTEXT))
return -1;
ret = CryptGenRandom(prov, len, buf);
CryptReleaseContext(prov, 0);
return ret ? 0 : -1;
}
unsigned long os_random(void)
{
return rand();
}
char * os_rel2abs_path(const char *rel_path)
{
return _strdup(rel_path);
}
int os_program_init(void)
{
#ifdef CONFIG_NATIVE_WINDOWS
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2, 0), &wsaData)) {
printf("Could not find a usable WinSock.dll\n");
return -1;
}
#endif /* CONFIG_NATIVE_WINDOWS */
return 0;
}
void os_program_deinit(void)
{
#ifdef CONFIG_NATIVE_WINDOWS
WSACleanup();
#endif /* CONFIG_NATIVE_WINDOWS */
}
int os_setenv(const char *name, const char *value, int overwrite)
{
return -1;
}
int os_unsetenv(const char *name)
{
return -1;
}
|