WifiStatus.dll: Updated to new API.

This commit is contained in:
spx 2012-04-19 07:49:35 -07:00
parent a96ebff1ee
commit d74ddda1b2
2 changed files with 408 additions and 412 deletions

View File

@ -105,6 +105,7 @@
<TargetMachine>MachineX86</TargetMachine> <TargetMachine>MachineX86</TargetMachine>
<AdditionalLibraryDirectories>..\..\Library\x32\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>..\..\Library\x32\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<ProgramDatabaseFile>$(IntDir)$(TargetName).pdb</ProgramDatabaseFile> <ProgramDatabaseFile>$(IntDir)$(TargetName).pdb</ProgramDatabaseFile>
<AdditionalDependencies>Rainmeter.lib;wlanapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@ -136,6 +137,7 @@
<TargetMachine>MachineX64</TargetMachine> <TargetMachine>MachineX64</TargetMachine>
<AdditionalLibraryDirectories>..\..\Library\x64\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>..\..\Library\x64\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<ProgramDatabaseFile>$(IntDir)$(TargetName).pdb</ProgramDatabaseFile> <ProgramDatabaseFile>$(IntDir)$(TargetName).pdb</ProgramDatabaseFile>
<AdditionalDependencies>Rainmeter.lib;wlanapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@ -154,7 +156,7 @@
<Culture>0x0409</Culture> <Culture>0x0409</Culture>
</ResourceCompile> </ResourceCompile>
<Link> <Link>
<AdditionalDependencies>Rainmeter.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>Rainmeter.lib;wlanapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>../../TestBench/x32/Release/Plugins/WifiStatus.dll</OutputFile> <OutputFile>../../TestBench/x32/Release/Plugins/WifiStatus.dll</OutputFile>
<AdditionalLibraryDirectories>..\..\Library\x32\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>..\..\Library\x32\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<RandomizedBaseAddress>false</RandomizedBaseAddress> <RandomizedBaseAddress>false</RandomizedBaseAddress>
@ -183,7 +185,7 @@
<Culture>0x0409</Culture> <Culture>0x0409</Culture>
</ResourceCompile> </ResourceCompile>
<Link> <Link>
<AdditionalDependencies>Rainmeter.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>Rainmeter.lib;wlanapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>../../TestBench/x64/Release/Plugins/WifiStatus.dll</OutputFile> <OutputFile>../../TestBench/x64/Release/Plugins/WifiStatus.dll</OutputFile>
<AdditionalLibraryDirectories>..\..\Library\x64\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>..\..\Library\x64\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<RandomizedBaseAddress>false</RandomizedBaseAddress> <RandomizedBaseAddress>false</RandomizedBaseAddress>

View File

@ -16,349 +16,376 @@
*/ */
#include <windows.h> #include <windows.h>
#include <map>
#include <string> #include <string>
#include <math.h>
#include <wlanapi.h> #include <wlanapi.h>
#pragma comment( lib, "wlanapi.lib") #include "../API/RainmeterAPI.h"
#include "../../Library/Export.h" // Rainmeter's exported functions
#include "../../Library/DisableThreadLibraryCalls.h" // contains DllMain entry point #include "../../Library/DisableThreadLibraryCalls.h" // contains DllMain entry point
/* 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);
enum MEASURETYPE enum MEASURETYPE
{ {
UNINITIALIZED,
UNKNOWN, UNKNOWN,
SSID, SSID,
QUALITY, QUALITY,
ENCRYPTION, ENCRYPTION,
AUTH, AUTH,
LIST, LIST,
PHY, PHY
}; };
//Struct for storing current meter's settings struct MeasureData
typedef struct meas_data { {
MEASURETYPE type; MEASURETYPE type;
UINT listStyle; UINT listStyle;
UINT listMax; UINT listMax;
WCHAR * netlist; std::wstring statusString;
bool listInit;
} meas_data_t;
MeasureData() : type(UNINITIALIZED), listStyle(), listMax(5) {}
};
std::map<UINT, meas_data_t> g_meas_data; UINT g_Instances = 0;
int g_Instances = 0;
/* 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;
/* // Globals that store system's wifi interface/adapter structs
This function is called when the measure is initialized. // These are initialized in Initialize(), used during each update
The function must return the maximum value that can be measured. HANDLE g_hClient = NULL;
The return value can also be 0, which means that Rainmeter will PWLAN_INTERFACE_INFO g_pInterface = NULL;
track the maximum value automatically. The parameters for this PWLAN_INTERFACE_INFO_LIST g_pIntfList = NULL;
function are:
instance The instance of this DLL // Function that translates DOT11 ENUMs to output strings
iniFile The name of the ini-file (usually Rainmeter.ini) LPCWSTR GetDot11Str(int, int);
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. std::wstring ConvertToWide(LPCSTR str, int strLen)
*/
UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id)
{ {
/* initialize interface/adapter structs */ std::wstring szWide;
DWORD dwNegotiatedVersion = 0;
DWORD dwErr;
g_Instances++;
//Create WINLAN API Handle
if (hClient == NULL){
dwErr = WlanOpenHandle( WLAN_API_VERSION, NULL, &dwNegotiatedVersion, &hClient );
if ( ERROR_SUCCESS != dwErr ){
WCHAR buffer[256];
wsprintf(buffer, L"WifiStatus.dll: Unable to open WLAN API Handle. Error code (%d): %s",(int)dwErr,getDot11str(dwErr,5));
LSLog(LOG_ERROR, NULL, buffer);
return 0;
}
}
//Query list of WLAN interfaces
if (pIntfList == NULL){
dwErr= WlanEnumInterfaces(hClient, NULL, &pIntfList);
if (( ERROR_SUCCESS != dwErr) || (&pIntfList->dwNumberOfItems <= 0)){
WCHAR buffer[256];
wsprintf(buffer, L"WifiStatus.dll: Unable to find any WLAN interfaces/adapters. Error code %d",(int) dwErr);
LSLog(LOG_ERROR, NULL, buffer);
return 0;
}
}
//Select a WLAN interface, default 0.
LPCTSTR data = ReadConfigString(section, L"WifiIntfID", L"");
if ((data != NULL) && *data){ if (str && *str)
if (_wtoi(data) < (int)pIntfList->dwNumberOfItems){ {
pInterface = &pIntfList->InterfaceInfo[_wtoi(data)]; int bufLen = MultiByteToWideChar(CP_ACP, 0, str, strLen, NULL, 0);
} else { if (bufLen > 0)
WCHAR buffer[256]; {
wsprintf(buffer, L"WifiStatus.dll: Adapter (WifiIntfID=%s) not valid", data); szWide.resize(bufLen);
LSLog(LOG_ERROR, NULL, buffer); MultiByteToWideChar(CP_ACP, 0, str, strLen, &szWide[0], bufLen);
pInterface = &pIntfList->InterfaceInfo[0];
} }
} else {
pInterface = &pIntfList->InterfaceInfo[0];
} }
//Select LIST style return szWide;
data = ReadConfigString(section, L"WifiListStyle", L""); }
if ((data != NULL) && *data){ void FinalizeHandle()
if ( (_wtoi(data) >= 0) && (_wtoi(data) <= 3)){ {
g_meas_data[id].listStyle = _wtoi(data); g_pInterface = NULL;
} else {
WCHAR buffer[256]; if (g_pIntfList != NULL)
wsprintf(buffer, L"WifiStatus.dll: WifiListStyle=%s not valid",data); {
LSLog(LOG_WARNING, NULL, buffer); WlanFreeMemory(g_pIntfList);
g_meas_data[id].listStyle = 0; g_pIntfList = NULL;
}
} else {
g_meas_data[id].listStyle = 0;
} }
//Set maxmimum number of list items if (g_hClient != NULL)
data = ReadConfigString(section, L"WifiListLimit", L""); {
g_meas_data[id].listInit = false; WlanCloseHandle(g_hClient, NULL);
if ((data != NULL) && *data){ g_hClient = NULL;
if (_wtoi(data) > 0){
g_meas_data[id].listMax = _wtoi(data);
} else {
WCHAR buffer[256];
wsprintf(buffer, L"WifiStatus.dll: WifiListLimit=%s not valid.",data);
LSLog(LOG_WARNING, NULL, buffer);
g_meas_data[id].listMax = 5;
}
} else {
g_meas_data[id].listMax = 5;
} }
//Select type of measure }
PLUGIN_EXPORT void Initialize(void** data, void* rm)
{
MeasureData* measure = new MeasureData;
*data = measure;
++g_Instances;
if (g_Instances == 1)
{
WCHAR buffer[256];
// Create WINLAN API Handle
if (g_hClient == NULL)
{
DWORD dwNegotiatedVersion = 0;
DWORD dwErr = WlanOpenHandle(WLAN_API_VERSION, NULL, &dwNegotiatedVersion, &g_hClient);
if (ERROR_SUCCESS != dwErr)
{
FinalizeHandle();
_snwprintf_s(buffer, _TRUNCATE, L"WifiStatus.dll: Unable to open WLAN API Handle. Error code (%u): %s", dwErr, GetDot11Str((int)dwErr, 5));
RmLog(LOG_ERROR, buffer);
return;
}
}
// Query list of WLAN interfaces
if (g_pIntfList == NULL)
{
DWORD dwErr = WlanEnumInterfaces(g_hClient, NULL, &g_pIntfList);
if (ERROR_SUCCESS != dwErr)
{
FinalizeHandle();
_snwprintf_s(buffer, _TRUNCATE, L"WifiStatus.dll: Unable to find any WLAN interfaces/adapters. Error code %u", dwErr);
RmLog(LOG_ERROR, buffer);
return;
}
else if (g_pIntfList->dwNumberOfItems == 0)
{
FinalizeHandle();
RmLog(LOG_ERROR, L"WifiStatus.dll: No WLAN interfaces/adapters available.");
return;
}
}
}
}
PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
{
if (g_hClient == NULL) return;
MeasureData* measure = (MeasureData*)data;
WCHAR buffer[256];
bool changed = false;
// Select a WLAN interface, default 0.
int value = RmReadInt(rm, L"WifiIntfID", 0);
if (value >= (int)g_pIntfList->dwNumberOfItems)
{
_snwprintf_s(buffer, _TRUNCATE, L"WifiStatus.dll: Adapter (WifiIntfID=%i) not valid.", value);
RmLog(LOG_ERROR, buffer);
value = 0;
}
g_pInterface = &g_pIntfList->InterfaceInfo[value];
// Select LIST style
value = RmReadInt(rm, L"WifiListStyle", 0);
if (value < 0 || value > 3)
{
_snwprintf_s(buffer, _TRUNCATE, L"WifiStatus.dll: WifiListStyle=%i not valid.", value);
RmLog(LOG_WARNING, buffer);
value = 0;
}
measure->listStyle = value;
// Set maxmimum number of list items
value = RmReadInt(rm, L"WifiListLimit", 5);
if (value <= 0)
{
_snwprintf_s(buffer, _TRUNCATE, L"WifiStatus.dll: WifiListLimit=%i not valid.", data);
RmLog(LOG_WARNING, buffer);
value = 5;
}
measure->listMax = value;
// Select type of measure
MEASURETYPE infoType = UNKNOWN; MEASURETYPE infoType = UNKNOWN;
LPCTSTR type = ReadConfigString(section, L"WifiInfoType", L""); LPCWSTR type = RmReadString(rm, L"WifiInfoType", L"");
if (type){ if (_wcsicmp(L"SSID", type) == 0)
if (_wcsicmp(L"SSID", type) == 0){ {
infoType=SSID; infoType = SSID;
}
else if (_wcsicmp(L"QUALITY", type) == 0){
infoType=QUALITY;
}
else if (_wcsicmp(L"ENCRYPTION", type) == 0){
infoType=ENCRYPTION;
}
else if (_wcsicmp(L"AUTH", type) == 0){
infoType=AUTH;
}
else if (_wcsicmp(L"LIST", type) == 0){
infoType=LIST;
}
else if (_wcsicmp(L"PHY", type) == 0){
infoType=PHY;
} else {
WCHAR buffer[256];
wsprintf(buffer, L"WifiStatus.dll: WifiInfoType=%d not valid",type);
LSLog(LOG_ERROR, NULL, buffer);
}
g_meas_data[id].type = infoType;
} }
else if (_wcsicmp(L"QUALITY", type) == 0)
{
infoType = QUALITY;
}
else if (_wcsicmp(L"ENCRYPTION", type) == 0)
{
infoType = ENCRYPTION;
}
else if (_wcsicmp(L"AUTH", type) == 0)
{
infoType = AUTH;
}
else if (_wcsicmp(L"LIST", type) == 0)
{
infoType = LIST;
}
else if (_wcsicmp(L"PHY", type) == 0)
{
infoType = PHY;
}
else
{
_snwprintf_s(buffer, _TRUNCATE, L"WifiStatus.dll: WifiInfoType=%s not valid.", type);
RmLog(LOG_ERROR, buffer);
}
if (infoType != measure->type)
{
changed = true;
}
measure->type = infoType;
switch(infoType){ if (changed)
{
measure->statusString.clear();
switch (infoType)
{
case SSID: case SSID:
case ENCRYPTION: case ENCRYPTION:
case AUTH: case AUTH:
return 0; *maxValue = 0;
break;
case QUALITY: case QUALITY:
return 100; *maxValue = 100;
break;
}
} }
return 0;
} }
/* PLUGIN_EXPORT double Update(void* data)
This function is called when new value should be measured.
The function returns the new value.
*/
UINT Update(UINT id)
{ {
if (pInterface == NULL) return NULL; if (g_pInterface == NULL) return 0;
//Get measure id, and identify type MeasureData* measure = (MeasureData*)data;
//std::map<UINT, MEASURETYPE>::iterator typeIter = g_Types.find(id); double value = 0;
//if (typeIter == g_Types.end()) return NULL;
MEASURETYPE current_type = g_meas_data[id].type; if (measure->type != UNKNOWN)
switch(current_type)
{ {
case QUALITY: if (measure->type == LIST)
//Set up variables for WLAN query {
ULONG outsize = 0; PWLAN_AVAILABLE_NETWORK_LIST pwnl = NULL;
PWLAN_CONNECTION_ATTRIBUTES wlan_cattr=NULL; DWORD dwErr = WlanGetAvailableNetworkList(g_hClient, &g_pInterface->InterfaceGuid, NULL, NULL, &pwnl);
DWORD dwErr;
GUID& intfGUID = pInterface->InterfaceGuid; if (ERROR_SUCCESS != dwErr)
dwErr = WlanQueryInterface( hClient, &intfGUID, wlan_intf_opcode_current_connection, NULL, &outsize, (PVOID*)&wlan_cattr, NULL ); {
if ( ERROR_SUCCESS != dwErr){ measure->statusString = L"Error";
return 0;
} }
int retval = (int)wlan_cattr->wlanAssociationAttributes.wlanSignalQuality; else
if (wlan_cattr!=NULL)WlanFreeMemory(wlan_cattr); {
return retval; // Size of network name can be up to 64 chars, set to 80 to add room for delimiters
measure->statusString.clear();
measure->statusString.reserve(80 * measure->listMax);
//Transfer rates will go here UINT printed = 0; // count of how many networks have been printed already
}
return NULL;
}
// Check all items in WLAN NETWORK LIST
for (size_t i = 0; i < pwnl->dwNumberOfItems ; ++i)
{
if (printed == measure->listMax) break;
LPCTSTR GetString(UINT id, UINT flags) // SSID is in UCHAR, convert to WCHAR
{ std::wstring ssid = ConvertToWide((LPCSTR)pwnl->Network[i].dot11Ssid.ucSSID, (int)pwnl->Network[i].dot11Ssid.uSSIDLength);
if (pInterface == NULL) return NULL;
//Some variables for data manipulation in this function // Prevent duplicates that result from profiles, check using SSID
static WCHAR buffer[128]; if (!ssid.empty() && ssid[0] && wcsstr(measure->statusString.c_str(), ssid.c_str()) == NULL)
bool bNetList = false; //whether to return buffer or netlist {
bool bInvalidType = false; ++printed;
bool bIntfError = false; measure->statusString += ssid;
unsigned int listStyle = 0; if (measure->listStyle > 0)
memset(buffer,'\0',128); {
listStyle = g_meas_data[id].listStyle; if (measure->listStyle == 1 || measure->listStyle == 3)
int printed = 0; //count of how many networks have been printed already {
// ADD PHY type
//Set up variables for WLAN queries measure->statusString += L" @";
ULONG outsize = 0; measure->statusString += GetDot11Str(pwnl->Network[i].dot11PhyTypes[0], 4);
PWLAN_CONNECTION_ATTRIBUTES wlan_cattr=NULL; }
PWLAN_AVAILABLE_NETWORK_LIST pwnl=NULL; if (measure->listStyle == 2 || measure->listStyle == 3)
DWORD dwCErr, dwLErr; {
GUID& intfGUID = pInterface->InterfaceGuid; // ADD cipher and authentication
measure->statusString += L" (";
//Initialize WLAN structs with queries, break if no interface found measure->statusString += GetDot11Str(pwnl->Network[i].dot11DefaultCipherAlgorithm, 1);
dwCErr= WlanQueryInterface( hClient, &intfGUID, wlan_intf_opcode_current_connection, NULL, &outsize, (PVOID*)&wlan_cattr, NULL ); measure->statusString += L':';
dwLErr= WlanGetAvailableNetworkList(hClient,&intfGUID,NULL,NULL,&pwnl); measure->statusString += GetDot11Str(pwnl->Network[i].dot11DefaultAuthAlgorithm, 2);
MEASURETYPE current_type = g_meas_data[id].type; measure->statusString += L')';
UINT listMax = g_meas_data[id].listMax; }
}
switch(current_type) measure->statusString += L'\n';
{ }
case LIST:
if (ERROR_SUCCESS != dwLErr){return L"Error";}
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);
if (g_meas_data[id].netlist == NULL){
LSLog(LOG_ERROR, NULL, L"WifiStatus.dll: Unable to allocate network list memory");
g_meas_data[id].listInit = false;
free(g_meas_data[id].netlist);
return NULL;
} }
g_meas_data[id].listInit = true;
WlanFreeMemory(pwnl);
} }
}
else
{
ULONG outsize = 0;
PWLAN_CONNECTION_ATTRIBUTES wlan_cattr = NULL;
DWORD dwErr = WlanQueryInterface(g_hClient, &g_pInterface->InterfaceGuid, wlan_intf_opcode_current_connection, NULL, &outsize, (PVOID*)&wlan_cattr, NULL);
memset(g_meas_data[id].netlist,'\0', (80 * sizeof(WCHAR) * g_meas_data[id].listMax)); if (ERROR_SUCCESS != dwErr)
memset(buffer,'\0',128); {
switch (measure->type)
//Check all items in WLAN NETWORK LIST {
for (int i=0; i < (int)pwnl->dwNumberOfItems ; i++){ case SSID:
if (printed == g_meas_data[id].listMax) case PHY:
case ENCRYPTION:
case AUTH:
measure->statusString = L"-1";
break;
}
}
else
{
switch (measure->type)
{
case QUALITY:
value = (double)wlan_cattr->wlanAssociationAttributes.wlanSignalQuality;
break; break;
//SSID is in UCHAR, convert to WCHAR case SSID:
mbstowcs(buffer,(char*)pwnl->Network[i].dot11Ssid.ucSSID,pwnl->Network[i].dot11Ssid.uSSIDLength); // Need to convert ucSSID to wchar from uchar
measure->statusString = ConvertToWide((LPCSTR)wlan_cattr->wlanAssociationAttributes.dot11Ssid.ucSSID, (int)wlan_cattr->wlanAssociationAttributes.dot11Ssid.uSSIDLength);
// If not connected yet add current status
measure->statusString += GetDot11Str(wlan_cattr->isState, 3);
break;
//Prevent duplicates that result from profiles, check using SSID case PHY:
if ((wcsstr(g_meas_data[id].netlist,buffer)== NULL)&&(_wcsicmp(L"", buffer) != 0)){ measure->statusString = GetDot11Str(wlan_cattr->wlanAssociationAttributes.dot11PhyType, 4);
printed++; break;
if (listStyle > 0){
wsprintf(g_meas_data[id].netlist,L"%s%s",g_meas_data[id].netlist,buffer); case ENCRYPTION:
memset(buffer,'\0',128); measure->statusString = GetDot11Str(wlan_cattr->wlanSecurityAttributes.dot11CipherAlgorithm, 1);
if (listStyle == 1 || listStyle == 3){ break;
//ADD PHY type
wsprintf(buffer,L" @%s", getDot11str(pwnl->Network[i].dot11PhyTypes[0],4)); case AUTH:
} measure->statusString = GetDot11Str(wlan_cattr->wlanSecurityAttributes.dot11AuthAlgorithm, 2);
if (listStyle == 2 || listStyle == 3){ break;
//ADD cipher and authentication
wsprintf(buffer,L"%s (%s:%s)",buffer,getDot11str(pwnl->Network[i].dot11DefaultCipherAlgorithm,1) default: // Invalid type
,getDot11str(pwnl->Network[i].dot11DefaultAuthAlgorithm,2)); measure->statusString.clear();
} break;
}
wsprintf(g_meas_data[id].netlist,L"%s%s\n",g_meas_data[id].netlist,buffer);
} }
memset(buffer,'\0',128);
}//end for WlanFreeMemory(wlan_cattr);
bNetList=true;
break;
case SSID:
if (ERROR_SUCCESS != dwCErr){
bIntfError = true;
break;
} }
//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;
case PHY:
if (ERROR_SUCCESS != dwCErr){
bIntfError = true;
break;
}
wcscpy(buffer,getDot11str(wlan_cattr->wlanAssociationAttributes.dot11PhyType,4));
break;
case ENCRYPTION:
if (ERROR_SUCCESS != dwCErr){
bIntfError = true;
break;
}
wcscpy(buffer,getDot11str(wlan_cattr->wlanSecurityAttributes.dot11CipherAlgorithm,1));
break;
case AUTH:
if (ERROR_SUCCESS != dwCErr){
bIntfError = true;
break;
}
wcscpy(buffer,getDot11str(wlan_cattr->wlanSecurityAttributes.dot11AuthAlgorithm,2));
break;
default: //InfoType does not refer to a string measure
bInvalidType= true;
break;
} }
if (wlan_cattr!=NULL)WlanFreeMemory(wlan_cattr);
if (pwnl!=NULL)WlanFreeMemory(pwnl);
if (bNetList) return value;
return g_meas_data[id].netlist; }
if (bIntfError)
return L"-1";
else { PLUGIN_EXPORT LPCWSTR GetString(void* data)
if (bInvalidType) {
return NULL; if (g_pInterface == NULL) return NULL;
else
return buffer; MeasureData* measure = (MeasureData*)data;
switch (measure->type)
{
case LIST:
case SSID:
case PHY:
case ENCRYPTION:
case AUTH:
return measure->statusString.c_str();
default:
return NULL;
}
}
PLUGIN_EXPORT void Finalize(void* data)
{
MeasureData* measure = (MeasureData*)data;
delete measure;
if (g_Instances > 0)
{
--g_Instances;
if (g_Instances == 0)
{
FinalizeHandle();
}
} }
} }
@ -368,134 +395,101 @@ LPCTSTR GetString(UINT id, UINT flags)
-type of ENUM (cipher=1, auth=2, status=3, phy=4, otherwise=error strings) -type of ENUM (cipher=1, auth=2, status=3, phy=4, otherwise=error strings)
out: String to be returned by measure out: String to be returned by measure
*/ */
LPCTSTR getDot11str(int dot11enum,int type){ LPCWSTR GetDot11Str(int dot11enum, int type)
if (type ==1){
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:
return L"???";
}
}
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:
return L"???";
}
}
else if (type==3){
switch(dot11enum){
case wlan_interface_state_connected:
return L"";
case wlan_interface_state_authenticating:
return L"(authorizing...)";
default:
return L"(connecting...)";
}
}
else if (type==4){
switch(dot11enum){
case dot11_phy_type_unknown:
return L"???";
case dot11_phy_type_dsss:
return L"DSSS";
case dot11_phy_type_erp:
return L"802.11g";
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:
return L"802.11n";
default:
return L"???";
}
}
else{
switch(dot11enum){
case ERROR_INVALID_PARAMETER:
return L"Invalid parameters";
case ERROR_NOT_ENOUGH_MEMORY:
return L"Not enough memory";
case ERROR_REMOTE_SESSION_LIMIT_EXCEEDED:
return L"Too many handles already issued";
default:
return L"Unknown error code";
}
}
}
/*
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)
{ {
std::map<UINT, meas_data_t>::iterator i1 = g_meas_data.find(id); if (type == 1)
if (i1 != g_meas_data.end())
{ {
free(g_meas_data[id].netlist); switch (dot11enum)
g_meas_data[id].listInit = false; {
g_meas_data.erase(i1); 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:
return L"???";
}
} }
g_Instances--; else if (type == 2)
if (hClient != NULL && g_Instances == 0){ {
WlanCloseHandle(hClient, NULL); switch (dot11enum)
hClient = NULL; {
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:
return L"???";
}
} }
if (pIntfList != NULL && g_Instances == 0){ else if (type == 3)
WlanFreeMemory(pIntfList); {
pIntfList = NULL; switch (dot11enum)
{
case wlan_interface_state_connected:
return L"";
case wlan_interface_state_authenticating:
return L"(authorizing...)";
default:
return L"(connecting...)";
}
}
else if (type == 4)
{
switch (dot11enum)
{
case dot11_phy_type_unknown:
default:
return L"???";
case dot11_phy_type_dsss:
return L"DSSS";
case dot11_phy_type_erp:
return L"802.11g";
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:
return L"802.11n";
}
}
else
{
switch (dot11enum)
{
case ERROR_INVALID_PARAMETER:
return L"Invalid parameters";
case ERROR_NOT_ENOUGH_MEMORY:
return L"Not enough memory";
case ERROR_REMOTE_SESSION_LIMIT_EXCEEDED:
return L"Too many handles already issued";
default:
return L"Unknown error code";
}
} }
} }
/*
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()
{
return 1009;
}
/*
Returns the author of the plugin for the about dialog.
*/
LPCTSTR GetPluginAuthor()
{
return L"nvme (shaivya.m@gmail.com)";
}