[C# Bluetooth] Adding C# Bluetooth code.
authorSudha Bheemanna <b.sudha@samsung.com>
Tue, 20 Dec 2016 07:25:05 +0000 (12:55 +0530)
committerSudha Bheemanna <b.sudha@samsung.com>
Tue, 20 Dec 2016 07:28:52 +0000 (12:58 +0530)
Added inital files for the C# bluetooth code.
This branch to be used as base for futher development
and issue fixing.

Change-Id: If5a8dc4f2253f1afa4b551ac434839259209d1fa
Signed-off-by: Sudha Bheemanna <b.sudha@samsung.com>
35 files changed:
LICENSE [new file with mode: 0644]
Tizen.Bluetooth/Interop/Interop.Bluetooth.cs [new file with mode: 0644]
Tizen.Bluetooth/Interop/Interop.Glib.cs [new file with mode: 0644]
Tizen.Bluetooth/Interop/Interop.Libc.cs [new file with mode: 0644]
Tizen.Bluetooth/Interop/Interop.Libraries.cs [new file with mode: 0644]
Tizen.Bluetooth/Properties/AssemblyInfo.cs [new file with mode: 0644]
Tizen.Bluetooth/Tizen.Bluetooth.Net45.csproj [new file with mode: 0644]
Tizen.Bluetooth/Tizen.Bluetooth.Net45.project.json [new file with mode: 0644]
Tizen.Bluetooth/Tizen.Bluetooth.csproj [new file with mode: 0644]
Tizen.Bluetooth/Tizen.Bluetooth.nuspec [new file with mode: 0644]
Tizen.Bluetooth/Tizen.Bluetooth.project.json [new file with mode: 0644]
Tizen.Bluetooth/Tizen.Bluetooth.snk [new file with mode: 0644]
Tizen.Bluetooth/Tizen.Bluetooth/BluetoothAdapter.cs [new file with mode: 0644]
Tizen.Bluetooth/Tizen.Bluetooth/BluetoothAdapterImpl.cs [new file with mode: 0644]
Tizen.Bluetooth/Tizen.Bluetooth/BluetoothAudio.cs [new file with mode: 0644]
Tizen.Bluetooth/Tizen.Bluetooth/BluetoothAudioImpl.cs [new file with mode: 0644]
Tizen.Bluetooth/Tizen.Bluetooth/BluetoothAvrcp.cs [new file with mode: 0644]
Tizen.Bluetooth/Tizen.Bluetooth/BluetoothAvrcpImpl.cs [new file with mode: 0644]
Tizen.Bluetooth/Tizen.Bluetooth/BluetoothData.cs [new file with mode: 0644]
Tizen.Bluetooth/Tizen.Bluetooth/BluetoothDevice.cs [new file with mode: 0644]
Tizen.Bluetooth/Tizen.Bluetooth/BluetoothEnumerations.cs [new file with mode: 0644]
Tizen.Bluetooth/Tizen.Bluetooth/BluetoothError.cs [new file with mode: 0644]
Tizen.Bluetooth/Tizen.Bluetooth/BluetoothEventArgs.cs [new file with mode: 0644]
Tizen.Bluetooth/Tizen.Bluetooth/BluetoothGatt.cs [new file with mode: 0644]
Tizen.Bluetooth/Tizen.Bluetooth/BluetoothGattImpl.cs [new file with mode: 0644]
Tizen.Bluetooth/Tizen.Bluetooth/BluetoothHid.cs [new file with mode: 0644]
Tizen.Bluetooth/Tizen.Bluetooth/BluetoothHidImpl.cs [new file with mode: 0644]
Tizen.Bluetooth/Tizen.Bluetooth/BluetoothLeAdapter.cs [new file with mode: 0644]
Tizen.Bluetooth/Tizen.Bluetooth/BluetoothLeAdapterImpl.cs [new file with mode: 0644]
Tizen.Bluetooth/Tizen.Bluetooth/BluetoothProfile.cs [new file with mode: 0644]
Tizen.Bluetooth/Tizen.Bluetooth/BluetoothServerSocket.cs [new file with mode: 0644]
Tizen.Bluetooth/Tizen.Bluetooth/BluetoothSocket.cs [new file with mode: 0644]
Tizen.Bluetooth/Tizen.Bluetooth/BluetoothStructs.cs [new file with mode: 0644]
packaging/csapi-bluetooth.manifest [new file with mode: 0644]
packaging/csapi-bluetooth.spec [new file with mode: 0644]

diff --git a/LICENSE b/LICENSE
new file mode 100644 (file)
index 0000000..d645695
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
diff --git a/Tizen.Bluetooth/Interop/Interop.Bluetooth.cs b/Tizen.Bluetooth/Interop/Interop.Bluetooth.cs
new file mode 100644 (file)
index 0000000..81aaf74
--- /dev/null
@@ -0,0 +1,597 @@
+/*
+ * 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.Bluetooth;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+    internal static partial class Bluetooth
+    {
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void StateChangedCallback(int result, int state, IntPtr userData);
+
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void NameChangedCallback(string deviceName, IntPtr userData);
+
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void VisibilityModeChangedCallback(int result, int visibility, IntPtr userData);
+
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void VisibilityDurationChangedCallback(int duration, IntPtr userData);
+
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void DiscoveryStateChangedCallback(int result, BluetoothDeviceDiscoveryState state, IntPtr deviceInfo, IntPtr userData);
+
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate bool BondedDeviceCallback([MarshalAs(UnmanagedType.Struct)]ref BluetoothDeviceStruct device, IntPtr userData);
+
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void BondCreatedCallback(int result, [MarshalAs(UnmanagedType.Struct)]ref BluetoothDeviceStruct device, IntPtr userData);
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void BondDestroyedCallback(int result, string deviceAddress, IntPtr userData);
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void AuthorizationChangedCallback(int authorization, string deviceAddress, IntPtr userData);
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void ServiceSearchedCallback(int result, [MarshalAs(UnmanagedType.Struct)]ref BluetoothDeviceSdpStruct sdp, IntPtr userData);
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void DeviceConnectionStateChangedCallback(bool connected, [MarshalAs(UnmanagedType.Struct)]ref BluetoothDeviceConnectionStruct device, IntPtr userData);
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate bool ConnectedProfileCallback(int profile, IntPtr userData);
+
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void DataReceivedCallback([MarshalAs(UnmanagedType.Struct)]ref SocketDataStruct socketData, IntPtr userData);
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void SocketConnectionStateChangedCallback(int result, BluetoothSocketState connectionState, [MarshalAs(UnmanagedType.Struct)]ref SocketConnectionStruct socketConnection, IntPtr userData);
+
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void AudioConnectionStateChangedCallback(int result, bool connected, string deviceAddress, int profileType, IntPtr userData);
+
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void HidConnectionStateChangedCallback(int result, bool connected, string deviceAddress, IntPtr userData);
+
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void TargetConnectionStateChangedCallback(bool connected, string deviceAddress, IntPtr userData);
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void EqualizerStateChangedCallback(int equalizer, IntPtr userData);
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void RepeatModeChangedCallback(int repeat, IntPtr userData);
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void ShuffleModeChangedCallback(int shuffle, IntPtr userData);
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void ScanModeChangedCallback(int scan, IntPtr userData);
+
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void ConnectionChangedCallback(int result, bool connected, string deviceAddress, IntPtr userData);
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void ClientCharacteristicValueChangedCallback(IntPtr characteristicHandle, string value, int len, IntPtr userData);
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void GattClientRequestedCallback(int result, IntPtr handle, IntPtr userData);
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate bool GattForEachCallback(int total, int index, IntPtr handle, IntPtr userData);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_initialize")]
+        internal static extern int Initialize();
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_deinitialize")]
+        internal static extern int Deinitialize();
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_get_name")]
+        internal static extern int GetName(out string name);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_set_name")]
+        internal static extern int SetName(string name);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_get_state")]
+        internal static extern int GetState(out BluetoothState isActivated);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_get_address")]
+        internal static extern int GetAddress(out string address);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_get_visibility")]
+        internal static extern int GetVisibility(out int visibility, out int duration);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_is_discovering")]
+        internal static extern int IsDiscovering(out bool isDiscovering);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_start_device_discovery")]
+        internal static extern int StartDiscovery();
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_stop_device_discovery")]
+        internal static extern int StopDiscovery();
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_foreach_bonded_device")]
+        internal static extern int GetBondedDevices(BondedDeviceCallback bondedDeviceCb, IntPtr userData);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_get_bonded_device_info")]
+        internal static extern int GetBondedDeviceByAddress(string deviceAddress, out IntPtr deviceInfo);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_free_device_info")]
+        internal static extern int FreeDeviceInfo(BluetoothDeviceStruct deviceInfo);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_is_service_used")]
+        internal static extern int IsServiceUsed(string serviceUuid, out bool used);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_get_local_oob_data")]
+        internal static extern int GetOobData(out IntPtr hash, out IntPtr randomizer, out int hashLen, out int randomizerLen);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_set_remote_oob_data")]
+        internal static extern int SetOobData(string deviceAddress, IntPtr hash, IntPtr randomizer, int hashLen, int randomizerLen);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_remove_remote_oob_data")]
+        internal static extern int RemoveOobData(string deviceAddress);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_set_state_changed_cb")]
+        internal static extern int SetStateChangedCallback(StateChangedCallback stateChangedCb, IntPtr userData);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_unset_state_changed_cb")]
+        internal static extern int UnsetStateChangedCallback();
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_set_name_changed_cb")]
+        internal static extern int SetNameChangedCallback(NameChangedCallback nameChangedCb, IntPtr userData);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_unset_name_changed_cb")]
+        internal static extern int UnsetNameChangedCallback();
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_set_visibility_mode_changed_cb")]
+        internal static extern int SetVisibilityModeChangedCallback(VisibilityModeChangedCallback visibilityChangedCb, IntPtr userData);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_unset_visibility_mode_changed_cb")]
+        internal static extern int UnsetVisibilityModeChangedCallback();
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_set_visibility_duration_changed_cb")]
+        internal static extern int SetVisibilityDurationChangedCallback(VisibilityDurationChangedCallback durationChangedCb, IntPtr userData);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_unset_visibility_duration_changed_cb")]
+        internal static extern int UnsetVisibilityDurationChangedCallback();
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_set_device_discovery_state_changed_cb")]
+        internal static extern int SetDiscoveryStateChangedCallback(DiscoveryStateChangedCallback discoveryChangedCb, IntPtr userData);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_unset_device_discovery_state_changed_cb")]
+        internal static extern int UnsetDiscoveryStateChangedCallback();
+
+        //Bluetooth Device
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_create_bond")]
+        internal static extern int CreateBond(string deviceAddress);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_destroy_bond")]
+        internal static extern int DestroyBond(string deviceAddress);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_cancel_bonding")]
+        internal static extern int CancelBonding();
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_set_alias")]
+        internal static extern int SetAlias(string deviceAddress, string alias);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_set_authorization")]
+        internal static extern int SetAuthorization(string deviceAddress, int state);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_get_service_mask_from_uuid_list")]
+        internal static extern int GetMaskFromUuid([MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr, SizeParamIndex = 1)] string[] uuids, int count, out BluetoothServiceClassType serviceMask);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_start_service_search")]
+        internal static extern int StartServiceSearch(string deviceAddress);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_foreach_connected_profiles")]
+        internal static extern int GetConnectedProfiles(string deviceAddress, ConnectedProfileCallback connectedProfileCb, IntPtr userData);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_is_profile_connected")]
+        internal static extern int IsProfileConnected(string deviceAddress, int profile, out bool connectionStatus);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_set_bond_created_cb")]
+        internal static extern int SetBondCreatedCallback(BondCreatedCallback bondCreatedCb, IntPtr userData);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_unset_bond_created_cb")]
+        internal static extern int UnsetBondCreatedCallback();
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_set_bond_destroyed_cb")]
+        internal static extern int SetBondDestroyedCallback(BondDestroyedCallback bondDestroyedCb, IntPtr userData);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_unset_bond_destroyed_cb")]
+        internal static extern int UnsetBondDestroyedCallback();
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_set_authorization_changed_cb")]
+        internal static extern int SetAuthorizationChangedCallback(AuthorizationChangedCallback authorizationChangedCb, IntPtr userData);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_unset_authorization_changed_cb")]
+        internal static extern int UnsetAuthorizationChangedCallback();
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_set_service_searched_cb")]
+        internal static extern int SetServiceSearchedCallback(ServiceSearchedCallback serviceSearchedCb, IntPtr userData);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_unset_service_searched_cb")]
+        internal static extern int UnsetServiceSearchedCallback();
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_set_connection_state_changed_cb")]
+        internal static extern int SetConnectionStateChangedCallback(DeviceConnectionStateChangedCallback connectionChangedCb, IntPtr userData);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_device_unset_connection_state_changed_cb")]
+        internal static extern int UnsetConnectionStateChangedCallback();
+
+        // Bluetooth LE Adapter
+
+        //Callback for event
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate void AdapterLeScanResultChangedCallBack(int result,
+            [MarshalAs(UnmanagedType.Struct)]ref BluetoothLeScanDataStruct scanData, IntPtr userData);
+
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        public delegate void AdvertisingStateChangedCallBack(int result, IntPtr advertiserHandle,
+                            BluetoothLeAdvertisingState advertisingState, IntPtr userData);
+
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        public delegate void GattConnectionStateChangedCallBack(int result, bool connected,
+                                        string remoteAddress, IntPtr userData);
+
+        //Bluetooth Le Adapter Apis
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_start_scan")]
+        public static extern int StartScan(AdapterLeScanResultChangedCallBack callback, IntPtr userData);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_stop_scan")]
+        public static extern int StopScan();
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_get_scan_result_service_uuids")]
+        public static extern int GetScanResultServiceUuid(ref BluetoothLeScanDataStruct scanData,
+            BluetoothLePacketType packetType, ref IntPtr uuids, ref int count);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_get_scan_result_device_name")]
+        public static extern int GetLeScanResultDeviceName(ref BluetoothLeScanDataStruct scanData,
+                            BluetoothLePacketType packetType, out string deviceName);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_get_scan_result_tx_power_level")]
+        public static extern int GetScanResultTxPowerLevel(ref BluetoothLeScanDataStruct scanData,
+                            BluetoothLePacketType packetType, out int txPowerLevel);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_get_scan_result_service_solicitation_uuids")]
+        public static extern int GetScaResultSvcSolicitationUuids(ref BluetoothLeScanDataStruct scanData,
+                            BluetoothLePacketType packetType, out IntPtr uuids, out int count);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_get_scan_result_service_data_list")]
+        public static extern int GetScanResultServiceDataList(ref BluetoothLeScanDataStruct scanData,
+                            BluetoothLePacketType PacketType, out IntPtr serviceDataArray, out int count);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_free_service_data_list")]
+        public static extern int FreeServiceDataList(IntPtr serviceData, int count);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_get_scan_result_appearance")]\r
+        public static extern int GetScanResultAppearance(ref BluetoothLeScanDataStruct scanData,
+                            BluetoothLePacketType packetType, out int appearance);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_get_scan_result_manufacturer_data")]
+        public static extern int GetScanResultManufacturerData(ref BluetoothLeScanDataStruct scanData,
+                            BluetoothLePacketType packetType, out int manufId, out IntPtr manufData,
+                            out int manufDataLength);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_connect")]
+        internal static extern int GattConnect(string deviceAddress, bool autoConnect);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_disconnect")]
+        internal static extern int GattDisconnect(string deviceAddress);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_set_connection_state_changed_cb")]
+        internal static extern int SetGattConnectionStateChangedCallback(
+            GattConnectionStateChangedCallBack gattConnectionChangedCb, IntPtr userData);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_unset_connection_state_changed_cb")]
+        internal static extern int UnsetGattConnectionStateChangedCallback();
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_create_advertiser")]
+        public static extern int CreateAdvertiser(out IntPtr advertiserHandle);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_destroy_advertiser")]
+        public static extern int DestroyAdvertiser(IntPtr advertiserHandle);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_add_advertising_service_uuid")]
+        public static extern int AddAdvertisingServiceUuid(IntPtr advertiserHandle,
+                                    BluetoothLePacketType PacketType, string uuid);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_add_advertising_service_solicitation_uuid")]
+        public static extern int AddAdvertisingServiceSolicitationUuid(IntPtr advertiserHandle,
+            BluetoothLePacketType PacketType, string uuid);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_add_advertising_service_data")]
+        public static extern int AddAdvertisingServiceData(IntPtr advertiserHandle,
+            BluetoothLePacketType PacketType, string uuid, IntPtr serviceData, int serviceDatalength);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_set_advertising_appearance")]
+        public static extern int SetAdvertisingAppearance(IntPtr advertiserHandle,
+                                    BluetoothLePacketType packetType, int appearance);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_add_advertising_manufacturer_data")]
+        public static extern int AddAdvertisingManufData(IntPtr advertiserHandle, BluetoothLePacketType packetType,
+            int manufId, IntPtr manufData, int manufacturerDataLength);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_set_advertising_device_name")]
+        public static extern int SetAdvertisingDeviceName(IntPtr advertiserHandle, BluetoothLePacketType packetType,
+                                                bool includeName);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_set_advertising_tx_power_level")]
+        public static extern int SetAdvertisingTxPowerLevel(IntPtr advertiserHandle, BluetoothLePacketType packetType,
+                                                bool includePowerLevel);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_clear_advertising_data")]
+        public static extern int ClearAdvertisingData(IntPtr advertiserHandle, BluetoothLePacketType packetType);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_start_advertising_new")]
+        public static extern int BluetoothLeStartAdvertising(IntPtr advertiserHandle,
+                                         AdvertisingStateChangedCallBack callback, IntPtr userData);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_stop_advertising")]
+        public static extern int BluetoothLeStopAdvertising(IntPtr advertiserHandle);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_set_advertising_mode")]
+        public static extern int SetAdvertisingMode(IntPtr advertiserHandle,
+                                        BluetoothLeAdvertisingMode advertisingMode);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_adapter_le_set_advertising_connectable")]
+        public static extern int SetAdvertisingConnectable(IntPtr advertiserHandle,
+                                        bool connectable);
+
+        //Bluetooth Socket
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_create_rfcomm")]
+        internal static extern int CreateServerSocket(string serviceUuid, out int socketFd);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_destroy_rfcomm")]
+        internal static extern int DestroyServerSocket(int socketFd);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_listen_and_accept_rfcomm")]
+        internal static extern int Listen(int socketFd, int pendingConnections);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_connect_rfcomm")]
+        internal static extern int ConnectSocket(string address, string serviceUuid);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_disconnect_rfcomm")]
+        internal static extern int DisconnectSocket(int socketFd);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_send_data")]
+        internal static extern int SendData(int socketFd, string data, int dataLength);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_set_data_received_cb")]
+        internal static extern int SetDataReceivedCallback(DataReceivedCallback callback, IntPtr userData);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_unset_data_received_cb")]
+        internal static extern int UnsetDataReceivedCallback();
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_set_connection_state_changed_cb")]
+        internal static extern int SetConnectionStateChangedCallback(SocketConnectionStateChangedCallback callback, IntPtr userData);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_socket_unset_connection_state_changed_cb")]
+        internal static extern int UnsetSocketConnectionStateChangedCallback();
+
+        // Bluetooth Audio
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_audio_initialize")]
+        internal static extern int InitializeAudio();
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_audio_deinitialize")]
+        internal static extern int DeinitializeAudio();
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_audio_connect")]
+        internal static extern int Connect(string deviceAddress, int profileType);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_audio_disconnect")]
+        internal static extern int Disconnect(string deviceAddress, int profileType);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_audio_set_connection_state_changed_cb")]
+        internal static extern int SetAudioConnectionStateChangedCallback(AudioConnectionStateChangedCallback audioStateChangedCb, IntPtr userData);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_audio_unset_connection_state_changed_cb")]
+        internal static extern int UnsetAudioConnectionStateChangedCallback();
+
+        //Bluetooth Hid
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_hid_host_initialize")]
+        internal static extern int InitializeHid(HidConnectionStateChangedCallback hidConnectionChangedCb, IntPtr userData);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_hid_host_deinitialize")]
+        internal static extern int DeinitializeHid();
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_hid_host_connect")]
+        internal static extern int Connect(string deviceAddress);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_hid_host_disconnect")]
+        internal static extern int Disconnect(string deviceAddress);
+
+        //Bluetooth Avrcp
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_target_initialize")]
+        internal static extern int InitializeAvrcp(TargetConnectionStateChangedCallback targetStateChangedCb, IntPtr userData);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_target_deinitialize")]
+        internal static extern int DeinitializeAvrcp();
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_target_notify_equalizer_state")]
+        internal static extern int NotifyEqualizerState(int state);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_target_notify_repeat_mode")]
+        internal static extern int NotifyRepeatMode(int repeat);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_target_notify_shuffle_mode")]
+        internal static extern int NotifyShuffleMode(int shuffle);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_target_notify_scan_mode")]
+        internal static extern int NotifyScanMode(int scan);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_target_notify_player_state")]
+        internal static extern int NotifyPlayerState(int state);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_target_notify_position")]
+        internal static extern int NotifyCurrentPosition(uint position);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_target_notify_track")]
+        internal static extern int NotifyTrack(string title, string artist, string album, string genre, uint trackNum, uint totaltracks, uint duration);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_set_equalizer_state_changed_cb")]
+        internal static extern int SetEqualizerStateChangedCallback(EqualizerStateChangedCallback equalizerStateChangedCb, IntPtr userData);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_unset_equalizer_state_changed_cb")]
+        internal static extern int UnsetEqualizerStateChangedCallback();
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_set_repeat_mode_changed_cb")]
+        internal static extern int SetRepeatModeChangedCallback(RepeatModeChangedCallback repeatModeChangedCb, IntPtr userData);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_unset_repeat_mode_changed_cb")]
+        internal static extern int UnsetRepeatModeChangedCallback();
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_set_shuffle_mode_changed_cb")]
+        internal static extern int SetShuffleModeChangedCallback(ShuffleModeChangedCallback shuffleModeChangedCb, IntPtr userData);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_unset_shuffle_mode_changed_cb")]
+        internal static extern int UnsetShuffleModeChangedCallback();
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_set_scan_mode_changed_cb")]
+        internal static extern int SetScanModeChangedCallback(ScanModeChangedCallback scanModeChangedCb, IntPtr userData);
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_avrcp_unset_scan_mode_changed_cb")]
+        internal static extern int UnsetScanModeChangedCallback();
+
+        // Bluetooth GATT
+
+        [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
+        internal delegate bool BtGattForeachCallback(int total, int index, IntPtr gattHandle, IntPtr userData);
+
+        [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
+        internal delegate void BtGattServerReadValueRequestedCallback(string clientAddress, int requestId, BluetoothGattServerHandle serverHandle, BluetoothGattAttributeHandle gattHandle, int offset, IntPtr userData);
+
+        [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
+        internal delegate void BtGattServerWriteValueRequestedCallback(string clientAddress, int requestId, BluetoothGattServerHandle serverHandle, BluetoothGattAttributeHandle gattHandle, int offset, byte[] value, int len, IntPtr userData);
+
+        [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
+        internal delegate void BtClientCharacteristicValueChangedCallback(BluetoothGattAttributeHandle characteristicHandle, byte[] value, int len, IntPtr userData);
+
+        [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
+        internal delegate void BtGattServerNotificationStateChangeCallback(bool notify, BluetoothGattServerHandle serverHandle, BluetoothGattAttributeHandle characteristicHandle, IntPtr userData);
+
+        [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
+        internal delegate void BtGattServerNotificationSentCallback(int result, string clientAddress, BluetoothGattServerHandle serverHandle, BluetoothGattAttributeHandle characteristicHandle, bool completed, IntPtr userData);
+
+        [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
+        internal delegate void BtGattClientRequestCompletedCallback(int result, IntPtr requestHandle, IntPtr userData);
+
+        // Gatt Attribute
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_destroy")]
+        internal static extern int BtGattDestroy(IntPtr gattHandle);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_get_uuid")]
+        internal static extern int BtGattGetUuid(BluetoothGattAttributeHandle gattHandle, out string uuid);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_get_value")]
+        internal static extern int BtGattGetValue(BluetoothGattAttributeHandle gattHandle, out IntPtr nativeValue, out int valueLength);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_set_value")]
+        internal static extern int BtGattSetValue(BluetoothGattAttributeHandle gattHandle, byte[] value, int valueLength);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_get_int_value")]
+        internal static extern int BtGattGetIntValue(BluetoothGattAttributeHandle gattHandle, int type, int offset, out int value);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_set_int_value")]
+        internal static extern int BtGattSetIntValue(BluetoothGattAttributeHandle gattHandle, int type, int value, int offset);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_get_float_value")]
+        internal static extern int BtGattGetFloatValue(BluetoothGattAttributeHandle gattHandle, int type, int offset, out float value);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_set_float_value")]
+        internal static extern int BtGattSetFloatValue(BluetoothGattAttributeHandle gattHandle, int type, int mantissa, int exponent, int offset);
+
+        // GATT Descriptor
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_descriptor_create")]
+        internal static extern int BtGattDescriptorCreate(string uuid, int permissions, byte[] value, int valueLength, out BluetoothGattAttributeHandle descriptorHandle);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_descriptor_get_permissions")]
+        internal static extern int BtGattDescriptorGetPermissions(BluetoothGattAttributeHandle descriptorHandle, out int permissions);
+
+        // GATT Characteristic
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_characteristic_create")]
+        internal static extern int BtGattCharacteristicCreate(string uuid, int permissions, int properties, byte[] value, int valueLength, out BluetoothGattAttributeHandle characteristicHandle);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_characteristic_get_permissions")]
+        internal static extern int BtGattCharacteristicGetPermissions(BluetoothGattAttributeHandle characteristicHandle, out int permissions);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_characteristic_get_properties")]
+        internal static extern int BtGattCharacteristicGetProperties(BluetoothGattAttributeHandle characteristicHandle, out int properties);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_characteristic_set_properties")]
+        internal static extern int BtGattCharacteristicSetProperties(BluetoothGattAttributeHandle characteristicHandle, int properties);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_characteristic_get_write_type")]
+        internal static extern int BtGattCharacteristicGetWriteType(BluetoothGattAttributeHandle characteristicHandle, out int writeType);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_characteristic_set_write_type")]
+        internal static extern int BtGattCharacteristicSetWriteType(BluetoothGattAttributeHandle characteristicHandle, int writeType);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_characteristic_add_descriptor")]
+        internal static extern int BtGattCharacteristicAddDescriptor(BluetoothGattAttributeHandle characteristicHandle, BluetoothGattAttributeHandle descriptorHandle);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_characteristic_get_descriptor")]
+        internal static extern int BtGattCharacteristicGetDescriptor(BluetoothGattAttributeHandle characteristicHandle, string uuid, out BluetoothGattAttributeHandle descriptorHandle);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_characteristic_foreach_descriptors")]
+        internal static extern int BtGattCharacteristicForeachDescriptors(BluetoothGattAttributeHandle characteristicHandle, BtGattForeachCallback callback, IntPtr userData);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_client_set_characteristic_value_changed_cb")]
+        internal static extern int BtGattClientSetCharacteristicValueChangedCallback(BluetoothGattAttributeHandle characteristicHandle, BtClientCharacteristicValueChangedCallback cb, IntPtr userData);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_client_unset_characteristic_value_changed_cb")]
+        internal static extern int BtGattClientUnsetCharacteristicValueChangedCallback(BluetoothGattAttributeHandle characteristicHandle);
+
+        // GATT Service
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_service_create")]
+        internal static extern int BtGattServiceCreate(string uuid, int type, out BluetoothGattAttributeHandle serviceHandle);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_service_add_characteristic")]
+        internal static extern int BtGattServiceAddCharacteristic(BluetoothGattAttributeHandle serviceHandle, BluetoothGattAttributeHandle characteristicHandle);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_service_get_characteristic")]
+        internal static extern int BtGattServiceGetCharacteristic(BluetoothGattAttributeHandle serviceHandle, string uuid, out BluetoothGattAttributeHandle characteristicHandle);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_service_foreach_characteristics")]
+        internal static extern int BtGattServiceForeachCharacteristics(BluetoothGattAttributeHandle serviceHandle, BtGattForeachCallback callback, IntPtr userData);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_service_add_included_service")]
+        internal static extern int BtGattServiceAddIncludedService(BluetoothGattAttributeHandle serviceHandle, BluetoothGattAttributeHandle includedServiceHandle);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_service_get_included_service")]
+        internal static extern int BtGattServiceGetIncludedService(BluetoothGattAttributeHandle serviceHandle, string uuid, out BluetoothGattAttributeHandle includedServiceHandle);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_service_foreach_included_services")]
+        internal static extern int BtGattServiceForeachIncludedServices(BluetoothGattAttributeHandle serviceHandle, BtGattForeachCallback callback, IntPtr userData);
+
+        // GATT Client
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_client_destroy")]
+        internal static extern int BtGattClientDestroy(IntPtr clientHandle);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_client_create")]
+        internal static extern int BtGattClientCreate(string remoteAddress, out BluetoothGattClientHandle clientHandle);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_client_get_remote_address")]
+        internal static extern int BtGattClientGetRemoteAddress(BluetoothGattClientHandle clientHandle, out string remoteAddress);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_client_get_service")]
+        internal static extern int BtGattClientGetService(BluetoothGattClientHandle clientHandle, string uuid, out BluetoothGattAttributeHandle serviceHandle);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_client_foreach_services")]
+        internal static extern int BtGattClientForeachServices(BluetoothGattClientHandle clientHandle, BtGattForeachCallback callback, IntPtr userData);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_client_read_value")]
+        internal static extern int BtGattClientReadValue(BluetoothGattAttributeHandle gattHandle, BtGattClientRequestCompletedCallback callback, IntPtr userData);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_client_write_value")]
+        internal static extern int BtGattClientWriteValue(BluetoothGattAttributeHandle gattHandle, BtGattClientRequestCompletedCallback callback, IntPtr userData);
+
+        // GATT Server
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_destroy")]
+        internal static extern int BtGattServerDestroy(IntPtr serverHandle);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_create")]
+        internal static extern int BtGattServerCreate(out BluetoothGattServerHandle serverHandle);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_initialize")]
+        internal static extern int BtGattServerInitialize();
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_deinitialize")]
+        internal static extern int BtGattServerDeinitialize();
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_set_read_value_requested_cb")]
+        internal static extern int BtGattServerSetReadValueRequestedCallback(BluetoothGattAttributeHandle gattHandle, BtGattServerReadValueRequestedCallback callback, IntPtr userData);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_set_read_value_requested_cb")]
+        internal static extern int BtGattServerSetWriteValueRequestedCallback(BluetoothGattAttributeHandle gattHandle, BtGattServerWriteValueRequestedCallback callback, IntPtr userData);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_set_notification_state_change_cb")]
+        internal static extern int BtGattServeSetNotificationStateChangeCallback(BluetoothGattAttributeHandle characteristicHandle, BtGattServerNotificationStateChangeCallback callback, IntPtr userData);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_start")]
+        internal static extern int BtGattServerStart();
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_register_service")]
+        internal static extern int BtGattServerRegisterService(BluetoothGattServerHandle serverHandle, BluetoothGattAttributeHandle serviceHandle);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_unregister_service")]
+        internal static extern int BtGattServerUnregisterService(BluetoothGattServerHandle serverHandle, BluetoothGattAttributeHandle serviceHandle);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_unregister_all_services")]
+        internal static extern int BtGattServerUnregisterAllServices(BluetoothGattServerHandle serverHandle);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_get_service")]
+        internal static extern int BtGattServerGetService(BluetoothGattServerHandle serverHandle, string uuid, out BluetoothGattAttributeHandle serviceHandle);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_foreach_services")]
+        internal static extern int BtGattServerForeachServices(BluetoothGattServerHandle serverHandle, BtGattForeachCallback callback, IntPtr userData);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_send_response")]
+        internal static extern int BtGattServerSendResponse(int requestId, int requestType, int offset, int status, byte[] value, int valueLen);
+
+        [DllImport(Libraries.Bluetooth, EntryPoint = "bt_gatt_server_notify")]
+        internal static extern int BtGattServerNotify(BluetoothGattAttributeHandle characteristicHandle, bool sendIndication, BtGattServerNotificationSentCallback callback, string clientAddress, IntPtr userData);
+    }
+}
+
+
diff --git a/Tizen.Bluetooth/Interop/Interop.Glib.cs b/Tizen.Bluetooth/Interop/Interop.Glib.cs
new file mode 100644 (file)
index 0000000..576a6e2
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+    internal static partial class Glib
+    {
+        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+        internal delegate bool GSourceFunc(IntPtr userData);
+
+        [DllImport(Libraries.Glib, EntryPoint = "g_idle_add", CallingConvention = CallingConvention.Cdecl)]
+        internal static extern uint IdleAdd(GSourceFunc d, IntPtr data);
+    }
+}
diff --git a/Tizen.Bluetooth/Interop/Interop.Libc.cs b/Tizen.Bluetooth/Interop/Interop.Libc.cs
new file mode 100644 (file)
index 0000000..825599e
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Runtime.InteropServices;
+
+internal static partial class Interop
+{
+    internal static partial class Libc
+    {
+        [DllImport(Libraries.Libc, EntryPoint = "free", CallingConvention = CallingConvention.Cdecl)]
+        internal static extern int Free(IntPtr ptr);
+    }
+}
diff --git a/Tizen.Bluetooth/Interop/Interop.Libraries.cs b/Tizen.Bluetooth/Interop/Interop.Libraries.cs
new file mode 100644 (file)
index 0000000..4aa83d4
--- /dev/null
@@ -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 Bluetooth = "libcapi-network-bluetooth.so.0";
+        public const string Glib = "libglib-2.0.so.0";
+        public const string Libc = "libc.so.6";
+    }
+}
diff --git a/Tizen.Bluetooth/Properties/AssemblyInfo.cs b/Tizen.Bluetooth/Properties/AssemblyInfo.cs
new file mode 100644 (file)
index 0000000..31b2b2b
--- /dev/null
@@ -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.Bluetooth")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Tizen.Bluetooth")]
+[assembly: AssemblyCopyright("Copyright \u00A9  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("99a90243-7db1-4704-a078-3529c2da4e81")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers 
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/Tizen.Bluetooth/Tizen.Bluetooth.Net45.csproj b/Tizen.Bluetooth/Tizen.Bluetooth.Net45.csproj
new file mode 100644 (file)
index 0000000..739aaca
--- /dev/null
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <PropertyGroup>\r
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>\r
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>\r
+    <ProjectGuid>{BF719F11-CDEA-4D04-A85B-4521A69E3614}</ProjectGuid>\r
+    <OutputType>Library</OutputType>\r
+    <AppDesignerFolder>Properties</AppDesignerFolder>\r
+    <RootNamespace>Tizen.Bluetooth</RootNamespace>\r
+    <AssemblyName>Tizen.Bluetooth</AssemblyName>\r
+    <FileAlignment>512</FileAlignment>\r
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">\r
+    <DebugSymbols>true</DebugSymbols>\r
+    <DebugType>full</DebugType>\r
+    <Optimize>false</Optimize>\r
+    <OutputPath>bin\Debug\Net45\</OutputPath>\r
+    <DefineConstants>DEBUG;TRACE</DefineConstants>\r
+    <ErrorReport>prompt</ErrorReport>\r
+    <WarningLevel>4</WarningLevel>\r
+    <Prefer32Bit>false</Prefer32Bit>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">\r
+    <DebugType>pdbonly</DebugType>\r
+    <Optimize>true</Optimize>\r
+    <OutputPath>bin\Release\Net45\</OutputPath>\r
+    <DefineConstants>TRACE</DefineConstants>\r
+    <ErrorReport>prompt</ErrorReport>\r
+    <WarningLevel>4</WarningLevel>\r
+    <Prefer32Bit>false</Prefer32Bit>\r
+  </PropertyGroup>\r
+  <PropertyGroup>\r
+    <SignAssembly>true</SignAssembly>\r
+  </PropertyGroup>\r
+  <PropertyGroup>\r
+    <AssemblyOriginatorKeyFile>Tizen.Bluetooth.snk</AssemblyOriginatorKeyFile>\r
+  </PropertyGroup>\r
+  <ItemGroup>\r
+    <Reference Include="System" />\r
+    <Reference Include="System.Core" />\r
+    <Reference Include="System.Xml.Linq" />\r
+    <Reference Include="System.Data.DataSetExtensions" />\r
+    <Reference Include="Microsoft.CSharp" />\r
+    <Reference Include="System.Data" />\r
+    <Reference Include="System.Net.Http" />\r
+    <Reference Include="System.Xml" />\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <Compile Include="Interop\Interop.Glib.cs" />\r
+    <Compile Include="Interop\Interop.Libc.cs" />\r
+    <Compile Include="Interop\Interop.Libraries.cs" />\r
+    <Compile Include="Interop\Interop.Bluetooth.cs" />\r
+    <Compile Include="Properties\AssemblyInfo.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothAdapter.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothAdapterImpl.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothAudio.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothAudioImpl.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothAvrcp.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothAvrcpImpl.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothData.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothDevice.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothEnumerations.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothError.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothEventArgs.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothGatt.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothGattImpl.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothHid.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothHidImpl.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothLeAdapter.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothLeAdapterImpl.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothProfile.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothServerSocket.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothSocket.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothStructs.cs" />\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <None Include="Tizen.Bluetooth.nuspec" />\r
+    <None Include="Tizen.Bluetooth.Net45.project.json" />\r
+    <None Include="Tizen.Bluetooth.snk" />\r
+  </ItemGroup>\r
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />\r
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.\r
+       Other similar extension points exist, see Microsoft.Common.targets.\r
+  <Target Name="BeforeBuild">\r
+  </Target>\r
+  <Target Name="AfterBuild">\r
+  </Target>\r
+  -->\r
+</Project>
\ No newline at end of file
diff --git a/Tizen.Bluetooth/Tizen.Bluetooth.Net45.project.json b/Tizen.Bluetooth/Tizen.Bluetooth.Net45.project.json
new file mode 100644 (file)
index 0000000..1ec1af2
--- /dev/null
@@ -0,0 +1,11 @@
+{
+  "dependencies": {
+    "Tizen": "1.0.2"
+  },
+  "frameworks": {
+    "net45": {}
+  },
+  "runtimes": {
+    "win": {}
+  }
+}
diff --git a/Tizen.Bluetooth/Tizen.Bluetooth.csproj b/Tizen.Bluetooth/Tizen.Bluetooth.csproj
new file mode 100644 (file)
index 0000000..511cbd4
--- /dev/null
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <PropertyGroup>\r
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>\r
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>\r
+    <ProjectGuid>{3EE5842E-7004-43BC-825B-29FFDEC18D4E}</ProjectGuid>\r
+    <OutputType>Library</OutputType>\r
+    <AppDesignerFolder>Properties</AppDesignerFolder>\r
+    <RootNamespace>Tizen.Bluetooth</RootNamespace>\r
+    <AssemblyName>Tizen.Bluetooth</AssemblyName>\r
+    <FileAlignment>512</FileAlignment>\r
+  </PropertyGroup>\r
+  <PropertyGroup>\r
+    <TargetFrameworkIdentifier>.NETStandard</TargetFrameworkIdentifier>\r
+    <TargetFrameworkVersion>v1.3</TargetFrameworkVersion>\r
+    <NuGetTargetMoniker>.NETStandard,Version=v1.3</NuGetTargetMoniker>\r
+    <AddAdditionalExplicitAssemblyReferences>false</AddAdditionalExplicitAssemblyReferences>\r
+    <NoStdLib>true</NoStdLib>\r
+    <NoWarn>$(NoWarn);1701;1702</NoWarn>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">\r
+    <DebugSymbols>true</DebugSymbols>\r
+    <DebugType>full</DebugType>\r
+    <Optimize>false</Optimize>\r
+    <OutputPath>bin\Debug\</OutputPath>\r
+    <DefineConstants>DEBUG;TRACE</DefineConstants>\r
+    <ErrorReport>prompt</ErrorReport>\r
+    <WarningLevel>4</WarningLevel>\r
+    <Prefer32Bit>false</Prefer32Bit>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">\r
+    <DebugType>pdbonly</DebugType>\r
+    <Optimize>true</Optimize>\r
+    <OutputPath>bin\Release\</OutputPath>\r
+    <DefineConstants>TRACE</DefineConstants>\r
+    <ErrorReport>prompt</ErrorReport>\r
+    <WarningLevel>4</WarningLevel>\r
+    <Prefer32Bit>false</Prefer32Bit>\r
+  </PropertyGroup>\r
+  <PropertyGroup>\r
+    <SignAssembly>true</SignAssembly>\r
+  </PropertyGroup>\r
+  <PropertyGroup>\r
+    <AssemblyOriginatorKeyFile>Tizen.Bluetooth.snk</AssemblyOriginatorKeyFile>\r
+  </PropertyGroup>\r
+  <ItemGroup>\r
+    <Compile Include="Interop\Interop.Glib.cs" />\r
+    <Compile Include="Interop\Interop.Libc.cs" />\r
+    <Compile Include="Interop\Interop.Libraries.cs" />\r
+    <Compile Include="Interop\Interop.Bluetooth.cs" />\r
+    <Compile Include="Properties\AssemblyInfo.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothAdapter.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothAdapterImpl.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothAudio.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothAudioImpl.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothAvrcp.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothAvrcpImpl.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothData.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothDevice.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothEnumerations.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothError.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothEventArgs.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothGatt.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothGattImpl.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothHid.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothHidImpl.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothLeAdapter.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothLeAdapterImpl.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothProfile.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothServerSocket.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothSocket.cs" />\r
+    <Compile Include="Tizen.Bluetooth\BluetoothStructs.cs" />\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <None Include="Tizen.Bluetooth.nuspec" />\r
+    <None Include="Tizen.Bluetooth.project.json" />\r
+    <None Include="Tizen.Bluetooth.snk" />\r
+  </ItemGroup>\r
+  <Import Project="$(MSBuildExtensionsPath)\Tizen\Tizen.CSharp.GBS.targets" Condition="Exists('$(MSBuildExtensionsPath)\Tizen\Tizen.CSharp.GBS.targets')" />\r
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />\r
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.\r
+       Other similar extension points exist, see Microsoft.Common.targets.\r
+  <Target Name="BeforeBuild">\r
+  </Target>\r
+  <Target Name="AfterBuild">\r
+  </Target>\r
+  -->\r
+  <PropertyGroup>\r
+    <!-- https://github.com/dotnet/corefxlab/tree/master/samples/NetCoreSample and\r
+       https://docs.microsoft.com/en-us/dotnet/articles/core/tutorials/target-dotnetcore-with-msbuild\r
+    -->\r
+    <!-- We don't use any of MSBuild's resolution logic for resolving the framework, so just set these two\r
+       properties to any folder that exists to skip the GetReferenceAssemblyPaths task (not target) and\r
+       to prevent it from outputting a warning (MSB3644).\r
+    -->\r
+    <_TargetFrameworkDirectories>$(MSBuildThisFileDirectory)</_TargetFrameworkDirectories>\r
+    <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory)</_FullFrameworkReferenceAssemblyPaths>\r
+    <AutoUnifyAssemblyReferences>true</AutoUnifyAssemblyReferences>\r
+  </PropertyGroup>\r
+</Project>
\ No newline at end of file
diff --git a/Tizen.Bluetooth/Tizen.Bluetooth.nuspec b/Tizen.Bluetooth/Tizen.Bluetooth.nuspec
new file mode 100644 (file)
index 0000000..fd37dce
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0"?>
+<package>
+       <metadata>
+               <id>Tizen.Bluetooth</id>
+               <version>$version$</version>
+               <authors>Samsung Electronics</authors>
+               <requireLicenseAcceptance>false</requireLicenseAcceptance>
+               <licenseUrl>https://www.apache.org/licenses/LICENSE-2.0</licenseUrl>
+               <projectUrl>https://www.tizen.org/</projectUrl>
+               <iconUrl>https://developer.tizen.org/sites/default/files/images/tizen-pinwheel-on-light-rgb_64_64.png</iconUrl>
+               <copyright>© Samsung Electronics Co., Ltd All Rights Reserved</copyright>
+               <description>Provides the Bluetooth API for Tizen.Net</description>
+               <dependencies>
+                       <dependency id="Tizen" version="1.0.2" />
+               </dependencies>
+       </metadata>
+       <files>
+               <file src="bin/$Configuration$/Tizen.Bluetooth.dll" target="lib/netstandard1.3" />
+               <file src="bin/$Configuration$/Net45/Tizen.Bluetooth.dll" target="lib/net45" />
+       </files>
+</package>
diff --git a/Tizen.Bluetooth/Tizen.Bluetooth.project.json b/Tizen.Bluetooth/Tizen.Bluetooth.project.json
new file mode 100644 (file)
index 0000000..a4c6be0
--- /dev/null
@@ -0,0 +1,9 @@
+{
+  "dependencies": {
+    "NETStandard.Library": "1.6.0",
+    "Tizen": "1.0.2"
+  },
+  "frameworks": {
+    "netstandard1.3": {}
+  }
+}
\ No newline at end of file
diff --git a/Tizen.Bluetooth/Tizen.Bluetooth.snk b/Tizen.Bluetooth/Tizen.Bluetooth.snk
new file mode 100644 (file)
index 0000000..f3d151d
Binary files /dev/null and b/Tizen.Bluetooth/Tizen.Bluetooth.snk differ
diff --git a/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothAdapter.cs b/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothAdapter.cs
new file mode 100644 (file)
index 0000000..727bb46
--- /dev/null
@@ -0,0 +1,459 @@
+/*
+ * 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.Bluetooth
+{
+    /// <summary>
+    /// A class which is used to control a bluetooth adapter and get the list of bonded devices.<br>
+    /// The BluetoothAdapter class is used to discover neighbouring bluetooth devices.
+    /// </summary>
+    /// <privilege> http://tizen.org/privilege/bluetooth </privilege>
+    static public class BluetoothAdapter
+    {
+        /// <summary>
+        /// A property to check whether Bluetooth is enabled.
+        /// </summary>
+        static public bool IsBluetoothEnabled
+        {
+            get
+            {
+                return BluetoothAdapterImpl.Instance.IsBluetoothEnabled;
+            }
+        }
+
+        /// <summary>
+        /// The local adapter address.
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        static public string Address
+        {
+            get
+            {
+                if (IsBluetoothEnabled)
+                {
+                    return BluetoothAdapterImpl.Instance.Address;
+                }
+                else
+                {
+                    return null;
+                }
+            }
+        }
+
+        /// <summary>
+        /// The name of the local adapter.
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        static public string Name
+        {
+            get
+            {
+                if (IsBluetoothEnabled)
+                {
+                    return BluetoothAdapterImpl.Instance.Name;
+                }
+                else
+                {
+                    return null;
+                }
+            }
+            set
+            {
+                BluetoothAdapterImpl.Instance.Name = value;
+            }
+        }
+
+        /// <summary>
+        /// The visibility mode of the Bluetooth adapter.
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        static public VisibilityMode Visibility
+        {
+            get
+            {
+                if (IsBluetoothEnabled)
+                {
+                    return BluetoothAdapterImpl.Instance.Visibility;
+                }
+                else
+                {
+                    return VisibilityMode.NonDiscoverable;
+                }
+            }
+        }
+
+        /// <summary>
+        /// A property to check whether device discovery is in progress.
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        static public bool IsDiscoveryInProgress
+        {
+            get
+            {
+                if (IsBluetoothEnabled)
+                {
+                    return BluetoothAdapterImpl.Instance.IsDiscoveryInProgress;
+                }
+                else
+                {
+                    return false;
+                }
+            }
+        }
+
+        /// <summary>
+        /// The remaining time, in seconds, until the visibility mode is changed from TimeLimitedDiscoverable to NonDiscoverable.
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        static public int RemainingTimeAsVisible
+        {
+            get
+            {
+                if (IsBluetoothEnabled)
+                {
+                    return BluetoothAdapterImpl.Instance.RemainingTimeAsVisible;
+                }
+                else
+                {
+                    return 0;
+                }
+            }
+        }
+
+        /// <summary>
+        /// (event) StateChanged is raised when bluetooth adapter state is changed.
+        /// </summary>
+        static public event EventHandler<StateChangedEventArgs> StateChanged
+        {
+            add
+            {
+                BluetoothAdapterImpl.Instance.StateChanged += value;
+            }
+            remove
+            {
+                BluetoothAdapterImpl.Instance.StateChanged -= value;
+            }
+        }
+
+        /// <summary>
+        /// (event) NameChanged is raised when bluetooth adapter name is changed.
+        /// </summary>
+        static public event EventHandler<NameChangedEventArgs> NameChanged
+        {
+            add
+            {
+                BluetoothAdapterImpl.Instance.NameChanged += value;
+            }
+            remove
+            {
+                BluetoothAdapterImpl.Instance.NameChanged -= value;
+            }
+        }
+
+        /// <summary>
+        /// (event) VisibilityModeChanged is raised when bluetooth adapter visibility mode is changed.
+        /// </summary>
+        static public event EventHandler<VisibilityModeChangedEventArgs> VisibilityModeChanged
+        {
+            add
+            {
+                BluetoothAdapterImpl.Instance.VisibilityModeChanged += value;
+            }
+            remove
+            {
+                BluetoothAdapterImpl.Instance.VisibilityModeChanged -= value;
+            }
+        }
+
+        /// <summary>
+        /// (event) VisibilityDurationChanged is raised very second until the visibility mode is changed to NonDiscoverable.
+        /// </summary>
+        static public event EventHandler<VisibilityDurationChangedEventArgs> VisibilityDurationChanged
+        {
+            add
+            {
+                BluetoothAdapterImpl.Instance.VisibilityDurationChanged += value;
+            }
+            remove
+            {
+                BluetoothAdapterImpl.Instance.VisibilityDurationChanged -= value;
+            }
+        }
+
+        /// <summary>
+        /// (event) DiscoveryStateChanged is raised when the device discovery state is changed.
+        /// </summary>
+        static public event EventHandler<DiscoveryStateChangedEventArgs> DiscoveryStateChanged
+        {
+            add
+            {
+                BluetoothAdapterImpl.Instance.DiscoveryStateChanged += value;
+            }
+            remove
+            {
+                BluetoothAdapterImpl.Instance.DiscoveryStateChanged -= value;
+            }
+        }
+
+        /// <summary>
+        /// Event that is called when the LE Scan result is obtained.
+        /// </summary>
+        static public event EventHandler<AdapterLeScanResultChangedEventArgs> ScanResultChanged
+        {
+            add
+            {
+                BluetoothLeImplAdapter.Instance.AdapterLeScanResultChanged += value;
+            }
+            remove {
+                BluetoothLeImplAdapter.Instance.AdapterLeScanResultChanged -= value;
+            }
+        }
+
+        /// <summary>
+        /// Starts the device discovery process.
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled and device discovery can be stopped by StopDiscovery().
+        /// If this succeeds, DiscoveryStateChanged event will be invoked.
+        /// </remarks>
+        static public void StartDiscovery()
+        {
+            if (IsBluetoothEnabled)
+            {
+                BluetoothAdapterImpl.Instance.StartDiscovery();
+            }
+        }
+
+        /// <summary>
+        /// Stops the device discovery process.
+        /// </summary>
+        /// <remarks>
+        /// The device discovery must be in progress with StartDiscovery().
+        /// If this succeeds, DiscoveryStateChanged event will be invoked.
+        /// </remarks>
+        static public void StopDiscovery()
+        {
+            if (IsDiscoveryInProgress)
+            {
+                BluetoothAdapterImpl.Instance.StopDiscovery();
+            }
+        }
+
+        /// <summary>
+        /// Retrieves the device information of all bonded devices.
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        /// <returns> List of Bonded BluetoothDeviceInfo objects.</returns>
+        static public IEnumerable<BluetoothDevice> GetBondedDevices()
+        {
+            if (IsBluetoothEnabled)
+            {
+                return BluetoothAdapterImpl.Instance.GetBondedDevices();
+            }
+            else
+            {
+                return null;
+            }
+        }
+
+        /// <summary>
+        /// Gets the device information of a bonded device.
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        /// <returns> Information of bonded BluetoothDeviceInfo object.</returns>
+        static public BluetoothDevice GetBondedDevice(string address)
+        {
+            if (IsBluetoothEnabled)
+            {
+                return BluetoothAdapterImpl.Instance.GetBondedDevice(address);
+            }
+            else
+            {
+                return null;
+            }
+        }
+
+        /// <summary>
+        /// Checks whether the UUID of service is used or not.
+        /// </summary>
+        /// <returns><c>true</c> if the specified serviceUuid is used; otherwise, <c>false</c>.</returns>
+        /// <param name="serviceUuid">The UUID of Service.</param>
+        static public bool IsServiceUsed(string serviceUuid)
+        {
+            return BluetoothAdapterImpl.Instance.IsServiceUsed(serviceUuid);
+        }
+
+        /// <summary>
+        /// Gets the hash and randomizer value of local oob data object.
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        /// <returns>The BluetoothOobData object.</returns>
+        static public BluetoothOobData GetLocalOobData()
+        {
+            if (IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                return BluetoothAdapterImpl.Instance.GetLocalOobData();
+            }
+            else
+            {
+                return null;
+            }
+        }
+
+        /// <summary>
+        /// Sets the Hash and Randmoizer value of oob data into the remote device.
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        /// <param name="address">Remote Device address.</param>
+        /// <param name="oobData">BluetoothOobData object.</param>
+        static public void SetRemoteOobData(string address, BluetoothOobData oobData)
+        {
+            if (IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                BluetoothAdapterImpl.Instance.SetRemoteOobData(address, oobData);
+            }
+        }
+
+        /// <summary>
+        /// Removes the Hash and Randomizer value of oob data from the remote device.
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        /// <param name="address">Remote Device address.</param>
+        static public void RemoveRemoteOobData(string address)
+        {
+            if (IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                BluetoothAdapterImpl.Instance.RemoveRemoteOobData(address);
+            }
+        }
+
+        /// <summary>
+        /// Starts the Bluetooth Le scan operation to discover BLE devices
+        /// </summary>
+        /// <remarks>
+        /// Bluetooth must be enabled.
+        /// </remarks>the result of the operation StartLeScan
+        static public void StartLeScan()
+        {
+            if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                int ret = BluetoothLeImplAdapter.Instance.StartScan ();
+                if (ret != (int)BluetoothError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to in start the le scan operation, Error - " + (BluetoothError)ret);
+                    BluetoothErrorFactory.ThrowBluetoothException(ret);
+                }
+            }
+            else
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
+        }
+
+        /// <summary>
+        /// Stops the Bluetooth Le scan operation.
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>the result of the operation stopLescan
+        static public void StopLeScan()
+        {
+            if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                int ret = BluetoothLeImplAdapter.Instance.StopScan ();
+                if (ret != (int)BluetoothError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to stop the le scan operation, Error - " + (BluetoothError)ret);
+                    BluetoothErrorFactory.ThrowBluetoothException(ret);
+                }
+            }
+            else
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
+        }
+
+        /// <summary>
+        /// Returns BluetoothLeAdvertiser instance.
+        /// </summary>
+        /// <remarks>
+        /// The bluetooth must be enabled before calling this API.
+        /// </remarks>
+        /// <returns>The BluetoothLeAdvertiser instance.</returns>
+        static public BluetoothLeAdvertiser GetBluetoothLeAdvertiser()
+        {
+            return BluetoothLeAdvertiser.Instance;
+        }
+
+        /// <summary>
+        /// Registers a rfcomm server socket with a specific UUID.
+        /// </summary>
+        /// <remarks>
+        /// The bluetooth must be enabled before calling this API.
+        /// </remarks>
+        /// <returns>The BluetoothServerSocket instance.</returns>
+        /// <param name="serviceUuid">The UUID of service to provide.</param>
+        static public BluetoothServerSocket CreateServerSocket(string serviceUuid)
+        {
+            if (IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                return BluetoothAdapterImpl.Instance.CreateServerSocket (serviceUuid);
+            }
+            else
+            {
+                return null;
+            }
+        }
+
+        /// <summary>
+        /// Removes the rfcomm server socket which was created using CreateServerSocket().
+        /// </summary>
+        /// <remarks>
+        /// The socket must be created with CreateServerSocket(). ConnectionStateChanged event is raised after this API is called.
+        /// </remarks>
+        /// <param name="socket">The server socket instance which is created using CreateServerSocket().</param>
+        static public void DestroyServerSocket(BluetoothServerSocket socket)
+        {
+            if (IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                BluetoothAdapterImpl.Instance.DestroyServerSocket(socket);
+            }
+        }
+    }
+}
diff --git a/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothAdapterImpl.cs b/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothAdapterImpl.cs
new file mode 100644 (file)
index 0000000..92c4b0a
--- /dev/null
@@ -0,0 +1,636 @@
+/*
+ * 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;
+
+namespace Tizen.Network.Bluetooth
+{
+    static internal class Globals
+    {
+        internal const string LogTag = "Tizen.Network.Bluetooth";
+        internal static bool IsInitialize = false;
+        internal static bool IsAudioInitialize = false;
+        internal static bool IsHidInitialize = false;
+    }
+
+    internal partial class BluetoothAdapterImpl : IDisposable
+    {
+        private event EventHandler<StateChangedEventArgs> _stateChanged;
+        private event EventHandler<NameChangedEventArgs> _nameChanged;
+        private event EventHandler<VisibilityModeChangedEventArgs> _visibilityModeChanged;
+        private event EventHandler<VisibilityDurationChangedEventArgs> _visibilityDurationChanged;
+        private event EventHandler<DiscoveryStateChangedEventArgs> _discoveryStateChanged;
+
+        private Interop.Bluetooth.StateChangedCallback _stateChangedCallback;
+        private Interop.Bluetooth.NameChangedCallback _nameChangedCallback;
+        private Interop.Bluetooth.VisibilityModeChangedCallback _visibilityChangedCallback;
+        private Interop.Bluetooth.VisibilityDurationChangedCallback _visibilitydurationChangedCallback;
+        private Interop.Bluetooth.DiscoveryStateChangedCallback _discoveryStateChangedCallback;
+
+        private static readonly BluetoothAdapterImpl _instance = new BluetoothAdapterImpl();
+        private bool disposed = false;
+
+        internal event EventHandler<StateChangedEventArgs> StateChanged
+        {
+            add
+            {
+                if (_stateChanged == null)
+                {
+                    RegisterStateChangedEvent();
+                }
+                _stateChanged += value;
+            }
+            remove
+            {
+                _stateChanged -= value;
+                if (_stateChanged == null)
+                {
+                    UnregisterStateChangedEvent();
+                }
+            }
+        }
+
+        internal event EventHandler<NameChangedEventArgs> NameChanged
+        {
+            add
+            {
+                if (_nameChanged == null)
+                {
+                    RegisterNameChangedEvent();
+                }
+                _nameChanged += value;
+            }
+            remove
+            {
+                _nameChanged -= value;
+                if (_nameChanged == null)
+                {
+                    UnregisterNameChangedEvent();
+                }
+            }
+        }
+
+        internal event EventHandler<VisibilityModeChangedEventArgs> VisibilityModeChanged
+        {
+            add
+            {
+                if (_visibilityModeChanged == null)
+                {
+                    RegisterVisibilityChangedEvent();
+                }
+                _visibilityModeChanged += value;
+            }
+            remove
+            {
+                _visibilityModeChanged -= value;
+                if (_visibilityModeChanged == null)
+                {
+                    UnregisterVisibilityChangedEvent();
+                }
+            }
+        }
+
+        internal event EventHandler<VisibilityDurationChangedEventArgs> VisibilityDurationChanged
+        {
+            add
+            {
+                if (_visibilityDurationChanged == null)
+                {
+                    RegisterVisibilityDurationChangedEvent();
+                }
+                _visibilityDurationChanged += value;
+            }
+            remove
+            {
+                _visibilityDurationChanged -= value;
+                if (_visibilityDurationChanged == null)
+                {
+                    UnregisterVisibilityDurationChangedEvent();
+                }
+            }
+        }
+
+        internal event EventHandler<DiscoveryStateChangedEventArgs> DiscoveryStateChanged
+        {
+            add
+            {
+                if (_discoveryStateChanged == null)
+                {
+                    RegisterDiscoveryStateChangedEvent();
+                }
+                _discoveryStateChanged+= value;
+            }
+            remove
+            {
+                _discoveryStateChanged -= value;
+                if (_discoveryStateChanged == null)
+                {
+                    UnregisterDiscoveryStateChangedEvent();
+                }
+            }
+        }
+
+        private void RegisterStateChangedEvent()
+        {
+            _stateChangedCallback = (int result, int state, IntPtr userData) =>
+            {
+                if (_stateChanged != null)
+                {
+                    BluetoothState st = (BluetoothState)state;
+                    BluetoothError res = (BluetoothError)result;
+                    _stateChanged(null, new StateChangedEventArgs(res,st));
+                }
+            };
+            int ret = Interop.Bluetooth.SetStateChangedCallback(_stateChangedCallback, IntPtr.Zero);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to set state changed callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
+        private void UnregisterStateChangedEvent()
+        {
+            int ret = Interop.Bluetooth.UnsetStateChangedCallback();
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to unset state changed callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
+        private void RegisterNameChangedEvent()
+        {
+            _nameChangedCallback = (string deviceName, IntPtr userData) =>
+            {
+                if (_nameChanged != null)
+                {
+                    _nameChanged(null, new NameChangedEventArgs(deviceName));
+                }
+            };
+            int ret = Interop.Bluetooth.SetNameChangedCallback(_nameChangedCallback, IntPtr.Zero);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to set name changed callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
+        private void UnregisterNameChangedEvent()
+        {
+            int ret = Interop.Bluetooth.UnsetNameChangedCallback();
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to unset name changed callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
+        private void RegisterVisibilityChangedEvent()
+        {
+            _visibilityChangedCallback = (int result, int mode, IntPtr userData) =>
+            {
+                if (_visibilityModeChanged != null)
+                {
+                    VisibilityMode visibility = (VisibilityMode)mode;
+                    BluetoothError res = (BluetoothError)result;
+                    _visibilityModeChanged(null, new VisibilityModeChangedEventArgs(res,visibility));
+                }
+            };
+            int ret = Interop.Bluetooth.SetVisibilityModeChangedCallback(_visibilityChangedCallback, IntPtr.Zero);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to set visibility mode changed callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
+        private void UnregisterVisibilityChangedEvent()
+        {
+            int ret = Interop.Bluetooth.UnsetVisibilityModeChangedCallback();
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to unset visibility mode changed callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
+        private void RegisterVisibilityDurationChangedEvent()
+        {
+            _visibilitydurationChangedCallback = (int duration, IntPtr userData) =>
+            {
+                if (_visibilityDurationChanged != null)
+                {
+                    _visibilityDurationChanged(null, new VisibilityDurationChangedEventArgs(duration));
+                }
+            };
+            int ret = Interop.Bluetooth.SetVisibilityDurationChangedCallback(_visibilitydurationChangedCallback, IntPtr.Zero);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to set visibility duration changed callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
+        private void UnregisterVisibilityDurationChangedEvent()
+        {
+            int ret = Interop.Bluetooth.UnsetVisibilityDurationChangedCallback();
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to unset visiiblity duration changed callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
+        private void RegisterDiscoveryStateChangedEvent()
+        {
+            _discoveryStateChangedCallback = (int result, BluetoothDeviceDiscoveryState state, IntPtr deviceInfo, IntPtr userData) =>
+            {
+                Log.Info(Globals.LogTag, "Discovery state changed callback is called");
+                if (_discoveryStateChanged != null)
+                {
+                    BluetoothError res = (BluetoothError)result;
+                    switch(state)
+                    {
+                    case BluetoothDeviceDiscoveryState.Started:
+                        _discoveryStateChanged(null, new DiscoveryStateChangedEventArgs(res,state));
+                        break;
+                    case BluetoothDeviceDiscoveryState.Finished:
+                        {
+                            _discoveryStateChanged(null, new DiscoveryStateChangedEventArgs(res,state));
+                            break;
+                        }
+                    case BluetoothDeviceDiscoveryState.Found:
+                        {
+                            BluetoothDiscoveredDeviceStruct info = (BluetoothDiscoveredDeviceStruct)Marshal.PtrToStructure(deviceInfo, typeof(BluetoothDiscoveredDeviceStruct));
+                            _discoveryStateChanged(null, new DiscoveryStateChangedEventArgs(res,state,BluetoothUtils.ConvertStructToDiscoveredDevice(info)));
+                            break;
+                        }
+                    default:
+                        break;
+                    }
+                }
+            };
+            int ret = Interop.Bluetooth.SetDiscoveryStateChangedCallback(_discoveryStateChangedCallback, IntPtr.Zero);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to set discovery state changed callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
+        private void UnregisterDiscoveryStateChangedEvent()
+        {
+            int ret = Interop.Bluetooth.UnsetDiscoveryStateChangedCallback();
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to unset discovery state changed callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
+        internal bool IsBluetoothEnabled
+        {
+            get
+            {
+                BluetoothState active;
+                int ret = Interop.Bluetooth.GetState(out active);
+                if (ret != (int)BluetoothError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to get state, Error - " + (BluetoothError)ret);
+                }
+                if (active == BluetoothState.Enabled)
+                    return true;
+                else
+                    return false;
+            }
+        }
+        internal string Address
+        {
+            get
+            {
+                string address;
+                int ret = Interop.Bluetooth.GetAddress(out address);
+                if (ret != (int)BluetoothError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to get address, Error - " + (BluetoothError)ret);
+                    return "";
+                }
+                return address;
+            }
+        }
+
+        internal VisibilityMode Visibility
+        {
+            get
+            {
+                int visibilityMode;
+                int time;
+                int ret = Interop.Bluetooth.GetVisibility(out visibilityMode, out time);
+                if(ret != (int)BluetoothError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to get visibility mode, Error - " + (BluetoothError)ret);
+                    return VisibilityMode.NonDiscoverable;
+                }
+                return (VisibilityMode)visibilityMode;
+            }
+        }
+
+        internal bool IsDiscoveryInProgress
+        {
+            get
+            {
+                bool isDiscovering;
+                int ret = Interop.Bluetooth.IsDiscovering(out isDiscovering);
+                if(ret != (int)BluetoothError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to get discovery progress state, Error - " + (BluetoothError)ret);
+                }
+                return isDiscovering;
+            }
+        }
+
+        internal int RemainingTimeAsVisible
+        {
+            get
+            {
+                int duration = 0;
+                int visibilityMode;
+                int ret = Interop.Bluetooth.GetVisibility(out visibilityMode, out duration);
+                if ((ret != (int)BluetoothError.None) || ((VisibilityMode)visibilityMode != VisibilityMode.TimeLimitedDiscoverable))
+                {
+                    Log.Error(Globals.LogTag, "Failed to get remaining visible time, Error - " + (BluetoothError)ret);
+                }
+                return duration;
+            }
+        }
+
+        internal string Name
+        {
+            get
+            {
+                string name;
+                int ret = Interop.Bluetooth.GetName(out name);
+                if (ret != (int)BluetoothError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to get adapter name, Error - " + (BluetoothError)ret);
+                    return "";
+                }
+                return name;
+            }
+            set
+            {
+                int ret = Interop.Bluetooth.SetName(value.ToString());
+                if (ret != (int)BluetoothError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to set adapter name, Error - " + (BluetoothError)ret);
+                    BluetoothErrorFactory.ThrowBluetoothException(ret);
+                }
+            }
+        }
+
+        internal void StartDiscovery()
+        {
+            int ret = Interop.Bluetooth.StartDiscovery();
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to start discovery, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+        }
+
+        internal void StopDiscovery()
+        {
+            int ret = Interop.Bluetooth.StopDiscovery();
+            if(ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to stop discovery, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+        }
+
+        internal IEnumerable<BluetoothDevice> GetBondedDevices()
+        {
+            List<BluetoothDevice> deviceList = new List<BluetoothDevice>();
+            Interop.Bluetooth.BondedDeviceCallback callback = (ref BluetoothDeviceStruct deviceInfo, IntPtr userData) =>
+            {
+                Log.Info(Globals.LogTag, "Bonded devices cb is called");
+                if(!deviceInfo.Equals(null))
+                {
+                    deviceList.Add(BluetoothUtils.ConvertStructToDeviceClass(deviceInfo));
+                }
+                return true;
+            };
+            int ret = Interop.Bluetooth.GetBondedDevices(callback, IntPtr.Zero);
+            if(ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to get bonded devices, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+            return deviceList;
+        }
+
+        internal BluetoothDevice GetBondedDevice(string address)
+        {
+            IntPtr deviceInfo;
+            int ret = Interop.Bluetooth.GetBondedDeviceByAddress(address, out deviceInfo);
+            if(ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to get bonded device by address, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+            BluetoothDeviceStruct device = (BluetoothDeviceStruct)Marshal.PtrToStructure(deviceInfo, typeof(BluetoothDeviceStruct));
+
+            return BluetoothUtils.ConvertStructToDeviceClass(device);
+        }
+
+        internal bool IsServiceUsed(string serviceUuid)
+        {
+            bool isUsed;
+            int ret = Interop.Bluetooth.IsServiceUsed(serviceUuid, out isUsed);
+            if(ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to check the usage of service, Error - " + (BluetoothError)ret);
+            }
+            return isUsed;
+        }
+
+        internal BluetoothOobData GetLocalOobData()
+        {
+            BluetoothOobData oobData = new BluetoothOobData();
+            IntPtr hash;
+            IntPtr randomizer;
+            int hashLength;
+            int randomizerLength;
+            int ret = Interop.Bluetooth.GetOobData(out hash, out randomizer, out hashLength, out randomizerLength);
+            if(ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to get the local oob data, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+
+            byte[] hashArr = new byte[hashLength];
+            Marshal.Copy(hash, hashArr, 0, hashLength);
+            byte[] randomizerArr = new byte[randomizerLength];
+            Marshal.Copy(randomizer, randomizerArr, 0, randomizerLength);
+
+            oobData.HashValue = hashArr;
+            oobData.RandomizerValue = randomizerArr;
+            return oobData;
+        }
+
+        internal void SetRemoteOobData(string deviceAddress, BluetoothOobData oobData)
+        {
+            byte[] hash = oobData.HashValue;
+            byte[] randomizer = oobData.RandomizerValue;
+            int hashLength = hash.Length;
+            int randomizerLength = randomizer.Length;
+
+            IntPtr hashPtr = Marshal.AllocHGlobal(hashLength);
+            Marshal.Copy(hash, 0, hashPtr, hashLength);
+            IntPtr randomizerPtr = Marshal.AllocHGlobal(randomizerLength);
+            Marshal.Copy(randomizer, 0, randomizerPtr, randomizerLength);
+
+            int ret = Interop.Bluetooth.SetOobData(deviceAddress, hashPtr, randomizerPtr, hashLength, randomizerLength);
+            if(ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to set the remote oob data, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+        }
+
+        internal void RemoveRemoteOobData(string deviceAddress)
+        {
+            int ret = Interop.Bluetooth.RemoveOobData(deviceAddress);
+            if(ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to remove the remote oob data, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+        }
+
+        internal BluetoothServerSocket CreateServerSocket(string serviceUuid)
+        {
+            int socketFd;
+            int ret = Interop.Bluetooth.CreateServerSocket(serviceUuid, out socketFd);
+            if(ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to create server socket, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+            Log.Info (Globals.LogTag, "Created socketfd: "+ socketFd);
+            return new BluetoothServerSocket(socketFd);
+        }
+
+        internal void DestroyServerSocket(BluetoothServerSocket socket)
+        {
+            int ret = Interop.Bluetooth.DestroyServerSocket(socket.socketFd);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to destroy socket, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+        }
+
+        internal static BluetoothAdapterImpl Instance
+        {
+            get
+            {
+                return _instance;
+            }
+        }
+
+        private BluetoothAdapterImpl()
+        {
+            initialize();
+        }
+
+        ~BluetoothAdapterImpl()
+        {
+            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 initialize()
+        {
+            int ret = Interop.Bluetooth.Initialize();
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error (Globals.LogTag, "Failed to initialize bluetooth, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException (ret);
+            }
+            else
+            {
+                Globals.IsInitialize = true;
+            }
+        }
+
+        private void deinitialize()
+        {
+            int ret = Interop.Bluetooth.Deinitialize();
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error (Globals.LogTag, "Failed to deinitialize bluetooth, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException (ret);
+            }
+            else
+            {
+                Globals.IsInitialize = false;
+            }
+        }
+
+        private void RemoveAllRegisteredEvent()
+        {
+            //unregister all remaining events when this object is released.
+            if (_stateChanged != null)
+            {
+                UnregisterStateChangedEvent();
+            }
+
+            if (_nameChanged != null)
+            {
+                UnregisterNameChangedEvent();
+            }
+
+            if (_visibilityDurationChanged != null)
+            {
+                UnregisterVisibilityDurationChangedEvent();
+            }
+
+            if (_visibilityModeChanged != null)
+            {
+                UnregisterVisibilityChangedEvent();
+            }
+
+            if (_discoveryStateChanged != null)
+            {
+                UnregisterDiscoveryStateChangedEvent();
+            }
+        }
+    }
+}
diff --git a/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothAudio.cs b/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothAudio.cs
new file mode 100644 (file)
index 0000000..d66a401
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * 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.Bluetooth
+{
+    /// <summary>
+    /// A class which is used to handle the connection with other Bluetooth audio devices
+    /// like headset, hands-free and headphone.
+    /// </summary>
+    /// <privilege> http://tizen.org/privilege/bluetooth </privilege>
+    public class BluetoothAudio : BluetoothProfile
+    {
+        internal BluetoothAudio()
+        {
+        }
+
+        /// <summary>
+        /// (event) AudioConnectionStateChanged is called when audio connection state is changed.
+        /// </summary>
+        public event EventHandler<AudioConnectionStateChangedEventArgs> AudioConnectionStateChanged
+        {
+            add
+            {
+                BluetoothAudioImpl.Instance.AudioConnectionStateChanged += value;
+            }
+            remove
+            {
+                BluetoothAudioImpl.Instance.AudioConnectionStateChanged -= value;
+            }
+        }
+
+        /// <summary>
+        /// Connect the remote device with the given audio profile.
+        /// </summary>
+        /// <remarks>
+        /// The device must be bonded with remote device by CreateBond().If connection request succeeds, AudioConnectionStateChanged event will be invoked.
+        /// If audio profile type is All and this request succeeds, then AudioConnectionStateChanged event will be called twice when HspHfp <br>
+        /// and AdvancedAudioDistribution is connected.
+        /// </remarks>
+        /// <param name="profileType">Type of audio profile.</param>
+        public void Connect(BluetoothAudioProfileType profileType)
+        {
+            if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                int ret = BluetoothAudioImpl.Instance.Connect(RemoteAddress, profileType);
+                if (ret != (int)BluetoothError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to Connect - " + (BluetoothError)ret);
+                    BluetoothErrorFactory.ThrowBluetoothException(ret);
+                }
+            }
+            else
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
+        }
+
+        /// <summary>
+        /// Disconnects the remote device with the given audio profile.
+        /// </summary>
+        /// <remarks>
+        /// The device must be connected by Connect().If the disconnection request succeeds, AudioConnectionStateChanged event will be invoked.
+        /// If audio profile type is All and this request succeeds, then AudioConnectionStateChanged event will be called twice when HspHfp <br>
+        /// and AdvancedAudioDistribution is disconnected.
+        /// </remarks>
+        /// <param name="type">Type of audio profile.</param>
+        public void Disconnect(BluetoothAudioProfileType type)
+        {
+            if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                int ret = BluetoothAudioImpl.Instance.Disconnect(RemoteAddress, type);
+                if (ret != (int)BluetoothError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to Disconnect - " + (BluetoothError)ret);
+                    BluetoothErrorFactory.ThrowBluetoothException(ret);
+                }
+            }
+            else
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
+        }
+    }
+}
diff --git a/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothAudioImpl.cs b/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothAudioImpl.cs
new file mode 100644 (file)
index 0000000..eeb1977
--- /dev/null
@@ -0,0 +1,174 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+namespace Tizen.Network.Bluetooth
+{
+    internal class BluetoothAudioImpl : IDisposable
+    {
+        private event EventHandler<AudioConnectionStateChangedEventArgs> _audioConnectionChanged;
+        private Interop.Bluetooth.AudioConnectionStateChangedCallback _audioConnectionChangedCallback;
+
+        private static readonly BluetoothAudioImpl _instance = new BluetoothAudioImpl();
+        private bool disposed = false;
+
+        internal event EventHandler<AudioConnectionStateChangedEventArgs> AudioConnectionStateChanged
+        {
+            add
+            {
+                if (_audioConnectionChanged == null)
+                {
+                    RegisterAudioConnectionChangedEvent();
+                }
+                _audioConnectionChanged += value;
+            }
+            remove
+            {
+                _audioConnectionChanged -= value;
+                if (_audioConnectionChanged == null)
+                {
+                    UnregisterAudioConnectionChangedEvent();
+                }
+            }
+        }
+
+        private void RegisterAudioConnectionChangedEvent()
+        {
+            _audioConnectionChangedCallback = (int result, bool connected, string deviceAddress, int profileType, IntPtr userData) =>
+            {
+                if (_audioConnectionChanged != null)
+                {
+                    _audioConnectionChanged(null, new AudioConnectionStateChangedEventArgs(result, connected, deviceAddress, (BluetoothAudioProfileType)profileType));
+                }
+            };
+            int ret = Interop.Bluetooth.SetAudioConnectionStateChangedCallback(_audioConnectionChangedCallback, IntPtr.Zero);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to set audio connection changed callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
+        private void UnregisterAudioConnectionChangedEvent()
+        {
+            int ret = Interop.Bluetooth.UnsetAudioConnectionStateChangedCallback();
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to unset audio connection changed callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
+        internal int Connect(string deviceAddress, BluetoothAudioProfileType type)
+        {
+            int ret = Interop.Bluetooth.Connect(deviceAddress, (int)type);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to connect device with the given profile type, Error - " + (BluetoothError)ret);
+            }
+            return ret;
+        }
+
+        internal int Disconnect(string deviceAddress, BluetoothAudioProfileType type)
+        {
+            int ret = Interop.Bluetooth.Disconnect(deviceAddress, (int)type);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to disconnect device with the given profile type, Error - " + (BluetoothError)ret);
+            }
+            return ret;
+        }
+
+        internal static BluetoothAudioImpl Instance
+        {
+            get
+            {
+                return _instance;
+            }
+        }
+
+        private BluetoothAudioImpl ()
+        {
+            Log.Info(Globals.LogTag, "Initializing audio");
+            initialize();
+        }
+
+        ~BluetoothAudioImpl()
+        {
+            Dispose(false);
+        }
+
+        public void Dispose()
+        {
+            Dispose(true);
+            GC.SuppressFinalize(this);
+        }
+
+        private void Dispose(bool disposing)
+        {
+            if (disposed)
+                return;
+
+            if (disposing)
+            {
+                // Free managed objects.
+            }
+            //Free unmanaged objects
+            deinitialize();
+            RemoveAllRegisteredEvent();
+            disposed = true;
+        }
+
+        private void initialize()
+        {
+            if (Globals.IsInitialize)
+            {
+                int ret = Interop.Bluetooth.InitializeAudio ();
+                if (ret != (int)BluetoothError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to initialize bluetoothaudio, Error - " + (BluetoothError)ret);
+                    Globals.IsAudioInitialize = false;
+                    BluetoothErrorFactory.ThrowBluetoothException (ret);
+                }
+                else
+                {
+                    Globals.IsAudioInitialize = true;
+                }
+            }
+            else
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotInitialized);
+            }
+        }
+
+        private void deinitialize()
+        {
+            if (Globals.IsAudioInitialize) {
+                int ret = Interop.Bluetooth.DeinitializeAudio ();
+                if (ret != (int)BluetoothError.None) {
+                    Log.Error (Globals.LogTag, "Failed to deinitialize bluetoothaudio, Error - " + (BluetoothError)ret);
+                }
+            }
+        }
+
+        private void RemoveAllRegisteredEvent()
+        {
+            if (_audioConnectionChanged != null)
+            {
+                UnregisterAudioConnectionChangedEvent();
+            }
+        }
+    }
+}
diff --git a/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothAvrcp.cs b/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothAvrcp.cs
new file mode 100644 (file)
index 0000000..f83ad82
--- /dev/null
@@ -0,0 +1,240 @@
+/*
+ * 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.Bluetooth
+{
+    /// <summary>
+    /// A class which is used to notify changes of the target device(e.g.media player) to the control device(e.g.headset).
+    /// </summary>
+    /// <privilege> http://tizen.org/privilege/bluetooth </privilege>
+    public class BluetoothAvrcp : BluetoothProfile
+    {
+        internal BluetoothAvrcp()
+        {
+        }
+
+        /// <summary>
+        /// (event) TargetConnectionStateChanged is invoked when the connection state is changed.
+        /// </summary>
+        public event EventHandler<TargetConnectionStateChangedEventArgs> TargetConnectionStateChanged
+        {
+            add
+            {
+                BluetoothAvrcpImpl.Instance.TargetConnectionStateChanged += value;
+            }
+            remove
+            {
+                BluetoothAvrcpImpl.Instance.TargetConnectionStateChanged -= value;
+            }
+        }
+
+        /// <summary>
+        /// (event) EqualizerStateChanged is invoked when the equalizer state is changed by the remote control device.
+        /// </summary>
+        public event EventHandler<EqualizerStateChangedEventArgs> EqualizerStateChanged
+        {
+            add
+            {
+                BluetoothAvrcpImpl.Instance.EqualizerStateChanged += value;
+            }
+            remove
+            {
+                BluetoothAvrcpImpl.Instance.EqualizerStateChanged -= value;
+            }
+        }
+
+        /// <summary>
+        /// (event) RepeatModeChanged is invoked when the repeat mode is changed by the remote control device.
+        /// </summary>
+        public event EventHandler<RepeatModeChangedEventArgs> RepeatModeChanged
+        {
+            add
+            {
+                BluetoothAvrcpImpl.Instance.RepeatModeChanged += value;
+            }
+            remove
+            {
+                BluetoothAvrcpImpl.Instance.RepeatModeChanged -= value;
+            }
+        }
+
+        /// <summary>
+        /// (event) ShuffleModeChanged is invoked when the shuffle mode is changed by the remote control device.
+        /// </summary>
+        public event EventHandler<ShuffleModeChangedeventArgs> ShuffleModeChanged
+        {
+            add
+            {
+                BluetoothAvrcpImpl.Instance.ShuffleModeChanged += value;
+            }
+            remove
+            {
+                BluetoothAvrcpImpl.Instance.ShuffleModeChanged -= value;
+            }
+        }
+
+        /// <summary>
+        /// (event) ScanModeChanged is invoked when the scan mode is changed by the remote control device.
+        /// </summary>
+        public event EventHandler<ScanModeChangedEventArgs> ScanModeChanged
+        {
+            add
+            {
+                BluetoothAvrcpImpl.Instance.ScanModeChanged += value;
+            }
+            remove
+            {
+                BluetoothAvrcpImpl.Instance.ScanModeChanged -= value;
+            }
+        }
+
+        /// <summary>
+        /// Notifies the equalize state to the remote device.
+        /// </summary>
+        /// <remarks>
+        /// The remote device must be connected.
+        /// </remarks>
+        /// <param name="state">Equalizer state.</param>
+        public void NotifyEqualizerState(EqualizerState state)
+        {
+            if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                BluetoothAvrcpImpl.Instance.NotifyEqualizeState(state);
+            }
+            else
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
+        }
+
+        /// <summary>
+        /// Notifies the repeat mode to the remote device.
+        /// </summary>
+        /// <remarks>
+        /// The remote device must be connected.
+        /// </remarks>
+        /// <param name="mode">Repeat mode.</param>
+        public void NotifyRepeatMode(RepeatMode mode)
+        {
+            if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                BluetoothAvrcpImpl.Instance.NotifyRepeatMode(mode);
+            }
+            else
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
+        }
+
+        /// <summary>
+        /// Notifies the shuffle mode to the remote device.
+        /// </summary>
+        /// <remarks>
+        /// The remote device must be connected.
+        /// </remarks>
+        /// <param name="mode">Shuffle mode.</param>
+        public void NotifyShuffleMode(ShuffleMode mode)
+        {
+            if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                BluetoothAvrcpImpl.Instance.NotifyShuffleMode(mode);
+            }
+            else
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
+        }
+
+        /// <summary>
+        /// Notifies the scan mode to the remote device.
+        /// </summary>
+        /// <remarks>
+        /// The remote device must be connected.
+        /// </remarks>
+        /// <param name="mode">Scan mode.</param>
+        public void NotifyScanMode(ScanMode mode)
+        {
+            if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                BluetoothAvrcpImpl.Instance.NotifyScanMode(mode);
+            }
+            else
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
+        }
+
+        /// <summary>
+        /// Notifies the player state to the remote device.
+        /// </summary>
+        /// <remarks>
+        /// The remote device must be connected.
+        /// </remarks>
+        /// <param name="state">Player state.</param>
+        public void NotifyPlayerState(PlayerState state)
+        {
+            if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                BluetoothAvrcpImpl.Instance.NotifyPlayerState(state);
+            }
+            else
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
+        }
+
+        /// <summary>
+        /// Notifies the current position of song to the remote device.
+        /// </summary>
+        /// <remarks>
+        /// The remote device must be connected.
+        /// </remarks>
+        /// <param name="position">Current position in milliseconds.</param>
+        public void NotifyCurrentPosition(uint position)
+        {
+            if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                BluetoothAvrcpImpl.Instance.NotifyCurrentPosition(position);
+            }
+            else
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
+        }
+
+        /// <summary>
+        /// Notifies the track to the remote device.
+        /// </summary>
+        /// <remarks>
+        /// The remote device must be connected.
+        /// </remarks>
+        /// <param name="trackData">Data of the track.</param>
+        public void NotifyTrack(Track trackData)
+        {
+            if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                BluetoothAvrcpImpl.Instance.NotifyTrack(trackData);
+            }
+            else
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
+        }
+    }
+}
+
diff --git a/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothAvrcpImpl.cs b/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothAvrcpImpl.cs
new file mode 100644 (file)
index 0000000..b9606bd
--- /dev/null
@@ -0,0 +1,419 @@
+/*
+ * 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.Bluetooth
+{
+    internal class BluetoothAvrcpImpl : IDisposable
+    {
+        private event EventHandler<TargetConnectionStateChangedEventArgs> _targetConnectionChanged;
+        private event EventHandler<EqualizerStateChangedEventArgs> _equalizerStateChanged;
+        private event EventHandler<RepeatModeChangedEventArgs> _repeatModeChanged;
+        private event EventHandler<ScanModeChangedEventArgs> _scanModeChanged;
+        private event EventHandler<ShuffleModeChangedeventArgs> _shuffleModeChanged;
+
+        private Interop.Bluetooth.TargetConnectionStateChangedCallback _targetConnectionChangedCallback;
+        private Interop.Bluetooth.EqualizerStateChangedCallback _equalizerStateChangedCallback;
+        private Interop.Bluetooth.RepeatModeChangedCallback _repeatModeChangedCallback;
+        private Interop.Bluetooth.ShuffleModeChangedCallback _shuffleModeChangedCallback;
+        private Interop.Bluetooth.ScanModeChangedCallback _scanModeChangedCallback;
+
+        private static BluetoothAvrcpImpl _instance = new BluetoothAvrcpImpl();
+        private bool disposed = false;
+
+        internal event EventHandler<TargetConnectionStateChangedEventArgs> TargetConnectionStateChanged
+        {
+            add
+            {
+                _targetConnectionChanged += value;
+            }
+            remove
+            {
+                _targetConnectionChanged -= value;
+            }
+        }
+
+        internal event EventHandler<EqualizerStateChangedEventArgs> EqualizerStateChanged
+        {
+            add
+            {
+                if (_equalizerStateChanged == null)
+                {
+                    RegisterEqualizerStateChangedEvent();
+                }
+                _equalizerStateChanged += value;
+            }
+            remove
+            {
+                _equalizerStateChanged -= value;
+                if (_equalizerStateChanged == null)
+                {
+                    UnregisterEqualizerStateChangedEvent();
+                }
+            }
+        }
+
+        internal event EventHandler<RepeatModeChangedEventArgs> RepeatModeChanged
+        {
+            add
+            {
+                if (_repeatModeChanged == null)
+                {
+                    RegisterRepeatModeChangedEvent();
+                }
+                _repeatModeChanged += value;
+            }
+            remove
+            {
+                _repeatModeChanged -= value;
+                if (_repeatModeChanged == null)
+                {
+                    UnregisterRepeatModeChangedEvent();
+                }
+            }
+        }
+
+        internal event EventHandler<ShuffleModeChangedeventArgs> ShuffleModeChanged
+        {
+            add
+            {
+                if (_shuffleModeChanged == null)
+                {
+                    RegisterShuffleModeChangedEvent();
+                }
+                _shuffleModeChanged += value;
+            }
+            remove
+            {
+                _shuffleModeChanged -= value;
+                if (_shuffleModeChanged == null)
+                {
+                    UnregisterShuffleModeChangedEvent();
+                }
+            }
+        }
+
+        internal event EventHandler<ScanModeChangedEventArgs> ScanModeChanged
+        {
+            add
+            {
+                if (_scanModeChanged == null)
+                {
+                    RegisterScanModeChangedEvent();
+                }
+                _scanModeChanged += value;
+            }
+            remove
+            {
+                _scanModeChanged -= value;
+                if (_scanModeChanged == null)
+                {
+                    UnregisterScanModeChangedEvent();
+                }
+            }
+        }
+
+        private void RegisterEqualizerStateChangedEvent()
+        {
+            _equalizerStateChangedCallback = (int equalizer, IntPtr userData) =>
+            {
+                if (_equalizerStateChanged != null)
+                {
+                    EqualizerState state = (EqualizerState) equalizer;
+                    _equalizerStateChanged(null, new EqualizerStateChangedEventArgs(state));
+                }
+            };
+            int ret = Interop.Bluetooth.SetEqualizerStateChangedCallback(_equalizerStateChangedCallback, IntPtr.Zero);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to set equalizer state changed callback, Error - " + (BluetoothError)ret);
+            }
+        }
+        private void UnregisterEqualizerStateChangedEvent()
+        {
+            int ret = Interop.Bluetooth.UnsetEqualizerStateChangedCallback();
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to unset equalizer state changed callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
+        private void RegisterRepeatModeChangedEvent()
+        {
+            _repeatModeChangedCallback = (int repeat, IntPtr userData) =>
+            {
+                if (_repeatModeChanged != null)
+                {
+                    RepeatMode mode = (RepeatMode)repeat;
+                    _repeatModeChanged(null, new RepeatModeChangedEventArgs(mode));
+                }
+            };
+            int ret = Interop.Bluetooth.SetRepeatModeChangedCallback(_repeatModeChangedCallback, IntPtr.Zero);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to set repeat mode changed callback, Error - " + (BluetoothError)ret);
+            }
+        }
+        private void UnregisterRepeatModeChangedEvent()
+        {
+            int ret = Interop.Bluetooth.UnsetRepeatModeChangedCallback();
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to unset repeat mode changed callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
+        private void RegisterShuffleModeChangedEvent()
+        {
+            Log.Debug (Globals.LogTag, "inside RegisterShuffleModeChangedEvent");
+            _shuffleModeChangedCallback = (int shuffle, IntPtr userData) =>
+            {
+                Log.Debug (Globals.LogTag, "inside RegisterShuffleModeChangedEvent callback");
+                if (_shuffleModeChanged != null)
+                {
+                    ShuffleMode mode = (ShuffleMode) shuffle;
+                    _shuffleModeChanged(null, new ShuffleModeChangedeventArgs(mode));
+                }
+            };
+            int ret = Interop.Bluetooth.SetShuffleModeChangedCallback(_shuffleModeChangedCallback, IntPtr.Zero);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Debug (Globals.LogTag, "failed inside RegisterShuffleModeChangedEvent");
+                Log.Error(Globals.LogTag, "Failed to set shuffle mode changed callback, Error - " + (BluetoothError)ret);
+            }
+        }
+        private void UnregisterShuffleModeChangedEvent()
+        {
+            int ret = Interop.Bluetooth.UnsetShuffleModeChangedCallback();
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to unset shuffle mode changed callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
+        private void RegisterScanModeChangedEvent()
+        {
+            _scanModeChangedCallback = (int scan, IntPtr userData) =>
+            {
+                if (_scanModeChanged != null)
+                {
+                    ScanMode mode = (ScanMode) scan;
+                    _scanModeChanged(null, new ScanModeChangedEventArgs(mode));
+                }
+            };
+            int ret = Interop.Bluetooth.SetScanModeChangedCallback(_scanModeChangedCallback, IntPtr.Zero);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to set scan mode changed callback, Error - " + (BluetoothError)ret);
+            }
+        }
+        private void UnregisterScanModeChangedEvent()
+        {
+            int ret = Interop.Bluetooth.UnsetScanModeChangedCallback();
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to unset scan mode changed callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
+        private void targetInitialize()
+        {
+            if (Globals.IsInitialize)
+            {
+                _targetConnectionChangedCallback = (bool connected, string deviceAddress, IntPtr userData) =>
+                {
+                    if (_targetConnectionChanged != null)
+                    {
+                        _targetConnectionChanged(null, new TargetConnectionStateChangedEventArgs(connected, deviceAddress));
+                    }
+                };
+
+                int ret = Interop.Bluetooth.InitializeAvrcp(_targetConnectionChangedCallback, IntPtr.Zero);
+                if (ret != (int)BluetoothError.None)
+                {
+                    Log.Error (Globals.LogTag, "Failed to initialize bluetooth avrcp, Error - " + (BluetoothError)ret);
+                    BluetoothErrorFactory.ThrowBluetoothException(ret);
+                }
+                else
+                {
+                    Globals.IsAudioInitialize = true;
+                }
+            }
+            else
+            {
+                Log.Error(Globals.LogTag, "Failed to initialize Avrcp, BT not initialized");
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotInitialized);
+            }
+        }
+
+        private void targetDeinitialize()
+        {
+            if (Globals.IsAudioInitialize)
+            {
+                int ret = Interop.Bluetooth.DeinitializeAvrcp();
+                if (ret != (int)BluetoothError.None)
+                {
+                    Log.Error (Globals.LogTag, "Failed to deinitialize bluetooth avrcp, Error - " + (BluetoothError)ret);
+                    BluetoothErrorFactory.ThrowBluetoothException(ret);
+                }
+                else
+                {
+                    Globals.IsAudioInitialize = false;
+                }
+            }
+        }
+
+        internal void NotifyEqualizeState(EqualizerState state)
+        {
+            int ret = Interop.Bluetooth.NotifyEqualizerState((int)state);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to notify equalizer state to remote device, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+        }
+
+        internal void NotifyRepeatMode(RepeatMode repeat)
+        {
+            int ret = Interop.Bluetooth.NotifyRepeatMode((int)repeat);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to notify repeat mode to remote device, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+        }
+
+        internal void NotifyShuffleMode(ShuffleMode shuffle)
+        {
+            int ret = Interop.Bluetooth.NotifyShuffleMode((int)shuffle);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to notify shuffle mode to remote device, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+        }
+
+        internal void NotifyScanMode(ScanMode scan)
+        {
+            int ret = Interop.Bluetooth.NotifyScanMode((int)scan);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to notify scan mode to remote device, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+        }
+
+        internal void NotifyPlayerState(PlayerState state)
+        {
+            int ret = Interop.Bluetooth.NotifyPlayerState((int)state);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to notify player state to remote device, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+        }
+
+        internal void NotifyCurrentPosition(uint position)
+        {
+            int ret = Interop.Bluetooth.NotifyCurrentPosition(position);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to notify position to remote device, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+        }
+
+        internal void NotifyTrack(Track trackData)
+        {
+            string title = trackData.Title;
+            string artist = trackData.Artist;
+            string album = trackData.Album;
+            string genre = trackData.Genre;
+            uint trackNum = trackData.TrackNum;
+            uint totalTracks = trackData.TotalTracks;
+            uint duration = trackData.Duration;
+
+            int ret = Interop.Bluetooth.NotifyTrack(title, artist, album, genre, trackNum, totalTracks, duration);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to notify track data to the remote device, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+        }
+
+        internal static BluetoothAvrcpImpl Instance
+        {
+            get
+            {
+                return _instance;
+            }
+        }
+
+        private BluetoothAvrcpImpl()
+        {
+            targetInitialize();
+        }
+
+        ~BluetoothAvrcpImpl()
+        {
+            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
+            targetDeinitialize();
+            RemoveAllRegisteredEvent();
+            disposed = true;
+        }
+
+        private void RemoveAllRegisteredEvent()
+        {
+            //unregister all remaining events when this object is released.
+            if (_equalizerStateChanged != null)
+            {
+                UnregisterEqualizerStateChangedEvent();
+            }
+            if (_repeatModeChanged != null)
+            {
+                UnregisterRepeatModeChangedEvent();
+            }
+            if (_scanModeChanged != null)
+            {
+                UnregisterScanModeChangedEvent();
+            }
+            if (_shuffleModeChanged != null)
+            {
+                UnregisterShuffleModeChangedEvent();
+            }
+        }
+    }
+}
+
diff --git a/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothData.cs b/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothData.cs
new file mode 100644 (file)
index 0000000..f219bc5
--- /dev/null
@@ -0,0 +1,535 @@
+/*
+ * 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.Generic;
+using System.Collections.Concurrent;
+using System.Collections.ObjectModel;
+using System.Collections.Specialized;
+
+namespace Tizen.Network.Bluetooth
+{
+    /// <summary>
+    /// A class to handle device class type and service.
+    /// </summary>
+    public class BluetoothClass
+    {
+        internal BluetoothMajorDeviceClassType MajorType;
+        internal BluetoothMinorDeviceClassType MinorType;
+        internal int Mask;
+
+        internal BluetoothClass()
+        {
+        }
+
+        /// <summary>
+        /// Type of the major device class.
+        /// </summary>
+        public BluetoothMajorDeviceClassType MajorDeviceClassType
+        {
+            get
+            {
+                return MajorType;
+            }
+        }
+        /// <summary>
+        /// Type of the minor device class.
+        /// </summary>
+        public BluetoothMinorDeviceClassType MinorDeviceClassType
+        {
+            get
+            {
+                return MinorType;
+            }
+        }
+        /// <summary>
+        /// Major service class mask.
+        /// </summary>
+        public int MajorServiceClassMask
+        {
+            get
+            {
+                return Mask;
+            }
+        }
+    }
+
+    /// <summary>
+    /// A class containing the information of Bluetooth oob data.
+    /// </summary>
+    public class BluetoothOobData
+    {
+        /// <summary>
+        /// Default Constructor.Initializes an object of BluetoothOobData
+        /// </summary>
+        public BluetoothOobData()
+        {
+        }
+
+        /// <summary>
+        /// Hash value.
+        /// </summary>
+        public byte[] HashValue
+        {
+            get;
+            set;
+        }
+        /// <summary>
+        /// Randomizer value.
+        /// </summary>
+        public byte[] RandomizerValue
+        {
+            get;
+            set;
+        }
+    }
+
+    /// <summary>
+    /// A class containing the information of Bluetooth device sdp data.
+    /// </summary>
+    public class BluetoothDeviceSdpData
+    {
+        internal string Address;
+        internal Collection<string> Uuid;
+
+        internal BluetoothDeviceSdpData()
+        {
+        }
+
+        /// <summary>
+        /// The device address.
+        /// </summary>
+        public string DeviceAddress
+        {
+            get
+            {
+                return Address;
+            }
+        }
+        /// <summary>
+        /// The service UUID.
+        /// </summary>
+        public IEnumerable<string> ServiceUuid
+        {
+            get
+            {
+                return Uuid;
+            }
+        }
+    }
+
+    /// <summary>
+    /// A class containing the information of Bluetooth device connection data.
+    /// </summary>
+    public class BluetoothDeviceConnectionData
+    {
+        internal string RemoteAddress;
+        internal BluetoothConnectionLinkType Link;
+        internal BluetoothDisconnectReason Reason;
+
+        internal BluetoothDeviceConnectionData()
+        {
+        }
+
+        /// <summary>
+        /// The device address.
+        /// </summary>
+        public string Address
+        {
+            get
+            {
+                return RemoteAddress;
+            }
+        }
+        /// <summary>
+        /// The type of the connection link.
+        /// </summary>
+        public BluetoothConnectionLinkType LinkType
+        {
+            get
+            {
+                return Link;
+            }
+        }
+        /// <summary>
+        /// The disconnect reason.
+        /// </summary>
+        public BluetoothDisconnectReason DisconnectReason
+        {
+            get
+            {
+                return Reason;
+            }
+        }
+    }
+
+    /// <summary>
+    /// A class containing the information of track data.
+    /// </summary>
+    public class Track
+    {
+        /// <summary>
+        /// Default Constructor.Initializes an object of Track
+        /// </summary>
+        public Track()
+        {
+        }
+
+        /// <summary>
+        /// Title of track.
+        /// </summary>
+        public string Title
+        {
+            get;
+            set;
+        }
+        /// <summary>
+        /// Artist of track.
+        /// </summary>
+        public string Artist
+        {
+            get;
+            set;
+        }
+        /// <summary>
+        /// Album of track.
+        /// </summary>
+        public string Album
+        {
+            get;
+            set;
+        }
+        /// <summary>
+        /// Genre of track.
+        /// </summary>
+        public string Genre
+        {
+            get;
+            set;
+        }
+        /// <summary>
+        /// Track number.
+        /// </summary>
+        public uint TrackNum
+        {
+            get;
+            set;
+        }
+        /// <summary>
+        /// Number of all tracks.
+        /// </summary>
+        public uint TotalTracks
+        {
+            get;
+            set;
+        }
+        /// <summary>
+        /// Duration of track in milliseconds.
+        /// </summary>
+        public uint Duration
+        {
+            get;
+            set;
+        }
+    }
+
+    /// </summary>
+    [StructLayout(LayoutKind.Sequential)]
+    internal struct BluetoothLeScanDataStruct
+    {
+        [MarshalAsAttribute(UnmanagedType.LPStr)]
+        internal string RemoteAddress;
+
+        internal BluetoothLeDeviceAddressType AddressType;
+
+        internal int Rssi;
+
+        internal int AdvDataLength;
+
+        internal IntPtr AdvData;
+
+        internal int ScanDataLength;
+
+        internal IntPtr ScanData;
+    }
+
+    /// <summary>
+    /// A class containing the information of Manufacturer data.
+    /// </summary>
+    public class ManufacturerData
+    {
+        /// <summary>
+        /// Default Constructor.Initializes an object of ManufacturerData
+        /// </summary>
+        public ManufacturerData()
+        {
+        }
+
+        /// <summary>
+        /// The manufacturer id.
+        /// </summary>
+        public int Id
+        {
+            get;
+            set;
+        }
+        /// <summary>
+        /// The length of the manufacturer data.
+        /// </summary>
+        public int DataLength
+        {
+            get;
+            set;
+        }
+        /// <summary>
+        /// The manufacturer data.
+        /// </summary>
+        public byte[] Data
+        {
+            get;
+            set;
+        }
+    }
+
+    internal class BluetoothLeScanData
+    {
+        internal string RemoteAddress
+        {
+            get;
+            set;
+        }
+        internal BluetoothLeDeviceAddressType AddressType
+        {
+            get;
+            set;
+        }
+        internal int Rssi
+        {
+            get;
+            set;
+        }
+        internal int AdvDataLength
+        {
+            get;
+            set;
+        }
+        internal byte[] AdvData
+        {
+            get;
+            set;
+        }
+        internal int ScanDataLength
+        {
+            get;
+            set;
+        }
+        internal byte[] ScanData
+        {
+            get;
+            set;
+        }
+    }
+
+    internal struct BluetoothLeServiceDataStruct
+    {
+        /// <summary>
+        /// Bluetooth Le service uuid.
+        /// </summary>
+        [MarshalAs(UnmanagedType.ByValTStr, SizeConst=16)]
+        internal string ServiceUuid;
+        /// <summary>
+        /// Bluetooth Le service data
+        /// </summary>
+        [MarshalAs(UnmanagedType.LPStr)]
+        internal string ServiceData;
+
+        internal int ServiceDataLength;
+    }
+
+    /// <summary>
+    /// A class containing the information of Bluetooth service data.
+    /// </summary>
+    public class BluetoothServiceData
+    {
+        /// <summary>
+        /// Default Constructor.Initializes an object of BluetoothServiceData
+        /// </summary>
+        public BluetoothServiceData()
+        {
+        }
+
+        /// <summary>
+        /// The Uuid of service.
+        /// </summary>
+        public string Uuid
+        {
+            get;
+            set;
+        }
+        /// <summary>
+        /// The data length of the service data.
+        /// </summary>
+        public int DataLength
+        {
+            get;
+            set;
+        }
+        /// <summary>
+        /// The service data.
+        /// </summary>
+        public byte[] Data
+        {
+            get;
+            set;
+        }
+    }
+
+    /// <summary>
+    /// A class containing the service data information.
+    /// </summary>
+    public class BluetoothLeServiceData
+    {
+        internal string Uuid;
+        internal string Data;
+        internal int Length;
+
+        internal BluetoothLeServiceData()
+        {
+        }
+
+        /// <summary>
+        /// Bluetooth Le service uuid.
+        /// </summary>
+        public string ServiceUuid
+        {
+            get
+            {
+                return Uuid;
+            }
+        }
+        /// <summary>
+        /// Bluetooth Le service data
+        /// </summary>
+        public string ServiceData
+        {
+            get
+            {
+                return Data;
+            }
+        }
+        /// <summary>
+        /// The length of the service data.
+        /// </summary>
+        public int ServiceDataLength
+        {
+            get
+            {
+                return Length;
+            }
+        }
+    }
+
+    /// <summary>
+    /// A class containing the information of Socket data.
+    /// </summary>
+    public class SocketData
+    {
+        internal string RecvData;
+        internal int Size;
+        internal int Fd;
+
+        internal SocketData()
+        {
+        }
+
+        /// <summary>
+        /// The socket fd.
+        /// </summary>
+        public int SocketFd
+        {
+            get
+            {
+                return Fd;
+            }
+        }
+        /// <summary>
+        /// The length of the received data.
+        /// </summary>
+        public int DataSize
+        {
+            get
+            {
+                return Size;
+            }
+        }
+        /// <summary>
+        /// The received data.
+        /// </summary>
+        public string Data
+        {
+            get
+            {
+                return RecvData;
+            }
+        }
+    }
+
+    /// <summary>
+    /// A class containing the information of Socket connection.
+    /// </summary>
+    public class SocketConnection
+    {
+        internal string Uuid;
+        internal string RemoteAddress;
+        internal int Fd;
+
+        internal SocketConnection()
+        {
+        }
+
+        /// <summary>
+        /// The connected socket fd.
+        /// </summary>
+        public int SocketFd
+        {
+            get
+            {
+                return Fd;
+            }
+        }
+        /// <summary>
+        /// The remote device address.
+        /// </summary>
+        public string Address
+        {
+            get
+            {
+                return RemoteAddress;
+            }
+        }
+        /// <summary>
+        /// The service Uuid.
+        /// </summary>
+        public string ServiceUuid
+        {
+            get
+            {
+                return Uuid;
+            }
+        }
+    }
+}
diff --git a/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothDevice.cs b/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothDevice.cs
new file mode 100644 (file)
index 0000000..f589744
--- /dev/null
@@ -0,0 +1,673 @@
+/*
+ * 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.Bluetooth
+{
+    /// <summary>
+    /// A class which is used to handle the connection with other devices and set authorization of other devices.<br>
+    /// The BluetoothDevice class is used to search for services available on remote devices.
+    /// </summary>
+    /// <privilege> http://tizen.org/privilege/bluetooth </privilege>
+    public class BluetoothDevice
+    {
+        private event EventHandler<BondCreatedEventArgs> _bondCreated;
+        private event EventHandler<BondDestroyedEventArgs> _bondDestroyed;
+        private event EventHandler<AuthorizationChangedEventArgs> _authorizationChanged;
+        private event EventHandler<ServiceSearchedEventArgs> _serviceSearched;
+        private event EventHandler<DeviceConnectionStateChangedEventArgs> _connectionChanged;
+
+        private Interop.Bluetooth.BondCreatedCallback _bondCreatedCallback;
+        private Interop.Bluetooth.BondDestroyedCallback _bondDestroyedCallback;
+        private Interop.Bluetooth.AuthorizationChangedCallback _authorizationChangedCallback;
+        private Interop.Bluetooth.ServiceSearchedCallback _serviceSearchedCallback;
+        private Interop.Bluetooth.DeviceConnectionStateChangedCallback _connectionChangedCallback;
+
+        internal string RemoteDeviceAddress;
+        internal string RemoteDeviceName;
+        internal int RemoteDeviceRssi;
+        internal BluetoothClass RemoteDeviceClass;
+        internal Collection<string> RemoteDeviceService;
+        internal int RemoteDeviceCount;
+        internal bool RemotePaired;
+        internal bool RemoteAuthorized;
+        internal bool RemoteConnected;
+        internal BluetoothAppearanceType RemoteAppearance;
+        internal int RemoteManufLength;
+        internal string RemoteManufData;
+
+        internal BluetoothDevice()
+        {
+        }
+
+        /// <summary>
+        /// Address of device.
+        /// </summary>
+        public string Address
+        {
+            get
+            {
+                return RemoteDeviceAddress;
+            }
+        }
+        /// <summary>
+        /// Name of device.
+        /// </summary>
+        public string Name
+        {
+            get
+            {
+                return RemoteDeviceName;
+            }
+        }
+        /// <summary>
+        /// Strength indicator of received signal of device.
+        /// </summary>
+        public int Rssi
+        {
+            get
+            {
+                return RemoteDeviceRssi;
+            }
+        }
+        /// <summary>
+        /// Class of device.
+        /// </summary>
+        public BluetoothClass Class
+        {
+            get
+            {
+                return RemoteDeviceClass;
+            }
+        }
+        /// <summary>
+        /// Service UUID list of device.
+        /// </summary>
+        public IEnumerable<string> ServiceUuidList
+        {
+            get
+            {
+                return RemoteDeviceService;
+            }
+        }
+        /// <summary>
+        /// The number of services.
+        /// </summary>
+        public int ServiceCount
+        {
+            get
+            {
+                return RemoteDeviceCount;
+            }
+        }
+        /// <summary>
+        /// The paired state of device.
+        /// </summary>
+        public bool IsPaired
+        {
+            get
+            {
+                return RemotePaired;
+            }
+        }
+        /// <summary>
+        /// The connection state of device.
+        /// </summary>
+        public bool IsConnected
+        {
+            get
+            {
+                return RemoteConnected;
+            }
+        }
+        /// <summary>
+        /// The authorization state of device.
+        /// </summary>
+        public bool IsAuthorized
+        {
+            get
+            {
+                return RemoteAuthorized;
+            }
+        }
+        /// <summary>
+        /// Bluetooth Appearance.
+        /// </summary>
+        public BluetoothAppearanceType AppearanceType
+        {
+            get
+            {
+                return RemoteAppearance;
+            }
+        }
+
+        /// <summary>
+        /// The length of manufacturer data.
+        /// </summary>
+        public int ManufacturerDataLength
+        {
+            get
+            {
+                return RemoteManufLength;
+            }
+        }
+        /// <summary>
+        /// The manufacturer data.
+        /// </summary>
+        public string ManufacturerData
+        {
+            get
+            {
+                return RemoteManufData;
+            }
+        }
+
+        /// <summary>
+        /// (event) BondCreated is raised when process of creating bond is finished.
+        /// </summary>
+        public event EventHandler<BondCreatedEventArgs> BondCreated
+        {
+            add
+            {
+                if (_bondCreated == null)
+                {
+                    RegisterBondCreatedEvent();
+                }
+                _bondCreated += value;
+            }
+            remove
+            {
+                _bondCreated -= value;
+                if (_bondCreated == null)
+                {
+                    UnregisterBondCreatedEvent();
+                }
+            }
+        }
+
+        /// <summary>
+        /// (event) BondDestroyed is raised when the bond is destroyed.
+        /// </summary>
+        public event EventHandler<BondDestroyedEventArgs> BondDestroyed
+        {
+            add
+            {
+                if (_bondDestroyed == null)
+                {
+                    RegisterBondDestroyedEvent();
+                }
+                _bondDestroyed += value;
+            }
+            remove
+            {
+                _bondDestroyed -= value;
+                if (_bondDestroyed == null)
+                {
+                    UnregisterBondDestroyedEvent();
+                }
+            }
+        }
+
+        /// <summary>
+        /// (event) AuthorizationChanged is raised when the authorization of device is changed.
+        /// </summary>
+        public event EventHandler<AuthorizationChangedEventArgs> AuthorizationChanged
+        {
+            add
+            {
+                if (_authorizationChanged == null)
+                {
+                    RegisterAuthorizationChangedEvent();
+                }
+                _authorizationChanged += value;
+            }
+            remove
+            {
+                _authorizationChanged -= value;
+                if (_authorizationChanged == null)
+                {
+                    UnregisterAuthorizationChangedEvent();
+                }
+            }
+        }
+
+        /// <summary>
+        /// (event) ServiceSearched is raised when the process of service searched is finished.
+        /// </summary>
+        public event EventHandler<ServiceSearchedEventArgs> ServiceSearched
+        {
+            add
+            {
+                if (_serviceSearched == null)
+                {
+                    RegisterServiceSearchedEvent();
+                }
+                _serviceSearched += value;
+            }
+            remove
+            {
+                _serviceSearched -= value;
+                if (_serviceSearched == null)
+                {
+                    UnregisterServiceSearchedEvent();
+                }
+            }
+        }
+
+        /// <summary>
+        /// (event) ConnectionStateChanged is raised when the connection state is changed.
+        /// </summary>
+        public event EventHandler<DeviceConnectionStateChangedEventArgs> ConnectionStateChanged
+        {
+            add
+            {
+                if (_connectionChanged == null)
+                {
+                    RegisterConnectionChangedEvent();
+                }
+                _connectionChanged += value;
+            }
+            remove
+            {
+                _connectionChanged -= value;
+                if (_connectionChanged == null)
+                {
+                    UnregisterConnectionChangedEvent();
+                }
+            }
+        }
+
+        private void RegisterBondCreatedEvent()
+        {
+            _bondCreatedCallback = (int result, ref BluetoothDeviceStruct device, IntPtr userData) =>
+            {
+                if (_bondCreated != null)
+                {
+                    BluetoothError res = (BluetoothError)result;
+                    _bondCreated(null, new BondCreatedEventArgs(res, BluetoothUtils.ConvertStructToDeviceClass(device)));
+                }
+            };
+            int ret = Interop.Bluetooth.SetBondCreatedCallback(_bondCreatedCallback, IntPtr.Zero);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to set bond created callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
+        private void UnregisterBondCreatedEvent()
+        {
+            int ret = Interop.Bluetooth.UnsetBondCreatedCallback();
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to unset bond created callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
+        private void RegisterBondDestroyedEvent()
+        {
+            _bondDestroyedCallback = (int result, string deviceAddress, IntPtr userData) =>
+            {
+                if (_bondDestroyed != null)
+                {
+                    BluetoothError res = (BluetoothError)result;
+                    _bondDestroyed(null, new BondDestroyedEventArgs(res, deviceAddress));
+                }
+            };
+            int ret = Interop.Bluetooth.SetBondDestroyedCallback(_bondDestroyedCallback, IntPtr.Zero);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to set bond destroyed callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
+        private void UnregisterBondDestroyedEvent()
+        {
+            int ret = Interop.Bluetooth.UnsetBondDestroyedCallback();
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to unset bond destroyed callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
+        private void RegisterServiceSearchedEvent()
+        {
+            _serviceSearchedCallback = (int result, ref BluetoothDeviceSdpStruct sdp, IntPtr userData) =>
+            {
+                Log.Info(Globals.LogTag, "Servicesearched cb is called");
+                if (_serviceSearched != null)
+                {
+                    BluetoothError res = (BluetoothError)result;
+                    _serviceSearched(null, new ServiceSearchedEventArgs(res, BluetoothUtils.ConvertStructToSdpData(sdp)));
+                }
+            };
+            int ret = Interop.Bluetooth.SetServiceSearchedCallback(_serviceSearchedCallback, IntPtr.Zero);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to set service searched callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
+        private void UnregisterServiceSearchedEvent()
+        {
+            int ret = Interop.Bluetooth.UnsetServiceSearchedCallback();
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to unset service searched callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
+        private void RegisterAuthorizationChangedEvent()
+        {
+            _authorizationChangedCallback = (int authorization, string deviceAddress, IntPtr userData) =>
+            {
+                Log.Info(Globals.LogTag, "Authorization changed cb is called");
+                if (_authorizationChanged != null)
+                {
+                    BluetoothAuthorizationType auth = (BluetoothAuthorizationType)authorization;
+                    _authorizationChanged(null, new AuthorizationChangedEventArgs(auth, deviceAddress));
+                }
+            };
+            int ret = Interop.Bluetooth.SetAuthorizationChangedCallback(_authorizationChangedCallback, IntPtr.Zero);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to set authroization changed callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
+        private void UnregisterAuthorizationChangedEvent()
+        {
+            int ret = Interop.Bluetooth.UnsetAuthorizationChangedCallback();
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to unset authroization changed callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
+        private void RegisterConnectionChangedEvent()
+        {
+            _connectionChangedCallback = (bool connected, ref BluetoothDeviceConnectionStruct device, IntPtr userData) =>
+            {
+                Log.Info(Globals.LogTag, "Connection state changed cb is called");
+                if (_connectionChanged != null)
+                {
+                    _connectionChanged(null, new DeviceConnectionStateChangedEventArgs(connected, BluetoothUtils.ConvertStructToConnectionData(device)));
+                }
+            };
+
+            int ret = Interop.Bluetooth.SetConnectionStateChangedCallback(_connectionChangedCallback, IntPtr.Zero);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to set connection state changed callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
+        private void UnregisterConnectionChangedEvent()
+        {
+            int ret = Interop.Bluetooth.UnsetConnectionStateChangedCallback();
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to unset connection state changed callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
+        /// <summary>
+        /// Creates a bond with remote Bluetooth device.
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled and remote device must be discoverable by StartDiscovery().The bond can be destroyed by DestroyBond().
+        /// The bonding request can be cancelled by CancelBonding().If this succeeds, BondCreated event will be invoked.
+        /// </remarks>
+        public void CreateBond()
+        {
+            if (BluetoothAdapter.IsBluetoothEnabled)
+            {
+                int ret = Interop.Bluetooth.CreateBond(RemoteDeviceAddress);
+                if (ret != (int)BluetoothError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to create bond, Error - " + (BluetoothError)ret);
+                    BluetoothErrorFactory.ThrowBluetoothException(ret);
+                }
+            }
+        }
+
+        /// <summary>
+        /// Cancels the bonding process.
+        /// </summary>
+        /// <remarks>
+        /// Bonding must be in progress by CreateBond().
+        /// </remarks>
+        public void CancelBonding()
+        {
+            int ret = Interop.Bluetooth.CancelBonding();
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to cancel bonding process, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+        }
+
+        /// <summary>
+        /// Destroys the bond.
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled and the bond must be created by CreateBond().
+        /// If this succeeds, BondDestroyed event will be invoked.
+        /// </remarks>
+        public void DestroyBond()
+        {
+            if (BluetoothAdapter.IsBluetoothEnabled)
+            {
+                int ret = Interop.Bluetooth.DestroyBond(RemoteDeviceAddress);
+                if (ret != (int)BluetoothError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to destroy bond, Error - " + (BluetoothError)ret);
+                    BluetoothErrorFactory.ThrowBluetoothException(ret);
+                }
+            }
+        }
+
+        /// <summary>
+        /// Sets an alias for the bonded device.
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled and the bond must be created by CreateBond().
+        /// </remarks>
+        /// <param name="aliasName">Alias name of remote device.</param>
+        public void SetAlias(string aliasName)
+        {
+            if (BluetoothAdapter.IsBluetoothEnabled)
+            {
+                int ret = Interop.Bluetooth.SetAlias(RemoteDeviceAddress, aliasName);
+                if (ret != (int)BluetoothError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to set alias name, Error - " + (BluetoothError)ret);
+                    BluetoothErrorFactory.ThrowBluetoothException(ret);
+                }
+            }
+        }
+
+        /// <summary>
+        /// Sets the authorization of a bonded device.
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled and the bond must be created by CreateBond().
+        /// If this succeeds, AuthorizationChanged event will be invoked.
+        /// </remarks>
+        /// <param name="authorizationState">Authorization state.</param>
+        public void SetAuthorization(BluetoothAuthorizationType authorizationState)
+        {
+            if (BluetoothAdapter.IsBluetoothEnabled)
+            {
+                int ret = Interop.Bluetooth.SetAuthorization(RemoteDeviceAddress, (int)authorizationState);
+                if (ret != (int)BluetoothError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to set authroization state, Error - " + (BluetoothError)ret);
+                    BluetoothErrorFactory.ThrowBluetoothException(ret);
+                }
+            }
+        }
+
+        /// <summary>
+        /// Gets the mask from UUID.
+        /// </summary>
+        /// <returns>The service mask list converted from the given UUID list.</returns>
+        /// <param name="uuids">Uuid list of the device.</param>
+        public BluetoothServiceClassType GetMaskFromUuid(string[] uuids)
+        {
+            BluetoothServiceClassType serviceMask;
+
+            int ret = Interop.Bluetooth.GetMaskFromUuid(uuids, uuids.Length, out serviceMask);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to get service mask, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+            return serviceMask;
+        }
+
+        /// <summary>
+        /// Starts the search for services supported by the specified device.
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled and remote device must be discoverable by StartDiscovery().The bond must be created by CreateBond().
+        /// If this succeeds, ServiceSearched will be invoked.
+        /// </remarks>
+        public void StartServiceSearch()
+        {
+            Log.Info(Globals.LogTag, "startservicesearch entry");
+            if (BluetoothAdapter.IsBluetoothEnabled)
+            {
+                int ret = Interop.Bluetooth.StartServiceSearch(RemoteDeviceAddress);
+                if (ret != (int)BluetoothError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to start service search, Error - " + (BluetoothError)ret);
+                    BluetoothErrorFactory.ThrowBluetoothException(ret);
+                }
+            }
+        }
+
+        /// <summary>
+        /// Gets the connected profiles.
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        /// <returns>The connected Bluetooth profiles.</returns>
+        public IEnumerable<BluetoothProfileType> GetConnectedProfiles()
+        {
+            if (BluetoothAdapter.IsBluetoothEnabled)
+            {
+                List<BluetoothProfileType> profileList = new List<BluetoothProfileType>();
+                Interop.Bluetooth.ConnectedProfileCallback callback = (int profile, IntPtr userData) =>
+                {
+                    if (!profile.Equals(null))
+                    {
+                        profileList.Add((BluetoothProfileType)profile);
+                    }
+                    return true;
+                };
+                int ret = Interop.Bluetooth.GetConnectedProfiles(RemoteDeviceAddress, callback, IntPtr.Zero);
+                if (ret != (int)BluetoothError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to get connected profiles, Error - " + (BluetoothError)ret);
+                    BluetoothErrorFactory.ThrowBluetoothException(ret);
+                }
+                return profileList;
+            }
+            else
+            {
+                return null;
+            }
+        }
+
+        /// <summary>
+        /// Determines if profile is connected to the specified remote device.
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        /// <returns><c>true</c> if profile is connected; otherwise, <c>false</c>.</returns>
+        /// <param name="profileType">Bluetooth Profile type.</param>
+        public bool IsProfileConnected(BluetoothProfileType profileType)
+        {
+            if (BluetoothAdapter.IsBluetoothEnabled)
+            {
+                bool isConnected;
+                int ret = Interop.Bluetooth.IsProfileConnected(RemoteDeviceAddress, (int)profileType, out isConnected);
+                if (ret != (int)BluetoothError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to get profile connected state, Error - " + (BluetoothError)ret);
+                }
+                return isConnected;
+            }
+            else
+            {
+                return false;
+            }
+        }
+
+        /// <summary>
+        /// Returns the instance of Bluetooth profile type.
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        public T GetProfile<T>() where T : BluetoothProfile
+        {
+            /*
+             * FIXME: Find a proper way for dynamic allocation.
+             */
+            T profile = null;
+            String type = typeof(T).ToString();
+            if (type.Equals("Tizen.Network.Bluetooth.BluetoothAudio"))
+            {
+                BluetoothAudio audio = new BluetoothAudio();
+                profile = (audio as T);
+            }
+            else if (type.Equals("Tizen.Network.Bluetooth.BluetoothAvrcp"))
+            {
+                BluetoothAvrcp avrcp = new BluetoothAvrcp();
+                profile = (avrcp as T);
+            }
+            else if (type.Equals("Tizen.Network.Bluetooth.BluetoothHid"))
+            {
+                BluetoothHid hid = new BluetoothHid();
+                profile = (hid as T);
+            }
+            profile.RemoteAddress = RemoteDeviceAddress;
+            return profile;
+        }
+
+        /// <summary>
+        /// Creates the client socket.
+        /// </summary>
+        /// <returns>The IBluetoothClientSocket instance.</returns>
+        /// <param name="serviceUuid">The UUID of service.</param>
+        public IBluetoothClientSocket CreateSocket(string serviceUuid)
+        {
+            BluetoothSocket clientSocket = new BluetoothSocket();
+            clientSocket.remoteAddress = this.Address;
+            clientSocket.serviceUuid = serviceUuid;
+            return (IBluetoothClientSocket)clientSocket;
+        }
+    }
+}
diff --git a/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothEnumerations.cs b/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothEnumerations.cs
new file mode 100644 (file)
index 0000000..6f4f107
--- /dev/null
@@ -0,0 +1,1187 @@
+/*
+ * 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.Bluetooth
+{
+    /// <summary>
+    /// Enumeration for Bluetooth state.
+    /// </summary>
+    public enum BluetoothState
+    {
+        /// <summary>
+        /// Disabled state.
+        /// </summary>
+        Disabled = 0,
+        /// <summary>
+        /// Enabled state.
+        /// </summary>
+        Enabled
+    }
+
+    /// <summary>
+    /// Enumeration for Bluetooth errors.
+    /// </summary>
+    public enum BluetoothError
+    {
+        /// <summary>
+        /// Successful
+        /// </summary>
+        None = ErrorCode.None,
+        /// <summary>
+        /// Operation cancelled
+        /// </summary>
+        Cancelled = ErrorCode.Canceled,
+        /// <summary>
+        /// Invalid parameter
+        /// </summary>
+        InvalidParameter = ErrorCode.InvalidParameter,
+        /// <summary>
+        /// Out of memory
+        /// </summary>
+        OutOfMemory = ErrorCode.OutOfMemory,
+        /// <summary>
+        /// Device or resource busy
+        /// </summary>
+        ResourceBusy = ErrorCode.ResourceBusy,
+        /// <summary>
+        /// Timeout error
+        /// </summary>
+        TimedOut = ErrorCode.TimedOut,
+        /// <summary>
+        /// Operation now in progress
+        /// </summary>
+        NowInProgress = ErrorCode.NowInProgress,
+        /// <summary>
+        /// Bluetooth is Not Supported
+        /// </summary>
+        NotSupported = ErrorCode.NotSupported,
+        /// <summary>
+        /// Permission denied
+        /// </summary>
+        PermissionDenied = ErrorCode.PermissionDenied,
+        /// <summary>
+        /// Quota exceeded
+        /// </summary>
+        QuotaExceeded = ErrorCode.QuotaExceeded,
+        /// <summary>
+        /// No data available
+        /// </summary>
+        NoData = ErrorCode.NoData,
+        /// <summary>
+        /// Local adapter not initialized
+        /// </summary>
+        NotInitialized = -0x01C00000 | 0x0101,
+        /// <summary>
+        /// Local adapter not enabled
+        /// </summary>
+        NotEnabled = -0x01C00000 | 0x0102,
+        /// <summary>
+        /// Operation already done
+        /// </summary>
+        AlreadyDone = -0x01C00000 | 0x0103,
+        /// <summary>
+        /// Operation failed
+        /// </summary>
+        OperationFailed = -0x01C00000 | 0x0104,
+        /// <summary>
+        /// Operation not in progress
+        /// </summary>
+        NotInProgress = -0x01C00000 | 0x0105,
+        /// <summary>
+        /// Remote device not bonded
+        /// </summary>
+        RemoteDeviceNotBonded = -0x01C00000 | 0x0106,
+        /// <summary>
+        /// Authentication rejected
+        /// </summary>
+        AuthRejected = -0x01C00000 | 0x0107,
+        /// <summary>
+        /// Authentication failed
+        /// </summary>
+        AuthFailed = -0x01C00000 | 0x0108,
+        /// <summary>
+        /// Remote device not found
+        /// </summary>
+        RemoteDeviceNotFound = -0x01C00000 | 0x0109,
+        /// <summary>
+        /// Service search failed
+        /// </summary>
+        ServiceSearchFailed = -0x01C00000 | 0x010A,
+        /// <summary>
+        /// Remote device is not connected
+        /// </summary>
+        RemoteDeviceNotConnected = -0x01C00000 | 0x010B,
+        /// <summary>
+        /// Resource temporarily unavailable
+        /// </summary>
+        ResourceUnavailable = -0x01C00000 | 0x010C,
+        /// <summary>
+        /// Service Not Found
+        /// </summary>
+        ServiceNotFound = -0x01C00000 | 0x010D
+    }
+
+    /// <summary>
+    /// Enumeration for Bluetooth visibility mode.
+    /// </summary>
+    public enum VisibilityMode
+    {
+        /// <summary>
+        /// Non discoverable mode.
+        /// </summary>
+        NonDiscoverable = 0,
+        /// <summary>
+        /// Discoverable mode.
+        /// </summary>
+        Discoverable = 1,
+        /// <summary>
+        /// Discoverable mode with limited time.
+        /// </summary>
+        TimeLimitedDiscoverable = 2
+    }
+
+    /// <summary>
+    /// Enumeration for Bluetooth major device class type.
+    /// </summary>
+    public enum BluetoothMajorDeviceClassType
+    {
+        /// <summary>
+        /// Miscellaneous major class type.
+        /// </summary>
+        Misc = 0x00,
+        /// <summary>
+        /// Computer major class type.
+        /// </summary>
+        Computer = 0x01,
+        /// <summary>
+        /// Phone major class type.
+        /// </summary>
+        Phone = 0x02,
+        /// <summary>
+        /// LAN/Network access point major class type.
+        /// </summary>
+        LanNetworkAccessPoint = 0x03,
+        /// <summary>
+        /// Audio/Video major class type.
+        /// </summary>
+        AudioVideo = 0x04,
+        /// <summary>
+        /// Peripheral major class type.
+        /// </summary>
+        Peripheral = 0x05,
+        /// <summary>
+        /// Imaging major class type.
+        /// </summary>
+        Imaging = 0x06,
+        /// <summary>
+        /// Wearable major class type.
+        /// </summary>
+        Wearable = 0x07,
+        /// <summary>
+        /// Toy major class type.
+        /// </summary>
+        Toy = 0x08,
+        /// <summary>
+        /// Health major class type.
+        /// </summary>
+        Health = 0x09,
+        /// <summary>
+        /// Uncategorized major class type.
+        /// </summary>
+        Uncategorized = 0x1F
+    }
+
+    /// <summary>
+    /// Enumeration for Bluetooth minor device class type.
+    /// </summary>
+    public enum BluetoothMinorDeviceClassType
+    {
+        /// <summary>
+        /// Uncategorized computer minor class type.
+        /// </summary>
+        ComputerUncategorized = 0x00,
+        /// <summary>
+        /// Desktop workstation computer minor class type.
+        /// </summary>
+        ComputerDesktopWorkstation = 0x04,
+        /// <summary>
+        /// Server computer minor class type.
+        /// </summary>
+        ComputerServer = 0x08,
+        /// <summary>
+        /// Laptop computer minor class type.
+        /// </summary>
+        ComputerLaptop = 0x0C,
+        /// <summary>
+        /// Handheld PC/PDA computer minor class type.
+        /// </summary>
+        ComputerHandheldPcOrPda = 0x10,
+        /// <summary>
+        /// Palm sized PC/PDA  computer minor class type.
+        /// </summary>
+        ComputerPalmSizedPcOrPda = 0x14,
+        /// <summary>
+        /// Wearable computer minor class type.
+        /// </summary>
+        ComputerWearableComputer = 0x18,
+
+        /// <summary>
+        /// Unclassified phone minor class type.
+        /// </summary>
+        PhoneUncategorized = 0x00,
+        /// <summary>
+        /// Cellular phone minor class type.
+        /// </summary>
+        PhoneCellular = 0x04,
+        /// <summary>
+        /// Cordless phone minor class type.
+        /// </summary>
+        PhoneCordless = 0x08,
+        /// <summary>
+        /// SmartPhone phone minor class type.
+        /// </summary>
+        PhoneSmartPhone = 0x0C,
+        /// <summary>
+        /// Wired modem or voice gateway phone minor class type.
+        /// </summary>
+        PhoneWiredModemOrVoiceGateway = 0x10,
+        /// <summary>
+        /// ISDN phone minor class type.
+        /// </summary>
+        PhoneCommonIsdnAccess = 0x14,
+
+        /// <summary>
+        /// Fully available LAN/Network access point minor class type.
+        /// </summary>
+        LanNetworkAccessPointFullyAvailable = 0x04,
+        /// <summary>
+        /// 1-17% utilized LAN/Network access point minor class type.
+        /// </summary>
+        LanNetworkAccessPoint1To17PercentUtilized = 0x20,
+        /// <summary>
+        /// 17-33% utilized LAN/Network access point minor class type.
+        /// </summary>
+        LanNetworkAccessPoint17To33PercentUtilized = 0x40,
+        /// <summary>
+        /// 33-50% utilized LAN/Network access point minor class type.
+        /// </summary>
+        LanNetworkAccessPoint33To50PercentUtilized = 0x60,
+        /// <summary>
+        /// 50-67% utilized LAN/Network access point minor class type.
+        /// </summary>
+        LanNetworkAccessPoint50To67PercentUtilized = 0x80,
+        /// <summary>
+        /// 67-83% utilized LAN/Network access point minor class type.
+        /// </summary>
+        LanNetworkAccessPoint67To83PercentUtilized = 0xA0,
+        /// <summary>
+        /// 83-99% utilized LAN/Network access point minor class type.
+        /// </summary>
+        LanNetworkAccessPoint83To99PercentUtilized = 0xC0,
+        /// <summary>
+        /// No service available LAN/Network access point minor class type.
+        /// </summary>
+        LanNetworkAccessPointNoServiceAvailable = 0xE0,
+
+        /// <summary>
+        /// Uncategorized audio/video minor class type.
+        /// </summary>
+        AudioVideoUncategorized = 0x00,
+        /// <summary>
+        /// Wearable headset audio/video minor class type.
+        /// </summary>
+        AudioVideoWearableHeadset = 0x04,
+        /// <summary>
+        /// Hands free audio/video minor class type.
+        /// </summary>
+        AudioVideoHandsFree = 0x08,
+        /// <summary>
+        /// Microphone audio/video minor class type.
+        /// </summary>
+        AudioVideoMicrophone = 0x10,
+        /// <summary>
+        /// Loudspeaker audio/video minor class type.
+        /// </summary>
+        AudioVideoLoudspeaker = 0x14,
+        /// <summary>
+        /// Headphones audio/video minor class type.
+        /// </summary>
+        AudioVideoHeadphones = 0x18,
+        /// <summary>
+        /// Portable audio audio/video minor class type.
+        /// </summary>
+        AudioVideoPortableAudio = 0x1C,
+        /// <summary>
+        /// Car audio audio/video minor class type.
+        /// </summary>
+        AudioVideoCarAudio = 0x20,
+        /// <summary>
+        /// SetTopbox audio/video minor class type.
+        /// </summary>
+        AudioVideoSetTopBox = 0x24,
+        /// <summary>
+        /// Hifi audio audio/video minor class type.
+        /// </summary>
+        AudioVideoHifiAudioDevice = 0x28,
+        /// <summary>
+        /// VCR audio/video minor class type.
+        /// </summary>
+        AudioVideoVcr = 0x2C,
+        /// <summary>
+        /// Video camera audio/video minor class type.
+        /// </summary>
+        AudioVideoVideoCamera = 0x30,
+        /// <summary>
+        /// Camcorder audio/video minor class type.
+        /// </summary>
+        AudioVideoCamcorder = 0x34,
+        /// <summary>
+        /// Video monitor audio/video minor class type.
+        /// </summary>
+        AudioVideoVideoMonitor = 0x38,
+        /// <summary>
+        /// Video display and loudspeaker audio/video minor class type.
+        /// </summary>
+        AudioVideoVideoDisplayLoudspeaker = 0x3C,
+        /// <summary>
+        /// Video conferencing audio/video minor class type.
+        /// </summary>
+        AudioVideoVideoConferencing = 0x40,
+        /// <summary>
+        /// Gaming/toy audio/video minor class type.
+        /// </summary>
+        AudioVideoGamingToy = 0x48,
+
+        /// <summary>
+        /// Uncategorized peripheral minor class type.
+        /// </summary>
+        PeripheralUncategorized = 0x00,
+        /// <summary>
+        /// Keyboard peripheral minor class type.
+        /// </summary>
+        PeripheralKeyBoard = 0x40,
+        /// <summary>
+        /// Pointing device peripheral minor class type.
+        /// </summary>
+        PeripheralPointingDevice = 0x80,
+        /// <summary>
+        /// Combo keyboard peripheral minor class type.
+        /// </summary>
+        PeripheralComboKeyboardPointingDevice = 0xC0,
+        /// <summary>
+        /// Joystick peripheral minor class type.
+        /// </summary>
+        PeripheralJoystick = 0x04,
+        /// <summary>
+        /// Game pad peripheral minor class type.
+        /// </summary>
+        PeripheralGamePad = 0x08,
+        /// <summary>
+        /// Remote control peripheral minor class type.
+        /// </summary>
+        PeripheralRemoteControl = 0x0C,
+        /// <summary>
+        /// Sensing device peripheral minor class type.
+        /// </summary>
+        PeripheralSensingDevice = 0x10,
+        /// <summary>
+        /// Digitizer peripheral minor class type.
+        /// </summary>
+        PeripheralDigitizerTablet = 0x14,
+        /// <summary>
+        /// Card reader peripheral minor class type.
+        /// </summary>
+        PeripheralCardReader = 0x18,
+        /// <summary>
+        /// Digital pen peripheral minor class type.
+        /// </summary>
+        PeripheralDigitalPen = 0x1C,
+        /// <summary>
+        /// Handheld scanner peripheral minor class type.
+        /// </summary>
+        PeripheralHandheldScanner = 0x20,
+        /// <summary>
+        /// Handheld gestural input computer minor class type.
+        /// </summary>
+        PeripheralHandheldGesturalInputDevice = 0x24,
+
+        /// <summary>
+        /// Display imaging minor class type.
+        /// </summary>
+        ImagingDisplay = 0x10,
+        /// <summary>
+        /// Camera imaging minor class type.
+        /// </summary>
+        ImagingCamera = 0x20,
+        /// <summary>
+        /// Scanner imaging minor class type.
+        /// </summary>
+        ImagingScanner = 0x40,
+        /// <summary>
+        /// Printer imaging minor class type.
+        /// </summary>
+        ImagingPrinter = 0x80,
+
+        /// <summary>
+        /// Wrist watch wearable minor class type.
+        /// </summary>
+        WearableWristWatch = 0x04,
+        /// <summary>
+        /// Pager wearable minor class type.
+        /// </summary>
+        WearablePager = 0x08,
+        /// <summary>
+        /// Jacket wearable minor class type.
+        /// </summary>
+        WearableJacket = 0x0C,
+        /// <summary>
+        /// Helmet wearable minor class type.
+        /// </summary>
+        WearableHelmet = 0x10,
+        /// <summary>
+        /// Glasses wearable minor class type.
+        /// </summary>
+        WearableGlasses = 0x14,
+
+        /// <summary>
+        /// Robot toy minor class type.
+        /// </summary>
+        ToyRobot = 0x04,
+        /// <summary>
+        /// Vehicle toy minor class type.
+        /// </summary>
+        ToyVehicle = 0x08,
+        /// <summary>
+        /// Doll toy minor class type.
+        /// </summary>
+        ToyDollAction = 0x0C,
+        /// <summary>
+        /// Controller toy minor class type.
+        /// </summary>
+        ToyController = 0x10,
+        /// <summary>
+        /// Game toy minor class type.
+        /// </summary>
+        ToyGame = 0x14,
+
+        /// <summary>
+        /// Uncategorized health minor class type.
+        /// </summary>
+        HealthUncategorized = 0x00,
+        /// <summary>
+        /// BP monitor health minor class type.
+        /// </summary>
+        HealthBloodPressureMonitor = 0x04,
+        /// <summary>
+        /// Thermometer health minor class type.
+        /// </summary>
+        HealthThermometer = 0x08,
+        /// <summary>
+        /// Scale health minor class type.
+        /// </summary>
+        HealthWeighingScale = 0x0C,
+        /// <summary>
+        /// Glucose meter health minor class type.
+        /// </summary>
+        HealthGlucoseMeter= 0x10,
+        /// <summary>
+        /// Pulse oximeter health minor class type.
+        /// </summary>
+        HealthPulseOximeter = 0x14,
+        /// <summary>
+        /// Heart/Pulse rate monitor health minor class type.
+        /// </summary>
+        HealthHeartPulseRateMonitor = 0x18,
+        /// <summary>
+        /// Display health minor class type.
+        /// </summary>
+        HealthDataDisplay = 0x1C,
+        /// <summary>
+        /// Step counter health minor class type.
+        /// </summary>
+        HealthStepCounter = 0x20,
+        /// <summary>
+        /// Body composition analyzer health minor class type.
+        /// </summary>
+        HealthBodyCompositionAnalyzer = 0x24,
+        /// <summary>
+        /// Peak flow monitor health minor class type.
+        /// </summary>
+        HealthPeakFlowMonitor = 0x28,
+        /// <summary>
+        /// Medication monitor health minor class type.
+        /// </summary>
+        HealthMedicationMonitor = 0x2C,
+        /// <summary>
+        /// Knee prosthesis health minor class type.
+        /// </summary>
+        HealthKneeProsthesis = 0x30,
+        /// <summary>
+        /// Ankle prosthesis health minor class type.
+        /// </summary>
+        HealthAnkleProsthesis = 0x34
+    }
+
+    /// <summary>
+    /// Enumeration for Bluetooth device discovery state.
+    /// </summary>
+    public enum BluetoothDeviceDiscoveryState
+    {
+        /// <summary>
+        /// Device discovery is started.
+        /// </summary>
+        Started = 0,
+        /// <summary>
+        /// Device discovery is finished.
+        /// </summary>
+        Finished,
+        /// <summary>
+        /// The remote device is found.
+        /// </summary>
+        Found
+    }
+
+    /// <summary>
+    /// Enumeration for Bluetooth appearance type.
+    /// </summary>
+    public enum BluetoothAppearanceType
+    {
+        /// <summary>
+        /// Unknown.
+        /// </summary>
+        Unknown = 0,
+        /// <summary>
+        /// Generic phone.
+        /// </summary>
+        GenericPhone = 1,
+        /// <summary>
+        /// Generic computer.
+        /// </summary>
+        GenericComputer = 2,
+        /// <summary>
+        /// Generic watch.
+        /// </summary>
+        GenericWatch = 3
+    }
+
+    /// <summary>
+    /// Enumeration for Bluetooth audio profile type.
+    /// </summary>
+    public enum BluetoothAudioProfileType
+    {
+        /// <summary>
+        /// All supported profiles of audio.
+        /// </summary>
+        All = 0,
+        /// <summary>
+        /// Headset and Hands-Free profile.
+        /// </summary>
+        HspHfp,
+        /// <summary>
+        /// Advanced audio distribution profile.
+        /// </summary>
+        AdvancedAudioDistribution,
+        /// <summary>
+        /// Audio Gateway profile.
+        /// </summary>
+        AudioGateway,
+        /// <summary>
+        /// Advanced Audio Distribution profile sink role.
+        /// </summary>
+        AdvancedAudioDistributionSink
+    }
+
+    /// <summary>
+    /// Enumeration for Bluetooth service class type.
+    /// </summary>
+    public enum BluetoothServiceClassType
+    {
+        /// <summary>
+        /// No service class.
+        /// </summary>
+        None = 0,
+        /// <summary>
+        /// Res service class.
+        /// </summary>
+        Res = 0x00000001,
+        /// <summary>
+        /// Spp service class.
+        /// </summary>
+        Spp = 0x00000002,
+        /// <summary>
+        /// Dun service class.
+        /// </summary>
+        Dun = 0x00000004,
+        /// <summary>
+        /// Fax service class.
+        /// </summary>
+        Fax = 0x00000008,
+        /// <summary>
+        /// Lap service class.
+        /// </summary>
+        Lap = 0x00000010,
+        /// <summary>
+        /// Hsp service class.
+        /// </summary>
+        Hsp = 0x00000020,
+        /// <summary>
+        /// Hfp service class.
+        /// </summary>
+        Hfp = 0x00000040,
+        /// <summary>
+        /// Opp service class.
+        /// </summary>
+        Opp = 0x00000080,
+        /// <summary>
+        /// Ftp service class.
+        /// </summary>
+        Ftp = 0x00000100,
+        /// <summary>
+        /// Ctp service class.
+        /// </summary>
+        Ctp = 0x00000200,
+        /// <summary>
+        /// Icp service class.
+        /// </summary>
+        Icp = 0x00000400,
+        /// <summary>
+        /// Sync service class.
+        /// </summary>
+        Sync = 0x00000800,
+        /// <summary>
+        /// Bpp service class.
+        /// </summary>
+        Bpp = 0x00001000,
+        /// <summary>
+        /// Bip service class.
+        /// </summary>
+        Bip = 0x00002000,
+        /// <summary>
+        /// Panu service class.
+        /// </summary>
+        Panu = 0x00004000,
+        /// <summary>
+        /// Nap service class.
+        /// </summary>
+        Nap = 0x00008000,
+        /// <summary>
+        /// Gn service class.
+        /// </summary>
+        Gn = 0x00010000,
+        /// <summary>
+        /// Sap service class.
+        /// </summary>
+        Sap = 0x00020000,
+        /// <summary>
+        /// A2dp service class.
+        /// </summary>
+        A2dp = 0x00040000,
+        /// <summary>
+        /// Avrcp service class.
+        /// </summary>
+        Avrcp = 0x00080000,
+        /// <summary>
+        /// Pbap service class.
+        /// </summary>
+        Pbap = 0x00100000,
+        /// <summary>
+        /// Hid service class.
+        /// </summary>
+        Hid = 0x00200000,
+        /// <summary>
+        /// A2dp Source service class.
+        /// </summary>
+        A2dpSource = 0x00400000,
+        /// <summary>
+        /// All service class.
+        /// </summary>
+        All = 0x00FFFFFF,
+        /// <summary>
+        /// Max service class.
+        /// </summary>
+        Max
+    }
+
+    /// <summary>
+    /// Enumeration for Bluetooth profile type.
+    /// </summary>
+    public enum BluetoothProfileType
+    {
+        /// <summary>
+        /// Rfcomm profile.
+        /// </summary>
+        Rfcomm = 0,
+        /// <summary>
+        /// Advanced Audio Distribution Profile Source role
+        /// </summary>
+        AdvancedAudioDistribution,
+        /// <summary>
+        /// Headset profile.
+        /// </summary>
+        Headset,
+        /// <summary>
+        /// Human Interface Device profile.
+        /// </summary>
+        HumanInterfaceDevice,
+        /// <summary>
+        /// Network Access Point profile.
+        /// </summary>
+        NetworkAccessPoint,
+        /// <summary>
+        /// Audio Gateway profile.
+        /// </summary>
+        AudioGateway,
+        /// <summary>
+        /// Generic Attribute profile.
+        /// </summary>
+        GenericAttribute,
+        /// <summary>
+        /// Nap Server profile.
+        /// </summary>
+        NapServer,
+        /// <summary>
+        /// Advanced Audio Distribution profile sink role.
+        /// </summary>
+        AdvancedAudioDistributionSink
+    }
+
+    /// <summary>
+    /// Enumeration for Bluetooth authorization type.
+    /// </summary>
+    public enum BluetoothAuthorizationType
+    {
+        /// <summary>
+        /// Authorized type.
+        /// </summary>
+        Authorized = 0,
+        /// <summary>
+        /// Unauthorized type.
+        /// </summary>
+        Unauthorized
+    }
+
+    /// <summary>
+    /// Enumeration for Bluetooth connection link type.
+    /// </summary>
+    public enum BluetoothConnectionLinkType
+    {
+        /// <summary>
+        /// BR/EDR link.
+        /// </summary>
+        BrEdr = 0,
+        /// <summary>
+        /// LE link.
+        /// </summary>
+        Le,
+        /// <summary>
+        /// The default connection type.
+        /// </summary>
+        Default
+    }
+
+    /// <summary>
+    /// Enumeration for Bluetooth disconnect reason.
+    /// </summary>
+    public enum BluetoothDisconnectReason
+    {
+        /// <summary>
+        /// Disconnected by unknown reason.
+        /// </summary>
+        Unknown = 0,
+        /// <summary>
+        /// Disconnected by timeout.
+        /// </summary>
+        Timeout,
+        /// <summary>
+        /// Disconnected by local host.
+        /// </summary>
+        LocalHost,
+        /// <summary>
+        /// Disconnected by remote.
+        /// </summary>
+        Remote
+    }
+
+    /// <summary>
+    /// Enumerations of connected Bluetooth device event role.
+    /// </summary>
+    public enum BluetoothSocketRole
+    {
+        /// <summary>
+        /// Unknown role.
+        /// </summary>
+        Unknown,
+        /// <summary>
+        /// Server role.
+        /// </summary>
+        Server,
+        /// <summary>
+        /// Client role.
+        /// </summary>
+        Client
+    }
+
+    /// <summary>
+    /// Enumerations of Bluetooth socket connection state.
+    /// </summary>
+    public enum BluetoothSocketState
+    {
+        /// <summary>
+        /// RFCOMM is connected.
+        /// </summary>
+        Connected,
+        /// <summary>
+        /// RFCOMM is disconnected.
+        /// </summary>
+        Disconnected
+    }
+
+    /// <summary>
+    /// Enumeration for equalizer state.
+    /// </summary>
+    public enum EqualizerState
+    {
+        /// <summary>
+        /// Equalizer Off.
+        /// </summary>
+        Off = 0,
+        /// <summary>
+        /// Equalizer On.
+        /// </summary>
+        On
+    }
+
+    /// <summary>
+    /// Enumeration for repeat mode.
+    /// </summary>
+    public enum RepeatMode
+    {
+        /// <summary>
+        /// Repeat off.
+        /// </summary>
+        Off = 0,
+        /// <summary>
+        /// Single track repeat.
+        /// </summary>
+        SingleTrack,
+        /// <summary>
+        /// All track repeat.
+        /// </summary>
+        AllTrack,
+        /// <summary>
+        /// Group repeat.
+        /// </summary>
+        Group
+    }
+
+    /// <summary>
+    /// Enumeration for shuffle mode.
+    /// </summary>
+    public enum ShuffleMode
+    {
+        /// <summary>
+        /// Shuffle off.
+        /// </summary>
+        Off = 0,
+        /// <summary>
+        /// All tracks shuffle.
+        /// </summary>
+        AllTrack,
+        /// <summary>
+        /// Group shuffle.
+        /// </summary>
+        Group
+    }
+
+    /// <summary>
+    /// Enumeration for scan mode.
+    /// </summary>
+    public enum ScanMode
+    {
+        /// <summary>
+        /// Scan off.
+        /// </summary>
+        Off = 0,
+        /// <summary>
+        /// All tracks scan.
+        /// </summary>
+        AllTrack,
+        /// <summary>
+        /// Group scan.
+        /// </summary>
+        Group
+    }
+
+    /// <summary>
+    /// Enumeration for player state.
+    /// </summary>
+    public enum PlayerState
+    {
+        /// <summary>
+        /// Stopped state.
+        /// </summary>
+        Stopped = 0,
+        /// <summary>
+        /// Playing state.
+        /// </summary>
+        Playing,
+        /// <summary>
+        /// Paused state.
+        /// </summary>
+        Paused,
+        /// <summary>
+        /// Seek forward state.
+        /// </summary>
+        SeekForward,
+        /// <summary>
+        /// Seek rewind state.
+        /// </summary>
+        SeekRewind
+    }
+
+    /// <summary>
+    /// Enumeration for Bluetooth Le device address type.
+    /// </summary>
+    public enum BluetoothLeDeviceAddressType
+    {
+        /// <summary>
+        /// The bluetooth le public address.
+        /// </summary>
+        BluetoothLePublicAddress,
+        /// <summary>
+        /// The bluetooth le private address.
+        /// </summary>
+        BluetoothLePrivateAddress
+    }
+
+    /// <summary>
+    /// Enumeration for Bluetooth LePacket type.
+    /// </summary>
+    public enum BluetoothLePacketType
+    {
+        /// <summary>
+        /// The bluetooth le advertising packet.
+        /// </summary>
+        BluetoothLeAdvertisingPacket,
+        /// <summary>
+        /// The bluetooth le scan response packet.
+        /// </summary>
+        BluetoothLeScanResponsePacket
+    }
+
+    /// <summary>
+    /// Enumeration for Bluetooth Le data type.
+    /// </summary>
+    public enum BluetoothLeDataType
+    {
+        /// <summary>
+        /// The bluetooth le packet data list 16 bit service uuid.
+        /// </summary>
+        BluetoothLePacketDataList16BitServiceUuid,
+        /// <summary>
+        /// The bluetooth le packet manufacturer data.
+        /// </summary>
+        BluetoothLePacketManufacturerData
+    }
+
+    /// <summary>
+    /// Enumeration for Bluetooth Le Advertising mode type.
+    /// </summary>
+    public enum BluetoothLeAdvertisingMode
+    {
+        /// <summary>
+        /// The bluetooth le advertising balanced mode.
+        /// </summary>
+        BluetoothLeAdvertisingBalancedMode,
+        /// <summary>
+        /// The bluetooth le advertising low latency mode.
+        /// </summary>
+        BluetoothLeAdvertisingLowLatencyMode,
+        /// <summary>
+        /// The bluetooth le advertising low energy mode.
+        /// </summary>
+        BluetoothLeAdvertisingLowEnergyMode
+    }
+
+    /// <summary>
+    /// Enumeration for Bluetooth Le Advertising mode type.
+    /// </summary>
+    public enum BluetoothLeAdvertisingState
+    {
+        /// <summary>
+        /// The bluetooth le advertising stopped.
+        /// </summary>
+        BluetoothLeAdvertisingStopped,
+        /// <summary>
+        /// The bluetooth le advertising started.
+        /// </summary>
+        BluetoothLeAdvertisingStarted
+    }
+
+    /// <summary>
+    /// Enumerations of the integer type for GATT handle's value.
+    /// </summary>
+    public enum IntDataType
+    {
+        /// <summary>
+        /// 8 bit signed int type.
+        /// </summary>
+        SignedInt8,
+        /// <summary>
+        /// 16 bit signed int type.
+        /// </summary>
+        SignedInt16,
+        /// <summary>
+        /// 32 bit signed int type.
+        /// </summary>
+        SignedInt32,
+        /// <summary>
+        /// 8 bit unsigned int type.
+        /// </summary>
+        UnsignedInt8,
+        /// <summary>
+        /// 16 bit unsigned int type.
+        /// </summary>
+        UnsignedInt16,
+        /// <summary>
+        /// 32 bit unsigned int type.
+        /// </summary>
+        UnsignedInt32
+    }
+
+    /// <summary>
+    /// Enumerations of the float type for GATT handle's value.
+    /// </summary>
+    public enum FloatDataType
+    {
+        /// <summary>
+        /// 32 bit float type.
+        /// </summary>
+        Float,
+        /// <summary>
+        /// 16 bit float type.
+        /// </summary>
+        SFloat,
+    }
+
+    /// <summary>
+    /// Enumerations of the GATT handle's type.
+    /// </summary>
+    public enum GattHandleType
+    {
+        /// <summary>
+        /// GATT service type.
+        /// </summary>
+        Service,
+        /// <summary>
+        /// GATT characteristic type.
+        /// </summary>
+        Characteristic,
+        /// <summary>
+        /// GATT descriptor type.
+        /// </summary>
+        Descriptor
+    }
+
+    /// <summary>
+    /// Enumerations of the service type.
+    /// </summary>
+    public enum BluetoothGattServiceType
+    {
+        /// <summary>
+        /// GATT primary service type.
+        /// </summary>
+        Primary,
+        /// <summary>
+        /// GATT secondary service type.
+        /// </summary>
+        Secondary
+    }
+
+    /// <summary>
+    /// Enumerations of the characteristic's property.
+    /// </summary>
+    [Flags]
+    public enum BluetoothGattProperty
+    {
+        /// <summary>
+        /// Broadcast property.
+        /// </summary>
+        Broadcast = 1,
+        /// <summary>
+        /// Read property.
+        /// </summary>
+        Read = 2,
+        /// <summary>
+        /// Write without response property.
+        /// </summary>
+        WriteWithoutResponse = 4,
+        /// <summary>
+        /// Write property.
+        /// </summary>
+        Write = 8,
+        /// <summary>
+        /// Notify property.
+        /// </summary>
+        Notify = 16,
+        /// <summary>
+        /// Indicate property.
+        /// </summary>
+        Indicate = 32,
+        /// <summary>
+        /// Authenticated signed writes property.
+        /// </summary>
+        AuthenticatedSignedWrites = 64,
+        /// <summary>
+        /// Extended properties.
+        /// </summary>
+        ExtendedProperties = 128,
+    }
+
+    /// <summary>
+    /// Enumerations of bluetooth gatt permission type.
+    /// </summary>
+    [Flags]
+    public enum BluetoothGattPermission
+    {
+        /// <summary>
+        /// Read permission.
+        /// </summary>
+        Read = 1,
+        /// <summary>
+        /// Write permission.
+        /// </summary>
+        Write = 2,
+    }
+
+    /// <summary>
+    /// Enumerations of the write type.
+    /// </summary>
+    public enum BluetoothGattWriteType
+    {
+        /// <summary>
+        /// Write without response.
+        /// </summary>
+        NoResponse,
+        /// <summary>
+        /// Write with response.
+        /// </summary>
+        WriteWithResponse
+    }
+}
diff --git a/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothError.cs b/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothError.cs
new file mode 100644 (file)
index 0000000..76ab207
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * 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.Bluetooth
+{
+    static internal class BluetoothErrorFactory
+    {
+        static internal void ThrowBluetoothException(int exception)
+        {
+            BluetoothError error = (BluetoothError)exception;
+            switch (error)
+            {
+            case BluetoothError.InvalidParameter:
+                throw new InvalidOperationException("Invalid parameter");
+
+            case BluetoothError.Cancelled:
+                throw new InvalidOperationException("Operation cancelled");
+
+            case BluetoothError.AlreadyDone:
+                throw new InvalidOperationException("Operation already done");
+
+            case BluetoothError.TimedOut:
+                throw new InvalidOperationException("Timeout error");
+
+            case BluetoothError.AuthFailed:
+                throw new InvalidOperationException("Authentication failed");
+
+            case BluetoothError.AuthRejected:
+                throw new InvalidOperationException("Authentication rejected");
+
+            case BluetoothError.NoData:
+                throw new InvalidOperationException("No data available");
+
+            case BluetoothError.NotEnabled:
+                throw new InvalidOperationException("Local adapter not enabled");
+
+            case BluetoothError.NotInitialized:
+                throw new InvalidOperationException("Local adapter not initialized");
+
+            case BluetoothError.NowInProgress:
+                throw new InvalidOperationException("Operation now in progress");
+
+            case BluetoothError.NotInProgress:
+                throw new InvalidOperationException("Operation not in progress");
+
+            case BluetoothError.NotSupported:
+                throw new InvalidOperationException("Bluetooth is not supported");
+
+            case BluetoothError.OperationFailed:
+                throw new InvalidOperationException("Operation failed");
+
+            case BluetoothError.OutOfMemory:
+                throw new InvalidOperationException("Out of memory");
+
+            case BluetoothError.PermissionDenied:
+                throw new InvalidOperationException("Permission denied");
+
+            case BluetoothError.QuotaExceeded:
+                throw new InvalidOperationException("Quota exceeded");
+
+            case BluetoothError.RemoteDeviceNotBonded:
+                throw new InvalidOperationException("Remote device not bonded");
+
+            case BluetoothError.RemoteDeviceNotConnected:
+                throw new InvalidOperationException("Remote device not connected");
+
+            case BluetoothError.RemoteDeviceNotFound:
+                throw new InvalidOperationException("Remote device not found");
+
+            case BluetoothError.ResourceBusy:
+                throw new InvalidOperationException("Device or resource busy");
+
+            case BluetoothError.ResourceUnavailable:
+                throw new InvalidOperationException("Resource temporarily unavailable");
+
+            case BluetoothError.ServiceNotFound:
+                throw new InvalidOperationException("Service Not Found");
+
+            case BluetoothError.ServiceSearchFailed:
+                throw new InvalidOperationException("Service search failed");
+
+            default:
+                throw new InvalidOperationException("Unknown exception");
+            }
+        }
+    }
+}
+
diff --git a/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothEventArgs.cs b/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothEventArgs.cs
new file mode 100644 (file)
index 0000000..8c136d6
--- /dev/null
@@ -0,0 +1,1039 @@
+/*
+ * 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.Bluetooth
+{
+    /// <summary>
+    /// An extended EventArgs class which contains changed Bluetooth state.
+    /// </summary>
+    public class StateChangedEventArgs : EventArgs
+    {
+        private BluetoothState _type;
+        private BluetoothError _result;
+
+        internal StateChangedEventArgs(BluetoothError result, BluetoothState type)
+        {
+            _type = type;
+            _result = result;
+        }
+
+        /// <summary>
+        /// The state of Bluetooth.
+        /// </summary>
+        public BluetoothState BTState
+        {
+            get
+            {
+                return _type;
+            }
+        }
+
+        /// <summary>
+        /// The BluetoothError result.
+        /// </summary>
+        public BluetoothError Result
+        {
+            get
+            {
+                return _result;
+            }
+        }
+    }
+
+    /// <summary>
+    /// An extended EventArgs class which contains changed Bluetooth name.
+    /// </summary>
+    public class NameChangedEventArgs : EventArgs
+    {
+        private string _name;
+
+        internal NameChangedEventArgs(string name)
+        {
+            _name = name;
+        }
+
+        /// <summary>
+        /// The name of the device.
+        /// </summary>
+        public string DeviceName
+        {
+            get
+            {
+                return _name;
+            }
+        }
+    }
+
+    /// <summary>
+    /// An extended EventArgs class which contains changed Bluetooth visibility mode.
+    /// </summary>
+    public class VisibilityModeChangedEventArgs : EventArgs
+    {
+        private VisibilityMode _mode;
+        private BluetoothError _result;
+
+        internal VisibilityModeChangedEventArgs(BluetoothError result, VisibilityMode mode)
+        {
+            _result = result;
+            _mode = mode;
+        }
+
+        /// <summary>
+        /// The visibility mode.
+        /// </summary>
+        public VisibilityMode Visibility
+        {
+            get
+            {
+                return _mode;
+            }
+        }
+
+        /// <summary>
+        /// The BluetoothError result.
+        /// </summary>
+        public BluetoothError Result
+        {
+            get
+            {
+                return _result;
+            }
+        }
+    }
+
+    /// <summary>
+    /// An extended EventArgs class which contains the duration until the visibility mode is changed from TimeLimitedDiscoverable to NonDiscoverable.
+    /// </summary>
+    public class VisibilityDurationChangedEventArgs : EventArgs
+    {
+        private int _duration;
+
+        internal VisibilityDurationChangedEventArgs(int duration)
+        {
+            _duration = duration;
+        }
+
+        /// <summary>
+        /// The duration.
+        /// </summary>
+        public int Duration
+        {
+            get
+            {
+                return _duration;
+            }
+        }
+    }
+
+    /// <summary>
+    /// An extended EventArgs class which contains changed Bluetooth device discovery state and the discovered device information.
+    /// </summary>
+    public class DiscoveryStateChangedEventArgs : EventArgs
+    {
+        private BluetoothError _result;
+        private BluetoothDeviceDiscoveryState _state;
+        private BluetoothDevice _device;
+
+        internal DiscoveryStateChangedEventArgs(BluetoothError result, BluetoothDeviceDiscoveryState state)
+        {
+            _result = result;
+            _state = state;
+        }
+
+        internal DiscoveryStateChangedEventArgs(BluetoothError result, BluetoothDeviceDiscoveryState state, BluetoothDevice device)
+        {
+            _result = result;
+            _state = state;
+            _device = device;
+        }
+
+        /// <summary>
+        /// The BluetoothError result.
+        /// </summary>
+        public BluetoothError Result
+        {
+            get
+            {
+                return _result;
+            }
+        }
+
+        /// <summary>
+        /// The state of the discovery.
+        /// </summary>
+        public BluetoothDeviceDiscoveryState DiscoveryState
+        {
+            get
+            {
+                return _state;
+            }
+        }
+
+        /// <summary>
+        /// The remote device found.
+        /// </summary>
+        public BluetoothDevice DeviceFound
+        {
+            get
+            {
+                return _device;
+            }
+        }
+    }
+
+    /// <summary>
+    /// An extended EventArgs class which contains the bonded device information.
+    /// </summary>
+    public class BondCreatedEventArgs : EventArgs
+    {
+        private BluetoothError _result;
+        private BluetoothDevice _device;
+
+        internal BondCreatedEventArgs(BluetoothError result, BluetoothDevice device)
+        {
+            _result = result;
+            _device = device;
+        }
+
+        /// <summary>
+        /// The BluetoothError result.
+        /// </summary>
+        public BluetoothError Result
+        {
+            get
+            {
+                return _result;
+            }
+        }
+
+        /// <summary>
+        /// The remote device.
+        /// </summary>
+        public BluetoothDevice Device
+        {
+            get
+            {
+                return _device;
+            }
+        }
+    }
+
+    /// <summary>
+    /// An extended EventArgs class which contains the address of the remote Bluetooth device to destroy bond with.
+    /// </summary>
+    public class BondDestroyedEventArgs : EventArgs
+    {
+        private BluetoothError _result;
+        private string _address;
+
+        internal BondDestroyedEventArgs(BluetoothError result, string address)
+        {
+            _result = result;
+            _address = address;
+        }
+
+        /// <summary>
+        /// The BluetoothError result.
+        /// </summary>
+        public BluetoothError Result
+        {
+            get
+            {
+                return _result;
+            }
+        }
+
+        /// <summary>
+        /// The remote device address.
+        /// </summary>
+        /// <value>The device address.</value>
+        public string DeviceAddress
+        {
+            get
+            {
+                return _address;
+            }
+        }
+    }
+
+    /// <summary>
+    /// An extended EventArgs class which contains the authorization state and address of the remote Bluetooth device.
+    /// </summary>
+    public class AuthorizationChangedEventArgs : EventArgs
+    {
+        private BluetoothAuthorizationType _authType;
+        private string _address;
+
+        internal AuthorizationChangedEventArgs(BluetoothAuthorizationType authType, string address)
+        {
+            _authType = authType;
+            _address = address;
+        }
+
+        /// <summary>
+        /// The authorization.
+        /// </summary>
+        public BluetoothAuthorizationType Authorization
+        {
+            get
+            {
+                return _authType;
+            }
+        }
+
+        /// <summary>
+        /// The device address.
+        /// </summary>
+        public string DeviceAddress
+        {
+            get
+            {
+                return _address;
+            }
+        }
+
+    }
+
+    /// <summary>
+    /// An extended EventArgs class which contains the service lists found on the remote Bluetooth device.
+    /// </summary>
+    public class ServiceSearchedEventArgs : EventArgs
+    {
+        private BluetoothDeviceSdpData _sdpData;
+        private BluetoothError _result;
+
+        internal ServiceSearchedEventArgs(BluetoothError result, BluetoothDeviceSdpData sdpData)
+        {
+            _result = result;
+            _sdpData = sdpData;
+        }
+
+        /// <summary>
+        /// The BluetoothError result.
+        /// </summary>
+        public BluetoothError Result
+        {
+            get
+            {
+                return _result;
+            }
+        }
+        /// <summary>
+        /// The sdp data.
+        /// </summary>
+        public BluetoothDeviceSdpData SdpData
+        {
+            get
+            {
+                return _sdpData;
+            }
+        }
+    }
+
+    /// <summary>
+    /// An extended EventArgs class which contains the connection state and connection information of the remote device.
+    /// </summary>
+    public class DeviceConnectionStateChangedEventArgs : EventArgs
+    {
+        private bool _isConnected;
+        private BluetoothDeviceConnectionData _connectionData;
+
+        internal DeviceConnectionStateChangedEventArgs(bool isConnected, BluetoothDeviceConnectionData connectionData)
+        {
+            _isConnected = isConnected;
+            _connectionData = connectionData;
+        }
+
+        /// <summary>
+        /// A value indicating whether the device is connected.
+        /// </summary>
+        public bool IsConnected
+        {
+            get
+            {
+                return _isConnected;
+            }
+        }
+
+        /// <summary>
+        /// The device connection data.
+        /// </summary>
+        public BluetoothDeviceConnectionData ConnectionData
+        {
+            get
+            {
+                return _connectionData;
+            }
+        }
+    }
+
+    /// <summary>
+    /// An extended EventArgs class which contains data received information.
+    /// </summary>
+    public class SocketDataReceivedEventArgs : EventArgs
+    {
+        private SocketData _data;
+
+        internal SocketDataReceivedEventArgs(SocketData data)
+        {
+            _data = data;
+        }
+
+        /// <summary>
+        /// The socket data.
+        /// </summary>
+        public SocketData Data
+        {
+            get
+            {
+                return _data;
+            }
+        }
+    }
+
+    /// <summary>
+    /// An extended EventArgs class which contains changed connection state.
+    /// </summary>
+    public class SocketConnectionStateChangedEventArgs : EventArgs
+    {
+        private BluetoothError _result;
+        private BluetoothSocketState _state;
+        private SocketConnection _connection;
+
+        internal SocketConnectionStateChangedEventArgs(BluetoothError result, BluetoothSocketState state, SocketConnection connection)
+        {
+            _result = result;
+            _state = state;
+            _connection = connection;
+        }
+
+        /// <summary>
+        /// The BluetoothError result.
+        /// </summary>
+        public BluetoothError Result
+        {
+            get
+            {
+                return _result;
+            }
+        }
+
+        /// <summary>
+        /// The socket state.
+        /// </summary>
+        public BluetoothSocketState State
+        {
+            get
+            {
+                return _state;
+            }
+        }
+
+        /// <summary>
+        /// The socket connection.
+        /// </summary>
+        public SocketConnection Connection
+        {
+            get
+            {
+                return _connection;
+            }
+        }
+    }
+
+    public class AcceptStateChangedEventArgs : EventArgs
+    {
+        private BluetoothError _result;
+        private BluetoothSocketState _state;
+        private SocketConnection _connection;
+        private IBluetoothServerSocket _server;
+
+        internal AcceptStateChangedEventArgs(BluetoothError result, BluetoothSocketState state, SocketConnection connection, BluetoothSocket server)
+        {
+            _result = result;
+            _state = state;
+            _connection = connection;
+            _server = (IBluetoothServerSocket)server;
+        }
+
+        /// <summary>
+        /// The BluetoothError result.
+        /// </summary>
+        public BluetoothError Result
+        {
+            get
+            {
+                return _result;
+            }
+        }
+
+        /// <summary>
+        /// The socket state.
+        /// </summary>
+        public BluetoothSocketState State
+        {
+            get
+            {
+                return _state;
+            }
+        }
+
+        /// <summary>
+        /// The socket connection.
+        /// </summary>
+        public SocketConnection Connection
+        {
+            get
+            {
+                return _connection;
+            }
+        }
+
+        /// <summary>
+        /// The server socket instance.
+        /// </summary>
+        public IBluetoothServerSocket Server
+        {
+            get
+            {
+                return _server;
+            }
+        }
+    }
+
+    /// <summary>
+    /// An extended EventArgs class which contains the connection state,remote address and the type of audio profile.
+    /// </summary>
+    public class AudioConnectionStateChangedEventArgs : EventArgs
+    {
+        private int _result;
+        private bool _isConnected;
+        private string _address;
+        private BluetoothAudioProfileType _type;
+
+        internal AudioConnectionStateChangedEventArgs(int result, bool isConnected, string address, BluetoothAudioProfileType type)
+        {
+            _result = result;
+            _type = type;
+            _isConnected = isConnected;
+            _address = address;
+        }
+
+        /// <summary>
+        /// The result.
+        /// </summary>
+        public int Result
+        {
+            get
+            {
+                return _result;
+            }
+        }
+
+        /// <summary>
+        /// A value indicating whether this instance is connected.
+        /// </summary>
+        public bool IsConnected
+        {
+            get
+            {
+                return _isConnected;
+            }
+        }
+
+        /// <summary>
+        /// The address.
+        /// </summary>
+        public string Address
+        {
+            get
+            {
+                return _address;
+            }
+        }
+
+        /// <summary>
+        /// The type of the audio profile.
+        /// </summary>
+        public BluetoothAudioProfileType ProfileType
+        {
+            get
+            {
+                return _type;
+            }
+        }
+    }
+
+    /// <summary>
+    /// An extended EventArgs class which contains the connection state and address of the remote Bluetooth device.
+    /// </summary>
+    public class HidConnectionStateChangedEventArgs : EventArgs
+    {
+        private int _result;
+        private bool _isConnected;
+        private string _address;
+
+        internal HidConnectionStateChangedEventArgs(int result, bool isConnected, string address)
+        {
+            _result = result;
+            _isConnected = isConnected;
+            _address = address;
+        }
+
+        /// <summary>
+        /// The result.
+        /// </summary>
+        public int Result
+        {
+            get
+            {
+                return _result;
+            }
+        }
+
+        /// <summary>
+        /// A value indicating whether this instance is connected.
+        /// </summary>
+        public bool IsConnected
+        {
+            get
+            {
+                return _isConnected;
+            }
+        }
+
+        /// <summary>
+        /// The address.
+        /// </summary>
+        public string Address
+        {
+            get
+            {
+                return _address;
+            }
+        }
+    }
+
+    /// <summary>
+    /// An extended EventArgs class which contains the changed equalizer state.
+    /// </summary>
+    public class EqualizerStateChangedEventArgs : EventArgs
+    {
+        private EqualizerState _state;
+
+        internal EqualizerStateChangedEventArgs(EqualizerState state)
+        {
+            _state = state;
+        }
+
+        /// <summary>
+        /// The state of equalizer.
+        /// </summary>
+        public EqualizerState State
+        {
+            get
+            {
+                return _state;
+            }
+        }
+    }
+
+    /// <summary>
+    /// An extended EventArgs class which contains the changed repeat mode.
+    /// </summary>
+    public class RepeatModeChangedEventArgs : EventArgs
+    {
+        private RepeatMode _mode;
+
+        internal RepeatModeChangedEventArgs(RepeatMode mode)
+        {
+            _mode = mode;
+        }
+
+        /// <summary>
+        /// The repeat mode.
+        /// </summary>
+        public RepeatMode Mode
+        {
+            get
+            {
+                return _mode;
+            }
+        }
+    }
+
+    /// <summary>
+    /// An extended EventArgs class which contains the changed shuffle mode.
+    /// </summary>
+    public class ShuffleModeChangedeventArgs : EventArgs
+    {
+        private ShuffleMode _mode;
+
+        internal ShuffleModeChangedeventArgs(ShuffleMode mode)
+        {
+            _mode = mode;
+        }
+
+        /// <summary>
+        /// The shuffle mode.
+        /// </summary>
+        public ShuffleMode Mode
+        {
+            get
+            {
+                return _mode;
+            }
+        }
+    }
+
+    /// <summary>
+    /// An extended EventArgs class which contains the changed scan mode.
+    /// </summary>
+    public class ScanModeChangedEventArgs : EventArgs
+    {
+        private ScanMode _mode;
+
+        internal ScanModeChangedEventArgs(ScanMode mode)
+        {
+            _mode = mode;
+        }
+
+        /// <summary>
+        /// The scan mode.
+        /// </summary>
+        public ScanMode Mode
+        {
+            get
+            {
+                return _mode;
+            }
+        }
+    }
+
+    /// <summary>
+    /// An extended EventArgs class which contains the connection state and the remote device address.
+    /// </summary>
+    public class TargetConnectionStateChangedEventArgs : EventArgs
+    {
+        private bool _isConnected;
+        private string _address;
+
+        internal TargetConnectionStateChangedEventArgs(bool isConnected, string address)
+        {
+            _isConnected = isConnected;
+            _address = address;
+        }
+
+        /// <summary>
+        /// A value indicating whether this instance is connected.
+        /// </summary>
+        public bool IsConnected
+        {
+            get
+            {
+                return _isConnected;
+            }
+        }
+
+        /// <summary>
+        /// The address.
+        /// </summary>
+        public string Address
+        {
+            get
+            {
+                return _address;
+            }
+        }
+    }
+
+    /// <summary>
+    /// An extended EventArgs class which contains changed Bluetooth LE advertising state changed information.
+    /// </summary>
+    public class AdvertisingStateChangedEventArgs : EventArgs
+    {
+        private BluetoothLeAdvertisingState _state;
+        private int _result;
+        private IntPtr _advertiserHandle;
+
+               //TODO : Add conversion code from IntPtr to BluetoothLeAdvertiser class later
+        internal AdvertisingStateChangedEventArgs(int result, IntPtr advertiserHandle,
+            BluetoothLeAdvertisingState state)
+        {
+            _result = result;
+            _advertiserHandle = advertiserHandle;
+            _state = state;
+        }
+
+        /// <summary>
+        /// The result.
+        /// </summary>
+        public int Result
+        {
+            get
+            {
+                return _result;
+            }
+        }
+
+        /// <summary>
+        /// The advertiser handle.
+        /// </summary>
+        public IntPtr AdvertiserHandle
+        {
+            get
+            {
+                return _advertiserHandle;
+            }
+        }
+
+        /// <summary>
+        /// The Le advertising state.
+        /// </summary>
+        public BluetoothLeAdvertisingState State
+        {
+            get
+            {
+                return _state;
+            }
+        }
+    }
+
+    /// <summary>
+    /// An extended EventArgs class which contains changed Bluetooth LE scan result information.
+    /// </summary>
+    public class AdapterLeScanResultChangedEventArgs : EventArgs
+    {
+        private BluetoothLeDevice _deviceData;
+        private int _result;
+
+        internal AdapterLeScanResultChangedEventArgs(int result, BluetoothLeDevice deviceData)
+        {
+            _deviceData = deviceData;
+            _result = result;
+        }
+
+        /// <summary>
+        /// The result.
+        /// </summary>
+        public int Result
+        {
+            get
+            {
+                return _result;
+            }
+        }
+
+        /// <summary>
+        /// The Le device data.
+        /// </summary>
+        public BluetoothLeDevice DeviceData
+        {
+            get
+            {
+                return _deviceData;
+            }
+        }
+    }
+
+    /// <summary>
+    /// An extended EventArgs class which contains changed Bluetooth LE GATT connection state.
+    /// </summary>
+    public class GattConnectionStateChangedEventArgs : EventArgs
+    {
+        private bool _isConnected;
+        private int _result;
+        private string _remoteAddress;
+
+        internal GattConnectionStateChangedEventArgs(int result, bool connected, string remoteAddress)
+        {
+            _isConnected = connected;
+            _result = result;
+            _remoteAddress = remoteAddress;
+        }
+
+        /// <summary>
+        /// The result.
+        /// </summary>
+        public int Result
+        {
+            get
+            {
+                return _result;
+            }
+        }
+
+        /// <summary>
+        /// A value indicating whether this instance is connected.
+        /// </summary>
+        public bool IsConnected
+        {
+            get
+            {
+                return _isConnected;
+            }
+        }
+
+        /// <summary>
+        /// The remote address.
+        /// </summary>
+        public string RemoteAddress
+        {
+            get
+            {
+                return _remoteAddress;
+            }
+        }
+    }
+
+    /// <summary>
+    /// An extended EventArgs class which contains changed attribute value.
+    /// </summary>
+    public class ValueChangedEventArgs : EventArgs
+    {
+        internal ValueChangedEventArgs(byte[] value)
+        {
+            Value = value;
+        }
+
+        /// <summary>
+        /// The attribute value.
+        /// </summary>
+        public byte[] Value { get; }
+    }
+
+    /// <summary>
+    /// An extended EventArgs class which contains read value request data.
+    /// </summary>
+    public class ReadRequestedEventArgs : EventArgs
+    {
+        internal ReadRequestedEventArgs(BluetoothGattServer server, string clientAddress, int requestId, int offset)
+        {
+            Server = server;
+            ClientAddress = clientAddress;
+            RequestId = requestId;
+            Offset = offset;
+        }
+
+        /// <summary>
+        /// The gatt server instance.
+        /// </summary>
+        public BluetoothGattServer Server { get; }
+        /// <summary>
+        /// The client address.
+        /// </summary>
+        public string ClientAddress { get; }
+        /// <summary>
+        /// The request identifier.
+        /// </summary>
+        public int RequestId { get; }
+        /// <summary>
+        /// The offset.
+        /// </summary>
+        public int Offset { get; }
+    }
+
+    /// <summary>
+    /// An extended EventArgs class which contains read value request data.
+    /// </summary>
+    public class WriteRequestedEventArgs : EventArgs
+    {
+        internal WriteRequestedEventArgs(BluetoothGattServer server, string clientAddress, int requestId, byte[] value, int offset)
+        {
+            Server = server;
+            ClientAddress = clientAddress;
+            RequestId = requestId;
+            Value = value;
+            Offset = offset;
+        }
+
+        /// <summary>
+        /// The gatt server instance.
+        /// </summary>
+        public BluetoothGattServer Server { get; }
+        /// <summary>
+        /// The client address.
+        /// </summary>
+        public string ClientAddress { get; }
+        /// <summary>
+        /// The request identifier.
+        /// </summary>
+        public int RequestId { get; }
+        /// <summary>
+        /// The read value.
+        /// </summary>
+        public byte[] Value { get; }
+        /// <summary>
+        /// The offset.
+        /// </summary>
+        public int Offset { get; }
+    }
+
+    /// <summary>
+    /// An extended EventArgs class which contains client preference to enables or disables the Notification/Indication.
+    /// </summary>
+    public class NotificationStateChangedEventArg : EventArgs
+    {
+        internal NotificationStateChangedEventArg(BluetoothGattServer server, bool value)
+        {
+            Server = server;
+            Value = value;
+        }
+
+        /// <summary>
+        /// The gatt server instance.
+        /// </summary>
+        public BluetoothGattServer Server { get; }
+        /// <summary>
+        /// A value indicating whether the notification is enabled
+        /// </summary>
+        public bool Value { get; }
+    }
+
+    /// <summary>
+    /// An extended EventArgs class which contains read value request data.
+    /// </summary>
+    public class NotificationSentEventArg : EventArgs
+    {
+        internal NotificationSentEventArg(BluetoothGattServer server, string clientAddress, int result, bool completed)
+        {
+            Result = result;
+            ClientAddress = clientAddress;
+            Server = server;
+            Completed = completed;
+        }
+
+        /// <summary>
+        /// The gatt server instance.
+        /// </summary>
+        public BluetoothGattServer Server { get; }
+        /// <summary>
+        /// The client address.
+        /// </summary>
+        public string ClientAddress { get; }
+        /// <summary>
+        /// The result.
+        /// </summary>
+        public int Result { get; }
+        /// <summary>
+        /// Gets a value indicating whether notification sent is completed.
+        /// </summary>
+        public bool Completed { get; }
+    }
+}
diff --git a/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothGatt.cs b/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothGatt.cs
new file mode 100644 (file)
index 0000000..d059df8
--- /dev/null
@@ -0,0 +1,916 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+
+namespace Tizen.Network.Bluetooth
+{
+    /// <summary>
+    /// Bluetooth GATT server
+    /// </summary>
+    public class BluetoothGattServer
+    {
+        private static BluetoothGattServer _instance;
+        private BluetoothGattServerImpl _impl;
+
+        private BluetoothGattServer()
+        {
+            _impl = new BluetoothGattServerImpl();
+        }
+
+        /// <summary>
+        /// (event) called when indication acknowledgement received, once for each notified client
+        /// </summary>
+        public event EventHandler<NotificationSentEventArg> NotificationSent
+        {
+            add
+            {
+                _impl._notificationSent += value;
+            }
+            remove
+            {
+                _impl._notificationSent -= value;
+            }
+        }
+
+        /// <summary>
+        /// Creates bluetooth gatt server
+        /// </summary>
+        /// <returns></returns>
+        public static BluetoothGattServer CreateServer()
+        {
+            if (_instance == null)
+            {
+                BluetoothGattServer server = new BluetoothGattServer();
+                if (server.IsValid())
+                {
+                    _instance = server;
+                }
+            }
+            return _instance;
+        }
+
+        /// <summary>
+        /// Registers the server along with the GATT services of the application it is hosting
+        /// </summary>
+        public void Start()
+        {
+            _impl.Start();
+        }
+
+        /// <summary>
+        /// Registers a specified service to this server
+        /// </summary>
+        /// <param name="service">service, which needs to be registered with this server</param>
+        public void RegisterGattService(BluetoothGattService service)
+        {
+            if (service.IsRegistered())
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.InvalidParameter);
+            }
+            _impl.RegisterGattService(this, service);
+        }
+
+        /// <summary>
+        /// Unregisters a specified service from this server
+        /// </summary>
+        /// <param name="service">service, which needs to be unregistered from this server</param>
+        /// <remarks>
+        /// Once unregistered, service object will become invalid and should not be used to access sevices's or any children attribute's methods/ members.
+        /// </remarks>
+        public void UnregisterGattService(BluetoothGattService service)
+        {
+            if (service.GetGattServer() != this)
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.InvalidParameter);
+            }
+
+            _impl.UnregisterGattService(service);
+        }
+
+        /// <summary>
+        /// Unregisters all services from this server
+        /// </summary>
+        /// <remarks>
+        /// Once unregistered, servicees will become invalid and should not be used to access sevices's or any children attribute's methods/ members.
+        /// </remarks>
+        public void UnregisterGattServices()
+        {
+            _impl.UnregisterAllGattServices(this);
+        }
+
+        /// <summary>
+        /// Gets service with given UUID that belongs to this server.
+        /// </summary>
+        /// <param name="uuid">UUID for the service to get</param>
+        /// <returns>service with given uuid if it exists, null otherwise</returns>
+        public BluetoothGattService GetService(string uuid)
+        {
+            return _impl.GetService(this, uuid);
+        }
+
+        /// <summary>
+        /// Gets list of services that belongs to this server.
+        /// </summary>
+        /// <returns>list of services that belongs to this server</returns>
+        public IEnumerable<BluetoothGattService> GetServices()
+        {
+            return _impl.GetServices(this);
+        }
+
+        /// <summary>
+        /// Send indication for value change of the characteristic to the remote devices
+        /// </summary>
+        /// <param name="characteristic">characteristic whose value is changes</param>
+        /// <param name="clientAddress">Remote device address to send notify or indicate and if set to NULL then notify/indicate all is enabled.</param>
+        public async Task<bool> SendIndicationAsync(BluetoothGattCharacteristic characteristic, string clientAddress)
+        {
+            return await _impl.SendIndicationAsync(this, characteristic, clientAddress);
+        }
+
+        /// <summary>
+        /// Send notification for value change of the characteristic to the remote devices
+        /// </summary>
+        /// <param name="characteristic">characteristic The characteristic which has a changed value</param>
+        /// <param name="clientAddress">Remote device address to send notify or indicate and if set to NULL then notify/indicate all is enabled.</param>
+        public void SendNotification(BluetoothGattCharacteristic characteristic, string clientAddress)
+        {
+            _impl.SendNotification(characteristic, clientAddress);
+        }
+
+        /// <summary>
+        /// Sends a response to the remote device as a result of a read/ write request
+        /// </summary>
+        /// <param name="requestId">The identification of a read/ write request</param>
+        /// <param name="status">error value in case of failure, 0 for success</param>
+        /// <param name="value">Value to be sent</param>
+        /// <param name="offset">Fffset from where the value is read</param>
+        public void SendResponse(int requestId, int status, byte[] value, int offset)
+        {
+            _impl.SendResponse(requestId, status, value, offset);
+        }
+
+        internal bool IsValid()
+        {
+            return _impl.GetHandle().IsInvalid == false;
+        }
+    }
+
+    /// <summary>
+    /// Bluetooth GATT client
+    /// </summary>
+    public class BluetoothGattClient
+    {
+        private BluetoothGattClientImpl _impl;
+        private string _remoteAddress = string.Empty;
+
+        internal BluetoothGattClient(string remoteAddress)
+        {
+            _impl = new BluetoothGattClientImpl(remoteAddress);
+            _remoteAddress = remoteAddress;
+        }
+
+        internal static BluetoothGattClient CreateClient(string remoteAddress)
+        {
+            BluetoothGattClient client = new BluetoothGattClient(remoteAddress);
+            return client.Isvalid() ? client : null;
+        }
+
+        /// <summary>
+        /// Address of remote device.
+        /// </summary>
+        public string RemoteAddress
+        {
+            get
+            {
+                if (string.IsNullOrEmpty(_remoteAddress))
+                {
+                    _remoteAddress = _impl.GetRemoteAddress();
+                }
+                return _remoteAddress;
+            }
+        }
+
+        /// <summary>
+        /// Gets service with given UUID that belongs to this client.
+        /// </summary>
+        /// <param name="uuid">UUID for the service to get</param>
+        /// <returns>service with given uuid if it exists, null otherwise</returns>
+        public BluetoothGattService GetService(string uuid)
+        {
+            return _impl.GetService(this, uuid);
+        }
+
+        /// <summary>
+        /// Gets list of services that belongs to this client.
+        /// </summary>
+        /// <returns>list of services that belongs to this client</returns>
+        public IEnumerable<BluetoothGattService> GetServices()
+        {
+            return _impl.GetServices(this);
+        }
+
+        /// <summary>
+        /// Reads the value of given characteristic from the remote device asynchronously.
+        /// </summary>
+        /// <param name="characteristic">characteristic to be read</param>
+        /// <returns>true on success, false otherwise</returns>
+        public async Task<bool> ReadValueAsync(BluetoothGattCharacteristic characteristic)
+        {
+            return await _impl.ReadValueAsyncTask(characteristic.GetHandle());
+        }
+
+        /// <summary>
+        /// Reads the value of given descriptor from the remote device asynchronously.
+        /// </summary>
+        /// <param name="descriptor">descriptor to be read</param>
+        /// <returns>true on success, false otherwise</returns>
+        public async Task<bool> ReadValueAsync(BluetoothGattDescriptor descriptor)
+        {
+            return await _impl.ReadValueAsyncTask(descriptor.GetHandle());
+        }
+
+        /// <summary>
+        /// Write value of given characteristic to remote device asynchronously.
+        /// </summary>
+        /// <param name="characteristic">characteristic to be written</param>
+        /// <returns>true on success, false otherwise</returns>
+        public async Task<bool> WriteValueAsync(BluetoothGattCharacteristic characteristic)
+        {
+            return await _impl.WriteValueAsyncTask(characteristic.GetHandle());
+        }
+
+        /// <summary>
+        /// Write value of given descriptor to remote device asynchronously.
+        /// </summary>
+        /// <param name="descriptor">descriptor to be written</param>
+        /// <returns>true on success, false otherwise</returns>
+        public async Task<bool> WriteValueAsync(BluetoothGattDescriptor descriptor)
+        {
+            return await _impl.WriteValueAsyncTask(descriptor.GetHandle());
+        }
+
+        internal bool Isvalid()
+        {
+            return _impl.GetHandle().IsInvalid == false;
+        }
+    }
+
+    /// <summary>
+    /// Bluetooth GATT service
+    /// </summary>
+    public class BluetoothGattService
+    {
+        private BluetoothGattServiceImpl _impl;
+        private BluetoothGattClient _parentClient = null;
+        private BluetoothGattServer _parentServer = null;
+        private BluetoothGattService _parentService = null;
+
+        /// <summary>
+        /// Constructor
+        /// </summary>
+        /// <param name="uuid">UUID of the service</param>
+        /// <param name="type">type of service</param>
+        public BluetoothGattService(string uuid, BluetoothGattServiceType type)
+        {
+            Uuid = uuid;
+            _impl = new BluetoothGattServiceImpl(uuid, type);
+        }
+
+        internal BluetoothGattService(BluetoothGattServiceImpl impl, string uuid)
+        {
+            Uuid = uuid;
+            _impl = impl;
+        }
+
+        /// <summary>
+        /// Specification name from the UUID
+        /// </summary>
+        public string Uuid { get; }
+
+        /// <summary>
+        /// Adds a characteristic to this service
+        /// </summary>
+        /// <param name="characteristic">characteristic to be added</param>
+        /// <returns>true on success, false otherwise</returns>
+        public void AddCharacteristic(BluetoothGattCharacteristic characteristic)
+        {
+            if (GetGattClient() != null)
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotSupported);
+            }
+
+            if (characteristic.GetService() != null)
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.InvalidParameter);
+            }
+
+            _impl.AddCharacteristic(characteristic);
+            characteristic.SetParent(this);
+        }
+
+        /// <summary>
+        /// Gets characteristic with given UUID that belongs to this service.
+        /// </summary>
+        /// <param name="uuid">UUID for the characteristic to get</param>
+        /// <returns>characteristic with given uuid if it exists, null otherwise</returns>
+        public BluetoothGattCharacteristic GetCharacteristic(string uuid)
+        {
+            return _impl.GetCharacteristic(this, uuid);
+        }
+
+        /// <summary>
+        /// Gets list of characteristic that belongs to this service.
+        /// </summary>
+        /// <returns>list of characteristic that belongs to this service</returns>
+        public IEnumerable<BluetoothGattCharacteristic> GetCharacteristics()
+        {
+            return _impl.GetCharacteristics(this);
+        }
+
+        /// <summary>
+        /// Includes a service to this service
+        /// </summary>
+        /// <param name="service">service to be included</param>
+        /// <returns>true on success, false otherwise</returns>
+        public void AddService(BluetoothGattService service)
+        {
+            if (GetGattClient() != null)
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotSupported);
+            }
+
+            if (service.IsRegistered())
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.InvalidParameter);
+            }
+
+            _impl.AddIncludeService(service);
+            service.SetParent(this);
+        }
+
+        /// </summary>
+        /// <param name="uuid">UUID for the service to get</param>
+        /// <returns>service with given uuid if it exists, null otherwise</returns>
+        public BluetoothGattService GetIncludeService(string uuid)
+        {
+            return _impl.GetIncludeService(this, uuid);
+        }
+
+        /// <summary>
+        /// Gets included service list of this service.
+        /// </summary>
+        /// <returns>included service list of this service</returns>
+        public IEnumerable<BluetoothGattService> GetIncludeServices()
+        {
+            return _impl.GetIncludeServices(this);
+        }
+
+        /// <summary>
+        /// Gets the server instance which the specified service belongs to.
+        /// </summary>
+        /// <returns>server instance which the specified service belongs to</returns>
+        public BluetoothGattServer GetGattServer()
+        {
+            return _parentServer;
+        }
+
+        /// <summary>
+        /// Gets the client instance which the specified service belongs to.
+        /// </summary>
+        /// <returns>client instance which the specified service belongs to</returns>
+        public BluetoothGattClient GetGattClient()
+        {
+            return _parentClient;
+        }
+
+        internal BluetoothGattAttributeHandle GetHandle()
+        {
+            return _impl.GetHandle();
+        }
+
+        internal void SetParent(BluetoothGattService parent)
+        {
+            if (!IsRegistered())
+            {
+                _parentService = parent;
+                _impl.ReleaseHandleOwnership();
+            }
+        }
+
+        internal void SetParent(BluetoothGattClient parent)
+        {
+            if (!IsRegistered())
+            {
+                _parentClient = parent;
+                _impl.ReleaseHandleOwnership();
+            }
+        }
+
+        internal void SetParent(BluetoothGattServer parent)
+        {
+            if (!IsRegistered())
+            {
+                _parentServer = parent;
+                _impl.ReleaseHandleOwnership();
+            }
+        }
+
+        internal void UnregisterService()
+        {
+            _parentServer = null;
+            _parentClient = null;
+            _parentService = null;
+        }
+
+        internal bool IsRegistered()
+        {
+            return _parentClient != null || _parentServer != null || _parentService != null;
+        }
+    }
+
+    /// <summary>
+    /// Bluetooth GATT characteristic
+    /// </summary>
+    public class BluetoothGattCharacteristic : BluetoothGattAttribute
+    {
+        private BluetoothGattCharacteristicImpl _impl;
+        private BluetoothGattService _parent = null;
+
+        private Interop.Bluetooth.BtClientCharacteristicValueChangedCallback _characteristicValueChangedCallback;
+        private Interop.Bluetooth.BtGattServerNotificationStateChangeCallback _notificationStateChangedCallback;
+
+        private EventHandler<ValueChangedEventArgs> _characteristicValueChanged;
+        internal EventHandler<NotificationStateChangedEventArg> _notificationStateChanged;
+
+        /// <summary>
+        /// Constructor
+        /// </summary>
+        /// <param name="uuid">UUID of the characterstic</param>
+        /// <param name="permissions">Permissions for the characterstic</param>
+        /// <param name="properties">Properties set for the characterstic</param>
+        /// <param name="value">Value associated with the characterstic</param>
+        /// <remarks>throws in case of internal error</remarks>
+        public BluetoothGattCharacteristic(string uuid, BluetoothGattPermission permissions, BluetoothGattProperty properties, byte[] value) : base(uuid, permissions)
+        {
+            _impl = new BluetoothGattCharacteristicImpl(uuid, permissions, properties, value);
+        }
+
+        internal BluetoothGattCharacteristic(BluetoothGattCharacteristicImpl impl, string uuid, BluetoothGattPermission permission) : base(uuid, permission)
+        {
+            _impl = impl;
+        }
+
+        /// <summary>
+        /// (event) CharacteristicValueChanged is raised when server notifies for change in this characteristic value
+        /// </summary>
+        /// <remarks>
+        /// Adding event handle on charateristic on server side will not have any effect
+        /// </remarks>
+        public event EventHandler<ValueChangedEventArgs> ValueChanged
+        {
+            add
+            {
+                if (Client != null)
+                {
+                    if (_characteristicValueChanged == null)
+                    {
+                        _characteristicValueChangedCallback = (gattHandle, characteristicValue, len, userData) =>
+                        {
+                            _characteristicValueChanged?.Invoke(this, new ValueChangedEventArgs(characteristicValue));
+                        };
+
+                        _impl.SetCharacteristicValueChangedEvent(_characteristicValueChangedCallback);
+                    }
+                    _characteristicValueChanged = value;
+                }
+            }
+            remove
+            {
+                if (Client != null)
+                {
+                    _characteristicValueChanged = null;
+                    if (_characteristicValueChanged == null)
+                    {
+                        _impl.UnsetCharacteristicValueChangedEvent();
+                    }
+
+                }
+            }
+        }
+
+        /// <summary>
+        /// (event) NotificationStateChanged is called when client enables or disables the Notification/Indication for particular characteristics.
+        /// </summary>
+        /// <remarks>
+        /// Adding event handle on charateristic on client side will not have any effect
+        /// </remarks>
+        public event EventHandler<NotificationStateChangedEventArg> NotificationStateChanged
+        {
+            add
+            {
+                if (Server != null)
+                {
+                    if (_notificationStateChangedCallback == null)
+                    {
+                        _notificationStateChangedCallback = (notify, serverHandle, characteristicHandle, userData) =>
+                        {
+                            _notificationStateChanged?.Invoke(this, new NotificationStateChangedEventArg(Server, notify));
+                        };
+
+                        _impl.SetNotificationStateChangedEvent(_notificationStateChangedCallback);
+                    }
+
+                    _notificationStateChanged = value;
+                }
+            }
+            remove
+            {
+                if (Server != null)
+                {
+                    _notificationStateChanged = null;
+                    // CAPI does not allow unsetting ReadValueRequestedEventCallback.
+                }
+            }
+        }
+
+        /// <summary>
+        /// Property for this characteristic
+        /// </summary>
+        public BluetoothGattProperty Properties
+        {
+            get
+            {
+                return _impl.GetProperties();
+            }
+            set
+            {
+                if (Server != null)
+                {
+                    _impl.SetProperties(value);
+                }
+            }
+        }
+
+        /// <summary>
+        /// Write type to be used for write operations
+        /// </summary>
+        public BluetoothGattWriteType WriteType
+        {
+            get
+            {
+                return _impl.GetWriteType();
+            }
+            set
+            {
+                _impl.SetWriteType(value);
+            }
+        }
+
+        internal override BluetoothGattClient Client
+        {
+            get
+            {
+                return _parent?.GetGattClient();
+            }
+        }
+
+        internal override BluetoothGattServer Server
+        {
+            get
+            {
+                return _parent?.GetGattServer();
+            }
+        }
+
+        internal override BluetoothGattAttributeImpl Impl
+        {
+            get
+            {
+                return _impl;
+            }
+        }
+
+        /// <summary>
+        /// Adds a descriptor to this characteristic
+        /// </summary>
+        /// <param name="descriptor">descriptor to be added</param>
+        /// <returns>true on success, false otherwise</returns>
+        public void AddDescriptor(BluetoothGattDescriptor descriptor)
+        {
+            if (Client != null)
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotSupported);
+            }
+
+            if (descriptor.GetCharacteristic() != null)
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.InvalidParameter);
+            }
+
+            _impl.AddDescriptor(descriptor);
+            descriptor.SetParent(this);
+        }
+
+        /// <summary>
+        /// Gets descriptor with given UUID that belongs to this characteristic.
+        /// </summary>
+        /// <param name="uuid">UUID for the descriptor to get</param>
+        /// <returns>descriptor with given uuid if it exists, null otherwise</returns>
+        public BluetoothGattDescriptor GetDescriptor(string uuid)
+        {
+            return _impl.GetDescriptor(this, uuid);
+        }
+
+        /// <summary>
+        /// Gets list of descriptors that belongs to this characteristic.
+        /// </summary>
+        /// <returns>list of descriptors that belongs to this characteristic</returns>
+        public IEnumerable<BluetoothGattDescriptor> GetDescriptors()
+        {
+            return _impl.GetDescriptors(this);
+        }
+
+        /// <summary>
+        /// Gets the service instance which the specified characterstic belongs to.
+        /// </summary>
+        /// <returns>characteristic instance, the specified characterstic belongs to.</returns>
+        public BluetoothGattService GetService()
+        {
+            return _parent;
+        }
+
+        internal void SetParent(BluetoothGattService parent)
+        {
+            if (_parent == null)
+            {
+                _parent = parent;
+                ReleaseHandleOwnership();
+            }
+         }
+    }
+
+    /// <summary>
+    /// Bluetooth GATT descriptor
+    /// </summary>
+    public class BluetoothGattDescriptor : BluetoothGattAttribute
+    {
+        private BluetoothGattCharacteristic _parent = null;
+        private BluetoothGattDescriptorImpl _impl;
+
+        /// <summary>
+        /// Constructor
+        /// </summary>
+        /// <param name="uuid">UUID of the descriptor</param>
+        /// <param name="permisions">Permissions for the descriptor</param>
+        /// <param name="value">Value associated with the descriptor</param>
+        /// <remarks>throws in case of internal error</remarks>
+        public BluetoothGattDescriptor(string uuid, BluetoothGattPermission permisions, byte[] value) : base (uuid, permisions)
+        {
+            _impl = new BluetoothGattDescriptorImpl(uuid, permisions, value);
+        }
+
+        internal BluetoothGattDescriptor(BluetoothGattDescriptorImpl impl, string uuid, BluetoothGattPermission permission) : base(uuid, permission)
+        {
+            _impl = impl;
+        }
+
+        internal override BluetoothGattClient Client
+        {
+            get
+            {
+                return _parent?.Client;
+            }
+        }
+
+        internal override BluetoothGattServer Server
+        {
+            get
+            {
+                return _parent?.Server;
+            }
+        }
+
+        internal override BluetoothGattAttributeImpl Impl
+        {
+            get
+            {
+                return _impl;
+            }
+        }
+
+        /// <summary>
+        /// Gets the characteristic instance which the specified descriptor belongs to.
+        /// </summary>
+        /// <returns>characteristic instance, the specified descriptor belongs to.</returns>
+        public BluetoothGattCharacteristic GetCharacteristic()
+        {
+            return _parent;
+        }
+
+        internal void SetParent(BluetoothGattCharacteristic parent)
+        {
+            if (_parent == null)
+            {
+                _parent = parent;
+                ReleaseHandleOwnership();
+            }
+        }
+    }
+
+    /// <summary>
+    /// Bluetooth GATT attribute
+    /// </summary>
+    public abstract class BluetoothGattAttribute
+    {
+        private Interop.Bluetooth.BtGattServerReadValueRequestedCallback _readValueRequestedCallback;
+        private Interop.Bluetooth.BtGattServerWriteValueRequestedCallback _writeValueRequestedCallback;
+
+        private EventHandler<ReadRequestedEventArgs> _readValueRequested;
+        private EventHandler<WriteRequestedEventArgs> _writeValueRequested;
+
+        public BluetoothGattAttribute(string uuid, BluetoothGattPermission permission)
+        {
+            Uuid = uuid;
+            Permissions = permission;
+        }
+
+        // Events
+
+        /// <summary>
+        /// Event called when client request to read value of a characteristic or descriptor
+        /// </summary>
+        public event EventHandler<ReadRequestedEventArgs> ReadRequested
+        {
+            add
+            {
+                if (Server == null) return;
+                if (_readValueRequestedCallback == null)
+                {
+                    _readValueRequestedCallback = (clientAddress, requestId, serverHandle, gattHandle, offset, userData) =>
+                    {
+                        _readValueRequested?.Invoke(this, new ReadRequestedEventArgs(Server, clientAddress, requestId, offset));
+                    };
+                    Impl.SetReadValueRequestedEventCallback(_readValueRequestedCallback);
+                }
+                _readValueRequested = value;
+            }
+            remove
+            {
+                if (Server == null) return;
+                _readValueRequested = null;
+                // CAPI does not allow unsetting ReadValueRequestedEventCallback.
+            }
+        }
+
+        /// <summary>
+        /// Event called when a value of a characteristic or descriptor has been changed by a client
+        /// </summary>
+        public event EventHandler<WriteRequestedEventArgs> WriteRequested
+        {
+            add
+            {
+                if (Server == null) return;
+                if (_writeValueRequested == null)
+                {
+                    _writeValueRequestedCallback = (clientAddress, requestId, serverHandle, gattHandle, offset, valueToWrite, len, userData) =>
+                    {
+                        _writeValueRequested?.Invoke(this, new WriteRequestedEventArgs(Server, clientAddress, requestId, valueToWrite, offset));
+                    };
+                    Impl.SetWriteValueRequestedEventCallback(_writeValueRequestedCallback);
+                }
+                _writeValueRequested = value;
+            }
+            remove
+            {
+                if (Server == null) return;
+                _writeValueRequested = null;
+                // CAPI does not allow unsetting ReadValueRequestedEventCallback.
+            }
+        }
+
+        /// <summary>
+        /// Attribute's UUID
+        /// </summary>
+        public string Uuid { get; }
+
+        /// <summary>
+        /// Permissions for this attribute
+        /// </summary>
+        public BluetoothGattPermission Permissions { get; }
+
+        /// <summary>
+        /// Value of this descriptor
+        /// </summary>
+        public byte[] Value
+        {
+            get
+            {
+                return Impl.GetValue();
+            }
+            set
+            {
+                Impl.SetValue(value);
+            }
+        }
+
+        internal abstract BluetoothGattClient Client { get; }
+        internal abstract BluetoothGattServer Server { get; }
+        internal abstract BluetoothGattAttributeImpl Impl { get; }
+
+        /// <summary>
+        /// Returns string value at specified offset
+        /// </summary>
+        /// <param name="offset"></param>
+        /// <returns>string value at specified offset</returns>
+        public string GetValue(int offset)
+        {
+            return Impl.GetValue(offset);
+        }
+
+        /// <summary>
+        /// Sets string value as specified offset
+        /// </summary>
+        /// <param name="value">value to set</param>
+        /// <param name="offset">offset in the attribute value buffer</param>
+        /// <exception cref="InvalidOperationException">Throws excetion if (offset + size of string value) is greater then length of value buffer</exception>
+        public void SetValue(string value, int offset)
+        {
+            Impl.SetValue(value, offset);
+        }
+
+        /// <summary>
+        /// Returns value at specified offset as int value of specified type
+        /// </summary>
+        /// <param name="type">type of int value</param>
+        /// <param name="offset">offset in the attribute value buffer</param>
+        /// <returns>int value at given offset</returns>
+        /// <exception cref="InvalidOperationException">Throws excetion if (offset + size of int value) is greater then length of value buffer</exception>
+        public int GetValue(IntDataType type, int offset)
+        {
+            return Impl.GetValue(type, offset);
+        }
+
+        /// <summary>
+        /// Update Value at specified offset by int value of specified type
+        /// </summary>
+        /// <param name="type">type of int value</param>
+        /// <param name="value">value to set</param>
+        /// <param name="offset">offset in the attribute value buffer</param>
+        /// <exception cref="InvalidOperationException">Throws excetion if (offset + size of int value) is greater then length of value buffer</exception>
+        public void SetValue(IntDataType type, int value, int offset)
+        {
+            Impl.SetValue(type, value, offset);
+        }
+
+        /// <summary>
+        /// Returns value at specified offset as float value of specified type
+        /// </summary>
+        /// <param name="type">type of float value</param>
+        /// <param name="offset">offset in the attribute value buffer</param>
+        /// <returns>float value at given offset</returns>
+        /// <exception cref="InvalidOperationException">Throws excetion if (offset + size of float value) is greater then length of value buffer</exception>
+        public float GetValue(FloatDataType type, int offset)
+        {
+            return Impl.GetValue(type, offset);
+        }
+
+        /// <summary>
+        /// Update Value at specified offset by float value of specified type
+        /// </summary>
+        /// <param name="type">type of float value</param>
+        /// <param name="mantissa">mantissa of float value</param>
+        /// <param name="exponent">exponent of float value</param>
+        /// <param name="offset">offset in the attribute value buffer</param>
+        /// <exception cref="InvalidOperationException">Throws excetion if (offset + size of float value) is greater then length of value buffer</exception>
+        public void SetValue(FloatDataType type, int mantissa, int exponent, int offset)
+        {
+            Impl.SetValue(type, mantissa, exponent, offset);
+        }
+
+        internal void ReleaseHandleOwnership()
+        {
+            Impl.ReleaseHandleOwnership();
+        }
+
+        internal BluetoothGattAttributeHandle GetHandle()
+        {
+            return Impl.GetHandle();
+        }
+    }
+}
diff --git a/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothGattImpl.cs b/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothGattImpl.cs
new file mode 100644 (file)
index 0000000..450169b
--- /dev/null
@@ -0,0 +1,716 @@
+/*
+ * 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.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tizen.Network.Bluetooth
+{
+    internal class BluetoothGattServerImpl
+    {
+        private BluetoothGattServerHandle _handle;
+        internal event EventHandler<NotificationSentEventArg> _notificationSent;
+
+        internal BluetoothGattServerImpl()
+        {
+            int err = Interop.Bluetooth.BtGattServerInitialize();
+            GattUtil.ThrowForError(err, "Failed to initialize server");
+
+            err = Interop.Bluetooth.BtGattServerCreate(out _handle);
+            GattUtil.ThrowForError(err, "Failed to create server");
+        }
+
+        internal void Start()
+        {
+            int err = Interop.Bluetooth.BtGattServerStart();
+            GattUtil.ThrowForError(err, "Failed to start server");
+        }
+
+        internal void RegisterGattService(BluetoothGattServer server, BluetoothGattService service)
+        {
+            int err = Interop.Bluetooth.BtGattServerRegisterService(_handle, service.GetHandle());
+            GattUtil.ThrowForError(err, "Failed to Register service");
+
+            service.SetParent(server);
+        }
+
+        internal void UnregisterGattService(BluetoothGattService service)
+        {
+            int err = Interop.Bluetooth.BtGattServerUnregisterService(_handle, service.GetHandle());
+            GattUtil.ThrowForError(err, "Failed to Unregister service");
+
+            service.UnregisterService();
+        }
+
+        internal void UnregisterAllGattServices(BluetoothGattServer server)
+        {
+            int err = Interop.Bluetooth.BtGattServerUnregisterAllServices(_handle);
+            GattUtil.ThrowForError(err, "Failed to Unregister all services");
+        }
+
+        internal BluetoothGattService GetService(BluetoothGattServer server, string uuid)
+        {
+            BluetoothGattAttributeHandle serviceHandle;
+            int err = Interop.Bluetooth.BtGattServerGetService(_handle, uuid, out serviceHandle);
+            if (err.IsFailed())
+            {
+                GattUtil.Error(err, string.Format("Failed to get service with UUID ({0})", uuid));
+                return null;
+            }
+
+            BluetoothGattService service = new BluetoothGattService(new BluetoothGattServiceImpl(serviceHandle), uuid); ;
+            service.SetParent(server);
+            return service;
+        }
+
+        internal IEnumerable<BluetoothGattService> GetServices(BluetoothGattServer server)
+        {
+            List<BluetoothGattService> attribututeList = new List<BluetoothGattService>();
+            Interop.Bluetooth.BtGattForeachCallback cb = (total, index, attributeHandle, userData) =>
+            {
+                BluetoothGattAttributeHandle handle = new BluetoothGattAttributeHandle(attributeHandle, false);
+                BluetoothGattService service = BluetoothGattServiceImpl.CreateBluetoothGattService(handle, ""); ;
+                if (service != null)
+                {
+                    service.SetParent(server);
+                    attribututeList.Add(service);
+                }
+                return true;
+            };
+
+            int err = Interop.Bluetooth.BtGattServerForeachServices(_handle, cb, IntPtr.Zero);
+            GattUtil.Error(err, "Failed to get all services");
+
+            return attribututeList;
+        }
+
+        internal void SendResponse(int requestId, int status, byte[] value, int offset)
+        {
+            int err = Interop.Bluetooth.BtGattServerSendResponse(requestId, 0, offset, status, value, value.Length);
+            GattUtil.ThrowForError(err, string.Format("Failed to send response for request Id {0}", requestId));
+        }
+
+        internal void SendNotification(BluetoothGattCharacteristic characteristic, string clientAddress)
+        {
+            int err = Interop.Bluetooth.BtGattServerNotify(characteristic.GetHandle(), false, null, clientAddress, IntPtr.Zero);
+            GattUtil.ThrowForError(err, string.Format("Failed to send value changed notification for characteristic uuid {0}", characteristic.Uuid));
+        }
+
+        internal Task<bool> SendIndicationAsync(BluetoothGattServer server, BluetoothGattCharacteristic characteristic, string clientAddress)
+        {
+            TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
+            Interop.Bluetooth.BtGattServerNotificationSentCallback cb = (result, address, serverHandle, characteristicHandle, completed, userData) =>
+            {
+                _notificationSent?.Invoke(characteristic, new NotificationSentEventArg(server, address, result, completed));
+                if (completed)
+                {
+                    tcs.SetResult(true);
+                }
+            };
+
+            int err = Interop.Bluetooth.BtGattServerNotify(characteristic.GetHandle(), true, cb, clientAddress, IntPtr.Zero);
+            GattUtil.ThrowForError(err, string.Format("Failed to send value changed indication for characteristic uuid {0}", characteristic.Uuid));
+
+            return tcs.Task;
+        }
+
+        internal BluetoothGattServerHandle GetHandle()
+        {
+            return _handle;
+        }
+    }
+
+    internal class BluetoothGattClientImpl
+    {
+        private BluetoothGattClientHandle _handle;
+
+        internal BluetoothGattClientImpl(string remoteAddress)
+        {
+            int err = Interop.Bluetooth.BtGattClientCreate(remoteAddress, out _handle);
+            GattUtil.ThrowForError(err, "Failed to get native client handle");
+        }
+
+        internal string GetRemoteAddress()
+        {
+            string remoteAddress;
+            int err = Interop.Bluetooth.BtGattClientGetRemoteAddress(_handle, out remoteAddress);
+            GattUtil.ThrowForError(err, "Failed to get remote address for this client");
+
+            return remoteAddress;
+        }
+
+        internal BluetoothGattService GetService(BluetoothGattClient client, string uuid)
+        {
+            BluetoothGattAttributeHandle serviceHandle;
+            int err = Interop.Bluetooth.BtGattClientGetService(_handle, uuid, out serviceHandle);
+            if (err.IsFailed())
+            {
+                GattUtil.Error(err, string.Format("Failed to get service with UUID ({0})", uuid));
+                return null;
+            }
+
+            BluetoothGattService service = new BluetoothGattService(new BluetoothGattServiceImpl(serviceHandle), uuid); ;
+            service.SetParent(client);
+            return service;
+        }
+
+        internal IEnumerable<BluetoothGattService> GetServices(BluetoothGattClient client)
+        {
+            List<BluetoothGattService> attribututeList = new List<BluetoothGattService>();
+            Interop.Bluetooth.BtGattForeachCallback cb = (total, index, attributeHandle, userData) =>
+            {
+                BluetoothGattAttributeHandle handle = new BluetoothGattAttributeHandle(attributeHandle, false);
+                BluetoothGattService service = BluetoothGattServiceImpl.CreateBluetoothGattService(handle, "");
+                if (service != null)
+                {
+                    service.SetParent(client);
+                    attribututeList.Add(service);
+                }
+                return true;
+            };
+
+            int err = Interop.Bluetooth.BtGattClientForeachServices(_handle, cb, IntPtr.Zero);
+            GattUtil.Error(err, "Failed to get all services");
+
+            return attribututeList;
+        }
+
+        internal Task<bool> ReadValueAsyncTask(BluetoothGattAttributeHandle handle)
+        {
+            TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
+            Interop.Bluetooth.BtGattClientRequestCompletedCallback cb = (result, requestHandle, userData) =>
+            {
+                tcs.SetResult(true);
+            };
+
+            int err = Interop.Bluetooth.BtGattClientReadValue(handle, cb, IntPtr.Zero);
+            if (err.IsFailed())
+            {
+                GattUtil.Error(err, "Failed to read value from remote device");
+                tcs.SetResult(false);
+                BluetoothErrorFactory.ThrowBluetoothException(err);
+            }
+            return tcs.Task;
+        }
+
+        internal Task<bool> WriteValueAsyncTask(BluetoothGattAttributeHandle handle)
+        {
+            TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
+            Interop.Bluetooth.BtGattClientRequestCompletedCallback cb = (result, requestHandle, userData) =>
+            {
+                tcs.SetResult(true);
+            };
+
+            int err = Interop.Bluetooth.BtGattClientWriteValue(handle, cb, IntPtr.Zero);
+            if (err.IsFailed())
+            {
+                GattUtil.Error(err, "Failed to write value to remote device");
+                tcs.SetResult(false);
+                BluetoothErrorFactory.ThrowBluetoothException(err);
+            }
+            return tcs.Task;
+        }
+
+        internal BluetoothGattClientHandle GetHandle()
+        {
+            return _handle;
+        }
+    }
+
+    internal class BluetoothGattServiceImpl : BluetoothGattAttributeImpl
+    {
+        internal BluetoothGattServiceImpl(string uuid, BluetoothGattServiceType type)
+        {
+            int err = Interop.Bluetooth.BtGattServiceCreate(uuid, (int)type, out _handle);
+            GattUtil.ThrowForError(err, "Failed to get native service handle");
+        }
+
+        internal BluetoothGattServiceImpl(BluetoothGattAttributeHandle handle)
+        {
+            _handle = handle;
+        }
+
+        internal static BluetoothGattService CreateBluetoothGattService(BluetoothGattAttributeHandle handle, string uuid)
+        {
+            if (uuid == "")
+            {
+                int err = Interop.Bluetooth.BtGattGetUuid(handle, out uuid);
+                GattUtil.ThrowForError(err, "Failed to get UUID");
+            }
+
+            BluetoothGattServiceImpl impl = new BluetoothGattServiceImpl(handle);
+            return new BluetoothGattService(impl, uuid);
+        }
+
+        internal void AddCharacteristic(BluetoothGattCharacteristic characteristic)
+        {
+            int err = Interop.Bluetooth.BtGattServiceAddCharacteristic(_handle, characteristic.GetHandle());
+            GattUtil.ThrowForError(err, string.Format("Failed to add characteristic with UUID ({0})", characteristic.Uuid));
+        }
+
+        internal BluetoothGattCharacteristic GetCharacteristic(BluetoothGattService service, string uuid)
+        {
+            BluetoothGattAttributeHandle attributeHandle;
+            int err = Interop.Bluetooth.BtGattServiceGetCharacteristic(_handle, uuid, out attributeHandle);
+            if (err.IsFailed())
+            {
+                GattUtil.Error(err, string.Format("Failed to get Characteristic with UUID ({0})", uuid));
+                return null;
+            }
+
+            BluetoothGattCharacteristic Characteristic = BluetoothGattCharacteristicImpl.CreateBluetoothGattGattCharacteristic(attributeHandle, uuid);
+            Characteristic.SetParent(service);
+            return Characteristic;
+        }
+
+        internal IEnumerable<BluetoothGattCharacteristic> GetCharacteristics(BluetoothGattService service)
+        {
+            List<BluetoothGattCharacteristic> attribututeList = new List<BluetoothGattCharacteristic>();
+            Interop.Bluetooth.BtGattForeachCallback cb = (total, index, attributeHandle, userData) =>
+            {
+                BluetoothGattAttributeHandle handle = new BluetoothGattAttributeHandle(attributeHandle, false);
+                BluetoothGattCharacteristic Characteristic = BluetoothGattCharacteristicImpl.CreateBluetoothGattGattCharacteristic(handle, "");
+                if (Characteristic != null)
+                {
+                    Characteristic.SetParent(service);
+                    attribututeList.Add(Characteristic);
+                }
+                return true;
+            };
+
+            int err = Interop.Bluetooth.BtGattServiceForeachCharacteristics(service.GetHandle(), cb, IntPtr.Zero);
+            GattUtil.Error(err, "Failed to get all Characteristic");
+
+            return attribututeList;
+        }
+
+        internal void AddIncludeService(BluetoothGattService includedService)
+        {
+            int err = Interop.Bluetooth.BtGattServiceAddIncludedService(_handle, includedService.GetHandle());
+            GattUtil.ThrowForError(err, string.Format("Failed to add service with UUID ({0})", includedService.Uuid));
+        }
+
+        internal BluetoothGattService GetIncludeService(BluetoothGattService parentService, string uuid)
+        {
+            BluetoothGattAttributeHandle attributeHandle;
+            int err = Interop.Bluetooth.BtGattServiceGetIncludedService(_handle, uuid, out attributeHandle);
+            if (err.IsFailed())
+            {
+                GattUtil.Error(err, string.Format("Failed to get included service with UUID ({0})", uuid));
+                return null;
+            }
+
+            BluetoothGattService service = new BluetoothGattService(new BluetoothGattServiceImpl(attributeHandle), uuid);
+            service.SetParent(parentService);
+            return service;
+        }
+
+        internal IEnumerable<BluetoothGattService> GetIncludeServices(BluetoothGattService parentService)
+        {
+            List<BluetoothGattService> attribututeList = new List<BluetoothGattService>();
+            Interop.Bluetooth.BtGattForeachCallback cb = (total, index, attributeHandle, userData) =>
+            {
+                BluetoothGattAttributeHandle handle = new BluetoothGattAttributeHandle(attributeHandle, false);
+                BluetoothGattService service = BluetoothGattServiceImpl.CreateBluetoothGattService(handle, "");
+                if (service != null)
+                {
+                    service.SetParent(parentService);
+                    attribututeList.Add(service);
+                }
+                return true;
+            };
+
+            int err = Interop.Bluetooth.BtGattServiceForeachIncludedServices(parentService.GetHandle(), cb, IntPtr.Zero);
+            GattUtil.Error(err, "Failed to get all services");
+
+            return attribututeList;
+        }
+    }
+
+    internal class BluetoothGattCharacteristicImpl : BluetoothGattAttributeImpl
+    {
+        internal BluetoothGattCharacteristicImpl(string uuid, BluetoothGattPermission permission, BluetoothGattProperty property, byte[] value)
+        {
+            int err = Interop.Bluetooth.BtGattCharacteristicCreate(uuid, (int)permission, (int)property, value, value.Length, out _handle);
+            GattUtil.ThrowForError(err, "Failed to get native characteristic handle");
+        }
+
+        internal BluetoothGattCharacteristicImpl(BluetoothGattAttributeHandle handle)
+        {
+            _handle = handle;
+        }
+
+        internal static BluetoothGattCharacteristic CreateBluetoothGattGattCharacteristic(BluetoothGattAttributeHandle handle, string uuid)
+        {
+            int permission;
+            int err = Interop.Bluetooth.BtGattCharacteristicGetPermissions(handle, out permission);
+            GattUtil.ThrowForError(err, "Failed to get permissions");
+
+            if (uuid == "")
+            {
+                err = Interop.Bluetooth.BtGattGetUuid(handle, out uuid);
+                GattUtil.ThrowForError(err, "Failed to get UUID");
+            }
+
+            BluetoothGattCharacteristicImpl impl = new BluetoothGattCharacteristicImpl(handle);
+            return new BluetoothGattCharacteristic(impl, uuid, (BluetoothGattPermission)permission);
+        }
+
+        internal void SetCharacteristicValueChangedEvent(Interop.Bluetooth.BtClientCharacteristicValueChangedCallback callback)
+        {
+            int err = Interop.Bluetooth.BtGattClientSetCharacteristicValueChangedCallback(_handle, callback, IntPtr.Zero);
+            GattUtil.Error(err, "Failed to set client characteristic value changed callback");
+        }
+
+        internal void UnsetCharacteristicValueChangedEvent()
+        {
+            int err = Interop.Bluetooth.BtGattClientUnsetCharacteristicValueChangedCallback(_handle);
+            GattUtil.Error(err, "Failed to unset client characteristic value changed callback");
+        }
+
+        internal void SetNotificationStateChangedEvent(Interop.Bluetooth.BtGattServerNotificationStateChangeCallback callback)
+        {
+            int err = Interop.Bluetooth.BtGattServeSetNotificationStateChangeCallback(_handle, callback, IntPtr.Zero);
+            GattUtil.Error(err, "Failed to set characteristic notification state changed callback");
+        }
+
+        internal BluetoothGattProperty GetProperties()
+        {
+            int properties = 0 ;
+            int err = Interop.Bluetooth.BtGattCharacteristicGetProperties(_handle, out properties);
+            GattUtil.Error(err, "Failed to get characteristic properties");
+            return (BluetoothGattProperty)properties;
+        }
+
+        internal void SetProperties(BluetoothGattProperty perperties)
+        {
+            int err = Interop.Bluetooth.BtGattCharacteristicSetProperties(_handle, (int)perperties);
+            GattUtil.Error(err, "Failed to set characteristic properties");
+        }
+
+        internal BluetoothGattWriteType GetWriteType()
+        {
+            int writeType;
+            int err = Interop.Bluetooth.BtGattCharacteristicGetWriteType(_handle, out writeType);
+            GattUtil.Error(err, "Failed to get characteristic writetype");
+            return (BluetoothGattWriteType) writeType;
+        }
+
+        internal void SetWriteType(BluetoothGattWriteType writeType)
+        {
+            int err = Interop.Bluetooth.BtGattCharacteristicSetWriteType(_handle, (int)writeType);
+            GattUtil.Error(err, "Failed to get characteristic writetype");
+        }
+
+        internal void AddDescriptor(BluetoothGattDescriptor descriptor)
+        {
+            int err = Interop.Bluetooth.BtGattCharacteristicAddDescriptor(_handle, descriptor.GetHandle());
+            GattUtil.ThrowForError(err, string.Format("Failed to add descriptor with UUID ({0})", descriptor.Uuid));
+        }
+
+        internal BluetoothGattDescriptor GetDescriptor(BluetoothGattCharacteristic characteristic, string uuid)
+        {
+            BluetoothGattAttributeHandle handle;
+            int err = Interop.Bluetooth.BtGattCharacteristicGetDescriptor(_handle, uuid, out handle);
+            if (err.IsFailed())
+            {
+                GattUtil.Error(err, string.Format("Failed to get descriptor with UUID ({0})", uuid));
+                return null;
+            }
+            BluetoothGattDescriptor descriptor = BluetoothGattDescriptorImpl.CreateBluetoothGattDescriptor(handle, uuid);
+            descriptor.SetParent(characteristic);
+            return descriptor;
+        }
+
+        internal IEnumerable<BluetoothGattDescriptor> GetDescriptors(BluetoothGattCharacteristic characteristic)
+        {
+            List<BluetoothGattDescriptor> attribututeList = new List<BluetoothGattDescriptor>();
+            Interop.Bluetooth.BtGattForeachCallback cb = (total, index, attributeHandle, userData) =>
+            {
+                BluetoothGattAttributeHandle handle = new BluetoothGattAttributeHandle(attributeHandle, false);
+                BluetoothGattDescriptor descriptor = BluetoothGattDescriptorImpl.CreateBluetoothGattDescriptor(handle, "");
+                if (descriptor != null)
+                {
+                    descriptor.SetParent(characteristic);
+                    attribututeList.Add(descriptor);
+                }
+                return true;
+            };
+
+            int err = Interop.Bluetooth.BtGattCharacteristicForeachDescriptors(characteristic.GetHandle(), cb, IntPtr.Zero);
+            GattUtil.Error(err, "Failed to get all descriptor");
+
+            return attribututeList;
+        }
+    }
+
+    internal class BluetoothGattDescriptorImpl : BluetoothGattAttributeImpl
+    {
+        internal BluetoothGattDescriptorImpl(string uuid, BluetoothGattPermission permission, byte[] value)
+        {
+            int err = Interop.Bluetooth.BtGattDescriptorCreate(uuid, (int)permission, value, value.Length, out _handle);
+            GattUtil.ThrowForError(err, "Failed to get native descriptor handle");
+        }
+
+        internal BluetoothGattDescriptorImpl(BluetoothGattAttributeHandle handle)
+        {
+            _handle = handle;
+        }
+
+        internal static BluetoothGattDescriptor CreateBluetoothGattDescriptor(BluetoothGattAttributeHandle handle, string uuid)
+        {
+            int permission;
+            int err = Interop.Bluetooth.BtGattDescriptorGetPermissions(handle, out permission);
+            GattUtil.ThrowForError(err, string.Format("Failed to get permissions with UUID ({0})", uuid));
+
+            if (uuid == "")
+            {
+                int ret = Interop.Bluetooth.BtGattGetUuid(handle, out uuid);
+                GattUtil.ThrowForError(ret, "Failed to get UUID");
+            }
+
+            BluetoothGattDescriptorImpl impl = new BluetoothGattDescriptorImpl(handle);
+            return new BluetoothGattDescriptor(impl, uuid, (BluetoothGattPermission)permission);
+        }
+    }
+
+    internal abstract class BluetoothGattAttributeImpl
+    {
+        protected BluetoothGattAttributeHandle _handle;
+
+        internal string GetUuid()
+        {
+            string uuid;
+            int err = Interop.Bluetooth.BtGattGetUuid(_handle, out uuid);
+            GattUtil.Error(err, "Failed to get attribute uuid");
+
+            return uuid;
+        }
+
+        internal byte[] GetValue()
+        {
+            IntPtr nativeValue;
+            int nativeValueLength;
+            int err = Interop.Bluetooth.BtGattGetValue(_handle, out nativeValue, out nativeValueLength);
+            GattUtil.Error(err, "Failed to get attribute value");
+
+            return GattUtil.IntPtrToByteArray(nativeValue, nativeValueLength);
+        }
+
+        internal void SetValue(byte[] value)
+        {
+            int err = Interop.Bluetooth.BtGattSetValue(_handle, value, value.Length);
+            GattUtil.ThrowForError(err, "Failed to set attribute value");
+        }
+
+        internal string GetValue(int offset)
+        {
+            byte[] value = GetValue();
+
+            int nullPos = value.Length - offset;
+            for (int i = offset; i < value.Length; ++i)
+            {
+                if (value[i] == '\0')
+                {
+                    nullPos = i;
+                    break;
+                }
+            }
+
+            string strValue = "";
+            strValue = Encoding.UTF8.GetString(value, offset, nullPos - offset);
+            return strValue;
+        }
+
+        internal void SetValue(string value, int offset)
+        {
+            byte[] byteValue = GetValue();
+            byte[] strValue = Encoding.UTF8.GetBytes(value);
+            int length = offset + strValue.Length;
+            if (length >= byteValue.Length)
+            {
+                GattUtil.ThrowForError((int)BluetoothError.InvalidParameter, "Can not fit value to buffer");
+            }
+
+            Buffer.BlockCopy(strValue, 0, byteValue, offset, strValue.Length);
+            byteValue[length] = (byte)'\0';
+            SetValue(byteValue);
+        }
+
+        internal int GetValue(IntDataType type, int offset)
+        {
+            int value;
+            int err = Interop.Bluetooth.BtGattGetIntValue(_handle, (int)type, offset, out value);
+            GattUtil.Error(err, "Failed to get attribute int value at offset");
+            return value;
+        }
+
+        internal void SetValue(IntDataType type, int value, int offset)
+        {
+            int err = Interop.Bluetooth.BtGattSetIntValue(_handle, (int)type, value, offset);
+            GattUtil.ThrowForError(err, "Failed to set attribute int value at offset");
+        }
+
+        internal float GetValue(FloatDataType type, int offset)
+        {
+            float value;
+            int err = Interop.Bluetooth.BtGattGetFloatValue(_handle, (int)type, offset, out value);
+            GattUtil.Error(err, "Failed to get attribute float value at offset");
+            return value;
+        }
+
+        internal void SetValue(FloatDataType type, int mantissa, int exponent, int offset)
+        {
+            int err = Interop.Bluetooth.BtGattSetFloatValue(_handle, (int)type, mantissa, exponent, offset);
+            GattUtil.ThrowForError(err, "Failed to set attribute float value at offset");
+        }
+
+        internal void SetReadValueRequestedEventCallback(Interop.Bluetooth.BtGattServerReadValueRequestedCallback callback)
+        {
+            int err = Interop.Bluetooth.BtGattServerSetReadValueRequestedCallback(_handle, callback, IntPtr.Zero);
+            GattUtil.ThrowForError(err, "Failed to set attribute read value requested callback");
+        }
+
+        internal void SetWriteValueRequestedEventCallback(Interop.Bluetooth.BtGattServerWriteValueRequestedCallback callback)
+        {
+            int err = Interop.Bluetooth.BtGattServerSetWriteValueRequestedCallback(_handle, callback, IntPtr.Zero);
+            GattUtil.ThrowForError(err, "Failed to set attribute write value requested callback");
+        }
+
+        internal BluetoothGattAttributeHandle GetHandle()
+        {
+            return _handle;
+        }
+
+        internal void ReleaseHandleOwnership()
+        {
+            _handle.ReleaseOwnership();
+        }
+    }
+
+
+    internal class BluetoothGattAttributeHandle : BluetoothGattHandle
+    {
+        public BluetoothGattAttributeHandle(IntPtr nativeHandle, bool hasOwnership) : base(nativeHandle, hasOwnership)
+        {
+        }
+
+        public BluetoothGattAttributeHandle()
+        {
+        }
+
+        protected override bool ReleaseHandle()
+        {
+            if (_hasOwnership == true)
+            {
+                Interop.Bluetooth.BtGattDestroy(handle);
+            }
+            SetHandle(IntPtr.Zero);
+            return true;
+        }
+    }
+
+    internal class BluetoothGattClientHandle : BluetoothGattHandle
+    {
+        protected override bool ReleaseHandle()
+        {
+            if (_hasOwnership == true)
+            {
+                Interop.Bluetooth.BtGattClientDestroy(handle);
+                Interop.Bluetooth.BtGattServerDeinitialize();
+            }
+            SetHandle(IntPtr.Zero);
+            return true;
+        }
+    }
+
+    internal class BluetoothGattServerHandle : BluetoothGattHandle
+    {
+        protected override bool ReleaseHandle()
+        {
+            if (_hasOwnership == true)
+            {
+                Interop.Bluetooth.BtGattServerDestroy(handle);
+            }
+            SetHandle(IntPtr.Zero);
+            return true;
+        }
+    }
+
+    internal abstract class BluetoothGattHandle : SafeHandle
+    {
+        protected bool _hasOwnership;
+
+        public BluetoothGattHandle() : base(IntPtr.Zero, true)
+        {
+            _hasOwnership = true;
+        }
+
+        public BluetoothGattHandle(IntPtr nativeHandle, bool hasOwnership) : base(nativeHandle, true)
+        {
+            _hasOwnership = hasOwnership;
+        }
+
+        public override bool IsInvalid
+        {
+            get { return handle == IntPtr.Zero; }
+        }
+
+        public void ReleaseOwnership()
+        {
+            _hasOwnership = false;
+        }
+    }
+
+    internal static class GattUtil
+    {
+        internal static byte[] IntPtrToByteArray(IntPtr nativeValue, int lenght)
+        {
+            byte[] value = new byte[lenght];
+            if (nativeValue != IntPtr.Zero)
+            {
+                Marshal.Copy(nativeValue, value, 0, lenght);
+            }
+            return value;
+        }
+
+        internal static void Error(int err, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
+        {
+            if (err.IsFailed())
+            {
+                Log.Error(Globals.LogTag, string.Format("{0}, err: {1}", message, (BluetoothError)err), file, func, line);
+            }
+        }
+
+        internal static void ThrowForError(int err, string message, [CallerFilePath] string file = "", [CallerMemberName] string func = "", [CallerLineNumber] int line = 0)
+        {
+            if (err.IsFailed())
+            {
+                Log.Error(Globals.LogTag, string.Format("{0}, err: {1}", message, (BluetoothError)err), file, func, line);
+                BluetoothErrorFactory.ThrowBluetoothException(err);
+            }
+        }
+
+        internal static bool IsFailed(this int err)
+        {
+            return err != (int)BluetoothError.None;
+        }
+    }
+}
diff --git a/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothHid.cs b/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothHid.cs
new file mode 100644 (file)
index 0000000..e546dd1
--- /dev/null
@@ -0,0 +1,75 @@
+using System;
+
+namespace Tizen.Network.Bluetooth
+{
+    /// <summary>
+    /// A class which is used to handle the connection to Bluetooth HID like keyboards and mouse.
+    /// </summary>
+    /// <privilege> http://tizen.org/privilege/bluetooth </privilege>
+    public class BluetoothHid : BluetoothProfile
+    {
+        internal BluetoothHid()
+        {
+        }
+
+        /// <summary>
+        /// (event) HidConnectionStateChanged is called when hid host connection state is changed.
+        /// </summary>
+        public event EventHandler<HidConnectionStateChangedEventArgs> HidConnectionStateChanged
+        {
+            add
+            {
+                BluetoothHidImpl.Instance.HidConnectionStateChanged += value;
+            }
+            remove
+            {
+                BluetoothHidImpl.Instance.HidConnectionStateChanged -= value;
+            }
+        }
+
+        /// <summary>
+        /// Connect the remote device with the Hid service.
+        /// </summary>
+        /// <remarks>
+        /// The device must be bonded with remote device by CreateBond().
+        /// If connection request succeeds, HidConnectionStateChanged event will be invoked.
+        /// </remarks>
+        public void Connect()
+        {
+            if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                int ret = BluetoothHidImpl.Instance.Connect(RemoteAddress);
+                if (ret != (int)BluetoothError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to Connect - " + (BluetoothError)ret);
+                    BluetoothErrorFactory.ThrowBluetoothException(ret);
+                }
+            }
+            else
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
+        }
+
+        /// <summary>
+        /// Disconnects the remote device with the Hid service.
+        /// </summary>
+        public void Disconnect()
+        {
+            if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                int ret = BluetoothHidImpl.Instance.Disconnect(RemoteAddress);
+                if (ret != (int)BluetoothError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to Disconnect - " + (BluetoothError)ret);
+                    BluetoothErrorFactory.ThrowBluetoothException(ret);
+                }
+            }
+            else
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
+        }
+    }
+}
+
diff --git a/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothHidImpl.cs b/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothHidImpl.cs
new file mode 100644 (file)
index 0000000..b8a9122
--- /dev/null
@@ -0,0 +1,148 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+
+namespace Tizen.Network.Bluetooth
+{
+    internal class BluetoothHidImpl : IDisposable
+    {
+        private event EventHandler<HidConnectionStateChangedEventArgs> _hidConnectionChanged;
+        private Interop.Bluetooth.HidConnectionStateChangedCallback _hidConnectionChangedCallback;
+
+        private static readonly BluetoothHidImpl _instance = new BluetoothHidImpl();
+        private bool disposed = false;
+
+        internal event EventHandler<HidConnectionStateChangedEventArgs> HidConnectionStateChanged
+        {
+            add
+            {
+                _hidConnectionChanged += value;
+            }
+            remove
+            {
+                //nothing to be done
+            }
+        }
+
+        internal int Connect(string deviceAddress)
+        {
+            if (Globals.IsHidInitialize)
+            {
+                int ret = Interop.Bluetooth.Connect (deviceAddress);
+                if (ret != (int)BluetoothError.None) {
+                    Log.Error (Globals.LogTag, "Failed to connect device with the hid service, Error - " + (BluetoothError)ret);
+                }
+                return ret;
+            }
+            return (int)BluetoothError.NotInitialized;
+        }
+
+        internal int Disconnect(string deviceAddress)
+        {
+            if (Globals.IsHidInitialize)
+            {
+                int ret = Interop.Bluetooth.Disconnect (deviceAddress);
+                if (ret != (int)BluetoothError.None) {
+                    Log.Error (Globals.LogTag, "Failed to disconnect device with the hid service, Error - " + (BluetoothError)ret);
+                }
+                return ret;
+            }
+            return (int)BluetoothError.NotInitialized;
+        }
+
+        internal static BluetoothHidImpl Instance
+        {
+            get
+            {
+                return _instance;
+            }
+        }
+        private BluetoothHidImpl ()
+        {
+            initialize();
+        }
+        ~BluetoothHidImpl()
+        {
+            Dispose(false);
+        }
+
+        public void Dispose()
+        {
+            Dispose(true);
+            GC.SuppressFinalize(this);
+        }
+
+        private void Dispose(bool disposing)
+        {
+            if (disposed)
+                return;
+
+            if (disposing)
+            {
+                // Free managed objects.
+            }
+            //Free unmanaged objects
+            deinitialize();
+            disposed = true;
+        }
+
+        private void initialize()
+        {
+            if (Globals.IsInitialize)
+            {
+                _hidConnectionChangedCallback = (int result, bool connected, string deviceAddress, IntPtr userData) =>
+                {
+                    if (_hidConnectionChanged != null)
+                    {
+                        _hidConnectionChanged(null, new HidConnectionStateChangedEventArgs(result, connected, deviceAddress));
+                    }
+                };
+
+                int ret = Interop.Bluetooth.InitializeHid (_hidConnectionChangedCallback, IntPtr.Zero);
+                if (ret != (int)BluetoothError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to initialize bluetooth hid, Error - " + (BluetoothError)ret);
+                    BluetoothErrorFactory.ThrowBluetoothException (ret);
+                }
+                else
+                {
+                    Globals.IsHidInitialize = true;
+                }
+            }
+            else
+            {
+                Log.Error(Globals.LogTag, "Failed to initialize HID, BT not initialized");
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotInitialized);
+            }
+        }
+
+        private void deinitialize()
+        {
+            if (Globals.IsHidInitialize)
+            {
+                int ret = Interop.Bluetooth.DeinitializeHid ();
+                if (ret != (int)BluetoothError.None) {
+                    Log.Error (Globals.LogTag, "Failed to deinitialize bluetooth hid, Error - " + (BluetoothError)ret);
+                    BluetoothErrorFactory.ThrowBluetoothException (ret);
+                } else {
+                    Globals.IsHidInitialize = false;
+                }
+            }
+        }
+    }
+}
+
diff --git a/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothLeAdapter.cs b/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothLeAdapter.cs
new file mode 100644 (file)
index 0000000..92c3355
--- /dev/null
@@ -0,0 +1,765 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Threading.Tasks;
+using System.Collections.Generic;
+using System.Collections.Specialized;
+using System.Runtime.InteropServices;
+
+namespace Tizen.Network.Bluetooth {
+
+    /// <summary>
+    /// This class is BluetoothLeAdvertiser. Handles the Le Advertising operation amd callback.
+    /// </summary>
+    public class BluetoothLeAdvertiser
+    {
+        private static readonly BluetoothLeAdvertiser _instance = new BluetoothLeAdvertiser();
+
+        internal static BluetoothLeAdvertiser Instance
+        {
+            get
+            {
+                return _instance;
+            }
+        }
+
+        private BluetoothLeAdvertiser()
+        {
+        }
+
+        /// <summary>
+        /// Event that is called when the LE advertising state changes
+        /// </summary>
+        public event EventHandler<AdvertisingStateChangedEventArgs> AdvertisingStateChanged
+        {
+            add
+            {
+                BluetoothLeImplAdapter.Instance.AdapterLeAdvertisingStateChanged += value;
+            }
+            remove
+            {
+                BluetoothLeImplAdapter.Instance.AdapterLeAdvertisingStateChanged -= value;
+            }
+        }
+        /// <summary>
+        /// Start advertising using the advertisedata object.
+        /// </summary>
+        /// <remarks>
+        /// Bluetooth must be enabled.
+        /// </remarks>
+        /// <param name="advertiseData">The advertiser object carrying information of the advertising.</param>
+        public void StartAdvertising(BluetoothLeAdvertiseData advertiseData)
+        {
+            if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                int ret = BluetoothLeImplAdapter.Instance.StartAdvertising (advertiseData.GetHandle ());
+                if (ret != (int)BluetoothError.None) {
+                    Log.Error (Globals.LogTag, "Failed to start advertising- " + (BluetoothError)ret);
+                    BluetoothErrorFactory.ThrowBluetoothException(ret);
+                }
+            }
+            else
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
+        }
+
+        /// <summary>
+        /// Stops the advertising.
+        /// </summary>
+        /// <remarks>
+        /// Bluetooth must be enabled.
+        /// </remarks>
+        /// <param name="advertiseData">The advertiser object carrying information of the advertising.</param>
+        public void StopAdvertising(BluetoothLeAdvertiseData advertiseData)
+        {
+            if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                int ret = BluetoothLeImplAdapter.Instance.StopAdvertising (advertiseData.GetHandle ());
+                if (ret != (int)BluetoothError.None) {
+                    Log.Error (Globals.LogTag, "Failed to stop advertising operation- " + (BluetoothError)ret);
+                    BluetoothErrorFactory.ThrowBluetoothException(ret);
+                }
+            }
+            else
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
+        }
+    }
+
+    /// <summary>
+    /// This class is BluetoothLeDevice.
+    /// Handles the Le device operations like getting data from the scan result information.
+    /// </summary>
+    public class BluetoothLeDevice
+    {
+        //properties of Bluetoothlesacandata
+        private string _remoteAddress;
+        private BluetoothLeDeviceAddressType _addressType;
+        private int _rssi;
+        private byte[] _advDataValue;
+        private byte[] _scanDataValue;
+        private BluetoothLePacketType _packetType;
+        private BluetoothLeScanData _scanData;
+
+        /// <summary>
+        /// Event that is called when the Gatt client connects/disconnects with the server
+        /// </summary>
+        public event EventHandler<GattConnectionStateChangedEventArgs> GattConnectionStateChanged
+        {
+            add
+            {
+                BluetoothLeImplAdapter.Instance.LeGattConnectionStateChanged += value;
+            }
+            remove
+            {
+                BluetoothLeImplAdapter.Instance.LeGattConnectionStateChanged -= value;
+            }
+        }
+
+        internal BluetoothLeDevice(BluetoothLeScanData scanData)
+        {
+            _scanData = new BluetoothLeScanData ();
+            _scanData = scanData;
+
+            Log.Info (Globals.LogTag, "scanData.Rssi" + _scanData.Rssi);
+            _rssi = scanData.Rssi;
+            Log.Info (Globals.LogTag, "scanData.RemoteAddress" + _scanData.RemoteAddress);
+            if (scanData.RemoteAddress != null)
+                _remoteAddress = scanData.RemoteAddress;
+            Log.Info (Globals.LogTag, "scanData.AddressType" + _scanData.AddressType);
+            _addressType = scanData.AddressType;
+            Log.Info (Globals.LogTag, "scanData.AdvData" + _scanData.AdvData);
+            _advDataValue = new byte[_scanData.AdvDataLength];
+            scanData.AdvData.CopyTo(_advDataValue, 0);
+            Log.Info (Globals.LogTag, "scanData.ScanData" + _scanData.ScanData);
+            _scanDataValue = new byte[_scanData.ScanDataLength];
+            scanData.ScanData.CopyTo(_scanDataValue, 0);
+        }
+
+        ~BluetoothLeDevice()
+        {
+            if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                BluetoothLeImplAdapter.Instance.FreeServiceDataList();
+            }
+        }
+
+        /// <summary>
+        /// The remote address.
+        /// </summary>
+        public string RemoteAddress
+        {
+            get
+            {
+                return _remoteAddress;
+            }
+        }
+
+        /// <summary>
+        /// The type of the address.
+        /// </summary>
+        public BluetoothLeDeviceAddressType AddressType
+        {
+            get
+            {
+                return _addressType;
+            }
+        }
+
+        /// <summary>
+        /// The rssi value.
+        /// </summary>
+        public int Rssi
+        {
+            get
+            {
+                return _rssi;
+            }
+        }
+
+        /// <summary>
+        /// The advertsing data information.
+        /// </summary>
+        public byte[] AdvertsingDataInformation
+        {
+            get
+            {
+                return _advDataValue;
+            }
+        }
+
+        /// <summary>
+        /// The scan data information.
+        /// </summary>
+        public byte[] ScanDataInformation
+        {
+            get
+            {
+                return _scanDataValue;
+            }
+        }
+
+        /// <summary>
+        /// The type of the packet.
+        /// </summary>
+        public BluetoothLePacketType PacketType
+        {
+            get
+            {
+                return _packetType;
+            }
+            set
+            {
+                _packetType = value;
+            }
+        }
+
+        /// <summary>
+        /// Get service uuids list from the Le scan result information
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        /// <returns> Returns list of string service uuids.
+        public IEnumerable<string> ServiceUuid
+        {
+            get
+            {
+                if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+                {
+                    Log.Info(Globals.LogTag, "Retrieving Service uuid- ");
+                    return BluetoothLeImplAdapter.Instance.GetLeScanResultServiceUuids(_scanData, _packetType);
+                }
+                return null;
+            }
+        }
+
+        /// <summary>
+        /// Get device name from the Le scan result information
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        /// <returns>  Returns device name.
+        public string DeviceName
+        {
+            get
+            {
+                Log.Info(Globals.LogTag, "Retrieving device name- ");
+                if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+                {
+                    return BluetoothLeImplAdapter.Instance.GetLeScanResultDeviceName(_scanData, _packetType);
+                }
+                return null;
+            }
+        }
+        /// <summary>
+        ///  Get transmission power level from the Le scan result information
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        /// <returns> Returns the transmission power level in dB.
+        public int TxPowerLevel
+        {
+            get
+            {
+                if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+                {
+                    return BluetoothLeImplAdapter.Instance.GetScanResultTxPowerLevel(_scanData, _packetType);
+                }
+                return -1;
+            }
+        }
+
+        /// <summary>
+        /// Get service solicitation uuid list from the scan result information
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        /// <returns> Returns list of service solicitation uuids.
+        public IEnumerable<string> ServiceSolictationUuid
+        {
+            get
+            {
+                if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+                {
+                    return BluetoothLeImplAdapter.Instance.GetScanResultSvcSolicitationUuids(_scanData, _packetType);
+                }
+                return null;
+            }
+        }
+        /// <summary>
+        /// Gets the manufacturer data from the scan result information
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        /// <returns> Returns the appearance value.
+        public int Appearance
+        {
+            get
+            {
+                if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+                {
+                    return BluetoothLeImplAdapter.Instance.GetScanResultAppearance(_scanData, _packetType);
+                }
+                return -1;
+            }
+        }
+        /// <summary>
+        /// Gets the manufacturer data from the scan result information
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        /// <returns> Returns the manufacturer data containing the manucturer data and id information.
+        public ManufacturerData ManufacturerData
+        {
+            get
+            {
+                if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+                {
+                    return BluetoothLeImplAdapter.Instance.GetScanResultManufacturerData(_scanData, _packetType);
+                }
+                return null;
+            }
+        }
+
+        /// <summary>
+        /// Get service data list from the scan result information
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        /// <returns> Returns the  service data list.
+        public IEnumerable<BluetoothLeServiceData> GetServiceDataList()
+        {
+            int serviceCount = 0;
+            if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                return BluetoothLeImplAdapter.Instance.GetScanResultServiceDataList(_scanData,
+                                            _packetType, out serviceCount);
+            }
+            return null;
+        }
+
+
+        /// <summary>
+        /// Creates a GATT connection with the remote device.
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        /// <param name="autoConnect"> The auto connect flag</param>
+        /// <returns>client instance</returns>
+        public BluetoothGattClient GattConnect(bool autoConnect)
+        {
+            BluetoothGattClient client = null;
+            if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                int ret = BluetoothLeImplAdapter.Instance.GattConnect (_remoteAddress, autoConnect);
+                if (ret != (int)BluetoothError.None) {
+                    Log.Error (Globals.LogTag, "Failed to create GATT Connection with remote device- " + (BluetoothError)ret);
+                }
+                else
+                {
+                    client = BluetoothGattClient.CreateClient(_remoteAddress);
+                }
+            }
+            else
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
+            return client;
+        }
+
+        /// <summary>
+        /// Disconnect a GATT connection with the remote device.
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        public void GattDisconnect()
+        {
+            if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                int ret = BluetoothLeImplAdapter.Instance.GattDisconnect (_remoteAddress);
+                if (ret != (int)BluetoothError.None) {
+                    Log.Error (Globals.LogTag, "Failed to disconnect GATT connection with remote device- " + (BluetoothError)ret);
+                }
+            }
+            else
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
+        }
+    }
+
+    /// <summary>
+    /// Bluetooth le advertise data. Handles the data advertising.
+    /// </summary>
+    public class BluetoothLeAdvertiseData:IDisposable
+    {
+        private IntPtr _handle = IntPtr.Zero;
+        private BluetoothLeAdvertisingMode _mode;
+        private bool _advertisingConnectable;
+        private BluetoothLePacketType _packetType;
+        private int _appearance;
+        private bool _includePowerLevel;
+        private bool _includeDeviceName;
+
+        /// <summary>
+        /// Default Constructor.Initializes an object of BluetoothLeAdvertiseData
+        /// </summary>
+        public BluetoothLeAdvertiseData()
+        {
+            if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                Log.Debug(Globals.LogTag, " Creating LeAdvertiser()");
+                int ret = Interop.Bluetooth.CreateAdvertiser(out _handle);
+                if (ret != (int)BluetoothError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to create advertiser object- " + (BluetoothError)ret);
+                    BluetoothErrorFactory.ThrowBluetoothException(ret);
+                }
+            }
+            else
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
+        }
+
+        ~BluetoothLeAdvertiseData()
+        {
+            if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                //clean-up
+                ClearAdvertisingData (BluetoothLePacketType.BluetoothLeAdvertisingPacket);
+                ClearAdvertisingData (BluetoothLePacketType.BluetoothLeScanResponsePacket);
+                BluetoothLeImplAdapter.Instance.DestroyAdvertiser (_handle);
+            }
+            Dispose(false);
+        }
+
+        internal IntPtr GetHandle()
+        {
+            return _handle;
+        }
+
+        /// <summary>
+        /// The advertising mode to control the advertising power and latency.
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        public BluetoothLeAdvertisingMode AdvertisingMode
+        {
+            get
+            {
+                return _mode;
+            }
+            set
+            {
+                if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+                {
+                    _mode = value;
+                    int ret = Interop.Bluetooth.SetAdvertisingMode (GetHandle (), _mode);
+                    if (ret != (int)BluetoothError.None) {
+                        Log.Error (Globals.LogTag, "Failed to set advertising mode- " + (BluetoothError)ret);
+                        BluetoothErrorFactory.ThrowBluetoothException (ret);
+                    }
+                }
+            }
+        }
+
+        /// <summary>
+        /// The advertising connectable type.
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        public bool AdvertisingConnectable
+        {
+            get
+            {
+                return _advertisingConnectable;
+            }
+            set
+            {
+                if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+                {
+                    _advertisingConnectable = value;
+                    int ret = Interop.Bluetooth.SetAdvertisingConnectable (GetHandle (), _advertisingConnectable);
+                    if (ret != (int)BluetoothError.None) {
+                        Log.Error (Globals.LogTag, "Failed to set advertising connectable value- " + (BluetoothError)ret);
+                        BluetoothErrorFactory.ThrowBluetoothException (ret);
+                    }
+                }
+            }
+        }
+
+        public void Dispose()
+        {
+            Dispose(true);
+            GC.SuppressFinalize(this);
+        }
+
+        private void Dispose(bool disposing)
+        {
+            //todo...
+        }
+
+        /// <summary>
+        /// The type of the packet.
+        /// </summary>
+        public BluetoothLePacketType PacketType
+        {
+            get
+            {
+                return _packetType;
+            }
+            set
+            {
+                _packetType = value;
+            }
+        }
+        /// <summary>
+        /// Sets the external appearance of this device to advertise or scan response data
+        /// Please refer to the adopted Bluetooth specification for the the appearance..
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        public int Appearance
+        {
+            get
+            {
+                return _appearance;
+            }
+            set
+            {
+                _appearance = value;
+                if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize) {
+                    int ret = Interop.Bluetooth.SetAdvertisingAppearance (GetHandle (), _packetType, _appearance);
+                    if (ret != (int)BluetoothError.None) {
+                        Log.Error (Globals.LogTag, "Failed to add appearance value to advertising data- " + (BluetoothError)ret);
+                        BluetoothErrorFactory.ThrowBluetoothException(ret);
+                    }
+                }
+            }
+        }
+        /// <summary>
+        /// Sets whether the device name has to be incuded in the advertise or scan response data
+        /// The maximum advertised or responded data size is 31 bytes including data type and system wide data.
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        public bool IncludeDeviceName
+        {
+            get
+            {
+                return _includeDeviceName;
+            }
+            set
+            {
+                _includeDeviceName = value;
+                if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+                {
+                    int ret = Interop.Bluetooth.SetAdvertisingDeviceName(GetHandle(), _packetType, _includeDeviceName);
+                    if (ret != (int)BluetoothError.None) {
+                        Log.Error (Globals.LogTag, "Failed to add device name to advertising data- " + (BluetoothError)ret);
+                        BluetoothErrorFactory.ThrowBluetoothException(ret);
+                    }
+                }
+            }
+        }
+
+
+        /// <summary>
+        /// Set whether the transmission power level should be included in advertise or scan response data.
+        /// The maximum advertised or responded data size is 31 bytes including data type and system wide data.
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        public bool IncludeTxPowerLevel
+        {
+            get
+            {
+                return _includePowerLevel;
+            }
+            set
+            {
+                _includePowerLevel = value;
+                if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+                {
+                    int ret = Interop.Bluetooth.SetAdvertisingTxPowerLevel(GetHandle(), _packetType, _includePowerLevel);
+                    if (ret != (int)BluetoothError.None)
+                    {
+                        Log.Error(Globals.LogTag, "Failed to add advertising service solicitation uuid- " + (BluetoothError)ret);
+                    }
+                }
+            }
+        }
+        /// <summary>
+        /// Add a service UUID to advertise or scan response data.
+        /// The maximum advertised or responded data size is 31 bytes
+        /// including data type and system wide data
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        /// <param name="packetType">The packet type </param>
+        /// <param name="serviceUuid"> The service uuid to add to advertise data</param>
+        public void AddAdvertisingServiceUuid(BluetoothLePacketType packetType, string serviceUuid)
+        {
+            if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                int ret = Interop.Bluetooth.AddAdvertisingServiceUuid (GetHandle (), packetType, serviceUuid);
+                if (ret != (int)BluetoothError.None) {
+                    Log.Error (Globals.LogTag, "Failed to add service uuid to advertising data- " + (BluetoothError)ret);
+                    BluetoothErrorFactory.ThrowBluetoothException (ret);
+                }
+            }
+            else
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
+        }
+
+        /// <summary>
+        /// Add a service solicitation UUID to advertise or scan response data.
+        /// The maximum advertised or responded data size is 31 bytes
+        /// including data type and system wide data.
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        /// <param name="packetType">The packet type </param>
+        /// <param name="serviceSolicitationUuid"> The service solicitation uuid to add to advertise data</param>
+        public void AddAdvertisingServiceSolicitationUuid(BluetoothLePacketType packetType,
+                                                        string serviceSolicitationUuid)
+        {
+            if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                int ret = Interop.Bluetooth.AddAdvertisingServiceSolicitationUuid(GetHandle(), packetType,
+                                                                serviceSolicitationUuid);
+                if (ret != (int)BluetoothError.None) {
+                    Log.Error (Globals.LogTag, "Failed to add service solicitation uuid to advertising data- " + (BluetoothError)ret);
+                    BluetoothErrorFactory.ThrowBluetoothException(ret);
+                }
+            }
+            else
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
+        }
+
+        /// <summary>
+        /// Add a service data to advertise or scan response data.
+        /// The maximum advertised or responded data size is 31 bytes
+        /// including data type and system wide data.
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        /// <param name="packetType">The packet type </param>
+        /// <param name="data"> The service data to be added to advertising</param>
+        public void AddAdvertisingServiceData(BluetoothLePacketType packetType, BluetoothServiceData data)
+        {
+            if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                IntPtr serviceDataPtr;
+                serviceDataPtr = Marshal.AllocHGlobal(data.DataLength);
+                Marshal.Copy(data.Data, 0, serviceDataPtr, data.DataLength);
+
+                for (int i = 0; i < 3; i++)
+                    Log.Error (Globals.LogTag, " service data is  " + data.Data [i]);
+                int ret = Interop.Bluetooth.AddAdvertisingServiceData(GetHandle(), packetType,
+                    data.Uuid, serviceDataPtr, data.DataLength);
+                if (ret != (int)BluetoothError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to add service data to advertising data- " + (BluetoothError)ret);
+                    BluetoothErrorFactory.ThrowBluetoothException(ret);
+                }
+            }
+            else
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
+        }
+
+        /// <summary>
+        /// Add manufacturer specific data to advertise or scan response data.
+        /// Please refer to the adopted Bluetooth specification for the the appearance..
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        /// <param name="packetType">The packet type</param>
+        /// <param name="manufacturerData"> The manufacturer specific data</param>
+        public void AddAdvertisingManufacturerData(BluetoothLePacketType packetType,
+                                    ManufacturerData manufacturerData)
+        {
+            if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                IntPtr manufDataPtr;
+                manufDataPtr = Marshal.AllocHGlobal(manufacturerData.DataLength);
+                Marshal.Copy(manufacturerData.Data, 0, manufDataPtr, manufacturerData.DataLength);
+
+                int ret = Interop.Bluetooth.AddAdvertisingManufData(GetHandle(), packetType,
+                    manufacturerData.Id, manufDataPtr, manufacturerData.DataLength);
+                if (ret != (int)BluetoothError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to add service solicitation uuid to advertising data- " + (BluetoothError)ret);
+                    BluetoothErrorFactory.ThrowBluetoothException(ret);
+                }
+            }
+            else
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
+        }
+
+        /// <summary>
+        /// Clear all data to be advertised or responded to scan request from LE scanning device.
+        /// </summary>
+        /// <remarks>
+        /// The Bluetooth must be enabled.
+        /// </remarks>
+        /// <param name="packetType">The packet type to be cleared</param>
+        internal void ClearAdvertisingData(BluetoothLePacketType packetType)
+        {
+            if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
+            {
+                int ret = Interop.Bluetooth.ClearAdvertisingData (GetHandle (), packetType);
+                if (ret != (int)BluetoothError.None) {
+                    Log.Error (Globals.LogTag, "Failed to Clear Advertising Data- " + (BluetoothError)ret);
+                }
+            }
+            else
+            {
+                BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
+            }
+        }
+    }
+}
diff --git a/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothLeAdapterImpl.cs b/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothLeAdapterImpl.cs
new file mode 100644 (file)
index 0000000..ae098cf
--- /dev/null
@@ -0,0 +1,469 @@
+/*
+ * 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.Collections.Specialized;
+using System.Threading.Tasks;
+using System.Runtime.InteropServices;
+
+namespace Tizen.Network.Bluetooth
+{
+    internal class BluetoothLeImplAdapter : IDisposable
+    {
+        private static readonly BluetoothLeImplAdapter _instance = new BluetoothLeImplAdapter();
+
+        private bool disposed = false;
+
+        private event EventHandler<AdapterLeScanResultChangedEventArgs> _adapterLeScanResultChanged = null;
+        private Interop.Bluetooth.AdapterLeScanResultChangedCallBack _adapterLeScanResultChangedCallback;
+
+        private event EventHandler<AdvertisingStateChangedEventArgs> _advertisingStateChanged = null;
+        private Interop.Bluetooth.AdvertisingStateChangedCallBack _advertisingStateChangedCallback;
+
+        private event EventHandler<GattConnectionStateChangedEventArgs> _gattConnectionStateChanged = null;
+        private Interop.Bluetooth.GattConnectionStateChangedCallBack _gattConnectionStateChangedCallback;
+
+        private int _serviceListCount = 0;
+        private IList<BluetoothLeServiceData> _list = new List<BluetoothLeServiceData>();
+        private bool _scanStarted;
+
+        internal static BluetoothLeImplAdapter Instance
+        {
+            get
+            {
+                return _instance;
+            }
+        }
+
+        private BluetoothLeImplAdapter()
+        {
+        }
+
+        ~BluetoothLeImplAdapter()
+        {
+            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
+            if (_gattConnectionStateChanged != null)
+            {
+                UnRegisterGattConnectionStateChangedEvent();
+            }
+
+            //stop scan operation in progress
+            StopScan ();
+
+            disposed = true;
+        }
+
+        internal event EventHandler<AdapterLeScanResultChangedEventArgs> AdapterLeScanResultChanged
+        {
+            add
+            {
+                _adapterLeScanResultChanged += value;
+            }
+            remove {
+                _adapterLeScanResultChanged -= value;
+            }
+        }
+
+        internal event EventHandler<AdvertisingStateChangedEventArgs> AdapterLeAdvertisingStateChanged
+        {
+            add
+            {
+                _advertisingStateChanged += value;
+            }
+            remove
+            {
+                _advertisingStateChanged -= value;
+            }
+        }
+
+        internal event EventHandler<GattConnectionStateChangedEventArgs> LeGattConnectionStateChanged
+        {
+            add
+            {
+                if (_gattConnectionStateChanged == null)
+                {
+                    RegisterGattConnectionStateChangedEvent();
+                }
+                _gattConnectionStateChanged += value;
+            }
+            remove
+            {
+                _gattConnectionStateChanged -= value;
+                if (_gattConnectionStateChanged == null)
+                {
+                    UnRegisterGattConnectionStateChangedEvent();
+                }
+            }
+        }
+
+        internal void RegisterGattConnectionStateChangedEvent()
+        {
+            _gattConnectionStateChangedCallback = (int result, bool connected,
+                                    string remoteDeviceAddress, IntPtr userData) =>
+            {
+                if (_gattConnectionStateChanged != null)
+                {
+                    Log.Info(Globals.LogTag, "Setting gatt connection state changed callback" );
+                    GattConnectionStateChangedEventArgs e = new GattConnectionStateChangedEventArgs (result,
+                        connected, remoteDeviceAddress);
+
+                    _gattConnectionStateChanged(null, e);
+                }
+            };
+
+            int ret = Interop.Bluetooth.SetGattConnectionStateChangedCallback(
+                                    _gattConnectionStateChangedCallback, IntPtr.Zero);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to set gatt connection state changed callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
+        internal void UnRegisterGattConnectionStateChangedEvent()
+        {
+            int ret = Interop.Bluetooth.UnsetGattConnectionStateChangedCallback();
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to unset gatt connection state changed callback, Error - " + (BluetoothError)ret);
+            }
+        }
+
+        internal int StartScan()
+        {
+            _adapterLeScanResultChangedCallback = (int result, ref BluetoothLeScanDataStruct scanData, IntPtr userData) =>
+            {
+                Log.Info(Globals.LogTag, "Inside scan callback " );
+                BluetoothLeScanData scanDataInfo = new BluetoothLeScanData();
+                scanDataInfo = BluetoothUtils.ConvertStructToLeScanData(scanData, scanDataInfo);
+
+                BluetoothLeDevice device = new BluetoothLeDevice(scanDataInfo);
+
+                AdapterLeScanResultChangedEventArgs e = new AdapterLeScanResultChangedEventArgs (result,
+                                                                    device);
+                _adapterLeScanResultChanged (null, e);
+            };
+
+            IntPtr data = IntPtr.Zero;
+            int ret = Interop.Bluetooth.StartScan(_adapterLeScanResultChangedCallback, data);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to start BLE scan - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+            _scanStarted = true;
+            return ret;
+        }
+
+        internal int StopScan()
+        {
+            int ret = (int)BluetoothError.None;
+
+            if (_scanStarted)
+            {
+                ret = Interop.Bluetooth.StopScan ();
+                if (ret != (int)BluetoothError.None) {
+                    Log.Error (Globals.LogTag, "Failed to stop BLE scan - " + (BluetoothError)ret);
+                    BluetoothErrorFactory.ThrowBluetoothException (ret);
+                }
+            }
+            return ret;
+        }
+
+        internal IList<string> GetLeScanResultServiceUuids(BluetoothLeScanData scanData, BluetoothLePacketType packetType)
+        {
+            IntPtr uuidListArray = IntPtr.Zero;
+            int count = -1;
+
+            BluetoothLeScanDataStruct scanDataStruct = new BluetoothLeScanDataStruct();
+            scanDataStruct.RemoteAddress = scanData.RemoteAddress;
+            scanDataStruct.AddressType = scanData.AddressType;
+            scanDataStruct.Rssi = scanData.Rssi;
+            scanDataStruct.AdvDataLength = scanData.AdvDataLength;
+
+            scanDataStruct.AdvData = Marshal.AllocHGlobal(scanData.AdvDataLength);
+            Marshal.Copy (scanData.AdvData, 0, scanDataStruct.AdvData, scanData.AdvDataLength);
+
+            scanDataStruct.ScanDataLength = scanData.ScanDataLength;
+            scanDataStruct.ScanData = Marshal.AllocHGlobal(scanData.ScanDataLength);
+            Marshal.Copy (scanData.ScanData, 0, scanDataStruct.ScanData, scanData.ScanDataLength);
+
+            int ret = Interop.Bluetooth.GetScanResultServiceUuid(ref scanDataStruct, packetType,
+                                                ref uuidListArray, ref count);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Info(Globals.LogTag, "Failed to service uuids list- " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+
+            Log.Info(Globals.LogTag, "count of uuids :  " + count);
+
+            IntPtr[] uuidList = new IntPtr[count];
+            Marshal.Copy(uuidListArray, uuidList, 0, count);
+            IList<string> list = new List<string>();
+            foreach(IntPtr uuids in uuidList)
+            {
+                list.Add(Marshal.PtrToStringAnsi(uuids));
+                Interop.Libc.Free(uuids);
+            }
+
+            Interop.Libc.Free(uuidListArray);
+            return list;
+        }
+
+        internal string GetLeScanResultDeviceName(BluetoothLeScanData scanData, BluetoothLePacketType packetType)
+        {
+            string deviceName;
+
+            BluetoothLeScanDataStruct scanDataStruct = new BluetoothLeScanDataStruct();
+            scanDataStruct = BluetoothUtils.ConvertLeScanDataToStruct (scanData, scanDataStruct);
+
+            int ret = Interop.Bluetooth.GetLeScanResultDeviceName(ref scanDataStruct, packetType, out deviceName);
+            if (ret != (int)BluetoothError.None) {
+                Log.Error(Globals.LogTag, "Failed to get Device name- " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+            Log.Info (Globals.LogTag, "Device name " + deviceName);
+            return deviceName;
+        }
+
+        internal int GetScanResultTxPowerLevel(BluetoothLeScanData scanData, BluetoothLePacketType packetType)
+        {
+            int powerLevel;
+            BluetoothLeScanDataStruct scanDataStruct = new BluetoothLeScanDataStruct();
+            scanDataStruct = BluetoothUtils.ConvertLeScanDataToStruct (scanData, scanDataStruct);
+
+            int ret = Interop.Bluetooth.GetScanResultTxPowerLevel(ref scanDataStruct, packetType, out powerLevel);
+            if (ret != (int)BluetoothError.None) {
+                Log.Error(Globals.LogTag, "Failed to get tx power level- " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+            Log.Info (Globals.LogTag, "TxPowerLevel is --- " + powerLevel);
+            return powerLevel;
+        }
+
+        internal IList<string> GetScanResultSvcSolicitationUuids(BluetoothLeScanData scanData, BluetoothLePacketType packetType)
+        {
+            IntPtr uuidListArray;
+            int count;
+
+            BluetoothLeScanDataStruct scanDataStruct = new BluetoothLeScanDataStruct();
+            scanDataStruct = BluetoothUtils.ConvertLeScanDataToStruct (scanData, scanDataStruct);
+
+            int ret = Interop.Bluetooth.GetScaResultSvcSolicitationUuids(ref scanDataStruct, packetType, out uuidListArray, out count);
+            if (ret != (int)BluetoothError.None) {
+                Log.Error(Globals.LogTag, "Failed to get service solicitation uuids " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+
+            IntPtr[] uuidList = new IntPtr[count];
+            Marshal.Copy(uuidListArray, uuidList, 0, count);
+            IList<string> list = new List<string>();
+            foreach(IntPtr uuids in uuidList)
+            {
+                list.Add(Marshal.PtrToStringAnsi(uuids));
+                Interop.Libc.Free(uuids);
+            }
+
+            Interop.Libc.Free(uuidListArray);
+            return list;
+        }
+
+        internal IList<BluetoothLeServiceData> GetScanResultServiceDataList(BluetoothLeScanData scanData,
+                            BluetoothLePacketType packetType, out int serviceCount)
+        {
+            int ret = 0;
+            IntPtr serviceListArray;
+            BluetoothLeScanDataStruct scanDataStruct = new BluetoothLeScanDataStruct();
+            scanDataStruct = BluetoothUtils.ConvertLeScanDataToStruct (scanData, scanDataStruct);
+
+            ret = Interop.Bluetooth.GetScanResultServiceDataList(ref scanDataStruct, packetType, out serviceListArray, out _serviceListCount);
+            if(ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to get Service Data List, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+
+            BluetoothLeServiceDataStruct[] serviceArray = new BluetoothLeServiceDataStruct[_serviceListCount];
+            IntPtr current = serviceListArray;
+            for (int i = 0; i < _serviceListCount; i++)
+            {
+                //serviceArray[i] = new BluetoothLeServiceDataStruct();// check
+                Marshal.PtrToStructure(current, serviceArray[i]);
+                BluetoothLeServiceData serviceData = new BluetoothLeServiceData();
+                BluetoothUtils.ConvertStructToLeServiceData(serviceArray[i], serviceData);
+
+                _list.Add(serviceData);
+
+                Marshal.DestroyStructure(current, typeof(BluetoothLeServiceDataStruct));
+
+                current = (IntPtr)((long)current + Marshal.SizeOf(serviceArray[i]));
+                Log.Info (Globals.LogTag, "Service Data " + i + serviceArray[i].ServiceData
+                    +serviceArray[i].ServiceDataLength);
+            }
+
+            serviceCount = _serviceListCount;
+            Log.Info (Globals.LogTag, "serviceCount "+serviceCount);
+
+            Marshal.FreeHGlobal (scanDataStruct.AdvData);
+            Marshal.FreeHGlobal (scanDataStruct.ScanData);
+            return _list;
+        }
+
+        internal int FreeServiceDataList()
+        {
+            int iServiceDataSize = Marshal.SizeOf(typeof(BluetoothLeServiceData));
+            IntPtr structServiceData = Marshal.AllocHGlobal(iServiceDataSize);
+            Marshal.StructureToPtr(_list, structServiceData, false);
+
+            int ret = Interop.Bluetooth.FreeServiceDataList(structServiceData, _serviceListCount);
+            if(ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to free Service Data List, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+
+            Marshal.FreeHGlobal(structServiceData);
+
+            return 0;
+        }
+
+        internal int GetScanResultAppearance(BluetoothLeScanData scanData, BluetoothLePacketType packetType)
+        {
+            int appearance;
+
+            BluetoothLeScanDataStruct scanDataStruct = new BluetoothLeScanDataStruct();
+            scanDataStruct = BluetoothUtils.ConvertLeScanDataToStruct (scanData, scanDataStruct);
+
+            int ret = Interop.Bluetooth.GetScanResultAppearance(ref scanDataStruct, packetType, out appearance);
+            if (ret != (int)BluetoothError.None) {
+                Log.Error(Globals.LogTag, "Failed to get Appearance value- " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+            return appearance;
+        }
+
+        internal ManufacturerData GetScanResultManufacturerData(BluetoothLeScanData scanData, BluetoothLePacketType packetType)
+        {
+            ManufacturerData data = new ManufacturerData();
+
+            BluetoothLeScanDataStruct scanDataStruct = new BluetoothLeScanDataStruct();
+            scanDataStruct = BluetoothUtils.ConvertLeScanDataToStruct (scanData, scanDataStruct);
+
+            int dataId;
+            int dataLength;
+            IntPtr manufData;
+
+            int ret = Interop.Bluetooth.GetScanResultManufacturerData(ref scanDataStruct, packetType, out dataId,
+                out manufData, out dataLength);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to get Manufacturer data - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+
+            Marshal.Copy (manufData, data.Data, 0, data.DataLength);
+            data.Id = dataId;
+            data.DataLength = dataLength;
+
+            return data;
+        }
+
+        internal int GattConnect(string remoteAddress, bool autoConnect)
+        {
+            int ret = Interop.Bluetooth.GattConnect (remoteAddress, autoConnect);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to establish GATT connection - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+            return ret;
+        }
+
+        internal int GattDisconnect(string remoteAddress)
+        {
+            int ret = Interop.Bluetooth.GattDisconnect (remoteAddress);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to disconnect GATT connection - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+            return ret;
+        }
+
+        internal int CreateAdvertiser(out IntPtr advertiserHandle)
+        {
+            return Interop.Bluetooth.CreateAdvertiser (out advertiserHandle);
+        }
+
+        internal int DestroyAdvertiser(IntPtr advertiserHandle)
+        {
+            int ret =  Interop.Bluetooth.DestroyAdvertiser (advertiserHandle);
+            if (ret != (int)BluetoothError.None) {
+                Log.Error(Globals.LogTag, "Failed to destroy the Advertiser- " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+            return ret;
+        }
+
+        internal int StartAdvertising(IntPtr advertisingHandle)
+        {
+            _advertisingStateChangedCallback = (int result, IntPtr advertiserHandle,
+                            BluetoothLeAdvertisingState state, IntPtr userData) =>
+            {
+                Log.Info(Globals.LogTag, "Setting advertising state changed callback !! " );
+                // TODO: Convert the advertiserHandle to leAdvertiser later
+                //BluetoothLeAdvertiser leAdvertiser = (BluetoothLeAdvertiser)Marshal.PtrToStructure(advertiserHandle, typeof(BluetoothLeAdvertiser));
+                AdvertisingStateChangedEventArgs e = new AdvertisingStateChangedEventArgs(result, advertiserHandle, state);
+                _advertisingStateChanged(null, e);
+            };
+
+            IntPtr uData = IntPtr.Zero;
+            int ret = Interop.Bluetooth.BluetoothLeStartAdvertising (advertisingHandle,
+                                   _advertisingStateChangedCallback, uData );
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to start BLE advertising - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+            return ret;
+        }
+
+
+        internal int StopAdvertising(IntPtr advertisingHandle)
+        {
+            return Interop.Bluetooth.BluetoothLeStopAdvertising (advertisingHandle);
+        }
+    }
+}
diff --git a/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothProfile.cs b/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothProfile.cs
new file mode 100644 (file)
index 0000000..6dff1cf
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * 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.
+ */
+
+namespace Tizen.Network.Bluetooth
+{
+    /// <summary>
+    /// A generic class to represent all Bluetooth profiles.<br>
+    /// Any common properties/functions to be added in this class in future.
+    /// </summary>
+    /// <privilege> http://tizen.org/privilege/bluetooth </privilege>
+    public abstract class BluetoothProfile
+    {
+        internal string RemoteAddress { get; set; }
+    }
+}
diff --git a/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothServerSocket.cs b/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothServerSocket.cs
new file mode 100644 (file)
index 0000000..0d1615e
--- /dev/null
@@ -0,0 +1,144 @@
+/*
+ * 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;
+
+namespace Tizen.Network.Bluetooth
+{
+    /// <summary>
+    /// BluetoothSocket provides functions for managing connections to other devices and exchanging data.
+    /// </summary>
+    public class BluetoothServerSocket : IDisposable
+    {
+        private event EventHandler<AcceptStateChangedEventArgs> _acceptStateChanged;
+        internal int socketFd;
+        private bool disposed = false;
+
+        /// <summary>
+        /// (event) AcceptStateChanged is raised when socket connection state is changed.
+        /// </summary>
+        public event EventHandler<AcceptStateChangedEventArgs> AcceptStateChanged
+        {
+            add
+            {
+                if (_acceptStateChanged == null)
+                {
+                    RegisterAcceptStateChangedEvent();
+                }
+                _acceptStateChanged += value;
+            }
+            remove
+            {
+                _acceptStateChanged -= value;
+                if (_acceptStateChanged == null)
+                {
+                    UnregisterAcceptStateChangedEvent();
+                }
+            }
+        }
+
+        private void RegisterAcceptStateChangedEvent()
+        {
+            Interop.Bluetooth.SocketConnectionStateChangedCallback ConnectionStateChangedCallback = (int result, BluetoothSocketState connectionState, ref SocketConnectionStruct socketConnection, IntPtr userData) =>
+            {
+                Log.Info(Globals.LogTag, "AcceptStateChanged cb is called");
+                if (_acceptStateChanged != null)
+                {
+                    BluetoothSocket socket = new BluetoothSocket();
+                    socket.connectedSocket = socketConnection.SocketFd;
+                    GCHandle handle2 = (GCHandle) userData;
+                    _acceptStateChanged(handle2.Target as BluetoothServerSocket, new AcceptStateChangedEventArgs((BluetoothError)result, connectionState, BluetoothUtils.ConvertStructToSocketConnection(socketConnection), socket));
+                }
+            };
+            GCHandle handle1 = GCHandle.Alloc(this);
+            IntPtr data = (IntPtr) handle1;
+            int ret = Interop.Bluetooth.SetConnectionStateChangedCallback(ConnectionStateChangedCallback, data);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to set accept state changed callback, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+        }
+
+        private void UnregisterAcceptStateChangedEvent()
+        {
+            int ret = Interop.Bluetooth.UnsetSocketConnectionStateChangedCallback();
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to unset accept state changed callback, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+        }
+
+        internal BluetoothServerSocket(int socketFd)
+        {
+            Log.Info (Globals.LogTag, "Constructing server socket");
+            this.socketFd = socketFd;
+        }
+
+        /// <summary>
+        /// Starts listening on passed rfcomm socket and accepts connection requests.
+        /// </summary>
+        /// <remarks>
+        /// The socket must be created with CreateServerSocket(). This API invokes ConnectionStateChanged event.
+        /// </remarks>
+        public void Listen()
+        {
+            int ret = Interop.Bluetooth.Listen(socketFd, 1);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to accept connection, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+        }
+
+        ~BluetoothServerSocket()
+        {
+            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
+            RemoveRegisteredEvents();
+            disposed = true;
+        }
+
+        private void RemoveRegisteredEvents()
+        {
+            //unregister all remaining events when this object is released.
+            if (_acceptStateChanged != null)
+            {
+                UnregisterAcceptStateChangedEvent();
+            }
+        }
+    }
+}
diff --git a/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothSocket.cs b/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothSocket.cs
new file mode 100644 (file)
index 0000000..4fb8416
--- /dev/null
@@ -0,0 +1,252 @@
+/*
+ * 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;
+
+namespace Tizen.Network.Bluetooth
+{
+    /// <summary>
+    /// IBluetoothServerSocket interface. Handles the server socket operations.
+    /// </summary>
+    public interface IBluetoothServerSocket
+    {
+        event EventHandler<SocketDataReceivedEventArgs> DataReceived;
+        event EventHandler<SocketConnectionStateChangedEventArgs> ConnectionStateChanged;
+        void SendData(string data);
+    }
+
+    /// <summary>
+    /// IBluetoothClientSocket interface. Handles the client socket operations.
+    /// </summary>
+    public interface IBluetoothClientSocket : IBluetoothServerSocket
+    {
+        void Connect();
+        void Disconnect();
+    }
+
+    internal class BluetoothSocket : IBluetoothClientSocket, IDisposable
+    {
+        private event EventHandler<SocketDataReceivedEventArgs> _dataReceived;
+        private event EventHandler<SocketConnectionStateChangedEventArgs> _connectionStateChanged;
+        private bool disposed = false;
+        internal int connectedSocket;
+        internal string remoteAddress;
+        internal string serviceUuid;
+
+        /// <summary>
+        /// This event occurs when socket server received data from client.
+        /// </summary>
+        public event EventHandler<SocketDataReceivedEventArgs> DataReceived
+        {
+            add
+            {
+                if (_dataReceived == null)
+                {
+                    RegisterDataReceivedEvent();
+                }
+                _dataReceived += value;
+            }
+            remove
+            {
+                _dataReceived -= value;
+                if (_dataReceived == null)
+                {
+                    UnregisterDataReceivedEvent();
+                }
+            }
+        }
+
+        /// <summary>
+        /// This event occurs when connection state between two devices is changed.
+        /// </summary>
+        public event EventHandler<SocketConnectionStateChangedEventArgs> ConnectionStateChanged
+        {
+            add
+            {
+                if (_connectionStateChanged == null)
+                {
+                    RegisterConnectionStateChangedEvent();
+                }
+                _connectionStateChanged += value;
+            }
+            remove
+            {
+                _connectionStateChanged -= value;
+                if (_connectionStateChanged == null)
+                {
+                    UnregisterConnectionStateChangedEvent();
+                }
+            }
+        }
+
+        private void RegisterDataReceivedEvent()
+        {
+            Interop.Bluetooth.DataReceivedCallback DataReceivedCallback = (ref SocketDataStruct socketData, IntPtr userData) =>
+            {
+                Log.Info(Globals.LogTag, "DataReceivedCallback is called");
+                if (_dataReceived != null)
+                {
+                    GCHandle handle2 = (GCHandle) userData;
+                    _dataReceived(handle2.Target as IBluetoothServerSocket, new SocketDataReceivedEventArgs(BluetoothUtils.ConvertStructToSocketData(socketData)));
+                }
+            };
+            GCHandle handle1 = GCHandle.Alloc (this);
+            IntPtr uData = (IntPtr) handle1;
+            int ret = Interop.Bluetooth.SetDataReceivedCallback(DataReceivedCallback, uData);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to set data received callback, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+        }
+
+        private void UnregisterDataReceivedEvent()
+        {
+            int ret = Interop.Bluetooth.UnsetDataReceivedCallback();
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to unset data received callback, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+        }
+
+        private void RegisterConnectionStateChangedEvent()
+        {
+            Interop.Bluetooth.SocketConnectionStateChangedCallback ConnectionStateChangedCallback = (int result, BluetoothSocketState connectionState, ref SocketConnectionStruct socketConnection, IntPtr userData) =>
+            {
+                Log.Info(Globals.LogTag, "ConnectionStateChangedCallback is called");
+                if (_connectionStateChanged != null)
+                {
+                    connectedSocket = socketConnection.SocketFd;
+                    GCHandle handle2 = (GCHandle) userData;
+                    _connectionStateChanged(handle2.Target as IBluetoothServerSocket, new SocketConnectionStateChangedEventArgs((BluetoothError)result, connectionState, BluetoothUtils.ConvertStructToSocketConnection(socketConnection)));
+                }
+            };
+            GCHandle handle1 = GCHandle.Alloc(this);
+            IntPtr data = (IntPtr) handle1;
+            int ret = Interop.Bluetooth.SetConnectionStateChangedCallback(ConnectionStateChangedCallback, data);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to set connection state changed callback, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+        }
+
+        private void UnregisterConnectionStateChangedEvent()
+        {
+            int ret = Interop.Bluetooth.UnsetSocketConnectionStateChangedCallback();
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to unset connection state changed callback, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+        }
+
+        /// <summary>
+        /// Connects to a specific RFCOMM based service on a remote Bluetooth device UUID.
+        /// </summary>
+        /// <remarks>
+        /// The bluetooth must be enabled, discoverable with StartDiscovery(), bonded with the remote device using CreateBond(). ConnectionStateChanged event is raised once this API is called.
+        /// </remarks>
+        /// <param name="address">The address of the remote Bluetooth device.</param>
+        /// <param name="serviceUuid">The UUID of service provided by the remote Bluetooth device.</param>
+        void IBluetoothClientSocket.Connect()
+        {
+            int ret = Interop.Bluetooth.ConnectSocket(remoteAddress, serviceUuid);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to connect to socket, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+        }
+
+        /// <summary>
+        /// Disconnects the RFCOMM connection with the given file descriptor of conneted socket.
+        /// </summary>
+        /// <remarks>
+        /// The connection must be established.
+        /// </remarks>
+        /// <param name="socketFd">The file descriptor of socket to close.</param>
+        void IBluetoothClientSocket.Disconnect()
+        {
+            int ret = Interop.Bluetooth.DisconnectSocket(connectedSocket);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to disconnect socket, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+        }
+
+        /// <summary>
+        /// Sends data to the connected device.
+        /// </summary>
+        /// <returns>The number of bytes written (zero indicates nothing was written).</returns>
+        /// <remarks>
+        /// The connection must be established.
+        /// </remarks>
+        /// <param name="socketFd">The file descriptor of connected socket.</param>
+        /// <param name="data">The data to be sent.</param>
+        public void SendData(string data)
+        {
+            int ret = Interop.Bluetooth.SendData(connectedSocket, data, data.Length);
+            if (ret != (int)BluetoothError.None)
+            {
+                Log.Error(Globals.LogTag, "Failed to send data, Error - " + (BluetoothError)ret);
+                BluetoothErrorFactory.ThrowBluetoothException(ret);
+            }
+        }
+
+        ~BluetoothSocket()
+        {
+            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
+            RemoveRegisteredEvents();
+            disposed = true;
+        }
+
+        private void RemoveRegisteredEvents()
+        {
+            //unregister all remaining events when this object is released.
+            if (_dataReceived != null)
+            {
+                UnregisterDataReceivedEvent();
+            }
+            if (_connectionStateChanged != null)
+            {
+                UnregisterConnectionStateChangedEvent();
+            }
+        }
+    }
+}
diff --git a/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothStructs.cs b/Tizen.Bluetooth/Tizen.Bluetooth/BluetoothStructs.cs
new file mode 100644 (file)
index 0000000..05d0110
--- /dev/null
@@ -0,0 +1,333 @@
+/*
+ * 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.Reflection;
+using System.Linq;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Collections.Specialized;
+using System.Runtime.InteropServices;
+
+namespace Tizen.Network.Bluetooth
+{
+    /// <summary>
+    /// Structure of device class type and service.
+    /// </summary>
+    [StructLayout(LayoutKind.Sequential)]
+    internal struct BluetoothClassStruct
+    {
+        /// <summary>
+        /// Type of the major device class.
+        /// </summary>
+        internal BluetoothMajorDeviceClassType MajorDeviceClassType;
+        /// <summary>
+        /// Type of the minor device class.
+        /// </summary>
+        internal BluetoothMinorDeviceClassType MinorDeviceClassType;
+        /// <summary>
+        /// Major service class mask.
+        /// </summary>
+        internal int MajorServiceClassMask;
+    }
+
+    /// <summary>
+    /// Structure containing the information of Bluetooth device.
+    /// </summary>
+    [StructLayout(LayoutKind.Sequential)]
+    internal struct BluetoothDeviceStruct
+    {
+        /// <summary>
+        /// Address of device.
+        /// </summary>
+        [MarshalAsAttribute(UnmanagedType.LPStr)]
+        internal string Address;
+
+        /// <summary>
+        /// Name of device.
+        /// </summary>
+        [MarshalAsAttribute(UnmanagedType.LPStr)]
+        internal string Name;
+
+        /// <summary>
+        /// Class of device.
+        /// </summary>
+        internal BluetoothClassStruct Class;
+
+        /// <summary>
+        /// Service UUID list of device.
+        /// </summary>
+        internal IntPtr ServiceUuidList;
+
+        /// <summary>
+        /// Service count of device.
+        /// </summary>
+        internal int ServiceCount;
+
+        /// <summary>
+        /// The paired state of device.
+        /// </summary>
+        [MarshalAsAttribute(UnmanagedType.I1)]
+        internal bool IsPaired;
+
+        /// <summary>
+        /// The connection state of device.
+        /// </summary>
+        [MarshalAsAttribute(UnmanagedType.I1)]
+        internal bool IsConnected;
+
+        /// <summary>
+        /// The authorization state of device.
+        /// </summary>
+        [MarshalAsAttribute(UnmanagedType.I1)]
+        internal bool IsAuthorized;
+
+        /// <summary>
+        /// The length of the manufacturer data.
+        /// </summary>
+        internal int ManufacturerDataLength;
+
+        /// <summary>
+        /// The manufacturer data.
+        /// </summary>
+        [MarshalAsAttribute(UnmanagedType.LPStr)]
+        internal string ManufacturerData;
+    }
+
+    [StructLayout(LayoutKind.Sequential)]
+    internal struct BluetoothDiscoveredDeviceStruct
+    {
+        [MarshalAsAttribute(UnmanagedType.LPStr)]
+        internal string Address;
+
+        [MarshalAsAttribute(UnmanagedType.LPStr)]
+        internal string Name;
+
+        internal BluetoothClassStruct Class;
+
+        internal int Rssi;
+
+        [MarshalAsAttribute(UnmanagedType.I1)]
+        internal bool IsPaired;
+
+        internal IntPtr ServiceUuidList;
+
+        internal int ServiceCount;
+
+        internal BluetoothAppearanceType AppearanceType;
+
+        internal int ManufacturerDataLength;
+
+        [MarshalAsAttribute(UnmanagedType.LPStr)]
+        internal string ManufacturerData;
+    }
+
+    internal struct BluetoothDeviceSdpStruct
+    {
+        [MarshalAsAttribute(UnmanagedType.LPStr)]
+        internal string DeviceAddress;
+        internal IntPtr ServiceUuid;
+        internal int ServiceCount;
+    }
+
+    internal struct BluetoothDeviceConnectionStruct
+    {
+        internal string Address;
+        internal BluetoothConnectionLinkType LinkType;
+        internal BluetoothDisconnectReason DisconnectReason;
+    }
+
+    internal struct SocketDataStruct
+    {
+        internal int SocketFd;
+        internal int DataSize;
+        internal string Data;
+    }
+
+    internal struct SocketConnectionStruct
+    {
+        internal int SocketFd;
+        internal int ServerFd;
+        internal BluetoothSocketRole LocalRole;
+        internal string Address;
+        internal string ServiceUuid;
+    }
+
+    internal static class BluetoothUtils
+    {
+        internal static BluetoothDevice ConvertStructToDeviceClass(BluetoothDeviceStruct device)
+        {
+            BluetoothDevice resultDevice = new BluetoothDevice();
+            Collection<string> uuidList = null;
+
+            if (device.ServiceCount > 0)
+            {
+                IntPtr[] extensionList = new IntPtr[device.ServiceCount];
+                Marshal.Copy (device.ServiceUuidList, extensionList, 0, device.ServiceCount);
+                uuidList = new Collection<string> ();
+                foreach (IntPtr extension in extensionList) {
+                    string uuid = Marshal.PtrToStringAnsi (extension);
+                    uuidList.Add (uuid);
+                }
+            }
+
+            resultDevice.RemoteDeviceAddress = device.Address;
+            resultDevice.RemoteDeviceName = device.Name;
+            resultDevice.RemoteDeviceClass = new BluetoothClass();
+            resultDevice.Class.MajorType = device.Class.MajorDeviceClassType;
+            resultDevice.Class.MinorType = device.Class.MinorDeviceClassType;
+            resultDevice.Class.Mask = device.Class.MajorServiceClassMask;
+            resultDevice.RemotePaired = device.IsPaired;
+            resultDevice.RemoteConnected = device.IsConnected;
+            resultDevice.RemoteAuthorized = device.IsAuthorized;
+            resultDevice.RemoteDeviceService = uuidList;
+            resultDevice.RemoteDeviceCount = device.ServiceCount;
+            resultDevice.RemoteManufLength = device.ManufacturerDataLength;
+            resultDevice.RemoteManufData = device.ManufacturerData;
+
+            return resultDevice;
+        }
+
+        internal static BluetoothDevice ConvertStructToDiscoveredDevice(BluetoothDiscoveredDeviceStruct structDevice)
+        {
+            BluetoothDevice resultDevice = new BluetoothDevice();
+            Collection<string> uuidList = null;
+
+            if (structDevice.ServiceCount > 0) {
+                IntPtr[] extensionList = new IntPtr[structDevice.ServiceCount];
+                Marshal.Copy (structDevice.ServiceUuidList, extensionList, 0, structDevice.ServiceCount);
+                uuidList = new Collection<string> ();
+                foreach (IntPtr extension in extensionList) {
+                    string uuid = Marshal.PtrToStringAnsi (extension);
+                    uuidList.Add (uuid);
+                }
+            }
+
+            resultDevice.RemoteDeviceAddress = structDevice.Address;
+            resultDevice.RemoteDeviceName = structDevice.Name;
+
+            resultDevice.RemoteDeviceClass = new BluetoothClass();
+            resultDevice.Class.MajorType = structDevice.Class.MajorDeviceClassType;
+            resultDevice.Class.MinorType = structDevice.Class.MinorDeviceClassType;
+            resultDevice.Class.Mask = structDevice.Class.MajorServiceClassMask;
+
+            resultDevice.RemoteDeviceRssi = structDevice.Rssi;
+            resultDevice.RemoteAppearance = structDevice.AppearanceType;
+
+            if (structDevice.ServiceCount > 0) {
+                resultDevice.RemoteDeviceService = uuidList;
+                resultDevice.RemoteDeviceCount = structDevice.ServiceCount;
+            }
+
+            resultDevice.RemotePaired = structDevice.IsPaired;
+            resultDevice.RemoteManufData = structDevice.ManufacturerData;
+            resultDevice.RemoteManufLength = structDevice.ManufacturerDataLength;
+            return resultDevice;
+        }
+
+        internal static BluetoothDeviceSdpData ConvertStructToSdpData(BluetoothDeviceSdpStruct structData)
+        {
+            BluetoothDeviceSdpData resultData = new BluetoothDeviceSdpData();
+            Collection<string> uuidList = null;
+
+            if (structData.ServiceCount > 0) {
+                IntPtr[] extensionList = new IntPtr[structData.ServiceCount];
+                Marshal.Copy (structData.ServiceUuid, extensionList, 0, structData.ServiceCount);
+                uuidList = new Collection<string> ();
+                foreach (IntPtr extension in extensionList) {
+                    string uuid = Marshal.PtrToStringAnsi (extension);
+                    uuidList.Add (uuid);
+                }
+            }
+
+            resultData.Uuid = uuidList;
+            resultData.Address = structData.DeviceAddress;
+
+            return resultData;
+        }
+
+        internal static BluetoothDeviceConnectionData ConvertStructToConnectionData(BluetoothDeviceConnectionStruct structInfo)
+        {
+            BluetoothDeviceConnectionData resultData = new BluetoothDeviceConnectionData();
+            resultData.RemoteAddress = structInfo.Address;
+            resultData.Link = structInfo.LinkType;
+            resultData.Reason = structInfo.DisconnectReason;
+            return resultData;
+        }
+
+        internal static BluetoothLeScanData ConvertStructToLeScanData(BluetoothLeScanDataStruct structScanData, BluetoothLeScanData scanData)
+        {
+            scanData.RemoteAddress = structScanData.RemoteAddress;
+            scanData.AddressType = structScanData.AddressType;
+            scanData.Rssi = structScanData.Rssi;
+
+            scanData.AdvDataLength = structScanData.AdvDataLength;
+            scanData.AdvData = new byte[scanData.AdvDataLength];
+            Marshal.Copy (structScanData.AdvData, scanData.AdvData, 0, scanData.AdvDataLength);
+
+            scanData.ScanDataLength = structScanData.ScanDataLength;
+            scanData.ScanData = new byte[scanData.ScanDataLength];
+            Marshal.Copy (structScanData.ScanData, scanData.ScanData, 0, scanData.ScanDataLength);
+
+            return scanData;
+        }
+
+        internal static BluetoothLeScanDataStruct ConvertLeScanDataToStruct(BluetoothLeScanData scanData, BluetoothLeScanDataStruct scanDataStruct)
+        {
+            scanDataStruct.RemoteAddress = scanData.RemoteAddress;
+            scanDataStruct.AddressType = scanData.AddressType;
+            scanDataStruct.Rssi = scanData.Rssi;
+
+            scanDataStruct.AdvDataLength = scanData.AdvDataLength;
+            scanDataStruct.AdvData = Marshal.AllocHGlobal (scanData.AdvDataLength);
+            Marshal.Copy (scanData.AdvData, 0, scanDataStruct.AdvData, scanData.AdvDataLength);
+
+            scanDataStruct.ScanDataLength = scanData.ScanDataLength;
+            scanDataStruct.ScanData = Marshal.AllocHGlobal (scanData.ScanDataLength);
+            Marshal.Copy (scanData.ScanData, 0, scanDataStruct.ScanData, scanData.ScanDataLength);
+
+            return scanDataStruct;
+        }
+
+        internal static BluetoothLeServiceData ConvertStructToLeServiceData(BluetoothLeServiceDataStruct structServiceData, BluetoothLeServiceData serviceData)
+        {
+            serviceData.Data = structServiceData.ServiceData;
+            serviceData.Uuid = structServiceData.ServiceUuid;
+            serviceData.Length = structServiceData.ServiceDataLength;
+
+            return serviceData;
+        }
+
+        internal static SocketData ConvertStructToSocketData(SocketDataStruct structInfo)
+        {
+            SocketData data = new SocketData();
+            data.Fd = structInfo.SocketFd;
+            data.Size = structInfo.DataSize;
+            data.RecvData = structInfo.Data;
+            return data;
+        }
+
+        internal static SocketConnection ConvertStructToSocketConnection(SocketConnectionStruct structInfo)
+        {
+            SocketConnection connectionInfo = new SocketConnection();
+            connectionInfo.Fd = structInfo.SocketFd;
+            connectionInfo.RemoteAddress = structInfo.Address;
+            connectionInfo.Uuid = structInfo.ServiceUuid;
+            return connectionInfo;
+        }
+    }
+}
+
diff --git a/packaging/csapi-bluetooth.manifest b/packaging/csapi-bluetooth.manifest
new file mode 100644 (file)
index 0000000..75b0fa5
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+    <request>
+        <domain name="_"/>
+    </request>
+</manifest>
diff --git a/packaging/csapi-bluetooth.spec b/packaging/csapi-bluetooth.spec
new file mode 100644 (file)
index 0000000..4413fe8
--- /dev/null
@@ -0,0 +1,76 @@
+%{!?dotnet_assembly_path: %define dotnet_assembly_path /opt/usr/share/dotnet.tizen/framework}
+
+%if 0%{?tizen_build_devel_mode}
+%define BUILDCONF Debug
+%else
+%define BUILDCONF Release
+%endif
+
+Name:       csapi-bluetooth
+Summary:    Tizen Bluetooth 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: %{ix86} aarch64
+
+BuildRequires: mono-compiler
+BuildRequires: mono-devel
+
+BuildRequires: dotnet-build-tools
+
+# C# API Requries
+BuildRequires: csapi-tizen-nuget
+
+%description
+Tizen Bluetooth API for C#
+
+%prep
+%setup -q
+cp %{SOURCE1} .
+
+%define Assemblies Tizen.Bluetooth
+
+%build
+for ASM in %{Assemblies}; do
+# NuGet Restore
+find $ASM/*.project.json -exec nuget restore {} \;
+# Build
+find $ASM/*.csproj -exec xbuild {} /p:Configuration=%{BUILDCONF} \;
+# NuGet Pack
+nuget pack $ASM/$ASM.nuspec -Version %{version} -Properties Configuration=%{BUILDCONF}
+done
+
+%install
+# Runtime Binary
+mkdir -p %{buildroot}%{dotnet_assembly_path}
+for ASM in %{Assemblies}; do
+%if 0%{?_with_corefx}
+  install -p -m 644 $ASM/bin/%{BUILDCONF}/$ASM.dll %{buildroot}%{dotnet_assembly_path}
+%else
+  install -p -m 644 $ASM/bin/%{BUILDCONF}/Net45/$ASM.dll %{buildroot}%{dotnet_assembly_path}
+%endif
+done
+# NuGet
+mkdir -p %{buildroot}/nuget
+install -p -m 644 *.nupkg %{buildroot}/nuget
+
+%files
+%manifest %{name}.manifest
+%license LICENSE
+%attr(644,root,root) %{dotnet_assembly_path}/*.dll
+
+%package nuget
+Summary:   NuGet package for %{name}
+Group:     Development/Libraries
+
+%description nuget
+NuGet package for %{name}
+
+%files nuget
+/nuget/*.nupkg