Ejemplo n.º 1
0
/*
 *              internal bool m_nearby = false;
 *              internal bool m_preferred = false;
 *
 *              public bool IsNearby
 *              {
 *                      get { return m_nearby; }
 *              }
 *
 *              public bool IsPreferred
 *              {
 *                      get { return m_preferred; }
 *              }
 */
        internal AccessPoint(NDIS_WLAN_BSSID bssid)
        {
            name    = bssid.SSID;
            macaddr = bssid.MacAddress;
            privacy = bssid.Privacy;

            // see if the rssi is in the HIWORD or LOWORD
            uint ssi = (uint)bssid.Rssi;

            if (((ssi & 0xFFFF0000) > 0) && ((ssi & 0xffff) == 0))
            {
                // hiword
                rssi = bssid.Rssi >> 16;
            }
            else
            {
                // loword
                rssi = bssid.Rssi;
            }

            supportedrates     = bssid.SupportedRates;
            networktypeinuse   = bssid.NetworkTypeInUse;
            infrastructuremode = bssid.InfrastructureMode;

            // ToDo: For now, the configuration is not returned.
            //			configuration = bssid.Configuration;
        }
Ejemplo n.º 2
0
/*
		internal bool m_nearby = false;
		internal bool m_preferred = false;

		public bool IsNearby
		{
			get { return m_nearby; }
		}

		public bool IsPreferred
		{
			get { return m_preferred; }
		}
*/
		internal AccessPoint( NDIS_WLAN_BSSID bssid )
		{
			name = bssid.SSID;
			macaddr = bssid.MacAddress;
			privacy = bssid.Privacy;

			// see if the rssi is in the HIWORD or LOWORD
			uint ssi = (uint)bssid.Rssi;
			if(((ssi & 0xFFFF0000) > 0) && ((ssi & 0xffff) == 0 ))
			{
				// hiword
				rssi = bssid.Rssi >> 16;
			}
			else
			{
				// loword
				rssi = bssid.Rssi;
			}

			supportedrates = bssid.SupportedRates;
			networktypeinuse = bssid.NetworkTypeInUse;
			infrastructuremode = bssid.InfrastructureMode;

			// ToDo: For now, the configuration is not returned.
			//			configuration = bssid.Configuration;
		}
        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 = 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.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;
            WZC_WLAN_CONFIG_LIST cl = new WZC_WLAN_CONFIG_LIST(rd);

            // Step through the list and add a new AP to the
            // collection for each entry.
            for (int i = 0; i < cl.NumberOfItems; i++)
            {
                WZC_WLAN_CONFIG c = cl.Item(0);

                // Get a NDIS_WLAN_BSSID corresponding to the
                // part of the WZC_WLAN_CONFIG entry and use that
                // to build an AccessPoint instance for this
                // entry.
                NDIS_WLAN_BSSID bssid = c.ToBssid();

                // 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(bssid.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.
                        bssid.Rssi = ss;

                        // Create the AP instance and add it to the
                        // preferred list.
                        AccessPoint ap = new AccessPoint(bssid);
                        this.List.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(bssid);
                    this.List.Add(ap);
                }
            }
        }
        internal unsafe void RefreshList(Boolean clearCache)
        {
            // If we are to clear the driver's cache of SSID
            // values, call the appropriate method.
            //Console.WriteLine("Entering RefreshList");
            if (clearCache)
            {
                this.ClearCache();

                // This seems to be needed to avoid having
                // a list of zero elements returned.
                System.Threading.Thread.Sleep(1000);
            }

            this.List.Clear();

            // 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.
            uint dwBytesReturned       = 0;
            NDISUIO_QUERY_OID queryOID = new NDISUIO_QUERY_OID(6000 /* TESTING JFK was 2000 */);
            IntPtr            ndisAccess;
            bool retval;

            // Attach to NDISUIO.
            ndisAccess = FileEx.CreateFile(
                NDISUIOPInvokes.NDISUIO_DEVICE_NAME,
                FileAccess.All,
                FileShare.None,
                FileCreateDisposition.OpenExisting,
                NDISUIOPInvokes.FILE_ATTRIBUTE_NORMAL | NDISUIOPInvokes.FILE_FLAG_OVERLAPPED);
            if ((int)ndisAccess == FileEx.InvalidHandle)
            {
                Console.WriteLine("Attach to NDISUIO Failed");
                // The operation failed.  Leave us empty.
                return;
            }

            // Get Signal strength
            byte[] namestr = System.Text.Encoding.Unicode.GetBytes(adapter.Name + '\0');
            fixed(byte *name = &namestr[0])
            {
                // Get Signal strength
                queryOID.ptcDeviceName = name;
                queryOID.Oid           = NDISUIOPInvokes.OID_802_11_BSSID_LIST;       // 0x0D010217

                retval = NDISUIOPInvokes.DeviceIoControl(ndisAccess,
                                                         NDISUIOPInvokes.IOCTL_NDISUIO_QUERY_OID_VALUE, // 0x00120804
                                                         queryOID,
                                                         queryOID.Size,
                                                         queryOID,
                                                         queryOID.Size,
                                                         ref dwBytesReturned,
                                                         IntPtr.Zero);
            }

            if (retval)
            {
                // Now we need to parse the incoming data into
                // suitable representations of the SSIDs.

                // Figure out how many SSIDs there are.
                NDIS_802_11_BSSID_LIST rawlist = new NDIS_802_11_BSSID_LIST(queryOID.Data);

                for (int i = 0; i < rawlist.NumberOfItems; i++)
                {
                    // Get the next raw item from the list.
                    NDIS_WLAN_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.
                    this.List.Add(ssid);
                }
            }
            else
            {
                // We might just need more room.
                // For now, we just leave the list empty.
                // ToDo: Additional error processing.
                Console.WriteLine("ERROR Buffer Too Small");                //You'll notice here there should be some sort of error contol but there isn't.
                //We simply don't have enough room.
            }
        }