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
31 changes: 28 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
- [wpa_cli.bssid(interface, ap, ssid, callback)](#wpa_clibssidinterface-ap-ssid-callback) - set preferred bssid for ssid
- [wpa_cli.reassociate(interface,
callback)](#wpa_clireassociateinterface-callback) - tell wpa_supplicant to reassociate to an access points
- [wpa_cli.reattach(interface,
callback)](#wpa_clireattachinterface-callback) - force reassociation back to the same BSS
- [wpa_cli.disconnect(interface,
callback)](#wpa_clidisconnectinterface-callback) - disconnect and wait for reassociate/reconnect command before connecting
- [wpa_cli.reconnect(interface,
callback)](#wpa_clireconnectinterface-callback) - like reassociate, but only takes effect if already disconnected
- [wpa_cli.reauthenticate(interface,
callback)](#wpa_clireauthenticateinterface-callback) - trigger IEEE 802.1X/EAPOL reauthentication
- [wpa_cli.set(interface, variable, value, callback)](#wpa_clisetinterface-variable-value-callback) - set variable to value
- [wpa_cli.add_network(interface, callback)](#wpa_cliadd_networkinterface-callback) - add network
- [wpa_cli.set_network(interface, id, variable, value, callback)](#wpa_cliset_networkinterface-id-variable-value-callback) - set network variables
Expand All @@ -44,6 +52,8 @@
- [wpa_cli.scan(interface, callback)](#wpa_cliscaninterface-callback) - new BSS scan
- [wpa_cli.scan_results(interface, callback)](#wpa_cliscan_resultsinterface-callback) - results of latest BSS scan
- [wpa_cli.save_config(interface, callback)](#wpa_clisave_configinterface-callback) - saves the current configuration
- [wpa_cli.flush(interface,
callback)](#wpa_cliflushinterface-callback) - flush wpa_supplicant state
- [wpa_supplicant](#wpa_supplicant) - configure a wireless network connection
- [wpa_supplicant.enable(options, callback)](#wpa_supplicantenableoptions-callback) - connect to a wireless network
- [wpa_supplicant.disable(interface, callback)](#wpa_supplicantdisableinterface-callback) - disconnect from a wireless network
Expand Down Expand Up @@ -499,6 +509,18 @@ wpa_cli.bssid('wlan0', 'Fake-Wifi', '2c:f5:d3:02:ea:dd', function(err, data){
}
});
```
## wpa_cli.reattach(interface, callback)
The **wpa_cli reattach** command is used to force reassociation back to the same BSS on a specific network interface.

## wpa_cli.disconnect(interface, callback)
The **wpa_cli disconnect** command is used to disconnect and wait for reassociate/reconnect command before connecting on a specific network interface.

## wpa_cli.reconnect(interface, callback)
The **wpa_cli reconnect** command is used like reassociate, but only takes effect if already disconnected.

## wpa_cli.reauthenticate(interface, callback)
The **wpa_cli reauthenticate** command is used to trigger IEEE 802.1X/EAPOL reauthentication on a specific network interface.

## wpa_cli.set(interface, variable, value, callback)
The **wpa_cli set** command is used to set wpa_supplicant parameters to a value on a specific network interface.

Expand Down Expand Up @@ -541,10 +563,10 @@ The **wpa_cli scan** is used to request a new BSS scan on a specific network int
## wpa_cli.scan_results(interface, callback)
The **wpa_cli scan_results** is used to return the results of the latest BSS scan
that was run on a specific network interface.

``` javascript
var wpa_cli = require('wireless-tools/wpa_cli');

wpa_cli.scan('wlan0', function(err, data){
wpa_cli.scan_results('wlan0', function(err, data) {
// returns the results of the BSS scan once it completes
Expand Down Expand Up @@ -578,12 +600,15 @@ The **wpa_cli save_config** command is used to save the current wpa_cli configur

``` javascript
var wpa_cli = require('wireless-tools/wpa_cli');

wpa_cli.save_config('wlan0', function(err, data){
// current wpa_cli configuration is saved
});
```

## wpa_cli.flush(interface, callback)
The **wpa_cli flush** command is used to flush wpa_supplicant state on a specific network interface.

# wpa_supplicant
The **wpa_supplicant** command is used to configure a wireless network connection for a network interface.

Expand Down
59 changes: 31 additions & 28 deletions wpa_cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,46 @@ var wpa_cli = module.exports = {
exec: child_process.exec,
status: status,
bssid: bssid,
reassociate: reassociate,
set: set,
add_network: add_network,
set_network: set_network,
enable_network: enable_network,
disable_network: disable_network,
remove_network: remove_network,
select_network: select_network,
scan: scan,
scan_results: scan_results,
save_config: save_config
};

// add simple command without arguments and simple outputs
function buildCommand(commandName, interface, args) {
return ['wpa_cli -i', interface, commandName]
.concat(args)
.join(' ');
}

function exportCommand(commandName) {
module.exports[commandName] = function(interface, callback) {
var command = buildCommand(commandName, interface, []);

return this.exec(command, parse_command_interface(callback));
}
}

commands = [
'reassociate',
'reattach',
'disconnect',
'reconnect',
'scan',
'reauthenticate',
'flush',
'save_config'
];

for(var i in commands) {
exportCommand(commands[i]);
}

/**
* Parses the status for a wpa network interface.
*
Expand Down Expand Up @@ -192,7 +219,7 @@ function parse_scan_results(block) {
var match;
var results = [];
var lines;

lines = block.split('\n').map(function(item) { return item + "\n"; });
lines.forEach(function(entry){
var parsed = {};
Expand Down Expand Up @@ -307,14 +334,6 @@ function bssid(interface, ap, ssid, callback) {
return this.exec(command, parse_command_interface(callback));
}

function reassociate(interface, callback) {
var command = ['wpa_cli -i',
interface,
'reassociate'].join(' ');

return this.exec(command, parse_command_interface(callback));
}

/* others commands not tested
//ap_scan 1
// set_network 0 0 scan_ssid 1
Expand Down Expand Up @@ -391,26 +410,10 @@ function select_network(interface, id, callback) {
return this.exec(command, parse_command_interface(callback));
}

function scan(interface, callback) {
var command = ['wpa_cli -i',
interface,
'scan'].join(' ');

return this.exec(command, parse_command_interface(callback));
}

function scan_results(interface, callback) {
var command = ['wpa_cli -i',
interface,
'scan_results'].join(' ');

return this.exec(command, parse_scan_results_interface(callback));
}

function save_config(interface, callback) {
var command = ['wpa_cli -i',
interface,
'save_config'].join(' ');

return this.exec(command, parse_command_interface(callback));
}