Ejemplo n.º 1
0
        internal static InterfaceRadio GetInterfaceRadio(Base.WlanClient client, Guid interfaceId)
        {
            if (interfaceId == Guid.Empty)
            {
                throw new ArgumentException(nameof(interfaceId));
            }

            using (var container = new DisposableContainer <Base.WlanClient>(client))
            {
                var capability = Base.GetInterfaceCapability(container.Content.Handle, interfaceId);
                var states     = Base.GetPhyRadioStates(container.Content.Handle, interfaceId);             // The underlying collection is array.

                if ((capability.interfaceType == WLAN_INTERFACE_TYPE.wlan_interface_type_invalid) ||
                    (capability.dwNumberOfSupportedPhys != states.Count()))
                {
                    return(null);
                }

                var radioSets = Enumerable.Zip(
                    capability.dot11PhyTypes,
                    states.OrderBy(x => x.dwPhyIndex),
                    (x, y) => new RadioSet(
                        type: PhyTypeConverter.Convert(x),
                        softwareOn: ConvertToNullableBoolean(y.dot11SoftwareRadioState),
                        hardwareOn: ConvertToNullableBoolean(y.dot11HardwareRadioState)));

                return(new InterfaceRadio(
                           id: interfaceId,
                           radioSets: radioSets));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Execute the command.
        /// </summary>
        /// <param name="context">The execution context to operate on.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Returns true if the command executed successfully such that the transition to the next state should occurr, false
        /// if the current state is to be maintained.</returns>
        internal override async Task <bool> ExecuteAsync(SmtpSessionContext context, CancellationToken cancellationToken)
        {
            using (var container = new DisposableContainer <IMailboxFilter>(Options.MailboxFilterFactory.CreateInstance(context)))
            {
                switch (await container.Instance.CanDeliverToAsync(context, Address, context.Transaction.From, cancellationToken).ConfigureAwait(false))
                {
                case MailboxFilterResult.Yes:
                    context.Transaction.To.Add(Address);
                    await context.NetworkClient.ReplyAsync(SmtpResponse.Ok, cancellationToken).ConfigureAwait(false);

                    return(true);

                case MailboxFilterResult.NoTemporarily:
                    await context.NetworkClient.ReplyAsync(SmtpResponse.MailboxUnavailable, cancellationToken).ConfigureAwait(false);

                    return(false);

                case MailboxFilterResult.NoPermanently:
                    await context.NetworkClient.ReplyAsync(SmtpResponse.MailboxNameNotAllowed, cancellationToken).ConfigureAwait(false);

                    return(false);
                }
            }

            throw new NotSupportedException("The Acceptance state is not supported.");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Execute the command.
        /// </summary>
        /// <param name="context">The execution context to operate on.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>A task which asynchronously performs the execution.</returns>
        internal override async Task ExecuteAsync(SmtpSessionContext context, CancellationToken cancellationToken)
        {
            if (context.Transaction.To.Count == 0)
            {
                await context.Client.ReplyAsync(SmtpResponse.NoValidRecipientsGiven, cancellationToken).ConfigureAwait(false);

                return;
            }

            await context.Client.ReplyAsync(new SmtpResponse(SmtpReplyCode.StartMailInput, "end with <CRLF>.<CRLF>"), cancellationToken).ConfigureAwait(false);

            context.Transaction.Message = await ReadMessageAsync(context, cancellationToken).ConfigureAwait(false);

            try
            {
                // store the transaction
                using (var container = new DisposableContainer <IMessageStore>(Options.MessageStoreFactory.CreateInstance(context)))
                {
                    var response = await container.Instance.SaveAsync(context, context.Transaction, cancellationToken).ConfigureAwait(false);

                    await context.Client.ReplyAsync(response, cancellationToken).ConfigureAwait(false);
                }
            }
            catch (Exception)
            {
                await context.Client.ReplyAsync(new SmtpResponse(SmtpReplyCode.TransactionFailed), cancellationToken).ConfigureAwait(false);
            }
        }
Ejemplo n.º 4
0
        internal static bool ConnectNetwork(Base.WlanClient client, Guid interfaceId, string profileName, BssType bssType, PhysicalAddress bssid = null)
        {
            if (interfaceId == Guid.Empty)
            {
                throw new ArgumentException("The specified interface ID is invalid.", nameof(interfaceId));
            }
            if (string.IsNullOrWhiteSpace(profileName))
            {
                throw new ArgumentNullException(nameof(profileName));
            }

            using var container = new DisposableContainer <Base.WlanClient>(client);

            if (bssid is not null)
            {
                var dot11MacAddress = new DOT11_MAC_ADDRESS {
                    ucDot11MacAddress = bssid.GetAddressBytes()
                };
                return(Base.Connect(container.Content.Handle, interfaceId, profileName, BssTypeConverter.ConvertBack(bssType), dot11MacAddress));
            }
            else
            {
                return(Base.Connect(container.Content.Handle, interfaceId, profileName, BssTypeConverter.ConvertBack(bssType)));
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Execute the command.
        /// </summary>
        /// <param name="context">The execution context to operate on.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>A task which asynchronously performs the execution.</returns>
        public override async Task ExecuteAsync(ISmtpSessionContext context, CancellationToken cancellationToken)
        {
            using (var container = new DisposableContainer <IMailboxFilter>(_mailboxFilterFactory.CreateInstance(context)))
            {
                switch (await container.Instance.CanDeliverToAsync(context, _address, context.Transaction.From))
                {
                case MailboxFilterResult.Yes:
                    context.Transaction.To.Add(_address);
                    await context.Text.ReplyAsync(SmtpResponse.Ok, cancellationToken);

                    return;

                case MailboxFilterResult.NoTemporarily:
                    await context.Text.ReplyAsync(SmtpResponse.MailboxUnavailable, cancellationToken);

                    return;

                case MailboxFilterResult.NoPermanently:
                    await context.Text.ReplyAsync(SmtpResponse.MailboxNameNotAllowed, cancellationToken);

                    return;
                }
            }

            throw new NotSupportedException("The Acceptance state is not supported.");
        }
Ejemplo n.º 6
0
        internal static IEnumerable <ProfilePack> EnumerateProfiles(Base.WlanClient client)
        {
            using var container = new DisposableContainer <Base.WlanClient>(client);

            foreach (var interfaceInfo in EnumerateInterfaces(container.Content))
            {
                int position = 0;

                foreach (var profileInfo in Base.GetProfileInfoList(container.Content.Handle, interfaceInfo.Id))
                {
                    var profileXml = Base.GetProfile(container.Content.Handle, interfaceInfo.Id, profileInfo.strProfileName, out uint profileTypeFlag);
                    if (string.IsNullOrWhiteSpace(profileXml))
                    {
                        continue;
                    }

                    if (!ProfileTypeConverter.TryConvert(profileTypeFlag, out ProfileType profileType))
                    {
                        continue;
                    }

                    yield return(new ProfilePack(
                                     name: profileInfo.strProfileName,
                                     interfaceInfo: interfaceInfo,
                                     profileType: profileType,
                                     profileXml: profileXml,
                                     position: position++));
                }
            }
        }
Ejemplo n.º 7
0
        internal static IEnumerable <ProfilePack> EnumerateProfiles(Base.WlanClient client)
        {
            using (var container = new DisposableContainer <Base.WlanClient>(client))
            {
                var interfaceInfoList = Base.GetInterfaceInfoList(container.Content.Handle);

                foreach (var interfaceInfo in interfaceInfoList.Select(x => new InterfaceInfo(x)))
                {
                    var interfaceIsConnected = (interfaceInfo.State == InterfaceState.Connected);

                    var interfaceIsRadioOn = interfaceIsConnected || IsInterfaceRadioOn(container.Content, interfaceInfo.Id);

                    var availableNetworkList = Base.GetAvailableNetworkList(container.Content.Handle, interfaceInfo.Id)
                                               .Where(x => !string.IsNullOrWhiteSpace(x.strProfileName))
                                               .ToArray();

                    var connection = Base.GetConnectionAttributes(container.Content.Handle, interfaceInfo.Id);

                    var profileInfoList = Base.GetProfileInfoList(container.Content.Handle, interfaceInfo.Id);

                    int position = 0;

                    foreach (var profileInfo in profileInfoList)
                    {
                        var availableNetwork   = availableNetworkList.FirstOrDefault(x => string.Equals(x.strProfileName, profileInfo.strProfileName, StringComparison.Ordinal));
                        var signalQuality      = (int)availableNetwork.wlanSignalQuality;
                        var profileIsConnected = interfaceIsConnected && string.Equals(connection.strProfileName, profileInfo.strProfileName, StringComparison.Ordinal);

                        var profileXml = Base.GetProfile(container.Content.Handle, interfaceInfo.Id, profileInfo.strProfileName, out uint profileTypeFlag);
                        if (string.IsNullOrWhiteSpace(profileXml))
                        {
                            continue;
                        }

                        if (!ProfileTypeConverter.TryConvert(profileTypeFlag, out ProfileType profileType))
                        {
                            continue;
                        }

                        //Debug.WriteLine("Interface: {0}, Profile: {1}, Position: {2}, RadioOn: {3}, Signal: {4}, Connected: {5}",
                        //	interfaceInfo.Description,
                        //	profileInfo.strProfileName,
                        //	position,
                        //	interfaceIsRadioOn,
                        //	signalQuality,
                        //	profileIsConnected);

                        yield return(new ProfilePack(
                                         name: profileInfo.strProfileName,
                                         interfaceInfo: interfaceInfo,
                                         profileType: profileType,
                                         profileXml: profileXml,
                                         position: position++,
                                         isRadioOn: interfaceIsRadioOn,
                                         signalQuality: signalQuality,
                                         isConnected: profileIsConnected));
                    }
                }
            }
        }
Ejemplo n.º 8
0
        internal static IEnumerable <AvailableNetworkPack> EnumerateAvailableNetworks(Base.WlanClient client)
        {
            using var container = new DisposableContainer <Base.WlanClient>(client);

            foreach (var interfaceInfo in EnumerateInterfaces(container.Content))
            {
                foreach (var availableNetwork in Base.GetAvailableNetworkList(container.Content.Handle, interfaceInfo.Id))
                {
                    if (!BssTypeConverter.TryConvert(availableNetwork.dot11BssType, out BssType bssType))
                    {
                        continue;
                    }

                    if (!AuthenticationAlgorithmConverter.TryConvert(availableNetwork.dot11DefaultAuthAlgorithm, out AuthenticationAlgorithm authenticationAlgorithm))
                    {
                        continue;
                    }

                    if (!CipherAlgorithmConverter.TryConvert(availableNetwork.dot11DefaultCipherAlgorithm, out CipherAlgorithm cipherAlgorithm))
                    {
                        continue;
                    }

                    yield return(new AvailableNetworkPack(
                                     interfaceInfo: interfaceInfo,
                                     ssid: new NetworkIdentifier(availableNetwork.dot11Ssid),
                                     bssType: bssType,
                                     signalQuality: (int)availableNetwork.wlanSignalQuality,
                                     isSecurityEnabled: availableNetwork.bSecurityEnabled,
                                     profileName: availableNetwork.strProfileName,
                                     authenticationAlgorithm: authenticationAlgorithm,
                                     cipherAlgorithm: cipherAlgorithm));
                }
            }
        }
        /// <summary>
        /// Execute the command.
        /// </summary>
        /// <param name="context">The execution context to operate on.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Returns true if the command executed successfully such that the transition to the next state should occurr, false
        /// if the current state is to be maintained.</returns>
        internal override async Task <bool> ExecuteAsync(SmtpSessionContext context, CancellationToken cancellationToken)
        {
            var mailboxFilter = context.ServiceProvider.GetService <IMailboxFilterFactory, IMailboxFilter>(context, MailboxFilter.Default);

            using var container = new DisposableContainer <IMailboxFilter>(mailboxFilter);

            switch (await container.Instance.CanDeliverToAsync(context, Address, context.Transaction.From, cancellationToken).ConfigureAwait(false))
            {
            case MailboxFilterResult.Yes:
                context.Transaction.To.Add(Address);
                await context.Pipe.Output.WriteReplyAsync(SmtpResponse.Ok, cancellationToken).ConfigureAwait(false);

                return(true);

            case MailboxFilterResult.NoTemporarily:
                await context.Pipe.Output.WriteReplyAsync(SmtpResponse.MailboxUnavailable, cancellationToken).ConfigureAwait(false);

                return(false);

            case MailboxFilterResult.NoPermanently:
                await context.Pipe.Output.WriteReplyAsync(SmtpResponse.MailboxNameNotAllowed, cancellationToken).ConfigureAwait(false);

                return(false);
            }

            throw new NotSupportedException("The Acceptance state is not supported.");
        }
Ejemplo n.º 10
0
        internal static IEnumerable <InterfaceInfo> EnumerateInterfaces(Base.WlanClient client)
        {
            using var container = new DisposableContainer <Base.WlanClient>(client);

            return(Base.GetInterfaceInfoList(container.Content.Handle)
                   .Select(x => new InterfaceInfo(x)));
        }
Ejemplo n.º 11
0
        internal static IEnumerable <AvailableNetworkPack> EnumerateAvailableNetworks(Base.WlanClient client)
        {
            using (var container = new DisposableContainer <Base.WlanClient>(client))
            {
                var interfaceInfoList = Base.GetInterfaceInfoList(container.Content.Handle);

                foreach (var interfaceInfo in interfaceInfoList.Select(x => new InterfaceInfo(x)))
                {
                    var availableNetworkList = Base.GetAvailableNetworkList(container.Content.Handle, interfaceInfo.Id);

                    foreach (var availableNetwork in availableNetworkList)
                    {
                        if (!BssTypeConverter.TryConvert(availableNetwork.dot11BssType, out BssType bssType))
                        {
                            continue;
                        }

                        //Debug.WriteLine("Interface: {0}, SSID: {1}, Signal: {2}, Security: {3}",
                        //	interfaceInfo.Description,
                        //	availableNetwork.dot11Ssid,
                        //	availableNetwork.wlanSignalQuality,
                        //	availableNetwork.bSecurityEnabled);

                        yield return(new AvailableNetworkPack(
                                         interfaceInfo: interfaceInfo,
                                         ssid: new NetworkIdentifier(availableNetwork.dot11Ssid.ToBytes(), availableNetwork.dot11Ssid.ToString()),
                                         bssType: bssType,
                                         signalQuality: (int)availableNetwork.wlanSignalQuality,
                                         isSecurityEnabled: availableNetwork.bSecurityEnabled,
                                         profileName: availableNetwork.strProfileName));
                    }
                }
            }
        }
Ejemplo n.º 12
0
        internal static IEnumerable <NetworkIdentifier> EnumerateConnectedNetworkSsids(Base.WlanClient client)
        {
            using (var container = new DisposableContainer <Base.WlanClient>(client))
            {
                var interfaceInfoList = Base.GetInterfaceInfoList(container.Content.Handle);

                foreach (var interfaceInfo in interfaceInfoList)
                {
                    var connection = Base.GetConnectionAttributes(container.Content.Handle, interfaceInfo.InterfaceGuid);
                    if (connection.isState != WLAN_INTERFACE_STATE.wlan_interface_state_connected)
                    {
                        continue;
                    }

                    var association = connection.wlanAssociationAttributes;

                    //Debug.WriteLine("Interface: {0}, SSID: {1}, BSSID: {2}, Signal: {3}",
                    //	interfaceInfo.strInterfaceDescription,
                    //	association.dot11Ssid,
                    //	association.dot11Bssid,
                    //	association.wlanSignalQuality);

                    yield return(new NetworkIdentifier(association.dot11Ssid.ToBytes(), association.dot11Ssid.ToString()));
                }
            }
        }
Ejemplo n.º 13
0
        internal static bool DisconnectNetwork(Base.WlanClient client, Guid interfaceId)
        {
            if (interfaceId == Guid.Empty)
            {
                throw new ArgumentException("The specified interface ID is invalid.", nameof(interfaceId));
            }

            using var container = new DisposableContainer <Base.WlanClient>(client);

            return(Base.Disconnect(container.Content.Handle, interfaceId));
        }
Ejemplo n.º 14
0
        internal static IEnumerable <string> EnumerateProfileNames(Base.WlanClient client)
        {
            using var container = new DisposableContainer <Base.WlanClient>(client);

            foreach (var interfaceInfo in Base.GetInterfaceInfoList(container.Content.Handle))
            {
                foreach (var profileInfo in Base.GetProfileInfoList(container.Content.Handle, interfaceInfo.InterfaceGuid))
                {
                    yield return(profileInfo.strProfileName);
                }
            }
        }
        /// <summary>
        /// Execute the command.
        /// </summary>
        /// <param name="context">The execution context to operate on.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Returns true if the command executed successfully such that the transition to the next state should occurr, false
        /// if the current state is to be maintained.</returns>
        internal override async Task <bool> ExecuteAsync(SmtpSessionContext context, CancellationToken cancellationToken)
        {
            if (context.EndpointDefinition.AuthenticationRequired && context.Authentication.IsAuthenticated == false)
            {
                await context.Pipe.Output.WriteReplyAsync(SmtpResponse.AuthenticationRequired, cancellationToken).ConfigureAwait(false);

                return(false);
            }

            context.Transaction.Reset();
            context.Transaction.Parameters = Parameters;

            // check if a size has been defined
            var size = GetMessageSize();

            // check against the server supplied maximum
            if (context.ServerOptions.MaxMessageSize > 0 && size > context.ServerOptions.MaxMessageSize)
            {
                await context.Pipe.Output.WriteReplyAsync(SmtpResponse.SizeLimitExceeded, cancellationToken).ConfigureAwait(false);

                return(false);
            }

            var mailboxFilter = context.ServiceProvider.GetService <IMailboxFilterFactory, IMailboxFilter>(context, MailboxFilter.Default);

            using var container = new DisposableContainer <IMailboxFilter>(mailboxFilter);

            switch (await container.Instance.CanAcceptFromAsync(context, Address, size, cancellationToken).ConfigureAwait(false))
            {
            case MailboxFilterResult.Yes:
                context.Transaction.From = Address;
                await context.Pipe.Output.WriteReplyAsync(SmtpResponse.Ok, cancellationToken).ConfigureAwait(false);

                return(true);

            case MailboxFilterResult.NoTemporarily:
                await context.Pipe.Output.WriteReplyAsync(SmtpResponse.MailboxUnavailable, cancellationToken).ConfigureAwait(false);

                return(false);

            case MailboxFilterResult.NoPermanently:
                await context.Pipe.Output.WriteReplyAsync(SmtpResponse.MailboxNameNotAllowed, cancellationToken).ConfigureAwait(false);

                return(false);

            case MailboxFilterResult.SizeLimitExceeded:
                await context.Pipe.Output.WriteReplyAsync(SmtpResponse.SizeLimitExceeded, cancellationToken).ConfigureAwait(false);

                return(false);
            }

            throw new SmtpResponseException(SmtpResponse.TransactionFailed);
        }
Ejemplo n.º 16
0
        internal static IEnumerable <AvailableNetworkGroupPack> EnumerateAvailableNetworkGroups(Base.WlanClient client)
        {
            using var container = new DisposableContainer <Base.WlanClient>(client);

            foreach (var interfaceInfo in EnumerateInterfaces(container.Content))
            {
                foreach (var availableNetworkGroup in EnumerateAvailableNetworkGroups(container.Content, interfaceInfo))
                {
                    yield return(availableNetworkGroup);
                }
            }
        }
Ejemplo n.º 17
0
        internal static IEnumerable <NetworkIdentifier> EnumerateAvailableNetworkSsids(Base.WlanClient client)
        {
            using var container = new DisposableContainer <Base.WlanClient>(client);

            foreach (var interfaceInfo in Base.GetInterfaceInfoList(container.Content.Handle))
            {
                foreach (var availableNetwork in Base.GetAvailableNetworkList(container.Content.Handle, interfaceInfo.InterfaceGuid))
                {
                    yield return(new NetworkIdentifier(availableNetwork.dot11Ssid));
                }
            }
        }
Ejemplo n.º 18
0
        internal static bool GetInterfaceAutoConfig(Base.WlanClient client, Guid interfaceId)
        {
            if (interfaceId == Guid.Empty)
            {
                throw new ArgumentException(nameof(interfaceId));
            }

            using (var container = new DisposableContainer <Base.WlanClient>(client))
            {
                return(Base.GetAutoConfig(container.Content.Handle, interfaceId).GetValueOrDefault());
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Execute the command.
        /// </summary>
        /// <param name="context">The execution context to operate on.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>Returns true if the command executed successfully such that the transition to the next state should occur, false
        /// if the current state is to be maintained.</returns>
        internal override async Task <bool> ExecuteAsync(SmtpSessionContext context, CancellationToken cancellationToken)
        {
            context.Authentication = AuthenticationContext.Unauthenticated;

            switch (Method)
            {
            case AuthenticationMethod.Plain:
                if (await TryPlainAsync(context, cancellationToken).ConfigureAwait(false) == false)
                {
                    await context.Pipe.Output.WriteReplyAsync(SmtpResponse.AuthenticationFailed, cancellationToken).ConfigureAwait(false);

                    return(false);
                }
                break;

            case AuthenticationMethod.Login:
                if (await TryLoginAsync(context, cancellationToken).ConfigureAwait(false) == false)
                {
                    await context.Pipe.Output.WriteReplyAsync(SmtpResponse.AuthenticationFailed, cancellationToken).ConfigureAwait(false);

                    return(false);
                }
                break;
            }

            var userAuthenticator = context.ServiceProvider.GetService <IUserAuthenticatorFactory, IUserAuthenticator>(context, UserAuthenticator.Default);

            using (var container = new DisposableContainer <IUserAuthenticator>(userAuthenticator))
            {
                if (await container.Instance.AuthenticateAsync(context, _user, _password, cancellationToken).ConfigureAwait(false) == false)
                {
                    var remaining = context.ServerOptions.MaxAuthenticationAttempts - ++context.AuthenticationAttempts;
                    var response  = new SmtpResponse(SmtpReplyCode.AuthenticationFailed, $"authentication failed, {remaining} attempt(s) remaining.");

                    await context.Pipe.Output.WriteReplyAsync(response, cancellationToken).ConfigureAwait(false);

                    if (remaining <= 0)
                    {
                        throw new SmtpResponseException(SmtpResponse.ServiceClosingTransmissionChannel, true);
                    }

                    return(false);
                }
            }

            await context.Pipe.Output.WriteReplyAsync(SmtpResponse.AuthenticationSuccessful, cancellationToken).ConfigureAwait(false);

            context.Authentication = new AuthenticationContext(_user);
            context.RaiseSessionAuthenticated();

            return(true);
        }
Ejemplo n.º 20
0
        public Foo()
        {
            _disposable = new DisposableContainer();

            // Adding a disposabe object.
            _baz = _disposable.AddManagedResource(new Baz());

            // Adding an event. This prevent a memory leak. object is the event argument type.
            _disposable.AddEventSubscription <object>(typeof(Baz), nameof(Baz.StaticEventHandler), EventHandler);

            // Adding an arbitary cleanup action.
            _disposable.AddCleanupAction(SomeCleanup);
        }
Ejemplo n.º 21
0
        internal static IEnumerable <BssNetworkPack> EnumerateBssNetworks(Base.WlanClient client)
        {
            using (var container = new DisposableContainer <Base.WlanClient>(client))
            {
                var interfaceInfoList = Base.GetInterfaceInfoList(container.Content.Handle);

                foreach (var interfaceInfo in interfaceInfoList.Select(x => new InterfaceInfo(container.Content.Handle, x)))
                {
                    var networkList = EnumerateAvailableNetworks(client);

                    var networkBssEntryList = Base.GetNetworkBssEntryList(container.Content.Handle, interfaceInfo.Id);

                    foreach (var networkBssEntry in networkBssEntryList)
                    {
                        if (!BssTypeConverter.TryConvert(networkBssEntry.dot11BssType, out BssType bssType))
                        {
                            continue;
                        }

                        //Debug.WriteLine("Interface: {0}, SSID: {1}, BSSID: {2}, Signal: {3} Link: {4}, Frequency: {5}",
                        //	interfaceInfo.Description,
                        //	networkBssEntry.dot11Ssid,
                        //	networkBssEntry.dot11Bssid,
                        //	networkBssEntry.lRssi,
                        //	networkBssEntry.uLinkQuality,
                        //	networkBssEntry.ulChCenterFrequency);
                        var network = networkList.Where(o => o.Ssid.ToString() == new NetworkIdentifier(networkBssEntry.dot11Ssid.ToBytes(), networkBssEntry.dot11Ssid.ToString(), networkBssEntry.dot11Ssid.uSSIDLength).ToString());

                        //this program work get available network first and get bssnetwork list.
                        //so if can not found network. just skip the bss network.
                        //it just happen if you don't have a luck.
                        if (!network.Any())
                        {
                            continue;
                        }

                        yield return(new BssNetworkPack(
                                         interfaceInfo: interfaceInfo,
                                         network: network.First(),
                                         ssid: new NetworkIdentifier(networkBssEntry.dot11Ssid.ToBytes(), networkBssEntry.dot11Ssid.ToString(), networkBssEntry.dot11Ssid.uSSIDLength),
                                         bssType: bssType,
                                         bssid: new NetworkIdentifier(networkBssEntry.dot11Bssid.ToBytes(), networkBssEntry.dot11Bssid.ToString(), networkBssEntry.dot11Ssid.uSSIDLength),
                                         signalStrength: networkBssEntry.lRssi,
                                         linkQuality: (int)networkBssEntry.uLinkQuality,
                                         frequency: (int)networkBssEntry.ulChCenterFrequency,
                                         channel: DetectChannel(networkBssEntry.ulChCenterFrequency)));
                    }
                }
            }
        }
Ejemplo n.º 22
0
        internal static IEnumerable <InterfaceInfoEx> EnumerateInterfacesEx(Base.WlanClient client)
        {
            using (var container = new DisposableContainer <Base.WlanClient>(client))
            {
                var interfaceInfoList = Base.GetInterfaceInfoList(container.Content.Handle);

                foreach (var interfaceInfo in interfaceInfoList)
                {
                    var connection = Base.GetConnectionAttributes(container.Content.Handle, interfaceInfo.InterfaceGuid);

                    yield return(new InterfaceInfoEx(interfaceInfo, connection));
                }
            }
        }
Ejemplo n.º 23
0
        internal static IEnumerable <BssNetworkPack> EnumerateBssNetworks(Base.WlanClient client)
        {
            using var container = new DisposableContainer <Base.WlanClient>(client);

            foreach (var interfaceInfo in EnumerateInterfaces(container.Content))
            {
                foreach (var networkBssEntry in Base.GetNetworkBssEntryList(container.Content.Handle, interfaceInfo.Id))
                {
                    if (TryConvertBssNetwork(interfaceInfo, networkBssEntry, out BssNetworkPack bssNetwork))
                    {
                        yield return(bssNetwork);
                    }
                }
            }
        }
Ejemplo n.º 24
0
        internal static bool DeleteProfile(Base.WlanClient client, Guid interfaceId, string profileName)
        {
            if (interfaceId == Guid.Empty)
            {
                throw new ArgumentException("The specified interface ID is invalid.", nameof(interfaceId));
            }
            if (string.IsNullOrWhiteSpace(profileName))
            {
                throw new ArgumentNullException(nameof(profileName));
            }

            using var container = new DisposableContainer <Base.WlanClient>(client);

            return(Base.DeleteProfile(container.Content.Handle, interfaceId, profileName));
        }
Ejemplo n.º 25
0
        public void Dispose(bool disposing)
        {
            if (m_Disposed)
            {
                return;
            }

            if (disposing)
            {
                m_Transaction.Dispose();
                m_Connection.Dispose();
                DisposableContainer?.OnDispose();
                m_Disposed = true;
            }
        }
Ejemplo n.º 26
0
        internal static async Task <IEnumerable <Guid> > ScanNetworksAsync(Base.WlanNotificationClient client, TimeSpan timeout, CancellationToken cancellationToken)
        {
            if (timeout <= TimeSpan.Zero)
            {
                throw new ArgumentException(nameof(timeout));
            }

            using (var container = new DisposableContainer <Base.WlanNotificationClient>(client))
            {
                var interfaceIds = Base.GetInterfaceInfoList(container.Content.Handle)
                                   .Select(x => x.InterfaceGuid)
                                   .ToArray();

                var tcs     = new TaskCompletionSource <bool>();
                var counter = new ScanCounter(() => Task.Run(() => tcs.TrySetResult(true)), interfaceIds);

                container.Content.NotificationReceived += (sender, data) =>
                {
                    switch ((WLAN_NOTIFICATION_ACM)data.NotificationCode)
                    {
                    case WLAN_NOTIFICATION_ACM.wlan_notification_acm_scan_complete:
                        counter.SetSuccess(data.InterfaceGuid);
                        break;

                    case WLAN_NOTIFICATION_ACM.wlan_notification_acm_scan_fail:
                        counter.SetFailure(data.InterfaceGuid);
                        break;
                    }
                };

                foreach (var interfaceId in interfaceIds)
                {
                    var result = Base.Scan(container.Content.Handle, interfaceId);
                    if (!result)
                    {
                        counter.SetFailure(interfaceId);
                    }
                }

                using (cancellationToken.Register(() => tcs.TrySetCanceled()))
                {
                    var scanTask = tcs.Task;
                    await Task.WhenAny(scanTask, Task.Delay(timeout, cancellationToken));

                    return(counter.Results);
                }
            }
        }
Ejemplo n.º 27
0
        internal static bool TurnInterfaceRadio(Base.WlanClient client, Guid interfaceId, DOT11_RADIO_STATE radioState)
        {
            if (interfaceId == Guid.Empty)
            {
                throw new ArgumentException(nameof(interfaceId));
            }

            using (var container = new DisposableContainer <Base.WlanClient>(client))
            {
                var phyRadioState = new WLAN_PHY_RADIO_STATE {
                    dot11SoftwareRadioState = radioState,
                };

                return(Base.SetPhyRadioState(container.Content.Handle, interfaceId, phyRadioState));
            }
        }
Ejemplo n.º 28
0
        internal static bool ConnectNetwork(Base.WlanClient client, Guid interfaceId, string profileName, BssType bssType)
        {
            if (interfaceId == Guid.Empty)
            {
                throw new ArgumentException(nameof(interfaceId));
            }

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

            using (var container = new DisposableContainer <Base.WlanClient>(client))
            {
                return(Base.Connect(container.Content.Handle, interfaceId, profileName, BssTypeConverter.ConvertBack(bssType)));
            }
        }
Ejemplo n.º 29
0
        internal static bool SetProfile(Base.WlanClient client, Guid interfaceId, ProfileType profileType, string profileXml, string profileSecurity, bool overwrite)
        {
            if (interfaceId == Guid.Empty)
            {
                throw new ArgumentException("The specified interface ID is invalid.", nameof(interfaceId));
            }
            if (string.IsNullOrWhiteSpace(profileXml))
            {
                throw new ArgumentNullException(nameof(profileXml));
            }

            using var container = new DisposableContainer <Base.WlanClient>(client);

            var profileTypeFlag = ProfileTypeConverter.ConvertBack(profileType);

            return(Base.SetProfile(container.Content.Handle, interfaceId, profileTypeFlag, profileXml, profileSecurity, overwrite));
        }
Ejemplo n.º 30
0
        internal static IEnumerable <NetworkIdentifier> EnumerateConnectedNetworkSsids(Base.WlanClient client)
        {
            using var container = new DisposableContainer <Base.WlanClient>(client);

            foreach (var interfaceInfo in Base.GetInterfaceInfoList(container.Content.Handle))
            {
                var connection = Base.GetConnectionAttributes(container.Content.Handle, interfaceInfo.InterfaceGuid);
                if (connection.isState != WLAN_INTERFACE_STATE.wlan_interface_state_connected)
                {
                    continue;
                }

                var association = connection.wlanAssociationAttributes;

                yield return(new NetworkIdentifier(association.dot11Ssid));
            }
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Execute the command.
        /// </summary>
        /// <param name="context">The execution context to operate on.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>A task which asynchronously performs the execution.</returns>
        public override async Task ExecuteAsync(ISmtpSessionContext context, CancellationToken cancellationToken)
        {
            if (context.Transaction.To.Count == 0)
            {
                await context.Text.ReplyAsync(SmtpResponse.NoValidRecipientsGiven, cancellationToken).ConfigureAwait(false);
                return;
            }

            await context.Text.ReplyAsync(new SmtpResponse(SmtpReplyCode.StartMailInput, "end with <CRLF>.<CRLF>"), cancellationToken).ConfigureAwait(false);

            try
            {
                string text;
                while ((text = await context.Text.ReadLineAsync(TimeSpan.FromSeconds(60), cancellationToken).ConfigureAwait(false)) != ".")
                {
                    // need to trim the '.' at the start of the line if it 
                    // exists as this would have been added for transparency
                    // http://tools.ietf.org/html/rfc5321#section-4.5.2
                    context.Transaction.Mime.AppendLine(text.TrimStart('.'));
                }
            }
            catch (TimeoutException)
            {
                // TODO: not sure what the best thing to do here is
                throw;
            }

            try
            {
                // store the transaction
                using (var container = new DisposableContainer<IMessageStore>(_messageStoreFactory.CreateInstance(context)))
                {
                    var response = await container.Instance.SaveAsync(context, context.Transaction, cancellationToken).ConfigureAwait(false);

                    await context.Text.ReplyAsync(response, cancellationToken).ConfigureAwait(false);
                }
            }
            catch (Exception)
            {
                await context.Text.ReplyAsync(new SmtpResponse(SmtpReplyCode.TransactionFailed), cancellationToken).ConfigureAwait(false);
            }
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Execute the command.
        /// </summary>
        /// <param name="context">The execution context to operate on.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>A task which asynchronously performs the execution.</returns>
        public override async Task ExecuteAsync(ISmtpSessionContext context, CancellationToken cancellationToken)
        {
            context.Transaction.Reset();

            // check if a size has been defined
            var size = GetMessageSize();

            // check against the server supplied maximum
            if (_maxMessageSize > 0 && size > _maxMessageSize)
            {
                await context.Text.ReplyAsync(SmtpResponse.SizeLimitExceeded, cancellationToken);
                return;
            }

            using (var container = new DisposableContainer<IMailboxFilter>(_mailboxFilterFactory.CreateInstance(context)))
            {
                switch (await container.Instance.CanAcceptFromAsync(context, Address, size))
                {
                    case MailboxFilterResult.Yes:
                        context.Transaction.From = _address;
                        await context.Text.ReplyAsync(SmtpResponse.Ok, cancellationToken);
                        return;

                    case MailboxFilterResult.NoTemporarily:
                        await context.Text.ReplyAsync(SmtpResponse.MailboxUnavailable, cancellationToken);
                        return;

                    case MailboxFilterResult.NoPermanently:
                        await context.Text.ReplyAsync(SmtpResponse.MailboxNameNotAllowed, cancellationToken);
                        return;

                    case MailboxFilterResult.SizeLimitExceeded:
                        await context.Text.ReplyAsync(SmtpResponse.SizeLimitExceeded, cancellationToken);
                        return;
                }
            }

            throw new NotSupportedException("The Acceptance state is not supported.");
        }
Ejemplo n.º 33
0
        /// <summary>
        /// Execute the command.
        /// </summary>
        /// <param name="context">The execution context to operate on.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>A task which asynchronously performs the execution.</returns>
        public override async Task ExecuteAsync(ISmtpSessionContext context, CancellationToken cancellationToken)
        {
            using (var container = new DisposableContainer<IMailboxFilter>(_mailboxFilterFactory.CreateInstance(context)))
            {
                switch (await container.Instance.CanDeliverToAsync(context, _address, context.Transaction.From))
                {
                    case MailboxFilterResult.Yes:
                        context.Transaction.To.Add(_address);
                        await context.Text.ReplyAsync(SmtpResponse.Ok, cancellationToken);
                        return;

                    case MailboxFilterResult.NoTemporarily:
                        await context.Text.ReplyAsync(SmtpResponse.MailboxUnavailable, cancellationToken);
                        return;

                    case MailboxFilterResult.NoPermanently:
                        await context.Text.ReplyAsync(SmtpResponse.MailboxNameNotAllowed, cancellationToken);
                        return;
                }
            }

            throw new NotSupportedException("The Acceptance state is not supported.");
        }