2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Threading.Tasks;
19 using System.Collections.Generic;
20 using System.Collections.Specialized;
21 using System.Runtime.InteropServices;
23 namespace Tizen.Network.Bluetooth {
26 /// This is the BluetoothLeAdvertiser class. It handles the LE advertising operation amd callback.
28 /// <since_tizen> 3 </since_tizen>
29 public class BluetoothLeAdvertiser
31 private static readonly BluetoothLeAdvertiser _instance = new BluetoothLeAdvertiser();
33 internal static BluetoothLeAdvertiser Instance
41 private BluetoothLeAdvertiser()
46 /// This event is called when the LE advertising state changes.
48 /// <since_tizen> 3 </since_tizen>
49 public event EventHandler<AdvertisingStateChangedEventArgs> AdvertisingStateChanged
53 BluetoothLeImplAdapter.Instance.AdapterLeAdvertisingStateChanged += value;
57 BluetoothLeImplAdapter.Instance.AdapterLeAdvertisingStateChanged -= value;
61 /// Starts advertising using the advertise data object.
64 /// The Bluetooth must be enabled.
66 /// <param name="advertiseData">The advertiser object carrying information of the advertising.</param>
67 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
68 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
69 /// <since_tizen> 3 </since_tizen>
70 public void StartAdvertising(BluetoothLeAdvertiseData advertiseData)
72 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
74 int ret = BluetoothLeImplAdapter.Instance.StartAdvertising (advertiseData.GetHandle ());
75 if (ret != (int)BluetoothError.None) {
76 Log.Error (Globals.LogTag, "Failed to start advertising- " + (BluetoothError)ret);
77 BluetoothErrorFactory.ThrowBluetoothException(ret);
82 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
87 /// Stops the advertising.
90 /// The Bluetooth must be enabled.
92 /// <param name="advertiseData">The advertiser object carrying information of the advertising.</param>
93 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
94 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
95 /// <since_tizen> 3 </since_tizen>
96 public void StopAdvertising(BluetoothLeAdvertiseData advertiseData)
98 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
100 int ret = BluetoothLeImplAdapter.Instance.StopAdvertising (advertiseData.GetHandle ());
101 if (ret != (int)BluetoothError.None) {
102 Log.Error (Globals.LogTag, "Failed to stop advertising operation- " + (BluetoothError)ret);
103 BluetoothErrorFactory.ThrowBluetoothException(ret);
108 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
114 /// This is the BluetoothLeDevice class.
115 /// It handles the LE device operations like getting data from the scan result information.
117 /// <since_tizen> 3 </since_tizen>
118 public class BluetoothLeDevice
120 //properties of Bluetoothlesacandata
121 private string _remoteAddress;
122 private BluetoothLeDeviceAddressType _addressType;
124 private byte[] _advDataValue;
125 private byte[] _scanDataValue;
126 private BluetoothLePacketType _packetType;
127 private BluetoothLeScanData _scanData;
130 /// This event is called when the GATT client connects/disconnects with the server.
132 /// <since_tizen> 3 </since_tizen>
133 public event EventHandler<GattConnectionStateChangedEventArgs> GattConnectionStateChanged
137 BluetoothLeImplAdapter.Instance.LeGattConnectionStateChanged += value;
141 BluetoothLeImplAdapter.Instance.LeGattConnectionStateChanged -= value;
145 internal BluetoothLeDevice(BluetoothLeScanData scanData)
147 _scanData = new BluetoothLeScanData ();
148 _scanData = scanData;
150 Log.Info (Globals.LogTag, "Rssi" + _scanData.Rssi);
151 _rssi = scanData.Rssi;
152 Log.Info (Globals.LogTag, "RemoteAddress" + _scanData.RemoteAddress);
153 if (scanData.RemoteAddress != null)
154 _remoteAddress = scanData.RemoteAddress;
155 Log.Info (Globals.LogTag, "AddressType" + _scanData.AddressType);
156 _addressType = scanData.AddressType;
158 Log.Info (Globals.LogTag, "AdvDataLength" + _scanData.AdvDataLength);
159 if (_scanData.AdvDataLength > 0)
161 _advDataValue = new byte[_scanData.AdvDataLength];
162 scanData.AdvData.CopyTo(_advDataValue, 0);
165 Log.Info(Globals.LogTag, "ScanDataLength" + _scanData.ScanDataLength);
166 // Check length before copying
167 if (_scanData.ScanDataLength > 0)
169 _scanDataValue = new byte[_scanData.ScanDataLength];
170 scanData.ScanData.CopyTo(_scanDataValue, 0);
175 /// BluetoothLeDevice destructor.
179 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
181 BluetoothLeImplAdapter.Instance.FreeServiceDataList();
186 /// The remote address.
188 /// <since_tizen> 3 </since_tizen>
189 public string RemoteAddress
193 return _remoteAddress;
198 /// The type of the address.
200 /// <since_tizen> 3 </since_tizen>
201 public BluetoothLeDeviceAddressType AddressType
212 /// <since_tizen> 3 </since_tizen>
222 /// The advertsing data information.
224 /// <since_tizen> 3 </since_tizen>
225 public byte[] AdvertsingDataInformation
229 return _advDataValue;
234 /// The scan data information.
236 /// <since_tizen> 3 </since_tizen>
237 public byte[] ScanDataInformation
241 return _scanDataValue;
246 /// The type of the packet.
248 /// <since_tizen> 3 </since_tizen>
249 public BluetoothLePacketType PacketType
262 /// Gets the service UUIDs list from the LE scan result information.
264 /// <value> Gets the list of the string service UUIDs.</value>
266 /// The Bluetooth must be enabled.
268 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
269 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
270 /// <since_tizen> 3 </since_tizen>
271 public IEnumerable<string> ServiceUuid
275 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
277 Log.Info(Globals.LogTag, "Retrieving Service uuid- ");
278 return BluetoothLeImplAdapter.Instance.GetLeScanResultServiceUuids(_scanData, _packetType);
285 /// Gets the device name from the LE scan result information.
287 /// <value> Gets the device name.</value>
289 /// The Bluetooth must be enabled.
291 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
292 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
293 /// <since_tizen> 3 </since_tizen>
294 public string DeviceName
298 Log.Info(Globals.LogTag, "Retrieving device name- ");
299 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
301 return BluetoothLeImplAdapter.Instance.GetLeScanResultDeviceName(_scanData, _packetType);
307 /// Gets the transmission power level from the LE scan result information.
309 /// <value> Gets the transmission power level in dB.</value>
311 /// The Bluetooth must be enabled.
313 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
314 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
315 /// <since_tizen> 3 </since_tizen>
316 public int TxPowerLevel
320 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
322 return BluetoothLeImplAdapter.Instance.GetScanResultTxPowerLevel(_scanData, _packetType);
329 /// Gets the service solicitation UUID list from the scan result information.
331 /// <value> Gets the list of the service solicitation UUIDs.</value>
333 /// The Bluetooth must be enabled.
335 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
336 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
337 /// <since_tizen> 3 </since_tizen>
338 public IEnumerable<string> ServiceSolictationUuid
342 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
344 return BluetoothLeImplAdapter.Instance.GetScanResultSvcSolicitationUuids(_scanData, _packetType);
350 /// Gets the manufacturer data from the scan result information.
352 /// <value> Gets the appearance value.</value>
354 /// The Bluetooth must be enabled.
356 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
357 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
358 /// <since_tizen> 3 </since_tizen>
359 public int Appearance
363 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
365 return BluetoothLeImplAdapter.Instance.GetScanResultAppearance(_scanData, _packetType);
371 /// Gets the manufacturer data from the scan result information.
373 /// <value> Gets the manufacturer data containing the manucturer data and ID information.</value>
375 /// The Bluetooth must be enabled.
377 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
378 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>///
379 /// <since_tizen> 3 </since_tizen>
380 public ManufacturerData ManufacturerData
384 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
386 return BluetoothLeImplAdapter.Instance.GetScanResultManufacturerData(_scanData, _packetType);
393 /// Gets the service data list from the scan result information.
396 /// The Bluetooth must be enabled.
398 /// <returns> Returns the service data list.</returns>
399 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
400 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
401 /// <since_tizen> 3 </since_tizen>
402 public IEnumerable<BluetoothLeServiceData> GetServiceDataList()
404 int serviceCount = 0;
405 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
407 return BluetoothLeImplAdapter.Instance.GetScanResultServiceDataList(_scanData,
408 _packetType, out serviceCount);
415 /// Creates a GATT connection with the remote device.
418 /// The Bluetooth must be enabled.
420 /// <param name="autoConnect"> The auto connect flag.</param>
421 /// <returns>client instance</returns>
422 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
423 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
424 /// or when the gatt connection attempt to remote device fails.</exception>
425 /// <since_tizen> 3 </since_tizen>
426 public BluetoothGattClient GattConnect(bool autoConnect)
428 BluetoothGattClient client = null;
429 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
431 int ret = BluetoothLeImplAdapter.Instance.GattConnect (_remoteAddress, autoConnect);
432 if (ret != (int)BluetoothError.None) {
433 Log.Error (Globals.LogTag, "Failed to create GATT Connection with remote device- " + (BluetoothError)ret);
437 client = BluetoothGattClient.CreateClient(_remoteAddress);
442 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
448 /// Disconnects a GATT connection with the remote device.
451 /// The Bluetooth must be enabled.
453 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
454 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
455 /// or when the GATT disconnection attempt to remote device fails.</exception>
456 /// <since_tizen> 3 </since_tizen>
457 public void GattDisconnect()
459 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
461 int ret = BluetoothLeImplAdapter.Instance.GattDisconnect (_remoteAddress);
462 if (ret != (int)BluetoothError.None) {
463 Log.Error (Globals.LogTag, "Failed to disconnect GATT connection with remote device- " + (BluetoothError)ret);
468 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
474 /// Bluetooth LE advertise data. Handles the data advertising.
476 /// <since_tizen> 3 </since_tizen>
477 public class BluetoothLeAdvertiseData:IDisposable
479 private IntPtr _handle = IntPtr.Zero;
480 private BluetoothLeAdvertisingMode _mode;
481 private bool _advertisingConnectable;
482 private BluetoothLePacketType _packetType;
483 private int _appearance;
484 private bool _includePowerLevel;
485 private bool _includeDeviceName;
488 /// The default constructor initializes an object of the BluetoothLeAdvertiseData.
490 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
491 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
492 /// or when create advertiser fails.</exception>
493 /// <since_tizen> 3 </since_tizen>
494 public BluetoothLeAdvertiseData()
496 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
498 Log.Debug(Globals.LogTag, " Creating LeAdvertiser()");
499 int ret = Interop.Bluetooth.CreateAdvertiser(out _handle);
500 if (ret != (int)BluetoothError.None)
502 Log.Error(Globals.LogTag, "Failed to create advertiser object- " + (BluetoothError)ret);
503 BluetoothErrorFactory.ThrowBluetoothException(ret);
508 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
513 /// BluetoothLeAdvertiseData destructor.
515 ~BluetoothLeAdvertiseData()
517 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
520 ClearAdvertisingData (BluetoothLePacketType.BluetoothLeAdvertisingPacket);
521 ClearAdvertisingData (BluetoothLePacketType.BluetoothLeScanResponsePacket);
522 BluetoothLeImplAdapter.Instance.DestroyAdvertiser (_handle);
527 internal IntPtr GetHandle()
533 /// The advertising mode to control the advertising power and latency.
536 /// The Bluetooth must be enabled.
538 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
539 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
540 /// or when the set advertising mode fails.</exception>
541 /// <since_tizen> 3 </since_tizen>
542 public BluetoothLeAdvertisingMode AdvertisingMode
550 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
553 int ret = Interop.Bluetooth.SetAdvertisingMode (GetHandle (), _mode);
554 if (ret != (int)BluetoothError.None) {
555 Log.Error (Globals.LogTag, "Failed to set advertising mode- " + (BluetoothError)ret);
556 BluetoothErrorFactory.ThrowBluetoothException (ret);
563 /// The advertising connectable type.
566 /// The Bluetooth must be enabled.
568 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
569 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
570 /// or when the set advertising connectable mode fails.</exception>
571 /// <since_tizen> 3 </since_tizen>
572 public bool AdvertisingConnectable
576 return _advertisingConnectable;
580 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
582 _advertisingConnectable = value;
583 int ret = Interop.Bluetooth.SetAdvertisingConnectable (GetHandle (), _advertisingConnectable);
584 if (ret != (int)BluetoothError.None) {
585 Log.Error (Globals.LogTag, "Failed to set advertising connectable value- " + (BluetoothError)ret);
586 BluetoothErrorFactory.ThrowBluetoothException (ret);
595 /// <since_tizen> 3 </since_tizen>
596 public void Dispose()
599 GC.SuppressFinalize(this);
602 private void Dispose(bool disposing)
608 /// The type of the packet.
610 /// <since_tizen> 3 </since_tizen>
611 public BluetoothLePacketType PacketType
623 /// Sets the external appearance of this device to the advertise or the scan response data.
624 /// Please refer to the adopted Bluetooth specification for the appearance.
627 /// The Bluetooth must be enabled.
629 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
630 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
631 /// or when the set appearance fails.</exception>
632 /// <since_tizen> 3 </since_tizen>
633 public int Appearance
642 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize) {
643 int ret = Interop.Bluetooth.SetAdvertisingAppearance (GetHandle (), _packetType, _appearance);
644 if (ret != (int)BluetoothError.None) {
645 Log.Error (Globals.LogTag, "Failed to add appearance value to advertising data- " + (BluetoothError)ret);
646 BluetoothErrorFactory.ThrowBluetoothException(ret);
652 /// Sets whether the device name has to be included in the advertise or the scan response data.
653 /// The maximum advertised or responded data size is 31 bytes including the data type and the system wide data.
656 /// The Bluetooth must be enabled.
658 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
659 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
660 /// or when the set advertising device name fails.</exception>
661 /// <since_tizen> 3 </since_tizen>
662 public bool IncludeDeviceName
666 return _includeDeviceName;
670 _includeDeviceName = value;
671 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
673 int ret = Interop.Bluetooth.SetAdvertisingDeviceName(GetHandle(), _packetType, _includeDeviceName);
674 if (ret != (int)BluetoothError.None) {
675 Log.Error (Globals.LogTag, "Failed to add device name to advertising data- " + (BluetoothError)ret);
676 BluetoothErrorFactory.ThrowBluetoothException(ret);
684 /// Sets whether the transmission power level should be included in the advertise or the scan response data.
685 /// The maximum advertised or responded data size is 31 bytes including the data type and the system wide data.
688 /// The Bluetooth must be enabled.
690 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
691 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
692 /// or when the set advertising TC power level fails.</exception>
693 /// <since_tizen> 3 </since_tizen>
694 public bool IncludeTxPowerLevel
698 return _includePowerLevel;
702 _includePowerLevel = value;
703 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
705 int ret = Interop.Bluetooth.SetAdvertisingTxPowerLevel(GetHandle(), _packetType, _includePowerLevel);
706 if (ret != (int)BluetoothError.None)
708 Log.Error(Globals.LogTag, "Failed to add advertising service solicitation uuid- " + (BluetoothError)ret);
714 /// Adds a service UUID to the advertise or the scan response data.
715 /// The maximum advertised or responded data size is 31 bytes
716 /// including the data type and the system wide data.
719 /// The Bluetooth must be enabled.
721 /// <param name="packetType">The packet type.</param>
722 /// <param name="serviceUuid"> The service UUID to add to advertise data.</param>
723 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
724 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
725 /// or when the add advertising service UUID procedure fails.</exception>
726 /// <since_tizen> 3 </since_tizen>
727 public void AddAdvertisingServiceUuid(BluetoothLePacketType packetType, string serviceUuid)
729 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
731 int ret = Interop.Bluetooth.AddAdvertisingServiceUuid (GetHandle (), packetType, serviceUuid);
732 if (ret != (int)BluetoothError.None) {
733 Log.Error (Globals.LogTag, "Failed to add service uuid to advertising data- " + (BluetoothError)ret);
734 BluetoothErrorFactory.ThrowBluetoothException (ret);
739 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
744 /// Adds a service solicitation UUID to advertise or scan the response data.
745 /// The maximum advertised or responded data size is 31 bytes
746 /// including the data type and the system wide data.
749 /// The Bluetooth must be enabled.
751 /// <param name="packetType">The packet type.</param>
752 /// <param name="serviceSolicitationUuid"> The service solicitation UUID to add to advertise data.</param>
753 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
754 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
755 /// or when the add advertising service solicitation UUID procedure fails.</exception>
756 /// <since_tizen> 3 </since_tizen>
757 public void AddAdvertisingServiceSolicitationUuid(BluetoothLePacketType packetType,
758 string serviceSolicitationUuid)
760 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
762 int ret = Interop.Bluetooth.AddAdvertisingServiceSolicitationUuid(GetHandle(), packetType,
763 serviceSolicitationUuid);
764 if (ret != (int)BluetoothError.None) {
765 Log.Error (Globals.LogTag, "Failed to add service solicitation uuid to advertising data- " + (BluetoothError)ret);
766 BluetoothErrorFactory.ThrowBluetoothException(ret);
771 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
776 /// Adds a service data to the advertise or the scan response data.
777 /// The maximum advertised or responded data size is 31 bytes
778 /// including data type and system wide data.
781 /// The Bluetooth must be enabled.
783 /// <param name="packetType">The packet type.</param>
784 /// <param name="data"> The service data to be added to advertising.</param>
785 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
786 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
787 /// or when the add advertising data procedure fails.</exception>
788 /// <since_tizen> 3 </since_tizen>
789 public void AddAdvertisingServiceData(BluetoothLePacketType packetType, BluetoothServiceData data)
791 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
793 IntPtr serviceDataPtr;
794 serviceDataPtr = Marshal.AllocHGlobal(data.DataLength);
795 Marshal.Copy(data.Data, 0, serviceDataPtr, data.DataLength);
797 for (int i = 0; i < 3; i++)
798 Log.Error (Globals.LogTag, " service data is " + data.Data [i]);
799 int ret = Interop.Bluetooth.AddAdvertisingServiceData(GetHandle(), packetType,
800 data.Uuid, serviceDataPtr, data.DataLength);
801 if (ret != (int)BluetoothError.None)
803 Log.Error(Globals.LogTag, "Failed to add service data to advertising data- " + (BluetoothError)ret);
804 BluetoothErrorFactory.ThrowBluetoothException(ret);
809 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
814 /// Adds the manufacturer specific data to the advertise or the scan response data.
815 /// Please refer to the adopted Bluetooth specification for the the appearance.
818 /// The Bluetooth must be enabled.
820 /// <param name="packetType">The packet type.</param>
821 /// <param name="manufacturerData"> The manufacturer specific data.</param>
822 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
823 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
824 /// or when the add advertising manufacturer data procedure fails.</exception>
825 /// <since_tizen> 3 </since_tizen>
826 public void AddAdvertisingManufacturerData(BluetoothLePacketType packetType,
827 ManufacturerData manufacturerData)
829 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
832 manufDataPtr = Marshal.AllocHGlobal(manufacturerData.DataLength);
833 Marshal.Copy(manufacturerData.Data, 0, manufDataPtr, manufacturerData.DataLength);
835 int ret = Interop.Bluetooth.AddAdvertisingManufData(GetHandle(), packetType,
836 manufacturerData.Id, manufDataPtr, manufacturerData.DataLength);
837 if (ret != (int)BluetoothError.None)
839 Log.Error(Globals.LogTag, "Failed to add service solicitation uuid to advertising data- " + (BluetoothError)ret);
840 BluetoothErrorFactory.ThrowBluetoothException(ret);
845 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
850 /// Clears all data to be advertised or responded to the scan request from the LE scanning device.
853 /// The Bluetooth must be enabled.
855 /// <param name="packetType">The packet type to be cleared.</param>
856 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
857 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
858 /// or when the clear advertising data procedure fails.</exception>
859 internal void ClearAdvertisingData(BluetoothLePacketType packetType)
861 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
863 int ret = Interop.Bluetooth.ClearAdvertisingData (GetHandle (), packetType);
864 if (ret != (int)BluetoothError.None) {
865 Log.Error (Globals.LogTag, "Failed to Clear Advertising Data- " + (BluetoothError)ret);
870 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);