/// <summary> /// Forces the system to refresh the device information. /// </summary> /// - /// <remarks> /// See <see cref="P:InTheHand.Net.Sockets.BluetoothDeviceInfo.DeviceName"/> /// for one reason why this method is necessary. /// </remarks> public void Refresh() { #if WinXP valid = false; #endif deviceInfo.ulClassofDevice = 0; deviceInfo.szName = ""; _remoteVersionsInfo = null; }
private void ReadVersionsInfo() { if (_remoteVersionsInfo != null) return; #if WinXP bool success; BTH_RADIO_INFO buf; IntPtr radioHandle = BluetoothRadio.PrimaryRadio.Handle; /* * http://msdn.microsoft.com/en-us/library/ff536685(v=VS.85).aspx * The IOCTL_BTH_GET_RADIO_INFO request obtains information about the specified remote radio. * struct _BTH_RADIO_INFO { ULONGLONG lmpSupportedFeatures; USHORT mfg; USHORT lmpSubversion; UCHAR lmpVersion; */ /* * e.g. BTH_RADIO_INFO v1_2, 777, Broadcom, 00000808380DFEFF. * When no connection: INFO: IOCTL_BTH_GET_RADIO_INFO failure: 1167 = 0x48F. * 1167 = ERROR_DEVICE_NOT_CONNECTED */ //var h = this. // Windows 7 IOCTL long bthaddr = this.DeviceAddress.ToInt64();//endian? buf = new BTH_RADIO_INFO(); var len = Marshal.SizeOf(buf); int bytesReturned; success = NativeMethods.DeviceIoControl(radioHandle, NativeMethods.MsftWin32BthIOCTL.IOCTL_BTH_GET_RADIO_INFO, ref bthaddr, Marshal.SizeOf(bthaddr), ref buf, len, out bytesReturned, IntPtr.Zero); if (!success) { var gle = Marshal.GetLastWin32Error(); var ex = new System.ComponentModel.Win32Exception(); Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "INFO: IOCTL_BTH_GET_RADIO_INFO failure: {0} = 0x{1:X}.", (InTheHand.Win32.Win32Error)gle, gle)); Debug.Assert(gle == ex.NativeErrorCode); throw ex; } else { _remoteVersionsInfo = buf.ConvertToRadioVersions(); } #else LmpVersion lmpVersion; UInt16 lmpSubversion; Manufacturer mfg; LmpFeatures lmpSupportedFeatures; int ret = NativeMethods.BthReadRemoteVersion( this.DeviceAddress.ToByteArrayLittleEndian(), out lmpVersion, out lmpSubversion, out mfg, out lmpSupportedFeatures); const int ERROR_SUCCESS = 0; if (ret == ERROR_SUCCESS) { _remoteVersionsInfo = new RadioVersions(lmpVersion, lmpSubversion, lmpSupportedFeatures, mfg); } else { var gle = Marshal.GetLastWin32Error(); var ex = new System.ComponentModel.Win32Exception(ret); Debug.WriteLine("BthReadRemoteVersion fail: " + ret + ", gle: " + gle); Debug.Assert(ret == gle, "WAS using gle but docs say use ret. Check that are the same."); throw ex; } #endif }
/// <summary> /// Try to get the version information from the current device. /// </summary> /// <param name="versions">The returned version information.</param> /// <returns> /// Whether this operation was successful. /// </returns> public bool TryGetVersions(out RadioVersions versions) { versions = null; this.Refresh(); if (!this.Connected) { return(false); } versions = this.GetVersions(); return(versions != null); }
private BTRadioInfo BuildRadioDataModel(BluetoothDeviceInfo device) { try { this.log.InfoEntry("BuildRadioDataModel"); BTDeviceInfo info = new BTDeviceInfo() { Name = device.DeviceName, Address = device.DeviceAddress.ToString(), }; // Need to connect to each device to get radio info RadioVersions devRadio = null; if (this.Connect(info)) { devRadio = device.GetVersions(); } else { this.log.Error(9991, "NOT CONNECTED TO READ RADIO INFO"); } if (devRadio == null) { this.log.Info("", "NULL Radio info"); return(new BTRadioInfo()); } string tmp = devRadio.LmpSupportedFeatures.ToString(); string[] pieces = tmp.Split(','); List <string> features = new List <string>(pieces.Length); for (int i = 0; i < pieces.Length; i++) { features.Add(pieces[i].Replace("_", "").CamelCaseToSpaces()); } return(new BTRadioInfo() { Manufacturer = devRadio.Manufacturer.ToString().CamelCaseToSpaces(), LinkManagerProtocol = string.Format("{0} ({1})", devRadio.LmpVersion.LmpVerToString(), devRadio.LmpSubversion), Features = features, }); } catch (Exception e) { this.log.Exception(9999, "", e); return(new BTRadioInfo()); } finally { // TODO - move this to the getInfo function as it takes a 1/2 second per device disconnect this.Disconnect(); } }
void GetInfo(ref BluetoothAddress addr) { BtSdkError ret; var props = new Structs.BtSdkRemoteDevicePropertyStru(); ret = _factory.Api.Btsdk_GetRemoteDeviceProperty(_hDev, out props); BluesoleilUtils.CheckAndThrow(ret, "Btsdk_GetRemoteDeviceProperty"); // if ((props.mask & Structs.BtSdkRemoteDevicePropertyStru.Mask.Handle) != 0) { Debug.Assert(_hDev == props.dev_hdl, "hDev"); } else { Debug.Fail("Handle unknown?!?"); } if ((props.mask & Structs.BtSdkRemoteDevicePropertyStru.Mask.Address) != 0) { addr = BluesoleilUtils.ToBluetoothAddress(props.bd_addr); } if ((props.mask & Structs.BtSdkRemoteDevicePropertyStru.Mask.Class) != 0) { _cod = new ClassOfDevice(props.dev_class); } if ((props.mask & Structs.BtSdkRemoteDevicePropertyStru.Mask.Name) != 0) { Debug.Assert(props.name.Length == StackConsts.BTSDK_DEVNAME_LEN, "props.name.Length: " + props.name.Length + ", BTSDK_DEVNAME_LEN: " + StackConsts.BTSDK_DEVNAME_LEN); string name = BluesoleilUtils.FromNameString(props.name); _cachedName = name; } if ((props.mask & Structs.BtSdkRemoteDevicePropertyStru.Mask.LmpInfo) != 0) { var fs = (LmpFeatures)BitConverter.ToInt64(props.lmp_info.lmp_feature, 0); var v = new RadioVersions(props.lmp_info.lmp_version, props.lmp_info.lmp_subversion, fs, props.lmp_info.manuf_name); _versions = v; } //props. }