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 public class BluetoothLeAdvertiser
30 private static readonly BluetoothLeAdvertiser _instance = new BluetoothLeAdvertiser();
32 internal static BluetoothLeAdvertiser Instance
40 private BluetoothLeAdvertiser()
45 /// This event is called when the LE advertising state changes.
47 public event EventHandler<AdvertisingStateChangedEventArgs> AdvertisingStateChanged
51 BluetoothLeImplAdapter.Instance.AdapterLeAdvertisingStateChanged += value;
55 BluetoothLeImplAdapter.Instance.AdapterLeAdvertisingStateChanged -= value;
59 /// Starts advertising using the advertise data object.
62 /// The Bluetooth must be enabled.
64 /// <param name="advertiseData">The advertiser object carrying information of the advertising.</param>
65 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
66 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
67 public void StartAdvertising(BluetoothLeAdvertiseData advertiseData)
69 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
71 int ret = BluetoothLeImplAdapter.Instance.StartAdvertising (advertiseData.GetHandle ());
72 if (ret != (int)BluetoothError.None) {
73 Log.Error (Globals.LogTag, "Failed to start advertising- " + (BluetoothError)ret);
74 BluetoothErrorFactory.ThrowBluetoothException(ret);
79 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
84 /// Stops the advertising.
87 /// The Bluetooth must be enabled.
89 /// <param name="advertiseData">The advertiser object carrying information of the advertising.</param>
90 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
91 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
92 public void StopAdvertising(BluetoothLeAdvertiseData advertiseData)
94 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
96 int ret = BluetoothLeImplAdapter.Instance.StopAdvertising (advertiseData.GetHandle ());
97 if (ret != (int)BluetoothError.None) {
98 Log.Error (Globals.LogTag, "Failed to stop advertising operation- " + (BluetoothError)ret);
99 BluetoothErrorFactory.ThrowBluetoothException(ret);
104 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
110 /// This is the BluetoothLeDevice class.
111 /// It handles the LE device operations like getting data from the scan result information.
113 public class BluetoothLeDevice
115 //properties of Bluetoothlesacandata
116 private string _remoteAddress;
117 private BluetoothLeDeviceAddressType _addressType;
119 private byte[] _advDataValue;
120 private byte[] _scanDataValue;
121 private BluetoothLePacketType _packetType;
122 private BluetoothLeScanData _scanData;
125 /// This event is called when the GATT client connects/disconnects with the server.
127 public event EventHandler<GattConnectionStateChangedEventArgs> GattConnectionStateChanged
131 BluetoothLeImplAdapter.Instance.LeGattConnectionStateChanged += value;
135 BluetoothLeImplAdapter.Instance.LeGattConnectionStateChanged -= value;
139 internal BluetoothLeDevice(BluetoothLeScanData scanData)
141 _scanData = new BluetoothLeScanData ();
142 _scanData = scanData;
144 Log.Info (Globals.LogTag, "Rssi" + _scanData.Rssi);
145 _rssi = scanData.Rssi;
146 Log.Info (Globals.LogTag, "RemoteAddress" + _scanData.RemoteAddress);
147 if (scanData.RemoteAddress != null)
148 _remoteAddress = scanData.RemoteAddress;
149 Log.Info (Globals.LogTag, "AddressType" + _scanData.AddressType);
150 _addressType = scanData.AddressType;
152 Log.Info (Globals.LogTag, "AdvDataLength" + _scanData.AdvDataLength);
153 if (_scanData.AdvDataLength > 0)
155 _advDataValue = new byte[_scanData.AdvDataLength];
156 scanData.AdvData.CopyTo(_advDataValue, 0);
159 Log.Info(Globals.LogTag, "ScanDataLength" + _scanData.ScanDataLength);
160 // Check length before copying
161 if (_scanData.ScanDataLength > 0)
163 _scanDataValue = new byte[_scanData.ScanDataLength];
164 scanData.ScanData.CopyTo(_scanDataValue, 0);
169 /// BluetoothLeDevice destructor.
173 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
175 BluetoothLeImplAdapter.Instance.FreeServiceDataList();
180 /// The remote address.
182 public string RemoteAddress
186 return _remoteAddress;
191 /// The type of the address.
193 public BluetoothLeDeviceAddressType AddressType
213 /// The advertsing data information.
215 public byte[] AdvertsingDataInformation
219 return _advDataValue;
224 /// The scan data information.
226 public byte[] ScanDataInformation
230 return _scanDataValue;
235 /// The type of the packet.
237 public BluetoothLePacketType PacketType
250 /// Gets the service UUIDs list from the LE scan result information.
252 /// <value> Gets the list of the string service UUIDs.</value>
254 /// The Bluetooth must be enabled.
256 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
257 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
258 public IEnumerable<string> ServiceUuid
262 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
264 Log.Info(Globals.LogTag, "Retrieving Service uuid- ");
265 return BluetoothLeImplAdapter.Instance.GetLeScanResultServiceUuids(_scanData, _packetType);
272 /// Gets the device name from the LE scan result information.
274 /// <value> Gets the device name.</value>
276 /// The Bluetooth must be enabled.
278 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
279 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
280 public string DeviceName
284 Log.Info(Globals.LogTag, "Retrieving device name- ");
285 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
287 return BluetoothLeImplAdapter.Instance.GetLeScanResultDeviceName(_scanData, _packetType);
293 /// Gets the transmission power level from the LE scan result information.
295 /// <value> Gets the transmission power level in dB.</value>
297 /// The Bluetooth must be enabled.
299 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
300 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
301 public int TxPowerLevel
305 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
307 return BluetoothLeImplAdapter.Instance.GetScanResultTxPowerLevel(_scanData, _packetType);
314 /// Gets the service solicitation UUID list from the scan result information.
316 /// <value> Gets the list of the service solicitation UUIDs.</value>
318 /// The Bluetooth must be enabled.
320 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
321 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
322 public IEnumerable<string> ServiceSolictationUuid
326 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
328 return BluetoothLeImplAdapter.Instance.GetScanResultSvcSolicitationUuids(_scanData, _packetType);
334 /// Gets the manufacturer data from the scan result information.
336 /// <value> Gets the appearance value.</value>
338 /// The Bluetooth must be enabled.
340 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
341 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
342 public int Appearance
346 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
348 return BluetoothLeImplAdapter.Instance.GetScanResultAppearance(_scanData, _packetType);
354 /// Gets the manufacturer data from the scan result information.
356 /// <value> Gets the manufacturer data containing the manucturer data and ID information.</value>
358 /// The Bluetooth must be enabled.
360 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
361 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>///
362 public ManufacturerData ManufacturerData
366 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
368 return BluetoothLeImplAdapter.Instance.GetScanResultManufacturerData(_scanData, _packetType);
375 /// Gets the service data list from the scan result information.
378 /// The Bluetooth must be enabled.
380 /// <returns> Returns the service data list.</returns>
381 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
382 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled.</exception>
383 public IEnumerable<BluetoothLeServiceData> GetServiceDataList()
385 int serviceCount = 0;
386 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
388 return BluetoothLeImplAdapter.Instance.GetScanResultServiceDataList(_scanData,
389 _packetType, out serviceCount);
396 /// Creates a GATT connection with the remote device.
399 /// The Bluetooth must be enabled.
401 /// <param name="autoConnect"> The auto connect flag.</param>
402 /// <returns>client instance</returns>
403 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
404 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
405 /// or when the gatt connection attempt to remote device fails.</exception>
406 public BluetoothGattClient GattConnect(bool autoConnect)
408 BluetoothGattClient client = null;
409 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
411 int ret = BluetoothLeImplAdapter.Instance.GattConnect (_remoteAddress, autoConnect);
412 if (ret != (int)BluetoothError.None) {
413 Log.Error (Globals.LogTag, "Failed to create GATT Connection with remote device- " + (BluetoothError)ret);
417 client = BluetoothGattClient.CreateClient(_remoteAddress);
422 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
428 /// Disconnects a GATT connection with the remote device.
431 /// The Bluetooth must be enabled.
433 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
434 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
435 /// or when the GATT disconnection attempt to remote device fails.</exception>
436 public void GattDisconnect()
438 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
440 int ret = BluetoothLeImplAdapter.Instance.GattDisconnect (_remoteAddress);
441 if (ret != (int)BluetoothError.None) {
442 Log.Error (Globals.LogTag, "Failed to disconnect GATT connection with remote device- " + (BluetoothError)ret);
447 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
453 /// Bluetooth LE advertise data. Handles the data advertising.
455 public class BluetoothLeAdvertiseData:IDisposable
457 private IntPtr _handle = IntPtr.Zero;
458 private BluetoothLeAdvertisingMode _mode;
459 private bool _advertisingConnectable;
460 private BluetoothLePacketType _packetType;
461 private int _appearance;
462 private bool _includePowerLevel;
463 private bool _includeDeviceName;
466 /// The default constructor initializes an object of the BluetoothLeAdvertiseData.
468 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
469 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
470 /// or when create advertiser fails.</exception>
471 public BluetoothLeAdvertiseData()
473 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
475 Log.Debug(Globals.LogTag, " Creating LeAdvertiser()");
476 int ret = Interop.Bluetooth.CreateAdvertiser(out _handle);
477 if (ret != (int)BluetoothError.None)
479 Log.Error(Globals.LogTag, "Failed to create advertiser object- " + (BluetoothError)ret);
480 BluetoothErrorFactory.ThrowBluetoothException(ret);
485 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
490 /// BluetoothLeAdvertiseData destructor.
492 ~BluetoothLeAdvertiseData()
494 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
497 ClearAdvertisingData (BluetoothLePacketType.BluetoothLeAdvertisingPacket);
498 ClearAdvertisingData (BluetoothLePacketType.BluetoothLeScanResponsePacket);
499 BluetoothLeImplAdapter.Instance.DestroyAdvertiser (_handle);
504 internal IntPtr GetHandle()
510 /// The advertising mode to control the advertising power and latency.
513 /// The Bluetooth must be enabled.
515 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
516 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
517 /// or when the set advertising mode fails.</exception>
518 public BluetoothLeAdvertisingMode AdvertisingMode
526 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
529 int ret = Interop.Bluetooth.SetAdvertisingMode (GetHandle (), _mode);
530 if (ret != (int)BluetoothError.None) {
531 Log.Error (Globals.LogTag, "Failed to set advertising mode- " + (BluetoothError)ret);
532 BluetoothErrorFactory.ThrowBluetoothException (ret);
539 /// The advertising connectable type.
542 /// The Bluetooth must be enabled.
544 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
545 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
546 /// or when the set advertising connectable mode fails.</exception>
547 public bool AdvertisingConnectable
551 return _advertisingConnectable;
555 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
557 _advertisingConnectable = value;
558 int ret = Interop.Bluetooth.SetAdvertisingConnectable (GetHandle (), _advertisingConnectable);
559 if (ret != (int)BluetoothError.None) {
560 Log.Error (Globals.LogTag, "Failed to set advertising connectable value- " + (BluetoothError)ret);
561 BluetoothErrorFactory.ThrowBluetoothException (ret);
570 public void Dispose()
573 GC.SuppressFinalize(this);
576 private void Dispose(bool disposing)
582 /// The type of the packet.
584 public BluetoothLePacketType PacketType
596 /// Sets the external appearance of this device to the advertise or the scan response data.
597 /// Please refer to the adopted Bluetooth specification for the appearance.
600 /// The Bluetooth must be enabled.
602 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
603 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
604 /// or when the set appearance fails.</exception>
605 public int Appearance
614 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize) {
615 int ret = Interop.Bluetooth.SetAdvertisingAppearance (GetHandle (), _packetType, _appearance);
616 if (ret != (int)BluetoothError.None) {
617 Log.Error (Globals.LogTag, "Failed to add appearance value to advertising data- " + (BluetoothError)ret);
618 BluetoothErrorFactory.ThrowBluetoothException(ret);
624 /// Sets whether the device name has to be included in the advertise or the scan response data.
625 /// The maximum advertised or responded data size is 31 bytes including the data type and the system wide data.
628 /// The Bluetooth must be enabled.
630 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
631 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
632 /// or when the set advertising device name fails.</exception>
633 public bool IncludeDeviceName
637 return _includeDeviceName;
641 _includeDeviceName = value;
642 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
644 int ret = Interop.Bluetooth.SetAdvertisingDeviceName(GetHandle(), _packetType, _includeDeviceName);
645 if (ret != (int)BluetoothError.None) {
646 Log.Error (Globals.LogTag, "Failed to add device name to advertising data- " + (BluetoothError)ret);
647 BluetoothErrorFactory.ThrowBluetoothException(ret);
655 /// Sets whether the transmission power level should be included in the advertise or the scan response data.
656 /// The maximum advertised or responded data size is 31 bytes including the data type and the system wide data.
659 /// The Bluetooth must be enabled.
661 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
662 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
663 /// or when the set advertising TC power level fails.</exception>
664 public bool IncludeTxPowerLevel
668 return _includePowerLevel;
672 _includePowerLevel = value;
673 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
675 int ret = Interop.Bluetooth.SetAdvertisingTxPowerLevel(GetHandle(), _packetType, _includePowerLevel);
676 if (ret != (int)BluetoothError.None)
678 Log.Error(Globals.LogTag, "Failed to add advertising service solicitation uuid- " + (BluetoothError)ret);
684 /// Adds a service UUID to the advertise or the scan response data.
685 /// The maximum advertised or responded data size is 31 bytes
686 /// including the data type and the system wide data.
689 /// The Bluetooth must be enabled.
691 /// <param name="packetType">The packet type.</param>
692 /// <param name="serviceUuid"> The service UUID to add to advertise data.</param>
693 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
694 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
695 /// or when the add advertising service UUID procedure fails.</exception>
696 public void AddAdvertisingServiceUuid(BluetoothLePacketType packetType, string serviceUuid)
698 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
700 int ret = Interop.Bluetooth.AddAdvertisingServiceUuid (GetHandle (), packetType, serviceUuid);
701 if (ret != (int)BluetoothError.None) {
702 Log.Error (Globals.LogTag, "Failed to add service uuid to advertising data- " + (BluetoothError)ret);
703 BluetoothErrorFactory.ThrowBluetoothException (ret);
708 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
713 /// Adds a service solicitation UUID to advertise or scan the response data.
714 /// The maximum advertised or responded data size is 31 bytes
715 /// including the data type and the system wide data.
718 /// The Bluetooth must be enabled.
720 /// <param name="packetType">The packet type.</param>
721 /// <param name="serviceSolicitationUuid"> The service solicitation UUID to add to advertise data.</param>
722 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
723 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
724 /// or when the add advertising service solicitation UUID procedure fails.</exception>
725 public void AddAdvertisingServiceSolicitationUuid(BluetoothLePacketType packetType,
726 string serviceSolicitationUuid)
728 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
730 int ret = Interop.Bluetooth.AddAdvertisingServiceSolicitationUuid(GetHandle(), packetType,
731 serviceSolicitationUuid);
732 if (ret != (int)BluetoothError.None) {
733 Log.Error (Globals.LogTag, "Failed to add service solicitation uuid to advertising data- " + (BluetoothError)ret);
734 BluetoothErrorFactory.ThrowBluetoothException(ret);
739 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
744 /// Adds a service data to the advertise or the scan response data.
745 /// The maximum advertised or responded data size is 31 bytes
746 /// including data type and system wide data.
749 /// The Bluetooth must be enabled.
751 /// <param name="packetType">The packet type.</param>
752 /// <param name="data"> The service data to be added to advertising.</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 data procedure fails.</exception>
756 public void AddAdvertisingServiceData(BluetoothLePacketType packetType, BluetoothServiceData data)
758 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
760 IntPtr serviceDataPtr;
761 serviceDataPtr = Marshal.AllocHGlobal(data.DataLength);
762 Marshal.Copy(data.Data, 0, serviceDataPtr, data.DataLength);
764 for (int i = 0; i < 3; i++)
765 Log.Error (Globals.LogTag, " service data is " + data.Data [i]);
766 int ret = Interop.Bluetooth.AddAdvertisingServiceData(GetHandle(), packetType,
767 data.Uuid, serviceDataPtr, data.DataLength);
768 if (ret != (int)BluetoothError.None)
770 Log.Error(Globals.LogTag, "Failed to add service data to advertising data- " + (BluetoothError)ret);
771 BluetoothErrorFactory.ThrowBluetoothException(ret);
776 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
781 /// Adds the manufacturer specific data to the advertise or the scan response data.
782 /// Please refer to the adopted Bluetooth specification for the the appearance.
785 /// The Bluetooth must be enabled.
787 /// <param name="packetType">The packet type.</param>
788 /// <param name="manufacturerData"> The manufacturer specific data.</param>
789 /// <exception cref="NotSupportedException">Thrown when the Bluetooth LE is not supported.</exception>
790 /// <exception cref="InvalidOperationException">Thrown when the Bluetooth LE is not enabled
791 /// or when the add advertising manufacturer data procedure fails.</exception>
792 public void AddAdvertisingManufacturerData(BluetoothLePacketType packetType,
793 ManufacturerData manufacturerData)
795 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
798 manufDataPtr = Marshal.AllocHGlobal(manufacturerData.DataLength);
799 Marshal.Copy(manufacturerData.Data, 0, manufDataPtr, manufacturerData.DataLength);
801 int ret = Interop.Bluetooth.AddAdvertisingManufData(GetHandle(), packetType,
802 manufacturerData.Id, manufDataPtr, manufacturerData.DataLength);
803 if (ret != (int)BluetoothError.None)
805 Log.Error(Globals.LogTag, "Failed to add service solicitation uuid to advertising data- " + (BluetoothError)ret);
806 BluetoothErrorFactory.ThrowBluetoothException(ret);
811 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
816 /// Clears all data to be advertised or responded to the scan request from the LE scanning device.
819 /// The Bluetooth must be enabled.
821 /// <param name="packetType">The packet type to be cleared.</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 clear advertising data procedure fails.</exception>
825 internal void ClearAdvertisingData(BluetoothLePacketType packetType)
827 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
829 int ret = Interop.Bluetooth.ClearAdvertisingData (GetHandle (), packetType);
830 if (ret != (int)BluetoothError.None) {
831 Log.Error (Globals.LogTag, "Failed to Clear Advertising Data- " + (BluetoothError)ret);
836 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);