コード例 #1
0
ファイル: WiFiManagerImpl.cs プロジェクト: prjung/TizenFX
        internal IEnumerable <WiFiAP> GetFoundSpecificAPs()
        {
            Log.Debug(Globals.LogTag, "GetFoundSpecificAPs");
            List <WiFiAP> apList = new List <WiFiAP>();

            Interop.WiFi.HandleCallback callback = (IntPtr apHandle, IntPtr userData) =>
            {
                if (apHandle != IntPtr.Zero)
                {
                    IntPtr clonedHandle;
                    Interop.WiFi.AP.Clone(out clonedHandle, apHandle);
                    WiFiAP apItem = new WiFiAP(clonedHandle);
                    apList.Add(apItem);
                    return(true);
                }
                return(false);
            };

            int ret = Interop.WiFi.GetForeachFoundSpecificAPs(GetSafeHandle(), callback, IntPtr.Zero);

            if (ret != (int)WiFiError.None)
            {
                Log.Error(Globals.LogTag, "Failed to get specific APs, Error - " + (WiFiError)ret);
                WiFiErrorFactory.ThrowWiFiException(ret, GetSafeHandle().DangerousGetHandle(), "http://tizen.org/privilege/network.get");
            }

            return(apList);
        }
コード例 #2
0
        internal WiFiAP GetConnectedAP()
        {
            Log.Info(Globals.LogTag, "GetConnectedAP");
            IntPtr apHandle;
            int    ret = Interop.WiFi.GetConnectedAP(GetSafeHandle(), out apHandle);

            if (ret != (int)WiFiError.None)
            {
                if (ret == (int)WiFiError.NoConnectionError)
                {
                    Log.Error(Globals.LogTag, "No connection " + (WiFiError)ret);
                    return(null);
                }
                else if (ret == (int)WiFiError.InvalidParameterError)
                {
                    throw new InvalidOperationException("Invalid handle");
                }
                else
                {
                    Log.Error(Globals.LogTag, "Failed to get connected AP, Error - " + (WiFiError)ret);
                    WiFiErrorFactory.ThrowWiFiException(ret, GetSafeHandle().DangerousGetHandle(), "http://tizen.org/privilege/network.get");
                }
            }
            WiFiAP ap = new WiFiAP(apHandle);

            return(ap);
        }
コード例 #3
0
ファイル: WiFiAP.cs プロジェクト: shulgaalexey/TizenFX
        /// <summary>
        /// Connects the access point with WPS without SSID asynchronously.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <param name="info">A WpsInfo instance which is of type WpsPbcInfo or WpsPinInfo.</param>
        /// <returns>A task which contains Connected access point information.</returns>
        /// <remarks>
        /// If WpsPinInfo is used, its object has to be constructed with a pin which must be 4 or 8 characters long.
        /// </remarks>
        /// <feature>http://tizen.org/feature/network.wifi</feature>
        /// <privilege>http://tizen.org/privilege/network.set</privilege>
        /// <privilege>http://tizen.org/privilege/network.get</privilege>
        /// <privilege>http://tizen.org/privilege/network.profile</privilege>
        /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
        /// <exception cref="ArgumentNullException">Thrown when the WpsPinInfo object is constructed with a null pin.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when the WpsPinInfo object is constructed with a pin which is not of 4 or 8 characters long.</exception>
        /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception>
        /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
        public static Task <WiFiAP> ConnectWpsWithoutSsidAsync(WpsInfo info)
        {
            TaskCompletionSource <WiFiAP> task = new TaskCompletionSource <WiFiAP>();
            IntPtr id;

            lock (s_callbackMap)
            {
                id = (IntPtr)s_requestId++;
                s_callbackMap[id] = (error, key) =>
                {
                    Log.Debug(Globals.LogTag, "Connecting by WPS finished");
                    if (error != (int)WiFiError.None)
                    {
                        Log.Error(Globals.LogTag, "Error occurs during WiFi connecting, " + (WiFiError)error);
                        task.SetException(new InvalidOperationException("Error occurs during WiFi connecting, " + (WiFiError)error));
                    }
                    else
                    {
                        WiFiAP ap = WiFiManagerImpl.Instance.GetConnectedAP();
                        task.SetResult(ap);
                    }
                    lock (s_callbackMap)
                    {
                        s_callbackMap.Remove(key);
                    }
                };
            }

            int ret = -1;

            if (info.GetType() == typeof(WpsPbcInfo))
            {
                ret = Interop.WiFi.ConnectByWpsPbcWithoutSsid(WiFiManagerImpl.Instance.GetSafeHandle(), s_callbackMap[id], id);
            }

            else if (info.GetType() == typeof(WpsPinInfo))
            {
                WpsPinInfo pinInfo = (WpsPinInfo)info;
                if (pinInfo.GetWpsPin() == null)
                {
                    throw new ArgumentNullException("Wps pin should not be null");
                }

                if (pinInfo.GetWpsPin().Length != 4 && pinInfo.GetWpsPin().Length != 8)
                {
                    throw new ArgumentOutOfRangeException("Wps pin should be of 4 or 8 characters long");
                }

                ret = Interop.WiFi.ConnectByWpsPinWithoutSsid(WiFiManagerImpl.Instance.GetSafeHandle(), pinInfo.GetWpsPin(), s_callbackMap[id], id);
            }

            if (ret != (int)WiFiError.None)
            {
                Log.Error(Globals.LogTag, "Failed to connect wifi, Error - " + (WiFiError)ret);
                WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle());
            }

            return(task.Task);
        }
コード例 #4
0
        internal ConnectionStateChangedEventArgs(WiFiConnectionState s, IntPtr apHandle)
        {
            _state = s;
            IntPtr clonedHandle;

            Interop.WiFi.AP.Clone(out clonedHandle, apHandle);
            _ap = new WiFiAP(clonedHandle);
        }
コード例 #5
0
        internal WiFiAP GetConnectedAP()
        {
            Log.Info(Globals.LogTag, "GetConnectedAP");
            IntPtr apHandle;
            int    ret = Interop.WiFi.GetConnectedAP(GetSafeHandle(), out apHandle);

            if (ret == (int)WiFiError.NoConnectionError)
            {
                Log.Error(Globals.LogTag, "No connection " + (WiFiError)ret);
                return(null);
            }
            CheckReturnValue(ret, "GetConnectedAP", PrivilegeNetworkGet);
            WiFiAP ap = new WiFiAP(apHandle);

            return(ap);
        }
コード例 #6
0
        internal IEnumerable <WiFiAP> GetFoundBssids()
        {
            Log.Info(Globals.LogTag, "GetFoundBssids");
            List <WiFiAP> apList = new List <WiFiAP>();

            Interop.WiFi.HandleCallback callback = (IntPtr apHandle, IntPtr userData) =>
            {
                if (apHandle != IntPtr.Zero)
                {
                    IntPtr clonedHandle;
                    Interop.WiFi.AP.Clone(out clonedHandle, apHandle);
                    WiFiAP apItem = new WiFiAP(clonedHandle);
                    apList.Add(apItem);
                    return(true);
                }
                return(false);
            };

            int ret = Interop.WiFi.GetForeachFoundBssids(GetSafeHandle(), callback, IntPtr.Zero);

            CheckReturnValue(ret, "GetForeachFoundBssids", PrivilegeNetworkGet);

            return(apList);
        }
コード例 #7
0
 internal ConnectionStateChangedEventArgs(WiFiConnectionState s, IntPtr apHandle)
 {
     _state = s;
     _ap    = new WiFiAP(apHandle);
 }