2009-07-31 07:53:33 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2009 Shaivya Mahajan
|
|
|
|
|
|
|
|
This program 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.
|
|
|
|
|
|
|
|
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <math.h>
|
|
|
|
#include <wlanapi.h>
|
|
|
|
#pragma comment( lib, "wlanapi.lib")
|
2011-02-03 18:09:24 +00:00
|
|
|
#include "../../Library/Export.h" // Rainmeter's exported functions
|
2009-07-31 07:53:33 +00:00
|
|
|
|
2011-02-03 18:09:24 +00:00
|
|
|
#include "../../Library/DisableThreadLibraryCalls.h" // contains DllMain entry point
|
2011-01-30 09:31:41 +00:00
|
|
|
|
2009-07-31 07:53:33 +00:00
|
|
|
/* The exported functions */
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
__declspec( dllexport ) UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id);
|
|
|
|
__declspec( dllexport ) void Finalize(HMODULE instance, UINT id);
|
|
|
|
__declspec( dllexport ) UINT Update(UINT id);
|
|
|
|
__declspec( dllexport ) LPCTSTR GetString(UINT id, UINT flags);
|
|
|
|
__declspec( dllexport ) UINT GetPluginVersion();
|
|
|
|
__declspec( dllexport ) LPCTSTR GetPluginAuthor();
|
|
|
|
|
|
|
|
}
|
|
|
|
//Function that translates DOT11 ENUMs to output strings
|
|
|
|
LPCTSTR getDot11str(int,int);
|
2009-10-10 20:25:00 +00:00
|
|
|
//Wrapper function for writing to log file
|
|
|
|
void Log(const WCHAR* string);
|
2009-07-31 07:53:33 +00:00
|
|
|
|
|
|
|
enum MEASURETYPE
|
|
|
|
{
|
|
|
|
UNKNOWN,
|
|
|
|
SSID,
|
|
|
|
QUALITY,
|
|
|
|
ENCRYPTION,
|
|
|
|
AUTH,
|
|
|
|
LIST,
|
|
|
|
PHY,
|
|
|
|
};
|
|
|
|
|
2009-10-10 20:25:00 +00:00
|
|
|
//Struct for storing current meter's settings
|
|
|
|
typedef struct meas_data {
|
|
|
|
MEASURETYPE type;
|
|
|
|
UINT listStyle;
|
|
|
|
UINT listMax;
|
|
|
|
WCHAR * netlist;
|
|
|
|
bool listInit;
|
|
|
|
} meas_data_t;
|
2009-07-31 07:53:33 +00:00
|
|
|
|
2009-10-10 20:25:00 +00:00
|
|
|
|
|
|
|
std::map<UINT, meas_data_t> g_meas_data;
|
2010-08-06 10:09:03 +00:00
|
|
|
int g_Instances = 0;
|
2009-07-31 07:53:33 +00:00
|
|
|
/* Globals that store system's wifi interface/adapter structs */
|
|
|
|
/* These are initialized in Initialize(), used during each update*/
|
|
|
|
HANDLE hClient = NULL;
|
|
|
|
PWLAN_INTERFACE_INFO pInterface = NULL;
|
|
|
|
PWLAN_INTERFACE_INFO_LIST pIntfList = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
This function is called when the measure is initialized.
|
2011-03-29 19:21:57 +00:00
|
|
|
The function must return the maximum value that can be measured.
|
2009-07-31 07:53:33 +00:00
|
|
|
The return value can also be 0, which means that Rainmeter will
|
|
|
|
track the maximum value automatically. The parameters for this
|
|
|
|
function are:
|
|
|
|
|
|
|
|
instance The instance of this DLL
|
|
|
|
iniFile The name of the ini-file (usually Rainmeter.ini)
|
|
|
|
section The name of the section in the ini-file for this measure
|
|
|
|
id The identifier for the measure. This is used to identify the measures that use the same plugin.
|
|
|
|
*/
|
|
|
|
UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
|
|
|
|
{
|
|
|
|
/* initialize interface/adapter structs */
|
|
|
|
DWORD dwNegotiatedVersion = 0;
|
|
|
|
DWORD dwErr;
|
2010-08-06 10:09:03 +00:00
|
|
|
g_Instances++;
|
2009-07-31 07:53:33 +00:00
|
|
|
//Create WINLAN API Handle
|
2011-03-29 19:21:57 +00:00
|
|
|
if (hClient == NULL){
|
2009-07-31 07:53:33 +00:00
|
|
|
dwErr = WlanOpenHandle( WLAN_API_VERSION, NULL, &dwNegotiatedVersion, &hClient );
|
2011-03-29 19:21:57 +00:00
|
|
|
if ( ERROR_SUCCESS != dwErr ){
|
2009-10-10 20:25:00 +00:00
|
|
|
WCHAR buffer[256];
|
|
|
|
wsprintf(buffer, L"WifiStatus.dll: Unable to open WLAN API Handle. Error code (%d): %s",(int)dwErr,getDot11str(dwErr,5));
|
|
|
|
Log(buffer);
|
|
|
|
return 0;
|
2009-07-31 07:53:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//Query list of WLAN interfaces
|
2011-03-29 19:21:57 +00:00
|
|
|
if (pIntfList == NULL){
|
2009-07-31 07:53:33 +00:00
|
|
|
dwErr= WlanEnumInterfaces(hClient, NULL, &pIntfList);
|
2011-03-29 19:21:57 +00:00
|
|
|
if (( ERROR_SUCCESS != dwErr) || (&pIntfList->dwNumberOfItems <= 0)){
|
2009-10-10 20:25:00 +00:00
|
|
|
WCHAR buffer[256];
|
|
|
|
wsprintf(buffer, L"WifiStatus.dll: Unable to find any WLAN interfaces/adapters. Error code %d",(int) dwErr);
|
2010-09-21 11:09:36 +00:00
|
|
|
Log(buffer);
|
2009-07-31 07:53:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Select a WLAN interface, default 0.
|
|
|
|
LPCTSTR data = ReadConfigString(section, L"WifiIntfID", L"");
|
2011-03-29 19:21:57 +00:00
|
|
|
|
2010-09-17 08:47:22 +00:00
|
|
|
if ((data != NULL) && (_wcsicmp(L"", data) != 0)){
|
2011-03-29 19:21:57 +00:00
|
|
|
if (_wtoi(data) < (int)pIntfList->dwNumberOfItems){
|
2009-07-31 07:53:33 +00:00
|
|
|
pInterface = &pIntfList->InterfaceInfo[_wtoi(data)];
|
|
|
|
} else {
|
2009-10-10 20:25:00 +00:00
|
|
|
WCHAR buffer[256];
|
|
|
|
wsprintf(buffer, L"WifiStatus.dll: Adapter is disabled or invalid (WifiIntfID=%s), fix INTF ID(default=0) or enable the adapter.",data);
|
|
|
|
Log(buffer);
|
2011-03-29 19:21:57 +00:00
|
|
|
pInterface = &pIntfList->InterfaceInfo[0];
|
|
|
|
}
|
2009-07-31 07:53:33 +00:00
|
|
|
} else {
|
2011-03-29 19:21:57 +00:00
|
|
|
pInterface = &pIntfList->InterfaceInfo[0];
|
2009-07-31 07:53:33 +00:00
|
|
|
}
|
|
|
|
//Select LIST style
|
|
|
|
data = ReadConfigString(section, L"WifiListStyle", L"");
|
2011-03-29 19:21:57 +00:00
|
|
|
|
2010-09-17 08:47:22 +00:00
|
|
|
if ((data != NULL) && (_wcsicmp(L"", data) != 0)){
|
2009-07-31 07:53:33 +00:00
|
|
|
if ( (_wtoi(data) >= 0) && (_wtoi(data) <= 3)){
|
2009-10-10 20:25:00 +00:00
|
|
|
g_meas_data[id].listStyle = _wtoi(data);
|
|
|
|
} else {
|
|
|
|
WCHAR buffer[256];
|
|
|
|
wsprintf(buffer, L"WifiStatus.dll: Invalid List Style given (WifiListStyle=%s), defaulting to 0.",data);
|
|
|
|
Log(buffer);
|
|
|
|
g_meas_data[id].listStyle = 0;
|
2011-03-29 19:21:57 +00:00
|
|
|
}
|
2009-10-10 20:25:00 +00:00
|
|
|
} else {
|
|
|
|
g_meas_data[id].listStyle = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Set maxmimum number of list items
|
|
|
|
data = ReadConfigString(section, L"WifiListLimit", L"");
|
|
|
|
g_meas_data[id].listInit = false;
|
2010-09-17 08:47:22 +00:00
|
|
|
if ((data != NULL) && (_wcsicmp(L"", data) != 0)){
|
2009-10-10 20:25:00 +00:00
|
|
|
if (_wtoi(data) > 0){
|
|
|
|
g_meas_data[id].listMax = _wtoi(data);
|
2009-07-31 07:53:33 +00:00
|
|
|
} else {
|
2009-10-10 20:25:00 +00:00
|
|
|
WCHAR buffer[256];
|
|
|
|
wsprintf(buffer, L"WifiStatus.dll: Invalid List Limit given (WifiListLimit=%s), defaulting to 5.",data);
|
|
|
|
Log(buffer);
|
|
|
|
g_meas_data[id].listMax = 5;
|
2011-03-29 19:21:57 +00:00
|
|
|
}
|
2009-07-31 07:53:33 +00:00
|
|
|
} else {
|
2009-10-10 20:25:00 +00:00
|
|
|
g_meas_data[id].listMax = 5;
|
2009-07-31 07:53:33 +00:00
|
|
|
}
|
|
|
|
//Select type of measure
|
|
|
|
MEASURETYPE infoType = UNKNOWN;
|
|
|
|
LPCTSTR type = ReadConfigString(section, L"WifiInfoType", L"");
|
2011-03-29 19:21:57 +00:00
|
|
|
if (type){
|
2010-09-17 08:47:22 +00:00
|
|
|
if (_wcsicmp(L"SSID", type) == 0){
|
2009-07-31 07:53:33 +00:00
|
|
|
infoType=SSID;
|
2011-03-29 19:21:57 +00:00
|
|
|
}
|
2010-09-17 08:47:22 +00:00
|
|
|
else if (_wcsicmp(L"QUALITY", type) == 0){
|
2009-07-31 07:53:33 +00:00
|
|
|
infoType=QUALITY;
|
2011-03-29 19:21:57 +00:00
|
|
|
}
|
2010-09-17 08:47:22 +00:00
|
|
|
else if (_wcsicmp(L"ENCRYPTION", type) == 0){
|
2009-07-31 07:53:33 +00:00
|
|
|
infoType=ENCRYPTION;
|
2011-03-29 19:21:57 +00:00
|
|
|
}
|
2010-09-17 08:47:22 +00:00
|
|
|
else if (_wcsicmp(L"AUTH", type) == 0){
|
2009-07-31 07:53:33 +00:00
|
|
|
infoType=AUTH;
|
2011-03-29 19:21:57 +00:00
|
|
|
}
|
2010-09-17 08:47:22 +00:00
|
|
|
else if (_wcsicmp(L"LIST", type) == 0){
|
2009-07-31 07:53:33 +00:00
|
|
|
infoType=LIST;
|
2011-03-29 19:21:57 +00:00
|
|
|
}
|
2010-09-17 08:47:22 +00:00
|
|
|
else if (_wcsicmp(L"PHY", type) == 0){
|
2009-07-31 07:53:33 +00:00
|
|
|
infoType=PHY;
|
|
|
|
} else {
|
2009-10-10 20:25:00 +00:00
|
|
|
WCHAR buffer[256];
|
|
|
|
wsprintf(buffer, L"WifiStatus.dll: Invalid type given, WifiInfoType=%d.",type);
|
|
|
|
Log(buffer);
|
2009-07-31 07:53:33 +00:00
|
|
|
}
|
2009-10-10 20:25:00 +00:00
|
|
|
g_meas_data[id].type = infoType;
|
2009-07-31 07:53:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch(infoType){
|
|
|
|
case SSID:
|
|
|
|
case ENCRYPTION:
|
|
|
|
case AUTH:
|
|
|
|
return 0;
|
|
|
|
case QUALITY:
|
|
|
|
return 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
This function is called when new value should be measured.
|
|
|
|
The function returns the new value.
|
|
|
|
*/
|
|
|
|
UINT Update(UINT id)
|
|
|
|
{
|
2011-03-29 19:21:57 +00:00
|
|
|
if (pInterface == NULL) return NULL;
|
2009-07-31 07:53:33 +00:00
|
|
|
|
|
|
|
//Get measure id, and identify type
|
2009-10-10 20:25:00 +00:00
|
|
|
//std::map<UINT, MEASURETYPE>::iterator typeIter = g_Types.find(id);
|
2011-03-29 19:21:57 +00:00
|
|
|
//if (typeIter == g_Types.end()) return NULL;
|
2009-10-10 20:25:00 +00:00
|
|
|
MEASURETYPE current_type = g_meas_data[id].type;
|
|
|
|
switch(current_type)
|
2009-07-31 07:53:33 +00:00
|
|
|
{
|
|
|
|
case QUALITY:
|
|
|
|
//Set up variables for WLAN query
|
|
|
|
ULONG outsize = 0;
|
|
|
|
PWLAN_CONNECTION_ATTRIBUTES wlan_cattr=NULL;
|
|
|
|
DWORD dwErr;
|
|
|
|
GUID& intfGUID = pInterface->InterfaceGuid;
|
|
|
|
dwErr = WlanQueryInterface( hClient, &intfGUID, wlan_intf_opcode_current_connection, NULL, &outsize, (PVOID*)&wlan_cattr, NULL );
|
2011-03-29 19:21:57 +00:00
|
|
|
if ( ERROR_SUCCESS != dwErr){
|
2009-07-31 07:53:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int retval = (int)wlan_cattr->wlanAssociationAttributes.wlanSignalQuality;
|
2011-03-29 19:21:57 +00:00
|
|
|
if (wlan_cattr!=NULL)WlanFreeMemory(wlan_cattr);
|
2009-07-31 07:53:33 +00:00
|
|
|
return retval;
|
2011-03-29 19:21:57 +00:00
|
|
|
|
2009-07-31 07:53:33 +00:00
|
|
|
//Transfer rates will go here
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-29 19:21:57 +00:00
|
|
|
LPCTSTR GetString(UINT id, UINT flags)
|
2009-07-31 07:53:33 +00:00
|
|
|
{
|
2011-03-29 19:21:57 +00:00
|
|
|
if (pInterface == NULL) return NULL;
|
|
|
|
|
2009-10-10 20:25:00 +00:00
|
|
|
//Some variables for data manipulation in this function
|
|
|
|
static WCHAR buffer[128];
|
2009-07-31 07:53:33 +00:00
|
|
|
bool bNetList = false; //whether to return buffer or netlist
|
2009-10-10 20:25:00 +00:00
|
|
|
bool bInvalidType = false;
|
|
|
|
bool bIntfError = false;
|
2009-07-31 07:53:33 +00:00
|
|
|
unsigned int listStyle = 0;
|
2009-10-10 20:25:00 +00:00
|
|
|
memset(buffer,'\0',128);
|
|
|
|
listStyle = g_meas_data[id].listStyle;
|
|
|
|
int printed = 0; //count of how many networks have been printed already
|
|
|
|
|
2009-07-31 07:53:33 +00:00
|
|
|
//Set up variables for WLAN queries
|
|
|
|
ULONG outsize = 0;
|
|
|
|
PWLAN_CONNECTION_ATTRIBUTES wlan_cattr=NULL;
|
|
|
|
PWLAN_AVAILABLE_NETWORK_LIST pwnl=NULL;
|
|
|
|
DWORD dwCErr, dwLErr;
|
|
|
|
GUID& intfGUID = pInterface->InterfaceGuid;
|
|
|
|
|
2009-10-10 20:25:00 +00:00
|
|
|
//Initialize WLAN structs with queries, break if no interface found
|
2009-07-31 07:53:33 +00:00
|
|
|
dwCErr= WlanQueryInterface( hClient, &intfGUID, wlan_intf_opcode_current_connection, NULL, &outsize, (PVOID*)&wlan_cattr, NULL );
|
|
|
|
dwLErr= WlanGetAvailableNetworkList(hClient,&intfGUID,NULL,NULL,&pwnl);
|
2009-10-10 20:25:00 +00:00
|
|
|
MEASURETYPE current_type = g_meas_data[id].type;
|
|
|
|
UINT listMax = g_meas_data[id].listMax;
|
2009-07-31 07:53:33 +00:00
|
|
|
|
2009-10-10 20:25:00 +00:00
|
|
|
switch(current_type)
|
2011-03-29 19:21:57 +00:00
|
|
|
{
|
2009-07-31 07:53:33 +00:00
|
|
|
case LIST:
|
2011-03-29 19:21:57 +00:00
|
|
|
if (ERROR_SUCCESS != dwLErr){return L"Error";}
|
|
|
|
|
2009-10-10 20:25:00 +00:00
|
|
|
if (!g_meas_data[id].listInit){//Check if netlist has memory allocated already
|
|
|
|
//Size of network name can be up to 64 chars, set to 80 to add room for delimiters
|
|
|
|
g_meas_data[id].netlist = (WCHAR*)malloc( 80 * sizeof(WCHAR) * g_meas_data[id].listMax);
|
2011-03-29 19:21:57 +00:00
|
|
|
if (g_meas_data[id].netlist == NULL){
|
2009-10-10 20:25:00 +00:00
|
|
|
WCHAR debug[256];
|
|
|
|
wsprintf(debug, L"WifiStatus.dll: Unable to allocate memory for network list.");
|
|
|
|
Log(buffer);
|
|
|
|
g_meas_data[id].listInit = false;
|
|
|
|
free(g_meas_data[id].netlist);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
g_meas_data[id].listInit = true;
|
|
|
|
}
|
2011-03-29 19:21:57 +00:00
|
|
|
|
2009-10-10 20:25:00 +00:00
|
|
|
memset(g_meas_data[id].netlist,'\0', (80 * sizeof(WCHAR) * g_meas_data[id].listMax));
|
|
|
|
memset(buffer,'\0',128);
|
2011-03-29 19:21:57 +00:00
|
|
|
|
2009-07-31 07:53:33 +00:00
|
|
|
//Check all items in WLAN NETWORK LIST
|
2011-03-29 19:21:57 +00:00
|
|
|
for (int i=0; i < (int)pwnl->dwNumberOfItems ; i++){
|
|
|
|
if (printed == g_meas_data[id].listMax)
|
2009-10-10 20:25:00 +00:00
|
|
|
break;
|
2011-03-29 19:21:57 +00:00
|
|
|
|
2009-07-31 07:53:33 +00:00
|
|
|
//SSID is in UCHAR, convert to WCHAR
|
|
|
|
mbstowcs(buffer,(char*)pwnl->Network[i].dot11Ssid.ucSSID,pwnl->Network[i].dot11Ssid.uSSIDLength);
|
2011-03-29 19:21:57 +00:00
|
|
|
|
2009-10-10 20:25:00 +00:00
|
|
|
//Prevent duplicates that result from profiles, check using SSID
|
2011-03-29 19:21:57 +00:00
|
|
|
if ((wcsstr(g_meas_data[id].netlist,buffer)== NULL)&&(_wcsicmp(L"", buffer) != 0)){
|
2009-10-10 20:25:00 +00:00
|
|
|
printed++;
|
2011-03-29 19:21:57 +00:00
|
|
|
if (listStyle > 0){
|
2009-10-10 20:25:00 +00:00
|
|
|
wsprintf(g_meas_data[id].netlist,L"%s%s",g_meas_data[id].netlist,buffer);
|
|
|
|
memset(buffer,'\0',128);
|
2011-03-29 19:21:57 +00:00
|
|
|
if (listStyle == 1 || listStyle == 3){
|
2009-10-10 20:25:00 +00:00
|
|
|
//ADD PHY type
|
2011-03-29 19:21:57 +00:00
|
|
|
wsprintf(buffer,L" @%s", getDot11str(pwnl->Network[i].dot11PhyTypes[0],4));
|
2009-07-31 07:53:33 +00:00
|
|
|
}
|
2011-03-29 19:21:57 +00:00
|
|
|
if (listStyle == 2 || listStyle == 3){
|
2009-10-10 20:25:00 +00:00
|
|
|
//ADD cipher and authentication
|
|
|
|
wsprintf(buffer,L"%s (%s:%s)",buffer,getDot11str(pwnl->Network[i].dot11DefaultCipherAlgorithm,1)
|
2011-03-29 19:21:57 +00:00
|
|
|
,getDot11str(pwnl->Network[i].dot11DefaultAuthAlgorithm,2));
|
2009-07-31 07:53:33 +00:00
|
|
|
}
|
|
|
|
}
|
2009-10-10 20:25:00 +00:00
|
|
|
wsprintf(g_meas_data[id].netlist,L"%s%s\n",g_meas_data[id].netlist,buffer);
|
2009-07-31 07:53:33 +00:00
|
|
|
}
|
2009-10-10 20:25:00 +00:00
|
|
|
memset(buffer,'\0',128);
|
2009-07-31 07:53:33 +00:00
|
|
|
|
|
|
|
}//end for
|
2009-10-10 20:25:00 +00:00
|
|
|
bNetList=true;
|
2009-07-31 07:53:33 +00:00
|
|
|
break;
|
2011-03-29 19:21:57 +00:00
|
|
|
|
2009-07-31 07:53:33 +00:00
|
|
|
case SSID:
|
2011-03-29 19:21:57 +00:00
|
|
|
if (ERROR_SUCCESS != dwCErr){
|
2009-10-10 20:25:00 +00:00
|
|
|
bIntfError = true;
|
|
|
|
break;
|
|
|
|
}
|
2009-07-31 07:53:33 +00:00
|
|
|
//Need to convert ucSSID to wchar from uchar
|
|
|
|
mbstowcs(buffer,(char *)wlan_cattr->wlanAssociationAttributes.dot11Ssid.ucSSID,wlan_cattr->wlanAssociationAttributes.dot11Ssid.uSSIDLength);
|
|
|
|
//If not connected yet add current status
|
|
|
|
wcscat(buffer,getDot11str(wlan_cattr->isState,3));
|
|
|
|
break;
|
2011-03-29 19:21:57 +00:00
|
|
|
|
2009-07-31 07:53:33 +00:00
|
|
|
case PHY:
|
2011-03-29 19:21:57 +00:00
|
|
|
if (ERROR_SUCCESS != dwCErr){
|
2009-10-10 20:25:00 +00:00
|
|
|
bIntfError = true;
|
|
|
|
break;
|
|
|
|
}
|
2009-07-31 07:53:33 +00:00
|
|
|
wcscpy(buffer,getDot11str(wlan_cattr->wlanAssociationAttributes.dot11PhyType,4));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ENCRYPTION:
|
2011-03-29 19:21:57 +00:00
|
|
|
if (ERROR_SUCCESS != dwCErr){
|
2009-10-10 20:25:00 +00:00
|
|
|
bIntfError = true;
|
|
|
|
break;
|
|
|
|
}
|
2009-07-31 07:53:33 +00:00
|
|
|
wcscpy(buffer,getDot11str(wlan_cattr->wlanSecurityAttributes.dot11CipherAlgorithm,1));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AUTH:
|
2011-03-29 19:21:57 +00:00
|
|
|
if (ERROR_SUCCESS != dwCErr){
|
2009-10-10 20:25:00 +00:00
|
|
|
bIntfError = true;
|
|
|
|
break;
|
|
|
|
}
|
2011-03-29 19:21:57 +00:00
|
|
|
wcscpy(buffer,getDot11str(wlan_cattr->wlanSecurityAttributes.dot11AuthAlgorithm,2));
|
2009-07-31 07:53:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: //InfoType does not refer to a string measure
|
2009-10-10 20:25:00 +00:00
|
|
|
bInvalidType= true;
|
2009-07-31 07:53:33 +00:00
|
|
|
break;
|
2011-03-29 19:21:57 +00:00
|
|
|
|
2009-07-31 07:53:33 +00:00
|
|
|
}
|
2011-03-29 19:21:57 +00:00
|
|
|
if (wlan_cattr!=NULL)WlanFreeMemory(wlan_cattr);
|
|
|
|
if (pwnl!=NULL)WlanFreeMemory(pwnl);
|
|
|
|
|
|
|
|
if (bNetList)
|
2009-10-10 20:25:00 +00:00
|
|
|
return g_meas_data[id].netlist;
|
2011-03-29 19:21:57 +00:00
|
|
|
if (bIntfError)
|
2009-10-10 20:25:00 +00:00
|
|
|
return L"-1";
|
|
|
|
else {
|
2011-03-29 19:21:57 +00:00
|
|
|
if (bInvalidType)
|
2009-10-10 20:25:00 +00:00
|
|
|
return NULL;
|
|
|
|
else
|
|
|
|
return buffer;
|
|
|
|
}
|
2009-07-31 07:53:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-03-29 19:21:57 +00:00
|
|
|
switches from winlanapi.h + SDK
|
2009-07-31 07:53:33 +00:00
|
|
|
in: -DOT11 ENUM (converted to int)
|
2011-03-29 19:21:57 +00:00
|
|
|
-type of ENUM (cipher=1, auth=2, status=3, phy=4, otherwise=error strings)
|
2009-07-31 07:53:33 +00:00
|
|
|
out: String to be returned by measure
|
|
|
|
*/
|
|
|
|
LPCTSTR getDot11str(int dot11enum,int type){
|
2011-03-29 19:21:57 +00:00
|
|
|
if (type ==1){
|
2009-07-31 07:53:33 +00:00
|
|
|
switch(dot11enum){
|
|
|
|
case DOT11_CIPHER_ALGO_NONE:
|
|
|
|
return L"NONE";
|
|
|
|
case DOT11_CIPHER_ALGO_WEP40:
|
|
|
|
return L"WEP40";
|
|
|
|
case DOT11_CIPHER_ALGO_TKIP:
|
|
|
|
return L"TKIP";
|
|
|
|
case DOT11_CIPHER_ALGO_CCMP:
|
|
|
|
return L"AES";
|
|
|
|
case DOT11_CIPHER_ALGO_WEP104:
|
|
|
|
return L"WEP104";
|
|
|
|
case DOT11_CIPHER_ALGO_WPA_USE_GROUP:
|
|
|
|
return L"WPA-GROUP";
|
|
|
|
case DOT11_CIPHER_ALGO_WEP:
|
|
|
|
return L"WEP";
|
|
|
|
default:
|
2011-03-29 19:21:57 +00:00
|
|
|
return L"???";
|
2009-07-31 07:53:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == 2){
|
|
|
|
switch(dot11enum){
|
|
|
|
case DOT11_AUTH_ALGO_80211_OPEN:
|
|
|
|
return L"Open";
|
|
|
|
case DOT11_AUTH_ALGO_80211_SHARED_KEY:
|
|
|
|
return L"Shared";
|
|
|
|
case DOT11_AUTH_ALGO_WPA_NONE:
|
|
|
|
return L"WPA-NONE";
|
|
|
|
case DOT11_AUTH_ALGO_WPA:
|
|
|
|
return L"WPA-Enterprise";
|
|
|
|
case DOT11_AUTH_ALGO_WPA_PSK:
|
|
|
|
return L"WPA-Personal";
|
|
|
|
case DOT11_AUTH_ALGO_RSNA:
|
|
|
|
return L"WPA2-Enterprise";
|
|
|
|
case DOT11_AUTH_ALGO_RSNA_PSK:
|
|
|
|
return L"WPA2-Personal";
|
|
|
|
default:
|
2011-03-29 19:21:57 +00:00
|
|
|
return L"???";
|
2009-07-31 07:53:33 +00:00
|
|
|
}
|
|
|
|
}
|
2011-03-29 19:21:57 +00:00
|
|
|
else if (type==3){
|
2009-07-31 07:53:33 +00:00
|
|
|
switch(dot11enum){
|
|
|
|
case wlan_interface_state_connected:
|
|
|
|
return L"";
|
|
|
|
case wlan_interface_state_authenticating:
|
|
|
|
return L"(authorizing...)";
|
|
|
|
default:
|
|
|
|
return L"(connecting...)";
|
|
|
|
}
|
|
|
|
}
|
2011-03-29 19:21:57 +00:00
|
|
|
else if (type==4){
|
2009-07-31 07:53:33 +00:00
|
|
|
switch(dot11enum){
|
|
|
|
case dot11_phy_type_unknown:
|
|
|
|
return L"???";
|
|
|
|
case dot11_phy_type_dsss:
|
|
|
|
return L"DSSS";
|
|
|
|
case dot11_phy_type_erp:
|
2011-03-29 19:21:57 +00:00
|
|
|
return L"802.11g";
|
2009-07-31 07:53:33 +00:00
|
|
|
case dot11_phy_type_fhss:
|
|
|
|
return L"FHSS";
|
|
|
|
case dot11_phy_type_hrdsss:
|
|
|
|
return L"802.11b";
|
|
|
|
case dot11_phy_type_irbaseband:
|
|
|
|
return L"IR-Band";
|
|
|
|
case dot11_phy_type_ofdm:
|
|
|
|
return L"802.11a";
|
|
|
|
//Case below appears as dot11_phy_type_ht on MSDN
|
|
|
|
//However its not supported in winlanapi.h ???
|
|
|
|
case 7:
|
2009-10-10 20:25:00 +00:00
|
|
|
return L"802.11n";
|
2009-07-31 07:53:33 +00:00
|
|
|
default:
|
|
|
|
return L"???";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
switch(dot11enum){
|
|
|
|
case ERROR_INVALID_PARAMETER:
|
2009-10-10 20:25:00 +00:00
|
|
|
return L"Invalid parameters.";
|
2009-07-31 07:53:33 +00:00
|
|
|
case ERROR_NOT_ENOUGH_MEMORY:
|
2009-10-10 20:25:00 +00:00
|
|
|
return L"Not enough memory.";
|
2009-07-31 07:53:33 +00:00
|
|
|
case ERROR_REMOTE_SESSION_LIMIT_EXCEEDED:
|
2009-10-10 20:25:00 +00:00
|
|
|
return L"Too many handles already issued.";
|
2009-07-31 07:53:33 +00:00
|
|
|
default:
|
2009-10-10 20:25:00 +00:00
|
|
|
return L"Unknown error code.";
|
2009-07-31 07:53:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
If the measure needs to free resources before quitting.
|
|
|
|
The plugin can export Finalize function, which is called
|
|
|
|
when Rainmeter quits (or refreshes).
|
|
|
|
*/
|
|
|
|
void Finalize(HMODULE instance, UINT id)
|
|
|
|
{
|
2009-10-10 20:25:00 +00:00
|
|
|
std::map<UINT, meas_data_t>::iterator i1 = g_meas_data.find(id);
|
|
|
|
if (i1 != g_meas_data.end())
|
2009-07-31 07:53:33 +00:00
|
|
|
{
|
2009-10-10 20:25:00 +00:00
|
|
|
free(g_meas_data[id].netlist);
|
|
|
|
g_meas_data[id].listInit = false;
|
|
|
|
g_meas_data.erase(i1);
|
2009-07-31 07:53:33 +00:00
|
|
|
}
|
2010-08-06 10:09:03 +00:00
|
|
|
g_Instances--;
|
2011-03-29 19:21:57 +00:00
|
|
|
if (hClient != NULL && g_Instances == 0){
|
2009-07-31 07:53:33 +00:00
|
|
|
WlanCloseHandle(hClient, NULL);
|
|
|
|
hClient = NULL;
|
|
|
|
}
|
2011-03-29 19:21:57 +00:00
|
|
|
if (pIntfList != NULL && g_Instances == 0){
|
2009-07-31 07:53:33 +00:00
|
|
|
WlanFreeMemory(pIntfList);
|
2009-10-10 20:25:00 +00:00
|
|
|
pIntfList = NULL;
|
2009-07-31 07:53:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-10 20:25:00 +00:00
|
|
|
/*
|
|
|
|
Wrapper function grabbed from the WebParser plugin
|
|
|
|
*/
|
|
|
|
void Log(const WCHAR* string)
|
|
|
|
{
|
|
|
|
// @TODO: put logging into critical section
|
|
|
|
LSLog(LOG_DEBUG, L"Rainmeter", string);
|
|
|
|
}
|
|
|
|
|
2009-07-31 07:53:33 +00:00
|
|
|
/*
|
|
|
|
Returns the version number of the plugin. The value
|
|
|
|
can be calculated like this: Major * 1000 + Minor.
|
|
|
|
So, e.g. 2.31 would be 2031.
|
|
|
|
*/
|
|
|
|
UINT GetPluginVersion()
|
|
|
|
{
|
2009-10-10 20:25:00 +00:00
|
|
|
return 1009;
|
2009-07-31 07:53:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Returns the author of the plugin for the about dialog.
|
|
|
|
*/
|
|
|
|
LPCTSTR GetPluginAuthor()
|
|
|
|
{
|
|
|
|
return L"nvme (shaivya.m@gmail.com)";
|
|
|
|
}
|