private WiFiBssType GetBssType(string source)
        {
            WiFiBssType wiFiBssType = default(WiFiBssType);

            if (string.Equals("ESS", source, StringComparison.OrdinalIgnoreCase))
            {
                wiFiBssType = WiFiBssType.Infrastructure;
            }
            else if (string.Equals("IBSS", source, StringComparison.OrdinalIgnoreCase))
            {
                wiFiBssType = WiFiBssType.Independent;
            }

            return(wiFiBssType);
        }
        /// <summary>
        /// Converts enum BssType (ManagedNativeWifi) to internal type WiFiBssType.
        /// </summary>
        private WiFiBssType BssTypeConverter(BssType bssType)
        {
            WiFiBssType wiFiBssType = default(WiFiBssType);;

            switch (bssType)
            {
            case BssType.Infrastructure:
                wiFiBssType = WiFiBssType.Infrastructure;
                break;

            case BssType.Independent:
                wiFiBssType = WiFiBssType.Independent;
                break;
            }

            return(wiFiBssType);
        }
 public AccessPoint(Guid id, string ssid, WiFiBssType bssType, bool isSecurityEnabled,
                    string profileName, bool networkConnectable, string wlanNotConnectableReason,
                    WiFiAuthentication authentication, WiFiEncryptionType encryption,
                    bool isConnected, int linkQuality, int frequency, float band, int channel)
 {
     Id                       = id;
     Ssid                     = ssid;
     BssType                  = bssType;
     IsSecurityEnabled        = isSecurityEnabled;
     ProfileName              = profileName;
     NetworkConnectable       = networkConnectable;
     WlanNotConnectableReason = wlanNotConnectableReason;
     Authentication           = authentication;
     Encryption               = encryption;
     IsConnected              = isConnected;
     LinkQuality              = linkQuality;
     Frequency                = frequency;
     Band                     = band;
     Channel                  = channel;
 }
 public Profile(Guid id, bool isConnected, string profileName, string ssid,
                WiFiProfileType profileType, WiFiBssType bssType, WiFiAuthentication authentication,
                WiFiEncryptionType encryption, WiFiKeyType keyType, bool keyIsEncrypted, string keyValue,
                bool isAutoConnectEnabled, bool isAutoSwitchEnabled, string xml, int position)
 {
     Id                   = id;
     IsConnected          = isConnected;
     ProfileName          = profileName;
     Ssid                 = ssid;
     ProfileType          = profileType;
     BssType              = bssType;
     Authentication       = authentication;
     Encryption           = encryption;
     KeyType              = keyType;
     KeyIsEncrypted       = keyIsEncrypted;
     KeyValue             = keyValue;
     IsAutoConnectEnabled = isAutoConnectEnabled;
     IsAutoSwitchEnabled  = isAutoSwitchEnabled;
     Xml                  = xml;
     Position             = position;
 }
예제 #5
0
        /// <summary>
        /// Validates the profile Parser method.
        /// </summary>
        /// <param name="index">Index of testcase see ProfileTestCases.</param>
        /// <param name="profileXml">Example profile used to call Parser method.</param>
        /// <param name="authentication">Authentication type of access point.</param>
        /// <param name="encryption">Encryption type of access point.</param>
        /// <param name="ssid">Ssid of access point.</param>
        /// <param name="bssType">BssType of access point.</param>
        /// <param name="IsAutoConnectEnabled">Is profile auto connectable.</param>
        /// <param name="IsAutoSwitchEnabled">Is auto switch enabled.</param>
        /// <param name="keyType">KeyType of access point.</param>
        /// <param name="keyIsEncrypted">Key/password specified in profile is encrypted or not.</param>
        /// <param name="password">Password needed to connect to access point, null if open access point.</param>
        public void ValidateProfileParser(int index, string profileXml,
                                          WiFiAuthentication authentication, WiFiEncryptionType encryption,
                                          string ssid, WiFiBssType bssType, bool IsAutoConnectEnabled,
                                          bool IsAutoSwitchEnabled, WiFiKeyType keyType, bool keyIsEncrypted, string password)
        {
            /* Attributes of generated profile are returned in profile object. */
            Profile profile = new Profile();
            bool    result  = _profileService.Parse(profileXml, ref profile);

            Assert.IsTrue(result, $"Testcase[{index}]: failed to parse example profile.");
            /* Validate attributes of generated profile. */
            Assert.AreEqual(authentication, profile.Authentication, $"Testcase[{index}]: failed to validate authentication.");
            Assert.AreEqual(encryption, profile.Encryption, $"Testcase[{index}]: failed to validate encryption.");
            Assert.AreEqual(ssid, profile.Ssid, $"Testcase[{index}]: failed to validate ssid.");
            Assert.AreEqual(ssid, profile.ProfileName, $"Testcase[{index}]: failed to validate profile name.");
            Assert.AreEqual(bssType, profile.BssType, $"Testcase[{index}]: failed to validate profile BSS type.");
            Assert.AreEqual(IsAutoConnectEnabled, profile.IsAutoConnectEnabled, $"Testcase[{index}]: failed to validate profile automatic connection property.");
            Assert.AreEqual(IsAutoSwitchEnabled, profile.IsAutoSwitchEnabled, $"Testcase[{index}]: failed to validate profile automatic switch property.");
            Assert.AreEqual(keyType, profile.KeyType, $"Testcase[{index}]: failed to validate wireless profile KeyType.");
            Assert.AreEqual(keyIsEncrypted, profile.KeyIsEncrypted, $"Testcase[{index}]: failed to validate profile property KeyIsEncrypted.");
            Assert.AreEqual(password, profile.KeyValue, $"Testcase[{index}]: wireless profile password is not equal to expected password.");
        }
예제 #6
0
        /// <summary>
        /// Validates the access point types that are not supported.
        /// </summary>
        /// <param name="authentication">Authentication type of access point.</param>
        /// <param name="encryption">Encryption type of access point.</param>
        /// <param name="ssid">Ssid of access point.</param>
        /// <param name="bssType">BssType of access point, only infrastructure is supported by Microsoft.</param>
        /// <param name="exceptionType">Type of exception thrown when creating (not supported) connection profile.</param>
        /// <param name="expectedErrorMsg">Expected error message when creating (not supported) connection profile.</param>
        public void CreateProfileExceptions(WiFiAuthentication authentication,
                                            WiFiEncryptionType encryption,
                                            string ssid,
                                            WiFiBssType bssType,
                                            Type exceptionType,
                                            string expectedErrorMsg)
        {
            AccessPoint accessPoint = new AccessPoint()
            {
                Ssid           = ssid,
                Authentication = authentication,
                Encryption     = encryption,
                BssType        = bssType
            };

            /* Create profile with parameters that result in an exception. */
            Exception ex = Assert.Throws(exceptionType, () => _profileService.CreateProfileXml(accessPoint, null),
                                         "CreateProfileXml does not throw an exception as expected.");

            /* Check error message */
            Assert.AreEqual(expectedErrorMsg, ex.Message);
        }
        /// <summary>
        /// Validates connection profile and retrieves the attributes from the connection profile.
        /// </summary>
        /// <param name="profileXml">Connection profile to validate.</param>
        /// <param name="profile">Profile object contains attributes retrieved from profile.</param>
        /// <returns>True if profile is valide, false otherwise.</returns>
        public bool Parse(string profileXml, ref Profile profile)
        {
            bool isValid = false;

            if (string.IsNullOrWhiteSpace(profileXml))
            {
                throw new ArgumentNullException(nameof(profileXml));
            }

            XDocument document = XDocument.Parse(profileXml);

            if (!string.Equals(document.Root.Name.NamespaceName, Namespace))
            {
                throw new ArgumentException("The namespace in the Xml does not indicate a WiFi profile.",
                                            nameof(profileXml));
            }

            string   name           = document.Elements().First().Elements(XName.Get("name", Namespace)).FirstOrDefault()?.Value;
            XElement ssidElement    = document.Descendants(XName.Get("SSID", Namespace)).FirstOrDefault();
            string   ssidName       = ssidElement?.Descendants(XName.Get("name", Namespace)).FirstOrDefault()?.Value;
            string   ssidHex        = ssidElement?.Descendants(XName.Get("hex", Namespace)).FirstOrDefault()?.Value;
            string   connectionType = document.Descendants(XName.Get("connectionType", Namespace)).FirstOrDefault()?.Value;
            string   authentication = document.Descendants(XName.Get("authentication", Namespace)).FirstOrDefault()?.Value;
            string   encryption     = document.Descendants(XName.Get("encryption", Namespace)).FirstOrDefault()?.Value;

            /* Retrieve password data, optional data. */
            string   keyType = document.Descendants(XName.Get("keyType", Namespace)).FirstOrDefault()?.Value;
            XElement keyIsEncryptedElement = document.Descendants(XName.Get("protected", Namespace)).FirstOrDefault();
            string   keyMaterial           = document.Descendants(XName.Get("keyMaterial", Namespace)).FirstOrDefault()?.Value;

            /* ConnectionMode and autoSwitchElement are optional data. */
            XElement connectionModeElement = document.Descendants(XName.Get("connectionMode", Namespace)).FirstOrDefault();
            XElement autoSwitchElement     = document.Descendants(XName.Get("autoSwitch", Namespace)).FirstOrDefault();

            if (!string.IsNullOrEmpty(name) &&
                (!string.IsNullOrEmpty(ssidName) ||
                 !string.IsNullOrEmpty(ssidHex)) &&
                !string.IsNullOrEmpty(connectionType) &&
                !string.IsNullOrEmpty(authentication) &&
                !string.IsNullOrEmpty(encryption))
            {
                string ssid = !string.IsNullOrEmpty(ssidHex) ?
                              HexConverter.HexToString(ssidHex) : ssidName;
                WiFiBssType        wiFiBssType        = GetBssType(connectionType);
                WiFiAuthentication wiFiAuthentication = GetAuthentication(authentication);
                WiFiEncryptionType wiFiEncryptionType = GetEncryptionType(encryption);

                if (wiFiBssType != default(WiFiBssType) &&
                    wiFiAuthentication != default(WiFiAuthentication) &&
                    wiFiEncryptionType != default(WiFiEncryptionType))
                {
                    if (!ReferenceEquals(profile, null))
                    {
                        profile.ProfileName          = name;
                        profile.Ssid                 = ssid;
                        profile.BssType              = wiFiBssType;
                        profile.Authentication       = wiFiAuthentication;
                        profile.Encryption           = wiFiEncryptionType;
                        profile.KeyType              = GetKeyType(keyType);
                        profile.KeyIsEncrypted       = ((bool?)keyIsEncryptedElement).GetValueOrDefault();
                        profile.KeyValue             = keyMaterial;
                        profile.IsAutoConnectEnabled = IsAutoConnectEnabled(connectionModeElement?.Value);
                        profile.IsAutoSwitchEnabled  = ((bool?)autoSwitchElement).GetValueOrDefault();
                        profile.Xml = profileXml;
                    }

                    isValid = true;
                }
            }

            return(isValid);
        }