Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[DESPERATE] Turn on/off Bluetooth, WiFi and an RFID tag reader.

464 views
Skip to first unread message

BLUE

unread,
Apr 27, 2007, 4:45:50 AM4/27/07
to
Psion WorkAbout Pro with Windows CE .NET 4.2

Dealer gave me PowerAPIOn.exe and PowerAPIOff.exe to turn on/off tag reader,
but I want to do it programmatically and do the same with WiFi and Bluetooth
as I can do from Control Panel ("Network and dialup connections" and
"Power").

Googling I've found that I should:


- search all devices in
HKEY_LOCAL_MACHINE / System / CurrentControlSet / Control / POWER /
State / {98C5250D-C29A-4985-AE5F-AFE5367E5006} / <DEVICE_NAME>

I've found no devices under POWER.
In Control Panel I've found that I've a Cambridge Silicon Bluetooth chip.
Under HKEY_LOCAL_MACHINE/Comm I've found:
- an unknown CF8385PN1 device
- an Agere WLAGS46B1 WiFi compact flash


- use "SetDevicePower" but I don't know <DEVICE_NAME> and Microsoft
discourages application developers from calling this function:
http://msdn2.microsoft.com/en-us/library/ms889607.aspx


- use "SetPowerRequirement" in this way:

[DllImport("coredll.dll", SetLastError = true)]
private static extern IntPtr SetPowerRequirement
(
string pvDevice,
CEDEVICE_POWER_STATE DeviceState,
uint DeviceFlags,
IntPtr pvSystemState,
uint StateFlags
);

...
string deviceName = ...;
CEDEVICE_POWER_STATE deviceState = ...;
uint devFlags = POWER_NAME | POWER_FORCE;
SetPowerRequirement(deviceName, deviceState, devFlags, IntPtr.Zero, 0);

MSDN says "DeviceFlags = Bitwise-or of the following flags POWER_NAME,
POWER_FORCE".
This mean Bitwise-or of all the flags or Bitwise-or of the needed ones?

MSDN says "pvDevice Must be a valid LPWSTR device name, for example,
"COM1:". The actual meaning is determined by the DeviceFlags parameter."
As mentioned above for "SetDevicePower" I don't know <DEVICE_NAME>.
In which way DeviceFLags modify the meaning???

MSDN says "POWER_NAME specifies the name of the device whose power should
be maintained at or above the DeviceState level."
I've found in Pm.h that POWER_NAME is a DWORD whose value is 1:
how can it specify a name???
Maybe MSDN means that if I use POWER_NAME will be used the name of the
device that is calling SetPowerRequirement?

If I import the dll why I have to define CEDEVICE_POWER_STATE again in
C#???


Paul G. Tobey [eMVP]

unread,
Apr 27, 2007, 11:29:55 AM4/27/07
to
Running a program programmatically is no big deal. If all that
PowerAPIOn.exe does is turn on the power,

CreateProcess( "PowerAPIOn.exe", ... );

seems like a perfectly valid way to accomplish what you want. The hardware
vendor is going to have to tell you what you can do and how they want you to
do it.

Paul T.

"BLUE" <blue> wrote in message
news:4631b849$0$4796$4faf...@reader4.news.tin.it...

BLUE

unread,
Apr 27, 2007, 11:39:10 AM4/27/07
to
>CreateProcess( "PowerAPIOn.exe", ... );
>
>seems like a perfectly valid way to accomplish what you want.

No because it desnt't let me to turn on/off bluetooth and WiFi, only the
RFID tag reader.


Paul G. Tobey [eMVP]

unread,
Apr 27, 2007, 12:29:47 PM4/27/07
to
Yes, it doesn't implement all of your desired functions, but it does do one
of them and the chances of there being a single API that does everything are
zero. So, you now have 1/3 of your desired capability implemented. There
isn't an API, for example, to turn off the Bluetooth radio for your
hardware, is there? That would give you another 1/3...

Paul T.

"BLUE" <blue> wrote in message

news:4632192a$0$10626$4faf...@reader2.news.tin.it...

BLUE

unread,
Apr 29, 2007, 10:03:05 AM4/29/07
to
I'll let you know what the dealer and the manufacturer will answer me as
soon as possible.


As far as now I've been capable or turning ON/OFF:

- the RFID reader using dealer supplied
executables (PowerAPIon/off.exe)
- CF WiFi and any other expansion card
using "Psion Mobile Devices SDK"


Regarding Bluetooth I've tried using unsuccessfully:

- SetPowerRequirement (coredll.dll)
- Psion Mobile Devices SDK
- BluetoothRadio.BluetoothRadioMode (32feet)
- BthSetMode (Bthutil.dll)

Googling I've found that 32feet and Microsoft methods are based on
Bthutil.dll library.
MSDN it's wrong when it says it's supported from Windows CE 4.2: it's
missing!!!
I think it's only supported on Pocket PC 2003 and later (Windows Mobile).

Windows can disable Bluetooth so it's possible to do it; moreover Pocket PC
2003 is based on CE 4.2 so I think that copying Bthutil.dll on my device it
will work!
Does anybody have a Pocket PC 2003 and could supply me that DLL?

My dream was making a DLL to power on/off devices calling Windows CE APIs,
but if it is impossible I'm happy to use dealer supplied EXEs and Psion
DLLs, but as for Bluetooth if I don't have Bthutil.dll, it cannot be done.


Thnak you everybody,
Luigi.


Paul G. Tobey [eMVP]

unread,
Apr 30, 2007, 11:30:20 AM4/30/07
to
It's not true that everyone uses the same Bluetooth stack. Microsoft's
stack is supported on CE 4.2, but that doesn't force a particular OEM to use
it. The Widcomm stack was widely used in those days and that's probably
what you have if Peter's library doesn't work with it. Widcomm charges a
significant amount of money for their SDK, which is why there's little
third-party support for it. Even if someone shipped you the DLL, it
wouldn't help, as it's for a different stack than your device is running.

Paul T.

"BLUE" <blue> wrote in message

news:4634a5b7$0$37202$4faf...@reader3.news.tin.it...

BLUE

unread,
Apr 30, 2007, 12:17:37 PM4/30/07
to
> It's not true that everyone uses the same Bluetooth stack.
> Microsoft's stack is supported on CE 4.2, but that doesn't force a
> particular OEM to use it.

I've never said so.

> The Widcomm stack was widely used in those days and that's probably what
> you have if Peter's library doesn't work with it.

I've seen I've Microsoft stack because in the registry I have
HKLM\Software\Microsoft\Bluetooth key and no Widcomm key.


Paul G. Tobey [eMVP]

unread,
Apr 30, 2007, 12:29:29 PM4/30/07
to
If your device has the Microsoft Bluetooth stack then it either has the DLL
that you need to operate it or it's broken (I suppose it could be
intentionally broken, too). Neither of those is fixable by random third
parties. If a DLL was somehow left out of the operating system build by the
device OEM, you'll have to contact them for an updated operating system
image that has the right files in it. Note that the DLL might be present,
even if you can't see it with File Explorer on the device (which hides
system files). Browsing the filesystem via ActiveSync or using the Remote
File Viewer should show you all the files in the \windows folder.

Paul T.

"BLUE" <blue> wrote in message

news:463616bf$0$37207$4faf...@reader3.news.tin.it...

BLUE

unread,
May 1, 2007, 4:19:48 AM5/1/07
to
> Note that the DLL might be present, even if you can't see it with File
> Explorer on the device (which hides system files).
> Browsing the filesystem via ActiveSync or using the Remote File Viewer
> should show you all the files in the \windows folder

In View\Options I've deselected all checkboxes (I can see hidden and system
files) and I don't see Bthutil.dll
Having done the same on my desktop PC, ActiveSync show me less files than
the ones I can see from the device and File Viewer is not usable because I
have Windows CE 4.2 so I can only use ActiveSync 3.8 (4.2 and up don't work,
I've tried them) wich is not supported by VS 2005 and its tools.

Thnak you for your tips regarding the exclusion of the dll from the os
image.
I'll contact them and ask them what to do.

Luigi.

Alberto Silva

unread,
May 1, 2007, 9:22:59 AM5/1/07
to
Hi,
Have you registered on the Teknet Psion website, where you can find SDK for
specific models?

http://www.psionteklogix.com/public.aspx?s=com&p=TeknetforDevelopers

Alberto Silva
MS Mobile Devices MVP
http://msmvps.com/AlbertoSilva

BLUE

unread,
May 1, 2007, 9:47:23 AM5/1/07
to
I've already registered to Teknet and I've sent two mail to Psion without an
answer.

For the latest info see this post and replies:
From: BLUE
Newsgroups: microsoft.public.windowsce.app.development
Sent: Sunday, April 29, 2007 4:03 PM
Subject: Turn ON/OFF Bluetooth, WiFi and other devices (what I've
discovered so far)


Here an interesting solution but it needs warm reboot... not so nice for the
user.

----- Original Message -----
From: Jim....@googlemail.com
Newsgroups: microsoft.public.dotnet.languages.csharp
Sent: Tuesday, May 01, 2007 10:36 AM
Subject: Re: Turn on/off Bluetooth, WiFi and an RFID tag reader.


Hi,

This is what I use, although you could also register as a developer at
PsionTeklogic's Teknet and download the SDK, that has lots of control
libraries.

Make this registry change (I use the OpenNETCF libraries)

HKLM\Drivers\PsionTeklogix\Bluetooth\PowerEnable = 0x1 (DWord)
Also in that Bluetooth section
resetdelay = 0x1388 (DWord)
baud = 0x1C200 (DWord)
name = "COM2:" (String)
driver = "bthuart.dll" (String)

Check for those settings at application load and reboot if you need to
change any of them.
If you use OpenNETCF, don't forget to call
Registry.LocalMachine.Flush();

To reboot:

[DllImport("coredll.dll")]
internal static extern bool KernelIoControl(UInt32 dwIoControlCode,
IntPtr lbInBuf, UInt32 nInBufSize, ref IntPtr lpOutBuf, ref UInt32
nOutBufSize, ref IntPtr lpBytesReturned);

public static void WarmReset()
{
IntPtr lpOutBuf = IntPtr.Zero;
UInt32 nOutBufSize = 0;
IntPtr lpBytesReturned = IntPtr.Zero;
UInt32 dwIocontrolCode = 0;

dwIocontrolCode = CTL_CODE(WinCEDeviceTypes.FILE_DEVICE_HAL,
WinCECTL_CODEFunctions.FUNCTION_REBOOT,
WinCEBufferMethodCodes.METHOD_BUFFERED,
WinCEKernelAccessors.FILE_ANY_ACCESS);

KernelIoControl(dwIocontrolCode, IntPtr.Zero, 0, ref lpOutBuf, ref
nOutBufSize, ref lpBytesReturned);
}

private static UInt32 CTL_CODE(WinCEDeviceTypes DeviceType,
WinCECTL_CODEFunctions Function, WinCEBufferMethodCodes Method,
WinCEKernelAccessors Access)
{
return (uint) DeviceType << 16 | (uint) Access << 14 | (uint)
Function << 2 | (uint) Method;

}

I found all this out by the following process:

1) Install embedded visual C++ 4 and all relevant service packs and
psion SDKs
2) Set the Bluetooth OFF
3) Take a copy of the CR Registry using the eVC++ Remote Registry
editor
4) Set the Bluetooth ON
5) Take a second copy of the Registry
6) Compare the to *.reg files using a text comparing application (I
use KDiff3)
7) Write code to make those registry changes progamatically.

Should work for the RFID and WiFi too.

Regards,

James Neave.


Paul G. Tobey [eMVP]

unread,
May 1, 2007, 11:34:59 AM5/1/07
to
That's not enough to see every file. Remote File Viewer downloadable as
part of eMbedded Visual C++ 4.0 should work with your device (well, VS2005's
Remote File Viewer works fine for me with CE4.2 devices, too, but...)

It sounds like there's a pretty high probability that the OEM doesn't
provide a well-known API for Bluetooth, so I think you're stuck getting the
information you need from the very source, them.

Paul T.

"BLUE" <blue> wrote in message

news:4636f834$0$36444$4faf...@reader5.news.tin.it...

dbgrick

unread,
May 8, 2007, 9:56:01 PM5/8/07
to
Have you tried BthSetMode located in the bthutil.dll. You should be able to
use this api to turn on and off the bluetooth radio. You can find
information about this call at:
http://msdn2.microsoft.com/en-us/library/ms837414.aspx

As for WLAN, check out hsi article:

http://www.ureader.com/message/1182448.aspx

Rick D
Contractor

BLUE

unread,
May 9, 2007, 2:42:16 PM5/9/07
to
I have MS BT tack but I do not have Bthutil.dll: I think Psion has removed
it from the OS image.

As for WLAN:

Enable and Disable in the Network and DialUp Connections manager is actually
setting a bit in the registry for the target adapter and then calling NDIS
to unbind or bind (depending on whether your disabling or enabling the
adapter).


In HKEY_LOCAL_MACHINE\Comm\NdisPower insert this value to disable the
adapter:
<adapterName> REG_DWORD 4 (0x00000004)

Delete the value to enable the adapter


To do a NDIS bind or NDIS unbind you can use these API:

VOID NdisBindProtocolsToAdapter
(
PNDIS_STATUS pStatus,
PWSTR wszAdapterInstanceName,
PWSTR wszProtocolName
);

VOID NdisMRebindProtocolsToAdapter(NDIS_HANDLE MiniportAdapterHandle);

VOID NdisUnbindProtocolsFromAdapter
(
PNDIS_STATUS pStatus,
PWSTR wszAdapterInstanceName,
PWSTR wszProtocolName,
);


I've tried using these API but I get a NotSupportedException
So I've tried using OpenNetCF.Net Adapter class but:

- I do not understand why I get an exception on the first time I try to
bind or unbind
- I do not know how to bind the adapter if it is disabled: the only way is
modifying Adapter source code so that the Name property let me set the Name:
exploring the source I've found that Adapter class needs only the name to
call internal bind functions

using OpenNETCF.Win32;
using OpenNETCF.Net;


[DllImport("Ndis.dll", SetLastError = true)]
private static extern void NdisBindProtocolsToAdapter
(
ref int pStatus,
ref string wszAdapterInstanceName,
ref string wszProtocolName
);

[DllImport("Ndis.dll", SetLastError = true)]
private static extern void NdisUnbindProtocolsFromAdapter
(
ref int pStatus,
ref string wszAdapterInstanceName,
ref string wszProtocolName
);


// DISCOVERY ********************** BUTTON1
AdapterCollection ac = Networking.GetAdapters();

string adapterName;
this.adapter = null;
int myAdapterIndex = -1;

for (int i = 0; i < ac.Count; i++)
{
adapterName = ac[i].Name;

if (adapterName == wiFiAdapterName)
{
this.adapter = ac[i];
myAdapterIndex = i;
}
}


// DISABLE ********************** BUTTON2
RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"Comm\NdisPower", true);
object obj = rk.GetValue(wiFiAdapterName);
rk.SetValue(wiFiAdapterName, 0x00000004);
rk.Flush();
rk.Close();

try
{
// Using this I get NotSupportedException
/*
int status = 0;
string name = this.adapter.Name;
string nullString = null;
NdisUnbindProtocolsFromAdapter(ref status, ref name, ref nullString);
*/

// Using this I get "DeviceIoControl( IOCTL_NDIS_UNBIND_ADAPTER )"
// exception only the first time I press the button: if I wait some
// seconds Bind and Unbind work!
this.adapter.UnbindAdapter();
}
catch(Exception exc)
{
MessageBox.Show(exc.Message);
}


// ENABLE ********************** BUTTON3
RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"Comm\NdisPower", true);
object obj = rk.GetValue(wiFiAdapterName);
rk.DeleteValue(wiFiAdapterName);
rk.Flush();
rk.Close();

try
{
// Using this I get NotSupportedException
/*
int status = 0;
string name = this.adapter.Name;
string nullString = null;
NdisBindProtocolsToAdapter(ref status, ref name, ref nullString);
*/

// THIS CAN BE DONE ONLY IF DISCOVERY WAS MADE WITH ADAPTER ACTIVE
// TO AVOID THIS PROBLEM I CAN MODIFY Adapter.Name PROPERTY TO HAVE A
// SET SECTION: EXPLORING THE SOURCE CODE I FOUND ONLY THE NAME IS
// NEEDED TO CALL INTERNAL API FOR DEVICE BINDING
//
// Using this I get "DeviceIoControl( IOCTL_NDIS_BIND_ADAPTER )"
// exception only the first time I press the button: if I wait some
// seconds Bind and Unbind work!
this.adapter.BindAdapter();
}
catch(Exception exc)
{
MessageBox.Show(exc.Message);
}


Paul G. Tobey [eMVP]

unread,
May 9, 2007, 4:56:45 PM5/9/07
to
It looks to me like you've disabled *all* adapters there! That's probably
not what you really meant to do. If it is, you'll have to figure out how to
undo it by whatever means is available to you.

Paul T.

"BLUE" <blue> wrote in message news:O1RUXnmk...@TK2MSFTNGP04.phx.gbl...

BLUE

unread,
May 10, 2007, 4:18:16 AM5/10/07
to
> It looks to me like you've disabled *all* adapters there!

Excuse me but I do not understand: I have only "USB cable" and WiFi
adapters: the first is enabled and connects when I cradle the device, the
second I want to be disabled and only the applications will enable it as
needed.
The main problem is that bind and unbind work, but only after the first try
from application start and waiting some seconds.

> If it is, you'll have to figure out how to undo it by whatever means is
> available to you.

What are these means: programmatically (I don't know how) or manually with
the stylus (this is not the solution I was looking for)?


Thanks,
Luigi.


Paul G. Tobey [eMVP]

unread,
May 10, 2007, 11:10:59 AM5/10/07
to
>> It looks to me like you've disabled *all* adapters there!
>
> Excuse me but I do not understand: I have only "USB cable" and WiFi
> adapters: the first is enabled and connects when I cradle the device, the
> second I want to be disabled and only the applications will enable it as
> needed.
> The main problem is that bind and unbind work, but only after the first
> try from application start and waiting some seconds.

You've disabled all of NDIS. That's not a documented method, so far as I
know, of doing anything that can be undone without a reboot. So, instead of
disabling the WiFi adapter, something which I can tell you how to undo,
you've done something which I can't. Good luck; you have to figure out how
to undo it yourself.

>> If it is, you'll have to figure out how to undo it by whatever means is
>> available to you.
> What are these means: programmatically (I don't know how) or manually with
> the stylus (this is not the solution I was looking for)?

Exactly! When you find out, let us know.

Paul T.


BLUE

unread,
May 10, 2007, 12:47:43 PM5/10/07
to
> You've disabled all of NDIS

You mean I've disabled in some way the drivers so now it doe not work?
By the way I've done a cold reboot and through control panel it seems that
the WiFi compact flash adapter works.


> That's not a documented method

The code is taken from OpenNETCF.Net source and registry stuff is taken from
one of your answers:
http://www.ureader.com:80/message/1182448.aspx

The same approach is used here (even if I cannot find a working driverName
through all that in the registry)
http://rburdick.blogspot.com/2005/05/programatically-turning-pocket-pc-wlan.html


> instead of disabling the WiFi adapter, something which I can tell you how
> to undo

Do you know what is the documented method of enabling/disabling it?
Could you tell me it?

I don't know if I have understood but it is possible that my WiFi adapter
works even if I've disabled all NDIS: if it works I've figured out how to
enable NDIS again?


Thanks,
Luigi.


Paul G. Tobey [eMVP]

unread,
May 10, 2007, 1:24:37 PM5/10/07
to
>> You've disabled all of NDIS
>
> You mean I've disabled in some way the drivers so now it doe not work?
> By the way I've done a cold reboot and through control panel it seems that
> the WiFi compact flash adapter works.
>
>> That's not a documented method
>
> The code is taken from OpenNETCF.Net source and registry stuff is taken
> from one of your answers:
> http://www.ureader.com:80/message/1182448.aspx

Yes, I misread your description of the registry changes. You have the name
of the adapter, because you just changed it from enabled to disabled. Reuse
that name when you want to reenable it again (change the registry entry to
'not disabled' and then BIND the adapter).

You can also enumerate the possible network adapters by enumerating the
registry under HKLM/Comm.

I thought I had some code laying around that duplicated the operations that
the Network and DialUp Connections applet does when you choose File |
Disable and File | Enable, but I can't find it.

Paul T.


BLUE

unread,
May 10, 2007, 1:53:29 PM5/10/07
to
> then BIND the adapter
The problem is that bind and unbind give me exceptions (DeviceIoControl
return false: I've tried doing all by using source code of
OpenNETCF.Net.Adapter) after application start for a while: if I wait for
example 4 seconds after Unbind all start going well.
I do not think I'm using a wrong code, but I do not know how to get it work
:(


Thanks a lot for your support,
Luigi


Paul G. Tobey [eMVP]

unread,
May 10, 2007, 2:33:12 PM5/10/07
to
Yes, oddly enough NDIS takes time to bind or unbind an adapter and trying to
rapidly do both isn't handled. Don't do that. Take whatever steps you need
to assure that you won't overlap those operations.

Paul T.

"BLUE" <blue> wrote in message news:eVkHywyk...@TK2MSFTNGP04.phx.gbl...

BLUE

unread,
May 10, 2007, 5:37:15 PM5/10/07
to
> trying to rapidly do both isn't handled
Even if I try to do an unbind it doesn't work: with adapter enabled I start
the app, then I press a button to unbind and I get the exception.
The only workaround I've found is to enable a System.Windows.Forms.Timer
with an interval of 1 ms at application start and to do an unbind at first
tick, a bind at second tick and then disable the timer: in this way I can
then click my on and off buttons as rapidly as I want (waiting only to see
WiFi icon appear and disappear that is acceptable).

I'll be very happy to know (one day perhaps) how to reproduce
programmatically the actions Windows do when I disable/enable in Network
applet: it works well, immediately and with no problems!
Maybe when Microsoft will make Windows code open source :)


Thanks a lot for your help!


I've forgot saying that contacting Psion I've managed to turn on/off
Bluetooth and Rfid with their API.
The only problem is that their latest SDK (2.0) has a bug regarding turning
on/off Bluetooth, while 1.8 SDK works fine with BT but does not implements
CF, SD, PCMCIA slots enabling/disabling.
RFID PowerAPI (to turn on/off rfid radio) is an example to compile with
Embedded VC++ of their HW dev kit.


HTH,
Luigi.


Paul G. Tobey [eMVP]

unread,
May 10, 2007, 6:04:39 PM5/10/07
to
I still don't understand what you're trying to do by adding timers and
binding and unbinding in rapid succession. Here's the process that the
system uses when you select Disable for an adapter in the Network and DialUp
Connections in generic Windows CE (we do have the source):

1. Open the NDIS power device NPW1:

2. Build up an NDISPWR_SAVEPOWERSTATE structure with the right adapter name
in it, along with the target state of D4 for disabled, and call
DeviceIoControl passing IOCTL_NPW_SAVE_POWER_STATE. Close the NPW1: driver
handle.

3. If NDIS supports power management, send it a SetDevicePower call with the
D4 state.

4. Send an IOCTL_NDIS_UNBIND_ADAPTER to the target adapter.

5. Send an IOCTL_NDIS_GET_ADAPTER_BINDINGS call to the adapter (you can tell
if it's bound by checking the returned string).

Paul T.


"BLUE" <blue> wrote in message

news:%23Ore0t0...@TK2MSFTNGP04.phx.gbl...

BLUE

unread,
May 10, 2007, 6:34:34 PM5/10/07
to
> I still don't understand what you're trying to do by adding timers and
> binding and unbinding in rapid succession

I want to enable or disable WiFi adapter when my app needs to do so (for
example before trying to connect to a server enable WLAN and after disable)
and I want to do this programmatically in a way it can work well as if I had
done it manually through control panel.

The only reason because I use that timer is that trying to use
OpenNETCF.Net.Adapter BindAdapter and UnbindAdapter methods I get an
exception so if I do an unbind and after a 1 ms a bind, after I can do all
things I need without exception!

Another problem is that if my adapter is disabled Network.GetAdapters does
not find it.

Is there a way to power on a disabled device as we can d with File ->
Enable?


> Here's the process that the system uses when you select Disable for an
> adapter in the Network and DialUp Connections in generic Windows CE (we do
> have the source):

I think many people want to implement this turn on/off functionality but
even if you have the source I found no web site and no library that make our
life easier: for a beginner is quite hard to spend time with Windows API and
I cannot understand why no one has done such a useful DLL or posted the code
that follows the phases you explained me.


You're very patient and you help a lot!

Thanks,
Luigi.


Paul G. Tobey [eMVP]

unread,
May 10, 2007, 6:53:29 PM5/10/07
to
> I want to enable or disable WiFi adapter when my app needs to do so (for
> example before trying to connect to a server enable WLAN and after
> disable) and I want to do this programmatically in a way it can work well
> as if I had done it manually through control panel.

This is fine and has nothing to do with a 1ms time between disable and
enable, as far as I can see.

> The only reason because I use that timer is that trying to use
> OpenNETCF.Net.Adapter BindAdapter and UnbindAdapter methods I get an
> exception so if I do an unbind and after a 1 ms a bind, after I can do all
> things I need without exception!
>
> Another problem is that if my adapter is disabled Network.GetAdapters does
> not find it.

Yes, and this is entirely expected.

> Is there a way to power on a disabled device as we can d with File ->
> Enable?

Yes, you'll have to follow the complete list of things that the Network and
DialUp Connections applet does, however.

>> Here's the process that the system uses when you select Disable for an
>> adapter in the Network and DialUp Connections in generic Windows CE (we
>> do have the source):
>
> I think many people want to implement this turn on/off functionality but
> even if you have the source I found no web site and no library that make
> our life easier: for a beginner is quite hard to spend time with Windows
> API and I cannot understand why no one has done such a useful DLL or
> posted the code that follows the phases you explained me.

You're wanting to do something that is not a beginner thing and, in fact,
there are *not* a lot of people who want to do it. I can remember 5. Once
you've done it in managed code, you can post that code and answer the next 5
people's questions...

Paul T.
:-)

BLUE

unread,
May 11, 2007, 7:33:08 AM5/11/07
to
>- Open the NDIS power device "NPW1:"
>
>- Build up an NDISPWR_SAVEPOWERSTATE structure with the right adapter name
>in it, along with the target state of D4 for disabled, and call
>DeviceIoControl passing IOCTL_NPW_SAVE_POWER_STATE. Close the "NPW1:"
>driver handle
>
>- If NDIS supports power management, send it a SetDevicePower call with the
>D4 state
>
>- Send an IOCTL_NDIS_UNBIND_ADAPTER to the target adapter
>
>- Send an IOCTL_NDIS_GET_ADAPTER_BINDINGS call to the adapter (you can tell
>if it's bound by checking the returned string)


1. Before doing that Comm\NdisPower\<AdapterName> registry value must be set
or not to 0x00000004?

2. How to check if NDIS supports power management?

3. I've done SetDevicePower(adapterName, POWER_NAME,
CEDEVICE_POWER_STATE.D4) but what value does adapterName have?
"NPW1:", "NDS0:", "NDS1:" or what?

4. In the IOCTL_NDIS_GET_ADAPTER_BINDINGS call to the adapter I must specify
lpOutBuffer and nOutBufferSize, but what value has nOutBufferSize since I do
not know how big is the retrieved list of protocol driver names?

5. To turn on wich are the steps?
The same changing D4 to D0 and UNBIND to BIND or what?


Thanks,
Luigi.


Paul G. Tobey [eMVP]

unread,
May 11, 2007, 12:55:01 PM5/11/07
to
Since you started a new thread by accident, I've copied your last message
below, so we don't split the result of the thread.

> >- Open the NDIS power device "NPW1:"
>>
>>- Build up an NDISPWR_SAVEPOWERSTATE structure with the right adapter name

>>in it, along with the target state of D4 for disabled, and call
>>DeviceIoControl passing IOCTL_NPW_SAVE_POWER_STATE. Close the "NPW1:"
>>driver handle
>>

>>- If NDIS supports power management, send it a SetDevicePower call with
>>the D4 state
>>


>>- Send an IOCTL_NDIS_UNBIND_ADAPTER to the target adapter
>>
>>- Send an IOCTL_NDIS_GET_ADAPTER_BINDINGS call to the adapter (you can
>>tell if it's bound by checking the returned string)
>
>
> 1. Before doing that Comm\NdisPower\<AdapterName> registry value must be
> set or not to 0x00000004?

I think that NDIS will set the entry for you. I don't see the code doing it
explicitly.

> 2. How to check if NDIS supports power management?

That should say to verify that the adapter supports power management. You
basically call GetDevicePower for the adapter's driver and, if it returns a
valid power state, it's assumed to be supported.

> 3. I've done SetDevicePower(adapterName, POWER_NAME,
> CEDEVICE_POWER_STATE.D4) but what value does adapterName have?
> "NPW1:", "NDS0:", "NDS1:" or what?

{98C5250D-C29A-4985-AE5F-AFE5367E5006}\<adaptername>

> 4. In the IOCTL_NDIS_GET_ADAPTER_BINDINGS call to the adapter I must
> specify lpOutBuffer and nOutBufferSize, but what value has nOutBufferSize
> since I do not know how big is the retrieved list of protocol driver
> names?

It's a 256 character TCHAR string.

> 5. To turn on wich are the steps?
> The same changing D4 to D0 and UNBIND to BIND or what?

In the IOCTL_NPW_SAVE_POWER_STATE call, and the SetPowerState call for the
adapter, set the state to PwrDeviceUnspecified instead of D4. Instead of
UNBIND_ADAPTER, use BIND_ADAPTER.

One other note is that some of the adapter names passed to various API calls
are not the same. Here's a summary, as I read it:

1. IOCTL_NPW_SAVE_POWER_STATE -- pass the adapter name, like "NE2000", etc.
Just the name.

2. SetDevicePower -- pass the combination of that GUID shown above and the
adapter name, as indicated above.

3. UNBIND_ADAPTER -- pass the adapter name only.

4. IOCTL_NDIS_GET_ADAPTER_BINDINGS -- pass the instance name of the adapter.
That is, if your adapter name is something like MYWIFI, then the instance
name would probably be MYWIFI1.

I'm thinking that you'd be better off just getting the source code and
reading it yourself. You can download an evaluation copy of Windows CE from
www.microsoft.com/embedded. Ideally, you'd get CE5, but that may not be up
there any more. If not, get CE6. The code in question can be found in
<winceroot>\public\common\oak\drivers\netsamp\connmc\lanconninfo.cpp (in a
method called ::defaultAction()).

Paul T.


BLUE

unread,
May 12, 2007, 4:36:57 AM5/12/07
to
You've pointed out the main problem: what is the adapter name.


In OpenNETCF.Net source, to BIND and UNBIND they always use "NDS0:" to
create ndisHandle and the adapter name we can find in
Comm\NdisPower\<AdapterName> to call DeviceIoControl (in my case "WLAGS46B1"
I've found it with the Adapter.Name property)


MSDN says Get/SetDevicePower must use GUID + a name as the one above:
"xxx#:" and we find it under


HKEY_LOCAL_MACHINE / System / CurrentControlSet / Control / POWER /
State / {98C5250D-C29A-4985-AE5F-AFE5367E5006} / <DEVICE_NAME>

The problem is that I've no adapter listed under any subkey of


HKEY_LOCAL_MACHINE / System / CurrentControlSet / Control / POWER

Doing a GetDevicePower on all devices I find under
HKEY_LOCAL_MACHINE / Drivers / Active
(even "NDS1:" whose PnpId refers to my Agere CF) with any of these GUID
PMCLASS_GENERIC_DEVICE = "{A32942B7-920C-486b-B0E6-92A702A99B35}";
PMCLASS_NDIS_MINIPORT = "{98C5250D-C29A-4985-AE5F-AFE5367E5006}";
PMCLASS_BLOCK_DEVICE = "{8DD679CE-8AB4-43c8-A14A-EA4963FAA715}";
PMCLASS_DISPLAY = "{EB91C7C9-8BF6-4a2d-9AB8-69724EED97D1}";
says the only ones I can poll are "NDS0:" and "COM4:" under
PMCLASS_GENERIC_DEVICE.
Maybe this is because my adapter is on a compact flash and not builtin.


So:
- what I've to pass to IOCTL_NPW_SAVE_POWER_STATE: "WLAGS46B", "WLAGS46B1"?
- what I've to pass to IOCTL_NDIS_GET_ADAPTER_BINDINGS: "WLAGS46B1"?


> I'm thinking that you'd be better off just getting the source code and
> reading it yourself

Yes I'll try hoping there are no relevant changes from my Windows CE .Net
4.2.


Moreover any call to DeviceIoControl return false to me!


I've attached the code I've used if someone wants to view it.


Yesterday I've solved all turn on/off problems using Psion Mobile SDK 1.8
libraries and RFID SDK 1.05 libraries.
It works even if I disable CF slot and not the adapter and even if this
works only for Psion handheld, while I was searching to make an almost
universal DLL but I think I'm not enough expert like you!
If someone needs a sample code tell me and I'll give you with all working
libraries included.

To turn off Bluetooth be aware of Psion Mobile SDK 1.9 and 2.0: they give an
exception and don't work!
Currently developers are trying to solve the problem and I'll tell you if
they will contact me.


Thank you all for any help and suggestion you gave me in the last weeks!!!

Luigi.


Paul G. Tobey [eMVP]

unread,
May 14, 2007, 12:15:13 PM5/14/07
to
As I said, this is all completely undocumented, so you get to figure it out
for yourself.

> So:
> - what I've to pass to IOCTL_NPW_SAVE_POWER_STATE: "WLAGS46B",
> "WLAGS46B1"?
> - what I've to pass to IOCTL_NDIS_GET_ADAPTER_BINDINGS: "WLAGS46B1"?

Try them both and see which works! If I were to guess, I'd say the name
with the instance number at the end, WLAGS46B1, would be the best choice.

>> I'm thinking that you'd be better off just getting the source code and
>> reading it yourself
> Yes I'll try hoping there are no relevant changes from my Windows CE .Net
> 4.2.

That deep internal code doesn't change much from version to version.

> Moreover any call to DeviceIoControl return false to me!

And what does GetLastError() return when that call fails? You've got to use
the information that the system is trying to give you to the maximum in
order to make some undocumented stuff work...

Paul T.


0 new messages