From: Yu Jiung Date: Thu, 22 Dec 2016 05:22:24 +0000 (+0900) Subject: [C# Wi-Fi Direct] Adding C# Wi-Fi Direct code X-Git-Tag: submit/trunk/20170823.075128~60^2~10 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d34c545840a3fa1a90581652e7eb5db11a6796ba;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [C# Wi-Fi Direct] Adding C# Wi-Fi Direct code Change-Id: I8a4d5635a1ee4fd80f97624dcf0ba764018ca857 Signed-off-by: Yu jiung --- 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/packaging/csapi-network-wifi-direct.manifest b/packaging/csapi-network-wifi-direct.manifest new file mode 100644 index 0000000..75b0fa5 --- /dev/null +++ b/packaging/csapi-network-wifi-direct.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/packaging/csapi-network-wifi-direct.spec b/packaging/csapi-network-wifi-direct.spec new file mode 100644 index 0000000..515f562 --- /dev/null +++ b/packaging/csapi-network-wifi-direct.spec @@ -0,0 +1,44 @@ +Name: csapi-network-wifi-direct +Summary: Tizen Wi-Fi Direct 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 + +%define Assemblies Tizen.Network.WiFiDirect + +%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} diff --git a/src/Tizen.Network.WiFiDirect/Interop/Interop.Libraries.cs b/src/Tizen.Network.WiFiDirect/Interop/Interop.Libraries.cs new file mode 100644 index 0000000..c036d47 --- /dev/null +++ b/src/Tizen.Network.WiFiDirect/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 WiFiDirect = "libwifi-direct.so.1"; + public const string Glib = "libglib-2.0.so.0"; + public const string Libc = "libc.so.6"; + } +} diff --git a/src/Tizen.Network.WiFiDirect/Interop/Interop.WiFiDirect.cs b/src/Tizen.Network.WiFiDirect/Interop/Interop.WiFiDirect.cs new file mode 100644 index 0000000..ac9afc1 --- /dev/null +++ b/src/Tizen.Network.WiFiDirect/Interop/Interop.WiFiDirect.cs @@ -0,0 +1,229 @@ +/* + * 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.WiFiDirect; +using System.Runtime.InteropServices; + +/// +/// Interop class for Wi-Fi Direct +/// +internal static partial class Interop +{ + /// + /// Wi-Fi Direct Native Apis + /// + internal static partial class WiFiDirect + { + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void DiscoveryStateChangedCallback(int result, WiFiDirectDiscoveryState state, IntPtr userData); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void PeerFoundCallback(int result, WiFiDirectDiscoveryState state, string address, IntPtr userData); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void DeviceStateChangedCallback(int result, WiFiDirectDeviceState state, IntPtr userData); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void ConnectionStateChangedCallback(int result, WiFiDirectConnectionState state, string address, IntPtr userData); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void ClientIpAddressAssignedCallback(string macAddress, string ipAddress, string interfaceAddress, IntPtr userData); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void ServiceStateChangedCallback(int result, WiFiDirectServiceDiscoveryState state, WiFiDirectServiceType type, IntPtr responseData, string address, IntPtr userData); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void StateChangedCallback(WiFiDirectState state, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate bool DiscoveredPeerCallback(ref DiscoveredPeerStruct peer, IntPtr userData); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate bool ConnectedPeerCallback(ref ConnectedPeerStruct peer, IntPtr userData); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate bool WpsTypeCallback(WiFiDirectWpsType type, IntPtr userData); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate bool PersistentGroupCallback(string address, string ssid, IntPtr userData); + + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_set_state_changed_cb")] + internal static extern int SetStateChangedCallback(StateChangedCallback stateChangedCb, IntPtr userData); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_unset_state_changed_cb")] + internal static extern int UnsetStateChangedCallback(); + + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_set_device_state_changed_cb")] + internal static extern int SetDeviceStateChangedCallback(DeviceStateChangedCallback deviceChangedCb, IntPtr userData); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_unset_device_state_changed_cb")] + internal static extern int UnsetDeviceStateChangedCallback(); + + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_set_discovery_state_changed_cb")] + internal static extern int SetDiscoveryStateChangedCallback(DiscoveryStateChangedCallback discoveryStateChangedCb, IntPtr userData); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_unset_discovery_state_changed_cb")] + internal static extern int UnsetDiscoveryStateChangedCallback(); + + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_set_peer_found_cb")] + internal static extern int SetPeerFoundCallback(PeerFoundCallback peerFoundCb, IntPtr userData); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_unset_peer_found_cb")] + internal static extern int UnsetPeerFoundCallback(); + + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_set_connection_state_changed_cb")] + internal static extern int SetConnectionChangedCallback(ConnectionStateChangedCallback connectionCb, IntPtr userData); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_unset_connection_state_changed_cb")] + internal static extern int UnsetConnectionChangedCallback(); + + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_set_client_ip_address_assigned_cb")] + internal static extern int SetIpAddressAssignedCallback(ClientIpAddressAssignedCallback callback, IntPtr userData); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_unset_client_ip_address_assigned_cb")] + internal static extern int UnsetIpAddressAssignedCallback(); + + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_set_service_state_changed_cb")] + internal static extern int SetServiceStateChangedCallback(ServiceStateChangedCallback serviceStateChangedCb, IntPtr userData); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_unset_service_state_changed_cb")] + internal static extern int UnsetServiceStateChangedCallback(); + + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_initialize")] + internal static extern int Initialize(); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_deinitialize")] + internal static extern int Deinitialize(); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_activate")] + internal static extern int Activate(); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_deactivate")] + internal static extern int Deactivate(); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_start_discovery_specific_channel")] + internal static extern int StartDiscoveryInChannel(bool listenOnly, int timeout, WiFiDirectDiscoveryChannel channel); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_cancel_discovery")] + internal static extern int StopDiscovery(); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_foreach_discovered_peers")] + internal static extern int GetDiscoveredPeers(DiscoveredPeerCallback callback, IntPtr userData); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_connect")] + internal static extern int Connect(string address); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_cancel_connection")] + internal static extern int CancelConnection(string address); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_disconnect_all")] + internal static extern int DisconnectAll(); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_disconnect")] + internal static extern int Disconnect(string address); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_foreach_connected_peers")] + internal static extern int GetConnectedPeers(ConnectedPeerCallback callback, IntPtr userData); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_create_group")] + internal static extern int CreateGroup(); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_destroy_group")] + internal static extern int DestroyGroup(); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_is_group_owner")] + internal static extern int IsGroupOwner(out bool isGroupOwner); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_is_autonomous_group")] + internal static extern int IsAutonomousGroup(out bool isAutonomous); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_set_device_name")] + internal static extern int SetName(string name); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_get_device_name")] + internal static extern int GetName(out string name); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_get_ssid")] + internal static extern int GetSsid(out string ssid); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_get_network_interface_name")] + internal static extern int GetInterfaceName(out string name); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_get_ip_address")] + internal static extern int GetIpAddress(out string address); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_get_subnet_mask")] + internal static extern int GetSubnetMask(out string mask); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_get_gateway_address")] + internal static extern int GetGatewayAddress(out string address); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_get_mac_address")] + internal static extern int GetMacAddress(out string address); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_get_state")] + internal static extern int GetState(out WiFiDirectState state); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_is_discoverable")] + internal static extern int IsDiscoverable(out bool isDiscoverable); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_is_listening_only")] + internal static extern int IsListeningOnly(out bool listenOnly); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_get_primary_device_type")] + internal static extern int GetPrimaryType(out WiFiDirectPrimaryDeviceType type); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_get_secondary_device_type")] + internal static extern int GetSecondaryType(out WiFiDirectSecondaryDeviceType type); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_activate_pushbutton")] + internal static extern int ActivatePushButton(); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_set_wps_pin")] + internal static extern int SetWpsPin(string pin); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_get_wps_pin")] + internal static extern int GetWpsPin(out string pin); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_get_supported_wps_mode")] + internal static extern int GetWpsMode(out int mode); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_foreach_supported_wps_types")] + internal static extern int GetWpsTypes(WpsTypeCallback callback, IntPtr userData); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_get_local_wps_type")] + internal static extern int GetLocalWpsType(out WiFiDirectWpsType type); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_set_req_wps_type")] + internal static extern int SetReqWpsType(WiFiDirectWpsType type); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_get_req_wps_type")] + internal static extern int GetReqWpsType(out WiFiDirectWpsType type); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_set_group_owner_intent")] + internal static extern int SetIntent(int intent); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_get_group_owner_intent")] + internal static extern int GetIntent(out int intent); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_set_max_clients")] + internal static extern int SetMaxClients(int max); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_get_max_clients")] + internal static extern int GetMaxClients(out int max); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_set_passphrase")] + internal static extern int SetPassPhrase(string passphrase); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_get_passphrase")] + internal static extern int GetPassPhrase(out string passphrase); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_get_operating_channel")] + internal static extern int GetChannel(out int channel); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_set_autoconnection_mode")] + internal static extern int SetAutoConnectionMode(bool mode); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_is_autoconnection_mode")] + internal static extern int GetAutoConnectionMode(out bool mode); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_set_autoconnection_peer")] + internal static extern int SetAutoConnectionPeer(string address); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_set_persistent_group_enabled")] + internal static extern int SetPersistentGroupState(bool enabled); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_is_persistent_group_enabled")] + internal static extern int GetPersistentGroupState(out bool enabled); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_foreach_persistent_groups")] + internal static extern int GetPersistentGroups(PersistentGroupCallback callback, IntPtr userData); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_remove_persistent_group")] + internal static extern int RemovePersistentGroup(string address, string ssid); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_start_service_discovery")] + internal static extern int StartServiceDiscovery(string address, WiFiDirectServiceType type); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_cancel_service_discovery")] + internal static extern int StopServiceDiscovery(string address, WiFiDirectServiceType type); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_register_service")] + internal static extern int RegisterService(WiFiDirectServiceType type, string info1, string info2, out uint serviceId); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_deregister_service")] + internal static extern int DeregisterService(uint serviceId); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_init_miracast")] + internal static extern int InitMiracast(bool enable); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_get_peer_info")] + internal static extern int GetDiscoveredPeerInfo(string address, out IntPtr peer); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_init_display")] + internal static extern int InitDisplay(); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_deinit_display")] + internal static extern int DeinitDisplay(); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_set_display")] + internal static extern int SetDisplay(WiFiDirectDisplayType type, int port, int hdcp); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_set_display_availability")] + internal static extern int SetDisplayAvailability(bool availability); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_get_peer_display_type")] + internal static extern int GetDisplayType(string address, out WiFiDirectDisplayType type); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_get_peer_display_availability")] + internal static extern int GetDisplayAvailability(string address, out bool availability); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_get_peer_display_hdcp")] + internal static extern int GetDisplayHdcp(string address, out int hdcp); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_get_peer_display_port")] + internal static extern int GetDisplayPort(string address, out int port); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_get_peer_display_throughput")] + internal static extern int GetDisplayThroughput(string address, out int throughput); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_get_session_timer")] + internal static extern int GetSessionTimer(out int seconds); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_set_session_timer")] + internal static extern int SetSessionTimer(int seconds); + [DllImport(Libraries.WiFiDirect,EntryPoint = "wifi_direct_set_auto_group_removal")] + internal static extern int SetAutoGroupRemoval(bool enable); + } +} diff --git a/src/Tizen.Network.WiFiDirect/Properties/AssemblyInfo.cs b/src/Tizen.Network.WiFiDirect/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..ca90f33 --- /dev/null +++ b/src/Tizen.Network.WiFiDirect/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.WiFiDirect")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Samsung Electronics")] +[assembly: AssemblyProduct("Tizen.Network.WiFiDirect")] +[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("08c34d73-7986-4e6e-8c21-5343c7feec86")] + +// 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/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect.Net45.csproj b/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect.Net45.csproj new file mode 100644 index 0000000..22b05ed --- /dev/null +++ b/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect.Net45.csproj @@ -0,0 +1,73 @@ + + + + Debug + AnyCPU + {E937D82B-AE58-409A-95C9-8F044EF58485} + Library + Properties + Tizen.Network.WiFiDirect + Tizen.Network.WiFiDirect + 512 + v4.5 + + + true + full + false + bin\Debug\Net45\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\Net45\ + TRACE + prompt + 4 + + + true + + + Tizen.Network.WiFiDirect.snk + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect.Net45.project.json b/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect.Net45.project.json new file mode 100644 index 0000000..6ce3032 --- /dev/null +++ b/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect.Net45.project.json @@ -0,0 +1,11 @@ +{ + "dependencies": { + "Tizen": "1.0.2" + }, + "frameworks": { + "net45": {} + }, + "runtimes": { + "win": {} + } +} diff --git a/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect.csproj b/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect.csproj new file mode 100755 index 0000000..83600d1 --- /dev/null +++ b/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect.csproj @@ -0,0 +1,82 @@ + + + + Debug + AnyCPU + {08C34D73-7986-4E6E-8C21-5343C7FEEC86} + Library + Properties + Tizen.Network.WiFiDirect + Tizen.Network.WiFiDirect + 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.WiFiDirect.snk + + + + + + + + + + + + + + + + + + + + + + + + + <_TargetFrameworkDirectories>$(MSBuildThisFileDirectory) + <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory) + true + + \ No newline at end of file diff --git a/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect.nuspec b/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect.nuspec new file mode 100644 index 0000000..039b102 --- /dev/null +++ b/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect.nuspec @@ -0,0 +1,21 @@ + + + + Tizen.Network.WiFiDirect + $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 Direct APIs for Tizen.Network.WiFiDirect + + + + + + + + + diff --git a/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect.project.json b/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect.project.json new file mode 100755 index 0000000..f463d9b --- /dev/null +++ b/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect.project.json @@ -0,0 +1,10 @@ +{ + "dependencies": { + "NETStandard.Library": "1.6.0", + "System.Threading.Thread": "4.3.0", + "Tizen": "1.0.2" + }, + "frameworks": { + "netstandard1.3": {} + } +} diff --git a/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect.sln b/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect.sln new file mode 100644 index 0000000..e448ba7 --- /dev/null +++ b/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect.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.WiFiDirect", "Tizen.Network.WiFiDirect.csproj", "{08C34D73-7986-4E6E-8C21-5343C7FEEC86}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {08C34D73-7986-4E6E-8C21-5343C7FEEC86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {08C34D73-7986-4E6E-8C21-5343C7FEEC86}.Debug|Any CPU.Build.0 = Debug|Any CPU + {08C34D73-7986-4E6E-8C21-5343C7FEEC86}.Release|Any CPU.ActiveCfg = Release|Any CPU + {08C34D73-7986-4E6E-8C21-5343C7FEEC86}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect.snk b/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect.snk new file mode 100644 index 0000000..cffdfb5 Binary files /dev/null and b/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect.snk differ diff --git a/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect/WiFiDirectData.cs b/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect/WiFiDirectData.cs new file mode 100644 index 0000000..10e2862 --- /dev/null +++ b/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect/WiFiDirectData.cs @@ -0,0 +1,165 @@ +/* + * 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 System.Collections.ObjectModel; + +namespace Tizen.Network.WiFiDirect +{ + [StructLayout(LayoutKind.Sequential)] + internal struct DiscoveredPeerStruct + { + [MarshalAsAttribute(UnmanagedType.LPStr)] + internal string _name; + + [MarshalAsAttribute(UnmanagedType.LPStr)] + internal string _macAddress; + + [MarshalAsAttribute(UnmanagedType.LPStr)] + internal string _interfaceAddress; + + internal int _channel; + + [MarshalAsAttribute(UnmanagedType.I1)] + internal bool _isConnected; + + [MarshalAsAttribute(UnmanagedType.I1)] + internal bool _isGroupOwner; + + [MarshalAsAttribute(UnmanagedType.I1)] + internal bool _isPersistentGroupOwner; + + internal WiFiDirectPrimaryDeviceType _primaryType; + + internal WiFiDirectSecondaryDeviceType _secondaryType; + + internal int _wpsTypes; + + [MarshalAsAttribute(UnmanagedType.I1)] + internal bool _isP2PInvitationSupported; + + internal uint _serviceCount; + + internal IntPtr _serviceList; + + [MarshalAsAttribute(UnmanagedType.I1)] + internal bool _isMiracast; + } + + [StructLayout(LayoutKind.Sequential)] + internal struct ConnectedPeerStruct + { + [MarshalAsAttribute(UnmanagedType.LPStr)] + internal string _name; + + [MarshalAsAttribute(UnmanagedType.LPStr)] + internal string _ipAddress; + + [MarshalAsAttribute(UnmanagedType.LPStr)] + internal string _macAddress; + + [MarshalAsAttribute(UnmanagedType.LPStr)] + internal string _interfaceAddress; + + internal int _channel; + + [MarshalAsAttribute(UnmanagedType.I1)] + internal bool _isP2PSupport; + + internal WiFiDirectPrimaryDeviceType _primaryType; + + internal WiFiDirectSecondaryDeviceType _secondaryType; + + internal uint _serviceCount; + + internal IntPtr _serviceList; + + [MarshalAsAttribute(UnmanagedType.I1)] + internal bool _isMiracast; + } + + internal static class WiFiDirectUtils + { + internal static WiFiDirectPeer ConvertStructToDiscoveredPeer(DiscoveredPeerStruct peer) + { + WiFiDirectPeer resultPeer = new WiFiDirectPeer(); + resultPeer._peerDeviceName = peer._name; + resultPeer._peerMacAddress = peer._macAddress; + resultPeer._peerInterfaceAddress = peer._interfaceAddress; + resultPeer._peerChannel = peer._channel; + resultPeer._isPeerConnected = peer._isConnected; + resultPeer._isPeerGroupOwner = peer._isGroupOwner; + resultPeer._isPeerPersistentGroupOwner = peer._isPersistentGroupOwner; + resultPeer._peerPrimaryType = peer._primaryType; + resultPeer._peerSecondaryType = peer._secondaryType; + resultPeer._peerWpsTypes = peer._wpsTypes; + resultPeer._p2PInvitationSupported = peer._isP2PInvitationSupported; + Collection uuidList = null; + + if (peer._serviceCount > 0) + { + IntPtr[] serviceList = new IntPtr[peer._serviceCount]; + Marshal.Copy(peer._serviceList, serviceList, 0, (int)peer._serviceCount); + uuidList = new Collection(); + foreach (IntPtr service in serviceList) + { + string registeredService = Marshal.PtrToStringAnsi(service); + uuidList.Add(registeredService); + } + + resultPeer._peerServiceCount = peer._serviceCount; + resultPeer._peerServiceList = uuidList; + } + + resultPeer._isPeerMiracastDevice = peer._isMiracast; + return resultPeer; + } + + internal static WiFiDirectPeer ConvertStructToConnectedPeer(ConnectedPeerStruct peer) + { + WiFiDirectPeer resultPeer = new WiFiDirectPeer(); + resultPeer._peerDeviceName = peer._name; + resultPeer._peerIpAddress = peer._ipAddress; + resultPeer._peerMacAddress = peer._macAddress; + resultPeer._peerInterfaceAddress = peer._interfaceAddress; + resultPeer._peerChannel = peer._channel; + resultPeer._peerP2PSupport = peer._isP2PSupport; + resultPeer._peerPrimaryType = peer._primaryType; + resultPeer._peerSecondaryType = peer._secondaryType; + Collection uuidList = null; + + if (peer._serviceCount > 0) + { + IntPtr[] serviceList = new IntPtr[peer._serviceCount]; + Marshal.Copy(peer._serviceList, serviceList, 0, (int)peer._serviceCount); + uuidList = new Collection(); + foreach (IntPtr service in serviceList) + { + string registeredService = Marshal.PtrToStringAnsi(service); + uuidList.Add(registeredService); + } + + resultPeer._peerServiceCount = peer._serviceCount; + resultPeer._peerServiceList = uuidList; + } + + resultPeer._isPeerMiracastDevice = peer._isMiracast; + return resultPeer; + } + } + +} diff --git a/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect/WiFiDirectEnumerations.cs b/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect/WiFiDirectEnumerations.cs new file mode 100644 index 0000000..e15f92e --- /dev/null +++ b/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect/WiFiDirectEnumerations.cs @@ -0,0 +1,651 @@ +/* + * 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.WiFiDirect +{ + /// + /// Enumeration for Wi-Fi Direct discovery state. + /// + public enum WiFiDirectDiscoveryState + { + /// + /// Only listen has started. + /// + OnlyListenStarted = 0, + /// + /// Discovery started. + /// + Started, + /// + /// A remote peer is found. + /// + Found, + /// + /// Discovery finished. + /// + Finished, + /// + /// A remote peer is lost. + /// + Lost + } + + /// + /// Enumeration for Wi-Fi Direct display device type. + /// + public enum WiFiDirectDisplayType + { + /// + /// Configure as WFD source. + /// + Source = 0, + /// + /// Configure as WFD primary sink. + /// + Prisink, + /// + /// Configure as WFD secondary sink. + /// + Secsink, + /// + /// Configure as WFD dual role. + /// + Dual + } + + /// + /// Enumeration for Wi-Fi Discovery channel. + /// + public enum WiFiDirectDiscoveryChannel + { + /// + /// Scan full channel. + /// + FullScan = 0, + /// + /// The social channel. + /// + SocialChannel = 1611, + /// + /// Scan channel 1. + /// + Channel1 = 1, + /// + /// Scan channel 6. + /// + Channel6 = 6, + /// + /// Scan channel 11. + /// + Channel11 = 11 + } + + /// + /// Enumeration for Wi-Fi Direct connection state. + /// + public enum WiFiDirectConnectionState + { + /// + /// Connection is requested. + /// + ConnectionRequest, + /// + /// Wps is requested. + /// + ConnectionWpsRequest, + /// + /// Connection in progress. + /// + ConnectionInProgress, + /// + /// Connected . + /// + ConnectionRsp, + /// + /// Disconnected by remote group client. + /// + DisassociationInd, + /// + /// Disconnected by local device. + /// + DisconnectRsp, + /// + /// Disconnected by remote group owner. + /// + DisconnectInd, + /// + /// Group is created. + /// + GroupCreated, + /// + /// Group is destroyed. + /// + GroupDestroyed + } + + /// + /// Enumeration for Wi-Fi Direct primary device type. + /// + public enum WiFiDirectPrimaryDeviceType + { + /// + /// Computer. + /// + Computer = 1, + /// + /// Input device. + /// + InputDevice = 2, + /// + /// Printer. + /// + Printer = 3, + /// + /// Camera. + /// + Camera = 4, + /// + /// Storage. + /// + Storage = 5, + /// + /// Network Infrastructure. + /// + NetworkInfrastructure = 6, + /// + /// Display. + /// + Display = 7, + /// + /// Multimedia device. + /// + MultimediaDevice = 8, + /// + /// Game device. + /// + GameDevice = 9, + /// + /// Telephone. + /// + Telephone = 10, + /// + /// Audio. + /// + Audio = 11, + /// + /// Others. + /// + Other = 255 + } + + /// + /// Enumeration for Wi-Fi Direct secondary device type. + /// + /// + public enum WiFiDirectSecondaryDeviceType + { + /// + /// Computer PC. + /// + ComputerPc = 1, + /// + /// Computer server. + /// + ComputerServer = 2, + /// + /// Computer media center. + /// + ComputerMediaCenter = 3, + /// + /// Computer UMPC. + /// + ComputerUmpc = 4, + /// + /// Computer notebook. + /// + ComputerNotebook = 5, + /// + /// Computer desktop + /// + ComputerDesktop = 6, + /// + /// Computer MID. + /// + ComputerMid = 7, + /// + /// Computer netbook. + /// + ComputerNetbook = 8, + /// + /// Input keyboard. + /// + InputKeyboard = 1, + /// + /// Input mouse. + /// + InputMouse = 2, + /// + /// Input joystick. + /// + InputJoystick = 3, + /// + /// Input trackball. + /// + InputTrackball = 4, + /// + /// Input controller. + /// + InputController = 5, + /// + /// Inpute remote. + /// + InputRemote = 6, + /// + /// Input touch screen. + /// + InputTouchScreen = 7, + /// + /// Input biometric reader. + /// + InputBiometricReader = 8, + /// + /// Input barcode reader. + /// + InputBarcodeReader = 9, + /// + /// Printer. + /// + Printer = 1, + /// + /// Printer scanner. + /// + PrinterScanner = 2, + /// + /// Printer fax. + /// + PrinterFax = 3, + /// + /// Printer copier. + /// + PrinterCopier = 4, + /// + /// Printer all-in-one. + /// + PrinterAllInOne = 5, + /// + /// Digital still camera. + /// + CameraDigital = 1, + /// + /// Video camera. + /// + CameraVideo = 2, + /// + /// Webcam. + /// + CameraWebcam = 3, + /// + /// Security camera. + /// + CameraSecurity = 4, + /// + /// Storage NAS. + /// + StorageNas = 1, + /// + /// Network ap. + /// + NetworkAp = 1, + /// + /// Network router. + /// + NetworkRouter = 2, + /// + /// Network switch. + /// + NetworkSwitch = 3, + /// + /// Network gateway. + /// + NetworkGateway = 4, + /// + /// Display tv. + /// + DisplayTv = 1, + /// + /// Display picture frame. + /// + DisplayPicFrame = 2, + /// + /// Display projector. + /// + DisplayProjector = 3, + /// + /// Display monitor. + /// + DisplayMonitor = 4, + /// + /// Multimedia DAR. + /// + MultimediaDar = 1, + /// + /// Multimedia PVR. + /// + MultimediaPvr = 2, + /// + /// Multimedia MCX. + /// + MultimediaMcx = 3, + /// + /// Multimedia set-top box. + /// + MultimediaStb = 4, + /// + /// Media Server / Media Adapter / Media Extender. + /// + MultimediaMsMaMe = 5, + /// + /// Multimedia portable video player. + /// + MultimediaPvp = 6, + /// + /// Game xbox. + /// + GameXbox = 1, + /// + /// The game xbox 360. + /// + GameXbox360, + /// + /// Game play station. + /// + GamePlayStation = 2, + /// + /// Game console. + /// + GameConsole = 3, + /// + /// Game portable. + /// + GamePortable = 4, + /// + /// Windows mobile. + /// + TelephoneWindowsMobile = 1, + /// + /// Phone - single mode. + /// + TelephonePhoneSingle = 2, + /// + /// Phone - dual mode. + /// + TelephonePhoneDual = 3, + /// + /// Smart Phone - single mode. + /// + TelephoneSmartphoneSingle = 4, + /// + /// Smart Phone - dual mode. + /// + TelephoneSmartphoneDual = 5, + /// + /// Audio tuner. + /// + AudioTuner = 1, + /// + /// Audio speaker. + /// + AudioSpeaker = 2, + /// + /// Audio pmp. + /// + AudioPmp = 3, + /// + /// Audio headset. + /// + AudioHeadset = 4, + /// + /// Audio headphone. + /// + AudioHeadphone = 5, + /// + /// Audio microphone. + /// + AudioMic = 6 + } + + /// + /// Enumeration for Wi-Fi Direct link status. + /// + /// + public enum WiFiDirectState + { + /// + /// Deactivated. + /// + Deactivated = 0, + /// + /// Deactivating. + /// + Deactivating, + /// + /// Activating. + /// + Activating, + /// + /// Activated. + /// + Activated, + /// + /// Discovering. + /// + Discovering, + /// + /// Connecting. + /// + Connecting, + /// + /// Disconnecting. + /// + Disconnecting, + /// + /// Connected. + /// + Connected, + /// + /// Group owner. + /// + GroupOwner + } + + /// + /// Enumeration for Wi-Fi WPS type. + /// + public enum WiFiDirectWpsType + { + /// + /// No WPS type. + /// + None = 0x00, + /// + /// Push button configuration. + /// + Pbc = 0x01, + /// + /// Display pin code. + /// + PinDisplay = 0x02, + /// + /// Provide the keypad to input the pin. + /// + PinKeypad = 0x04 + } + + /// + /// Enumeration for Service Discovery type. + /// + public enum WiFiDirectServiceType + { + /// + /// Service discovery Type all. + /// + All, + /// + /// Service discovery Type bonjour. + /// + Bonjour, + /// + /// Service discovery Type UPNP. + /// + Upnp, + /// + /// Service discovery Type ws discovery. + /// + WsDiscovery, + /// + /// Service discovery Type wifi-display. + /// + WiFiDisplay, + /// + /// Service discovery Type bt address. + /// + BtAddress, + /// + /// Service discovery Type contact info. + /// + ContactInfo, + /// + /// Service discovery Type vendor-specific. + /// + Vendor + } + + /// + /// Enumeration for Wi-Fi Direct service Discovery state. + /// + public enum WiFiDirectServiceDiscoveryState + { + /// + /// Service discovery started. + /// + Started, + /// + /// Service discovery found. + /// + Found, + /// + /// Service discovery finished. + /// + Finished + } + + /// + /// Enumeration for Wi-Fi Direct device state. + /// + public enum WiFiDirectDeviceState + { + /// + /// Activated. + /// + Activated, + /// + /// Deactivated. + /// + Deactivated + } + + /// + /// Enumeration for Wi-Fi Direct error code. + /// + public enum WiFiDirectError + { + /// + /// Successful. + /// + None = ErrorCode.None, + /// + /// Operation not permitted. + /// + NotPermitted = ErrorCode.NotPermitted, + /// + /// Out of memory. + /// + OutOfMemory = ErrorCode.OutOfMemory, + /// + /// Permission denied. + /// + PermissionDenied = ErrorCode.PermissionDenied, + /// + /// Device or resource busy. + /// + ResourceBusy = ErrorCode.ResourceBusy, + /// + /// Invalid function parameter. + /// + InvalidParameter = ErrorCode.InvalidParameter, + /// + /// Connection timed out. + /// + ConnectionTimeOut = ErrorCode.ConnectionTimeout, + /// + /// Not supported. + /// + NotSupported = ErrorCode.NotSupported, + /// + /// Not initialized. + /// + NotInitialized = -0x01C60000 | 0x01, + /// + /// I/O error. + /// + CommunicationFailed = -0x01C60000 | 0x02, + /// + /// WiFi is being used. + /// + WiFiUsed = -0x01C60000 | 0x03, + /// + /// Mobile AP is being used. + /// + MobileApUsed = -0x01C60000 | 0x04, + /// + /// Connection failed. + /// + ConnectionFailed = -0x01C60000 | 0x05, + /// + /// Authentication failed. + /// + AuthFailed = -0x01C60000 | 0x06, + /// + /// Operation failed. + /// + OperationFailed = -0x01C60000 | 0x07, + /// + /// Too many client. + /// + TooManyClient = -0x01C60000 | 0x08, + /// + /// Already initialized client. + /// + AlreadyInitialized = -0x01C60000 | 0x09, + /// + /// Connection cancelled by local device. + /// + ConnectionCancelled = -0x01C60000 | 0x10 + } +} diff --git a/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect/WiFiDirectError.cs b/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect/WiFiDirectError.cs new file mode 100644 index 0000000..325a5c9 --- /dev/null +++ b/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect/WiFiDirectError.cs @@ -0,0 +1,65 @@ +/* + * 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.WiFiDirect +{ + internal static class WiFiDirectErrorFactory + { + internal static void ThrowWiFiDirectException(int exception) + { + WiFiDirectError _error = (WiFiDirectError)exception; + switch (_error) + { + case WiFiDirectError.InvalidParameter: + throw new InvalidOperationException("Invalid parameter"); + case WiFiDirectError.AlreadyInitialized: + throw new InvalidOperationException("Already initialized"); + case WiFiDirectError.AuthFailed: + throw new InvalidOperationException("Authentication failed"); + case WiFiDirectError.CommunicationFailed: + throw new InvalidOperationException("Communication failed"); + case WiFiDirectError.ConnectionCancelled: + throw new InvalidOperationException("Connection cancelled"); + case WiFiDirectError.ConnectionFailed: + throw new InvalidOperationException("Connection failed"); + case WiFiDirectError.ConnectionTimeOut: + throw new InvalidOperationException("Connection timed out"); + case WiFiDirectError.MobileApUsed: + throw new InvalidOperationException("Mobile Ap is being used"); + case WiFiDirectError.NotInitialized: + throw new InvalidOperationException("Not initialized"); + case WiFiDirectError.NotPermitted: + throw new InvalidOperationException("Not permitted"); + case WiFiDirectError.NotSupported: + throw new NotSupportedException("Not supported"); + case WiFiDirectError.OperationFailed: + throw new InvalidOperationException("Operation failed"); + case WiFiDirectError.OutOfMemory: + throw new InvalidOperationException("Out of memory"); + case WiFiDirectError.PermissionDenied: + throw new InvalidOperationException("Permission denied"); + case WiFiDirectError.ResourceBusy: + throw new InvalidOperationException("Resource is busy"); + case WiFiDirectError.TooManyClient: + throw new InvalidOperationException("Too many client"); + case WiFiDirectError.WiFiUsed: + throw new InvalidOperationException("Wi-fi is being used"); + } + } + } +} diff --git a/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect/WiFiDirectEventArgs.cs b/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect/WiFiDirectEventArgs.cs new file mode 100644 index 0000000..b87af3b --- /dev/null +++ b/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect/WiFiDirectEventArgs.cs @@ -0,0 +1,382 @@ +/* + * 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; + +namespace Tizen.Network.WiFiDirect +{ + /// + /// An extended EventArgs class which contains changed connection state during connecting or disconnecting peer device. + /// + public class ConnectionStateChangedEventArgs : EventArgs + { + private WiFiDirectError _error; + private WiFiDirectConnectionState _state; + private string _macAddress; + + internal ConnectionStateChangedEventArgs(WiFiDirectError error, WiFiDirectConnectionState state, string macAddress) + { + _error = error; + _state = state; + _macAddress = macAddress; + } + + /// + /// Wi-Fi Direct result. + /// + public WiFiDirectError Error + { + get + { + return _error; + } + } + + /// + /// Wi-Fi Direct connection state of peer. + /// + public WiFiDirectConnectionState State + { + get + { + return _state; + } + } + + /// + /// MacAddress of peer. + /// + public string MacAddress + { + get + { + return _macAddress; + } + } + } + + /// + /// An extended EventArgs class which contains address properties of the peer when it connects to a group owner. + /// + public class IpAddressAssignedEventArgs : EventArgs + { + private string _macAddress; + private string _ipAddress; + private string _interfaceAddress; + + internal IpAddressAssignedEventArgs(string macAddress, string ipAddress, string interfaceAddress) + { + _macAddress = macAddress; + _ipAddress = ipAddress; + _interfaceAddress = interfaceAddress; + } + + /// + /// MacAddress of connected peer. + /// + public string MacAddress + { + get + { + return _macAddress; + } + } + + /// + /// IpAddress of connected peer. + /// + public string IpAddress + { + get + { + return _ipAddress; + } + } + + /// + /// InterfaceAddress of connected peer. + /// + public string InterfaceAddress + { + get + { + return _interfaceAddress; + } + } + } + + /// + /// An extended EventArgs class which contains changed Wi-Fi Direct state of local device. + /// + public class StateChangedEventArgs : EventArgs + { + private WiFiDirectState _state; + + internal StateChangedEventArgs(WiFiDirectState state) + { + _state = state; + } + + /// + /// Wi-Fi Direct state. + /// + public WiFiDirectState State + { + get + { + return _state; + } + } + } + + /// + /// An extended EventArgs class which contains changed Wi-Fi Direct discovery state during Wi-Fi Direct scan operation. + /// + public class DiscoveryStateChangedEventArgs : EventArgs + { + private WiFiDirectError _error; + private WiFiDirectDiscoveryState _state; + + internal DiscoveryStateChangedEventArgs(WiFiDirectError error, WiFiDirectDiscoveryState state) + { + _error = error; + _state = state; + } + + /// + /// Wi-Fi Direct result. + /// + public WiFiDirectError Error + { + get + { + return _error; + } + } + + /// + /// Wi-Fi Direct Discovery state. + /// + public WiFiDirectDiscoveryState DiscoveryState + { + get + { + return _state; + } + } + } + + /// + /// An extended EventArgs class which contains found peer information during Wi-Fi Direct scan operation. + /// + public class PeerFoundEventArgs : EventArgs + { + private WiFiDirectError _error; + private WiFiDirectDiscoveryState _state; + private WiFiDirectPeer _peer; + + internal PeerFoundEventArgs(WiFiDirectError error, WiFiDirectDiscoveryState state, WiFiDirectPeer peer) + { + _error = error; + _state = state; + _peer = peer; + } + + /// + /// Wi-Fi Direct result. + /// + public WiFiDirectError Error + { + get + { + return _error; + } + } + + /// + /// Wi-Fi Direct Discovery state. + /// + public WiFiDirectDiscoveryState DiscoveryState + { + get + { + return _state; + } + } + + /// + /// Found peer. + /// + public WiFiDirectPeer Peer + { + get + { + return _peer; + } + } + } + + /// + /// An extended EventArgs class which contains changed device state during activation or deactivation. + /// + public class DeviceStateChangedEventArgs : EventArgs + { + private WiFiDirectError _error; + private WiFiDirectDeviceState _state; + + internal DeviceStateChangedEventArgs(WiFiDirectError error, WiFiDirectDeviceState state) + { + _error = error; + _state = state; + } + + /// + /// Wi-Fi Direct result. + /// + public WiFiDirectError Error + { + get + { + return _error; + } + } + + /// + /// State of the device. + /// + public WiFiDirectDeviceState DeviceState + { + get + { + return _state; + } + } + } + + /// + /// An extended EventArgs class which contains changed service information during service discovery. + /// + public class ServiceStateChangedEventArgs : EventArgs + { + private WiFiDirectError _error; + private WiFiDirectServiceDiscoveryState _state; + private WiFiDirectServiceType _type; + private string _response; + private WiFiDirectPeer _peer; + + internal ServiceStateChangedEventArgs(WiFiDirectError error, WiFiDirectServiceDiscoveryState state, WiFiDirectServiceType type, string response, WiFiDirectPeer peer) + { + _error = error; + _state = state; + _type = type; + _response = response; + _peer = peer; + } + + /// + /// Wi-Fi Direct result. + /// + public WiFiDirectError Error + { + get + { + return _error; + } + } + + /// + /// Service discovery state. + /// + public WiFiDirectServiceDiscoveryState ServiceDiscoveryState + { + get + { + return _state; + } + } + + /// + /// Types of service. + /// + public WiFiDirectServiceType ServiceType + { + get + { + return _type; + } + } + + /// + /// Received response. + /// + public string Response + { + get + { + return _response; + } + } + + /// + /// Peer servicing device. + /// + public WiFiDirectPeer Peer + { + get + { + return _peer; + } + } + } + + /// + /// An extended EventArgs class which contains changed connection state during disconnect all peers or group related operations. + /// + public class ConnectionStatusChangedEventArgs : EventArgs + { + private WiFiDirectError _error; + private WiFiDirectConnectionState _state; + + internal ConnectionStatusChangedEventArgs(WiFiDirectError error, WiFiDirectConnectionState state) + { + _error = error; + _state = state; + } + + /// + /// Wi-Fi Direct result. + /// + public WiFiDirectError Error + { + get + { + return _error; + } + } + + /// + /// Connection state. + /// + public WiFiDirectConnectionState ConnectionState + { + get + { + return _state; + } + } + } +} diff --git a/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect/WiFiDirectManager.cs b/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect/WiFiDirectManager.cs new file mode 100644 index 0000000..139e0c5 --- /dev/null +++ b/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect/WiFiDirectManager.cs @@ -0,0 +1,1237 @@ +/* + * 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; + +namespace Tizen.Network.WiFiDirect +{ + /// + /// A class which is used to manage settings of Wi-Fi Direct.
+ /// This class is used to discover peer devices and manage settings of Wi-Fi Direct. + ///
+ /// http://tizen.org/privilege/wifidirect + public static class WiFiDirectManager + { + /// + /// A property to check whether the device is group owner or not. + /// + /// + /// Wi-Fi Direct must be activated. + /// If it is deactivated, false will be returned. + /// + public static bool IsGroupOwner + { + get + { + if (Globals.IsActivated) + { + return WiFiDirectManagerImpl.Instance.IsGroupOwner; + } + + else + { + return false; + } + } + } + + /// + /// A property to check whether the current group is the autonomous group or not. + /// + /// + /// Wi-Fi Direct must be activated. + /// If it is deactivated, false will be returned. + /// + public static bool IsAutonomousGroup + { + get + { + if (Globals.IsActivated) + { + return WiFiDirectManagerImpl.Instance.IsAutonomousGroup; + } + + else + { + return false; + } + } + } + + /// + /// SSID of local device. + /// + /// + /// If there is any error, null will be returned. + /// + public static string Ssid + { + get + { + if (Globals.IsInitialize) + { + return WiFiDirectManagerImpl.Instance.Ssid; + } + + else + { + return null; + } + } + } + + /// + /// Name of network interface. + /// + /// + /// Wi-Fi Direct must be activated. + /// If it is deactivated, null will be returned. + /// + public static string NetworkInterface + { + get + { + if (Globals.IsActivated) + { + return WiFiDirectManagerImpl.Instance.NetworkInterface; + } + + else + { + return null; + } + } + } + + /// + /// IP address of a local device. + /// + /// + /// Wi-Fi Direct must be activated. + /// If it is deactivated, null will be returned. + /// + public static string IpAddress + { + get + { + if (Globals.IsActivated) + { + return WiFiDirectManagerImpl.Instance.IpAddress; + } + + else + { + return null; + } + } + } + + /// + /// Subnet mask. + /// + /// + /// Wi-Fi Direct must be activated. + /// If it is deactivated, null will be returned. + /// + public static string SubnetMask + { + get + { + if (Globals.IsActivated) + { + return WiFiDirectManagerImpl.Instance.SubnetMask; + } + + else + { + return null; + } + } + } + + /// + /// Gateway address. + /// + /// + /// Wi-Fi Direct must be activated. + /// If it is deactivated, null will be returned. + /// + public static string GatewayAddress + { + get + { + if (Globals.IsActivated) + { + return WiFiDirectManagerImpl.Instance.GatewayAddress; + } + + else + { + return null; + } + } + } + + /// + /// Mac address of a local device. + /// + /// + /// If there is any error, null will be returned. + /// + public static string MacAddress + { + get + { + if (Globals.IsInitialize) + { + return WiFiDirectManagerImpl.Instance.MacAddress; + } + + else + { + return null; + } + } + } + + /// + /// State of Wi-Fi direct service. + /// + public static WiFiDirectState State + { + get + { + return WiFiDirectManagerImpl.Instance.State; + } + } + + /// + /// A property to check whether the device is discoverable or not by P2P discovery. + /// + public static bool IsDiscoverable + { + get + { + if (Globals.IsInitialize) + { + return WiFiDirectManagerImpl.Instance.IsDiscoverable; + } + + else + { + return false; + } + } + } + + /// + /// A property to check whether the local device is listening only. + /// + /// + /// Wi-Fi Direct must be activated. + /// If it is deactivated, false will be returned. + /// + public static bool IsListenOnly + { + get + { + if (Globals.IsActivated) + { + return WiFiDirectManagerImpl.Instance.IsListenOnly; + } + + else + { + return false; + } + } + } + + /// + /// Primary device type of local device. + /// + /// + /// If there is any error, 0 will be returned. + /// + public static WiFiDirectPrimaryDeviceType PrimaryType + { + get + { + if (Globals.IsInitialize) + { + return WiFiDirectManagerImpl.Instance.PrimaryType; + } + + else + { + return default(WiFiDirectPrimaryDeviceType); + } + } + } + + /// + /// Secondary device type of local device. + /// + /// + /// If there is any error, 0 will be returned. + /// + public static WiFiDirectSecondaryDeviceType SecondaryType + { + get + { + if (Globals.IsInitialize) + { + return WiFiDirectManagerImpl.Instance.SecondaryType; + } + + else + { + return default(WiFiDirectSecondaryDeviceType); + } + } + } + + /// + /// Supported WPS (Wi-Fi Protected Setup) types at local device. + /// + /// + /// If there is any error, -1 will be returned. + /// + public static int WpsMode + { + get + { + if (Globals.IsInitialize) + { + return WiFiDirectManagerImpl.Instance.WpsMode; + } + + else + { + return -1; + } + } + } + + /// + /// WPS (Wi-Fi Protected Setup) type. + /// + public static WiFiDirectWpsType Wps + { + get + { + if (Globals.IsInitialize) + { + return WiFiDirectManagerImpl.Instance.WpsType; + } + + else + { + return default(WiFiDirectWpsType); + } + } + } + + /// + /// Channel number on which the P2P Device is operating as the P2P Group. + /// + /// + /// If there is any error, -1 will be returned. + /// + public static int OperatingChannel + { + get + { + if (Globals.IsInitialize) + { + return WiFiDirectManagerImpl.Instance.OperatingChannel; + } + + else + { + return -1; + } + } + } + + /// + /// A property to check whether persistent group is enabled. + /// + /// Thrown while setting this property when the wifidirect is not supported + public static bool PersistentGroupEnabled + { + get + { + if (Globals.IsInitialize) + { + return WiFiDirectManagerImpl.Instance.PersistentGroupEnabled; + } + + else + { + return false; + } + } + + set + { + if (Globals.IsInitialize) + { + WiFiDirectManagerImpl.Instance.PersistentGroupEnabled = value; + } + } + } + + /// + /// Autoconnection mode status. + /// + /// Thrown while setting this property when the wifidirect is not supported + public static bool AutoConnect + { + get + { + if (Globals.IsInitialize) + { + return WiFiDirectManagerImpl.Instance.AutoConnect; + } + + else + { + return false; + } + } + + set + { + if (Globals.IsInitialize) + { + WiFiDirectManagerImpl.Instance.AutoConnect = value; + } + } + } + + /// + /// WPS PIN number. + /// + /// + /// Wi-Fi Direct must be activated. + /// If it is deactivated, null will be returned during get and Not permitted exception message will be returned during set. + /// + /// Thrown while setting this property when the wifidirect is not supported + public static string WpsPin + { + get + { + if (Globals.IsActivated) + { + return WiFiDirectManagerImpl.Instance.WpsPin; + } + + else + { + return null; + } + } + + set + { + if (Globals.IsActivated) + { + WiFiDirectManagerImpl.Instance.WpsPin = value; + } + + else + { + Log.Error(Globals.LogTag, "Wifi-direct is not activated"); + WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); + } + } + } + + /// + /// Name of local device. + /// + /// Thrown while setting this property when the wifidirect is not supported + public static string Name + { + get + { + if (Globals.IsInitialize) + { + return WiFiDirectManagerImpl.Instance.Name; + } + + else + { + return null; + } + } + + set + { + if (Globals.IsInitialize) + { + WiFiDirectManagerImpl.Instance.Name = value; + } + } + } + + /// + /// Requested WPS (Wi-Fi Protected Setup) type. + /// + /// Thrown while setting this property when the wifidirect is not supported + public static WiFiDirectWpsType RequestedWps + { + get + { + if (Globals.IsInitialize) + { + return WiFiDirectManagerImpl.Instance.RequestedWps; + } + + else + { + return default(WiFiDirectWpsType); + } + } + + set + { + if (Globals.IsInitialize) + { + WiFiDirectManagerImpl.Instance.RequestedWps = value; + } + } + } + + /// + /// Intent of the group owner. + /// + /// Thrown while setting this property when the wifidirect is not supported + public static int GroupOwnerIntent + { + get + { + if (Globals.IsInitialize) + { + return WiFiDirectManagerImpl.Instance.GroupOwnerIntent; + } + + else + { + return -1; + } + } + + set + { + if (Globals.IsInitialize) + { + WiFiDirectManagerImpl.Instance.GroupOwnerIntent = value; + } + } + } + + /// + /// Max number of clients. + /// + /// Thrown while setting this property when the wifidirect is not supported + public static int MaxClients + { + get + { + if (Globals.IsInitialize) + { + return WiFiDirectManagerImpl.Instance.MaxClients; + } + + else + { + return -1; + } + } + + set + { + if (Globals.IsInitialize) + { + WiFiDirectManagerImpl.Instance.MaxClients = value; + } + } + } + + /// + /// Wi-Fi Protected Access (WPA) password. + /// It is used during Wi-Fi Direct Group creation. + /// + /// + /// Wi-Fi Direct must be activated. + /// If it is deactivated, null will be returned during get and Not permitted exception message will be returned during set. + /// + /// Thrown while setting this property when the wifidirect is not supported + public static string Passphrase + { + get + { + if (Globals.IsActivated) + { + return WiFiDirectManagerImpl.Instance.Passphrase; + } + + else + { + return null; + } + } + + set + { + if (Globals.IsActivated) + { + WiFiDirectManagerImpl.Instance.Passphrase = value; + } + + else + { + Log.Error(Globals.LogTag, "Wi-Fi direct is not activated"); + WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); + } + } + } + + /// + /// Connection session timer value in second. + /// + /// + /// Wi-Fi Direct must be activated. + /// If it is deactivated, -1 will be returned during get and Not permitted exception message will be returned during set. + /// + /// Thrown while setting this property when the wifidirect is not supported + public static int SessionTimer + { + get + { + if (Globals.IsActivated) + { + return WiFiDirectManagerImpl.Instance.SessionTimer; + } + + else + { + return -1; + } + } + + set + { + if (Globals.IsActivated) + { + WiFiDirectManagerImpl.Instance.SessionTimer = value; + } + + else + { + Log.Error(Globals.LogTag, "Wi-Fi direct is not activated"); + WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); + } + } + } + + /// + /// (event) StateChanged is raised when Wi-Fi Direct state is changed. + /// + public static event EventHandler StateChanged + { + add + { + WiFiDirectManagerImpl.Instance.StateChanged += value; + } + + remove + { + WiFiDirectManagerImpl.Instance.StateChanged -= value; + } + } + + /// + /// (event) DiscoveryStateChanged is raised when Wi-Fi Direct discovery state is changed. + /// + public static event EventHandler DiscoveryStateChanged + { + add + { + if (Globals.IsInitialize) + { + WiFiDirectManagerImpl.Instance.DiscoveryStateChanged += value; + } + } + + remove + { + if (Globals.IsInitialize) + { + WiFiDirectManagerImpl.Instance.DiscoveryStateChanged -= value; + } + } + } + + /// + /// (event) DeviceStateChanged is raised when device state is changed. + /// + public static event EventHandler DeviceStateChanged + { + add + { + if (Globals.IsInitialize) + { + WiFiDirectManagerImpl.Instance.DeviceStateChanged += value; + } + } + + remove + { + if (Globals.IsInitialize) + { + WiFiDirectManagerImpl.Instance.DeviceStateChanged -= value; + } + } + } + + /// + /// (event) PeerFound is raised when peer is found. + /// + public static event EventHandler PeerFound + { + add + { + if (Globals.IsInitialize) + { + WiFiDirectManagerImpl.Instance.PeerFound += value; + } + } + + remove + { + if (Globals.IsInitialize) + { + WiFiDirectManagerImpl.Instance.PeerFound -= value; + } + } + } + + /// + /// (event) ConnectionStatusChanged is raised when status of connection is changed. + /// + public static event EventHandler ConnectionStatusChanged + { + add + { + if (Globals.IsInitialize) + { + WiFiDirectManagerImpl.Instance.ConnectionStatusChanged += value; + } + } + + remove + { + if (Globals.IsInitialize) + { + WiFiDirectManagerImpl.Instance.ConnectionStatusChanged -= value; + } + } + } + + /// + /// Activates the Wi-Fi Direct service. + /// + /// + /// If this succeeds, DeviceStateChanged event will be invoked. + /// + /// Thrown when the wifidirect is not supported + public static void Activate() + { + if (Globals.IsInitialize) + { + WiFiDirectManagerImpl.Instance.Activate(); + } + + else + { + Log.Error(Globals.LogTag, "Wi-Fi direct is not initialized"); + WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotInitialized); + } + } + + /// + /// Deactivates the Wi-Fi Direct service. + /// + /// + /// Wi-Fi Direct must be activated. + /// If this succeeds, DeviceStateChanged event will be invoked. + /// + /// Thrown when the wifidirect is not supported + public static void Deactivate() + { + if (Globals.IsActivated) + { + WiFiDirectManagerImpl.Instance.Deactivate(); + } + + else + { + Log.Error(Globals.LogTag, "Wi-Fi direct is not activated"); + WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); + } + } + + /// + /// Starts discovery to find all P2P capable devices. + /// + /// + /// Wi-Fi Direct must be activated. + /// If this succeeds, DiscoveryStateChanged and PeerFound event will be invoked. + /// + /// Thrown when the wifidirect is not supported + /// Listen status.If False, then cycle between Scan and Listen.If True, then skip the initial 802.11 Scan and enter Listen state. + /// Duration of discovery period, in seconds. + /// Discovery channel.It is optional, default enum value FullScan is assigned. + public static void StartDiscovery(bool listenOnly, int duration, WiFiDirectDiscoveryChannel channel = WiFiDirectDiscoveryChannel.FullScan) + { + if (Globals.IsActivated) + { + WiFiDirectManagerImpl.Instance.StartDiscovery(listenOnly, duration, channel); + } + + else + { + Log.Error(Globals.LogTag, "Wi-Fi direct is not activated"); + WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); + } + } + + /// + /// Cancels discovery process. + /// + /// + /// Discovery must be started by StartDiscovery. + /// If this succeeds, DiscoveryStateChanged and PeerFound event will be invoked. + /// + /// Thrown when the wifidirect is not supported + public static void CancelDiscovery() + { + if (WiFiDirectManager.State == WiFiDirectState.Discovering) + { + WiFiDirectManagerImpl.Instance.CancelDiscovery(); + } + + else + { + Log.Error(Globals.LogTag, "Wi-Fi direct discovery is not started"); + WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); + } + } + + /// + /// Gets the information of discovered peers. + /// + /// + /// Wi-Fi Direct must be activated. + /// + /// Thrown when the wifidirect is not supported + /// List of discovered peer objects. + public static IEnumerable GetDiscoveredPeers() + { + if (Globals.IsActivated) + { + return WiFiDirectManagerImpl.Instance.GetDiscoveredPeers(); + } + + else + { + return null; + } + } + + /// + /// Gets the information of connected peers. + /// + /// + /// Wi-Fi Direct must be activated. + /// + /// Thrown when the wifidirect is not supported + /// List of connected peer objects. + public static IEnumerable GetConnectedPeers() + { + if (Globals.IsActivated) + { + return WiFiDirectManagerImpl.Instance.GetConnectedPeers(); + } + + else + { + return null; + } + } + + /// + /// Disconnects all connected links to peers. + /// + /// + /// Wi-Fi Direct must be activated. + /// If this succeeds, ConnectionStatusChanged event will be invoked. + /// + /// Thrown when the wifidirect is not supported + public static void DisconnectAll() + { + if (Globals.IsActivated) + { + WiFiDirectManagerImpl.Instance.DisconnectAll(); + } + + else + { + Log.Error(Globals.LogTag, "Wifi-direct is not activated"); + WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); + } + } + + /// + /// Creates a Wi-Fi Direct group and sets up device as the group owner. + /// + /// + /// Wi-Fi Direct must be activated. + /// If this succeeds, ConnectionStatusChanged event will be invoked with GroupCreated. + /// + /// Thrown when the wifidirect is not supported + public static void CreateGroup() + { + if (Globals.IsActivated) + { + WiFiDirectManagerImpl.Instance.CreateGroup(); + } + + else + { + Log.Error(Globals.LogTag, "Wifi-direct is not activated"); + WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); + } + } + + /// + /// Destroys the Wi-Fi Direct group owned by a local device.If creating a group is in progress, this API cancels that process. + /// + /// + /// Wi-Fi Direct must be activated. + /// If this succeeds, ConnectionStatusChanged event will be invoked with GroupDestroyed. + /// + /// Thrown when the wifidirect is not supported + public static void DestroyGroup() + { + if (Globals.IsActivated) + { + WiFiDirectManagerImpl.Instance.DestroyGroup(); + } + + else + { + Log.Error(Globals.LogTag, "Wifi-direct is not activated"); + WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); + } + } + + /// + /// Set the WPS config PBC as preferred method for connection. + /// + /// Thrown when the wifidirect is not supported + public static void ActivatePushButton() + { + if (Globals.IsActivated) + { + WiFiDirectManagerImpl.Instance.ActivatePushButton(); + } + + else + { + Log.Error(Globals.LogTag, "Wifi-direct is not activated"); + WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); + } + } + + /// + /// Gets the supported WPS types. + /// + /// Thrown when the wifidirect is not supported + /// The list of supported wps types. + public static IEnumerable GetSupportedWpsTypes() + { + if (Globals.IsInitialize) + { + return WiFiDirectManagerImpl.Instance.GetSupportedWpsTypes(); + } + + else + { + return null; + } + } + + /// + /// Gets the persistent groups. + /// + /// Thrown when the wifidirect is not supported + /// List of the persistent group objects. + public static IEnumerable GetPersistentGroups() + { + if (Globals.IsInitialize) + { + return WiFiDirectManagerImpl.Instance.GetPersistentGroups(); + } + + else + { + return null; + } + } + + /// + /// Removes a persistent group. + /// + /// Thrown when the wifidirect is not supported + /// Persistent group owner. + public static void RemovePersistentGroup(WiFiDirectPersistentGroup group) + { + if (Globals.IsInitialize) + { + WiFiDirectManagerImpl.Instance.RemovePersistentGroup(group); + } + + else + { + Log.Error(Globals.LogTag, "Wifi-direct is not activated"); + WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotInitialized); + } + } + + /// + /// Initializes or Deintializes the WiFi-Direct Display(MIRACAST) service. + /// + /// + /// Wi-Fi Direct must be activated. + /// + /// + /// Thrown during one of the following cases : + /// 1. When the wifidirect is not supported + /// 2. When the wifidirect display feature is not supported + /// + /// Enables/Disables service. + public static void InitMiracast(bool enable) + { + if (Globals.IsActivated) + { + WiFiDirectManagerImpl.Instance.InitMiracast(enable); + } + + else + { + Log.Error(Globals.LogTag, "Wifi-direct is not activated"); + WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); + } + } + + /// + /// Enables Wi-Fi Display functionality. + /// + /// + /// Wi-Fi Direct must be activated. + /// + /// + /// Thrown during one of the following cases : + /// 1. When the wifidirect is not supported + /// 2. When the wifidirect display feature is not supported + /// + public static void InitDisplay() + { + if (Globals.IsActivated) + { + WiFiDirectManagerImpl.Instance.InitDisplay(); + } + + else + { + Log.Error(Globals.LogTag, "Wifi-direct is not activated"); + WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); + } + } + + /// + /// Disable Wi-Fi Display(WFD) functionality and disable the support of WFD Information Element(IE). + /// + /// + /// Wi-Fi Direct must be activated and WFD must be enabled. + /// + /// + /// Thrown during one of the following cases : + /// 1. When the wifidirect is not supported + /// 2. When the wifidirect display feature is not supported + /// + public static void DeinitDisplay() + { + if (Globals.IsActivated && Globals.s_isDisplay) + { + WiFiDirectManagerImpl.Instance.DeinitDisplay(); + } + + else + { + Log.Error(Globals.LogTag, "Wifi-direct is not activated and/or Wi-Fi display is not enabled"); + WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); + } + } + + /// + /// Sets the Wi-Fi Display parameters for the WFD IE of local device. + /// + /// + /// Wi-Fi Direct must be activated and WFD must be enabled. + /// + /// + /// Thrown during one of the following cases : + /// 1. When the wifidirect is not supported + /// 2. When the wifidirect display feature is not supported + /// + /// WFD Device Type: define the Role of WFD device like source or sink. + /// Specifies Session Management Control Port number. It should be 2 bytes(0~65535). + /// CP support bit: (1 = enable the hdcp support, 0 = disable the hdcp support). + public static void SetDisplay(WiFiDirectDisplayType type, int port, int hdcp) + { + if (Globals.IsActivated && Globals.s_isDisplay) + { + WiFiDirectManagerImpl.Instance.SetDisplay(type, port, hdcp); + } + + else + { + Log.Error(Globals.LogTag, "Wifi-direct is not activated and/or Wi-Fi display is not enabled"); + WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); + } + } + + /// + /// Sets the Wi-Fi Display session availability. + /// + /// + /// Wi-Fi Direct must be activated and WFD must be enabled. + /// + /// + /// Thrown during one of the following cases : + /// 1. When the wifidirect is not supported + /// 2. When the wifidirect display feature is not supported + /// + /// Wi-Fi Display session availability. + public static void SetDisplayAvailability(bool availability) + { + if (Globals.IsActivated && Globals.s_isDisplay) + { + WiFiDirectManagerImpl.Instance.SetDisplayAvailability(availability); + } + + else + { + Log.Error(Globals.LogTag, "Wifi-direct is not activated and/or Wi-Fi display is not enabled"); + WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); + } + } + + /// + /// Sets the automatic group removal feature when all peers are disconnected. + /// + /// + /// Wi-Fi Direct must be activated. + /// ConnectionStatusChanged event will be invoked with GroupDestroyed when this feature is enabled and there's no connected group client and if device is group owner. + /// + /// Thrown when the wifidirect is not supported + /// Enables/Disables group removal feature. + public static void SetAutoGroupRemove(bool enable) + { + if (Globals.IsActivated) + { + WiFiDirectManagerImpl.Instance.SetAutoGroupRemove(enable); + } + + else + { + Log.Error(Globals.LogTag, "Wifi-direct is not activated"); + WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); + } + } + + /// + /// Registers the service. + /// + /// + /// Wi-Fi Direct must be activated. + /// If there is any error while registering service, 0 will be returned. + /// + /// + /// Thrown during one of the following cases : + /// 1. When the wifidirect is not supported + /// 2. When the wifidirect service discovery is not supported + /// + /// The service Id of service getting registered. + /// Type of Wi-Fi Direct Service. + /// Service specific information. + /// Service information. + public static uint RegisterService(WiFiDirectServiceType type, string info, string serviceInfo) + { + if (Globals.IsActivated) + { + return WiFiDirectManagerImpl.Instance.RegisterService(type, info, serviceInfo); + } + + else + { + return 0; + } + } + + /// + /// Deregisters for a service used for WiFi Direct Service Discovery. + /// + /// + /// Wi-Fi Direct must be activated. + /// + /// + /// Thrown during one of the following cases : + /// 1. When the wifidirect is not supported + /// 2. When the wifidirect service discovery is not supported + /// + /// Service ID for which service has to be deregistered. + public static void DeregisterService(uint serviceId) + { + if (Globals.IsActivated) + { + WiFiDirectManagerImpl.Instance.DeregisterService(serviceId); + } + + else + { + Log.Error(Globals.LogTag, "Wifi-direct is not activated"); + WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); + } + } + } +} diff --git a/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect/WiFiDirectManagerImpl.cs b/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect/WiFiDirectManagerImpl.cs new file mode 100644 index 0000000..f376264 --- /dev/null +++ b/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect/WiFiDirectManagerImpl.cs @@ -0,0 +1,1241 @@ +/* + * 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.Runtime.InteropServices; +using System.Threading; + +namespace Tizen.Network.WiFiDirect +{ + internal class WiFiDirectThreadLocal + { + private int _threadId; + internal WiFiDirectThreadLocal(int id) + { + _threadId = id; + } + + public int ThreadId + { + get + { + return _threadId; + } + } + + ~WiFiDirectThreadLocal() + { + Log.Info(Globals.LogTag, "Deinitializing Wi-Fi direct"); + int ret = Interop.WiFiDirect.Deinitialize(); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to deinitialize Wi-Fi direct, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + + else + { + Globals.s_isInitialize = false; + } + } + } + + internal static class Globals + { + internal const string LogTag = "Tizen.Network.WiFiDirect"; + internal static bool s_isInitialize = false; + internal static bool s_isDisplay = false; + private static ThreadLocal s_threadName = new ThreadLocal(() => + { + Log.Info(Globals.LogTag, "In threadlocal delegate"); + return new WiFiDirectThreadLocal(Thread.CurrentThread.ManagedThreadId); + }); + internal static bool IsActivated + { + get + { + WiFiDirectState _state = WiFiDirectManager.State; + if (IsInitialize) + { + if (_state == WiFiDirectState.Deactivated || _state == WiFiDirectState.Deactivating) + { + return false; + } + + else + { + return true; + } + } + + else + { + return false; + } + } + } + + private static bool IsUniqueThread() + { + if (s_threadName.IsValueCreated) + { + Log.Info(Globals.LogTag, "This thread is old"); + return false; + } + + else + { + WiFiDirectThreadLocal obj = s_threadName.Value; + Log.Info(Globals.LogTag, "This thread is new , Id = " + obj.ThreadId); + return true; + } + } + + internal static bool IsInitialize + { + get + { + if(Globals.IsUniqueThread() || !Globals.s_isInitialize) + { + WiFiDirectManagerImpl.Instance.Initialize(); + } + + return (Globals.s_isInitialize); + } + } + } + + /// + /// Implementation of Wi-Fi Direct Apis + /// + internal partial class WiFiDirectManagerImpl : IDisposable + { + private event EventHandler _stateChanged; + private event EventHandler _discoveryStateChanged; + private event EventHandler _peerFound; + private event EventHandler _deviceStateChanged; + private event EventHandler _connectionStatusChanged; + + private Interop.WiFiDirect.StateChangedCallback _stateChangedCallback; + private Interop.WiFiDirect.DiscoveryStateChangedCallback _discoveryStateChangedCallback; + private Interop.WiFiDirect.PeerFoundCallback _peerFoundCallback; + private Interop.WiFiDirect.DeviceStateChangedCallback _deviceStateChangedCallback; + private Interop.WiFiDirect.ConnectionStateChangedCallback _connectionChangedCallback; + + internal event EventHandler StateChanged + { + add + { + if (_stateChanged == null) + { + RegisterStateChangedEvent(); + } + + _stateChanged += value; + } + + remove + { + _stateChanged -= value; + if (_stateChanged == null) + { + UnregisterStateChangedEvent(); + } + } + } + + internal event EventHandler DiscoveryStateChanged + { + add + { + if (_discoveryStateChanged == null) + { + RegisterDiscoveryStateChangedEvent(); + } + + _discoveryStateChanged += value; + } + + remove + { + _discoveryStateChanged -= value; + if (_discoveryStateChanged == null) + { + UnregisterDiscoveryStateChangedEvent(); + } + } + } + + internal event EventHandler PeerFound + { + add + { + if (_peerFound == null) + { + RegisterPeerFoundEvent(); + } + + _peerFound += value; + } + + remove + { + _peerFound -= value; + if (_peerFound == null) + { + UnregisterPeerFoundEvent(); + } + } + } + + internal event EventHandler DeviceStateChanged + { + add + { + if (_deviceStateChanged == null) + { + RegisterDeviceStateChangedEvent(); + } + + _deviceStateChanged += value; + } + + remove + { + _deviceStateChanged -= value; + if (_deviceStateChanged == null) + { + UnregisterDeviceStateChangedEvent(); + } + } + } + + internal event EventHandler ConnectionStatusChanged + { + add + { + if (_connectionStatusChanged == null) + { + RegisterConnectionStatusChangedEvent(); + } + + _connectionStatusChanged += value; + } + + remove + { + _connectionStatusChanged -= value; + if (_connectionStatusChanged == null) + { + UnregisterConnectionStatusChangedEvent(); + } + } + } + + private bool _disposed = false; + private static WiFiDirectManagerImpl _instance; + + private void RegisterStateChangedEvent() + { + _stateChangedCallback = (WiFiDirectState stateInfo, IntPtr userData) => + { + if (_stateChanged != null) + { + WiFiDirectState state = stateInfo; + _stateChanged(null, new StateChangedEventArgs(state)); + } + }; + int ret = Interop.WiFiDirect.SetStateChangedCallback(_stateChangedCallback, IntPtr.Zero); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to set Wi-Fi Direct state changed callback, Error - " + (WiFiDirectError)ret); + } + } + + private void UnregisterStateChangedEvent() + { + int ret = Interop.WiFiDirect.UnsetStateChangedCallback(); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to unset Wi-Fi Direct state changed callback, Error - " + (WiFiDirectError)ret); + } + } + + private void RegisterDiscoveryStateChangedEvent() + { + _discoveryStateChangedCallback = (int result, WiFiDirectDiscoveryState stateInfo, IntPtr userData) => + { + if (_discoveryStateChanged != null) + { + WiFiDirectError error = (WiFiDirectError)result; + WiFiDirectDiscoveryState state = stateInfo; + _discoveryStateChanged(null, new DiscoveryStateChangedEventArgs(error, state)); + } + }; + int ret = Interop.WiFiDirect.SetDiscoveryStateChangedCallback(_discoveryStateChangedCallback, IntPtr.Zero); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to set Wi-Fi Direct discovery state changed callback, Error - " + (WiFiDirectError)ret); + } + } + + private void UnregisterDiscoveryStateChangedEvent() + { + int ret = Interop.WiFiDirect.UnsetDiscoveryStateChangedCallback(); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to unset Wi-Fi Direct discovery state changed callback, Error - " + (WiFiDirectError)ret); + } + } + + private void RegisterPeerFoundEvent() + { + _peerFoundCallback = (int result, WiFiDirectDiscoveryState stateInfo, string address, IntPtr userData) => + { + if (_peerFound != null) + { + WiFiDirectError error = (WiFiDirectError)result; + WiFiDirectDiscoveryState state = stateInfo; + IntPtr peer; + Interop.WiFiDirect.GetDiscoveredPeerInfo(address, out peer); + DiscoveredPeerStruct peerStruct = (DiscoveredPeerStruct)Marshal.PtrToStructure(peer, typeof(DiscoveredPeerStruct)); + _peerFound(null, new PeerFoundEventArgs(error, state, WiFiDirectUtils.ConvertStructToDiscoveredPeer(peerStruct))); + } + }; + int ret = Interop.WiFiDirect.SetPeerFoundCallback(_peerFoundCallback, IntPtr.Zero); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to set Wi-Fi Direct discovery state changed callback, Error - " + (WiFiDirectError)ret); + } + } + + private void UnregisterPeerFoundEvent() + { + int ret = Interop.WiFiDirect.UnsetPeerFoundCallback(); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to unset Wi-Fi Direct discovery state changed callback, Error - " + (WiFiDirectError)ret); + } + } + + private void RegisterDeviceStateChangedEvent() + { + _deviceStateChangedCallback = (int result, WiFiDirectDeviceState stateInfo, IntPtr userData) => + { + if (_deviceStateChanged != null) + { + WiFiDirectError error = (WiFiDirectError)result; + WiFiDirectDeviceState state = stateInfo; + _deviceStateChanged(null, new DeviceStateChangedEventArgs(error, state)); + } + }; + int ret = Interop.WiFiDirect.SetDeviceStateChangedCallback(_deviceStateChangedCallback, IntPtr.Zero); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to set device state changed callback, Error - " + (WiFiDirectError)ret); + } + } + + private void UnregisterDeviceStateChangedEvent() + { + int ret = Interop.WiFiDirect.UnsetDeviceStateChangedCallback(); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to unset device state changed callback, Error - " + (WiFiDirectError)ret); + } + } + + private void RegisterConnectionStatusChangedEvent() + { + _connectionChangedCallback = (int result, WiFiDirectConnectionState stateInfo, string address, IntPtr userData) => + { + if (_connectionStatusChanged != null) + { + WiFiDirectError error = (WiFiDirectError)result; + WiFiDirectConnectionState state = stateInfo; + + _connectionStatusChanged(null, new ConnectionStatusChangedEventArgs(error, state)); + } + }; + int ret = Interop.WiFiDirect.SetConnectionChangedCallback(_connectionChangedCallback, IntPtr.Zero); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to set connection status changed callback, Error - " + (WiFiDirectError)ret); + } + } + + private void UnregisterConnectionStatusChangedEvent() + { + int ret = Interop.WiFiDirect.UnsetConnectionChangedCallback(); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to unset connection status changed callback, Error - " + (WiFiDirectError)ret); + } + } + + internal bool IsGroupOwner + { + get + { + bool isGroupOwner; + int ret = Interop.WiFiDirect.IsGroupOwner(out isGroupOwner); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to get whether this device is the group owner or not, Error - " + (WiFiDirectError)ret); + } + + return isGroupOwner; + } + } + + internal bool IsAutonomousGroup + { + get + { + bool isAutonomousGroup; + int ret = Interop.WiFiDirect.IsAutonomousGroup(out isAutonomousGroup); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to check whether the current group is autonomous or not, Error - " + (WiFiDirectError)ret); + } + + return isAutonomousGroup; + } + } + + internal string Ssid + { + get + { + string ssid; + int ret = Interop.WiFiDirect.GetSsid(out ssid); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to get SSID of local device, Error - " + (WiFiDirectError)ret); + return null; + } + + return ssid; + } + } + + internal string NetworkInterface + { + get + { + string networkInterface; + int ret = Interop.WiFiDirect.GetInterfaceName(out networkInterface); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to get name of network interface, Error - " + (WiFiDirectError)ret); + return ""; + } + + return networkInterface; + } + } + + internal string IpAddress + { + get + { + string ipAddress; + int ret = Interop.WiFiDirect.GetIpAddress(out ipAddress); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to get IP address of local device, Error - " + (WiFiDirectError)ret); + return ""; + } + + return ipAddress; + } + } + + internal string SubnetMask + { + get + { + string subnetMask; + int ret = Interop.WiFiDirect.GetSubnetMask(out subnetMask); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to get subnet mask, Error - " + (WiFiDirectError)ret); + return ""; + } + + return subnetMask; + } + } + + internal string GatewayAddress + { + get + { + string gatewayAddress; + int ret = Interop.WiFiDirect.GetGatewayAddress(out gatewayAddress); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to get gateway address, Error - " + (WiFiDirectError)ret); + return ""; + } + + return gatewayAddress; + } + } + + internal string MacAddress + { + get + { + string macAddress; + int ret = Interop.WiFiDirect.GetMacAddress(out macAddress); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to get mac address, Error - " + (WiFiDirectError)ret); + return null; + } + + return macAddress; + } + } + + internal WiFiDirectState State + { + get + { + WiFiDirectState state; + int ret = Interop.WiFiDirect.GetState(out state); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to get state of Wi-Fi direct service, Error - " + (WiFiDirectError)ret); + } + + return state; + } + } + + internal bool IsDiscoverable + { + get + { + bool isDiscoverable; + int ret = Interop.WiFiDirect.IsDiscoverable(out isDiscoverable); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to check whether the device is discoverable, Error - " + (WiFiDirectError)ret); + } + + return isDiscoverable; + } + } + + internal bool IsListenOnly + { + get + { + bool isListenOnly; + int ret = Interop.WiFiDirect.IsListeningOnly(out isListenOnly); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to check whether the local device is listening only, Error - " + (WiFiDirectError)ret); + } + + return isListenOnly; + } + } + + internal WiFiDirectPrimaryDeviceType PrimaryType + { + get + { + WiFiDirectPrimaryDeviceType primaryType; + int ret = Interop.WiFiDirect.GetPrimaryType(out primaryType); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to get the primary device type of local device, Error - " + (WiFiDirectError)ret); + } + + return primaryType; + } + } + + internal WiFiDirectSecondaryDeviceType SecondaryType + { + get + { + WiFiDirectSecondaryDeviceType secondaryType; + int ret = Interop.WiFiDirect.GetSecondaryType(out secondaryType); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to get the secondary device type of local device, Error - " + (WiFiDirectError)ret); + } + + return secondaryType; + } + } + + internal int WpsMode + { + get + { + int mode; + int ret = Interop.WiFiDirect.GetWpsMode(out mode); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to get supproted wps modes at local device, Error - " + (WiFiDirectError)ret); + return -1; + } + + return mode; + } + } + + internal WiFiDirectWpsType WpsType + { + get + { + WiFiDirectWpsType wpsType; + int ret = Interop.WiFiDirect.GetLocalWpsType(out wpsType); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to get the WPS type, Error - " + (WiFiDirectError)ret); + } + + return wpsType; + } + } + + internal int OperatingChannel + { + get + { + int channel; + int ret = Interop.WiFiDirect.GetChannel(out channel); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to get operating channel, Error - " + (WiFiDirectError)ret); + return -1; + } + + return channel; + } + } + + internal bool PersistentGroupEnabled + { + get + { + bool isEnabled; + int ret = Interop.WiFiDirect.GetPersistentGroupState(out isEnabled); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to check persistent group state, Error - " + (WiFiDirectError)ret); + } + + return isEnabled; + } + + set + { + int ret = Interop.WiFiDirect.SetPersistentGroupState(value); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to set the persistent group state, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + } + } + + internal bool AutoConnect + { + get + { + bool isAutoConnect; + int ret = Interop.WiFiDirect.GetAutoConnectionMode(out isAutoConnect); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to get autoconnection mode status, Error - " + (WiFiDirectError)ret); + } + + return isAutoConnect; + } + + set + { + int ret = Interop.WiFiDirect.SetAutoConnectionMode(value); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to set the autoconnection mode, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + } + } + + internal string WpsPin + { + get + { + string pin; + int ret = Interop.WiFiDirect.GetWpsPin(out pin); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to get WPS pin, Error - " + (WiFiDirectError)ret); + } + + return pin; + } + + set + { + int ret = Interop.WiFiDirect.SetWpsPin(value.ToString()); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to set or update WPS pin, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + } + } + + internal string Name + { + get + { + string name; + int ret = Interop.WiFiDirect.GetName(out name); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to get name of local device, Error - " + (WiFiDirectError)ret); + return null; + } + + return name; + } + + set + { + int ret = Interop.WiFiDirect.SetName(value.ToString()); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to set name of local device, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + } + } + + internal WiFiDirectWpsType RequestedWps + { + get + { + WiFiDirectWpsType wpsType; + int ret = Interop.WiFiDirect.GetReqWpsType(out wpsType); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to get the requested WPS type, Error - " + (WiFiDirectError)ret); + } + + return wpsType; + } + + set + { + int ret = Interop.WiFiDirect.SetReqWpsType(value); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to set the requested WPS type, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + } + } + + internal int GroupOwnerIntent + { + get + { + int intent; + int ret = Interop.WiFiDirect.GetIntent(out intent); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to get the intent of the group owner, Error - " + (WiFiDirectError)ret); + } + + return intent; + } + + set + { + int ret = Interop.WiFiDirect.SetIntent(value); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to set the intent of the group owner, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + } + } + + internal int MaxClients + { + get + { + int maxClients; + int ret = Interop.WiFiDirect.GetMaxClients(out maxClients); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to get the max number of clients, Error - " + (WiFiDirectError)ret); + } + + return maxClients; + } + + set + { + int ret = Interop.WiFiDirect.SetMaxClients(value); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to set the max number of clients, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + } + } + + internal string Passphrase + { + get + { + string passphrase; + int ret = Interop.WiFiDirect.GetPassPhrase(out passphrase); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to get Wi-Fi Protected Access password, Error - " + (WiFiDirectError)ret); + return ""; + } + + return passphrase; + } + + set + { + int ret = Interop.WiFiDirect.SetPassPhrase(value.ToString()); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to set or update Wi-Fi Protected Access password, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + } + } + + internal int SessionTimer + { + get + { + int sessionTimer; + int ret = Interop.WiFiDirect.GetSessionTimer(out sessionTimer); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to get the timer used to expire the connection session, Error - " + (WiFiDirectError)ret); + } + + return sessionTimer; + } + + set + { + int ret = Interop.WiFiDirect.SetSessionTimer(value); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to set the timer used to expire the connection session, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + } + } + + internal void Activate() + { + int ret = Interop.WiFiDirect.Activate(); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to activate Wi-Fi direct service, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + } + + internal void Deactivate() + { + int ret = Interop.WiFiDirect.Deactivate(); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to deactivate Wi-Fi direct service, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + } + + internal void StartDiscovery(bool listenOnly, int duration, WiFiDirectDiscoveryChannel channel = WiFiDirectDiscoveryChannel.FullScan) + { + int ret = Interop.WiFiDirect.StartDiscoveryInChannel(listenOnly, duration, channel); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to start discovery, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + } + + internal void CancelDiscovery() + { + int ret = Interop.WiFiDirect.StopDiscovery(); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to cancel discovery, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + } + + internal IEnumerable GetDiscoveredPeers() + { + List discoveredPeerList = new List(); + Interop.WiFiDirect.DiscoveredPeerCallback callback = (ref DiscoveredPeerStruct peer, IntPtr userData) => + { + if (!peer.Equals(null)) + { + discoveredPeerList.Add(WiFiDirectUtils.ConvertStructToDiscoveredPeer(peer)); + } + + return true; + }; + int ret = Interop.WiFiDirect.GetDiscoveredPeers(callback, IntPtr.Zero); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to get information of discovered peers, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + + return discoveredPeerList; + } + + internal IEnumerable GetConnectedPeers() + { + List connectedPeerList = new List(); + Interop.WiFiDirect.ConnectedPeerCallback callback = (ref ConnectedPeerStruct peer, IntPtr userData) => + { + if (!peer.Equals(null)) + { + connectedPeerList.Add(WiFiDirectUtils.ConvertStructToConnectedPeer(peer)); + } + + return true; + }; + int ret = Interop.WiFiDirect.GetConnectedPeers(callback, IntPtr.Zero); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to get information of connected peers, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + + return connectedPeerList; + } + + internal void DisconnectAll() + { + int ret = Interop.WiFiDirect.DisconnectAll(); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to disconnect all connected links, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + } + + internal void CreateGroup() + { + int ret = Interop.WiFiDirect.CreateGroup(); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to create a WiFi-Direct group, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + } + + internal void DestroyGroup() + { + int ret = Interop.WiFiDirect.DestroyGroup(); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to destroy the WiFi-Direct group, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + } + + internal void ActivatePushButton() + { + int ret = Interop.WiFiDirect.ActivatePushButton(); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to set the Wps config PBC, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + } + + internal IEnumerable GetSupportedWpsTypes() + { + List wpsList = new List(); + Interop.WiFiDirect.WpsTypeCallback callback = (WiFiDirectWpsType type, IntPtr userData) => + { + if (!type.Equals(null)) + { + wpsList.Add(type); + } + + return true; + }; + int ret = Interop.WiFiDirect.GetWpsTypes(callback, IntPtr.Zero); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to get the supported WPS types, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + + return wpsList; + } + + internal IEnumerable GetPersistentGroups() + { + List persistentGroupList = new List(); + Interop.WiFiDirect.PersistentGroupCallback callback = (string address, string ssid, IntPtr userData) => + { + if (address != null && ssid != null) + { + persistentGroupList.Add(new WiFiDirectPersistentGroup(address, ssid)); + } + + return true; + }; + int ret = Interop.WiFiDirect.GetPersistentGroups(callback, IntPtr.Zero); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to get the persistent groups, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + + return persistentGroupList; + } + + internal void RemovePersistentGroup(WiFiDirectPersistentGroup group) + { + int ret = Interop.WiFiDirect.RemovePersistentGroup(group.MacAddress, group.Ssid); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to remove a persistent group, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + } + + internal void InitMiracast(bool enable) + { + int ret = Interop.WiFiDirect.InitMiracast(enable); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to set the WiFi-Direct Display(MIRACAST) service, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + } + + internal void InitDisplay() + { + int ret = Interop.WiFiDirect.InitDisplay(); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to enable Wi-Fi Display functionality, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + + else + { + Globals.s_isDisplay = true; + } + } + + internal void DeinitDisplay() + { + int ret = Interop.WiFiDirect.DeinitDisplay(); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to disable Wi-Fi Display functionality, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + + else + { + Globals.s_isDisplay = false; + } + } + + internal void SetDisplay(WiFiDirectDisplayType type, int port, int hdcp) + { + int ret = Interop.WiFiDirect.SetDisplay(type, port, hdcp); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to set the Wi-Fi Display parameters, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + } + + internal void SetDisplayAvailability(bool availability) + { + int ret = Interop.WiFiDirect.SetDisplayAvailability(availability); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to set the Wi-Fi Display session availability, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + } + + internal void SetAutoGroupRemove(bool enable) + { + int ret = Interop.WiFiDirect.SetAutoGroupRemoval(enable); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to set automatic group removal feature when all peers are disconnected, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + } + + internal uint RegisterService(WiFiDirectServiceType type, string info, string serviceInfo) + { + uint serviceId; + int ret = Interop.WiFiDirect.RegisterService(type, info, serviceInfo, out serviceId); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to register for service, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + + return serviceId; + } + + internal void DeregisterService(uint serviceId) + { + int ret = Interop.WiFiDirect.DeregisterService(serviceId); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to deregister service, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + } + + internal static WiFiDirectManagerImpl Instance + { + get + { + if (_instance == null) + { + _instance = new WiFiDirectManagerImpl(); + } + + return _instance; + } + } + + private WiFiDirectManagerImpl() + { + } + + internal void Initialize() + { + int ret = Interop.WiFiDirect.Initialize(); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to initialize Wi-Fi direct, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + + else + { + Globals.s_isInitialize = true; + } + } + + ~WiFiDirectManagerImpl() + { + 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 + RemoveAllRegisteredEvent(); + Deinitialize(); + _disposed = true; + } + + private void Deinitialize() + { + int ret = Interop.WiFiDirect.Deinitialize(); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to deinitialize Wi-Fi direct, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + + else + { + Globals.s_isInitialize = false; + } + } + + private void RemoveAllRegisteredEvent() + { + //unregister all remaining events when this object is released. + if (_stateChanged != null) + { + UnregisterStateChangedEvent(); + } + + if (_discoveryStateChanged != null) + { + UnregisterDiscoveryStateChangedEvent(); + } + + if (_peerFound != null) + { + UnregisterPeerFoundEvent(); + } + + if (_deviceStateChanged != null) + { + UnregisterDeviceStateChangedEvent(); + } + + if (_connectionStatusChanged != null) + { + UnregisterConnectionStatusChangedEvent(); + } + } + } +} diff --git a/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect/WiFiDirectPeer.cs b/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect/WiFiDirectPeer.cs new file mode 100644 index 0000000..a97e466 --- /dev/null +++ b/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect/WiFiDirectPeer.cs @@ -0,0 +1,736 @@ +/* + * 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.Runtime.InteropServices; +using System.Collections.Concurrent; +using System.Collections.ObjectModel; +using System.Collections.Specialized; + +namespace Tizen.Network.WiFiDirect +{ + /// + /// WiFiDirectPeer class is used to handle the connection with remote devices using WiFi Direct. + /// + /// http://tizen.org/privilege/wifidirect + public class WiFiDirectPeer + { + private event EventHandler _connectionStateChanged; + private event EventHandler _ipAddressAssigned; + private event EventHandler _serviceStateChanged; + + private Interop.WiFiDirect.ConnectionStateChangedCallback _connectionStateChangedCallback; + private Interop.WiFiDirect.ClientIpAddressAssignedCallback _ipAddressAssignedCallback; + private Interop.WiFiDirect.ServiceStateChangedCallback _serviceStateChangedCallback; + + internal string _peerDeviceName; + internal string _peerIpAddress; + internal string _peerMacAddress; + internal string _peerInterfaceAddress; + internal int _peerChannel; + internal bool _isPeerConnected; + internal bool _isPeerGroupOwner; + internal bool _isPeerPersistentGroupOwner; + internal bool _peerP2PSupport; + internal WiFiDirectPrimaryDeviceType _peerPrimaryType; + internal WiFiDirectSecondaryDeviceType _peerSecondaryType; + internal int _peerWpsTypes; + internal bool _p2PInvitationSupported; + internal uint _peerServiceCount; + internal IEnumerable _peerServiceList; + internal bool _isPeerMiracastDevice; + + internal WiFiDirectPeer() + { + } + + /// + /// Name of Peer device. + /// + public string Name + { + get + { + return _peerDeviceName; + } + } + + /// + /// Ip address of the peer device. + /// + public string IpAddress + { + get + { + return _peerIpAddress; + } + } + + /// + /// Mac address of the peer device. + /// + public string MacAddress + { + get + { + return _peerMacAddress; + } + } + + /// + /// Interface address of the peer device. + /// + public string InterfaceAddress + { + get + { + return _peerInterfaceAddress; + } + } + + /// + /// Listening channel of the peer device. + /// + public int Channel + { + get + { + return _peerChannel; + } + } + + /// + /// Connected state of the peer device. + /// + public bool IsConnected + { + get + { + return _isPeerConnected; + } + } + + /// + /// P2P group state of the peer device. + /// + public bool IsGroupOwner + { + get + { + return _isPeerGroupOwner; + } + } + + /// + /// Persistent group state of the peer device. + /// + public bool IsPersistentGroupOwner + { + get + { + return _isPeerPersistentGroupOwner; + } + } + + /// + /// P2P state of the peer device. + /// + public bool P2PSupport + { + get + { + return _peerP2PSupport; + } + } + + /// + /// Primary catagory of the peer device. + /// + public WiFiDirectPrimaryDeviceType PrimaryType + { + get + { + return _peerPrimaryType; + } + } + + /// + /// Sub category of the peer device. + /// + public WiFiDirectSecondaryDeviceType SecondaryType + { + get + { + return _peerSecondaryType; + } + } + + /// + /// List of supported WPS type of the peer device. + /// + public int WpsTypes + { + get + { + return _peerWpsTypes; + } + } + + /// + /// P2P invitation state of the peer device. + /// + public bool IsP2PInvitationSupported + { + get + { + return _p2PInvitationSupported; + } + } + + /// + /// Number of registered services of the peer device. + /// + public uint ServiceCount + { + get + { + return _peerServiceCount; + } + } + + /// + /// List of registered services of the peer device. + /// + public IEnumerable ServiceList + { + get + { + return _peerServiceList; + } + } + + /// + /// Checks if peer device is a wifi display device. + /// + public bool IsMiracastDevice + { + get + { + return _isPeerMiracastDevice; + } + } + + /// + /// Wi-Fi Display device type of the peer device. + /// + /// + /// Wi-Fi Direct must be activated. + /// If there is any error, default value of WiFiDirectDisplayType will be returned. + /// + public WiFiDirectDisplayType Display + { + get + { + if (Globals.IsActivated) + { + WiFiDirectDisplayType displayType; + int ret = Interop.WiFiDirect.GetDisplayType(_peerMacAddress, out displayType); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to get the peer display type, Error - " + (WiFiDirectError)ret); + } + + return displayType; + } + + else + { + return default(WiFiDirectDisplayType); + } + } + } + + /// + /// Wi-Fi Display Session Availability of the peer device. + /// + /// + /// Wi-Fi Direct must be activated. + /// If there is any error, false will be returned. + /// + public bool DisplayAvailability + { + get + { + if (Globals.IsActivated) + { + bool displayAvailability; + int ret = Interop.WiFiDirect.GetDisplayAvailability(_peerMacAddress, out displayAvailability); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to get the peer display availability, Error - " + (WiFiDirectError)ret); + } + + return displayAvailability; + } + + else + { + return false; + } + } + } + + /// + /// Hdcp information of the peer device. + /// + /// + /// Wi-Fi Direct must be activated. + /// If there is any error, -1 will be returned. + /// + public int Hdcp + { + get + { + if (Globals.IsActivated) + { + int hdcpSupport; + int ret = Interop.WiFiDirect.GetDisplayHdcp(_peerMacAddress, out hdcpSupport); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to get the peer display hdcp support, Error - " + (WiFiDirectError)ret); + return -1; + } + + return hdcpSupport; + } + + else + { + return -1; + } + } + } + + /// + /// Port of the connected peer device. + /// + /// + /// Wi-Fi Direct must be activated. + /// If there is any error, -1 will be returned. + /// + public int Port + { + get + { + if (Globals.IsActivated) + { + int displayPort; + int ret = Interop.WiFiDirect.GetDisplayPort(_peerMacAddress, out displayPort); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to get the peer display port, Error - " + (WiFiDirectError)ret); + return -1; + } + + return displayPort; + } + + else + { + return -1; + } + } + } + + /// + /// WiFi Display max throughput of the peer device. + /// + /// + /// Wi-Fi Direct must be activated. + /// If there is any error, -1 will be returned. + /// + public int Throughput + { + get + { + if (Globals.IsActivated) + { + int displayThroughput; + int ret = Interop.WiFiDirect.GetDisplayThroughput(_peerMacAddress, out displayThroughput); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to get the peer display max throughput, Error - " + (WiFiDirectError)ret); + return -1; + } + + return displayThroughput; + } + + else + { + return -1; + } + } + } + + /// + /// (event) ConnectionStateChanged event is raised when the connection state of the peer device changes. + /// + public event EventHandler ConnectionStateChanged + { + add + { + if (Globals.IsInitialize) + { + if (_connectionStateChanged == null) + { + RegisterConnectionStateChangedEvent(); + } + + _connectionStateChanged += value; + } + } + + remove + { + if (Globals.IsInitialize) + { + _connectionStateChanged -= value; + if (_connectionStateChanged == null) + { + UnregisterConnectionStateChangedEvent(); + } + } + } + } + + /// + /// (event) IpAddressAssigned event is raised when ip address of the peer device is assigned. + /// + public event EventHandler IpAddressAssigned + { + add + { + if (Globals.IsInitialize) + { + if (_ipAddressAssigned == null) + { + RegisterIpAddressAssignedEvent(); + } + + _ipAddressAssigned += value; + } + } + + remove + { + if (Globals.IsInitialize) + { + _ipAddressAssigned -= value; + if (_ipAddressAssigned == null) + { + UnregisterIpAddressAssignedEvent(); + } + } + } + } + + /// + /// (event) ServiceStateChanged is raised when state of service discovery is changed. + /// + public event EventHandler ServiceStateChanged + { + add + { + if (Globals.IsInitialize) + { + if (_serviceStateChanged == null) + { + RegisterServiceStateChangedEvent(); + } + + _serviceStateChanged += value; + } + } + + remove + { + if (Globals.IsInitialize) + { + _serviceStateChanged -= value; + if (_serviceStateChanged == null) + { + UnregisterServiceStateChangedEvent(); + } + } + } + } + + private void RegisterConnectionStateChangedEvent() + { + _connectionStateChangedCallback = (int result, WiFiDirectConnectionState state, string address, IntPtr userData) => + { + if (_connectionStateChanged != null) + { + WiFiDirectError res = (WiFiDirectError)result; + _connectionStateChanged(null, new ConnectionStateChangedEventArgs(res, state, address)); + } + }; + int ret = Interop.WiFiDirect.SetConnectionChangedCallback(_connectionStateChangedCallback, IntPtr.Zero); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to set connection state changed callback, Error - " + (WiFiDirectError)ret); + } + } + + private void UnregisterConnectionStateChangedEvent() + { + int ret = Interop.WiFiDirect.UnsetConnectionChangedCallback(); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to unset connection state changed callback, Error - " + (WiFiDirectError)ret); + } + } + + private void RegisterIpAddressAssignedEvent() + { + _ipAddressAssignedCallback = (string macAddress, string ipAddress, string interfaceAddress, IntPtr userData) => + { + if (_ipAddressAssigned != null) + { + _ipAddressAssigned(null, new IpAddressAssignedEventArgs(macAddress, ipAddress, interfaceAddress)); + } + }; + int ret = Interop.WiFiDirect.SetIpAddressAssignedCallback(_ipAddressAssignedCallback, IntPtr.Zero); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to set ip address assigned callback, Error - " + (WiFiDirectError)ret); + } + } + + private void UnregisterIpAddressAssignedEvent() + { + int ret = Interop.WiFiDirect.UnsetIpAddressAssignedCallback(); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to unset ip address assigned callback, Error - " + (WiFiDirectError)ret); + } + } + + private void RegisterServiceStateChangedEvent() + { + _serviceStateChangedCallback = (int result, WiFiDirectServiceDiscoveryState stateInfo, WiFiDirectServiceType typeInfo, IntPtr responseData, string address, IntPtr userData) => + { + if (_serviceStateChanged != null) + { + WiFiDirectError error = (WiFiDirectError)result; + WiFiDirectServiceDiscoveryState state = stateInfo; + WiFiDirectServiceType type = typeInfo; + string response = Marshal.PtrToStringAnsi(responseData); + IntPtr peer; + Interop.WiFiDirect.GetDiscoveredPeerInfo(address, out peer); + DiscoveredPeerStruct peerStruct = (DiscoveredPeerStruct)Marshal.PtrToStructure(peer, typeof(DiscoveredPeerStruct)); + + _serviceStateChanged(null, new ServiceStateChangedEventArgs(error, state, type, response, WiFiDirectUtils.ConvertStructToDiscoveredPeer(peerStruct))); + } + }; + int ret = Interop.WiFiDirect.SetServiceStateChangedCallback(_serviceStateChangedCallback, IntPtr.Zero); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to set service state changed callback, Error - " + (WiFiDirectError)ret); + } + } + + private void UnregisterServiceStateChangedEvent() + { + int ret = Interop.WiFiDirect.UnsetServiceStateChangedCallback(); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to unset service state changed callback, Error - " + (WiFiDirectError)ret); + } + } + + /// + /// Connects to a specified remote device. + /// + /// + /// Wi-Fi Direct must be activated. + /// If this succeeds, ConnectionStateChanged event will be invoked. + /// + /// Thrown when the wifidirect is not supported + public void Connect() + { + if (Globals.IsActivated) + { + int ret = Interop.WiFiDirect.Connect(_peerMacAddress); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to connect, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + } + + else + { + Log.Error(Globals.LogTag, "Wifi-direct is not activated"); + WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); + } + } + + /// + /// Cancels the connection now in progress. + /// + /// + /// Wi-Fi Direct must be activated. + /// + /// Thrown when the wifidirect is not supported + public void CancelConnection() + { + if (Globals.IsActivated) + { + int ret = Interop.WiFiDirect.CancelConnection(_peerMacAddress); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to cancel the connection, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + } + + else + { + Log.Error(Globals.LogTag, "Wifi-direct is not activated"); + WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); + } + } + + /// + /// Disconnects the specified remote device. + /// + /// + /// Wi-Fi Direct must be activated. + /// If this succeeds, ConnectionStateChanged event will be invoked. + /// + /// Thrown when the wifidirect is not supported + public void Disconnect() + { + if (Globals.IsActivated) + { + int ret = Interop.WiFiDirect.Disconnect(_peerMacAddress); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to disconnect, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + } + + else + { + Log.Error(Globals.LogTag, "Wifi-direct is not activated"); + WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); + } + } + + /// + /// Allows a device to connect automatically. + /// + /// + /// Wi-Fi Direct must be activated. + /// + /// Thrown when the wifidirect is not supported + public void SetAutoConnect() + { + if (Globals.IsActivated) + { + int ret = Interop.WiFiDirect.SetAutoConnectionPeer(_peerMacAddress); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to set auto connection, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + } + + else + { + Log.Error(Globals.LogTag, "Wifi-direct is not activated"); + WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); + } + } + + /// + /// Starts the Wi-Fi Direct service discovery. + /// + /// + /// Wi-Fi Direct must be activated. + /// If this succeeds, ServiceStateChanged event will be invoked. + /// + /// + /// Thrown during one of the following cases : + /// 1. When the wifidirect is not supported + /// 2. When the wifidirect service discovery is not supported + /// + /// Type of service. + public void StartServiceDiscovery(WiFiDirectServiceType type) + { + if (Globals.IsActivated) + { + int ret = Interop.WiFiDirect.StartServiceDiscovery(_peerMacAddress, type); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to start Wi-Fi Direct service discovery, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + } + + else + { + Log.Error(Globals.LogTag, "Wifi-direct is not activated"); + WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); + } + } + + /// + /// Stops the Wi-Fi Direct service discovery. + /// + /// + /// Wi-Fi Direct must be activated. + /// + /// + /// Thrown during one of the following cases : + /// 1. When the wifidirect is not supported + /// 2. When the wifidirect service discovery is not supported + /// + /// Type of service. + public void CancelServiceDiscovery(WiFiDirectServiceType type) + { + if (Globals.IsActivated) + { + int ret = Interop.WiFiDirect.StopServiceDiscovery(_peerMacAddress, type); + if (ret != (int)WiFiDirectError.None) + { + Log.Error(Globals.LogTag, "Failed to stop Wi-Fi Direct service discovery, Error - " + (WiFiDirectError)ret); + WiFiDirectErrorFactory.ThrowWiFiDirectException(ret); + } + } + + else + { + Log.Error(Globals.LogTag, "Wifi-direct is not activated"); + WiFiDirectErrorFactory.ThrowWiFiDirectException((int)WiFiDirectError.NotPermitted); + } + } + } +} diff --git a/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect/WiFiDirectPersistentGroup.cs b/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect/WiFiDirectPersistentGroup.cs new file mode 100644 index 0000000..10274c9 --- /dev/null +++ b/src/Tizen.Network.WiFiDirect/Tizen.Network.WiFiDirect/WiFiDirectPersistentGroup.cs @@ -0,0 +1,57 @@ +/* + * 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.WiFiDirect +{ + /// + /// A class to handle persistent groups. + /// + public class WiFiDirectPersistentGroup + { + private string _address; + private string _ssid; + + internal WiFiDirectPersistentGroup(string address, string id) + { + _address = address; + _ssid = id; + } + + /// + /// MAC address of the persistent group owner. + /// + public string MacAddress + { + get + { + return _address; + } + } + + /// + /// SSID (Service Set Identifier) of the persistent group owner. + /// + public string Ssid + { + get + { + return _ssid; + } + } + } +}