Binding KeyboardGrab and KeyboardUnGrab
[platform/core/csapi/tizenfx.git] / src / Tizen.Network.Connection / Tizen.Network.Connection / WiFiProfile.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18 using System.Collections.Generic;
19 using System.Linq;
20 using System.Text;
21 using System.Runtime.InteropServices;
22
23 namespace Tizen.Network.Connection
24 {
25     /// <summary>
26     /// This is the WiFiProfile class. It provides functions to manage the WiFi profile.
27     /// </summary>
28     /// <since_tizen> 3 </since_tizen>
29     public class WiFiProfile : ConnectionProfile
30     {
31         internal WiFiProfile(IntPtr Handle) : base(Handle)
32         {
33         }
34
35         /// <summary>
36         /// Destroy the WiFiProfile object
37         /// </summary>
38         ~WiFiProfile()
39         {
40         }
41
42         /// <summary>
43         /// The ESSID (Extended Service Set Identifier).
44         /// </summary>
45         /// <since_tizen> 3 </since_tizen>
46         /// <value>ESSID of the WiFi.</value>
47         public string Essid
48         {
49             get
50             {
51                 IntPtr value;
52                 int ret = Interop.ConnectionWiFiProfile.GetEssid(ProfileHandle, out value);
53                 if ((ConnectionError)ret != ConnectionError.None)
54                 {
55                     Log.Error(Globals.LogTag, "It failed to create profile handle, " + (ConnectionError)ret);
56                 }
57                 string result = Marshal.PtrToStringAnsi(value);
58                 Interop.Libc.Free(value);
59                 return result;
60             }
61         }
62
63         /// <summary>
64         /// The BSSID (Basic Service Set Identifier).
65         /// </summary>
66         /// <since_tizen> 3 </since_tizen>
67         /// <value>BSSID of the WiFi.</value>
68         public string Bssid
69         {
70             get
71             {
72                 IntPtr value;
73                 int ret = Interop.ConnectionWiFiProfile.GetBssid(ProfileHandle, out value);
74                 if ((ConnectionError)ret != ConnectionError.None)
75                 {
76                     Log.Error(Globals.LogTag, "It failed to get bssid, " + (ConnectionError)ret);
77                 }
78                 string result = Marshal.PtrToStringAnsi(value);
79                 Interop.Libc.Free(value);
80                 return result;
81             }
82         }
83
84         /// <summary>
85         /// The RSSI.
86         /// </summary>
87         /// <since_tizen> 3 </since_tizen>
88         /// <value>RSSI of the WiFi.</value>
89         public int Rssi
90         {
91             get
92             {
93                 int value;
94                 int ret = Interop.ConnectionWiFiProfile.GetRssi(ProfileHandle, out value);
95                 if ((ConnectionError)ret != ConnectionError.None)
96                 {
97                     Log.Error(Globals.LogTag, "It failed to get rssi, " + (ConnectionError)ret);
98                 }
99                 return value;
100             }
101         }
102
103         /// <summary>
104         /// The frequency (MHz).
105         /// </summary>
106         /// <since_tizen> 3 </since_tizen>
107         /// <value>Frequency of the WiFi.</value>
108         public int Frequency
109         {
110             get
111             {
112                 int value;
113                 int ret = Interop.ConnectionWiFiProfile.GetFrequency(ProfileHandle, out value);
114                 if ((ConnectionError)ret != ConnectionError.None)
115                 {
116                     Log.Error(Globals.LogTag, "It failed to get frequency, " + (ConnectionError)ret);
117                 }
118                 return value;
119             }
120         }
121
122         /// <summary>
123         /// The max speed (Mbps).
124         /// </summary>
125         /// <since_tizen> 3 </since_tizen>
126         /// <value>Maximum speed of the WiFi.</value>
127         public int MaxSpeed
128         {
129             get
130             {
131                 int value;
132                 int ret = Interop.ConnectionWiFiProfile.GetMaxSpeed(ProfileHandle, out value);
133                 if ((ConnectionError)ret != ConnectionError.None)
134                 {
135                     Log.Error(Globals.LogTag, "It failed to get max speed, " + (ConnectionError)ret);
136                 }
137                 return value;
138             }
139         }
140
141         /// <summary>
142         /// The security type of WiFi.
143         /// </summary>
144         /// <since_tizen> 3 </since_tizen>
145         /// <value>Security type of the WiFi.</value>
146         public WiFiSecurityType SecurityType
147         {
148             get
149             {
150                 int value;
151                 int ret = Interop.ConnectionWiFiProfile.GetSecurityType(ProfileHandle, out value);
152                 if ((ConnectionError)ret != ConnectionError.None)
153                 {
154                     Log.Error(Globals.LogTag, "It failed to get security type, " + (ConnectionError)ret);
155                 }
156                 return (WiFiSecurityType)value;
157             }
158         }
159
160         /// <summary>
161         /// The encryption type of WiFi.
162         /// </summary>
163         /// <since_tizen> 3 </since_tizen>
164         /// <value>Encryption mode of the WiFi.</value>
165         public WiFiEncryptionType EncryptionType
166         {
167             get
168             {
169                 int value;
170                 int ret = Interop.ConnectionWiFiProfile.GetEncryptionType(ProfileHandle, out value);
171                 if ((ConnectionError)ret != ConnectionError.None)
172                 {
173                     Log.Error(Globals.LogTag, "It failed to get encryption type, " + (ConnectionError)ret);
174                 }
175                 return (WiFiEncryptionType)value;
176             }
177         }
178
179         /// <summary>
180         /// Checks whether passphrase is required.
181         /// </summary>
182         /// <since_tizen> 3 </since_tizen>
183         /// <value>True if a passphrase is required, otherwise false.</value>
184         /// <remarks>This property is not valid if <c>WiFiSecurityType</c> is <c>Eap</c>.</remarks>
185         public bool PassphraseRequired
186         {
187             get
188             {
189                 bool value;
190                 int ret = Interop.ConnectionWiFiProfile.IsRequiredPassphrase(ProfileHandle, out value);
191                 if ((ConnectionError)ret != ConnectionError.None)
192                 {
193                     Log.Error(Globals.LogTag, "It failed to get PassphraseRequired, " + (ConnectionError)ret);
194                 }
195                 return value;
196             }
197         }
198
199         /// <summary>
200         /// Checks whether the WPS (Wi-Fi Protected Setup) is supported.
201         /// </summary>
202         /// <since_tizen> 3 </since_tizen>
203         /// <value>True if WPS is supported, otherwise false.</value>
204         public bool WpsSupported
205         {
206             get
207             {
208                 bool value;
209                 int ret = Interop.ConnectionWiFiProfile.IsSupportedWps(ProfileHandle, out value);
210                 if ((ConnectionError)ret != ConnectionError.None)
211                 {
212                     Log.Error(Globals.LogTag, "It failed to get IsSupportedWps, " + (ConnectionError)ret);
213                 }
214                 return value;
215             }
216         }
217
218         /// <summary>
219         /// Sets the passphrase of the Wi-Fi WPA.
220         /// </summary>
221         /// <since_tizen> 3 </since_tizen>
222         /// <param name="passphrase">The passphrase of Wi-Fi security.</param>
223         /// <feature>http://tizen.org/feature/network.wifi</feature>
224         /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
225         /// <exception cref="System.ArgumentException">Thrown when a value is an invalid parameter.</exception>
226         /// <exception cref="System.ArgumentNullException">Thrown when a passphrase is null.</exception>
227         /// <exception cref="System.InvalidOperationException">Thrown when a profile instance is invalid or when a method fails due to an invalid operation.</exception>
228         /// <exception cref="System.ObjectDisposedException">Thrown when an operation is performed on a disposed object.</exception>
229         public void SetPassphrase(string passphrase)
230         {
231             CheckDisposed();
232             if (passphrase != null)
233             {
234                 int ret = Interop.ConnectionWiFiProfile.SetPassphrase(ProfileHandle, passphrase);
235                 if ((ConnectionError)ret != ConnectionError.None)
236                 {
237                     Log.Error(Globals.LogTag, "It failed to set passphrase, " + (ConnectionError)ret);
238                     ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.wifi");
239                     ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released");
240                     ConnectionErrorFactory.ThrowConnectionException(ret);
241                 }
242             }
243
244             else
245             {
246                 throw new ArgumentNullException("Value of passphrase is null");
247             }
248         }
249     }
250 }