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

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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);
}


.



Relevant Pages

  • Enable network adapter and BindAdapter exceptions.
    ... setting a bit in the registry for the target adapter and then calling NDIS ... To do a NDIS bind or NDIS unbind you can use these API: ... ref string wszAdapterInstanceName, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: [DESPERATE] Turn on/off Bluetooth, WiFi and an RFID tag reader.
    ... 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 ... ref string wszAdapterInstanceName, ...
    (microsoft.public.windowsce.app.development)
  • Re: OpenNETCF SetWirelessSettings
    ... "8 character hex string" sounds like something along the lines of ... to actually tell us what the WEP key you enter at the WZC dialog is and what ... // be storing Next pointers from adapter information ... /// encapsulates the SSID raw binary ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: UDP question.
    ... >> My two adapters has two different IP address, and I bind one IP ... >> do you mean that I alloc two socket and bind different IP is not ... > sending a packet *to* 1.2.4.5, it will go out the first interface. ... not real bind the adapter? ...
    (Linux-Kernel)
  • Re: My Brain Hurts - Help
    ... 'Type is: String. ... the adapter ... "Bernie Yaeger" wrote in message ... > Hi Siv, ...
    (microsoft.public.dotnet.languages.vb)