Esempio n. 1
0
        private void InitializeAsync(object state)
        {
            // we want to store key material in the registry so it survives a restart
            using (var key = Registry.LocalMachine.OpenSubKey("\\init\\bootvars", true))
            {
                // this key may not exist in WinMo - it does in CE
                if (key != null)
                {
                    key.SetValue("MasterKeysInRegistry", 1, RegistryValueKind.DWord);
                    key.Flush();
                }
            }

            m_wzc = GetFirstWZCInterface();

            RaisePropertyChanged("AdapterName");

            Initialized = true;

            var handler = InitializationComplete;

            if (handler != null)
            {
                handler(this, EventArgs.Empty);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Retorna una lista de adaptadores de red disponibles en la máquina
 /// Si ocurre un error se arroja una Excepción
 /// </summary>
 /// <returns></returns>
 public static List <NetworkAdapter> getNetworkAdapters()
 {
     try
     {
         List <NetworkAdapter> networkAdapters   = new List <NetworkAdapter>();
         INetworkInterface[]   networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
         foreach (INetworkInterface networkInterface in networkInterfaces)
         {
             try
             {
                 WirelessZeroConfigNetworkInterface adapter = (WirelessZeroConfigNetworkInterface)networkInterface;
                 NetworkAdapter networkAdapter = new NetworkAdapter();
                 networkAdapter.Name        = adapter.Name;
                 networkAdapter.Description = adapter.Description;
                 networkAdapters.Add(networkAdapter);
             }
             catch (Exception)
             {
             }
         }
         return(networkAdapters);
     }
     catch (ThreadAbortException e)
     {
         throw e;
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        /// <summary>
        /// Conecta a la red adhoc
        /// Si ocurre algun error se informa en informationNetworkingHandler
        /// </summary>
        internal void openWLanConnection()
        {
            try
            {
                //Revisa si hay un adaptador seleccionado en la configuración
                if (netData.NetworkAdapter == null)
                {
                    throw new Exception("no hay un adaptador de red seleccionado");
                }

                INetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
                foreach (INetworkInterface networkInterface in networkInterfaces)
                {
                    if (netData.NetworkAdapter.Name.Equals(networkInterface.Name))
                    {
                        WirelessZeroConfigNetworkInterface adapter = (WirelessZeroConfigNetworkInterface)networkInterface;
                        adapter.AddPreferredNetwork(netData.AdhocNetworkName, false, "", 1, AuthenticationMode.Open, WEPStatus.WEPDisabled, null);
                        adapter.ConnectToPreferredNetwork(netData.AdhocNetworkName);
                        connectionState = WifiConnectionState.WAINTING;
                        break;
                    }
                }
            }
            catch (ThreadAbortException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                wifiInformation("error " + e.Message);
            }
        }
Esempio n. 4
0
        void apConnectMenuItem_Click(object sender, EventArgs e)
        {
            AccessPoint ap = m_selectedItem.Tag as AccessPoint;

            WirelessZeroConfigNetworkInterface wzc = Presenter.WirelessInterface as WirelessZeroConfigNetworkInterface;

            if (apConnectMenuItem.Text == "Connect")
            {
                // is it in our preferred list?  If so, add it
                if ((wzc == null) || (Presenter.IsPreferredAP(ap)))
                {
                    Presenter.WirelessInterface.Connect(ap.Name);
                }
                else
                {
                    // is it an open network?
                    if (ap.Privacy == 0)
                    {
                        wzc.AddPreferredNetwork(ap.Name, true, (byte[])null, 0, AuthenticationMode.Open, WEPStatus.WEPDisabled, null);
                    }
                    else
                    {
                        // TODO:
                        MessageBox.Show("Need to get WEP key from user", "Not Implemented");
                    }
                }
            }
            else
            {
            }
        }
Esempio n. 5
0
        public void WhenCallingWifiAndWirelessZeroConfigNetworkInterfaceExistsShouldReturnTrue()
        {
            var wirelessInterface = new WirelessZeroConfigNetworkInterface();

            NetworkInterface.NetworkInterfaces = new INetworkInterface[] { wirelessInterface };

            Assert.True(this.ConnectionInfo.Wifi);
        }
 public connInfo()
 {
     InitializeComponent();
     myface = (WirelessZeroConfigNetworkInterface)WirelessZeroConfigNetworkInterface.GetAllNetworkInterfaces()[0];
     Timer mymer = new Timer();
     mymer.Tick += new EventHandler(mymer_Tick);
     mymer.Interval = 200;
     mymer.Enabled = true;
 }
Esempio n. 7
0
 /// <summary>
 /// Initialize wi-fi card.
 /// </summary>
 protected WiFiCardInterface()
 {
     foreach (INetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
     {
         if (ni is WirelessNetworkInterface)
         {
             if (ni is WirelessZeroConfigNetworkInterface)
             {
                 wzcController = ni as WirelessZeroConfigNetworkInterface;
             }
             break;
         }
     }
 }
        /// <summary>
        /// Verifica la conexión de la red ad-hoc
        /// </summary>
        internal void checkWLanConnection()
        {
            try
            {
                //Revisa si hay un adaptador seleccionado en la configuración
                if (netData.NetworkAdapter == null)
                {
                    throw new Exception("no hay un adaptador de red seleccionado");
                }

                INetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
                foreach (INetworkInterface networkInterface in networkInterfaces)
                {
                    if (netData.NetworkAdapter.Name.Equals(networkInterface.Name))
                    {
                        WirelessZeroConfigNetworkInterface adapter = (WirelessZeroConfigNetworkInterface)networkInterface;
                        String ssid = adapter.AssociatedAccessPoint;
                        if (ssid == null)
                        {
                            connectionState = WifiConnectionState.DISCONNECTED;
                            wifiInformation("disconnected");
                        }
                        else if (netData.AdhocNetworkName.Equals(ssid) && adapter.OperationalStatus == OperationalStatus.Up && SystemHandler.getIpState(netData.NetworkAdapter, netData.IpTcpListener) != IpState.NOTFOUND)
                        {
                            connectionState = WifiConnectionState.CONNECTED;
                            wifiInformation("connected");
                        }
                        else if (netData.AdhocNetworkName.Equals(ssid) && adapter.OperationalStatus != OperationalStatus.Up)
                        {
                            connectionState = WifiConnectionState.WAINTING;
                            wifiInformation("waiting");
                        }
                        else
                        {
                            connectionState = WifiConnectionState.DISCONNECTED;
                            wifiInformation("disconnected");
                        }
                        break;
                    }
                }
            }
            catch (ThreadAbortException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                wifiInformation("error " + e.Message);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Cambia la IP del sistema operativo al estádo dinámico
        /// Si ocurre un error se arroja la excepción
        /// </summary>
        internal static bool rebindAdapter(NetData netData)
        {
            INetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
            foreach (INetworkInterface networkInterface in networkInterfaces)
            {
                if (netData.NetworkAdapter.Name.Equals(networkInterface.Name))
                {
                    WirelessZeroConfigNetworkInterface adapter = (WirelessZeroConfigNetworkInterface)networkInterface;
                    adapter.Unbind();
                    adapter.Bind();
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 10
0
        /// <summary>
        /// Busca el adaptador de red WIFI
        /// </summary>
        /// <returns>El adaptador de red Wifi</returns>
        public static NetworkAdapter getWifiAdapter()
        {
            try
            {
                Radios radios = Radios.GetRadios();
                foreach (IRadio radio in radios)
                {
                    if (radio.RadioType.Equals(RadioType.WiFi))
                    {
                        WiFiRadio wifiRadio = (WiFiRadio)radio;

                        NetworkAdapter adapter = new NetworkAdapter();
                        adapter.Name        = wifiRadio.DeviceName;
                        adapter.Name        = adapter.Name.Substring(adapter.Name.IndexOf("\\") + 1);
                        adapter.Description = wifiRadio.DisplayName;

                        INetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
                        foreach (INetworkInterface networkInterface in networkInterfaces)
                        {
                            try
                            {
                                WirelessZeroConfigNetworkInterface Wadapter = (WirelessZeroConfigNetworkInterface)networkInterface;
                                adapter.Name        = Wadapter.Name;
                                adapter.Description = Wadapter.Description;
                                break;
                            }
                            catch (Exception)
                            {
                                adapter.Description += "interface NOT FOUND";
                            }
                        }

                        return(adapter);
                    }
                }
                return(null);
            }
            catch (ThreadAbortException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Esempio n. 11
0
        void FindWirelessAdapter()
        {
            bool foundWirelessNIC = false;

            foreach (INetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
            {
                if (ni is WirelessNetworkInterface)
                {
                    // will be true for wireless or WZC
                    adapterName.Text = ni.Name;
                    adapterType.Text = ni.GetType().Name;
                    foundWirelessNIC = true;

                    if (ni is WirelessZeroConfigNetworkInterface)
                    {
                        m_wzc           = ni as WirelessZeroConfigNetworkInterface;
                        refresh.Enabled = true;
                    }
                    else
                    {
                        apList.Items.Add("No WZC adapter found");
                        apList.Items.Add("Cannot retrieve nearby AP list");
                        apList.Enabled = false;
                    }

                    break;
                }
            }

            if (foundWirelessNIC)
            {
                refresh_Click(null, null);
            }
            else
            {
                MessageBox.Show("Could not find a compatible wireless network adapter");
            }
        }
Esempio n. 12
0
        static void Main()
        {
            WirelessZeroConfigNetworkInterface wzc = null;

            foreach (var intf in NetworkInterface.GetAllNetworkInterfaces())
            {
                if (intf is WirelessZeroConfigNetworkInterface)
                {
                    wzc = (WirelessZeroConfigNetworkInterface)intf;
                    break;
                }
            }

            if (wzc == null)
            {
                Output("No WZC adapter found");
                Debugger.Break();
                return;
            }


            int PAD = 20;

            foreach (var ap in wzc.PreferredAccessPoints)
            {
                Output("AP: " + ap.Name);
                Output("\tPrivacy: ".PadRight(PAD, ' ') + ap.Privacy.ToString());
                Output("\tSignal: ".PadRight(PAD, ' ') + ap.SignalStrength);
                Output("\tChannel: ".PadRight(PAD, ' ') + ap.Channel);
            }

            foreach (var ap in wzc.NearbyAccessPoints)
            {
                Output("AP: " + ap.Name);
                Output("\tPrivacy: ".PadRight(PAD, ' ') + ap.Privacy.ToString());
                Output("\tSignal: ".PadRight(PAD, ' ') + ap.SignalStrength);
                Output("\tChannel: ".PadRight(PAD, ' ') + ap.Channel);

                if ((ap.Privacy == WEPStatus.WEPEnabled) && (ap.Name.ToLower().StartsWith("opennetcf")))
                {
                    continue;
                    string key = "badf00d";
                    wzc.AddPreferredNetwork(ap.Name, true, key, 1, AuthenticationMode.Shared, WEPStatus.WEPEnabled, null);
                }
                else if (ap.Privacy == WEPStatus.TKIPEnabled)
                {
                    //continue;

                    string        key = "sharedkey";
                    EAPParameters eap = null;

                    wzc.AddPreferredNetwork(ap.Name, true, key, 1, AuthenticationMode.WPAPSK, WEPStatus.TKIPEnabled, eap);
                }
                else if (ap.Privacy == WEPStatus.AESEnabled)
                {
                    //continue;

                    string        key = "sharedkey";
                    EAPParameters eap = null;

                    wzc.AddPreferredNetwork(ap.Name, true, key, 1, AuthenticationMode.WPA, WEPStatus.AESEnabled, eap);
                }
            }

            Output("Press <ENTER> to continue");

            Console.ReadLine();
//            Application.Run(new Form1());
        }
 public WZCAdapterStateMachine(WirelessZeroConfigNetworkInterface intf)
     : base(intf)
 {
 }
Esempio n. 14
0
        public void WhenCallingWifiAndWirelessZeroConfigNetworkInterfaceExistsShouldReturnTrue()
        {
            var wirelessInterface = new WirelessZeroConfigNetworkInterface();
            NetworkInterface.NetworkInterfaces = new INetworkInterface[] { wirelessInterface };

            Assert.True(this.ConnectionInfo.Wifi);
        }
        public void PreferredOpenInfrastructureAPTest(WirelessZeroConfigNetworkInterface wzc)
        {
            List <string> preferredAPs = new List <string>();

            // get a list of available adapters
            INetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces();

            if (interfaces.Length <= 0)
            {
                Assert.Fail("No interfaces available to test");
            }

            bool wzcFound = false;

            // find the WZC adapter
            foreach (INetworkInterface intf in interfaces)
            {
                if (intf is WirelessZeroConfigNetworkInterface)
                {
                    // run the test
                    wzcFound = true;

                    // get a list of preferred APs
                    foreach (NI.AccessPoint ap in wzc.PreferredAccessPoints)
                    {
                        preferredAPs.Add(ap.Name);
                    }

                    // remove them all
                    foreach (string ssid in preferredAPs)
                    {
                        if (!wzc.RemovePreferredNetwork(ssid))
                        {
                            Assert.Fail("Failed to remove AP " + ssid);
                        }
                    }

                    // make sure the list really got emptied
                    if (wzc.PreferredAccessPoints.Count > 0)
                    {
                        Assert.Fail("Failed to drop all preferred APs");
                    }

                    // make sure we have a nearby AP
                    NI.AccessPointCollection nearbyAPs = wzc.NearbyAccessPoints;
                    if (nearbyAPs.Count <= 0)
                    {
                        // try twice, in case the adapter was not initialized
                        System.Threading.Thread.Sleep(100);
                        nearbyAPs = wzc.NearbyAccessPoints;
                        if (nearbyAPs.Count <= 0)
                        {
                            Assert.Fail("No nearby APs found");
                        }
                    }

                    bool          nearbyFound = false;
                    List <string> nearbyNames = new List <string>();

                    foreach (NI.AccessPoint ap in nearbyAPs)
                    {
                        if (nearbyNames.Contains(ap.Name))
                        {
                            // we can't add two APs with the same name (and different physical addresses)
                            continue;
                        }
                        nearbyNames.Add(ap.Name);

                        if (ap.InfrastructureMode == NI.InfrastructureMode.Infrastructure)
                        {
                            if (ap.Privacy == 0)
                            {
                                // we have found an open, infrastructure AP
                                nearbyFound = true;

                                if (!wzc.AddPreferredNetwork(ap.Name, false, null, 1, NI.AuthenticationMode.Open, NI.WEPStatus.WEPDisabled, null))
                                {
                                    Assert.Fail("Failed to add AP named " + ap.Name);
                                }
                            }
                        }
                    }

                    if (!nearbyFound)
                    {
                        Assert.Fail("No nearby APs found");
                    }

                    // now remove them all again (to ensure we've actually removed something - we could have started with none)
                    preferredAPs.Clear();

                    // get a list of preferred APs
                    foreach (NI.AccessPoint ap in wzc.PreferredAccessPoints)
                    {
                        preferredAPs.Add(ap.Name);
                    }

                    // remove them all
                    foreach (string ssid in preferredAPs)
                    {
                        if (!wzc.RemovePreferredNetwork(ssid))
                        {
                            Assert.Fail("Failed to remove AP " + ssid);
                        }
                    }

                    Assert.IsTrue(wzc.PreferredAccessPoints.Count == 0, "Failed to remove all preferred APs");
                    break;
                }
            }

            if (!wzcFound)
            {
                Assert.Fail("No WZC Adapter found");
            }
        }