1.1.2 • Published 6 years ago

wpa-ctrl v1.1.2

Weekly downloads
5
License
ISC
Repository
github
Last release
6 years ago

WpaCtrl

WpaCtrl to control wpa_supplicant

npm install wpa-ctrl --save

This only works on linux, tested on Debian stretch. You need to have wpa_supplicant installed and run as a user in the netdev group.

For more examples, see the test directory for p2p and wifi connection samples. This is a very basic library, it is nessary to write another wrapper over this.

Kind: global class
Emits: WpaCtrl#event:raw_msg, WpaCtrl#event:response, WpaCtrl#event:CTRL-REQ, WpaCtrl#event:P2P-DEVICE-FOUND, WpaCtrl#event:P2P-DEVICE-LOST, WpaCtrl#event:P2P-GROUP-STARTED, WpaCtrl#event:P2P-INVITATION-RECEIVED, WpaCtrl#event:CTRL-EVENT-CONNECTED, WpaCtrl#event:CTRL-EVENT-DISCONNECTED
See: http://w1.fi/wpa_supplicant/devel/ctrl_iface_page.html for full documentation of the commands that can be sent and events that can be emitted.

new WpaCtrl(ifName, ctrlPath)

constructs WpaCtrl

ParamTypeDefaultDescription
ifNamestringinterface name eg. wlan0
ctrlPathstring"'/run/wpa_supplicant'"The location of the wpa_supplicant control interface.

Example (Scan for SSIDs and connect to an wireless network.)

'use strict';

const WpaCtrl = require('wap-ctrl');
let wpa = new WpaCtrl('wlan0');

wpa.on('raw_msg', function(msg) {
    console.log(msg);
});

wpa.connect().then(function () {
    console.log('ready');

    return wpa.listNetworks();
}).then(function (networks) {
    console.log(networks);

    return wpa.scan();
}).then(function (accessPoints) {
    console.log(accessPoints);

    wpa.addNetwork();
    wpa.setNetworkSSID(0, 'ssid');
    wpa.setNetworkPreSharedKey(0, 'password');
    wpa.enableNetwork(0);
    return wpa.selectNetwork(0);
}).then(function () {
    wpa.close();
}).catch(function (err) {
    console.log(err);
});

wpaCtrl.connect() ⇒ Promise

connect to wpa control interface

Kind: instance method of WpaCtrl

wpaCtrl.close()

close the wpa control interface

Kind: instance method of WpaCtrl

wpaCtrl.sendCmd(msg) ⇒ Promise

send request to wpa_supplicant control interface

Kind: instance method of WpaCtrl

ParamTypeDescription
msgstringwpa_supplicant commands

wpaCtrl.scan() ⇒ Promise

scan for wifi AP

Kind: instance method of WpaCtrl

wpaCtrl.scanResults() ⇒ Promise

request for wifi scan results

Kind: instance method of WpaCtrl

wpaCtrl.addNetwork() ⇒ Promise

add new network

Kind: instance method of WpaCtrl

wpaCtrl.listNetworks() ⇒ Promise

request to list networks

Kind: instance method of WpaCtrl

wpaCtrl.status() ⇒ Promise

request for status

Kind: instance method of WpaCtrl

wpaCtrl.setNetworkVariable(networkId, variable, value) ⇒ Promise

set network variable

Kind: instance method of WpaCtrl

ParamTypeDescription
networkIdnumbernetwork id recieved from list networks
variablestringvariable to set
valuestringvalue for the variable

wpaCtrl.setNetworkSSID(networkId, ssid) ⇒ Promise

set network ssid

Kind: instance method of WpaCtrl

ParamTypeDescription
networkIdnumbernetwork id recieved from list networks
ssidstringssid of the network

wpaCtrl.setNetworkPreSharedKey(networkId, preSharedKey, ssid) ⇒ Promise

set network pre-shared key

Kind: instance method of WpaCtrl

ParamTypeDescription
networkIdnumbernetworkId network id recieved from list networks
preSharedKeystringpre-shared key
ssidstringssid of the network

wpaCtrl.setNetworkIdentity(networkId, identity) ⇒ Promise

set network identity

Kind: instance method of WpaCtrl

ParamTypeDescription
networkIdnumbernetwork id recieved from list networks
identitystringidentity string for EAP

wpaCtrl.setNetworkPassword(networkId, password) ⇒ Promise

set network password

Kind: instance method of WpaCtrl

ParamTypeDescription
networkIdnumbernetwork id recieved from list networks
passwordstringpassword string for EAP

wpaCtrl.enableNetwork(networkId) ⇒ Promise

enable configured network

Kind: instance method of WpaCtrl

ParamTypeDescription
networkIdnumbernetworkId network id recieved from list networks

wpaCtrl.selectNetwork(networkId) ⇒ Promise

select network to connect

Kind: instance method of WpaCtrl

ParamTypeDescription
networkIdnumbernetworkId network id recieved from list networks

wpaCtrl.saveConfig() ⇒ Promise

save the current configuration

Kind: instance method of WpaCtrl

wpaCtrl.reconfigure() ⇒ Promise

reload the configuration from disk

Kind: instance method of WpaCtrl

wpaCtrl.reassociate() ⇒ Promise

Force reassociation

Kind: instance method of WpaCtrl

wpaCtrl.disconnectAP() ⇒ Promise

disconnect from AP

Kind: instance method of WpaCtrl

wpaCtrl.peerFind() ⇒ Promise

search for peers

Kind: instance method of WpaCtrl

wpaCtrl.peerStopFind() ⇒ Promise

stop peer search

Kind: instance method of WpaCtrl

wpaCtrl.peerInfo(peerAddress) ⇒ Promise

fetch Peer Information

Kind: instance method of WpaCtrl

ParamTypeDescription
peerAddressstringpeer device address

wpaCtrl.peerConnectPBC(peerAddress, isOwner) ⇒ Promise

connect to peer with PBC(Push Button Control) authentication mechanism

Kind: instance method of WpaCtrl

ParamTypeDescription
peerAddressstringMac Address of peer
isOwnerBooleanYour role, are you group owner? if yes then true else false

wpaCtrl.peerConnectPIN(peerAddress, pin, isOwner) ⇒ Promise

connect to peer with PIN(password) authentication mechanism

Kind: instance method of WpaCtrl

ParamTypeDescription
peerAddressstringMac Address of peer
pinstringpassword for authentication
isOwnerBooleanYour role, are you group owner? if yes then true else false

wpaCtrl.listInterfaces() ⇒ Promise

list network interfaces on system

Kind: instance method of WpaCtrl

wpaCtrl.removeVitualInterface(iFaceName, callback) ⇒ Promise

Remove virtual interface eg: p2p-p2p0-1

Kind: instance method of WpaCtrl

ParamTypeDescription
iFaceNamestringinterface name
callbackfunctioncallback function

wpaCtrl.flushPeers() ⇒ Promise

Flush peer data

Kind: instance method of WpaCtrl

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago