From: Vibhav Pant vibhavp@gmail.com
--- dlls/wlanapi/Makefile.in | 6 +- dlls/wlanapi/dbus.c | 101 ++++++++++++++++++++++++++++++++ dlls/wlanapi/dbus.h | 113 ++++++++++++++++++++++++++++++++++++ dlls/wlanapi/main.c | 35 +++++++++++ dlls/wlanapi/unixlib.c | 71 ++++++++++++++++++++++ dlls/wlanapi/unixlib.h | 48 +++++++++++++++ dlls/wlanapi/unixlib_priv.h | 28 +++++++++ 7 files changed, 401 insertions(+), 1 deletion(-) create mode 100644 dlls/wlanapi/dbus.c create mode 100644 dlls/wlanapi/dbus.h create mode 100644 dlls/wlanapi/unixlib.c create mode 100644 dlls/wlanapi/unixlib.h create mode 100644 dlls/wlanapi/unixlib_priv.h
diff --git a/dlls/wlanapi/Makefile.in b/dlls/wlanapi/Makefile.in index bd2bf87d4d1..92e65dabd54 100644 --- a/dlls/wlanapi/Makefile.in +++ b/dlls/wlanapi/Makefile.in @@ -1,7 +1,11 @@ MODULE = wlanapi.dll IMPORTLIB = wlanapi +UNIXLIB = wlanapi.so +UNIX_CFLAGS = $(DBUS_CFLAGS)
EXTRADLLFLAGS = -Wb,--prefer-native
SOURCES = \ - main.c + main.c \ + dbus.c \ + unixlib.c diff --git a/dlls/wlanapi/dbus.c b/dlls/wlanapi/dbus.c new file mode 100644 index 00000000000..8a6b5e5b5bb --- /dev/null +++ b/dlls/wlanapi/dbus.c @@ -0,0 +1,101 @@ +/* + * wlanapi DBus backed implementation + * + * Copyright 2024 Vibhav Pant + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#if 0 +#pragma makedep unix +#endif + +#include "config.h" + +#include <dlfcn.h> + +#ifdef SONAME_LIBDBUS_1 +#include <dbus/dbus.h> +#endif + +#include <ntstatus.h> +#define WIN32_NO_STATUS +#include <winternl.h> + +#include <wine/debug.h> + +#include "dbus.h" + +WINE_DEFAULT_DEBUG_CHANNEL( wlanapi ); + +#ifdef SONAME_LIBDBUS_1 + +#define DO_FUNC( f ) typeof( f ) (*p_##f) +DBUS_FUNCS; +#undef DO_FUNC + +BOOL load_dbus_functions( void ) +{ + void *handle = dlopen( SONAME_LIBDBUS_1, RTLD_NOW ); + + if (handle == NULL) goto failed; + +#define DO_FUNC( f ) \ + if (!(p_##f = dlsym( handle, #f ))) \ + { \ + ERR( "failed to load symbol %s: %s\n", #f, dlerror() ); \ + goto failed; \ + } + DBUS_FUNCS; +#undef DO_FUNC + p_dbus_threads_init_default(); + return TRUE; + +failed: + WARN( "failed to load DBus support: %s\n", dlerror() ); + return FALSE; +} + +NTSTATUS init_dbus_connection( UINT_PTR *handle ) +{ + DBusError error; + DBusConnection *connection; + NTSTATUS ret = STATUS_SUCCESS; + + p_dbus_error_init( &error ); + connection = p_dbus_bus_get_private( DBUS_BUS_SYSTEM, &error ); + if (connection == NULL) + { + ERR( "Failed to get system dbus connection: %s: %s.\n", debugstr_a( error.name ), + debugstr_a( error.message ) ); + ret = STATUS_NOT_SUPPORTED; + } + else + *handle = (UINT_PTR)connection; + p_dbus_error_free( &error ); + + return ret; +} + +void close_dbus_connection( void *c ) +{ + p_dbus_connection_close( c ); + p_dbus_connection_unref( c ); +} +#else /* SONAME_LIBDBUS_1 */ +BOOL load_dbus_functions( void ) { return FALSE; } +NTSTATUS init_dbus_connection( UINT_PTR *handle ) { return STATUS_NOT_SUPPORTED; } +void close_dbus_connection( void *c ) { return STATUS_NOT_SUPPORTED; } +#endif diff --git a/dlls/wlanapi/dbus.h b/dlls/wlanapi/dbus.h new file mode 100644 index 00000000000..86c5309d117 --- /dev/null +++ b/dlls/wlanapi/dbus.h @@ -0,0 +1,113 @@ +/* + * DBus declarations. + * + * Copyright 2024 Vibhav Pant + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef __WINE_WLANAPI_UNIXLIB_DBUS_H +#define __WINE_WLANAPI_UNIXLIB_DBUS_H + +#include "config.h" + +#ifdef SONAME_LIBDBUS_1 +#include <dbus/dbus.h> +#endif + +#ifdef SONAME_LIBDBUS_1 + +#define DBUS_FUNCS \ + DO_FUNC(dbus_bus_add_match); \ + DO_FUNC(dbus_bus_get); \ + DO_FUNC(dbus_bus_get_id); \ + DO_FUNC(dbus_bus_get_private); \ + DO_FUNC(dbus_bus_remove_match); \ + DO_FUNC(dbus_connection_add_filter); \ + DO_FUNC(dbus_connection_close); \ + DO_FUNC(dbus_connection_flush); \ + DO_FUNC(dbus_connection_free_preallocated_send); \ + DO_FUNC(dbus_connection_get_is_anonymous); \ + DO_FUNC(dbus_connection_get_is_authenticated); \ + DO_FUNC(dbus_connection_get_is_connected); \ + DO_FUNC(dbus_connection_get_server_id); \ + DO_FUNC(dbus_connection_get_unix_process_id); \ + DO_FUNC(dbus_connection_get_unix_fd); \ + DO_FUNC(dbus_connection_get_unix_user); \ + DO_FUNC(dbus_connection_preallocate_send); \ + DO_FUNC(dbus_connection_read_write_dispatch); \ + DO_FUNC(dbus_connection_remove_filter); \ + DO_FUNC(dbus_connection_ref); \ + DO_FUNC(dbus_connection_send); \ + DO_FUNC(dbus_connection_send_preallocated); \ + DO_FUNC(dbus_connection_send_with_reply); \ + DO_FUNC(dbus_connection_send_with_reply_and_block); \ + DO_FUNC(dbus_connection_try_register_object_path); \ + DO_FUNC(dbus_connection_unref); \ + DO_FUNC(dbus_connection_unregister_object_path); \ + DO_FUNC(dbus_error_free); \ + DO_FUNC(dbus_error_has_name) ; \ + DO_FUNC(dbus_error_init); \ + DO_FUNC(dbus_error_is_set); \ + DO_FUNC(dbus_free); \ + DO_FUNC(dbus_free_string_array); \ + DO_FUNC(dbus_message_append_args); \ + DO_FUNC(dbus_message_get_args); \ + DO_FUNC(dbus_message_iter_get_element_count); \ + DO_FUNC(dbus_message_get_interface); \ + DO_FUNC(dbus_message_get_member); \ + DO_FUNC(dbus_message_get_path); \ + DO_FUNC(dbus_message_get_sender); \ + DO_FUNC(dbus_message_get_serial); \ + DO_FUNC(dbus_message_get_signature); \ + DO_FUNC(dbus_message_get_type); \ + DO_FUNC(dbus_message_has_signature); \ + DO_FUNC(dbus_message_iter_has_next); \ + DO_FUNC(dbus_message_is_error); \ + DO_FUNC(dbus_message_is_method_call); \ + DO_FUNC(dbus_message_is_signal); \ + DO_FUNC(dbus_message_iter_append_basic); \ + DO_FUNC(dbus_message_iter_close_container); \ + DO_FUNC(dbus_message_iter_get_arg_type); \ + DO_FUNC(dbus_message_iter_get_element_type); \ + DO_FUNC(dbus_message_iter_get_basic); \ + DO_FUNC(dbus_message_iter_get_fixed_array); \ + DO_FUNC(dbus_message_iter_get_signature); \ + DO_FUNC(dbus_message_iter_init); \ + DO_FUNC(dbus_message_iter_init_append); \ + DO_FUNC(dbus_message_iter_next); \ + DO_FUNC(dbus_message_iter_open_container); \ + DO_FUNC(dbus_message_iter_recurse); \ + DO_FUNC(dbus_message_new_error); \ + DO_FUNC(dbus_message_new_error_printf); \ + DO_FUNC(dbus_message_new_method_return); \ + DO_FUNC(dbus_message_new_method_call); \ + DO_FUNC(dbus_message_ref); \ + DO_FUNC(dbus_message_unref); \ + DO_FUNC(dbus_pending_call_block); \ + DO_FUNC(dbus_pending_call_cancel); \ + DO_FUNC(dbus_pending_call_get_completed); \ + DO_FUNC(dbus_pending_call_set_notify); \ + DO_FUNC(dbus_pending_call_steal_reply); \ + DO_FUNC(dbus_pending_call_unref); \ + DO_FUNC(dbus_set_error_from_message); \ + DO_FUNC(dbus_threads_init_default); + +#define DO_FUNC( f ) extern typeof( f ) *p_##f +DBUS_FUNCS; +#undef DO_FUNC + +#endif /* SONAME_LIBDBUS_1 */ +#endif /* __WINE_WLANAPI_UNIXLIB_DBUS_H */ diff --git a/dlls/wlanapi/main.c b/dlls/wlanapi/main.c index c3712662232..6335088973c 100644 --- a/dlls/wlanapi/main.c +++ b/dlls/wlanapi/main.c @@ -28,12 +28,18 @@
#include <stdarg.h>
+#include <ntstatus.h> +#define WIN32_NO_STATUS + #include "windef.h" #include "winbase.h" #include "wine/debug.h" +#include "wine/unixlib.h"
#include "wlanapi.h"
+#include "unixlib.h" + WINE_DEFAULT_DEBUG_CHANNEL(wlanapi);
#define WLAN_MAGIC 0x574c414e /* WLAN */ @@ -41,6 +47,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(wlanapi); static struct wine_wlan { DWORD magic, cli_version; + UINT_PTR unix_handle; } handle_table[16];
static struct wine_wlan* handle_index(HANDLE handle) @@ -98,6 +105,8 @@ DWORD WINAPI WlanEnumInterfaces(HANDLE handle, void *reserved, WLAN_INTERFACE_IN DWORD WINAPI WlanCloseHandle(HANDLE handle, void *reserved) { struct wine_wlan *wlan; + struct wlan_close_handle_params params = {0}; + NTSTATUS status;
TRACE("(%p, %p)\n", handle, reserved);
@@ -108,6 +117,11 @@ DWORD WINAPI WlanCloseHandle(HANDLE handle, void *reserved) if (!wlan) return ERROR_INVALID_HANDLE;
+ params.handle = wlan->unix_handle; + status = UNIX_WLAN_CALL( wlan_close_handle, ¶ms ); + if (status != STATUS_SUCCESS && status != STATUS_NOT_SUPPORTED) + return RtlNtStatusToDosError( status ); + wlan->magic = 0; return ERROR_SUCCESS; } @@ -115,7 +129,9 @@ DWORD WINAPI WlanCloseHandle(HANDLE handle, void *reserved) DWORD WINAPI WlanOpenHandle(DWORD client_version, void *reserved, DWORD *negotiated_version, HANDLE *handle) { struct wine_wlan *wlan; + struct wlan_open_handle_params params = {0}; HANDLE ret_handle; + NTSTATUS status;
TRACE("(%lu, %p, %p, %p)\n", client_version, reserved, negotiated_version, handle);
@@ -129,6 +145,11 @@ DWORD WINAPI WlanOpenHandle(DWORD client_version, void *reserved, DWORD *negotia if (!ret_handle) return ERROR_REMOTE_SESSION_LIMIT_EXCEEDED;
+ status = UNIX_WLAN_CALL( wlan_open_handle, ¶ms ); + if (status != STATUS_SUCCESS && status != STATUS_NOT_SUPPORTED) + return RtlNtStatusToDosError( status ); + + wlan->unix_handle = params.handle; wlan->magic = WLAN_MAGIC; wlan->cli_version = *negotiated_version = client_version; *handle = ret_handle; @@ -225,3 +246,17 @@ void *WINAPI WlanAllocateMemory(DWORD size)
return ret; } + +BOOL WINAPI DllMain( HINSTANCE instance, DWORD reason, LPVOID reserved ) +{ + switch (reason) + { + case DLL_PROCESS_ATTACH: + DisableThreadLibraryCalls( instance ); + if (__wine_init_unix_call()) return FALSE; + UNIX_WLAN_CALL( wlan_init, NULL ); + break; + } + + return TRUE; +} diff --git a/dlls/wlanapi/unixlib.c b/dlls/wlanapi/unixlib.c new file mode 100644 index 00000000000..92311ffb856 --- /dev/null +++ b/dlls/wlanapi/unixlib.c @@ -0,0 +1,71 @@ +/* + * wlanapi unixlib implementation + * + * Copyright 2024 Vibhav Pant + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#if 0 +#pragma makedep unix +#endif + +#include "config.h" + +#include <ntstatus.h> +#define WIN32_NO_STATUS +#include <winternl.h> + +#include <wine/unixlib.h> + +#include "unixlib.h" +#include "unixlib_priv.h" + +static BOOL initialized; + +NTSTATUS wlan_init( void *params ) +{ + initialized = load_dbus_functions(); + return STATUS_SUCCESS; +} + +NTSTATUS wlan_open_handle( void *params ) +{ + struct wlan_open_handle_params *args = params; + NTSTATUS status; + if (!initialized) + return STATUS_NOT_SUPPORTED; + + status = init_dbus_connection( &args->handle ); + return status; +} + +NTSTATUS wlan_close_handle( void *params ) +{ + struct wlan_close_handle_params *args = params; + if (!initialized) + return STATUS_NOT_SUPPORTED; + + close_dbus_connection( (void *)args->handle ); + return STATUS_SUCCESS; +} + +const unixlib_entry_t __wine_unix_call_funcs[] = { + wlan_init, + wlan_open_handle, + wlan_close_handle +}; + +C_ASSERT( ARRAYSIZE( __wine_unix_call_funcs ) == unix_funcs_count ); diff --git a/dlls/wlanapi/unixlib.h b/dlls/wlanapi/unixlib.h new file mode 100644 index 00000000000..9bf2149e7c3 --- /dev/null +++ b/dlls/wlanapi/unixlib.h @@ -0,0 +1,48 @@ +/* + * Unix interface definitions + * + * Copyright 2024 Vibhav Pant + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef __WINE_WLANAPI_UNIXLIB_H +#define __WINE_WLANAPI_UNIXLIB_H + +#include <windef.h> + +struct wlan_open_handle_params +{ + UINT_PTR handle; +}; + +struct wlan_close_handle_params +{ + UINT_PTR handle; +}; + +enum wlanpi_funcs +{ + unix_wlan_init, + + unix_wlan_open_handle, + unix_wlan_close_handle, + + unix_funcs_count +}; + +#define UNIX_WLAN_CALL( func, params ) WINE_UNIX_CALL( unix_##func, (params) ) + +#endif /* __WINE_WLANAPI_UNIXLIB_H */ diff --git a/dlls/wlanapi/unixlib_priv.h b/dlls/wlanapi/unixlib_priv.h new file mode 100644 index 00000000000..fa813d07844 --- /dev/null +++ b/dlls/wlanapi/unixlib_priv.h @@ -0,0 +1,28 @@ +/* + * Unix private definitions + * + * Copyright 2024 Vibhav Pant + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef __WINE_WLANAPI_UNIXLIB_PRIV_H +#define __WINE_WLANAPI_UNIXLIB_PRIV_H + +extern BOOL load_dbus_functions( void ); +extern NTSTATUS init_dbus_connection( UINT_PTR *handle ); +extern void close_dbus_connection( void *c ); + +#endif /* __WINE_WLANAPI_UNIXLIB_PRIV_H */