[WLANCONF]

- Add localization support. Patch by Lee Schroeder.
CORE-6721

svn path=/trunk/; revision=57539
This commit is contained in:
Thomas Faber 2012-10-12 11:40:53 +00:00
parent 4377ed8869
commit 4ea59af31f
5 changed files with 150 additions and 51 deletions

View file

@ -3,6 +3,13 @@ include_directories(
BEFORE include
${REACTOS_SOURCE_DIR}/include/reactos/drivers/ndisuio)
add_executable(wlanconf wlanconf.c wlanconf.rc)
# FIXME: http://www.cmake.org/Bug/view.php?id=12998
if(NOT MSVC)
#add_target_compile_flags(wlanconf "-Wno-format")
set_source_files_properties(wlanconf.c PROPERTIES COMPILE_FLAGS "-Wno-format")
endif()
set_module_type(wlanconf win32cui)
add_importlibs(wlanconf msvcrt iphlpapi kernel32)
add_importlibs(wlanconf msvcrt user32 iphlpapi kernel32)
add_cd_file(TARGET wlanconf DESTINATION reactos/system32 FOR all)

View file

@ -0,0 +1,40 @@
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
STRINGTABLE DISCARDABLE
BEGIN
IDS_USAGE, "\nConfigure a WLAN adapter.\n\n\
WLANCONF [-c SSID [-w WEP] [-a]] [-d] [-s]\n\n\
\t-c SSID\t\tConnects to a supplied SSID,\n\
\t-w WEP\t\tSpecifies a WEP key to use.\n\
\t-a\t\tSpecifies the target network is ad-hoc\n\
\t-d\t\tDisconnects from the current AP.\n\
\t-s\t\tScans and displays a list of access points\n\
\t\t\tin range.\n\n\
Passing no parameters will print information about the current WLAN connection\n"
/* === */
IDS_NO_NETWORK, "No networks found in range\n"
IDS_NO_WLAN_ADAPTER, "Unable to find a WLAN adapter on the system\n"
IDS_SUCCESS, "The operation completed successfully.\n"
IDS_WLAN_DISCONNECT, "\nWLAN disconnected\n"
/* === */
IDS_MSG_WEP_ENABLED, "WEP enabled: %s\n"
IDS_MSG_NETWORK_MODE, "Network mode: %s\n"
IDS_MSG_CURRENT_WIRELESS, "\nCurrent wireless configuration information:\n\n"
IDS_MSG_ENCRYPTED, "Encrypted: %s\n"
IDS_MSG_NETWORK_TYPE, "Network Type: %s\n"
IDS_MSG_RSSI, "RSSI: %i dBm\n"
IDS_MSG_SUPPORT_RATE, "Supported Rates (Mbps): "
IDS_MSG_TRANSMISSION_POWER, "Transmission power: %d mW\n"
IDS_MSG_ANTENNA_COUNT, "Antenna count: %d\n"
IDS_MSG_TRANSMIT_ANTENNA, "Transmit antenna: %d\n"
IDS_MSG_TRANSMIT_ANTENNA_ANY, "Transmit antenna: Any\n"
IDS_MSG_RECEIVE_ANTENNA, "Receive antenna: %d\n"
IDS_MSG_RECEIVE_ANTENNA_ANY, "Receive antenna: Any\n"
IDS_MSG_FRAGMENT_THRESHOLD, "Fragmentation threshold: %d bytes\n"
IDS_MSG_RTS_THRESHOLD, "RTS threshold: %d bytes\n"
/* === */
IDS_YES, "Yes"
IDS_NO, "No"
IDS_ADHOC, "Adhoc"
IDS_INFRASTRUCTURE, "Infrastructure"
END

View file

@ -0,0 +1,24 @@
#define IDS_USAGE 0
#define IDS_NO_NETWORK 1
#define IDS_NO_WLAN_ADAPTER 2
#define IDS_SUCCESS 3
#define IDS_WLAN_DISCONNECT 4
#define IDS_MSG_WEP_ENABLED 5
#define IDS_MSG_NETWORK_MODE 6
#define IDS_MSG_CURRENT_WIRELESS 7
#define IDS_MSG_ENCRYPTED 8
#define IDS_MSG_NETWORK_TYPE 9
#define IDS_MSG_RSSI 10
#define IDS_MSG_SUPPORT_RATE 11
#define IDS_MSG_TRANSMISSION_POWER 12
#define IDS_MSG_ANTENNA_COUNT 13
#define IDS_MSG_TRANSMIT_ANTENNA 14
#define IDS_MSG_TRANSMIT_ANTENNA_ANY 15
#define IDS_MSG_RECEIVE_ANTENNA 16
#define IDS_MSG_RECEIVE_ANTENNA_ANY 17
#define IDS_MSG_FRAGMENT_THRESHOLD 18
#define IDS_MSG_RTS_THRESHOLD 19
#define IDS_YES 20
#define IDS_NO 21
#define IDS_ADHOC 22
#define IDS_INFRASTRUCTURE 23

View file

@ -14,6 +14,11 @@
#include <nuiouser.h>
#include <iphlpapi.h>
#include "resource.h"
#define COUNT_OF(a) (sizeof(a) / sizeof(a[0]))
#define MAX_BUFFER_SIZE 5024
BOOL bScan = FALSE;
BOOL bConnect = FALSE;
@ -23,6 +28,19 @@ BOOL bAdhoc = FALSE;
BOOL bDisconnect = FALSE;
/* This takes strings from a resource stringtable and outputs it to
the command prompt. */
VOID PrintResourceString(INT resID, ...)
{
TCHAR szMsgBuf[MAX_BUFFER_SIZE];
va_list arg_ptr;
va_start(arg_ptr, resID);
LoadString(GetModuleHandle(NULL), resID, szMsgBuf, MAX_BUFFER_SIZE);
_vtprintf(szMsgBuf, arg_ptr);
va_end(arg_ptr);
}
DWORD DoFormatMessage(DWORD ErrorCode)
{
LPVOID lpMsgBuf;
@ -258,7 +276,7 @@ WlanDisconnect(HANDLE hAdapter, PIP_ADAPTER_INDEX_MAP IpInfo)
if (!bSuccess)
return FALSE;
_tprintf(_T("The operation completed successfully.\n"));
PrintResourceString(IDS_SUCCESS);
return TRUE;
}
@ -317,6 +335,7 @@ WlanPrintCurrentStatus(HANDLE hAdapter)
PNDIS_802_11_SSID SsidInfo;
CHAR SsidBuffer[NDIS_802_11_LENGTH_SSID + 1];
DWORD i;
TCHAR szMsgBuf[128];
QueryOidSize = FIELD_OFFSET(NDISUIO_QUERY_OID, Data) + sizeof(NDIS_802_11_SSID);
QueryOid = HeapAlloc(GetProcessHeap(), 0, QueryOidSize);
@ -362,16 +381,16 @@ WlanPrintCurrentStatus(HANDLE hAdapter)
NULL);
if (SsidInfo->SsidLength == 0 || !bSuccess)
{
_tprintf(_T("\nWLAN disconnected\n"));
PrintResourceString(IDS_WLAN_DISCONNECT);
HeapFree(GetProcessHeap(), 0, QueryOid);
return TRUE;
}
else
{
_tprintf(_T("\nCurrent wireless configuration information:\n\n"));
PrintResourceString(IDS_MSG_CURRENT_WIRELESS);
}
_tprintf(_T("SSID: %s\n"), SsidBuffer);
_tprintf(_T("SSID: %hs\n"), SsidBuffer);
_tprintf(_T("BSSID: "));
for (i = 0; i < sizeof(NDIS_802_11_MAC_ADDRESS); i++)
@ -407,7 +426,11 @@ WlanPrintCurrentStatus(HANDLE hAdapter)
return FALSE;
}
_tprintf(_T("Network mode: %s\n"), (*(PUINT)QueryOid->Data == Ndis802_11IBSS) ? "Adhoc" : "Infrastructure");
LoadString(GetModuleHandle(NULL),
*(PUINT)QueryOid->Data == Ndis802_11IBSS ? IDS_ADHOC : IDS_INFRASTRUCTURE,
szMsgBuf,
COUNT_OF(szMsgBuf));
PrintResourceString(IDS_MSG_NETWORK_MODE, szMsgBuf);
QueryOid->Oid = OID_802_11_WEP_STATUS;
@ -425,9 +448,13 @@ WlanPrintCurrentStatus(HANDLE hAdapter)
return FALSE;
}
_tprintf(_T("WEP enabled: %s\n"), (*(PUINT)QueryOid->Data == Ndis802_11WEPEnabled) ? "Yes" : "No");
LoadString(GetModuleHandle(NULL),
*(PUINT)QueryOid->Data == Ndis802_11WEPEnabled ? IDS_YES : IDS_NO,
szMsgBuf,
COUNT_OF(szMsgBuf));
PrintResourceString(IDS_MSG_WEP_ENABLED, szMsgBuf);
_tprintf("\n");
_tprintf(_T("\n"));
QueryOid->Oid = OID_802_11_RSSI;
bSuccess = DeviceIoControl(hAdapter,
@ -457,7 +484,7 @@ WlanPrintCurrentStatus(HANDLE hAdapter)
if (bSuccess)
{
/* This OID is optional */
_tprintf(_T("Transmission power: %d mW\n"), *(PUINT)QueryOid->Data);
PrintResourceString(IDS_MSG_TRANSMISSION_POWER, *(PUINT)QueryOid->Data);
}
_tprintf(_T("\n"));
@ -475,7 +502,7 @@ WlanPrintCurrentStatus(HANDLE hAdapter)
if (bSuccess)
{
/* This OID is optional */
_tprintf(_T("Antenna count: %d\n"), *(PUINT)QueryOid->Data);
PrintResourceString(IDS_MSG_ANTENNA_COUNT, *(PUINT)QueryOid->Data);
}
QueryOid->Oid = OID_802_11_TX_ANTENNA_SELECTED;
@ -493,9 +520,9 @@ WlanPrintCurrentStatus(HANDLE hAdapter)
UINT TransmitAntenna = *(PUINT)QueryOid->Data;
if (TransmitAntenna != 0xFFFFFFFF)
_tprintf(_T("Transmit antenna: %d\n"), TransmitAntenna);
PrintResourceString(IDS_MSG_TRANSMIT_ANTENNA, TransmitAntenna);
else
_tprintf(_T("Transmit antenna: Any\n"));
PrintResourceString(IDS_MSG_TRANSMIT_ANTENNA_ANY);
}
QueryOid->Oid = OID_802_11_RX_ANTENNA_SELECTED;
@ -513,9 +540,9 @@ WlanPrintCurrentStatus(HANDLE hAdapter)
UINT ReceiveAntenna = *(PUINT)QueryOid->Data;
if (ReceiveAntenna != 0xFFFFFFFF)
_tprintf(_T("Receive antenna: %d\n"), ReceiveAntenna);
PrintResourceString(IDS_MSG_RECEIVE_ANTENNA, ReceiveAntenna);
else
_tprintf(_T("Receive antenna: Any\n"));
PrintResourceString(IDS_MSG_RECEIVE_ANTENNA_ANY);
}
_tprintf(_T("\n"));
@ -533,7 +560,7 @@ WlanPrintCurrentStatus(HANDLE hAdapter)
if (bSuccess)
{
/* This OID is optional */
_tprintf(_T("Fragmentation threshold: %d bytes\n"), *(PUINT)QueryOid->Data);
PrintResourceString(IDS_MSG_FRAGMENT_THRESHOLD, *(PUINT)QueryOid->Data);
}
QueryOid->Oid = OID_802_11_RTS_THRESHOLD;
@ -549,7 +576,7 @@ WlanPrintCurrentStatus(HANDLE hAdapter)
if (bSuccess)
{
/* This OID is optional */
_tprintf(_T("RTS threshold: %d bytes\n"), *(PUINT)QueryOid->Data);
PrintResourceString(IDS_MSG_RTS_THRESHOLD, *(PUINT)QueryOid->Data);
}
HeapFree(GetProcessHeap(), 0, QueryOid);
@ -722,7 +749,7 @@ WlanConnect(HANDLE hAdapter)
if (!bSuccess)
return FALSE;
_tprintf(_T("The operation completed successfully.\n"));
PrintResourceString(IDS_SUCCESS);
return TRUE;
}
@ -736,6 +763,7 @@ WlanScan(HANDLE hAdapter)
DWORD QueryOidSize;
PNDIS_802_11_BSSID_LIST BssidList;
DWORD i, j;
TCHAR szMsgBuf[128];
SetOid.Oid = OID_802_11_BSSID_LIST_SCAN;
@ -776,7 +804,7 @@ WlanScan(HANDLE hAdapter)
if (BssidList->NumberOfItems == 0)
{
_tprintf(_T("No networks found in range\n"));
PrintResourceString(IDS_NO_NETWORK);
}
else
{
@ -793,9 +821,7 @@ WlanScan(HANDLE hAdapter)
RtlCopyMemory(SsidBuffer, Ssid->Ssid, Ssid->SsidLength);
SsidBuffer[Ssid->SsidLength] = 0;
_tprintf(_T("\n"));
_tprintf(_T("SSID: %s\n"), SsidBuffer);
_tprintf(_T("\nSSID: %hs\n"), SsidBuffer);
_tprintf(_T("BSSID: "));
for (j = 0; j < sizeof(NDIS_802_11_MAC_ADDRESS); j++)
@ -809,13 +835,18 @@ WlanScan(HANDLE hAdapter)
}
_tprintf(_T("\n"));
_tprintf(_T("Encrypted: %s\n"
"Network Type: %s\n"
"RSSI: %i dBm\n"
"Supported Rates (Mbps): "),
BssidInfo->Privacy == 0 ? "No" : "Yes",
NetworkType == Ndis802_11IBSS ? "Adhoc" : "Infrastructure",
(int)Rssi);
LoadString(GetModuleHandle(NULL),
BssidInfo->Privacy == 0 ? IDS_NO : IDS_YES,
szMsgBuf,
COUNT_OF(szMsgBuf));
PrintResourceString(IDS_MSG_ENCRYPTED, szMsgBuf);
LoadString(GetModuleHandle(NULL),
NetworkType == Ndis802_11IBSS ? IDS_ADHOC : IDS_INFRASTRUCTURE,
szMsgBuf,
COUNT_OF(szMsgBuf));
PrintResourceString(IDS_MSG_NETWORK_TYPE, szMsgBuf);
PrintResourceString(IDS_MSG_RSSI, (int)Rssi);
PrintResourceString(IDS_MSG_SUPPORT_RATE);
for (j = 0; j < NDIS_802_11_LENGTH_RATES; j++)
{
@ -850,19 +881,6 @@ WlanScan(HANDLE hAdapter)
return bSuccess;
}
VOID Usage()
{
_tprintf(_T("\nConfigures a WLAN adapter.\n\n"
"WLANCONF [-c SSID [-w WEP] [-a]] [-d] [-s]\n\n"
" -c SSID Connects to a supplied SSID.\n"
" -w WEP Specifies a WEP key to use.\n"
" -a Specifies the target network is ad-hoc\n"
" -d Disconnects from the current AP.\n"
" -s Scans and displays a list of access points in range.\n\n"
" Passing no parameters will print information about the current WLAN connection\n"));
}
BOOL ParseCmdline(int argc, char *argv[])
{
INT i;
@ -882,7 +900,7 @@ BOOL ParseCmdline(int argc, char* argv[])
case 'c':
if (i == argc - 1)
{
Usage();
PrintResourceString(IDS_USAGE);
return FALSE;
}
bConnect = TRUE;
@ -891,7 +909,7 @@ BOOL ParseCmdline(int argc, char* argv[])
case 'w':
if (i == argc - 1)
{
Usage();
PrintResourceString(IDS_USAGE);
return FALSE;
}
sWepKey = argv[++i];
@ -900,14 +918,14 @@ BOOL ParseCmdline(int argc, char* argv[])
bAdhoc = TRUE;
break;
default :
Usage();
PrintResourceString(IDS_USAGE);
return FALSE;
}
}
else
{
Usage();
PrintResourceString(IDS_USAGE);
return FALSE;
}
}
@ -925,7 +943,7 @@ int main(int argc, char* argv[])
if (!OpenWlanAdapter(&hAdapter, &IpInfo))
{
_tprintf(_T("Unable to find a WLAN adapter on the system\n"));
PrintResourceString(IDS_NO_WLAN_ADAPTER);
return -1;
}

View file

@ -1,7 +1,17 @@
#include "resource.h"
#include <windows.h>
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
#define REACTOS_STR_FILE_DESCRIPTION "ReactOS WLAN Configuration Tool\0"
#define REACTOS_STR_INTERNAL_NAME "wlanconf\0"
#define REACTOS_STR_ORIGINAL_FILENAME "wlanconf.exe\0"
#define REACTOS_STR_ORIGINAL_COPYRIGHT "Cameron Gutman (cameron.gutman@reactos.org)\0"
#include <reactos/version.rc>
// UTF-8
#pragma code_page(65001)
#ifdef LANGUAGE_EN_US
#include "lang/en-US.rc"
#endif