Dynamically Setting Wireless Settings

  • Thread starter Thread starter MoonLiver
  • Start date Start date
M

MoonLiver

A couple months ago I posted asking about how to change the wireless
settings dynamically. At the time it wasnt really possible. Has
anything changed? can we access this yet?

Recently we have found that our devices are connecting to the Panera
Bread Co network instead of our own, and this is causing havok. Help!

Tia,
B
 
What the heck is a Panera Bread Co network? You can adjust some of the
wireless settings via code found in OpenNETCF. There's no interface built
into the .NET CF from MS for this, though, no. What *specifically* are you
wanting to do?

Paul T.
 
Some vendors offer an API to control wireless settings from managed
code, if your vendor doesn't, you may be stuck managing this from
windows. Can you tell the device to only connect to preferred networks?
 
panera bread is a sandwich and soup shop that has free wifi. and we
keep connecting to it cause they are close, and oddly have a better
connection to thier network than our router that is 8ft away.

We are using the Dell Axim X50. We have talked to dell and they have
pretty much told us to shove it (and we bought 500 of them!) as far as
getting an api.

what I WANT to do is have the ability to set the wifi network settings
from code. worst case scenario I would like to disable baloon help and
set the 'preferred networks only' setting to true.

Tia,
B
 
Well, the preferred network only settings isn't something I've ever tried to
change programmatically, but, with suitable research into the source code
for the Windows Zero Config API, it may be there.

*What* WiFi settings? "The WiFi settings" doesn't mean anything. You want
to establish connection with a given unsecured access point? The access
point is secured using WEP, so you need to set both the SSID and the WEP
key(s)? You're using PEAP authentication? The name of the access point
changes regularly? Or you just want to run the program once to configure
the device, rather than doing it manually once per device?

Is there an icon in the system tray that you double-click on to get to
wireless settings? Does it show the list of SSID values that it can hear?
If so, the code in OpenNETCF will allow you to do some minimal programmatic
configuration of the wireless adapter. I'm sure that Dell won't tell you
because it's *not their API*. It's Microsoft's and is essentially
undocumented, except by the source code.

Paul T.
 
Hi Moonliver

Hope I'm not too late. I had the same problem some month ago, and after some
week of lonely desperation I got the right suggestion. Unfortunately, I'm
working with eVC++ 4.0 (that is, in the unmanaged world), then I can only
provide a snippet of C++ code. This is a function to set the preferred
connection with WPA-PSK. It is not real working code (it has been extracted
from a very complex class), but at least it compiles. Hope you can map WZC
calls it into OpenNETCF environment. If so, take care of the call to
WZCPassword2Key, required to translate the ASCII passphrase into a valid
network key (this was the right suggestion).

Best regards.

Marco


#include <eapol.h>
#include <wzcsapi.h>

#define MAXNETKEYCHARS 27
#define MAXSSIDCHARS 33

BOOL SetPreferredConnection (// Your adapter (e.g. CISCO1)
LPCTSTR pszAdapter,
// Your SSID (network name)
LPCTSTR pszSSID,
// Your WPA passphrase
LPCTSTR pszNetKey)
{
BOOL fOk = FALSE;

// Get current settings for this adapter.
wchar_t wszAdapter[64];
ZeroMemory (wszAdapter, sizeof(wszAdapter));
#ifdef _UNICODE
wcsncpy (wszAdapter, pszAdapter, SIZEOF(wszAdapter)-1);
#else
if (! MultiByteToWideChar (CP_ACP, 0, pszAdapter, -1,
wszAdapter, SIZEOF(wszAdapter)-1))
return fOk;
#endif
INTF_ENTRY intfEntry;
intfEntry.wszGuid = wszAdapter;
DWORD dwOutFlags;
DWORD dwStatus =
WZCQueryInterface (NULL, INTF_ALL, &intfEntry, &dwOutFlags);
if (dwStatus != ERROR_SUCCESS) return fOk;
if (intfEntry.nAuthMode < 0) intfEntry.nAuthMode = 0;
if (intfEntry.nInfraMode < 0) intfEntry.nInfraMode = 0;

// Allocate a new configuration list with a single entry.
WZC_802_11_CONFIG_LIST configList;
ZeroMemory (&configList, sizeof(configList));
configList.NumberOfItems = 1;
configList.Index = 0;
PWZC_WLAN_CONFIG pConfig = configList.Config;
pConfig->Length = sizeof(WZC_WLAN_CONFIG);

// Setup SSID.
char szSSID[MAXSSIDCHARS+1];
ZeroMemory (szSSID, sizeof(szSSID));
#ifdef UNICODE
if (! WideCharToMultiByte (CP_ACP, 0, pszSSID, -1,
szSSID, MAXSSIDCHARS, NULL, NULL))
return fOk;
#else
strncpy (szSSID, pszSSID, MAXSSIDCHARS);
#endif
pConfig->Ssid.SsidLength = strlen (szSSID);
memcpy (pConfig->Ssid.Ssid, szSSID, strlen (szSSID));

// Setup authentication mode and encryption type.
pConfig->AuthenticationMode = Ndis802_11AuthModeWPAPSK;
pConfig->Privacy = Ndis802_11Encryption2Enabled;
pConfig->EapolParams.bEnable8021x = TRUE;
pConfig->EapolParams.dwEapFlags = DEFAULT_EAPOL_STATE;
pConfig->EapolParams.dwEapType = DEFAULT_EAP_TYPE;

// Setup infrastructure mode.
pConfig->InfrastructureMode = Ndis802_11Infrastructure;

// Setup network key.
size_t ccNetKey = _tcslen (pszNetKey);
if (ccNetKey > MAXNETKEYCHARS) return fOk;
char szNetKey[MAXNETKEYCHARS+1];
ZeroMemory (szNetKey, sizeof(szNetKey));
#ifdef UNICODE
if (! WideCharToMultiByte (CP_ACP, 0, pszNetKey, -1,
szNetKey, MAXNETKEYCHARS, NULL, NULL))
return fOk;
#else
strncpy (szNetKey, pszNetKey, MAXNETKEYCHARS);
#endif

// TKIP pre-shared keys take 256 bit key (everything else is incorrect
// formatting).
// User can only enter either 64 HEX entries, or 8 to 63 ASCII entries
// (always converted to HEX format).
if (ccNetKey >= 8 && ccNetKey <= 63) {
WZCPassword2Key (pConfig, szNetKey);
ccNetKey = WZCCTL_MAX_WEPK_MATERIAL;
} else if (ccNetKey != 64) {
return fOk;
}
pConfig->KeyLength = ccNetKey;
pConfig->dwCtlFlags |= (WZCCTL_WEPK_PRESENT | WZCCTL_WEPK_XFORMAT);
if (pConfig->EapolParams.bEnable8021x)
pConfig->dwCtlFlags |= WZCCTL_ONEX_ENABLED;
BYTE chFakeKeyMaterial[] =
{0x56, 0x09, 0x08, 0x98, 0x4D, 0x08, 0x11, 0x66, 0x42, 0x03,
0x01, 0x67, 0x66};
for (size_t ccIndex = 0; ccIndex < WZCCTL_MAX_WEPK_MATERIAL; ccIndex++) {
pConfig->KeyMaterial[ccIndex] ^=
chFakeKeyMaterial[(7*ccIndex)%13];
}

// Apply new settings.
// The preferred configuration list will contain only the new entry.
intfEntry.rdStSSIDList.dwDataLen = sizeof(WZC_802_11_CONFIG_LIST);
intfEntry.rdStSSIDList.pData = (LPBYTE) &configList;
dwStatus = WZCSetInterface (NULL, INTF_PREFLIST, &intfEntry, NULL);
if (dwStatus == ERROR_SUCCESS) fOk = TRUE;
return fOk;
}
 
Wow man, thats awesome, thanks. At this time my budget/brain time cant
slap your code into a usable form, however I am anticipating a time
when I would be able to dedicate some time to this issue, likely in the
2nd 1/4 of 2k6 :P.

I'll give this to one of my guys to see if he can muddle me a program.

Thanks again,
B
 
easier than that

I think you can configure your WZC to disable fallback. This will force WZC to stay on the chosen SSID and not change to the next best thing. Also try moving some metal objects ( file cabinets, mirrors, etc.) against the wall near the offending WiFi source.

Jeff
 
Back
Top