public void ConstructorSetsProperties() { WirelessZeroConfigNetworkInterface wirelessZeroConfigNI = new WirelessZeroConfigNetworkInterface(0, "Config1"); AccessPointCollection target = new AccessPointCollection(wirelessZeroConfigNI, false); Assert.AreEqual <WirelessZeroConfigNetworkInterface>(wirelessZeroConfigNI, target.AssociatedAdapter, "Constructor did not set AssociatedAdapter property correctly"); }
public void ConstructorWithNullBSSID() { ArgumentNullException caughtException = null; try { AccessPointCollection target = new AccessPointCollection(null); } catch (ArgumentNullException ex) { caughtException = ex; } Assert.IsNotNull(caughtException, "AccessPointCollection did not throw ArgumentNullException when null WirelessZeroConfigNetworkInterface was passed"); }
public void ConstructorValidWirelessZeroConfigNetworkInterface() { WirelessZeroConfigNetworkInterface wirelessZeroConfigNI = new WirelessZeroConfigNetworkInterface(0, "Config1"); AccessPointCollection target = null; Exception caughtException = null; try { target = new AccessPointCollection(wirelessZeroConfigNI); } catch (Exception ex) { caughtException = ex; } Assert.IsNull(caughtException, "Constructor threw exception. AccessPointCollection was not constructed successfully"); }
public void PreferredOpenInfrastructureAPTest(WirelessZeroConfigNetworkInterface wzc) { List <string> preferredAPs = new List <string>(); // get a list of available adapters INetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces(); if (interfaces.Length <= 0) { Assert.Fail("No interfaces available to test"); } bool wzcFound = false; // find the WZC adapter foreach (INetworkInterface intf in interfaces) { if (intf is WirelessZeroConfigNetworkInterface) { // run the test wzcFound = true; // get a list of preferred APs foreach (NI.AccessPoint ap in wzc.PreferredAccessPoints) { preferredAPs.Add(ap.Name); } // remove them all foreach (string ssid in preferredAPs) { if (!wzc.RemovePreferredNetwork(ssid)) { Assert.Fail("Failed to remove AP " + ssid); } } // make sure the list really got emptied if (wzc.PreferredAccessPoints.Count > 0) { Assert.Fail("Failed to drop all preferred APs"); } // make sure we have a nearby AP NI.AccessPointCollection nearbyAPs = wzc.NearbyAccessPoints; if (nearbyAPs.Count <= 0) { // try twice, in case the adapter was not initialized System.Threading.Thread.Sleep(100); nearbyAPs = wzc.NearbyAccessPoints; if (nearbyAPs.Count <= 0) { Assert.Fail("No nearby APs found"); } } bool nearbyFound = false; List <string> nearbyNames = new List <string>(); foreach (NI.AccessPoint ap in nearbyAPs) { if (nearbyNames.Contains(ap.Name)) { // we can't add two APs with the same name (and different physical addresses) continue; } nearbyNames.Add(ap.Name); if (ap.InfrastructureMode == NI.InfrastructureMode.Infrastructure) { if (ap.Privacy == 0) { // we have found an open, infrastructure AP nearbyFound = true; if (!wzc.AddPreferredNetwork(ap.Name, false, null, 1, NI.AuthenticationMode.Open, NI.WEPStatus.WEPDisabled, null)) { Assert.Fail("Failed to add AP named " + ap.Name); } } } } if (!nearbyFound) { Assert.Fail("No nearby APs found"); } // now remove them all again (to ensure we've actually removed something - we could have started with none) preferredAPs.Clear(); // get a list of preferred APs foreach (NI.AccessPoint ap in wzc.PreferredAccessPoints) { preferredAPs.Add(ap.Name); } // remove them all foreach (string ssid in preferredAPs) { if (!wzc.RemovePreferredNetwork(ssid)) { Assert.Fail("Failed to remove AP " + ssid); } } Assert.IsTrue(wzc.PreferredAccessPoints.Count == 0, "Failed to remove all preferred APs"); break; } } if (!wzcFound) { Assert.Fail("No WZC Adapter found"); } }
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(); }