• Stars
    star
    5
  • Rank 2,771,586 (Top 57 %)
  • Language
    C
  • License
    Apache License 2.0
  • Created almost 10 years ago
  • Updated almost 8 years ago

Reviews

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

Repository Details

See Nerves.WpaSupplicant now

This package enables Elixir applications to interact with the local WPA supplicant. The WPA supplicant handles various Wi-Fi operations like scanning for wireless networks, connecting, authenticating, and collecting wireless adapter statistics.

Note on permissions

The wpa_supplicant daemon runs as root and requires processes that attach to its control interface to be root. This project contains a C port process whose sole purpose is to interact with the wpa_supplicant daemon, but it needs sufficient permission to do so. The Makefile contains logic to mark the port process setuid root so that this works, but you may want to change this depending on your setup.

Building

Building wpa_supplicant.ex is similar to other Elixir projects. The Makefile will invoke mix to compile both the Elixir and C source code. The only extra step is to ensure that the permissions are right on the wpa_ex binary. The way this is accomplished is by setting wpa_ex setuid root. By default, when you run make, you'll be asked your password to change permissions.

$ make

If you want to disable the setuid root step in the Makefile, just set the SUDO environment variable to true to make it a nop:

$ SUDO=true make

If you need to use a different askpass program, you can set that as well:

$ SUDO_ASKPASS=/usr/bin/ssh-askpass make

Running

The wpa_supplicant daemon must be running already on your system and the control interface must be exposed. If you have any doubt, try running wpa_cli. If that doesn't work, the Elixir WpaSupplicant won't work.

If you're on a system where you can start the wpa_supplicant manually, here's an example command line:

$ /sbin/wpa_supplicant -iwlan0 -C/var/run/wpa_supplicant -B

Once you're happy that the wpa_supplicant is running, start iex by running:

$ iex -S mix

Start a WpaSupplicant process:

iex> {:ok, pid} = WpaSupplicant.start_link("/var/run/wpa_supplicant/wlan0")
{:ok, #PID<0.82.0>}

You can sanity check that Elixir has properly attached to the wpa_supplicant daemon by pinging the daemon:

iex> WpaSupplicant.request(pid, :PING)
:PONG

To scan for access points, call WpaSupplicant.scan/1. This can take a few seconds:

iex> WpaSupplicant.scan(pid)
[%{age: 42, beacon_int: 100, bssid: "00:1f:90:db:45:54", capabilities: 1073,
   flags: "[WEP][ESS]", freq: 2462, id: 8,
   ie: "00053153555434010882848b0c1296182403010b07",
   level: -83, noise: 0, qual: 0, ssid: "1SUT4", tsf: 580579066269},
 %{age: 109, beacon_int: 100, bssid: "00:18:39:7a:23:e8", capabilities: 1041,
   flags: "[WEP][ESS]", freq: 2412, id: 5,
   ie: "00076c696e6b737973010882848b962430486c0301",
   level: -86, noise: 0, qual: 0, ssid: "linksys", tsf: 464957892243},
 %{age: 42, beacon_int: 100, bssid: "1c:7e:e5:32:d1:f8", capabilities: 1041,
   flags: "[WPA2-PSK-CCMP][ESS]", freq: 2412, id: 0,
   ie: "000768756e6c657468010882848b960c1218240301",
   level: -43, noise: 0, qual: 0, ssid: "dlink", tsf: 580587711245}]

To attach to an access point, you need to configure a network entry in the wpa_supplicant. The wpa_supplicant can have multiple network entries configured. The following removes all network entries so that only one is configured.

iex> WpaSupplicant.set_network(pid, ssid: "MyNetworkSsid", key_mgmt: :WPA_PSK, psk: "secret")
:ok

If the access point is around, the wpa_supplicant will eventually connect to the network.

iex> WpaSupplicant.status(pid)
%{address: "84:3a:4b:11:95:23", bssid: "1c:7e:e5:32:de:32",
  group_cipher: "TKIP", id: 0, key_mgmt: "WPA2-PSK", mode: "station",
  pairwise_cipher: "CCMP", ssid: "MyNetworkSsid", wpa_state: "COMPLETED"}

Polling the wpa_supplicant for status isn't that great, so it's possible to register a GenEvent with WpaSupplicant. If you don't supply one in the call to start_link, one is automatically created and available via WpaSupplicant.event_manager/1. The following example shows how to view events at the prompt:

iex> defmodule Forwarder do
...>  use GenEvent
...>  def handle_event(event, parent) do
...>    send parent, event
...>    {:ok, parent}
...>  end
...> end
iex> WpaSupplicant.event_manager(pid) |> GenEvent.add_handler(Forwarder, self())
iex> flush
{:wpa_supplicant, #PID<0.85.0>, :"CTRL-EVENT-SCAN-STARTED"}
{:wpa_supplicant, #PID<0.85.0>, :"CTRL-EVENT-SCAN-RESULTS"}

Low level messaging

It is expected that the helper functions for interacting with the wpa_supplicant will not cover every situation. The WpaSupplicant.request/2 function allows you to send arbitrary commands. Requests are atoms that are named the same as described in the wpa_supplicant documentation (see Useful links). If a request takes a parameter, pass it as a tuple where the first element is the command. Parameters may be strings or numbers and will be properly formatted for the control interface. The response is also parsed and turned into atoms, numbers, strings, lists, or maps depending on the command. The string parsing is taken care of by this library. Here are some examples:

iex> WpaSupplicant.request(pid, :INTERFACES)
["wlan0"]

iex> WpaSupplicant.request(pid, {:GET_NETWORK, 0, :key_mgmt})
"WPA-PSK"

Useful links

  1. wpa_supplicant homepage
  2. wpa_supplicant control interface
  3. wpa_supplicant information on the archlinux wiki

Licensing

The majority of this package is licensed under the Apache 2.0 license. The code that directly interfaces with the wpa_supplicant is copied from the wpa_supplicant package and has the following copyright and license:

/*
 * wpa_supplicant/hostapd control interface library
 * Copyright (c) 2004-2007, Jouni Malinen <[email protected]>
 *
 * This software may be distributed under the terms of the BSD license.
 * See README for more details.
 */

More Repositories

1

elixir_ale

Interact with hardware in Elixir - GPIOs, I2C and SPI
C
339
star
2

muontrap

Keep your ports contained
Elixir
147
star
3

code128

Trivial Code 128 barcode encoder
C
51
star
4

elixirbot

Elixir robots created for Erlang Factory 2015
Eagle
35
star
5

bbb-buildroot-fwup

Example project showing how to use buildroot and fwup
Makefile
26
star
6

midi_synth

Play music in Elixir
Elixir
26
star
7

relsync

Synchronize Erlang/OTP releases to remote nodes
Erlang
26
star
8

snake

Snake in Elixir
Elixir
23
star
9

nerves_system_npi_imx6ull

Nerves system for the Seeed Studio i.MX6ULL-eMMC dev board
Elixir
14
star
10

mmccopy

Convenient alternative to dd for writing images to SDCards
C
14
star
11

embedded-elixir

News and Articles on Elixir in Embedded Systems
HTML
10
star
12

qt-rectangles

Test program for OpenGL ES performance on RPi
C++
10
star
13

qt-opencl

Fixes for http://qt.gitorious.org/qt-labs/opencl
C++
8
star
14

raspijpgs

Simple command-line driven MotionJPEG streamer for the Raspberry Pi
C
8
star
15

see-experiments

Erlang
8
star
16

one_dhcpd

The Elixir DHCP Server that only serves one very important client
Elixir
8
star
17

hollowcore-h264

The Android OpenCORE multimedia framework stripped down to just the H.264 decoder to make it easier to integrate.
C++
7
star
18

vultr_example

Experiment in using Nerves to deploy to the clouds
JavaScript
7
star
19

fhunleth-buildroot-experiments

A Buildroot repository for various experiments
Shell
6
star
20

u-boot-squashfs

Experimental support for SquashFS in U-Boot
C
6
star
21

buildroot-edison

Working on Intel Edison support in Buildroot...
Makefile
6
star
22

buildroot-bbb

Read README below
C
5
star
23

nerves-see

Joe Armstrong's SEE code in the Nerves embedded environment
Erlang
5
star
24

rpi_video

Try to playback video on the RPi on Nerves
C
5
star
25

gpio_twiddler

GPIO twiddling benchmark
Elixir
5
star
26

android_external_i2c_tools

i2c_tools for Android
Perl
4
star
27

beam_benchmarks

Collection of benchmarks to run on devices running the BEAM
Erlang
4
star
28

mdns_query

C
4
star
29

circuits_led

Experiments
Elixir
4
star
30

nbtty

Simplification of dtach to prevent things from blocking a tty
C
4
star
31

nerves_ev3_example

Example application for getting started with the Lego EV3 and Nerves
Elixir
4
star
32

dumpdm365

Utility for dumping and modifying registers on TI Davinci DM36x processors
C
4
star
33

ffmpeg

Experimental ffmpeg modifications
C
3
star
34

kiosk_system_rpi4

Nerves QtWebEngine Kiosk system for Raspberry Pi 4
Elixir
3
star
35

binary_clock

Build a Binary Clock with Elixir and Nerves
3
star
36

export_server

A port of Garrett Smith's port_server example to Elixir
Elixir
3
star
37

nerves_presenter

C++
3
star
38

nerves_system_up_board

Elixir
3
star
39

realtime_tests

Real-time experiments in Elixir
Elixir
3
star
40

osd32mp157c-brk-buildroot

Buildroot fork to support the OSD32MP157C-BRK board
Makefile
3
star
41

nv12topnm

Simple utility for converting NV12 memory dumps to PNM images
C
3
star
42

keytar

Rockband 3 Keytar USB driver and key generator
C
3
star
43

nerves_system_jslinux

Elixir
3
star
44

eef-embedded-systems-wg

Temporary location for the EEF Embedded Systems WG repo
2
star
45

am3358_memtester

Bare metal port of memtester to AM335x-based boards
C
2
star
46

fwup-snap

Metadata for building snap packages for fwup
2
star
47

canbcm

Old Erlang project to interface with the Linux SocketCAN BCM driver (not maintained)
C
2
star
48

fbgrab

Random fbgrab updates
C
2
star
49

logging_demo

RingLogger demo code for the Baltimore Elixir meetup
Elixir
2
star
50

intel_hex

Decode Intel hex records in Elixir
Elixir
2
star
51

nerves_system_rpi3_kiosk

See https://github.com/LeToteTeam/kiosk_system_rpi3 now
HTML
2
star
52

elixir-ply

ply for Elixir (VERY EXPERIMENTAL)
Elixir
2
star
53

l2elog

Linux syslog/klog bridge to Erlang's Lager logger
Erlang
2
star
54

iodata_nif

IOData NIF experiments
Elixir
2
star
55

dtach

Patches to http://dtach.sourceforge.net/ (These have been merged!)
C
1
star
56

nerves_key

1
star
57

nerves_system_alix

Base Nerves system configuration for the PC Engines ALIX - WARNING: Unmaintained
Elixir
1
star
58

dotfiles

Yay
Shell
1
star
59

net_managers.ex

Use Nerves.InterimWifi for wifi support
Elixir
1
star
60

elixirport

Elixir/Port process test app
C
1
star
61

erlangdc_demo

Nerves demo app for ErlangDC 2013
Erlang
1
star
62

nerves_system_galileo

Base Nerves system configuration for the Intel Galileo Gen 2 - WARNING: Unmaintained
Elixir
1
star
63

tls_experiment

Elixir
1
star
64

erlang_fileutils

Erlang versions of Unix file utilities to enable distributed use
Erlang
1
star
65

sdburner

UI for CoderDojoDC Raspberry Pi SDCard burner device
C++
1
star
66

dumb_ldattach

ldattach, but dumber
C
1
star
67

jsnerves

Emscripten, TinyEMU, Nerves experiment
JavaScript
1
star
68

silhouette

Experiments in making shadows
C++
1
star
69

test_build_embedded

Elixir
1
star
70

troodon-cam

Work in progress AM335x PRU -> camera interface with Erlang
C
1
star
71

psk_maker

A to-be-named library that supports the passphrase->psk algorithm and maybe more
Elixir
1
star
72

buildroot-pc-dhcpserver

DHCP/DNS server for managing a LAN island - ISO image
C
1
star
73

android_external_lsof

lsof for Android
C
1
star
74

buildroot-olinuxino

Buildroot repo for Olimex OLinuxino support
C
1
star
75

dm36x-packager

Python
1
star
76

presi-aoke

Presentation Karaoke Player
C++
1
star
77

troodonsw-website

Troodon Software website source code
CSS
1
star
78

laser-cutter-svgs

SVG files and utilities for various laser cutter designs
1
star
79

v4l2reg

Utility for getting and setting registers on V4L2 cameras
C
1
star
80

nerves_system_bbb_kiosk

Beaglebone Black configuration that drives a display
Shell
1
star
81

nerves_system_ag150

Base Nerves system configuration for the Logic Supply AG150 - WARNING: Unmaintained
Elixir
1
star
82

htc-kernel-incrediblec

2.6.32.15 kernel source for HTC incredible (use CyanogenMod version of kernel once it gets updated)
C
1
star
83

net_basic.ex

This has been moved to Nerves.NetworkInterface
C
1
star
84

nerves_system_orange_pi_zero_3

Nerves system for the OrangePi Zero 3
Elixir
1
star