diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f1527d4..645a4180 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,25 @@ project(netremote VERSION 0.0.1 ) +# Conditional inclusion of OS-dependent source trees. +if (CMAKE_SYSTEM_NAME STREQUAL "Linux") + set(BUILD_FOR_LINUX TRUE) +elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows") + set(BUILD_FOR_WINDOWS TRUE) +else () + MESSAGE(FATAL_ERROR "No supported target OS detected, SYSTEM_NAME=${CMAKE_SYSTEM_NAME}") +endif() + +MESSAGE(STATUS "Target OS ${CMAKE_SYSTEM_NAME} detected") + +# Option determining whether the hostapd client library should be built from +# source, or a pre-built, packaged version discovered on the system. +option( + BUILD_HOSTAP_EXTERNAL + "Build hostap project from built-in external source" + ON +) + # Set language configutation options. The C++ standard used must be the lowest # common denominator for all the OS-dependent projects. In practice, since this # project must build under the Windows build system (build.exe), its toolchain @@ -27,6 +46,7 @@ set_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED 1) include(CheckPIESupported) include(CTest) +include(ExternalProject) include(GNUInstallDirs) include(grpc) include(protoc) @@ -108,6 +128,44 @@ if (CMAKE_BUILD_TYPE MATCHES "(Release|RelWithDebInfo|MinSizeRel)") add_compile_definitions(_FORTIFY_SOURCE=2) endif() +# Common source directories +set(NETREMOTE_DIR_SRC ${CMAKE_CURRENT_LIST_DIR}/src) +set(NETREMOTE_DIR_LINUX ${CMAKE_CURRENT_LIST_DIR}/linux) +set(NETREMOTE_DIR_WINDOWS ${CMAKE_CURRENT_LIST_DIR}/windows) + +# Add common, global compile definitions. +add_compile_definitions( + MAGIC_ENUM_RANGE_MIN=0 + MAGIC_ENUM_RANGE_MAX=255 +) + +# Conditional inclusion of OS-dependent source trees. +if (BUILD_FOR_LINUX) + include(hostap) + add_subdirectory(linux) +elseif (BUILD_FOR_WINDOWS) + # Make public version of wil available. + set(WIL_BUILD_TESTS OFF CACHE INTERNAL "Turn off wil tests") + set(WIL_BUILD_PACKAGING OFF CACHE INTERNAL "Turn off wil packaging") + + find_package(wil CONFIG REQUIRED) + + # Add Windows-specific global compile definitions. + add_compile_definitions( + _UNICODE + UNICODE + NOMINMAX + WIN32_LEAN_AND_MEAN + ) + + # Allow more than default number of sections in object files. + add_compile_options( + /bigobj + ) + + add_subdirectory(windows) +endif() + add_subdirectory(protocol) add_subdirectory(src) add_subdirectory(tests) diff --git a/cmake/hostap.cmake b/cmake/hostap.cmake new file mode 100644 index 00000000..45e00f96 --- /dev/null +++ b/cmake/hostap.cmake @@ -0,0 +1,13 @@ + +if (BUILD_HOSTAP_EXTERNAL) + add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../external/hostap) +else() + find_library(LIBWPA_CLIENT + NAMES libwpa_client.so + REQUIRED) +endif() + +if(LIBWPA_CLIENT) + set(LIBWPA_CLIENT_TARGET ${LIBWPA_CLIENT}) + MESSAGE(STATUS "Found wpa client: ${LIBWPA_CLIENT}") +endif() diff --git a/development/docker/images/netremote/dev/hostapd/Dockerfile b/development/docker/images/netremote/dev/hostapd/Dockerfile index 223685af..8ae59e74 100644 --- a/development/docker/images/netremote/dev/hostapd/Dockerfile +++ b/development/docker/images/netremote/dev/hostapd/Dockerfile @@ -6,10 +6,11 @@ FROM abeltrano/netremote-dev RUN sudo apt-get update && \ sudo apt-get install -y -qq --no-install-recommends \ # hostapd build dependencies. - # libnl-3-dev libssl-dev libnl-genl-3-dev + # libnl-3-dev libssl-dev libwpa-client-dev libnl-genl-3-dev libnl-3-dev \ - libssl-dev \ libnl-genl-3-dev \ + libssl-dev \ + libwpa-client-dev \ # wpa_supplicant build dependencies. # libnl-3-dev libssl-dev libnl-genl-3-dev libdbus-c++-dev libnl-route-3-dev libdbus-c++-dev \ diff --git a/external/hostap/.config b/external/hostap/.config new file mode 100644 index 00000000..e57b0b2b --- /dev/null +++ b/external/hostap/.config @@ -0,0 +1,2 @@ +CONFIG_CTRL_IFACE=y +CONFIG_BUILD_WPA_CLIENT_SO=y \ No newline at end of file diff --git a/external/hostap/CMakeLists.txt b/external/hostap/CMakeLists.txt new file mode 100644 index 00000000..548b7d10 --- /dev/null +++ b/external/hostap/CMakeLists.txt @@ -0,0 +1,28 @@ + +find_program(MAKE_EXE + NAMES gmake nmake make + REQUIRED +) + +set(HOSTAP_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}) + +set(HOSTAP_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/hostap-prefix/src/hostap/wpa_supplicant CACHE INTERNAL "Path of external project code") +set(HOSTAP_LOCAL_INCLUDE_DIR ${HOSTAP_INSTALL_DIR}/usr/local/include CACHE INTERNAL "Path of external project includes") +set(HOSTAP_LOCAL_LIB_DIR ${HOSTAP_INSTALL_DIR}/usr/local/lib CACHE INTERNAL "Path of external project built libraries") +set(HOSTAP_LOCAL_SBIN_DIR ${HOSTAP_INSTALL_DIR}/usr/local/sbin CACHE INTERNAL "Path of external project built system binaries") + +ExternalProject_Add(hostap + GIT_REPOSITORY "http://w1.fi/hostap.git" + GIT_TAG "hostap_2_10" + CONFIGURE_COMMAND cp -n ${CMAKE_CURRENT_SOURCE_DIR}/.config ${HOSTAP_PREFIX}/.config + BINARY_DIR ${HOSTAP_PREFIX} + BUILD_COMMAND QUIET=1 ${MAKE_EXE} libwpa_client.so + INSTALL_DIR ${HOSTAP_INSTALL_DIR} + INSTALL_COMMAND QUIET=1 DESTDIR=${HOSTAP_INSTALL_DIR} ${MAKE_EXE} install +) + +set(LIBWPA_CLIENT + ${HOSTAP_LOCAL_LIB_DIR}/libwpa_client.so + CACHE FILEPATH + "wpa client shared object" +) diff --git a/linux/CMakeLists.txt b/linux/CMakeLists.txt new file mode 100644 index 00000000..e31076a5 --- /dev/null +++ b/linux/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(hostap-controller) \ No newline at end of file diff --git a/linux/README.md b/linux/README.md index f1bc6061..7931e97e 100644 --- a/linux/README.md +++ b/linux/README.md @@ -64,7 +64,7 @@ sudo apt-get install -y build-essential git ninja-build clang clang-format clang The above will install all the tools required to compile, lint, and debug the project. If hostapd will also be compiled ([git://w1.fi/hostap.git](git://w1.fi/hostap.git)), install the following additional development dependencies: ```bash -sudo apt-get install -y libnl-3-dev libssl-dev libnl-genl-3-dev +sudo apt-get install -y libnl-3-dev libssl-dev libwpa-client-dev libnl-genl-3-dev ``` ### 3. Install Docker on Windows diff --git a/linux/hostap-controller/CMakeLists.txt b/linux/hostap-controller/CMakeLists.txt new file mode 100644 index 00000000..9d42406b --- /dev/null +++ b/linux/hostap-controller/CMakeLists.txt @@ -0,0 +1,22 @@ + +add_library(hostap-controller SHARED "") + +if (BUILD_HOSTAP_EXTERNAL) + add_dependencies(hostap-controller hostap) + + target_include_directories(hostap-controller + PRIVATE + ${HOSTAP_LOCAL_INCLUDE_DIR} + ) +endif() + +target_sources(hostap-controller + PRIVATE + Placeholder.cxx +) + + +target_link_libraries(hostap-controller + INTERFACE + ${LIBWPA_CLIENT_TARGET} +) diff --git a/linux/hostap-controller/Placeholder.cxx b/linux/hostap-controller/Placeholder.cxx new file mode 100644 index 00000000..4631bc9e --- /dev/null +++ b/linux/hostap-controller/Placeholder.cxx @@ -0,0 +1,4 @@ + +#include + +#include diff --git a/vcpkg.json b/vcpkg.json index 450355b5..ea38c0ce 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -8,6 +8,10 @@ }, "protobuf", "catch2", - "magic-enum" + "magic-enum", + { + "name": "wil", + "platform": "windows" + } ] } \ No newline at end of file diff --git a/windows/CMakeLists.txt b/windows/CMakeLists.txt new file mode 100644 index 00000000..e69de29b