Skip to content
Open
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
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
*.o
*.so
*.so.*
/iwinfo
obj-*
debian/.debhelper/
debian/debhelper-build-stamp
debian/*.debhelper.log
debian/*.substvars
debian/files
debian/iwinfo/
debian/libiwinfo-dev/
debian/libiwinfo-plugin-lua5.1/
debian/libiwinfo0/
debian/changelog
debian/tmp/
142 changes: 142 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
cmake_minimum_required(VERSION 3.13)
project(iwinfo LANGUAGES C VERSION 0)
add_compile_definitions(_GNU_SOURCE)
include(GNUInstallDirs)

option(IWINFO_BUILD_LUA "Build Lua 5.1 module" ON)
set(IWINFO_BACKENDS "nl80211;wext" CACHE STRING "Space/semicolon separated list of backends to enable (nl80211;wext;wl;madwifi)")

set(CMAKE_C_STANDARD 99)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_compile_options(-Wall -Wextra -Wformat -Werror=format-security -fno-omit-frame-pointer)

FIND_LIBRARY(ubox_library NAMES ubox)
FIND_LIBRARY(ubus_library NAMES ubus)
FIND_LIBRARY(uci_library NAMES uci)

FIND_PATH(ubox_include_dir libubox/usock.h)
INCLUDE_DIRECTORIES(${ubox_include_dir})

FIND_PATH(ubus_include_dir libubus.h)
INCLUDE_DIRECTORIES(${ubus_include_dir})

FIND_PATH(uci_include_dir uci.h)
INCLUDE_DIRECTORIES(${uci_include_dir})

find_package(PkgConfig REQUIRED)
set(NL_LIBS "")
set(NL_CFLAGS "")
if (PKG_CONFIG_FOUND)
pkg_check_modules(NLTINY QUIET libnl-tiny)
if (NLTINY_FOUND)
set(NL_LIBS "${NLTINY_LINK_LIBRARIES}")
set(NL_CFLAGS "${NLTINY_CFLAGS}")
add_definitions(-DUSE_NL_TINY)
else()
pkg_check_modules(NL3 REQUIRED libnl-3.0 libnl-genl-3.0)
set(NL_LIBS "${NL3_LINK_LIBRARIES}")
set(NL_CFLAGS "${NL3_CFLAGS}")
add_definitions(-DUSE_LIBNL3)
endif()
endif()

# Lua 5.1 (for module)
if (IWINFO_BUILD_LUA)
pkg_check_modules(LUA51 REQUIRED lua5.1)
endif()

include_directories(
${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/include
${ubox_include_dir}
${ubus_include_dir}
${uci_include_dir}
)
if (NL_CFLAGS)
separate_arguments(_NL_CFLAGS NATIVE_COMMAND "${NL_CFLAGS}")
add_compile_options(${_NL_CFLAGS})
endif()
if (IWINFO_BUILD_LUA)
include_directories(${LUA51_INCLUDE_DIRS})
endif()

set(IWINFO_SRC
iwinfo_utils.c
iwinfo_lib.c
)

function(add_backend name def)
list(FIND IWINFO_BACKENDS "${name}" _idx)
if (_idx EQUAL -1)
return()
endif()

add_definitions(-D${def})
set(IWINFO_SRC ${IWINFO_SRC} ${ARGN} PARENT_SCOPE)
endfunction()

add_backend("nl80211" "USE_NL80211" iwinfo_nl80211.c)
add_backend("wext" "USE_WEXT" iwinfo_wext.c iwinfo_wext_scan.c)
add_backend("wl" "USE_WL" iwinfo_wl.c)
add_backend("madwifi" "USE_MADWIFI" iwinfo_madwifi.c)

if (IWINFO_BUILD_LUA AND EXISTS "${CMAKE_SOURCE_DIR}/iwinfo_lua.c")
set(IWINFO_LUA_SRC iwinfo_lua.c)
endif()

add_library(iwinfo SHARED ${IWINFO_SRC})
target_link_libraries(iwinfo
${ubox_library}
${ubus_library}
${uci_library}
${NL_LIBS}
)

set_target_properties(iwinfo PROPERTIES
SOVERSION 0
VERSION 0.0.0
OUTPUT_NAME "iwinfo"
)

add_executable(iwinfo_cli iwinfo_cli.c)

if (TARGET iwinfo_cli)
target_link_libraries(iwinfo_cli iwinfo ${NL_LIBS} ${ubox_library} ${ubus_library} ${uci_library})
set_target_properties(iwinfo_cli PROPERTIES OUTPUT_NAME "iwinfo")
install(TARGETS iwinfo_cli RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR})
endif()

if (IWINFO_BUILD_LUA AND IWINFO_LUA_SRC)
add_library(iwinfo_lua MODULE ${IWINFO_LUA_SRC})
target_link_libraries(iwinfo_lua iwinfo ${LUA51_LINK_LIBRARIES})
set_target_properties(iwinfo_lua PROPERTIES
PREFIX ""
OUTPUT_NAME "iwinfo"
)
install(TARGETS iwinfo_lua LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/lua/5.1)
endif()

install(TARGETS iwinfo LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})

install(FILES include/iwinfo.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(DIRECTORY include/iwinfo/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/iwinfo FILES_MATCHING PATTERN "*.h")

message(STATUS "Backends enabled: ${IWINFO_BACKENDS}")
if (NLTINY_FOUND)
message(STATUS "Using libnl-tiny")
else()
message(STATUS "Using libnl-3/libnl-genl-3")
endif()
if (IWINFO_BUILD_LUA AND IWINFO_LUA_SRC)
message(STATUS "Building Lua 5.1 module")
else()
message(STATUS "Lua module disabled or source not found")
endif()

ADD_CUSTOM_TARGET(debian
COMMAND ${CMAKE_COMMAND} -E echo "Generating debian/changelog from git..."
COMMAND ${CMAKE_SOURCE_DIR}/debian/generate-changelog.sh
COMMAND dpkg-buildpackage -b -uc -us
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMENT "Building Debian package"
)
49 changes: 49 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Source: iwinfo
Section: libs
Priority: optional
Maintainer: Russ Dill <russ.dill@gmail.com>
Build-Depends: debhelper-compat (= 13),
pkg-config,
make,
gcc,
libnl-3-dev,
libnl-genl-3-dev,
libuci-dev,
libubus-dev,
libubox-dev,
lua5.1,
liblua5.1-dev
Standards-Version: 4.7.0
Homepage: https://github.com/openwrt/iwinfo
Rules-Requires-Root: no

Package: libiwinfo0
Section: libs
Architecture: any
Multi-Arch: same
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: Wireless information library (runtime)
iwinfo exposes wireless driver info via a common API.

Package: libiwinfo-dev
Section: libdevel
Architecture: any
Multi-Arch: same
Depends: libiwinfo0 (= ${binary:Version}), ${misc:Depends}
Description: Wireless information library (development files)
Headers and linker symlink for libiwinfo.

Package: iwinfo
Section: net
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, libiwinfo0 (= ${binary:Version}), libuci0
Description: Wireless information tool (CLI)
Command-line frontend for the iwinfo library.

Package: libiwinfo-plugin-lua5.1
Section: libs
Architecture: any
Multi-Arch: same
Depends: ${shlibs:Depends}, ${misc:Depends}, libiwinfo0 (= ${binary:Version}), lua5.1, liblua5.1
Description: Lua 5.1 module for iwinfo
Lua bindings for the iwinfo library.
15 changes: 15 additions & 0 deletions debian/generate-changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

cd "$(dirname "$0")/.."

COMMIT_DATE=$(git log -1 --format='%cd' --date=format:'%Y%m%d' 2>/dev/null || echo '00000000')
COMMIT_HASH=$(git log -1 --format='%h' 2>/dev/null || echo 'unknown')
COMMIT_TIMESTAMP=$(git log -1 --format='%cd' --date=rfc2822 2>/dev/null || date -R)

cat > debian/changelog <<EOF
iwinfo (0.0.${COMMIT_DATE}) unstable; urgency=medium

* Latest version (${COMMIT_HASH})

-- Russ Dill <russ.dill@gmail.com> ${COMMIT_TIMESTAMP}
EOF
1 change: 1 addition & 0 deletions debian/iwinfo.install
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
usr/sbin/iwinfo
3 changes: 3 additions & 0 deletions debian/libiwinfo-dev.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
usr/include/iwinfo.h
usr/include/iwinfo/*
usr/lib/*/libiwinfo.so
1 change: 1 addition & 0 deletions debian/libiwinfo-plugin-lua5.1.install
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
usr/lib/*/lua/5.1/iwinfo.so
1 change: 1 addition & 0 deletions debian/libiwinfo0.install
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
usr/lib/*/libiwinfo.so.0*
19 changes: 19 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

IWINFO_BACKENDS ?= nl80211;wext
IWINFO_BUILD_LUA ?= ON

%:
dh $@ --buildsystem=cmake

override_dh_auto_configure:
dh_auto_configure -- \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_INSTALL_PREFIX=/usr \
-DIWINFO_BUILD_LUA=$(IWINFO_BUILD_LUA) \
-DIWINFO_BACKENDS="$(IWINFO_BACKENDS)"

override_dh_auto_install:
dh_auto_install --destdir=$(CURDIR)/debian/tmp
1 change: 1 addition & 0 deletions debian/source/format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0 (native)
2 changes: 2 additions & 0 deletions debian/watch
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version=4
# When using git snapshots, you can wire this to git.openwrt.org tags once available.
2 changes: 1 addition & 1 deletion include/iwinfo/lua.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* with the iwinfo library. If not, see http://www.gnu.org/licenses/.
*/

#ifndef __IWINFO_LUALUB_H_
#ifndef __IWINFO_LUALIB_H_
#define __IWINFO_LUALIB_H_

#include <lua.h>
Expand Down