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;
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
return new Promise((resolve) => {
|
||||
@ -155,79 +233,25 @@ function wifiNetworks(callback) {
|
||||
}
|
||||
}
|
||||
if (iface) {
|
||||
let iwlistParts = execSync(`export LC_ALL=C; iwlist ${iface} scan 2>/dev/null; unset LC_ALL`).toString().split(' Cell ');
|
||||
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 = util.getValue(lines, 'address', ':', true);
|
||||
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[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);
|
||||
const res = getWifiNetworkAlt(iface);
|
||||
if (res === -1) {
|
||||
// try again after 4 secs
|
||||
setTimeout(function (iface) {
|
||||
const res = getWifiNetworkAlt(iface);
|
||||
if (res != -1) { result = res; }
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
|
||||
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: []
|
||||
});
|
||||
resolve(result);
|
||||
}, 4000);
|
||||
} else {
|
||||
result = res;
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
} catch (e) {
|
||||
if (callback) {
|
||||
callback(result);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user