Exemple #1
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (_wifi.setProfile(button1.Text) == 0)
     {
         addLog("\r\nsetting Profile " + button1.Text + " enabled");
     }
     else
     {
         addLog("\r\nenable Profile " + button1.Text + " FAILED");
     }
     updateGrid();
 }
Exemple #2
0
        //public connector(string[] profiles)
        public connector()
        {
            //read config values
            _profiles            = new string[] { _myConfig._profile1, _myConfig._profile2 };
            _bcheckOnUndock      = _myConfig._checkOnUndock;
            _bcheckOnResume      = _myConfig._checkOnResume;
            _bswitchOnDisconnect = _myConfig._switchOnDisconnect;
            _iSwitchTimeout      = _myConfig._switchTimeout;
            _benableLogging      = _myConfig._enableLogging;
#if DEBUG
            Logger.bEnableLogging = true;
#else
            Logger.bEnableLogging = _benableLogging;
#endif
            //_profiles = profiles;
            evtStopThreads.Reset(); // clear event

            OnConnectedMessage("connector initialized with profiles: ");
            try
            {
                _wifi = new wifi();
            }
            catch (Exception)
            {
                throw new NotSupportedException("FUNK not active");
            }

            //list profiles and disable all first, only one should be enabled
            //foreach (string s in _profiles)
            //{
            //    OnConnectedMessage("\t" + s);
            //    _wifi.enableProfile(s, false);
            //}
            _wifi.setProfile(_profiles[0]); //enable primary profile

            _workThread      = new Thread(new ThreadStart(myWorkerThread));
            _workThread.Name = "myWorkerThread";
            _workThread.Start();

            _connectThread      = new Thread(new ThreadStart(connectWatchThread));
            _connectThread.Name = "connectWatchThread";
            _connectThread.Start();

            _timerThread      = new Thread(new ThreadStart(timerThread));
            _timerThread.Name = "timerThread";
            _timerThread.Start();

            _PowerSourceMessages = new PowerSourceChanges();
            _PowerSourceMessages.powerChangedEvent += new PowerSourceChanges.powerChangeEventHandler(_powerSourceMessages_powerChangedEvent);

            _PowerMessages = new PowerMessages();
            _PowerMessages.powerChangedEvent += new PowerMessages.powerChangeEventHandler(_PowerMessages_powerChangedEvent);

            OnConnectedMessage("connector started");
        }
Exemple #3
0
        /// <summary>
        /// this function tries to switch to the preferred network
        /// and falls back to second profile if 1st did not connect
        /// </summary>
        void doSwitch()
        {
            if (bInsideSwitch)
            {
                Logger.WriteLine("doSwitch called although already insideSwitch");
                return;
            }
            lock (syncObject)
                bInsideSwitch = true;

            OnConnectedMessage("DoSwitch() start...");
            Logger.WriteLine("DoSwitch() start...");

            int iConnectTry = 0;
            //is first profile active?
            //USES instance or regKey name!
            string currentProfile = _wifi.getCurrentProfile().sProfileRegKey;
            string desiredSSID    = _wifi.getCurrentProfile().sSSID;

            OnConnectedMessage("current profile=" + currentProfile);
            //is the preferred profile active?
            if (currentProfile == _profiles[0])
            {
                OnConnectedMessage("Current Profile = First profile");
                if (network._getConnected() == false)
                { //not connected
                    OnConnectedMessage("network not connected. Switching to 2nd profile...");
                    _wifi.setProfile(_profiles[1]);
                }
                else
                {
                    OnConnectedMessage("network connected. No profile change.");
                }
            }
            else if (_wifi.getCurrentProfile().sProfileRegKey == _profiles[1])
            {
                //TODO: do not use an INDEX use the names as in App.Config
                desiredSSID = _wifi.SSIDsecondary;
                OnConnectedMessage("Current Profile = Second profile");
                if (network._getConnected() == false)
                {
                    OnConnectedMessage("secondary profile not connected");
                }
                else
                {
                    OnConnectedMessage("secondary profile connected");
                }
                //try first profile, regardless of connect state
                OnConnectedMessage("Trying first Profile. Switching ...");
                _wifi.setProfile(_profiles[0]); //enable first profile

                desiredSSID = _wifi.SSIDprimary;

                iConnectTry = 0;
                //try for 40 seconds or so
                while (!_bStopThread && (iConnectTry < _iSwitchTimeout))
                {
                    Thread.Sleep(1000);
                    iConnectTry++;
                    if (_myConfig._checkConnectIP)
                    {
                        if (network._getConnected() == true)    // do not care about AP association
                        {
                            break;
                        }
                    }
                    else //check AP association but not IP
                    {
                        if (wifi.isAssociated(desiredSSID) == true) // do not care about IP
                        {
                            break;
                        }
                    }
                }
                //another test for being connected
                if (network._getConnected() == false)
                {
                    OnConnectedMessage("First Profile did not connect. Switching to secondary profile...");
                    //switch back
                    _wifi.setProfile(_profiles[1]); //enable second profile
                }
                else
                {
                    OnConnectedMessage("primary network connected.");
                }
            }
            else
            {
                OnConnectedMessage("Current profile not in list!");
            }

            lock (syncObject)
                bInsideSwitch = false;
            OnConnectedMessage("DoSwitch() end.");
            Logger.WriteLine("DoSwitch() end.");
        }