From: Vibhav Pant vibhavp@gmail.com
The event is sent when a remote Bluetooth device is either discovered during device inquiry, or when the its known properties have changed. --- dlls/winebth.sys/bthenum.c | 44 +++++++++++++++++++++++++++++++++++++- include/bthdef.h | 9 ++++++++ 2 files changed, 52 insertions(+), 1 deletion(-)
diff --git a/dlls/winebth.sys/bthenum.c b/dlls/winebth.sys/bthenum.c index 7e55cff1219..2d9ed16c070 100644 --- a/dlls/winebth.sys/bthenum.c +++ b/dlls/winebth.sys/bthenum.c @@ -220,14 +220,49 @@ static UINT32 device_get_flags( winebluetooth_device_props_mask_t props_mask, static BOOL device_set_properties( DEVICE_OBJECT *device_obj, UINT32 *old_flags, winebluetooth_device_props_mask_t props_mask, struct winebluetooth_device_properties props ); +static void device_get_properties( DEVICE_OBJECT *device_obj, BTH_DEVICE_INFO *info ); + +static void device_send_radio_in_range_event( DEVICE_OBJECT *device_obj, UINT32 old_flags ) +{ + TARGET_DEVICE_CUSTOM_NOTIFICATION *notification; + DWORD size = offsetof( TARGET_DEVICE_CUSTOM_NOTIFICATION, + CustomDataBuffer[sizeof( BTH_RADIO_IN_RANGE )] ); + BTH_RADIO_IN_RANGE *device_data; + struct bthenum_phys_remote_radio_ext *device_ext = + (struct bthenum_phys_remote_radio_ext *)device_obj->DeviceExtension; + NTSTATUS status; + + notification = malloc( size ); + if (!notification) + { + ERR( "Could not allocate memory for BLUETOOTH_RADIO_IN_RANGE event.\n" ); + return; + } + + notification->Version = 1; + notification->Size = size; + notification->Event = GUID_BLUETOOTH_RADIO_IN_RANGE; + notification->FileObject = NULL; + notification->NameBufferOffset = -1; + device_data = (BTH_RADIO_IN_RANGE *)notification->CustomDataBuffer; + device_data->previousDeviceFlags = old_flags; + device_get_properties( device_obj, &device_data->deviceInfo ); + + status = + IoReportTargetDeviceChange( device_ext->base.parent_fdo->parent_radio_pdo, notification ); + if (status) + ERR( "Could not send BLUETOOTH_RADIO_IN_RANGE notification: %#x\n", status ); + free( notification ); +}
static void device_refresh_properties( struct bthenum_phys_remote_radio_ext *remote_device, struct winebluetooth_device_properties new_props, - winebluetooth_device_props_mask_t changed_props) + winebluetooth_device_props_mask_t changed_props ) { UINT32 old_flags = device_get_flags( remote_device->known_props, remote_device->props ); device_set_properties( remote_device->device_obj, &old_flags, changed_props, new_props );
+ device_send_radio_in_range_event( remote_device->device_obj, old_flags ); return; }
@@ -721,6 +756,7 @@ static NTSTATUS WINAPI pdo_device_pnp( DEVICE_OBJECT *device_obj, IRP *irp ) { GUID g = GUID_NULL; GUID *guids = NULL; + BOOL discovering = FALSE;
if ( IoRegisterDeviceInterface( device->device_obj, &GUID_BTH_DEVICE_INTERFACE, NULL, &device->device_link_name ) == STATUS_SUCCESS ) @@ -741,6 +777,12 @@ static NTSTATUS WINAPI pdo_device_pnp( DEVICE_OBJECT *device_obj, IRP *irp ) } remote_device_refresh_services( device, guids, device->props.uuids_len ); if (guids) free( guids ); + /* If the radio is currently in a discovery procedure, notify userspace about the newly + * discovered device. */ + if (!IoGetDevicePropertyData( device->base.parent_fdo->parent_radio_pdo, + &DEVPKEY_WineBluetooth_Radio_Discovering, LOCALE_NEUTRAL, + 0, sizeof( BOOL ), &discovering, NULL, NULL ) && discovering) + device_send_radio_in_range_event( device_obj, 0 ); break; } case IRP_MN_SURPRISE_REMOVAL: diff --git a/include/bthdef.h b/include/bthdef.h index d431de929c9..6c200073995 100644 --- a/include/bthdef.h +++ b/include/bthdef.h @@ -49,6 +49,15 @@ typedef struct _BTH_DEVICE_INFO DEFINE_GUID( GUID_BTHPORT_DEVICE_INTERFACE, 0x850302a, 0xb344, 0x4fda, 0x9b, 0xe9, 0x90, 0x57, 0x6b, 0x8d, 0x46, 0xf0 );
+DEFINE_GUID( GUID_BLUETOOTH_RADIO_IN_RANGE, 0xea3b5b82, 0x26ee, 0x450e, 0xb0, 0xd8, 0xd2, 0x6f, + 0xe3, 0x0a, 0x38, 0x69 ); +typedef struct _BTH_RADIO_IN_RANGE +{ + BTH_DEVICE_INFO deviceInfo; + /* 0 when the device has just been discovered. */ + ULONG previousDeviceFlags; +} BTH_RADIO_IN_RANGE, *PBTH_RADIO_IN_RANGE; + #ifdef __cplusplus } #endif