Fixed failing tcts in the le adapter.
re-arrangement of code and fix issues to handle crash
Change-Id: I9cf2efa6b88527eb934342ffb1d2010395a54860
Signed-off-by: Sudha Bheemanna <b.sudha@samsung.com>
-/*
+/*
* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
}
}
- /// </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>
}
}
- 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 BluetoothLeServiceData
{
internal string Uuid;
- internal string Data;
+ internal byte[] Data;
internal int Length;
internal BluetoothLeServiceData()
/// <summary>
/// Bluetooth Le service data
/// </summary>
- public string ServiceData
+ public byte[] ServiceData
{
get
{
return null;
}
- IntPtr[] svcList = new IntPtr[_serviceListCount];
- Marshal.Copy(serviceListArray, svcList, 0, _serviceListCount);
- foreach (IntPtr svcs in svcList)
+ BluetoothLeServiceDataStruct[] svcList = new BluetoothLeServiceDataStruct[_serviceListCount];
+ int sizePointerToABC = Marshal.SizeOf(new BluetoothLeServiceDataStruct());
+ for (int i = 0; i < _serviceListCount; i++)
{
- BluetoothLeServiceDataStruct svcstruct = (BluetoothLeServiceDataStruct)Marshal.PtrToStructure(svcs, typeof(BluetoothLeServiceDataStruct));
- _list.Add(BluetoothUtils.ConvertStructToLeServiceData(svcstruct));
- Interop.Libc.Free(svcs);
+ svcList[i] = (BluetoothLeServiceDataStruct)Marshal.PtrToStructure(new IntPtr(serviceListArray.ToInt32() + (i * sizePointerToABC)), typeof(BluetoothLeServiceDataStruct));
+ Log.Info(Globals.LogTag, " Uuid : " + svcList[i].ServiceUuid + "length : " + svcList[i].ServiceDataLength);
+
+ _list.Add(BluetoothUtils.ConvertStructToLeServiceData(svcList[i]));
}
serviceCount = _serviceListCount;
data.Id = dataId;
data.DataLength = dataLength;
- Marshal.Copy(manufData, data.Data, 0, data.DataLength);
+ if (data.DataLength > 0)
+ Marshal.Copy(manufData, data.Data, 0, data.DataLength);
return data;
}
internal string ServiceUuid;
}
+ /// </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;
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct BluetoothLeServiceDataStruct
+ {
+ /// <summary>
+ /// Bluetooth Le service uuid.
+ /// </summary>
+ [MarshalAs(UnmanagedType.LPStr)]
+ internal string ServiceUuid;
+ /// <summary>
+ /// Bluetooth Le service data
+ /// </summary>
+ internal IntPtr ServiceData;
+
+ internal int ServiceDataLength;
+ }
+
internal static class BluetoothUtils
{
internal static BluetoothDevice ConvertStructToDeviceClass(BluetoothDeviceStruct device)
internal static BluetoothLeServiceData ConvertStructToLeServiceData(BluetoothLeServiceDataStruct structServiceData)
{
BluetoothLeServiceData serviceData = new BluetoothLeServiceData();
+ Log.Info(Globals.LogTag, "ServiceDataLength" + structServiceData.ServiceDataLength);
+
if (structServiceData.ServiceDataLength > 0)
{
serviceData.Uuid = structServiceData.ServiceUuid;
serviceData.Length = structServiceData.ServiceDataLength;
- serviceData.Data = structServiceData.ServiceData;
+ serviceData.Data = new byte[serviceData.Length];
+ Marshal.Copy(structServiceData.ServiceData, serviceData.Data, 0, serviceData.Length);
}
return serviceData;
}