private void GetNDISAPs() { // Retrieve a list of NDIS_802_11_BSSID_LIST // structures from the driver. We'll parse that // list and populate ourselves based on the data // that we find there. string name = m_adapter.Name; byte[] data = NDISUIO.QueryOID(NDIS_OID.BSSID_LIST, name); if (data != null) { // Figure out how many SSIDs there are. NDIS_802_11_BSSID_LIST rawlist = new NDIS_802_11_BSSID_LIST(data, false); for (int i = 0; i < rawlist.NumberOfItems; i++) { // Get the next raw item from the list. BSSID bssid = rawlist.Item(i); // Using the raw item, create a cooked // SSID item. AccessPoint ssid = new AccessPoint(bssid); // Add the new item to this. m_aps.Add(ssid); } } else { throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error(), "Unable to get BSSID List"); } }
public void ToStringReturnsSSID() { BSSID bssid = GetBSSID(); AccessPoint target = new AccessPoint(bssid); Assert.AreEqual <string>(bssid.SSID, target.ToString(), "ToString() method did not return SSID"); }
public bool Contains(AccessPoint accessPoint) { if (accessPoint == null) { throw new ArgumentNullException(); } return(m_aps.Contains(accessPoint)); }
public void ConstructorWithNullBSSID() { ArgumentNullException caughtException = null; try { AccessPoint accessPoint = new AccessPoint((WLANConfiguration)null); } catch (ArgumentNullException ex) { caughtException = ex; } Assert.IsNotNull(caughtException, "AccessPoint did not throw ArgumentNullException when null BSSID was passed"); }
internal static List <IAccessPoint> GetAPs(string adapterName) { var apList = new List <IAccessPoint>(); INTF_ENTRY entry = new INTF_ENTRY(); entry.Guid = adapterName; INTF_FLAGS flags = 0; int result = WZCQueryInterface(null, INTF_FLAGS.INTF_ALL, ref entry, out flags); if (result != 0) { entry.Dispose(); throw new Exception("WZCQueryInterface failed for " + adapterName); } try { // Figure out how many SSIDs there are. if (entry.rdBSSIDList.cbData == 0) { // list is empty return(apList); } NDIS_802_11_BSSID_LIST rawlist = new NDIS_802_11_BSSID_LIST(entry.rdBSSIDList.lpData, true); for (int i = 0; i < rawlist.NumberOfItems; i++) { // Get the next raw item from the list. BSSID bssid = rawlist.Item(i); // Using the raw item, create a cooked // SSID item. AccessPoint ssid = new AccessPoint(bssid); // Add the new item to this. apList.Add(ssid); } return(apList); } finally { WZCDeleteIntfObj(ref entry); } }
public void ConstructorPositive() { BSSID bssid = GetBSSID(); AccessPoint target = null; Exception caughtException = null; try { target = new AccessPoint(bssid); } catch (Exception ex) { caughtException = ex; } Assert.IsNull(caughtException, "Constructor threw exception. AccessPoint was not constructed successfully"); }
/// <summary> /// Determines if two access points are the same based on a MAC/Name comparison /// </summary> /// <param name="obj"></param> /// <returns></returns> public override bool Equals(object obj) { AccessPoint ap = obj as AccessPoint; if (ap == null) { return(false); } if (!ap.PhysicalAddress.Equals(this.PhysicalAddress)) { return(false); } // check the name, just in case they've MAC spoofed. Sure, they could be named the same too, but it's one more layer of checking if (ap.Name != this.Name) { return(false); } return(true); }
/// <summary> /// Removes a network from the adapter's preferred list /// </summary> /// <param name="SSID">The SSID of the network to remove</param> public bool RemovePreferredNetwork(AccessPoint ap) { return(RemovePreferredNetwork(ap.Name)); }
public void ConstructorSetProperties() { BSSID bssid = GetBSSID(); AccessPoint target = new AccessPoint(bssid); int expectedChannel = GetExpectedFrequency(bssid); int expectedDecibel = GetExpectedDecibel(bssid); //Channel is set correctly Assert.AreEqual <int>(expectedChannel, target.Channel, "AccessPoint did not return expected Channel"); //InfrastructureMode is set correctly Assert.AreEqual <InfrastructureMode>(bssid.InfrastructureMode, target.InfrastructureMode, "AccessPoint did not return expected InfrastructureMode"); //Name is set correctly Assert.AreEqual <string>(bssid.SSID, target.Name, "AccessPoint did not return expected Name"); //MacAddress is set correctly Assert.AreEqual <int>(bssid.MacAddress.Length, target.PhysicalAddress.GetAddressBytes().Length, "AccessPoint did not return expected length for PhysicalAddress address length"); bool addressByteMismatch = false; byte[] addressByteArray = target.PhysicalAddress.GetAddressBytes(); for (int loopVariable = 0; loopVariable < bssid.MacAddress.Length; loopVariable++) { if (bssid.MacAddress[loopVariable] != addressByteArray[loopVariable]) { addressByteMismatch = true; break; } } Assert.IsFalse(addressByteMismatch, "AccessPoint did not return expected macaddress bytes"); //NetworkTypeInUse is set correctly Assert.AreEqual <NetworkType>(bssid.NetworkTypeInUse, target.NetworkTypeInUse, "AccessPoint did not return expected NetworkTypeInUse"); //Privacy is set correctly Assert.AreEqual <WEPStatus>((WEPStatus)bssid.Privacy, target.Privacy, "AccessPoint did not return expected Privacy"); //SignalStrength is set correctly Assert.AreEqual <int>(expectedDecibel, target.SignalStrength.Decibels, "AccessPoint did not return expected Decibels"); //SignalStrengthInDecibels is set correctly Assert.AreEqual <int>(expectedDecibel, target.SignalStrengthInDecibels, "AccessPoint did not return expected SignalStrengthInDecibels"); //SupportedRates is set correctly List <int> validRatesList = new List <int>(); for (int loopVariable = 0; loopVariable < bssid.SupportedRates.Length; loopVariable++) { if (bssid.SupportedRates[loopVariable] > 0) { validRatesList.Add(bssid.SupportedRates[loopVariable] * 500); } } Assert.AreEqual <int>(validRatesList.Count, target.SupportedRates.Length, "AccessPoint did not return the correct count of valid supportedrates"); bool supportedRateByteMismatch = false; int[] supportedRates = target.SupportedRates; for (int loopVariable = 0; loopVariable < validRatesList.Count; loopVariable++) { if (validRatesList[loopVariable] != supportedRates[loopVariable]) { supportedRateByteMismatch = true; break; } } Assert.IsFalse(supportedRateByteMismatch, "AccessPoint did not return expected supportedrates bytes"); }
internal unsafe void RefreshListPreferred(bool nearbyOnly) { // If the caller wants only the local preferred APs, // we check nearby list and, if the AP is not there, // we don't add it to our own preferred list. AccessPointCollection apc = null; if (nearbyOnly) { apc = m_adapter.NearbyAccessPoints; } // First step is to get the INTF_ENTRY for the adapter. // This includes the list of preferred SSID values. INTF_ENTRY ie = INTF_ENTRY.GetEntry(this.m_adapter.Name); // The field rdStSSIDList is the preferred list. It comes // in the form of a WZC_802_11_CONFIG_LIST. RAW_DATA rd = ie.rdStSSIDList; WLANConfigurationList cl = new WLANConfigurationList(rd); // Step through the list and add a new AP to the // collection for each entry. for (int i = 0; i < cl.NumberOfItems; i++) { WLANConfiguration c = cl.Item(i); //Debug.WriteLine(c.SSID); //for (int d = 1; d <= c.Data.Length; d++) //{ // Debug.Write(string.Format("{0:x2}{1}", c.Data[d - 1], (d%8 == 0) ? "\r\n" : " ")); //} //Debug.WriteLine(string.Empty); // If we're only showing those which we can hear, // see if the current SSID is in the nearby list. if (nearbyOnly) { // Find the currently active AP with the SSID // to match the one we're working on. AccessPoint activeAP = apc.FindBySSID(c.SSID); int ss; // If the given SSID is not in range, don't add // an entry to the list. if (activeAP != null) { // Update signal strength. ss = activeAP.SignalStrengthInDecibels; // Copy the signal strength value to the // NDIS_WLAN_BSSID structure for the // preferred list entry. c.Rssi = ss; // Create the AP instance and add it to the // preferred list. AccessPoint ap = new AccessPoint(c); m_aps.Add(ap); } } else { // Create the AP instance and add it to the // preferred list. The signal strength will // not necessarily be valid. AccessPoint ap = new AccessPoint(c); m_aps.Add(ap); } } // Dispose of INTF_ENTRY ie.Dispose(); }
void m_stateMachine_APInRange(OpenNETCF.Net.NetworkInformation.AccessPoint ap) { View.AddNearbyAP(ap); }
void m_stateMachine_APOutOfRange(OpenNETCF.Net.NetworkInformation.AccessPoint ap) { View.RemoveNearbyAP(ap); }