From 44ce02fbb6af3d797bfd20024c56cb390818c8c7 Mon Sep 17 00:00:00 2001 From: keeramis Date: Thu, 23 May 2024 11:31:55 -0700 Subject: [PATCH] Add wifi security enum --- src/particle-usb.js | 4 ++- src/wifi-device.js | 88 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 88 insertions(+), 4 deletions(-) diff --git a/src/particle-usb.js b/src/particle-usb.js index 896ff06..1728e05 100644 --- a/src/particle-usb.js +++ b/src/particle-usb.js @@ -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'); @@ -51,6 +52,7 @@ module.exports = { NetworkStatus, WifiAntenna, WifiSecurity, + WifiSecurityEnum, WifiCipher, EapMethod, CloudConnectionStatus, diff --git a/src/wifi-device.js b/src/wifi-device.js index f327996..a91ec96 100644 --- a/src/wifi-device.js +++ b/src/wifi-device.js @@ -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) { + 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. * @@ -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 = { @@ -122,7 +201,7 @@ const WifiDevice = base => class extends base { dataPayload = { ssid, bssid: null, - security: null, + security, credentials: { type: 1, // CredentialsType.PASSWORD password @@ -211,6 +290,9 @@ const WifiDevice = base => class extends base { } }; +const WifiSecurityEnum = DeviceOSProtobuf.getDefinition('wifi.Security').message; + module.exports = { - WifiDevice + WifiDevice, + WifiSecurityEnum };