Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate hostap into project #7

Merged
merged 7 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,6 +46,7 @@ set_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED 1)

include(CheckPIESupported)
include(CTest)
include(ExternalProject)
include(GNUInstallDirs)
include(grpc)
include(protoc)
Expand Down Expand Up @@ -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)
13 changes: 13 additions & 0 deletions cmake/hostap.cmake
Original file line number Diff line number Diff line change
@@ -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()
5 changes: 3 additions & 2 deletions development/docker/images/netremote/dev/hostapd/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
2 changes: 2 additions & 0 deletions external/hostap/.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_CTRL_IFACE=y
CONFIG_BUILD_WPA_CLIENT_SO=y
28 changes: 28 additions & 0 deletions external/hostap/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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"
)
1 change: 1 addition & 0 deletions linux/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(hostap-controller)
2 changes: 1 addition & 1 deletion linux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions linux/hostap-controller/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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}
)
4 changes: 4 additions & 0 deletions linux/hostap-controller/Placeholder.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

#include <cstddef>

#include <wpa_ctrl.h>
6 changes: 5 additions & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
},
"protobuf",
"catch2",
"magic-enum"
"magic-enum",
{
"name": "wil",
"platform": "windows"
}
]
}
Empty file added windows/CMakeLists.txt
Empty file.