Skip to content

Commit def1d0f

Browse files
authored
Merge pull request #76 from derskythe/feat/refactor
feat: Some refactoring to clean-up the code
2 parents 3227a82 + 37436c7 commit def1d0f

16 files changed

+395
-188
lines changed

.github/workflows/pr-build.yaml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
name: "PR Build"
2+
run-name: "PR Build ${{ inputs.DEPLOY_TARGET }} triggered by ${{ github.EVENT_NAME }} (@${{ github.ACTOR }})"
3+
4+
on:
5+
pull_request:
6+
types: [opened, reopened]
7+
8+
jobs:
9+
build-for-pr:
10+
runs-on: ubuntu-latest
11+
env:
12+
REPO_SELF: ${{ vars.REPO_SELF }}
13+
APP_PATH: "applications_user/subbrute"
14+
RELATIVE_PATH: "applications/external/subbrute"
15+
PREV_TAG: ""
16+
APP_NAME: ""
17+
ZIP_NAME: ""
18+
ZIP_TAG: ""
19+
TGZ_NAME: ""
20+
TGZ_TAG: ""
21+
SHA: ""
22+
FW_VERSION: ""
23+
RELEASE_VERSION: ""
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
firmware: [unlshd, official]
28+
include:
29+
- firmware: unlshd
30+
url: ${{ vars.REPO_UNLEASHED }}
31+
version: ${{ vars.FIRMWARE_VERSION }}
32+
src-included: 0
33+
- firmware: official
34+
url: ${{ vars.REPO_OFFICIAL }}
35+
version: official
36+
src-included: 0
37+
steps:
38+
- name: Copy Firmware Files
39+
uses: actions/checkout@v4
40+
with:
41+
repository: ${{ matrix.url }}
42+
clean: true
43+
submodules: true
44+
ref: dev
45+
46+
- name: Copy Repo Files
47+
if: ${{ matrix.src-included == 0 }}
48+
uses: actions/checkout@v4
49+
with:
50+
repository: ${{ vars.REPO_SELF }}
51+
clean: true
52+
submodules: true
53+
path: ${{ env.APP_PATH }}
54+
55+
- name: Remove other apps
56+
shell: pwsh
57+
# rm to remove problem FAP which includes non-existent files
58+
run: |
59+
Remove-Item -Force -Recurse ./applications/debug -ErrorAction SilentlyContinue
60+
Remove-Item -Force -Recurse ./applications/examples -ErrorAction SilentlyContinue
61+
Remove-Item -Force -Recurse ${{ env.RELATIVE_PATH }} -ErrorAction SilentlyContinue
62+
63+
- name: Get SHA of our application and release version
64+
shell: pwsh
65+
env:
66+
GITHUB_TOKEN: ${{ secrets.FLIPPER_TOKEN }}
67+
INPUT_VERSION: ${{ inputs.version }}
68+
run: |
69+
Write-Output "::notice title=${{ matrix.firmware }} Input Version Number::v${{ inputs.version }}"
70+
$fwInfo = ((gh release view --json tagName,url -R ${{ matrix.url }}) | ConvertFrom-Json)
71+
cd '${{ env.APP_PATH }}'
72+
$sha = (git rev-parse --verify HEAD)
73+
74+
$releaseVersion = ''
75+
$latestTag = ((gh release view --json tagName,url -R ${{ vars.REPO_SELF }}) | ConvertFrom-Json ).tagName
76+
77+
if ( [string]::IsNullOrWhitespace($env:INPUT_VERSION) ) {
78+
Write-Output "::notice title=${{ matrix.firmware }} Latest tag::$latestTag"
79+
80+
$lastIndex = $latestTag.LastIndexOf('.')
81+
82+
$minorValue = $latestTag.Substring($latestTag.LastIndexOf('.') + 1)
83+
$minorValue = [Convert]::ToInt32($minorValue) + 1
84+
$newTag = $latestTag.Substring(0, $lastIndex)
85+
86+
$releaseVersion = ('{0}.{1}' -f $newTag, $minorValue)
87+
} else {
88+
$releaseVersion = "$env:INPUT_VERSION"
89+
}
90+
91+
if ( $releaseVersion.StartsWith('v') ) {
92+
$releaseVersion = $releaseVersion.Substring(1)
93+
}
94+
95+
Write-Output "::notice title=${{ matrix.firmware }} PREV_TAG::$latestTag"
96+
Write-Output "::notice title=${{ matrix.firmware }} RELEASE_VERSION::$releaseVersion"
97+
Write-Output "::notice title=${{ matrix.firmware }} SHA::$sha"
98+
Write-Output ('::notice title=${{ matrix.firmware }} FW_VERSION::{0}' -f $fwInfo.tagName)
99+
100+
Write-Output ('RELEASE_VERSION={0}' -f $releaseVersion) >> $env:GITHUB_ENV
101+
Write-Output ('SHA={0}' -f $sha) >> $env:GITHUB_ENV
102+
Write-Output ('FW_VERSION={0}' -f $fwInfo.tagName) >> $env:GITHUB_ENV
103+
Write-Output ('PREV_TAG={0}' -f $latestTag) >> $env:GITHUB_ENV
104+
105+
- name: Build Firmware
106+
shell: bash
107+
if: ${{ success() }}
108+
env:
109+
FBT_NO_SYNC: 0
110+
DIST_SUFFIX: ${{ matrix.version }}
111+
WORKFLOW_BRANCH_OR_TAG: release-cfw
112+
run: |
113+
./fbt COMPACT=1 DEBUG=0 FBT_NO_SYNC=0
114+
115+
- name: Build FAPs
116+
shell: bash
117+
if: ${{ success() }}
118+
env:
119+
FBT_NO_SYNC: 0
120+
DIST_SUFFIX: ${{ matrix.version }}
121+
WORKFLOW_BRANCH_OR_TAG: release-cfw
122+
# rm to remove problem FAP which includes non-existent files
123+
run: |
124+
./fbt COMPACT=1 DEBUG=0 FBT_NO_SYNC=0 fap_dist
125+
126+
#EOF

helpers/gui_top_buttons.h

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,29 @@
77
#include <gui/icon_animation.h>
88

99
/**
10-
* Thanks to the author of metronome
11-
* @param canvas
12-
* @param str
10+
* @brief This function draws a button in the top left corner of the canvas with icon and string.
11+
*
12+
* The design and layout of the button is defined within this function.
13+
*
14+
*
15+
* @param[in] canvas This is a pointer to the @c Canvas structure where the button will be drawn.
16+
* @param[in] str This is a pointer to the character string that will be drawn within the button.
17+
*
18+
* @note Thanks to the author of metronome @see https://github.com/panki27/Metronome
19+
*
1320
*/
1421
void elements_button_top_left(Canvas* canvas, const char* str);
1522

1623
/**
17-
* Thanks to the author of metronome
18-
* @param canvas
19-
* @param str
24+
* @brief This function draws a button in the top right corner of the canvas with icon and string.
25+
*
26+
* The design and layout of the button is defined within this function.
27+
*
28+
*
29+
* @param[in] canvas This is a pointer to the @c Canvas structure where the button will be drawn.
30+
* @param[in] str This is a pointer to the character string that will be drawn within the button.
31+
*
32+
* @note Thanks to the author of metronome @see https://github.com/panki27/Metronome
33+
*
2034
*/
21-
void elements_button_top_right(Canvas* canvas, const char* str);
35+
void elements_button_top_right(Canvas* canvas, const char* str);

helpers/subbrute_radio_device_loader.c

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
1-
#include <furi/core/check.h>
1+
#include "subbrute_radio_device_loader.h"
22

3-
#include <applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h>
3+
#include <furi/core/check.h>
44
#include <lib/subghz/devices/cc1101_int/cc1101_int_interconnect.h>
55

6-
#include "subbrute_radio_device_loader.h"
6+
#include "applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h"
77

88
#define TAG "SubBruteRadioDeviceLoader"
99

10+
/**
11+
* @brief This function is responsible for powering on the radio device loader.
12+
*
13+
* This function is responsible for powering on the radio device loader.
14+
* It attempts to enable the OTG (On-The-Go) power.
15+
* The function uses a @c `while` loop with a maximum of 5 attempts to enable the OTG power.
16+
* If it succeeds, it will break out of the loop.
17+
* If the maximum number of attempts is reached and the OTG power is not enabled,
18+
* the function checks the USB voltage using @c `furi_hal_power_get_usb_voltage()`.
19+
*
20+
* If the voltage is below 4.5 volts, an error message is logged using @c `FURI_LOG_E()`
21+
* with a message includes the value of @c `furi_hal_power_check_otg_fault()`
22+
* (converted to 1 if true, 0 if false),
23+
* which checks the OTG fault status using the BQ2589 chip.
24+
*
25+
*/
1026
static void subbrute_radio_device_loader_power_on() {
1127
uint8_t attempts = 5;
1228
while(--attempts > 0) {
@@ -24,13 +40,34 @@ static void subbrute_radio_device_loader_power_on() {
2440
}
2541
}
2642

43+
/**
44+
* @brief Turns off the power of the radio device loader.
45+
*
46+
* This function checks if OTG (On-The-Go) power is enabled, and if so, it disables it.
47+
*
48+
* @note This function is static and used internally by the radio device loader module.
49+
*
50+
*/
2751
static void subbrute_radio_device_loader_power_off() {
2852
if(furi_hal_power_is_otg_enabled()) {
2953
furi_hal_power_disable_otg();
3054
}
3155
}
3256

33-
bool subbrute_radio_device_loader_is_connect_external(const char* name) {
57+
/**
58+
* @brief Checks if a radio device of the given name is connected externally.
59+
*
60+
* This function checks if a radio device with the specified name is connected externally.
61+
* If the OTG power is not enabled, it attempts to power on the radio device loader.
62+
* It then retrieves the device information using the provided name and checks if it is connected.
63+
* Finally, if the OTG power was initially disabled, it powers off the radio device loader.
64+
*
65+
* @param[in] name The name of the radio device to check.
66+
*
67+
* @return true if the device is connected externally, false otherwise.
68+
*
69+
*/
70+
static bool subbrute_radio_device_loader_is_connect_external(const char* name) {
3471
bool is_connect = false;
3572
bool is_otg_enabled = furi_hal_power_is_otg_enabled();
3673

helpers/subbrute_radio_device_loader.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,33 @@ typedef enum {
1616
*
1717
* This function is used to set the SubGhz radio device type for the SubBrute radio device loader.
1818
*
19-
* @param current_radio_device Pointer to the current SubGhz radio device.
20-
* @param radio_device_type The desired SubGhz radio device type.
21-
* @return const SubGhzDevice* Pointer to the new SubGhz radio device.
19+
* @param [in] current_radio_device Pointer to the current SubGhz radio device.
20+
* @param [in] radio_device_type The desired SubGhz radio device type.
21+
*
22+
* @return @c const SubGhzDevice* Pointer to the new SubGhz radio device.
2223
*
2324
* @remark This function sets the SubGhz radio device type for the SubBrute radio device loader.
2425
* The current radio device will be replaced with a new instance of the specified radio device type.
2526
* If @p current_radio_device is NULL, a new instance of the specified radio device type will be created.
2627
*
2728
* @note The caller is responsible for handling memory deallocation of the returned pointer.
29+
*
2830
*/
2931
const SubGhzDevice* subbrute_radio_device_loader_set(
3032
const SubGhzDevice* current_radio_device,
3133
SubGhzRadioDeviceType radio_device_type);
3234

3335
/**
34-
* @brief Unloads a SubGhz radio device.
36+
* @brief Unloads the radio device in the subbrute radio device loader.
37+
*
38+
* This function is called to unload the specified radio device in the
39+
* subbrute radio device loader.
40+
* It first checks if the radio device is valid and then performs the necessary steps to
41+
* power off the device.
42+
* If the radio device is not the CC1101 internal device, it calls @c subghz_devices_end()
43+
* function to terminate the radio device.
3544
*
36-
* This function unloads a SubGhz radio device and performs any necessary cleanup.
45+
* @param[in] radio_device A pointer to the radio device to unload.
3746
*
38-
* @param radio_device Pointer to the SubGhzDevice structure representing the radio device to be unloaded.
3947
*/
4048
void subbrute_radio_device_loader_end(const SubGhzDevice* radio_device);

helpers/subbrute_worker.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ typedef struct SubBruteWorker SubBruteWorker;
3232
* This function creates a new SubBruteWorker object by allocating memory for it on the heap and
3333
* initializes it with the provided radio_device. The radio_device parameter must not be NULL.
3434
*
35-
* @param radio_device A pointer to a valid SubGhzDevice object.
36-
* @return A pointer to the newly allocated SubBruteWorker object, or NULL if memory allocation failed.
35+
* @param[in] radio_device A pointer to a valid SubGhzDevice object.
36+
* @return A pointer to the newly allocated SubBruteWorker object, or @c NULL if memory
37+
* allocation was failed.
3738
*/
3839
SubBruteWorker* subbrute_worker_alloc(const SubGhzDevice* radio_device);
3940

helpers/subbrute_worker_private.h

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include "subbrute_worker.h"
4+
45
#include <lib/subghz/protocols/base.h>
56
#include <lib/subghz/transmitter.h>
67
#include <lib/subghz/receiver.h>
@@ -14,41 +15,41 @@
1415
* It manages the state, configuration and execution of the sub-brute forcing algorithm.
1516
*/
1617
struct SubBruteWorker {
17-
SubBruteWorkerState state;
18-
volatile bool worker_running;
19-
volatile bool initiated;
20-
volatile bool transmit_mode;
18+
SubBruteWorkerState state; /**< State of the worker */
19+
volatile bool worker_running; /**< Worker running state */
20+
volatile bool initiated; /**< Initiated state */
21+
volatile bool transmit_mode; /**< Transmit mode */
22+
23+
uint64_t step; /**< Current step */
2124

22-
// Current step
23-
uint64_t step;
25+
FuriThread* thread; /**< Thread */
2426

25-
// SubGhz
26-
FuriThread* thread;
27+
/** @see @c SubGhz service for more info */
28+
SubGhzEnvironment* environment; /**< Environment */
2729
SubGhzProtocolDecoderBase* decoder_result;
28-
SubGhzEnvironment* environment;
29-
SubGhzTransmitter* transmitter;
30-
const char* protocol_name;
31-
uint8_t tx_timeout_ms;
32-
const SubGhzDevice* radio_device;
30+
SubGhzTransmitter* transmitter; /**< Transmitter */
31+
const char* protocol_name; /**< Name of the protocol */
32+
uint8_t tx_timeout_ms; /**< Timeout for transmit */
33+
const SubGhzDevice* radio_device; /**< Radio device */
3334

3435
// Initiated values
35-
SubBruteAttacks attack; // Attack state
36-
uint32_t frequency;
37-
FuriHalSubGhzPreset preset;
38-
SubBruteFileProtocol file;
39-
uint8_t bits;
40-
uint32_t te;
41-
uint8_t repeat;
42-
uint8_t load_index; // Index of group to bruteforce in loaded file
43-
uint64_t file_key;
44-
uint64_t max_value; // Max step
45-
bool two_bytes;
36+
SubBruteAttacks attack; /**< Attack state */
37+
uint32_t frequency; /**< Frequency */
38+
FuriHalSubGhzPreset preset; /**< Preset */
39+
SubBruteFileProtocol file; /**< File protocol */
40+
uint8_t bits; /**< Number of bits in key */
41+
uint32_t te; /**< Time to wait for response */
42+
uint8_t repeat; /**< Number of extra repeats */
43+
uint8_t load_index; /**< Index of group to bruteforce in loaded file */
44+
uint64_t file_key; /**< Key from file */
45+
uint64_t max_value; /**< Max step */
46+
bool two_bytes; /**< Two bytes key */
4647

4748
// Manual transmit
48-
uint32_t last_time_tx_data;
49+
uint32_t last_time_tx_data; /**< Last time data was transmitted */
4950

5051
// Callback for changed states
51-
SubBruteWorkerCallback callback;
52+
SubBruteWorkerCallback callback; /**< Callback for changed states */
5253
void* context;
5354
};
5455

@@ -85,4 +86,4 @@ void subbrute_worker_subghz_transmit(SubBruteWorker* instance, FlipperFormat* fl
8586
*
8687
* @note This function does not return any values.
8788
*/
88-
void subbrute_worker_send_callback(SubBruteWorker* instance);
89+
void subbrute_worker_send_callback(SubBruteWorker* instance);

subbrute.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ SubBruteState* subbrute_alloc() {
107107

108108
instance->settings = subbrute_settings_alloc();
109109
subbrute_settings_load(instance->settings);
110-
//instance->flipper_format = flipper_format_string_alloc();
111-
//instance->environment = subghz_environment_alloc();
112110

113111
// Uncomment to enable Debug pin output on PIN 17(1W)
114112
// subghz_devices_set_async_mirror_pin(instance->radio_device, &gpio_ibutton);
@@ -166,7 +164,7 @@ void subbrute_free(SubBruteState* instance) {
166164
view_dispatcher_remove_view(instance->view_dispatcher, SubBruteViewStack);
167165
view_stack_free(instance->view_stack);
168166

169-
//Dialog
167+
// Dialog
170168
furi_record_close(RECORD_DIALOGS);
171169
instance->dialogs = NULL;
172170

@@ -216,5 +214,6 @@ int32_t subbrute_app(void* p) {
216214
subbrute_free(instance);
217215

218216
furi_hal_power_suppress_charge_exit();
217+
219218
return 0;
220219
}

0 commit comments

Comments
 (0)