• Stars
    star
    151
  • Rank 246,057 (Top 5 %)
  • Language
    C
  • License
    Mozilla Public Li...
  • Created about 8 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

nl80211 C/C++ library for monitoring signal strength of WiFi networks

wifi-scan

This is a small C/C++ library for monitoring signal strength of WiFi networks. It can collect data from:

  • associated station only (rapidly)
  • all networks around (slow passive scan)

Platforms

Any platforms supporting nl80211 netlink interface (new 802.11 interface). Generally *nix platforms.

Hardware

Wireless devices that have cfg80211/mac80211 driver (typically everything in use nowadays).

From wireless.wiki.kernel.org:

All new Linux wireless drivers should be written targeting either cfg80211 for fullmac devices or mac80211 for softmac devices.

State

The return values of public library functions are subject to change (mainly error codes). Currently if anything goes wrong library dies cleanly with error message on stderr explaining what happened. Note that if library dies - it also kills your program and you have no chance to recover.

Dependencies

The library depends on libmnl for netlink nl80211 user space - kernel space communication.

Building Instructions

# update package repositories
sudo apt-get update 
# get compilers and make
sudo apt-get install build-essential
# get dependencies
sudo apt-get install libmnl0 libmnl-dev
# get git
sudo apt-get install git
# clone the repository
git clone https://github.com/bmegli/wifi-scan.git

# finally build the library and examples
cd wifi-scan
make all

Testing

Check your wireless interface name with ifconfig:

ifconfig

Run wifi-scan-station with your interface, e.g. wlan0

./wifi-scan-station wlan0

Run wifi-scan-all with your interface, e.g. wlan0.

Triggering a scan needs permission so:

sudo ./wifi-scan-all wlan0

Using

See examples directory for more complete and commented examples with error handling.

Normally you would call wifi_scan_station or wifi_scan_all in a loop.

wifi-scan-station

	struct station_info station;
	struct wifi_scan *wifi = wifi_scan_init("wlan0");
	
	if (wifi_scan_station(wifi, &station) > 0 )
		printf("%s signal %d dBm avg %d dBm rx %u tx %u\n",
		station.signal_dbm, station.signal_avg_dbm,
		station.rx_packets, station.tx_packets);
	
	wifi_scan_close(wifi);

wifi-scan-all

	int status, i;
	struct bss_info bss[10]; 
	struct wifi_scan *wifi = wifi_scan_init("wlan0");

	status=wifi_scan_all(wifi, bss, 10);
		
	for(i=0;i<status && i<10;++i)	
		printf("%s signal %d dBm on %u MHz seen %d ms ago status %s\n",
		bss[i].signal_mbm/100, bss[i].frequency, bss[i].seen_ms_ago,
		(bss[i].status==BSS_ASSOCIATED ? "associated" : ""));

	wifi_scan_close(wifi);

Compiling your code

Don't forget to link with lmnl

C

gcc wifi_scan.c your_program.c -lmnl -o your-program

C++

gcc -c wifi_scan.c
g++ -c your_program.cpp
g++ wifi_scan.o your_program.o -lmnl -o your-program

Understanding nl80211 Netlink

Here are some of the resources that helped writing this library:

And finally the implementation wifi-scan.c has some comments that may be usefull to you.

License

Library is licensed under Mozilla Public License, v. 2.0

This is similiar to LGPL but more permissive:

  • you can use it as LGPL in prioprietrary software
  • unlike LGPL you may compile it statically with your code

Like in LGPL, if you modify this library, you have to make your changes available. Making a github fork of the library with your changes satisfies those requirements perfectly.

Additional information

Building with CMake

Alternatively build examples and shared library with Cmake

sudo apt-get install cmake
cd wifi-scan
mkdir build
cd build
cmake ..
make

Used In

Some notable uses found with google search:

More Repositories

1

unity-network-hardware-video-decoder

Video and point cloud streaming over custom UDP protocol with hardware decoding (Unity example)
C#
51
star
2

hardware-video-streaming

Hardware Video Streaming meta repository
24
star
3

hybrid-a-star

C++ hybrid-a-star extracted from ROS2 nav2 stack
C++
23
star
4

realsense-network-hardware-video-encoder

Realsense hardware encoded color/ir H.264 and color/ir/depth HEVC streaming
C++
23
star
5

ev3dev-mapping

The ev3dev-mapping project meta repository
16
star
6

hardware-video-encoder

HVE - Hardware Video Encoder C library
C
16
star
7

hardware-video-decoder

HVD - Hardware Video Decoder C library
C
13
star
8

minimal-latency-streaming-protocol

MLSP - Minimal Latency Streaming Protocol library
C
10
star
9

network-hardware-video-encoder

NHVE Network Hardware Video Encoder C library
C
10
star
10

xv11lidar

C Library for XV11 LIDAR
C
9
star
11

ev3dev-mapping-ui

A cross-platform real-time 3D spatial data visualization
C#
9
star
12

realsense-depth-to-vaapi-hevc10

Hardware encode Realsense D400 depth stream to HEVC Main10
C++
8
star
13

unhvd-native

Unity Network Hardware Video Decoder Native library
C
8
star
14

rplidar-a3-arduino

Arduino/Teensy library for non-blocking communication with RPLidar A3
C++
6
star
15

roboclaw

C library for ION MC Roboclaw
C
6
star
16

xv11lidar-test

Test for XV11 lidar (character/raw binary synchronized output)
C
6
star
17

realsense-ir-to-vaapi-h264

Hardware encode Realsense D400 infrared stream to H.264
C++
5
star
18

network-hardware-video-decoder

NHVD Network Hardware Video Decoder C library
C
4
star
19

ev3dev-mapping-modules

A bunch of small programs feeding data to ev3dev-mapping-ui
C++
4
star
20

xv11lidar-arduino

Arduino/Teensy library for non-blocking communication with XV11 lidar
C++
3
star
21

vmu931

C library for Variense VMU931 IMU
C
3
star
22

footprint-collision-checker

C++ footprint collision checker extracted from ROS2 navigation2 stack
C++
2
star
23

trx

A fork of http://www.pogo.org.uk/~mark/trx.git
C
2
star
24

ev3dev-mapping-ui-udp

Recorded UDP communication between robot (ev3dev-mapping-modules) and ui (ev3dev-mapping-ui)
2
star
25

cave-crawler

The cave-crawler project meta repository
2
star
26

serial-nb-arduino

Arduino/Teensy library for non-blocking serial (UART/USB) communication
C++
1
star
27

ev3dev-mapping-abandoned

The completely abandoned unsupported and unlicensed test code
C++
1
star