[FL-3759] Fix expansion protocol crash when fed lots of garbage (#3409)

* Fix crash caused by garbage input
* Add unit tests for garbage input
* Enable applications to disable and then restore expansion module support
* GPIO App: disable expansion on app start and re-enable on exit

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
Georgii Surkov
2024-01-30 16:54:25 +03:00
committed by GitHub
parent c8ea167a06
commit e6f078eeb7
12 changed files with 166 additions and 118 deletions

View File

@@ -21,18 +21,17 @@ extern "C" {
typedef struct Expansion Expansion;
/**
* @brief Enable support for expansion modules on designated serial port.
* @brief Enable support for expansion modules.
*
* Only one serial port can be used to communicate with an expansion
* module at a time.
* Calling this function will load user settings and enable
* expansion module support on the serial port specified in said settings.
*
* Calling this function when expansion module support is already enabled
* will first disable the previous setting, then enable the current one.
* If expansion module support was disabled in settings, this function
* does nothing.
*
* @param[in,out] instance pointer to the Expansion instance.
* @param[in] serial_id numerical identifier of the serial.
*/
void expansion_enable(Expansion* instance, FuriHalSerialId serial_id);
void expansion_enable(Expansion* instance);
/**
* @brief Disable support for expansion modules.
@@ -41,10 +40,34 @@ void expansion_enable(Expansion* instance, FuriHalSerialId serial_id);
* expansion module (if any), release the serial handle and
* reset the respective pins to the default state.
*
* @note Applications requiring serial port access MUST call
* this function BEFORE calling furi_hal_serial_control_acquire().
* Similarly, an expansion_enable() call MUST be made right AFTER
* a call to furi_hal_serial_control_release() to ensure that
* the user settings are properly restored.
*
* @param[in,out] instance pointer to the Expansion instance.
*/
void expansion_disable(Expansion* instance);
/**
* @brief Enable support for expansion modules on designated serial port.
*
* Only one serial port can be used to communicate with an expansion
* module at a time.
*
* Calling this function when expansion module support is already enabled
* will first disable the previous setting, then enable the current one.
*
* @warning This function does not respect user settings for expansion modules,
* so calling it might leave the system in inconsistent state. Avoid using it
* unless absolutely necessary.
*
* @param[in,out] instance pointer to the Expansion instance.
* @param[in] serial_id numerical identifier of the serial.
*/
void expansion_set_listen_serial(Expansion* instance, FuriHalSerialId serial_id);
#ifdef __cplusplus
}
#endif