<commit_before>const debug = require('debug')('connman-tests:wifi');
const async = require('async');

var _timeoutWiFiEnable = 5000;
var _timeoutTetherDisable = 4000;
var _scanRetryTimeout = 5000;
var _numScanRetries = 3;
var _connMan;
var _tech;
var _service;
var _connection;
var _available = false;
var _networks = [];
var _self;

/** https://kernel.googlesource.com/pub/scm/network/connman/connman/+/1.14/doc/service-api.txt
 *  string State [readonly]
 *     The service state information.
 *     Valid states are "idle", "failure", "association", "configuration", "ready", "disconnect" and "online".
 */
const WIFI_STATES = {
  IDLE: 'idle',
  FAILURE: 'failure',
  ASSOCIATION: 'association',
  CONFIGURATION: 'configuration',
  READY: 'ready',
  DISCONNECT: 'disconnect',
  ONLINE: 'online',
  CONNECTING: 'connecting', //--extra
  UNKNOWN: 'unkown' //--extra
};

const HOTSPOT_STATES = {
  UNKNOWN: 'unknown',
  CREATING_FAILED: 'creatingFailed',
  DISABLED: 'disabled',
  CREATING: 'creating',
  ENABLED: 'enabled'
};

const ETHERNET_STATES = {
  IDLE: 'idle',
  FAILURE: 'failure',
  ASSOCIATION: 'association',
  CONFIGURATION: 'configuration',
  READY: 'ready',
  DISCONNECT: 'disconnect',
  ONLINE: 'online',
  CONNECTING: 'connecting', //--extra
  UNKNOWN: 'unkown', //--extra
  DISABLED: 'disabled'
};

module.exports = WiFi;
var _hotspotSSID;
var _hotspotPassphrase;

function WiFi(connMan) {
  _connMan = connMan;
}

WiFi.prototype.init = function(hotspotSSID,hotspotPassphrase,callback) {
  debug("init: ",hotspotSSID,hotspotPassphrase);
  _self = this;
  _hotspotSSID = hotspotSSID;
  _hotspotPassphrase = hotspotPassphrase;
  _tech = _connMan.technologies.WiFi;
  if(_tech === undefined) return callback(new Error("No WiFi available"));
  _available = true;
  _self.enable(callback);
};
WiFi.prototype.enable = function(callback) {
  // Note: Hostmodule tries this 3 times?
  _self.setProperty('Powered', true, function(err) {
    //debug("WiFi setProperty 'Powered' true response: ",err);
    setTimeout(callback, _timeoutWiFiEnable);
  });
}
WiFi.prototype.disable = function(callback) {
  // Note: Hostmodule tries this 3 times?
  _self.setProperty('Powered', false, function(err) {
    //debug("WiFi setProperty 'Powered' true response: ",err);
    setTimeout(callback, _timeoutWiFiEnable);
  });
}
WiFi.prototype.setProperty = function(type, value, callback) {
  _tech.getProperties(function(err, properties) {
    //debug("getProperties response: ",err,properties);
    if(err) return callback(err);
    if(properties[type] === value) {
      //debug("property '",type,"' already set to '",value,"'");
      return callback();
    }
    _tech.setProperty(type,value, function(err) {
      //debug("WiFi setProperty '",type,"' to '",value,"' response: ",err);
      callback(err);
    });
  });
}
WiFi.prototype.getNetworks = function(callback) {
  debug("getNetworks");
  // ToDo: check if tethering, if so we can't scan
  async.retry(_numScanRetries, function(nextRetry) {
    debug("attempt scan");
    _tech.scan(function(err) {
      debug("  scan response: ",err);
      if(err) return setTimeout(nextRetry, _scanRetryTimeout, err);
      debug("listAccessPoints");<commit_msg>Comments<commit_after>const debug = require('debug')('connman-tests:wifi');
const async = require('async');

var _timeoutWiFiEnable = 5000;
var _timeoutTetherDisable = 4000;
var _scanRetryTimeout = 5000;
var _numScanRetries = 3;
var _connMan;
var _tech;
var _service;
var _connection;
var _available = false;
var _networks = [];
var _self;

/** https://kernel.googlesource.com/pub/scm/network/connman/connman/+/1.14/doc/service-api.txt
 *  string State [readonly]
 *     The service state information.
 *     Valid states are "idle", "failure", "association", "configuration", "ready", "disconnect" and "online".
 */
const WIFI_STATES = {
  IDLE: 'idle',
  FAILURE: 'failure',
  ASSOCIATION: 'association',
  CONFIGURATION: 'configuration',
  READY: 'ready',
  DISCONNECT: 'disconnect',
  ONLINE: 'online',
  CONNECTING: 'connecting', //--extra
  UNKNOWN: 'unkown' //--extra
};

const HOTSPOT_STATES = {
  UNKNOWN: 'unknown',
  CREATING_FAILED: 'creatingFailed',
  DISABLED: 'disabled',
  CREATING: 'creating',
  ENABLED: 'enabled'
};

const ETHERNET_STATES = {
  IDLE: 'idle',
  FAILURE: 'failure',
  ASSOCIATION: 'association',
  CONFIGURATION: 'configuration',
  READY: 'ready',
  DISCONNECT: 'disconnect',
  ONLINE: 'online',
  CONNECTING: 'connecting', //--extra
  UNKNOWN: 'unkown', //--extra
  DISABLED: 'disabled'
};

module.exports = WiFi;
var _hotspotSSID;
var _hotspotPassphrase;

function WiFi(connMan) {
  _connMan = connMan;
}

WiFi.prototype.init = function(hotspotSSID,hotspotPassphrase,callback) {
  debug("init: ",hotspotSSID,hotspotPassphrase);
  _self = this;
  _hotspotSSID = hotspotSSID;
  _hotspotPassphrase = hotspotPassphrase;
  // Retrieve WiFi technology
  // https://kernel.googlesource.com/pub/scm/network/connman/connman/+/1.14/doc/technology-api.txt
  _tech = _connMan.technologies.WiFi;
  if(_tech === undefined) return callback(new Error("No WiFi hardware available"));
  _available = true;
  _self.enable(callback);
};
WiFi.prototype.enable = function(callback) {
  // Note: Hostmodule tries this 3 times?
  _self.setProperty('Powered', true, function(err) {
    //debug("WiFi setProperty 'Powered' true response: ",err);
    setTimeout(callback, _timeoutWiFiEnable); // ToDo: needed?
  });
}
WiFi.prototype.disable = function(callback) {
  // Note: Hostmodule tries this 3 times?
  _self.setProperty('Powered', false, function(err) {
    //debug("WiFi setProperty 'Powered' true response: ",err);
    setTimeout(callback, _timeoutWiFiEnable); // ToDo: needed?
  });
}
WiFi.prototype.setProperty = function(type, value, callback) {
  _tech.getProperties(function(err, properties) {
    //debug("getProperties response: ",err,properties);
    if(err) return callback(err);
    if(properties[type] === value) {
      //debug("property '",type,"' already set to '",value,"'");
      return callback();
    }
    _tech.setProperty(type,value, function(err) {
      //debug("WiFi setProperty '",type,"' to '",value,"' response: ",err);
      callback(err);
    });
  });
}
WiFi.prototype.getNetworks = function(callback) {
  debug("getNetworks");
  // ToDo: check if tethering, if so we can't scan
  async.retry(_numScanRetries, function(nextRetry) {
    debug("attempt scan");
    _tech.scan(function(err) {
      debug("  scan response: ",err);
      if(err) return setTimeout(nextRetry, _scanRetryTimeout, err);
      debug("listAccessPoints");
      // ToDo research: Results will be signaled via the ServicesChanged signal from the manager interface.
{'fraction_non_alphanumeric': 0.15209920812789482, 'fraction_numerical': 0.00582698341550874, 'mean_word_length': 4.523102310231023, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3640743', 'n_tokens_mistral': 2303, 'n_tokens_neox': 2253, 'n_words': 500}