ReactOS  0.4.14-dev-599-g2d4d3f5
wlanconf.c File Reference
#include <stdio.h>
#include <stdarg.h>
#include <tchar.h>
#include <windef.h>
#include <winbase.h>
#include <devioctl.h>
#include <ntddndis.h>
#include <nuiouser.h>
#include <iphlpapi.h>
#include <conutils.h>
#include "resource.h"
Include dependency graph for wlanconf.c:

Go to the source code of this file.

Functions

VOID DoFormatMessage (DWORD ErrorCode)
 
HANDLE OpenDriverHandle (VOID)
 
BOOL IsWlanAdapter (HANDLE hAdapter)
 
BOOL OpenAdapterHandle (DWORD Index, HANDLE *hAdapter, IP_ADAPTER_INDEX_MAP *IpInfo)
 
BOOL OpenWlanAdapter (HANDLE *hAdapter, IP_ADAPTER_INDEX_MAP *IpInfo)
 
BOOL WlanDisconnect (HANDLE hAdapter, PIP_ADAPTER_INDEX_MAP IpInfo)
 
static UCHAR CharToHex (WCHAR Char)
 
BOOL WlanPrintCurrentStatus (HANDLE hAdapter)
 
BOOL WlanConnect (HANDLE hAdapter)
 
BOOL WlanScan (HANDLE hAdapter)
 
BOOL ParseCmdline (int argc, WCHAR *argv[])
 
int wmain (int argc, WCHAR *argv[])
 

Variables

BOOL bScan = FALSE
 
BOOL bConnect = FALSE
 
WCHARsSsid = NULL
 
WCHARsWepKey = NULL
 
BOOL bAdhoc = FALSE
 
BOOL bDisconnect = FALSE
 

Function Documentation

◆ CharToHex()

static UCHAR CharToHex ( WCHAR  Char)
static

Definition at line 255 of file wlanconf.c.

256 {
257  if ((Char >= L'0') && (Char <= L'9'))
258  return Char - L'0';
259 
260  if ((Char >= L'a') && (Char <= L'f'))
261  return Char - L'a' + 10;
262 
263  if ((Char >= L'A') && (Char <= L'F'))
264  return Char - L'A' + 10;
265 
266  return 0;
267 }
static const WCHAR L[]
Definition: oid.c:1250

Referenced by WlanConnect().

◆ DoFormatMessage()

VOID DoFormatMessage ( DWORD  ErrorCode)

Definition at line 33 of file wlanconf.c.

34 {
35  if (ErrorCode == ERROR_SUCCESS)
36  return;
37 
40 }
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define ERROR_SUCCESS
Definition: deptool.c:10
smooth NULL
Definition: ftsmooth.c:416
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:404
INT ConMsgPuts(IN PCON_STREAM Stream, IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId)
Definition: outstream.c:837
#define StdErr
Definition: stream.h:77
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50

Referenced by wmain().

◆ IsWlanAdapter()

BOOL IsWlanAdapter ( HANDLE  hAdapter)

Definition at line 79 of file wlanconf.c.

80 {
81  BOOL bSuccess;
82  DWORD dwBytesReturned;
83  NDISUIO_QUERY_OID QueryOid;
84 
85  /* WLAN drivers must support this OID */
86  QueryOid.Oid = OID_GEN_PHYSICAL_MEDIUM;
87 
88  bSuccess = DeviceIoControl(hAdapter,
90  &QueryOid,
91  sizeof(QueryOid),
92  &QueryOid,
93  sizeof(QueryOid),
94  &dwBytesReturned,
95  NULL);
96  if (!bSuccess || *(PULONG)QueryOid.Data != NdisPhysicalMediumWirelessLan)
97  return FALSE;
98 
99  return TRUE;
100 }
#define OID_GEN_PHYSICAL_MEDIUM
Definition: ntddndis.h:264
#define TRUE
Definition: types.h:120
#define IOCTL_NDISUIO_QUERY_OID_VALUE
Definition: nuiouser.h:16
static BOOLEAN bSuccess
Definition: drive.cpp:419
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136
unsigned int * PULONG
Definition: retypes.h:1
UCHAR Data[sizeof(ULONG)]
Definition: nuiouser.h:38
NDIS_OID Oid
Definition: nuiouser.h:37

Referenced by OpenWlanAdapter().

◆ OpenAdapterHandle()

BOOL OpenAdapterHandle ( DWORD  Index,
HANDLE hAdapter,
IP_ADAPTER_INDEX_MAP IpInfo 
)

Definition at line 103 of file wlanconf.c.

104 {
105  HANDLE hDriver;
106  BOOL bSuccess;
107  DWORD dwBytesReturned;
108  DWORD QueryBindingSize = sizeof(NDISUIO_QUERY_BINDING) + (1024 * sizeof(WCHAR));
111  LONG i;
112  PIP_INTERFACE_INFO InterfaceInfo = NULL;
113 
114  /* Open the driver handle */
117  return FALSE;
118 
119  /* Allocate the binding struct */
120  QueryBinding = HeapAlloc(GetProcessHeap(), 0, QueryBindingSize);
121  if (!QueryBinding)
122  {
124  return FALSE;
125  }
126 
127  /* Query the adapter binding information */
128  QueryBinding->BindingIndex = Index;
131  QueryBinding,
132  QueryBindingSize,
133  QueryBinding,
134  QueryBindingSize,
135  &dwBytesReturned,
136  NULL);
137 
138  if (!bSuccess)
139  {
142  return FALSE;
143  }
144 
145  /* Bind to the adapter */
148  (PUCHAR)QueryBinding + QueryBinding->DeviceNameOffset,
149  QueryBinding->DeviceNameLength,
150  NULL,
151  0,
152  &dwBytesReturned,
153  NULL);
154 
155  if (!bSuccess)
156  {
159  return FALSE;
160  }
161 
162  /* Get interface info from the IP helper */
163  dwSize = sizeof(IP_INTERFACE_INFO);
164  do {
165  if (InterfaceInfo) HeapFree(GetProcessHeap(), 0, InterfaceInfo);
166  InterfaceInfo = HeapAlloc(GetProcessHeap(), 0, dwSize);
167  if (!InterfaceInfo)
168  {
171  return FALSE;
172  }
173  dwStatus = GetInterfaceInfo(InterfaceInfo, &dwSize);
174  } while (dwStatus == ERROR_INSUFFICIENT_BUFFER);
175 
176  if (dwStatus != NO_ERROR)
177  {
179  HeapFree(GetProcessHeap(), 0, InterfaceInfo);
181  return FALSE;
182  }
183 
184  for (i = 0; i < InterfaceInfo->NumAdapters; i++)
185  {
186  if (wcsstr((PWCHAR)((PUCHAR)QueryBinding + QueryBinding->DeviceNameOffset),
187  InterfaceInfo->Adapter[i].Name))
188  {
189  *IpInfo = InterfaceInfo->Adapter[i];
190  *hAdapter = hDriver;
191 
193  HeapFree(GetProcessHeap(), 0, InterfaceInfo);
194 
195  return TRUE;
196  }
197  }
198 
200  HeapFree(GetProcessHeap(), 0, InterfaceInfo);
202 
203  return FALSE;
204 }
static NTSTATUS QueryBinding(PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: ioctl.c:34
IP_ADAPTER_INDEX_MAP Adapter[1]
Definition: ipexport.h:141
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:406
_CONST_RETURN wchar_t *__cdecl wcsstr(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_SubStr)
unsigned char * PUCHAR
Definition: retypes.h:3
DWORD WINAPI GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable, PULONG dwOutBufLen)
_In_ LPWSTR _In_ ULONG _In_ ULONG _In_ ULONG _Out_ DEVINFO _In_ HDEV _In_ LPWSTR _In_ HANDLE hDriver
Definition: winddi.h:3553
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
HANDLE OpenDriverHandle(VOID)
Definition: wlanconf.c:43
uint16_t * PWCHAR
Definition: typedefs.h:54
#define NO_ERROR
Definition: dderror.h:5
static BOOLEAN bSuccess
Definition: drive.cpp:419
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
struct _NDISUIO_QUERY_BINDING NDISUIO_QUERY_BINDING
unsigned int BOOL
Definition: ntddk_ex.h:94
#define IOCTL_NDISUIO_QUERY_BINDING
Definition: nuiouser.h:23
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
WCHAR Name[MAX_ADAPTER_NAME]
Definition: ipexport.h:136
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
static const UCHAR Index[8]
Definition: usbohci.c:18
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD dwStatus
Definition: mediaobj.idl:95
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136
#define IOCTL_NDISUIO_OPEN_DEVICE
Definition: nuiouser.h:12
#define HeapFree(x, y, z)
Definition: compat.h:402
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
struct _IP_INTERFACE_INFO IP_INTERFACE_INFO
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by OpenWlanAdapter().

◆ OpenDriverHandle()

HANDLE OpenDriverHandle ( VOID  )

Definition at line 43 of file wlanconf.c.

44 {
46  DWORD dwBytesReturned;
47  BOOL bSuccess;
48 
49  /* Open a handle to the NDISUIO driver */
52  0,
53  NULL,
56  NULL);
58  return INVALID_HANDLE_VALUE;
59 
60  /* Wait for binds */
63  NULL,
64  0,
65  NULL,
66  0,
67  &dwBytesReturned,
68  NULL);
69  if (!bSuccess)
70  {
72  return INVALID_HANDLE_VALUE;
73  }
74 
75  return hDriver;
76 }
#define CloseHandle
Definition: compat.h:406
#define IOCTL_NDISUIO_BIND_WAIT
Definition: nuiouser.h:27
_In_ LPWSTR _In_ ULONG _In_ ULONG _In_ ULONG _Out_ DEVINFO _In_ HDEV _In_ LPWSTR _In_ HANDLE hDriver
Definition: winddi.h:3553
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
static BOOLEAN bSuccess
Definition: drive.cpp:419
#define NDISUIO_DEVICE_NAME
Definition: nuiouser.h:9
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
#define OPEN_EXISTING
Definition: compat.h:434
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define GENERIC_READ
Definition: compat.h:124
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136
#define CreateFileW
Definition: compat.h:408

Referenced by OpenAdapterHandle().

◆ OpenWlanAdapter()

BOOL OpenWlanAdapter ( HANDLE hAdapter,
IP_ADAPTER_INDEX_MAP IpInfo 
)

Definition at line 208 of file wlanconf.c.

209 {
210  DWORD dwCurrentIndex;
211 
212  for (dwCurrentIndex = 0; ; dwCurrentIndex++)
213  {
214  if (!OpenAdapterHandle(dwCurrentIndex, hAdapter, IpInfo))
215  break;
216 
217  if (IsWlanAdapter(*hAdapter))
218  return TRUE;
219  else
220  CloseHandle(*hAdapter);
221  }
222 
223  return FALSE;
224 }
BOOL OpenAdapterHandle(DWORD Index, HANDLE *hAdapter, IP_ADAPTER_INDEX_MAP *IpInfo)
Definition: wlanconf.c:103
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:406
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL IsWlanAdapter(HANDLE hAdapter)
Definition: wlanconf.c:79

Referenced by wmain().

◆ ParseCmdline()

BOOL ParseCmdline ( int  argc,
WCHAR argv[] 
)

Definition at line 849 of file wlanconf.c.

850 {
851  INT i;
852 
853  for (i = 1; i < argc; i++)
854  {
855  if (argv[i][0] == L'-')
856  {
857  switch (argv[i][1])
858  {
859  case L's':
860  bScan = TRUE;
861  break;
862  case L'd':
863  bDisconnect = TRUE;
864  break;
865  case L'c':
866  if (i == argc - 1)
867  {
869  return FALSE;
870  }
871  bConnect = TRUE;
872  sSsid = argv[++i];
873  break;
874  case L'w':
875  if (i == argc - 1)
876  {
878  return FALSE;
879  }
880  sWepKey = argv[++i];
881  break;
882  case L'a':
883  bAdhoc = TRUE;
884  break;
885  default :
887  return FALSE;
888  }
889 
890  }
891  else
892  {
894  return FALSE;
895  }
896  }
897 
898  return TRUE;
899 }
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
BOOL bDisconnect
Definition: wlanconf.c:31
#define IDS_USAGE
Definition: resource.h:3
#define argv
Definition: mplay32.c:18
int32_t INT
Definition: typedefs.h:56
WCHAR * sWepKey
Definition: wlanconf.c:28
BOOL bAdhoc
Definition: wlanconf.c:29
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
BOOL bScan
Definition: wlanconf.c:24
BOOL bConnect
Definition: wlanconf.c:26
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
static const WCHAR L[]
Definition: oid.c:1250
WCHAR * sSsid
Definition: wlanconf.c:27
#define StdOut
Definition: stream.h:76

Referenced by wmain().

◆ WlanConnect()

BOOL WlanConnect ( HANDLE  hAdapter)

Definition at line 530 of file wlanconf.c.

531 {
532  CHAR SsidBuffer[NDIS_802_11_LENGTH_SSID + 1];
533  BOOL bSuccess;
534  DWORD dwBytesReturned, SetOidSize;
535  PNDISUIO_SET_OID SetOid;
536  PNDIS_802_11_SSID Ssid;
537  DWORD i;
538 
539  SetOidSize = sizeof(NDISUIO_SET_OID);
540  SetOid = HeapAlloc(GetProcessHeap(), 0, SetOidSize);
541  if (!SetOid)
542  return FALSE;
543 
544  /* Set the network mode */
547 
548  bSuccess = DeviceIoControl(hAdapter,
550  SetOid,
551  SetOidSize,
552  NULL,
553  0,
554  &dwBytesReturned,
555  NULL);
556  if (!bSuccess)
557  {
558  HeapFree(GetProcessHeap(), 0, SetOid);
559  return FALSE;
560  }
561 
562  /* Set the authentication mode */
565 
566  bSuccess = DeviceIoControl(hAdapter,
568  SetOid,
569  SetOidSize,
570  NULL,
571  0,
572  &dwBytesReturned,
573  NULL);
574  if (!bSuccess)
575  {
576  HeapFree(GetProcessHeap(), 0, SetOid);
577  return FALSE;
578  }
579 
580  if (sWepKey)
581  {
582  PNDIS_802_11_WEP WepData;
583 
584  HeapFree(GetProcessHeap(), 0, SetOid);
585 
586  SetOidSize = FIELD_OFFSET(NDISUIO_SET_OID, Data) +
587  FIELD_OFFSET(NDIS_802_11_WEP, KeyMaterial) +
588  (wcslen(sWepKey) >> 1);
589  SetOid = HeapAlloc(GetProcessHeap(), 0, SetOidSize);
590  if (!SetOid)
591  return FALSE;
592 
593  /* Add the WEP key */
594  SetOid->Oid = OID_802_11_ADD_WEP;
595  WepData = (PNDIS_802_11_WEP)SetOid->Data;
596 
597  WepData->KeyIndex = 0x80000000;
598  WepData->KeyLength = wcslen(sWepKey) >> 1;
599  WepData->Length = FIELD_OFFSET(NDIS_802_11_WEP, KeyMaterial) + WepData->KeyLength;
600 
601  /* Assemble the hex key */
602  i = 0;
603  while (sWepKey[i << 1] != '\0')
604  {
605  WepData->KeyMaterial[i] = CharToHex(sWepKey[i << 1]) << 4;
606  WepData->KeyMaterial[i] |= CharToHex(sWepKey[(i << 1) + 1]);
607  i++;
608  }
609 
610  bSuccess = DeviceIoControl(hAdapter,
612  SetOid,
613  SetOidSize,
614  NULL,
615  0,
616  &dwBytesReturned,
617  NULL);
618  if (!bSuccess)
619  {
620  HeapFree(GetProcessHeap(), 0, SetOid);
621  return FALSE;
622  }
623  }
624 
625  /* Set the encryption status */
626  SetOid->Oid = OID_802_11_WEP_STATUS;
628 
629  bSuccess = DeviceIoControl(hAdapter,
631  SetOid,
632  SetOidSize,
633  NULL,
634  0,
635  &dwBytesReturned,
636  NULL);
637  if (!bSuccess)
638  {
639  HeapFree(GetProcessHeap(), 0, SetOid);
640  return FALSE;
641  }
642 
643  HeapFree(GetProcessHeap(), 0, SetOid);
644  SetOidSize = FIELD_OFFSET(NDISUIO_SET_OID, Data) + sizeof(NDIS_802_11_MAC_ADDRESS);
645  SetOid = HeapAlloc(GetProcessHeap(), 0, SetOidSize);
646  if (!SetOid)
647  return FALSE;
648 
649  /* Set the BSSID */
650  SetOid->Oid = OID_802_11_BSSID;
651  RtlFillMemory(SetOid->Data, sizeof(NDIS_802_11_MAC_ADDRESS), 0xFF);
652 
653  bSuccess = DeviceIoControl(hAdapter,
655  SetOid,
656  SetOidSize,
657  NULL,
658  0,
659  &dwBytesReturned,
660  NULL);
661  if (!bSuccess)
662  {
663  HeapFree(GetProcessHeap(), 0, SetOid);
664  return FALSE;
665  }
666 
667  HeapFree(GetProcessHeap(), 0, SetOid);
668  SetOidSize = FIELD_OFFSET(NDISUIO_SET_OID, Data) + sizeof(NDIS_802_11_SSID);
669  SetOid = HeapAlloc(GetProcessHeap(), 0, SetOidSize);
670  if (!SetOid)
671  return FALSE;
672 
673  /* Finally, set the SSID */
674  SetOid->Oid = OID_802_11_SSID;
675  Ssid = (PNDIS_802_11_SSID)SetOid->Data;
676 
677  snprintf(SsidBuffer, sizeof(SsidBuffer), "%S", sSsid);
678  RtlCopyMemory(Ssid->Ssid, SsidBuffer, strlen(SsidBuffer));
679  Ssid->SsidLength = strlen(SsidBuffer);
680 
681  bSuccess = DeviceIoControl(hAdapter,
683  SetOid,
684  SetOidSize,
685  NULL,
686  0,
687  &dwBytesReturned,
688  NULL);
689 
690  HeapFree(GetProcessHeap(), 0, SetOid);
691 
692  if (!bSuccess)
693  return FALSE;
694 
696  return TRUE;
697 }
#define OID_802_11_WEP_STATUS
Definition: ntddndis.h:344
UCHAR KeyMaterial[1]
Definition: ntddndis.h:155
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define NDIS_802_11_LENGTH_SSID
Definition: ntddndis.h:100
struct _NDISUIO_SET_OID NDISUIO_SET_OID
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define OID_802_11_BSSID
Definition: ntddndis.h:319
char CHAR
Definition: xmlstorage.h:175
#define snprintf
Definition: wintirpc.h:48
#define IDS_SUCCESS
Definition: resource.h:6
#define OID_802_11_AUTHENTICATION_MODE
Definition: ntddndis.h:341
UCHAR Ssid[NDIS_802_11_LENGTH_SSID]
Definition: ntddndis.h:110
static BOOLEAN bSuccess
Definition: drive.cpp:419
WCHAR * sWepKey
Definition: wlanconf.c:28
#define OID_802_11_ADD_WEP
Definition: ntddndis.h:336
BOOL bAdhoc
Definition: wlanconf.c:29
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
struct _NDIS_802_11_SSID * PNDIS_802_11_SSID
struct _NDIS_802_11_WEP * PNDIS_802_11_WEP
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
static UCHAR CharToHex(WCHAR Char)
Definition: wlanconf.c:255
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned long DWORD
Definition: ntddk_ex.h:95
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
NDIS_OID Oid
Definition: nuiouser.h:44
UCHAR Data[sizeof(ULONG)]
Definition: nuiouser.h:45
#define IOCTL_NDISUIO_SET_OID_VALUE
Definition: nuiouser.h:31
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136
struct _NDIS_802_11_SSID NDIS_802_11_SSID
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
unsigned int * PULONG
Definition: retypes.h:1
WCHAR * sSsid
Definition: wlanconf.c:27
#define StdOut
Definition: stream.h:76
UCHAR NDIS_802_11_MAC_ADDRESS[6]
Definition: ntddndis.h:103
#define OID_802_11_SSID
Definition: ntddndis.h:320
#define OID_802_11_INFRASTRUCTURE_MODE
Definition: ntddndis.h:326
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
Definition: compat.h:402

Referenced by WlanConnect_test(), and wmain().

◆ WlanDisconnect()

BOOL WlanDisconnect ( HANDLE  hAdapter,
PIP_ADAPTER_INDEX_MAP  IpInfo 
)

Definition at line 227 of file wlanconf.c.

228 {
229  BOOL bSuccess;
230  DWORD dwBytesReturned;
231  NDISUIO_SET_OID SetOid;
232 
233  /* Release this IP address */
234  IpReleaseAddress(IpInfo);
235 
236  /* Disassociate from the AP */
237  SetOid.Oid = OID_802_11_DISASSOCIATE;
238  bSuccess = DeviceIoControl(hAdapter,
240  &SetOid,
242  NULL,
243  0,
244  &dwBytesReturned,
245  NULL);
246  if (!bSuccess)
247  return FALSE;
248 
250  return TRUE;
251 }
DWORD WINAPI IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo)
#define TRUE
Definition: types.h:120
#define IDS_SUCCESS
Definition: resource.h:6
static BOOLEAN bSuccess
Definition: drive.cpp:419
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
#define OID_802_11_DISASSOCIATE
Definition: ntddndis.h:338
unsigned long DWORD
Definition: ntddk_ex.h:95
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
NDIS_OID Oid
Definition: nuiouser.h:44
#define IOCTL_NDISUIO_SET_OID_VALUE
Definition: nuiouser.h:31
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
#define StdOut
Definition: stream.h:76

Referenced by WlanDisconnect_test(), and wmain().

◆ WlanPrintCurrentStatus()

BOOL WlanPrintCurrentStatus ( HANDLE  hAdapter)

Definition at line 270 of file wlanconf.c.

271 {
272  PNDISUIO_QUERY_OID QueryOid;
273  DWORD QueryOidSize;
274  BOOL bSuccess;
275  DWORD dwBytesReturned;
276  PNDIS_802_11_SSID SsidInfo;
277  CHAR SsidBuffer[NDIS_802_11_LENGTH_SSID + 1];
278  DWORD i;
279  WCHAR szMsgBuf[128];
280 
281  QueryOidSize = FIELD_OFFSET(NDISUIO_QUERY_OID, Data) + sizeof(NDIS_802_11_SSID);
282  QueryOid = HeapAlloc(GetProcessHeap(), 0, QueryOidSize);
283  if (!QueryOid)
284  return FALSE;
285 
286  QueryOid->Oid = OID_802_11_SSID;
287  SsidInfo = (PNDIS_802_11_SSID)QueryOid->Data;
288 
289  bSuccess = DeviceIoControl(hAdapter,
291  QueryOid,
292  QueryOidSize,
293  QueryOid,
294  QueryOidSize,
295  &dwBytesReturned,
296  NULL);
297  if (!bSuccess)
298  {
299  HeapFree(GetProcessHeap(), 0, QueryOid);
300  return FALSE;
301  }
302 
303  /* Copy the SSID to our internal buffer and terminate it */
304  RtlCopyMemory(SsidBuffer, SsidInfo->Ssid, SsidInfo->SsidLength);
305  SsidBuffer[SsidInfo->SsidLength] = 0;
306 
307  HeapFree(GetProcessHeap(), 0, QueryOid);
308  QueryOidSize = FIELD_OFFSET(NDISUIO_QUERY_OID, Data) + sizeof(NDIS_802_11_MAC_ADDRESS);
309  QueryOid = HeapAlloc(GetProcessHeap(), 0, QueryOidSize);
310  if (!QueryOid)
311  return FALSE;
312 
313  QueryOid->Oid = OID_802_11_BSSID;
314 
315  bSuccess = DeviceIoControl(hAdapter,
317  QueryOid,
318  QueryOidSize,
319  QueryOid,
320  QueryOidSize,
321  &dwBytesReturned,
322  NULL);
323  if (SsidInfo->SsidLength == 0 || !bSuccess)
324  {
326  HeapFree(GetProcessHeap(), 0, QueryOid);
327  return TRUE;
328  }
329  else
330  {
332  }
333 
334  printf("SSID: %s\n", SsidBuffer);
335 
336  printf("BSSID: ");
337  for (i = 0; i < sizeof(NDIS_802_11_MAC_ADDRESS); i++)
338  {
339  UINT BssidData = QueryOid->Data[i];
340 
341  printf("%.2x", BssidData);
342 
343  if (i != sizeof(NDIS_802_11_MAC_ADDRESS) - 1)
344  printf(":");
345  }
346  printf("\n");
347 
348  HeapFree(GetProcessHeap(), 0, QueryOid);
349  QueryOidSize = sizeof(NDISUIO_QUERY_OID);
350  QueryOid = HeapAlloc(GetProcessHeap(), 0, QueryOidSize);
351  if (!QueryOid)
352  return FALSE;
353 
355 
356  bSuccess = DeviceIoControl(hAdapter,
358  QueryOid,
359  QueryOidSize,
360  QueryOid,
361  QueryOidSize,
362  &dwBytesReturned,
363  NULL);
364  if (!bSuccess)
365  {
366  HeapFree(GetProcessHeap(), 0, QueryOid);
367  return FALSE;
368  }
369 
372  szMsgBuf,
373  ARRAYSIZE(szMsgBuf));
375 
376  QueryOid->Oid = OID_802_11_WEP_STATUS;
377 
378  bSuccess = DeviceIoControl(hAdapter,
380  QueryOid,
381  QueryOidSize,
382  QueryOid,
383  QueryOidSize,
384  &dwBytesReturned,
385  NULL);
386  if (!bSuccess)
387  {
388  HeapFree(GetProcessHeap(), 0, QueryOid);
389  return FALSE;
390  }
391 
393  *(PUINT)QueryOid->Data == Ndis802_11WEPEnabled ? IDS_YES : IDS_NO,
394  szMsgBuf,
395  ARRAYSIZE(szMsgBuf));
397 
398  printf("\n");
399  QueryOid->Oid = OID_802_11_RSSI;
400 
401  bSuccess = DeviceIoControl(hAdapter,
403  QueryOid,
404  QueryOidSize,
405  QueryOid,
406  QueryOidSize,
407  &dwBytesReturned,
408  NULL);
409  if (bSuccess)
410  {
411  /* This OID is optional */
412  printf("RSSI: %i dBm\n", *(PINT)QueryOid->Data);
413  }
414 
415  QueryOid->Oid = OID_802_11_TX_POWER_LEVEL;
416 
417  bSuccess = DeviceIoControl(hAdapter,
419  QueryOid,
420  QueryOidSize,
421  QueryOid,
422  QueryOidSize,
423  &dwBytesReturned,
424  NULL);
425  if (bSuccess)
426  {
427  /* This OID is optional */
429  }
430 
431  printf("\n");
432 
434 
435  bSuccess = DeviceIoControl(hAdapter,
437  QueryOid,
438  QueryOidSize,
439  QueryOid,
440  QueryOidSize,
441  &dwBytesReturned,
442  NULL);
443  if (bSuccess)
444  {
445  /* This OID is optional */
447  }
448 
450 
451  bSuccess = DeviceIoControl(hAdapter,
453  QueryOid,
454  QueryOidSize,
455  QueryOid,
456  QueryOidSize,
457  &dwBytesReturned,
458  NULL);
459  if (bSuccess)
460  {
461  UINT TransmitAntenna = *(PUINT)QueryOid->Data;
462 
463  if (TransmitAntenna != 0xFFFFFFFF)
464  ConResPrintf(StdOut, IDS_MSG_TRANSMIT_ANTENNA, TransmitAntenna);
465  else
467  }
468 
470 
471  bSuccess = DeviceIoControl(hAdapter,
473  QueryOid,
474  QueryOidSize,
475  QueryOid,
476  QueryOidSize,
477  &dwBytesReturned,
478  NULL);
479  if (bSuccess)
480  {
481  UINT ReceiveAntenna = *(PUINT)QueryOid->Data;
482 
483  if (ReceiveAntenna != 0xFFFFFFFF)
484  ConResPrintf(StdOut, IDS_MSG_RECEIVE_ANTENNA, ReceiveAntenna);
485  else
487  }
488 
489  printf("\n");
490 
492 
493  bSuccess = DeviceIoControl(hAdapter,
495  QueryOid,
496  QueryOidSize,
497  QueryOid,
498  QueryOidSize,
499  &dwBytesReturned,
500  NULL);
501  if (bSuccess)
502  {
503  /* This OID is optional */
505  }
506 
507  QueryOid->Oid = OID_802_11_RTS_THRESHOLD;
508 
509  bSuccess = DeviceIoControl(hAdapter,
511  QueryOid,
512  QueryOidSize,
513  QueryOid,
514  QueryOidSize,
515  &dwBytesReturned,
516  NULL);
517  if (bSuccess)
518  {
519  /* This OID is optional */
521  }
522 
523  HeapFree(GetProcessHeap(), 0, QueryOid);
524 
525  printf("\n");
526  return TRUE;
527 }
#define OID_802_11_WEP_STATUS
Definition: ntddndis.h:344
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define NDIS_802_11_LENGTH_SSID
Definition: ntddndis.h:100
#define IDS_MSG_NETWORK_MODE
Definition: resource.h:9
#define OID_802_11_NUMBER_OF_ANTENNAS
Definition: ntddndis.h:329
#define IOCTL_NDISUIO_QUERY_OID_VALUE
Definition: nuiouser.h:16
#define IDS_ADHOC
Definition: resource.h:25
#define OID_802_11_BSSID
Definition: ntddndis.h:319
char CHAR
Definition: xmlstorage.h:175
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define OID_802_11_TX_ANTENNA_SELECTED
Definition: ntddndis.h:331
INT WINAPI K32LoadStringW(IN HINSTANCE hInstance OPTIONAL, IN UINT uID, OUT LPWSTR lpBuffer, IN INT nBufferMax)
Definition: utils.c:173
UCHAR Ssid[NDIS_802_11_LENGTH_SSID]
Definition: ntddndis.h:110
static BOOLEAN bSuccess
Definition: drive.cpp:419
#define IDS_YES
Definition: resource.h:16
#define IDS_INFRASTRUCTURE
Definition: resource.h:26
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
struct _NDIS_802_11_SSID * PNDIS_802_11_SSID
unsigned int BOOL
Definition: ntddk_ex.h:94
#define IDS_MSG_ANTENNA_COUNT
Definition: resource.h:16
#define IDS_MSG_RECEIVE_ANTENNA
Definition: resource.h:19
smooth NULL
Definition: ftsmooth.c:416
#define IDS_NO
Definition: resource.h:17
#define OID_802_11_RTS_THRESHOLD
Definition: ntddndis.h:328
#define IDS_MSG_FRAGMENT_THRESHOLD
Definition: resource.h:21
INT __cdecl ConResPrintf(IN PCON_STREAM Stream, IN UINT uID,...)
Definition: outstream.c:781
#define IDS_MSG_TRANSMISSION_POWER
Definition: resource.h:15
int * PINT
Definition: windef.h:177
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define OID_802_11_RX_ANTENNA_SELECTED
Definition: ntddndis.h:330
#define IDS_MSG_TRANSMIT_ANTENNA_ANY
Definition: resource.h:18
if(!(yy_init))
Definition: macro.lex.yy.c:714
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define IDS_MSG_TRANSMIT_ANTENNA
Definition: resource.h:17
unsigned long DWORD
Definition: ntddk_ex.h:95
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
#define OID_802_11_FRAGMENTATION_THRESHOLD
Definition: ntddndis.h:327
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136
#define GetModuleHandle
Definition: winbase.h:3661
#define IDS_MSG_RTS_THRESHOLD
Definition: resource.h:22
struct _NDIS_802_11_SSID NDIS_802_11_SSID
#define IDS_MSG_CURRENT_WIRELESS
Definition: resource.h:10
#define IDS_WLAN_DISCONNECT
Definition: resource.h:7
#define OID_802_11_RSSI
Definition: ntddndis.h:324
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
unsigned int UINT
Definition: ndis.h:50
UCHAR Data[sizeof(ULONG)]
Definition: nuiouser.h:38
#define IDS_MSG_WEP_ENABLED
Definition: resource.h:8
#define StdOut
Definition: stream.h:76
UCHAR NDIS_802_11_MAC_ADDRESS[6]
Definition: ntddndis.h:103
#define OID_802_11_SSID
Definition: ntddndis.h:320
#define OID_802_11_INFRASTRUCTURE_MODE
Definition: ntddndis.h:326
#define OID_802_11_TX_POWER_LEVEL
Definition: ntddndis.h:323
#define HeapFree(x, y, z)
Definition: compat.h:402
NDIS_OID Oid
Definition: nuiouser.h:37
unsigned int * PUINT
Definition: ndis.h:50
#define IDS_MSG_RECEIVE_ANTENNA_ANY
Definition: resource.h:20
#define printf
Definition: config.h:203
struct _NDISUIO_QUERY_OID NDISUIO_QUERY_OID

Referenced by wmain().

◆ WlanScan()

BOOL WlanScan ( HANDLE  hAdapter)

Definition at line 700 of file wlanconf.c.

701 {
702  BOOL bSuccess;
703  DWORD dwBytesReturned;
704  NDISUIO_SET_OID SetOid;
705  PNDISUIO_QUERY_OID QueryOid;
706  DWORD QueryOidSize;
707  PNDIS_802_11_BSSID_LIST BssidList;
708  DWORD i, j;
709  DWORD dwNetworkCount;
710  WCHAR szMsgBuf[128];
711 
713 
714  /* Send the scan OID */
715  bSuccess = DeviceIoControl(hAdapter,
717  &SetOid,
719  NULL,
720  0,
721  &dwBytesReturned,
722  NULL);
723  if (!bSuccess)
724  return FALSE;
725 
726  /* Wait 2 seconds for the scan to return some results */
727  Sleep(2000);
728 
729  /* Allocate space for 10 networks to be returned initially */
730  QueryOid = NULL;
731  dwNetworkCount = 10;
732  for (;;)
733  {
734  if (QueryOid)
735  HeapFree(GetProcessHeap(), 0, QueryOid);
736 
737  QueryOidSize = sizeof(NDISUIO_QUERY_OID) + (sizeof(NDIS_WLAN_BSSID) * dwNetworkCount);
738  QueryOid = HeapAlloc(GetProcessHeap(), 0, QueryOidSize);
739  if (!QueryOid)
740  return FALSE;
741 
742  QueryOid->Oid = OID_802_11_BSSID_LIST;
743  BssidList = (PNDIS_802_11_BSSID_LIST)QueryOid->Data;
744 
745  bSuccess = DeviceIoControl(hAdapter,
747  QueryOid,
748  QueryOidSize,
749  QueryOid,
750  QueryOidSize,
751  &dwBytesReturned,
752  NULL);
754  {
755  /* Try allocating space for 10 more networks */
756  dwNetworkCount += 10;
757  }
758  else
759  {
760  break;
761  }
762  }
763 
764  if (!bSuccess)
765  {
766  HeapFree(GetProcessHeap(), 0, QueryOid);
767  return FALSE;
768  }
769 
770  if (BssidList->NumberOfItems == 0)
771  {
773  }
774  else
775  {
776  PNDIS_WLAN_BSSID BssidInfo = BssidList->Bssid;
777  for (i = 0; i < BssidList->NumberOfItems; i++)
778  {
779  PNDIS_802_11_SSID Ssid = &BssidInfo->Ssid;
780  NDIS_802_11_RSSI Rssi = BssidInfo->Rssi;
782  CHAR SsidBuffer[NDIS_802_11_LENGTH_SSID + 1];
783  UINT Rate;
784 
785  /* SSID member is a non-null terminated ASCII string */
786  RtlCopyMemory(SsidBuffer, Ssid->Ssid, Ssid->SsidLength);
787  SsidBuffer[Ssid->SsidLength] = 0;
788 
789  printf("\nSSID: %s\n", SsidBuffer);
790 
791  printf("BSSID: ");
792  for (j = 0; j < sizeof(NDIS_802_11_MAC_ADDRESS); j++)
793  {
794  UINT BssidData = BssidInfo->MacAddress[j];
795 
796  printf("%.2x", BssidData);
797 
798  if (j != sizeof(NDIS_802_11_MAC_ADDRESS) - 1)
799  printf(":");
800  }
801  printf("\n");
802 
804  BssidInfo->Privacy == 0 ? IDS_NO : IDS_YES,
805  szMsgBuf,
806  ARRAYSIZE(szMsgBuf));
810  szMsgBuf,
811  ARRAYSIZE(szMsgBuf));
813  ConResPrintf(StdOut, IDS_MSG_RSSI, (int)Rssi);
815 
816  for (j = 0; j < NDIS_802_11_LENGTH_RATES; j++)
817  {
818  Rate = BssidInfo->SupportedRates[j];
819  if (Rate != 0)
820  {
821  /* Bit 7 is the basic rates bit */
822  Rate = Rate & 0x7F;
823 
824  /* SupportedRates are in units of .5 */
825  if (Rate & 0x01)
826  {
827  /* Bit 0 is set so we need to add 0.5 */
828  printf("%u.5 ", (Rate >> 1));
829  }
830  else
831  {
832  /* Bit 0 is clear so just print the conversion */
833  printf("%u ", (Rate >> 1));
834  }
835  }
836  }
837  printf("\n");
838 
839  /* Move to the next entry */
840  BssidInfo = (PNDIS_WLAN_BSSID)((PUCHAR)BssidInfo + BssidInfo->Length);
841  }
842  }
843 
844  HeapFree(GetProcessHeap(), 0, QueryOid);
845 
846  return bSuccess;
847 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
NDIS_802_11_NETWORK_INFRASTRUCTURE InfrastructureMode
Definition: ntddndis.h:140
#define NDIS_802_11_LENGTH_SSID
Definition: ntddndis.h:100
NDIS_802_11_MAC_ADDRESS MacAddress
Definition: ntddndis.h:133
#define IOCTL_NDISUIO_QUERY_OID_VALUE
Definition: nuiouser.h:16
#define IDS_ADHOC
Definition: resource.h:25
#define IDS_MSG_SUPPORT_RATE
Definition: resource.h:14
unsigned char * PUCHAR
Definition: retypes.h:3
char CHAR
Definition: xmlstorage.h:175
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
INT WINAPI K32LoadStringW(IN HINSTANCE hInstance OPTIONAL, IN UINT uID, OUT LPWSTR lpBuffer, IN INT nBufferMax)
Definition: utils.c:173
#define IDS_MSG_RSSI
Definition: resource.h:13
UCHAR Ssid[NDIS_802_11_LENGTH_SSID]
Definition: ntddndis.h:110
NetworkType
Definition: tnetwork.h:8
#define IDS_MSG_ENCRYPTED
Definition: resource.h:11
static BOOLEAN bSuccess
Definition: drive.cpp:419
#define IDS_NO_NETWORK
Definition: resource.h:4
#define IDS_YES
Definition: resource.h:16
NDIS_802_11_RATES SupportedRates
Definition: ntddndis.h:141
LONG NDIS_802_11_RSSI
Definition: ntddndis.h:104
#define IDS_INFRASTRUCTURE
Definition: resource.h:26
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
NDIS_WLAN_BSSID Bssid[1]
Definition: ntddndis.h:147
#define IDS_NO
Definition: resource.h:17
NDIS_802_11_SSID Ssid
Definition: ntddndis.h:135
#define OID_802_11_BSSID_LIST
Definition: ntddndis.h:340
#define OID_802_11_BSSID_LIST_SCAN
Definition: ntddndis.h:343
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
INT __cdecl ConResPrintf(IN PCON_STREAM Stream, IN UINT uID,...)
Definition: outstream.c:781
#define NDIS_802_11_LENGTH_RATES
Definition: ntddndis.h:101
enum _NDIS_802_11_NETWORK_INFRASTRUCTURE NDIS_802_11_NETWORK_INFRASTRUCTURE
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
struct _NDIS_WLAN_BSSID * PNDIS_WLAN_BSSID
unsigned long DWORD
Definition: ntddk_ex.h:95
#define IDS_MSG_NETWORK_TYPE
Definition: resource.h:12
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
NDIS_OID Oid
Definition: nuiouser.h:44
#define IOCTL_NDISUIO_SET_OID_VALUE
Definition: nuiouser.h:31
struct _NDIS_802_11_BSSID_LIST * PNDIS_802_11_BSSID_LIST
BOOL WINAPI DeviceIoControl(IN HANDLE hDevice, IN DWORD dwIoControlCode, IN LPVOID lpInBuffer OPTIONAL, IN DWORD nInBufferSize OPTIONAL, OUT LPVOID lpOutBuffer OPTIONAL, IN DWORD nOutBufferSize OPTIONAL, OUT LPDWORD lpBytesReturned OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: deviceio.c:136
#define GetModuleHandle
Definition: winbase.h:3661
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
unsigned int UINT
Definition: ndis.h:50
UCHAR Data[sizeof(ULONG)]
Definition: nuiouser.h:38
NDIS_802_11_RSSI Rssi
Definition: ntddndis.h:137
#define StdOut
Definition: stream.h:76
UCHAR NDIS_802_11_MAC_ADDRESS[6]
Definition: ntddndis.h:103
#define HeapFree(x, y, z)
Definition: compat.h:402
NDIS_OID Oid
Definition: nuiouser.h:37
#define printf
Definition: config.h:203
struct _NDISUIO_QUERY_OID NDISUIO_QUERY_OID
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by WlanScan_test(), and wmain().

◆ wmain()

int wmain ( int  argc,
WCHAR argv[] 
)

Definition at line 901 of file wlanconf.c.

902 {
903  HANDLE hAdapter;
904  IP_ADAPTER_INDEX_MAP IpInfo;
905 
906  /* Initialize the Console Standard Streams */
908 
909  if (!ParseCmdline(argc, argv))
910  return -1;
911 
912  if (!OpenWlanAdapter(&hAdapter, &IpInfo))
913  {
915  return -1;
916  }
917 
918  if (bScan)
919  {
920  if (!WlanScan(hAdapter))
921  {
923  CloseHandle(hAdapter);
924  return -1;
925  }
926  }
927  else if (bDisconnect)
928  {
929  if (!WlanDisconnect(hAdapter, &IpInfo))
930  {
932  CloseHandle(hAdapter);
933  return -1;
934  }
935  }
936  else if (bConnect)
937  {
938  if (!WlanConnect(hAdapter))
939  {
941  CloseHandle(hAdapter);
942  return -1;
943  }
944  }
945  else
946  {
947  if (!WlanPrintCurrentStatus(hAdapter))
948  {
950  CloseHandle(hAdapter);
951  return -1;
952  }
953  }
954 
955  CloseHandle(hAdapter);
956  return 0;
957 }
static int argc
Definition: ServiceArgs.c:12
#define CloseHandle
Definition: compat.h:406
BOOL bDisconnect
Definition: wlanconf.c:31
BOOL WlanScan(HANDLE hAdapter)
Definition: wlanconf.c:700
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define IDS_NO_WLAN_ADAPTER
Definition: resource.h:5
#define argv
Definition: mplay32.c:18
VOID DoFormatMessage(DWORD ErrorCode)
Definition: wlanconf.c:33
#define ConInitStdStreams()
Definition: stream.h:122
BOOL WlanConnect(HANDLE hAdapter)
Definition: wlanconf.c:530
BOOL bScan
Definition: wlanconf.c:24
BOOL bConnect
Definition: wlanconf.c:26
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
BOOL WlanDisconnect(HANDLE hAdapter, PIP_ADAPTER_INDEX_MAP IpInfo)
Definition: wlanconf.c:227
BOOL OpenWlanAdapter(HANDLE *hAdapter, IP_ADAPTER_INDEX_MAP *IpInfo)
Definition: wlanconf.c:208
BOOL WlanPrintCurrentStatus(HANDLE hAdapter)
Definition: wlanconf.c:270
BOOL ParseCmdline(int argc, WCHAR *argv[])
Definition: wlanconf.c:849
#define StdOut
Definition: stream.h:76

Variable Documentation

◆ bAdhoc

BOOL bAdhoc = FALSE

Definition at line 29 of file wlanconf.c.

Referenced by ParseCmdline(), and WlanConnect().

◆ bConnect

BOOL bConnect = FALSE

Definition at line 26 of file wlanconf.c.

Referenced by ParseCmdline(), and wmain().

◆ bDisconnect

BOOL bDisconnect = FALSE

Definition at line 31 of file wlanconf.c.

Referenced by ParseCmdline(), and wmain().

◆ bScan

BOOL bScan = FALSE

Definition at line 24 of file wlanconf.c.

Referenced by keybd_event(), ParseCmdline(), and wmain().

◆ sSsid

WCHAR* sSsid = NULL

Definition at line 27 of file wlanconf.c.

Referenced by ParseCmdline(), and WlanConnect().

◆ sWepKey

WCHAR* sWepKey = NULL

Definition at line 28 of file wlanconf.c.

Referenced by ParseCmdline(), and WlanConnect().