public static bool IsStackCompatible() { BLUETOOTH_DEVICE_INFO device = new BLUETOOTH_DEVICE_INFO(); device.dwSize = Marshal.SizeOf(typeof(BLUETOOTH_DEVICE_INFO)); device.szName = ""; BLUETOOTH_DEVICE_SEARCH_PARAMS searchparams = new BLUETOOTH_DEVICE_SEARCH_PARAMS(); searchparams.dwSize = Marshal.SizeOf(typeof(BLUETOOTH_DEVICE_SEARCH_PARAMS)); searchparams.fIssueInquiry = true; searchparams.fReturnAuthenticated = true; searchparams.fReturnConnected = true; searchparams.fReturnRemembered = true; searchparams.fReturnUnknown = false; searchparams.hRadio = IntPtr.Zero; searchparams.cTimeoutMultiplier = 1; IntPtr handle = BluetoothFindFirstDevice(ref searchparams, ref device); if (handle != IntPtr.Zero) BluetoothFindDeviceClose(handle); return handle != IntPtr.Zero; }
public static extern uint BluetoothAuthenticateDeviceEx( IntPtr hwndParentIn, IntPtr hRadioIn, ref BLUETOOTH_DEVICE_INFO pbtdiInout, /*BLUETOOTH_OOB_DATA*/ object pbtOobData, AUTHENTICATION_REQUIREMENTS authenticationRequirement);
public static extern bool BluetoothFindNextDevice( IntPtr hFind, ref BLUETOOTH_DEVICE_INFO pbtdi);
private bool NativeCallback(BluetoothAuthenticationMethod method, IntPtr param, ref BLUETOOTH_DEVICE_INFO bdi, bool versionEx, ref BLUETOOTH_AUTHENTICATION_CALLBACK_PARAMS?pAuthCallbackParams) { System.Diagnostics.Debug.Assert(m_pin == null ^ m_userCallback == null); // System.Diagnostics.Debug.WriteLine(String.Format( System.Globalization.CultureInfo.InvariantCulture, "AuthenticateResponder callback (for {0}): 0x{1:X} 0x{2:X}", m_remoteAddress, param, bdi.Address)); // String pin; Int32 ret; if (m_pin != null) { // Pre-specified case. System.Diagnostics.Debug.Assert(bdi.Address == m_remoteAddress.ToInt64(), "Should only get callback for the single device."); //TODO if (bdi.Address != m_remoteAddress.ToInt64()) { // return false; //} pin = m_pin; if (versionEx) { // TODO Want to send a positive response here to NumericComparison?? ret = BluetoothSendAuthenticationResponseExPin(ref bdi, pin); } else { ret = NativeMethods.BluetoothSendAuthenticationResponse( m_radioHandle, ref bdi, pin); } } else if (method == BluetoothAuthenticationMethod.Legacy) { // Callback case. System.Diagnostics.Debug.Assert(m_userCallback != null); BluetoothWin32AuthenticationEventArgs e = new BluetoothWin32AuthenticationEventArgs(bdi); while (true) { // Callback the user code OnAuthentication(e); // Don't proceed if no (null) passcode given, or // if the last attempt was successful, or // the decvice has disppeared. if (e.Pin == null) { ret = NativeErrorSuccess; break; } if (e.PreviousNativeErrorCode == NativeErrorSuccess && e.AttemptNumber != 0) { Debug.Assert(e.CallbackWithResult, "NOT CbWR but here (A#)!!"); ret = NativeErrorSuccess; break; } if (e.PreviousNativeErrorCode == NativeErrorDeviceNotConnected) { Debug.Assert(e.CallbackWithResult, "NOT CbWR but here (DNC)!!"); // When I try this (against Win2k+Belkin and iPaq hx2190, // both apparently with Broadcom) I see: //[[ //Authenticate one device -- with wrong passcode here the first two times. //Passcode respectively: 'BAD-x', 'BAD-y', '9876' //Making PC discoverable //Hit Return to complete //Authenticating 0017E464CF1E wm_alan1 // Attempt# 0, Last error code 0 //Using '0.23672947484847' //Authenticating 0017E464CF1E wm_alan1 // Attempt# 1, Last error code 1244 //Using '0.54782851764365' //Authenticating 0017E464CF1E wm_alan1 // Attempt# 2, Last error code 1167 //Using '9876' //Authenticating 0017E464CF1E wm_alan1 // Attempt# 3, Last error code 1167 //etc //]] // That is we see the error code of 1244=ErrorNotAuthenticated // once, and then the peer device disappears (1167=ErrorDeviceNotConnected). // I suppose that's a security feature -- its stops an attacker // from trying again and again with different passcodes. // // Anyway the result of that is that is it NOT worth repeating // the callback after the device disappears. ret = NativeErrorSuccess; break; } pin = e.Pin; System.Diagnostics.Debug.WriteLine(String.Format(System.Globalization.CultureInfo.InvariantCulture, "BW32Auth SendAuthRsp pin {0}", pin)); if (versionEx) { ret = BluetoothSendAuthenticationResponseExPin(ref bdi, pin); } else { ret = NativeMethods.BluetoothSendAuthenticationResponse( m_radioHandle, ref bdi, pin); } if (ret != NativeErrorSuccess) { System.Diagnostics.Trace.WriteLine(String.Format( System.Globalization.CultureInfo.InvariantCulture, " BluetoothSendAuthenticationResponse failed: {0}=0x{0:X}", ret)); } // Have to callback the user code after the attempt? BluetoothWin32AuthenticationEventArgs lastEa = e; if (!lastEa.CallbackWithResult) { break; } e = new BluetoothWin32AuthenticationEventArgs(ret, lastEa); } } else if (method == BluetoothAuthenticationMethod.NumericComparison || method == BluetoothAuthenticationMethod.Passkey || method == BluetoothAuthenticationMethod.PasskeyNotification || method == BluetoothAuthenticationMethod.OutOfBand ) { // Callback case. System.Diagnostics.Debug.Assert(m_userCallback != null); BluetoothWin32AuthenticationEventArgs e = new BluetoothWin32AuthenticationEventArgs(bdi, ref pAuthCallbackParams); while (true) { // Callback the user code OnAuthentication(e); // Check if after e.CallbackWithResult... if (e.PreviousNativeErrorCode == NativeErrorSuccess && e.AttemptNumber != 0) { Debug.Assert(e.CallbackWithResult, "NOT CbWR but here (A#)!!"); ret = NativeErrorSuccess; break; } if (e.PreviousNativeErrorCode == NativeErrorDeviceNotConnected) { Debug.Assert(e.CallbackWithResult, "NOT CbWR but here (DNC)!!"); ret = NativeErrorSuccess; break; } bool?confirm = e.Confirm; System.Diagnostics.Debug.WriteLine(String.Format(System.Globalization.CultureInfo.InvariantCulture, "BW32Auth SendAuthRspEx-NumComparison {0}", confirm)); if (confirm == null) { ret = NativeErrorSuccess; break; } if (method != BluetoothAuthenticationMethod.OutOfBand) { ret = BluetoothSendAuthenticationResponseExNumCompPasskey(ref bdi, confirm, e); } else { ret = BluetoothSendAuthenticationResponseExOob(ref bdi, confirm, e); } if (ret != NativeErrorSuccess) { System.Diagnostics.Trace.WriteLine(String.Format( System.Globalization.CultureInfo.InvariantCulture, " BluetoothSendAuthenticationResponseEx failed: {0}=0x{0:X}", ret)); } // Have to callback the user code after the attempt? BluetoothWin32AuthenticationEventArgs lastEa = e; if (!lastEa.CallbackWithResult) { break; } e = new BluetoothWin32AuthenticationEventArgs(ret, lastEa); } } else { Debug.Fail("Unsupported auth method: " + method); ret = NativeErrorSuccess; } // if (ret != NativeErrorSuccess) { System.Diagnostics.Trace.WriteLine(String.Format( System.Globalization.CultureInfo.InvariantCulture, "BluetoothSendAuthenticationResponse failed: {0}=0x{0:X}", ret)); } return(true); // "The return value from this function is ignored by the system." }
static extern bool BluetoothFindNextDevice(IntPtr hFind, ref BLUETOOTH_DEVICE_INFO DeviceInfo);
//---- internal static BluetoothWin32RadioOutOfRangeEventArgs Create(long addrLong) { BLUETOOTH_DEVICE_INFO bdi0 = new BLUETOOTH_DEVICE_INFO(addrLong); return(new BluetoothWin32RadioOutOfRangeEventArgs(bdi0)); }
static extern IntPtr BluetoothFindFirstDevice(ref BLUETOOTH_DEVICE_SEARCH_PARAMS SearchParams, ref BLUETOOTH_DEVICE_INFO DeviceInfo);
internal DeviceInformationPairing(BLUETOOTH_DEVICE_INFO info) { _deviceInfo = info; }
public static BTSTATUS BT_InquireDevices(INQUIRY ucInqMode, byte ucInqTimeLen, out BLUETOOTH_DEVICE_INFO[] deviceInfos) { NativeMethods.BLUETOOTH_DEVICE_INFO DeviceInfo = new BLUETOOTH_DEVICE_INFO(); long DeviceInfoSize = Marshal.SizeOf(DeviceInfo); int DeviceInfoCount = 1; long DeviceInfosSize = DeviceInfoCount * DeviceInfoSize; IntPtr DeviceInfosPtr = Marshal.AllocHGlobal((int)DeviceInfosSize); // Copy the struct to unmanaged memory. Marshal.StructureToPtr(DeviceInfo, DeviceInfosPtr, false); BTSTATUS result = NativeMethods.BT_InquireDevices( ucInqMode, ucInqTimeLen, ref DeviceInfosSize, DeviceInfosPtr); DeviceInfoCount = (int)(DeviceInfosSize / DeviceInfoSize); deviceInfos = new BLUETOOTH_DEVICE_INFO[DeviceInfoCount]; for (int i = 0; i < DeviceInfoCount; i++) { DeviceInfo = (BLUETOOTH_DEVICE_INFO)Marshal.PtrToStructure(new IntPtr(DeviceInfosPtr.ToInt64() + i * DeviceInfoSize), typeof(BLUETOOTH_DEVICE_INFO)); deviceInfos[i] = DeviceInfo; } return result; }
public static BTSTATUS BT_ConnectService(BLUETOOTH_DEVICE_INFO DeviceInfo, GENERAL_SERVICE_INFO ServiceInfo, ref int lpConnectionHandle) { int DeviceInfoSize = Marshal.SizeOf(DeviceInfo); IntPtr DeviceInfoPtr = Marshal.AllocHGlobal(DeviceInfoSize); Marshal.StructureToPtr(DeviceInfo, DeviceInfoPtr, false); int ServiceInfoSize = Marshal.SizeOf(ServiceInfo); IntPtr ServiceInfoPtr = Marshal.AllocHGlobal(ServiceInfoSize); Marshal.StructureToPtr(ServiceInfo, ServiceInfoPtr, false); return BT_ConnectService(DeviceInfoPtr, ServiceInfoPtr, IntPtr.Zero, ref lpConnectionHandle); }
public static BTSTATUS BT_BrowseServices(BLUETOOTH_DEVICE_INFO DeviceInfo, bool bBrowseAllServices, out GENERAL_SERVICE_INFO[] ServiceInfos) { int DeviceInfoSize = Marshal.SizeOf(DeviceInfo); IntPtr DeviceInfoPtr = Marshal.AllocHGlobal(DeviceInfoSize); Marshal.StructureToPtr(DeviceInfo, DeviceInfoPtr, false); GENERAL_SERVICE_INFO ServiceInfo = new GENERAL_SERVICE_INFO(); int ServiceInfoCount = 16; int ServiceInfoSize = Marshal.SizeOf(ServiceInfo); int ServiceInfosSize = ServiceInfoSize * ServiceInfoCount; IntPtr ServiceInfosPtr = Marshal.AllocHGlobal(ServiceInfosSize); Marshal.StructureToPtr(ServiceInfo, ServiceInfosPtr, false); ServiceInfoCount = 0; BTSTATUS result = NativeMethods.BT_BrowseServices( DeviceInfoPtr, bBrowseAllServices, ref ServiceInfosSize, ServiceInfosPtr); ServiceInfoCount = ServiceInfosSize / ServiceInfoSize; ServiceInfos = new GENERAL_SERVICE_INFO[ServiceInfoCount]; for (int i = 0; i < ServiceInfoCount; i++) { ServiceInfos[i] = (GENERAL_SERVICE_INFO)Marshal.PtrToStructure(new IntPtr(ServiceInfosPtr.ToInt64() + i * ServiceInfoSize), typeof(GENERAL_SERVICE_INFO)); } return result; }
/// <summary> /// Initializes an instance of the BluetoothDeviceInfo class for the device with the given address. /// </summary> /// <param name="address">The BluetoothAddress.</param> public BluetoothDeviceInfo(BluetoothAddress address) { _info = BLUETOOTH_DEVICE_INFO.Create(); _info.Address = address; DoRefresh(); }
private void Connect(bool DisconnectOld) { //TODO: honour disconnectold parameter BLUETOOTH_DEVICE_INFO device = new BLUETOOTH_DEVICE_INFO(); device.dwSize = Marshal.SizeOf(typeof(BLUETOOTH_DEVICE_INFO)); device.szName = ""; BLUETOOTH_DEVICE_SEARCH_PARAMS searchparams = new BLUETOOTH_DEVICE_SEARCH_PARAMS(); searchparams.dwSize = Marshal.SizeOf(typeof(BLUETOOTH_DEVICE_SEARCH_PARAMS)); searchparams.fIssueInquiry = true; searchparams.fReturnAuthenticated = true; searchparams.fReturnConnected = true; searchparams.fReturnRemembered = true; searchparams.fReturnUnknown = true; searchparams.hRadio = IntPtr.Zero; searchparams.cTimeoutMultiplier = 1; bool connected = false; IntPtr handle = BluetoothFindFirstDevice(ref searchparams, ref device); if (handle == IntPtr.Zero) { int lasterror = Marshal.GetLastWin32Error(); if (lasterror != 0) LogError("Bluetooth API returned: " + lasterror.ToString()); } else { while (true) { if (Cancel) break; if (device.szName.StartsWith("Nintendo RVL")) { if (device.fRemembered) { BluetoothRemoveDevice(ref device.Address); } else { if (BluetoothSetServiceState(IntPtr.Zero, ref device, ref HumanInterfaceDeviceServiceClass_UUID, BLUETOOTH_SERVICE_ENABLE) != 0) LogError("Failed to connect to wiimote controller"); else connected = true; } break; } device.szName = ""; if (!BluetoothFindNextDevice(handle, ref device)) break; } } BluetoothFindDeviceClose(handle); try { if (connected && Connected != null) Connected(this, EventArgs.Empty); else if (ConnectionFailed != null) ConnectionFailed(this, EventArgs.Empty); } catch(Exception) { } }
static extern uint BluetoothSetServiceState(IntPtr hRadio, ref BLUETOOTH_DEVICE_INFO DeviceInfo, ref Guid guid, int ServiceFlags);
public static extern int BluetoothGetDeviceInfo(IntPtr hRadio, ref BLUETOOTH_DEVICE_INFO pbtdi);
public DeviceInformation PickSingleDevice() { NativeMethods.BLUETOOTH_SELECT_DEVICE_PARAMS sdp = new NativeMethods.BLUETOOTH_SELECT_DEVICE_PARAMS(); sdp.dwSize = Marshal.SizeOf(sdp); sdp.hwndParent = Process.GetCurrentProcess().MainWindowHandle; sdp.numDevices = 1; #if !UNITY /*if (!string.IsNullOrEmpty(Appearance.Title)) * { * sdp.info = Appearance.Title; * }*/ #endif //defaults sdp.fShowAuthenticated = true; sdp.fShowUnknown = false; List <int> codMasks = new List <int>(); if (Filter.SupportedDeviceSelectors.Count > 0) { foreach (string filter in Filter.SupportedDeviceSelectors) { var parts = filter.Split(':'); switch (parts[0]) { case "bluetoothClassOfDevice": int codMask = 0; if (int.TryParse(parts[1], NumberStyles.HexNumber, null, out codMask)) { codMasks.Add(codMask); break; } break; case "bluetoothPairingState": bool pairingState = bool.Parse(parts[1]); if (pairingState) { sdp.fShowAuthenticated = true; sdp.fShowUnknown = false; } else { sdp.fShowAuthenticated = false; sdp.fShowUnknown = true; } break; } } } sdp.hwndParent = NativeMethods.GetForegroundWindow(); if (codMasks.Count > 0) { // marshal the CODs to native memory sdp.numOfClasses = codMasks.Count; sdp.prgClassOfDevices = Marshal.AllocHGlobal(8 * codMasks.Count); for (int i = 0; i < codMasks.Count; i++) { Marshal.WriteInt32(new IntPtr(sdp.prgClassOfDevices.ToInt32() + (8 * i)), codMasks[i]); } } /*if (Filter.SupportedDeviceSelectors.Count > 0) * { * _callback = new NativeMethods.PFN_DEVICE_CALLBACK(FilterDevices); * sdp.pfnDeviceCallback = _callback; * //sdp.pvParam = Marshal.AllocHGlobal(4); * //Marshal.WriteInt32(sdp.pvParam, 1); * }*/ bool success = NativeMethods.BluetoothSelectDevices(ref sdp); if (sdp.prgClassOfDevices != IntPtr.Zero) { Marshal.FreeHGlobal(sdp.prgClassOfDevices); sdp.prgClassOfDevices = IntPtr.Zero; sdp.numOfClasses = 0; } if (success) { #if UNITY BLUETOOTH_DEVICE_INFO info = (BLUETOOTH_DEVICE_INFO)Marshal.PtrToStructure(sdp.pDevices, typeof(BLUETOOTH_DEVICE_INFO)); #else BLUETOOTH_DEVICE_INFO info = Marshal.PtrToStructure <BLUETOOTH_DEVICE_INFO>(sdp.pDevices); #endif NativeMethods.BluetoothSelectDevicesFree(ref sdp); foreach (string query in Filter.SupportedDeviceSelectors) { var parts = query.Split(':'); if (parts[0] == "bluetoothService") { Guid serviceUuid = new Guid(parts[1]); foreach (Guid g in BluetoothDevice.GetRfcommServices(ref info)) { if (g == serviceUuid) { return(new DeviceInformation(info, serviceUuid)); } } return(null); } } return(new DeviceInformation(info)); } return(null); }
internal BluetoothWin32AuthenticationEventArgs(BLUETOOTH_DEVICE_INFO device) : this(new BluetoothDeviceInfo(new WindowsBluetoothDeviceInfo(device))) { }
public static extern IntPtr BluetoothFindFirstDevice(ref BLUETOOTH_DEVICE_SEARCH_PARAMS pSearchParams, ref BLUETOOTH_DEVICE_INFO pbtdi);
private void DoDevTypHandle(ref WndProcClient.WindowMessage m, ref String text) { DEV_BROADCAST_HANDLE hdrHandle = (DEV_BROADCAST_HANDLE)Marshal.PtrToStructure(m.lParam, typeof(DEV_BROADCAST_HANDLE)); var pData = PointerUtils.Add(m.lParam, _OffsetOfData); if (BluetoothDeviceNotificationEvent.BthPortDeviceInterface == hdrHandle.dbch_eventguid) { text += "GUID_BTHPORT_DEVICE_INTERFACE"; } else if (BluetoothDeviceNotificationEvent.RadioInRange == hdrHandle.dbch_eventguid) { text += "GUID_BLUETOOTH_RADIO_IN_RANGE"; BTH_RADIO_IN_RANGE inRange = (BTH_RADIO_IN_RANGE)Marshal.PtrToStructure(pData, typeof(BTH_RADIO_IN_RANGE)); text += String.Format(" 0x{0:X12}", inRange.deviceInfo.address); text += String.Format(" is ({0}) 0x{0:X}", inRange.deviceInfo.flags); text += String.Format(" was ({0}) 0x{0:X}", inRange.previousDeviceFlags); var bdi0 = BLUETOOTH_DEVICE_INFO.Create(inRange.deviceInfo); var e = BluetoothWin32RadioInRangeEventArgs.Create( inRange.previousDeviceFlags, inRange.deviceInfo.flags, bdi0); DeviceInRange?.Invoke(this, e); } else if (BluetoothDeviceNotificationEvent.RadioOutOfRange == hdrHandle.dbch_eventguid) { BTH_RADIO_OUT_OF_RANGE outOfRange = (BTH_RADIO_OUT_OF_RANGE)Marshal.PtrToStructure(pData, typeof(BTH_RADIO_OUT_OF_RANGE)); text += "GUID_BLUETOOTH_RADIO_OUT_OF_RANGE"; text += String.Format(System.Globalization.CultureInfo.InvariantCulture, " 0x{0:X12}", outOfRange.deviceAddress); var e = BluetoothWin32RadioOutOfRangeEventArgs.Create( outOfRange.deviceAddress); DeviceOutOfRange?.Invoke(this, e); } else if (BluetoothDeviceNotificationEvent.PinRequest == hdrHandle.dbch_eventguid) { text += "GUID_BLUETOOTH_PIN_REQUEST"; } else if (BluetoothDeviceNotificationEvent.L2capEvent == hdrHandle.dbch_eventguid) { text += "GUID_BLUETOOTH_L2CAP_EVENT"; } else if (BluetoothDeviceNotificationEvent.HciEvent == hdrHandle.dbch_eventguid) { text += "GUID_BLUETOOTH_HCI_EVENT"; } else if (BluetoothDeviceNotificationEvent.AuthenticationRequestEvent == hdrHandle.dbch_eventguid) { text += "GUID_BLUETOOTH_AUTHENTICATION_REQUEST"; } else if (BluetoothDeviceNotificationEvent.KeyPressEvent == hdrHandle.dbch_eventguid) { text += "GUID_BLUETOOTH_KEYPRESS_EVENT"; } else if (BluetoothDeviceNotificationEvent.HciVendorEvent == hdrHandle.dbch_eventguid) { text += "GUID_BLUETOOTH_HCI_VENDOR_EVENT"; } else { text += "Unknown event: " + hdrHandle.dbch_eventguid; } Log.Verbose("Interop.Win32: Device changed: " + text); }
private BluetoothWin32RadioOutOfRangeEventArgs(BLUETOOTH_DEVICE_INFO bdi0) : base(bdi0) { }
public extern static IntPtr MyBluetoothFindFirstDevice( ref BLUETOOTH_DEVICE_SEARCH_PARAMS btsp, ref BLUETOOTH_DEVICE_INFO btdi );
private void Connect(bool DisconnectOld) { //TODO: honour disconnectold parameter BLUETOOTH_DEVICE_INFO device = new BLUETOOTH_DEVICE_INFO(); device.dwSize = Marshal.SizeOf(typeof(BLUETOOTH_DEVICE_INFO)); device.szName = ""; BLUETOOTH_DEVICE_SEARCH_PARAMS searchparams = new BLUETOOTH_DEVICE_SEARCH_PARAMS(); searchparams.dwSize = Marshal.SizeOf(typeof(BLUETOOTH_DEVICE_SEARCH_PARAMS)); searchparams.fIssueInquiry = true; searchparams.fReturnAuthenticated = true; searchparams.fReturnConnected = true; searchparams.fReturnRemembered = true; searchparams.fReturnUnknown = true; searchparams.hRadio = IntPtr.Zero; searchparams.cTimeoutMultiplier = 1; bool connected = false; IntPtr handle = BluetoothFindFirstDevice(ref searchparams, ref device); if (handle == IntPtr.Zero) { int lasterror = Marshal.GetLastWin32Error(); if (lasterror != 0) { LogError("Bluetooth API returned: " + lasterror.ToString()); } } else { while (true) { if (Cancel) { break; } if (device.szName.StartsWith("Nintendo RVL")) { if (device.fRemembered) { BluetoothRemoveDevice(ref device.Address); } else { if (BluetoothSetServiceState(IntPtr.Zero, ref device, ref HumanInterfaceDeviceServiceClass_UUID, BLUETOOTH_SERVICE_ENABLE) != 0) { LogError("Failed to connect to wiimote controller"); } else { connected = true; } } break; } device.szName = ""; if (!BluetoothFindNextDevice(handle, ref device)) { break; } } } BluetoothFindDeviceClose(handle); try { if (connected && Connected != null) { Connected(this, EventArgs.Empty); } else if (ConnectionFailed != null) { ConnectionFailed(this, EventArgs.Empty); } } catch (Exception) { } }
public extern static bool MyBluetoothFindNextDevice( IntPtr hFind, ref BLUETOOTH_DEVICE_INFO btdi );
public extern static UInt32 MyBluetoothSetServiceState( IntPtr hRadio, ref BLUETOOTH_DEVICE_INFO btdi, ref Guid GUIDService, UInt32 dwServiceFlags );
public static extern IntPtr BluetoothFindFirstDevice( ref BLUETOOTH_DEVICE_SEARCH_PARAMS searchParams, ref BLUETOOTH_DEVICE_INFO deviceInfo);
public extern static UInt32 MyBluetoothAuthenticateDevice( IntPtr hwnd, IntPtr hRadio, ref BLUETOOTH_DEVICE_INFO btdi, char[] passkey, UInt32 passkeylen);
public static extern uint BluetoothAuthenticateDevice( IntPtr hwndParent, IntPtr hRadio, ref BLUETOOTH_DEVICE_INFO pbtdi, [MarshalAs(UnmanagedType.LPWStr)] string pszPasskey, ulong ulPasskeyLength);
public extern static UInt32 MyBluetoothEnumerateInstalledServices( IntPtr hRadio, ref BLUETOOTH_DEVICE_INFO btdi, ref UInt32 pcServices, Guid[] pGuidServices);
public static extern uint BluetoothSetServiceState( IntPtr hRadio, ref BLUETOOTH_DEVICE_INFO pbtdi, ref Guid pGuidService, byte dwServiceFlags);
internal BluetoothDeviceInfo(BLUETOOTH_DEVICE_INFO info) { _info = info; }
private void DoDevTypHandle(ref Message m, ref String text) { #if DEBUG WindowsBluetoothDeviceInfo dev = null; #endif DEV_BROADCAST_HANDLE hdrHandle = (DEV_BROADCAST_HANDLE)m.GetLParam(typeof(DEV_BROADCAST_HANDLE)); var pData = Utils.Pointers.Add(m.LParam, _OffsetOfData); if (BluetoothDeviceNotificationEvent.BthPortDeviceInterface == hdrHandle.dbch_eventguid) { text += "GUID_BTHPORT_DEVICE_INTERFACE"; } else if (BluetoothDeviceNotificationEvent.RadioInRange == hdrHandle.dbch_eventguid) { text += "GUID_BLUETOOTH_RADIO_IN_RANGE"; BTH_RADIO_IN_RANGE inRange = (BTH_RADIO_IN_RANGE)Marshal.PtrToStructure(pData, typeof(BTH_RADIO_IN_RANGE)); text += String.Format(System.Globalization.CultureInfo.InvariantCulture, " 0x{0:X12}", inRange.deviceInfo.address); text += String.Format(System.Globalization.CultureInfo.InvariantCulture, " is ({0}) 0x{0:X}", inRange.deviceInfo.flags); text += String.Format(System.Globalization.CultureInfo.InvariantCulture, " was ({0}) 0x{0:X}", inRange.previousDeviceFlags); var bdi0 = BLUETOOTH_DEVICE_INFO.Create(inRange.deviceInfo); var e = BluetoothWin32RadioInRangeEventArgs.Create( inRange.previousDeviceFlags, inRange.deviceInfo.flags, bdi0); #if DEBUG dev = new WindowsBluetoothDeviceInfo(bdi0); Debug.WriteLine("InRange: " + dev.DeviceAddress); #endif RaiseInRange(e); } else if (BluetoothDeviceNotificationEvent.RadioOutOfRange == hdrHandle.dbch_eventguid) { BTH_RADIO_OUT_OF_RANGE outOfRange = (BTH_RADIO_OUT_OF_RANGE)Marshal.PtrToStructure(pData, typeof(BTH_RADIO_OUT_OF_RANGE)); text += "GUID_BLUETOOTH_RADIO_OUT_OF_RANGE"; text += String.Format(System.Globalization.CultureInfo.InvariantCulture, " 0x{0:X12}", outOfRange.deviceAddress); var e = BluetoothWin32RadioOutOfRangeEventArgs.Create( outOfRange.deviceAddress); Debug.WriteLine("OutOfRange: " + outOfRange.deviceAddress); RaiseOutOfRange(e); } else if (BluetoothDeviceNotificationEvent.PinRequest == hdrHandle.dbch_eventguid) { text += "GUID_BLUETOOTH_PIN_REQUEST"; // "This message should be ignored by the application. // If the application must receive PIN requests, the // BluetoothRegisterForAuthentication function should be used." } else if (BluetoothDeviceNotificationEvent.L2capEvent == hdrHandle.dbch_eventguid) { text += "GUID_BLUETOOTH_L2CAP_EVENT"; // struct BTH_L2CAP_EVENT_INFO { // BTH_ADDR bthAddress; USHORT psm; UCHAR connected; UCHAR initiated; } #if DEBUG var l2capE = Marshal_PtrToStructure <BTH_L2CAP_EVENT_INFO>(pData); Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "L2CAP_EVENT: addr: {0:X}, psm: {1}, conn: {2}, init'd: {3}", l2capE.bthAddress, l2capE.psm, l2capE.connected, l2capE.initiated)); #endif } else if (BluetoothDeviceNotificationEvent.HciEvent == hdrHandle.dbch_eventguid) { text += "GUID_BLUETOOTH_HCI_EVENT"; // struct BTH_HCI_EVENT_INFO { // BTH_ADDR bthAddress; UCHAR connectionType; UCHAR connected; } #if DEBUG var hciE = Marshal_PtrToStructure <BTH_HCI_EVENT_INFO>(pData); Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "HCI_EVENT: addr: {0:X}, type: {1}, conn: {2}", hciE.bthAddress, hciE.connectionType, hciE.connected)); #endif } // -- New somewhere after WinXP. else if (BluetoothDeviceNotificationEvent.AuthenticationRequestEvent == hdrHandle.dbch_eventguid) { text += "GUID_BLUETOOTH_AUTHENTICATION_REQUEST"; // Same content as BluetoothRegisterForAuthenticationEx } else if (BluetoothDeviceNotificationEvent.KeyPressEvent == hdrHandle.dbch_eventguid) { text += "GUID_BLUETOOTH_KEYPRESS_EVENT"; // struct BTH_HCI_KEYPRESS_INFO { // BTH_ADDR BTH_ADDR; UCHAR NotificationType; // HCI_KEYPRESS_XXX value } } else if (BluetoothDeviceNotificationEvent.HciVendorEvent == hdrHandle.dbch_eventguid) { text += "GUID_BLUETOOTH_HCI_VENDOR_EVENT"; } // -- Unknown else { text += "Unknown event: " + hdrHandle.dbch_eventguid; } Debug.WriteLine("Text: " + text); }
public BluetoothDeviceInfo(BluetoothAddress address) { _info = BLUETOOTH_DEVICE_INFO.Create(); _info.Address = address; NativeMethods.BluetoothGetDeviceInfo(IntPtr.Zero, ref _info); }
internal static extern int BluetoothEnumerateInstalledServices( IntPtr hRadio, ref BLUETOOTH_DEVICE_INFO pbtdi, ref int pcServices, Guid[] pGuidServices);
internal DeviceInformation(BLUETOOTH_DEVICE_INFO info, Guid service) : this(info) { _service = service; }
//---- private BluetoothWin32RadioInRangeEventArgs(BLUETOOTH_DEVICE_INFO bdi0, BluetoothDeviceInfoProperties currentFlags, BluetoothDeviceInfoProperties previousFlags) : base(bdi0) { _currentFlags = currentFlags; _previousFlags = previousFlags; }
public static extern bool BluetoothFindNextDevice(IntPtr hFind, ref BLUETOOTH_DEVICE_INFO pbtdi);
//-------- internal /*and protected*/ BluetoothWin32RadioEventArgs(BLUETOOTH_DEVICE_INFO bdi0) { _bdiWin = new WindowsBluetoothDeviceInfo(bdi0); _bdi = new BluetoothDeviceInfo(_bdiWin); }