internal static void FindUnsetValues(LmpFeatures lmpFeatures) { #if DEBUG Action <LmpFeatures> action = delegate(LmpFeatures bitMask) { var x = lmpFeatures & bitMask; if (x == 0) { var name = Enum.GetName(typeof(LmpFeatures), bitMask); string msg; if (name == null) { //msg = "((Not exist: '" + bitMask + "' 0x" + ((UInt64)bitMask).ToString("X16") + "))"; //Debug.WriteLine(msg); } else { msg = "Not set: '" + bitMask + "' 0x" + ((UInt64)bitMask).ToString("X16"); Debug.WriteLine(msg); Debug.Fail(msg); } } }; ForEachBit(action); #endif }
internal BTH_RADIO_INFO(Version fakeSetAllUnknown) { _lmpSupportedFeatures = 0; _mfg = Manufacturer.Unknown; _lmpSubversion = 0; _lmpVersion = LmpVersion.Unknown; }
internal BTH_RADIO_INFO(LmpVersion lmpVersion, UInt16 lmpSubversion, Manufacturer mfg, UInt64 lmpSupportedFeatures) { _lmpSupportedFeatures = unchecked ((LmpFeatures)lmpSupportedFeatures); _mfg = mfg; _lmpSubversion = lmpSubversion; _lmpVersion = lmpVersion; }
public RadioVersions(LmpVersion lmpVersion, ushort lmpSubversion, LmpFeatures lmpSupportedFeatures, Manufacturer mfg) { this.LmpVersion = lmpVersion; LmpSubversion = lmpSubversion; LmpSupportedFeatures = lmpSupportedFeatures; Manufacturer = mfg; }
//private IntPtr msgQueueHandle; //private IntPtr notificationHandle; #region Constructor internal WindowsBluetoothRadio(IntPtr handle) { //get version/manufacturer byte CHECK0 = 0; byte hv; byte CHECK1 = 0; ushort hr; byte CHECK2 = 0; byte lv; byte CHECK3 = 0; ushort ls; byte CHECK4 = 0; ushort man; byte CHECK5 = 0; const int HciFeaturesLength = 8; var fea = new byte[HciFeaturesLength]; byte CHECK6 = 0; int hresult = NativeMethods.BthReadLocalVersion(out hv, out hr, out lv, out ls, out man, fea); Debug.Assert((CHECK0 == 0) && (CHECK1 == 0) && (CHECK2 == 0) && (CHECK3 == 0) && (CHECK4 == 0) && (CHECK5 == 0) && (CHECK6 == 0)); if (hresult == 0) { manufacturer = (Manufacturer)man; _hciV = (HciVersion)hv; _hciRev = hr; _lmpV = (LmpVersion)lv; _lmpSubv = ls; var feaI = BitConverter.ToInt64(fea, 0); // ?? ordering ?? _lmpFeatures = (LmpFeatures)feaI; var msgFe = "BtRadio lmpFeatures: '" + _lmpFeatures + "' 0x" + _lmpFeatures.ToString("X"); Debug.WriteLine(msgFe); } else { manufacturer = Manufacturer.Unknown; _hciV = HciVersion.Unknown; _lmpV = LmpVersion.Unknown; } //setup message queue /*NativeMethods.MSGQUEUEOPTIONS mqo = new NativeMethods.MSGQUEUEOPTIONS(); * mqo.dwFlags = 0; * mqo.cbMaxMessage = 72; * mqo.bReadAccess = true; * mqo.dwSize = System.Runtime.InteropServices.Marshal.SizeOf(mqo); * msgQueueHandle = NativeMethods.CreateMsgQueue("InTheHand.Net.Bluetooth.BluetoothRadio", ref mqo); * * notificationHandle = NativeMethods.RequestBluetoothNotifications(NativeMethods.BTE_CLASS.CONNECTIONS | NativeMethods.BTE_CLASS.DEVICE | NativeMethods.BTE_CLASS.PAIRING | NativeMethods.BTE_CLASS.STACK, msgQueueHandle); * * System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(EventThread)); * t.IsBackground = true; * t.Start();*/ }
void ReadVersionsOnce() { if (_readVersions) { return; } _readVersions = true; // Just do once even if error BluetopiaError ret; try { StackConsts.HCI_ERROR_CODE hciStatus; ret = _fcty.Api.HCI_Read_Local_Version_Information(_fcty.StackId, out hciStatus, out _hciVersion, out _hciRev, out _lmpVersion, out _manuf, out _lmpSubver); } catch (MissingMethodException) { // Function added later to the SDK. ret = BluetopiaError.UNSUPPORTED_PLATFORM_ERROR; } BluetopiaUtils.Assert(ret, "HCI_Read_Local_Version_Information"); if (!BluetopiaUtils.IsSuccess(ret)) { _hciVersion = HciVersion.Unknown; _lmpVersion = LmpVersion.Unknown; _manuf = Manufacturer.Unknown; _hciRev = _lmpSubver = 0; } var arr = new byte[8]; try { StackConsts.HCI_ERROR_CODE hciStatus; ret = _fcty.Api.HCI_Read_Local_Supported_Features(_fcty.StackId, out hciStatus, arr); } catch (MissingMethodException) { // Function added later to the SDK. ret = BluetopiaError.UNSUPPORTED_PLATFORM_ERROR; } BluetopiaUtils.Assert(ret, "HCI_Read_Local_Version_Information"); if (BluetopiaUtils.IsSuccess(ret)) { _lmpFeatures = (LmpFeatures)BitConverter.ToInt64(arr, 0); } else { _lmpFeatures = LmpFeatures.None; } }
internal static void FindUndefinedValues(LmpFeatures lmpFeatures) { #if DEBUG Action <LmpFeatures> action = delegate(LmpFeatures bitMask) { var x = lmpFeatures & bitMask; if (x != 0) { var name = Enum.GetName(typeof(LmpFeatures), x); if (name == null) { var msg = "Not defined: 0x" + unchecked ((UInt64)x).ToString("X16"); Debug.WriteLine(msg); Debug.Fail(msg); } } }; ForEachBit(action); #endif }
//-- void ReadVersions() { if (_doneVersions) { return; } var vers = new Structs.hci_version(HciVersion.Unknown); var ret = NativeMethods.hci_read_local_version(_dd, ref vers, _fcty.StackTimeout); BluezUtils.Assert(ret, "hci_read_local_version"); if (BluezUtils.IsSuccess(ret)) { _versions = vers; } _doneVersions = true; // Always set, as unlikely to work second time if failed first time. // var arr = new byte[8]; ret = NativeMethods.hci_read_local_features(_dd, arr, _fcty.StackTimeout); if (BluezUtils.IsSuccess(ret)) { _lmpFeatures = (LmpFeatures)BitConverter.ToInt64(arr, 0); } }
internal static extern int BthReadRemoteVersion(byte[] pba, out LmpVersion plmp_version, out ushort plmp_subversion, out Manufacturer pmanufacturer, out LmpFeatures plmp_features);
void ReadVersionInfo(WindowsRadioHandle handle, ref LmpVersion lmpV, ref int lmpSubv, ref HciVersion hciV, ref int hciRev, ref LmpFeatures lmpFeatures) { // Windows 7 IOCTL var buf = new byte[300]; int bytesReturned; var success = NativeMethods.DeviceIoControl(handle, NativeMethods.MsftWin32BthIOCTL.IOCTL_BTH_GET_LOCAL_INFO, IntPtr.Zero, 0, buf, buf.Length, out bytesReturned, IntPtr.Zero); if (!success) { int gle = Marshal.GetLastWin32Error(); Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "INFO: IOCTL_BTH_GET_LOCAL_INFO failure: {0} = 0x{0:X}.", gle)); } else { const int OffsetOf_flags = 272; const int OffsetOf_hciRevision = OffsetOf_flags + 4; const int OffsetOf_hciVersion = OffsetOf_hciRevision + 2; const int OffsetOf_radioInfo = OffsetOf_hciVersion + 1; //????? pad?? const int OffsetOf_lmpFeatures = OffsetOf_radioInfo; const int OffsetOf_mfg = OffsetOf_radioInfo + 8; const int OffsetOf_lmpSubversion = OffsetOf_mfg + 2; const int OffsetOf_lmpVersion = OffsetOf_lmpSubversion + 2; const int OffsetOf_END = OffsetOf_lmpVersion + 1; const int ExpectedSize = 292; Debug.Assert(OffsetOf_END == ExpectedSize, "OffsetOf_END: " + OffsetOf_END + ", ExpectedSize: " + ExpectedSize); hciRev = BitConverter.ToUInt16(buf, OffsetOf_hciRevision); hciV = (HciVersion)buf[OffsetOf_hciVersion]; lmpSubv = BitConverter.ToUInt16(buf, OffsetOf_lmpSubversion); lmpV = (LmpVersion)buf[OffsetOf_lmpVersion]; var dbg_mfg = BitConverter.ToUInt16(buf, OffsetOf_mfg); Debug.Assert(lmpSubv == radio.lmpSubversion, "_lmpSubv: " + lmpSubv + ", radio.lmpSubversion: " + radio.lmpSubversion); Debug.Assert(dbg_mfg == unchecked ((ushort)radio.manufacturer), "dbg_mfg: " + dbg_mfg + ", radio.manufacturer: " + radio.manufacturer); Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "hciSubvers: {0}, hciVersion: {1}, lmpSubversion : {2}, lmpVersion: {3}", hciRev, hciV, lmpSubv, lmpV)); var flags = (LOCAL_FLAGS)BitConverter.ToUInt32(buf, OffsetOf_flags); lmpFeatures = (LmpFeatures)BitConverter.ToInt64(buf, OffsetOf_lmpFeatures); #if DEBUG var msgFl = "IOCTL_BTH_GET_LOCAL_INFO flags: '" + flags + "' 0x" + flags.ToString("X"); //Debug.WriteLine(msgFl); //Console.WriteLine(msgFl); // var msgFe = "IOCTL_BTH_GET_LOCAL_INFO lmpFeatures: '" + lmpFeatures + "' 0x" + lmpFeatures.ToString("X"); Debug.WriteLine(msgFe); //Console.WriteLine(msgFe); LmpFeaturesUtils.FindUndefinedValues(lmpFeatures); //LmpFeaturesUtils.FindUnsetValues(lmpFeatures); #endif } }