I’m trying to enumerate and switch wireless profiles under Windows Mobile 6. The unit that I’m using is the SocketMobile 650. I’ve pretty much ruled out using OpenNetCF to accomplish this, since the GetAllNetworkInterfaces() call returns a wifi network interface that doesn’t appear to advertise itself as WirelessZeroConfigNetworkInterface (or even WirelessNetworkInterface, for that matter).
So, I’m back to looking at API calls. My question is: How can I use c# to enumerate and switch wireless profiles without using OpenNetCF?
sorry, looks like SO “insert code” does not handle long code listings well, so codes look bad. Please copy/paste them into your editor, and do reformatting.
items (1), (2), (3) are quite trivial – they are just definitions of classes/structs/export functions. Item (4) is where all magic happens – but i was not able to insert it here (too long), so I copied it to PasteBin (link is below). Please let me know if you have any questions – i will try to help you – but idea is to use DeviceIoControl low-level function to communicate with the adapter.
please take a look at the codes. I don’t think you will be able to compile them, however they should give you an idea what’s going on under the hood. Disclaimer – i wrote them 5-6 years ago, and now i would do it quite different 🙂
C# wrapper for C++ dll:
public class WiFiDllWrapper
{
private class DllFunctions
{
[DllImport(“ewf.dll”)]
internal static extern bool TurnWlanOn();
}
AccessPoint model definition:
enum NDIS_802_11_WEP_STATUS
{
Ndis802_11WEPEnabled,
Ndis802_11Encryption1Enabled = Ndis802_11WEPEnabled,
Ndis802_11WEPDisabled,
Ndis802_11EncryptionDisabled = Ndis802_11WEPDisabled,
Ndis802_11WEPKeyAbsent,
Ndis802_11Encryption1KeyAbsent = Ndis802_11WEPKeyAbsent,
Ndis802_11WEPNotSupported,
Ndis802_11EncryptionNotSupported = Ndis802_11WEPNotSupported,
Ndis802_11Encryption2Enabled,
Ndis802_11Encryption2KeyAbsent,
Ndis802_11Encryption3Enabled,
Ndis802_11Encryption3KeyAbsent
};
enum NDIS_802_11_NETWORK_INFRASTRUCTURE
{
Ndis802_11IBSS,
Ndis802_11Infrastructure,
Ndis802_11AutoUnknown,
Ndis802_11InfrastructureMax // Not a real value, defined as upper bound
};
enum NDIS_802_11_NETWORK_TYPE
{
Ndis802_11FH,
Ndis802_11DS,
Ndis802_11OFDM5, // Added new types for OFDM 5G and 2.4G
Ndis802_11OFDM24,
Ndis802_11NetworkTypeMax // not a real type, defined as an upper bound
};
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
struct APInfo
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 40)]
public string _ssid; // SSID of the AP
}
public class AccessPoint
{
// if the power level (in dBm) lower that this, then the signal is weak
const int STRONG_WEEK_dBm_THRESHOLD = -70;
}
C++ file #1 – exportable functions:
include “stdafx.h”
include “ewf.h”
include “NdisConnect.h”
include
NdisConnect g_NdisAdapter(L”ewf_log.txt”);
extern HANDLE g_NdisConnectedEvent;
extern “C” EWF_API BOOL WINAPI FindWirelessAdapter()
{
ENTER;
}
// 1. init adapter: CreateFile(NDISUIO_DEVICE_NAME, – done at g_NdisAdapter ctor
// 2. disable WZC
// 3. rebind adapter
// 4. open adapter
extern “C” EWF_API BOOL WINAPI ConnectToAdapter()
{
ENTER;
}
extern “C” EWF_API BOOL WINAPI TurnWlanOn()
{
return g_NdisAdapter.TurnWlanOn();
}
extern “C” EWF_API BOOL WINAPI DisconnectFromAdapter()
{
ENTER;
try
{
g_NdisAdapter.Disassociate();
}
catch (NdisException* e)
{
LOG_EXCEPTION(e);
return FALSE;
}
}
extern “C” EWF_API BOOL StartScan()
{
ENTER;
g_NdisAdapter.ScanForAPs();
}
extern “C” EWF_API BOOL GetAPsList(APInfo* pAPs, int maxAPs, int* foundAPs)
{
ENTER;
BOOL res = FALSE;
}
extern “C” EWF_API BOOL ConnectToAP(int maxWaitTimeSeconds, const wchar_t* ssid, bool isWepEnabled, const wchar_t* wepKey)
{
char cSSID[33], cWepKey[30];
localFunctionCT2A(ssid, cSSID, sizeof(cSSID));
localFunctionCT2A(wepKey, cWepKey, sizeof(cWepKey));
}
<< when i pasted code here, i went well over 30k limit for the post, so I created PasteBin file>> – http://pastebin.com/wMBZAYCQ