예제 #1
0
        /// <summary>
        /// Gets wireless interface radio information of a specified wireless interface.
        /// </summary>
        /// <param name="interfaceId">Interface ID</param>
        /// <returns>Wireless interface radio information if succeeded. Null if not.</returns>
        public static InterfaceRadio GetInterfaceRadio(Guid interfaceId)
        {
            if (interfaceId == Guid.Empty)
            {
                throw new ArgumentException(nameof(interfaceId));
            }

            using (var client = new Base.WlanClient())
            {
                var capability = Base.GetInterfaceCapability(client.Handle, interfaceId);
                var states     = Base.GetPhyRadioStates(client.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: ConvertToPhyType(x),
                        softwareOn: ConvertToNullableBoolean(y.dot11SoftwareRadioState),
                        hardwareOn: ConvertToNullableBoolean(y.dot11HardwareRadioState)));

                return(new InterfaceRadio(
                           id: interfaceId,
                           radioSets: radioSets));
            }
        }