OpenNETCF and SetWirelessSettings

K

Kent Briggs

I can't get SetWirelessSettings() to work on my Dell Axim x51 to connect
to a specific access point called WGN. It fires off this exception each
time:

ArgumentOutOfRangeException
at System.Runtime.InteropServices.Marshal.CopyInternal()
at OpenNETCF.Net.WLANConfigurationList.Item()
at OpenNETCF.Net.Adapter.SetWirelessSettings()

My VB 2005 code does this:

Private Sub BindWGNBtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BindWGNBtn.Click
Dim MyAdapter As OpenNETCF.Net.Adapter
Dim MyAdapters As OpenNETCF.Net.AdapterCollection
MyAdapters = Networking.GetAdapters
Dim n As Integer = MyAdapters.Count
If n = 0 Then
MsgBox("No network adapter currently active. Turn WiFi on.")
Exit Sub
End If
Dim i As Integer
For i = 0 To n - 1
MyAdapter = MyAdapters.Item(i)
If MyAdapter.IsWireless Then
MyAdapter.SetWirelessSettings("WGN")
MyAdapter.RebindAdapter()
End If
Next
End Sub


What am I doing wrong here? By the way, I have no problem manually
connecting to that access point (a wireless LinkSys router) using the
Dell WLAN utility.
 
P

Paul G. Tobey [eMVP]

And can we assume that the AP is open, unsecured, and that it's in the list
of preferred APs for the adapter to which you're making that call? I've
tried this with the latest 1.4 build and it works perfectly on my test
device. It moves the indicated SSID value to the top of the list of
preferred SSID values. You did read the help for that method, right?

/// <summary>

/// Attaches to an existing SSID value which *must* already be

/// on the preferred list. Settings are copied from when the

/// AP was added to the preferred list. This allows you to

/// connect to a preconfigured SSID value without respecifying

/// the WEP key, etc.

/// </summary>

/// <param name="SSID">Target SSID to connect</param>

/// <returns>true if succeeded</returns>


Paul T.
 
K

Kent Briggs

Paul said:
And can we assume that the AP is open, unsecured, and that it's in the list
of preferred APs for the adapter to which you're making that call? I've
tried this with the latest 1.4 build and it works perfectly on my test
device. It moves the indicated SSID value to the top of the list of
preferred SSID values. You did read the help for that method, right?

I'm using the OpenNETCF 2.0 build. I'm not sure what constitutes a
preferred AP on the Axim x51. When I add an AP, there's no option to
make it "preferred". But it shows up in my list. But so do some of my
neighbor's wireless routers, which is the problem. My AP is secured, but
the key has already been entered and I can connect manually using Dell's
WLAN utility.

In any case, the function should just return "false" if it couldn't
connect, not fire an exception, right?

The online help at www.opennetcf.org/library for SetWirelessSettings
only says this:

------------------------------
Parameters

SSID
Target SSID to connect
bInfrastructure
Is infrastructure
Key
binary wep key - 5 or 13 bytes
Return Value
true if succeeded
 
P

Paul G. Tobey [eMVP]

You have to look at the normal UI for wireless. You can specify SSID A and
B and set up their WEP values, or other security and authentication
settings. Once you do that, they are in the preferred list. You cannot use
the method you are trying to use there *unless* you've already done that,
which is what is distinct between your AP, which it sounds like is in the
list, and the neighbors'. "Preferred" has nothing to do with what is
currently in range, the list on which your neighbors' devices show. The
method you are using brings the indicated AP to the top of the preferred
list, which is ordered based on which SSIDs you want to connect to most.

I don't have an Axim, so I can't tell you what might be going on. If you
have the source, you can trace into it to find where the exception is thrown
and that might tell us something. If the Axim is running a customized
version of WZC, you may not be able to use the Adapter class to control its
wireless settings.

I wasn't directly involved in the build of 2.0, so it's possible that the
latest code wasn't used or the help is out of date. You are using the
*released* or the beta 2.0 build, binary presumably?

Paul T.
 
K

Kent Briggs

Paul said:
You have to look at the normal UI for wireless. You can specify SSID A and
B and set up their WEP values, or other security and authentication
settings.

I don't see an A or B setting in the Dell WLAN utility but I now see a
Config tab and it does show my AP in the "Pref SSId" box. I guess the
last selected AP gets put there automatically, I don't know.

I don't have an Axim, so I can't tell you what might be going on. If you
have the source, you can trace into it to find where the exception is thrown
and that might tell us something. If the Axim is running a customized
version of WZC, you may not be able to use the Adapter class to control its
wireless settings.

I came across a thread titled "AccessPointCollection Problem??"
(05/01/2006) in the .Net section of the OpenNETCF.org forums. Someone
reported the same ArgumentOutOfRangeException exception and someone
replied that it looked like a bug: "--> copying 196 bytes to an array
with size of 180 will not work --> ArgumentOutOfRangeException". Are the
developers aware of this?

I wasn't directly involved in the build of 2.0, so it's possible that the
latest code wasn't used or the help is out of date. You are using the
*released* or the beta 2.0 build, binary presumably?

I assume it's the released version. I just got it last week from the
www.opencfnet.org site.
 
G

Guest

SDF 2.0 is using the same as the latest SDF 1.4 source for the Adapter
class.

-Chris


"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:%[email protected]...
You have to look at the normal UI for wireless. You can specify SSID A
and B and set up their WEP values, or other security and authentication
settings. Once you do that, they are in the preferred list. You cannot
use the method you are trying to use there *unless* you've already done
that, which is what is distinct between your AP, which it sounds like is
in the list, and the neighbors'. "Preferred" has nothing to do with what
is currently in range, the list on which your neighbors' devices show.
The method you are using brings the indicated AP to the top of the
preferred list, which is ordered based on which SSIDs you want to connect
to most.

I don't have an Axim, so I can't tell you what might be going on. If you
have the source, you can trace into it to find where the exception is
thrown and that might tell us something. If the Axim is running a
customized version of WZC, you may not be able to use the Adapter class to
control its wireless settings.

I wasn't directly involved in the build of 2.0, so it's possible that the
latest code wasn't used or the help is out of date. You are using the
*released* or the beta 2.0 build, binary presumably?

Paul T.
 
P

Paul G. Tobey [eMVP]

A or B would be examples of SSIDs, not things that appear on all devices.
When you connect to any SSID, "A", "B", or whatever the one you're
connecting to is called, it's added to the preferred list. Your
configuration program is clearly Dell-specific. That doesn't necessarily
mean that it will fail, but it certainly could cause that. Was the bug
report for an Axim, as well?

No, I haven't heard about anything recently. I rearchitected the
SetWirelessSettings group of methods and added support for EAP control in
February.

No, release just occurred this week. Doesn't mean that it has changed, of
course, but it might have.

Paul T.
 
P

Paul G. Tobey [eMVP]

It appears to me to be specific to the target hardware. My own hardware
with Cisco has no problem with this OP's code. I see no reason not to set
it to 196 (or anything else in particular). Ideally, the code would be
tolerant of any size packet being copied. For now, I've changed it to 196
in the vault.

Paul T.

I'll log it as a bug and see if I can track it down.

-Chris
 
K

Kent Briggs

Paul said:
No, release just occurred this week.

I see the "Extensions for VS" were released yesterday but the 2.0
framework itself must have been out before that because there was no
beta indication on the copy I downloaded last week.
 
K

Kent Briggs

Paul said:
You may be able to just get the file to compile into your project and
supersede the one in the binary distribution. I've tried to attach
it, in ZIP form.

I'm not sure how to compile that cs file. My project is in vb.
 
P

Paul G. Tobey [eMVP]

That, as it turns out, is irrelevant. One of the nice capabilities of the
managed code scheme is that you can freely mix and match development
languages. If you add a .cs file to your project, it gets compiled just
like a .vb file does.

Paul T.
 
K

Kent Briggs

Paul said:
That, as it turns out, is irrelevant. One of the nice capabilities of the
managed code scheme is that you can freely mix and match development
languages. If you add a .cs file to your project, it gets compiled just
like a .vb file does.

How do I do that exactly? With my VB project loaded, I can select
Project/Add_Existing_Item, and select the Adapter.cs file, but it just
adds it as a text file to my VB project. If I change the Build Action to
"Compile" then it just generates syntax errors on every line since it's
expecting VB code.
 
P

Paul G. Tobey [eMVP]

Yes, generally you'd do this by making a C# ClassLibrary project to be added
to your workspace for the program. In this case, however, there are
internal classes which the Adapter.cs file can't access when compiled
outside of the namespace where it was designed to go. As I said, I wasn't
sure that it would work. Other than getting the source or waiting for the
next update of the binaries, I don't see a solution. Maybe someone who
knows more about the VS build system can recommend a way to get around
this...

Paul T.
 
K

Kent Briggs

Paul said:
Other than getting the source or waiting for the
next update of the binaries, I don't see a solution.

Any idea when the next binaries will be released?
 
G

Guest

Since we just did a release this week, it will probably be at least a month
before we do another release. If you get the source you can always make the
change manually.
 
K

Kent Briggs

Since we just did a release this week, it will probably be at least a month
before we do another release. If you get the source you can always make the
change manually.

All right, you talked me into it. I just ordered the $50 license. ;-)
 
K

Kent Briggs

Paul said:
Other than getting the source or waiting for the
next update of the binaries, I don't see a solution.

Paul,

I purchased the SDF 2.0 Extensions license and got the full source code
today which I can rebuild as-is without any errors. However, if I
substitute in your Adapter.cs file, the rebuild fails starting with this
error:

Error 681 The namespace 'OpenNETCF.Net' already contains a definition
for 'IP_ADAPTER_INFO' C:\Program Files\OpenNETCF\Smart Device
Framework 2.0\Source\OpenNETCF.Net\Adapter.cs 104 17 OpenNETCF.Net

The Adapter.cs file that was included in the SDF 2.0 Extensions is 74575
bytes and has a 2006 copyright date at the top. Your file is 99559 bytes
and still shows a 2003 copyright date. Why are these so different?
 
G

Guest

We've refactored the files in SDF 2.0, so the change is in a different
location - a file replacement won't work.

-Chris
 
K

Kent Briggs

We've refactored the files in SDF 2.0, so the change is in a different
location - a file replacement won't work.

Ok, I see this line at the end of WLANConfiguration.cs:

internal const int SizeOf = 180;

Would just changing 180 to 196 fix that problem?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

WM2005 Wireless 8
Exception with OpenNETCF ? 14
wifi info 3
OpenNetCF 2.2 changes 7
OpenNETCF AnimateCtl 0
GetHostEntry 8
Image Flicker 2
Register HotKey 0

Top