Skip to content

Commit

Permalink
Add wifi security enum
Browse files Browse the repository at this point in the history
  • Loading branch information
keeramis committed May 23, 2024
1 parent e089514 commit 44ce02f
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/particle-usb.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const { getDevices: getUsbDevices, openDeviceById: openUsbDeviceById, openNative
const { PollingPolicy } = require('./device-base');
const { FirmwareModule, FirmwareModuleDisplayNames } = require('./device');
const { NetworkStatus } = require('./network-device');
const { WifiAntenna, WifiSecurity, WifiCipher, EapMethod } = require('./wifi-device');
const { WifiAntenna, WifiCipher, EapMethod, WifiSecurityEnum } = require('./wifi-device');
const { WifiSecurity } = require('./wifi-device-legacy');
const { CloudConnectionStatus, ServerProtocol } = require('./cloud-device');
const { Result } = require('./result');
const { DeviceError, NotFoundError, NotAllowedError, StateError, TimeoutError, MemoryError, ProtocolError, UsbError, InternalError, RequestError, DeviceProtectionError } = require('./error');
Expand Down Expand Up @@ -51,6 +52,7 @@ module.exports = {
NetworkStatus,
WifiAntenna,
WifiSecurity,
WifiSecurityEnum,
WifiCipher,
EapMethod,
CloudConnectionStatus,
Expand Down
88 changes: 85 additions & 3 deletions src/wifi-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,85 @@ const WifiDevice = base => class extends base {
);
}

/**
* Join a known WiFi network for Gen 3+ devices.
*
* Note, there are known bugs with this method/Device OS:
* - sc-96270: where P2's don't do anything with bssid or security fields; so cannot connect to hidden networks
* - sc-96826: Connecting to open network without passsword does not work
*
* Supported platforms:
* - Gen 4: Supported on P2 since Device OS 3.x
* - Gen 4: Supported on M-SoM since Device OS 5.x
* @param {string} ssid - SSID of Wifi Network
* @param {string} password - Password of Wifi network, if not set will not use security
* @param {Object} options See sendControlRequest(), same options are here.
* @return {ProtobufInteraction} -
*/
async joinKnownWifiNetwork({ ssid }, options) {
return await this._sendAndHandleProtobufRequest(
'wifi.JoinKnownNetworkRequest',
{ ssid },
options
);
}

/**
* Gets the list of networks for Gen 3+ devices.
*
* Note, there are known bugs with this method/Device OS:
* - sc-96270: where P2's don't do anything with bssid or security fields; so cannot connect to hidden networks
* - sc-96826: Connecting to open network without passsword does not work
*
* Supported platforms:
* - Gen 4: Supported on P2 since Device OS 3.x
* - Gen 4: Supported on M-SoM since Device OS 5.x
* @param {string} ssid - SSID of Wifi Network
* @param {string} password - Password of Wifi network, if not set will not use security
* @param {Object} options See sendControlRequest(), same options are here.
* @return {ProtobufInteraction} -
*/
async listWifiNetworks({ ssid }, options) {

Check failure on line 136 in src/wifi-device.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v12)

'ssid' is defined but never used

Check failure on line 136 in src/wifi-device.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v14)

'ssid' is defined but never used

Check failure on line 136 in src/wifi-device.js

View workflow job for this annotation

GitHub Actions / Test (Node.js v16)

'ssid' is defined but never used
return await this._sendAndHandleProtobufRequest(
'wifi.GetKnownNetworksRequest',
options
);
}

/**
* Gets the list of networks for Gen 3+ devices.
*
* Note, there are known bugs with this method/Device OS:
* - sc-96270: where P2's don't do anything with bssid or security fields; so cannot connect to hidden networks
* - sc-96826: Connecting to open network without passsword does not work
*
* Supported platforms:
* - Gen 4: Supported on P2 since Device OS 3.x
* - Gen 4: Supported on M-SoM since Device OS 5.x
* @param {string} ssid - SSID of Wifi Network
* @param {string} password - Password of Wifi network, if not set will not use security
* @param {Object} options See sendControlRequest(), same options are here.
* @return {ProtobufInteraction} -
*/
async removeWifiNetwork({ ssid }, options) {
const dataPayload = {
ssid
};
return await this._sendAndHandleProtobufRequest(
'wifi.RemoveKnownNetworkRequest',
dataPayload,
options
);
}

async getCurrentWifiNetwork(options) {
return await this._sendAndHandleProtobufRequest(
'wifi.GetCurrentNetworkRequest',
{},
options
);
}

/**
* Set a new WiFi network for Gen 3+ devices.
*
Expand All @@ -109,7 +188,7 @@ const WifiDevice = base => class extends base {
* @param {Object} options See sendControlRequest(), same options are here.
* @return {ProtobufInteraction} -
*/
async setWifiCredentials({ ssid, password = null }, options) {
async setWifiCredentials({ ssid, security, password = null }, options) {
let dataPayload;
if (password === null) {
dataPayload = {
Expand All @@ -122,7 +201,7 @@ const WifiDevice = base => class extends base {
dataPayload = {
ssid,
bssid: null,
security: null,
security,
credentials: {
type: 1, // CredentialsType.PASSWORD
password
Expand Down Expand Up @@ -211,6 +290,9 @@ const WifiDevice = base => class extends base {
}
};

const WifiSecurityEnum = DeviceOSProtobuf.getDefinition('wifi.Security').message;

module.exports = {
WifiDevice
WifiDevice,
WifiSecurityEnum
};

0 comments on commit 44ce02f

Please sign in to comment.