particle-iot / particle-cli

Command Line Interface for Particle Cloud and devices
Apache License 2.0
212 stars 92 forks source link

Add support for Protected Devices in CLI operations #754

Closed keeramis closed 2 weeks ago

keeramis commented 1 month ago

Description

This PR introduces support for managing Protected Devices similar to Open Devices. When a device is identified as a Protected Device, CLI puts the device in Service Mode, executes the CLI operation that is run by the user, and re-enables Device Protection on the device (whether the command succeeds or fails). If the device is in Service Mode, CLI executes the command and enables Device Protection on the device.

A generic wrapper has been implemented to handle both Open and Protected Devices. This wrapper obtains the USB device handle, executes the requested command (e.g., particle flash xxx), and, if applicable, handles the transition into Service Mode and re-enables Device Protection after command execution.

The output of CLI commands for all device types and platforms remains unchanged, with all handling of Protected Devices occurring seamlessly in the background.

How to Test

Use any device on any platform in any mode (Open / Protected ) and run various CLI commands to ensure proper functionality. Example: particle flash xxx, particle serial xxx, particle wifi xxx

You can use particle device-protection --help to enable Device Protection on your device.

Note that if you are testing Protected Devices starting in DFU mode, CLI is expected to fail the command after a 60 sec timeout for devices on device-os 6.1.0 and 6.1.1. Device-OS fixes to handle Protected Devices in DFU mode are deployed in future 6.2.0 (or current develop-6.x branch). Noted here.

Related Issues / Discussions

https://app.shortcut.com/particle/epic/127955 Device Protection Tooling SDD

Completeness