ReactOS  0.4.15-dev-5488-ge316d61
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 259 of file wlanconf.c.

260 {
261  if ((Char >= L'0') && (Char <= L'9'))
262  return Char - L'0';
263 
264  if ((Char >= L'a') && (Char <= L'f'))
265  return Char - L'a' + 10;
266 
267  if ((Char >= L'A') && (Char <= L'F'))
268  return Char - L'A' + 10;
269 
270  return 0;
271 }
#define L(x)
Definition: ntvdm.h:50

Referenced by WlanConnect().

◆ DoFormatMessage()

VOID DoFormatMessage ( DWORD  ErrorCode)

Definition at line 32 of file wlanconf.c.

33 {
34  if (ErrorCode == ERROR_SUCCESS)
35  return;
36 
39 }
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define ERROR_SUCCESS
Definition: deptool.c:10
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:423
INT ConMsgPuts(IN PCON_STREAM Stream, IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId)
Definition: outstream.c:837
#define NULL
Definition: types.h:112
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50
#define StdErr
Definition: fc.c:15

Referenced by wmain().

◆ IsWlanAdapter()

BOOL IsWlanAdapter ( HANDLE  hAdapter)

Definition at line 78 of file wlanconf.c.

79 {
80  BOOL bSuccess;
81  DWORD dwBytesReturned;
82  NDISUIO_QUERY_OID QueryOid;
83 
84  /* WLAN drivers must support this OID */
85  QueryOid.Oid = OID_GEN_PHYSICAL_MEDIUM;
86 
87  bSuccess = DeviceIoControl(hAdapter,
89  &QueryOid,
90  sizeof(QueryOid),
91  &QueryOid,
92  sizeof(QueryOid),
93  &dwBytesReturned,
94  NULL);
95  if (!bSuccess || *(PULONG)QueryOid.Data != NdisPhysicalMediumWirelessLan)
96  return FALSE;
97 
98  return TRUE;
99 }
#define OID_GEN_PHYSICAL_MEDIUM
Definition: ntddndis.h:264
#define IOCTL_NDISUIO_QUERY_OID_VALUE
Definition: nuiouser.h:16
#define TRUE
Definition: types.h:120
static BOOLEAN bSuccess
Definition: drive.cpp:433
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
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
#define NULL
Definition: types.h:112
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 102 of file wlanconf.c.

103 {
104  HANDLE hDriver;
105  BOOL bSuccess;
106  DWORD dwBytesReturned;
107  DWORD QueryBindingSize = sizeof(NDISUIO_QUERY_BINDING) + (1024 * sizeof(WCHAR));
110  LONG i;
111  PIP_INTERFACE_INFO InterfaceInfo = NULL;
112 
113  /* Open the driver handle */
116  return FALSE;
117 
118  /* Allocate the binding struct */
119  QueryBinding = HeapAlloc(GetProcessHeap(), 0, QueryBindingSize);
120  if (!QueryBinding)
121  {
123  return FALSE;
124  }
125 
126  /* Query the adapter binding information */
127  QueryBinding->BindingIndex = Index;
130  QueryBinding,
131  QueryBindingSize,
132  QueryBinding,
133  QueryBindingSize,
134  &dwBytesReturned,
135  NULL);
136 
137  if (!bSuccess)
138  {
141  return FALSE;
142  }
143 
144  /* Bind to the adapter */
147  (PUCHAR)QueryBinding + QueryBinding->DeviceNameOffset,
148  QueryBinding->DeviceNameLength,
149  NULL,
150  0,
151  &dwBytesReturned,
152  NULL);
153 
154  if (!bSuccess)
155  {
158  return FALSE;
159  }
160 
161  /* Get interface info from the IP helper */
162  dwSize = sizeof(IP_INTERFACE_INFO);
163  do {
164  if (InterfaceInfo) HeapFree(GetProcessHeap(), 0, InterfaceInfo);
165  InterfaceInfo = HeapAlloc(GetProcessHeap(), 0, dwSize);
166  if (!InterfaceInfo)
167  {
170  return FALSE;
171  }
172  dwStatus = GetInterfaceInfo(InterfaceInfo, &dwSize);
173  } while (dwStatus == ERROR_INSUFFICIENT_BUFFER);
174 
175  if (dwStatus != NO_ERROR)
176  {
178  HeapFree(GetProcessHeap(), 0, InterfaceInfo);
180  return FALSE;
181  }
182 
183  for (i = 0; i < InterfaceInfo->NumAdapters; i++)
184  {
185  PWCHAR InterfaceGuid = wcschr(InterfaceInfo->Adapter[i].Name, L'{');
186 
187  if (InterfaceGuid == NULL)
188  continue;
189 
190  if (wcsstr((PWCHAR)((PUCHAR)QueryBinding + QueryBinding->DeviceNameOffset),
191  InterfaceGuid))
192  {
193  *IpInfo = InterfaceInfo->Adapter[i];
194  *hAdapter = hDriver;
195 
197  HeapFree(GetProcessHeap(), 0, InterfaceInfo);
198 
199  return TRUE;
200  }
201  }
202 
204  HeapFree(GetProcessHeap(), 0, InterfaceInfo);
206 
207  return FALSE;
208 }
static NTSTATUS QueryBinding(PIRP Irp, PIO_STACK_LOCATION IrpSp)
Definition: ioctl.c:34
IP_ADAPTER_INDEX_MAP Adapter[1]
Definition: ipexport.h:152
#define CloseHandle
Definition: compat.h:739
#define TRUE
Definition: types.h:120
_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:731
HANDLE OpenDriverHandle(VOID)
Definition: wlanconf.c:42
uint16_t * PWCHAR
Definition: typedefs.h:56
#define NO_ERROR
Definition: dderror.h:5
static BOOLEAN bSuccess
Definition: drive.cpp:433
struct _NDISUIO_QUERY_BINDING NDISUIO_QUERY_BINDING
#define L(x)
Definition: ntvdm.h:50
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define IOCTL_NDISUIO_QUERY_BINDING
Definition: nuiouser.h:23
long LONG
Definition: pedump.c:60
WCHAR Name[MAX_ADAPTER_NAME]
Definition: ipexport.h:147
#define GetProcessHeap()
Definition: compat.h:736
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_ WDFCOLLECTION _In_ ULONG Index
unsigned long DWORD
Definition: ntddk_ex.h:95
static const GUID InterfaceGuid
Definition: wlanapi.c:25
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
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
#define NULL
Definition: types.h:112
#define IOCTL_NDISUIO_OPEN_DEVICE
Definition: nuiouser.h:12
#define HeapFree(x, y, z)
Definition: compat.h:735
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
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 42 of file wlanconf.c.

43 {
45  DWORD dwBytesReturned;
46  BOOL bSuccess;
47 
48  /* Open a handle to the NDISUIO driver */
51  0,
52  NULL,
55  NULL);
57  return INVALID_HANDLE_VALUE;
58 
59  /* Wait for binds */
62  NULL,
63  0,
64  NULL,
65  0,
66  &dwBytesReturned,
67  NULL);
68  if (!bSuccess)
69  {
71  return INVALID_HANDLE_VALUE;
72  }
73 
74  return hDriver;
75 }
#define CloseHandle
Definition: compat.h:739
#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:731
static BOOLEAN bSuccess
Definition: drive.cpp:433
#define NDISUIO_DEVICE_NAME
Definition: nuiouser.h:9
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
#define OPEN_EXISTING
Definition: compat.h:775
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define GENERIC_READ
Definition: compat.h:135
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 NULL
Definition: types.h:112
#define CreateFileW
Definition: compat.h:741

Referenced by OpenAdapterHandle().

◆ OpenWlanAdapter()

BOOL OpenWlanAdapter ( HANDLE hAdapter,
IP_ADAPTER_INDEX_MAP IpInfo 
)

Definition at line 212 of file wlanconf.c.

213 {
214  DWORD dwCurrentIndex;
215 
216  for (dwCurrentIndex = 0; ; dwCurrentIndex++)
217  {
218  if (!OpenAdapterHandle(dwCurrentIndex, hAdapter, IpInfo))
219  break;
220 
221  if (IsWlanAdapter(*hAdapter))
222  return TRUE;
223  else
224  CloseHandle(*hAdapter);
225  }
226 
227  return FALSE;
228 }
BOOL OpenAdapterHandle(DWORD Index, HANDLE *hAdapter, IP_ADAPTER_INDEX_MAP *IpInfo)
Definition: wlanconf.c:102
#define CloseHandle
Definition: compat.h:739
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL IsWlanAdapter(HANDLE hAdapter)
Definition: wlanconf.c:78

Referenced by wmain().

◆ ParseCmdline()

BOOL ParseCmdline ( int  argc,
WCHAR argv[] 
)

Definition at line 853 of file wlanconf.c.

854 {
855  INT i;
856 
857  for (i = 1; i < argc; i++)
858  {
859  if (argv[i][0] == L'-')
860  {
861  switch (argv[i][1])
862  {
863  case L's':
864  bScan = TRUE;
865  break;
866  case L'd':
867  bDisconnect = TRUE;
868  break;
869  case L'c':
870  if (i == argc - 1)
871  {
873  return FALSE;
874  }
875  bConnect = TRUE;
876  sSsid = argv[++i];
877  break;
878  case L'w':
879  if (i == argc - 1)
880  {
882  return FALSE;
883  }
884  sWepKey = argv[++i];
885  break;
886  case L'a':
887  bAdhoc = TRUE;
888  break;
889  default :
891  return FALSE;
892  }
893 
894  }
895  else
896  {
898  return FALSE;
899  }
900  }
901 
902  return TRUE;
903 }
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
BOOL bDisconnect
Definition: wlanconf.c:30
#define IDS_USAGE
Definition: resource.h:3
#define argv
Definition: mplay32.c:18
int32_t INT
Definition: typedefs.h:58
WCHAR * sWepKey
Definition: wlanconf.c:27
BOOL bAdhoc
Definition: wlanconf.c:28
#define L(x)
Definition: ntvdm.h:50
#define FALSE
Definition: types.h:117
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
BOOL bScan
Definition: wlanconf.c:23
BOOL bConnect
Definition: wlanconf.c:25
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
WCHAR * sSsid
Definition: wlanconf.c:26
#define StdOut
Definition: fc.c:14

Referenced by wmain().

◆ WlanConnect()

BOOL WlanConnect ( HANDLE  hAdapter)

Definition at line 534 of file wlanconf.c.

535 {
536  CHAR SsidBuffer[NDIS_802_11_LENGTH_SSID + 1];
537  BOOL bSuccess;
538  DWORD dwBytesReturned, SetOidSize;
539  PNDISUIO_SET_OID SetOid;
540  PNDIS_802_11_SSID Ssid;
541  DWORD i;
542 
543  SetOidSize = sizeof(NDISUIO_SET_OID);
544  SetOid = HeapAlloc(GetProcessHeap(), 0, SetOidSize);
545  if (!SetOid)
546  return FALSE;
547 
548  /* Set the network mode */
551 
552  bSuccess = DeviceIoControl(hAdapter,
554  SetOid,
555  SetOidSize,
556  NULL,
557  0,
558  &dwBytesReturned,
559  NULL);
560  if (!bSuccess)
561  {
562  HeapFree(GetProcessHeap(), 0, SetOid);
563  return FALSE;
564  }
565 
566  /* Set the authentication mode */
569 
570  bSuccess = DeviceIoControl(hAdapter,
572  SetOid,
573  SetOidSize,
574  NULL,
575  0,
576  &dwBytesReturned,
577  NULL);
578  if (!bSuccess)
579  {
580  HeapFree(GetProcessHeap(), 0, SetOid);
581  return FALSE;
582  }
583 
584  if (sWepKey)
585  {
586  PNDIS_802_11_WEP WepData;
587 
588  HeapFree(GetProcessHeap(), 0, SetOid);
589 
590  SetOidSize = FIELD_OFFSET(NDISUIO_SET_OID, Data) +
591  FIELD_OFFSET(NDIS_802_11_WEP, KeyMaterial) +
592  (wcslen(sWepKey) >> 1);
593  SetOid = HeapAlloc(GetProcessHeap(), 0, SetOidSize);
594  if (!SetOid)
595  return FALSE;
596 
597  /* Add the WEP key */
598  SetOid->Oid = OID_802_11_ADD_WEP;
599  WepData = (PNDIS_802_11_WEP)SetOid->Data;
600 
601  WepData->KeyIndex = 0x80000000;
602  WepData->KeyLength = wcslen(sWepKey) >> 1;
603  WepData->Length = FIELD_OFFSET(NDIS_802_11_WEP, KeyMaterial) + WepData->KeyLength;
604 
605  /* Assemble the hex key */
606  i = 0;
607  while (sWepKey[i << 1] != '\0')
608  {
609  WepData->KeyMaterial[i] = CharToHex(sWepKey[i << 1]) << 4;
610  WepData->KeyMaterial[i] |= CharToHex(sWepKey[(i << 1) + 1]);
611  i++;
612  }
613 
614  bSuccess = DeviceIoControl(hAdapter,
616  SetOid,
617  SetOidSize,
618  NULL,
619  0,
620  &dwBytesReturned,
621  NULL);
622  if (!bSuccess)
623  {
624  HeapFree(GetProcessHeap(), 0, SetOid);
625  return FALSE;
626  }
627  }
628 
629  /* Set the encryption status */
630  SetOid->Oid = OID_802_11_WEP_STATUS;
632 
633  bSuccess = DeviceIoControl(hAdapter,
635  SetOid,
636  SetOidSize,
637  NULL,
638  0,
639  &dwBytesReturned,
640  NULL);
641  if (!bSuccess)
642  {
643  HeapFree(GetProcessHeap(), 0, SetOid);
644  return FALSE;
645  }
646 
647  HeapFree(GetProcessHeap(), 0, SetOid);
648  SetOidSize = FIELD_OFFSET(NDISUIO_SET_OID, Data) + sizeof(NDIS_802_11_MAC_ADDRESS);
649  SetOid = HeapAlloc(GetProcessHeap(), 0, SetOidSize);
650  if (!SetOid)
651  return FALSE;
652 
653  /* Set the BSSID */
654  SetOid->Oid = OID_802_11_BSSID;
655  RtlFillMemory(SetOid->Data, sizeof(NDIS_802_11_MAC_ADDRESS), 0xFF);
656 
657  bSuccess = DeviceIoControl(hAdapter,
659  SetOid,
660  SetOidSize,
661  NULL,
662  0,
663  &dwBytesReturned,
664  NULL);
665  if (!bSuccess)
666  {
667  HeapFree(GetProcessHeap(), 0, SetOid);
668  return FALSE;
669  }
670 
671  HeapFree(GetProcessHeap(), 0, SetOid);
672  SetOidSize = FIELD_OFFSET(NDISUIO_SET_OID, Data) + sizeof(NDIS_802_11_SSID);
673  SetOid = HeapAlloc(GetProcessHeap(), 0, SetOidSize);
674  if (!SetOid)
675  return FALSE;
676 
677  /* Finally, set the SSID */
678  SetOid->Oid = OID_802_11_SSID;
679  Ssid = (PNDIS_802_11_SSID)SetOid->Data;
680 
681  snprintf(SsidBuffer, sizeof(SsidBuffer), "%S", sSsid);
682  RtlCopyMemory(Ssid->Ssid, SsidBuffer, strlen(SsidBuffer));
683  Ssid->SsidLength = strlen(SsidBuffer);
684 
685  bSuccess = DeviceIoControl(hAdapter,
687  SetOid,
688  SetOidSize,
689  NULL,
690  0,
691  &dwBytesReturned,
692  NULL);
693 
694  HeapFree(GetProcessHeap(), 0, SetOid);
695 
696  if (!bSuccess)
697  return FALSE;
698 
700  return TRUE;
701 }
#define OID_802_11_WEP_STATUS
Definition: ntddndis.h:344
UCHAR KeyMaterial[1]
Definition: ntddndis.h:155
#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 TRUE
Definition: types.h:120
#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:433
WCHAR * sWepKey
Definition: wlanconf.c:27
#define OID_802_11_ADD_WEP
Definition: ntddndis.h:336
BOOL bAdhoc
Definition: wlanconf.c:28
struct _NDIS_802_11_SSID * PNDIS_802_11_SSID
struct _NDIS_802_11_WEP * PNDIS_802_11_WEP
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
static UCHAR CharToHex(WCHAR Char)
Definition: wlanconf.c:259
#define GetProcessHeap()
Definition: compat.h:736
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
unsigned long DWORD
Definition: ntddk_ex.h:95
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
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 NDIS_802_11_SSID
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
unsigned int * PULONG
Definition: retypes.h:1
#define NULL
Definition: types.h:112
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
WCHAR * sSsid
Definition: wlanconf.c:26
#define StdOut
Definition: fc.c:14
UCHAR NDIS_802_11_MAC_ADDRESS[6]
Definition: ntddndis.h:103
#define OID_802_11_SSID
Definition: ntddndis.h:320
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define OID_802_11_INFRASTRUCTURE_MODE
Definition: ntddndis.h:326
#define HeapFree(x, y, z)
Definition: compat.h:735

Referenced by WlanConnect_test(), and wmain().

◆ WlanDisconnect()

BOOL WlanDisconnect ( HANDLE  hAdapter,
PIP_ADAPTER_INDEX_MAP  IpInfo 
)

Definition at line 231 of file wlanconf.c.

232 {
233  BOOL bSuccess;
234  DWORD dwBytesReturned;
235  NDISUIO_SET_OID SetOid;
236 
237  /* Release this IP address */
238  IpReleaseAddress(IpInfo);
239 
240  /* Disassociate from the AP */
241  SetOid.Oid = OID_802_11_DISASSOCIATE;
242  bSuccess = DeviceIoControl(hAdapter,
244  &SetOid,
246  NULL,
247  0,
248  &dwBytesReturned,
249  NULL);
250  if (!bSuccess)
251  return FALSE;
252 
254  return TRUE;
255 }
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:433
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
#define OID_802_11_DISASSOCIATE
Definition: ntddndis.h:338
unsigned long DWORD
Definition: ntddk_ex.h:95
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:255
#define NULL
Definition: types.h:112
#define StdOut
Definition: fc.c:14

Referenced by WlanDisconnect_test(), and wmain().

◆ WlanPrintCurrentStatus()

BOOL WlanPrintCurrentStatus ( HANDLE  hAdapter)

Definition at line 274 of file wlanconf.c.

275 {
276  PNDISUIO_QUERY_OID QueryOid;
277  DWORD QueryOidSize;
278  BOOL bSuccess;
279  DWORD dwBytesReturned;
280  PNDIS_802_11_SSID SsidInfo;
281  CHAR SsidBuffer[NDIS_802_11_LENGTH_SSID + 1];
282  DWORD i;
283  WCHAR szMsgBuf[128];
284 
285  QueryOidSize = FIELD_OFFSET(NDISUIO_QUERY_OID, Data) + sizeof(NDIS_802_11_SSID);
286  QueryOid = HeapAlloc(GetProcessHeap(), 0, QueryOidSize);
287  if (!QueryOid)
288  return FALSE;
289 
290  QueryOid->Oid = OID_802_11_SSID;
291  SsidInfo = (PNDIS_802_11_SSID)QueryOid->Data;
292 
293  bSuccess = DeviceIoControl(hAdapter,
295  QueryOid,
296  QueryOidSize,
297  QueryOid,
298  QueryOidSize,
299  &dwBytesReturned,
300  NULL);
301  if (!bSuccess)
302  {
303  HeapFree(GetProcessHeap(), 0, QueryOid);
304  return FALSE;
305  }
306 
307  /* Copy the SSID to our internal buffer and terminate it */
308  RtlCopyMemory(SsidBuffer, SsidInfo->Ssid, SsidInfo->SsidLength);
309  SsidBuffer[SsidInfo->SsidLength] = 0;
310 
311  HeapFree(GetProcessHeap(), 0, QueryOid);
312  QueryOidSize = FIELD_OFFSET(NDISUIO_QUERY_OID, Data) + sizeof(NDIS_802_11_MAC_ADDRESS);
313  QueryOid = HeapAlloc(GetProcessHeap(), 0, QueryOidSize);
314  if (!QueryOid)
315  return FALSE;
316 
317  QueryOid->Oid = OID_802_11_BSSID;
318 
319  bSuccess = DeviceIoControl(hAdapter,
321  QueryOid,
322  QueryOidSize,
323  QueryOid,
324  QueryOidSize,
325  &dwBytesReturned,
326  NULL);
327  if (SsidInfo->SsidLength == 0 || !bSuccess)
328  {
330  HeapFree(GetProcessHeap(), 0, QueryOid);
331  return TRUE;
332  }
333  else
334  {
336  }
337 
338  printf("SSID: %s\n", SsidBuffer);
339 
340  printf("BSSID: ");
341  for (i = 0; i < sizeof(NDIS_802_11_MAC_ADDRESS); i++)
342  {
343  UINT BssidData = QueryOid->Data[i];
344 
345  printf("%.2x", BssidData);
346 
347  if (i != sizeof(NDIS_802_11_MAC_ADDRESS) - 1)
348  printf(":");
349  }
350  printf("\n");
351 
352  HeapFree(GetProcessHeap(), 0, QueryOid);
353  QueryOidSize = sizeof(NDISUIO_QUERY_OID);
354  QueryOid = HeapAlloc(GetProcessHeap(), 0, QueryOidSize);
355  if (!QueryOid)
356  return FALSE;
357 
359 
360  bSuccess = DeviceIoControl(hAdapter,
362  QueryOid,
363  QueryOidSize,
364  QueryOid,
365  QueryOidSize,
366  &dwBytesReturned,
367  NULL);
368  if (!bSuccess)
369  {
370  HeapFree(GetProcessHeap(), 0, QueryOid);
371  return FALSE;
372  }
373 
376  szMsgBuf,
377  ARRAYSIZE(szMsgBuf));
379 
380  QueryOid->Oid = OID_802_11_WEP_STATUS;
381 
382  bSuccess = DeviceIoControl(hAdapter,
384  QueryOid,
385  QueryOidSize,
386  QueryOid,
387  QueryOidSize,
388  &dwBytesReturned,
389  NULL);
390  if (!bSuccess)
391  {
392  HeapFree(GetProcessHeap(), 0, QueryOid);
393  return FALSE;
394  }
395 
397  *(PUINT)QueryOid->Data == Ndis802_11WEPEnabled ? IDS_YES : IDS_NO,
398  szMsgBuf,
399  ARRAYSIZE(szMsgBuf));
401 
402  printf("\n");
403  QueryOid->Oid = OID_802_11_RSSI;
404 
405  bSuccess = DeviceIoControl(hAdapter,
407  QueryOid,
408  QueryOidSize,
409  QueryOid,
410  QueryOidSize,
411  &dwBytesReturned,
412  NULL);
413  if (bSuccess)
414  {
415  /* This OID is optional */
416  printf("RSSI: %i dBm\n", *(PINT)QueryOid->Data);
417  }
418 
419  QueryOid->Oid = OID_802_11_TX_POWER_LEVEL;
420 
421  bSuccess = DeviceIoControl(hAdapter,
423  QueryOid,
424  QueryOidSize,
425  QueryOid,
426  QueryOidSize,
427  &dwBytesReturned,
428  NULL);
429  if (bSuccess)
430  {
431  /* This OID is optional */
433  }
434 
435  printf("\n");
436 
438 
439  bSuccess = DeviceIoControl(hAdapter,
441  QueryOid,
442  QueryOidSize,
443  QueryOid,
444  QueryOidSize,
445  &dwBytesReturned,
446  NULL);
447  if (bSuccess)
448  {
449  /* This OID is optional */
451  }
452 
454 
455  bSuccess = DeviceIoControl(hAdapter,
457  QueryOid,
458  QueryOidSize,
459  QueryOid,
460  QueryOidSize,
461  &dwBytesReturned,
462  NULL);
463  if (bSuccess)
464  {
465  UINT TransmitAntenna = *(PUINT)QueryOid->Data;
466 
467  if (TransmitAntenna != 0xFFFFFFFF)
468  ConResPrintf(StdOut, IDS_MSG_TRANSMIT_ANTENNA, TransmitAntenna);
469  else
471  }
472 
474 
475  bSuccess = DeviceIoControl(hAdapter,
477  QueryOid,
478  QueryOidSize,
479  QueryOid,
480  QueryOidSize,
481  &dwBytesReturned,
482  NULL);
483  if (bSuccess)
484  {
485  UINT ReceiveAntenna = *(PUINT)QueryOid->Data;
486 
487  if (ReceiveAntenna != 0xFFFFFFFF)
488  ConResPrintf(StdOut, IDS_MSG_RECEIVE_ANTENNA, ReceiveAntenna);
489  else
491  }
492 
493  printf("\n");
494 
496 
497  bSuccess = DeviceIoControl(hAdapter,
499  QueryOid,
500  QueryOidSize,
501  QueryOid,
502  QueryOidSize,
503  &dwBytesReturned,
504  NULL);
505  if (bSuccess)
506  {
507  /* This OID is optional */
509  }
510 
511  QueryOid->Oid = OID_802_11_RTS_THRESHOLD;
512 
513  bSuccess = DeviceIoControl(hAdapter,
515  QueryOid,
516  QueryOidSize,
517  QueryOid,
518  QueryOidSize,
519  &dwBytesReturned,
520  NULL);
521  if (bSuccess)
522  {
523  /* This OID is optional */
525  }
526 
527  HeapFree(GetProcessHeap(), 0, QueryOid);
528 
529  printf("\n");
530  return TRUE;
531 }
#define OID_802_11_WEP_STATUS
Definition: ntddndis.h:344
#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 TRUE
Definition: types.h:120
#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
if(dx==0 &&dy==0)
Definition: linetemp.h:174
UCHAR Ssid[NDIS_802_11_LENGTH_SSID]
Definition: ntddndis.h:110
static BOOLEAN bSuccess
Definition: drive.cpp:433
#define IDS_YES
Definition: resource.h:16
#define IDS_INFRASTRUCTURE
Definition: resource.h:26
struct _NDIS_802_11_SSID * PNDIS_802_11_SSID
#define FALSE
Definition: types.h:117
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
#define IDS_NO
Definition: resource.h:17
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
#define OID_802_11_RTS_THRESHOLD
Definition: ntddndis.h:328
#define IDS_MSG_FRAGMENT_THRESHOLD
Definition: resource.h:21
#define IDS_MSG_TRANSMISSION_POWER
Definition: resource.h:15
int * PINT
Definition: windef.h:177
void ConResPrintf(FILE *fp, UINT nID,...)
Definition: fc.c:33
#define printf
Definition: freeldr.h:94
#define GetProcessHeap()
Definition: compat.h:736
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
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define IDS_MSG_TRANSMIT_ANTENNA
Definition: resource.h:17
unsigned long DWORD
Definition: ntddk_ex.h:95
#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:3698
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
#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:255
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
UCHAR Data[sizeof(ULONG)]
Definition: nuiouser.h:38
#define IDS_MSG_WEP_ENABLED
Definition: resource.h:8
#define StdOut
Definition: fc.c:14
UCHAR NDIS_802_11_MAC_ADDRESS[6]
Definition: ntddndis.h:103
#define OID_802_11_SSID
Definition: ntddndis.h:320
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#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:735
NDIS_OID Oid
Definition: nuiouser.h:37
unsigned int * PUINT
Definition: ndis.h:50
#define IDS_MSG_RECEIVE_ANTENNA_ANY
Definition: resource.h:20
struct _NDISUIO_QUERY_OID NDISUIO_QUERY_OID

Referenced by wmain().

◆ WlanScan()

BOOL WlanScan ( HANDLE  hAdapter)

Definition at line 704 of file wlanconf.c.

705 {
706  BOOL bSuccess;
707  DWORD dwBytesReturned;
708  NDISUIO_SET_OID SetOid;
709  PNDISUIO_QUERY_OID QueryOid;
710  DWORD QueryOidSize;
711  PNDIS_802_11_BSSID_LIST BssidList;
712  DWORD i, j;
713  DWORD dwNetworkCount;
714  WCHAR szMsgBuf[128];
715 
717 
718  /* Send the scan OID */
719  bSuccess = DeviceIoControl(hAdapter,
721  &SetOid,
723  NULL,
724  0,
725  &dwBytesReturned,
726  NULL);
727  if (!bSuccess)
728  return FALSE;
729 
730  /* Wait 2 seconds for the scan to return some results */
731  Sleep(2000);
732 
733  /* Allocate space for 10 networks to be returned initially */
734  QueryOid = NULL;
735  dwNetworkCount = 10;
736  for (;;)
737  {
738  if (QueryOid)
739  HeapFree(GetProcessHeap(), 0, QueryOid);
740 
741  QueryOidSize = sizeof(NDISUIO_QUERY_OID) + (sizeof(NDIS_WLAN_BSSID) * dwNetworkCount);
742  QueryOid = HeapAlloc(GetProcessHeap(), 0, QueryOidSize);
743  if (!QueryOid)
744  return FALSE;
745 
746  QueryOid->Oid = OID_802_11_BSSID_LIST;
747  BssidList = (PNDIS_802_11_BSSID_LIST)QueryOid->Data;
748 
749  bSuccess = DeviceIoControl(hAdapter,
751  QueryOid,
752  QueryOidSize,
753  QueryOid,
754  QueryOidSize,
755  &dwBytesReturned,
756  NULL);
758  {
759  /* Try allocating space for 10 more networks */
760  dwNetworkCount += 10;
761  }
762  else
763  {
764  break;
765  }
766  }
767 
768  if (!bSuccess)
769  {
770  HeapFree(GetProcessHeap(), 0, QueryOid);
771  return FALSE;
772  }
773 
774  if (BssidList->NumberOfItems == 0)
775  {
777  }
778  else
779  {
780  PNDIS_WLAN_BSSID BssidInfo = BssidList->Bssid;
781  for (i = 0; i < BssidList->NumberOfItems; i++)
782  {
783  PNDIS_802_11_SSID Ssid = &BssidInfo->Ssid;
784  NDIS_802_11_RSSI Rssi = BssidInfo->Rssi;
786  CHAR SsidBuffer[NDIS_802_11_LENGTH_SSID + 1];
787  UINT Rate;
788 
789  /* SSID member is a non-null terminated ASCII string */
790  RtlCopyMemory(SsidBuffer, Ssid->Ssid, Ssid->SsidLength);
791  SsidBuffer[Ssid->SsidLength] = 0;
792 
793  printf("\nSSID: %s\n", SsidBuffer);
794 
795  printf("BSSID: ");
796  for (j = 0; j < sizeof(NDIS_802_11_MAC_ADDRESS); j++)
797  {
798  UINT BssidData = BssidInfo->MacAddress[j];
799 
800  printf("%.2x", BssidData);
801 
802  if (j != sizeof(NDIS_802_11_MAC_ADDRESS) - 1)
803  printf(":");
804  }
805  printf("\n");
806 
808  BssidInfo->Privacy == 0 ? IDS_NO : IDS_YES,
809  szMsgBuf,
810  ARRAYSIZE(szMsgBuf));
814  szMsgBuf,
815  ARRAYSIZE(szMsgBuf));
817  ConResPrintf(StdOut, IDS_MSG_RSSI, (int)Rssi);
819 
820  for (j = 0; j < NDIS_802_11_LENGTH_RATES; j++)
821  {
822  Rate = BssidInfo->SupportedRates[j];
823  if (Rate != 0)
824  {
825  /* Bit 7 is the basic rates bit */
826  Rate = Rate & 0x7F;
827 
828  /* SupportedRates are in units of .5 */
829  if (Rate & 0x01)
830  {
831  /* Bit 0 is set so we need to add 0.5 */
832  printf("%u.5 ", (Rate >> 1));
833  }
834  else
835  {
836  /* Bit 0 is clear so just print the conversion */
837  printf("%u ", (Rate >> 1));
838  }
839  }
840  }
841  printf("\n");
842 
843  /* Move to the next entry */
844  BssidInfo = (PNDIS_WLAN_BSSID)((PUCHAR)BssidInfo + BssidInfo->Length);
845  }
846  }
847 
848  HeapFree(GetProcessHeap(), 0, QueryOid);
849 
850  return bSuccess;
851 }
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:1040
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:433
#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
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
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
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
#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
#define NDIS_802_11_LENGTH_RATES
Definition: ntddndis.h:101
void ConResPrintf(FILE *fp, UINT nID,...)
Definition: fc.c:33
enum _NDIS_802_11_NETWORK_INFRASTRUCTURE NDIS_802_11_NETWORK_INFRASTRUCTURE
#define printf
Definition: freeldr.h:94
#define GetProcessHeap()
Definition: compat.h:736
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
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:3698
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
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
UCHAR Data[sizeof(ULONG)]
Definition: nuiouser.h:38
#define StdOut
Definition: fc.c:14
NDIS_802_11_RSSI Rssi
Definition: ntddndis.h:137
UCHAR NDIS_802_11_MAC_ADDRESS[6]
Definition: ntddndis.h:103
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define HeapFree(x, y, z)
Definition: compat.h:735
NDIS_OID Oid
Definition: nuiouser.h:37
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 905 of file wlanconf.c.

906 {
907  HANDLE hAdapter;
908  IP_ADAPTER_INDEX_MAP IpInfo;
909 
910  /* Initialize the Console Standard Streams */
912 
913  if (!ParseCmdline(argc, argv))
914  return -1;
915 
916  if (!OpenWlanAdapter(&hAdapter, &IpInfo))
917  {
919  return -1;
920  }
921 
922  if (bScan)
923  {
924  if (!WlanScan(hAdapter))
925  {
927  CloseHandle(hAdapter);
928  return -1;
929  }
930  }
931  else if (bDisconnect)
932  {
933  if (!WlanDisconnect(hAdapter, &IpInfo))
934  {
936  CloseHandle(hAdapter);
937  return -1;
938  }
939  }
940  else if (bConnect)
941  {
942  if (!WlanConnect(hAdapter))
943  {
945  CloseHandle(hAdapter);
946  return -1;
947  }
948  }
949  else
950  {
951  if (!WlanPrintCurrentStatus(hAdapter))
952  {
954  CloseHandle(hAdapter);
955  return -1;
956  }
957  }
958 
959  CloseHandle(hAdapter);
960  return 0;
961 }
static int argc
Definition: ServiceArgs.c:12
#define CloseHandle
Definition: compat.h:739
BOOL bDisconnect
Definition: wlanconf.c:30
BOOL WlanScan(HANDLE hAdapter)
Definition: wlanconf.c:704
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
#define IDS_NO_WLAN_ADAPTER
Definition: resource.h:5
#define argv
Definition: mplay32.c:18
VOID DoFormatMessage(DWORD ErrorCode)
Definition: wlanconf.c:32
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
BOOL WlanConnect(HANDLE hAdapter)
Definition: wlanconf.c:534
BOOL bScan
Definition: wlanconf.c:23
BOOL bConnect
Definition: wlanconf.c:25
BOOL WlanDisconnect(HANDLE hAdapter, PIP_ADAPTER_INDEX_MAP IpInfo)
Definition: wlanconf.c:231
BOOL OpenWlanAdapter(HANDLE *hAdapter, IP_ADAPTER_INDEX_MAP *IpInfo)
Definition: wlanconf.c:212
BOOL WlanPrintCurrentStatus(HANDLE hAdapter)
Definition: wlanconf.c:274
BOOL ParseCmdline(int argc, WCHAR *argv[])
Definition: wlanconf.c:853
#define StdOut
Definition: fc.c:14
#define ConInitStdStreams()
Definition: fc.c:13

Variable Documentation

◆ bAdhoc

BOOL bAdhoc = FALSE

Definition at line 28 of file wlanconf.c.

Referenced by ParseCmdline(), and WlanConnect().

◆ bConnect

BOOL bConnect = FALSE

Definition at line 25 of file wlanconf.c.

Referenced by ParseCmdline(), and wmain().

◆ bDisconnect

BOOL bDisconnect = FALSE

Definition at line 30 of file wlanconf.c.

Referenced by ParseCmdline(), and wmain().

◆ bScan

BOOL bScan = FALSE

Definition at line 23 of file wlanconf.c.

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

◆ sSsid

WCHAR* sSsid = NULL

Definition at line 26 of file wlanconf.c.

Referenced by ParseCmdline(), and WlanConnect().

◆ sWepKey

WCHAR* sWepKey = NULL

Definition at line 27 of file wlanconf.c.

Referenced by ParseCmdline(), and WlanConnect().