示例#1
0
        public static int QueryAdapter(string adapterName, out INTF_ENTRY entry)
        {
            // Attempt to get the status of the indicated
            // interface by calling WZCQueryInterface.  If
            // it works, we return true; if not, false.
            // Note that the first parameter, the WZC server,
            // is set to null, apparently indicating that the
            // local machine is the target.
            entry = new INTF_ENTRY();
            INTF_FLAGS flags = 0;

            entry.Guid = adapterName;
            int retVal = 0;

            try
            {
                retVal = WZC.WZCQueryInterface(null, INTF_FLAGS.INTF_ALL, ref entry, out flags);
            }
            catch (Exception ex)
            {
                // on a throw, the return value needs to get set to a non-zero
                try
                {
                    WZC.WZCDeleteIntfObj(ref entry);
                }
                catch { }
                return(-1);
            }

            return(retVal);
        }
示例#2
0
        /// <summary>
        /// Creates a new entry with given name in memory
        /// </summary>
        /// <param name="guid">Name</param>
        /// <returns>Entry</returns>
        public static INTF_ENTRY GetEntry(string guid)
        {
            INTF_ENTRY entry = new INTF_ENTRY();

            entry.Guid = guid;
            INTF_FLAGS dwOutFlags;
            int        uret = WZC.WZCQueryInterface(null, INTF_FLAGS.INTF_ALL, ref entry, out dwOutFlags);

            if (uret > 0)
            {
                throw new NetworkInformationException(uret);
            }
            return(entry);
        }
示例#3
0
        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);
            }
        }
示例#4
0
        public object Clone()
        {
            INTF_ENTRY entry = (INTF_ENTRY)MemberwiseClone();

            entry.rdBSSID.Clear();
            entry.rdBSSIDList.Clear();
            entry.rdCtrlData.Clear();
            entry.rdSSID.Clear();
            entry.rdStSSIDList.Clear();
            entry.rdBSSID.lpData      = this.rdBSSID.lpData;
            entry.rdBSSIDList.lpData  = this.rdBSSIDList.lpData;
            entry.rdCtrlData.lpData   = this.rdCtrlData.lpData;
            entry.rdSSID.lpData       = this.rdSSID.lpData;
            entry.rdStSSIDList.lpData = this.rdStSSIDList.lpData;
            return(entry);
        }
示例#5
0
 public static int SetAdapter(INTF_ENTRY entry, INTF_FLAGS flags)
 {
     return(WZC.WZCSetInterface(null, flags, ref entry, null));
 }
示例#6
0
 WZCDeleteIntfObj(
     ref INTF_ENTRY Intf);
示例#7
0
 WZCSetInterface(
     string pSrvAddr,
     INTF_FLAGS dwInFlags,
     ref INTF_ENTRY pIntf,
     object pdwOutFlags);
示例#8
0
 WZCQueryInterface(
     string pSrvAddr,
     INTF_FLAGS dwInFlags,
     ref INTF_ENTRY pIntf,
     out INTF_FLAGS pdwOutFlags);
示例#9
0
        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();
        }