IBluetoothDeviceInfo[] DoDiscoverDevices( int maxDevices, bool authenticated, bool remembered, bool unknown, bool discoverableOnly, BluetoothClient.LiveDiscoveryCallback liveDiscoHandler, object liveDiscoState) { Console.WriteLine("DoDiscoverDevices"); var discoTime = DateTime.UtcNow; List <IBluetoothDeviceInfo> known = new List <IBluetoothDeviceInfo>(); // hack often GC fodder var bus = _fcty.BluezDbus; known = bus.GetDeviceList_OnDefaultAdapter(); // List <IBluetoothDeviceInfo> inquired = null; if (discoverableOnly || unknown) { inquired = new List <IBluetoothDeviceInfo>(); double td = InquiryLength.TotalSeconds; const double Multiplier = 1.25d; td /= Multiplier; int t = (int)td; StackConsts.IREQ_int flags = StackConsts.IREQ_int.IREQ_CACHE_FLUSH; // var TypeofItem = typeof(Structs.inquiry_info); var SizeofItem = Marshal.SizeOf(TypeofItem); IntPtr pii = BluezUtils.malloc(maxDevices * SizeofItem); try { Console.WriteLine("Gonna hci_inquiry num_rsp: {0}, t: {1} ({2} was {3}) ", maxDevices, t, td, InquiryLength); // TO-DO LAP/IAC: var lap = InquiryAccessCode; //var stackTrace = new StackTrace(); //var msg = "Gonna hci_inquiry at: " + stackTrace; //Debug.WriteLine(msg); //Console.WriteLine(msg); int num = NativeMethods.hci_inquiry(_fcty.DevId, t, maxDevices, IntPtr.Zero, ref pii, flags); Console.WriteLine("inquiry num=" + num); //BluezUtils.CheckAndThrow((BluezError)num, "hci_inquiry"); BluezUtils.Assert((BluezError)num, "hci_inquiry"); // IntPtr pCur = pii; for (int i = 0; i < num; i++) { var cur = (Structs.inquiry_info)Marshal.PtrToStructure(pCur, TypeofItem); var bdi = BluezDeviceInfo.CreateFromInquiry(_fcty, cur); inquired.Add(bdi); pCur = PointerAdd(pCur, SizeofItem); }//for } finally { BluezUtils.free(pii); } } // var merged = BluetoothClient.DiscoverDevicesMerge( authenticated, remembered, unknown, known, inquired, discoverableOnly, discoTime); return(merged.ToArray()); }
internal static extern int hci_inquiry(int dev_id, int len, int num_rsp, byte[] lap, ref IntPtr /*"inquiry_info **"*/ ppii, StackConsts.IREQ_int flags);