Additional support for working with WLAN added
This commit is contained in:
parent
ea9a08e02a
commit
276546ee18
@ -85,6 +85,7 @@
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\Win.cpp" />
|
||||
<ClCompile Include="..\src\WLAN.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\include\WinStd\Base64.h" />
|
||||
|
@ -35,6 +35,9 @@
|
||||
<ClCompile Include="..\src\Sec.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\WLAN.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\src\StdAfx.h">
|
||||
|
@ -34,6 +34,23 @@ extern DWORD (WINAPI *pfnWlanReasonCodeToString)(__in DWORD dwReasonCode, __in D
|
||||
///
|
||||
/// @{
|
||||
|
||||
namespace winstd {
|
||||
///
|
||||
/// Deleter for unique_ptr using WlanFreeMemory
|
||||
///
|
||||
template <class _Ty> struct WlanFreeMemory_delete;
|
||||
|
||||
///
|
||||
/// Deleter for unique_ptr to array of unknown size using WlanFreeMemory
|
||||
///
|
||||
template <class _Ty> struct WlanFreeMemory_delete<_Ty[]>;
|
||||
|
||||
///
|
||||
/// WLAN handle wrapper
|
||||
///
|
||||
class WINSTD_API wlan_handle;
|
||||
}
|
||||
|
||||
///
|
||||
/// Retrieves a string that describes a specified reason code and stores it in a std::wstring string.
|
||||
///
|
||||
@ -50,6 +67,140 @@ template<class _Elem, class _Traits, class _Ax> inline DWORD WlanReasonCodeToStr
|
||||
#pragma once
|
||||
|
||||
|
||||
namespace winstd
|
||||
{
|
||||
template <class _Ty> struct WlanFreeMemory_delete
|
||||
{
|
||||
typedef WlanFreeMemory_delete<_Ty> _Myt; ///< This type
|
||||
|
||||
///
|
||||
/// Default construct
|
||||
///
|
||||
WlanFreeMemory_delete() {}
|
||||
|
||||
///
|
||||
/// Construct from another WlanFreeMemory_delete
|
||||
///
|
||||
template <class _Ty2> WlanFreeMemory_delete(const WlanFreeMemory_delete<_Ty2>&) {}
|
||||
|
||||
///
|
||||
/// Delete a pointer
|
||||
///
|
||||
void operator()(_Ty *_Ptr) const
|
||||
{
|
||||
WlanFreeMemory(_Ptr);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <class _Ty> struct WlanFreeMemory_delete<_Ty[]>
|
||||
{
|
||||
typedef WlanFreeMemory_delete<_Ty> _Myt; ///< This type
|
||||
|
||||
///
|
||||
/// Default construct
|
||||
///
|
||||
WlanFreeMemory_delete() {}
|
||||
|
||||
///
|
||||
/// Delete a pointer
|
||||
///
|
||||
void operator()(_Ty *_Ptr) const
|
||||
{
|
||||
WlanFreeMemory(_Ptr);
|
||||
}
|
||||
|
||||
///
|
||||
/// Delete a pointer of another type
|
||||
///
|
||||
template<class _Other>
|
||||
void operator()(_Other *) const
|
||||
{
|
||||
WlanFreeMemory(_Ptr);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class WINSTD_API wlan_handle : public handle<HANDLE>
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Initializes a new class instance with the object handle set to NULL.
|
||||
///
|
||||
inline wlan_handle() : handle<HANDLE>() {}
|
||||
|
||||
///
|
||||
/// Initializes a new class instance with an already available object handle.
|
||||
///
|
||||
/// \param[in] h Initial object handle value
|
||||
///
|
||||
inline wlan_handle(_In_opt_ handle_type h) : handle<HANDLE>(h) {}
|
||||
|
||||
///
|
||||
/// Move constructor
|
||||
///
|
||||
/// \param[inout] h A rvalue reference of another object
|
||||
///
|
||||
inline wlan_handle(_Inout_ wlan_handle &&h) : handle<HANDLE>(std::move(h)) {}
|
||||
|
||||
///
|
||||
/// Closes a connection to the server.
|
||||
///
|
||||
/// \sa [WlanCloseHandle function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms706610(v=vs.85).aspx)
|
||||
///
|
||||
virtual ~wlan_handle();
|
||||
|
||||
///
|
||||
/// Move assignment
|
||||
///
|
||||
/// \param[inout] h A rvalue reference of another object
|
||||
///
|
||||
wlan_handle& operator=(_Inout_ wlan_handle &&h)
|
||||
{
|
||||
if (this != std::addressof(h))
|
||||
*(handle<handle_type>*)this = std::move(h);
|
||||
return *this;
|
||||
}
|
||||
|
||||
///
|
||||
/// Opens a connection to the server.
|
||||
///
|
||||
/// \sa [WlanOpenHandle function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms706759.aspx)
|
||||
///
|
||||
/// \return
|
||||
/// - \c true when succeeds;
|
||||
/// - \c false when fails. Use `GetLastError()` for failure reason.
|
||||
///
|
||||
inline bool open(_In_ DWORD dwClientVersion, _Out_ PDWORD pdwNegotiatedVersion)
|
||||
{
|
||||
handle_type h;
|
||||
DWORD dwResult = WlanOpenHandle(dwClientVersion, 0, pdwNegotiatedVersion, &h);
|
||||
if (dwResult == ERROR_SUCCESS) {
|
||||
attach(h);
|
||||
return true;
|
||||
} else {
|
||||
SetLastError(dwResult);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
// This class is noncopyable.
|
||||
wlan_handle(_In_ const wlan_handle &h);
|
||||
wlan_handle& operator=(_In_ const wlan_handle &h);
|
||||
|
||||
protected:
|
||||
///
|
||||
/// Closes a connection to the server.
|
||||
///
|
||||
/// \sa [WlanCloseHandle function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms706610(v=vs.85).aspx)
|
||||
///
|
||||
virtual void free_internal();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
template<class _Elem, class _Traits, class _Ax>
|
||||
inline DWORD WlanReasonCodeToString(_In_ DWORD dwReasonCode, _Out_ std::basic_string<_Elem, _Traits, _Ax> &sValue, __reserved PVOID pReserved)
|
||||
{
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
|
||||
#if defined(SECURITY_WIN32) || defined(SECURITY_KERNEL) || defined(SECURITY_MAC)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
40
src/WLAN.cpp
Normal file
40
src/WLAN.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
Copyright 1991-2016 Amebis
|
||||
Copyright 2016 GÉANT
|
||||
|
||||
This file is part of WinStd.
|
||||
|
||||
Setup is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Setup 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Setup. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// winstd::wlan_handle
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
winstd::wlan_handle::~wlan_handle()
|
||||
{
|
||||
if (m_h)
|
||||
WlanCloseHandle(m_h, NULL);
|
||||
}
|
||||
|
||||
|
||||
void winstd::wlan_handle::free_internal()
|
||||
{
|
||||
WlanCloseHandle(m_h, NULL);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user