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.
18 using System.Collections.Generic;
21 using System.Threading.Tasks;
22 using System.Runtime.InteropServices;
24 namespace Tizen.Network.Connection
27 /// This Class is RequestWiFiProfile
29 public class RequestWiFiProfile : RequestProfile
31 internal IntPtr ProfileHandle = IntPtr.Zero;
32 private IAddressInformation Ipv4;
33 private IAddressInformation Ipv6;
34 private bool disposed = false;
37 /// The constructor of WiFiProfile class with profile type and keyword.
39 /// <privilege>http://tizen.org/privilege/network.get</privilege>
40 public RequestWiFiProfile(string keyword)
42 Log.Debug(Globals.LogTag, "RequestWiFiProfile : " + keyword);
43 ProfileHandle = ConnectionInternalManager.CreateRequestProfile(ConnectionProfileType.WiFi, keyword);
45 Ipv4 = AddressFactory.CreateAddressInformation(ProfileHandle, AddressFamily.Ipv4, AddressInformationType.Connection);
46 Ipv6 = AddressFactory.CreateAddressInformation(ProfileHandle, AddressFamily.Ipv6, AddressInformationType.Connection);
50 /// The destructor of WiFiProfile class
59 GC.SuppressFinalize(this);
62 private void Dispose(bool disposing)
69 // Free managed objects.
71 Interop.ConnectionProfile.Destroy(ProfileHandle);
76 /// Gets the network type.
78 public ConnectionProfileType Type
83 int ret = Interop.ConnectionProfile.GetType(ProfileHandle, out Value);
84 if ((ConnectionError)ret != ConnectionError.None)
86 Log.Error(Globals.LogTag, "It failed to get profile type, " + (ConnectionError)ret);
88 return (ConnectionProfileType)Value;
93 /// Gets the Proxy type.
95 public ProxyType ProxyType
100 int ret = Interop.ConnectionProfile.GetProxyType(ProfileHandle, out Value);
101 if ((ConnectionError)ret != ConnectionError.None)
103 Log.Error(Globals.LogTag, "It failed to get proxy type, " + (ConnectionError)ret);
105 return (ProxyType)Value;
110 int ret = Interop.ConnectionProfile.SetProxyType(ProfileHandle, (int)value);
111 if ((ConnectionError)ret != ConnectionError.None)
113 Log.Error(Globals.LogTag, "It failed to set proxy type, " + (ConnectionError)ret);
114 ConnectionErrorFactory.ThrowConnectionException(ret);
120 /// The proxy address.
122 public System.Net.IPAddress ProxyAddress
127 int ret = Interop.ConnectionProfile.GetProxyAddress(ProfileHandle, (int)AddressFamily.Ipv4, out Value);
128 if ((ConnectionError)ret != ConnectionError.None)
130 Log.Error(Globals.LogTag, "It failed to get proxy address, " + (ConnectionError)ret);
132 string result = Marshal.PtrToStringAnsi(Value);
133 Interop.Libc.Free(Value);
135 return System.Net.IPAddress.Parse("0.0.0.0");
136 return System.Net.IPAddress.Parse(result);
141 int ret = Interop.ConnectionProfile.SetProxyAddress(ProfileHandle, (int)AddressFamily.Ipv4, value.ToString());
142 if ((ConnectionError)ret != ConnectionError.None)
144 Log.Error(Globals.LogTag, "It failed to set proxy address, " + (ConnectionError)ret);
145 ConnectionErrorFactory.ThrowConnectionException(ret);
151 /// The subnet mask address(Ipv4).
153 public IAddressInformation Ipv4Settings
163 /// The subnet mask address(Ipv4).
165 public IAddressInformation Ipv6Settings
175 /// Sets the passphrase of the Wi-Fi WPA.
177 public int SetPassphrase(string passphrase)
179 int ret = Interop.ConnectionWiFiProfile.SetPassphrase(ProfileHandle, (string)passphrase);
180 if ((ConnectionError)ret != ConnectionError.None)
182 Log.Error(Globals.LogTag, "It failed to set passphrase, " + (ConnectionError)ret);
183 ConnectionErrorFactory.ThrowConnectionException(ret);