How to connert to WLAN programmatically

How to connert to WLAN programmatically

Postby Otto » Sat May 23, 2009 5:44 pm

I want to ask is there any way to start WLAN connection programmatically when WLAN is not activated in Comm manager.
Thanks in advance
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6003
Joined: Fri Oct 07, 2005 7:07 pm

Re: How to connert to WLAN programmatically

Postby Otto » Sat May 23, 2009 6:10 pm

Does someone know how to convert this to FWPPC?
Thanks in advance
Otto

Use Power Manager APIs with NDIS Miniport driver (valid for WiFi only)

If you look at pm.h header file of the WM5\6 SDKs, you’ll find a constant, which is is even public for 5.0 here and for 6.x here:

#define PMCLASS_NDIS_MINIPORT TEXT("{98C5250D-C29A-4985-AE5F-AFE5367E5006}")If you examine the registry contents at [HKLM\System\CurrentControlSet\Control\Power\State], you’ll see “devices” whose power-state can be controlled thru Power Manager APIs, accordingly to the SDK Documentation. One of those devices is the WiFi driver, described as “{98C5250D-C29A-4985-AE5F-AFE5367E5006}\<device name chosen by the OEM>” (The name can be seen also for example in the IPConfig section of the log generated by the Windows Mobile Network Analyzer PowerToy). Since the device appears under that registry key, an ISV can programmatically control its power state by using the documented Power Manager API SetDevicePower():

[DllImport("coredll.dll", SetLastError = true)]
private static extern int SetDevicePower(string pvDevice, int dwDeviceFlags, DevicePowerState DeviceState);

private enum DevicePowerState : int
{
Unspecified = -1,
D0 = 0, // Full On: full power, full functionality
D1, // Low Power On: fully functional at low power/performance
D2, // Standby: partially powered with automatic wake
D3, // Sleep: partially powered with device initiated wake
D4, // Off: unpowered
}

private const int POWER_NAME = 0x00000001;
So, to turn the WiFi ON:

string driver = Utilities.WiFi.FindDriverKey();
SetDevicePower(driver, POWER_NAME, DevicePowerState.D0);And OFF:

string driver = Utilities.WiFi.FindDriverKey();
SetDevicePower(driver, POWER_NAME, DevicePowerState.D4);Utilities.WiFi.FindDriverKey() is simply a function that returns the whole registry key name of the key containing the NDIS MINIPORT class GUID defined in the SDK’s pm.h:

private static string FindDriverKey()
{
string ret = string.Empty;

//#define PMCLASS_NDIS_MINIPORT TEXT("{98C5250D-C29A-4985-AE5F-AFE5367E5006}")
//(From "c:\Program Files (x86)\Windows Mobile 6 SDK\PocketPC\Include\Armv4i\pm.h")
string WiFiDriverClass= "{98C5250D-C29A-4985-AE5F-AFE5367E5006}";

foreach (string tmp in Registry.LocalMachine.OpenSubKey("System\\CurrentControlSet\\Control\\Power\\State", false).GetValueNames())
{
if (tmp.Contains(WiFiDriverClass))
{
ret = tmp;
break;
}
}

return ret;
}This proved to work on some devices I’ve tested it with, after reboots and also consistently with the Wireless Manager\Comm Manager of the device. I’ve found a forum post stating that on iPAQ devices this approach doesn’t work (and this is in line with the fact that HP provided a DLL within its private SDK exposing specific APIs to interact with their driver), however I tested this approach on an iPAQ Smartphone and it worked as well.

Now, the usual question: IS THIS SUPPORTED OR NOT BY MICROSOFT TECHNICAL SUPPORT? Every single detail an ISV uses in this approach is documented, hence supported. Cool! But… again, as before… what more can Microsoft Technical Support do after verifying that the ISV used the functions above correctly? If a Power Manager API doesn’t work correctly with a driver, chances are that the problem is with the driver, not with the PM API (considering that the same API works correctly in other cases). And who develops the driver and has technically the ability to give support about it? Again, the OEM…



I hope things are a bit clearer now… just let me know in case that’s not true!



Cheers,
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6003
Joined: Fri Oct 07, 2005 7:07 pm


Return to FiveWin for Pocket PC

Who is online

Users browsing this forum: No registered users and 5 guests