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.Runtime.InteropServices;
23 namespace Tizen.Network.Connection
26 /// This Class is CellularProfile
28 public class CellularProfile : ConnectionProfile
30 private CellularAuthInformation AuthInfo;
32 internal CellularProfile(IntPtr handle): base(handle)
34 AuthInfo = new CellularAuthInformation(handle);
42 /// Gets the APN (access point name).
49 int ret = Interop.ConnectionCellularProfile.GetApn(ProfileHandle, out Value);
50 if ((ConnectionError)ret != ConnectionError.None)
52 Log.Error(Globals.LogTag, "It failed to get apn, " + (ConnectionError)ret);
54 string result = Marshal.PtrToStringAnsi(Value);
55 Interop.Libc.Free(Value);
60 int ret = Interop.ConnectionCellularProfile.SetApn(ProfileHandle, (string)value);
61 if ((ConnectionError)ret != ConnectionError.None)
63 Log.Error(Globals.LogTag, "It failed to set apn, " + (ConnectionError)ret);
64 ConnectionErrorFactory.ThrowConnectionException(ret);
70 /// Gets the home URL.
77 int ret = Interop.ConnectionCellularProfile.GetHomeUrl(ProfileHandle, out Value);
78 if ((ConnectionError)ret != ConnectionError.None)
80 Log.Error(Globals.LogTag, "It failed to get home url, " + (ConnectionError)ret);
82 string result = Marshal.PtrToStringAnsi(Value);
83 Interop.Libc.Free(Value);
88 int ret = Interop.ConnectionCellularProfile.SetHomeUrl(ProfileHandle, (string)value);
89 if ((ConnectionError)ret != ConnectionError.None)
91 Log.Error(Globals.LogTag, "It failed to set home url, " + (ConnectionError)ret);
92 ConnectionErrorFactory.ThrowConnectionException(ret);
99 /// Gets the service type.
101 public CellularServiceType ServiceType
106 int ret = Interop.ConnectionCellularProfile.GetServiceType(ProfileHandle, out value);
107 if ((ConnectionError)ret != ConnectionError.None)
109 Log.Error(Globals.LogTag, "It failed to get service type, " + (ConnectionError)ret);
111 return (CellularServiceType)value;
115 int ret = Interop.ConnectionCellularProfile.SetServiceType(ProfileHandle, (int)value);
116 if ((ConnectionError)ret != ConnectionError.None)
118 Log.Error(Globals.LogTag, "It failed to set service type, " + (ConnectionError)ret);
119 ConnectionErrorFactory.ThrowConnectionException(ret);
125 /// Gets cellular Authentification Information.
127 public CellularAuthInformation CellularAuthInfo
136 /// Checks whether the profile is hidden.
143 int ret = Interop.ConnectionCellularProfile.IsHidden(ProfileHandle, out value);
144 if ((ConnectionError)ret != ConnectionError.None)
146 Log.Error(Globals.LogTag, "It failed to get hidden value, " + (ConnectionError)ret);
153 /// Checks whether the profile is editable.
160 int ret = Interop.ConnectionCellularProfile.IsEditable(ProfileHandle, out value);
161 if ((ConnectionError)ret != ConnectionError.None)
163 Log.Error(Globals.LogTag, "It failed to get editable value, " + (ConnectionError)ret);
170 /// Checks whether the profile is default.
172 public bool IsDefault
177 int ret = Interop.ConnectionCellularProfile.IsDefault(ProfileHandle, out value);
178 if ((ConnectionError)ret != ConnectionError.None)
180 Log.Error(Globals.LogTag, "It failed to get IsDefault value, " + (ConnectionError)ret);
188 /// The authentication information.
190 public class CellularAuthInformation
192 private IntPtr ProfileHandle;
194 private string Name = "";
195 private string Passwd = "";
196 private CellularAuthType AuthenType = CellularAuthType.None;
198 internal CellularAuthInformation(IntPtr handle)
200 ProfileHandle = handle;
206 public string UserName
214 int ret = Interop.ConnectionCellularProfile.GetAuthInfo(ProfileHandle, out type, out name, out password);
215 if ((ConnectionError)ret != ConnectionError.None)
217 Log.Error(Globals.LogTag, "It failed to get auth information, " + (ConnectionError)ret);
220 Name = Marshal.PtrToStringAnsi(name);
221 Passwd = Marshal.PtrToStringAnsi(name);
222 AuthenType = (CellularAuthType)type;
224 Interop.Libc.Free(name);
225 Interop.Libc.Free(password);
232 int ret = Interop.ConnectionCellularProfile.SetAuthInfo(ProfileHandle, (int)AuthenType, (string)value, Passwd);
233 Log.Error(Globals.LogTag, "UserName : "+ value);
234 if ((ConnectionError)ret != ConnectionError.None)
236 Log.Error(Globals.LogTag, "It failed to set auth information, " + (ConnectionError)ret);
237 ConnectionErrorFactory.ThrowConnectionException(ret);
245 public string Password
253 int ret = Interop.ConnectionCellularProfile.GetAuthInfo(ProfileHandle, out type, out name, out password);
254 if ((ConnectionError)ret != ConnectionError.None)
256 Log.Error(Globals.LogTag, "It failed to get auth information, " + (ConnectionError)ret);
258 Name = Marshal.PtrToStringAnsi(name);
259 Passwd = Marshal.PtrToStringAnsi(password);
260 AuthenType = (CellularAuthType)type;
262 Interop.Libc.Free(name);
263 Interop.Libc.Free(password);
270 int ret = Interop.ConnectionCellularProfile.SetAuthInfo(ProfileHandle, (int)AuthenType, Name, (string)value);
271 if ((ConnectionError)ret != ConnectionError.None)
273 Log.Error(Globals.LogTag, "It failed to set auth information, " + (ConnectionError)ret);
274 ConnectionErrorFactory.ThrowConnectionException(ret);
280 /// The authentication type
282 public CellularAuthType AuthType
290 int ret = Interop.ConnectionCellularProfile.GetAuthInfo(ProfileHandle, out type, out name, out password);
291 if ((ConnectionError)ret != ConnectionError.None)
293 Log.Error(Globals.LogTag, "It failed to get auth information, " + (ConnectionError)ret);
296 Name = Marshal.PtrToStringAnsi(name);
297 Passwd = Marshal.PtrToStringAnsi(name);
298 AuthenType = (CellularAuthType)type;
300 Interop.Libc.Free(name);
301 Interop.Libc.Free(password);
307 int ret = Interop.ConnectionCellularProfile.SetAuthInfo(ProfileHandle, (int)value, Name, Passwd);
308 if ((ConnectionError)ret != ConnectionError.None)
310 Log.Error(Globals.LogTag, "It failed to set auth information, " + (ConnectionError)ret);
311 ConnectionErrorFactory.ThrowConnectionException(ret);