raspberry wifi fix (wip)
This commit is contained in:
parent
3781d3c219
commit
26d49b0e25
162
lib/wifi.js
162
lib/wifi.js
@ -112,6 +112,84 @@ function wifiFrequencyFromChannel(channel) {
|
|||||||
return {}.hasOwnProperty.call(frequencies, channel) ? frequencies[channel] : null;
|
return {}.hasOwnProperty.call(frequencies, channel) ? frequencies[channel] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getWifiNetworkAlt(iface) {
|
||||||
|
const result = [];
|
||||||
|
try {
|
||||||
|
let iwlistParts = execSync(`export LC_ALL=C; iwlist ${iface} scan; unset LC_ALL`).toString().split(' Cell ');
|
||||||
|
if (iwlistParts[0].indexOf('resource busy')) { return -1; }
|
||||||
|
if (iwlistParts.length > 1) {
|
||||||
|
iwlistParts.shift();
|
||||||
|
for (let i = 0; i < iwlistParts.length; i++) {
|
||||||
|
const lines = iwlistParts[i].split('\n');
|
||||||
|
const channel = util.getValue(lines, 'channel', ':', true);
|
||||||
|
const address = (lines && lines.length && lines[0].indexOf('Address:') >= 0 ? lines[0].split('Address:')[1].trim().toLowerCase() : '');
|
||||||
|
const mode = util.getValue(lines, 'mode', ':', true);
|
||||||
|
const frequency = util.getValue(lines, 'frequency', ':', true);
|
||||||
|
const qualityString = util.getValue(lines, 'Quality', '=', true);
|
||||||
|
const dbParts = qualityString.toLowerCase().split('signal level=');
|
||||||
|
const db = dbParts.length > 1 ? util.toInt(dbParts[1]) : 0;
|
||||||
|
const quality = db ? wifiQualityFromDB(db) : 0;
|
||||||
|
const ssid = util.getValue(lines, 'essid', ':', true);
|
||||||
|
|
||||||
|
// security and wpa-flags
|
||||||
|
const isWpa = iwlistParts[i].indexOf(' WPA ') >= 0;
|
||||||
|
const isWpa2 = iwlistParts[i].indexOf('WPA2 ') >= 0;
|
||||||
|
const security = [];
|
||||||
|
if (isWpa) { security.push('WPA'); }
|
||||||
|
if (isWpa2) { security.push('WPA2'); }
|
||||||
|
const wpaFlags = [];
|
||||||
|
let wpaFlag = '';
|
||||||
|
lines.forEach(function (line) {
|
||||||
|
const l = line.trim().toLowerCase();
|
||||||
|
if (l.indexOf('group cipher') >= 0) {
|
||||||
|
if (wpaFlag) {
|
||||||
|
wpaFlags.push(wpaFlag);
|
||||||
|
}
|
||||||
|
const parts = l.split(':');
|
||||||
|
if (parts.length > 1) {
|
||||||
|
wpaFlag = parts[1].trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (l.indexOf('pairwise cipher') >= 0) {
|
||||||
|
const parts = l.split(':');
|
||||||
|
if (parts.length > 1) {
|
||||||
|
if (parts[1].indexOf('tkip')) { wpaFlag = (wpaFlag ? 'TKIP/' + wpaFlag : 'TKIP'); }
|
||||||
|
else if (parts[1].indexOf('ccmp')) { wpaFlag = (wpaFlag ? 'CCMP/' + wpaFlag : 'CCMP'); }
|
||||||
|
else if (parts[1].indexOf('proprietary')) { wpaFlag = (wpaFlag ? 'PROP/' + wpaFlag : 'PROP'); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (l.indexOf('authentication suites') >= 0) {
|
||||||
|
const parts = l.split(':');
|
||||||
|
if (parts.length > 1) {
|
||||||
|
if (parts[1].indexOf('802.1x')) { wpaFlag = (wpaFlag ? '802.1x/' + wpaFlag : '802.1x'); }
|
||||||
|
else if (parts[1].indexOf('psk')) { wpaFlag = (wpaFlag ? 'PSK/' + wpaFlag : 'PSK'); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (wpaFlag) {
|
||||||
|
wpaFlags.push(wpaFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
result.push({
|
||||||
|
ssid,
|
||||||
|
bssid: address,
|
||||||
|
mode,
|
||||||
|
channel: channel ? util.toInt(channel) : null,
|
||||||
|
frequency: frequency ? util.toInt(frequency.replace('.', '')) : null,
|
||||||
|
signalLevel: db,
|
||||||
|
quality,
|
||||||
|
security,
|
||||||
|
wpaFlags,
|
||||||
|
rsnFlags: []
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
} catch (e) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function wifiNetworks(callback) {
|
function wifiNetworks(callback) {
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
@ -155,79 +233,25 @@ function wifiNetworks(callback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (iface) {
|
if (iface) {
|
||||||
let iwlistParts = execSync(`export LC_ALL=C; iwlist ${iface} scan 2>/dev/null; unset LC_ALL`).toString().split(' Cell ');
|
const res = getWifiNetworkAlt(iface);
|
||||||
if (iwlistParts.length > 1) {
|
if (res === -1) {
|
||||||
iwlistParts.shift();
|
// try again after 4 secs
|
||||||
for (let i = 0; i < iwlistParts.length; i++) {
|
setTimeout(function (iface) {
|
||||||
const lines = iwlistParts[i].split('\n');
|
const res = getWifiNetworkAlt(iface);
|
||||||
const channel = util.getValue(lines, 'channel', ':', true);
|
if (res != -1) { result = res; }
|
||||||
const address = util.getValue(lines, 'address', ':', true);
|
if (callback) {
|
||||||
const mode = util.getValue(lines, 'mode', ':', true);
|
callback(result);
|
||||||
const frequency = util.getValue(lines, 'frequency', ':', true);
|
|
||||||
const qualityString = util.getValue(lines, 'Quality', '=', true);
|
|
||||||
const dbParts = qualityString.toLowerCase().split('signal level=');
|
|
||||||
const db = dbParts.length > 1 ? util.toInt(dbParts[1]) : 0;
|
|
||||||
const quality = db ? wifiQualityFromDB(db) : 0;
|
|
||||||
const ssid = util.getValue(lines, 'essid', ':', true);
|
|
||||||
|
|
||||||
// security and wpa-flags
|
|
||||||
const isWpa = iwlistParts[i].indexOf(' WPA ') >= 0;
|
|
||||||
const isWpa2 = iwlistParts[i].indexOf('WPA2 ') >= 0;
|
|
||||||
const security = [];
|
|
||||||
if (isWpa) { security.push('WPA'); }
|
|
||||||
if (isWpa2) { security.push('WPA2'); }
|
|
||||||
const wpaFlags = [];
|
|
||||||
let wpaFlag = '';
|
|
||||||
lines.forEach(function (line) {
|
|
||||||
const l = line.trim().toLowerCase();
|
|
||||||
if (l.indexOf('group cipher') >= 0) {
|
|
||||||
if (wpaFlag) {
|
|
||||||
wpaFlags.push(wpaFlag);
|
|
||||||
}
|
|
||||||
const parts = l.split(':');
|
|
||||||
if (parts.length > 1) {
|
|
||||||
wpaFlag = parts[1].trim();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (l.indexOf('pairwise cipher') >= 0) {
|
|
||||||
const parts = l.split(':');
|
|
||||||
if (parts.length > 1) {
|
|
||||||
if (parts[i].indexOf('tkip')) { wpaFlag = (wpaFlag ? 'TKIP/' + wpaFlag : 'TKIP'); }
|
|
||||||
else if (parts[i].indexOf('ccmp')) { wpaFlag = (wpaFlag ? 'CCMP/' + wpaFlag : 'CCMP'); }
|
|
||||||
else if (parts[i].indexOf('proprietary')) { wpaFlag = (wpaFlag ? 'PROP/' + wpaFlag : 'PROP'); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (l.indexOf('authentication suites') >= 0) {
|
|
||||||
const parts = l.split(':');
|
|
||||||
if (parts.length > 1) {
|
|
||||||
if (parts[i].indexOf('802.1x')) { wpaFlag = (wpaFlag ? '802.1x/' + wpaFlag : '802.1x'); }
|
|
||||||
else if (parts[i].indexOf('psk')) { wpaFlag = (wpaFlag ? 'PSK/' + wpaFlag : 'PSK'); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (wpaFlag) {
|
|
||||||
wpaFlags.push(wpaFlag);
|
|
||||||
}
|
}
|
||||||
|
resolve(result);
|
||||||
result.push({
|
}, 4000);
|
||||||
ssid,
|
} else {
|
||||||
bssid: address,
|
result = res;
|
||||||
mode,
|
if (callback) {
|
||||||
channel: channel ? util.toInt(channel) : null,
|
callback(result);
|
||||||
frequency: frequency ? util.toInt(frequency.replace('.', '')) : null,
|
|
||||||
signalLevel: db,
|
|
||||||
quality,
|
|
||||||
security,
|
|
||||||
wpaFlags,
|
|
||||||
rsnFlags: []
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
resolve(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (callback) {
|
|
||||||
callback(result);
|
|
||||||
}
|
|
||||||
resolve(result);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(result);
|
callback(result);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user