[C# Connection] Adding C# Connection code
[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 Class is WiFiProfile
27     /// </summary>
28     public class WiFiProfile : ConnectionProfile
29     {
30         internal WiFiProfile(IntPtr Handle) : base(Handle)
31         {
32         }
33
34         ~WiFiProfile()
35         {
36         }
37
38         /// <summary>
39         /// Gets the ESSID (Extended Service Set Identifier).
40         /// </summary>
41         public string Essid
42         {
43             get
44             {
45                 IntPtr value;
46                 int ret = Interop.ConnectionWiFiProfile.GetEssid(ProfileHandle, out value);
47                 if ((ConnectionError)ret != ConnectionError.None)
48                 {
49                     Log.Error(Globals.LogTag, "It failed to create profile handle, " + (ConnectionError)ret);
50                 }
51                 string result = Marshal.PtrToStringAnsi(value);
52                 Interop.Libc.Free(value);
53                 return result;
54             }
55         }
56
57         /// <summary>
58         ///  Gets the BSSID (Basic Service Set Identifier).
59         /// </summary>
60         public string Bssid
61         {
62             get
63             {
64                 IntPtr value;
65                 int ret = Interop.ConnectionWiFiProfile.GetBssid(ProfileHandle, out value);
66                 if ((ConnectionError)ret != ConnectionError.None)
67                 {
68                     Log.Error(Globals.LogTag, "It failed to get bssid, " + (ConnectionError)ret);
69                 }
70                 string result = Marshal.PtrToStringAnsi(value);
71                 Interop.Libc.Free(value);
72                 return result;
73             }
74         }
75
76         /// <summary>
77         /// Gets the RSSI.
78         /// </summary>
79         public int Rssi
80         {
81             get
82             {
83                 int value;
84                 int ret = Interop.ConnectionWiFiProfile.GetRssi(ProfileHandle, out value);
85                 if ((ConnectionError)ret != ConnectionError.None)
86                 {
87                     Log.Error(Globals.LogTag, "It failed to get rssi, " + (ConnectionError)ret);
88                 }
89                 return value;
90             }
91         }
92
93         /// <summary>
94         /// Gets the frequency (MHz).
95         /// </summary>
96         public int Frequency
97         {
98             get
99             {
100                 int value;
101                 int ret = Interop.ConnectionWiFiProfile.GetFrequency(ProfileHandle, out value);
102                 if ((ConnectionError)ret != ConnectionError.None)
103                 {
104                     Log.Error(Globals.LogTag, "It failed to get frequency, " + (ConnectionError)ret);
105                 }
106                 return value;
107             }
108         }
109
110         /// <summary>
111         /// Gets the max speed (Mbps).
112         /// </summary>
113         public int MaxSpeed
114         {
115             get
116             {
117                 int value;
118                 int ret = Interop.ConnectionWiFiProfile.GetMaxSpeed(ProfileHandle, out value);
119                 if ((ConnectionError)ret != ConnectionError.None)
120                 {
121                     Log.Error(Globals.LogTag, "It failed to get max speed, " + (ConnectionError)ret);
122                 }
123                 return value;
124             }
125         }
126
127         /// <summary>
128         /// Gets the security type of Wi-Fi.
129         /// </summary>
130         public WiFiSecureType SecureType
131         {
132             get
133             {
134                 int value;
135                 int ret = Interop.ConnectionWiFiProfile.GetSecurityType(ProfileHandle, out value);
136                 if ((ConnectionError)ret != ConnectionError.None)
137                 {
138                     Log.Error(Globals.LogTag, "It failed to get security type, " + (ConnectionError)ret);
139                 }
140                 return (WiFiSecureType)value;
141             }
142         }
143
144         /// <summary>
145         /// Gets the encryption type of Wi-Fi.
146         /// </summary>
147         public WiFiEncryptionType EncryptionType
148         {
149             get
150             {
151                 int value;
152                 int ret = Interop.ConnectionWiFiProfile.GetEncryptionType(ProfileHandle, out value);
153                 if ((ConnectionError)ret != ConnectionError.None)
154                 {
155                     Log.Error(Globals.LogTag, "It failed to get encryption type, " + (ConnectionError)ret);
156                 }
157                 return (WiFiEncryptionType)value;
158             }
159         }
160
161         /// <summary>
162         /// Checks whether passphrase is required.
163         /// </summary>
164         public bool PassphraseRequired
165         {
166             get
167             {
168                 bool value;
169                 int ret = Interop.ConnectionWiFiProfile.IsRequiredPassphrase(ProfileHandle, out value);
170                 if ((ConnectionError)ret != ConnectionError.None)
171                 {
172                     Log.Error(Globals.LogTag, "It failed to get PassphraseRequired, " + (ConnectionError)ret);
173                 }
174                 return value;
175             }
176         }
177
178         /// <summary>
179         /// Checks whether the WPS (Wi-Fi Protected Setup) is supported.
180         /// </summary>
181         public bool WpsSupported
182         {
183             get
184             {
185                 bool value;
186                 int ret = Interop.ConnectionWiFiProfile.IsSupportedWps(ProfileHandle, out value);
187                 if ((ConnectionError)ret != ConnectionError.None)
188                 {
189                     Log.Error(Globals.LogTag, "It failed to get IsSupportedWps, " + (ConnectionError)ret);
190                 }
191                 return value;
192             }
193         }
194
195         /// <summary>
196         /// Sets the passphrase of the Wi-Fi WPA.
197         /// </summary>
198         public int SetPassphrase(string passphrase)
199         {
200             int ret = Interop.ConnectionWiFiProfile.SetPassphrase(ProfileHandle, (string)passphrase);
201             if ((ConnectionError)ret != ConnectionError.NoConnection)
202             {
203                 Log.Error(Globals.LogTag, "It failed to set passphrase, " + (ConnectionError)ret);
204                 ConnectionErrorFactory.ThrowConnectionException(ret);
205             }
206             return ret;
207         }
208     }
209 }