From 8534679b71701f4883e058efa5451ae1debb53e9 Mon Sep 17 00:00:00 2001 From: Yu Jiung Date: Thu, 22 Dec 2016 16:40:54 +0900 Subject: [PATCH] [C# Wi-Fi] Adding C# Wi-Fi code Change-Id: Ic107d5cda39e6617eabe69b5f143a5a0aab47ea4 Signed-off-by: Yu jiung --- LICENSE | 202 ++++++++ Tizen.Network.WiFi/Interop/Interop.Libraries.cs | 25 + Tizen.Network.WiFi/Interop/Interop.WiFi.cs | 254 ++++++++++ Tizen.Network.WiFi/Properties/AssemblyInfo.cs | 36 ++ Tizen.Network.WiFi/Tizen.Network.WiFi.Net45.csproj | 81 +++ .../Tizen.Network.WiFi.Net45.project.json | 12 + Tizen.Network.WiFi/Tizen.Network.WiFi.csproj | 90 ++++ Tizen.Network.WiFi/Tizen.Network.WiFi.nuspec | 22 + Tizen.Network.WiFi/Tizen.Network.WiFi.project.json | 10 + Tizen.Network.WiFi/Tizen.Network.WiFi.sln | 22 + Tizen.Network.WiFi/Tizen.Network.WiFi.snk | Bin 0 -> 596 bytes .../ConnectionStateChangedEventArgs.cs | 55 ++ .../DeviceStateChangedEventArgs.cs | 44 ++ Tizen.Network.WiFi/Tizen.Network.WiFi/IWiFiEap.cs | 39 ++ .../RssiLevelChangedEventArgs.cs | 43 ++ .../Tizen.Network.WiFi/WiFiAddressInformation.cs | 205 ++++++++ Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiAp.cs | 148 ++++++ .../Tizen.Network.WiFi/WiFiConfiguration.cs | 174 +++++++ Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiEap.cs | 255 ++++++++++ .../Tizen.Network.WiFi/WiFiEapConfiguration.cs | 250 +++++++++ .../Tizen.Network.WiFi/WiFiEnumerations.cs | 161 ++++++ .../Tizen.Network.WiFi/WiFiErrorFactory.cs | 85 ++++ .../Tizen.Network.WiFi/WiFiManager.cs | 260 ++++++++++ .../Tizen.Network.WiFi/WiFiManagerImpl.cs | 564 +++++++++++++++++++++ .../Tizen.Network.WiFi/WiFiNetwork.cs | 286 +++++++++++ .../Tizen.Network.WiFi/WiFiNetworkChange.cs | 254 ++++++++++ .../Tizen.Network.WiFi/WiFiSecurity.cs | 173 +++++++ packaging/csapi-network-wifi.manifest | 5 + packaging/csapi-network-wifi.spec | 45 ++ 29 files changed, 3800 insertions(+) create mode 100644 LICENSE create mode 100644 Tizen.Network.WiFi/Interop/Interop.Libraries.cs create mode 100644 Tizen.Network.WiFi/Interop/Interop.WiFi.cs create mode 100644 Tizen.Network.WiFi/Properties/AssemblyInfo.cs create mode 100644 Tizen.Network.WiFi/Tizen.Network.WiFi.Net45.csproj create mode 100644 Tizen.Network.WiFi/Tizen.Network.WiFi.Net45.project.json create mode 100644 Tizen.Network.WiFi/Tizen.Network.WiFi.csproj create mode 100644 Tizen.Network.WiFi/Tizen.Network.WiFi.nuspec create mode 100644 Tizen.Network.WiFi/Tizen.Network.WiFi.project.json create mode 100644 Tizen.Network.WiFi/Tizen.Network.WiFi.sln create mode 100644 Tizen.Network.WiFi/Tizen.Network.WiFi.snk create mode 100644 Tizen.Network.WiFi/Tizen.Network.WiFi/ConnectionStateChangedEventArgs.cs create mode 100644 Tizen.Network.WiFi/Tizen.Network.WiFi/DeviceStateChangedEventArgs.cs create mode 100644 Tizen.Network.WiFi/Tizen.Network.WiFi/IWiFiEap.cs create mode 100644 Tizen.Network.WiFi/Tizen.Network.WiFi/RssiLevelChangedEventArgs.cs create mode 100644 Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiAddressInformation.cs create mode 100644 Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiAp.cs create mode 100644 Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiConfiguration.cs create mode 100644 Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiEap.cs create mode 100644 Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiEapConfiguration.cs create mode 100644 Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiEnumerations.cs create mode 100644 Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiErrorFactory.cs create mode 100644 Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManager.cs create mode 100644 Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManagerImpl.cs create mode 100644 Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiNetwork.cs create mode 100644 Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiNetworkChange.cs create mode 100644 Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiSecurity.cs create mode 100644 packaging/csapi-network-wifi.manifest create mode 100644 packaging/csapi-network-wifi.spec diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/Tizen.Network.WiFi/Interop/Interop.Libraries.cs b/Tizen.Network.WiFi/Interop/Interop.Libraries.cs new file mode 100644 index 0000000..704b024 --- /dev/null +++ b/Tizen.Network.WiFi/Interop/Interop.Libraries.cs @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +internal static partial class Interop +{ + internal static partial class Libraries + { + public const string WiFi = "libcapi-network-wifi.so.1"; + public const string Glib = "libglib-2.0.so.0"; + public const string Libc = "libc.so.6"; + } +} diff --git a/Tizen.Network.WiFi/Interop/Interop.WiFi.cs b/Tizen.Network.WiFi/Interop/Interop.WiFi.cs new file mode 100644 index 0000000..52c1ffb --- /dev/null +++ b/Tizen.Network.WiFi/Interop/Interop.WiFi.cs @@ -0,0 +1,254 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.Runtime.InteropServices; + +internal static partial class Interop +{ + internal static partial class WiFi + { + //Callback for async method + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void VoidCallback(int result, IntPtr userData); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate bool HandleCallback(IntPtr handle, IntPtr userData); + + //Callback for event + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void DeviceStateChangedCallback(int deviceState, IntPtr userData); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void ConnectionStateChangedCallback(int connectionState, IntPtr ap, IntPtr userData); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void RssiLevelChangedCallback(int level, IntPtr userData); + + //capi-network-wifi-1.0.65-19.23.armv7l + [DllImport(Libraries.WiFi, EntryPoint = "wifi_initialize")] + internal static extern int Initialize(); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_deinitialize")] + internal static extern int Deinitialize(); + + ////Wi-Fi Manager + [DllImport(Libraries.WiFi, EntryPoint = "wifi_activate")] + internal static extern int Activate(VoidCallback callback, IntPtr userData); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_activate_with_wifi_picker_tested")] + internal static extern int ActivateWithWiFiPickerTested(VoidCallback callback, IntPtr userData); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_deactivate")] + internal static extern int Deactivate(VoidCallback callback, IntPtr userData); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_is_activated")] + internal static extern int IsActivated(out bool activated); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_get_mac_address")] + internal static extern int GetMacAddress(out string macAddress); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_get_network_interface_name")] + internal static extern int GetNetworkInterfaceName(out string interfaceName); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_scan")] + internal static extern int Scan(VoidCallback callback, IntPtr userData); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_scan_specific_ap")] + internal static extern int ScanSpecificAp(string essid, VoidCallback callback, IntPtr userData); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_get_connected_ap")] + internal static extern int GetConnectedAp(out IntPtr ap); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_foreach_found_aps")] + internal static extern int GetForeachFoundAps(HandleCallback callback, IntPtr userData); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_foreach_found_specific_aps")] + internal static extern int GetForeachFoundSpecificAps(HandleCallback callback, IntPtr userData); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_connect")] + internal static extern int Connect(IntPtr ap, VoidCallback callback, IntPtr userData); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_disconnect")] + internal static extern int Disconnect(IntPtr ap, VoidCallback callback, IntPtr userData); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_connect_by_wps_pbc")] + internal static extern int ConnectByWpsPbc(IntPtr ap, VoidCallback callback, IntPtr userData); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_connect_by_wps_pin")] + internal static extern int ConnectByWpsPin(IntPtr ap, string pin, VoidCallback callback, IntPtr userData); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_forget_ap")] + internal static extern int RemoveAp(IntPtr ap); + + //Wi-Fi Monitor + [DllImport(Libraries.WiFi, EntryPoint = "wifi_get_connection_state")] + internal static extern int GetConnectionState(out int connectionState); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_set_device_state_changed_cb")] + internal static extern int SetDeviceStateChangedCallback(DeviceStateChangedCallback callback, IntPtr userData); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_unset_device_state_changed_cb")] + internal static extern int UnsetDeviceStateChangedCallback(); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_set_background_scan_cb")] + internal static extern int SetBackgroundScanCallback(VoidCallback callback, IntPtr userData); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_unset_background_scan_cb")] + internal static extern int UnsetBackgroundScanCallback(); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_set_connection_state_changed_cb")] + internal static extern int SetConnectionStateChangedCallback(ConnectionStateChangedCallback callback, IntPtr userData); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_unset_connection_state_changed_cb")] + internal static extern int UnsetConnectionStateChangedCallback(); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_set_rssi_level_changed_cb")] + internal static extern int SetRssiLevelchangedCallback(RssiLevelChangedCallback callback, IntPtr userData); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_unset_rssi_level_changed_cb")] + internal static extern int UnsetRssiLevelchangedCallback(); + + internal static class Ap + { + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_create")] + internal static extern int Create(string essid, out IntPtr ap); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_hidden_create")] + internal static extern int CreateHiddenAp(string essid, out IntPtr ap); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_destroy")] + internal static extern int Destroy(IntPtr ap); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_clone")] + internal static extern int Clone(out IntPtr cloned, IntPtr original); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_refresh")] + internal static extern int Refresh(IntPtr ap); + + ////Network Information + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_get_essid")] + internal static extern int GetEssid(IntPtr ap, out IntPtr essid); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_get_bssid")] + internal static extern int GetBssid(IntPtr ap, out IntPtr bssid); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_get_rssi")] + internal static extern int GetRssi(IntPtr ap, out int rssi); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_get_frequency")] + internal static extern int GetFrequency(IntPtr ap, out int frequency); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_get_max_speed")] + internal static extern int GetMaxSpeed(IntPtr ap, out int maxSpeed); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_is_favorite")] + internal static extern int IsFavorite(IntPtr ap, out bool isFavorite); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_is_passpoint")] + internal static extern int IsPasspoint(IntPtr ap, out bool isPasspoint); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_get_connection_state")] + internal static extern int GetConnectionState(IntPtr ap, out int connectionState); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_get_ip_config_type")] + internal static extern int GetIpConfigType(IntPtr ap, int addressFamily, out int ipConfigType); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_set_ip_config_type")] + internal static extern int SetIpConfigType(IntPtr ap, int addressFamily, int ipConfigType); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_get_ip_address")] + internal static extern int GetIpAddress(IntPtr ap, int addressFamily, out IntPtr ipAddress); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_set_ip_address")] + internal static extern int SetIpAddress(IntPtr ap, int addressFamily, string ipAddress); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_get_subnet_mask")] + internal static extern int GetSubnetMask(IntPtr ap, int addressFamily, out IntPtr subnetMask); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_set_subnet_mask")] + internal static extern int SetSubnetMask(IntPtr ap, int addressFamily, string subnetMask); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_get_gateway_address")] + internal static extern int GetGatewayAddress(IntPtr ap, int addressFamily, out IntPtr gatewayAddress); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_set_gateway_address")] + internal static extern int SetGatewayAddress(IntPtr ap, int addressFamily, string gatewayAddress); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_get_proxy_address")] + internal static extern int GetProxyAddress(IntPtr ap, int addressFamily, out IntPtr proxyAddress); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_set_proxy_address")] + internal static extern int SetProxyAddress(IntPtr ap, int addressFamily, string proxyAddress); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_get_proxy_type")] + internal static extern int GetProxyType(IntPtr ap, out int proxyType); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_set_proxy_type")] + internal static extern int SetProxyType(IntPtr ap, int proxyType); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_get_dns_address")] + internal static extern int GetDnsAddress(IntPtr ap, int order, int addressFamily, out IntPtr dnsAddress); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_set_dns_address")] + internal static extern int SetDnsAddress(IntPtr ap, int order, int addressFamily, string dnsAddress); + + ////Security Information + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_get_security_type")] + internal static extern int GetSecurityType(IntPtr ap, out int securityType); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_set_security_type")] + internal static extern int SetSecurityType(IntPtr ap, int securityType); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_get_encryption_type")] + internal static extern int GetEncryptionType(IntPtr ap, out int encryptionType); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_set_encryption_type")] + internal static extern int SetEncryptionType(IntPtr ap, int encryptionType); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_is_passphrase_required")] + internal static extern int IsPassphraseRequired(IntPtr ap, out bool required); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_set_passphrase")] + internal static extern int SetPassphrase(IntPtr ap, string passphrase); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_is_wps_supported")] + internal static extern int IsWpsSupported(IntPtr ap, out bool supported); + + ////EAP + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_set_eap_passphrase")] + internal static extern int SetEapPassphrase(IntPtr ap, string userName, string password); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_get_eap_passphrase")] + internal static extern int GetEapPassphrase(IntPtr ap, out IntPtr userName, out bool isPasswordSet); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_get_eap_ca_cert_file")] + internal static extern int GetEapCaCertFile(IntPtr ap, out IntPtr file); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_set_eap_ca_cert_file")] + internal static extern int SetEapCaCertFile(IntPtr ap, string file); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_get_eap_client_cert_file")] + internal static extern int GetEapClientCertFile(IntPtr ap, out IntPtr file); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_set_eap_client_cert_file")] + internal static extern int SetEapClientCertFile(IntPtr ap, string file); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_get_eap_private_key_file")] + internal static extern int GetEapPrivateKeyFile(IntPtr ap, out IntPtr file); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_set_eap_private_key_info")] + internal static extern int SetEapPrivateKeyInfo(IntPtr ap, string file, string password); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_get_eap_type")] + internal static extern int GetEapType(IntPtr ap, out int eapType); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_set_eap_type")] + internal static extern int SetEapType(IntPtr ap, int eapType); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_get_eap_auth_type")] + internal static extern int GetEapAuthType(IntPtr ap, out int file); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_ap_set_eap_auth_type")] + internal static extern int SetEapAuthType(IntPtr ap, int file); + } + + internal static class Config + { + [DllImport(Libraries.WiFi, EntryPoint = "wifi_config_create")] + internal static extern int Create(string name, string passPhrase, int securityType, out IntPtr config); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_config_clone")] + internal static extern int Clone(IntPtr origin, out IntPtr cloned); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_config_destroy")] + internal static extern int Destroy(IntPtr config); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_config_save_configuration")] + internal static extern int SaveConfiguration(IntPtr config); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_config_foreach_configuration")] + internal static extern int GetForeachConfiguration(HandleCallback callback, IntPtr userData); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_config_get_name")] + internal static extern int GetName(IntPtr config, out IntPtr name); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_config_get_security_type")] + internal static extern int GetSecurityType(IntPtr config, out int securityType); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_config_set_proxy_address")] + internal static extern int SetProxyAddress(IntPtr config, int addressFamily, string proxyAddress); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_config_get_proxy_address")] + internal static extern int GetProxyAddress(IntPtr config, out int addressFamily, out IntPtr proxyAddress); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_config_set_hidden_ap_property")] + internal static extern int SetHiddenApProperty(IntPtr config, bool isHidden); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_config_get_hidden_ap_property")] + internal static extern int GetHiddenApProperty(IntPtr config, out bool isHidden); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_config_get_eap_anonymous_identity")] + internal static extern int GetEapAnonymousIdentity(IntPtr config, out IntPtr anonymousIdentify); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_config_set_eap_anonymous_identity")] + internal static extern int SetEapAnonymousIdentity(IntPtr config, string anonymousIdentify); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_config_get_eap_ca_cert_file")] + internal static extern int GetEapCaCertFile(IntPtr config, out IntPtr caCert); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_config_set_eap_ca_cert_file")] + internal static extern int SetEapCaCertFile(IntPtr config, string caCert); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_config_get_eap_client_cert_file")] + internal static extern int GetEapClientCertFile(IntPtr config, out IntPtr clientCert); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_config_set_eap_client_cert_file")] + internal static extern int SetEapClientCertFile(IntPtr config, string privateKey, string clientCert); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_config_get_eap_identity")] + internal static extern int GetEapIdentity(IntPtr config, out IntPtr identify); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_config_set_eap_identity")] + internal static extern int SetEapIdentity(IntPtr config, string identify); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_config_get_eap_type")] + internal static extern int GetEapType(IntPtr config, out int eapType); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_config_set_eap_type")] + internal static extern int SetEapType(IntPtr config, int eapType); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_config_get_eap_auth_type")] + internal static extern int GetEapAuthType(IntPtr config, out int eapAuthType); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_config_set_eap_auth_type")] + internal static extern int SetEapAuthType(IntPtr config, int eapAuthType); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_config_get_eap_subject_match")] + internal static extern int GetEapSubjectMatch(IntPtr config, out IntPtr subjectMatch); + [DllImport(Libraries.WiFi, EntryPoint = "wifi_config_set_eap_subject_match")] + internal static extern int SetEapSubjectMatch(IntPtr config, string subjectMatch); + } + } +} diff --git a/Tizen.Network.WiFi/Properties/AssemblyInfo.cs b/Tizen.Network.WiFi/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..837f185 --- /dev/null +++ b/Tizen.Network.WiFi/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Tizen.Network.WiFi")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Samsung Electronics")] +[assembly: AssemblyProduct("Tizen.Network.WiFi")] +[assembly: AssemblyCopyright("Copyright © Samsung Electronics 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("9a2167e1-3b35-4da9-ab78-8e699302baa7")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Tizen.Network.WiFi/Tizen.Network.WiFi.Net45.csproj b/Tizen.Network.WiFi/Tizen.Network.WiFi.Net45.csproj new file mode 100644 index 0000000..e8362cf --- /dev/null +++ b/Tizen.Network.WiFi/Tizen.Network.WiFi.Net45.csproj @@ -0,0 +1,81 @@ + + + + Debug + AnyCPU + {97C028B1-8A8F-411C-A52C-5B8B7ED90001} + Library + Properties + Tizen.Network.WiFi + Tizen.Network.WiFi + 512 + v4.5 + + + true + full + false + bin\Debug\Net45\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\Net45\ + TRACE + prompt + 4 + + + true + + + Tizen.Network.WiFi.snk + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Tizen.Network.WiFi/Tizen.Network.WiFi.Net45.project.json b/Tizen.Network.WiFi/Tizen.Network.WiFi.Net45.project.json new file mode 100644 index 0000000..7455788 --- /dev/null +++ b/Tizen.Network.WiFi/Tizen.Network.WiFi.Net45.project.json @@ -0,0 +1,12 @@ +{ + "dependencies": { + "Tizen": "1.0.2", + "Tizen.Network.Connection": "1.0.2" + }, + "frameworks": { + "net45": {} + }, + "runtimes": { + "win": {} + } +} diff --git a/Tizen.Network.WiFi/Tizen.Network.WiFi.csproj b/Tizen.Network.WiFi/Tizen.Network.WiFi.csproj new file mode 100644 index 0000000..4388ae9 --- /dev/null +++ b/Tizen.Network.WiFi/Tizen.Network.WiFi.csproj @@ -0,0 +1,90 @@ + + + + Debug + AnyCPU + {9A2167E1-3B35-4DA9-AB78-8E699302BAA7} + Library + Properties + Tizen.Network.WiFi + Tizen.Network.WiFi + 512 + + + .NETStandard + v1.3 + .NETStandard,Version=v1.3 + false + true + $(NoWarn);1701;1702 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + + + Tizen.Network.WiFi.snk + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <_TargetFrameworkDirectories>$(MSBuildThisFileDirectory) + <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory) + true + + \ No newline at end of file diff --git a/Tizen.Network.WiFi/Tizen.Network.WiFi.nuspec b/Tizen.Network.WiFi/Tizen.Network.WiFi.nuspec new file mode 100644 index 0000000..adf6335 --- /dev/null +++ b/Tizen.Network.WiFi/Tizen.Network.WiFi.nuspec @@ -0,0 +1,22 @@ + + + + Tizen.Network.WiFi + $version$ + Samsung Electronics + false + https://www.apache.org/licenses/LICENSE-2.0 + https://www.tizen.org/ + https://developer.tizen.org/sites/default/files/images/tizen-pinwheel-on-light-rgb_64_64.png + © Samsung Electronics Co., Ltd All Rights Reserved + Provides the Wi-Fi APIs for Tizen.Network.WiFi + + + + + + + + + + diff --git a/Tizen.Network.WiFi/Tizen.Network.WiFi.project.json b/Tizen.Network.WiFi/Tizen.Network.WiFi.project.json new file mode 100644 index 0000000..a754ff9 --- /dev/null +++ b/Tizen.Network.WiFi/Tizen.Network.WiFi.project.json @@ -0,0 +1,10 @@ +{ + "dependencies": { + "NETStandard.Library": "1.6.0", + "Tizen": "1.0.2", + "Tizen.Network.Connection": "1.0.2" + }, + "frameworks": { + "netstandard1.3": {} + } +} diff --git a/Tizen.Network.WiFi/Tizen.Network.WiFi.sln b/Tizen.Network.WiFi/Tizen.Network.WiFi.sln new file mode 100644 index 0000000..7763278 --- /dev/null +++ b/Tizen.Network.WiFi/Tizen.Network.WiFi.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tizen.Network.WiFi", "Tizen.Network.WiFi.csproj", "{9A2167E1-3B35-4DA9-AB78-8E699302BAA7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9A2167E1-3B35-4DA9-AB78-8E699302BAA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9A2167E1-3B35-4DA9-AB78-8E699302BAA7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9A2167E1-3B35-4DA9-AB78-8E699302BAA7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9A2167E1-3B35-4DA9-AB78-8E699302BAA7}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Tizen.Network.WiFi/Tizen.Network.WiFi.snk b/Tizen.Network.WiFi/Tizen.Network.WiFi.snk new file mode 100644 index 0000000000000000000000000000000000000000..e3e34afddad5f484857a80f845abe152fbc8a9b3 GIT binary patch literal 596 zcmV-a0;~N80ssI2Bme+XQ$aES1ONa50098ef*>GN&mGcn-j^x3%|%V5wdzgf)`n_}7CMDO zhc`$YO*hQksHYEO=xM*fp&;O73rWw@u`0O3WE?#p%m7&+5G0mc9PcaEgKK!iuCwXO zpack6nqgb@k7oZ7<{2LE!KoM~l%Z+UYxMeyS4erAXb`_bG>8PNowcF=U4d3iRGtQ` zXbkqv#KGRmLS8$cuiHrxT`F>-2H}OXuu8H1nA6Br;s{~ zP%ME>5Nx~1D-NczXxBls6O_$`yB+1chZRI$VXrYfOnHOJa}9?UaV85dVN;Fu0tF;L zhGRfkf~D8`?ij9dm)gS>5m3FR#!;|e@@7Cg5(t{(uoC{vm0|_?K-ZAm)}tTB;ILt} z_6|^2X%72+>!uLhqig8$qfe6%Ckq;8ys{HG9Mg0caJK2G4fxTZ7z8cIm>jn6ij{WS z=#>zAnN=%gY1c9`mBr7!%cN)K8oe?#DO#AtztdC`MdB0n)u28lYu`LCiDmU~z3N-D zR<(;+8S<#31)N$dCNJ|{zgtvbFu3Y-V(jTW$4`_ZE;s^k;#@W&u$7YiW7CPz@$u>D ipI(;tOP>c%FXA2IWvrK?rKJMCTQ@~PUr&|MsctSFWFQX! literal 0 HcmV?d00001 diff --git a/Tizen.Network.WiFi/Tizen.Network.WiFi/ConnectionStateChangedEventArgs.cs b/Tizen.Network.WiFi/Tizen.Network.WiFi/ConnectionStateChangedEventArgs.cs new file mode 100644 index 0000000..58ccaed --- /dev/null +++ b/Tizen.Network.WiFi/Tizen.Network.WiFi/ConnectionStateChangedEventArgs.cs @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; + +namespace Tizen.Network.WiFi +{ + /// + /// An extended EventArgs class which contains changed connection state. + /// + public class ConnectionStateChangedEventArgs : EventArgs + { + private WiFiConnectionState _state = WiFiConnectionState.Disconnected; + private WiFiAp _ap; + + internal ConnectionStateChangedEventArgs(WiFiConnectionState s, IntPtr _apHandle) + { + _state = s; + _ap = new WiFiAp(_apHandle); + } + /// + /// The wifi connection state. + /// + public WiFiConnectionState State + { + get + { + return _state; + } + } + /// + /// The access point + /// + public WiFiAp Ap + { + get + { + return _ap; + } + } + } +} diff --git a/Tizen.Network.WiFi/Tizen.Network.WiFi/DeviceStateChangedEventArgs.cs b/Tizen.Network.WiFi/Tizen.Network.WiFi/DeviceStateChangedEventArgs.cs new file mode 100644 index 0000000..2271685 --- /dev/null +++ b/Tizen.Network.WiFi/Tizen.Network.WiFi/DeviceStateChangedEventArgs.cs @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; + +namespace Tizen.Network.WiFi +{ + /// + /// An extended EventArgs class which contains changed device state. + /// + public class DeviceStateChangedEventArgs : EventArgs + { + private WiFiDeviceState _state = WiFiDeviceState.Deactivated; + + internal DeviceStateChangedEventArgs(WiFiDeviceState s) + { + _state = s; + } + + /// + /// The wifi device state. + /// + public WiFiDeviceState State + { + get + { + return _state; + } + } + } +} diff --git a/Tizen.Network.WiFi/Tizen.Network.WiFi/IWiFiEap.cs b/Tizen.Network.WiFi/Tizen.Network.WiFi/IWiFiEap.cs new file mode 100644 index 0000000..5556be4 --- /dev/null +++ b/Tizen.Network.WiFi/Tizen.Network.WiFi/IWiFiEap.cs @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; + +namespace Tizen.Network.WiFi +{ + /// + /// An abstract class for WiFi EAP information. + /// + internal interface IWiFiEap + { + /// + /// The file path of CA Certificate of EAP. + /// + string CaCertificationFile { get; set; } + /// + /// The EAP type of wifi. + /// + WiFiEapType EapType { get; set; } + /// + /// The type of EAP phase2 authentication of Wi-Fi. + /// + WiFiAuthenticationType AuthenticationType { get; set; } + } //WiFiEap +} diff --git a/Tizen.Network.WiFi/Tizen.Network.WiFi/RssiLevelChangedEventArgs.cs b/Tizen.Network.WiFi/Tizen.Network.WiFi/RssiLevelChangedEventArgs.cs new file mode 100644 index 0000000..41d0e98 --- /dev/null +++ b/Tizen.Network.WiFi/Tizen.Network.WiFi/RssiLevelChangedEventArgs.cs @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; + +namespace Tizen.Network.WiFi +{ + /// + /// An extended EventArgs class which contains changed RSSI level. + /// + public class RssiLevelChangedEventArgs : EventArgs + { + private WiFiRssiLevel _level = WiFiRssiLevel.Level0; + + internal RssiLevelChangedEventArgs(WiFiRssiLevel l) + { + _level = l; + } + /// + /// The wifi RSSI level. + /// + public WiFiRssiLevel Level + { + get + { + return _level; + } + } + } +} diff --git a/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiAddressInformation.cs b/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiAddressInformation.cs new file mode 100644 index 0000000..1e5dc37 --- /dev/null +++ b/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiAddressInformation.cs @@ -0,0 +1,205 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.Runtime.InteropServices; +using Tizen.Network.Connection; + +namespace Tizen.Network.WiFi +{ + internal class WiFiAddressInformation : IAddressInformation + { + private IntPtr _handle; + private AddressFamily _family; + private bool _disposed = false; + + internal WiFiAddressInformation(IntPtr handle, AddressFamily family) + { + _handle = handle; + _family = family; + } + + ~WiFiAddressInformation() + { + Dispose(false); + } + + protected void Dispose(bool disposing) + { + if (_disposed) + return; + + if (disposing) + { + // Free managed objects. + } + _handle = IntPtr.Zero; + _disposed = true; + } + + public void Dispose() + { + Dispose(true); + } + + public System.Net.IPAddress Dns1 + { + get + { + IntPtr addrPtr; + int ret = Interop.WiFi.Ap.GetDnsAddress(_handle, 1, (int)_family, out addrPtr); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get first dns address, Error - " + (WiFiError)ret); + return System.Net.IPAddress.Parse("0.0.0.0"); + } + string addrStr = Marshal.PtrToStringAnsi(addrPtr); + if (addrStr == null) + return System.Net.IPAddress.Parse("0.0.0.0"); + return System.Net.IPAddress.Parse(addrStr); + } + set + { + int ret = Interop.WiFi.Ap.SetDnsAddress(_handle, 1, (int)_family, value.ToString()); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to set first dns address, Error - " + (WiFiError)ret); + } + } + } + public System.Net.IPAddress Dns2 + { + get + { + IntPtr addrPtr; + int ret = Interop.WiFi.Ap.GetDnsAddress(_handle, 2, (int)_family, out addrPtr); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get second dns address, Error - " + (WiFiError)ret); + return System.Net.IPAddress.Parse("0.0.0.0"); + } + string addrStr = Marshal.PtrToStringAnsi(addrPtr); + if (addrStr == null) + return System.Net.IPAddress.Parse("0.0.0.0"); + return System.Net.IPAddress.Parse(addrStr); + } + set + { + int ret = Interop.WiFi.Ap.SetDnsAddress(_handle, 2, (int)_family, value.ToString()); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to set second dns address, Error - " + (WiFiError)ret); + } + } + } + public System.Net.IPAddress Gateway + { + get + { + IntPtr addrPtr; + int ret = Interop.WiFi.Ap.GetGatewayAddress(_handle, (int)_family, out addrPtr); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get gateway address, Error - " + (WiFiError)ret); + return System.Net.IPAddress.Parse("0.0.0.0"); + } + string addrStr = Marshal.PtrToStringAnsi(addrPtr); + if (addrStr == null) + return System.Net.IPAddress.Parse("0.0.0.0"); + return System.Net.IPAddress.Parse(addrStr); + } + set + { + int ret = Interop.WiFi.Ap.SetGatewayAddress(_handle, (int)_family, value.ToString()); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to set gateway address, Error - " + (WiFiError)ret); + } + } + } + public System.Net.IPAddress SubnetMask + { + get + { + IntPtr addrPtr; + int ret = Interop.WiFi.Ap.GetSubnetMask(_handle, (int)_family, out addrPtr); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get subnet mask, Error - " + (WiFiError)ret); + return System.Net.IPAddress.Parse("0.0.0.0"); + } + string addrStr = Marshal.PtrToStringAnsi(addrPtr); + if (addrStr == null) + return System.Net.IPAddress.Parse("0.0.0.0"); + return System.Net.IPAddress.Parse(addrStr); + } + set + { + int ret = Interop.WiFi.Ap.SetSubnetMask(_handle, (int)_family, value.ToString()); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to set subnet mask, Error - " + (WiFiError)ret); + } + } + } + public System.Net.IPAddress Ip + { + get + { + IntPtr addrPtr; + int ret = Interop.WiFi.Ap.GetIpAddress(_handle, (int)_family, out addrPtr); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get ip address, Error - " + (WiFiError)ret); + return System.Net.IPAddress.Parse("0.0.0.0"); + } + string addrStr = Marshal.PtrToStringAnsi(addrPtr); + if (addrStr == null) + return System.Net.IPAddress.Parse("0.0.0.0"); + return System.Net.IPAddress.Parse(addrStr); + } + set + { + int ret = Interop.WiFi.Ap.SetIpAddress(_handle, (int)_family, value.ToString()); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to set ip address, Error - " + (WiFiError)ret); + } + } + } + public IpConfigType IpConfigType + { + get + { + int type; + int ret = Interop.WiFi.Ap.GetIpConfigType(_handle, (int)_family, out type); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get ip config type, Error - " + (WiFiError)ret); + } + return (IpConfigType)type; + } + set + { + int ret = Interop.WiFi.Ap.SetIpConfigType(_handle, (int)_family, (int)value); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to set ip config type, Error - " + (WiFiError)ret); + } + } + } + } +} diff --git a/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiAp.cs b/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiAp.cs new file mode 100644 index 0000000..35b1b67 --- /dev/null +++ b/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiAp.cs @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; + +namespace Tizen.Network.WiFi +{ + /// + /// A class for manager the network information of the access point(AP). It allows applications to manager netowrk informaiton. + /// + public class WiFiAp : IDisposable + { + private IntPtr _apHandle = IntPtr.Zero; + private WiFiNetwork _network; + private WiFiSecurity _security; + private bool disposed = false; + + /// + /// The network information of the acces point(AP). + /// + public WiFiNetwork NetworkInformation + { + get + { + return _network; + } + } + /// + /// The security information of the access point(AP). + /// + public WiFiSecurity SecurityInformation + { + get + { + return _security; + } + } + + internal WiFiAp(IntPtr handle) + { + Log.Debug(Globals.LogTag, "New WiFiAp. Handle: " + handle); + _apHandle = handle; + Initialize(); + } + /// + /// Creates a object for the access point. + /// + /// The ESSID (Extended Service Set Identifier) can be UTF-8 encoded + public WiFiAp(string essid) + { + Log.Debug(Globals.LogTag, "New WiFiAp. Essid: " + essid); + createHandle(essid, true); + Initialize(); + } + /// + /// Creates a object for the hidden access point. + /// + /// The ESSID (Extended Service Set Identifier) can be UTF-8 encoded + /// The value to set hidden AP + public WiFiAp(string essid, bool hidden) + { + createHandle(essid, hidden); + Initialize(); + } + + ~WiFiAp() + { + Dispose(false); + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + private void Dispose(bool disposing) + { + if (disposed) + return; + + if (disposing) + { + _network.Dispose(); + _security.Dispose(); + } + Interop.WiFi.Ap.Destroy(_apHandle); + _apHandle = IntPtr.Zero; + disposed = true; + } + + private void createHandle(string id, bool hidden) + { + int ret = -1; + if (hidden) + { + ret = Interop.WiFi.Ap.Create(id, out _apHandle); + } + else + { + ret = Interop.WiFi.Ap.CreateHiddenAp(id, out _apHandle); + } + + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to create handle, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret); + } + } + + private void Initialize() + { + _network = new WiFiNetwork(_apHandle); + _security = new WiFiSecurity(_apHandle); + } + + /// + /// Refreshes the access point information. + /// + public void Refresh() + { + int ret = Interop.WiFi.Ap.Refresh(_apHandle); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to refresh ap handle, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, _apHandle); + } + } + + internal IntPtr GetHandle() + { + return _apHandle; + } + } +} diff --git a/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiConfiguration.cs b/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiConfiguration.cs new file mode 100644 index 0000000..ac4d60a --- /dev/null +++ b/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiConfiguration.cs @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.Net; +using System.Threading.Tasks; +using System.Runtime.InteropServices; +using Tizen.Network.Connection; + +namespace Tizen.Network.WiFi +{ + /// + /// A class for managing the configuration of Wi-Fi. It allows applications to manage the configuration information of Wi-Fi. + /// + public class WiFiConfiguration : IDisposable + { + private IntPtr _configHandle = IntPtr.Zero; + private bool disposed = false; + private WiFiEapConfiguration _eapConfig; + + /// + /// The name of access point(AP). + /// + public string Name + { + get + { + IntPtr strPtr; + int ret = Interop.WiFi.Config.GetName(_configHandle, out strPtr); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get name, Error - " + (WiFiError)ret); + return ""; + } + return Marshal.PtrToStringAnsi(strPtr); + } + } + /// + /// The security type of access point(AP). + /// + public WiFiSecureType SecurityType + { + get + { + int type; + int ret = Interop.WiFi.Config.GetSecurityType(_configHandle, out type); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get security type, Error - " + (WiFiError)ret); + } + return (WiFiSecureType)type; + } + } + /// + /// The proxy address. + /// + public string ProxyAddress + { + get + { + IntPtr strPtr; + int addressFamily; + int ret = Interop.WiFi.Config.GetProxyAddress(_configHandle, out addressFamily, out strPtr); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get proxy address, Error - " + (WiFiError)ret); + return ""; + } + return Marshal.PtrToStringAnsi(strPtr); + } + set + { + int ret = Interop.WiFi.Config.SetProxyAddress(_configHandle, (int)AddressFamily.Ipv4, value); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to set proxy address, Error - " + (WiFiError)ret); + } + } + } + /// + /// A property check whether the access point(AP) is hidden or not. + /// + public bool IsHidden + { + get + { + bool hidden; + int ret = Interop.WiFi.Config.GetHiddenApProperty(_configHandle, out hidden); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get isHidden, Error - " + (WiFiError)ret); + } + return hidden; + } + set + { + int ret = Interop.WiFi.Config.SetHiddenApProperty(_configHandle, value); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to set IsHidden, Error - " + (WiFiError)ret); + } + } + } + /// + /// The EAP Configuration. + /// + public WiFiEapConfiguration EapConfiguration + { + get + { + return _eapConfig; + } + } + + internal WiFiConfiguration(IntPtr handle) + { + _configHandle = handle; + _eapConfig = new WiFiEapConfiguration(_configHandle); + } + + public WiFiConfiguration(string name, string passPhrase, WiFiSecureType type) + { + int ret = Interop.WiFi.Config.Create(name, passPhrase, (int)type, out _configHandle); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to create config handle, Error - " + (WiFiError)ret); + } + _eapConfig = new WiFiEapConfiguration(_configHandle); + } + + ~WiFiConfiguration() + { + Dispose(false); + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + private void Dispose(bool disposing) + { + if (disposed) + return; + + if (disposing) + { + _eapConfig.Dispose(); + } + Interop.WiFi.Config.Destroy(_configHandle); + _configHandle = IntPtr.Zero; + disposed = true; + } + + internal IntPtr GetHandle() + { + return _configHandle; + } + } //WiFiNetworkConfiguratin +} diff --git a/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiEap.cs b/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiEap.cs new file mode 100644 index 0000000..7b0193c --- /dev/null +++ b/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiEap.cs @@ -0,0 +1,255 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Runtime.InteropServices; + +namespace Tizen.Network.WiFi +{ + /// + /// A class for managing the EAP information of access point(AP). It allows applications to manager EAP information. + /// This class is not intended to create instance directly from applications. + /// + public class WiFiEap : IWiFiEap, IDisposable + { + private IntPtr _apHandle = IntPtr.Zero; + private bool disposed = false; + + /// + /// The file path of CA Certificate of EAP. + /// + public string CaCertificationFile + { + get + { + IntPtr strPtr; + int ret = Interop.WiFi.Ap.GetEapCaCertFile(_apHandle, out strPtr); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get caCertFile, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret); + return ""; + } + return Marshal.PtrToStringAnsi(strPtr); + } + set + { + int ret = Interop.WiFi.Ap.SetEapCaCertFile(_apHandle, value); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to set caCertFile, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret); + } + } + } + /// + /// The EAP type of wifi. + /// + public WiFiEapType EapType + { + get + { + int type; + int ret = Interop.WiFi.Ap.GetEapType(_apHandle, out type); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get eap type, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret); + } + return (WiFiEapType)type; + } + set + { + int ret = Interop.WiFi.Ap.SetEapType(_apHandle, (int)value); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to set eap type, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret); + } + } + } + /// + /// The type of EAP phase2 authentication of Wi-Fi. + /// + public WiFiAuthenticationType AuthenticationType + { + get + { + int type; + int ret = Interop.WiFi.Ap.GetEapAuthType(_apHandle, out type); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get auth type, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret); + } + return (WiFiAuthenticationType)type; + } + set + { + int ret = Interop.WiFi.Ap.SetEapAuthType(_apHandle, (int)value); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to set eap auth type, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret); + } + } + } + + internal WiFiEap(IntPtr apHandle) + { + _apHandle = apHandle; + } + + ~WiFiEap() + { + Dispose(false); + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + private void Dispose(bool disposing) + { + if (disposed) + return; + + if (disposing) + { + // Free managed objects. + } + _apHandle = IntPtr.Zero; + disposed = true; + } + + /// + /// Gets the private key file of EAP. + /// + /// The file path of private key. + public string GetPrivateKeyFile() + { + IntPtr strPtr; + int ret = Interop.WiFi.Ap.GetEapPrivateKeyFile(_apHandle, out strPtr); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get private key file, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, _apHandle); + } + return Marshal.PtrToStringAnsi(strPtr); + } + + /// + /// Sets the private key information of EAP. + /// + /// The file path of private key. + /// The password. + public void SetPrivateKeyInfo(string privateKeyFile, string password) + { + int ret = Interop.WiFi.Ap.SetEapPrivateKeyInfo(_apHandle, privateKeyFile, password); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to set private key info, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, _apHandle); + } + } + + /// + /// Gets the Client Certificate of EAP. + /// + /// The file path of Client Certificate. + public string GetClientCertFile() + { + IntPtr strPtr; + int ret = Interop.WiFi.Ap.GetEapClientCertFile(_apHandle, out strPtr); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get client cert file, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, _apHandle); + } + return Marshal.PtrToStringAnsi(strPtr); + } + + /// + /// Sets the CA Certificate of EAP. + /// + /// The file path of Client Certificate. + public void SetClientCertFile(string clientCertFile) + { + int ret = Interop.WiFi.Ap.SetEapClientCertFile(_apHandle, clientCertFile); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to set client cert file, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, _apHandle); + } + } + + /// + /// Gets the username of EAP passphrase. + /// + /// The user name + public string GetEapPassphraseUserName() + { + IntPtr strptr; + bool passwordSet; + int ret = Interop.WiFi.Ap.GetEapPassphrase(_apHandle, out strptr, out passwordSet); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get user name in eap passphrase, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, _apHandle); + } + return Marshal.PtrToStringAnsi(strptr); + } + /// + /// Returns whether the password is set for not set. + /// + /// ture if password is set, otherwise flase if password is not set. + public bool IsEapPassphrasePasswordSet() + { + IntPtr strptr; + bool passwordSet; + int ret = Interop.WiFi.Ap.GetEapPassphrase(_apHandle, out strptr, out passwordSet); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get IsPasswordSet in passphrase, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, _apHandle); + } + return passwordSet; + } + + /// + /// Sets the passphrase of EAP. + /// You can set one of user_name and password as NULL.
+ /// In this case, the value of a parameter which is set as NULL will be the previous value. But it is not allowed that both user_name and password are set as NULL. + ///
+ /// The user name + /// The password + public void SetEapPassphrase(string userName, string password) + { + int ret = Interop.WiFi.Ap.SetEapPassphrase(_apHandle, userName, password); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to set passphrase, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, _apHandle); + } + } + } //WiFiEapInformation +} diff --git a/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiEapConfiguration.cs b/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiEapConfiguration.cs new file mode 100644 index 0000000..2a2175b --- /dev/null +++ b/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiEapConfiguration.cs @@ -0,0 +1,250 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.Runtime.InteropServices; + +namespace Tizen.Network.WiFi +{ + /// + /// A class for managing the EAP configuration. + /// This class is not intended to create instance directly from applications. + /// + public class WiFiEapConfiguration : IWiFiEap, IDisposable + { + private IntPtr _configHandle = IntPtr.Zero; + private bool disposed = false; + + /// + /// The file path of CA Certificate of EAP. + /// + public string CaCertificationFile + { + get + { + IntPtr strPtr; + int ret = Interop.WiFi.Config.GetEapCaCertFile(_configHandle, out strPtr); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get caCertFile Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, _configHandle); + } + return Marshal.PtrToStringAnsi(strPtr); + } + set + { + int ret = Interop.WiFi.Config.SetEapCaCertFile(_configHandle, value); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to set caCertFile, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, _configHandle); + } + } + } + /// + /// The EAP type of wifi. + /// + public WiFiEapType EapType + { + get + { + int type; + int ret = Interop.WiFi.Config.GetEapType(_configHandle, out type); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to eap type Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, _configHandle); + } + return (WiFiEapType)type; + } + set + { + int ret = Interop.WiFi.Config.SetEapType(_configHandle, (int)value); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to set eap type, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, _configHandle); + } + } + } + /// + /// The type of EAP phase2 authentication of Wi-Fi. + /// + public WiFiAuthenticationType AuthenticationType + { + get + { + int type; + int ret = Interop.WiFi.Config.GetEapAuthType(_configHandle, out type); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get auth type Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, _configHandle); + } + return (WiFiAuthenticationType)type; + } + set + { + int ret = Interop.WiFi.Config.SetEapAuthType(_configHandle, (int)value); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to set eap auth type, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, _configHandle); + } + } + } + /// + /// The anonymous identity of access point(AP). + /// + public string AnonymousIdentify + { + get + { + IntPtr strPtr; + int ret = Interop.WiFi.Config.GetEapAnonymousIdentity(_configHandle, out strPtr); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get anonymous identify Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, _configHandle); + return ""; + } + return Marshal.PtrToStringAnsi(strPtr); + } + set + { + int ret = Interop.WiFi.Config.SetEapAnonymousIdentity(_configHandle, value); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to set anonymous identify, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, _configHandle); + } + } + } + /// + /// The identity of access point(AP). + /// + public string Identity + { + get + { + IntPtr strPtr; + int ret = Interop.WiFi.Config.GetEapIdentity(_configHandle, out strPtr); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get identify Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, _configHandle); + return ""; + } + return Marshal.PtrToStringAnsi(strPtr); + } + set + { + int ret = Interop.WiFi.Config.SetEapIdentity(_configHandle, value); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to set identify, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, _configHandle); + } + } + } + /// + /// The subject match of access point(AP). + /// + public string SubjectMatch + { + get + { + IntPtr strPtr; + int ret = Interop.WiFi.Config.GetEapSubjectMatch(_configHandle, out strPtr); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get subject match Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, _configHandle); + return ""; + } + return Marshal.PtrToStringAnsi(strPtr); + } + set + { + int ret = Interop.WiFi.Config.SetEapSubjectMatch(_configHandle, value); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to set subject match, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, _configHandle); + } + } + } + + internal WiFiEapConfiguration(IntPtr handle) + { + _configHandle = handle; + } + + ~WiFiEapConfiguration() + { + Dispose(false); + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + private void Dispose(bool disposing) + { + if (disposed) + return; + + if (disposing) + { + // Free managed objects. + } + _configHandle = IntPtr.Zero; + disposed = true; + } + + /// + /// Gets access point client cert file from configuration. + /// + /// The certification authority(CA) certificates file of access point. + public string GetClientCertFile() + { + IntPtr strPtr; + int ret = Interop.WiFi.Config.GetEapClientCertFile(_configHandle, out strPtr); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get client cert file, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, _configHandle); + } + return Marshal.PtrToStringAnsi(strPtr); + } + /// + /// Sets access point client cert file to configuration. + /// + /// The private key file. + /// The certification authority(CA) certificates file of access point. + public void SetClientCertFile(string privateKey, string clientCert) + { + int ret = Interop.WiFi.Config.SetEapClientCertFile(_configHandle, privateKey, clientCert); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to set client cert file, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, _configHandle); + } + } + } //WiFiEapConfiguration +} diff --git a/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiEnumerations.cs b/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiEnumerations.cs new file mode 100644 index 0000000..1f36d92 --- /dev/null +++ b/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiEnumerations.cs @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; + +namespace Tizen.Network.WiFi +{ + /// + /// Enumeration for Wi-Fi EAP type. + /// + public enum WiFiEapType + { + /// + /// EAP PEAP type + /// + Peap = 0, + /// + /// EAP TLS type + /// + Tls = 1, + /// + /// EAP TTLS type + /// + Ttls = 2, + /// + /// EAP SIM type + /// + Sim = 3, + /// + /// EAP AKA type + /// + Aka = 4 + } + /// + /// Enumeration for Wi-Fi RSSI level. + /// + public enum WiFiRssiLevel + { + /// + /// Level 0 + /// + Level0 = 0, + /// + /// Level 1 + /// + Level1 = 1, + /// + /// Level 2 + /// + Level2 = 2, + /// + /// Level 3 + /// + Level3 = 3, + /// + /// Level 4 + /// + Level4 = 4 + } + /// + /// Enumeration for Wi-Fi connection state. + /// + public enum WiFiConnectionState + { + /// + /// Connection failed state + /// + Failure = -1, + /// + /// Disconnected state + /// + Disconnected = 0, + /// + /// Association state + /// + Association = 1, + /// + /// Configuration state + /// + Congfiguration = 2, + /// + /// Connected state + /// + Connected = 3 + } + /// + /// Enumeration for Wi-Fi device state. + /// + public enum WiFiDeviceState + { + /// + /// Wi-Fi is Deactivated + /// + Deactivated = 0, + /// + /// Wi-Fi is activated + /// + Activated = 1 + } + /// + /// Enumeration for Wi-Fi proxy type. + /// + public enum WiFiProxyType + { + /// + /// Direct connection + /// + Direct = 0, + /// + /// Auto configuration(Use PAC file). If URL property is not set, DHCP/WPAD auto-discover will be tried + /// + Auto = 1, + /// + /// Manual configuration + /// + Manual = 2 + } + /// + /// Enumeration for Wi-Fi authentication type. + /// + public enum WiFiAuthenticationType + { + /// + /// EAP phase2 authentication none + /// + None = 0, + /// + /// EAP phase2 authentication PAP + /// + Pap = 1, + /// + /// EAP phase2 authentication MSCHAP + /// + Mschap = 2, + /// + /// EAP phase2 authentication MSCHAPv2 + /// + Mschapv2 = 3, + /// + /// EAP phase2 authentication GTC + /// + Gtc = 4, + /// + /// EAP phase2 authentication MD5 + /// + Md5 = 5 + } +} diff --git a/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiErrorFactory.cs b/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiErrorFactory.cs new file mode 100644 index 0000000..687f154 --- /dev/null +++ b/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiErrorFactory.cs @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using Tizen.Internals.Errors; + +namespace Tizen.Network.WiFi +{ + internal enum WiFiError + { + None = ErrorCode.None, + InvalidParameterError = ErrorCode.InvalidParameter, + OutOfMemoryError = ErrorCode.OutOfMemory, + InvalidOperationError = ErrorCode.InvalidOperation, + AddressFamilyNotSupportedError = ErrorCode.AddressFamilyNotSupported, + OperationFailedError = -0x01C50000 | 0x0301, + NoConnectionError = -0x01C50000 | 0x0302, + NowInProgressError = ErrorCode.NowInProgress, + AlreadyExistsError = -0x01C50000 | 0x0303, + OperationAbortedError = -0x01C50000 | 0x0304, + DhcpFailedError = -0x01C50000 | 0x0306, + InvalidKeyError = -0x01C50000 | 0x0307, + NoReplyError = -0x01C50000 | 0x0308, + SecurityRestrictedError = -0x01C50000 | 0x0309, + PermissionDeniedError = ErrorCode.PermissionDenied, + NotSupportedError = ErrorCode.NotSupported + } + + internal static class WiFiErrorFactory + { + static internal void ThrowWiFiException(int e) + { + ThrowExcption(e, false); + } + + static internal void ThrowWiFiException(int e, IntPtr handle) + { + ThrowExcption(e, (handle == IntPtr.Zero)); + } + + static private void ThrowExcption(int e, bool isHandleNull) + { + WiFiError err = (WiFiError)e; + if (err == WiFiError.NotSupportedError) + { + throw new NotSupportedException("Not Supported"); + } + + if (isHandleNull) + { + if (err == WiFiError.InvalidParameterError || err == WiFiError.InvalidKeyError) + { + throw new ArgumentException(err.ToString()); + } + else + { + throw new InvalidOperationException("Invalid instance (object may have been disposed or released)"); + } + } + + if (err == WiFiError.InvalidParameterError || err == WiFiError.InvalidKeyError) + { + throw new ArgumentException(err.ToString()); + } + else + { + throw new InvalidOperationException(err.ToString()); + } + } + + } +} diff --git a/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManager.cs b/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManager.cs new file mode 100644 index 0000000..dd8b65a --- /dev/null +++ b/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManager.cs @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Tizen.Network.WiFi +{ + /// + /// A manager class which allows applications to connect to a Wireless Local Area Network (WLAN) and to transfer data over the network.
+ /// The Wi-Fi Manager enables your application to activate and deactivate a local Wi-Fi device, and to connect to a WLAN network in the infrastructure mode. + ///
+ static public class WiFiManager + { + /// + /// The local MAC address. + /// + static public string MacAddress + { + get + { + return WiFiManagerImpl.Instance.MacAddress; + } + } + /// + /// The name of the network interface. + /// + static public string InterfaceName + { + get + { + return WiFiManagerImpl.Instance.InterfaceName; + } + } + /// + /// The networtk connection state. + /// + static public WiFiConnectionState ConnectionState + { + get + { + return WiFiManagerImpl.Instance.ConnectionState; + } + } + /// + /// A property to Check whether Wi-Fi is activated. + /// + static public bool IsActivated + { + get + { + return WiFiManagerImpl.Instance.IsActivated; + } + } + + /// + /// (event) DeviceStateChanged is raised when the device state is changed. + /// + static public event EventHandler DeviceStateChanged + { + add + { + WiFiManagerImpl.Instance.DeviceStateChanged += value; + } + remove + { + WiFiManagerImpl.Instance.DeviceStateChanged -= value; + } + } + /// + /// (event) ConnectionStateChanged is rasied when the connection state is changed. + /// + static public event EventHandler ConnectionStateChanged + { + add + { + WiFiManagerImpl.Instance.ConnectionStateChanged += value; + } + remove + { + WiFiManagerImpl.Instance.ConnectionStateChanged -= value; + } + } + /// + /// (event) RssiLevelChanged is rasied when the RSSI of connected Wi-Fi is changed. + /// + static public event EventHandler RssiLevelChanged + { + add + { + WiFiManagerImpl.Instance.RssiLevelChanged += value; + } + remove + { + WiFiManagerImpl.Instance.RssiLevelChanged -= value; + } + } + /// + /// (event) BackgroundScanFinished is rasied when the background scan is finished. + /// The background scan starts automatically when wifi is activated. The callback will be invoked periodically. + /// + static public event EventHandler BackgroundScanFinished + { + add + { + WiFiManagerImpl.Instance.BackgroundScanFinished += value; + } + remove + { + WiFiManagerImpl.Instance.BackgroundScanFinished -= value; + } + } + /// + /// Gets the result of the scan asynchronously. + /// + /// A task contains the lisf for WiFiApInformation objects. + static public IEnumerable GetFoundAps() + { + return WiFiManagerImpl.Instance.GetFoundAps(); + } + /// + /// Gets the result of specific ap scan asynchronously. + /// + /// A task contains the WiFiApInformation object. + static public IEnumerable GetFoundSpecificAps() + { + return WiFiManagerImpl.Instance.GetFoundSpecificAps(); + } + /// + /// Gets the list of wifi configuration. + /// + /// A task contains the lisf for WiFiConfiguration objects. + static public IEnumerable GetWiFiConfigurations() + { + return WiFiManagerImpl.Instance.GetWiFiConfigurations(); + } + /// + /// Saves Wi-Fi configuration of access point. + /// + /// The configuration to be stored + static public void SaveWiFiNetworkConfiguration(WiFiConfiguration configuration) + { + WiFiManagerImpl.Instance.SaveWiFiNetworkConfiguration(configuration); + } + /// + /// Gets the handle of the connected access point. + /// + /// The connected wifi access point(AP) information. + static public WiFiAp GetConnectedAp() + { + return WiFiManagerImpl.Instance.GetConnectedAp(); + + } + /// + /// Deletes the information of stored access point and disconnects it when it connected.
+ /// If an AP is connected, then connection information will be stored. This information is used when a connection to that AP is established automatically. + ///
+ /// The access point to be removed + static public void RemoveAP(WiFiAp ap) + { + WiFiManagerImpl.Instance.RemoveAp(ap); + } + /// + /// Activates Wi-Fi asynchronously. + /// + /// A task indicates whether the Activate method is done or not. + static public Task ActivateAsync() + { + + return WiFiManagerImpl.Instance.ActivateAsync(); + } + /// + /// Activates Wi-Fi asynchronously and displays Wi-Fi picker (popup) when Wi-Fi is not automatically connected. + /// + /// A task indicates whether the ActivateWithPickerTeated method is done or not. + static public Task ActivateWithPickerTeatedAsync() + { + return WiFiManagerImpl.Instance.ActivateWithWiFiPickerTestedAsync(); + } + /// + /// Deactivates Wi-Fi asynchronously. + /// + /// A task indicates whether the Deactivate method is done or not. + static public Task DeactivateAsync() + { + return WiFiManagerImpl.Instance.DeactivateAsync(); + } + /// + /// Starts scan asynchronously. + /// + /// A task indicates whether the Scan method is done or not. + static public Task ScanAsync() + { + Log.Debug(Globals.LogTag, "ScanAsync"); + return WiFiManagerImpl.Instance.ScanAsync(); + } + /// + /// Starts specific ap scan, asynchronously. + /// + /// A task contains WiFiApInformation object. + /// The essid of hidden ap + static public Task ScanSpecificApAsync(string essid) + { + return WiFiManagerImpl.Instance.ScanSpecificApAsync(essid); + } + /// + /// Connects the access point asynchronously. + /// + /// The access point + /// A task indicates whether the Connect method is done or not. + static public Task ConnectAsync(WiFiAp ap) + { + Log.Debug(Globals.LogTag, "ConnectAsync"); + return WiFiManagerImpl.Instance.ConnectAsync(ap); + } + /// + /// Connects the access point with WPS PBC asynchronously. + /// + /// A task indicates whether the ConnectByWpsPbs method is done or not. + /// The access point(AP) + static public Task ConnectByWpsPbcAsync(WiFiAp ap) + { + Log.Debug(Globals.LogTag, "ConnectByWpsPbcAsync"); + return WiFiManagerImpl.Instance.ConnectByWpsPbcAsync(ap); + } + /// + /// Connects the access point with WPS PIN asynchronously. + /// + /// A task indicates whether the ConnectByWpsPin method is done or not. + /// The access point(AP) + /// The WPS PIN is a non-NULL string with length greater than 0 and less than or equal to 8. + static public Task ConnectByWpsPinAsync(WiFiAp ap, string pin) + { + Log.Debug(Globals.LogTag, "ConnectByWpsPinAsync"); + return WiFiManagerImpl.Instance.ConnectByWpsPinAsync(ap, pin); + } + /// + /// Disconnects the access point asynchronously. + /// + /// A task indicates whether the Disconnect method is done or not. + static public Task DisconnectAsync(WiFiAp ap) + { + return WiFiManagerImpl.Instance.DisconnectAsync(ap); + } + } +} diff --git a/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManagerImpl.cs b/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManagerImpl.cs new file mode 100644 index 0000000..7ea0a01 --- /dev/null +++ b/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiManagerImpl.cs @@ -0,0 +1,564 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Tizen.Network.WiFi +{ + static internal class Globals + { + internal const string LogTag = "Tizen.Network.WiFi"; + } + + internal partial class WiFiManagerImpl : IDisposable + { + private static readonly WiFiManagerImpl _instance = new WiFiManagerImpl(); + private Dictionary _callback_map = new Dictionary(); + private int _requestId = 0; + private string _macAddress; + private bool disposed = false; + + internal string MacAddress + { + get + { + if (String.IsNullOrEmpty(_macAddress)) + { + string address; + int ret = Interop.WiFi.GetMacAddress(out address); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get mac address, Error - " + (WiFiError)ret); + _macAddress = ""; + } + else + { + _macAddress = address; + } + } + return _macAddress; + } + } + internal string InterfaceName + { + get + { + string name; + int ret = Interop.WiFi.GetNetworkInterfaceName(out name); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get interface name, Error - " + (WiFiError)ret); + return ""; + } + return name; + } + } + internal WiFiConnectionState ConnectionState + { + get + { + int state; + int ret = Interop.WiFi.GetConnectionState(out state); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get connection state, Error - " + (WiFiError)ret); + return WiFiConnectionState.Failure; + } + return (WiFiConnectionState)state; + } + } + internal bool IsActivated + { + get + { + bool active; + int ret = Interop.WiFi.IsActivated(out active); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get isActive, Error - " + (WiFiError)ret); + } + return active; + } + } + + internal static WiFiManagerImpl Instance + { + get + { + return _instance; + } + } + + private WiFiManagerImpl() + { + initialize(); + } + + ~WiFiManagerImpl() + { + Dispose(false); + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + private void Dispose(bool disposing) + { + if (disposed) + return; + + if (disposing) + { + // Free managed objects. + } + //Free unmanaged objects + deinitialize(); + RemoveAllRegisteredEvent(); + disposed = true; + } + + private void initialize() + { + int ret = Interop.WiFi.Initialize(); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to initialize wifi, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret); + } + string address; + ret = Interop.WiFi.GetMacAddress(out address); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get mac address, Error - " + (WiFiError)ret); + _macAddress = ""; + } + _macAddress = address; + } + + private void deinitialize() + { + int ret = Interop.WiFi.Deinitialize(); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to deinitialize wifi, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret); + } + } + + internal IEnumerable GetFoundAps() + { + List apList = new List(); + Interop.WiFi.HandleCallback callback = (IntPtr apHandle, IntPtr userData) => + { + if (apHandle != IntPtr.Zero) + { + IntPtr clonedHandle; + Interop.WiFi.Ap.Clone(out clonedHandle, apHandle); + WiFiAp apItem = new WiFiAp(clonedHandle); + apList.Add(apItem); + return true; + } + return false; + }; + + int ret = Interop.WiFi.GetForeachFoundAps(callback, IntPtr.Zero); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get all APs, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret); + } + + return apList; + } + + internal IEnumerable GetFoundSpecificAps() + { + List apList = new List(); + Interop.WiFi.HandleCallback callback = (IntPtr apHandle, IntPtr userData) => + { + if (apHandle != IntPtr.Zero) + { + IntPtr clonedHandle; + Interop.WiFi.Ap.Clone(out clonedHandle, apHandle); + WiFiAp apItem = new WiFiAp(clonedHandle); + apList.Add(apItem); + return true; + } + return false; + + }; + + int ret = Interop.WiFi.GetForeachFoundSpecificAps(callback, IntPtr.Zero); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get specific APs, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret); + } + + return apList; + } + + internal IEnumerable GetWiFiConfigurations() + { + List configList = new List(); + Interop.WiFi.HandleCallback callback = (IntPtr configHandle, IntPtr userData) => + { + if (configHandle != IntPtr.Zero) + { + IntPtr clonedConfig; + Interop.WiFi.Config.Clone(configHandle, out clonedConfig); + WiFiConfiguration configItem = new WiFiConfiguration(clonedConfig); + configList.Add(configItem); + return true; + } + return false; + }; + + int ret = Interop.WiFi.Config.GetForeachConfiguration(callback, IntPtr.Zero); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get configurations, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret); + } + + return configList; + } + + internal void SaveWiFiNetworkConfiguration(WiFiConfiguration config) + { + IntPtr configHandle = config.GetHandle(); + int ret = Interop.WiFi.Config.SaveConfiguration(configHandle); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to save configuration, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret); + } + } + + internal WiFiAp GetConnectedAp() + { + IntPtr apHandle; + + int ret = Interop.WiFi.GetConnectedAp(out apHandle); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to connect with AP, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret); + } + WiFiAp ap = new WiFiAp(apHandle); + return ap; + } + + internal void RemoveAp(WiFiAp ap) + { + IntPtr apHandle = ap.GetHandle(); + int ret = Interop.WiFi.RemoveAp(apHandle); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to remove with AP, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret); + } + } + + internal Task ActivateAsync() + { + TaskCompletionSource task = new TaskCompletionSource(); + IntPtr id; + lock (_callback_map) + { + id = (IntPtr)_requestId++; + _callback_map[id] = (error, key) => + { + Log.Debug(Globals.LogTag, "wifi activated"); + if (error != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Error occurs during WiFi activating, " + (WiFiError)error); + task.SetException(new InvalidOperationException("Error occurs during WiFi activating, " + (WiFiError)error)); + } + task.SetResult(true); + lock (_callback_map) + { + _callback_map.Remove(key); + } + }; + } + int ret = Interop.WiFi.Activate(_callback_map[id], id); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to activate wifi, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret); + } + return task.Task; + } + + internal Task ActivateWithWiFiPickerTestedAsync() + { + TaskCompletionSource task = new TaskCompletionSource(); + IntPtr id; + lock (_callback_map) + { + id = (IntPtr)_requestId++; + _callback_map[id] = (error, key) => + { + Log.Debug(Globals.LogTag, "Activation finished"); + if (error != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Error occurs during WiFi activating, " + (WiFiError)error); + task.SetException(new InvalidOperationException("Error occurs during WiFi activating, " + (WiFiError)error)); + } + task.SetResult(true); + lock (_callback_map) + { + _callback_map.Remove(key); + } + }; + } + int ret = Interop.WiFi.ActivateWithWiFiPickerTested(_callback_map[id], id); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to activate wifi, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret); + } + return task.Task; + } + + internal Task DeactivateAsync() + { + TaskCompletionSource task = new TaskCompletionSource(); + IntPtr id; + lock (_callback_map) + { + id = (IntPtr)_requestId++; + _callback_map[id] = (error, key) => + { + Log.Debug(Globals.LogTag, "Deactivation finished"); + if (error != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Error occurs during WiFi deactivating, " + (WiFiError)error); + task.SetException(new InvalidOperationException("Error occurs during WiFi deactivating, " + (WiFiError)error)); + } + task.SetResult(true); + lock (_callback_map) + { + _callback_map.Remove(key); + } + }; + } + int ret = Interop.WiFi.Deactivate(_callback_map[id], id); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to deactivate wifi, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret); + } + return task.Task; + } + + internal Task ScanAsync() + { + TaskCompletionSource task = new TaskCompletionSource(); + IntPtr id; + lock (_callback_map) + { + id = (IntPtr)_requestId++; + _callback_map[id] = (error, key) => + { + Log.Debug(Globals.LogTag, "Scanning finished"); + if (error != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Error occurs during WiFi scanning, " + (WiFiError)error); + task.SetException(new InvalidOperationException("Error occurs during WiFi scanning, " + (WiFiError)error)); + } + task.SetResult(true); + lock (_callback_map) + { + _callback_map.Remove(key); + } + }; + } + int ret = Interop.WiFi.Scan(_callback_map[id], id); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to scan all AP, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret); + } + return task.Task; + } + + internal Task ScanSpecificApAsync(string essid) + { + TaskCompletionSource task = new TaskCompletionSource(); + IntPtr id; + lock (_callback_map) + { + id = (IntPtr)_requestId++; + _callback_map[id] = (error, key) => + { + Log.Debug(Globals.LogTag, "Scanning with specific AP finished"); + if (error != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Error occurs during WiFi scanning, " + (WiFiError)error); + task.SetException(new InvalidOperationException("Error occurs during WiFi scanning, " + (WiFiError)error)); + } + task.SetResult(true); + lock (_callback_map) + { + _callback_map.Remove(key); + } + }; + } + int ret = Interop.WiFi.ScanSpecificAp(essid, _callback_map[id], id); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to scan with specific AP, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret); + } + return task.Task; + } + + internal Task ConnectAsync(WiFiAp ap) + { + TaskCompletionSource task = new TaskCompletionSource(); + IntPtr id; + lock (_callback_map) + { + id = (IntPtr)_requestId++; + _callback_map[id] = (error, key) => + { + Log.Debug(Globals.LogTag, "Connecting finished : " + (WiFiError)error); + if (error != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Error occurs during WiFi connecting, " + (WiFiError)error); + task.SetException(new InvalidOperationException("Error occurs during WiFi connecting, " + (WiFiError)error)); + } + task.SetResult(true); + lock (_callback_map) + { + _callback_map.Remove(key); + } + }; + } + IntPtr apHandle = ap.GetHandle(); + int ret = Interop.WiFi.Connect(apHandle, _callback_map[id], id); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to connect wifi, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret); + } + return task.Task; + } + + internal Task DisconnectAsync(WiFiAp ap) + { + TaskCompletionSource task = new TaskCompletionSource(); + IntPtr id; + lock (_callback_map) + { + id = (IntPtr)_requestId++; + _callback_map[id] = (error, key) => + { + Log.Debug(Globals.LogTag, "Disconnecting finished"); + if (error != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Error occurs during WiFi disconnecting, " + (WiFiError)error); + task.SetException(new InvalidOperationException("Error occurs during WiFi disconnecting, " + (WiFiError)error)); + } + task.SetResult(true); + lock (_callback_map) + { + _callback_map.Remove(key); + } + }; + } + IntPtr apHandle = ap.GetHandle(); + int ret = Interop.WiFi.Disconnect(apHandle, _callback_map[id], id); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to disconnect wifi, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret); + } + return task.Task; + } + + internal Task ConnectByWpsPbcAsync(WiFiAp ap) + { + TaskCompletionSource task = new TaskCompletionSource(); + IntPtr id; + lock (_callback_map) + { + id = (IntPtr)_requestId++; + _callback_map[id] = (error, key) => + { + Log.Debug(Globals.LogTag, "Connecting by WPS PBC finished"); + if (error != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Error occurs during WiFi connecting, " + (WiFiError)error); + task.SetException(new InvalidOperationException("Error occurs during WiFi connecting, " + (WiFiError)error)); + } + task.SetResult(true); + lock (_callback_map) + { + _callback_map.Remove(key); + } + }; + } + IntPtr apHandle = ap.GetHandle(); + int ret = Interop.WiFi.ConnectByWpsPbc(apHandle, _callback_map[id], id); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to connect wifi, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret); + } + return task.Task; + } + + internal Task ConnectByWpsPinAsync(WiFiAp ap, string pin) + { + TaskCompletionSource task = new TaskCompletionSource(); + IntPtr id; + lock (_callback_map) + { + id = (IntPtr)_requestId++; + _callback_map[id] = (error, key) => + { + Log.Debug(Globals.LogTag, "Connecting by WPS PIN finished"); + if (error != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Error occurs during WiFi connecting, " + (WiFiError)error); + task.SetException(new InvalidOperationException("Error occurs during WiFi connecting, " + (WiFiError)error)); + } + task.SetResult(true); + lock (_callback_map) + { + _callback_map.Remove(key); + } + }; + } + IntPtr apHandle = ap.GetHandle(); + int ret = Interop.WiFi.ConnectByWpsPin(apHandle, pin, _callback_map[id], id); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to connect wifi, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret); + } + return task.Task; + } + } +} diff --git a/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiNetwork.cs b/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiNetwork.cs new file mode 100644 index 0000000..c80e03a --- /dev/null +++ b/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiNetwork.cs @@ -0,0 +1,286 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.Collections.Generic; +using System.Net; +using System.Runtime.InteropServices; +using Tizen.Network.Connection; + +namespace Tizen.Network.WiFi +{ + /// + /// A class for managing the Wi-Fi information. It allows applications to manager network information. + /// This class is not intended to create instance directly from applications. + /// + public class WiFiNetwork : IDisposable + { + private IntPtr _apHandle = IntPtr.Zero; + private IAddressInformation _ipv4; + private IAddressInformation _ipv6; + private bool disposed = false; + private string _essid; + + /// + /// The Extended Service Set Identifier(ESSID). + /// + public string Essid + { + get + { + if (string.IsNullOrEmpty(_essid)) + { + IntPtr strPtr; + int ret = Interop.WiFi.Ap.GetEssid(_apHandle, out strPtr); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get essid, Error - " + (WiFiError)ret); + _essid = ""; + } + else + { + _essid = Marshal.PtrToStringAnsi(strPtr); + } + } + return _essid; + } + } + /// + /// The Basic Service Set Identifier(BSSID). + /// + public string Bssid + { + get + { + IntPtr strPtr; + int ret = Interop.WiFi.Ap.GetBssid(_apHandle, out strPtr); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get bssid, Error - " + (WiFiError)ret); + return ""; + } + return Marshal.PtrToStringAnsi(strPtr); + } + } + /// + /// The address informaiton for Ipv4. + /// + public IAddressInformation Ipv4Setting + { + get + { + return _ipv4; + } + } + /// + /// The address ainformation for Ipv6. + /// + public IAddressInformation Ipv6Setting + { + get + { + return _ipv6; + } + } + /// + /// The proxy address. + /// + public string ProxyAddress + { + get + { + IntPtr strPtr; + int ret = Interop.WiFi.Ap.GetProxyAddress(_apHandle, (int)AddressFamily.Ipv4, out strPtr); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get proxy address, Error - " + (WiFiError)ret); + return ""; + } + return Marshal.PtrToStringAnsi(strPtr); + } + set + { + int ret = Interop.WiFi.Ap.SetProxyAddress(_apHandle, (int)AddressFamily.Ipv4, value); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to set proxy address, Error - " + (WiFiError)ret); + } + } + } + /// + /// The proxy type(Ipv6). + /// + public WiFiProxyType ProxyType + { + get + { + int type; + int ret = Interop.WiFi.Ap.GetProxyType(_apHandle, out type); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get proxy type, Error - " + (WiFiError)ret); + } + return (WiFiProxyType)type; + } + set + { + int ret = Interop.WiFi.Ap.SetProxyType(_apHandle, (int)value); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to set proxy type, Error - " + (WiFiError)ret); + } + } + } + /// + /// The frequency band(MHz). + /// + public int Frequency + { + get + { + int freq; + int ret = Interop.WiFi.Ap.GetFrequency(_apHandle, out freq); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get frequency, Error - " + (WiFiError)ret); + } + return freq; + } + } + /// + /// The Received signal strength indication(RSSI). + /// + public int Rssi + { + get + { + int rssi; + int ret = Interop.WiFi.Ap.GetRssi(_apHandle, out rssi); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get rssi, Error - " + (WiFiError)ret); + } + return rssi; + } + } + /// + /// Rhe max speed (Mbps). + /// + public int MaxSpeed + { + get + { + int maxSpeed; + int ret = Interop.WiFi.Ap.GetMaxSpeed(_apHandle, out maxSpeed); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get max speed, Error - " + (WiFiError)ret); + } + return maxSpeed; + } + } + /// + /// A property to check whether the access point is favorite or not. + /// + public bool IsFavorite + { + get + { + bool isFavorite; + int ret = Interop.WiFi.Ap.IsFavorite(_apHandle, out isFavorite); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get favorite, Error - " + (WiFiError)ret); + } + return isFavorite; + } + } + /// + /// A property to check whether the access point is passpoint or not. + /// + public bool IsPasspoint + { + get + { + bool isPasspoint; + Log.Debug(Globals.LogTag, "Handle: " + _apHandle); + int ret = Interop.WiFi.Ap.IsPasspoint(_apHandle, out isPasspoint); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get isPassport, Error - " + (WiFiError)ret); + } + return isPasspoint; + } + } + /// + /// The connection state. + /// + public WiFiConnectionState ConnectionState + { + get + { + int state; + int ret = Interop.WiFi.Ap.GetConnectionState(_apHandle, out state); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get connection state, Error - " + (WiFiError)ret); + } + return (WiFiConnectionState)state; + } + } + + internal WiFiNetwork(IntPtr apHandle) + { + _apHandle = apHandle; + _ipv4 = AddressFactory.CreateAddressInformation(apHandle, AddressFamily.Ipv4, AddressInformationType.WiFi); + _ipv6 = AddressFactory.CreateAddressInformation(apHandle, AddressFamily.Ipv6, AddressInformationType.WiFi); + + IntPtr strPtr; + int ret = Interop.WiFi.Ap.GetEssid(_apHandle, out strPtr); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get essid, Error - " + (WiFiError)ret); + } + _essid = Marshal.PtrToStringAnsi(strPtr); + } + + ~WiFiNetwork() + { + Dispose(false); + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + private void Dispose(bool disposing) + { + if (disposed) + return; + + if (disposing) + { + _ipv4.Dispose(); + _ipv6.Dispose(); + } + _apHandle = IntPtr.Zero; + disposed = true; + } + + } //WiFiNetworkInformation +} diff --git a/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiNetworkChange.cs b/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiNetworkChange.cs new file mode 100644 index 0000000..917d420 --- /dev/null +++ b/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiNetworkChange.cs @@ -0,0 +1,254 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.Threading.Tasks; + +namespace Tizen.Network.WiFi +{ + internal static class EventHandlerExtension + { + internal static void SafeInvoke(this EventHandler evt, object sender, EventArgs e) + { + var handler = evt; + if (handler != null) + { + handler(sender, e); + } + } + internal static void SafeInvoke(this EventHandler evt, object sender, T e) where T : EventArgs + { + var handler = evt; + if (handler != null) + { + handler(sender, e); + } + } + } + + internal partial class WiFiManagerImpl + { + private event EventHandler _deviceStateChanged; + private event EventHandler _connectionStateChanged; + private event EventHandler _rssiLevelChanged; + private event EventHandler _backgroundScanFinished; + + private Interop.WiFi.DeviceStateChangedCallback _deviceChangedCallback; + private Interop.WiFi.ConnectionStateChangedCallback _connectionChangedCallback; + private Interop.WiFi.RssiLevelChangedCallback _rssiChangedCallback; + private Interop.WiFi.VoidCallback _backgroundScanFinishedCallback; + + internal event EventHandler DeviceStateChanged + { + add + { + if (_deviceStateChanged == null) + { + RegisterDeviceStateChangedEvent(); + } + _deviceStateChanged += value; + } + remove + { + _deviceStateChanged -= value; + if (_deviceStateChanged == null) + { + UnregisterDeviceStateChangedEvent(); + } + } + } + + internal event EventHandler ConnectionStateChanged + { + add + { + if (_connectionStateChanged == null) + { + RegisterConnectionStateChangedEvent(); + } + _connectionStateChanged += value; + } + remove + { + _connectionStateChanged -= value; + if (_connectionStateChanged == null) + { + UnregisterConnectionStateChangedEvent(); + } + } + } + + internal event EventHandler RssiLevelChanged + { + add + { + if (_rssiLevelChanged == null) + { + RegisterRssiLevelChangedEvent(); + } + _rssiLevelChanged += value; + } + remove + { + _rssiLevelChanged -= value; + if (_rssiLevelChanged == null) + { + UnregisterRssiLevelChangedEvent(); + } + } + } + + internal event EventHandler BackgroundScanFinished + { + add + { + if (_backgroundScanFinished == null) + { + RegisterBackgroundScanFinishedEvent(); + } + _backgroundScanFinished += value; + } + remove + { + _backgroundScanFinished -= value; + if (_backgroundScanFinished == null) + { + UnregisterBackgroundScanFinishedEvent(); + } + } + } + + internal void RemoveAllRegisteredEvent() + { + //unregister all remaining events when this object is released. + if (_deviceStateChanged != null) + { + UnregisterDeviceStateChangedEvent(); + } + + if (_connectionStateChanged != null) + { + UnregisterConnectionStateChangedEvent(); + } + + if (_rssiLevelChanged != null) + { + UnregisterRssiLevelChangedEvent(); + } + + if (_backgroundScanFinished != null) + { + UnregisterBackgroundScanFinishedEvent(); + } + } + + private void RegisterDeviceStateChangedEvent() + { + _deviceChangedCallback = (int deviceState, IntPtr userDate) => + { + WiFiDeviceState state = (WiFiDeviceState)deviceState; + DeviceStateChangedEventArgs e = new DeviceStateChangedEventArgs(state); + _deviceStateChanged.SafeInvoke(null, e); + }; + int ret = Interop.WiFi.SetDeviceStateChangedCallback(_deviceChangedCallback, IntPtr.Zero); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to set device state changed callback, Error - " + (WiFiError)ret); + } + } + + private void UnregisterDeviceStateChangedEvent() + { + int ret = Interop.WiFi.UnsetDeviceStateChangedCallback(); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to unset device state changed callback, Error - " + (WiFiError)ret); + } + } + + private void RegisterConnectionStateChangedEvent() + { + _connectionChangedCallback = (int connectionState, IntPtr ap, IntPtr userDate) => + { + WiFiConnectionState state = (WiFiConnectionState)connectionState; + ConnectionStateChangedEventArgs e = new ConnectionStateChangedEventArgs(state, ap); + _connectionStateChanged.SafeInvoke(null, e); + }; + int ret = Interop.WiFi.SetConnectionStateChangedCallback(_connectionChangedCallback, IntPtr.Zero); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to set copnnection state changed callback, Error - " + (WiFiError)ret); + } + } + + private void UnregisterConnectionStateChangedEvent() + { + int ret = Interop.WiFi.UnsetConnectionStateChangedCallback(); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to unset device state changed callback, Error - " + (WiFiError)ret); + } + } + + private void RegisterRssiLevelChangedEvent() + { + + _rssiChangedCallback = (int rssiLevel, IntPtr userDate) => + { + WiFiRssiLevel level = (WiFiRssiLevel)rssiLevel; + RssiLevelChangedEventArgs e = new RssiLevelChangedEventArgs(level); + _rssiLevelChanged.SafeInvoke(null, e); + }; + int ret = Interop.WiFi.SetRssiLevelchangedCallback(_rssiChangedCallback, IntPtr.Zero); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to set rssi level changed callback, Error - " + (WiFiError)ret); + } + } + + private void UnregisterRssiLevelChangedEvent() + { + int ret = Interop.WiFi.UnsetRssiLevelchangedCallback(); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to unset rssi level changed callback, Error - " + (WiFiError)ret); + } + } + + private void RegisterBackgroundScanFinishedEvent() + { + _backgroundScanFinishedCallback = (int result, IntPtr userDate) => + { + EventArgs e = new EventArgs(); + _backgroundScanFinished.SafeInvoke(null, e); + }; + int ret = Interop.WiFi.SetBackgroundScanCallback(_backgroundScanFinishedCallback, IntPtr.Zero); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to set background scan callback, Error - " + (WiFiError)ret); + } + } + + private void UnregisterBackgroundScanFinishedEvent() + { + int ret = Interop.WiFi.UnsetBackgroundScanCallback(); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to unset background scan callback, Error - " + (WiFiError)ret); + } + } + } +} diff --git a/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiSecurity.cs b/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiSecurity.cs new file mode 100644 index 0000000..c35ba5a --- /dev/null +++ b/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiSecurity.cs @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using Tizen.Network.Connection; + +namespace Tizen.Network.WiFi +{ + /// + /// A class for managing the security information. It allows applications to manager security information. + /// This class is not intended to create instance directly from applications. + /// + public class WiFiSecurity : IDisposable + { + private IntPtr _apHandle = IntPtr.Zero; + private WiFiEap _eap; + private bool disposed = false; + + /// + /// The type of Wi-Fi security. + /// + public WiFiSecureType SecurityType + { + get + { + int type; + int ret = Interop.WiFi.Ap.GetSecurityType(_apHandle, out type); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get security type, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret); + } + return (WiFiSecureType)type; + } + set + { + int ret = Interop.WiFi.Ap.SetSecurityType(_apHandle, (int)value); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to set security type, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret); + } + } + } + /// + /// The type of Wi-Fi encryption + /// + public WiFiEncryptionType EncryptionType + { + get + { + int type; + int ret = Interop.WiFi.Ap.GetEncryptionType(_apHandle, out type); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get encryption type, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret); + } + return (WiFiEncryptionType)type; + } + set + { + int ret = Interop.WiFi.Ap.SetEncryptionType(_apHandle, (int)value); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to set encryption type, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret); + } + } + } + /// + /// The EAP information + /// + public WiFiEap EapInformation + { + get + { + return _eap; + } + } + + /// + /// A property to check whether the passphrase is required or not. + /// + public bool IsPassphraseRequired + { + get + { + bool required; + int ret = Interop.WiFi.Ap.IsPassphraseRequired(_apHandle, out required); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get isPassportRequired, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret); + } + return required; + } + } + /// + /// A property to check whether the Wi-Fi Protected Setup(WPS) is supported or not. + /// + public bool IsWpsSupported + { + get + { + bool supported; + int ret = Interop.WiFi.Ap.IsWpsSupported(_apHandle, out supported); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to get isWapSupported, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret); + } + return supported; + } + } + + internal WiFiSecurity(IntPtr apHandle) + { + _apHandle = apHandle; + _eap = new WiFiEap(apHandle); + } + + ~WiFiSecurity() + { + Dispose(false); + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + private void Dispose(bool disposing) + { + if (disposed) + return; + + if (disposing) + { + _eap.Dispose(); + } + _apHandle = IntPtr.Zero; + disposed = true; + } + + /// + /// Sets the passphrase. + /// + public void SetPassphrase(string passphrase) + { + int ret = Interop.WiFi.Ap.SetPassphrase(_apHandle, passphrase); + if (ret != (int)WiFiError.None) + { + Log.Error(Globals.LogTag, "Failed to set passphrase, Error - " + (WiFiError)ret); + WiFiErrorFactory.ThrowWiFiException(ret, _apHandle); + } + } + } //WiFiSecurityInformation +} diff --git a/packaging/csapi-network-wifi.manifest b/packaging/csapi-network-wifi.manifest new file mode 100644 index 0000000..75b0fa5 --- /dev/null +++ b/packaging/csapi-network-wifi.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/csapi-network-wifi.spec b/packaging/csapi-network-wifi.spec new file mode 100644 index 0000000..9e2a127 --- /dev/null +++ b/packaging/csapi-network-wifi.spec @@ -0,0 +1,45 @@ +Name: csapi-network-wifi +Summary: Tizen Wi-Fi API for C# +Version: 1.0.2 +Release: 1 +Group: Development/Libraries +License: Apache-2.0 +URL: https://www.tizen.org +Source0: %{name}-%{version}.tar.gz +Source1: %{name}.manifest + +AutoReqProv: no +ExcludeArch: aarch64 %ix86 + +BuildRequires: dotnet-build-tools + +# C# API Requires +BuildRequires: csapi-tizen-nuget +BuildRequires: csapi-network-connection-nuget + +%define Assemblies Tizen.Network.WiFi + +%description +%{summary} + +%dotnet_import_sub_packages + +%prep +%setup -q +cp %{SOURCE1} . + +%build +for ASM in %{Assemblies}; do +%dotnet_build $ASM +%dotnet_pack $ASM/$ASM.nuspec %{version} +done + +%install +for ASM in %{Assemblies}; do +%dotnet_install $ASM +done + +%files +%manifest %{name}.manifest +%license LICENSE +%attr(644,root,root) %{dotnet_assembly_files} -- 2.7.4