2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using System.Threading.Tasks;
20 using System.Runtime.InteropServices;
21 using Tizen.Network.Connection;
23 namespace Tizen.Network.WiFi
26 /// A class for managing the configuration of Wi-Fi.
28 /// <since_tizen> 3 </since_tizen>
29 public class WiFiConfiguration : IDisposable
31 private IntPtr _configHandle = IntPtr.Zero;
32 private bool _disposed = false;
33 private WiFiEapConfiguration _eapConfig;
36 /// The name of the access point (AP).
38 /// <since_tizen> 3 </since_tizen>
39 /// <value>Name assigned to AP in the Wi-Fi configuration.</value>
45 int ret = Interop.WiFi.Config.GetName(_configHandle, out strPtr);
46 if (ret != (int)WiFiError.None)
48 Log.Error(Globals.LogTag, "Failed to get name, Error - " + (WiFiError)ret);
51 return Marshal.PtrToStringAnsi(strPtr);
56 /// The security type of the access point (AP).
58 /// <since_tizen> 3 </since_tizen>
59 /// <value>Security type of AP in the Wi-Fi configuration.</value>
60 public WiFiSecurityType SecurityType
65 int ret = Interop.WiFi.Config.GetSecurityType(_configHandle, out type);
66 if (ret != (int)WiFiError.None)
68 Log.Error(Globals.LogTag, "Failed to get security type, Error - " + (WiFiError)ret);
70 return (WiFiSecurityType)type;
75 /// The proxy address.
77 /// <since_tizen> 3 </since_tizen>
78 /// <value>Proxy address of the access point.</value>
79 /// <exception cref="NotSupportedException">Thrown while setting this property when Wi-Fi is not supported.</exception>
80 /// <exception cref="ArgumentException">Thrown while setting this property due to an invalid parameter.</exception>
81 /// <exception cref="InvalidOperationException">Thrown while setting this value due to an invalid operation.</exception>
82 public string ProxyAddress
88 int ret = Interop.WiFi.Config.GetProxyAddress(_configHandle, out addressFamily, out strPtr);
89 if (ret != (int)WiFiError.None)
91 Log.Error(Globals.LogTag, "Failed to get proxy address, Error - " + (WiFiError)ret);
94 return Marshal.PtrToStringAnsi(strPtr);
100 throw new ObjectDisposedException("Invalid WiFiConfiguration instance (Object may have been disposed or released)");
102 int ret = Interop.WiFi.Config.SetProxyAddress(_configHandle, (int)AddressFamily.IPv4, value);
103 if (ret != (int)WiFiError.None)
105 Log.Error(Globals.LogTag, "Failed to set proxy address, Error - " + (WiFiError)ret);
106 WiFiErrorFactory.ThrowWiFiException(ret, _configHandle);
112 /// A property check whether the access point (AP) is hidden.
114 /// <since_tizen> 3 </since_tizen>
115 /// <value>Boolean value indicating whether the AP is hidden.</value>
116 /// <exception cref="NotSupportedException">Thrown while setting this property when the Wi-Fi is not supported.</exception>
117 /// <exception cref="ArgumentException">Thrown while setting this property due to an invalid parameter.</exception>
118 /// <exception cref="InvalidOperationException">Thrown while setting this value due to an invalid operation.</exception>
124 int ret = Interop.WiFi.Config.GetHiddenAPProperty(_configHandle, out hidden);
125 if (ret != (int)WiFiError.None)
127 Log.Error(Globals.LogTag, "Failed to get isHidden, Error - " + (WiFiError)ret);
135 throw new ObjectDisposedException("Invalid WiFiConfiguration instance (Object may have been disposed or released)");
137 int ret = Interop.WiFi.Config.SetHiddenAPProperty(_configHandle, value);
138 if (ret != (int)WiFiError.None)
140 Log.Error(Globals.LogTag, "Failed to set IsHidden, Error - " + (WiFiError)ret);
141 WiFiErrorFactory.ThrowWiFiException(ret, _configHandle);
147 /// EAP configuration.
149 /// <since_tizen> 3 </since_tizen>
150 /// <value>EAP configuration assigned to the Wi-Fi.</value>
151 public WiFiEapConfiguration EapConfiguration
159 internal WiFiConfiguration(IntPtr handle)
161 _configHandle = handle;
162 Interop.WiFi.SafeWiFiConfigHandle configHandle = new Interop.WiFi.SafeWiFiConfigHandle(handle);
163 _eapConfig = new WiFiEapConfiguration(configHandle);
167 /// Creates a WiFiConfiguration object with the given name, passphrase, and securetype.
169 /// <since_tizen> 3 </since_tizen>
170 /// <param name="name">Name of the Wi-Fi.</param>
171 /// <param name="passPhrase">Password to access the Wi-Fi.</param>
172 /// <param name="type">Security type of the Wi-Fi.</param>
173 /// <feature>http://tizen.org/feature/network.wifi</feature>
174 /// <privilege>http://tizen.org/privilege/network.get</privilege>
175 /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
176 /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
177 /// <exception cref="ArgumentNullException">Thrown when the object is constructed with name as null.</exception>
178 /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception>
179 /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
180 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
181 public WiFiConfiguration(string name, string passPhrase, WiFiSecurityType type)
185 throw new ArgumentNullException("Name of the WiFi is null");
188 int ret = Interop.WiFi.Config.Create(WiFiManagerImpl.Instance.GetSafeHandle(), name, passPhrase, (int)type, out _configHandle);
189 if (ret != (int)WiFiError.None)
191 Log.Error(Globals.LogTag, "Failed to create config handle, Error - " + (WiFiError)ret);
192 WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle());
195 Interop.WiFi.SafeWiFiConfigHandle configHandle = new Interop.WiFi.SafeWiFiConfigHandle(_configHandle);
196 _eapConfig = new WiFiEapConfiguration(configHandle);
200 /// Destroy of the WiFiConfiguration object
208 /// A method to destroy the managed objects in the WiFiConfiguration.
210 /// <since_tizen> 3 </since_tizen>
211 public void Dispose()
214 GC.SuppressFinalize(this);
217 private void Dispose(bool disposing)
222 Interop.WiFi.Config.Destroy(_configHandle);
223 _configHandle = IntPtr.Zero;
227 internal IntPtr GetHandle()
229 return _configHandle;
231 } //WiFiNetworkConfiguratin