示例#1
0
        public override Task <GenericMessage> Scan(Wifistuff.WlanInterface request, ServerCallContext context)
        {
            GenericMessage      result     = new GenericMessage();
            WlanNotifSubscriber subscriber = new WlanNotifSubscriber()
            {
                InterfaceGuid = Guid.Parse(request.InterfaceGuid)
            };
            // subscriber._interfaceGuid = Guid.Parse(request.InterfaceGuid);
            //Get the interface matching the one described by the request (Guid should match)
            WlanInterface wlanInterface = GetWlanInterfaceById(request.InterfaceGuid);

            wlanInterface.WlanNotification += subscriber.WlanNotificationChanged;
            try
            {
                wlanInterface.Scan();
                while (subscriber.ScanSuccessful == null)
                {
                }

                result.Result  = (bool)subscriber.ScanSuccessful;
                result.Message = subscriber.LastFailReason;
            }
            catch (Exception e)
            {
                subscriber.ScanSuccessful = false;
                subscriber.LastFailReason = e.Message;
            }

            wlanInterface.WlanNotification -= subscriber.WlanNotificationChanged;
            return(Task.FromResult(result));
        }
示例#2
0
 public static Wifistuff.WlanInterface Translate(WlanInterface wlanInterface)
 {
     Wifistuff.WlanInterface result = new Wifistuff.WlanInterface
     {
         State = (Wifistuff.WlanInterface.Types.WlanInterfaceState)Enum.Parse(typeof(WlanInterfaceState),
                                                                              wlanInterface.InterfaceState.ToString())
     };
     return(result);
 }
示例#3
0
        public static JAccessPoint Translate(AccessPoint thisAp)
        {
            WlanInterface        wlanInterface = thisAp.GetFieldValue <WlanInterface>("_interface");
            WlanAvailableNetwork network       = thisAp.GetFieldValue <WlanAvailableNetwork>("_network");
            JAccessPoint         customAp      = new JAccessPoint
            {
                //TODO: Figure out why this line is so damn costly (and maybe replace it with interface Guid)
                InterfaceName            = wlanInterface.InterfaceName,
                Name                     = thisAp.Name,
                SignalStrength           = (int)thisAp.SignalStrength,
                AuthAlgorithm            = Enum.GetName(typeof(Dot11AuthAlgorithm), network.dot11DefaultAuthAlgorithm),
                CipherAlgorithm          = Enum.GetName(typeof(Dot11CipherAlgorithm), network.dot11DefaultCipherAlgorithm),
                BssType                  = Enum.GetName(typeof(Dot11BssType), network.dot11BssType),
                Connectable              = network.networkConnectable,
                WlanNotConnectableReason = Enum.GetName(typeof(WlanReasonCode), network.wlanNotConnectableReason)
            };

            return(customAp);
        }
示例#4
0
        /// <summary>
        /// Grabs the access points seen ONLY by this interface. This is essentially just <see cref="Wifi.Scan"/>
        /// but without the interface iteration.
        /// </summary>
        /// <param name="wlanIface"></param>
        /// <param name="wifiInstance"></param>
        /// <param name="bRescan"></param>
        /// <returns></returns>
        public static List <AccessPoint> GetAccessPoints(this WlanInterface wlanIface, Wifi wifiInstance,
                                                         bool bRescan = true)
        {
            List <AccessPoint> accessPoints = new List <AccessPoint>();

            if (wifiInstance.NoWifiAvailable)
            {
                return(accessPoints);
            }

            if (bRescan && (DateTime.Now - wifiInstance.GetFieldValue <DateTime>("_lastScanned") >
                            TimeSpan.FromSeconds(60)))
            {
                wifiInstance.Scan();
            }

            WlanAvailableNetwork[]      rawNetworks = wlanIface.GetAvailableNetworkList(0);
            List <WlanAvailableNetwork> networks    = new List <WlanAvailableNetwork>();

            // Remove network entries without profile name if one exist with a profile name.
            foreach (WlanAvailableNetwork network in rawNetworks)
            {
                bool hasProfileName = !string.IsNullOrEmpty(network.profileName);
                bool anotherInstanceWithProfileExists =
                    rawNetworks.Where(n => n.Equals(network) && !string.IsNullOrEmpty(n.profileName)).Any();

                if (!anotherInstanceWithProfileExists || hasProfileName)
                {
                    networks.Add(network);
                }
            }

            foreach (WlanAvailableNetwork network in networks)
            {
                //see https://stackoverflow.com/questions/708952/how-to-instantiate-an-object-with-a-private-constructor-in-c/39076814#comment65026579_708976
                // AccessPoint ap = Activator.CreateInstance(typeof(AccessPoint), BindingFlags.Instance | BindingFlags.NonPublic,null,new object[]{wlanIface,network},null) as AccessPoint;
                AccessPoint ap =
                    CreatePrivateClassInstance(typeof(AccessPoint), new object[] { wlanIface, network }) as AccessPoint;
                accessPoints.Add(ap);
            }

            return(accessPoints);
        }