Wednesday, February 02, 2011

Developing a Windows Networking Driver to Keep a Computer from Connecting to Different WiFi Networks



When you connect to your wireless LAN (this is a standard term for local area network), you'll see a long list of nearby networks. Occasionally your computer on its own might actually connect to a network other than yours. There is always an unsecured network available in the air wherever you go, making a random connection possible.

It'll be good to just block out all but your own network from even showing up in the list of wireless networks, or at least making sure that you are only connecting to your own network. With a few exceptions, people don't really need to see all the networks around them, and definitely don't want to connect to them - just your own. So, I'm looking into writing some Windows code that will do this - possibly a networking driver. I downloaded the Windows Device Driver Kit (DDK) and started looking through the documentation.

Before long I came across this:
The msDot11DesiredSSIDList MIB object specifies the list of 802.11 service set identifiers (SSIDs) that the 802.11 station uses when connecting to a basic service set (BSS) network. After OID_DOT11_CONNECT_REQUEST is set, the 802.11 station will attempt to connect to a BSS with an service set identifier (SSID) that matches an entry from this list.

That sounds like if we could set the msDot11DesiredSSIDList with only your own network name, then the networking drivers would only connect to your network. Now just need to see how that could be set. Looking further I also found a regular Windows API that might be able to control WiFi connections. Here's what the Microsoft documentation says:

The Wireless LAN Win32 API enables developers to build applications that manage wireless adapters, wireless connections, and wireless profiles. The APIs consist of the following functionalities:

Operational API: Applications can request the adapter to scan, connect/disconnect to/from a wireless network and query attributes of the current connection. (etc...)

So those are two possible leads I've found so far. On the 2nd one - the Wireless LAN API - it turns out there is a Microsoft SDK sample program (called "wlsample") that shows you how to retrieve the name of the current WiFi network you are connected to, as well as how to disconnect from the current network. With some additional logic this could monitor which network you are connected to and promptly disconnect you if you happen to connect to the wrong one. It could then attempt to re-connect to your approved network. This could be run as a Windows Service that starts up and runs in the background.

Update: Now I've got the program working that detects if I'm on the wrong network, but I need to turn it into a Windows service that starts automatically when Windows boots, and keeps running. Looks like there are multiple paths to developing a service. Here are my leading candidates:
  • From a pure C example in the SDK that uses Win32 APIs directly
  • From a C++ example based on the CAtlServiceModule
  • From a C# example generated from a Visual Studio "Windows Service" project template.
The code for the C# example is the simplest, and the C example is probably the most complex, with the C++ example somewhere in between. The code I've written so far is in C and would need some work to convert to C#. So I'm debating which one to go with. I may start with the C example and see how it goes.

1 comments:

david said...

hello is this still open ?

Post a Comment

Note: Only a member of this blog may post a comment.