From: Vibhav Pant vibhavp@gmail.com
This requests the system's Bluetooth service to send all incoming authentication requests to Wine's auth agent. This may be necessary to receive requests if another pairing agent outside Wine is already running. --- dlls/winebth.sys/dbus.c | 45 ++++++++++++++++++++++++++++++++ dlls/winebth.sys/unixlib.c | 8 ++++++ dlls/winebth.sys/unixlib.h | 2 ++ dlls/winebth.sys/unixlib_priv.h | 1 + dlls/winebth.sys/winebluetooth.c | 5 ++++ dlls/winebth.sys/winebth.c | 13 ++++++++- include/wine/winebth.h | 4 ++- 7 files changed, 76 insertions(+), 2 deletions(-)
diff --git a/dlls/winebth.sys/dbus.c b/dlls/winebth.sys/dbus.c index 7ea264e8a0a..f04a840b19b 100644 --- a/dlls/winebth.sys/dbus.c +++ b/dlls/winebth.sys/dbus.c @@ -1099,6 +1099,50 @@ NTSTATUS bluez_auth_agent_stop( void *connection, void *auth_agent_ctx ) return success ? STATUS_SUCCESS : STATUS_NO_MEMORY; }
+NTSTATUS bluez_auth_agent_request_default( void *connection ) +{ + static const char *wine_bluez_auth_agent_path = WINE_BLUEZ_AUTH_AGENT_PATH; + DBusMessage *request, *reply; + dbus_bool_t success; + NTSTATUS status; + DBusError error; + + TRACE( "(%p)\n", connection ); + + request = p_dbus_message_new_method_call( BLUEZ_DEST, "/org/bluez", BLUEZ_INTERFACE_AGENT_MANAGER, + "RequestDefaultAgent" ); + if (!request) + return STATUS_NO_MEMORY; + + success = p_dbus_message_append_args( request, DBUS_TYPE_OBJECT_PATH, &wine_bluez_auth_agent_path, + DBUS_TYPE_INVALID ); + if (!success) + { + p_dbus_message_unref( request ); + return STATUS_NO_MEMORY; + } + + p_dbus_error_init( &error ); + status = bluez_dbus_send_and_wait_for_reply( connection, request, &reply, &error ); + if (status) + { + p_dbus_message_unref( request ); + p_dbus_error_free( &error ); + return status; + } + if (!reply) + { + status = bluez_dbus_error_to_ntstatus( &error ); + ERR( "RequestDefaultAgent failed: %s: %s\n", debugstr_a( error.name ), debugstr_a( error.message ) ); + p_dbus_error_free( &error ); + return status; + } + p_dbus_error_free( &error ); + p_dbus_message_unref( reply ); + + return STATUS_SUCCESS; +} + struct bluez_watcher_event { struct list entry; @@ -2012,5 +2056,6 @@ NTSTATUS bluez_adapter_stop_discovery( void *connection, const char *adapter_pat } NTSTATUS bluez_auth_agent_start( void *connection, void **ctx ) { return STATUS_NOT_SUPPORTED; } NTSTATUS bluez_auth_agent_stop( void *connection ) { return STATUS_NOT_SUPPORTED; } +NTSTATUS bluez_auth_agent_request_default( void *connection ) { return STATUS_NOT_SUPPORTED; }
#endif /* SONAME_LIBDBUS_1 */ diff --git a/dlls/winebth.sys/unixlib.c b/dlls/winebth.sys/unixlib.c index 6afb3bacb00..7b3edaad61a 100644 --- a/dlls/winebth.sys/unixlib.c +++ b/dlls/winebth.sys/unixlib.c @@ -208,6 +208,12 @@ static NTSTATUS bluetooth_adapter_stop_discovery( void *args ) return bluez_adapter_stop_discovery( dbus_connection, params->adapter->str ); }
+static NTSTATUS bluetooth_auth_agent_enable_incoming( void *args ) +{ + if (!dbus_connection) return STATUS_NOT_SUPPORTED; + return bluez_auth_agent_request_default( dbus_connection ); +} + static NTSTATUS bluetooth_get_event( void *args ) { struct bluetooth_get_event_params *params = args; @@ -229,6 +235,8 @@ const unixlib_entry_t __wine_unix_call_funcs[] = {
bluetooth_device_free,
+ bluetooth_auth_agent_enable_incoming, + bluetooth_get_event, };
diff --git a/dlls/winebth.sys/unixlib.h b/dlls/winebth.sys/unixlib.h index 732c76f7d64..c9630fe6676 100644 --- a/dlls/winebth.sys/unixlib.h +++ b/dlls/winebth.sys/unixlib.h @@ -98,6 +98,8 @@ enum bluetoothapis_funcs
unix_bluetooth_device_free,
+ unix_bluetooth_auth_agent_enable_incoming, + unix_bluetooth_get_event,
unix_funcs_count diff --git a/dlls/winebth.sys/unixlib_priv.h b/dlls/winebth.sys/unixlib_priv.h index a81162b605e..29b789ab025 100644 --- a/dlls/winebth.sys/unixlib_priv.h +++ b/dlls/winebth.sys/unixlib_priv.h @@ -54,6 +54,7 @@ extern NTSTATUS bluez_adapter_set_prop( void *connection, struct bluetooth_adapter_set_prop_params *params ); extern NTSTATUS bluez_adapter_start_discovery( void *connection, const char *adapter_path ); extern NTSTATUS bluez_adapter_stop_discovery( void *connection, const char *adapter_path ); +extern NTSTATUS bluez_auth_agent_request_default( void *connection ); extern NTSTATUS bluez_auth_agent_start( void *connection, void **ctx ); extern NTSTATUS bluez_auth_agent_stop( void *connection, void *ctx ); extern NTSTATUS bluez_watcher_init( void *connection, void **ctx ); diff --git a/dlls/winebth.sys/winebluetooth.c b/dlls/winebth.sys/winebluetooth.c index cb3a27ba25d..0f421a87828 100644 --- a/dlls/winebth.sys/winebluetooth.c +++ b/dlls/winebth.sys/winebluetooth.c @@ -87,6 +87,11 @@ NTSTATUS winebluetooth_radio_stop_discovery( winebluetooth_radio_t radio ) return UNIX_BLUETOOTH_CALL(bluetooth_adapter_stop_discovery, ¶ms); }
+NTSTATUS winebluetooth_auth_agent_enable_incoming( void ) +{ + return UNIX_BLUETOOTH_CALL( bluetooth_auth_agent_enable_incoming, NULL ); +} + void winebluetooth_radio_free( winebluetooth_radio_t radio ) { struct bluetooth_adapter_free_params args = { 0 }; diff --git a/dlls/winebth.sys/winebth.c b/dlls/winebth.sys/winebth.c index fd825c1cba3..8c885cde2fa 100644 --- a/dlls/winebth.sys/winebth.c +++ b/dlls/winebth.sys/winebth.c @@ -97,9 +97,20 @@ static NTSTATUS WINAPI dispatch_auth( DEVICE_OBJECT *device, IRP *irp ) { IO_STACK_LOCATION *stack = IoGetCurrentIrpStackLocation( irp ); ULONG code = stack->Parameters.DeviceIoControl.IoControlCode; + NTSTATUS status = irp->IoStatus.Status; + + TRACE( "device %p irp %p code %#lx\n", device, irp, code );
- FIXME( "device %p irp %p code %#lx: stub!\n", device, irp, code ); + switch (code) + { + case IOCTL_WINEBTH_AUTH_REGISTER: + status = winebluetooth_auth_agent_enable_incoming(); + break; + default: + break; + }
+ irp->IoStatus.Status = status; IoCompleteRequest( irp, IO_NO_INCREMENT ); return irp->IoStatus.Status; } diff --git a/include/wine/winebth.h b/include/wine/winebth.h index d6e3b87c259..5fa702726a7 100644 --- a/include/wine/winebth.h +++ b/include/wine/winebth.h @@ -24,11 +24,13 @@
/* Set the discoverability or connectable flag for a local radio. Enabling discoverability will also enable incoming * connections, while disabling incoming connections disables discoverability as well. */ -#define IOCTL_WINEBTH_RADIO_SET_FLAG CTL_CODE(FILE_DEVICE_BLUETOOTH, 0xa3, METHOD_BUFFERED, FILE_ANY_ACCESS) +#define IOCTL_WINEBTH_RADIO_SET_FLAG CTL_CODE(FILE_DEVICE_BLUETOOTH, 0xa3, METHOD_BUFFERED, FILE_ANY_ACCESS) /* Start device inquiry for a local radio. */ #define IOCTL_WINEBTH_RADIO_START_DISCOVERY CTL_CODE(FILE_DEVICE_BLUETOOTH, 0xa6, METHOD_BUFFERED, FILE_ANY_ACCESS) /* Stop device inquiry for a local radio. */ #define IOCTL_WINEBTH_RADIO_STOP_DISCOVERY CTL_CODE(FILE_DEVICE_BLUETOOTH, 0xa7, METHOD_BUFFERED, FILE_ANY_ACCESS) +/* Ask the system's Bluetooth service to send all incoming authentication requests to Wine. */ +#define IOCTL_WINEBTH_AUTH_REGISTER CTL_CODE(FILE_DEVICE_BLUETOOTH, 0xa8, METHOD_BUFFERED, FILE_ANY_ACCESS)
DEFINE_GUID( GUID_WINEBTH_AUTHENTICATION_REQUEST, 0xca67235f, 0xf621, 0x4c27, 0x85, 0x65, 0xa4,